From: Sunil V L <sunilvl@ventanamicro.com>
To: Heinrich Schuchardt <xypron.glpk@gmx.de>
Cc: u-boot@lists.denx.de, Ard Biesheuvel <ardb@kernel.org>,
Anup Patel <apatel@ventanamicro.com>,
Atish Patra <atishp@rivosinc.com>,
Abner Chang <abner.chang@hpe.com>,
Jessica Clarke <jrtc27@jrtc27.com>,
Sunil V L <sunilvl@ventanamicro.com>
Subject: [RFC PATCH 1/1] efi_loader: Enable RISCV_EFI_BOOT_PROTOCOL support
Date: Wed, 26 Jan 2022 16:36:11 +0530 [thread overview]
Message-ID: <20220126110611.33325-2-sunilvl@ventanamicro.com> (raw)
In-Reply-To: <20220126110611.33325-1-sunilvl@ventanamicro.com>
This adds support for new RISCV_EFI_BOOT_PROTOCOL to
communicate the boot hart ID to bootloader/kernel on RISC-V
UEFI platforms.
Signed-off-by: Sunil V L <sunilvl@ventanamicro.com>
---
include/efi_api.h | 4 +++
include/efi_loader.h | 2 ++
include/efi_riscv.h | 16 +++++++++
lib/efi_loader/Kconfig | 7 ++++
lib/efi_loader/Makefile | 1 +
lib/efi_loader/efi_riscv.c | 69 ++++++++++++++++++++++++++++++++++++++
lib/efi_loader/efi_setup.c | 6 ++++
7 files changed, 105 insertions(+)
create mode 100644 include/efi_riscv.h
create mode 100644 lib/efi_loader/efi_riscv.c
diff --git a/include/efi_api.h b/include/efi_api.h
index 8d5d835bd0..f123d0557c 100644
--- a/include/efi_api.h
+++ b/include/efi_api.h
@@ -438,6 +438,10 @@ struct efi_runtime_services {
EFI_GUID(0x607f766c, 0x7455, 0x42be, 0x93, \
0x0b, 0xe4, 0xd7, 0x6d, 0xb2, 0x72, 0x0f)
+#define RISCV_EFI_BOOT_PROTOCOL_GUID \
+ EFI_GUID(0xccd15fec, 0x6f73, 0x4eec, 0x83, \
+ 0x95, 0x3e, 0x69, 0xe4, 0xb9, 0x40, 0xbf)
+
/**
* struct efi_configuration_table - EFI Configuration Table
*
diff --git a/include/efi_loader.h b/include/efi_loader.h
index 701efcd2b6..1fa75b40fe 100644
--- a/include/efi_loader.h
+++ b/include/efi_loader.h
@@ -527,6 +527,8 @@ efi_status_t efi_disk_register(void);
efi_status_t efi_rng_register(void);
/* Called by efi_init_obj_list() to install EFI_TCG2_PROTOCOL */
efi_status_t efi_tcg2_register(void);
+/* Called by efi_init_obj_list() to install RISCV_EFI_BOOT_PROTOCOL */
+efi_status_t efi_riscv_register(void);
/* Called by efi_init_obj_list() to do initial measurement */
efi_status_t efi_tcg2_do_initial_measurement(void);
/* measure the pe-coff image, extend PCR and add Event Log */
diff --git a/include/efi_riscv.h b/include/efi_riscv.h
new file mode 100644
index 0000000000..6beb2637f6
--- /dev/null
+++ b/include/efi_riscv.h
@@ -0,0 +1,16 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+/*
+ * RISCV_EFI_BOOT_PROTOCOL
+ *
+ * Copyright (c) 2022 Ventana Micro Systems Inc
+ */
+
+#include <efi_api.h>
+
+#define RISCV_EFI_BOOT_PROTOCOL_REVISION 0x00010000
+
+struct riscv_efi_boot_protocol {
+ u64 revision;
+ efi_status_t (EFIAPI *get_boot_hartid) (struct riscv_efi_boot_protocol *this,
+ efi_uintn_t *boot_hartid);
+};
diff --git a/lib/efi_loader/Kconfig b/lib/efi_loader/Kconfig
index 24f9a2bb75..77ba6a7ea1 100644
--- a/lib/efi_loader/Kconfig
+++ b/lib/efi_loader/Kconfig
@@ -369,4 +369,11 @@ config EFI_ESRT
help
Enabling this option creates the ESRT UEFI system table.
+config EFI_RISCV_BOOT_PROTOCOL
+ bool "RISCV_EFI_BOOT_PROTOCOL support"
+ default y
+ depends on RISCV
+ help
+ Provide a RISCV_EFI_BOOT_PROTOCOL implementation on RISC-V platform.
+
endif
diff --git a/lib/efi_loader/Makefile b/lib/efi_loader/Makefile
index fd344cea29..b2c664d108 100644
--- a/lib/efi_loader/Makefile
+++ b/lib/efi_loader/Makefile
@@ -62,6 +62,7 @@ obj-$(CONFIG_GENERATE_ACPI_TABLE) += efi_acpi.o
obj-$(CONFIG_GENERATE_SMBIOS_TABLE) += efi_smbios.o
obj-$(CONFIG_EFI_RNG_PROTOCOL) += efi_rng.o
obj-$(CONFIG_EFI_TCG2_PROTOCOL) += efi_tcg2.o
+obj-$(CONFIG_EFI_RISCV_BOOT_PROTOCOL) += efi_riscv.o
obj-$(CONFIG_EFI_LOAD_FILE2_INITRD) += efi_load_initrd.o
obj-$(CONFIG_EFI_SIGNATURE_SUPPORT) += efi_signature.o
diff --git a/lib/efi_loader/efi_riscv.c b/lib/efi_loader/efi_riscv.c
new file mode 100644
index 0000000000..91b8d2b927
--- /dev/null
+++ b/lib/efi_loader/efi_riscv.c
@@ -0,0 +1,69 @@
+// 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;
+static efi_uintn_t hartid;
+
+/**
+ * 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)
+{
+ log_err(" efi_riscv_get_boot_hartid ENTER\n");
+ if ((this == NULL) || (boot_hartid == NULL))
+ return EFI_INVALID_PARAMETER;
+
+ *boot_hartid = hartid;
+
+ return EFI_SUCCESS;
+}
+
+static const 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;
+
+ /* save boot hart id since gd is not accessible after launching
+ * the kernel
+ */
+ hartid = gd->arch.boot_hart;
+
+ 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;
+}
diff --git a/lib/efi_loader/efi_setup.c b/lib/efi_loader/efi_setup.c
index 49172e3579..380adc15c8 100644
--- a/lib/efi_loader/efi_setup.c
+++ b/lib/efi_loader/efi_setup.c
@@ -247,6 +247,12 @@ efi_status_t efi_init_obj_list(void)
goto out;
}
+ if (IS_ENABLED(CONFIG_EFI_RISCV_BOOT_PROTOCOL)) {
+ ret = efi_riscv_register();
+ if (ret != EFI_SUCCESS)
+ goto out;
+ }
+
/* Secure boot */
ret = efi_init_secure_boot();
if (ret != EFI_SUCCESS)
--
2.25.1
next prev parent reply other threads:[~2022-01-26 23:24 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-01-26 11:06 [RFC PATCH 0/1] RISCV_EFI_BOOT_PROTOCOL support in U-boot Sunil V L
2022-01-26 11:06 ` Sunil V L [this message]
2022-01-26 14:01 ` [RFC PATCH 1/1] efi_loader: Enable RISCV_EFI_BOOT_PROTOCOL support Jessica Clarke
2022-01-27 6:35 ` Heinrich Schuchardt
2022-01-27 8:44 ` Heinrich Schuchardt
2022-01-28 5:08 ` Sunil V L
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220126110611.33325-2-sunilvl@ventanamicro.com \
--to=sunilvl@ventanamicro.com \
--cc=abner.chang@hpe.com \
--cc=apatel@ventanamicro.com \
--cc=ardb@kernel.org \
--cc=atishp@rivosinc.com \
--cc=jrtc27@jrtc27.com \
--cc=u-boot@lists.denx.de \
--cc=xypron.glpk@gmx.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox