]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - arch/arm/lib/cache.c
20c708a7c3edfe7239aa673205e61c65602031e8
[karo-tx-uboot.git] / arch / arm / lib / cache.c
1 /*
2  * (C) Copyright 2002
3  * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
4  *
5  * SPDX-License-Identifier:     GPL-2.0+
6  */
7
8 /* for now: just dummy functions to satisfy the linker */
9
10 #include <common.h>
11 #include <malloc.h>
12
13 __weak void flush_cache(unsigned long start, unsigned long size)
14 {
15 #if defined(CONFIG_CPU_ARM1136)
16
17 #if !defined(CONFIG_SYS_ICACHE_OFF)
18         asm("mcr p15, 0, r1, c7, c5, 0"); /* invalidate I cache */
19 #endif
20
21 #if !defined(CONFIG_SYS_DCACHE_OFF)
22         asm("mcr p15, 0, r1, c7, c14, 0"); /* Clean+invalidate D cache */
23 #endif
24
25 #endif /* CONFIG_CPU_ARM1136 */
26
27 #ifdef CONFIG_CPU_ARM926EJS
28 #if !(defined(CONFIG_SYS_ICACHE_OFF) && defined(CONFIG_SYS_DCACHE_OFF))
29         asm(
30                 /* test and clean, page 2-23 of arm926ejs manual */
31                 "0: mrc p15, 0, r15, c7, c10, 3\n\t" "bne 0b\n"
32                 /* flush write buffer as well (page 2-22) */
33                 "mcr p15, 0, %0, c7, c10, 4" : : "r"(0) : "memory"
34                 );
35 #endif
36 #endif /* CONFIG_CPU_ARM926EJS */
37         return;
38 }
39
40 /*
41  * Default implementation:
42  * do a range flush for the entire range
43  */
44 __weak void flush_dcache_all(void)
45 {
46         flush_cache(0, ~0);
47 }
48
49 /*
50  * Default implementation of enable_caches()
51  * Real implementation should be in platform code
52  */
53 __weak void enable_caches(void)
54 {
55         puts("WARNING: Caches not enabled\n");
56 }
57
58 #ifdef CONFIG_SYS_NONCACHED_MEMORY
59 /*
60  * Reserve one MMU section worth of address space below the malloc() area that
61  * will be mapped uncached.
62  */
63 static unsigned long noncached_start;
64 static unsigned long noncached_end;
65 static unsigned long noncached_next;
66
67 void noncached_init(void)
68 {
69         phys_addr_t start, end;
70         size_t size;
71
72         end = ALIGN(mem_malloc_start, MMU_SECTION_SIZE) - MMU_SECTION_SIZE;
73         size = ALIGN(CONFIG_SYS_NONCACHED_MEMORY, MMU_SECTION_SIZE);
74         start = end - size;
75
76         debug("mapping memory %pa-%pa non-cached\n", &start, &end);
77
78         noncached_start = start;
79         noncached_end = end;
80         noncached_next = start;
81
82 #ifndef CONFIG_SYS_DCACHE_OFF
83         mmu_set_region_dcache_behaviour(noncached_start, size, DCACHE_OFF);
84 #endif
85 }
86
87 phys_addr_t noncached_alloc(size_t size, size_t align)
88 {
89         phys_addr_t next = ALIGN(noncached_next, align);
90
91         if (next >= noncached_end || (noncached_end - next) < size)
92                 return 0;
93
94         debug("allocated %zu bytes of uncached memory @%pa\n", size, &next);
95         noncached_next = next + size;
96
97         return next;
98 }
99 #endif /* CONFIG_SYS_NONCACHED_MEMORY */