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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [packages/] [hal/] [mn10300/] [am33/] [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
//
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, dmoseley
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
// AM33 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                 4       // Associativity of the cache
76
 
77
// Instruction cache
78
#define HAL_ICACHE_SIZE                 8192    // Size of cache in bytes
79
#define HAL_ICACHE_LINE_SIZE            16      // Size of a cache line
80
#define HAL_ICACHE_WAYS                 4       // 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 *)0xC0000070)
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 *)0xC8400000)
101
#define HAL_DCACHE_PURGE_WAY1   ((volatile CYG_BYTE *)0xC8401000)
102
#define HAL_DCACHE_PURGE_WAY2   ((volatile CYG_BYTE *)0xC8402000)
103
#define HAL_DCACHE_PURGE_WAY3   ((volatile CYG_BYTE *)0xC8403000)
104
 
105
//-----------------------------------------------------------------------------
106
// Global control of data cache
107
 
108
// Enable the data cache
109
#define HAL_DCACHE_ENABLE()                     \
110
{                                               \
111
    register CYG_ADDRWORD chctr = *HAL_CHCTR;   \
112
    chctr |= HAL_CHCTR_DCEN;                    \
113
    *HAL_CHCTR = chctr;                         \
114
}
115
 
116
// Disable the data cache
117
#define HAL_DCACHE_DISABLE()                    \
118
{                                               \
119
    register CYG_ADDRWORD chctr = *HAL_CHCTR;   \
120
    chctr &= ~HAL_CHCTR_DCEN;                   \
121
    *HAL_CHCTR = chctr;                         \
122
    while( HAL_CHCTR_DCBUSY & *HAL_CHCTR );     \
123
}
124
 
125
// Query the state of the data cache
126
#define HAL_DCACHE_IS_ENABLED(_state_)          \
127
{                                               \
128
    register CYG_ADDRWORD chctr = *HAL_CHCTR;   \
129
    _state_ = (0 != (chctr & HAL_CHCTR_DCEN));  \
130
}
131
 
132
// Invalidate the entire cache
133
#define HAL_DCACHE_INVALIDATE_ALL()             \
134
{                                               \
135
    register CYG_ADDRWORD chctr;                \
136
    register CYG_ADDRWORD state;                \
137
    HAL_DCACHE_IS_ENABLED(state);               \
138
    if (state)                                  \
139
        HAL_DCACHE_DISABLE();                   \
140
    chctr = *HAL_CHCTR;                         \
141
    chctr |= HAL_CHCTR_DCINV;                   \
142
    *HAL_CHCTR = chctr;                         \
143
    while( HAL_CHCTR_DCBUSY & *HAL_CHCTR );     \
144
    if (state)                                  \
145
        HAL_DCACHE_ENABLE();                    \
146
}
147
 
148
// Synchronize the contents of the cache with memory.
149
#define HAL_DCACHE_SYNC() HAL_DCACHE_STORE( 0, HAL_DCACHE_SIZE )
150
 
151
// Set the data cache refill burst size
152
//#define HAL_DCACHE_BURST_SIZE(_size_)
153
 
154
// Set the data cache write mode
155
#define HAL_DCACHE_WRITE_MODE( _mode_ )         \
156
{                                               \
157
    register CYG_ADDRWORD chctr;                \
158
    register CYG_ADDRWORD state;                \
159
    HAL_DCACHE_IS_ENABLED(state);               \
160
    if (state)                                  \
161
        HAL_DCACHE_DISABLE();                   \
162
    chctr = *HAL_CHCTR;                         \
163
    chctr &= ~HAL_CHCTR_DCWTMD;                 \
164
    chctr |= HAL_CHCTR_DCWTMD*(_mode_);         \
165
    *HAL_CHCTR = chctr;                         \
166
    while( HAL_CHCTR_DCBUSY & *HAL_CHCTR );     \
167
    if (state)                                  \
168
        HAL_DCACHE_ENABLE();                    \
169
}
170
 
171
#define HAL_DCACHE_WRITEBACK_MODE       0
172
#define HAL_DCACHE_WRITETHRU_MODE       1
173
 
174
// Load the contents of the given address range into the data cache
175
// and then lock the cache so that it stays there.
176
//#define HAL_DCACHE_LOCK(_base_, _size_)
177
 
178
// Undo a previous lock operation
179
//#define HAL_DCACHE_UNLOCK(_base_, _size_)
180
 
181
// Unlock entire cache
182
//#define HAL_DCACHE_UNLOCK_ALL()
183
 
184
//-----------------------------------------------------------------------------
185
// Data cache line control
186
 
187
// Allocate cache lines for the given address range without reading its
188
// contents from memory.
189
//#define HAL_DCACHE_ALLOCATE( _base_ , _size_ )
190
 
