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

Subversion Repositories openrisc_me

[/] [openrisc/] [trunk/] [rtos/] [ecos-2.0/] [packages/] [hal/] [sparclite/] [sleb/] [v2_0/] [include/] [hal_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_HAL_CACHE_H
2
#define CYGONCE_HAL_CACHE_H
3
 
4
//=============================================================================
5
//
6
//      hal_cache.h
7
//
8
//      HAL Cache control support (such as it is in the simulator)
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 Red Hat, 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 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, gthomas, hmt
47
// Contributors:        nickg, gthomas, hmt
48
// Date:        1999-01-28
49
// Purpose:     Define Interrupt support
50
// Description: The macros defined here provide the HAL APIs for handling
51
//              the caches.
52
//              
53
// Usage:
54
//              #include <cyg/hal/hal_cache.h>
55
//              ...
56
//              
57
//
58
//####DESCRIPTIONEND####
59
//
60
//=============================================================================
61
 
62
#include <pkgconf/hal.h>
63
#include <pkgconf/hal_sparclite.h>
64
 
65
#include <cyg/infra/cyg_type.h>
66
 
67
//-----------------------------------------------------------------------------
68
// SPARClite cache macros
69
 
70
// The MB6863x Control Registers are in Address Space 1:
71
#define HAL_SPARC_ASI_1_READ( addr, res )                                   \
72
    asm volatile(                                                           \
73
        "lda [ %1 ] 1, %0"                                                  \
74
        : "=r"(res)                                                         \
75
        : "r"(addr)                                                         \
76
    );
77
 
78
#define HAL_SPARC_ASI_1_WRITE( addr, val )                                  \
79
    asm volatile(                                                           \
80
        "sta %0, [ %1 ] 1"                                                  \
81
        :                                                                   \
82
        : "r"(val),"r"(addr)                                                \
83
    );
84
 
85
#define HAL_SPARC_MMCR_CBIR    0x00     // Cache/BusInterfaceUnit Control
86
#define HAL_SPARC_MMCR_LCR     0x04     // Lock Control Register
87
#define HAL_SPARC_MMCR_LCSR    0x08     // Lock Control Save Reg
88
#define HAL_SPARC_MMCR_CSR     0x0c     // Cache Status Reg
89
#define HAL_SPARC_MMCR_RLCR    0x10     // Restore Lock Control Register
90
 
91
#define HAL_SPARC_MMCR_CBIR_ICE  0x01   // Instruction Cache Enable
92
#define HAL_SPARC_MMCR_CBIR_GICL 0x02   // Global IC Lock
93
#define HAL_SPARC_MMCR_CBIR_DCE  0x04   // Data CE
94
#define HAL_SPARC_MMCR_CBIR_GDCL 0x08   // G Data CE
95
#define HAL_SPARC_MMCR_CBIR_PBE  0x10   // Prefetch Buffer Enable
96
#define HAL_SPARC_MMCR_CBIR_WBE  0x20   // Write BE
97
 
98
 
99
//-----------------------------------------------------------------------------
100
// Cache dimensions
101
 
102
// These definitions are suitable for any MB8683x processor:
103
//    The largest possible cachesize and "ways",
104
//    the smallest possible line size.
105
// This gives values that can correctly manipulate the cache by
106
// jumping on memory.
107
 
108
// Data cache
109
#define HAL_DCACHE_SIZE                 0x2000   // Size of data cache in bytes
110
#define HAL_DCACHE_LINE_SIZE            16       // Size of a data cache line
111
#define HAL_DCACHE_WAYS                 2        // Associativity of the cache
112
 
113
// Instruction cache
114
#define HAL_ICACHE_SIZE                 0x2000   // Size of cache in bytes
115
#define HAL_ICACHE_LINE_SIZE            16       // Size of a cache line
116
#define HAL_ICACHE_WAYS                 2        // Associativity of the cache
117
 
118
#define HAL_DCACHE_SETS (HAL_DCACHE_SIZE/(HAL_DCACHE_LINE_SIZE*HAL_DCACHE_WAYS))
119
#define HAL_ICACHE_SETS (HAL_ICACHE_SIZE/(HAL_ICACHE_LINE_SIZE*HAL_ICACHE_WAYS))
120
 
121
//-----------------------------------------------------------------------------
122
// Global control of data cache
123
 
124
// Enable the data cache
125
#define HAL_DCACHE_ENABLE() CYG_MACRO_START                                 \
126
    int _v_;                                                                \
127
    HAL_SPARC_ASI_1_READ( HAL_SPARC_MMCR_CBIR, _v_ );                       \
128
    _v_ |= HAL_SPARC_MMCR_CBIR_DCE;                                         \
129
    HAL_SPARC_ASI_1_WRITE( HAL_SPARC_MMCR_CBIR, _v_ );                      \
130
    asm volatile ( "nop; nop; nop; nop;" );                                 \
131
CYG_MACRO_END
132
 
133
// Disable the data cache
134
#define HAL_DCACHE_DISABLE() CYG_MACRO_START                                \
135
    int _v_;                                                                \
136
    HAL_SPARC_ASI_1_READ( HAL_SPARC_MMCR_CBIR, _v_ );                       \
137
    _v_ &=~ HAL_SPARC_MMCR_CBIR_DCE;                                        \
138
    HAL_SPARC_ASI_1_WRITE( HAL_SPARC_MMCR_CBIR, _v_ );                      \
139
    asm volatile ( "nop; nop; nop; nop;" );                                 \
140
CYG_MACRO_END
141
 
142
// Invalidate the entire cache
143
#define HAL_DCACHE_INVALIDATE_ALL() CYG_MACRO_START                         \
144
    asm volatile (                                                          \
145
        "set    3, %%l0;"                                                   \
146
        "set    0x00001000, %%l1;"                                          \
147
        "set    0x80001000, %%l2;"                                          \
148
        "sta    %%l0, [ %%l1 ] 0x0e;"                                       \
149
        "sta    %%l0, [ %%l2 ] 0x0e;"                                       \
150
        "nop;"                                                              \
151
        "nop;"                                                              \
152
        "nop;"                                                              \
153
        "nop" : : : "l0","l1","l2" );                                       \
154
CYG_MACRO_END
155
 
156
// Synchronize the contents of the cache with memory.
157
#define HAL_DCACHE_SYNC() CYG_MACRO_START                                   \
158
    /* read 8k from the ROM; that should do it... */                        \
159
    volatile cyg_uint32 *_p_ = (cyg_uint32 *)0;                             \
160
    volatile cyg_uint32 *_q_ = (cyg_uint32 *)HAL_DCACHE_SIZE;               \
161
    volatile cyg_uint32 _tmp_;                                              \
162
    for ( ; _p_ < _q_; _p_ ++ ) _tmp_ = *_q_;                               \
163
CYG_MACRO_END
164
 
165
// Query the state of the data cache
166
#define HAL_DCACHE_IS_ENABLED(_state_) CYG_MACRO_START                      \
167
    int _v_;                                                                \
168
    HAL_SPARC_ASI_1_READ( HAL_SPARC_MMCR_CBIR, _v_ );                       \
169
    (_state_) = (0 != (_v_ & HAL_SPARC_MMCR_CBIR_DCE));                     \
170
CYG_MACRO_END
171
 
172
 
173
// Set the data cache refill burst size
174
//#define HAL_DCACHE_BURST_SIZE(_size_)
175
 
176
// Set the data cache write mode
177
//#define HAL_DCACHE_WRITE_MODE( _mode_ )
178
 
179
//#define HAL_DCACHE_WRITETHRU_MODE       0
180
//#define HAL_DCACHE_WRITEBACK_MODE       1
181
 
182
// Load the contents of the given address range into the data cache
183
// and then lock the cache so that it stays there.
184
//#define HAL_DCACHE_LOCK(_base_, _size_)
185
 
186
// Undo a previous lock operation
187
//#define HAL_DCACHE_UNLOCK(_base_, _size_)
188
 
189
// Unlock entire cache
190
//#define HAL_DCACHE_UNLOCK_ALL()
191
 
192
//-----------------------------------------------------------------------------
193
// Data cache line control
194
 
195
// Allocate cache lines for the given address range without reading its
196
// contents from memory.
197
//#define HAL_DCACHE_ALLOCATE( _base_ , _size_ )
198
 
199
// Write dirty cache lines to memory and invalidate the cache entries
200
// for the given address range.
201
//#define HAL_DCACHE_FLUSH( _base_ , _size_ )
202
 
203
// Invalidate cache lines in the given range without writing to memory.
204
//#define HAL_DCACHE_INVALIDATE( _base_ , _size_ )
205
 
206
// Write dirty cache lines to memory for the given address range.
207
//#define HAL_DCACHE_STORE( _base_ , _size_ )
208
 
209
// Preread the given range into the cache with the intention of reading
210
// from it later.
211
//#define HAL_DCACHE_READ_HINT( _base_ , _size_ )
212
 
213
// Preread the given range into the cache with the intention of writing
214
// to it later.
215
//#define HAL_DCACHE_WRITE_HINT( _base_ , _size_ )
216
 
217
// Allocate and zero the cache lines associated with the given range.
218
//#define HAL_DCACHE_ZERO( _base_ , _size_ )
219
 
220
//-----------------------------------------------------------------------------
221
// Global control of Instruction cache - use Data cache controls since they
222
// are not separatable.
223
 
224
// Enable the data cache
225
#define HAL_ICACHE_ENABLE() CYG_MACRO_START                                 \
226
    int _v_;                                                                \
227
    HAL_SPARC_ASI_1_READ( HAL_SPARC_MMCR_CBIR, _v_ );                       \
228
    _v_ |= HAL_SPARC_MMCR_CBIR_ICE;                                         \
229
    HAL_SPARC_ASI_1_WRITE( HAL_SPARC_MMCR_CBIR, _v_ );                      \
230
    asm volatile ( "nop; nop; nop; nop;" );                                 \
231
CYG_MACRO_END
232
 
233
// Disable the data cache
234
#define HAL_ICACHE_DISABLE() CYG_MACRO_START                                \
235
    int _v_;                                                                \
236
    HAL_SPARC_ASI_1_READ( HAL_SPARC_MMCR_CBIR, _v_ );                       \
237
    _v_ &=~ HAL_SPARC_MMCR_CBIR_ICE;                                        \
238
    HAL_SPARC_ASI_1_WRITE( HAL_SPARC_MMCR_CBIR, _v_ );                      \
239
    asm volatile ( "nop; nop; nop; nop;" );                                 \
240
CYG_MACRO_END
241
 
242
// Invalidate the entire cache
243
#define HAL_ICACHE_INVALIDATE_ALL() CYG_MACRO_START                         \
244
    asm volatile (                                                          \
245
        "set    3, %%l0;"                                                   \
246
        "set    0x00001000, %%l1;"                                          \
247
        "set    0x80001000, %%l2;"                                          \
248
        "sta    %%l0, [ %%l1 ] 0x0c;"                                       \
249
        "sta    %%l0, [ %%l2 ] 0x0c;"                                       \
250
        "nop;"                                                              \
251
        "nop;"                                                              \
252
        "nop;"                                                              \
253
        "nop" : : : "l0","l1","l2" );                                       \
254
CYG_MACRO_END
255
 
256
// Synchronize the contents of the cache with memory.
257
#define HAL_ICACHE_SYNC() CYG_MACRO_START                                   \
258
    HAL_DCACHE_SYNC();           /* Ensure data is in memory */             \
259
    HAL_ICACHE_INVALIDATE_ALL(); /* Pick up new memory contents */          \
260
CYG_MACRO_END
261
 
262
// Query the state of the instruction cache
263
#define HAL_ICACHE_IS_ENABLED(_state_) CYG_MACRO_START                      \
264
    int _v_;                                                                \
265
    HAL_SPARC_ASI_1_READ( HAL_SPARC_MMCR_CBIR, _v_ );                       \
266
    (_state_) = (0 != (_v_ & HAL_SPARC_MMCR_CBIR_ICE));                     \
267
CYG_MACRO_END
268
 
269
// Set the instruction cache refill burst size
270
//#define HAL_ICACHE_BURST_SIZE(_size_)
271
 
272
// Load the contents of the given address range into the instruction cache
273
// and then lock the cache so that it stays there.
274
//#define HAL_ICACHE_LOCK(_base_, _size_)
275
 
276
// Undo a previous lock operation
277
//#define HAL_ICACHE_UNLOCK(_base_, _size_)
278
 
279
// Unlock entire cache
280
//#define HAL_ICACHE_UNLOCK_ALL()
281
 
282
//-----------------------------------------------------------------------------
283
// Instruction cache line control
284
 
285
// Invalidate cache lines in the given range without writing to memory.
286
//#define HAL_ICACHE_INVALIDATE( _base_ , _size_ )
287
 
288
//-----------------------------------------------------------------------------
289
#endif // ifndef CYGONCE_HAL_CACHE_H
290
// End of hal_cache.h

powered by: WebSVN 2.1.0

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