Home | History | Annotate | Line # | Download | only in dev
obio.c revision 1.35
      1  1.35        pk /*	$NetBSD: obio.c,v 1.35 1997/06/07 19:16:23 pk 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 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.34        pk 		mapdev(&ra->ra_reg[0], 0, 0, ra->ra_reg[0].rr_len);
    351  1.32        pk 	sc->sc_vec = (struct vmebusvec *)
    352  1.34        pk 		mapdev(&ra->ra_reg[1], 0, 0, ra->ra_reg[1].rr_len);
    353  1.32        pk 
    354  1.32        pk 	/*
    355  1.32        pk 	 * Get "range" property, though we don't do anything with it yet.
    356  1.32        pk 	 */
    357  1.32        pk 	rlen = getproplen(node, "ranges");
    358  1.32        pk 	if (rlen > 0) {
    359  1.32        pk 		sc->sc_nrange = rlen / sizeof(struct rom_range);
    360  1.32        pk 		sc->sc_range =
    361  1.32        pk 			(struct rom_range *)malloc(rlen, M_DEVBUF, M_NOWAIT);
    362  1.32        pk 		if (sc->sc_range == 0)
    363  1.32        pk 			panic("vme: PROM ranges too large: %d", rlen);
    364  1.32        pk 		(void)getprop(node, "ranges", sc->sc_range, rlen);
    365  1.32        pk 	}
    366  1.32        pk 
    367  1.32        pk 	vmebus_sc = sc;
    368  1.32        pk 	printf(": version %x\n",
    369  1.32        pk 	       sc->sc_reg->vmebus_cr & VMEBUS_CR_IMPL);
    370  1.32        pk 
    371  1.32        pk 	if (ra->ra_bp != NULL && strcmp(ra->ra_bp->name, "vme") == 0)
    372  1.32        pk 		oca.ca_ra.ra_bp = ra->ra_bp + 1;
    373  1.32        pk 	else
    374  1.32        pk 		oca.ca_ra.ra_bp = NULL;
    375  1.32        pk 
    376  1.32        pk 	oca.ca_ra.ra_name = "vmes";
    377  1.32        pk 	oca.ca_bustype = BUS_MAIN;
    378  1.32        pk 	(void)config_found(self, (void *)&oca, vmeprint);
    379  1.32        pk 
    380  1.32        pk 	oca.ca_ra.ra_name = "vmel";
    381  1.32        pk 	oca.ca_bustype = BUS_MAIN;
    382  1.32        pk 	(void)config_found(self, (void *)&oca, vmeprint);
    383  1.32        pk }
    384  1.32        pk 
    385  1.35        pk void
    386  1.35        pk vmebus_translate(dev, ca, bustype)
    387  1.35        pk 	struct device *dev;
    388  1.35        pk 	struct confargs *ca;
    389  1.35        pk 	int bustype;
    390  1.35        pk {
    391  1.35        pk 	struct vmebus_softc *sc = (struct vmebus_softc *)dev;
    392  1.35        pk 	register int j;
    393  1.35        pk 	int cspace;
    394  1.35        pk 
    395  1.35        pk 	if (sc->sc_nrange == 0)
    396  1.35        pk 		panic("vmebus: no ranges");
    397  1.35        pk 
    398  1.35        pk 	/*
    399  1.35        pk 	 * Find VMEbus modifier based on address space.
    400  1.35        pk 	 * XXX - should not be encoded in `ra_paddr'
    401  1.35        pk 	 */
    402  1.35        pk 	if (((u_long)ca->ca_ra.ra_paddr & 0xffff0000) == 0xffff0000)
    403  1.35        pk 		cspace = VMEMOD_A16_D_S;
    404  1.35        pk 	else if (((u_long)ca->ca_ra.ra_paddr & 0xff000000) == 0xff000000)
    405  1.35        pk 		cspace = VMEMOD_A24_D_S;
    406  1.35        pk 	else
    407  1.35        pk 		cspace = VMEMOD_A32_D_S;
    408  1.35        pk 
    409  1.35        pk 	cspace |= (bustype == BUS_VME32) ? VMEMOD_D32 : 0;
    410  1.35        pk 
    411  1.35        pk 	/* Translate into parent address spaces */
    412  1.35        pk 	for (j = 0; j < sc->sc_nrange; j++) {
    413  1.35        pk 		if (sc->sc_range[j].cspace == cspace) {
    414  1.35        pk #if notyet
    415  1.35        pk 			(int)ca->ca_ra.ra_paddr +=
    416  1.35        pk 				sc->sc_range[j].poffset;
    417  1.35        pk #endif
    418  1.35        pk 			(int)ca->ca_ra.ra_iospace =
    419  1.35        pk 				sc->sc_range[j].pspace;
    420  1.35        pk 			break;
    421  1.35        pk 		}
    422  1.35        pk 	}
    423  1.35        pk }
    424  1.35        pk 
    425  1.34        pk int bt2pmt[] = {
    426  1.34        pk 	PMAP_OBIO,
    427  1.34        pk 	PMAP_OBIO,
    428  1.34        pk 	PMAP_VME16,
    429  1.34        pk 	PMAP_VME32,
    430  1.34        pk 	PMAP_OBIO
    431  1.34        pk };
    432  1.34        pk 
    433  1.14        pk int
    434  1.28        pk busattach(parent, cf, args, bustype)
    435  1.14        pk 	struct device *parent;
    436  1.28        pk 	struct cfdata *cf;
    437  1.28        pk 	void *args;
    438   1.4   deraadt 	int bustype;
    439   1.1   deraadt {
    440  1.32        pk #if defined(SUN4) || defined(SUN4M)
    441   1.3   deraadt 	register struct confargs *ca = args;
    442   1.3   deraadt 	struct confargs oca;
    443   1.4   deraadt 	caddr_t tmp;
    444   1.1   deraadt 
    445  1.22        pk 	if (bustype == BUS_OBIO && CPU_ISSUN4) {
    446  1.23     chuck 
    447  1.23     chuck 		/*
    448  1.23     chuck 		 * avoid sun4m entries which don't have valid PA's.
    449  1.23     chuck 		 * no point in even probing them.
    450  1.23     chuck 		 */
    451  1.23     chuck 		if (cf->cf_loc[0] == -1) return 0;
    452  1.23     chuck 
    453  1.14        pk 		/*
    454  1.14        pk 		 * On the 4/100 obio addresses must be mapped at
    455  1.14        pk 		 * 0x0YYYYYYY, but alias higher up (we avoid the
    456  1.14        pk 		 * alias condition because it causes pmap difficulties)
    457  1.14        pk 		 * XXX: We also assume that 4/[23]00 obio addresses
    458  1.14        pk 		 * must be 0xZYYYYYYY, where (Z != 0)
    459  1.14        pk 		 */
    460  1.30        pk 		if (cpuinfo.cpu_type == CPUTYP_4_100 &&
    461  1.30        pk 		    (cf->cf_loc[0] & 0xf0000000))
    462  1.14        pk 			return 0;
    463  1.30        pk 		if (cpuinfo.cpu_type != CPUTYP_4_100 &&
    464  1.30        pk 		    !(cf->cf_loc[0] & 0xf0000000))
    465  1.14        pk 			return 0;
    466  1.14        pk 	}
    467  1.14        pk 
    468  1.14        pk 	oca.ca_ra.ra_paddr = (void *)cf->cf_loc[0];
    469  1.14        pk 	oca.ca_ra.ra_len = 0;
    470  1.14        pk 	oca.ca_ra.ra_nreg = 1;
    471  1.35        pk 	if (CPU_ISSUN4M)
    472  1.35        pk 		vmebus_translate(parent->dv_parent, &oca, bustype);
    473  1.35        pk 	else
    474  1.35        pk 		oca.ca_ra.ra_iospace = bt2pmt[bustype];
    475  1.35        pk 
    476  1.14        pk 	if (oca.ca_ra.ra_paddr)
    477  1.34        pk 		tmp = (caddr_t)mapdev(oca.ca_ra.ra_reg, TMPMAP_VA, 0, NBPG);
    478  1.24       mrg 	else
    479  1.24       mrg 		tmp = NULL;
    480  1.14        pk 	oca.ca_ra.ra_vaddr = tmp;
    481  1.14        pk 	oca.ca_ra.ra_intr[0].int_pri = cf->cf_loc[1];
    482  1.14        pk 	if (bustype == BUS_VME16 || bustype == BUS_VME32)
    483  1.14        pk 		oca.ca_ra.ra_intr[0].int_vec = cf->cf_loc[2];
    484  1.14        pk 	else
    485  1.14        pk 		oca.ca_ra.ra_intr[0].int_vec = -1;
    486  1.14        pk 	oca.ca_ra.ra_nintr = 1;
    487  1.14        pk 	oca.ca_ra.ra_name = cf->cf_driver->cd_name;
    488  1.15        pk 	if (ca->ca_ra.ra_bp != NULL &&
    489  1.16        pk 	  ((bustype == BUS_VME16 && strcmp(ca->ca_ra.ra_bp->name,"vmes") ==0) ||
    490  1.16        pk 	   (bustype == BUS_VME32 && strcmp(ca->ca_ra.ra_bp->name,"vmel") ==0) ||
    491  1.16        pk 	   (bustype == BUS_OBIO && strcmp(ca->ca_ra.ra_bp->name,"obio") == 0)))
    492  1.15        pk 		oca.ca_ra.ra_bp = ca->ca_ra.ra_bp + 1;
    493  1.15        pk 	else
    494  1.15        pk 		oca.ca_ra.ra_bp = NULL;
    495  1.14        pk 	oca.ca_bustype = bustype;
    496  1.14        pk 
    497  1.21   thorpej 	if ((*cf->cf_attach->ca_match)(parent, cf, &oca) == 0)
    498  1.14        pk 		return 0;
    499  1.14        pk 
    500  1.14        pk 	/*
    501  1.22        pk 	 * check if XXmatch routine replaced the temporary mapping with
    502  1.19     chuck 	 * a real mapping.   If not, then make sure we don't pass the
    503  1.19     chuck 	 * tmp mapping to the attach routine.
    504  1.14        pk 	 */
    505  1.19     chuck 	if (oca.ca_ra.ra_vaddr == tmp)
    506  1.19     chuck 		oca.ca_ra.ra_vaddr = NULL; /* wipe out tmp address */
    507  1.14        pk 	/*
    508  1.22        pk 	 * the match routine will set "ra_len" if it wants us to
    509  1.19     chuck 	 * establish a mapping for it.
    510  1.14        pk 	 * (which won't be seen on future XXmatch calls,
    511  1.14        pk 	 * so not as useful as it seems.)
    512  1.14        pk 	 */
    513  1.22        pk 	if (oca.ca_ra.ra_len)
    514  1.14        pk 		oca.ca_ra.ra_vaddr =
    515  1.34        pk 		    bus_map(oca.ca_ra.ra_reg, oca.ca_ra.ra_len);
    516  1.14        pk 
    517  1.14        pk 	config_attach(parent, cf, &oca, busprint);
    518  1.14        pk 	return 1;
    519  1.22        pk #else
    520  1.22        pk 	return 0;
    521  1.22        pk #endif
    522  1.14        pk }
    523   1.4   deraadt 
    524  1.14        pk int
    525  1.14        pk obio_scan(parent, child, args)
    526  1.14        pk 	struct device *parent;
    527  1.28        pk 	struct cfdata *child;
    528  1.28        pk 	void *args;
    529  1.14        pk {
    530  1.14        pk 	return busattach(parent, child, args, BUS_OBIO);
    531   1.4   deraadt }
    532   1.5   deraadt 
    533  1.14        pk int
    534  1.14        pk vmes_scan(parent, child, args)
    535  1.14        pk 	struct device *parent;
    536  1.28        pk 	struct cfdata *child;
    537  1.28        pk 	void *args;
    538  1.14        pk {
    539  1.14        pk 	return busattach(parent, child, args, BUS_VME16);
    540  1.14        pk }
    541  1.14        pk 
    542  1.14        pk int
    543  1.14        pk vmel_scan(parent, child, args)
    544  1.14        pk 	struct device *parent;
    545  1.28        pk 	struct cfdata *child;
    546  1.28        pk 	void *args;
    547  1.14        pk {
    548  1.14        pk 	return busattach(parent, child, args, BUS_VME32);
    549   1.4   deraadt }
    550   1.4   deraadt 
    551   1.5   deraadt int pil_to_vme[] = {
    552   1.5   deraadt 	-1,	/* pil 0 */
    553   1.5   deraadt 	-1,	/* pil 1 */
    554   1.5   deraadt 	1,	/* pil 2 */
    555   1.5   deraadt 	2,	/* pil 3 */
    556   1.5   deraadt 	-1,	/* pil 4 */
    557   1.5   deraadt 	3,	/* pil 5 */
    558   1.5   deraadt 	-1,	/* pil 6 */
    559   1.5   deraadt 	4,	/* pil 7 */
    560   1.5   deraadt 	-1,	/* pil 8 */
    561   1.5   deraadt 	5,	/* pil 9 */
    562   1.5   deraadt 	-1,	/* pil 10 */
    563   1.5   deraadt 	6,	/* pil 11 */
    564   1.5   deraadt 	-1,	/* pil 12 */
    565   1.5   deraadt 	7,	/* pil 13 */
    566   1.5   deraadt 	-1,	/* pil 14 */
    567   1.5   deraadt 	-1,	/* pil 15 */
    568   1.5   deraadt };
    569   1.5   deraadt 
    570   1.5   deraadt int
    571   1.5   deraadt vmeintr(arg)
    572   1.5   deraadt 	void *arg;
    573   1.5   deraadt {
    574  1.32        pk 	int pil = (int)arg, level, vec;
    575   1.5   deraadt 	struct intrhand *ih;
    576   1.5   deraadt 	int i = 0;
    577   1.5   deraadt 
    578  1.32        pk 	level = (pil_to_vme[pil] << 1) | 1;
    579  1.32        pk 
    580  1.32        pk 	if (CPU_ISSUN4) {
    581  1.32        pk 		vec = ldcontrolb((caddr_t)(AC_VMEINTVEC | level));
    582  1.32        pk 	} else if (CPU_ISSUN4M) {
    583  1.32        pk 		vec = vmebus_sc->sc_vec->vmebusvec[level];
    584  1.32        pk 	} else
    585  1.22        pk 		panic("vme: spurious interrupt");
    586  1.22        pk 
    587   1.6   deraadt 	if (vec == -1) {
    588  1.27  christos 		printf("vme: spurious interrupt\n");
    589   1.6   deraadt 		return 0;
    590   1.6   deraadt 	}
    591   1.5   deraadt 
    592   1.5   deraadt 	for (ih = vmeints[vec]; ih; ih = ih->ih_next)
    593   1.5   deraadt 		if (ih->ih_fun)
    594   1.5   deraadt 			i += (ih->ih_fun)(ih->ih_arg);
    595   1.5   deraadt 	return (i);
    596   1.5   deraadt }
    597   1.5   deraadt 
    598   1.5   deraadt void
    599   1.5   deraadt vmeintr_establish(vec, level, ih)
    600   1.5   deraadt 	int vec, level;
    601   1.5   deraadt 	struct intrhand *ih;
    602  1.22        pk {
    603   1.5   deraadt 	struct intrhand *ihs;
    604   1.5   deraadt 
    605  1.22        pk 	if (!CPU_ISSUN4) {
    606  1.22        pk 		panic("vmeintr_establish: not supported on cpu-type %d",
    607  1.22        pk 		      cputyp);
    608  1.22        pk 	}
    609  1.22        pk 
    610   1.8   deraadt 	if (vec == -1)
    611   1.8   deraadt 		panic("vmeintr_establish: uninitialized vec\n");
    612   1.8   deraadt 
    613   1.5   deraadt 	if (vmeints[vec] == NULL)
    614   1.5   deraadt 		vmeints[vec] = ih;
    615   1.5   deraadt 	else {
    616   1.5   deraadt 		for (ihs = vmeints[vec]; ihs->ih_next; ihs = ihs->ih_next)
    617   1.5   deraadt 			;
    618   1.5   deraadt 		ihs->ih_next = ih;
    619   1.5   deraadt 	}
    620   1.5   deraadt 
    621   1.5   deraadt 	/* ensure the interrupt subsystem will call us at this level */
    622   1.5   deraadt 	for (ihs = intrhand[level]; ihs; ihs = ihs->ih_next)
    623   1.5   deraadt 		if (ihs->ih_fun == vmeintr)
    624   1.5   deraadt 			return;
    625   1.5   deraadt 
    626   1.5   deraadt 	ihs = (struct intrhand *)malloc(sizeof(struct intrhand),
    627   1.5   deraadt 	    M_TEMP, M_NOWAIT);
    628   1.5   deraadt 	if (ihs == NULL)
    629   1.5   deraadt 		panic("vme_addirq");
    630   1.5   deraadt 	bzero(ihs, sizeof *ihs);
    631   1.5   deraadt 	ihs->ih_fun = vmeintr;
    632   1.5   deraadt 	ihs->ih_arg = (void *)level;
    633   1.5   deraadt 	intr_establish(level, ihs);
    634   1.5   deraadt }
    635   1.4   deraadt 
    636   1.2   deraadt #define	getpte(va)		lda(va, ASI_PTE)
    637   1.2   deraadt 
    638   1.2   deraadt /*
    639   1.2   deraadt  * If we can find a mapping that was established by the rom, use it.
    640   1.2   deraadt  * Else, create a new mapping.
    641   1.2   deraadt  */
    642   1.2   deraadt void *
    643  1.34        pk bus_map(pa, len)
    644  1.17        pk 	struct rom_reg *pa;
    645   1.2   deraadt 	int len;
    646   1.2   deraadt {
    647   1.2   deraadt 
    648  1.32        pk 	if (CPU_ISSUN4 && len <= NBPG) {
    649  1.32        pk 		u_long	pf = (u_long)(pa->rr_paddr) >> PGSHIFT;
    650  1.34        pk 		int pgtype = PMAP_T2PTE_4(pa->rr_iospace);
    651  1.32        pk 		u_long	va, pte;
    652  1.32        pk 
    653   1.3   deraadt 		for (va = OLDMON_STARTVADDR; va < OLDMON_ENDVADDR; va += NBPG) {
    654   1.3   deraadt 			pte = getpte(va);
    655   1.4   deraadt 			if ((pte & PG_V) != 0 && (pte & PG_TYPE) == pgtype &&
    656   1.3   deraadt 			    (pte & PG_PFNUM) == pf)
    657  1.19     chuck 				return ((void *)
    658  1.19     chuck 				    (va | ((u_long)pa->rr_paddr & PGOFSET)) );
    659  1.19     chuck 					/* note: preserve page offset */
    660   1.3   deraadt 		}
    661   1.2   deraadt 	}
    662  1.32        pk 
    663  1.34        pk 	return mapiodev(pa, 0, len);
    664   1.2   deraadt }
    665   1.2   deraadt 
    666   1.2   deraadt void
    667   1.4   deraadt bus_untmp()
    668   1.2   deraadt {
    669  1.13   mycroft 	pmap_remove(pmap_kernel(), TMPMAP_VA, TMPMAP_VA+NBPG);
    670   1.1   deraadt }
    671