Blame SOURCES/0333-Support-coreboot-framebuffer.patch

f96e0b
From f387540a52ff93c10fca1e765adaeb829c44e688 Mon Sep 17 00:00:00 2001
f96e0b
From: Vladimir 'phcoder' Serbinenko <phcoder@gmail.com>
f96e0b
Date: Sun, 21 Apr 2013 13:02:10 +0200
f96e0b
Subject: [PATCH 333/482] 	Support coreboot framebuffer.
f96e0b
f96e0b
	* grub-core/video/i386/coreboot/cbfb.c: New file.
f96e0b
---
f96e0b
 ChangeLog                               |   6 ++
f96e0b
 grub-core/Makefile.core.def             |   6 ++
f96e0b
 grub-core/commands/i386/coreboot/cbls.c |  16 ++-
f96e0b
 grub-core/video/i386/coreboot/cbfb.c    | 180 ++++++++++++++++++++++++++++++++
f96e0b
 include/grub/i386/coreboot/lbio.h       |  36 +++++--
f96e0b
 5 files changed, 236 insertions(+), 8 deletions(-)
f96e0b
 create mode 100644 grub-core/video/i386/coreboot/cbfb.c
f96e0b
f96e0b
diff --git a/ChangeLog b/ChangeLog
f96e0b
index 2a4264c..6be583e 100644
f96e0b
--- a/ChangeLog
f96e0b
+++ b/ChangeLog
f96e0b
@@ -1,3 +1,9 @@
f96e0b
+2013-04-21  Vladimir Serbinenko  <phcoder@gmail.com>
f96e0b
+
f96e0b
+	Support coreboot framebuffer.
f96e0b
+
f96e0b
+	* grub-core/video/i386/coreboot/cbfb.c: New file.
f96e0b
+
f96e0b
 2013-04-20  Vladimir Serbinenko  <phcoder@gmail.com>
f96e0b
 
f96e0b
 	* grub-core/kern/mm.c (grub_mm_init_region): Fix condition for
f96e0b
diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def
f96e0b
index 1f04afb..7269609 100644
f96e0b
--- a/grub-core/Makefile.core.def
f96e0b
+++ b/grub-core/Makefile.core.def
f96e0b
@@ -1797,6 +1797,12 @@ module = {
f96e0b
 };
f96e0b
 
