diff mbox series

[v2,07/17] hw/loongarch: Init efi_initrd table

Message ID 20231218090059.2678224-8-gaosong@loongson.cn
State New
Headers show
Series Add boot LoongArch elf kernel with FDT | expand

Commit Message

Song Gao Dec. 18, 2023, 9 a.m. UTC
Signed-off-by: Song Gao <gaosong@loongson.cn>
---
 hw/loongarch/boot.c         | 29 +++++++++++++++++++++++++++--
 include/hw/loongarch/boot.h |  9 +++++++++
 2 files changed, 36 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/hw/loongarch/boot.c b/hw/loongarch/boot.c
index 5d963176bd..1600ae6e55 100644
--- a/hw/loongarch/boot.c
+++ b/hw/loongarch/boot.c
@@ -14,11 +14,15 @@ 
 #include "qemu/error-report.h"
 #include "sysemu/reset.h"
 
+ram_addr_t initrd_offset;
+uint64_t initrd_size;
+
 enum {
     SLAVE_BOOT,
     EFI_SYSTAB,
     EFI_TABLES,
     EFI_MEMMAP,
+    EFI_INITRD,
 };
 
 static const MemMapEntry loader_rommap[] = {
@@ -26,6 +30,7 @@  static const MemMapEntry loader_rommap[] = {
     [EFI_SYSTAB] = {0xf200000, 0x10000},
     [EFI_TABLES] = {0xf300000, 0x10000},
     [EFI_MEMMAP] = {0xf400000, 0x10000},
+    [EFI_INITRD] = {0xf500000, 0x10000},
 };
 
 static unsigned int slave_boot_code[] = {
@@ -117,6 +122,26 @@  static void init_efi_boot_memmap(struct efi_system_table *systab)
     g_free(boot_memmap);
 }
 
+static void init_efi_initrd_table(struct efi_system_table *systab)
+{
+    efi_guid_t tbl_guid = LINUX_EFI_INITRD_MEDIA_GUID;
+    struct efi_initrd *initrd_table  = g_malloc0(loader_rommap[EFI_INITRD].size);
+
+    initrd_table->base = initrd_offset;
+    initrd_table->size = initrd_size;
+
+    rom_add_blob_fixed("initrd_tbl_rom", initrd_table,
+                       loader_rommap[EFI_INITRD].size,
+                       loader_rommap[EFI_INITRD].base);
+
+    /* efi_configuration_table 2 */
+    guidcpy(&systab->tables[1].guid, &tbl_guid);
+    systab->tables[1].table = (void *)loader_rommap[EFI_INITRD].base;
+    systab->nr_tables = 2;
+
+    g_free(initrd_table);
+}
+
 static void init_systab(struct loongarch_boot_info *info)
 {
     struct efi_system_table *systab;
@@ -134,6 +159,7 @@  static void init_systab(struct loongarch_boot_info *info)
     systab->tables = efi_tables;
 
     init_efi_boot_memmap(systab);
+    init_efi_initrd_table(systab);
 
     rom_add_blob_fixed("tables_rom", efi_tables,
                        loader_rommap[EFI_TABLES].size,
@@ -173,8 +199,7 @@  static uint64_t cpu_loongarch_virt_to_phys(void *opaque, uint64_t addr)
 
 static int64_t load_kernel_info(struct loongarch_boot_info *info)
 {
-    uint64_t kernel_entry, kernel_low, kernel_high, initrd_size;
-    ram_addr_t initrd_offset;
+    uint64_t kernel_entry, kernel_low, kernel_high;
     ssize_t kernel_size;
 
     kernel_size = load_elf(info->kernel_filename, NULL,
diff --git a/include/hw/loongarch/boot.h b/include/hw/loongarch/boot.h
index bef9ab659e..e482b829f7 100644
--- a/include/hw/loongarch/boot.h
+++ b/include/hw/loongarch/boot.h
@@ -32,6 +32,10 @@  typedef struct {
         EFI_GUID(0x800f683f, 0xd08b, 0x423a,  0xa2, 0x93, \
                  0x96, 0x5c, 0x3c, 0x6f, 0xe2, 0xb4)
 
+#define LINUX_EFI_INITRD_MEDIA_GUID \
+        EFI_GUID(0x5568e427, 0x68fc, 0x4f3d,  0xac, 0x74, \
+                 0xca, 0x55, 0x52, 0x31, 0xcc, 0x68)
+
 struct efi_config_table {
     efi_guid_t guid;
     uint64_t *ptr;
@@ -85,6 +89,11 @@  struct efi_boot_memmap {
     efi_memory_desc_t map[32];
 };
 
+struct efi_initrd {
+    uint64_t base;
+    uint64_t size;
+};
+
 struct loongarch_boot_info {
     uint64_t ram_size;
     const char *kernel_filename;