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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [packages/] [hal/] [arm/] [edb7xxx/] [current/] [include/] [hal_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_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, gthomas
46
// Contributors:        nickg, gthomas
47
// Date:        1998-09-28
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 <cyg/infra/cyg_type.h>
61
#include <cyg/hal/hal_mmu.h>
62
 
63
//-----------------------------------------------------------------------------
64
// FIXME: This definition forces the IO flash driver to use a
65
// known-good procedure for fiddling flash before calling flash device
66
// driver functions. The procedure breaks on other platform/driver
67
// combinations though so is depricated. Hence this definition.
68
//
69
// If you work on this target, please try to remove this definition
70
// and verify that the flash driver still works (both from RAM and
71
// flash). If it does, remove the definition and this comment for good
72
// [and the old macro definition if this happens to be the last client
73
// of that code].
74
#define HAL_FLASH_CACHES_OLD_MACROS
75
 
76
//-----------------------------------------------------------------------------
77
// Cache dimensions
78
 
79
#define HAL_UCACHE_SIZE                 0x2000   // Size of data cache in bytes
80
#define HAL_UCACHE_LINE_SIZE            16       // Size of a data cache line
81
#define HAL_UCACHE_WAYS                 4        // Associativity of the cache
82
#define HAL_UCACHE_SETS (HAL_UCACHE_SIZE/(HAL_UCACHE_LINE_SIZE*HAL_UCACHE_WAYS))
83
 
84
#define HAL_CACHE_UNIFIED   // Let programs know the caches are combined
85
 
86
//-----------------------------------------------------------------------------
87
// Global control of caches
88
 
89
// Note: the 'mrc' doesn't seem to work.
90
#if 0
91
// Enable the data cache
92
//    mrc  MMU_CP,0,r1,MMU_Control,c0
93
//    orr  r1,r1,#MMU_Control_C|MMU_Control_B
94
//    mcr  MMU_CP,0,r1,MMU_Control,c0    
95
 
96
#define HAL_UCACHE_ENABLE()                     \
97
{                                               \
98
    asm volatile ("mrc  p15,0,r1,c1,c0;"        \
99
                  "orr  r1,r1,#0x000C;"         \
100
                  "mcr  p15,0,r1,c1,c0;"        \
101
                  :                             \
102
                  :                             \
103
                  : "r1" /* Clobber list */     \
104
        );                                      \
105
                                                \
106
}
107
 
108
// Disable the data cache
109
#define HAL_UCACHE_DISABLE()                     \
110
{                                               \
111
    asm volatile ("mrc  p15,0,r1,c1,c0;"        \
112
                  "bic  r1,r1,#0x000C;"         \
113
                  "mcr  p15,0,r1,c1,c0;"        \
114
                  :                             \
115
                  :                             \
116
                  : "r1" /* Clobber list */     \
117
        );                                      \
118
                                                \
119
}
120
#else
121
#define HAL_UCACHE_ENABLE()                     \
122
{                                               \
123
    asm volatile ("mov  r1,#0x7D;"              \
124
                  "mcr  p15,0,r1,c1,c0,0;"      \
125
                  :                             \
126
                  :                             \
127
                  : "r1" /* Clobber list */     \
128
        );                                      \
129
}
130
 
131
// Disable the data cache
132
#define HAL_UCACHE_DISABLE()                                            \
133
{                                                                       \
134
    asm volatile ("mov  r1,#0x71;"                                      \
135
                  "mcr  p15,0,r1,c1,c0,0;"                              \
136
                  "mov  r1,#0;"                                         \
137
                  "mcr  p15,0,r1,c8,c7,0;"  /* flush I+D TLBs */        \
138
                  "nop; nop; nop; nop; nop;"                            \
139
                  :                                                     \
140
                  :                                                     \
141
                  : "r1" /* Clobber list */                             \
142
        );                                                              \
143
}
144
#endif
145
 
146
// Is the cache turned on?
147
#define HAL_UCACHE_IS_ENABLED(_state_) _state_ = 1;
148
 
149
// Invalidate the entire cache
150
//    mcr  MMU_CP,0,r1,MMU_InvalidateCache,c0
151
#define HAL_UCACHE_INVALIDATE_ALL()             \
152
{                                               \
153
    asm volatile (                              \
154
        "mov    r1,#0;"                         \
155
        "mcr p15,0,r1,c7,c7,0;"                 \
156
        :                                       \
157
        :                                       \
158
        : "r1","memory" /* Clobber list */      \
159
    );                                          \
160
                                                \
161
}
162
 
163
// Synchronize the contents of the cache with memory.
164
#define HAL_UCACHE_SYNC()                                               \
165
{                                                                       \
166
    cyg_uint32 *RAM = (cyg_uint32 *)0x00000000;                         \
167
    int i;                                                              \
168
    volatile cyg_uint32 val;                                            \
169
    for (i = 0;  i < HAL_UCACHE_SETS;  i++) {                           \
170
        val = *RAM;                                                     \
171
        RAM += HAL_UCACHE_LINE_SIZE;                                    \
172
    }                                                                   \
173
}
174
 
175
// Purge contents of data cache
176
#define HAL_UCACHE_PURGE_ALL()  HAL_UCACHE_INVALIDATE_ALL()
177
 
178
// Set the data cache refill burst size
179
//#define HAL_UCACHE_BURST_SIZE(_size_)
180
 
181
// Set the data cache write mode
182
//#define HAL_UCACHE_WRITE_MODE( _mode_ )
183
 
184
//#define HAL_UCACHE_WRITETHRU_MODE       0
185
//#define HAL_UCACHE_WRITEBACK_MODE       1
186
 
187
// Load the contents of the given address range into the data cache
188
// and then lock the cache so that it stays there.
189
//#define HAL_UCACHE_LOCK(_base_, _size_)
190
 
191
// Undo a previous lock operation
192
//#define HAL_UCACHE_UNLOCK(_base_, _size_)
193
 
194
// Unlock entire cache
195
//#define HAL_UCACHE_UNLOCK_ALL()
196
 
197
//-----------------------------------------------------------------------------
198
// Data cache line control
199
 
200
// Allocate cache lines for the given address range without reading its
201
// contents from memory.
202
//#define HAL_UCACHE_ALLOCATE( _base_ , _size_ )
203
 
204
// Write dirty cache lines to memory and invalidate the cache entries
205
// for the given address range.
206
#define HAL_UCACHE_FLUSH( _base_ , _size_ )  HAL_UCACHE_SYNC()
207
 
208
// Invalidate cache lines in the given range without writing to memory.
209
//#define HAL_UCACHE_INVALIDATE( _base_ , _size_ )
210
 
211
// Write dirty cache lines to memory for the given address range.
212
#define HAL_UCACHE_STORE( _base_ , _size_ )  HAL_UCACHE_SYNC()
213
 
214
// Preread the given range into the cache with the intention of reading
215
// from it later.
216
//#define HAL_UCACHE_READ_HINT( _base_ , _size_ )
217
 
218
// Preread the given range into the cache with the intention of writing
219
// to it later.
220
//#define HAL_UCACHE_WRITE_HINT( _base_ , _size_ )
221
 
222
// Allocate and zero the cache lines associated with the given range.
223
//#define HAL_UCACHE_ZERO( _base_ , _size_ )
224
 
225
//-----------------------------------------------------------------------------
226
// Global control of data cache
227
 
228
#define HAL_DCACHE_SIZE                 HAL_UCACHE_SIZE
229
#define HAL_DCACHE_LINE_SIZE            HAL_UCACHE_LINE_SIZE
230
#define HAL_DCACHE_WAYS                 HAL_UCACHE_WAYS
231
#define HAL_DCACHE_SETS                 HAL_UCACHE_SETS
232
 
233
// Enable the data cache
234
#define HAL_DCACHE_ENABLE()             HAL_UCACHE_ENABLE()
235
 
236
// Disable the data cache
237
#define HAL_DCACHE_DISABLE()            HAL_UCACHE_DISABLE()
238
 
239
// Invalidate the entire cache
240
#define HAL_DCACHE_INVALIDATE_ALL()     HAL_UCACHE_INVALIDATE_ALL()
241
 
242
// Synchronize the contents of the cache with memory.
243
#define HAL_DCACHE_SYNC()               HAL_UCACHE_SYNC()
244
 
245
// Query the state of the data cache
246
#define HAL_DCACHE_IS_ENABLED(_state_)  HAL_UCACHE_IS_ENABLED(_state_)
247
 
248
// Set the data cache refill burst size
249
//#define HAL_DCACHE_BURST_SIZE(_size_)
250
 
251
// Set the data cache write mode
252
//#define HAL_DCACHE_WRITE_MODE( _mode_ )
253
 
254
//#define HAL_DCACHE_WRITETHRU_MODE       0
255
//#define HAL_DCACHE_WRITEBACK_MODE       1
256
 
257
// Load the contents of the given address range into the data cache
258
// and then lock the cache so that it stays there.
259
//#define HAL_DCACHE_LOCK(_base_, _size_)
260
 
261
// Undo a previous lock operation
262
//#define HAL_DCACHE_UNLOCK(_base_, _size_)
263
 
264
// Unlock entire cache
265
//#define HAL_DCACHE_UNLOCK_ALL()
266
 
267
//-----------------------------------------------------------------------------
268
// Data cache line control
269
 
270
// Allocate cache lines for the given address range without reading its
271
// contents from memory.
272
//#define HAL_DCACHE_ALLOCATE( _base_ , _size_ )
273
 
274
// Write dirty cache lines to memory and invalidate the cache entries
275
// for the given address range.
276
#define HAL_DCACHE_FLUSH( _base_ , _size_ )  HAL_UCACHE_FLUSH( _base_ , _size_ )
277
 
278
// Invalidate cache lines in the given range without writing to memory.
279
//#define HAL_DCACHE_INVALIDATE( _base_ , _size_ )
280
 
281
// Write dirty cache lines to memory for the given address range.
282
#define HAL_DCACHE_STORE( _base_ , _size_ )  HAL_UCACHE_STORE( _base_ , _size_ )
283
 
284
// Preread the given range into the cache with the intention of reading
285
// from it later.
286
//#define HAL_DCACHE_READ_HINT( _base_ , _size_ )
287
 
288
// Preread the given range into the cache with the intention of writing
289
// to it later.
290
//#define HAL_DCACHE_WRITE_HINT( _base_ , _size_ )
291
 
292
// Allocate and zero the cache lines associated with the given range.
293
//#define HAL_DCACHE_ZERO( _base_ , _size_ )
294
 
295
//-----------------------------------------------------------------------------
296
// Global control of Instruction cache - use Data cache controls since they
297
// are not separatable.
298
 
299
#define HAL_ICACHE_SIZE                 HAL_UCACHE_SIZE
300
#define HAL_ICACHE_LINE_SIZE            HAL_UCACHE_LINE_SIZE
301
#define HAL_ICACHE_WAYS                 HAL_UCACHE_WAYS
302
#define HAL_ICACHE_SETS                 HAL_UCACHE_SETS
303
 
304
// Enable the instruction cache
305
#define HAL_ICACHE_ENABLE()      HAL_UCACHE_ENABLE()
306
 
307
// Disable the instruction cache
308
#define HAL_ICACHE_DISABLE()     HAL_UCACHE_DISABLE()
309
 
310
// Is the cache turned on?
311
#define HAL_ICACHE_IS_ENABLED(_state_) HAL_UCACHE_IS_ENABLED(_state_)
312
 
313
// Invalidate the entire cache
314
#define HAL_ICACHE_INVALIDATE_ALL()  HAL_UCACHE_INVALIDATE_ALL()
315
 
316
// Synchronize the contents of the cache with memory.
317
#define HAL_ICACHE_SYNC()        HAL_UCACHE_SYNC()
318
 
319
// Set the instruction cache refill burst size
320
//#define HAL_ICACHE_BURST_SIZE(_size_)
321
 
322
// Load the contents of the given address range into the instruction cache
323
// and then lock the cache so that it stays there.
324
//#define HAL_ICACHE_LOCK(_base_, _size_)
325
 
326
// Undo a previous lock operation
327
//#define HAL_ICACHE_UNLOCK(_base_, _size_)
328
 
329
// Unlock entire cache
330
//#define HAL_ICACHE_UNLOCK_ALL()
331
 
332
//-----------------------------------------------------------------------------
333
// Instruction cache line control
334
 
335
// Invalidate cache lines in the given range without writing to memory.
336
//#define HAL_ICACHE_INVALIDATE( _base_ , _size_ )
337
 
338
//-----------------------------------------------------------------------------
339
#endif // ifndef CYGONCE_HAL_CACHE_H
340
// End of hal_cache.h

powered by: WebSVN 2.1.0

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