coreboot: Split parts that are platform-independent.
authorVladimir Serbinenko <phcoder@gmail.com>
Mon, 8 May 2017 17:06:22 +0000 (19:06 +0200)
committerVladimir Serbinenko <phcoder@gmail.com>
Mon, 8 May 2017 17:10:24 +0000 (19:10 +0200)
We currently assume that coreboot is always i386, it's no longer the case,
so split i386-coreboot parts from generic coreboot code.

grub-core/Makefile.am
grub-core/Makefile.core.def
grub-core/commands/i386/coreboot/cb_timestamps.c
grub-core/commands/i386/coreboot/cbls.c
grub-core/kern/coreboot/cbtable.c [new file with mode: 0644]
grub-core/kern/coreboot/mmap.c [moved from grub-core/kern/i386/coreboot/mmap.c with 97% similarity]
grub-core/kern/i386/coreboot/cbtable.c
grub-core/term/i386/coreboot/cbmemc.c
grub-core/video/coreboot/cbfb.c [moved from grub-core/video/i386/coreboot/cbfb.c with 99% similarity]
include/grub/coreboot/lbio.h [moved from include/grub/i386/coreboot/lbio.h with 93% similarity]

index 809a8aa..781d0ff 100644 (file)
@@ -112,7 +112,7 @@ endif
 
 if COND_i386_coreboot
 KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/i386/tsc.h
-KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/i386/coreboot/lbio.h
+KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/coreboot/lbio.h
 KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/video.h
 KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/video_fb.h
 KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/gfxterm.h
