Commit 05ef48a2484be4d1d232534b919c8e9b4bcfaecd

Authored by Heinrich Schuchardt
Committed by Alexander Graf
1 parent ba45c9e4e1

efi_driver: EFI block driver

This patch provides
* a uclass for EFI drivers
* a EFI driver for block devices

For each EFI driver the uclass
* creates a handle
* adds the driver binding protocol

The uclass provides the bind, start, and stop entry points for the driver
binding protocol.

In bind() and stop() it checks if the controller implements the protocol
supported by the EFI driver. In the start() function it calls the bind()
function of the EFI driver. In the stop() function it destroys the child
controllers.

The EFI block driver binds to controllers implementing the block io
protocol.

When the bind function of the EFI block driver is called it creates a
new U-Boot block device. It installs child handles for all partitions and
installs the simple file protocol on these.

The read and write functions of the EFI block driver delegate calls to the
controller that it is bound to.

A usage example is as following:

U-Boot loads the iPXE snp.efi executable. iPXE connects an iSCSI drive and
exposes a handle with the block IO protocol. It calls ConnectController.

Now the EFI block driver installs the partitions with the simple file
protocol.

iPXE uses the simple file protocol to load Grub or the Linux Kernel.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
[agraf: add comment on calloc len]
Signed-off-by: Alexander Graf <agraf@suse.de>

Showing 11 changed files with 595 additions and 1 deletions Side-by-side Diff

... ... @@ -32,6 +32,9 @@
32 32 {
33 33 efi_obj_list_initalized = 1;
34 34  
  35 + /* Initialize EFI driver uclass */
  36 + efi_driver_init();
  37 +
35 38 efi_console_register();
36 39 #ifdef CONFIG_PARTITIONS
37 40 efi_disk_register();
drivers/block/blk-uclass.c
... ... @@ -24,6 +24,7 @@
24 24 [IF_TYPE_HOST] = "host",
25 25 [IF_TYPE_SYSTEMACE] = "ace",
26 26 [IF_TYPE_NVME] = "nvme",
  27 + [IF_TYPE_EFI] = "efi",
27 28 };
28 29  
29 30 static enum uclass_id if_type_uclass_id[IF_TYPE_COUNT] = {
30 31  
... ... @@ -36,8 +37,9 @@
36 37 [IF_TYPE_SD] = UCLASS_INVALID,
37 38 [IF_TYPE_SATA] = UCLASS_AHCI,
38 39 [IF_TYPE_HOST] = UCLASS_ROOT,
39   - [IF_TYPE_NVME] = UCLASS_NVME,
40 40 [IF_TYPE_SYSTEMACE] = UCLASS_INVALID,
  41 + [IF_TYPE_NVME] = UCLASS_NVME,
  42 + [IF_TYPE_EFI] = UCLASS_EFI,
41 43 };
42 44  
43 45 static enum if_type if_typename_to_iftype(const char *if_typename)
... ... @@ -34,6 +34,7 @@
34 34 IF_TYPE_HOST,
35 35 IF_TYPE_SYSTEMACE,
36 36 IF_TYPE_NVME,
  37 + IF_TYPE_EFI,
37 38  
38 39 IF_TYPE_COUNT, /* Number of interface types */
39 40 };
include/config_fallbacks.h
... ... @@ -52,6 +52,7 @@
52 52 defined(CONFIG_MMC) || \
53 53 defined(CONFIG_NVME) || \
54 54 defined(CONFIG_SYSTEMACE) || \
  55 + (defined(CONFIG_EFI_LOADER) && !defined(CONFIG_SPL_BUILD)) || \
55 56 defined(CONFIG_SANDBOX)
56 57 #define HAVE_BLOCK_DEVICE
57 58 #endif
include/dm/uclass-id.h
... ... @@ -34,6 +34,7 @@
34 34 UCLASS_CROS_EC, /* Chrome OS EC */
35 35 UCLASS_DISPLAY, /* Display (e.g. DisplayPort, HDMI) */
36 36 UCLASS_DMA, /* Direct Memory Access */
  37 + UCLASS_EFI, /* EFI managed devices */
