blob: 74cfde637c1c433f3f834cdfbdac48b05ff78b6a [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
Jeroen Hofsteed7460772014-06-23 22:07:04 +020013__weak void flush_cache(unsigned long start, unsigned long size)
wdenkedc48b62002-09-08 17:56:50 +000014{
Masahiro Yamadaa8b4c8c2014-11-06 14:59:37 +090015#if defined(CONFIG_CPU_ARM1136)
wdenkf8062712005-01-09 23:16:25 +000016
Albert ARIBAUD7a6fd042014-04-15 16:13:47 +020017#if !defined(CONFIG_SYS_ICACHE_OFF)
18 asm("mcr p15, 0, r1, c7, c5, 0"); /* invalidate I cache */
wdenkf8062712005-01-09 23:16:25 +000019#endif
Albert ARIBAUD7a6fd042014-04-15 16:13:47 +020020
21#if !defined(CONFIG_SYS_DCACHE_OFF)
22 asm("mcr p15, 0, r1, c7, c14, 0"); /* Clean+invalidate D cache */
23#endif
24
Masahiro Yamadaa8b4c8c2014-11-06 14:59:37 +090025#endif /* CONFIG_CPU_ARM1136 */
Albert ARIBAUD7a6fd042014-04-15 16:13:47 +020026
Masahiro Yamada4fb5d072014-11-06 14:59:36 +090027#ifdef CONFIG_CPU_ARM926EJS
Heiko Schocherb642d832014-11-18 09:41:56 +010028#if !(defined(CONFIG_SYS_ICACHE_OFF) && defined(CONFIG_SYS_DCACHE_OFF))
Heiko Schocher54433092010-09-17 13:10:30 +020029 /* 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));
Heiko Schocherb642d832014-11-18 09:41:56 +010033#endif
Masahiro Yamada4fb5d072014-11-06 14:59:36 +090034#endif /* CONFIG_CPU_ARM926EJS */
wdenkedc48b62002-09-08 17:56:50 +000035 return;
36}
Aneesh V3bda3772011-06-16 23:30:50 +000037
38/*
39 * Default implementation:
40 * do a range flush for the entire range
41 */
Jeroen Hofsteed7460772014-06-23 22:07:04 +020042__weak void flush_dcache_all(void)
Aneesh V3bda3772011-06-16 23:30:50 +000043{
44 flush_cache(0, ~0);
45}
Aneesh Vfffbb972011-08-16 04:33:05 +000046
47/*
48 * Default implementation of enable_caches()
49 * Real implementation should be in platform code
50 */
Jeroen Hofsteed7460772014-06-23 22:07:04 +020051__weak void enable_caches(void)
Aneesh Vfffbb972011-08-16 04:33:05 +000052{
53 puts("WARNING: Caches not enabled\n");
54}
Thierry Redingc97d9742014-12-09 22:25:22 -070055
56#ifdef CONFIG_SYS_NONCACHED_MEMORY
57/*
58 * Reserve one MMU section worth of address space below the malloc() area that
59 * will be mapped uncached.
60 */
61static unsigned long noncached_start;
62static unsigned long noncached_end;
63static unsigned long noncached_next;
64
65void noncached_init(void)
66{
67 phys_addr_t start, end;
68 size_t size;
69
70 end = ALIGN(mem_malloc_start, MMU_SECTION_SIZE) - MMU_SECTION_SIZE;
71 size = ALIGN(CONFIG_SYS_NONCACHED_MEMORY, MMU_SECTION_SIZE);
72 start = end - size;
73
74 debug("mapping memory %pa-%pa non-cached\n", &start, &end);
75
76 noncached_start = start;
77 noncached_end = end;
78 noncached_next = start;
79
80#ifndef CONFIG_SYS_DCACHE_OFF
81 mmu_set_region_dcache_behaviour(noncached_start, size, DCACHE_OFF);
82#endif
83}
84
85phys_addr_t noncached_alloc(size_t size, size_t align)
86{
87 phys_addr_t next = ALIGN(noncached_next, align);
88
89 if (next >= noncached_end || (noncached_end - next) < size)
90 return 0;
91
92 debug("allocated %zu bytes of uncached memory @%pa\n", size, &next);
93 noncached_next = next + size;
94
95 return next;
96}
97#endif /* CONFIG_SYS_NONCACHED_MEMORY */