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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-2.0/] [packages/] [hal/] [powerpc/] [ppc60x/] [v2_0/] [include/] [var_cache.h] - Blame information for rev 279

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

Line No. Rev Author Line
1 27 unneback
#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 Red Hat, Inc.
14
// Copyright (C) 2002, 2003 Gary Thomas
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
47
// Contributors:nickg, jskov, gthomas
48
// Date:        2000-04-02
49
// Purpose:     Variant cache control API
50
// Description: The macros defined here provide the HAL APIs for handling
51
//              cache control operations on the PPC60x variant CPUs.
52
// Usage:       Is included via the architecture cache header:
53
//              #include <cyg/hal/hal_cache.h>
54
//              ...
55
//
56
//####DESCRIPTIONEND####
57
//
58
//=============================================================================
59
 
60
#include <pkgconf/hal.h>
61
#include <cyg/infra/cyg_type.h>
62
 
63
#include <cyg/hal/ppc_regs.h>
64
#include <cyg/hal/plf_cache.h>
65
 
66
 
67
//-----------------------------------------------------------------------------
68
// Cache dimensions
69
 
70
// Data cache
71
#ifndef HAL_DCACHE_SIZE
72
#define HAL_DCACHE_SIZE                 16384   // Size of data cache in bytes
73
#define HAL_DCACHE_LINE_SIZE            32      // Size of a data cache line
74
#define HAL_DCACHE_WAYS                 4       // Associativity of the cache
75
#endif
76
 
77
// Instruction cache
78
#ifndef HAL_ICACHE_SIZE
79
#define HAL_ICACHE_SIZE                 16384   // Size of cache in bytes
80
#define HAL_ICACHE_LINE_SIZE            32      // Size of a cache line
81
#define HAL_ICACHE_WAYS                 4       // Associativity of the cache
82
#endif
83
 
84
#define HAL_DCACHE_SETS (HAL_DCACHE_SIZE/(HAL_DCACHE_LINE_SIZE*HAL_DCACHE_WAYS))
85
#define HAL_ICACHE_SETS (HAL_ICACHE_SIZE/(HAL_ICACHE_LINE_SIZE*HAL_ICACHE_WAYS))
86
 
87
//-----------------------------------------------------------------------------
88
// Global control of data cache
89
 
90
// Enable the data cache
91
#define HAL_DCACHE_ENABLE()                     \
92
    CYG_MACRO_START                             \
93
    cyg_int32 _scratch;                         \
94
    asm volatile ("isync;"                      \
95
                  "mfspr %0,%1;"                \
96
                  "or  %0,%0,%2;"               \
97
                  "mtspr %1,%0"                 \
98
                  : "=&r" (_scratch)            \
99
                  : "I" (CYGARC_REG_HID0),      \
100
                    "r" (_HID0_DCE)             \
101
        );                                      \
102
    CYG_MACRO_END
103
 
104
// Disable the data cache
105
#define HAL_DCACHE_DISABLE()                    \
106
    CYG_MACRO_START                             \
107
    cyg_int32 _scratch;                         \
108
    asm volatile ("isync;"                      \
109
                  "mfspr %0,%1;"                \
110
                  "andc %0,%0,%2;"              \
111
                  "mtspr %1,%0"                 \
112
                  : "=&r" (_scratch)            \
113
                  : "I" (CYGARC_REG_HID0),      \
114
                    "r" (_HID0_DCE)             \
115
        );                                      \
116
    CYG_MACRO_END
117
 
118
// Invalidate the entire cache
119
#define HAL_DCACHE_INVALIDATE_ALL()             \
120
    CYG_MACRO_START                             \
121
    cyg_int32 _scr1, _scr2;                     \
122
    asm volatile ("isync;"                      \
123
                  "mfspr %0,%2;"                \
124
                  "mr %1,%0;"                   \
125
                  "or %0,%0,%3;"                \
126
                  "mtspr %2,%0;"                \
127
                  "mtspr %2,%1"                 \
128
                  : "=&r" (_scr1),              \
129
                    "=&r" (_scr2)               \
130
                  : "I" (CYGARC_REG_HID0),      \
131
                    "r" (_HID0_DCFI)            \
132
        );                                      \
133
    CYG_MACRO_END
134
 
135
// Synchronize the contents of the cache with memory.
136
#define HAL_DCACHE_SYNC()                                                     \
137
    CYG_MACRO_START                                                           \
138
    cyg_int32 i;                                                              \
139
    cyg_uint32 *__base = (cyg_uint32 *) (0);                  \
140
    for (i = 0; i < (HAL_DCACHE_SIZE/HAL_DCACHE_LINE_SIZE); i++, __base += HAL_DCACHE_LINE_SIZE/4){ \
141
        asm volatile ("lwz %%r0,0(%0)" : : "r" (__base) : "r0");      \
142
    }                                                                         \
143
    CYG_MACRO_END
