193bc2193SAneesh V /*
293bc2193SAneesh V * (C) Copyright 2010
393bc2193SAneesh V * Texas Instruments, <www.ti.com>
493bc2193SAneesh V * Aneesh V <aneesh@ti.com>
593bc2193SAneesh V *
6*1a459660SWolfgang Denk * SPDX-License-Identifier: GPL-2.0+
793bc2193SAneesh V */
893bc2193SAneesh V #include <linux/types.h>
993bc2193SAneesh V #include <asm/io.h>
1093bc2193SAneesh V #include <asm/armv7.h>
1193bc2193SAneesh V #include <asm/pl310.h>
1293bc2193SAneesh V #include <config.h>
13cabe2878SAneesh V #include <common.h>
1493bc2193SAneesh V
1593bc2193SAneesh V struct pl310_regs *const pl310 = (struct pl310_regs *)CONFIG_SYS_PL310_BASE;
1693bc2193SAneesh V
pl310_cache_sync(void)1793bc2193SAneesh V static void pl310_cache_sync(void)
1893bc2193SAneesh V {
1993bc2193SAneesh V writel(0, &pl310->pl310_cache_sync);
2093bc2193SAneesh V }
2193bc2193SAneesh V
pl310_background_op_all_ways(u32 * op_reg)2293bc2193SAneesh V static void pl310_background_op_all_ways(u32 *op_reg)
2393bc2193SAneesh V {
2493bc2193SAneesh V u32 assoc_16, associativity, way_mask;
2593bc2193SAneesh V
2693bc2193SAneesh V assoc_16 = readl(&pl310->pl310_aux_ctrl) &
2793bc2193SAneesh V PL310_AUX_CTRL_ASSOCIATIVITY_MASK;
2893bc2193SAneesh V if (assoc_16)
2993bc2193SAneesh V associativity = 16;
3093bc2193SAneesh V else
3193bc2193SAneesh V associativity = 8;
3293bc2193SAneesh V
3393bc2193SAneesh V way_mask = (1 << associativity) - 1;
3493bc2193SAneesh V /* Invalidate all ways */
3593bc2193SAneesh V writel(way_mask, op_reg);
3693bc2193SAneesh V /* Wait for all ways to be invalidated */
3793bc2193SAneesh V while (readl(op_reg) && way_mask)
3893bc2193SAneesh V ;
3993bc2193SAneesh V pl310_cache_sync();
4093bc2193SAneesh V }
4193bc2193SAneesh V
v7_outer_cache_inval_all(void)4293bc2193SAneesh V void v7_outer_cache_inval_all(void)
4393bc2193SAneesh V {
4493bc2193SAneesh V pl310_background_op_all_ways(&pl310->pl310_inv_way);
4593bc2193SAneesh V }
4693bc2193SAneesh V
v7_outer_cache_flush_all(void)4793bc2193SAneesh V void v7_outer_cache_flush_all(void)
4893bc2193SAneesh V {
4993bc2193SAneesh V pl310_background_op_all_ways(&pl310->pl310_clean_inv_way);
5093bc2193SAneesh V }
5193bc2193SAneesh V
5293bc2193SAneesh V /* Flush(clean invalidate) memory from start to stop-1 */
v7_outer_cache_flush_range(u32 start,u32 stop)5393bc2193SAneesh V void v7_outer_cache_flush_range(u32 start, u32 stop)
5493bc2193SAneesh V {
5593bc2193SAneesh V /* PL310 currently supports only 32 bytes cache line */
5693bc2193SAneesh V u32 pa, line_size = 32;
5793bc2193SAneesh V
5893bc2193SAneesh V /*
5993bc2193SAneesh V * Align to the beginning of cache-line - this ensures that
6093bc2193SAneesh V * the first 5 bits are 0 as required by PL310 TRM
6193bc2193SAneesh V */
6293bc2193SAneesh V start &= ~(line_size - 1);
6393bc2193SAneesh V
6493bc2193SAneesh V for (pa = start; pa < stop; pa = pa + line_size)
6593bc2193SAneesh V writel(pa, &pl310->pl310_clean_inv_line_pa);
6693bc2193SAneesh V
6793bc2193SAneesh V pl310_cache_sync();
6893bc2193SAneesh V }
6993bc2193SAneesh V
7093bc2193SAneesh V /* invalidate memory from start to stop-1 */
v7_outer_cache_inval_range(u32 start,u32 stop)7193bc2193SAneesh V void v7_outer_cache_inval_range(u32 start, u32 stop)
7293bc2193SAneesh V {
7393bc2193SAneesh V /* PL310 currently supports only 32 bytes cache line */
7493bc2193SAneesh V u32 pa, line_size = 32;
7593bc2193SAneesh V
7693bc2193SAneesh V /*
77cabe2878SAneesh V * If start address is not aligned to cache-line do not
78cabe2878SAneesh V * invalidate the first cache-line
7993bc2193SAneesh V */
8093bc2193SAneesh V if (start & (line_size - 1)) {
81cabe2878SAneesh V printf("ERROR: %s - start address is not aligned - 0x%08x\n",
82cabe2878SAneesh V __func__, start);
8393bc2193SAneesh V /* move to next cache line */
8493bc2193SAneesh V start = (start + line_size - 1) & ~(line_size - 1);
8593bc2193SAneesh V }
8693bc2193SAneesh V
8793bc2193SAneesh V /*
88cabe2878SAneesh V * If stop address is not aligned to cache-line do not
89cabe2878SAneesh V * invalidate the last cache-line
9093bc2193SAneesh V */
9193bc2193SAneesh V if (stop & (line_size - 1)) {
92cabe2878SAneesh V printf("ERROR: %s - stop address is not aligned - 0x%08x\n",
93cabe2878SAneesh V __func__, stop);
9493bc2193SAneesh V /* align to the beginning of this cache line */
9593bc2193SAneesh V stop &= ~(line_size - 1);
9693bc2193SAneesh V }
9793bc2193SAneesh V
9893bc2193SAneesh V for (pa = start; pa < stop; pa = pa + line_size)
9993bc2193SAneesh V writel(pa, &pl310->pl310_inv_line_pa);
10093bc2193SAneesh V
10193bc2193SAneesh V pl310_cache_sync();
10293bc2193SAneesh V }
103