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