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