From patchwork Wed Jun 3 21:34:34 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Williams X-Patchwork-Id: 6541641 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 047D59F326 for ; Wed, 3 Jun 2015 21:37:50 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 0AD492073F for ; Wed, 3 Jun 2015 21:37:49 +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 102EC20739 for ; Wed, 3 Jun 2015 21:37:48 +0000 (UTC) Received: from ml01.vlan14.01.org (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 01F4C182888; Wed, 3 Jun 2015 14:37:48 -0700 (PDT) X-Original-To: linux-nvdimm@lists.01.org Delivered-To: linux-nvdimm@lists.01.org Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by ml01.01.org (Postfix) with ESMTP id 9868D182886 for ; Wed, 3 Jun 2015 14:37:46 -0700 (PDT) Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga103.jf.intel.com with ESMTP; 03 Jun 2015 14:37:16 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.13,548,1427785200"; d="scan'208";a="740459128" Received: from dwillia2-desk3.jf.intel.com (HELO dwillia2-desk3.amr.corp.intel.com) ([10.23.232.36]) by orsmga002.jf.intel.com with ESMTP; 03 Jun 2015 14:37:14 -0700 Subject: [PATCH v3 4/6] 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: Wed, 03 Jun 2015 17:34:34 -0400 Message-ID: <20150603213434.13749.46518.stgit@dwillia2-desk3.amr.corp.intel.com> In-Reply-To: <20150603211948.13749.85816.stgit@dwillia2-desk3.amr.corp.intel.com> References: <20150603211948.13749.85816.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, linux-nvdimm@lists.01.org, benh@kernel.crashing.org, mcgrof@suse.com, x86@kernel.org, linux-kernel@vger.kernel.org, stefan.bader@canonical.com, luto@amacapital.net, linux-mm@kvack.org, geert@linux-m68k.org, ralf@linux-mips.org, hmh@hmh.eng.br, mpe@ellerman.id.au, tj@kernel.org, paulus@samba.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 Cc: Arnd Bergmann Signed-off-by: Dan Williams --- include/linux/io.h | 2 ++ lib/devres.c | 53 +++++++++++++++++++++++++--------------------------- 2 files changed, 27 insertions(+), 28 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 f4001d90d24d..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); @@ -153,8 +147,11 @@ void __iomem *devm_ioremap_resource(struct device *dev, struct resource *res) return IOMEM_ERR_PTR(-EBUSY); } - /* FIXME: add devm_ioremap_cache support */ - dest_ptr = devm_ioremap(dev, res->start, size); + if (res->flags & IORESOURCE_CACHEABLE) + dest_ptr = devm_ioremap_cache(dev, res->start, size); + else + dest_ptr = devm_ioremap_nocache(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);