mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <s.hauer@pengutronix.de>
To: Barebox List <barebox@lists.infradead.org>
Subject: [PATCH 24/25] efi: add efi_device hook to be called before an image is started
Date: Mon, 13 Dec 2021 22:09:04 +0100	[thread overview]
Message-ID: <20211213210905.3399551-25-s.hauer@pengutronix.de> (raw)
In-Reply-To: <20211213210905.3399551-1-s.hauer@pengutronix.de>

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


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


  parent reply	other threads:[~2021-12-13 21:13 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-12-13 21:08 [PATCH 00/25] EFI improvements Sascha Hauer
2021-12-13 21:08 ` [PATCH 01/25] efi-devicepath: Make efi_device_path argument const Sascha Hauer
2021-12-13 21:08 ` [PATCH 02/25] efi: move device-path defines and types to header file Sascha Hauer
2021-12-13 21:08 ` [PATCH 03/25] efi: Implement device_path_to_subtype() Sascha Hauer
2021-12-13 21:08 ` [PATCH 04/25] efi: Do not register IPv[46] devices Sascha Hauer
2021-12-13 21:08 ` [PATCH 05/25] console: Fix message colours Sascha Hauer
2021-12-16 12:21   ` Jules Maselbas
2021-12-17 13:23     ` Sascha Hauer
2021-12-17 13:24       ` Jules Maselbas
2021-12-13 21:08 ` [PATCH 06/25] efi-stdio: remove unnecessary check Sascha Hauer
2021-12-13 21:08 ` [PATCH 07/25] efi-stdio: rename to efi_process_escape Sascha Hauer
2021-12-13 21:08 ` [PATCH 08/25] efi-stdio: return bytes actually consumed Sascha Hauer
2021-12-13 21:08 ` [PATCH 09/25] efi-stdio: fix escape sequence end detection Sascha Hauer
2021-12-13 21:08 ` [PATCH 10/25] efi-stdio: improve escape sequence parsing Sascha Hauer
2021-12-13 21:08 ` [PATCH 11/25] efi-stdio: Fix out of bounds error in puts Sascha Hauer
2021-12-13 21:08 ` [PATCH 12/25] efi-stdio: Fix tab printing Sascha Hauer
2021-12-13 21:08 ` [PATCH 13/25] efi-stdio: Implement efi_console_putc() using efi_console_puts() Sascha Hauer
2021-12-15 11:04   ` Ahmad Fatoum
2021-12-13 21:08 ` [PATCH 14/25] efi-stdio: Fix '\b' handling Sascha Hauer
2021-12-13 21:08 ` [PATCH 15/25] efi-stdio: implement input buffering with a kfifo Sascha Hauer
2021-12-13 21:08 ` [PATCH 16/25] efi-stdio: limit set_cursor to screen size boundaries Sascha Hauer
2021-12-13 21:08 ` [PATCH 17/25] efi-stdio: implement getting the cursor position Sascha Hauer
2021-12-13 21:08 ` [PATCH 18/25] efi-stdio: Implement setting cursor visibility Sascha Hauer
2021-12-13 21:08 ` [PATCH 19/25] efi-stdio: Support different text modes Sascha Hauer
2021-12-13 21:09 ` [PATCH 20/25] edit: improve screen size detection Sascha Hauer
2021-12-13 21:09 ` [PATCH 21/25] edit: Improve behaviour on efi-stdio console Sascha Hauer
2021-12-16 12:41   ` Jules Maselbas
2021-12-17 13:29     ` Sascha Hauer
2021-12-13 21:09 ` [PATCH 22/25] edit: send escape sequence only for smartscroll Sascha Hauer
2021-12-13 21:09 ` [PATCH 23/25] net: efi-snp: Check for carrier before sending Sascha Hauer
2021-12-13 21:09 ` Sascha Hauer [this message]
2021-12-13 21:09 ` [PATCH 25/25] net: efi-snp: Open protocol exclusively Sascha Hauer
2021-12-15 11:07 ` [PATCH 00/25] EFI improvements Ahmad Fatoum
2021-12-18 12:07   ` Michael Graichen
2021-12-18 13:55     ` Sascha Hauer

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=20211213210905.3399551-25-s.hauer@pengutronix.de \
    --to=s.hauer@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    /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