[PATCH 3/3] efi_driver: move event registration to driver

Heinrich Schuchardt heinrich.schuchardt at canonical.com
Thu Oct 6 07:49:33 CEST 2022


Move the registration of events for the addition and removal of block
devices to the block device driver. Here we can add a reference to the
EFI Driver Binding protocol as context.

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt at canonical.com>
---
 include/efi_loader.h              |  7 +++++--
 lib/efi_driver/efi_block_device.c | 16 ++++++++++++++++
 lib/efi_loader/efi_disk.c         | 25 ++-----------------------
 lib/efi_loader/efi_setup.c        |  4 ----
 4 files changed, 23 insertions(+), 29 deletions(-)

diff --git a/include/efi_loader.h b/include/efi_loader.h
index 6f78f77404..15e7680af9 100644
--- a/include/efi_loader.h
+++ b/include/efi_loader.h
@@ -10,6 +10,7 @@
 
 #include <common.h>
 #include <blk.h>
+#include <event.h>
 #include <log.h>
 #include <part_efi.h>
 #include <efi_api.h>
@@ -544,8 +545,6 @@ void efi_carve_out_dt_rsv(void *fdt);
 void efi_try_purge_kaslr_seed(void *fdt);
 /* Called by bootefi to make console interface available */
 efi_status_t efi_console_register(void);
-/* Called by efi_init_early() to add block devices when probed */
-efi_status_t efi_disk_init(void);
 /* Called by efi_init_obj_list() to proble all block devices */
 efi_status_t efi_disks_register(void);
 /* Called by efi_init_obj_list() to install EFI_RNG_PROTOCOL */
@@ -749,6 +748,10 @@ efi_status_t efi_add_conventional_memory_map(u64 ram_start, u64 ram_end,
 
 /* Called by board init to initialize the EFI drivers */
 efi_status_t efi_driver_init(void);
+/* Called when a block device is added */
+int efi_disk_probe(void *ctx, struct event *event);
+/* Called when a block device is removed */
+int efi_disk_remove(void *ctx, struct event *event);
 /* Called by board init to initialize the EFI memory map */
 int efi_memory_init(void);
 /* Adds new or overrides configuration table entry to the system table */
diff --git a/lib/efi_driver/efi_block_device.c b/lib/efi_driver/efi_block_device.c
index bd3688848b..add00eeebb 100644
--- a/lib/efi_driver/efi_block_device.c
+++ b/lib/efi_driver/efi_block_device.c
@@ -205,6 +205,22 @@ static efi_status_t efi_bl_bind(
 static efi_status_t
 efi_bl_init(struct efi_driver_binding_extended_protocol *this)
 {
+	int ret;
+
+	ret = event_register("efi_disk add", EVT_DM_POST_PROBE,
+			     efi_disk_probe, this);
+	if (ret) {
+		log_err("Event registration for efi_disk add failed\n");
+		return EFI_OUT_OF_RESOURCES;
+	}
+
+	ret = event_register("efi_disk del", EVT_DM_PRE_REMOVE,
+			     efi_disk_remove, this);
+	if (ret) {
+		log_err("Event registration for efi_disk del failed\n");
+		return EFI_OUT_OF_RESOURCES;
+	}
+
 	return EFI_SUCCESS;
 }
 
diff --git a/lib/efi_loader/efi_disk.c b/lib/efi_loader/efi_disk.c
index 39ea1a68a6..aea17b7380 100644
--- a/lib/efi_loader/efi_disk.c
+++ b/lib/efi_loader/efi_disk.c
@@ -620,7 +620,7 @@ static int efi_disk_create_part(struct udevice *dev)
  *
  * @return	0 on success, -1 otherwise
  */
-static int efi_disk_probe(void *ctx, struct event *event)
+int efi_disk_probe(void *ctx, struct event *event)
 {
 	struct udevice *dev;
 	enum uclass_id id;
@@ -724,7 +724,7 @@ static int efi_disk_delete_part(struct udevice *dev)
  *
  * @return	0 on success, -1 otherwise
  */
-static int efi_disk_remove(void *ctx, struct event *event)
+int efi_disk_remove(void *ctx, struct event *event)
 {
 	enum uclass_id id;
 	struct udevice *dev;
@@ -740,27 +740,6 @@ static int efi_disk_remove(void *ctx, struct event *event)
 		return 0;
 }
 
-efi_status_t efi_disk_init(void)
-{
-	int ret;
-
-	ret = event_register("efi_disk add", EVT_DM_POST_PROBE,
-			     efi_disk_probe, NULL);
-	if (ret) {
-		log_err("Event registration for efi_disk add failed\n");
-		return EFI_OUT_OF_RESOURCES;
-	}
-
-	ret = event_register("efi_disk del", EVT_DM_PRE_REMOVE,
-			     efi_disk_remove, NULL);
-	if (ret) {
-		log_err("Event registration for efi_disk del failed\n");
-		return EFI_OUT_OF_RESOURCES;
-	}
-
-	return EFI_SUCCESS;
-}
-
 /**
  * efi_disk_get_device_name() - get U-Boot device name associated with EFI handle
  *
diff --git a/lib/efi_loader/efi_setup.c b/lib/efi_loader/efi_setup.c
index 113d5d5d56..9d7189336d 100644
--- a/lib/efi_loader/efi_setup.c
+++ b/lib/efi_loader/efi_setup.c
@@ -200,10 +200,6 @@ static efi_status_t __efi_init_early(void)
 
 	/* Initialize EFI driver uclass */
 	ret = efi_driver_init();
-	if (ret != EFI_SUCCESS)
-		goto out;
-
-	ret = efi_disk_init();
 out:
 	return ret;
 }
-- 
2.37.2



More information about the U-Boot mailing list