Home | History | Annotate | Line # | Download | only in vsa
vsbus.c revision 1.25.2.1
      1  1.25.2.1   minoura /*	$NetBSD: vsbus.c,v 1.25.2.1 2000/06/22 17:05:33 minoura Exp $ */
      2       1.1     ragge /*
      3      1.20     ragge  * Copyright (c) 1996, 1999 Ludd, University of Lule}, Sweden.
      4       1.1     ragge  * All rights reserved.
      5       1.1     ragge  *
      6       1.1     ragge  * This code is derived from software contributed to Ludd by Bertram Barth.
      7       1.1     ragge  *
      8       1.1     ragge  * Redistribution and use in source and binary forms, with or without
      9       1.1     ragge  * modification, are permitted provided that the following conditions
     10       1.1     ragge  * are met:
     11       1.1     ragge  * 1. Redistributions of source code must retain the above copyright
     12       1.1     ragge  *    notice, this list of conditions and the following disclaimer.
     13       1.1     ragge  * 2. Redistributions in binary form must reproduce the above copyright
     14       1.1     ragge  *    notice, this list of conditions and the following disclaimer in the
     15       1.1     ragge  *    documentation and/or other materials provided with the distribution.
     16       1.1     ragge  * 3. All advertising materials mentioning features or use of this software
     17       1.1     ragge  *    must display the following acknowledgement:
     18       1.1     ragge  *	This product includes software developed at Ludd, University of
     19       1.1     ragge  *	Lule}, Sweden and its contributors.
     20       1.1     ragge  * 4. The name of the author may not be used to endorse or promote products
     21       1.1     ragge  *    derived from this software without specific prior written permission
     22       1.1     ragge  *
     23       1.1     ragge  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     24       1.1     ragge  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     25       1.1     ragge  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     26       1.1     ragge  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     27       1.1     ragge  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     28       1.1     ragge  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     29       1.1     ragge  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     30       1.1     ragge  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     31       1.1     ragge  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     32       1.1     ragge  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     33       1.1     ragge  */
     34       1.1     ragge 
     35       1.1     ragge #include <sys/param.h>
     36       1.1     ragge #include <sys/systm.h>
     37       1.1     ragge #include <sys/buf.h>
     38       1.1     ragge #include <sys/conf.h>
     39       1.1     ragge #include <sys/file.h>
     40       1.1     ragge #include <sys/ioctl.h>
     41       1.1     ragge #include <sys/proc.h>
     42       1.1     ragge #include <sys/user.h>
     43       1.1     ragge #include <sys/map.h>
     44       1.1     ragge #include <sys/device.h>
     45       1.1     ragge #include <sys/dkstat.h>
     46       1.1     ragge #include <sys/disklabel.h>
     47       1.1     ragge #include <sys/syslog.h>
     48       1.1     ragge #include <sys/stat.h>
     49       1.1     ragge 
     50      1.20     ragge #include <vm/vm.h>
     51      1.20     ragge 
     52      1.17     ragge #define	_VAX_BUS_DMA_PRIVATE
     53      1.17     ragge #include <machine/bus.h>
     54       1.1     ragge #include <machine/pte.h>
     55       1.1     ragge #include <machine/sid.h>
     56       1.1     ragge #include <machine/scb.h>
     57       1.1     ragge #include <machine/cpu.h>
     58       1.1     ragge #include <machine/trap.h>
     59       1.1     ragge #include <machine/nexus.h>
     60       1.1     ragge 
     61       1.1     ragge #include <machine/uvax.h>
     62       1.1     ragge #include <machine/ka410.h>
     63      1.12     ragge #include <machine/ka420.h>
     64       1.1     ragge #include <machine/ka43.h>
     65       1.1     ragge 
     66       1.1     ragge #include <machine/vsbus.h>
     67       1.1     ragge 
     68      1.10     ragge #include "ioconf.h"
     69  1.25.2.1   minoura #include "opt_cputype.h"
     70       1.1     ragge 
     71       1.9     ragge int	vsbus_match	__P((struct device *, struct cfdata *, void *));
     72       1.1     ragge void	vsbus_attach	__P((struct device *, struct device *, void *));
     73       1.2       cgd int	vsbus_print	__P((void *, const char *));
     74      1.16     ragge int	vsbus_search	__P((struct device *, struct cfdata *, void *));
     75       1.1     ragge 
     76      1.21      matt static struct vax_bus_dma_tag vsbus_bus_dma_tag = {
     77      1.17     ragge 	0,
     78      1.17     ragge 	0,
     79      1.17     ragge 	0,
     80      1.17     ragge 	0,
     81      1.17     ragge 	0,
     82      1.17     ragge 	0,
     83      1.17     ragge 	_bus_dmamap_create,
     84      1.17     ragge 	_bus_dmamap_destroy,
     85      1.17     ragge 	_bus_dmamap_load,
     86      1.17     ragge 	_bus_dmamap_load_mbuf,
     87      1.17     ragge 	_bus_dmamap_load_uio,
     88      1.17     ragge 	_bus_dmamap_load_raw,
     89      1.17     ragge 	_bus_dmamap_unload,
     90      1.17     ragge 	_bus_dmamap_sync,
     91      1.17     ragge 	_bus_dmamem_alloc,
     92      1.17     ragge 	_bus_dmamem_free,
     93      1.17     ragge 	_bus_dmamem_map,
     94      1.17     ragge 	_bus_dmamem_unmap,
     95      1.17     ragge 	_bus_dmamem_mmap,
     96      1.17     ragge };
     97      1.17     ragge 
     98      1.21      matt extern struct vax_bus_space vax_mem_bus_space;
     99      1.21      matt 
    100      1.10     ragge struct	cfattach vsbus_ca = {
    101      1.10     ragge 	sizeof(struct vsbus_softc), vsbus_match, vsbus_attach
    102       1.1     ragge };
    103       1.6     ragge 
    104       1.1     ragge int
    105       1.1     ragge vsbus_print(aux, name)
    106       1.1     ragge 	void *aux;
    107       1.2       cgd 	const char *name;
    108       1.1     ragge {
    109      1.10     ragge 	struct vsbus_attach_args *va = aux;
    110       1.1     ragge 
    111      1.19     ragge 	printf(" csr 0x%lx vec %o ipl %x maskbit %d", va->va_paddr,
    112      1.16     ragge 	    va->va_cvec & 511, va->va_br, va->va_maskno - 1);
    113      1.16     ragge 	return(UNCONF);
    114       1.1     ragge }
    115       1.1     ragge 
    116       1.1     ragge int
    117       1.1     ragge vsbus_match(parent, cf, aux)
    118       1.1     ragge 	struct	device	*parent;
    119       1.9     ragge 	struct cfdata	*cf;
    120       1.1     ragge 	void	*aux;
    121       1.1     ragge {
    122      1.18     ragge 	if (vax_bustype == VAX_VSBUS)
    123      1.18     ragge 		return 1;
    124      1.18     ragge 	return 0;
    125       1.1     ragge }
    126       1.1     ragge 
    127       1.1     ragge void
    128       1.1     ragge vsbus_attach(parent, self, aux)
    129       1.1     ragge 	struct	device	*parent, *self;
    130       1.1     ragge 	void	*aux;
    131       1.1     ragge {
    132      1.10     ragge 	struct	vsbus_softc *sc = (void *)self;
    133       1.1     ragge 
    134       1.4  christos 	printf("\n");
    135      1.14     ragge 
    136      1.21      matt 	sc->sc_dmatag = vsbus_bus_dma_tag;
    137      1.21      matt 
    138      1.19     ragge 	switch (vax_boardtype) {
    139      1.22      matt #if VAX49
    140      1.19     ragge 	case VAX_BTYP_49:
    141      1.24      matt 		sc->sc_vsregs = vax_map_physmem(0x25c00000, 1);
    142      1.24      matt 		sc->sc_intreq = (char *)sc->sc_vsregs + 12;
    143      1.24      matt 		sc->sc_intclr = (char *)sc->sc_vsregs + 12;
    144      1.24      matt 		sc->sc_intmsk = (char *)sc->sc_vsregs + 8;
    145      1.24      matt 		vsbus_dma_init(sc, 8192);
    146      1.19     ragge 		break;
    147      1.22      matt #endif
    148      1.19     ragge 
    149      1.22      matt #if VAX46 || VAX48
    150      1.21      matt 	case VAX_BTYP_48:
    151      1.21      matt 	case VAX_BTYP_46:
    152      1.24      matt 		sc->sc_vsregs = vax_map_physmem(VS_REGS, 1);
    153      1.24      matt 		sc->sc_intreq = (char *)sc->sc_vsregs + 15;
    154      1.24      matt 		sc->sc_intclr = (char *)sc->sc_vsregs + 15;
    155      1.24      matt 		sc->sc_intmsk = (char *)sc->sc_vsregs + 12;
    156      1.24      matt 		vsbus_dma_init(sc, 32768);
    157      1.22      matt #endif
    158      1.21      matt 
    159      1.19     ragge 	default:
    160      1.24      matt 		sc->sc_vsregs = vax_map_physmem(VS_REGS, 1);
    161      1.24      matt 		sc->sc_intreq = (char *)sc->sc_vsregs + 15;
    162      1.24      matt 		sc->sc_intclr = (char *)sc->sc_vsregs + 15;
    163      1.24      matt 		sc->sc_intmsk = (char *)sc->sc_vsregs + 12;
    164      1.19     ragge 		break;
    165      1.19     ragge 	}
    166      1.16     ragge 
    167       1.1     ragge 	/*
    168      1.16     ragge 	 * First: find which interrupts we won't care about.
    169      1.16     ragge 	 * There are interrupts that interrupt on a periodic basic
    170      1.16     ragge 	 * that we don't want to interfere with the rest of the
    171      1.16     ragge 	 * interrupt probing.
    172       1.1     ragge 	 */
    173      1.19     ragge 	*sc->sc_intmsk = 0;
    174      1.19     ragge 	*sc->sc_intclr = 0xff;
    175      1.16     ragge 	DELAY(1000000); /* Wait a second */
    176      1.19     ragge 	sc->sc_mask = *sc->sc_intreq;
    177      1.16     ragge 	printf("%s: interrupt mask %x\n", self->dv_xname, sc->sc_mask);
    178       1.1     ragge 	/*
    179       1.1     ragge 	 * now check for all possible devices on this "bus"
    180       1.1     ragge 	 */
    181      1.16     ragge 	config_search(vsbus_search, self, NULL);
    182      1.13     ragge 
    183      1.16     ragge 	/* Autoconfig finished, enable interrupts */
    184      1.19     ragge 	*sc->sc_intmsk = ~sc->sc_mask;
    185       1.1     ragge }
    186       1.1     ragge 
    187      1.16     ragge int
    188      1.16     ragge vsbus_search(parent, cf, aux)
    189      1.16     ragge 	struct device *parent;
    190      1.16     ragge 	struct cfdata *cf;
    191      1.16     ragge 	void *aux;
    192       1.1     ragge {
    193      1.16     ragge 	struct	vsbus_softc *sc = (void *)parent;
    194      1.16     ragge 	struct	vsbus_attach_args va;
    195      1.16     ragge 	int i, vec, br;
    196      1.16     ragge 	u_char c;
    197       1.1     ragge 
    198      1.16     ragge 	va.va_paddr = cf->cf_loc[0];
    199      1.16     ragge 	va.va_addr = vax_map_physmem(va.va_paddr, 1);
    200      1.21      matt 	va.va_dmat = &sc->sc_dmatag;
    201      1.21      matt 	va.va_iot = &vax_mem_bus_space;
    202       1.1     ragge 
    203      1.19     ragge 	*sc->sc_intmsk = 0;
    204      1.19     ragge 	*sc->sc_intclr = 0xff;
    205      1.16     ragge 	scb_vecref(0, 0); /* Clear vector ref */
    206      1.16     ragge 
    207      1.16     ragge 	i = (*cf->cf_attach->ca_match) (parent, cf, &va);
    208      1.16     ragge 	vax_unmap_physmem(va.va_addr, 1);
    209      1.19     ragge 	c = *sc->sc_intreq & ~sc->sc_mask;
    210      1.19     ragge 	if (i == 0)
    211      1.19     ragge 		goto forgetit;
    212      1.16     ragge 	if (i > 10)
    213      1.16     ragge 		c = sc->sc_mask; /* Fooling interrupt */
    214      1.19     ragge 	else if (c == 0)
    215      1.16     ragge 		goto forgetit;
    216      1.16     ragge 
    217      1.19     ragge 	*sc->sc_intmsk = c;
    218      1.16     ragge 	DELAY(100);
    219      1.19     ragge 	*sc->sc_intmsk = 0;
    220      1.16     ragge 	va.va_maskno = ffs((u_int)c);
    221      1.16     ragge 	i = scb_vecref(&vec, &br);
    222      1.16     ragge 	if (i == 0)
    223      1.16     ragge 		goto fail;
    224      1.16     ragge 	if (vec == 0)
    225      1.16     ragge 		goto fail;
    226      1.16     ragge 
    227      1.16     ragge 	va.va_br = br;
    228      1.16     ragge 	va.va_cvec = vec;
    229      1.16     ragge 
    230      1.16     ragge 	config_attach(parent, cf, &va, vsbus_print);
    231      1.16     ragge 	return 0;
    232      1.16     ragge 
    233      1.16     ragge fail:
    234      1.16     ragge 	printf("%s%d at %s csr %x %s\n",
    235      1.16     ragge 	    cf->cf_driver->cd_name, cf->cf_unit, parent->dv_xname,
    236      1.16     ragge 	    cf->cf_loc[0], (i ? "zero vector" : "didn't interrupt"));
    237      1.16     ragge forgetit:
    238      1.16     ragge 	return 0;
    239       1.1     ragge }
    240       1.1     ragge 
    241      1.16     ragge /*
    242      1.16     ragge  * Sets a new interrupt mask. Returns the old one.
    243      1.16     ragge  * Works like spl functions.
    244      1.16     ragge  */
    245      1.16     ragge unsigned char
    246      1.16     ragge vsbus_setmask(mask)
    247      1.16     ragge 	unsigned char mask;
    248       1.1     ragge {
    249      1.25     ragge 	struct vsbus_softc *sc;
    250      1.16     ragge 	unsigned char ch;
    251       1.1     ragge 
    252      1.25     ragge 	if (vsbus_cd.cd_ndevs == 0)
    253      1.25     ragge 		return 0;
    254      1.25     ragge 	sc = vsbus_cd.cd_devs[0];
    255      1.25     ragge 
    256      1.19     ragge 	ch = *sc->sc_intmsk;
    257      1.19     ragge 	*sc->sc_intmsk = mask;
    258      1.16     ragge 	return ch;
    259       1.1     ragge }
    260       1.1     ragge 
    261      1.16     ragge /*
    262      1.16     ragge  * Clears the interrupts in mask.
    263      1.16     ragge  */
    264      1.10     ragge void
    265      1.16     ragge vsbus_clrintr(mask)
    266      1.16     ragge 	unsigned char mask;
    267       1.1     ragge {
    268      1.25     ragge 	struct vsbus_softc *sc;
    269      1.25     ragge 
    270      1.25     ragge 	if (vsbus_cd.cd_ndevs == 0)
    271      1.25     ragge 		return;
    272      1.25     ragge 	sc = vsbus_cd.cd_devs[0];
    273       1.1     ragge 
    274      1.19     ragge 	*sc->sc_intclr = mask;
    275       1.1     ragge }
    276       1.1     ragge 
    277       1.1     ragge /*
    278      1.20     ragge  * Copy data from/to a user process' space from the DMA area.
    279      1.20     ragge  * Use the physical memory directly.
    280       1.1     ragge  */
    281      1.20     ragge void
    282      1.20     ragge vsbus_copytoproc(p, from, to, len)
    283      1.20     ragge 	struct proc *p;
    284      1.20     ragge 	caddr_t from, to;
    285      1.20     ragge 	int len;
    286      1.20     ragge {
    287      1.20     ragge 	struct pte *pte;
    288      1.20     ragge 	paddr_t pa;
    289       1.1     ragge 
    290      1.20     ragge 	pte = uvtopte(TRUNC_PAGE(to), (&p->p_addr->u_pcb));
    291      1.20     ragge 	if ((vaddr_t)to & PGOFSET) {
    292      1.20     ragge 		int cz = ROUND_PAGE(to) - (vaddr_t)to;
    293      1.20     ragge 
    294      1.20     ragge 		pa = (pte->pg_pfn << VAX_PGSHIFT) | (NBPG - cz) | KERNBASE;
    295      1.20     ragge 		bcopy(from, (caddr_t)pa, min(cz, len));
    296      1.20     ragge 		from += cz;
    297      1.20     ragge 		to += cz;
    298      1.20     ragge 		len -= cz;
    299      1.20     ragge 		pte += 8; /* XXX */
    300      1.20     ragge 	}
    301      1.20     ragge 	while (len > 0) {
    302      1.20     ragge 		pa = (pte->pg_pfn << VAX_PGSHIFT) | KERNBASE;
    303      1.20     ragge 		bcopy(from, (caddr_t)pa, min(NBPG, len));
    304      1.20     ragge 		from += NBPG;
    305      1.20     ragge 		to += NBPG;
    306      1.20     ragge 		len -= NBPG;
    307      1.20     ragge 		pte += 8; /* XXX */
    308      1.20     ragge 	}
    309      1.20     ragge }
    310       1.1     ragge 
    311      1.20     ragge void
    312      1.20     ragge vsbus_copyfromproc(p, from, to, len)
    313      1.20     ragge 	struct proc *p;
    314      1.20     ragge 	caddr_t from, to;
    315      1.20     ragge 	int len;
    316      1.20     ragge {
    317      1.20     ragge 	struct pte *pte;
    318      1.20     ragge 	paddr_t pa;
    319      1.20     ragge 
    320      1.20     ragge 	pte = uvtopte(TRUNC_PAGE(from), (&p->p_addr->u_pcb));
    321      1.20     ragge 	if ((vaddr_t)from & PGOFSET) {
    322      1.20     ragge 		int cz = ROUND_PAGE(from) - (vaddr_t)from;
    323      1.20     ragge 
    324      1.20     ragge 		pa = (pte->pg_pfn << VAX_PGSHIFT) | (NBPG - cz) | KERNBASE;
    325      1.20     ragge 		bcopy((caddr_t)pa, to, min(cz, len));
    326      1.20     ragge 		from += cz;
    327      1.20     ragge 		to += cz;
    328      1.20     ragge 		len -= cz;
    329      1.20     ragge 		pte += 8; /* XXX */
    330      1.20     ragge 	}
    331      1.20     ragge 	while (len > 0) {
    332      1.20     ragge 		pa = (pte->pg_pfn << VAX_PGSHIFT) | KERNBASE;
    333      1.20     ragge 		bcopy((caddr_t)pa, to, min(NBPG, len));
    334      1.20     ragge 		from += NBPG;
    335      1.20     ragge 		to += NBPG;
    336      1.20     ragge 		len -= NBPG;
    337      1.20     ragge 		pte += 8; /* XXX */
    338      1.20     ragge 	}
    339      1.20     ragge }
    340