Home | History | Annotate | Line # | Download | only in dev
obio.c revision 1.38
      1  1.38   thorpej /*	$NetBSD: obio.c,v 1.38 1998/01/12 20:23:54 thorpej Exp $	*/
      2   1.1   deraadt 
      3   1.1   deraadt /*
      4   1.1   deraadt  * Copyright (c) 1993, 1994 Theo de Raadt
      5  1.33        pk  * Copyright (c) 1995, 1997 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.28        pk int		obio_scan __P((struct device *, struct cfdata *, void *));
     86  1.28        pk int 		vmes_scan __P((struct device *, struct cfdata *, void *));
     87  1.28        pk int 		vmel_scan __P((struct device *, struct cfdata *, void *));
     88  1.35        pk void		vmebus_translate __P((struct device *, struct confargs *, int));
     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 cfattach vmel_ca = {
     96  1.21   thorpej 	sizeof(struct bus_softc), busmatch, vmelattach
     97  1.21   thorpej };
     98  1.21   thorpej 
     99  1.21   thorpej struct cfattach vmes_ca = {
    100  1.21   thorpej 	sizeof(struct bus_softc), busmatch, vmesattach
    101   1.1   deraadt };
    102  1.21   thorpej 
    103  1.32        pk struct cfattach vme_ca = {
    104  1.32        pk 	sizeof(struct bus_softc), busmatch, vmeattach
    105  1.32        pk };
    106  1.32        pk 
    107  1.22        pk struct intrhand **vmeints;
    108   1.4   deraadt 
    109   1.2   deraadt 
    110   1.1   deraadt int
    111  1.28        pk busmatch(parent, cf, aux)
    112   1.1   deraadt 	struct device *parent;
    113  1.28        pk 	struct cfdata *cf;
    114  1.28        pk 	void *aux;
    115   1.1   deraadt {
    116   1.3   deraadt 	register struct confargs *ca = aux;
    117   1.3   deraadt 	register struct romaux *ra = &ca->ca_ra;
    118   1.3   deraadt 
    119  1.22        pk 	if (CPU_ISSUN4M)
    120  1.22        pk 		return (strcmp(cf->cf_driver->cd_name, ra->ra_name) == 0);
    121  1.22        pk 
    122  1.22        pk 	if (!CPU_ISSUN4)
    123   1.3   deraadt 		return (0);
    124  1.22        pk 
    125   1.3   deraadt 	return (strcmp(cf->cf_driver->cd_name, ra->ra_name) == 0);
    126   1.1   deraadt }
    127   1.1   deraadt 
    128   1.1   deraadt int
    129   1.4   deraadt busprint(args, obio)
    130   1.1   deraadt 	void *args;
    131  1.25       cgd 	const char *obio;
    132   1.1   deraadt {
    133   1.2   deraadt 	register struct confargs *ca = args;
    134   1.2   deraadt 
    135   1.2   deraadt 	if (ca->ca_ra.ra_name == NULL)
    136   1.2   deraadt 		ca->ca_ra.ra_name = "<unknown>";
    137  1.22        pk 
    138   1.2   deraadt 	if (obio)
    139  1.27  christos 		printf("[%s at %s]", ca->ca_ra.ra_name, obio);
    140  1.22        pk 
    141  1.27  christos 	printf(" addr %p", ca->ca_ra.ra_paddr);
    142  1.22        pk 
    143  1.22        pk 	if (CPU_ISSUN4 && ca->ca_ra.ra_intr[0].int_vec != -1)
    144  1.27  christos 		printf(" vec 0x%x", ca->ca_ra.ra_intr[0].int_vec);
    145  1.22        pk 
    146   1.1   deraadt 	return (UNCONF);
    147   1.1   deraadt }
    148   1.1   deraadt 
    149  1.32        pk int
    150  1.32        pk vmeprint(args, name)
    151  1.32        pk 	void *args;
    152  1.32        pk 	const char *name;
    153  1.32        pk {
    154  1.32        pk 	register struct confargs *ca = args;
    155  1.32        pk 
    156  1.32        pk 	if (name)
    157  1.32        pk 		printf("%s at %s", ca->ca_ra.ra_name, name);
    158  1.32        pk 	return (UNCONF);
    159  1.32        pk }
    160  1.14        pk 
    161  1.22        pk void
    162  1.22        pk obioattach(parent, self, args)
    163  1.22        pk 	struct device *parent, *self;
    164  1.22        pk 	void *args;
    165  1.22        pk {
    166  1.22        pk #if defined(SUN4M)
    167  1.22        pk 	register struct bus_softc *sc = (struct bus_softc *)self;
    168  1.22        pk 	struct confargs oca, *ca = args;
    169  1.22        pk 	register struct romaux *ra = &ca->ca_ra;
    170  1.22        pk 	register int node0, node;
    171  1.22        pk 	register char *name;
    172  1.22        pk 	register const char *sp;
    173  1.22        pk 	const char *const *ssp;
    174  1.31        pk 	int rlen;
    175  1.22        pk 	extern int autoconf_nzs;
    176  1.22        pk 
    177  1.22        pk 	static const char *const special4m[] = {
    178  1.22        pk 		/* find these first */
    179  1.22        pk 		"eeprom",
    180  1.22        pk 		"counter",
    181  1.29        pk #if 0 /* Not all sun4m's have an `auxio' */
    182  1.22        pk 		"auxio",
    183  1.29        pk #endif
    184  1.22        pk 		"",
    185  1.22        pk 		/* place device to ignore here */
    186  1.22        pk 		"interrupt",
    187  1.22        pk 		NULL
    188  1.22        pk 	};
    189  1.22        pk #endif
    190  1.22        pk 
    191  1.22        pk 	if (CPU_ISSUN4) {
    192  1.22        pk 		if (self->dv_unit > 0) {
    193  1.27  christos 			printf(" unsupported\n");
    194  1.22        pk 			return;
    195  1.22        pk 		}
    196  1.27  christos 		printf("\n");
    197  1.22        pk 
    198  1.22        pk 		(void)config_search(obio_scan, self, args);
    199  1.22        pk 		bus_untmp();
    200  1.22        pk 	}
    201  1.22        pk 
    202  1.22        pk #if defined(SUN4M)
    203  1.22        pk 	if (!CPU_ISSUN4M)
    204  1.22        pk 		return;
    205  1.22        pk 
    206  1.22        pk 	/*
    207  1.22        pk 	 * There is only one obio bus (it is in fact one of the Sbus slots)
    208  1.22        pk 	 * How about VME?
    209  1.22        pk 	 */
    210  1.32        pk 	if (self->dv_unit > 0) {
    211  1.27  christos 		printf(" unsupported\n");
    212  1.22        pk 		return;
    213  1.22        pk 	}
    214  1.22        pk 
    215  1.27  christos 	printf("\n");
    216  1.22        pk 
    217  1.22        pk 	if (ra->ra_bp != NULL && strcmp(ra->ra_bp->name, "obio") == 0)
    218  1.22        pk 		oca.ca_ra.ra_bp = ra->ra_bp + 1;
    219  1.22        pk 	else
    220  1.22        pk 		oca.ca_ra.ra_bp = NULL;
    221  1.22        pk 
    222  1.31        pk 	node = ra->ra_node;
    223  1.31        pk 	rlen = getproplen(node, "ranges");
    224  1.31        pk 	if (rlen > 0) {
    225  1.31        pk 		sc->bu.scu_sbus.sc_nrange = rlen / sizeof(struct rom_range);
    226  1.31        pk 		sc->bu.scu_sbus.sc_range =
    227  1.31        pk 			(struct rom_range *)malloc(rlen, M_DEVBUF, M_NOWAIT);
    228  1.31        pk 		if (sc->bu.scu_sbus.sc_range == 0)
    229  1.31        pk 			panic("obio: PROM ranges too large: %d", rlen);
    230  1.31        pk 		(void)getprop(node, "ranges", sc->bu.scu_sbus.sc_range, rlen);
    231  1.31        pk 	}
    232  1.22        pk 
    233  1.22        pk 	/*
    234  1.22        pk 	 * Loop through ROM children, fixing any relative addresses
    235  1.22        pk 	 * and then configuring each device.
    236  1.22        pk 	 * We first do the crucial ones, such as eeprom, etc.
    237  1.22        pk 	 */
    238  1.22        pk 	node0 = firstchild(ra->ra_node);
    239  1.22        pk 	for (ssp = special4m ; *(sp = *ssp) != 0; ssp++) {
    240  1.22        pk 		if ((node = findnode(node0, sp)) == 0) {
    241  1.27  christos 			printf("could not find %s amongst obio devices\n", sp);
    242  1.22        pk 			panic(sp);
    243  1.22        pk 		}
    244  1.22        pk 		if (!romprop(&oca.ca_ra, sp, node))
    245  1.22        pk 			continue;
    246  1.22        pk 
    247  1.22        pk 		sbus_translate(self, &oca);
    248  1.22        pk 		oca.ca_bustype = BUS_OBIO;
    249  1.32        pk 		(void) config_found(self, (void *)&oca, busprint);
    250  1.22        pk 	}
    251  1.22        pk 
    252  1.22        pk 	for (node = node0; node; node = nextsibling(node)) {
    253  1.22        pk 		name = getpropstring(node, "name");
    254  1.22        pk 		for (ssp = special4m ; (sp = *ssp) != NULL; ssp++)
    255  1.22        pk 			if (strcmp(name, sp) == 0)
    256  1.22        pk 				break;
    257  1.22        pk 
    258  1.22        pk 		if (sp != NULL || !romprop(&oca.ca_ra, name, node))
    259  1.22        pk 			continue;
    260  1.22        pk 
    261  1.22        pk 		if (strcmp(name, "zs") == 0)
    262  1.22        pk 			/* XXX - see autoconf.c for this hack */
    263  1.22        pk 			autoconf_nzs++;
    264  1.22        pk 
    265  1.22        pk 		/* Translate into parent address spaces */
    266  1.22        pk 		sbus_translate(self, &oca);
    267  1.22        pk 		oca.ca_bustype = BUS_OBIO;
    268  1.32        pk 		(void) config_found(self, (void *)&oca, busprint);
    269  1.22        pk 	}
    270  1.22        pk #endif
    271  1.22        pk }
    272  1.22        pk 
    273  1.22        pk void
    274  1.22        pk vmesattach(parent, self, args)
    275  1.22        pk 	struct device *parent, *self;
    276  1.22        pk 	void *args;
    277  1.22        pk {
    278  1.32        pk 	if (self->dv_unit > 0 ||
    279  1.32        pk 	    (CPU_ISSUN4M && strncmp(parent->dv_xname, "vme", 3) != 0)) {
    280  1.27  christos 		printf(" unsupported\n");
    281  1.22        pk 		return;
    282  1.22        pk 	}
    283  1.27  christos 	printf("\n");
    284  1.22        pk 
    285  1.22        pk 	if (vmeints == NULL) {
    286  1.22        pk 		vmeints = (struct intrhand **)malloc(256 *
    287  1.22        pk 		    sizeof(struct intrhand *), M_TEMP, M_NOWAIT);
    288  1.22        pk 		bzero(vmeints, 256 * sizeof(struct intrhand *));
    289  1.22        pk 	}
    290  1.22        pk 	(void)config_search(vmes_scan, self, args);
    291  1.22        pk 	bus_untmp();
    292  1.22        pk }
    293  1.22        pk 
    294  1.22        pk void
    295  1.22        pk vmelattach(parent, self, args)
    296  1.22        pk 	struct device *parent, *self;
    297  1.22        pk 	void *args;
    298  1.22        pk {
    299  1.32        pk 	if (self->dv_unit > 0 ||
    300  1.32        pk 	    (CPU_ISSUN4M && strncmp(parent->dv_xname, "vme", 3) != 0)) {
    301  1.27  christos 		printf(" unsupported\n");
    302  1.22        pk 		return;
    303  1.22        pk 	}
    304  1.27  christos 	printf("\n");
    305  1.22        pk 
    306  1.22        pk 	if (vmeints == NULL) {
    307  1.22        pk 		vmeints = (struct intrhand **)malloc(256 *
    308  1.22        pk 		    sizeof(struct intrhand *), M_TEMP, M_NOWAIT);
    309  1.22        pk 		bzero(vmeints, 256 * sizeof(struct intrhand *));
    310  1.22        pk 	}
    311  1.22        pk 	(void)config_search(vmel_scan, self, args);
    312  1.22        pk 	bus_untmp();
    313  1.22        pk }
    314  1.22        pk 
    315  1.32        pk void
    316  1.32        pk vmeattach(parent, self, aux)
    317  1.32        pk 	struct device *parent, *self;
    318  1.32        pk 	void *aux;
    319  1.32        pk {
    320  1.32        pk 	struct vmebus_softc *sc = (struct vmebus_softc *)self;
    321  1.32        pk 	struct confargs *ca = aux;
    322  1.32        pk 	register struct romaux *ra = &ca->ca_ra;
    323  1.32        pk 	int node, rlen;
    324  1.32        pk 	struct confargs oca;
    325  1.32        pk 
    326  1.32        pk 	if (!CPU_ISSUN4M || self->dv_unit > 0) {
    327  1.32        pk 		printf(" unsupported\n");
    328  1.32        pk 		return;
    329  1.32        pk 	}
    330  1.32        pk 
    331  1.32        pk 	node = ra->ra_node;
    332  1.32        pk 
    333  1.32        pk 	sc->sc_reg = (struct vmebusreg *)
    334  1.34        pk 		mapdev(&ra->ra_reg[0], 0, 0, ra->ra_reg[0].rr_len);
    335  1.32        pk 	sc->sc_vec = (struct vmebusvec *)
    336  1.34        pk 		mapdev(&ra->ra_reg[1], 0, 0, ra->ra_reg[1].rr_len);
    337  1.32        pk 
    338  1.32        pk 	/*
    339  1.32        pk 	 * Get "range" property, though we don't do anything with it yet.
    340  1.32        pk 	 */
    341  1.32        pk 	rlen = getproplen(node, "ranges");
    342  1.32        pk 	if (rlen > 0) {
    343  1.32        pk 		sc->sc_nrange = rlen / sizeof(struct rom_range);
    344  1.32        pk 		sc->sc_range =
    345  1.32        pk 			(struct rom_range *)malloc(rlen, M_DEVBUF, M_NOWAIT);
    346  1.32        pk 		if (sc->sc_range == 0)
    347  1.32        pk 			panic("vme: PROM ranges too large: %d", rlen);
    348  1.32        pk 		(void)getprop(node, "ranges", sc->sc_range, rlen);
    349  1.32        pk 	}
    350  1.32        pk 
    351  1.32        pk 	vmebus_sc = sc;
    352  1.37      fair 	printf(": version 0x%x\n",
    353  1.32        pk 	       sc->sc_reg->vmebus_cr & VMEBUS_CR_IMPL);
    354  1.32        pk 
    355  1.32        pk 	if (ra->ra_bp != NULL && strcmp(ra->ra_bp->name, "vme") == 0)
    356  1.32        pk 		oca.ca_ra.ra_bp = ra->ra_bp + 1;
    357  1.32        pk 	else
    358  1.32        pk 		oca.ca_ra.ra_bp = NULL;
    359  1.32        pk 
    360  1.32        pk 	oca.ca_ra.ra_name = "vmes";
    361  1.32        pk 	oca.ca_bustype = BUS_MAIN;
    362  1.32        pk 	(void)config_found(self, (void *)&oca, vmeprint);
    363  1.32        pk 
    364  1.32        pk 	oca.ca_ra.ra_name = "vmel";
    365  1.32        pk 	oca.ca_bustype = BUS_MAIN;
    366  1.32        pk 	(void)config_found(self, (void *)&oca, vmeprint);
    367  1.32        pk }
    368  1.32        pk 
    369  1.35        pk void
    370  1.35        pk vmebus_translate(dev, ca, bustype)
    371  1.35        pk 	struct device *dev;
    372  1.35        pk 	struct confargs *ca;
    373  1.35        pk 	int bustype;
    374  1.35        pk {
    375  1.35        pk 	struct vmebus_softc *sc = (struct vmebus_softc *)dev;
    376  1.35        pk 	register int j;
    377  1.35        pk 	int cspace;
    378  1.35        pk 
    379  1.35        pk 	if (sc->sc_nrange == 0)
    380  1.35        pk 		panic("vmebus: no ranges");
    381  1.35        pk 
    382  1.35        pk 	/*
    383  1.35        pk 	 * Find VMEbus modifier based on address space.
    384  1.35        pk 	 * XXX - should not be encoded in `ra_paddr'
    385  1.35        pk 	 */
    386  1.35        pk 	if (((u_long)ca->ca_ra.ra_paddr & 0xffff0000) == 0xffff0000)
    387  1.35        pk 		cspace = VMEMOD_A16_D_S;
    388  1.35        pk 	else if (((u_long)ca->ca_ra.ra_paddr & 0xff000000) == 0xff000000)
    389  1.35        pk 		cspace = VMEMOD_A24_D_S;
    390  1.35        pk 	else
    391  1.35        pk 		cspace = VMEMOD_A32_D_S;
    392  1.35        pk 
    393  1.35        pk 	cspace |= (bustype == BUS_VME32) ? VMEMOD_D32 : 0;
    394  1.35        pk 
    395  1.35        pk 	/* Translate into parent address spaces */
    396  1.35        pk 	for (j = 0; j < sc->sc_nrange; j++) {
    397  1.35        pk 		if (sc->sc_range[j].cspace == cspace) {
    398  1.35        pk #if notyet
    399  1.35        pk 			(int)ca->ca_ra.ra_paddr +=
    400  1.35        pk 				sc->sc_range[j].poffset;
    401  1.35        pk #endif
    402  1.35        pk 			(int)ca->ca_ra.ra_iospace =
    403  1.35        pk 				sc->sc_range[j].pspace;
    404  1.35        pk 			break;
    405  1.35        pk 		}
    406  1.35        pk 	}
    407  1.35        pk }
    408  1.35        pk 
    409  1.34        pk int bt2pmt[] = {
    410  1.34        pk 	PMAP_OBIO,
    411  1.34        pk 	PMAP_OBIO,
    412  1.34        pk 	PMAP_VME16,
    413  1.34        pk 	PMAP_VME32,
    414  1.34        pk 	PMAP_OBIO
    415  1.34        pk };
    416  1.34        pk 
    417  1.14        pk int
    418  1.28        pk busattach(parent, cf, args, bustype)
    419  1.14        pk 	struct device *parent;
    420  1.28        pk 	struct cfdata *cf;
    421  1.28        pk 	void *args;
    422   1.4   deraadt 	int bustype;
    423   1.1   deraadt {
    424  1.32        pk #if defined(SUN4) || defined(SUN4M)
    425   1.3   deraadt 	register struct confargs *ca = args;
    426   1.3   deraadt 	struct confargs oca;
    427   1.4   deraadt 	caddr_t tmp;
    428   1.1   deraadt 
    429  1.22        pk 	if (bustype == BUS_OBIO && CPU_ISSUN4) {
    430  1.23     chuck 
    431  1.23     chuck 		/*
    432  1.23     chuck 		 * avoid sun4m entries which don't have valid PA's.
    433  1.23     chuck 		 * no point in even probing them.
    434  1.23     chuck 		 */
    435  1.23     chuck 		if (cf->cf_loc[0] == -1) return 0;
    436  1.23     chuck 
    437  1.14        pk 		/*
    438  1.14        pk 		 * On the 4/100 obio addresses must be mapped at
    439  1.14        pk 		 * 0x0YYYYYYY, but alias higher up (we avoid the
    440  1.14        pk 		 * alias condition because it causes pmap difficulties)
    441  1.14        pk 		 * XXX: We also assume that 4/[23]00 obio addresses
    442  1.14        pk 		 * must be 0xZYYYYYYY, where (Z != 0)
    443  1.14        pk 		 */
    444  1.30        pk 		if (cpuinfo.cpu_type == CPUTYP_4_100 &&
    445  1.30        pk 		    (cf->cf_loc[0] & 0xf0000000))
    446  1.14        pk 			return 0;
    447  1.30        pk 		if (cpuinfo.cpu_type != CPUTYP_4_100 &&
    448  1.30        pk 		    !(cf->cf_loc[0] & 0xf0000000))
    449  1.14        pk 			return 0;
    450  1.14        pk 	}
    451  1.14        pk 
    452  1.14        pk 	oca.ca_ra.ra_paddr = (void *)cf->cf_loc[0];
    453  1.14        pk 	oca.ca_ra.ra_len = 0;
    454  1.14        pk 	oca.ca_ra.ra_nreg = 1;
    455  1.35        pk 	if (CPU_ISSUN4M)
    456  1.35        pk 		vmebus_translate(parent->dv_parent, &oca, bustype);
    457  1.35        pk 	else
    458  1.35        pk 		oca.ca_ra.ra_iospace = bt2pmt[bustype];
    459  1.35        pk 
    460  1.14        pk 	if (oca.ca_ra.ra_paddr)
    461  1.34        pk 		tmp = (caddr_t)mapdev(oca.ca_ra.ra_reg, TMPMAP_VA, 0, NBPG);
    462  1.24       mrg 	else
    463  1.24       mrg 		tmp = NULL;
    464  1.14        pk 	oca.ca_ra.ra_vaddr = tmp;
    465  1.14        pk 	oca.ca_ra.ra_intr[0].int_pri = cf->cf_loc[1];
    466  1.14        pk 	if (bustype == BUS_VME16 || bustype == BUS_VME32)
    467  1.14        pk 		oca.ca_ra.ra_intr[0].int_vec = cf->cf_loc[2];
    468  1.14        pk 	else
    469  1.14        pk 		oca.ca_ra.ra_intr[0].int_vec = -1;
    470  1.14        pk 	oca.ca_ra.ra_nintr = 1;
    471  1.14        pk 	oca.ca_ra.ra_name = cf->cf_driver->cd_name;
    472  1.15        pk 	if (ca->ca_ra.ra_bp != NULL &&
    473  1.16        pk 	  ((bustype == BUS_VME16 && strcmp(ca->ca_ra.ra_bp->name,"vmes") ==0) ||
    474  1.16        pk 	   (bustype == BUS_VME32 && strcmp(ca->ca_ra.ra_bp->name,"vmel") ==0) ||
    475  1.16        pk 	   (bustype == BUS_OBIO && strcmp(ca->ca_ra.ra_bp->name,"obio") == 0)))
    476  1.15        pk 		oca.ca_ra.ra_bp = ca->ca_ra.ra_bp + 1;
    477  1.15        pk 	else
    478  1.15        pk 		oca.ca_ra.ra_bp = NULL;
    479  1.14        pk 	oca.ca_bustype = bustype;
    480  1.14        pk 
    481  1.21   thorpej 	if ((*cf->cf_attach->ca_match)(parent, cf, &oca) == 0)
    482  1.14        pk 		return 0;
    483  1.14        pk 
    484  1.14        pk 	/*
    485  1.22        pk 	 * check if XXmatch routine replaced the temporary mapping with
    486  1.19     chuck 	 * a real mapping.   If not, then make sure we don't pass the
    487  1.19     chuck 	 * tmp mapping to the attach routine.
    488  1.14        pk 	 */
    489  1.19     chuck 	if (oca.ca_ra.ra_vaddr == tmp)
    490  1.19     chuck 		oca.ca_ra.ra_vaddr = NULL; /* wipe out tmp address */
    491  1.14        pk 	/*
    492  1.22        pk 	 * the match routine will set "ra_len" if it wants us to
    493  1.19     chuck 	 * establish a mapping for it.
    494  1.14        pk 	 * (which won't be seen on future XXmatch calls,
    495  1.14        pk 	 * so not as useful as it seems.)
    496  1.14        pk 	 */
    497  1.22        pk 	if (oca.ca_ra.ra_len)
    498  1.14        pk 		oca.ca_ra.ra_vaddr =
    499  1.34        pk 		    bus_map(oca.ca_ra.ra_reg, oca.ca_ra.ra_len);
    500  1.14        pk 
    501  1.14        pk 	config_attach(parent, cf, &oca, busprint);
    502  1.14        pk 	return 1;
    503  1.22        pk #else
    504  1.22        pk 	return 0;
    505  1.22        pk #endif
    506  1.14        pk }
    507   1.4   deraadt 
    508  1.14        pk int
    509  1.14        pk obio_scan(parent, child, args)
    510  1.14        pk 	struct device *parent;
    511  1.28        pk 	struct cfdata *child;
    512  1.28        pk 	void *args;
    513  1.14        pk {
    514  1.14        pk 	return busattach(parent, child, args, BUS_OBIO);
    515   1.4   deraadt }
    516   1.5   deraadt 
    517  1.14        pk int
    518  1.14        pk vmes_scan(parent, child, args)
    519  1.14        pk 	struct device *parent;
    520  1.28        pk 	struct cfdata *child;
    521  1.28        pk 	void *args;
    522  1.14        pk {
    523  1.14        pk 	return busattach(parent, child, args, BUS_VME16);
    524  1.14        pk }
    525  1.14        pk 
    526  1.14        pk int
    527  1.14        pk vmel_scan(parent, child, args)
    528  1.14        pk 	struct device *parent;
    529  1.28        pk 	struct cfdata *child;
    530  1.28        pk 	void *args;
    531  1.14        pk {
    532  1.14        pk 	return busattach(parent, child, args, BUS_VME32);
    533   1.4   deraadt }
    534   1.4   deraadt 
    535   1.5   deraadt int pil_to_vme[] = {
    536   1.5   deraadt 	-1,	/* pil 0 */
    537   1.5   deraadt 	-1,	/* pil 1 */
    538   1.5   deraadt 	1,	/* pil 2 */
    539   1.5   deraadt 	2,	/* pil 3 */
    540   1.5   deraadt 	-1,	/* pil 4 */
    541   1.5   deraadt 	3,	/* pil 5 */
    542   1.5   deraadt 	-1,	/* pil 6 */
    543   1.5   deraadt 	4,	/* pil 7 */
    544   1.5   deraadt 	-1,	/* pil 8 */
    545   1.5   deraadt 	5,	/* pil 9 */
    546   1.5   deraadt 	-1,	/* pil 10 */
    547   1.5   deraadt 	6,	/* pil 11 */
    548   1.5   deraadt 	-1,	/* pil 12 */
    549   1.5   deraadt 	7,	/* pil 13 */
    550   1.5   deraadt 	-1,	/* pil 14 */
    551   1.5   deraadt 	-1,	/* pil 15 */
    552   1.5   deraadt };
    553   1.5   deraadt 
    554   1.5   deraadt int
    555   1.5   deraadt vmeintr(arg)
    556   1.5   deraadt 	void *arg;
    557   1.5   deraadt {
    558  1.32        pk 	int pil = (int)arg, level, vec;
    559   1.5   deraadt 	struct intrhand *ih;
    560   1.5   deraadt 	int i = 0;
    561   1.5   deraadt 
    562  1.32        pk 	level = (pil_to_vme[pil] << 1) | 1;
    563  1.32        pk 
    564  1.32        pk 	if (CPU_ISSUN4) {
    565  1.32        pk 		vec = ldcontrolb((caddr_t)(AC_VMEINTVEC | level));
    566  1.32        pk 	} else if (CPU_ISSUN4M) {
    567  1.32        pk 		vec = vmebus_sc->sc_vec->vmebusvec[level];
    568  1.32        pk 	} else
    569  1.22        pk 		panic("vme: spurious interrupt");
    570  1.22        pk 
    571   1.6   deraadt 	if (vec == -1) {
    572  1.27  christos 		printf("vme: spurious interrupt\n");
    573   1.6   deraadt 		return 0;
    574   1.6   deraadt 	}
    575   1.5   deraadt 
    576   1.5   deraadt 	for (ih = vmeints[vec]; ih; ih = ih->ih_next)
    577   1.5   deraadt 		if (ih->ih_fun)
    578   1.5   deraadt 			i += (ih->ih_fun)(ih->ih_arg);
    579   1.5   deraadt 	return (i);
    580   1.5   deraadt }
    581   1.5   deraadt 
    582   1.5   deraadt void
    583   1.5   deraadt vmeintr_establish(vec, level, ih)
    584   1.5   deraadt 	int vec, level;
    585   1.5   deraadt 	struct intrhand *ih;
    586  1.22        pk {
    587   1.5   deraadt 	struct intrhand *ihs;
    588   1.5   deraadt 
    589  1.36        pk 	if (vmeints == NULL)
    590  1.36        pk 		panic("vmeintr_establish: interrupt vector not allocated");
    591  1.22        pk 
    592   1.8   deraadt 	if (vec == -1)
    593  1.36        pk 		panic("vmeintr_establish: uninitialized vec");
    594   1.8   deraadt 
    595   1.5   deraadt 	if (vmeints[vec] == NULL)
    596   1.5   deraadt 		vmeints[vec] = ih;
    597   1.5   deraadt 	else {
    598   1.5   deraadt 		for (ihs = vmeints[vec]; ihs->ih_next; ihs = ihs->ih_next)
    599   1.5   deraadt 			;
    600   1.5   deraadt 		ihs->ih_next = ih;
    601   1.5   deraadt 	}
    602   1.5   deraadt 
    603   1.5   deraadt 	/* ensure the interrupt subsystem will call us at this level */
    604   1.5   deraadt 	for (ihs = intrhand[level]; ihs; ihs = ihs->ih_next)
    605   1.5   deraadt 		if (ihs->ih_fun == vmeintr)
    606   1.5   deraadt 			return;
    607   1.5   deraadt 
    608   1.5   deraadt 	ihs = (struct intrhand *)malloc(sizeof(struct intrhand),
    609   1.5   deraadt 	    M_TEMP, M_NOWAIT);
    610   1.5   deraadt 	if (ihs == NULL)
    611   1.5   deraadt 		panic("vme_addirq");
    612   1.5   deraadt 	bzero(ihs, sizeof *ihs);
    613   1.5   deraadt 	ihs->ih_fun = vmeintr;
    614   1.5   deraadt 	ihs->ih_arg = (void *)level;
    615   1.5   deraadt 	intr_establish(level, ihs);
    616   1.5   deraadt }
    617   1.4   deraadt 
    618   1.2   deraadt #define	getpte(va)		lda(va, ASI_PTE)
    619   1.2   deraadt 
    620   1.2   deraadt /*
    621   1.2   deraadt  * If we can find a mapping that was established by the rom, use it.
    622   1.2   deraadt  * Else, create a new mapping.
    623   1.2   deraadt  */
    624   1.2   deraadt void *
    625  1.34        pk bus_map(pa, len)
    626  1.17        pk 	struct rom_reg *pa;
    627   1.2   deraadt 	int len;
    628   1.2   deraadt {
    629   1.2   deraadt 
    630  1.32        pk 	if (CPU_ISSUN4 && len <= NBPG) {
    631  1.32        pk 		u_long	pf = (u_long)(pa->rr_paddr) >> PGSHIFT;
    632  1.34        pk 		int pgtype = PMAP_T2PTE_4(pa->rr_iospace);
    633  1.32        pk 		u_long	va, pte;
    634  1.32        pk 
    635   1.3   deraadt 		for (va = OLDMON_STARTVADDR; va < OLDMON_ENDVADDR; va += NBPG) {
    636   1.3   deraadt 			pte = getpte(va);
    637   1.4   deraadt 			if ((pte & PG_V) != 0 && (pte & PG_TYPE) == pgtype &&
    638   1.3   deraadt 			    (pte & PG_PFNUM) == pf)
    639  1.19     chuck 				return ((void *)
    640  1.19     chuck 				    (va | ((u_long)pa->rr_paddr & PGOFSET)) );
    641  1.19     chuck 					/* note: preserve page offset */
    642   1.3   deraadt 		}
    643   1.2   deraadt 	}
    644  1.32        pk 
    645  1.34        pk 	return mapiodev(pa, 0, len);
    646   1.2   deraadt }
    647   1.2   deraadt 
    648   1.2   deraadt void
    649   1.4   deraadt bus_untmp()
    650   1.2   deraadt {
    651  1.13   mycroft 	pmap_remove(pmap_kernel(), TMPMAP_VA, TMPMAP_VA+NBPG);
    652   1.1   deraadt }
    653