2 * Copyright (C) 2004-2006 Atmel Corporation
4 * SPDX-License-Identifier: GPL-2.0+
9 #include <asm/arch/cacheflush.h>
11 void dcache_clean_range(volatile void *start, size_t size)
13 unsigned long v, begin, end, linesz;
15 linesz = CONFIG_SYS_DCACHE_LINESZ;
17 /* You asked for it, you got it */
18 begin = (unsigned long)start & ~(linesz - 1);
19 end = ((unsigned long)start + size + linesz - 1) & ~(linesz - 1);
21 for (v = begin; v < end; v += linesz)
22 dcache_clean_line((void *)v);
27 void invalidate_dcache_range(unsigned long start, unsigned long stop)
29 unsigned long v, linesz;
31 linesz = CONFIG_SYS_DCACHE_LINESZ;
33 /* You asked for it, you got it */
34 start = start & ~(linesz - 1);
35 stop = (stop + linesz - 1) & ~(linesz - 1);
37 for (v = start; v < stop; v += linesz)
38 dcache_invalidate_line((void *)v);
41 void flush_dcache_range(unsigned long start, unsigned long stop)
43 unsigned long v, linesz;
45 linesz = CONFIG_SYS_DCACHE_LINESZ;
47 /* You asked for it, you got it */
48 start = start & ~(linesz - 1);
49 stop = (stop + linesz - 1) & ~(linesz - 1);
51 for (v = start; v < stop; v += linesz)
52 dcache_flush_line((void *)v);
57 void icache_invalidate_range(volatile void *start, size_t size)
59 unsigned long v, begin, end, linesz;
61 linesz = CONFIG_SYS_ICACHE_LINESZ;
63 /* You asked for it, you got it */
64 begin = (unsigned long)start & ~(linesz - 1);
65 end = ((unsigned long)start + size + linesz - 1) & ~(linesz - 1);
67 for (v = begin; v < end; v += linesz)
68 icache_invalidate_line((void *)v);
72 * This is called after loading something into memory. We need to
73 * make sure that everything that was loaded is actually written to
74 * RAM, and that the icache will look for it. Cleaning the dcache and
75 * invalidating the icache will do the trick.
77 void flush_cache (unsigned long start_addr, unsigned long size)
79 dcache_clean_range((void *)start_addr, size);
80 icache_invalidate_range((void *)start_addr, size);