From patchwork Tue Mar 1 14:14:35 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Evan Lloyd X-Patchwork-Id: 63307 Delivered-To: patch@linaro.org Received: by 10.112.199.169 with SMTP id jl9csp1852350lbc; Tue, 1 Mar 2016 06:14:47 -0800 (PST) X-Received: by 10.98.43.149 with SMTP id r143mr30026534pfr.7.1456841686004; Tue, 01 Mar 2016 06:14:46 -0800 (PST) Return-Path: Received: from ml01.01.org (ml01.01.org. [2001:19d0:306:5::1]) by mx.google.com with ESMTPS id 4si50772062pfo.244.2016.03.01.06.14.45 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 01 Mar 2016 06:14:45 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 2001:19d0:306:5::1 as permitted sender) client-ip=2001:19d0:306:5::1; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 2001:19d0:306:5::1 as permitted sender) smtp.mailfrom=edk2-devel-bounces@lists.01.org Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 962491A1E50; Tue, 1 Mar 2016 06:14:53 -0800 (PST) X-Original-To: edk2-devel@ml01.01.org Delivered-To: edk2-devel@ml01.01.org Received: from cam-smtp0.cambridge.arm.com (fw-tnat.cambridge.arm.com [217.140.96.140]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 7D9821A1E1C for ; Tue, 1 Mar 2016 06:14:51 -0800 (PST) Received: from E107800.Emea.Arm.com (e107800.emea.arm.com [10.1.27.28]) by cam-smtp0.cambridge.arm.com (8.13.8/8.13.8) with ESMTP id u21EEcX4030150; Tue, 1 Mar 2016 14:14:39 GMT From: evan.lloyd@arm.com To: edk2-devel@ml01.01.org Date: Tue, 1 Mar 2016 14:14:35 +0000 Message-Id: <1456841675-7928-1-git-send-email-evan.lloyd@arm.com> X-Mailer: git-send-email 2.7.0 Cc: leif.lindholm@linaro.org Subject: [edk2] [PATCH] ArmPkg: Configure TTBCR register X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.17 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" From: Evan Lloyd Architecturally, the TTBCR register value is undefined at reset for Non-Secure. On some platforms the reset value for TTBCR is not zero and this causes a data abort exception once the MMU is enabled. This patch configures the TTBCR register to enable translation table walk using TTBR0. Contributed-under: Tianocore Contribution Agreement 1.0 Signed-off-by: Evan Lloyd --- ArmPkg/Include/Library/ArmLib.h | 8 +++++++- ArmPkg/Library/ArmLib/ArmV7/ArmV7Mmu.c | 14 +++++++++++++- ArmPkg/Library/ArmLib/Common/Arm/ArmLibSupport.S | 8 +++++++- ArmPkg/Library/ArmLib/Common/Arm/ArmLibSupport.asm | 7 ++++++- 4 files changed, 33 insertions(+), 4 deletions(-) -- 2.7.0 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel diff --git a/ArmPkg/Include/Library/ArmLib.h b/ArmPkg/Include/Library/ArmLib.h index 85fa1f6..15f610d 100644 --- a/ArmPkg/Include/Library/ArmLib.h +++ b/ArmPkg/Include/Library/ArmLib.h @@ -1,7 +1,7 @@ /** @file Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.
- Copyright (c) 2011 - 2015, ARM Ltd. All rights reserved.
+ Copyright (c) 2011 - 2016, ARM Ltd. All rights reserved.
This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License @@ -353,6 +353,12 @@ ArmSetTTBR0 ( IN VOID *TranslationTableBase ); +VOID +EFIAPI +ArmSetTTBCR ( + IN UINT32 Bits + ); + VOID * EFIAPI ArmGetTTBR0BaseAddress ( diff --git a/ArmPkg/Library/ArmLib/ArmV7/ArmV7Mmu.c b/ArmPkg/Library/ArmLib/ArmV7/ArmV7Mmu.c index fc8ea42..8cc33e3 100644 --- a/ArmPkg/Library/ArmLib/ArmV7/ArmV7Mmu.c +++ b/ArmPkg/Library/ArmLib/ArmV7/ArmV7Mmu.c @@ -1,7 +1,7 @@ /** @file * File managing the MMU for ARMv7 architecture * -* Copyright (c) 2011-2013, ARM Limited. All rights reserved. +* Copyright (c) 2011-2016, ARM Limited. All rights reserved. * * This program and the accompanying materials * are licensed and made available under the terms and conditions of the BSD License @@ -347,6 +347,18 @@ ArmConfigureMmu ( ArmSetTTBR0 ((VOID *)(UINTN)(((UINTN)TranslationTable & ~TRANSLATION_TABLE_SECTION_ALIGNMENT_MASK) | (TTBRAttributes & 0x7F))); + // + // The TTBCR register value is undefined at reset in the Non-Secure world. + // Writing 0 has the effect of: + // Clearing EAE: Important because current page table set up code does not + // support Extended Addressing, so only uses short descriptors. + // Clearing PD0 and PD1: Prevents translation faults from non-secure page + // lookups. + // Clearing N: 0 is the default reset value, and is again compatible with + // current page table set up. + // + ArmSetTTBCR (0); + ArmSetDomainAccessControl (DOMAIN_ACCESS_CONTROL_NONE(15) | DOMAIN_ACCESS_CONTROL_NONE(14) | DOMAIN_ACCESS_CONTROL_NONE(13) | diff --git a/ArmPkg/Library/ArmLib/Common/Arm/ArmLibSupport.S b/ArmPkg/Library/ArmLib/Common/Arm/ArmLibSupport.S index 085f08b..5d1194e 100644 --- a/ArmPkg/Library/ArmLib/Common/Arm/ArmLibSupport.S +++ b/ArmPkg/Library/ArmLib/Common/Arm/ArmLibSupport.S @@ -1,7 +1,7 @@ #------------------------------------------------------------------------------ # # Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.
-# Copyright (c) 2011 - 2014, ARM Limited. All rights reserved. +# Copyright (c) 2011 - 2016, ARM Limited. All rights reserved. # # This program and the accompanying materials # are licensed and made available under the terms and conditions of the BSD License @@ -23,6 +23,7 @@ GCC_ASM_EXPORT(ArmGetInterruptState) GCC_ASM_EXPORT(ArmGetFiqState) GCC_ASM_EXPORT(ArmGetTTBR0BaseAddress) GCC_ASM_EXPORT(ArmSetTTBR0) +GCC_ASM_EXPORT(ArmSetTTBCR) GCC_ASM_EXPORT(ArmSetDomainAccessControl) GCC_ASM_EXPORT(CPSRMaskInsert) GCC_ASM_EXPORT(CPSRRead) @@ -111,6 +112,11 @@ ASM_PFX(ArmSetTTBR0): isb bx lr +ASM_PFX(ArmSetTTBCR): + mcr p15, 0, r0, c2, c0, 2 + isb + bx lr + ASM_PFX(ArmGetTTBR0BaseAddress): mrc p15,0,r0,c2,c0,0 LoadConstantToReg(0xFFFFC000, r1) diff --git a/ArmPkg/Library/ArmLib/Common/Arm/ArmLibSupport.asm b/ArmPkg/Library/ArmLib/Common/Arm/ArmLibSupport.asm index 228d7c8..9b87b7f 100644 --- a/ArmPkg/Library/ArmLib/Common/Arm/ArmLibSupport.asm +++ b/ArmPkg/Library/ArmLib/Common/Arm/ArmLibSupport.asm @@ -1,7 +1,7 @@ //------------------------------------------------------------------------------ // // Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.
-// Copyright (c) 2011 - 2014, ARM Limited. All rights reserved. +// Copyright (c) 2011 - 2016, ARM Limited. All rights reserved. // // This program and the accompanying materials // are licensed and made available under the terms and conditions of the BSD License @@ -85,6 +85,11 @@ isb bx lr + RVCT_ASM_EXPORT ArmSetTTBCR + mcr p15, 0, r0, c2, c0, 2 + isb + bx lr + RVCT_ASM_EXPORT ArmGetTTBR0BaseAddress mrc p15,0,r0,c2,c0,0 LoadConstantToReg(0xFFFFC000, r1)