Home | History | Annotate | Line # | Download | only in isa
boca.c revision 1.2
      1 /*	$NetBSD: boca.c,v 1.2 1995/01/03 22:38:55 mycroft Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 1995 Charles Hannum.  All rights reserved.
      5  *
      6  * This code is derived from public-domain software written by
      7  * Roland McGrath, and information provided by David Muir Sharnoff.
      8  *
      9  * Redistribution and use in source and binary forms, with or without
     10  * modification, are permitted provided that the following conditions
     11  * are met:
     12  * 1. Redistributions of source code must retain the above copyright
     13  *    notice, this list of conditions and the following disclaimer.
     14  * 2. Redistributions in binary form must reproduce the above copyright
     15  *    notice, this list of conditions and the following disclaimer in the
     16  *    documentation and/or other materials provided with the distribution.
     17  * 3. All advertising materials mentioning features or use of this software
     18  *    must display the following acknowledgement:
     19  *	This product includes software developed by Charles Hannum.
     20  * 4. The name of the author may not be used to endorse or promote products
     21  *    derived from this software without specific prior written permission.
     22  *
     23  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     24  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     25  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     26  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     27  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     28  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     29  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     30  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     31  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     32  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     33  */
     34 
     35 #include <sys/param.h>
     36 #include <sys/device.h>
     37 
     38 #include <machine/pio.h>
     39 
     40 #include <i386/isa/isavar.h>
     41 
     42 struct boca_softc {
     43 	struct device sc_dev;
     44 	struct intrhand sc_ih;
     45 
     46 	int sc_iobase;
     47 	int sc_alive;		/* mask of slave units attached */
     48 	void *sc_slaves[8];	/* com device unit numbers */
     49 };
     50 
     51 int bocaprobe();
     52 void bocaattach();
     53 int bocaintr __P((struct boca_softc *));
     54 
     55 struct cfdriver bocacd = {
     56 	NULL, "boca", bocaprobe, bocaattach, DV_TTY, sizeof(struct boca_softc)
     57 };
     58 
     59 int
     60 bocaprobe(parent, self, aux)
     61 	struct device *parent, *self;
     62 	void *aux;
     63 {
     64 	struct isa_attach_args *ia = aux;
     65 
     66 	/*
     67 	 * Do the normal com probe for the first UART and assume
     68 	 * its presence means there is a multiport board there.
     69 	 * XXX Needs more robustness.
     70 	 */
     71 	ia->ia_iosize = 8 * 8;
     72 	return (comprobe1(ia->ia_iobase));
     73 }
     74 
     75 struct boca_attach_args {
     76 	int ba_slave;
     77 };
     78 
     79 int
     80 bocasubmatch(parent, match, aux)
     81 	struct device *parent;
     82 	void *match, *aux;
     83 {
     84 	struct boca_softc *sc = (void *)parent;
     85 	struct device *self = match;
     86 	struct isa_attach_args *ia = aux;
     87 	struct boca_attach_args *ba = ia->ia_aux;
     88 	struct cfdata *cf = self->dv_cfdata;
     89 
     90 	if (cf->cf_loc[0] != -1 && cf->cf_loc[0] != ba->ba_slave)
     91 		return (0);
     92 	return ((*cf->cf_driver->cd_match)(parent, match, ia));
     93 }
     94 
     95 int
     96 bocaprint(aux, boca)
     97 	void *aux;
     98 	char *boca;
     99 {
    100 	struct isa_attach_args *ia = aux;
    101 	struct boca_attach_args *ba = ia->ia_aux;
    102 
    103 	printf(" slave %d", ba->ba_slave);
    104 }
    105 
    106 void
    107 bocaattach(parent, self, aux)
    108 	struct device *parent, *self;
    109 	void *aux;
    110 {
    111 	struct boca_softc *sc = (void *)self;
    112 	struct isa_attach_args *ia = aux;
    113 	struct boca_attach_args ba;
    114 	struct isa_attach_args isa;
    115 
    116 	sc->sc_iobase = ia->ia_iobase;
    117 
    118 	printf("\n");
    119 
    120 	isa.ia_aux = &ba;
    121 	for (ba.ba_slave = 0; ba.ba_slave < 8; ba.ba_slave++) {
    122 		struct cfdata *cf;
    123 		isa.ia_iobase = sc->sc_iobase + 8 * ba.ba_slave;
    124 		isa.ia_iosize = 0x666;
    125 		isa.ia_irq = IRQUNK;
    126 		isa.ia_drq = DRQUNK;
    127 		isa.ia_msize = 0;
    128 		if ((cf = config_search(bocasubmatch, self, &isa)) != 0) {
    129 			config_attach(self, cf, &isa, bocaprint);
    130 			sc->sc_slaves[ba.ba_slave] =
    131 			    cf->cf_driver->cd_devs[cf->cf_unit];
    132 			sc->sc_alive |= 1 << ba.ba_slave;
    133 		}
    134 	}
    135 
    136 	sc->sc_ih.ih_fun = bocaintr;
    137 	sc->sc_ih.ih_arg = sc;
    138 	sc->sc_ih.ih_level = IPL_TTY;
    139 	intr_establish(ia->ia_irq, IST_EDGE, &sc->sc_ih);
    140 }
    141 
    142 int
    143 bocaintr(sc)
    144 	struct boca_softc *sc;
    145 {
    146 	int iobase = sc->sc_iobase;
    147 	int alive = sc->sc_alive;
    148 	int bits;
    149 
    150 	bits = inb(iobase | 0x07) & alive;
    151 	if (bits == 0)
    152 		return (0);
    153 
    154 	for (;;) {
    155 #define	TRY(n) \
    156 		if (bits & (1 << (n))) \
    157 			comintr(sc->sc_slaves[n]);
    158 		TRY(0);
    159 		TRY(1);
    160 		TRY(2);
    161 		TRY(3);
    162 		TRY(4);
    163 		TRY(5);
    164 		TRY(6);
    165 		TRY(7);
    166 #undef TRY
    167 		bits = inb(iobase | 0x07) & alive;
    168 		if (bits == 0)
    169 			return (1);
    170  	}
    171 }
    172