From patchwork Thu Oct 27 18:56:11 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dave Gerlach X-Patchwork-Id: 9400225 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id D739B60231 for ; Thu, 27 Oct 2016 18:59:20 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BD3CD2A380 for ; Thu, 27 Oct 2016 18:59:20 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B19342A382; Thu, 27 Oct 2016 18:59:20 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 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.wl.linuxfoundation.org (Postfix) with ESMTPS id 59B162A380 for ; Thu, 27 Oct 2016 18:59:20 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.85_2 #1 (Red Hat Linux)) id 1bzpsL-0004ca-IO; Thu, 27 Oct 2016 18:58:05 +0000 Received: from devils.ext.ti.com ([198.47.26.153]) by bombadil.infradead.org with esmtps (Exim 4.85_2 #1 (Red Hat Linux)) id 1bzprx-0004U6-3B for linux-arm-kernel@lists.infradead.org; Thu, 27 Oct 2016 18:57:42 +0000 Received: from dflxv15.itg.ti.com ([128.247.5.124]) by devils.ext.ti.com (8.13.7/8.13.7) with ESMTP id u9RIuwUn006017; Thu, 27 Oct 2016 13:56:58 -0500 Received: from DLEE71.ent.ti.com (dlee71.ent.ti.com [157.170.170.114]) by dflxv15.itg.ti.com (8.14.3/8.13.8) with ESMTP id u9RIuvlV015289; Thu, 27 Oct 2016 13:56:57 -0500 Received: from dlep33.itg.ti.com (157.170.170.75) by DLEE71.ent.ti.com (157.170.170.114) with Microsoft SMTP Server id 14.3.294.0; Thu, 27 Oct 2016 13:56:57 -0500 Received: from legion.dal.design.ti.com (legion.dal.design.ti.com [128.247.22.53]) by dlep33.itg.ti.com (8.14.3/8.13.8) with ESMTP id u9RIuv4o021103; Thu, 27 Oct 2016 13:56:57 -0500 Received: from localhost (uda0274052.am.dhcp.ti.com [128.247.83.19]) by legion.dal.design.ti.com (8.11.7p1+Sun/8.11.7) with ESMTP id u9RIuu327515; Thu, 27 Oct 2016 13:56:56 -0500 (CDT) From: Dave Gerlach To: Arnd Bergmann , Russell King , Dan Williams Subject: [PATCH 2/3] memremap: add MEMREMAP_EXEC and MEMREMAP_EXEC_NOCACHE flags Date: Thu, 27 Oct 2016 13:56:11 -0500 Message-ID: <20161027185612.22362-3-d-gerlach@ti.com> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20161027185612.22362-1-d-gerlach@ti.com> References: <20161027185612.22362-1-d-gerlach@ti.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20161027_115741_313157_4C52C194 X-CRM114-Status: GOOD ( 12.99 ) 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: Nishanth Menon , Dave Gerlach , Tony Lindgren , Greg Kroah-Hartman , linux-kernel@vger.kernel.org, Alexandre Belloni , linux-omap@vger.kernel.org, Shawn Guo , 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-Virus-Scanned: ClamAV using ClamSMTP Add flags to memremap() for MEMREMAP_EXEC and MEMREMAP_EXEC_NOCACHE mappings. Mappings provided by these flags will both allow execution, with MEMREMAP_EXEC_NOCACHE also requiring the memory to be mapped non-cached. These mappings are useful for architectures that must map on-chip memory such as SRAM and then copy and execute code from it, such as code used to reconfigure system memory controllers or the low-level PM code on ARM platforms. Also add stubs for both underlying arch_memremap_exec/nocache calls that return NULL so that if either is attempted from a platform cannot map memory in such a way will fail. Signed-off-by: Dave Gerlach --- include/linux/io.h | 2 ++ kernel/memremap.c | 34 +++++++++++++++++++++++++++++++++- 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/include/linux/io.h b/include/linux/io.h index e2c8419278c1..6668b6b9123b 100644 --- a/include/linux/io.h +++ b/include/linux/io.h @@ -136,6 +136,8 @@ enum { MEMREMAP_WB = 1 << 0, MEMREMAP_WT = 1 << 1, MEMREMAP_WC = 1 << 2, + MEMREMAP_EXEC = 1 << 3, + MEMREMAP_EXEC_NOCACHE = 1 << 4, }; void *memremap(resource_size_t offset, size_t size, unsigned long flags); diff --git a/kernel/memremap.c b/kernel/memremap.c index b501e390bb34..47cefc64057d 100644 --- a/kernel/memremap.c +++ b/kernel/memremap.c @@ -34,6 +34,21 @@ static void *arch_memremap_wb(resource_size_t offset, unsigned long size) } #endif +#ifndef arch_memremap_exec +static void *arch_memremap_exec(resource_size_t offset, unsigned long size) +{ + return NULL; +} +#endif + +#ifndef arch_memremap_exec_nocache +static void *arch_memremap_exec_nocache(resource_size_t offset, + unsigned long size) +{ + return NULL; +} +#endif + static void *try_ram_remap(resource_size_t offset, size_t size) { unsigned long pfn = PHYS_PFN(offset); @@ -48,7 +63,8 @@ static void *try_ram_remap(resource_size_t offset, size_t size) * memremap() - remap an iomem_resource as cacheable memory * @offset: iomem resource start address * @size: size of remap - * @flags: any of MEMREMAP_WB, MEMREMAP_WT and MEMREMAP_WC + * @flags: any of MEMREMAP_WB, MEMREMAP_WT, MEMREMAP_WC, MEMREMAP_EXEC, + * and MEMREMAP_EXEC_NOCACHE * * memremap() is "ioremap" for cases where it is known that the resource * being mapped does not have i/o side effects and the __iomem @@ -70,6 +86,16 @@ static void *try_ram_remap(resource_size_t offset, size_t size) * MEMREMAP_WC - establish a writecombine mapping, whereby writes may * be coalesced together (e.g. in the CPU's write buffers), but is otherwise * uncached. Attempts to map System RAM with this mapping type will fail. + * + * MEMREMAP_EXEC - map memory as cached, as MEMREMAP_WB does, but also + * executable to allow for executing code from something like an on-chip + * memory. If support for executable mapping is not present on platform + * then the mapping will fail. + * + * MEMREMAP_EXEC_NOCACHE - map memory as non-cached and executable to allow + * for executing code from something like an on-chip memory. If support for + * executable, non-cached mapping is not present on platform then the + * mapping will fail. */ void *memremap(resource_size_t offset, size_t size, unsigned long flags) { @@ -118,6 +144,12 @@ void *memremap(resource_size_t offset, size_t size, unsigned long flags) if (!addr && (flags & MEMREMAP_WC)) addr = ioremap_wc(offset, size); + if (!addr && (flags & MEMREMAP_EXEC)) + addr = arch_memremap_exec(offset, size); + + if (!addr && (flags & MEMREMAP_EXEC_NOCACHE)) + addr = arch_memremap_exec_nocache(offset, size); + return addr; } EXPORT_SYMBOL(memremap);