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