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