summaryrefslogtreecommitdiff
path: root/payloads/libpayload/drivers
diff options
context:
space:
mode:
Diffstat (limited to 'payloads/libpayload/drivers')
-rw-r--r--payloads/libpayload/drivers/Makefile.inc2
-rw-r--r--payloads/libpayload/drivers/video/corebootfb.c48
-rw-r--r--payloads/libpayload/drivers/video/font.c40
-rw-r--r--payloads/libpayload/drivers/video/font.h46
-rw-r--r--payloads/libpayload/drivers/video/geodelx.c20
5 files changed, 122 insertions, 34 deletions
diff --git a/payloads/libpayload/drivers/Makefile.inc b/payloads/libpayload/drivers/Makefile.inc
index c6f6575df6..8dc6e8bbb6 100644
--- a/payloads/libpayload/drivers/Makefile.inc
+++ b/payloads/libpayload/drivers/Makefile.inc
@@ -63,10 +63,12 @@ libc-$(CONFIG_LP_VGA_VIDEO_CONSOLE) += video/vga.c
# Geode LX console drivers
libc-$(CONFIG_LP_GEODELX_VIDEO_CONSOLE) += video/geodelx.c
libc-$(CONFIG_LP_GEODELX_VIDEO_CONSOLE) += video/font8x16.c
+libc-$(CONFIG_LP_GEODELX_VIDEO_CONSOLE) += video/font.c
# coreboot generic framebuffer driver
libc-$(CONFIG_LP_COREBOOT_VIDEO_CONSOLE) += video/corebootfb.c
libc-$(CONFIG_LP_COREBOOT_VIDEO_CONSOLE) += video/font8x16.c
+libc-$(CONFIG_LP_COREBOOT_VIDEO_CONSOLE) += video/font.c
# cbgfx: coreboot graphics library
libc-y += video/graphics.c
diff --git a/payloads/libpayload/drivers/video/corebootfb.c b/payloads/libpayload/drivers/video/corebootfb.c
index 572a02bf66..69aa1d7f65 100644
--- a/payloads/libpayload/drivers/video/corebootfb.c
+++ b/payloads/libpayload/drivers/video/corebootfb.c
@@ -32,7 +32,7 @@
#include <coreboot_tables.h>
#include <pci.h>
#include <video_console.h>
-#include "font8x16.h"
+#include "font.h"
struct video_console coreboot_video_console;
@@ -73,11 +73,11 @@ static unsigned long chars;
static void corebootfb_scroll_up(void)
{
unsigned char *dst = FB;
- unsigned char *src = FB + (FI->bytes_per_line * FONT_HEIGHT);
+ unsigned char *src = FB + (FI->bytes_per_line * font_height);
int y;
/* Scroll all lines up */
- for(y = 0; y < FI->y_resolution - FONT_HEIGHT; y++) {
+ for(y = 0; y < FI->y_resolution - font_height; y++) {
memcpy(dst, src, FI->x_resolution * (FI->bits_per_pixel >> 3));
dst += FI->bytes_per_line;
@@ -85,7 +85,7 @@ static void corebootfb_scroll_up(void)
}
/* Erase last line */
- dst = FB + (FI->y_resolution - FONT_HEIGHT) * FI->bytes_per_line;
+ dst = FB + (FI->y_resolution - font_height) * FI->bytes_per_line;
for(; y < FI->y_resolution; y++) {
memset(dst, 0, FI->x_resolution * (FI->bits_per_pixel >> 3));
@@ -124,7 +124,6 @@ static void corebootfb_clear(void)
static void corebootfb_putchar(u8 row, u8 col, unsigned int ch)
{
unsigned char *dst;
- unsigned char *glyph = font8x16 + ((ch & 0xFF) * FONT_HEIGHT);
unsigned char bg = (ch >> 12) & 0xF;
unsigned char fg = (ch >> 8) & 0xF;
@@ -144,40 +143,39 @@ static void corebootfb_putchar(u8 row, u8 col, unsigned int ch)
}
- dst = FB + ((row * FONT_HEIGHT) * FI->bytes_per_line);
- dst += (col * FONT_WIDTH * (FI->bits_per_pixel >> 3));
+ dst = FB + ((row * font_height) * FI->bytes_per_line);
+ dst += (col * font_width * (FI->bits_per_pixel >> 3));
- for(y = 0; y < FONT_HEIGHT; y++) {
- for(x = FONT_WIDTH - 1; x >= 0; x--) {
+ for(y = 0; y < font_height; y++) {
+ for(x = font_width - 1; x >= 0; x--) {
switch (FI->bits_per_pixel) {
case 8: /* Indexed */
- dst[(FONT_WIDTH - x) * (FI->bits_per_pixel >> 3)] = (*glyph & (1 << x)) ? fg : bg;
+ dst[(font_width - x) * (FI->bits_per_pixel >> 3)] = font_glyph_filled(ch, x, y) ? fg : bg;
break;
case 16: /* 16 bpp */
- dst16 = (u16 *)(dst + (FONT_WIDTH - x) * (FI->bits_per_pixel >> 3));
- *dst16 = (*glyph & (1 << x)) ? fgval : bgval;
+ dst16 = (u16 *)(dst + (font_width - x) * (FI->bits_per_pixel >> 3));
+ *dst16 = font_glyph_filled(ch, x, y) ? fgval : bgval;
break;
case 24: /* 24 bpp */
- if (*glyph & (1 << x)) {
- 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;
+ 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;
} else {
- 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;
+ 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;
}
break;
case 32: /* 32 bpp */
- dst32 = (u32 *)(dst + (FONT_WIDTH - x) * (FI->bits_per_pixel >> 3));
- *dst32 = (*glyph & (1 << x)) ? fgval : bgval;
+ dst32 = (u32 *)(dst + (font_width - x) * (FI->bits_per_pixel >> 3));
+ *dst32 = font_glyph_filled(ch, x, y) ? fgval : bgval;
break;
}
}
dst += FI->bytes_per_line;
- glyph++;
}
}
@@ -240,8 +238,10 @@ static int corebootfb_init(void)
if (fbaddr == 0)
return -1;
- coreboot_video_console.columns = FI->x_resolution / FONT_WIDTH;
- coreboot_video_console.rows = FI->y_resolution / FONT_HEIGHT;
+ font_init();
+
+ coreboot_video_console.columns = FI->x_resolution / font_width;
+ coreboot_video_console.rows = FI->y_resolution / font_height;
/* See setting of fbinfo above. */
chars = virt_to_phys(malloc(coreboot_video_console.rows *
diff --git a/payloads/libpayload/drivers/video/font.c b/payloads/libpayload/drivers/video/font.c
new file mode 100644
index 0000000000..59d476dacf
--- /dev/null
+++ b/payloads/libpayload/drivers/video/font.c
@@ -0,0 +1,40 @@
+/*
+ * This file is part of the libpayload project.
+ *
+ * Copyright (C) 2017 Paul Kocialkowski <contact@paulk.fr>
+ *
+ * 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 "font8x16.h"
+#include "font.h"
+
+int font_width;
+int font_height;
+
+void font_init(void)
+{
+ font_width = FONT_WIDTH;
+ font_height = FONT_HEIGHT;
+}
diff --git a/payloads/libpayload/drivers/video/font.h b/payloads/libpayload/drivers/video/font.h
new file mode 100644
index 0000000000..a5e0b85c02
--- /dev/null
+++ b/payloads/libpayload/drivers/video/font.h
@@ -0,0 +1,46 @@
+/*
+ * This file is part of the libpayload project.
+ *
+ * Copyright (C) 2017 Paul Kocialkowski <contact@paulk.fr>
+ *
+ * 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.
+ */
+
+#ifndef _DRIVERS_VIDEO_FONT_H
+#define _DRIVERS_VIDEO_FONT_H
+
+#include "font8x16.h"
+
+extern int font_width;
+extern int font_height;
+
+inline int font_glyph_filled(unsigned int ch, int x, int y)
+{
+ unsigned char *glyph = font8x16 + ((ch & 0xFF) * FONT_HEIGHT);
+ return glyph[y] & (1 << x);
+}
+
+void font_init(void);
+
+#endif
diff --git a/payloads/libpayload/drivers/video/geodelx.c b/payloads/libpayload/drivers/video/geodelx.c
index ede997cb26..46fa833ec1 100644
--- a/payloads/libpayload/drivers/video/geodelx.c
+++ b/payloads/libpayload/drivers/video/geodelx.c
@@ -31,7 +31,7 @@
#include <pci.h>
#include <video_console.h>
#include <arch/msr.h>
-#include "font8x16.h"
+#include "font.h"
/* This is the video mode that we're going to use for our VGA screen */
@@ -206,10 +206,10 @@ static void geodelx_set_palette(int entry, unsigned int color)
static void geodelx_scroll_up(void)
{
unsigned char *dst = FB;
- unsigned char *src = FB + FONT_HEIGHT * vga_mode.hactive;
+ unsigned char *src = FB + font_height * vga_mode.hactive;
int y;
- for(y = 0; y < vga_mode.vactive - FONT_HEIGHT; y++) {
+ for(y = 0; y < vga_mode.vactive - font_height; y++) {
memcpy(dst, src, vga_mode.hactive);
dst += vga_mode.hactive;
@@ -236,24 +236,22 @@ static void geodelx_clear(void)
static void geodelx_putc(u8 row, u8 col, unsigned int ch)
{
unsigned char *dst;
- unsigned char *glyph = font8x16 + ((ch & 0xFF) * FONT_HEIGHT);
unsigned char bg = (ch >> 12) & 0xF;
unsigned char fg = (ch >> 8) & 0xF;
int x, y;
- dst = FB + ((row * FONT_HEIGHT) * vga_mode.hactive);
- dst += (col * FONT_WIDTH);
+ dst = FB + ((row * font_height) * vga_mode.hactive);
+ dst += (col * font_width);
- for(y = 0; y < FONT_HEIGHT; y++) {
+ for(y = 0; y < font_height; y++) {
- for(x = FONT_WIDTH - 1; x >= 0; x--)
- dst[FONT_WIDTH - x] = (*glyph & (1 << x)) ?
+ for(x = font_width - 1; x >= 0; x--)
+ dst[font_width - x] = font_glyph_filled(ch, x, y) ?
fg : bg;
dst += vga_mode.hactive;
- glyph++;
}
}
@@ -270,6 +268,8 @@ static int geodelx_init(void)
dcaddr = pci_read_resource(dev, 2);
vgaddr = pci_read_resource(dev, 3);
+ font_init();
+
init_video_mode();
/* Set up the palette */