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