bpp.c revision 1.8.6.2 1 1.8.6.2 fvdl /* $NetBSD: bpp.c,v 1.8.6.2 2001/10/10 11:57:00 fvdl Exp $ */
2 1.7 eeh
3 1.1 pk /*-
4 1.1 pk * Copyright (c) 1998 The NetBSD Foundation, Inc.
5 1.1 pk * All rights reserved.
6 1.1 pk *
7 1.1 pk * This code is derived from software contributed to The NetBSD Foundation
8 1.1 pk * by Paul Kranenburg.
9 1.1 pk *
10 1.1 pk * Redistribution and use in source and binary forms, with or without
11 1.1 pk * modification, are permitted provided that the following conditions
12 1.1 pk * are met:
13 1.1 pk * 1. Redistributions of source code must retain the above copyright
14 1.1 pk * notice, this list of conditions and the following disclaimer.
15 1.1 pk * 2. Redistributions in binary form must reproduce the above copyright
16 1.1 pk * notice, this list of conditions and the following disclaimer in the
17 1.1 pk * documentation and/or other materials provided with the distribution.
18 1.1 pk * 3. All advertising materials mentioning features or use of this software
19 1.1 pk * must display the following acknowledgement:
20 1.1 pk * This product includes software developed by the NetBSD
21 1.1 pk * Foundation, Inc. and its contributors.
22 1.1 pk * 4. Neither the name of The NetBSD Foundation nor the names of its
23 1.1 pk * contributors may be used to endorse or promote products derived
24 1.1 pk * from this software without specific prior written permission.
25 1.1 pk *
26 1.1 pk * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 1.1 pk * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 1.1 pk * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 1.1 pk * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 1.1 pk * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 1.1 pk * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 1.1 pk * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 1.1 pk * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 1.1 pk * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 1.1 pk * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 1.1 pk * POSSIBILITY OF SUCH DAMAGE.
37 1.1 pk */
38 1.1 pk
39 1.1 pk #include <sys/param.h>
40 1.1 pk #include <sys/ioctl.h>
41 1.1 pk #include <sys/fcntl.h>
42 1.1 pk #include <sys/systm.h>
43 1.1 pk #include <sys/kernel.h>
44 1.1 pk #include <sys/vnode.h>
45 1.1 pk #include <sys/poll.h>
46 1.1 pk #include <sys/select.h>
47 1.1 pk #include <sys/malloc.h>
48 1.1 pk #include <sys/proc.h>
49 1.1 pk #include <sys/signalvar.h>
50 1.1 pk #include <sys/conf.h>
51 1.1 pk #include <sys/errno.h>
52 1.1 pk #include <sys/device.h>
53 1.8.6.2 fvdl #include <sys/vnode.h>
54 1.1 pk
55 1.1 pk #include <machine/bus.h>
56 1.5 pk #include <machine/intr.h>
57 1.1 pk #include <machine/autoconf.h>
58 1.5 pk #include <machine/conf.h>
59 1.1 pk
60 1.1 pk #include <dev/ic/lsi64854reg.h>
61 1.1 pk #include <dev/ic/lsi64854var.h>
62 1.1 pk
63 1.1 pk #include <dev/sbus/sbusvar.h>
64 1.1 pk #include <dev/sbus/bppreg.h>
65 1.1 pk
66 1.1 pk #define splbpp() spltty() /* XXX */
67 1.1 pk
68 1.6 eeh #ifdef DEBUG
69 1.6 eeh #define DPRINTF(x) do { if (bppdebug) printf x ; } while (0)
70 1.6 eeh int bppdebug = 1;
71 1.6 eeh #else
72 1.6 eeh #define DPRINTF(x)
73 1.6 eeh #endif
74 1.6 eeh
75 1.1 pk #if 0
76 1.1 pk struct bpp_param {
77 1.1 pk int bpp_dss; /* data setup to strobe */
78 1.1 pk int bpp_dsw; /* data strobe width */
79 1.1 pk int bpp_outputpins; /* Select/Autofeed/Init pins */
80 1.1 pk int bpp_inputpins; /* Error/Select/Paperout pins */
81 1.1 pk };
82 1.1 pk #endif
83 1.1 pk
84 1.1 pk struct hwstate {
85 1.1 pk u_int16_t hw_hcr; /* Hardware config register */
86 1.1 pk u_int16_t hw_ocr; /* Operation config register */
87 1.1 pk u_int8_t hw_tcr; /* Transfer Control register */
88 1.1 pk u_int8_t hw_or; /* Output register */
89 1.1 pk u_int16_t hw_irq; /* IRQ; polarity bits only */
90 1.1 pk };
91 1.1 pk
92 1.1 pk struct bpp_softc {
93 1.1 pk struct lsi64854_softc sc_lsi64854; /* base device */
94 1.1 pk struct sbusdev sc_sd; /* sbus device */
95 1.1 pk
96 1.1 pk size_t sc_bufsz; /* temp buffer */
97 1.1 pk caddr_t sc_buf;
98 1.1 pk
99 1.1 pk int sc_error; /* bottom-half error */
100 1.1 pk int sc_flags;
101 1.1 pk #define BPP_OPEN 0x01 /* Device is open */
102 1.1 pk #define BPP_XCLUDE 0x02 /* Exclusive-open mode */
103 1.1 pk #define BPP_ASYNC 0x04 /* Asynchronous I/O mode */
104 1.1 pk #define BPP_LOCKED 0x08 /* DMA in progress */
105 1.1 pk #define BPP_WANT 0x10 /* Waiting for DMA */
106 1.1 pk
107 1.1 pk struct selinfo sc_rsel;
108 1.1 pk struct selinfo sc_wsel;
109 1.1 pk struct proc *sc_asyncproc; /* Process to notify if async */
110 1.1 pk
111 1.1 pk /* Hardware state */
112 1.1 pk struct hwstate sc_hwdefault;
113 1.1 pk struct hwstate sc_hwcurrent;
114 1.1 pk };
115 1.1 pk
116 1.1 pk static int bppmatch __P((struct device *, struct cfdata *, void *));
117 1.1 pk static void bppattach __P((struct device *, struct device *, void *));
118 1.1 pk static int bppintr __P((void *));
119 1.1 pk static void bpp_setparams __P((struct bpp_softc *, struct hwstate *));
120 1.1 pk
121 1.1 pk struct cfattach bpp_ca = {
122 1.1 pk sizeof(struct bpp_softc), bppmatch, bppattach
123 1.1 pk };
124 1.1 pk
125 1.1 pk extern struct cfdriver bpp_cd;
126 1.1 pk #define BPPUNIT(dev) (minor(dev))
127 1.1 pk
128 1.1 pk
129 1.1 pk int
130 1.1 pk bppmatch(parent, cf, aux)
131 1.1 pk struct device *parent;
132 1.1 pk struct cfdata *cf;
133 1.1 pk void *aux;
134 1.1 pk {
135 1.1 pk struct sbus_attach_args *sa = aux;
136 1.1 pk
137 1.1 pk return (strcmp("SUNW,bpp", sa->sa_name) == 0);
138 1.1 pk }
139 1.1 pk
140 1.1 pk void
141 1.1 pk bppattach(parent, self, aux)
142 1.1 pk struct device *parent, *self;
143 1.1 pk void *aux;
144 1.1 pk {
145 1.1 pk struct sbus_attach_args *sa = aux;
146 1.1 pk struct bpp_softc *dsc = (void *)self;
147 1.1 pk struct lsi64854_softc *sc = &dsc->sc_lsi64854;
148 1.1 pk int burst, sbusburst;
149 1.1 pk int node;
150 1.1 pk
151 1.1 pk sc->sc_bustag = sa->sa_bustag;
152 1.1 pk sc->sc_dmatag = sa->sa_dmatag;
153 1.1 pk node = sa->sa_node;
154 1.1 pk
155 1.1 pk /* Map device registers */
156 1.1 pk if (bus_space_map2(sa->sa_bustag,
157 1.1 pk sa->sa_slot,
158 1.1 pk sa->sa_offset,
159 1.1 pk sa->sa_size,
160 1.1 pk BUS_SPACE_MAP_LINEAR,
161 1.1 pk 0, &sc->sc_regs) != 0) {
162 1.1 pk printf("%s: cannot map registers\n", self->dv_xname);
163 1.1 pk return;
164 1.1 pk }
165 1.1 pk
166 1.1 pk /*
167 1.1 pk * Get transfer burst size from PROM and plug it into the
168 1.1 pk * controller registers. This is needed on the Sun4m; do
169 1.1 pk * others need it too?
170 1.1 pk */
171 1.1 pk sbusburst = ((struct sbus_softc *)parent)->sc_burst;
172 1.1 pk if (sbusburst == 0)
173 1.1 pk sbusburst = SBUS_BURST_32 - 1; /* 1->16 */
174 1.1 pk
175 1.8.6.1 fvdl burst = PROM_getpropint(node, "burst-sizes", -1);
176 1.1 pk if (burst == -1)
177 1.1 pk /* take SBus burst sizes */
178 1.1 pk burst = sbusburst;
179 1.1 pk
180 1.1 pk /* Clamp at parent's burst sizes */
181 1.1 pk burst &= sbusburst;
182 1.1 pk sc->sc_burst = (burst & SBUS_BURST_32) ? 32 :
183 1.1 pk (burst & SBUS_BURST_16) ? 16 : 0;
184 1.1 pk
185 1.1 pk /* Join the Sbus device family */
186 1.1 pk dsc->sc_sd.sd_reset = (void *)0;
187 1.1 pk sbus_establish(&dsc->sc_sd, self);
188 1.1 pk
189 1.1 pk /* Initialize the DMA channel */
190 1.1 pk sc->sc_channel = L64854_CHANNEL_PP;
191 1.1 pk lsi64854_attach(sc);
192 1.1 pk
193 1.3 pk /* Establish interrupt handler */
194 1.3 pk if (sa->sa_nintr) {
195 1.3 pk sc->sc_intrchain = bppintr;
196 1.3 pk sc->sc_intrchainarg = dsc;
197 1.5 pk (void)bus_intr_establish(sa->sa_bustag, sa->sa_pri, IPL_TTY, 0,
198 1.6 eeh bppintr, sc);
199 1.3 pk }
200 1.1 pk
201 1.1 pk /* Allocate buffer XXX - should actually use dmamap_uio() */
202 1.1 pk dsc->sc_bufsz = 1024;
203 1.1 pk dsc->sc_buf = malloc(dsc->sc_bufsz, M_DEVBUF, M_NOWAIT);
204 1.1 pk
205 1.1 pk /* XXX read default state */
206 1.1 pk {
207 1.1 pk bus_space_handle_t h = sc->sc_regs;
208 1.1 pk struct hwstate *hw = &dsc->sc_hwdefault;
209 1.6 eeh int ack_rate = sa->sa_frequency/1000000;
210 1.6 eeh
211 1.1 pk hw->hw_hcr = bus_space_read_2(sc->sc_bustag, h, L64854_REG_HCR);
212 1.1 pk hw->hw_ocr = bus_space_read_2(sc->sc_bustag, h, L64854_REG_OCR);
213 1.1 pk hw->hw_tcr = bus_space_read_1(sc->sc_bustag, h, L64854_REG_TCR);
214 1.1 pk hw->hw_or = bus_space_read_1(sc->sc_bustag, h, L64854_REG_OR);
215 1.6 eeh
216 1.6 eeh DPRINTF(("bpp: hcr %x ocr %x tcr %x or %x\n",
217 1.6 eeh hw->hw_hcr, hw->hw_ocr, hw->hw_tcr, hw->hw_or));
218 1.6 eeh /* Set these to sane values */
219 1.6 eeh hw->hw_hcr = ((ack_rate<<BPP_HCR_DSS_SHFT)&BPP_HCR_DSS_MASK)
220 1.6 eeh | ((ack_rate<<BPP_HCR_DSW_SHFT)&BPP_HCR_DSW_MASK);
221 1.6 eeh hw->hw_ocr |= BPP_OCR_ACK_OP;
222 1.1 pk }
223 1.1 pk }
224 1.1 pk
225 1.1 pk void
226 1.1 pk bpp_setparams(sc, hw)
227 1.1 pk struct bpp_softc *sc;
228 1.1 pk struct hwstate *hw;
229 1.1 pk {
230 1.1 pk u_int16_t irq;
231 1.1 pk bus_space_tag_t t = sc->sc_lsi64854.sc_bustag;
232 1.1 pk bus_space_handle_t h = sc->sc_lsi64854.sc_regs;
233 1.1 pk
234 1.1 pk bus_space_write_2(t, h, L64854_REG_HCR, hw->hw_hcr);
235 1.1 pk bus_space_write_2(t, h, L64854_REG_OCR, hw->hw_ocr);
236 1.1 pk bus_space_write_1(t, h, L64854_REG_TCR, hw->hw_tcr);
237 1.1 pk bus_space_write_1(t, h, L64854_REG_OR, hw->hw_or);
238 1.1 pk
239 1.1 pk /* Only change IRP settings in interrupt status register */
240 1.1 pk irq = bus_space_read_2(t, h, L64854_REG_ICR);
241 1.1 pk irq &= ~BPP_ALLIRP;
242 1.1 pk irq |= (hw->hw_irq & BPP_ALLIRP);
243 1.1 pk bus_space_write_2(t, h, L64854_REG_ICR, irq);
244 1.6 eeh DPRINTF(("bpp_setparams: hcr %x ocr %x tcr %x or %x, irq %x\n",
245 1.6 eeh hw->hw_hcr, hw->hw_ocr, hw->hw_tcr, hw->hw_or, irq));
246 1.1 pk }
247 1.1 pk
248 1.1 pk int
249 1.8.6.2 fvdl bppopen(devvp, flags, mode, p)
250 1.8.6.2 fvdl struct vnode *devvp;
251 1.1 pk int flags, mode;
252 1.1 pk struct proc *p;
253 1.1 pk {
254 1.8.6.2 fvdl dev_t dev = vdev_rdev(devvp);
255 1.1 pk int unit = BPPUNIT(dev);
256 1.1 pk struct bpp_softc *sc;
257 1.1 pk struct lsi64854_softc *lsi;
258 1.1 pk u_int16_t irq;
259 1.1 pk int s;
260 1.1 pk
261 1.1 pk if (unit >= bpp_cd.cd_ndevs)
262 1.1 pk return (ENXIO);
263 1.1 pk sc = bpp_cd.cd_devs[unit];
264 1.1 pk
265 1.1 pk if ((sc->sc_flags & (BPP_OPEN|BPP_XCLUDE)) == (BPP_OPEN|BPP_XCLUDE))
266 1.1 pk return (EBUSY);
267 1.1 pk
268 1.1 pk lsi = &sc->sc_lsi64854;
269 1.1 pk
270 1.1 pk /* Set default parameters */
271 1.1 pk sc->sc_hwcurrent = sc->sc_hwdefault;
272 1.1 pk s = splbpp();
273 1.1 pk bpp_setparams(sc, &sc->sc_hwdefault);
274 1.1 pk splx(s);
275 1.1 pk
276 1.8.6.2 fvdl vdev_setprivdata(devvp, sc);
277 1.8.6.2 fvdl
278 1.1 pk /* Enable interrupts */
279 1.6 eeh irq = BPP_ERR_IRQ_EN;
280 1.1 pk irq |= sc->sc_hwdefault.hw_irq;
281 1.1 pk bus_space_write_2(lsi->sc_bustag, lsi->sc_regs, L64854_REG_ICR, irq);
282 1.1 pk return (0);
283 1.1 pk }
284 1.1 pk
285 1.1 pk int
286 1.8.6.2 fvdl bppclose(devvp, flags, mode, p)
287 1.8.6.2 fvdl struct vnode *devvp;
288 1.1 pk int flags, mode;
289 1.1 pk struct proc *p;
290 1.1 pk {
291 1.8.6.2 fvdl struct bpp_softc *sc = vdev_privdata(devvp);
292 1.1 pk struct lsi64854_softc *lsi = &sc->sc_lsi64854;
293 1.1 pk u_int16_t irq;
294 1.1 pk
295 1.1 pk /* Turn off all interrupt enables */
296 1.1 pk irq = sc->sc_hwdefault.hw_irq | BPP_ALLIRQ;
297 1.1 pk irq &= ~BPP_ALLEN;
298 1.1 pk bus_space_write_2(lsi->sc_bustag, lsi->sc_regs, L64854_REG_ICR, irq);
299 1.1 pk
300 1.1 pk sc->sc_asyncproc = NULL;
301 1.1 pk sc->sc_flags = 0;
302 1.1 pk return (0);
303 1.1 pk }
304 1.1 pk
305 1.1 pk int
306 1.8.6.2 fvdl bppread(devvp, uio, flags)
307 1.8.6.2 fvdl struct vnode *devvp;
308 1.1 pk struct uio *uio;
309 1.1 pk int flags;
310 1.1 pk {
311 1.1 pk
312 1.1 pk return (ENXIO);
313 1.1 pk }
314 1.1 pk
315 1.1 pk int
316 1.8.6.2 fvdl bppwrite(devvp, uio, flags)
317 1.8.6.2 fvdl struct vnode *devvp;
318 1.1 pk struct uio *uio;
319 1.1 pk int flags;
320 1.1 pk {
321 1.8.6.2 fvdl struct bpp_softc *sc = vdev_privdata(devvp);
322 1.1 pk struct lsi64854_softc *lsi = &sc->sc_lsi64854;
323 1.1 pk int error = 0;
324 1.1 pk int s;
325 1.1 pk
326 1.1 pk /*
327 1.4 pk * Wait until the DMA engine is free.
328 1.1 pk */
329 1.1 pk s = splbpp();
330 1.1 pk while ((sc->sc_flags & BPP_LOCKED) != 0) {
331 1.1 pk if ((flags & IO_NDELAY) != 0) {
332 1.1 pk splx(s);
333 1.1 pk return (EWOULDBLOCK);
334 1.1 pk }
335 1.1 pk
336 1.1 pk sc->sc_flags |= BPP_WANT;
337 1.1 pk error = tsleep(sc->sc_buf, PZERO|PCATCH, "bppwrite", 0);
338 1.1 pk if (error != 0) {
339 1.1 pk splx(s);
340 1.1 pk return (error);
341 1.1 pk }
342 1.1 pk }
343 1.1 pk sc->sc_flags |= BPP_LOCKED;
344 1.1 pk splx(s);
345 1.1 pk
346 1.1 pk /*
347 1.1 pk * Move data from user space into our private buffer
348 1.1 pk * and start DMA.
349 1.1 pk */
350 1.1 pk while (uio->uio_resid > 0) {
351 1.1 pk caddr_t bp = sc->sc_buf;
352 1.1 pk size_t len = min(sc->sc_bufsz, uio->uio_resid);
353 1.1 pk
354 1.1 pk if ((error = uiomove(bp, len, uio)) != 0)
355 1.1 pk break;
356 1.1 pk
357 1.1 pk while (len > 0) {
358 1.1 pk u_int8_t tcr;
359 1.1 pk size_t size = len;
360 1.1 pk DMA_SETUP(lsi, &bp, &len, 0, &size);
361 1.6 eeh
362 1.6 eeh #ifdef DEBUG
363 1.6 eeh if (bppdebug) {
364 1.6 eeh int i;
365 1.8 eeh printf("bpp: writing %ld : ", len);
366 1.6 eeh for (i=0; i<len; i++) printf("%c(0x%x)", bp[i], bp[i]);
367 1.6 eeh printf("\n");
368 1.6 eeh }
369 1.6 eeh #endif
370 1.1 pk
371 1.1 pk /* Clear direction control bit */
372 1.1 pk tcr = bus_space_read_1(lsi->sc_bustag, lsi->sc_regs,
373 1.1 pk L64854_REG_TCR);
374 1.1 pk tcr &= ~BPP_TCR_DIR;
375 1.2 pk bus_space_write_1(lsi->sc_bustag, lsi->sc_regs,
376 1.2 pk L64854_REG_TCR, tcr);
377 1.1 pk
378 1.1 pk /* Enable DMA */
379 1.4 pk s = splbpp();
380 1.1 pk DMA_GO(lsi);
381 1.1 pk error = tsleep(sc, PZERO|PCATCH, "bppdma", 0);
382 1.4 pk splx(s);
383 1.1 pk if (error != 0)
384 1.1 pk goto out;
385 1.1 pk
386 1.1 pk /* Bail out if bottom half reported an error */
387 1.1 pk if ((error = sc->sc_error) != 0)
388 1.1 pk goto out;
389 1.4 pk
390 1.6 eeh /*
391 1.6 eeh * lsi64854_pp_intr() does this part.
392 1.6 eeh *
393 1.6 eeh * len -= size;
394 1.6 eeh */
395 1.1 pk }
396 1.1 pk }
397 1.1 pk
398 1.1 pk out:
399 1.6 eeh DPRINTF(("bpp done %x\n", error));
400 1.1 pk s = splbpp();
401 1.1 pk sc->sc_flags &= ~BPP_LOCKED;
402 1.1 pk if ((sc->sc_flags & BPP_WANT) != 0) {
403 1.1 pk sc->sc_flags &= ~BPP_WANT;
404 1.1 pk wakeup(sc->sc_buf);
405 1.1 pk }
406 1.1 pk splx(s);
407 1.1 pk return (error);
408 1.1 pk }
409 1.1 pk
410 1.1 pk /* move to header: */
411 1.1 pk #define BPPIOCSPARAM _IOW('P', 0x1, struct hwstate)
412 1.1 pk #define BPPIOCGPARAM _IOR('P', 0x2, struct hwstate)
413 1.1 pk
414 1.1 pk int
415 1.8.6.2 fvdl bppioctl(devvp, cmd, data, flag, p)
416 1.8.6.2 fvdl struct vnode *devvp;
417 1.1 pk u_long cmd;
418 1.1 pk caddr_t data;
419 1.1 pk int flag;
420 1.1 pk struct proc *p;
421 1.1 pk {
422 1.8.6.2 fvdl struct bpp_softc *sc = vdev_privdata(devvp);
423 1.1 pk struct hwstate *hw, *chw;
424 1.1 pk int error = 0;
425 1.1 pk int s;
426 1.1 pk
427 1.1 pk switch(cmd) {
428 1.1 pk case BPPIOCSPARAM:
429 1.1 pk chw = &sc->sc_hwcurrent;
430 1.1 pk hw = (struct hwstate *)data;
431 1.1 pk
432 1.1 pk /*
433 1.1 pk * Extract and store user-settable bits.
434 1.1 pk */
435 1.1 pk #define _bpp_set(reg,mask) do { \
436 1.1 pk chw->reg &= ~(mask); \
437 1.1 pk chw->reg |= (hw->reg & (mask)); \
438 1.1 pk } while (0)
439 1.1 pk _bpp_set(hw_hcr, BPP_HCR_DSS_MASK|BPP_HCR_DSW_MASK);
440 1.1 pk _bpp_set(hw_ocr, BPP_OCR_USER);
441 1.1 pk _bpp_set(hw_tcr, BPP_TCR_USER);
442 1.1 pk _bpp_set(hw_or, BPP_OR_USER);
443 1.1 pk _bpp_set(hw_irq, BPP_IRQ_USER);
444 1.1 pk #undef _bpp_set
445 1.1 pk
446 1.1 pk /* Apply settings */
447 1.1 pk s = splbpp();
448 1.1 pk bpp_setparams(sc, chw);
449 1.1 pk splx(s);
450 1.1 pk break;
451 1.1 pk case BPPIOCGPARAM:
452 1.1 pk *((struct hwstate *)data) = sc->sc_hwcurrent;
453 1.1 pk break;
454 1.1 pk case TIOCEXCL:
455 1.1 pk s = splbpp();
456 1.1 pk sc->sc_flags |= BPP_XCLUDE;
457 1.1 pk splx(s);
458 1.1 pk break;
459 1.1 pk case TIOCNXCL:
460 1.1 pk s = splbpp();
461 1.1 pk sc->sc_flags &= ~BPP_XCLUDE;
462 1.1 pk splx(s);
463 1.1 pk break;
464 1.1 pk case FIOASYNC:
465 1.1 pk s = splbpp();
466 1.1 pk if (*(int *)data) {
467 1.1 pk if (sc->sc_asyncproc != NULL)
468 1.1 pk error = EBUSY;
469 1.1 pk else
470 1.1 pk sc->sc_asyncproc = p;
471 1.1 pk } else
472 1.1 pk sc->sc_asyncproc = NULL;
473 1.1 pk splx(s);
474 1.1 pk break;
475 1.1 pk default:
476 1.1 pk break;
477 1.1 pk }
478 1.1 pk
479 1.1 pk return (error);
480 1.1 pk }
481 1.1 pk
482 1.1 pk int
483 1.8.6.2 fvdl bpppoll(devvp, events, p)
484 1.8.6.2 fvdl struct vnode *devvp;
485 1.1 pk int events;
486 1.1 pk struct proc *p;
487 1.1 pk {
488 1.8.6.2 fvdl struct bpp_softc *sc = vdev_privdata(devvp);
489 1.1 pk int revents = 0;
490 1.1 pk
491 1.1 pk if (events & (POLLIN | POLLRDNORM)) {
492 1.1 pk /* read is not yet implemented */
493 1.1 pk }
494 1.1 pk
495 1.1 pk if (events & (POLLOUT | POLLWRNORM)) {
496 1.1 pk if ((sc->sc_flags & BPP_LOCKED) == 0)
497 1.1 pk revents |= (POLLOUT | POLLWRNORM);
498 1.1 pk }
499 1.1 pk
500 1.1 pk if (revents == 0) {
501 1.1 pk if (events & (POLLIN | POLLRDNORM))
502 1.1 pk selrecord(p, &sc->sc_rsel);
503 1.1 pk if (events & (POLLOUT | POLLWRNORM))
504 1.1 pk selrecord(p, &sc->sc_wsel);
505 1.1 pk }
506 1.1 pk
507 1.1 pk return (revents);
508 1.1 pk }
509 1.1 pk
510 1.1 pk int
511 1.1 pk bppintr(arg)
512 1.1 pk void *arg;
513 1.1 pk {
514 1.1 pk struct bpp_softc *sc = arg;
515 1.1 pk struct lsi64854_softc *lsi = &sc->sc_lsi64854;
516 1.1 pk u_int16_t irq;
517 1.1 pk
518 1.6 eeh /* First handle any possible DMA interrupts */
519 1.6 eeh if (lsi64854_pp_intr((void *)lsi) == -1)
520 1.6 eeh sc->sc_error = 1;
521 1.6 eeh
522 1.1 pk irq = bus_space_read_2(lsi->sc_bustag, lsi->sc_regs, L64854_REG_ICR);
523 1.1 pk /* Ack all interrupts */
524 1.1 pk bus_space_write_2(lsi->sc_bustag, lsi->sc_regs, L64854_REG_ICR,
525 1.1 pk irq | BPP_ALLIRQ);
526 1.1 pk
527 1.6 eeh DPRINTF(("bpp_intr: %x\n", irq));
528 1.1 pk /* Did our device interrupt? */
529 1.1 pk if ((irq & BPP_ALLIRQ) == 0)
530 1.1 pk return (0);
531 1.1 pk
532 1.1 pk if ((sc->sc_flags & BPP_LOCKED) != 0)
533 1.1 pk wakeup(sc);
534 1.1 pk else if ((sc->sc_flags & BPP_WANT) != 0) {
535 1.1 pk sc->sc_flags &= ~BPP_WANT;
536 1.1 pk wakeup(sc->sc_buf);
537 1.1 pk } else {
538 1.1 pk selwakeup(&sc->sc_wsel);
539 1.1 pk if (sc->sc_asyncproc != NULL)
540 1.1 pk psignal(sc->sc_asyncproc, SIGIO);
541 1.1 pk }
542 1.1 pk return (1);
543 1.1 pk }
544