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