diff mbox series

[kvm-unit-tests,v6,32/32] arm64: Use the provided fdt when booting through EFI

Message ID 20230530160924.82158-33-nikos.nikoleris@arm.com (mailing list archive)
State New, archived
Headers show
Series EFI and ACPI support for arm64 | expand

Commit Message

Nikos Nikoleris May 30, 2023, 4:09 p.m. UTC
This patch uses the fdt pointer provided through efi_bootinfo_t for
tests that run as EFI apps. As in Linux, we give priority to the fdt.
First, we check if the pointer to the fdt is set and only if it isn't
we fallback to using the ACPI.

In addition, this patches changes the efi run script to generate and
use a fdt unless the user has set the enviroment variable EFI_USE_ACPI
to 'y'.

As a result:

$> ./arm/efi/run ./arm/selftest.efi -append "setup smp=2 mem=256" -smp 2 -m 256

will use an fdt, where as

$> EFI_USE_ACPI=y ./arm/efi/run ./arm/selftest.efi -append "setup smp=2 mem=256" -smp 2 -m 256

will run relying on ACPI.

Signed-off-by: Nikos Nikoleris <nikos.nikoleris@arm.com>
---
 arm/efi/run     |  9 +++++++++
 lib/arm/setup.c | 23 +++++++++++++++++++----
 2 files changed, 28 insertions(+), 4 deletions(-)
diff mbox series

Patch

diff --git a/arm/efi/run b/arm/efi/run
index dfff717a..c61da311 100755
--- a/arm/efi/run
+++ b/arm/efi/run
@@ -19,6 +19,9 @@  source scripts/common.bash
 : "${EFI_UEFI:=/usr/share/qemu-efi-aarch64/QEMU_EFI.fd}"
 : "${EFI_TEST:=efi-tests}"
 : "${EFI_CASE:=$(basename $1 .efi)}"
+: "${EFI_VAR_GUID:=97ef3e03-7329-4a6a-b9ba-6c1fdcc5f823}"
+
+[ "$EFI_USE_ACPI" = "y" ] || EFI_USE_DTB=y
 
 if [ ! -f "$EFI_UEFI" ]; then
 	echo "UEFI firmware not found: $EFI_UEFI"
@@ -53,6 +56,12 @@  mkdir -p "$EFI_CASE_DIR"
 
 cp "$EFI_SRC/$EFI_CASE.efi" "$EFI_TEST/$EFI_CASE/"
 echo "@echo -off" > "$EFI_TEST/$EFI_CASE/startup.nsh"
+if [ "$EFI_USE_DTB" = "y" ]; then
+	qemu_args+=(-machine acpi=off)
+	FDT_BASENAME="dtb"
+	$(EFI_RUN=y $TEST_DIR/run -machine dumpdtb="$EFI_TEST/$EFI_CASE/$FDT_BASENAME" "${qemu_args[@]}")
+	echo "setvar fdtfile -guid $EFI_VAR_GUID -rt =L\"$FDT_BASENAME\""  >> "$EFI_TEST/$EFI_CASE/startup.nsh"
+fi
 echo "$EFI_CASE.efi" "${cmd_args[@]}" >> "$EFI_TEST/$EFI_CASE/startup.nsh"
 
 EFI_RUN=y $TEST_DIR/run \
diff --git a/lib/arm/setup.c b/lib/arm/setup.c
index c4f495a9..0fa21b7e 100644
--- a/lib/arm/setup.c
+++ b/lib/arm/setup.c
@@ -329,6 +329,8 @@  static efi_status_t efi_mem_init(efi_bootinfo_t *efi_bootinfo)
 	struct mem_region r;
 	uintptr_t text = (uintptr_t)&_text, etext = __ALIGN((uintptr_t)&_etext, 4096);
 	uintptr_t data = (uintptr_t)&_data, edata = __ALIGN((uintptr_t)&_edata, 4096);
+	const void *fdt = efi_bootinfo->fdt;
+	int fdt_size, ret;
 
 	/*
 	 * Record the largest free EFI_CONVENTIONAL_MEMORY region
@@ -393,6 +395,17 @@  static efi_status_t efi_mem_init(efi_bootinfo_t *efi_bootinfo)
 		}
 		mem_region_add(&r);
 	}
+	if (fdt) {
+		/* Move the FDT to the base of free memory */
+		fdt_size = fdt_totalsize(fdt);
+		ret = fdt_move(fdt, (void *)free_mem_start, fdt_size);
+		assert(ret == 0);
+		ret = dt_init((void *)free_mem_start);
+		assert(ret == 0);
+		free_mem_start += ALIGN(fdt_size, EFI_PAGE_SIZE);
+		free_mem_pages -= ALIGN(fdt_size, EFI_PAGE_SIZE) >> EFI_PAGE_SHIFT;
+	}
+
 	__phys_end &= PHYS_MASK;
 	asm_mmu_disable();
 
@@ -440,10 +453,12 @@  efi_status_t setup_efi(efi_bootinfo_t *efi_bootinfo)
 		return status;
 	}
 
-	status = setup_rsdp(efi_bootinfo);
-	if (status != EFI_SUCCESS) {
-		printf("Cannot find RSDP in EFI system table\n");
-		return status;
+	if (!dt_available()) {
+		status = setup_rsdp(efi_bootinfo);
+		if (status != EFI_SUCCESS) {
+			printf("Cannot find RSDP in EFI system table\n");
+			return status;
+		}
 	}
 
 	psci_set_conduit();