summaryrefslogtreecommitdiffstats
path: root/arch/arm/cpu
diff options
context:
space:
mode:
authorAndrey Smirnov <andrew.smirnov@gmail.com>2019-01-17 16:38:25 -0800
committerSascha Hauer <s.hauer@pengutronix.de>2019-01-21 10:34:06 +0100
commit7aeebcb3ba069bf9c8bb699630928ee84ba60bc4 (patch)
tree45e2cb47299d7d5b371a5bf476c955f2c7530efc /arch/arm/cpu
parentf6cfdf9288238ce61b9103cbeb9c63275b39b69f (diff)
downloadbarebox-7aeebcb3ba069bf9c8bb699630928ee84ba60bc4.tar.gz
barebox-7aeebcb3ba069bf9c8bb699630928ee84ba60bc4.tar.xz
ARM: mmu: Share sanity checking code in mmu_init()
Share sanity checking code in mmu_init() as well as code to detect if MMU is on or not on both ARM and ARM64. Reviewed-by: Sam Ravnborg <sam@ravnborg.org> Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'arch/arm/cpu')
-rw-r--r--arch/arm/cpu/mmu-common.c23
-rw-r--r--arch/arm/cpu/mmu-common.h1
-rw-r--r--arch/arm/cpu/mmu.c16
-rw-r--r--arch/arm/cpu/mmu_64.c16
4 files changed, 26 insertions, 30 deletions
diff --git a/arch/arm/cpu/mmu-common.c b/arch/arm/cpu/mmu-common.c
index a7d3b5b112..c5b24bff8e 100644
--- a/arch/arm/cpu/mmu-common.c
+++ b/arch/arm/cpu/mmu-common.c
@@ -2,10 +2,12 @@
#define pr_fmt(fmt) "mmu: " fmt
#include <common.h>
+#include <init.h>
#include <dma-dir.h>
#include <dma.h>
#include <mmu.h>
-
+#include <asm/system.h>
+#include <memory.h>
#include "mmu.h"
@@ -59,4 +61,21 @@ void dma_free_coherent(void *mem, dma_addr_t dma_handle, size_t size)
arch_remap_range(mem, size, MAP_CACHED);
free(mem);
-} \ No newline at end of file
+}
+
+static int mmu_init(void)
+{
+ if (list_empty(&memory_banks))
+ /*
+ * If you see this it means you have no memory registered.
+ * This can be done either with arm_add_mem_device() in an
+ * initcall prior to mmu_initcall or via devicetree in the
+ * memory node.
+ */
+ panic("MMU: No memory bank found! Cannot continue\n");
+
+ __mmu_init(get_cr() & CR_M);
+
+ return 0;
+}
+mmu_initcall(mmu_init); \ No newline at end of file
diff --git a/arch/arm/cpu/mmu-common.h b/arch/arm/cpu/mmu-common.h
index e8689ac310..37eef3ef28 100644
--- a/arch/arm/cpu/mmu-common.h
+++ b/arch/arm/cpu/mmu-common.h
@@ -3,5 +3,6 @@
void dma_inv_range(void *ptr, size_t size);
void *dma_alloc_map(size_t size, dma_addr_t *dma_handle, unsigned flags);
+void __mmu_init(bool mmu_on);
#endif \ No newline at end of file
diff --git a/arch/arm/cpu/mmu.c b/arch/arm/cpu/mmu.c
index 97c459ff0c..ba1c3e007d 100644
--- a/arch/arm/cpu/mmu.c
+++ b/arch/arm/cpu/mmu.c
@@ -412,19 +412,10 @@ static void vectors_init(void)
/*
* Prepare MMU for usage enable it.
*/
-static int mmu_init(void)
+void __mmu_init(bool mmu_on)
{
struct memory_bank *bank;
- if (list_empty(&memory_banks))
- /*
- * If you see this it means you have no memory registered.
- * This can be done either with arm_add_mem_device() in an
- * initcall prior to mmu_initcall or via devicetree in the
- * memory node.
- */
- panic("MMU: No memory bank found! Cannot continue\n");
-
arm_set_cache_functions();
if (cpu_architecture() >= CPU_ARCH_ARMv7) {
@@ -439,7 +430,7 @@ static int mmu_init(void)
pte_flags_uncached = PTE_FLAGS_UNCACHED_V4;
}
- if (get_cr() & CR_M) {
+ if (mmu_on) {
/*
* Early MMU code has already enabled the MMU. We assume a
* flat 1:1 section mapping in this case.
@@ -483,10 +474,7 @@ static int mmu_init(void)
}
__mmu_cache_on();
-
- return 0;
}
-mmu_initcall(mmu_init);
/*
* Clean and invalide caches, disable MMU
diff --git a/arch/arm/cpu/mmu_64.c b/arch/arm/cpu/mmu_64.c
index 2cb62370e9..7f8a8f249b 100644
--- a/arch/arm/cpu/mmu_64.c
+++ b/arch/arm/cpu/mmu_64.c
@@ -194,21 +194,12 @@ static void mmu_enable(void)
/*
* Prepare MMU for usage enable it.
*/
-static int mmu_init(void)
+void __mmu_init(bool mmu_on)
{
struct memory_bank *bank;
unsigned int el;
- if (list_empty(&memory_banks))
- /*
- * If you see this it means you have no memory registered.
- * This can be done either with arm_add_mem_device() in an
- * initcall prior to mmu_initcall or via devicetree in the
- * memory node.
- */
- panic("MMU: No memory bank found! Cannot continue\n");
-
- if (get_cr() & CR_M)
+ if (mmu_on)
mmu_disable();
ttb = create_table();
@@ -228,10 +219,7 @@ static int mmu_init(void)
create_sections(0x0, 0x0, 0x1000, 0x0);
mmu_enable();
-
- return 0;
}
-mmu_initcall(mmu_init);
void mmu_disable(void)
{