Home | History | Annotate | Line # | Download | only in pci
pci_machdep_common.c revision 1.20
      1  1.20  christos /* $NetBSD: pci_machdep_common.c,v 1.20 2014/03/29 19:28:29 christos Exp $ */
      2   1.2   garbled 
      3   1.2   garbled /*-
      4   1.2   garbled  * Copyright (c) 2007 The NetBSD Foundation, Inc.
      5   1.2   garbled  * All rights reserved.
      6   1.2   garbled  *
      7   1.2   garbled  * This code is derived from software contributed to The NetBSD Foundation
      8   1.2   garbled  * by Tim Rightnour
      9   1.2   garbled  *
     10   1.2   garbled  * Redistribution and use in source and binary forms, with or without
     11   1.2   garbled  * modification, are permitted provided that the following conditions
     12   1.2   garbled  * are met:
     13   1.2   garbled  * 1. Redistributions of source code must retain the above copyright
     14   1.2   garbled  *    notice, this list of conditions and the following disclaimer.
     15   1.2   garbled  * 2. Redistributions in binary form must reproduce the above copyright
     16   1.2   garbled  *    notice, this list of conditions and the following disclaimer in the
     17   1.2   garbled  *    documentation and/or other materials provided with the distribution.
     18   1.2   garbled  *
     19   1.2   garbled  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20   1.2   garbled  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21   1.2   garbled  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22   1.2   garbled  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23   1.2   garbled  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24   1.2   garbled  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25   1.2   garbled  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26   1.2   garbled  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27   1.2   garbled  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28   1.2   garbled  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29   1.2   garbled  * POSSIBILITY OF SUCH DAMAGE.
     30   1.2   garbled  */
     31   1.2   garbled 
     32   1.2   garbled /*
     33   1.2   garbled  * Generic PowerPC functions for dealing with a PCI bridge.  For most cases,
     34   1.2   garbled  * these functions will work just fine, however, some machines may need
     35   1.2   garbled  * specialized code, so those ports are free to write thier own functions
     36   1.2   garbled  * and call those instead where appropriate.
     37   1.2   garbled  */
     38   1.2   garbled 
     39   1.2   garbled #include <sys/cdefs.h>
     40  1.20  christos __KERNEL_RCSID(0, "$NetBSD: pci_machdep_common.c,v 1.20 2014/03/29 19:28:29 christos Exp $");
     41  1.12      matt 
     42  1.12      matt #define _POWERPC_BUS_DMA_PRIVATE
     43   1.2   garbled 
     44   1.2   garbled #include <sys/param.h>
     45  1.13      matt #include <sys/bus.h>
     46  1.13      matt #include <sys/device.h>
     47   1.2   garbled #include <sys/errno.h>
     48   1.2   garbled #include <sys/extent.h>
     49  1.13      matt #include <sys/intr.h>
     50  1.13      matt #include <sys/systm.h>
     51  1.13      matt #include <sys/time.h>
     52   1.2   garbled 
     53   1.2   garbled #include <uvm/uvm_extern.h>
     54   1.2   garbled 
     55   1.2   garbled #include <dev/pci/pcivar.h>
     56   1.2   garbled #include <dev/pci/pcireg.h>
     57   1.2   garbled #include <dev/pci/pcidevs.h>
     58   1.2   garbled #include <dev/pci/pciconf.h>
     59   1.4       phx #include <dev/pci/pciidereg.h>
     60   1.2   garbled 
     61   1.2   garbled /*
     62   1.2   garbled  * PCI doesn't have any special needs; just use the generic versions
     63   1.2   garbled  * of these functions.
     64   1.2   garbled  */
     65   1.2   garbled struct powerpc_bus_dma_tag pci_bus_dma_tag = {
     66  1.16      matt 	._dmamap_create = _bus_dmamap_create,
     67  1.16      matt 	._dmamap_destroy = _bus_dmamap_destroy,
     68  1.16      matt 	._dmamap_load = _bus_dmamap_load,
     69  1.16      matt 	._dmamap_load_mbuf = _bus_dmamap_load_mbuf,
     70  1.16      matt 	._dmamap_load_uio = _bus_dmamap_load_uio,
     71  1.16      matt 	._dmamap_load_raw = _bus_dmamap_load_raw,
     72  1.16      matt 	._dmamap_unload = _bus_dmamap_unload,
     73  1.16      matt 
     74  1.16      matt 	._dmamem_alloc = _bus_dmamem_alloc,
     75  1.16      matt 	._dmamem_free = _bus_dmamem_free,
     76  1.16      matt 	._dmamem_map = _bus_dmamem_map,
     77  1.16      matt 	._dmamem_unmap = _bus_dmamem_unmap,
     78  1.16      matt 	._dmamem_mmap = _bus_dmamem_mmap,
     79   1.2   garbled };
     80   1.5  macallan 
     81   1.2   garbled int
     82   1.9      matt genppc_pci_bus_maxdevs(void *v, int busno)
     83   1.2   garbled {
     84   1.2   garbled 	return 32;
     85   1.2   garbled }
     86   1.2   garbled 
     87   1.2   garbled const char *
     88  1.20  christos genppc_pci_intr_string(void *v, pci_intr_handle_t ih, char *buf, size_t len)
     89   1.2   garbled {
     90  1.13      matt #ifdef ICU_LEN
     91   1.2   garbled 	if (ih == 0 || ih >= ICU_LEN
     92   1.2   garbled /* XXX on macppc it's completely legal to have PCI interrupts on a slave PIC */
     93   1.2   garbled #ifdef IRQ_SLAVE
     94   1.2   garbled 	    || ih == IRQ_SLAVE
     95   1.2   garbled #endif
     96   1.2   garbled 	    )
     97   1.2   garbled 		panic("pci_intr_string: bogus handle 0x%x", ih);
     98  1.13      matt #endif
     99   1.2   garbled 
    100  1.20  christos 	snprintf(buf, len, "irq %d", ih);
    101  1.20  christos 	return buf;
    102   1.2   garbled 
    103   1.2   garbled }
    104   1.2   garbled 
    105   1.2   garbled const struct evcnt *
    106   1.2   garbled genppc_pci_intr_evcnt(void *v, pci_intr_handle_t ih)
    107   1.2   garbled {
    108   1.2   garbled 
    109   1.2   garbled 	/* XXX for now, no evcnt parent reported */
    110   1.2   garbled 	return NULL;
    111   1.2   garbled }
    112   1.2   garbled 
    113   1.2   garbled void *
    114   1.2   garbled genppc_pci_intr_establish(void *v, pci_intr_handle_t ih, int level,
    115   1.2   garbled     int (*func)(void *), void *arg)
    116   1.2   garbled {
    117   1.2   garbled 
    118  1.13      matt #ifdef ICU_LEN
    119   1.2   garbled 	if (ih == 0 || ih >= ICU_LEN
    120   1.2   garbled #ifdef IRQ_SLAVE
    121   1.2   garbled 	    || ih == IRQ_SLAVE
    122   1.2   garbled #endif
    123   1.2   garbled 	    )
    124   1.2   garbled 		panic("pci_intr_establish: bogus handle 0x%x", ih);
    125  1.13      matt #endif
    126   1.2   garbled 
    127   1.2   garbled 	return intr_establish(ih, IST_LEVEL, level, func, arg);
    128   1.2   garbled }
    129   1.2   garbled 
    130   1.2   garbled void
    131   1.2   garbled genppc_pci_intr_disestablish(void *v, void *cookie)
    132   1.2   garbled {
    133   1.2   garbled 
    134   1.2   garbled 	intr_disestablish(cookie);
    135   1.2   garbled }
    136   1.2   garbled 
    137  1.13      matt int
    138  1.13      matt genppc_pci_intr_setattr(void *v, pci_intr_handle_t *ihp, int attr,
    139  1.13      matt     uint64_t data)
    140  1.13      matt {
    141  1.13      matt 
    142  1.13      matt 	return ENODEV;
    143  1.13      matt }
    144  1.13      matt 
    145   1.2   garbled void
    146  1.13      matt genppc_pci_conf_interrupt(void *v, int bus, int dev, int pin,
    147   1.2   garbled     int swiz, int *iline)
    148   1.2   garbled {
    149   1.2   garbled 	/* do nothing */
    150   1.2   garbled }
    151   1.2   garbled 
    152   1.2   garbled int
    153  1.13      matt genppc_pci_conf_hook(void *v, int bus, int dev, int func, pcireg_t id)
    154   1.2   garbled {
    155   1.2   garbled 	return (PCI_CONF_DEFAULT);
    156   1.2   garbled }
    157   1.2   garbled 
    158   1.2   garbled int
    159  1.10    dyoung genppc_pci_intr_map(const struct pci_attach_args *pa, pci_intr_handle_t *ihp)
    160   1.2   garbled {
    161   1.2   garbled 	int pin = pa->pa_intrpin;
    162   1.2   garbled 	int line = pa->pa_intrline;
    163   1.2   garbled 
    164   1.7   garbled #ifdef DEBUG
    165   1.3     perry 	printf("%s: pin: %d, line: %d\n", __func__, pin, line);
    166   1.2   garbled #endif
    167   1.2   garbled 
    168   1.2   garbled 	if (pin == 0) {
    169   1.2   garbled 		/* No IRQ used. */
    170   1.2   garbled 		aprint_error("pci_intr_map: interrupt pin %d\n", pin);
    171   1.2   garbled 		goto bad;
    172   1.2   garbled 	}
    173  1.18  macallan 
    174   1.2   garbled 	if (pin > 4) {
    175   1.2   garbled 		aprint_error("pci_intr_map: bad interrupt pin %d\n", pin);
    176   1.2   garbled 		goto bad;
    177   1.2   garbled 	}
    178   1.2   garbled 
    179   1.2   garbled 	/*
    180   1.2   garbled 	 * Section 6.2.4, `Miscellaneous Functions', says that 255 means
    181   1.2   garbled 	 * `unknown' or `no connection' on a PC.  We assume that a device with
    182   1.2   garbled 	 * `no connection' either doesn't have an interrupt (in which case the
    183   1.2   garbled 	 * pin number should be 0, and would have been noticed above), or
    184   1.2   garbled 	 * wasn't configured by the BIOS (in which case we punt, since there's
    185   1.2   garbled 	 * no real way we can know how the interrupt lines are mapped in the
    186   1.2   garbled 	 * hardware).
    187   1.2   garbled 	 *
    188   1.2   garbled 	 * XXX
    189   1.2   garbled 	 * Since IRQ 0 is only used by the clock, and we can't actually be sure
    190   1.2   garbled 	 * that the BIOS did its job, we also recognize that as meaning that
    191   1.2   garbled 	 * the BIOS has not configured the device.
    192   1.2   garbled 	 */
    193   1.2   garbled 	if (line == 0 || line == 255) {
    194   1.2   garbled 		aprint_error("pci_intr_map: no mapping for pin %c\n", '@' + pin);
    195   1.2   garbled 		goto bad;
    196  1.13      matt #ifdef ICU_LEN
    197   1.2   garbled 	} else {
    198   1.2   garbled 		if (line >= ICU_LEN) {
    199   1.2   garbled 			aprint_error("pci_intr_map: bad interrupt line %d\n", line);
    200   1.2   garbled 			goto bad;
    201   1.2   garbled 		}
    202  1.13      matt #endif
    203   1.2   garbled 	}
    204   1.2   garbled 
    205   1.2   garbled 	*ihp = line;
    206   1.2   garbled 	return 0;
    207   1.2   garbled 
    208   1.2   garbled bad:
    209   1.2   garbled 	*ihp = -1;
    210   1.2   garbled 	return 1;
    211   1.2   garbled }
    212   1.2   garbled 
    213  1.14      matt int
    214  1.14      matt genppc_pci_msi_request(const struct pci_attach_args *pa,
    215  1.14      matt     pci_msi_handle_t *msihp, size_t nmsirq, int ipl, int capid)
    216  1.14      matt {
    217  1.14      matt 	return EOPNOTSUPP;
    218  1.14      matt }
    219  1.14      matt 
    220  1.14      matt int
    221  1.14      matt genppc_pci_msi_type(void *v, pci_msi_handle_t msih)
    222  1.14      matt {
    223  1.14      matt 	panic("%s", __func__);
    224  1.14      matt }
    225  1.14      matt 
    226  1.14      matt size_t
    227  1.14      matt genppc_pci_msi_available(void *v, pci_msi_handle_t msih)
    228  1.14      matt {
    229  1.14      matt 	panic("%s", __func__);
    230  1.14      matt }
    231  1.14      matt 
    232  1.14      matt const char *
    233  1.14      matt genppc_pci_msi_string(void *v, pci_msi_handle_t msih, size_t msirq)
    234  1.14      matt {
    235  1.14      matt 	panic("%s", __func__);
    236  1.14      matt }
    237  1.14      matt 
    238  1.14      matt const struct evcnt *
    239  1.14      matt genppc_pci_msi_evcnt(void *v, pci_msi_handle_t msih, size_t msirq)
    240  1.14      matt {
    241  1.14      matt 	panic("%s", __func__);
    242  1.14      matt }
    243  1.14      matt 
    244  1.14      matt void *
    245  1.14      matt genppc_pci_msi_establish(void *v, pci_msi_handle_t msih, size_t msirq,
    246  1.14      matt 		    int ipl, int (*func)(void *), void *arg)
    247  1.14      matt {
    248  1.14      matt 	panic("%s", __func__);
    249  1.14      matt }
    250  1.14      matt 
    251  1.14      matt void *
    252  1.14      matt genppc_pci_msix_establish(void *v, pci_msi_handle_t msih, size_t vec,
    253  1.14      matt     size_t msirq, int ipl, int (*func)(void *), void *arg)
    254  1.14      matt {
    255  1.14      matt 	panic("%s", __func__);
    256  1.14      matt }
    257  1.14      matt 
    258  1.14      matt void
    259  1.14      matt genppc_pci_msi_disestablish(void *v, void *ih)
    260  1.14      matt {
    261  1.14      matt 	panic("%s", __func__);
    262  1.14      matt }
    263  1.14      matt 
    264  1.14      matt void
    265  1.14      matt genppc_pci_msi_free(void *v, pci_msi_handle_t msih, size_t msirq)
    266  1.14      matt {
    267  1.14      matt 	panic("%s", __func__);
    268  1.14      matt }
    269  1.14      matt 
    270  1.14      matt void
    271  1.14      matt genppc_pci_msi_release(void *v, pci_msi_handle_t msih)
    272  1.14      matt {
    273  1.14      matt 	panic("%s", __func__);
    274  1.14      matt }
    275  1.14      matt 
    276  1.14      matt void
    277  1.14      matt genppc_pci_chipset_msi_init(pci_chipset_tag_t pc)
    278  1.14      matt {
    279  1.14      matt 	pc->pc_msi_request = genppc_pci_msi_request;
    280  1.14      matt 	pc->pc_msi_type = genppc_pci_msi_type;
    281  1.14      matt 	pc->pc_msi_available = genppc_pci_msi_available;
    282  1.14      matt 	pc->pc_msi_evcnt = genppc_pci_msi_evcnt;
    283  1.14      matt 	pc->pc_msi_string = genppc_pci_msi_string;
    284  1.14      matt 	pc->pc_msi_establish = genppc_pci_msi_establish;
    285  1.14      matt 	pc->pc_msix_establish = genppc_pci_msix_establish;
    286  1.14      matt 	pc->pc_msi_disestablish = genppc_pci_msi_disestablish;
    287  1.14      matt 	pc->pc_msi_free = genppc_pci_msi_free;
    288  1.14      matt 	pc->pc_msi_release = genppc_pci_msi_release;
    289  1.14      matt }
    290  1.14      matt 
    291   1.4       phx #ifdef __HAVE_PCIIDE_MACHDEP_COMPAT_INTR_ESTABLISH
    292   1.5  macallan #include <machine/isa_machdep.h>
    293   1.4       phx #include "isa.h"
    294   1.4       phx 
    295  1.11      matt void *genppc_pciide_machdep_compat_intr_establish(device_t,
    296   1.4       phx     struct pci_attach_args *, int, int (*)(void *), void *);
    297   1.4       phx 
    298   1.4       phx void *
    299  1.11      matt genppc_pciide_machdep_compat_intr_establish(device_t dev,
    300   1.4       phx     struct pci_attach_args *pa, int chan, int (*func)(void *), void *arg)
    301   1.4       phx {
    302   1.4       phx #if NISA > 0
    303   1.4       phx 	int irq;
    304   1.4       phx 	void *cookie;
    305   1.4       phx 
    306   1.4       phx 	irq = PCIIDE_COMPAT_IRQ(chan);
    307   1.4       phx 	cookie = isa_intr_establish(NULL, irq, IST_LEVEL, IPL_BIO, func, arg);
    308   1.4       phx 	if (cookie == NULL)
    309   1.4       phx 		return (NULL);
    310  1.11      matt 	aprint_normal_dev(dev, "%s channel interrupting at irq %d\n",
    311   1.4       phx 	    PCIIDE_CHANNEL_NAME(chan), irq);
    312   1.4       phx 	return (cookie);
    313   1.4       phx #else
    314   1.4       phx 	panic("pciide_machdep_compat_intr_establish() called");
    315   1.4       phx #endif
    316   1.4       phx }
    317   1.4       phx #endif /* __HAVE_PCIIDE_MACHDEP_COMPAT_INTR_ESTABLISH */
    318