/* * This file is subject to the terms and conditions of the GNU General Public * License. See the file "COPYING" in the main directory of this archive * for more details. * * Copyright (C) 1996 David S. Miller (davem@davemloft.net) * Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002 Ralf Baechle (ralf@gnu.org) * Copyright (C) 1999, 2000 Silicon Graphics, Inc.
*/ #include <linux/cpu_pm.h> #include <linux/hardirq.h> #include <linux/init.h> #include <linux/highmem.h> #include <linux/kernel.h> #include <linux/linkage.h> #include <linux/preempt.h> #include <linux/sched.h> #include <linux/smp.h> #include <linux/mm.h> #include <linux/export.h> #include <linux/bitops.h> #include <linux/dma-map-ops.h> /* for dma_default_coherent */
/* * Bits describing what cache ops an SMP callback function may perform. * * R4K_HIT - Virtual user or kernel address based cache operations. The * active_mm must be checked before using user addresses, falling * back to kmap. * R4K_INDEX - Index based cache operations.
*/
#define R4K_HIT BIT(0) #define R4K_INDEX BIT(1)
/** * r4k_op_needs_ipi() - Decide if a cache op needs to be done on every core. * @type: Type of cache operations (R4K_HIT or R4K_INDEX). * * Decides whether a cache op needs to be performed on every core in the system. * This may change depending on the @type of cache operation, as well as the set * of online CPUs, so preemption should be disabled by the caller to prevent CPU * hotplug from changing the result. * * Returns: 1 if the cache operation @type should be done on every core in * the system. * 0 if the cache operation @type is globalized and only needs to * be performed on a simple CPU.
*/ staticinlinebool r4k_op_needs_ipi(unsignedint type)
{ /* The MIPS Coherence Manager (CM) globalizes address-based cache ops */ if (type == R4K_HIT && mips_cm_present()) returnfalse;
/* * Hardware doesn't globalize the required cache ops, so SMP calls may * be needed, but only if there are foreign CPUs (non-siblings with * separate caches).
*/ /* cpu_foreign_map[] undeclared when !CONFIG_SMP */ #ifdef CONFIG_SMP return !cpumask_empty(&cpu_foreign_map[0]); #else returnfalse; #endif
}
/* * Special Variant of smp_call_function for use by cache functions: * * o No return value * o collapses to normal function call on UP kernels * o collapses to normal function call on systems with a single shared * primary cache. * o doesn't disable interrupts on the local CPU
*/ staticinlinevoid r4k_on_each_cpu(unsignedint type, void (*func)(void *info), void *info)
{
preempt_disable(); if (r4k_op_needs_ipi(type))
smp_call_function_many(&cpu_foreign_map[smp_processor_id()],
func, info, 1);
func(info);
preempt_enable();
}
staticinlinevoid local_r4k___flush_cache_all(void * args)
{ switch (current_cpu_type()) { case CPU_LOONGSON2EF: case CPU_R4000SC: case CPU_R4000MC: case CPU_R4400SC: case CPU_R4400MC: case CPU_R10000: case CPU_R12000: case CPU_R14000: case CPU_R16000: /* * These caches are inclusive caches, that is, if something * is not cached in the S-cache, we know it also won't be * in one of the primary caches.
*/
r4k_blast_scache(); break;
case CPU_LOONGSON64: /* Use get_ebase_cpunum() for both NUMA=y/n */
r4k_blast_scache_node(get_ebase_cpunum() >> 2); break;
case CPU_BMIPS5000:
r4k_blast_scache();
__sync(); break;
/** * has_valid_asid() - Determine if an mm already has an ASID. * @mm: Memory map. * @type: R4K_HIT or R4K_INDEX, type of cache op. * * Determines whether @mm already has an ASID on any of the CPUs which cache ops * of type @type within an r4k_on_each_cpu() call will affect. If * r4k_on_each_cpu() does an SMP call to a single VPE in each core, then the * scope of the operation is confined to sibling CPUs, otherwise all online CPUs * will need to be checked. * * Must be called in non-preemptive context. * * Returns: 1 if the CPUs affected by @type cache ops have an ASID for @mm. * 0 otherwise.
*/ staticinlineint has_valid_asid(conststruct mm_struct *mm, unsignedint type)
{ unsignedint i; const cpumask_t *mask = cpu_present_mask;
if (cpu_has_mmid) return cpu_context(0, mm) != 0;
/* cpu_sibling_map[] undeclared when !CONFIG_SMP */ #ifdef CONFIG_SMP /* * If r4k_on_each_cpu does SMP calls, it does them to a single VPE in * each foreign core, so we only need to worry about siblings. * Otherwise we need to worry about all present CPUs.
*/ if (r4k_op_needs_ipi(type))
mask = &cpu_sibling_map[smp_processor_id()]; #endif
for_each_cpu(i, mask) if (cpu_context(i, mm)) return 1; return 0;
}
if (!has_valid_asid(vma->vm_mm, R4K_INDEX)) return;
/* * If dcache can alias, we must blast it since mapping is changing. * If executable, we must ensure any dirty lines are written back far * enough to be visible to icache.
*/ if (cpu_has_dc_aliases || (exec && !cpu_has_ic_fills_f_dc))
r4k_blast_dcache(); /* If executable, blast stale lines from icache */ if (exec)
r4k_blast_icache();
}
/* * Kludge alert. For obscure reasons R4000SC and R4400SC go nuts if we * only flush the primary caches but R1x000 behave sane ... * R4000SC and R4400SC indexed S-cache ops also invalidate primary * caches, so we can bail out early.
*/ if (current_cpu_type() == CPU_R4000SC ||
current_cpu_type() == CPU_R4000MC ||
current_cpu_type() == CPU_R4400SC ||
current_cpu_type() == CPU_R4400MC) {
r4k_blast_scache(); return;
}
r4k_blast_dcache();
}
staticvoid r4k_flush_cache_mm(struct mm_struct *mm)
{ if (!cpu_has_dc_aliases) return;
/* * Indexed cache ops require an SMP call. * Consider if that can or should be avoided.
*/
preempt_disable(); if (r4k_op_needs_ipi(R4K_INDEX) && !r4k_op_needs_ipi(R4K_HIT)) { /* * If address-based cache ops don't require an SMP call, then * use them exclusively for small flushes.
*/
size = end - start;
cache_size = icache_size; if (!cpu_has_ic_fills_f_dc) {
size *= 2;
cache_size += dcache_size;
} if (size <= cache_size)
args.type &= ~R4K_INDEX;
}
r4k_on_each_cpu(args.type, local_r4k_flush_icache_range_ipi, &args);
preempt_enable();
instruction_hazard();
}
staticvoid r4k_dma_cache_wback_inv(unsignedlong addr, unsignedlong size)
{ /* Catch bad driver code */ if (WARN_ON(size == 0)) return;
preempt_disable(); if (cpu_has_inclusive_pcaches) { if (size >= scache_size) { if (current_cpu_type() != CPU_LOONGSON64)
r4k_blast_scache(); else
r4k_blast_scache_node(pa_to_nid(addr));
} else {
blast_scache_range(addr, addr + size);
}
preempt_enable();
__sync(); return;
}
/* * Either no secondary cache or the available caches don't have the * subset property so we have to flush the primary caches * explicitly. * If we would need IPI to perform an INDEX-type operation, then * we have to use the HIT-type alternative as IPI cannot be used * here due to interrupts possibly being disabled.
*/ if (!r4k_op_needs_ipi(R4K_INDEX) && size >= dcache_size) {
r4k_blast_dcache();
} else {
R4600_HIT_CACHEOP_WAR_IMPL;
blast_dcache_range(addr, addr + size);
}
preempt_enable();
protected_writeback_scache_line(addr0); if (likely(addr1 != addr0))
protected_writeback_scache_line(addr1); else return;
addr0 += linesz; if (likely(addr1 != addr0))
protected_writeback_scache_line(addr0); else return;
addr1 -= linesz; if (likely(addr1 > addr0))
protected_writeback_scache_line(addr0);
}
staticvoid r4k_dma_cache_inv(unsignedlong addr, unsignedlong size)
{ /* Catch bad driver code */ if (WARN_ON(size == 0)) return;
preempt_disable();
if (current_cpu_type() == CPU_BMIPS5000)
prefetch_cache_inv(addr, size);
if (cpu_has_inclusive_pcaches) { if (size >= scache_size) { if (current_cpu_type() != CPU_LOONGSON64)
r4k_blast_scache(); else
r4k_blast_scache_node(pa_to_nid(addr));
} else { /* * There is no clearly documented alignment requirement * for the cache instruction on MIPS processors and * some processors, among them the RM5200 and RM7000 * QED processors will throw an address error for cache * hit ops with insufficient alignment. Solved by * aligning the address to cache line size.
*/
blast_inv_scache_range(addr, addr + size);
}
preempt_enable();
__sync(); return;
}
staticvoid r4k_flush_icache_all(void)
{ if (cpu_has_vtag_icache)
r4k_blast_icache();
}
struct flush_kernel_vmap_range_args { unsignedlong vaddr; int size;
};
staticinlinevoid local_r4k_flush_kernel_vmap_range_index(void *args)
{ /* * Aliases only affect the primary caches so don't bother with * S-caches or T-caches.
*/
r4k_blast_dcache();
}
/* * Aliases only affect the primary caches so don't bother with * S-caches or T-caches.
*/
R4600_HIT_CACHEOP_WAR_IMPL;
blast_dcache_range(vaddr, vaddr + size);
}
staticvoid r4k_flush_kernel_vmap_range(unsignedlong vaddr, int size)
{ struct flush_kernel_vmap_range_args args;
/* * Early versions of the 74K do not update the cache tags on a * vtag miss/ptag hit which can occur in the case of KSEG0/KUSEG * aliases. In this case it is better to treat the cache as always * having aliases. Also disable the synonym tag update feature * where available. In this case no opportunistic tag update will * happen where a load causes a virtual address miss but a physical * address hit during a D-cache look-up.
*/ switch (imp) { case PRID_IMP_74K: if (rev <= PRID_REV_ENCODE_332(2, 4, 0))
present = 1; if (rev == PRID_REV_ENCODE_332(2, 4, 0))
write_c0_config6(read_c0_config6() | MTI_CONF6_SYND); break; case PRID_IMP_1074K: if (rev <= PRID_REV_ENCODE_332(1, 1, 0)) {
present = 1;
write_c0_config6(read_c0_config6() | MTI_CONF6_SYND);
} break; default:
BUG();
}
case CPU_CAVIUM_OCTEON3: /* For now lie about the number of ways. */
c->icache.linesz = 128;
c->icache.sets = 16;
c->icache.ways = 8;
c->icache.flags |= MIPS_CACHE_VTAG;
icache_size = c->icache.sets * c->icache.ways * c->icache.linesz;
/* * Processor configuration sanity check for the R4000SC erratum * #5. With page sizes larger than 32kB there is no possibility * to get a VCE exception anymore so we don't care about this * misconfiguration. The case is rather theoretical anyway; * presumably no vendor is shipping his hardware in the "bad" * configuration.
*/ if ((prid & PRID_IMP_MASK) == PRID_IMP_R4000 &&
(prid & PRID_REV_MASK) < PRID_REV_R4400 &&
!(config & CONF_SC) && c->icache.linesz != 16 &&
PAGE_SIZE <= 0x8000)
panic("Improper R4000SC processor configuration detected");
/* compute a couple of other cache variables */
c->icache.waysize = icache_size / c->icache.ways;
c->dcache.waysize = dcache_size / c->dcache.ways;
/* * R1x000 P-caches are odd in a positive way. They're 32kB 2-way * virtually indexed so normally would suffer from aliases. So * normally they'd suffer from aliases but magic in the hardware deals * with that for us so we don't need to take care ourselves.
*/ switch (current_cpu_type()) { case CPU_20KC: case CPU_25KF: case CPU_I6400: case CPU_I6500: case CPU_SB1: case CPU_SB1A:
c->dcache.flags |= MIPS_CACHE_PINDEX; break;
case CPU_R10000: case CPU_R12000: case CPU_R14000: case CPU_R16000: break;
case CPU_74K: case CPU_1074K:
has_74k_erratum = alias_74k_erratum(c);
fallthrough; case CPU_M14KC: case CPU_M14KEC: case CPU_24K: case CPU_34K: case CPU_1004K: case CPU_INTERAPTIV: case CPU_P5600: case CPU_PROAPTIV: case CPU_M5150: case CPU_QEMU_GENERIC: case CPU_P6600: case CPU_M6250: if (!(read_c0_config7() & MIPS_CONF7_IAR) &&
(c->icache.waysize > PAGE_SIZE))
c->icache.flags |= MIPS_CACHE_ALIASES; if (!has_74k_erratum && (read_c0_config7() & MIPS_CONF7_AR)) { /* * Effectively physically indexed dcache, * thus no virtual aliases.
*/
c->dcache.flags |= MIPS_CACHE_PINDEX; break;
}
fallthrough; default: if (has_74k_erratum || c->dcache.waysize > PAGE_SIZE)
c->dcache.flags |= MIPS_CACHE_ALIASES;
}
/* Physically indexed caches don't suffer from virtual aliasing */ if (c->dcache.flags & MIPS_CACHE_PINDEX)
c->dcache.flags &= ~MIPS_CACHE_ALIASES;
/* * In systems with CM the icache fills from L2 or closer caches, and * thus sees remote stores without needing to write them back any * further than that.
*/ if (mips_cm_present())
c->icache.flags |= MIPS_IC_SNOOPS_REMOTE;
switch (current_cpu_type()) { case CPU_20KC: /* * Some older 20Kc chips doesn't have the 'VI' bit in * the config register.
*/
c->icache.flags |= MIPS_CACHE_VTAG; break;
case CPU_ALCHEMY: case CPU_I6400: case CPU_I6500:
c->icache.flags |= MIPS_CACHE_IC_F_DC; break;
case CPU_BMIPS5000:
c->icache.flags |= MIPS_CACHE_IC_F_DC; /* Cache aliases are handled in hardware; allow HIGHMEM */
c->dcache.flags &= ~MIPS_CACHE_ALIASES; break;
case CPU_LOONGSON2EF: /* * LOONGSON2 has 4 way icache, but when using indexed cache op, * one op will act on all 4 ways
*/
c->icache.ways = 1;
}
/* * If you even _breathe_ on this function, look at the gcc output and make sure * it does not pop things on and off the stack for the cache sizing loop that * executes in KSEG1 space or else you will crash and burn badly. You have * been warned.
*/ staticint probe_scache(void)
{ unsignedlong flags, addr, begin, end, pow2; unsignedint config = read_c0_config(); struct cpuinfo_mips *c = ¤t_cpu_data;
if (config & CONF_SC) return 0;
begin = (unsignedlong) &_stext;
begin &= ~((4 * 1024 * 1024) - 1);
end = begin + (4 * 1024 * 1024);
/* * This is such a bitch, you'd think they would make it easy to do * this. Away you daemons of stupidity!
*/
local_irq_save(flags);
/* Fill each size-multiple cache line with a valid tag. */
pow2 = (64 * 1024); for (addr = begin; addr < end; addr = (begin + pow2)) { unsignedlong *p = (unsignedlong *) addr;
__asm__ __volatile__("nop" : : "r" (*p)); /* whee... */
pow2 <<= 1;
}
/* Load first line with zero (therefore invalid) tag. */
write_c0_taglo(0);
write_c0_taghi(0);
__asm__ __volatile__("nop; nop; nop; nop;"); /* avoid the hazard */
cache_op(Index_Store_Tag_I, begin);
cache_op(Index_Store_Tag_D, begin);
cache_op(Index_Store_Tag_SD, begin);
/* Now search for the wrap around point. */
pow2 = (128 * 1024); for (addr = begin + (128 * 1024); addr < end; addr = begin + pow2) {
cache_op(Index_Load_Tag_SD, addr);
__asm__ __volatile__("nop; nop; nop; nop;"); /* hazard... */ if (!read_c0_taglo()) break;
pow2 <<= 1;
}
local_irq_restore(flags);
addr -= begin;
/* Loongson-3 has 4-Scache banks, while Loongson-2K have only 2 banks */ if ((c->processor_id & PRID_IMP_MASK) == PRID_IMP_LOONGSON_64R)
c->scache.sets *= 2; else
c->scache.sets *= 4;
/* * Do the probing thing on R4000SC and R4400SC processors. Other * processors don't have a S-cache that would be relevant to the * Linux memory management.
*/ switch (current_cpu_type()) { case CPU_R4000SC: case CPU_R4000MC: case CPU_R4400SC: case CPU_R4400MC:
sc_present = run_uncached(probe_scache); if (sc_present)
c->options |= MIPS_CPU_CACHE_CDEX_S; break;
case CPU_R10000: case CPU_R12000: case CPU_R14000: case CPU_R16000:
scache_size = 0x80000 << ((config & R10K_CONF_SS) >> 16);
c->scache.linesz = 64 << ((config >> 13) & 1);
c->scache.ways = 2;
c->scache.waybit= 0;
sc_present = 1; break;
case CPU_R5000: case CPU_NEVADA: #ifdef CONFIG_R5000_CPU_SCACHE
r5k_sc_init(); #endif return;
case CPU_RM7000: #ifdef CONFIG_RM7000_CPU_SCACHE
rm7k_sc_init(); #endif return;
case CPU_LOONGSON2EF:
loongson2_sc_init(); return;
case CPU_LOONGSON64:
loongson3_sc_init(); return;
case CPU_CAVIUM_OCTEON3: /* don't need to worry about L2, fully coherent */ return;
void au1x00_fixup_config_od(void)
{ /* * c0_config.od (bit 19) was write only (and read as 0) * on the early revisions of Alchemy SOCs. It disables the bus * transaction overlapping and needs to be set to fix various errata.
*/ switch (read_c0_prid()) { case 0x00030100: /* Au1000 DA */ case 0x00030201: /* Au1000 HA */ case 0x00030202: /* Au1000 HB */ case 0x01030200: /* Au1500 AB */ /* * Au1100 errata actually keeps silence about this bit, so we set it * just in case for those revisions that require it to be set according * to the (now gone) cpu table.
*/ case 0x02030200: /* Au1100 AB */ case 0x02030201: /* Au1100 BA */ case 0x02030202: /* Au1100 BC */
set_c0_config(1 << 19); break;
}
}
/* * c0_status.cu=0 specifies that updates by the sc instruction use * the coherency mode specified by the TLB; 1 means cacheable * coherent update on write will be used. Not all processors have * this bit and; some wire it to zero, others like Toshiba had the * silly idea of putting something else there ...
*/ switch (current_cpu_type()) { case CPU_R4000PC: case CPU_R4000SC: case CPU_R4000MC: case CPU_R4400PC: case CPU_R4400SC: case CPU_R4400MC:
clear_c0_config(CONF_CU); break; /* * We need to catch the early Alchemy SOCs with * the write-only co_config.od bit and set it back to one on: * Au1000 rev DA, HA, HB; Au1100 AB, BA, BC, Au1500 AB
*/ case CPU_ALCHEMY:
au1x00_fixup_config_od(); break;
case PRID_IMP_PR4450:
nxp_pr4450_fixup_config(); break;
}
}
/* * We want to run CMP kernels on core with and without coherent * caches. Therefore, do not use CONFIG_MIPS_CMP to decide whether * or not to flush caches.
*/
local_r4k___flush_cache_all(NULL);
/* * Per-CPU overrides
*/ switch (current_cpu_type()) { case CPU_BMIPS4350: case CPU_BMIPS4380: /* No IPI is needed because all CPUs share the same D$ */
flush_data_cache_page = r4k_blast_dcache_page; break; case CPU_BMIPS5000: /* We lose our superpowers if L2 is disabled */ if (c->scache.flags & MIPS_CACHE_NOT_PRESENT) break;
/* I$ fills from D$ just by emptying the write buffers */
flush_cache_page = (void *)b5k_instruction_hazard;
flush_cache_range = (void *)b5k_instruction_hazard;
flush_data_cache_page = (void *)b5k_instruction_hazard;
flush_icache_range = (void *)b5k_instruction_hazard;
local_flush_icache_range = (void *)b5k_instruction_hazard;
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.