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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [packages/] [hal/] [powerpc/] [mpc8xxx/] [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
//      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, 2003 Free Software Foundation, Inc.
14
//
15
// eCos is free software; you can redistribute it and/or modify it under    
16
// the terms of the GNU General Public License as published by the Free     
17
// Software Foundation; either version 2 or (at your option) any later      
18
// version.                                                                 
19
//
20
// eCos is distributed in the hope that it will be useful, but WITHOUT      
21
// ANY 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        
26
// along with eCos; if not, write to the Free Software Foundation, Inc.,    
27
// 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.            
28
//
29
// As a special exception, if other files instantiate templates or use      
30
// macros or inline functions from this file, or you compile this file      
31
// and link it with other works to produce a work based on this file,       
32
// this file does not by itself cause the resulting work to be covered by   
33
// the GNU General Public License. However the source code for this file    
34
// must still be made available in accordance with section (3) of the GNU   
35
// General Public License v2.                                               
36
//
37
// This exception does not invalidate any other reasons why a work based    
38
// on this file might be covered by the GNU General Public License.         
39
// -------------------------------------------                              
40
// ####ECOSGPLCOPYRIGHTEND####                                              
41
//=============================================================================
42
//#####DESCRIPTIONBEGIN####
43
//
44
// Author(s):   pfine
45
// Contributors:nickg, jskov
46
// Date:        2001-12-12
47
// Purpose:     Variant cache control API
48
// Description: The macros defined here provide the HAL APIs for handling
49
//              cache control operations on the MPC8260 variant CPU.
50
// Usage:       Is included via the architecture cache header:
51
//              #include <cyg/hal/hal_cache.h>
52
//              ...
53
//
54
//####DESCRIPTIONEND####
55
//
56
//=============================================================================
57
 
58
#include <pkgconf/hal.h>
59
#include <cyg/infra/cyg_type.h>
60
 
61
#include <cyg/hal/ppc_regs.h>
62
#include <cyg/hal/var_regs.h>
63
 
64
#include <cyg/hal/plf_cache.h>
65
 
66
//-----------------------------------------------------------------------------
67
// Cache dimensions
68
 
69
// Data cache
70
#define HAL_DCACHE_SIZE                 16384    // Size of data cache in bytes
71
#define HAL_DCACHE_LINE_SIZE            32       // Size of a data cache line
72
#define HAL_DCACHE_WAYS                 4        // Associativity of the cache
73
 
74
// Instruction cache
75
#define HAL_ICACHE_SIZE                 16384    // Size of cache in bytes
76
#define HAL_ICACHE_LINE_SIZE            32       // Size of a cache line
77
#define HAL_ICACHE_WAYS                 4        // Associativity of the cache
78
 
79
#define HAL_DCACHE_SETS (HAL_DCACHE_SIZE/(HAL_DCACHE_LINE_SIZE*HAL_DCACHE_WAYS))
80
#define HAL_ICACHE_SETS (HAL_ICACHE_SIZE/(HAL_ICACHE_LINE_SIZE*HAL_ICACHE_WAYS))
81
 
82
//-----------------------------------------------------------------------------
83
// Global control of data cache
84
 
85
// Enable the data cache
86
#define HAL_DCACHE_ENABLE()                 \
87
    CYG_MACRO_START                         \
88
    cyg_uint32 tmp1, tmp2;                  \
89
    asm volatile (                          \
90
        "mfspr %1, %2;"                     \
91
        "li %0, 0x4000;"                     \
92
        "rlwimi %1,%0,0,17,17;"             \
93
        "sync;"                             \
94
        "mtspr %2,%1;"                      \
95
        "isync;"                            \
96
        "sync;"                             \
97
        : "=r" (tmp1), "=r" (tmp2)          \
98
        : "I" (CYGARC_REG_HID0) /* %2 ==> HID0 */); \
99
    CYG_MACRO_END
100
 
101
// Disable the data cache
102
#define HAL_DCACHE_DISABLE()                \
103
    CYG_MACRO_START                         \
104
    register cyg_uint32 tmp1;               \
105
    register cyg_uint32 tmp2;               \
106
    for (tmp1 = 0; tmp1 < HAL_DCACHE_SIZE; tmp1 += HAL_DCACHE_LINE_SIZE) \
107
        tmp2 = *((cyg_uint32 *) tmp1);      \
108
    asm volatile (                          \
109
        "mfspr %1, %2;"                     \
110
        "li %0, 0x0;"                       \
111
        "rlwimi %1,%0,0,17,17;"             \
112
        "sync;"                             \
113
        "mtspr %2,%1;"                      \
114
        "isync;"                            \
115
        "sync;"                             \
116
        : "=r" (tmp1), "=r" (tmp2)          \
117
        : "I" (CYGARC_REG_HID0) /* %2 ==> HID0 */); \
118
    CYG_MACRO_END
119
 
120
// Invalidate the entire cache
121
#define HAL_DCACHE_INVALIDATE_ALL()                   \
122
    CYG_MACRO_START                                   \
123
    cyg_uint32 tmp1, tmp2;                            \
124
    asm volatile ("sync;"                             \
125
                  "mfspr %0, %2;"                     \
126
                  "ori   %0, %0, 0x0400;"             \
127
                  "mtspr %2, %0;"                     \
128
                  "li    %1, 0;"                      \
129
                  "rlwimi %0,%1,0,21,21;"             \
130
                  "mtspr %2, %0;"                     \
131
                  "sync;"                             \
132
                  : "=r" (tmp1), "=r" (tmp2)          \
133
                  : "I" (CYGARC_REG_HID0) /* %3 ==> HID0 */);\
134
    CYG_MACRO_END
135
 
136
 
137
// Synchronize the contents of the cache with memory.
138
// Modifications to this macro should mirror modifications to the
139
// identically named one in the ppc60x variant.
140
// We step through twice the number of lines in the cache in order
141
// to ensure that all dirty lines are flushed to main memory.
142
// (Consider the case where one of the dirty lines is in the
143
// first 16Kbytes of RAM -- it won't get flushed by loading
144
// in words from the first 16Kbytes of RAM).
145
#define HAL_DCACHE_SYNC()                                       \
146
    CYG_MACRO_START                                             \
147
    cyg_int32 i;                                                \
148
    cyg_uint32 *__base = (cyg_uint32 *) (0);                    \
149
    for(i=0;i< (2 * HAL_DCACHE_SIZE/HAL_DCACHE_LINE_SIZE);i++,__base += HAL_DCACHE_LINE_SIZE/4){                                                 \
150
        asm volatile ("lwz %%r0,0(%0);"::"r"(__base):"r0");     \
151
    }                                                           \
152
    CYG_MACRO_END
153
 
154
// Query the state of the data cache
155
#define HAL_DCACHE_IS_ENABLED(_state_)                          \
156
    asm volatile ("mfspr  %0, %1;"                              \
157
                  "rlwinm %0,%0,18,31,31;"                      \
158
                  : "=r" (_state_) : "I" (CYGARC_REG_HID0))
159
 
160
// Set the data cache refill burst size
161
//#define HAL_DCACHE_BURST_SIZE(_size_)
162
 
163
// Set the data cache write mode
164
//#define HAL_DCACHE_WRITE_MODE( _mode_ )
165
 
166
//#define HAL_DCACHE_WRITETHRU_MODE       0
167
//#define HAL_DCACHE_WRITEBACK_MODE       1
168
 
169
// Load the contents of the given address range into the data cache
170
// and then lock the cache so that it stays there.
171
//#define HAL_DCACHE_LOCK(_base_, _size_)
172
 
173
// Undo a previous lock operation
174
//#define HAL_DCACHE_UNLOCK(_base_, _size_)
175
 
176
// Unlock entire cache
177
#define HAL_DCACHE_UNLOCK_ALL()                       \
178
    asm volatile ("isync;"                            \
179
                  "mfspr %0, %2;"                     \
180
                  "oris  %1, 0,0xFFFF;"               \
181
                  "ori   %1,%1,0xEFFF;"               \
182
                  "and   %0,%0,%1;"                   \
183
                  "mtspr %2,%0;"                      \
184
                  "isync;"                            \
185
                  "sync;"                             \
186
                  : /* No output */                   \
187
                  : "I" (5) /* %0 ==> r5 */,          \
188
                    "I" (6) /* %1 ==> r6 */,          \
189
                    "I" (CYGARC_REG_HID0) /* %2 ==> HID0 */);
190
 
191
//-----------------------------------------------------------------------------
192
// Data cache line control
193
 
194
// Allocate cache lines for the given address range without reading its
195
// contents from memory.
196
//#define HAL_DCACHE_ALLOCATE( _base_ , _size_ )
197
 
198
// Write dirty cache lines to memory and invalidate the cache entries
199
// for the given address range.
200
#define HAL_DCACHE_FLUSH( _base_ , _size_ )                     \
201
    CYG_MACRO_START                                             \
202
    cyg_uint32 __base = (cyg_uint32) (_base_);                  \
203
    cyg_int32 __size = (cyg_int32) (_size_);                    \
204
    while (__size > 0) {                                        \
205
        asm volatile ("dcbf 0,%0;sync;" : : "r" (__base));      \
206
        __base += HAL_DCACHE_LINE_SIZE;                         \
207
        __size -= HAL_DCACHE_LINE_SIZE;                         \
208
    }                                                           \
209
    CYG_MACRO_END
210
 
211
 
212
// Invalidate cache lines in the given range without writing to memory.
213
// NOTE: The errata for the 603e processor indicates use of the dcbf
214
// command as the dcbi command will only invalidate modified blocks.
215
#define HAL_DCACHE_INVALIDATE( _base_ , _size_ )                \
216
    CYG_MACRO_START                                             \
217
    cyg_uint32 __base = (cyg_uint32) (_base_);                  \
218
    cyg_int32 __size = (cyg_int32) (_size_);                    \
219
    while (__size > 0) {                                        \
220
        asm volatile ("dcbf 0,%0;sync;" : : "r" (__base));      \
221
        __base += HAL_DCACHE_LINE_SIZE;                         \
222
        __size -= HAL_DCACHE_LINE_SIZE;                         \
223
    }                                                           \
224
    CYG_MACRO_END
225
 
226
// Write dirty cache lines to memory for the given address range.
227
#define HAL_DCACHE_STORE( _base_ , _size_ )                     \
228
    CYG_MACRO_START                                             \
229
    cyg_uint32 __base = (cyg_uint32) (_base_);                  \
230
    cyg_int32 __size = (cyg_int32) (_size_);                    \
231
    while (__size > 0) {                                        \
232
        asm volatile ("dcbst 0,%0;sync;" : : "r" (__base));     \
233
        __base += HAL_DCACHE_LINE_SIZE;                         \
234
        __size -= HAL_DCACHE_LINE_SIZE;                         \
235
    }                                                           \
236
    CYG_MACRO_END
237
 
238
// Preread the given range into the cache with the intention of reading
239
// from it later.
240
//#define HAL_DCACHE_READ_HINT( _base_ , _size_ )
241
 
242
// Preread the given range into the cache with the intention of writing
243
// to it later.
244
//#define HAL_DCACHE_WRITE_HINT( _base_ , _size_ )
245
 
246
// Allocate and zero the cache lines associated with the given range.
247
//#define HAL_DCACHE_ZERO( _base_ , _size_ )
248
 
249
//-----------------------------------------------------------------------------
250
// Global control of Instruction cache
251
 
252
// Enable the instruction cache
253
#define HAL_ICACHE_ENABLE()                 \
254
    CYG_MACRO_START                         \
255
    cyg_uint32 tmp1, tmp2;                  \
256
    asm volatile (                          \
257
        "mfspr %1, %2;"                     \
258
        "li %0, 0x4000;"                    \
259
        "rlwimi %1,%0,1,16,16;"             \
260
        "sync;"                             \
261
        "isync;"                            \
262
        "mtspr %2,%1;"                      \
263
        "isync;"                            \
264
        "sync;"                             \
265
        : "=r" (tmp1), "=r" (tmp2)          \
266
        : "I" (CYGARC_REG_HID0) /* %2 ==> HID0 */); \
267
    CYG_MACRO_END
268
 
269
// Disable the instruction cache
270
#define HAL_ICACHE_DISABLE()                          \
271
    CYG_MACRO_START                         \
272
    cyg_uint32 tmp1, tmp2;                  \
273
    asm volatile (                          \
274
        "mfspr %1, %2;"                     \
275
        "li %0, 0x0;"                       \
276
        "rlwimi %1,%0,0,16,16;"             \
277
        "sync;"                             \
278
        "isync;"                            \
279
        "mtspr %2,%1;"                      \
280
        "isync;"                            \
281
        "sync;"                             \
282
        : "=r" (tmp1), "=r" (tmp2)          \
283
        : "I" (CYGARC_REG_HID0) /* %2 ==> HID0 */); \
284
    CYG_MACRO_END
285
 
286
// Invalidate the entire cache
287
#if 1
288
#define HAL_ICACHE_INVALIDATE_ALL()                   \
289
    CYG_MACRO_START                                   \
290
    cyg_uint32 tmp1, tmp2;                            \
291
    asm volatile ("sync;"                             \
292
                  "mfspr %0, %2;"                     \
293
                  "ori   %1, %0, 0x8000;"             \
294
                  "mtspr %2, %1;"                     \
295
                  "isync;"                            \
296
                  "sync;"                             \
297
                  "ori   %1, %1, 0x0800;"             \
298
                  "mtspr %2, %1;"                     \
299
                  "isync;"                            \
300
                  "sync;"                             \
301
                  "mtspr %2, %0;"                     \
302
                  "isync;"                            \
303
                  "sync;"                             \
304
                  : "=r" (tmp1), "=r" (tmp2)          \
305
                  : "I" (CYGARC_REG_HID0) /* %3 ==> HID0 */);\
306
    CYG_MACRO_END
307
#else
308
#define HAL_ICACHE_INVALIDATE_ALL()                   \
309
    CYG_MACRO_START                                   \
310
    cyg_uint32 tmp1, tmp2;                            \
311
    asm volatile ("sync;"                             \
312
                  "mfspr %0, %2;"                     \
313
                  "ori   %0, %0, 0x0800;"             \
314
                  "isync;"                            \
315
                  "mtspr %2, %0;"                     \
316
                  "li    %1, 0;"                      \
317
                  "rlwimi %0,%1,0,20,20;"             \
318
                  "isync;"                            \
319
                  "mtspr %2, %0;"                     \
320
                  "isync;"                            \
321
                  "sync;"                             \
322
                  : "=r" (tmp1), "=r" (tmp2)          \
323
                  : "I" (CYGARC_REG_HID0) /* %3 ==> HID0 */);\
324
    CYG_MACRO_END
325
#endif
326
// Synchronize the contents of the cache with memory.
327
#define HAL_ICACHE_SYNC()                             \
328
    HAL_ICACHE_INVALIDATE_ALL()
329
 
330
 
331
// Query the state of the instruction cache
332
#define HAL_ICACHE_IS_ENABLED(_state_)                          \
333
    asm volatile ("mfspr  %0, %1;"                              \
334
                  "rlwinm %0,%0,17,31,31;"                      \
335
                  : "=r" (_state_) : "I" (CYGARC_REG_HID0))
336
 
337
 
338
// Set the instruction cache refill burst size
339
//#define HAL_ICACHE_BURST_SIZE(_size_)
340
 
341
// Load the contents of the given address range into the instruction cache
342
// and then lock the cache so that it stays there.
343
//#define HAL_ICACHE_LOCK(_base_, _size_)
344
 
345
// Undo a previous lock operation
346
//#define HAL_ICACHE_UNLOCK(_base_, _size_)
347
 
348
// Unlock entire cache
349
#define HAL_ICACHE_UNLOCK_ALL()                       \
350
    asm volatile ("isync;"                            \
351
                  "mfspr %0, %2;"                     \
352
                  "oris  %1, 0,0xFFFF;"               \
353
                  "ori   %1,%1,0xDFFF;"               \
354
                  "and   %0,%0,%1;"                   \
355
                  "isync;"                            \
356
                  "mtspr %2,%0;"                      \
357
                  "isync;"                            \
358
                  "sync;"                             \
359
                  : /* No output */                   \
360
                  : "I" (5) /* %0 ==> r5 */,          \
361
                    "I" (6) /* %1 ==> r6 */,          \
362
                    "I" (CYGARC_REG_HID0) /* %2 ==> HID0 */);
363
 
364
//-----------------------------------------------------------------------------
365
// Instruction cache line control
366
 
367
// Invalidate cache lines in the given range without writing to memory.
368
//#define HAL_ICACHE_INVALIDATE( _base_ , _size_ )
369
 
370
//-----------------------------------------------------------------------------
371
#endif // ifndef CYGONCE_VAR_CACHE_H
372
// 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.