Home | History | Annotate | Line # | Download | only in vsa
vsbus.c revision 1.16
      1 /*	$NetBSD: vsbus.c,v 1.16 1999/03/13 15:16:48 ragge Exp $ */
      2 /*
      3  * Copyright (c) 1996 Ludd, University of Lule}, Sweden.
      4  * All rights reserved.
      5  *
      6  * This code is derived from software contributed to Ludd by Bertram Barth.
      7  *
      8  * Redistribution and use in source and binary forms, with or without
      9  * modification, are permitted provided that the following conditions
     10  * are met:
     11  * 1. Redistributions of source code must retain the above copyright
     12  *    notice, this list of conditions and the following disclaimer.
     13  * 2. Redistributions in binary form must reproduce the above copyright
     14  *    notice, this list of conditions and the following disclaimer in the
     15  *    documentation and/or other materials provided with the distribution.
     16  * 3. All advertising materials mentioning features or use of this software
     17  *    must display the following acknowledgement:
     18  *	This product includes software developed at Ludd, University of
     19  *	Lule}, Sweden and its contributors.
     20  * 4. The name of the author may not be used to endorse or promote products
     21  *    derived from this software without specific prior written permission
     22  *
     23  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     24  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     25  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     26  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     27  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     28  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     29  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     30  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     31  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     32  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     33  */
     34 
     35 #include <sys/param.h>
     36 #include <sys/systm.h>
     37 #include <sys/buf.h>
     38 #include <sys/conf.h>
     39 #include <sys/file.h>
     40 #include <sys/ioctl.h>
     41 #include <sys/proc.h>
     42 #include <sys/user.h>
     43 #include <sys/map.h>
     44 #include <sys/device.h>
     45 #include <sys/dkstat.h>
     46 #include <sys/disklabel.h>
     47 #include <sys/syslog.h>
     48 #include <sys/stat.h>
     49 
     50 #include <machine/pte.h>
     51 #include <machine/sid.h>
     52 #include <machine/scb.h>
     53 #include <machine/cpu.h>
     54 #include <machine/trap.h>
     55 #include <machine/nexus.h>
     56 
     57 #include <machine/uvax.h>
     58 #include <machine/ka410.h>
     59 #include <machine/ka420.h>
     60 #include <machine/ka43.h>
     61 
     62 #include <machine/vsbus.h>
     63 
     64 #include "ioconf.h"
     65 
     66 int	vsbus_match	__P((struct device *, struct cfdata *, void *));
     67 void	vsbus_attach	__P((struct device *, struct device *, void *));
     68 int	vsbus_print	__P((void *, const char *));
     69 int	vsbus_search	__P((struct device *, struct cfdata *, void *));
     70 
     71 void	ka410_attach	__P((struct device *, struct device *, void *));
     72 void	ka43_attach	__P((struct device *, struct device *, void *));
     73 
     74 struct	vsbus_softc {
     75 	struct	device sc_dev;
     76 	volatile struct vs_cpu *sc_cpu;
     77 	u_char	sc_mask;	/* Interrupts to enable after autoconf */
     78 };
     79 
     80 struct	cfattach vsbus_ca = {
     81 	sizeof(struct vsbus_softc), vsbus_match, vsbus_attach
     82 };
     83 
     84 int
     85 vsbus_print(aux, name)
     86 	void *aux;
     87 	const char *name;
     88 {
     89 	struct vsbus_attach_args *va = aux;
     90 
     91 	printf(" csr 0x%lx vec %o ipl %x maskbit %x", va->va_paddr,
     92 	    va->va_cvec & 511, va->va_br, va->va_maskno - 1);
     93 	return(UNCONF);
     94 }
     95 
     96 int
     97 vsbus_match(parent, cf, aux)
     98 	struct	device	*parent;
     99 	struct cfdata	*cf;
    100 	void	*aux;
    101 {
    102 	struct bp_conf *bp = aux;
    103 
    104 	if (strcmp(bp->type, "vsbus"))
    105 		return 0;
    106 	/*
    107 	 * on machines which can have it, the vsbus is always there
    108 	 */
    109 	if ((vax_bustype & VAX_VSBUS) == 0)
    110 		return (0);
    111 
    112 	return (1);
    113 }
    114 
    115 void
    116 vsbus_attach(parent, self, aux)
    117 	struct	device	*parent, *self;
    118 	void	*aux;
    119 {
    120 	struct	vsbus_softc *sc = (void *)self;
    121 
    122 	printf("\n");
    123 
    124 	sc->sc_cpu = (void *)vax_map_physmem(VS_REGS, 1);
    125 
    126 	/*
    127 	 * First: find which interrupts we won't care about.
    128 	 * There are interrupts that interrupt on a periodic basic
    129 	 * that we don't want to interfere with the rest of the
    130 	 * interrupt probing.
    131 	 */
    132 	sc->sc_cpu->vc_intmsk = 0;
    133 	sc->sc_cpu->vc_intclr = 0xff;
    134 	DELAY(1000000); /* Wait a second */
    135 	sc->sc_mask = sc->sc_cpu->vc_intreq;
    136 	printf("%s: interrupt mask %x\n", self->dv_xname, sc->sc_mask);
    137 	/*
    138 	 * now check for all possible devices on this "bus"
    139 	 */
    140 	config_search(vsbus_search, self, NULL);
    141 
    142 	/* Autoconfig finished, enable interrupts */
    143 	sc->sc_cpu->vc_intmsk = ~sc->sc_mask;
    144 }
    145 
    146 int
    147 vsbus_search(parent, cf, aux)
    148 	struct device *parent;
    149 	struct cfdata *cf;
    150 	void *aux;
    151 {
    152 	struct	vsbus_softc *sc = (void *)parent;
    153 	struct	vsbus_attach_args va;
    154 	int i, vec, br;
    155 	u_char c;
    156 
    157 	va.va_paddr = cf->cf_loc[0];
    158 	va.va_addr = vax_map_physmem(va.va_paddr, 1);
    159 
    160 	sc->sc_cpu->vc_intmsk = 0;
    161 	sc->sc_cpu->vc_intclr = 0xff;
    162 	scb_vecref(0, 0); /* Clear vector ref */
    163 
    164 	i = (*cf->cf_attach->ca_match) (parent, cf, &va);
    165 	vax_unmap_physmem(va.va_addr, 1);
    166 	c = sc->sc_cpu->vc_intreq & ~sc->sc_mask;
    167 	if (i > 10)
    168 		c = sc->sc_mask; /* Fooling interrupt */
    169 	if (c == 0 || i == 0)
    170 		goto forgetit;
    171 
    172 	sc->sc_cpu->vc_intmsk = c;
    173 	DELAY(100);
    174 	sc->sc_cpu->vc_intmsk = 0;
    175 	va.va_maskno = ffs((u_int)c);
    176 	i = scb_vecref(&vec, &br);
    177 	if (i == 0)
    178 		goto fail;
    179 	if (vec == 0)
    180 		goto fail;
    181 
    182 	scb_vecalloc(vec, va.va_ivec, cf->cf_unit, SCB_ISTACK);
    183 	va.va_br = br;
    184 	va.va_cvec = vec;
    185 
    186 	config_attach(parent, cf, &va, vsbus_print);
    187 	return 0;
    188 
    189 fail:
    190 	printf("%s%d at %s csr %x %s\n",
    191 	    cf->cf_driver->cd_name, cf->cf_unit, parent->dv_xname,
    192 	    cf->cf_loc[0], (i ? "zero vector" : "didn't interrupt"));
    193 forgetit:
    194 	return 0;
    195 }
    196 
    197 /*
    198  * Sets a new interrupt mask. Returns the old one.
    199  * Works like spl functions.
    200  */
    201 unsigned char
    202 vsbus_setmask(mask)
    203 	unsigned char mask;
    204 {
    205 	struct vsbus_softc *sc = vsbus_cd.cd_devs[0];
    206 	unsigned char ch;
    207 
    208 	ch = sc->sc_cpu->vc_intmsk;
    209 	sc->sc_cpu->vc_intmsk = mask;
    210 	return ch;
    211 }
    212 
    213 /*
    214  * Clears the interrupts in mask.
    215  */
    216 void
    217 vsbus_clrintr(mask)
    218 	unsigned char mask;
    219 {
    220 	struct vsbus_softc *sc = vsbus_cd.cd_devs[0];
    221 
    222 	sc->sc_cpu->vc_intclr = mask;
    223 }
    224 
    225 #ifdef notyet
    226 /*
    227  * Allocate/free DMA pages and other bus resources.
    228  * VS2000: All DMA and register access must be exclusive.
    229  * VS3100: DMA area may be accessed by anyone anytime.
    230  *   MFM/SCSI: Don't touch reg's while DMA is active.
    231  *   SCSI/SCSI: Legal to touch any register anytime.
    232  */
    233 
    234 
    235 #endif
    236