All of lore.kernel.org
 help / color / mirror / Atom feed
From: Heinrich Schuchardt <xypron.glpk@gmx.de>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH 15/23] efi_loader: implement ConnectController
Date: Sun, 27 Aug 2017 00:53:24 +0200	[thread overview]
Message-ID: <20170826225328.7550-6-xypron.glpk@gmx.de> (raw)
In-Reply-To: <20170826225328.7550-1-xypron.glpk@gmx.de>

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
---
 include/efi_api.h             |  22 ++++++++
 include/efi_loader.h          |   1 +
 lib/efi_loader/efi_boottime.c | 119 +++++++++++++++++++++++++++++++++++++++++-
 3 files changed, 141 insertions(+), 1 deletion(-)

diff --git a/include/efi_api.h b/include/efi_api.h
index 8efc8dfab8..b2838125d7 100644
--- a/include/efi_api.h
+++ b/include/efi_api.h
@@ -609,4 +609,26 @@ struct efi_pxe {
 	struct efi_pxe_mode *mode;
 };
 
+#define EFI_DRIVER_BINDING_PROTOCOL_GUID \
+	EFI_GUID(0x18a031ab, 0xb443, 0x4d1a,\
+		 0xa5, 0xc0, 0x0c, 0x09, 0x26, 0x1e, 0x9f, 0x71)
+struct efi_driver_binding_protocol {
+	efi_status_t (EFIAPI * supported)(
+			struct efi_driver_binding_protocol *this,
+			efi_handle_t controller_handle,
+			struct efi_device_path *remaining_device_path);
+	efi_status_t (EFIAPI * start)(
+			struct efi_driver_binding_protocol *this,
+			efi_handle_t controller_handle,
+			struct efi_device_path *remaining_device_path);
+	efi_status_t (EFIAPI * stop)(
+			struct efi_driver_binding_protocol *this,
+			efi_handle_t controller_handle,
+			UINTN number_of_children,
+			efi_handle_t child_handle_buffer);
+	u32 version;
+	efi_handle_t image_handle;
+	efi_handle_t driver_binding_handle;
+};
+
 #endif
diff --git a/include/efi_loader.h b/include/efi_loader.h
index 9c68246c7c..f9f33e1d01 100644
--- a/include/efi_loader.h
+++ b/include/efi_loader.h
@@ -74,6 +74,7 @@ extern const struct efi_device_path_to_text_protocol efi_device_path_to_text;
 
 extern const efi_guid_t efi_guid_console_control;
 extern const efi_guid_t efi_guid_device_path;
+extern const efi_guid_t efi_guid_driver_binding_protocol;
 extern const efi_guid_t efi_guid_loaded_image;
 extern const efi_guid_t efi_guid_device_path_to_text_protocol;
 
diff --git a/lib/efi_loader/efi_boottime.c b/lib/efi_loader/efi_boottime.c
index 5a73ea5cd0..1069da7d79 100644
--- a/lib/efi_loader/efi_boottime.c
+++ b/lib/efi_loader/efi_boottime.c
@@ -18,6 +18,14 @@
 
 DECLARE_GLOBAL_DATA_PTR;
 
+static efi_status_t EFIAPI efi_locate_protocol(const efi_guid_t *protocol,
+					       void *registration,
+					       void **protocol_interface);
+static efi_status_t EFIAPI efi_locate_handle_buffer(
+			enum efi_locate_search_type search_type,
+			const efi_guid_t *protocol, void *search_key,
+			unsigned long *no_handles, efi_handle_t **buffer);
+
 /* This list contains all the EFI objects our payload has access to */
 LIST_HEAD(efi_obj_list);
 
@@ -49,6 +57,9 @@ static struct efi_configuration_table __efi_runtime_data efi_conf_table[2];
 static volatile void *efi_gd, *app_gd;
 #endif
 
+const efi_guid_t efi_guid_driver_binding_protocol =
+			EFI_DRIVER_BINDING_PROTOCOL_GUID;
+
 static int entry_count;
 static int nesting_level;
 
