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

Subversion Repositories openrisc_me

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

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
//
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 version.
18
//
19
// eCos is distributed in the hope that it will be useful, but WITHOUT ANY
20
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
21
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
22
// for more details.
23
//
24
// You should have received a copy of the GNU General Public License along
25
// with eCos; if not, write to the Free Software Foundation, Inc.,
26
// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
27
//
28
// As a special exception, if other files instantiate templates or use macros
29
// or inline functions from this file, or you compile this file and link it
30
// with other works to produce a work based on this file, this file does not
31
// by itself cause the resulting work to be covered by the GNU General Public
32
// License. However the source code for this file must still be made available
33
// in accordance with section (3) of the GNU General Public License.
34
//
35
// This exception does not invalidate any other reasons why a work based on
36
// this file might be covered by the GNU General Public License.
37
//
38
// Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.
39
// at http://sources.redhat.com/ecos/ecos-license/
40
// -------------------------------------------
41
//####ECOSGPLCOPYRIGHTEND####
42
//=============================================================================
43
//#####DESCRIPTIONBEGIN####
44
//
45
// Author(s):   nickg
46
// Contributors:nickg, jskov
47
// Date:        2000-04-02
48
// Purpose:     Variant cache control API
49
// Description: The macros defined here provide the HAL APIs for handling
50
//              cache control operations on the MPC8xx variant CPUs.
51
// Usage:       Is included via the architecture cache header:
52
//              #include <cyg/hal/hal_cache.h>
53
//              ...
54
//
55
//####DESCRIPTIONEND####
56
//
57
//=============================================================================
58
 
59
#include <pkgconf/hal.h>
60
#include <cyg/infra/cyg_type.h>
61
 
62
#include <cyg/hal/ppc_regs.h>
63
 
64
#include <cyg/hal/plf_cache.h>
65
 
66
 
67
//-----------------------------------------------------------------------------
68
// Cache dimensions - these vary between the 8xx sub-models
69
 
70
#if defined(CYGPKG_HAL_POWERPC_MPC860)
71
// Data cache
72
#define HAL_DCACHE_SIZE                 4096    // Size of data cache in bytes
73
#define HAL_DCACHE_LINE_SIZE            16      // Size of a data cache line
74
#define HAL_DCACHE_WAYS                 2       // Associativity of the cache
75
 
76
// Instruction cache
77
#define HAL_ICACHE_SIZE                 4096    // Size of cache in bytes
78
#define HAL_ICACHE_LINE_SIZE            16      // Size of a cache line
79
#define HAL_ICACHE_WAYS                 2       // Associativity of the cache
80
#endif // defined(CYGPKG_HAL_POWERPC_MPC860)
81
 
82
#if defined(CYGPKG_HAL_POWERPC_MPC823) || defined(CYGPKG_HAL_POWERPC_MPC850)
83
// Data cache
84
#define HAL_DCACHE_SIZE                 1024    // Size of data cache in bytes
85
#define HAL_DCACHE_LINE_SIZE            16      // Size of a data cache line
86
#define HAL_DCACHE_WAYS                 2       // Associativity of the cache
87
 
88
// Instruction cache
89
#define HAL_ICACHE_SIZE                 2048    // Size of cache in bytes
90
#define HAL_ICACHE_LINE_SIZE            16      // Size of a cache line
91
#define HAL_ICACHE_WAYS                 2       // Associativity of the cache
92
#endif // defined(CYGPKG_HAL_POWERPC_MPC823) || defined(CYGPKG_HAL_POWERPC_MPC850)
93
 
94
#define HAL_DCACHE_SETS (HAL_DCACHE_SIZE/(HAL_DCACHE_LINE_SIZE*HAL_DCACHE_WAYS))
95
#define HAL_ICACHE_SETS (HAL_ICACHE_SIZE/(HAL_ICACHE_LINE_SIZE*HAL_ICACHE_WAYS))
96
 
