1 |
27 |
unneback |
#ifndef CYGONCE_VAR_CACHE_H
|
2 |
|
|
#define CYGONCE_VAR_CACHE_H
|
3 |
|
|
//=============================================================================
|
4 |
|
|
//
|
5 |
|
|
// var_cache.h
|
6 |
|
|
//
|
7 |
|
|
// Variant 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 Red Hat, 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 version.
|
18 |
|
|
//
|
19 |
|
|
// eCos is distributed in the hope that it will be useful, but WITHOUT ANY
|
20 |
|
|
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
21 |
|
|
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
22 |
|
|
// for more details.
|
23 |
|
|
//
|
24 |
|
|
// You should have received a copy of the GNU General Public License along
|
25 |
|
|
// with eCos; if not, write to the Free Software Foundation, Inc.,
|
26 |
|
|
// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
|
27 |
|
|
//
|
28 |
|
|
// As a special exception, if other files instantiate templates or use macros
|
29 |
|
|
// or inline functions from this file, or you compile this file and link it
|
30 |
|
|
// with other works to produce a work based on this file, this file does not
|
31 |
|
|
// by itself cause the resulting work to be covered by the GNU General Public
|
32 |
|
|
// License. However the source code for this file must still be made available
|
33 |
|
|
// in accordance with section (3) of the GNU General Public License.
|
34 |
|
|
//
|
35 |
|
|
// This exception does not invalidate any other reasons why a work based on
|
36 |
|
|
// this file might be covered by the GNU General Public License.
|
37 |
|
|
//
|
38 |
|
|
// Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.
|
39 |
|
|
// at http://sources.redhat.com/ecos/ecos-license/
|
40 |
|
|
// -------------------------------------------
|
41 |
|
|
//####ECOSGPLCOPYRIGHTEND####
|
42 |
|
|
//=============================================================================
|
43 |
|
|
//#####DESCRIPTIONBEGIN####
|
44 |
|
|
//
|
45 |
|
|
// Author(s): nickg
|
46 |
|
|
// Contributors:nickg, jskov
|
47 |
|
|
// Date: 2000-04-02
|
48 |
|
|
// Purpose: Variant cache control API
|
49 |
|
|
// Description: The macros defined here provide the HAL APIs for handling
|
50 |
|
|
// cache control operations on the SH variant CPUs.
|
51 |
|
|
// Usage: Is included via the architecture cache header:
|
52 |
|
|
// #include <cyg/hal/hal_cache.h>
|
53 |
|
|
// ...
|
54 |
|
|
//
|
55 |
|
|
//####DESCRIPTIONEND####
|
56 |
|
|
//
|
57 |
|
|
//=============================================================================
|
58 |
|
|
|
59 |
|
|
#include <pkgconf/hal.h>
|
60 |
|
|
|
61 |
|
|
#include <cyg/hal/sh_regs.h>
|
62 |
|
|
|
63 |
|
|
#include <cyg/hal/plf_cache.h>
|
64 |
|
|
|
65 |
|
|
#include <cyg/hal/hal_io.h>
|
66 |
|
|
|
67 |
|
|
//=============================================================================
|
68 |
|
|
|
69 |
|
|
#ifndef HAL_DCACHE_DEFINED
|
70 |
|
|
|
71 |
|
|
#define HAL_DCACHE_SIZE CYGARC_SH_MOD_CAC_D_SIZE
|
72 |
|
|
#define HAL_DCACHE_LINE_SIZE CYGARC_SH_MOD_CAC_D_LINE_SIZE
|
73 |
|
|
#define HAL_DCACHE_WAYS CYGARC_SH_MOD_CAC_D_WAYS
|
74 |
|
|
#define HAL_DCACHE_SETS (HAL_DCACHE_SIZE/(HAL_DCACHE_LINE_SIZE*HAL_DCACHE_WAYS))
|
75 |
|
|
|
76 |
|
|
// Cache addressing information
|
77 |
|
|
#define CYGARC_REG_DCACHE_ADDRESS_BASE CYGARC_SH_MOD_DCAC_ADDRESS_BASE
|
78 |
|
|
#define CYGARC_REG_DCACHE_ADDRESS_TOP CYGARC_SH_MOD_DCAC_ADDRESS_TOP
|
79 |
|
|
#define CYGARC_REG_DCACHE_ADDRESS_STEP CYGARC_SH_MOD_DCAC_ADDRESS_STEP
|
80 |
|
|
#define CYGARC_REG_DCACHE_ADDRESS_FLUSH CYGARC_SH_MOD_DCAC_ADDRESS_FLUSH
|
81 |
|
|
|
82 |
|
|
#define HAL_DCACHE_DEFINED
|
83 |
|
|
#endif
|
84 |
|
|
|
85 |
|
|
#ifndef HAL_ICACHE_DEFINED
|
86 |
|
|
|
87 |
|
|
#define HAL_ICACHE_SIZE CYGARC_SH_MOD_CAC_I_SIZE
|
88 |
|
|
#define HAL_ICACHE_LINE_SIZE CYGARC_SH_MOD_CAC_I_LINE_SIZE
|
89 |
|
|
#define HAL_ICACHE_WAYS CYGARC_SH_MOD_CAC_I_WAYS
|
90 |
|
|
#define HAL_ICACHE_SETS (HAL_ICACHE_SIZE/(HAL_ICACHE_LINE_SIZE*HAL_ICACHE_WAYS))
|
91 |
|
|
|
92 |
|
|
// Cache addressing information
|
93 |
|
|
#define CYGARC_REG_ICACHE_ADDRESS_BASE CYGARC_SH_MOD_ICAC_ADDRESS_BASE
|
94 |
|
|
#define CYGARC_REG_ICACHE_ADDRESS_TOP CYGARC_SH_MOD_ICAC_ADDRESS_TOP
|
95 |
|
|
#define CYGARC_REG_ICACHE_ADDRESS_STEP CYGARC_SH_MOD_ICAC_ADDRESS_STEP
|
96 |
|
|
#define CYGARC_REG_ICACHE_ADDRESS_FLUSH CYGARC_SH_MOD_ICAC_ADDRESS_FLUSH
|
97 |
|
|
|
98 |
|
|
#define HAL_ICACHE_DEFINED
|
99 |
|
|
#endif
|
100 |
|
|
|
101 |
|
|
|
102 |
|
|
//-----------------------------------------------------------------------------
|
103 |
|
|
// Global control of cache
|
104 |
|
|
|
105 |
|
|
// This is all handled in assembly (see variant.S) due to a requirement about
|
106 |
|
|
// not fiddling the cache from cachable memory.
|
107 |
|
|
|
108 |
|
|
externC void cyg_hal_dcache_enable(void);
|
109 |
|
|
externC void cyg_hal_dcache_disable(void);
|
110 |
|
|
externC void cyg_hal_dcache_invalidate_all(void);
|
111 |
|
|
externC void cyg_hal_dcache_sync(void);
|
112 |
|
|
externC void cyg_hal_dcache_sync_region(cyg_haladdress base,
|
113 |
|
|
cyg_haladdrword len);
|
114 |
|
|
externC void cyg_hal_dcache_write_mode(int mode);
|
115 |
|
|
|
116 |
|
|
// Enable the cache
|
117 |
|
|
#define HAL_DCACHE_ENABLE() cyg_hal_dcache_enable()
|
118 |
|
|
|
119 |
|
|
// Disable the cache
|
120 |
|
|
#define HAL_DCACHE_DISABLE() cyg_hal_dcache_disable()
|
121 |
|
|
|
122 |
|
|
// Invalidate the entire cache
|
123 |
|
|
#define HAL_DCACHE_INVALIDATE_ALL() cyg_hal_dcache_invalidate_all()
|
124 |
|
|
|
125 |
|
|
// Synchronize the contents of the cache with memory.
|
126 |
|
|
#define HAL_DCACHE_SYNC() cyg_hal_dcache_sync()
|
127 |
|
|
|
128 |
|
|
// Query the state of the cache (does not affect the caching)
|
129 |
|
|
#define HAL_DCACHE_IS_ENABLED(_state_) \
|
130 |
|
|
CYG_MACRO_START \
|
131 |
|
|
cyg_uint32 _tmp; \
|
132 |
|
|
HAL_READ_UINT32(CYGARC_REG_CCR, _tmp); \
|
133 |
|
|
(_state_) = (_tmp & CYGARC_REG_CCR_OCE) ? 1 : 0; \
|
134 |
|
|
CYG_MACRO_END
|
135 |
|
|
|
136 |
|
|
// Set the cache refill burst size
|
137 |
|
|
//#define HAL_ICACHE_BURST_SIZE(_size_)
|
138 |
|
|
|
139 |
|
|
// Set the cache write mode
|
140 |
|
|
#define HAL_DCACHE_WRITE_MODE( _mode_ ) \
|
141 |
|
|
CYG_MACRO_START \
|
142 |
|
|
cyg_uint32 _m_; \
|
143 |
|
|
if (HAL_DCACHE_WRITETHRU_MODE == _mode_) \
|
144 |
|
|
_m_ = CYGARC_REG_CCR_WT; \
|
145 |
|
|
else \
|
146 |
|
|
_m_ = CYGARC_REG_CCR_CB; \
|
147 |
|
|
cyg_hal_dcache_write_mode(_m_); \
|
148 |
|
|
CYG_MACRO_END
|
149 |
|
|
|
150 |
|
|
#define HAL_DCACHE_WRITETHRU_MODE 0
|
151 |
|
|
#define HAL_DCACHE_WRITEBACK_MODE 1
|
152 |
|
|
|
153 |
|
|
// This macro allows the client to specify separate modes for the two
|
154 |
|
|
// regions.
|
155 |
|
|
#define HAL_DCACHE_WRITE_MODE_SH( _mode_ ) cyg_hal_dcache_write_mode(_mode_)
|
156 |
|
|
|
157 |
|
|
// Load the contents of the given address range into the cache
|
158 |
|
|
// and then lock the cache so that it stays there.
|
159 |
|
|
//#define HAL_DCACHE_LOCK(_base_, _size_)
|
160 |
|
|
|
161 |
|
|
// Undo a previous lock operation
|
162 |
|
|
//#define HAL_DCACHE_UNLOCK(_base_, _size_)
|
163 |
|
|
|
164 |
|
|
// Unlock entire cache
|
165 |
|
|
//#define HAL_DCACHE_UNLOCK_ALL()
|
166 |
|
|
|
167 |
|
|
//-----------------------------------------------------------------------------
|
168 |
|
|
// Cache line control
|
169 |
|
|
|
170 |
|
|
// Allocate cache lines for the given address range without reading its
|
171 |
|
|
// contents from memory.
|
172 |
|
|
//#define HAL_DCACHE_ALLOCATE( _base_ , _size_ )
|
173 |
|
|
|
174 |
|
|
// Write dirty cache lines to memory and invalidate the cache entries
|
175 |
|
|
// for the given address range.
|
176 |
|
|
#define HAL_DCACHE_FLUSH( _base_ , _size_ ) \
|
177 |
|
|
cyg_hal_dcache_sync_region((cyg_haladdress)_base_, (cyg_haladdrword)_size_)
|
178 |
|
|
|
179 |
|
|
// Invalidate cache lines in the given range without writing to memory.
|
180 |
|
|
//#define HAL_DCACHE_INVALIDATE( _base_ , _size_ )
|
181 |
|
|
|
182 |
|
|
// Write dirty cache lines to memory for the given address range.
|
183 |
|
|
//#define HAL_DCACHE_STORE( _base_ , _size_ )
|
184 |
|
|
|
185 |
|
|
|
186 |
|
|
// Preread the given range into the cache with the intention of reading
|
187 |
|
|
// from it later.
|
188 |
|
|
//#define HAL_DCACHE_READ_HINT( _base_ , _size_ )
|
189 |
|
|
|
190 |
|
|
// Preread the given range into the cache with the intention of writing
|
191 |
|
|
// to it later.
|
192 |
|
|
//#define HAL_DCACHE_WRITE_HINT( _base_ , _size_ )
|
193 |
|
|
|
194 |
|
|
// Allocate and zero the cache lines associated with the given range.
|
195 |
|
|
//#define HAL_DCACHE_ZERO( _base_ , _size_ )
|
196 |
|
|
|
197 |
|
|
|
198 |
|
|
//-----------------------------------------------------------------------------
|
199 |
|
|
// Global control of Instruction cache
|
200 |
|
|
|
201 |
|
|
externC void cyg_hal_icache_enable(void);
|
202 |
|
|
externC void cyg_hal_icache_disable(void);
|
203 |
|
|
externC void cyg_hal_icache_invalidate_all(void);
|
204 |
|
|
|
205 |
|
|
// Enable the cache
|
206 |
|
|
#define HAL_ICACHE_ENABLE() cyg_hal_icache_enable()
|
207 |
|
|
|
208 |
|
|
// Disable the cache
|
209 |
|
|
#define HAL_ICACHE_DISABLE() cyg_hal_icache_disable()
|
210 |
|
|
|
211 |
|
|
// Invalidate the entire cache
|
212 |
|
|
#define HAL_ICACHE_INVALIDATE_ALL() cyg_hal_icache_invalidate_all()
|
213 |
|
|
|
214 |
|
|
// Synchronize the contents of the cache with memory.
|
215 |
|
|
#define HAL_ICACHE_SYNC() HAL_ICACHE_INVALIDATE_ALL()
|
216 |
|
|
|
217 |
|
|
// Query the state of the cache (does not affect the caching)
|
218 |
|
|
#define HAL_ICACHE_IS_ENABLED(_state_) \
|
219 |
|
|
CYG_MACRO_START \
|
220 |
|
|
cyg_uint32 _tmp; \
|
221 |
|
|
HAL_READ_UINT32(CYGARC_REG_CCR, _tmp); \
|
222 |
|
|
(_state_) = (_tmp & CYGARC_REG_CCR_ICE) ? 1 : 0; \
|
223 |
|
|
CYG_MACRO_END
|
224 |
|
|
|
225 |
|
|
// Set the instruction cache refill burst size
|
226 |
|
|
//#define HAL_ICACHE_BURST_SIZE(_size_)
|
227 |
|
|
|
228 |
|
|
// Load the contents of the given address range into the instruction cache
|
229 |
|
|
// and then lock the cache so that it stays there.
|
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 |
|
|
//-----------------------------------------------------------------------------
|
240 |
|
|
// Instruction cache line control
|
241 |
|
|
|
242 |
|
|
// Invalidate cache lines in the given range without writing to memory.
|
243 |
|
|
//#define HAL_ICACHE_INVALIDATE( _base_ , _size_ )
|
244 |
|
|
|
245 |
|
|
//-----------------------------------------------------------------------------
|
246 |
|
|
// Flash related cache macros
|
247 |
|
|
|
248 |
|
|
#define HAL_FLASH_CACHES_OFF(_d_, _i_) \
|
249 |
|
|
CYG_MACRO_START \
|
250 |
|
|
HAL_ICACHE_IS_ENABLED(_i_); \
|
251 |
|
|
HAL_DCACHE_IS_ENABLED(_d_); \
|
252 |
|
|
HAL_DCACHE_SYNC(); \
|
253 |
|
|
HAL_DCACHE_INVALIDATE_ALL(); \
|
254 |
|
|
HAL_DCACHE_DISABLE(); \
|
255 |
|
|
HAL_ICACHE_INVALIDATE_ALL(); \
|
256 |
|
|
HAL_ICACHE_DISABLE(); \
|
257 |
|
|
CYG_MACRO_END
|
258 |
|
|
|
259 |
|
|
#define HAL_FLASH_CACHES_ON(_d_, _i_) \
|
260 |
|
|
CYG_MACRO_START \
|
261 |
|
|
if (_d_) HAL_DCACHE_ENABLE(); \
|
262 |
|
|
if (_i_) HAL_ICACHE_ENABLE(); \
|
263 |
|
|
CYG_MACRO_END
|
264 |
|
|
|
265 |
|
|
//-----------------------------------------------------------------------------
|
266 |
|
|
#endif // ifndef CYGONCE_VAR_CACHE_H
|
267 |
|
|
// End of var_cache.h
|