Skip to content

Commit 2948d9c

Browse files
hackpascaldanielschwierzeck
authored andcommitted
mips: add support for noncached_alloc()
This patch adds support for noncached_alloc() which was only supported by ARM platform. Unlike the ARM platform, MMU is not used in u-boot for MIPS. Instead, KSEG is provided to access uncached memory. So most code of this patch is copied from cache.c of ARM platform, with only two differences: 1. MMU is untouched in noncached_set_region() 2. Address returned by noncached_alloc() is converted using KSEG1ADDR() Reviewed-by: Daniel Schwierzeck <[email protected]> Signed-off-by: Weijie Gao <[email protected]>
1 parent 9a3bbb0 commit 2948d9c

File tree

2 files changed

+63
-0
lines changed

2 files changed

+63
-0
lines changed

arch/mips/include/asm/system.h

+20
Original file line numberDiff line numberDiff line change
@@ -282,4 +282,24 @@ static inline void instruction_hazard_barrier(void)
282282
: "=&r"(tmp));
283283
}
284284

285+
#ifdef CONFIG_SYS_NONCACHED_MEMORY
286+
/* 1MB granularity */
287+
#define MMU_SECTION_SHIFT 20
288+
#define MMU_SECTION_SIZE (1 << MMU_SECTION_SHIFT)
289+
290+
/**
291+
* noncached_init() - Initialize non-cached memory region
292+
*
293+
* Initialize non-cached memory area. This memory region will be typically
294+
* located right below the malloc() area and be accessed from KSEG1.
295+
*
296+
* It is called during the generic post-relocation init sequence.
297+
*
298+
* Return: 0 if OK
299+
*/
300+
int noncached_init(void);
301+
302+
phys_addr_t noncached_alloc(size_t size, size_t align);
303+
#endif /* CONFIG_SYS_NONCACHED_MEMORY */
304+
285305
#endif /* _ASM_SYSTEM_H */

arch/mips/lib/cache.c

+43
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
#include <common.h>
88
#include <cpu_func.h>
9+
#include <malloc.h>
910
#include <asm/cache.h>
1011
#include <asm/cacheops.h>
1112
#include <asm/cm.h>
@@ -197,3 +198,45 @@ void dcache_disable(void)
197198
/* ensure the pipeline doesn't contain now-invalid instructions */
198199
instruction_hazard_barrier();
199200
}
201+
202+
#ifdef CONFIG_SYS_NONCACHED_MEMORY
203+
static unsigned long noncached_start;
204+
static unsigned long noncached_end;
205+
static unsigned long noncached_next;
206+
207+
void noncached_set_region(void)
208+
{
209+
}
210+
211+
int noncached_init(void)
212+
{
213+
phys_addr_t start, end;
214+
size_t size;
215+
216+
/* If this calculation changes, update board_f.c:reserve_noncached() */
217+
end = ALIGN(mem_malloc_start, MMU_SECTION_SIZE) - MMU_SECTION_SIZE;
218+
size = ALIGN(CONFIG_SYS_NONCACHED_MEMORY, MMU_SECTION_SIZE);
219+
start = end - size;
220+
221+
debug("mapping memory %pa-%pa non-cached\n", &start, &end);
222+
223+
noncached_start = start;
224+
noncached_end = end;
225+
noncached_next = start;
226+
227+
return 0;
228+
}
229+
230+
phys_addr_t noncached_alloc(size_t size, size_t align)
231+
{
232+
phys_addr_t next = ALIGN(noncached_next, align);
233+
234+
if (next >= noncached_end || (noncached_end - next) < size)
235+
return 0;
236+
237+
debug("allocated %zu bytes of uncached memory @%pa\n", size, &next);
238+
noncached_next = next + size;
239+
240+
return CKSEG1ADDR(next);
241+
}
242+
#endif /* CONFIG_SYS_NONCACHED_MEMORY */

0 commit comments

Comments
 (0)