Home | History | Annotate | Line # | Download | only in pci
pci_machdep_common.c revision 1.20
      1 /* $NetBSD: pci_machdep_common.c,v 1.20 2014/03/29 19:28:29 christos 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  *
     19  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29  * POSSIBILITY OF SUCH DAMAGE.
     30  */
     31 
     32 /*
     33  * Generic PowerPC functions for dealing with a PCI bridge.  For most cases,
     34  * these functions will work just fine, however, some machines may need
     35  * specialized code, so those ports are free to write thier own functions
     36  * and call those instead where appropriate.
     37  */
     38 
     39 #include <sys/cdefs.h>
     40 __KERNEL_RCSID(0, "$NetBSD: pci_machdep_common.c,v 1.20 2014/03/29 19:28:29 christos Exp $");
     41 
     42 #define _POWERPC_BUS_DMA_PRIVATE
     43 
     44 #include <sys/param.h>
     45 #include <sys/bus.h>
     46 #include <sys/device.h>
     47 #include <sys/errno.h>
     48 #include <sys/extent.h>
     49 #include <sys/intr.h>
     50 #include <sys/systm.h>
     51 #include <sys/time.h>
     52 
     53 #include <uvm/uvm_extern.h>
     54 
     55 #include <dev/pci/pcivar.h>
     56 #include <dev/pci/pcireg.h>
     57 #include <dev/pci/pcidevs.h>
     58 #include <dev/pci/pciconf.h>
     59 #include <dev/pci/pciidereg.h>
     60 
     61 /*
     62  * PCI doesn't have any special needs; just use the generic versions
     63  * of these functions.
     64  */
     65 struct powerpc_bus_dma_tag pci_bus_dma_tag = {
     66 	._dmamap_create = _bus_dmamap_create,
     67 	._dmamap_destroy = _bus_dmamap_destroy,
     68 	._dmamap_load = _bus_dmamap_load,
     69 	._dmamap_load_mbuf = _bus_dmamap_load_mbuf,
     70 	._dmamap_load_uio = _bus_dmamap_load_uio,
     71 	._dmamap_load_raw = _bus_dmamap_load_raw,
     72 	._dmamap_unload = _bus_dmamap_unload,
     73 
     74 	._dmamem_alloc = _bus_dmamem_alloc,
     75 	._dmamem_free = _bus_dmamem_free,
     76 	._dmamem_map = _bus_dmamem_map,
     77 	._dmamem_unmap = _bus_dmamem_unmap,
     78 	._dmamem_mmap = _bus_dmamem_mmap,
     79 };
     80 
     81 int
     82 genppc_pci_bus_maxdevs(void *v, int busno)
     83 {
     84 	return 32;
     85 }
     86 
     87 const char *
     88 genppc_pci_intr_string(void *v, pci_intr_handle_t ih, char *buf, size_t len)
     89 {
     90 #ifdef ICU_LEN
     91 	if (ih == 0 || ih >= ICU_LEN
     92 /* XXX on macppc it's completely legal to have PCI interrupts on a slave PIC */
     93 #ifdef IRQ_SLAVE
     94 	    || ih == IRQ_SLAVE
     95 #endif
     96 	    )
     97 		panic("pci_intr_string: bogus handle 0x%x", ih);
     98 #endif
     99 
    100 	snprintf(buf, len, "irq %d", ih);
    101 	return buf;
    102 
    103 }
    104 
    105 const struct evcnt *
    106 genppc_pci_intr_evcnt(void *v, pci_intr_handle_t ih)
    107 {
    108 
    109 	/* XXX for now, no evcnt parent reported */
    110 	return NULL;
    111 }
    112 
    113 void *
    114 genppc_pci_intr_establish(void *v, pci_intr_handle_t ih, int level,
    115     int (*func)(void *), void *arg)
    116 {
    117 
    118 #ifdef ICU_LEN
    119 	if (ih == 0 || ih >= ICU_LEN
    120 #ifdef IRQ_SLAVE
    121 	    || ih == IRQ_SLAVE
    122 #endif
    123 	    )
    124 		panic("pci_intr_establish: bogus handle 0x%x", ih);
    125 #endif
    126 
    127 	return intr_establish(ih, IST_LEVEL, level, func, arg);
    128 }
    129 
    130 void
    131 genppc_pci_intr_disestablish(void *v, void *cookie)
    132 {
    133 
    134 	intr_disestablish(cookie);
    135 }
    136 
    137 int
    138 genppc_pci_intr_setattr(void *v, pci_intr_handle_t *ihp, int attr,
    139     uint64_t data)
    140 {
    141 
    142 	return ENODEV;
    143 }
    144 
    145 void
    146 genppc_pci_conf_interrupt(void *v, int bus, int dev, int pin,
    147     int swiz, int *iline)
    148 {
    149 	/* do nothing */
    150 }
    151 
    152 int
    153 genppc_pci_conf_hook(void *v, int bus, int dev, int func, pcireg_t id)
    154 {
    155 	return (PCI_CONF_DEFAULT);
    156 }
    157 
    158 int
    159 genppc_pci_intr_map(const 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 #ifdef ICU_LEN
    197 	} else {
    198 		if (line >= ICU_LEN) {
    199 			aprint_error("pci_intr_map: bad interrupt line %d\n", line);
    200 			goto bad;
    201 		}
    202 #endif
    203 	}
    204 
    205 	*ihp = line;
    206 	return 0;
    207 
    208 bad:
    209 	*ihp = -1;
    210 	return 1;
    211 }
    212 
    213 int
    214 genppc_pci_msi_request(const struct pci_attach_args *pa,
    215     pci_msi_handle_t *msihp, size_t nmsirq, int ipl, int capid)
    216 {
    217 	return EOPNOTSUPP;
    218 }
    219 
    220 int
    221 genppc_pci_msi_type(void *v, pci_msi_handle_t msih)
    222 {
    223 	panic("%s", __func__);
    224 }
    225 
    226 size_t
    227 genppc_pci_msi_available(void *v, pci_msi_handle_t msih)
    228 {
    229 	panic("%s", __func__);
    230 }
    231 
    232 const char *
    233 genppc_pci_msi_string(void *v, pci_msi_handle_t msih, size_t msirq)
    234 {
    235 	panic("%s", __func__);
    236 }
    237 
    238 const struct evcnt *
    239 genppc_pci_msi_evcnt(void *v, pci_msi_handle_t msih, size_t msirq)
    240 {
    241 	panic("%s", __func__);
    242 }
    243 
    244 void *
    245 genppc_pci_msi_establish(void *v, pci_msi_handle_t msih, size_t msirq,
    246 		    int ipl, int (*func)(void *), void *arg)
    247 {
    248 	panic("%s", __func__);
    249 }
    250 
    251 void *
    252 genppc_pci_msix_establish(void *v, pci_msi_handle_t msih, size_t vec,
    253     size_t msirq, int ipl, int (*func)(void *), void *arg)
    254 {
    255 	panic("%s", __func__);
    256 }
    257 
    258 void
    259 genppc_pci_msi_disestablish(void *v, void *ih)
    260 {
    261 	panic("%s", __func__);
    262 }
    263 
    264 void
    265 genppc_pci_msi_free(void *v, pci_msi_handle_t msih, size_t msirq)
    266 {
    267 	panic("%s", __func__);
    268 }
    269 
    270 void
    271 genppc_pci_msi_release(void *v, pci_msi_handle_t msih)
    272 {
    273 	panic("%s", __func__);
    274 }
    275 
    276 void
    277 genppc_pci_chipset_msi_init(pci_chipset_tag_t pc)
    278 {
    279 	pc->pc_msi_request = genppc_pci_msi_request;
    280 	pc->pc_msi_type = genppc_pci_msi_type;
    281 	pc->pc_msi_available = genppc_pci_msi_available;
    282 	pc->pc_msi_evcnt = genppc_pci_msi_evcnt;
    283 	pc->pc_msi_string = genppc_pci_msi_string;
    284 	pc->pc_msi_establish = genppc_pci_msi_establish;
    285 	pc->pc_msix_establish = genppc_pci_msix_establish;
    286 	pc->pc_msi_disestablish = genppc_pci_msi_disestablish;
    287 	pc->pc_msi_free = genppc_pci_msi_free;
    288 	pc->pc_msi_release = genppc_pci_msi_release;
    289 }
    290 
    291 #ifdef __HAVE_PCIIDE_MACHDEP_COMPAT_INTR_ESTABLISH
    292 #include <machine/isa_machdep.h>
    293 #include "isa.h"
    294 
    295 void *genppc_pciide_machdep_compat_intr_establish(device_t,
    296     struct pci_attach_args *, int, int (*)(void *), void *);
    297 
    298 void *
    299 genppc_pciide_machdep_compat_intr_establish(device_t dev,
    300     struct pci_attach_args *pa, int chan, int (*func)(void *), void *arg)
    301 {
    302 #if NISA > 0
    303 	int irq;
    304 	void *cookie;
    305 
    306 	irq = PCIIDE_COMPAT_IRQ(chan);
    307 	cookie = isa_intr_establish(NULL, irq, IST_LEVEL, IPL_BIO, func, arg);
    308 	if (cookie == NULL)
    309 		return (NULL);
    310 	aprint_normal_dev(dev, "%s channel interrupting at irq %d\n",
    311 	    PCIIDE_CHANNEL_NAME(chan), irq);
    312 	return (cookie);
    313 #else
    314 	panic("pciide_machdep_compat_intr_establish() called");
    315 #endif
    316 }
    317 #endif /* __HAVE_PCIIDE_MACHDEP_COMPAT_INTR_ESTABLISH */
    318