isa.c revision 1.89 1 /* $NetBSD: isa.c,v 1.89 1996/10/21 22:41:09 thorpej Exp $ */
2
3 /*-
4 * Copyright (c) 1993, 1994 Charles Hannum. All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. All advertising materials mentioning features or use of this software
15 * must display the following acknowledgement:
16 * This product includes software developed by Charles Hannum.
17 * 4. The name of the author may not be used to endorse or promote products
18 * derived from this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
21 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
22 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
23 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
24 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
25 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
29 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 */
31
32 #include <sys/param.h>
33 #include <sys/systm.h>
34 #include <sys/kernel.h>
35 #include <sys/conf.h>
36 #include <sys/malloc.h>
37 #include <sys/device.h>
38
39 #include <machine/intr.h>
40
41 #include <dev/isa/isareg.h>
42 #include <dev/isa/isavar.h>
43
44 int isamatch __P((struct device *, void *, void *));
45 void isaattach __P((struct device *, struct device *, void *));
46 int isaprint __P((void *, const char *));
47
48 struct cfattach isa_ca = {
49 sizeof(struct isa_softc), isamatch, isaattach
50 };
51
52 struct cfdriver isa_cd = {
53 NULL, "isa", DV_DULL, 1
54 };
55
56 int
57 isamatch(parent, match, aux)
58 struct device *parent;
59 void *match, *aux;
60 {
61 struct cfdata *cf = match;
62 struct isabus_attach_args *iba = aux;
63
64 if (strcmp(iba->iba_busname, cf->cf_driver->cd_name))
65 return (0);
66
67 /* XXX check other indicators */
68
69 return (1);
70 }
71
72 void
73 isaattach(parent, self, aux)
74 struct device *parent, *self;
75 void *aux;
76 {
77 struct isa_softc *sc = (struct isa_softc *)self;
78 struct isabus_attach_args *iba = aux;
79
80 isa_attach_hook(parent, self, iba);
81 printf("\n");
82
83 sc->sc_iot = iba->iba_iot;
84 sc->sc_memt = iba->iba_memt;
85 sc->sc_ic = iba->iba_ic;
86
87 /*
88 * Map port 0x84, which causes a 1.25us delay when read.
89 * We do this now, since several drivers need it.
90 */
91 if (bus_space_map(sc->sc_iot, 0x84, 1, 0, &sc->sc_delaybah))
92 panic("isaattach: can't map `delay port'"); /* XXX */
93
94 TAILQ_INIT(&sc->sc_subdevs);
95 config_scan(isascan, self);
96 }
97
98 int
99 isaprint(aux, isa)
100 void *aux;
101 const char *isa;
102 {
103 struct isa_attach_args *ia = aux;
104
105 if (ia->ia_iosize)
106 printf(" port 0x%x", ia->ia_iobase);
107 if (ia->ia_iosize > 1)
108 printf("-0x%x", ia->ia_iobase + ia->ia_iosize - 1);
109 if (ia->ia_msize)
110 printf(" iomem 0x%x", ia->ia_maddr);
111 if (ia->ia_msize > 1)
112 printf("-0x%x", ia->ia_maddr + ia->ia_msize - 1);
113 if (ia->ia_irq != IRQUNK)
114 printf(" irq %d", ia->ia_irq);
115 if (ia->ia_drq != DRQUNK)
116 printf(" drq %d", ia->ia_drq);
117 return (UNCONF);
118 }
119
120 void
121 isascan(parent, match)
122 struct device *parent;
123 void *match;
124 {
125 struct isa_softc *sc = (struct isa_softc *)parent;
126 struct device *dev = match;
127 struct cfdata *cf = dev->dv_cfdata;
128 struct isa_attach_args ia;
129
130 if (cf->cf_fstate == FSTATE_STAR)
131 panic("clone devices not supported on ISA bus");
132
133 ia.ia_iot = sc->sc_iot;
134 ia.ia_memt = sc->sc_memt;
135 ia.ia_ic = sc->sc_ic;
136 ia.ia_iobase = cf->cf_loc[0];
137 ia.ia_iosize = 0x666;
138 ia.ia_maddr = cf->cf_loc[2];
139 ia.ia_msize = cf->cf_loc[3];
140 ia.ia_irq = cf->cf_loc[4] == 2 ? 9 : cf->cf_loc[4];
141 ia.ia_drq = cf->cf_loc[5];
142 ia.ia_delaybah = sc->sc_delaybah;
143
144 if ((*cf->cf_attach->ca_match)(parent, dev, &ia) > 0)
145 config_attach(parent, dev, &ia, isaprint);
146 else
147 free(dev, M_DEVBUF);
148 }
149
150 char *
151 isa_intr_typename(type)
152 int type;
153 {
154
155 switch (type) {
156 case IST_NONE :
157 return ("none");
158 case IST_PULSE:
159 return ("pulsed");
160 case IST_EDGE:
161 return ("edge-triggered");
162 case IST_LEVEL:
163 return ("level-triggered");
164 default:
165 panic("isa_intr_typename: invalid type %d", type);
166 }
167 }
168