Line 28... |
Line 28... |
|
|
extern int cont_run;
|
extern int cont_run;
|
|
|
/* Data MMU */
|
/* Data MMU */
|
|
|
unsigned long dmmu_translate(unsigned long virtaddr)
|
inline unsigned long dmmu_simulate_tlb(unsigned long virtaddr, int write_access)
|
{
|
{
|
unsigned long phyaddr = dmmu_simulate_tlb(virtaddr);
|
int set, way = -1;
|
|
int i;
|
|
unsigned long tagaddr;
|
|
unsigned long vpn;
|
|
|
|
if (!(mfspr(SPR_SR) & SPR_SR_DME) || (!testsprbits(SPR_SR, SPR_SR_DME)))
|
|
return virtaddr;
|
|
|
|
/* Which set to check out? */
|
|
set = (virtaddr / config.dmmu.pagesize) % config.dmmu.nsets;
|
|
tagaddr = (virtaddr / config.dmmu.pagesize) / config.dmmu.nsets;
|
|
vpn = virtaddr / config.dmmu.pagesize;
|
|
|
|
/* Scan all ways and try to find a matching way. */
|
|
for (i = 0; i < config.dmmu.nways; i++)
|
|
if ((getsprbits(SPR_DTLBMR_BASE(i) + set, SPR_DTLBMR_VPN) == vpn) &&
|
|
testsprbits(SPR_DTLBMR_BASE(i) + set, SPR_DTLBMR_V))
|
|
way = i;
|
|
|
|
/* Did we find our tlb entry? */
|
|
if (way >= 0) { /* Yes, we did. */
|
|
dmmu_stats.loads_tlbhit++;
|
|
debug(5, "DTLB hit (virtaddr=%x).\n", virtaddr);
|
|
|
|
/* Test for page fault */
|
|
if (mfspr (SPR_SR) & SPR_SR_SUPV) {
|
|
if ( write_access && !(mfspr (SPR_ITLBTR_BASE(way) + set) & SPR_ITLBTR_SWE)
|
|
|| !write_access && !(mfspr (SPR_ITLBTR_BASE(way) + set) & SPR_ITLBTR_SRE))
|
|
except_handle(EXCEPT_DPF, virtaddr);
|
|
} else {
|
|
if ( write_access && !(mfspr (SPR_ITLBTR_BASE(way) + set) & SPR_ITLBTR_UWE)
|
|
|| !write_access && !(mfspr (SPR_ITLBTR_BASE(way) + set) & SPR_ITLBTR_URE))
|
|
except_handle(EXCEPT_DPF, virtaddr);
|
|
}
|
|
|
|
/* Set LRUs */
|
|
for (i = 0; i < config.dmmu.nways; i++)
|
|
if (testsprbits(SPR_DTLBMR_BASE(i) + set, SPR_DTLBMR_LRU))
|
|
setsprbits(SPR_DTLBMR_BASE(i) + set, SPR_DTLBMR_LRU, getsprbits(SPR_DTLBMR_BASE(i) + set, SPR_DTLBMR_LRU) - 1);
|
|
setsprbits(SPR_DTLBMR_BASE(way) + set, SPR_DTLBMR_LRU, config.dmmu.ustates - 1);
|
|
|
|
return getsprbits(SPR_DTLBTR_BASE(way) + set, SPR_DTLBTR_PPN) * config.dmmu.pagesize + (virtaddr % config.dmmu.pagesize);
|
|
}
|
|
else { /* No, we didn't. */
|
|
int minlru = config.dmmu.ustates - 1;
|
|
int minway = 0;
|
|
|
|
dmmu_stats.loads_tlbmiss++;
|
|
#if 0
|
|
for (i = 0; i < config.dmmu.nways; i++)
|
|
if (getsprbits(SPR_DTLBMR_BASE(i) + set, SPR_DTLBMR_LRU) < minlru)
|
|
minway = i;
|
|
|
|
setsprbits(SPR_DTLBMR_BASE(minway) + set, SPR_DTLBMR_VPN, vpn);
|
|
for (i = 0; i < config.dmmu.nways; i++)
|
|
if (getsprbits(SPR_DTLBMR_BASE(i) + set, SPR_DTLBMR_LRU))
|
|
setsprbits(SPR_DTLBMR_BASE(i) + set, SPR_DTLBMR_LRU, getsprbits(SPR_DTLBMR_BASE(i) + set, SPR_DTLBMR_LRU) - 1);
|
|
setsprbits(SPR_DTLBMR_BASE(minway) + set, SPR_DTLBMR_LRU, config.dmmu.ustates - 1);
|
|
setsprbits(SPR_DTLBTR_BASE(minway) + set, SPR_DTLBTR_PPN, vpn); /* 1 to 1 */
|
|
setsprbits(SPR_DTLBMR_BASE(minway) + set, SPR_DTLBMR_V, 1);
|
|
#endif
|
|
except_handle(EXCEPT_DTLBMISS, virtaddr);
|
|
/* if tlb refill implemented in HW */
|
|
/* return getsprbits(SPR_DTLBTR_BASE(minway) + set, SPR_DTLBTR_PPN) * config.dmmu.pagesize + (virtaddr % config.dmmu.pagesize); */
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
unsigned long dmmu_translate(unsigned long virtaddr, int write_access)
|
|
{
|
|
unsigned long phyaddr = dmmu_simulate_tlb(virtaddr, write_access);
|
|
|
/* printf("DMMU translate(%x) = %x\n", virtaddr, phyaddr);*/
|
/* printf("DMMU translate(%x) = %x\n", virtaddr, phyaddr);*/
|
return phyaddr;
|
return phyaddr;
|
}
|
}
|
|
|
Line 100... |
Line 170... |
}
|
}
|
}
|
}
|
printf("\n");
|
printf("\n");
|
}
|
}
|
|
|
unsigned long dmmu_simulate_tlb(unsigned long virtaddr)
|
|
{
|
|
int set, way = -1;
|
|
int i;
|
|
unsigned long tagaddr;
|
|
unsigned long vpn;
|
|
|
|
if (!(mfspr(SPR_SR) & SPR_SR_DME) || (!testsprbits(SPR_SR, SPR_SR_DME)))
|
|
return virtaddr;
|
|
|
|
/* Which set to check out? */
|
|
set = (virtaddr / config.dmmu.pagesize) % config.dmmu.nsets;
|
|
tagaddr = (virtaddr / config.dmmu.pagesize) / config.dmmu.nsets;
|
|
vpn = virtaddr / config.dmmu.pagesize;
|
|
|
|
/* Scan all ways and try to find a matching way. */
|
|
for (i = 0; i < config.dmmu.nways; i++)
|
|
if ((getsprbits(SPR_DTLBMR_BASE(i) + set, SPR_DTLBMR_VPN) == vpn) &&
|
|
testsprbits(SPR_DTLBMR_BASE(i) + set, SPR_DTLBMR_V))
|
|
way = i;
|
|
|
|
/* Did we find our tlb entry? */
|
|
if (way >= 0) { /* Yes, we did. */
|
|
dmmu_stats.loads_tlbhit++;
|
|
debug(5, "DTLB hit (virtaddr=%x).\n", virtaddr);
|
|
|
|
/* Set LRUs */
|
|
for (i = 0; i < config.dmmu.nways; i++)
|
|
if (testsprbits(SPR_DTLBMR_BASE(i) + set, SPR_DTLBMR_LRU))
|
|
setsprbits(SPR_DTLBMR_BASE(i) + set, SPR_DTLBMR_LRU, getsprbits(SPR_DTLBMR_BASE(i) + set, SPR_DTLBMR_LRU) - 1);
|
|
setsprbits(SPR_DTLBMR_BASE(way) + set, SPR_DTLBMR_LRU, config.dmmu.ustates - 1);
|
|
|
|
return getsprbits(SPR_DTLBTR_BASE(way) + set, SPR_DTLBTR_PPN) * config.dmmu.pagesize + (virtaddr % config.dmmu.pagesize);
|
|
}
|
|
else { /* No, we didn't. */
|
|
int minlru = config.dmmu.ustates - 1;
|
|
int minway = 0;
|
|
|
|
dmmu_stats.loads_tlbmiss++;
|
|
#if 0
|
|
for (i = 0; i < config.dmmu.nways; i++)
|
|
if (getsprbits(SPR_DTLBMR_BASE(i) + set, SPR_DTLBMR_LRU) < minlru)
|
|
minway = i;
|
|
|
|
setsprbits(SPR_DTLBMR_BASE(minway) + set, SPR_DTLBMR_VPN, vpn);
|
|
for (i = 0; i < config.dmmu.nways; i++)
|
|
if (getsprbits(SPR_DTLBMR_BASE(i) + set, SPR_DTLBMR_LRU))
|
|
setsprbits(SPR_DTLBMR_BASE(i) + set, SPR_DTLBMR_LRU, getsprbits(SPR_DTLBMR_BASE(i) + set, SPR_DTLBMR_LRU) - 1);
|
|
setsprbits(SPR_DTLBMR_BASE(minway) + set, SPR_DTLBMR_LRU, config.dmmu.ustates - 1);
|
|
setsprbits(SPR_DTLBTR_BASE(minway) + set, SPR_DTLBTR_PPN, vpn); /* 1 to 1 */
|
|
setsprbits(SPR_DTLBMR_BASE(minway) + set, SPR_DTLBMR_V, 1);
|
|
#endif
|
|
except_handle(EXCEPT_DTLBMISS, virtaddr);
|
|
/* if tlb refill implemented in HW */
|
|
/* return getsprbits(SPR_DTLBTR_BASE(minway) + set, SPR_DTLBTR_PPN) * config.dmmu.pagesize + (virtaddr % config.dmmu.pagesize); */
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
No newline at end of file
|
No newline at end of file
|