1 |
786 |
skrzyp |
#ifndef CYGONCE_VAR_CACHE_H
|
2 |
|
|
#define CYGONCE_VAR_CACHE_H
|
3 |
|
|
//=============================================================================
|
4 |
|
|
//
|
5 |
|
|
// var_cache.h
|
6 |
|
|
//
|
7 |
|
|
// HAL cache control API
|
8 |
|
|
//
|
9 |
|
|
//=============================================================================
|
10 |
|
|
// ####ECOSGPLCOPYRIGHTBEGIN####
|
11 |
|
|
// -------------------------------------------
|
12 |
|
|
// This file is part of eCos, the Embedded Configurable Operating System.
|
13 |
|
|
// Copyright (C) 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
|
14 |
|
|
//
|
15 |
|
|
// eCos is free software; you can redistribute it and/or modify it under
|
16 |
|
|
// the terms of the GNU General Public License as published by the Free
|
17 |
|
|
// Software Foundation; either version 2 or (at your option) any later
|
18 |
|
|
// version.
|
19 |
|
|
//
|
20 |
|
|
// eCos is distributed in the hope that it will be useful, but WITHOUT
|
21 |
|
|
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
22 |
|
|
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
23 |
|
|
// for more details.
|
24 |
|
|
//
|
25 |
|
|
// You should have received a copy of the GNU General Public License
|
26 |
|
|
// along with eCos; if not, write to the Free Software Foundation, Inc.,
|
27 |
|
|
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
28 |
|
|
//
|
29 |
|
|
// As a special exception, if other files instantiate templates or use
|
30 |
|
|
// macros or inline functions from this file, or you compile this file
|
31 |
|
|
// and link it with other works to produce a work based on this file,
|
32 |
|
|
// this file does not by itself cause the resulting work to be covered by
|
33 |
|
|
// the GNU General Public License. However the source code for this file
|
34 |
|
|
// must still be made available in accordance with section (3) of the GNU
|
35 |
|
|
// General Public License v2.
|
36 |
|
|
//
|
37 |
|
|
// This exception does not invalidate any other reasons why a work based
|
38 |
|
|
// on this file might be covered by the GNU General Public License.
|
39 |
|
|
// -------------------------------------------
|
40 |
|
|
// ####ECOSGPLCOPYRIGHTEND####
|
41 |
|
|
//=============================================================================
|
42 |
|
|
//#####DESCRIPTIONBEGIN####
|
43 |
|
|
//
|
44 |
|
|
// Author(s): tmichals
|
45 |
|
|
// Contributors: nickg, dmoseley
|
46 |
|
|
// Date: 2003-02-13
|
47 |
|
|
// Purpose: Cache control API
|
48 |
|
|
// Description: The macros defined here provide the HAL APIs for handling
|
49 |
|
|
// cache control operations.
|
50 |
|
|
// Usage:
|
51 |
|
|
// #include <cyg/hal/var_cache.h>
|
52 |
|
|
// ...
|
53 |
|
|
//
|
54 |
|
|
//
|
55 |
|
|
//####DESCRIPTIONEND####
|
56 |
|
|
//
|
57 |
|
|
//=============================================================================
|
58 |
|
|
|
59 |
|
|
#include <pkgconf/hal.h>
|
60 |
|
|
#include <cyg/infra/cyg_type.h>
|
61 |
|
|
|
62 |
|
|
#include <cyg/hal/mips-regs.h>
|
63 |
|
|
#include <cyg/hal/hal_arch.h>
|
64 |
|
|
#include <cyg/hal/plf_cache.h>
|
65 |
|
|
#include <cyg/hal/var_arch.h>
|
66 |
|
|
|
67 |
|
|
|
68 |
|
|
|
69 |
|
|
//-----------------------------------------------------------------------------
|
70 |
|
|
// Cache dimensions
|
71 |
|
|
|
72 |
|
|
// Data cache
|
73 |
|
|
#define HAL_DCACHE_SIZE (1024 *8) // Size of data cache in bytes
|
74 |
|
|
#define HAL_DCACHE_LINE_SIZE 16 // Size of a data cache line
|
75 |
|
|
#define HAL_DCACHE_WAYS 4 // Associativity of the cache
|
76 |
|
|
|
77 |
|
|
// Instruction cache
|
78 |
|
|
#define HAL_ICACHE_SIZE (1024*16) // Size of cache in bytes
|
79 |
|
|
#define HAL_ICACHE_LINE_SIZE 16 // Size of a cache line
|
80 |
|
|
#define HAL_ICACHE_WAYS 4 // Associativity of the cache
|
81 |
|
|
|
82 |
|
|
#define HAL_DCACHE_SETS (HAL_DCACHE_SIZE/(HAL_DCACHE_LINE_SIZE*HAL_DCACHE_WAYS))
|
83 |
|
|
#define HAL_ICACHE_SETS (HAL_ICACHE_SIZE/(HAL_ICACHE_LINE_SIZE*HAL_ICACHE_WAYS))
|
84 |
|
|
|
85 |
|
|
#define HAL_DCACHE_WRITETHRU_MODE 1
|
86 |
|
|
#define HAL_DCACHE_WRITEBACK_MODE 0
|
87 |
|
|
|
88 |
|
|
|
89 |
|
|
//-----------------------------------------------------------------------------
|
90 |
|
|
// General cache defines.
|
91 |
|
|
#define HAL_CLEAR_TAGLO() asm volatile (" mtc0 $0, $28;" \
|
92 |
|
|
" nop;" \
|
93 |
|
|
" nop;" \
|
94 |
|
|
" nop;")
|
95 |
|
|
#define HAL_CLEAR_TAGHI() asm volatile (" mtc0 $0, $29;" \
|
96 |
|
|
" nop;" \
|
97 |
|
|
" nop;" \
|
98 |
|
|
" nop;")
|
99 |
|
|
|
100 |
|
|
/* Cache instruction opcodes */
|
101 |
|
|
#define HAL_CACHE_OP(which, op) (which | (op << 2))
|
102 |
|
|
|
103 |
|
|
#define HAL_WHICH_ICACHE 0x0
|
104 |
|
|
#define HAL_WHICH_DCACHE 0x1
|
105 |
|
|
|
106 |
|
|
#define HAL_INDEX_INVALIDATE 0x0
|
107 |
|
|
#define HAL_INDEX_LOAD_TAG 0x1
|
108 |
|
|
#define HAL_INDEX_STORE_TAG 0x2
|
109 |
|
|
#define HAL_HIT_INVALIDATE 0x4
|
110 |
|
|
#define HAL_ICACHE_FILL 0x5
|
111 |
|
|
#define HAL_DCACHE_HIT_INVALIDATE 0x5
|
112 |
|
|
#define HAL_DCACHE_HIT_WRITEBACK 0x6
|
113 |
|
|
#define HAL_FETCH_AND_LOCK 0x7
|
114 |
|
|
|
115 |
|
|
//-----------------------------------------------------------------------------
|
116 |
|
|
// Global control of data cache
|
117 |
|
|
|
118 |
|
|
// Invalidate the entire cache
|
119 |
|
|
#define HAL_DCACHE_INVALIDATE_ALL_DEFINED
|
120 |
|
|
#define HAL_DCACHE_INVALIDATE_ALL() \
|
121 |
|
|
CYG_MACRO_START \
|
122 |
|
|
register volatile CYG_BYTE *addr; \
|
123 |
|
|
HAL_CLEAR_TAGLO(); \
|
124 |
|
|
HAL_CLEAR_TAGHI(); \
|
125 |
|
|
for (addr = (CYG_BYTE *)CYGARC_KSEG_CACHED_BASE; \
|
126 |
|
|
addr < (CYG_BYTE *)(CYGARC_KSEG_CACHED_BASE + HAL_DCACHE_SIZE); \
|
127 |
|
|
addr += HAL_DCACHE_LINE_SIZE ) \
|
128 |
|
|
{ \
|
129 |
|
|
asm volatile (" cache %0, 0(%1)" \
|
130 |
|
|
: \
|
131 |
|
|
: "I" (HAL_CACHE_OP(HAL_WHICH_DCACHE, HAL_INDEX_STORE_TAG)), \
|
132 |
|
|
"r"(addr)); \
|
133 |
|
|
} \
|
134 |
|
|
CYG_MACRO_END
|
135 |
|
|
|
136 |
|
|
// Synchronize the contents of the cache with memory.
|
137 |
|
|
__externC void hal_dcache_sync(void);
|
138 |
|
|
#define HAL_DCACHE_SYNC_DEFINED
|
139 |
|
|
#define HAL_DCACHE_SYNC() hal_dcache_sync()
|
140 |
|
|
|
141 |
|
|
// Set the data cache refill burst size
|
142 |
|
|
//#define HAL_DCACHE_BURST_SIZE(_asize_)
|
143 |
|
|
|
144 |
|
|
// Set the data cache write mode
|
145 |
|
|
//#define HAL_DCACHE_WRITE_MODE( _mode_ )
|
146 |
|
|
|
147 |
|
|
// Load the contents of the given address range into the data cache
|
148 |
|
|
// and then lock the cache so that it stays there.
|
149 |
|
|
#define HAL_DCACHE_LOCK_DEFINED
|
150 |
|
|
#define HAL_DCACHE_LOCK(_base_, _asize_) \
|
151 |
|
|
CYG_MACRO_START \
|
152 |
|
|
register CYG_ADDRESS _baddr_ = (CYG_ADDRESS)(_base_); \
|
153 |
|
|
register CYG_ADDRESS _addr_ = (CYG_ADDRESS)(_base_); \
|
154 |
|
|
register CYG_WORD _size_ = (_asize_); \
|
155 |
|
|
for( ; _addr_ <= _baddr_+_size_; _addr_ += HAL_DCACHE_LINE_SIZE ) \
|
156 |
|
|
asm volatile (" cache %0, 0(%1)" \
|
157 |
|
|
: \
|
158 |
|
|
: "I" (HAL_CACHE_OP(HAL_WHICH_DCACHE, HAL_FETCH_AND_LOCK)), \
|
159 |
|
|
"r"(_addr_)); \
|
160 |
|
|
CYG_MACRO_END
|
161 |
|
|
|
162 |
|
|
// Undo a previous lock operation
|
163 |
|
|
#define HAL_DCACHE_UNLOCK_DEFINED
|
164 |
|
|
#define HAL_DCACHE_UNLOCK(_base_, _asize_) \
|
165 |
|
|
CYG_MACRO_START \
|
166 |
|
|
register CYG_ADDRESS _baddr_ = (CYG_ADDRESS)(_base_); \
|
167 |
|
|
register CYG_ADDRESS _addr_ = (CYG_ADDRESS)(_base_); \
|
168 |
|
|
register CYG_WORD _size_ = (_asize_); \
|
169 |
|
|
for( ; _addr_ <= _baddr_+_size_; _addr_ += HAL_DCACHE_LINE_SIZE ) \
|
170 |
|
|
asm volatile (" cache %0, 0(%1)" \
|
171 |
|
|
: \
|
172 |
|
|
: "I" (HAL_CACHE_OP(HAL_WHICH_DCACHE, HAL_HIT_INVALIDATE)), \
|
173 |
|
|
"r"(_addr_)); \
|
174 |
|
|
CYG_MACRO_END
|
175 |
|
|
|
176 |
|
|
// Unlock entire cache
|
177 |
|
|
#define HAL_DCACHE_UNLOCK_ALL_DEFINED
|
178 |
|
|
#define HAL_DCACHE_UNLOCK_ALL() HAL_DCACHE_UNLOCK(0,HAL_DCACHE_SIZE)
|
179 |
|
|
|
180 |
|
|
|
181 |
|
|
//-----------------------------------------------------------------------------
|
182 |
|
|
// Data cache line control
|
183 |
|
|
|
184 |
|
|
// Allocate cache lines for the given address range without reading its
|
185 |
|
|
// contents from memory.
|
186 |
|
|
//#define HAL_DCACHE_ALLOCATE( _base_ , _asize_ )
|
187 |
|
|
|
188 |
|
|
// Write dirty cache lines to memory and invalidate the cache entries
|
189 |
|
|
// for the given address range.
|
190 |
|
|
#define HAL_DCACHE_FLUSH_DEFINED
|
191 |
|
|
#if HAL_DCACHE_WRITETHRU_MODE == 1
|
192 |
|
|
// No need to flush a writethrough cache
|
193 |
|
|
#define HAL_DCACHE_FLUSH( _base_ , _asize_ )
|
194 |
|
|
#else
|
195 |
|
|
#error HAL_DCACHE_FLUSH undefined for MIPS32 writeback cache
|
196 |
|
|
#endif
|
197 |
|
|
|
198 |
|
|
// Write dirty cache lines to memory for the given address range.
|
199 |
|
|
#define HAL_DCACHE_STORE_DEFINED
|
200 |
|
|
#if HAL_DCACHE_WRITETHRU_MODE == 1
|
201 |
|
|
// No need to store a writethrough cache
|
202 |
|
|
#define HAL_DCACHE_STORE( _base_ , _asize_ )
|
203 |
|
|
#else
|
204 |
|
|
#error HAL_DCACHE_STORE undefined for MIPS32 writeback cache
|
205 |
|
|
#endif
|
206 |
|
|
|
207 |
|
|
// Invalidate cache lines in the given range without writing to memory.
|
208 |
|
|
#define HAL_DCACHE_INVALIDATE_DEFINED
|
209 |
|
|
#define HAL_DCACHE_INVALIDATE( _base_ , _asize_ ) \
|
210 |
|
|
CYG_MACRO_START \
|
211 |
|
|
register CYG_ADDRESS _baddr_ = (CYG_ADDRESS)(_base_); \
|
212 |
|
|
register CYG_ADDRESS _addr_ = (CYG_ADDRESS)(_base_); \
|
213 |
|
|
register CYG_WORD _size_ = (_asize_); \
|
214 |
|
|
for( ; _addr_ <= _baddr_+_size_; _addr_ += HAL_DCACHE_LINE_SIZE ) \
|
215 |
|
|
asm volatile (" cache %0, 0(%1)" \
|
216 |
|
|
: \
|
217 |
|
|
: "I" (HAL_CACHE_OP(HAL_WHICH_DCACHE, HAL_HIT_INVALIDATE)), \
|
218 |
|
|
"r"(_addr_)); \
|
219 |
|
|
CYG_MACRO_END
|
220 |
|
|
|
221 |
|
|
|
222 |
|
|
|
223 |
|
|
|
224 |
|
|
|
225 |
|
|
|
226 |
|
|
//-----------------------------------------------------------------------------
|
227 |
|
|
// Global control of Instruction cache
|
228 |
|
|
|
229 |
|
|
// Invalidate the entire cache
|
230 |
|
|
#define HAL_ICACHE_INVALIDATE_ALL_DEFINED
|
231 |
|
|
#define HAL_ICACHE_INVALIDATE_ALL() \
|
232 |
|
|
CYG_MACRO_START \
|
233 |
|
|
register volatile CYG_BYTE *addr; \
|
234 |
|
|
HAL_CLEAR_TAGLO(); \
|
235 |
|
|
HAL_CLEAR_TAGHI(); \
|
236 |
|
|
for (addr = (CYG_BYTE *)CYGARC_KSEG_CACHED_BASE; \
|
237 |
|
|
addr < (CYG_BYTE *)(CYGARC_KSEG_CACHED_BASE + HAL_ICACHE_SIZE); \
|
238 |
|
|
addr += HAL_ICACHE_LINE_SIZE ) \
|
239 |
|
|
{ \
|
240 |
|
|
asm volatile (" cache %0, 0(%1)" \
|
241 |
|
|
: \
|
242 |
|
|
: "I" (HAL_CACHE_OP(HAL_WHICH_ICACHE, HAL_INDEX_STORE_TAG)), \
|
243 |
|
|
"r"(addr)); \
|
244 |
|
|
} \
|
245 |
|
|
CYG_MACRO_END
|
246 |
|
|
|
247 |
|
|
// Synchronize the contents of the cache with memory.
|
248 |
|
|
//extern void hal_icache_sync(void);
|
249 |
|
|
//#define HAL_ICACHE_SYNC_DEFINED
|
250 |
|
|
//#define HAL_ICACHE_SYNC() hal_icache_sync()
|
251 |
|
|
|
252 |
|
|
// Set the instruction cache refill burst size
|
253 |
|
|
//#define HAL_ICACHE_BURST_SIZE(_asize_)
|
254 |
|
|
|
255 |
|
|
// Load the contents of the given address range into the data cache
|
256 |
|
|
// and then lock the cache so that it stays there.
|
257 |
|
|
#define HAL_ICACHE_LOCK_DEFINED
|
258 |
|
|
#define HAL_ICACHE_LOCK(_base_, _asize_) \
|
259 |
|
|
CYG_MACRO_START \
|
260 |
|
|
register CYG_ADDRESS _baddr_ = (CYG_ADDRESS)(_base_); \
|
261 |
|
|
register CYG_ADDRESS _addr_ = (CYG_ADDRESS)(_base_); \
|
262 |
|
|
register CYG_WORD _size_ = (_asize_); \
|
263 |
|
|
for( ; _addr_ <= _baddr_+_size_; _addr_ += HAL_ICACHE_LINE_SIZE ) \
|
264 |
|
|
asm volatile (" cache %0, 0(%1)" \
|
265 |
|
|
: \
|
266 |
|
|
: "I" (HAL_CACHE_OP(HAL_WHICH_ICACHE, HAL_FETCH_AND_LOCK)), \
|
267 |
|
|
"r"(_addr_)); \
|
268 |
|
|
CYG_MACRO_END
|
269 |
|
|
|
270 |
|
|
// Undo a previous lock operation
|
271 |
|
|
#define HAL_ICACHE_UNLOCK_DEFINED
|
272 |
|
|
#define HAL_ICACHE_UNLOCK(_base_, _asize_) \
|
273 |
|
|
CYG_MACRO_START \
|
274 |
|
|
register CYG_ADDRESS _baddr_ = (CYG_ADDRESS)(_base_); \
|
275 |
|
|
register CYG_ADDRESS _addr_ = (CYG_ADDRESS)(_base_); \
|
276 |
|
|
register CYG_WORD _size_ = (_asize_); \
|
277 |
|
|
for( ; _addr_ <= _baddr_+_size_; _addr_ += HAL_ICACHE_LINE_SIZE ) \
|
278 |
|
|
asm volatile (" cache %0, 0(%1)" \
|
279 |
|
|
: \
|
280 |
|
|
: "I" (HAL_CACHE_OP(HAL_WHICH_ICACHE, HAL_HIT_INVALIDATE)), \
|
281 |
|
|
"r"(_addr_)); \
|
282 |
|
|
CYG_MACRO_END
|
283 |
|
|
|
284 |
|
|
// Unlock entire cache
|
285 |
|
|
#define HAL_ICACHE_UNLOCK_ALL_DEFINED
|
286 |
|
|
#define HAL_ICACHE_UNLOCK_ALL() HAL_ICACHE_UNLOCK(0,HAL_ICACHE_SIZE)
|
287 |
|
|
|
288 |
|
|
//-----------------------------------------------------------------------------
|
289 |
|
|
// Instruction cache line control
|
290 |
|
|
|
291 |
|
|
// Invalidate cache lines in the given range without writing to memory.
|
292 |
|
|
#define HAL_ICACHE_INVALIDATE_DEFINED
|
293 |
|
|
#define HAL_ICACHE_INVALIDATE( _base_ , _asize_ ) \
|
294 |
|
|
CYG_MACRO_START \
|
295 |
|
|
register CYG_ADDRESS _baddr_ = (CYG_ADDRESS)(_base_); \
|
296 |
|
|
register CYG_ADDRESS _addr_ = (CYG_ADDRESS)(_base_); \
|
297 |
|
|
register CYG_WORD _size_ = (_asize_); \
|
298 |
|
|
for( ; _addr_ <= _baddr_+_size_; _addr_ += HAL_ICACHE_LINE_SIZE ) \
|
299 |
|
|
asm volatile (" cache %0, 0(%1)" \
|
300 |
|
|
: \
|
301 |
|
|
: "I" (HAL_CACHE_OP(HAL_WHICH_ICACHE, HAL_HIT_INVALIDATE)), \
|
302 |
|
|
"r"(_addr_)); \
|
303 |
|
|
CYG_MACRO_END
|
304 |
|
|
|
305 |
|
|
//-----------------------------------------------------------------------------
|
306 |
|
|
#endif // ifndef CYGONCE_VAR_CACHE_H
|
307 |
|
|
// End of var_cache.h
|