97
//-----------------------------------------------------------------------------
98
// Global control of data cache
99
 
100
// Enable the data cache
101
#define HAL_DCACHE_ENABLE()                     \
102
    asm volatile ("sync;"                       \
103
                  "mtspr %0, %1;"               \
104
                  : : "I" (CYGARC_REG_DC_CST), "r" (CYGARC_REG_DC_CMD_CE))
105
 
106
// Disable the data cache
107
#define HAL_DCACHE_DISABLE()                    \
108
    asm volatile ("sync;"                       \
109
                  "mtspr %0, %1;"               \
110
                  : : "I" (CYGARC_REG_DC_CST), "r" (CYGARC_REG_DC_CMD_CD))
111
 
112
// Invalidate the entire cache
113
// Note: Any locked lines will not be invalidated.
114
#define HAL_DCACHE_INVALIDATE_ALL()                     \
115
    asm volatile ("sync;"                               \
116
                  "mtspr %0, %1;"                       \
117
                  : : "I" (CYGARC_REG_DC_CST),          \
118
                      "r" (CYGARC_REG_DC_CMD_IA))
119
 
120
// Synchronize the contents of the cache with memory.
121
#define HAL_DCACHE_SYNC()                                                     \
122
    CYG_MACRO_START                                                           \
123
    cyg_int32 i;                                                              \
124
    for (i = 0; i < HAL_DCACHE_SETS; i++){                                    \
125
        asm volatile ("sync;"                                                 \
126
                      "mtspr %0, %2;"                                         \
127
                      "mtspr %1, %4;"                                         \
128
                      "mtspr %0, %3;"                                         \
129
                      "mtspr %1, %4;"                                         \
130
                      : /* no output */                                       \
131
                      : /* %0 */ "I" (CYGARC_REG_DC_ADR),                     \
132
                        /* %1 */ "I" (CYGARC_REG_DC_CST),                     \
133
                        /* %2 */ "r" (CYGARC_REG_DC_ADR_WAY0                  \
134
                                      |(i << CYGARC_REG_DC_ADR_SETID_SHIFT)), \
135
                        /* %3 */ "r" (CYGARC_REG_DC_ADR_WAY1                  \
136
                                      |(i << CYGARC_REG_DC_ADR_SETID_SHIFT)), \
137
                        /* %4 */ "r" (CYGARC_REG_DC_CMD_FL));                 \
138
    }                                                                         \
139
    CYG_MACRO_END
140
 
141
// Query the state of the data cache
142
#define HAL_DCACHE_IS_ENABLED(_state_)                          \
143
    asm volatile ("mfspr  %0, %1;"                              \
144
                  "rlwinm %0,%0,1,31,31;"                       \
145
                  : "=r" (_state_) : "I" (CYGARC_REG_DC_CST))
146
 
147
// Set the data cache refill burst size
148
//#define HAL_DCACHE_BURST_SIZE(_size_)
149
 
150
// Set the data cache write mode
151
#define HAL_DCACHE_WRITE_MODE( _mode_ )                 \
152
    CYG_MACRO_START                                     \
153
    if (_mode_ == HAL_DCACHE_WRITETHRU_MODE) {          \
154
        asm volatile ("sync;"                           \
155
                  "mtspr %0, %1;"                       \
156
                  : : "I" (CYGARC_REG_DC_CST),          \
157
                      "r" (CYGARC_REG_DC_CMD_SW));      \
158
    }                                                   \
159
    if (_mode_ == HAL_DCACHE_WRITEBACK_MODE) {          \
160
        asm volatile ("sync;"                           \
161
                  "mtspr %0, %1;"                       \
162
                  : : "I" (CYGARC_REG_DC_CST),          \
163
                      "r" (CYGARC_REG_DC_CMD_CW));      \
164
    }                                                   \
165
    CYG_MACRO_END
166
 
167
#define HAL_DCACHE_WRITETHRU_MODE       0
168
#define HAL_DCACHE_WRITEBACK_MODE       1
169
 
