xref: /openbsd/sys/arch/i386/eisa/eisa_machdep.c (revision cecf84d4)
1 /*	$OpenBSD: eisa_machdep.c,v 1.15 2015/01/24 15:13:55 kettenis Exp $	*/
2 /*	$NetBSD: eisa_machdep.c,v 1.10.22.2 2000/06/25 19:36:58 sommerfeld Exp $	*/
3 
4 /*-
5  * Copyright (c) 1997 The NetBSD Foundation, Inc.
6  * All rights reserved.
7  *
8  * This code is derived from software contributed to The NetBSD Foundation
9  * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
10  * NASA Ames Research Center.
11  *
12  * Redistribution and use in source and binary forms, with or without
13  * modification, are permitted provided that the following conditions
14  * are met:
15  * 1. Redistributions of source code must retain the above copyright
16  *    notice, this list of conditions and the following disclaimer.
17  * 2. Redistributions in binary form must reproduce the above copyright
18  *    notice, this list of conditions and the following disclaimer in the
19  *    documentation and/or other materials provided with the distribution.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
22  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
23  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
25  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31  * POSSIBILITY OF SUCH DAMAGE.
32  */
33 
34 /*
35  * Copyright (c) 1996 Christopher G. Demetriou.  All rights reserved.
36  *
37  * Redistribution and use in source and binary forms, with or without
38  * modification, are permitted provided that the following conditions
39  * are met:
40  * 1. Redistributions of source code must retain the above copyright
41  *    notice, this list of conditions and the following disclaimer.
42  * 2. Redistributions in binary form must reproduce the above copyright
43  *    notice, this list of conditions and the following disclaimer in the
44  *    documentation and/or other materials provided with the distribution.
45  * 3. All advertising materials mentioning features or use of this software
46  *    must display the following acknowledgement:
47  *      This product includes software developed by Christopher G. Demetriou
48  *	for the NetBSD Project.
49  * 4. The name of the author may not be used to endorse or promote products
50  *    derived from this software without specific prior written permission
51  *
52  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
53  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
54  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
55  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
56  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
57  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
58  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
59  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
60  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
61  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
62  */
63 
64 /*
65  * Machine-specific functions for EISA autoconfiguration.
66  */
67 
68 #include <sys/types.h>
69 #include <sys/param.h>
70 #include <sys/time.h>
71 #include <sys/systm.h>
72 #include <sys/errno.h>
73 #include <sys/device.h>
74 
75 #include <machine/bus.h>
76 #include <machine/i8259.h>
77 
78 #include <dev/isa/isavar.h>
79 #include <dev/eisa/eisavar.h>
80 
81 /*
82  * EISA doesn't have any special needs; just use the generic versions
83  * of these funcions.
84  */
85 struct bus_dma_tag eisa_bus_dma_tag = {
86 	NULL,			/* _cookie */
87 	_bus_dmamap_create,
88 	_bus_dmamap_destroy,
89 	_bus_dmamap_load,
90 	_bus_dmamap_load_mbuf,
91 	_bus_dmamap_load_uio,
92 	_bus_dmamap_load_raw,
93 	_bus_dmamap_unload,
94 	_bus_dmamap_sync,
95 	_bus_dmamem_alloc,
96 	_bus_dmamem_alloc_range,
97 	_bus_dmamem_free,
98 	_bus_dmamem_map,
99 	_bus_dmamem_unmap,
100 	_bus_dmamem_mmap,
101 };
102 
103 void
104 eisa_attach_hook(struct device *parent, struct device *self,
105     struct eisabus_attach_args *eba)
106 {
107 	/* Nothing to do */
108 }
109 
110 int
111 eisa_maxslots(eisa_chipset_tag_t ec)
112 {
113 	/*
114 	 * Always try 16 slots.
115 	 */
116 	return (16);
117 }
118 
119 int
120 eisa_intr_map(eisa_chipset_tag_t ec, u_int irq, eisa_intr_handle_t *ihp)
121 {
122 #if NIOAPIC > 0
123 	struct mp_intr_map *mip;
124 #endif
125 
126 	if (irq >= ICU_LEN) {
127 		printf("eisa_intr_map: bad IRQ %d\n", irq);
128 		*ihp = -1;
129 		return (1);
130 	}
131 	if (irq == 2) {
132 		printf("eisa_intr_map: changed IRQ 2 to IRQ 9\n");
133 		irq = 9;
134 	}
135 
136 #if NIOAPIC > 0
137 	if (mp_busses != NULL) {
138 		/*
139 		 * Assumes 1:1 mapping between PCI bus numbers and
140 		 * the numbers given by the MP bios.
141 		 * XXX Is this a valid assumption?
142 		 */
143 
144 		for (mip = mp_busses[bus].mb_intrs; mip != NULL;
145 		    mip = mip->next) {
146 			if (mip->bus_pin == irq) {
147 				*ihp = mip->ioapic_ih | irq;
148 				return (0);
149 			}
150 		}
151 		if (mip == NULL)
152 			printf("eisa_intr_map: no MP mapping found\n");
153 	}
154 #endif
155 
156 	*ihp = irq;
157 	return (0);
158 }
159 
160 const char *
161 eisa_intr_string(eisa_chipset_tag_t ec, eisa_intr_handle_t ih)
162 {
163 	static char irqstr[64];
164 
165 	if (ih == 0 || (ih & 0xff) >= ICU_LEN || ih == 2)
166 		panic("eisa_intr_string: bogus handle 0x%x", ih);
167 
168 #if NIOAPIC > 0
169 	if (ih & APIC_INT_VIA_APIC) {
170 		snprintf(irqstr, sizeof irqstr, "apic %d int %d (irq %d)",
171 		    APIC_IRQ_APIC(ih), APIC_IRQ_PIN(ih), ih & 0xff);
172 		return (irqstr);
173 	}
174 #endif
175 
176 	snprintf(irqstr, sizeof irqstr, "irq %d", ih);
177 	return (irqstr);
178 
179 }
180 
181 void *
182 eisa_intr_establish(eisa_chipset_tag_t ec, eisa_intr_handle_t ih, int type,
183     int level, int (*func)(void *), void *arg, char *what)
184 {
185 #if NIOAPIC > 0
186 	if (ih != -1) {
187 		if (ih != -1 && (ih & APIC_INT_VIA_APIC)) {
188 			return (apic_intr_establish(ih, type, level, func, arg,
189 			    what));
190 		}
191 	}
192 #endif
193 	if (ih == 0 || ih >= ICU_LEN || ih == 2)
194 		panic("eisa_intr_establish: bogus handle 0x%x", ih);
195 
196 	return (isa_intr_establish(NULL, ih, type, level, func, arg, what));
197 }
198 
199 void
200 eisa_intr_disestablish(eisa_chipset_tag_t ec, void *cookie)
201 {
202 	return (isa_intr_disestablish(NULL, cookie));
203 }
204