144
 
145
// Query the state of the data cache
146
#define HAL_DCACHE_IS_ENABLED(_state_)          \
147
    CYG_MACRO_START                             \
148
    cyg_int32 _scratch;                         \
149
    asm volatile ("isync;"                      \
150
                  "mfspr %0,%1;"                \
151
                  "and %0,%0,%2;"               \
152
                  : "=&r" (_scratch)            \
153
                  : "I" (CYGARC_REG_HID0),      \
154
                    "r" (_HID0_DCE)             \
155
        );                                      \
156
    (_state_) = _scratch != 0;                  \
157
    CYG_MACRO_END
158
 
159
// Set the data cache refill burst size
160
//#define HAL_DCACHE_BURST_SIZE(_size_)
161
 
162
// Set the data cache write mode
163
//#define HAL_DCACHE_WRITE_MODE( _mode_ )
164
 
165
//#define HAL_DCACHE_WRITETHRU_MODE       0
166
//#define HAL_DCACHE_WRITEBACK_MODE       1
167
 
168
// Load the contents of the given address range into the data cache
169
// and then lock the cache so that it stays there.
170
//#define HAL_DCACHE_LOCK(_base_, _size_)
171
 
172
// Undo a previous lock operation
173
//#define HAL_DCACHE_UNLOCK(_base_, _size_)
174
 
175
// Unlock entire cache
176
//#define HAL_DCACHE_UNLOCK_ALL()
177
 
178
//-----------------------------------------------------------------------------
179
// Data cache line control
180
 
181
// Allocate cache lines for the given address range without reading its
182
// contents from memory.
183
//#define HAL_DCACHE_ALLOCATE( _base_ , _size_ )
184
 
185
// Write dirty cache lines to memory and invalidate the cache entries
186
// for the given address range.
187
#define HAL_DCACHE_FLUSH( _base_ , _size_ )                     \
188
    CYG_MACRO_START                                             \
189
    cyg_uint32 __base = (cyg_uint32) (_base_);                  \
190
    cyg_int32 __size = (cyg_int32) (_size_);                    \
191
    while (__size > 0) {                                        \
192
        asm volatile ("dcbf 0,%0;sync;" : : "r" (__base));      \
193
        __base += HAL_DCACHE_LINE_SIZE;                         \
194
        __size -= HAL_DCACHE_LINE_SIZE;                         \
195
    }                                                           \
196
    CYG_MACRO_END
197
 
198
// Invalidate cache lines in the given range without writing to memory.
199
#define HAL_DCACHE_INVALIDATE( _base_ , _size_ )                \
200
    CYG_MACRO_START                                             \
201
    cyg_uint32 __base = (cyg_uint32) (_base_);                  \
202
    cyg_int32 __size = (cyg_int32) (_size_);                    \
203
    while (__size > 0) {                                        \
204
        asm volatile ("dcbi 0,%0;sync;" : : "r" (__base));      \
205
        __base += HAL_DCACHE_LINE_SIZE;                         \
206
        __size -= HAL_DCACHE_LINE_SIZE;                         \
207
    }                                                           \
208
    CYG_MACRO_END
209
 
210
// Write dirty cache lines to memory for the given address range.
211
#define HAL_DCACHE_STORE( _base_ , _size_ )                     \
212
    CYG_MACRO_START                                             \
213
    cyg_uint32 __base = (cyg_uint32) (_base_);                  \
214
    cyg_int32 __size = (cyg_int32) (_size_);                    \
215
    while (__size > 0) {                                        \
216
        asm volatile ("dcbst 0,%0;sync;" : : "r" (__base));     \
217
        __base += HAL_DCACHE_LINE_SIZE;                         \
218
        __size -= HAL_DCACHE_LINE_SIZE;                         \
219
    }                                                           \
220
    CYG_MACRO_END
221
 
222
// Preread the given range into the cache with the intention of reading
223
// from it later.
224
#define HAL_DCACHE_READ_HINT( _base_ , _size_ )                 \
225
    CYG_MACRO_START                                             \
226
    cyg_uint32 __base = (cyg_uint32) (_base_);                  \
227
    cyg_int32 __size = (cyg_int32) (_size_);                    \
228
    while (__size > 0) {                                        \
229
        asm volatile ("dcbt 0,%0;" : : "r" (__base));           \
230
        __base += HAL_DCACHE_LINE_SIZE;                         \
231
        __size -= HAL_DCACHE_LINE_SIZE;                         \
232
    }                                                           \
233
    CYG_MACRO_END
234
 
235
// Preread the given range into the cache with the intention of writing
236
// to it later.
237
#define HAL_DCACHE_WRITE_HINT( _base_ , _size_ )                \
238
    CYG_MACRO_START                                             \
239
    cyg_uint32 __base = (cyg_uint32) (_base_);                  \
240
    cyg_int32 __size = (cyg_int32) (_size_);                    \
