1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
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
33static void pl310_cache_sync(void)
34{
35 writel(0, &pl310->pl310_cache_sync);
36}
37
38static void pl310_background_op_all_ways(u32 *op_reg)
39{
40 u32 assoc_16, associativity, way_mask;
41
42 assoc_16 = readl(&pl310->pl310_aux_ctrl) &
43 PL310_AUX_CTRL_ASSOCIATIVITY_MASK;
44 if (assoc_16)
45 associativity = 16;
46 else
47 associativity = 8;
48
49 way_mask = (1 << associativity) - 1;
50
51 writel(way_mask, op_reg);
52
53 while (readl(op_reg) && way_mask)
54 ;
55 pl310_cache_sync();
56}
57
58void v7_outer_cache_inval_all(void)
59{
60 pl310_background_op_all_ways(&pl310->pl310_inv_way);
61}
62
63void v7_outer_cache_flush_all(void)
64{
65 pl310_background_op_all_ways(&pl310->pl310_clean_inv_way);
66}
67
68
69void v7_outer_cache_flush_range(u32 start, u32 stop)
70{
71
72 u32 pa, line_size = 32;
73
74
75
76
77
78 start &= ~(line_size - 1);
79
80 for (pa = start; pa < stop; pa = pa + line_size)
81 writel(pa, &pl310->pl310_clean_inv_line_pa);
82
83 pl310_cache_sync();
84}
85
86
87void v7_outer_cache_inval_range(u32 start, u32 stop)
88{
89
90 u32 pa, line_size = 32;
91
92
93
94
95
96 if (start & (line_size - 1)) {
97 printf("ERROR: %s - start address is not aligned - 0x%08x\n",
98 __func__, start);
99
100 start = (start + line_size - 1) & ~(line_size - 1);
101 }
102
103
104
105
106
107 if (stop & (line_size - 1)) {
108 printf("ERROR: %s - stop address is not aligned - 0x%08x\n",
109 __func__, stop);
110
111 stop &= ~(line_size - 1);
112 }
113
114 for (pa = start; pa < stop; pa = pa + line_size)
115 writel(pa, &pl310->pl310_inv_line_pa);
116
117 pl310_cache_sync();
118}
119