Annotation of sys/arch/sparc64/dev/fb.c, Revision 1.1
1.1 ! nbrk 1: /* $OpenBSD: fb.c,v 1.16 2006/12/03 16:41:58 miod Exp $ */
! 2: /* $NetBSD: fb.c,v 1.23 1997/07/07 23:30:22 pk Exp $ */
! 3:
! 4: /*
! 5: * Copyright (c) 2002, 2004 Miodrag Vallat.
! 6: * All rights reserved.
! 7: *
! 8: * Redistribution and use in source and binary forms, with or without
! 9: * modification, are permitted provided that the following conditions
! 10: * are met:
! 11: * 1. Redistributions of source code must retain the above copyright
! 12: * notice, this list of conditions and the following disclaimer.
! 13: * 2. Redistributions in binary form must reproduce the above copyright
! 14: * notice, this list of conditions and the following disclaimer in the
! 15: * documentation and/or other materials provided with the distribution.
! 16: *
! 17: * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
! 18: * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
! 19: * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
! 20: * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
! 21: * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
! 22: * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
! 23: * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
! 24: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
! 25: * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
! 26: * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
! 27: * POSSIBILITY OF SUCH DAMAGE.
! 28: *
! 29: *
! 30: * Copyright (c) 1992, 1993
! 31: * The Regents of the University of California. All rights reserved.
! 32: *
! 33: * This software was developed by the Computer Systems Engineering group
! 34: * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
! 35: * contributed to Berkeley.
! 36: *
! 37: * All advertising materials mentioning features or use of this software
! 38: * must display the following acknowledgement:
! 39: * This product includes software developed by the University of
! 40: * California, Lawrence Berkeley Laboratory.
! 41: *
! 42: * Redistribution and use in source and binary forms, with or without
! 43: * modification, are permitted provided that the following conditions
! 44: * are met:
! 45: * 1. Redistributions of source code must retain the above copyright
! 46: * notice, this list of conditions and the following disclaimer.
! 47: * 2. Redistributions in binary form must reproduce the above copyright
! 48: * notice, this list of conditions and the following disclaimer in the
! 49: * documentation and/or other materials provided with the distribution.
! 50: * 3. Neither the name of the University nor the names of its contributors
! 51: * may be used to endorse or promote products derived from this software
! 52: * without specific prior written permission.
! 53: *
! 54: * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
! 55: * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
! 56: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
! 57: * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
! 58: * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
! 59: * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
! 60: * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
! 61: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
! 62: * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
! 63: * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
! 64: * SUCH DAMAGE.
! 65: *
! 66: * @(#)fb.c 8.1 (Berkeley) 6/11/93
! 67: */
! 68:
! 69: /*
! 70: * Common wsdisplay framebuffer drivers helpers.
! 71: */
! 72:
! 73: #include <sys/param.h>
! 74: #include <sys/systm.h>
! 75: #include <sys/device.h>
! 76: #include <sys/proc.h>
! 77: #include <sys/conf.h>
! 78:
! 79: #include <machine/autoconf.h>
! 80: #include <machine/conf.h>
! 81:
! 82: #include <dev/wscons/wsdisplayvar.h>
! 83: #include <dev/rasops/rasops.h>
! 84: #include <machine/fbvar.h>
! 85:
! 86: #include "wsdisplay.h"
! 87:
! 88: /*
! 89: * Sun specific color indexes.
! 90: * Black is not really 7, but rather ~0; to fit within the 8 ANSI color
! 91: * palette we are using on console, we pick (~0) & 0x07 instead.
! 92: * This essentially swaps WSCOL_BLACK and WSCOL_WHITE.
! 93: */
! 94: #define WSCOL_SUN_WHITE 0
! 95: #define WSCOL_SUN_BLACK 7
! 96:
! 97: /*
! 98: * emergency unblank code
! 99: * XXX should be somewhat moved to wscons MI code
! 100: */
! 101:
! 102: void (*fb_burner)(void *, u_int, u_int);
! 103: void *fb_cookie;
! 104:
! 105: void
! 106: fb_unblank()
! 107: {
! 108: if (fb_burner != NULL)
! 109: (*fb_burner)(fb_cookie, 1, 0);
! 110: }
! 111:
! 112: #if NWSDISPLAY > 0
! 113:
! 114: static int a2int(char *, int);
! 115: static void fb_initwsd(struct sunfb *);
! 116: static void fb_updatecursor(struct rasops_info *);
! 117:
! 118: void
! 119: fb_setsize(struct sunfb *sf, int def_depth, int def_width, int def_height,
! 120: int node, int unused)
! 121: {
! 122: int def_linebytes;
! 123:
! 124: sf->sf_depth = getpropint(node, "depth", def_depth);
! 125: sf->sf_width = getpropint(node, "width", def_width);
! 126: sf->sf_height = getpropint(node, "height", def_height);
! 127:
! 128: def_linebytes =
! 129: roundup(sf->sf_width, sf->sf_depth) * sf->sf_depth / 8;
! 130: sf->sf_linebytes = getpropint(node, "linebytes", def_linebytes);
! 131: /*
! 132: * XXX If we are configuring a board in a wider depth level
! 133: * than the mode it is currently operating in, the PROM will
! 134: * return a linebytes property tied to the current depth value,
! 135: * which is NOT what we are relying upon!
! 136: */
! 137: if (sf->sf_linebytes < (sf->sf_width * sf->sf_depth) / 8) {
! 138: sf->sf_linebytes = def_linebytes;
! 139: }
! 140:
! 141: sf->sf_fbsize = sf->sf_height * sf->sf_linebytes;
! 142: }
! 143:
! 144: static int
! 145: a2int(char *cp, int deflt)
! 146: {
! 147: int i = 0;
! 148:
! 149: if (*cp == '\0')
! 150: return (deflt);
! 151: while (*cp != '\0')
! 152: i = i * 10 + *cp++ - '0';
! 153: return (i);
! 154: }
! 155:
! 156: /* setup the embedded wsscreen_descr structure from rasops settings */
! 157: static void
! 158: fb_initwsd(struct sunfb *sf)
! 159: {
! 160: strlcpy(sf->sf_wsd.name, "std", sizeof(sf->sf_wsd.name));
! 161: sf->sf_wsd.capabilities = sf->sf_ro.ri_caps;
! 162: sf->sf_wsd.nrows = sf->sf_ro.ri_rows;
! 163: sf->sf_wsd.ncols = sf->sf_ro.ri_cols;
! 164: sf->sf_wsd.textops = &sf->sf_ro.ri_ops;
! 165: }
! 166:
! 167: static void
! 168: fb_updatecursor(struct rasops_info *ri)
! 169: {
! 170: struct sunfb *sf = (struct sunfb *)ri->ri_hw;
! 171:
! 172: if (sf->sf_crowp != NULL)
! 173: *sf->sf_crowp = ri->ri_crow;
! 174: if (sf->sf_ccolp != NULL)
! 175: *sf->sf_ccolp = ri->ri_ccol;
! 176: }
! 177:
! 178: void
! 179: fbwscons_init(struct sunfb *sf, int flags)
! 180: {
! 181: struct rasops_info *ri = &sf->sf_ro;
! 182: int cols, rows;
! 183:
! 184: /* ri_hw and ri_bits must have already been setup by caller */
! 185: ri->ri_flg = RI_CENTER | RI_FULLCLEAR | flags;
! 186: ri->ri_depth = sf->sf_depth;
! 187: ri->ri_stride = sf->sf_linebytes;
! 188: ri->ri_width = sf->sf_width;
! 189: ri->ri_height = sf->sf_height;
! 190:
! 191: rows = a2int(getpropstring(optionsnode, "screen-#rows"), 34);
! 192: cols = a2int(getpropstring(optionsnode, "screen-#columns"), 80);
! 193:
! 194: rasops_init(ri, rows, cols);
! 195:
! 196: if (sf->sf_depth == 8) {
! 197: /*
! 198: * If we are running with an indexed palette, compensate
! 199: * the swap of black and white through ri_devcmap.
! 200: */
! 201: ri->ri_devcmap[WSCOL_SUN_BLACK] = 0;
! 202: ri->ri_devcmap[WSCOL_SUN_WHITE] = 0xffffffff;
! 203: } else if (sf->sf_depth > 8) {
! 204: /*
! 205: * If we are running on a direct color frame buffer,
! 206: * make the ``normal'' white the same as the highlighted
! 207: * white.
! 208: */
! 209: ri->ri_devcmap[WSCOL_WHITE] = ri->ri_devcmap[WSCOL_WHITE + 8];
! 210: }
! 211: }
! 212:
! 213: void
! 214: fbwscons_console_init(struct sunfb *sf, int row)
! 215: {
! 216: struct rasops_info *ri = &sf->sf_ro;
! 217: long defattr;
! 218:
! 219: if (romgetcursoraddr(&sf->sf_crowp, &sf->sf_ccolp))
! 220: sf->sf_ccolp = sf->sf_crowp = NULL;
! 221: if (sf->sf_ccolp != NULL)
! 222: ri->ri_ccol = *sf->sf_ccolp;
! 223:
! 224: if (row < 0) {
! 225: if (sf->sf_crowp != NULL)
! 226: ri->ri_crow = *sf->sf_crowp;
! 227: else
! 228: /* assume last row */
! 229: ri->ri_crow = ri->ri_rows - 1;
! 230: } else {
! 231: /*
! 232: * If we force the display row, this is because the screen
! 233: * has been cleared or the font has been changed.
! 234: * In this case, choose not to keep pointers to the PROM
! 235: * cursor position, as the values are likely to be inaccurate
! 236: * upon shutdown...
! 237: */
! 238: sf->sf_crowp = sf->sf_ccolp = NULL;
! 239: ri->ri_crow = row;
! 240: }
! 241:
! 242: /*
! 243: * Scale back rows and columns if the font would not otherwise
! 244: * fit on this display. Without this we would panic later.
! 245: */
! 246: if (ri->ri_crow >= ri->ri_rows)
! 247: ri->ri_crow = ri->ri_rows - 1;
! 248: if (ri->ri_ccol >= ri->ri_cols)
! 249: ri->ri_ccol = ri->ri_cols - 1;
! 250:
! 251: /*
! 252: * Take care of updating the PROM cursor position as weel if we can.
! 253: */
! 254: if (ri->ri_updatecursor != NULL &&
! 255: (sf->sf_ccolp != NULL || sf->sf_crowp != NULL))
! 256: ri->ri_updatecursor = fb_updatecursor;
! 257:
! 258: if (ISSET(ri->ri_caps, WSSCREEN_WSCOLORS))
! 259: ri->ri_ops.alloc_attr(ri,
! 260: WSCOL_BLACK, WSCOL_WHITE, WSATTR_WSCOLORS, &defattr);
! 261: else
! 262: ri->ri_ops.alloc_attr(ri, 0, 0, 0, &defattr);
! 263:
! 264: fb_initwsd(sf);
! 265: wsdisplay_cnattach(&sf->sf_wsd, ri, ri->ri_ccol, ri->ri_crow, defattr);
! 266: }
! 267:
! 268: void
! 269: fbwscons_setcolormap(struct sunfb *sf,
! 270: void (*setcolor)(void *, u_int, u_int8_t, u_int8_t, u_int8_t))
! 271: {
! 272: int i;
! 273: const u_char *color;
! 274:
! 275: if (sf->sf_depth <= 8 && setcolor != NULL) {
! 276: for (i = 0; i < 16; i++) {
! 277: color = &rasops_cmap[i * 3];
! 278: setcolor(sf, i, color[0], color[1], color[2]);
! 279: }
! 280: for (i = 240; i < 256; i++) {
! 281: color = &rasops_cmap[i * 3];
! 282: setcolor(sf, i, color[0], color[1], color[2]);
! 283: }
! 284: /*
! 285: * Compensate for BoW default hardware palette: existing
! 286: * output (which we do not want to affect) is black on
! 287: * white with color index 0 being white and 0xff being
! 288: * black.
! 289: */
! 290: setcolor(sf, WSCOL_SUN_WHITE, 0xff, 0xff, 0xff);
! 291: setcolor(sf, 0xff ^ WSCOL_SUN_WHITE, 0, 0, 0);
! 292: setcolor(sf, WSCOL_SUN_BLACK, 0, 0, 0);
! 293: setcolor(sf, 0xff ^ (WSCOL_SUN_BLACK), 0xff, 0xff, 0xff);
! 294: }
! 295: }
! 296:
! 297: void
! 298: fbwscons_attach(struct sunfb *sf, struct wsdisplay_accessops *op, int isconsole)
! 299: {
! 300: struct wsemuldisplaydev_attach_args waa;
! 301:
! 302: if (isconsole == 0) {
! 303: /* done in wsdisplay_cnattach() earlier if console */
! 304: fb_initwsd(sf);
! 305: } else {
! 306: /* remember screen burner routine */
! 307: fb_burner = op->burn_screen;
! 308: fb_cookie = sf;
! 309: }
! 310:
! 311: sf->sf_scrlist[0] = &sf->sf_wsd;
! 312: sf->sf_wsl.nscreens = 1;
! 313: sf->sf_wsl.screens = (const struct wsscreen_descr **)sf->sf_scrlist;
! 314:
! 315: waa.console = isconsole;
! 316: waa.scrdata = &sf->sf_wsl;
! 317: waa.accessops = op;
! 318: waa.accesscookie = sf;
! 319: waa.defaultscreens = 0;
! 320: config_found(&sf->sf_dev, &waa, wsemuldisplaydevprint);
! 321: }
! 322:
! 323: #endif /* NWSDISPLAY */
CVSweb