Rev 1991 | Rev 1994 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
| Rev 1991 | Rev 1993 | ||
|---|---|---|---|
| Line 31... | Line 31... | ||
| 31 | */ |
31 | */ |
| 32 | /** @file |
32 | /** @file |
| 33 | */ |
33 | */ |
| 34 | 34 | ||
| 35 | #include <genarch/fb/font-8x16.h> |
35 | #include <genarch/fb/font-8x16.h> |
| - | 36 | #include <genarch/fb/visuals.h> |
|
| 36 | #include <genarch/fb/fb.h> |
37 | #include <genarch/fb/fb.h> |
| 37 | #include <console/chardev.h> |
38 | #include <console/chardev.h> |
| 38 | #include <console/console.h> |
39 | #include <console/console.h> |
| 39 | #include <sysinfo/sysinfo.h> |
40 | #include <sysinfo/sysinfo.h> |
| 40 | #include <mm/slab.h> |
41 | #include <mm/slab.h> |
| Line 56... | Line 57... | ||
| 56 | static int dboffset; |
57 | static int dboffset; |
| 57 | 58 | ||
| 58 | static unsigned int xres = 0; |
59 | static unsigned int xres = 0; |
| 59 | static unsigned int yres = 0; |
60 | static unsigned int yres = 0; |
| 60 | static unsigned int scanline = 0; |
61 | static unsigned int scanline = 0; |
| 61 | static unsigned int bitspp = 0; |
- | |
| 62 | static unsigned int pixelbytes = 0; |
62 | static unsigned int pixelbytes = 0; |
| 63 | #ifdef FB_INVERT_COLORS |
63 | #ifdef FB_INVERT_COLORS |
| 64 | static bool invert_colors = true; |
64 | static bool invert_colors = true; |
| 65 | #else |
65 | #else |
| 66 | static bool invert_colors = false; |
66 | static bool invert_colors = false; |
| Line 93... | Line 93... | ||
| 93 | { |
93 | { |
| 94 | return invert_colors ? ~color : color; |
94 | return invert_colors ? ~color : color; |
| 95 | } |
95 | } |
| 96 | 96 | ||
| 97 | /* Conversion routines between different color representations */ |
97 | /* Conversion routines between different color representations */ |
| 98 | static void rgb_4byte(void *dst, int rgb) |
98 | static void rgb_byte0888(void *dst, int rgb) |
| 99 | { |
99 | { |
| 100 | *((int *) dst) = rgb; |
100 | *((int *) dst) = rgb; |
| 101 | } |
101 | } |
| 102 | 102 | ||
| 103 | static int byte4_rgb(void *src) |
103 | static int byte0888_rgb(void *src) |
| 104 | { |
104 | { |
| 105 | return (*((int *) src)) & 0xffffff; |
105 | return (*((int *) src)) & 0xffffff; |
| 106 | } |
106 | } |
| 107 | 107 | ||
| 108 | static void rgb_3byte(void *dst, int rgb) |
108 | static void rgb_byte888(void *dst, int rgb) |
| 109 | { |
109 | { |
| 110 | uint8_t *scr = dst; |
110 | uint8_t *scr = dst; |
| 111 | #if defined(FB_INVERT_ENDIAN) |
111 | #if defined(FB_INVERT_ENDIAN) |
| 112 | scr[0] = RED(rgb, 8); |
112 | scr[0] = RED(rgb, 8); |
| 113 | scr[1] = GREEN(rgb, 8); |
113 | scr[1] = GREEN(rgb, 8); |
| Line 117... | Line 117... | ||
| 117 | scr[1] = GREEN(rgb, 8); |
117 | scr[1] = GREEN(rgb, 8); |
| 118 | scr[0] = BLUE(rgb, 8); |
118 | scr[0] = BLUE(rgb, 8); |
| 119 | #endif |
119 | #endif |
| 120 | } |
120 | } |
| 121 | 121 | ||
| 122 | static int byte3_rgb(void *src) |
122 | static int byte888_rgb(void *src) |
| 123 | { |
123 | { |
| 124 | uint8_t *scr = src; |
124 | uint8_t *scr = src; |
| 125 | #if defined(FB_INVERT_ENDIAN) |
125 | #if defined(FB_INVERT_ENDIAN) |
| 126 | return scr[0] << 16 | scr[1] << 8 | scr[2]; |
126 | return scr[0] << 16 | scr[1] << 8 | scr[2]; |
| 127 | #else |
127 | #else |
| 128 | return scr[2] << 16 | scr[1] << 8 | scr[0]; |
128 | return scr[2] << 16 | scr[1] << 8 | scr[0]; |
| 129 | #endif |
129 | #endif |
| 130 | } |
130 | } |
| 131 | 131 | ||
| - | 132 | /** 16-bit depth (5:5:5) */ |
|
| - | 133 | static void rgb_byte555(void *dst, int rgb) |
|
| - | 134 | { |
|
| - | 135 | /* 5-bit, 5-bits, 5-bits */ |
|
| - | 136 | *((uint16_t *) dst) = RED(rgb, 5) << 10 | GREEN(rgb, 5) << 5 | BLUE(rgb, 5); |
|
| - | 137 | } |
|
| - | 138 | ||
| - | 139 | /** 16-bit depth (5:5:5) */ |
|
| - | 140 | static int byte555_rgb(void *src) |
|
| - | 141 | { |
|
| - | 142 | int color = *(uint16_t *)(src); |
|
| - | 143 | return (((color >> 10) & 0x1f) << (16 + 3)) | (((color >> 5) & 0x1f) << (8 + 3)) | ((color & 0x1f) << 3); |
|
| - | 144 | } |
|
| - | 145 | ||
| 132 | /** 16-bit depth (5:6:5) */ |
146 | /** 16-bit depth (5:6:5) */ |
| 133 | static void rgb_2byte(void *dst, int rgb) |
147 | static void rgb_byte565(void *dst, int rgb) |
| 134 | { |
148 | { |
| 135 | /* 5-bit, 6-bits, 5-bits */ |
149 | /* 5-bit, 6-bits, 5-bits */ |
| 136 | *((uint16_t *) dst) = RED(rgb, 5) << 11 | GREEN(rgb, 6) << 5 | BLUE(rgb, 5); |
150 | *((uint16_t *) dst) = RED(rgb, 5) << 11 | GREEN(rgb, 6) << 5 | BLUE(rgb, 5); |
| 137 | } |
151 | } |
| 138 | 152 | ||
| 139 | /** 16-bit depth (5:6:5) */ |
153 | /** 16-bit depth (5:6:5) */ |
| 140 | static int byte2_rgb(void *src) |
154 | static int byte565_rgb(void *src) |
| 141 | { |
155 | { |
| 142 | int color = *(uint16_t *)(src); |
156 | int color = *(uint16_t *)(src); |
| 143 | return (((color >> 11) & 0x1f) << (16 + 3)) | (((color >> 5) & 0x3f) << (8 + 2)) | ((color & 0x1f) << 3); |
157 | return (((color >> 11) & 0x1f) << (16 + 3)) | (((color >> 5) & 0x3f) << (8 + 2)) | ((color & 0x1f) << 3); |
| 144 | } |
158 | } |
| 145 | 159 | ||
| Line 149... | Line 163... | ||
| 149 | * will most likely use a color palette. The color appearance |
163 | * will most likely use a color palette. The color appearance |
| 150 | * will be pretty random and depend on the default installed |
164 | * will be pretty random and depend on the default installed |
| 151 | * palette. This could be fixed by supporting custom palette |
165 | * palette. This could be fixed by supporting custom palette |
| 152 | * and setting it to simulate the 8-bit truecolor. |
166 | * and setting it to simulate the 8-bit truecolor. |
| 153 | */ |
167 | */ |
| 154 | static void rgb_1byte(void *dst, int rgb) |
168 | static void rgb_byte8(void *dst, int rgb) |
| 155 | { |
169 | { |
| 156 | *((uint8_t *) dst) = RED(rgb, 3) << 5 | GREEN(rgb, 2) << 3 | BLUE(rgb, 3); |
170 | *((uint8_t *) dst) = RED(rgb, 3) << 5 | GREEN(rgb, 2) << 3 | BLUE(rgb, 3); |
| 157 | } |
171 | } |
| 158 | 172 | ||
| 159 | /** Return pixel color - 8-bit depth (color palette/3:2:3) |
173 | /** Return pixel color - 8-bit depth (color palette/3:2:3) |
| 160 | * |
174 | * |
| 161 | * See the comment for rgb_1byte(). |
175 | * See the comment for rgb_byte(). |
| 162 | */ |
176 | */ |
| 163 | static int byte1_rgb(void *src) |
177 | static int byte8_rgb(void *src) |
| 164 | { |
178 | { |
| 165 | int color = *(uint8_t *)src; |
179 | int color = *(uint8_t *)src; |
| 166 | return (((color >> 5) & 0x7) << (16 + 5)) | (((color >> 3) & 0x3) << (8 + 6)) | ((color & 0x7) << 5); |
180 | return (((color >> 5) & 0x7) << (16 + 5)) | (((color >> 3) & 0x3) << (8 + 6)) | ((color & 0x7) << 5); |
| 167 | } |
181 | } |
| 168 | 182 | ||
| Line 205... | Line 219... | ||
| 205 | { |
219 | { |
| 206 | uint8_t *lastline = &fbaddress[(rows - 1) * ROW_BYTES]; |
220 | uint8_t *lastline = &fbaddress[(rows - 1) * ROW_BYTES]; |
| 207 | int firstsz; |
221 | int firstsz; |
| 208 | 222 | ||
| 209 | if (dbbuffer) { |
223 | if (dbbuffer) { |
| 210 | memcpy(&dbbuffer[dboffset * scanline], blankline, FONT_SCANLINES * scanline); |
224 | memcpy(&dbbuffer[dboffset * scanline], blankline, ROW_BYTES); |
| 211 | 225 | ||
| 212 | dboffset = (dboffset + FONT_SCANLINES) % yres; |
226 | dboffset = (dboffset + FONT_SCANLINES) % yres; |
| 213 | firstsz = yres - dboffset; |
227 | firstsz = yres - dboffset; |
| 214 | 228 | ||
| 215 | memcpy(fbaddress, &dbbuffer[scanline * dboffset], firstsz * scanline); |
229 | memcpy(fbaddress, &dbbuffer[scanline * dboffset], firstsz * scanline); |
| Line 346... | Line 360... | ||
| 346 | }; |
360 | }; |
| 347 | 361 | ||
| 348 | 362 | ||
| 349 | /** Initialize framebuffer as a chardev output device |
363 | /** Initialize framebuffer as a chardev output device |
| 350 | * |
364 | * |
| 351 | * @param addr Physical address of the framebuffer |
365 | * @param addr Physical address of the framebuffer |
| 352 | * @param x Screen width in pixels |
366 | * @param x Screen width in pixels |
| 353 | * @param y Screen height in pixels |
367 | * @param y Screen height in pixels |
| 354 | * @param bpp Bits per pixel (8, 16, 24, 32) |
- | |
| 355 | * @param scan Bytes per one scanline |
368 | * @param scan Bytes per one scanline |
| 356 | * @param align Request alignment for 24bpp mode. |
369 | * @param visual Color model |
| - | 370 | * |
|
| 357 | */ |
371 | */ |
| 358 | void fb_init(uintptr_t addr, unsigned int x, unsigned int y, unsigned int bpp, unsigned int scan, bool align) |
372 | void fb_init(uintptr_t addr, unsigned int x, unsigned int y, unsigned int scan, unsigned int visual) |
| 359 | { |
373 | { |
| 360 | switch (bpp) { |
374 | switch (visual) { |
| 361 | case 8: |
375 | case VISUAL_INDIRECT_8: |
| 362 | rgb2scr = rgb_1byte; |
376 | rgb2scr = rgb_byte8; |
| 363 | scr2rgb = byte1_rgb; |
377 | scr2rgb = byte8_rgb; |
| 364 | pixelbytes = 1; |
378 | pixelbytes = 1; |
| 365 | break; |
379 | break; |
| - | 380 | case VISUAL_RGB_5_5_5: |
|
| - | 381 | rgb2scr = rgb_byte555; |
|
| - | 382 | scr2rgb = byte555_rgb; |
|
| - | 383 | pixelbytes = 2; |
|
| 366 | case 16: |
384 | break; |
| - | 385 | case VISUAL_RGB_5_6_5: |
|
| 367 | rgb2scr = rgb_2byte; |
386 | rgb2scr = rgb_byte565; |
| 368 | scr2rgb = byte2_rgb; |
387 | scr2rgb = byte565_rgb; |
| 369 | pixelbytes = 2; |
388 | pixelbytes = 2; |
| 370 | break; |
389 | break; |
| 371 | case 24: |
390 | case VISUAL_RGB_8_8_8: |
| 372 | rgb2scr = rgb_3byte; |
391 | rgb2scr = rgb_byte888; |
| 373 | scr2rgb = byte3_rgb; |
392 | scr2rgb = byte888_rgb; |
| 374 | if (align) |
- | |
| 375 | pixelbytes = 4; |
393 | pixelbytes = 3; |
| 376 | else |
394 | break; |
| - | 395 | case VISUAL_RGB_8_8_8_0: |
|
| - | 396 | rgb2scr = rgb_byte888; |
|
| - | 397 | scr2rgb = byte888_rgb; |
|
| 377 | pixelbytes = 3; |
398 | pixelbytes = 4; |
| 378 | break; |
399 | break; |
| 379 | case 32: |
400 | case VISUAL_RGB_0_8_8_8: |
| 380 | rgb2scr = rgb_4byte; |
401 | rgb2scr = rgb_byte0888; |
| 381 | scr2rgb = byte4_rgb; |
402 | scr2rgb = byte0888_rgb; |
| 382 | pixelbytes = 4; |
403 | pixelbytes = 4; |
| 383 | break; |
404 | break; |
| 384 | default: |
405 | default: |
| 385 | panic("Unsupported bpp.\n"); |
406 | panic("Unsupported visual.\n"); |
| 386 | } |
407 | } |
| 387 | 408 | ||
| 388 | unsigned int fbsize = scan * y; |
409 | unsigned int fbsize = scan * y; |
| 389 | 410 | ||
| 390 | /* Map the framebuffer */ |
411 | /* Map the framebuffer */ |
| 391 | fbaddress = (uint8_t *) hw_map((uintptr_t) addr, fbsize); |
412 | fbaddress = (uint8_t *) hw_map((uintptr_t) addr, fbsize); |
| 392 | 413 | ||
| 393 | xres = x; |
414 | xres = x; |
| 394 | yres = y; |
415 | yres = y; |
| 395 | bitspp = bpp; |
- | |
| 396 | scanline = scan; |
416 | scanline = scan; |
| 397 | 417 | ||
| 398 | rows = y / FONT_SCANLINES; |
418 | rows = y / FONT_SCANLINES; |
| 399 | columns = x / COL_WIDTH; |
419 | columns = x / COL_WIDTH; |
| 400 | 420 | ||
| 401 | sysinfo_set_item_val("fb", NULL, true); |
421 | sysinfo_set_item_val("fb", NULL, true); |
| 402 | sysinfo_set_item_val("fb.kind", NULL, 1); |
422 | sysinfo_set_item_val("fb.kind", NULL, 1); |
| 403 | sysinfo_set_item_val("fb.width", NULL, xres); |
423 | sysinfo_set_item_val("fb.width", NULL, xres); |
| 404 | sysinfo_set_item_val("fb.height", NULL, yres); |
424 | sysinfo_set_item_val("fb.height", NULL, yres); |
| 405 | sysinfo_set_item_val("fb.bpp", NULL, bpp); |
- | |
| 406 | sysinfo_set_item_val("fb.bpp-align", NULL, align); |
- | |
| 407 | sysinfo_set_item_val("fb.scanline", NULL, scan); |
425 | sysinfo_set_item_val("fb.scanline", NULL, scan); |
| - | 426 | sysinfo_set_item_val("fb.visual", NULL, visual); |
|
| 408 | sysinfo_set_item_val("fb.address.physical", NULL, addr); |
427 | sysinfo_set_item_val("fb.address.physical", NULL, addr); |
| 409 | sysinfo_set_item_val("fb.invert-colors", NULL, invert_colors); |
428 | sysinfo_set_item_val("fb.invert-colors", NULL, invert_colors); |
| 410 | 429 | ||
| 411 | /* Allocate double buffer */ |
430 | /* Allocate double buffer */ |
| 412 | unsigned int order = fnzb(SIZE2FRAMES(ALIGN_UP(fbsize, FRAME_SIZE))) + 1; |
431 | unsigned int order = fnzb(SIZE2FRAMES(ALIGN_UP(fbsize, FRAME_SIZE))) + 1; |