Home | History | Annotate | Line # | Download | only in dev
ebus.c revision 1.9.2.1
      1  1.9.2.1  minoura /*	$NetBSD: ebus.c,v 1.9.2.1 2000/06/22 17:04:19 minoura 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  * 3. The name of the author may not be used to endorse or promote products
     16      1.1      mrg  *    derived from this software without specific prior written permission.
     17      1.1      mrg  *
     18      1.1      mrg  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     19      1.1      mrg  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     20      1.1      mrg  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     21      1.1      mrg  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     22      1.1      mrg  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
     23      1.1      mrg  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
     24      1.1      mrg  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
     25      1.1      mrg  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
     26      1.1      mrg  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     27      1.1      mrg  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     28      1.1      mrg  * SUCH DAMAGE.
     29      1.1      mrg  */
     30      1.1      mrg 
     31      1.8      mrg #include "opt_ddb.h"
     32      1.8      mrg 
     33      1.1      mrg /*
     34      1.1      mrg  * UltraSPARC 5 and beyond ebus support.
     35      1.8      mrg  *
     36      1.8      mrg  * note that this driver is far from complete:
     37      1.8      mrg  *	- ebus2 dma code is completely unwritten
     38      1.8      mrg  *	- interrupt establish code is completely unwritten
     39      1.8      mrg  *	- bus map code is written and appears to work
     40      1.1      mrg  */
     41      1.1      mrg 
     42      1.1      mrg #undef DEBUG
     43      1.1      mrg #define DEBUG
     44      1.1      mrg 
     45      1.1      mrg #ifdef DEBUG
     46      1.8      mrg #define	EDB_PROM	0x01
     47      1.8      mrg #define EDB_CHILD	0x02
     48      1.8      mrg #define	EDB_INTRMAP	0x04
     49      1.8      mrg #define EDB_BUSMAP	0x08
     50      1.8      mrg #define EDB_BUSDMA	0x10
     51      1.8      mrg #define EDB_INTR	0x20
     52      1.1      mrg int ebus_debug = 0;
     53      1.1      mrg #define DPRINTF(l, s)   do { if (ebus_debug & l) printf s; } while (0)
     54      1.1      mrg #else
     55      1.1      mrg #define DPRINTF(l, s)
     56      1.1      mrg #endif
     57      1.1      mrg 
     58      1.1      mrg #include <sys/param.h>
     59      1.1      mrg #include <sys/conf.h>
     60      1.1      mrg #include <sys/device.h>
     61      1.8      mrg #include <sys/errno.h>
     62      1.8      mrg #include <sys/extent.h>
     63      1.1      mrg #include <sys/malloc.h>
     64      1.1      mrg #include <sys/systm.h>
     65      1.8      mrg #include <sys/time.h>
     66      1.8      mrg 
     67      1.8      mrg #include <vm/vm.h>
     68      1.8      mrg #include <vm/vm_kern.h>
     69      1.1      mrg 
     70      1.1      mrg #define _SPARC_BUS_DMA_PRIVATE
     71      1.1      mrg #include <machine/bus.h>
     72      1.1      mrg #include <machine/autoconf.h>
     73      1.1      mrg 
     74      1.1      mrg #include <dev/pci/pcivar.h>
     75      1.1      mrg #include <dev/pci/pcireg.h>
     76      1.1      mrg #include <dev/pci/pcidevs.h>
     77      1.1      mrg 
     78      1.8      mrg #include <sparc64/dev/iommureg.h>
     79      1.8      mrg #include <sparc64/dev/iommuvar.h>
     80      1.8      mrg #include <sparc64/dev/psychoreg.h>
     81      1.8      mrg #include <sparc64/dev/psychovar.h>
     82      1.1      mrg #include <sparc64/dev/ebusreg.h>
     83      1.1      mrg #include <sparc64/dev/ebusvar.h>
     84      1.8      mrg #include <sparc64/sparc64/cache.h>
     85      1.1      mrg 
     86      1.1      mrg int	ebus_match __P((struct device *, struct cfdata *, void *));
     87      1.1      mrg void	ebus_attach __P((struct device *, struct device *, void *));
     88      1.1      mrg 
     89      1.1      mrg struct cfattach ebus_ca = {
     90  1.9.2.1  minoura 	sizeof(struct ebus_softc), ebus_match, ebus_attach
     91      1.1      mrg };
     92      1.1      mrg 
     93      1.1      mrg int	ebus_setup_attach_args __P((struct ebus_softc *, int,
     94      1.1      mrg 	    struct ebus_attach_args *));
     95      1.1      mrg void	ebus_destroy_attach_args __P((struct ebus_attach_args *));
     96      1.1      mrg int	ebus_print __P((void *, const char *));
     97      1.3      mrg void	ebus_find_ino __P((struct ebus_softc *, struct ebus_attach_args *));
     98  1.9.2.1  minoura int	ebus_find_node __P((struct pci_attach_args *));
     99      1.1      mrg 
    100      1.8      mrg /*
    101      1.8      mrg  * here are our bus space and bus dma routines.
    102      1.8      mrg  */
    103      1.8      mrg static int ebus_bus_mmap __P((bus_space_tag_t, bus_type_t, bus_addr_t,
    104      1.8      mrg 				int, bus_space_handle_t *));
    105      1.8      mrg static int _ebus_bus_map __P((bus_space_tag_t, bus_type_t, bus_addr_t,
    106      1.8      mrg 				bus_size_t, int, vaddr_t,
    107      1.8      mrg 				bus_space_handle_t *));
    108      1.8      mrg static void *ebus_intr_establish __P((bus_space_tag_t, int, int,
    109      1.8      mrg 				int (*) __P((void *)), void *));
    110      1.8      mrg 
    111      1.8      mrg static int ebus_dmamap_load __P((bus_dma_tag_t, bus_dmamap_t, void *,
    112      1.8      mrg 			  bus_size_t, struct proc *, int));
    113      1.8      mrg static void ebus_dmamap_unload __P((bus_dma_tag_t, bus_dmamap_t));
    114      1.8      mrg static void ebus_dmamap_sync __P((bus_dma_tag_t, bus_dmamap_t, bus_addr_t,
    115      1.8      mrg 				  bus_size_t, int));
    116      1.8      mrg int ebus_dmamem_alloc __P((bus_dma_tag_t, bus_size_t, bus_size_t, bus_size_t,
    117      1.8      mrg 			   bus_dma_segment_t *, int, int *, int));
    118      1.8      mrg void ebus_dmamem_free __P((bus_dma_tag_t, bus_dma_segment_t *, int));
    119      1.8      mrg int ebus_dmamem_map __P((bus_dma_tag_t, bus_dma_segment_t *, int, size_t,
    120      1.8      mrg 			 caddr_t *, int));
    121      1.8      mrg void ebus_dmamem_unmap __P((bus_dma_tag_t, caddr_t, size_t));
    122      1.8      mrg 
    123      1.1      mrg int
    124      1.1      mrg ebus_match(parent, match, aux)
    125      1.1      mrg 	struct device *parent;
    126      1.1      mrg 	struct cfdata *match;
    127      1.1      mrg 	void *aux;
    128      1.1      mrg {
    129      1.1      mrg 	struct pci_attach_args *pa = aux;
    130      1.1      mrg 
    131      1.1      mrg 	if (PCI_CLASS(pa->pa_class) == PCI_CLASS_BRIDGE &&
    132      1.1      mrg 	    PCI_VENDOR(pa->pa_id) == PCI_VENDOR_SUN &&
    133  1.9.2.1  minoura 	    PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_SUN_EBUS &&
    134  1.9.2.1  minoura 	    ebus_find_node(pa))
    135      1.1      mrg 		return (1);
    136      1.1      mrg 
    137      1.1      mrg 	return (0);
    138      1.1      mrg }
    139      1.1      mrg 
    140      1.1      mrg /*
    141      1.1      mrg  * attach an ebus and all it's children.  this code is modeled
    142      1.1      mrg  * after the sbus code which does similar things.
    143      1.1      mrg  */
    144      1.1      mrg void
    145      1.1      mrg ebus_attach(parent, self, aux)
    146      1.1      mrg 	struct device *parent, *self;
    147      1.1      mrg 	void *aux;
    148      1.1      mrg {
    149      1.1      mrg 	struct ebus_softc *sc = (struct ebus_softc *)self;
    150      1.1      mrg 	struct pci_attach_args *pa = aux;
    151      1.1      mrg 	struct ebus_attach_args eba;
    152      1.1      mrg 	struct ebus_interrupt_map_mask *immp;
    153      1.1      mrg 	int node, nmapmask, rv;
    154      1.1      mrg 	char devinfo[256];
    155      1.1      mrg 
    156      1.1      mrg 	printf("\n");
    157      1.1      mrg 
    158      1.1      mrg 	pci_devinfo(pa->pa_id, pa->pa_class, 0, devinfo);
    159      1.1      mrg 	printf("%s: %s, revision 0x%02x\n", self->dv_xname, devinfo,
    160      1.1      mrg 	    PCI_REVISION(pa->pa_class));
    161      1.1      mrg 
    162      1.5      mrg 	sc->sc_parent = (struct psycho_softc *)parent;
    163      1.1      mrg 	sc->sc_bustag = pa->pa_memt;
    164      1.1      mrg 	sc->sc_childbustag = ebus_alloc_bus_tag(sc, PCI_MEMORY_BUS_SPACE);
    165      1.1      mrg 	sc->sc_dmatag = ebus_alloc_dma_tag(sc, pa->pa_dmat);
    166      1.1      mrg 
    167  1.9.2.1  minoura 	node = ebus_find_node(pa);
    168      1.1      mrg 	if (node == 0)
    169      1.1      mrg 		panic("could not find ebus node");
    170      1.1      mrg 
    171      1.1      mrg 	sc->sc_node = node;
    172      1.1      mrg 
    173      1.1      mrg 	/*
    174      1.1      mrg 	 * fill in our softc with information from the prom
    175      1.1      mrg 	 */
    176      1.3      mrg 	sc->sc_intmap = NULL;
    177      1.3      mrg 	sc->sc_range = NULL;
    178      1.1      mrg 	rv = getprop(node, "interrupt-map", sizeof(struct ebus_interrupt_map),
    179      1.1      mrg 	    &sc->sc_nintmap, (void **)&sc->sc_intmap);
    180      1.1      mrg 	if (rv)
    181      1.1      mrg 		panic("could not get ebus interrupt-map");
    182      1.1      mrg 
    183      1.1      mrg 	immp = &sc->sc_intmapmask;
    184      1.1      mrg 	rv = getprop(node, "interrupt-map-mask",
    185      1.1      mrg 	    sizeof(struct ebus_interrupt_map_mask), &nmapmask,
    186      1.1      mrg 	    (void **)&immp);
    187      1.1      mrg 	if (rv)
    188      1.1      mrg 		panic("could not get ebus interrupt-map-mask");
    189      1.1      mrg 	if (nmapmask != 1)
    190      1.1      mrg 		panic("ebus interrupt-map-mask is broken");
    191      1.1      mrg 
    192      1.1      mrg 	rv = getprop(node, "ranges", sizeof(struct ebus_ranges),
    193      1.1      mrg 	    &sc->sc_nrange, (void **)&sc->sc_range);
    194      1.1      mrg 	if (rv)
    195      1.1      mrg 		panic("could not get ebus ranges");
    196      1.1      mrg 
    197      1.1      mrg 	/*
    198      1.1      mrg 	 * now attach all our children
    199      1.1      mrg 	 */
    200      1.1      mrg 	DPRINTF(EDB_CHILD, ("ebus node %08x, searching children...\n", node));
    201      1.1      mrg 	for (node = firstchild(node); node; node = nextsibling(node)) {
    202      1.1      mrg 		char *name = getpropstring(node, "name");
    203      1.1      mrg 
    204      1.1      mrg 		if (ebus_setup_attach_args(sc, node, &eba) != 0) {
    205      1.1      mrg 			printf("ebus_attach: %s: incomplete\n", name);
    206      1.1      mrg 			continue;
    207      1.6      mrg 		} else {
    208      1.6      mrg 			DPRINTF(EDB_CHILD, ("- found child `%s', attaching\n", eba.ea_name));
    209      1.6      mrg 			(void)config_found(self, &eba, ebus_print);
    210      1.1      mrg 		}
    211      1.1      mrg 		ebus_destroy_attach_args(&eba);
    212      1.1      mrg 	}
    213      1.1      mrg }
    214      1.1      mrg 
    215      1.1      mrg int
    216      1.1      mrg ebus_setup_attach_args(sc, node, ea)
    217      1.1      mrg 	struct ebus_softc	*sc;
    218      1.1      mrg 	int			node;
    219      1.1      mrg 	struct ebus_attach_args	*ea;
    220      1.1      mrg {
    221      1.1      mrg 	int	n, rv;
    222      1.1      mrg 
    223      1.1      mrg 	bzero(ea, sizeof(struct ebus_attach_args));
    224      1.1      mrg 	rv = getprop(node, "name", 1, &n, (void **)&ea->ea_name);
    225      1.1      mrg 	if (rv != 0)
    226      1.1      mrg 		return (rv);
    227      1.1      mrg 	ea->ea_name[n] = '\0';
    228      1.1      mrg 
    229      1.1      mrg 	ea->ea_node = node;
    230      1.1      mrg 	ea->ea_bustag = sc->sc_childbustag;
    231      1.1      mrg 	ea->ea_dmatag = sc->sc_dmatag;
    232      1.1      mrg 
    233      1.1      mrg 	rv = getprop(node, "reg", sizeof(struct ebus_regs), &ea->ea_nregs,
    234      1.1      mrg 	    (void **)&ea->ea_regs);
    235      1.1      mrg 	if (rv)
    236      1.1      mrg 		return (rv);
    237      1.1      mrg 
    238      1.7      mrg 	rv = getprop(node, "address", sizeof(u_int32_t), &ea->ea_nvaddrs,
    239      1.1      mrg 	    (void **)&ea->ea_vaddrs);
    240      1.1      mrg 	if (rv != ENOENT) {
    241      1.1      mrg 		if (rv)
    242      1.1      mrg 			return (rv);
    243      1.1      mrg 
    244      1.7      mrg 		if (ea->ea_nregs != ea->ea_nvaddrs)
    245      1.1      mrg 			printf("ebus loses: device %s: %d regs and %d addrs\n",
    246      1.7      mrg 			    ea->ea_name, ea->ea_nregs, ea->ea_nvaddrs);
    247      1.3      mrg 	} else
    248      1.7      mrg 		ea->ea_nvaddrs = 0;
    249      1.1      mrg 
    250      1.3      mrg 	if (getprop(node, "interrupts", sizeof(u_int32_t), &ea->ea_nintrs,
    251      1.3      mrg 	    (void **)&ea->ea_intrs))
    252      1.3      mrg 		ea->ea_nintrs = 0;
    253      1.3      mrg 	else
    254      1.3      mrg 		ebus_find_ino(sc, ea);
    255      1.1      mrg 
    256      1.1      mrg 	return (0);
    257      1.1      mrg }
    258      1.1      mrg 
    259      1.1      mrg void
    260      1.1      mrg ebus_destroy_attach_args(ea)
    261      1.1      mrg 	struct ebus_attach_args	*ea;
    262      1.1      mrg {
    263      1.1      mrg 
    264      1.1      mrg 	if (ea->ea_name)
    265      1.1      mrg 		free((void *)ea->ea_name, M_DEVBUF);
    266      1.1      mrg 	if (ea->ea_regs)
    267      1.1      mrg 		free((void *)ea->ea_regs, M_DEVBUF);
    268      1.1      mrg 	if (ea->ea_intrs)
    269      1.1      mrg 		free((void *)ea->ea_intrs, M_DEVBUF);
    270      1.1      mrg 	if (ea->ea_vaddrs)
    271      1.1      mrg 		free((void *)ea->ea_vaddrs, M_DEVBUF);
    272      1.1      mrg }
    273      1.1      mrg 
    274      1.1      mrg int
    275      1.1      mrg ebus_print(aux, p)
    276      1.1      mrg 	void *aux;
    277      1.1      mrg 	const char *p;
    278      1.1      mrg {
    279      1.1      mrg 	struct ebus_attach_args *ea = aux;
    280      1.4      mrg 	int i;
    281      1.1      mrg 
    282      1.1      mrg 	if (p)
    283      1.1      mrg 		printf("%s at %s", ea->ea_name, p);
    284      1.4      mrg 	for (i = 0; i < ea->ea_nregs; i++)
    285      1.4      mrg 		printf(" addr %x-%x", ea->ea_regs[i].lo,
    286      1.4      mrg 		    ea->ea_regs[i].lo + ea->ea_regs[i].size - 1);
    287      1.4      mrg 	for (i = 0; i < ea->ea_nintrs; i++)
    288      1.4      mrg 		printf(" ipl %d", ea->ea_intrs[i]);
    289      1.1      mrg 	return (UNCONF);
    290      1.3      mrg }
    291      1.3      mrg 
    292      1.3      mrg /*
    293      1.3      mrg  * find the INO values for each interrupt and fill them in.
    294      1.3      mrg  *
    295      1.3      mrg  * for each "reg" property of this device, mask it's hi and lo
    296      1.3      mrg  * values with the "interrupt-map-mask"'s hi/lo values, and also
    297      1.3      mrg  * mask the interrupt number with the interrupt mask.  search the
    298      1.3      mrg  * "interrupt-map" list for matching values of hi, lo and interrupt
    299      1.3      mrg  * to give the INO for this interrupt.
    300      1.3      mrg  */
    301      1.3      mrg void
    302      1.3      mrg ebus_find_ino(sc, ea)
    303      1.3      mrg 	struct ebus_softc *sc;
    304      1.3      mrg 	struct ebus_attach_args *ea;
    305      1.3      mrg {
    306      1.3      mrg 	u_int32_t hi, lo, intr;
    307      1.3      mrg 	int i, j, k;
    308      1.3      mrg 
    309      1.3      mrg 	DPRINTF(EDB_INTRMAP, ("ebus_find_ino: searching %d interrupts", ea->ea_nintrs));
    310      1.3      mrg 	for (j = 0; j < ea->ea_nintrs; j++) {
    311      1.3      mrg 		intr = ea->ea_intrs[j] & sc->sc_intmapmask.intr;
    312      1.3      mrg 
    313      1.3      mrg 		DPRINTF(EDB_INTRMAP, ("; intr %x masked to %x", ea->ea_intrs[j], intr));
    314      1.3      mrg 		for (i = 0; i < ea->ea_nregs; i++) {
    315      1.3      mrg 			hi = ea->ea_regs[i].hi & sc->sc_intmapmask.hi;
    316      1.3      mrg 			lo = ea->ea_regs[i].lo & sc->sc_intmapmask.lo;
    317      1.3      mrg 
    318      1.3      mrg 			DPRINTF(EDB_INTRMAP, ("; reg hi.lo %08x.08x masked to %08x.%08x", ea->ea_regs[i].hi, ea->ea_regs[i].lo, hi, lo));
    319      1.3      mrg 			for (k = 0; k < sc->sc_nintmap; k++) {
    320      1.3      mrg 				DPRINTF(EDB_INTRMAP, ("; checking hi.lo %08x.%08x intr %x", sc->sc_intmap[k].hi, sc->sc_intmap[k].lo, sc->sc_intmap[k].intr));
    321      1.3      mrg 				if (hi == sc->sc_intmap[k].hi &&
    322      1.3      mrg 				    lo == sc->sc_intmap[k].lo &&
    323      1.3      mrg 				    intr == sc->sc_intmap[k].intr) {
    324      1.3      mrg 					ea->ea_intrs[j] = sc->sc_intmap[k].cintr;
    325      1.3      mrg 					DPRINTF(EDB_INTRMAP, ("; FOUND IT! changing to %d\n", sc->sc_intmap[k].cintr));
    326      1.3      mrg 					goto next_intr;
    327      1.3      mrg 				}
    328      1.3      mrg 			}
    329      1.3      mrg 		}
    330      1.3      mrg next_intr:
    331      1.3      mrg 	}
    332      1.1      mrg }
    333      1.1      mrg 
    334      1.1      mrg /*
    335      1.9      mrg  * what is our OFW node?  this depends on our pci chipset tag
    336      1.9      mrg  * having it's "node" value set to the OFW node of the PCI bus,
    337      1.9      mrg  * see the simba driver.
    338      1.1      mrg  */
    339      1.1      mrg int
    340  1.9.2.1  minoura ebus_find_node(pa)
    341      1.1      mrg 	struct pci_attach_args *pa;
    342      1.1      mrg {
    343      1.1      mrg 	int node = pa->pa_pc->node;
    344      1.1      mrg 	int n, *ap;
    345      1.1      mrg 	int pcibus, bus, dev, fn;
    346      1.1      mrg 
    347      1.1      mrg 	DPRINTF(EDB_PROM, ("ebus_find_node: looking at pci node %08x\n", node));
    348      1.1      mrg 	for (node = firstchild(node); node; node = nextsibling(node)) {
    349      1.1      mrg 		char *name = getpropstring(node, "name");
    350      1.1      mrg 
    351      1.1      mrg 		DPRINTF(EDB_PROM, ("ebus_find_node: looking at PCI device `%s', node = %08x\n", name, node));
    352      1.1      mrg 		/* must be "ebus" */
    353      1.1      mrg 		if (strcmp(name, "ebus") != 0)
    354      1.1      mrg 			continue;
    355      1.1      mrg 
    356      1.1      mrg 		/* pull the PCI bus out of the pa_tag */
    357      1.1      mrg 		pcibus = (pa->pa_tag >> 16) & 0xff;
    358      1.1      mrg 		DPRINTF(EDB_PROM, ("; pcibus %d dev %d fn %d\n", pcibus, pa->pa_device, pa->pa_function));
    359      1.1      mrg 
    360      1.1      mrg 		/* get the PCI bus/device/function for this node */
    361      1.2      mrg 		ap = NULL;
    362      1.1      mrg 		if (getprop(node, "reg", sizeof(int), &n,
    363      1.1      mrg 		    (void **)&ap))
    364      1.1      mrg 			continue;
    365      1.1      mrg 
    366      1.1      mrg 		bus = (ap[0] >> 16) & 0xff;
    367      1.1      mrg 		dev = (ap[0] >> 11) & 0x1f;
    368      1.1      mrg 		fn = (ap[0] >> 8) & 0x7;
    369      1.1      mrg 
    370      1.1      mrg 		DPRINTF(EDB_PROM, ("; looking for bus %d dev %d fn %d\n", pcibus, pa->pa_device, pa->pa_function));
    371      1.1      mrg 		if (pa->pa_device != dev ||
    372      1.1      mrg 		    pa->pa_function != fn ||
    373      1.1      mrg 		    pcibus != bus)
    374      1.1      mrg 			continue;
    375      1.1      mrg 
    376      1.1      mrg 		DPRINTF(EDB_PROM, ("; found it, returning %08x\n", node));
    377      1.1      mrg 		/* found it! */
    378      1.1      mrg 		free(ap, M_DEVBUF);
    379      1.1      mrg 		return (node);
    380      1.1      mrg 	}
    381      1.1      mrg 
    382      1.1      mrg 	/* damn! */
    383      1.1      mrg 	return (0);
    384      1.8      mrg }
    385      1.8      mrg 
    386      1.8      mrg /*
    387      1.8      mrg  * bus space and bus dma below here
    388      1.8      mrg  */
    389      1.8      mrg bus_space_tag_t
    390      1.8      mrg ebus_alloc_bus_tag(sc, type)
    391      1.8      mrg 	struct ebus_softc *sc;
    392      1.8      mrg 	int type;
    393      1.8      mrg {
    394      1.8      mrg 	bus_space_tag_t bt;
    395      1.8      mrg 
    396      1.8      mrg 	bt = (bus_space_tag_t)
    397      1.8      mrg 		malloc(sizeof(struct sparc_bus_space_tag), M_DEVBUF, M_NOWAIT);
    398      1.8      mrg 	if (bt == NULL)
    399      1.8      mrg 		panic("could not allocate ebus bus tag");
    400      1.8      mrg 
    401      1.8      mrg 	bzero(bt, sizeof *bt);
    402      1.8      mrg 	bt->cookie = sc;
    403      1.8      mrg 	bt->parent = sc->sc_bustag;
    404      1.8      mrg 	bt->type = type;
    405      1.8      mrg 	bt->sparc_bus_map = _ebus_bus_map;
    406      1.8      mrg 	bt->sparc_bus_mmap = ebus_bus_mmap;
    407      1.8      mrg 	bt->sparc_intr_establish = ebus_intr_establish;
    408      1.8      mrg 	return (bt);
    409      1.8      mrg }
    410      1.8      mrg 
    411      1.8      mrg /* XXX? */
    412      1.8      mrg bus_dma_tag_t
    413      1.8      mrg ebus_alloc_dma_tag(sc, pdt)
    414      1.8      mrg 	struct ebus_softc *sc;
    415      1.8      mrg 	bus_dma_tag_t pdt;
    416      1.8      mrg {
    417      1.8      mrg 	bus_dma_tag_t dt;
    418      1.8      mrg 
    419      1.8      mrg 	dt = (bus_dma_tag_t)
    420      1.8      mrg 		malloc(sizeof(struct sparc_bus_dma_tag), M_DEVBUF, M_NOWAIT);
    421      1.8      mrg 	if (dt == NULL)
    422      1.8      mrg 		panic("could not allocate ebus dma tag");
    423      1.8      mrg 
    424      1.8      mrg 	bzero(dt, sizeof *dt);
    425      1.8      mrg 	dt->_cookie = sc;
    426      1.8      mrg 	dt->_parent = pdt;
    427      1.8      mrg #define PCOPY(x)	dt->x = pdt->x
    428      1.8      mrg 	PCOPY(_dmamap_create);
    429      1.8      mrg 	PCOPY(_dmamap_destroy);
    430      1.8      mrg 	dt->_dmamap_load = ebus_dmamap_load;
    431      1.8      mrg 	PCOPY(_dmamap_load_mbuf);
    432      1.8      mrg 	PCOPY(_dmamap_load_uio);
    433      1.8      mrg 	PCOPY(_dmamap_load_raw);
    434      1.8      mrg 	dt->_dmamap_unload = ebus_dmamap_unload;
    435      1.8      mrg 	dt->_dmamap_sync = ebus_dmamap_sync;
    436      1.8      mrg 	dt->_dmamem_alloc = ebus_dmamem_alloc;
    437      1.8      mrg 	dt->_dmamem_free = ebus_dmamem_free;
    438      1.8      mrg 	dt->_dmamem_map = ebus_dmamem_map;
    439      1.8      mrg 	dt->_dmamem_unmap = ebus_dmamem_unmap;
    440      1.8      mrg 	PCOPY(_dmamem_mmap);
    441      1.8      mrg #undef	PCOPY
    442      1.8      mrg 	return (dt);
    443      1.8      mrg }
    444      1.8      mrg 
    445      1.8      mrg /*
    446      1.8      mrg  * bus space support.  <sparc64/dev/psychoreg.h> has a discussion
    447      1.8      mrg  * about PCI physical addresses, which also applies to ebus.
    448      1.8      mrg  */
    449      1.8      mrg static int
    450      1.8      mrg _ebus_bus_map(t, btype, offset, size, flags, vaddr, hp)
    451      1.8      mrg 	bus_space_tag_t t;
    452      1.8      mrg 	bus_type_t btype;
    453      1.8      mrg 	bus_addr_t offset;
    454      1.8      mrg 	bus_size_t size;
    455      1.8      mrg 	int	flags;
    456      1.8      mrg 	vaddr_t vaddr;
    457      1.8      mrg 	bus_space_handle_t *hp;
    458      1.8      mrg {
    459      1.8      mrg 	struct ebus_softc *sc = t->cookie;
    460      1.8      mrg 	bus_addr_t hi, lo;
    461      1.8      mrg 	int i;
    462      1.8      mrg 
    463      1.8      mrg 	DPRINTF(EDB_BUSMAP, ("\n_ebus_bus_map: type %d off %016llx sz %x flags %d va %p", (int)t->type, (u_int64_t)offset, (int)size, (int)flags, vaddr));
    464      1.8      mrg 
    465      1.8      mrg 	hi = offset >> 32UL;
    466      1.8      mrg 	lo = offset & 0xffffffff;
    467      1.8      mrg 	DPRINTF(EDB_BUSMAP, (" (hi %08x lo %08x)", (u_int)hi, (u_int)lo));
    468      1.8      mrg 	for (i = 0; i < sc->sc_nrange; i++) {
    469      1.8      mrg 		bus_addr_t pciaddr;
    470      1.8      mrg 
    471      1.8      mrg 		if (hi != sc->sc_range[i].child_hi)
    472      1.8      mrg 			continue;
    473      1.8      mrg 		if (lo < sc->sc_range[i].child_lo ||
    474      1.8      mrg 		    (lo + size) > (sc->sc_range[i].child_lo + sc->sc_range[i].size))
    475      1.8      mrg 			continue;
    476      1.8      mrg 
    477      1.8      mrg 		pciaddr = ((bus_addr_t)sc->sc_range[i].phys_mid << 32UL) |
    478      1.8      mrg 				       sc->sc_range[i].phys_lo;
    479      1.8      mrg 		pciaddr += lo;
    480      1.8      mrg 		DPRINTF(EDB_BUSMAP, ("\n_ebus_bus_map: mapping paddr offset %qx pciaddr %qx\n",
    481      1.8      mrg 			       offset, pciaddr));
    482      1.8      mrg 		/* pass it onto the psycho */
    483      1.8      mrg 		return (bus_space_map2(sc->sc_bustag, t->type, pciaddr,
    484      1.8      mrg 					size, flags, vaddr, hp));
    485      1.8      mrg 	}
    486      1.8      mrg 	DPRINTF(EDB_BUSMAP, (": FAILED\n"));
    487      1.8      mrg 	return (EINVAL);
    488      1.8      mrg }
    489      1.8      mrg 
    490      1.8      mrg static int
    491      1.8      mrg ebus_bus_mmap(t, btype, paddr, flags, hp)
    492      1.8      mrg 	bus_space_tag_t t;
    493      1.8      mrg 	bus_type_t btype;
    494      1.8      mrg 	bus_addr_t paddr;
    495      1.8      mrg 	int flags;
    496      1.8      mrg 	bus_space_handle_t *hp;
    497      1.8      mrg {
    498      1.8      mrg 	bus_addr_t offset = paddr;
    499      1.8      mrg 	struct ebus_softc *sc = t->cookie;
    500      1.8      mrg 	int i;
    501      1.8      mrg 
    502      1.8      mrg 	for (i = 0; i < sc->sc_nrange; i++) {
    503      1.8      mrg 		bus_addr_t paddr = ((bus_addr_t)sc->sc_range[i].child_hi << 32) |
    504      1.8      mrg 		    sc->sc_range[i].child_lo;
    505      1.8      mrg 
    506      1.8      mrg 		if (offset != paddr)
    507      1.8      mrg 			continue;
    508      1.8      mrg 
    509      1.8      mrg 		DPRINTF(EDB_BUSMAP, ("\n_ebus_bus_mmap: mapping paddr %qx\n", paddr));
    510      1.8      mrg 		return (bus_space_mmap(sc->sc_bustag, 0, paddr,
    511      1.8      mrg 				       flags, hp));
    512      1.8      mrg 	}
    513      1.8      mrg 
    514      1.8      mrg 	return (-1);
    515      1.8      mrg }
    516      1.8      mrg 
    517      1.8      mrg /*
    518      1.8      mrg  * install an interrupt handler for a PCI device
    519      1.8      mrg  */
    520      1.8      mrg void *
    521      1.8      mrg ebus_intr_establish(t, level, flags, handler, arg)
    522      1.8      mrg 	bus_space_tag_t t;
    523      1.8      mrg 	int level;
    524      1.8      mrg 	int flags;
    525      1.8      mrg 	int (*handler) __P((void *));
    526      1.8      mrg 	void *arg;
    527      1.8      mrg {
    528      1.8      mrg 
    529      1.8      mrg 	/* XXX */
    530      1.8      mrg 	return (0);
    531      1.8      mrg }
    532      1.8      mrg 
    533      1.8      mrg /*
    534      1.8      mrg  * bus dma support
    535      1.8      mrg  */
    536      1.8      mrg int
    537      1.8      mrg ebus_dmamap_load(t, map, buf, buflen, p, flags)
    538      1.8      mrg 	bus_dma_tag_t t;
    539      1.8      mrg 	bus_dmamap_t map;
    540      1.8      mrg 	void *buf;
    541      1.8      mrg 	bus_size_t buflen;
    542      1.8      mrg 	struct proc *p;
    543      1.8      mrg 	int flags;
    544      1.8      mrg {
    545      1.8      mrg 	struct ebus_softc *sc = t->_cookie;
    546      1.8      mrg 
    547      1.8      mrg 	return (iommu_dvmamap_load(t, &sc->sc_parent->sc_is, map, buf, buflen,
    548      1.8      mrg 	    p, flags));
    549      1.8      mrg }
    550      1.8      mrg 
    551      1.8      mrg void
    552      1.8      mrg ebus_dmamap_unload(t, map)
    553      1.8      mrg 	bus_dma_tag_t t;
    554      1.8      mrg 	bus_dmamap_t map;
    555      1.8      mrg {
    556      1.8      mrg 	struct ebus_softc *sc = t->_cookie;
    557      1.8      mrg 
    558      1.8      mrg 	iommu_dvmamap_unload(t, &sc->sc_parent->sc_is, map);
    559      1.8      mrg }
    560      1.8      mrg 
    561      1.8      mrg void
    562      1.8      mrg ebus_dmamap_sync(t, map, offset, len, ops)
    563      1.8      mrg 	bus_dma_tag_t t;
    564      1.8      mrg 	bus_dmamap_t map;
    565      1.8      mrg 	bus_addr_t offset;
    566      1.8      mrg 	bus_size_t len;
    567      1.8      mrg 	int ops;
    568      1.8      mrg {
    569      1.8      mrg 	struct ebus_softc *sc = t->_cookie;
    570      1.8      mrg 
    571      1.8      mrg 	iommu_dvmamap_sync(t, &sc->sc_parent->sc_is, map, offset, len, ops);
    572      1.8      mrg 	bus_dmamap_sync(t->_parent, map, offset, len, ops);
    573      1.8      mrg }
    574      1.8      mrg 
    575      1.8      mrg int
    576      1.8      mrg ebus_dmamem_alloc(t, size, alignment, boundary, segs, nsegs, rsegs, flags)
    577      1.8      mrg 	bus_dma_tag_t t;
    578      1.8      mrg 	bus_size_t size;
    579      1.8      mrg 	bus_size_t alignment;
    580      1.8      mrg 	bus_size_t boundary;
    581      1.8      mrg 	bus_dma_segment_t *segs;
    582      1.8      mrg 	int nsegs;
    583      1.8      mrg 	int *rsegs;
    584      1.8      mrg 	int flags;
    585      1.8      mrg {
    586      1.8      mrg 	struct ebus_softc *sc = t->_cookie;
    587      1.8      mrg 
    588      1.8      mrg 	return (iommu_dvmamem_alloc(t, &sc->sc_parent->sc_is, size, alignment,
    589      1.8      mrg 	    boundary, segs, nsegs, rsegs, flags));
    590      1.8      mrg }
    591      1.8      mrg 
    592      1.8      mrg void
    593      1.8      mrg ebus_dmamem_free(t, segs, nsegs)
    594      1.8      mrg 	bus_dma_tag_t t;
    595      1.8      mrg 	bus_dma_segment_t *segs;
    596      1.8      mrg 	int nsegs;
    597      1.8      mrg {
    598      1.8      mrg 	struct ebus_softc *sc = t->_cookie;
    599      1.8      mrg 
    600      1.8      mrg 	iommu_dvmamem_free(t, &sc->sc_parent->sc_is, segs, nsegs);
    601      1.8      mrg }
    602      1.8      mrg 
    603      1.8      mrg int
    604      1.8      mrg ebus_dmamem_map(t, segs, nsegs, size, kvap, flags)
    605      1.8      mrg 	bus_dma_tag_t t;
    606      1.8      mrg 	bus_dma_segment_t *segs;
    607      1.8      mrg 	int nsegs;
    608      1.8      mrg 	size_t size;
    609      1.8      mrg 	caddr_t *kvap;
    610      1.8      mrg 	int flags;
    611      1.8      mrg {
    612      1.8      mrg 	struct ebus_softc *sc = t->_cookie;
    613      1.8      mrg 
    614      1.8      mrg 	return (iommu_dvmamem_map(t, &sc->sc_parent->sc_is, segs, nsegs,
    615      1.8      mrg 	    size, kvap, flags));
    616      1.8      mrg }
    617      1.8      mrg 
    618      1.8      mrg void
    619      1.8      mrg ebus_dmamem_unmap(t, kva, size)
    620      1.8      mrg 	bus_dma_tag_t t;
    621      1.8      mrg 	caddr_t kva;
    622      1.8      mrg 	size_t size;
    623      1.8      mrg {
    624      1.8      mrg 	struct ebus_softc *sc = t->_cookie;
    625      1.8      mrg 
    626      1.8      mrg 	iommu_dvmamem_unmap(t, &sc->sc_parent->sc_is, kva, size);
    627      1.1      mrg }
    628