Annotation of sys/arch/vax/vsa/vsbus.c, Revision 1.1
1.1 ! nbrk 1: /* $OpenBSD: vsbus.c,v 1.18 2006/12/13 21:12:06 miod Exp $ */
! 2: /* $NetBSD: vsbus.c,v 1.29 2000/06/29 07:14:37 mrg Exp $ */
! 3: /*
! 4: * Copyright (c) 1996, 1999 Ludd, University of Lule}, Sweden.
! 5: * All rights reserved.
! 6: *
! 7: * This code is derived from software contributed to Ludd by Bertram Barth.
! 8: *
! 9: * Redistribution and use in source and binary forms, with or without
! 10: * modification, are permitted provided that the following conditions
! 11: * are met:
! 12: * 1. Redistributions of source code must retain the above copyright
! 13: * notice, this list of conditions and the following disclaimer.
! 14: * 2. Redistributions in binary form must reproduce the above copyright
! 15: * notice, this list of conditions and the following disclaimer in the
! 16: * documentation and/or other materials provided with the distribution.
! 17: * 3. All advertising materials mentioning features or use of this software
! 18: * must display the following acknowledgement:
! 19: * This product includes software developed at Ludd, University of
! 20: * Lule}, Sweden and its contributors.
! 21: * 4. The name of the author may not be used to endorse or promote products
! 22: * derived from this software without specific prior written permission
! 23: *
! 24: * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
! 25: * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
! 26: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
! 27: * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
! 28: * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
! 29: * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
! 30: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
! 31: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
! 32: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
! 33: * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
! 34: */
! 35:
! 36: #include <sys/param.h>
! 37: #include <sys/systm.h>
! 38: #include <sys/buf.h>
! 39: #include <sys/conf.h>
! 40: #include <sys/file.h>
! 41: #include <sys/ioctl.h>
! 42: #include <sys/proc.h>
! 43: #include <sys/user.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 <uvm/uvm_extern.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:
! 65: #include <machine/vsbus.h>
! 66:
! 67: int vsbus_match(struct device *, struct cfdata *, void *);
! 68: void vsbus_attach(struct device *, struct device *, void *);
! 69: int vsbus_print(void *, const char *);
! 70: int vsbus_search(struct device *, void *, void *);
! 71:
! 72: static struct vax_bus_dma_tag vsbus_bus_dma_tag = {
! 73: 0,
! 74: 0,
! 75: 0,
! 76: 0,
! 77: 0,
! 78: 0,
! 79: _bus_dmamap_create,
! 80: _bus_dmamap_destroy,
! 81: _bus_dmamap_load,
! 82: _bus_dmamap_load_mbuf,
! 83: _bus_dmamap_load_uio,
! 84: _bus_dmamap_load_raw,
! 85: _bus_dmamap_unload,
! 86: _bus_dmamap_sync,
! 87: _bus_dmamem_alloc,
! 88: _bus_dmamem_free,
! 89: _bus_dmamem_map,
! 90: _bus_dmamem_unmap,
! 91: _bus_dmamem_mmap,
! 92: };
! 93:
! 94: extern struct vax_bus_space vax_mem_bus_space;
! 95: static SIMPLEQ_HEAD(, vsbus_dma) vsbus_dma;
! 96:
! 97: struct cfattach vsbus_ca = {
! 98: sizeof(struct vsbus_softc), (cfmatch_t)vsbus_match, vsbus_attach
! 99: };
! 100:
! 101: struct cfdriver vsbus_cd = {
! 102: NULL, "vsbus", DV_DULL
! 103: };
! 104:
! 105: int oldvsbus;
! 106:
! 107: int
! 108: vsbus_print(aux, name)
! 109: void *aux;
! 110: const char *name;
! 111: {
! 112: struct vsbus_attach_args *va = aux;
! 113:
! 114: printf(" csr 0x%lx vec %d ipl %x maskbit %d", va->va_paddr,
! 115: va->va_cvec & 511, va->va_br, va->va_maskno - 1);
! 116: return(UNCONF);
! 117: }
! 118:
! 119: int
! 120: vsbus_match(parent, cf, aux)
! 121: struct device *parent;
! 122: struct cfdata *cf;
! 123: void *aux;
! 124: {
! 125: struct mainbus_attach_args *maa = aux;
! 126:
! 127: if (maa->maa_bustype == VAX_VSBUS)
! 128: return 1;
! 129: return 0;
! 130: }
! 131:
! 132: void
! 133: vsbus_attach(parent, self, aux)
! 134: struct device *parent, *self;
! 135: void *aux;
! 136: {
! 137: struct vsbus_softc *sc = (void *)self;
! 138: int dbase, dsize;
! 139:
! 140: printf("\n");
! 141:
! 142: sc->sc_dmatag = vsbus_bus_dma_tag;
! 143:
! 144: switch (vax_boardtype) {
! 145: #if VAX49 || VAX53
! 146: case VAX_BTYP_1303:
! 147: case VAX_BTYP_49:
! 148: sc->sc_vsregs = vax_map_physmem(0x25c00000, 1);
! 149: sc->sc_intreq = (char *)sc->sc_vsregs + 12;
! 150: sc->sc_intclr = (char *)sc->sc_vsregs + 12;
! 151: sc->sc_intmsk = (char *)sc->sc_vsregs + 8;
! 152: vsbus_dma_init(sc, 8192);
! 153: break;
! 154: #endif
! 155:
! 156: #if VAX46 || VAX48
! 157: case VAX_BTYP_48:
! 158: case VAX_BTYP_46:
! 159: sc->sc_vsregs = vax_map_physmem(VS_REGS, 1);
! 160: sc->sc_intreq = (char *)sc->sc_vsregs + 15;
! 161: sc->sc_intclr = (char *)sc->sc_vsregs + 15;
! 162: sc->sc_intmsk = (char *)sc->sc_vsregs + 12;
! 163: vsbus_dma_init(sc, 32768);
! 164: break;
! 165: #endif
! 166:
! 167: default:
! 168: sc->sc_vsregs = vax_map_physmem(VS_REGS, 1);
! 169: sc->sc_intreq = (char *)sc->sc_vsregs + 15;
! 170: sc->sc_intclr = (char *)sc->sc_vsregs + 15;
! 171: sc->sc_intmsk = (char *)sc->sc_vsregs + 12;
! 172: if (vax_boardtype == VAX_BTYP_410) {
! 173: dbase = KA410_DMA_BASE;
! 174: dsize = KA410_DMA_SIZE;
! 175: } else {
! 176: dbase = KA420_DMA_BASE;
! 177: dsize = KA420_DMA_SIZE;
! 178: *(char *)(sc->sc_vsregs + 0xe0) = 1; /* Big DMA */
! 179: }
! 180: sc->sc_dmasize = dsize;
! 181: sc->sc_dmaaddr = uvm_km_valloc(kernel_map, dsize);
! 182: ioaccess(sc->sc_dmaaddr, dbase, dsize/VAX_NBPG);
! 183: break;
! 184: }
! 185:
! 186: SIMPLEQ_INIT(&vsbus_dma);
! 187: /*
! 188: * First: find which interrupts we won't care about.
! 189: * There are interrupts that interrupt on a periodic basic
! 190: * that we don't want to interfere with the rest of the
! 191: * interrupt probing.
! 192: */
! 193: *sc->sc_intmsk = 0;
! 194: *sc->sc_intclr = 0xff;
! 195: DELAY(1000000); /* Wait a second */
! 196: sc->sc_mask = *sc->sc_intreq;
! 197:
! 198: #if VAX48
! 199: /*
! 200: * It's possible for the 4000/VLC to generate an DZ-11 rx interrupt
! 201: * (0x20) during the delay period, unmask that bit.
! 202: */
! 203: if (vax_boardtype == VAX_BTYP_48)
! 204: sc->sc_mask &= ~0x20;
! 205: #endif
! 206:
! 207: printf("%s: interrupt mask %x\n", self->dv_xname, sc->sc_mask);
! 208:
! 209: /*
! 210: * now check for all possible devices on this "bus"
! 211: */
! 212: config_search(vsbus_search, self, NULL);
! 213:
! 214: /* Autoconfig finished, enable interrupts */
! 215: *sc->sc_intmsk = ~sc->sc_mask;
! 216: }
! 217:
! 218: int
! 219: vsbus_search(parent, cfd, aux)
! 220: struct device *parent;
! 221: void *cfd;
! 222: void *aux;
! 223: {
! 224: struct vsbus_softc *sc = (void *)parent;
! 225: struct vsbus_attach_args va;
! 226: struct cfdata *cf = cfd;
! 227: int i, vec, br;
! 228: u_char c;
! 229:
! 230: va.va_paddr = cf->cf_loc[0];
! 231: va.va_addr = vax_map_physmem(va.va_paddr, 1);
! 232: va.va_dmat = &sc->sc_dmatag;
! 233: va.va_iot = &vax_mem_bus_space;
! 234:
! 235: *sc->sc_intmsk = 0;
! 236: *sc->sc_intclr = 0xff;
! 237: scb_vecref(0, 0); /* Clear vector ref */
! 238:
! 239: i = (*cf->cf_attach->ca_match) (parent, cf, &va);
! 240: vax_unmap_physmem(va.va_addr, 1);
! 241: c = *sc->sc_intreq & ~sc->sc_mask;
! 242:
! 243: if (i == 0)
! 244: goto forgetit;
! 245: if (i > 10)
! 246: c = sc->sc_mask; /* Fooling interrupt */
! 247: else if (c == 0)
! 248: goto forgetit;
! 249:
! 250: *sc->sc_intmsk = c;
! 251: DELAY(1000);
! 252: *sc->sc_intmsk = 0;
! 253: va.va_maskno = ffs((u_int)c);
! 254: i = scb_vecref(&vec, &br);
! 255: if (i == 0)
! 256: goto fail;
! 257: if (vec == 0)
! 258: goto fail;
! 259:
! 260: /*
! 261: * For proper splassert operation, we need to know if we are on
! 262: * a vsbus system where its devices interrupt at level 0x14 instead
! 263: * of 0x15.
! 264: */
! 265: if (br == 0x14)
! 266: oldvsbus = 1;
! 267:
! 268: va.va_br = br;
! 269: va.va_cvec = vec;
! 270: va.va_dmaaddr = sc->sc_dmaaddr;
! 271: va.va_dmasize = sc->sc_dmasize;
! 272: *sc->sc_intmsk = c; /* Allow interrupts during attach */
! 273: config_attach(parent, cf, &va, vsbus_print);
! 274: *sc->sc_intmsk = 0;
! 275: return 0;
! 276:
! 277: fail:
! 278: printf("%s%d at %s csr 0x%x %s\n",
! 279: cf->cf_driver->cd_name, cf->cf_unit, parent->dv_xname,
! 280: cf->cf_loc[0], (i ? "zero vector" : "didn't interrupt"));
! 281: forgetit:
! 282: return 0;
! 283: }
! 284:
! 285: /*
! 286: * Sets a new interrupt mask. Returns the old one.
! 287: * Works like spl functions.
! 288: */
! 289: unsigned char
! 290: vsbus_setmask(mask)
! 291: unsigned char mask;
! 292: {
! 293: struct vsbus_softc *sc;
! 294: unsigned char ch;
! 295:
! 296: if (vsbus_cd.cd_ndevs == 0)
! 297: return 0;
! 298: sc = vsbus_cd.cd_devs[0];
! 299:
! 300: ch = *sc->sc_intmsk;
! 301: *sc->sc_intmsk = mask;
! 302: return ch;
! 303: }
! 304:
! 305: /*
! 306: * Clears the interrupts in mask.
! 307: */
! 308: void
! 309: vsbus_clrintr(mask)
! 310: unsigned char mask;
! 311: {
! 312: struct vsbus_softc *sc;
! 313:
! 314: if (vsbus_cd.cd_ndevs == 0)
! 315: return;
! 316: sc = vsbus_cd.cd_devs[0];
! 317:
! 318: *sc->sc_intclr = mask;
! 319: }
! 320:
! 321: /*
! 322: * Copy data from/to a user process' space from the DMA area.
! 323: * Use the physical memory directly.
! 324: */
! 325: void
! 326: vsbus_copytoproc(struct proc *p, caddr_t from, caddr_t to, int len)
! 327: {
! 328: pt_entry_t *pte;
! 329: paddr_t pa;
! 330:
! 331: if ((vaddr_t)to & KERNBASE) { /* In kernel space */
! 332: bcopy(from, to, len);
! 333: return;
! 334: }
! 335: pte = uvtopte(TRUNC_PAGE(to), (&p->p_addr->u_pcb));
! 336: if ((vaddr_t)to & PGOFSET) {
! 337: int cz = ROUND_PAGE(to) - (vaddr_t)to;
! 338:
! 339: pa = ((*pte & PG_FRAME) << VAX_PGSHIFT) |
! 340: (NBPG - cz) | KERNBASE;
! 341: bcopy(from, (caddr_t)pa, min(cz, len));
! 342: from += cz;
! 343: to += cz;
! 344: len -= cz;
! 345: pte += 8; /* XXX */
! 346: }
! 347: while (len > 0) {
! 348: pa = ((*pte & PG_FRAME) << VAX_PGSHIFT) | KERNBASE;
! 349: bcopy(from, (caddr_t)pa, min(NBPG, len));
! 350: from += NBPG;
! 351: to += NBPG;
! 352: len -= NBPG;
! 353: pte += 8; /* XXX */
! 354: }
! 355: }
! 356:
! 357: void
! 358: vsbus_copyfromproc(struct proc *p, caddr_t from, caddr_t to, int len)
! 359: {
! 360: pt_entry_t *pte;
! 361: paddr_t pa;
! 362:
! 363: if ((vaddr_t)from & KERNBASE) { /* In kernel space */
! 364: bcopy(from, to, len);
! 365: return;
! 366: }
! 367: pte = uvtopte(TRUNC_PAGE(from), (&p->p_addr->u_pcb));
! 368: if ((vaddr_t)from & PGOFSET) {
! 369: int cz = ROUND_PAGE(from) - (vaddr_t)from;
! 370:
! 371: pa = ((*pte & PG_FRAME) << VAX_PGSHIFT) |
! 372: (NBPG - cz) | KERNBASE;
! 373: bcopy((caddr_t)pa, to, min(cz, len));
! 374: from += cz;
! 375: to += cz;
! 376: len -= cz;
! 377: pte += 8; /* XXX */
! 378: }
! 379: while (len > 0) {
! 380: pa = ((*pte & PG_FRAME) << VAX_PGSHIFT) | KERNBASE;
! 381: bcopy((caddr_t)pa, to, min(NBPG, len));
! 382: from += NBPG;
! 383: to += NBPG;
! 384: len -= NBPG;
! 385: pte += 8; /* XXX */
! 386: }
! 387: }
! 388:
! 389: /*
! 390: * There can only be one user of the DMA area on VS2k/VS3100 at one
! 391: * time, so keep track of it here.
! 392: */
! 393: static int vsbus_active = 0;
! 394:
! 395: void
! 396: vsbus_dma_start(struct vsbus_dma *vd)
! 397: {
! 398:
! 399: SIMPLEQ_INSERT_TAIL(&vsbus_dma, vd, vd_q);
! 400:
! 401: if (vsbus_active == 0)
! 402: vsbus_dma_intr();
! 403: }
! 404:
! 405: void
! 406: vsbus_dma_intr(void)
! 407: {
! 408: struct vsbus_dma *vd;
! 409:
! 410: vd = SIMPLEQ_FIRST(&vsbus_dma);
! 411: if (vd == NULL) {
! 412: vsbus_active = 0;
! 413: return;
! 414: }
! 415: vsbus_active = 1;
! 416: SIMPLEQ_REMOVE_HEAD(&vsbus_dma, vd_q);
! 417: (*vd->vd_go)(vd->vd_arg);
! 418: }
! 419:
CVSweb