public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
* [PATCH 0/3] efi_driver: move event registration to driver
@ 2022-10-06  5:49 Heinrich Schuchardt
  2022-10-06  5:49 ` [PATCH 1/3] efi_driver: add init function to EFI block driver Heinrich Schuchardt
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Heinrich Schuchardt @ 2022-10-06  5:49 UTC (permalink / raw)
  To: Ilias Apalodimas; +Cc: u-boot, Heinrich Schuchardt

For correct handling of protocols by the EFI block driver we need to
open protocols BY_DRIVER or BY_CHILD_CONTROLLER. By moving the event
registration for block devices to the block device driver we can add
the EFI Driver Binding protocol interface as context to the events.
Later patches will use the driver handle from this protocol as agent
handle.

Heinrich Schuchardt (3):
  efi_driver: add init function to EFI block driver
  efi_selftest: rename event_notify
  efi_driver: move event registration to driver

 include/efi_driver.h                          |  3 ++
 include/efi_loader.h                          |  7 ++-
 lib/efi_driver/efi_block_device.c             | 28 +++++++++++
 lib/efi_driver/efi_uclass.c                   | 17 +++++--
 lib/efi_loader/efi_disk.c                     | 25 +---------
 lib/efi_loader/efi_setup.c                    |  8 +---
 lib/efi_selftest/efi_selftest_events.c        | 18 +++----
 .../efi_selftest_exitbootservices.c           |  6 +--
 lib/efi_selftest/efi_selftest_tpl.c           | 47 ++++++++++---------
 lib/efi_selftest/efi_selftest_watchdog.c      | 30 ++++++------
 10 files changed, 107 insertions(+), 82 deletions(-)

-- 
2.37.2


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 1/3] efi_driver: add init function to EFI block driver
  2022-10-06  5:49 [PATCH 0/3] efi_driver: move event registration to driver Heinrich Schuchardt
@ 2022-10-06  5:49 ` Heinrich Schuchardt
  2022-10-06  5:49 ` [PATCH 2/3] efi_selftest: rename event_notify Heinrich Schuchardt
  2022-10-06  5:49 ` [PATCH 3/3] efi_driver: move event registration to driver Heinrich Schuchardt
  2 siblings, 0 replies; 5+ messages in thread
From: Heinrich Schuchardt @ 2022-10-06  5:49 UTC (permalink / raw)
  To: Ilias Apalodimas; +Cc: u-boot, Heinrich Schuchardt

For handling added and removed block devices we need to register events
which has to be done when the driver is installed.

This patch only creates an empty init function that will be filled with
code later on. The function needs to be called before any EFI block devices
are used. Move the efi_driver_init() call to early init.

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
---
 include/efi_driver.h              |  3 +++
 lib/efi_driver/efi_block_device.c | 12 ++++++++++++
 lib/efi_driver/efi_uclass.c       | 17 ++++++++++++-----
 lib/efi_loader/efi_setup.c        | 10 +++++-----
 4 files changed, 32 insertions(+), 10 deletions(-)