37 38 UCLASS_ETH, /* Ethernet device */
38 39 UCLASS_GPIO, /* Bank of general-purpose I/O pins */
39 40 UCLASS_FIRMWARE, /* Firmware */
include/efi_driver.h
  1 +/*
  2 + * EFI application loader
  3 + *
  4 + * Copyright (c) 2017 Heinrich Schuchardt
  5 + *
  6 + * SPDX-License-Identifier: GPL-2.0+
  7 + */
  8 +
  9 +#ifndef _EFI_DRIVER_H
  10 +#define _EFI_DRIVER_H 1
  11 +
  12 +#include <common.h>
  13 +#include <dm.h>
  14 +#include <efi_loader.h>
  15 +
  16 +struct efi_driver_ops {
  17 + const efi_guid_t *protocol;
  18 + const efi_guid_t *child_protocol;
  19 + int (*bind)(efi_handle_t handle, void *interface);
  20 +};
  21 +
  22 +/*
  23 + * This structure adds internal fields to the driver binding protocol.
  24 + */
  25 +struct efi_driver_binding_extended_protocol {
  26 + struct efi_driver_binding_protocol bp;
  27 + const struct efi_driver_ops *ops;
  28 +};
  29 +
  30 +#endif /* _EFI_DRIVER_H */
include/efi_loader.h
... ... @@ -271,6 +271,8 @@
271 271 /* Adds a range into the EFI memory map */
272 272 uint64_t efi_add_memory_map(uint64_t start, uint64_t pages, int memory_type,
273 273 bool overlap_only_ram);
  274 +/* Called by board init to initialize the EFI drivers */
  275 +int efi_driver_init(void);
274 276 /* Called by board init to initialize the EFI memory map */
275 277 int efi_memory_init(void);
276 278 /* Adds new or overrides configuration table entry to the system table */
... ... @@ -8,6 +8,7 @@
8 8 ifndef CONFIG_SPL_BUILD
9 9  
10 10 obj-$(CONFIG_EFI) += efi/
  11 +obj-$(CONFIG_EFI_LOADER) += efi_driver/
11 12 obj-$(CONFIG_EFI_LOADER) += efi_loader/
12 13 obj-$(CONFIG_EFI_LOADER) += efi_selftest/
13 14 obj-$(CONFIG_LZMA) += lzma/
lib/efi_driver/Makefile
  1 +#
  2 +# (C) Copyright 2017 Heinrich Schuchardt
  3 +#
  4 +# SPDX-License-Identifier: GPL-2.0+
  5 +#
  6 +
  7 +# This file only gets included with CONFIG_EFI_LOADER set, so all
  8 +# object inclusion implicitly depends on it
  9 +
  10 +obj-y += efi_uclass.o
  11 +ifeq ($(CONFIG_BLK)$(CONFIG_PARTITIONS),yy)
  12 +obj-y += efi_block_device.o
  13 +endif
