| 1 | /* SPDX-License-Identifier: GPL-2.0-or-later */ |
| 2 | /* |
| 3 | * Definitions for LoongArch boot. |
| 4 | * |
| 5 | * Copyright (C) 2023 Loongson Technology Corporation Limited |
| 6 | */ |
| 7 | |
| 8 | #ifndef HW_LOONGARCH_BOOT_H |
| 9 | #define HW_LOONGARCH_BOOT_H |
| 10 | |
| 11 | /* UEFI 2.10 */ |
| 12 | #define EFI_SYSTEM_TABLE_SIGNATURE 0x5453595320494249 |
| 13 | #define EFI_2_100_SYSTEM_TABLE_REVISION ((2<<16) | (100)) |
| 14 | #define EFI_SPECIFICATION_VERSION EFI_SYSTEM_TABLE_REVISION |
| 15 | #define EFI_SYSTEM_TABLE_REVISION EFI_2_100_SYSTEM_TABLE_REVISION |
| 16 | |
| 17 | #define FW_VERSION 0x1 |
| 18 | #define FW_PATCHLEVEL 0x0 |
| 19 | |
| 20 | typedef struct { |
| 21 | uint8_t b[16]; |
| 22 | } efi_guid_t QEMU_ALIGNED(8); |
| 23 | |
| 24 | #define EFI_GUID(a, b, c, d...) (efi_guid_t){ { \ |
| 25 | (a) & 0xff, ((a) >> 8) & 0xff, ((a) >> 16) & 0xff, ((a) >> 24) & 0xff, \ |
| 26 | (b) & 0xff, ((b) >> 8) & 0xff, \ |
| 27 | (c) & 0xff, ((c) >> 8) & 0xff, d } } |
| 28 | |
| 29 | #define LINUX_EFI_BOOT_MEMMAP_GUID \ |
| 30 | EFI_GUID(0x800f683f, 0xd08b, 0x423a, 0xa2, 0x93, \ |
| 31 | 0x96, 0x5c, 0x3c, 0x6f, 0xe2, 0xb4) |
| 32 | |
| 33 | #define LINUX_EFI_INITRD_MEDIA_GUID \ |
| 34 | EFI_GUID(0x5568e427, 0x68fc, 0x4f3d, 0xac, 0x74, \ |
| 35 | 0xca, 0x55, 0x52, 0x31, 0xcc, 0x68) |
| 36 | |
| 37 | #define DEVICE_TREE_GUID \ |
| 38 | EFI_GUID(0xb1b621d5, 0xf19c, 0x41a5, 0x83, 0x0b, \ |
| 39 | 0xd9, 0x15, 0x2c, 0x69, 0xaa, 0xe0) |
| 40 | |
| 41 | struct efi_config_table { |
| 42 | efi_guid_t guid; |
| 43 | uint64_t *ptr; |
| 44 | const char name[16]; |
| 45 | }; |
| 46 | |
| 47 | typedef struct { |
| 48 | uint64_t signature; |
| 49 | uint32_t revision; |
| 50 | uint32_t headersize; |
| 51 | uint32_t crc32; |
| 52 | uint32_t reserved; |
| 53 | } efi_table_hdr_t; |
| 54 | |
| 55 | struct efi_configuration_table { |
| 56 | efi_guid_t guid; |
| 57 | void *table; |
| 58 | }; |
| 59 | |
| 60 | struct efi_system_table { |
| 61 | efi_table_hdr_t hdr; |
| 62 | uint64_t fw_vendor; /* physical addr of CHAR16 vendor string */ |
| 63 | uint32_t fw_revision; |
| 64 | uint64_t con_in_handle; |
| 65 | uint64_t *con_in; |
| 66 | uint64_t con_out_handle; |
| 67 | uint64_t *con_out; |
| 68 | uint64_t stderr_handle; |
| 69 | uint64_t stderr_placeholder; |
| 70 | uint64_t *runtime; |
| 71 | uint64_t *boottime; |
| 72 | uint64_t nr_tables; |
| 73 | struct efi_configuration_table *tables; |
| 74 | }; |
| 75 | |
| 76 | typedef struct { |
| 77 | uint32_t type; |
| 78 | uint32_t pad; |
| 79 | uint64_t phys_addr; |
| 80 | uint64_t virt_addr; |
| 81 | uint64_t num_pages; |
| 82 | uint64_t attribute; |
| 83 | } efi_memory_desc_t; |
| 84 | |
| 85 | struct efi_boot_memmap { |
| 86 | uint64_t map_size; |
| 87 | uint64_t desc_size; |
| 88 | uint32_t desc_ver; |
| 89 | uint64_t map_key; |
| 90 | uint64_t buff_size; |
| 91 | efi_memory_desc_t map[32]; |
| 92 | }; |
| 93 | |
| 94 | struct efi_initrd { |
| 95 | uint64_t base; |
| 96 | uint64_t size; |
| 97 | }; |
| 98 | |
| 99 | struct loongarch_boot_info { |
| 100 | uint64_t ram_size; |
| 101 | const char *kernel_filename; |
| 102 | const char *kernel_cmdline; |
| 103 | const char *initrd_filename; |
| 104 | uint64_t a0, a1, a2; |
| 105 | uint64_t initrd_addr; |
| 106 | uint64_t initrd_size; |
| 107 | }; |
| 108 | |
| 109 | struct memmap_entry { |
| 110 | uint64_t address; |
| 111 | uint64_t length; |
| 112 | uint32_t type; |
| 113 | uint32_t reserved; |
| 114 | }; |
| 115 | |
| 116 | void loongarch_load_kernel(MachineState *ms, struct loongarch_boot_info *info, |
| 117 | uint64_t phys_addr_mask); |
| 118 | |
| 119 | #endif /* HW_LOONGARCH_BOOT_H */ |