1 #ifndef CYGONCE_VAR_CACHE_H
2 #define CYGONCE_VAR_CACHE_H
3 //=============================================================================
7 // Variant HAL cache control API
9 //=============================================================================
10 //####ECOSGPLCOPYRIGHTBEGIN####
11 // -------------------------------------------
12 // This file is part of eCos, the Embedded Configurable Operating System.
13 // Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
14 // Copyright (C) 2002, 2003 Gary Thomas
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.
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
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.
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.
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.
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####
47 // Contributors:nickg, jskov, gthomas
49 // Purpose: Variant cache control API
50 // Description: The macros defined here provide the HAL APIs for handling
51 // cache control operations on the PPC60x variant CPUs.
52 // Usage: Is included via the architecture cache header:
53 // #include <cyg/hal/hal_cache.h>
56 //####DESCRIPTIONEND####
58 //=============================================================================
60 #include <pkgconf/hal.h>
61 #include <cyg/infra/cyg_type.h>
63 #include <cyg/hal/ppc_regs.h>
64 #include <cyg/hal/plf_cache.h>
67 //-----------------------------------------------------------------------------
71 #ifndef HAL_DCACHE_SIZE
72 #define HAL_DCACHE_SIZE 16384 // Size of data cache in bytes
73 #define HAL_DCACHE_LINE_SIZE 32 // Size of a data cache line
74 #define HAL_DCACHE_WAYS 4 // Associativity of the cache
78 #ifndef HAL_ICACHE_SIZE
79 #define HAL_ICACHE_SIZE 16384 // Size of cache in bytes
80 #define HAL_ICACHE_LINE_SIZE 32 // Size of a cache line
81 #define HAL_ICACHE_WAYS 4 // Associativity of the cache
84 #define HAL_DCACHE_SETS (HAL_DCACHE_SIZE/(HAL_DCACHE_LINE_SIZE*HAL_DCACHE_WAYS))
85 #define HAL_ICACHE_SETS (HAL_ICACHE_SIZE/(HAL_ICACHE_LINE_SIZE*HAL_ICACHE_WAYS))
87 //-----------------------------------------------------------------------------
88 // Global control of data cache
90 // Enable the data cache
91 #define HAL_DCACHE_ENABLE() \
94 asm volatile ("isync;" \
99 : "I" (CYGARC_REG_HID0), \
104 // Disable the data cache
105 #define HAL_DCACHE_DISABLE() \
107 cyg_int32 _scratch; \
108 asm volatile ("isync;" \
113 : "I" (CYGARC_REG_HID0), \
118 // Invalidate the entire cache
119 #define HAL_DCACHE_INVALIDATE_ALL() \
121 cyg_int32 _scr1, _scr2; \
122 asm volatile ("isync;" \
130 : "I" (CYGARC_REG_HID0), \
135 // Synchronize the contents of the cache with memory.
136 // Modifications to this macro should mirror modifications to the
137 // identically named one in the mpc8260 variant.
138 // We step through twice the number of lines in the cache in order
139 // to ensure that all dirty lines are flushed to main memory.
140 // (Consider the case where one of the dirty lines is in the
141 // first 16Kbytes of RAM -- it won't get flushed by loading
142 // in words from the first 16Kbytes of RAM).
143 #define HAL_DCACHE_SYNC() \
146 cyg_uint32 *__base = (cyg_uint32 *) (0); \
147 for(i=0;i< (2 * HAL_DCACHE_SIZE/HAL_DCACHE_LINE_SIZE);i++,__base += HAL_DCACHE_LINE_SIZE/4){ \
148 asm volatile ("lwz %%r0,0(%0);"::"r"(__base):"r0"); \
152 // Query the state of the data cache
153 #define HAL_DCACHE_IS_ENABLED(_state_) \
155 cyg_int32 _scratch; \
156 asm volatile ("isync;" \
160 : "I" (CYGARC_REG_HID0), \
163 (_state_) = _scratch != 0; \
166 // Set the data cache refill burst size
167 //#define HAL_DCACHE_BURST_SIZE(_size_)
169 // Set the data cache write mode
170 //#define HAL_DCACHE_WRITE_MODE( _mode_ )
172 //#define HAL_DCACHE_WRITETHRU_MODE 0
173 //#define HAL_DCACHE_WRITEBACK_MODE 1
175 // Load the contents of the given address range into the data cache
176 // and then lock the cache so that it stays there.
177 //#define HAL_DCACHE_LOCK(_base_, _size_)
179 // Undo a previous lock operation
180 //#define HAL_DCACHE_UNLOCK(_base_, _size_)
182 // Unlock entire cache
183 //#define HAL_DCACHE_UNLOCK_ALL()
185 //-----------------------------------------------------------------------------
186 // Data cache line control
188 // Allocate cache lines for the given address range without reading its
189 // contents from memory.
190 //#define HAL_DCACHE_ALLOCATE( _base_ , _size_ )
192 // Write dirty cache lines to memory and invalidate the cache entries
193 // for the given address range.
194 #define HAL_DCACHE_FLUSH( _base_ , _size_ ) \
196 cyg_uint32 __base = (cyg_uint32) (_base_); \
197 cyg_int32 __size = (cyg_int32) (_size_); \
198 while (__size > 0) { \
199 asm volatile ("dcbf 0,%0;sync;" : : "r" (__base)); \
200 __base += HAL_DCACHE_LINE_SIZE; \
201 __size -= HAL_DCACHE_LINE_SIZE; \
205 // Invalidate cache lines in the given range without writing to memory.
206 #define HAL_DCACHE_INVALIDATE( _base_ , _size_ ) \
208 cyg_uint32 __base = (cyg_uint32) (_base_); \
209 cyg_int32 __size = (cyg_int32) (_size_); \
210 while (__size > 0) { \
211 asm volatile ("dcbi 0,%0;sync;" : : "r" (__base)); \
212 __base += HAL_DCACHE_LINE_SIZE; \
213 __size -= HAL_DCACHE_LINE_SIZE; \
217 // Write dirty cache lines to memory for the given address range.
218 #define HAL_DCACHE_STORE( _base_ , _size_ ) \
220 cyg_uint32 __base = (cyg_uint32) (_base_); \
221 cyg_int32 __size = (cyg_int32) (_size_); \
222 while (__size > 0) { \
223 asm volatile ("dcbst 0,%0;sync;" : : "r" (__base)); \
224 __base += HAL_DCACHE_LINE_SIZE; \
225 __size -= HAL_DCACHE_LINE_SIZE; \
229 // Preread the given range into the cache with the intention of reading
231 #define HAL_DCACHE_READ_HINT( _base_ , _size_ ) \
233 cyg_uint32 __base = (cyg_uint32) (_base_); \
234 cyg_int32 __size = (cyg_int32) (_size_); \
235 while (__size > 0) { \
236 asm volatile ("dcbt 0,%0;" : : "r" (__base)); \
237 __base += HAL_DCACHE_LINE_SIZE; \
238 __size -= HAL_DCACHE_LINE_SIZE; \
242 // Preread the given range into the cache with the intention of writing
244 #define HAL_DCACHE_WRITE_HINT( _base_ , _size_ ) \
246 cyg_uint32 __base = (cyg_uint32) (_base_); \
247 cyg_int32 __size = (cyg_int32) (_size_); \
248 while (__size > 0) { \
249 asm volatile ("dcbtst 0,%0;" : : "r" (__base)); \
250 __base += HAL_DCACHE_LINE_SIZE; \
251 __size -= HAL_DCACHE_LINE_SIZE; \
255 // Allocate and zero the cache lines associated with the given range.
256 #define HAL_DCACHE_ZERO( _base_ , _size_ ) \
258 cyg_uint32 __base = (cyg_uint32) (_base_); \
259 cyg_int32 __size = (cyg_int32) (_size_); \
260 while (__size > 0) { \
261 asm volatile ("dcbz 0,%0;" : : "r" (__base)); \
262 __base += HAL_DCACHE_LINE_SIZE; \
263 __size -= HAL_DCACHE_LINE_SIZE; \
267 //-----------------------------------------------------------------------------
268 // Global control of Instruction cache
270 // Enable the instruction cache
271 #define HAL_ICACHE_ENABLE() \
273 cyg_int32 _scratch; \
274 asm volatile ("isync;" \
279 : "I" (CYGARC_REG_HID0), \
284 // Disable the instruction cache
285 #define HAL_ICACHE_DISABLE() \
287 cyg_int32 _scratch; \
288 asm volatile ("isync;" \
293 : "I" (CYGARC_REG_HID0), \
298 // Invalidate the entire cache
299 #define HAL_ICACHE_INVALIDATE_ALL() \
301 cyg_int32 _scr1, _scr2; \
302 asm volatile ("isync;" \
310 : "I" (CYGARC_REG_HID0), \
315 // Synchronize the contents of the cache with memory.
316 #define HAL_ICACHE_SYNC() \
317 HAL_ICACHE_INVALIDATE_ALL()
319 // Query the state of the instruction cache
320 #define HAL_ICACHE_IS_ENABLED(_state_) \
322 cyg_int32 _scratch; \
323 asm volatile ("isync;" \
327 : "I" (CYGARC_REG_HID0), \
330 (_state_) = _scratch != 0; \
333 // Set the instruction cache refill burst size
334 //#define HAL_ICACHE_BURST_SIZE(_size_)
336 // Load the contents of the given address range into the instruction cache
337 // and then lock the cache so that it stays there.
338 //#define HAL_ICACHE_LOCK(_base_, _size_)
340 // Undo a previous lock operation
341 //#define HAL_ICACHE_UNLOCK(_base_, _size_)
343 // Unlock entire cache
344 //#define HAL_ICACHE_UNLOCK_ALL()
346 //-----------------------------------------------------------------------------
347 // Instruction cache line control
349 // Invalidate cache lines in the given range without writing to memory.
350 //#define HAL_ICACHE_INVALIDATE( _base_ , _size_ )
352 //-----------------------------------------------------------------------------
353 #endif // ifndef CYGONCE_VAR_CACHE_H
354 // End of var_cache.h