Home | History | Annotate | Line # | Download | only in dev
sbus.c revision 1.51
      1  1.51  thorpej /*	$NetBSD: sbus.c,v 1.51 2002/08/23 02:53:12 thorpej Exp $ */
      2   1.1      eeh 
      3  1.50      eeh /*
      4  1.50      eeh  * Copyright (c) 1999-2002 Eduardo Horvath
      5   1.1      eeh  * All rights reserved.
      6   1.1      eeh  *
      7   1.1      eeh  * Redistribution and use in source and binary forms, with or without
      8   1.1      eeh  * modification, are permitted provided that the following conditions
      9   1.1      eeh  * are met:
     10   1.1      eeh  * 1. Redistributions of source code must retain the above copyright
     11   1.1      eeh  *    notice, this list of conditions and the following disclaimer.
     12   1.1      eeh  * 2. Redistributions in binary form must reproduce the above copyright
     13   1.1      eeh  *    notice, this list of conditions and the following disclaimer in the
     14   1.1      eeh  *    documentation and/or other materials provided with the distribution.
     15  1.50      eeh  * 3. The name of the author may not be used to endorse or promote products
     16  1.50      eeh  *    derived from this software without specific prior written permission.
     17  1.18      eeh  *
     18  1.50      eeh  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     19  1.50      eeh  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     20  1.50      eeh  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     21  1.50      eeh  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     22  1.50      eeh  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
     23  1.50      eeh  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
     24  1.50      eeh  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
     25  1.50      eeh  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
     26  1.50      eeh  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     27  1.18      eeh  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     28  1.18      eeh  * SUCH DAMAGE.
     29  1.18      eeh  */
     30  1.18      eeh 
     31  1.18      eeh 
     32  1.18      eeh /*
     33   1.1      eeh  * Sbus stuff.
     34   1.1      eeh  */
     35   1.8      eeh #include "opt_ddb.h"
     36   1.1      eeh 
     37   1.1      eeh #include <sys/param.h>
     38  1.12      eeh #include <sys/extent.h>
     39   1.1      eeh #include <sys/malloc.h>
     40   1.1      eeh #include <sys/systm.h>
     41   1.1      eeh #include <sys/device.h>
     42  1.40      eeh #include <sys/reboot.h>
     43   1.1      eeh 
     44   1.1      eeh #include <machine/bus.h>
     45  1.50      eeh #include <machine/openfirm.h>
     46  1.50      eeh 
     47  1.25      mrg #include <sparc64/sparc64/cache.h>
     48  1.13      mrg #include <sparc64/dev/iommureg.h>
     49  1.17      mrg #include <sparc64/dev/iommuvar.h>
     50   1.1      eeh #include <sparc64/dev/sbusreg.h>
     51   1.7       pk #include <dev/sbus/sbusvar.h>
     52   1.1      eeh 
     53  1.44      eeh #include <uvm/uvm_prot.h>
     54  1.44      eeh 
     55   1.1      eeh #include <machine/autoconf.h>
     56   1.1      eeh #include <machine/cpu.h>
     57   1.8      eeh #include <machine/sparc64.h>
     58   1.1      eeh 
     59   1.1      eeh #ifdef DEBUG
     60   1.1      eeh #define SDB_DVMA	0x1
     61   1.1      eeh #define SDB_INTR	0x2
     62  1.27      mrg int sbus_debug = 0;
     63  1.27      mrg #define DPRINTF(l, s)   do { if (sbus_debug & l) printf s; } while (0)
     64  1.27      mrg #else
     65  1.27      mrg #define DPRINTF(l, s)
     66   1.1      eeh #endif
     67   1.1      eeh 
     68   1.1      eeh void sbusreset __P((int));
     69   1.1      eeh 
     70   1.1      eeh static bus_space_tag_t sbus_alloc_bustag __P((struct sbus_softc *));
     71   1.1      eeh static bus_dma_tag_t sbus_alloc_dmatag __P((struct sbus_softc *));
     72   1.3      eeh static int sbus_get_intr __P((struct sbus_softc *, int,
     73  1.51  thorpej 			      struct openprom_intr **, int *, int));
     74  1.40      eeh static int sbus_overtemp __P((void *));
     75   1.1      eeh static int _sbus_bus_map __P((
     76   1.1      eeh 		bus_space_tag_t,
     77   1.1      eeh 		bus_addr_t,		/*offset*/
     78   1.1      eeh 		bus_size_t,		/*size*/
     79   1.1      eeh 		int,			/*flags*/
     80  1.47      eeh 		vaddr_t,			/* XXX unused -- compat w/sparc */
     81   1.1      eeh 		bus_space_handle_t *));
     82   1.1      eeh static void *sbus_intr_establish __P((
     83   1.1      eeh 		bus_space_tag_t,
     84  1.35       pk 		int,			/*Sbus interrupt level*/
     85  1.35       pk 		int,			/*`device class' priority*/
     86   1.1      eeh 		int,			/*flags*/
     87   1.1      eeh 		int (*) __P((void *)),	/*handler*/
     88   1.1      eeh 		void *));		/*handler arg*/
     89   1.1      eeh 
     90   1.1      eeh 
     91   1.1      eeh /* autoconfiguration driver */
     92   1.1      eeh int	sbus_match __P((struct device *, struct cfdata *, void *));
     93   1.1      eeh void	sbus_attach __P((struct device *, struct device *, void *));
     94   1.1      eeh 
     95   1.1      eeh 
     96   1.1      eeh struct cfattach sbus_ca = {
     97   1.1      eeh 	sizeof(struct sbus_softc), sbus_match, sbus_attach
     98   1.1      eeh };
     99   1.1      eeh 
    100   1.1      eeh extern struct cfdriver sbus_cd;
    101   1.1      eeh 
    102   1.1      eeh /*
    103   1.1      eeh  * DVMA routines
    104   1.1      eeh  */
    105   1.1      eeh int sbus_dmamap_load __P((bus_dma_tag_t, bus_dmamap_t, void *,
    106   1.1      eeh 			  bus_size_t, struct proc *, int));
    107   1.1      eeh void sbus_dmamap_unload __P((bus_dma_tag_t, bus_dmamap_t));
    108  1.29      eeh int sbus_dmamap_load_raw __P((bus_dma_tag_t, bus_dmamap_t,
    109  1.29      eeh 		    bus_dma_segment_t *, int, bus_size_t, int));
    110   1.1      eeh void sbus_dmamap_sync __P((bus_dma_tag_t, bus_dmamap_t, bus_addr_t,
    111   1.1      eeh 			   bus_size_t, int));
    112   1.1      eeh int sbus_dmamem_alloc __P((bus_dma_tag_t tag, bus_size_t size,
    113   1.1      eeh 			   bus_size_t alignment, bus_size_t boundary,
    114  1.28      mrg 			   bus_dma_segment_t *segs, int nsegs, int *rsegs,
    115  1.28      mrg 			   int flags));
    116   1.1      eeh void sbus_dmamem_free __P((bus_dma_tag_t tag, bus_dma_segment_t *segs,
    117   1.1      eeh 			   int nsegs));
    118   1.2      eeh int sbus_dmamem_map __P((bus_dma_tag_t tag, bus_dma_segment_t *segs,
    119   1.2      eeh 			 int nsegs, size_t size, caddr_t *kvap, int flags));
    120   1.2      eeh void sbus_dmamem_unmap __P((bus_dma_tag_t tag, caddr_t kva,
    121   1.2      eeh 			    size_t size));
    122   1.1      eeh 
    123   1.1      eeh /*
    124   1.1      eeh  * Child devices receive the Sbus interrupt level in their attach
    125   1.1      eeh  * arguments. We translate these to CPU IPLs using the following
    126   1.1      eeh  * tables. Note: obio bus interrupt levels are identical to the
    127   1.1      eeh  * processor IPL.
    128   1.1      eeh  *
    129   1.1      eeh  * The second set of tables is used when the Sbus interrupt level
    130   1.1      eeh  * cannot be had from the PROM as an `interrupt' property. We then
    131   1.1      eeh  * fall back on the `intr' property which contains the CPU IPL.
    132   1.1      eeh  */
    133   1.1      eeh 
    134   1.1      eeh /*
    135   1.1      eeh  * This value is or'ed into the attach args' interrupt level cookie
    136   1.1      eeh  * if the interrupt level comes from an `intr' property, i.e. it is
    137   1.1      eeh  * not an Sbus interrupt level.
    138   1.1      eeh  */
    139   1.1      eeh #define SBUS_INTR_COMPAT	0x80000000
    140   1.1      eeh 
    141   1.1      eeh 
    142   1.1      eeh /*
    143   1.1      eeh  * Print the location of some sbus-attached device (called just
    144   1.1      eeh  * before attaching that device).  If `sbus' is not NULL, the
    145   1.1      eeh  * device was found but not configured; print the sbus as well.
    146   1.1      eeh  * Return UNCONF (config_find ignores this if the device was configured).
    147   1.1      eeh  */
    148   1.1      eeh int
    149   1.1      eeh sbus_print(args, busname)
    150   1.1      eeh 	void *args;
    151   1.1      eeh 	const char *busname;
    152   1.1      eeh {
    153   1.1      eeh 	struct sbus_attach_args *sa = args;
    154   1.3      eeh 	int i;
    155   1.1      eeh 
    156   1.1      eeh 	if (busname)
    157   1.1      eeh 		printf("%s at %s", sa->sa_name, busname);
    158   1.8      eeh 	printf(" slot %ld offset 0x%lx", (long)sa->sa_slot,
    159   1.8      eeh 	       (u_long)sa->sa_offset);
    160  1.22      mrg 	for (i = 0; i < sa->sa_nintr; i++) {
    161  1.51  thorpej 		struct openprom_intr *sbi = &sa->sa_intr[i];
    162   1.1      eeh 
    163   1.8      eeh 		printf(" vector %lx ipl %ld",
    164  1.51  thorpej 		       (u_long)sbi->oi_vec,
    165  1.51  thorpej 		       (long)INTLEV(sbi->oi_pri));
    166   1.1      eeh 	}
    167   1.1      eeh 	return (UNCONF);
    168   1.1      eeh }
    169   1.1      eeh 
    170   1.1      eeh int
    171   1.1      eeh sbus_match(parent, cf, aux)
    172   1.1      eeh 	struct device *parent;
    173   1.1      eeh 	struct cfdata *cf;
    174   1.1      eeh 	void *aux;
    175   1.1      eeh {
    176   1.1      eeh 	struct mainbus_attach_args *ma = aux;
    177   1.1      eeh 
    178   1.1      eeh 	return (strcmp(cf->cf_driver->cd_name, ma->ma_name) == 0);
    179   1.1      eeh }
    180   1.1      eeh 
    181   1.1      eeh /*
    182   1.1      eeh  * Attach an Sbus.
    183   1.1      eeh  */
    184   1.1      eeh void
    185   1.1      eeh sbus_attach(parent, self, aux)
    186   1.1      eeh 	struct device *parent;
    187   1.1      eeh 	struct device *self;
    188   1.1      eeh 	void *aux;
    189   1.1      eeh {
    190   1.9      eeh 	struct sbus_softc *sc = (struct sbus_softc *)self;
    191   1.1      eeh 	struct mainbus_attach_args *ma = aux;
    192  1.40      eeh 	struct intrhand *ih;
    193  1.40      eeh 	int ipl;
    194  1.27      mrg 	char *name;
    195   1.1      eeh 	int node = ma->ma_node;
    196   1.1      eeh 	int node0, error;
    197   1.1      eeh 	bus_space_tag_t sbt;
    198   1.1      eeh 	struct sbus_attach_args sa;
    199   1.1      eeh 
    200   1.1      eeh 	sc->sc_bustag = ma->ma_bustag;
    201   1.1      eeh 	sc->sc_dmatag = ma->ma_dmatag;
    202  1.48      eeh 	sc->sc_ign = ma->ma_interrupts[0] & INTMAP_IGN;
    203   1.1      eeh 
    204  1.48      eeh 	/* XXXX Use sysio PROM mappings for interrupt vector regs. */
    205  1.48      eeh 	sparc_promaddr_to_handle(sc->sc_bustag,	ma->ma_address[0], &sc->sc_bh);
    206  1.48      eeh 	sc->sc_sysio = (struct sysioreg *)bus_space_vaddr(sc->sc_bustag,
    207  1.49      eeh 		sc->sc_bh);
    208  1.48      eeh 
    209  1.48      eeh #ifdef _LP64
    210  1.48      eeh 	/*
    211  1.48      eeh 	 * 32-bit kernels use virtual addresses for bus space operations
    212  1.48      eeh 	 * so we may as well use the prom VA.
    213  1.48      eeh 	 *
    214  1.48      eeh 	 * 64-bit kernels use physical addresses for bus space operations
    215  1.48      eeh 	 * so mapping this in again will reduce TLB thrashing.
    216  1.48      eeh 	 */
    217  1.48      eeh 	if (bus_space_map(sc->sc_bustag, ma->ma_reg[0].ur_paddr,
    218  1.48      eeh 		ma->ma_reg[0].ur_len, 0, &sc->sc_bh) != 0) {
    219  1.48      eeh 		printf("%s: cannot map registers\n", self->dv_xname);
    220  1.48      eeh 		return;
    221  1.48      eeh 	}
    222  1.48      eeh #endif
    223   1.1      eeh 
    224   1.1      eeh 	/*
    225   1.1      eeh 	 * Record clock frequency for synchronous SCSI.
    226   1.1      eeh 	 * IS THIS THE CORRECT DEFAULT??
    227   1.1      eeh 	 */
    228  1.48      eeh 	sc->sc_clockfreq = PROM_getpropint(node, "clock-frequency",
    229  1.48      eeh 		25*1000*1000);
    230   1.1      eeh 	printf(": clock = %s MHz\n", clockfreq(sc->sc_clockfreq));
    231   1.1      eeh 
    232   1.1      eeh 	sbt = sbus_alloc_bustag(sc);
    233   1.1      eeh 	sc->sc_dmatag = sbus_alloc_dmatag(sc);
    234   1.1      eeh 
    235   1.1      eeh 	/*
    236   1.1      eeh 	 * Get the SBus burst transfer size if burst transfers are supported
    237   1.1      eeh 	 */
    238  1.45      eeh 	sc->sc_burst = PROM_getpropint(node, "burst-sizes", 0);
    239   1.1      eeh 
    240   1.1      eeh 	/*
    241   1.1      eeh 	 * Collect address translations from the OBP.
    242   1.1      eeh 	 */
    243  1.51  thorpej 	error = PROM_getprop(node, "ranges", sizeof(struct openprom_range),
    244   1.1      eeh 			 &sc->sc_nrange, (void **)&sc->sc_range);
    245  1.16      eeh 	if (error)
    246   1.1      eeh 		panic("%s: error getting ranges property", sc->sc_dev.dv_xname);
    247   1.1      eeh 
    248  1.48      eeh 	/* initialize the IOMMU */
    249  1.17      mrg 
    250  1.17      mrg 	/* punch in our copies */
    251  1.17      mrg 	sc->sc_is.is_bustag = sc->sc_bustag;
    252  1.48      eeh 	bus_space_subregion(sc->sc_bustag, sc->sc_bh,
    253  1.48      eeh 		(vaddr_t)&((struct sysioreg *)NULL)->sys_iommu,
    254  1.48      eeh 		sizeof (struct iommureg), &sc->sc_is.is_iommu);
    255  1.50      eeh 
    256  1.50      eeh 	/* initialize our strbuf_ctl */
    257  1.50      eeh 	sc->sc_is.is_sb[0] = &sc->sc_sb;
    258  1.50      eeh 	sc->sc_sb.sb_is = &sc->sc_is;
    259  1.48      eeh 	bus_space_subregion(sc->sc_bustag, sc->sc_bh,
    260  1.48      eeh 		(vaddr_t)&((struct sysioreg *)NULL)->sys_strbuf,
    261  1.50      eeh 		sizeof (struct iommu_strbuf), &sc->sc_sb.sb_sb);
    262  1.50      eeh 	/* Point sb_flush to our flush buffer. */
    263  1.50      eeh 	sc->sc_sb.sb_flush = &sc->sc_flush;
    264  1.16      eeh 
    265  1.27      mrg 	/* give us a nice name.. */
    266  1.27      mrg 	name = (char *)malloc(32, M_DEVBUF, M_NOWAIT);
    267  1.27      mrg 	if (name == 0)
    268  1.27      mrg 		panic("couldn't malloc iommu name");
    269  1.27      mrg 	snprintf(name, 32, "%s dvma", sc->sc_dev.dv_xname);
    270  1.27      mrg 
    271  1.43      eeh 	iommu_init(name, &sc->sc_is, 0, -1);
    272  1.12      eeh 
    273  1.40      eeh 	/* Enable the over temp intr */
    274  1.40      eeh 	ih = (struct intrhand *)
    275  1.40      eeh 		malloc(sizeof(struct intrhand), M_DEVBUF, M_NOWAIT);
    276  1.40      eeh 	ih->ih_map = &sc->sc_sysio->therm_int_map;
    277  1.40      eeh 	ih->ih_clr = NULL; /* &sc->sc_sysio->therm_clr_int; */
    278  1.40      eeh 	ih->ih_fun = sbus_overtemp;
    279  1.40      eeh 	ipl = 1;
    280  1.40      eeh 	ih->ih_pil = (1<<ipl);
    281  1.40      eeh 	ih->ih_number = INTVEC(*(ih->ih_map));
    282  1.40      eeh 	intr_establish(ipl, ih);
    283  1.40      eeh 	*(ih->ih_map) |= INTMAP_V;
    284  1.40      eeh 
    285  1.42      mrg 	/*
    286  1.42      mrg 	 * Note: the stupid SBUS IOMMU ignores the high bits of an address, so a
    287  1.42      mrg 	 * NULL DMA pointer will be translated by the first page of the IOTSB.
    288  1.42      mrg 	 * To avoid bugs we'll alloc and ignore the first entry in the IOTSB.
    289  1.42      mrg 	 */
    290  1.42      mrg 	{
    291  1.42      mrg 		u_long dummy;
    292  1.42      mrg 
    293  1.42      mrg 		if (extent_alloc_subregion(sc->sc_is.is_dvmamap,
    294  1.42      mrg 		    sc->sc_is.is_dvmabase, sc->sc_is.is_dvmabase + NBPG, NBPG,
    295  1.42      mrg 		    NBPG, 0, EX_NOWAIT|EX_BOUNDZERO, (u_long *)&dummy) != 0)
    296  1.42      mrg 			panic("sbus iommu: can't toss first dvma page");
    297  1.42      mrg 	}
    298  1.42      mrg 
    299  1.12      eeh 	/*
    300   1.1      eeh 	 * Loop through ROM children, fixing any relative addresses
    301   1.1      eeh 	 * and then configuring each device.
    302   1.1      eeh 	 * `specials' is an array of device names that are treated
    303   1.1      eeh 	 * specially:
    304   1.1      eeh 	 */
    305  1.50      eeh 	node0 = OF_child(node);
    306  1.50      eeh 	for (node = node0; node; node = OF_peer(node)) {
    307  1.45      eeh 		char *name = PROM_getpropstring(node, "name");
    308   1.1      eeh 
    309   1.1      eeh 		if (sbus_setup_attach_args(sc, sbt, sc->sc_dmatag,
    310  1.23       pk 					   node, &sa) != 0) {
    311   1.1      eeh 			printf("sbus_attach: %s: incomplete\n", name);
    312   1.1      eeh 			continue;
    313   1.1      eeh 		}
    314   1.1      eeh 		(void) config_found(&sc->sc_dev, (void *)&sa, sbus_print);
    315   1.3      eeh 		sbus_destroy_attach_args(&sa);
    316   1.1      eeh 	}
    317   1.1      eeh }
    318   1.1      eeh 
    319   1.1      eeh int
    320  1.23       pk sbus_setup_attach_args(sc, bustag, dmatag, node, sa)
    321   1.1      eeh 	struct sbus_softc	*sc;
    322   1.1      eeh 	bus_space_tag_t		bustag;
    323   1.1      eeh 	bus_dma_tag_t		dmatag;
    324   1.1      eeh 	int			node;
    325   1.1      eeh 	struct sbus_attach_args	*sa;
    326   1.1      eeh {
    327  1.51  thorpej 	/*struct	openprom_addr sbusreg;*/
    328   1.3      eeh 	/*int	base;*/
    329   1.1      eeh 	int	error;
    330   1.3      eeh 	int n;
    331   1.1      eeh 
    332   1.1      eeh 	bzero(sa, sizeof(struct sbus_attach_args));
    333  1.45      eeh 	error = PROM_getprop(node, "name", 1, &n, (void **)&sa->sa_name);
    334   1.3      eeh 	if (error != 0)
    335   1.3      eeh 		return (error);
    336   1.3      eeh 	sa->sa_name[n] = '\0';
    337   1.3      eeh 
    338   1.1      eeh 	sa->sa_bustag = bustag;
    339   1.1      eeh 	sa->sa_dmatag = dmatag;
    340   1.1      eeh 	sa->sa_node = node;
    341  1.37      eeh 	sa->sa_frequency = sc->sc_clockfreq;
    342   1.1      eeh 
    343  1.51  thorpej 	error = PROM_getprop(node, "reg", sizeof(struct openprom_addr),
    344   1.3      eeh 			 &sa->sa_nreg, (void **)&sa->sa_reg);
    345   1.3      eeh 	if (error != 0) {
    346   1.3      eeh 		char buf[32];
    347   1.3      eeh 		if (error != ENOENT ||
    348   1.3      eeh 		    !node_has_property(node, "device_type") ||
    349  1.45      eeh 		    strcmp(PROM_getpropstringA(node, "device_type", buf),
    350   1.3      eeh 			   "hierarchical") != 0)
    351   1.3      eeh 			return (error);
    352   1.3      eeh 	}
    353   1.3      eeh 	for (n = 0; n < sa->sa_nreg; n++) {
    354   1.3      eeh 		/* Convert to relative addressing, if necessary */
    355  1.51  thorpej 		u_int32_t base = sa->sa_reg[n].oa_base;
    356   1.3      eeh 		if (SBUS_ABS(base)) {
    357  1.51  thorpej 			sa->sa_reg[n].oa_space = SBUS_ABS_TO_SLOT(base);
    358  1.51  thorpej 			sa->sa_reg[n].oa_base = SBUS_ABS_TO_OFFSET(base);
    359   1.3      eeh 		}
    360   1.1      eeh 	}
    361   1.1      eeh 
    362  1.22      mrg 	if ((error = sbus_get_intr(sc, node, &sa->sa_intr, &sa->sa_nintr,
    363  1.22      mrg 	    sa->sa_slot)) != 0)
    364   1.1      eeh 		return (error);
    365   1.1      eeh 
    366  1.45      eeh 	error = PROM_getprop(node, "address", sizeof(u_int32_t),
    367   1.3      eeh 			 &sa->sa_npromvaddrs, (void **)&sa->sa_promvaddrs);
    368   1.3      eeh 	if (error != 0 && error != ENOENT)
    369   1.1      eeh 		return (error);
    370   1.1      eeh 
    371   1.1      eeh 	return (0);
    372   1.1      eeh }
    373   1.1      eeh 
    374   1.3      eeh void
    375   1.3      eeh sbus_destroy_attach_args(sa)
    376   1.3      eeh 	struct sbus_attach_args	*sa;
    377   1.3      eeh {
    378   1.3      eeh 	if (sa->sa_name != NULL)
    379   1.3      eeh 		free(sa->sa_name, M_DEVBUF);
    380   1.3      eeh 
    381   1.3      eeh 	if (sa->sa_nreg != 0)
    382   1.3      eeh 		free(sa->sa_reg, M_DEVBUF);
    383   1.3      eeh 
    384   1.3      eeh 	if (sa->sa_intr)
    385   1.3      eeh 		free(sa->sa_intr, M_DEVBUF);
    386   1.3      eeh 
    387   1.3      eeh 	if (sa->sa_promvaddrs)
    388   1.8      eeh 		free((void *)sa->sa_promvaddrs, M_DEVBUF);
    389   1.3      eeh 
    390  1.27      mrg 	bzero(sa, sizeof(struct sbus_attach_args)); /*DEBUG*/
    391   1.3      eeh }
    392   1.3      eeh 
    393   1.3      eeh 
    394   1.1      eeh int
    395  1.47      eeh _sbus_bus_map(t, addr, size, flags, v, hp)
    396   1.1      eeh 	bus_space_tag_t t;
    397  1.47      eeh 	bus_addr_t addr;
    398   1.1      eeh 	bus_size_t size;
    399   1.1      eeh 	int	flags;
    400  1.47      eeh 	vaddr_t v;
    401   1.1      eeh 	bus_space_handle_t *hp;
    402   1.1      eeh {
    403   1.1      eeh 	struct sbus_softc *sc = t->cookie;
    404  1.47      eeh 	int64_t slot = BUS_ADDR_IOSPACE(addr);
    405  1.47      eeh 	int64_t offset = BUS_ADDR_PADDR(addr);
    406   1.1      eeh 	int i;
    407   1.1      eeh 
    408   1.1      eeh 	for (i = 0; i < sc->sc_nrange; i++) {
    409   1.1      eeh 		bus_addr_t paddr;
    410   1.1      eeh 
    411  1.51  thorpej 		if (sc->sc_range[i].or_child_space != slot)
    412   1.1      eeh 			continue;
    413   1.1      eeh 
    414   1.1      eeh 		/* We've found the connection to the parent bus */
    415  1.51  thorpej 		paddr = sc->sc_range[i].or_parent_base + offset;
    416  1.51  thorpej 		paddr |= ((bus_addr_t)sc->sc_range[i].or_parent_space<<32);
    417  1.27      mrg 		DPRINTF(SDB_DVMA,
    418  1.27      mrg ("\n_sbus_bus_map: mapping paddr slot %lx offset %lx poffset %lx paddr %lx\n",
    419  1.51  thorpej 		    (long)slot, (long)offset,
    420  1.51  thorpej 		    (long)sc->sc_range[i].or_parent_base,
    421  1.27      mrg 		    (long)paddr));
    422  1.47      eeh 		return (bus_space_map(sc->sc_bustag, paddr, size, flags, hp));
    423   1.1      eeh 	}
    424   1.1      eeh 
    425   1.1      eeh 	return (EINVAL);
    426   1.1      eeh }
    427   1.1      eeh 
    428  1.44      eeh 
    429  1.44      eeh bus_addr_t
    430  1.44      eeh sbus_bus_addr(t, btype, offset)
    431  1.44      eeh 	bus_space_tag_t t;
    432  1.44      eeh 	u_int btype;
    433  1.44      eeh 	u_int offset;
    434  1.44      eeh {
    435  1.44      eeh 	bus_addr_t baddr;
    436  1.44      eeh 	int slot = btype;
    437  1.44      eeh 	struct sbus_softc *sc = t->cookie;
    438  1.44      eeh 	int i;
    439  1.44      eeh 
    440  1.44      eeh 	for (i = 0; i < sc->sc_nrange; i++) {
    441  1.51  thorpej 		if (sc->sc_range[i].or_child_space != slot)
    442  1.44      eeh 			continue;
    443  1.44      eeh 
    444  1.51  thorpej 		baddr = sc->sc_range[i].or_parent_base + offset;
    445  1.51  thorpej 		baddr |= ((bus_addr_t)sc->sc_range[i].or_parent_space<<32);
    446   1.1      eeh 	}
    447   1.1      eeh 
    448  1.44      eeh 	return (baddr);
    449   1.1      eeh }
    450   1.1      eeh 
    451   1.1      eeh 
    452   1.1      eeh /*
    453   1.1      eeh  * Each attached device calls sbus_establish after it initializes
    454   1.1      eeh  * its sbusdev portion.
    455   1.1      eeh  */
    456   1.1      eeh void
    457   1.1      eeh sbus_establish(sd, dev)
    458   1.1      eeh 	register struct sbusdev *sd;
    459   1.1      eeh 	register struct device *dev;
    460   1.1      eeh {
    461   1.1      eeh 	register struct sbus_softc *sc;
    462   1.1      eeh 	register struct device *curdev;
    463   1.1      eeh 
    464   1.1      eeh 	/*
    465   1.1      eeh 	 * We have to look for the sbus by name, since it is not necessarily
    466   1.1      eeh 	 * our immediate parent (i.e. sun4m /iommu/sbus/espdma/esp)
    467   1.1      eeh 	 * We don't just use the device structure of the above-attached
    468   1.1      eeh 	 * sbus, since we might (in the future) support multiple sbus's.
    469   1.1      eeh 	 */
    470   1.1      eeh 	for (curdev = dev->dv_parent; ; curdev = curdev->dv_parent) {
    471   1.1      eeh 		if (!curdev || !curdev->dv_xname)
    472   1.1      eeh 			panic("sbus_establish: can't find sbus parent for %s",
    473   1.1      eeh 			      sd->sd_dev->dv_xname
    474   1.1      eeh 					? sd->sd_dev->dv_xname
    475   1.1      eeh 					: "<unknown>" );
    476   1.1      eeh 
    477   1.1      eeh 		if (strncmp(curdev->dv_xname, "sbus", 4) == 0)
    478   1.1      eeh 			break;
    479   1.1      eeh 	}
    480   1.1      eeh 	sc = (struct sbus_softc *) curdev;
    481   1.1      eeh 
    482   1.1      eeh 	sd->sd_dev = dev;
    483   1.1      eeh 	sd->sd_bchain = sc->sc_sbdev;
    484   1.1      eeh 	sc->sc_sbdev = sd;
    485   1.1      eeh }
    486   1.1      eeh 
    487   1.1      eeh /*
    488  1.33      mrg  * Reset the given sbus.
    489   1.1      eeh  */
    490   1.1      eeh void
    491   1.1      eeh sbusreset(sbus)
    492   1.1      eeh 	int sbus;
    493   1.1      eeh {
    494   1.1      eeh 	register struct sbusdev *sd;
    495   1.1      eeh 	struct sbus_softc *sc = sbus_cd.cd_devs[sbus];
    496   1.1      eeh 	struct device *dev;
    497   1.1      eeh 
    498   1.1      eeh 	printf("reset %s:", sc->sc_dev.dv_xname);
    499   1.1      eeh 	for (sd = sc->sc_sbdev; sd != NULL; sd = sd->sd_bchain) {
    500   1.1      eeh 		if (sd->sd_reset) {
    501   1.1      eeh 			dev = sd->sd_dev;
    502   1.1      eeh 			(*sd->sd_reset)(dev);
    503   1.1      eeh 			printf(" %s", dev->dv_xname);
    504   1.1      eeh 		}
    505   1.1      eeh 	}
    506   1.1      eeh 	/* Reload iommu regs */
    507  1.17      mrg 	iommu_reset(&sc->sc_is);
    508  1.40      eeh }
    509  1.40      eeh 
    510  1.40      eeh /*
    511  1.40      eeh  * Handle an overtemp situation.
    512  1.41  hubertf  *
    513  1.41  hubertf  * SPARCs have temperature sensors which generate interrupts
    514  1.41  hubertf  * if the machine's temperature exceeds a certain threshold.
    515  1.41  hubertf  * This handles the interrupt and powers off the machine.
    516  1.41  hubertf  * The same needs to be done to PCI controller drivers.
    517  1.40      eeh  */
    518  1.40      eeh int
    519  1.40      eeh sbus_overtemp(arg)
    520  1.40      eeh 	void *arg;
    521  1.40      eeh {
    522  1.40      eeh 	/* Should try a clean shutdown first */
    523  1.41  hubertf 	printf("DANGER: OVER TEMPERATURE detected\nShutting down...\n");
    524  1.40      eeh 	delay(20);
    525  1.40      eeh 	cpu_reboot(RB_POWERDOWN|RB_HALT, NULL);
    526   1.1      eeh }
    527   1.1      eeh 
    528   1.1      eeh /*
    529   1.1      eeh  * Get interrupt attributes for an Sbus device.
    530   1.1      eeh  */
    531   1.1      eeh int
    532  1.22      mrg sbus_get_intr(sc, node, ipp, np, slot)
    533   1.1      eeh 	struct sbus_softc *sc;
    534   1.1      eeh 	int node;
    535  1.51  thorpej 	struct openprom_intr **ipp;
    536   1.3      eeh 	int *np;
    537  1.22      mrg 	int slot;
    538   1.1      eeh {
    539   1.1      eeh 	int *ipl;
    540  1.22      mrg 	int n, i;
    541   1.1      eeh 	char buf[32];
    542   1.1      eeh 
    543   1.1      eeh 	/*
    544   1.1      eeh 	 * The `interrupts' property contains the Sbus interrupt level.
    545   1.1      eeh 	 */
    546   1.1      eeh 	ipl = NULL;
    547  1.45      eeh 	if (PROM_getprop(node, "interrupts", sizeof(int), np, (void **)&ipl) == 0) {
    548  1.51  thorpej 		struct openprom_intr *ip;
    549  1.22      mrg 		int pri;
    550  1.22      mrg 
    551  1.10      eeh 		/* Default to interrupt level 2 -- otherwise unused */
    552  1.22      mrg 		pri = INTLEVENCODE(2);
    553  1.22      mrg 
    554  1.22      mrg 		/* Change format to an `struct sbus_intr' array */
    555  1.51  thorpej 		ip = malloc(*np * sizeof(struct openprom_intr), M_DEVBUF,
    556  1.51  thorpej 		    M_NOWAIT);
    557   1.3      eeh 		if (ip == NULL)
    558   1.3      eeh 			return (ENOMEM);
    559  1.22      mrg 
    560  1.22      mrg 		/*
    561  1.22      mrg 		 * Now things get ugly.  We need to take this value which is
    562   1.1      eeh 		 * the interrupt vector number and encode the IPL into it
    563   1.1      eeh 		 * somehow. Luckily, the interrupt vector has lots of free
    564  1.22      mrg 		 * space and we can easily stuff the IPL in there for a while.
    565   1.1      eeh 		 */
    566  1.45      eeh 		PROM_getpropstringA(node, "device_type", buf);
    567  1.22      mrg 		if (!buf[0])
    568  1.45      eeh 			PROM_getpropstringA(node, "name", buf);
    569  1.22      mrg 
    570  1.22      mrg 		for (i = 0; intrmap[i].in_class; i++)
    571   1.3      eeh 			if (strcmp(intrmap[i].in_class, buf) == 0) {
    572   1.3      eeh 				pri = INTLEVENCODE(intrmap[i].in_lev);
    573   1.1      eeh 				break;
    574   1.1      eeh 			}
    575  1.22      mrg 
    576  1.22      mrg 		/*
    577  1.22      mrg 		 * Sbus card devices need the slot number encoded into
    578  1.22      mrg 		 * the vector as this is generally not done.
    579  1.22      mrg 		 */
    580  1.22      mrg 		if ((ipl[0] & INTMAP_OBIO) == 0)
    581  1.22      mrg 			pri |= slot << 3;
    582  1.22      mrg 
    583   1.3      eeh 		for (n = 0; n < *np; n++) {
    584   1.3      eeh 			/*
    585   1.3      eeh 			 * We encode vector and priority into sbi_pri so we
    586   1.3      eeh 			 * can pass them as a unit.  This will go away if
    587   1.3      eeh 			 * sbus_establish ever takes an sbus_intr instead
    588   1.3      eeh 			 * of an integer level.
    589   1.3      eeh 			 * Stuff the real vector in sbi_vec.
    590   1.3      eeh 			 */
    591  1.22      mrg 
    592  1.51  thorpej 			ip[n].oi_pri = pri|ipl[n];
    593  1.51  thorpej 			ip[n].oi_vec = ipl[n];
    594   1.3      eeh 		}
    595   1.1      eeh 		free(ipl, M_DEVBUF);
    596   1.3      eeh 		*ipp = ip;
    597   1.1      eeh 	}
    598   1.1      eeh 
    599  1.22      mrg 	return (0);
    600   1.1      eeh }
    601   1.1      eeh 
    602   1.1      eeh 
    603   1.1      eeh /*
    604   1.1      eeh  * Install an interrupt handler for an Sbus device.
    605   1.1      eeh  */
    606   1.1      eeh void *
    607  1.35       pk sbus_intr_establish(t, pri, level, flags, handler, arg)
    608   1.1      eeh 	bus_space_tag_t t;
    609  1.35       pk 	int pri;
    610   1.1      eeh 	int level;
    611   1.1      eeh 	int flags;
    612   1.1      eeh 	int (*handler) __P((void *));
    613   1.1      eeh 	void *arg;
    614   1.1      eeh {
    615   1.1      eeh 	struct sbus_softc *sc = t->cookie;
    616   1.1      eeh 	struct intrhand *ih;
    617   1.1      eeh 	int ipl;
    618  1.35       pk 	long vec = pri;
    619   1.1      eeh 
    620   1.1      eeh 	ih = (struct intrhand *)
    621   1.1      eeh 		malloc(sizeof(struct intrhand), M_DEVBUF, M_NOWAIT);
    622   1.1      eeh 	if (ih == NULL)
    623   1.1      eeh 		return (NULL);
    624   1.1      eeh 
    625   1.1      eeh 	if ((flags & BUS_INTR_ESTABLISH_SOFTINTR) != 0)
    626   1.8      eeh 		ipl = vec;
    627   1.8      eeh 	else if ((vec & SBUS_INTR_COMPAT) != 0)
    628   1.8      eeh 		ipl = vec & ~SBUS_INTR_COMPAT;
    629   1.1      eeh 	else {
    630   1.1      eeh 		/* Decode and remove IPL */
    631   1.8      eeh 		ipl = INTLEV(vec);
    632   1.8      eeh 		vec = INTVEC(vec);
    633  1.27      mrg 		DPRINTF(SDB_INTR,
    634  1.27      mrg 		    ("\nsbus: intr[%ld]%lx: %lx\nHunting for IRQ...\n",
    635  1.39      mrg 		    (long)ipl, (long)vec, (u_long)intrlev[vec]));
    636   1.8      eeh 		if ((vec & INTMAP_OBIO) == 0) {
    637   1.1      eeh 			/* We're in an SBUS slot */
    638   1.1      eeh 			/* Register the map and clear intr registers */
    639  1.22      mrg 
    640  1.35       pk 			int slot = INTSLOT(pri);
    641  1.22      mrg 
    642  1.22      mrg 			ih->ih_map = &(&sc->sc_sysio->sbus_slot0_int)[slot];
    643  1.22      mrg 			ih->ih_clr = &sc->sc_sysio->sbus0_clr_int[vec];
    644   1.1      eeh #ifdef DEBUG
    645  1.27      mrg 			if (sbus_debug & SDB_INTR) {
    646  1.22      mrg 				int64_t intrmap = *ih->ih_map;
    647   1.1      eeh 
    648  1.36      mrg 				printf("SBUS %lx IRQ as %llx in slot %d\n",
    649  1.22      mrg 				       (long)vec, (long long)intrmap, slot);
    650  1.36      mrg 				printf("\tmap addr %p clr addr %p\n",
    651  1.36      mrg 				    ih->ih_map, ih->ih_clr);
    652   1.1      eeh 			}
    653   1.1      eeh #endif
    654   1.1      eeh 			/* Enable the interrupt */
    655   1.8      eeh 			vec |= INTMAP_V;
    656   1.9      eeh 			/* Insert IGN */
    657   1.9      eeh 			vec |= sc->sc_ign;
    658  1.48      eeh 			/* XXXX */
    659  1.48      eeh 			*(ih->ih_map) = vec;
    660   1.1      eeh 		} else {
    661   1.1      eeh 			int64_t *intrptr = &sc->sc_sysio->scsi_int_map;
    662   1.1      eeh 			int64_t intrmap = 0;
    663   1.1      eeh 			int i;
    664   1.1      eeh 
    665   1.1      eeh 			/* Insert IGN */
    666   1.8      eeh 			vec |= sc->sc_ign;
    667  1.22      mrg 			for (i = 0; &intrptr[i] <=
    668  1.22      mrg 			    (int64_t *)&sc->sc_sysio->reserved_int_map &&
    669  1.22      mrg 			    INTVEC(intrmap = intrptr[i]) != INTVEC(vec); i++)
    670  1.22      mrg 				;
    671   1.8      eeh 			if (INTVEC(intrmap) == INTVEC(vec)) {
    672  1.27      mrg 				DPRINTF(SDB_INTR,
    673  1.36      mrg 				    ("OBIO %lx IRQ as %lx in slot %d\n",
    674  1.27      mrg 				    vec, (long)intrmap, i));
    675   1.1      eeh 				/* Register the map and clear intr registers */
    676   1.1      eeh 				ih->ih_map = &intrptr[i];
    677   1.1      eeh 				intrptr = (int64_t *)&sc->sc_sysio->scsi_clr_int;
    678   1.1      eeh 				ih->ih_clr = &intrptr[i];
    679   1.1      eeh 				/* Enable the interrupt */
    680   1.1      eeh 				intrmap |= INTMAP_V;
    681  1.48      eeh 				/* XXXX */
    682  1.48      eeh 				*(ih->ih_map) = intrmap;
    683  1.27      mrg 			} else
    684  1.27      mrg 				panic("IRQ not found!");
    685   1.1      eeh 		}
    686   1.1      eeh 	}
    687   1.1      eeh #ifdef DEBUG
    688  1.27      mrg 	if (sbus_debug & SDB_INTR) { long i; for (i = 0; i < 400000000; i++); }
    689   1.1      eeh #endif
    690   1.1      eeh 
    691   1.1      eeh 	ih->ih_fun = handler;
    692   1.1      eeh 	ih->ih_arg = arg;
    693   1.8      eeh 	ih->ih_number = vec;
    694   1.1      eeh 	ih->ih_pil = (1<<ipl);
    695  1.18      eeh 	intr_establish(ipl, ih);
    696   1.1      eeh 	return (ih);
    697   1.1      eeh }
    698   1.1      eeh 
    699   1.1      eeh static bus_space_tag_t
    700   1.1      eeh sbus_alloc_bustag(sc)
    701   1.1      eeh 	struct sbus_softc *sc;
    702   1.1      eeh {
    703   1.1      eeh 	bus_space_tag_t sbt;
    704   1.1      eeh 
    705   1.1      eeh 	sbt = (bus_space_tag_t)
    706   1.1      eeh 		malloc(sizeof(struct sparc_bus_space_tag), M_DEVBUF, M_NOWAIT);
    707   1.1      eeh 	if (sbt == NULL)
    708   1.1      eeh 		return (NULL);
    709   1.1      eeh 
    710   1.1      eeh 	bzero(sbt, sizeof *sbt);
    711   1.1      eeh 	sbt->cookie = sc;
    712   1.1      eeh 	sbt->parent = sc->sc_bustag;
    713  1.12      eeh 	sbt->type = SBUS_BUS_SPACE;
    714   1.1      eeh 	sbt->sparc_bus_map = _sbus_bus_map;
    715  1.44      eeh 	sbt->sparc_bus_mmap = sc->sc_bustag->sparc_bus_mmap;
    716   1.1      eeh 	sbt->sparc_intr_establish = sbus_intr_establish;
    717   1.1      eeh 	return (sbt);
    718   1.1      eeh }
    719   1.1      eeh 
    720   1.1      eeh 
    721   1.1      eeh static bus_dma_tag_t
    722   1.1      eeh sbus_alloc_dmatag(sc)
    723   1.1      eeh 	struct sbus_softc *sc;
    724   1.1      eeh {
    725   1.1      eeh 	bus_dma_tag_t sdt, psdt = sc->sc_dmatag;
    726   1.1      eeh 
    727   1.1      eeh 	sdt = (bus_dma_tag_t)
    728   1.1      eeh 		malloc(sizeof(struct sparc_bus_dma_tag), M_DEVBUF, M_NOWAIT);
    729   1.1      eeh 	if (sdt == NULL)
    730   1.1      eeh 		/* Panic? */
    731   1.1      eeh 		return (psdt);
    732   1.1      eeh 
    733   1.1      eeh 	sdt->_cookie = sc;
    734   1.1      eeh 	sdt->_parent = psdt;
    735   1.1      eeh #define PCOPY(x)	sdt->x = psdt->x
    736   1.1      eeh 	PCOPY(_dmamap_create);
    737   1.1      eeh 	PCOPY(_dmamap_destroy);
    738   1.1      eeh 	sdt->_dmamap_load = sbus_dmamap_load;
    739   1.1      eeh 	PCOPY(_dmamap_load_mbuf);
    740   1.1      eeh 	PCOPY(_dmamap_load_uio);
    741  1.29      eeh 	sdt->_dmamap_load_raw = sbus_dmamap_load_raw;
    742   1.1      eeh 	sdt->_dmamap_unload = sbus_dmamap_unload;
    743   1.1      eeh 	sdt->_dmamap_sync = sbus_dmamap_sync;
    744   1.1      eeh 	sdt->_dmamem_alloc = sbus_dmamem_alloc;
    745   1.1      eeh 	sdt->_dmamem_free = sbus_dmamem_free;
    746   1.2      eeh 	sdt->_dmamem_map = sbus_dmamem_map;
    747   1.2      eeh 	sdt->_dmamem_unmap = sbus_dmamem_unmap;
    748   1.1      eeh 	PCOPY(_dmamem_mmap);
    749   1.1      eeh #undef	PCOPY
    750   1.1      eeh 	sc->sc_dmatag = sdt;
    751   1.1      eeh 	return (sdt);
    752   1.1      eeh }
    753   1.1      eeh 
    754   1.1      eeh int
    755  1.28      mrg sbus_dmamap_load(tag, map, buf, buflen, p, flags)
    756  1.28      mrg 	bus_dma_tag_t tag;
    757   1.1      eeh 	bus_dmamap_t map;
    758   1.1      eeh 	void *buf;
    759   1.1      eeh 	bus_size_t buflen;
    760   1.1      eeh 	struct proc *p;
    761   1.1      eeh 	int flags;
    762   1.1      eeh {
    763  1.28      mrg 	struct sbus_softc *sc = (struct sbus_softc *)tag->_cookie;
    764   1.1      eeh 
    765  1.50      eeh 	return (iommu_dvmamap_load(tag, &sc->sc_sb, map, buf, buflen, p, flags));
    766  1.29      eeh }
    767  1.29      eeh 
    768  1.29      eeh int
    769  1.29      eeh sbus_dmamap_load_raw(tag, map, segs, nsegs, size, flags)
    770  1.29      eeh 	bus_dma_tag_t tag;
    771  1.29      eeh 	bus_dmamap_t map;
    772  1.29      eeh 	bus_dma_segment_t *segs;
    773  1.29      eeh 	int nsegs;
    774  1.29      eeh 	bus_size_t size;
    775  1.29      eeh 	int flags;
    776  1.29      eeh {
    777  1.29      eeh 	struct sbus_softc *sc = (struct sbus_softc *)tag->_cookie;
    778  1.29      eeh 
    779  1.50      eeh 	return (iommu_dvmamap_load_raw(tag, &sc->sc_sb, map, segs, nsegs, flags, size));
    780   1.1      eeh }
    781   1.1      eeh 
    782   1.1      eeh void
    783  1.28      mrg sbus_dmamap_unload(tag, map)
    784  1.28      mrg 	bus_dma_tag_t tag;
    785   1.1      eeh 	bus_dmamap_t map;
    786   1.1      eeh {
    787  1.28      mrg 	struct sbus_softc *sc = (struct sbus_softc *)tag->_cookie;
    788  1.12      eeh 
    789  1.50      eeh 	iommu_dvmamap_unload(tag, &sc->sc_sb, map);
    790   1.1      eeh }
    791   1.1      eeh 
    792   1.1      eeh void
    793  1.28      mrg sbus_dmamap_sync(tag, map, offset, len, ops)
    794  1.28      mrg 	bus_dma_tag_t tag;
    795   1.1      eeh 	bus_dmamap_t map;
    796   1.1      eeh 	bus_addr_t offset;
    797   1.1      eeh 	bus_size_t len;
    798   1.1      eeh 	int ops;
    799   1.1      eeh {
    800  1.28      mrg 	struct sbus_softc *sc = (struct sbus_softc *)tag->_cookie;
    801   1.1      eeh 
    802  1.30      eeh 	if (ops & (BUS_DMASYNC_PREREAD|BUS_DMASYNC_PREWRITE)) {
    803  1.30      eeh 		/* Flush the CPU then the IOMMU */
    804  1.30      eeh 		bus_dmamap_sync(tag->_parent, map, offset, len, ops);
    805  1.50      eeh 		iommu_dvmamap_sync(tag, &sc->sc_sb, map, offset, len, ops);
    806  1.30      eeh 	}
    807  1.30      eeh 	if (ops & (BUS_DMASYNC_POSTREAD|BUS_DMASYNC_POSTWRITE)) {
    808  1.30      eeh 		/* Flush the IOMMU then the CPU */
    809  1.50      eeh 		iommu_dvmamap_sync(tag, &sc->sc_sb, map, offset, len, ops);
    810  1.30      eeh 		bus_dmamap_sync(tag->_parent, map, offset, len, ops);
    811  1.30      eeh 	}
    812   1.1      eeh }
    813   1.1      eeh 
    814   1.1      eeh int
    815  1.28      mrg sbus_dmamem_alloc(tag, size, alignment, boundary, segs, nsegs, rsegs, flags)
    816  1.28      mrg 	bus_dma_tag_t tag;
    817  1.28      mrg 	bus_size_t size;
    818  1.28      mrg 	bus_size_t alignment;
    819  1.28      mrg 	bus_size_t boundary;
    820   1.1      eeh 	bus_dma_segment_t *segs;
    821   1.1      eeh 	int nsegs;
    822   1.1      eeh 	int *rsegs;
    823   1.1      eeh 	int flags;
    824   1.1      eeh {
    825  1.28      mrg 	struct sbus_softc *sc = (struct sbus_softc *)tag->_cookie;
    826   1.1      eeh 
    827  1.50      eeh 	return (iommu_dvmamem_alloc(tag, &sc->sc_sb, size, alignment, boundary,
    828  1.28      mrg 	    segs, nsegs, rsegs, flags));
    829   1.1      eeh }
    830   1.1      eeh 
    831   1.1      eeh void
    832  1.28      mrg sbus_dmamem_free(tag, segs, nsegs)
    833  1.28      mrg 	bus_dma_tag_t tag;
    834   1.1      eeh 	bus_dma_segment_t *segs;
    835   1.1      eeh 	int nsegs;
    836   1.1      eeh {
    837  1.28      mrg 	struct sbus_softc *sc = (struct sbus_softc *)tag->_cookie;
    838   1.1      eeh 
    839  1.50      eeh 	iommu_dvmamem_free(tag, &sc->sc_sb, segs, nsegs);
    840   1.1      eeh }
    841   1.1      eeh 
    842   1.2      eeh int
    843  1.28      mrg sbus_dmamem_map(tag, segs, nsegs, size, kvap, flags)
    844  1.28      mrg 	bus_dma_tag_t tag;
    845   1.2      eeh 	bus_dma_segment_t *segs;
    846   1.2      eeh 	int nsegs;
    847   1.2      eeh 	size_t size;
    848   1.2      eeh 	caddr_t *kvap;
    849   1.2      eeh 	int flags;
    850   1.2      eeh {
    851  1.28      mrg 	struct sbus_softc *sc = (struct sbus_softc *)tag->_cookie;
    852   1.2      eeh 
    853  1.50      eeh 	return (iommu_dvmamem_map(tag, &sc->sc_sb, segs, nsegs, size, kvap, flags));
    854   1.2      eeh }
    855   1.2      eeh 
    856   1.2      eeh void
    857  1.28      mrg sbus_dmamem_unmap(tag, kva, size)
    858  1.28      mrg 	bus_dma_tag_t tag;
    859   1.2      eeh 	caddr_t kva;
    860   1.2      eeh 	size_t size;
    861   1.2      eeh {
    862  1.28      mrg 	struct sbus_softc *sc = (struct sbus_softc *)tag->_cookie;
    863  1.28      mrg 
    864  1.50      eeh 	iommu_dvmamem_unmap(tag, &sc->sc_sb, kva, size);
    865   1.2      eeh }
    866