Home | History | Annotate | Line # | Download | only in pci
pci_machdep_common.c revision 1.4
      1 /* $NetBSD: pci_machdep_common.c,v 1.4 2007/12/20 22:24:40 phx 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.4 2007/12/20 22:24:40 phx 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 #include <machine/isa_machdep.h>
     64 
     65 #include <dev/pci/pcivar.h>
     66 #include <dev/pci/pcireg.h>
     67 #include <dev/pci/pcidevs.h>
     68 #include <dev/pci/pciconf.h>
     69 #include <dev/pci/pciidereg.h>
     70 
     71 /*
     72  * PCI doesn't have any special needs; just use the generic versions
     73  * of these functions.
     74  */
     75 /*
     76  * XXX for now macppc needs its own pci_bus_dma_tag
     77  * this will go away once we use the common bus_space stuff
     78  */
     79 #ifndef macppc
     80 struct powerpc_bus_dma_tag pci_bus_dma_tag = {
     81 	0,			/* _bounce_thresh */
     82 	_bus_dmamap_create,
     83 	_bus_dmamap_destroy,
     84 	_bus_dmamap_load,
     85 	_bus_dmamap_load_mbuf,
     86 	_bus_dmamap_load_uio,
     87 	_bus_dmamap_load_raw,
     88 	_bus_dmamap_unload,
     89 	NULL,			/* _dmamap_sync */
     90 	_bus_dmamem_alloc,
     91 	_bus_dmamem_free,
     92 	_bus_dmamem_map,
     93 	_bus_dmamem_unmap,
     94 	_bus_dmamem_mmap,
     95 };
     96 #endif
     97 int
     98 genppc_pci_bus_maxdevs(pci_chipset_tag_t pc, int busno)
     99 {
    100 	return 32;
    101 }
    102 
    103 const char *
    104 genppc_pci_intr_string(void *v, pci_intr_handle_t ih)
    105 {
    106 	static char irqstr[8];		/* 4 + 2 + NULL + sanity */
    107 
    108 	if (ih == 0 || ih >= ICU_LEN
    109 /* XXX on macppc it's completely legal to have PCI interrupts on a slave PIC */
    110 #ifdef IRQ_SLAVE
    111 	    || ih == IRQ_SLAVE
    112 #endif
    113 	    )
    114 		panic("pci_intr_string: bogus handle 0x%x", ih);
    115 
    116 	sprintf(irqstr, "irq %d", ih);
    117 	return (irqstr);
    118 
    119 }
    120 
    121 const struct evcnt *
    122 genppc_pci_intr_evcnt(void *v, pci_intr_handle_t ih)
    123 {
    124 
    125 	/* XXX for now, no evcnt parent reported */
    126 	return NULL;
    127 }
    128 
    129 void *
    130 genppc_pci_intr_establish(void *v, pci_intr_handle_t ih, int level,
    131     int (*func)(void *), void *arg)
    132 {
    133 
    134 	if (ih == 0 || ih >= ICU_LEN
    135 #ifdef IRQ_SLAVE
    136 	    || ih == IRQ_SLAVE
    137 #endif
    138 	    )
    139 		panic("pci_intr_establish: bogus handle 0x%x", ih);
    140 
    141 	return intr_establish(ih, IST_LEVEL, level, func, arg);
    142 }
    143 
    144 void
    145 genppc_pci_intr_disestablish(void *v, void *cookie)
    146 {
    147 
    148 	intr_disestablish(cookie);
    149 }
    150 
    151 void
    152 genppc_pci_conf_interrupt(pci_chipset_tag_t pct, int bus, int dev, int pin,
    153     int swiz, int *iline)
    154 {
    155 	/* do nothing */
    156 }
    157 
    158 int
    159 genppc_pci_conf_hook(pci_chipset_tag_t pct, int bus, int dev, int func,
    160 	pcireg_t id)
    161 {
    162 	return (PCI_CONF_DEFAULT);
    163 }
    164 
    165 int
    166 genppc_pci_intr_map(struct pci_attach_args *pa, pci_intr_handle_t *ihp)
    167 {
    168 	int pin = pa->pa_intrpin;
    169 	int line = pa->pa_intrline;
    170 
    171 #if DEBUG
    172 	printf("%s: pin: %d, line: %d\n", __func__, pin, line);
    173 #endif
    174 
    175 	if (pin == 0) {
    176 		/* No IRQ used. */
    177 		aprint_error("pci_intr_map: interrupt pin %d\n", pin);
    178 		goto bad;
    179 	}
    180 
    181 	if (pin > 4) {
    182 		aprint_error("pci_intr_map: bad interrupt pin %d\n", pin);
    183 		goto bad;
    184 	}
    185 
    186 	/*
    187 	 * Section 6.2.4, `Miscellaneous Functions', says that 255 means
    188 	 * `unknown' or `no connection' on a PC.  We assume that a device with
    189 	 * `no connection' either doesn't have an interrupt (in which case the
    190 	 * pin number should be 0, and would have been noticed above), or
    191 	 * wasn't configured by the BIOS (in which case we punt, since there's
    192 	 * no real way we can know how the interrupt lines are mapped in the
    193 	 * hardware).
    194 	 *
    195 	 * XXX
    196 	 * Since IRQ 0 is only used by the clock, and we can't actually be sure
    197 	 * that the BIOS did its job, we also recognize that as meaning that
    198 	 * the BIOS has not configured the device.
    199 	 */
    200 	if (line == 0 || line == 255) {
    201 		aprint_error("pci_intr_map: no mapping for pin %c\n", '@' + pin);
    202 		goto bad;
    203 	} else {
    204 		if (line >= ICU_LEN) {
    205 			aprint_error("pci_intr_map: bad interrupt line %d\n", line);
    206 			goto bad;
    207 		}
    208 	}
    209 
    210 	*ihp = line;
    211 	return 0;
    212 
    213 bad:
    214 	*ihp = -1;
    215 	return 1;
    216 }
    217 
    218 #ifdef __HAVE_PCIIDE_MACHDEP_COMPAT_INTR_ESTABLISH
    219 #include "isa.h"
    220 
    221 void *genppc_pciide_machdep_compat_intr_establish(struct device *,
    222     struct pci_attach_args *, int, int (*)(void *), void *);
    223 
    224 void *
    225 genppc_pciide_machdep_compat_intr_establish(struct device *dev,
    226     struct pci_attach_args *pa, int chan, int (*func)(void *), void *arg)
    227 {
    228 #if NISA > 0
    229 	int irq;
    230 	void *cookie;
    231 
    232 	irq = PCIIDE_COMPAT_IRQ(chan);
    233 	cookie = isa_intr_establish(NULL, irq, IST_LEVEL, IPL_BIO, func, arg);
    234 	if (cookie == NULL)
    235 		return (NULL);
    236 	printf("%s: %s channel interrupting at irq %d\n", dev->dv_xname,
    237 	    PCIIDE_CHANNEL_NAME(chan), irq);
    238 	return (cookie);
    239 #else
    240 	panic("pciide_machdep_compat_intr_establish() called");
    241 #endif
    242 }
    243 #endif /* __HAVE_PCIIDE_MACHDEP_COMPAT_INTR_ESTABLISH */
    244