Home | History | Annotate | Line # | Download | only in dev
obio.c revision 1.29
      1  1.29        pk /*	$NetBSD: obio.c,v 1.29 1996/12/10 23:24:56 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.22        pk #include <sparc/dev/sbusvar.h>
     54   1.1   deraadt 
     55   1.4   deraadt struct bus_softc {
     56  1.22        pk 	union {
     57  1.22        pk 		struct	device scu_dev;		/* base device */
     58  1.22        pk 		struct	sbus_softc scu_sbus;	/* obio is another sbus slot */
     59  1.22        pk 	} bu;
     60  1.22        pk #define sc_dev	bu.scu_dev
     61   1.1   deraadt };
     62   1.1   deraadt 
     63   1.1   deraadt /* autoconfiguration driver */
     64  1.28        pk static int	busmatch __P((struct device *, struct cfdata *, void *));
     65   1.9   deraadt static void	obioattach __P((struct device *, struct device *, void *));
     66   1.9   deraadt static void	vmesattach __P((struct device *, struct device *, void *));
     67   1.9   deraadt static void	vmelattach __P((struct device *, struct device *, void *));
     68  1.22        pk 
     69  1.25       cgd int		busprint __P((void *, const char *));
     70  1.28        pk static int	busattach __P((struct device *, struct cfdata *, void *, int));
     71  1.17        pk void *		bus_map __P((struct rom_reg *, int, int));
     72  1.28        pk int		obio_scan __P((struct device *, struct cfdata *, void *));
     73  1.28        pk int 		vmes_scan __P((struct device *, struct cfdata *, void *));
     74  1.28        pk int 		vmel_scan __P((struct device *, struct cfdata *, void *));
     75  1.20  christos int 		vmeintr __P((void *));
     76   1.4   deraadt 
     77  1.21   thorpej struct cfattach obio_ca = {
     78  1.21   thorpej 	sizeof(struct bus_softc), busmatch, obioattach
     79   1.4   deraadt };
     80  1.21   thorpej 
     81  1.21   thorpej struct cfdriver obio_cd = {
     82  1.21   thorpej 	NULL, "obio", DV_DULL
     83  1.21   thorpej };
     84  1.21   thorpej 
     85  1.21   thorpej struct cfattach vmel_ca = {
     86  1.21   thorpej 	sizeof(struct bus_softc), busmatch, vmelattach
     87  1.21   thorpej };
     88  1.21   thorpej 
     89  1.21   thorpej struct cfdriver vmel_cd = {
     90  1.21   thorpej 	NULL, "vmel", DV_DULL
     91  1.21   thorpej };
     92  1.21   thorpej 
     93  1.21   thorpej struct cfattach vmes_ca = {
     94  1.21   thorpej 	sizeof(struct bus_softc), busmatch, vmesattach
     95   1.1   deraadt };
     96  1.21   thorpej 
     97  1.21   thorpej struct cfdriver vmes_cd = {
     98  1.21   thorpej 	NULL, "vmes", DV_DULL
     99   1.4   deraadt };
    100  1.22        pk 
    101  1.22        pk struct intrhand **vmeints;
    102   1.4   deraadt 
    103   1.2   deraadt 
    104   1.1   deraadt int
    105  1.28        pk busmatch(parent, cf, aux)
    106   1.1   deraadt 	struct device *parent;
    107  1.28        pk 	struct cfdata *cf;
    108  1.28        pk 	void *aux;
    109   1.1   deraadt {
    110   1.3   deraadt 	register struct confargs *ca = aux;
    111   1.3   deraadt 	register struct romaux *ra = &ca->ca_ra;
    112   1.3   deraadt 
    113  1.22        pk 	if (CPU_ISSUN4M)
    114  1.22        pk 		return (strcmp(cf->cf_driver->cd_name, ra->ra_name) == 0);
    115  1.22        pk 
    116  1.22        pk 	if (!CPU_ISSUN4)
    117   1.3   deraadt 		return (0);
    118  1.22        pk 
    119   1.3   deraadt 	return (strcmp(cf->cf_driver->cd_name, ra->ra_name) == 0);
    120   1.1   deraadt }
    121   1.1   deraadt 
    122   1.1   deraadt int
    123   1.4   deraadt busprint(args, obio)
    124   1.1   deraadt 	void *args;
    125  1.25       cgd 	const char *obio;
    126   1.1   deraadt {
    127   1.2   deraadt 	register struct confargs *ca = args;
    128   1.2   deraadt 
    129   1.2   deraadt 	if (ca->ca_ra.ra_name == NULL)
    130   1.2   deraadt 		ca->ca_ra.ra_name = "<unknown>";
    131  1.22        pk 
    132   1.2   deraadt 	if (obio)
    133  1.27  christos 		printf("[%s at %s]", ca->ca_ra.ra_name, obio);
    134  1.22        pk 
    135  1.27  christos 	printf(" addr %p", ca->ca_ra.ra_paddr);
    136  1.22        pk 
    137  1.22        pk 	if (CPU_ISSUN4 && ca->ca_ra.ra_intr[0].int_vec != -1)
    138  1.27  christos 		printf(" vec 0x%x", ca->ca_ra.ra_intr[0].int_vec);
    139  1.22        pk 
    140   1.1   deraadt 	return (UNCONF);
    141   1.1   deraadt }
    142   1.1   deraadt 
    143  1.14        pk 
    144  1.22        pk void
    145  1.22        pk obioattach(parent, self, args)
    146  1.22        pk 	struct device *parent, *self;
    147  1.22        pk 	void *args;
    148  1.22        pk {
    149  1.22        pk #if defined(SUN4M)
    150  1.22        pk 	register struct bus_softc *sc = (struct bus_softc *)self;
    151  1.22        pk 	struct confargs oca, *ca = args;
    152  1.22        pk 	register struct romaux *ra = &ca->ca_ra;
    153  1.22        pk 	register int node0, node;
    154  1.22        pk 	register char *name;
    155  1.22        pk 	register const char *sp;
    156  1.22        pk 	const char *const *ssp;
    157  1.22        pk 	extern int autoconf_nzs;
    158  1.22        pk 
    159  1.22        pk 	static const char *const special4m[] = {
    160  1.22        pk 		/* find these first */
    161  1.22        pk 		"eeprom",
    162  1.22        pk 		"counter",
    163  1.29        pk #if 0 /* Not all sun4m's have an `auxio' */
    164  1.22        pk 		"auxio",
    165  1.29        pk #endif
    166  1.22        pk 		"",
    167  1.22        pk 		/* place device to ignore here */
    168  1.22        pk 		"interrupt",
    169  1.22        pk 		NULL
    170  1.22        pk 	};
    171  1.22        pk #endif
    172  1.22        pk 
    173  1.22        pk 	if (CPU_ISSUN4) {
    174  1.22        pk 		if (self->dv_unit > 0) {
    175  1.27  christos 			printf(" unsupported\n");
    176  1.22        pk 			return;
    177  1.22        pk 		}
    178  1.27  christos 		printf("\n");
    179  1.22        pk 
    180  1.22        pk 		(void)config_search(obio_scan, self, args);
    181  1.22        pk 		bus_untmp();
    182  1.22        pk 	}
    183  1.22        pk 
    184  1.22        pk #if defined(SUN4M)
    185  1.22        pk 	if (!CPU_ISSUN4M)
    186  1.22        pk 		return;
    187  1.22        pk 
    188  1.22        pk 	/*
    189  1.22        pk 	 * There is only one obio bus (it is in fact one of the Sbus slots)
    190  1.22        pk 	 * How about VME?
    191  1.22        pk 	 */
    192  1.22        pk 	if (sc->sc_dev.dv_unit > 0) {
    193  1.27  christos 		printf(" unsupported\n");
    194  1.22        pk 		return;
    195  1.22        pk 	}
    196  1.22        pk 
    197  1.27  christos 	printf("\n");
    198  1.22        pk 
    199  1.22        pk 	if (ra->ra_bp != NULL && strcmp(ra->ra_bp->name, "obio") == 0)
    200  1.22        pk 		oca.ca_ra.ra_bp = ra->ra_bp + 1;
    201  1.22        pk 	else
    202  1.22        pk 		oca.ca_ra.ra_bp = NULL;
    203  1.22        pk 
    204  1.22        pk 	sc->bu.scu_sbus.sc_range = ra->ra_range;
    205  1.22        pk 	sc->bu.scu_sbus.sc_nrange = ra->ra_nrange;
    206  1.22        pk 
    207  1.22        pk 	/*
    208  1.22        pk 	 * Loop through ROM children, fixing any relative addresses
    209  1.22        pk 	 * and then configuring each device.
    210  1.22        pk 	 * We first do the crucial ones, such as eeprom, etc.
    211  1.22        pk 	 */
    212  1.22        pk 	node0 = firstchild(ra->ra_node);
    213  1.22        pk 	for (ssp = special4m ; *(sp = *ssp) != 0; ssp++) {
    214  1.22        pk 		if ((node = findnode(node0, sp)) == 0) {
    215  1.27  christos 			printf("could not find %s amongst obio devices\n", sp);
    216  1.22        pk 			panic(sp);
    217  1.22        pk 		}
    218  1.22        pk 		if (!romprop(&oca.ca_ra, sp, node))
    219  1.22        pk 			continue;
    220  1.22        pk 
    221  1.22        pk 		sbus_translate(self, &oca);
    222  1.22        pk 		oca.ca_bustype = BUS_OBIO;
    223  1.22        pk 		(void) config_found(&sc->sc_dev, (void *)&oca, busprint);
    224  1.22        pk 	}
    225  1.22        pk 
    226  1.22        pk 	for (node = node0; node; node = nextsibling(node)) {
    227  1.22        pk 		name = getpropstring(node, "name");
    228  1.22        pk 		for (ssp = special4m ; (sp = *ssp) != NULL; ssp++)
    229  1.22        pk 			if (strcmp(name, sp) == 0)
    230  1.22        pk 				break;
    231  1.22        pk 
    232  1.22        pk 		if (sp != NULL || !romprop(&oca.ca_ra, name, node))
    233  1.22        pk 			continue;
    234  1.22        pk 
    235  1.22        pk 		if (strcmp(name, "zs") == 0)
    236  1.22        pk 			/* XXX - see autoconf.c for this hack */
    237  1.22        pk 			autoconf_nzs++;
    238  1.22        pk 
    239  1.22        pk 		/* Translate into parent address spaces */
    240  1.22        pk 		sbus_translate(self, &oca);
    241  1.22        pk 		oca.ca_bustype = BUS_OBIO;
    242  1.22        pk 		(void) config_found(&sc->sc_dev, (void *)&oca, busprint);
    243  1.22        pk 	}
    244  1.22        pk #endif
    245  1.22        pk }
    246  1.22        pk 
    247  1.22        pk void
    248  1.22        pk vmesattach(parent, self, args)
    249  1.22        pk 	struct device *parent, *self;
    250  1.22        pk 	void *args;
    251  1.22        pk {
    252  1.22        pk 	if (CPU_ISSUN4M || self->dv_unit > 0) {
    253  1.27  christos 		printf(" unsupported\n");
    254  1.22        pk 		return;
    255  1.22        pk 	}
    256  1.27  christos 	printf("\n");
    257  1.22        pk 
    258  1.22        pk 	if (vmeints == NULL) {
    259  1.22        pk 		vmeints = (struct intrhand **)malloc(256 *
    260  1.22        pk 		    sizeof(struct intrhand *), M_TEMP, M_NOWAIT);
    261  1.22        pk 		bzero(vmeints, 256 * sizeof(struct intrhand *));
    262  1.22        pk 	}
    263  1.22        pk 	(void)config_search(vmes_scan, self, args);
    264  1.22        pk 	bus_untmp();
    265  1.22        pk }
    266  1.22        pk 
    267  1.22        pk void
    268  1.22        pk vmelattach(parent, self, args)
    269  1.22        pk 	struct device *parent, *self;
    270  1.22        pk 	void *args;
    271  1.22        pk {
    272  1.22        pk 	if (CPU_ISSUN4M || self->dv_unit > 0) {
    273  1.27  christos 		printf(" unsupported\n");
    274  1.22        pk 		return;
    275  1.22        pk 	}
    276  1.27  christos 	printf("\n");
    277  1.22        pk 
    278  1.22        pk 	if (vmeints == NULL) {
    279  1.22        pk 		vmeints = (struct intrhand **)malloc(256 *
    280  1.22        pk 		    sizeof(struct intrhand *), M_TEMP, M_NOWAIT);
    281  1.22        pk 		bzero(vmeints, 256 * sizeof(struct intrhand *));
    282  1.22        pk 	}
    283  1.22        pk 	(void)config_search(vmel_scan, self, args);
    284  1.22        pk 	bus_untmp();
    285  1.22        pk }
    286  1.22        pk 
    287  1.14        pk int
    288  1.28        pk busattach(parent, cf, args, bustype)
    289  1.14        pk 	struct device *parent;
    290  1.28        pk 	struct cfdata *cf;
    291  1.28        pk 	void *args;
    292   1.4   deraadt 	int bustype;
    293   1.1   deraadt {
    294  1.22        pk #if defined(SUN4)
    295   1.3   deraadt 	register struct confargs *ca = args;
    296   1.3   deraadt 	struct confargs oca;
    297   1.4   deraadt 	caddr_t tmp;
    298   1.1   deraadt 
    299  1.22        pk 	if (bustype == BUS_OBIO && CPU_ISSUN4) {
    300  1.23     chuck 
    301  1.23     chuck 		/*
    302  1.23     chuck 		 * avoid sun4m entries which don't have valid PA's.
    303  1.23     chuck 		 * no point in even probing them.
    304  1.23     chuck 		 */
    305  1.23     chuck 		if (cf->cf_loc[0] == -1) return 0;
    306  1.23     chuck 
    307  1.14        pk 		/*
    308  1.14        pk 		 * On the 4/100 obio addresses must be mapped at
    309  1.14        pk 		 * 0x0YYYYYYY, but alias higher up (we avoid the
    310  1.14        pk 		 * alias condition because it causes pmap difficulties)
    311  1.14        pk 		 * XXX: We also assume that 4/[23]00 obio addresses
    312  1.14        pk 		 * must be 0xZYYYYYYY, where (Z != 0)
    313  1.14        pk 		 */
    314  1.22        pk 		if (cpumod == SUN4_100 && (cf->cf_loc[0] & 0xf0000000))
    315  1.14        pk 			return 0;
    316  1.22        pk 		if (cpumod != SUN4_100 && !(cf->cf_loc[0] & 0xf0000000))
    317  1.14        pk 			return 0;
    318  1.14        pk 	}
    319  1.14        pk 
    320  1.14        pk 	oca.ca_ra.ra_iospace = -1;
    321  1.14        pk 	oca.ca_ra.ra_paddr = (void *)cf->cf_loc[0];
    322  1.14        pk 	oca.ca_ra.ra_len = 0;
    323  1.14        pk 	oca.ca_ra.ra_nreg = 1;
    324  1.14        pk 	if (oca.ca_ra.ra_paddr)
    325  1.24       mrg 		tmp = (caddr_t)bus_tmp(oca.ca_ra.ra_paddr,
    326  1.14        pk 		    bustype);
    327  1.24       mrg 	else
    328  1.24       mrg 		tmp = NULL;
    329  1.14        pk 	oca.ca_ra.ra_vaddr = tmp;
    330  1.14        pk 	oca.ca_ra.ra_intr[0].int_pri = cf->cf_loc[1];
    331  1.14        pk 	if (bustype == BUS_VME16 || bustype == BUS_VME32)
    332  1.14        pk 		oca.ca_ra.ra_intr[0].int_vec = cf->cf_loc[2];
    333  1.14        pk 	else
    334  1.14        pk 		oca.ca_ra.ra_intr[0].int_vec = -1;
    335  1.14        pk 	oca.ca_ra.ra_nintr = 1;
    336  1.14        pk 	oca.ca_ra.ra_name = cf->cf_driver->cd_name;
    337  1.15        pk 	if (ca->ca_ra.ra_bp != NULL &&
    338  1.16        pk 	  ((bustype == BUS_VME16 && strcmp(ca->ca_ra.ra_bp->name,"vmes") ==0) ||
    339  1.16        pk 	   (bustype == BUS_VME32 && strcmp(ca->ca_ra.ra_bp->name,"vmel") ==0) ||
    340  1.16        pk 	   (bustype == BUS_OBIO && strcmp(ca->ca_ra.ra_bp->name,"obio") == 0)))
    341  1.15        pk 		oca.ca_ra.ra_bp = ca->ca_ra.ra_bp + 1;
    342  1.15        pk 	else
    343  1.15        pk 		oca.ca_ra.ra_bp = NULL;
    344  1.14        pk 	oca.ca_bustype = bustype;
    345  1.14        pk 
    346  1.21   thorpej 	if ((*cf->cf_attach->ca_match)(parent, cf, &oca) == 0)
    347  1.14        pk 		return 0;
    348  1.14        pk 
    349  1.14        pk 	/*
    350  1.22        pk 	 * check if XXmatch routine replaced the temporary mapping with
    351  1.19     chuck 	 * a real mapping.   If not, then make sure we don't pass the
    352  1.19     chuck 	 * tmp mapping to the attach routine.
    353  1.14        pk 	 */
    354  1.19     chuck 	if (oca.ca_ra.ra_vaddr == tmp)
    355  1.19     chuck 		oca.ca_ra.ra_vaddr = NULL; /* wipe out tmp address */
    356  1.14        pk 	/*
    357  1.22        pk 	 * the match routine will set "ra_len" if it wants us to
    358  1.19     chuck 	 * establish a mapping for it.
    359  1.14        pk 	 * (which won't be seen on future XXmatch calls,
    360  1.14        pk 	 * so not as useful as it seems.)
    361  1.14        pk 	 */
    362  1.22        pk 	if (oca.ca_ra.ra_len)
    363  1.14        pk 		oca.ca_ra.ra_vaddr =
    364  1.17        pk 		    bus_map(oca.ca_ra.ra_reg,
    365  1.14        pk 		    oca.ca_ra.ra_len, oca.ca_bustype);
    366  1.14        pk 
    367  1.14        pk 	config_attach(parent, cf, &oca, busprint);
    368  1.14        pk 	return 1;
    369  1.22        pk #else
    370  1.22        pk 	return 0;
    371  1.22        pk #endif
    372  1.14        pk }
    373   1.4   deraadt 
    374  1.14        pk int
    375  1.14        pk obio_scan(parent, child, args)
    376  1.14        pk 	struct device *parent;
    377  1.28        pk 	struct cfdata *child;
    378  1.28        pk 	void *args;
    379  1.14        pk {
    380  1.14        pk 	return busattach(parent, child, args, BUS_OBIO);
    381   1.4   deraadt }
    382   1.5   deraadt 
    383  1.14        pk int
    384  1.14        pk vmes_scan(parent, child, args)
    385  1.14        pk 	struct device *parent;
    386  1.28        pk 	struct cfdata *child;
    387  1.28        pk 	void *args;
    388  1.14        pk {
    389  1.14        pk 	return busattach(parent, child, args, BUS_VME16);
    390  1.14        pk }
    391  1.14        pk 
    392  1.14        pk int
    393  1.14        pk vmel_scan(parent, child, args)
    394  1.14        pk 	struct device *parent;
    395  1.28        pk 	struct cfdata *child;
    396  1.28        pk 	void *args;
    397  1.14        pk {
    398  1.14        pk 	return busattach(parent, child, args, BUS_VME32);
    399   1.4   deraadt }
    400   1.4   deraadt 
    401   1.5   deraadt int pil_to_vme[] = {
    402   1.5   deraadt 	-1,	/* pil 0 */
    403   1.5   deraadt 	-1,	/* pil 1 */
    404   1.5   deraadt 	1,	/* pil 2 */
    405   1.5   deraadt 	2,	/* pil 3 */
    406   1.5   deraadt 	-1,	/* pil 4 */
    407   1.5   deraadt 	3,	/* pil 5 */
    408   1.5   deraadt 	-1,	/* pil 6 */
    409   1.5   deraadt 	4,	/* pil 7 */
    410   1.5   deraadt 	-1,	/* pil 8 */
    411   1.5   deraadt 	5,	/* pil 9 */
    412   1.5   deraadt 	-1,	/* pil 10 */
    413   1.5   deraadt 	6,	/* pil 11 */
    414   1.5   deraadt 	-1,	/* pil 12 */
    415   1.5   deraadt 	7,	/* pil 13 */
    416   1.5   deraadt 	-1,	/* pil 14 */
    417   1.5   deraadt 	-1,	/* pil 15 */
    418   1.5   deraadt };
    419   1.5   deraadt 
    420   1.5   deraadt int
    421   1.5   deraadt vmeintr(arg)
    422   1.5   deraadt 	void *arg;
    423   1.5   deraadt {
    424   1.5   deraadt 	int level = (int)arg, vec;
    425   1.5   deraadt 	struct intrhand *ih;
    426   1.5   deraadt 	int i = 0;
    427   1.5   deraadt 
    428  1.22        pk #ifdef DIAGNOSTIC
    429  1.22        pk 	if (!CPU_ISSUN4) {
    430  1.22        pk 		panic("vme: spurious interrupt");
    431  1.22        pk 	}
    432  1.22        pk #endif
    433  1.22        pk 
    434  1.20  christos 	vec = ldcontrolb((caddr_t)
    435  1.20  christos 	    (AC_VMEINTVEC | (pil_to_vme[level] << 1) | 1));
    436   1.6   deraadt 	if (vec == -1) {
    437  1.27  christos 		printf("vme: spurious interrupt\n");
    438   1.6   deraadt 		return 0;
    439   1.6   deraadt 	}
    440   1.5   deraadt 
    441   1.5   deraadt 	for (ih = vmeints[vec]; ih; ih = ih->ih_next)
    442   1.5   deraadt 		if (ih->ih_fun)
    443   1.5   deraadt 			i += (ih->ih_fun)(ih->ih_arg);
    444   1.5   deraadt 	return (i);
    445   1.5   deraadt }
    446   1.5   deraadt 
    447   1.5   deraadt void
    448   1.5   deraadt vmeintr_establish(vec, level, ih)
    449   1.5   deraadt 	int vec, level;
    450   1.5   deraadt 	struct intrhand *ih;
    451  1.22        pk {
    452   1.5   deraadt 	struct intrhand *ihs;
    453   1.5   deraadt 
    454  1.22        pk 	if (!CPU_ISSUN4) {
    455  1.22        pk 		panic("vmeintr_establish: not supported on cpu-type %d",
    456  1.22        pk 		      cputyp);
    457  1.22        pk 	}
    458  1.22        pk 
    459   1.8   deraadt 	if (vec == -1)
    460   1.8   deraadt 		panic("vmeintr_establish: uninitialized vec\n");
    461   1.8   deraadt 
    462   1.5   deraadt 	if (vmeints[vec] == NULL)
    463   1.5   deraadt 		vmeints[vec] = ih;
    464   1.5   deraadt 	else {
    465   1.5   deraadt 		for (ihs = vmeints[vec]; ihs->ih_next; ihs = ihs->ih_next)
    466   1.5   deraadt 			;
    467   1.5   deraadt 		ihs->ih_next = ih;
    468   1.5   deraadt 	}
    469   1.5   deraadt 
    470   1.5   deraadt 	/* ensure the interrupt subsystem will call us at this level */
    471   1.5   deraadt 	for (ihs = intrhand[level]; ihs; ihs = ihs->ih_next)
    472   1.5   deraadt 		if (ihs->ih_fun == vmeintr)
    473   1.5   deraadt 			return;
    474   1.5   deraadt 
    475   1.5   deraadt 	ihs = (struct intrhand *)malloc(sizeof(struct intrhand),
    476   1.5   deraadt 	    M_TEMP, M_NOWAIT);
    477   1.5   deraadt 	if (ihs == NULL)
    478   1.5   deraadt 		panic("vme_addirq");
    479   1.5   deraadt 	bzero(ihs, sizeof *ihs);
    480   1.5   deraadt 	ihs->ih_fun = vmeintr;
    481   1.5   deraadt 	ihs->ih_arg = (void *)level;
    482   1.5   deraadt 	intr_establish(level, ihs);
    483   1.5   deraadt }
    484   1.4   deraadt 
    485   1.2   deraadt #define	getpte(va)		lda(va, ASI_PTE)
    486   1.2   deraadt 
    487   1.2   deraadt /*
    488   1.2   deraadt  * If we can find a mapping that was established by the rom, use it.
    489   1.2   deraadt  * Else, create a new mapping.
    490   1.2   deraadt  */
    491   1.2   deraadt void *
    492   1.4   deraadt bus_map(pa, len, bustype)
    493  1.17        pk 	struct rom_reg *pa;
    494   1.2   deraadt 	int len;
    495   1.4   deraadt 	int bustype;
    496   1.2   deraadt {
    497  1.18        pk 	u_long	pf = (u_long)(pa->rr_paddr) >> PGSHIFT;
    498   1.2   deraadt 	u_long	va, pte;
    499  1.20  christos 	int pgtype = -1;
    500   1.4   deraadt 
    501   1.4   deraadt 	switch (bt2pmt[bustype]) {
    502   1.4   deraadt 	case PMAP_OBIO:
    503   1.4   deraadt 		pgtype = PG_OBIO;
    504   1.4   deraadt 		break;
    505   1.4   deraadt 	case PMAP_VME32:
    506   1.4   deraadt 		pgtype = PG_VME32;
    507   1.4   deraadt 		break;
    508   1.4   deraadt 	case PMAP_VME16:
    509   1.4   deraadt 		pgtype = PG_VME16;
    510   1.4   deraadt 		break;
    511   1.4   deraadt 	}
    512   1.2   deraadt 
    513   1.3   deraadt 	if (len <= NBPG) {
    514   1.3   deraadt 		for (va = OLDMON_STARTVADDR; va < OLDMON_ENDVADDR; va += NBPG) {
    515   1.3   deraadt 			pte = getpte(va);
    516   1.4   deraadt 			if ((pte & PG_V) != 0 && (pte & PG_TYPE) == pgtype &&
    517   1.3   deraadt 			    (pte & PG_PFNUM) == pf)
    518  1.19     chuck 				return ((void *)
    519  1.19     chuck 				    (va | ((u_long)pa->rr_paddr & PGOFSET)) );
    520  1.19     chuck 					/* note: preserve page offset */
    521   1.3   deraadt 		}
    522   1.2   deraadt 	}
    523  1.17        pk 	return mapiodev(pa, 0, len, bustype);
    524   1.2   deraadt }
    525   1.2   deraadt 
    526   1.2   deraadt void *
    527   1.4   deraadt bus_tmp(pa, bustype)
    528   1.2   deraadt 	void *pa;
    529   1.4   deraadt 	int bustype;
    530   1.2   deraadt {
    531   1.3   deraadt 	vm_offset_t addr = (vm_offset_t)pa & ~PGOFSET;
    532   1.4   deraadt 	int pmtype = bt2pmt[bustype];
    533   1.3   deraadt 
    534  1.13   mycroft 	pmap_enter(pmap_kernel(), TMPMAP_VA,
    535  1.22        pk 		   addr | pmtype | PMAP_NC,
    536  1.22        pk 		   VM_PROT_READ | VM_PROT_WRITE, 1);
    537  1.19     chuck 	return ((void *)(TMPMAP_VA | ((u_long) pa & PGOFSET)) );
    538   1.2   deraadt }
    539   1.2   deraadt 
    540   1.2   deraadt void
    541   1.4   deraadt bus_untmp()
    542   1.2   deraadt {
    543  1.13   mycroft 	pmap_remove(pmap_kernel(), TMPMAP_VA, TMPMAP_VA+NBPG);
    544   1.1   deraadt }
    545