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

Subversion Repositories openrisc

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

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):   gthomas
46
// Contributors:hmt
47
//              Travis C. Furrer <furrer@mit.edu>
48
// Date:        2000-05-08
49
// Purpose:     Cache control API
50
// Description: The macros defined here provide the HAL APIs for handling
51
//              cache control operations.
52
// Usage:
53
//              #include <cyg/hal/hal_cache.h>
54
//              ...
55
//              
56
//
57
//####DESCRIPTIONEND####
58
//
59
//=============================================================================
60
 
61
#include <cyg/infra/cyg_type.h>
62
#include <cyg/hal/hal_sa11x0.h>
63
#include <cyg/hal/hal_mmu.h>
64
 
65
//-----------------------------------------------------------------------------
66
// FIXME: This definition forces the IO flash driver to use a
67
// known-good procedure for fiddling flash before calling flash device
68
// driver functions. The procedure breaks on other platform/driver
69
// combinations though so is depricated. Hence this definition.
70
//
71
// If you work on this target, please try to remove this definition
72
// and verify that the flash driver still works (both from RAM and
73
// flash). If it does, remove the definition and this comment for good
74
// [and the old macro definition if this happens to be the last client
75
// of that code].
76
#if defined(CYGPKG_HAL_ARM_SA11X0_ASSABET) \
77
    || defined(CYGPKG_HAL_ARM_SA11X0_SA1100MM)
78
# define HAL_FLASH_CACHES_OLD_MACROS
79
#endif
80
 
81
//-----------------------------------------------------------------------------
82
// Cache dimensions
83
 
84
#define HAL_ICACHE_SIZE                 SA11X0_ICACHE_SIZE
85
#define HAL_ICACHE_LINE_SIZE            SA11X0_ICACHE_LINESIZE_BYTES
86
#define HAL_ICACHE_WAYS                 SA11X0_ICACHE_WAYS
87
#define HAL_ICACHE_SETS (HAL_ICACHE_SIZE/(HAL_ICACHE_LINE_SIZE*HAL_ICACHE_WAYS))
88
 
89
#define HAL_DCACHE_SIZE                 SA11X0_DCACHE_SIZE
90
#define HAL_DCACHE_LINE_SIZE            SA11X0_DCACHE_LINESIZE_BYTES
91
#define HAL_DCACHE_WAYS                 SA11X0_DCACHE_WAYS
92
#define HAL_DCACHE_SETS (HAL_DCACHE_SIZE/(HAL_DCACHE_LINE_SIZE*HAL_DCACHE_WAYS))
93
 
94
// FIXME: much of the code below should make better use of
95
// the definitions from hal_mmu.h
96
 
97
//-----------------------------------------------------------------------------
98
// Global control of Instruction cache
99
 
100
// Enable the instruction cache
101
#define HAL_ICACHE_ENABLE()                                             \
102
CYG_MACRO_START                                                         \
103
    asm volatile (                                                      \
104
        "mrc  p15,0,r1,c1,c0,0;"                                        \
105
        "orr  r1,r1,#0x1000;"                                           \
106
        "orr  r1,r1,#0x0003;" /* enable ICache (also ensures   */       \
107
                              /* that MMU and alignment faults */       \
108
                              /* are enabled)                  */       \
109
        "mcr  p15,0,r1,c1,c0,0"                                         \
110
        :                                                               \
111
        :                                                               \
112
        : "r1" /* Clobber list */                                       \
113
        );                                                              \
114
CYG_MACRO_END
115
 
116
// Disable the instruction cache (and invalidate it, required semanitcs)
117
#define HAL_ICACHE_DISABLE()                                            \
118
CYG_MACRO_START                                                         \
119
    asm volatile (                                                      \
120
        "mrc    p15,0,r1,c1,c0,0;"                                      \
121
        "bic    r1,r1,#0x1000;" /* disable ICache (but not MMU, etc) */ \
122
        "mcr    p15,0,r1,c1,c0,0;"                                      \
123
        "mov    r1,#0;"                                                 \
124
        "mcr    p15,0,r1,c7,c5,0;"  /* flush ICache */                  \
125
        "nop;" /* next few instructions may be via cache    */          \
126
        "nop;"                                                          \
127
        "nop;"                                                          \
128
        "nop;"                                                          \
129
        "nop;"                                                          \
130
        "nop"                                                           \
131
        :                                                               \
132
        :                                                               \
133
        : "r1" /* Clobber list */                                       \
134
        );                                                              \
