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

Subversion Repositories openrisc

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

Go to most recent revision | 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):   hmt
46
// Contributors:hmt
47
// Date:        1999-07-05
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
#include <cyg/infra/cyg_type.h>
61
//#include <cyg/hal/hal_mmu.h>
62
 
63
//-----------------------------------------------------------------------------
64
// FIXME: This definition forces the IO flash driver to use a
65
// known-good procedure for fiddling flash before calling flash device
66
// driver functions. The procedure breaks on other platform/driver
67
// combinations though so is depricated. Hence this definition.
68
//
69
// If you work on this target, please try to remove this definition
70
// and verify that the flash driver still works (both from RAM and
71
// flash). If it does, remove the definition and this comment for good
72
// [and the old macro definition if this happens to be the last client
73
// of that code].
74
#define HAL_FLASH_CACHES_OLD_MACROS
75
 
76
//-----------------------------------------------------------------------------
77
// Cache dimensions
78
 
79
#define HAL_DCACHE_SIZE                 0x4000 // Size of data cache in bytes
80
#define HAL_DCACHE_LINE_SIZE            32     // Size of a data cache line
81
#define HAL_DCACHE_WAYS                 32     // Associativity of the cache
82
#define HAL_DCACHE_SETS (HAL_UCACHE_SIZE/(HAL_UCACHE_LINE_SIZE*HAL_UCACHE_WAYS))
83
 
84
#define HAL_ICACHE_SIZE                 0x4000 // Size of instruction cache in bytes
85
#define HAL_ICACHE_LINE_SIZE            32     // Size of ins cache line
86
#define HAL_ICACHE_WAYS                 32     // Associativity of the cache
87
#define HAL_ICACHE_SETS (HAL_UCACHE_SIZE/(HAL_UCACHE_LINE_SIZE*HAL_UCACHE_WAYS))
88
 
89
//-----------------------------------------------------------------------------
90
// Global control of data cache
91
 
92
// Enable the data cache
93
#define HAL_DCACHE_ENABLE()                                             \
94
CYG_MACRO_START                                                         \
95
    /* SA-110 manual states that the control reg is read-write */       \
96
    asm volatile (                                                      \
97
        "mrc  p15,0,r1,c1,c0,0;"                                        \
98
        "orr  r1,r1,#0x000F;" /* ensure MM is enabled */                \
99
        "mcr  p15,0,r1,c1,c0,0"                                         \
100
        :                                                               \
101
        :                                                               \
102
        : "r1" /* Clobber list */                                       \
103
        );                                                              \
104
CYG_MACRO_END
105
 
106
// Disable the data cache (and invalidate it, required semanitcs)
107
#define HAL_DCACHE_DISABLE()                                            \
108
CYG_MACRO_START                                                         \
109
    /* SA-110 manual states that the control reg is read-write */       \
110
    asm volatile (                                                      \
111
        "mrc  p15,0,r1,c1,c0,0;"                                        \
112
        "bic  r1,r1,#0x000C;" /* but leave MM alone */                  \
113
        "mcr  p15,0,r1,c1,c0,0;"                                        \
114
        "mov    r1,#0;"                                                 \
115
        "mcr  p15,0,r1,c7,c6,0" /* clear data cache */                  \
116
        :                                                               \
117
        :                                                               \
118
        : "r1" /* Clobber list */                                       \
119
        );                                                              \
120
CYG_MACRO_END
121
 
122
// Invalidate the entire cache (and both TLBs, just in case)
123
#define HAL_DCACHE_INVALIDATE_ALL()                                     \
124
CYG_MACRO_START                                                         \
125
    /* this macro can discard dirty cache lines. */                     \
126
    asm volatile (                                                      \
127
        "mov    r1,#0;"                                                 \
128
        "mcr    p15,0,r1,c7,c6,0;"  /* clear data cache */              \
129
        "mcr    p15,0,r1,c8,c7,0;"  /* flush I+D TLBs */                \
130
        :                                                               \
131
        :                                                               \
132
        : "r1","memory" /* Clobber list */                              \
133
        );                                                              \
134
CYG_MACRO_END
135
 
136
 
137
// Synchronize the contents of the cache with memory.
138
#define HAL_DCACHE_SYNC()                                               \
139
CYG_MACRO_START                                                         \
140
    /* This is slightly naff in that the only way to force a dirty */   \
141
    /* line out is by loading other data into its slot, so         */   \
142
    /* invalidating that slot.                                     */   \
143
    asm volatile (                                                      \
144
        "mov    r0, #0x50000000;" /* 21285~s cache flush region */      \
145
        "add    r1, r0, #0x4000;" /* 16MB of fast don~t-care amnesia */ \
146
 "667: "                          /* We read in 16kB of it */           \
147
        "ldr    r2, [r0], #32;"                                         \
148
        "teq    r1, r0;"                                                \
149
        "bne    667b;"                                                  \
150
        "mov    r0,#0;"                                                 \
151
        "mcr    p15,0,r0,c7,c6,0;"  /* clear data cache */              \
152
        "mcr    p15,0,r0,c7,c10,4;" /* and drain the write buffer */    \
153
        :                                                               \
154
        :                                                               \
155
        : "r0","r1","r2" /* Clobber list */                             \
156
        );                                                              \
