2010-03-25 19:56:26 +01:00
|
|
|
/*
|
|
|
|
* This file is part of the libpayload project.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2008 Advanced Micro Devices, Inc.
|
|
|
|
* Copyright (C) 2010 coresystems GmbH
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. The name of the author may not be used to endorse or promote products
|
|
|
|
* derived from this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <libpayload.h>
|
|
|
|
#include <coreboot_tables.h>
|
|
|
|
#include <pci.h>
|
|
|
|
#include <video_console.h>
|
2017-07-23 14:36:43 +02:00
|
|
|
#include "font.h"
|
2010-03-25 19:56:26 +01:00
|
|
|
|
|
|
|
struct video_console coreboot_video_console;
|
|
|
|
|
|
|
|
static unsigned int cursor_x = 0, cursor_y = 0, cursor_en = 0;
|
|
|
|
|
|
|
|
/* color definitions for the 16 standard colors */
|
|
|
|
|
|
|
|
#define VGA_COLOR_DEFAULT 7
|
|
|
|
static const u32 vga_colors[] = {
|
|
|
|
// BLUE | GREEN | RED
|
|
|
|
(0x00 << 16) | (0x00 << 8) | 0x00,
|
|
|
|
(0xAA << 16) | (0x00 << 8) | 0x00,
|
|
|
|
(0x00 << 16) | (0xAA << 8) | 0x00,
|
|
|
|
(0xAA << 16) | (0x55 << 8) | 0x00,
|
|
|
|
(0x00 << 16) | (0x00 << 8) | 0xAA,
|
|
|
|
(0xAA << 16) | (0x00 << 8) | 0xAA,
|
|
|
|
(0x00 << 16) | (0xAA << 8) | 0xAA,
|
|
|
|
(0xAA << 16) | (0xAA << 8) | 0xAA,
|
|
|
|
(0x55 << 16) | (0x55 << 8) | 0x55,
|
|
|
|
(0xFF << 16) | (0x55 << 8) | 0x55,
|
|
|
|
(0x55 << 16) | (0xFF << 8) | 0x55,
|
|
|
|
(0xFF << 16) | (0xFF << 8) | 0x55,
|
|
|
|
(0x55 << 16) | (0x55 << 8) | 0xFF,
|
|
|
|
(0xFF << 16) | (0x55 << 8) | 0xFF,
|
|
|
|
(0x55 << 16) | (0xFF << 8) | 0xFF,
|
|
|
|
(0xFF << 16) | (0xFF << 8) | 0xFF,
|
|
|
|
};
|
|
|
|
|
2020-01-16 13:08:18 +01:00
|
|
|
struct cb_framebuffer fbinfo;
|
2020-01-23 12:48:03 +01:00
|
|
|
static unsigned short *chars;
|
2010-03-25 19:56:26 +01:00
|
|
|
|
2020-01-16 13:08:18 +01:00
|
|
|
/* Addresses for the various components */
|
|
|
|
#define FI (&fbinfo)
|
|
|
|
#define FB ((unsigned char *) phys_to_virt(FI->physical_address))
|
2020-01-23 12:48:03 +01:00
|
|
|
#define CHARS (chars)
|
2010-03-25 19:56:26 +01:00
|
|
|
|
|
|
|
static void corebootfb_scroll_up(void)
|
|
|
|
{
|
|
|
|
unsigned char *dst = FB;
|
2017-07-23 14:36:43 +02:00
|
|
|
unsigned char *src = FB + (FI->bytes_per_line * font_height);
|
2010-03-25 19:56:26 +01:00
|
|
|
int y;
|
|
|
|
|
|
|
|
/* Scroll all lines up */
|
2017-07-23 14:36:43 +02:00
|
|
|
for(y = 0; y < FI->y_resolution - font_height; y++) {
|
2010-03-25 19:56:26 +01:00
|
|
|
memcpy(dst, src, FI->x_resolution * (FI->bits_per_pixel >> 3));
|
|
|
|
|
|
|
|
dst += FI->bytes_per_line;
|
|
|
|
src += FI->bytes_per_line;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Erase last line */
|
2017-07-23 14:36:43 +02:00
|
|
|
dst = FB + (FI->y_resolution - font_height) * FI->bytes_per_line;
|
2010-03-25 19:56:26 +01:00
|
|
|
|
|
|
|
for(; y < FI->y_resolution; y++) {
|
|
|
|
memset(dst, 0, FI->x_resolution * (FI->bits_per_pixel >> 3));
|
|
|
|
dst += FI->bytes_per_line;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* And update the char buffer */
|
|
|
|
dst = (unsigned char *) CHARS;
|
|
|
|
src = (unsigned char *) (CHARS + coreboot_video_console.columns);
|
|
|
|
memcpy(dst, src, coreboot_video_console.columns *
|
|
|
|
(coreboot_video_console.rows - 1) * 2);
|
|
|
|
int column;
|
|
|
|
for (column = 0; column < coreboot_video_console.columns; column++)
|
|
|
|
CHARS[(coreboot_video_console.rows - 1) * coreboot_video_console.columns + column] = (VGA_COLOR_DEFAULT << 8);
|
|
|
|
|
|
|
|
cursor_y--;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void corebootfb_clear(void)
|
|
|
|
{
|
|
|
|
int row, column;
|
|
|
|
unsigned char *ptr = FB;
|
|
|
|
|
|
|
|
/* Clear the screen */
|
|
|
|
for(row = 0; row < FI->y_resolution; row++) {
|
|
|
|
memset(ptr, 0, FI->x_resolution * (FI->bits_per_pixel >> 3));
|
|
|
|
ptr += FI->bytes_per_line;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* And update the char buffer */
|
|
|
|
for(row = 0; row < coreboot_video_console.rows; row++)
|
|
|
|
for (column = 0; column < coreboot_video_console.columns; column++)
|
|
|
|
CHARS[row * coreboot_video_console.columns + column] = (VGA_COLOR_DEFAULT << 8);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void corebootfb_putchar(u8 row, u8 col, unsigned int ch)
|
|
|
|
{
|
|
|
|
unsigned char *dst;
|
|
|
|
|
|
|
|
unsigned char bg = (ch >> 12) & 0xF;
|
|
|
|
unsigned char fg = (ch >> 8) & 0xF;
|
|
|
|
u32 fgval = 0, bgval = 0;
|
|
|
|
u16 *dst16;
|
|
|
|
u32 *dst32;
|
|
|
|
|
|
|
|
int x, y;
|
|
|
|
|
|
|
|
if (FI->bits_per_pixel > 8) {
|
|
|
|
bgval = ((((vga_colors[bg] >> 0) & 0xff) >> (8 - FI->blue_mask_size)) << FI->blue_mask_pos) |
|
|
|
|
((((vga_colors[bg] >> 8) & 0xff) >> (8 - FI->green_mask_size)) << FI->green_mask_pos) |
|
|
|
|
((((vga_colors[bg] >> 16) & 0xff) >> (8 - FI->red_mask_size)) << FI->red_mask_pos);
|
|
|
|
fgval = ((((vga_colors[fg] >> 0) & 0xff) >> (8 - FI->blue_mask_size)) << FI->blue_mask_pos) |
|
|
|
|
((((vga_colors[fg] >> 8) & 0xff) >> (8 - FI->green_mask_size)) << FI->green_mask_pos) |
|
|
|
|
((((vga_colors[fg] >> 16) & 0xff) >> (8 - FI->red_mask_size)) << FI->red_mask_pos);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-07-23 14:36:43 +02:00
|
|
|
dst = FB + ((row * font_height) * FI->bytes_per_line);
|
|
|
|
dst += (col * font_width * (FI->bits_per_pixel >> 3));
|
2010-03-25 19:56:26 +01:00
|
|
|
|
2017-07-23 14:36:43 +02:00
|
|
|
for(y = 0; y < font_height; y++) {
|
|
|
|
for(x = font_width - 1; x >= 0; x--) {
|
2010-04-27 08:56:47 +02:00
|
|
|
|
2010-03-25 19:56:26 +01:00
|
|
|
switch (FI->bits_per_pixel) {
|
|
|
|
case 8: /* Indexed */
|
2017-07-23 14:36:43 +02:00
|
|
|
dst[(font_width - x) * (FI->bits_per_pixel >> 3)] = font_glyph_filled(ch, x, y) ? fg : bg;
|
2010-03-25 19:56:26 +01:00
|
|
|
break;
|
|
|
|
case 16: /* 16 bpp */
|
2017-07-23 14:36:43 +02:00
|
|
|
dst16 = (u16 *)(dst + (font_width - x) * (FI->bits_per_pixel >> 3));
|
|
|
|
*dst16 = font_glyph_filled(ch, x, y) ? fgval : bgval;
|
2010-03-25 19:56:26 +01:00
|
|
|
break;
|
|
|
|
case 24: /* 24 bpp */
|
2017-07-23 14:36:43 +02:00
|
|
|
if (font_glyph_filled(ch, x, y)) {
|
|
|
|
dst[(font_width - x) * (FI->bits_per_pixel >> 3) + 0] = fgval & 0xff;
|
|
|
|
dst[(font_width - x) * (FI->bits_per_pixel >> 3) + 1] = (fgval >> 8) & 0xff;
|
|
|
|
dst[(font_width - x) * (FI->bits_per_pixel >> 3) + 2] = (fgval >> 16) & 0xff;
|
2010-03-25 19:56:26 +01:00
|
|
|
} else {
|
2017-07-23 14:36:43 +02:00
|
|
|
dst[(font_width - x) * (FI->bits_per_pixel >> 3) + 0] = bgval & 0xff;
|
|
|
|
dst[(font_width - x) * (FI->bits_per_pixel >> 3) + 1] = (bgval >> 8) & 0xff;
|
|
|
|
dst[(font_width - x) * (FI->bits_per_pixel >> 3) + 2] = (bgval >> 16) & 0xff;
|
2010-03-25 19:56:26 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 32: /* 32 bpp */
|
2017-07-23 14:36:43 +02:00
|
|
|
dst32 = (u32 *)(dst + (font_width - x) * (FI->bits_per_pixel >> 3));
|
|
|
|
*dst32 = font_glyph_filled(ch, x, y) ? fgval : bgval;
|
2010-03-25 19:56:26 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
dst += FI->bytes_per_line;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void corebootfb_putc(u8 row, u8 col, unsigned int ch)
|
|
|
|
{
|
|
|
|
CHARS[row * coreboot_video_console.columns + col] = ch;
|
|
|
|
corebootfb_putchar(row, col, ch);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void corebootfb_update_cursor(void)
|
|
|
|
{
|
|
|
|
int ch, paint;
|
|
|
|
if(cursor_en) {
|
|
|
|
ch = CHARS[cursor_y * coreboot_video_console.columns + cursor_x];
|
2017-06-27 21:51:20 +02:00
|
|
|
paint = (ch & 0xff) | ((ch << 4) & 0xf000) | ((ch >> 4) & 0x0f00);
|
2010-03-25 19:56:26 +01:00
|
|
|
} else {
|
|
|
|
paint = CHARS[cursor_y * coreboot_video_console.columns + cursor_x];
|
|
|
|
}
|
|
|
|
|
2014-12-29 20:41:37 +01:00
|
|
|
if (cursor_y < coreboot_video_console.rows)
|
2010-03-25 19:56:26 +01:00
|
|
|
corebootfb_putchar(cursor_y, cursor_x, paint);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void corebootfb_enable_cursor(int state)
|
|
|
|
{
|
|
|
|
cursor_en = state;
|
|
|
|
corebootfb_update_cursor();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void corebootfb_get_cursor(unsigned int *x, unsigned int *y, unsigned int *en)
|
|
|
|
{
|
|
|
|
*x = cursor_x;
|
|
|
|
*y = cursor_y;
|
|
|
|
*en = cursor_en;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void corebootfb_set_cursor(unsigned int x, unsigned int y)
|
|
|
|
{
|
|
|
|
int cursor_remember = cursor_en;
|
|
|
|
if (cursor_remember)
|
|
|
|
corebootfb_enable_cursor(0);
|
|
|
|
|
|
|
|
cursor_x = x;
|
|
|
|
cursor_y = y;
|
|
|
|
|
|
|
|
if (cursor_remember)
|
|
|
|
corebootfb_enable_cursor(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int corebootfb_init(void)
|
|
|
|
{
|
|
|
|
if (lib_sysinfo.framebuffer == NULL)
|
|
|
|
return -1;
|
|
|
|
|
2020-01-16 13:08:18 +01:00
|
|
|
fbinfo = *lib_sysinfo.framebuffer;
|
2010-03-25 19:56:26 +01:00
|
|
|
|
2020-01-16 13:08:18 +01:00
|
|
|
if (FI->physical_address == 0)
|
2017-06-26 10:38:00 +02:00
|
|
|
return -1;
|
2010-03-25 19:56:26 +01:00
|
|
|
|
2017-07-23 15:05:47 +02:00
|
|
|
font_init(FI->x_resolution);
|
2017-07-23 14:36:43 +02:00
|
|
|
|
2020-01-23 13:23:09 +01:00
|
|
|
/* Draw centered on the framebuffer if requested and feasible, */
|
|
|
|
const int center =
|
|
|
|
IS_ENABLED(CONFIG_LP_COREBOOT_VIDEO_CENTERED)
|
|
|
|
&& coreboot_video_console.columns * font_width <= FI->x_resolution
|
|
|
|
&& coreboot_video_console.rows * font_height <= FI->y_resolution;
|
|
|
|
/* adapt to the framebuffer size, otherwise. */
|
|
|
|
if (!center) {
|
|
|
|
coreboot_video_console.columns = FI->x_resolution / font_width;
|
|
|
|
coreboot_video_console.rows = FI->y_resolution / font_height;
|
|
|
|
}
|
2010-03-25 19:56:26 +01:00
|
|
|
|
2020-01-23 12:48:03 +01:00
|
|
|
chars = malloc(coreboot_video_console.rows *
|
|
|
|
coreboot_video_console.columns * 2);
|
|
|
|
if (!chars)
|
|
|
|
return -1;
|
2010-03-25 19:56:26 +01:00
|
|
|
|
|
|
|
// clear boot splash screen if there is one.
|
|
|
|
corebootfb_clear();
|
2020-01-23 13:23:09 +01:00
|
|
|
|
|
|
|
if (center) {
|
|
|
|
FI->physical_address +=
|
|
|
|
(FI->x_resolution - coreboot_video_console.columns * font_width)
|
|
|
|
/ 2 * FI->bits_per_pixel / 8
|
|
|
|
+ (FI->y_resolution - coreboot_video_console.rows * font_height)
|
|
|
|
/ 2 * FI->bytes_per_line;
|
|
|
|
FI->x_resolution = coreboot_video_console.columns * font_width;
|
|
|
|
FI->y_resolution = coreboot_video_console.rows * font_height;
|
|
|
|
}
|
|
|
|
|
2010-03-25 19:56:26 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct video_console coreboot_video_console = {
|
|
|
|
.init = corebootfb_init,
|
|
|
|
.putc = corebootfb_putc,
|
|
|
|
.clear = corebootfb_clear,
|
|
|
|
.scroll_up = corebootfb_scroll_up,
|
|
|
|
|
|
|
|
.get_cursor = corebootfb_get_cursor,
|
|
|
|
.set_cursor = corebootfb_set_cursor,
|
|
|
|
.enable_cursor = corebootfb_enable_cursor,
|
|
|
|
|
|
|
|
.columns = 80,
|
|
|
|
.rows = 25
|
|
|
|
};
|