135
CYG_MACRO_END
136
 
137
// Query the state of the instruction cache
138
#define HAL_ICACHE_IS_ENABLED(_state_)                                   \
139
CYG_MACRO_START                                                          \
140
    register cyg_uint32 reg;                                             \
141
    asm volatile ("mrc  p15,0,%0,c1,c0,0"                                \
142
                  : "=r"(reg)                                            \
143
                  :                                                      \
144
        );                                                               \
145
    (_state_) = (0 != (0x1000 & reg)); /* Bit 12 is ICache enable */     \
146
CYG_MACRO_END
147
 
148
// Invalidate the entire cache
149
#define HAL_ICACHE_INVALIDATE_ALL()                                     \
150
CYG_MACRO_START                                                         \
151
    /* this macro can discard dirty cache lines (N/A for ICache) */     \
152
    asm volatile (                                                      \
153
        "mov    r1,#0;"                                                 \
154
        "mcr    p15,0,r1,c7,c5,0;"  /* flush ICache */                  \
155
        "mcr    p15,0,r1,c8,c5,0;"  /* flush ITLB only */               \
156
        "nop;" /* next few instructions may be via cache    */          \
157
        "nop;"                                                          \
158
        "nop;"                                                          \
159
        "nop;"                                                          \
160
        "nop;"                                                          \
161
        "nop;"                                                          \
162
        :                                                               \
163
        :                                                               \
164
        : "r1" /* Clobber list */                                       \
165
        );                                                              \
166
CYG_MACRO_END
167
 
168
// Synchronize the contents of the cache with memory.
169
// (which includes flushing out pending writes)
170
#define HAL_ICACHE_SYNC()                                       \
171
CYG_MACRO_START                                                 \
172
    HAL_DCACHE_SYNC(); /* ensure data gets to RAM */            \
173
    HAL_ICACHE_INVALIDATE_ALL(); /* forget all we know */       \
174
CYG_MACRO_END
175
 
176
// Set the instruction cache refill burst size
177
//#define HAL_ICACHE_BURST_SIZE(_size_)
178
// This feature is not available on the SA11X0.
179
 
180
// Load the contents of the given address range into the instruction cache
181
// and then lock the cache so that it stays there.
182
//#define HAL_ICACHE_LOCK(_base_, _size_)
183
// This feature is not available on the SA11X0.
184
 
185
// Undo a previous lock operation
186
//#define HAL_ICACHE_UNLOCK(_base_, _size_)
187
// This feature is not available on the SA11X0.
188
 
189
// Unlock entire cache
190
//#define HAL_ICACHE_UNLOCK_ALL()
191
// This feature is not available on the SA11X0.
192
 
193
//-----------------------------------------------------------------------------
194
// Instruction cache line control
195
 
196
// Invalidate cache lines in the given range without writing to memory.
197
//#define HAL_ICACHE_INVALIDATE( _base_ , _size_ )
198
// This feature is not available on the SA11X0.
199
 
200
//-----------------------------------------------------------------------------
201
// Global control of data cache
202
 
203
// Enable the data cache
204
#define HAL_DCACHE_ENABLE()                                             \
205
CYG_MACRO_START                                                         \
206
    asm volatile (                                                      \
207
        "mrc  p15,0,r1,c1,c0,0;"                                        \
208
        "orr  r1,r1,#0x000F;" /* enable DCache (also ensures    */      \
209
                              /* the MMU, alignment faults, and */      \
210
                              /* write buffer are enabled)      */      \
211
        "mcr  p15,0,r1,c1,c0,0"                                         \
212
        :                                                               \
213
        :                                                               \
214
        : "r1" /* Clobber list */                                       \
215
        );                                                              \
216
CYG_MACRO_END
217
 
