Annotation of sys/arch/hp300/dev/rbox.c, Revision 1.1
1.1 ! nbrk 1: /* $OpenBSD: rbox.c,v 1.14 2006/08/11 18:33:13 miod Exp $ */
! 2:
! 3: /*
! 4: * Copyright (c) 2005, Miodrag Vallat
! 5: *
! 6: * Redistribution and use in source and binary forms, with or without
! 7: * modification, are permitted provided that the following conditions
! 8: * are met:
! 9: * 1. Redistributions of source code must retain the above copyright
! 10: * notice, this list of conditions and the following disclaimer.
! 11: * 2. Redistributions in binary form must reproduce the above copyright
! 12: * notice, this list of conditions and the following disclaimer in the
! 13: * documentation and/or other materials provided with the distribution.
! 14: *
! 15: * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
! 16: * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
! 17: * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
! 18: * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
! 19: * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
! 20: * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
! 21: * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
! 22: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
! 23: * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
! 24: * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
! 25: * POSSIBILITY OF SUCH DAMAGE.
! 26: */
! 27: /*
! 28: * Copyright (c) 1996 Jason R. Thorpe. All rights reserved.
! 29: * Copyright (c) 1988 University of Utah.
! 30: * Copyright (c) 1990, 1993
! 31: * The Regents of the University of California. All rights reserved.
! 32: *
! 33: * This code is derived from software contributed to Berkeley by
! 34: * the Systems Programming Group of the University of Utah Computer
! 35: * Science Department.
! 36: *
! 37: * Redistribution and use in source and binary forms, with or without
! 38: * modification, are permitted provided that the following conditions
! 39: * are met:
! 40: * 1. Redistributions of source code must retain the above copyright
! 41: * notice, this list of conditions and the following disclaimer.
! 42: * 2. Redistributions in binary form must reproduce the above copyright
! 43: * notice, this list of conditions and the following disclaimer in the
! 44: * documentation and/or other materials provided with the distribution.
! 45: * 3. Neither the name of the University nor the names of its contributors
! 46: * may be used to endorse or promote products derived from this software
! 47: * without specific prior written permission.
! 48: *
! 49: * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
! 50: * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
! 51: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
! 52: * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
! 53: * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
! 54: * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
! 55: * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
! 56: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
! 57: * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
! 58: * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
! 59: * SUCH DAMAGE.
! 60: *
! 61: * from: Utah $Hdr: grf_rb.c 1.15 93/08/13$
! 62: *
! 63: * @(#)grf_rb.c 8.4 (Berkeley) 1/12/94
! 64: */
! 65:
! 66: /*
! 67: * Graphics routines for the Renaissance, HP98720 Graphics system.
! 68: */
! 69:
! 70: #include <sys/param.h>
! 71: #include <sys/systm.h>
! 72: #include <sys/conf.h>
! 73: #include <sys/device.h>
! 74: #include <sys/proc.h>
! 75: #include <sys/ioctl.h>
! 76:
! 77: #include <machine/autoconf.h>
! 78: #include <machine/bus.h>
! 79: #include <machine/cpu.h>
! 80:
! 81: #include <hp300/dev/dioreg.h>
! 82: #include <hp300/dev/diovar.h>
! 83: #include <hp300/dev/diodevs.h>
! 84: #include <hp300/dev/intiovar.h>
! 85:
! 86: #include <dev/wscons/wsconsio.h>
! 87: #include <dev/wscons/wsdisplayvar.h>
! 88: #include <dev/rasops/rasops.h>
! 89:
! 90: #include <hp300/dev/diofbreg.h>
! 91: #include <hp300/dev/diofbvar.h>
! 92: #include <hp300/dev/rboxreg.h>
! 93:
! 94: struct rbox_softc {
! 95: struct device sc_dev;
! 96: struct diofb *sc_fb;
! 97: struct diofb sc_fb_store;
! 98: int sc_scode;
! 99: };
! 100:
! 101: int rbox_dio_match(struct device *, void *, void *);
! 102: void rbox_dio_attach(struct device *, struct device *, void *);
! 103: int rbox_intio_match(struct device *, void *, void *);
! 104: void rbox_intio_attach(struct device *, struct device *, void *);
! 105:
! 106: struct cfattach rbox_dio_ca = {
! 107: sizeof(struct rbox_softc), rbox_dio_match, rbox_dio_attach
! 108: };
! 109:
! 110: struct cfattach rbox_intio_ca = {
! 111: sizeof(struct rbox_softc), rbox_intio_match, rbox_intio_attach
! 112: };
! 113:
! 114: struct cfdriver rbox_cd = {
! 115: NULL, "rbox", DV_DULL
! 116: };
! 117:
! 118: int rbox_reset(struct diofb *, int, struct diofbreg *);
! 119: void rbox_restore(struct diofb *);
! 120: void rbox_setcolor(struct diofb *, u_int,
! 121: u_int8_t, u_int8_t, u_int8_t);
! 122: int rbox_windowmove(struct diofb *, u_int16_t, u_int16_t, u_int16_t,
! 123: u_int16_t, u_int16_t, u_int16_t, int16_t, int16_t);
! 124:
! 125: int rbox_ioctl(void *, u_long, caddr_t, int, struct proc *);
! 126: void rbox_burner(void *, u_int, u_int);
! 127:
! 128: struct wsdisplay_accessops rbox_accessops = {
! 129: rbox_ioctl,
! 130: diofb_mmap,
! 131: diofb_alloc_screen,
! 132: diofb_free_screen,
! 133: diofb_show_screen,
! 134: NULL, /* load_font */
! 135: NULL, /* scrollback */
! 136: NULL, /* getchar */
! 137: rbox_burner
! 138: };
! 139:
! 140: /*
! 141: * Attachment glue
! 142: */
! 143:
! 144: int
! 145: rbox_intio_match(struct device *parent, void *match, void *aux)
! 146: {
! 147: struct intio_attach_args *ia = aux;
! 148: struct diofbreg *fbr;
! 149:
! 150: fbr = (struct diofbreg *)IIOV(GRFIADDR);
! 151:
! 152: if (badaddr((caddr_t)fbr))
! 153: return (0);
! 154:
! 155: if (fbr->id == GRFHWID && fbr->fbid == GID_RENAISSANCE) {
! 156: ia->ia_addr = (caddr_t)GRFIADDR;
! 157: return (1);
! 158: }
! 159:
! 160: return (0);
! 161: }
! 162:
! 163: void
! 164: rbox_intio_attach(struct device *parent, struct device *self, void *aux)
! 165: {
! 166: struct rbox_softc *sc = (struct rbox_softc *)self;
! 167: struct diofbreg *fbr;
! 168:
! 169: fbr = (struct diofbreg *)IIOV(GRFIADDR);
! 170: sc->sc_scode = CONSCODE_INTERNAL;
! 171:
! 172: if (sc->sc_scode == conscode) {
! 173: sc->sc_fb = &diofb_cn;
! 174: } else {
! 175: sc->sc_fb = &sc->sc_fb_store;
! 176: rbox_reset(sc->sc_fb, sc->sc_scode, fbr);
! 177: }
! 178:
! 179: diofb_end_attach(sc, &rbox_accessops, sc->sc_fb,
! 180: sc->sc_scode == conscode, NULL);
! 181: }
! 182:
! 183: int
! 184: rbox_dio_match(struct device *parent, void *match, void *aux)
! 185: {
! 186: struct dio_attach_args *da = aux;
! 187:
! 188: if (da->da_id == DIO_DEVICE_ID_FRAMEBUFFER &&
! 189: da->da_secid == DIO_DEVICE_SECID_RENAISSANCE)
! 190: return (1);
! 191:
! 192: return (0);
! 193: }
! 194:
! 195: void
! 196: rbox_dio_attach(struct device *parent, struct device *self, void *aux)
! 197: {
! 198: struct rbox_softc *sc = (struct rbox_softc *)self;
! 199: struct dio_attach_args *da = aux;
! 200: struct diofbreg *fbr;
! 201:
! 202: sc->sc_scode = da->da_scode;
! 203: if (sc->sc_scode == conscode) {
! 204: fbr = (struct diofbreg *)conaddr; /* already mapped */
! 205: sc->sc_fb = &diofb_cn;
! 206: } else {
! 207: sc->sc_fb = &sc->sc_fb_store;
! 208: fbr = (struct diofbreg *)
! 209: iomap(dio_scodetopa(sc->sc_scode), da->da_size);
! 210: if (fbr == NULL ||
! 211: rbox_reset(sc->sc_fb, sc->sc_scode, fbr) != 0) {
! 212: printf(": can't map framebuffer\n");
! 213: return;
! 214: }
! 215: }
! 216:
! 217: diofb_end_attach(sc, &rbox_accessops, sc->sc_fb,
! 218: sc->sc_scode == conscode, NULL);
! 219: }
! 220:
! 221: /*
! 222: * Initialize hardware and display routines.
! 223: */
! 224: int
! 225: rbox_reset(struct diofb *fb, int scode, struct diofbreg *fbr)
! 226: {
! 227: int rc;
! 228:
! 229: if ((rc = diofb_fbinquire(fb, scode, fbr)) != 0)
! 230: return (rc);
! 231:
! 232: /*
! 233: * Restrict the framebuffer to a monochrome view for now, until
! 234: * I know better how to detect and frob overlay planes, and
! 235: * setup a proper colormap. -- miod
! 236: */
! 237: fb->planes = fb->planemask = 1;
! 238:
! 239: fb->bmv = rbox_windowmove;
! 240: rbox_restore(fb);
! 241: diofb_fbsetup(fb);
! 242:
! 243: return (0);
! 244: }
! 245:
! 246: void
! 247: rbox_restore(struct diofb *fb)
! 248: {
! 249: volatile struct rboxfb *rb = (struct rboxfb *)fb->regkva;
! 250: u_int i;
! 251:
! 252: rb_waitbusy(rb);
! 253:
! 254: rb->regs.id = GRFHWID; /* trigger reset */
! 255: DELAY(1000);
! 256:
! 257: rb->regs.interrupt = 0x04;
! 258: rb->video_enable = 0x01;
! 259: rb->drive = 0x01;
! 260: rb->vdrive = 0x0;
! 261:
! 262: rb->opwen = 0xFF;
! 263:
! 264: /*
! 265: * Clear color map
! 266: */
! 267: rb_waitbusy(fb->regkva);
! 268: for (i = 0; i < 16; i++) {
! 269: *(fb->regkva + 0x63c3 + i*4) = 0x0;
! 270: *(fb->regkva + 0x6403 + i*4) = 0x0;
! 271: *(fb->regkva + 0x6803 + i*4) = 0x0;
! 272: *(fb->regkva + 0x6c03 + i*4) = 0x0;
! 273: *(fb->regkva + 0x73c3 + i*4) = 0x0;
! 274: *(fb->regkva + 0x7403 + i*4) = 0x0;
! 275: *(fb->regkva + 0x7803 + i*4) = 0x0;
! 276: *(fb->regkva + 0x7c03 + i*4) = 0x0;
! 277: }
! 278:
! 279: rb->rep_rule = RBOX_DUALROP(RR_COPY);
! 280:
! 281: /*
! 282: * I cannot figure out how to make the blink planes stop. So, we
! 283: * must set both colormaps so that when the planes blink, and
! 284: * the secondary colormap is active, we still get text.
! 285: */
! 286: CM1RED(fb)[0x00].value = 0x00;
! 287: CM1GRN(fb)[0x00].value = 0x00;
! 288: CM1BLU(fb)[0x00].value = 0x00;
! 289: CM1RED(fb)[0x01].value = 0xFF;
! 290: CM1GRN(fb)[0x01].value = 0xFF;
! 291: CM1BLU(fb)[0x01].value = 0xFF;
! 292:
! 293: CM2RED(fb)[0x00].value = 0x00;
! 294: CM2GRN(fb)[0x00].value = 0x00;
! 295: CM2BLU(fb)[0x00].value = 0x00;
! 296: CM2RED(fb)[0x01].value = 0xFF;
! 297: CM2GRN(fb)[0x01].value = 0xFF;
! 298: CM2BLU(fb)[0x01].value = 0xFF;
! 299:
! 300: rb->blink = 0x00;
! 301: rb->write_enable = 0x01;
! 302: rb->opwen = 0x00;
! 303:
! 304: /* enable display */
! 305: rb->display_enable = 0x01;
! 306: }
! 307:
! 308: int
! 309: rbox_ioctl(void *v, u_long cmd, caddr_t data, int flags, struct proc *p)
! 310: {
! 311: struct diofb *fb = v;
! 312: struct wsdisplay_fbinfo *wdf;
! 313:
! 314: switch (cmd) {
! 315: case WSDISPLAYIO_GTYPE:
! 316: *(u_int *)data = WSDISPLAY_TYPE_RBOX;
! 317: break;
! 318: case WSDISPLAYIO_SMODE:
! 319: fb->mapmode = *(u_int *)data;
! 320: if (fb->mapmode == WSDISPLAYIO_MODE_EMUL)
! 321: rbox_restore(fb);
! 322: break;
! 323: case WSDISPLAYIO_GINFO:
! 324: wdf = (void *)data;
! 325: wdf->width = fb->ri.ri_width;
! 326: wdf->height = fb->ri.ri_height;
! 327: wdf->depth = fb->ri.ri_depth;
! 328: wdf->cmsize = 0; /* XXX */
! 329: break;
! 330: case WSDISPLAYIO_LINEBYTES:
! 331: *(u_int *)data = fb->ri.ri_stride;
! 332: break;
! 333: case WSDISPLAYIO_GETCMAP:
! 334: case WSDISPLAYIO_PUTCMAP:
! 335: break; /* XXX until color support is implemented */
! 336: break;
! 337: case WSDISPLAYIO_GVIDEO:
! 338: case WSDISPLAYIO_SVIDEO:
! 339: break;
! 340: default:
! 341: return (-1);
! 342: }
! 343:
! 344: return (0);
! 345: }
! 346:
! 347: void
! 348: rbox_burner(void *v, u_int on, u_int flags)
! 349: {
! 350: struct diofb *fb = v;
! 351: volatile struct rboxfb *rb = (struct rboxfb *)fb->regkva;
! 352:
! 353: if (on) {
! 354: rb->display_enable = 0x01;
! 355: } else {
! 356: rb->display_enable = 0x00;
! 357: }
! 358: }
! 359:
! 360: int
! 361: rbox_windowmove(struct diofb *fb, u_int16_t sx, u_int16_t sy,
! 362: u_int16_t dx, u_int16_t dy, u_int16_t cx, u_int16_t cy, int16_t rop,
! 363: int16_t planemask)
! 364: {
! 365: volatile struct rboxfb *rb = (struct rboxfb *)fb->regkva;
! 366:
! 367: if (planemask != 0xff)
! 368: return (EINVAL);
! 369:
! 370: rb_waitbusy(rb);
! 371:
! 372: rb->rep_rule = RBOX_DUALROP(rop);
! 373: rb->source_y = sy;
! 374: rb->source_x = sx;
! 375: rb->dest_y = dy;
! 376: rb->dest_x = dx;
! 377: rb->wheight = cy;
! 378: rb->wwidth = cx;
! 379: rb->wmove = 1;
! 380:
! 381: rb_waitbusy(rb);
! 382:
! 383: return (0);
! 384: }
! 385:
! 386: /*
! 387: * Renaissance console support
! 388: */
! 389:
! 390: void
! 391: rboxcninit()
! 392: {
! 393: rbox_reset(&diofb_cn, conscode, (struct diofbreg *)conaddr);
! 394: diofb_cnattach(&diofb_cn);
! 395: }
CVSweb