Thanks,
drew
diff --git a/lib/arm/asm/mmu-api.h b/lib/arm/asm/mmu-api.h
index 3d04d0312622..05fc12b5afb8 100644
--- a/lib/arm/asm/mmu-api.h
+++ b/lib/arm/asm/mmu-api.h
@@ -5,12 +5,7 @@
#include <stdbool.h>
extern pgd_t *mmu_idmap;
-extern unsigned int mmu_disabled_cpu_count;
-extern bool __mmu_enabled(void);
-static inline bool mmu_enabled(void)
-{
- return mmu_disabled_cpu_count == 0 || __mmu_enabled();
-}
+extern bool mmu_enabled(void);
extern void mmu_mark_enabled(int cpu);
extern void mmu_mark_disabled(int cpu);
extern void mmu_enable(pgd_t *pgtable);
diff --git a/lib/arm/asm/processor.h b/lib/arm/asm/processor.h
index 273366d1fe1c..6b762ad060eb 100644
--- a/lib/arm/asm/processor.h
+++ b/lib/arm/asm/processor.h
@@ -67,11 +67,13 @@ extern int mpidr_to_cpu(uint64_t mpidr);
((mpidr >> MPIDR_LEVEL_SHIFT(level)) & 0xff)
extern void start_usr(void (*func)(void *arg), void *arg, unsigned long sp_usr);
+extern bool __mmu_enabled(void);
extern bool is_user(void);
#define CNTVCT __ACCESS_CP15_64(1, c14)
#define CNTFRQ __ACCESS_CP15(c14, 0, c0, 0)
#define CTR __ACCESS_CP15(c0, 0, c0, 1)
+#define SCTRL __ACCESS_CP15(c1, 0, c0, 0)
static inline u64 get_cntvct(void)
{
diff --git a/lib/arm/mmu.c b/lib/arm/mmu.c
index a1862a55db8b..15eef007f256 100644
--- a/lib/arm/mmu.c
+++ b/lib/arm/mmu.c
@@ -24,13 +24,10 @@ extern unsigned long etext;
pgd_t *mmu_idmap;
/* CPU 0 starts with disabled MMU */
-static cpumask_t mmu_disabled_cpumask = { {1} };
-unsigned int mmu_disabled_cpu_count = 1;
+static cpumask_t mmu_enabled_cpumask;
-bool __mmu_enabled(void)
+bool mmu_enabled(void)
{
- int cpu = current_thread_info()->cpu;
-
/*
* mmu_enabled is called from places that are guarding the
* use of exclusive ops (which require the mmu to be enabled).
@@ -38,19 +35,22 @@ bool __mmu_enabled(void)
* spinlock, atomic bitop, etc., otherwise we'll recurse.
* [cpumask_]test_bit is safe though.
*/
- return !cpumask_test_cpu(cpu, &mmu_disabled_cpumask);
+ if (is_user()) {
+ int cpu = current_thread_info()->cpu;
+ return cpumask_test_cpu(cpu, &mmu_enabled_cpumask);
+ }
+
+ return __mmu_enabled();
}
void mmu_mark_enabled(int cpu)
{
- if (cpumask_test_and_clear_cpu(cpu, &mmu_disabled_cpumask))
- --mmu_disabled_cpu_count;
+ cpumask_set_cpu(cpu, &mmu_enabled_cpumask);
}
void mmu_mark_disabled(int cpu)
{
- if (!cpumask_test_and_set_cpu(cpu, &mmu_disabled_cpumask))
- ++mmu_disabled_cpu_count;
+ cpumask_clear_cpu(cpu, &mmu_enabled_cpumask);
}
extern void asm_mmu_enable(phys_addr_t pgtable);
diff --git a/lib/arm/processor.c b/lib/arm/processor.c
index 773337e6d3b7..9d5759686b73 100644
--- a/lib/arm/processor.c
+++ b/lib/arm/processor.c
@@ -145,3 +145,8 @@ bool is_user(void)
{
return current_thread_info()->flags & TIF_USER_MODE;
}
+
+bool __mmu_enabled(void)
+{
+ return read_sysreg(SCTRL) & CR_M;
+}
diff --git a/lib/arm64/asm/processor.h b/lib/arm64/asm/processor.h
index 771b2d1e0c94..8e2037e1a43e 100644
--- a/lib/arm64/asm/processor.h
+++ b/lib/arm64/asm/processor.h
@@ -98,6 +98,7 @@ extern int mpidr_to_cpu(uint64_t mpidr);
extern void start_usr(void (*func)(void *arg), void *arg, unsigned long sp_usr);
extern bool is_user(void);
+extern bool __mmu_enabled(void);
static inline u64 get_cntvct(void)
{
diff --git a/lib/arm64/processor.c b/lib/arm64/processor.c
index 2a024e3f4e9d..ef558625e284 100644
--- a/lib/arm64/processor.c
+++ b/lib/arm64/processor.c
@@ -257,3 +257,8 @@ bool is_user(void)
{
return current_thread_info()->flags & TIF_USER_MODE;
}
+
+bool __mmu_enabled(void)
+{
+ return read_sysreg(sctlr_el1) & SCTLR_EL1_M;
+}