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 10/23] efi_loader: open_info in OpenProtocol
Date: Sun, 27 Aug 2017 00:53:19 +0200	[thread overview]
Message-ID: <20170826225328.7550-1-xypron.glpk@gmx.de> (raw)
In-Reply-To: <20170826225110.7381-1-xypron.glpk@gmx.de>

efi_open_protocol and close_protocol have to keep track of
opened protocols.

So we add an array open_info to each protocol of each handle.

OpenProtocol has enter the agent and controller handle
information into this array.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
---
 include/efi_loader.h          |   1 +
 lib/efi_loader/efi_boottime.c | 130 +++++++++++++++++++++++++++++++-----------
 2 files changed, 99 insertions(+), 32 deletions(-)

diff --git a/include/efi_loader.h b/include/efi_loader.h
index 193fca24ce..2c3360534b 100644
--- a/include/efi_loader.h
+++ b/include/efi_loader.h
@@ -87,6 +87,7 @@ extern unsigned int __efi_runtime_rel_start, __efi_runtime_rel_stop;
 struct efi_handler {
 	const efi_guid_t *guid;
 	void *protocol_interface;
+	struct efi_open_protocol_info_entry open_info[4];
 };
 
 /*
diff --git a/lib/efi_loader/efi_boottime.c b/lib/efi_loader/efi_boottime.c
index a483b827cd..294bc1f138 100644
--- a/lib/efi_loader/efi_boottime.c
+++ b/lib/efi_loader/efi_boottime.c
@@ -1152,24 +1152,111 @@ static void EFIAPI efi_set_mem(void *buffer, unsigned long size, uint8_t value)
 	memset(buffer, value, size);
 }
 
+static efi_status_t efi_protocol_open(
+			struct efi_handler *protocol,
+			void **protocol_interface, void *agent_handle,
+			void *controller_handle, uint32_t attributes)
+{
+	bool opened_exclusive = false;
+	bool opened_by_driver = false;
+	int i;
+	struct efi_open_protocol_info_entry *open_info;
+	struct efi_open_protocol_info_entry *match = NULL;
+
+	if (attributes !=
+	    EFI_OPEN_PROTOCOL_TEST_PROTOCOL) {
+		*protocol_interface = NULL;
+	}
+
+	for (i = 0; i < ARRAY_SIZE(protocol->open_info); ++i) {
+		open_info = &protocol->open_info[i];
+
+		if (!open_info->open_count)
+			continue;
+		if (open_info->agent_handle == agent_handle) {
+			if ((attributes & EFI_OPEN_PROTOCOL_BY_DRIVER) &&
+			    (open_info->attributes == attributes))
+				return EFI_ALREADY_STARTED;
+			if (open_info->controller_handle == controller_handle)
+				match = open_info;
+		}
+		if (open_info->attributes & EFI_OPEN_PROTOCOL_EXCLUSIVE)
+			opened_exclusive = true;
+	}
+
+	if (attributes &
+	    (EFI_OPEN_PROTOCOL_EXCLUSIVE | EFI_OPEN_PROTOCOL_BY_DRIVER) &&
+	    opened_exclusive)
+		return EFI_ACCESS_DENIED;
+
+	if (attributes & EFI_OPEN_PROTOCOL_EXCLUSIVE) {
+		for (i = 0; i < ARRAY_SIZE(protocol->open_info); ++i) {
+			open_info = &protocol->open_info[i];
+
+			if (!open_info->open_count)
+				continue;
+			if (open_info->attributes ==
+					EFI_OPEN_PROTOCOL_BY_DRIVER)
+				EFI_CALL(efi_disconnect_controller(
+						open_info->controller_handle,
+						open_info->agent_handle,
+						NULL));
+		}
+		opened_by_driver = false;
+		for (i = 0; i < ARRAY_SIZE(protocol->open_info); ++i) {
+			open_info = &protocol->open_info[i];
+
+			if (!open_info->open_count)
+				continue;
+			if (open_info->attributes & EFI_OPEN_PROTOCOL_BY_DRIVER)
+				opened_by_driver = true;
+		}
+		if (opened_by_driver)
+			return EFI_ACCESS_DENIED;
+		if (match && !match->open_count)
+			match = NULL;
+	}
+
+	/*
+	 * Find an empty slot.
+	 */
+	if (!match) {
+		for (i = 0; i < ARRAY_SIZE(protocol->open_info); ++i) {
+			open_info = &protocol->open_info[i];
+
+			if (!open_info->open_count) {
+				match = open_info;
+				break;
+			}
+		}
+	}
+	if (!match)
+		return EFI_OUT_OF_RESOURCES;
+
+	match->agent_handle = agent_handle;
+	match->controller_handle = controller_handle;
+	match->attributes = attributes;
+	match->open_count++;
+	*protocol_interface = protocol->protocol_interface;
+
+	return EFI_SUCCESS;
+}
+
 static efi_status_t EFIAPI efi_open_protocol(
 			void *handle, efi_guid_t *protocol,
 			void **protocol_interface, void *agent_handle,
 			void *controller_handle, uint32_t attributes)
 {
-	struct list_head *lhandle;
-	int i;
+	struct efi_handler *handler;
 	efi_status_t r = EFI_INVALID_PARAMETER;
 
 	EFI_ENTRY("%p, %p, %p, %p, %p, 0x%x", handle, protocol,
 		  protocol_interface, agent_handle, controller_handle,
 		  attributes);
 
-	if (!handle || !protocol ||
-	    (!protocol_interface && attributes !=
-	     EFI_OPEN_PROTOCOL_TEST_PROTOCOL)) {
+	if (!protocol_interface && attributes !=
+	    EFI_OPEN_PROTOCOL_TEST_PROTOCOL)
 		goto out;
-	}
 
 	switch (attributes) {
 	case EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL:
@@ -1191,33 +1278,12 @@ static efi_status_t EFIAPI efi_open_protocol(
 		goto out;
 	}
 
-	list_for_each(lhandle, &efi_obj_list) {
-		struct efi_object *efiobj;
-		efiobj = list_entry(lhandle, struct efi_object, link);
-
-		if (efiobj->handle != handle)
-			continue;
-
-		for (i = 0; i < ARRAY_SIZE(efiobj->protocols); i++) {
-			struct efi_handler *handler = &efiobj->protocols[i];
-			const efi_guid_t *hprotocol = handler->guid;
-			if (!hprotocol)
-				continue;
-			if (!guidcmp(hprotocol, protocol)) {
-				if (attributes !=
-				    EFI_OPEN_PROTOCOL_TEST_PROTOCOL) {
-					*protocol_interface =
-						handler->protocol_interface;
-				}
-				r = EFI_SUCCESS;
-				goto out;
-			}
-		}
-		goto unsupported;
-	}
+	r = efi_search_protocol(handle, protocol, &handler);
+	if (r != EFI_SUCCESS)
+		goto out;
 
-unsupported:
-	r = EFI_UNSUPPORTED;
+	r = efi_protocol_open(handler, protocol_interface, agent_handle,
+			      controller_handle, attributes);
 out:
 	return EFI_EXIT(r);
 }
-- 
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 ` Heinrich Schuchardt [this message]
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   ` [U-Boot] [PATCH 15/23] efi_loader: implement ConnectController Heinrich Schuchardt
2017-08-31 12:52     ` 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-1-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.