efi_loader: move udevice pointer into struct efi_object
This is a preparation patch to provide the unified method
to access udevice pointer associated with the EFI handle
by adding udevice pointer into struct efi_object.
The patch also introduces a helper function efi_link_dev()
to link the udevice and EFI handle.
The EFI handles of both EFI block io driver implemented in
lib/efi_loader/efi_disk.c and EFI block io driver implemented
as EFI payload can access the udevice pointer in the struct efi_object.
We can use this udevice pointer to get the U-Boot friendly
block device name(e.g. mmc 0:1, nvme 0:1) through EFI handle.
Signed-off-by: Masahisa Kojima <masahisa.kojima@linaro.org>
Reviewed-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
diff --git a/include/efi_loader.h b/include/efi_loader.h
index 3a63a1f..b0d6fff 100644
--- a/include/efi_loader.h
+++ b/include/efi_loader.h
@@ -375,6 +375,7 @@
* @protocols: linked list with the protocol interfaces installed on this
* handle
* @type: image type if the handle relates to an image
+ * @dev: pointer to the DM device which is associated with this EFI handle
*
* UEFI offers a flexible and expandable object model. The objects in the UEFI
* API are devices, drivers, and loaded images. struct efi_object is our storage
@@ -392,6 +393,7 @@
/* The list of protocols */
struct list_head protocols;
enum efi_object_type type;
+ struct udevice *dev;
};
enum efi_image_auth_status {
@@ -690,6 +692,8 @@
const char *guid_to_sha_str(const efi_guid_t *guid);
int algo_to_len(const char *algo);
+int efi_link_dev(efi_handle_t handle, struct udevice *dev);
+
/**
* efi_size_in_pages() - convert size in bytes to size in pages
*
diff --git a/lib/efi_driver/efi_block_device.c b/lib/efi_driver/efi_block_device.c
index 5baa6f8..d57d281 100644
--- a/lib/efi_driver/efi_block_device.c
+++ b/lib/efi_driver/efi_block_device.c
@@ -158,8 +158,7 @@
* FIXME: necessary because we won't do almost nothing in
* efi_disk_create() when called from device_probe().
*/
- ret = dev_tag_set_ptr(bdev, DM_TAG_EFI, handle);
- if (ret)
+ if (efi_link_dev(handle, bdev))
/* FIXME: cleanup for bdev */
return ret;
diff --git a/lib/efi_loader/efi_disk.c b/lib/efi_loader/efi_disk.c
index 1d700b2..16d14b0 100644
--- a/lib/efi_loader/efi_disk.c
+++ b/lib/efi_loader/efi_disk.c
@@ -46,7 +46,6 @@
struct efi_device_path *dp;
unsigned int part;
struct efi_simple_file_system_protocol *volume;
- struct udevice *dev; /* TODO: move it to efi_object */
};
/**
@@ -124,16 +123,16 @@
return EFI_BAD_BUFFER_SIZE;
if (CONFIG_IS_ENABLED(PARTITIONS) &&
- device_get_uclass_id(diskobj->dev) == UCLASS_PARTITION) {
+ device_get_uclass_id(diskobj->header.dev) == UCLASS_PARTITION) {
if (direction == EFI_DISK_READ)
- n = dev_read(diskobj->dev, lba, blocks, buffer);
+ n = dev_read(diskobj->header.dev, lba, blocks, buffer);
else
- n = dev_write(diskobj->dev, lba, blocks, buffer);
+ n = dev_write(diskobj->header.dev, lba, blocks, buffer);
} else {
/* dev is a block device (UCLASS_BLK) */
struct blk_desc *desc;
- desc = dev_get_uclass_plat(diskobj->dev);
+ desc = dev_get_uclass_plat(diskobj->header.dev);
if (direction == EFI_DISK_READ)
n = blk_dread(desc, lba, blocks, buffer);
else
@@ -552,8 +551,7 @@
return -1;
}
- disk->dev = dev;
- if (dev_tag_set_ptr(dev, DM_TAG_EFI, &disk->header)) {
+ if (efi_link_dev(&disk->header, dev)) {
efi_free_pool(disk->dp);
efi_delete_handle(&disk->header);
@@ -609,8 +607,7 @@
log_err("Adding partition for %s failed\n", dev->name);
return -1;
}
- disk->dev = dev;
- if (dev_tag_set_ptr(dev, DM_TAG_EFI, &disk->header)) {
+ if (efi_link_dev(&disk->header, dev)) {
efi_free_pool(disk->dp);
efi_delete_handle(&disk->header);
diff --git a/lib/efi_loader/efi_helper.c b/lib/efi_loader/efi_helper.c
index c4499f6..8ed564e 100644
--- a/lib/efi_loader/efi_helper.c
+++ b/lib/efi_loader/efi_helper.c
@@ -158,3 +158,16 @@
return 0;
}
+
+/** efi_link_dev - link the efi_handle_t and udevice
+ *
+ * @handle: efi handle to associate with udevice
+ * @dev: udevice to associate with efi handle
+ *
+ * Return: 0 on success, negative on failure
+ */
+int efi_link_dev(efi_handle_t handle, struct udevice *dev)
+{
+ handle->dev = dev;
+ return dev_tag_set_ptr(dev, DM_TAG_EFI, handle);
+}