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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [packages/] [hal/] [mn10300/] [am31/] [current/] [include/] [var_cache.h] - Blame information for rev 856

Go to most recent revision | 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
//
6
//      var_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/var_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/plf_cache.h>
64
 
65
//=============================================================================
66
// MN103002 implementation
67
 
68
//-----------------------------------------------------------------------------
69
// Cache dimensions
70
 
71
 
72
// Data cache
73
#define HAL_DCACHE_SIZE                 4096    // Size of data cache in bytes
74
#define HAL_DCACHE_LINE_SIZE            16      // Size of a data cache line
75
#define HAL_DCACHE_WAYS                 2       // Associativity of the cache
76
 
77
// Instruction cache
78
#define HAL_ICACHE_SIZE                 4096    // Size of cache in bytes
79
#define HAL_ICACHE_LINE_SIZE            16      // Size of a cache line
80
#define HAL_ICACHE_WAYS                 2       // Associativity of the cache
81
 
82
#define HAL_DCACHE_SETS (HAL_DCACHE_SIZE/(HAL_DCACHE_LINE_SIZE*HAL_DCACHE_WAYS))
83
#define HAL_ICACHE_SETS (HAL_ICACHE_SIZE/(HAL_ICACHE_LINE_SIZE*HAL_ICACHE_WAYS))
84
 
85
//-----------------------------------------------------------------------------
86
// Control registers
87
 
88
#define HAL_CHCTR               ((volatile CYG_ADDRWORD *)0x20000070)
89
 
90
#define HAL_CHCTR_ICEN          0x0001
91
#define HAL_CHCTR_DCEN          0x0002
92
#define HAL_CHCTR_ICBUSY        0x0004
93
#define HAL_CHCTR_DCBUSY        0x0008
94
#define HAL_CHCTR_ICINV         0x0010
95
#define HAL_CHCTR_DCINV         0x0020
96
#define HAL_CHCTR_DCWTMD        0x0040
97
#define HAL_CHCTR_ICWMD         0x0300
98
#define HAL_CHCTR_DCWMD         0x3000
99
 
100
#define HAL_DCACHE_PURGE_WAY0   ((volatile CYG_BYTE *)0x28400000)
101
#define HAL_DCACHE_PURGE_WAY1   ((volatile CYG_BYTE *)0x28401000)
102
 
103
//-----------------------------------------------------------------------------
104
// Global control of data cache
105
 
106
// Enable the data cache
107
#define HAL_DCACHE_ENABLE()                     \
108
{                                               \
109
    register CYG_ADDRWORD chctr = *HAL_CHCTR;   \
110
    chctr |= HAL_CHCTR_DCEN;                    \
111
    *HAL_CHCTR = chctr;                         \
112
}
113
 
114
// Disable the data cache
115
#define HAL_DCACHE_DISABLE()                    \
116
{                                               \
117
    register CYG_ADDRWORD chctr = *HAL_CHCTR;   \
118
    chctr &= ~HAL_CHCTR_DCEN;                   \
119
    *HAL_CHCTR = chctr;                         \
120
    while( HAL_CHCTR_DCBUSY & *HAL_CHCTR );     \
121
}
122
 
123
// Query the state of the data cache
124
#define HAL_DCACHE_IS_ENABLED(_state_)          \
125
{                                               \
126
    register CYG_ADDRWORD chctr = *HAL_CHCTR;   \
127
    _state_ = (0 != (chctr & HAL_CHCTR_DCEN));  \
128
}
129
 
130
// Invalidate the entire cache
131
#define HAL_DCACHE_INVALIDATE_ALL()             \
132
{                                               \
133
    register CYG_ADDRWORD chctr;                \
134
    register CYG_ADDRWORD state;                \
135
    HAL_DCACHE_IS_ENABLED(state);               \
136
    if (state)                                  \
137
        HAL_DCACHE_DISABLE();                   \
138
    chctr = *HAL_CHCTR;                         \
139
    chctr |= HAL_CHCTR_DCINV;                   \
140
    *HAL_CHCTR = chctr;                         \
141
    while( HAL_CHCTR_DCBUSY & *HAL_CHCTR );     \
142
    if (state)                                  \
143
        HAL_DCACHE_ENABLE();                    \
144
}
145
 
146
// Synchronize the contents of the cache with memory.
147
#define HAL_DCACHE_SYNC() HAL_DCACHE_STORE( 0, HAL_DCACHE_SIZE/HAL_DCACHE_WAYS )
148
 
149
// Set the data cache refill burst size
150
//#define HAL_DCACHE_BURST_SIZE(_size_)
151
 
152
// Set the data cache write mode
153
#define HAL_DCACHE_WRITE_MODE( _mode_ )         \
154
{                                               \
155
    register CYG_ADDRWORD chctr;                \
156
    register CYG_ADDRWORD state;                \
157
    HAL_DCACHE_IS_ENABLED(state);               \
158
    if (state)                                  \
159
        HAL_DCACHE_DISABLE();                   \
160
    chctr = *HAL_CHCTR;                         \
161
    chctr |= HAL_CHCTR_DCWTMD*(_mode_);         \
162
    *HAL_CHCTR = chctr;                         \
163
    while( HAL_CHCTR_DCBUSY & *HAL_CHCTR );     \
164
    if (state)                                  \
165
        HAL_DCACHE_ENABLE();                    \
166
}
167
 
