[PATCH v16 5/7] x86/boot: Early parse RSDP and fill in boot_params

From: Chao Fan
Date: Wed Jan 23 2019 - 06:10:21 EST


RSDP is needed by both KASLR, so parse it early and fill it in
boot_params before KASLR code.

RSDP is needed by lots of other code, it would be easier to have it
always built-in instead of a long "depends on" line in Kconfig.

Signed-off-by: Chao Fan <fanc.fnst@xxxxxxxxxxxxxx>
---
arch/x86/boot/compressed/Makefile | 2 ++
arch/x86/boot/compressed/acpi.c | 22 ++++++++++++++++++++++
arch/x86/boot/compressed/misc.c | 7 +++++++
arch/x86/boot/compressed/misc.h | 7 +++++++
4 files changed, 38 insertions(+)

diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/Makefile
index f0515ac895a4..96b71e52a2e8 100644
--- a/arch/x86/boot/compressed/Makefile
+++ b/arch/x86/boot/compressed/Makefile
@@ -84,6 +84,8 @@ ifdef CONFIG_X86_64
vmlinux-objs-y += $(obj)/pgtable_64.o
endif

+vmlinux-objs-y += $(obj)/acpi.o
+
$(obj)/eboot.o: KBUILD_CFLAGS += -fshort-wchar -mno-red-zone

vmlinux-objs-$(CONFIG_EFI_STUB) += $(obj)/eboot.o $(obj)/efi_stub_$(BITS).o \
diff --git a/arch/x86/boot/compressed/acpi.c b/arch/x86/boot/compressed/acpi.c
index 0c389a22bb86..c207791332c7 100644
--- a/arch/x86/boot/compressed/acpi.c
+++ b/arch/x86/boot/compressed/acpi.c
@@ -194,4 +194,26 @@ static acpi_physical_address bios_get_rsdp_addr(void)

return 0;
}
+
+/*
+ * Very early parse RSDP, based on acpi_os_get_root_pointer().
+ * Return address of RSDP on success, 0 on failed to parse RSDP.
+ */
+acpi_physical_address get_rsdp_addr(void)
+{
+ acpi_physical_address pa;
+
+ pa = get_acpi_rsdp();
+
+ if (!pa)
+ pa = boot_params->acpi_rsdp_addr;
+
+ if (!pa)
+ pa = efi_get_rsdp_addr();
+
+ if (!pa)
+ pa = bios_get_rsdp_addr();
+
+ return pa;
+}
#endif /* CONFIG_ACPI */
diff --git a/arch/x86/boot/compressed/misc.c b/arch/x86/boot/compressed/misc.c
index 8dd1d5ccae58..86fa8bf56d68 100644
--- a/arch/x86/boot/compressed/misc.c
+++ b/arch/x86/boot/compressed/misc.c
@@ -382,6 +382,13 @@ asmlinkage __visible void *extract_kernel(void *rmode, memptr heap,
debug_putaddr(trampoline_32bit);
#endif

+ /*
+ * Very early parse RSDP and fill in boot_params.
+ * Early parsing is only executed once, and later anyone who
+ * needs RSDP can gain RSDP address by boot_params but not parse again.
+ */
+ boot_params->acpi_rsdp_addr = get_rsdp_addr();
+
/*
* The memory hole needed for the kernel is the larger of either
* the entire decompressed kernel plus relocation table, or the
diff --git a/arch/x86/boot/compressed/misc.h b/arch/x86/boot/compressed/misc.h
index 764ad50c0119..e1dd15769cf3 100644
--- a/arch/x86/boot/compressed/misc.h
+++ b/arch/x86/boot/compressed/misc.h
@@ -119,3 +119,10 @@ static inline void console_init(void)
void set_sev_encryption_mask(void);

#endif
+
+/* acpi.c */
+#ifdef CONFIG_ACPI
+acpi_physical_address get_rsdp_addr(void);
+#else
+static inline acpi_physical_address get_rsdp_addr(void) { return 0; }
+#endif
--
2.20.1