170
 
171
// Load the contents of the given address range into the data cache 
172
// and then lock the cache so that it stays there.  
173
 
174
// Restrictions: This implementation only allows a single area to be
175
// locked at any one time. This area must be 2kB or less in size.
176
 
177
// Implementation: Flush entire cache, then invalidate it. This
178
// ensures that the fetched data go into way0.
179
 
180
#define HAL_DCACHE_LOCK(_base_, _size_)                                       \
181
    CYG_MACRO_START                                                           \
182
    cyg_int32 __scratch;                                                      \
183
    cyg_uint32 __base = (cyg_uint32)(_base_);                                 \
184
    cyg_int32 __l = ((__base / HAL_DCACHE_LINE_SIZE) % HAL_DCACHE_SETS);      \
185
    cyg_int32 __count = ((_size_) / HAL_DCACHE_LINE_SIZE);                    \
186
    HAL_DCACHE_DISABLE();                                                     \
187
    HAL_DCACHE_SYNC ();                                                       \
188
    HAL_DCACHE_INVALIDATE_ALL ();                                             \
189
    HAL_DCACHE_ENABLE();                                                      \
190
    do {                                                                      \
191
        asm volatile ("lbz   %0,0(%1);"                                       \
192
                      "sync;"                                                 \
193
                      "mtspr %2, %4;"                                         \
194
                      "mtspr %3, %5;"                                         \
195
                      : /* %0 */ "=&r" (__scratch)                            \
196
                      : /* %1 */ "b" (__base),                                \
197
                        /* %2 */ "I" (CYGARC_REG_DC_ADR),                     \
198
                        /* %3 */ "I" (CYGARC_REG_DC_CST),                     \
199
                        /* %4 */ "r" (CYGARC_REG_DC_ADR_WAY0                  \
200
                                      |(__l<<CYGARC_REG_DC_ADR_SETID_SHIFT)), \
201
                        /* %5 */ "r" (CYGARC_REG_DC_CMD_LL));                 \
202
        __l++;                                                                \
203
        __base += HAL_DCACHE_LINE_SIZE;                                       \
204
    } while (__count--);                                                      \
205
    CYG_MACRO_END
206
 
207
 
208
// Undo a previous lock operation
209
 
210
// Implementation: Unlocks entire cache.
211
 
212
#define HAL_DCACHE_UNLOCK(_base_, _size_)               \
213
    HAL_DCACHE_UNLOCK_ALL()
214
 
215
 
216
// Unlock entire cache
217
#define HAL_DCACHE_UNLOCK_ALL()                         \
218
    CYG_MACRO_START                                     \
219
    asm volatile ("sync;"                               \
220
                  "mtspr %0, %1;"                       \
221
                  : : "I" (CYGARC_REG_DC_CST),          \
222
                      "r" (CYGARC_REG_DC_CMD_UA));      \
223
    CYG_MACRO_END
224
 
225
 
226
 
227
//-----------------------------------------------------------------------------
228
// Data cache line control
229
 
230
// Allocate cache lines for the given address range without reading its
231
// contents from memory.
232
//#define HAL_DCACHE_ALLOCATE( _base_ , _size_ )
233
 
234
// Write dirty cache lines to memory and invalidate the cache entries
235
// for the given address range.
236
#define HAL_DCACHE_FLUSH( _base_ , _size_ )                     \
237
    CYG_MACRO_START                                             \
238
    cyg_uint32 __base = (cyg_uint32) (_base_);                  \
239
    cyg_int32 __size = (cyg_int32) (_size_);                    \
240
    while (__size > 0) {                                        \
241
        asm volatile ("dcbf 0,%0;sync;" : : "r" (__base));      \
242
        __base += HAL_DCACHE_LINE_SIZE;                         \
243
        __size -= HAL_DCACHE_LINE_SIZE;                         \
244
    }                                                           \
245
    CYG_MACRO_END