157
CYG_MACRO_END
158
 
159
// Query the state of the data cache
160
#define HAL_DCACHE_IS_ENABLED(_state_)                                  \
161
CYG_MACRO_START                                                         \
162
    /* SA-110 manual states clearly that the control reg is readable */ \
163
    register int reg;                                                   \
164
    asm volatile ("mrc  p15,0,%0,c1,c0,0"                               \
165
                  : "=r"(reg)                                           \
166
                  :                                                     \
167
                /*:*/                                                   \
168
        );                                                              \
169
    (_state_) = (0 != (4 & reg)); /* Bit 2 is DCache enable */          \
170
CYG_MACRO_END
171
 
172
// Set the data cache refill burst size
173
//#define HAL_DCACHE_BURST_SIZE(_size_)
174
 
175
// Set the data cache write mode
176
//#define HAL_DCACHE_WRITE_MODE( _mode_ )
177
 
178
#define HAL_DCACHE_WRITETHRU_MODE       0
179
#define HAL_DCACHE_WRITEBACK_MODE       1
180
 
181
// Get the current writeback mode - or only writeback mode if fixed
182
#define HAL_DCACHE_QUERY_WRITE_MODE( _mode_ ) CYG_MACRO_START           \
183
    _mode_ = HAL_DCACHE_WRITEBACK_MODE;                                 \
184
CYG_MACRO_END
185
 
186
// Load the contents of the given address range into the data cache
187
// and then lock the cache so that it stays there.
188
//#define HAL_DCACHE_LOCK(_base_, _size_)
189
 
190
// Undo a previous lock operation
191
//#define HAL_DCACHE_UNLOCK(_base_, _size_)
192
 
193
// Unlock entire cache
194
//#define HAL_DCACHE_UNLOCK_ALL()
195
 
196
//-----------------------------------------------------------------------------
197
// Data cache line control
198
 
199
// Allocate cache lines for the given address range without reading its
200
// contents from memory.
201
//#define HAL_DCACHE_ALLOCATE( _base_ , _size_ )
202
 
203
// Write dirty cache lines to memory and invalidate the cache entries
204
// for the given address range.
205
#define HAL_DCACHE_FLUSH( _base_ , _size_ )     \
206
CYG_MACRO_START                                 \
207
    HAL_DCACHE_STORE( _base_ , _size_ );        \
208
    HAL_DCACHE_INVALIDATE( _base_ , _size_ );   \
209
CYG_MACRO_END
210
 
211
// Invalidate cache lines in the given range without writing to memory.
212
#define HAL_DCACHE_INVALIDATE( _base_ , _size_ )                        \
213
CYG_MACRO_START                                                         \
214
    register int addr, enda;                                            \
215
    for ( addr = (~(HAL_DCACHE_LINE_SIZE - 1)) & (int)(_base_),         \
216
              enda = (int)(_base_) + (_size_);                          \
217
          addr < enda ;                                                 \
218
          addr += HAL_DCACHE_LINE_SIZE )                                \
219
    {                                                                   \
220
        asm volatile (                                                  \
221
                      "mcr  p15,0,%0,c7,c6,1;" /* flush entry away */   \
222
                      :                                                 \
223
                      : "r"(addr)                                       \
224
                      : "memory"                                        \
225
            );                                                          \
226
    }                                                                   \
227
CYG_MACRO_END
228
 
229
// Write dirty cache lines to memory for the given address range.
230
#define HAL_DCACHE_STORE( _base_ , _size_ )                             \
231
CYG_MACRO_START                                                         \
232
    register int addr, enda;                                            \
233
    for ( addr = (~(HAL_DCACHE_LINE_SIZE - 1)) & (int)(_base_),         \
234
              enda = (int)(_base_) + (_size_);                          \
235
          addr < enda ;                                                 \
236
          addr += HAL_DCACHE_LINE_SIZE )                                \
237
    {                                                                   \
238
        asm volatile ("mcr  p15,0,%0,c7,c10,1;" /* push entry to RAM */ \
239
                      :                                                 \
240
                      : "r"(addr)                                       \
241
                      : "memory"                                        \
242
            );                                                          \
243
    }                                                                   \
244
    /* and also drain the write buffer */                               \
245
    asm volatile (                                                      \
246
        "mov    r1,#0;"                                                 \
247
        "mcr    p15,0,r1,c7,c10,4;"                                     \
248
        :                                                               \
249
        :                                                               \
250
        : "r1", "memory" );                                             \
251
CYG_MACRO_END
252
 
253
// Preread the given range into the cache with the intention of reading
254
// from it later.
255
//#define HAL_DCACHE_READ_HINT( _base_ , _size_ )
256
 
257
// Preread the given range into the cache with the intention of writing
258
// to it later.
259
//#define HAL_DCACHE_WRITE_HINT( _base_ , _size_ )
260
 
