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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [packages/] [hal/] [openrisc/] [arch/] [current/] [include/] [hal_cache.h] - Blame information for rev 791

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 786 skrzyp
#ifndef CYGONCE_HAL_CACHE_H
2
#define CYGONCE_HAL_CACHE_H
3
 
4
//=============================================================================
5
//
6
//      hal_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):   Scott Furman
46 791 skrzyp
// Contributors:Piotr Skrzypek
47 786 skrzyp
// Date:        2003-02-08
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/hal_cache.h>
53
//              ...
54
//              
55
//
56
//####DESCRIPTIONEND####
57
//
58
//=============================================================================
59
 
60 791 skrzyp
#ifndef __ASSEMBLER__
61 786 skrzyp
 
62 791 skrzyp
#include <cyg/hal/plf_cache.h>
63
#include <cyg/hal/hal_arch.h>
64 786 skrzyp
 
65 791 skrzyp
//-----------------------------------------------------------------------------
66 786 skrzyp
// Data cache
67 791 skrzyp
//
68
// If HAL_DCACHE_SIZE is undefined, assume that device does not implement
69
// data cache. Provide set of empty macros.
70
#ifndef HAL_DCACHE_SIZE
71 786 skrzyp
 
72 791 skrzyp
//Enable the data cache
73
#define HAL_DCACHE_ENABLE()
74 786 skrzyp
 
75 791 skrzyp
//Disable the data cache
76
#define HAL_DCACHE_DISABLE()
77 786 skrzyp
 
78 791 skrzyp
//Invalidate the entire cache
79
#define HAL_DCACHE_INVALIDATE_ALL()
80 786 skrzyp
 
81 791 skrzyp
//Synchronize the contents of the cache with memory
82
#define HAL_DCACHE_SYNC()
83 786 skrzyp
 
84 791 skrzyp
// Query the state of the data cache
85
#define HAL_DCACHE_IS_ENABLED(_state_)          \
86
    CYG_MACRO_START                             \
87
    (_state_) = 0;                              \
88
    CYG_MACRO_END
89 786 skrzyp
 
90 791 skrzyp
// If HAL_DCACHE_SIZE is defined, then implement proper macros.
91
#else //#ifndef HAL_DCACHE_SIZE
92 786 skrzyp
 
93
// Enable the data cache
94
#define HAL_DCACHE_ENABLE() MTSPR(SPR_SR, MFSPR(SPR_SR) | SPR_SR_DCE)
95
 
96
// Disable the data cache
97
#define HAL_DCACHE_DISABLE() MTSPR(SPR_SR, MFSPR(SPR_SR) & ~SPR_SR_DCE)
98
 
99 791 skrzyp
// Support macro. Enable or disable the data cache, depending on argument, 
100
// which is required to be 0 or 1.
101 786 skrzyp
#define HAL_SET_DCACHE_ENABLED(enable)                          \
102
    MTSPR(SPR_SR, MFSPR(SPR_SR) | (SPR_SR_DCE & -(enable)))
103
 
104
// Invalidate the entire data cache
105
#define HAL_DCACHE_INVALIDATE_ALL()                             \
106
    CYG_MACRO_START                                             \
107
    int cache_enabled, addr;                                    \
108
                                                                \
109
    /* Save current cache mode (disabled/enabled) */            \
110
    HAL_DCACHE_IS_ENABLED(cache_enabled);                       \
111
                                                                \
112
    /* Disable cache, so that invalidation ignores cache tags */\
113
    HAL_DCACHE_DISABLE();                                       \
114
    addr = HAL_DCACHE_SIZE;                                     \
115
    do {                                                        \
116
        MTSPR(SPR_DCBIR, addr);                                 \
117
        addr -= HAL_DCACHE_LINE_SIZE;                           \
118
    } while (addr > 0);                                         \
119
                                                                \
120
    /* Re-enable cache if it was enabled on entry */            \
121
    HAL_SET_DCACHE_ENABLED(cache_enabled);                      \
122
    CYG_MACRO_END
123
 
124
// Synchronize the contents of the cache with memory.
125 791 skrzyp
#define HAL_DCACHE_SYNC() HAL_DCACHE_FLUSH(0, HAL_DCACHE_SIZE)
126 786 skrzyp
 
127 791 skrzyp
// Query the state of the data cache
128 786 skrzyp
#define HAL_DCACHE_IS_ENABLED(_state_)                          \
129
    CYG_MACRO_START                                             \
130
    (_state_) = (1 - !(MFSPR(SPR_SR) & SPR_SR_DCE));            \
131
    CYG_MACRO_END
132
 
133
// Write dirty cache lines to memory and invalidate the cache entries
134
// for the given address range.
135
#define HAL_DCACHE_FLUSH( _base_ , _size_ )                          \
136 791 skrzyp
    CYG_MACRO_START                                                  \
137
    int addr;                                                        \
138
    int end = _base_ + _size_ - 1;                                   \
139
    for (addr = end; addr >= _base_; addr -= HAL_DCACHE_LINE_SIZE) { \
140
        MTSPR(SPR_DCBFR, addr);                                      \
141
    }                                                                \
142
    CYG_MACRO_END
143
 