246
 
247
// Invalidate cache lines in the given range without writing to memory.
248
#define HAL_DCACHE_INVALIDATE( _base_ , _size_ )                \
249
    CYG_MACRO_START                                             \
250
    cyg_uint32 __base = (cyg_uint32) (_base_);                  \
251
    cyg_int32 __size = (cyg_int32) (_size_);                    \
252
    while (__size > 0) {                                        \
253
        asm volatile ("dcbi 0,%0;sync;" : : "r" (__base));      \
254
        __base += HAL_DCACHE_LINE_SIZE;                         \
255
        __size -= HAL_DCACHE_LINE_SIZE;                         \
256
    }                                                           \
257
    CYG_MACRO_END
258
 
259
// Write dirty cache lines to memory for the given address range.
260
#define HAL_DCACHE_STORE( _base_ , _size_ )                     \
261
    CYG_MACRO_START                                             \
262
    cyg_uint32 __base = (cyg_uint32) (_base_);                  \
263
    cyg_int32 __size = (cyg_int32) (_size_);                    \
264
    while (__size > 0) {                                        \
265
        asm volatile ("dcbst 0,%0;sync;" : : "r" (__base));     \
266
        __base += HAL_DCACHE_LINE_SIZE;                         \
267
        __size -= HAL_DCACHE_LINE_SIZE;                         \
268
    }                                                           \
269
    CYG_MACRO_END
270
 
271
// Preread the given range into the cache with the intention of reading
272
// from it later.
273
#define HAL_DCACHE_READ_HINT( _base_ , _size_ )                 \
274
    CYG_MACRO_START                                             \
275
    cyg_uint32 __base = (cyg_uint32) (_base_);                  \
276
    cyg_int32 __size = (cyg_int32) (_size_);                    \
277
    while (__size > 0) {                                        \
278
        asm volatile ("dcbt 0,%0;" : : "r" (__base));           \
279
        __base += HAL_DCACHE_LINE_SIZE;                         \
280
        __size -= HAL_DCACHE_LINE_SIZE;                         \
281
    }                                                           \
282
    CYG_MACRO_END
283
 
284
// Preread the given range into the cache with the intention of writing
285
// to it later.
286
#define HAL_DCACHE_WRITE_HINT( _base_ , _size_ )                \
287
    CYG_MACRO_START                                             \
288
    cyg_uint32 __base = (cyg_uint32) (_base_);                  \
289
    cyg_int32 __size = (cyg_int32) (_size_);                    \
290
    while (__size > 0) {                                        \
291
        asm volatile ("dcbtst 0,%0;" : : "r" (__base));         \
292
        __base += HAL_DCACHE_LINE_SIZE;                         \
293
        __size -= HAL_DCACHE_LINE_SIZE;                         \
294
    }                                                           \
295
    CYG_MACRO_END
296
 
297
// Allocate and zero the cache lines associated with the given range.
298
#define HAL_DCACHE_ZERO( _base_ , _size_ )                      \
299
    CYG_MACRO_START                                             \
300
    cyg_uint32 __base = (cyg_uint32) (_base_);                  \
301
    cyg_int32 __size = (cyg_int32) (_size_);                    \
302
    while (__size > 0) {                                        \
303
        asm volatile ("dcbz 0,%0;" : : "r" (__base));           \
304
        __base += HAL_DCACHE_LINE_SIZE;                         \
305
        __size -= HAL_DCACHE_LINE_SIZE;                         \
306
    }                                                           \
307
    CYG_MACRO_END
308
 
309
//-----------------------------------------------------------------------------
310
// Global control of Instruction cache
311
 
312
// Enable the instruction cache
313
#define HAL_ICACHE_ENABLE()                     \
314
    asm volatile ("isync;"                      \
315
                  "mtspr %0, %1;"               \
316
                  "isync"                       \
317
                  : : "I" (CYGARC_REG_IC_CST), "r" (CYGARC_REG_IC_CMD_CE))
