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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [packages/] [hal/] [mips/] [mips32/] [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_IMP_CACHE_H
2
#define CYGONCE_IMP_CACHE_H
3
 
4
//=============================================================================
5
//
6
//      imp_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
46
// Contributors:        nickg, dmoseley
47
// Date:        1998-02-17
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/imp_cache.h>
53
//              ...
54
//              
55
//
56
//####DESCRIPTIONEND####
57
//
58
//=============================================================================
59
 
60
#include <pkgconf/hal.h>
61
#include <cyg/infra/cyg_type.h>
62
 
63
#include <cyg/hal/mips-regs.h>
64
#include <cyg/hal/hal_arch.h>
65
#include <cyg/hal/plf_cache.h>
66
#include <cyg/hal/var_arch.h>
67
 
68
#ifdef CYGHWR_HAL_MIPS_MIPS32_CORE_4Kc
69
 
70
//-----------------------------------------------------------------------------
71
// Cache dimensions
72
 
73
// Data cache
74
#define HAL_DCACHE_SIZE                 16384   // Size of data cache in bytes
75
#define HAL_DCACHE_LINE_SIZE            16      // Size of a data cache line
76
#define HAL_DCACHE_WAYS                 4       // Associativity of the cache
77
 
78
// Instruction cache
79
#define HAL_ICACHE_SIZE                 16384   // Size of cache in bytes
80
#define HAL_ICACHE_LINE_SIZE            16      // Size of a cache line
81
#define HAL_ICACHE_WAYS                 4       // Associativity of the cache
82
 
83
#define HAL_DCACHE_SETS (HAL_DCACHE_SIZE/(HAL_DCACHE_LINE_SIZE*HAL_DCACHE_WAYS))
84
#define HAL_ICACHE_SETS (HAL_ICACHE_SIZE/(HAL_ICACHE_LINE_SIZE*HAL_ICACHE_WAYS))
85
 
86
#define HAL_DCACHE_WRITETHRU_MODE       1
87
#define HAL_DCACHE_WRITEBACK_MODE       0
88
 
89
#else
90
 
91
#error Unknown MIPS32 Variant
92
 
93
#endif
94
 
95
//-----------------------------------------------------------------------------
96
// General cache defines.
97
#define HAL_CLEAR_TAGLO()  asm volatile (" mtc0 $0, $28;" \
98
                                             " nop;"      \
99
                                             " nop;"      \
100
                                             " nop;")
101
#define HAL_CLEAR_TAGHI()  asm volatile (" mtc0 $0, $29;" \
102
                                             " nop;"      \
103
                                             " nop;"      \
104
                                             " nop;")
105
 
106
/* Cache instruction opcodes */
107
#define HAL_CACHE_OP(which, op)             (which | (op << 2))
108
 
109
#define HAL_WHICH_ICACHE                    0x0
110
#define HAL_WHICH_DCACHE                    0x1
111
 
112
#define HAL_INDEX_INVALIDATE                0x0
113
#define HAL_INDEX_LOAD_TAG                  0x1
114
#define HAL_INDEX_STORE_TAG                 0x2
115
#define HAL_HIT_INVALIDATE                  0x4
116
#define HAL_ICACHE_FILL                     0x5
117
#define HAL_DCACHE_HIT_INVALIDATE           0x5
118
#define HAL_DCACHE_HIT_WRITEBACK            0x6
119
#define HAL_FETCH_AND_LOCK                  0x7
120
 
121
//-----------------------------------------------------------------------------
122
// Global control of data cache
123
 
124
// Invalidate the entire cache
125
#define HAL_DCACHE_INVALIDATE_ALL_DEFINED
126
#define HAL_DCACHE_INVALIDATE_ALL()                                                     \
127
    CYG_MACRO_START                                                                     \
128
    register volatile CYG_BYTE *addr;                                                   \
129
    HAL_CLEAR_TAGLO();                                                                  \
130
    HAL_CLEAR_TAGHI();                                                                  \
131
    for (addr = (CYG_BYTE *)CYGARC_KSEG_CACHED_BASE;                                    \
132
         addr < (CYG_BYTE *)(CYGARC_KSEG_CACHED_BASE + HAL_DCACHE_SIZE);                \
133
         addr += HAL_DCACHE_LINE_SIZE )                                                 \
134
    {                                                                                   \
135
        asm volatile (" cache %0, 0(%1)"                                                \
136
                      :                                                                 \
137
                      : "I" (HAL_CACHE_OP(HAL_WHICH_DCACHE, HAL_INDEX_STORE_TAG)),      \
138
                        "r"(addr));                                                     \
139
    }                                                                                   \
140
    CYG_MACRO_END
141
 
142
// Synchronize the contents of the cache with memory.
143
extern void hal_dcache_sync(void);
144
#define HAL_DCACHE_SYNC_DEFINED
145
#define HAL_DCACHE_SYNC() hal_dcache_sync()
146
 
