Home | History | Annotate | Line # | Download | only in vsa
vsbus.c revision 1.20
      1 /*	$NetBSD: vsbus.c,v 1.20 1999/10/22 21:10:12 ragge Exp $ */
      2 /*
      3  * Copyright (c) 1996, 1999 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 <vm/vm.h>
     51 
     52 #define	_VAX_BUS_DMA_PRIVATE
     53 #include <machine/bus.h>
     54 #include <machine/pte.h>
     55 #include <machine/sid.h>
     56 #include <machine/scb.h>
     57 #include <machine/cpu.h>
     58 #include <machine/trap.h>
     59 #include <machine/nexus.h>
     60 
     61 #include <machine/uvax.h>
     62 #include <machine/ka410.h>
     63 #include <machine/ka420.h>
     64 #include <machine/ka43.h>
     65 
     66 #include <machine/vsbus.h>
     67 
     68 #include "ioconf.h"
     69 
     70 int	vsbus_match	__P((struct device *, struct cfdata *, void *));
     71 void	vsbus_attach	__P((struct device *, struct device *, void *));
     72 int	vsbus_print	__P((void *, const char *));
     73 int	vsbus_search	__P((struct device *, struct cfdata *, void *));
     74 
     75 void	ka410_attach	__P((struct device *, struct device *, void *));
     76 void	ka43_attach	__P((struct device *, struct device *, void *));
     77 
     78 struct vax_bus_dma_tag vsbus_bus_dma_tag = {
     79 	0,
     80 	0,
     81 	0,
     82 	0,
     83 	0,
     84 	0,
     85 	_bus_dmamap_create,
     86 	_bus_dmamap_destroy,
     87 	_bus_dmamap_load,
     88 	_bus_dmamap_load_mbuf,
     89 	_bus_dmamap_load_uio,
     90 	_bus_dmamap_load_raw,
     91 	_bus_dmamap_unload,
     92 	_bus_dmamap_sync,
     93 	_bus_dmamem_alloc,
     94 	_bus_dmamem_free,
     95 	_bus_dmamem_map,
     96 	_bus_dmamem_unmap,
     97 	_bus_dmamem_mmap,
     98 };
     99 
    100 struct	vsbus_softc {
    101 	struct	device sc_dev;
    102 #if 0
    103 	volatile struct vs_cpu *sc_cpu;
    104 #endif
    105 	u_char	*sc_intmsk;	/* Mask register */
    106 	u_char	*sc_intclr;	/* Clear interrupt register */
    107 	u_char	*sc_intreq;	/* Interrupt request register */
    108 	u_char	sc_mask;	/* Interrupts to enable after autoconf */
    109 };
    110 
    111 struct	cfattach vsbus_ca = {
    112 	sizeof(struct vsbus_softc), vsbus_match, vsbus_attach
    113 };
    114 
    115 int
    116 vsbus_print(aux, name)
    117 	void *aux;
    118 	const char *name;
    119 {
    120 	struct vsbus_attach_args *va = aux;
    121 
    122 	printf(" csr 0x%lx vec %o ipl %x maskbit %d", va->va_paddr,
    123 	    va->va_cvec & 511, va->va_br, va->va_maskno - 1);
    124 	return(UNCONF);
    125 }
    126 
    127 int
    128 vsbus_match(parent, cf, aux)
    129 	struct	device	*parent;
    130 	struct cfdata	*cf;
    131 	void	*aux;
    132 {
    133 	if (vax_bustype == VAX_VSBUS)
    134 		return 1;
    135 	return 0;
    136 }
    137 
    138 void
    139 vsbus_attach(parent, self, aux)
    140 	struct	device	*parent, *self;
    141 	void	*aux;
    142 {
    143 	struct	vsbus_softc *sc = (void *)self;
    144 	vaddr_t temp;
    145 
    146 	printf("\n");
    147 
    148 	switch (vax_boardtype) {
    149 	case VAX_BTYP_49:
    150 		temp = vax_map_physmem(0x25c00000, 1);
    151 		sc->sc_intreq = (char *)temp + 12;
    152 		sc->sc_intclr = (char *)temp + 12;
    153 		sc->sc_intmsk = (char *)temp + 8;
    154 		break;
    155 
    156 	default:
    157 		temp = vax_map_physmem(VS_REGS, 1);
    158 		sc->sc_intreq = (char *)temp + 15;
    159 		sc->sc_intclr = (char *)temp + 15;
    160 		sc->sc_intmsk = (char *)temp + 12;
    161 		break;
    162 	}
    163 
    164 	/*
    165 	 * First: find which interrupts we won't care about.
    166 	 * There are interrupts that interrupt on a periodic basic
    167 	 * that we don't want to interfere with the rest of the
    168 	 * interrupt probing.
    169 	 */
    170 	*sc->sc_intmsk = 0;
    171 	*sc->sc_intclr = 0xff;
    172 	DELAY(1000000); /* Wait a second */
    173 	sc->sc_mask = *sc->sc_intreq;
    174 	printf("%s: interrupt mask %x\n", self->dv_xname, sc->sc_mask);
    175 	/*
    176 	 * now check for all possible devices on this "bus"
    177 	 */
    178 	config_search(vsbus_search, self, NULL);
    179 
    180 	/* Autoconfig finished, enable interrupts */
    181 	*sc->sc_intmsk = ~sc->sc_mask;
    182 }
    183 
    184 int
    185 vsbus_search(parent, cf, aux)
    186 	struct device *parent;
    187 	struct cfdata *cf;
    188 	void *aux;
    189 {
    190 	struct	vsbus_softc *sc = (void *)parent;
    191 	struct	vsbus_attach_args va;
    192 	int i, vec, br;
    193 	u_char c;
    194 
    195 	va.va_paddr = cf->cf_loc[0];
    196 	va.va_addr = vax_map_physmem(va.va_paddr, 1);
    197 	va.va_dmat = &vsbus_bus_dma_tag;
    198 
    199 	*sc->sc_intmsk = 0;
    200 	*sc->sc_intclr = 0xff;
    201 	scb_vecref(0, 0); /* Clear vector ref */
    202 
    203 	i = (*cf->cf_attach->ca_match) (parent, cf, &va);
    204 	vax_unmap_physmem(va.va_addr, 1);
    205 	c = *sc->sc_intreq & ~sc->sc_mask;
    206 	if (i == 0)
    207 		goto forgetit;
    208 	if (i > 10)
    209 		c = sc->sc_mask; /* Fooling interrupt */
    210 	else if (c == 0)
    211 		goto forgetit;
    212 
    213 	*sc->sc_intmsk = c;
    214 	DELAY(100);
    215 	*sc->sc_intmsk = 0;
    216 	va.va_maskno = ffs((u_int)c);
    217 	i = scb_vecref(&vec, &br);
    218 	if (i == 0)
    219 		goto fail;
    220 	if (vec == 0)
    221 		goto fail;
    222 
    223 	scb_vecalloc(vec, va.va_ivec, cf->cf_unit, SCB_ISTACK);
    224 	va.va_br = br;
    225 	va.va_cvec = vec;
    226 
    227 	config_attach(parent, cf, &va, vsbus_print);
    228 	return 0;
    229 
    230 fail:
    231 	printf("%s%d at %s csr %x %s\n",
    232 	    cf->cf_driver->cd_name, cf->cf_unit, parent->dv_xname,
    233 	    cf->cf_loc[0], (i ? "zero vector" : "didn't interrupt"));
    234 forgetit:
    235 	return 0;
    236 }
    237 
    238 /*
    239  * Sets a new interrupt mask. Returns the old one.
    240  * Works like spl functions.
    241  */
    242 unsigned char
    243 vsbus_setmask(mask)
    244 	unsigned char mask;
    245 {
    246 	struct vsbus_softc *sc = vsbus_cd.cd_devs[0];
    247 	unsigned char ch;
    248 
    249 	ch = *sc->sc_intmsk;
    250 	*sc->sc_intmsk = mask;
    251 	return ch;
    252 }
    253 
    254 /*
    255  * Clears the interrupts in mask.
    256  */
    257 void
    258 vsbus_clrintr(mask)
    259 	unsigned char mask;
    260 {
    261 	struct vsbus_softc *sc = vsbus_cd.cd_devs[0];
    262 
    263 	*sc->sc_intclr = mask;
    264 }
    265 
    266 /*
    267  * Copy data from/to a user process' space from the DMA area.
    268  * Use the physical memory directly.
    269  */
    270 void
    271 vsbus_copytoproc(p, from, to, len)
    272 	struct proc *p;
    273 	caddr_t from, to;
    274 	int len;
    275 {
    276 	struct pte *pte;
    277 	paddr_t pa;
    278 
    279 	pte = uvtopte(TRUNC_PAGE(to), (&p->p_addr->u_pcb));
    280 	if ((vaddr_t)to & PGOFSET) {
    281 		int cz = ROUND_PAGE(to) - (vaddr_t)to;
    282 
    283 		pa = (pte->pg_pfn << VAX_PGSHIFT) | (NBPG - cz) | KERNBASE;
    284 		bcopy(from, (caddr_t)pa, min(cz, len));
    285 		from += cz;
    286 		to += cz;
    287 		len -= cz;
    288 		pte += 8; /* XXX */
    289 	}
    290 	while (len > 0) {
    291 		pa = (pte->pg_pfn << VAX_PGSHIFT) | KERNBASE;
    292 		bcopy(from, (caddr_t)pa, min(NBPG, len));
    293 		from += NBPG;
    294 		to += NBPG;
    295 		len -= NBPG;
    296 		pte += 8; /* XXX */
    297 	}
    298 }
    299 
    300 void
    301 vsbus_copyfromproc(p, from, to, len)
    302 	struct proc *p;
    303 	caddr_t from, to;
    304 	int len;
    305 {
    306 	struct pte *pte;
    307 	paddr_t pa;
    308 
    309 	pte = uvtopte(TRUNC_PAGE(from), (&p->p_addr->u_pcb));
    310 	if ((vaddr_t)from & PGOFSET) {
    311 		int cz = ROUND_PAGE(from) - (vaddr_t)from;
    312 
    313 		pa = (pte->pg_pfn << VAX_PGSHIFT) | (NBPG - cz) | KERNBASE;
    314 		bcopy((caddr_t)pa, to, min(cz, len));
    315 		from += cz;
    316 		to += cz;
    317 		len -= cz;
    318 		pte += 8; /* XXX */
    319 	}
    320 	while (len > 0) {
    321 		pa = (pte->pg_pfn << VAX_PGSHIFT) | KERNBASE;
    322 		bcopy((caddr_t)pa, to, min(NBPG, len));
    323 		from += NBPG;
    324 		to += NBPG;
    325 		len -= NBPG;
    326 		pte += 8; /* XXX */
    327 	}
    328 }
    329