isv.c revision 1.1 1 1.1 dyoung /* $NetBSD: isv.c,v 1.1 2008/04/02 01:34:36 dyoung Exp $ */
2 1.1 dyoung
3 1.1 dyoung /*-
4 1.1 dyoung * Copyright (c) 2008 The NetBSD Foundation, Inc.
5 1.1 dyoung * All rights reserved.
6 1.1 dyoung *
7 1.1 dyoung * This code is derived from software contributed to The NetBSD Foundation
8 1.1 dyoung * by David Young.
9 1.1 dyoung *
10 1.1 dyoung * Redistribution and use in source and binary forms, with or without
11 1.1 dyoung * modification, are permitted provided that the following conditions
12 1.1 dyoung * are met:
13 1.1 dyoung * 1. Redistributions of source code must retain the above copyright
14 1.1 dyoung * notice, this list of conditions and the following disclaimer.
15 1.1 dyoung * 2. Redistributions in binary form must reproduce the above copyright
16 1.1 dyoung * notice, this list of conditions and the following disclaimer in the
17 1.1 dyoung * documentation and/or other materials provided with the distribution.
18 1.1 dyoung * 3. All advertising materials mentioning features or use of this software
19 1.1 dyoung * must display the following acknowledgement:
20 1.1 dyoung * This product includes software developed by the NetBSD
21 1.1 dyoung * Foundation, Inc. and its contributors.
22 1.1 dyoung * 4. Neither the name of The NetBSD Foundation nor the names of its
23 1.1 dyoung * contributors may be used to endorse or promote products derived
24 1.1 dyoung * from this software without specific prior written permission.
25 1.1 dyoung *
26 1.1 dyoung * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 1.1 dyoung * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 1.1 dyoung * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 1.1 dyoung * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 1.1 dyoung * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 1.1 dyoung * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 1.1 dyoung * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 1.1 dyoung * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 1.1 dyoung * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 1.1 dyoung * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 1.1 dyoung * POSSIBILITY OF SUCH DAMAGE.
37 1.1 dyoung */
38 1.1 dyoung
39 1.1 dyoung #include <sys/cdefs.h>
40 1.1 dyoung __KERNEL_RCSID(0, "$NetBSD: isv.c,v 1.1 2008/04/02 01:34:36 dyoung Exp $");
41 1.1 dyoung
42 1.1 dyoung #include <sys/param.h>
43 1.1 dyoung #include <sys/systm.h>
44 1.1 dyoung #include <sys/kernel.h>
45 1.1 dyoung #include <sys/device.h>
46 1.1 dyoung #include <sys/conf.h>
47 1.1 dyoung #include <uvm/uvm.h>
48 1.1 dyoung
49 1.1 dyoung #include <sys/bus.h>
50 1.1 dyoung
51 1.1 dyoung #include <dev/isa/isareg.h>
52 1.1 dyoung #include <dev/isa/isavar.h>
53 1.1 dyoung
54 1.1 dyoung #include <dev/isa/isvio.h>
55 1.1 dyoung
56 1.1 dyoung #define ISV_CONTROL 0x0 /* control: write-only */
57 1.1 dyoung #define ISV_CONTROL_MODE_MASK __BIT(0)
58 1.1 dyoung #define ISV_CONTROL_MODE_CAPTURE __SHIFTIN(0, ISV_CONTROL_MODE_MASK)
59 1.1 dyoung #define ISV_CONTROL_MODE_READ __SHIFTIN(1, ISV_CONTROL_MODE_MASK)
60 1.1 dyoung #define ISV_CONTROL_COUNTER_MASK __BIT(1)
61 1.1 dyoung #define ISV_CONTROL_COUNTER_RESET __SHIFTIN(1, ISV_CONTROL_COUNTER_MASK)
62 1.1 dyoung #define ISV_CONTROL_COUNTER_AUTOINC __SHIFTIN(0, ISV_CONTROL_COUNTER_MASK)
63 1.1 dyoung
64 1.1 dyoung #define ISV_DATA ISV_CONTROL /* data: read-only */
65 1.1 dyoung
66 1.1 dyoung #define ISV_STATUS 0x2 /* status: read-only */
67 1.1 dyoung #define ISV_STATUS_VIDEO_MASK __BIT(15)
68 1.1 dyoung #define ISV_STATUS_VIDEO_RETRACE __SHIFTIN(0, ISV_STATUS_VIDEO_MASK)
69 1.1 dyoung #define ISV_STATUS_VIDEO_WRITE __SHIFTIN(1, ISV_STATUS_VIDEO_MASK)
70 1.1 dyoung
71 1.1 dyoung struct isv_regs {
72 1.1 dyoung bus_space_tag_t ir_bt;
73 1.1 dyoung bus_space_handle_t ir_bh;
74 1.1 dyoung };
75 1.1 dyoung
76 1.1 dyoung enum isv_state {
77 1.1 dyoung ISV_S_CAPTURE0 = 0
78 1.1 dyoung , ISV_S_CAPTURE1 = 1
79 1.1 dyoung , ISV_S_CAPTURE2 = 2
80 1.1 dyoung , ISV_S_RETRACE = 3
81 1.1 dyoung };
82 1.1 dyoung
83 1.1 dyoung struct isv_softc {
84 1.1 dyoung struct isv_regs sc_ir;
85 1.1 dyoung device_t sc_dev;
86 1.1 dyoung uint16_t *sc_frame;
87 1.1 dyoung int sc_speed;
88 1.1 dyoung };
89 1.1 dyoung
90 1.1 dyoung extern struct cfdriver isv_cd;
91 1.1 dyoung
92 1.1 dyoung static dev_type_ioctl(isv_ioctl);
93 1.1 dyoung static dev_type_open(isv_open);
94 1.1 dyoung static dev_type_mmap(isv_mmap);
95 1.1 dyoung
96 1.1 dyoung static int isv_capture(struct isv_softc *);
97 1.1 dyoung static int isv_match(device_t, cfdata_t, void *);
98 1.1 dyoung static void isv_attach(device_t, device_t, void *);
99 1.1 dyoung static int isv_detach(device_t, int);
100 1.1 dyoung static uint16_t isv_read(struct isv_regs *, bus_size_t);
101 1.1 dyoung static void isv_write(struct isv_regs *, bus_size_t, uint16_t);
102 1.1 dyoung static bool isv_retrace(struct isv_regs *);
103 1.1 dyoung static int isv_retrace_wait(struct isv_regs *, int *,
104 1.1 dyoung const struct timeval *);
105 1.1 dyoung static int isv_capture_wait(struct isv_regs *, int *,
106 1.1 dyoung const struct timeval *);
107 1.1 dyoung static bool isv_delta(int *, bool);
108 1.1 dyoung static int isv_probe(struct isv_regs *);
109 1.1 dyoung
110 1.1 dyoung CFATTACH_DECL_NEW(isv_isa, sizeof(struct isv_softc),
111 1.1 dyoung isv_match, isv_attach, isv_detach, NULL);
112 1.1 dyoung
113 1.1 dyoung const struct cdevsw isv_cdevsw = {
114 1.1 dyoung isv_open, nullclose, noread, nowrite, isv_ioctl,
115 1.1 dyoung nostop, notty, nopoll, isv_mmap, nokqfilter, D_OTHER
116 1.1 dyoung };
117 1.1 dyoung
118 1.1 dyoung static uint16_t
119 1.1 dyoung isv_read(struct isv_regs *ir, bus_size_t reg)
120 1.1 dyoung {
121 1.1 dyoung return bus_space_read_2(ir->ir_bt, ir->ir_bh, reg);
122 1.1 dyoung }
123 1.1 dyoung
124 1.1 dyoung static void
125 1.1 dyoung isv_write(struct isv_regs *ir, bus_size_t reg, uint16_t val)
126 1.1 dyoung {
127 1.1 dyoung bus_space_write_2(ir->ir_bt, ir->ir_bh, reg, val);
128 1.1 dyoung }
129 1.1 dyoung
130 1.1 dyoung static bool
131 1.1 dyoung isv_retrace(struct isv_regs *ir)
132 1.1 dyoung {
133 1.1 dyoung uint16_t video;
134 1.1 dyoung
135 1.1 dyoung video = isv_read(ir, ISV_STATUS) & ISV_STATUS_VIDEO_MASK;
136 1.1 dyoung return video == ISV_STATUS_VIDEO_RETRACE;
137 1.1 dyoung }
138 1.1 dyoung
139 1.1 dyoung #define state_and_input(__state, __retrace) \
140 1.1 dyoung (((__state) << 1) | ((__retrace) ? 1 : 0))
141 1.1 dyoung
142 1.1 dyoung static bool
143 1.1 dyoung isv_delta(int *state, bool retrace)
144 1.1 dyoung {
145 1.1 dyoung bool transition = false;
146 1.1 dyoung
147 1.1 dyoung switch (state_and_input(*state, retrace)) {
148 1.1 dyoung case state_and_input(ISV_S_CAPTURE0, false):
149 1.1 dyoung case state_and_input(ISV_S_RETRACE, true):
150 1.1 dyoung break;
151 1.1 dyoung case state_and_input(ISV_S_CAPTURE2, true):
152 1.1 dyoung transition = true;
153 1.1 dyoung /*FALLTHROUGH*/
154 1.1 dyoung case state_and_input(ISV_S_CAPTURE1, true):
155 1.1 dyoung case state_and_input(ISV_S_CAPTURE0, true):
156 1.1 dyoung (*state)++;
157 1.1 dyoung break;
158 1.1 dyoung case state_and_input(ISV_S_RETRACE, false):
159 1.1 dyoung transition = true;
160 1.1 dyoung /*FALLTHROUGH*/
161 1.1 dyoung case state_and_input(ISV_S_CAPTURE2, false):
162 1.1 dyoung case state_and_input(ISV_S_CAPTURE1, false):
163 1.1 dyoung *state = ISV_S_CAPTURE0;
164 1.1 dyoung break;
165 1.1 dyoung }
166 1.1 dyoung return transition;
167 1.1 dyoung }
168 1.1 dyoung
169 1.1 dyoung static int
170 1.1 dyoung isv_probe(struct isv_regs *ir)
171 1.1 dyoung {
172 1.1 dyoung int state, transitions;
173 1.1 dyoung struct timeval end, now,
174 1.1 dyoung wait = {.tv_sec = 0, .tv_usec = 1000000 * 4 / 30};
175 1.1 dyoung
176 1.1 dyoung aprint_debug("%s: resetting\n", __func__);
177 1.1 dyoung isv_write(ir, ISV_CONTROL,
178 1.1 dyoung ISV_CONTROL_MODE_CAPTURE|ISV_CONTROL_COUNTER_AUTOINC);
179 1.1 dyoung
180 1.1 dyoung aprint_debug("%s: waiting\n", __func__);
181 1.1 dyoung
182 1.1 dyoung microtime(&now);
183 1.1 dyoung timeradd(&now, &wait, &end);
184 1.1 dyoung
185 1.1 dyoung state = transitions = 0;
186 1.1 dyoung
187 1.1 dyoung do {
188 1.1 dyoung if (isv_delta(&state, isv_retrace(ir)))
189 1.1 dyoung transitions++;
190 1.1 dyoung
191 1.1 dyoung if (state == ISV_S_CAPTURE0 || state == ISV_S_RETRACE)
192 1.1 dyoung microtime(&now);
193 1.1 dyoung } while (timercmp(&now, &end, <));
194 1.1 dyoung
195 1.1 dyoung aprint_debug("%s: %d transitions\n", __func__, transitions);
196 1.1 dyoung
197 1.1 dyoung return transitions >= 4 && transitions <= 10;
198 1.1 dyoung }
199 1.1 dyoung
200 1.1 dyoung static int
201 1.1 dyoung isv_match(device_t parent, cfdata_t match, void *aux)
202 1.1 dyoung {
203 1.1 dyoung struct isv_regs ir;
204 1.1 dyoung struct isa_attach_args *ia = aux;
205 1.1 dyoung int rv;
206 1.1 dyoung
207 1.1 dyoung /* Must supply an address */
208 1.1 dyoung if (ia->ia_nio < 1 || ia->ia_io[0].ir_addr == ISA_UNKNOWN_PORT)
209 1.1 dyoung return 0;
210 1.1 dyoung
211 1.1 dyoung ir.ir_bt = ia->ia_iot;
212 1.1 dyoung
213 1.1 dyoung if (bus_space_map(ir.ir_bt, ia->ia_io[0].ir_addr, 8, 0, &ir.ir_bh))
214 1.1 dyoung return 0;
215 1.1 dyoung
216 1.1 dyoung rv = isv_probe(&ir);
217 1.1 dyoung
218 1.1 dyoung bus_space_unmap(ir.ir_bt, ir.ir_bh, 8);
219 1.1 dyoung
220 1.1 dyoung if (rv) {
221 1.1 dyoung ia->ia_nio = 1;
222 1.1 dyoung ia->ia_io[0].ir_size = 8;
223 1.1 dyoung
224 1.1 dyoung ia->ia_niomem = 0;
225 1.1 dyoung ia->ia_nirq = 0;
226 1.1 dyoung ia->ia_ndrq = 0;
227 1.1 dyoung }
228 1.1 dyoung
229 1.1 dyoung return rv;
230 1.1 dyoung }
231 1.1 dyoung
232 1.1 dyoung
233 1.1 dyoung static void
234 1.1 dyoung isv_attach(device_t parent, device_t self, void *aux)
235 1.1 dyoung {
236 1.1 dyoung struct isv_softc *sc = device_private(self);
237 1.1 dyoung struct isv_regs *ir = &sc->sc_ir;
238 1.1 dyoung struct isa_attach_args *ia = aux;
239 1.1 dyoung
240 1.1 dyoung ir->ir_bt = ia->ia_iot;
241 1.1 dyoung
242 1.1 dyoung if (bus_space_map(ir->ir_bt, ia->ia_io[0].ir_addr, 8, 0, &ir->ir_bh)) {
243 1.1 dyoung aprint_error(": can't map i/o space\n");
244 1.1 dyoung return;
245 1.1 dyoung }
246 1.1 dyoung
247 1.1 dyoung /* Bus-independent attachment */
248 1.1 dyoung sc->sc_dev = self;
249 1.1 dyoung
250 1.1 dyoung aprint_normal(": IDEC Supervision/16\n");
251 1.1 dyoung
252 1.1 dyoung /* TBD */
253 1.1 dyoung }
254 1.1 dyoung
255 1.1 dyoung int
256 1.1 dyoung isv_open(dev_t dev, int flag, int devtype, lwp_t *l)
257 1.1 dyoung {
258 1.1 dyoung vaddr_t va;
259 1.1 dyoung struct isv_softc *sc = device_lookup_private(&isv_cd, minor(dev));
260 1.1 dyoung
261 1.1 dyoung if (sc == NULL)
262 1.1 dyoung return ENXIO;
263 1.1 dyoung
264 1.1 dyoung if (sc->sc_frame != NULL)
265 1.1 dyoung return 0;
266 1.1 dyoung
267 1.1 dyoung if ((va = uvm_km_alloc(kernel_map, ISV_WIDTH * ISV_LINES, PAGE_SIZE,
268 1.1 dyoung UVM_KMF_WIRED|UVM_KMF_ZERO|UVM_KMF_CANFAIL|UVM_KMF_WAITVA)) == 0)
269 1.1 dyoung return ENOMEM;
270 1.1 dyoung
271 1.1 dyoung sc->sc_frame = (uint16_t *)(void *)va;
272 1.1 dyoung return 0;
273 1.1 dyoung }
274 1.1 dyoung
275 1.1 dyoung /* wait for retrace */
276 1.1 dyoung static int
277 1.1 dyoung isv_retrace_wait(struct isv_regs *ir, int *state, const struct timeval *end)
278 1.1 dyoung {
279 1.1 dyoung struct timeval now;
280 1.1 dyoung
281 1.1 dyoung for (;;) {
282 1.1 dyoung if (!isv_delta(state, isv_retrace(ir))) {
283 1.1 dyoung microtime(&now);
284 1.1 dyoung continue;
285 1.1 dyoung }
286 1.1 dyoung if (*state == ISV_S_RETRACE)
287 1.1 dyoung break;
288 1.1 dyoung if (*state != ISV_S_CAPTURE0)
289 1.1 dyoung continue;
290 1.1 dyoung
291 1.1 dyoung microtime(&now);
292 1.1 dyoung if (timercmp(&now, end, >=))
293 1.1 dyoung return EIO;
294 1.1 dyoung }
295 1.1 dyoung return 0;
296 1.1 dyoung }
297 1.1 dyoung
298 1.1 dyoung /* wait for capture mode */
299 1.1 dyoung static int
300 1.1 dyoung isv_capture_wait(struct isv_regs *ir, int *state, const struct timeval *end)
301 1.1 dyoung {
302 1.1 dyoung struct timeval now;
303 1.1 dyoung
304 1.1 dyoung for (;;) {
305 1.1 dyoung if (!isv_delta(state, isv_retrace(ir))) {
306 1.1 dyoung microtime(&now);
307 1.1 dyoung continue;
308 1.1 dyoung }
309 1.1 dyoung if (*state != ISV_S_RETRACE)
310 1.1 dyoung break;
311 1.1 dyoung
312 1.1 dyoung microtime(&now);
313 1.1 dyoung if (timercmp(&now, end, >=))
314 1.1 dyoung return EIO;
315 1.1 dyoung }
316 1.1 dyoung return 0;
317 1.1 dyoung }
318 1.1 dyoung
319 1.1 dyoung
320 1.1 dyoung static int
321 1.1 dyoung isv_capture(struct isv_softc *sc)
322 1.1 dyoung {
323 1.1 dyoung int speed;
324 1.1 dyoung uint16_t discard;
325 1.1 dyoung int rc, state = ISV_S_CAPTURE0;
326 1.1 dyoung struct timeval diff, end, start, stop;
327 1.1 dyoung static const struct timeval wait = {.tv_sec = 0, .tv_usec = 200000};
328 1.1 dyoung struct isv_regs *ir = &sc->sc_ir;
329 1.1 dyoung
330 1.1 dyoung if (sc->sc_frame == NULL)
331 1.1 dyoung return EAGAIN;
332 1.1 dyoung
333 1.1 dyoung microtime(&start);
334 1.1 dyoung
335 1.1 dyoung timeradd(&start, &wait, &end);
336 1.1 dyoung
337 1.1 dyoung speed = sc->sc_speed;
338 1.1 dyoung sc->sc_speed = 0;
339 1.1 dyoung
340 1.1 dyoung if (speed < 1 && (rc = isv_retrace_wait(ir, &state, &end)) != 0)
341 1.1 dyoung return rc;
342 1.1 dyoung
343 1.1 dyoung if (speed < 2 && (rc = isv_capture_wait(ir, &state, &end)) != 0)
344 1.1 dyoung return rc;
345 1.1 dyoung
346 1.1 dyoung if ((rc = isv_retrace_wait(ir, &state, &end)) != 0)
347 1.1 dyoung return rc;
348 1.1 dyoung
349 1.1 dyoung microtime(&stop);
350 1.1 dyoung
351 1.1 dyoung timersub(&stop, &start, &diff);
352 1.1 dyoung
353 1.1 dyoung aprint_debug_dev(sc->sc_dev, "%ssync in %ld.%06ld seconds\n",
354 1.1 dyoung (speed < 1) ? "" : ((speed < 2) ? "faster " : "fastest "),
355 1.1 dyoung diff.tv_sec, diff.tv_usec);
356 1.1 dyoung
357 1.1 dyoung microtime(&start);
358 1.1 dyoung
359 1.1 dyoung /* enter read mode, then toggle counter mode,
360 1.1 dyoung * autoinc -> reset -> autoinc, so that we start reading
361 1.1 dyoung * at the top of the frame.
362 1.1 dyoung */
363 1.1 dyoung isv_write(ir, ISV_CONTROL,
364 1.1 dyoung ISV_CONTROL_MODE_READ|ISV_CONTROL_COUNTER_AUTOINC);
365 1.1 dyoung isv_write(ir, ISV_CONTROL,
366 1.1 dyoung ISV_CONTROL_MODE_READ|ISV_CONTROL_COUNTER_RESET);
367 1.1 dyoung isv_write(ir, ISV_CONTROL,
368 1.1 dyoung ISV_CONTROL_MODE_READ|ISV_CONTROL_COUNTER_AUTOINC);
369 1.1 dyoung /* read one dummy word to prime the state machine on the
370 1.1 dyoung * image capture board
371 1.1 dyoung */
372 1.1 dyoung discard = isv_read(ir, ISV_DATA);
373 1.1 dyoung bus_space_read_multi_stream_2(ir->ir_bt, ir->ir_bh, ISV_DATA,
374 1.1 dyoung sc->sc_frame, ISV_WIDTH * ISV_LINES / 2);
375 1.1 dyoung
376 1.1 dyoung /* restore to initial conditions */
377 1.1 dyoung isv_write(ir, ISV_CONTROL,
378 1.1 dyoung ISV_CONTROL_MODE_CAPTURE|ISV_CONTROL_COUNTER_AUTOINC);
379 1.1 dyoung
380 1.1 dyoung microtime(&stop);
381 1.1 dyoung
382 1.1 dyoung timersub(&stop, &start, &diff);
383 1.1 dyoung
384 1.1 dyoung aprint_debug_dev(sc->sc_dev, "read in %ld.%06ld seconds\n",
385 1.1 dyoung diff.tv_sec, diff.tv_usec);
386 1.1 dyoung
387 1.1 dyoung state = 0;
388 1.1 dyoung
389 1.1 dyoung if (isv_retrace_wait(ir, &state, &end) != 0)
390 1.1 dyoung return 0;
391 1.1 dyoung sc->sc_speed++;
392 1.1 dyoung
393 1.1 dyoung if (isv_capture_wait(ir, &state, &end) != 0)
394 1.1 dyoung return 0;
395 1.1 dyoung sc->sc_speed++;
396 1.1 dyoung
397 1.1 dyoung return 0;
398 1.1 dyoung }
399 1.1 dyoung
400 1.1 dyoung int
401 1.1 dyoung isv_ioctl(dev_t dev, u_long cmd, void *data, int flag, lwp_t *l)
402 1.1 dyoung {
403 1.1 dyoung struct isv_cmd ic;
404 1.1 dyoung struct isv_softc *sc = device_lookup_private(&isv_cd, minor(dev));
405 1.1 dyoung
406 1.1 dyoung if (cmd != ISV_CMD)
407 1.1 dyoung return ENOTTY;
408 1.1 dyoung
409 1.1 dyoung memcpy(&ic, data, sizeof(ic));
410 1.1 dyoung
411 1.1 dyoung if (ic.c_cmd != ISV_CMD_READ)
412 1.1 dyoung return EINVAL;
413 1.1 dyoung
414 1.1 dyoung ic.c_frameno = 0;
415 1.1 dyoung
416 1.1 dyoung return isv_capture(sc);
417 1.1 dyoung }
418 1.1 dyoung
419 1.1 dyoung paddr_t
420 1.1 dyoung isv_mmap(dev_t dev, off_t offset, int prot)
421 1.1 dyoung {
422 1.1 dyoung struct isv_softc *sc = device_lookup_private(&isv_cd, minor(dev));
423 1.1 dyoung paddr_t pa;
424 1.1 dyoung
425 1.1 dyoung if ((prot & ~(VM_PROT_READ)) != 0)
426 1.1 dyoung return -1;
427 1.1 dyoung
428 1.1 dyoung if (sc->sc_frame == NULL)
429 1.1 dyoung return -1;
430 1.1 dyoung
431 1.1 dyoung if (offset >= ISV_WIDTH * ISV_LINES)
432 1.1 dyoung return -1;
433 1.1 dyoung
434 1.1 dyoung if (!pmap_extract(pmap_kernel(), (vaddr_t)&sc->sc_frame[offset/2], &pa))
435 1.1 dyoung return -1;
436 1.1 dyoung
437 1.1 dyoung return atop(pa);
438 1.1 dyoung }
439 1.1 dyoung
440 1.1 dyoung static int
441 1.1 dyoung isv_detach(device_t self, int flags)
442 1.1 dyoung {
443 1.1 dyoung struct isv_softc *sc = device_private(self);
444 1.1 dyoung struct isv_regs *ir = &sc->sc_ir;
445 1.1 dyoung
446 1.1 dyoung if (sc->sc_frame != NULL) {
447 1.1 dyoung uvm_km_free(kernel_map, (vaddr_t)sc->sc_frame,
448 1.1 dyoung ISV_WIDTH * ISV_LINES, UVM_KMF_WIRED);
449 1.1 dyoung }
450 1.1 dyoung bus_space_unmap(ir->ir_bt, ir->ir_bh, 8);
451 1.1 dyoung return 0;
452 1.1 dyoung }
453