147
// Set the data cache refill burst size
148
//#define HAL_DCACHE_BURST_SIZE(_asize_)
149
 
150
// Set the data cache write mode
151
//#define HAL_DCACHE_WRITE_MODE( _mode_ )
152
 
153
// Load the contents of the given address range into the data cache
154
// and then lock the cache so that it stays there.
155
#define HAL_DCACHE_LOCK_DEFINED
156
#define HAL_DCACHE_LOCK(_base_, _asize_)                                                \
157
    CYG_MACRO_START                                                                     \
158
    register CYG_ADDRESS _baddr_ = (CYG_ADDRESS)(_base_);                               \
159
    register CYG_ADDRESS _addr_ = (CYG_ADDRESS)(_base_);                                \
160
    register CYG_WORD _size_ = (_asize_);                                               \
161
    for( ; _addr_ <= _baddr_+_size_; _addr_ += HAL_DCACHE_LINE_SIZE )                   \
162
      asm volatile (" cache %0, 0(%1)"                                                  \
163
                    :                                                                   \
164
                    : "I" (HAL_CACHE_OP(HAL_WHICH_DCACHE, HAL_FETCH_AND_LOCK)),         \
165
                      "r"(_addr_));                                                     \
166
    CYG_MACRO_END
167
 
168
// Undo a previous lock operation
169
#define HAL_DCACHE_UNLOCK_DEFINED
170
#define HAL_DCACHE_UNLOCK(_base_, _asize_)                                              \
171
    CYG_MACRO_START                                                                     \
172
    register CYG_ADDRESS _baddr_ = (CYG_ADDRESS)(_base_);                               \
173
    register CYG_ADDRESS _addr_ = (CYG_ADDRESS)(_base_);                                \
174
    register CYG_WORD _size_ = (_asize_);                                               \
175
    for( ; _addr_ <= _baddr_+_size_; _addr_ += HAL_DCACHE_LINE_SIZE )                   \
176
      asm volatile (" cache %0, 0(%1)"                                                  \
177
                    :                                                                   \
178
                    : "I" (HAL_CACHE_OP(HAL_WHICH_DCACHE, HAL_HIT_INVALIDATE)),         \
179
                      "r"(_addr_));                                                     \
180
    CYG_MACRO_END
181
 
182
// Unlock entire cache
183
#define HAL_DCACHE_UNLOCK_ALL_DEFINED
184
#define HAL_DCACHE_UNLOCK_ALL() HAL_DCACHE_UNLOCK(0,HAL_DCACHE_SIZE)
185
 
186
 
187
//-----------------------------------------------------------------------------
188
// Data cache line control
189
 
190
// Allocate cache lines for the given address range without reading its
191
// contents from memory.
192
//#define HAL_DCACHE_ALLOCATE( _base_ , _asize_ )
193
 
194
// Write dirty cache lines to memory and invalidate the cache entries
195
// for the given address range.
196
#define HAL_DCACHE_FLUSH_DEFINED
197
#if HAL_DCACHE_WRITETHRU_MODE == 1
198
// No need to flush a writethrough cache
199
#define HAL_DCACHE_FLUSH( _base_ , _asize_ )
200
#else
201
#error HAL_DCACHE_FLUSH undefined for MIPS32 writeback cache
202
#endif
203
 
204
// Write dirty cache lines to memory for the given address range.
205
#define HAL_DCACHE_STORE_DEFINED
206
#if HAL_DCACHE_WRITETHRU_MODE == 1
207
// No need to store a writethrough cache
208
#define HAL_DCACHE_STORE( _base_ , _asize_ )
209
#else
210
#error HAL_DCACHE_STORE undefined for MIPS32 writeback cache
211
#endif
212
 
213
// Invalidate cache lines in the given range without writing to memory.
214
#define HAL_DCACHE_INVALIDATE_DEFINED
215
#define HAL_DCACHE_INVALIDATE( _base_ , _asize_ )                                       \
216
    CYG_MACRO_START                                                                     \
217
    register CYG_ADDRESS _baddr_ = (CYG_ADDRESS)(_base_);                               \
218
    register CYG_ADDRESS _addr_ = (CYG_ADDRESS)(_base_);                                \
219
    register CYG_WORD _size_ = (_asize_);                                               \
220
    for( ; _addr_ <= _baddr_+_size_; _addr_ += HAL_DCACHE_LINE_SIZE )                   \
221
      asm volatile (" cache %0, 0(%1)"                                                  \
222
                    :                                                                   \
223
                    : "I" (HAL_CACHE_OP(HAL_WHICH_DCACHE, HAL_HIT_INVALIDATE)),         \
224
                      "r"(_addr_));                                                       \
225
    CYG_MACRO_END
226
 
227
 
228
 
229
 
230
 
231
 
232
//-----------------------------------------------------------------------------
233
// Global control of Instruction cache
234
 
235
// Invalidate the entire cache
236
#define HAL_ICACHE_INVALIDATE_ALL_DEFINED
237
#define HAL_ICACHE_INVALIDATE_ALL()                                                     \
238
    CYG_MACRO_START                                                                     \
