OSDN Git Service

riscv/efi_stub: Add support for RISCV_EFI_BOOT_PROTOCOL
authorSunil V L <sunilvl@ventanamicro.com>
Thu, 19 May 2022 05:15:12 +0000 (10:45 +0530)
committerArd Biesheuvel <ardb@kernel.org>
Thu, 19 May 2022 08:22:17 +0000 (10:22 +0200)
Add support for getting the boot hart ID from the Linux EFI stub using
RISCV_EFI_BOOT_PROTOCOL. This method is preferred over the existing DT
based approach since it works irrespective of DT or ACPI.

The specification of the protocol is hosted at:
https://github.com/riscv-non-isa/riscv-uefi

Signed-off-by: Sunil V L <sunilvl@ventanamicro.com>
Acked-by: Palmer Dabbelt <palmer@rivosinc.com>
Reviewed-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
Link: https://lore.kernel.org/r/20220519051512.136724-2-sunilvl@ventanamicro.com
[ardb: minor tweaks for coding style and whitespace]
Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
drivers/firmware/efi/libstub/efistub.h
drivers/firmware/efi/libstub/riscv-stub.c
include/linux/efi.h

index a0477af..b0ae0a4 100644 (file)
@@ -794,6 +794,13 @@ union efi_tcg2_protocol {
        } mixed_mode;
 };
 
+struct riscv_efi_boot_protocol {
+       u64 revision;
+
+       efi_status_t (__efiapi *get_boot_hartid)(struct riscv_efi_boot_protocol *,
+                                                unsigned long *boot_hartid);
+};
+
 typedef union efi_load_file_protocol efi_load_file_protocol_t;
 typedef union efi_load_file_protocol efi_load_file2_protocol_t;
 
index eec0438..9e85e58 100644 (file)
@@ -21,9 +21,9 @@
 #define MIN_KIMG_ALIGN         SZ_4M
 #endif
 
-typedef void __noreturn (*jump_kernel_func)(unsigned int, unsigned long);
+typedef void __noreturn (*jump_kernel_func)(unsigned long, unsigned long);
 
-static u32 hartid;
+static unsigned long hartid;
 
 static int get_boot_hartid_from_fdt(void)
 {
@@ -47,14 +47,31 @@ static int get_boot_hartid_from_fdt(void)
        return 0;
 }
 
+static efi_status_t get_boot_hartid_from_efi(void)
+{
+       efi_guid_t boot_protocol_guid = RISCV_EFI_BOOT_PROTOCOL_GUID;
+       struct riscv_efi_boot_protocol *boot_protocol;
+       efi_status_t status;
+
+       status = efi_bs_call(locate_protocol, &boot_protocol_guid, NULL,
+                            (void **)&boot_protocol);
+       if (status != EFI_SUCCESS)
+               return status;
+       return efi_call_proto(boot_protocol, get_boot_hartid, &hartid);
+}
+
 efi_status_t check_platform_features(void)
 {
+       efi_status_t status;
        int ret;
 
-       ret = get_boot_hartid_from_fdt();
-       if (ret) {
-               efi_err("/chosen/boot-hartid missing or invalid!\n");
-               return EFI_UNSUPPORTED;
+       status = get_boot_hartid_from_efi();
+       if (status != EFI_SUCCESS) {
+               ret = get_boot_hartid_from_fdt();
+               if (ret) {
+                       efi_err("Failed to get boot hartid!\n");
+                       return EFI_UNSUPPORTED;
+               }
        }
        return EFI_SUCCESS;
 }
index 580ce60..0412304 100644 (file)
@@ -410,6 +410,8 @@ void efi_native_runtime_setup(void);
 #define LINUX_EFI_MOK_VARIABLE_TABLE_GUID      EFI_GUID(0xc451ed2b, 0x9694, 0x45d3,  0xba, 0xba, 0xed, 0x9f, 0x89, 0x88, 0xa3, 0x89)
 #define LINUX_EFI_COCO_SECRET_AREA_GUID                EFI_GUID(0xadf956ad, 0xe98c, 0x484c,  0xae, 0x11, 0xb5, 0x1c, 0x7d, 0x33, 0x64, 0x47)
 
+#define RISCV_EFI_BOOT_PROTOCOL_GUID           EFI_GUID(0xccd15fec, 0x6f73, 0x4eec,  0x83, 0x95, 0x3e, 0x69, 0xe4, 0xb9, 0x40, 0xbf)
+
 /*
  * This GUID may be installed onto the kernel image's handle as a NULL protocol
  * to signal to the stub that the placement of the image should be respected,