* [PATCH 2/5] efi: capitalize enumeration constants
2022-10-10 6:08 [PATCH 1/5] efi: retire efi_bool_t Ahmad Fatoum
@ 2022-10-10 6:08 ` Ahmad Fatoum
2022-10-10 6:08 ` [PATCH 3/5] hw_random: add EFI RNG driver Ahmad Fatoum
` (3 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: Ahmad Fatoum @ 2022-10-10 6:08 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
Linux coding style is using all caps for constants. Follow this for
enum efi_locate_search_type as well. No functional change.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
drivers/efi/efi-device.c | 10 +++++-----
include/efi.h | 6 +++---
2 files changed, 8 insertions(+), 8 deletions(-)
diff --git a/drivers/efi/efi-device.c b/drivers/efi/efi-device.c
index af5406afa682..6b903723524e 100644
--- a/drivers/efi/efi-device.c
+++ b/drivers/efi/efi-device.c
@@ -91,7 +91,7 @@ static efi_handle_t *efi_find_parent(efi_handle_t *handle)
struct efi_open_protocol_information_entry *entry_buffer;
unsigned long entry_count;
- ret = efi_locate_handle(by_protocol, &efi_device_path_protocol_guid,
+ ret = efi_locate_handle(BY_PROTOCOL, &efi_device_path_protocol_guid,
NULL, &handle_count, &handles);
if (ret)
return NULL;
@@ -245,7 +245,7 @@ void efi_register_devices(void)
struct efi_device **efidevs;
int registered;
- ret = efi_locate_handle(by_protocol, &efi_device_path_protocol_guid,
+ ret = efi_locate_handle(BY_PROTOCOL, &efi_device_path_protocol_guid,
NULL, &handle_count, &handles);
if (ret)
return;
@@ -290,7 +290,7 @@ int efi_connect_all(void)
efi_handle_t *handle_buffer;
int i;
- efiret = BS->locate_handle_buffer(all_handles, NULL, NULL, &handle_count,
+ efiret = BS->locate_handle_buffer(ALL_HANDLES, NULL, NULL, &handle_count,
&handle_buffer);
if (EFI_ERROR(efiret))
return -efi_errno(efiret);
@@ -637,7 +637,7 @@ static int do_efi_protocol_dump(int argc, char **argv)
printf("Searching for:\n");
printf(" %pUl: %s\n", &guid, efi_guid_string(&guid));
- ret = efi_locate_handle(by_protocol, &guid, NULL, &handle_count, &handles);
+ ret = efi_locate_handle(BY_PROTOCOL, &guid, NULL, &handle_count, &handles);
if (!ret)
efi_dump(handles, handle_count);
@@ -653,7 +653,7 @@ static int do_efi_handle_dump(int argc, char *argv[])
if (argc > 1)
return do_efi_protocol_dump(--argc, ++argv);
- ret = efi_locate_handle(all_handles, NULL, NULL, &handle_count, &handles);
+ ret = efi_locate_handle(ALL_HANDLES, NULL, NULL, &handle_count, &handles);
if (!ret)
efi_dump(handles, handle_count);
diff --git a/include/efi.h b/include/efi.h
index 691e3d5493fc..864158259c53 100644
--- a/include/efi.h
+++ b/include/efi.h
@@ -175,9 +175,9 @@ typedef struct {
} efi_time_cap_t;
enum efi_locate_search_type {
- all_handles,
- by_register_notify,
- by_protocol
+ ALL_HANDLES,
+ BY_REGISTER_NOTIFY,
+ BY_PROTOCOL
};
struct efi_open_protocol_information_entry {
--
2.30.2
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH 3/5] hw_random: add EFI RNG driver
2022-10-10 6:08 [PATCH 1/5] efi: retire efi_bool_t Ahmad Fatoum
2022-10-10 6:08 ` [PATCH 2/5] efi: capitalize enumeration constants Ahmad Fatoum
@ 2022-10-10 6:08 ` Ahmad Fatoum
2022-10-10 6:08 ` [PATCH 4/5] efi: implement and use for_each_efi_config_table Ahmad Fatoum
` (2 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: Ahmad Fatoum @ 2022-10-10 6:08 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
The EFI_RNG_PROTOCOL_GUID is quite simple and as such was a good first
protocol to implement for the barebox EFI loader support. We don't yet
have a payload-side driver making use of it though, so add that here.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
common/efi/guid.c | 1 +
drivers/hw_random/Kconfig | 7 +++++
drivers/hw_random/Makefile | 1 +
drivers/hw_random/efi-rng.c | 53 +++++++++++++++++++++++++++++++++++++
include/efi.h | 18 +++++++++++++
5 files changed, 80 insertions(+)
create mode 100644 drivers/hw_random/efi-rng.c
diff --git a/common/efi/guid.c b/common/efi/guid.c
index f16c597a20fc..93418d57b469 100644
--- a/common/efi/guid.c
+++ b/common/efi/guid.c
@@ -11,6 +11,7 @@ efi_guid_t efi_unknown_device_guid = EFI_UNKNOWN_DEVICE_GUID;
efi_guid_t efi_null_guid = EFI_NULL_GUID;
efi_guid_t efi_global_variable_guid = EFI_GLOBAL_VARIABLE_GUID;
efi_guid_t efi_block_io_protocol_guid = EFI_BLOCK_IO_PROTOCOL_GUID;
+efi_guid_t efi_rng_protocol_guid = EFI_RNG_PROTOCOL_GUID;
efi_guid_t efi_barebox_vendor_guid = EFI_BAREBOX_VENDOR_GUID;
efi_guid_t efi_systemd_vendor_guid = EFI_SYSTEMD_VENDOR_GUID;
diff --git a/drivers/hw_random/Kconfig b/drivers/hw_random/Kconfig
index 32b84b028b0e..bf86240623c4 100644
--- a/drivers/hw_random/Kconfig
+++ b/drivers/hw_random/Kconfig
@@ -44,4 +44,11 @@ config HW_RANDOM_STARFIVE
This driver provides barebox support for the Random Number
Generator hardware found on the StarFive family of SoCs.
+config HW_RANDOM_EFI
+ tristate "EFI Random Number Generator"
+ depends on EFI
+ help
+ This driver provides barebox support for the Random Number
+ Generator Protocol offered by EFI firmware
+
endif
diff --git a/drivers/hw_random/Makefile b/drivers/hw_random/Makefile
index 6fe21bb84c28..9ea064340916 100644
--- a/drivers/hw_random/Makefile
+++ b/drivers/hw_random/Makefile
@@ -5,3 +5,4 @@ obj-$(CONFIG_HWRNG_STM32) += stm32-rng.o
obj-$(CONFIG_HWRNG_DEV_RANDOM) += dev-random.o
obj-$(CONFIG_HW_RANDOM_VIRTIO) += virtio-rng.o
obj-$(CONFIG_HW_RANDOM_STARFIVE) += starfive-vic-rng.o
+obj-$(CONFIG_HW_RANDOM_EFI) += efi-rng.o
diff --git a/drivers/hw_random/efi-rng.c b/drivers/hw_random/efi-rng.c
new file mode 100644
index 000000000000..b74075e3a4ac
--- /dev/null
+++ b/drivers/hw_random/efi-rng.c
@@ -0,0 +1,53 @@
+// SPDX-License-Identifier: GPL-2.0
+#include <common.h>
+#include <driver.h>
+#include <init.h>
+#include <linux/hw_random.h>
+#include <efi/efi-util.h>
+#include <efi/efi-device.h>
+
+struct efi_rng_priv {
+ struct efi_rng_protocol *protocol;
+ struct hwrng hwrng;
+};
+
+static inline struct efi_rng_priv *to_efi_rng(struct hwrng *hwrng)
+{
+ return container_of(hwrng, struct efi_rng_priv, hwrng);
+}
+
+static int efi_rng_read(struct hwrng *hwrng, void *data, size_t len, bool wait)
+{
+ struct efi_rng_protocol *protocol = to_efi_rng(hwrng)->protocol;
+ efi_status_t efiret;
+
+ efiret = protocol->get_rng(protocol, NULL, len, data);
+
+ return -efi_errno(efiret) ?: len;
+}
+
+static int efi_rng_probe(struct efi_device *efidev)
+{
+ struct efi_rng_priv *priv;
+
+ priv = xzalloc(sizeof(*priv));
+
+ BS->handle_protocol(efidev->handle, &efi_rng_protocol_guid,
+ (void **)&priv->protocol);
+ if (!priv->protocol)
+ return -ENODEV;
+
+ priv->hwrng.name = dev_name(&efidev->dev);
+ priv->hwrng.read = efi_rng_read;
+
+ return hwrng_register(&efidev->dev, &priv->hwrng);
+}
+
+static struct efi_driver efi_rng_driver = {
+ .driver = {
+ .name = "efi-rng",
+ },
+ .probe = efi_rng_probe,
+ .guid = EFI_RNG_PROTOCOL_GUID,
+};
+device_efi_driver(efi_rng_driver);
diff --git a/include/efi.h b/include/efi.h
index 864158259c53..149c4e74c6cb 100644
--- a/include/efi.h
+++ b/include/efi.h
@@ -538,6 +538,7 @@ extern efi_guid_t efi_unknown_device_guid;
extern efi_guid_t efi_null_guid;
extern efi_guid_t efi_global_variable_guid;
extern efi_guid_t efi_block_io_protocol_guid;
+extern efi_guid_t efi_rng_protocol_guid;
extern efi_guid_t efi_barebox_vendor_guid;
extern efi_guid_t efi_systemd_vendor_guid;
@@ -691,4 +692,21 @@ char *device_path_to_partuuid(struct efi_device_path *dev_path);
const char *efi_guid_string(efi_guid_t *g);
+#define EFI_RNG_PROTOCOL_GUID \
+ EFI_GUID(0x3152bca5, 0xeade, 0x433d, 0x86, 0x2e, \
+ 0xc0, 0x1c, 0xdc, 0x29, 0x1f, 0x44)
+
+#define EFI_RNG_ALGORITHM_RAW \
+ EFI_GUID(0xe43176d7, 0xb6e8, 0x4827, 0xb7, 0x84, \
+ 0x7f, 0xfd, 0xc4, 0xb6, 0x85, 0x61)
+
+struct efi_rng_protocol {
+ efi_status_t (EFIAPI *get_info)(struct efi_rng_protocol *protocol,
+ size_t *rng_algorithm_list_size,
+ efi_guid_t *rng_algorithm_list);
+ efi_status_t (EFIAPI *get_rng)(struct efi_rng_protocol *protocol,
+ efi_guid_t *rng_algorithm,
+ size_t rng_value_length, uint8_t *rng_value);
+};
+
#endif /* _LINUX_EFI_H */
--
2.30.2
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH 4/5] efi: implement and use for_each_efi_config_table
2022-10-10 6:08 [PATCH 1/5] efi: retire efi_bool_t Ahmad Fatoum
2022-10-10 6:08 ` [PATCH 2/5] efi: capitalize enumeration constants Ahmad Fatoum
2022-10-10 6:08 ` [PATCH 3/5] hw_random: add EFI RNG driver Ahmad Fatoum
@ 2022-10-10 6:08 ` Ahmad Fatoum
2022-10-10 6:08 ` [PATCH 5/5] efi: add device tree configuration table support Ahmad Fatoum
2022-10-13 6:33 ` [PATCH 1/5] efi: retire efi_bool_t Sascha Hauer
4 siblings, 0 replies; 6+ messages in thread
From: Ahmad Fatoum @ 2022-10-10 6:08 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
Iterating over the system table is something we do at two places,
already and the third will soon follow. Use the occasion to factor the
loop head into a macro.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
drivers/bus/acpi.c | 6 ++----
drivers/efi/efi-device.c | 9 ++++-----
include/efi.h | 5 +++++
3 files changed, 11 insertions(+), 9 deletions(-)
diff --git a/drivers/bus/acpi.c b/drivers/bus/acpi.c
index 63d3f618b4fb..1d6069b6d82a 100644
--- a/drivers/bus/acpi.c
+++ b/drivers/bus/acpi.c
@@ -231,11 +231,9 @@ struct bus_type acpi_bus = {
static int efi_acpi_probe(void)
{
- efi_config_table_t *table = NULL;
- int i;
+ efi_config_table_t *ect, *table = NULL;
- for (i = 0; i < efi_sys_table->nr_tables; i++) {
- efi_config_table_t *ect = &efi_sys_table->tables[i];
+ for_each_efi_config_table(ect) {
/* take ACPI < 2 table only if no ACPI 2.0 is available */
if (!efi_guidcmp(ect->guid, EFI_ACPI_20_TABLE_GUID)) {
acpi_bus.name = "acpi2";
diff --git a/drivers/efi/efi-device.c b/drivers/efi/efi-device.c
index 6b903723524e..defde7018696 100644
--- a/drivers/efi/efi-device.c
+++ b/drivers/efi/efi-device.c
@@ -347,13 +347,12 @@ struct bus_type efi_bus = {
static void efi_businfo(struct device_d *dev)
{
- int i;
+ efi_config_table_t *t;
+ int i = 0;
printf("Tables:\n");
- for (i = 0; i < efi_sys_table->nr_tables; i++) {
- efi_config_table_t *t = &efi_sys_table->tables[i];
-
- printf(" %d: %pUl: %s\n", i, &t->guid,
+ for_each_efi_config_table(t) {
+ printf(" %d: %pUl: %s\n", i++, &t->guid,
efi_guid_string(&t->guid));
}
}
diff --git a/include/efi.h b/include/efi.h
index 149c4e74c6cb..36e08af67bf3 100644
--- a/include/efi.h
+++ b/include/efi.h
@@ -547,6 +547,11 @@ typedef struct {
unsigned long table;
} efi_config_table_t;
+#define for_each_efi_config_table(t) \
+ for (t = efi_sys_table->tables; \
+ t - efi_sys_table->tables < efi_sys_table->nr_tables; \
+ t++)
+
#define EFI_SYSTEM_TABLE_SIGNATURE ((u64)0x5453595320494249ULL)
#define EFI_2_30_SYSTEM_TABLE_REVISION ((2 << 16) | (30))
--
2.30.2
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH 5/5] efi: add device tree configuration table support
2022-10-10 6:08 [PATCH 1/5] efi: retire efi_bool_t Ahmad Fatoum
` (2 preceding siblings ...)
2022-10-10 6:08 ` [PATCH 4/5] efi: implement and use for_each_efi_config_table Ahmad Fatoum
@ 2022-10-10 6:08 ` Ahmad Fatoum
2022-10-13 6:33 ` [PATCH 1/5] efi: retire efi_bool_t Sascha Hauer
4 siblings, 0 replies; 6+ messages in thread
From: Ahmad Fatoum @ 2022-10-10 6:08 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
When running on device-tree enabled systems, barebox as EFI payload may
be passed a device tree via the system table. We've no use for that just
yet, but lets make it available as /efi.dtb.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
common/efi/guid.c | 1 +
common/efi/payload/Makefile | 1 +
common/efi/payload/fdt.c | 43 +++++++++++++++++++++++++++++++++++++
include/efi.h | 1 +
4 files changed, 46 insertions(+)
create mode 100644 common/efi/payload/fdt.c
diff --git a/common/efi/guid.c b/common/efi/guid.c
index 93418d57b469..ca16f4520ff2 100644
--- a/common/efi/guid.c
+++ b/common/efi/guid.c
@@ -14,6 +14,7 @@ efi_guid_t efi_block_io_protocol_guid = EFI_BLOCK_IO_PROTOCOL_GUID;
efi_guid_t efi_rng_protocol_guid = EFI_RNG_PROTOCOL_GUID;
efi_guid_t efi_barebox_vendor_guid = EFI_BAREBOX_VENDOR_GUID;
efi_guid_t efi_systemd_vendor_guid = EFI_SYSTEMD_VENDOR_GUID;
+efi_guid_t efi_fdt_guid = EFI_DEVICE_TREE_GUID;
#define EFI_GUID_STRING(guid, short, long) do { \
if (!efi_guidcmp(guid, *g)) \
diff --git a/common/efi/payload/Makefile b/common/efi/payload/Makefile
index bcbdda335f06..eeed046b0045 100644
--- a/common/efi/payload/Makefile
+++ b/common/efi/payload/Makefile
@@ -2,5 +2,6 @@
obj-y += init.o
obj-y += image.o
+obj-$(CONFIG_OFTREE) += fdt.o
bbenv-y += env-efi
obj-$(CONFIG_CMD_IOMEM) += iomem.o
diff --git a/common/efi/payload/fdt.c b/common/efi/payload/fdt.c
new file mode 100644
index 000000000000..dbbc93fb7d68
--- /dev/null
+++ b/common/efi/payload/fdt.c
@@ -0,0 +1,43 @@
+// SPDX-License-Identifier: GPL-2.0
+
+#define pr_fmt(fmt) "efi-fdt: " fmt
+
+#include <common.h>
+#include <init.h>
+#include <libfile.h>
+#include <efi/efi-payload.h>
+#include <efi/efi-device.h>
+
+static int efi_fdt_probe(void)
+{
+ efi_config_table_t *ect;
+
+ for_each_efi_config_table(ect) {
+ struct fdt_header *oftree;
+ u32 magic, size;
+ int ret;
+
+ if (efi_guidcmp(ect->guid, EFI_DEVICE_TREE_GUID))
+ continue;
+
+ oftree = (void *)ect->table;
+ magic = be32_to_cpu(oftree->magic);
+
+ if (magic != FDT_MAGIC) {
+ pr_err("table has invalid magic 0x%08x\n", magic);
+ return -EILSEQ;
+ }
+
+ size = be32_to_cpu(oftree->totalsize);
+ ret = write_file("/efi.dtb", oftree, size);
+ if (ret) {
+ pr_err("error saving /efi.dtb: %pe\n", ERR_PTR(ret));
+ return ret;
+ }
+
+ return 0;
+ }
+
+ return 0;
+}
+late_initcall(efi_fdt_probe);
diff --git a/include/efi.h b/include/efi.h
index 36e08af67bf3..3595cf05ccb7 100644
--- a/include/efi.h
+++ b/include/efi.h
@@ -541,6 +541,7 @@ extern efi_guid_t efi_block_io_protocol_guid;
extern efi_guid_t efi_rng_protocol_guid;
extern efi_guid_t efi_barebox_vendor_guid;
extern efi_guid_t efi_systemd_vendor_guid;
+extern efi_guid_t efi_fdt_guid;
typedef struct {
efi_guid_t guid;
--
2.30.2
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 1/5] efi: retire efi_bool_t
2022-10-10 6:08 [PATCH 1/5] efi: retire efi_bool_t Ahmad Fatoum
` (3 preceding siblings ...)
2022-10-10 6:08 ` [PATCH 5/5] efi: add device tree configuration table support Ahmad Fatoum
@ 2022-10-13 6:33 ` Sascha Hauer
4 siblings, 0 replies; 6+ messages in thread
From: Sascha Hauer @ 2022-10-13 6:33 UTC (permalink / raw)
To: Ahmad Fatoum; +Cc: barebox
On Mon, Oct 10, 2022 at 08:08:38AM +0200, Ahmad Fatoum wrote:
> GCC defaults to a one-byte bool on all its platform, except for IBM RS/6000,
> which will most likely never support. Thus just drop the efi_bool type
> we only use at a single place and use bool directly.
>
> Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
> ---
> include/efi.h | 1 -
> include/efi/efi-stdio.h | 2 +-
> 2 files changed, 1 insertion(+), 2 deletions(-)
Applied, thanks
Sascha
>
> diff --git a/include/efi.h b/include/efi.h
> index a1b22f2d8f88..691e3d5493fc 100644
> --- a/include/efi.h
> +++ b/include/efi.h
> @@ -62,7 +62,6 @@ struct efi_device_path;
> #define EFI_ERROR(a) (((signed long) a) < 0)
>
> typedef unsigned long efi_status_t;
> -typedef u8 efi_bool_t;
> typedef u16 efi_char16_t; /* UNICODE character */
> typedef u64 efi_physical_addr_t;
> typedef void *efi_handle_t;
> diff --git a/include/efi/efi-stdio.h b/include/efi/efi-stdio.h
> index 66fb0afc36b3..e8af244bfcf6 100644
> --- a/include/efi/efi-stdio.h
> +++ b/include/efi/efi-stdio.h
> @@ -8,7 +8,7 @@ struct efi_simple_text_input_ex_protocol;
>
> typedef efi_status_t (EFIAPI *efi_input_reset_ex)(
> struct efi_simple_text_input_ex_protocol *this,
> - efi_bool_t extended_verification
> + bool extended_verification
> );
>
> struct efi_key_state {
> --
> 2.30.2
>
>
>
--
Pengutronix e.K. | |
Steuerwalder Str. 21 | http://www.pengutronix.de/ |
31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
^ permalink raw reply [flat|nested] 6+ messages in thread