1 // SPDX-License-Identifier: GPL-2.0+
4 * Texas Instruments, <www.ti.com>
5 * Aneesh V <aneesh@ti.com>
7 #include <linux/types.h>
10 #include <asm/pl310.h>
14 struct pl310_regs *const pl310 = (struct pl310_regs *)CONFIG_SYS_PL310_BASE;
16 static void pl310_cache_sync(void)
18 writel(0, &pl310->pl310_cache_sync);
21 static void pl310_background_op_all_ways(u32 *op_reg)
23 u32 assoc_16, associativity, way_mask;
25 assoc_16 = readl(&pl310->pl310_aux_ctrl) &
26 PL310_AUX_CTRL_ASSOCIATIVITY_MASK;
32 way_mask = (1 << associativity) - 1;
33 /* Invalidate all ways */
34 writel(way_mask, op_reg);
35 /* Wait for all ways to be invalidated */
36 while (readl(op_reg) & way_mask)
41 void v7_outer_cache_inval_all(void)
43 pl310_background_op_all_ways(&pl310->pl310_inv_way);
46 void v7_outer_cache_flush_all(void)
48 pl310_background_op_all_ways(&pl310->pl310_clean_inv_way);
51 /* Flush(clean invalidate) memory from start to stop-1 */
52 void v7_outer_cache_flush_range(u32 start, u32 stop)
54 /* PL310 currently supports only 32 bytes cache line */
55 u32 pa, line_size = 32;
58 * Align to the beginning of cache-line - this ensures that
59 * the first 5 bits are 0 as required by PL310 TRM
61 start &= ~(line_size - 1);
63 for (pa = start; pa < stop; pa = pa + line_size)
64 writel(pa, &pl310->pl310_clean_inv_line_pa);
69 /* invalidate memory from start to stop-1 */
70 void v7_outer_cache_inval_range(u32 start, u32 stop)
72 /* PL310 currently supports only 32 bytes cache line */
73 u32 pa, line_size = 32;
76 * If start address is not aligned to cache-line do not
77 * invalidate the first cache-line
79 if (start & (line_size - 1)) {
80 printf("ERROR: %s - start address is not aligned - 0x%08x\n",
82 /* move to next cache line */
83 start = (start + line_size - 1) & ~(line_size - 1);
87 * If stop address is not aligned to cache-line do not
88 * invalidate the last cache-line
90 if (stop & (line_size - 1)) {
91 printf("ERROR: %s - stop address is not aligned - 0x%08x\n",
93 /* align to the beginning of this cache line */
94 stop &= ~(line_size - 1);
97 for (pa = start; pa < stop; pa = pa + line_size)
98 writel(pa, &pl310->pl310_inv_line_pa);