Home | History | Annotate | Line # | Download | only in dev
ebus.c revision 1.67
      1  1.67   thorpej /*	$NetBSD: ebus.c,v 1.67 2021/05/10 23:53:44 thorpej Exp $	*/
      2   1.1       mrg 
      3   1.1       mrg /*
      4  1.29       mrg  * Copyright (c) 1999, 2000, 2001 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.40     lukem 
     29  1.40     lukem #include <sys/cdefs.h>
     30  1.67   thorpej __KERNEL_RCSID(0, "$NetBSD: ebus.c,v 1.67 2021/05/10 23:53:44 thorpej Exp $");
     31   1.1       mrg 
     32   1.8       mrg #include "opt_ddb.h"
     33   1.8       mrg 
     34   1.1       mrg /*
     35   1.1       mrg  * UltraSPARC 5 and beyond ebus support.
     36   1.8       mrg  *
     37  1.21       mrg  * note that this driver is not complete:
     38  1.21       mrg  *	- interrupt establish is written and appears to work
     39   1.8       mrg  *	- bus map code is written and appears to work
     40  1.38       wiz  *	- ebus2 DMA code is completely unwritten, we just punt to
     41  1.29       mrg  *	  the iommu.
     42   1.1       mrg  */
     43   1.1       mrg 
     44   1.1       mrg #ifdef DEBUG
     45   1.8       mrg #define	EDB_PROM	0x01
     46   1.8       mrg #define EDB_CHILD	0x02
     47   1.8       mrg #define	EDB_INTRMAP	0x04
     48   1.8       mrg #define EDB_BUSMAP	0x08
     49  1.56       mrg #define EDB_BUSDMA	0x10
     50  1.56       mrg #define EDB_INTR	0x20
     51  1.56       mrg int ebus_debug = 0x0;
     52   1.1       mrg #define DPRINTF(l, s)   do { if (ebus_debug & l) printf s; } while (0)
     53   1.1       mrg #else
     54   1.1       mrg #define DPRINTF(l, s)
     55   1.1       mrg #endif
     56   1.1       mrg 
     57   1.1       mrg #include <sys/param.h>
     58   1.1       mrg #include <sys/conf.h>
     59   1.1       mrg #include <sys/device.h>
     60   1.8       mrg #include <sys/errno.h>
     61   1.8       mrg #include <sys/extent.h>
     62   1.1       mrg #include <sys/malloc.h>
     63  1.65   thorpej #include <sys/kmem.h>
     64   1.1       mrg #include <sys/systm.h>
     65   1.8       mrg #include <sys/time.h>
     66   1.1       mrg 
     67   1.1       mrg #define _SPARC_BUS_DMA_PRIVATE
     68  1.58    dyoung #include <sys/bus.h>
     69   1.1       mrg #include <machine/autoconf.h>
     70  1.23       eeh #include <machine/openfirm.h>
     71   1.1       mrg 
     72   1.1       mrg #include <dev/pci/pcivar.h>
     73   1.1       mrg #include <dev/pci/pcireg.h>
     74   1.1       mrg #include <dev/pci/pcidevs.h>
     75   1.1       mrg 
     76  1.29       mrg #include <dev/ebus/ebusreg.h>
     77  1.31       mrg #include <dev/ebus/ebusvar.h>
     78  1.56       mrg #include <sparc64/dev/ebusvar.h>
     79  1.29       mrg 
     80  1.57  christos int	ebus_match(device_t, cfdata_t, void *);
     81  1.57  christos void	ebus_attach(device_t, device_t, void *);
     82   1.1       mrg 
     83  1.57  christos CFATTACH_DECL_NEW(ebus, sizeof(struct ebus_softc),
     84  1.34   thorpej     ebus_match, ebus_attach, NULL, NULL);
     85   1.1       mrg 
     86   1.8       mrg /*
     87  1.38       wiz  * here are our bus space and bus DMA routines.
     88   1.8       mrg  */
     89  1.50       cdi static int _ebus_bus_map(bus_space_tag_t, bus_addr_t, bus_size_t, int, vaddr_t,
     90  1.50       cdi 	bus_space_handle_t *);
     91  1.50       cdi static void *ebus_intr_establish(bus_space_tag_t, int, int, int (*)(void *),
     92  1.50       cdi 	void *, void(*)(void));
     93   1.8       mrg 
     94   1.1       mrg int
     95  1.57  christos ebus_match(device_t parent, cfdata_t match, void *aux)
     96   1.1       mrg {
     97   1.1       mrg 	struct pci_attach_args *pa = aux;
     98  1.45        pk 	char *name;
     99  1.23       eeh 	int node;
    100   1.1       mrg 
    101  1.23       eeh 	/* Only attach if there's a PROM node. */
    102  1.23       eeh 	node = PCITAG_NODE(pa->pa_tag);
    103  1.45        pk 	if (node == -1)
    104  1.45        pk 		return (0);
    105  1.45        pk 
    106  1.45        pk 	if (PCI_CLASS(pa->pa_class) != PCI_CLASS_BRIDGE)
    107  1.45        pk 		return (0);
    108  1.23       eeh 
    109  1.23       eeh 	/* Match a real ebus */
    110  1.45        pk 	name = prom_getpropstring(node, "name");
    111  1.45        pk 	if (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_SUN &&
    112  1.24       eeh 	    PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_SUN_EBUS &&
    113  1.25       eeh 		strcmp(name, "ebus") == 0)
    114  1.25       eeh 		return (1);
    115  1.25       eeh 
    116  1.25       eeh 	/* Or a real ebus III */
    117  1.45        pk 	if (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_SUN &&
    118  1.25       eeh 	    PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_SUN_EBUSIII &&
    119  1.24       eeh 		strcmp(name, "ebus") == 0)
    120   1.1       mrg 		return (1);
    121   1.1       mrg 
    122  1.23       eeh 	/* Or a PCI-ISA bridge XXX I hope this is on-board. */
    123  1.45        pk 	if (PCI_SUBCLASS(pa->pa_class) == PCI_SUBCLASS_BRIDGE_ISA) {
    124  1.23       eeh 		return (1);
    125  1.23       eeh 	}
    126  1.23       eeh 
    127  1.61       jdc 	/* Or the Altera bridge on SPARCle */
    128  1.61       jdc 	if (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_ALTERA &&
    129  1.61       jdc 	    PCI_PRODUCT(pa->pa_id) == 0 &&
    130  1.61       jdc 		strcmp(name, "ebus") == 0)
    131  1.61       jdc 		return (1);
    132  1.61       jdc 
    133   1.1       mrg 	return (0);
    134   1.1       mrg }
    135   1.1       mrg 
    136   1.1       mrg /*
    137  1.62       snj  * attach an ebus and all its children.  this code is modeled
    138   1.1       mrg  * after the sbus code which does similar things.
    139   1.1       mrg  */
    140   1.1       mrg void
    141  1.57  christos ebus_attach(device_t parent, device_t self, void *aux)
    142   1.1       mrg {
    143  1.57  christos 	struct ebus_softc *sc = device_private(self);
    144   1.1       mrg 	struct pci_attach_args *pa = aux;
    145   1.1       mrg 	struct ebus_attach_args eba;
    146   1.1       mrg 	struct ebus_interrupt_map_mask *immp;
    147  1.16        pk 	int node, nmapmask, error;
    148   1.1       mrg 	char devinfo[256];
    149   1.1       mrg 
    150  1.57  christos 	sc->sc_dev = self;
    151  1.57  christos 
    152  1.54       mrg 	aprint_naive("\n");
    153   1.1       mrg 
    154  1.46    kleink 	pci_devinfo(pa->pa_id, pa->pa_class, 0, devinfo, sizeof(devinfo));
    155  1.63       mrg 	aprint_normal(": %s, revision 0x%02x\n", devinfo,
    156   1.1       mrg 	    PCI_REVISION(pa->pa_class));
    157   1.1       mrg 
    158  1.23       eeh 	sc->sc_memtag = pa->pa_memt;
    159  1.23       eeh 	sc->sc_iotag = pa->pa_iot;
    160   1.1       mrg 	sc->sc_childbustag = ebus_alloc_bus_tag(sc, PCI_MEMORY_BUS_SPACE);
    161  1.29       mrg 	sc->sc_dmatag = pa->pa_dmat;
    162   1.1       mrg 
    163  1.23       eeh 	node = PCITAG_NODE(pa->pa_tag);
    164  1.23       eeh 	if (node == -1)
    165   1.1       mrg 		panic("could not find ebus node");
    166   1.1       mrg 
    167   1.1       mrg 	sc->sc_node = node;
    168   1.1       mrg 
    169   1.1       mrg 	/*
    170   1.1       mrg 	 * fill in our softc with information from the prom
    171   1.1       mrg 	 */
    172   1.3       mrg 	sc->sc_intmap = NULL;
    173   1.3       mrg 	sc->sc_range = NULL;
    174  1.44    martin 	sc->sc_nintmap = 0;
    175  1.43        pk 	error = prom_getprop(node, "interrupt-map",
    176  1.16        pk 			sizeof(struct ebus_interrupt_map),
    177  1.41       mrg 			&sc->sc_nintmap, &sc->sc_intmap);
    178  1.16        pk 	switch (error) {
    179  1.16        pk 	case 0:
    180  1.16        pk 		immp = &sc->sc_intmapmask;
    181  1.44    martin 		nmapmask = sizeof(*immp);
    182  1.43        pk 		error = prom_getprop(node, "interrupt-map-mask",
    183  1.16        pk 			    sizeof(struct ebus_interrupt_map_mask), &nmapmask,
    184  1.41       mrg 			    &immp);
    185  1.16        pk 		if (error)
    186  1.44    martin 			panic("could not get ebus interrupt-map-mask, error %d",
    187  1.44    martin 			    error);
    188  1.16        pk 		if (nmapmask != 1)
    189  1.16        pk 			panic("ebus interrupt-map-mask is broken");
    190  1.16        pk 		break;
    191  1.16        pk 	case ENOENT:
    192  1.16        pk 		break;
    193  1.16        pk 	default:
    194  1.16        pk 		panic("ebus interrupt-map: error %d", error);
    195  1.16        pk 		break;
    196  1.16        pk 	}
    197   1.1       mrg 
    198  1.43        pk 	error = prom_getprop(node, "ranges", sizeof(struct ebus_ranges),
    199  1.41       mrg 	    &sc->sc_nrange, &sc->sc_range);
    200  1.16        pk 	if (error)
    201  1.16        pk 		panic("ebus ranges: error %d", error);
    202   1.1       mrg 
    203   1.1       mrg 	/*
    204   1.1       mrg 	 * now attach all our children
    205   1.1       mrg 	 */
    206   1.1       mrg 	DPRINTF(EDB_CHILD, ("ebus node %08x, searching children...\n", node));
    207   1.1       mrg 	for (node = firstchild(node); node; node = nextsibling(node)) {
    208  1.43        pk 		char *name = prom_getpropstring(node, "name");
    209   1.1       mrg 
    210   1.1       mrg 		if (ebus_setup_attach_args(sc, node, &eba) != 0) {
    211  1.54       mrg 			aprint_error("ebus_attach: %s: incomplete\n", name);
    212   1.1       mrg 			continue;
    213   1.6       mrg 		} else {
    214  1.21       mrg 			DPRINTF(EDB_CHILD, ("- found child `%s', attaching\n",
    215  1.21       mrg 			    eba.ea_name));
    216  1.67   thorpej 			(void)config_found(self, &eba, ebus_print,
    217  1.67   thorpej 			    CFARG_DEVHANDLE, prom_node_to_devhandle(node),
    218  1.67   thorpej 			    CFARG_EOL);
    219   1.1       mrg 		}
    220   1.1       mrg 		ebus_destroy_attach_args(&eba);
    221   1.1       mrg 	}
    222   1.1       mrg }
    223   1.1       mrg 
    224  1.49       cdi int	ebus_setup_attach_args(struct ebus_softc *, int,
    225  1.49       cdi 	    struct ebus_attach_args *);
    226   1.1       mrg int
    227  1.49       cdi ebus_setup_attach_args(struct ebus_softc *sc, int node,
    228  1.49       cdi 	struct ebus_attach_args	*ea)
    229   1.1       mrg {
    230   1.1       mrg 	int	n, rv;
    231   1.1       mrg 
    232  1.42    martin 	memset(ea, 0, sizeof(struct ebus_attach_args));
    233  1.44    martin 	n = 0;
    234  1.43        pk 	rv = prom_getprop(node, "name", 1, &n, &ea->ea_name);
    235   1.1       mrg 	if (rv != 0)
    236   1.1       mrg 		return (rv);
    237  1.60       mrg 	KASSERT(ea->ea_name[n-1] == '\0');
    238   1.1       mrg 
    239   1.1       mrg 	ea->ea_node = node;
    240   1.1       mrg 	ea->ea_bustag = sc->sc_childbustag;
    241   1.1       mrg 	ea->ea_dmatag = sc->sc_dmatag;
    242   1.1       mrg 
    243  1.43        pk 	rv = prom_getprop(node, "reg", sizeof(struct ebus_regs), &ea->ea_nreg,
    244  1.41       mrg 	    &ea->ea_reg);
    245   1.1       mrg 	if (rv)
    246   1.1       mrg 		return (rv);
    247   1.1       mrg 
    248  1.50       cdi 	rv = prom_getprop(node, "address", sizeof(uint32_t), &ea->ea_nvaddr,
    249  1.41       mrg 	    &ea->ea_vaddr);
    250   1.1       mrg 	if (rv != ENOENT) {
    251   1.1       mrg 		if (rv)
    252   1.1       mrg 			return (rv);
    253   1.1       mrg 
    254  1.31       mrg 		if (ea->ea_nreg != ea->ea_nvaddr)
    255   1.1       mrg 			printf("ebus loses: device %s: %d regs and %d addrs\n",
    256  1.31       mrg 			    ea->ea_name, ea->ea_nreg, ea->ea_nvaddr);
    257   1.3       mrg 	} else
    258  1.31       mrg 		ea->ea_nvaddr = 0;
    259   1.1       mrg 
    260  1.50       cdi 	if (prom_getprop(node, "interrupts", sizeof(uint32_t), &ea->ea_nintr,
    261  1.41       mrg 	    &ea->ea_intr))
    262  1.31       mrg 		ea->ea_nintr = 0;
    263  1.16        pk 	else
    264   1.3       mrg 		ebus_find_ino(sc, ea);
    265   1.1       mrg 
    266   1.1       mrg 	return (0);
    267   1.1       mrg }
    268   1.1       mrg 
    269   1.1       mrg void
    270  1.49       cdi ebus_destroy_attach_args(struct ebus_attach_args *ea)
    271   1.1       mrg {
    272   1.1       mrg 
    273   1.1       mrg 	if (ea->ea_name)
    274   1.1       mrg 		free((void *)ea->ea_name, M_DEVBUF);
    275  1.31       mrg 	if (ea->ea_reg)
    276  1.31       mrg 		free((void *)ea->ea_reg, M_DEVBUF);
    277  1.31       mrg 	if (ea->ea_intr)
    278  1.31       mrg 		free((void *)ea->ea_intr, M_DEVBUF);
    279  1.31       mrg 	if (ea->ea_vaddr)
    280  1.31       mrg 		free((void *)ea->ea_vaddr, M_DEVBUF);
    281   1.1       mrg }
    282   1.1       mrg 
    283   1.1       mrg int
    284  1.49       cdi ebus_print(void *aux, const char *p)
    285   1.1       mrg {
    286   1.1       mrg 	struct ebus_attach_args *ea = aux;
    287   1.4       mrg 	int i;
    288   1.1       mrg 
    289   1.1       mrg 	if (p)
    290  1.37   thorpej 		aprint_normal("%s at %s", ea->ea_name, p);
    291  1.31       mrg 	for (i = 0; i < ea->ea_nreg; i++)
    292  1.37   thorpej 		aprint_normal("%s %x-%x", i == 0 ? " addr" : ",",
    293  1.31       mrg 		    ea->ea_reg[i].lo,
    294  1.31       mrg 		    ea->ea_reg[i].lo + ea->ea_reg[i].size - 1);
    295  1.31       mrg 	for (i = 0; i < ea->ea_nintr; i++)
    296  1.59  macallan 		aprint_normal(" ipl %x", ea->ea_intr[i]);
    297   1.1       mrg 	return (UNCONF);
    298   1.3       mrg }
    299   1.3       mrg 
    300  1.23       eeh 
    301   1.3       mrg /*
    302   1.3       mrg  * find the INO values for each interrupt and fill them in.
    303   1.3       mrg  *
    304  1.62       snj  * for each "reg" property of this device, mask its hi and lo
    305   1.3       mrg  * values with the "interrupt-map-mask"'s hi/lo values, and also
    306   1.3       mrg  * mask the interrupt number with the interrupt mask.  search the
    307   1.3       mrg  * "interrupt-map" list for matching values of hi, lo and interrupt
    308   1.3       mrg  * to give the INO for this interrupt.
    309   1.3       mrg  */
    310   1.3       mrg void
    311  1.49       cdi ebus_find_ino(struct ebus_softc *sc, struct ebus_attach_args *ea)
    312   1.3       mrg {
    313  1.50       cdi 	uint32_t hi, lo, intr;
    314   1.3       mrg 	int i, j, k;
    315   1.3       mrg 
    316  1.16        pk 	if (sc->sc_nintmap == 0) {
    317  1.31       mrg 		for (i = 0; i < ea->ea_nintr; i++) {
    318  1.31       mrg 			OF_mapintr(ea->ea_node, &ea->ea_intr[i],
    319  1.31       mrg 				sizeof(ea->ea_intr[0]),
    320  1.31       mrg 				sizeof(ea->ea_intr[0]));
    321  1.23       eeh 		}
    322  1.16        pk 		return;
    323  1.16        pk 	}
    324  1.16        pk 
    325  1.21       mrg 	DPRINTF(EDB_INTRMAP,
    326  1.31       mrg 	    ("ebus_find_ino: searching %d interrupts", ea->ea_nintr));
    327  1.16        pk 
    328  1.31       mrg 	for (j = 0; j < ea->ea_nintr; j++) {
    329  1.16        pk 
    330  1.31       mrg 		intr = ea->ea_intr[j] & sc->sc_intmapmask.intr;
    331   1.3       mrg 
    332  1.21       mrg 		DPRINTF(EDB_INTRMAP,
    333  1.31       mrg 		    ("; intr %x masked to %x", ea->ea_intr[j], intr));
    334  1.31       mrg 		for (i = 0; i < ea->ea_nreg; i++) {
    335  1.31       mrg 			hi = ea->ea_reg[i].hi & sc->sc_intmapmask.hi;
    336  1.31       mrg 			lo = ea->ea_reg[i].lo & sc->sc_intmapmask.lo;
    337   1.3       mrg 
    338  1.21       mrg 			DPRINTF(EDB_INTRMAP,
    339  1.21       mrg 			    ("; reg hi.lo %08x.%08x masked to %08x.%08x",
    340  1.31       mrg 			    ea->ea_reg[i].hi, ea->ea_reg[i].lo, hi, lo));
    341   1.3       mrg 			for (k = 0; k < sc->sc_nintmap; k++) {
    342  1.21       mrg 				DPRINTF(EDB_INTRMAP,
    343  1.21       mrg 				    ("; checking hi.lo %08x.%08x intr %x",
    344  1.21       mrg 				    sc->sc_intmap[k].hi, sc->sc_intmap[k].lo,
    345  1.21       mrg 				    sc->sc_intmap[k].intr));
    346   1.3       mrg 				if (hi == sc->sc_intmap[k].hi &&
    347   1.3       mrg 				    lo == sc->sc_intmap[k].lo &&
    348   1.3       mrg 				    intr == sc->sc_intmap[k].intr) {
    349  1.31       mrg 					ea->ea_intr[j] =
    350  1.21       mrg 					    sc->sc_intmap[k].cintr;
    351  1.21       mrg 					DPRINTF(EDB_INTRMAP,
    352  1.21       mrg 					    ("; FOUND IT! changing to %d\n",
    353  1.21       mrg 					    sc->sc_intmap[k].cintr));
    354   1.3       mrg 					goto next_intr;
    355   1.3       mrg 				}
    356   1.3       mrg 			}
    357   1.3       mrg 		}
    358  1.22       mrg next_intr:;
    359   1.3       mrg 	}
    360   1.1       mrg }
    361   1.1       mrg 
    362   1.8       mrg /*
    363  1.29       mrg  * bus space support.  <sparc64/dev/psychoreg.h> has a discussion
    364  1.29       mrg  * about PCI physical addresses, which also applies to ebus.
    365   1.8       mrg  */
    366   1.8       mrg bus_space_tag_t
    367  1.49       cdi ebus_alloc_bus_tag(struct ebus_softc *sc, int type)
    368   1.8       mrg {
    369   1.8       mrg 	bus_space_tag_t bt;
    370   1.8       mrg 
    371  1.65   thorpej 	bt = kmem_zalloc(sizeof(*bt), KM_SLEEP);
    372   1.8       mrg 	bt->cookie = sc;
    373  1.23       eeh 	bt->parent = sc->sc_memtag;
    374   1.8       mrg 	bt->type = type;
    375   1.8       mrg 	bt->sparc_bus_map = _ebus_bus_map;
    376   1.8       mrg 	bt->sparc_bus_mmap = ebus_bus_mmap;
    377   1.8       mrg 	bt->sparc_intr_establish = ebus_intr_establish;
    378   1.8       mrg 	return (bt);
    379   1.8       mrg }
    380   1.8       mrg 
    381   1.8       mrg static int
    382  1.50       cdi _ebus_bus_map(bus_space_tag_t t, bus_addr_t ba, bus_size_t size, int flags,
    383  1.50       cdi 	vaddr_t va, bus_space_handle_t *hp)
    384   1.8       mrg {
    385   1.8       mrg 	struct ebus_softc *sc = t->cookie;
    386  1.31       mrg 	paddr_t offset;
    387  1.31       mrg 	u_int bar;
    388  1.23       eeh 	int i, ss;
    389   1.8       mrg 
    390  1.31       mrg 	bar = BUS_ADDR_IOSPACE(ba);
    391  1.31       mrg 	offset = BUS_ADDR_PADDR(ba);
    392  1.31       mrg 
    393  1.21       mrg 	DPRINTF(EDB_BUSMAP,
    394  1.31       mrg 		("\n_ebus_bus_map: bar %d offset %08x sz %x flags %x va %p\n",
    395  1.50       cdi 		 (int)bar, (uint32_t)offset, (uint32_t)size,
    396  1.31       mrg 		 flags, (void *)va));
    397  1.31       mrg 
    398   1.8       mrg 	for (i = 0; i < sc->sc_nrange; i++) {
    399   1.8       mrg 		bus_addr_t pciaddr;
    400   1.8       mrg 
    401  1.31       mrg 		if (bar != sc->sc_range[i].child_hi)
    402   1.8       mrg 			continue;
    403  1.31       mrg 		if (offset < sc->sc_range[i].child_lo ||
    404  1.31       mrg 		    (offset + size) >
    405  1.21       mrg 		      (sc->sc_range[i].child_lo + sc->sc_range[i].size))
    406   1.8       mrg 			continue;
    407   1.8       mrg 
    408  1.23       eeh 		/* Isolate address space and find the right tag */
    409  1.23       eeh 		ss = (sc->sc_range[i].phys_hi>>24)&3;
    410  1.23       eeh 		switch (ss) {
    411  1.23       eeh 		case 1:	/* I/O space */
    412  1.23       eeh 			t = sc->sc_iotag;
    413  1.23       eeh 			break;
    414  1.23       eeh 		case 2:	/* Memory space */
    415  1.23       eeh 			t = sc->sc_memtag;
    416  1.23       eeh 			break;
    417  1.23       eeh 		case 0:	/* Config space */
    418  1.23       eeh 		case 3:	/* 64-bit Memory space */
    419  1.23       eeh 		default: /* WTF? */
    420  1.23       eeh 			/* We don't handle these */
    421  1.23       eeh 			panic("_ebus_bus_map: illegal space %x", ss);
    422  1.23       eeh 			break;
    423  1.23       eeh 		}
    424   1.8       mrg 		pciaddr = ((bus_addr_t)sc->sc_range[i].phys_mid << 32UL) |
    425   1.8       mrg 				       sc->sc_range[i].phys_lo;
    426  1.31       mrg 		pciaddr += offset;
    427  1.31       mrg 
    428  1.21       mrg 		DPRINTF(EDB_BUSMAP,
    429  1.31       mrg 			("_ebus_bus_map: mapping to PCI addr %x\n",
    430  1.50       cdi 			 (uint32_t)pciaddr));
    431  1.31       mrg 
    432   1.8       mrg 		/* pass it onto the psycho */
    433  1.30       eeh 		return (bus_space_map(t, pciaddr, size, flags, hp));
    434   1.8       mrg 	}
    435   1.8       mrg 	DPRINTF(EDB_BUSMAP, (": FAILED\n"));
    436   1.8       mrg 	return (EINVAL);
    437   1.8       mrg }
    438   1.8       mrg 
    439  1.56       mrg paddr_t
    440  1.50       cdi ebus_bus_mmap(bus_space_tag_t t, bus_addr_t paddr, off_t off, int prot,
    441  1.50       cdi 	int flags)
    442   1.8       mrg {
    443   1.8       mrg 	bus_addr_t offset = paddr;
    444   1.8       mrg 	struct ebus_softc *sc = t->cookie;
    445   1.8       mrg 	int i;
    446   1.8       mrg 
    447   1.8       mrg 	for (i = 0; i < sc->sc_nrange; i++) {
    448  1.47  christos 		bus_addr_t paddr1 =
    449  1.47  christos 		    ((bus_addr_t)sc->sc_range[i].child_hi << 32) |
    450   1.8       mrg 		    sc->sc_range[i].child_lo;
    451   1.8       mrg 
    452  1.47  christos 		if (offset != paddr1)
    453   1.8       mrg 			continue;
    454   1.8       mrg 
    455  1.21       mrg 		DPRINTF(EDB_BUSMAP, ("\n_ebus_bus_mmap: mapping paddr %qx\n",
    456  1.47  christos 		    (unsigned long long)paddr1));
    457  1.47  christos 		return (bus_space_mmap(sc->sc_memtag, paddr1, off,
    458  1.27       eeh 				       prot, flags));
    459   1.8       mrg 	}
    460   1.8       mrg 
    461   1.8       mrg 	return (-1);
    462   1.8       mrg }
    463   1.8       mrg 
    464   1.8       mrg /*
    465  1.29       mrg  * install an interrupt handler for a ebus device
    466   1.8       mrg  */
    467   1.8       mrg void *
    468  1.50       cdi ebus_intr_establish(bus_space_tag_t t, int pri, int level,
    469  1.50       cdi 	int (*handler)(void *), void *arg, void (*fastvec)(void) /* ignored */)
    470   1.8       mrg {
    471  1.29       mrg 
    472  1.36        pk 	return (bus_intr_establish(t->parent, pri, level, handler, arg));
    473   1.1       mrg }
    474