isa.c revision 1.108 1 1.108 fvdl /* $NetBSD: isa.c,v 1.108 2001/06/19 12:45:23 fvdl 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/malloc.h>
43 1.46 mycroft #include <sys/device.h>
44 1.85 thorpej
45 1.85 thorpej #include <machine/intr.h>
46 1.31 mycroft
47 1.72 cgd #include <dev/isa/isareg.h>
48 1.72 cgd #include <dev/isa/isavar.h>
49 1.95 thorpej #include <dev/isa/isadmareg.h>
50 1.77 cgd
51 1.102 leo #include "isadma.h"
52 1.102 leo
53 1.103 christos #include "isapnp.h"
54 1.108 fvdl #if NISAPNP > 0
55 1.103 christos #include <dev/isapnp/isapnpreg.h>
56 1.103 christos #include <dev/isapnp/isapnpvar.h>
57 1.103 christos #endif
58 1.103 christos
59 1.91 cgd int isamatch __P((struct device *, struct cfdata *, void *));
60 1.77 cgd void isaattach __P((struct device *, struct device *, void *));
61 1.86 cgd int isaprint __P((void *, const char *));
62 1.77 cgd
63 1.79 thorpej struct cfattach isa_ca = {
64 1.79 thorpej sizeof(struct isa_softc), isamatch, isaattach
65 1.79 thorpej };
66 1.79 thorpej
67 1.91 cgd int isasearch __P((struct device *, struct cfdata *, void *));
68 1.91 cgd
69 1.77 cgd int
70 1.91 cgd isamatch(parent, cf, aux)
71 1.77 cgd struct device *parent;
72 1.91 cgd struct cfdata *cf;
73 1.91 cgd void *aux;
74 1.77 cgd {
75 1.77 cgd struct isabus_attach_args *iba = aux;
76 1.77 cgd
77 1.77 cgd if (strcmp(iba->iba_busname, cf->cf_driver->cd_name))
78 1.77 cgd return (0);
79 1.77 cgd
80 1.77 cgd /* XXX check other indicators */
81 1.77 cgd
82 1.77 cgd return (1);
83 1.77 cgd }
84 1.77 cgd
85 1.77 cgd void
86 1.77 cgd isaattach(parent, self, aux)
87 1.77 cgd struct device *parent, *self;
88 1.77 cgd void *aux;
89 1.77 cgd {
90 1.77 cgd struct isa_softc *sc = (struct isa_softc *)self;
91 1.77 cgd struct isabus_attach_args *iba = aux;
92 1.98 thorpej
93 1.80 cgd isa_attach_hook(parent, self, iba);
94 1.88 christos printf("\n");
95 1.77 cgd
96 1.89 thorpej sc->sc_iot = iba->iba_iot;
97 1.89 thorpej sc->sc_memt = iba->iba_memt;
98 1.95 thorpej sc->sc_dmat = iba->iba_dmat;
99 1.80 cgd sc->sc_ic = iba->iba_ic;
100 1.103 christos
101 1.103 christos #if NISAPNP > 0
102 1.103 christos /*
103 1.103 christos * Reset isapnp cards that the bios configured for us
104 1.103 christos */
105 1.103 christos isapnp_isa_attach_hook(sc);
106 1.103 christos #endif
107 1.78 cgd
108 1.102 leo #if NISADMA > 0
109 1.82 thorpej /*
110 1.101 thorpej * Initialize our DMA state.
111 1.95 thorpej */
112 1.101 thorpej isa_dmainit(sc->sc_ic, sc->sc_iot, sc->sc_dmat, self);
113 1.102 leo #endif
114 1.100 drochner
115 1.91 cgd config_search(isasearch, self, NULL);
116 1.77 cgd }
117 1.1 cgd
118 1.46 mycroft int
119 1.46 mycroft isaprint(aux, isa)
120 1.46 mycroft void *aux;
121 1.86 cgd const char *isa;
122 1.46 mycroft {
123 1.46 mycroft struct isa_attach_args *ia = aux;
124 1.46 mycroft
125 1.46 mycroft if (ia->ia_iosize)
126 1.88 christos printf(" port 0x%x", ia->ia_iobase);
127 1.46 mycroft if (ia->ia_iosize > 1)
128 1.88 christos printf("-0x%x", ia->ia_iobase + ia->ia_iosize - 1);
129 1.46 mycroft if (ia->ia_msize)
130 1.88 christos printf(" iomem 0x%x", ia->ia_maddr);
131 1.46 mycroft if (ia->ia_msize > 1)
132 1.88 christos printf("-0x%x", ia->ia_maddr + ia->ia_msize - 1);
133 1.69 mycroft if (ia->ia_irq != IRQUNK)
134 1.88 christos printf(" irq %d", ia->ia_irq);
135 1.69 mycroft if (ia->ia_drq != DRQUNK)
136 1.88 christos printf(" drq %d", ia->ia_drq);
137 1.97 augustss if (ia->ia_drq2 != DRQUNK)
138 1.97 augustss printf(" drq2 %d", ia->ia_drq2);
139 1.71 mycroft return (UNCONF);
140 1.46 mycroft }
141 1.46 mycroft
142 1.94 cgd int
143 1.94 cgd isasearch(parent, cf, aux)
144 1.94 cgd struct device *parent;
145 1.94 cgd struct cfdata *cf;
146 1.94 cgd void *aux;
147 1.94 cgd {
148 1.94 cgd struct isa_softc *sc = (struct isa_softc *)parent;
149 1.94 cgd struct isa_attach_args ia;
150 1.94 cgd int tryagain;
151 1.94 cgd
152 1.94 cgd do {
153 1.94 cgd ia.ia_iot = sc->sc_iot;
154 1.94 cgd ia.ia_memt = sc->sc_memt;
155 1.95 thorpej ia.ia_dmat = sc->sc_dmat;
156 1.94 cgd ia.ia_ic = sc->sc_ic;
157 1.96 jtk ia.ia_iobase = cf->cf_iobase;
158 1.96 jtk ia.ia_iosize = 0x666; /* cf->cf_iosize; */
159 1.96 jtk ia.ia_maddr = cf->cf_maddr;
160 1.96 jtk ia.ia_msize = cf->cf_msize;
161 1.96 jtk ia.ia_irq = cf->cf_irq == 2 ? 9 : cf->cf_irq;
162 1.96 jtk ia.ia_drq = cf->cf_drq;
163 1.97 augustss ia.ia_drq2 = cf->cf_drq2;
164 1.94 cgd
165 1.94 cgd tryagain = 0;
166 1.94 cgd if ((*cf->cf_attach->ca_match)(parent, cf, &ia) > 0) {
167 1.94 cgd config_attach(parent, cf, &ia, isaprint);
168 1.94 cgd tryagain = (cf->cf_fstate == FSTATE_STAR);
169 1.94 cgd }
170 1.94 cgd } while (tryagain);
171 1.94 cgd
172 1.91 cgd return (0);
173 1.72 cgd }
174 1.72 cgd
175 1.72 cgd char *
176 1.72 cgd isa_intr_typename(type)
177 1.75 mycroft int type;
178 1.72 cgd {
179 1.72 cgd
180 1.72 cgd switch (type) {
181 1.75 mycroft case IST_NONE :
182 1.72 cgd return ("none");
183 1.75 mycroft case IST_PULSE:
184 1.72 cgd return ("pulsed");
185 1.75 mycroft case IST_EDGE:
186 1.72 cgd return ("edge-triggered");
187 1.75 mycroft case IST_LEVEL:
188 1.72 cgd return ("level-triggered");
189 1.72 cgd default:
190 1.72 cgd panic("isa_intr_typename: invalid type %d", type);
191 1.72 cgd }
192 1.1 cgd }
193