Home | History | Annotate | Line # | Download | only in pci
pci_machdep.c revision 1.25
      1 /*	$NetBSD: pci_machdep.c,v 1.25 2006/04/25 02:19:31 snj 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/cdefs.h>
     42 __KERNEL_RCSID(0, "$NetBSD: pci_machdep.c,v 1.25 2006/04/25 02:19:31 snj Exp $");
     43 
     44 #include <sys/types.h>
     45 #include <sys/param.h>
     46 #include <sys/time.h>
     47 #include <sys/systm.h>
     48 #include <sys/errno.h>
     49 #include <sys/extent.h>
     50 #include <sys/device.h>
     51 
     52 #include <uvm/uvm_extern.h>
     53 
     54 #define _POWERPC_BUS_DMA_PRIVATE
     55 #include <machine/bus.h>
     56 #include <machine/intr.h>
     57 #include <machine/platform.h>
     58 #include <machine/pnp.h>
     59 
     60 #include <dev/isa/isavar.h>
     61 
     62 #include <dev/pci/pcivar.h>
     63 #include <dev/pci/pcireg.h>
     64 #include <dev/pci/pcidevs.h>
     65 #include <dev/pci/pciconf.h>
     66 
     67 /*
     68  * PCI doesn't have any special needs; just use the generic versions
     69  * of these functions.
     70  */
     71 struct powerpc_bus_dma_tag pci_bus_dma_tag = {
     72 	0,			/* _bounce_thresh */
     73 	_bus_dmamap_create,
     74 	_bus_dmamap_destroy,
     75 	_bus_dmamap_load,
     76 	_bus_dmamap_load_mbuf,
     77 	_bus_dmamap_load_uio,
     78 	_bus_dmamap_load_raw,
     79 	_bus_dmamap_unload,
     80 	NULL,			/* _dmamap_sync */
     81 	_bus_dmamem_alloc,
     82 	_bus_dmamem_free,
     83 	_bus_dmamem_map,
     84 	_bus_dmamem_unmap,
     85 	_bus_dmamem_mmap,
     86 };
     87 
     88 void
     89 prep_pci_get_chipset_tag(pci_chipset_tag_t pc)
     90 {
     91 	int i;
     92 
     93 	i = pci_chipset_tag_type();
     94 
     95 	if (i == PCIBridgeIndirect)
     96 		prep_pci_get_chipset_tag_indirect(pc);
     97 	else if (i == PCIBridgeDirect)
     98 		prep_pci_get_chipset_tag_direct(pc);
     99 	else
    100 		panic("Unknown PCI chipset tag configuration method");
    101 }
    102 
    103 int
    104 prep_pci_bus_maxdevs(void *v, int busno)
    105 {
    106 
    107 	/*
    108 	 * Bus number is irrelevant.  Configuration Mechanism 1 is in
    109 	 * use, can have devices 0-32 (i.e. the `normal' range).
    110 	 */
    111 	return (32);
    112 }
    113 
    114 
    115 int
    116 prep_pci_intr_map(struct pci_attach_args *pa, pci_intr_handle_t *ihp)
    117 {
    118 	int pin = pa->pa_intrpin;
    119 	int line = pa->pa_intrline;
    120 
    121 	if (pin == 0) {
    122 		/* No IRQ used. */
    123 		goto bad;
    124 	}
    125 
    126 	if (pin > 4) {
    127 		printf("pci_intr_map: bad interrupt pin %d\n", pin);
    128 		goto bad;
    129 	}
    130 
    131 	/*
    132 	* Section 6.2.4, `Miscellaneous Functions', says that 255 means
    133 	* `unknown' or `no connection' on a PC.  We assume that a device with
    134 	* `no connection' either doesn't have an interrupt (in which case the
    135 	* pin number should be 0, and would have been noticed above), or
    136 	* wasn't configured by the BIOS (in which case we punt, since there's
    137 	* no real way we can know how the interrupt lines are mapped in the
    138 	* hardware).
    139 	*
    140 	* XXX
    141 	* Since IRQ 0 is only used by the clock, and we can't actually be sure
    142 	* that the BIOS did its job, we also recognize that as meaning that
    143 	* the BIOS has not configured the device.
    144 	*/
    145 	if (line == 0 || line == 255) {
    146 		printf("pci_intr_map: no mapping for pin %c\n", '@' + pin);
    147 		goto bad;
    148 	} else {
    149 		if (line >= ICU_LEN) {
    150 			printf("pci_intr_map: bad interrupt line %d\n", line);
    151 			goto bad;
    152 		}
    153 		if (line == IRQ_SLAVE) {
    154 			printf("pci_intr_map: changed line 2 to line 9\n");
    155 			line = 9;
    156 		}
    157 	}
    158 
    159 	*ihp = line;
    160 	return 0;
    161 
    162 bad:
    163 	*ihp = -1;
    164 	return 1;
    165 }
    166 
    167 const char *
    168 prep_pci_intr_string(void *v, pci_intr_handle_t ih)
    169 {
    170 	static char irqstr[8];		/* 4 + 2 + NULL + sanity */
    171 
    172 	if (ih == 0 || ih >= ICU_LEN || ih == IRQ_SLAVE)
    173 		panic("pci_intr_string: bogus handle 0x%x", ih);
    174 
    175 	sprintf(irqstr, "irq %d", ih);
    176 	return (irqstr);
    177 
    178 }
    179 
    180 const struct evcnt *
    181 prep_pci_intr_evcnt(void *v, pci_intr_handle_t ih)
    182 {
    183 
    184 	/* XXX for now, no evcnt parent reported */
    185 	return NULL;
    186 }
    187 
    188 void *
    189 prep_pci_intr_establish(void *v, pci_intr_handle_t ih, int level,
    190     int (*func)(void *), void *arg)
    191 {
    192 
    193 	if (ih == 0 || ih >= ICU_LEN || ih == IRQ_SLAVE)
    194 		panic("pci_intr_establish: bogus handle 0x%x", ih);
    195 
    196 	return isa_intr_establish(NULL, ih, IST_LEVEL, level, func, arg);
    197 }
    198 
    199 void
    200 prep_pci_intr_disestablish(void *v, void *cookie)
    201 {
    202 
    203 	isa_intr_disestablish(NULL, cookie);
    204 }
    205 
    206 void
    207 prep_pci_conf_interrupt(void *v, int bus, int dev, int pin,
    208     int swiz, int *iline)
    209 {
    210 
    211 	pci_intr_fixup_pnp(bus, dev, pin, swiz, iline);
    212 }
    213 
    214 int
    215 prep_pci_conf_hook(void *v, int bus, int dev, int func, pcireg_t id)
    216 {
    217 
    218 	/*
    219 	 * The P9100 board found in some IBM machines cannot be
    220 	 * over-configured.
    221 	 */
    222 	if (PCI_VENDOR(id) == PCI_VENDOR_WEITEK &&
    223 	    PCI_PRODUCT(id) == PCI_PRODUCT_WEITEK_P9100)
    224 		return 0;
    225 
    226 	/* We have already mapped the MPIC2 if we have one, so leave it
    227 	   alone */
    228 	if (PCI_VENDOR(id) == PCI_VENDOR_IBM &&
    229 	    PCI_PRODUCT(id) == PCI_PRODUCT_IBM_MPIC2)
    230 		return 0;
    231 
    232 	return (PCI_CONF_DEFAULT);
    233 }
    234