1 | /* |
---|
2 | * Copyright (c) 2014 embedded brains GmbH. All rights reserved. |
---|
3 | * |
---|
4 | * The license and distribution terms for this file may be |
---|
5 | * found in the file LICENSE in this distribution or at |
---|
6 | * http://www.rtems.org/license/LICENSE. |
---|
7 | */ |
---|
8 | |
---|
9 | #include <amba.h> |
---|
10 | #include <leon.h> |
---|
11 | |
---|
12 | #define CPU_CACHE_SUPPORT_PROVIDES_RANGE_FUNCTIONS |
---|
13 | |
---|
14 | #define CPU_CACHE_SUPPORT_PROVIDES_CACHE_SIZE_FUNCTIONS |
---|
15 | |
---|
16 | #define CPU_CACHE_NO_INSTRUCTION_CACHE_SNOOPING |
---|
17 | |
---|
18 | #define CPU_INSTRUCTION_CACHE_ALIGNMENT 64 |
---|
19 | |
---|
20 | #define CPU_DATA_CACHE_ALIGNMENT 64 |
---|
21 | |
---|
22 | static inline volatile struct l2c_regs *get_l2c_regs(void) |
---|
23 | { |
---|
24 | volatile struct l2c_regs *l2c = NULL; |
---|
25 | struct ambapp_dev *adev; |
---|
26 | |
---|
27 | adev = (void *) ambapp_for_each( |
---|
28 | ambapp_plb(), |
---|
29 | OPTIONS_ALL | OPTIONS_AHB_SLVS, |
---|
30 | VENDOR_GAISLER, |
---|
31 | GAISLER_L2CACHE, |
---|
32 | ambapp_find_by_idx, |
---|
33 | NULL |
---|
34 | ); |
---|
35 | if (adev != NULL) { |
---|
36 | l2c = (volatile struct l2c_regs *) DEV_TO_AHB(adev)->start[1]; |
---|
37 | } |
---|
38 | |
---|
39 | return l2c; |
---|
40 | } |
---|
41 | |
---|
42 | static inline size_t get_l2_size(void) |
---|
43 | { |
---|
44 | size_t size = 0; |
---|
45 | volatile struct l2c_regs *l2c = get_l2c_regs(); |
---|
46 | |
---|
47 | if (l2c != NULL) { |
---|
48 | unsigned status = l2c->status; |
---|
49 | unsigned ways = (status & 0x3) + 1; |
---|
50 | unsigned set_size = ((status & 0x7ff) >> 2) * 1024; |
---|
51 | |
---|
52 | size = ways * set_size; |
---|
53 | } |
---|
54 | |
---|
55 | return size; |
---|
56 | } |
---|
57 | |
---|
58 | static inline size_t get_l1_size(uint32_t l1_cfg) |
---|
59 | { |
---|
60 | uint32_t ways = ((l1_cfg >> 24) & 0x7) + 1; |
---|
61 | uint32_t wsize = UINT32_C(1) << (((l1_cfg >> 20) & 0xf) + 10); |
---|
62 | |
---|
63 | return ways * wsize; |
---|
64 | } |
---|
65 | |
---|
66 | static inline size_t get_max_size(size_t a, size_t b) |
---|
67 | { |
---|
68 | return a < b ? b : a; |
---|
69 | } |
---|
70 | |
---|
71 | static inline size_t get_cache_size(uint32_t level, uint32_t l1_cfg) |
---|
72 | { |
---|
73 | size_t size; |
---|
74 | |
---|
75 | switch (level) { |
---|
76 | case 0: |
---|
77 | size = get_max_size(get_l1_size(l1_cfg), get_l2_size()); |
---|
78 | break; |
---|
79 | case 1: |
---|
80 | size = get_l1_size(l1_cfg); |
---|
81 | break; |
---|
82 | case 2: |
---|
83 | size = get_l2_size(); |
---|
84 | break; |
---|
85 | default: |
---|
86 | size = 0; |
---|
87 | break; |
---|
88 | } |
---|
89 | |
---|
90 | return size; |
---|
91 | } |
---|
92 | |
---|
93 | static inline size_t _CPU_cache_get_data_cache_size(uint32_t level) |
---|
94 | { |
---|
95 | return get_cache_size(level, leon3_get_data_cache_config_register()); |
---|
96 | } |
---|
97 | |
---|
98 | static inline void _CPU_cache_flush_data_range( |
---|
99 | const void *d_addr, |
---|
100 | size_t n_bytes |
---|
101 | ) |
---|
102 | { |
---|
103 | /* TODO */ |
---|
104 | } |
---|
105 | |
---|
106 | static inline void _CPU_cache_invalidate_data_range( |
---|
107 | const void *d_addr, |
---|
108 | size_t n_bytes |
---|
109 | ) |
---|
110 | { |
---|
111 | /* TODO */ |
---|
112 | } |
---|
113 | |
---|
114 | static inline void _CPU_cache_freeze_data(void) |
---|
115 | { |
---|
116 | /* TODO */ |
---|
117 | } |
---|
118 | |
---|
119 | static inline void _CPU_cache_unfreeze_data(void) |
---|
120 | { |
---|
121 | /* TODO */ |
---|
122 | } |
---|
123 | |
---|
124 | static inline void _CPU_cache_invalidate_entire_instruction(void) |
---|
125 | { |
---|
126 | uint32_t cache_reg = leon3_get_cache_control_register(); |
---|
127 | |
---|
128 | cache_reg |= LEON3_REG_CACHE_CTRL_FI; |
---|
129 | leon3_set_cache_control_register(cache_reg); |
---|
130 | } |
---|
131 | |
---|
132 | static inline void _CPU_cache_invalidate_instruction_range( |
---|
133 | const void *i_addr, |
---|
134 | size_t n_bytes |
---|
135 | ) |
---|
136 | { |
---|
137 | _CPU_cache_invalidate_entire_instruction(); |
---|
138 | } |
---|
139 | |
---|
140 | static inline void _CPU_cache_freeze_instruction(void) |
---|
141 | { |
---|
142 | /* TODO */ |
---|
143 | } |
---|
144 | |
---|
145 | static inline void _CPU_cache_unfreeze_instruction(void) |
---|
146 | { |
---|
147 | /* TODO */ |
---|
148 | } |
---|
149 | |
---|
150 | static inline void _CPU_cache_flush_entire_data(void) |
---|
151 | { |
---|
152 | /* TODO */ |
---|
153 | } |
---|
154 | |
---|
155 | static inline void _CPU_cache_invalidate_entire_data(void) |
---|
156 | { |
---|
157 | /* TODO */ |
---|
158 | } |
---|
159 | |
---|
160 | static inline void _CPU_cache_enable_data(void) |
---|
161 | { |
---|
162 | /* TODO */ |
---|
163 | } |
---|
164 | |
---|
165 | static inline void _CPU_cache_disable_data(void) |
---|
166 | { |
---|
167 | /* TODO */ |
---|
168 | } |
---|
169 | |
---|
170 | static inline size_t _CPU_cache_get_instruction_cache_size( uint32_t level ) |
---|
171 | { |
---|
172 | return get_cache_size(level, leon3_get_inst_cache_config_register()); |
---|
173 | } |
---|
174 | |
---|
175 | static inline void _CPU_cache_enable_instruction(void) |
---|
176 | { |
---|
177 | /* TODO */ |
---|
178 | } |
---|
179 | |
---|
180 | static inline void _CPU_cache_disable_instruction(void) |
---|
181 | { |
---|
182 | /* TODO */ |
---|
183 | } |
---|
184 | |
---|
185 | #include "../../../shared/cache/cacheimpl.h" |
---|