2000-05-27 01:05:01 +04:00
|
|
|
/* $NetBSD: vsbus.c,v 1.25 2000/05/26 21:05:01 ragge Exp $ */
|
1996-07-20 22:55:09 +04:00
|
|
|
/*
|
1999-10-23 01:10:12 +04:00
|
|
|
* Copyright (c) 1996, 1999 Ludd, University of Lule}, Sweden.
|
1996-07-20 22:55:09 +04:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This code is derived from software contributed to Ludd by Bertram Barth.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software developed at Ludd, University of
|
|
|
|
* Lule}, Sweden and its contributors.
|
|
|
|
* 4. The name of the author may not be used to endorse or promote products
|
|
|
|
* derived from this software without specific prior written permission
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
|
|
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
|
|
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
|
|
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
|
|
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
|
|
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/buf.h>
|
|
|
|
#include <sys/conf.h>
|
|
|
|
#include <sys/file.h>
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#include <sys/proc.h>
|
|
|
|
#include <sys/user.h>
|
|
|
|
#include <sys/map.h>
|
|
|
|
#include <sys/device.h>
|
|
|
|
#include <sys/dkstat.h>
|
|
|
|
#include <sys/disklabel.h>
|
|
|
|
#include <sys/syslog.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
|
1999-10-23 01:10:12 +04:00
|
|
|
#include <vm/vm.h>
|
|
|
|
|
1999-04-15 03:14:45 +04:00
|
|
|
#define _VAX_BUS_DMA_PRIVATE
|
|
|
|
#include <machine/bus.h>
|
1996-07-20 22:55:09 +04:00
|
|
|
#include <machine/pte.h>
|
|
|
|
#include <machine/sid.h>
|
|
|
|
#include <machine/scb.h>
|
|
|
|
#include <machine/cpu.h>
|
|
|
|
#include <machine/trap.h>
|
|
|
|
#include <machine/nexus.h>
|
|
|
|
|
|
|
|
#include <machine/uvax.h>
|
|
|
|
#include <machine/ka410.h>
|
1998-08-10 18:47:16 +04:00
|
|
|
#include <machine/ka420.h>
|
1996-07-20 22:55:09 +04:00
|
|
|
#include <machine/ka43.h>
|
|
|
|
|
|
|
|
#include <machine/vsbus.h>
|
|
|
|
|
1998-05-21 17:10:59 +04:00
|
|
|
#include "ioconf.h"
|
2000-03-04 10:27:47 +03:00
|
|
|
#include "opt_vax46.h"
|
|
|
|
#include "opt_vax48.h"
|
|
|
|
#include "opt_vax49.h"
|
1996-07-20 22:55:09 +04:00
|
|
|
|
1998-01-24 17:16:11 +03:00
|
|
|
int vsbus_match __P((struct device *, struct cfdata *, void *));
|
1996-07-20 22:55:09 +04:00
|
|
|
void vsbus_attach __P((struct device *, struct device *, void *));
|
1996-08-28 01:53:46 +04:00
|
|
|
int vsbus_print __P((void *, const char *));
|
1999-03-13 18:16:47 +03:00
|
|
|
int vsbus_search __P((struct device *, struct cfdata *, void *));
|
1996-07-20 22:55:09 +04:00
|
|
|
|
2000-01-24 05:40:28 +03:00
|
|
|
static struct vax_bus_dma_tag vsbus_bus_dma_tag = {
|
1999-04-15 03:14:45 +04:00
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
_bus_dmamap_create,
|
|
|
|
_bus_dmamap_destroy,
|
|
|
|
_bus_dmamap_load,
|
|
|
|
_bus_dmamap_load_mbuf,
|
|
|
|
_bus_dmamap_load_uio,
|
|
|
|
_bus_dmamap_load_raw,
|
|
|
|
_bus_dmamap_unload,
|
|
|
|
_bus_dmamap_sync,
|
|
|
|
_bus_dmamem_alloc,
|
|
|
|
_bus_dmamem_free,
|
|
|
|
_bus_dmamem_map,
|
|
|
|
_bus_dmamem_unmap,
|
|
|
|
_bus_dmamem_mmap,
|
|
|
|
};
|
|
|
|
|
2000-01-24 05:40:28 +03:00
|
|
|
extern struct vax_bus_space vax_mem_bus_space;
|
|
|
|
|
1998-05-21 17:10:59 +04:00
|
|
|
struct cfattach vsbus_ca = {
|
|
|
|
sizeof(struct vsbus_softc), vsbus_match, vsbus_attach
|
1997-03-23 02:05:31 +03:00
|
|
|
};
|
1996-07-20 22:55:09 +04:00
|
|
|
|
|
|
|
int
|
|
|
|
vsbus_print(aux, name)
|
|
|
|
void *aux;
|
1996-08-28 01:53:46 +04:00
|
|
|
const char *name;
|
1996-07-20 22:55:09 +04:00
|
|
|
{
|
1998-05-21 17:10:59 +04:00
|
|
|
struct vsbus_attach_args *va = aux;
|
1996-07-20 22:55:09 +04:00
|
|
|
|
1999-08-27 21:45:57 +04:00
|
|
|
printf(" csr 0x%lx vec %o ipl %x maskbit %d", va->va_paddr,
|
1999-03-13 18:16:47 +03:00
|
|
|
va->va_cvec & 511, va->va_br, va->va_maskno - 1);
|
|
|
|
return(UNCONF);
|
1996-07-20 22:55:09 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
vsbus_match(parent, cf, aux)
|
|
|
|
struct device *parent;
|
1998-01-24 17:16:11 +03:00
|
|
|
struct cfdata *cf;
|
1996-07-20 22:55:09 +04:00
|
|
|
void *aux;
|
|
|
|
{
|
1999-08-07 14:36:43 +04:00
|
|
|
if (vax_bustype == VAX_VSBUS)
|
|
|
|
return 1;
|
|
|
|
return 0;
|
1996-07-20 22:55:09 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
vsbus_attach(parent, self, aux)
|
|
|
|
struct device *parent, *self;
|
|
|
|
void *aux;
|
|
|
|
{
|
1998-05-21 17:10:59 +04:00
|
|
|
struct vsbus_softc *sc = (void *)self;
|
1996-07-20 22:55:09 +04:00
|
|
|
|
1996-10-13 07:29:05 +04:00
|
|
|
printf("\n");
|
1999-02-02 21:37:20 +03:00
|
|
|
|
2000-01-24 05:40:28 +03:00
|
|
|
sc->sc_dmatag = vsbus_bus_dma_tag;
|
|
|
|
|
1999-08-27 21:45:57 +04:00
|
|
|
switch (vax_boardtype) {
|
2000-03-04 10:27:47 +03:00
|
|
|
#if VAX49
|
1999-08-27 21:45:57 +04:00
|
|
|
case VAX_BTYP_49:
|
2000-04-23 20:38:52 +04:00
|
|
|
sc->sc_vsregs = vax_map_physmem(0x25c00000, 1);
|
|
|
|
sc->sc_intreq = (char *)sc->sc_vsregs + 12;
|
|
|
|
sc->sc_intclr = (char *)sc->sc_vsregs + 12;
|
|
|
|
sc->sc_intmsk = (char *)sc->sc_vsregs + 8;
|
|
|
|
vsbus_dma_init(sc, 8192);
|
1999-08-27 21:45:57 +04:00
|
|
|
break;
|
2000-03-04 10:27:47 +03:00
|
|
|
#endif
|
1999-08-27 21:45:57 +04:00
|
|
|
|
2000-03-04 10:27:47 +03:00
|
|
|
#if VAX46 || VAX48
|
2000-01-24 05:40:28 +03:00
|
|
|
case VAX_BTYP_48:
|
|
|
|
case VAX_BTYP_46:
|
2000-04-23 20:38:52 +04:00
|
|
|
sc->sc_vsregs = vax_map_physmem(VS_REGS, 1);
|
|
|
|
sc->sc_intreq = (char *)sc->sc_vsregs + 15;
|
|
|
|
sc->sc_intclr = (char *)sc->sc_vsregs + 15;
|
|
|
|
sc->sc_intmsk = (char *)sc->sc_vsregs + 12;
|
|
|
|
vsbus_dma_init(sc, 32768);
|
2000-03-04 10:27:47 +03:00
|
|
|
#endif
|
2000-01-24 05:40:28 +03:00
|
|
|
|
1999-08-27 21:45:57 +04:00
|
|
|
default:
|
2000-04-23 20:38:52 +04:00
|
|
|
sc->sc_vsregs = vax_map_physmem(VS_REGS, 1);
|
|
|
|
sc->sc_intreq = (char *)sc->sc_vsregs + 15;
|
|
|
|
sc->sc_intclr = (char *)sc->sc_vsregs + 15;
|
|
|
|
sc->sc_intmsk = (char *)sc->sc_vsregs + 12;
|
1999-08-27 21:45:57 +04:00
|
|
|
break;
|
|
|
|
}
|
1996-07-20 22:55:09 +04:00
|
|
|
|
|
|
|
/*
|
1999-03-13 18:16:47 +03:00
|
|
|
* First: find which interrupts we won't care about.
|
|
|
|
* There are interrupts that interrupt on a periodic basic
|
|
|
|
* that we don't want to interfere with the rest of the
|
|
|
|
* interrupt probing.
|
1996-07-20 22:55:09 +04:00
|
|
|
*/
|
1999-08-27 21:45:57 +04:00
|
|
|
*sc->sc_intmsk = 0;
|
|
|
|
*sc->sc_intclr = 0xff;
|
1999-03-13 18:16:47 +03:00
|
|
|
DELAY(1000000); /* Wait a second */
|
1999-08-27 21:45:57 +04:00
|
|
|
sc->sc_mask = *sc->sc_intreq;
|
1999-03-13 18:16:47 +03:00
|
|
|
printf("%s: interrupt mask %x\n", self->dv_xname, sc->sc_mask);
|
1998-08-10 18:47:16 +04:00
|
|
|
/*
|
1999-03-13 18:16:47 +03:00
|
|
|
* now check for all possible devices on this "bus"
|
1998-08-10 18:47:16 +04:00
|
|
|
*/
|
1999-03-13 18:16:47 +03:00
|
|
|
config_search(vsbus_search, self, NULL);
|
1996-07-20 22:55:09 +04:00
|
|
|
|
1999-03-13 18:16:47 +03:00
|
|
|
/* Autoconfig finished, enable interrupts */
|
1999-08-27 21:45:57 +04:00
|
|
|
*sc->sc_intmsk = ~sc->sc_mask;
|
1996-07-20 22:55:09 +04:00
|
|
|
}
|
|
|
|
|
1999-03-13 18:16:47 +03:00
|
|
|
int
|
|
|
|
vsbus_search(parent, cf, aux)
|
|
|
|
struct device *parent;
|
|
|
|
struct cfdata *cf;
|
|
|
|
void *aux;
|
1996-07-20 22:55:09 +04:00
|
|
|
{
|
1999-03-13 18:16:47 +03:00
|
|
|
struct vsbus_softc *sc = (void *)parent;
|
|
|
|
struct vsbus_attach_args va;
|
|
|
|
int i, vec, br;
|
|
|
|
u_char c;
|
|
|
|
|
|
|
|
va.va_paddr = cf->cf_loc[0];
|
|
|
|
va.va_addr = vax_map_physmem(va.va_paddr, 1);
|
2000-01-24 05:40:28 +03:00
|
|
|
va.va_dmat = &sc->sc_dmatag;
|
|
|
|
va.va_iot = &vax_mem_bus_space;
|
1999-03-13 18:16:47 +03:00
|
|
|
|
1999-08-27 21:45:57 +04:00
|
|
|
*sc->sc_intmsk = 0;
|
|
|
|
*sc->sc_intclr = 0xff;
|
1999-03-13 18:16:47 +03:00
|
|
|
scb_vecref(0, 0); /* Clear vector ref */
|
|
|
|
|
|
|
|
i = (*cf->cf_attach->ca_match) (parent, cf, &va);
|
|
|
|
vax_unmap_physmem(va.va_addr, 1);
|
1999-08-27 21:45:57 +04:00
|
|
|
c = *sc->sc_intreq & ~sc->sc_mask;
|
|
|
|
if (i == 0)
|
|
|
|
goto forgetit;
|
1999-03-13 18:16:47 +03:00
|
|
|
if (i > 10)
|
|
|
|
c = sc->sc_mask; /* Fooling interrupt */
|
1999-08-27 21:45:57 +04:00
|
|
|
else if (c == 0)
|
1999-03-13 18:16:47 +03:00
|
|
|
goto forgetit;
|
|
|
|
|
1999-08-27 21:45:57 +04:00
|
|
|
*sc->sc_intmsk = c;
|
1999-03-13 18:16:47 +03:00
|
|
|
DELAY(100);
|
1999-08-27 21:45:57 +04:00
|
|
|
*sc->sc_intmsk = 0;
|
1999-03-13 18:16:47 +03:00
|
|
|
va.va_maskno = ffs((u_int)c);
|
|
|
|
i = scb_vecref(&vec, &br);
|
|
|
|
if (i == 0)
|
|
|
|
goto fail;
|
|
|
|
if (vec == 0)
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
va.va_br = br;
|
|
|
|
va.va_cvec = vec;
|
|
|
|
|
|
|
|
config_attach(parent, cf, &va, vsbus_print);
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
fail:
|
|
|
|
printf("%s%d at %s csr %x %s\n",
|
|
|
|
cf->cf_driver->cd_name, cf->cf_unit, parent->dv_xname,
|
|
|
|
cf->cf_loc[0], (i ? "zero vector" : "didn't interrupt"));
|
|
|
|
forgetit:
|
|
|
|
return 0;
|
1996-07-20 22:55:09 +04:00
|
|
|
}
|
|
|
|
|
1999-03-13 18:16:47 +03:00
|
|
|
/*
|
|
|
|
* Sets a new interrupt mask. Returns the old one.
|
|
|
|
* Works like spl functions.
|
|
|
|
*/
|
|
|
|
unsigned char
|
|
|
|
vsbus_setmask(mask)
|
|
|
|
unsigned char mask;
|
1996-07-20 22:55:09 +04:00
|
|
|
{
|
2000-05-27 01:05:01 +04:00
|
|
|
struct vsbus_softc *sc;
|
1999-03-13 18:16:47 +03:00
|
|
|
unsigned char ch;
|
1996-07-20 22:55:09 +04:00
|
|
|
|
2000-05-27 01:05:01 +04:00
|
|
|
if (vsbus_cd.cd_ndevs == 0)
|
|
|
|
return 0;
|
|
|
|
sc = vsbus_cd.cd_devs[0];
|
|
|
|
|
1999-08-27 21:45:57 +04:00
|
|
|
ch = *sc->sc_intmsk;
|
|
|
|
*sc->sc_intmsk = mask;
|
1999-03-13 18:16:47 +03:00
|
|
|
return ch;
|
1996-07-20 22:55:09 +04:00
|
|
|
}
|
|
|
|
|
1999-03-13 18:16:47 +03:00
|
|
|
/*
|
|
|
|
* Clears the interrupts in mask.
|
|
|
|
*/
|
1998-05-21 17:10:59 +04:00
|
|
|
void
|
1999-03-13 18:16:47 +03:00
|
|
|
vsbus_clrintr(mask)
|
|
|
|
unsigned char mask;
|
1996-07-20 22:55:09 +04:00
|
|
|
{
|
2000-05-27 01:05:01 +04:00
|
|
|
struct vsbus_softc *sc;
|
|
|
|
|
|
|
|
if (vsbus_cd.cd_ndevs == 0)
|
|
|
|
return;
|
|
|
|
sc = vsbus_cd.cd_devs[0];
|
1996-07-20 22:55:09 +04:00
|
|
|
|
1999-08-27 21:45:57 +04:00
|
|
|
*sc->sc_intclr = mask;
|
1996-07-20 22:55:09 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
1999-10-23 01:10:12 +04:00
|
|
|
* Copy data from/to a user process' space from the DMA area.
|
|
|
|
* Use the physical memory directly.
|
1996-07-20 22:55:09 +04:00
|
|
|
*/
|
1999-10-23 01:10:12 +04:00
|
|
|
void
|
|
|
|
vsbus_copytoproc(p, from, to, len)
|
|
|
|
struct proc *p;
|
|
|
|
caddr_t from, to;
|
|
|
|
int len;
|
|
|
|
{
|
|
|
|
struct pte *pte;
|
|
|
|
paddr_t pa;
|
|
|
|
|
|
|
|
pte = uvtopte(TRUNC_PAGE(to), (&p->p_addr->u_pcb));
|
|
|
|
if ((vaddr_t)to & PGOFSET) {
|
|
|
|
int cz = ROUND_PAGE(to) - (vaddr_t)to;
|
|
|
|
|
|
|
|
pa = (pte->pg_pfn << VAX_PGSHIFT) | (NBPG - cz) | KERNBASE;
|
|
|
|
bcopy(from, (caddr_t)pa, min(cz, len));
|
|
|
|
from += cz;
|
|
|
|
to += cz;
|
|
|
|
len -= cz;
|
|
|
|
pte += 8; /* XXX */
|
|
|
|
}
|
|
|
|
while (len > 0) {
|
|
|
|
pa = (pte->pg_pfn << VAX_PGSHIFT) | KERNBASE;
|
|
|
|
bcopy(from, (caddr_t)pa, min(NBPG, len));
|
|
|
|
from += NBPG;
|
|
|
|
to += NBPG;
|
|
|
|
len -= NBPG;
|
|
|
|
pte += 8; /* XXX */
|
|
|
|
}
|
|
|
|
}
|
1996-07-20 22:55:09 +04:00
|
|
|
|
1999-10-23 01:10:12 +04:00
|
|
|
void
|
|
|
|
vsbus_copyfromproc(p, from, to, len)
|
|
|
|
struct proc *p;
|
|
|
|
caddr_t from, to;
|
|
|
|
int len;
|
|
|
|
{
|
|
|
|
struct pte *pte;
|
|
|
|
paddr_t pa;
|
|
|
|
|
|
|
|
pte = uvtopte(TRUNC_PAGE(from), (&p->p_addr->u_pcb));
|
|
|
|
if ((vaddr_t)from & PGOFSET) {
|
|
|
|
int cz = ROUND_PAGE(from) - (vaddr_t)from;
|
|
|
|
|
|
|
|
pa = (pte->pg_pfn << VAX_PGSHIFT) | (NBPG - cz) | KERNBASE;
|
|
|
|
bcopy((caddr_t)pa, to, min(cz, len));
|
|
|
|
from += cz;
|
|
|
|
to += cz;
|
|
|
|
len -= cz;
|
|
|
|
pte += 8; /* XXX */
|
|
|
|
}
|
|
|
|
while (len > 0) {
|
|
|
|
pa = (pte->pg_pfn << VAX_PGSHIFT) | KERNBASE;
|
|
|
|
bcopy((caddr_t)pa, to, min(NBPG, len));
|
|
|
|
from += NBPG;
|
|
|
|
to += NBPG;
|
|
|
|
len -= NBPG;
|
|
|
|
pte += 8; /* XXX */
|
|
|
|
}
|
|
|
|
}
|