]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
efi_driver: add init function to EFI block driver
authorHeinrich Schuchardt <heinrich.schuchardt@canonical.com>
Wed, 5 Oct 2022 09:28:47 +0000 (11:28 +0200)
committerHeinrich Schuchardt <heinrich.schuchardt@canonical.com>
Thu, 6 Oct 2022 20:54:58 +0000 (22:54 +0200)
For handling added and removed block devices we need to register events
which has to be done when the driver is installed.

This patch only creates an empty init function that will be filled with
code later on. The function needs to be called before any EFI block devices
are used. Move the efi_driver_init() call to early init.

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
include/efi_driver.h
lib/efi_driver/efi_block_device.c
lib/efi_driver/efi_uclass.c
lib/efi_loader/efi_setup.c

index 71e0d3194ea82a7bcf0d5c35b32b8fed9ca46f98..63a95e4cf800033388057aae44ce4fc7890c1c4f 100644 (file)
@@ -32,12 +32,15 @@ struct efi_driver_binding_extended_protocol {
  *                     EFI_DRIVER_BINDING_PROTOCOL.
  * @child_protocol:    Protocol supported by the child handles generated by
  *                     the EFI driver.
+ * @init:              Function called by the EFI uclass after installing the
+ *                     driver binding protocol.
  * @bind:              Function called by the EFI uclass to attach the
  *                     driver to EFI driver to a handle.
  */
 struct efi_driver_ops {
        const efi_guid_t *protocol;
        const efi_guid_t *child_protocol;
+       efi_status_t (*init)(struct efi_driver_binding_extended_protocol *this);
        efi_status_t (*bind)(struct efi_driver_binding_extended_protocol *this,
                             efi_handle_t handle, void *interface);
 };
index f440067f702bedeeecc255142c031f79b8b95420..bd3688848ba8379a5409a74730ae8b0fa09bc971 100644 (file)
@@ -197,6 +197,17 @@ static efi_status_t efi_bl_bind(
        return ret;
 }
 
+/**
+ * efi_bl_init() - initialize block device driver
+ *
+ * @this:      extended driver binding protocol
+ */
+static efi_status_t
+efi_bl_init(struct efi_driver_binding_extended_protocol *this)
+{
+       return EFI_SUCCESS;
+}
+
 /* Block device driver operators */
 static const struct blk_ops efi_blk_ops = {
        .read   = efi_bl_read,
@@ -215,6 +226,7 @@ U_BOOT_DRIVER(efi_blk) = {
 static const struct efi_driver_ops driver_ops = {
        .protocol       = &efi_block_io_guid,
        .child_protocol = &efi_block_io_guid,
+       .init           = efi_bl_init,
        .bind           = efi_bl_bind,
 };
 
index 0a16c594e3ae937db00741b8eba595b00d433ca6..2193f8493fd6c02409507bbe0c08cf1e257b9272 100644 (file)
@@ -284,7 +284,7 @@ static efi_status_t efi_add_driver(struct driver *drv)
        bp->bp.start = efi_uc_start;
        bp->bp.stop = efi_uc_stop;
        bp->bp.version = 0xffffffff;
-       bp->ops = drv->ops;
+       bp->ops = ops;
 
        ret = efi_create_handle(&bp->bp.driver_binding_handle);
        if (ret != EFI_SUCCESS) {
@@ -294,13 +294,20 @@ static efi_status_t efi_add_driver(struct driver *drv)
        bp->bp.image_handle = bp->bp.driver_binding_handle;
        ret = efi_add_protocol(bp->bp.driver_binding_handle,
                               &efi_guid_driver_binding_protocol, bp);
-       if (ret != EFI_SUCCESS) {
-               efi_delete_handle(bp->bp.driver_binding_handle);
-               free(bp);
-               goto out;
+       if (ret != EFI_SUCCESS)
+               goto err;
+       if (ops->init) {
+               ret = ops->init(bp);
+               if (ret != EFI_SUCCESS)
+                       goto err;
        }
 out:
        return ret;
+
+err:
+       efi_delete_handle(bp->bp.driver_binding_handle);
+       free(bp);
+       return ret;
 }
 
 /**
index c633fcd91e35e8d7bca79ecf1c5d4ed45f4a4d9d..113d5d5d56af7f381d52024556f594a1c67e7229 100644 (file)
@@ -198,6 +198,11 @@ static efi_status_t __efi_init_early(void)
        if (ret != EFI_SUCCESS)
                goto out;
 
+       /* Initialize EFI driver uclass */
+       ret = efi_driver_init();
+       if (ret != EFI_SUCCESS)
+               goto out;
+
        ret = efi_disk_init();
 out:
        return ret;
@@ -319,11 +324,6 @@ efi_status_t efi_init_obj_list(void)
        if (ret != EFI_SUCCESS)
                goto out;
 
-       /* Initialize EFI driver uclass */
-       ret = efi_driver_init();
-       if (ret != EFI_SUCCESS)
-               goto out;
-
        if (IS_ENABLED(CONFIG_EFI_HAVE_CAPSULE_SUPPORT)) {
                ret = efi_load_capsule_drivers();
                if (ret != EFI_SUCCESS)