Home | History | Annotate | Line # | Download | only in eisa
eisa_machdep.c revision 1.19
      1  1.19      fvdl /*	$NetBSD: eisa_machdep.c,v 1.19 2003/05/08 12:05:34 fvdl Exp $	*/
      2   1.6   thorpej 
      3   1.6   thorpej /*-
      4   1.7   thorpej  * Copyright (c) 1997, 1998 The NetBSD Foundation, Inc.
      5   1.6   thorpej  * All rights reserved.
      6   1.6   thorpej  *
      7   1.6   thorpej  * This code is derived from software contributed to The NetBSD Foundation
      8   1.6   thorpej  * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
      9   1.6   thorpej  * NASA Ames Research Center.
     10   1.6   thorpej  *
     11   1.6   thorpej  * Redistribution and use in source and binary forms, with or without
     12   1.6   thorpej  * modification, are permitted provided that the following conditions
     13   1.6   thorpej  * are met:
     14   1.6   thorpej  * 1. Redistributions of source code must retain the above copyright
     15   1.6   thorpej  *    notice, this list of conditions and the following disclaimer.
     16   1.6   thorpej  * 2. Redistributions in binary form must reproduce the above copyright
     17   1.6   thorpej  *    notice, this list of conditions and the following disclaimer in the
     18   1.6   thorpej  *    documentation and/or other materials provided with the distribution.
     19   1.6   thorpej  * 3. All advertising materials mentioning features or use of this software
     20   1.6   thorpej  *    must display the following acknowledgement:
     21   1.6   thorpej  *	This product includes software developed by the NetBSD
     22   1.6   thorpej  *	Foundation, Inc. and its contributors.
     23   1.6   thorpej  * 4. Neither the name of The NetBSD Foundation nor the names of its
     24   1.6   thorpej  *    contributors may be used to endorse or promote products derived
     25   1.6   thorpej  *    from this software without specific prior written permission.
     26   1.6   thorpej  *
     27   1.6   thorpej  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     28   1.6   thorpej  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     29   1.6   thorpej  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     30   1.6   thorpej  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     31   1.6   thorpej  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     32   1.6   thorpej  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     33   1.6   thorpej  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     34   1.6   thorpej  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     35   1.6   thorpej  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     36   1.6   thorpej  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     37   1.6   thorpej  * POSSIBILITY OF SUCH DAMAGE.
     38   1.6   thorpej  */
     39   1.1       cgd 
     40   1.1       cgd /*
     41   1.1       cgd  * Copyright (c) 1996 Christopher G. Demetriou.  All rights reserved.
     42   1.1       cgd  *
     43   1.1       cgd  * Redistribution and use in source and binary forms, with or without
     44   1.1       cgd  * modification, are permitted provided that the following conditions
     45   1.1       cgd  * are met:
     46   1.1       cgd  * 1. Redistributions of source code must retain the above copyright
     47   1.1       cgd  *    notice, this list of conditions and the following disclaimer.
     48   1.1       cgd  * 2. Redistributions in binary form must reproduce the above copyright
     49   1.1       cgd  *    notice, this list of conditions and the following disclaimer in the
     50   1.1       cgd  *    documentation and/or other materials provided with the distribution.
     51   1.1       cgd  * 3. All advertising materials mentioning features or use of this software
     52   1.1       cgd  *    must display the following acknowledgement:
     53   1.1       cgd  *      This product includes software developed by Christopher G. Demetriou
     54   1.1       cgd  *	for the NetBSD Project.
     55   1.1       cgd  * 4. The name of the author may not be used to endorse or promote products
     56   1.1       cgd  *    derived from this software without specific prior written permission
     57   1.1       cgd  *
     58   1.1       cgd  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     59   1.1       cgd  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     60   1.1       cgd  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     61   1.1       cgd  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     62   1.1       cgd  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     63   1.1       cgd  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     64   1.1       cgd  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     65   1.1       cgd  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     66   1.1       cgd  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     67   1.1       cgd  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     68   1.1       cgd  */
     69   1.1       cgd 
     70   1.1       cgd /*
     71   1.1       cgd  * Machine-specific functions for EISA autoconfiguration.
     72   1.1       cgd  */
     73  1.14     lukem 
     74  1.14     lukem #include <sys/cdefs.h>
     75  1.19      fvdl __KERNEL_RCSID(0, "$NetBSD: eisa_machdep.c,v 1.19 2003/05/08 12:05:34 fvdl Exp $");
     76  1.16      fvdl 
     77  1.16      fvdl #include "ioapic.h"
     78   1.1       cgd 
     79   1.1       cgd #include <sys/types.h>
     80   1.1       cgd #include <sys/param.h>
     81   1.1       cgd #include <sys/time.h>
     82   1.1       cgd #include <sys/systm.h>
     83   1.1       cgd #include <sys/errno.h>
     84   1.1       cgd #include <sys/device.h>
     85   1.5   thorpej #include <sys/extent.h>
     86   1.1       cgd 
     87  1.18      fvdl #define _X86_BUS_DMA_PRIVATE
     88   1.6   thorpej #include <machine/bus.h>
     89   1.6   thorpej 
     90   1.5   thorpej #include <dev/isa/isareg.h>
     91   1.1       cgd #include <dev/isa/isavar.h>
     92   1.1       cgd #include <dev/eisa/eisavar.h>
     93   1.1       cgd 
     94  1.16      fvdl #if NIOAPIC > 0
     95  1.16      fvdl #include <machine/i82093var.h>
     96  1.16      fvdl #include <machine/mpbiosvar.h>
     97  1.16      fvdl #endif
     98  1.16      fvdl 
     99   1.6   thorpej /*
    100   1.6   thorpej  * EISA doesn't have any special needs; just use the generic versions
    101   1.6   thorpej  * of these funcions.
    102   1.6   thorpej  */
    103  1.18      fvdl struct x86_bus_dma_tag eisa_bus_dma_tag = {
    104  1.10   thorpej 	0,			/* _bounce_thresh */
    105  1.19      fvdl 	0,			/* _bounce_alloc_lo */
    106  1.19      fvdl 	0,			/* _bounce_alloc_hi */
    107  1.19      fvdl 	NULL,			/* _may_bounce */
    108   1.6   thorpej 	_bus_dmamap_create,
    109   1.6   thorpej 	_bus_dmamap_destroy,
    110   1.6   thorpej 	_bus_dmamap_load,
    111   1.6   thorpej 	_bus_dmamap_load_mbuf,
    112   1.6   thorpej 	_bus_dmamap_load_uio,
    113   1.6   thorpej 	_bus_dmamap_load_raw,
    114   1.6   thorpej 	_bus_dmamap_unload,
    115   1.6   thorpej 	NULL,			/* _dmamap_sync */
    116   1.6   thorpej 	_bus_dmamem_alloc,
    117   1.6   thorpej 	_bus_dmamem_free,
    118   1.6   thorpej 	_bus_dmamem_map,
    119   1.6   thorpej 	_bus_dmamem_unmap,
    120   1.6   thorpej 	_bus_dmamem_mmap,
    121   1.6   thorpej };
    122   1.6   thorpej 
    123   1.1       cgd void
    124   1.1       cgd eisa_attach_hook(parent, self, eba)
    125   1.1       cgd 	struct device *parent, *self;
    126   1.1       cgd 	struct eisabus_attach_args *eba;
    127   1.1       cgd {
    128   1.7   thorpej 	extern int eisa_has_been_seen;
    129   1.1       cgd 
    130   1.7   thorpej 	/*
    131   1.8   thorpej 	 * Notify others that might need to know that the EISA bus
    132   1.7   thorpej 	 * has now been attached.
    133   1.7   thorpej 	 */
    134   1.7   thorpej 	if (eisa_has_been_seen)
    135   1.7   thorpej 		panic("eisaattach: EISA bus already seen!");
    136   1.7   thorpej 	eisa_has_been_seen = 1;
    137   1.1       cgd }
    138   1.1       cgd 
    139   1.1       cgd int
    140   1.1       cgd eisa_maxslots(ec)
    141   1.1       cgd 	eisa_chipset_tag_t ec;
    142   1.1       cgd {
    143   1.1       cgd 
    144   1.1       cgd 	/*
    145   1.1       cgd 	 * Always try 16 slots.
    146   1.1       cgd 	 */
    147   1.1       cgd 	return (16);
    148   1.1       cgd }
    149   1.1       cgd 
    150   1.1       cgd int
    151   1.1       cgd eisa_intr_map(ec, irq, ihp)
    152   1.1       cgd 	eisa_chipset_tag_t ec;
    153   1.1       cgd 	u_int irq;
    154   1.1       cgd 	eisa_intr_handle_t *ihp;
    155   1.1       cgd {
    156  1.17      fvdl 	if (irq >= NUM_LEGACY_IRQS) {
    157   1.4  christos 		printf("eisa_intr_map: bad IRQ %d\n", irq);
    158   1.1       cgd 		*ihp = -1;
    159   1.1       cgd 		return 1;
    160   1.1       cgd 	}
    161   1.1       cgd 	if (irq == 2) {
    162   1.4  christos 		printf("eisa_intr_map: changed IRQ 2 to IRQ 9\n");
    163   1.1       cgd 		irq = 9;
    164   1.1       cgd 	}
    165   1.1       cgd 
    166  1.16      fvdl #if NIOAPIC > 0
    167  1.17      fvdl 
    168  1.16      fvdl 	if (mp_busses != NULL) {
    169  1.17      fvdl 		if (intr_find_mpmapping(mp_eisa_bus, irq, ihp) == 0 ||
    170  1.17      fvdl 		    intr_find_mpmapping(mp_isa_bus, irq, ihp) == 0) {
    171  1.17      fvdl 			*ihp |= irq;
    172  1.17      fvdl 			return 0;
    173  1.17      fvdl 		} else
    174  1.17      fvdl 			printf("eisa_intr_map: no MP mapping found\n");
    175  1.16      fvdl 	}
    176  1.17      fvdl 	printf("eisa_intr_map: no MP mapping found\n");
    177  1.16      fvdl #endif
    178  1.16      fvdl 
    179   1.1       cgd 	*ihp = irq;
    180   1.1       cgd 	return 0;
    181   1.1       cgd }
    182   1.1       cgd 
    183   1.1       cgd const char *
    184   1.1       cgd eisa_intr_string(ec, ih)
    185   1.1       cgd 	eisa_chipset_tag_t ec;
    186   1.1       cgd 	eisa_intr_handle_t ih;
    187   1.1       cgd {
    188   1.1       cgd 	static char irqstr[8];		/* 4 + 2 + NULL + sanity */
    189   1.1       cgd 
    190  1.17      fvdl 	if (ih == 0 || (ih & 0xff) >= NUM_LEGACY_IRQS || ih == 2)
    191  1.15    provos 		panic("eisa_intr_string: bogus handle 0x%x", ih);
    192   1.1       cgd 
    193  1.16      fvdl #if NIOAPIC > 0
    194  1.16      fvdl 	if (ih & APIC_INT_VIA_APIC)
    195  1.16      fvdl 		sprintf(irqstr, "apic %d int %d (irq %d)",
    196  1.16      fvdl 		    APIC_IRQ_APIC(ih),
    197  1.16      fvdl 		    APIC_IRQ_PIN(ih),
    198  1.16      fvdl 		    ih&0xff);
    199  1.16      fvdl 	else
    200  1.16      fvdl 		sprintf(irqstr, "irq %d", ih&0xff);
    201  1.16      fvdl #else
    202   1.4  christos 	sprintf(irqstr, "irq %d", ih);
    203  1.16      fvdl #endif
    204   1.1       cgd 	return (irqstr);
    205   1.1       cgd 
    206  1.11       cgd }
    207  1.11       cgd 
    208  1.11       cgd const struct evcnt *
    209  1.11       cgd eisa_intr_evcnt(eisa_chipset_tag_t ec, eisa_intr_handle_t ih)
    210  1.11       cgd {
    211  1.11       cgd 
    212  1.11       cgd 	/* XXX for now, no evcnt parent reported */
    213  1.11       cgd 	return NULL;
    214   1.1       cgd }
    215   1.1       cgd 
    216   1.1       cgd void *
    217   1.1       cgd eisa_intr_establish(ec, ih, type, level, func, arg)
    218   1.1       cgd 	eisa_chipset_tag_t ec;
    219   1.1       cgd 	eisa_intr_handle_t ih;
    220   1.1       cgd 	int type, level, (*func) __P((void *));
    221   1.1       cgd 	void *arg;
    222   1.1       cgd {
    223  1.17      fvdl 	int pin, irq;
    224  1.17      fvdl 	struct pic *pic;
    225  1.17      fvdl 
    226  1.17      fvdl 	pic = &i8259_pic;
    227  1.17      fvdl 	pin = irq = ih;
    228  1.17      fvdl 
    229  1.16      fvdl #if NIOAPIC > 0
    230  1.17      fvdl 	if (ih & APIC_INT_VIA_APIC) {
    231  1.17      fvdl 		pic = (struct pic *)ioapic_find(APIC_IRQ_APIC(ih));
    232  1.17      fvdl 		if (pic == NULL) {
    233  1.17      fvdl 			printf("eisa_intr_establish: bad ioapic %d\n",
    234  1.17      fvdl 			    APIC_IRQ_APIC(ih));
    235  1.17      fvdl 			return NULL;
    236  1.16      fvdl 		}
    237  1.17      fvdl 		pin = APIC_IRQ_PIN(ih);
    238  1.17      fvdl 		irq = APIC_IRQ_LEGACY_IRQ(ih);
    239  1.17      fvdl 		if (irq < 0 || irq >= NUM_LEGACY_IRQS)
    240  1.17      fvdl 			irq = -1;
    241  1.17      fvdl 	}
    242  1.16      fvdl #endif
    243   1.1       cgd 
    244  1.17      fvdl 	return intr_establish(irq, pic, pin, type, level, func, arg);
    245   1.1       cgd }
    246   1.1       cgd 
    247   1.1       cgd void
    248   1.1       cgd eisa_intr_disestablish(ec, cookie)
    249   1.1       cgd 	eisa_chipset_tag_t ec;
    250   1.1       cgd 	void *cookie;
    251   1.1       cgd {
    252   1.1       cgd 
    253  1.17      fvdl 	intr_disestablish(cookie);
    254   1.5   thorpej }
    255   1.5   thorpej 
    256   1.5   thorpej int
    257   1.5   thorpej eisa_mem_alloc(t, size, align, boundary, cacheable, addrp, bahp)
    258   1.5   thorpej 	bus_space_tag_t t;
    259   1.5   thorpej 	bus_size_t size, align;
    260   1.5   thorpej 	bus_addr_t boundary;
    261   1.5   thorpej 	int cacheable;
    262   1.5   thorpej 	bus_addr_t *addrp;
    263   1.5   thorpej 	bus_space_handle_t *bahp;
    264   1.5   thorpej {
    265   1.5   thorpej 	extern struct extent *iomem_ex;
    266   1.5   thorpej 
    267   1.5   thorpej 	/*
    268   1.5   thorpej 	 * Allocate physical address space after the ISA hole.
    269   1.5   thorpej 	 */
    270   1.5   thorpej 	return bus_space_alloc(t, IOM_END, iomem_ex->ex_end, size, align,
    271   1.5   thorpej 	    boundary, cacheable, addrp, bahp);
    272   1.5   thorpej }
    273   1.5   thorpej 
    274   1.5   thorpej void
    275   1.5   thorpej eisa_mem_free(t, bah, size)
    276   1.5   thorpej 	bus_space_tag_t t;
    277   1.5   thorpej 	bus_space_handle_t bah;
    278   1.5   thorpej 	bus_size_t size;
    279   1.5   thorpej {
    280   1.5   thorpej 
    281   1.5   thorpej 	bus_space_free(t, bah, size);
    282  1.12   thorpej }
    283  1.12   thorpej 
    284  1.12   thorpej int
    285  1.12   thorpej eisa_conf_read_mem(ec, slot, func, entry, ecm)
    286  1.12   thorpej 	eisa_chipset_tag_t ec;
    287  1.12   thorpej 	int slot, func, entry;
    288  1.12   thorpej 	struct eisa_cfg_mem *ecm;
    289  1.12   thorpej {
    290  1.12   thorpej 
    291  1.12   thorpej 	/* XXX XXX XXX */
    292  1.12   thorpej 	return (ENOENT);
    293  1.12   thorpej }
    294  1.12   thorpej 
    295  1.12   thorpej int
    296  1.12   thorpej eisa_conf_read_irq(ec, slot, func, entry, eci)
    297  1.12   thorpej 	eisa_chipset_tag_t ec;
    298  1.12   thorpej 	int slot, func, entry;
    299  1.12   thorpej 	struct eisa_cfg_irq *eci;
    300  1.12   thorpej {
    301  1.12   thorpej 
    302  1.12   thorpej 	/* XXX XXX XXX */
    303  1.12   thorpej 	return (ENOENT);
    304  1.12   thorpej }
    305  1.12   thorpej 
    306  1.12   thorpej int
    307  1.12   thorpej eisa_conf_read_dma(ec, slot, func, entry, ecd)
    308  1.12   thorpej 	eisa_chipset_tag_t ec;
    309  1.12   thorpej 	int slot, func, entry;
    310  1.12   thorpej 	struct eisa_cfg_dma *ecd;
    311  1.12   thorpej {
    312  1.12   thorpej 
    313  1.12   thorpej 	/* XXX XXX XXX */
    314  1.12   thorpej 	return (ENOENT);
    315  1.12   thorpej }
    316  1.12   thorpej 
    317  1.12   thorpej int
    318  1.12   thorpej eisa_conf_read_io(ec, slot, func, entry, ecio)
    319  1.12   thorpej 	eisa_chipset_tag_t ec;
    320  1.12   thorpej 	int slot, func, entry;
    321  1.12   thorpej 	struct eisa_cfg_io *ecio;
    322  1.12   thorpej {
    323  1.12   thorpej 
    324  1.12   thorpej 	/* XXX XXX XXX */
    325  1.12   thorpej 	return (ENOENT);
    326   1.1       cgd }
    327