* [PATCH v4 01/29] ARM: mmu: Remove unused ARM_VECTORS_SIZE
2018-05-22 3:14 [PATCH v4 00/29] ARM MMU code improvements and on-demand PTE allocation Andrey Smirnov
@ 2018-05-22 3:14 ` Andrey Smirnov
2018-05-22 3:14 ` [PATCH v4 02/29] ARM: mmu: Make use of IS_ALIGNED in arm_mmu_remap_sdram() Andrey Smirnov
` (28 subsequent siblings)
29 siblings, 0 replies; 32+ messages in thread
From: Andrey Smirnov @ 2018-05-22 3:14 UTC (permalink / raw)
To: barebox; +Cc: Andrey Smirnov
Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
---
arch/arm/cpu/mmu.c | 6 ------
1 file changed, 6 deletions(-)
diff --git a/arch/arm/cpu/mmu.c b/arch/arm/cpu/mmu.c
index 6ccd5893b..9472013ca 100644
--- a/arch/arm/cpu/mmu.c
+++ b/arch/arm/cpu/mmu.c
@@ -270,12 +270,6 @@ static int arm_mmu_remap_sdram(struct memory_bank *bank)
return 0;
}
-/*
- * We have 8 exception vectors and the table consists of absolute
- * jumps, so we need 8 * 4 bytes for the instructions and another
- * 8 * 4 bytes for the addresses.
- */
-#define ARM_VECTORS_SIZE (sizeof(u32) * 8 * 2)
#define ARM_HIGH_VECTORS 0xffff0000
#define ARM_LOW_VECTORS 0x0
--
2.17.0
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 32+ messages in thread
* [PATCH v4 02/29] ARM: mmu: Make use of IS_ALIGNED in arm_mmu_remap_sdram()
2018-05-22 3:14 [PATCH v4 00/29] ARM MMU code improvements and on-demand PTE allocation Andrey Smirnov
2018-05-22 3:14 ` [PATCH v4 01/29] ARM: mmu: Remove unused ARM_VECTORS_SIZE Andrey Smirnov
@ 2018-05-22 3:14 ` Andrey Smirnov
2018-05-22 3:14 ` [PATCH v4 03/29] ARM: mmu: Use ALIGN and ALIGN_DOWN in map_cachable() Andrey Smirnov
` (27 subsequent siblings)
29 siblings, 0 replies; 32+ messages in thread
From: Andrey Smirnov @ 2018-05-22 3:14 UTC (permalink / raw)
To: barebox; +Cc: Andrey Smirnov
Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
---
arch/arm/cpu/mmu.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/arch/arm/cpu/mmu.c b/arch/arm/cpu/mmu.c
index 9472013ca..c70e9e782 100644
--- a/arch/arm/cpu/mmu.c
+++ b/arch/arm/cpu/mmu.c
@@ -241,7 +241,7 @@ static int arm_mmu_remap_sdram(struct memory_bank *bank)
* We replace each 1MiB section in this range with second level page
* tables, therefore we must have 1Mib aligment here.
*/
- if ((phys & (SZ_1M - 1)) || (bank->size & (SZ_1M - 1)))
+ if (!IS_ALIGNED(phys, SZ_1M) || !IS_ALIGNED(bank->size, SZ_1M))
return -EINVAL;
ptes = xmemalign(PAGE_SIZE, num_ptes * sizeof(u32));
--
2.17.0
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 32+ messages in thread
* [PATCH v4 03/29] ARM: mmu: Use ALIGN and ALIGN_DOWN in map_cachable()
2018-05-22 3:14 [PATCH v4 00/29] ARM MMU code improvements and on-demand PTE allocation Andrey Smirnov
2018-05-22 3:14 ` [PATCH v4 01/29] ARM: mmu: Remove unused ARM_VECTORS_SIZE Andrey Smirnov
2018-05-22 3:14 ` [PATCH v4 02/29] ARM: mmu: Make use of IS_ALIGNED in arm_mmu_remap_sdram() Andrey Smirnov
@ 2018-05-22 3:14 ` Andrey Smirnov
2018-05-22 3:14 ` [PATCH v4 04/29] ARM: mmu: Introduce set_ttbr() Andrey Smirnov
` (26 subsequent siblings)
29 siblings, 0 replies; 32+ messages in thread
From: Andrey Smirnov @ 2018-05-22 3:14 UTC (permalink / raw)
To: barebox; +Cc: Andrey Smirnov
Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
---
arch/arm/cpu/mmu-early.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/arch/arm/cpu/mmu-early.c b/arch/arm/cpu/mmu-early.c
index 70cb5fe31..fc14d5cac 100644
--- a/arch/arm/cpu/mmu-early.c
+++ b/arch/arm/cpu/mmu-early.c
@@ -23,8 +23,8 @@ static void create_sections(unsigned long addr, int size_m, unsigned int flags)
static void map_cachable(unsigned long start, unsigned long size)
{
- start &= ~(SZ_1M - 1);
- size = (size + (SZ_1M - 1)) & ~(SZ_1M - 1);
+ start = ALIGN_DOWN(start, SZ_1M);
+ size = ALIGN(size, SZ_1M);
create_sections(start, size >> 20, PMD_SECT_AP_WRITE |
PMD_SECT_AP_READ | PMD_TYPE_SECT | PMD_SECT_WB);
--
2.17.0
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 32+ messages in thread
* [PATCH v4 04/29] ARM: mmu: Introduce set_ttbr()
2018-05-22 3:14 [PATCH v4 00/29] ARM MMU code improvements and on-demand PTE allocation Andrey Smirnov
` (2 preceding siblings ...)
2018-05-22 3:14 ` [PATCH v4 03/29] ARM: mmu: Use ALIGN and ALIGN_DOWN in map_cachable() Andrey Smirnov
@ 2018-05-22 3:14 ` Andrey Smirnov
2018-05-22 3:14 ` [PATCH v4 05/29] ARM: mmu: Introduce set_domain() Andrey Smirnov
` (25 subsequent siblings)
29 siblings, 0 replies; 32+ messages in thread
From: Andrey Smirnov @ 2018-05-22 3:14 UTC (permalink / raw)
To: barebox; +Cc: Andrey Smirnov
Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
---
arch/arm/cpu/mmu-early.c | 3 +--
arch/arm/cpu/mmu.c | 3 +--
arch/arm/cpu/mmu.h | 5 +++++
3 files changed, 7 insertions(+), 4 deletions(-)
diff --git a/arch/arm/cpu/mmu-early.c b/arch/arm/cpu/mmu-early.c
index fc14d5cac..79fc3080a 100644
--- a/arch/arm/cpu/mmu-early.c
+++ b/arch/arm/cpu/mmu-early.c
@@ -39,8 +39,7 @@ void mmu_early_enable(unsigned long membase, unsigned long memsize,
arm_set_cache_functions();
- /* Set the ttb register */
- asm volatile ("mcr p15,0,%0,c2,c0,0" : : "r"(ttb) /*:*/);
+ set_ttbr(ttb);
/* Set the Domain Access Control Register */
i = 0x3;
diff --git a/arch/arm/cpu/mmu.c b/arch/arm/cpu/mmu.c
index c70e9e782..28732b795 100644
--- a/arch/arm/cpu/mmu.c
+++ b/arch/arm/cpu/mmu.c
@@ -471,8 +471,7 @@ static int mmu_init(void)
pr_debug("ttb: 0x%p\n", ttb);
- /* Set the ttb register */
- asm volatile ("mcr p15,0,%0,c2,c0,0" : : "r"(ttb) /*:*/);
+ set_ttbr(ttb);
/* Set the Domain Access Control Register */
i = 0x3;
diff --git a/arch/arm/cpu/mmu.h b/arch/arm/cpu/mmu.h
index 79ebc80d7..5dcf4b53a 100644
--- a/arch/arm/cpu/mmu.h
+++ b/arch/arm/cpu/mmu.h
@@ -11,4 +11,9 @@ static inline void __mmu_cache_off(void) {}
static inline void __mmu_cache_flush(void) {}
#endif
+static inline void set_ttbr(void *ttb)
+{
+ asm volatile ("mcr p15,0,%0,c2,c0,0" : : "r"(ttb) /*:*/);
+}
+
#endif /* __ARM_MMU_H */
--
2.17.0
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 32+ messages in thread
* [PATCH v4 05/29] ARM: mmu: Introduce set_domain()
2018-05-22 3:14 [PATCH v4 00/29] ARM MMU code improvements and on-demand PTE allocation Andrey Smirnov
` (3 preceding siblings ...)
2018-05-22 3:14 ` [PATCH v4 04/29] ARM: mmu: Introduce set_ttbr() Andrey Smirnov
@ 2018-05-22 3:14 ` Andrey Smirnov
2018-05-22 3:14 ` [PATCH v4 06/29] ARM: mmu: Share code for create_sections() Andrey Smirnov
` (24 subsequent siblings)
29 siblings, 0 replies; 32+ messages in thread
From: Andrey Smirnov @ 2018-05-22 3:14 UTC (permalink / raw)
To: barebox; +Cc: Andrey Smirnov
Port set_domain() form Linux kernel and share it between regular and
early MMU code to avoid duplication.
Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
---
arch/arm/cpu/mmu-early.c | 7 +------
arch/arm/cpu/mmu.c | 6 +-----
arch/arm/cpu/mmu.h | 9 +++++++++
3 files changed, 11 insertions(+), 11 deletions(-)
diff --git a/arch/arm/cpu/mmu-early.c b/arch/arm/cpu/mmu-early.c
index 79fc3080a..f75cc7e4a 100644
--- a/arch/arm/cpu/mmu-early.c
+++ b/arch/arm/cpu/mmu-early.c
@@ -33,17 +33,12 @@ static void map_cachable(unsigned long start, unsigned long size)
void mmu_early_enable(unsigned long membase, unsigned long memsize,
unsigned long _ttb)
{
- int i;
-
ttb = (uint32_t *)_ttb;
arm_set_cache_functions();
set_ttbr(ttb);
-
- /* Set the Domain Access Control Register */
- i = 0x3;
- asm volatile ("mcr p15,0,%0,c3,c0,0" : : "r"(i) /*:*/);
+ set_domain(DOMAIN_MANAGER);
create_sections(0, 4096, PMD_SECT_AP_WRITE |
PMD_SECT_AP_READ | PMD_TYPE_SECT);
diff --git a/arch/arm/cpu/mmu.c b/arch/arm/cpu/mmu.c
index 28732b795..7e087d08f 100644
--- a/arch/arm/cpu/mmu.c
+++ b/arch/arm/cpu/mmu.c
@@ -422,7 +422,6 @@ static void vectors_init(void)
static int mmu_init(void)
{
struct memory_bank *bank;
- int i;
if (list_empty(&memory_banks))
/*
@@ -472,10 +471,7 @@ static int mmu_init(void)
pr_debug("ttb: 0x%p\n", ttb);
set_ttbr(ttb);
-
- /* Set the Domain Access Control Register */
- i = 0x3;
- asm volatile ("mcr p15,0,%0,c3,c0,0" : : "r"(i) /*:*/);
+ set_domain(DOMAIN_MANAGER);
/* create a flat mapping using 1MiB sections */
create_sections(0, 0, PAGE_SIZE, PMD_SECT_AP_WRITE | PMD_SECT_AP_READ |
diff --git a/arch/arm/cpu/mmu.h b/arch/arm/cpu/mmu.h
index 5dcf4b53a..e71ff8e9a 100644
--- a/arch/arm/cpu/mmu.h
+++ b/arch/arm/cpu/mmu.h
@@ -16,4 +16,13 @@ static inline void set_ttbr(void *ttb)
asm volatile ("mcr p15,0,%0,c2,c0,0" : : "r"(ttb) /*:*/);
}
+#define DOMAIN_MANAGER 3
+
+static inline void set_domain(unsigned val)
+{
+ /* Set the Domain Access Control Register */
+ asm volatile ("mcr p15,0,%0,c3,c0,0" : : "r"(val) /*:*/);
+}
+
+
#endif /* __ARM_MMU_H */
--
2.17.0
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 32+ messages in thread
* [PATCH v4 06/29] ARM: mmu: Share code for create_sections()
2018-05-22 3:14 [PATCH v4 00/29] ARM MMU code improvements and on-demand PTE allocation Andrey Smirnov
` (4 preceding siblings ...)
2018-05-22 3:14 ` [PATCH v4 05/29] ARM: mmu: Introduce set_domain() Andrey Smirnov
@ 2018-05-22 3:14 ` Andrey Smirnov
2018-05-22 3:14 ` [PATCH v4 07/29] ARM: mmu: Separate index and address in create_sections() Andrey Smirnov
` (23 subsequent siblings)
29 siblings, 0 replies; 32+ messages in thread
From: Andrey Smirnov @ 2018-05-22 3:14 UTC (permalink / raw)
To: barebox; +Cc: Andrey Smirnov
Regular MMU code never creates anything but 1:1 mapping, and barring
that plus the call to __mmu_cache_flush(), early MMU code version of
the function is pretty much identical. To avoid code duplication, move
it to mmu.h and convert both regular and early MMU code to use it.
Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
---
arch/arm/cpu/mmu-early.c | 14 ++------------
arch/arm/cpu/mmu.c | 27 ++++++++-------------------
arch/arm/cpu/mmu.h | 10 ++++++++++
3 files changed, 20 insertions(+), 31 deletions(-)
diff --git a/arch/arm/cpu/mmu-early.c b/arch/arm/cpu/mmu-early.c
index f75cc7e4a..70ece0d2f 100644
--- a/arch/arm/cpu/mmu-early.c
+++ b/arch/arm/cpu/mmu-early.c
@@ -11,22 +11,12 @@
static uint32_t *ttb;
-static void create_sections(unsigned long addr, int size_m, unsigned int flags)
-{
- int i;
-
- addr >>= 20;
-
- for (i = size_m; i > 0; i--, addr++)
- ttb[addr] = (addr << 20) | flags;
-}
-
static void map_cachable(unsigned long start, unsigned long size)
{
start = ALIGN_DOWN(start, SZ_1M);
size = ALIGN(size, SZ_1M);
- create_sections(start, size >> 20, PMD_SECT_AP_WRITE |
+ create_sections(ttb, start, size >> 20, PMD_SECT_AP_WRITE |
PMD_SECT_AP_READ | PMD_TYPE_SECT | PMD_SECT_WB);
}
@@ -40,7 +30,7 @@ void mmu_early_enable(unsigned long membase, unsigned long memsize,
set_ttbr(ttb);
set_domain(DOMAIN_MANAGER);
- create_sections(0, 4096, PMD_SECT_AP_WRITE |
+ create_sections(ttb, 0, 4096, PMD_SECT_AP_WRITE |
PMD_SECT_AP_READ | PMD_TYPE_SECT);
map_cachable(membase, memsize);
diff --git a/arch/arm/cpu/mmu.c b/arch/arm/cpu/mmu.c
index 7e087d08f..2289a19c5 100644
--- a/arch/arm/cpu/mmu.c
+++ b/arch/arm/cpu/mmu.c
@@ -37,21 +37,7 @@
#define PMD_SECT_DEF_UNCACHED (PMD_SECT_AP_WRITE | PMD_SECT_AP_READ | PMD_TYPE_SECT)
#define PMD_SECT_DEF_CACHED (PMD_SECT_WB | PMD_SECT_DEF_UNCACHED)
-static unsigned long *ttb;
-
-static void create_sections(unsigned long virt, unsigned long phys, int size_m,
- unsigned int flags)
-{
- int i;
-
- phys >>= 20;
- virt >>= 20;
-
- for (i = size_m; i > 0; i--, virt++, phys++)
- ttb[virt] = (phys << 20) | flags;
-
- __mmu_cache_flush();
-}
+static uint32_t *ttb;
/*
* Do it the simple way for now and invalidate the entire
@@ -452,7 +438,7 @@ static int mmu_init(void)
asm volatile ("mrc p15,0,%0,c2,c0,0" : "=r"(ttb));
/* Clear unpredictable bits [13:0] */
- ttb = (unsigned long *)((unsigned long)ttb & ~0x3fff);
+ ttb = (uint32_t *)((unsigned long)ttb & ~0x3fff);
if (!request_sdram_region("ttb", (unsigned long)ttb, SZ_16K))
/*
@@ -474,8 +460,9 @@ static int mmu_init(void)
set_domain(DOMAIN_MANAGER);
/* create a flat mapping using 1MiB sections */
- create_sections(0, 0, PAGE_SIZE, PMD_SECT_AP_WRITE | PMD_SECT_AP_READ |
+ create_sections(ttb, 0, PAGE_SIZE, PMD_SECT_AP_WRITE | PMD_SECT_AP_READ |
PMD_TYPE_SECT);
+ __mmu_cache_flush();
vectors_init();
@@ -484,9 +471,11 @@ static int mmu_init(void)
* This is to speed up the generation of 2nd level page tables
* below
*/
- for_each_memory_bank(bank)
- create_sections(bank->start, bank->start, bank->size >> 20,
+ for_each_memory_bank(bank) {
+ create_sections(ttb, bank->start, bank->size >> 20,
PMD_SECT_DEF_CACHED);
+ __mmu_cache_flush();
+ }
__mmu_cache_on();
diff --git a/arch/arm/cpu/mmu.h b/arch/arm/cpu/mmu.h
index e71ff8e9a..af429edbc 100644
--- a/arch/arm/cpu/mmu.h
+++ b/arch/arm/cpu/mmu.h
@@ -24,5 +24,15 @@ static inline void set_domain(unsigned val)
asm volatile ("mcr p15,0,%0,c3,c0,0" : : "r"(val) /*:*/);
}
+static inline void
+create_sections(uint32_t *ttb, unsigned long addr,
+ int size_m, unsigned int flags)
+{
+ unsigned int i;
+
+ for (i = 0, addr >>= 20; i < size_m; i++, addr++)
+ ttb[addr] = (addr << 20) | flags;
+}
+
#endif /* __ARM_MMU_H */
--
2.17.0
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 32+ messages in thread
* [PATCH v4 07/29] ARM: mmu: Separate index and address in create_sections()
2018-05-22 3:14 [PATCH v4 00/29] ARM MMU code improvements and on-demand PTE allocation Andrey Smirnov
` (5 preceding siblings ...)
2018-05-22 3:14 ` [PATCH v4 06/29] ARM: mmu: Share code for create_sections() Andrey Smirnov
@ 2018-05-22 3:14 ` Andrey Smirnov
2018-05-22 3:14 ` [PATCH v4 08/29] sizes.h: Sync with Linux 4.16 Andrey Smirnov
` (22 subsequent siblings)
29 siblings, 0 replies; 32+ messages in thread
From: Andrey Smirnov @ 2018-05-22 3:14 UTC (permalink / raw)
To: barebox; +Cc: Andrey Smirnov
Both TTB index and address used to fill that entry are derived from
the same variable 'addr' which requires shifting right and left by 20
and somewhat confusing.
Split the counter used to iterate over elements of TTB into a
separate variable to make this code a bit easier to read.
Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
---
arch/arm/cpu/mmu.h | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)
diff --git a/arch/arm/cpu/mmu.h b/arch/arm/cpu/mmu.h
index af429edbc..56e78c715 100644
--- a/arch/arm/cpu/mmu.h
+++ b/arch/arm/cpu/mmu.h
@@ -1,6 +1,8 @@
#ifndef __ARM_MMU_H
#define __ARM_MMU_H
+#include <linux/sizes.h>
+
#ifdef CONFIG_MMU
void __mmu_cache_on(void);
void __mmu_cache_off(void);
@@ -28,10 +30,14 @@ static inline void
create_sections(uint32_t *ttb, unsigned long addr,
int size_m, unsigned int flags)
{
+ unsigned long ttb_start = addr >> 20;
+ unsigned long ttb_end = ttb_start + size_m;
unsigned int i;
- for (i = 0, addr >>= 20; i < size_m; i++, addr++)
- ttb[addr] = (addr << 20) | flags;
+ for (i = ttb_start; i < ttb_end; i++) {
+ ttb[i] = addr | flags;
+ addr += SZ_1M;
+ }
}
--
2.17.0
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 32+ messages in thread
* [PATCH v4 08/29] sizes.h: Sync with Linux 4.16
2018-05-22 3:14 [PATCH v4 00/29] ARM MMU code improvements and on-demand PTE allocation Andrey Smirnov
` (6 preceding siblings ...)
2018-05-22 3:14 ` [PATCH v4 07/29] ARM: mmu: Separate index and address in create_sections() Andrey Smirnov
@ 2018-05-22 3:14 ` Andrey Smirnov
2018-05-22 3:14 ` [PATCH v4 09/29] ARM: mmu: Specify size in bytes in create_sections() Andrey Smirnov
` (21 subsequent siblings)
29 siblings, 0 replies; 32+ messages in thread
From: Andrey Smirnov @ 2018-05-22 3:14 UTC (permalink / raw)
To: barebox; +Cc: Andrey Smirnov
Sync with Linux 4.16 to get SZ_4G.
Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
---
arch/arm/boards/phytec-som-imx6/lowlevel.c | 1 +
include/linux/sizes.h | 4 ++++
2 files changed, 5 insertions(+)
diff --git a/arch/arm/boards/phytec-som-imx6/lowlevel.c b/arch/arm/boards/phytec-som-imx6/lowlevel.c
index f9d70c745..05f918f6c 100644
--- a/arch/arm/boards/phytec-som-imx6/lowlevel.c
+++ b/arch/arm/boards/phytec-som-imx6/lowlevel.c
@@ -38,6 +38,7 @@ static inline void setup_uart(void)
putc_ll('>');
}
+#undef SZ_4G
#define SZ_4G 0xEFFFFFF8
BAREBOX_IMD_TAG_STRING(physom_mx6_memsize_SZ_128M, IMD_TYPE_PARAMETER, "memsize=128", 0);
diff --git a/include/linux/sizes.h b/include/linux/sizes.h
index ce3e8150c..fbde0bc7e 100644
--- a/include/linux/sizes.h
+++ b/include/linux/sizes.h
@@ -8,6 +8,8 @@
#ifndef __LINUX_SIZES_H__
#define __LINUX_SIZES_H__
+#include <linux/const.h>
+
#define SZ_1 0x00000001
#define SZ_2 0x00000002
#define SZ_4 0x00000004
@@ -44,4 +46,6 @@
#define SZ_1G 0x40000000
#define SZ_2G 0x80000000
+#define SZ_4G _AC(0x100000000, ULL)
+
#endif /* __LINUX_SIZES_H__ */
--
2.17.0
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 32+ messages in thread
* [PATCH v4 09/29] ARM: mmu: Specify size in bytes in create_sections()
2018-05-22 3:14 [PATCH v4 00/29] ARM MMU code improvements and on-demand PTE allocation Andrey Smirnov
` (7 preceding siblings ...)
2018-05-22 3:14 ` [PATCH v4 08/29] sizes.h: Sync with Linux 4.16 Andrey Smirnov
@ 2018-05-22 3:14 ` Andrey Smirnov
2018-05-22 3:14 ` [PATCH v4 10/29] ARM: mmu: Share code for initial flat mapping creation Andrey Smirnov
` (20 subsequent siblings)
29 siblings, 0 replies; 32+ messages in thread
From: Andrey Smirnov @ 2018-05-22 3:14 UTC (permalink / raw)
To: barebox; +Cc: Andrey Smirnov
Seeing
create_sections(ttb, 0, PAGE_SIZE, ...);
as the code the creates initial flat 4 GiB mapping is a bit less
intuitive then
create_sections(ttb, 0, SZ_4G - 1, ...);
so, for the sake of clarification, convert create_sections() to accept
address of the last byte in the region instead of size in MiB. Note
the alternative of converting size to units of bytes was not chosen to
avoid converting 3-rd function argument into a 64-bit number.
Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
---
arch/arm/cpu/mmu-early.c | 4 ++--
arch/arm/cpu/mmu.c | 4 ++--
arch/arm/cpu/mmu.h | 10 +++++-----
3 files changed, 9 insertions(+), 9 deletions(-)
diff --git a/arch/arm/cpu/mmu-early.c b/arch/arm/cpu/mmu-early.c
index 70ece0d2f..b10aa6fde 100644
--- a/arch/arm/cpu/mmu-early.c
+++ b/arch/arm/cpu/mmu-early.c
@@ -16,7 +16,7 @@ static void map_cachable(unsigned long start, unsigned long size)
start = ALIGN_DOWN(start, SZ_1M);
size = ALIGN(size, SZ_1M);
- create_sections(ttb, start, size >> 20, PMD_SECT_AP_WRITE |
+ create_sections(ttb, start, start + size - 1, PMD_SECT_AP_WRITE |
PMD_SECT_AP_READ | PMD_TYPE_SECT | PMD_SECT_WB);
}
@@ -30,7 +30,7 @@ void mmu_early_enable(unsigned long membase, unsigned long memsize,
set_ttbr(ttb);
set_domain(DOMAIN_MANAGER);
- create_sections(ttb, 0, 4096, PMD_SECT_AP_WRITE |
+ create_sections(ttb, 0, SZ_4G - 1, PMD_SECT_AP_WRITE |
PMD_SECT_AP_READ | PMD_TYPE_SECT);
map_cachable(membase, memsize);
diff --git a/arch/arm/cpu/mmu.c b/arch/arm/cpu/mmu.c
index 2289a19c5..a9a5f2f8c 100644
--- a/arch/arm/cpu/mmu.c
+++ b/arch/arm/cpu/mmu.c
@@ -460,7 +460,7 @@ static int mmu_init(void)
set_domain(DOMAIN_MANAGER);
/* create a flat mapping using 1MiB sections */
- create_sections(ttb, 0, PAGE_SIZE, PMD_SECT_AP_WRITE | PMD_SECT_AP_READ |
+ create_sections(ttb, 0, SZ_4G - 1, PMD_SECT_AP_WRITE | PMD_SECT_AP_READ |
PMD_TYPE_SECT);
__mmu_cache_flush();
@@ -472,7 +472,7 @@ static int mmu_init(void)
* below
*/
for_each_memory_bank(bank) {
- create_sections(ttb, bank->start, bank->size >> 20,
+ create_sections(ttb, bank->start, bank->start + bank->size - 1,
PMD_SECT_DEF_CACHED);
__mmu_cache_flush();
}
diff --git a/arch/arm/cpu/mmu.h b/arch/arm/cpu/mmu.h
index 56e78c715..fa01cbe4e 100644
--- a/arch/arm/cpu/mmu.h
+++ b/arch/arm/cpu/mmu.h
@@ -27,12 +27,12 @@ static inline void set_domain(unsigned val)
}
static inline void
-create_sections(uint32_t *ttb, unsigned long addr,
- int size_m, unsigned int flags)
+create_sections(uint32_t *ttb, unsigned long first,
+ unsigned long last, unsigned int flags)
{
- unsigned long ttb_start = addr >> 20;
- unsigned long ttb_end = ttb_start + size_m;
- unsigned int i;
+ unsigned long ttb_start = first >> 20;
+ unsigned long ttb_end = (last >> 20) + 1;
+ unsigned int i, addr = first;
for (i = ttb_start; i < ttb_end; i++) {
ttb[i] = addr | flags;
--
2.17.0
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 32+ messages in thread
* [PATCH v4 10/29] ARM: mmu: Share code for initial flat mapping creation
2018-05-22 3:14 [PATCH v4 00/29] ARM MMU code improvements and on-demand PTE allocation Andrey Smirnov
` (8 preceding siblings ...)
2018-05-22 3:14 ` [PATCH v4 09/29] ARM: mmu: Specify size in bytes in create_sections() Andrey Smirnov
@ 2018-05-22 3:14 ` Andrey Smirnov
2018-05-22 3:14 ` [PATCH v4 11/29] ARM: mmu: Share PMD_SECT_DEF_CACHED Andrey Smirnov
` (19 subsequent siblings)
29 siblings, 0 replies; 32+ messages in thread
From: Andrey Smirnov @ 2018-05-22 3:14 UTC (permalink / raw)
To: barebox; +Cc: Andrey Smirnov
Code creating inital 4GiB flat mapping is identical between mmu.c and
mmu-early.c, so move it to mmu.h and share.
Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
---
arch/arm/cpu/mmu-early.c | 4 +---
arch/arm/cpu/mmu.c | 6 +-----
arch/arm/cpu/mmu.h | 8 ++++++++
3 files changed, 10 insertions(+), 8 deletions(-)
diff --git a/arch/arm/cpu/mmu-early.c b/arch/arm/cpu/mmu-early.c
index b10aa6fde..d9aafdd8a 100644
--- a/arch/arm/cpu/mmu-early.c
+++ b/arch/arm/cpu/mmu-early.c
@@ -5,7 +5,6 @@
#include <asm/memory.h>
#include <asm/system.h>
#include <asm/cache.h>
-#include <asm/pgtable.h>
#include "mmu.h"
@@ -30,8 +29,7 @@ void mmu_early_enable(unsigned long membase, unsigned long memsize,
set_ttbr(ttb);
set_domain(DOMAIN_MANAGER);
- create_sections(ttb, 0, SZ_4G - 1, PMD_SECT_AP_WRITE |
- PMD_SECT_AP_READ | PMD_TYPE_SECT);
+ create_flat_mapping(ttb);
map_cachable(membase, memsize);
diff --git a/arch/arm/cpu/mmu.c b/arch/arm/cpu/mmu.c
index a9a5f2f8c..f0f279ffa 100644
--- a/arch/arm/cpu/mmu.c
+++ b/arch/arm/cpu/mmu.c
@@ -27,14 +27,12 @@
#include <asm/barebox-arm.h>
#include <asm/system.h>
#include <asm/cache.h>
-#include <asm/pgtable.h>
#include <memory.h>
#include <asm/system_info.h>
#include <asm/sections.h>
#include "mmu.h"
-#define PMD_SECT_DEF_UNCACHED (PMD_SECT_AP_WRITE | PMD_SECT_AP_READ | PMD_TYPE_SECT)
#define PMD_SECT_DEF_CACHED (PMD_SECT_WB | PMD_SECT_DEF_UNCACHED)
static uint32_t *ttb;
@@ -459,9 +457,7 @@ static int mmu_init(void)
set_ttbr(ttb);
set_domain(DOMAIN_MANAGER);
- /* create a flat mapping using 1MiB sections */
- create_sections(ttb, 0, SZ_4G - 1, PMD_SECT_AP_WRITE | PMD_SECT_AP_READ |
- PMD_TYPE_SECT);
+ create_flat_mapping(ttb);
__mmu_cache_flush();
vectors_init();
diff --git a/arch/arm/cpu/mmu.h b/arch/arm/cpu/mmu.h
index fa01cbe4e..0c9e44cd2 100644
--- a/arch/arm/cpu/mmu.h
+++ b/arch/arm/cpu/mmu.h
@@ -1,6 +1,7 @@
#ifndef __ARM_MMU_H
#define __ARM_MMU_H
+#include <asm/pgtable.h>
#include <linux/sizes.h>
#ifdef CONFIG_MMU
@@ -40,5 +41,12 @@ create_sections(uint32_t *ttb, unsigned long first,
}
}
+#define PMD_SECT_DEF_UNCACHED (PMD_SECT_AP_WRITE | PMD_SECT_AP_READ | PMD_TYPE_SECT)
+
+static inline void create_flat_mapping(uint32_t *ttb)
+{
+ /* create a flat mapping using 1MiB sections */
+ create_sections(ttb, 0, SZ_4G - 1, PMD_SECT_DEF_UNCACHED);
+}
#endif /* __ARM_MMU_H */
--
2.17.0
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 32+ messages in thread
* [PATCH v4 11/29] ARM: mmu: Share PMD_SECT_DEF_CACHED
2018-05-22 3:14 [PATCH v4 00/29] ARM MMU code improvements and on-demand PTE allocation Andrey Smirnov
` (9 preceding siblings ...)
2018-05-22 3:14 ` [PATCH v4 10/29] ARM: mmu: Share code for initial flat mapping creation Andrey Smirnov
@ 2018-05-22 3:14 ` Andrey Smirnov
2018-05-22 3:14 ` [PATCH v4 12/29] ARM: mmu: Drop needless shifting in map_io_sections() Andrey Smirnov
` (18 subsequent siblings)
29 siblings, 0 replies; 32+ messages in thread
From: Andrey Smirnov @ 2018-05-22 3:14 UTC (permalink / raw)
To: barebox; +Cc: Andrey Smirnov
Share PMD_SECT_DEF_CACHED between mmu.c and mmu-early.c.
Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
---
arch/arm/cpu/mmu-early.c | 3 +--
arch/arm/cpu/mmu.h | 1 +
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/arch/arm/cpu/mmu-early.c b/arch/arm/cpu/mmu-early.c
index d9aafdd8a..d39a03ed9 100644
--- a/arch/arm/cpu/mmu-early.c
+++ b/arch/arm/cpu/mmu-early.c
@@ -15,8 +15,7 @@ static void map_cachable(unsigned long start, unsigned long size)
start = ALIGN_DOWN(start, SZ_1M);
size = ALIGN(size, SZ_1M);
- create_sections(ttb, start, start + size - 1, PMD_SECT_AP_WRITE |
- PMD_SECT_AP_READ | PMD_TYPE_SECT | PMD_SECT_WB);
+ create_sections(ttb, start, start + size - 1, PMD_SECT_DEF_CACHED);
}
void mmu_early_enable(unsigned long membase, unsigned long memsize,
diff --git a/arch/arm/cpu/mmu.h b/arch/arm/cpu/mmu.h
index 0c9e44cd2..efe4091c6 100644
--- a/arch/arm/cpu/mmu.h
+++ b/arch/arm/cpu/mmu.h
@@ -42,6 +42,7 @@ create_sections(uint32_t *ttb, unsigned long first,
}
#define PMD_SECT_DEF_UNCACHED (PMD_SECT_AP_WRITE | PMD_SECT_AP_READ | PMD_TYPE_SECT)
+#define PMD_SECT_DEF_CACHED (PMD_SECT_WB | PMD_SECT_DEF_UNCACHED)
static inline void create_flat_mapping(uint32_t *ttb)
{
--
2.17.0
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 32+ messages in thread
* [PATCH v4 12/29] ARM: mmu: Drop needless shifting in map_io_sections()
2018-05-22 3:14 [PATCH v4 00/29] ARM MMU code improvements and on-demand PTE allocation Andrey Smirnov
` (10 preceding siblings ...)
2018-05-22 3:14 ` [PATCH v4 11/29] ARM: mmu: Share PMD_SECT_DEF_CACHED Andrey Smirnov
@ 2018-05-22 3:14 ` Andrey Smirnov
2018-05-22 3:14 ` [PATCH v4 13/29] ARM: mmu: Replace hardcoded shifts with pgd_index() from Linux Andrey Smirnov
` (17 subsequent siblings)
29 siblings, 0 replies; 32+ messages in thread
From: Andrey Smirnov @ 2018-05-22 3:14 UTC (permalink / raw)
To: barebox; +Cc: Andrey Smirnov
Instead of shifting phys right by 20 and then again left by the same
amount, just convert the code to expect it to be in unit of bytes all
the time.
Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
---
arch/arm/cpu/mmu.c | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/arch/arm/cpu/mmu.c b/arch/arm/cpu/mmu.c
index f0f279ffa..06c9045b7 100644
--- a/arch/arm/cpu/mmu.c
+++ b/arch/arm/cpu/mmu.c
@@ -196,9 +196,8 @@ void *map_io_sections(unsigned long phys, void *_start, size_t size)
{
unsigned long start = (unsigned long)_start, sec;
- phys >>= 20;
- for (sec = start; sec < start + size; sec += (1 << 20))
- ttb[sec >> 20] = (phys++ << 20) | PMD_SECT_DEF_UNCACHED;
+ for (sec = start; sec < start + size; sec += (1 << 20), phys += SZ_1M)
+ ttb[sec >> 20] = phys | PMD_SECT_DEF_UNCACHED;
dma_flush_range((unsigned long)ttb, (unsigned long)ttb + 0x4000);
tlb_invalidate();
--
2.17.0
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 32+ messages in thread
* [PATCH v4 13/29] ARM: mmu: Replace hardcoded shifts with pgd_index() from Linux
2018-05-22 3:14 [PATCH v4 00/29] ARM MMU code improvements and on-demand PTE allocation Andrey Smirnov
` (11 preceding siblings ...)
2018-05-22 3:14 ` [PATCH v4 12/29] ARM: mmu: Drop needless shifting in map_io_sections() Andrey Smirnov
@ 2018-05-22 3:14 ` Andrey Smirnov
2018-05-22 3:14 ` [PATCH v4 14/29] ARM: mmu: Trivial simplification in arm_mmu_remap_sdram() Andrey Smirnov
` (16 subsequent siblings)
29 siblings, 0 replies; 32+ messages in thread
From: Andrey Smirnov @ 2018-05-22 3:14 UTC (permalink / raw)
To: barebox; +Cc: Andrey Smirnov
Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
---
arch/arm/cpu/mmu.c | 12 ++++++------
arch/arm/cpu/mmu.h | 8 ++++++--
2 files changed, 12 insertions(+), 8 deletions(-)
diff --git a/arch/arm/cpu/mmu.c b/arch/arm/cpu/mmu.c
index 06c9045b7..1dbfcee16 100644
--- a/arch/arm/cpu/mmu.c
+++ b/arch/arm/cpu/mmu.c
@@ -96,7 +96,7 @@ static u32 *arm_create_pte(unsigned long virt)
if (!ttb)
arm_mmu_not_initialized_error();
- ttb[virt >> 20] = (unsigned long)table | PMD_TYPE_TABLE;
+ ttb[pgd_index(virt)] = (unsigned long)table | PMD_TYPE_TABLE;
for (i = 0; i < 256; i++) {
table[i] = virt | PTE_TYPE_SMALL | pte_flags_uncached;
@@ -113,7 +113,7 @@ static u32 *find_pte(unsigned long adr)
if (!ttb)
arm_mmu_not_initialized_error();
- if ((ttb[adr >> 20] & PMD_TYPE_MASK) != PMD_TYPE_TABLE) {
+ if ((ttb[pgd_index(adr)] & PMD_TYPE_MASK) != PMD_TYPE_TABLE) {
struct memory_bank *bank;
int i = 0;
@@ -132,7 +132,7 @@ static u32 *find_pte(unsigned long adr)
}
/* find the coarse page table base address */
- table = (u32 *)(ttb[adr >> 20] & ~0x3ff);
+ table = (u32 *)(ttb[pgd_index(adr)] & ~0x3ff);
/* find second level descriptor */
return &table[(adr >> PAGE_SHIFT) & 0xff];
@@ -197,7 +197,7 @@ void *map_io_sections(unsigned long phys, void *_start, size_t size)
unsigned long start = (unsigned long)_start, sec;
for (sec = start; sec < start + size; sec += (1 << 20), phys += SZ_1M)
- ttb[sec >> 20] = phys | PMD_SECT_DEF_UNCACHED;
+ ttb[pgd_index(sec)] = phys | PMD_SECT_DEF_UNCACHED;
dma_flush_range((unsigned long)ttb, (unsigned long)ttb + 0x4000);
tlb_invalidate();
@@ -211,8 +211,8 @@ void *map_io_sections(unsigned long phys, void *_start, size_t size)
static int arm_mmu_remap_sdram(struct memory_bank *bank)
{
unsigned long phys = (unsigned long)bank->start;
- unsigned long ttb_start = phys >> 20;
- unsigned long ttb_end = (phys >> 20) + (bank->size >> 20);
+ unsigned long ttb_start = pgd_index(phys);
+ unsigned long ttb_end = pgd_index(phys) + pgd_index(bank->size);
unsigned long num_ptes = bank->size >> 12;
int i, pte;
u32 *ptes;
diff --git a/arch/arm/cpu/mmu.h b/arch/arm/cpu/mmu.h
index efe4091c6..4f6ab2e71 100644
--- a/arch/arm/cpu/mmu.h
+++ b/arch/arm/cpu/mmu.h
@@ -4,6 +4,10 @@
#include <asm/pgtable.h>
#include <linux/sizes.h>
+#define PGDIR_SHIFT 20
+
+#define pgd_index(addr) ((addr) >> PGDIR_SHIFT)
+
#ifdef CONFIG_MMU
void __mmu_cache_on(void);
void __mmu_cache_off(void);
@@ -31,8 +35,8 @@ static inline void
create_sections(uint32_t *ttb, unsigned long first,
unsigned long last, unsigned int flags)
{
- unsigned long ttb_start = first >> 20;
- unsigned long ttb_end = (last >> 20) + 1;
+ unsigned long ttb_start = pgd_index(first);
+ unsigned long ttb_end = pgd_index(last) + 1;
unsigned int i, addr = first;
for (i = ttb_start; i < ttb_end; i++) {
--
2.17.0
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 32+ messages in thread
* [PATCH v4 14/29] ARM: mmu: Trivial simplification in arm_mmu_remap_sdram()
2018-05-22 3:14 [PATCH v4 00/29] ARM MMU code improvements and on-demand PTE allocation Andrey Smirnov
` (12 preceding siblings ...)
2018-05-22 3:14 ` [PATCH v4 13/29] ARM: mmu: Replace hardcoded shifts with pgd_index() from Linux Andrey Smirnov
@ 2018-05-22 3:14 ` Andrey Smirnov
2018-05-22 3:14 ` [PATCH v4 15/29] ARM: mmu: Replace various SZ_1M with PGDIR_SIZE Andrey Smirnov
` (15 subsequent siblings)
29 siblings, 0 replies; 32+ messages in thread
From: Andrey Smirnov @ 2018-05-22 3:14 UTC (permalink / raw)
To: barebox; +Cc: Andrey Smirnov
Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
---
arch/arm/cpu/mmu.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/arch/arm/cpu/mmu.c b/arch/arm/cpu/mmu.c
index 1dbfcee16..83577300f 100644
--- a/arch/arm/cpu/mmu.c
+++ b/arch/arm/cpu/mmu.c
@@ -212,7 +212,7 @@ static int arm_mmu_remap_sdram(struct memory_bank *bank)
{
unsigned long phys = (unsigned long)bank->start;
unsigned long ttb_start = pgd_index(phys);
- unsigned long ttb_end = pgd_index(phys) + pgd_index(bank->size);
+ unsigned long ttb_end = ttb_start + pgd_index(bank->size);
unsigned long num_ptes = bank->size >> 12;
int i, pte;
u32 *ptes;
--
2.17.0
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 32+ messages in thread
* [PATCH v4 15/29] ARM: mmu: Replace various SZ_1M with PGDIR_SIZE
2018-05-22 3:14 [PATCH v4 00/29] ARM MMU code improvements and on-demand PTE allocation Andrey Smirnov
` (13 preceding siblings ...)
2018-05-22 3:14 ` [PATCH v4 14/29] ARM: mmu: Trivial simplification in arm_mmu_remap_sdram() Andrey Smirnov
@ 2018-05-22 3:14 ` Andrey Smirnov
2018-05-22 3:14 ` [PATCH v4 16/29] ARM: mmu: Use PAGE_SIZE when specifying size of one page Andrey Smirnov
` (14 subsequent siblings)
29 siblings, 0 replies; 32+ messages in thread
From: Andrey Smirnov @ 2018-05-22 3:14 UTC (permalink / raw)
To: barebox; +Cc: Andrey Smirnov
Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
---
arch/arm/cpu/mmu.c | 8 ++++----
arch/arm/cpu/mmu.h | 3 ++-
2 files changed, 6 insertions(+), 5 deletions(-)
diff --git a/arch/arm/cpu/mmu.c b/arch/arm/cpu/mmu.c
index 83577300f..de242e0d7 100644
--- a/arch/arm/cpu/mmu.c
+++ b/arch/arm/cpu/mmu.c
@@ -196,7 +196,7 @@ void *map_io_sections(unsigned long phys, void *_start, size_t size)
{
unsigned long start = (unsigned long)_start, sec;
- for (sec = start; sec < start + size; sec += (1 << 20), phys += SZ_1M)
+ for (sec = start; sec < start + size; sec += PGDIR_SIZE, phys += PGDIR_SIZE)
ttb[pgd_index(sec)] = phys | PMD_SECT_DEF_UNCACHED;
dma_flush_range((unsigned long)ttb, (unsigned long)ttb + 0x4000);
@@ -224,7 +224,7 @@ static int arm_mmu_remap_sdram(struct memory_bank *bank)
* We replace each 1MiB section in this range with second level page
* tables, therefore we must have 1Mib aligment here.
*/
- if (!IS_ALIGNED(phys, SZ_1M) || !IS_ALIGNED(bank->size, SZ_1M))
+ if (!IS_ALIGNED(phys, PGDIR_SIZE) || !IS_ALIGNED(bank->size, PGDIR_SIZE))
return -EINVAL;
ptes = xmemalign(PAGE_SIZE, num_ptes * sizeof(u32));
@@ -289,8 +289,8 @@ static void create_vector_table(unsigned long adr)
vectors = xmemalign(PAGE_SIZE, PAGE_SIZE);
pr_debug("Creating vector table, virt = 0x%p, phys = 0x%08lx\n",
vectors, adr);
- exc = arm_create_pte(ALIGN_DOWN(adr, SZ_1M));
- idx = (adr & (SZ_1M - 1)) >> PAGE_SHIFT;
+ exc = arm_create_pte(ALIGN_DOWN(adr, PGDIR_SIZE));
+ idx = (adr & (PGDIR_SIZE - 1)) >> PAGE_SHIFT;
exc[idx] = (u32)vectors | PTE_TYPE_SMALL | pte_flags_cached;
}
diff --git a/arch/arm/cpu/mmu.h b/arch/arm/cpu/mmu.h
index 4f6ab2e71..211770af8 100644
--- a/arch/arm/cpu/mmu.h
+++ b/arch/arm/cpu/mmu.h
@@ -5,6 +5,7 @@
#include <linux/sizes.h>
#define PGDIR_SHIFT 20
+#define PGDIR_SIZE (1UL << PGDIR_SHIFT)
#define pgd_index(addr) ((addr) >> PGDIR_SHIFT)
@@ -41,7 +42,7 @@ create_sections(uint32_t *ttb, unsigned long first,
for (i = ttb_start; i < ttb_end; i++) {
ttb[i] = addr | flags;
- addr += SZ_1M;
+ addr += PGDIR_SIZE;
}
}
--
2.17.0
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 32+ messages in thread
* [PATCH v4 16/29] ARM: mmu: Use PAGE_SIZE when specifying size of one page
2018-05-22 3:14 [PATCH v4 00/29] ARM MMU code improvements and on-demand PTE allocation Andrey Smirnov
` (14 preceding siblings ...)
2018-05-22 3:14 ` [PATCH v4 15/29] ARM: mmu: Replace various SZ_1M with PGDIR_SIZE Andrey Smirnov
@ 2018-05-22 3:14 ` Andrey Smirnov
2018-05-22 3:14 ` [PATCH v4 17/29] ARM: mmu: Define and use PTRS_PER_PTE Andrey Smirnov
` (13 subsequent siblings)
29 siblings, 0 replies; 32+ messages in thread
From: Andrey Smirnov @ 2018-05-22 3:14 UTC (permalink / raw)
To: barebox; +Cc: Andrey Smirnov
Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
---
arch/arm/cpu/mmu.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/arch/arm/cpu/mmu.c b/arch/arm/cpu/mmu.c
index de242e0d7..62425b828 100644
--- a/arch/arm/cpu/mmu.c
+++ b/arch/arm/cpu/mmu.c
@@ -271,7 +271,7 @@ static void create_vector_table(unsigned long adr)
u32 *exc;
int idx;
- vectors_sdram = request_sdram_region("vector table", adr, SZ_4K);
+ vectors_sdram = request_sdram_region("vector table", adr, PAGE_SIZE);
if (vectors_sdram) {
/*
* The vector table address is inside the SDRAM physical
@@ -352,7 +352,7 @@ static void create_zero_page(void)
struct resource *zero_sdram;
u32 *zero;
- zero_sdram = request_sdram_region("zero page", 0x0, SZ_4K);
+ zero_sdram = request_sdram_region("zero page", 0x0, PAGE_SIZE);
if (zero_sdram) {
/*
* Here we would need to set the second level page table
--
2.17.0
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 32+ messages in thread
* [PATCH v4 17/29] ARM: mmu: Define and use PTRS_PER_PTE
2018-05-22 3:14 [PATCH v4 00/29] ARM MMU code improvements and on-demand PTE allocation Andrey Smirnov
` (15 preceding siblings ...)
2018-05-22 3:14 ` [PATCH v4 16/29] ARM: mmu: Use PAGE_SIZE when specifying size of one page Andrey Smirnov
@ 2018-05-22 3:14 ` Andrey Smirnov
2018-05-22 3:14 ` [PATCH v4 18/29] ARM: mmu: Use PAGE_SIZE instead of magic right shift by 12 Andrey Smirnov
` (12 subsequent siblings)
29 siblings, 0 replies; 32+ messages in thread
From: Andrey Smirnov @ 2018-05-22 3:14 UTC (permalink / raw)
To: barebox; +Cc: Andrey Smirnov
Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
---
arch/arm/cpu/mmu.c | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/arch/arm/cpu/mmu.c b/arch/arm/cpu/mmu.c
index 62425b828..627962fea 100644
--- a/arch/arm/cpu/mmu.c
+++ b/arch/arm/cpu/mmu.c
@@ -34,6 +34,7 @@
#include "mmu.h"
#define PMD_SECT_DEF_CACHED (PMD_SECT_WB | PMD_SECT_DEF_UNCACHED)
+#define PTRS_PER_PTE (PGDIR_SIZE / PAGE_SIZE)
static uint32_t *ttb;
@@ -91,14 +92,15 @@ static u32 *arm_create_pte(unsigned long virt)
u32 *table;
int i;
- table = memalign(0x400, 0x400);
+ table = memalign(PTRS_PER_PTE * sizeof(u32),
+ PTRS_PER_PTE * sizeof(u32));
if (!ttb)
arm_mmu_not_initialized_error();
ttb[pgd_index(virt)] = (unsigned long)table | PMD_TYPE_TABLE;
- for (i = 0; i < 256; i++) {
+ for (i = 0; i < PTRS_PER_PTE; i++) {
table[i] = virt | PTE_TYPE_SMALL | pte_flags_uncached;
virt += PAGE_SIZE;
}
@@ -242,7 +244,7 @@ static int arm_mmu_remap_sdram(struct memory_bank *bank)
for (i = ttb_start; i < ttb_end; i++) {
ttb[i] = (unsigned long)(&ptes[pte]) | PMD_TYPE_TABLE |
(0 << 4);
- pte += 256;
+ pte += PTRS_PER_PTE;
}
dma_flush_range((unsigned long)ttb, (unsigned long)ttb + 0x4000);
--
2.17.0
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 32+ messages in thread
* [PATCH v4 18/29] ARM: mmu: Use PAGE_SIZE instead of magic right shift by 12
2018-05-22 3:14 [PATCH v4 00/29] ARM MMU code improvements and on-demand PTE allocation Andrey Smirnov
` (16 preceding siblings ...)
2018-05-22 3:14 ` [PATCH v4 17/29] ARM: mmu: Define and use PTRS_PER_PTE Andrey Smirnov
@ 2018-05-22 3:14 ` Andrey Smirnov
2018-05-22 3:15 ` [PATCH v4 19/29] ARM: mmu: Use xmemalign in arm_create_pte() Andrey Smirnov
` (11 subsequent siblings)
29 siblings, 0 replies; 32+ messages in thread
From: Andrey Smirnov @ 2018-05-22 3:14 UTC (permalink / raw)
To: barebox; +Cc: Andrey Smirnov
Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
---
arch/arm/cpu/mmu.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/arch/arm/cpu/mmu.c b/arch/arm/cpu/mmu.c
index 627962fea..4090f7da9 100644
--- a/arch/arm/cpu/mmu.c
+++ b/arch/arm/cpu/mmu.c
@@ -215,7 +215,7 @@ static int arm_mmu_remap_sdram(struct memory_bank *bank)
unsigned long phys = (unsigned long)bank->start;
unsigned long ttb_start = pgd_index(phys);
unsigned long ttb_end = ttb_start + pgd_index(bank->size);
- unsigned long num_ptes = bank->size >> 12;
+ unsigned long num_ptes = bank->size / PAGE_SIZE;
int i, pte;
u32 *ptes;
--
2.17.0
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 32+ messages in thread
* [PATCH v4 19/29] ARM: mmu: Use xmemalign in arm_create_pte()
2018-05-22 3:14 [PATCH v4 00/29] ARM MMU code improvements and on-demand PTE allocation Andrey Smirnov
` (17 preceding siblings ...)
2018-05-22 3:14 ` [PATCH v4 18/29] ARM: mmu: Use PAGE_SIZE instead of magic right shift by 12 Andrey Smirnov
@ 2018-05-22 3:15 ` Andrey Smirnov
2018-05-22 3:15 ` [PATCH v4 20/29] ARM: mmu: Use xmemalign in mmu_init() Andrey Smirnov
` (10 subsequent siblings)
29 siblings, 0 replies; 32+ messages in thread
From: Andrey Smirnov @ 2018-05-22 3:15 UTC (permalink / raw)
To: barebox; +Cc: Andrey Smirnov
We don't handle the OOM case in that code, so using xmemalign seems
like a better option.
Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
---
arch/arm/cpu/mmu.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/arch/arm/cpu/mmu.c b/arch/arm/cpu/mmu.c
index 4090f7da9..9fbefa453 100644
--- a/arch/arm/cpu/mmu.c
+++ b/arch/arm/cpu/mmu.c
@@ -92,8 +92,8 @@ static u32 *arm_create_pte(unsigned long virt)
u32 *table;
int i;
- table = memalign(PTRS_PER_PTE * sizeof(u32),
- PTRS_PER_PTE * sizeof(u32));
+ table = xmemalign(PTRS_PER_PTE * sizeof(u32),
+ PTRS_PER_PTE * sizeof(u32));
if (!ttb)
arm_mmu_not_initialized_error();
--
2.17.0
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 32+ messages in thread
* [PATCH v4 20/29] ARM: mmu: Use xmemalign in mmu_init()
2018-05-22 3:14 [PATCH v4 00/29] ARM MMU code improvements and on-demand PTE allocation Andrey Smirnov
` (18 preceding siblings ...)
2018-05-22 3:15 ` [PATCH v4 19/29] ARM: mmu: Use xmemalign in arm_create_pte() Andrey Smirnov
@ 2018-05-22 3:15 ` Andrey Smirnov
2018-05-22 3:15 ` [PATCH v4 21/29] ARM: mmu: Share code between dma_alloc_*() functions Andrey Smirnov
` (9 subsequent siblings)
29 siblings, 0 replies; 32+ messages in thread
From: Andrey Smirnov @ 2018-05-22 3:15 UTC (permalink / raw)
To: barebox; +Cc: Andrey Smirnov
We don't handle OOM case in that code, so using xmemalign seems like a
better option.
Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
---
arch/arm/cpu/mmu.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/arch/arm/cpu/mmu.c b/arch/arm/cpu/mmu.c
index 9fbefa453..fc4046e85 100644
--- a/arch/arm/cpu/mmu.c
+++ b/arch/arm/cpu/mmu.c
@@ -450,7 +450,7 @@ static int mmu_init(void)
pr_crit("Critical Error: Can't request SDRAM region for ttb at %p\n",
ttb);
} else {
- ttb = memalign(0x10000, 0x4000);
+ ttb = xmemalign(0x10000, 0x4000);
}
pr_debug("ttb: 0x%p\n", ttb);
--
2.17.0
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 32+ messages in thread
* [PATCH v4 21/29] ARM: mmu: Share code between dma_alloc_*() functions
2018-05-22 3:14 [PATCH v4 00/29] ARM MMU code improvements and on-demand PTE allocation Andrey Smirnov
` (19 preceding siblings ...)
2018-05-22 3:15 ` [PATCH v4 20/29] ARM: mmu: Use xmemalign in mmu_init() Andrey Smirnov
@ 2018-05-22 3:15 ` Andrey Smirnov
2018-05-22 3:15 ` [PATCH v4 22/29] ARM: mmu: Pass PTE flags a parameter to arm_create_pte() Andrey Smirnov
` (8 subsequent siblings)
29 siblings, 0 replies; 32+ messages in thread
From: Andrey Smirnov @ 2018-05-22 3:15 UTC (permalink / raw)
To: barebox; +Cc: Andrey Smirnov
Code of dma_alloc_coherent() and dma_alloc_writecombine() is almost
identical with exception of the flags passed to undelying call to
__remap_range(). Move commong code into a shared subroutine and
convert both functions to use it.
Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
---
arch/arm/cpu/mmu.c | 22 ++++++++--------------
1 file changed, 8 insertions(+), 14 deletions(-)
diff --git a/arch/arm/cpu/mmu.c b/arch/arm/cpu/mmu.c
index fc4046e85..7d4432b98 100644
--- a/arch/arm/cpu/mmu.c
+++ b/arch/arm/cpu/mmu.c
@@ -500,7 +500,7 @@ void mmu_disable(void)
__mmu_cache_off();
}
-void *dma_alloc_coherent(size_t size, dma_addr_t *dma_handle)
+static void *dma_alloc(size_t size, dma_addr_t *dma_handle, uint32_t pte_flags)
{
void *ret;
@@ -511,25 +511,19 @@ void *dma_alloc_coherent(size_t size, dma_addr_t *dma_handle)
dma_inv_range((unsigned long)ret, (unsigned long)ret + size);
- __remap_range(ret, size, pte_flags_uncached);
+ __remap_range(ret, size, pte_flags);
return ret;
}
-void *dma_alloc_writecombine(size_t size, dma_addr_t *dma_handle)
+void *dma_alloc_coherent(size_t size, dma_addr_t *dma_handle)
{
- void *ret;
-
- size = PAGE_ALIGN(size);
- ret = xmemalign(PAGE_SIZE, size);
- if (dma_handle)
- *dma_handle = (dma_addr_t)ret;
-
- dma_inv_range((unsigned long)ret, (unsigned long)ret + size);
-
- __remap_range(ret, size, pte_flags_wc);
+ return dma_alloc(size, dma_handle, pte_flags_uncached);
+}
- return ret;
+void *dma_alloc_writecombine(size_t size, dma_addr_t *dma_handle)
+{
+ return dma_alloc(size, dma_handle, pte_flags_wc);
}
unsigned long virt_to_phys(volatile void *virt)
--
2.17.0
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 32+ messages in thread
* [PATCH v4 22/29] ARM: mmu: Pass PTE flags a parameter to arm_create_pte()
2018-05-22 3:14 [PATCH v4 00/29] ARM MMU code improvements and on-demand PTE allocation Andrey Smirnov
` (20 preceding siblings ...)
2018-05-22 3:15 ` [PATCH v4 21/29] ARM: mmu: Share code between dma_alloc_*() functions Andrey Smirnov
@ 2018-05-22 3:15 ` Andrey Smirnov
2018-05-22 3:15 ` [PATCH v4 23/29] ARM: mmu: Make sure that address is 1M aligned in arm_create_pte() Andrey Smirnov
` (7 subsequent siblings)
29 siblings, 0 replies; 32+ messages in thread
From: Andrey Smirnov @ 2018-05-22 3:15 UTC (permalink / raw)
To: barebox; +Cc: Andrey Smirnov
In order to make it possible to use this functions in contexts where
creating a new PTE of uncached pages in not appropriate, pass PTE
flags a parameter to arm_create_pte() and fix all of the current users
as necessary.
Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
---
arch/arm/cpu/mmu.c | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)
diff --git a/arch/arm/cpu/mmu.c b/arch/arm/cpu/mmu.c
index 7d4432b98..1713238ad 100644
--- a/arch/arm/cpu/mmu.c
+++ b/arch/arm/cpu/mmu.c
@@ -87,7 +87,7 @@ static void arm_mmu_not_initialized_error(void)
* We initially create a flat uncached mapping on it.
* Not yet exported, but may be later if someone finds use for it.
*/
-static u32 *arm_create_pte(unsigned long virt)
+static u32 *arm_create_pte(unsigned long virt, uint32_t flags)
{
u32 *table;
int i;
@@ -101,7 +101,7 @@ static u32 *arm_create_pte(unsigned long virt)
ttb[pgd_index(virt)] = (unsigned long)table | PMD_TYPE_TABLE;
for (i = 0; i < PTRS_PER_PTE; i++) {
- table[i] = virt | PTE_TYPE_SMALL | pte_flags_uncached;
+ table[i] = virt | PTE_TYPE_SMALL | flags;
virt += PAGE_SIZE;
}
@@ -291,7 +291,8 @@ static void create_vector_table(unsigned long adr)
vectors = xmemalign(PAGE_SIZE, PAGE_SIZE);
pr_debug("Creating vector table, virt = 0x%p, phys = 0x%08lx\n",
vectors, adr);
- exc = arm_create_pte(ALIGN_DOWN(adr, PGDIR_SIZE));
+ exc = arm_create_pte(ALIGN_DOWN(adr, PGDIR_SIZE),
+ pte_flags_uncached);
idx = (adr & (PGDIR_SIZE - 1)) >> PAGE_SHIFT;
exc[idx] = (u32)vectors | PTE_TYPE_SMALL | pte_flags_cached;
}
@@ -362,7 +363,7 @@ static void create_zero_page(void)
*/
pr_debug("zero page is in SDRAM area, currently not supported\n");
} else {
- zero = arm_create_pte(0x0);
+ zero = arm_create_pte(0x0, pte_flags_uncached);
zero[0] = 0;
pr_debug("Created zero page\n");
}
--
2.17.0
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 32+ messages in thread
* [PATCH v4 23/29] ARM: mmu: Make sure that address is 1M aligned in arm_create_pte()
2018-05-22 3:14 [PATCH v4 00/29] ARM MMU code improvements and on-demand PTE allocation Andrey Smirnov
` (21 preceding siblings ...)
2018-05-22 3:15 ` [PATCH v4 22/29] ARM: mmu: Pass PTE flags a parameter to arm_create_pte() Andrey Smirnov
@ 2018-05-22 3:15 ` Andrey Smirnov
2018-05-22 3:15 ` [PATCH v4 24/29] ARM: mmu: Use find_pte() to find PTE in create_vector_table() Andrey Smirnov
` (6 subsequent siblings)
29 siblings, 0 replies; 32+ messages in thread
From: Andrey Smirnov @ 2018-05-22 3:15 UTC (permalink / raw)
To: barebox; +Cc: Andrey Smirnov
If address passed arm_create_pte() is not 1M (PGDIR_SIZE) aligned,
page table that is created will end up having unexpected mapping
offset, breaking "1:1 mapping" assumption and leading to bugs that are
not immediately obvious in their nature.
To prevent this and because all of the callers already do said
alignement in-place, move the alignment code to be a part of
arm_create_pte().
Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
---
arch/arm/cpu/mmu.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/arch/arm/cpu/mmu.c b/arch/arm/cpu/mmu.c
index 1713238ad..21394deb1 100644
--- a/arch/arm/cpu/mmu.c
+++ b/arch/arm/cpu/mmu.c
@@ -92,6 +92,8 @@ static u32 *arm_create_pte(unsigned long virt, uint32_t flags)
u32 *table;
int i;
+ virt = ALIGN_DOWN(virt, PGDIR_SIZE);
+
table = xmemalign(PTRS_PER_PTE * sizeof(u32),
PTRS_PER_PTE * sizeof(u32));
@@ -291,8 +293,7 @@ static void create_vector_table(unsigned long adr)
vectors = xmemalign(PAGE_SIZE, PAGE_SIZE);
pr_debug("Creating vector table, virt = 0x%p, phys = 0x%08lx\n",
vectors, adr);
- exc = arm_create_pte(ALIGN_DOWN(adr, PGDIR_SIZE),
- pte_flags_uncached);
+ exc = arm_create_pte(adr, pte_flags_uncached);
idx = (adr & (PGDIR_SIZE - 1)) >> PAGE_SHIFT;
exc[idx] = (u32)vectors | PTE_TYPE_SMALL | pte_flags_cached;
}
--
2.17.0
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 32+ messages in thread
* [PATCH v4 24/29] ARM: mmu: Use find_pte() to find PTE in create_vector_table()
2018-05-22 3:14 [PATCH v4 00/29] ARM MMU code improvements and on-demand PTE allocation Andrey Smirnov
` (22 preceding siblings ...)
2018-05-22 3:15 ` [PATCH v4 23/29] ARM: mmu: Make sure that address is 1M aligned in arm_create_pte() Andrey Smirnov
@ 2018-05-22 3:15 ` Andrey Smirnov
2018-05-22 3:15 ` [PATCH v4 25/29] ARM: mmu: Use dma_inv_range() in dma_sync_single_for_cpu() Andrey Smirnov
` (5 subsequent siblings)
29 siblings, 0 replies; 32+ messages in thread
From: Andrey Smirnov @ 2018-05-22 3:15 UTC (permalink / raw)
To: barebox; +Cc: Andrey Smirnov
There's already a function that implement necessary arithemtic to find
offset within page table for a given address, so make use of it
instead of re-implementing it again.
Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
---
arch/arm/cpu/mmu.c | 9 ++++-----
1 file changed, 4 insertions(+), 5 deletions(-)
diff --git a/arch/arm/cpu/mmu.c b/arch/arm/cpu/mmu.c
index 21394deb1..f9e4d1a50 100644
--- a/arch/arm/cpu/mmu.c
+++ b/arch/arm/cpu/mmu.c
@@ -272,8 +272,7 @@ static void create_vector_table(unsigned long adr)
{
struct resource *vectors_sdram;
void *vectors;
- u32 *exc;
- int idx;
+ u32 *pte;
vectors_sdram = request_sdram_region("vector table", adr, PAGE_SIZE);
if (vectors_sdram) {
@@ -293,9 +292,9 @@ static void create_vector_table(unsigned long adr)
vectors = xmemalign(PAGE_SIZE, PAGE_SIZE);
pr_debug("Creating vector table, virt = 0x%p, phys = 0x%08lx\n",
vectors, adr);
- exc = arm_create_pte(adr, pte_flags_uncached);
- idx = (adr & (PGDIR_SIZE - 1)) >> PAGE_SHIFT;
- exc[idx] = (u32)vectors | PTE_TYPE_SMALL | pte_flags_cached;
+ arm_create_pte(adr, pte_flags_uncached);
+ pte = find_pte(adr);
+ *pte = (u32)vectors | PTE_TYPE_SMALL | pte_flags_cached;
}
arm_fixup_vectors();
--
2.17.0
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 32+ messages in thread
* [PATCH v4 25/29] ARM: mmu: Use dma_inv_range() in dma_sync_single_for_cpu()
2018-05-22 3:14 [PATCH v4 00/29] ARM MMU code improvements and on-demand PTE allocation Andrey Smirnov
` (23 preceding siblings ...)
2018-05-22 3:15 ` [PATCH v4 24/29] ARM: mmu: Use find_pte() to find PTE in create_vector_table() Andrey Smirnov
@ 2018-05-22 3:15 ` Andrey Smirnov
2018-05-22 3:15 ` [PATCH v4 26/29] ARM: mmu: Simplify the use of dma_flush_range() Andrey Smirnov
` (4 subsequent siblings)
29 siblings, 0 replies; 32+ messages in thread
From: Andrey Smirnov @ 2018-05-22 3:15 UTC (permalink / raw)
To: barebox; +Cc: Andrey Smirnov
The code in the if () statement is identical to already existing
dma_inv_rand(). Use it instead.
Reviewed-by: Lucas Stach <l.stach@pengutronix.de>
Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
---
arch/arm/cpu/mmu.c | 7 ++-----
1 file changed, 2 insertions(+), 5 deletions(-)
diff --git a/arch/arm/cpu/mmu.c b/arch/arm/cpu/mmu.c
index f9e4d1a50..5e1e613d9 100644
--- a/arch/arm/cpu/mmu.c
+++ b/arch/arm/cpu/mmu.c
@@ -548,11 +548,8 @@ void dma_free_coherent(void *mem, dma_addr_t dma_handle, size_t size)
void dma_sync_single_for_cpu(dma_addr_t address, size_t size,
enum dma_data_direction dir)
{
- if (dir != DMA_TO_DEVICE) {
- if (outer_cache.inv_range)
- outer_cache.inv_range(address, address + size);
- __dma_inv_range(address, address + size);
- }
+ if (dir != DMA_TO_DEVICE)
+ dma_inv_range(address, address + size);
}
void dma_sync_single_for_device(dma_addr_t address, size_t size,
--
2.17.0
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 32+ messages in thread
* [PATCH v4 26/29] ARM: mmu: Simplify the use of dma_flush_range()
2018-05-22 3:14 [PATCH v4 00/29] ARM MMU code improvements and on-demand PTE allocation Andrey Smirnov
` (24 preceding siblings ...)
2018-05-22 3:15 ` [PATCH v4 25/29] ARM: mmu: Use dma_inv_range() in dma_sync_single_for_cpu() Andrey Smirnov
@ 2018-05-22 3:15 ` Andrey Smirnov
2018-05-22 3:15 ` [PATCH v4 27/29] ARM: mmu: Implement on-demand PTE allocation Andrey Smirnov
` (3 subsequent siblings)
29 siblings, 0 replies; 32+ messages in thread
From: Andrey Smirnov @ 2018-05-22 3:15 UTC (permalink / raw)
To: barebox; +Cc: Andrey Smirnov
Simplify the use of dma_flush_range() by changing its signature to
accept pointer to start of the data and data size. This change allows
us to avoid a whole bunch of repetitive arithmetic currently done by
all of the callers.
Reviewed-by: Lucas Stach <l.stach@pengutronix.de>
Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
---
arch/arm/cpu/mmu.c | 16 ++++++++--------
1 file changed, 8 insertions(+), 8 deletions(-)
diff --git a/arch/arm/cpu/mmu.c b/arch/arm/cpu/mmu.c
index 5e1e613d9..c3c23c639 100644
--- a/arch/arm/cpu/mmu.c
+++ b/arch/arm/cpu/mmu.c
@@ -142,8 +142,11 @@ static u32 *find_pte(unsigned long adr)
return &table[(adr >> PAGE_SHIFT) & 0xff];
}
-static void dma_flush_range(unsigned long start, unsigned long end)
+static void dma_flush_range(void *ptr, size_t size)
{
+ unsigned long start = (unsigned long)ptr;
+ unsigned long end = start + size;
+
__dma_flush_range(start, end);
if (outer_cache.flush_range)
outer_cache.flush_range(start, end);
@@ -170,9 +173,7 @@ static int __remap_range(void *_start, size_t size, u32 pte_flags)
p[i] |= pte_flags | PTE_TYPE_SMALL;
}
- dma_flush_range((unsigned long)p,
- (unsigned long)p + numentries * sizeof(u32));
-
+ dma_flush_range(p, numentries * sizeof(u32));
tlb_invalidate();
return 0;
@@ -203,7 +204,7 @@ void *map_io_sections(unsigned long phys, void *_start, size_t size)
for (sec = start; sec < start + size; sec += PGDIR_SIZE, phys += PGDIR_SIZE)
ttb[pgd_index(sec)] = phys | PMD_SECT_DEF_UNCACHED;
- dma_flush_range((unsigned long)ttb, (unsigned long)ttb + 0x4000);
+ dma_flush_range(ttb, 0x4000);
tlb_invalidate();
return _start;
}
@@ -249,9 +250,8 @@ static int arm_mmu_remap_sdram(struct memory_bank *bank)
pte += PTRS_PER_PTE;
}
- dma_flush_range((unsigned long)ttb, (unsigned long)ttb + 0x4000);
- dma_flush_range((unsigned long)ptes,
- (unsigned long)ptes + num_ptes * sizeof(u32));
+ dma_flush_range(ttb, 0x4000);
+ dma_flush_range(ptes, num_ptes * sizeof(u32));
tlb_invalidate();
--
2.17.0
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 32+ messages in thread
* [PATCH v4 27/29] ARM: mmu: Implement on-demand PTE allocation
2018-05-22 3:14 [PATCH v4 00/29] ARM MMU code improvements and on-demand PTE allocation Andrey Smirnov
` (25 preceding siblings ...)
2018-05-22 3:15 ` [PATCH v4 26/29] ARM: mmu: Simplify the use of dma_flush_range() Andrey Smirnov
@ 2018-05-22 3:15 ` Andrey Smirnov
2018-05-22 3:15 ` [PATCH v4 28/29] ARM: mmu: Introduce ARM_TTB_SIZE Andrey Smirnov
` (2 subsequent siblings)
29 siblings, 0 replies; 32+ messages in thread
From: Andrey Smirnov @ 2018-05-22 3:15 UTC (permalink / raw)
To: barebox; +Cc: Andrey Smirnov
Allocating PTEs for every 4K page corresponding to SDRAM upfront costs
us quite a bit of memory: 1KB per 1MB or RAM. This is far from being a
deal-breaker for majority of use-cases, but for builds where amount of
free memory is in hundres of KBs* it becomes a real hurdle for being
able to use MMU (which also means no L1 cache).
Given how we really only need PTEs for a very few regions of memory
dedicated from DMA buffers (Ethernet, USB, etc), changing MMU code to
do on-demand section splitting can allow us to save significant amount
of memory without any functionality loss.
Below is a very trivial comparison of memory usages on start before
and after this patch is applied.
Before:
barebox@ZII VF610 Development Board, Rev B:/ meminfo
used: 1271584
free: 265553032
After:
barebox@ZII VF610 Development Board, Rev B:/ meminfo
used: 795276
free: 266024448
Tested on:
- VF610 Tower Board,
- VF610 ZII Development Board (Rev. C)
- i.MX51 Babbage Board
- i.MX7 SabreSD Board
- i.MX6 ZII RDU2 Board
- AT91SAM9X5-EK Board
* One example of such use-case is memory testing while running purely
out of SRAM
Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
---
arch/arm/cpu/mmu.c | 209 ++++++++++++++++++++++++---------------------
1 file changed, 110 insertions(+), 99 deletions(-)
diff --git a/arch/arm/cpu/mmu.c b/arch/arm/cpu/mmu.c
index c3c23c639..5f82b63ca 100644
--- a/arch/arm/cpu/mmu.c
+++ b/arch/arm/cpu/mmu.c
@@ -35,6 +35,7 @@
#define PMD_SECT_DEF_CACHED (PMD_SECT_WB | PMD_SECT_DEF_UNCACHED)
#define PTRS_PER_PTE (PGDIR_SIZE / PAGE_SIZE)
+#define ARCH_MAP_WRITECOMBINE ((unsigned)-1)
static uint32_t *ttb;
@@ -60,6 +61,7 @@ static inline void tlb_invalidate(void)
#define PTE_FLAGS_UNCACHED_V7 (0)
#define PTE_FLAGS_CACHED_V4 (PTE_SMALL_AP_UNO_SRW | PTE_BUFFERABLE | PTE_CACHEABLE)
#define PTE_FLAGS_UNCACHED_V4 PTE_SMALL_AP_UNO_SRW
+#define PGD_FLAGS_WC_V7 PMD_SECT_TEX(1)
/*
* PTE flags to set cached and uncached areas.
@@ -68,6 +70,7 @@ static inline void tlb_invalidate(void)
static uint32_t pte_flags_cached;
static uint32_t pte_flags_wc;
static uint32_t pte_flags_uncached;
+static uint32_t pgd_flags_wc;
#define PTE_MASK ((1 << 12) - 1)
@@ -110,6 +113,11 @@ static u32 *arm_create_pte(unsigned long virt, uint32_t flags)
return table;
}
+static bool pgd_type_table(u32 pgd)
+{
+ return (pgd & PMD_TYPE_MASK) == PMD_TYPE_TABLE;
+}
+
static u32 *find_pte(unsigned long adr)
{
u32 *table;
@@ -117,23 +125,8 @@ static u32 *find_pte(unsigned long adr)
if (!ttb)
arm_mmu_not_initialized_error();
- if ((ttb[pgd_index(adr)] & PMD_TYPE_MASK) != PMD_TYPE_TABLE) {
- struct memory_bank *bank;
- int i = 0;
-
- /*
- * This should only be called for page mapped memory inside our
- * memory banks. It's a bug to call it with section mapped memory
- * locations.
- */
- pr_crit("%s: TTB for address 0x%08lx is not of type table\n",
- __func__, adr);
- pr_crit("Memory banks:\n");
- for_each_memory_bank(bank)
- pr_crit("#%d 0x%08lx - 0x%08lx\n", i, bank->start,
- bank->start + bank->size - 1);
- BUG();
- }
+ if (!pgd_type_table(ttb[pgd_index(adr)]))
+ return NULL;
/* find the coarse page table base address */
table = (u32 *)(ttb[pgd_index(adr)] & ~0x3ff);
@@ -159,42 +152,114 @@ static void dma_inv_range(unsigned long start, unsigned long end)
__dma_inv_range(start, end);
}
-static int __remap_range(void *_start, size_t size, u32 pte_flags)
-{
- unsigned long start = (unsigned long)_start;
- u32 *p;
- int numentries, i;
-
- numentries = size >> PAGE_SHIFT;
- p = find_pte(start);
-
- for (i = 0; i < numentries; i++) {
- p[i] &= ~PTE_MASK;
- p[i] |= pte_flags | PTE_TYPE_SMALL;
- }
-
- dma_flush_range(p, numentries * sizeof(u32));
- tlb_invalidate();
-
- return 0;
-}
-
int arch_remap_range(void *start, size_t size, unsigned flags)
{
+ u32 addr = (u32)start;
u32 pte_flags;
+ u32 pgd_flags;
+
+ BUG_ON(!IS_ALIGNED(addr, PAGE_SIZE));
switch (flags) {
case MAP_CACHED:
pte_flags = pte_flags_cached;
+ pgd_flags = PMD_SECT_DEF_CACHED;
break;
case MAP_UNCACHED:
pte_flags = pte_flags_uncached;
+ pgd_flags = PMD_SECT_DEF_UNCACHED;
+ break;
+ case ARCH_MAP_WRITECOMBINE:
+ pte_flags = pte_flags_wc;
+ pgd_flags = pgd_flags_wc;
break;
default:
return -EINVAL;
}
- return __remap_range(start, size, pte_flags);
+ while (size) {
+ const bool pgdir_size_aligned = IS_ALIGNED(addr, PGDIR_SIZE);
+ u32 *pgd = (u32 *)&ttb[pgd_index(addr)];
+ size_t chunk;
+
+ if (size >= PGDIR_SIZE && pgdir_size_aligned &&
+ !pgd_type_table(*pgd)) {
+ /*
+ * TODO: Add code to discard a page table and
+ * replace it with a section
+ */
+ chunk = PGDIR_SIZE;
+ *pgd = addr | pgd_flags;
+ dma_flush_range(pgd, sizeof(*pgd));
+ } else {
+ unsigned int num_ptes;
+ u32 *table = NULL;
+ unsigned int i;
+ u32 *pte;
+ /*
+ * We only want to cover pages up until next
+ * section boundary in case there we would
+ * have an opportunity to re-map the whole
+ * section (say if we got here becasue address
+ * was not aligned on PGDIR_SIZE boundary)
+ */
+ chunk = pgdir_size_aligned ?
+ PGDIR_SIZE : ALIGN(addr, PGDIR_SIZE) - addr;
+ /*
+ * At the same time we want to make sure that
+ * we don't go on remapping past requested
+ * size in case that is less that the distance
+ * to next PGDIR_SIZE boundary.
+ */
+ chunk = min(chunk, size);
+ num_ptes = chunk / PAGE_SIZE;
+
+ pte = find_pte(addr);
+ if (!pte) {
+ /*
+ * If PTE is not found it means that
+ * we needs to split this section and
+ * create a new page table for it
+ *
+ * NOTE: Here we assume that section
+ * we just split was mapped as cached
+ */
+ table = arm_create_pte(addr, pte_flags_cached);
+ pte = find_pte(addr);
+ BUG_ON(!pte);
+ /*
+ * We just split this section and
+ * modified it's Level 1 descriptor,
+ * so it needs to be flushed.
+ */
+ dma_flush_range(pgd, sizeof(*pgd));
+ }
+
+ for (i = 0; i < num_ptes; i++) {
+ pte[i] &= ~PTE_MASK;
+ pte[i] |= pte_flags | PTE_TYPE_SMALL;
+ }
+
+ if (table) {
+ /*
+ * If we just created a new page
+ * table, the whole table would have
+ * to be flushed, not just PTEs that
+ * we touched when re-mapping.
+ */
+ pte = table;
+ num_ptes = PTRS_PER_PTE;
+ }
+
+ dma_flush_range(pte, num_ptes * sizeof(u32));
+ }
+
+ addr += chunk;
+ size -= chunk;
+ }
+
+ tlb_invalidate();
+ return 0;
}
void *map_io_sections(unsigned long phys, void *_start, size_t size)
@@ -209,55 +274,6 @@ void *map_io_sections(unsigned long phys, void *_start, size_t size)
return _start;
}
-/*
- * remap the memory bank described by mem cachable and
- * bufferable
- */
-static int arm_mmu_remap_sdram(struct memory_bank *bank)
-{
- unsigned long phys = (unsigned long)bank->start;
- unsigned long ttb_start = pgd_index(phys);
- unsigned long ttb_end = ttb_start + pgd_index(bank->size);
- unsigned long num_ptes = bank->size / PAGE_SIZE;
- int i, pte;
- u32 *ptes;
-
- pr_debug("remapping SDRAM from 0x%08lx (size 0x%08lx)\n",
- phys, bank->size);
-
- /*
- * We replace each 1MiB section in this range with second level page
- * tables, therefore we must have 1Mib aligment here.
- */
- if (!IS_ALIGNED(phys, PGDIR_SIZE) || !IS_ALIGNED(bank->size, PGDIR_SIZE))
- return -EINVAL;
-
- ptes = xmemalign(PAGE_SIZE, num_ptes * sizeof(u32));
-
- pr_debug("ptes: 0x%p ttb_start: 0x%08lx ttb_end: 0x%08lx\n",
- ptes, ttb_start, ttb_end);
-
- for (i = 0; i < num_ptes; i++) {
- ptes[i] = (phys + i * PAGE_SIZE) | PTE_TYPE_SMALL |
- pte_flags_cached;
- }
-
- pte = 0;
-
- for (i = ttb_start; i < ttb_end; i++) {
- ttb[i] = (unsigned long)(&ptes[pte]) | PMD_TYPE_TABLE |
- (0 << 4);
- pte += PTRS_PER_PTE;
- }
-
- dma_flush_range(ttb, 0x4000);
- dma_flush_range(ptes, num_ptes * sizeof(u32));
-
- tlb_invalidate();
-
- return 0;
-}
-
#define ARM_HIGH_VECTORS 0xffff0000
#define ARM_LOW_VECTORS 0x0
@@ -423,10 +439,12 @@ static int mmu_init(void)
if (cpu_architecture() >= CPU_ARCH_ARMv7) {
pte_flags_cached = PTE_FLAGS_CACHED_V7;
pte_flags_wc = PTE_FLAGS_WC_V7;
+ pgd_flags_wc = PGD_FLAGS_WC_V7;
pte_flags_uncached = PTE_FLAGS_UNCACHED_V7;
} else {
pte_flags_cached = PTE_FLAGS_CACHED_V4;
pte_flags_wc = PTE_FLAGS_UNCACHED_V4;
+ pgd_flags_wc = PMD_SECT_DEF_UNCACHED;
pte_flags_uncached = PTE_FLAGS_UNCACHED_V4;
}
@@ -477,13 +495,6 @@ static int mmu_init(void)
__mmu_cache_on();
- /*
- * Now that we have the MMU and caches on remap sdram again using
- * page tables
- */
- for_each_memory_bank(bank)
- arm_mmu_remap_sdram(bank);
-
return 0;
}
mmu_initcall(mmu_init);
@@ -501,7 +512,7 @@ void mmu_disable(void)
__mmu_cache_off();
}
-static void *dma_alloc(size_t size, dma_addr_t *dma_handle, uint32_t pte_flags)
+static void *dma_alloc(size_t size, dma_addr_t *dma_handle, unsigned flags)
{
void *ret;
@@ -512,19 +523,19 @@ static void *dma_alloc(size_t size, dma_addr_t *dma_handle, uint32_t pte_flags)
dma_inv_range((unsigned long)ret, (unsigned long)ret + size);
- __remap_range(ret, size, pte_flags);
+ arch_remap_range(ret, size, flags);
return ret;
}
void *dma_alloc_coherent(size_t size, dma_addr_t *dma_handle)
{
- return dma_alloc(size, dma_handle, pte_flags_uncached);
+ return dma_alloc(size, dma_handle, MAP_UNCACHED);
}
void *dma_alloc_writecombine(size_t size, dma_addr_t *dma_handle)
{
- return dma_alloc(size, dma_handle, pte_flags_wc);
+ return dma_alloc(size, dma_handle, ARCH_MAP_WRITECOMBINE);
}
unsigned long virt_to_phys(volatile void *virt)
@@ -540,7 +551,7 @@ void *phys_to_virt(unsigned long phys)
void dma_free_coherent(void *mem, dma_addr_t dma_handle, size_t size)
{
size = PAGE_ALIGN(size);
- __remap_range(mem, size, pte_flags_cached);
+ arch_remap_range(mem, size, MAP_CACHED);
free(mem);
}
--
2.17.0
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 32+ messages in thread
* [PATCH v4 28/29] ARM: mmu: Introduce ARM_TTB_SIZE
2018-05-22 3:14 [PATCH v4 00/29] ARM MMU code improvements and on-demand PTE allocation Andrey Smirnov
` (26 preceding siblings ...)
2018-05-22 3:15 ` [PATCH v4 27/29] ARM: mmu: Implement on-demand PTE allocation Andrey Smirnov
@ 2018-05-22 3:15 ` Andrey Smirnov
2018-05-22 3:15 ` [PATCH v4 29/29] ARM: mmu: Do not try to pick early TTB up Andrey Smirnov
2018-05-22 7:16 ` [PATCH v4 00/29] ARM MMU code improvements and on-demand PTE allocation Sascha Hauer
29 siblings, 0 replies; 32+ messages in thread
From: Andrey Smirnov @ 2018-05-22 3:15 UTC (permalink / raw)
To: barebox; +Cc: Andrey Smirnov
Commit 1c33aacf8a247ab45814b43ac0ca903677afffae ("ARM: use memalign to
allocate page table"), reasonalby changed TTB allocation size from
SZ_32K to SZ_16K (TTB's real size), but it also changed alignment from
SZ_16K to SZ_64K for unclear reasons.
Reading various TTBR related ARM documentation it seems that worst
case alignment for it is 16KiB (bits [0, 13 - N] must be zero) which
also matches early TTB allocation code.
Since both early and regular MMU code has to share this paramter,
introduce ARM_TTB_SIZE and use it in both cases for both size and
alignment.
Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
---
arch/arm/cpu/mmu.c | 2 +-
arch/arm/include/asm/barebox-arm.h | 8 +++++++-
2 files changed, 8 insertions(+), 2 deletions(-)
diff --git a/arch/arm/cpu/mmu.c b/arch/arm/cpu/mmu.c
index 5f82b63ca..a89f420f2 100644
--- a/arch/arm/cpu/mmu.c
+++ b/arch/arm/cpu/mmu.c
@@ -469,7 +469,7 @@ static int mmu_init(void)
pr_crit("Critical Error: Can't request SDRAM region for ttb at %p\n",
ttb);
} else {
- ttb = xmemalign(0x10000, 0x4000);
+ ttb = xmemalign(ARM_TTB_SIZE, ARM_TTB_SIZE);
}
pr_debug("ttb: 0x%p\n", ttb);
diff --git a/arch/arm/include/asm/barebox-arm.h b/arch/arm/include/asm/barebox-arm.h
index f55c8bb0c..d97f68c54 100644
--- a/arch/arm/include/asm/barebox-arm.h
+++ b/arch/arm/include/asm/barebox-arm.h
@@ -32,6 +32,12 @@
#include <linux/compiler.h>
#include <asm/barebox-arm-head.h>
+/*
+ * We have a 4GiB address space split into 1MiB sections, with each
+ * section header taking 4 bytes
+ */
+#define ARM_TTB_SIZE (SZ_4G / SZ_1M * sizeof(u32))
+
unsigned long get_runtime_offset(void);
/* global_variable_offset() - Access global variables when not running at link address
@@ -117,7 +123,7 @@ static inline unsigned long arm_mem_ttb(unsigned long membase,
unsigned long endmem)
{
endmem = arm_mem_stack(membase, endmem);
- endmem = ALIGN_DOWN(endmem, SZ_16K) - SZ_16K;
+ endmem = ALIGN_DOWN(endmem, ARM_TTB_SIZE) - ARM_TTB_SIZE;
return endmem;
}
--
2.17.0
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 32+ messages in thread
* [PATCH v4 29/29] ARM: mmu: Do not try to pick early TTB up
2018-05-22 3:14 [PATCH v4 00/29] ARM MMU code improvements and on-demand PTE allocation Andrey Smirnov
` (27 preceding siblings ...)
2018-05-22 3:15 ` [PATCH v4 28/29] ARM: mmu: Introduce ARM_TTB_SIZE Andrey Smirnov
@ 2018-05-22 3:15 ` Andrey Smirnov
2018-05-22 7:16 ` [PATCH v4 00/29] ARM MMU code improvements and on-demand PTE allocation Sascha Hauer
29 siblings, 0 replies; 32+ messages in thread
From: Andrey Smirnov @ 2018-05-22 3:15 UTC (permalink / raw)
To: barebox; +Cc: Andrey Smirnov
TODO: Fix the message below
diff --git a/arch/arm/cpu/mmu.c b/arch/arm/cpu/mmu.c
index aa1a7c09c..650e20828 100644
--- a/arch/arm/cpu/mmu.c
+++ b/arch/arm/cpu/mmu.c
@@ -419,6 +419,11 @@ static void vectors_init(void)
create_vector_table(ARM_LOW_VECTORS);
}
+static void dump_bank(struct memory_bank *b)
+{
+ pr_crit("0x%08lx - 0x%08lx\n", b->start, b->start + b->size - 1);
+}
+
/*
* Prepare MMU for usage enable it.
*/
@@ -494,6 +499,7 @@ static int mmu_init(void)
* below
*/
for_each_memory_bank(bank) {
+ dump_bank(bank);
create_sections(ttb, bank->start, bank->size,
PMD_SECT_DEF_CACHED);
__mmu_cache_flush();
@@ -501,6 +507,10 @@ static int mmu_init(void)
__mmu_cache_on();
+ pr_info("%s %d\n", __func__, __LINE__);
+ for_each_memory_bank(bank)
+ dump_bank(bank);
+
return 0;
}
mmu_initcall(mmu_init);
barebox 2018.04.0-00195-ge7ba82254-dirty #552 Thu Apr 19 11:32:56 PDT 2018
Board: VF610 OCRAM
i.MX clk 9: register failed with -22
i.MX clk 10: register failed with -22
i.MX clk 160: register failed with -22
mmu: Critical Error: Can't request SDRAM region for ttb at 3f078000
mmu: 0x80000000 - 0x9fffffff
mmu: 0x80000000 - 0x9fffffff
mmu: mmu_init 510
unable to handle NULL pointer dereference at address 0x00000000
pc : [<3f01b7da>] lr : [<3f01b7d1>]
sp : 3f07ff38 ip : 00000000 fp : 00000000
r10: 00000000 r9 : 3f000009 r8 : 00000c0e
r7 : 3f0258aa r6 : 3f0258aa r5 : 3f413b80 r4 : 00000000
r3 : 3f02f1b4 r2 : b0000000 r1 : 0000000a r0 : 00000012
Flags: nZCv IRQs off FIQs off Mode SVC_32
[<3f01b7da>] (mmu_init+0xce/0x168) from [<3f000b9d>] (start_barebox+0x45/0x98)
[<3f000b9d>] (start_barebox+0x45/0x98) from [<3f01bb19>] (barebox_non_pbl_start+0x95/0xd4)
[<3f01bb19>] (barebox_non_pbl_start+0x95/0xd4) from [<3f01bb71>] (barebox_arm_entry+0x19/0x1c)
[<3f01d085>] (unwind_backtrace+0x1/0x58) from [<3f000e45>] (panic+0x1d/0x2c)
[<3f000e45>] (panic+0x1d/0x2c) from [<3f01b5d1>] (do_exception+0xd/0x10)
[<3f01b5d1>] (do_exception+0xd/0x10) from [<3f01b631>] (do_data_abort+0x21/0x2c)
[<3f01b631>] (do_data_abort+0x21/0x2c) from [<3f01b3d4>] (do_abort_6+0x48/0x54)
\### ERROR ### Please RESET the board ###
barebox 2018.04.0-00195-ge7ba82254-dirty #553 Thu Apr 19 12:03:17 PDT 2018
Board: VF610 OCRAM
i.MX clk 9: register failed with -22
i.MX clk 10: register failed with -22
i.MX clk 160: register failed with -22
mmu: 0x80000000 - 0x9fffffff
mmu: mmu_init 493
mmu: 0x80000000 - 0x9fffffff
Error: Cannot request SDRAM region for stack
Warning: Using dummy clocksource
malloc space: 0x3f400000 -> 0x3f47ffff (size 512 KiB)
environment load /dev/env0: No such file or directory
Maybe you have to create the partition.
running /env/bin/init...
Hit any key to stop autoboot: 3
barebox@VF610 OCRAM:/
Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
---
arch/arm/cpu/mmu.c | 27 +++++----------------------
1 file changed, 5 insertions(+), 22 deletions(-)
diff --git a/arch/arm/cpu/mmu.c b/arch/arm/cpu/mmu.c
index a89f420f2..bb25f6b4f 100644
--- a/arch/arm/cpu/mmu.c
+++ b/arch/arm/cpu/mmu.c
@@ -450,36 +450,20 @@ static int mmu_init(void)
if (get_cr() & CR_M) {
/*
- * Early MMU code has already enabled the MMU. We assume a
- * flat 1:1 section mapping in this case.
+ * Early MMU code has already enabled the MMU. To
+ * start form a clean slate we need to disable it
+ * first.
*/
- asm volatile ("mrc p15,0,%0,c2,c0,0" : "=r"(ttb));
-
- /* Clear unpredictable bits [13:0] */
- ttb = (uint32_t *)((unsigned long)ttb & ~0x3fff);
-
- if (!request_sdram_region("ttb", (unsigned long)ttb, SZ_16K))
- /*
- * This can mean that:
- * - the early MMU code has put the ttb into a place
- * which we don't have inside our available memory
- * - Somebody else has occupied the ttb region which means
- * the ttb will get corrupted.
- */
- pr_crit("Critical Error: Can't request SDRAM region for ttb at %p\n",
- ttb);
- } else {
- ttb = xmemalign(ARM_TTB_SIZE, ARM_TTB_SIZE);
+ mmu_disable();
}
+ ttb = xmemalign(ARM_TTB_SIZE, ARM_TTB_SIZE);
pr_debug("ttb: 0x%p\n", ttb);
set_ttbr(ttb);
set_domain(DOMAIN_MANAGER);
create_flat_mapping(ttb);
- __mmu_cache_flush();
-
vectors_init();
/*
@@ -490,7 +474,6 @@ static int mmu_init(void)
for_each_memory_bank(bank) {
create_sections(ttb, bank->start, bank->start + bank->size - 1,
PMD_SECT_DEF_CACHED);
- __mmu_cache_flush();
}
__mmu_cache_on();
--
2.17.0
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 32+ messages in thread
* Re: [PATCH v4 00/29] ARM MMU code improvements and on-demand PTE allocation
2018-05-22 3:14 [PATCH v4 00/29] ARM MMU code improvements and on-demand PTE allocation Andrey Smirnov
` (28 preceding siblings ...)
2018-05-22 3:15 ` [PATCH v4 29/29] ARM: mmu: Do not try to pick early TTB up Andrey Smirnov
@ 2018-05-22 7:16 ` Sascha Hauer
2018-05-22 18:37 ` Andrey Smirnov
29 siblings, 1 reply; 32+ messages in thread
From: Sascha Hauer @ 2018-05-22 7:16 UTC (permalink / raw)
To: Andrey Smirnov; +Cc: barebox
On Mon, May 21, 2018 at 08:14:41PM -0700, Andrey Smirnov wrote:
> Everyone:
>
> With exeception of patch 27/28, all patches in this series are just
> small improvements(IMHO) that I made while working with ARM MMU code.
>
> Patch 27/28, OTOH, brings a bit of a change to how MMU code allocates
> PTEs, postponing that until the users of DMA API actually request
> that.
Applied, thanks. I skipped 29/29 which hasn't been part of the other
series and doesn't seem to be ready yet.
Sascha
--
Pengutronix e.K. | |
Industrial Linux Solutions | http://www.pengutronix.de/ |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 32+ messages in thread
* Re: [PATCH v4 00/29] ARM MMU code improvements and on-demand PTE allocation
2018-05-22 7:16 ` [PATCH v4 00/29] ARM MMU code improvements and on-demand PTE allocation Sascha Hauer
@ 2018-05-22 18:37 ` Andrey Smirnov
0 siblings, 0 replies; 32+ messages in thread
From: Andrey Smirnov @ 2018-05-22 18:37 UTC (permalink / raw)
To: Sascha Hauer; +Cc: Barebox List
On Tue, May 22, 2018 at 12:16 AM, Sascha Hauer <s.hauer@pengutronix.de> wrote:
> On Mon, May 21, 2018 at 08:14:41PM -0700, Andrey Smirnov wrote:
>> Everyone:
>>
>> With exeception of patch 27/28, all patches in this series are just
>> small improvements(IMHO) that I made while working with ARM MMU code.
>>
>> Patch 27/28, OTOH, brings a bit of a change to how MMU code allocates
>> PTEs, postponing that until the users of DMA API actually request
>> that.
>
> Applied, thanks. I skipped 29/29 which hasn't been part of the other
> series and doesn't seem to be ready yet.
>
Ugh, yes, thank you, 29 was not supposed to be in a series. My bad.
Sorry about that.
Thanks,
Andrey Smirnov
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 32+ messages in thread