/* * Low-level cache maintenance operations. * * As well as the regular 'clean/invalidate/flush L2 cache line by * MVA' instructions, the Feroceon L2 cache controller also features * 'clean/invalidate L2 range by MVA' operations. * * Cache range operations are initiated by writing the start and * end addresses to successive cp15 registers, and process every * cache line whose first byte address lies in the inclusive range * [start:end]. * * The cache range operations stall the CPU pipeline until completion. * * The range operations require two successive cp15 writes, in * between which we don't want to be preempted.
*/
staticinlineunsignedlong l2_get_va(unsignedlong paddr)
{ #ifdef CONFIG_HIGHMEM /* * Because range ops can't be done on physical addresses, * we simply install a virtual mapping for it only for the * TLB lookup to occur, hence no need to flush the untouched * memory mapping afterwards (note: a cache flush may happen * in some circumstances depending on the path taken in kunmap_atomic).
*/ void *vaddr = kmap_atomic_pfn(paddr >> PAGE_SHIFT); return (unsignedlong)vaddr + (paddr & ~PAGE_MASK); #else return __phys_to_virt(paddr); #endif
}
/* * Make sure 'start' and 'end' reference the same page, as * L2 is PIPT and range operations only do a TLB lookup on * the start address.
*/
BUG_ON((start ^ end) >> PAGE_SHIFT);
/* * Make sure 'start' and 'end' reference the same page, as * L2 is PIPT and range operations only do a TLB lookup on * the start address.
*/
BUG_ON((start ^ end) >> PAGE_SHIFT);
/* * Linux primitives. * * Note that the end addresses passed to Linux primitives are * noninclusive, while the hardware cache range operations use * inclusive start and end addresses.
*/ #define CACHE_LINE_SIZE 32 #define MAX_RANGE_SIZE 1024
/* * Try to process all cache lines between 'start' and 'end'.
*/
range_end = end;
/* * Limit the number of cache lines processed at once, * since cache range operations stall the CPU pipeline * until completion.
*/ if (range_end > start + MAX_RANGE_SIZE)
range_end = start + MAX_RANGE_SIZE;
/* * Cache range operations can't straddle a page boundary.
*/ if (range_end > (start | (PAGE_SIZE - 1)) + 1)
range_end = (start | (PAGE_SIZE - 1)) + 1;
/* * Clean and invalidate partial last cache line.
*/ if (start < end && end & (CACHE_LINE_SIZE - 1)) {
l2_clean_inv_pa(end & ~(CACHE_LINE_SIZE - 1));
end &= ~(CACHE_LINE_SIZE - 1);
}
/* * Invalidate all full cache lines between 'start' and 'end'.
*/ while (start < end) { unsignedlong range_end = calc_range_end(start, end);
l2_inv_pa_range(start, range_end - CACHE_LINE_SIZE);
start = range_end;
}
dsb();
}
staticvoid feroceon_l2_clean_range(unsignedlong start, unsignedlong end)
{ /* * If L2 is forced to WT, the L2 will always be clean and we * don't need to do anything here.
*/ if (!l2_wt_override) {
start &= ~(CACHE_LINE_SIZE - 1);
end = (end + CACHE_LINE_SIZE - 1) & ~(CACHE_LINE_SIZE - 1); while (start != end) { unsignedlong range_end = calc_range_end(start, end);
l2_clean_pa_range(start, range_end - CACHE_LINE_SIZE);
start = range_end;
}
}
/* * Routines to disable and re-enable the D-cache and I-cache at run * time. These are necessary because the L2 cache can only be enabled * or disabled while the L1 Dcache and Icache are both disabled.
*/ staticint __init flush_and_disable_dcache(void)
{
u32 cr;
cr = get_cr(); if (cr & CR_C) { unsignedlong flags;
/* * Read the CPU Extra Features register and verify that the * Disable L2 Prefetch bit is set.
*/
u = read_extra_features(); if (!(u & 0x01000000)) {
pr_info("Feroceon L2: Disabling L2 prefetch.\n");
write_extra_features(u | 0x01000000);
}
}
staticvoid __init enable_l2(void)
{
u32 u;
u = read_extra_features(); if (!(u & 0x00400000)) { int i, d;
pr_info("Feroceon L2: Enabling L2\n");
d = flush_and_disable_dcache();
i = invalidate_and_disable_icache();
l2_inv_all();
write_extra_features(u | 0x00400000); if (i)
enable_icache(); if (d)
enable_dcache();
} else
pr_err(FW_BUG "Feroceon L2: bootloader left the L2 cache on!\n");
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.