191
// Write dirty cache lines to memory and invalidate the cache entries
192
// for the given address range.
193
//#define HAL_DCACHE_FLUSH( _base_ , _size_ )
194
 
195
// Invalidate cache lines in the given range without writing to memory.
196
//#define HAL_DCACHE_INVALIDATE( _base_ , _size_ )
197
 
198
// Write dirty cache lines to memory for the given address range.
199
 
200
// This functionality requires 4 register variables. To prevent register
201
// spilling, put the code in a separate function.
202
externC void cyg_hal_dcache_store(CYG_ADDRWORD base, int size);
203
 
204
#define HAL_DCACHE_STORE( _base_ , _size_ ) \
205
    cyg_hal_dcache_store((CYG_ADDRWORD)(_base_), (_size_))
206
 
207
// Preread the given range into the cache with the intention of reading
208
// from it later.
209
//#define HAL_DCACHE_READ_HINT( _base_ , _size_ )
210
 
211
// Preread the given range into the cache with the intention of writing
212
// to it later.
213
//#define HAL_DCACHE_WRITE_HINT( _base_ , _size_ )
214
 
215
// Allocate and zero the cache lines associated with the given range.
216
//#define HAL_DCACHE_ZERO( _base_ , _size_ )
217
 
218
//-----------------------------------------------------------------------------
219
// Global control of Instruction cache
220
 
221
// Enable the instruction cache
222
#define HAL_ICACHE_ENABLE()                     \
223
{                                               \
224
    register CYG_ADDRWORD chctr = *HAL_CHCTR;   \
225
    chctr |= HAL_CHCTR_ICEN;                    \
226
    *HAL_CHCTR = chctr;                         \
227
}
228
 
229
// Disable the instruction cache
230
#define HAL_ICACHE_DISABLE()                    \
231
{                                               \
232
    register CYG_ADDRWORD chctr = *HAL_CHCTR;   \
233
    chctr &= ~HAL_CHCTR_ICEN;                   \
234
    *HAL_CHCTR = chctr;                         \
235
    while( HAL_CHCTR_ICBUSY & *HAL_CHCTR );     \
236
}
237
 
238
// Query the state of the instruction cache
239
#define HAL_ICACHE_IS_ENABLED(_state_)          \
240
{                                               \
241
    register CYG_ADDRWORD chctr = *HAL_CHCTR;   \
242
    _state_ = (0 != (chctr & HAL_CHCTR_ICEN));  \
243
}
244
 
245
// Invalidate the entire cache
246
#define HAL_ICACHE_INVALIDATE_ALL()             \
247
{                                               \
248
    register CYG_ADDRWORD chctr;                \
249
    register CYG_ADDRWORD state;                \
250
    HAL_ICACHE_IS_ENABLED(state);               \
251
    if (state)                                  \
252
        HAL_ICACHE_DISABLE();                   \
253
    chctr = *HAL_CHCTR;                         \
254
    chctr |= HAL_CHCTR_ICINV;                   \
255
    *HAL_CHCTR = chctr;                         \
256
    while( HAL_CHCTR_ICBUSY & *HAL_CHCTR );     \
257
    if (state)                                  \
258
        HAL_ICACHE_ENABLE();                    \
259
}
260
 
261
// Synchronize the contents of the cache with memory.
262
#define HAL_ICACHE_SYNC() HAL_ICACHE_INVALIDATE_ALL()
263
 
264
// Set the instruction cache refill burst size
265
//#define HAL_ICACHE_BURST_SIZE(_size_)
266
 
267
// Load the contents of the given address range into the instruction cache
268
// and then lock the cache so that it stays there.
269
//#define HAL_ICACHE_LOCK(_base_, _size_)
270
 
271
// Undo a previous lock operation
272
//#define HAL_ICACHE_UNLOCK(_base_, _size_)
273
 
274
// Unlock entire cache
275
//#define HAL_ICACHE_UNLOCK_ALL()
276
 
277
//-----------------------------------------------------------------------------
278
// Instruction cache line control
279
 
280
// Invalidate cache lines in the given range without writing to memory.
281
//#define HAL_ICACHE_INVALIDATE( _base_ , _size_ )
282
 
283
//-----------------------------------------------------------------------------
284
// flash caching control
285
#ifdef CYGSEM_HAL_UNCACHED_FLASH_ACCESS
286
#define HAL_FLASH_CACHES_OFF(_d_, _i_)          \
287
    CYG_MACRO_START                             \
288
    _d_ = 0; /* avoids warning */               \
289
    _i_ = 0; /* avoids warning */               \
290
    CYG_MACRO_END
291
 
292
#define HAL_FLASH_CACHES_ON(_d_, _i_)           \
293
    CYG_MACRO_START                             \
294
    CYG_MACRO_END
295
#endif
296
 
297
//-----------------------------------------------------------------------------
298
#endif // ifndef CYGONCE_VAR_CACHE_H
299
// 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.