summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGiorgio Dal Molin <giorgio.nicole@arcor.de>2020-04-07 17:31:11 +0200
committerSascha Hauer <s.hauer@pengutronix.de>2020-04-14 12:03:24 +0200
commitb1d30239ccde137bcd998437ef96d4af3a696415 (patch)
tree62fd0b0f35916e8f8724634b458ebc2075e86922
parent41594beb02d714e2641c70d36a442b1c1e1964e3 (diff)
downloadbarebox-b1d30239ccde137bcd998437ef96d4af3a696415.tar.gz
ARM: i.MX: fixed enabling the MMU after switching in non secure mode.
The Domain Access Control Register (DACR) in CP15 is banked between secure and non secure mode: there a copy of the reg. in secure mode and a second copy in non secure mode. As barebox boots on the imx7 SOC it runs in secure mode and initializes the secure-mode copy of DACR (with 0x00000001). After switching to non secure mode, for example with the command 'smc -n' or while booting a kernel image with global.bootm.secure_state=nonsecure, the active value of DACR is the copy in non-secure mode and that copy was still uninitialized and in an UNKNOWN state. This caused the cpu to hang as soon as the MMU was enabled in non-secure mode. We fix this by reading the DACR value in secure mode just before switching to non secure and then initializing it again with the same value. Signed-off-by: Giorgio Dal Molin <giorgio.nicole@arcor.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
-rw-r--r--arch/arm/cpu/mmu.h9
-rw-r--r--arch/arm/cpu/sm.c4
2 files changed, 12 insertions, 1 deletions
diff --git a/arch/arm/cpu/mmu.h b/arch/arm/cpu/mmu.h
index 6e7a4c0..c85e0ea 100644
--- a/arch/arm/cpu/mmu.h
+++ b/arch/arm/cpu/mmu.h
@@ -39,6 +39,15 @@ static inline void set_ttbr(void *ttb)
#define DOMAIN_CLIENT 1
#define DOMAIN_MANAGER 3
+static inline unsigned long get_domain(void)
+{
+ unsigned long dacr;
+
+ asm volatile ("mrc p15, 0, %0, c3, c0, 0" : "=r"(dacr));
+
+ return dacr;
+}
+
static inline void set_domain(unsigned val)
{
/* Set the Domain Access Control Register */
diff --git a/arch/arm/cpu/sm.c b/arch/arm/cpu/sm.c
index 1f2c236..cb33d96 100644
--- a/arch/arm/cpu/sm.c
+++ b/arch/arm/cpu/sm.c
@@ -150,7 +150,7 @@ static bool armv7_have_security_extensions(void)
int armv7_secure_monitor_install(void)
{
int mmuon;
- unsigned long ttb, vbar;
+ unsigned long ttb, vbar, dacr;
if (!armv7_have_security_extensions()) {
pr_err("Security extensions not implemented.\n");
@@ -164,12 +164,14 @@ int armv7_secure_monitor_install(void)
vbar = get_vbar();
ttb = get_ttbr();
+ dacr = get_domain();
armv7_init_nonsec();
__armv7_secure_monitor_install();
set_ttbr((void *)ttb);
set_vbar(vbar);
+ set_domain(dacr);
if (mmuon) {
/*