144
// Invalidate cache lines in the given range without writing to memory
145 786 skrzyp
#define HAL_DCACHE_INVALIDATE( _base_ , _size_ )                     \
146
    CYG_MACRO_START                                                  \
147
    int addr;                                                        \
148 791 skrzyp
    int end = _base_ + _size_ - 1;                                   \
149 786 skrzyp
    for (addr = end; addr >= _base_; addr -= HAL_DCACHE_LINE_SIZE) { \
150
        MTSPR(SPR_DCBIR, addr);                                      \
151
    }                                                                \
152
    CYG_MACRO_END
153
 
154 791 skrzyp
// Write dirty cache lines to memory for the given address range
155
#if defined(HAL_DCACHE_MODE_WRITETHROUGH)
156
 
157 786 skrzyp
#define HAL_DCACHE_STORE( _base_ , _size_ )
158
 
159 791 skrzyp
#elif defined(HAL_DCACHE_MODE_WRITEBACK)
160 786 skrzyp
 
161 791 skrzyp
#define HAL_DCACHE_STORE( _base_ , _size_ )                          \
162
    CYG_MACRO_START                                                  \
163
    int addr;                                                        \
164
    int end = _base_ + _size_ - 1;                                   \
165
    for (addr = end; addr >= _base_; addr -= HAL_DCACHE_LINE_SIZE) { \
166
        MTSPR(SPR_DCBWR, addr);                                      \
167
    }                                                                \
168
    CYG_MACRO_END
169 786 skrzyp
 
170 791 skrzyp
#else
171 786 skrzyp
 
172 791 skrzyp
#error Unsupported cache mode
173
 
174
#endif
175
 
176
#endif //#ifndef HAL_DCACHE_SIZE
177
 
178 786 skrzyp
//-----------------------------------------------------------------------------
179 791 skrzyp
// Instruction cache
180
//
181
// If HAL_ICACHE_SIZE is undefined, assume that device does not implement
182
// instruction cache. Provide set of empty macros.
183
#ifndef HAL_ICACHE_SIZE
184 786 skrzyp
 
185
// Enable the instruction cache
186 791 skrzyp
#define HAL_ICACHE_ENABLE()
187
 
188
// Disable the instruction cache
189
#define HAL_ICACHE_DISABLE()
190
 
191
// Invalidate the entire cache
192
#define HAL_ICACHE_INVALIDATE_ALL()
193
 
194
// Synchronize the contents of the cache with memory.
195
#define HAL_ICACHE_SYNC()
196
 
197
// Query the state of the instruction cache (does not affect the caching)
198
#define HAL_ICACHE_IS_ENABLED(_state_)          \
199
    CYG_MACRO_START                             \
200
    (_state_) = 0;                              \
201
    CYG_MACRO_END
202
 
203
#else //#ifndef HAL_ICACHE_SIZE
204
 
205
// Enable the instruction cache
206 786 skrzyp
#define HAL_ICACHE_ENABLE() MTSPR(SPR_SR, MFSPR(SPR_SR) | SPR_SR_ICE)
207
 
208
// Disable the instruction cache
209
#define HAL_ICACHE_DISABLE() MTSPR(SPR_SR, MFSPR(SPR_SR) & ~SPR_SR_ICE)
210
 
211 791 skrzyp
// Support macro. Enable or disable the data cache, depending on argument, 
212
// which must be 0 or 1.
213 786 skrzyp
#define HAL_SET_ICACHE_ENABLED(enable)                          \
214
    MTSPR(SPR_SR, MFSPR(SPR_SR) | (SPR_SR_ICE & -(enable)))
215
 
216
// Invalidate the entire instruction cache
217
#define HAL_ICACHE_INVALIDATE_ALL()                             \
218
    CYG_MACRO_START                                             \
219
    int cache_enabled, addr;                                    \
220
                                                                \
221
    /* Save current cache mode (disabled/enabled) */            \
222
    HAL_ICACHE_IS_ENABLED(cache_enabled);                       \
223
                                                                \
224
    /* Disable cache, so that invalidation ignores cache tags */\
225
    HAL_ICACHE_DISABLE();                                       \
226
    addr = HAL_ICACHE_SIZE;                                     \
227
    do {                                                        \
228
        MTSPR(SPR_ICBIR, addr);                                 \
229
        addr -= HAL_ICACHE_LINE_SIZE;                           \
230
    } while (addr > 0);                                         \
231
                                                                \
232
    /* Re-enable cache if it was enabled on entry */            \
233
    HAL_SET_ICACHE_ENABLED(cache_enabled);                      \
234
    CYG_MACRO_END
235
 
236
// Synchronize the contents of the cache with memory.
237
#define HAL_ICACHE_SYNC() HAL_ICACHE_INVALIDATE_ALL()
238
 
239
// Query the state of the instruction cache
240
#define HAL_ICACHE_IS_ENABLED(_state_)                          \
241
    CYG_MACRO_START                                             \
242
    (_state_) = (1 - !(MFSPR(SPR_SR) & SPR_SR_ICE));            \
243
    CYG_MACRO_END
244
 
245 791 skrzyp
#endif //#ifndef HAL_ICACHE_SIZE
246 786 skrzyp
 
247
#endif /* __ASSEMBLER__ */
248
 
249
#endif // ifndef CYGONCE_HAL_CACHE_H
250
// 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.