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: 9400221 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 B4C9860231 for ; Thu, 27 Oct 2016 18:58:42 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9B8E12A381 for ; Thu, 27 Oct 2016 18:58:42 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9061D2A384; Thu, 27 Oct 2016 18:58:42 +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=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 135E42A381 for ; Thu, 27 Oct 2016 18:58:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S935449AbcJ0S5o (ORCPT ); Thu, 27 Oct 2016 14:57:44 -0400 Received: from devils.ext.ti.com ([198.47.26.153]:37444 "EHLO devils.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751169AbcJ0S5n (ORCPT ); Thu, 27 Oct 2016 14:57:43 -0400 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 CC: , , , Greg Kroah-Hartman , Shawn Guo , Tony Lindgren , Alexandre Belloni , Nishanth Menon , Dave Gerlach 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 Sender: linux-omap-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-omap@vger.kernel.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);