summaryrefslogtreecommitdiff
path: root/lib/efi_loader/efi_riscv.c
diff options
context:
space:
mode:
authorSunil V L <sunilvl@ventanamicro.com>2022-01-28 18:18:44 +0300
committerHal Feng <hal.feng@starfivetech.com>2023-11-29 05:47:33 +0300
commitf1428044084cf04e545cd4f5d67ad68adf3f7873 (patch)
tree177cc2facd03ed792ae73333fbf386f30af6aaf1 /lib/efi_loader/efi_riscv.c
parent3adcafc929ced658e704e5c215425e009c61e2bf (diff)
downloadu-boot-f1428044084cf04e545cd4f5d67ad68adf3f7873.tar.xz
efi_loader: Enable RISCV_EFI_BOOT_PROTOCOL support
This adds support for new RISCV_EFI_BOOT_PROTOCOL to communicate the boot hart ID to bootloader/kernel on RISC-V UEFI platforms. 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> Reviewed-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
Diffstat (limited to 'lib/efi_loader/efi_riscv.c')
-rw-r--r--lib/efi_loader/efi_riscv.c60
1 files changed, 60 insertions, 0 deletions
diff --git a/lib/efi_loader/efi_riscv.c b/lib/efi_loader/efi_riscv.c
new file mode 100644
index 0000000000..bccfefd8fb
--- /dev/null
+++ b/lib/efi_loader/efi_riscv.c
@@ -0,0 +1,60 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Defines APIs that allow an OS to interact with UEFI firmware to query
+ * information about the boot hart ID.
+ *
+ * Copyright (c) 2022, Ventana Micro Systems Inc
+ */
+
+#define LOG_CATEGORY LOGC_EFI
+#include <common.h>
+#include <efi_loader.h>
+#include <efi_variable.h>
+#include <log.h>
+#include <asm/global_data.h>
+#include <efi_riscv.h>
+
+DECLARE_GLOBAL_DATA_PTR;
+
+static const efi_guid_t efi_guid_riscv_boot_protocol = RISCV_EFI_BOOT_PROTOCOL_GUID;
+
+/**
+ * efi_riscv_get_boot_hartid() - return boot hart ID
+ * @this: RISCV_EFI_BOOT_PROTOCOL instance
+ * @boot_hartid: caller allocated memory to return boot hart id
+ * Return: status code
+ */
+static efi_status_t EFIAPI
+efi_riscv_get_boot_hartid(struct riscv_efi_boot_protocol *this,
+ efi_uintn_t *boot_hartid)
+{
+ EFI_ENTRY("%p, %p", this, boot_hartid);
+
+ if (this != &riscv_efi_boot_prot || !boot_hartid)
+ return EFI_INVALID_PARAMETER;
+
+ *boot_hartid = gd->arch.boot_hart;
+
+ return EFI_EXIT(EFI_SUCCESS);
+}
+
+struct riscv_efi_boot_protocol riscv_efi_boot_prot = {
+ .revision = RISCV_EFI_BOOT_PROTOCOL_REVISION,
+ .get_boot_hartid = efi_riscv_get_boot_hartid
+};
+
+/**
+ * efi_riscv_register() - register RISCV_EFI_BOOT_PROTOCOL
+ *
+ * Return: status code
+ */
+efi_status_t efi_riscv_register(void)
+{
+ efi_status_t ret = EFI_SUCCESS;
+
+ ret = efi_add_protocol(efi_root, &efi_guid_riscv_boot_protocol,
+ (void *)&riscv_efi_boot_prot);
+ if (ret != EFI_SUCCESS)
+ log_err("Cannot install RISCV_EFI_BOOT_PROTOCOL\n");
+ return ret;
+}