eisa_machdep.c revision 1.41
1/*	$NetBSD: eisa_machdep.c,v 1.41 2022/06/18 22:11:00 andvar 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.41 2022/06/18 22:11:00 andvar 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
79#include <sys/bus.h>
80#include <machine/bus_private.h>
81
82#include <dev/isa/isareg.h>
83#include <dev/isa/isavar.h>
84#include <dev/eisa/eisavar.h>
85
86#if NIOAPIC > 0
87#include <machine/i82093var.h>
88#include <machine/mpbiosvar.h>
89#endif
90
91/*
92 * EISA doesn't have any special needs; just use the generic versions
93 * of these functions.
94 *
95 * XXX really doesn't use bounce buffers? --dyoung
96 */
97struct x86_bus_dma_tag eisa_bus_dma_tag = {
98	._tag_needs_free	= 0,
99	._bounce_thresh		= 0,
100	._bounce_alloc_lo	= 0,
101	._bounce_alloc_hi	= 0,
102	._may_bounce		= NULL,
103};
104
105void
106eisa_attach_hook(device_t parent, device_t self,
107    struct eisabus_attach_args *eba)
108{
109	extern int eisa_has_been_seen;
110
111	/*
112	 * Notify others that might need to know that the EISA bus
113	 * has now been attached.
114	 */
115	if (eisa_has_been_seen)
116		panic("eisaattach: EISA bus already seen!");
117	eisa_has_been_seen = 1;
118}
119
120int
121eisa_maxslots(eisa_chipset_tag_t ec)
122{
123
124	/*
125	 * Always try 16 slots.
126	 */
127	return (16);
128}
129
130int
131eisa_intr_map(eisa_chipset_tag_t ec, u_int irq,
132    eisa_intr_handle_t *ihp)
133{
134	if (irq >= NUM_LEGACY_IRQS) {
135		aprint_error("eisa_intr_map: bad IRQ %d\n", irq);
136		*ihp = -1;
137		return 1;
138	}
139	if (irq == 2) {
140		aprint_verbose("eisa_intr_map: changed IRQ 2 to IRQ 9\n");
141		irq = 9;
142	}
143
144#if NIOAPIC > 0
145	if (mp_busses != NULL) {
146		if (intr_find_mpmapping(mp_eisa_bus, irq, ihp) == 0 ||
147		    intr_find_mpmapping(mp_isa_bus, irq, ihp) == 0) {
148			*ihp |= irq;
149			return 0;
150		} else
151			aprint_verbose("eisa_intr_map: no MP mapping found\n");
152	}
153#endif
154
155	*ihp = irq;
156	return 0;
157}
158
159const char *
160eisa_intr_string(eisa_chipset_tag_t ec, eisa_intr_handle_t ih, char *buf,
161    size_t len)
162{
163	if (ih == 0 || APIC_IRQ_LEGACY_IRQ(ih) >= NUM_LEGACY_IRQS || ih == 2)
164		panic("eisa_intr_string: bogus handle 0x%" PRIx64, ih);
165
166#if NIOAPIC > 0
167	if (ih & APIC_INT_VIA_APIC)
168		snprintf(buf, len, "apic %d int %d (irq %d)",
169		    APIC_IRQ_APIC(ih),
170		    APIC_IRQ_PIN(ih),
171		    APIC_IRQ_LEGACY_IRQ(ih));
172	else
173		snprintf(buf, len, "irq %d",  APIC_IRQ_LEGACY_IRQ(ih));
174#else
175	snprintf(buf, len, "irq %d", APIC_IRQ_LEGACY_IRQ(ih));
176#endif
177	return buf;
178}
179
180const struct evcnt *
181eisa_intr_evcnt(eisa_chipset_tag_t ec, eisa_intr_handle_t ih)
182{
183
184	/* XXX for now, no evcnt parent reported */
185	return NULL;
186}
187
188void *
189eisa_intr_establish(eisa_chipset_tag_t ec, eisa_intr_handle_t ih,
190    int type, int level, int (*func)(void *), void *arg)
191{
192	int pin, irq;
193	struct pic *pic;
194
195	pic = &i8259_pic;
196	pin = irq = ih;
197
198#if NIOAPIC > 0
199	if (ih & APIC_INT_VIA_APIC) {
200		struct ioapic_softc * const ioapic = ioapic_find(APIC_IRQ_APIC(ih));
201		if (ioapic == NULL) {
202			aprint_normal("eisa_intr_establish: bad ioapic %d\n",
203			    APIC_IRQ_APIC(ih));
204			return NULL;
205		}
206		pic = &ioapic->sc_pic;
207		pin = APIC_IRQ_PIN(ih);
208		irq = APIC_IRQ_LEGACY_IRQ(ih);
209		if (irq < 0 || irq >= NUM_LEGACY_IRQS)
210			irq = -1;
211	}
212#endif
213
214	return intr_establish(irq, pic, pin, type, level, func, arg, false);
215}
216
217void
218eisa_intr_disestablish(eisa_chipset_tag_t ec, void *cookie)
219{
220
221	intr_disestablish(cookie);
222}
223
224int
225eisa_conf_read_mem(eisa_chipset_tag_t ec, int slot,
226    int func, int entry, struct eisa_cfg_mem *ecm)
227{
228
229	/* XXX XXX XXX */
230	return (ENOENT);
231}
232
233int
234eisa_conf_read_irq(eisa_chipset_tag_t ec, int slot,
235    int func, int entry, struct eisa_cfg_irq *eci)
236{
237
238	/* XXX XXX XXX */
239	return (ENOENT);
240}
241
242int
243eisa_conf_read_dma(eisa_chipset_tag_t ec, int slot,
244    int func, int entry, struct eisa_cfg_dma *ecd)
245{
246
247	/* XXX XXX XXX */
248	return (ENOENT);
249}
250
251int
252eisa_conf_read_io(eisa_chipset_tag_t ec, int slot,
253    int func, int entry, struct eisa_cfg_io *ecio)
254{
255
256	/* XXX XXX XXX */
257	return (ENOENT);
258}
259