Home | History | Annotate | Line # | Download | only in pci
pci_machdep.c revision 1.9
      1 /*	$NetBSD: pci_machdep.c,v 1.9 2003/10/05 15:38:08 tsutsui 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.9 2003/10/05 15:38:08 tsutsui 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 #include <sgimips/dev/crimevar.h>
     56 
     57 /*
     58  * PCI doesn't have any special needs; just use
     59  * the generic versions of these functions.
     60  */
     61 struct sgimips_bus_dma_tag pci_bus_dma_tag = {
     62 	_bus_dmamap_create,
     63 	_bus_dmamap_destroy,
     64 	_bus_dmamap_load,
     65 	_bus_dmamap_load_mbuf,
     66 	_bus_dmamap_load_uio,
     67 	_bus_dmamap_load_raw,
     68 	_bus_dmamap_unload,
     69 	_bus_dmamap_sync,
     70 	_bus_dmamem_alloc,
     71 	_bus_dmamem_free,
     72 	_bus_dmamem_map,
     73 	_bus_dmamem_unmap,
     74 	_bus_dmamem_mmap,
     75 };
     76 
     77 void
     78 pci_attach_hook(parent, self, pba)
     79 	struct device *parent, *self;
     80 	struct pcibus_attach_args *pba;
     81 {
     82 	/* XXX */
     83 
     84 	return;
     85 }
     86 
     87 int
     88 pci_bus_maxdevs(pc, busno)
     89 	pci_chipset_tag_t pc;
     90 	int busno;
     91 {
     92 
     93 	if (busno == 0)
     94 		return 5;	/* 2 on-board SCSI chips, slots 0, 1 and 2 */
     95 	else
     96 		return 0;	/* XXX */
     97 }
     98 
     99 pcitag_t
    100 pci_make_tag(pc, bus, device, function)
    101 	pci_chipset_tag_t pc;
    102 	int bus, device, function;
    103 {
    104 
    105 	return (bus << 16) | (device << 11) | (function << 8);
    106 }
    107 
    108 void
    109 pci_decompose_tag(pc, tag, bp, dp, fp)
    110 	pci_chipset_tag_t pc;
    111 	pcitag_t tag;
    112 	int *bp, *dp, *fp;
    113 {
    114 
    115 	if (bp != NULL)
    116 		*bp = (tag >> 16) & 0xff;
    117 	if (dp != NULL)
    118 		*dp = (tag >> 11) & 0x1f;
    119 	if (fp != NULL)
    120 		*fp = (tag >> 8) & 0x07;
    121 }
    122 
    123 pcireg_t
    124 pci_conf_read(pc, tag, reg)
    125 	pci_chipset_tag_t pc;
    126 	pcitag_t tag;
    127 	int reg;
    128 {
    129 
    130 	return (*pc->pc_conf_read)(pc, tag, reg);
    131 }
    132 
    133 void
    134 pci_conf_write(pc, tag, reg, data)
    135 	pci_chipset_tag_t pc;
    136 	pcitag_t tag;
    137 	int reg;
    138 	pcireg_t data;
    139 {
    140 
    141 	(*pc->pc_conf_write)(pc, tag, reg, data);
    142 }
    143 
    144 int
    145 pci_intr_map(pa, ihp)
    146 	struct pci_attach_args *pa;
    147 	pci_intr_handle_t *ihp;
    148 {
    149 	pci_chipset_tag_t pc = pa->pa_pc;
    150 	pcitag_t intrtag = pa->pa_intrtag;
    151 	int pin = pa->pa_intrpin;
    152 	int bus, dev, func, start;
    153 
    154 	pci_decompose_tag(pc, intrtag, &bus, &dev, &func);
    155 
    156 	if (dev < 3 && pin != PCI_INTERRUPT_PIN_A)
    157 		panic("SCSI0 and SCSI1 must be hardwired!");
    158 
    159 	switch (pin) {
    160 	case PCI_INTERRUPT_PIN_NONE:
    161 		return -1;
    162 
    163 	case PCI_INTERRUPT_PIN_A:
    164 		/*
    165 		 * Each of SCSI{0,1}, & slots 0 - 2 has dedicated interrupt
    166 		 * for pin A?
    167 		 */
    168 		*ihp = dev + 7;
    169 		return 0;
    170 
    171 	case PCI_INTERRUPT_PIN_B:
    172 		start = 0;
    173 		break;
    174 	case PCI_INTERRUPT_PIN_C:
    175 		start = 1;
    176 		break;
    177 	case PCI_INTERRUPT_PIN_D:
    178 		start = 2;
    179 		break;
    180 	}
    181 
    182 	/* Pins B,C,D are mapped to PCI_SHARED0 - PCI_SHARED2 interrupts */
    183 	*ihp = 13 /* PCI_SHARED0 */ + (start + dev - 3) % 3;
    184 	return 0;
    185 }
    186 
    187 const char *
    188 pci_intr_string(pc, ih)
    189 	pci_chipset_tag_t pc;
    190 	pci_intr_handle_t ih;
    191 {
    192 	static char irqstr[32];
    193 
    194 	sprintf(irqstr, "crime interrupt %d", ih);
    195 	return irqstr;
    196 }
    197 
    198 const struct evcnt *
    199 pci_intr_evcnt(pc, ih)
    200 	pci_chipset_tag_t pc;
    201 	pci_intr_handle_t ih;
    202 {
    203 
    204 	/* XXX for now, no evcnt parent reported */
    205 	return NULL;
    206 }
    207 
    208 void *
    209 pci_intr_establish(pc, ih, level, func, arg)
    210 	pci_chipset_tag_t pc;
    211 	pci_intr_handle_t ih;
    212 	int level, (*func)(void *);
    213 	void *arg;
    214 {
    215 
    216 	return crime_intr_establish(ih, 0, 0, func, arg);
    217 }
    218 
    219 void
    220 pci_intr_disestablish(pc, cookie)
    221 	pci_chipset_tag_t pc;
    222 	void *cookie;
    223 {
    224 
    225 	panic("pci_intr_disestablish: not implemented");
    226 }
    227