<p>Paul Kocialkowski has uploaded this change for <strong>review</strong>.</p><p><a href="https://review.coreboot.org/20708">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">libpayload: video: Introduce helpers for font access<br><br>This introduces helpers for accessing the included font, instead of<br>using hardcoded values provided by the font's header itself.<br><br>It will allow painlessly adding support for font scaling in a subsequent<br>change. It should not introduce any functionality change.<br><br>Change-Id: I0277984ec01f49dc51bfc8237ef806f13e3547e2<br>Signed-off-by: Paul Kocialkowski <contact@paulk.fr><br>---<br>M payloads/libpayload/drivers/Makefile.inc<br>M payloads/libpayload/drivers/video/corebootfb.c<br>A payloads/libpayload/drivers/video/font.c<br>A payloads/libpayload/drivers/video/font.h<br>M payloads/libpayload/drivers/video/geodelx.c<br>5 files changed, 133 insertions(+), 34 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://review.coreboot.org:29418/coreboot refs/changes/08/20708/1</pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">diff --git a/payloads/libpayload/drivers/Makefile.inc b/payloads/libpayload/drivers/Makefile.inc<br>index c6f6575..8dc6e8b 100644<br>--- a/payloads/libpayload/drivers/Makefile.inc<br>+++ b/payloads/libpayload/drivers/Makefile.inc<br>@@ -63,10 +63,12 @@<br> # Geode LX console drivers<br> libc-$(CONFIG_LP_GEODELX_VIDEO_CONSOLE) += video/geodelx.c<br> libc-$(CONFIG_LP_GEODELX_VIDEO_CONSOLE) += video/font8x16.c<br>+libc-$(CONFIG_LP_GEODELX_VIDEO_CONSOLE) += video/font.c<br> <br> # coreboot generic framebuffer driver<br> libc-$(CONFIG_LP_COREBOOT_VIDEO_CONSOLE) += video/corebootfb.c<br> libc-$(CONFIG_LP_COREBOOT_VIDEO_CONSOLE) += video/font8x16.c<br>+libc-$(CONFIG_LP_COREBOOT_VIDEO_CONSOLE) += video/font.c<br> <br> # cbgfx: coreboot graphics library<br> libc-y += video/graphics.c<br>diff --git a/payloads/libpayload/drivers/video/corebootfb.c b/payloads/libpayload/drivers/video/corebootfb.c<br>index 572a02b..6c2d242 100644<br>--- a/payloads/libpayload/drivers/video/corebootfb.c<br>+++ b/payloads/libpayload/drivers/video/corebootfb.c<br>@@ -32,7 +32,7 @@<br> #include <coreboot_tables.h><br> #include <pci.h><br> #include <video_console.h><br>-#include "font8x16.h"<br>+#include "font.h"<br> <br> struct video_console coreboot_video_console;<br> <br>@@ -73,11 +73,11 @@<br> static void corebootfb_scroll_up(void)<br> {<br>  unsigned char *dst = FB;<br>-     unsigned char *src = FB + (FI->bytes_per_line * FONT_HEIGHT);<br>+     unsigned char *src = FB + (FI->bytes_per_line * font_height());<br>    int y;<br> <br>     /* Scroll all lines up */<br>-    for(y = 0; y < FI->y_resolution - FONT_HEIGHT; y++) {<br>+  for(y = 0; y < FI->y_resolution - font_height(); y++) {<br>                 memcpy(dst, src, FI->x_resolution * (FI->bits_per_pixel >> 3));<br> <br>                dst += FI->bytes_per_line;<br>@@ -85,7 +85,7 @@<br>      }<br> <br>  /* Erase last line */<br>-        dst = FB + (FI->y_resolution - FONT_HEIGHT) * FI->bytes_per_line;<br>+      dst = FB + (FI->y_resolution - font_height()) * FI->bytes_per_line;<br> <br>  for(; y < FI->y_resolution; y++) {<br>              memset(dst, 0, FI->x_resolution * (FI->bits_per_pixel >> 3));<br>@@ -124,7 +124,6 @@<br> static void corebootfb_putchar(u8 row, u8 col, unsigned int ch)<br> {<br>  unsigned char *dst;<br>-  unsigned char *glyph = font8x16 + ((ch & 0xFF) * FONT_HEIGHT);<br> <br>         unsigned char bg = (ch >> 12) & 0xF;<br>        unsigned char fg = (ch >> 8) & 0xF;<br>@@ -144,40 +143,39 @@<br>  }<br> <br> <br>-      dst = FB + ((row * FONT_HEIGHT) * FI->bytes_per_line);<br>-    dst += (col * FONT_WIDTH * (FI->bits_per_pixel >> 3));<br>+      dst = FB + ((row * font_height()) * FI->bytes_per_line);<br>+  dst += (col * font_width() * (FI->bits_per_pixel >> 3));<br> <br>- for(y = 0; y < FONT_HEIGHT; y++) {<br>-                for(x = FONT_WIDTH - 1; x >= 0; x--) {<br>+    for(y = 0; y < font_height(); y++) {<br>+              for(x = font_width() - 1; x >= 0; x--) {<br> <br>                        switch (FI->bits_per_pixel) {<br>                      case 8: /* Indexed */<br>-                                dst[(FONT_WIDTH - x) * (FI->bits_per_pixel >> 3)] = (*glyph & (1 << x)) ?  fg : bg;<br>+                               dst[(font_width() - x) * (FI->bits_per_pixel >> 3)] = font_glyph_filled(ch, x, y) ?  fg : bg;<br>                                break;<br>                        case 16: /* 16 bpp */<br>-                                dst16 = (u16 *)(dst + (FONT_WIDTH - x) * (FI->bits_per_pixel >> 3));<br>-                                *dst16 = (*glyph & (1 << x)) ? fgval : bgval;<br>+                              dst16 = (u16 *)(dst + (font_width() - x) * (FI->bits_per_pixel >> 3));<br>+                              *dst16 = font_glyph_filled(ch, x, y) ? fgval : bgval;<br>                                 break;<br>                        case 24: /* 24 bpp */<br>-                                if (*glyph & (1 << x)) {<br>-                                   dst[(FONT_WIDTH - x) * (FI->bits_per_pixel >> 3) + 0] = fgval & 0xff;<br>-                                   dst[(FONT_WIDTH - x) * (FI->bits_per_pixel >> 3) + 1] = (fgval >> 8) & 0xff;<br>-                                      dst[(FONT_WIDTH - x) * (FI->bits_per_pixel >> 3) + 2] = (fgval >> 16) & 0xff;<br>+                             if (font_glyph_filled(ch, x, y)) {<br>+                                   dst[(font_width() - x) * (FI->bits_per_pixel >> 3) + 0] = fgval & 0xff;<br>+                                 dst[(font_width() - x) * (FI->bits_per_pixel >> 3) + 1] = (fgval >> 8) & 0xff;<br>+                                    dst[(font_width() - x) * (FI->bits_per_pixel >> 3) + 2] = (fgval >> 16) & 0xff;<br>                            } else {<br>-                                     dst[(FONT_WIDTH - x) * (FI->bits_per_pixel >> 3) + 0] = bgval & 0xff;<br>-                                   dst[(FONT_WIDTH - x) * (FI->bits_per_pixel >> 3) + 1] = (bgval >> 8) & 0xff;<br>-                                      dst[(FONT_WIDTH - x) * (FI->bits_per_pixel >> 3) + 2] = (bgval >> 16) & 0xff;<br>+                                     dst[(font_width() - x) * (FI->bits_per_pixel >> 3) + 0] = bgval & 0xff;<br>+                                 dst[(font_width() - x) * (FI->bits_per_pixel >> 3) + 1] = (bgval >> 8) & 0xff;<br>+                                    dst[(font_width() - x) * (FI->bits_per_pixel >> 3) + 2] = (bgval >> 16) & 0xff;<br>                            }<br>                             break;<br>                        case 32: /* 32 bpp */<br>-                                dst32 = (u32 *)(dst + (FONT_WIDTH - x) * (FI->bits_per_pixel >> 3));<br>-                                *dst32 = (*glyph & (1 << x)) ? fgval : bgval;<br>+                              dst32 = (u32 *)(dst + (font_width() - x) * (FI->bits_per_pixel >> 3));<br>+                              *dst32 = font_glyph_filled(ch, x, y) ? fgval : bgval;<br>                                 break;<br>                        }<br>             }<br> <br>          dst += FI->bytes_per_line;<br>-                glyph++;<br>      }<br> }<br> <br>@@ -232,6 +230,8 @@<br>         if (lib_sysinfo.framebuffer == NULL)<br>          return -1;<br> <br>+        font_init();<br>+<br>       /* We might have been called before relocation (like FILO does). So<br>      just keep the physical address which won't break on relocation. */<br>     fbinfo = virt_to_phys(lib_sysinfo.framebuffer);<br>@@ -240,8 +240,8 @@<br>  if (fbaddr == 0)<br>              return -1;<br> <br>-        coreboot_video_console.columns = FI->x_resolution / FONT_WIDTH;<br>-   coreboot_video_console.rows = FI->y_resolution / FONT_HEIGHT;<br>+     coreboot_video_console.columns = FI->x_resolution / font_width();<br>+ coreboot_video_console.rows = FI->y_resolution / font_height();<br> <br>         /* See setting of fbinfo above. */<br>    chars = virt_to_phys(malloc(coreboot_video_console.rows *<br>diff --git a/payloads/libpayload/drivers/video/font.c b/payloads/libpayload/drivers/video/font.c<br>new file mode 100644<br>index 0000000..3e02b00<br>--- /dev/null<br>+++ b/payloads/libpayload/drivers/video/font.c<br>@@ -0,0 +1,59 @@<br>+/*<br>+ * This file is part of the libpayload project.<br>+ *<br>+ * Copyright (C) 2017 Paul Kocialkowski <contact@paulk.fr><br>+ *<br>+ * Redistribution and use in source and binary forms, with or without<br>+ * modification, are permitted provided that the following conditions<br>+ * are met:<br>+ * 1. Redistributions of source code must retain the above copyright<br>+ *    notice, this list of conditions and the following disclaimer.<br>+ * 2. Redistributions in binary form must reproduce the above copyright<br>+ *    notice, this list of conditions and the following disclaimer in the<br>+ *    documentation and/or other materials provided with the distribution.<br>+ * 3. The name of the author may not be used to endorse or promote products<br>+ *    derived from this software without specific prior written permission.<br>+ *<br>+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND<br>+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE<br>+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE<br>+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE<br>+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL<br>+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS<br>+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)<br>+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT<br>+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY<br>+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF<br>+ * SUCH DAMAGE.<br>+ */<br>+<br>+#include "font8x16.h"<br>+#include "font.h"<br>+<br>+static unsigned char *font;<br>+static int width;<br>+static int height;<br>+<br>+int font_width(void)<br>+{<br>+      return width;<br>+}<br>+<br>+int font_height(void)<br>+{<br>+     return height;<br>+}<br>+<br>+int font_glyph_filled(unsigned int ch, int x, int y)<br>+{<br>+     unsigned char *glyph = font + ((ch & 0xFF) * FONT_HEIGHT);<br>+       return glyph[y] & (1 << x);<br>+}<br>+<br>+void font_init(void)<br>+{<br>+      width = FONT_WIDTH;<br>+  height = FONT_HEIGHT;<br>+<br>+     font = font8x16;<br>+}<br>diff --git a/payloads/libpayload/drivers/video/font.h b/payloads/libpayload/drivers/video/font.h<br>new file mode 100644<br>index 0000000..8dd855a<br>--- /dev/null<br>+++ b/payloads/libpayload/drivers/video/font.h<br>@@ -0,0 +1,38 @@<br>+/*<br>+ * This file is part of the libpayload project.<br>+ *<br>+ * Copyright (C) 2017 Paul Kocialkowski <contact@paulk.fr><br>+ *<br>+ * Redistribution and use in source and binary forms, with or without<br>+ * modification, are permitted provided that the following conditions<br>+ * are met:<br>+ * 1. Redistributions of source code must retain the above copyright<br>+ *    notice, this list of conditions and the following disclaimer.<br>+ * 2. Redistributions in binary form must reproduce the above copyright<br>+ *    notice, this list of conditions and the following disclaimer in the<br>+ *    documentation and/or other materials provided with the distribution.<br>+ * 3. The name of the author may not be used to endorse or promote products<br>+ *    derived from this software without specific prior written permission.<br>+ *<br>+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND<br>+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE<br>+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE<br>+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE<br>+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL<br>+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS<br>+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)<br>+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT<br>+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY<br>+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF<br>+ * SUCH DAMAGE.<br>+ */<br>+<br>+#ifndef _DRIVERS_VIDEO_FONT_H<br>+#define _DRIVERS_VIDEO_FONT_H<br>+<br>+int font_width(void);<br>+int font_height(void);<br>+int font_glyph_filled(unsigned int ch, int x, int y);<br>+void font_init(void);<br>+<br>+#endif<br>diff --git a/payloads/libpayload/drivers/video/geodelx.c b/payloads/libpayload/drivers/video/geodelx.c<br>index ede997c..b8ff1b7 100644<br>--- a/payloads/libpayload/drivers/video/geodelx.c<br>+++ b/payloads/libpayload/drivers/video/geodelx.c<br>@@ -31,7 +31,7 @@<br> #include <pci.h><br> #include <video_console.h><br> #include <arch/msr.h><br>-#include "font8x16.h"<br>+#include "font.h"<br> <br> /* This is the video mode that we're going to use for our VGA screen */<br> <br>@@ -206,10 +206,10 @@<br> static void geodelx_scroll_up(void)<br> {<br>     unsigned char *dst = FB;<br>-     unsigned char *src = FB + FONT_HEIGHT * vga_mode.hactive;<br>+    unsigned char *src = FB + font_height() * vga_mode.hactive;<br>   int y;<br> <br>-    for(y = 0; y < vga_mode.vactive - FONT_HEIGHT; y++) {<br>+     for(y = 0; y < vga_mode.vactive - font_height(); y++) {<br>            memcpy(dst, src, vga_mode.hactive);<br> <br>                dst += vga_mode.hactive;<br>@@ -236,24 +236,22 @@<br> static void geodelx_putc(u8 row, u8 col, unsigned int ch)<br> {<br>       unsigned char *dst;<br>-  unsigned char *glyph = font8x16 + ((ch & 0xFF) * FONT_HEIGHT);<br> <br>         unsigned char bg = (ch >> 12) & 0xF;<br>        unsigned char fg = (ch >> 8) & 0xF;<br> <br>      int x, y;<br> <br>- dst = FB + ((row * FONT_HEIGHT) * vga_mode.hactive);<br>- dst += (col * FONT_WIDTH);<br>+   dst = FB + ((row * font_height()) * vga_mode.hactive);<br>+       dst += (col * font_width());<br> <br>-      for(y = 0; y < FONT_HEIGHT; y++) {<br>+        for(y = 0; y < font_height(); y++) {<br> <br>-           for(x = FONT_WIDTH - 1; x >= 0; x--)<br>-                      dst[FONT_WIDTH - x] = (*glyph & (1 << x)) ?<br>+                for(x = font_width() - 1; x >= 0; x--)<br>+                    dst[font_width() - x] = font_glyph_filled(ch, x, y) ?<br>                                 fg : bg;<br> <br>           dst += vga_mode.hactive;<br>-             glyph++;<br>      }<br> }<br> <br>@@ -270,6 +268,8 @@<br>         dcaddr = pci_read_resource(dev, 2);<br>   vgaddr = pci_read_resource(dev, 3);<br> <br>+       font_init();<br>+<br>       init_video_mode();<br> <br>         /* Set up the palette */<br></pre><p>To view, visit <a href="https://review.coreboot.org/20708">change 20708</a>. To unsubscribe, visit <a href="https://review.coreboot.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://review.coreboot.org/20708"/><meta itemprop="name" content="View Change"/></div></div>

<div style="display:none"> Gerrit-Project: coreboot </div>
<div style="display:none"> Gerrit-Branch: master </div>
<div style="display:none"> Gerrit-MessageType: newchange </div>
<div style="display:none"> Gerrit-Change-Id: I0277984ec01f49dc51bfc8237ef806f13e3547e2 </div>
<div style="display:none"> Gerrit-Change-Number: 20708 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: Paul Kocialkowski <contact@paulk.fr> </div>