2015-01-29 01:27:57 +00:00
|
|
|
/*
|
|
|
|
* (C) Copyright 2003
|
|
|
|
* Wolfgang Denk, DENX Software Engineering, <wd@denx.de>
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: GPL-2.0+
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
|
|
|
#include <asm/cacheops.h>
|
|
|
|
#include <asm/mipsregs.h>
|
|
|
|
|
|
|
|
static inline unsigned long icache_line_size(void)
|
|
|
|
{
|
2016-05-27 13:28:05 +00:00
|
|
|
unsigned long conf1, il;
|
2015-01-29 01:27:57 +00:00
|
|
|
|
2016-05-27 13:28:05 +00:00
|
|
|
if (!config_enabled(CONFIG_SYS_CACHE_SIZE_AUTO))
|
|
|
|
return CONFIG_SYS_ICACHE_LINE_SIZE;
|
2015-01-29 01:27:57 +00:00
|
|
|
|
|
|
|
conf1 = read_c0_config1();
|
2016-01-12 20:48:26 +00:00
|
|
|
il = (conf1 & MIPS_CONF1_IL) >> MIPS_CONF1_IL_SHF;
|
2015-01-29 01:27:57 +00:00
|
|
|
if (!il)
|
|
|
|
return 0;
|
|
|
|
return 2 << il;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline unsigned long dcache_line_size(void)
|
|
|
|
{
|
|
|
|
unsigned long conf1, dl;
|
2016-05-27 13:28:05 +00:00
|
|
|
|
|
|
|
if (!config_enabled(CONFIG_SYS_CACHE_SIZE_AUTO))
|
|
|
|
return CONFIG_SYS_DCACHE_LINE_SIZE;
|
|
|
|
|
2015-01-29 01:27:57 +00:00
|
|
|
conf1 = read_c0_config1();
|
2016-01-12 20:48:26 +00:00
|
|
|
dl = (conf1 & MIPS_CONF1_DL) >> MIPS_CONF1_DL_SHF;
|
2015-01-29 01:27:57 +00:00
|
|
|
if (!dl)
|
|
|
|
return 0;
|
|
|
|
return 2 << dl;
|
|
|
|
}
|
|
|
|
|
2016-05-27 13:28:06 +00:00
|
|
|
#define cache_loop(start, end, lsize, ops...) do { \
|
|
|
|
const void *addr = (const void *)(start & ~(lsize - 1)); \
|
|
|
|
const void *aend = (const void *)((end - 1) & ~(lsize - 1)); \
|
|
|
|
const unsigned int cache_ops[] = { ops }; \
|
|
|
|
unsigned int i; \
|
|
|
|
\
|
|
|
|
for (; addr <= aend; addr += lsize) { \
|
|
|
|
for (i = 0; i < ARRAY_SIZE(cache_ops); i++) \
|
|
|
|
mips_cache(cache_ops[i], addr); \
|
|
|
|
} \
|
|
|
|
} while (0)
|
|
|
|
|
2015-01-29 01:27:57 +00:00
|
|
|
void flush_cache(ulong start_addr, ulong size)
|
|
|
|
{
|
|
|
|
unsigned long ilsize = icache_line_size();
|
|
|
|
unsigned long dlsize = dcache_line_size();
|
|
|
|
|
|
|
|
/* aend will be miscalculated when size is zero, so we return here */
|
|
|
|
if (size == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (ilsize == dlsize) {
|
|
|
|
/* flush I-cache & D-cache simultaneously */
|
2016-05-27 13:28:06 +00:00
|
|
|
cache_loop(start_addr, start_addr + size, ilsize,
|
|
|
|
HIT_WRITEBACK_INV_D, HIT_INVALIDATE_I);
|
2015-01-29 01:27:57 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* flush D-cache */
|
2016-05-27 13:28:06 +00:00
|
|
|
cache_loop(start_addr, start_addr + size, dlsize, HIT_WRITEBACK_INV_D);
|
2015-01-29 01:27:57 +00:00
|
|
|
|
|
|
|
/* flush I-cache */
|
2016-05-27 13:28:06 +00:00
|
|
|
cache_loop(start_addr, start_addr + size, ilsize, HIT_INVALIDATE_I);
|
2015-01-29 01:27:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void flush_dcache_range(ulong start_addr, ulong stop)
|
|
|
|
{
|
|
|
|
unsigned long lsize = dcache_line_size();
|
|
|
|
|
2016-01-27 02:13:59 +00:00
|
|
|
/* aend will be miscalculated when size is zero, so we return here */
|
|
|
|
if (start_addr == stop)
|
|
|
|
return;
|
|
|
|
|
2016-05-27 13:28:06 +00:00
|
|
|
cache_loop(start_addr, stop, lsize, HIT_WRITEBACK_INV_D);
|
2015-01-29 01:27:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void invalidate_dcache_range(ulong start_addr, ulong stop)
|
|
|
|
{
|
|
|
|
unsigned long lsize = dcache_line_size();
|
|
|
|
|
2016-01-27 02:13:59 +00:00
|
|
|
/* aend will be miscalculated when size is zero, so we return here */
|
|
|
|
if (start_addr == stop)
|
|
|
|
return;
|
|
|
|
|
2016-06-09 12:09:51 +00:00
|
|
|
cache_loop(start_addr, stop, lsize, HIT_INVALIDATE_D);
|
2015-01-29 01:27:57 +00:00
|
|
|
}
|