glamo-mmc.patch
[u-boot-openmoko/mini2440.git] / cpu / at32ap / cache.c
blob41fb5aa0473d15454925463ea38599877a1325b0
1 /*
2 * Copyright (C) 2004-2006 Atmel Corporation
4 * See file CREDITS for list of people who contributed to this
5 * project.
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License as
9 * published by the Free Software Foundation; either version 2 of
10 * the License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
20 * MA 02111-1307 USA
23 #include <common.h>
25 #include <asm/cacheflush.h>
27 void dcache_clean_range(volatile void *start, size_t size)
29 unsigned long v, begin, end, linesz;
31 linesz = CFG_DCACHE_LINESZ;
33 /* You asked for it, you got it */
34 begin = (unsigned long)start & ~(linesz - 1);
35 end = ((unsigned long)start + size + linesz - 1) & ~(linesz - 1);
37 for (v = begin; v < end; v += linesz)
38 dcache_clean_line((void *)v);
40 sync_write_buffer();
43 void dcache_invalidate_range(volatile void *start, size_t size)
45 unsigned long v, begin, end, linesz;
47 linesz = CFG_DCACHE_LINESZ;
49 /* You asked for it, you got it */
50 begin = (unsigned long)start & ~(linesz - 1);
51 end = ((unsigned long)start + size + linesz - 1) & ~(linesz - 1);
53 for (v = begin; v < end; v += linesz)
54 dcache_invalidate_line((void *)v);
57 void dcache_flush_range(volatile void *start, size_t size)
59 unsigned long v, begin, end, linesz;
61 linesz = CFG_DCACHE_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 dcache_flush_line((void *)v);
70 sync_write_buffer();
73 void icache_invalidate_range(volatile void *start, size_t size)
75 unsigned long v, begin, end, linesz;
77 linesz = CFG_ICACHE_LINESZ;
79 /* You asked for it, you got it */
80 begin = (unsigned long)start & ~(linesz - 1);
81 end = ((unsigned long)start + size + linesz - 1) & ~(linesz - 1);
83 for (v = begin; v < end; v += linesz)
84 icache_invalidate_line((void *)v);
88 * This is called after loading something into memory. We need to
89 * make sure that everything that was loaded is actually written to
90 * RAM, and that the icache will look for it. Cleaning the dcache and
91 * invalidating the icache will do the trick.
93 void flush_cache (unsigned long start_addr, unsigned long size)
95 dcache_clean_range((void *)start_addr, size);
96 icache_invalidate_range((void *)start_addr, size);