blob: d330b09434a46df1ab6505bf8b46c54e90ccfa21 [file] [log] [blame]
wdenkedc48b62002-09-08 17:56:50 +00001/*
2 * (C) Copyright 2002
3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
4 *
Wolfgang Denkd79de1d2013-07-08 09:37:19 +02005 * SPDX-License-Identifier: GPL-2.0+
wdenkedc48b62002-09-08 17:56:50 +00006 */
7
8/* for now: just dummy functions to satisfy the linker */
9
wdenkf8062712005-01-09 23:16:25 +000010#include <common.h>
Thierry Redingc97d9742014-12-09 22:25:22 -070011#include <malloc.h>
wdenkf8062712005-01-09 23:16:25 +000012
Simon Glass85406582016-06-19 19:43:01 -060013#ifndef CONFIG_SYS_CACHELINE_SIZE
14#define CONFIG_SYS_CACHELINE_SIZE 32
15#endif
16
Wu, Josh22190262015-07-27 11:40:17 +080017/*
18 * Flush range from all levels of d-cache/unified-cache.
19 * Affects the range [start, start + size - 1].
20 */
Jeroen Hofsteed7460772014-06-23 22:07:04 +020021__weak void flush_cache(unsigned long start, unsigned long size)
wdenkedc48b62002-09-08 17:56:50 +000022{
Wu, Josh22190262015-07-27 11:40:17 +080023 flush_dcache_range(start, start + size);
wdenkedc48b62002-09-08 17:56:50 +000024}
Aneesh V3bda3772011-06-16 23:30:50 +000025
26/*
27 * Default implementation:
28 * do a range flush for the entire range
29 */
Jeroen Hofsteed7460772014-06-23 22:07:04 +020030__weak void flush_dcache_all(void)
Aneesh V3bda3772011-06-16 23:30:50 +000031{
32 flush_cache(0, ~0);
33}
Aneesh Vfffbb972011-08-16 04:33:05 +000034
35/*
36 * Default implementation of enable_caches()
37 * Real implementation should be in platform code
38 */
Jeroen Hofsteed7460772014-06-23 22:07:04 +020039__weak void enable_caches(void)
Aneesh Vfffbb972011-08-16 04:33:05 +000040{
41 puts("WARNING: Caches not enabled\n");
42}
Thierry Redingc97d9742014-12-09 22:25:22 -070043
Wu, Joshaaa35452015-07-27 11:40:16 +080044__weak void invalidate_dcache_range(unsigned long start, unsigned long stop)
45{
46 /* An empty stub, real implementation should be in platform code */
47}
48__weak void flush_dcache_range(unsigned long start, unsigned long stop)
49{
50 /* An empty stub, real implementation should be in platform code */
51}
52
Simon Glass85406582016-06-19 19:43:01 -060053int check_cache_range(unsigned long start, unsigned long stop)
54{
55 int ok = 1;
56
57 if (start & (CONFIG_SYS_CACHELINE_SIZE - 1))
58 ok = 0;
59
60 if (stop & (CONFIG_SYS_CACHELINE_SIZE - 1))
61 ok = 0;
62
63 if (!ok) {
Simon Glass143997a2016-06-19 19:43:05 -060064 warn_non_spl("CACHE: Misaligned operation at range [%08lx, %08lx]\n",
65 start, stop);
Simon Glass85406582016-06-19 19:43:01 -060066 }
67
68 return ok;
69}
70
Thierry Redingc97d9742014-12-09 22:25:22 -070071#ifdef CONFIG_SYS_NONCACHED_MEMORY
72/*
73 * Reserve one MMU section worth of address space below the malloc() area that
74 * will be mapped uncached.
75 */
76static unsigned long noncached_start;
77static unsigned long noncached_end;
78static unsigned long noncached_next;
79
80void noncached_init(void)
81{
82 phys_addr_t start, end;
83 size_t size;
84
85 end = ALIGN(mem_malloc_start, MMU_SECTION_SIZE) - MMU_SECTION_SIZE;
86 size = ALIGN(CONFIG_SYS_NONCACHED_MEMORY, MMU_SECTION_SIZE);
87 start = end - size;
88
89 debug("mapping memory %pa-%pa non-cached\n", &start, &end);
90
91 noncached_start = start;
92 noncached_end = end;
93 noncached_next = start;
94
95#ifndef CONFIG_SYS_DCACHE_OFF
96 mmu_set_region_dcache_behaviour(noncached_start, size, DCACHE_OFF);
97#endif
98}
99
100phys_addr_t noncached_alloc(size_t size, size_t align)
101{
102 phys_addr_t next = ALIGN(noncached_next, align);
103
104 if (next >= noncached_end || (noncached_end - next) < size)
105 return 0;
106
107 debug("allocated %zu bytes of uncached memory @%pa\n", size, &next);
108 noncached_next = next + size;
109
110 return next;
111}
112#endif /* CONFIG_SYS_NONCACHED_MEMORY */
Albert ARIBAUDa3823222015-10-23 18:06:40 +0200113
114#if defined(CONFIG_SYS_THUMB_BUILD)
115void invalidate_l2_cache(void)
116{
117 unsigned int val = 0;
118
119 asm volatile("mcr p15, 1, %0, c15, c11, 0 @ invl l2 cache"
120 : : "r" (val) : "cc");
121 isb();
122}
123#endif