1 /* $Id: cache.h,v 1.8 1999/03/11 00:14:45 davem Exp $
2 * cache.h: Cache specific code for the Sparc. These include flushing
3 * and direct tag/data line access.
5 * Copyright (C) 1995 David S. Miller (davem@caip.rutgers.edu)
13 #define L1_CACHE_BYTES 32
14 #define L1_CACHE_ALIGN(x) ((((x)+(L1_CACHE_BYTES-1))&~(L1_CACHE_BYTES-1)))
16 #define SMP_CACHE_BYTES 32
18 /* Direct access to the instruction cache is provided through and
19 * alternate address space. The IDC bit must be off in the ICCR on
20 * HyperSparcs for these accesses to work. The code below does not do
21 * any checking, the caller must do so. These routines are for
22 * diagnostics only, but could end up being useful. Use with care.
23 * Also, you are asking for trouble if you execute these in one of the
24 * three instructions following a %asr/%psr access or modification.
27 /* First, cache-tag access. */
28 extern __inline__
unsigned int get_icache_tag(int setnum
, int tagnum
)
30 unsigned int vaddr
, retval
;
32 vaddr
= ((setnum
&1) << 12) | ((tagnum
&0x7f) << 5);
33 __asm__
__volatile__("lda [%1] %2, %0\n\t" :
35 "r" (vaddr
), "i" (ASI_M_TXTC_TAG
));
39 extern __inline__
void put_icache_tag(int setnum
, int tagnum
, unsigned int entry
)
43 vaddr
= ((setnum
&1) << 12) | ((tagnum
&0x7f) << 5);
44 __asm__
__volatile__("sta %0, [%1] %2\n\t" : :
45 "r" (entry
), "r" (vaddr
), "i" (ASI_M_TXTC_TAG
) :
49 /* Second cache-data access. The data is returned two-32bit quantities
52 extern __inline__
void get_icache_data(int setnum
, int tagnum
, int subblock
,
55 unsigned int value1
, value2
, vaddr
;
57 vaddr
= ((setnum
&0x1) << 12) | ((tagnum
&0x7f) << 5) |
58 ((subblock
&0x3) << 3);
59 __asm__
__volatile__("ldda [%2] %3, %%g2\n\t"
60 "or %%g0, %%g2, %0\n\t"
61 "or %%g0, %%g3, %1\n\t" :
62 "=r" (value1
), "=r" (value2
) :
63 "r" (vaddr
), "i" (ASI_M_TXTC_DATA
) :
65 data
[0] = value1
; data
[1] = value2
;
68 extern __inline__
void put_icache_data(int setnum
, int tagnum
, int subblock
,
71 unsigned int value1
, value2
, vaddr
;
73 vaddr
= ((setnum
&0x1) << 12) | ((tagnum
&0x7f) << 5) |
74 ((subblock
&0x3) << 3);
75 value1
= data
[0]; value2
= data
[1];
76 __asm__
__volatile__("or %%g0, %0, %%g2\n\t"
77 "or %%g0, %1, %%g3\n\t"
78 "stda %%g2, [%2] %3\n\t" : :
79 "r" (value1
), "r" (value2
),
80 "r" (vaddr
), "i" (ASI_M_TXTC_DATA
) :
81 "g2", "g3", "memory" /* no joke */);
84 /* Different types of flushes with the ICACHE. Some of the flushes
85 * affect both the ICACHE and the external cache. Others only clear
86 * the ICACHE entries on the cpu itself. V8's (most) allow
87 * granularity of flushes on the packet (element in line), whole line,
88 * and entire cache (ie. all lines) level. The ICACHE only flushes are
89 * ROSS HyperSparc specific and are in ross.h
92 /* Flushes which clear out both the on-chip and external caches */
93 extern __inline__
void flush_ei_page(unsigned int addr
)
95 __asm__
__volatile__("sta %%g0, [%0] %1\n\t" : :
96 "r" (addr
), "i" (ASI_M_FLUSH_PAGE
) :
100 extern __inline__
void flush_ei_seg(unsigned int addr
)
102 __asm__
__volatile__("sta %%g0, [%0] %1\n\t" : :
103 "r" (addr
), "i" (ASI_M_FLUSH_SEG
) :
107 extern __inline__
void flush_ei_region(unsigned int addr
)
109 __asm__
__volatile__("sta %%g0, [%0] %1\n\t" : :
110 "r" (addr
), "i" (ASI_M_FLUSH_REGION
) :
114 extern __inline__
void flush_ei_ctx(unsigned int addr
)
116 __asm__
__volatile__("sta %%g0, [%0] %1\n\t" : :
117 "r" (addr
), "i" (ASI_M_FLUSH_CTX
) :
121 extern __inline__
void flush_ei_user(unsigned int addr
)
123 __asm__
__volatile__("sta %%g0, [%0] %1\n\t" : :
124 "r" (addr
), "i" (ASI_M_FLUSH_USER
) :
128 #endif /* !(_SPARC_CACHE_H) */