Home | History | Annotate | Line # | Download | only in pci
pci_machdep_common.c revision 1.1.6.1
      1  1.1.6.1  joerg /* $NetBSD: pci_machdep_common.c,v 1.1.6.1 2007/11/02 13:34:42 joerg Exp $ */
      2  1.1.6.1  joerg 
      3  1.1.6.1  joerg /*-
      4  1.1.6.1  joerg  * Copyright (c) 2007 The NetBSD Foundation, Inc.
      5  1.1.6.1  joerg  * All rights reserved.
      6  1.1.6.1  joerg  *
      7  1.1.6.1  joerg  * This code is derived from software contributed to The NetBSD Foundation
      8  1.1.6.1  joerg  * by Tim Rightnour
      9  1.1.6.1  joerg  *
     10  1.1.6.1  joerg  * Redistribution and use in source and binary forms, with or without
     11  1.1.6.1  joerg  * modification, are permitted provided that the following conditions
     12  1.1.6.1  joerg  * are met:
     13  1.1.6.1  joerg  * 1. Redistributions of source code must retain the above copyright
     14  1.1.6.1  joerg  *    notice, this list of conditions and the following disclaimer.
     15  1.1.6.1  joerg  * 2. Redistributions in binary form must reproduce the above copyright
     16  1.1.6.1  joerg  *    notice, this list of conditions and the following disclaimer in the
     17  1.1.6.1  joerg  *    documentation and/or other materials provided with the distribution.
     18  1.1.6.1  joerg  * 3. All advertising materials mentioning features or use of this software
     19  1.1.6.1  joerg  *    must display the following acknowledgement:
     20  1.1.6.1  joerg  *        This product includes software developed by the NetBSD
     21  1.1.6.1  joerg  *        Foundation, Inc. and its contributors.
     22  1.1.6.1  joerg  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23  1.1.6.1  joerg  *    contributors may be used to endorse or promote products derived
     24  1.1.6.1  joerg  *    from this software without specific prior written permission.
     25  1.1.6.1  joerg  *
     26  1.1.6.1  joerg  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27  1.1.6.1  joerg  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28  1.1.6.1  joerg  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29  1.1.6.1  joerg  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30  1.1.6.1  joerg  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31  1.1.6.1  joerg  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32  1.1.6.1  joerg  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33  1.1.6.1  joerg  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34  1.1.6.1  joerg  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35  1.1.6.1  joerg  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36  1.1.6.1  joerg  * POSSIBILITY OF SUCH DAMAGE.
     37  1.1.6.1  joerg  */
     38  1.1.6.1  joerg 
     39  1.1.6.1  joerg /*
     40  1.1.6.1  joerg  * Generic PowerPC functions for dealing with a PCI bridge.  For most cases,
     41  1.1.6.1  joerg  * these functions will work just fine, however, some machines may need
     42  1.1.6.1  joerg  * specialized code, so those ports are free to write thier own functions
     43  1.1.6.1  joerg  * and call those instead where appropriate.
     44  1.1.6.1  joerg  */
     45  1.1.6.1  joerg 
     46  1.1.6.1  joerg #include <sys/cdefs.h>
     47  1.1.6.1  joerg __KERNEL_RCSID(0, "$NetBSD: pci_machdep_common.c,v 1.1.6.1 2007/11/02 13:34:42 joerg Exp $");
     48  1.1.6.1  joerg 
     49  1.1.6.1  joerg #include <sys/types.h>
     50  1.1.6.1  joerg #include <sys/param.h>
     51  1.1.6.1  joerg #include <sys/time.h>
     52  1.1.6.1  joerg #include <sys/systm.h>
     53  1.1.6.1  joerg #include <sys/errno.h>
     54  1.1.6.1  joerg #include <sys/extent.h>
     55  1.1.6.1  joerg #include <sys/device.h>
     56  1.1.6.1  joerg #include <sys/malloc.h>
     57  1.1.6.1  joerg 
     58  1.1.6.1  joerg #include <uvm/uvm_extern.h>
     59  1.1.6.1  joerg 
     60  1.1.6.1  joerg #define _POWERPC_BUS_DMA_PRIVATE
     61  1.1.6.1  joerg #include <machine/bus.h>
     62  1.1.6.1  joerg #include <machine/intr.h>
     63  1.1.6.1  joerg 
     64  1.1.6.1  joerg #include <dev/pci/pcivar.h>
     65  1.1.6.1  joerg #include <dev/pci/pcireg.h>
     66  1.1.6.1  joerg #include <dev/pci/pcidevs.h>
     67  1.1.6.1  joerg #include <dev/pci/pciconf.h>
     68  1.1.6.1  joerg 
     69  1.1.6.1  joerg /*
     70  1.1.6.1  joerg  * PCI doesn't have any special needs; just use the generic versions
     71  1.1.6.1  joerg  * of these functions.
     72  1.1.6.1  joerg  */
     73  1.1.6.1  joerg /*
     74  1.1.6.1  joerg  * XXX for now macppc needs its own pci_bus_dma_tag
     75  1.1.6.1  joerg  * this will go away once we use the common bus_space stuff
     76  1.1.6.1  joerg  */
     77  1.1.6.1  joerg #ifndef macppc
     78  1.1.6.1  joerg struct powerpc_bus_dma_tag pci_bus_dma_tag = {
     79  1.1.6.1  joerg 	0,			/* _bounce_thresh */
     80  1.1.6.1  joerg 	_bus_dmamap_create,
     81  1.1.6.1  joerg 	_bus_dmamap_destroy,
     82  1.1.6.1  joerg 	_bus_dmamap_load,
     83  1.1.6.1  joerg 	_bus_dmamap_load_mbuf,
     84  1.1.6.1  joerg 	_bus_dmamap_load_uio,
     85  1.1.6.1  joerg 	_bus_dmamap_load_raw,
     86  1.1.6.1  joerg 	_bus_dmamap_unload,
     87  1.1.6.1  joerg 	NULL,			/* _dmamap_sync */
     88  1.1.6.1  joerg 	_bus_dmamem_alloc,
     89  1.1.6.1  joerg 	_bus_dmamem_free,
     90  1.1.6.1  joerg 	_bus_dmamem_map,
     91  1.1.6.1  joerg 	_bus_dmamem_unmap,
     92  1.1.6.1  joerg 	_bus_dmamem_mmap,
     93  1.1.6.1  joerg };
     94  1.1.6.1  joerg #endif
     95  1.1.6.1  joerg int
     96  1.1.6.1  joerg genppc_pci_bus_maxdevs(pci_chipset_tag_t pc, int busno)
     97  1.1.6.1  joerg {
     98  1.1.6.1  joerg 	return 32;
     99  1.1.6.1  joerg }
    100  1.1.6.1  joerg 
    101  1.1.6.1  joerg const char *
    102  1.1.6.1  joerg genppc_pci_intr_string(void *v, pci_intr_handle_t ih)
    103  1.1.6.1  joerg {
    104  1.1.6.1  joerg 	static char irqstr[8];		/* 4 + 2 + NULL + sanity */
    105  1.1.6.1  joerg 
    106  1.1.6.1  joerg 	if (ih == 0 || ih >= ICU_LEN
    107  1.1.6.1  joerg /* XXX on macppc it's completely legal to have PCI interrupts on a slave PIC */
    108  1.1.6.1  joerg #ifdef IRQ_SLAVE
    109  1.1.6.1  joerg 	    || ih == IRQ_SLAVE
    110  1.1.6.1  joerg #endif
    111  1.1.6.1  joerg 	    )
    112  1.1.6.1  joerg 		panic("pci_intr_string: bogus handle 0x%x", ih);
    113  1.1.6.1  joerg 
    114  1.1.6.1  joerg 	sprintf(irqstr, "irq %d", ih);
    115  1.1.6.1  joerg 	return (irqstr);
    116  1.1.6.1  joerg 
    117  1.1.6.1  joerg }
    118  1.1.6.1  joerg 
    119  1.1.6.1  joerg const struct evcnt *
    120  1.1.6.1  joerg genppc_pci_intr_evcnt(void *v, pci_intr_handle_t ih)
    121  1.1.6.1  joerg {
    122  1.1.6.1  joerg 
    123  1.1.6.1  joerg 	/* XXX for now, no evcnt parent reported */
    124  1.1.6.1  joerg 	return NULL;
    125  1.1.6.1  joerg }
    126  1.1.6.1  joerg 
    127  1.1.6.1  joerg void *
    128  1.1.6.1  joerg genppc_pci_intr_establish(void *v, pci_intr_handle_t ih, int level,
    129  1.1.6.1  joerg     int (*func)(void *), void *arg)
    130  1.1.6.1  joerg {
    131  1.1.6.1  joerg 
    132  1.1.6.1  joerg 	if (ih == 0 || ih >= ICU_LEN
    133  1.1.6.1  joerg #ifdef IRQ_SLAVE
    134  1.1.6.1  joerg 	    || ih == IRQ_SLAVE
    135  1.1.6.1  joerg #endif
    136  1.1.6.1  joerg 	    )
    137  1.1.6.1  joerg 		panic("pci_intr_establish: bogus handle 0x%x", ih);
    138  1.1.6.1  joerg 
    139  1.1.6.1  joerg 	return intr_establish(ih, IST_LEVEL, level, func, arg);
    140  1.1.6.1  joerg }
    141  1.1.6.1  joerg 
    142  1.1.6.1  joerg void
    143  1.1.6.1  joerg genppc_pci_intr_disestablish(void *v, void *cookie)
    144  1.1.6.1  joerg {
    145  1.1.6.1  joerg 
    146  1.1.6.1  joerg 	intr_disestablish(cookie);
    147  1.1.6.1  joerg }
    148  1.1.6.1  joerg 
    149  1.1.6.1  joerg void
    150  1.1.6.1  joerg genppc_pci_conf_interrupt(pci_chipset_tag_t pct, int bus, int dev, int pin,
    151  1.1.6.1  joerg     int swiz, int *iline)
    152  1.1.6.1  joerg {
    153  1.1.6.1  joerg 	/* do nothing */
    154  1.1.6.1  joerg }
    155  1.1.6.1  joerg 
    156  1.1.6.1  joerg int
    157  1.1.6.1  joerg genppc_pci_conf_hook(pci_chipset_tag_t pct, int bus, int dev, int func,
    158  1.1.6.1  joerg 	pcireg_t id)
    159  1.1.6.1  joerg {
    160  1.1.6.1  joerg 	return (PCI_CONF_DEFAULT);
    161  1.1.6.1  joerg }
    162  1.1.6.1  joerg 
    163  1.1.6.1  joerg int
    164  1.1.6.1  joerg genppc_pci_intr_map(struct pci_attach_args *pa, pci_intr_handle_t *ihp)
    165  1.1.6.1  joerg {
    166  1.1.6.1  joerg 	int pin = pa->pa_intrpin;
    167  1.1.6.1  joerg 	int line = pa->pa_intrline;
    168  1.1.6.1  joerg 
    169  1.1.6.1  joerg #if DEBUG
    170  1.1.6.1  joerg 	printf("%s: pin: %d, line: %d\n", __FUNCTION__, pin, line);
    171  1.1.6.1  joerg #endif
    172  1.1.6.1  joerg 
    173  1.1.6.1  joerg 	if (pin == 0) {
    174  1.1.6.1  joerg 		/* No IRQ used. */
    175  1.1.6.1  joerg 		aprint_error("pci_intr_map: interrupt pin %d\n", pin);
    176  1.1.6.1  joerg 		goto bad;
    177  1.1.6.1  joerg 	}
    178  1.1.6.1  joerg 
    179  1.1.6.1  joerg 	if (pin > 4) {
    180  1.1.6.1  joerg 		aprint_error("pci_intr_map: bad interrupt pin %d\n", pin);
    181  1.1.6.1  joerg 		goto bad;
    182  1.1.6.1  joerg 	}
    183  1.1.6.1  joerg 
    184  1.1.6.1  joerg 	/*
    185  1.1.6.1  joerg 	 * Section 6.2.4, `Miscellaneous Functions', says that 255 means
    186  1.1.6.1  joerg 	 * `unknown' or `no connection' on a PC.  We assume that a device with
    187  1.1.6.1  joerg 	 * `no connection' either doesn't have an interrupt (in which case the
    188  1.1.6.1  joerg 	 * pin number should be 0, and would have been noticed above), or
    189  1.1.6.1  joerg 	 * wasn't configured by the BIOS (in which case we punt, since there's
    190  1.1.6.1  joerg 	 * no real way we can know how the interrupt lines are mapped in the
    191  1.1.6.1  joerg 	 * hardware).
    192  1.1.6.1  joerg 	 *
    193  1.1.6.1  joerg 	 * XXX
    194  1.1.6.1  joerg 	 * Since IRQ 0 is only used by the clock, and we can't actually be sure
    195  1.1.6.1  joerg 	 * that the BIOS did its job, we also recognize that as meaning that
    196  1.1.6.1  joerg 	 * the BIOS has not configured the device.
    197  1.1.6.1  joerg 	 */
    198  1.1.6.1  joerg 	if (line == 0 || line == 255) {
    199  1.1.6.1  joerg 		aprint_error("pci_intr_map: no mapping for pin %c\n", '@' + pin);
    200  1.1.6.1  joerg 		goto bad;
    201  1.1.6.1  joerg 	} else {
    202  1.1.6.1  joerg 		if (line >= ICU_LEN) {
    203  1.1.6.1  joerg 			aprint_error("pci_intr_map: bad interrupt line %d\n", line);
    204  1.1.6.1  joerg 			goto bad;
    205  1.1.6.1  joerg 		}
    206  1.1.6.1  joerg 	}
    207  1.1.6.1  joerg 
    208  1.1.6.1  joerg 	*ihp = line;
    209  1.1.6.1  joerg 	return 0;
    210  1.1.6.1  joerg 
    211  1.1.6.1  joerg bad:
    212  1.1.6.1  joerg 	*ihp = -1;
    213  1.1.6.1  joerg 	return 1;
    214  1.1.6.1  joerg }
    215  1.1.6.1  joerg 
    216