boca.c revision 1.1 1 1.1 mycroft /* $NetBSD: boca.c,v 1.1 1995/01/03 22:30:26 mycroft Exp $ */
2 1.1 mycroft
3 1.1 mycroft /*
4 1.1 mycroft * Multi-port serial card interrupt demuxing support.
5 1.1 mycroft * Roland McGrath 3/20/94
6 1.1 mycroft * The author disclaims copyright and places this file in the public domain.
7 1.1 mycroft *
8 1.1 mycroft * Modified by: Charles Hannum, 3/22/94
9 1.1 mycroft *
10 1.1 mycroft * The programming details of the BOCA board (i.e. how the interrupt register
11 1.1 mycroft * works) were determined by David Muir Sharnoff. BOCA Research refused to
12 1.1 mycroft * provide any programming information.
13 1.1 mycroft */
14 1.1 mycroft
15 1.1 mycroft #include <sys/param.h>
16 1.1 mycroft #include <sys/device.h>
17 1.1 mycroft
18 1.1 mycroft #include <machine/pio.h>
19 1.1 mycroft
20 1.1 mycroft #include <i386/isa/isavar.h>
21 1.1 mycroft
22 1.1 mycroft struct boca_softc {
23 1.1 mycroft struct device sc_dev;
24 1.1 mycroft struct intrhand sc_ih;
25 1.1 mycroft
26 1.1 mycroft int sc_iobase;
27 1.1 mycroft int sc_alive; /* mask of slave units attached */
28 1.1 mycroft void *sc_slaves[8]; /* com device unit numbers */
29 1.1 mycroft };
30 1.1 mycroft
31 1.1 mycroft int bocaprobe();
32 1.1 mycroft void bocaattach();
33 1.1 mycroft int bocaintr __P((struct boca_softc *));
34 1.1 mycroft
35 1.1 mycroft struct cfdriver bocacd = {
36 1.1 mycroft NULL, "boca", bocaprobe, bocaattach, DV_TTY, sizeof(struct boca_softc)
37 1.1 mycroft };
38 1.1 mycroft
39 1.1 mycroft int
40 1.1 mycroft bocaprobe(parent, self, aux)
41 1.1 mycroft struct device *parent, *self;
42 1.1 mycroft void *aux;
43 1.1 mycroft {
44 1.1 mycroft struct isa_attach_args *ia = aux;
45 1.1 mycroft
46 1.1 mycroft /*
47 1.1 mycroft * Do the normal com probe for the first UART and assume
48 1.1 mycroft * its presence means there is a multiport board there.
49 1.1 mycroft * XXX Needs more robustness.
50 1.1 mycroft */
51 1.1 mycroft ia->ia_iosize = 8 * 8;
52 1.1 mycroft return (comprobe1(ia->ia_iobase));
53 1.1 mycroft }
54 1.1 mycroft
55 1.1 mycroft struct boca_attach_args {
56 1.1 mycroft int ba_slave;
57 1.1 mycroft };
58 1.1 mycroft
59 1.1 mycroft int
60 1.1 mycroft bocasubmatch(parent, match, aux)
61 1.1 mycroft struct device *parent;
62 1.1 mycroft void *match, *aux;
63 1.1 mycroft {
64 1.1 mycroft struct boca_softc *sc = (void *)parent;
65 1.1 mycroft struct device *self = match;
66 1.1 mycroft struct isa_attach_args *ia = aux;
67 1.1 mycroft struct boca_attach_args *ba = ia->ia_aux;
68 1.1 mycroft struct cfdata *cf = self->dv_cfdata;
69 1.1 mycroft
70 1.1 mycroft if (cf->cf_loc[0] != -1 && cf->cf_loc[0] != ba->ba_slave)
71 1.1 mycroft return (0);
72 1.1 mycroft return ((*cf->cf_driver->cd_match)(parent, match, ia));
73 1.1 mycroft }
74 1.1 mycroft
75 1.1 mycroft int
76 1.1 mycroft bocaprint(aux, boca)
77 1.1 mycroft void *aux;
78 1.1 mycroft char *boca;
79 1.1 mycroft {
80 1.1 mycroft struct isa_attach_args *ia = aux;
81 1.1 mycroft struct boca_attach_args *ba = ia->ia_aux;
82 1.1 mycroft
83 1.1 mycroft printf(" slave %d", ba->ba_slave);
84 1.1 mycroft }
85 1.1 mycroft
86 1.1 mycroft void
87 1.1 mycroft bocaattach(parent, self, aux)
88 1.1 mycroft struct device *parent, *self;
89 1.1 mycroft void *aux;
90 1.1 mycroft {
91 1.1 mycroft struct boca_softc *sc = (void *)self;
92 1.1 mycroft struct isa_attach_args *ia = aux;
93 1.1 mycroft struct boca_attach_args ba;
94 1.1 mycroft struct isa_attach_args isa;
95 1.1 mycroft
96 1.1 mycroft sc->sc_iobase = ia->ia_iobase;
97 1.1 mycroft
98 1.1 mycroft printf("\n");
99 1.1 mycroft
100 1.1 mycroft isa.ia_aux = &ba;
101 1.1 mycroft for (ba.ba_slave = 0; ba.ba_slave < 8; ba.ba_slave++) {
102 1.1 mycroft struct cfdata *cf;
103 1.1 mycroft isa.ia_iobase = sc->sc_iobase + 8 * ba.ba_slave;
104 1.1 mycroft isa.ia_iosize = 0x666;
105 1.1 mycroft isa.ia_irq = IRQUNK;
106 1.1 mycroft isa.ia_drq = DRQUNK;
107 1.1 mycroft isa.ia_msize = 0;
108 1.1 mycroft if ((cf = config_search(bocasubmatch, self, &isa)) != 0) {
109 1.1 mycroft config_attach(self, cf, &isa, bocaprint);
110 1.1 mycroft sc->sc_slaves[ba.ba_slave] =
111 1.1 mycroft cf->cf_driver->cd_devs[cf->cf_unit];
112 1.1 mycroft sc->sc_alive |= 1 << ba.ba_slave;
113 1.1 mycroft }
114 1.1 mycroft }
115 1.1 mycroft
116 1.1 mycroft sc->sc_ih.ih_fun = bocaintr;
117 1.1 mycroft sc->sc_ih.ih_arg = sc;
118 1.1 mycroft sc->sc_ih.ih_level = IPL_TTY;
119 1.1 mycroft intr_establish(ia->ia_irq, IST_EDGE, &sc->sc_ih);
120 1.1 mycroft }
121 1.1 mycroft
122 1.1 mycroft int
123 1.1 mycroft bocaintr(sc)
124 1.1 mycroft struct boca_softc *sc;
125 1.1 mycroft {
126 1.1 mycroft int iobase = sc->sc_iobase;
127 1.1 mycroft int alive = sc->sc_alive;
128 1.1 mycroft int bits;
129 1.1 mycroft
130 1.1 mycroft bits = inb(iobase | 0x07) & alive;
131 1.1 mycroft if (bits == 0)
132 1.1 mycroft return (0);
133 1.1 mycroft
134 1.1 mycroft for (;;) {
135 1.1 mycroft #define TRY(n) \
136 1.1 mycroft if (bits & (1 << (n))) \
137 1.1 mycroft comintr(sc->sc_slaves[n]);
138 1.1 mycroft TRY(0);
139 1.1 mycroft TRY(1);
140 1.1 mycroft TRY(2);
141 1.1 mycroft TRY(3);
142 1.1 mycroft TRY(4);
143 1.1 mycroft TRY(5);
144 1.1 mycroft TRY(6);
145 1.1 mycroft TRY(7);
146 1.1 mycroft #undef TRY
147 1.1 mycroft bits = inb(iobase | 0x07) & alive;
148 1.1 mycroft if (bits == 0)
149 1.1 mycroft return (1);
150 1.1 mycroft }
151 1.1 mycroft }
152