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