blob: 0afd3880447f62a54ca577deee9f2324e4a59d0e [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Aneesh V686a0752011-06-16 23:30:51 +00002/*
3 * (C) Copyright 2010
4 * Texas Instruments, <www.ti.com>
5 * Aneesh V <aneesh@ti.com>
Aneesh V686a0752011-06-16 23:30:51 +00006 */
7#include <linux/types.h>
8#include <asm/io.h>
9#include <asm/armv7.h>
10#include <asm/pl310.h>
11#include <config.h>
12
Tom Rini6a5dccc2022-11-16 13:10:41 -050013struct pl310_regs *const pl310 = (struct pl310_regs *)CFG_SYS_PL310_BASE;
Aneesh V686a0752011-06-16 23:30:51 +000014
15static void pl310_cache_sync(void)
16{
17 writel(0, &pl310->pl310_cache_sync);
18}
19
20static void pl310_background_op_all_ways(u32 *op_reg)
21{
22 u32 assoc_16, associativity, way_mask;
23
24 assoc_16 = readl(&pl310->pl310_aux_ctrl) &
25 PL310_AUX_CTRL_ASSOCIATIVITY_MASK;
26 if (assoc_16)
27 associativity = 16;
28 else
29 associativity = 8;
30
31 way_mask = (1 << associativity) - 1;
32 /* Invalidate all ways */
33 writel(way_mask, op_reg);
34 /* Wait for all ways to be invalidated */
Marek Vasut8791b1f2019-02-19 01:43:51 +010035 while (readl(op_reg) & way_mask)
Aneesh V686a0752011-06-16 23:30:51 +000036 ;
37 pl310_cache_sync();
38}
39
40void v7_outer_cache_inval_all(void)
41{
42 pl310_background_op_all_ways(&pl310->pl310_inv_way);
43}
44
45void v7_outer_cache_flush_all(void)
46{
47 pl310_background_op_all_ways(&pl310->pl310_clean_inv_way);
48}
49
50/* Flush(clean invalidate) memory from start to stop-1 */
51void v7_outer_cache_flush_range(u32 start, u32 stop)
52{
53 /* PL310 currently supports only 32 bytes cache line */
54 u32 pa, line_size = 32;
55
56 /*
57 * Align to the beginning of cache-line - this ensures that
58 * the first 5 bits are 0 as required by PL310 TRM
59 */
60 start &= ~(line_size - 1);
61
62 for (pa = start; pa < stop; pa = pa + line_size)
63 writel(pa, &pl310->pl310_clean_inv_line_pa);
64
65 pl310_cache_sync();
66}
67
68/* invalidate memory from start to stop-1 */
69void v7_outer_cache_inval_range(u32 start, u32 stop)
70{
71 /* PL310 currently supports only 32 bytes cache line */
72 u32 pa, line_size = 32;
73
74 /*
Aneesh V6a22a622011-08-11 04:35:45 +000075 * If start address is not aligned to cache-line do not
76 * invalidate the first cache-line
Aneesh V686a0752011-06-16 23:30:51 +000077 */
78 if (start & (line_size - 1)) {
Aneesh V6a22a622011-08-11 04:35:45 +000079 printf("ERROR: %s - start address is not aligned - 0x%08x\n",
80 __func__, start);
Aneesh V686a0752011-06-16 23:30:51 +000081 /* move to next cache line */
82 start = (start + line_size - 1) & ~(line_size - 1);
83 }
84
85 /*
Aneesh V6a22a622011-08-11 04:35:45 +000086 * If stop address is not aligned to cache-line do not
87 * invalidate the last cache-line
Aneesh V686a0752011-06-16 23:30:51 +000088 */
89 if (stop & (line_size - 1)) {
Aneesh V6a22a622011-08-11 04:35:45 +000090 printf("ERROR: %s - stop address is not aligned - 0x%08x\n",
91 __func__, stop);
Aneesh V686a0752011-06-16 23:30:51 +000092 /* align to the beginning of this cache line */
93 stop &= ~(line_size - 1);
94 }
95
96 for (pa = start; pa < stop; pa = pa + line_size)
97 writel(pa, &pl310->pl310_inv_line_pa);
98
99 pl310_cache_sync();
100}