[PATCH 24/25] efi: add efi_device hook to be called before an image is started

Sascha Hauer s.hauer at pengutronix.de
Mon Dec 13 13:09:04 PST 2021


boot_services::open_protocol supports opening protocols exclusively.
A protocol that is opened exclusively can not be used anymore by
an application that is called via boot_services::start_image.

We want to open the SNP protocol exclusively in the next step. That
would mean a chainloaded barebox could no longer use the SNP protocol
because it's exclusively opened by the current barebox already.
To work around this a efi_drv::dev_pause and efi_drv::dev_continue is
introduced. The former is called before an application is started and
the latter right after an application has exited. This will be used
by the SNP network driver to enter/leave exclusive mode.

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 common/efi/efi-image.c   |  4 ++++
 drivers/efi/efi-device.c | 28 ++++++++++++++++++++++++++++
 include/efi/efi-device.h |  5 +++++
 3 files changed, 37 insertions(+)

diff --git a/common/efi/efi-image.c b/common/efi/efi-image.c
index bd1c58438e..7807d0653e 100644
--- a/common/efi/efi-image.c
+++ b/common/efi/efi-image.c
@@ -149,10 +149,14 @@ static int efi_execute_image(const char *file)
 		shutdown_barebox();
 	}
 
+	efi_pause_devices();
+
 	efiret = BS->start_image(handle, NULL, NULL);
 	if (EFI_ERROR(efiret))
 		pr_err("failed to StartImage: %s\n", efi_strerror(efiret));
 
+	efi_continue_devices();
+
 	if (!is_driver)
 		BS->unload_image(handle);
 
diff --git a/drivers/efi/efi-device.c b/drivers/efi/efi-device.c
index 6c86a8ab1a..f3f5452b98 100644
--- a/drivers/efi/efi-device.c
+++ b/drivers/efi/efi-device.c
@@ -466,6 +466,34 @@ static int efi_init_devices(void)
 }
 core_initcall(efi_init_devices);
 
+void efi_pause_devices(void)
+{
+	struct device_d *dev;
+
+	bus_for_each_device(&efi_bus, dev) {
+		struct driver_d *drv = dev->driver;
+		struct efi_device *efidev = to_efi_device(dev);
+		struct efi_driver *efidrv = to_efi_driver(drv);
+
+		if (efidrv->dev_pause)
+			efidrv->dev_pause(efidev);
+	}
+}
+
+void efi_continue_devices(void)
+{
+	struct device_d *dev;
+
+	bus_for_each_device(&efi_bus, dev) {
+		struct driver_d *drv = dev->driver;
+		struct efi_device *efidev = to_efi_device(dev);
+		struct efi_driver *efidrv = to_efi_driver(drv);
+
+		if (efidrv->dev_continue)
+			efidrv->dev_continue(efidev);
+	}
+}
+
 static void efi_devpath(efi_handle_t handle)
 {
 	efi_status_t efiret;
diff --git a/include/efi/efi-device.h b/include/efi/efi-device.h
index 5ec59a8a2d..729fbc8103 100644
--- a/include/efi/efi-device.h
+++ b/include/efi/efi-device.h
@@ -15,6 +15,8 @@ struct efi_driver {
 	struct driver_d driver;
 	int (*probe)(struct efi_device *efidev);
 	void (*remove)(struct efi_device *efidev);
+	int (*dev_pause)(struct efi_device *efidev);
+	int (*dev_continue)(struct efi_device *efidev);
 	efi_guid_t guid;
 };
 
@@ -45,6 +47,9 @@ int efi_connect_all(void);
 void efi_register_devices(void);
 struct efi_device *efi_get_bootsource(void);
 
+void efi_pause_devices(void);
+void efi_continue_devices(void);
+
 static inline bool efi_device_has_guid(struct efi_device *efidev, efi_guid_t guid)
 {
 	int i;
-- 
2.30.2




More information about the barebox mailing list