Store cache associativities in the `cacheinfo' structure, and use it

in computing the cache "alias distance" and in the viking cache line
flush function.
This commit is contained in:
pk 1997-03-21 01:32:15 +00:00
parent a823d31f7e
commit 31f3ff5346
3 changed files with 42 additions and 14 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: cache.c,v 1.16 1997/03/20 21:44:21 pk Exp $ */
/* $NetBSD: cache.c,v 1.17 1997/03/21 01:32:20 pk Exp $ */
/*
* Copyright (c) 1996
@ -134,7 +134,9 @@ void
viking_cache_enable()
{
cache_alias_dist = max(CACHEINFO.ic_totalsize, CACHEINFO.dc_totalsize);
cache_alias_dist = max(
CACHEINFO.ic_totalsize / CACHEINFO.ic_associativity,
CACHEINFO.dc_totalsize / CACHEINFO.dc_associativity);
cache_alias_bits = (cache_alias_dist - 1) & ~PGOFSET;
/* We "flash-clear" the I/D caches. */
@ -202,7 +204,9 @@ hypersparc_cache_enable()
void
swift_cache_enable()
{
cache_alias_dist = max(CACHEINFO.ic_totalsize, CACHEINFO.dc_totalsize);
cache_alias_dist = max(
CACHEINFO.ic_totalsize / CACHEINFO.ic_associativity,
CACHEINFO.dc_totalsize / CACHEINFO.dc_associativity);
cache_alias_bits = (cache_alias_dist - 1) & ~PGOFSET;
}
@ -600,16 +604,26 @@ viking_pcache_flush_line(va, pa)
* Flush cache line corresponding to virtual address `va'
* which is mapped at physical address `pa'.
*/
int i, cmask, cshift, *v;
extern char *etext;
/* NOT YET IMPLEMENTED */
#if 0
int i = CACHEINFO.c_dassociativity;
int v = X + (pa & PG_OFSET);
i = CACHEINFO.dc_associativity;
cmask = CACHEINFO.ic_totalsize - 1;
cshift = CACHEINFO.ic_l2linesize;
/*
* Construct a virtual address that hits the same cache line
* as VA, then read from ASSOCIATIVITY different physical
* locations (all different from PA).
*/
v = (int *)(((va & cmask) >> cshift) << cshift);
v += roundup((int)etext, NBPG); /* XXX */
while (i--) {
volatile int x = *v;
volatile int x;
x = *v;
v += NBPG;
}
#endif
}
void

View File

@ -1,4 +1,4 @@
/* $NetBSD: cache.h,v 1.11 1997/03/20 23:57:30 pk Exp $ */
/* $NetBSD: cache.h,v 1.12 1997/03/21 01:32:15 pk Exp $ */
/*
* Copyright (c) 1996
@ -209,18 +209,25 @@ struct cacheinfo {
int c_l2linesize; /* log2(linesize) */
int c_physical; /* true => cache is physical */
int c_split; /* true => cache is split */
int ic_totalsize; /* instruction cache */
int ic_enabled;
int ic_linesize;
int ic_l2linesize;
int ic_associativity;
int dc_totalsize; /* data cache */
int dc_enabled;
int dc_linesize;
int dc_l2linesize;
int dc_associativity;
int ec_totalsize; /* external cache info */
int ec_enabled;
int ec_linesize;
int ec_l2linesize;
int ec_associativity;
enum vactype c_vactype;
};

View File

@ -1,4 +1,4 @@
/* $NetBSD: cpu.c,v 1.31 1997/03/20 23:26:25 pk Exp $ */
/* $NetBSD: cpu.c,v 1.32 1997/03/21 01:32:18 pk Exp $ */
/*
* Copyright (c) 1996
@ -589,9 +589,11 @@ getcacheinfo_obp(sc, node)
if ((1 << i) != l && l)
panic("bad icache line size %d", l);
sc->cacheinfo.ic_l2linesize = i;
sc->cacheinfo.ic_associativity =
getpropint(node, "icache-associativity", 1);
sc->cacheinfo.ic_totalsize = l *
getpropint(node, "icache-nlines", 64) *
getpropint(node, "icache-associativity", 1);
sc->cacheinfo.ic_associativity;
sc->cacheinfo.dc_linesize = l =
getpropint(node, "dcache-line-size",0);
@ -600,9 +602,11 @@ getcacheinfo_obp(sc, node)
if ((1 << i) != l && l)
panic("bad dcache line size %d", l);
sc->cacheinfo.dc_l2linesize = i;
sc->cacheinfo.dc_associativity =
getpropint(node, "dcache-associativity", 1);
sc->cacheinfo.dc_totalsize = l *
getpropint(node, "dcache-nlines", 128) *
getpropint(node, "dcache-associativity", 1);
sc->cacheinfo.dc_associativity;
sc->cacheinfo.c_l2linesize =
min(sc->cacheinfo.ic_l2linesize,
@ -636,9 +640,11 @@ getcacheinfo_obp(sc, node)
if ((1 << i) != l && l)
panic("bad ecache line size %d", l);
sc->cacheinfo.ec_l2linesize = i;
sc->cacheinfo.ec_associativity =
getpropint(node, "ecache-associativity", 1);
sc->cacheinfo.ec_totalsize = l *
getpropint(node, "ecache-nlines", 32768) *
getpropint(node, "ecache-associativity", 1);
sc->cacheinfo.ec_associativity;
}
if (sc->cacheinfo.c_totalsize == 0)
printf("warning: couldn't identify cache\n");
@ -786,6 +792,7 @@ viking_hotfix(sc)
sc->flags |= CPUFLG_CACHEPAGETABLES;
sc->flags |= CPUFLG_CACHE_MANDATORY;
sc->pcache_flush_line = viking_pcache_flush_line;
sc->cacheinfo.dc_associativity = 5; /* need this early */
}
/* XXX! */