[PATCH v10 01/10] efi_loader: move udevice pointer into struct efi_object
Masahisa Kojima
masahisa.kojima at linaro.org
Fri Jul 22 04:39:10 CEST 2022
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 at linaro.org>
---
Changes in v10:
- introduce efi_link_dev() and remove accessor macro
- set udevice in efi_bl_bind()
Newly created in v9
include/efi_loader.h | 4 ++++
lib/efi_driver/efi_block_device.c | 3 +--
lib/efi_loader/efi_disk.c | 15 ++++++---------
lib/efi_loader/efi_helper.c | 13 +++++++++++++
4 files changed, 24 insertions(+), 11 deletions(-)
diff --git a/include/efi_loader.h b/include/efi_loader.h
index 3a63a1f75f..b0d6fff67c 100644
--- a/include/efi_loader.h
+++ b/include/efi_loader.h
@@ -375,6 +375,7 @@ enum efi_object_type {
* @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 @@ struct efi_object {
/* 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 @@ struct efi_device_path *efi_get_dp_from_boot(const efi_guid_t guid);
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 5baa6f87a3..d57d281f85 100644
--- a/lib/efi_driver/efi_block_device.c
+++ b/lib/efi_driver/efi_block_device.c
@@ -158,8 +158,7 @@ static int efi_bl_bind(efi_handle_t handle, void *interface)
* 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 1d700b2a6b..16d14b0429 100644
--- a/lib/efi_loader/efi_disk.c
+++ b/lib/efi_loader/efi_disk.c
@@ -46,7 +46,6 @@ struct efi_disk_obj {
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 @@ static efi_status_t efi_disk_rw_blocks(struct efi_block_io *this,
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 @@ static int efi_disk_create_raw(struct udevice *dev)
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 @@ static int efi_disk_create_part(struct udevice *dev)
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 c4499f65ee..8ed564e261 100644
--- a/lib/efi_loader/efi_helper.c
+++ b/lib/efi_loader/efi_helper.c
@@ -158,3 +158,16 @@ int algo_to_len(const char *algo)
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);
+}
--
2.17.1
More information about the U-Boot
mailing list