diff --git a/include/efi_driver.h b/include/efi_driver.h
index 71e0d3194e..63a95e4cf8 100644
--- a/include/efi_driver.h
+++ b/include/efi_driver.h
@@ -32,12 +32,15 @@ struct efi_driver_binding_extended_protocol {
  *			EFI_DRIVER_BINDING_PROTOCOL.
  * @child_protocol:	Protocol supported by the child handles generated by
  *			the EFI driver.
+ * @init:		Function called by the EFI uclass after installing the
+ *			driver binding protocol.
  * @bind:		Function called by the EFI uclass to attach the
  *			driver to EFI driver to a handle.
  */
 struct efi_driver_ops {
 	const efi_guid_t *protocol;
 	const efi_guid_t *child_protocol;
+	efi_status_t (*init)(struct efi_driver_binding_extended_protocol *this);
 	efi_status_t (*bind)(struct efi_driver_binding_extended_protocol *this,
 			     efi_handle_t handle, void *interface);
 };
diff --git a/lib/efi_driver/efi_block_device.c b/lib/efi_driver/efi_block_device.c
index f440067f70..bd3688848b 100644
--- a/lib/efi_driver/efi_block_device.c
+++ b/lib/efi_driver/efi_block_device.c
@@ -197,6 +197,17 @@ static efi_status_t efi_bl_bind(
 	return ret;
 }
 
+/**
+ * efi_bl_init() - initialize block device driver
+ *
+ * @this:	extended driver binding protocol
+ */
+static efi_status_t
+efi_bl_init(struct efi_driver_binding_extended_protocol *this)
+{
+	return EFI_SUCCESS;
+}
+
 /* Block device driver operators */
 static const struct blk_ops efi_blk_ops = {
 	.read	= efi_bl_read,
@@ -215,6 +226,7 @@ U_BOOT_DRIVER(efi_blk) = {
 static const struct efi_driver_ops driver_ops = {
 	.protocol	= &efi_block_io_guid,
 	.child_protocol = &efi_block_io_guid,
+	.init		= efi_bl_init,
 	.bind		= efi_bl_bind,
 };
 
diff --git a/lib/efi_driver/efi_uclass.c b/lib/efi_driver/efi_uclass.c
index 0a16c594e3..2193f8493f 100644
--- a/lib/efi_driver/efi_uclass.c
+++ b/lib/efi_driver/efi_uclass.c
@@ -284,7 +284,7 @@ static efi_status_t efi_add_driver(struct driver *drv)
 	bp->bp.start = efi_uc_start;
 	bp->bp.stop = efi_uc_stop;
 	bp->bp.version = 0xffffffff;
-	bp->ops = drv->ops;
+	bp->ops = ops;
 
 	ret = efi_create_handle(&bp->bp.driver_binding_handle);
 	if (ret != EFI_SUCCESS) {
@@ -294,13 +294,20 @@ static efi_status_t efi_add_driver(struct driver *drv)
 	bp->bp.image_handle = bp->bp.driver_binding_handle;
 	ret = efi_add_protocol(bp->bp.driver_binding_handle,
 			       &efi_guid_driver_binding_protocol, bp);
-	if (ret != EFI_SUCCESS) {
-		efi_delete_handle(bp->bp.driver_binding_handle);
-		free(bp);
-		goto out;
+	if (ret != EFI_SUCCESS)
+		goto err;
+	if (ops->init) {
+		ret = ops->init(bp);
+		if (ret != EFI_SUCCESS)
+			goto err;
 	}
 out:
 	return ret;
+
+err:
+	efi_delete_handle(bp->bp.driver_binding_handle);
+	free(bp);
+	return ret;
 }
 
 /**
diff --git a/lib/efi_loader/efi_setup.c b/lib/efi_loader/efi_setup.c
index c633fcd91e..113d5d5d56 100644
--- a/lib/efi_loader/efi_setup.c
+++ b/lib/efi_loader/efi_setup.c
@@ -198,6 +198,11 @@ static efi_status_t __efi_init_early(void)
 	if (ret != EFI_SUCCESS)
 		goto out;
 
+	/* Initialize EFI driver uclass */
+	ret = efi_driver_init();
+	if (ret != EFI_SUCCESS)
+		goto out;
+
 	ret = efi_disk_init();
 out:
 	return ret;
@@ -319,11 +324,6 @@ efi_status_t efi_init_obj_list(void)
 	if (ret != EFI_SUCCESS)
 		goto out;
 
-	/* Initialize EFI driver uclass */
-	ret = efi_driver_init();
-	if (ret != EFI_SUCCESS)
-		goto out;
-
 	if (IS_ENABLED(CONFIG_EFI_HAVE_CAPSULE_SUPPORT)) {
 		ret = efi_load_capsule_drivers();
 		if (ret != EFI_SUCCESS)
-- 
2.37.2


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 2/3] efi_selftest: rename event_notify
  2022-10-06  5:49 [PATCH 0/3] efi_driver: move event registration to driver Heinrich Schuchardt
  2022-10-06  5:49 ` [PATCH 1/3] efi_driver: add init function to EFI block driver Heinrich Schuchardt
@ 2022-10-06  5:49 ` Heinrich Schuchardt
  2022-10-06  6:38   ` Ilias Apalodimas
  2022-10-06  5:49 ` [PATCH 3/3] efi_driver: move event registration to driver Heinrich Schuchardt
  2 siblings, 1 reply; 5+ messages in thread
From: Heinrich Schuchardt @ 2022-10-06  5:49 UTC (permalink / raw)
  To: Ilias Apalodimas; +Cc: u-boot, Heinrich Schuchardt

A function event_notify() exists. We should not use the same name for and
EFI event. Rename events in unit tests.

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
---
 lib/efi_selftest/efi_selftest_events.c        | 18 +++----
 .../efi_selftest_exitbootservices.c           |  6 +--
 lib/efi_selftest/efi_selftest_tpl.c           | 47 ++++++++++---------
 lib/efi_selftest/efi_selftest_watchdog.c      | 30 ++++++------
 4 files changed, 55 insertions(+), 46 deletions(-)

diff --git a/lib/efi_selftest/efi_selftest_events.c b/lib/efi_selftest/efi_selftest_events.c
index 90071536a2..743a6b9154 100644
--- a/lib/efi_selftest/efi_selftest_events.c
+++ b/lib/efi_selftest/efi_selftest_events.c
@@ -11,7 +11,7 @@
 
 #include <efi_selftest.h>
 
-static struct efi_event *event_notify;
+static struct efi_event *efi_st_event_notify;
 static struct efi_event *event_wait;
 static unsigned int timer_ticks;
 static struct efi_boot_services *boottime;
@@ -50,7 +50,7 @@ static int setup(const efi_handle_t handle,
 
 	ret = boottime->create_event(EVT_TIMER | EVT_NOTIFY_SIGNAL,
 				     TPL_CALLBACK, notify, (void *)&timer_ticks,
-				     &event_notify);
+				     &efi_st_event_notify);
 	if (ret != EFI_SUCCESS) {
 		efi_st_error("could not create event\n");
 		return EFI_ST_FAILURE;
@@ -75,9 +75,9 @@ static int teardown(void)
 {
 	efi_status_t ret;
 
-	if (event_notify) {
-		ret = boottime->close_event(event_notify);
-		event_notify = NULL;
+	if (efi_st_event_notify) {
+		ret = boottime->close_event(efi_st_event_notify);
+		efi_st_event_notify = NULL;
 		if (ret != EFI_SUCCESS) {
 			efi_st_error("could not close event\n");
 			return EFI_ST_FAILURE;
@@ -112,7 +112,8 @@ static int execute(void)
 
 	/* Set 10 ms timer */
 	timer_ticks = 0;
-	ret = boottime->set_timer(event_notify, EFI_TIMER_PERIODIC, 100000);
+	ret = boottime->set_timer(efi_st_event_notify, EFI_TIMER_PERIODIC,
+				  100000);
 	if (ret != EFI_SUCCESS) {
 		efi_st_error("Could not set timer\n");
 		return EFI_ST_FAILURE;
@@ -146,14 +147,15 @@ static int execute(void)
 		efi_st_error("Incorrect timing of events\n");
 		return EFI_ST_FAILURE;
 	}
-	ret = boottime->set_timer(event_notify, EFI_TIMER_STOP, 0);
+	ret = boottime->set_timer(efi_st_event_notify, EFI_TIMER_STOP, 0);
 	if (ret != EFI_SUCCESS) {
 		efi_st_error("Could not cancel timer\n");
 		return EFI_ST_FAILURE;
 	}
 	/* Set 10 ms timer */
 	timer_ticks = 0;
-	ret = boottime->set_timer(event_notify, EFI_TIMER_RELATIVE, 100000);
+	ret = boottime->set_timer(efi_st_event_notify, EFI_TIMER_RELATIVE,
+				  100000);
 	if (ret != EFI_SUCCESS) {
 		efi_st_error("Could not set timer\n");
 		return EFI_ST_FAILURE;
diff --git a/lib/efi_selftest/efi_selftest_exitbootservices.c b/lib/efi_selftest/efi_selftest_exitbootservices.c
index f5e0d9da89..11b43fdd90 100644
--- a/lib/efi_selftest/efi_selftest_exitbootservices.c
+++ b/lib/efi_selftest/efi_selftest_exitbootservices.c
@@ -26,7 +26,7 @@ struct notification_context {
 };
 
 static struct efi_boot_services *boottime;
-static struct efi_event *event_notify;
+static struct efi_event *efi_st_event_notify;
 struct notification_record record;
 
 struct notification_context context_before = {
@@ -75,7 +75,7 @@ static int setup(const efi_handle_t handle,
 	ret = boottime->create_event(EVT_SIGNAL_EXIT_BOOT_SERVICES,
 				     TPL_CALLBACK, ebs_notify,
 				     &context,
-				     &event_notify);
+				     &efi_st_event_notify);
 	if (ret != EFI_SUCCESS) {
 		efi_st_error("could not create event\n");
 		return EFI_ST_FAILURE;
@@ -83,7 +83,7 @@ static int setup(const efi_handle_t handle,
 	ret = boottime->create_event_ex(0, TPL_CALLBACK, ebs_notify,
 					&context_before,
 					&guid_before_exit_boot_services,
-					&event_notify);
+					&efi_st_event_notify);
 	if (ret != EFI_SUCCESS) {
 		efi_st_error("could not create event\n");
 		return EFI_ST_FAILURE;
diff --git a/lib/efi_selftest/efi_selftest_tpl.c b/lib/efi_selftest/efi_selftest_tpl.c
index f4e467267e..909c78a1c2 100644
--- a/lib/efi_selftest/efi_selftest_tpl.c
+++ b/lib/efi_selftest/efi_selftest_tpl.c
@@ -10,8 +10,8 @@
 
 #include <efi_selftest.h>
 
-static struct efi_event *event_notify;
-static struct efi_event *event_wait;
+static struct efi_event *efi_st_event_notify;
+static struct efi_event *efi_st_event_wait;
 static unsigned int notification_count;
 static struct efi_boot_services *boottime;
 
@@ -49,13 +49,14 @@ static int setup(const efi_handle_t handle,
 	ret = boottime->create_event(EVT_TIMER | EVT_NOTIFY_SIGNAL,
 				     TPL_CALLBACK, notify,
 				     (void *)&notification_count,
-				     &event_notify);
+				     &efi_st_event_notify);
 	if (ret != EFI_SUCCESS) {
 		efi_st_error("could not create event\n");
 		return EFI_ST_FAILURE;
 	}
 	ret = boottime->create_event(EVT_TIMER | EVT_NOTIFY_WAIT,
-				     TPL_NOTIFY, notify, NULL, &event_wait);
+				     TPL_NOTIFY, notify, NULL,
+				     &efi_st_event_wait);
 	if (ret != EFI_SUCCESS) {
 		efi_st_error("could not create event\n");
 		return EFI_ST_FAILURE;
@@ -74,17 +75,17 @@ static int teardown(void)
 {
 	efi_status_t ret;
 
-	if (event_notify) {
-		ret = boottime->close_event(event_notify);
-		event_notify = NULL;
+	if (efi_st_event_notify) {
+		ret = boottime->close_event(efi_st_event_notify);
+		efi_st_event_notify = NULL;
 		if (ret != EFI_SUCCESS) {
 			efi_st_error("could not close event\n");
 			return EFI_ST_FAILURE;
 		}
 	}
-	if (event_wait) {
-		ret = boottime->close_event(event_wait);
-		event_wait = NULL;
+	if (efi_st_event_wait) {
+		ret = boottime->close_event(efi_st_event_wait);
+		efi_st_event_wait = NULL;
 		if (ret != EFI_SUCCESS) {
 			efi_st_error("could not close event\n");
 			return EFI_ST_FAILURE;
@@ -116,24 +117,26 @@ static int execute(void)
 
 	/* Set 10 ms timer */
 	notification_count = 0;
-	ret = boottime->set_timer(event_notify, EFI_TIMER_PERIODIC, 100000);
+	ret = boottime->set_timer(efi_st_event_notify, EFI_TIMER_PERIODIC,
+				  100000);
 	if (ret != EFI_SUCCESS) {
 		efi_st_error("Could not set timer\n");
 		return EFI_ST_FAILURE;
 	}
 	/* Set 100 ms timer */
-	ret = boottime->set_timer(event_wait, EFI_TIMER_RELATIVE, 1000000);
+	ret = boottime->set_timer(efi_st_event_wait, EFI_TIMER_RELATIVE,
+				  1000000);
 	if (ret != EFI_SUCCESS) {
 		efi_st_error("Could not set timer\n");
 		return EFI_ST_FAILURE;
 	}
 	index = 5;
-	ret = boottime->wait_for_event(1, &event_wait, &index);
+	ret = boottime->wait_for_event(1, &efi_st_event_wait, &index);
 	if (ret != EFI_SUCCESS) {
 		efi_st_error("Could not wait for event\n");
 		return EFI_ST_FAILURE;
 	}
-	ret = boottime->check_event(event_wait);
+	ret = boottime->check_event(efi_st_event_wait);
 	if (ret != EFI_NOT_READY) {
 		efi_st_error("Signaled state was not cleared.\n");
 		efi_st_printf("ret = %u\n", (unsigned int)ret);
@@ -150,7 +153,7 @@ static int execute(void)
 		efi_st_error("Incorrect timing of events\n");
 		return EFI_ST_FAILURE;
 	}
-	ret = boottime->set_timer(event_notify, EFI_TIMER_STOP, 0);
+	ret = boottime->set_timer(efi_st_event_notify, EFI_TIMER_STOP, 0);
 	if (ret != EFI_SUCCESS) {
 		efi_st_error("Could not cancel timer\n");
 		return EFI_ST_FAILURE;
@@ -163,19 +166,21 @@ static int execute(void)
 	}
 	/* Set 10 ms timer */
 	notification_count = 0;
-	ret = boottime->set_timer(event_notify, EFI_TIMER_PERIODIC, 100000);
+	ret = boottime->set_timer(efi_st_event_notify, EFI_TIMER_PERIODIC,
+				  100000);
 	if (ret != EFI_SUCCESS) {
 		efi_st_error("Could not set timer\n");
 		return EFI_ST_FAILURE;
 	}
 	/* Set 100 ms timer */
-	ret = boottime->set_timer(event_wait, EFI_TIMER_RELATIVE, 1000000);
+	ret = boottime->set_timer(efi_st_event_wait, EFI_TIMER_RELATIVE,
+				  1000000);
 	if (ret != EFI_SUCCESS) {
 		efi_st_error("Could not set timer\n");
 		return EFI_ST_FAILURE;
 	}
 	do {
-		ret = boottime->check_event(event_wait);
+		ret = boottime->check_event(efi_st_event_wait);
 	} while (ret == EFI_NOT_READY);
 	if (ret != EFI_SUCCESS) {
 		efi_st_error("Could not check event\n");
@@ -189,14 +194,14 @@ static int execute(void)
 		return EFI_ST_FAILURE;
 	}
 	/* Set 1 ms timer */
-	ret = boottime->set_timer(event_wait, EFI_TIMER_RELATIVE, 1000);
+	ret = boottime->set_timer(efi_st_event_wait, EFI_TIMER_RELATIVE, 1000);
 	if (ret != EFI_SUCCESS) {
 		efi_st_error("Could not set timer\n");
 		return EFI_ST_FAILURE;
 	}
 	/* Restore the old TPL level */
 	boottime->restore_tpl(TPL_APPLICATION);
-	ret = boottime->wait_for_event(1, &event_wait, &index);
+	ret = boottime->wait_for_event(1, &efi_st_event_wait, &index);
 	if (ret != EFI_SUCCESS) {
 		efi_st_error("Could not wait for event\n");
 		return EFI_ST_FAILURE;
@@ -208,7 +213,7 @@ static int execute(void)
 		efi_st_error("Queued timer event did not fire\n");
 		return EFI_ST_FAILURE;
 	}
-	ret = boottime->set_timer(event_wait, EFI_TIMER_STOP, 0);
+	ret = boottime->set_timer(efi_st_event_wait, EFI_TIMER_STOP, 0);
 	if (ret != EFI_SUCCESS) {
 		efi_st_error("Could not cancel timer\n");
 		return EFI_ST_FAILURE;
diff --git a/lib/efi_selftest/efi_selftest_watchdog.c b/lib/efi_selftest/efi_selftest_watchdog.c
index a352d4a5ad..4d7ed5a54b 100644
--- a/lib/efi_selftest/efi_selftest_watchdog.c
+++ b/lib/efi_selftest/efi_selftest_watchdog.c
@@ -28,8 +28,8 @@ struct notify_context {
 	unsigned int timer_ticks;
 };
 
-static struct efi_event *event_notify;
-static struct efi_event *event_wait;
+static struct efi_event *efi_st_event_notify;
+static struct efi_event *efi_st_event_wait;
 static struct efi_boot_services *boottime;
 static struct notify_context notification_context;
 static bool watchdog_reset;
@@ -79,13 +79,14 @@ static int setup(const efi_handle_t handle,
 	ret = boottime->create_event(EVT_TIMER | EVT_NOTIFY_SIGNAL,
 				     TPL_CALLBACK, notify,
 				     (void *)&notification_context,
-				     &event_notify);
+				     &efi_st_event_notify);
 	if (ret != EFI_SUCCESS) {
 		efi_st_error("could not create event\n");
 		return EFI_ST_FAILURE;
 	}
 	ret = boottime->create_event(EVT_TIMER | EVT_NOTIFY_WAIT,
-				     TPL_CALLBACK, notify, NULL, &event_wait);
+				     TPL_CALLBACK, notify, NULL,
+				     &efi_st_event_wait);
 	if (ret != EFI_SUCCESS) {
 		efi_st_error("could not create event\n");
 		return EFI_ST_FAILURE;
@@ -138,17 +139,17 @@ static int teardown(void)
 		efi_st_error("Setting watchdog timer failed\n");
 		return EFI_ST_FAILURE;
 	}
-	if (event_notify) {
-		ret = boottime->close_event(event_notify);
-		event_notify = NULL;
+	if (efi_st_event_notify) {
+		ret = boottime->close_event(efi_st_event_notify);
+		efi_st_event_notify = NULL;
 		if (ret != EFI_SUCCESS) {
 			efi_st_error("Could not close event\n");
 			return EFI_ST_FAILURE;
 		}
 	}
-	if (event_wait) {
-		ret = boottime->close_event(event_wait);
-		event_wait = NULL;
+	if (efi_st_event_wait) {
+		ret = boottime->close_event(efi_st_event_wait);
+		efi_st_event_wait = NULL;
 		if (ret != EFI_SUCCESS) {
 			efi_st_error("Could not close event\n");
 			return EFI_ST_FAILURE;
@@ -181,21 +182,22 @@ static int execute(void)
 	}
 	if (watchdog_reset) {
 		/* Set 600 ms timer */
-		ret = boottime->set_timer(event_notify, EFI_TIMER_PERIODIC,
-					  6000000);
+		ret = boottime->set_timer(efi_st_event_notify,
+					  EFI_TIMER_PERIODIC, 6000000);
 		if (ret != EFI_SUCCESS) {
 			efi_st_error("Could not set timer\n");
 			return EFI_ST_FAILURE;
 		}
 	}
 	/* Set 1350 ms timer */
-	ret = boottime->set_timer(event_wait, EFI_TIMER_RELATIVE, 13500000);
+	ret = boottime->set_timer(efi_st_event_wait, EFI_TIMER_RELATIVE,
+				  13500000);
 	if (ret != EFI_SUCCESS) {
 		efi_st_error("Could not set timer\n");
 		return EFI_ST_FAILURE;
 	}
 
-	ret = boottime->wait_for_event(1, &event_wait, &index);
+	ret = boottime->wait_for_event(1, &efi_st_event_wait, &index);
 	if (ret != EFI_SUCCESS) {
 		efi_st_error("Could not wait for event\n");
 		return EFI_ST_FAILURE;
-- 
2.37.2


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 3/3] efi_driver: move event registration to driver
  2022-10-06  5:49 [PATCH 0/3] efi_driver: move event registration to driver Heinrich Schuchardt
  2022-10-06  5:49 ` [PATCH 1/3] efi_driver: add init function to EFI block driver Heinrich Schuchardt
  2022-10-06  5:49 ` [PATCH 2/3] efi_selftest: rename event_notify Heinrich Schuchardt
@ 2022-10-06  5:49 ` Heinrich Schuchardt
  2 siblings, 0 replies; 5+ messages in thread
From: Heinrich Schuchardt @ 2022-10-06  5:49 UTC (permalink / raw)
  To: Ilias Apalodimas; +Cc: u-boot, Heinrich Schuchardt

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@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


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH 2/3] efi_selftest: rename event_notify
  2022-10-06  5:49 ` [PATCH 2/3] efi_selftest: rename event_notify Heinrich Schuchardt
@ 2022-10-06  6:38   ` Ilias Apalodimas
  0 siblings, 0 replies; 5+ messages in thread
From: Ilias Apalodimas @ 2022-10-06  6:38 UTC (permalink / raw)
  To: Heinrich Schuchardt; +Cc: u-boot

On Thu, Oct 06, 2022 at 07:49:32AM +0200, Heinrich Schuchardt wrote:
> A function event_notify() exists. We should not use the same name for and
> EFI event. Rename events in unit tests.
> 
> Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
> ---
>  lib/efi_selftest/efi_selftest_events.c        | 18 +++----
>  .../efi_selftest_exitbootservices.c           |  6 +--
>  lib/efi_selftest/efi_selftest_tpl.c           | 47 ++++++++++---------
>  lib/efi_selftest/efi_selftest_watchdog.c      | 30 ++++++------
>  4 files changed, 55 insertions(+), 46 deletions(-)
> 
> diff --git a/lib/efi_selftest/efi_selftest_events.c b/lib/efi_selftest/efi_selftest_events.c
> index 90071536a2..743a6b9154 100644
> --- a/lib/efi_selftest/efi_selftest_events.c
> +++ b/lib/efi_selftest/efi_selftest_events.c
> @@ -11,7 +11,7 @@
>  
>  #include <efi_selftest.h>
>  
> -static struct efi_event *event_notify;
> +static struct efi_event *efi_st_event_notify;
>  static struct efi_event *event_wait;
>  static unsigned int timer_ticks;
>  static struct efi_boot_services *boottime;
> @@ -50,7 +50,7 @@ static int setup(const efi_handle_t handle,
>  
>  	ret = boottime->create_event(EVT_TIMER | EVT_NOTIFY_SIGNAL,
>  				     TPL_CALLBACK, notify, (void *)&timer_ticks,
> -				     &event_notify);
> +				     &efi_st_event_notify);
>  	if (ret != EFI_SUCCESS) {
>  		efi_st_error("could not create event\n");
>  		return EFI_ST_FAILURE;
> @@ -75,9 +75,9 @@ static int teardown(void)
>  {
>  	efi_status_t ret;
>  
> -	if (event_notify) {
> -		ret = boottime->close_event(event_notify);
> -		event_notify = NULL;
> +	if (efi_st_event_notify) {
> +		ret = boottime->close_event(efi_st_event_notify);
> +		efi_st_event_notify = NULL;
>  		if (ret != EFI_SUCCESS) {
>  			efi_st_error("could not close event\n");
>  			return EFI_ST_FAILURE;
> @@ -112,7 +112,8 @@ static int execute(void)
>  
>  	/* Set 10 ms timer */
>  	timer_ticks = 0;
> -	ret = boottime->set_timer(event_notify, EFI_TIMER_PERIODIC, 100000);
> +	ret = boottime->set_timer(efi_st_event_notify, EFI_TIMER_PERIODIC,
> +				  100000);
>  	if (ret != EFI_SUCCESS) {
>  		efi_st_error("Could not set timer\n");
>  		return EFI_ST_FAILURE;
> @@ -146,14 +147,15 @@ static int execute(void)
>  		efi_st_error("Incorrect timing of events\n");
>  		return EFI_ST_FAILURE;
>  	}
> -	ret = boottime->set_timer(event_notify, EFI_TIMER_STOP, 0);
> +	ret = boottime->set_timer(efi_st_event_notify, EFI_TIMER_STOP, 0);
>  	if (ret != EFI_SUCCESS) {
>  		efi_st_error("Could not cancel timer\n");
>  		return EFI_ST_FAILURE;
>  	}
>  	/* Set 10 ms timer */
>  	timer_ticks = 0;
> -	ret = boottime->set_timer(event_notify, EFI_TIMER_RELATIVE, 100000);
> +	ret = boottime->set_timer(efi_st_event_notify, EFI_TIMER_RELATIVE,
> +				  100000);
>  	if (ret != EFI_SUCCESS) {
>  		efi_st_error("Could not set timer\n");
>  		return EFI_ST_FAILURE;
> diff --git a/lib/efi_selftest/efi_selftest_exitbootservices.c b/lib/efi_selftest/efi_selftest_exitbootservices.c
> index f5e0d9da89..11b43fdd90 100644
> --- a/lib/efi_selftest/efi_selftest_exitbootservices.c
> +++ b/lib/efi_selftest/efi_selftest_exitbootservices.c
> @@ -26,7 +26,7 @@ struct notification_context {
>  };
>  
>  static struct efi_boot_services *boottime;
> -static struct efi_event *event_notify;
> +static struct efi_event *efi_st_event_notify;
>  struct notification_record record;
>  
>  struct notification_context context_before = {
> @@ -75,7 +75,7 @@ static int setup(const efi_handle_t handle,
>  	ret = boottime->create_event(EVT_SIGNAL_EXIT_BOOT_SERVICES,
>  				     TPL_CALLBACK, ebs_notify,
>  				     &context,
> -				     &event_notify);
> +				     &efi_st_event_notify);
>  	if (ret != EFI_SUCCESS) {
>  		efi_st_error("could not create event\n");
>  		return EFI_ST_FAILURE;
> @@ -83,7 +83,7 @@ static int setup(const efi_handle_t handle,
>  	ret = boottime->create_event_ex(0, TPL_CALLBACK, ebs_notify,
>  					&context_before,
>  					&guid_before_exit_boot_services,
> -					&event_notify);
> +					&efi_st_event_notify);
>  	if (ret != EFI_SUCCESS) {
>  		efi_st_error("could not create event\n");
>  		return EFI_ST_FAILURE;
> diff --git a/lib/efi_selftest/efi_selftest_tpl.c b/lib/efi_selftest/efi_selftest_tpl.c
> index f4e467267e..909c78a1c2 100644
> --- a/lib/efi_selftest/efi_selftest_tpl.c
> +++ b/lib/efi_selftest/efi_selftest_tpl.c
> @@ -10,8 +10,8 @@
>  
>  #include <efi_selftest.h>
>  
> -static struct efi_event *event_notify;
> -static struct efi_event *event_wait;
> +static struct efi_event *efi_st_event_notify;
> +static struct efi_event *efi_st_event_wait;
>  static unsigned int notification_count;
>  static struct efi_boot_services *boottime;
>  
> @@ -49,13 +49,14 @@ static int setup(const efi_handle_t handle,
>  	ret = boottime->create_event(EVT_TIMER | EVT_NOTIFY_SIGNAL,
>  				     TPL_CALLBACK, notify,
>  				     (void *)&notification_count,
> -				     &event_notify);
> +				     &efi_st_event_notify);
>  	if (ret != EFI_SUCCESS) {
>  		efi_st_error("could not create event\n");
>  		return EFI_ST_FAILURE;
>  	}
>  	ret = boottime->create_event(EVT_TIMER | EVT_NOTIFY_WAIT,
> -				     TPL_NOTIFY, notify, NULL, &event_wait);
> +				     TPL_NOTIFY, notify, NULL,
> +				     &efi_st_event_wait);
>  	if (ret != EFI_SUCCESS) {
>  		efi_st_error("could not create event\n");
>  		return EFI_ST_FAILURE;
> @@ -74,17 +75,17 @@ static int teardown(void)
>  {
>  	efi_status_t ret;
>  
> -	if (event_notify) {
> -		ret = boottime->close_event(event_notify);
> -		event_notify = NULL;
> +	if (efi_st_event_notify) {
> +		ret = boottime->close_event(efi_st_event_notify);
> +		efi_st_event_notify = NULL;
>  		if (ret != EFI_SUCCESS) {
>  			efi_st_error("could not close event\n");
>  			return EFI_ST_FAILURE;
>  		}
>  	}
> -	if (event_wait) {
> -		ret = boottime->close_event(event_wait);
> -		event_wait = NULL;
> +	if (efi_st_event_wait) {
> +		ret = boottime->close_event(efi_st_event_wait);
> +		efi_st_event_wait = NULL;
>  		if (ret != EFI_SUCCESS) {
>  			efi_st_error("could not close event\n");
>  			return EFI_ST_FAILURE;
> @@ -116,24 +117,26 @@ static int execute(void)
>  
>  	/* Set 10 ms timer */
>  	notification_count = 0;
> -	ret = boottime->set_timer(event_notify, EFI_TIMER_PERIODIC, 100000);
> +	ret = boottime->set_timer(efi_st_event_notify, EFI_TIMER_PERIODIC,
> +				  100000);
>  	if (ret != EFI_SUCCESS) {
>  		efi_st_error("Could not set timer\n");
>  		return EFI_ST_FAILURE;
>  	}
>  	/* Set 100 ms timer */
> -	ret = boottime->set_timer(event_wait, EFI_TIMER_RELATIVE, 1000000);
> +	ret = boottime->set_timer(efi_st_event_wait, EFI_TIMER_RELATIVE,
> +				  1000000);
>  	if (ret != EFI_SUCCESS) {
>  		efi_st_error("Could not set timer\n");
>  		return EFI_ST_FAILURE;
>  	}
>  	index = 5;
> -	ret = boottime->wait_for_event(1, &event_wait, &index);
> +	ret = boottime->wait_for_event(1, &efi_st_event_wait, &index);
>  	if (ret != EFI_SUCCESS) {
>  		efi_st_error("Could not wait for event\n");
>  		return EFI_ST_FAILURE;
>  	}
> -	ret = boottime->check_event(event_wait);
> +	ret = boottime->check_event(efi_st_event_wait);
>  	if (ret != EFI_NOT_READY) {
>  		efi_st_error("Signaled state was not cleared.\n");
>  		efi_st_printf("ret = %u\n", (unsigned int)ret);
> @@ -150,7 +153,7 @@ static int execute(void)
>  		efi_st_error("Incorrect timing of events\n");
>  		return EFI_ST_FAILURE;
>  	}
> -	ret = boottime->set_timer(event_notify, EFI_TIMER_STOP, 0);
> +	ret = boottime->set_timer(efi_st_event_notify, EFI_TIMER_STOP, 0);
>  	if (ret != EFI_SUCCESS) {
>  		efi_st_error("Could not cancel timer\n");
>  		return EFI_ST_FAILURE;
> @@ -163,19 +166,21 @@ static int execute(void)
>  	}
>  	/* Set 10 ms timer */
>  	notification_count = 0;
> -	ret = boottime->set_timer(event_notify, EFI_TIMER_PERIODIC, 100000);
> +	ret = boottime->set_timer(efi_st_event_notify, EFI_TIMER_PERIODIC,
> +				  100000);
>  	if (ret != EFI_SUCCESS) {
>  		efi_st_error("Could not set timer\n");
>  		return EFI_ST_FAILURE;
>  	}
>  	/* Set 100 ms timer */
> -	ret = boottime->set_timer(event_wait, EFI_TIMER_RELATIVE, 1000000);
> +	ret = boottime->set_timer(efi_st_event_wait, EFI_TIMER_RELATIVE,
> +				  1000000);
>  	if (ret != EFI_SUCCESS) {
>  		efi_st_error("Could not set timer\n");
>  		return EFI_ST_FAILURE;
>  	}
>  	do {
> -		ret = boottime->check_event(event_wait);
> +		ret = boottime->check_event(efi_st_event_wait);
>  	} while (ret == EFI_NOT_READY);
>  	if (ret != EFI_SUCCESS) {
>  		efi_st_error("Could not check event\n");
> @@ -189,14 +194,14 @@ static int execute(void)
>  		return EFI_ST_FAILURE;
>  	}
>  	/* Set 1 ms timer */
> -	ret = boottime->set_timer(event_wait, EFI_TIMER_RELATIVE, 1000);
> +	ret = boottime->set_timer(efi_st_event_wait, EFI_TIMER_RELATIVE, 1000);
>  	if (ret != EFI_SUCCESS) {
>  		efi_st_error("Could not set timer\n");
>  		return EFI_ST_FAILURE;
>  	}
>  	/* Restore the old TPL level */
>  	boottime->restore_tpl(TPL_APPLICATION);
> -	ret = boottime->wait_for_event(1, &event_wait, &index);
> +	ret = boottime->wait_for_event(1, &efi_st_event_wait, &index);
>  	if (ret != EFI_SUCCESS) {
>  		efi_st_error("Could not wait for event\n");
>  		return EFI_ST_FAILURE;
> @@ -208,7 +213,7 @@ static int execute(void)
>  		efi_st_error("Queued timer event did not fire\n");
>  		return EFI_ST_FAILURE;
>  	}
> -	ret = boottime->set_timer(event_wait, EFI_TIMER_STOP, 0);
> +	ret = boottime->set_timer(efi_st_event_wait, EFI_TIMER_STOP, 0);
>  	if (ret != EFI_SUCCESS) {
>  		efi_st_error("Could not cancel timer\n");
>  		return EFI_ST_FAILURE;
> diff --git a/lib/efi_selftest/efi_selftest_watchdog.c b/lib/efi_selftest/efi_selftest_watchdog.c
> index a352d4a5ad..4d7ed5a54b 100644
> --- a/lib/efi_selftest/efi_selftest_watchdog.c
> +++ b/lib/efi_selftest/efi_selftest_watchdog.c
> @@ -28,8 +28,8 @@ struct notify_context {
>  	unsigned int timer_ticks;
>  };
>  
> -static struct efi_event *event_notify;
> -static struct efi_event *event_wait;
> +static struct efi_event *efi_st_event_notify;
> +static struct efi_event *efi_st_event_wait;
>  static struct efi_boot_services *boottime;
>  static struct notify_context notification_context;
>  static bool watchdog_reset;
> @@ -79,13 +79,14 @@ static int setup(const efi_handle_t handle,
>  	ret = boottime->create_event(EVT_TIMER | EVT_NOTIFY_SIGNAL,
>  				     TPL_CALLBACK, notify,
>  				     (void *)&notification_context,
> -				     &event_notify);
> +				     &efi_st_event_notify);
>  	if (ret != EFI_SUCCESS) {
>  		efi_st_error("could not create event\n");
>  		return EFI_ST_FAILURE;
>  	}
>  	ret = boottime->create_event(EVT_TIMER | EVT_NOTIFY_WAIT,
> -				     TPL_CALLBACK, notify, NULL, &event_wait);
> +				     TPL_CALLBACK, notify, NULL,
> +				     &efi_st_event_wait);
>  	if (ret != EFI_SUCCESS) {
>  		efi_st_error("could not create event\n");
>  		return EFI_ST_FAILURE;
> @@ -138,17 +139,17 @@ static int teardown(void)
>  		efi_st_error("Setting watchdog timer failed\n");
>  		return EFI_ST_FAILURE;
>  	}
> -	if (event_notify) {
> -		ret = boottime->close_event(event_notify);
> -		event_notify = NULL;
> +	if (efi_st_event_notify) {
> +		ret = boottime->close_event(efi_st_event_notify);
> +		efi_st_event_notify = NULL;
>  		if (ret != EFI_SUCCESS) {
>  			efi_st_error("Could not close event\n");
>  			return EFI_ST_FAILURE;
>  		}
>  	}
> -	if (event_wait) {
> -		ret = boottime->close_event(event_wait);
> -		event_wait = NULL;
> +	if (efi_st_event_wait) {
> +		ret = boottime->close_event(efi_st_event_wait);
> +		efi_st_event_wait = NULL;
>  		if (ret != EFI_SUCCESS) {
>  			efi_st_error("Could not close event\n");
>  			return EFI_ST_FAILURE;
> @@ -181,21 +182,22 @@ static int execute(void)
>  	}
>  	if (watchdog_reset) {
>  		/* Set 600 ms timer */
> -		ret = boottime->set_timer(event_notify, EFI_TIMER_PERIODIC,
> -					  6000000);
> +		ret = boottime->set_timer(efi_st_event_notify,
> +					  EFI_TIMER_PERIODIC, 6000000);
>  		if (ret != EFI_SUCCESS) {
>  			efi_st_error("Could not set timer\n");
>  			return EFI_ST_FAILURE;
>  		}
>  	}
>  	/* Set 1350 ms timer */
> -	ret = boottime->set_timer(event_wait, EFI_TIMER_RELATIVE, 13500000);
> +	ret = boottime->set_timer(efi_st_event_wait, EFI_TIMER_RELATIVE,
> +				  13500000);
>  	if (ret != EFI_SUCCESS) {
>  		efi_st_error("Could not set timer\n");
>  		return EFI_ST_FAILURE;
>  	}
>  
> -	ret = boottime->wait_for_event(1, &event_wait, &index);
> +	ret = boottime->wait_for_event(1, &efi_st_event_wait, &index);
>  	if (ret != EFI_SUCCESS) {
>  		efi_st_error("Could not wait for event\n");
>  		return EFI_ST_FAILURE;
> -- 
> 2.37.2
> 

Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2022-10-06  6:38 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-10-06  5:49 [PATCH 0/3] efi_driver: move event registration to driver Heinrich Schuchardt
2022-10-06  5:49 ` [PATCH 1/3] efi_driver: add init function to EFI block driver Heinrich Schuchardt
2022-10-06  5:49 ` [PATCH 2/3] efi_selftest: rename event_notify Heinrich Schuchardt
2022-10-06  6:38   ` Ilias Apalodimas
2022-10-06  5:49 ` [PATCH 3/3] efi_driver: move event registration to driver Heinrich Schuchardt

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox