Home | History | Annotate | Line # | Download | only in sbus
bpp.c revision 1.8.2.7
      1  1.8.2.3  nathanw /*	$NetBSD: bpp.c,v 1.8.2.7 2002/12/11 06:38:39 thorpej 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.8.2.2  nathanw 
     39  1.8.2.2  nathanw #include <sys/cdefs.h>
     40  1.8.2.2  nathanw __KERNEL_RCSID(0, "$NetBSD: bpp.c,v 1.8.2.7 2002/12/11 06:38:39 thorpej Exp $");
     41      1.1       pk 
     42      1.1       pk #include <sys/param.h>
     43      1.1       pk #include <sys/ioctl.h>
     44      1.1       pk #include <sys/fcntl.h>
     45      1.1       pk #include <sys/systm.h>
     46      1.1       pk #include <sys/kernel.h>
     47      1.1       pk #include <sys/vnode.h>
     48      1.1       pk #include <sys/poll.h>
     49      1.1       pk #include <sys/select.h>
     50      1.1       pk #include <sys/malloc.h>
     51      1.1       pk #include <sys/proc.h>
     52      1.1       pk #include <sys/signalvar.h>
     53      1.1       pk #include <sys/conf.h>
     54      1.1       pk #include <sys/errno.h>
     55      1.1       pk #include <sys/device.h>
     56      1.1       pk 
     57      1.1       pk #include <machine/bus.h>
     58      1.5       pk #include <machine/intr.h>
     59      1.1       pk #include <machine/autoconf.h>
     60      1.1       pk 
     61      1.1       pk #include <dev/ic/lsi64854reg.h>
     62      1.1       pk #include <dev/ic/lsi64854var.h>
     63      1.1       pk 
     64      1.1       pk #include <dev/sbus/sbusvar.h>
     65      1.1       pk #include <dev/sbus/bppreg.h>
     66      1.1       pk 
     67      1.1       pk #define splbpp()	spltty()	/* XXX */
     68      1.1       pk 
     69      1.6      eeh #ifdef DEBUG
     70      1.6      eeh #define DPRINTF(x) do { if (bppdebug) printf x ; } while (0)
     71      1.6      eeh int bppdebug = 1;
     72      1.6      eeh #else
     73      1.6      eeh #define DPRINTF(x)
     74      1.6      eeh #endif
     75      1.6      eeh 
     76      1.1       pk #if 0
     77      1.1       pk struct bpp_param {
     78      1.1       pk 	int	bpp_dss;		/* data setup to strobe */
     79      1.1       pk 	int	bpp_dsw;		/* data strobe width */
     80      1.1       pk 	int	bpp_outputpins;		/* Select/Autofeed/Init pins */
     81      1.1       pk 	int	bpp_inputpins;		/* Error/Select/Paperout pins */
     82      1.1       pk };
     83      1.1       pk #endif
     84      1.1       pk 
     85      1.1       pk struct hwstate {
     86      1.1       pk 	u_int16_t	hw_hcr;		/* Hardware config register */
     87      1.1       pk 	u_int16_t	hw_ocr;		/* Operation config register */
     88      1.1       pk 	u_int8_t	hw_tcr;		/* Transfer Control register */
     89      1.1       pk 	u_int8_t	hw_or;		/* Output register */
     90      1.1       pk 	u_int16_t	hw_irq;		/* IRQ; polarity bits only */
     91      1.1       pk };
     92      1.1       pk 
     93      1.1       pk struct bpp_softc {
     94      1.1       pk 	struct lsi64854_softc	sc_lsi64854;	/* base device */
     95      1.1       pk 	struct sbusdev	sc_sd;			/* sbus device */
     96      1.1       pk 
     97      1.1       pk 	size_t		sc_bufsz;		/* temp buffer */
     98      1.1       pk 	caddr_t		sc_buf;
     99      1.1       pk 
    100      1.1       pk 	int		sc_error;		/* bottom-half error */
    101      1.1       pk 	int		sc_flags;
    102      1.1       pk #define BPP_OPEN	0x01		/* Device is open */
    103      1.1       pk #define BPP_XCLUDE	0x02		/* Exclusive-open mode */
    104      1.1       pk #define BPP_ASYNC	0x04		/* Asynchronous I/O mode */
    105      1.1       pk #define BPP_LOCKED	0x08		/* DMA in progress */
    106      1.1       pk #define BPP_WANT	0x10		/* Waiting for DMA */
    107      1.1       pk 
    108      1.1       pk 	struct selinfo	sc_rsel;
    109      1.1       pk 	struct selinfo	sc_wsel;
    110      1.1       pk 	struct proc	*sc_asyncproc;	/* Process to notify if async */
    111      1.1       pk 
    112      1.1       pk 	/* Hardware state */
    113      1.1       pk 	struct hwstate		sc_hwdefault;
    114      1.1       pk 	struct hwstate		sc_hwcurrent;
    115      1.1       pk };
    116      1.1       pk 
    117      1.1       pk static int	bppmatch	__P((struct device *, struct cfdata *, void *));
    118      1.1       pk static void	bppattach	__P((struct device *, struct device *, void *));
    119      1.1       pk static int	bppintr		__P((void *));
    120      1.1       pk static void	bpp_setparams	__P((struct bpp_softc *, struct hwstate *));
    121      1.1       pk 
    122  1.8.2.5  nathanw CFATTACH_DECL(bpp, sizeof(struct bpp_softc),
    123  1.8.2.5  nathanw     bppmatch, bppattach, NULL, NULL);
    124      1.1       pk 
    125      1.1       pk extern struct cfdriver bpp_cd;
    126  1.8.2.4  nathanw 
    127  1.8.2.4  nathanw dev_type_open(bppopen);
    128  1.8.2.4  nathanw dev_type_close(bppclose);
    129  1.8.2.4  nathanw dev_type_write(bppwrite);
    130  1.8.2.4  nathanw dev_type_ioctl(bppioctl);
    131  1.8.2.4  nathanw dev_type_poll(bpppoll);
    132  1.8.2.6  nathanw dev_type_kqfilter(bppkqfilter);
    133  1.8.2.4  nathanw 
    134  1.8.2.4  nathanw const struct cdevsw bpp_cdevsw = {
    135  1.8.2.4  nathanw 	bppopen, bppclose, noread, bppwrite, bppioctl,
    136  1.8.2.6  nathanw 	nostop, notty, bpppoll, nommap, bppkqfilter,
    137  1.8.2.4  nathanw };
    138  1.8.2.4  nathanw 
    139      1.1       pk #define BPPUNIT(dev)	(minor(dev))
    140      1.1       pk 
    141      1.1       pk 
    142      1.1       pk int
    143      1.1       pk bppmatch(parent, cf, aux)
    144      1.1       pk 	struct device *parent;
    145      1.1       pk 	struct cfdata *cf;
    146      1.1       pk 	void *aux;
    147      1.1       pk {
    148      1.1       pk 	struct sbus_attach_args *sa = aux;
    149      1.1       pk 
    150      1.1       pk 	return (strcmp("SUNW,bpp", sa->sa_name) == 0);
    151      1.1       pk }
    152      1.1       pk 
    153      1.1       pk void
    154      1.1       pk bppattach(parent, self, aux)
    155      1.1       pk 	struct device *parent, *self;
    156      1.1       pk 	void *aux;
    157      1.1       pk {
    158      1.1       pk 	struct sbus_attach_args *sa = aux;
    159      1.1       pk 	struct bpp_softc *dsc = (void *)self;
    160      1.1       pk 	struct lsi64854_softc *sc = &dsc->sc_lsi64854;
    161      1.1       pk 	int burst, sbusburst;
    162      1.1       pk 	int node;
    163      1.1       pk 
    164      1.1       pk 	sc->sc_bustag = sa->sa_bustag;
    165      1.1       pk 	sc->sc_dmatag = sa->sa_dmatag;
    166      1.1       pk 	node = sa->sa_node;
    167      1.1       pk 
    168      1.1       pk 	/* Map device registers */
    169  1.8.2.3  nathanw 	if (sbus_bus_map(sa->sa_bustag,
    170  1.8.2.3  nathanw 			 sa->sa_slot, sa->sa_offset, sa->sa_size,
    171  1.8.2.3  nathanw 			 0, &sc->sc_regs) != 0) {
    172      1.1       pk 		printf("%s: cannot map registers\n", self->dv_xname);
    173      1.1       pk 		return;
    174      1.1       pk 	}
    175      1.1       pk 
    176      1.1       pk 	/*
    177      1.1       pk 	 * Get transfer burst size from PROM and plug it into the
    178      1.1       pk 	 * controller registers. This is needed on the Sun4m; do
    179      1.1       pk 	 * others need it too?
    180      1.1       pk 	 */
    181      1.1       pk 	sbusburst = ((struct sbus_softc *)parent)->sc_burst;
    182      1.1       pk 	if (sbusburst == 0)
    183      1.1       pk 		sbusburst = SBUS_BURST_32 - 1; /* 1->16 */
    184      1.1       pk 
    185  1.8.2.1  nathanw 	burst = PROM_getpropint(node, "burst-sizes", -1);
    186      1.1       pk 	if (burst == -1)
    187      1.1       pk 		/* take SBus burst sizes */
    188      1.1       pk 		burst = sbusburst;
    189      1.1       pk 
    190      1.1       pk 	/* Clamp at parent's burst sizes */
    191      1.1       pk 	burst &= sbusburst;
    192      1.1       pk 	sc->sc_burst = (burst & SBUS_BURST_32) ? 32 :
    193      1.1       pk 		       (burst & SBUS_BURST_16) ? 16 : 0;
    194      1.1       pk 
    195      1.1       pk 	/* Join the Sbus device family */
    196      1.1       pk 	dsc->sc_sd.sd_reset = (void *)0;
    197      1.1       pk 	sbus_establish(&dsc->sc_sd, self);
    198      1.1       pk 
    199      1.1       pk 	/* Initialize the DMA channel */
    200      1.1       pk 	sc->sc_channel = L64854_CHANNEL_PP;
    201      1.1       pk 	lsi64854_attach(sc);
    202      1.1       pk 
    203      1.3       pk 	/* Establish interrupt handler */
    204      1.3       pk 	if (sa->sa_nintr) {
    205      1.3       pk 		sc->sc_intrchain = bppintr;
    206      1.3       pk 		sc->sc_intrchainarg = dsc;
    207  1.8.2.7  thorpej 		(void)bus_intr_establish(sa->sa_bustag, sa->sa_pri, IPL_TTY,
    208      1.6      eeh 					 bppintr, sc);
    209      1.3       pk 	}
    210      1.1       pk 
    211      1.1       pk 	/* Allocate buffer XXX - should actually use dmamap_uio() */
    212      1.1       pk 	dsc->sc_bufsz = 1024;
    213      1.1       pk 	dsc->sc_buf = malloc(dsc->sc_bufsz, M_DEVBUF, M_NOWAIT);
    214      1.1       pk 
    215      1.1       pk 	/* XXX read default state */
    216      1.1       pk 	{
    217      1.1       pk 	bus_space_handle_t h = sc->sc_regs;
    218      1.1       pk 	struct hwstate *hw = &dsc->sc_hwdefault;
    219      1.6      eeh 	int ack_rate = sa->sa_frequency/1000000;
    220      1.6      eeh 
    221      1.1       pk 	hw->hw_hcr = bus_space_read_2(sc->sc_bustag, h, L64854_REG_HCR);
    222      1.1       pk 	hw->hw_ocr = bus_space_read_2(sc->sc_bustag, h, L64854_REG_OCR);
    223      1.1       pk 	hw->hw_tcr = bus_space_read_1(sc->sc_bustag, h, L64854_REG_TCR);
    224      1.1       pk 	hw->hw_or = bus_space_read_1(sc->sc_bustag, h, L64854_REG_OR);
    225      1.6      eeh 
    226      1.6      eeh 	DPRINTF(("bpp: hcr %x ocr %x tcr %x or %x\n",
    227      1.6      eeh 		 hw->hw_hcr, hw->hw_ocr, hw->hw_tcr, hw->hw_or));
    228      1.6      eeh 	/* Set these to sane values */
    229      1.6      eeh 	hw->hw_hcr = ((ack_rate<<BPP_HCR_DSS_SHFT)&BPP_HCR_DSS_MASK)
    230      1.6      eeh 		| ((ack_rate<<BPP_HCR_DSW_SHFT)&BPP_HCR_DSW_MASK);
    231      1.6      eeh 	hw->hw_ocr |= BPP_OCR_ACK_OP;
    232      1.1       pk 	}
    233      1.1       pk }
    234      1.1       pk 
    235      1.1       pk void
    236      1.1       pk bpp_setparams(sc, hw)
    237      1.1       pk 	struct bpp_softc *sc;
    238      1.1       pk 	struct hwstate *hw;
    239      1.1       pk {
    240      1.1       pk 	u_int16_t irq;
    241      1.1       pk 	bus_space_tag_t t = sc->sc_lsi64854.sc_bustag;
    242      1.1       pk 	bus_space_handle_t h = sc->sc_lsi64854.sc_regs;
    243      1.1       pk 
    244      1.1       pk 	bus_space_write_2(t, h, L64854_REG_HCR, hw->hw_hcr);
    245      1.1       pk 	bus_space_write_2(t, h, L64854_REG_OCR, hw->hw_ocr);
    246      1.1       pk 	bus_space_write_1(t, h, L64854_REG_TCR, hw->hw_tcr);
    247      1.1       pk 	bus_space_write_1(t, h, L64854_REG_OR, hw->hw_or);
    248      1.1       pk 
    249      1.1       pk 	/* Only change IRP settings in interrupt status register */
    250      1.1       pk 	irq = bus_space_read_2(t, h, L64854_REG_ICR);
    251      1.1       pk 	irq &= ~BPP_ALLIRP;
    252      1.1       pk 	irq |= (hw->hw_irq & BPP_ALLIRP);
    253      1.1       pk 	bus_space_write_2(t, h, L64854_REG_ICR, irq);
    254      1.6      eeh 	DPRINTF(("bpp_setparams: hcr %x ocr %x tcr %x or %x, irq %x\n",
    255      1.6      eeh 		 hw->hw_hcr, hw->hw_ocr, hw->hw_tcr, hw->hw_or, irq));
    256      1.1       pk }
    257      1.1       pk 
    258      1.1       pk int
    259      1.1       pk bppopen(dev, flags, mode, p)
    260      1.1       pk 	dev_t dev;
    261      1.1       pk 	int flags, mode;
    262      1.1       pk 	struct proc *p;
    263      1.1       pk {
    264      1.1       pk 	int unit = BPPUNIT(dev);
    265      1.1       pk 	struct bpp_softc *sc;
    266      1.1       pk 	struct lsi64854_softc *lsi;
    267      1.1       pk 	u_int16_t irq;
    268      1.1       pk 	int s;
    269      1.1       pk 
    270      1.1       pk 	if (unit >= bpp_cd.cd_ndevs)
    271      1.1       pk 		return (ENXIO);
    272      1.1       pk 	sc = bpp_cd.cd_devs[unit];
    273      1.1       pk 
    274      1.1       pk 	if ((sc->sc_flags & (BPP_OPEN|BPP_XCLUDE)) == (BPP_OPEN|BPP_XCLUDE))
    275      1.1       pk 		return (EBUSY);
    276      1.1       pk 
    277      1.1       pk 	lsi = &sc->sc_lsi64854;
    278      1.1       pk 
    279      1.1       pk 	/* Set default parameters */
    280      1.1       pk 	sc->sc_hwcurrent = sc->sc_hwdefault;
    281      1.1       pk 	s = splbpp();
    282      1.1       pk 	bpp_setparams(sc, &sc->sc_hwdefault);
    283      1.1       pk 	splx(s);
    284      1.1       pk 
    285      1.1       pk 	/* Enable interrupts */
    286      1.6      eeh 	irq = BPP_ERR_IRQ_EN;
    287      1.1       pk 	irq |= sc->sc_hwdefault.hw_irq;
    288      1.1       pk 	bus_space_write_2(lsi->sc_bustag, lsi->sc_regs, L64854_REG_ICR, irq);
    289      1.1       pk 	return (0);
    290      1.1       pk }
    291      1.1       pk 
    292      1.1       pk int
    293      1.1       pk bppclose(dev, flags, mode, p)
    294      1.1       pk 	dev_t dev;
    295      1.1       pk 	int flags, mode;
    296      1.1       pk 	struct proc *p;
    297      1.1       pk {
    298      1.1       pk 	struct bpp_softc *sc = bpp_cd.cd_devs[BPPUNIT(dev)];
    299      1.1       pk 	struct lsi64854_softc *lsi = &sc->sc_lsi64854;
    300      1.1       pk 	u_int16_t irq;
    301      1.1       pk 
    302      1.1       pk 	/* Turn off all interrupt enables */
    303      1.1       pk 	irq = sc->sc_hwdefault.hw_irq | BPP_ALLIRQ;
    304      1.1       pk 	irq &= ~BPP_ALLEN;
    305      1.1       pk 	bus_space_write_2(lsi->sc_bustag, lsi->sc_regs, L64854_REG_ICR, irq);
    306      1.1       pk 
    307      1.1       pk 	sc->sc_asyncproc = NULL;
    308      1.1       pk 	sc->sc_flags = 0;
    309      1.1       pk 	return (0);
    310      1.1       pk }
    311      1.1       pk 
    312      1.1       pk int
    313      1.1       pk bppwrite(dev, uio, flags)
    314      1.1       pk 	dev_t dev;
    315      1.1       pk 	struct uio *uio;
    316      1.1       pk 	int flags;
    317      1.1       pk {
    318      1.1       pk 	struct bpp_softc *sc = bpp_cd.cd_devs[BPPUNIT(dev)];
    319      1.1       pk 	struct lsi64854_softc *lsi = &sc->sc_lsi64854;
    320      1.1       pk 	int error = 0;
    321      1.1       pk 	int s;
    322      1.1       pk 
    323      1.1       pk 	/*
    324      1.4       pk 	 * Wait until the DMA engine is free.
    325      1.1       pk 	 */
    326      1.1       pk 	s = splbpp();
    327      1.1       pk 	while ((sc->sc_flags & BPP_LOCKED) != 0) {
    328      1.1       pk 		if ((flags & IO_NDELAY) != 0) {
    329      1.1       pk 			splx(s);
    330      1.1       pk 			return (EWOULDBLOCK);
    331      1.1       pk 		}
    332      1.1       pk 
    333      1.1       pk 		sc->sc_flags |= BPP_WANT;
    334      1.1       pk 		error = tsleep(sc->sc_buf, PZERO|PCATCH, "bppwrite", 0);
    335      1.1       pk 		if (error != 0) {
    336      1.1       pk 			splx(s);
    337      1.1       pk 			return (error);
    338      1.1       pk 		}
    339      1.1       pk 	}
    340      1.1       pk 	sc->sc_flags |= BPP_LOCKED;
    341      1.1       pk 	splx(s);
    342      1.1       pk 
    343      1.1       pk 	/*
    344      1.1       pk 	 * Move data from user space into our private buffer
    345      1.1       pk 	 * and start DMA.
    346      1.1       pk 	 */
    347      1.1       pk 	while (uio->uio_resid > 0) {
    348      1.1       pk 		caddr_t bp = sc->sc_buf;
    349      1.1       pk 		size_t len = min(sc->sc_bufsz, uio->uio_resid);
    350      1.1       pk 
    351      1.1       pk 		if ((error = uiomove(bp, len, uio)) != 0)
    352      1.1       pk 			break;
    353      1.1       pk 
    354      1.1       pk 		while (len > 0) {
    355      1.1       pk 			u_int8_t tcr;
    356      1.1       pk 			size_t size = len;
    357      1.1       pk 			DMA_SETUP(lsi, &bp, &len, 0, &size);
    358      1.6      eeh 
    359      1.6      eeh #ifdef DEBUG
    360      1.6      eeh 			if (bppdebug) {
    361      1.6      eeh 				int i;
    362      1.8      eeh 				printf("bpp: writing %ld : ", len);
    363      1.6      eeh 				for (i=0; i<len; i++) printf("%c(0x%x)", bp[i], bp[i]);
    364      1.6      eeh 				printf("\n");
    365      1.6      eeh 			}
    366      1.6      eeh #endif
    367      1.1       pk 
    368      1.1       pk 			/* Clear direction control bit */
    369      1.1       pk 			tcr = bus_space_read_1(lsi->sc_bustag, lsi->sc_regs,
    370      1.1       pk 						L64854_REG_TCR);
    371      1.1       pk 			tcr &= ~BPP_TCR_DIR;
    372      1.2       pk 			bus_space_write_1(lsi->sc_bustag, lsi->sc_regs,
    373      1.2       pk 					  L64854_REG_TCR, tcr);
    374      1.1       pk 
    375      1.1       pk 			/* Enable DMA */
    376      1.4       pk 			s = splbpp();
    377      1.1       pk 			DMA_GO(lsi);
    378      1.1       pk 			error = tsleep(sc, PZERO|PCATCH, "bppdma", 0);
    379      1.4       pk 			splx(s);
    380      1.1       pk 			if (error != 0)
    381      1.1       pk 				goto out;
    382      1.1       pk 
    383      1.1       pk 			/* Bail out if bottom half reported an error */
    384      1.1       pk 			if ((error = sc->sc_error) != 0)
    385      1.1       pk 				goto out;
    386      1.4       pk 
    387      1.6      eeh 			/*
    388      1.6      eeh 			 * lsi64854_pp_intr() does this part.
    389      1.6      eeh 			 *
    390      1.6      eeh 			 * len -= size;
    391      1.6      eeh 			 */
    392      1.1       pk 		}
    393      1.1       pk 	}
    394      1.1       pk 
    395      1.1       pk out:
    396      1.6      eeh 	DPRINTF(("bpp done %x\n", error));
    397      1.1       pk 	s = splbpp();
    398      1.1       pk 	sc->sc_flags &= ~BPP_LOCKED;
    399      1.1       pk 	if ((sc->sc_flags & BPP_WANT) != 0) {
    400      1.1       pk 		sc->sc_flags &= ~BPP_WANT;
    401      1.1       pk 		wakeup(sc->sc_buf);
    402      1.1       pk 	}
    403      1.1       pk 	splx(s);
    404      1.1       pk 	return (error);
    405      1.1       pk }
    406      1.1       pk 
    407      1.1       pk /* move to header: */
    408      1.1       pk #define BPPIOCSPARAM	_IOW('P', 0x1, struct hwstate)
    409      1.1       pk #define BPPIOCGPARAM	_IOR('P', 0x2, struct hwstate)
    410      1.1       pk 
    411      1.1       pk int
    412      1.1       pk bppioctl(dev, cmd, data, flag, p)
    413      1.1       pk 	dev_t	dev;
    414      1.1       pk 	u_long	cmd;
    415      1.1       pk 	caddr_t	data;
    416      1.1       pk 	int	flag;
    417      1.1       pk 	struct	proc *p;
    418      1.1       pk {
    419      1.1       pk 	struct bpp_softc *sc = bpp_cd.cd_devs[BPPUNIT(dev)];
    420      1.1       pk 	struct hwstate *hw, *chw;
    421      1.1       pk 	int error = 0;
    422      1.1       pk 	int s;
    423      1.1       pk 
    424      1.1       pk 	switch(cmd) {
    425      1.1       pk 	case BPPIOCSPARAM:
    426      1.1       pk 		chw = &sc->sc_hwcurrent;
    427      1.1       pk 		hw = (struct hwstate *)data;
    428      1.1       pk 
    429      1.1       pk 		/*
    430      1.1       pk 		 * Extract and store user-settable bits.
    431      1.1       pk 		 */
    432      1.1       pk #define _bpp_set(reg,mask) do {		\
    433      1.1       pk 	chw->reg &= ~(mask);		\
    434      1.1       pk 	chw->reg |= (hw->reg & (mask));	\
    435      1.1       pk } while (0)
    436      1.1       pk 		_bpp_set(hw_hcr, BPP_HCR_DSS_MASK|BPP_HCR_DSW_MASK);
    437      1.1       pk 		_bpp_set(hw_ocr, BPP_OCR_USER);
    438      1.1       pk 		_bpp_set(hw_tcr, BPP_TCR_USER);
    439      1.1       pk 		_bpp_set(hw_or,  BPP_OR_USER);
    440      1.1       pk 		_bpp_set(hw_irq, BPP_IRQ_USER);
    441      1.1       pk #undef _bpp_set
    442      1.1       pk 
    443      1.1       pk 		/* Apply settings */
    444      1.1       pk 		s = splbpp();
    445      1.1       pk 		bpp_setparams(sc, chw);
    446      1.1       pk 		splx(s);
    447      1.1       pk 		break;
    448      1.1       pk 	case BPPIOCGPARAM:
    449      1.1       pk 		*((struct hwstate *)data) = sc->sc_hwcurrent;
    450      1.1       pk 		break;
    451      1.1       pk 	case TIOCEXCL:
    452      1.1       pk 		s = splbpp();
    453      1.1       pk 		sc->sc_flags |= BPP_XCLUDE;
    454      1.1       pk 		splx(s);
    455      1.1       pk 		break;
    456      1.1       pk 	case TIOCNXCL:
    457      1.1       pk 		s = splbpp();
    458      1.1       pk 		sc->sc_flags &= ~BPP_XCLUDE;
    459      1.1       pk 		splx(s);
    460      1.1       pk 		break;
    461      1.1       pk 	case FIOASYNC:
    462      1.1       pk 		s = splbpp();
    463      1.1       pk 		if (*(int *)data) {
    464      1.1       pk 			if (sc->sc_asyncproc != NULL)
    465      1.1       pk 				error = EBUSY;
    466      1.1       pk 			else
    467      1.1       pk 				sc->sc_asyncproc = p;
    468      1.1       pk 		} else
    469      1.1       pk 			sc->sc_asyncproc = NULL;
    470      1.1       pk 		splx(s);
    471      1.1       pk 		break;
    472      1.1       pk 	default:
    473      1.1       pk 		break;
    474      1.1       pk 	}
    475      1.1       pk 
    476      1.1       pk 	return (error);
    477      1.1       pk }
    478      1.1       pk 
    479      1.1       pk int
    480      1.1       pk bpppoll(dev, events, p)
    481      1.1       pk 	dev_t dev;
    482      1.1       pk 	int events;
    483      1.1       pk 	struct proc *p;
    484      1.1       pk {
    485      1.1       pk 	struct bpp_softc *sc = bpp_cd.cd_devs[BPPUNIT(dev)];
    486      1.1       pk 	int revents = 0;
    487      1.1       pk 
    488      1.1       pk 	if (events & (POLLIN | POLLRDNORM)) {
    489      1.1       pk 		/* read is not yet implemented */
    490      1.1       pk 	}
    491      1.1       pk 
    492      1.1       pk 	if (events & (POLLOUT | POLLWRNORM)) {
    493      1.1       pk 		if ((sc->sc_flags & BPP_LOCKED) == 0)
    494      1.1       pk 			revents |= (POLLOUT | POLLWRNORM);
    495      1.1       pk 	}
    496      1.1       pk 
    497      1.1       pk 	if (revents == 0) {
    498      1.1       pk 		if (events & (POLLIN | POLLRDNORM))
    499      1.1       pk 			selrecord(p, &sc->sc_rsel);
    500      1.1       pk 		if (events & (POLLOUT | POLLWRNORM))
    501      1.1       pk 			selrecord(p, &sc->sc_wsel);
    502      1.1       pk 	}
    503      1.1       pk 
    504      1.1       pk 	return (revents);
    505      1.1       pk }
    506      1.1       pk 
    507  1.8.2.6  nathanw static void
    508  1.8.2.6  nathanw filt_bpprdetach(struct knote *kn)
    509  1.8.2.6  nathanw {
    510  1.8.2.6  nathanw 	struct bpp_softc *sc = kn->kn_hook;
    511  1.8.2.6  nathanw 	int s;
    512  1.8.2.6  nathanw 
    513  1.8.2.6  nathanw 	s = splbpp();
    514  1.8.2.7  thorpej 	SLIST_REMOVE(&sc->sc_rsel.sel_klist, kn, knote, kn_selnext);
    515  1.8.2.6  nathanw 	splx(s);
    516  1.8.2.6  nathanw }
    517  1.8.2.6  nathanw 
    518  1.8.2.6  nathanw static int
    519  1.8.2.6  nathanw filt_bppread(struct knote *kn, long hint)
    520  1.8.2.6  nathanw {
    521  1.8.2.6  nathanw 	/* XXX Read not yet implemented. */
    522  1.8.2.6  nathanw 	return (0);
    523  1.8.2.6  nathanw }
    524  1.8.2.6  nathanw 
    525  1.8.2.6  nathanw static const struct filterops bppread_filtops =
    526  1.8.2.6  nathanw 	{ 1, NULL, filt_bpprdetach, filt_bppread };
    527  1.8.2.6  nathanw 
    528  1.8.2.6  nathanw static void
    529  1.8.2.6  nathanw filt_bppwdetach(struct knote *kn)
    530  1.8.2.6  nathanw {
    531  1.8.2.6  nathanw 	struct bpp_softc *sc = kn->kn_hook;
    532  1.8.2.6  nathanw 	int s;
    533  1.8.2.6  nathanw 
    534  1.8.2.6  nathanw 	s = splbpp();
    535  1.8.2.7  thorpej 	SLIST_REMOVE(&sc->sc_wsel.sel_klist, kn, knote, kn_selnext);
    536  1.8.2.6  nathanw 	splx(s);
    537  1.8.2.6  nathanw }
    538  1.8.2.6  nathanw 
    539  1.8.2.6  nathanw static int
    540  1.8.2.6  nathanw filt_bpfwrite(struct knote *kn, long hint)
    541  1.8.2.6  nathanw {
    542  1.8.2.6  nathanw 	struct bpp_softc *sc = kn->kn_hook;
    543  1.8.2.6  nathanw 
    544  1.8.2.6  nathanw 	if (sc->sc_flags & BPP_LOCKED)
    545  1.8.2.6  nathanw 		return (0);
    546  1.8.2.6  nathanw 
    547  1.8.2.6  nathanw 	kn->kn_data = 0;	/* XXXLUKEM (thorpej): what to put here? */
    548  1.8.2.6  nathanw 	return (1);
    549  1.8.2.6  nathanw }
    550  1.8.2.6  nathanw 
    551  1.8.2.6  nathanw static const struct filterops bppwrite_filtops =
    552  1.8.2.6  nathanw 	{ 1, NULL, filt_bppwdetach, filt_bpfwrite };
    553  1.8.2.6  nathanw 
    554  1.8.2.6  nathanw int
    555  1.8.2.6  nathanw bppkqfilter(dev_t dev, struct knote *kn)
    556  1.8.2.6  nathanw {
    557  1.8.2.6  nathanw 	struct bpp_softc *sc = bpp_cd.cd_devs[BPPUNIT(dev)];
    558  1.8.2.6  nathanw 	struct klist *klist;
    559  1.8.2.6  nathanw 	int s;
    560  1.8.2.6  nathanw 
    561  1.8.2.6  nathanw 	switch (kn->kn_filter) {
    562  1.8.2.6  nathanw 	case EVFILT_READ:
    563  1.8.2.7  thorpej 		klist = &sc->sc_rsel.sel_klist;
    564  1.8.2.6  nathanw 		kn->kn_fop = &bppread_filtops;
    565  1.8.2.6  nathanw 		break;
    566  1.8.2.6  nathanw 
    567  1.8.2.6  nathanw 	case EVFILT_WRITE:
    568  1.8.2.7  thorpej 		klist = &sc->sc_wsel.sel_klist;
    569  1.8.2.6  nathanw 		kn->kn_fop = &bppwrite_filtops;
    570  1.8.2.6  nathanw 		break;
    571  1.8.2.6  nathanw 
    572  1.8.2.6  nathanw 	default:
    573  1.8.2.6  nathanw 		return (1);
    574  1.8.2.6  nathanw 	}
    575  1.8.2.6  nathanw 
    576  1.8.2.6  nathanw 	kn->kn_hook = sc;
    577  1.8.2.6  nathanw 
    578  1.8.2.6  nathanw 	s = splbpp();
    579  1.8.2.6  nathanw 	SLIST_INSERT_HEAD(klist, kn, kn_selnext);
    580  1.8.2.6  nathanw 	splx(s);
    581  1.8.2.6  nathanw 
    582  1.8.2.6  nathanw 	return (0);
    583  1.8.2.6  nathanw }
    584  1.8.2.6  nathanw 
    585      1.1       pk int
    586      1.1       pk bppintr(arg)
    587      1.1       pk 	void *arg;
    588      1.1       pk {
    589      1.1       pk 	struct bpp_softc *sc = arg;
    590      1.1       pk 	struct lsi64854_softc *lsi = &sc->sc_lsi64854;
    591      1.1       pk 	u_int16_t irq;
    592      1.1       pk 
    593      1.6      eeh 	/* First handle any possible DMA interrupts */
    594      1.6      eeh 	if (lsi64854_pp_intr((void *)lsi) == -1)
    595      1.6      eeh 		sc->sc_error = 1;
    596      1.6      eeh 
    597      1.1       pk 	irq = bus_space_read_2(lsi->sc_bustag, lsi->sc_regs, L64854_REG_ICR);
    598      1.1       pk 	/* Ack all interrupts */
    599      1.1       pk 	bus_space_write_2(lsi->sc_bustag, lsi->sc_regs, L64854_REG_ICR,
    600      1.1       pk 			  irq | BPP_ALLIRQ);
    601      1.1       pk 
    602      1.6      eeh 	DPRINTF(("bpp_intr: %x\n", irq));
    603      1.1       pk 	/* Did our device interrupt? */
    604      1.1       pk 	if ((irq & BPP_ALLIRQ) == 0)
    605      1.1       pk 		return (0);
    606      1.1       pk 
    607      1.1       pk 	if ((sc->sc_flags & BPP_LOCKED) != 0)
    608      1.1       pk 		wakeup(sc);
    609      1.1       pk 	else if ((sc->sc_flags & BPP_WANT) != 0) {
    610      1.1       pk 		sc->sc_flags &= ~BPP_WANT;
    611      1.1       pk 		wakeup(sc->sc_buf);
    612      1.1       pk 	} else {
    613  1.8.2.6  nathanw 		selnotify(&sc->sc_wsel, 0);
    614      1.1       pk 		if (sc->sc_asyncproc != NULL)
    615      1.1       pk 			psignal(sc->sc_asyncproc, SIGIO);
    616      1.1       pk 	}
    617      1.1       pk 	return (1);
    618      1.1       pk }
    619