1 /*
2  * Copyright (C) 2018-2022 Intel Corporation.
3  *
4  * SPDX-License-Identifier: BSD-3-Clause
5  */
6 
7 #ifndef BOOT_H
8 #define BOOT_H
9 
10 #include <multiboot_std.h>
11 #include <efi.h>
12 #include <vm_configurations.h>
13 
14 /* TODO: MAX_MMAP_ENTRIES shall be config by config tool, and same as E820_MAX_ENTRIES */
15 #define MAX_MMAP_ENTRIES		32U
16 
17 #define MAX_BOOTARGS_SIZE		2048U
18 #define MAX_LOADER_NAME_SIZE		32U
19 #define MAX_PROTOCOL_NAME_SIZE		16U
20 #define MAX_MOD_STRING_SIZE		2048U
21 
22 /* The modules in multiboot are: Pre-launched VM: kernel/ramdisk/acpi; Service VM: kernel/ramdisk */
23 #define MAX_MODULE_NUM			(3U * PRE_VM_NUM + 2U * SERVICE_VM_NUM)
24 
25 /* The vACPI module size is fixed to 1MB */
26 #define ACPI_MODULE_SIZE		MEM_1M
27 
28 struct abi_module {
29 	void			*start;		/* HVA */
30 	uint32_t		size;
31 	const char		string[MAX_MOD_STRING_SIZE];
32 };
33 
34 /* ABI memory map types, compatible to Multiboot/Multiboot2/E820; */
35 #define MMAP_TYPE_RAM		1U
36 #define MMAP_TYPE_RESERVED	2U
37 #define MMAP_TYPE_ACPI_RECLAIM	3U
38 #define MMAP_TYPE_ACPI_NVS	4U
39 #define MMAP_TYPE_UNUSABLE	5U
40 
41 struct abi_mmap {
42 	uint64_t		baseaddr;
43 	uint64_t		length;
44 	uint32_t		type;
45 };
46 
47 struct acrn_boot_info {
48 
49 	char			protocol_name[MAX_PROTOCOL_NAME_SIZE];
50 	const char		cmdline[MAX_BOOTARGS_SIZE];
51 	const char		loader_name[MAX_LOADER_NAME_SIZE];
52 
53 	uint32_t		mods_count;
54 	struct abi_module	mods[MAX_MODULE_NUM];
55 
56 	uint32_t		mmap_entries;
57 	struct abi_mmap		mmap_entry[MAX_MMAP_ENTRIES];
58 
59 	const void		*acpi_rsdp_va;
60 	struct efi_info		uefi_info;
61 };
62 
boot_from_uefi(struct acrn_boot_info * abi)63 static inline bool boot_from_uefi(struct acrn_boot_info *abi)
64 {
65 	return !((abi->uefi_info.systab == 0U) && (abi->uefi_info.systab_hi == 0U));
66 }
67 
68 void get_boot_mods_range(uint64_t *p_start, uint64_t *p_end);
69 
70 int32_t init_multiboot_info(uint32_t *registers);
71 
72 void init_acrn_boot_info(uint32_t *registers);
73 int32_t sanitize_acrn_boot_info(struct acrn_boot_info *abi);
74 struct acrn_boot_info *get_acrn_boot_info(void);
75 
76 struct abi_module *get_mod_by_tag(const struct acrn_boot_info *abi, const char *tag);
77 #endif	/* BOOT_H */
78