index fb59a7b..45ed0fa 100644 (file)
@@ -166,7 +166,7 @@ kernel = {
   i386_multiboot = kern/i386/coreboot/init.c;
   i386_qemu = kern/i386/qemu/init.c;
   i386_coreboot_multiboot_qemu = term/i386/pc/vga_text.c;
-  i386_coreboot = video/i386/coreboot/cbfb.c;
+  i386_coreboot = video/coreboot/cbfb.c;
 
   efi = disk/efi/efidisk.c;
   efi = kern/efi/efi.c;
@@ -227,8 +227,9 @@ kernel = {
   i386_qemu = kern/vga_init.c;
   i386_qemu = kern/i386/qemu/mmap.c;
 
-  i386_coreboot = kern/i386/coreboot/mmap.c;
+  i386_coreboot = kern/coreboot/mmap.c;
   i386_coreboot = kern/i386/coreboot/cbtable.c;
+  i386_coreboot = kern/coreboot/cbtable.c;
 
   i386_multiboot = kern/i386/multiboot_mmap.c;
 
@@ -643,6 +644,7 @@ module = {
 module = {
   name = cbtable;
   common = kern/i386/coreboot/cbtable.c;
+  common = kern/coreboot/cbtable.c;
   enable = i386_pc;
   enable = i386_efi;
   enable = i386_qemu;
index e72f38d..e97ea6b 100644 (file)
@@ -20,7 +20,7 @@
 #include <grub/misc.h>
 #include <grub/command.h>
 #include <grub/i18n.h>
-#include <grub/i386/coreboot/lbio.h>
+#include <grub/coreboot/lbio.h>
 #include <grub/i386/tsc.h>
 
 GRUB_MOD_LICENSE ("GPLv3+");
index e0a1059..102291f 100644 (file)
@@ -20,7 +20,7 @@
 #include <grub/misc.h>
 #include <grub/command.h>
 #include <grub/i18n.h>
-#include <grub/i386/coreboot/lbio.h>
+#include <grub/coreboot/lbio.h>
 #include <grub/i386/tsc.h>
 
 GRUB_MOD_LICENSE ("GPLv3+");
diff --git a/grub-core/kern/coreboot/cbtable.c b/grub-core/kern/coreboot/cbtable.c
new file mode 100644 (file)
index 0000000..996d3f4
--- /dev/null
@@ -0,0 +1,70 @@
+/*
+ *  GRUB  --  GRand Unified Bootloader
+ *  Copyright (C) 2007,2008,2013  Free Software Foundation, Inc.
+ *
+ *  GRUB is free software: you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation, either version 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  GRUB is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with GRUB.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <grub/i386/coreboot/memory.h>
+#include <grub/coreboot/lbio.h>
+#include <grub/types.h>
+#include <grub/err.h>
+#include <grub/misc.h>
+#include <grub/dl.h>
+
+/* Helper for grub_linuxbios_table_iterate.  */
+int
+grub_linuxbios_check_signature (grub_linuxbios_table_header_t tbl_header)
+{
+  if (! grub_memcmp (tbl_header->signature, "LBIO", 4))
+    return 1;
+
+  return 0;
+}
+
+grub_err_t
+grub_linuxbios_table_iterate (int (*hook) (grub_linuxbios_table_item_t,
+                                          void *),
+                             void *hook_data)
+{
+  grub_linuxbios_table_header_t table_header = grub_linuxbios_get_tables ();
+  grub_linuxbios_table_item_t table_item;
+
+  if (!table_header)
+    return 0;
+
+signature_found:
+
+  table_item =
+    (grub_linuxbios_table_item_t) ((char *) table_header +
+                                  table_header->header_size);
+  for (; table_item < (grub_linuxbios_table_item_t) ((char *) table_header
+                                                    + table_header->header_size
+                                                    + table_header->table_size);
+       table_item = (grub_linuxbios_table_item_t) ((char *) table_item + table_item->size))
+    {
+      if (table_item->tag == GRUB_LINUXBIOS_MEMBER_LINK
+         && grub_linuxbios_check_signature ((grub_linuxbios_table_header_t) (grub_addr_t)
+                             *(grub_uint64_t *) (table_item + 1)))
+       {
+         table_header = (grub_linuxbios_table_header_t) (grub_addr_t)
+           *(grub_uint64_t *) (table_item + 1);
+         goto signature_found;   
+       }
+      if (hook (table_item, hook_data))
+       return 1;
+    }
+
+  return 0;
+}
similarity index 97%
rename from grub-core/kern/i386/coreboot/mmap.c
rename to grub-core/kern/coreboot/mmap.c
index 4d29f6b..caf8f7c 100644 (file)
@@ -16,8 +16,8 @@
  *  along with GRUB.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-#include <grub/machine/memory.h>
-#include <grub/machine/lbio.h>
+#include <grub/memory.h>
+#include <grub/coreboot/lbio.h>
 #include <grub/types.h>
 #include <grub/err.h>
 #include <grub/misc.h>
@@ -49,6 +49,7 @@ iterate_linuxbios_table (grub_linuxbios_table_item_t table_item, void *data)
     {
       grub_uint64_t start = mem_region->addr;
       grub_uint64_t end = mem_region->addr + mem_region->size;
+#ifdef __i386__
       /* Mark region 0xa0000 - 0x100000 as reserved.  */
       if (start < 0x100000 && end >= 0xa0000
          && mem_region->type == GRUB_MACHINE_MEMORY_AVAILABLE)
@@ -75,6 +76,7 @@ iterate_linuxbios_table (grub_linuxbios_table_item_t table_item, void *data)
          if (end <= start)
            continue;
        }
+#endif
       if (ctx->hook (start, end - start,
                     /* Multiboot mmaps match with the coreboot mmap
                        definition.  Therefore, we can just pass type
index 1669bc0..34a2b59 100644 (file)
@@ -17,7 +17,7 @@
  */
 
 #include <grub/i386/coreboot/memory.h>
-#include <grub/i386/coreboot/lbio.h>
+#include <grub/coreboot/lbio.h>
 #include <grub/types.h>
 #include <grub/err.h>
 #include <grub/misc.h>
 
 GRUB_MOD_LICENSE ("GPLv3+");
 
-/* Helper for grub_linuxbios_table_iterate.  */
-static int
-check_signature (grub_linuxbios_table_header_t tbl_header)
-{
-  if (! grub_memcmp (tbl_header->signature, "LBIO", 4))
-    return 1;
-
-  return 0;
-}
-
-grub_err_t
-grub_linuxbios_table_iterate (int (*hook) (grub_linuxbios_table_item_t,
-                                          void *),
-                             void *hook_data)
+grub_linuxbios_table_header_t
+grub_linuxbios_get_tables (void)
 {
   grub_linuxbios_table_header_t table_header;
-  grub_linuxbios_table_item_t table_item;
-
   /* Assuming table_header is aligned to its size (8 bytes).  */
-
   for (table_header = (grub_linuxbios_table_header_t) 0x500;
        table_header < (grub_linuxbios_table_header_t) 0x1000; table_header++)
-    if (check_signature (table_header))
-      goto signature_found;
+    if (grub_linuxbios_check_signature (table_header))
+      return table_header;
 
   for (table_header = (grub_linuxbios_table_header_t) 0xf0000;
        table_header < (grub_linuxbios_table_header_t) 0x100000; table_header++)
-    if (check_signature (table_header))
-      goto signature_found;
-
-  return 0;
-
-signature_found:
-
-  table_item =
-    (grub_linuxbios_table_item_t) ((char *) table_header +
-                                  table_header->header_size);
-  for (; table_item < (grub_linuxbios_table_item_t) ((char *) table_header
-                                                    + table_header->header_size
-                                                    + table_header->table_size);
-       table_item = (grub_linuxbios_table_item_t) ((char *) table_item + table_item->size))
-    {
-      if (table_item->tag == GRUB_LINUXBIOS_MEMBER_LINK
-         && check_signature ((grub_linuxbios_table_header_t) (grub_addr_t)
-                             *(grub_uint64_t *) (table_item + 1)))
-       {
-         table_header = (grub_linuxbios_table_header_t) (grub_addr_t)
-           *(grub_uint64_t *) (table_item + 1);
-         goto signature_found;   
-       }
-      if (hook (table_item, hook_data))
-       return 1;
-    }
+    if (grub_linuxbios_check_signature (table_header))
+      return table_header;
 
   return 0;
 }
index 25e64a0..129248c 100644 (file)
@@ -23,7 +23,7 @@
 #include <grub/time.h>
 #include <grub/terminfo.h>
 #include <grub/dl.h>
-#include <grub/i386/coreboot/lbio.h>
+#include <grub/coreboot/lbio.h>
 #include <grub/command.h>
 #include <grub/normal.h>
 
similarity index 99%
rename from grub-core/video/i386/coreboot/cbfb.c
rename to grub-core/video/coreboot/cbfb.c
index dede0c3..9af81fa 100644 (file)
@@ -25,7 +25,7 @@
 #include <grub/mm.h>
 #include <grub/video.h>
 #include <grub/video_fb.h>
-#include <grub/machine/lbio.h>
+#include <grub/coreboot/lbio.h>
 #include <grub/machine/console.h>
 
 struct grub_linuxbios_table_framebuffer *grub_video_coreboot_fbtable;
similarity index 93%
rename from include/grub/i386/coreboot/lbio.h
rename to include/grub/coreboot/lbio.h
index 1c3fa6f..5076d36 100644 (file)
@@ -20,6 +20,9 @@
 #ifndef _GRUB_MACHINE_LBIO_HEADER
 #define _GRUB_MACHINE_LBIO_HEADER      1
 
+#include <grub/types.h>
+#include <grub/err.h>
+
 struct grub_linuxbios_table_header
 {
   grub_uint8_t signature[4];
@@ -102,4 +105,10 @@ EXPORT_FUNC(grub_linuxbios_table_iterate) (int (*hook) (grub_linuxbios_table_ite
                                           void *),
                                           void *hook_data);
 
+grub_linuxbios_table_header_t
+grub_linuxbios_get_tables (void);
+
+int
+grub_linuxbios_check_signature (grub_linuxbios_table_header_t tbl_header);
+
 #endif