318
 
319
// Disable the instruction cache
320
#define HAL_ICACHE_DISABLE()                    \
321
    asm volatile ("isync;"                      \
322
                  "mtspr %0, %1;"               \
323
                  "isync"                       \
324
                  : : "I" (CYGARC_REG_IC_CST), "r" (CYGARC_REG_IC_CMD_CD))
325
 
326
// Invalidate the entire cache
327
#define HAL_ICACHE_INVALIDATE_ALL()                     \
328
    asm volatile ("isync;"                              \
329
                  "mtspr %0, %1;"                       \
330
                  "isync"                               \
331
                  : : "I" (CYGARC_REG_IC_CST),          \
332
                      "r" (CYGARC_REG_IC_CMD_IA))
333
 
334
// Synchronize the contents of the cache with memory.
335
#define HAL_ICACHE_SYNC()                               \
336
    HAL_ICACHE_INVALIDATE_ALL()
337
 
338
// Query the state of the instruction cache
339
#define HAL_ICACHE_IS_ENABLED(_state_)                          \
340
    asm volatile ("mfspr  %0, %1;"                              \
341
                  "rlwinm %0,%0,1,31,31;"                       \
342
                  : "=r" (_state_) : "I" (CYGARC_REG_IC_CST))
343
 
344
// Set the instruction cache refill burst size
345
//#define HAL_ICACHE_BURST_SIZE(_size_)
346
 
347
 
348
// Load the contents of the given address range into the instruction cache
349
// and then lock the cache so that it stays there.
350
 
351
// Restrictions: This implementation only allows a single area to be
352
// locked at any one time. This area must be 2kB or less in size.
353
 
354
// Implementation: Flush entire cache, then invalidate it. This
355
// ensures that the fetched data go into way0.
356
 
357
#define HAL_ICACHE_LOCK(_base_, _size_)                                       \
358
    CYG_MACRO_START                                                           \
359
    unsigned long __base =                                                    \
360
        ((unsigned long) (_base_)) & ~(HAL_ICACHE_LINE_SIZE-1);               \
361
    int __count = ((_size_) / HAL_ICACHE_LINE_SIZE);                          \
362
    do {                                                                      \
363
        asm volatile ("mtspr %0, %2;"                                         \
364
                      "mtspr %1, %3;"                                         \
365
                      "isync;"                                                \
366
                      : /* no output */                                       \
367
                      : /* %0 */ "I" (CYGARC_REG_IC_ADR),                     \
368
                        /* %1 */ "I" (CYGARC_REG_IC_CST),                     \
369
                        /* %2 */ "r" (__base),                                \
370
                        /* %3 */ "r" (CYGARC_REG_IC_CMD_LL));                 \
371
        __base += HAL_ICACHE_LINE_SIZE;                                       \
372
    } while (__count--);                                                      \
373
    CYG_MACRO_END
374
 
375
// Undo a previous lock operation
376
 
377
// Implementation: Unlocks entire cache.
378
#define HAL_ICACHE_UNLOCK(_base_, _size_)       \
379
    HAL_ICACHE_UNLOCK_ALL()
380
 
381
// Unlock entire cache
382
#define HAL_ICACHE_UNLOCK_ALL()                         \
383
    CYG_MACRO_START                                     \
384
    asm volatile ("sync;"                               \
385
                  "mtspr %0, %1;"                       \
386
                  : : "I" (CYGARC_REG_IC_CST),          \
387
                      "r" (CYGARC_REG_IC_CMD_UA));      \
388
    CYG_MACRO_END
389
 
390
//-----------------------------------------------------------------------------
391
// Instruction cache line control
392
 
393
// Invalidate cache lines in the given range without writing to memory.
394
//#define HAL_ICACHE_INVALIDATE( _base_ , _size_ )
395
 
396
//-----------------------------------------------------------------------------
397
#endif // ifndef CYGONCE_VAR_CACHE_H
398
// 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.