#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: cache.c,v 1.19 2013/11/18 15:34:06 skrll Exp $");
#include "opt_cache.h"
#include "opt_memsize.h"
#include <sys/param.h>
#include <sys/systm.h>
#include <sh3/cache.h>
#include <sh3/cache_sh3.h>
#include <sh3/cache_sh4.h>
static void __cache_flush(void);
struct sh_cache_ops sh_cache_ops = {
._icache_sync_all = (void (*)(void))__cache_flush,
._icache_sync_range = (void (*)(vaddr_t, vsize_t))__cache_flush,
._icache_sync_range_index = (void (*)(vaddr_t, vsize_t))__cache_flush,
._dcache_wbinv_all = (void (*)(void))__cache_flush,
._dcache_wbinv_range = (void (*)(vaddr_t, vsize_t))__cache_flush,
._dcache_wbinv_range_index = (void (*)(vaddr_t, vsize_t))__cache_flush,
._dcache_inv_range = (void (*)(vaddr_t, vsize_t))__cache_flush,
._dcache_wb_range = (void (*)(vaddr_t, vsize_t))__cache_flush
};
int sh_cache_enable_icache;
int sh_cache_enable_dcache;
int sh_cache_write_through;
int sh_cache_write_through_p0_u0_p3;
int sh_cache_write_through_p1;
int sh_cache_unified;
int sh_cache_ways;
int sh_cache_size_icache;
int sh_cache_size_dcache;
int sh_cache_line_size;
int sh_cache_ram_mode;
int sh_cache_index_mode_icache;
int sh_cache_index_mode_dcache;
int sh_cache_alias_mask;
int sh_cache_prefer_mask;
void
sh_cache_init(void)
{
#ifdef CACHE_DEBUG
return;
#endif
#ifdef SH3
if (CPU_IS_SH3)
sh3_cache_config();
#endif
#ifdef SH4
if (CPU_IS_SH4)
sh4_cache_config();
#endif
}
void
sh_cache_information(void)
{
#ifdef CACHE_DEBUG
printf("*** USE CPU INDEPENDENT CACHE OPS. ***\n");
return;
#endif
aprint_normal("cpu0: %dKB/%dB",
sh_cache_size_icache >> 10,
sh_cache_line_size);
if (sh_cache_ways > 1)
aprint_normal(" %d-way set-associative", sh_cache_ways);
else
aprint_normal(" direct-mapped");
if (sh_cache_unified)
aprint_normal(" I/D-unified cache.");
else
aprint_normal(" Instruction cache.");
if (!sh_cache_enable_icache)
aprint_normal(" DISABLED");
if (sh_cache_unified && sh_cache_ram_mode)
aprint_normal(" RAM-mode");
if (sh_cache_index_mode_icache)
aprint_normal(" INDEX-mode");
aprint_normal("\n");
if (!sh_cache_unified) {
aprint_normal("cpu0: %dKB/%dB",
sh_cache_size_dcache >> 10,
sh_cache_line_size);
if (sh_cache_ways > 1)
aprint_normal(" %d-way set-associative",
sh_cache_ways);
else
aprint_normal(" direct-mapped");
aprint_normal(" Data cache.");
if (!sh_cache_enable_dcache)
aprint_normal(" DISABLED");
if (sh_cache_ram_mode)
aprint_normal(" RAM-mode");
if (sh_cache_index_mode_dcache)
aprint_normal(" INDEX-mode");
aprint_normal("\n");
}
aprint_normal("cpu0: U0, P0, P3 write-%s; P1 write-%s\n",
sh_cache_write_through_p0_u0_p3 ? "through" : "back",
sh_cache_write_through_p1 ? "through" : "back");
}
void
__cache_flush(void)
{
volatile int *p = (int *)SH3_PHYS_TO_P1SEG(IOM_RAM_BEGIN);
int i;
for (i = 0; i < 256 * 4; i++) {
(void)*p;
p += 4;
}
}