OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [packages/] [hal/] [sh/] [sh4/] [current/] [include/] [var_cache.h] - Blame information for rev 786

Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.