cache.c revision 1.2.14.2 1 1.2.14.2 ad /* $NetBSD: cache.c,v 1.2.14.2 2007/12/03 19:03:07 ad Exp $ */
2 1.2.14.2 ad
3 1.2.14.2 ad /*
4 1.2.14.2 ad * Copyright 2001 Wasabi Systems, Inc.
5 1.2.14.2 ad * All rights reserved.
6 1.2.14.2 ad *
7 1.2.14.2 ad * Written by Jason R. Thorpe for Wasabi Systems, Inc.
8 1.2.14.2 ad *
9 1.2.14.2 ad * Redistribution and use in source and binary forms, with or without
10 1.2.14.2 ad * modification, are permitted provided that the following conditions
11 1.2.14.2 ad * are met:
12 1.2.14.2 ad * 1. Redistributions of source code must retain the above copyright
13 1.2.14.2 ad * notice, this list of conditions and the following disclaimer.
14 1.2.14.2 ad * 2. Redistributions in binary form must reproduce the above copyright
15 1.2.14.2 ad * notice, this list of conditions and the following disclaimer in the
16 1.2.14.2 ad * documentation and/or other materials provided with the distribution.
17 1.2.14.2 ad * 3. All advertising materials mentioning features or use of this software
18 1.2.14.2 ad * must display the following acknowledgement:
19 1.2.14.2 ad * This product includes software developed for the NetBSD Project by
20 1.2.14.2 ad * Wasabi Systems, Inc.
21 1.2.14.2 ad * 4. The name of Wasabi Systems, Inc. may not be used to endorse
22 1.2.14.2 ad * or promote products derived from this software without specific prior
23 1.2.14.2 ad * written permission.
24 1.2.14.2 ad *
25 1.2.14.2 ad * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
26 1.2.14.2 ad * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
27 1.2.14.2 ad * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 1.2.14.2 ad * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC
29 1.2.14.2 ad * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30 1.2.14.2 ad * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31 1.2.14.2 ad * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32 1.2.14.2 ad * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33 1.2.14.2 ad * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34 1.2.14.2 ad * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35 1.2.14.2 ad * POSSIBILITY OF SUCH DAMAGE.
36 1.2.14.2 ad */
37 1.2.14.2 ad
38 1.2.14.2 ad #include <lib/libsa/stand.h>
39 1.2.14.2 ad #include <lib/libkern/libkern.h>
40 1.2.14.2 ad
41 1.2.14.2 ad #include <mips/cpuregs.h>
42 1.2.14.2 ad #include <mips/cache_r4k.h>
43 1.2.14.2 ad
44 1.2.14.2 ad #include "boot.h"
45 1.2.14.2 ad
46 1.2.14.2 ad #define round_line(x) (((x) + (CACHELINESIZE - 1)) & ~(CACHELINESIZE - 1))
47 1.2.14.2 ad #define trunc_line(x) ((x) & ~(CACHELINESIZE - 1))
48 1.2.14.2 ad
49 1.2.14.2 ad __asm(".set mips3");
50 1.2.14.2 ad
51 1.2.14.2 ad void
52 1.2.14.2 ad pdcache_inv(uint32_t va, u_int size)
53 1.2.14.2 ad {
54 1.2.14.2 ad uint32_t eva;
55 1.2.14.2 ad
56 1.2.14.2 ad eva = round_line(va + size);
57 1.2.14.2 ad va = trunc_line(va);
58 1.2.14.2 ad
59 1.2.14.2 ad while (va < eva) {
60 1.2.14.2 ad cache_op_r4k_line(va, CACHE_R4K_D|CACHEOP_R4K_HIT_INV);
61 1.2.14.2 ad va += CACHELINESIZE;
62 1.2.14.2 ad }
63 1.2.14.2 ad }
64 1.2.14.2 ad
65 1.2.14.2 ad void
66 1.2.14.2 ad pdcache_wb(uint32_t va, u_int size)
67 1.2.14.2 ad {
68 1.2.14.2 ad uint32_t eva;
69 1.2.14.2 ad
70 1.2.14.2 ad eva = round_line(va + size);
71 1.2.14.2 ad va = trunc_line(va);
72 1.2.14.2 ad
73 1.2.14.2 ad while (va < eva) {
74 1.2.14.2 ad cache_op_r4k_line(va, CACHE_R4K_D|CACHEOP_R4K_HIT_WB);
75 1.2.14.2 ad va += CACHELINESIZE;
76 1.2.14.2 ad }
77 1.2.14.2 ad }
78 1.2.14.2 ad
79 1.2.14.2 ad void
80 1.2.14.2 ad pdcache_wbinv(uint32_t va, u_int size)
81 1.2.14.2 ad {
82 1.2.14.2 ad uint32_t eva;
83 1.2.14.2 ad
84 1.2.14.2 ad eva = round_line(va + size);
85 1.2.14.2 ad va = trunc_line(va);
86 1.2.14.2 ad
87 1.2.14.2 ad while (va < eva) {
88 1.2.14.2 ad cache_op_r4k_line(va, CACHE_R4K_D|CACHEOP_R4K_HIT_WB_INV);
89 1.2.14.2 ad va += CACHELINESIZE;
90 1.2.14.2 ad }
91 1.2.14.2 ad }
92 1.2.14.2 ad /* $NetBSD: cache.c,v 1.2.14.2 2007/12/03 19:03:07 ad Exp $ */
93 1.2.14.2 ad
94 1.2.14.2 ad /*
95 1.2.14.2 ad * Copyright 2001 Wasabi Systems, Inc.
96 1.2.14.2 ad * All rights reserved.
97 1.2.14.2 ad *
98 1.2.14.2 ad * Written by Jason R. Thorpe for Wasabi Systems, Inc.
99 1.2.14.2 ad *
100 1.2.14.2 ad * Redistribution and use in source and binary forms, with or without
101 1.2.14.2 ad * modification, are permitted provided that the following conditions
102 1.2.14.2 ad * are met:
103 1.2.14.2 ad * 1. Redistributions of source code must retain the above copyright
104 1.2.14.2 ad * notice, this list of conditions and the following disclaimer.
105 1.2.14.2 ad * 2. Redistributions in binary form must reproduce the above copyright
106 1.2.14.2 ad * notice, this list of conditions and the following disclaimer in the
107 1.2.14.2 ad * documentation and/or other materials provided with the distribution.
108 1.2.14.2 ad * 3. All advertising materials mentioning features or use of this software
109 1.2.14.2 ad * must display the following acknowledgement:
110 1.2.14.2 ad * This product includes software developed for the NetBSD Project by
111 1.2.14.2 ad * Wasabi Systems, Inc.
112 1.2.14.2 ad * 4. The name of Wasabi Systems, Inc. may not be used to endorse
113 1.2.14.2 ad * or promote products derived from this software without specific prior
114 1.2.14.2 ad * written permission.
115 1.2.14.2 ad *
116 1.2.14.2 ad * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
117 1.2.14.2 ad * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
118 1.2.14.2 ad * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
119 1.2.14.2 ad * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC
120 1.2.14.2 ad * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
121 1.2.14.2 ad * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
122 1.2.14.2 ad * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
123 1.2.14.2 ad * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
124 1.2.14.2 ad * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
125 1.2.14.2 ad * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
126 1.2.14.2 ad * POSSIBILITY OF SUCH DAMAGE.
127 1.2.14.2 ad */
128 1.2.14.2 ad
129 1.2.14.2 ad #include <lib/libsa/stand.h>
130 1.2.14.2 ad #include <lib/libkern/libkern.h>
131 1.2.14.2 ad
132 1.2.14.2 ad #include <mips/cpuregs.h>
133 1.2.14.2 ad #include <mips/cache_r4k.h>
134 1.2.14.2 ad
135 1.2.14.2 ad #include "boot.h"
136 1.2.14.2 ad
137 1.2.14.2 ad #define round_line(x) (((x) + (CACHELINESIZE - 1)) & ~(CACHELINESIZE - 1))
138 1.2.14.2 ad #define trunc_line(x) ((x) & ~(CACHELINESIZE - 1))
139 1.2.14.2 ad
140 1.2.14.2 ad __asm(".set mips3");
141 1.2.14.2 ad
142 1.2.14.2 ad void
143 1.2.14.2 ad pdcache_inv(uint32_t va, u_int size)
144 1.2.14.2 ad {
145 1.2.14.2 ad uint32_t eva;
146 1.2.14.2 ad
147 1.2.14.2 ad eva = round_line(va + size);
148 1.2.14.2 ad va = trunc_line(va);
149 1.2.14.2 ad
150 1.2.14.2 ad while (va < eva) {
151 1.2.14.2 ad cache_op_r4k_line(va, CACHE_R4K_D|CACHEOP_R4K_HIT_INV);
152 1.2.14.2 ad va += CACHELINESIZE;
153 1.2.14.2 ad }
154 1.2.14.2 ad }
155 1.2.14.2 ad
156 1.2.14.2 ad void
157 1.2.14.2 ad pdcache_wb(uint32_t va, u_int size)
158 1.2.14.2 ad {
159 1.2.14.2 ad uint32_t eva;
160 1.2.14.2 ad
161 1.2.14.2 ad eva = round_line(va + size);
162 1.2.14.2 ad va = trunc_line(va);
163 1.2.14.2 ad
164 1.2.14.2 ad while (va < eva) {
165 1.2.14.2 ad cache_op_r4k_line(va, CACHE_R4K_D|CACHEOP_R4K_HIT_WB);
166 1.2.14.2 ad va += CACHELINESIZE;
167 1.2.14.2 ad }
168 1.2.14.2 ad }
169 1.2.14.2 ad
170 1.2.14.2 ad void
171 1.2.14.2 ad pdcache_wbinv(uint32_t va, u_int size)
172 1.2.14.2 ad {
173 1.2.14.2 ad uint32_t eva;
174 1.2.14.2 ad
175 1.2.14.2 ad eva = round_line(va + size);
176 1.2.14.2 ad va = trunc_line(va);
177 1.2.14.2 ad
178 1.2.14.2 ad while (va < eva) {
179 1.2.14.2 ad cache_op_r4k_line(va, CACHE_R4K_D|CACHEOP_R4K_HIT_WB_INV);
180 1.2.14.2 ad va += CACHELINESIZE;
181 1.2.14.2 ad }
182 1.2.14.2 ad }
183 1.2.14.2 ad /* $NetBSD: cache.c,v 1.2.14.2 2007/12/03 19:03:07 ad Exp $ */
184 1.2.14.2 ad
185 1.2.14.2 ad /*
186 1.2.14.2 ad * Copyright 2001 Wasabi Systems, Inc.
187 1.2.14.2 ad * All rights reserved.
188 1.2.14.2 ad *
189 1.2.14.2 ad * Written by Jason R. Thorpe for Wasabi Systems, Inc.
190 1.2.14.2 ad *
191 1.2.14.2 ad * Redistribution and use in source and binary forms, with or without
192 1.2.14.2 ad * modification, are permitted provided that the following conditions
193 1.2.14.2 ad * are met:
194 1.2.14.2 ad * 1. Redistributions of source code must retain the above copyright
195 1.2.14.2 ad * notice, this list of conditions and the following disclaimer.
196 1.2.14.2 ad * 2. Redistributions in binary form must reproduce the above copyright
197 1.2.14.2 ad * notice, this list of conditions and the following disclaimer in the
198 1.2.14.2 ad * documentation and/or other materials provided with the distribution.
199 1.2.14.2 ad * 3. All advertising materials mentioning features or use of this software
200 1.2.14.2 ad * must display the following acknowledgement:
201 1.2.14.2 ad * This product includes software developed for the NetBSD Project by
202 1.2.14.2 ad * Wasabi Systems, Inc.
203 1.2.14.2 ad * 4. The name of Wasabi Systems, Inc. may not be used to endorse
204 1.2.14.2 ad * or promote products derived from this software without specific prior
205 1.2.14.2 ad * written permission.
206 1.2.14.2 ad *
207 1.2.14.2 ad * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
208 1.2.14.2 ad * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
209 1.2.14.2 ad * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
210 1.2.14.2 ad * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC
211 1.2.14.2 ad * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
212 1.2.14.2 ad * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
213 1.2.14.2 ad * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
214 1.2.14.2 ad * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
215 1.2.14.2 ad * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
216 1.2.14.2 ad * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
217 1.2.14.2 ad * POSSIBILITY OF SUCH DAMAGE.
218 1.2.14.2 ad */
219 1.2.14.2 ad
220 1.2.14.2 ad #include <lib/libsa/stand.h>
221 1.2.14.2 ad #include <lib/libkern/libkern.h>
222 1.2.14.2 ad
223 1.2.14.2 ad #include <mips/cpuregs.h>
224 1.2.14.2 ad #include <mips/cache_r4k.h>
225 1.2.14.2 ad
226 1.2.14.2 ad #include "boot.h"
227 1.2.14.2 ad
228 1.2.14.2 ad #define round_line(x) (((x) + (CACHELINESIZE - 1)) & ~(CACHELINESIZE - 1))
229 1.2.14.2 ad #define trunc_line(x) ((x) & ~(CACHELINESIZE - 1))
230 1.2.14.2 ad
231 1.2.14.2 ad __asm(".set mips3");
232 1.2.14.2 ad
233 1.2.14.2 ad void
234 1.2.14.2 ad pdcache_inv(uint32_t va, u_int size)
235 1.2.14.2 ad {
236 1.2.14.2 ad uint32_t eva;
237 1.2.14.2 ad
238 1.2.14.2 ad eva = round_line(va + size);
239 1.2.14.2 ad va = trunc_line(va);
240 1.2.14.2 ad
241 1.2.14.2 ad while (va < eva) {
242 1.2.14.2 ad cache_op_r4k_line(va, CACHE_R4K_D|CACHEOP_R4K_HIT_INV);
243 1.2.14.2 ad va += CACHELINESIZE;
244 1.2.14.2 ad }
245 1.2.14.2 ad }
246 1.2.14.2 ad
247 1.2.14.2 ad void
248 1.2.14.2 ad pdcache_wb(uint32_t va, u_int size)
249 1.2.14.2 ad {
250 1.2.14.2 ad uint32_t eva;
251 1.2.14.2 ad
252 1.2.14.2 ad eva = round_line(va + size);
253 1.2.14.2 ad va = trunc_line(va);
254 1.2.14.2 ad
255 1.2.14.2 ad while (va < eva) {
256 1.2.14.2 ad cache_op_r4k_line(va, CACHE_R4K_D|CACHEOP_R4K_HIT_WB);
257 1.2.14.2 ad va += CACHELINESIZE;
258 1.2.14.2 ad }
259 1.2.14.2 ad }
260 1.2.14.2 ad
261 1.2.14.2 ad void
262 1.2.14.2 ad pdcache_wbinv(uint32_t va, u_int size)
263 1.2.14.2 ad {
264 1.2.14.2 ad uint32_t eva;
265 1.2.14.2 ad
266 1.2.14.2 ad eva = round_line(va + size);
267 1.2.14.2 ad va = trunc_line(va);
268 1.2.14.2 ad
269 1.2.14.2 ad while (va < eva) {
270 1.2.14.2 ad cache_op_r4k_line(va, CACHE_R4K_D|CACHEOP_R4K_HIT_WB_INV);
271 1.2.14.2 ad va += CACHELINESIZE;
272 1.2.14.2 ad }
273 1.2.14.2 ad }
274