| 1 |
786 |
skrzyp |
#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 Free Software Foundation, 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
|
| 19 |
|
|
// version.
|
| 20 |
|
|
//
|
| 21 |
|
|
// eCos is distributed in the hope that it will be useful, but WITHOUT
|
| 22 |
|
|
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
| 23 |
|
|
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
| 24 |
|
|
// for more details.
|
| 25 |
|
|
//
|
| 26 |
|
|
// You should have received a copy of the GNU General Public License
|
| 27 |
|
|
// along with eCos; if not, write to the Free Software Foundation, Inc.,
|
| 28 |
|
|
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
| 29 |
|
|
//
|
| 30 |
|
|
// As a special exception, if other files instantiate templates or use
|
| 31 |
|
|
// macros or inline functions from this file, or you compile this file
|
| 32 |
|
|
// and link it with other works to produce a work based on this file,
|
| 33 |
|
|
// this file does not by itself cause the resulting work to be covered by
|
| 34 |
|
|
// the GNU General Public License. However the source code for this file
|
| 35 |
|
|
// must still be made available in accordance with section (3) of the GNU
|
| 36 |
|
|
// General Public License v2.
|
| 37 |
|
|
//
|
| 38 |
|
|
// This exception does not invalidate any other reasons why a work based
|
| 39 |
|
|
// on this file might be covered by the GNU General Public License.
|
| 40 |
|
|
// -------------------------------------------
|
| 41 |
|
|
// ####ECOSGPLCOPYRIGHTEND####
|
| 42 |
|
|
//=============================================================================
|
| 43 |
|
|
//#####DESCRIPTIONBEGIN####
|
| 44 |
|
|
//
|
| 45 |
|
|
// Author(s): nickg
|
| 46 |
|
|
// Contributors: nickg
|
| 47 |
|
|
// Date: 1998-02-17
|
| 48 |
|
|
// Purpose: Cache control API
|
| 49 |
|
|
// Description: The macros defined here provide the HAL APIs for handling
|
| 50 |
|
|
// cache control operations.
|
| 51 |
|
|
// Usage:
|
| 52 |
|
|
// #include <cyg/hal/hal_cache.h>
|
| 53 |
|
|
// ...
|
| 54 |
|
|
//
|
| 55 |
|
|
//
|
| 56 |
|
|
//####DESCRIPTIONEND####
|
| 57 |
|
|
//
|
| 58 |
|
|
//=============================================================================
|
| 59 |
|
|
|
| 60 |
|
|
#include <pkgconf/hal.h>
|
| 61 |
|
|
#include <cyg/infra/cyg_type.h>
|
| 62 |
|
|
|
| 63 |
|
|
#include <cyg/hal/var_cache.h>
|
| 64 |
|
|
|
| 65 |
|
|
// Use this macro to allow the assembler to accept "cache" instructions,
|
| 66 |
|
|
// which are MIPS ISA 3. This is useful if someone is compiling
|
| 67 |
|
|
// with -mips2, but the architecture is really MIPS ISA 3.
|
| 68 |
|
|
|
| 69 |
|
|
#define _hal_asm_mips_cpp_stringize( _x_ ) #_x_
|
| 70 |
|
|
#define _HAL_ASM_SET_MIPS_ISA( _isal_ ) asm volatile ( \
|
| 71 |
|
|
".set mips" _hal_asm_mips_cpp_stringize(_isal_) )
|
| 72 |
|
|
|
| 73 |
|
|
|
| 74 |
|
|
//=============================================================================
|
| 75 |
|
|
// Default Implementation. This uses the standard MIPS CP0 registers and
|
| 76 |
|
|
// cache instructions. Note that not all variants will have all of the
|
| 77 |
|
|
// functionality defined here.
|
| 78 |
|
|
|
| 79 |
|
|
//-----------------------------------------------------------------------------
|
| 80 |
|
|
// Cache dimensions.
|
| 81 |
|
|
// These really should be defined in var_cache.h. If they are not, then provide
|
| 82 |
|
|
// a set of numbers that are typical of many variants.
|
| 83 |
|
|
|
| 84 |
|
|
#ifndef HAL_DCACHE_SIZE
|
| 85 |
|
|
|
| 86 |
|
|
// Data cache
|
| 87 |
|
|
#define HAL_DCACHE_SIZE 4096 // Size of data cache in bytes
|
| 88 |
|
|
#define HAL_DCACHE_LINE_SIZE 16 // Size of a data cache line
|
| 89 |
|
|
#define HAL_DCACHE_WAYS 2 // Associativity of the cache
|
| 90 |
|
|
|
| 91 |
|
|
// Instruction cache
|
| 92 |
|
|
#define HAL_ICACHE_SIZE 4096 // Size of cache in bytes
|
| 93 |
|
|
#define HAL_ICACHE_LINE_SIZE 16 // Size of a cache line
|
| 94 |
|
|
#define HAL_ICACHE_WAYS 2 // Associativity of the cache
|
| 95 |
|
|
|
| 96 |
|
|
#define HAL_DCACHE_SETS (HAL_DCACHE_SIZE/(HAL_DCACHE_LINE_SIZE*HAL_DCACHE_WAYS))
|
| 97 |
|
|
#define HAL_ICACHE_SETS (HAL_ICACHE_SIZE/(HAL_ICACHE_LINE_SIZE*HAL_ICACHE_WAYS))
|
| 98 |
|
|
|
| 99 |
|
|
#endif
|
| 100 |
|
|
|
| 101 |
|
|
// Defines for various R4000+ MIPS cache operations
|
| 102 |
|
|
// this is a 5 bit field with bits 4-2 defining the operation
|
| 103 |
|
|
// and bits 1-0 defining which cache is being operated on
|
| 104 |
|
|
#define HAL_MIPS_CACHE_INDEX_INVALIDATE_I 0x00 /* 0 0 */
|
| 105 |
|
|
#define HAL_MIPS_CACHE_INDEX_WRITEBACK_INV_D 0x01 /* 0 1 */
|
| 106 |
|
|
#define HAL_MIPS_CACHE_INDEX_WRITEBACK_INV_S 0x03 /* 0 3 */
|
| 107 |
|
|
#define HAL_MIPS_CACHE_INDEX_LOAD_TAG_I 0x04 /* 1 0 */
|
| 108 |
|
|
#define HAL_MIPS_CACHE_INDEX_LOAD_TAG_D 0x05 /* 1 1 */
|
| 109 |
|
|
#define HAL_MIPS_CACHE_INDEX_LOAD_TAG_S 0x07 /* 1 3 */
|
| 110 |
|
|
#define HAL_MIPS_CACHE_INDEX_STORE_TAG_I 0x08 /* 2 0 */
|
| 111 |
|
|
#define HAL_MIPS_CACHE_INDEX_STORE_TAG_D 0x09 /* 2 1 */
|
| 112 |
|
|
#define HAL_MIPS_CACHE_INDEX_STORE_TAG_S 0x0b /* 2 3 */
|
| 113 |
|
|
#define HAL_MIPS_CACHE_HIT_INVALIDATE_I 0x10 /* 4 0 */
|
| 114 |
|
|
#define HAL_MIPS_CACHE_HIT_INVALIDATE_D 0x11 /* 4 1 */
|
| 115 |
|
|
#define HAL_MIPS_CACHE_HIT_INVALIDATE_S 0x13 /* 4 3 */
|
| 116 |
|
|
#define HAL_MIPS_CACHE_FILL_I 0x14 /* 5 0 */
|
| 117 |
|
|
#define HAL_MIPS_CACHE_HIT_WRITEBACK_INV_D 0x15 /* 5 1 */
|
| 118 |
|
|
#define HAL_MIPS_CACHE_HIT_WRITEBACK_INV_S 0x17 /* 5 3 */
|
| 119 |
|
|
|
| 120 |
|
|
// there seems to be different uses for operation
|
| 121 |
|
|
// code 6 depending on CPU
|
| 122 |
|
|
#define HAL_MIPS_CACHE_HIT_WRITEBACK_D 0x19 /* 6 1 */
|
| 123 |
|
|
|
| 124 |
|
|
#define HAL_MIPS_CACHE_INDEX_LOAD_DATA_I 0x18 /* 6 0 */
|
| 125 |
|
|
#define HAL_MIPS_CACHE_INDEX_LOAD_DATA_D 0x19 /* 6 1 */
|
| 126 |
|
|
#define HAL_MIPS_CACHE_INDEX_LOAD_DATA_S 0x1b /* 6 3 */
|
| 127 |
|
|
|
| 128 |
|
|
// there seems to be different uses for operation
|
| 129 |
|
|
// code 7 depending on CPU
|
| 130 |
|
|
#define HAL_MIPS_CACHE_FETCH_AND_LOCK_I 0x1c /* 7 0 */
|
| 131 |
|
|
#define HAL_MIPS_CACHE_FETCH_AND_LOCK_D 0x1d /* 7 1 */
|
| 132 |
|
|
|
| 133 |
|
|
#define HAL_MIPS_CACHE_INDEX_STORE_DATA_I 0x1c /* 7 0 */
|
| 134 |
|
|
#define HAL_MIPS_CACHE_INDEX_STORE_DATA_D 0x1d /* 7 1 */
|
| 135 |
|
|
#define HAL_MIPS_CACHE_INDEX_STORE_DATA_S 0x1f /* 7 3 */
|
| 136 |
|
|
|
| 137 |
|
|
|
| 138 |
|
|
//-----------------------------------------------------------------------------
|
| 139 |
|
|
// Cache instruction uses LSBs or MSBs (depending on the
|
| 140 |
|
|
// implementation) of the virtual address to specify which WAY to
|
| 141 |
|
|
// affect. The _ALL_WAYS macro defines the necessary cache instructions
|
| 142 |
|
|
// to affect all ways.
|
| 143 |
|
|
|
| 144 |
|
|
#ifdef HAL_MIPS_CACHE_INSN_USES_LSB
|
| 145 |
|
|
# define _IWAY(_n_) (_n_)
|
| 146 |
|
|
# define _DWAY(_n_) (_n_)
|
| 147 |
|
|
#else
|
| 148 |
|
|
# define _IWAY(_n_) ((_n_)*HAL_ICACHE_SIZE/HAL_ICACHE_WAYS)
|
| 149 |
|
|
# define _DWAY(_n_) ((_n_)*HAL_DCACHE_SIZE/HAL_DCACHE_WAYS)
|
| 150 |
|
|
#endif
|
| 151 |
|
|
|
| 152 |
|
|
#if (HAL_DCACHE_WAYS == 1)
|
| 153 |
|
|
#define _HAL_ASM_DCACHE_ALL_WAYS( _cmd_ , _addr_ ) \
|
| 154 |
|
|
asm volatile ("cache %0,0(%1);" \
|
| 155 |
|
|
: : "I" ((_cmd_) | 1), "r"(_addr_) )
|
| 156 |
|
|
#elif (HAL_DCACHE_WAYS == 2)
|
| 157 |
|
|
#define _HAL_ASM_DCACHE_ALL_WAYS( _cmd_ , _addr_ ) \
|
| 158 |
|
|
asm volatile ("cache %0,0(%1);" \
|
| 159 |
|
|
"cache %0,%2(%1);" \
|
| 160 |
|
|
: : "I" ((_cmd_) | 1), "r"(_addr_), \
|
| 161 |
|
|
"I" (_DWAY(1)))
|
| 162 |
|
|
#elif (HAL_DCACHE_WAYS == 4)
|
| 163 |
|
|
#define _HAL_ASM_DCACHE_ALL_WAYS( _cmd_ , _addr_ ) \
|
| 164 |
|
|
asm volatile ("cache %0,0(%1);" \
|
| 165 |
|
|
"cache %0,%2(%1);" \
|
| 166 |
|
|
"cache %0,%3(%1);" \
|
| 167 |
|
|
"cache %0,%4(%1);" \
|
| 168 |
|
|
: : "I" ((_cmd_) | 1), "r"(_addr_), \
|
| 169 |
|
|
"I" (_DWAY(1)), \
|
| 170 |
|
|
"I" (_DWAY(2)), \
|
| 171 |
|
|
"I" (_DWAY(3)))
|
| 172 |
|
|
#else
|
| 173 |
|
|
# error "Unsupported number of ways"
|
| 174 |
|
|
#endif
|
| 175 |
|
|
|
| 176 |
|
|
#if (HAL_ICACHE_WAYS == 1)
|
| 177 |
|
|
#define _HAL_ASM_ICACHE_ALL_WAYS( _cmd_ , _addr_ ) \
|
| 178 |
|
|
asm volatile ("cache %0,0(%1);" \
|
| 179 |
|
|
: : "I" (_cmd_), "r"(_addr_) )
|
| 180 |
|
|
#elif (HAL_ICACHE_WAYS == 2)
|
| 181 |
|
|
#define _HAL_ASM_ICACHE_ALL_WAYS( _cmd_ , _addr_ ) \
|
| 182 |
|
|
asm volatile ("cache %0,0(%1);" \
|
| 183 |
|
|
"cache %0,%2(%1);" \
|
| 184 |
|
|
: : "I" (_cmd_), "r"(_addr_), \
|
| 185 |
|
|
"I" (_IWAY(1)))
|
| 186 |
|
|
#elif (HAL_ICACHE_WAYS == 4)
|
| 187 |
|
|
#define _HAL_ASM_ICACHE_ALL_WAYS( _cmd_ , _addr_ ) \
|
| 188 |
|
|
asm volatile ("cache %0,0(%1);" \
|
| 189 |
|
|
"cache %0,%2(%1);" \
|
| 190 |
|
|
"cache %0,%3(%1);" \
|
| 191 |
|
|
"cache %0,%4(%1);" \
|
| 192 |
|
|
: : "I" (_cmd_), "r"(_addr_), \
|
| 193 |
|
|
"I" (_IWAY(1)), \
|
| 194 |
|
|
"I" (_IWAY(2)), \
|
| 195 |
|
|
"I" (_IWAY(3)))
|
| 196 |
|
|
#else
|
| 197 |
|
|
# error "Unsupported number of ways"
|
| 198 |
|
|
#endif
|
| 199 |
|
|
|
| 200 |
|
|
//-----------------------------------------------------------------------------
|
| 201 |
|
|
// Address adjustment.
|
| 202 |
|
|
// Given an address and a size, these macros return the first
|
| 203 |
|
|
// cacheline containing the requested range and a terminating address.
|
| 204 |
|
|
|
| 205 |
|
|
#define HAL_DCACHE_START_ADDRESS(_addr_) \
|
| 206 |
|
|
(((CYG_ADDRESS)(_addr_)) & ~(HAL_DCACHE_LINE_SIZE-1))
|
| 207 |
|
|
|
| 208 |
|
|
#define HAL_DCACHE_END_ADDRESS(_addr_, _asize_) \
|
| 209 |
|
|
((CYG_ADDRESS)((_addr_) + (_asize_)))
|
| 210 |
|
|
|
| 211 |
|
|
#define HAL_ICACHE_START_ADDRESS(_addr_) \
|
| 212 |
|
|
(((CYG_ADDRESS)(_addr_)) & ~(HAL_ICACHE_LINE_SIZE-1))
|
| 213 |
|
|
|
| 214 |
|
|
#define HAL_ICACHE_END_ADDRESS(_addr_, _asize_) \
|
| 215 |
|
|
((CYG_ADDRESS)((_addr_) + (_asize_)))
|
| 216 |
|
|
|
| 217 |
|
|
//-----------------------------------------------------------------------------
|
| 218 |
|
|
// Global control of data cache
|
| 219 |
|
|
|
| 220 |
|
|
// Enable the data cache
|
| 221 |
|
|
// There is no default mechanism for enabling or disabling the caches.
|
| 222 |
|
|
#ifndef HAL_DCACHE_ENABLE_DEFINED
|
| 223 |
|
|
#define HAL_DCACHE_ENABLE()
|
| 224 |
|
|
#endif
|
| 225 |
|
|
|
| 226 |
|
|
// Disable the data cache
|
| 227 |
|
|
#ifndef HAL_DCACHE_DISABLE_DEFINED
|
| 228 |
|
|
#define HAL_DCACHE_DISABLE()
|
| 229 |
|
|
#endif
|
| 230 |
|
|
|
| 231 |
|
|
#ifndef HAL_DCACHE_IS_ENABLED_DEFINED
|
| 232 |
|
|
#define HAL_DCACHE_IS_ENABLED(_state_) (_state_) = 1;
|
| 233 |
|
|
#endif
|
| 234 |
|
|
|
| 235 |
|
|
// Invalidate the entire cache
|
| 236 |
|
|
// We simply use HAL_DCACHE_SYNC() to do this. For writeback caches this
|
| 237 |
|
|
// is not quite what we want, but there is no index-invalidate operation
|
| 238 |
|
|
// available.
|
| 239 |
|
|
#ifndef HAL_DCACHE_INVALIDATE_ALL_DEFINED
|
| 240 |
|
|
#define HAL_DCACHE_INVALIDATE_ALL() HAL_DCACHE_SYNC()
|
| 241 |
|
|
#endif
|
| 242 |
|
|
|
| 243 |
|
|
// Synchronize the contents of the cache with memory.
|
| 244 |
|
|
// This uses the index-writeback-invalidate operation.
|
| 245 |
|
|
#ifndef HAL_DCACHE_SYNC_DEFINED
|
| 246 |
|
|
#define HAL_DCACHE_SYNC() \
|
| 247 |
|
|
CYG_MACRO_START \
|
| 248 |
|
|
register CYG_ADDRESS _baddr_ = 0x80000000; \
|
| 249 |
|
|
register CYG_ADDRESS _addr_ = 0x80000000; \
|
| 250 |
|
|
register CYG_WORD _size_ = HAL_DCACHE_SIZE; \
|
| 251 |
|
|
_HAL_ASM_SET_MIPS_ISA(3); \
|
| 252 |
|
|
for( ; _addr_ <= _baddr_+_size_; _addr_ += HAL_DCACHE_LINE_SIZE ) \
|
| 253 |
|
|
{ _HAL_ASM_DCACHE_ALL_WAYS(HAL_MIPS_CACHE_INDEX_WRITEBACK_INV_D, _addr_); } \
|
| 254 |
|
|
_HAL_ASM_SET_MIPS_ISA(0); \
|
| 255 |
|
|
CYG_MACRO_END
|
| 256 |
|
|
#endif
|
| 257 |
|
|
|
| 258 |
|
|
// Set the data cache refill burst size
|
| 259 |
|
|
//#define HAL_DCACHE_BURST_SIZE(_size_)
|
| 260 |
|
|
|
| 261 |
|
|
// Set the data cache write mode
|
| 262 |
|
|
//#define HAL_DCACHE_WRITE_MODE( _mode_ )
|
| 263 |
|
|
|
| 264 |
|
|
//#define HAL_DCACHE_WRITETHRU_MODE 0
|
| 265 |
|
|
//#define HAL_DCACHE_WRITEBACK_MODE 1
|
| 266 |
|
|
|
| 267 |
|
|
// Load the contents of the given address range into the data cache
|
| 268 |
|
|
// and then lock the cache so that it stays there.
|
| 269 |
|
|
// This uses the fetch-and-lock cache operation.
|
| 270 |
|
|
#ifndef HAL_DCACHE_LOCK_DEFINED
|
| 271 |
|
|
#define HAL_DCACHE_LOCK(_base_, _asize_) \
|
| 272 |
|
|
CYG_MACRO_START \
|
| 273 |
|
|
register CYG_ADDRESS _addr_ = HAL_DCACHE_START_ADDRESS(_base_); \
|
| 274 |
|
|
register CYG_ADDRESS _eaddr_ = HAL_DCACHE_END_ADDRESS(_base_, _asize_); \
|
| 275 |
|
|
register CYG_WORD _state_; \
|
| 276 |
|
|
HAL_DCACHE_IS_ENABLED( _state_ ); \
|
| 277 |
|
|
if( _state_ ) { \
|
| 278 |
|
|
_HAL_ASM_SET_MIPS_ISA(3); \
|
| 279 |
|
|
for( ; _addr_ < _eaddr_; _addr_ += HAL_DCACHE_LINE_SIZE ) \
|
| 280 |
|
|
{ _HAL_ASM_DCACHE_ALL_WAYS(HAL_MIPS_CACHE_FETCH_AND_LOCK_D, _addr_); } \
|
| 281 |
|
|
_HAL_ASM_SET_MIPS_ISA(0); \
|
| 282 |
|
|
} \
|
| 283 |
|
|
CYG_MACRO_END
|
| 284 |
|
|
#endif
|
| 285 |
|
|
|
| 286 |
|
|
// Undo a previous lock operation.
|
| 287 |
|
|
// Do this by flushing the cache, which is defined to clear the lock bit.
|
| 288 |
|
|
#ifndef HAL_DCACHE_UNLOCK_DEFINED
|
| 289 |
|
|
#define HAL_DCACHE_UNLOCK(_base_, _size_) \
|
| 290 |
|
|
HAL_DCACHE_FLUSH( _base_, _size_ )
|
| 291 |
|
|
#endif
|
| 292 |
|
|
|
| 293 |
|
|
// Unlock entire cache
|
| 294 |
|
|
#ifndef HAL_DCACHE_UNLOCK_ALL_DEFINED
|
| 295 |
|
|
#define HAL_DCACHE_UNLOCK_ALL() \
|
| 296 |
|
|
HAL_DCACHE_INVALIDATE_ALL()
|
| 297 |
|
|
#endif
|
| 298 |
|
|
|
| 299 |
|
|
//-----------------------------------------------------------------------------
|
| 300 |
|
|
// Data cache line control
|
| 301 |
|
|
|
| 302 |
|
|
// Allocate cache lines for the given address range without reading its
|
| 303 |
|
|
// contents from memory.
|
| 304 |
|
|
//#define HAL_DCACHE_ALLOCATE( _base_ , _size_ )
|
| 305 |
|
|
|
| 306 |
|
|
// Write dirty cache lines to memory and invalidate the cache entries
|
| 307 |
|
|
// for the given address range.
|
| 308 |
|
|
// This uses the hit-writeback-invalidate cache operation.
|
| 309 |
|
|
#ifndef HAL_DCACHE_FLUSH_DEFINED
|
| 310 |
|
|
#define HAL_DCACHE_FLUSH( _base_ , _asize_ ) \
|
| 311 |
|
|
CYG_MACRO_START \
|
| 312 |
|
|
register CYG_ADDRESS _addr_ = HAL_DCACHE_START_ADDRESS(_base_); \
|
| 313 |
|
|
register CYG_ADDRESS _eaddr_ = HAL_DCACHE_END_ADDRESS(_base_, _asize_); \
|
| 314 |
|
|
register CYG_WORD _state_; \
|
| 315 |
|
|
HAL_DCACHE_IS_ENABLED( _state_ ); \
|
| 316 |
|
|
if( _state_ ) { \
|
| 317 |
|
|
_HAL_ASM_SET_MIPS_ISA(3); \
|
| 318 |
|
|
for( ; _addr_ < _eaddr_; _addr_ += HAL_DCACHE_LINE_SIZE ) \
|
| 319 |
|
|
{ _HAL_ASM_DCACHE_ALL_WAYS(HAL_MIPS_CACHE_HIT_WRITEBACK_INV_D, _addr_); } \
|
| 320 |
|
|
_HAL_ASM_SET_MIPS_ISA(0); \
|
| 321 |
|
|
} \
|
| 322 |
|
|
CYG_MACRO_END
|
| 323 |
|
|
#endif
|
| 324 |
|
|
|
| 325 |
|
|
// Invalidate cache lines in the given range without writing to memory.
|
| 326 |
|
|
// This uses the hit-invalidate cache operation.
|
| 327 |
|
|
#ifndef HAL_DCACHE_INVALIDATE_DEFINED
|
| 328 |
|
|
#define HAL_DCACHE_INVALIDATE( _base_ , _asize_ ) \
|
| 329 |
|
|
CYG_MACRO_START \
|
| 330 |
|
|
register CYG_ADDRESS _addr_ = HAL_DCACHE_START_ADDRESS(_base_); \
|
| 331 |
|
|
register CYG_ADDRESS _eaddr_ = HAL_DCACHE_END_ADDRESS(_base_, _asize_); \
|
| 332 |
|
|
_HAL_ASM_SET_MIPS_ISA(3); \
|
| 333 |
|
|
for( ; _addr_ < _eaddr_; _addr_ += HAL_DCACHE_LINE_SIZE ) \
|
| 334 |
|
|
{ _HAL_ASM_DCACHE_ALL_WAYS(HAL_MIPS_CACHE_HIT_INVALIDATE_D, _addr_); } \
|
| 335 |
|
|
_HAL_ASM_SET_MIPS_ISA(0); \
|
| 336 |
|
|
CYG_MACRO_END
|
| 337 |
|
|
#endif
|
| 338 |
|
|
|
| 339 |
|
|
// Write dirty cache lines to memory for the given address range.
|
| 340 |
|
|
// This uses the hit-writeback cache operation.
|
| 341 |
|
|
#ifndef HAL_DCACHE_STORE_DEFINED
|
| 342 |
|
|
#define HAL_DCACHE_STORE( _base_ , _asize_ ) \
|
| 343 |
|
|
CYG_MACRO_START \
|
| 344 |
|
|
register CYG_ADDRESS _addr_ = HAL_DCACHE_START_ADDRESS(_base_); \
|
| 345 |
|
|
register CYG_ADDRESS _eaddr_ = HAL_DCACHE_END_ADDRESS(_base_, _asize_); \
|
| 346 |
|
|
register CYG_WORD _state_; \
|
| 347 |
|
|
HAL_DCACHE_IS_ENABLED( _state_ ); \
|
| 348 |
|
|
if( _state_ ) { \
|
| 349 |
|
|
_HAL_ASM_SET_MIPS_ISA(3); \
|
| 350 |
|
|
for( ; _addr_ < _eaddr_; _addr_ += HAL_DCACHE_LINE_SIZE ) \
|
| 351 |
|
|
{ _HAL_ASM_DCACHE_ALL_WAYS(HAL_MIPS_CACHE_HIT_WRITEBACK_D, _addr_); } \
|
| 352 |
|
|
_HAL_ASM_SET_MIPS_ISA(0); \
|
| 353 |
|
|
} \
|
| 354 |
|
|
CYG_MACRO_END
|
| 355 |
|
|
#endif
|
| 356 |
|
|
|
| 357 |
|
|
// Preread the given range into the cache with the intention of reading
|
| 358 |
|
|
// from it later.
|
| 359 |
|
|
//#define HAL_DCACHE_READ_HINT( _base_ , _size_ )
|
| 360 |
|
|
|
| 361 |
|
|
// Preread the given range into the cache with the intention of writing
|
| 362 |
|
|
// to it later.
|
| 363 |
|
|
//#define HAL_DCACHE_WRITE_HINT( _base_ , _size_ )
|
| 364 |
|
|
|
| 365 |
|
|
// Allocate and zero the cache lines associated with the given range.
|
| 366 |
|
|
//#define HAL_DCACHE_ZERO( _base_ , _size_ )
|
| 367 |
|
|
|
| 368 |
|
|
//-----------------------------------------------------------------------------
|
| 369 |
|
|
// Global control of Instruction cache
|
| 370 |
|
|
|
| 371 |
|
|
// Enable the instruction cache
|
| 372 |
|
|
// There is no default mechanism for enabling or disabling the caches.
|
| 373 |
|
|
#ifndef HAL_ICACHE_ENABLE_DEFINED
|
| 374 |
|
|
#define HAL_ICACHE_ENABLE()
|
| 375 |
|
|
#endif
|
| 376 |
|
|
|
| 377 |
|
|
// Disable the instruction cache
|
| 378 |
|
|
#ifndef HAL_ICACHE_DISABLE_DEFINED
|
| 379 |
|
|
#define HAL_ICACHE_DISABLE()
|
| 380 |
|
|
#endif
|
| 381 |
|
|
|
| 382 |
|
|
#ifndef HAL_ICACHE_IS_ENABLED_DEFINED
|
| 383 |
|
|
#define HAL_ICACHE_IS_ENABLED(_state_) (_state_) = 1;
|
| 384 |
|
|
#endif
|
| 385 |
|
|
|
| 386 |
|
|
// Invalidate the entire cache
|
| 387 |
|
|
// This uses the index-invalidate cache operation.
|
| 388 |
|
|
#ifndef HAL_ICACHE_INVALIDATE_ALL_DEFINED
|
| 389 |
|
|
#define HAL_ICACHE_INVALIDATE_ALL() \
|
| 390 |
|
|
CYG_MACRO_START \
|
| 391 |
|
|
register CYG_ADDRESS _baddr_ = 0x80000000; \
|
| 392 |
|
|
register CYG_ADDRESS _addr_ = 0x80000000; \
|
| 393 |
|
|
_HAL_ASM_SET_MIPS_ISA(3); \
|
| 394 |
|
|
for( ; _addr_ < _baddr_+HAL_ICACHE_SIZE; _addr_ += HAL_ICACHE_LINE_SIZE ) \
|
| 395 |
|
|
{ _HAL_ASM_ICACHE_ALL_WAYS(HAL_MIPS_CACHE_INDEX_INVALIDATE_I, _addr_); } \
|
| 396 |
|
|
_HAL_ASM_SET_MIPS_ISA(0); \
|
| 397 |
|
|
CYG_MACRO_END
|
| 398 |
|
|
#endif
|
| 399 |
|
|
|
| 400 |
|
|
// Synchronize the contents of the cache with memory.
|
| 401 |
|
|
// Simply force the cache to reload.
|
| 402 |
|
|
#ifndef HAL_ICACHE_SYNC_DEFINED
|
| 403 |
|
|
#define HAL_ICACHE_SYNC() HAL_ICACHE_INVALIDATE_ALL()
|
| 404 |
|
|
#endif
|
| 405 |
|
|
|
| 406 |
|
|
// Set the instruction cache refill burst size
|
| 407 |
|
|
//#define HAL_ICACHE_BURST_SIZE(_size_)
|
| 408 |
|
|
|
| 409 |
|
|
// Load the contents of the given address range into the instruction cache
|
| 410 |
|
|
// and then lock the cache so that it stays there.
|
| 411 |
|
|
// This uses the fetch-and-lock cache operation.
|
| 412 |
|
|
#ifndef HAL_ICACHE_LOCK_DEFINED
|
| 413 |
|
|
#define HAL_ICACHE_LOCK(_base_, _asize_) \
|
| 414 |
|
|
CYG_MACRO_START \
|
| 415 |
|
|
register CYG_ADDRESS _addr_ = HAL_ICACHE_START_ADDRESS(_base_); \
|
| 416 |
|
|
register CYG_ADDRESS _eaddr_ = HAL_ICACHE_END_ADDRESS(_base_, _asize_); \
|
| 417 |
|
|
register CYG_WORD _state_; \
|
| 418 |
|
|
HAL_ICACHE_IS_ENABLED( _state_ ); \
|
| 419 |
|
|
if( _state_ ) { \
|
| 420 |
|
|
_HAL_ASM_SET_MIPS_ISA(3); \
|
| 421 |
|
|
for( ; _addr_ < _eaddr_; _addr_ += HAL_ICACHE_LINE_SIZE ) \
|
| 422 |
|
|
{ _HAL_ASM_ICACHE_ALL_WAYS(HAL_MIPS_CACHE_FETCH_AND_LOCK_I, _addr_); } \
|
| 423 |
|
|
_HAL_ASM_SET_MIPS_ISA(0); \
|
| 424 |
|
|
} \
|
| 425 |
|
|
CYG_MACRO_END
|
| 426 |
|
|
#endif
|
| 427 |
|
|
|
| 428 |
|
|
// Undo a previous lock operation.
|
| 429 |
|
|
// Do this by invalidating the cache, which is defined to clear the lock bit.
|
| 430 |
|
|
#ifndef HAL_ICACHE_UNLOCK_DEFINED
|
| 431 |
|
|
#define HAL_ICACHE_UNLOCK(_base_, _size_) \
|
| 432 |
|
|
HAL_ICACHE_INVALIDATE( _base_, _size_ )
|
| 433 |
|
|
#endif
|
| 434 |
|
|
|
| 435 |
|
|
// Unlock entire cache
|
| 436 |
|
|
//#define HAL_ICACHE_UNLOCK_ALL()
|
| 437 |
|
|
|
| 438 |
|
|
//-----------------------------------------------------------------------------
|
| 439 |
|
|
// Instruction cache line control
|
| 440 |
|
|
|
| 441 |
|
|
// Invalidate cache lines in the given range without writing to memory.
|
| 442 |
|
|
// This uses the hit-invalidate cache operation.
|
| 443 |
|
|
#ifndef HAL_ICACHE_INVALIDATE_DEFINED
|
| 444 |
|
|
#define HAL_ICACHE_INVALIDATE( _base_ , _asize_ ) \
|
| 445 |
|
|
CYG_MACRO_START \
|
| 446 |
|
|
register CYG_ADDRESS _addr_ = HAL_ICACHE_START_ADDRESS(_base_); \
|
| 447 |
|
|
register CYG_ADDRESS _eaddr_ = HAL_ICACHE_END_ADDRESS(_base_, _asize_); \
|
| 448 |
|
|
_HAL_ASM_SET_MIPS_ISA(3); \
|
| 449 |
|
|
for( ; _addr_ < _eaddr_; _addr_ += HAL_ICACHE_LINE_SIZE ) \
|
| 450 |
|
|
{ _HAL_ASM_ICACHE_ALL_WAYS(HAL_MIPS_CACHE_HIT_INVALIDATE_I, _addr_); } \
|
| 451 |
|
|
_HAL_ASM_SET_MIPS_ISA(0); \
|
| 452 |
|
|
CYG_MACRO_END
|
| 453 |
|
|
#endif
|
| 454 |
|
|
|
| 455 |
|
|
//-----------------------------------------------------------------------------
|
| 456 |
|
|
// Check that a supported configuration has actually defined some macros.
|
| 457 |
|
|
|
| 458 |
|
|
#ifndef HAL_DCACHE_ENABLE
|
| 459 |
|
|
|
| 460 |
|
|
#error Unsupported MIPS configuration
|
| 461 |
|
|
|
| 462 |
|
|
#endif
|
| 463 |
|
|
|
| 464 |
|
|
//-----------------------------------------------------------------------------
|
| 465 |
|
|
#endif // ifndef CYGONCE_HAL_CACHE_H
|
| 466 |
|
|
// End of hal_cache.h
|