lib/efi_driver/efi_block_device.c
  1 +/*
  2 + * EFI block driver
  3 + *
  4 + * Copyright (c) 2017 Heinrich Schuchardt
  5 + *
  6 + * SPDX-License-Identifier: GPL-2.0+
  7 + *
  8 + * The EFI uclass creates a handle for this driver and installs the
  9 + * driver binding protocol on it.
  10 + *
  11 + * The EFI block driver binds to controllers implementing the block io
  12 + * protocol.
  13 + *
  14 + * When the bind function of the EFI block driver is called it creates a
  15 + * new U-Boot block device. It installs child handles for all partitions and
  16 + * installs the simple file protocol on these.
  17 + *
  18 + * The read and write functions of the EFI block driver delegate calls to the
  19 + * controller that it is bound to.
  20 + *
  21 + * A usage example is as following:
  22 + *
  23 + * U-Boot loads the iPXE snp.efi executable. iPXE connects an iSCSI drive and
  24 + * exposes a handle with the block IO protocol. It calls ConnectController.
  25 + *
  26 + * Now the EFI block driver installs the partitions with the simple file
  27 + * protocol.
  28 + *
  29 + * iPXE uses the simple file protocol to load Grub or the Linux Kernel.
  30 + */
  31 +
  32 +#include <efi_driver.h>
  33 +#include <dm/device-internal.h>
  34 +#include <dm/root.h>
  35 +
  36 +/*
  37 + * EFI attributes of the udevice handled by this driver.
  38 + *
  39 + * handle handle of the controller on which this driver is installed
  40 + * io block io protocol proxied by this driver
  41 + */
  42 +struct efi_blk_priv {
  43 + efi_handle_t handle;
  44 + struct efi_block_io *io;
  45 +};
  46 +
  47 +/*
  48 + * Read from block device
  49 + *
  50 + * @dev device
  51 + * @blknr first block to be read
  52 + * @blkcnt number of blocks to read
  53 + * @buffer output buffer
  54 + * @return number of blocks transferred
  55 + */
  56 +static ulong efi_bl_read(struct udevice *dev, lbaint_t blknr, lbaint_t blkcnt,
  57 + void *buffer)
  58 +{
  59 + struct efi_blk_priv *priv = dev->priv;
  60 + struct efi_block_io *io = priv->io;
  61 + efi_status_t ret;
  62 +
  63 + EFI_PRINT("%s: read '%s', from block " LBAFU ", " LBAFU " blocks\n",
  64 + __func__, dev->name, blknr, blkcnt);
  65 + ret = EFI_CALL(io->read_blocks(
  66 + io, io->media->media_id, (u64)blknr,
  67 + (efi_uintn_t)blkcnt *
  68 + (efi_uintn_t)io->media->block_size, buffer));
  69 + EFI_PRINT("%s: r = %u\n", __func__,
  70 + (unsigned int)(ret & ~EFI_ERROR_MASK));
  71 + if (ret != EFI_SUCCESS)
  72 + return 0;
  73 + return blkcnt;
  74 +}
  75 +
  76 +/*
  77 + * Write to block device
  78 + *
  79 + * @dev device
  80 + * @blknr first block to be write
  81 + * @blkcnt number of blocks to write
  82 + * @buffer input buffer
  83 + * @return number of blocks transferred
  84 + */
  85 +static ulong efi_bl_write(struct udevice *dev, lbaint_t blknr, lbaint_t blkcnt,
  86 + const void *buffer)
  87 +{
  88 + struct efi_blk_priv *priv = dev->priv;
  89 + struct efi_block_io *io = priv->io;
  90 + efi_status_t ret;
  91 +
  92 + EFI_PRINT("%s: write '%s', from block " LBAFU ", " LBAFU " blocks\n",
  93 + __func__, dev->name, blknr, blkcnt);
  94 + ret = EFI_CALL(io->write_blocks(
  95 + io, io->media->media_id, (u64)blknr,
  96 + (efi_uintn_t)blkcnt *
  97 + (efi_uintn_t)io->media->block_size,
  98 + (void *)buffer));
  99 + EFI_PRINT("%s: r = %u\n", __func__,
  100 + (unsigned int)(ret & ~EFI_ERROR_MASK));
  101 + if (ret != EFI_SUCCESS)
  102 + return 0;
  103 + return blkcnt;
  104 +}
  105 +
  106 +/*
  107 + * Create partions for the block device.
  108 + *
  109 + * @handle EFI handle of the block device
  110 + * @dev udevice of the block device
  111 + */
  112 +static int efi_bl_bind_partitions(efi_handle_t handle, struct udevice *dev)
  113 +{
  114 + struct blk_desc *desc;
  115 + const char *if_typename;
  116 +
  117 + desc = dev_get_uclass_platdata(dev);
  118 + if_typename = blk_get_if_type_name(desc->if_type);
  119 +
  120 + return efi_disk_create_partitions(handle, desc, if_typename,
  121 + desc->devnum, dev->name);
  122 +}
  123 +
  124 +/*
  125 + * Create a block device for a handle
  126 + *
  127 + * @handle handle
  128 + * @interface block io protocol
  129 + * @return 0 = success
  130 + */
  131 +static int efi_bl_bind(efi_handle_t handle, void *interface)
  132 +{
  133 + struct udevice *bdev, *parent = dm_root();
  134 + int ret, devnum;
  135 + char *name;
  136 + struct efi_object *obj = efi_search_obj(handle);
  137 + struct efi_block_io *io = interface;
  138 + int disks;
  139 + struct efi_blk_priv *priv;
  140 +
  141 + EFI_PRINT("%s: handle %p, interface %p\n", __func__, handle, io);
  142 +
  143 + if (!obj)
  144 + return -ENOENT;
  145 +
  146 + devnum = blk_find_max_devnum(IF_TYPE_EFI);
  147 + if (devnum == -ENODEV)
  148 + devnum = 0;
  149 + else if (devnum < 0)
  150 + return devnum;
  151 +
  152 + name = calloc(1, 18); /* strlen("efiblk#2147483648") + 1 */
  153 + if (!name)
  154 + return -ENOMEM;
  155 + sprintf(name, "efiblk#%d", devnum);
  156 +
  157 + /* Create driver model udevice for the EFI block io device */
  158 + ret = blk_create_device(parent, "efi_blk", name, IF_TYPE_EFI, devnum,
  159 + io->media->block_size,
  160 + (lbaint_t)io->media->last_block, &bdev);
  161 + if (ret)
  162 + return ret;
  163 + if (!bdev)
  164 + return -ENOENT;
  165 + /* Allocate priv */
  166 + ret = device_probe(bdev);
  167 + if (ret)
  168 + return ret;
  169 + EFI_PRINT("%s: block device '%s' created\n", __func__, bdev->name);
  170 +
  171 + priv = bdev->priv;
  172 + priv->handle = handle;
  173 + priv->io = interface;
  174 +
  175 + ret = blk_prepare_device(bdev);
  176 +
  177 + /* Create handles for the partions of the block device */
  178 + disks = efi_bl_bind_partitions(handle, bdev);
  179 + EFI_PRINT("Found %d partitions\n", disks);
  180 +
  181 + return 0;
  182 +}
  183 +
  184 +/* Block device driver operators */
  185 +static const struct blk_ops efi_blk_ops = {
  186 + .read = efi_bl_read,
  187 + .write = efi_bl_write,
  188 +};
  189 +
  190 +/* Identify as block device driver */
  191 +U_BOOT_DRIVER(efi_blk) = {
  192 + .name = "efi_blk",
  193 + .id = UCLASS_BLK,
  194 + .ops = &efi_blk_ops,
  195 + .priv_auto_alloc_size = sizeof(struct efi_blk_priv),
  196 +};
  197 +
  198 +/* EFI driver operators */
  199 +static const struct efi_driver_ops driver_ops = {
  200 + .protocol = &efi_block_io_guid,
  201 + .child_protocol = &efi_block_io_guid,
  202 + .bind = efi_bl_bind,
  203 +};
  204 +
  205 +/* Identify as EFI driver */
  206 +U_BOOT_DRIVER(efi_block) = {
  207 + .name = "EFI block driver",
  208 + .id = UCLASS_EFI,
  209 + .ops = &driver_ops,
  210 +};
