From patchwork Sun Jan 22 03:20:50 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: afzal mohammed X-Patchwork-Id: 9530745 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 7B83F601D4 for ; Sun, 22 Jan 2017 03:22:58 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6BDAE28358 for ; Sun, 22 Jan 2017 03:22:58 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6088A28387; Sun, 22 Jan 2017 03:22:58 +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=-1.3 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_SORBS_SPAM, T_DKIM_INVALID autolearn=no version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 166E528358 for ; Sun, 22 Jan 2017 03:22:58 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1cV8k0-0003P2-R0; Sun, 22 Jan 2017 03:22:52 +0000 Received: from mail-pg0-f66.google.com ([74.125.83.66]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1cV8jb-0003DH-Hs for linux-arm-kernel@lists.infradead.org; Sun, 22 Jan 2017 03:22:29 +0000 Received: by mail-pg0-f66.google.com with SMTP id t6so10413694pgt.1 for ; Sat, 21 Jan 2017 19:22:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=d1DkaGXwhpm4MBOyAvg1bjzOqAUHuh54ZRHjgg2WqEM=; b=pECIyLmDzNopu8rxkoyIPhAQpQ+F0NdqbdFqnixDgK2UU8gVpmbWObCDXYMx7scigl 1Hxkb3tpnPYiqHTYKci7lkPVU+T055D9ROfL990VUbnTDh8ihzr+oWMSqhFsXwf8g1Rh yHM8CPf3hAPOYM3yQ3T8jUj+YUVXtBxq99Y3XyF6+gZk6AC+PcYhFSXn3HUb1ET26LS0 YDMX/8zKGilEtB1rbr5dHifFl2oizZYezr/LTAfI7dbOyK+IVfEwH22QVxyXFF34B0/0 NW3OsNxiaQ7l/IhEA5uRBFofA7k7QPRKr2yhjMH/OH5YAinFpSIw6vvSfQ+/qXlzM1ue Awiw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=d1DkaGXwhpm4MBOyAvg1bjzOqAUHuh54ZRHjgg2WqEM=; b=Pqung4flPoe6d3cPOxuVjxCMrnW/WmL/tGVoqcGEWBfRoyj2btbOmZkAatSP5rMA90 Hjhnj5/aih4KYtKUx3ikBOmOiagjGFBN5fUBbkhkDyzDOtlBpsazmIGNy6iYLDxy87xy ELLwtPmLg9xMcTEN3cNuEyjpMa/BfVg8JczHMRIwPCOw0B4zRf26jxhWtlbsP9ISQP/n SRVEZH2XG8O+cspapldjD8+YYGkvyTEGM+Zl5MywhLmuNFMaakIkDZyDSygjwB03lYHm MDojV6MORRHRdC67Y8m34jJfORvGpI8lspAjCcCjffxThlRtL94mBsq1cOXDQdYmh5rQ 5dPQ== X-Gm-Message-State: AIkVDXKX1lsTSg7in3XnQVKUfkpGNckhn17zDXuiDh9oynmqs2B3UIvn57ydZIuJtaxgQw== X-Received: by 10.99.3.5 with SMTP id 5mr25598994pgd.150.1485055267091; Sat, 21 Jan 2017 19:21:07 -0800 (PST) Received: from localhost.localdomain ([223.227.141.101]) by smtp.gmail.com with ESMTPSA id q5sm26888443pgf.45.2017.01.21.19.20.58 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 21 Jan 2017 19:21:06 -0800 (PST) From: afzal mohammed To: Russell King - ARM Linux Subject: [PATCH v2 2/4] ARM: nommu: dynamic exception base address setting Date: Sun, 22 Jan 2017 08:50:50 +0530 Message-Id: <20170122032050.13344-1-afzal.mohd.ma@gmail.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170122031652.13074-1-afzal.mohd.ma@gmail.com> References: <20170122031652.13074-1-afzal.mohd.ma@gmail.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170121_192227_621131_7BFC7F29 X-CRM114-Status: GOOD ( 16.93 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Vladimir Murzin , afzal mohammed , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 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 No-MMU dynamic exception base address configuration on CP15 processors. In the case of low vectors, decision based on whether security extensions are enabled & whether remap vectors to RAM CONFIG option is selected. For no-MMU without CP15, current default value of 0x0 is retained. Signed-off-by: afzal mohammed --- v2: Use existing helpers to detect security extensions Rewrite a CPP step to C for readability arch/arm/mm/nommu.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 50 insertions(+), 2 deletions(-) diff --git a/arch/arm/mm/nommu.c b/arch/arm/mm/nommu.c index 2740967727e2..20ac52579952 100644 --- a/arch/arm/mm/nommu.c +++ b/arch/arm/mm/nommu.c @@ -11,6 +11,7 @@ #include #include +#include #include #include #include @@ -22,6 +23,8 @@ #include "mm.h" +unsigned long vectors_base; + #ifdef CONFIG_ARM_MPU struct mpu_rgn_info mpu_rgn_info; @@ -278,15 +281,60 @@ static void sanity_check_meminfo_mpu(void) {} static void __init mpu_setup(void) {} #endif /* CONFIG_ARM_MPU */ +#ifdef CONFIG_CPU_CP15 +#ifdef CONFIG_CPU_HIGH_VECTOR +static unsigned long __init setup_vectors_base(void) +{ + unsigned long reg = get_cr(); + + set_cr(reg | CR_V); + return 0xffff0000; +} +#else /* CONFIG_CPU_HIGH_VECTOR */ +/* Write exception base address to VBAR */ +static inline void set_vbar(unsigned long val) +{ + asm("mcr p15, 0, %0, c12, c0, 0" : : "r" (val) : "cc"); +} + +/* + * Security extensions, bits[7:4], permitted values, + * 0b0000 - not implemented, 0b0001/0b0010 - implemented + */ +static inline bool security_extensions_enabled(void) +{ + return !!cpuid_feature_extract(CPUID_EXT_PFR1, 4); +} + +static unsigned long __init setup_vectors_base(void) +{ + unsigned long base = 0, reg = get_cr(); + + set_cr(reg & ~CR_V); + if (security_extensions_enabled()) { + if (IS_ENABLED(CONFIG_REMAP_VECTORS_TO_RAM)) + base = CONFIG_DRAM_BASE; + set_vbar(base); + } else if (IS_ENABLED(CONFIG_REMAP_VECTORS_TO_RAM)) { + if (CONFIG_DRAM_BASE != 0) + pr_err("Security extensions not enabled, vectors cannot be remapped to RAM, vectors base will be 0x00000000\n"); + } + + return base; +} +#endif /* CONFIG_CPU_HIGH_VECTOR */ +#endif /* CONFIG_CPU_CP15 */ + void __init arm_mm_memblock_reserve(void) { #ifndef CONFIG_CPU_V7M + vectors_base = IS_ENABLED(CONFIG_CPU_CP15) ? setup_vectors_base() : 0; /* * Register the exception vector page. * some architectures which the DRAM is the exception vector to trap, * alloc_page breaks with error, although it is not NULL, but "0." */ - memblock_reserve(CONFIG_VECTORS_BASE, 2 * PAGE_SIZE); + memblock_reserve(vectors_base, 2 * PAGE_SIZE); #else /* ifndef CONFIG_CPU_V7M */ /* * There is no dedicated vector page on V7-M. So nothing needs to be @@ -310,7 +358,7 @@ void __init sanity_check_meminfo(void) */ void __init paging_init(const struct machine_desc *mdesc) { - early_trap_init((void *)CONFIG_VECTORS_BASE); + early_trap_init((void *)vectors_base); mpu_setup(); bootmem_init(); }