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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [packages/] [hal/] [mips/] [tx39/] [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
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/plf_cache.h>
64
 
65
//=============================================================================
66
// Toshiba TX3904
67
 
68
#ifdef CYGPKG_HAL_MIPS_TX3904
69
 
70
//-----------------------------------------------------------------------------
71
// Cache dimensions
72
 
73
// Data cache
74
#define HAL_DCACHE_SIZE                 1024    // Size of data cache in bytes
75
#define HAL_DCACHE_LINE_SIZE            4       // Size of a data cache line
76
#define HAL_DCACHE_WAYS                 2       // Associativity of the cache
77
 
78
// Instruction cache
79
#define HAL_ICACHE_SIZE                 4096    // Size of cache in bytes
80
#define HAL_ICACHE_LINE_SIZE            16      // Size of a cache line
81
#define HAL_ICACHE_WAYS                 1       // 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
//-----------------------------------------------------------------------------
87
// Global control of data cache
88
 
89
// Enable the data cache
90
// This uses a bit in the config register, which is TX39 specific.
91
#define HAL_DCACHE_ENABLE_DEFINED
92
#define HAL_DCACHE_ENABLE()                     \
93
{                                               \
94
    asm volatile ("mfc0 $2,$3;"                 \
95
                  "ori  $2,$2,0x0010;"          \
96
                  "mtc0 $2,$3;"                 \
97
                  :                             \
98
                  :                             \
99
                  : "$2"                        \
100
                 );                             \
101
                                                \
102
}
103
 
104
// Disable the data cache
105
#define HAL_DCACHE_DISABLE_DEFINED
106
#define HAL_DCACHE_DISABLE()                    \
107
{                                               \
108
    asm volatile ("mfc0 $2,$3;"                 \
109
                  "la   $3,0xFFFFFFEF;"         \
110
                  "and  $2,$2,$3;"              \
111
                  "mtc0 $2,$3;"                 \
112
                  :                             \
113
                  :                             \
114
                  : "$2", "$3"                  \
115
                 );                             \
116
                                                \
117
}
118
 
119
 
120
// Invalidate the entire cache
121
// The TX39 only has hit-invalidate on the DCACHE, not
122
// index-invalidate, so we cannot just empty the cache out without
123
// knowing what is in it. This is annoying. So, the best we can do is
124
// fill the cache with data that is unlikely to be there
125
// otherwise. Hence we read bytes from the ROM space since this is
126
// most likely to be code, and will not get out of sync even if it is not.
127
#define HAL_DCACHE_INVALIDATE_ALL_DEFINED
128
#define HAL_DCACHE_INVALIDATE_ALL()                                     \
129
{                                                                       \
130
    volatile CYG_BYTE *addr = (CYG_BYTE *)(0x9fc00000);                 \
131
    volatile CYG_BYTE tmp = 0;                                          \
132
    int i;                                                              \
133
    for( i = 0; i < (HAL_DCACHE_SIZE*2); i += HAL_DCACHE_LINE_SIZE )    \
134
    {                                                                   \
135
        tmp = addr[i];                                                  \
136
    }                                                                   \
137
}
138
 
139
// Synchronize the contents of the cache with memory.
140
#define HAL_DCACHE_SYNC_DEFINED
141
#define HAL_DCACHE_SYNC() HAL_DCACHE_INVALIDATE_ALL()
142
 
143
// Set the data cache refill burst size
144
//#define HAL_DCACHE_BURST_SIZE(_size_)
145
 
146
// Set the data cache write mode
147
//#define HAL_DCACHE_WRITE_MODE( _mode_ )
148
 
149
//#define HAL_DCACHE_WRITETHRU_MODE       0
150
//#define HAL_DCACHE_WRITEBACK_MODE       1
151
 
152
// Load the contents of the given address range into the data cache
153
// and then lock the cache so that it stays there.
154
#define HAL_DCACHE_LOCK_DEFINED
155
#define HAL_DCACHE_LOCK(_base_, _size_)         \
156
{                                               \
157
    asm volatile ("mfc0 $2,$7;"                 \
158
                  "ori  $2,$2,0x0100;"          \
159
                  "mtc0 $2,$7;"                 \
160
                  :                             \
161
                  :                             \
162
                  : "$2"                        \
163
                 );                             \
164
}
165
 
166
// Undo a previous lock operation
167
#define HAL_DCACHE_UNLOCK_DEFINED
168
#define HAL_DCACHE_UNLOCK(_base_, _size_)       \
169
{                                               \
170
    asm volatile ("mfc0 $2,$7;"                 \
171
                  "la   $3,0xFFFFFEFF;"         \
172
                  "and  $2,$2,$3;"              \
173
                  "mtc0 $2,$7;"                 \
174
                  :                             \
175
                  :                             \
176
                  : "$2", "$3"                  \
177
                 );                             \
178
}
179
 
180
// Unlock entire cache
181
#define HAL_DCACHE_UNLOCK_ALL_DEFINED
182
#define HAL_DCACHE_UNLOCK_ALL() HAL_DCACHE_UNLOCK(0,HAL_DCACHE_SIZE)
183
 
184
 
185
//-----------------------------------------------------------------------------
186
// Data cache line control
187
 
188
// Allocate cache lines for the given address range without reading its
189
// contents from memory.
190
//#define HAL_DCACHE_ALLOCATE( _base_ , _size_ )
191
 
192
// Write dirty cache lines to memory and invalidate the cache entries
193
// for the given address range.
194
//#define HAL_DCACHE_FLUSH( _base_ , _size_ )
195
#define HAL_DCACHE_FLUSH_DEFINED        // Ensure no default definition
196
 
197
// Write dirty cache lines to memory for the given address range.
198
//#define HAL_DCACHE_STORE( _base_ , _size_ )
199
#define HAL_DCACHE_STORE_DEFINED        // Disable default definition
200
 
201
//-----------------------------------------------------------------------------
202
// Global control of Instruction cache
203
 
204
// Enable the instruction cache
205
// This uses a bit in the config register, which is TX39 specific.
206
#define HAL_ICACHE_ENABLE_DEFINED
207
#define HAL_ICACHE_ENABLE()                     \
208
{                                               \
209
    asm volatile ("mfc0 $2,$3;"                 \
210
                  "ori  $2,$2,0x0020;"          \
211
                  "mtc0 $2,$3;"                 \
212
                  :                             \
213
                  :                             \
214
                  : "$2"                        \
215
                 );                             \
216
                                                \
217
}
218
 
219
// Disable the instruction cache
220
#define HAL_ICACHE_DISABLE_DEFINED
221
#define HAL_ICACHE_DISABLE()                    \
222
{                                               \
223
    asm volatile ("mfc0 $2,$3;"                 \
224
                  "la   $3,0xFFFFFFDF;"         \
225
                  "and  $2,$2,$3;"              \
226
                  "mtc0 $2,$3;"                 \
227
                  "j    1f;"                    \
228
                  "nop;"                        \
229
                  ".balign 16,0;"               \
230
                  "1:;"                         \
231
                  :                             \
232
                  :                             \
233
                  : "$2", "$3"                  \
234
                 );                             \
235
                                                \
236
}
237
 
238
// Load the contents of the given address range into the instruction cache
239
// and then lock the cache so that it stays there.
240
#define HAL_ICACHE_LOCK_DEFINED
241
#define HAL_ICACHE_LOCK(_base_, _size_)         \
242
{                                               \
243
    asm volatile ("mfc0 $2,$7;"                 \
244
                  "ori  $2,$2,0x0200;"          \
245
                  "mtc0 $2,$7;"                 \
246
                  :                             \
247
                  :                             \
248
                  : "$2"                        \
249
                 );                             \
250
}
251
 
252
// Undo a previous lock operation
253
#define HAL_ICACHE_UNLOCK_DEFINED
254
#define HAL_ICACHE_UNLOCK(_base_, _size_)       \
255
{                                               \
256
    asm volatile ("mfc0 $2,$7;"                 \
257
                  "la   $3,0xFFFFFDFF;"         \
258
                  "and  $2,$2,$3;"              \
259
                  "mtc0 $2,$7;"                 \
260
                  :                             \
261
                  :                             \
262
                  : "$2", "$3"                  \
263
                 );                             \
264
}
265
 
266
// Unlock entire cache
267
#define HAL_ICACHE_UNLOCK_ALL_DEFINED
268
#define HAL_ICACHE_UNLOCK_ALL() HAL_ICACHE_UNLOCK(0, HAL_ICACHE_SIZE)
269
 
270
//-----------------------------------------------------------------------------
271
// Instruction cache line control
272
// On the TX39, the instruction cache must be disabled to use the index-invalidate
273
// cache operation.
274
 
275
// Invalidate the entire cache
276
// This uses the index-invalidate cache operation.
277
#define HAL_ICACHE_INVALIDATE_ALL_DEFINED
278
#define HAL_ICACHE_INVALIDATE_ALL()                                             \
279
{                                                                               \
280
    register CYG_ADDRESS _baddr_ = 0x80000000;                                  \
281
    register CYG_ADDRESS _addr_ = 0x80000000;                                   \
282
    register CYG_WORD _state_;                                                  \
283
    HAL_ICACHE_IS_ENABLED(_state_);                                             \
284
    HAL_ICACHE_DISABLE();                                                       \
285
    for( ; _addr_ < _baddr_+HAL_ICACHE_SIZE; _addr_ += HAL_ICACHE_LINE_SIZE )   \
286
    {                                                                           \
287
        asm volatile ("cache 0x00,0(%0)" : : "r"(_addr_) );                     \
288
    }                                                                           \
289
    if( _state_ ) HAL_ICACHE_ENABLE();                                          \
290
}
291
 
292
// Invalidate cache lines in the given range without writing to memory.
293
// This uses the index-invalidate cache operation since the TX39 does not
294
// have hit-invalidate on the instruction cache.
295
#define HAL_ICACHE_INVALIDATE_DEFINED
296
#define HAL_ICACHE_INVALIDATE( _base_ , _asize_ )                       \
297
{                                                                       \
298
    register CYG_ADDRESS _addr_ = (CYG_ADDRESS)(_base_);                \
299
    register CYG_WORD _size_ = (_asize_);                               \
300
    register CYG_WORD _state_;                                          \
301
    HAL_ICACHE_IS_ENABLED(_state_);                                     \
302
    HAL_ICACHE_DISABLE();                                               \
303
    for( ; _addr_ <= _addr_+_size_; _addr_ += HAL_ICACHE_LINE_SIZE )    \
304
    {                                                                   \
305
        asm volatile ("cache 0,0(%0)" : : "r"(_addr_) );                \
306
    }                                                                   \
307
    if( _state_ ) HAL_ICACHE_ENABLE();                                  \
308
}
309
 
310
#endif // CYGPKG_HAL_MIPS_TX3904
311
 
312
//-----------------------------------------------------------------------------
313
#endif // ifndef CYGONCE_IMP_CACHE_H
314
// End of imp_cache.h

powered by: WebSVN 2.1.0

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