241
    while (__size > 0) {                                        \
242
        asm volatile ("dcbtst 0,%0;" : : "r" (__base));         \
243
        __base += HAL_DCACHE_LINE_SIZE;                         \
244
        __size -= HAL_DCACHE_LINE_SIZE;                         \
245
    }                                                           \
246
    CYG_MACRO_END
247
 
248
// Allocate and zero the cache lines associated with the given range.
249
#define HAL_DCACHE_ZERO( _base_ , _size_ )                      \
250
    CYG_MACRO_START                                             \
251
    cyg_uint32 __base = (cyg_uint32) (_base_);                  \
252
    cyg_int32 __size = (cyg_int32) (_size_);                    \
253
    while (__size > 0) {                                        \
254
        asm volatile ("dcbz 0,%0;" : : "r" (__base));           \
255
        __base += HAL_DCACHE_LINE_SIZE;                         \
256
        __size -= HAL_DCACHE_LINE_SIZE;                         \
257
    }                                                           \
258
    CYG_MACRO_END
259
 
260
//-----------------------------------------------------------------------------
261
// Global control of Instruction cache
262
 
263
// Enable the instruction cache
264
#define HAL_ICACHE_ENABLE()                     \
265
    CYG_MACRO_START                             \
266
    cyg_int32 _scratch;                         \
267
    asm volatile ("isync;"                      \
268
                  "mfspr %0,%1;"                \
269
                  "or  %0,%0,%2;"               \
270
                  "mtspr %1,%0"                 \
271
                  : "=&r" (_scratch)            \
272
                  : "I" (CYGARC_REG_HID0),      \
273
                    "r" (_HID0_ICE)             \
274
        );                                      \
275
    CYG_MACRO_END
276
 
277
// Disable the instruction cache
278
#define HAL_ICACHE_DISABLE()                    \
279
    CYG_MACRO_START                             \
280
    cyg_int32 _scratch;                         \
281
    asm volatile ("isync;"                      \
282
                  "mfspr %0,%1;"                \
283
                  "andc %0,%0,%2;"              \
284
                  "mtspr %1,%0"                 \
285
                  : "=&r" (_scratch)            \
286
                  : "I" (CYGARC_REG_HID0),      \
287
                    "r" (_HID0_ICE)             \
288
        );                                      \
289
    CYG_MACRO_END
290
 
291
// Invalidate the entire cache
292
#define HAL_ICACHE_INVALIDATE_ALL()             \
293
    CYG_MACRO_START                             \
294
    cyg_int32 _scr1, _scr2;                     \
295
    asm volatile ("isync;"                      \
296
                  "mfspr %0,%2;"                \
297
                  "mr %1,%0;"                   \
298
                  "or %0,%0,%3;"                \
299
                  "mtspr %2,%0;"                \
300
                  "mtspr %2,%1"                 \
301
                  : "=&r" (_scr1),              \
302
                    "=&r" (_scr2)               \
303
                  : "I" (CYGARC_REG_HID0),      \
304
                    "r" (_HID0_ICFI)            \
305
        );                                      \
306
    CYG_MACRO_END
307
 
308
// Synchronize the contents of the cache with memory.
309
#define HAL_ICACHE_SYNC()                       \
310
  HAL_ICACHE_INVALIDATE_ALL()
311
 
312
// Query the state of the instruction cache
313
#define HAL_ICACHE_IS_ENABLED(_state_)          \
314
    CYG_MACRO_START                             \
315
    cyg_int32 _scratch;                         \
316
    asm volatile ("isync;"                      \
317
                  "mfspr %0,%1;"                \
318
                  "and %0,%0,%2;"               \
319
                  : "=&r" (_scratch)            \
320
                  : "I" (CYGARC_REG_HID0),      \
321
                    "r" (_HID0_ICE)             \
322
        );                                      \
323
    (_state_) = _scratch != 0;                  \
324
    CYG_MACRO_END
325
 
326
// Set the instruction cache refill burst size
327
//#define HAL_ICACHE_BURST_SIZE(_size_)
328
 
329
// Load the contents of the given address range into the instruction cache
330
// and then lock the cache so that it stays there.
331
//#define HAL_ICACHE_LOCK(_base_, _size_)
332
 
333
// Undo a previous lock operation
334
//#define HAL_ICACHE_UNLOCK(_base_, _size_)
335
 
336
// Unlock entire cache
337
//#define HAL_ICACHE_UNLOCK_ALL()
338
 
339
//-----------------------------------------------------------------------------
340
// Instruction cache line control
341
 
342
// Invalidate cache lines in the given range without writing to memory.
343
//#define HAL_ICACHE_INVALIDATE( _base_ , _size_ )
344
 
345
//-----------------------------------------------------------------------------
346
#endif // ifndef CYGONCE_VAR_CACHE_H
347
// End of var_cache.h

powered by: WebSVN 2.1.0

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