Home | History | Annotate | Line # | Download | only in pci
pci_machdep.c revision 1.17
      1 /*	NetBSD: pci_machdep.c,v 1.12 2001/06/19 11:56:27 nonaka Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 1996 Christopher G. Demetriou.  All rights reserved.
      5  * Copyright (c) 1994 Charles M. Hannum.  All rights reserved.
      6  *
      7  * Redistribution and use in source and binary forms, with or without
      8  * modification, are permitted provided that the following conditions
      9  * are met:
     10  * 1. Redistributions of source code must retain the above copyright
     11  *    notice, this list of conditions and the following disclaimer.
     12  * 2. Redistributions in binary form must reproduce the above copyright
     13  *    notice, this list of conditions and the following disclaimer in the
     14  *    documentation and/or other materials provided with the distribution.
     15  * 3. All advertising materials mentioning features or use of this software
     16  *    must display the following acknowledgement:
     17  *	This product includes software developed by Charles M. Hannum.
     18  * 4. The name of the author may not be used to endorse or promote products
     19  *    derived from this software without specific prior written permission.
     20  *
     21  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     22  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     23  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     24  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     25  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     26  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     27  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     28  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     29  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     30  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     31  */
     32 
     33 /*
     34  * Machine-specific functions for PCI autoconfiguration.
     35  *
     36  * On PCs, there are two methods of generating PCI configuration cycles.
     37  * We try to detect the appropriate mechanism for this machine and set
     38  * up a few function pointers to access the correct method directly.
     39  */
     40 
     41 #include <sys/types.h>
     42 #include <sys/param.h>
     43 #include <sys/time.h>
     44 #include <sys/systm.h>
     45 #include <sys/errno.h>
     46 #include <sys/extent.h>
     47 #include <sys/device.h>
     48 
     49 #include <uvm/uvm_extern.h>
     50 
     51 #define _POWERPC_BUS_DMA_PRIVATE
     52 #include <machine/bus.h>
     53 #include <machine/intr.h>
     54 #include <machine/platform.h>
     55 
     56 #include <dev/isa/isavar.h>
     57 
     58 #include <dev/pci/pcivar.h>
     59 #include <dev/pci/pcireg.h>
     60 #include <dev/pci/pcidevs.h>
     61 #include <dev/pci/pciconf.h>
     62 
     63 /*
     64  * PCI doesn't have any special needs; just use the generic versions
     65  * of these functions.
     66  */
     67 struct powerpc_bus_dma_tag pci_bus_dma_tag = {
     68 	0,			/* _bounce_thresh */
     69 	_bus_dmamap_create,
     70 	_bus_dmamap_destroy,
     71 	_bus_dmamap_load,
     72 	_bus_dmamap_load_mbuf,
     73 	_bus_dmamap_load_uio,
     74 	_bus_dmamap_load_raw,
     75 	_bus_dmamap_unload,
     76 	NULL,			/* _dmamap_sync */
     77 	_bus_dmamem_alloc,
     78 	_bus_dmamem_free,
     79 	_bus_dmamem_map,
     80 	_bus_dmamem_unmap,
     81 	_bus_dmamem_mmap,
     82 };
     83 
     84 int
     85 prep_pci_bus_maxdevs(void *v, int busno)
     86 {
     87 
     88 	/*
     89 	 * Bus number is irrelevant.  Configuration Mechanism 1 is in
     90 	 * use, can have devices 0-32 (i.e. the `normal' range).
     91 	 */
     92 	return (32);
     93 }
     94 
     95 
     96 int
     97 prep_pci_intr_map(struct pci_attach_args *pa, pci_intr_handle_t *ihp)
     98 {
     99 	int pin = pa->pa_intrpin;
    100 	int line = pa->pa_intrline;
    101 
    102 	if (pin == 0) {
    103 		/* No IRQ used. */
    104 		goto bad;
    105 	}
    106 
    107 	if (pin > 4) {
    108 		printf("pci_intr_map: bad interrupt pin %d\n", pin);
    109 		goto bad;
    110 	}
    111 
    112 	/*
    113 	* Section 6.2.4, `Miscellaneous Functions', says that 255 means
    114 	* `unknown' or `no connection' on a PC.  We assume that a device with
    115 	* `no connection' either doesn't have an interrupt (in which case the
    116 	* pin number should be 0, and would have been noticed above), or
    117 	* wasn't configured by the BIOS (in which case we punt, since there's
    118 	* no real way we can know how the interrupt lines are mapped in the
    119 	* hardware).
    120 	*
    121 	* XXX
    122 	* Since IRQ 0 is only used by the clock, and we can't actually be sure
    123 	* that the BIOS did its job, we also recognize that as meaning that
    124 	* the BIOS has not configured the device.
    125 	*/
    126 	if (line == 0 || line == 255) {
    127 		printf("pci_intr_map: no mapping for pin %c\n", '@' + pin);
    128 		goto bad;
    129 	} else {
    130 		if (line >= ICU_LEN) {
    131 			printf("pci_intr_map: bad interrupt line %d\n", line);
    132 			goto bad;
    133 		}
    134 		if (line == IRQ_SLAVE) {
    135 			printf("pci_intr_map: changed line 2 to line 9\n");
    136 			line = 9;
    137 		}
    138 	}
    139 
    140 	*ihp = line;
    141 	return 0;
    142 
    143 bad:
    144 	*ihp = -1;
    145 	return 1;
    146 }
    147 
    148 const char *
    149 prep_pci_intr_string(void *v, pci_intr_handle_t ih)
    150 {
    151 	static char irqstr[8];		/* 4 + 2 + NULL + sanity */
    152 
    153 	if (ih == 0 || ih >= ICU_LEN || ih == IRQ_SLAVE)
    154 		panic("pci_intr_string: bogus handle 0x%x", ih);
    155 
    156 	sprintf(irqstr, "irq %d", ih);
    157 	return (irqstr);
    158 
    159 }
    160 
    161 const struct evcnt *
    162 prep_pci_intr_evcnt(void *v, pci_intr_handle_t ih)
    163 {
    164 
    165 	/* XXX for now, no evcnt parent reported */
    166 	return NULL;
    167 }
    168 
    169 void *
    170 prep_pci_intr_establish(void *v, pci_intr_handle_t ih, int level,
    171     int (*func)(void *), void *arg)
    172 {
    173 
    174 	if (ih == 0 || ih >= ICU_LEN || ih == IRQ_SLAVE)
    175 		panic("pci_intr_establish: bogus handle 0x%x", ih);
    176 
    177 	return isa_intr_establish(NULL, ih, IST_LEVEL, level, func, arg);
    178 }
    179 
    180 void
    181 prep_pci_intr_disestablish(void *v, void *cookie)
    182 {
    183 
    184 	isa_intr_disestablish(NULL, cookie);
    185 }
    186 
    187 void
    188 prep_pci_conf_interrupt(void *v, int bus, int dev, int pin,
    189     int swiz, int *iline)
    190 {
    191 
    192 	(*platform->pci_intr_fixup)(bus, dev, iline);
    193 }
    194 
    195 int
    196 prep_pci_conf_hook(void *v, int bus, int dev, int func, pcireg_t id)
    197 {
    198 
    199 	/*
    200 	 * The P9100 board found in some IBM machines cannot be
    201 	 * over-configured.
    202 	 */
    203 	if (PCI_VENDOR(id) == PCI_VENDOR_WEITEK &&
    204 	    PCI_PRODUCT(id) == PCI_PRODUCT_WEITEK_P9100)
    205 		return 0;
    206 
    207 	return (PCI_CONF_ALL & ~PCI_CONF_MAP_ROM);
    208 }
    209