isa.c revision 1.102 1 /* $NetBSD: isa.c,v 1.102 1998/06/11 08:29:33 leo 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 #include <dev/isa/isadmareg.h>
44
45 #include "isadma.h"
46
47 int isamatch __P((struct device *, struct cfdata *, void *));
48 void isaattach __P((struct device *, struct device *, void *));
49 int isaprint __P((void *, const char *));
50
51 struct cfattach isa_ca = {
52 sizeof(struct isa_softc), isamatch, isaattach
53 };
54
55 int isasearch __P((struct device *, struct cfdata *, void *));
56
57 int
58 isamatch(parent, cf, aux)
59 struct device *parent;
60 struct cfdata *cf;
61 void *aux;
62 {
63 struct isabus_attach_args *iba = aux;
64
65 if (strcmp(iba->iba_busname, cf->cf_driver->cd_name))
66 return (0);
67
68 /* XXX check other indicators */
69
70 return (1);
71 }
72
73 void
74 isaattach(parent, self, aux)
75 struct device *parent, *self;
76 void *aux;
77 {
78 struct isa_softc *sc = (struct isa_softc *)self;
79 struct isabus_attach_args *iba = aux;
80
81 isa_attach_hook(parent, self, iba);
82 printf("\n");
83
84 sc->sc_iot = iba->iba_iot;
85 sc->sc_memt = iba->iba_memt;
86 sc->sc_dmat = iba->iba_dmat;
87 sc->sc_ic = iba->iba_ic;
88
89 #if NISADMA > 0
90 /*
91 * Initialize our DMA state.
92 */
93 isa_dmainit(sc->sc_ic, sc->sc_iot, sc->sc_dmat, self);
94 #endif
95
96 TAILQ_INIT(&sc->sc_subdevs);
97
98 config_search(isasearch, self, NULL);
99 }
100
101 int
102 isaprint(aux, isa)
103 void *aux;
104 const char *isa;
105 {
106 struct isa_attach_args *ia = aux;
107
108 if (ia->ia_iosize)
109 printf(" port 0x%x", ia->ia_iobase);
110 if (ia->ia_iosize > 1)
111 printf("-0x%x", ia->ia_iobase + ia->ia_iosize - 1);
112 if (ia->ia_msize)
113 printf(" iomem 0x%x", ia->ia_maddr);
114 if (ia->ia_msize > 1)
115 printf("-0x%x", ia->ia_maddr + ia->ia_msize - 1);
116 if (ia->ia_irq != IRQUNK)
117 printf(" irq %d", ia->ia_irq);
118 if (ia->ia_drq != DRQUNK)
119 printf(" drq %d", ia->ia_drq);
120 if (ia->ia_drq2 != DRQUNK)
121 printf(" drq2 %d", ia->ia_drq2);
122 return (UNCONF);
123 }
124
125 int
126 isasearch(parent, cf, aux)
127 struct device *parent;
128 struct cfdata *cf;
129 void *aux;
130 {
131 struct isa_softc *sc = (struct isa_softc *)parent;
132 struct isa_attach_args ia;
133 int tryagain;
134
135 do {
136 ia.ia_iot = sc->sc_iot;
137 ia.ia_memt = sc->sc_memt;
138 ia.ia_dmat = sc->sc_dmat;
139 ia.ia_ic = sc->sc_ic;
140 ia.ia_iobase = cf->cf_iobase;
141 ia.ia_iosize = 0x666; /* cf->cf_iosize; */
142 ia.ia_maddr = cf->cf_maddr;
143 ia.ia_msize = cf->cf_msize;
144 ia.ia_irq = cf->cf_irq == 2 ? 9 : cf->cf_irq;
145 ia.ia_drq = cf->cf_drq;
146 ia.ia_drq2 = cf->cf_drq2;
147
148 tryagain = 0;
149 if ((*cf->cf_attach->ca_match)(parent, cf, &ia) > 0) {
150 config_attach(parent, cf, &ia, isaprint);
151 tryagain = (cf->cf_fstate == FSTATE_STAR);
152 }
153 } while (tryagain);
154
155 return (0);
156 }
157
158 char *
159 isa_intr_typename(type)
160 int type;
161 {
162
163 switch (type) {
164 case IST_NONE :
165 return ("none");
166 case IST_PULSE:
167 return ("pulsed");
168 case IST_EDGE:
169 return ("edge-triggered");
170 case IST_LEVEL:
171 return ("level-triggered");
172 default:
173 panic("isa_intr_typename: invalid type %d", type);
174 }
175 }
176