Home | History | Annotate | Line # | Download | only in dev
pci_machdep.c revision 1.63
      1  1.63       mrg /*	$NetBSD: pci_machdep.c,v 1.63 2009/11/27 22:31:29 mrg Exp $	*/
      2   1.1       mrg 
      3   1.1       mrg /*
      4   1.5       mrg  * Copyright (c) 1999, 2000 Matthew R. Green
      5   1.1       mrg  * All rights reserved.
      6   1.1       mrg  *
      7   1.1       mrg  * Redistribution and use in source and binary forms, with or without
      8   1.1       mrg  * modification, are permitted provided that the following conditions
      9   1.1       mrg  * are met:
     10   1.1       mrg  * 1. Redistributions of source code must retain the above copyright
     11   1.1       mrg  *    notice, this list of conditions and the following disclaimer.
     12   1.1       mrg  * 2. Redistributions in binary form must reproduce the above copyright
     13   1.1       mrg  *    notice, this list of conditions and the following disclaimer in the
     14   1.1       mrg  *    documentation and/or other materials provided with the distribution.
     15   1.1       mrg  *
     16   1.1       mrg  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     17   1.1       mrg  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     18   1.1       mrg  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     19   1.1       mrg  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     20   1.1       mrg  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
     21   1.1       mrg  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
     22   1.1       mrg  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
     23   1.1       mrg  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
     24   1.1       mrg  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     25   1.1       mrg  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     26   1.1       mrg  * SUCH DAMAGE.
     27   1.1       mrg  */
     28   1.1       mrg 
     29   1.1       mrg /*
     30   1.1       mrg  * functions expected by the MI PCI code.
     31   1.1       mrg  */
     32  1.38     lukem 
     33  1.38     lukem #include <sys/cdefs.h>
     34  1.63       mrg __KERNEL_RCSID(0, "$NetBSD: pci_machdep.c,v 1.63 2009/11/27 22:31:29 mrg Exp $");
     35   1.1       mrg 
     36   1.1       mrg #include <sys/types.h>
     37   1.1       mrg #include <sys/param.h>
     38   1.1       mrg #include <sys/time.h>
     39   1.1       mrg #include <sys/systm.h>
     40   1.1       mrg #include <sys/errno.h>
     41   1.1       mrg #include <sys/device.h>
     42   1.1       mrg #include <sys/malloc.h>
     43   1.1       mrg 
     44   1.1       mrg #define _SPARC_BUS_DMA_PRIVATE
     45   1.1       mrg #include <machine/bus.h>
     46   1.1       mrg #include <machine/autoconf.h>
     47  1.22       eeh #include <machine/openfirm.h>
     48   1.1       mrg #include <dev/pci/pcivar.h>
     49   1.1       mrg #include <dev/pci/pcireg.h>
     50   1.1       mrg 
     51  1.19       mrg #include <dev/ofw/ofw_pci.h>
     52  1.19       mrg 
     53   1.1       mrg #include <sparc64/dev/iommureg.h>
     54   1.1       mrg #include <sparc64/dev/iommuvar.h>
     55   1.1       mrg #include <sparc64/dev/psychoreg.h>
     56   1.1       mrg #include <sparc64/dev/psychovar.h>
     57  1.37    martin #include <sparc64/sparc64/cache.h>
     58  1.39    petrov 
     59  1.49  drochner #include "locators.h"
     60  1.49  drochner 
     61  1.39    petrov #ifdef DEBUG
     62  1.39    petrov #define SPDB_CONF	0x01
     63  1.39    petrov #define SPDB_INTR	0x04
     64  1.39    petrov #define SPDB_INTMAP	0x08
     65  1.39    petrov #define SPDB_PROBE	0x20
     66  1.61       mrg #define SPDB_TAG	0x40
     67  1.39    petrov int sparc_pci_debug = 0x0;
     68  1.39    petrov #define DPRINTF(l, s)	do { if (sparc_pci_debug & l) printf s; } while (0)
     69  1.39    petrov #else
     70  1.39    petrov #define DPRINTF(l, s)
     71  1.39    petrov #endif
     72   1.1       mrg 
     73   1.1       mrg /* this is a base to be copied */
     74   1.1       mrg struct sparc_pci_chipset _sparc_pci_chipset = {
     75  1.52    martin 	.cookie = NULL,
     76   1.1       mrg };
     77   1.2       mrg 
     78  1.30   thorpej static pcitag_t
     79  1.30   thorpej ofpci_make_tag(pci_chipset_tag_t pc, int node, int b, int d, int f)
     80  1.30   thorpej {
     81  1.30   thorpej 	pcitag_t tag;
     82  1.61       mrg 	pcireg_t reg;
     83  1.30   thorpej 
     84  1.30   thorpej 	tag = PCITAG_CREATE(node, b, d, f);
     85  1.30   thorpej 
     86  1.61       mrg 	DPRINTF(SPDB_TAG,
     87  1.61       mrg 		("%s: creating tag for node %d bus %d dev %d fn %d\n",
     88  1.61       mrg 		 __func__, node, b, d, f));
     89  1.61       mrg 
     90  1.30   thorpej 	/* Enable all the different spaces for this device */
     91  1.61       mrg 	reg = pci_conf_read(pc, tag, PCI_COMMAND_STATUS_REG);
     92  1.61       mrg 	reg |= PCI_COMMAND_MEM_ENABLE|PCI_COMMAND_MASTER_ENABLE|
     93  1.61       mrg 	       PCI_COMMAND_IO_ENABLE;
     94  1.61       mrg 	pci_conf_write(pc, tag, PCI_COMMAND_STATUS_REG, reg);
     95  1.61       mrg 
     96  1.30   thorpej 	return (tag);
     97  1.30   thorpej }
     98  1.30   thorpej 
     99   1.1       mrg /*
    100   1.1       mrg  * functions provided to the MI code.
    101   1.1       mrg  */
    102   1.1       mrg 
    103   1.1       mrg void
    104  1.51       cdi pci_attach_hook(struct device *parent, struct device *self,
    105  1.51       cdi 	struct pcibus_attach_args *pba)
    106   1.1       mrg {
    107   1.1       mrg }
    108   1.1       mrg 
    109   1.1       mrg int
    110  1.51       cdi pci_bus_maxdevs(pci_chipset_tag_t pc, int busno)
    111   1.1       mrg {
    112   1.1       mrg 
    113   1.1       mrg 	return 32;
    114   1.1       mrg }
    115  1.19       mrg 
    116   1.1       mrg pcitag_t
    117  1.51       cdi pci_make_tag(pci_chipset_tag_t pc, int b, int d, int f)
    118   1.1       mrg {
    119  1.46  nakayama 	struct ofw_pci_register reg;
    120  1.22       eeh 	pcitag_t tag;
    121  1.51       cdi 	int (*valid)(void *);
    122  1.22       eeh 	int node, len;
    123  1.22       eeh #ifdef DEBUG
    124  1.22       eeh 	char name[80];
    125  1.40    martin 	memset(name, 0, sizeof(name));
    126  1.22       eeh #endif
    127   1.1       mrg 
    128  1.35  nakayama 	/*
    129  1.35  nakayama 	 * Refer to the PCI/CardBus bus node first.
    130  1.35  nakayama 	 * It returns a tag if node is present and bus is valid.
    131  1.35  nakayama 	 */
    132  1.35  nakayama 	if (0 <= b && b < 256) {
    133  1.62  nakayama 		KASSERT(pc->spc_busnode != NULL);
    134  1.60       mrg 		node = (*pc->spc_busnode)[b].node;
    135  1.60       mrg 		valid = (*pc->spc_busnode)[b].valid;
    136  1.35  nakayama 		if (node != 0 && d == 0 &&
    137  1.60       mrg 		    (valid == NULL || (*valid)((*pc->spc_busnode)[b].arg)))
    138  1.35  nakayama 			return ofpci_make_tag(pc, node, b, d, f);
    139  1.35  nakayama 	}
    140  1.35  nakayama 
    141  1.22       eeh 	/*
    142  1.22       eeh 	 * Hunt for the node that corresponds to this device
    143  1.22       eeh 	 *
    144  1.22       eeh 	 * We could cache this info in an array in the parent
    145  1.22       eeh 	 * device... except then we have problems with devices
    146  1.22       eeh 	 * attached below pci-pci bridges, and we would need to
    147  1.22       eeh 	 * add special code to the pci-pci bridge to cache this
    148  1.22       eeh 	 * info.
    149  1.22       eeh 	 */
    150   1.1       mrg 
    151  1.22       eeh 	tag = PCITAG_CREATE(-1, b, d, f);
    152  1.22       eeh 	node = pc->rootnode;
    153  1.22       eeh 	/*
    154  1.22       eeh 	 * First make sure we're on the right bus.  If our parent
    155  1.22       eeh 	 * has a bus-range property and we're not in the range,
    156  1.22       eeh 	 * then we're obviously on the wrong bus.  So go up one
    157  1.22       eeh 	 * level.
    158  1.22       eeh 	 */
    159  1.22       eeh #ifdef DEBUG
    160  1.22       eeh 	if (sparc_pci_debug & SPDB_PROBE) {
    161  1.42        pk 		printf("curnode %x %s\n", node,
    162  1.42        pk 			prom_getpropstringA(node, "name", name, sizeof(name)));
    163  1.22       eeh 	}
    164  1.22       eeh #endif
    165  1.22       eeh #if 0
    166  1.22       eeh 	while ((OF_getprop(OF_parent(node), "bus-range", (void *)&busrange,
    167  1.22       eeh 		sizeof(busrange)) == sizeof(busrange)) &&
    168  1.22       eeh 		(b < busrange[0] || b > busrange[1])) {
    169  1.22       eeh 		/* Out of range, go up one */
    170  1.22       eeh 		node = OF_parent(node);
    171  1.22       eeh #ifdef DEBUG
    172  1.22       eeh 		if (sparc_pci_debug & SPDB_PROBE) {
    173  1.42        pk 			printf("going up to node %x %s\n", node,
    174  1.42        pk 			prom_getpropstringA(node, "name", name, sizeof(name)));
    175  1.22       eeh 		}
    176  1.22       eeh #endif
    177  1.22       eeh 	}
    178  1.22       eeh #endif
    179  1.22       eeh 	/*
    180  1.22       eeh 	 * Now traverse all peers until we find the node or we find
    181  1.22       eeh 	 * the right bridge.
    182  1.22       eeh 	 *
    183  1.22       eeh 	 * XXX We go up one and down one to make sure nobody's missed.
    184  1.22       eeh 	 * but this should not be necessary.
    185  1.22       eeh 	 */
    186  1.42        pk 	for (node = ((node)); node; node = prom_nextsibling(node)) {
    187   1.1       mrg 
    188  1.22       eeh #ifdef DEBUG
    189  1.22       eeh 		if (sparc_pci_debug & SPDB_PROBE) {
    190  1.43        pk 			printf("checking node %x %s\n", node,
    191  1.42        pk 			prom_getpropstringA(node, "name", name, sizeof(name)));
    192  1.42        pk 
    193  1.22       eeh 		}
    194  1.22       eeh #endif
    195   1.1       mrg 
    196  1.22       eeh #if 1
    197   1.1       mrg 		/*
    198  1.22       eeh 		 * Check for PCI-PCI bridges.  If the device we want is
    199  1.22       eeh 		 * in the bus-range for that bridge, work our way down.
    200   1.1       mrg 		 */
    201  1.44        pk 		while (1) {
    202  1.44        pk 			int busrange[2], *brp;
    203  1.44        pk 			len = 2;
    204  1.44        pk 			brp = busrange;
    205  1.45  nakayama 			if (prom_getprop(node, "bus-range", sizeof(*brp),
    206  1.45  nakayama 					 &len, &brp) != 0)
    207  1.44        pk 				break;
    208  1.44        pk 			if (len != 2 || b < busrange[0] || b > busrange[1])
    209  1.44        pk 				break;
    210  1.22       eeh 			/* Go down 1 level */
    211  1.42        pk 			node = prom_firstchild(node);
    212  1.22       eeh #ifdef DEBUG
    213  1.22       eeh 			if (sparc_pci_debug & SPDB_PROBE) {
    214  1.43        pk 				printf("going down to node %x %s\n", node,
    215  1.42        pk 					prom_getpropstringA(node, "name",
    216  1.42        pk 							name, sizeof(name)));
    217  1.22       eeh 			}
    218  1.22       eeh #endif
    219   1.1       mrg 		}
    220  1.44        pk #endif /*1*/
    221  1.22       eeh 		/*
    222  1.22       eeh 		 * We only really need the first `reg' property.
    223  1.22       eeh 		 *
    224  1.22       eeh 		 * For simplicity, we'll query the `reg' when we
    225  1.22       eeh 		 * need it.  Otherwise we could malloc() it, but
    226  1.22       eeh 		 * that gets more complicated.
    227  1.22       eeh 		 */
    228  1.46  nakayama 		len = prom_getproplen(node, "reg");
    229  1.46  nakayama 		if (len < sizeof(reg))
    230  1.46  nakayama 			continue;
    231  1.46  nakayama 		if (OF_getprop(node, "reg", (void *)&reg, sizeof(reg)) != len)
    232  1.44        pk 			panic("pci_probe_bus: OF_getprop len botch");
    233  1.22       eeh 
    234  1.22       eeh 		if (b != OFW_PCI_PHYS_HI_BUS(reg.phys_hi))
    235  1.22       eeh 			continue;
    236  1.22       eeh 		if (d != OFW_PCI_PHYS_HI_DEVICE(reg.phys_hi))
    237  1.22       eeh 			continue;
    238  1.22       eeh 		if (f != OFW_PCI_PHYS_HI_FUNCTION(reg.phys_hi))
    239  1.22       eeh 			continue;
    240  1.22       eeh 
    241  1.22       eeh 		/* Got a match */
    242  1.27       eeh 		tag = ofpci_make_tag(pc, node, b, d, f);
    243  1.22       eeh 
    244  1.22       eeh 		return (tag);
    245   1.1       mrg 	}
    246  1.22       eeh 	/* No device found -- return a dead tag */
    247  1.27       eeh 	return (tag);
    248  1.28   thorpej }
    249  1.28   thorpej 
    250  1.28   thorpej void
    251  1.51       cdi pci_decompose_tag(pci_chipset_tag_t pc, pcitag_t tag, int *bp, int *dp, int *fp)
    252  1.28   thorpej {
    253  1.28   thorpej 
    254  1.28   thorpej 	if (bp != NULL)
    255  1.28   thorpej 		*bp = PCITAG_BUS(tag);
    256  1.28   thorpej 	if (dp != NULL)
    257  1.28   thorpej 		*dp = PCITAG_DEV(tag);
    258  1.28   thorpej 	if (fp != NULL)
    259  1.28   thorpej 		*fp = PCITAG_FUN(tag);
    260  1.27       eeh }
    261  1.27       eeh 
    262  1.30   thorpej int
    263  1.49  drochner sparc64_pci_enumerate_bus(struct pci_softc *sc, const int *locators,
    264  1.30   thorpej     int (*match)(struct pci_attach_args *), struct pci_attach_args *pap)
    265  1.27       eeh {
    266  1.30   thorpej 	struct ofw_pci_register reg;
    267  1.30   thorpej 	pci_chipset_tag_t pc = sc->sc_pc;
    268  1.27       eeh 	pcitag_t tag;
    269  1.35  nakayama 	pcireg_t class, csr, bhlc, ic;
    270  1.30   thorpej 	int node, b, d, f, ret;
    271  1.37    martin 	int bus_frequency, lt, cl, cacheline;
    272  1.30   thorpej 	char name[30];
    273  1.32       eeh 	extern int pci_config_dump;
    274  1.30   thorpej 
    275  1.31       eeh 	if (sc->sc_bridgetag)
    276  1.31       eeh 		node = PCITAG_NODE(*sc->sc_bridgetag);
    277  1.31       eeh 	else
    278  1.31       eeh 		node = pc->rootnode;
    279  1.31       eeh 
    280  1.42        pk 	bus_frequency =
    281  1.42        pk 		prom_getpropint(node, "clock-frequency", 33000000) / 1000000;
    282  1.35  nakayama 
    283  1.37    martin 	/*
    284  1.37    martin 	 * Make sure the cache line size is at least as big as the
    285  1.37    martin 	 * ecache line and the streaming cache (64 byte).
    286  1.37    martin 	 */
    287  1.53       mrg 	cacheline = max(ecache_min_line_size, 64);
    288  1.37    martin 	KASSERT((cacheline/64)*64 == cacheline &&
    289  1.53       mrg 	    (cacheline/ecache_min_line_size)*ecache_min_line_size == cacheline &&
    290  1.37    martin 	    (cacheline/4)*4 == cacheline);
    291  1.37    martin 
    292  1.32       eeh 	/* Turn on parity for the bus. */
    293  1.32       eeh 	tag = ofpci_make_tag(pc, node, sc->sc_bus, 0, 0);
    294  1.32       eeh 	csr = pci_conf_read(pc, tag, PCI_COMMAND_STATUS_REG);
    295  1.32       eeh 	csr |= PCI_COMMAND_PARITY_ENABLE;
    296  1.32       eeh 	pci_conf_write(pc, tag, PCI_COMMAND_STATUS_REG, csr);
    297  1.32       eeh 
    298  1.35  nakayama 	/*
    299  1.35  nakayama 	 * Initialize the latency timer register.
    300  1.35  nakayama 	 * The value 0x40 is from Solaris.
    301  1.35  nakayama 	 */
    302  1.35  nakayama 	bhlc = pci_conf_read(pc, tag, PCI_BHLC_REG);
    303  1.35  nakayama 	bhlc &= ~(PCI_LATTIMER_MASK << PCI_LATTIMER_SHIFT);
    304  1.35  nakayama 	bhlc |= 0x40 << PCI_LATTIMER_SHIFT;
    305  1.35  nakayama 	pci_conf_write(pc, tag, PCI_BHLC_REG, bhlc);
    306  1.35  nakayama 
    307  1.32       eeh 	if (pci_config_dump) pci_conf_print(pc, tag, NULL);
    308  1.32       eeh 
    309  1.42        pk 	for (node = prom_firstchild(node); node != 0 && node != -1;
    310  1.42        pk 	     node = prom_nextsibling(node)) {
    311  1.30   thorpej 		name[0] = name[29] = 0;
    312  1.42        pk 		prom_getpropstringA(node, "name", name, sizeof(name));
    313  1.27       eeh 
    314  1.30   thorpej 		if (OF_getprop(node, "class-code", &class, sizeof(class)) !=
    315  1.30   thorpej 		    sizeof(class))
    316  1.30   thorpej 			continue;
    317  1.30   thorpej 		if (OF_getprop(node, "reg", &reg, sizeof(reg)) < sizeof(reg))
    318  1.30   thorpej 			panic("pci_enumerate_bus: \"%s\" regs too small", name);
    319  1.27       eeh 
    320  1.30   thorpej 		b = OFW_PCI_PHYS_HI_BUS(reg.phys_hi);
    321  1.30   thorpej 		d = OFW_PCI_PHYS_HI_DEVICE(reg.phys_hi);
    322  1.30   thorpej 		f = OFW_PCI_PHYS_HI_FUNCTION(reg.phys_hi);
    323  1.30   thorpej 
    324  1.30   thorpej 		if (sc->sc_bus != b) {
    325  1.57      cube 			aprint_error_dev(sc->sc_dev, "WARNING: incorrect "
    326  1.57      cube 			    "bus # for \"%s\" (%d/%d/%d)\n", name, b, d, f);
    327  1.30   thorpej 			continue;
    328  1.30   thorpej 		}
    329  1.49  drochner                 if ((locators[PCICF_DEV] != PCICF_DEV_DEFAULT) &&
    330  1.49  drochner                     (locators[PCICF_DEV] != d))
    331  1.49  drochner                         continue;
    332  1.49  drochner 		if ((locators[PCICF_FUNCTION] != PCICF_FUNCTION_DEFAULT) &&
    333  1.49  drochner 		    (locators[PCICF_FUNCTION] != f))
    334  1.49  drochner 			continue;
    335  1.27       eeh 
    336  1.30   thorpej 		tag = ofpci_make_tag(pc, node, b, d, f);
    337  1.32       eeh 
    338  1.32       eeh 		/*
    339  1.32       eeh 		 * Turn on parity and fast-back-to-back for the device.
    340  1.32       eeh 		 */
    341  1.32       eeh 		csr = pci_conf_read(pc, tag, PCI_COMMAND_STATUS_REG);
    342  1.32       eeh 		if (csr & PCI_STATUS_BACKTOBACK_SUPPORT)
    343  1.32       eeh 			csr |= PCI_COMMAND_BACKTOBACK_ENABLE;
    344  1.32       eeh 		csr |= PCI_COMMAND_PARITY_ENABLE;
    345  1.32       eeh 		pci_conf_write(pc, tag, PCI_COMMAND_STATUS_REG, csr);
    346  1.32       eeh 
    347  1.35  nakayama 		/*
    348  1.35  nakayama 		 * Initialize the latency timer register for busmaster
    349  1.35  nakayama 		 * devices to work properly.
    350  1.35  nakayama 		 *   latency-timer = min-grant * bus-freq / 4  (from FreeBSD)
    351  1.35  nakayama 		 * Also initialize the cache line size register.
    352  1.35  nakayama 		 * Solaris anytime sets this register to the value 0x10.
    353  1.35  nakayama 		 */
    354  1.35  nakayama 		bhlc = pci_conf_read(pc, tag, PCI_BHLC_REG);
    355  1.35  nakayama 		ic = pci_conf_read(pc, tag, PCI_INTERRUPT_REG);
    356  1.35  nakayama 
    357  1.35  nakayama 		lt = min(PCI_MIN_GNT(ic) * bus_frequency / 4, 255);
    358  1.35  nakayama 		if (lt == 0 || lt < PCI_LATTIMER(bhlc))
    359  1.35  nakayama 			lt = PCI_LATTIMER(bhlc);
    360  1.35  nakayama 
    361  1.35  nakayama 		cl = PCI_CACHELINE(bhlc);
    362  1.35  nakayama 		if (cl == 0)
    363  1.37    martin 			cl = cacheline;
    364  1.35  nakayama 
    365  1.35  nakayama 		bhlc &= ~((PCI_LATTIMER_MASK << PCI_LATTIMER_SHIFT) |
    366  1.35  nakayama 			  (PCI_CACHELINE_MASK << PCI_CACHELINE_SHIFT));
    367  1.35  nakayama 		bhlc |= (lt << PCI_LATTIMER_SHIFT) |
    368  1.35  nakayama 			(cl << PCI_CACHELINE_SHIFT);
    369  1.35  nakayama 		pci_conf_write(pc, tag, PCI_BHLC_REG, bhlc);
    370  1.35  nakayama 
    371  1.30   thorpej 		ret = pci_probe_device(sc, tag, match, pap);
    372  1.30   thorpej 		if (match != NULL && ret != 0)
    373  1.30   thorpej 			return (ret);
    374  1.30   thorpej 	}
    375  1.30   thorpej 	return (0);
    376   1.1       mrg }
    377   1.1       mrg 
    378   1.1       mrg /*
    379   1.1       mrg  * interrupt mapping foo.
    380  1.20       mrg  * XXX: how does this deal with multiple interrupts for a device?
    381   1.1       mrg  */
    382   1.1       mrg int
    383  1.51       cdi pci_intr_map(struct pci_attach_args *pa, pci_intr_handle_t *ihp)
    384   1.1       mrg {
    385  1.22       eeh 	pcitag_t tag = pa->pa_tag;
    386  1.44        pk 	int interrupts, *intp;
    387  1.22       eeh 	int len, node = PCITAG_NODE(tag);
    388  1.22       eeh 	char devtype[30];
    389  1.22       eeh 
    390  1.44        pk 	intp = &interrupts;
    391  1.44        pk 	len = 1;
    392  1.44        pk 	if (prom_getprop(node, "interrupts", sizeof(interrupts),
    393  1.44        pk 			&len, &intp) != 0 || len != 1) {
    394  1.22       eeh 		DPRINTF(SPDB_INTMAP,
    395  1.22       eeh 			("pci_intr_map: could not read interrupts\n"));
    396  1.22       eeh 		return (ENODEV);
    397  1.22       eeh 	}
    398  1.20       mrg 
    399  1.22       eeh 	if (OF_mapintr(node, &interrupts, sizeof(interrupts),
    400  1.23       eeh 		sizeof(interrupts)) < 0) {
    401  1.22       eeh 		printf("OF_mapintr failed\n");
    402  1.60       mrg 		KASSERT(pa->pa_pc->spc_find_ino);
    403  1.60       mrg 		pa->pa_pc->spc_find_ino(pa, &interrupts);
    404  1.22       eeh 	}
    405  1.44        pk 
    406  1.22       eeh 	/* Try to find an IPL for this type of device. */
    407  1.44        pk 	prom_getpropstringA(node, "device_type", devtype, sizeof(devtype));
    408  1.44        pk 	for (len = 0; intrmap[len].in_class != NULL; len++)
    409  1.44        pk 		if (strcmp(intrmap[len].in_class, devtype) == 0) {
    410  1.44        pk 			interrupts |= INTLEVENCODE(intrmap[len].in_lev);
    411  1.44        pk 			break;
    412  1.44        pk 		}
    413  1.20       mrg 
    414  1.22       eeh 	/* XXXX -- we use the ino.  What if there is a valid IGN? */
    415  1.22       eeh 	*ihp = interrupts;
    416  1.22       eeh 	return (0);
    417   1.1       mrg }
    418   1.1       mrg 
    419   1.1       mrg const char *
    420  1.51       cdi pci_intr_string(pci_chipset_tag_t pc, pci_intr_handle_t ih)
    421   1.1       mrg {
    422   1.1       mrg 	static char str[16];
    423   1.1       mrg 
    424  1.22       eeh 	sprintf(str, "ivec %x", ih);
    425  1.63       mrg 	DPRINTF(SPDB_INTR, ("pci_intr_string: returning %s\n", str));
    426   1.1       mrg 
    427   1.1       mrg 	return (str);
    428   1.8       cgd }
    429   1.8       cgd 
    430   1.8       cgd const struct evcnt *
    431  1.51       cdi pci_intr_evcnt(pci_chipset_tag_t pc, pci_intr_handle_t ih)
    432   1.8       cgd {
    433   1.8       cgd 
    434   1.8       cgd 	/* XXX for now, no evcnt parent reported */
    435   1.8       cgd 	return NULL;
    436   1.1       mrg }
    437   1.1       mrg 
    438  1.59        ad int
    439  1.59        ad pci_intr_setattr(pci_chipset_tag_t pc, pci_intr_handle_t *ih,
    440  1.59        ad 		 int attr, uint64_t data)
    441  1.59        ad {
    442  1.59        ad 
    443  1.59        ad 	switch (attr) {
    444  1.59        ad 	case PCI_INTR_MPSAFE:
    445  1.59        ad 		return 0;
    446  1.59        ad 	default:
    447  1.59        ad 		return ENODEV;
    448  1.59        ad 	}
    449  1.59        ad }
    450  1.59        ad 
    451   1.1       mrg void
    452  1.51       cdi pci_intr_disestablish(pci_chipset_tag_t pc, void *cookie)
    453   1.1       mrg {
    454   1.1       mrg 
    455   1.1       mrg 	DPRINTF(SPDB_INTR, ("pci_intr_disestablish: cookie %p\n", cookie));
    456   1.1       mrg 
    457   1.1       mrg 	/* XXX */
    458  1.55    martin 	/* panic("can't disestablish PCI interrupts yet"); */
    459   1.1       mrg }
    460  1.61       mrg 
    461  1.61       mrg int
    462  1.61       mrg sparc_pci_childspace(int type)
    463  1.61       mrg {
    464  1.61       mrg 	int ss;
    465  1.61       mrg 
    466  1.61       mrg 	switch (type) {
    467  1.61       mrg 	case PCI_CONFIG_BUS_SPACE:
    468  1.61       mrg 		ss = 0x00;
    469  1.61       mrg 		break;
    470  1.61       mrg 	case PCI_IO_BUS_SPACE:
    471  1.61       mrg 		ss = 0x01;
    472  1.61       mrg 		break;
    473  1.61       mrg 	case PCI_MEMORY_BUS_SPACE:
    474  1.61       mrg 		ss = 0x02;
    475  1.61       mrg 		break;
    476  1.61       mrg #if 0
    477  1.61       mrg 	/* we don't do 64 bit memory space */
    478  1.61       mrg 	case PCI_MEMORY64_BUS_SPACE:
    479  1.61       mrg 		ss = 0x03;
    480  1.61       mrg 		break;
    481  1.61       mrg #endif
    482  1.61       mrg 	default:
    483  1.61       mrg 		panic("get_childspace: unknown bus type");
    484  1.61       mrg 	}
    485  1.61       mrg 
    486  1.61       mrg 	return (ss);
    487  1.61       mrg }
    488