2006-10-24 12:27:35 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2004-2006 Atmel Corporation
|
|
|
|
*
|
2013-07-08 07:37:19 +00:00
|
|
|
* SPDX-License-Identifier: GPL-2.0+
|
2006-10-24 12:27:35 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
|
|
|
|
2009-01-23 11:56:27 +00:00
|
|
|
#include <asm/arch/cacheflush.h>
|
2006-10-24 12:27:35 +00:00
|
|
|
|
|
|
|
void dcache_clean_range(volatile void *start, size_t size)
|
|
|
|
{
|
|
|
|
unsigned long v, begin, end, linesz;
|
|
|
|
|
2008-10-16 13:01:15 +00:00
|
|
|
linesz = CONFIG_SYS_DCACHE_LINESZ;
|
2006-10-24 12:27:35 +00:00
|
|
|
|
|
|
|
/* You asked for it, you got it */
|
|
|
|
begin = (unsigned long)start & ~(linesz - 1);
|
|
|
|
end = ((unsigned long)start + size + linesz - 1) & ~(linesz - 1);
|
|
|
|
|
|
|
|
for (v = begin; v < end; v += linesz)
|
|
|
|
dcache_clean_line((void *)v);
|
|
|
|
|
|
|
|
sync_write_buffer();
|
|
|
|
}
|
|
|
|
|
|
|
|
void dcache_invalidate_range(volatile void *start, size_t size)
|
|
|
|
{
|
|
|
|
unsigned long v, begin, end, linesz;
|
|
|
|
|
2008-10-16 13:01:15 +00:00
|
|
|
linesz = CONFIG_SYS_DCACHE_LINESZ;
|
2006-10-24 12:27:35 +00:00
|
|
|
|
|
|
|
/* You asked for it, you got it */
|
|
|
|
begin = (unsigned long)start & ~(linesz - 1);
|
|
|
|
end = ((unsigned long)start + size + linesz - 1) & ~(linesz - 1);
|
|
|
|
|
|
|
|
for (v = begin; v < end; v += linesz)
|
|
|
|
dcache_invalidate_line((void *)v);
|
|
|
|
}
|
|
|
|
|
|
|
|
void dcache_flush_range(volatile void *start, size_t size)
|
|
|
|
{
|
|
|
|
unsigned long v, begin, end, linesz;
|
|
|
|
|
2008-10-16 13:01:15 +00:00
|
|
|
linesz = CONFIG_SYS_DCACHE_LINESZ;
|
2006-10-24 12:27:35 +00:00
|
|
|
|
|
|
|
/* You asked for it, you got it */
|
|
|
|
begin = (unsigned long)start & ~(linesz - 1);
|
|
|
|
end = ((unsigned long)start + size + linesz - 1) & ~(linesz - 1);
|
|
|
|
|
|
|
|
for (v = begin; v < end; v += linesz)
|
|
|
|
dcache_flush_line((void *)v);
|
|
|
|
|
|
|
|
sync_write_buffer();
|
|
|
|
}
|
|
|
|
|
|
|
|
void icache_invalidate_range(volatile void *start, size_t size)
|
|
|
|
{
|
|
|
|
unsigned long v, begin, end, linesz;
|
|
|
|
|
2008-10-16 13:01:15 +00:00
|
|
|
linesz = CONFIG_SYS_ICACHE_LINESZ;
|
2006-10-24 12:27:35 +00:00
|
|
|
|
|
|
|
/* You asked for it, you got it */
|
|
|
|
begin = (unsigned long)start & ~(linesz - 1);
|
|
|
|
end = ((unsigned long)start + size + linesz - 1) & ~(linesz - 1);
|
|
|
|
|
|
|
|
for (v = begin; v < end; v += linesz)
|
|
|
|
icache_invalidate_line((void *)v);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This is called after loading something into memory. We need to
|
|
|
|
* make sure that everything that was loaded is actually written to
|
|
|
|
* RAM, and that the icache will look for it. Cleaning the dcache and
|
|
|
|
* invalidating the icache will do the trick.
|
|
|
|
*/
|
|
|
|
void flush_cache (unsigned long start_addr, unsigned long size)
|
|
|
|
{
|
|
|
|
dcache_clean_range((void *)start_addr, size);
|
|
|
|
icache_invalidate_range((void *)start_addr, size);
|
|
|
|
}
|