eisa_machdep.c revision 1.17 1 /* $NetBSD: eisa_machdep.c,v 1.17 2002/11/22 15:23:37 fvdl Exp $ */
2
3 /*-
4 * Copyright (c) 1997, 1998 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
9 * NASA Ames Research Center.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
19 * 3. All advertising materials mentioning features or use of this software
20 * must display the following acknowledgement:
21 * This product includes software developed by the NetBSD
22 * Foundation, Inc. and its contributors.
23 * 4. Neither the name of The NetBSD Foundation nor the names of its
24 * contributors may be used to endorse or promote products derived
25 * from this software without specific prior written permission.
26 *
27 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
28 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
29 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
30 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
31 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
32 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
33 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
34 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
35 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
36 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
37 * POSSIBILITY OF SUCH DAMAGE.
38 */
39
40 /*
41 * Copyright (c) 1996 Christopher G. Demetriou. All rights reserved.
42 *
43 * Redistribution and use in source and binary forms, with or without
44 * modification, are permitted provided that the following conditions
45 * are met:
46 * 1. Redistributions of source code must retain the above copyright
47 * notice, this list of conditions and the following disclaimer.
48 * 2. Redistributions in binary form must reproduce the above copyright
49 * notice, this list of conditions and the following disclaimer in the
50 * documentation and/or other materials provided with the distribution.
51 * 3. All advertising materials mentioning features or use of this software
52 * must display the following acknowledgement:
53 * This product includes software developed by Christopher G. Demetriou
54 * for the NetBSD Project.
55 * 4. The name of the author may not be used to endorse or promote products
56 * derived from this software without specific prior written permission
57 *
58 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
59 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
60 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
61 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
62 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
63 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
64 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
65 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
66 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
67 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
68 */
69
70 /*
71 * Machine-specific functions for EISA autoconfiguration.
72 */
73
74 #include <sys/cdefs.h>
75 __KERNEL_RCSID(0, "$NetBSD: eisa_machdep.c,v 1.17 2002/11/22 15:23:37 fvdl Exp $");
76
77 #include "ioapic.h"
78
79 #include <sys/types.h>
80 #include <sys/param.h>
81 #include <sys/time.h>
82 #include <sys/systm.h>
83 #include <sys/errno.h>
84 #include <sys/device.h>
85 #include <sys/extent.h>
86
87 #define _I386_BUS_DMA_PRIVATE
88 #include <machine/bus.h>
89
90 #include <dev/isa/isareg.h>
91 #include <dev/isa/isavar.h>
92 #include <dev/eisa/eisavar.h>
93
94 #if NIOAPIC > 0
95 #include <machine/i82093var.h>
96 #include <machine/mpbiosvar.h>
97 #endif
98
99 /*
100 * EISA doesn't have any special needs; just use the generic versions
101 * of these funcions.
102 */
103 struct i386_bus_dma_tag eisa_bus_dma_tag = {
104 0, /* _bounce_thresh */
105 _bus_dmamap_create,
106 _bus_dmamap_destroy,
107 _bus_dmamap_load,
108 _bus_dmamap_load_mbuf,
109 _bus_dmamap_load_uio,
110 _bus_dmamap_load_raw,
111 _bus_dmamap_unload,
112 NULL, /* _dmamap_sync */
113 _bus_dmamem_alloc,
114 _bus_dmamem_free,
115 _bus_dmamem_map,
116 _bus_dmamem_unmap,
117 _bus_dmamem_mmap,
118 };
119
120 void
121 eisa_attach_hook(parent, self, eba)
122 struct device *parent, *self;
123 struct eisabus_attach_args *eba;
124 {
125 extern int eisa_has_been_seen;
126
127 /*
128 * Notify others that might need to know that the EISA bus
129 * has now been attached.
130 */
131 if (eisa_has_been_seen)
132 panic("eisaattach: EISA bus already seen!");
133 eisa_has_been_seen = 1;
134 }
135
136 int
137 eisa_maxslots(ec)
138 eisa_chipset_tag_t ec;
139 {
140
141 /*
142 * Always try 16 slots.
143 */
144 return (16);
145 }
146
147 int
148 eisa_intr_map(ec, irq, ihp)
149 eisa_chipset_tag_t ec;
150 u_int irq;
151 eisa_intr_handle_t *ihp;
152 {
153 if (irq >= NUM_LEGACY_IRQS) {
154 printf("eisa_intr_map: bad IRQ %d\n", irq);
155 *ihp = -1;
156 return 1;
157 }
158 if (irq == 2) {
159 printf("eisa_intr_map: changed IRQ 2 to IRQ 9\n");
160 irq = 9;
161 }
162
163 #if NIOAPIC > 0
164
165 if (mp_busses != NULL) {
166 if (intr_find_mpmapping(mp_eisa_bus, irq, ihp) == 0 ||
167 intr_find_mpmapping(mp_isa_bus, irq, ihp) == 0) {
168 *ihp |= irq;
169 return 0;
170 } else
171 printf("eisa_intr_map: no MP mapping found\n");
172 }
173 printf("eisa_intr_map: no MP mapping found\n");
174 #endif
175
176 *ihp = irq;
177 return 0;
178 }
179
180 const char *
181 eisa_intr_string(ec, ih)
182 eisa_chipset_tag_t ec;
183 eisa_intr_handle_t ih;
184 {
185 static char irqstr[8]; /* 4 + 2 + NULL + sanity */
186
187 if (ih == 0 || (ih & 0xff) >= NUM_LEGACY_IRQS || ih == 2)
188 panic("eisa_intr_string: bogus handle 0x%x", ih);
189
190 #if NIOAPIC > 0
191 if (ih & APIC_INT_VIA_APIC)
192 sprintf(irqstr, "apic %d int %d (irq %d)",
193 APIC_IRQ_APIC(ih),
194 APIC_IRQ_PIN(ih),
195 ih&0xff);
196 else
197 sprintf(irqstr, "irq %d", ih&0xff);
198 #else
199 sprintf(irqstr, "irq %d", ih);
200 #endif
201 return (irqstr);
202
203 }
204
205 const struct evcnt *
206 eisa_intr_evcnt(eisa_chipset_tag_t ec, eisa_intr_handle_t ih)
207 {
208
209 /* XXX for now, no evcnt parent reported */
210 return NULL;
211 }
212
213 void *
214 eisa_intr_establish(ec, ih, type, level, func, arg)
215 eisa_chipset_tag_t ec;
216 eisa_intr_handle_t ih;
217 int type, level, (*func) __P((void *));
218 void *arg;
219 {
220 int pin, irq;
221 struct pic *pic;
222
223 pic = &i8259_pic;
224 pin = irq = ih;
225
226 #if NIOAPIC > 0
227 if (ih & APIC_INT_VIA_APIC) {
228 pic = (struct pic *)ioapic_find(APIC_IRQ_APIC(ih));
229 if (pic == NULL) {
230 printf("eisa_intr_establish: bad ioapic %d\n",
231 APIC_IRQ_APIC(ih));
232 return NULL;
233 }
234 pin = APIC_IRQ_PIN(ih);
235 irq = APIC_IRQ_LEGACY_IRQ(ih);
236 if (irq < 0 || irq >= NUM_LEGACY_IRQS)
237 irq = -1;
238 }
239 #endif
240
241 return intr_establish(irq, pic, pin, type, level, func, arg);
242 }
243
244 void
245 eisa_intr_disestablish(ec, cookie)
246 eisa_chipset_tag_t ec;
247 void *cookie;
248 {
249
250 intr_disestablish(cookie);
251 }
252
253 int
254 eisa_mem_alloc(t, size, align, boundary, cacheable, addrp, bahp)
255 bus_space_tag_t t;
256 bus_size_t size, align;
257 bus_addr_t boundary;
258 int cacheable;
259 bus_addr_t *addrp;
260 bus_space_handle_t *bahp;
261 {
262 extern struct extent *iomem_ex;
263
264 /*
265 * Allocate physical address space after the ISA hole.
266 */
267 return bus_space_alloc(t, IOM_END, iomem_ex->ex_end, size, align,
268 boundary, cacheable, addrp, bahp);
269 }
270
271 void
272 eisa_mem_free(t, bah, size)
273 bus_space_tag_t t;
274 bus_space_handle_t bah;
275 bus_size_t size;
276 {
277
278 bus_space_free(t, bah, size);
279 }
280
281 int
282 eisa_conf_read_mem(ec, slot, func, entry, ecm)
283 eisa_chipset_tag_t ec;
284 int slot, func, entry;
285 struct eisa_cfg_mem *ecm;
286 {
287
288 /* XXX XXX XXX */
289 return (ENOENT);
290 }
291
292 int
293 eisa_conf_read_irq(ec, slot, func, entry, eci)
294 eisa_chipset_tag_t ec;
295 int slot, func, entry;
296 struct eisa_cfg_irq *eci;
297 {
298
299 /* XXX XXX XXX */
300 return (ENOENT);
301 }
302
303 int
304 eisa_conf_read_dma(ec, slot, func, entry, ecd)
305 eisa_chipset_tag_t ec;
306 int slot, func, entry;
307 struct eisa_cfg_dma *ecd;
308 {
309
310 /* XXX XXX XXX */
311 return (ENOENT);
312 }
313
314 int
315 eisa_conf_read_io(ec, slot, func, entry, ecio)
316 eisa_chipset_tag_t ec;
317 int slot, func, entry;
318 struct eisa_cfg_io *ecio;
319 {
320
321 /* XXX XXX XXX */
322 return (ENOENT);
323 }
324