]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
efi_loader: implement InstallProtocolInterface
authorxypron.glpk@gmx.de <xypron.glpk@gmx.de>
Tue, 11 Jul 2017 20:06:16 +0000 (22:06 +0200)
committerAlexander Graf <agraf@suse.de>
Wed, 19 Jul 2017 12:14:38 +0000 (14:14 +0200)
efi_install_protocol_interface up to now only returned an error code.

The patch implements the UEFI specification for InstallProtocolInterface
with the exception that it will not create new handles.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Signed-off-by: Alexander Graf <agraf@suse.de>
include/efi_api.h
lib/efi_loader/efi_boottime.c

index f071b36b53623e6e60baf515fd1ff9daa6b2cfdd..42cd47ff08052548e41b3b0f79aa409779f44a41 100644 (file)
@@ -58,7 +58,7 @@ struct efi_boot_services {
        efi_status_t (EFIAPI *signal_event)(void *event);
        efi_status_t (EFIAPI *close_event)(void *event);
        efi_status_t (EFIAPI *check_event)(void *event);
-
+#define EFI_NATIVE_INTERFACE   0x00000000
        efi_status_t (EFIAPI *install_protocol_interface)(
                        void **handle, efi_guid_t *protocol,
                        int protocol_interface_type, void *protocol_interface);
index 22e9e6001d1b6efc07e162bf6fadb619645a9939..a6325ba9d87309f2194c1eecff442149c2d7982a 100644 (file)
@@ -303,10 +303,62 @@ static efi_status_t EFIAPI efi_install_protocol_interface(void **handle,
                        efi_guid_t *protocol, int protocol_interface_type,
                        void *protocol_interface)
 {
+       struct list_head *lhandle;
+       int i;
+       efi_status_t r;
+
        EFI_ENTRY("%p, %p, %d, %p", handle, protocol, protocol_interface_type,
                  protocol_interface);
-       return EFI_EXIT(EFI_OUT_OF_RESOURCES);
+
+       if (!handle || !protocol ||
+           protocol_interface_type != EFI_NATIVE_INTERFACE) {
+               r = EFI_INVALID_PARAMETER;
+               goto out;
+       }
+
+       /* Create new handle if requested. */
+       if (!*handle) {
+               r = EFI_OUT_OF_RESOURCES;
+               goto out;
+       }
+       /* Find object. */
+       list_for_each(lhandle, &efi_obj_list) {
+               struct efi_object *efiobj;
+               efiobj = list_entry(lhandle, struct efi_object, link);
+
+               if (efiobj->handle != *handle)
+                       continue;
+               /* Check if protocol is already installed on the handle. */
+               for (i = 0; i < ARRAY_SIZE(efiobj->protocols); i++) {
+                       struct efi_handler *handler = &efiobj->protocols[i];
+
+                       if (!handler->guid)
+                               continue;
+                       if (!guidcmp(handler->guid, protocol)) {
+                               r = EFI_INVALID_PARAMETER;
+                               goto out;
+                       }
+               }
+               /* Install protocol in first empty slot. */
+               for (i = 0; i < ARRAY_SIZE(efiobj->protocols); i++) {
+                       struct efi_handler *handler = &efiobj->protocols[i];
+
+                       if (handler->guid)
+                               continue;
+
+                       handler->guid = protocol;
+                       handler->protocol_interface = protocol_interface;
+                       r = EFI_SUCCESS;
+                       goto out;
+               }
+               r = EFI_OUT_OF_RESOURCES;
+               goto out;
+       }
+       r = EFI_INVALID_PARAMETER;
+out:
+       return EFI_EXIT(r);
 }
+
 static efi_status_t EFIAPI efi_reinstall_protocol_interface(void *handle,
                        efi_guid_t *protocol, void *old_interface,
                        void *new_interface)