From patchwork Fri Oct 9 22:15:43 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Williams X-Patchwork-Id: 7364581 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.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id AC5889F36A for ; Fri, 9 Oct 2015 22:23:51 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 89E692085B for ; Fri, 9 Oct 2015 22:23:50 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 2681020860 for ; Fri, 9 Oct 2015 22:23:49 +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 1Zkg2v-0000zQ-6C; Fri, 09 Oct 2015 22:21:49 +0000 Received: from mga09.intel.com ([134.134.136.24]) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1Zkg2s-0000x6-FV for linux-arm-kernel@lists.infradead.org; Fri, 09 Oct 2015 22:21:47 +0000 Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga102.jf.intel.com with ESMTP; 09 Oct 2015 15:21:25 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.17,660,1437462000"; d="scan'208";a="823302552" Received: from dwillia2-desk3.jf.intel.com ([10.54.39.39]) by orsmga002.jf.intel.com with ESMTP; 09 Oct 2015 15:21:25 -0700 Subject: [PATCH 01/20] x86: introduce arch_memremap() From: Dan Williams To: linux-kernel@vger.kernel.org Date: Fri, 09 Oct 2015 18:15:43 -0400 Message-ID: <20151009221543.32203.63200.stgit@dwillia2-desk3.jf.intel.com> In-Reply-To: <20151009221537.32203.5867.stgit@dwillia2-desk3.jf.intel.com> References: <20151009221537.32203.5867.stgit@dwillia2-desk3.jf.intel.com> User-Agent: StGit/0.17.1-9-g687f MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20151009_152146_593440_824E3B5D X-CRM114-Status: GOOD ( 20.22 ) X-Spam-Score: -6.9 (------) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-arch@vger.kernel.org, Arnd Bergmann , Ingo Molnar , Borislav Petkov , "H. Peter Anvin" , Thomas Gleixner , Ross Zwisler , linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, 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 In preparation for removing ioremap_cache() introduce arch_memremap() for x86. For now, arch_memremap(..., MEMREMAP_WB) and arch_memremap(..., MEMREMAP_WT) are aliases for ioremap_cache() and ioremap_wt() respectively. While the memremap() conversion patches are filtering through the other sub-systems further development of the memremap interface may proceed. This also initiates the guarantee that a successful call to memremap(..., MEMREMAP_WB) has indeed established a cached mapping and has not silently fallen back to uncached. Cc: Arnd Bergmann Cc: Thomas Gleixner Cc: H. Peter Anvin Cc: Ingo Molnar Cc: Borislav Petkov Cc: Ross Zwisler Signed-off-by: Dan Williams --- Documentation/x86/pat.txt | 2 ++ arch/x86/Kconfig | 1 + arch/x86/mm/ioremap.c | 17 +++++++++++++++++ drivers/nvdimm/Kconfig | 2 +- include/linux/io.h | 1 + kernel/memremap.c | 25 +++++++++++++------------ lib/Kconfig | 5 ++++- 7 files changed, 39 insertions(+), 14 deletions(-) diff --git a/Documentation/x86/pat.txt b/Documentation/x86/pat.txt index 54944c71b819..8c908fa5ea26 100644 --- a/Documentation/x86/pat.txt +++ b/Documentation/x86/pat.txt @@ -40,6 +40,8 @@ ioremap_nocache | -- | UC- | UC- | | | | | ioremap_wc | -- | -- | WC | | | | | +memremap(MEMREMAP_WB) | WB | WB | WB | + | | | | ioremap_wt | -- | -- | WT | | | | | set_memory_uc | UC- | -- | -- | diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig index 328c8352480c..488cb210d055 100644 --- a/arch/x86/Kconfig +++ b/arch/x86/Kconfig @@ -27,6 +27,7 @@ config X86 select ARCH_HAS_ELF_RANDOMIZE select ARCH_HAS_FAST_MULTIPLIER select ARCH_HAS_GCOV_PROFILE_ALL + select ARCH_HAS_MEMREMAP select ARCH_HAS_PMEM_API if X86_64 select ARCH_HAS_MMIO_FLUSH select ARCH_HAS_SG_CHAIN diff --git a/arch/x86/mm/ioremap.c b/arch/x86/mm/ioremap.c index b9c78f3bcd67..123431ae702f 100644 --- a/arch/x86/mm/ioremap.c +++ b/arch/x86/mm/ioremap.c @@ -317,6 +317,23 @@ void __iomem *ioremap_cache(resource_size_t phys_addr, unsigned long size) } EXPORT_SYMBOL(ioremap_cache); +void *arch_memremap(resource_size_t phys_addr, size_t size, + unsigned long flags) +{ + int prot; + + if (flags & MEMREMAP_WB) + prot = _PAGE_CACHE_MODE_WB; + else if (flags & MEMREMAP_WT) + prot = _PAGE_CACHE_MODE_WT; + else + return NULL; + + return (void __force *) __ioremap_caller(phys_addr, size, prot, + __builtin_return_address(0)); +} +EXPORT_SYMBOL(arch_memremap); + void __iomem *ioremap_prot(resource_size_t phys_addr, unsigned long size, unsigned long prot_val) { diff --git a/drivers/nvdimm/Kconfig b/drivers/nvdimm/Kconfig index 53c11621d5b1..b8e9d8b46f33 100644 --- a/drivers/nvdimm/Kconfig +++ b/drivers/nvdimm/Kconfig @@ -1,5 +1,6 @@ menuconfig LIBNVDIMM tristate "NVDIMM (Non-Volatile Memory Device) Support" + depends on ARCH_HAS_MEMREMAP depends on PHYS_ADDR_T_64BIT depends on BLK_DEV help @@ -19,7 +20,6 @@ if LIBNVDIMM config BLK_DEV_PMEM tristate "PMEM: Persistent memory block device support" default LIBNVDIMM - depends on HAS_IOMEM select ND_BTT if BTT select ND_PFN if NVDIMM_PFN help diff --git a/include/linux/io.h b/include/linux/io.h index de64c1e53612..4f150781735d 100644 --- a/include/linux/io.h +++ b/include/linux/io.h @@ -153,5 +153,6 @@ enum { void *memremap(resource_size_t offset, size_t size, unsigned long flags); void memunmap(void *addr); +void *arch_memremap(resource_size_t offset, size_t size, unsigned long flags); #endif /* _LINUX_IO_H */ diff --git a/kernel/memremap.c b/kernel/memremap.c index 72b0c66628b6..8bd5fe05d4a4 100644 --- a/kernel/memremap.c +++ b/kernel/memremap.c @@ -24,6 +24,16 @@ __weak void __iomem *ioremap_cache(resource_size_t offset, unsigned long size) } #endif +/* temporary while we convert arch implementations to arch_memremap */ +__weak void *arch_memremap(resource_size_t offset, size_t size, + unsigned long flags) +{ + if (flags & MEMREMAP_WB) + return (void __force *) ioremap_cache(offset, size); + else if (flags & MEMREMAP_WT) + return (void __force *) ioremap_wt(offset, size); +} + /** * memremap() - remap an iomem_resource as cacheable memory * @offset: iomem resource start address @@ -48,7 +58,6 @@ __weak void __iomem *ioremap_cache(resource_size_t offset, unsigned long size) void *memremap(resource_size_t offset, size_t size, unsigned long flags) { int is_ram = region_intersects(offset, size, "System RAM"); - void *addr = NULL; if (is_ram == REGION_MIXED) { WARN_ONCE(1, "memremap attempted on mixed range %pa size: %#lx\n", @@ -58,7 +67,6 @@ void *memremap(resource_size_t offset, size_t size, unsigned long flags) /* Try all mapping types requested until one returns non-NULL */ if (flags & MEMREMAP_WB) { - flags &= ~MEMREMAP_WB; /* * MEMREMAP_WB is special in that it can be satisifed * from the direct map. Some archs depend on the @@ -66,9 +74,7 @@ void *memremap(resource_size_t offset, size_t size, unsigned long flags) * the requested range is potentially in "System RAM" */ if (is_ram == REGION_INTERSECTS) - addr = __va(offset); - else - addr = ioremap_cache(offset, size); + return __va(offset); } /* @@ -77,18 +83,13 @@ void *memremap(resource_size_t offset, size_t size, unsigned long flags) * address mapping. Enforce that this mapping is not aliasing * "System RAM" */ - if (!addr && is_ram == REGION_INTERSECTS && flags) { + if (is_ram == REGION_INTERSECTS) { WARN_ONCE(1, "memremap attempted on ram %pa size: %#lx\n", &offset, (unsigned long) size); return NULL; } - if (!addr && (flags & MEMREMAP_WT)) { - flags &= ~MEMREMAP_WT; - addr = ioremap_wt(offset, size); - } - - return addr; + return arch_memremap(offset, size, flags); } EXPORT_SYMBOL(memremap); diff --git a/lib/Kconfig b/lib/Kconfig index 2e491ac15622..8d99b4e6a45b 100644 --- a/lib/Kconfig +++ b/lib/Kconfig @@ -520,7 +520,10 @@ config SG_SPLIT # config ARCH_HAS_SG_CHAIN - def_bool n + bool + +config ARCH_HAS_MEMREMAP + bool config ARCH_HAS_PMEM_API bool