|
0
|
1 #ifndef CYGONCE_HAL_CACHE_H |
|
|
2 #define CYGONCE_HAL_CACHE_H |
|
|
3 |
|
|
4 //============================================================================= |
|
|
5 // |
|
|
6 // hal_cache.h |
|
|
7 // |
|
|
8 // HAL cache control API |
|
|
9 // |
|
|
10 //============================================================================= |
|
|
11 //####COPYRIGHTBEGIN#### |
|
|
12 // |
|
|
13 // ------------------------------------------- |
|
|
14 // The contents of this file are subject to the Cygnus eCos Public License |
|
|
15 // Version 1.0 (the "License"); you may not use this file except in |
|
|
16 // compliance with the License. You may obtain a copy of the License at |
|
|
17 // http://sourceware.cygnus.com/ecos |
|
|
18 // |
|
|
19 // Software distributed under the License is distributed on an "AS IS" |
|
|
20 // basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the |
|
|
21 // License for the specific language governing rights and limitations under |
|
|
22 // the License. |
|
|
23 // |
|
|
24 // The Original Code is eCos - Embedded Cygnus Operating System, released |
|
|
25 // September 30, 1998. |
|
|
26 // |
|
|
27 // The Initial Developer of the Original Code is Cygnus. Portions created |
|
|
28 // by Cygnus are Copyright (C) 1998 Cygnus Solutions. All Rights Reserved. |
|
|
29 // ------------------------------------------- |
|
|
30 // |
|
|
31 //####COPYRIGHTEND#### |
|
|
32 //============================================================================= |
|
|
33 //#####DESCRIPTIONBEGIN#### |
|
|
34 // |
|
|
35 // Author(s): nickg |
|
|
36 // Contributors: nickg |
|
|
37 // Date: 1998-02-17 |
|
|
38 // Purpose: Cache control API |
|
|
39 // Description: The macros defined here provide the HAL APIs for handling |
|
|
40 // cache control operations. |
|
|
41 // Usage: |
|
|
42 // #include <cyg/hal/hal_cache.h> |
|
|
43 // ... |
|
|
44 // |
|
|
45 // |
|
|
46 //####DESCRIPTIONEND#### |
|
|
47 // |
|
|
48 //============================================================================= |
|
|
49 |
|
|
50 #include <cyg/infra/cyg_type.h> |
|
|
51 |
|
|
52 //============================================================================= |
|
|
53 // MN10300 Simulator |
|
|
54 |
|
|
55 #if defined(CYG_HAL_MN10300_SIM) |
|
|
56 |
|
|
57 //----------------------------------------------------------------------------- |
|
|
58 // Cache dimensions |
|
|
59 |
|
|
60 // Data cache |
|
|
61 #define HAL_DCACHE_SIZE 4096 // Size of data cache in bytes |
|
|
62 #define HAL_DCACHE_LINE_SIZE 16 // Size of a data cache line |
|
|
63 #define HAL_DCACHE_WAYS 2 // Associativity of the cache |
|
|
64 |
|
|
65 // Instruction cache |
|
|
66 #define HAL_ICACHE_SIZE 4096 // Size of cache in bytes |
|
|
67 #define HAL_ICACHE_LINE_SIZE 16 // Size of a cache line |
|
|
68 #define HAL_ICACHE_WAYS 2 // Associativity of the cache |
|
|
69 |
|
|
70 #define HAL_DCACHE_SETS (HAL_DCACHE_SIZE/(HAL_DCACHE_LINE_SIZE*HAL_DCACHE_WAYS)) |
|
|
71 #define HAL_ICACHE_SETS (HAL_ICACHE_SIZE/(HAL_ICACHE_LINE_SIZE*HAL_ICACHE_WAYS)) |
|
|
72 |
|
|
73 //----------------------------------------------------------------------------- |
|
|
74 // Global control of data cache |
|
|
75 |
|
|
76 // Enable the data cache |
|
|
77 #define HAL_DCACHE_ENABLE() |
|
|
78 |
|
|
79 // Disable the data cache |
|
|
80 #define HAL_DCACHE_DISABLE() |
|
|
81 |
|
|
82 // Invalidate the entire cache |
|
|
83 #define HAL_DCACHE_INVALIDATE_ALL() |
|
|
84 |
|
|
85 // Synchronize the contents of the cache with memory. |
|
|
86 #define HAL_DCACHE_SYNC() |
|
|
87 |
|
|
88 // Set the data cache refill burst size |
|
|
89 //#define HAL_DCACHE_BURST_SIZE(_size_) |
|
|
90 |
|
|
91 // Set the data cache write mode |
|
|
92 //#define HAL_DCACHE_WRITE_MODE( _mode_ ) |
|
|
93 |
|
|
94 // Load the contents of the given address range into the data cache |
|
|
95 // and then lock the cache so that it stays there. |
|
|
96 //#define HAL_DCACHE_LOCK(_base_, _size_) |
|
|
97 |
|
|
98 // Undo a previous lock operation |
|
|
99 //#define HAL_DCACHE_UNLOCK(_base_, _size_) |
|
|
100 |
|
|
101 //----------------------------------------------------------------------------- |
|
|
102 // Data cache line control |
|
|
103 |
|
|
104 // Allocate cache lines for the given address range without reading its |
|
|
105 // contents from memory. |
|
|
106 //#define HAL_DCACHE_ALLOCATE( _base_ , _size_ ) |
|
|
107 |
|
|
108 // Write dirty cache lines to memory and invalidate the cache entries |
|
|
109 // for the given address range. |
|
|
110 //#define HAL_DCACHE_FLUSH( _base_ , _size_ ) |
|
|
111 |
|
|
112 // Invalidate cache lines in the given range without writing to memory. |
|
|
113 //#define HAL_DCACHE_INVALIDATE( _base_ , _size_ ) |
|
|
114 |
|
|
115 // Write dirty cache lines to memory for the given address range. |
|
|
116 //#define HAL_DCACHE_STORE( _base_ , _size_ ) |
|
|
117 |
|
|
118 // Preread the given range into the cache with the intention of reading |
|
|
119 // from it later. |
|
|
120 //#define HAL_DCACHE_READ_HINT( _base_ , _size_ ) |
|
|
121 |
|
|
122 // Preread the given range into the cache with the intention of writing |
|
|
123 // to it later. |
|
|
124 //#define HAL_DCACHE_WRITE_HINT( _base_ , _size_ ) |
|
|
125 |
|
|
126 // Allocate and zero the cache lines associated with the given range. |
|
|
127 //#define HAL_DCACHE_ZERO( _base_ , _size_ ) |
|
|
128 |
|
|
129 //----------------------------------------------------------------------------- |
|
|
130 // Global control of Instruction cache |
|
|
131 |
|
|
132 // Enable the instruction cache |
|
|
133 #define HAL_ICACHE_ENABLE() |
|
|
134 |
|
|
135 // Disable the instruction cache |
|
|
136 #define HAL_ICACHE_DISABLE() |
|
|
137 |
|
|
138 // Invalidate the entire cache |
|
|
139 #define HAL_ICACHE_INVALIDATE_ALL() |
|
|
140 |
|
|
141 // Synchronize the contents of the cache with memory. |
|
|
142 #define HAL_ICACHE_SYNC() |
|
|
143 |
|
|
144 // Set the instruction cache refill burst size |
|
|
145 //#define HAL_ICACHE_BURST_SIZE(_size_) |
|
|
146 |
|
|
147 // Load the contents of the given address range into the instruction cache |
|
|
148 // and then lock the cache so that it stays there. |
|
|
149 //#define HAL_ICACHE_LOCK(_base_, _size_) |
|
|
150 |
|
|
151 // Undo a previous lock operation |
|
|
152 //#define HAL_ICACHE_UNLOCK(_base_, _size_) |
|
|
153 |
|
|
154 //----------------------------------------------------------------------------- |
|
|
155 // Instruction cache line control |
|
|
156 |
|
|
157 // Invalidate cache lines in the given range without writing to memory. |
|
|
158 //#define HAL_ICACHE_INVALIDATE( _base_ , _size_ ) |
|
|
159 |
|
|
160 #endif |
|
|
161 |
|
|
162 |
|
|
163 //============================================================================= |
|
|
164 // MN103002 implementation |
|
|
165 |
|
|
166 #if !defined(CYG_HAL_MN10300_SIM) && defined(CYG_HAL_MN10300_MN103002) |
|
|
167 |
|
|
168 //----------------------------------------------------------------------------- |
|
|
169 // Cache dimensions |
|
|
170 |
|
|
171 |
|
|
172 // Data cache |
|
|
173 #define HAL_DCACHE_SIZE 4096 // Size of data cache in bytes |
|
|
174 #define HAL_DCACHE_LINE_SIZE 16 // Size of a data cache line |
|
|
175 #define HAL_DCACHE_WAYS 2 // Associativity of the cache |
|
|
176 |
|
|
177 // Instruction cache |
|
|
178 #define HAL_ICACHE_SIZE 4096 // Size of cache in bytes |
|
|
179 #define HAL_ICACHE_LINE_SIZE 16 // Size of a cache line |
|
|
180 #define HAL_ICACHE_WAYS 2 // Associativity of the cache |
|
|
181 |
|
|
182 #define HAL_DCACHE_SETS (HAL_DCACHE_SIZE/(HAL_DCACHE_LINE_SIZE*HAL_DCACHE_WAYS)) |
|
|
183 #define HAL_ICACHE_SETS (HAL_ICACHE_SIZE/(HAL_ICACHE_LINE_SIZE*HAL_ICACHE_WAYS)) |
|
|
184 |
|
|
185 //----------------------------------------------------------------------------- |
|
|
186 // Control registers |
|
|
187 |
|
|
188 #define HAL_CHCTR ((CYG_ADDRWORD *)0x20000070) |
|
|
189 |
|
|
190 #define HAL_CHCTR_ICEN 0x0001 |
|
|
191 #define HAL_CHCTR_DCEN 0x0002 |
|
|
192 #define HAL_CHCTR_ICBUSY 0x0004 |
|
|
193 #define HAL_CHCTR_DCBUSY 0x0008 |
|
|
194 #define HAL_CHCTR_ICINV 0x0010 |
|
|
195 #define HAL_CHCTR_DCINV 0x0020 |
|
|
196 #define HAL_CHCTR_DCWTMD 0x0040 |
|
|
197 #define HAL_CHCTR_ICWMD 0x0300 |
|
|
198 #define HAL_CHCTR_DCWMD 0x3000 |
|
|
199 |
|
|
200 #define HAL_DCACHE_PURGE_WAY0 ((CYG_ADDRWORD *)0x28400000) |
|
|
201 #define HAL_DCACHE_PURGE_WAY1 ((CYG_ADDRWORD *)0x28401000) |
|
|
202 |
|
|
203 //----------------------------------------------------------------------------- |
|
|
204 // Global control of data cache |
|
|
205 |
|
|
206 // Enable the data cache |
|
|
207 #define HAL_DCACHE_ENABLE() \ |
|
|
208 { \ |
|
|
209 CYG_ADDRWORD chctr = *HAL_CHCTR; \ |
|
|
210 chctr |= HAL_CHCTR_DCEN; \ |
|
|
211 *HAL_CHCTR = chctr; \ |
|
|
212 } |
|
|
213 |
|
|
214 // Disable the data cache |
|
|
215 #define HAL_DCACHE_DISABLE() \ |
|
|
216 { \ |
|
|
217 CYG_ADDRWORD chctr = *HAL_CHCTR; \ |
|
|
218 chctr &= ~HAL_CHCTR_DCEN; \ |
|
|
219 *HAL_CHCTR = chctr; \ |
|
|
220 } |
|
|
221 |
|
|
222 // Invalidate the entire cache |
|
|
223 #define HAL_DCACHE_INVALIDATE_ALL() \ |
|
|
224 { \ |
|
|
225 CYG_ADDRWORD chctr, chctr1; \ |
|
|
226 chctr1 = *HAL_CHCTR; \ |
|
|
227 HAL_DCACHE_DISABLE(); \ |
|
|
228 while( *HAL_CHCTR & HAL_CHCTR_DCBUSY ); \ |
|
|
229 chctr = *HAL_CHCTR; \ |
|
|
230 chctr |= HAL_CHCTR_DCINV; \ |
|
|
231 *HAL_CHCTR = chctr; \ |
|
|
232 while( *HAL_CHCTR & HAL_CHCTR_DCBUSY ); \ |
|
|
233 *HAL_CHCTR = chctr1; \ |
|
|
234 } |
|
|
235 |
|
|
236 // Synchronize the contents of the cache with memory. |
|
|
237 #define HAL_DCACHE_SYNC() |
|
|
238 |
|
|
239 // Set the data cache refill burst size |
|
|
240 //#define HAL_DCACHE_BURST_SIZE(_size_) |
|
|
241 |
|
|
242 // Set the data cache write mode |
|
|
243 #define HAL_DCACHE_WRITE_MODE( _mode_ ) \ |
|
|
244 { \ |
|
|
245 CYG_ADDRWORD chctr; \ |
|
|
246 chctr = *HAL_CHCTR; \ |
|
|
247 HAL_DCACHE_DISABLE(); \ |
|
|
248 while( *HAL_CHCTR & HAL_CHCTR_DCBUSY ); \ |
|
|
249 chctr |= HAL_CHCTR_DCWTMD*(_mode_); \ |
|
|
250 *HAL_CHCTR = chctr; \ |
|
|
251 } |
|
|
252 |
|
|
253 #define HAL_DCACHE_WRITEBACK_MODE 0 |
|
|
254 #define HAL_DCACHE_WRITETHRU_MODE 1 |
|
|
255 |
|
|
256 // Load the contents of the given address range into the data cache |
|
|
257 // and then lock the cache so that it stays there. |
|
|
258 //#define HAL_DCACHE_LOCK(_base_, _size_) |
|
|
259 |
|
|
260 // Undo a previous lock operation |
|
|
261 //#define HAL_DCACHE_UNLOCK(_base_, _size_) |
|
|
262 |
|
|
263 //----------------------------------------------------------------------------- |
|
|
264 // Data cache line control |
|
|
265 |
|
|
266 // Allocate cache lines for the given address range without reading its |
|
|
267 // contents from memory. |
|
|
268 //#define HAL_DCACHE_ALLOCATE( _base_ , _size_ ) |
|
|
269 |
|
|
270 // Write dirty cache lines to memory and invalidate the cache entries |
|
|
271 // for the given address range. |
|
|
272 //#define HAL_DCACHE_FLUSH( _base_ , _size_ ) |
|
|
273 |
|
|
274 // Invalidate cache lines in the given range without writing to memory. |
|
|
275 //#define HAL_DCACHE_INVALIDATE( _base_ , _size_ ) |
|
|
276 |
|
|
277 // Write dirty cache lines to memory for the given address range. |
|
|
278 #define HAL_DCACHE_STORE( _base_ , _size_ ) \ |
|
|
279 { \ |
|
|
280 volatile CYG_ADDRWORD *way0 = HAL_DCACHE_PURGE_WAY0; \ |
|
|
281 volatile CYG_ADDRWORD *way1 = HAL_DCACHE_PURGE_WAY1; \ |
|
|
282 int i; \ |
|
|
283 CYG_ADDRWORD chctr; \ |
|
|
284 chctr = *HAL_CHCTR; \ |
|
|
285 HAL_DCACHE_DISABLE(); \ |
|
|
286 while( *HAL_CHCTR & HAL_CHCTR_DCBUSY ); \ |
|
|
287 \ |
|
|
288 way0 += ((CYG_ADDRWORD)_base_) & 0x000007f0; \ |
|
|
289 way1 += ((CYG_ADDRWORD)_base_) & 0x000007f0; \ |
|
|
290 for( i = 0; i < _size_ ; i += HAL_DCACHE_LINE_SIZE ) \ |
|
|
291 { \ |
|
|
292 *way0 = 0; \ |
|
|
293 *way1 = 0; \ |
|
|
294 way0 += HAL_DCACHE_LINE_SIZE; \ |
|
|
295 way1 += HAL_DCACHE_LINE_SIZE; \ |
|
|
296 } \ |
|
|
297 *HAL_CHCTR = chctr; \ |
|
|
298 } |
|
|
299 |
|
|
300 // Preread the given range into the cache with the intention of reading |
|
|
301 // from it later. |
|
|
302 //#define HAL_DCACHE_READ_HINT( _base_ , _size_ ) |
|
|
303 |
|
|
304 // Preread the given range into the cache with the intention of writing |
|
|
305 // to it later. |
|
|
306 //#define HAL_DCACHE_WRITE_HINT( _base_ , _size_ ) |
|
|
307 |
|
|
308 // Allocate and zero the cache lines associated with the given range. |
|
|
309 //#define HAL_DCACHE_ZERO( _base_ , _size_ ) |
|
|
310 |
|
|
311 //----------------------------------------------------------------------------- |
|
|
312 // Global control of Instruction cache |
|
|
313 |
|
|
314 // Enable the instruction cache |
|
|
315 #define HAL_ICACHE_ENABLE() \ |
|
|
316 { \ |
|
|
317 CYG_ADDRWORD chctr = *HAL_CHCTR; \ |
|
|
318 chctr |= HAL_CHCTR_ICEN; \ |
|
|
319 *HAL_CHCTR = chctr; \ |
|
|
320 } |
|
|
321 |
|
|
322 // Disable the instruction cache |
|
|
323 #define HAL_ICACHE_DISABLE() \ |
|
|
324 { \ |
|
|
325 CYG_ADDRWORD chctr = *HAL_CHCTR; \ |
|
|
326 chctr &= ~HAL_CHCTR_ICEN; \ |
|
|
327 *HAL_CHCTR = chctr; \ |
|
|
328 } |
|
|
329 |
|
|
330 // Invalidate the entire cache |
|
|
331 #define HAL_ICACHE_INVALIDATE_ALL() \ |
|
|
332 { \ |
|
|
333 CYG_ADDRWORD chctr, chctr1; \ |
|
|
334 chctr1 = *HAL_CHCTR; \ |
|
|
335 HAL_ICACHE_DISABLE(); \ |
|
|
336 while( *HAL_CHCTR & HAL_CHCTR_ICBUSY ); \ |
|
|
337 chctr = *HAL_CHCTR; \ |
|
|
338 chctr |= HAL_CHCTR_ICINV; \ |
|
|
339 *HAL_CHCTR = chctr; \ |
|
|
340 while( *HAL_CHCTR & HAL_CHCTR_ICBUSY ); \ |
|
|
341 *HAL_CHCTR = chctr1; \ |
|
|
342 } |
|
|
343 |
|
|
344 // Synchronize the contents of the cache with memory. |
|
|
345 #define HAL_ICACHE_SYNC() |
|
|
346 |
|
|
347 // Set the instruction cache refill burst size |
|
|
348 //#define HAL_ICACHE_BURST_SIZE(_size_) |
|
|
349 |
|
|
350 // Load the contents of the given address range into the instruction cache |
|
|
351 // and then lock the cache so that it stays there. |
|
|
352 //#define HAL_ICACHE_LOCK(_base_, _size_) |
|
|
353 |
|
|
354 // Undo a previous lock operation |
|
|
355 //#define HAL_ICACHE_UNLOCK(_base_, _size_) |
|
|
356 |
|
|
357 //----------------------------------------------------------------------------- |
|
|
358 // Instruction cache line control |
|
|
359 |
|
|
360 // Invalidate cache lines in the given range without writing to memory. |
|
|
361 //#define HAL_ICACHE_INVALIDATE( _base_ , _size_ ) |
|
|
362 |
|
|
363 #endif |
|
|
364 |
|
|
365 |
|
|
366 //----------------------------------------------------------------------------- |
|
|
367 #endif // ifndef CYGONCE_HAL_CACHE_H |
|
|
368 // End of hal_cache.h |