239
    register volatile CYG_BYTE *addr;                                                   \
240
    HAL_CLEAR_TAGLO();                                                                  \
241
    HAL_CLEAR_TAGHI();                                                                  \
242
    for (addr = (CYG_BYTE *)CYGARC_KSEG_CACHED_BASE;                                    \
243
         addr < (CYG_BYTE *)(CYGARC_KSEG_CACHED_BASE + HAL_ICACHE_SIZE);                \
244
         addr += HAL_ICACHE_LINE_SIZE )                                                 \
245
    {                                                                                   \
246
        asm volatile (" cache %0, 0(%1)"                                                \
247
                      :                                                                 \
248
                      : "I" (HAL_CACHE_OP(HAL_WHICH_ICACHE, HAL_INDEX_STORE_TAG)),      \
249
                        "r"(addr));                                                     \
250
    }                                                                                   \
251
    CYG_MACRO_END
252
 
253
// Synchronize the contents of the cache with memory.
254
extern void hal_icache_sync(void);
255
#define HAL_ICACHE_SYNC_DEFINED
256
#define HAL_ICACHE_SYNC() hal_icache_sync()
257
 
258
// Set the instruction cache refill burst size
259
//#define HAL_ICACHE_BURST_SIZE(_asize_)
260
 
261
// Load the contents of the given address range into the data cache
262
// and then lock the cache so that it stays there.
263
#define HAL_ICACHE_LOCK_DEFINED
264
#define HAL_ICACHE_LOCK(_base_, _asize_)                                                \
265
    CYG_MACRO_START                                                                     \
266
    register CYG_ADDRESS _baddr_ = (CYG_ADDRESS)(_base_);                               \
267
    register CYG_ADDRESS _addr_ = (CYG_ADDRESS)(_base_);                                \
268
    register CYG_WORD _size_ = (_asize_);                                               \
269
    for( ; _addr_ <= _baddr_+_size_; _addr_ += HAL_ICACHE_LINE_SIZE )                   \
270
      asm volatile (" cache %0, 0(%1)"                                                  \
271
                    :                                                                   \
272
                    : "I" (HAL_CACHE_OP(HAL_WHICH_ICACHE, HAL_FETCH_AND_LOCK)),         \
273
                      "r"(_addr_));                                                     \
274
    CYG_MACRO_END
275
 
276
// Undo a previous lock operation
277
#define HAL_ICACHE_UNLOCK_DEFINED
278
#define HAL_ICACHE_UNLOCK(_base_, _asize_)                                              \
279
    CYG_MACRO_START                                                                     \
280
    register CYG_ADDRESS _baddr_ = (CYG_ADDRESS)(_base_);                               \
281
    register CYG_ADDRESS _addr_ = (CYG_ADDRESS)(_base_);                                \
282
    register CYG_WORD _size_ = (_asize_);                                               \
283
    for( ; _addr_ <= _baddr_+_size_; _addr_ += HAL_ICACHE_LINE_SIZE )                   \
284
      asm volatile (" cache %0, 0(%1)"                                                  \
285
                    :                                                                   \
286
                    : "I" (HAL_CACHE_OP(HAL_WHICH_ICACHE, HAL_HIT_INVALIDATE)),         \
287
                      "r"(_addr_));                                                     \
288
    CYG_MACRO_END
289
 
290
// Unlock entire cache
291
#define HAL_ICACHE_UNLOCK_ALL_DEFINED
292
#define HAL_ICACHE_UNLOCK_ALL() HAL_ICACHE_UNLOCK(0,HAL_ICACHE_SIZE)
293
 
294
//-----------------------------------------------------------------------------
295
// Instruction cache line control
296
 
297
// Invalidate cache lines in the given range without writing to memory.
298
#define HAL_ICACHE_INVALIDATE_DEFINED
299
#define HAL_ICACHE_INVALIDATE( _base_ , _asize_ )                                       \
300
    CYG_MACRO_START                                                                     \
301
    register CYG_ADDRESS _baddr_ = (CYG_ADDRESS)(_base_);                               \
302
    register CYG_ADDRESS _addr_ = (CYG_ADDRESS)(_base_);                                \
303
    register CYG_WORD _size_ = (_asize_);                                               \
304
    for( ; _addr_ <= _baddr_+_size_; _addr_ += HAL_ICACHE_LINE_SIZE )                   \
305
      asm volatile (" cache %0, 0(%1)"                                                  \
306
                    :                                                                   \
307
                    : "I" (HAL_CACHE_OP(HAL_WHICH_ICACHE, HAL_HIT_INVALIDATE)),         \
308
                      "r"(_addr_));                                                     \
309
    CYG_MACRO_END
310
 
311
//-----------------------------------------------------------------------------
312
#endif // ifndef CYGONCE_IMP_CACHE_H
313
// End of imp_cache.h

powered by: WebSVN 2.1.0

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