Home | History | Annotate | Line # | Download | only in pci
      1 /*	$NetBSD: pci_machdep.c,v 1.25 2015/02/18 16:47:59 macallan 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.25 2015/02/18 16:47:59 macallan Exp $");
     37 
     38 #include "opt_pci.h"
     39 #include "pci.h"
     40 
     41 #include <sys/types.h>
     42 #include <sys/param.h>
     43 #include <sys/time.h>
     44 #include <sys/systm.h>
     45 #include <sys/errno.h>
     46 #include <sys/device.h>
     47 
     48 #include <uvm/uvm_extern.h>
     49 
     50 #include <sys/bus.h>
     51 #include <machine/intr.h>
     52 #include <machine/sysconf.h>
     53 
     54 #include <dev/pci/pcivar.h>
     55 #include <dev/pci/pcireg.h>
     56 #include <dev/pci/pcidevs.h>
     57 #include <dev/pci/pciconf.h>
     58 
     59 struct mips_bus_dma_tag pci_bus_dma_tag;
     60 
     61 void
     62 pci_attach_hook(device_t parent, device_t self, struct pcibus_attach_args *pba)
     63 {
     64 	/*
     65 	 * PCI doesn't have any special needs; just use
     66 	 * the generic versions of these functions as
     67 	 * established in sgimips_bus_dma_init().
     68 	 */
     69 	pci_bus_dma_tag = sgimips_default_bus_dma_tag;	/* struct copy */
     70 
     71 	/* XXX */
     72 
     73 	return;
     74 }
     75 
     76 int
     77 pci_bus_maxdevs(pci_chipset_tag_t pc, int busno)
     78 {
     79 
     80 	return (*pc->pc_bus_maxdevs)(pc, busno);
     81 }
     82 
     83 pcitag_t
     84 pci_make_tag(pci_chipset_tag_t pc, int bus, int device, int function)
     85 {
     86 
     87 	return (bus << 16) | (device << 11) | (function << 8);
     88 }
     89 
     90 void
     91 pci_decompose_tag(pci_chipset_tag_t pc, pcitag_t tag, int *bp, int *dp, int *fp)
     92 {
     93 
     94 	if (bp != NULL)
     95 		*bp = (tag >> 16) & 0xff;
     96 	if (dp != NULL)
     97 		*dp = (tag >> 11) & 0x1f;
     98 	if (fp != NULL)
     99 		*fp = (tag >> 8) & 0x07;
    100 }
    101 
    102 pcireg_t
    103 pci_conf_read(pci_chipset_tag_t pc, pcitag_t tag, int reg)
    104 {
    105 
    106 	return (*pc->pc_conf_read)(pc, tag, reg);
    107 }
    108 
    109 void
    110 pci_conf_write(pci_chipset_tag_t pc, pcitag_t tag, int reg, pcireg_t data)
    111 {
    112 
    113 	(*pc->pc_conf_write)(pc, tag, reg, data);
    114 }
    115 
    116 int
    117 pci_intr_map(const struct pci_attach_args *pa, pci_intr_handle_t *ihp)
    118 {
    119 	return (*pa->pa_pc->pc_intr_map)(pa, ihp);
    120 }
    121 
    122 const char *
    123 pci_intr_string(pci_chipset_tag_t pc, pci_intr_handle_t ih, char *buf,
    124     size_t len)
    125 {
    126 	return (*pc->pc_intr_string)(pc, ih, buf, len);
    127 }
    128 
    129 const struct evcnt *
    130 pci_intr_evcnt(pci_chipset_tag_t pc, pci_intr_handle_t ih)
    131 {
    132 
    133 	/* XXX for now, no evcnt parent reported */
    134 	return NULL;
    135 }
    136 
    137 int
    138 pci_intr_setattr(pci_chipset_tag_t pc, pci_intr_handle_t *ih,
    139 		 int attr, uint64_t data)
    140 {
    141 
    142 	switch (attr) {
    143 	case PCI_INTR_MPSAFE:
    144 		return 0;
    145 	default:
    146 		return ENODEV;
    147 	}
    148 }
    149 
    150 void *
    151 pci_intr_establish(pci_chipset_tag_t pc, pci_intr_handle_t ih, int level,
    152 	int (*func)(void *), void *arg)
    153 {
    154 
    155 	return (void *)(*pc->intr_establish)(ih, 0, func, arg);
    156 }
    157 
    158 void
    159 pci_intr_disestablish(pci_chipset_tag_t pc, void *cookie)
    160 {
    161 
    162 	(*pc->intr_disestablish)(cookie);
    163 }
    164 
    165 #ifdef PCI_NETBSD_CONFIGURE
    166 int
    167 pci_conf_hook(pci_chipset_tag_t pc, int bus, int device, int function,
    168     pcireg_t id)
    169 {
    170 
    171 	if (pc->pc_conf_hook)
    172 		return (*pc->pc_conf_hook)(pc, bus, device, function, id);
    173 	else
    174 		return (PCI_CONF_DEFAULT);
    175 }
    176 
    177 void
    178 pci_conf_interrupt(pci_chipset_tag_t pc, int bus, int dev, int pin, int swiz,
    179     int *iline)
    180 {
    181 
    182 	return;
    183 }
    184 #endif
    185