iommu.c revision 1.2.2.3 1 1.2.2.3 thorpej /* $NetBSD: iommu.c,v 1.2.2.3 1999/08/02 21:43:52 thorpej Exp $ */
2 1.2.2.2 thorpej
3 1.2.2.2 thorpej /*-
4 1.2.2.2 thorpej * Copyright (c) 1998 The NetBSD Foundation, Inc.
5 1.2.2.2 thorpej * All rights reserved.
6 1.2.2.2 thorpej *
7 1.2.2.2 thorpej * This code is derived from software contributed to The NetBSD Foundation
8 1.2.2.2 thorpej * by Paul Kranenburg.
9 1.2.2.2 thorpej *
10 1.2.2.2 thorpej * Redistribution and use in source and binary forms, with or without
11 1.2.2.2 thorpej * modification, are permitted provided that the following conditions
12 1.2.2.2 thorpej * are met:
13 1.2.2.2 thorpej * 1. Redistributions of source code must retain the above copyright
14 1.2.2.2 thorpej * notice, this list of conditions and the following disclaimer.
15 1.2.2.2 thorpej * 2. Redistributions in binary form must reproduce the above copyright
16 1.2.2.2 thorpej * notice, this list of conditions and the following disclaimer in the
17 1.2.2.2 thorpej * documentation and/or other materials provided with the distribution.
18 1.2.2.2 thorpej * 3. All advertising materials mentioning features or use of this software
19 1.2.2.2 thorpej * must display the following acknowledgement:
20 1.2.2.2 thorpej * This product includes software developed by the NetBSD
21 1.2.2.2 thorpej * Foundation, Inc. and its contributors.
22 1.2.2.2 thorpej * 4. Neither the name of The NetBSD Foundation nor the names of its
23 1.2.2.2 thorpej * contributors may be used to endorse or promote products derived
24 1.2.2.2 thorpej * from this software without specific prior written permission.
25 1.2.2.2 thorpej *
26 1.2.2.2 thorpej * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 1.2.2.2 thorpej * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 1.2.2.2 thorpej * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 1.2.2.2 thorpej * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 1.2.2.2 thorpej * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 1.2.2.2 thorpej * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 1.2.2.2 thorpej * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 1.2.2.2 thorpej * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 1.2.2.2 thorpej * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 1.2.2.2 thorpej * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 1.2.2.2 thorpej * POSSIBILITY OF SUCH DAMAGE.
37 1.2.2.2 thorpej */
38 1.2.2.2 thorpej
39 1.2.2.2 thorpej /*
40 1.2.2.2 thorpej * Copyright (c) 1992, 1993
41 1.2.2.2 thorpej * The Regents of the University of California. All rights reserved.
42 1.2.2.2 thorpej *
43 1.2.2.2 thorpej * This software was developed by the Computer Systems Engineering group
44 1.2.2.2 thorpej * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
45 1.2.2.2 thorpej * contributed to Berkeley.
46 1.2.2.2 thorpej *
47 1.2.2.2 thorpej * All advertising materials mentioning features or use of this software
48 1.2.2.2 thorpej * must display the following acknowledgement:
49 1.2.2.2 thorpej * This product includes software developed by the University of
50 1.2.2.2 thorpej * California, Lawrence Berkeley Laboratory.
51 1.2.2.2 thorpej *
52 1.2.2.2 thorpej * Redistribution and use in source and binary forms, with or without
53 1.2.2.2 thorpej * modification, are permitted provided that the following conditions
54 1.2.2.2 thorpej * are met:
55 1.2.2.2 thorpej * 1. Redistributions of source code must retain the above copyright
56 1.2.2.2 thorpej * notice, this list of conditions and the following disclaimer.
57 1.2.2.2 thorpej * 2. Redistributions in binary form must reproduce the above copyright
58 1.2.2.2 thorpej * notice, this list of conditions and the following disclaimer in the
59 1.2.2.2 thorpej * documentation and/or other materials provided with the distribution.
60 1.2.2.2 thorpej * 3. All advertising materials mentioning features or use of this software
61 1.2.2.2 thorpej * must display the following acknowledgement:
62 1.2.2.2 thorpej * This product includes software developed by the University of
63 1.2.2.2 thorpej * California, Berkeley and its contributors.
64 1.2.2.2 thorpej * 4. Neither the name of the University nor the names of its contributors
65 1.2.2.2 thorpej * may be used to endorse or promote products derived from this software
66 1.2.2.2 thorpej * without specific prior written permission.
67 1.2.2.2 thorpej *
68 1.2.2.2 thorpej * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
69 1.2.2.2 thorpej * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
70 1.2.2.2 thorpej * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
71 1.2.2.2 thorpej * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
72 1.2.2.2 thorpej * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
73 1.2.2.2 thorpej * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
74 1.2.2.2 thorpej * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
75 1.2.2.2 thorpej * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
76 1.2.2.2 thorpej * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
77 1.2.2.2 thorpej * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
78 1.2.2.2 thorpej * SUCH DAMAGE.
79 1.2.2.2 thorpej *
80 1.2.2.2 thorpej * from: NetBSD: sbus.c,v 1.13 1999/05/23 07:24:02 mrg Exp
81 1.2.2.2 thorpej * from: @(#)sbus.c 8.1 (Berkeley) 6/11/93
82 1.2.2.2 thorpej */
83 1.2.2.2 thorpej
84 1.2.2.2 thorpej #include <sys/param.h>
85 1.2.2.2 thorpej #include <sys/extent.h>
86 1.2.2.2 thorpej #include <sys/malloc.h>
87 1.2.2.2 thorpej #include <sys/systm.h>
88 1.2.2.2 thorpej #include <sys/device.h>
89 1.2.2.2 thorpej #include <vm/vm.h>
90 1.2.2.2 thorpej
91 1.2.2.2 thorpej #include <machine/bus.h>
92 1.2.2.2 thorpej #include <sparc64/sparc64/vaddrs.h>
93 1.2.2.2 thorpej #include <sparc64/dev/iommureg.h>
94 1.2.2.2 thorpej #include <sparc64/dev/iommuvar.h>
95 1.2.2.2 thorpej
96 1.2.2.2 thorpej #include <machine/autoconf.h>
97 1.2.2.2 thorpej #include <machine/ctlreg.h>
98 1.2.2.2 thorpej #include <machine/cpu.h>
99 1.2.2.2 thorpej
100 1.2.2.2 thorpej #ifdef DEBUG
101 1.2.2.2 thorpej #define IDB_DVMA 0x1
102 1.2.2.2 thorpej #define IDB_INTR 0x2
103 1.2.2.2 thorpej int iommudebug = 0;
104 1.2.2.2 thorpej #endif
105 1.2.2.2 thorpej
106 1.2.2.2 thorpej /*
107 1.2.2.2 thorpej * initialise the UltraSPARC IOMMU (SBUS or PCI):
108 1.2.2.2 thorpej * - allocate and setup the iotsb.
109 1.2.2.2 thorpej * - enable the IOMMU
110 1.2.2.2 thorpej * - initialise the streaming buffers
111 1.2.2.2 thorpej * - create a private DVMA map.
112 1.2.2.2 thorpej *
113 1.2.2.2 thorpej */
114 1.2.2.2 thorpej void
115 1.2.2.2 thorpej iommu_init(name, is, tsbsize)
116 1.2.2.2 thorpej char *name;
117 1.2.2.2 thorpej struct iommu_state *is;
118 1.2.2.2 thorpej int tsbsize;
119 1.2.2.2 thorpej {
120 1.2.2.2 thorpej
121 1.2.2.2 thorpej /*
122 1.2.2.2 thorpej * Setup the iommu.
123 1.2.2.2 thorpej *
124 1.2.2.2 thorpej * The sun4u iommu is part of the SBUS controller so we will
125 1.2.2.2 thorpej * deal with it here. We could try to fake a device node so
126 1.2.2.2 thorpej * we can eventually share it with the PCI bus run by psycho,
127 1.2.2.2 thorpej * but I don't want to get into that sort of cruft.
128 1.2.2.2 thorpej *
129 1.2.2.2 thorpej * First we need to allocate a IOTSB. Problem is that the IOMMU
130 1.2.2.2 thorpej * can only access the IOTSB by physical address, so all the
131 1.2.2.2 thorpej * pages must be contiguous. Luckily, the smallest IOTSB size
132 1.2.2.2 thorpej * is one 8K page.
133 1.2.2.2 thorpej */
134 1.2.2.2 thorpej if (tsbsize != 0)
135 1.2.2.2 thorpej panic("tsbsize != 0; FIX ME"); /* XXX */
136 1.2.2.2 thorpej
137 1.2.2.2 thorpej /* we want 8K pages */
138 1.2.2.2 thorpej is->is_cr = IOMMUCR_8KPG | IOMMUCR_EN;
139 1.2.2.2 thorpej /*
140 1.2.2.2 thorpej *
141 1.2.2.2 thorpej * The IOMMU address space always ends at 0xffffe000, but the starting
142 1.2.2.2 thorpej * address depends on the size of the map. The map size is 1024 * 2 ^
143 1.2.2.2 thorpej * is->is_tsbsize entries, where each entry is 8 bytes. The start of
144 1.2.2.2 thorpej * the map can be calculated by (0xffffe000 << (8 + is->is_tsbsize)).
145 1.2.2.2 thorpej *
146 1.2.2.2 thorpej * Note: the stupid IOMMU ignores the high bits of an address, so a
147 1.2.2.2 thorpej * NULL DMA pointer will be translated by the first page of the IOTSB.
148 1.2.2.2 thorpej * To trap bugs we'll skip the first entry in the IOTSB.
149 1.2.2.2 thorpej */
150 1.2.2.2 thorpej is->is_dvmabase = IOTSB_VSTART(is->is_tsbsize) + NBPG;
151 1.2.2.2 thorpej is->is_tsbsize = tsbsize;
152 1.2.2.2 thorpej is->is_tsb = malloc(NBPG, M_DMAMAP, M_WAITOK); /* XXX */
153 1.2.2.3 thorpej (void) pmap_extract(pmap_kernel(), (vaddr_t)is->is_tsb,
154 1.2.2.3 thorpej (paddr_t *)&is->is_ptsb);
155 1.2.2.2 thorpej
156 1.2.2.2 thorpej #ifdef DEBUG
157 1.2.2.2 thorpej if (iommudebug & IDB_DVMA)
158 1.2.2.2 thorpej {
159 1.2.2.2 thorpej /* Probe the iommu */
160 1.2.2.2 thorpej struct iommureg *regs = is->is_iommu;
161 1.2.2.2 thorpej int64_t cr, tsb;
162 1.2.2.2 thorpej
163 1.2.2.2 thorpej printf("iommu regs at: cr=%lx tsb=%lx flush=%lx\n", ®s->iommu_cr,
164 1.2.2.2 thorpej ®s->iommu_tsb, ®s->iommu_flush);
165 1.2.2.2 thorpej cr = regs->iommu_cr;
166 1.2.2.2 thorpej tsb = regs->iommu_tsb;
167 1.2.2.2 thorpej printf("iommu cr=%lx tsb=%lx\n", (long)cr, (long)tsb);
168 1.2.2.2 thorpej printf("TSB base %p phys %p\n", (long)is->is_tsb, (long)is->is_ptsb);
169 1.2.2.2 thorpej delay(1000000); /* 1 s */
170 1.2.2.2 thorpej }
171 1.2.2.2 thorpej #endif
172 1.2.2.2 thorpej
173 1.2.2.2 thorpej /*
174 1.2.2.2 thorpej * Initialize streaming buffer.
175 1.2.2.2 thorpej */
176 1.2.2.3 thorpej (void) pmap_extract(pmap_kernel(), (vaddr_t)&is->is_flush,
177 1.2.2.3 thorpej (paddr_t *)&is->is_flushpa);
178 1.2.2.2 thorpej
179 1.2.2.2 thorpej /*
180 1.2.2.2 thorpej * now actually start up the IOMMU
181 1.2.2.2 thorpej */
182 1.2.2.2 thorpej iommu_reset(is);
183 1.2.2.2 thorpej
184 1.2.2.2 thorpej /*
185 1.2.2.2 thorpej * Now all the hardware's working we need to allocate a dvma map.
186 1.2.2.2 thorpej */
187 1.2.2.2 thorpej is->is_dvmamap = extent_create(name,
188 1.2.2.2 thorpej is->is_dvmabase, IOTSB_VEND,
189 1.2.2.2 thorpej M_DEVBUF, 0, 0, EX_NOWAIT);
190 1.2.2.2 thorpej }
191 1.2.2.2 thorpej
192 1.2.2.2 thorpej void
193 1.2.2.2 thorpej iommu_reset(is)
194 1.2.2.2 thorpej struct iommu_state *is;
195 1.2.2.2 thorpej {
196 1.2.2.2 thorpej
197 1.2.2.2 thorpej /* Need to do 64-bit stores */
198 1.2.2.2 thorpej bus_space_write_8(is->is_bustag, &is->is_iommu->iommu_cr, 0, is->is_cr);
199 1.2.2.2 thorpej bus_space_write_8(is->is_bustag, &is->is_iommu->iommu_tsb, 0, is->is_ptsb);
200 1.2.2.2 thorpej /* Enable diagnostics mode? */
201 1.2.2.2 thorpej bus_space_write_8(is->is_bustag, &is->is_sb->strbuf_ctl, 0, STRBUF_EN);
202 1.2.2.2 thorpej }
203 1.2.2.2 thorpej
204 1.2.2.2 thorpej /*
205 1.2.2.2 thorpej * Here are the iommu control routines.
206 1.2.2.2 thorpej */
207 1.2.2.2 thorpej void
208 1.2.2.2 thorpej iommu_enter(is, va, pa, flags)
209 1.2.2.2 thorpej struct iommu_state *is;
210 1.2.2.2 thorpej vaddr_t va;
211 1.2.2.2 thorpej int64_t pa;
212 1.2.2.2 thorpej int flags;
213 1.2.2.2 thorpej {
214 1.2.2.2 thorpej int64_t tte;
215 1.2.2.2 thorpej
216 1.2.2.2 thorpej #ifdef DIAGNOSTIC
217 1.2.2.2 thorpej if (va < is->is_dvmabase)
218 1.2.2.2 thorpej panic("sbus_enter: va 0x%lx not in DVMA space",va);
219 1.2.2.2 thorpej #endif
220 1.2.2.2 thorpej
221 1.2.2.2 thorpej tte = MAKEIOTTE(pa, !(flags&BUS_DMA_NOWRITE), !(flags&BUS_DMA_NOCACHE),
222 1.2.2.2 thorpej !(flags&BUS_DMA_COHERENT));
223 1.2.2.2 thorpej
224 1.2.2.2 thorpej /* Is the streamcache flush really needed? */
225 1.2.2.2 thorpej bus_space_write_8(is->is_bustag, &is->is_sb->strbuf_pgflush,
226 1.2.2.2 thorpej 0, va);
227 1.2.2.2 thorpej iommu_flush(is);
228 1.2.2.2 thorpej #ifdef DEBUG
229 1.2.2.2 thorpej if (iommudebug & IDB_DVMA)
230 1.2.2.2 thorpej printf("Clearing TSB slot %d for va %p\n",
231 1.2.2.2 thorpej (int)IOTSBSLOT(va,is->is_tsbsize), va);
232 1.2.2.2 thorpej #endif
233 1.2.2.2 thorpej is->is_tsb[IOTSBSLOT(va,is->is_tsbsize)] = tte;
234 1.2.2.2 thorpej bus_space_write_8(is->is_bustag, &is->is_iommu->iommu_flush,
235 1.2.2.2 thorpej 0, va);
236 1.2.2.2 thorpej #ifdef DEBUG
237 1.2.2.2 thorpej if (iommudebug & IDB_DVMA)
238 1.2.2.2 thorpej printf("sbus_enter: va %lx pa %lx TSB[%lx]@%p=%lx\n",
239 1.2.2.2 thorpej va, (long)pa, IOTSBSLOT(va,is->is_tsbsize),
240 1.2.2.2 thorpej &is->is_tsb[IOTSBSLOT(va,is->is_tsbsize)],
241 1.2.2.2 thorpej (long)tte);
242 1.2.2.2 thorpej #endif
243 1.2.2.2 thorpej }
244 1.2.2.2 thorpej
245 1.2.2.2 thorpej /*
246 1.2.2.2 thorpej * iommu_remove: removes mappings created by iommu_enter
247 1.2.2.2 thorpej *
248 1.2.2.2 thorpej * Only demap from IOMMU if flag is set.
249 1.2.2.2 thorpej */
250 1.2.2.2 thorpej void
251 1.2.2.2 thorpej iommu_remove(is, va, len)
252 1.2.2.2 thorpej struct iommu_state *is;
253 1.2.2.2 thorpej vaddr_t va;
254 1.2.2.2 thorpej size_t len;
255 1.2.2.2 thorpej {
256 1.2.2.2 thorpej
257 1.2.2.2 thorpej #ifdef DIAGNOSTIC
258 1.2.2.2 thorpej if (va < is->is_dvmabase)
259 1.2.2.2 thorpej panic("sbus_remove: va 0x%lx not in DVMA space", (long)va);
260 1.2.2.2 thorpej if ((long)(va + len) < (long)va)
261 1.2.2.2 thorpej panic("sbus_remove: va 0x%lx + len 0x%lx wraps",
262 1.2.2.2 thorpej (long) va, (long) len);
263 1.2.2.2 thorpej if (len & ~0xfffffff)
264 1.2.2.2 thorpej panic("sbus_remove: rediculous len 0x%lx", (long)len);
265 1.2.2.2 thorpej #endif
266 1.2.2.2 thorpej
267 1.2.2.2 thorpej va = trunc_page(va);
268 1.2.2.2 thorpej while (len > 0) {
269 1.2.2.2 thorpej
270 1.2.2.2 thorpej /*
271 1.2.2.2 thorpej * Streaming buffer flushes:
272 1.2.2.2 thorpej *
273 1.2.2.2 thorpej * 1 Tell strbuf to flush by storing va to strbuf_pgflush
274 1.2.2.2 thorpej * If we're not on a cache line boundary (64-bits):
275 1.2.2.2 thorpej * 2 Store 0 in flag
276 1.2.2.2 thorpej * 3 Store pointer to flag in flushsync
277 1.2.2.2 thorpej * 4 wait till flushsync becomes 0x1
278 1.2.2.2 thorpej *
279 1.2.2.2 thorpej * If it takes more than .5 sec, something went wrong.
280 1.2.2.2 thorpej */
281 1.2.2.2 thorpej #ifdef DEBUG
282 1.2.2.2 thorpej if (iommudebug & IDB_DVMA)
283 1.2.2.2 thorpej printf("sbus_remove: flushing va %p TSB[%lx]@%p=%lx, %lu bytes left\n",
284 1.2.2.2 thorpej (long)va, (long)IOTSBSLOT(va,is->is_tsbsize),
285 1.2.2.2 thorpej (long)&is->is_tsb[IOTSBSLOT(va,is->is_tsbsize)],
286 1.2.2.2 thorpej (long)(is->is_tsb[IOTSBSLOT(va,is->is_tsbsize)]),
287 1.2.2.2 thorpej (u_long)len);
288 1.2.2.2 thorpej #endif
289 1.2.2.2 thorpej bus_space_write_8(is->is_bustag, &is->is_sb->strbuf_pgflush, 0, va);
290 1.2.2.2 thorpej if (len <= NBPG) {
291 1.2.2.2 thorpej iommu_flush(is);
292 1.2.2.2 thorpej len = 0;
293 1.2.2.2 thorpej } else len -= NBPG;
294 1.2.2.2 thorpej #ifdef DEBUG
295 1.2.2.2 thorpej if (iommudebug & IDB_DVMA)
296 1.2.2.2 thorpej printf("sbus_remove: flushed va %p TSB[%lx]@%p=%lx, %lu bytes left\n",
297 1.2.2.2 thorpej (long)va, (long)IOTSBSLOT(va,is->is_tsbsize),
298 1.2.2.2 thorpej (long)&is->is_tsb[IOTSBSLOT(va,is->is_tsbsize)],
299 1.2.2.2 thorpej (long)(is->is_tsb[IOTSBSLOT(va,is->is_tsbsize)]),
300 1.2.2.2 thorpej (u_long)len);
301 1.2.2.2 thorpej #endif
302 1.2.2.2 thorpej is->is_tsb[IOTSBSLOT(va,is->is_tsbsize)] = 0;
303 1.2.2.2 thorpej bus_space_write_8(is->is_bustag, &is->is_iommu->iommu_flush, 0, va);
304 1.2.2.2 thorpej va += NBPG;
305 1.2.2.2 thorpej }
306 1.2.2.2 thorpej }
307 1.2.2.2 thorpej
308 1.2.2.2 thorpej int
309 1.2.2.2 thorpej iommu_flush(is)
310 1.2.2.2 thorpej struct iommu_state *is;
311 1.2.2.2 thorpej {
312 1.2.2.2 thorpej struct timeval cur, flushtimeout;
313 1.2.2.2 thorpej
314 1.2.2.2 thorpej #define BUMPTIME(t, usec) { \
315 1.2.2.2 thorpej register volatile struct timeval *tp = (t); \
316 1.2.2.2 thorpej register long us; \
317 1.2.2.2 thorpej \
318 1.2.2.2 thorpej tp->tv_usec = us = tp->tv_usec + (usec); \
319 1.2.2.2 thorpej if (us >= 1000000) { \
320 1.2.2.2 thorpej tp->tv_usec = us - 1000000; \
321 1.2.2.2 thorpej tp->tv_sec++; \
322 1.2.2.2 thorpej } \
323 1.2.2.2 thorpej }
324 1.2.2.2 thorpej
325 1.2.2.2 thorpej is->is_flush = 0;
326 1.2.2.2 thorpej membar_sync();
327 1.2.2.2 thorpej bus_space_write_8(is->is_bustag, &is->is_sb->strbuf_flushsync, 0, is->is_flushpa);
328 1.2.2.2 thorpej membar_sync();
329 1.2.2.2 thorpej
330 1.2.2.2 thorpej microtime(&flushtimeout);
331 1.2.2.2 thorpej cur = flushtimeout;
332 1.2.2.2 thorpej BUMPTIME(&flushtimeout, 500000); /* 1/2 sec */
333 1.2.2.2 thorpej
334 1.2.2.2 thorpej #ifdef DEBUG
335 1.2.2.2 thorpej if (iommudebug & IDB_DVMA)
336 1.2.2.2 thorpej printf("sbus_flush: flush = %lx at va = %lx pa = %lx now=%lx:%lx until = %lx:%lx\n",
337 1.2.2.2 thorpej (long)is->is_flush, (long)&is->is_flush,
338 1.2.2.2 thorpej (long)is->is_flushpa, cur.tv_sec, cur.tv_usec,
339 1.2.2.2 thorpej flushtimeout.tv_sec, flushtimeout.tv_usec);
340 1.2.2.2 thorpej #endif
341 1.2.2.2 thorpej /* Bypass non-coherent D$ */
342 1.2.2.2 thorpej while (!ldxa(is->is_flushpa, ASI_PHYS_CACHED) &&
343 1.2.2.2 thorpej ((cur.tv_sec <= flushtimeout.tv_sec) &&
344 1.2.2.2 thorpej (cur.tv_usec <= flushtimeout.tv_usec)))
345 1.2.2.2 thorpej microtime(&cur);
346 1.2.2.2 thorpej
347 1.2.2.2 thorpej #ifdef DIAGNOSTIC
348 1.2.2.2 thorpej if (!is->is_flush) {
349 1.2.2.2 thorpej printf("sbus_flush: flush timeout %p at %p\n", (long)is->is_flush,
350 1.2.2.2 thorpej (long)is->is_flushpa); /* panic? */
351 1.2.2.2 thorpej #ifdef DDB
352 1.2.2.2 thorpej Debugger();
353 1.2.2.2 thorpej #endif
354 1.2.2.2 thorpej }
355 1.2.2.2 thorpej #endif
356 1.2.2.2 thorpej #ifdef DEBUG
357 1.2.2.2 thorpej if (iommudebug & IDB_DVMA)
358 1.2.2.2 thorpej printf("sbus_flush: flushed\n");
359 1.2.2.2 thorpej #endif
360 1.2.2.2 thorpej return (is->is_flush);
361 1.2.2.2 thorpej }
362