int gbox_setcmap(struct diofb *fb, struct wsdisplay_cmap *cm) { u_int8_t r[256], g[256], b[256]; u_int index = cm->index, count = cm->count; u_int colcount = 1 << fb->planes; int error; if (index >= colcount || count > colcount - index) return (EINVAL); if ((error = copyin(cm->red, r, count)) != 0) return (error); if ((error = copyin(cm->green, g, count)) != 0) return (error); if ((error = copyin(cm->blue, b, count)) != 0) return (error); bcopy(r, fb->cmap.r + index, count); bcopy(g, fb->cmap.g + index, count); bcopy(b, fb->cmap.b + index, count); while (count-- != 0) gbox_setcolor(fb, index++); return (0); }
int gbox_reset(struct diofb *fb, int scode, struct diofbreg *fbr) { int rc; u_int i; /* XXX don't trust hardware, force defaults */ fb->fbwidth = 1024; fb->fbheight = 1024; fb->dwidth = 1024; fb->dheight = 768; if ((rc = diofb_fbinquire(fb, scode, fbr)) != 0) return (rc); fb->bmv = gbox_windowmove; gbox_restore(fb); /* * Find out how many colors are available by determining * which planes are installed. That is, write all ones to * a frame buffer location, see how many ones are read back. */ if (1 /* fb->planes == 0 */) { volatile u_int8_t *fbp; u_int8_t save; fbp = (u_int8_t *)fb->fbkva; save = *fbp; *fbp = 0xff; fb->planemask = *fbp; *fbp = save; for (fb->planes = 1; fb->planemask >= (1 << fb->planes); fb->planes++); if (fb->planes > 8) fb->planes = 8; fb->planemask = (1 << fb->planes) - 1; } diofb_fbsetup(fb); for (i = 0; i <= fb->planemask; i++) gbox_setcolor(fb, i); return (0); }
int gbox_ioctl(void *v, u_long cmd, caddr_t data, int flags, struct proc *p) { struct diofb *fb = v; struct wsdisplay_fbinfo *wdf; u_int i; switch (cmd) { case WSDISPLAYIO_GTYPE: *(u_int *)data = WSDISPLAY_TYPE_GBOX; break; case WSDISPLAYIO_SMODE: fb->mapmode = *(u_int *)data; if (fb->mapmode == WSDISPLAYIO_MODE_EMUL) { gbox_restore(fb); for (i = 0; i <= fb->planemask; i++) gbox_setcolor(fb, i); } break; case WSDISPLAYIO_GINFO: wdf = (void *)data; wdf->width = fb->ri.ri_width; wdf->height = fb->ri.ri_height; wdf->depth = fb->ri.ri_depth; wdf->cmsize = 1 << fb->planes; break; case WSDISPLAYIO_LINEBYTES: *(u_int *)data = fb->ri.ri_stride; break; case WSDISPLAYIO_GETCMAP: return (diofb_getcmap(fb, (struct wsdisplay_cmap *)data)); case WSDISPLAYIO_PUTCMAP: return (gbox_setcmap(fb, (struct wsdisplay_cmap *)data)); case WSDISPLAYIO_GVIDEO: case WSDISPLAYIO_SVIDEO: break; default: return (-1); } return (0); }
int gbox_ioctl(void *v, void *vs, u_long cmd, void *data, int flags, struct lwp *l) { struct diofb *fb = v; struct wsdisplay_fbinfo *wdf; u_int i; switch (cmd) { case WSDISPLAYIO_GTYPE: *(u_int *)data = WSDISPLAY_TYPE_GBOX; return 0; case WSDISPLAYIO_SMODE: fb->mapmode = *(u_int *)data; if (fb->mapmode == WSDISPLAYIO_MODE_EMUL) { gbox_restore(fb); for (i = 0; i <= fb->planemask; i++) gbox_setcolor(fb, i); } return 0; case WSDISPLAYIO_GINFO: wdf = (void *)data; wdf->width = fb->ri.ri_width; wdf->height = fb->ri.ri_height; wdf->depth = fb->ri.ri_depth; wdf->cmsize = 1 << fb->planes; return 0; case WSDISPLAYIO_LINEBYTES: *(u_int *)data = fb->ri.ri_stride; return 0; case WSDISPLAYIO_GETCMAP: return diofb_getcmap(fb, (struct wsdisplay_cmap *)data); case WSDISPLAYIO_PUTCMAP: return gbox_setcmap(fb, (struct wsdisplay_cmap *)data); case WSDISPLAYIO_GVIDEO: case WSDISPLAYIO_SVIDEO: return EPASSTHROUGH; } return EPASSTHROUGH; }