Received: by 10.223.176.46 with SMTP id f43csp549800wra; Wed, 24 Jan 2018 02:16:15 -0800 (PST) X-Google-Smtp-Source: AH8x226kRzKrhAuX6TanCC9UZDyAnlua2P7HGP9bOEafDtxhvGOtXCuapM9lS4Or2reqer7pC1Gl X-Received: by 10.101.71.130 with SMTP id e2mr10476785pgs.396.1516788975672; Wed, 24 Jan 2018 02:16:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516788975; cv=none; d=google.com; s=arc-20160816; b=yaBPvhBEORd67MbppFPwUSDXh+GgCKf2a1QG6e1ZFNwhnu4xrYooyN2otQcH0hjG0s NuKnyjd7fECvQJ7RqB0yR02GO8fm+rAUZ5PgyGUA4mLJ3NNerrShZywXUNyPimID4UEz YC+W9ypTXaZA6eDYFAOPYc/4aBtrZOAIWn0uOkah7VnKUwzl8gIRuqWAs9/ybJ4MygSD QU51noOPRwhu8EVBRd/lXoN6h5XMSUOQ0jIPCUU7xSlht/6ypBBTLNoJYu/XE5aUpbEK P5w+odo+9fNF6jct8BYO6NR/IW8Zmk0Ys7ECPPZTj3CXT21t17UQHjF3RnknOp5PUTIu 9AOA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:arc-authentication-results; bh=RuY7TJ/9eFe5yitzZK9PXP12mbw3VxzV34tL/4n+HHE=; b=Cvrd9sH6z9HL4KFT5eswojR4AkUF3R/KAQlsGte4DZQwcrTDrFx0ppXazDJWLL9iph Ik9UUmVZDovLqrGcqT0V4Pz0jQZ85kRVLK9PuI2oCFERJ4bVlT/TxbnmDTMq1aaWCNjr n5TxKrOhYCoxytn+lxbj9Ia+dOIq5z54m9ljTSQTjF5wdQ/agmU1VsA7wnDCn/wTgcxf P3LAkK66k9G9qTY1pPgEYvEYEiGponBo6pLI3qEjJ9e5lGOW0fTbelcJGI+KrScupx69 imgKP34COQEXLuTGYWg/90E3ddkG0sLZDbjZR+J3qCqiHiFPOTLjH62gmbY28phKctIl iCRA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n16si15815374pgc.589.2018.01.24.02.16.02; Wed, 24 Jan 2018 02:16:15 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933062AbeAXKP0 (ORCPT + 99 others); Wed, 24 Jan 2018 05:15:26 -0500 Received: from eddie.linux-mips.org ([148.251.95.138]:60430 "EHLO cvs.linux-mips.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932531AbeAXKPE (ORCPT ); Wed, 24 Jan 2018 05:15:04 -0500 Received: (from localhost user: 'ladis' uid#1021 fake: STDIN (ladis@eddie.linux-mips.org)) by eddie.linux-mips.org id S23991025AbeAXKH4IwC-V (ORCPT ); Wed, 24 Jan 2018 11:07:56 +0100 Date: Wed, 24 Jan 2018 11:07:54 +0100 From: Ladislav Michl To: linux-kernel@vger.kernel.org, linux-mtd@lists.infradead.org Cc: Thomas Gleixner , Tom Lendacky , Borislav Petkov , Ingo Molnar , Lorenzo Pieralisi , Philippe Ombredanne , Kate Stewart , Greg Kroah-Hartman , Boris Brezillon , Dmitry Torokhov , Bjorn Helgaas , Wei Yongjun Subject: [PATCH v2 2/3] devres: Add devm_ioremap_shared_resource() Message-ID: <20180124100754.GC19593@lenoch> References: <20180124100604.GA19593@lenoch> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180124100604.GA19593@lenoch> User-Agent: Mutt/1.9.2 (2017-12-15) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Implement managed ioremap function for shared resources. Signed-off-by: Ladislav Michl --- Changes: - v2: Rebased on top of PATCH v2 1/3 include/linux/io.h | 8 +++++++- lib/devres.c | 22 ++++++++++++++-------- 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/include/linux/io.h b/include/linux/io.h index 2aea3363bfb2..2b9eb48e0f49 100644 --- a/include/linux/io.h +++ b/include/linux/io.h @@ -79,10 +79,16 @@ void __iomem *devm_ioremap_nocache(struct device *dev, resource_size_t offset, resource_size_t size); void __iomem *devm_ioremap_wc(struct device *dev, resource_size_t offset, resource_size_t size); -void __iomem *devm_ioremap_resource(struct device *dev, struct resource *res); +#define devm_ioremap_resource(dev, res) \ + __devm_ioremap_resource(dev, res, false) +#define devm_ioremap_shared_resource(dev, res) \ + __devm_ioremap_resource(dev, res, true) +void __iomem *__devm_ioremap_resource(struct device *dev, struct resource *res, + bool shared); void devm_iounmap(struct device *dev, void __iomem *addr); int check_signature(const volatile void __iomem *io_addr, const unsigned char *signature, int length); + void devm_ioremap_release(struct device *dev, void *res); void *devm_memremap(struct device *dev, resource_size_t offset, diff --git a/lib/devres.c b/lib/devres.c index 5f2aedd58bc5..7711ff40a572 100644 --- a/lib/devres.c +++ b/lib/devres.c @@ -22,6 +22,9 @@ static int devm_ioremap_match(struct device *dev, void *res, void *match_data) * @size: Size of map * * Managed ioremap(). Map is automatically unmapped on driver detach. + * + * When possible, use devm_ioremap_resource() or + * devm_ioremap_shared_resource() instead. */ void __iomem *devm_ioremap(struct device *dev, resource_size_t offset, resource_size_t size) @@ -116,13 +119,14 @@ void devm_iounmap(struct device *dev, void __iomem *addr) EXPORT_SYMBOL(devm_iounmap); /** - * devm_ioremap_resource() - check, request region, and ioremap resource + * __devm_ioremap_resource() - check, request region, and ioremap resource * @dev: generic device to handle the resource for * @res: resource to be handled + * @shared: region is not requested when true * - * Checks that a resource is a valid memory region, requests the memory - * region and ioremaps it. All operations are managed and will be undone - * on driver detach. + * Checks that a resource is a valid memory region, eventually requests the + * memory region and ioremaps it. All operations are managed and will be + * undone on driver detach. * * Returns a pointer to the remapped memory or an ERR_PTR() encoded error code * on failure. Usage example: @@ -132,7 +136,8 @@ EXPORT_SYMBOL(devm_iounmap); * if (IS_ERR(base)) * return PTR_ERR(base); */ -void __iomem *devm_ioremap_resource(struct device *dev, struct resource *res) +void __iomem *__devm_ioremap_resource(struct device *dev, struct resource *res, + bool shared) { resource_size_t size; const char *name; @@ -148,7 +153,7 @@ void __iomem *devm_ioremap_resource(struct device *dev, struct resource *res) size = resource_size(res); name = res->name ?: dev_name(dev); - if (!devm_request_mem_region(dev, res->start, size, name)) { + if (!shared && !devm_request_mem_region(dev, res->start, size, name)) { dev_err(dev, "can't request region for resource %pR\n", res); return IOMEM_ERR_PTR(-EBUSY); } @@ -156,13 +161,14 @@ void __iomem *devm_ioremap_resource(struct device *dev, struct resource *res) dest_ptr = devm_ioremap(dev, res->start, size); if (!dest_ptr) { dev_err(dev, "ioremap failed for resource %pR\n", res); - devm_release_mem_region(dev, res->start, size); + if (!shared) + devm_release_mem_region(dev, res->start, size); dest_ptr = IOMEM_ERR_PTR(-ENOMEM); } return dest_ptr; } -EXPORT_SYMBOL(devm_ioremap_resource); +EXPORT_SYMBOL(__devm_ioremap_resource); #ifdef CONFIG_HAS_IOPORT_MAP /* -- 2.15.1