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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-2.0/] [packages/] [hal/] [arm/] [edb7xxx/] [v2_0/] [include/] [hal_cache.h] - Blame information for rev 861

Go to most recent revision | Details | Compare with Previous | View Log

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