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