lib/efi_driver/efi_uclass.c
  1 +/*
  2 + * Uclass for EFI drivers
  3 + *
  4 + * Copyright (c) 2017 Heinrich Schuchardt
  5 + *
  6 + * SPDX-License-Identifier: GPL-2.0+
  7 + *
  8 + * For each EFI driver the uclass
  9 + * - creates a handle
  10 + * - installs the driver binding protocol
  11 + *
  12 + * The uclass provides the bind, start, and stop entry points for the driver
  13 + * binding protocol.
  14 + *
  15 + * In bind() and stop() it checks if the controller implements the protocol
  16 + * supported by the EFI driver. In the start() function it calls the bind()
  17 + * function of the EFI driver. In the stop() function it destroys the child
  18 + * controllers.
  19 + */
  20 +
  21 +#include <efi_driver.h>
  22 +
  23 +/*
  24 + * Check node type. We do not support partitions as controller handles.
  25 + *
  26 + * @handle handle to be checked
  27 + * @return status code
  28 + */
  29 +static efi_status_t check_node_type(efi_handle_t handle)
  30 +{
  31 + efi_status_t r, ret = EFI_SUCCESS;
  32 + const struct efi_device_path *dp;
  33 +
  34 + /* Open the device path protocol */
  35 + r = EFI_CALL(systab.boottime->open_protocol(
  36 + handle, &efi_guid_device_path, (void **)&dp,
  37 + NULL, NULL, EFI_OPEN_PROTOCOL_GET_PROTOCOL));
  38 + if (r == EFI_SUCCESS && dp) {
  39 + /* Get the last node */
  40 + const struct efi_device_path *node = efi_dp_last_node(dp);
  41 + /* We do not support partitions as controller */
  42 + if (!node || node->type == DEVICE_PATH_TYPE_MEDIA_DEVICE)
  43 + ret = EFI_UNSUPPORTED;
  44 + }
  45 + return ret;
  46 +}
  47 +
  48 +/*
  49 + * Check if the driver supports the controller.
  50 + *
  51 + * @this driver binding protocol
  52 + * @controller_handle handle of the controller
  53 + * @remaining_device_path path specifying the child controller
  54 + * @return status code
  55 + */
  56 +static efi_status_t EFIAPI efi_uc_supported(
  57 + struct efi_driver_binding_protocol *this,
  58 + efi_handle_t controller_handle,
  59 + struct efi_device_path *remaining_device_path)
  60 +{
  61 + efi_status_t r, ret;
  62 + void *interface;
  63 + struct efi_driver_binding_extended_protocol *bp =
  64 + (struct efi_driver_binding_extended_protocol *)this;
  65 +
  66 + EFI_ENTRY("%p, %p, %ls", this, controller_handle,
  67 + efi_dp_str(remaining_device_path));
  68 +
  69 + ret = EFI_CALL(systab.boottime->open_protocol(
  70 + controller_handle, bp->ops->protocol,
  71 + &interface, this->driver_binding_handle,
  72 + controller_handle, EFI_OPEN_PROTOCOL_BY_DRIVER));
  73 + switch (ret) {
  74 + case EFI_ACCESS_DENIED:
  75 + case EFI_ALREADY_STARTED:
  76 + goto out;
  77 + case EFI_SUCCESS:
  78 + break;
  79 + default:
  80 + ret = EFI_UNSUPPORTED;
  81 + goto out;
  82 + }
  83 +
  84 + ret = check_node_type(controller_handle);
  85 +
  86 + r = EFI_CALL(systab.boottime->close_protocol(
  87 + controller_handle, bp->ops->protocol,
  88 + this->driver_binding_handle,
  89 + controller_handle));
  90 + if (r != EFI_SUCCESS)
  91 + ret = EFI_UNSUPPORTED;
  92 +out:
  93 + return EFI_EXIT(ret);
  94 +}
  95 +
  96 +/*
  97 + * Create child controllers and attach driver.
  98 + *
  99 + * @this driver binding protocol
  100 + * @controller_handle handle of the controller
  101 + * @remaining_device_path path specifying the child controller
  102 + * @return status code
  103 + */
  104 +static efi_status_t EFIAPI efi_uc_start(
  105 + struct efi_driver_binding_protocol *this,
  106 + efi_handle_t controller_handle,
  107 + struct efi_device_path *remaining_device_path)
  108 +{
  109 + efi_status_t r, ret;
  110 + void *interface = NULL;
  111 + struct efi_driver_binding_extended_protocol *bp =
  112 + (struct efi_driver_binding_extended_protocol *)this;
  113 +
  114 + EFI_ENTRY("%p, %pUl, %ls", this, controller_handle,
  115 + efi_dp_str(remaining_device_path));
  116 +
  117 + /* Attach driver to controller */
  118 + ret = EFI_CALL(systab.boottime->open_protocol(
  119 + controller_handle, bp->ops->protocol,
  120 + &interface, this->driver_binding_handle,
  121 + controller_handle, EFI_OPEN_PROTOCOL_BY_DRIVER));
  122 + switch (ret) {
  123 + case EFI_ACCESS_DENIED:
  124 + case EFI_ALREADY_STARTED:
  125 + goto out;
  126 + case EFI_SUCCESS:
  127 + break;
  128 + default:
  129 + ret = EFI_UNSUPPORTED;
  130 + goto out;
  131 + }
  132 + ret = check_node_type(controller_handle);
  133 + if (ret != EFI_SUCCESS) {
  134 + r = EFI_CALL(systab.boottime->close_protocol(
  135 + controller_handle, bp->ops->protocol,
  136 + this->driver_binding_handle,
  137 + controller_handle));
  138 + if (r != EFI_SUCCESS)
  139 + EFI_PRINT("Failure to close handle\n");
  140 + goto out;
  141 + }
  142 +
  143 + /* TODO: driver specific stuff */
  144 + bp->ops->bind(controller_handle, interface);
  145 +
  146 +out:
  147 + return EFI_EXIT(ret);
  148 +}
  149 +
  150 +/*
  151 + * Remove a single child controller from the parent controller.
  152 + *
  153 + * @controller_handle parent controller
  154 + * @child_handle child controller
  155 + * @return status code
  156 + */
  157 +static efi_status_t disconnect_child(efi_handle_t controller_handle,
  158 + efi_handle_t child_handle)
  159 +{
  160 + efi_status_t ret;
  161 + efi_guid_t *guid_controller = NULL;
  162 + efi_guid_t *guid_child_controller = NULL;
  163 +
  164 + ret = EFI_CALL(systab.boottime->close_protocol(
  165 + controller_handle, guid_controller,
  166 + child_handle, child_handle));
  167 + if (ret != EFI_SUCCESS) {
  168 + EFI_PRINT("Cannot close protocol\n");
  169 + return ret;
  170 + }
  171 + ret = EFI_CALL(systab.boottime->uninstall_protocol_interface(
  172 + child_handle, guid_child_controller, NULL));
  173 + if (ret != EFI_SUCCESS) {
  174 + EFI_PRINT("Cannot uninstall protocol interface\n");
  175 + return ret;
  176 + }
  177 + return ret;
  178 +}
  179 +
  180 +/*
  181 + * Remove child controllers and disconnect the controller.
  182 + *
  183 + * @this driver binding protocol
  184 + * @controller_handle handle of the controller
  185 + * @number_of_children number of child controllers to remove
  186 + * @child_handle_buffer handles of the child controllers to remove
  187 + * @return status code
  188 + */
  189 +static efi_status_t EFIAPI efi_uc_stop(
  190 + struct efi_driver_binding_protocol *this,
  191 + efi_handle_t controller_handle,
  192 + size_t number_of_children,
  193 + efi_handle_t *child_handle_buffer)
  194 +{
  195 + efi_status_t ret;
  196 + efi_uintn_t count;
  197 + struct efi_open_protocol_info_entry *entry_buffer;
  198 + efi_guid_t *guid_controller = NULL;
  199 +
  200 + EFI_ENTRY("%p, %pUl, %zu, %p", this, controller_handle,
  201 + number_of_children, child_handle_buffer);
  202 +
  203 + /* Destroy provided child controllers */
  204 + if (number_of_children) {
  205 + efi_uintn_t i;
  206 +
  207 + for (i = 0; i < number_of_children; ++i) {
  208 + ret = disconnect_child(controller_handle,
  209 + child_handle_buffer[i]);
  210 + if (ret != EFI_SUCCESS)
  211 + return ret;
  212 + }
  213 + return EFI_SUCCESS;
  214 + }
  215 +
  216 + /* Destroy all children */
  217 + ret = EFI_CALL(systab.boottime->open_protocol_information(
  218 + controller_handle, guid_controller,
  219 + &entry_buffer, &count));
  220 + if (ret != EFI_SUCCESS)
  221 + goto out;
  222 + while (count) {
  223 + if (entry_buffer[--count].attributes &
  224 + EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER) {
  225 + ret = disconnect_child(
  226 + controller_handle,
  227 + entry_buffer[count].agent_handle);
  228 + if (ret != EFI_SUCCESS)
  229 + goto out;
  230 + }
  231 + }
  232 + ret = EFI_CALL(systab.boottime->free_pool(entry_buffer));
  233 + if (ret != EFI_SUCCESS)
  234 + printf("%s(%u) %s: ERROR: Cannot free pool\n",
  235 + __FILE__, __LINE__, __func__);
  236 +
  237 + /* Detach driver from controller */
  238 + ret = EFI_CALL(systab.boottime->close_protocol(
  239 + controller_handle, guid_controller,
  240 + this->driver_binding_handle, controller_handle));
  241 +out:
  242 + return EFI_EXIT(ret);
  243 +}
  244 +
  245 +static efi_status_t efi_add_driver(struct driver *drv)
  246 +{
  247 + efi_status_t ret;
  248 + const struct efi_driver_ops *ops = drv->ops;
  249 + struct efi_driver_binding_extended_protocol *bp;
  250 +
  251 + debug("EFI: Adding driver '%s'\n", drv->name);
  252 + if (!ops->protocol) {
  253 + printf("EFI: ERROR: protocol GUID missing for driver '%s'\n",
  254 + drv->name);
  255 + return EFI_INVALID_PARAMETER;
  256 + }
  257 + bp = calloc(1, sizeof(struct efi_driver_binding_extended_protocol));
  258 + if (!bp)
  259 + return EFI_OUT_OF_RESOURCES;
  260 +
  261 + bp->bp.supported = efi_uc_supported;
  262 + bp->bp.start = efi_uc_start;
  263 + bp->bp.stop = efi_uc_stop;
  264 + bp->bp.version = 0xffffffff;
  265 + bp->ops = drv->ops;
  266 +
  267 + ret = efi_create_handle(&bp->bp.driver_binding_handle);
  268 + if (ret != EFI_SUCCESS) {
  269 + free(bp);
  270 + goto out;
  271 + }
  272 + bp->bp.image_handle = bp->bp.driver_binding_handle;
  273 + ret = efi_add_protocol(bp->bp.driver_binding_handle,
  274 + &efi_guid_driver_binding_protocol, bp);
  275 + if (ret != EFI_SUCCESS) {
  276 + efi_delete_handle(bp->bp.driver_binding_handle);
  277 + free(bp);
  278 + goto out;
  279 + }
  280 +out:
  281 + return ret;
  282 +}
  283 +
  284 +/*
  285 + * Initialize the EFI drivers.
  286 + * Called by board_init_r().
  287 + *
  288 + * @return 0 = success, any other value will stop further execution
  289 + */
  290 +int efi_driver_init(void)
  291 +{
  292 + struct driver *drv;
  293 + int ret = 0;
  294 +
  295 + /* Save 'gd' pointer */
  296 + efi_save_gd();
  297 +
  298 + debug("EFI: Initializing EFI driver framework\n");
  299 + for (drv = ll_entry_start(struct driver, driver);
  300 + drv < ll_entry_end(struct driver, driver); ++drv) {
  301 + if (drv->id == UCLASS_EFI) {
  302 + ret = efi_add_driver(drv);
  303 + if (ret) {
  304 + printf("EFI: ERROR: failed to add driver %s\n",
  305 + drv->name);
  306 + break;
  307 + }
  308 + }
  309 + }
  310 + return ret;
  311 +}
  312 +
  313 +static int efi_uc_init(struct uclass *class)
  314 +{
  315 + printf("EFI: Initializing UCLASS_EFI\n");
  316 + return 0;
  317 +}
  318 +
  319 +static int efi_uc_destroy(struct uclass *class)
  320 +{
  321 + printf("Destroying UCLASS_EFI\n");
  322 + return 0;
  323 +}
  324 +
  325 +UCLASS_DRIVER(efi) = {
  326 + .name = "efi",
  327 + .id = UCLASS_EFI,
  328 + .init = efi_uc_init,
  329 + .destroy = efi_uc_destroy,
  330 +};