summaryrefslogtreecommitdiffstats
path: root/src/drivers/pc80
diff options
context:
space:
mode:
authorSubrata Banik <subratabanik@google.com>2022-12-26 21:39:59 +0530
committerSubrata Banik <subratabanik@google.com>2023-01-02 05:45:23 +0000
commit3e3b78a391ad51a030957fc1cc062746821513ac (patch)
treefd7ca21d4a306c2d351a4b7fbc98c4e2aacda48c /src/drivers/pc80
parente51978f26fde2f400979ad28f35d497ff3b8ad76 (diff)
downloadcoreboot-3e3b78a391ad51a030957fc1cc062746821513ac.tar.gz
coreboot-3e3b78a391ad51a030957fc1cc062746821513ac.tar.bz2
coreboot-3e3b78a391ad51a030957fc1cc062746821513ac.zip
drivers/pc80/vga: Add API to write multi-line video message
This patch provides an API to allow users to output multi-line messages using VGA framebuffer. The current limitation with multiline message is that, vga_line_write() function is unable to understand newline character hence, eventually output multiple lines separated with a newline character with a single line statement. This patch ensures to parse the entire string and split it into multiple lines based on the newline character and print each line separately to the VFG framebuffer. User can choose to align the output video message as per given choice between left/center/right of the screen (i.e. enum VGA_TEXT_ALIGNMENT ). Additionally, added macros to define the horizontal screen alignment as well. Ideally if user would like to print the video message at the middle of the screen then the vertical alignment would be `VGA_TEXT_CENTER` and horizontal alignment would be `VGA_TEXT_HORIZONTAL_MIDDLE`. TEST=Able to build and boot Google/Taeko. While output a video message such as : "Your device is finishing an update. This may take 1-2 minutes.\nPlease do not turn off your device." Without this patch: Your device is finishing an update. This may take 1-2 minutes. nPlease do not turn off your device. With this patch: (in Left Alignment): Your device is finishing an update. This may take 1-2 minutes. Please do not turn off your device. (in Right Alignment): Your device is finishing an update. This may take 1-2 minutes. Please do not turn off your device. (in Center Alignment): Your device is finishing an update. This may take 1-2 minutes. Please do not turn off your device. Signed-off-by: Subrata Banik <subratabanik@google.com> Change-Id: Ib837e4deeba9b84038a91c93a68f03cee3474f9b Reviewed-on: https://review.coreboot.org/c/coreboot/+/71265 Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Tarun Tuli <taruntuli@google.com>
Diffstat (limited to 'src/drivers/pc80')
-rw-r--r--src/drivers/pc80/vga/vga.c46
1 files changed, 39 insertions, 7 deletions
diff --git a/src/drivers/pc80/vga/vga.c b/src/drivers/pc80/vga/vga.c
index 3471c944a11f..a52ba6dc1fb2 100644
--- a/src/drivers/pc80/vga/vga.c
+++ b/src/drivers/pc80/vga/vga.c
@@ -256,19 +256,16 @@ vga_frame_set(unsigned int line, unsigned int character)
vga_cr_write(0x0D, offset & 0xFF);
}
-/*
- * simply fills a line with the given string.
- */
-void
-vga_line_write(unsigned int line, const char *string)
+static void
+vga_write_at_offset(unsigned int line, unsigned int offset, const char *string)
{
if (!string)
return;
- unsigned short *p = (unsigned short *)VGA_FB + (VGA_COLUMNS * line);
+ unsigned short *p = (unsigned short *)VGA_FB + (VGA_COLUMNS * line) + offset;
size_t i, len = strlen(string);
- for (i = 0; i < VGA_COLUMNS; i++) {
+ for (i = 0; i < (VGA_COLUMNS - offset); i++) {
if (i < len)
p[i] = 0x0F00 | string[i];
else
@@ -277,6 +274,41 @@ vga_line_write(unsigned int line, const char *string)
}
/*
+ * simply fills a line with the given string.
+ */
+void
+vga_line_write(unsigned int line, const char *string)
+{
+ vga_write_at_offset(line, 0, string);
+}
+
+void
+vga_write_text(enum VGA_TEXT_ALIGNMENT alignment, unsigned int line, const char *string)
+{
+ char str[VGA_COLUMNS * VGA_LINES] = {0};
+ memcpy(str, string, strnlen(string, sizeof(str) - 1));
+
+ char *token = strtok(str, "\n");
+
+ while (token != NULL) {
+ size_t offset = VGA_COLUMNS - strnlen(token, VGA_COLUMNS);
+ switch (alignment) {
+ case VGA_TEXT_CENTER:
+ vga_write_at_offset(line++, offset/2, token);
+ break;
+ case VGA_TEXT_RIGHT:
+ vga_write_at_offset(line++, offset, token);
+ break;
+ case VGA_TEXT_LEFT:
+ default:
+ vga_write_at_offset(line++, 0, token);
+ break;
+ }
+ token = strtok(NULL, "\n");
+ }
+}
+
+/*
* set up everything to get a basic 80x25 textmode.
*/
void