1 From d7cfa1cb5602a1d936df36ee70869753835de28e Mon Sep 17 00:00:00 2001
2 From: Weijie Gao <weijie.gao@mediatek.com>
3 Date: Fri, 20 May 2022 11:21:51 +0800
4 Subject: [PATCH 04/25] mips: add support for noncached_alloc()
6 This patch adds support for noncached_alloc() which was only supported by
9 Unlike the ARM platform, MMU is not used in u-boot for MIPS. Instead, KSEG
10 is provided to access uncached memory. So most code of this patch is copied
11 from cache.c of ARM platform, with only two differences:
12 1. MMU is untouched in noncached_set_region()
13 2. Address returned by noncached_alloc() is converted using KSEG1ADDR()
15 Reviewed-by: Daniel Schwierzeck <daniel.schwierzeck@gmail.com>
16 Signed-off-by: Weijie Gao <weijie.gao@mediatek.com>
18 arch/mips/include/asm/system.h | 20 ++++++++++++++++
19 arch/mips/lib/cache.c | 43 ++++++++++++++++++++++++++++++++++
20 2 files changed, 63 insertions(+)
22 --- a/arch/mips/include/asm/system.h
23 +++ b/arch/mips/include/asm/system.h
24 @@ -282,4 +282,24 @@ static inline void instruction_hazard_ba
28 +#ifdef CONFIG_SYS_NONCACHED_MEMORY
29 +/* 1MB granularity */
30 +#define MMU_SECTION_SHIFT 20
31 +#define MMU_SECTION_SIZE (1 << MMU_SECTION_SHIFT)
34 + * noncached_init() - Initialize non-cached memory region
36 + * Initialize non-cached memory area. This memory region will be typically
37 + * located right below the malloc() area and be accessed from KSEG1.
39 + * It is called during the generic post-relocation init sequence.
43 +int noncached_init(void);
45 +phys_addr_t noncached_alloc(size_t size, size_t align);
46 +#endif /* CONFIG_SYS_NONCACHED_MEMORY */
48 #endif /* _ASM_SYSTEM_H */
49 --- a/arch/mips/lib/cache.c
50 +++ b/arch/mips/lib/cache.c
56 #include <asm/cache.h>
57 #include <asm/cacheops.h>
59 @@ -197,3 +198,45 @@ void dcache_disable(void)
60 /* ensure the pipeline doesn't contain now-invalid instructions */
61 instruction_hazard_barrier();
64 +#ifdef CONFIG_SYS_NONCACHED_MEMORY
65 +static unsigned long noncached_start;
66 +static unsigned long noncached_end;
67 +static unsigned long noncached_next;
69 +void noncached_set_region(void)
73 +int noncached_init(void)
75 + phys_addr_t start, end;
78 + /* If this calculation changes, update board_f.c:reserve_noncached() */
79 + end = ALIGN(mem_malloc_start, MMU_SECTION_SIZE) - MMU_SECTION_SIZE;
80 + size = ALIGN(CONFIG_SYS_NONCACHED_MEMORY, MMU_SECTION_SIZE);
83 + debug("mapping memory %pa-%pa non-cached\n", &start, &end);
85 + noncached_start = start;
86 + noncached_end = end;
87 + noncached_next = start;
92 +phys_addr_t noncached_alloc(size_t size, size_t align)
94 + phys_addr_t next = ALIGN(noncached_next, align);
96 + if (next >= noncached_end || (noncached_end - next) < size)
99 + debug("allocated %zu bytes of uncached memory @%pa\n", size, &next);
100 + noncached_next = next + size;
102 + return CKSEG1ADDR(next);
104 +#endif /* CONFIG_SYS_NONCACHED_MEMORY */