From 0588ef3ae3d23466ab812bc5f3e10cb2a6b2e09b Mon Sep 17 00:00:00 2001 From: Victor Sun Date: Tue, 9 Feb 2021 10:23:36 +0800 Subject: [PATCH] HV: merge multiboot standard data structures in one header In this way, all multiboot standard data structure could be found in multiboot_std.h. The multiboot_priv.h stores all private definitions and multiboot.h is the only public API header file. Tracked-On: #5661 Signed-off-by: Victor Sun Reviewed-by: Jason Chen CJ --- hypervisor/boot/include/multiboot.h | 35 +--- hypervisor/boot/include/multiboot2.h | 82 -------- hypervisor/boot/include/multiboot_std.h | 229 +++++++++++++++++++++ hypervisor/boot/multiboot/multiboot.c | 51 ----- hypervisor/boot/multiboot/multiboot_priv.h | 68 +----- 5 files changed, 234 insertions(+), 231 deletions(-) delete mode 100644 hypervisor/boot/include/multiboot2.h create mode 100644 hypervisor/boot/include/multiboot_std.h diff --git a/hypervisor/boot/include/multiboot.h b/hypervisor/boot/include/multiboot.h index e59706181..a0bb78b26 100644 --- a/hypervisor/boot/include/multiboot.h +++ b/hypervisor/boot/include/multiboot.h @@ -7,26 +7,7 @@ #ifndef MULTIBOOT_H #define MULTIBOOT_H -#ifdef CONFIG_MULTIBOOT2 -#include -#endif - -#define MULTIBOOT_HEADER_MAGIC 0x1BADB002 -#define MULTIBOOT_INFO_MAGIC 0x2BADB002U - -/* MULTIBOOT HEADER FLAGS */ -#define MULTIBOOT_HEADER_NEED_MEMINFO 0x00000002 - -/* MULTIBOOT INFO FLAGS */ -#define MULTIBOOT_INFO_HAS_CMDLINE 0x00000004U -#define MULTIBOOT_INFO_HAS_MODS 0x00000008U -#define MULTIBOOT_INFO_HAS_MMAP 0x00000040U -#define MULTIBOOT_INFO_HAS_DRIVES 0x00000080U -#define MULTIBOOT_INFO_HAS_LOADER_NAME 0x00000200U - -/* extended flags for acrn multiboot info from multiboot2 */ -#define MULTIBOOT_INFO_HAS_EFI_MMAP 0x00010000U -#define MULTIBOOT_INFO_HAS_EFI64 0x00020000U +#include /* TODO: MAX_MMAP_ENTRIES shall be config by config tool, and same as E820_MAX_ENTRIES */ #define MAX_MMAP_ENTRIES 32U @@ -44,20 +25,6 @@ #include #include -struct multiboot_mmap { - uint32_t size; - uint64_t baseaddr; - uint64_t length; - uint32_t type; -} __packed; - -struct multiboot_module { - uint32_t mm_mod_start; - uint32_t mm_mod_end; - uint32_t mm_string; - uint32_t mm_reserved; -}; - struct acrn_multiboot_info { uint32_t mi_flags; /* the flags is back-compatible with multiboot1 */ diff --git a/hypervisor/boot/include/multiboot2.h b/hypervisor/boot/include/multiboot2.h deleted file mode 100644 index 2f163c584..000000000 --- a/hypervisor/boot/include/multiboot2.h +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Copyright (C) 2020 Intel Corporation. All rights reserved. - * - * SPDX-License-Identifier: BSD-3-Clause - */ - -/* multiboot2.h - Multiboot 2 header file. */ -/* Copyright (C) 1999,2003,2007,2008,2009,2010 Free Software Foundation, Inc. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to - * deal in the Software without restriction, including without limitation the - * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or - * sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL ANY - * DEVELOPER OR DISTRIBUTOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, - * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR - * IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ - -#ifndef MULTIBOOT2_H -#define MULTIBOOT2_H - -#define MULTIBOOT2_HEADER_ALIGN 8 - -#define MULTIBOOT2_HEADER_MAGIC 0xe85250d6U - -/* This should be in %eax. */ -#define MULTIBOOT2_INFO_MAGIC 0x36d76289U - -/* Alignment of the multiboot info structure. */ -#define MULTIBOOT2_INFO_ALIGN 0x00000008U - -/* Flags set in the 'flags' member of the multiboot header. */ - -#define MULTIBOOT2_TAG_ALIGN 8U -#define MULTIBOOT2_TAG_TYPE_END 0U -#define MULTIBOOT2_TAG_TYPE_CMDLINE 1U -#define MULTIBOOT2_TAG_TYPE_BOOT_LOADER_NAME 2U -#define MULTIBOOT2_TAG_TYPE_MODULE 3U -#define MULTIBOOT2_TAG_TYPE_BASIC_MEMINFO 4U -#define MULTIBOOT2_TAG_TYPE_BOOTDEV 5U -#define MULTIBOOT2_TAG_TYPE_MMAP 6U -#define MULTIBOOT2_TAG_TYPE_VBE 7U -#define MULTIBOOT2_TAG_TYPE_FRAMEBUFFER 8U -#define MULTIBOOT2_TAG_TYPE_ELF_SECTIONS 9U -#define MULTIBOOT2_TAG_TYPE_APM 10U -#define MULTIBOOT2_TAG_TYPE_EFI32 11U -#define MULTIBOOT2_TAG_TYPE_EFI64 12U -#define MULTIBOOT2_TAG_TYPE_SMBIOS 13U -#define MULTIBOOT2_TAG_TYPE_ACPI_OLD 14U -#define MULTIBOOT2_TAG_TYPE_ACPI_NEW 15U -#define MULTIBOOT2_TAG_TYPE_NETWORK 16U -#define MULTIBOOT2_TAG_TYPE_EFI_MMAP 17U -#define MULTIBOOT2_TAG_TYPE_EFI_BS 18U -#define MULTIBOOT2_TAG_TYPE_EFI32_IH 19U -#define MULTIBOOT2_TAG_TYPE_EFI64_IH 20U -#define MULTIBOOT2_TAG_TYPE_LOAD_BASE_ADDR 21U - -#define MULTIBOOT2_HEADER_TAG_END 0 -#define MULTIBOOT2_HEADER_TAG_INFORMATION_REQUEST 1 -#define MULTIBOOT2_HEADER_TAG_ADDRESS 2 -#define MULTIBOOT2_HEADER_TAG_ENTRY_ADDRESS 3 -#define MULTIBOOT2_HEADER_TAG_CONSOLE_FLAGS 4 -#define MULTIBOOT2_HEADER_TAG_FRAMEBUFFER 5 -#define MULTIBOOT2_HEADER_TAG_MODULE_ALIGN 6 -#define MULTIBOOT2_HEADER_TAG_EFI_BS 7 -#define MULTIBOOT2_HEADER_TAG_ENTRY_ADDRESS_EFI32 8 -#define MULTIBOOT2_HEADER_TAG_ENTRY_ADDRESS_EFI64 9 -#define MULTIBOOT2_HEADER_TAG_RELOCATABLE 10 - -#define MULTIBOOT2_ARCHITECTURE_I386 0 -#define MULTIBOOT2_ARCHITECTURE_MIPS32 4 - -#endif /* MULTIBOOT2_H */ diff --git a/hypervisor/boot/include/multiboot_std.h b/hypervisor/boot/include/multiboot_std.h new file mode 100644 index 000000000..76cfb09d9 --- /dev/null +++ b/hypervisor/boot/include/multiboot_std.h @@ -0,0 +1,229 @@ +/* + * Copyright (C) 2021 Intel Corporation. All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +/* multiboot_std.h - Multiboot standard header file. */ +/* + * Reference: + * https://www.gnu.org/software/grub/manual/multiboot/multiboot.html + * https://www.gnu.org/software/grub/manual/multiboot2/multiboot.html + */ + +/* Copyright (C) 1999,2003,2007,2008,2009,2010 Free Software Foundation, Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL ANY + * DEVELOPER OR DISTRIBUTOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR + * IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +#ifndef MULTIBOOT_STD_H +#define MULTIBOOT_STD_H + +#define MULTIBOOT_HEADER_MAGIC 0x1BADB002 +#define MULTIBOOT_INFO_MAGIC 0x2BADB002U + +/* MULTIBOOT HEADER FLAGS */ +#define MULTIBOOT_HEADER_NEED_MEMINFO 0x00000002 + +/* MULTIBOOT INFO FLAGS */ +#define MULTIBOOT_INFO_HAS_CMDLINE 0x00000004U +#define MULTIBOOT_INFO_HAS_MODS 0x00000008U +#define MULTIBOOT_INFO_HAS_MMAP 0x00000040U +#define MULTIBOOT_INFO_HAS_DRIVES 0x00000080U +#define MULTIBOOT_INFO_HAS_LOADER_NAME 0x00000200U + +#ifndef ASSEMBLER +struct multiboot_mmap { + uint32_t size; + uint64_t baseaddr; + uint64_t length; + uint32_t type; +} __packed; + +struct multiboot_module { + uint32_t mm_mod_start; + uint32_t mm_mod_end; + uint32_t mm_string; + uint32_t mm_reserved; +} __packed; + +struct multiboot_info { + uint32_t mi_flags; + + /* Valid if mi_flags sets MULTIBOOT_INFO_HAS_MEMORY. */ + uint32_t mi_mem_lower; + uint32_t mi_mem_upper; + + /* Valid if mi_flags sets MULTIBOOT_INFO_HAS_BOOT_DEVICE. */ + uint8_t mi_boot_device_part3; + uint8_t mi_boot_device_part2; + uint8_t mi_boot_device_part1; + uint8_t mi_boot_device_drive; + + /* Valid if mi_flags sets MULTIBOOT_INFO_HAS_CMDLINE. */ + uint32_t mi_cmdline; + + /* Valid if mi_flags sets MULTIBOOT_INFO_HAS_MODS. */ + uint32_t mi_mods_count; + uint32_t mi_mods_addr; + + /* Valid if mi_flags sets MULTIBOOT_INFO_HAS_{AOUT,ELF}_SYMS. */ + uint32_t mi_elfshdr_num; + uint32_t mi_elfshdr_size; + uint32_t mi_elfshdr_addr; + uint32_t mi_elfshdr_shndx; + + /* Valid if mi_flags sets MULTIBOOT_INFO_HAS_MMAP. */ + uint32_t mi_mmap_length; + uint32_t mi_mmap_addr; + + /* Valid if mi_flags sets MULTIBOOT_INFO_HAS_DRIVES. */ + uint32_t mi_drives_length; + uint32_t mi_drives_addr; + + /* Valid if mi_flags sets MULTIBOOT_INFO_HAS_CONFIG_TABLE. */ + uint32_t unused_mi_config_table; + + /* Valid if mi_flags sets MULTIBOOT_INFO_HAS_LOADER_NAME. */ + uint32_t mi_loader_name; + + /* Valid if mi_flags sets MULTIBOOT_INFO_HAS_APM. */ + uint32_t unused_mi_apm_table; + + /* Valid if mi_flags sets MULTIBOOT_INFO_HAS_VBE. */ + uint32_t unused_mi_vbe_control_info; + uint32_t unused_mi_vbe_mode_info; + uint16_t unused_mi_vbe_mode; + uint16_t unused_mi_vbe_interface_seg; + uint16_t unused_mi_vbe_interface_off; + uint16_t unused_mi_vbe_interface_len; +} __packed; +#endif + +#ifdef CONFIG_MULTIBOOT2 +#define MULTIBOOT2_HEADER_ALIGN 8 + +#define MULTIBOOT2_HEADER_MAGIC 0xe85250d6U + +/* This should be in %eax. */ +#define MULTIBOOT2_INFO_MAGIC 0x36d76289U + +/* Alignment of the multiboot info structure. */ +#define MULTIBOOT2_INFO_ALIGN 0x00000008U + +/* Flags set in the 'flags' member of the multiboot header. */ + +#define MULTIBOOT2_TAG_ALIGN 8U +#define MULTIBOOT2_TAG_TYPE_END 0U +#define MULTIBOOT2_TAG_TYPE_CMDLINE 1U +#define MULTIBOOT2_TAG_TYPE_BOOT_LOADER_NAME 2U +#define MULTIBOOT2_TAG_TYPE_MODULE 3U +#define MULTIBOOT2_TAG_TYPE_BASIC_MEMINFO 4U +#define MULTIBOOT2_TAG_TYPE_BOOTDEV 5U +#define MULTIBOOT2_TAG_TYPE_MMAP 6U +#define MULTIBOOT2_TAG_TYPE_VBE 7U +#define MULTIBOOT2_TAG_TYPE_FRAMEBUFFER 8U +#define MULTIBOOT2_TAG_TYPE_ELF_SECTIONS 9U +#define MULTIBOOT2_TAG_TYPE_APM 10U +#define MULTIBOOT2_TAG_TYPE_EFI32 11U +#define MULTIBOOT2_TAG_TYPE_EFI64 12U +#define MULTIBOOT2_TAG_TYPE_SMBIOS 13U +#define MULTIBOOT2_TAG_TYPE_ACPI_OLD 14U +#define MULTIBOOT2_TAG_TYPE_ACPI_NEW 15U +#define MULTIBOOT2_TAG_TYPE_NETWORK 16U +#define MULTIBOOT2_TAG_TYPE_EFI_MMAP 17U +#define MULTIBOOT2_TAG_TYPE_EFI_BS 18U +#define MULTIBOOT2_TAG_TYPE_EFI32_IH 19U +#define MULTIBOOT2_TAG_TYPE_EFI64_IH 20U +#define MULTIBOOT2_TAG_TYPE_LOAD_BASE_ADDR 21U + +#define MULTIBOOT2_HEADER_TAG_END 0 +#define MULTIBOOT2_HEADER_TAG_INFORMATION_REQUEST 1 +#define MULTIBOOT2_HEADER_TAG_ADDRESS 2 +#define MULTIBOOT2_HEADER_TAG_ENTRY_ADDRESS 3 +#define MULTIBOOT2_HEADER_TAG_CONSOLE_FLAGS 4 +#define MULTIBOOT2_HEADER_TAG_FRAMEBUFFER 5 +#define MULTIBOOT2_HEADER_TAG_MODULE_ALIGN 6 +#define MULTIBOOT2_HEADER_TAG_EFI_BS 7 +#define MULTIBOOT2_HEADER_TAG_ENTRY_ADDRESS_EFI32 8 +#define MULTIBOOT2_HEADER_TAG_ENTRY_ADDRESS_EFI64 9 +#define MULTIBOOT2_HEADER_TAG_RELOCATABLE 10 + +#define MULTIBOOT2_ARCHITECTURE_I386 0 +#define MULTIBOOT2_ARCHITECTURE_MIPS32 4 + +#ifndef ASSEMBLER + +struct multiboot2_mmap_entry { + uint64_t addr; + uint64_t len; + uint32_t type; + uint32_t zero; +}; + +struct multiboot2_tag { + uint32_t type; + uint32_t size; +}; + +struct multiboot2_tag_string { + uint32_t type; + uint32_t size; + char string[0]; +}; + +struct multiboot2_tag_module { + uint32_t type; + uint32_t size; + uint32_t mod_start; + uint32_t mod_end; + char cmdline[0]; +}; + +struct multiboot2_tag_mmap { + uint32_t type; + uint32_t size; + uint32_t entry_size; + uint32_t entry_version; + struct multiboot2_mmap_entry entries[0]; +}; + +struct multiboot2_tag_new_acpi { + uint32_t type; + uint32_t size; + uint8_t rsdp[0]; +}; + +struct multiboot2_tag_efi64 { + uint32_t type; + uint32_t size; + uint64_t pointer; +}; + +struct multiboot2_tag_efi_mmap { + uint32_t type; + uint32_t size; + uint32_t descr_size; + uint32_t descr_vers; + uint8_t efi_mmap[0]; +}; +#endif + +#endif /* CONFIG_MULTIBOOT2 */ + +#endif /* MULTIBOOT2_STD_H */ diff --git a/hypervisor/boot/multiboot/multiboot.c b/hypervisor/boot/multiboot/multiboot.c index fc2095a3f..45cbcede4 100644 --- a/hypervisor/boot/multiboot/multiboot.c +++ b/hypervisor/boot/multiboot/multiboot.c @@ -12,57 +12,6 @@ #include #include "multiboot_priv.h" -struct multiboot_info { - uint32_t mi_flags; - - /* Valid if mi_flags sets MULTIBOOT_INFO_HAS_MEMORY. */ - uint32_t mi_mem_lower; - uint32_t mi_mem_upper; - - /* Valid if mi_flags sets MULTIBOOT_INFO_HAS_BOOT_DEVICE. */ - uint8_t mi_boot_device_part3; - uint8_t mi_boot_device_part2; - uint8_t mi_boot_device_part1; - uint8_t mi_boot_device_drive; - - /* Valid if mi_flags sets MULTIBOOT_INFO_HAS_CMDLINE. */ - uint32_t mi_cmdline; - - /* Valid if mi_flags sets MULTIBOOT_INFO_HAS_MODS. */ - uint32_t mi_mods_count; - uint32_t mi_mods_addr; - - /* Valid if mi_flags sets MULTIBOOT_INFO_HAS_{AOUT,ELF}_SYMS. */ - uint32_t mi_elfshdr_num; - uint32_t mi_elfshdr_size; - uint32_t mi_elfshdr_addr; - uint32_t mi_elfshdr_shndx; - - /* Valid if mi_flags sets MULTIBOOT_INFO_HAS_MMAP. */ - uint32_t mi_mmap_length; - uint32_t mi_mmap_addr; - - /* Valid if mi_flags sets MULTIBOOT_INFO_HAS_DRIVES. */ - uint32_t mi_drives_length; - uint32_t mi_drives_addr; - - /* Valid if mi_flags sets MULTIBOOT_INFO_HAS_CONFIG_TABLE. */ - uint32_t unused_mi_config_table; - - /* Valid if mi_flags sets MULTIBOOT_INFO_HAS_LOADER_NAME. */ - uint32_t mi_loader_name; - - /* Valid if mi_flags sets MULTIBOOT_INFO_HAS_APM. */ - uint32_t unused_mi_apm_table; - - /* Valid if mi_flags sets MULTIBOOT_INFO_HAS_VBE. */ - uint32_t unused_mi_vbe_control_info; - uint32_t unused_mi_vbe_mode_info; - uint32_t unused_mi_vbe_interface_seg; - uint32_t unused_mi_vbe_interface_off; - uint32_t unused_mi_vbe_interface_len; -}; - static struct acrn_multiboot_info acrn_mbi = { 0U }; static int32_t mbi_status; diff --git a/hypervisor/boot/multiboot/multiboot_priv.h b/hypervisor/boot/multiboot/multiboot_priv.h index 926493384..8d114816c 100644 --- a/hypervisor/boot/multiboot/multiboot_priv.h +++ b/hypervisor/boot/multiboot/multiboot_priv.h @@ -7,71 +7,11 @@ #ifndef MULTIBOOT_PRIV_H #define MULTIBOOT_PRIV_H +/* extended flags for acrn multiboot info from multiboot2 */ +#define MULTIBOOT_INFO_HAS_EFI_MMAP 0x00010000U +#define MULTIBOOT_INFO_HAS_EFI64 0x00020000U + #ifdef CONFIG_MULTIBOOT2 -#include - -struct multiboot2_mmap_entry -{ - uint64_t addr; - uint64_t len; - uint32_t type; - uint32_t zero; -}; - -struct multiboot2_tag -{ - uint32_t type; - uint32_t size; -}; - -struct multiboot2_tag_string -{ - uint32_t type; - uint32_t size; - char string[0]; -}; - -struct multiboot2_tag_module -{ - uint32_t type; - uint32_t size; - uint32_t mod_start; - uint32_t mod_end; - char cmdline[0]; -}; - -struct multiboot2_tag_mmap -{ - uint32_t type; - uint32_t size; - uint32_t entry_size; - uint32_t entry_version; - struct multiboot2_mmap_entry entries[0]; -}; - -struct multiboot2_tag_new_acpi -{ - uint32_t type; - uint32_t size; - uint8_t rsdp[0]; -}; - -struct multiboot2_tag_efi64 -{ - uint32_t type; - uint32_t size; - uint64_t pointer; -}; - -struct multiboot2_tag_efi_mmap -{ - uint32_t type; - uint32_t size; - uint32_t descr_size; - uint32_t descr_vers; - uint8_t efi_mmap[0]; -}; - /* * @post boot_regs[1] stores the address pointer that point to a valid multiboot2 info */