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