uboot-mediatek: unbreak build with binman
[openwrt/staging/dedeckeh.git] / package / boot / uboot-mediatek / patches / 001-mtk-0004-mips-add-support-for-noncached_alloc.patch
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()
5
6 This patch adds support for noncached_alloc() which was only supported by
7 ARM platform.
8
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()
14
15 Reviewed-by: Daniel Schwierzeck <daniel.schwierzeck@gmail.com>
16 Signed-off-by: Weijie Gao <weijie.gao@mediatek.com>
17 ---
18 arch/mips/include/asm/system.h | 20 ++++++++++++++++
19 arch/mips/lib/cache.c | 43 ++++++++++++++++++++++++++++++++++
20 2 files changed, 63 insertions(+)
21
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
25 : "=&r"(tmp));
26 }
27
28 +#ifdef CONFIG_SYS_NONCACHED_MEMORY
29 +/* 1MB granularity */
30 +#define MMU_SECTION_SHIFT 20
31 +#define MMU_SECTION_SIZE (1 << MMU_SECTION_SHIFT)
32 +
33 +/**
34 + * noncached_init() - Initialize non-cached memory region
35 + *
36 + * Initialize non-cached memory area. This memory region will be typically
37 + * located right below the malloc() area and be accessed from KSEG1.
38 + *
39 + * It is called during the generic post-relocation init sequence.
40 + *
41 + * Return: 0 if OK
42 + */
43 +int noncached_init(void);
44 +
45 +phys_addr_t noncached_alloc(size_t size, size_t align);
46 +#endif /* CONFIG_SYS_NONCACHED_MEMORY */
47 +
48 #endif /* _ASM_SYSTEM_H */
49 --- a/arch/mips/lib/cache.c
50 +++ b/arch/mips/lib/cache.c
51 @@ -6,6 +6,7 @@
52
53 #include <common.h>
54 #include <cpu_func.h>
55 +#include <malloc.h>
56 #include <asm/cache.h>
57 #include <asm/cacheops.h>
58 #include <asm/cm.h>
59 @@ -197,3 +198,45 @@ void dcache_disable(void)
60 /* ensure the pipeline doesn't contain now-invalid instructions */
61 instruction_hazard_barrier();
62 }
63 +
64 +#ifdef CONFIG_SYS_NONCACHED_MEMORY
65 +static unsigned long noncached_start;
66 +static unsigned long noncached_end;
67 +static unsigned long noncached_next;
68 +
69 +void noncached_set_region(void)
70 +{
71 +}
72 +
73 +int noncached_init(void)
74 +{
75 + phys_addr_t start, end;
76 + size_t size;
77 +
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);
81 + start = end - size;
82 +
83 + debug("mapping memory %pa-%pa non-cached\n", &start, &end);
84 +
85 + noncached_start = start;
86 + noncached_end = end;
87 + noncached_next = start;
88 +
89 + return 0;
90 +}
91 +
92 +phys_addr_t noncached_alloc(size_t size, size_t align)
93 +{
94 + phys_addr_t next = ALIGN(noncached_next, align);
95 +
96 + if (next >= noncached_end || (noncached_end - next) < size)
97 + return 0;
98 +
99 + debug("allocated %zu bytes of uncached memory @%pa\n", size, &next);
100 + noncached_next = next + size;
101 +
102 + return CKSEG1ADDR(next);
103 +}
104 +#endif /* CONFIG_SYS_NONCACHED_MEMORY */