Home | History | Annotate | Line # | Download | only in eisa
eisa_machdep.c revision 1.32.10.2
      1 /*	$NetBSD: eisa_machdep.c,v 1.32.10.2 2011/08/27 15:37:24 jym 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.32.10.2 2011/08/27 15:37:24 jym 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 funcions.
     94  */
     95 struct x86_bus_dma_tag eisa_bus_dma_tag = {
     96 	._tag_needs_free	= 0,
     97 	._bounce_thresh		= 0,
     98 	._bounce_alloc_lo	= 0,
     99 	._bounce_alloc_hi	= 0,
    100 	._may_bounce		= NULL,
    101 
    102 	._dmamap_create		= _bus_dmamap_create,
    103 	._dmamap_destroy	= _bus_dmamap_destroy,
    104 	._dmamap_load		= _bus_dmamap_load,
    105 	._dmamap_load_mbuf	= _bus_dmamap_load_mbuf,
    106 	._dmamap_load_uio	= _bus_dmamap_load_uio,
    107 	._dmamap_load_raw	= _bus_dmamap_load_raw,
    108 	._dmamap_unload		= _bus_dmamap_unload,
    109 	._dmamap_sync 		= NULL,
    110 
    111 	._dmamem_alloc		= _bus_dmamem_alloc,
    112 	._dmamem_free		= _bus_dmamem_free,
    113 	._dmamem_map		= _bus_dmamem_map,
    114 	._dmamem_unmap		= _bus_dmamem_unmap,
    115 	._dmamem_mmap		= _bus_dmamem_mmap,
    116 
    117 	._dmatag_subregion	= _bus_dmatag_subregion,
    118 	._dmatag_destroy	= _bus_dmatag_destroy,
    119 };
    120 
    121 void
    122 eisa_attach_hook(device_t parent, device_t self,
    123     struct eisabus_attach_args *eba)
    124 {
    125 	extern int eisa_has_been_seen;
    126 
    127 	/*
    128 	 * Notify others that might need to know that the EISA bus
    129 	 * has now been attached.
    130 	 */
    131 	if (eisa_has_been_seen)
    132 		panic("eisaattach: EISA bus already seen!");
    133 	eisa_has_been_seen = 1;
    134 }
    135 
    136 int
    137 eisa_maxslots(eisa_chipset_tag_t ec)
    138 {
    139 
    140 	/*
    141 	 * Always try 16 slots.
    142 	 */
    143 	return (16);
    144 }
    145 
    146 int
    147 eisa_intr_map(eisa_chipset_tag_t ec, u_int irq,
    148     eisa_intr_handle_t *ihp)
    149 {
    150 	if (irq >= NUM_LEGACY_IRQS) {
    151 		aprint_error("eisa_intr_map: bad IRQ %d\n", irq);
    152 		*ihp = -1;
    153 		return 1;
    154 	}
    155 	if (irq == 2) {
    156 		aprint_verbose("eisa_intr_map: changed IRQ 2 to IRQ 9\n");
    157 		irq = 9;
    158 	}
    159 
    160 #if NIOAPIC > 0
    161 	if (mp_busses != NULL) {
    162 		if (intr_find_mpmapping(mp_eisa_bus, irq, ihp) == 0 ||
    163 		    intr_find_mpmapping(mp_isa_bus, irq, ihp) == 0) {
    164 			*ihp |= irq;
    165 			return 0;
    166 		} else
    167 			aprint_verbose("eisa_intr_map: no MP mapping found\n");
    168 	}
    169 #endif
    170 
    171 	*ihp = irq;
    172 	return 0;
    173 }
    174 
    175 const char *
    176 eisa_intr_string(eisa_chipset_tag_t ec, eisa_intr_handle_t ih)
    177 {
    178 	static char irqstr[8];		/* 4 + 2 + NULL + sanity */
    179 
    180 	if (ih == 0 || (ih & 0xff) >= NUM_LEGACY_IRQS || ih == 2)
    181 		panic("eisa_intr_string: bogus handle 0x%x", ih);
    182 
    183 #if NIOAPIC > 0
    184 	if (ih & APIC_INT_VIA_APIC)
    185 		snprintf(irqstr, sizeof(irqstr), "apic %d int %d (irq %d)",
    186 		    APIC_IRQ_APIC(ih),
    187 		    APIC_IRQ_PIN(ih),
    188 		    ih&0xff);
    189 	else
    190 		snprintf(irqstr, sizeof(irqstr), "irq %d", ih&0xff);
    191 #else
    192 	snprintf(irqstr, sizeof(irqstr), "irq %d", ih);
    193 #endif
    194 	return (irqstr);
    195 
    196 }
    197 
    198 const struct evcnt *
    199 eisa_intr_evcnt(eisa_chipset_tag_t ec, eisa_intr_handle_t ih)
    200 {
    201 
    202 	/* XXX for now, no evcnt parent reported */
    203 	return NULL;
    204 }
    205 
    206 void *
    207 eisa_intr_establish(eisa_chipset_tag_t ec, eisa_intr_handle_t ih,
    208     int type, int level, int (*func)(void *), void *arg)
    209 {
    210 	int pin, irq;
    211 	struct pic *pic;
    212 
    213 	pic = &i8259_pic;
    214 	pin = irq = ih;
    215 
    216 #if NIOAPIC > 0
    217 	if (ih & APIC_INT_VIA_APIC) {
    218 		pic = (struct pic *)ioapic_find(APIC_IRQ_APIC(ih));
    219 		if (pic == NULL) {
    220 			aprint_error("eisa_intr_establish: bad ioapic %d\n",
    221 			    APIC_IRQ_APIC(ih));
    222 			return NULL;
    223 		}
    224 		pin = APIC_IRQ_PIN(ih);
    225 		irq = APIC_IRQ_LEGACY_IRQ(ih);
    226 		if (irq < 0 || irq >= NUM_LEGACY_IRQS)
    227 			irq = -1;
    228 	}
    229 #endif
    230 
    231 	return intr_establish(irq, pic, pin, type, level, func, arg, false);
    232 }
    233 
    234 void
    235 eisa_intr_disestablish(eisa_chipset_tag_t ec, void *cookie)
    236 {
    237 
    238 	intr_disestablish(cookie);
    239 }
    240 
    241 int
    242 eisa_conf_read_mem(eisa_chipset_tag_t ec, int slot,
    243     int func, int entry, struct eisa_cfg_mem *ecm)
    244 {
    245 
    246 	/* XXX XXX XXX */
    247 	return (ENOENT);
    248 }
    249 
    250 int
    251 eisa_conf_read_irq(eisa_chipset_tag_t ec, int slot,
    252     int func, int entry, struct eisa_cfg_irq *eci)
    253 {
    254 
    255 	/* XXX XXX XXX */
    256 	return (ENOENT);
    257 }
    258 
    259 int
    260 eisa_conf_read_dma(eisa_chipset_tag_t ec, int slot,
    261     int func, int entry, struct eisa_cfg_dma *ecd)
    262 {
    263 
    264 	/* XXX XXX XXX */
    265 	return (ENOENT);
    266 }
    267 
    268 int
    269 eisa_conf_read_io(eisa_chipset_tag_t ec, int slot,
    270     int func, int entry, struct eisa_cfg_io *ecio)
    271 {
    272 
    273 	/* XXX XXX XXX */
    274 	return (ENOENT);
    275 }
    276