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