1 |
786 |
skrzyp |
#ifndef CYGONCE_VAR_CACHE_H
|
2 |
|
|
#define CYGONCE_VAR_CACHE_H
|
3 |
|
|
|
4 |
|
|
//=============================================================================
|
5 |
|
|
//
|
6 |
|
|
// var_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, jskov
|
47 |
|
|
// Date: 2000-05-09
|
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 |
|
|
|
65 |
|
|
#include <cyg/hal/plf_cache.h>
|
66 |
|
|
|
67 |
|
|
//=============================================================================
|
68 |
|
|
// Toshiba TX4955
|
69 |
|
|
|
70 |
|
|
#ifdef CYGPKG_HAL_MIPS_TX4955
|
71 |
|
|
|
72 |
|
|
//-----------------------------------------------------------------------------
|
73 |
|
|
// Cache dimensions
|
74 |
|
|
|
75 |
|
|
// Data cache
|
76 |
|
|
#define HAL_DCACHE_SIZE CYGHWR_HAL_DCACHE_SIZE // size in bytes
|
77 |
|
|
#define HAL_DCACHE_LINE_SIZE 32 // Size of a data cache line
|
78 |
|
|
#define HAL_DCACHE_WAYS 4 // Associativity of the cache
|
79 |
|
|
|
80 |
|
|
// Instruction cache
|
81 |
|
|
#define HAL_ICACHE_SIZE CYGHWR_HAL_ICACHE_SIZE // size in bytes
|
82 |
|
|
#define HAL_ICACHE_LINE_SIZE 32 // Size of a cache line
|
83 |
|
|
#define HAL_ICACHE_WAYS 4 // Associativity of the cache
|
84 |
|
|
|
85 |
|
|
#define HAL_DCACHE_SETS (HAL_DCACHE_SIZE/(HAL_DCACHE_LINE_SIZE*HAL_DCACHE_WAYS))
|
86 |
|
|
#define HAL_ICACHE_SETS (HAL_ICACHE_SIZE/(HAL_ICACHE_LINE_SIZE*HAL_ICACHE_WAYS))
|
87 |
|
|
|
88 |
|
|
#define HAL_MIPS_CACHE_INSN_USES_LSB
|
89 |
|
|
|
90 |
|
|
//-----------------------------------------------------------------------------
|
91 |
|
|
// Cache controls
|
92 |
|
|
|
93 |
|
|
// Register $16 is Config register (controls cache state)
|
94 |
|
|
|
95 |
|
|
// Config Register fields
|
96 |
|
|
#define CYGARC_REG_CONFIG_ICE 0x00020000 // Instruction cache enable
|
97 |
|
|
#define CYGARC_REG_CONFIG_DCE 0x00010000 // Data cache enable
|
98 |
|
|
|
99 |
|
|
|
100 |
|
|
//-----------------------------------------------------------------------------
|
101 |
|
|
// Global control of data cache
|
102 |
|
|
|
103 |
|
|
// Enable the data cache
|
104 |
|
|
// This uses a bit in the config register, which is TX49 specific.
|
105 |
|
|
#define HAL_DCACHE_ENABLE_DEFINED
|
106 |
|
|
#define HAL_DCACHE_ENABLE() \
|
107 |
|
|
CYG_MACRO_START \
|
108 |
|
|
cyg_uint32 tmp; \
|
109 |
|
|
asm volatile ("mfc0 %0,$16;" \
|
110 |
|
|
"and %0,%0,%1;" \
|
111 |
|
|
"mtc0 %0,$16;" \
|
112 |
|
|
: "=&r" (tmp) \
|
113 |
|
|
: "r" (~CYGARC_REG_CONFIG_DCE) \
|
114 |
|
|
); \
|
115 |
|
|
CYG_MACRO_END
|
116 |
|
|
|
117 |
|
|
// Disable the data cache
|
118 |
|
|
#define HAL_DCACHE_DISABLE_DEFINED
|
119 |
|
|
#define HAL_DCACHE_DISABLE() \
|
120 |
|
|
CYG_MACRO_START \
|
121 |
|
|
cyg_uint32 tmp; \
|
122 |
|
|
asm volatile ("mfc0 %0,$16;" \
|
123 |
|
|
"or %0,%0,%1;" \
|
124 |
|
|
"mtc0 %0,$16;" \
|
125 |
|
|
: "=&r" (tmp) \
|
126 |
|
|
: "r" (CYGARC_REG_CONFIG_DCE) \
|
127 |
|
|
); \
|
128 |
|
|
CYG_MACRO_END
|
129 |
|
|
|
130 |
|
|
#define HAL_DCACHE_IS_ENABLED_DEFINED
|
131 |
|
|
#define HAL_DCACHE_IS_ENABLED(_state_) \
|
132 |
|
|
CYG_MACRO_START \
|
133 |
|
|
cyg_uint32 _cstate_; \
|
134 |
|
|
asm volatile ( "mfc0 %0,$16\n" \
|
135 |
|
|
: "=r"(_cstate_) \
|
136 |
|
|
); \
|
137 |
|
|
if( _cstate_ & CYGARC_REG_CONFIG_DCE) \
|
138 |
|
|
_state_ = 0; \
|
139 |
|
|
else \
|
140 |
|
|
_state_ = 1; \
|
141 |
|
|
CYG_MACRO_END
|
142 |
|
|
|
143 |
|
|
// Architecture HAL defines other operations
|
144 |
|
|
|
145 |
|
|
|
146 |
|
|
//-----------------------------------------------------------------------------
|
147 |
|
|
// Global control of Instruction cache
|
148 |
|
|
|
149 |
|
|
// Enable the instruction cache
|
150 |
|
|
#define HAL_ICACHE_ENABLE_DEFINED
|
151 |
|
|
#define HAL_ICACHE_ENABLE() \
|
152 |
|
|
CYG_MACRO_START \
|
153 |
|
|
cyg_uint32 tmp; \
|
154 |
|
|
asm volatile ("mfc0 %0,$16;" \
|
155 |
|
|
"and %0,%0,%1;" \
|
156 |
|
|
"mtc0 %0,$16;" \
|
157 |
|
|
: "=&r" (tmp) \
|
158 |
|
|
: "r" (~CYGARC_REG_CONFIG_ICE) \
|
159 |
|
|
); \
|
160 |
|
|
CYG_MACRO_END
|
161 |
|
|
|
162 |
|
|
// Disable the instruction cache
|
163 |
|
|
#define HAL_ICACHE_DISABLE_DEFINED
|
164 |
|
|
#define HAL_ICACHE_DISABLE() \
|
165 |
|
|
CYG_MACRO_START \
|
166 |
|
|
cyg_uint32 tmp; \
|
167 |
|
|
asm volatile ("mfc0 %0,$16;" \
|
168 |
|
|
"or %0,%0,%1;" \
|
169 |
|
|
"mtc0 %0,$16;" \
|
170 |
|
|
: "=&r" (tmp) \
|
171 |
|
|
: "r" (CYGARC_REG_CONFIG_ICE) \
|
172 |
|
|
); \
|
173 |
|
|
CYG_MACRO_END
|
174 |
|
|
|
175 |
|
|
#define HAL_ICACHE_IS_ENABLED_DEFINED
|
176 |
|
|
#define HAL_ICACHE_IS_ENABLED(_state_) \
|
177 |
|
|
CYG_MACRO_START \
|
178 |
|
|
cyg_uint32 _cstate_; \
|
179 |
|
|
asm volatile ( "mfc0 %0,$16\n" \
|
180 |
|
|
: "=r"(_cstate_) \
|
181 |
|
|
); \
|
182 |
|
|
if( _cstate_ & CYGARC_REG_CONFIG_ICE) \
|
183 |
|
|
_state_ = 0; \
|
184 |
|
|
else \
|
185 |
|
|
_state_ = 1; \
|
186 |
|
|
CYG_MACRO_END
|
187 |
|
|
|
188 |
|
|
// TX49 cache instruction must not affect the line it executes out of,
|
189 |
|
|
// so disable instruction cache before invalidating it.
|
190 |
|
|
#define HAL_ICACHE_INVALIDATE_ALL_DEFINED
|
191 |
|
|
#define HAL_ICACHE_INVALIDATE_ALL() \
|
192 |
|
|
CYG_MACRO_START \
|
193 |
|
|
register CYG_ADDRESS _baddr_ = 0x80000000; \
|
194 |
|
|
register CYG_ADDRESS _addr_ = 0x80000000; \
|
195 |
|
|
register CYG_WORD _state_; \
|
196 |
|
|
_HAL_ASM_SET_MIPS_ISA(3); \
|
197 |
|
|
HAL_ICACHE_IS_ENABLED( _state_ ); \
|
198 |
|
|
HAL_ICACHE_DISABLE(); \
|
199 |
|
|
for( ; _addr_ < _baddr_+HAL_ICACHE_SIZE; _addr_ += HAL_ICACHE_LINE_SIZE ) \
|
200 |
|
|
{ _HAL_ASM_ICACHE_ALL_WAYS(0x00, _addr_); } \
|
201 |
|
|
if( _state_ ) HAL_ICACHE_ENABLE(); \
|
202 |
|
|
_HAL_ASM_SET_MIPS_ISA(0); \
|
203 |
|
|
CYG_MACRO_END
|
204 |
|
|
|
205 |
|
|
// Architecture HAL defines other operations
|
206 |
|
|
|
207 |
|
|
#endif // CYGPKG_HAL_MIPS_TX4955
|
208 |
|
|
|
209 |
|
|
|
210 |
|
|
//-----------------------------------------------------------------------------
|
211 |
|
|
#endif // ifndef CYGONCE_VAR_CACHE_H
|
212 |
|
|
// End of var_cache.h
|