blob: 8337cc3c207c1728a98a7e39221c5c7dffb70807 [file] [log] [blame]
yuezonghe824eb0c2024-06-27 02:32:26 -07001/*
2 * (C) Copyright 2010
3 * Texas Instruments, <www.ti.com>
4 * Aneesh V <aneesh@ti.com>
5 *
6 * See file CREDITS for list of people who contributed to this
7 * project.
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License as
11 * published by the Free Software Foundation; either version 2 of
12 * the License, or (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
22 * MA 02111-1307 USA
23 */
24#include <linux/types.h>
25#include <asm/io.h>
26#include <asm/armv7.h>
27#include <asm/pl310.h>
28#include <config.h>
29#include <common.h>
30
31struct pl310_regs *const pl310 = (struct pl310_regs *)CONFIG_SYS_PL310_BASE;
32
33#if 0
34static void pl310_cache_sync(void)
35{
36 writel(0, &pl310->pl310_cache_sync);
37}
38
39static void pl310_background_op_all_ways(u32 *op_reg)
40{
41 u32 assoc_16, associativity, way_mask;
42
43 assoc_16 = readl(&pl310->pl310_aux_ctrl) &
44 PL310_AUX_CTRL_ASSOCIATIVITY_MASK;
45 if (assoc_16)
46 associativity = 16;
47 else
48 associativity = 8;
49
50 way_mask = (1 << associativity) - 1;
51 /* Invalidate all ways */
52 writel(way_mask, op_reg);
53 /* Wait for all ways to be invalidated */
54 while (readl(op_reg) && way_mask)
55 ;
56 pl310_cache_sync();
57}
58
59void v7_outer_cache_inval_all(void)
60{
61 pl310_background_op_all_ways(&pl310->pl310_inv_way);
62}
63
64void v7_outer_cache_flush_all(void)
65{
66 pl310_background_op_all_ways(&pl310->pl310_clean_inv_way);
67}
68
69/* Flush(clean invalidate) memory from start to stop-1 */
70void v7_outer_cache_flush_range(u32 start, u32 stop)
71{
72 /* PL310 currently supports only 32 bytes cache line */
73 u32 pa, line_size = 32;
74
75 /*
76 * Align to the beginning of cache-line - this ensures that
77 * the first 5 bits are 0 as required by PL310 TRM
78 */
79 start &= ~(line_size - 1);
80
81 for (pa = start; pa < stop; pa = pa + line_size)
82 writel(pa, &pl310->pl310_clean_inv_line_pa);
83
84 pl310_cache_sync();
85}
86
87/* invalidate memory from start to stop-1 */
88void v7_outer_cache_inval_range(u32 start, u32 stop)
89{
90 /* PL310 currently supports only 32 bytes cache line */
91 u32 pa, line_size = 32;
92
93 /*
94 * If start address is not aligned to cache-line do not
95 * invalidate the first cache-line
96 */
97 if (start & (line_size - 1)) {
98 printf("ERROR: %s - start address is not aligned - 0x%08x\n",
99 __func__, start);
100 /* move to next cache line */
101 start = (start + line_size - 1) & ~(line_size - 1);
102 }
103
104 /*
105 * If stop address is not aligned to cache-line do not
106 * invalidate the last cache-line
107 */
108 if (stop & (line_size - 1)) {
109 printf("ERROR: %s - stop address is not aligned - 0x%08x\n",
110 __func__, stop);
111 /* align to the beginning of this cache line */
112 stop &= ~(line_size - 1);
113 }
114
115 for (pa = start; pa < stop; pa = pa + line_size)
116 writel(pa, &pl310->pl310_inv_line_pa);
117
118 pl310_cache_sync();
119}
120#else
121static void pl310_cache_sync(void)
122{
123}
124
125static void pl310_background_op_all_ways(u32 *op_reg)
126{
127}
128
129void v7_outer_cache_inval_all(void)
130{
131}
132
133void v7_outer_cache_flush_all(void)
134{
135}
136
137/* Flush(clean invalidate) memory from start to stop-1 */
138void v7_outer_cache_flush_range(u32 start, u32 stop)
139{
140}
141
142/* invalidate memory from start to stop-1 */
143void v7_outer_cache_inval_range(u32 start, u32 stop)
144{
145}
146#endif
147