Home | History | Annotate | Line # | Download | only in dev
obio.c revision 1.32
      1  1.32        pk /*	$NetBSD: obio.c,v 1.32 1997/05/18 19:37:37 pk Exp $	*/
      2   1.1   deraadt 
      3   1.1   deraadt /*
      4   1.1   deraadt  * Copyright (c) 1993, 1994 Theo de Raadt
      5  1.22        pk  * Copyright (c) 1995 Paul Kranenburg
      6   1.1   deraadt  * All rights reserved.
      7   1.1   deraadt  *
      8   1.1   deraadt  * Redistribution and use in source and binary forms, with or without
      9   1.1   deraadt  * modification, are permitted provided that the following conditions
     10   1.1   deraadt  * are met:
     11   1.1   deraadt  * 1. Redistributions of source code must retain the above copyright
     12   1.1   deraadt  *    notice, this list of conditions and the following disclaimer.
     13   1.1   deraadt  * 2. Redistributions in binary form must reproduce the above copyright
     14   1.1   deraadt  *    notice, this list of conditions and the following disclaimer in the
     15   1.1   deraadt  *    documentation and/or other materials provided with the distribution.
     16   1.1   deraadt  * 3. All advertising materials mentioning features or use of this software
     17   1.1   deraadt  *    must display the following acknowledgement:
     18   1.1   deraadt  *	This product includes software developed by Theo de Raadt.
     19   1.1   deraadt  * 4. The name of the author may not be used to endorse or promote products
     20   1.1   deraadt  *    derived from this software without specific prior written permission.
     21   1.1   deraadt  *
     22   1.1   deraadt  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     23   1.1   deraadt  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     24   1.1   deraadt  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     25   1.1   deraadt  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     26   1.1   deraadt  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     27   1.1   deraadt  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     28   1.1   deraadt  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     29   1.1   deraadt  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     30   1.1   deraadt  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     31   1.1   deraadt  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     32   1.1   deraadt  */
     33   1.1   deraadt 
     34   1.1   deraadt #include <sys/param.h>
     35  1.20  christos #include <sys/systm.h>
     36   1.1   deraadt #include <sys/device.h>
     37   1.1   deraadt #include <sys/malloc.h>
     38   1.1   deraadt 
     39   1.1   deraadt #ifdef DEBUG
     40   1.1   deraadt #include <sys/proc.h>
     41   1.1   deraadt #include <sys/syslog.h>
     42   1.1   deraadt #endif
     43   1.1   deraadt 
     44   1.1   deraadt #include <vm/vm.h>
     45   1.1   deraadt 
     46   1.1   deraadt #include <machine/autoconf.h>
     47   1.1   deraadt #include <machine/pmap.h>
     48   1.2   deraadt #include <machine/oldmon.h>
     49   1.5   deraadt #include <machine/cpu.h>
     50   1.2   deraadt #include <machine/ctlreg.h>
     51   1.2   deraadt #include <sparc/sparc/asm.h>
     52   1.2   deraadt #include <sparc/sparc/vaddrs.h>
     53  1.30        pk #include <sparc/sparc/cpuvar.h>
     54  1.22        pk #include <sparc/dev/sbusvar.h>
     55  1.32        pk #include <sparc/dev/vmereg.h>
     56  1.32        pk 
     57  1.32        pk struct vmebus_softc {
     58  1.32        pk 	struct device	 sc_dev;	/* base device */
     59  1.32        pk 	struct vmebusreg *sc_reg; 	/* VME control registers */
     60  1.32        pk 	struct vmebusvec *sc_vec;	/* VME interrupt vector */
     61  1.32        pk 	struct rom_range *sc_range;	/* ROM range property */
     62  1.32        pk 	int		 sc_nrange;
     63  1.32        pk };
     64  1.32        pk struct  vmebus_softc *vmebus_sc;/*XXX*/
     65   1.1   deraadt 
     66   1.4   deraadt struct bus_softc {
     67  1.22        pk 	union {
     68  1.22        pk 		struct	device scu_dev;		/* base device */
     69  1.22        pk 		struct	sbus_softc scu_sbus;	/* obio is another sbus slot */
     70  1.32        pk 		struct	vmebus_softc scu_vme;
     71  1.22        pk 	} bu;
     72   1.1   deraadt };
     73   1.1   deraadt 
     74  1.32        pk 
     75   1.1   deraadt /* autoconfiguration driver */
     76  1.28        pk static int	busmatch __P((struct device *, struct cfdata *, void *));
     77   1.9   deraadt static void	obioattach __P((struct device *, struct device *, void *));
     78   1.9   deraadt static void	vmesattach __P((struct device *, struct device *, void *));
     79   1.9   deraadt static void	vmelattach __P((struct device *, struct device *, void *));
     80  1.32        pk static void	vmeattach __P((struct device *, struct device *, void *));
     81  1.22        pk 
     82  1.25       cgd int		busprint __P((void *, const char *));
     83  1.32        pk int		vmeprint __P((void *, const char *));
     84  1.28        pk static int	busattach __P((struct device *, struct cfdata *, void *, int));
     85  1.17        pk void *		bus_map __P((struct rom_reg *, int, int));
     86  1.28        pk int		obio_scan __P((struct device *, struct cfdata *, void *));
     87  1.28        pk int 		vmes_scan __P((struct device *, struct cfdata *, void *));
     88  1.28        pk int 		vmel_scan __P((struct device *, struct cfdata *, void *));
     89  1.20  christos int 		vmeintr __P((void *));
     90   1.4   deraadt 
     91  1.21   thorpej struct cfattach obio_ca = {
     92  1.21   thorpej 	sizeof(struct bus_softc), busmatch, obioattach
     93   1.4   deraadt };
     94  1.21   thorpej 
     95  1.21   thorpej struct cfdriver obio_cd = {
     96  1.21   thorpej 	NULL, "obio", DV_DULL
     97  1.21   thorpej };
     98  1.21   thorpej 
     99  1.21   thorpej struct cfattach vmel_ca = {
    100  1.21   thorpej 	sizeof(struct bus_softc), busmatch, vmelattach
    101  1.21   thorpej };
    102  1.21   thorpej 
    103  1.21   thorpej struct cfdriver vmel_cd = {
    104  1.21   thorpej 	NULL, "vmel", DV_DULL
    105  1.21   thorpej };
    106  1.21   thorpej 
    107  1.21   thorpej struct cfattach vmes_ca = {
    108  1.21   thorpej 	sizeof(struct bus_softc), busmatch, vmesattach
    109   1.1   deraadt };
    110  1.21   thorpej 
    111  1.21   thorpej struct cfdriver vmes_cd = {
    112  1.21   thorpej 	NULL, "vmes", DV_DULL
    113   1.4   deraadt };
    114  1.22        pk 
    115  1.32        pk struct cfattach vme_ca = {
    116  1.32        pk 	sizeof(struct bus_softc), busmatch, vmeattach
    117  1.32        pk };
    118  1.32        pk 
    119  1.32        pk struct cfdriver vme_cd = {
    120  1.32        pk 	NULL, "vme", DV_DULL
    121  1.32        pk };
    122  1.32        pk 
    123  1.22        pk struct intrhand **vmeints;
    124   1.4   deraadt 
    125   1.2   deraadt 
    126   1.1   deraadt int
    127  1.28        pk busmatch(parent, cf, aux)
    128   1.1   deraadt 	struct device *parent;
    129  1.28        pk 	struct cfdata *cf;
    130  1.28        pk 	void *aux;
    131   1.1   deraadt {
    132   1.3   deraadt 	register struct confargs *ca = aux;
    133   1.3   deraadt 	register struct romaux *ra = &ca->ca_ra;
    134   1.3   deraadt 
    135  1.22        pk 	if (CPU_ISSUN4M)
    136  1.22        pk 		return (strcmp(cf->cf_driver->cd_name, ra->ra_name) == 0);
    137  1.22        pk 
    138  1.22        pk 	if (!CPU_ISSUN4)
    139   1.3   deraadt 		return (0);
    140  1.22        pk 
    141   1.3   deraadt 	return (strcmp(cf->cf_driver->cd_name, ra->ra_name) == 0);
    142   1.1   deraadt }
    143   1.1   deraadt 
    144   1.1   deraadt int
    145   1.4   deraadt busprint(args, obio)
    146   1.1   deraadt 	void *args;
    147  1.25       cgd 	const char *obio;
    148   1.1   deraadt {
    149   1.2   deraadt 	register struct confargs *ca = args;
    150   1.2   deraadt 
    151   1.2   deraadt 	if (ca->ca_ra.ra_name == NULL)
    152   1.2   deraadt 		ca->ca_ra.ra_name = "<unknown>";
    153  1.22        pk 
    154   1.2   deraadt 	if (obio)
    155  1.27  christos 		printf("[%s at %s]", ca->ca_ra.ra_name, obio);
    156  1.22        pk 
    157  1.27  christos 	printf(" addr %p", ca->ca_ra.ra_paddr);
    158  1.22        pk 
    159  1.22        pk 	if (CPU_ISSUN4 && ca->ca_ra.ra_intr[0].int_vec != -1)
    160  1.27  christos 		printf(" vec 0x%x", ca->ca_ra.ra_intr[0].int_vec);
    161  1.22        pk 
    162   1.1   deraadt 	return (UNCONF);
    163   1.1   deraadt }
    164   1.1   deraadt 
    165  1.32        pk int
    166  1.32        pk vmeprint(args, name)
    167  1.32        pk 	void *args;
    168  1.32        pk 	const char *name;
    169  1.32        pk {
    170  1.32        pk 	register struct confargs *ca = args;
    171  1.32        pk 
    172  1.32        pk 	if (name)
    173  1.32        pk 		printf("%s at %s", ca->ca_ra.ra_name, name);
    174  1.32        pk 	return (UNCONF);
    175  1.32        pk }
    176  1.14        pk 
    177  1.22        pk void
    178  1.22        pk obioattach(parent, self, args)
    179  1.22        pk 	struct device *parent, *self;
    180  1.22        pk 	void *args;
    181  1.22        pk {
    182  1.22        pk #if defined(SUN4M)
    183  1.22        pk 	register struct bus_softc *sc = (struct bus_softc *)self;
    184  1.22        pk 	struct confargs oca, *ca = args;
    185  1.22        pk 	register struct romaux *ra = &ca->ca_ra;
    186  1.22        pk 	register int node0, node;
    187  1.22        pk 	register char *name;
    188  1.22        pk 	register const char *sp;
    189  1.22        pk 	const char *const *ssp;
    190  1.31        pk 	int rlen;
    191  1.22        pk 	extern int autoconf_nzs;
    192  1.22        pk 
    193  1.22        pk 	static const char *const special4m[] = {
    194  1.22        pk 		/* find these first */
    195  1.22        pk 		"eeprom",
    196  1.22        pk 		"counter",
    197  1.29        pk #if 0 /* Not all sun4m's have an `auxio' */
    198  1.22        pk 		"auxio",
    199  1.29        pk #endif
    200  1.22        pk 		"",
    201  1.22        pk 		/* place device to ignore here */
    202  1.22        pk 		"interrupt",
    203  1.22        pk 		NULL
    204  1.22        pk 	};
    205  1.22        pk #endif
    206  1.22        pk 
    207  1.22        pk 	if (CPU_ISSUN4) {
    208  1.22        pk 		if (self->dv_unit > 0) {
    209  1.27  christos 			printf(" unsupported\n");
    210  1.22        pk 			return;
    211  1.22        pk 		}
    212  1.27  christos 		printf("\n");
    213  1.22        pk 
    214  1.22        pk 		(void)config_search(obio_scan, self, args);
    215  1.22        pk 		bus_untmp();
    216  1.22        pk 	}
    217  1.22        pk 
    218  1.22        pk #if defined(SUN4M)
    219  1.22        pk 	if (!CPU_ISSUN4M)
    220  1.22        pk 		return;
    221  1.22        pk 
    222  1.22        pk 	/*
    223  1.22        pk 	 * There is only one obio bus (it is in fact one of the Sbus slots)
    224  1.22        pk 	 * How about VME?
    225  1.22        pk 	 */
    226  1.32        pk 	if (self->dv_unit > 0) {
    227  1.27  christos 		printf(" unsupported\n");
    228  1.22        pk 		return;
    229  1.22        pk 	}
    230  1.22        pk 
    231  1.27  christos 	printf("\n");
    232  1.22        pk 
    233  1.22        pk 	if (ra->ra_bp != NULL && strcmp(ra->ra_bp->name, "obio") == 0)
    234  1.22        pk 		oca.ca_ra.ra_bp = ra->ra_bp + 1;
    235  1.22        pk 	else
    236  1.22        pk 		oca.ca_ra.ra_bp = NULL;
    237  1.22        pk 
    238  1.31        pk 	node = ra->ra_node;
    239  1.31        pk 	rlen = getproplen(node, "ranges");
    240  1.31        pk 	if (rlen > 0) {
    241  1.31        pk 		sc->bu.scu_sbus.sc_nrange = rlen / sizeof(struct rom_range);
    242  1.31        pk 		sc->bu.scu_sbus.sc_range =
    243  1.31        pk 			(struct rom_range *)malloc(rlen, M_DEVBUF, M_NOWAIT);
    244  1.31        pk 		if (sc->bu.scu_sbus.sc_range == 0)
    245  1.31        pk 			panic("obio: PROM ranges too large: %d", rlen);
    246  1.31        pk 		(void)getprop(node, "ranges", sc->bu.scu_sbus.sc_range, rlen);
    247  1.31        pk 	}
    248  1.22        pk 
    249  1.22        pk 	/*
    250  1.22        pk 	 * Loop through ROM children, fixing any relative addresses
    251  1.22        pk 	 * and then configuring each device.
    252  1.22        pk 	 * We first do the crucial ones, such as eeprom, etc.
    253  1.22        pk 	 */
    254  1.22        pk 	node0 = firstchild(ra->ra_node);
    255  1.22        pk 	for (ssp = special4m ; *(sp = *ssp) != 0; ssp++) {
    256  1.22        pk 		if ((node = findnode(node0, sp)) == 0) {
    257  1.27  christos 			printf("could not find %s amongst obio devices\n", sp);
    258  1.22        pk 			panic(sp);
    259  1.22        pk 		}
    260  1.22        pk 		if (!romprop(&oca.ca_ra, sp, node))
    261  1.22        pk 			continue;
    262  1.22        pk 
    263  1.22        pk 		sbus_translate(self, &oca);
    264  1.22        pk 		oca.ca_bustype = BUS_OBIO;
    265  1.32        pk 		(void) config_found(self, (void *)&oca, busprint);
    266  1.22        pk 	}
    267  1.22        pk 
    268  1.22        pk 	for (node = node0; node; node = nextsibling(node)) {
    269  1.22        pk 		name = getpropstring(node, "name");
    270  1.22        pk 		for (ssp = special4m ; (sp = *ssp) != NULL; ssp++)
    271  1.22        pk 			if (strcmp(name, sp) == 0)
    272  1.22        pk 				break;
    273  1.22        pk 
    274  1.22        pk 		if (sp != NULL || !romprop(&oca.ca_ra, name, node))
    275  1.22        pk 			continue;
    276  1.22        pk 
    277  1.22        pk 		if (strcmp(name, "zs") == 0)
    278  1.22        pk 			/* XXX - see autoconf.c for this hack */
    279  1.22        pk 			autoconf_nzs++;
    280  1.22        pk 
    281  1.22        pk 		/* Translate into parent address spaces */
    282  1.22        pk 		sbus_translate(self, &oca);
    283  1.22        pk 		oca.ca_bustype = BUS_OBIO;
    284  1.32        pk 		(void) config_found(self, (void *)&oca, busprint);
    285  1.22        pk 	}
    286  1.22        pk #endif
    287  1.22        pk }
    288  1.22        pk 
    289  1.22        pk void
    290  1.22        pk vmesattach(parent, self, args)
    291  1.22        pk 	struct device *parent, *self;
    292  1.22        pk 	void *args;
    293  1.22        pk {
    294  1.32        pk 	if (self->dv_unit > 0 ||
    295  1.32        pk 	    (CPU_ISSUN4M && strncmp(parent->dv_xname, "vme", 3) != 0)) {
    296  1.27  christos 		printf(" unsupported\n");
    297  1.22        pk 		return;
    298  1.22        pk 	}
    299  1.27  christos 	printf("\n");
    300  1.22        pk 
    301  1.22        pk 	if (vmeints == NULL) {
    302  1.22        pk 		vmeints = (struct intrhand **)malloc(256 *
    303  1.22        pk 		    sizeof(struct intrhand *), M_TEMP, M_NOWAIT);
    304  1.22        pk 		bzero(vmeints, 256 * sizeof(struct intrhand *));
    305  1.22        pk 	}
    306  1.22        pk 	(void)config_search(vmes_scan, self, args);
    307  1.22        pk 	bus_untmp();
    308  1.22        pk }
    309  1.22        pk 
    310  1.22        pk void
    311  1.22        pk vmelattach(parent, self, args)
    312  1.22        pk 	struct device *parent, *self;
    313  1.22        pk 	void *args;
    314  1.22        pk {
    315  1.32        pk 	if (self->dv_unit > 0 ||
    316  1.32        pk 	    (CPU_ISSUN4M && strncmp(parent->dv_xname, "vme", 3) != 0)) {
    317  1.27  christos 		printf(" unsupported\n");
    318  1.22        pk 		return;
    319  1.22        pk 	}
    320  1.27  christos 	printf("\n");
    321  1.22        pk 
    322  1.22        pk 	if (vmeints == NULL) {
    323  1.22        pk 		vmeints = (struct intrhand **)malloc(256 *
    324  1.22        pk 		    sizeof(struct intrhand *), M_TEMP, M_NOWAIT);
    325  1.22        pk 		bzero(vmeints, 256 * sizeof(struct intrhand *));
    326  1.22        pk 	}
    327  1.22        pk 	(void)config_search(vmel_scan, self, args);
    328  1.22        pk 	bus_untmp();
    329  1.22        pk }
    330  1.22        pk 
    331  1.32        pk void
    332  1.32        pk vmeattach(parent, self, aux)
    333  1.32        pk 	struct device *parent, *self;
    334  1.32        pk 	void *aux;
    335  1.32        pk {
    336  1.32        pk 	struct vmebus_softc *sc = (struct vmebus_softc *)self;
    337  1.32        pk 	struct confargs *ca = aux;
    338  1.32        pk 	register struct romaux *ra = &ca->ca_ra;
    339  1.32        pk 	int node, rlen;
    340  1.32        pk 	struct confargs oca;
    341  1.32        pk 
    342  1.32        pk 	if (!CPU_ISSUN4M || self->dv_unit > 0) {
    343  1.32        pk 		printf(" unsupported\n");
    344  1.32        pk 		return;
    345  1.32        pk 	}
    346  1.32        pk 
    347  1.32        pk 	node = ra->ra_node;
    348  1.32        pk 
    349  1.32        pk 	sc->sc_reg = (struct vmebusreg *)
    350  1.32        pk 		mapdev(&ra->ra_reg[0], 0, 0, ra->ra_reg[0].rr_len,
    351  1.32        pk 			ra->ra_reg[0].rr_iospace);
    352  1.32        pk 	sc->sc_vec = (struct vmebusvec *)
    353  1.32        pk 		mapdev(&ra->ra_reg[1], 0, 0, ra->ra_reg[1].rr_len,
    354  1.32        pk 			ra->ra_reg[1].rr_iospace);
    355  1.32        pk 
    356  1.32        pk 	/*
    357  1.32        pk 	 * Get "range" property, though we don't do anything with it yet.
    358  1.32        pk 	 */
    359  1.32        pk 	rlen = getproplen(node, "ranges");
    360  1.32        pk 	if (rlen > 0) {
    361  1.32        pk 		sc->sc_nrange = rlen / sizeof(struct rom_range);
    362  1.32        pk 		sc->sc_range =
    363  1.32        pk 			(struct rom_range *)malloc(rlen, M_DEVBUF, M_NOWAIT);
    364  1.32        pk 		if (sc->sc_range == 0)
    365  1.32        pk 			panic("vme: PROM ranges too large: %d", rlen);
    366  1.32        pk 		(void)getprop(node, "ranges", sc->sc_range, rlen);
    367  1.32        pk 	}
    368  1.32        pk 
    369  1.32        pk 	vmebus_sc = sc;
    370  1.32        pk 	printf(": version %x\n",
    371  1.32        pk 	       sc->sc_reg->vmebus_cr & VMEBUS_CR_IMPL);
    372  1.32        pk 
    373  1.32        pk 	if (ra->ra_bp != NULL && strcmp(ra->ra_bp->name, "vme") == 0)
    374  1.32        pk 		oca.ca_ra.ra_bp = ra->ra_bp + 1;
    375  1.32        pk 	else
    376  1.32        pk 		oca.ca_ra.ra_bp = NULL;
    377  1.32        pk 
    378  1.32        pk 	oca.ca_ra.ra_name = "vmes";
    379  1.32        pk 	oca.ca_bustype = BUS_MAIN;
    380  1.32        pk 	(void)config_found(self, (void *)&oca, vmeprint);
    381  1.32        pk 
    382  1.32        pk 	oca.ca_ra.ra_name = "vmel";
    383  1.32        pk 	oca.ca_bustype = BUS_MAIN;
    384  1.32        pk 	(void)config_found(self, (void *)&oca, vmeprint);
    385  1.32        pk }
    386  1.32        pk 
    387  1.14        pk int
    388  1.28        pk busattach(parent, cf, args, bustype)
    389  1.14        pk 	struct device *parent;
    390  1.28        pk 	struct cfdata *cf;
    391  1.28        pk 	void *args;
    392   1.4   deraadt 	int bustype;
    393   1.1   deraadt {
    394  1.32        pk #if defined(SUN4) || defined(SUN4M)
    395   1.3   deraadt 	register struct confargs *ca = args;
    396   1.3   deraadt 	struct confargs oca;
    397   1.4   deraadt 	caddr_t tmp;
    398   1.1   deraadt 
    399  1.22        pk 	if (bustype == BUS_OBIO && CPU_ISSUN4) {
    400  1.23     chuck 
    401  1.23     chuck 		/*
    402  1.23     chuck 		 * avoid sun4m entries which don't have valid PA's.
    403  1.23     chuck 		 * no point in even probing them.
    404  1.23     chuck 		 */
    405  1.23     chuck 		if (cf->cf_loc[0] == -1) return 0;
    406  1.23     chuck 
    407  1.14        pk 		/*
    408  1.14        pk 		 * On the 4/100 obio addresses must be mapped at
    409  1.14        pk 		 * 0x0YYYYYYY, but alias higher up (we avoid the
    410  1.14        pk 		 * alias condition because it causes pmap difficulties)
    411  1.14        pk 		 * XXX: We also assume that 4/[23]00 obio addresses
    412  1.14        pk 		 * must be 0xZYYYYYYY, where (Z != 0)
    413  1.14        pk 		 */
    414  1.30        pk 		if (cpuinfo.cpu_type == CPUTYP_4_100 &&
    415  1.30        pk 		    (cf->cf_loc[0] & 0xf0000000))
    416  1.14        pk 			return 0;
    417  1.30        pk 		if (cpuinfo.cpu_type != CPUTYP_4_100 &&
    418  1.30        pk 		    !(cf->cf_loc[0] & 0xf0000000))
    419  1.14        pk 			return 0;
    420  1.14        pk 	}
    421  1.14        pk 
    422  1.14        pk 	oca.ca_ra.ra_iospace = -1;
    423  1.14        pk 	oca.ca_ra.ra_paddr = (void *)cf->cf_loc[0];
    424  1.14        pk 	oca.ca_ra.ra_len = 0;
    425  1.14        pk 	oca.ca_ra.ra_nreg = 1;
    426  1.14        pk 	if (oca.ca_ra.ra_paddr)
    427  1.32        pk 		tmp = (caddr_t)bus_tmp(oca.ca_ra.ra_paddr, bustype);
    428  1.24       mrg 	else
    429  1.24       mrg 		tmp = NULL;
    430  1.14        pk 	oca.ca_ra.ra_vaddr = tmp;
    431  1.14        pk 	oca.ca_ra.ra_intr[0].int_pri = cf->cf_loc[1];
    432  1.14        pk 	if (bustype == BUS_VME16 || bustype == BUS_VME32)
    433  1.14        pk 		oca.ca_ra.ra_intr[0].int_vec = cf->cf_loc[2];
    434  1.14        pk 	else
    435  1.14        pk 		oca.ca_ra.ra_intr[0].int_vec = -1;
    436  1.14        pk 	oca.ca_ra.ra_nintr = 1;
    437  1.14        pk 	oca.ca_ra.ra_name = cf->cf_driver->cd_name;
    438  1.15        pk 	if (ca->ca_ra.ra_bp != NULL &&
    439  1.16        pk 	  ((bustype == BUS_VME16 && strcmp(ca->ca_ra.ra_bp->name,"vmes") ==0) ||
    440  1.16        pk 	   (bustype == BUS_VME32 && strcmp(ca->ca_ra.ra_bp->name,"vmel") ==0) ||
    441  1.16        pk 	   (bustype == BUS_OBIO && strcmp(ca->ca_ra.ra_bp->name,"obio") == 0)))
    442  1.15        pk 		oca.ca_ra.ra_bp = ca->ca_ra.ra_bp + 1;
    443  1.15        pk 	else
    444  1.15        pk 		oca.ca_ra.ra_bp = NULL;
    445  1.14        pk 	oca.ca_bustype = bustype;
    446  1.14        pk 
    447  1.21   thorpej 	if ((*cf->cf_attach->ca_match)(parent, cf, &oca) == 0)
    448  1.14        pk 		return 0;
    449  1.14        pk 
    450  1.14        pk 	/*
    451  1.22        pk 	 * check if XXmatch routine replaced the temporary mapping with
    452  1.19     chuck 	 * a real mapping.   If not, then make sure we don't pass the
    453  1.19     chuck 	 * tmp mapping to the attach routine.
    454  1.14        pk 	 */
    455  1.19     chuck 	if (oca.ca_ra.ra_vaddr == tmp)
    456  1.19     chuck 		oca.ca_ra.ra_vaddr = NULL; /* wipe out tmp address */
    457  1.14        pk 	/*
    458  1.22        pk 	 * the match routine will set "ra_len" if it wants us to
    459  1.19     chuck 	 * establish a mapping for it.
    460  1.14        pk 	 * (which won't be seen on future XXmatch calls,
    461  1.14        pk 	 * so not as useful as it seems.)
    462  1.14        pk 	 */
    463  1.22        pk 	if (oca.ca_ra.ra_len)
    464  1.14        pk 		oca.ca_ra.ra_vaddr =
    465  1.32        pk 		    bus_map(oca.ca_ra.ra_reg, oca.ca_ra.ra_len, oca.ca_bustype);
    466  1.14        pk 
    467  1.14        pk 	config_attach(parent, cf, &oca, busprint);
    468  1.14        pk 	return 1;
    469  1.22        pk #else
    470  1.22        pk 	return 0;
    471  1.22        pk #endif
    472  1.14        pk }
    473   1.4   deraadt 
    474  1.14        pk int
    475  1.14        pk obio_scan(parent, child, args)
    476  1.14        pk 	struct device *parent;
    477  1.28        pk 	struct cfdata *child;
    478  1.28        pk 	void *args;
    479  1.14        pk {
    480  1.14        pk 	return busattach(parent, child, args, BUS_OBIO);
    481   1.4   deraadt }
    482   1.5   deraadt 
    483  1.14        pk int
    484  1.14        pk vmes_scan(parent, child, args)
    485  1.14        pk 	struct device *parent;
    486  1.28        pk 	struct cfdata *child;
    487  1.28        pk 	void *args;
    488  1.14        pk {
    489  1.14        pk 	return busattach(parent, child, args, BUS_VME16);
    490  1.14        pk }
    491  1.14        pk 
    492  1.14        pk int
    493  1.14        pk vmel_scan(parent, child, args)
    494  1.14        pk 	struct device *parent;
    495  1.28        pk 	struct cfdata *child;
    496  1.28        pk 	void *args;
    497  1.14        pk {
    498  1.14        pk 	return busattach(parent, child, args, BUS_VME32);
    499   1.4   deraadt }
    500   1.4   deraadt 
    501   1.5   deraadt int pil_to_vme[] = {
    502   1.5   deraadt 	-1,	/* pil 0 */
    503   1.5   deraadt 	-1,	/* pil 1 */
    504   1.5   deraadt 	1,	/* pil 2 */
    505   1.5   deraadt 	2,	/* pil 3 */
    506   1.5   deraadt 	-1,	/* pil 4 */
    507   1.5   deraadt 	3,	/* pil 5 */
    508   1.5   deraadt 	-1,	/* pil 6 */
    509   1.5   deraadt 	4,	/* pil 7 */
    510   1.5   deraadt 	-1,	/* pil 8 */
    511   1.5   deraadt 	5,	/* pil 9 */
    512   1.5   deraadt 	-1,	/* pil 10 */
    513   1.5   deraadt 	6,	/* pil 11 */
    514   1.5   deraadt 	-1,	/* pil 12 */
    515   1.5   deraadt 	7,	/* pil 13 */
    516   1.5   deraadt 	-1,	/* pil 14 */
    517   1.5   deraadt 	-1,	/* pil 15 */
    518   1.5   deraadt };
    519   1.5   deraadt 
    520   1.5   deraadt int
    521   1.5   deraadt vmeintr(arg)
    522   1.5   deraadt 	void *arg;
    523   1.5   deraadt {
    524  1.32        pk 	int pil = (int)arg, level, vec;
    525   1.5   deraadt 	struct intrhand *ih;
    526   1.5   deraadt 	int i = 0;
    527   1.5   deraadt 
    528  1.32        pk 	level = (pil_to_vme[pil] << 1) | 1;
    529  1.32        pk 
    530  1.32        pk 	if (CPU_ISSUN4) {
    531  1.32        pk 		vec = ldcontrolb((caddr_t)(AC_VMEINTVEC | level));
    532  1.32        pk 	} else if (CPU_ISSUN4M) {
    533  1.32        pk 		vec = vmebus_sc->sc_vec->vmebusvec[level];
    534  1.32        pk 	} else
    535  1.22        pk 		panic("vme: spurious interrupt");
    536  1.22        pk 
    537   1.6   deraadt 	if (vec == -1) {
    538  1.27  christos 		printf("vme: spurious interrupt\n");
    539   1.6   deraadt 		return 0;
    540   1.6   deraadt 	}
    541   1.5   deraadt 
    542   1.5   deraadt 	for (ih = vmeints[vec]; ih; ih = ih->ih_next)
    543   1.5   deraadt 		if (ih->ih_fun)
    544   1.5   deraadt 			i += (ih->ih_fun)(ih->ih_arg);
    545   1.5   deraadt 	return (i);
    546   1.5   deraadt }
    547   1.5   deraadt 
    548   1.5   deraadt void
    549   1.5   deraadt vmeintr_establish(vec, level, ih)
    550   1.5   deraadt 	int vec, level;
    551   1.5   deraadt 	struct intrhand *ih;
    552  1.22        pk {
    553   1.5   deraadt 	struct intrhand *ihs;
    554   1.5   deraadt 
    555  1.22        pk 	if (!CPU_ISSUN4) {
    556  1.22        pk 		panic("vmeintr_establish: not supported on cpu-type %d",
    557  1.22        pk 		      cputyp);
    558  1.22        pk 	}
    559  1.22        pk 
    560   1.8   deraadt 	if (vec == -1)
    561   1.8   deraadt 		panic("vmeintr_establish: uninitialized vec\n");
    562   1.8   deraadt 
    563   1.5   deraadt 	if (vmeints[vec] == NULL)
    564   1.5   deraadt 		vmeints[vec] = ih;
    565   1.5   deraadt 	else {
    566   1.5   deraadt 		for (ihs = vmeints[vec]; ihs->ih_next; ihs = ihs->ih_next)
    567   1.5   deraadt 			;
    568   1.5   deraadt 		ihs->ih_next = ih;
    569   1.5   deraadt 	}
    570   1.5   deraadt 
    571   1.5   deraadt 	/* ensure the interrupt subsystem will call us at this level */
    572   1.5   deraadt 	for (ihs = intrhand[level]; ihs; ihs = ihs->ih_next)
    573   1.5   deraadt 		if (ihs->ih_fun == vmeintr)
    574   1.5   deraadt 			return;
    575   1.5   deraadt 
    576   1.5   deraadt 	ihs = (struct intrhand *)malloc(sizeof(struct intrhand),
    577   1.5   deraadt 	    M_TEMP, M_NOWAIT);
    578   1.5   deraadt 	if (ihs == NULL)
    579   1.5   deraadt 		panic("vme_addirq");
    580   1.5   deraadt 	bzero(ihs, sizeof *ihs);
    581   1.5   deraadt 	ihs->ih_fun = vmeintr;
    582   1.5   deraadt 	ihs->ih_arg = (void *)level;
    583   1.5   deraadt 	intr_establish(level, ihs);
    584   1.5   deraadt }
    585   1.4   deraadt 
    586   1.2   deraadt #define	getpte(va)		lda(va, ASI_PTE)
    587   1.2   deraadt 
    588   1.2   deraadt /*
    589   1.2   deraadt  * If we can find a mapping that was established by the rom, use it.
    590   1.2   deraadt  * Else, create a new mapping.
    591   1.2   deraadt  */
    592   1.2   deraadt void *
    593   1.4   deraadt bus_map(pa, len, bustype)
    594  1.17        pk 	struct rom_reg *pa;
    595   1.2   deraadt 	int len;
    596   1.4   deraadt 	int bustype;
    597   1.2   deraadt {
    598   1.2   deraadt 
    599  1.32        pk 	if (CPU_ISSUN4 && len <= NBPG) {
    600  1.32        pk 		u_long	pf = (u_long)(pa->rr_paddr) >> PGSHIFT;
    601  1.32        pk 		u_long	va, pte;
    602  1.32        pk 		int pgtype = -1;
    603  1.32        pk 
    604  1.32        pk 		switch (bt2pmt[bustype]) {
    605  1.32        pk 		case PMAP_OBIO:
    606  1.32        pk 			pgtype = PG_OBIO;
    607  1.32        pk 			break;
    608  1.32        pk 		case PMAP_VME32:
    609  1.32        pk 			pgtype = PG_VME32;
    610  1.32        pk 			break;
    611  1.32        pk 		case PMAP_VME16:
    612  1.32        pk 			pgtype = PG_VME16;
    613  1.32        pk 			break;
    614  1.32        pk 		}
    615  1.32        pk 
    616   1.3   deraadt 		for (va = OLDMON_STARTVADDR; va < OLDMON_ENDVADDR; va += NBPG) {
    617   1.3   deraadt 			pte = getpte(va);
    618   1.4   deraadt 			if ((pte & PG_V) != 0 && (pte & PG_TYPE) == pgtype &&
    619   1.3   deraadt 			    (pte & PG_PFNUM) == pf)
    620  1.19     chuck 				return ((void *)
    621  1.19     chuck 				    (va | ((u_long)pa->rr_paddr & PGOFSET)) );
    622  1.19     chuck 					/* note: preserve page offset */
    623   1.3   deraadt 		}
    624   1.2   deraadt 	}
    625  1.32        pk 
    626  1.32        pk 	if (CPU_ISSUN4M)
    627  1.32        pk 		pa->rr_iospace =
    628  1.32        pk 		     (bustype == BUS_VME32) ? VME_SUN4M_32 : VME_SUN4M_16;
    629  1.17        pk 	return mapiodev(pa, 0, len, bustype);
    630   1.2   deraadt }
    631   1.2   deraadt 
    632   1.2   deraadt void *
    633   1.4   deraadt bus_tmp(pa, bustype)
    634   1.2   deraadt 	void *pa;
    635   1.4   deraadt 	int bustype;
    636   1.2   deraadt {
    637   1.3   deraadt 	vm_offset_t addr = (vm_offset_t)pa & ~PGOFSET;
    638  1.32        pk 	int pmtype;
    639  1.32        pk 
    640  1.32        pk 	if (CPU_ISSUN4)
    641  1.32        pk 		pmtype = bt2pmt[bustype];
    642  1.32        pk 	else if (CPU_ISSUN4M) {
    643  1.32        pk 		/* XXX - clear up bustype stuff */
    644  1.32        pk 		pmtype = (bustype == BUS_VME32) ? VME_SUN4M_32 : VME_SUN4M_16;
    645  1.32        pk 		pmtype <<= PMAP_SHFT4M;
    646  1.32        pk 	} else
    647  1.32        pk 		panic("bus_tmp: architecture unsupported");
    648   1.3   deraadt 
    649  1.13   mycroft 	pmap_enter(pmap_kernel(), TMPMAP_VA,
    650  1.22        pk 		   addr | pmtype | PMAP_NC,
    651  1.22        pk 		   VM_PROT_READ | VM_PROT_WRITE, 1);
    652  1.19     chuck 	return ((void *)(TMPMAP_VA | ((u_long) pa & PGOFSET)) );
    653   1.2   deraadt }
    654   1.2   deraadt 
    655   1.2   deraadt void
    656   1.4   deraadt bus_untmp()
    657   1.2   deraadt {
    658  1.13   mycroft 	pmap_remove(pmap_kernel(), TMPMAP_VA, TMPMAP_VA+NBPG);
    659   1.1   deraadt }
    660