3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
5 * SPDX-License-Identifier: GPL-2.0+
8 /* for now: just dummy functions to satisfy the linker */
13 __weak void flush_cache(unsigned long start, unsigned long size)
15 #if defined(CONFIG_CPU_ARM1136)
17 #if !defined(CONFIG_SYS_ICACHE_OFF)
18 asm("mcr p15, 0, r1, c7, c5, 0"); /* invalidate I cache */
21 #if !defined(CONFIG_SYS_DCACHE_OFF)
22 asm("mcr p15, 0, r1, c7, c14, 0"); /* Clean+invalidate D cache */
25 #endif /* CONFIG_CPU_ARM1136 */
27 #ifdef CONFIG_CPU_ARM926EJS
28 #if !(defined(CONFIG_SYS_ICACHE_OFF) && defined(CONFIG_SYS_DCACHE_OFF))
29 /* test and clean, page 2-23 of arm926ejs manual */
30 asm("0: mrc p15, 0, r15, c7, c10, 3\n\t" "bne 0b\n" : : : "memory");
31 /* disable write buffer as well (page 2-22) */
32 asm("mcr p15, 0, %0, c7, c10, 4" : : "r" (0));
34 #endif /* CONFIG_CPU_ARM926EJS */
39 * Default implementation:
40 * do a range flush for the entire range
42 __weak void flush_dcache_all(void)
48 * Default implementation of enable_caches()
49 * Real implementation should be in platform code
51 __weak void enable_caches(void)
53 puts("WARNING: Caches not enabled\n");
56 __weak void invalidate_dcache_range(unsigned long start, unsigned long stop)
58 /* An empty stub, real implementation should be in platform code */
60 __weak void flush_dcache_range(unsigned long start, unsigned long stop)
62 /* An empty stub, real implementation should be in platform code */
65 #ifdef CONFIG_SYS_NONCACHED_MEMORY
67 * Reserve one MMU section worth of address space below the malloc() area that
68 * will be mapped uncached.
70 static unsigned long noncached_start;
71 static unsigned long noncached_end;
72 static unsigned long noncached_next;
74 void noncached_init(void)
76 phys_addr_t start, end;
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;
87 noncached_next = start;
89 #ifndef CONFIG_SYS_DCACHE_OFF
90 mmu_set_region_dcache_behaviour(noncached_start, size, DCACHE_OFF);
94 phys_addr_t noncached_alloc(size_t size, size_t align)
96 phys_addr_t next = ALIGN(noncached_next, align);
98 if (next >= noncached_end || (noncached_end - next) < size)
101 debug("allocated %zu bytes of uncached memory @%pa\n", size, &next);
102 noncached_next = next + size;
106 #endif /* CONFIG_SYS_NONCACHED_MEMORY */