| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
#include <libpayload.h> |
| 31 |
#include <coreboot_tables.h> |
| 32 |
#include <pci.h> |
| 33 |
#include <video_console.h> |
| 34 |
#include "font.h" |
| 35 |
|
| 36 |
struct video_console coreboot_video_console; |
| 37 |
|
| 38 |
static unsigned int cursor_x = 0, cursor_y = 0, cursor_en = 0; |
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
#define VGA_COLOR_DEFAULT 7 |
| 43 |
static const u32 vga_colors[] = { |
| 44 |
|
| 45 |
(0x00 << 16) | (0x00 << 8) | 0x00, |
| 46 |
(0xAA << 16) | (0x00 << 8) | 0x00, |
| 47 |
(0x00 << 16) | (0xAA << 8) | 0x00, |
| 48 |
(0xAA << 16) | (0x55 << 8) | 0x00, |
| 49 |
(0x00 << 16) | (0x00 << 8) | 0xAA, |
| 50 |
(0xAA << 16) | (0x00 << 8) | 0xAA, |
| 51 |
(0x00 << 16) | (0xAA << 8) | 0xAA, |
| 52 |
(0xAA << 16) | (0xAA << 8) | 0xAA, |
| 53 |
(0x55 << 16) | (0x55 << 8) | 0x55, |
| 54 |
(0xFF << 16) | (0x55 << 8) | 0x55, |
| 55 |
(0x55 << 16) | (0xFF << 8) | 0x55, |
| 56 |
(0xFF << 16) | (0xFF << 8) | 0x55, |
| 57 |
(0x55 << 16) | (0x55 << 8) | 0xFF, |
| 58 |
(0xFF << 16) | (0x55 << 8) | 0xFF, |
| 59 |
(0x55 << 16) | (0xFF << 8) | 0xFF, |
| 60 |
(0xFF << 16) | (0xFF << 8) | 0xFF, |
| 61 |
}; |
| 62 |
|
| 63 |
static struct cb_framebuffer fbinfo; |
| 64 |
static unsigned short *chars; |
| 65 |
|
| 66 |
|
| 67 |
#define FB ((unsigned char *)phys_to_virt(fbinfo.physical_address)) |
| 68 |
|
| 69 |
static void corebootfb_scroll_up(void) |
| 70 |
{ |
| 71 |
unsigned char *dst = FB; |
| 72 |
unsigned char *src = FB + (fbinfo.bytes_per_line * font_height); |
| 73 |
int y; |
| 74 |
|
| 75 |
|
| 76 |
for (y = 0; y < fbinfo.y_resolution - font_height; y++) { |
| 77 |
memcpy(dst, src, fbinfo.x_resolution * (fbinfo.bits_per_pixel >> 3)); |
| 78 |
|
| 79 |
dst += fbinfo.bytes_per_line; |
| 80 |
src += fbinfo.bytes_per_line; |
| 81 |
} |
| 82 |
|
| 83 |
|
| 84 |
dst = FB + (fbinfo.y_resolution - font_height) * fbinfo.bytes_per_line; |
| 85 |
|
| 86 |
for (; y < fbinfo.y_resolution; y++) { |
| 87 |
memset(dst, 0, fbinfo.x_resolution * (fbinfo.bits_per_pixel >> 3)); |
| 88 |
dst += fbinfo.bytes_per_line; |
| 89 |
} |
| 90 |
|
| 91 |
|
| 92 |
dst = (unsigned char *)chars; |
| 93 |
src = (unsigned char *)(chars + coreboot_video_console.columns); |
| 94 |
memcpy(dst, src, coreboot_video_console.columns * |
| 95 |
(coreboot_video_console.rows - 1) * 2); |
| 96 |
int column; |
| 97 |
for (column = 0; column < coreboot_video_console.columns; column++) |
| 98 |
chars[(coreboot_video_console.rows - 1) * coreboot_video_console.columns + column] = (VGA_COLOR_DEFAULT << 8); |
| 99 |
|
| 100 |
cursor_y--; |
| 101 |
} |
| 102 |
|
| 103 |
static void corebootfb_clear(void) |
| 104 |
{ |
| 105 |
int row, column; |
| 106 |
unsigned char *ptr = FB; |
| 107 |
|
| 108 |
|
| 109 |
for (row = 0; row < fbinfo.y_resolution; row++) { |
| 110 |
memset(ptr, 0, fbinfo.x_resolution * (fbinfo.bits_per_pixel >> 3)); |
| 111 |
ptr += fbinfo.bytes_per_line; |
| 112 |
} |
| 113 |
|
| 114 |
|
| 115 |
for(row = 0; row < coreboot_video_console.rows; row++) |
| 116 |
for (column = 0; column < coreboot_video_console.columns; column++) |
| 117 |
chars[row * coreboot_video_console.columns + column] = (VGA_COLOR_DEFAULT << 8); |
| 118 |
} |
| 119 |
|
| 120 |
static void corebootfb_putchar(u8 row, u8 col, unsigned int ch) |
| 121 |
{ |
| 122 |
unsigned char *dst; |
| 123 |
|
| 124 |
unsigned char bg = (ch >> 12) & 0xF; |
| 125 |
unsigned char fg = (ch >> 8) & 0xF; |
| 126 |
u32 fgval = 0, bgval = 0; |
| 127 |
u16 *dst16; |
| 128 |
u32 *dst32; |
| 129 |
|
| 130 |
int x, y; |
| 131 |
|
| 132 |
if (fbinfo.bits_per_pixel > 8) { |
| 133 |
bgval = ((((vga_colors[bg] >> 0) & 0xff) >> (8 - fbinfo.blue_mask_size)) << fbinfo.blue_mask_pos) | |
| 134 |
((((vga_colors[bg] >> 8) & 0xff) >> (8 - fbinfo.green_mask_size)) << fbinfo.green_mask_pos) | |
| 135 |
((((vga_colors[bg] >> 16) & 0xff) >> (8 - fbinfo.red_mask_size)) << fbinfo.red_mask_pos); |
| 136 |
fgval = ((((vga_colors[fg] >> 0) & 0xff) >> (8 - fbinfo.blue_mask_size)) << fbinfo.blue_mask_pos) | |
| 137 |
((((vga_colors[fg] >> 8) & 0xff) >> (8 - fbinfo.green_mask_size)) << fbinfo.green_mask_pos) | |
| 138 |
((((vga_colors[fg] >> 16) & 0xff) >> (8 - fbinfo.red_mask_size)) << fbinfo.red_mask_pos); |
| 139 |
} |
| 140 |
|
| 141 |
dst = FB + ((row * font_height) * fbinfo.bytes_per_line); |
| 142 |
dst += (col * font_width * (fbinfo.bits_per_pixel >> 3)); |
| 143 |
|
| 144 |
for(y = 0; y < font_height; y++) { |
| 145 |
for(x = font_width - 1; x >= 0; x--) { |
| 146 |
|
| 147 |
switch (fbinfo.bits_per_pixel) { |
| 148 |
case 8: |
| 149 |
dst[(font_width - x) * (fbinfo.bits_per_pixel >> 3)] = font_glyph_filled(ch, x, y) ? fg : bg; |
| 150 |
break; |
| 151 |
case 16: |
| 152 |
dst16 = (u16 *)(dst + (font_width - x) * (fbinfo.bits_per_pixel >> 3)); |
| 153 |
*dst16 = font_glyph_filled(ch, x, y) ? fgval : bgval; |
| 154 |
break; |
| 155 |
case 24: |
| 156 |
if (font_glyph_filled(ch, x, y)) { |
| 157 |
dst[(font_width - x) * (fbinfo.bits_per_pixel >> 3) + 0] = fgval & 0xff; |
| 158 |
dst[(font_width - x) * (fbinfo.bits_per_pixel >> 3) + 1] = (fgval >> 8) & 0xff; |
| 159 |
dst[(font_width - x) * (fbinfo.bits_per_pixel >> 3) + 2] = (fgval >> 16) & 0xff; |
| 160 |
} else { |
| 161 |
dst[(font_width - x) * (fbinfo.bits_per_pixel >> 3) + 0] = bgval & 0xff; |
| 162 |
dst[(font_width - x) * (fbinfo.bits_per_pixel >> 3) + 1] = (bgval >> 8) & 0xff; |
| 163 |
dst[(font_width - x) * (fbinfo.bits_per_pixel >> 3) + 2] = (bgval >> 16) & 0xff; |
| 164 |
} |
| 165 |
break; |
| 166 |
case 32: |
| 167 |
dst32 = (u32 *)(dst + (font_width - x) * (fbinfo.bits_per_pixel >> 3)); |
| 168 |
*dst32 = font_glyph_filled(ch, x, y) ? fgval : bgval; |
| 169 |
break; |
| 170 |
} |
| 171 |
} |
| 172 |
|
| 173 |
dst += fbinfo.bytes_per_line; |
| 174 |
} |
| 175 |
} |
| 176 |
|
| 177 |
static void corebootfb_putc(u8 row, u8 col, unsigned int ch) |
| 178 |
{ |
| 179 |
chars[row * coreboot_video_console.columns + col] = ch; |
| 180 |
corebootfb_putchar(row, col, ch); |
| 181 |
} |
| 182 |
|
| 183 |
static void corebootfb_update_cursor(void) |
| 184 |
{ |
| 185 |
int ch, paint; |
| 186 |
if(cursor_en) { |
| 187 |
ch = chars[cursor_y * coreboot_video_console.columns + cursor_x]; |
| 188 |
paint = (ch & 0xff) | ((ch << 4) & 0xf000) | ((ch >> 4) & 0x0f00); |
| 189 |
} else { |
| 190 |
paint = chars[cursor_y * coreboot_video_console.columns + cursor_x]; |
| 191 |
} |
| 192 |
|
| 193 |
if (cursor_y < coreboot_video_console.rows) |
| 194 |
corebootfb_putchar(cursor_y, cursor_x, paint); |
| 195 |
} |
| 196 |
|
| 197 |
static void corebootfb_enable_cursor(int state) |
| 198 |
{ |
| 199 |
cursor_en = state; |
| 200 |
corebootfb_update_cursor(); |
| 201 |
} |
| 202 |
|
| 203 |
static void corebootfb_get_cursor(unsigned int *x, unsigned int *y, unsigned int *en) |
| 204 |
{ |
| 205 |
*x = cursor_x; |
| 206 |
*y = cursor_y; |
| 207 |
*en = cursor_en; |
| 208 |
} |
| 209 |
|
| 210 |
static void corebootfb_set_cursor(unsigned int x, unsigned int y) |
| 211 |
{ |
| 212 |
int cursor_remember = cursor_en; |
| 213 |
if (cursor_remember) |
| 214 |
corebootfb_enable_cursor(0); |
| 215 |
|
| 216 |
cursor_x = x; |
| 217 |
cursor_y = y; |
| 218 |
|
| 219 |
if (cursor_remember) |
| 220 |
corebootfb_enable_cursor(1); |
| 221 |
} |
| 222 |
|
| 223 |
static int corebootfb_init(void) |
| 224 |
{ |
| 225 |
if (!lib_sysinfo.framebuffer.physical_address) |
| 226 |
return -1; |
| 227 |
|
| 228 |
fbinfo = lib_sysinfo.framebuffer; |
| 229 |
|
| 230 |
font_init(fbinfo.x_resolution); |
| 231 |
|
| 232 |
|
| 233 |
const int center = |
| 234 |
IS_ENABLED(CONFIG_LP_COREBOOT_VIDEO_CENTERED) |
| 235 |
&& coreboot_video_console.columns * font_width <= fbinfo.x_resolution |
| 236 |
&& coreboot_video_console.rows * font_height <= fbinfo.y_resolution; |
| 237 |
|
| 238 |
if (!center) { |
| 239 |
coreboot_video_console.columns = fbinfo.x_resolution / font_width; |
| 240 |
coreboot_video_console.rows = fbinfo.y_resolution / font_height; |
| 241 |
} |
| 242 |
|
| 243 |
chars = malloc(coreboot_video_console.rows * |
| 244 |
coreboot_video_console.columns * 2); |
| 245 |
if (!chars) |
| 246 |
return -1; |
| 247 |
|
| 248 |
|
| 249 |
corebootfb_clear(); |
| 250 |
|
| 251 |
if (center) { |
| 252 |
fbinfo.physical_address += |
| 253 |
(fbinfo.x_resolution - coreboot_video_console.columns * font_width) |
| 254 |
/ 2 * fbinfo.bits_per_pixel / 8 |
| 255 |
+ (fbinfo.y_resolution - coreboot_video_console.rows * font_height) |
| 256 |
/ 2 * fbinfo.bytes_per_line; |
| 257 |
fbinfo.x_resolution = coreboot_video_console.columns * font_width; |
| 258 |
fbinfo.y_resolution = coreboot_video_console.rows * font_height; |
| 259 |
} |
| 260 |
|
| 261 |
return 0; |
| 262 |
} |
| 263 |
|
| 264 |
struct video_console coreboot_video_console = { |
| 265 |
.init = corebootfb_init, |
| 266 |
.putc = corebootfb_putc, |
| 267 |
.clear = corebootfb_clear, |
| 268 |
.scroll_up = corebootfb_scroll_up, |
| 269 |
|
| 270 |
.get_cursor = corebootfb_get_cursor, |
| 271 |
.set_cursor = corebootfb_set_cursor, |
| 272 |
.enable_cursor = corebootfb_enable_cursor, |
| 273 |
|
| 274 |
.columns = 80, |
| 275 |
.rows = 25 |
| 276 |
}; |