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