218
// Disable the data cache (and invalidate it, required semanitcs)
219
#define HAL_DCACHE_DISABLE()                                            \
220
CYG_MACRO_START                                                         \
221
    asm volatile (                                                      \
222
        "mrc  p15,0,r1,c1,c0,0;"                                        \
223
        "bic  r1,r1,#0x000C;" /* disable DCache AND write buffer  */    \
224
                              /* but not MMU and alignment faults */    \
225
        "mcr  p15,0,r1,c1,c0,0;"                                        \
226
        "mov    r1,#0;"                                                 \
227
        "mcr  p15,0,r1,c7,c6,0" /* clear data cache */                  \
228
        :                                                               \
229
        :                                                               \
230
        : "r1" /* Clobber list */                                       \
231
        );                                                              \
232
CYG_MACRO_END
233
 
234
// Query the state of the data cache
235
#define HAL_DCACHE_IS_ENABLED(_state_)                                   \
236
CYG_MACRO_START                                                          \
237
    register int reg;                                                    \
238
    asm volatile ("mrc  p15,0,%0,c1,c0,0;"                               \
239
                  : "=r"(reg)                                            \
240
                  :                                                      \
241
        );                                                               \
242
    (_state_) = (0 != (4 & reg)); /* Bit 2 is DCache enable */           \
243
CYG_MACRO_END
244
 
245
// Flush the entire dcache (and then both TLBs, just in case)
246
#define HAL_DCACHE_INVALIDATE_ALL()                                     \
247
CYG_MACRO_START    /* this macro can discard dirty cache lines. */      \
248
    asm volatile (                                                      \
249
        "mov    r1,#0;"                                                 \
250
        "mcr    p15,0,r1,c7,c6,0;"                                      \
251
        "mcr    p15,0,r1,c8,c7,0;"                                      \
252
        :                                                               \
253
        :                                                               \
254
        : "r1","memory" );                                              \
255
CYG_MACRO_END
256
 
257
 
258
// Synchronize the contents of the cache with memory.
259
#define HAL_DCACHE_SYNC()                                               \
260
CYG_MACRO_START                                                         \
261
    /* This is slightly naff in that the only way to force a dirty */   \
262
    /* line out is by loading other data into its slot, so         */   \
263
    /* invalidating that slot.                                     */   \
264
    asm volatile (                                                      \
265
        "mov    r0, #0xE0000000;" /* SA11X0 zeros bank (128Mb) */       \
266
        "add    r1, r0, #0x2000;" /* We read 8kB of it */               \
267
 "667: "                                                                \
268
        "ldr    r2, [r0], #32;"                                         \
269
        "teq    r1, r0;"                                                \
270
        "bne    667b;"                                                  \
271
        "mov    r0,#0;"                                                 \
272
        "mcr    p15,0,r0,c7,c6,0;"  /* flush DCache */                  \
273
        "mcr    p15,0,r0,c7,c10,4;" /* and drain the write buffer */    \
274
        :                                                               \
275
        :                                                               \
276
        : "r0","r1","r2" /* Clobber list */                             \
277
        );                                                              \
278
CYG_MACRO_END
279
 
280
// Set the data cache refill burst size
281
//#define HAL_DCACHE_BURST_SIZE(_size_)
282
// This feature is not available on the SA11X0.
283
 
284
// Set the data cache write mode
285
//#define HAL_DCACHE_WRITE_MODE( _mode_ )
286
// This feature is not available on the SA11X0.
287
 
288
#define HAL_DCACHE_WRITETHRU_MODE       0
289
#define HAL_DCACHE_WRITEBACK_MODE       1
290
 
291
// Get the current writeback mode - or only writeback mode if fixed
292
#define HAL_DCACHE_QUERY_WRITE_MODE( _mode_ ) CYG_MACRO_START           \
293
    _mode_ = HAL_DCACHE_WRITEBACK_MODE;                                 \
294
CYG_MACRO_END
295
 
296
// Load the contents of the given address range into the data cache
297
// and then lock the cache so that it stays there.
298
//#define HAL_DCACHE_LOCK(_base_, _size_)
299
// This feature is not available on the SA11X0.
300
 
301
// Undo a previous lock operation
302
//#define HAL_DCACHE_UNLOCK(_base_, _size_)
303
// This feature is not available on the SA11X0.
304
 
305
// Unlock entire cache
306
//#define HAL_DCACHE_UNLOCK_ALL()
307
// This feature is not available on the SA11X0.
308
 
309
//-----------------------------------------------------------------------------
310
// Data cache line control
311
 
