xref: /rk3399_rockchip-uboot/arch/arm/lib/cache.c (revision 633b6ccedf9d536fd93299b2207a5227dedd987c)
1ea0364f1SPeter Tyser /*
2ea0364f1SPeter Tyser  * (C) Copyright 2002
3ea0364f1SPeter Tyser  * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
4ea0364f1SPeter Tyser  *
51a459660SWolfgang Denk  * SPDX-License-Identifier:	GPL-2.0+
6ea0364f1SPeter Tyser  */
7ea0364f1SPeter Tyser 
8ea0364f1SPeter Tyser /* for now: just dummy functions to satisfy the linker */
9ea0364f1SPeter Tyser 
10ea0364f1SPeter Tyser #include <common.h>
111dfdd9baSThierry Reding #include <malloc.h>
12ea0364f1SPeter Tyser 
13*633b6cceSWu, Josh /*
14*633b6cceSWu, Josh  * Flush range from all levels of d-cache/unified-cache.
15*633b6cceSWu, Josh  * Affects the range [start, start + size - 1].
16*633b6cceSWu, Josh  */
17fcfddfd5SJeroen Hofstee __weak void flush_cache(unsigned long start, unsigned long size)
18ea0364f1SPeter Tyser {
19*633b6cceSWu, Josh 	flush_dcache_range(start, start + size);
20ea0364f1SPeter Tyser }
21e05f0079SAneesh V 
22e05f0079SAneesh V /*
23e05f0079SAneesh V  * Default implementation:
24e05f0079SAneesh V  * do a range flush for the entire range
25e05f0079SAneesh V  */
26fcfddfd5SJeroen Hofstee __weak void flush_dcache_all(void)
27e05f0079SAneesh V {
28e05f0079SAneesh V 	flush_cache(0, ~0);
29e05f0079SAneesh V }
30cba4b180SAneesh V 
31cba4b180SAneesh V /*
32cba4b180SAneesh V  * Default implementation of enable_caches()
33cba4b180SAneesh V  * Real implementation should be in platform code
34cba4b180SAneesh V  */
35fcfddfd5SJeroen Hofstee __weak void enable_caches(void)
36cba4b180SAneesh V {
37cba4b180SAneesh V 	puts("WARNING: Caches not enabled\n");
38cba4b180SAneesh V }
391dfdd9baSThierry Reding 
40387871a1SWu, Josh __weak void invalidate_dcache_range(unsigned long start, unsigned long stop)
41387871a1SWu, Josh {
42387871a1SWu, Josh 	/* An empty stub, real implementation should be in platform code */
43387871a1SWu, Josh }
44387871a1SWu, Josh __weak void flush_dcache_range(unsigned long start, unsigned long stop)
45387871a1SWu, Josh {
46387871a1SWu, Josh 	/* An empty stub, real implementation should be in platform code */
47387871a1SWu, Josh }
48387871a1SWu, Josh 
491dfdd9baSThierry Reding #ifdef CONFIG_SYS_NONCACHED_MEMORY
501dfdd9baSThierry Reding /*
511dfdd9baSThierry Reding  * Reserve one MMU section worth of address space below the malloc() area that
521dfdd9baSThierry Reding  * will be mapped uncached.
531dfdd9baSThierry Reding  */
541dfdd9baSThierry Reding static unsigned long noncached_start;
551dfdd9baSThierry Reding static unsigned long noncached_end;
561dfdd9baSThierry Reding static unsigned long noncached_next;
571dfdd9baSThierry Reding 
581dfdd9baSThierry Reding void noncached_init(void)
591dfdd9baSThierry Reding {
601dfdd9baSThierry Reding 	phys_addr_t start, end;
611dfdd9baSThierry Reding 	size_t size;
621dfdd9baSThierry Reding 
631dfdd9baSThierry Reding 	end = ALIGN(mem_malloc_start, MMU_SECTION_SIZE) - MMU_SECTION_SIZE;
641dfdd9baSThierry Reding 	size = ALIGN(CONFIG_SYS_NONCACHED_MEMORY, MMU_SECTION_SIZE);
651dfdd9baSThierry Reding 	start = end - size;
661dfdd9baSThierry Reding 
671dfdd9baSThierry Reding 	debug("mapping memory %pa-%pa non-cached\n", &start, &end);
681dfdd9baSThierry Reding 
691dfdd9baSThierry Reding 	noncached_start = start;
701dfdd9baSThierry Reding 	noncached_end = end;
711dfdd9baSThierry Reding 	noncached_next = start;
721dfdd9baSThierry Reding 
731dfdd9baSThierry Reding #ifndef CONFIG_SYS_DCACHE_OFF
741dfdd9baSThierry Reding 	mmu_set_region_dcache_behaviour(noncached_start, size, DCACHE_OFF);
751dfdd9baSThierry Reding #endif
761dfdd9baSThierry Reding }
771dfdd9baSThierry Reding 
781dfdd9baSThierry Reding phys_addr_t noncached_alloc(size_t size, size_t align)
791dfdd9baSThierry Reding {
801dfdd9baSThierry Reding 	phys_addr_t next = ALIGN(noncached_next, align);
811dfdd9baSThierry Reding 
821dfdd9baSThierry Reding 	if (next >= noncached_end || (noncached_end - next) < size)
831dfdd9baSThierry Reding 		return 0;
841dfdd9baSThierry Reding 
851dfdd9baSThierry Reding 	debug("allocated %zu bytes of uncached memory @%pa\n", size, &next);
861dfdd9baSThierry Reding 	noncached_next = next + size;
871dfdd9baSThierry Reding 
881dfdd9baSThierry Reding 	return next;
891dfdd9baSThierry Reding }
901dfdd9baSThierry Reding #endif /* CONFIG_SYS_NONCACHED_MEMORY */
91