Home | History | Annotate | Line # | Download | only in pci
pci_machdep.c revision 1.7
      1 /*	$NetBSD: pci_machdep.c,v 1.7 2003/07/15 03:35:54 lukem Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 2000 Soren S. Jorvang
      5  * All rights reserved.
      6  *
      7  * Redistribution and use in source and binary forms, with or without
      8  * modification, are permitted provided that the following conditions
      9  * are met:
     10  * 1. Redistributions of source code must retain the above copyright
     11  *    notice, this list of conditions and the following disclaimer.
     12  * 2. Redistributions in binary form must reproduce the above copyright
     13  *    notice, this list of conditions and the following disclaimer in the
     14  *    documentation and/or other materials provided with the distribution.
     15  * 3. All advertising materials mentioning features or use of this software
     16  *    must display the following acknowledgement:
     17  *          This product includes software developed for the
     18  *          NetBSD Project.  See http://www.netbsd.org/ for
     19  *          information about NetBSD.
     20  * 4. The name of the author may not be used to endorse or promote products
     21  *    derived from this software without specific prior written permission.
     22  *
     23  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     24  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     25  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     26  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     27  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     28  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     29  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     30  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     31  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     32  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     33  */
     34 
     35 #include <sys/cdefs.h>
     36 __KERNEL_RCSID(0, "$NetBSD: pci_machdep.c,v 1.7 2003/07/15 03:35:54 lukem Exp $");
     37 
     38 #include <sys/types.h>
     39 #include <sys/param.h>
     40 #include <sys/time.h>
     41 #include <sys/systm.h>
     42 #include <sys/errno.h>
     43 #include <sys/device.h>
     44 
     45 #include <uvm/uvm_extern.h>
     46 
     47 #define _SGIMIPS_BUS_DMA_PRIVATE
     48 #include <machine/bus.h>
     49 #include <machine/intr.h>
     50 
     51 #include <dev/pci/pcivar.h>
     52 #include <dev/pci/pcireg.h>
     53 #include <dev/pci/pcidevs.h>
     54 
     55 /*
     56  * PCI doesn't have any special needs; just use
     57  * the generic versions of these functions.
     58  */
     59 struct sgimips_bus_dma_tag pci_bus_dma_tag = {
     60 	_bus_dmamap_create,
     61 	_bus_dmamap_destroy,
     62 	_bus_dmamap_load,
     63 	_bus_dmamap_load_mbuf,
     64 	_bus_dmamap_load_uio,
     65 	_bus_dmamap_load_raw,
     66 	_bus_dmamap_unload,
     67 	_bus_dmamap_sync,
     68 	_bus_dmamem_alloc,
     69 	_bus_dmamem_free,
     70 	_bus_dmamem_map,
     71 	_bus_dmamem_unmap,
     72 	_bus_dmamem_mmap,
     73 };
     74 
     75 void
     76 pci_attach_hook(parent, self, pba)
     77 	struct device *parent, *self;
     78 	struct pcibus_attach_args *pba;
     79 {
     80 	/* XXX */
     81 
     82 	return;
     83 }
     84 
     85 int
     86 pci_bus_maxdevs(pc, busno)
     87 	pci_chipset_tag_t pc;
     88 	int busno;
     89 {
     90 	return 5;	/* 2 on-board SCSI chips, slots 0, 1 and 2 */
     91 }
     92 
     93 pcitag_t
     94 pci_make_tag(pc, bus, device, function)
     95 	pci_chipset_tag_t pc;
     96 	int bus, device, function;
     97 {
     98 	return (bus << 16) | (device << 11) | (function << 8);
     99 }
    100 
    101 void
    102 pci_decompose_tag(pc, tag, bp, dp, fp)
    103 	pci_chipset_tag_t pc;
    104 	pcitag_t tag;
    105 	int *bp, *dp, *fp;
    106 {
    107 	if (bp != NULL)
    108 		*bp = (tag >> 16) & 0xff;
    109 	if (dp != NULL)
    110 		*dp = (tag >> 11) & 0x1f;
    111 	if (fp != NULL)
    112 		*fp = (tag >> 8) & 0x07;
    113 }
    114 
    115 pcireg_t
    116 pci_conf_read(pc, tag, reg)
    117 	pci_chipset_tag_t pc;
    118 	pcitag_t tag;
    119 	int reg;
    120 {
    121 	return (*pc->pc_conf_read)(pc, tag, reg);
    122 }
    123 
    124 void
    125 pci_conf_write(pc, tag, reg, data)
    126 	pci_chipset_tag_t pc;
    127 	pcitag_t tag;
    128 	int reg;
    129 	pcireg_t data;
    130 {
    131 	(*pc->pc_conf_write)(pc, tag, reg, data);
    132 }
    133 
    134 int
    135 pci_intr_map(pa, ihp)
    136 	struct pci_attach_args *pa;
    137 	pci_intr_handle_t *ihp;
    138 {
    139 	pci_chipset_tag_t pc = pa->pa_pc;
    140 	pcitag_t intrtag = pa->pa_intrtag;
    141 	int pin = pa->pa_intrpin;
    142 	int bus, dev, func, start;
    143 
    144 	pci_decompose_tag(pc, intrtag, &bus, &dev, &func);
    145 
    146 	if (dev < 3 && pin != PCI_INTERRUPT_PIN_A)
    147 		panic("SCSI0 and SCSI1 must be hardwired!");
    148 
    149 	switch (pin) {
    150 	case PCI_INTERRUPT_PIN_NONE:
    151 		return -1;
    152 
    153 	case PCI_INTERRUPT_PIN_A:
    154 		/*
    155 		 * Each of SCSI{0,1}, & slots 0 - 2 has dedicated interrupt
    156 		 * for pin A?
    157 		 */
    158 		*ihp = dev + 7;
    159 		return 0;
    160 
    161 	case PCI_INTERRUPT_PIN_B:
    162 		start = 0;
    163 		break;
    164 	case PCI_INTERRUPT_PIN_C:
    165 		start = 1;
    166 		break;
    167 	case PCI_INTERRUPT_PIN_D:
    168 		start = 2;
    169 		break;
    170 	}
    171 
    172 	/* Pins B,C,D are mapped to PCI_SHARED0 - PCI_SHARED2 interrupts */
    173 	*ihp = 13 /* PCI_SHARED0 */ + (start + dev - 3) % 3;
    174 	return 0;
    175 }
    176 
    177 const char *
    178 pci_intr_string(pc, ih)
    179 	pci_chipset_tag_t pc;
    180 	pci_intr_handle_t ih;
    181 {
    182 	static char irqstr[32];
    183 
    184 	sprintf(irqstr, "crime interrupt %d", ih);
    185 	return irqstr;
    186 }
    187 
    188 const struct evcnt *
    189 pci_intr_evcnt(pc, ih)
    190 	pci_chipset_tag_t pc;
    191 	pci_intr_handle_t ih;
    192 {
    193 
    194 	/* XXX for now, no evcnt parent reported */
    195 	return NULL;
    196 }
    197 
    198 extern void *	crime_intr_establish(int, int, int, int (*)(void *), void *);
    199 
    200 void *
    201 pci_intr_establish(pc, ih, level, func, arg)
    202 	pci_chipset_tag_t pc;
    203 	pci_intr_handle_t ih;
    204 	int level, (*func)(void *);
    205 	void *arg;
    206 {
    207 	return crime_intr_establish(ih, 0, 0, func, arg);
    208 }
    209 
    210 void
    211 pci_intr_disestablish(pc, cookie)
    212 	pci_chipset_tag_t pc;
    213 	void *cookie;
    214 {
    215 	panic("pci_intr_disestablish: not implemented");
    216 
    217 	return;
    218 }
    219