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