cache_sh3.h revision 1.4.2.3 1 1.4.2.3 jdolecek /* $NetBSD: cache_sh3.h,v 1.4.2.3 2002/06/23 17:40:37 jdolecek Exp $ */
2 1.4.2.2 jdolecek
3 1.4.2.2 jdolecek /*-
4 1.4.2.2 jdolecek * Copyright (c) 2002 The NetBSD Foundation, Inc.
5 1.4.2.2 jdolecek * All rights reserved.
6 1.4.2.2 jdolecek *
7 1.4.2.2 jdolecek * This code is derived from software contributed to The NetBSD Foundation
8 1.4.2.2 jdolecek * by UCHIYAMA Yasushi.
9 1.4.2.2 jdolecek *
10 1.4.2.2 jdolecek * Redistribution and use in source and binary forms, with or without
11 1.4.2.2 jdolecek * modification, are permitted provided that the following conditions
12 1.4.2.2 jdolecek * are met:
13 1.4.2.2 jdolecek * 1. Redistributions of source code must retain the above copyright
14 1.4.2.2 jdolecek * notice, this list of conditions and the following disclaimer.
15 1.4.2.2 jdolecek * 2. Redistributions in binary form must reproduce the above copyright
16 1.4.2.2 jdolecek * notice, this list of conditions and the following disclaimer in the
17 1.4.2.2 jdolecek * documentation and/or other materials provided with the distribution.
18 1.4.2.2 jdolecek * 3. All advertising materials mentioning features or use of this software
19 1.4.2.2 jdolecek * must display the following acknowledgement:
20 1.4.2.2 jdolecek * This product includes software developed by the NetBSD
21 1.4.2.2 jdolecek * Foundation, Inc. and its contributors.
22 1.4.2.2 jdolecek * 4. Neither the name of The NetBSD Foundation nor the names of its
23 1.4.2.2 jdolecek * contributors may be used to endorse or promote products derived
24 1.4.2.2 jdolecek * from this software without specific prior written permission.
25 1.4.2.2 jdolecek *
26 1.4.2.2 jdolecek * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 1.4.2.2 jdolecek * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 1.4.2.2 jdolecek * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 1.4.2.2 jdolecek * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 1.4.2.2 jdolecek * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 1.4.2.2 jdolecek * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 1.4.2.2 jdolecek * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 1.4.2.2 jdolecek * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 1.4.2.2 jdolecek * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 1.4.2.2 jdolecek * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 1.4.2.2 jdolecek * POSSIBILITY OF SUCH DAMAGE.
37 1.4.2.2 jdolecek */
38 1.4.2.2 jdolecek
39 1.4.2.2 jdolecek /*
40 1.4.2.2 jdolecek * SH3: SH7708, SH7708S, SH7708R, SH7709, SH7709A
41 1.4.2.2 jdolecek */
42 1.4.2.3 jdolecek #ifndef _SH3_CACHE_SH3_H_
43 1.4.2.3 jdolecek #define _SH3_CACHE_SH3_H_
44 1.4.2.2 jdolecek #include <sh3/devreg.h>
45 1.4.2.2 jdolecek #ifdef _KERNEL
46 1.4.2.2 jdolecek
47 1.4.2.3 jdolecek #define SH3_CCR 0xffffffec
48 1.4.2.3 jdolecek #define SH3_CCR_CE 0x00000001
49 1.4.2.3 jdolecek #define SH3_CCR_WT 0x00000002
50 1.4.2.2 jdolecek /* SH7708 don't have CB bit */
51 1.4.2.3 jdolecek #define SH3_CCR_CB 0x00000004
52 1.4.2.3 jdolecek #define SH3_CCR_CF 0x00000008
53 1.4.2.2 jdolecek /* SH7709A don't have RA bit */
54 1.4.2.2 jdolecek #define SH3_CCR_RA 0x00000020
55 1.4.2.2 jdolecek
56 1.4.2.2 jdolecek /* SH7709A specific cache-lock control register */
57 1.4.2.3 jdolecek #define SH7709A_CCR2 0xa40000b0
58 1.4.2.3 jdolecek #define SH7709A_CCR2_W2LOCK 0x00000001
59 1.4.2.3 jdolecek #define SH7709A_CCR2_W2LOAD 0x00000002
60 1.4.2.3 jdolecek #define SH7709A_CCR2_W3LOCK 0x00000100
61 1.4.2.3 jdolecek #define SH7709A_CCR2_W3LOAD 0x00000200
62 1.4.2.2 jdolecek
63 1.4.2.3 jdolecek #define SH3_CCA 0xf0000000
64 1.4.2.2 jdolecek /* Address specification */
65 1.4.2.3 jdolecek #define CCA_A 0x00000008
66 1.4.2.3 jdolecek #define CCA_ENTRY_SHIFT 4
67 1.4.2.2 jdolecek /* 8KB cache (SH7708, SH7708S, SH7708R, SH7709) */
68 1.4.2.3 jdolecek #define CCA_8K_ENTRY 128
69 1.4.2.3 jdolecek #define CCA_8K_ENTRY_MASK 0x000007f0 /* [10:4] */
70 1.4.2.3 jdolecek #define CCA_8K_WAY_SHIFT 11
71 1.4.2.3 jdolecek #define CCA_8K_WAY_MASK 0x00001800 /* [12:11] */
72 1.4.2.2 jdolecek /* 16KB cache (SH7709A) */
73 1.4.2.3 jdolecek #define CCA_16K_ENTRY 256
74 1.4.2.3 jdolecek #define CCA_16K_ENTRY_MASK 0x00000ff0 /* [11:4] */
75 1.4.2.3 jdolecek #define CCA_16K_WAY_SHIFT 12
76 1.4.2.3 jdolecek #define CCA_16K_WAY_MASK 0x00003000 /* [13:12] */
77 1.4.2.2 jdolecek
78 1.4.2.2 jdolecek /* Data specification */
79 1.4.2.2 jdolecek #define CCA_V 0x00000001
80 1.4.2.3 jdolecek #define CCA_U 0x00000002
81 1.4.2.2 jdolecek #define CCA_LRU_SHIFT 4
82 1.4.2.3 jdolecek #define CCA_LRU_MASK 0x000003f0 /* [9:4] */
83 1.4.2.3 jdolecek #define CCA_TAGADDR_SHIFT 10
84 1.4.2.3 jdolecek #define CCA_TAGADDR_MASK 0xfffffc00 /* [31:10] */
85 1.4.2.2 jdolecek
86 1.4.2.3 jdolecek #define SH3_CCD 0xf1000000
87 1.4.2.2 jdolecek /* Address specification */
88 1.4.2.3 jdolecek #define CCD_L_SHIFT 2
89 1.4.2.3 jdolecek #define CCD_L_MASK 0x0000000c /* [3:2] */
90 1.4.2.3 jdolecek #define CCD_E_SHIFT 4
91 1.4.2.3 jdolecek #define CCD_8K_E_MASK 0x000007f0 /* [10:4] */
92 1.4.2.3 jdolecek #define CCD_16K_E_MASK 0x00000ff0 /* [11:4] */
93 1.4.2.3 jdolecek #define CCD_8K_W_SHIFT 11
94 1.4.2.3 jdolecek #define CCD_8K_W_MASK 0x00001800 /* [12:11] */
95 1.4.2.3 jdolecek #define CCD_16K_W_SHIFT 12
96 1.4.2.3 jdolecek #define CCD_16K_W_MASK 0x00003000 /* [13:12] */
97 1.4.2.2 jdolecek /* Data specification */
98 1.4.2.2 jdolecek
99 1.4.2.2 jdolecek /*
100 1.4.2.2 jdolecek * Configuration
101 1.4.2.2 jdolecek */
102 1.4.2.3 jdolecek #define SH3_CACHE_LINESZ 16
103 1.4.2.3 jdolecek #define SH3_CACHE_NORMAL_WAY 4
104 1.4.2.3 jdolecek #define SH3_CACHE_RAMMODE_WAY 2
105 1.4.2.3 jdolecek
106 1.4.2.3 jdolecek #define SH3_CACHE_8K_ENTRY 128
107 1.4.2.3 jdolecek #define SH3_CACHE_8K_WAY_NORMAL 4
108 1.4.2.3 jdolecek #define SH3_CACHE_8K_WAY_RAMMODE 2
109 1.4.2.2 jdolecek
110 1.4.2.3 jdolecek #define SH3_CACHE_16K_ENTRY 256
111 1.4.2.3 jdolecek #define SH3_CACHE_16K_WAY 4
112 1.4.2.2 jdolecek
113 1.4.2.2 jdolecek /*
114 1.4.2.2 jdolecek * cache flush macro for locore level code.
115 1.4.2.2 jdolecek */
116 1.4.2.3 jdolecek #define SH3_CACHE_8K_FLUSH(maxway) \
117 1.4.2.2 jdolecek do { \
118 1.4.2.2 jdolecek u_int32_t __e, __w, __wa, __a; \
119 1.4.2.2 jdolecek \
120 1.4.2.2 jdolecek for (__w = 0; __w < maxway; __w++) { \
121 1.4.2.2 jdolecek __wa = SH3_CCA | __w << CCA_8K_WAY_SHIFT; \
122 1.4.2.2 jdolecek for (__e = 0; __e < CCA_8K_ENTRY; __e++) { \
123 1.4.2.2 jdolecek __a = __wa |(__e << CCA_ENTRY_SHIFT); \
124 1.4.2.2 jdolecek (*(__volatile__ u_int32_t *)__a) &= \
125 1.4.2.2 jdolecek ~(CCA_U | CCA_V); \
126 1.4.2.2 jdolecek } \
127 1.4.2.2 jdolecek } \
128 1.4.2.2 jdolecek } while (/*CONSTCOND*/0)
129 1.4.2.2 jdolecek
130 1.4.2.3 jdolecek #define SH3_CACHE_16K_FLUSH() \
131 1.4.2.2 jdolecek do { \
132 1.4.2.2 jdolecek u_int32_t __e, __w, __wa, __a; \
133 1.4.2.2 jdolecek \
134 1.4.2.2 jdolecek for (__w = 0; __w < SH3_CACHE_16K_WAY; __w++) { \
135 1.4.2.2 jdolecek __wa = SH3_CCA | __w << CCA_16K_WAY_SHIFT; \
136 1.4.2.2 jdolecek for (__e = 0; __e < CCA_16K_ENTRY; __e++) { \
137 1.4.2.2 jdolecek __a = __wa |(__e << CCA_ENTRY_SHIFT); \
138 1.4.2.2 jdolecek (*(__volatile__ u_int32_t *)__a) &= \
139 1.4.2.2 jdolecek ~(CCA_U | CCA_V); \
140 1.4.2.2 jdolecek } \
141 1.4.2.2 jdolecek } \
142 1.4.2.2 jdolecek } while (/*CONSTCOND*/0)
143 1.4.2.2 jdolecek
144 1.4.2.3 jdolecek #define SH7708_CACHE_FLUSH() SH3_CACHE_8K_FLUSH(4)
145 1.4.2.3 jdolecek #define SH7708_CACHE_FLUSH_RAMMODE() SH3_CACHE_8K_FLUSH(2)
146 1.4.2.3 jdolecek #define SH7708S_CACHE_FLUSH() SH3_CACHE_8K_FLUSH(4)
147 1.4.2.3 jdolecek #define SH7708S_CACHE_FLUSH_RAMMODE() SH3_CACHE_8K_FLUSH(2)
148 1.4.2.3 jdolecek #define SH7708R_CACHE_FLUSH() SH3_CACHE_8K_FLUSH(4)
149 1.4.2.3 jdolecek #define SH7708R_CACHE_FLUSH_RAMMODE() SH3_CACHE_8K_FLUSH(2)
150 1.4.2.3 jdolecek #define SH7709_CACHE_FLUSH() SH3_CACHE_8K_FLUSH(4)
151 1.4.2.3 jdolecek #define SH7709_CACHE_FLUSH_RAMMODE() SH3_CACHE_8K_FLUSH(2)
152 1.4.2.3 jdolecek #define SH7709A_CACHE_FLUSH() SH3_CACHE_16K_FLUSH()
153 1.4.2.2 jdolecek
154 1.4.2.2 jdolecek #ifndef _LOCORE
155 1.4.2.2 jdolecek extern void sh3_cache_config(void);
156 1.4.2.2 jdolecek #endif
157 1.4.2.3 jdolecek #endif /* _KERNEL */
158 1.4.2.3 jdolecek #endif /* !_SH3_CACHE_SH3_H_ */
159