eisa_machdep.c revision 1.22.6.1 1 /* $NetBSD: eisa_machdep.c,v 1.22.6.1 2005/02/12 18:17:34 yamt 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.22.6.1 2005/02/12 18:17:34 yamt 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 _X86_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 x86_bus_dma_tag eisa_bus_dma_tag = {
104 0, /* _bounce_thresh */
105 0, /* _bounce_alloc_lo */
106 0, /* _bounce_alloc_hi */
107 NULL, /* _may_bounce */
108 _bus_dmamap_create,
109 _bus_dmamap_destroy,
110 _bus_dmamap_load,
111 _bus_dmamap_load_mbuf,
112 _bus_dmamap_load_uio,
113 _bus_dmamap_load_raw,
114 _bus_dmamap_unload,
115 NULL, /* _dmamap_sync */
116 _bus_dmamem_alloc,
117 _bus_dmamem_free,
118 _bus_dmamem_map,
119 _bus_dmamem_unmap,
120 _bus_dmamem_mmap,
121 };
122
123 void
124 eisa_attach_hook(struct device *parent, struct device *self,
125 struct eisabus_attach_args *eba)
126 {
127 extern int eisa_has_been_seen;
128
129 /*
130 * Notify others that might need to know that the EISA bus
131 * has now been attached.
132 */
133 if (eisa_has_been_seen)
134 panic("eisaattach: EISA bus already seen!");
135 eisa_has_been_seen = 1;
136 }
137
138 int
139 eisa_maxslots(eisa_chipset_tag_t ec)
140 {
141
142 /*
143 * Always try 16 slots.
144 */
145 return (16);
146 }
147
148 int
149 eisa_intr_map(eisa_chipset_tag_t ec, u_int irq, eisa_intr_handle_t *ihp)
150 {
151 if (irq >= NUM_LEGACY_IRQS) {
152 printf("eisa_intr_map: bad IRQ %d\n", irq);
153 *ihp = -1;
154 return 1;
155 }
156 if (irq == 2) {
157 printf("eisa_intr_map: changed IRQ 2 to IRQ 9\n");
158 irq = 9;
159 }
160
161 #if NIOAPIC > 0
162
163 if (mp_busses != NULL) {
164 if (intr_find_mpmapping(mp_eisa_bus, irq, ihp) == 0 ||
165 intr_find_mpmapping(mp_isa_bus, irq, ihp) == 0) {
166 *ihp |= irq;
167 return 0;
168 } else
169 printf("eisa_intr_map: no MP mapping found\n");
170 }
171 printf("eisa_intr_map: no MP mapping found\n");
172 #endif
173
174 *ihp = irq;
175 return 0;
176 }
177
178 const char *
179 eisa_intr_string(eisa_chipset_tag_t ec, eisa_intr_handle_t ih)
180 {
181 static char irqstr[8]; /* 4 + 2 + NULL + sanity */
182
183 if (ih == 0 || (ih & 0xff) >= NUM_LEGACY_IRQS || ih == 2)
184 panic("eisa_intr_string: bogus handle 0x%x", ih);
185
186 #if NIOAPIC > 0
187 if (ih & APIC_INT_VIA_APIC)
188 snprintf(irqstr, sizeof(irqstr), "apic %d int %d (irq %d)",
189 APIC_IRQ_APIC(ih),
190 APIC_IRQ_PIN(ih),
191 ih&0xff);
192 else
193 snprintf(irqstr, sizeof(irqstr), "irq %d", ih&0xff);
194 #else
195 snprintf(irqstr, sizeof(irqstr), "irq %d", ih);
196 #endif
197 return (irqstr);
198
199 }
200
201 const struct evcnt *
202 eisa_intr_evcnt(eisa_chipset_tag_t ec, eisa_intr_handle_t ih)
203 {
204
205 /* XXX for now, no evcnt parent reported */
206 return NULL;
207 }
208
209 void *
210 eisa_intr_establish(eisa_chipset_tag_t ec, eisa_intr_handle_t ih,
211 int type, int level, int (*func)(void *), void *arg)
212 {
213 int pin, irq;
214 struct pic *pic;
215
216 pic = &i8259_pic;
217 pin = irq = ih;
218
219 #if NIOAPIC > 0
220 if (ih & APIC_INT_VIA_APIC) {
221 pic = (struct pic *)ioapic_find(APIC_IRQ_APIC(ih));
222 if (pic == NULL) {
223 printf("eisa_intr_establish: bad ioapic %d\n",
224 APIC_IRQ_APIC(ih));
225 return NULL;
226 }
227 pin = APIC_IRQ_PIN(ih);
228 irq = APIC_IRQ_LEGACY_IRQ(ih);
229 if (irq < 0 || irq >= NUM_LEGACY_IRQS)
230 irq = -1;
231 }
232 #endif
233
234 return intr_establish(irq, pic, pin, type, level, func, arg);
235 }
236
237 void
238 eisa_intr_disestablish(eisa_chipset_tag_t ec, void *cookie)
239 {
240
241 intr_disestablish(cookie);
242 }
243
244 int
245 eisa_mem_alloc(bus_space_tag_t t, bus_size_t size, bus_size_t align,
246 bus_addr_t boundary, int cacheable,
247 bus_addr_t *addrp, bus_space_handle_t *bahp)
248 {
249 extern struct extent *iomem_ex;
250
251 /*
252 * Allocate physical address space after the ISA hole.
253 */
254 return bus_space_alloc(t, IOM_END, iomem_ex->ex_end, size, align,
255 boundary, cacheable, addrp, bahp);
256 }
257
258 void
259 eisa_mem_free(bus_space_tag_t t, bus_space_handle_t bah, bus_size_t size)
260 {
261
262 bus_space_free(t, bah, size);
263 }
264
265 int
266 eisa_conf_read_mem(eisa_chipset_tag_t ec, int slot, int func, int entry,
267 struct eisa_cfg_mem *ecm)
268 {
269
270 /* XXX XXX XXX */
271 return (ENOENT);
272 }
273
274 int
275 eisa_conf_read_irq(eisa_chipset_tag_t ec, int slot, int func, int entry,
276 struct eisa_cfg_irq *eci)
277 {
278
279 /* XXX XXX XXX */
280 return (ENOENT);
281 }
282
283 int
284 eisa_conf_read_dma(eisa_chipset_tag_t ec, int slot, int func, int entry,
285 struct eisa_cfg_dma *ecd)
286 {
287
288 /* XXX XXX XXX */
289 return (ENOENT);
290 }
291
292 int
293 eisa_conf_read_io(eisa_chipset_tag_t ec, int slot, int func, int entry,
294 struct eisa_cfg_io *ecio)
295 {
296
297 /* XXX XXX XXX */
298 return (ENOENT);
299 }
300