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