From patchwork Sat May 30 18:59:29 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Williams X-Patchwork-Id: 6514351 Return-Path: X-Original-To: patchwork-linux-nvdimm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 8CB899F1CC for ; Sat, 30 May 2015 19:02:13 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 774372083C for ; Sat, 30 May 2015 19:02:12 +0000 (UTC) Received: from ml01.01.org (ml01.01.org [198.145.21.10]) (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 7B93120843 for ; Sat, 30 May 2015 19:02:11 +0000 (UTC) Received: from ml01.vlan14.01.org (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 6E08C182915; Sat, 30 May 2015 12:02:11 -0700 (PDT) X-Original-To: linux-nvdimm@lists.01.org Delivered-To: linux-nvdimm@lists.01.org Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by ml01.01.org (Postfix) with ESMTP id 34F4B1828FC for ; Sat, 30 May 2015 12:02:10 -0700 (PDT) Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga102.jf.intel.com with ESMTP; 30 May 2015 12:02:10 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.13,523,1427785200"; d="scan'208";a="718042415" Received: from dwillia2-desk3.jf.intel.com (HELO dwillia2-desk3.amr.corp.intel.com) ([10.23.232.36]) by fmsmga001.fm.intel.com with ESMTP; 30 May 2015 12:02:09 -0700 Subject: [PATCH v2 2/4] devm: fix ioremap_cache() usage From: Dan Williams To: arnd@arndb.de, mingo@redhat.com, bp@alien8.de, hpa@zytor.com, tglx@linutronix.de, ross.zwisler@linux.intel.com, akpm@linux-foundation.org Date: Sat, 30 May 2015 14:59:29 -0400 Message-ID: <20150530185929.32590.22873.stgit@dwillia2-desk3.amr.corp.intel.com> In-Reply-To: <20150530185425.32590.3190.stgit@dwillia2-desk3.amr.corp.intel.com> References: <20150530185425.32590.3190.stgit@dwillia2-desk3.amr.corp.intel.com> User-Agent: StGit/0.17.1-8-g92dd MIME-Version: 1.0 Cc: jgross@suse.com, konrad.wilk@oracle.com, mcgrof@suse.com, x86@kernel.org, linux-kernel@vger.kernel.org, stefan.bader@canonical.com, luto@amacapital.net, linux-mm@kvack.org, linux-nvdimm@lists.01.org, geert@linux-m68k.org, hmh@hmh.eng.br, tj@kernel.org, hch@lst.de X-BeenThere: linux-nvdimm@lists.01.org X-Mailman-Version: 2.1.17 Precedence: list List-Id: "Linux-nvdimm developer list." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: linux-nvdimm-bounces@lists.01.org Sender: "Linux-nvdimm" X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, 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 Provide devm_ioremap_cache() and fix up devm_ioremap_resource() to actually provide cacheable mappings. On archs that implement ioremap_cache() devm_ioremap_resource() is always silently falling back to uncached when IORESOURCE_CACHEABLE is specified. Cc: Toshi Kani Signed-off-by: Dan Williams --- include/linux/io.h | 2 ++ lib/devres.c | 48 +++++++++++++++++++++--------------------------- 2 files changed, 23 insertions(+), 27 deletions(-) diff --git a/include/linux/io.h b/include/linux/io.h index 04cce4da3685..1c9ad4c6d485 100644 --- a/include/linux/io.h +++ b/include/linux/io.h @@ -70,6 +70,8 @@ static inline void devm_ioport_unmap(struct device *dev, void __iomem *addr) void __iomem *devm_ioremap(struct device *dev, resource_size_t offset, resource_size_t size); +void __iomem *devm_ioremap_cache(struct device *dev, resource_size_t offset, + resource_size_t size); 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, diff --git a/lib/devres.c b/lib/devres.c index fbe2aac522e6..c8e75cdaf816 100644 --- a/lib/devres.c +++ b/lib/devres.c @@ -14,6 +14,8 @@ static int devm_ioremap_match(struct device *dev, void *res, void *match_data) return *(void **)res == match_data; } +typedef void __iomem *(*ioremap_fn)(resource_size_t offset, unsigned long size); + /** * devm_ioremap - Managed ioremap() * @dev: Generic device to remap IO address for @@ -22,8 +24,9 @@ static int devm_ioremap_match(struct device *dev, void *res, void *match_data) * * Managed ioremap(). Map is automatically unmapped on driver detach. */ -void __iomem *devm_ioremap(struct device *dev, resource_size_t offset, - resource_size_t size) +static void __iomem *devm_ioremap_type(struct device *dev, + resource_size_t offset, resource_size_t size, + ioremap_fn ioremap_type) { void __iomem **ptr, *addr; @@ -31,7 +34,7 @@ void __iomem *devm_ioremap(struct device *dev, resource_size_t offset, if (!ptr) return NULL; - addr = ioremap(offset, size); + addr = ioremap_type(offset, size); if (addr) { *ptr = addr; devres_add(dev, ptr); @@ -40,34 +43,25 @@ void __iomem *devm_ioremap(struct device *dev, resource_size_t offset, return addr; } + +void __iomem *devm_ioremap(struct device *dev, resource_size_t offset, + resource_size_t size) +{ + return devm_ioremap_type(dev, offset, size, ioremap); +} EXPORT_SYMBOL(devm_ioremap); -/** - * devm_ioremap_nocache - Managed ioremap_nocache() - * @dev: Generic device to remap IO address for - * @offset: BUS offset to map - * @size: Size of map - * - * Managed ioremap_nocache(). Map is automatically unmapped on driver - * detach. - */ +void __iomem *devm_ioremap_cache(struct device *dev, resource_size_t offset, + resource_size_t size) +{ + return devm_ioremap_type(dev, offset, size, ioremap_cache); +} +EXPORT_SYMBOL(devm_ioremap_cache); + void __iomem *devm_ioremap_nocache(struct device *dev, resource_size_t offset, resource_size_t size) { - void __iomem **ptr, *addr; - - ptr = devres_alloc(devm_ioremap_release, sizeof(*ptr), GFP_KERNEL); - if (!ptr) - return NULL; - - addr = ioremap_nocache(offset, size); - if (addr) { - *ptr = addr; - devres_add(dev, ptr); - } else - devres_free(ptr); - - return addr; + return devm_ioremap_type(dev, offset, size, ioremap_nocache); } EXPORT_SYMBOL(devm_ioremap_nocache); @@ -154,7 +148,7 @@ void __iomem *devm_ioremap_resource(struct device *dev, struct resource *res) } if (res->flags & IORESOURCE_CACHEABLE) - dest_ptr = devm_ioremap(dev, res->start, size); + dest_ptr = devm_ioremap_cache(dev, res->start, size); else dest_ptr = devm_ioremap_nocache(dev, res->start, size);