cache.h revision 1.2.8.3 1 1.2.8.3 jdolecek /* $NetBSD: cache.h,v 1.2.8.3 2002/06/23 17:40:37 jdolecek Exp $ */
2 1.2.8.2 jdolecek
3 1.2.8.2 jdolecek /*-
4 1.2.8.2 jdolecek * Copyright (c) 2002 The NetBSD Foundation, Inc.
5 1.2.8.2 jdolecek * All rights reserved.
6 1.2.8.2 jdolecek *
7 1.2.8.2 jdolecek * This code is derived from software contributed to The NetBSD Foundation
8 1.2.8.2 jdolecek * by UCHIYAMA Yasushi.
9 1.2.8.2 jdolecek *
10 1.2.8.2 jdolecek * Redistribution and use in source and binary forms, with or without
11 1.2.8.2 jdolecek * modification, are permitted provided that the following conditions
12 1.2.8.2 jdolecek * are met:
13 1.2.8.2 jdolecek * 1. Redistributions of source code must retain the above copyright
14 1.2.8.2 jdolecek * notice, this list of conditions and the following disclaimer.
15 1.2.8.2 jdolecek * 2. Redistributions in binary form must reproduce the above copyright
16 1.2.8.2 jdolecek * notice, this list of conditions and the following disclaimer in the
17 1.2.8.2 jdolecek * documentation and/or other materials provided with the distribution.
18 1.2.8.2 jdolecek * 3. All advertising materials mentioning features or use of this software
19 1.2.8.2 jdolecek * must display the following acknowledgement:
20 1.2.8.2 jdolecek * This product includes software developed by the NetBSD
21 1.2.8.2 jdolecek * Foundation, Inc. and its contributors.
22 1.2.8.2 jdolecek * 4. Neither the name of The NetBSD Foundation nor the names of its
23 1.2.8.2 jdolecek * contributors may be used to endorse or promote products derived
24 1.2.8.2 jdolecek * from this software without specific prior written permission.
25 1.2.8.2 jdolecek *
26 1.2.8.2 jdolecek * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 1.2.8.2 jdolecek * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 1.2.8.2 jdolecek * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 1.2.8.2 jdolecek * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 1.2.8.2 jdolecek * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 1.2.8.2 jdolecek * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 1.2.8.2 jdolecek * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 1.2.8.2 jdolecek * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 1.2.8.2 jdolecek * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 1.2.8.2 jdolecek * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 1.2.8.2 jdolecek * POSSIBILITY OF SUCH DAMAGE.
37 1.2.8.2 jdolecek */
38 1.2.8.2 jdolecek
39 1.2.8.2 jdolecek /*
40 1.2.8.2 jdolecek * Cache configurations.
41 1.2.8.2 jdolecek *
42 1.2.8.2 jdolecek * SH3 I/D unified virtual-index physical-tag cache.
43 1.2.8.2 jdolecek * SH4 I/D separated virtual-index physical-tag cache.
44 1.2.8.2 jdolecek *
45 1.2.8.2 jdolecek *
46 1.2.8.2 jdolecek * size line-size entry way
47 1.2.8.2 jdolecek * SH7708 4/8K 16B 128 2/4 P0, P2, U0 write-through/back selectable
48 1.2.8.2 jdolecek * P1 write-through
49 1.2.8.2 jdolecek * SH7709 4/8K 16B 128 2/4 write-through/back selectable
50 1.2.8.2 jdolecek * SH7709A 16K 16B 256 4 write-through/back selectable
51 1.2.8.2 jdolecek *
52 1.2.8.2 jdolecek * SH7750 I$ D$ line-size entry way
53 1.2.8.2 jdolecek * 8K 8/16K 32B 256 1 write-through/back selectable
54 1.2.8.2 jdolecek *
55 1.2.8.3 jdolecek *
56 1.2.8.2 jdolecek * Cache operations.
57 1.2.8.3 jdolecek *
58 1.2.8.2 jdolecek * There are some rules that must be followed:
59 1.2.8.2 jdolecek *
60 1.2.8.2 jdolecek * I-cache Synch (all or range):
61 1.2.8.2 jdolecek * The goal is to synchronize the instruction stream,
62 1.2.8.2 jdolecek * so you may need to write-back dirty data cache
63 1.2.8.2 jdolecek * blocks first. If a range is requested, and you
64 1.2.8.2 jdolecek * can't synchronize just a range, you have to hit
65 1.2.8.2 jdolecek * the whole thing.
66 1.2.8.2 jdolecek *
67 1.2.8.2 jdolecek * D-cache Write-back Invalidate range:
68 1.2.8.2 jdolecek * If you can't WB-Inv a range, you must WB-Inv the
69 1.2.8.2 jdolecek * entire D-cache.
70 1.2.8.2 jdolecek *
71 1.2.8.2 jdolecek * D-cache Invalidate:
72 1.2.8.2 jdolecek * If you can't Inv the D-cache without doing a
73 1.2.8.2 jdolecek * Write-back, YOU MUST PANIC. This is to catch
74 1.2.8.2 jdolecek * errors in calling code. Callers must be aware
75 1.2.8.2 jdolecek * of this scenario, and must handle it appropriately
76 1.2.8.2 jdolecek * (consider the bus_dma(9) operations).
77 1.2.8.2 jdolecek *
78 1.2.8.2 jdolecek * D-cache Write-back:
79 1.2.8.2 jdolecek * If you can't Write-back without doing an invalidate,
80 1.2.8.2 jdolecek * that's fine. Then treat this as a WB-Inv. Skipping
81 1.2.8.2 jdolecek * the invalidate is merely an optimization.
82 1.2.8.2 jdolecek *
83 1.2.8.2 jdolecek * All operations:
84 1.2.8.2 jdolecek * Valid virtual addresses must be passed to the
85 1.2.8.2 jdolecek * cache operation.
86 1.2.8.2 jdolecek *
87 1.2.8.2 jdolecek *
88 1.2.8.2 jdolecek * sh_icache_sync_all Synchronize I-cache
89 1.2.8.2 jdolecek *
90 1.2.8.2 jdolecek * sh_icache_sync_range Synchronize I-cache range
91 1.2.8.2 jdolecek *
92 1.2.8.2 jdolecek * sh_icache_sync_range_index (index ops)
93 1.2.8.2 jdolecek *
94 1.2.8.2 jdolecek * sh_dcache_wbinv_all Write-back Invalidate D-cache
95 1.2.8.2 jdolecek *
96 1.2.8.2 jdolecek * sh_dcache_wbinv_range Write-back Invalidate D-cache range
97 1.2.8.2 jdolecek *
98 1.2.8.2 jdolecek * sh_dcache_wbinv_range_index (index ops)
99 1.2.8.2 jdolecek *
100 1.2.8.2 jdolecek * sh_dcache_inv_range Invalidate D-cache range
101 1.2.8.2 jdolecek *
102 1.2.8.2 jdolecek * sh_dcache_wb_range Write-back D-cache range
103 1.2.8.3 jdolecek *
104 1.2.8.3 jdolecek * If I/D unified cache (SH3), I-cache ops are writeback invalidate
105 1.2.8.2 jdolecek * operation.
106 1.2.8.2 jdolecek * If write-through mode, sh_dcache_wb_range is no-operation.
107 1.2.8.2 jdolecek *
108 1.2.8.2 jdolecek */
109 1.2.8.2 jdolecek
110 1.2.8.2 jdolecek #ifndef _SH3_CACHE_H_
111 1.2.8.3 jdolecek #define _SH3_CACHE_H_
112 1.2.8.2 jdolecek
113 1.2.8.2 jdolecek #ifdef _KERNEL
114 1.2.8.2 jdolecek struct sh_cache_ops {
115 1.2.8.2 jdolecek void (*_icache_sync_all)(void);
116 1.2.8.2 jdolecek void (*_icache_sync_range)(vaddr_t, vsize_t);
117 1.2.8.2 jdolecek void (*_icache_sync_range_index)(vaddr_t, vsize_t);
118 1.2.8.3 jdolecek
119 1.2.8.2 jdolecek void (*_dcache_wbinv_all)(void);
120 1.2.8.2 jdolecek void (*_dcache_wbinv_range)(vaddr_t, vsize_t);
121 1.2.8.2 jdolecek void (*_dcache_wbinv_range_index)(vaddr_t, vsize_t);
122 1.2.8.2 jdolecek void (*_dcache_inv_range)(vaddr_t, vsize_t);
123 1.2.8.2 jdolecek void (*_dcache_wb_range)(vaddr_t, vsize_t);
124 1.2.8.2 jdolecek };
125 1.2.8.2 jdolecek
126 1.2.8.2 jdolecek /* Cache configurations */
127 1.2.8.3 jdolecek #define sh_cache_enable_unified sh_cache_enable_icache
128 1.2.8.2 jdolecek extern int sh_cache_enable_icache;
129 1.2.8.2 jdolecek extern int sh_cache_enable_dcache;
130 1.2.8.2 jdolecek extern int sh_cache_write_through;
131 1.2.8.2 jdolecek extern int sh_cache_write_through_p0_u0_p3;
132 1.2.8.2 jdolecek extern int sh_cache_write_through_p1;
133 1.2.8.2 jdolecek extern int sh_cache_ways;
134 1.2.8.2 jdolecek extern int sh_cache_unified;
135 1.2.8.3 jdolecek #define sh_cache_size_unified sh_cache_size_icache
136 1.2.8.2 jdolecek extern int sh_cache_size_icache;
137 1.2.8.2 jdolecek extern int sh_cache_size_dcache;
138 1.2.8.2 jdolecek extern int sh_cache_line_size;
139 1.2.8.2 jdolecek /* for n-way set associative cache */
140 1.2.8.2 jdolecek extern int sh_cache_way_size;
141 1.2.8.2 jdolecek extern int sh_cache_way_shift;
142 1.2.8.2 jdolecek extern int sh_cache_entry_mask;
143 1.2.8.2 jdolecek
144 1.2.8.2 jdolecek /* Special mode */
145 1.2.8.2 jdolecek extern int sh_cache_ram_mode;
146 1.2.8.2 jdolecek extern int sh_cache_index_mode_icache;
147 1.2.8.2 jdolecek extern int sh_cache_index_mode_dcache;
148 1.2.8.2 jdolecek
149 1.2.8.2 jdolecek extern struct sh_cache_ops sh_cache_ops;
150 1.2.8.2 jdolecek
151 1.2.8.2 jdolecek #define sh_icache_sync_all() \
152 1.2.8.2 jdolecek (*sh_cache_ops._icache_sync_all)()
153 1.2.8.2 jdolecek
154 1.2.8.2 jdolecek #define sh_icache_sync_range(v, s) \
155 1.2.8.2 jdolecek (*sh_cache_ops._icache_sync_range)((v), (s))
156 1.2.8.2 jdolecek
157 1.2.8.2 jdolecek #define sh_icache_sync_range_index(v, s) \
158 1.2.8.2 jdolecek (*sh_cache_ops._icache_sync_range_index)((v), (s))
159 1.2.8.2 jdolecek
160 1.2.8.2 jdolecek #define sh_dcache_wbinv_all() \
161 1.2.8.2 jdolecek (*sh_cache_ops._dcache_wbinv_all)()
162 1.2.8.2 jdolecek
163 1.2.8.2 jdolecek #define sh_dcache_wbinv_range(v, s) \
164 1.2.8.2 jdolecek (*sh_cache_ops._dcache_wbinv_range)((v), (s))
165 1.2.8.2 jdolecek
166 1.2.8.2 jdolecek #define sh_dcache_wbinv_range_index(v, s) \
167 1.2.8.2 jdolecek (*sh_cache_ops._dcache_wbinv_range_index)((v), (s))
168 1.2.8.2 jdolecek
169 1.2.8.2 jdolecek #define sh_dcache_inv_range(v, s) \
170 1.2.8.2 jdolecek (*sh_cache_ops._dcache_inv_range)((v), (s))
171 1.2.8.2 jdolecek
172 1.2.8.2 jdolecek #define sh_dcache_wb_range(v, s) \
173 1.2.8.2 jdolecek (*sh_cache_ops._dcache_wb_range)((v), (s))
174 1.2.8.2 jdolecek
175 1.2.8.2 jdolecek void sh_cache_init(void);
176 1.2.8.2 jdolecek void sh_cache_information(void);
177 1.2.8.2 jdolecek
178 1.2.8.3 jdolecek #if defined(SH3) && defined(SH4)
179 1.2.8.3 jdolecek #define SH_HAS_VIRTUAL_ALIAS CPU_IS_SH4
180 1.2.8.3 jdolecek #define SH_HAS_UNIFIED_CACHE CPU_IS_SH3
181 1.2.8.3 jdolecek #define SH_HAS_WRITEBACK_CACHE (!sh_cache_write_through)
182 1.2.8.3 jdolecek #elif defined(SH3)
183 1.2.8.3 jdolecek #define SH_HAS_VIRTUAL_ALIAS 0
184 1.2.8.3 jdolecek #define SH_HAS_UNIFIED_CACHE 1
185 1.2.8.3 jdolecek #define SH_HAS_WRITEBACK_CACHE (!sh_cache_write_through)
186 1.2.8.3 jdolecek #elif defined(SH4)
187 1.2.8.3 jdolecek #define SH_HAS_VIRTUAL_ALIAS 1
188 1.2.8.3 jdolecek #define SH_HAS_UNIFIED_CACHE 0
189 1.2.8.3 jdolecek #define SH_HAS_WRITEBACK_CACHE (!sh_cache_write_through)
190 1.2.8.3 jdolecek #endif
191 1.2.8.3 jdolecek
192 1.2.8.2 jdolecek #endif /* _KERNEL */
193 1.2.8.2 jdolecek #endif /* _SH3_CACHE_H_ */
194