All of lore.kernel.org
 help / color / mirror / Atom feed
From: Masahisa Kojima <masahisa.kojima@linaro.org>
To: u-boot@lists.denx.de
Cc: Heinrich Schuchardt <xypron.glpk@gmx.de>,
	Ilias Apalodimas <ilias.apalodimas@linaro.org>,
	Simon Glass <sjg@chromium.org>,
	Takahiro Akashi <takahiro.akashi@linaro.org>,
	Mark Kettenis <mark.kettenis@xs4all.nl>,
	Masahisa Kojima <masahisa.kojima@linaro.org>
Subject: [PATCH v10 01/10] efi_loader: move udevice pointer into struct efi_object
Date: Fri, 22 Jul 2022 11:39:10 +0900	[thread overview]
Message-ID: <20220722023919.19676-2-masahisa.kojima@linaro.org> (raw)
In-Reply-To: <20220722023919.19676-1-masahisa.kojima@linaro.org>

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>
---
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


  reply	other threads:[~2022-07-22  2:36 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-22  2:39 [PATCH v10 00/10] enable menu-driven UEFI variable maintenance Masahisa Kojima
2022-07-22  2:39 ` Masahisa Kojima [this message]
2022-08-02 14:53   ` [PATCH v10 01/10] efi_loader: move udevice pointer into struct efi_object Heinrich Schuchardt
2022-07-22  2:39 ` [PATCH v10 02/10] eficonfig: menu-driven addition of UEFI boot option Masahisa Kojima
2022-07-22  2:39 ` [PATCH v10 03/10] eficonfig: add "Edit Boot Option" menu entry Masahisa Kojima
2022-08-02  7:38   ` Heinrich Schuchardt
2022-08-17  9:02     ` Masahisa Kojima
2022-07-22  2:39 ` [PATCH v10 04/10] menu: add KEY_PLUS and KEY_MINUS handling Masahisa Kojima
2022-07-22  2:39 ` [PATCH v10 05/10] eficonfig: add "Change Boot Order" menu entry Masahisa Kojima
2022-08-02  7:43   ` Heinrich Schuchardt
2022-08-17  8:48     ` Masahisa Kojima
2022-07-22  2:39 ` [PATCH v10 06/10] eficonfig: add "Delete Boot Option" " Masahisa Kojima
2022-07-22  2:39 ` [PATCH v10 07/10] bootmenu: add removable media entries Masahisa Kojima
2022-07-22  2:39 ` [PATCH v10 08/10] doc:bootmenu: add description for UEFI boot support Masahisa Kojima
2022-07-22  2:39 ` [PATCH v10 09/10] doc:eficonfig: add documentation for eficonfig command Masahisa Kojima
2022-07-22  2:39 ` [PATCH v10 10/10] test: unit test for eficonfig Masahisa Kojima
2022-07-22  8:45 ` [PATCH v10 00/10] enable menu-driven UEFI variable maintenance Ilias Apalodimas
2022-07-27  1:08   ` Takahiro Akashi
2022-07-27  1:56     ` Takahiro Akashi
2022-08-04  8:26       ` Masahisa Kojima

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220722023919.19676-2-masahisa.kojima@linaro.org \
    --to=masahisa.kojima@linaro.org \
    --cc=ilias.apalodimas@linaro.org \
    --cc=mark.kettenis@xs4all.nl \
    --cc=sjg@chromium.org \
    --cc=takahiro.akashi@linaro.org \
    --cc=u-boot@lists.denx.de \
    --cc=xypron.glpk@gmx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.