1 |
27 |
unneback |
#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 |
|
|
//####ECOSGPLCOPYRIGHTBEGIN####
|
12 |
|
|
// -------------------------------------------
|
13 |
|
|
// This file is part of eCos, the Embedded Configurable Operating System.
|
14 |
|
|
// Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
|
15 |
|
|
//
|
16 |
|
|
// eCos is free software; you can redistribute it and/or modify it under
|
17 |
|
|
// the terms of the GNU General Public License as published by the Free
|
18 |
|
|
// Software Foundation; either version 2 or (at your option) any later version.
|
19 |
|
|
//
|
20 |
|
|
// eCos is distributed in the hope that it will be useful, but WITHOUT ANY
|
21 |
|
|
// 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 along
|
26 |
|
|
// with eCos; if not, write to the Free Software Foundation, Inc.,
|
27 |
|
|
// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
|
28 |
|
|
//
|
29 |
|
|
// As a special exception, if other files instantiate templates or use macros
|
30 |
|
|
// or inline functions from this file, or you compile this file and link it
|
31 |
|
|
// with other works to produce a work based on this file, this file does not
|
32 |
|
|
// by itself cause the resulting work to be covered by the GNU General Public
|
33 |
|
|
// License. However the source code for this file must still be made available
|
34 |
|
|
// in accordance with section (3) of the GNU General Public License.
|
35 |
|
|
//
|
36 |
|
|
// This exception does not invalidate any other reasons why a work based on
|
37 |
|
|
// this file might be covered by the GNU General Public License.
|
38 |
|
|
//
|
39 |
|
|
// Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.
|
40 |
|
|
// at http://sources.redhat.com/ecos/ecos-license/
|
41 |
|
|
// -------------------------------------------
|
42 |
|
|
//####ECOSGPLCOPYRIGHTEND####
|
43 |
|
|
//=============================================================================
|
44 |
|
|
//#####DESCRIPTIONBEGIN####
|
45 |
|
|
//
|
46 |
|
|
// Author(s): Scott Furman
|
47 |
|
|
// Contributors:
|
48 |
|
|
// Date: 2003-02-08
|
49 |
|
|
// Purpose: Cache control API
|
50 |
|
|
// Description: The macros defined here provide the HAL APIs for handling
|
51 |
|
|
// cache control operations.
|
52 |
|
|
// Usage:
|
53 |
|
|
// #include <cyg/hal/hal_cache.h>
|
54 |
|
|
// ...
|
55 |
|
|
//
|
56 |
|
|
//
|
57 |
|
|
//####DESCRIPTIONEND####
|
58 |
|
|
//
|
59 |
|
|
//=============================================================================
|
60 |
|
|
|
61 |
|
|
//-----------------------------------------------------------------------------
|
62 |
|
|
// Cache dimensions.
|
63 |
|
|
// These really should be defined in var_cache.h. If they are not, then provide
|
64 |
|
|
// a set of numbers that are typical of many variants.
|
65 |
|
|
|
66 |
|
|
#ifndef HAL_DCACHE_SIZE
|
67 |
|
|
|
68 |
|
|
// Data cache
|
69 |
|
|
#define HAL_DCACHE_SIZE 4096 // Size of data cache in bytes
|
70 |
|
|
#define HAL_DCACHE_LINE_SIZE 16 // Bytes in a data cache line
|
71 |
|
|
#define HAL_DCACHE_WAYS 1 // Associativity of the cache
|
72 |
|
|
|
73 |
|
|
// Instruction cache
|
74 |
|
|
#define HAL_ICACHE_SIZE 4096 // Size of cache in bytes
|
75 |
|
|
#define HAL_ICACHE_LINE_SIZE 16 // Bytes in a cache line
|
76 |
|
|
#define HAL_ICACHE_WAYS 1 // Associativity of the cache
|
77 |
|
|
|
78 |
|
|
#define HAL_DCACHE_SETS (HAL_DCACHE_SIZE/(HAL_DCACHE_LINE_SIZE*HAL_DCACHE_WAYS))
|
79 |
|
|
#define HAL_ICACHE_SETS (HAL_ICACHE_SIZE/(HAL_ICACHE_LINE_SIZE*HAL_ICACHE_WAYS))
|
80 |
|
|
|
81 |
|
|
#endif
|
82 |
|
|
|
83 |
|
|
#ifndef __ASSEMBLER__
|
84 |
|
|
|
85 |
|
|
//-----------------------------------------------------------------------------
|
86 |
|
|
// Global control of data cache
|
87 |
|
|
|
88 |
|
|
// Enable the data cache
|
89 |
|
|
#define HAL_DCACHE_ENABLE() MTSPR(SPR_SR, MFSPR(SPR_SR) | SPR_SR_DCE)
|
90 |
|
|
|
91 |
|
|
// Disable the data cache
|
92 |
|
|
#define HAL_DCACHE_DISABLE() MTSPR(SPR_SR, MFSPR(SPR_SR) & ~SPR_SR_DCE)
|
93 |
|
|
|
94 |
|
|
// Enable or disable the data cache, depending on argument, which is required
|
95 |
|
|
// to be 0 or 1.
|
96 |
|
|
#define HAL_SET_DCACHE_ENABLED(enable) \
|
97 |
|
|
MTSPR(SPR_SR, MFSPR(SPR_SR) | (SPR_SR_DCE & -(enable)))
|
98 |
|
|
|
99 |
|
|
// Invalidate the entire data cache
|
100 |
|
|
#define HAL_DCACHE_INVALIDATE_ALL() \
|
101 |
|
|
CYG_MACRO_START \
|
102 |
|
|
int cache_enabled, addr; \
|
103 |
|
|
\
|
104 |
|
|
/* Save current cache mode (disabled/enabled) */ \
|
105 |
|
|
HAL_DCACHE_IS_ENABLED(cache_enabled); \
|
106 |
|
|
\
|
107 |
|
|
/* Disable cache, so that invalidation ignores cache tags */\
|
108 |
|
|
HAL_DCACHE_DISABLE(); \
|
109 |
|
|
addr = HAL_DCACHE_SIZE; \
|
110 |
|
|
do { \
|
111 |
|
|
MTSPR(SPR_DCBIR, addr); \
|
112 |
|
|
addr -= HAL_DCACHE_LINE_SIZE; \
|
113 |
|
|
} while (addr > 0); \
|
114 |
|
|
\
|
115 |
|
|
/* Re-enable cache if it was enabled on entry */ \
|
116 |
|
|
HAL_SET_DCACHE_ENABLED(cache_enabled); \
|
117 |
|
|
CYG_MACRO_END
|
118 |
|
|
|
119 |
|
|
// Synchronize the contents of the cache with memory.
|
120 |
|
|
// (Unnecessary on OR12K, since cache is write-through.)
|
121 |
|
|
#define HAL_DCACHE_SYNC() \
|
122 |
|
|
CYG_MACRO_START \
|
123 |
|
|
CYG_MACRO_END
|
124 |
|
|
|
125 |
|
|
// Query the state (enabled/disabled) of the data cache
|
126 |
|
|
#define HAL_DCACHE_IS_ENABLED(_state_) \
|
127 |
|
|
CYG_MACRO_START \
|
128 |
|
|
(_state_) = (1 - !(MFSPR(SPR_SR) & SPR_SR_DCE)); \
|
129 |
|
|
CYG_MACRO_END
|
130 |
|
|
|
131 |
|
|
// Load the contents of the given address range into the data cache
|
132 |
|
|
// and then lock the cache so that it stays there.
|
133 |
|
|
|
134 |
|
|
// The OpenRISC architecture defines these operations, but no
|
135 |
|
|
// implementation supports them yet.
|
136 |
|
|
|
137 |
|
|
//#define HAL_DCACHE_LOCK(_base_, _size_)
|
138 |
|
|
|
139 |
|
|
// Undo a previous lock operation
|
140 |
|
|
//#define HAL_DCACHE_UNLOCK(_base_, _size_)
|
141 |
|
|
|
142 |
|
|
// Unlock entire cache
|
143 |
|
|
//#define HAL_DCACHE_UNLOCK_ALL()
|
144 |
|
|
|
145 |
|
|
|
146 |
|
|
//-----------------------------------------------------------------------------
|
147 |
|
|
// Data cache line control
|
148 |
|
|
|
149 |
|
|
// Write dirty cache lines to memory and invalidate the cache entries
|
150 |
|
|
// for the given address range.
|
151 |
|
|
// OR12k has write-through cache, so no flushing of writes to memory
|
152 |
|
|
// are necessary.
|
153 |
|
|
#define HAL_DCACHE_FLUSH( _base_ , _size_ ) \
|
154 |
|
|
HAL_DCACHE_INVALIDATE(_base_, _size_)
|
155 |
|
|
|
156 |
|
|
// Invalidate cache lines in the given range without writing to memory.
|
157 |
|
|
#define HAL_DCACHE_INVALIDATE( _base_ , _size_ ) \
|
158 |
|
|
CYG_MACRO_START \
|
159 |
|
|
int addr; \
|
160 |
|
|
int end = _base_ + _size_; \
|
161 |
|
|
for (addr = end; addr >= _base_; addr -= HAL_DCACHE_LINE_SIZE) { \
|
162 |
|
|
MTSPR(SPR_DCBIR, addr); \
|
163 |
|
|
} \
|
164 |
|
|
CYG_MACRO_END
|
165 |
|
|
|
166 |
|
|
// Write dirty cache lines to memory for the given address range.
|
167 |
|
|
// OR12k has write-through cache, so this is a NOP
|
168 |
|
|
#define HAL_DCACHE_STORE( _base_ , _size_ )
|
169 |
|
|
|
170 |
|
|
// Preread the given range into the cache with the intention of reading
|
171 |
|
|
// from it later.
|
172 |
|
|
//#define HAL_DCACHE_READ_HINT( _base_ , _size_ )
|
173 |
|
|
|
174 |
|
|
// Preread the given range into the cache with the intention of writing
|
175 |
|
|
// to it later.
|
176 |
|
|
//#define HAL_DCACHE_WRITE_HINT( _base_ , _size_ )
|
177 |
|
|
|
178 |
|
|
// Allocate and zero the cache lines associated with the given range.
|
179 |
|
|
//#define HAL_DCACHE_ZERO( _base_ , _size_ )
|
180 |
|
|
|
181 |
|
|
//-----------------------------------------------------------------------------
|
182 |
|
|
// Global control of Instruction cache
|
183 |
|
|
|
184 |
|
|
// Enable the instruction cache
|
185 |
|
|
#define HAL_ICACHE_ENABLE() MTSPR(SPR_SR, MFSPR(SPR_SR) | SPR_SR_ICE)
|
186 |
|
|
|
187 |
|
|
// Disable the instruction cache
|
188 |
|
|
#define HAL_ICACHE_DISABLE() MTSPR(SPR_SR, MFSPR(SPR_SR) & ~SPR_SR_ICE)
|
189 |
|
|
|
190 |
|
|
// Enable or disable the data cache, depending on argument, which must
|
191 |
|
|
// be 0 or 1.
|
192 |
|
|
#define HAL_SET_ICACHE_ENABLED(enable) \
|
193 |
|
|
MTSPR(SPR_SR, MFSPR(SPR_SR) | (SPR_SR_ICE & -(enable)))
|
194 |
|
|
|
195 |
|
|
// Invalidate the entire instruction cache
|
196 |
|
|
#define HAL_ICACHE_INVALIDATE_ALL() \
|
197 |
|
|
CYG_MACRO_START \
|
198 |
|
|
int cache_enabled, addr; \
|
199 |
|
|
\
|
200 |
|
|
/* Save current cache mode (disabled/enabled) */ \
|
201 |
|
|
HAL_ICACHE_IS_ENABLED(cache_enabled); \
|
202 |
|
|
\
|
203 |
|
|
/* Disable cache, so that invalidation ignores cache tags */\
|
204 |
|
|
HAL_ICACHE_DISABLE(); \
|
205 |
|
|
addr = HAL_ICACHE_SIZE; \
|
206 |
|
|
do { \
|
207 |
|
|
MTSPR(SPR_ICBIR, addr); \
|
208 |
|
|
addr -= HAL_ICACHE_LINE_SIZE; \
|
209 |
|
|
} while (addr > 0); \
|
210 |
|
|
\
|
211 |
|
|
/* Re-enable cache if it was enabled on entry */ \
|
212 |
|
|
HAL_SET_ICACHE_ENABLED(cache_enabled); \
|
213 |
|
|
CYG_MACRO_END
|
214 |
|
|
|
215 |
|
|
// Synchronize the contents of the cache with memory.
|
216 |
|
|
#define HAL_ICACHE_SYNC() HAL_ICACHE_INVALIDATE_ALL()
|
217 |
|
|
|
218 |
|
|
// Query the state of the instruction cache
|
219 |
|
|
#define HAL_ICACHE_IS_ENABLED(_state_) \
|
220 |
|
|
CYG_MACRO_START \
|
221 |
|
|
(_state_) = (1 - !(MFSPR(SPR_SR) & SPR_SR_ICE)); \
|
222 |
|
|
CYG_MACRO_END
|
223 |
|
|
|
224 |
|
|
|
225 |
|
|
// Load the contents of the given address range into the instruction cache
|
226 |
|
|
// and then lock the cache so that it stays there.
|
227 |
|
|
|
228 |
|
|
// The OpenRISC architecture defines these operations, but no
|
229 |
|
|
// implementation supports them yet.
|
230 |
|
|
|
231 |
|
|
//#define HAL_ICACHE_LOCK(_base_, _size_)
|
232 |
|
|
|
233 |
|
|
// Undo a previous lock operation
|
234 |
|
|
//#define HAL_ICACHE_UNLOCK(_base_, _size_)
|
235 |
|
|
|
236 |
|
|
// Unlock entire cache
|
237 |
|
|
//#define HAL_ICACHE_UNLOCK_ALL()
|
238 |
|
|
|
239 |
|
|
#endif /* __ASSEMBLER__ */
|
240 |
|
|
|
241 |
|
|
#endif // ifndef CYGONCE_HAL_CACHE_H
|
242 |
|
|
// End of hal_cache.h
|