/* * Common code for all cache controllers.
*/ staticinlinevoid l2c_wait_mask(void __iomem *reg, unsignedlong mask)
{ /* wait for cache operation by line or way to complete */ while (readl_relaxed(reg) & mask)
cpu_relax();
}
/* * By default, we write directly to secure registers. Platforms must * override this if they are running non-secure.
*/ staticvoid l2c_write_sec(unsignedlong val, void __iomem *base, unsigned reg)
{ if (val == readl_relaxed(base + reg)) return; if (outer_cache.write_sec)
outer_cache.write_sec(val, reg); else
writel_relaxed(val, base + reg);
}
/* * This should only be called when we have a requirement that the * register be written due to a work-around, as platforms running * in non-secure mode may not be able to access this register.
*/ staticinlinevoid l2c_set_debug(void __iomem *base, unsignedlong val)
{
l2c_write_sec(val, base, L2X0_DEBUG_CTRL);
}
for (i = 0; i < num; i++) {
writel_relaxed(0, base + L2X0_LOCKDOWN_WAY_D_BASE +
i * L2X0_LOCKDOWN_STRIDE);
writel_relaxed(0, base + L2X0_LOCKDOWN_WAY_I_BASE +
i * L2X0_LOCKDOWN_STRIDE);
}
}
/* * Enable the L2 cache controller. This function must only be * called when the cache controller is known to be disabled.
*/ staticvoid l2c_enable(void __iomem *base, unsigned num_lock)
{ unsignedlong flags;
if (outer_cache.configure)
outer_cache.configure(&l2x0_saved_regs); else
l2x0_data->configure(base);
/* Do not touch the controller if already enabled. */ if (!(readl_relaxed(base + L2X0_CTRL) & L2X0_CTRL_EN))
l2c_enable(base, l2x0_data->num_lock);
l2x0_pmu_resume();
}
/* * L2C-210 specific code. * * The L2C-2x0 PA, set/way and sync operations are atomic, but we must * ensure that no background operation is running. The way operations * are all background tasks. * * While a background operation is in progress, any new operation is * ignored (unspecified whether this causes an error.) Thankfully, not * used on SMP. * * Never has a different sync register other than L2X0_CACHE_SYNC, but * we use sync_reg_offset here so we can share some of this with L2C-310.
*/ staticvoid __l2c210_cache_sync(void __iomem *base)
{
writel_relaxed(0, base + sync_reg_offset);
}
/* * L2C-220 specific code. * * All operations are background operations: they have to be waited for. * Conflicting requests generate a slave error (which will cause an * imprecise abort.) Never uses sync_reg_offset, so we hard-code the * sync register here. * * However, we can re-use the l2c210_resume call.
*/ staticinlinevoid __l2c220_cache_sync(void __iomem *base)
{
writel_relaxed(0, base + L2X0_CACHE_SYNC);
l2c_wait_mask(base + L2X0_CACHE_SYNC, 1);
}
staticvoid l2c220_enable(void __iomem *base, unsigned num_lock)
{ /* * Always enable non-secure access to the lockdown registers - * we write to them as part of the L2C enable sequence so they * need to be accessible.
*/
l2x0_saved_regs.aux_ctrl |= L220_AUX_CTRL_NS_LOCKDOWN;
/* * L2C-310 specific code. * * Very similar to L2C-210, the PA, set/way and sync operations are atomic, * and the way operations are all background tasks. However, issuing an * operation while a background operation is in progress results in a * SLVERR response. We can reuse: * * __l2c210_cache_sync (using sync_reg_offset) * l2c210_sync * l2c210_inv_range (if 588369 is not applicable) * l2c210_clean_range * l2c210_flush_range (if 588369 is not applicable) * l2c210_flush_all (if 727915 is not applicable) * * Errata: * 588369: PL310 R0P0->R1P0, fixed R2P0. * Affects: all clean+invalidate operations * clean and invalidate skips the invalidate step, so we need to issue * separate operations. We also require the above debug workaround * enclosing this code fragment on affected parts. On unaffected parts, * we must not use this workaround without the debug register writes * to avoid exposing a problem similar to 727915. * * 727915: PL310 R2P0->R3P0, fixed R3P1. * Affects: clean+invalidate by way * clean and invalidate by way runs in the background, and a store can * hit the line between the clean operation and invalidate operation, * resulting in the store being lost. * * 752271: PL310 R3P0->R3P1-50REL0, fixed R3P2. * Affects: 8x64-bit (double fill) line fetches * double fill line fetches can fail to cause dirty data to be evicted * from the cache before the new data overwrites the second line. * * 753970: PL310 R3P0, fixed R3P1. * Affects: sync * prevents merging writes after the sync operation, until another L2C * operation is performed (or a number of other conditions.) * * 769419: PL310 R0P0->R3P1, fixed R3P2. * Affects: store buffer * store buffer is not automatically drained.
*/ staticvoid l2c310_inv_range_erratum(unsignedlong start, unsignedlong end)
{ void __iomem *base = l2x0_base;
/* From r2p0, there is Prefetch offset/control register */ if (revision >= L310_CACHE_ID_RTL_R2P0)
l2x0_saved_regs.prefetch_ctrl = readl_relaxed(base +
L310_PREFETCH_CTRL);
/* From r3p0, there is Power control register */ if (revision >= L310_CACHE_ID_RTL_R3P0)
l2x0_saved_regs.pwr_ctrl = readl_relaxed(base +
L310_POWER_CTRL);
}
if (rev >= L310_CACHE_ID_RTL_R2P0) { if (cortex_a9 && !l2x0_bresp_disable) {
aux |= L310_AUX_CTRL_EARLY_BRESP;
pr_info("L2C-310 enabling early BRESP for Cortex-A9\n");
} elseif (aux & L310_AUX_CTRL_EARLY_BRESP) {
pr_warn("L2C-310 early BRESP only supported with Cortex-A9\n");
aux &= ~L310_AUX_CTRL_EARLY_BRESP;
}
}
if (acr & BIT(3) && !(aux_cur & L310_AUX_CTRL_FULL_LINE_ZERO))
pr_err("L2C-310: full line of zeros enabled in Cortex-A9 but not L2C-310 - invalid\n");
if (aux & L310_AUX_CTRL_FULL_LINE_ZERO && !(acr & BIT(3)))
pr_err("L2C-310: enabling full line of zeros but not enabled in Cortex-A9\n");
if (!(aux & L310_AUX_CTRL_FULL_LINE_ZERO) && !outer_cache.write_sec) {
aux |= L310_AUX_CTRL_FULL_LINE_ZERO;
pr_info("L2C-310 full line of zeros enabled for Cortex-A9\n");
}
} elseif (aux & (L310_AUX_CTRL_FULL_LINE_ZERO | L310_AUX_CTRL_EARLY_BRESP)) {
pr_err("L2C-310: disabling Cortex-A9 specific feature bits\n");
aux &= ~(L310_AUX_CTRL_FULL_LINE_ZERO | L310_AUX_CTRL_EARLY_BRESP);
}
/* * Always enable non-secure access to the lockdown registers - * we write to them as part of the L2C enable sequence so they * need to be accessible.
*/
l2x0_saved_regs.aux_ctrl = aux | L310_AUX_CTRL_NS_LOCKDOWN;
l2c_enable(base, num_lock);
/* Read back resulting AUX_CTRL value as it could have been altered. */
aux = readl_relaxed(base + L2X0_AUX_CTRL);
if (IS_ENABLED(CONFIG_PL310_ERRATA_769419))
errata[n++] = "769419";
if (n) { unsigned i;
pr_info("L2C-310 errat%s", n > 1 ? "a" : "um"); for (i = 0; i < n; i++)
pr_cont(" %s", errata[i]);
pr_cont(" enabled\n");
}
}
staticvoid l2c310_disable(void)
{ /* * If full-line-of-zeros is enabled, we must first disable it in the * Cortex-A9 auxiliary control register before disabling the L2 cache.
*/ if (l2x0_saved_regs.aux_ctrl & L310_AUX_CTRL_FULL_LINE_ZERO)
set_auxcr(get_auxcr() & ~(BIT(3) | BIT(2) | BIT(1)));
l2c_disable();
}
staticvoid l2c310_resume(void)
{
l2c_resume();
/* Re-enable full-line-of-zeros for Cortex-A9 */ if (l2x0_saved_regs.aux_ctrl & L310_AUX_CTRL_FULL_LINE_ZERO)
set_auxcr(get_auxcr() | BIT(3) | BIT(2) | BIT(1));
}
/* * Save the pointer globally so that callbacks which do not receive * context from callers can access the structure.
*/
l2x0_data = kmemdup(data, sizeof(*data), GFP_KERNEL); if (!l2x0_data) return -ENOMEM;
/* * Sanity check the aux values. aux_mask is the bits we preserve * from reading the hardware register, and aux_val is the bits we * set.
*/ if (aux_val & aux_mask)
pr_alert("L2C: platform provided aux values permit register corruption.\n");
old_aux = aux = readl_relaxed(l2x0_base + L2X0_AUX_CTRL);
aux &= aux_mask;
aux |= aux_val;
if (old_aux != aux)
pr_warn("L2C: DT/platform modifies aux control register: 0x%08x -> 0x%08x\n",
old_aux, aux);
/* Determine the number of ways */ switch (cache_id & L2X0_CACHE_ID_PART_MASK) { case L2X0_CACHE_ID_PART_L310: if ((aux_val | ~aux_mask) & (L2C_AUX_CTRL_WAY_SIZE_MASK | L310_AUX_CTRL_ASSOCIATIVITY_16))
pr_warn("L2C: DT/platform tries to modify or specify cache size\n"); if (aux & (1 << 16))
ways = 16; else
ways = 8; break;
case L2X0_CACHE_ID_PART_L210: case L2X0_CACHE_ID_PART_L220:
ways = (aux >> 13) & 0xf; break;
/* * way_size_0 is the size that a way_size value of zero would be * given the calculation: way_size = way_size_0 << way_size_bits. * So, if way_size_bits=0 is reserved, but way_size_bits=1 is 16k, * then way_size_0 would be 8k. * * L2 cache size = number of ways * way size.
*/
way_size_bits = (aux & L2C_AUX_CTRL_WAY_SIZE_MASK) >>
L2C_AUX_CTRL_WAY_SIZE_SHIFT;
l2x0_size = ways * (data->way_size_0 << way_size_bits);
/* * Check if l2x0 controller is already enabled. If we are booting * in non-secure mode accessing the below registers will fault.
*/ if (!(readl_relaxed(l2x0_base + L2X0_CTRL) & L2X0_CTRL_EN)) {
l2x0_saved_regs.aux_ctrl = aux;
data->enable(l2x0_base, data->num_lock);
}
outer_cache = fns;
/* * It is strange to save the register state before initialisation, * but hey, this is what the DT implementations decided to do.
*/ if (data->save)
data->save(l2x0_base);
/* Re-read it in case some bits are reserved. */
aux = readl_relaxed(l2x0_base + L2X0_AUX_CTRL);
/* Aurora don't have the cache ID register available, so we have to
* pass it though the device tree */ static u32 cache_id_part_number_from_dt;
/** * l2x0_cache_size_of_parse() - read cache size parameters from DT * @np: the device tree node for the l2 cache * @aux_val: pointer to machine-supplied auxilary register value, to * be augmented by the call (bits to be set to 1) * @aux_mask: pointer to machine-supplied auxilary register mask, to * be augmented by the call (bits to be set to 0) * @associativity: variable to return the calculated associativity in * @max_way_size: the maximum size in bytes for the cache ways
*/ staticint __init l2x0_cache_size_of_parse(conststruct device_node *np,
u32 *aux_val, u32 *aux_mask,
u32 *associativity,
u32 max_way_size)
{
u32 mask = 0, val = 0;
u32 cache_size = 0, sets = 0;
u32 way_size_bits = 1;
u32 way_size = 0;
u32 block_size = 0;
u32 line_size = 0;
/* All these l2 caches have the same line = block size actually */ if (!line_size) { if (block_size) { /* If linesize is not given, it is equal to blocksize */
line_size = block_size;
} else { /* Fall back to known size */
pr_warn("L2C OF: no cache block/line size given: " "falling back to default size %d bytes\n",
CACHE_LINE_SIZE);
line_size = CACHE_LINE_SIZE;
}
}
if (line_size != CACHE_LINE_SIZE)
pr_warn("L2C OF: DT supplied line size %d bytes does " "not match hardware line size of %d bytes\n",
line_size,
CACHE_LINE_SIZE);
/* * Since: * set size = cache size / sets * ways = cache size / (sets * line size) * way size = cache size / (cache size / (sets * line size)) * way size = sets * line size * associativity = ways = cache size / way size
*/
way_size = sets * line_size;
*associativity = cache_size / way_size;
if (way_size > max_way_size) {
pr_err("L2C OF: set size %dKB is too large\n", way_size); return -EINVAL;
}
if (of_property_read_bool(np, "arm,early-bresp-disable"))
l2x0_bresp_disable = true;
if (of_property_read_bool(np, "arm,full-line-zero-disable"))
l2x0_flz_disable = true;
prefetch = l2x0_saved_regs.prefetch_ctrl;
ret = of_property_read_u32(np, "arm,double-linefill", &val); if (ret == 0) { if (val)
prefetch |= L310_PREFETCH_CTRL_DBL_LINEFILL; else
prefetch &= ~L310_PREFETCH_CTRL_DBL_LINEFILL;
} elseif (ret != -EINVAL) {
pr_err("L2C-310 OF arm,double-linefill property value is missing\n");
}
ret = of_property_read_u32(np, "arm,double-linefill-incr", &val); if (ret == 0) { if (val)
prefetch |= L310_PREFETCH_CTRL_DBL_LINEFILL_INCR; else
prefetch &= ~L310_PREFETCH_CTRL_DBL_LINEFILL_INCR;
} elseif (ret != -EINVAL) {
pr_err("L2C-310 OF arm,double-linefill-incr property value is missing\n");
}
ret = of_property_read_u32(np, "arm,double-linefill-wrap", &val); if (ret == 0) { if (!val)
prefetch |= L310_PREFETCH_CTRL_DBL_LINEFILL_WRAP; else
prefetch &= ~L310_PREFETCH_CTRL_DBL_LINEFILL_WRAP;
} elseif (ret != -EINVAL) {
pr_err("L2C-310 OF arm,double-linefill-wrap property value is missing\n");
}
ret = of_property_read_u32(np, "arm,prefetch-drop", &val); if (ret == 0) { if (val)
prefetch |= L310_PREFETCH_CTRL_PREFETCH_DROP; else
prefetch &= ~L310_PREFETCH_CTRL_PREFETCH_DROP;
} elseif (ret != -EINVAL) {
pr_err("L2C-310 OF arm,prefetch-drop property value is missing\n");
}
ret = of_property_read_u32(np, "arm,prefetch-offset", &val); if (ret == 0) {
prefetch &= ~L310_PREFETCH_CTRL_OFFSET_MASK;
prefetch |= val & L310_PREFETCH_CTRL_OFFSET_MASK;
} elseif (ret != -EINVAL) {
pr_err("L2C-310 OF arm,prefetch-offset property value is missing\n");
}
ret = of_property_read_u32(np, "prefetch-data", &val); if (ret == 0) { if (val) {
prefetch |= L310_PREFETCH_CTRL_DATA_PREFETCH;
*aux_val |= L310_PREFETCH_CTRL_DATA_PREFETCH;
} else {
prefetch &= ~L310_PREFETCH_CTRL_DATA_PREFETCH;
*aux_val &= ~L310_PREFETCH_CTRL_DATA_PREFETCH;
}
*aux_mask &= ~L310_PREFETCH_CTRL_DATA_PREFETCH;
} elseif (ret != -EINVAL) {
pr_err("L2C-310 OF prefetch-data property value is missing\n");
}
ret = of_property_read_u32(np, "prefetch-instr", &val); if (ret == 0) { if (val) {
prefetch |= L310_PREFETCH_CTRL_INSTR_PREFETCH;
*aux_val |= L310_PREFETCH_CTRL_INSTR_PREFETCH;
} else {
prefetch &= ~L310_PREFETCH_CTRL_INSTR_PREFETCH;
*aux_val &= ~L310_PREFETCH_CTRL_INSTR_PREFETCH;
}
*aux_mask &= ~L310_PREFETCH_CTRL_INSTR_PREFETCH;
} elseif (ret != -EINVAL) {
pr_err("L2C-310 OF prefetch-instr property value is missing\n");
}
l2x0_saved_regs.prefetch_ctrl = prefetch;
power = l2x0_saved_regs.pwr_ctrl |
L310_DYNAMIC_CLK_GATING_EN | L310_STNDBY_MODE_EN;
ret = of_property_read_u32(np, "arm,dynamic-clock-gating", &val); if (!ret) { if (!val)
power &= ~L310_DYNAMIC_CLK_GATING_EN;
} elseif (ret != -EINVAL) {
pr_err("L2C-310 OF dynamic-clock-gating property value is missing or invalid\n");
}
ret = of_property_read_u32(np, "arm,standby-mode", &val); if (!ret) { if (!val)
power &= ~L310_STNDBY_MODE_EN;
} elseif (ret != -EINVAL) {
pr_err("L2C-310 OF standby-mode property value is missing or invalid\n");
}
/* * This is a variant of the of_l2c310_data with .sync set to * NULL. Outer sync operations are not needed when the system is I/O * coherent, and potentially harmful in certain situations (PCIe/PL310 * deadlock on Armada 375/38x due to hardware I/O coherency). The * other operations are kept because they are infrequent (therefore do * not cause the deadlock in practice) and needed for secondary CPU * boot and other power management activities.
*/ staticconststruct l2c_init_data of_l2c310_coherent_data __initconst = {
.type = "L2C-310 Coherent",
.way_size_0 = SZ_8K,
.num_lock = 8,
.of_parse = l2c310_of_parse,
.enable = l2c310_enable,
.fixup = l2c310_fixup,
.save = l2c310_save,
.configure = l2c310_configure,
.unlock = l2c310_unlock,
.outer_cache = {
.inv_range = l2c210_inv_range,
.clean_range = l2c210_clean_range,
.flush_range = l2c210_flush_range,
.flush_all = l2c210_flush_all,
.disable = l2c310_disable,
.resume = l2c310_resume,
},
};
/* * Note that the end addresses passed to Linux primitives are * noninclusive, while the hardware cache range operations use * inclusive start and end addresses.
*/ staticunsignedlong aurora_range_end(unsignedlong start, unsignedlong end)
{ /* * Limit the number of cache lines processed at once, * since cache range operations stall the CPU pipeline * until completion.
*/ if (end > start + AURORA_MAX_RANGE_SIZE)
end = start + AURORA_MAX_RANGE_SIZE;
/* * Cache range operations can't straddle a page boundary.
*/ if (end > PAGE_ALIGN(start+1))
end = PAGE_ALIGN(start+1);
staticvoid aurora_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)
aurora_pa_range(start, end, AURORA_CLEAN_RANGE_REG);
}
/* * For Aurora cache in no outer mode, enable via the CP15 coprocessor * broadcasting of cache commands to L2.
*/ staticvoid __init aurora_enable_no_outer(void __iomem *base, unsigned num_lock)
{
u32 u;
asmvolatile("mrc p15, 1, %0, c15, c2, 0" : "=r" (u));
u |= AURORA_CTRL_FW; /* Set the FW bit */ asmvolatile("mcr p15, 1, %0, c15, c2, 0" : : "r" (u));
/* * For certain Broadcom SoCs, depending on the address range, different offsets * need to be added to the address before passing it to L2 for * invalidation/clean/flush * * Section Address Range Offset EMI * 1 0x00000000 - 0x3FFFFFFF 0x80000000 VC * 2 0x40000000 - 0xBFFFFFFF 0x40000000 SYS * 3 0xC0000000 - 0xFFFFFFFF 0x80000000 VC * * When the start and end addresses have crossed two different sections, we * need to break the L2 operation into two, each within its own section. * For example, if we need to invalidate addresses starts at 0xBFFF0000 and * ends at 0xC0001000, we need do invalidate 1) 0xBFFF0000 - 0xBFFFFFFF and 2) * 0xC0000000 - 0xC0001000 * * Note 1: * By breaking a single L2 operation into two, we may potentially suffer some * performance hit, but keep in mind the cross section case is very rare * * Note 2: * We do not need to handle the case when the start address is in * Section 1 and the end address is in Section 3, since it is not a valid use * case * * Note 3: * Section 1 in practical terms can no longer be used on rev A2. Because of * that the code does not need to handle section 1 at all. *
*/ #define BCM_SYS_EMI_START_ADDR 0x40000000UL #define BCM_VC_EMI_SEC3_START_ADDR 0xC0000000UL
/* normal case, no cross section between start and end */ if (likely(bcm_addr_is_sys_emi(end) || !bcm_addr_is_sys_emi(start))) {
l2c210_inv_range(new_start, new_end); return;
}
/* They cross sections, so it can only be a cross from section * 2 to section 3
*/
l2c210_inv_range(new_start,
bcm_l2_phys_addr(BCM_VC_EMI_SEC3_START_ADDR-1));
l2c210_inv_range(bcm_l2_phys_addr(BCM_VC_EMI_SEC3_START_ADDR),
new_end);
}
/* normal case, no cross section between start and end */ if (likely(bcm_addr_is_sys_emi(end) || !bcm_addr_is_sys_emi(start))) {
l2c210_clean_range(new_start, new_end); return;
}
/* They cross sections, so it can only be a cross from section * 2 to section 3
*/
l2c210_clean_range(new_start,
bcm_l2_phys_addr(BCM_VC_EMI_SEC3_START_ADDR-1));
l2c210_clean_range(bcm_l2_phys_addr(BCM_VC_EMI_SEC3_START_ADDR),
new_end);
}
/* normal case, no cross section between start and end */ if (likely(bcm_addr_is_sys_emi(end) || !bcm_addr_is_sys_emi(start))) {
l2c210_flush_range(new_start, new_end); return;
}
/* They cross sections, so it can only be a cross from section * 2 to section 3
*/
l2c210_flush_range(new_start,
bcm_l2_phys_addr(BCM_VC_EMI_SEC3_START_ADDR-1));
l2c210_flush_range(bcm_l2_phys_addr(BCM_VC_EMI_SEC3_START_ADDR),
new_end);
}
np = of_find_matching_node(NULL, l2x0_ids); if (!np) return -ENODEV;
if (of_address_to_resource(np, 0, &res)) return -ENODEV;
l2x0_base = ioremap(res.start, resource_size(&res)); if (!l2x0_base) return -ENOMEM;
l2x0_saved_regs.phy_base = res.start;
data = of_match_node(l2x0_ids, np)->data;
if (of_device_is_compatible(np, "arm,pl310-cache") &&
of_property_read_bool(np, "arm,io-coherent"))
data = &of_l2c310_coherent_data;
old_aux = readl_relaxed(l2x0_base + L2X0_AUX_CTRL); if (old_aux != ((old_aux & aux_mask) | aux_val)) {
pr_warn("L2C: platform modifies aux control register: 0x%08x -> 0x%08x\n",
old_aux, (old_aux & aux_mask) | aux_val);
} elseif (aux_mask != ~0U && aux_val != 0) {
pr_alert("L2C: platform provided aux values match the hardware, so have no effect. Please remove them.\n");
}
/* All L2 caches are unified, so this property should be specified */ if (!of_property_read_bool(np, "cache-unified"))
pr_err("L2C: device tree omits to specify unified cache\n");
if (of_property_read_u32(np, "cache-level", &cache_level))
pr_err("L2C: device tree omits to specify cache-level\n");
if (cache_level != 2)
pr_err("L2C: device tree specifies invalid cache level\n");
/* Read back current (default) hardware configuration */ if (data->save)
data->save(l2x0_base);
/* L2 configuration can only be changed if the cache is disabled */ if (!(readl_relaxed(l2x0_base + L2X0_CTRL) & L2X0_CTRL_EN)) if (data->of_parse)
data->of_parse(np, &aux_val, &aux_mask);
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.