168
#define HAL_DCACHE_WRITEBACK_MODE       0
169
#define HAL_DCACHE_WRITETHRU_MODE       1
170
 
171
// Load the contents of the given address range into the data cache
172
// and then lock the cache so that it stays there.
173
//#define HAL_DCACHE_LOCK(_base_, _size_)
174
 
175
// Undo a previous lock operation
176
//#define HAL_DCACHE_UNLOCK(_base_, _size_)
177
 
178
// Unlock entire cache
179
//#define HAL_DCACHE_UNLOCK_ALL()
180
 
181
//-----------------------------------------------------------------------------
182
// Data cache line control
183
 
184
// Allocate cache lines for the given address range without reading its
185
// contents from memory.
186
//#define HAL_DCACHE_ALLOCATE( _base_ , _size_ )
187
 
188
// Write dirty cache lines to memory and invalidate the cache entries
189
// for the given address range.
190
//#define HAL_DCACHE_FLUSH( _base_ , _size_ )
191
 
192
// Invalidate cache lines in the given range without writing to memory.
193
//#define HAL_DCACHE_INVALIDATE( _base_ , _size_ )
194
 
195
// Write dirty cache lines to memory for the given address range.
196
 
197
// This functionality requires 4 register variables. To prevent register
198
// spilling, put the code in a separate function.
199
externC void cyg_hal_dcache_store(CYG_ADDRWORD base, int size);
200
 
201
#define HAL_DCACHE_STORE( _base_ , _size_ ) \
202
    cyg_hal_dcache_store((CYG_ADDRWORD)(_base_), (int)(_size_))
203
 
204
// Preread the given range into the cache with the intention of reading
205
// from it later.
206
//#define HAL_DCACHE_READ_HINT( _base_ , _size_ )
207
 
208
// Preread the given range into the cache with the intention of writing
209
// to it later.
210
//#define HAL_DCACHE_WRITE_HINT( _base_ , _size_ )
211
 
212
// Allocate and zero the cache lines associated with the given range.
213
//#define HAL_DCACHE_ZERO( _base_ , _size_ )
214
 
215
//-----------------------------------------------------------------------------
216
// Global control of Instruction cache
217
 
218
// Enable the instruction cache
219
#define HAL_ICACHE_ENABLE()                     \
220
{                                               \
221
    register CYG_ADDRWORD chctr = *HAL_CHCTR;   \
222
    chctr |= HAL_CHCTR_ICEN;                    \
223
    *HAL_CHCTR = chctr;                         \
224
}
225
 
226
// Disable the instruction cache
227
#define HAL_ICACHE_DISABLE()                    \
228
{                                               \
229
    register CYG_ADDRWORD chctr = *HAL_CHCTR;   \
230
    chctr &= ~HAL_CHCTR_ICEN;                   \
231
    *HAL_CHCTR = chctr;                         \
232
    while( HAL_CHCTR_ICBUSY & *HAL_CHCTR );     \
233
}
234
 
235
// Query the state of the instruction cache
236
#define HAL_ICACHE_IS_ENABLED(_state_)          \
237
{                                               \
238
    register CYG_ADDRWORD chctr = *HAL_CHCTR;   \
239
    _state_ = (0 != (chctr & HAL_CHCTR_ICEN));  \
240
}
241
 
242
// Invalidate the entire cache
243
#define HAL_ICACHE_INVALIDATE_ALL()             \
244
{                                               \
245
    register CYG_ADDRWORD chctr;                \
246
    register CYG_ADDRWORD state;                \
247
    HAL_ICACHE_IS_ENABLED(state);               \
248
    if (state)                                  \
249
        HAL_ICACHE_DISABLE();                   \
250
    chctr = *HAL_CHCTR;                         \
251
    chctr |= HAL_CHCTR_ICINV;                   \
252
    *HAL_CHCTR = chctr;                         \
253
    while( HAL_CHCTR_ICBUSY & *HAL_CHCTR );     \
254
    if (state)                                  \
255
        HAL_ICACHE_ENABLE();                    \
256
}
257
 
258
// Synchronize the contents of the cache with memory.
259
#define HAL_ICACHE_SYNC()
260
 
261
// Set the instruction cache refill burst size
262
//#define HAL_ICACHE_BURST_SIZE(_size_)
263
 
264
// Load the contents of the given address range into the instruction cache
265
// and then lock the cache so that it stays there.
266
//#define HAL_ICACHE_LOCK(_base_, _size_)
267
 
268
// Undo a previous lock operation
269
//#define HAL_ICACHE_UNLOCK(_base_, _size_)
270
 
271
// Unlock entire cache
272
//#define HAL_ICACHE_UNLOCK_ALL()
273
 
274
//-----------------------------------------------------------------------------
275
// Instruction cache line control
276
 
277
// Invalidate cache lines in the given range without writing to memory.
278
//#define HAL_ICACHE_INVALIDATE( _base_ , _size_ )
279
 
280
//-----------------------------------------------------------------------------
281
#endif // ifndef CYGONCE_VAR_CACHE_H
282
// 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.