From: Andrey Smirnov <andrew.smirnov@gmail.com>
To: barebox@lists.infradead.org
Cc: Andrey Smirnov <andrew.smirnov@gmail.com>
Subject: [PATCH 10/12] ARM: mmu: Share sanity checking code in mmu_init()
Date: Wed, 16 Jan 2019 22:38:38 -0800 [thread overview]
Message-ID: <20190117063840.13674-11-andrew.smirnov@gmail.com> (raw)
In-Reply-To: <20190117063840.13674-1-andrew.smirnov@gmail.com>
Share sanity checking code in mmu_init() as well as code to detect if
MMU is on or not on both ARM and ARM64.
Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
---
arch/arm/cpu/mmu-common.c | 23 +++++++++++++++++++++--
arch/arm/cpu/mmu-common.h | 1 +
arch/arm/cpu/mmu.c | 16 ++--------------
arch/arm/cpu/mmu_64.c | 16 ++--------------
4 files changed, 26 insertions(+), 30 deletions(-)
diff --git a/arch/arm/cpu/mmu-common.c b/arch/arm/cpu/mmu-common.c
index a7d3b5b11..c5b24bff8 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 e8689ac31..37eef3ef2 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 97c459ff0..ba1c3e007 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 2cb62370e..7f8a8f249 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)
{
--
2.20.1
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
next prev parent reply other threads:[~2019-01-17 6:39 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-01-17 6:38 [PATCH 00/12] ARM/ARM64 MMU code consolidation, zeroing of DMA coherent memory Andrey Smirnov
2019-01-17 6:38 ` [PATCH 01/12] ARM: mmu: Drop custom virt_to_phys/phys_to_virt Andrey Smirnov
2019-01-17 6:38 ` [PATCH 02/12] ARM: mmu: Simplify the use of dma_inv_range() Andrey Smirnov
2019-01-17 6:38 ` [PATCH 03/12] ARM: mmu: Share code for dma_(un)map_single() Andrey Smirnov
2019-01-17 6:38 ` [PATCH 04/12] ARM64: mmu: Use arch_remap_range() internaly Andrey Smirnov
2019-01-17 6:38 ` [PATCH 05/12] ARM64: mmu: Merge create_sections() and map_region() together Andrey Smirnov
2019-01-17 6:38 ` [PATCH 06/12] ARM: mmu: Share code for dma_free_coherent() Andrey Smirnov
2019-01-17 6:38 ` [PATCH 07/12] ARM64: mmu: Invalidate memory before remapping as DMA coherent Andrey Smirnov
2019-01-17 6:38 ` [PATCH 08/12] ARM: mmu: Share code for dma_alloc_coherent() Andrey Smirnov
2019-01-17 21:23 ` Sam Ravnborg
2019-01-17 21:54 ` Andrey Smirnov
2019-01-17 22:06 ` Sam Ravnborg
2019-01-17 6:38 ` [PATCH 09/12] ARM: mmu: Share code for dma_sync_single_for_cpu() Andrey Smirnov
2019-01-17 21:28 ` Sam Ravnborg
2019-01-17 21:50 ` Andrey Smirnov
2019-01-17 22:04 ` Sam Ravnborg
2019-01-17 6:38 ` Andrey Smirnov [this message]
2019-01-17 6:38 ` [PATCH 11/12] ARM: mmu: Share code for arm_mmu_not_initialized_error() Andrey Smirnov
2019-01-17 6:38 ` [PATCH 12/12] ARM: mmu: Make sure DMA coherent memory is zeroed out Andrey Smirnov
2019-01-17 21:36 ` Sam Ravnborg
2019-01-17 22:00 ` Andrey Smirnov
2019-01-17 22:11 ` Sam Ravnborg
2019-01-17 21:40 ` [PATCH 00/12] ARM/ARM64 MMU code consolidation, zeroing of DMA coherent memory Sam Ravnborg
2019-01-17 22:01 ` Andrey Smirnov
2019-01-17 22:06 ` Sam Ravnborg
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190117063840.13674-11-andrew.smirnov@gmail.com \
--to=andrew.smirnov@gmail.com \
--cc=barebox@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox