Home | History | Annotate | Line # | Download | only in dev
pci_machdep.c revision 1.57.6.1
      1  1.57.6.1  wrstuden /*	$NetBSD: pci_machdep.c,v 1.57.6.1 2008/06/23 04:30:43 wrstuden 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.57.6.1  wrstuden __KERNEL_RCSID(0, "$NetBSD: pci_machdep.c,v 1.57.6.1 2008/06/23 04:30:43 wrstuden 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.39    petrov int sparc_pci_debug = 0x0;
     67      1.39    petrov #define DPRINTF(l, s)	do { if (sparc_pci_debug & l) printf s; } while (0)
     68      1.39    petrov #else
     69      1.39    petrov #define DPRINTF(l, s)
     70      1.39    petrov #endif
     71       1.1       mrg 
     72       1.1       mrg /* this is a base to be copied */
     73       1.1       mrg struct sparc_pci_chipset _sparc_pci_chipset = {
     74      1.52    martin 	.cookie = NULL,
     75       1.1       mrg };
     76       1.2       mrg 
     77      1.41    petrov static int pci_find_ino(struct pci_attach_args *, pci_intr_handle_t *);
     78      1.36    martin 
     79      1.30   thorpej static pcitag_t
     80      1.30   thorpej ofpci_make_tag(pci_chipset_tag_t pc, int node, int b, int d, int f)
     81      1.30   thorpej {
     82      1.30   thorpej 	pcitag_t tag;
     83      1.30   thorpej 
     84      1.30   thorpej 	tag = PCITAG_CREATE(node, b, d, f);
     85      1.30   thorpej 
     86      1.30   thorpej 	/* Enable all the different spaces for this device */
     87      1.30   thorpej 	pci_conf_write(pc, tag, PCI_COMMAND_STATUS_REG,
     88      1.30   thorpej 		PCI_COMMAND_MEM_ENABLE|PCI_COMMAND_MASTER_ENABLE|
     89      1.30   thorpej 		PCI_COMMAND_IO_ENABLE);
     90      1.30   thorpej 	return (tag);
     91      1.30   thorpej }
     92      1.30   thorpej 
     93       1.1       mrg /*
     94       1.1       mrg  * functions provided to the MI code.
     95       1.1       mrg  */
     96       1.1       mrg 
     97       1.1       mrg void
     98      1.51       cdi pci_attach_hook(struct device *parent, struct device *self,
     99      1.51       cdi 	struct pcibus_attach_args *pba)
    100       1.1       mrg {
    101       1.1       mrg }
    102       1.1       mrg 
    103       1.1       mrg int
    104      1.51       cdi pci_bus_maxdevs(pci_chipset_tag_t pc, int busno)
    105       1.1       mrg {
    106       1.1       mrg 
    107       1.1       mrg 	return 32;
    108       1.1       mrg }
    109      1.19       mrg 
    110       1.1       mrg pcitag_t
    111      1.51       cdi pci_make_tag(pci_chipset_tag_t pc, int b, int d, int f)
    112       1.1       mrg {
    113      1.35  nakayama 	struct psycho_pbm *pp = pc->cookie;
    114      1.46  nakayama 	struct ofw_pci_register reg;
    115      1.22       eeh 	pcitag_t tag;
    116      1.51       cdi 	int (*valid)(void *);
    117      1.22       eeh 	int node, len;
    118      1.22       eeh #ifdef DEBUG
    119      1.22       eeh 	char name[80];
    120      1.40    martin 	memset(name, 0, sizeof(name));
    121      1.22       eeh #endif
    122       1.1       mrg 
    123      1.35  nakayama 	/*
    124      1.35  nakayama 	 * Refer to the PCI/CardBus bus node first.
    125      1.35  nakayama 	 * It returns a tag if node is present and bus is valid.
    126      1.35  nakayama 	 */
    127      1.35  nakayama 	if (0 <= b && b < 256) {
    128      1.35  nakayama 		node = (*pp->pp_busnode)[b].node;
    129      1.35  nakayama 		valid = (*pp->pp_busnode)[b].valid;
    130      1.35  nakayama 		if (node != 0 && d == 0 &&
    131      1.35  nakayama 		    (valid == NULL || (*valid)((*pp->pp_busnode)[b].arg)))
    132      1.35  nakayama 			return ofpci_make_tag(pc, node, b, d, f);
    133      1.35  nakayama 	}
    134      1.35  nakayama 
    135      1.22       eeh 	/*
    136      1.22       eeh 	 * Hunt for the node that corresponds to this device
    137      1.22       eeh 	 *
    138      1.22       eeh 	 * We could cache this info in an array in the parent
    139      1.22       eeh 	 * device... except then we have problems with devices
    140      1.22       eeh 	 * attached below pci-pci bridges, and we would need to
    141      1.22       eeh 	 * add special code to the pci-pci bridge to cache this
    142      1.22       eeh 	 * info.
    143      1.22       eeh 	 */
    144       1.1       mrg 
    145      1.22       eeh 	tag = PCITAG_CREATE(-1, b, d, f);
    146      1.22       eeh 	node = pc->rootnode;
    147      1.22       eeh 	/*
    148      1.22       eeh 	 * First make sure we're on the right bus.  If our parent
    149      1.22       eeh 	 * has a bus-range property and we're not in the range,
    150      1.22       eeh 	 * then we're obviously on the wrong bus.  So go up one
    151      1.22       eeh 	 * level.
    152      1.22       eeh 	 */
    153      1.22       eeh #ifdef DEBUG
    154      1.22       eeh 	if (sparc_pci_debug & SPDB_PROBE) {
    155      1.42        pk 		printf("curnode %x %s\n", node,
    156      1.42        pk 			prom_getpropstringA(node, "name", name, sizeof(name)));
    157      1.22       eeh 	}
    158      1.22       eeh #endif
    159      1.22       eeh #if 0
    160      1.22       eeh 	while ((OF_getprop(OF_parent(node), "bus-range", (void *)&busrange,
    161      1.22       eeh 		sizeof(busrange)) == sizeof(busrange)) &&
    162      1.22       eeh 		(b < busrange[0] || b > busrange[1])) {
    163      1.22       eeh 		/* Out of range, go up one */
    164      1.22       eeh 		node = OF_parent(node);
    165      1.22       eeh #ifdef DEBUG
    166      1.22       eeh 		if (sparc_pci_debug & SPDB_PROBE) {
    167      1.42        pk 			printf("going up to node %x %s\n", node,
    168      1.42        pk 			prom_getpropstringA(node, "name", name, sizeof(name)));
    169      1.22       eeh 		}
    170      1.22       eeh #endif
    171      1.22       eeh 	}
    172      1.22       eeh #endif
    173      1.22       eeh 	/*
    174      1.22       eeh 	 * Now traverse all peers until we find the node or we find
    175      1.22       eeh 	 * the right bridge.
    176      1.22       eeh 	 *
    177      1.22       eeh 	 * XXX We go up one and down one to make sure nobody's missed.
    178      1.22       eeh 	 * but this should not be necessary.
    179      1.22       eeh 	 */
    180      1.42        pk 	for (node = ((node)); node; node = prom_nextsibling(node)) {
    181       1.1       mrg 
    182      1.22       eeh #ifdef DEBUG
    183      1.22       eeh 		if (sparc_pci_debug & SPDB_PROBE) {
    184      1.43        pk 			printf("checking node %x %s\n", node,
    185      1.42        pk 			prom_getpropstringA(node, "name", name, sizeof(name)));
    186      1.42        pk 
    187      1.22       eeh 		}
    188      1.22       eeh #endif
    189       1.1       mrg 
    190      1.22       eeh #if 1
    191       1.1       mrg 		/*
    192      1.22       eeh 		 * Check for PCI-PCI bridges.  If the device we want is
    193      1.22       eeh 		 * in the bus-range for that bridge, work our way down.
    194       1.1       mrg 		 */
    195      1.44        pk 		while (1) {
    196      1.44        pk 			int busrange[2], *brp;
    197      1.44        pk 			len = 2;
    198      1.44        pk 			brp = busrange;
    199      1.45  nakayama 			if (prom_getprop(node, "bus-range", sizeof(*brp),
    200      1.45  nakayama 					 &len, &brp) != 0)
    201      1.44        pk 				break;
    202      1.44        pk 			if (len != 2 || b < busrange[0] || b > busrange[1])
    203      1.44        pk 				break;
    204      1.22       eeh 			/* Go down 1 level */
    205      1.42        pk 			node = prom_firstchild(node);
    206      1.22       eeh #ifdef DEBUG
    207      1.22       eeh 			if (sparc_pci_debug & SPDB_PROBE) {
    208      1.43        pk 				printf("going down to node %x %s\n", node,
    209      1.42        pk 					prom_getpropstringA(node, "name",
    210      1.42        pk 							name, sizeof(name)));
    211      1.22       eeh 			}
    212      1.22       eeh #endif
    213       1.1       mrg 		}
    214      1.44        pk #endif /*1*/
    215      1.22       eeh 		/*
    216      1.22       eeh 		 * We only really need the first `reg' property.
    217      1.22       eeh 		 *
    218      1.22       eeh 		 * For simplicity, we'll query the `reg' when we
    219      1.22       eeh 		 * need it.  Otherwise we could malloc() it, but
    220      1.22       eeh 		 * that gets more complicated.
    221      1.22       eeh 		 */
    222      1.46  nakayama 		len = prom_getproplen(node, "reg");
    223      1.46  nakayama 		if (len < sizeof(reg))
    224      1.46  nakayama 			continue;
    225      1.46  nakayama 		if (OF_getprop(node, "reg", (void *)&reg, sizeof(reg)) != len)
    226      1.44        pk 			panic("pci_probe_bus: OF_getprop len botch");
    227      1.22       eeh 
    228      1.22       eeh 		if (b != OFW_PCI_PHYS_HI_BUS(reg.phys_hi))
    229      1.22       eeh 			continue;
    230      1.22       eeh 		if (d != OFW_PCI_PHYS_HI_DEVICE(reg.phys_hi))
    231      1.22       eeh 			continue;
    232      1.22       eeh 		if (f != OFW_PCI_PHYS_HI_FUNCTION(reg.phys_hi))
    233      1.22       eeh 			continue;
    234      1.22       eeh 
    235      1.22       eeh 		/* Got a match */
    236      1.27       eeh 		tag = ofpci_make_tag(pc, node, b, d, f);
    237      1.22       eeh 
    238      1.22       eeh 		return (tag);
    239       1.1       mrg 	}
    240      1.22       eeh 	/* No device found -- return a dead tag */
    241      1.27       eeh 	return (tag);
    242      1.28   thorpej }
    243      1.28   thorpej 
    244      1.28   thorpej void
    245      1.51       cdi pci_decompose_tag(pci_chipset_tag_t pc, pcitag_t tag, int *bp, int *dp, int *fp)
    246      1.28   thorpej {
    247      1.28   thorpej 
    248      1.28   thorpej 	if (bp != NULL)
    249      1.28   thorpej 		*bp = PCITAG_BUS(tag);
    250      1.28   thorpej 	if (dp != NULL)
    251      1.28   thorpej 		*dp = PCITAG_DEV(tag);
    252      1.28   thorpej 	if (fp != NULL)
    253      1.28   thorpej 		*fp = PCITAG_FUN(tag);
    254      1.27       eeh }
    255      1.27       eeh 
    256      1.30   thorpej int
    257      1.49  drochner sparc64_pci_enumerate_bus(struct pci_softc *sc, const int *locators,
    258      1.30   thorpej     int (*match)(struct pci_attach_args *), struct pci_attach_args *pap)
    259      1.27       eeh {
    260      1.30   thorpej 	struct ofw_pci_register reg;
    261      1.30   thorpej 	pci_chipset_tag_t pc = sc->sc_pc;
    262      1.27       eeh 	pcitag_t tag;
    263      1.35  nakayama 	pcireg_t class, csr, bhlc, ic;
    264      1.30   thorpej 	int node, b, d, f, ret;
    265      1.37    martin 	int bus_frequency, lt, cl, cacheline;
    266      1.30   thorpej 	char name[30];
    267      1.32       eeh 	extern int pci_config_dump;
    268      1.30   thorpej 
    269      1.31       eeh 	if (sc->sc_bridgetag)
    270      1.31       eeh 		node = PCITAG_NODE(*sc->sc_bridgetag);
    271      1.31       eeh 	else
    272      1.31       eeh 		node = pc->rootnode;
    273      1.31       eeh 
    274      1.42        pk 	bus_frequency =
    275      1.42        pk 		prom_getpropint(node, "clock-frequency", 33000000) / 1000000;
    276      1.35  nakayama 
    277      1.37    martin 	/*
    278      1.37    martin 	 * Make sure the cache line size is at least as big as the
    279      1.37    martin 	 * ecache line and the streaming cache (64 byte).
    280      1.37    martin 	 */
    281      1.53       mrg 	cacheline = max(ecache_min_line_size, 64);
    282      1.37    martin 	KASSERT((cacheline/64)*64 == cacheline &&
    283      1.53       mrg 	    (cacheline/ecache_min_line_size)*ecache_min_line_size == cacheline &&
    284      1.37    martin 	    (cacheline/4)*4 == cacheline);
    285      1.37    martin 
    286      1.32       eeh 	/* Turn on parity for the bus. */
    287      1.32       eeh 	tag = ofpci_make_tag(pc, node, sc->sc_bus, 0, 0);
    288      1.32       eeh 	csr = pci_conf_read(pc, tag, PCI_COMMAND_STATUS_REG);
    289      1.32       eeh 	csr |= PCI_COMMAND_PARITY_ENABLE;
    290      1.32       eeh 	pci_conf_write(pc, tag, PCI_COMMAND_STATUS_REG, csr);
    291      1.32       eeh 
    292      1.35  nakayama 	/*
    293      1.35  nakayama 	 * Initialize the latency timer register.
    294      1.35  nakayama 	 * The value 0x40 is from Solaris.
    295      1.35  nakayama 	 */
    296      1.35  nakayama 	bhlc = pci_conf_read(pc, tag, PCI_BHLC_REG);
    297      1.35  nakayama 	bhlc &= ~(PCI_LATTIMER_MASK << PCI_LATTIMER_SHIFT);
    298      1.35  nakayama 	bhlc |= 0x40 << PCI_LATTIMER_SHIFT;
    299      1.35  nakayama 	pci_conf_write(pc, tag, PCI_BHLC_REG, bhlc);
    300      1.35  nakayama 
    301      1.32       eeh 	if (pci_config_dump) pci_conf_print(pc, tag, NULL);
    302      1.32       eeh 
    303      1.42        pk 	for (node = prom_firstchild(node); node != 0 && node != -1;
    304      1.42        pk 	     node = prom_nextsibling(node)) {
    305      1.30   thorpej 		name[0] = name[29] = 0;
    306      1.42        pk 		prom_getpropstringA(node, "name", name, sizeof(name));
    307      1.27       eeh 
    308      1.30   thorpej 		if (OF_getprop(node, "class-code", &class, sizeof(class)) !=
    309      1.30   thorpej 		    sizeof(class))
    310      1.30   thorpej 			continue;
    311      1.30   thorpej 		if (OF_getprop(node, "reg", &reg, sizeof(reg)) < sizeof(reg))
    312      1.30   thorpej 			panic("pci_enumerate_bus: \"%s\" regs too small", name);
    313      1.27       eeh 
    314      1.30   thorpej 		b = OFW_PCI_PHYS_HI_BUS(reg.phys_hi);
    315      1.30   thorpej 		d = OFW_PCI_PHYS_HI_DEVICE(reg.phys_hi);
    316      1.30   thorpej 		f = OFW_PCI_PHYS_HI_FUNCTION(reg.phys_hi);
    317      1.30   thorpej 
    318      1.30   thorpej 		if (sc->sc_bus != b) {
    319      1.57      cube 			aprint_error_dev(sc->sc_dev, "WARNING: incorrect "
    320      1.57      cube 			    "bus # for \"%s\" (%d/%d/%d)\n", name, b, d, f);
    321      1.30   thorpej 			continue;
    322      1.30   thorpej 		}
    323      1.49  drochner                 if ((locators[PCICF_DEV] != PCICF_DEV_DEFAULT) &&
    324      1.49  drochner                     (locators[PCICF_DEV] != d))
    325      1.49  drochner                         continue;
    326      1.49  drochner 		if ((locators[PCICF_FUNCTION] != PCICF_FUNCTION_DEFAULT) &&
    327      1.49  drochner 		    (locators[PCICF_FUNCTION] != f))
    328      1.49  drochner 			continue;
    329      1.27       eeh 
    330      1.30   thorpej 		tag = ofpci_make_tag(pc, node, b, d, f);
    331      1.32       eeh 
    332      1.32       eeh 		/*
    333      1.32       eeh 		 * Turn on parity and fast-back-to-back for the device.
    334      1.32       eeh 		 */
    335      1.32       eeh 		csr = pci_conf_read(pc, tag, PCI_COMMAND_STATUS_REG);
    336      1.32       eeh 		if (csr & PCI_STATUS_BACKTOBACK_SUPPORT)
    337      1.32       eeh 			csr |= PCI_COMMAND_BACKTOBACK_ENABLE;
    338      1.32       eeh 		csr |= PCI_COMMAND_PARITY_ENABLE;
    339      1.32       eeh 		pci_conf_write(pc, tag, PCI_COMMAND_STATUS_REG, csr);
    340      1.32       eeh 
    341      1.35  nakayama 		/*
    342      1.35  nakayama 		 * Initialize the latency timer register for busmaster
    343      1.35  nakayama 		 * devices to work properly.
    344      1.35  nakayama 		 *   latency-timer = min-grant * bus-freq / 4  (from FreeBSD)
    345      1.35  nakayama 		 * Also initialize the cache line size register.
    346      1.35  nakayama 		 * Solaris anytime sets this register to the value 0x10.
    347      1.35  nakayama 		 */
    348      1.35  nakayama 		bhlc = pci_conf_read(pc, tag, PCI_BHLC_REG);
    349      1.35  nakayama 		ic = pci_conf_read(pc, tag, PCI_INTERRUPT_REG);
    350      1.35  nakayama 
    351      1.35  nakayama 		lt = min(PCI_MIN_GNT(ic) * bus_frequency / 4, 255);
    352      1.35  nakayama 		if (lt == 0 || lt < PCI_LATTIMER(bhlc))
    353      1.35  nakayama 			lt = PCI_LATTIMER(bhlc);
    354      1.35  nakayama 
    355      1.35  nakayama 		cl = PCI_CACHELINE(bhlc);
    356      1.35  nakayama 		if (cl == 0)
    357      1.37    martin 			cl = cacheline;
    358      1.35  nakayama 
    359      1.35  nakayama 		bhlc &= ~((PCI_LATTIMER_MASK << PCI_LATTIMER_SHIFT) |
    360      1.35  nakayama 			  (PCI_CACHELINE_MASK << PCI_CACHELINE_SHIFT));
    361      1.35  nakayama 		bhlc |= (lt << PCI_LATTIMER_SHIFT) |
    362      1.35  nakayama 			(cl << PCI_CACHELINE_SHIFT);
    363      1.35  nakayama 		pci_conf_write(pc, tag, PCI_BHLC_REG, bhlc);
    364      1.35  nakayama 
    365      1.30   thorpej 		ret = pci_probe_device(sc, tag, match, pap);
    366      1.30   thorpej 		if (match != NULL && ret != 0)
    367      1.30   thorpej 			return (ret);
    368      1.30   thorpej 	}
    369      1.30   thorpej 	return (0);
    370       1.1       mrg }
    371       1.1       mrg 
    372       1.1       mrg /* assume we are mapped little-endian/side-effect */
    373       1.1       mrg pcireg_t
    374      1.51       cdi pci_conf_read(pci_chipset_tag_t pc, pcitag_t tag, int reg)
    375       1.1       mrg {
    376       1.1       mrg 	struct psycho_pbm *pp = pc->cookie;
    377       1.1       mrg 	struct psycho_softc *sc = pp->pp_sc;
    378      1.22       eeh 	pcireg_t val = (pcireg_t)~0;
    379      1.22       eeh 
    380      1.22       eeh 	DPRINTF(SPDB_CONF, ("pci_conf_read: tag %lx reg %x ",
    381      1.22       eeh 		(long)tag, reg));
    382      1.22       eeh 	if (PCITAG_NODE(tag) != -1) {
    383      1.22       eeh 		DPRINTF(SPDB_CONF, ("asi=%x addr=%qx (offset=%x) ...",
    384      1.26       eeh 			sc->sc_configaddr._asi,
    385      1.26       eeh 			(long long)(sc->sc_configaddr._ptr +
    386      1.22       eeh 				PCITAG_OFFSET(tag) + reg),
    387      1.22       eeh 			(int)PCITAG_OFFSET(tag) + reg));
    388       1.1       mrg 
    389       1.1       mrg 		val = bus_space_read_4(sc->sc_configtag, sc->sc_configaddr,
    390      1.22       eeh 			PCITAG_OFFSET(tag) + reg);
    391       1.1       mrg 	}
    392      1.22       eeh #ifdef DEBUG
    393      1.24       mrg 	else DPRINTF(SPDB_CONF, ("pci_conf_read: bogus pcitag %x\n",
    394      1.24       mrg 		(int)PCITAG_OFFSET(tag)));
    395      1.22       eeh #endif
    396       1.1       mrg 	DPRINTF(SPDB_CONF, (" returning %08x\n", (u_int)val));
    397       1.1       mrg 
    398       1.1       mrg 	return (val);
    399       1.1       mrg }
    400       1.1       mrg 
    401       1.1       mrg void
    402      1.51       cdi pci_conf_write(pci_chipset_tag_t pc, pcitag_t tag, int reg, pcireg_t data)
    403       1.1       mrg {
    404       1.1       mrg 	struct psycho_pbm *pp = pc->cookie;
    405       1.1       mrg 	struct psycho_softc *sc = pp->pp_sc;
    406       1.1       mrg 
    407      1.22       eeh 	DPRINTF(SPDB_CONF, ("pci_conf_write: tag %lx; reg %x; data %x; ",
    408      1.22       eeh 		(long)PCITAG_OFFSET(tag), reg, (int)data));
    409       1.1       mrg 	DPRINTF(SPDB_CONF, ("asi = %x; readaddr = %qx (offset = %x)\n",
    410      1.26       eeh 		sc->sc_configaddr._asi,
    411      1.26       eeh 		(long long)(sc->sc_configaddr._ptr + PCITAG_OFFSET(tag) + reg),
    412      1.22       eeh 		(int)PCITAG_OFFSET(tag) + reg));
    413       1.1       mrg 
    414      1.24       mrg 	/* If we don't know it, just punt it.  */
    415      1.24       mrg 	if (PCITAG_NODE(tag) == -1) {
    416      1.24       mrg 		DPRINTF(SPDB_CONF, ("pci_conf_write: bad addr"));
    417      1.24       mrg 		return;
    418      1.24       mrg 	}
    419       1.1       mrg 
    420      1.22       eeh 	bus_space_write_4(sc->sc_configtag, sc->sc_configaddr,
    421      1.22       eeh 		PCITAG_OFFSET(tag) + reg, data);
    422       1.1       mrg }
    423       1.1       mrg 
    424      1.54       tnn /*
    425      1.54       tnn  * XXX: This code assumes we're on a psycho host bridge.
    426      1.54       tnn  */
    427      1.41    petrov static int
    428      1.51       cdi pci_find_ino(struct pci_attach_args *pa, pci_intr_handle_t *ihp)
    429      1.41    petrov {
    430      1.41    petrov 	struct psycho_pbm *pp = pa->pa_pc->cookie;
    431      1.41    petrov 	struct psycho_softc *sc = pp->pp_sc;
    432      1.54       tnn 	u_int bus;
    433      1.41    petrov 	u_int dev;
    434      1.54       tnn 	u_int pin;
    435      1.41    petrov 
    436      1.47    petrov 	DPRINTF(SPDB_INTMAP, ("pci_find_ino: pa_tag: node %x, %d:%d:%d\n",
    437      1.47    petrov 			      PCITAG_NODE(pa->pa_tag), (int)PCITAG_BUS(pa->pa_tag),
    438      1.47    petrov 			      (int)PCITAG_DEV(pa->pa_tag),
    439      1.47    petrov 			      (int)PCITAG_FUN(pa->pa_tag)));
    440      1.47    petrov 	DPRINTF(SPDB_INTMAP,
    441      1.47    petrov 		("pci_find_ino: intrswiz %d, intrpin %d, intrline %d, rawintrpin %d\n",
    442      1.47    petrov 		 pa->pa_intrswiz, pa->pa_intrpin, pa->pa_intrline, pa->pa_rawintrpin));
    443      1.47    petrov 	DPRINTF(SPDB_INTMAP, ("pci_find_ino: pa_intrtag: node %x, %d:%d:%d\n",
    444      1.47    petrov 			      PCITAG_NODE(pa->pa_intrtag),
    445      1.47    petrov 			      (int)PCITAG_BUS(pa->pa_intrtag),
    446      1.47    petrov 			      (int)PCITAG_DEV(pa->pa_intrtag),
    447      1.47    petrov 			      (int)PCITAG_FUN(pa->pa_intrtag)));
    448      1.47    petrov 
    449      1.54       tnn 	bus = (pp->pp_id == PSYCHO_PBM_B);
    450      1.54       tnn 	/*
    451      1.54       tnn 	 * If we are on a ppb, use the devno on the underlying bus when forming
    452      1.54       tnn 	 * the ivec.
    453      1.54       tnn 	 */
    454      1.54       tnn 	if (pa->pa_intrswiz != 0 && PCITAG_NODE(pa->pa_intrtag) != 0)
    455      1.54       tnn 		dev = PCITAG_DEV(pa->pa_intrtag);
    456      1.54       tnn 	else
    457      1.54       tnn 		dev = pa->pa_device;
    458      1.54       tnn 	dev--;
    459      1.41    petrov 
    460      1.54       tnn 	if (sc->sc_mode == PSYCHO_MODE_PSYCHO &&
    461      1.54       tnn 	    pp->pp_id == PSYCHO_PBM_B)
    462      1.54       tnn 		dev--;
    463      1.54       tnn 
    464      1.54       tnn 	pin = pa->pa_intrpin - 1;
    465      1.54       tnn 	DPRINTF(SPDB_INTMAP, ("pci_find_ino: mode %d, pbm %d, dev %d, pin %d\n",
    466      1.54       tnn 	    sc->sc_mode, pp->pp_id, dev, pin));
    467      1.47    petrov 
    468      1.54       tnn 	*ihp = sc->sc_ign | ((bus << 4) & INTMAP_PCIBUS) |
    469      1.54       tnn 	    ((dev << 2) & INTMAP_PCISLOT) | (pin & INTMAP_PCIINT);
    470      1.41    petrov 
    471      1.41    petrov 	return (0);
    472      1.41    petrov }
    473      1.41    petrov 
    474       1.1       mrg /*
    475       1.1       mrg  * interrupt mapping foo.
    476      1.20       mrg  * XXX: how does this deal with multiple interrupts for a device?
    477       1.1       mrg  */
    478       1.1       mrg int
    479      1.51       cdi pci_intr_map(struct pci_attach_args *pa, pci_intr_handle_t *ihp)
    480       1.1       mrg {
    481      1.22       eeh 	pcitag_t tag = pa->pa_tag;
    482      1.44        pk 	int interrupts, *intp;
    483      1.22       eeh 	int len, node = PCITAG_NODE(tag);
    484      1.22       eeh 	char devtype[30];
    485      1.22       eeh 
    486      1.44        pk 	intp = &interrupts;
    487      1.44        pk 	len = 1;
    488      1.44        pk 	if (prom_getprop(node, "interrupts", sizeof(interrupts),
    489      1.44        pk 			&len, &intp) != 0 || len != 1) {
    490      1.22       eeh 		DPRINTF(SPDB_INTMAP,
    491      1.22       eeh 			("pci_intr_map: could not read interrupts\n"));
    492      1.22       eeh 		return (ENODEV);
    493      1.22       eeh 	}
    494      1.20       mrg 
    495      1.22       eeh 	if (OF_mapintr(node, &interrupts, sizeof(interrupts),
    496      1.23       eeh 		sizeof(interrupts)) < 0) {
    497      1.22       eeh 		printf("OF_mapintr failed\n");
    498      1.41    petrov 		pci_find_ino(pa, &interrupts);
    499      1.22       eeh 	}
    500      1.44        pk 
    501      1.22       eeh 	/* Try to find an IPL for this type of device. */
    502      1.44        pk 	prom_getpropstringA(node, "device_type", devtype, sizeof(devtype));
    503      1.44        pk 	for (len = 0; intrmap[len].in_class != NULL; len++)
    504      1.44        pk 		if (strcmp(intrmap[len].in_class, devtype) == 0) {
    505      1.44        pk 			interrupts |= INTLEVENCODE(intrmap[len].in_lev);
    506      1.44        pk 			break;
    507      1.44        pk 		}
    508      1.20       mrg 
    509      1.22       eeh 	/* XXXX -- we use the ino.  What if there is a valid IGN? */
    510      1.22       eeh 	*ihp = interrupts;
    511      1.22       eeh 	return (0);
    512       1.1       mrg }
    513       1.1       mrg 
    514       1.1       mrg const char *
    515      1.51       cdi pci_intr_string(pci_chipset_tag_t pc, pci_intr_handle_t ih)
    516       1.1       mrg {
    517       1.1       mrg 	static char str[16];
    518       1.1       mrg 
    519       1.1       mrg 	DPRINTF(SPDB_INTR, ("pci_intr_string: ih %u", ih));
    520      1.22       eeh 	sprintf(str, "ivec %x", ih);
    521       1.1       mrg 	DPRINTF(SPDB_INTR, ("; returning %s\n", str));
    522       1.1       mrg 
    523       1.1       mrg 	return (str);
    524       1.8       cgd }
    525       1.8       cgd 
    526       1.8       cgd const struct evcnt *
    527      1.51       cdi pci_intr_evcnt(pci_chipset_tag_t pc, pci_intr_handle_t ih)
    528       1.8       cgd {
    529       1.8       cgd 
    530       1.8       cgd 	/* XXX for now, no evcnt parent reported */
    531       1.8       cgd 	return NULL;
    532       1.1       mrg }
    533       1.1       mrg 
    534  1.57.6.1  wrstuden int
    535  1.57.6.1  wrstuden pci_intr_setattr(pci_chipset_tag_t pc, pci_intr_handle_t *ih,
    536  1.57.6.1  wrstuden 		 int attr, uint64_t data)
    537  1.57.6.1  wrstuden {
    538  1.57.6.1  wrstuden 
    539  1.57.6.1  wrstuden 	switch (attr) {
    540  1.57.6.1  wrstuden 	case PCI_INTR_MPSAFE:
    541  1.57.6.1  wrstuden 		return 0;
    542  1.57.6.1  wrstuden 	default:
    543  1.57.6.1  wrstuden 		return ENODEV;
    544  1.57.6.1  wrstuden 	}
    545  1.57.6.1  wrstuden }
    546  1.57.6.1  wrstuden 
    547       1.1       mrg void *
    548      1.51       cdi pci_intr_establish(pci_chipset_tag_t pc, pci_intr_handle_t ih, int level,
    549      1.51       cdi 	int (*func)(void *), void *arg)
    550       1.1       mrg {
    551       1.1       mrg 	void *cookie;
    552       1.1       mrg 	struct psycho_pbm *pp = (struct psycho_pbm *)pc->cookie;
    553       1.1       mrg 
    554       1.1       mrg 	DPRINTF(SPDB_INTR, ("pci_intr_establish: ih %lu; level %d", (u_long)ih, level));
    555      1.34        pk 	cookie = bus_intr_establish(pp->pp_memt, ih, level, func, arg);
    556       1.1       mrg 
    557       1.1       mrg 	DPRINTF(SPDB_INTR, ("; returning handle %p\n", cookie));
    558       1.1       mrg 	return (cookie);
    559       1.1       mrg }
    560       1.1       mrg 
    561       1.1       mrg void
    562      1.51       cdi pci_intr_disestablish(pci_chipset_tag_t pc, void *cookie)
    563       1.1       mrg {
    564       1.1       mrg 
    565       1.1       mrg 	DPRINTF(SPDB_INTR, ("pci_intr_disestablish: cookie %p\n", cookie));
    566       1.1       mrg 
    567       1.1       mrg 	/* XXX */
    568      1.55    martin 	/* panic("can't disestablish PCI interrupts yet"); */
    569       1.1       mrg }
    570