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