Home | History | Annotate | Line # | Download | only in vsa
vsbus.c revision 1.19
      1 /*	$NetBSD: vsbus.c,v 1.19 1999/08/27 17:45:57 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 #define	_VAX_BUS_DMA_PRIVATE
     51 #include <machine/bus.h>
     52 #include <machine/pte.h>
     53 #include <machine/sid.h>
     54 #include <machine/scb.h>
     55 #include <machine/cpu.h>
     56 #include <machine/trap.h>
     57 #include <machine/nexus.h>
     58 
     59 #include <machine/uvax.h>
     60 #include <machine/ka410.h>
     61 #include <machine/ka420.h>
     62 #include <machine/ka43.h>
     63 
     64 #include <machine/vsbus.h>
     65 
     66 #include "ioconf.h"
     67 
     68 int	vsbus_match	__P((struct device *, struct cfdata *, void *));
     69 void	vsbus_attach	__P((struct device *, struct device *, void *));
     70 int	vsbus_print	__P((void *, const char *));
     71 int	vsbus_search	__P((struct device *, struct cfdata *, void *));
     72 
     73 void	ka410_attach	__P((struct device *, struct device *, void *));
     74 void	ka43_attach	__P((struct device *, struct device *, void *));
     75 
     76 struct vax_bus_dma_tag vsbus_bus_dma_tag = {
     77 	0,
     78 	0,
     79 	0,
     80 	0,
     81 	0,
     82 	0,
     83 	_bus_dmamap_create,
     84 	_bus_dmamap_destroy,
     85 	_bus_dmamap_load,
     86 	_bus_dmamap_load_mbuf,
     87 	_bus_dmamap_load_uio,
     88 	_bus_dmamap_load_raw,
     89 	_bus_dmamap_unload,
     90 	_bus_dmamap_sync,
     91 	_bus_dmamem_alloc,
     92 	_bus_dmamem_free,
     93 	_bus_dmamem_map,
     94 	_bus_dmamem_unmap,
     95 	_bus_dmamem_mmap,
     96 };
     97 
     98 struct	vsbus_softc {
     99 	struct	device sc_dev;
    100 #if 0
    101 	volatile struct vs_cpu *sc_cpu;
    102 #endif
    103 	u_char	*sc_intmsk;	/* Mask register */
    104 	u_char	*sc_intclr;	/* Clear interrupt register */
    105 	u_char	*sc_intreq;	/* Interrupt request register */
    106 	u_char	sc_mask;	/* Interrupts to enable after autoconf */
    107 };
    108 
    109 struct	cfattach vsbus_ca = {
    110 	sizeof(struct vsbus_softc), vsbus_match, vsbus_attach
    111 };
    112 
    113 int
    114 vsbus_print(aux, name)
    115 	void *aux;
    116 	const char *name;
    117 {
    118 	struct vsbus_attach_args *va = aux;
    119 
    120 	printf(" csr 0x%lx vec %o ipl %x maskbit %d", va->va_paddr,
    121 	    va->va_cvec & 511, va->va_br, va->va_maskno - 1);
    122 	return(UNCONF);
    123 }
    124 
    125 int
    126 vsbus_match(parent, cf, aux)
    127 	struct	device	*parent;
    128 	struct cfdata	*cf;
    129 	void	*aux;
    130 {
    131 	if (vax_bustype == VAX_VSBUS)
    132 		return 1;
    133 	return 0;
    134 }
    135 
    136 void
    137 vsbus_attach(parent, self, aux)
    138 	struct	device	*parent, *self;
    139 	void	*aux;
    140 {
    141 	struct	vsbus_softc *sc = (void *)self;
    142 	vaddr_t temp;
    143 
    144 	printf("\n");
    145 
    146 	switch (vax_boardtype) {
    147 	case VAX_BTYP_49:
    148 		temp = vax_map_physmem(0x25c00000, 1);
    149 		sc->sc_intreq = (char *)temp + 12;
    150 		sc->sc_intclr = (char *)temp + 12;
    151 		sc->sc_intmsk = (char *)temp + 8;
    152 		break;
    153 
    154 	default:
    155 		temp = vax_map_physmem(VS_REGS, 1);
    156 		sc->sc_intreq = (char *)temp + 15;
    157 		sc->sc_intclr = (char *)temp + 15;
    158 		sc->sc_intmsk = (char *)temp + 12;
    159 		break;
    160 	}
    161 
    162 	/*
    163 	 * First: find which interrupts we won't care about.
    164 	 * There are interrupts that interrupt on a periodic basic
    165 	 * that we don't want to interfere with the rest of the
    166 	 * interrupt probing.
    167 	 */
    168 	*sc->sc_intmsk = 0;
    169 	*sc->sc_intclr = 0xff;
    170 	DELAY(1000000); /* Wait a second */
    171 	sc->sc_mask = *sc->sc_intreq;
    172 	printf("%s: interrupt mask %x\n", self->dv_xname, sc->sc_mask);
    173 	/*
    174 	 * now check for all possible devices on this "bus"
    175 	 */
    176 	config_search(vsbus_search, self, NULL);
    177 
    178 	/* Autoconfig finished, enable interrupts */
    179 	*sc->sc_intmsk = ~sc->sc_mask;
    180 }
    181 
    182 int
    183 vsbus_search(parent, cf, aux)
    184 	struct device *parent;
    185 	struct cfdata *cf;
    186 	void *aux;
    187 {
    188 	struct	vsbus_softc *sc = (void *)parent;
    189 	struct	vsbus_attach_args va;
    190 	int i, vec, br;
    191 	u_char c;
    192 
    193 	va.va_paddr = cf->cf_loc[0];
    194 	va.va_addr = vax_map_physmem(va.va_paddr, 1);
    195 	va.va_dmat = &vsbus_bus_dma_tag;
    196 
    197 	*sc->sc_intmsk = 0;
    198 	*sc->sc_intclr = 0xff;
    199 	scb_vecref(0, 0); /* Clear vector ref */
    200 
    201 	i = (*cf->cf_attach->ca_match) (parent, cf, &va);
    202 	vax_unmap_physmem(va.va_addr, 1);
    203 	c = *sc->sc_intreq & ~sc->sc_mask;
    204 	if (i == 0)
    205 		goto forgetit;
    206 	if (i > 10)
    207 		c = sc->sc_mask; /* Fooling interrupt */
    208 	else if (c == 0)
    209 		goto forgetit;
    210 
    211 	*sc->sc_intmsk = c;
    212 	DELAY(100);
    213 	*sc->sc_intmsk = 0;
    214 	va.va_maskno = ffs((u_int)c);
    215 	i = scb_vecref(&vec, &br);
    216 	if (i == 0)
    217 		goto fail;
    218 	if (vec == 0)
    219 		goto fail;
    220 
    221 	scb_vecalloc(vec, va.va_ivec, cf->cf_unit, SCB_ISTACK);
    222 	va.va_br = br;
    223 	va.va_cvec = vec;
    224 
    225 	config_attach(parent, cf, &va, vsbus_print);
    226 	return 0;
    227 
    228 fail:
    229 	printf("%s%d at %s csr %x %s\n",
    230 	    cf->cf_driver->cd_name, cf->cf_unit, parent->dv_xname,
    231 	    cf->cf_loc[0], (i ? "zero vector" : "didn't interrupt"));
    232 forgetit:
    233 	return 0;
    234 }
    235 
    236 /*
    237  * Sets a new interrupt mask. Returns the old one.
    238  * Works like spl functions.
    239  */
    240 unsigned char
    241 vsbus_setmask(mask)
    242 	unsigned char mask;
    243 {
    244 	struct vsbus_softc *sc = vsbus_cd.cd_devs[0];
    245 	unsigned char ch;
    246 
    247 	ch = *sc->sc_intmsk;
    248 	*sc->sc_intmsk = mask;
    249 	return ch;
    250 }
    251 
    252 /*
    253  * Clears the interrupts in mask.
    254  */
    255 void
    256 vsbus_clrintr(mask)
    257 	unsigned char mask;
    258 {
    259 	struct vsbus_softc *sc = vsbus_cd.cd_devs[0];
    260 
    261 	*sc->sc_intclr = mask;
    262 }
    263 
    264 #ifdef notyet
    265 /*
    266  * Allocate/free DMA pages and other bus resources.
    267  * VS2000: All DMA and register access must be exclusive.
    268  * VS3100: DMA area may be accessed by anyone anytime.
    269  *   MFM/SCSI: Don't touch reg's while DMA is active.
    270  *   SCSI/SCSI: Legal to touch any register anytime.
    271  */
    272 
    273 
    274 #endif
    275