From patchwork Wed Nov 26 21:14:01 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dave Gerlach X-Patchwork-Id: 5388091 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 07E019F2F5 for ; Wed, 26 Nov 2014 21:17:07 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id DD7112016C for ; Wed, 26 Nov 2014 21:17:05 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id C264320149 for ; Wed, 26 Nov 2014 21:17:04 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1XtjvX-00048m-0o; Wed, 26 Nov 2014 21:15:07 +0000 Received: from arroyo.ext.ti.com ([192.94.94.40]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1XtjvF-00042h-Se for linux-arm-kernel@lists.infradead.org; Wed, 26 Nov 2014 21:14:51 +0000 Received: from dflxv15.itg.ti.com ([128.247.5.124]) by arroyo.ext.ti.com (8.13.7/8.13.7) with ESMTP id sAQLEM06025237; Wed, 26 Nov 2014 15:14:22 -0600 Received: from DFLE73.ent.ti.com (dfle73.ent.ti.com [128.247.5.110]) by dflxv15.itg.ti.com (8.14.3/8.13.8) with ESMTP id sAQLEMmw016249; Wed, 26 Nov 2014 15:14:22 -0600 Received: from dlep32.itg.ti.com (157.170.170.100) by DFLE73.ent.ti.com (128.247.5.110) with Microsoft SMTP Server id 14.3.174.1; Wed, 26 Nov 2014 15:14:22 -0600 Received: from legion.dal.design.ti.com (legion.dal.design.ti.com [128.247.22.53]) by dlep32.itg.ti.com (8.14.3/8.13.8) with ESMTP id sAQLELv8018373; Wed, 26 Nov 2014 15:14:21 -0600 Received: from localhost (j-172-22-146-2.vpn.ti.com [172.22.146.2]) by legion.dal.design.ti.com (8.11.7p1+Sun/8.11.7) with ESMTP id sAQLEKt13493; Wed, 26 Nov 2014 15:14:20 -0600 (CST) From: Dave Gerlach To: , , , , Subject: [RFC PATCH 2/2] lib: devres: Add exec versions of devm_ioremap_resource and friends Date: Wed, 26 Nov 2014 15:14:01 -0600 Message-ID: X-Mailer: git-send-email 2.1.0 In-Reply-To: References: MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20141126_131450_086753_3B40947F X-CRM114-Status: GOOD ( 16.64 ) X-Spam-Score: -5.0 (-----) Cc: Arnd Bergmann , Dave Gerlach , Tony Lindgren , Greg Kroah-Hartman , Anson.Huang@freescale.com, Russ Dill , Philipp Zabel , Shawn Guo X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_LOW, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Russ Dill Now that there is an _exec version of ioremap, add devm support for it. Signed-off-by: Russ Dill Signed-off-by: Dave Gerlach --- include/linux/device.h | 19 +++++++- include/linux/io.h | 9 +++- lib/devres.c | 125 +++++++++++++++++++++++++++++++++++++++++++++++-- 3 files changed, 147 insertions(+), 6 deletions(-) diff --git a/include/linux/device.h b/include/linux/device.h index ce1f2160..d336465 100644 --- a/include/linux/device.h +++ b/include/linux/device.h @@ -635,7 +635,24 @@ extern unsigned long devm_get_free_pages(struct device *dev, gfp_t gfp_mask, unsigned int order); extern void devm_free_pages(struct device *dev, unsigned long addr); -void __iomem *devm_ioremap_resource(struct device *dev, struct resource *res); +void __iomem *__devm_ioremap_resource(struct device *dev, struct resource *res, + bool exec); +static inline void __iomem *devm_ioremap_resource(struct device *dev, + struct resource *res) +{ + return __devm_ioremap_resource(dev, res, false); +} +void __iomem *devm_request_and_ioremap(struct device *dev, + struct resource *res); + +static inline void __iomem *devm_ioremap_exec_resource(struct device *dev, + struct resource *res) +{ + return __devm_ioremap_resource(dev, res, true); +} + +void __iomem *devm_request_and_ioremap_exec(struct device *dev, + struct resource *res); /* allows to add/remove a custom action to devres stack */ int devm_add_action(struct device *dev, void (*action)(void *), void *data); diff --git a/include/linux/io.h b/include/linux/io.h index d5fc9b8..0c6405a 100644 --- a/include/linux/io.h +++ b/include/linux/io.h @@ -61,9 +61,14 @@ static inline void devm_ioport_unmap(struct device *dev, void __iomem *addr) #define IOMEM_ERR_PTR(err) (__force void __iomem *)ERR_PTR(err) void __iomem *devm_ioremap(struct device *dev, resource_size_t offset, - unsigned long size); + unsigned long size); void __iomem *devm_ioremap_nocache(struct device *dev, resource_size_t offset, - unsigned long size); + unsigned long size); +void __iomem *devm_ioremap_exec(struct device *dev, resource_size_t offset, + unsigned long size); +void __iomem *devm_ioremap_exec_nocache(struct device *dev, + resource_size_t offset, + unsigned long size); void devm_iounmap(struct device *dev, void __iomem *addr); int check_signature(const volatile void __iomem *io_addr, const unsigned char *signature, int length); diff --git a/lib/devres.c b/lib/devres.c index f4a195a..f5d0eac 100644 --- a/lib/devres.c +++ b/lib/devres.c @@ -72,6 +72,64 @@ void __iomem *devm_ioremap_nocache(struct device *dev, resource_size_t offset, EXPORT_SYMBOL(devm_ioremap_nocache); /** + * devm_ioremap_exec - Managed ioremap_exec() + * @dev: Generic device to remap IO address for + * @offset: BUS offset to map + * @size: Size of map + * + * Managed ioremap_exec(). Map is automatically unmapped on driver detach. + */ +void __iomem *devm_ioremap_exec(struct device *dev, resource_size_t offset, + unsigned long size) +{ + void __iomem **ptr, *addr; + + ptr = devres_alloc(devm_ioremap_release, sizeof(*ptr), GFP_KERNEL); + if (!ptr) + return NULL; + + addr = ioremap_exec(offset, size); + if (addr) { + *ptr = addr; + devres_add(dev, ptr); + } else + devres_free(ptr); + + return addr; +} +EXPORT_SYMBOL(devm_ioremap_exec); + +/** + * devm_ioremap_exec_nocache - Managed ioremap_exec_nocache() + * @dev: Generic device to remap IO address for + * @offset: BUS offset to map + * @size: Size of map + * + * Managed ioremap_exec_nocache(). Map is automatically unmapped on driver + * detach. + */ +void __iomem *devm_ioremap_exec_nocache(struct device *dev, + resource_size_t offset, + unsigned long size) +{ + void __iomem **ptr, *addr; + + ptr = devres_alloc(devm_ioremap_release, sizeof(*ptr), GFP_KERNEL); + if (!ptr) + return NULL; + + addr = ioremap_exec_nocache(offset, size); + if (addr) { + *ptr = addr; + devres_add(dev, ptr); + } else + devres_free(ptr); + + return addr; +} +EXPORT_SYMBOL(devm_ioremap_exec_nocache); + +/** * devm_iounmap - Managed iounmap() * @dev: Generic device to unmap for * @addr: Address to unmap @@ -104,7 +162,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 exec) { resource_size_t size; const char *name; @@ -125,7 +184,11 @@ void __iomem *devm_ioremap_resource(struct device *dev, struct resource *res) return IOMEM_ERR_PTR(-EBUSY); } - if (res->flags & IORESOURCE_CACHEABLE) + if (exec && res->flags & IORESOURCE_CACHEABLE) + dest_ptr = devm_ioremap_exec(dev, res->start, size); + else if (exec) + dest_ptr = devm_ioremap_exec_nocache(dev, res->start, size); + else if (res->flags & IORESOURCE_CACHEABLE) dest_ptr = devm_ioremap(dev, res->start, size); else dest_ptr = devm_ioremap_nocache(dev, res->start, size); @@ -138,7 +201,63 @@ void __iomem *devm_ioremap_resource(struct device *dev, struct resource *res) return dest_ptr; } -EXPORT_SYMBOL(devm_ioremap_resource); +EXPORT_SYMBOL(__devm_ioremap_resource); + +/** + * devm_request_and_ioremap() - Check, request region, and ioremap resource + * @dev: Generic device to handle the resource for + * @res: resource to be handled + * + * Takes all necessary steps to ioremap a mem resource. Uses managed device, so + * everything is undone on driver detach. Checks arguments, so you can feed + * it the result from e.g. platform_get_resource() directly. Returns the + * remapped pointer or NULL on error. Usage example: + * + * res = platform_get_resource(pdev, IORESOURCE_MEM, 0); + * base = devm_request_and_ioremap(&pdev->dev, res); + * if (!base) + * return -EADDRNOTAVAIL; + */ +void __iomem *devm_request_and_ioremap(struct device *device, + struct resource *res) +{ + void __iomem *dest_ptr; + + dest_ptr = devm_ioremap_resource(device, res); + if (IS_ERR(dest_ptr)) + return NULL; + + return dest_ptr; +} +EXPORT_SYMBOL(devm_request_and_ioremap); + +/** + * devm_request_and_ioremap_exec() - Check, request region, and ioremap resource + * @dev: Generic device to handle the resource for + * @res: resource to be handled + * + * Takes all necessary steps to ioremap a mem resource. Uses managed device, so + * everything is undone on driver detach. Checks arguments, so you can feed + * it the result from e.g. platform_get_resource() directly. Returns the + * remapped pointer or NULL on error. Usage example: + * + * res = platform_get_resource(pdev, IORESOURCE_MEM, 0); + * base = devm_request_and_ioremap_exec(&pdev->dev, res); + * if (!base) + * return -EADDRNOTAVAIL; + */ +void __iomem *devm_request_and_ioremap_exec(struct device *device, + struct resource *res) +{ + void __iomem *dest_ptr; + + dest_ptr = devm_ioremap_exec_resource(device, res); + if (IS_ERR(dest_ptr)) + return NULL; + + return dest_ptr; +} +EXPORT_SYMBOL(devm_request_and_ioremap_exec); #ifdef CONFIG_HAS_IOPORT_MAP /*