1 #ifndef CYGONCE_IMP_CACHE_H
2 #define CYGONCE_IMP_CACHE_H
4 //=============================================================================
8 // HAL cache control API
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.
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
49 // Purpose: Cache control API
50 // Description: The macros defined here provide the HAL APIs for handling
51 // cache control operations.
53 // #include <cyg/hal/imp_cache.h>
57 //####DESCRIPTIONEND####
59 //=============================================================================
61 #include <pkgconf/hal.h>
62 #include <cyg/infra/cyg_type.h>
64 #include <cyg/hal/plf_cache.h>
66 //=============================================================================
69 #ifdef CYGPKG_HAL_MIPS_TX3904
71 //-----------------------------------------------------------------------------
75 #define HAL_DCACHE_SIZE 1024 // Size of data cache in bytes
76 #define HAL_DCACHE_LINE_SIZE 4 // Size of a data cache line
77 #define HAL_DCACHE_WAYS 2 // Associativity of the cache
80 #define HAL_ICACHE_SIZE 4096 // Size of cache in bytes
81 #define HAL_ICACHE_LINE_SIZE 16 // Size of a cache line
82 #define HAL_ICACHE_WAYS 1 // 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 // This uses a bit in the config register, which is TX39 specific.
92 #define HAL_DCACHE_ENABLE_DEFINED
93 #define HAL_DCACHE_ENABLE() \
95 asm volatile ("mfc0 $2,$3;" \
105 // Disable the data cache
106 #define HAL_DCACHE_DISABLE_DEFINED
107 #define HAL_DCACHE_DISABLE() \
109 asm volatile ("mfc0 $2,$3;" \
110 "la $3,0xFFFFFFEF;" \
121 // Invalidate the entire cache
122 // The TX39 only has hit-invalidate on the DCACHE, not
123 // index-invalidate, so we cannot just empty the cache out without
124 // knowing what is in it. This is annoying. So, the best we can do is
125 // fill the cache with data that is unlikely to be there
126 // otherwise. Hence we read bytes from the ROM space since this is
127 // most likely to be code, and will not get out of sync even if it is not.
128 #define HAL_DCACHE_INVALIDATE_ALL_DEFINED
129 #define HAL_DCACHE_INVALIDATE_ALL() \
131 volatile CYG_BYTE *addr = (CYG_BYTE *)(0x9fc00000); \
132 volatile CYG_BYTE tmp = 0; \
134 for( i = 0; i < (HAL_DCACHE_SIZE*2); i += HAL_DCACHE_LINE_SIZE ) \
140 // Synchronize the contents of the cache with memory.
141 #define HAL_DCACHE_SYNC_DEFINED
142 #define HAL_DCACHE_SYNC() HAL_DCACHE_INVALIDATE_ALL()
144 // Set the data cache refill burst size
145 //#define HAL_DCACHE_BURST_SIZE(_size_)
147 // Set the data cache write mode
148 //#define HAL_DCACHE_WRITE_MODE( _mode_ )
150 //#define HAL_DCACHE_WRITETHRU_MODE 0
151 //#define HAL_DCACHE_WRITEBACK_MODE 1
153 // Load the contents of the given address range into the data cache
154 // and then lock the cache so that it stays there.
155 #define HAL_DCACHE_LOCK_DEFINED
156 #define HAL_DCACHE_LOCK(_base_, _size_) \
158 asm volatile ("mfc0 $2,$7;" \
159 "ori $2,$2,0x0100;" \
167 // Undo a previous lock operation
168 #define HAL_DCACHE_UNLOCK_DEFINED
169 #define HAL_DCACHE_UNLOCK(_base_, _size_) \
171 asm volatile ("mfc0 $2,$7;" \
172 "la $3,0xFFFFFEFF;" \
181 // Unlock entire cache
182 #define HAL_DCACHE_UNLOCK_ALL_DEFINED
183 #define HAL_DCACHE_UNLOCK_ALL() HAL_DCACHE_UNLOCK(0,HAL_DCACHE_SIZE)
186 //-----------------------------------------------------------------------------
187 // Data cache line control
189 // Allocate cache lines for the given address range without reading its
190 // contents from memory.
191 //#define HAL_DCACHE_ALLOCATE( _base_ , _size_ )
193 // Write dirty cache lines to memory and invalidate the cache entries
194 // for the given address range.
195 //#define HAL_DCACHE_FLUSH( _base_ , _size_ )
196 #define HAL_DCACHE_FLUSH_DEFINED // Ensure no default definition
198 // Write dirty cache lines to memory for the given address range.
199 //#define HAL_DCACHE_STORE( _base_ , _size_ )
200 #define HAL_DCACHE_STORE_DEFINED // Disable default definition
202 //-----------------------------------------------------------------------------
203 // Global control of Instruction cache
205 // Enable the instruction cache
206 // This uses a bit in the config register, which is TX39 specific.
207 #define HAL_ICACHE_ENABLE_DEFINED
208 #define HAL_ICACHE_ENABLE() \
210 asm volatile ("mfc0 $2,$3;" \
211 "ori $2,$2,0x0020;" \
220 // Disable the instruction cache
221 #define HAL_ICACHE_DISABLE_DEFINED
222 #define HAL_ICACHE_DISABLE() \
224 asm volatile ("mfc0 $2,$3;" \
225 "la $3,0xFFFFFFDF;" \
239 // Load the contents of the given address range into the instruction cache
240 // and then lock the cache so that it stays there.
241 #define HAL_ICACHE_LOCK_DEFINED
242 #define HAL_ICACHE_LOCK(_base_, _size_) \
244 asm volatile ("mfc0 $2,$7;" \
245 "ori $2,$2,0x0200;" \
253 // Undo a previous lock operation
254 #define HAL_ICACHE_UNLOCK_DEFINED
255 #define HAL_ICACHE_UNLOCK(_base_, _size_) \
257 asm volatile ("mfc0 $2,$7;" \
258 "la $3,0xFFFFFDFF;" \
267 // Unlock entire cache
268 #define HAL_ICACHE_UNLOCK_ALL_DEFINED
269 #define HAL_ICACHE_UNLOCK_ALL() HAL_ICACHE_UNLOCK(0, HAL_ICACHE_SIZE)
271 //-----------------------------------------------------------------------------
272 // Instruction cache line control
273 // On the TX39, the instruction cache must be disabled to use the index-invalidate
276 // Invalidate the entire cache
277 // This uses the index-invalidate cache operation.
278 #define HAL_ICACHE_INVALIDATE_ALL_DEFINED
279 #define HAL_ICACHE_INVALIDATE_ALL() \
281 register CYG_ADDRESS _baddr_ = 0x80000000; \
282 register CYG_ADDRESS _addr_ = 0x80000000; \
283 register CYG_WORD _state_; \
284 HAL_ICACHE_IS_ENABLED(_state_); \
285 HAL_ICACHE_DISABLE(); \
286 for( ; _addr_ < _baddr_+HAL_ICACHE_SIZE; _addr_ += HAL_ICACHE_LINE_SIZE ) \
288 asm volatile ("cache 0x00,0(%0)" : : "r"(_addr_) ); \
290 if( _state_ ) HAL_ICACHE_ENABLE(); \
293 // Invalidate cache lines in the given range without writing to memory.
294 // This uses the index-invalidate cache operation since the TX39 does not
295 // have hit-invalidate on the instruction cache.
296 #define HAL_ICACHE_INVALIDATE_DEFINED
297 #define HAL_ICACHE_INVALIDATE( _base_ , _asize_ ) \
299 register CYG_ADDRESS _addr_ = (CYG_ADDRESS)(_base_); \
300 register CYG_WORD _size_ = (_asize_); \
301 register CYG_WORD _state_; \
302 HAL_ICACHE_IS_ENABLED(_state_); \
303 HAL_ICACHE_DISABLE(); \
304 for( ; _addr_ <= _addr_+_size_; _addr_ += HAL_ICACHE_LINE_SIZE ) \
306 asm volatile ("cache 0,0(%0)" : : "r"(_addr_) ); \
308 if( _state_ ) HAL_ICACHE_ENABLE(); \
311 #endif // CYGPKG_HAL_MIPS_TX3904
313 //-----------------------------------------------------------------------------
314 #endif // ifndef CYGONCE_IMP_CACHE_H
315 // End of imp_cache.h