cache.h revision 1.1.2.1 1 1.1.2.1 thorpej /* $NetBSD: cache.h,v 1.1.2.1 2001/10/24 16:47:51 thorpej Exp $ */
2 1.1.2.1 thorpej
3 1.1.2.1 thorpej /*
4 1.1.2.1 thorpej * Copyright 2001 Wasabi Systems, Inc.
5 1.1.2.1 thorpej * All rights reserved.
6 1.1.2.1 thorpej *
7 1.1.2.1 thorpej * Written by Jason R. Thorpe for Wasabi Systems, Inc.
8 1.1.2.1 thorpej *
9 1.1.2.1 thorpej * Redistribution and use in source and binary forms, with or without
10 1.1.2.1 thorpej * modification, are permitted provided that the following conditions
11 1.1.2.1 thorpej * are met:
12 1.1.2.1 thorpej * 1. Redistributions of source code must retain the above copyright
13 1.1.2.1 thorpej * notice, this list of conditions and the following disclaimer.
14 1.1.2.1 thorpej * 2. Redistributions in binary form must reproduce the above copyright
15 1.1.2.1 thorpej * notice, this list of conditions and the following disclaimer in the
16 1.1.2.1 thorpej * documentation and/or other materials provided with the distribution.
17 1.1.2.1 thorpej * 3. All advertising materials mentioning features or use of this software
18 1.1.2.1 thorpej * must display the following acknowledgement:
19 1.1.2.1 thorpej * This product includes software developed for the NetBSD Project by
20 1.1.2.1 thorpej * Wasabi Systems, Inc.
21 1.1.2.1 thorpej * 4. The name of Wasabi Systems, Inc. may not be used to endorse
22 1.1.2.1 thorpej * or promote products derived from this software without specific prior
23 1.1.2.1 thorpej * written permission.
24 1.1.2.1 thorpej *
25 1.1.2.1 thorpej * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
26 1.1.2.1 thorpej * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
27 1.1.2.1 thorpej * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 1.1.2.1 thorpej * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC
29 1.1.2.1 thorpej * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30 1.1.2.1 thorpej * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31 1.1.2.1 thorpej * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32 1.1.2.1 thorpej * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33 1.1.2.1 thorpej * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34 1.1.2.1 thorpej * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35 1.1.2.1 thorpej * POSSIBILITY OF SUCH DAMAGE.
36 1.1.2.1 thorpej */
37 1.1.2.1 thorpej
38 1.1.2.1 thorpej /*
39 1.1.2.1 thorpej * Cache operations.
40 1.1.2.1 thorpej *
41 1.1.2.1 thorpej * We define the following primitives:
42 1.1.2.1 thorpej *
43 1.1.2.1 thorpej * --- Instruction cache synchronization (mandatory):
44 1.1.2.1 thorpej *
45 1.1.2.1 thorpej * icache_sync_all Synchronize I-cache
46 1.1.2.1 thorpej *
47 1.1.2.1 thorpej * icache_sync_range Synchronize I-cache range
48 1.1.2.1 thorpej *
49 1.1.2.1 thorpej * icache_sync_range_index (index ops)
50 1.1.2.1 thorpej *
51 1.1.2.1 thorpej * --- Primary data cache (mandatory):
52 1.1.2.1 thorpej *
53 1.1.2.1 thorpej * pdcache_wbinv_all Write-back Invalidate primary D-cache
54 1.1.2.1 thorpej *
55 1.1.2.1 thorpej * pdcache_wbinv_range Write-back Invalidate primary D-cache range
56 1.1.2.1 thorpej *
57 1.1.2.1 thorpej * pdcache_wbinv_range_index (index ops)
58 1.1.2.1 thorpej *
59 1.1.2.1 thorpej * pdcache_inv_range Invalidate primary D-cache range
60 1.1.2.1 thorpej *
61 1.1.2.1 thorpej * pdcache_wb_range Write-back primary D-cache range
62 1.1.2.1 thorpej *
63 1.1.2.1 thorpej * --- Secondary data cache (optional):
64 1.1.2.1 thorpej *
65 1.1.2.1 thorpej * sdcache_wbinv_all Write-back Invalidate secondary D-cache
66 1.1.2.1 thorpej *
67 1.1.2.1 thorpej * sdcache_wbinv_range Write-back Invalidate secondary D-cache range
68 1.1.2.1 thorpej *
69 1.1.2.1 thorpej * sdcache_wbinv_range_index (index ops)
70 1.1.2.1 thorpej *
71 1.1.2.1 thorpej * sdcache_inv_range Invalidate secondary D-cache range
72 1.1.2.1 thorpej *
73 1.1.2.1 thorpej * sdcache_wb_range Write-back secondary D-cache range
74 1.1.2.1 thorpej *
75 1.1.2.1 thorpej * There are some rules that must be followed:
76 1.1.2.1 thorpej *
77 1.1.2.1 thorpej * I-cache Synch (all or range):
78 1.1.2.1 thorpej * The goal is to synchronize the instruction stream,
79 1.1.2.1 thorpej * so you may need to write-back dirty data cache
80 1.1.2.1 thorpej * blocks first. If a range is requested, and you
81 1.1.2.1 thorpej * can't synchronize just a range, you have to hit
82 1.1.2.1 thorpej * the whole thing.
83 1.1.2.1 thorpej *
84 1.1.2.1 thorpej * D-cache Write-back Invalidate range:
85 1.1.2.1 thorpej * If you can't WB-Inv a range, you must WB-Inv the
86 1.1.2.1 thorpej * entire D-cache.
87 1.1.2.1 thorpej *
88 1.1.2.1 thorpej * D-cache Invalidate:
89 1.1.2.1 thorpej * If you can't Inv the D-cache without doing a
90 1.1.2.1 thorpej * Write-back, YOU MUST PANIC. This is to catch
91 1.1.2.1 thorpej * errors in calling code. Callers must be aware
92 1.1.2.1 thorpej * of this scenario, and must handle it appropriately
93 1.1.2.1 thorpej * (consider the bus_dma(9) operations).
94 1.1.2.1 thorpej *
95 1.1.2.1 thorpej * D-cache Write-back:
96 1.1.2.1 thorpej * If you can't Write-back without doing an invalidate,
97 1.1.2.1 thorpej * that's fine. Then treat this as a WB-Inv. Skipping
98 1.1.2.1 thorpej * the invalidate is merely an optimization.
99 1.1.2.1 thorpej *
100 1.1.2.1 thorpej * All operations:
101 1.1.2.1 thorpej * Valid virtual addresses must be passed to the
102 1.1.2.1 thorpej * cache operation.
103 1.1.2.1 thorpej *
104 1.1.2.1 thorpej * Finally, these primitives are grouped together in reasonable
105 1.1.2.1 thorpej * ways. For all operations described here, first the primary
106 1.1.2.1 thorpej * cache is frobbed, then the secondary cache frobbed, if the
107 1.1.2.1 thorpej * operation for the secondary cache exists.
108 1.1.2.1 thorpej *
109 1.1.2.1 thorpej * mips_icache_sync_all Synchronize I-cache
110 1.1.2.1 thorpej *
111 1.1.2.1 thorpej * mips_icache_sync_range Synchronize I-cache range
112 1.1.2.1 thorpej *
113 1.1.2.1 thorpej * mips_icache_sync_range_index (index ops)
114 1.1.2.1 thorpej *
115 1.1.2.1 thorpej * mips_dcache_wbinv_all Write-back Invalidate D-cache
116 1.1.2.1 thorpej *
117 1.1.2.1 thorpej * mips_dcache_wbinv_range Write-back Invalidate D-cache range
118 1.1.2.1 thorpej *
119 1.1.2.1 thorpej * mips_dcache_wbinv_range_index (index ops)
120 1.1.2.1 thorpej *
121 1.1.2.1 thorpej * mips_dcache_inv_range Invalidate D-cache range
122 1.1.2.1 thorpej *
123 1.1.2.1 thorpej * mips_dcache_wb_range Write-back D-cache range
124 1.1.2.1 thorpej */
125 1.1.2.1 thorpej
126 1.1.2.1 thorpej struct mips_cache_ops {
127 1.1.2.1 thorpej void (*mco_icache_sync_all)(void);
128 1.1.2.1 thorpej void (*mco_icache_sync_range)(vaddr_t, vsize_t);
129 1.1.2.1 thorpej void (*mco_icache_sync_range_index)(vaddr_t, vsize_t);
130 1.1.2.1 thorpej
131 1.1.2.1 thorpej void (*mco_pdcache_wbinv_all)(void);
132 1.1.2.1 thorpej void (*mco_pdcache_wbinv_range)(vaddr_t, vsize_t);
133 1.1.2.1 thorpej void (*mco_pdcache_wbinv_range_index)(vaddr_t, vsize_t);
134 1.1.2.1 thorpej void (*mco_pdcache_inv_range)(vaddr_t, vsize_t);
135 1.1.2.1 thorpej void (*mco_pdcache_wb_range)(vaddr_t, vsize_t);
136 1.1.2.1 thorpej
137 1.1.2.1 thorpej void (*mco_sdcache_wbinv_all)(void);
138 1.1.2.1 thorpej void (*mco_sdcache_wbinv_range)(vaddr_t, vsize_t);
139 1.1.2.1 thorpej void (*mco_sdcache_wbinv_range_index)(vaddr_t, vsize_t);
140 1.1.2.1 thorpej void (*mco_sdcache_inv_range)(vaddr_t, vsize_t);
141 1.1.2.1 thorpej void (*mco_sdcache_wb_range)(vaddr_t, vsize_t);
142 1.1.2.1 thorpej };
143 1.1.2.1 thorpej
144 1.1.2.1 thorpej #ifdef _KERNEL
145 1.1.2.1 thorpej extern struct mips_cache_ops mips_cache_ops;
146 1.1.2.1 thorpej
147 1.1.2.1 thorpej /* PRIMARY CACHE VARIABLES */
148 1.1.2.1 thorpej extern int mips_picache_size;
149 1.1.2.1 thorpej extern int mips_picache_line_size;
150 1.1.2.1 thorpej extern int mips_picache_ways;
151 1.1.2.1 thorpej extern int mips_picache_way_size;
152 1.1.2.1 thorpej extern int mips_picache_way_mask;
153 1.1.2.1 thorpej
154 1.1.2.1 thorpej extern int mips_pdcache_size; /* and unified */
155 1.1.2.1 thorpej extern int mips_pdcache_line_size;
156 1.1.2.1 thorpej extern int mips_pdcache_ways;
157 1.1.2.1 thorpej extern int mips_pdcache_way_size;
158 1.1.2.1 thorpej extern int mips_pdcache_way_mask;
159 1.1.2.1 thorpej extern int mips_pdcache_write_through;
160 1.1.2.1 thorpej
161 1.1.2.1 thorpej extern int mips_pcache_unified;
162 1.1.2.1 thorpej
163 1.1.2.1 thorpej /* SECONDARY CACHE VARIABLES */
164 1.1.2.1 thorpej extern int mips_sicache_size;
165 1.1.2.1 thorpej extern int mips_sicache_line_size;
166 1.1.2.1 thorpej extern int mips_sicache_ways;
167 1.1.2.1 thorpej extern int mips_sicache_way_size;
168 1.1.2.1 thorpej extern int mips_sicache_way_mask;
169 1.1.2.1 thorpej
170 1.1.2.1 thorpej extern int mips_sdcache_size; /* and unified */
171 1.1.2.1 thorpej extern int mips_sdcache_line_size;
172 1.1.2.1 thorpej extern int mips_sdcache_ways;
173 1.1.2.1 thorpej extern int mips_sdcache_way_size;
174 1.1.2.1 thorpej extern int mips_sdcache_way_mask;
175 1.1.2.1 thorpej extern int mips_sdcache_write_through;
176 1.1.2.1 thorpej
177 1.1.2.1 thorpej extern int mips_scache_unified;
178 1.1.2.1 thorpej
179 1.1.2.1 thorpej /* TERTIARY CACHE VARIABLES */
180 1.1.2.1 thorpej extern int mips_tcache_size; /* always unified */
181 1.1.2.1 thorpej extern int mips_tcache_line_size;
182 1.1.2.1 thorpej extern int mips_tcache_ways;
183 1.1.2.1 thorpej extern int mips_tcache_way_size;
184 1.1.2.1 thorpej extern int mips_tcache_way_mask;
185 1.1.2.1 thorpej extern int mips_tcache_write_through;
186 1.1.2.1 thorpej
187 1.1.2.1 thorpej extern int mips_cache_alias_mask;
188 1.1.2.1 thorpej extern int mips_cache_prefer_mask;
189 1.1.2.1 thorpej
190 1.1.2.1 thorpej /*
191 1.1.2.1 thorpej * XXX XXX XXX THIS SHOULD NOT EXIST XXX XXX XXX
192 1.1.2.1 thorpej */
193 1.1.2.1 thorpej #define mips_cache_indexof(x) (((vaddr_t)(x)) & mips_cache_alias_mask)
194 1.1.2.1 thorpej
195 1.1.2.1 thorpej #define __mco_noargs(x) \
196 1.1.2.1 thorpej do { \
197 1.1.2.1 thorpej (*mips_cache_ops.mco_p ## x )(); \
198 1.1.2.1 thorpej if (*mips_cache_ops.mco_s ## x ) \
199 1.1.2.1 thorpej (*mips_cache_ops.mco_s ## x )(); \
200 1.1.2.1 thorpej } while (/*CONSTCOND*/0)
201 1.1.2.1 thorpej
202 1.1.2.1 thorpej #define __mco_2args(x, a, b) \
203 1.1.2.1 thorpej do { \
204 1.1.2.1 thorpej (*mips_cache_ops.mco_p ## x )((a), (b)); \
205 1.1.2.1 thorpej if (*mips_cache_ops.mco_s ## x ) \
206 1.1.2.1 thorpej (*mips_cache_ops.mco_s ## x )((a), (b)); \
207 1.1.2.1 thorpej } while (/*CONSTCOND*/0)
208 1.1.2.1 thorpej
209 1.1.2.1 thorpej #define mips_icache_sync_all() \
210 1.1.2.1 thorpej (*mips_cache_ops.mco_icache_sync_all)()
211 1.1.2.1 thorpej
212 1.1.2.1 thorpej #define mips_icache_sync_range(v, s) \
213 1.1.2.1 thorpej (*mips_cache_ops.mco_icache_sync_range)((v), (s))
214 1.1.2.1 thorpej
215 1.1.2.1 thorpej #define mips_icache_sync_range_index(v, s) \
216 1.1.2.1 thorpej (*mips_cache_ops.mco_icache_sync_range_index)((v), (s))
217 1.1.2.1 thorpej
218 1.1.2.1 thorpej #define mips_dcache_wbinv_all() \
219 1.1.2.1 thorpej __mco_noargs(dcache_wbinv_all)
220 1.1.2.1 thorpej
221 1.1.2.1 thorpej #define mips_dcache_wbinv_range(v, s) \
222 1.1.2.1 thorpej __mco_2args(dcache_wbinv_range, (v), (s))
223 1.1.2.1 thorpej
224 1.1.2.1 thorpej #define mips_dcache_wbinv_range_index(v, s) \
225 1.1.2.1 thorpej __mco_2args(dcache_wbinv_range_index, (v), (s))
226 1.1.2.1 thorpej
227 1.1.2.1 thorpej #define mips_dcache_inv_range(v, s) \
228 1.1.2.1 thorpej __mco_2args(dcache_inv_range, (v), (s))
229 1.1.2.1 thorpej
230 1.1.2.1 thorpej #define mips_dcache_wb_range(v, s) \
231 1.1.2.1 thorpej __mco_2args(dcache_wb_range, (v), (s))
232 1.1.2.1 thorpej
233 1.1.2.1 thorpej void mips_config_cache(void);
234 1.1.2.1 thorpej
235 1.1.2.1 thorpej #endif /* _KERNEL */
236