261
// Allocate and zero the cache lines associated with the given range.
262
//#define HAL_DCACHE_ZERO( _base_ , _size_ )
263
 
264
//-----------------------------------------------------------------------------
265
// Global control of Instruction cache
266
 
267
// Enable the instruction cache
268
#define HAL_ICACHE_ENABLE()                                             \
269
CYG_MACRO_START                                                         \
270
    /* SA-110 manual states that the control reg is read-write */       \
271
    asm volatile (                                                      \
272
        "mrc  p15,0,r1,c1,c0,0;"                                        \
273
        "orr  r1,r1,#0x0003;" /* ensure MM is enabled */                \
274
        "orr  r1,r1,#0x1000;" /* enable ICache */                       \
275
        "mcr  p15,0,r1,c1,c0,0"                                         \
276
        :                                                               \
277
        :                                                               \
278
        : "r1" /* Clobber list */                                       \
279
        );                                                              \
280
CYG_MACRO_END
281
 
282
// Disable the instruction cache (and invalidate it, required semanitcs)
283
#define HAL_ICACHE_DISABLE()                                            \
284
CYG_MACRO_START                                                         \
285
    /* SA-110 manual states that the control reg is read-write */       \
286
    asm volatile (                                                      \
287
        "mrc    p15,0,r1,c1,c0,0;"                                      \
288
        "bic    r1,r1,#0x1000;" /* but leave MM alone */                \
289
        "mcr    p15,0,r1,c1,c0,0;"                                      \
290
        "mov    r1, #0;"                                                \
291
        "mcr    p15,0,r1,c7,c5,0;"  /* clear instruction cache */       \
292
        "nop;" /* next few instructions may be via cache */             \
293
        "nop;"                                                          \
294
        "nop;"                                                          \
295
        "nop;"                                                          \
296
        "nop;"                                                          \
297
        "nop"                                                           \
298
        :                                                               \
299
        :                                                               \
300
        : "r1" /* Clobber list */                                       \
301
        );                                                              \
302
CYG_MACRO_END
303
 
304
// Invalidate the entire cache
305
#define HAL_ICACHE_INVALIDATE_ALL()                                     \
306
CYG_MACRO_START                                                         \
307
    /* this macro can discard dirty cache lines (N/A for ICache) */     \
308
    asm volatile (                                                      \
309
        "mov    r1, #0;"                                                \
310
        "mcr    p15,0,r1,c7,c5,0;"  /* clear instruction cache */       \
311
        "mcr    p15,0,r1,c8,c5,0;"  /* flush I TLB only */              \
312
        "nop;" /* next few instructions may be via cache */             \
313
        "nop;"                                                          \
314
        "nop;"                                                          \
315
        "nop;"                                                          \
316
        "nop;"                                                          \
317
        "nop"                                                           \
318
        :                                                               \
319
        :                                                               \
320
        : "r1" /* Clobber list */                                       \
321
        );                                                              \
322
CYG_MACRO_END
323
 
324
 
325
// Synchronize the contents of the cache with memory.
326
// (which includes flushing out pending writes)
327
#define HAL_ICACHE_SYNC()                                       \
328
CYG_MACRO_START                                                 \
329
    HAL_DCACHE_SYNC(); /* ensure data gets to RAM */            \
330
    HAL_ICACHE_INVALIDATE_ALL(); /* forget all we know */       \
331
CYG_MACRO_END
332
 
333
// Query the state of the instruction cache
334
#define HAL_ICACHE_IS_ENABLED(_state_)                                  \
335
CYG_MACRO_START                                                         \
336
    /* SA-110 manual states clearly that the control reg is readable */ \
337
    register cyg_uint32 reg;                                            \
338
    asm volatile ("mrc  p15,0,%0,c1,c0,0"                               \
339
                  : "=r"(reg)                                           \
340
                  :                                                     \
341
                /*:*/                                                   \
342
        );                                                              \
343
    (_state_) = (0 != (0x1000 & reg)); /* Bit 12 is ICache enable */    \
344
CYG_MACRO_END
345
 
346
// Set the instruction cache refill burst size
347
//#define HAL_ICACHE_BURST_SIZE(_size_)
348
 
349
// Load the contents of the given address range into the instruction cache
350
// and then lock the cache so that it stays there.
351
//#define HAL_ICACHE_LOCK(_base_, _size_)
352
 
353
// Undo a previous lock operation
354
//#define HAL_ICACHE_UNLOCK(_base_, _size_)
355
 
356
// Unlock entire cache
357
//#define HAL_ICACHE_UNLOCK_ALL()
358
 
359
//-----------------------------------------------------------------------------
360
// Instruction cache line control
361
 
362
// Invalidate cache lines in the given range without writing to memory.
363
//#define HAL_ICACHE_INVALIDATE( _base_ , _size_ )
364
 
365
//-----------------------------------------------------------------------------
366
#endif // ifndef CYGONCE_HAL_CACHE_H
367
// 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.