[bbf5657] | 1 | /*
|
---|
[76fca31] | 2 | * Copyright (c) 2008 Martin Decky
|
---|
[df4ed85] | 3 | * Copyright (c) 2006 Ondrej Palkovsky
|
---|
[bbf5657] | 4 | * All rights reserved.
|
---|
| 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 | *
|
---|
| 10 | * - Redistributions of source code must retain the above copyright
|
---|
| 11 | * notice, this list of conditions and the following disclaimer.
|
---|
| 12 | * - Redistributions in binary form must reproduce the above copyright
|
---|
| 13 | * notice, this list of conditions and the following disclaimer in the
|
---|
| 14 | * documentation and/or other materials provided with the distribution.
|
---|
| 15 | * - The name of the author may not be used to endorse or promote products
|
---|
| 16 | * derived from this software without specific prior written permission.
|
---|
| 17 | *
|
---|
| 18 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
---|
| 19 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
---|
| 20 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
---|
| 21 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
---|
| 22 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
---|
| 23 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
---|
| 24 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
---|
| 25 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
| 26 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
---|
| 27 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
| 28 | */
|
---|
| 29 |
|
---|
[76fca31] | 30 | /** @addtogroup genarch
|
---|
[b45c443] | 31 | * @{
|
---|
| 32 | */
|
---|
| 33 | /** @file
|
---|
| 34 | */
|
---|
| 35 |
|
---|
[fe050b7] | 36 | #include <genarch/fb/font-8x16.h>
|
---|
| 37 | #include <genarch/fb/fb.h>
|
---|
[bbf5657] | 38 | #include <console/chardev.h>
|
---|
| 39 | #include <console/console.h>
|
---|
[2666daa] | 40 | #include <sysinfo/sysinfo.h>
|
---|
[d4673296] | 41 | #include <mm/km.h>
|
---|
[74d1d66] | 42 | #include <mm/slab.h>
|
---|
[76fca31] | 43 | #include <align.h>
|
---|
[fcbca14f] | 44 | #include <panic.h>
|
---|
[d87c3f3] | 45 | #include <memstr.h>
|
---|
[74d1d66] | 46 | #include <config.h>
|
---|
[6eb96fce] | 47 | #include <bitops.h>
|
---|
| 48 | #include <print.h>
|
---|
[19f857a] | 49 | #include <str.h>
|
---|
[f8ddd17] | 50 | #include <ddi/ddi.h>
|
---|
[d99c1d2] | 51 | #include <typedefs.h>
|
---|
[30885b9] | 52 | #include <byteorder.h>
|
---|
[bbf5657] | 53 |
|
---|
[d2b66d4] | 54 | #define BG_COLOR 0x001620
|
---|
| 55 | #define FG_COLOR 0xf3cf65
|
---|
[a71c158] | 56 | #define INV_COLOR 0xaaaaaa
|
---|
[6e71a9d8] | 57 |
|
---|
[a71c158] | 58 | #define RED(x, bits) (((x) >> (8 + 8 + 8 - (bits))) & ((1 << (bits)) - 1))
|
---|
| 59 | #define GREEN(x, bits) (((x) >> (8 + 8 - (bits))) & ((1 << (bits)) - 1))
|
---|
| 60 | #define BLUE(x, bits) (((x) >> (8 - (bits))) & ((1 << (bits)) - 1))
|
---|
[76fca31] | 61 |
|
---|
[a71c158] | 62 | #define COL2X(col) ((col) * FONT_WIDTH)
|
---|
| 63 | #define ROW2Y(row) ((row) * FONT_SCANLINES)
|
---|
[bbf5657] | 64 |
|
---|
[a71c158] | 65 | #define X2COL(x) ((x) / FONT_WIDTH)
|
---|
| 66 | #define Y2ROW(y) ((y) / FONT_SCANLINES)
|
---|
[bbf5657] | 67 |
|
---|
[a71c158] | 68 | #define FB_POS(instance, x, y) \
|
---|
| 69 | ((y) * (instance)->scanline + (x) * (instance)->pixelbytes)
|
---|
[a2c4445] | 70 |
|
---|
[a71c158] | 71 | #define BB_POS(instance, col, row) \
|
---|
| 72 | ((row) * (instance)->cols + (col))
|
---|
[a2c4445] | 73 |
|
---|
[a71c158] | 74 | #define GLYPH_POS(instance, glyph, y) \
|
---|
| 75 | ((glyph) * (instance)->glyphbytes + (y) * (instance)->glyphscanline)
|
---|
[95c7526] | 76 |
|
---|
[a71c158] | 77 | typedef void (* rgb_conv_t)(void *, uint32_t);
|
---|
[bbf5657] | 78 |
|
---|
[a71c158] | 79 | typedef struct {
|
---|
[c263c77] | 80 | SPINLOCK_DECLARE(lock);
|
---|
[a71c158] | 81 |
|
---|
[b366a6f4] | 82 | parea_t parea;
|
---|
| 83 |
|
---|
[a71c158] | 84 | uint8_t *addr;
|
---|
| 85 | uint16_t *backbuf;
|
---|
| 86 | uint8_t *glyphs;
|
---|
| 87 | uint8_t *bgscan;
|
---|
| 88 |
|
---|
| 89 | rgb_conv_t rgb_conv;
|
---|
| 90 |
|
---|
| 91 | unsigned int xres;
|
---|
| 92 | unsigned int yres;
|
---|
| 93 |
|
---|
| 94 | unsigned int rowtrim;
|
---|
| 95 |
|
---|
| 96 | unsigned int scanline;
|
---|
| 97 | unsigned int glyphscanline;
|
---|
| 98 |
|
---|
| 99 | unsigned int pixelbytes;
|
---|
| 100 | unsigned int glyphbytes;
|
---|
| 101 | unsigned int bgscanbytes;
|
---|
| 102 |
|
---|
| 103 | unsigned int cols;
|
---|
| 104 | unsigned int rows;
|
---|
| 105 |
|
---|
| 106 | unsigned int position;
|
---|
| 107 | } fb_instance_t;
|
---|
[fcbca14f] | 108 |
|
---|
[b366a6f4] | 109 | static void fb_putchar(outdev_t *dev, wchar_t ch);
|
---|
[a71c158] | 110 | static void fb_redraw_internal(fb_instance_t *instance);
|
---|
| 111 | static void fb_redraw(outdev_t *dev);
|
---|
[253f35a1] | 112 |
|
---|
[a71c158] | 113 | static outdev_operations_t fbdev_ops = {
|
---|
| 114 | .write = fb_putchar,
|
---|
| 115 | .redraw = fb_redraw
|
---|
| 116 | };
|
---|
[95c7526] | 117 |
|
---|
[30885b9] | 118 | /*
|
---|
| 119 | * RGB conversion functions.
|
---|
[76fca31] | 120 | *
|
---|
[30885b9] | 121 | * These functions write an RGB value to some memory in some predefined format.
|
---|
| 122 | * The naming convention corresponds to the format created by these functions.
|
---|
| 123 | * The functions use the so called network order (i.e. big endian) with respect
|
---|
| 124 | * to their names.
|
---|
[76fca31] | 125 | */
|
---|
[30885b9] | 126 |
|
---|
[76fca31] | 127 | static void rgb_0888(void *dst, uint32_t rgb)
|
---|
[ccb0cbc] | 128 | {
|
---|
[30885b9] | 129 | *((uint32_t *) dst) = host2uint32_t_be((0 << 24) |
|
---|
| 130 | (RED(rgb, 8) << 16) | (GREEN(rgb, 8) << 8) | (BLUE(rgb, 8)));
|
---|
[ccb0cbc] | 131 | }
|
---|
| 132 |
|
---|
[76fca31] | 133 | static void bgr_0888(void *dst, uint32_t rgb)
|
---|
[ccb0cbc] | 134 | {
|
---|
[30885b9] | 135 | *((uint32_t *) dst) = host2uint32_t_be((0 << 24) |
|
---|
| 136 | (BLUE(rgb, 8) << 16) | (GREEN(rgb, 8) << 8) | (RED(rgb, 8)));
|
---|
[ccb0cbc] | 137 | }
|
---|
| 138 |
|
---|
[6ac14a70] | 139 | static void rgb_8880(void *dst, uint32_t rgb)
|
---|
| 140 | {
|
---|
[30885b9] | 141 | *((uint32_t *) dst) = host2uint32_t_be((RED(rgb, 8) << 24) |
|
---|
| 142 | (GREEN(rgb, 8) << 16) | (BLUE(rgb, 8) << 8) | 0);
|
---|
[6ac14a70] | 143 | }
|
---|
| 144 |
|
---|
[30885b9] | 145 | static void bgr_8880(void *dst, uint32_t rgb)
|
---|
| 146 | {
|
---|
| 147 | *((uint32_t *) dst) = host2uint32_t_be((BLUE(rgb, 8) << 24) |
|
---|
| 148 | (GREEN(rgb, 8) << 16) | (RED(rgb, 8) << 8) | 0);
|
---|
| 149 | }
|
---|
[76fca31] | 150 |
|
---|
| 151 | static void rgb_888(void *dst, uint32_t rgb)
|
---|
[fcbca14f] | 152 | {
|
---|
[30885b9] | 153 | ((uint8_t *) dst)[0] = RED(rgb, 8);
|
---|
[6e71a9d8] | 154 | ((uint8_t *) dst)[1] = GREEN(rgb, 8);
|
---|
[30885b9] | 155 | ((uint8_t *) dst)[2] = BLUE(rgb, 8);
|
---|
[95b9963] | 156 | }
|
---|
| 157 |
|
---|
| 158 | static void bgr_888(void *dst, uint32_t rgb)
|
---|
| 159 | {
|
---|
[30885b9] | 160 | ((uint8_t *) dst)[0] = BLUE(rgb, 8);
|
---|
[95b9963] | 161 | ((uint8_t *) dst)[1] = GREEN(rgb, 8);
|
---|
[30885b9] | 162 | ((uint8_t *) dst)[2] = RED(rgb, 8);
|
---|
[fcbca14f] | 163 | }
|
---|
| 164 |
|
---|
[19490ce] | 165 | static void rgb_555_be(void *dst, uint32_t rgb)
|
---|
[2bc137c2] | 166 | {
|
---|
[19490ce] | 167 | *((uint16_t *) dst) = host2uint16_t_be(RED(rgb, 5) << 10 |
|
---|
| 168 | GREEN(rgb, 5) << 5 | BLUE(rgb, 5));
|
---|
[2bc137c2] | 169 | }
|
---|
| 170 |
|
---|
[19490ce] | 171 | static void rgb_555_le(void *dst, uint32_t rgb)
|
---|
[fcbca14f] | 172 | {
|
---|
[19490ce] | 173 | *((uint16_t *) dst) = host2uint16_t_le(RED(rgb, 5) << 10 |
|
---|
| 174 | GREEN(rgb, 5) << 5 | BLUE(rgb, 5));
|
---|
| 175 | }
|
---|
| 176 |
|
---|
| 177 | static void rgb_565_be(void *dst, uint32_t rgb)
|
---|
| 178 | {
|
---|
| 179 | *((uint16_t *) dst) = host2uint16_t_be(RED(rgb, 5) << 11 |
|
---|
| 180 | GREEN(rgb, 6) << 5 | BLUE(rgb, 5));
|
---|
| 181 | }
|
---|
| 182 |
|
---|
| 183 | static void rgb_565_le(void *dst, uint32_t rgb)
|
---|
| 184 | {
|
---|
| 185 | *((uint16_t *) dst) = host2uint16_t_le(RED(rgb, 5) << 11 |
|
---|
| 186 | GREEN(rgb, 6) << 5 | BLUE(rgb, 5));
|
---|
[fcbca14f] | 187 | }
|
---|
| 188 |
|
---|
[30885b9] | 189 | /** BGR 3:2:3
|
---|
[b4fa652] | 190 | *
|
---|
| 191 | * Even though we try 3:2:3 color scheme here, an 8-bit framebuffer
|
---|
| 192 | * will most likely use a color palette. The color appearance
|
---|
| 193 | * will be pretty random and depend on the default installed
|
---|
| 194 | * palette. This could be fixed by supporting custom palette
|
---|
| 195 | * and setting it to simulate the 8-bit truecolor.
|
---|
[925fdd7] | 196 | *
|
---|
[a71c158] | 197 | * Currently we set the palette on the ia32, amd64, ppc32 and sparc64 port.
|
---|
[925fdd7] | 198 | *
|
---|
| 199 | * Note that the byte is being inverted by this function. The reason is
|
---|
| 200 | * that we would like to use a color palette where the white color code
|
---|
[882d7a8] | 201 | * is 0 and the black color code is 255, as some machines (Sun Blade 1500)
|
---|
[925fdd7] | 202 | * use these codes for black and white and prevent to set codes
|
---|
| 203 | * 0 and 255 to other colors.
|
---|
[882d7a8] | 204 | *
|
---|
[b4fa652] | 205 | */
|
---|
[30885b9] | 206 | static void bgr_323(void *dst, uint32_t rgb)
|
---|
[fcbca14f] | 207 | {
|
---|
[76fca31] | 208 | *((uint8_t *) dst)
|
---|
| 209 | = ~((RED(rgb, 3) << 5) | (GREEN(rgb, 2) << 3) | BLUE(rgb, 3));
|
---|
[fcbca14f] | 210 | }
|
---|
| 211 |
|
---|
[76fca31] | 212 | /** Draw character at given position
|
---|
[b4fa652] | 213 | *
|
---|
| 214 | */
|
---|
[a71c158] | 215 | static void glyph_draw(fb_instance_t *instance, uint16_t glyph,
|
---|
[b366a6f4] | 216 | unsigned int col, unsigned int row, bool overlay)
|
---|
[bbf5657] | 217 | {
|
---|
[76fca31] | 218 | unsigned int x = COL2X(col);
|
---|
| 219 | unsigned int y = ROW2Y(row);
|
---|
| 220 | unsigned int yd;
|
---|
| 221 |
|
---|
[c8bf88d] | 222 | if (!overlay)
|
---|
[a71c158] | 223 | instance->backbuf[BB_POS(instance, col, row)] = glyph;
|
---|
[76fca31] | 224 |
|
---|
[b366a6f4] | 225 | if ((!instance->parea.mapped) || (console_override)) {
|
---|
[516ff92] | 226 | for (yd = 0; yd < FONT_SCANLINES; yd++)
|
---|
[c43b89e8] | 227 | memcpy(&instance->addr[FB_POS(instance, x, y + yd)],
|
---|
[a71c158] | 228 | &instance->glyphs[GLYPH_POS(instance, glyph, yd)],
|
---|
| 229 | instance->glyphscanline);
|
---|
[516ff92] | 230 | }
|
---|
[bbf5657] | 231 | }
|
---|
| 232 |
|
---|
[76fca31] | 233 | /** Scroll screen down by one row
|
---|
| 234 | *
|
---|
| 235 | *
|
---|
| 236 | */
|
---|
[b366a6f4] | 237 | static void screen_scroll(fb_instance_t *instance)
|
---|
[bbf5657] | 238 | {
|
---|
[b366a6f4] | 239 | if ((!instance->parea.mapped) || (console_override)) {
|
---|
[516ff92] | 240 | unsigned int row;
|
---|
[730376d] | 241 |
|
---|
[a71c158] | 242 | for (row = 0; row < instance->rows; row++) {
|
---|
[516ff92] | 243 | unsigned int y = ROW2Y(row);
|
---|
| 244 | unsigned int yd;
|
---|
[76fca31] | 245 |
|
---|
[516ff92] | 246 | for (yd = 0; yd < FONT_SCANLINES; yd++) {
|
---|
| 247 | unsigned int x;
|
---|
| 248 | unsigned int col;
|
---|
[76fca31] | 249 |
|
---|
[a71c158] | 250 | for (col = 0, x = 0; col < instance->cols;
|
---|
| 251 | col++, x += FONT_WIDTH) {
|
---|
[dcdc31d] | 252 | uint16_t glyph;
|
---|
[76fca31] | 253 |
|
---|
[a71c158] | 254 | if (row < instance->rows - 1) {
|
---|
| 255 | if (instance->backbuf[BB_POS(instance, col, row)] ==
|
---|
| 256 | instance->backbuf[BB_POS(instance, col, row + 1)])
|
---|
[516ff92] | 257 | continue;
|
---|
| 258 |
|
---|
[a71c158] | 259 | glyph = instance->backbuf[BB_POS(instance, col, row + 1)];
|
---|
[516ff92] | 260 | } else
|
---|
| 261 | glyph = 0;
|
---|
| 262 |
|
---|
[a71c158] | 263 | memcpy(&instance->addr[FB_POS(instance, x, y + yd)],
|
---|
| 264 | &instance->glyphs[GLYPH_POS(instance, glyph, yd)],
|
---|
| 265 | instance->glyphscanline);
|
---|
[516ff92] | 266 | }
|
---|
[76fca31] | 267 | }
|
---|
[51baa8a] | 268 | }
|
---|
[6eb96fce] | 269 | }
|
---|
[76fca31] | 270 |
|
---|
[a71c158] | 271 | memmove(instance->backbuf, &instance->backbuf[BB_POS(instance, 0, 1)],
|
---|
| 272 | instance->cols * (instance->rows - 1) * sizeof(uint16_t));
|
---|
| 273 | memsetw(&instance->backbuf[BB_POS(instance, 0, instance->rows - 1)],
|
---|
| 274 | instance->cols, 0);
|
---|
[a2c4445] | 275 | }
|
---|
| 276 |
|
---|
[b366a6f4] | 277 | static void cursor_put(fb_instance_t *instance)
|
---|
[bbf5657] | 278 | {
|
---|
[a71c158] | 279 | unsigned int col = instance->position % instance->cols;
|
---|
| 280 | unsigned int row = instance->position / instance->cols;
|
---|
[c8bf88d] | 281 |
|
---|
[b366a6f4] | 282 | glyph_draw(instance, fb_font_glyph(U_CURSOR), col, row, true);
|
---|
[bbf5657] | 283 | }
|
---|
| 284 |
|
---|
[b366a6f4] | 285 | static void cursor_remove(fb_instance_t *instance)
|
---|
[bbf5657] | 286 | {
|
---|
[a71c158] | 287 | unsigned int col = instance->position % instance->cols;
|
---|
| 288 | unsigned int row = instance->position / instance->cols;
|
---|
[c8bf88d] | 289 |
|
---|
[a71c158] | 290 | glyph_draw(instance, instance->backbuf[BB_POS(instance, col, row)],
|
---|
[b366a6f4] | 291 | col, row, true);
|
---|
[bbf5657] | 292 | }
|
---|
| 293 |
|
---|
[76fca31] | 294 | /** Render glyphs
|
---|
| 295 | *
|
---|
| 296 | * Convert glyphs from device independent font
|
---|
| 297 | * description to current visual representation.
|
---|
| 298 | *
|
---|
| 299 | */
|
---|
[a71c158] | 300 | static void glyphs_render(fb_instance_t *instance)
|
---|
[76fca31] | 301 | {
|
---|
[6e71a9d8] | 302 | /* Prerender glyphs */
|
---|
[dcdc31d] | 303 | uint16_t glyph;
|
---|
[76fca31] | 304 |
|
---|
| 305 | for (glyph = 0; glyph < FONT_GLYPHS; glyph++) {
|
---|
[98895c5c] | 306 | uint32_t fg_color;
|
---|
| 307 |
|
---|
| 308 | if (glyph == FONT_GLYPHS - 1)
|
---|
| 309 | fg_color = INV_COLOR;
|
---|
| 310 | else
|
---|
| 311 | fg_color = FG_COLOR;
|
---|
| 312 |
|
---|
[76fca31] | 313 | unsigned int y;
|
---|
| 314 |
|
---|
| 315 | for (y = 0; y < FONT_SCANLINES; y++) {
|
---|
| 316 | unsigned int x;
|
---|
| 317 |
|
---|
[edf5774] | 318 | for (x = 0; x < FONT_WIDTH; x++) {
|
---|
[a71c158] | 319 | void *dst =
|
---|
| 320 | &instance->glyphs[GLYPH_POS(instance, glyph, y) +
|
---|
| 321 | x * instance->pixelbytes];
|
---|
[dcdc31d] | 322 | uint32_t rgb = (fb_font[glyph][y] &
|
---|
[98895c5c] | 323 | (1 << (7 - x))) ? fg_color : BG_COLOR;
|
---|
[a71c158] | 324 | instance->rgb_conv(dst, rgb);
|
---|
[edf5774] | 325 | }
|
---|
[76fca31] | 326 | }
|
---|
| 327 | }
|
---|
| 328 |
|
---|
[6e71a9d8] | 329 | /* Prerender background scanline */
|
---|
| 330 | unsigned int x;
|
---|
| 331 |
|
---|
[a71c158] | 332 | for (x = 0; x < instance->xres; x++)
|
---|
| 333 | instance->rgb_conv(&instance->bgscan[x * instance->pixelbytes], BG_COLOR);
|
---|
[76fca31] | 334 | }
|
---|
| 335 |
|
---|
[a71c158] | 336 | /** Print character to screen
|
---|
| 337 | *
|
---|
| 338 | * Emulate basic terminal commands.
|
---|
[76fca31] | 339 | *
|
---|
| 340 | */
|
---|
[b366a6f4] | 341 | static void fb_putchar(outdev_t *dev, wchar_t ch)
|
---|
[76fca31] | 342 | {
|
---|
[a71c158] | 343 | fb_instance_t *instance = (fb_instance_t *) dev->data;
|
---|
[c263c77] | 344 | spinlock_lock(&instance->lock);
|
---|
[a71c158] | 345 |
|
---|
| 346 | switch (ch) {
|
---|
| 347 | case '\n':
|
---|
[b366a6f4] | 348 | cursor_remove(instance);
|
---|
[a71c158] | 349 | instance->position += instance->cols;
|
---|
| 350 | instance->position -= instance->position % instance->cols;
|
---|
| 351 | break;
|
---|
| 352 | case '\r':
|
---|
[b366a6f4] | 353 | cursor_remove(instance);
|
---|
[a71c158] | 354 | instance->position -= instance->position % instance->cols;
|
---|
| 355 | break;
|
---|
| 356 | case '\b':
|
---|
[b366a6f4] | 357 | cursor_remove(instance);
|
---|
[a71c158] | 358 | if (instance->position % instance->cols)
|
---|
| 359 | instance->position--;
|
---|
| 360 | break;
|
---|
| 361 | case '\t':
|
---|
[b366a6f4] | 362 | cursor_remove(instance);
|
---|
[a71c158] | 363 | do {
|
---|
| 364 | glyph_draw(instance, fb_font_glyph(' '),
|
---|
| 365 | instance->position % instance->cols,
|
---|
[b366a6f4] | 366 | instance->position / instance->cols, false);
|
---|
[a71c158] | 367 | instance->position++;
|
---|
[f061e404] | 368 | } while (((instance->position % instance->cols) % 8 != 0) &&
|
---|
| 369 | (instance->position < instance->cols * instance->rows));
|
---|
[a71c158] | 370 | break;
|
---|
| 371 | default:
|
---|
| 372 | glyph_draw(instance, fb_font_glyph(ch),
|
---|
| 373 | instance->position % instance->cols,
|
---|
[b366a6f4] | 374 | instance->position / instance->cols, false);
|
---|
[a71c158] | 375 | instance->position++;
|
---|
| 376 | }
|
---|
| 377 |
|
---|
| 378 | if (instance->position >= instance->cols * instance->rows) {
|
---|
| 379 | instance->position -= instance->cols;
|
---|
[b366a6f4] | 380 | screen_scroll(instance);
|
---|
[a71c158] | 381 | }
|
---|
| 382 |
|
---|
[b366a6f4] | 383 | cursor_put(instance);
|
---|
[a71c158] | 384 |
|
---|
[c263c77] | 385 | spinlock_unlock(&instance->lock);
|
---|
[a71c158] | 386 | }
|
---|
| 387 |
|
---|
| 388 | static void fb_redraw_internal(fb_instance_t *instance)
|
---|
| 389 | {
|
---|
[76fca31] | 390 | unsigned int row;
|
---|
| 391 |
|
---|
[a71c158] | 392 | for (row = 0; row < instance->rowtrim; row++) {
|
---|
[c43b89e8] | 393 | unsigned int y = ROW2Y(row);
|
---|
[76fca31] | 394 | unsigned int yd;
|
---|
| 395 |
|
---|
| 396 | for (yd = 0; yd < FONT_SCANLINES; yd++) {
|
---|
| 397 | unsigned int x;
|
---|
| 398 | unsigned int col;
|
---|
| 399 |
|
---|
[a71c158] | 400 | for (col = 0, x = 0; col < instance->cols;
|
---|
[edf5774] | 401 | col++, x += FONT_WIDTH) {
|
---|
[a71c158] | 402 | uint16_t glyph =
|
---|
| 403 | instance->backbuf[BB_POS(instance, col, row)];
|
---|
| 404 | void *dst = &instance->addr[FB_POS(instance, x, y + yd)];
|
---|
| 405 | void *src = &instance->glyphs[GLYPH_POS(instance, glyph, yd)];
|
---|
| 406 | memcpy(dst, src, instance->glyphscanline);
|
---|
[edf5774] | 407 | }
|
---|
[76fca31] | 408 | }
|
---|
| 409 | }
|
---|
| 410 |
|
---|
[a71c158] | 411 | if (COL2X(instance->cols) < instance->xres) {
|
---|
[76fca31] | 412 | unsigned int y;
|
---|
[a71c158] | 413 | unsigned int size =
|
---|
| 414 | (instance->xres - COL2X(instance->cols)) * instance->pixelbytes;
|
---|
[76fca31] | 415 |
|
---|
[c43b89e8] | 416 | for (y = 0; y < instance->yres; y++)
|
---|
[a71c158] | 417 | memcpy(&instance->addr[FB_POS(instance, COL2X(instance->cols), y)],
|
---|
| 418 | instance->bgscan, size);
|
---|
[76fca31] | 419 | }
|
---|
| 420 |
|
---|
[c43b89e8] | 421 | if (ROW2Y(instance->rowtrim) < instance->yres) {
|
---|
[76fca31] | 422 | unsigned int y;
|
---|
| 423 |
|
---|
[c43b89e8] | 424 | for (y = ROW2Y(instance->rowtrim); y < instance->yres; y++)
|
---|
[a71c158] | 425 | memcpy(&instance->addr[FB_POS(instance, 0, y)],
|
---|
| 426 | instance->bgscan, instance->bgscanbytes);
|
---|
[76fca31] | 427 | }
|
---|
| 428 | }
|
---|
| 429 |
|
---|
[a71c158] | 430 | /** Refresh the screen
|
---|
| 431 | *
|
---|
| 432 | */
|
---|
| 433 | static void fb_redraw(outdev_t *dev)
|
---|
| 434 | {
|
---|
| 435 | fb_instance_t *instance = (fb_instance_t *) dev->data;
|
---|
| 436 |
|
---|
[c263c77] | 437 | spinlock_lock(&instance->lock);
|
---|
[a71c158] | 438 | fb_redraw_internal(instance);
|
---|
[c263c77] | 439 | spinlock_unlock(&instance->lock);
|
---|
[a71c158] | 440 | }
|
---|
[76fca31] | 441 |
|
---|
[a0e1b48] | 442 | /** Initialize framebuffer as a output character device
|
---|
[76fca31] | 443 | *
|
---|
[bbf5657] | 444 | */
|
---|
[a71c158] | 445 | outdev_t *fb_init(fb_properties_t *props)
|
---|
[bbf5657] | 446 | {
|
---|
[00a020d] | 447 | ASSERT(props);
|
---|
| 448 | ASSERT(props->x > 0);
|
---|
| 449 | ASSERT(props->y > 0);
|
---|
| 450 | ASSERT(props->scan > 0);
|
---|
| 451 |
|
---|
[a71c158] | 452 | rgb_conv_t rgb_conv;
|
---|
| 453 | unsigned int pixelbytes;
|
---|
| 454 |
|
---|
[965dc18] | 455 | switch (props->visual) {
|
---|
[2bc137c2] | 456 | case VISUAL_INDIRECT_8:
|
---|
[30885b9] | 457 | rgb_conv = bgr_323;
|
---|
[d6f270f] | 458 | pixelbytes = 1;
|
---|
| 459 | break;
|
---|
[19490ce] | 460 | case VISUAL_RGB_5_5_5_LE:
|
---|
| 461 | rgb_conv = rgb_555_le;
|
---|
| 462 | pixelbytes = 2;
|
---|
| 463 | break;
|
---|
| 464 | case VISUAL_RGB_5_5_5_BE:
|
---|
| 465 | rgb_conv = rgb_555_be;
|
---|
| 466 | pixelbytes = 2;
|
---|
| 467 | break;
|
---|
| 468 | case VISUAL_RGB_5_6_5_LE:
|
---|
| 469 | rgb_conv = rgb_565_le;
|
---|
[2bc137c2] | 470 | pixelbytes = 2;
|
---|
| 471 | break;
|
---|
[19490ce] | 472 | case VISUAL_RGB_5_6_5_BE:
|
---|
| 473 | rgb_conv = rgb_565_be;
|
---|
[d6f270f] | 474 | pixelbytes = 2;
|
---|
| 475 | break;
|
---|
[2bc137c2] | 476 | case VISUAL_RGB_8_8_8:
|
---|
[76fca31] | 477 | rgb_conv = rgb_888;
|
---|
[2bc137c2] | 478 | pixelbytes = 3;
|
---|
| 479 | break;
|
---|
[95b9963] | 480 | case VISUAL_BGR_8_8_8:
|
---|
| 481 | rgb_conv = bgr_888;
|
---|
| 482 | pixelbytes = 3;
|
---|
| 483 | break;
|
---|
[2bc137c2] | 484 | case VISUAL_RGB_8_8_8_0:
|
---|
[6ac14a70] | 485 | rgb_conv = rgb_8880;
|
---|
[2bc137c2] | 486 | pixelbytes = 4;
|
---|
[d6f270f] | 487 | break;
|
---|
[2bc137c2] | 488 | case VISUAL_RGB_0_8_8_8:
|
---|
[76fca31] | 489 | rgb_conv = rgb_0888;
|
---|
[d6f270f] | 490 | pixelbytes = 4;
|
---|
| 491 | break;
|
---|
[ccb0cbc] | 492 | case VISUAL_BGR_0_8_8_8:
|
---|
[76fca31] | 493 | rgb_conv = bgr_0888;
|
---|
[ccb0cbc] | 494 | pixelbytes = 4;
|
---|
| 495 | break;
|
---|
[30885b9] | 496 | case VISUAL_BGR_8_8_8_0:
|
---|
| 497 | rgb_conv = bgr_8880;
|
---|
| 498 | pixelbytes = 4;
|
---|
| 499 | break;
|
---|
[d6f270f] | 500 | default:
|
---|
[00a020d] | 501 | LOG("Unsupported visual.");
|
---|
[a71c158] | 502 | return NULL;
|
---|
[fcbca14f] | 503 | }
|
---|
[8424198] | 504 |
|
---|
[a71c158] | 505 | outdev_t *fbdev = malloc(sizeof(outdev_t), FRAME_ATOMIC);
|
---|
| 506 | if (!fbdev)
|
---|
| 507 | return NULL;
|
---|
[bbf5657] | 508 |
|
---|
[a71c158] | 509 | fb_instance_t *instance = malloc(sizeof(fb_instance_t), FRAME_ATOMIC);
|
---|
| 510 | if (!instance) {
|
---|
| 511 | free(fbdev);
|
---|
| 512 | return NULL;
|
---|
| 513 | }
|
---|
[6e71a9d8] | 514 |
|
---|
[a71c158] | 515 | outdev_initialize("fbdev", fbdev, &fbdev_ops);
|
---|
| 516 | fbdev->data = instance;
|
---|
| 517 |
|
---|
[c263c77] | 518 | spinlock_initialize(&instance->lock, "*fb.instance.lock");
|
---|
[b366a6f4] | 519 |
|
---|
[a71c158] | 520 | instance->rgb_conv = rgb_conv;
|
---|
| 521 | instance->pixelbytes = pixelbytes;
|
---|
| 522 | instance->xres = props->x;
|
---|
| 523 | instance->yres = props->y;
|
---|
| 524 | instance->scanline = props->scan;
|
---|
| 525 | instance->position = 0;
|
---|
| 526 |
|
---|
| 527 | instance->cols = X2COL(instance->xres);
|
---|
| 528 | instance->rows = Y2ROW(instance->yres);
|
---|
| 529 |
|
---|
[c43b89e8] | 530 | instance->rowtrim = instance->rows;
|
---|
[76fca31] | 531 |
|
---|
[a71c158] | 532 | instance->glyphscanline = FONT_WIDTH * instance->pixelbytes;
|
---|
| 533 | instance->glyphbytes = ROW2Y(instance->glyphscanline);
|
---|
| 534 | instance->bgscanbytes = instance->xres * instance->pixelbytes;
|
---|
[76fca31] | 535 |
|
---|
[a71c158] | 536 | size_t fbsize = instance->scanline * instance->yres;
|
---|
| 537 | size_t bbsize = instance->cols * instance->rows * sizeof(uint16_t);
|
---|
| 538 | size_t glyphsize = FONT_GLYPHS * instance->glyphbytes;
|
---|
[76fca31] | 539 |
|
---|
[adec5b45] | 540 | instance->addr = (uint8_t *) km_map((uintptr_t) props->addr, fbsize,
|
---|
| 541 | PAGE_WRITE | PAGE_NOT_CACHEABLE);
|
---|
[a71c158] | 542 | if (!instance->addr) {
|
---|
[00a020d] | 543 | LOG("Unable to map framebuffer.");
|
---|
[a71c158] | 544 | free(instance);
|
---|
| 545 | free(fbdev);
|
---|
| 546 | return NULL;
|
---|
[00a020d] | 547 | }
|
---|
| 548 |
|
---|
[a71c158] | 549 | instance->backbuf = (uint16_t *) malloc(bbsize, 0);
|
---|
| 550 | if (!instance->backbuf) {
|
---|
[00a020d] | 551 | LOG("Unable to allocate backbuffer.");
|
---|
[a71c158] | 552 | free(instance);
|
---|
| 553 | free(fbdev);
|
---|
| 554 | return NULL;
|
---|
[00a020d] | 555 | }
|
---|
[76fca31] | 556 |
|
---|
[a71c158] | 557 | instance->glyphs = (uint8_t *) malloc(glyphsize, 0);
|
---|
| 558 | if (!instance->glyphs) {
|
---|
[00a020d] | 559 | LOG("Unable to allocate glyphs.");
|
---|
[a71c158] | 560 | free(instance->backbuf);
|
---|
| 561 | free(instance);
|
---|
| 562 | free(fbdev);
|
---|
| 563 | return NULL;
|
---|
[00a020d] | 564 | }
|
---|
[76fca31] | 565 |
|
---|
[a71c158] | 566 | instance->bgscan = malloc(instance->bgscanbytes, 0);
|
---|
| 567 | if (!instance->bgscan) {
|
---|
[00a020d] | 568 | LOG("Unable to allocate background pixel.");
|
---|
[a71c158] | 569 | free(instance->glyphs);
|
---|
| 570 | free(instance->backbuf);
|
---|
| 571 | free(instance);
|
---|
| 572 | free(fbdev);
|
---|
| 573 | return NULL;
|
---|
[00a020d] | 574 | }
|
---|
[76fca31] | 575 |
|
---|
[a71c158] | 576 | memsetw(instance->backbuf, instance->cols * instance->rows, 0);
|
---|
| 577 | glyphs_render(instance);
|
---|
| 578 |
|
---|
[b366a6f4] | 579 | link_initialize(&instance->parea.link);
|
---|
| 580 | instance->parea.pbase = props->addr;
|
---|
| 581 | instance->parea.frames = SIZE2FRAMES(fbsize);
|
---|
| 582 | instance->parea.unpriv = false;
|
---|
| 583 | instance->parea.mapped = false;
|
---|
| 584 | ddi_parea_register(&instance->parea);
|
---|
| 585 |
|
---|
[a71c158] | 586 | if (!fb_exported) {
|
---|
| 587 | /*
|
---|
[b366a6f4] | 588 | * We export the kernel framebuffer for uspace usage.
|
---|
| 589 | * This is used in the case the uspace framebuffer
|
---|
| 590 | * driver is not self-sufficient.
|
---|
[a71c158] | 591 | */
|
---|
| 592 | sysinfo_set_item_val("fb", NULL, true);
|
---|
| 593 | sysinfo_set_item_val("fb.kind", NULL, 1);
|
---|
| 594 | sysinfo_set_item_val("fb.width", NULL, instance->xres);
|
---|
| 595 | sysinfo_set_item_val("fb.height", NULL, instance->yres);
|
---|
| 596 | sysinfo_set_item_val("fb.scanline", NULL, instance->scanline);
|
---|
| 597 | sysinfo_set_item_val("fb.visual", NULL, props->visual);
|
---|
| 598 | sysinfo_set_item_val("fb.address.physical", NULL, props->addr);
|
---|
| 599 |
|
---|
| 600 | fb_exported = true;
|
---|
| 601 | }
|
---|
[00a020d] | 602 |
|
---|
[a71c158] | 603 | fb_redraw(fbdev);
|
---|
| 604 | return fbdev;
|
---|
[bbf5657] | 605 | }
|
---|
[b45c443] | 606 |
|
---|
[94d614e] | 607 | /** @}
|
---|
[b45c443] | 608 | */
|
---|