@@ -920,15 +931,121 @@ static efi_status_t EFIAPI efi_set_watchdog_timer(unsigned long timeout,
 	return efi_unsupported(__func__);
 }
 
+static efi_status_t efi_bind_controller(
+			efi_handle_t controller_handle,
+			efi_handle_t driver_image_handle,
+			struct efi_device_path *remain_device_path)
+{
+	struct efi_driver_binding_protocol *binding_protocol;
+	efi_status_t r;
+
+	r = EFI_CALL(efi_open_protocol(driver_image_handle,
+				       &efi_guid_driver_binding_protocol,
+				       (void **)&binding_protocol,
+				       driver_image_handle, NULL,
+				       EFI_OPEN_PROTOCOL_GET_PROTOCOL));
+	if (r != EFI_SUCCESS)
+		return r;
+	r = EFI_CALL(binding_protocol->supported(binding_protocol,
+						 controller_handle,
+						 remain_device_path));
+	if (r == EFI_SUCCESS)
+		r = EFI_CALL(binding_protocol->start(binding_protocol,
+						     controller_handle,
+						     remain_device_path));
+	EFI_CALL(efi_close_protocol(driver_image_handle,
+				    &efi_guid_driver_binding_protocol,
+				    driver_image_handle, NULL));
+	return r;
+}
+
+static efi_status_t efi_connect_single_controller(
+			efi_handle_t controller_handle,
+			efi_handle_t *driver_image_handle,
+			struct efi_device_path *remain_device_path)
+{
+	efi_handle_t *buffer;
+	unsigned long count;
+	size_t i;
+	efi_status_t r;
+	size_t connected = 0;
+
+	/* Get buffer with all handles with driver binding protocol */
+	r = EFI_CALL(efi_locate_handle_buffer(by_protocol,
+					      &efi_guid_driver_binding_protocol,
+					      NULL, &count, &buffer));
+	if (r != EFI_SUCCESS)
+		return r;
+
+	/*  Context Override */
+	if (driver_image_handle) {
+		for (; *driver_image_handle; ++driver_image_handle) {
+			for (i = 0; i < count; ++i) {
+				if (buffer[i] == *driver_image_handle) {
+					buffer[i] = NULL;
+					r = efi_bind_controller(
+							controller_handle,
+							*driver_image_handle,
+							remain_device_path);
+					if (r == EFI_SUCCESS)
+						++connected;
+				}
+			}
+		}
+	}
+
+	/*
+	 * Some overrides are not yet implemented:
+	 * Platform Driver Override
+	 * Driver Family Override Search
+	 * Driver Family Override Search
+	 * Bus Specific Driver Override
+	 */
+
+	/* Driver Binding Search */
+	for (i = 0; i < count; ++i) {
+		if (buffer[i]) {
+			r = efi_bind_controller(controller_handle,
+						buffer[i],
+						remain_device_path);
+			if (r == EFI_SUCCESS)
+				++connected;
+		}
+	}
+
+	efi_free_pool(buffer);
+	if (!connected)
+		return EFI_NOT_FOUND;
+	return EFI_SUCCESS;
+}
+
 static efi_status_t EFIAPI efi_connect_controller(
 			efi_handle_t controller_handle,
 			efi_handle_t *driver_image_handle,
 			struct efi_device_path *remain_device_path,
 			bool recursive)
 {
+	efi_status_t r;
+
 	EFI_ENTRY("%p, %p, %p, %d", controller_handle, driver_image_handle,
 		  remain_device_path, recursive);
-	return EFI_EXIT(EFI_NOT_FOUND);
+
+	if (!controller_handle) {
+		r = EFI_INVALID_PARAMETER;
+		goto out;
+	}
+
+	if (recursive) {
+		r = EFI_UNSUPPORTED;
+		goto out;
+	}
+
+	r = efi_connect_single_controller(controller_handle,
+					  driver_image_handle,
+					  remain_device_path);
+
+out:
+	return EFI_EXIT(r);
 }
 
 static efi_status_t EFIAPI efi_disconnect_controller(void *controller_handle,
-- 
2.14.1

  parent reply	other threads:[~2017-08-26 22:53 UTC|newest]

Thread overview: 89+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-08-26 22:51 [U-Boot] [PATCH 00/23] efi_loader implement missing functions Heinrich Schuchardt
2017-08-26 22:51 ` [U-Boot] [PATCH 01/23] efi_loader: allow return value in EFI_CALL Heinrich Schuchardt
2017-08-31 12:51   ` Simon Glass
2017-08-31 13:58     ` Alexander Graf
2017-09-04  6:51       ` Simon Glass
2017-08-26 22:51 ` [U-Boot] [PATCH 02/23] efi_loader: notify when ExitBootServices is invoked Heinrich Schuchardt
2017-08-31 12:51   ` Simon Glass
2017-08-26 22:51 ` [U-Boot] [PATCH 03/23] efi_loader: support 16 protocols per efi_object Heinrich Schuchardt
2017-08-31 12:51   ` Simon Glass
2017-08-31 14:01   ` Alexander Graf
2017-09-01  1:45     ` Heinrich Schuchardt
2017-09-01  8:15       ` Alexander Graf
2017-09-02 18:14     ` Rob Clark
2017-09-02 22:26       ` Alexander Graf
2017-08-26 22:51 ` [U-Boot] [PATCH 04/23] efi_loader: rework efi_locate_handle Heinrich Schuchardt
2017-08-31 12:51   ` Simon Glass
2017-08-26 22:51 ` [U-Boot] [PATCH 05/23] efi_loader: rework efi_search_obj Heinrich Schuchardt
2017-08-31 12:51   ` Simon Glass
2017-08-26 22:51 ` [U-Boot] [PATCH 06/23] efi_loader: new function efi_search_protocol Heinrich Schuchardt
2017-08-31 12:51   ` Simon Glass
2017-08-26 22:51 ` [U-Boot] [PATCH 07/23] efi_loader: simplify efi_install_protocol_interface Heinrich Schuchardt
2017-08-31 12:51   ` Simon Glass
2017-08-26 22:51 ` [U-Boot] [PATCH 08/23] efi_loader: allow creating new handles Heinrich Schuchardt
2017-08-31 12:51   ` Simon Glass
2017-09-07 19:20     ` Rob Clark
2017-08-26 22:51 ` [U-Boot] [PATCH 09/23] efi_loader: simplify efi_uninstall_protocol_interface Heinrich Schuchardt
2017-08-31 12:51   ` Simon Glass
2017-08-26 22:53 ` [U-Boot] [PATCH 10/23] efi_loader: open_info in OpenProtocol Heinrich Schuchardt
2017-08-26 22:53   ` [U-Boot] [PATCH 11/23] efi_loader: open_info in CloseProtocol Heinrich Schuchardt
2017-08-31 12:51     ` Simon Glass
2017-08-26 22:53   ` [U-Boot] [PATCH 12/23] efi_loader: implement OpenProtocolInformation Heinrich Schuchardt
2017-08-31 12:51     ` Simon Glass
2017-08-31 17:39       ` Heinrich Schuchardt
2017-08-26 22:53   ` [U-Boot] [PATCH 13/23] efi_loader: non-static efi_open_protocol, efi_close_protocol Heinrich Schuchardt
2017-08-31 12:51     ` Simon Glass
2017-08-26 22:53   ` [U-Boot] [PATCH 14/23] efi_loader: pass GUIDs as const efi_guid_t * Heinrich Schuchardt
2017-08-31 12:51     ` Simon Glass
2017-08-26 22:53   ` Heinrich Schuchardt [this message]
2017-08-31 12:52     ` [U-Boot] [PATCH 15/23] efi_loader: implement ConnectController Simon Glass
2017-09-15  6:48       ` Heinrich Schuchardt
2017-09-20 13:49         ` Simon Glass
2017-09-15  7:45       ` [U-Boot] [PATCH 1/1] efi_loader: provide comment for protocol GUIDs Heinrich Schuchardt
2017-09-25  2:11         ` Simon Glass
2017-08-26 22:53   ` [U-Boot] [PATCH 16/23] efi_loader: implement DisconnectController Heinrich Schuchardt
2017-08-31 12:52     ` Simon Glass
2017-09-15  6:35       ` Heinrich Schuchardt
2017-09-20 13:49         ` Simon Glass
2017-09-20 14:23           ` Rob Clark
2017-09-21  4:58             ` Simon Glass
2017-08-26 22:53   ` [U-Boot] [PATCH 17/23] efi_loader: efi_net: hwaddr_size = 6 Heinrich Schuchardt
2017-08-31 12:52     ` Simon Glass
2017-08-26 22:53   ` [U-Boot] [PATCH 18/23] efi_net: return EFI_UNSUPPORTED where appropriate Heinrich Schuchardt
2017-08-31 12:52     ` Simon Glass
2017-08-26 22:53   ` [U-Boot] [PATCH 19/23] efi_loader: correct bits of receive_filters bit mask Heinrich Schuchardt
2017-08-31 12:52     ` Simon Glass
2017-08-31 12:51   ` [U-Boot] [PATCH 10/23] efi_loader: open_info in OpenProtocol Simon Glass
2017-08-26 22:54 ` [U-Boot] [PATCH 20/23] efi_loader: use events for efi_net_receive Heinrich Schuchardt
2017-08-26 22:54   ` [U-Boot] [PATCH 21/23] efi_loader: fix efi_net_get_status Heinrich Schuchardt
2017-08-31 12:52     ` Simon Glass
2017-08-26 22:54   ` [U-Boot] [PATCH 22/23] efi_loader: set parent handle in efi_load_image Heinrich Schuchardt
2017-08-31 12:52     ` Simon Glass
2017-08-26 22:54   ` [U-Boot] [PATCH 23/23] efi_loader: implement SetWatchdogTimer Heinrich Schuchardt
2017-08-31 12:52     ` Simon Glass
2017-08-31 12:52   ` [U-Boot] [PATCH 20/23] efi_loader: use events for efi_net_receive Simon Glass
2017-08-27 20:10 ` [U-Boot] [PATCH 00/23] efi_loader implement missing functions Simon Glass
2017-08-29 10:52   ` Heinrich Schuchardt
2017-08-29 11:45     ` Alexander Graf
2017-08-29 12:17       ` Rob Clark
2017-08-29 12:26         ` Alexander Graf
2017-08-29 12:57           ` Leif Lindholm
2017-08-29 14:16             ` Rob Clark
2017-08-29 17:11               ` Heinrich Schuchardt
2017-08-29 20:16               ` Simon Glass
2017-08-29 20:38                 ` Alexander Graf
2017-08-29 22:03                   ` Heinrich Schuchardt
2017-08-30  7:59                     ` Leif Lindholm
2017-08-31 14:45                       ` Leif Lindholm
2017-09-01 12:54                         ` Rob Clark
2017-09-01 13:05                         ` Rob Clark
2017-08-30  9:36                     ` Simon Glass
2017-09-01 14:45                 ` Tom Rini
2017-09-05  8:55                   ` Simon Glass
2017-09-05 23:48                     ` Rob Clark
2017-09-06  4:18                       ` Heinrich Schuchardt
2017-09-06 10:54                         ` Rob Clark
2017-08-29 15:59             ` Heinrich Schuchardt
2017-08-29 16:06               ` Leif Lindholm
2017-08-29 16:13                 ` Alexander Graf
2017-08-29 12:22     ` Simon Glass

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=20170826225328.7550-6-xypron.glpk@gmx.de \
    --to=xypron.glpk@gmx.de \
    --cc=u-boot@lists.denx.de \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.