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