eisa_machdep.c revision 1.25.2.1 1 /* $NetBSD: eisa_machdep.c,v 1.25.2.1 2006/03/01 09:27:55 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.25.2.1 2006/03/01 09:27:55 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 #include <machine/bus.h>
88 #include <machine/bus_private.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 aprint_error("eisa_intr_map: bad IRQ %d\n", irq);
153 *ihp = -1;
154 return 1;
155 }
156 if (irq == 2) {
157 aprint_verbose("eisa_intr_map: changed IRQ 2 to IRQ 9\n");
158 irq = 9;
159 }
160
161 #if NIOAPIC > 0
162 if (mp_busses != NULL) {
163 if (intr_find_mpmapping(mp_eisa_bus, irq, ihp) == 0 ||
164 intr_find_mpmapping(mp_isa_bus, irq, ihp) == 0) {
165 *ihp |= irq;
166 return 0;
167 } else
168 aprint_verbose("eisa_intr_map: no MP mapping found\n");
169 }
170 #endif
171
172 *ihp = irq;
173 return 0;
174 }
175
176 const char *
177 eisa_intr_string(eisa_chipset_tag_t ec, eisa_intr_handle_t ih)
178 {
179 static char irqstr[8]; /* 4 + 2 + NULL + sanity */
180
181 if (ih == 0 || (ih & 0xff) >= NUM_LEGACY_IRQS || ih == 2)
182 panic("eisa_intr_string: bogus handle 0x%x", ih);
183
184 #if NIOAPIC > 0
185 if (ih & APIC_INT_VIA_APIC)
186 snprintf(irqstr, sizeof(irqstr), "apic %d int %d (irq %d)",
187 APIC_IRQ_APIC(ih),
188 APIC_IRQ_PIN(ih),
189 ih&0xff);
190 else
191 snprintf(irqstr, sizeof(irqstr), "irq %d", ih&0xff);
192 #else
193 snprintf(irqstr, sizeof(irqstr), "irq %d", ih);
194 #endif
195 return (irqstr);
196
197 }
198
199 const struct evcnt *
200 eisa_intr_evcnt(eisa_chipset_tag_t ec, eisa_intr_handle_t ih)
201 {
202
203 /* XXX for now, no evcnt parent reported */
204 return NULL;
205 }
206
207 void *
208 eisa_intr_establish(eisa_chipset_tag_t ec, eisa_intr_handle_t ih,
209 int type, int level, int (*func)(void *), void *arg)
210 {
211 int pin, irq;
212 struct pic *pic;
213
214 pic = &i8259_pic;
215 pin = irq = ih;
216
217 #if NIOAPIC > 0
218 if (ih & APIC_INT_VIA_APIC) {
219 pic = (struct pic *)ioapic_find(APIC_IRQ_APIC(ih));
220 if (pic == NULL) {
221 aprint_error("eisa_intr_establish: bad ioapic %d\n",
222 APIC_IRQ_APIC(ih));
223 return NULL;
224 }
225 pin = APIC_IRQ_PIN(ih);
226 irq = APIC_IRQ_LEGACY_IRQ(ih);
227 if (irq < 0 || irq >= NUM_LEGACY_IRQS)
228 irq = -1;
229 }
230 #endif
231
232 return intr_establish(irq, pic, pin, type, level, func, arg);
233 }
234
235 void
236 eisa_intr_disestablish(eisa_chipset_tag_t ec, void *cookie)
237 {
238
239 intr_disestablish(cookie);
240 }
241
242 int
243 eisa_mem_alloc(bus_space_tag_t t, bus_size_t size, bus_size_t align,
244 bus_addr_t boundary, int cacheable,
245 bus_addr_t *addrp, bus_space_handle_t *bahp)
246 {
247 extern struct extent *iomem_ex;
248
249 /*
250 * Allocate physical address space after the ISA hole.
251 */
252 return bus_space_alloc(t, IOM_END, iomem_ex->ex_end, size, align,
253 boundary, cacheable, addrp, bahp);
254 }
255
256 void
257 eisa_mem_free(bus_space_tag_t t, bus_space_handle_t bah, bus_size_t size)
258 {
259
260 bus_space_free(t, bah, size);
261 }
262
263 int
264 eisa_conf_read_mem(eisa_chipset_tag_t ec, int slot, int func, int entry,
265 struct eisa_cfg_mem *ecm)
266 {
267
268 /* XXX XXX XXX */
269 return (ENOENT);
270 }
271
272 int
273 eisa_conf_read_irq(eisa_chipset_tag_t ec, int slot, int func, int entry,
274 struct eisa_cfg_irq *eci)
275 {
276
277 /* XXX XXX XXX */
278 return (ENOENT);
279 }
280
281 int
282 eisa_conf_read_dma(eisa_chipset_tag_t ec, int slot, int func, int entry,
283 struct eisa_cfg_dma *ecd)
284 {
285
286 /* XXX XXX XXX */
287 return (ENOENT);
288 }
289
290 int
291 eisa_conf_read_io(eisa_chipset_tag_t ec, int slot, int func, int entry,
292 struct eisa_cfg_io *ecio)
293 {
294
295 /* XXX XXX XXX */
296 return (ENOENT);
297 }
298