312
// Allocate cache lines for the given address range without reading its
313
// contents from memory.
314
//#define HAL_DCACHE_ALLOCATE( _base_ , _size_ )
315
// This feature is not available on the SA11X0.
316
 
317
// Write dirty cache lines to memory and invalidate the cache entries
318
// for the given address range.
319
#define HAL_DCACHE_FLUSH( _base_ , _size_ )     \
320
CYG_MACRO_START                                 \
321
    HAL_DCACHE_STORE( _base_ , _size_ );        \
322
    HAL_DCACHE_INVALIDATE( _base_ , _size_ );   \
323
CYG_MACRO_END
324
 
325
// Invalidate cache lines in the given range without writing to memory.
326
#define HAL_DCACHE_INVALIDATE( _base_ , _size_ )                        \
327
CYG_MACRO_START                                                         \
328
    register int addr, enda;                                            \
329
    for ( addr = (~(HAL_DCACHE_LINE_SIZE - 1)) & (int)(_base_),         \
330
              enda = (int)(_base_) + (_size_);                          \
331
          addr < enda ;                                                 \
332
          addr += HAL_DCACHE_LINE_SIZE )                                \
333
    {                                                                   \
334
        asm volatile (                                                  \
335
                      "mcr  p15,0,%0,c7,c6,1;" /* flush entry away */   \
336
                      :                                                 \
337
                      : "r"(addr)                                       \
338
                      : "memory"                                        \
339
            );                                                          \
340
    }                                                                   \
341
CYG_MACRO_END
342
 
343
// Write dirty cache lines to memory for the given address range.
344
#define HAL_DCACHE_STORE( _base_ , _size_ )                             \
345
CYG_MACRO_START                                                         \
346
    register int addr, enda;                                            \
347
    for ( addr = (~(HAL_DCACHE_LINE_SIZE - 1)) & (int)(_base_),         \
348
              enda = (int)(_base_) + (_size_);                          \
349
          addr < enda ;                                                 \
350
          addr += HAL_DCACHE_LINE_SIZE )                                \
351
    {                                                                   \
352
        asm volatile ("mcr  p15,0,%0,c7,c10,1;" /* push entry to RAM */ \
353
                      :                                                 \
354
                      : "r"(addr)                                       \
355
                      : "memory"                                        \
356
            );                                                          \
357
    }                                                                   \
358
    /* and also drain the write buffer */                               \
359
    asm volatile (                                                      \
360
        "mov    r1,#0;"                                                 \
361
        "mcr    p15,0,r1,c7,c10,4;"                                     \
362
        :                                                               \
363
        :                                                               \
364
        : "r1", "memory" /* Clobber list */                             \
365
    );                                                                  \
366
CYG_MACRO_END
367
 
368
// Preread the given range into the cache with the intention of reading
369
// from it later.
370
//#define HAL_DCACHE_READ_HINT( _base_ , _size_ )
371
// This feature is available on the SA11X0, but due to tricky
372
// coherency issues with the read buffer (see SA11X0 developer's
373
// manual page 6-7) we don't bother to implement it here.
374
 
375
// Preread the given range into the cache with the intention of writing
376
// to it later.
377
//#define HAL_DCACHE_WRITE_HINT( _base_ , _size_ )
378
// This feature is not available on the SA11X0.
379
 
380
// Allocate and zero the cache lines associated with the given range.
381
//#define HAL_DCACHE_ZERO( _base_ , _size_ )
382
// This feature is not available on the SA11X0.
383
 
384
//-----------------------------------------------------------------------------
385
// Now include the details of the platform's Memory Map setup:
386
 
387
#include <cyg/hal/plf_mmap.h>
388
 
389
// and define the (considerably less efficient) routines that are available
390
// for testing the actual memory map in force.
391
 
392
externC cyg_uint32 hal_virt_to_phys_address( cyg_uint32 vaddr );
393
externC cyg_uint32 hal_phys_to_virt_address( cyg_uint32 paddr );
394
externC cyg_uint32 hal_virt_to_uncached_address( cyg_uint32 vaddr );
395
 
396
//-----------------------------------------------------------------------------
397
#endif // ifndef CYGONCE_HAL_CACHE_H
398
// 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.