2018-05-06 21:58:06 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
2015-01-29 01:27:57 +00:00
|
|
|
/*
|
|
|
|
* (C) Copyright 2003
|
|
|
|
* Wolfgang Denk, DENX Software Engineering, <wd@denx.de>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
2019-11-14 19:57:37 +00:00
|
|
|
#include <cpu_func.h>
|
2015-01-29 01:27:57 +00:00
|
|
|
#include <asm/cacheops.h>
|
2017-05-12 11:26:11 +00:00
|
|
|
#ifdef CONFIG_MIPS_L2_CACHE
|
2016-09-21 10:18:54 +00:00
|
|
|
#include <asm/cm.h>
|
2017-05-12 11:26:11 +00:00
|
|
|
#endif
|
2017-11-21 19:18:37 +00:00
|
|
|
#include <asm/io.h>
|
2015-01-29 01:27:57 +00:00
|
|
|
#include <asm/mipsregs.h>
|
2017-11-21 19:18:38 +00:00
|
|
|
#include <asm/system.h>
|
2015-01-29 01:27:57 +00:00
|
|
|
|
2016-09-21 10:18:48 +00:00
|
|
|
DECLARE_GLOBAL_DATA_PTR;
|
2015-01-29 01:27:57 +00:00
|
|
|
|
2016-09-21 10:18:54 +00:00
|
|
|
static void probe_l2(void)
|
|
|
|
{
|
|
|
|
#ifdef CONFIG_MIPS_L2_CACHE
|
|
|
|
unsigned long conf2, sl;
|
|
|
|
bool l2c = false;
|
|
|
|
|
|
|
|
if (!(read_c0_config1() & MIPS_CONF_M))
|
|
|
|
return;
|
|
|
|
|
|
|
|
conf2 = read_c0_config2();
|
|
|
|
|
|
|
|
if (__mips_isa_rev >= 6) {
|
|
|
|
l2c = conf2 & MIPS_CONF_M;
|
|
|
|
if (l2c)
|
|
|
|
l2c = read_c0_config3() & MIPS_CONF_M;
|
|
|
|
if (l2c)
|
|
|
|
l2c = read_c0_config4() & MIPS_CONF_M;
|
|
|
|
if (l2c)
|
|
|
|
l2c = read_c0_config5() & MIPS_CONF5_L2C;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (l2c && config_enabled(CONFIG_MIPS_CM)) {
|
|
|
|
gd->arch.l2_line_size = mips_cm_l2_line_size();
|
|
|
|
} else if (l2c) {
|
|
|
|
/* We don't know how to retrieve L2 config on this system */
|
|
|
|
BUG();
|
|
|
|
} else {
|
|
|
|
sl = (conf2 & MIPS_CONF2_SL) >> MIPS_CONF2_SL_SHF;
|
|
|
|
gd->arch.l2_line_size = sl ? (2 << sl) : 0;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2016-09-21 10:18:48 +00:00
|
|
|
void mips_cache_probe(void)
|
|
|
|
{
|
|
|
|
#ifdef CONFIG_SYS_CACHE_SIZE_AUTO
|
|
|
|
unsigned long conf1, il, dl;
|
2015-01-29 01:27:57 +00:00
|
|
|
|
|
|
|
conf1 = read_c0_config1();
|
2016-09-21 10:18:48 +00:00
|
|
|
|
2016-01-12 20:48:26 +00:00
|
|
|
il = (conf1 & MIPS_CONF1_IL) >> MIPS_CONF1_IL_SHF;
|
2016-09-21 10:18:48 +00:00
|
|
|
dl = (conf1 & MIPS_CONF1_DL) >> MIPS_CONF1_DL_SHF;
|
|
|
|
|
|
|
|
gd->arch.l1i_line_size = il ? (2 << il) : 0;
|
|
|
|
gd->arch.l1d_line_size = dl ? (2 << dl) : 0;
|
|
|
|
#endif
|
2016-09-21 10:18:54 +00:00
|
|
|
probe_l2();
|
2015-01-29 01:27:57 +00:00
|
|
|
}
|
|
|
|
|
2016-09-21 10:18:48 +00:00
|
|
|
static inline unsigned long icache_line_size(void)
|
2015-01-29 01:27:57 +00:00
|
|
|
{
|
2016-09-21 10:18:48 +00:00
|
|
|
#ifdef CONFIG_SYS_CACHE_SIZE_AUTO
|
|
|
|
return gd->arch.l1i_line_size;
|
|
|
|
#else
|
|
|
|
return CONFIG_SYS_ICACHE_LINE_SIZE;
|
|
|
|
#endif
|
|
|
|
}
|
2016-05-27 13:28:05 +00:00
|
|
|
|
2016-09-21 10:18:48 +00:00
|
|
|
static inline unsigned long dcache_line_size(void)
|
|
|
|
{
|
|
|
|
#ifdef CONFIG_SYS_CACHE_SIZE_AUTO
|
|
|
|
return gd->arch.l1d_line_size;
|
|
|
|
#else
|
|
|
|
return CONFIG_SYS_DCACHE_LINE_SIZE;
|
|
|
|
#endif
|
2015-01-29 01:27:57 +00:00
|
|
|
}
|
|
|
|
|
2016-09-21 10:18:54 +00:00
|
|
|
static inline unsigned long scache_line_size(void)
|
|
|
|
{
|
|
|
|
#ifdef CONFIG_MIPS_L2_CACHE
|
|
|
|
return gd->arch.l2_line_size;
|
|
|
|
#else
|
2019-06-10 18:05:26 +00:00
|
|
|
return CONFIG_SYS_SCACHE_LINE_SIZE;
|
2016-09-21 10:18:54 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
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; \
|
|
|
|
\
|
2017-11-21 19:18:39 +00:00
|
|
|
if (!lsize) \
|
|
|
|
break; \
|
|
|
|
\
|
2016-05-27 13:28:06 +00:00
|
|
|
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();
|
2016-09-21 10:18:54 +00:00
|
|
|
unsigned long slsize = scache_line_size();
|
2015-01-29 01:27:57 +00:00
|
|
|
|
|
|
|
/* aend will be miscalculated when size is zero, so we return here */
|
|
|
|
if (size == 0)
|
|
|
|
return;
|
|
|
|
|
2016-09-21 10:18:54 +00:00
|
|
|
if ((ilsize == dlsize) && !slsize) {
|
2015-01-29 01:27:57 +00:00
|
|
|
/* 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);
|
2017-11-21 19:18:37 +00:00
|
|
|
goto ops_done;
|
2015-01-29 01:27:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* 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
|
|
|
|
2016-09-21 10:18:54 +00:00
|
|
|
/* flush L2 cache */
|
2017-11-21 19:18:39 +00:00
|
|
|
cache_loop(start_addr, start_addr + size, slsize, HIT_WRITEBACK_INV_SD);
|
2016-09-21 10:18:54 +00:00
|
|
|
|
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);
|
2017-11-21 19:18:37 +00:00
|
|
|
|
|
|
|
ops_done:
|
|
|
|
/* ensure cache ops complete before any further memory accesses */
|
|
|
|
sync();
|
2017-11-21 19:18:38 +00:00
|
|
|
|
|
|
|
/* ensure the pipeline doesn't contain now-invalid instructions */
|
|
|
|
instruction_hazard_barrier();
|
2015-01-29 01:27:57 +00:00
|
|
|
}
|
|
|
|
|
2019-12-23 20:19:20 +00:00
|
|
|
void __weak flush_dcache_range(ulong start_addr, ulong stop)
|
2015-01-29 01:27:57 +00:00
|
|
|
{
|
|
|
|
unsigned long lsize = dcache_line_size();
|
2016-09-21 10:18:54 +00:00
|
|
|
unsigned long slsize = scache_line_size();
|
2015-01-29 01:27:57 +00:00
|
|
|
|
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);
|
2016-09-21 10:18:54 +00:00
|
|
|
|
|
|
|
/* flush L2 cache */
|
2017-11-21 19:18:39 +00:00
|
|
|
cache_loop(start_addr, stop, slsize, HIT_WRITEBACK_INV_SD);
|
2017-11-21 19:18:37 +00:00
|
|
|
|
|
|
|
/* ensure cache ops complete before any further memory accesses */
|
|
|
|
sync();
|
2015-01-29 01:27:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void invalidate_dcache_range(ulong start_addr, ulong stop)
|
|
|
|
{
|
|
|
|
unsigned long lsize = dcache_line_size();
|
2016-09-21 10:18:54 +00:00
|
|
|
unsigned long slsize = scache_line_size();
|
2015-01-29 01:27:57 +00:00
|
|
|
|
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-09-21 10:18:54 +00:00
|
|
|
/* invalidate L2 cache */
|
2017-11-21 19:18:39 +00:00
|
|
|
cache_loop(start_addr, stop, slsize, HIT_INVALIDATE_SD);
|
2016-09-21 10:18:54 +00:00
|
|
|
|
2016-06-09 12:09:51 +00:00
|
|
|
cache_loop(start_addr, stop, lsize, HIT_INVALIDATE_D);
|
2017-11-21 19:18:37 +00:00
|
|
|
|
|
|
|
/* ensure cache ops complete before any further memory accesses */
|
|
|
|
sync();
|
2015-01-29 01:27:57 +00:00
|
|
|
}
|
2018-09-07 17:02:03 +00:00
|
|
|
|
|
|
|
int dcache_status(void)
|
|
|
|
{
|
|
|
|
unsigned int cca = read_c0_config() & CONF_CM_CMASK;
|
|
|
|
return cca != CONF_CM_UNCACHED;
|
|
|
|
}
|
|
|
|
|
|
|
|
void dcache_enable(void)
|
|
|
|
{
|
|
|
|
puts("Not supported!\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
void dcache_disable(void)
|
|
|
|
{
|
|
|
|
/* change CCA to uncached */
|
|
|
|
change_c0_config(CONF_CM_CMASK, CONF_CM_UNCACHED);
|
|
|
|
|
|
|
|
/* ensure the pipeline doesn't contain now-invalid instructions */
|
|
|
|
instruction_hazard_barrier();
|
|
|
|
}
|