isa.c revision 1.84 1 /* $NetBSD: isa.c,v 1.84 1996/05/12 23:53:01 mycroft 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 <dev/isa/isareg.h>
40 #include <dev/isa/isavar.h>
41
42 int isamatch __P((struct device *, void *, void *));
43 void isaattach __P((struct device *, struct device *, void *));
44 int isaprint __P((void *, char *));
45
46 struct cfattach isa_ca = {
47 sizeof(struct isa_softc), isamatch, isaattach
48 };
49
50 struct cfdriver isa_cd = {
51 NULL, "isa", DV_DULL, 1
52 };
53
54 int
55 isamatch(parent, match, aux)
56 struct device *parent;
57 void *match, *aux;
58 {
59 struct cfdata *cf = match;
60 struct isabus_attach_args *iba = aux;
61
62 if (strcmp(iba->iba_busname, cf->cf_driver->cd_name))
63 return (0);
64
65 /* XXX check other indicators */
66
67 return (1);
68 }
69
70 void
71 isaattach(parent, self, aux)
72 struct device *parent, *self;
73 void *aux;
74 {
75 struct isa_softc *sc = (struct isa_softc *)self;
76 struct isabus_attach_args *iba = aux;
77
78 isa_attach_hook(parent, self, iba);
79 printf("\n");
80
81 sc->sc_bc = iba->iba_bc;
82 sc->sc_ic = iba->iba_ic;
83
84 /*
85 * Map port 0x84, which causes a 1.25us delay when read.
86 * We do this now, since several drivers need it.
87 */
88 if (bus_io_map(sc->sc_bc, 0x84, 1, &sc->sc_delayioh))
89 panic("isaattach: can't map `delay port'"); /* XXX */
90
91 TAILQ_INIT(&sc->sc_subdevs);
92 config_scan(isascan, self);
93 }
94
95 int
96 isaprint(aux, isa)
97 void *aux;
98 char *isa;
99 {
100 struct isa_attach_args *ia = aux;
101
102 if (ia->ia_iosize)
103 printf(" port 0x%x", ia->ia_iobase);
104 if (ia->ia_iosize > 1)
105 printf("-0x%x", ia->ia_iobase + ia->ia_iosize - 1);
106 if (ia->ia_msize)
107 printf(" iomem 0x%x", ia->ia_maddr);
108 if (ia->ia_msize > 1)
109 printf("-0x%x", ia->ia_maddr + ia->ia_msize - 1);
110 if (ia->ia_irq != IRQUNK)
111 printf(" irq %d", ia->ia_irq);
112 if (ia->ia_drq != DRQUNK)
113 printf(" drq %d", ia->ia_drq);
114 return (UNCONF);
115 }
116
117 void
118 isascan(parent, match)
119 struct device *parent;
120 void *match;
121 {
122 struct isa_softc *sc = (struct isa_softc *)parent;
123 struct device *dev = match;
124 struct cfdata *cf = dev->dv_cfdata;
125 struct isa_attach_args ia;
126
127 if (cf->cf_fstate == FSTATE_STAR)
128 panic("clone devices not supported on ISA bus");
129
130 ia.ia_bc = sc->sc_bc;
131 ia.ia_ic = sc->sc_ic;
132 ia.ia_iobase = cf->cf_loc[0];
133 ia.ia_iosize = 0x666;
134 ia.ia_maddr = cf->cf_loc[2];
135 ia.ia_msize = cf->cf_loc[3];
136 ia.ia_irq = cf->cf_loc[4] == 2 ? 9 : cf->cf_loc[4];
137 ia.ia_drq = cf->cf_loc[5];
138 ia.ia_delayioh = sc->sc_delayioh;
139
140 if ((*cf->cf_attach->ca_match)(parent, dev, &ia) > 0)
141 config_attach(parent, dev, &ia, isaprint);
142 else
143 free(dev, M_DEVBUF);
144 }
145
146 char *
147 isa_intr_typename(type)
148 int type;
149 {
150
151 switch (type) {
152 case IST_NONE :
153 return ("none");
154 case IST_PULSE:
155 return ("pulsed");
156 case IST_EDGE:
157 return ("edge-triggered");
158 case IST_LEVEL:
159 return ("level-triggered");
160 default:
161 panic("isa_intr_typename: invalid type %d", type);
162 }
163 }
164