f96e0b
 module = {
f96e0b
+  name = coreboot_fb;
f96e0b
+  common = video/i386/coreboot/cbfb.c;
f96e0b
+  enable = i386_coreboot;
f96e0b
+};
f96e0b
+
f96e0b
+module = {
f96e0b
   name = sdl;
f96e0b
   emu = video/emu/sdl.c;
f96e0b
   enable = emu;
f96e0b
diff --git a/grub-core/commands/i386/coreboot/cbls.c b/grub-core/commands/i386/coreboot/cbls.c
f96e0b
index 151f9e8..a3542f3 100644
f96e0b
--- a/grub-core/commands/i386/coreboot/cbls.c
f96e0b
+++ b/grub-core/commands/i386/coreboot/cbls.c
f96e0b
@@ -50,7 +50,7 @@ static const char *descs[] = {
f96e0b
   [0xd] = "assembler",
f96e0b
   [0xf] = "serial",
f96e0b
   [GRUB_LINUXBIOS_MEMBER_CONSOLE] = "console",
f96e0b
-  [0x12] = "framebuffer",
f96e0b
+  [GRUB_LINUXBIOS_MEMBER_FRAMEBUFFER] = "framebuffer",
f96e0b
   [0x13] = "GPIO",
f96e0b
   [0x15] = "VDAT",
f96e0b
   [GRUB_LINUXBIOS_MEMBER_TIMESTAMPS] = "timestamps (`coreboot_boottime' to list)",
f96e0b
@@ -77,6 +77,20 @@ iterate_linuxbios_table (grub_linuxbios_table_item_t table_item,
f96e0b
 
f96e0b
   switch (table_item->tag)
f96e0b
     {
f96e0b
+    case GRUB_LINUXBIOS_MEMBER_FRAMEBUFFER:
f96e0b
+      {
f96e0b
+	struct grub_linuxbios_table_framebuffer *fb;
f96e0b
+	fb = (struct grub_linuxbios_table_framebuffer *) (table_item + 1);
f96e0b
+
f96e0b
+	grub_printf (": %dx%dx%d pitch=%d lfb=0x%llx %d/%d/%d/%d %d/%d/%d/%d",
f96e0b
+		     fb->width, fb->height,
f96e0b
+		     fb->bpp, fb->pitch, fb->lfb,
f96e0b
+		     fb->red_mask_size, fb->green_mask_size,
f96e0b
+		     fb->blue_mask_size, fb->reserved_mask_size,
f96e0b
+		     fb->red_field_pos, fb->green_field_pos,
f96e0b
+		     fb->blue_field_pos, fb->reserved_field_pos);
f96e0b
+	break;
f96e0b
+      }
f96e0b
     case GRUB_LINUXBIOS_MEMBER_MAINBOARD:
f96e0b
       {
f96e0b
 	struct grub_linuxbios_mainboard *mb;
f96e0b
diff --git a/grub-core/video/i386/coreboot/cbfb.c b/grub-core/video/i386/coreboot/cbfb.c
f96e0b
new file mode 100644
f96e0b
index 0000000..000efdb
f96e0b
--- /dev/null
f96e0b
+++ b/grub-core/video/i386/coreboot/cbfb.c
f96e0b
@@ -0,0 +1,180 @@
f96e0b
+/*
f96e0b
+ *  GRUB  --  GRand Unified Bootloader
f96e0b
+ *  Copyright (C) 2005,2006,2007,2008,2009  Free Software Foundation, Inc.
f96e0b
+ *
f96e0b
+ *  GRUB is free software: you can redistribute it and/or modify
f96e0b
+ *  it under the terms of the GNU General Public License as published by
f96e0b
+ *  the Free Software Foundation, either version 3 of the License, or
f96e0b
+ *  (at your option) any later version.
f96e0b
+ *
f96e0b
+ *  GRUB is distributed in the hope that it will be useful,
f96e0b
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
f96e0b
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
f96e0b
+ *  GNU General Public License for more details.
f96e0b
+ *
f96e0b
+ *  You should have received a copy of the GNU General Public License
f96e0b
+ *  along with GRUB.  If not, see <http://www.gnu.org/licenses/>.
f96e0b
+ */
f96e0b
+
f96e0b
+#define grub_video_render_target grub_video_fbrender_target
f96e0b
+
f96e0b
+#include <grub/err.h>
f96e0b
+#include <grub/types.h>
f96e0b
+#include <grub/dl.h>
f96e0b
+#include <grub/misc.h>
f96e0b
+#include <grub/mm.h>
f96e0b
+#include <grub/video.h>
f96e0b
+#include <grub/video_fb.h>
f96e0b
+#include <grub/machine/lbio.h>
f96e0b
+
f96e0b
+GRUB_MOD_LICENSE ("GPLv3+");
f96e0b
+
f96e0b
+static struct grub_linuxbios_table_framebuffer *cbfb;
f96e0b
+
f96e0b
+static struct
f96e0b
+{
f96e0b
+  struct grub_video_mode_info mode_info;
f96e0b
+  grub_uint8_t *ptr;
f96e0b
+} framebuffer;
f96e0b
+
f96e0b
+static grub_err_t
f96e0b
+grub_video_cbfb_init (void)
f96e0b
+{
f96e0b
+  grub_memset (&framebuffer, 0, sizeof(framebuffer));
f96e0b
+
f96e0b
+  return grub_video_fb_init ();
f96e0b
+}
f96e0b
+
f96e0b
+static grub_err_t
f96e0b
+grub_video_cbfb_fill_mode_info (struct grub_video_mode_info *out)
f96e0b
+{
f96e0b
+  grub_memset (out, 0, sizeof (*out));
f96e0b
+
f96e0b
+  out->width = cbfb->width;
f96e0b
+  out->height = cbfb->height;
f96e0b
+  out->pitch = cbfb->pitch;
f96e0b
+
f96e0b
+  out->red_field_pos = cbfb->red_field_pos;
f96e0b
+  out->red_mask_size = cbfb->red_mask_size;
f96e0b
+  out->green_field_pos = cbfb->green_field_pos;
f96e0b
+  out->green_mask_size = cbfb->green_mask_size;
f96e0b
+  out->blue_field_pos = cbfb->blue_field_pos;
f96e0b
+  out->blue_mask_size = cbfb->blue_mask_size;
f96e0b
+  out->reserved_field_pos = cbfb->reserved_field_pos;
f96e0b
+  out->reserved_mask_size = cbfb->reserved_mask_size;
f96e0b
+
f96e0b
+  out->mode_type = GRUB_VIDEO_MODE_TYPE_RGB;
f96e0b
+  out->bpp = cbfb->bpp;
f96e0b
+  out->bytes_per_pixel = (cbfb->bpp + 7) / 8;
f96e0b
+  out->number_of_colors = 256;
f96e0b
+
f96e0b
+  out->blit_format = grub_video_get_blit_format (out);
f96e0b
+  return GRUB_ERR_NONE;
f96e0b
+}
f96e0b
+
f96e0b
+static grub_err_t
f96e0b
+grub_video_cbfb_setup (unsigned int width, unsigned int height,
f96e0b
+			   unsigned int mode_type __attribute__ ((unused)),
f96e0b
+			   unsigned int mode_mask __attribute__ ((unused)))
f96e0b
+{
f96e0b
+  grub_err_t err;
f96e0b
+
f96e0b
+  if (!cbfb)
f96e0b
+    return grub_error (GRUB_ERR_IO, "Couldn't find display device.");
f96e0b
+
f96e0b
+  if (!((width == cbfb->width && height == cbfb->height)
f96e0b
+	|| (width == 0 && height == 0)))
f96e0b
+    return grub_error (GRUB_ERR_IO, "can't set mode %dx%d", width, height);
f96e0b
+
f96e0b
+  err = grub_video_cbfb_fill_mode_info (&framebuffer.mode_info);
f96e0b
+  if (err)
f96e0b
+    {
f96e0b
+      grub_dprintf ("video", "CBFB: couldn't fill mode info\n");
f96e0b
+      return err;
f96e0b
+    }
f96e0b
+
f96e0b
+  framebuffer.ptr = (void *) (grub_addr_t) cbfb->lfb;
f96e0b
+
f96e0b
+  grub_dprintf ("video", "CBFB: initialising FB @ %p %dx%dx%d\n",
f96e0b
+		framebuffer.ptr, framebuffer.mode_info.width,
f96e0b
+		framebuffer.mode_info.height, framebuffer.mode_info.bpp);
f96e0b
+
f96e0b
+  err = grub_video_fb_setup (mode_type, mode_mask,
f96e0b
+			     &framebuffer.mode_info,
f96e0b
+			     framebuffer.ptr, NULL, NULL);
f96e0b
+  if (err)
f96e0b
+    return err;
f96e0b
+
f96e0b
+  grub_video_fb_set_palette (0, GRUB_VIDEO_FBSTD_NUMCOLORS,
f96e0b
+			     grub_video_fbstd_colors);
f96e0b
+    
f96e0b
+  return err;
f96e0b
+}
f96e0b
+
f96e0b
+static grub_err_t
f96e0b
+grub_video_cbfb_get_info_and_fini (struct grub_video_mode_info *mode_info,
f96e0b
+				  void **framebuf)
f96e0b
+{
f96e0b
+  grub_memcpy (mode_info, &(framebuffer.mode_info), sizeof (*mode_info));
f96e0b
+  *framebuf = (char *) framebuffer.ptr;
f96e0b
+
f96e0b
+  grub_video_fb_fini ();
f96e0b
+
f96e0b
+  return GRUB_ERR_NONE;
f96e0b
+}
f96e0b
+
f96e0b
+static struct grub_video_adapter grub_video_cbfb_adapter =
f96e0b
+  {
f96e0b
+    .name = "Coreboot video driver",
f96e0b
+
f96e0b
+    .prio = GRUB_VIDEO_ADAPTER_PRIO_FIRMWARE_DIRTY,
f96e0b
+
f96e0b
+    .init = grub_video_cbfb_init,
f96e0b
+    .fini = grub_video_fb_fini,
f96e0b
+    .setup = grub_video_cbfb_setup,
f96e0b
+    .get_info = grub_video_fb_get_info,
f96e0b
+    .get_info_and_fini = grub_video_cbfb_get_info_and_fini,
f96e0b
+    .set_palette = grub_video_fb_set_palette,
f96e0b
+    .get_palette = grub_video_fb_get_palette,
f96e0b
+    .set_viewport = grub_video_fb_set_viewport,
f96e0b
+    .get_viewport = grub_video_fb_get_viewport,
f96e0b
+    .map_color = grub_video_fb_map_color,
f96e0b
+    .map_rgb = grub_video_fb_map_rgb,
f96e0b
+    .map_rgba = grub_video_fb_map_rgba,
f96e0b
+    .unmap_color = grub_video_fb_unmap_color,
f96e0b
+    .fill_rect = grub_video_fb_fill_rect,
f96e0b
+    .blit_bitmap = grub_video_fb_blit_bitmap,
f96e0b
+    .blit_render_target = grub_video_fb_blit_render_target,
f96e0b
+    .scroll = grub_video_fb_scroll,
f96e0b
+    .swap_buffers = grub_video_fb_swap_buffers,
f96e0b
+    .create_render_target = grub_video_fb_create_render_target,
f96e0b
+    .delete_render_target = grub_video_fb_delete_render_target,
f96e0b
+    .set_active_render_target = grub_video_fb_set_active_render_target,
f96e0b
+    .get_active_render_target = grub_video_fb_get_active_render_target,
f96e0b
+
f96e0b
+    .next = 0
f96e0b
+  };
f96e0b
+
f96e0b
+static int
f96e0b
+iterate_linuxbios_table (grub_linuxbios_table_item_t table_item,
f96e0b
+			 void *data __attribute__ ((unused)))
f96e0b
+{
f96e0b
+  if (table_item->tag != GRUB_LINUXBIOS_MEMBER_FRAMEBUFFER)
f96e0b
+    return 0;
f96e0b
+  cbfb = (struct grub_linuxbios_table_framebuffer *) (table_item + 1);
f96e0b
+  return 1;
f96e0b
+}
f96e0b
+
f96e0b
+GRUB_MOD_INIT(coreboot_fb)
f96e0b
+{
f96e0b
+  grub_linuxbios_table_iterate (iterate_linuxbios_table, 0);
f96e0b
+
f96e0b
+  if (cbfb)
f96e0b
+    grub_video_register (&grub_video_cbfb_adapter);
f96e0b
+}
f96e0b
+
f96e0b
+GRUB_MOD_FINI(coreboot_fb)
f96e0b
+{
f96e0b
+  if (cbfb)
f96e0b
+    grub_video_unregister (&grub_video_cbfb_adapter);
f96e0b
+}
f96e0b
diff --git a/include/grub/i386/coreboot/lbio.h b/include/grub/i386/coreboot/lbio.h
f96e0b
index b4150f4..9a93046 100644
f96e0b
--- a/include/grub/i386/coreboot/lbio.h
f96e0b
+++ b/include/grub/i386/coreboot/lbio.h
f96e0b
@@ -54,18 +54,40 @@ struct grub_linuxbios_mainboard
f96e0b
 
f96e0b
 struct grub_linuxbios_table_item
f96e0b
 {
f96e0b
-#define GRUB_LINUXBIOS_MEMBER_UNUSED		0x00
f96e0b
-#define GRUB_LINUXBIOS_MEMBER_MEMORY		0x01
f96e0b
-#define GRUB_LINUXBIOS_MEMBER_MAINBOARD		0x03
f96e0b
-#define GRUB_LINUXBIOS_MEMBER_CONSOLE           0x10
f96e0b
-#define GRUB_LINUXBIOS_MEMBER_LINK              0x11
f96e0b
-#define GRUB_LINUXBIOS_MEMBER_TIMESTAMPS        0x16
f96e0b
-#define GRUB_LINUXBIOS_MEMBER_CBMEMC            0x17
f96e0b
   grub_uint32_t tag;
f96e0b
   grub_uint32_t size;
f96e0b
 };
f96e0b
 typedef struct grub_linuxbios_table_item *grub_linuxbios_table_item_t;
f96e0b
 
f96e0b
+enum
f96e0b
+  {
f96e0b
+    GRUB_LINUXBIOS_MEMBER_UNUSED      = 0x00,
f96e0b
+    GRUB_LINUXBIOS_MEMBER_MEMORY      = 0x01,
f96e0b
+    GRUB_LINUXBIOS_MEMBER_MAINBOARD   = 0x03,
f96e0b
+    GRUB_LINUXBIOS_MEMBER_CONSOLE     = 0x10,
f96e0b
+    GRUB_LINUXBIOS_MEMBER_LINK        = 0x11,
f96e0b
+    GRUB_LINUXBIOS_MEMBER_FRAMEBUFFER = 0x12,
f96e0b
+    GRUB_LINUXBIOS_MEMBER_TIMESTAMPS  = 0x16,
f96e0b
+    GRUB_LINUXBIOS_MEMBER_CBMEMC      = 0x17
f96e0b
+  };
f96e0b
+
f96e0b
+struct grub_linuxbios_table_framebuffer {
f96e0b
+  grub_uint64_t lfb;
f96e0b
+  grub_uint32_t width;
f96e0b
+  grub_uint32_t height;
f96e0b
+  grub_uint32_t pitch;
f96e0b
+  grub_uint8_t bpp;
f96e0b
+
f96e0b
+  grub_uint8_t red_field_pos;
f96e0b
+  grub_uint8_t red_mask_size;
f96e0b
+  grub_uint8_t green_field_pos;
f96e0b
+  grub_uint8_t green_mask_size;
f96e0b
+  grub_uint8_t blue_field_pos;
f96e0b
+  grub_uint8_t blue_mask_size;
f96e0b
+  grub_uint8_t reserved_field_pos;
f96e0b
+  grub_uint8_t reserved_mask_size;
f96e0b
+};
f96e0b
+
f96e0b
 struct grub_linuxbios_mem_region
f96e0b
 {
f96e0b
   grub_uint64_t addr;
f96e0b
-- 
f96e0b
1.8.2.1
f96e0b