isa.c revision 1.105 1 /* $NetBSD: isa.c,v 1.105 1998/08/15 03:51:31 mycroft Exp $ */
2
3 /*-
4 * Copyright (c) 1998 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Charles M. Hannum.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. All advertising materials mentioning features or use of this software
19 * must display the following acknowledgement:
20 * This product includes software developed by the NetBSD
21 * Foundation, Inc. and its contributors.
22 * 4. Neither the name of The NetBSD Foundation nor the names of its
23 * contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
25 *
26 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 * POSSIBILITY OF SUCH DAMAGE.
37 */
38
39 #include <sys/param.h>
40 #include <sys/systm.h>
41 #include <sys/kernel.h>
42 #include <sys/conf.h>
43 #include <sys/malloc.h>
44 #include <sys/device.h>
45
46 #include <machine/intr.h>
47
48 #include <dev/isa/isareg.h>
49 #include <dev/isa/isavar.h>
50 #include <dev/isa/isadmareg.h>
51
52 #include "isadma.h"
53
54 #include "isapnp.h"
55 #ifdef NISAPNP
56 #include <dev/isapnp/isapnpreg.h>
57 #include <dev/isapnp/isapnpvar.h>
58 #endif
59
60 int isamatch __P((struct device *, struct cfdata *, void *));
61 void isaattach __P((struct device *, struct device *, void *));
62 int isaprint __P((void *, const char *));
63
64 struct cfattach isa_ca = {
65 sizeof(struct isa_softc), isamatch, isaattach
66 };
67
68 int isasearch __P((struct device *, struct cfdata *, void *));
69
70 int
71 isamatch(parent, cf, aux)
72 struct device *parent;
73 struct cfdata *cf;
74 void *aux;
75 {
76 struct isabus_attach_args *iba = aux;
77
78 if (strcmp(iba->iba_busname, cf->cf_driver->cd_name))
79 return (0);
80
81 /* XXX check other indicators */
82
83 return (1);
84 }
85
86 void
87 isaattach(parent, self, aux)
88 struct device *parent, *self;
89 void *aux;
90 {
91 struct isa_softc *sc = (struct isa_softc *)self;
92 struct isabus_attach_args *iba = aux;
93
94 isa_attach_hook(parent, self, iba);
95 printf("\n");
96
97 sc->sc_iot = iba->iba_iot;
98 sc->sc_memt = iba->iba_memt;
99 sc->sc_dmat = iba->iba_dmat;
100 sc->sc_ic = iba->iba_ic;
101
102 #if NISAPNP > 0
103 /*
104 * Reset isapnp cards that the bios configured for us
105 */
106 isapnp_isa_attach_hook(sc);
107 #endif
108
109 #if NISADMA > 0
110 /*
111 * Initialize our DMA state.
112 */
113 isa_dmainit(sc->sc_ic, sc->sc_iot, sc->sc_dmat, self);
114 #endif
115
116 TAILQ_INIT(&sc->sc_subdevs);
117
118 config_search(isasearch, self, NULL);
119 }
120
121 int
122 isaprint(aux, isa)
123 void *aux;
124 const char *isa;
125 {
126 struct isa_attach_args *ia = aux;
127
128 if (ia->ia_iosize)
129 printf(" port 0x%x", ia->ia_iobase);
130 if (ia->ia_iosize > 1)
131 printf("-0x%x", ia->ia_iobase + ia->ia_iosize - 1);
132 if (ia->ia_msize)
133 printf(" iomem 0x%x", ia->ia_maddr);
134 if (ia->ia_msize > 1)
135 printf("-0x%x", ia->ia_maddr + ia->ia_msize - 1);
136 if (ia->ia_irq != IRQUNK)
137 printf(" irq %d", ia->ia_irq);
138 if (ia->ia_drq != DRQUNK)
139 printf(" drq %d", ia->ia_drq);
140 if (ia->ia_drq2 != DRQUNK)
141 printf(" drq2 %d", ia->ia_drq2);
142 return (UNCONF);
143 }
144
145 int
146 isasearch(parent, cf, aux)
147 struct device *parent;
148 struct cfdata *cf;
149 void *aux;
150 {
151 struct isa_softc *sc = (struct isa_softc *)parent;
152 struct isa_attach_args ia;
153 int tryagain;
154
155 do {
156 ia.ia_iot = sc->sc_iot;
157 ia.ia_memt = sc->sc_memt;
158 ia.ia_dmat = sc->sc_dmat;
159 ia.ia_ic = sc->sc_ic;
160 ia.ia_iobase = cf->cf_iobase;
161 ia.ia_iosize = 0x666; /* cf->cf_iosize; */
162 ia.ia_maddr = cf->cf_maddr;
163 ia.ia_msize = cf->cf_msize;
164 ia.ia_irq = cf->cf_irq == 2 ? 9 : cf->cf_irq;
165 ia.ia_drq = cf->cf_drq;
166 ia.ia_drq2 = cf->cf_drq2;
167
168 tryagain = 0;
169 if ((*cf->cf_attach->ca_match)(parent, cf, &ia) > 0) {
170 config_attach(parent, cf, &ia, isaprint);
171 tryagain = (cf->cf_fstate == FSTATE_STAR);
172 }
173 } while (tryagain);
174
175 return (0);
176 }
177
178 char *
179 isa_intr_typename(type)
180 int type;
181 {
182
183 switch (type) {
184 case IST_NONE :
185 return ("none");
186 case IST_PULSE:
187 return ("pulsed");
188 case IST_EDGE:
189 return ("edge-triggered");
190 case IST_LEVEL:
191 return ("level-triggered");
192 default:
193 panic("isa_intr_typename: invalid type %d", type);
194 }
195 }
196