All of lore.kernel.org
 help / color / mirror / Atom feed
From: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
To: Simon Glass <sjg@chromium.org>,
	Ilias Apalodimas <ilias.apalodimas@linaro.org>
Cc: AKASHI Takahiro <takahiro.akashi@linaro.org>,
	Masahisa Kojima <masahisa.kojima@linaro.org>,
	u-boot@lists.denx.de,
	Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
Subject: [PATCH 1/2] dm: blk: assign media ID to block devices
Date: Thu, 15 Sep 2022 22:02:41 +0200	[thread overview]
Message-ID: <20220915200242.18358-2-heinrich.schuchardt@canonical.com> (raw)
In-Reply-To: <20220915200242.18358-1-heinrich.schuchardt@canonical.com>

Currently block devices are only identified by uclass_id and device number.
When dealing with removable media this is not enough to uniquely identify
the medium.

E.g. after host unbind, host bind we can have the same device number but a
different backing file.

The EFI specification uses a 32bit number media ID to identify media. Add a
matching field to the block device descriptor.

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
---
 drivers/block/blk-uclass.c | 16 +++++++++++++++-
 include/blk.h              | 11 +++++++++++
 2 files changed, 26 insertions(+), 1 deletion(-)

diff --git a/drivers/block/blk-uclass.c b/drivers/block/blk-uclass.c
index 21c5209bb6..c6f6be81c3 100644
--- a/drivers/block/blk-uclass.c
+++ b/drivers/block/blk-uclass.c
@@ -51,6 +51,11 @@ static enum uclass_id if_type_uclass_id[IF_TYPE_COUNT] = {
 	[IF_TYPE_PVBLOCK]	= UCLASS_PVBLOCK,
 };
 
+/*
+ * Global counter for media IDs
+ */
+static u32 media_id_counter;
+
 static enum if_type if_typename_to_iftype(const char *if_typename)
 {
 	int i;
@@ -741,11 +746,20 @@ int blk_unbind_all(int if_type)
 	return 0;
 }
 
+void blk_assign_media_id(struct blk_desc *desc)
+{
+	desc->media_id = ++media_id_counter;
+}
+
 static int blk_post_probe(struct udevice *dev)
 {
+	struct blk_desc *desc = dev_get_uclass_plat(dev);
+
+	if (!desc->media_id)
+		blk_assign_media_id(desc);
+
 	if (CONFIG_IS_ENABLED(PARTITIONS) &&
 	    IS_ENABLED(CONFIG_HAVE_BLOCK_DEVICE)) {
-		struct blk_desc *desc = dev_get_uclass_plat(dev);
 
 		part_init(desc);
 
diff --git a/include/blk.h b/include/blk.h
index 9503369db8..c176f8374e 100644
--- a/include/blk.h
+++ b/include/blk.h
@@ -77,6 +77,7 @@ struct blk_desc {
 	unsigned char	hwpart;		/* HW partition, e.g. for eMMC */
 	unsigned char	type;		/* device type */
 	unsigned char	removable;	/* removable device */
+	u32		media_id;	/* ID to identify media */
 #ifdef CONFIG_LBA48
 	/* device can use 48bit addr (ATA/ATAPI v7) */
 	unsigned char	lba48;
@@ -808,4 +809,14 @@ int blk_find_next(enum blk_flag_t flags, struct udevice **devp);
  */
 int blk_count_devices(enum blk_flag_t flag);
 
+/**
+ * blk_assign_media_id() - assign a media ID to the block device
+ *
+ * The field media_id of the block device descriptor is filled from a global
+ * counter.
+ *
+ * @desc:	block device descriptor
+ */
+void blk_assign_media_id(struct blk_desc *desc);
+
 #endif
-- 
2.37.2


  reply	other threads:[~2022-09-15 20:03 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-15 20:02 [PATCH 0/2] efi_loader: provide media ID Heinrich Schuchardt
2022-09-15 20:02 ` Heinrich Schuchardt [this message]
2022-09-16  1:30   ` [PATCH 1/2] dm: blk: assign media ID to block devices Simon Glass
2022-09-16  6:41     ` Heinrich Schuchardt
2022-09-16 20:29       ` Simon Glass
2022-09-15 20:02 ` [PATCH 2/2] efi_loader: fill media_id from block device descriptor Heinrich Schuchardt
2022-09-23  7:07   ` Ilias Apalodimas
2022-09-25 14:15     ` Simon Glass
2022-09-26  0:05       ` AKASHI Takahiro
2022-09-16  0:58 ` [PATCH 0/2] efi_loader: provide media ID AKASHI Takahiro
2022-09-26  6:06   ` Heinrich Schuchardt
2022-09-27  1:51     ` AKASHI Takahiro
2022-09-27  6:53       ` Heinrich Schuchardt
2022-09-28  1:54         ` Simon Glass
2022-09-28  6:57           ` Heinrich Schuchardt
2022-09-28  7:24             ` AKASHI Takahiro
2022-09-28 16:27               ` Simon Glass

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=20220915200242.18358-2-heinrich.schuchardt@canonical.com \
    --to=heinrich.schuchardt@canonical.com \
    --cc=ilias.apalodimas@linaro.org \
    --cc=masahisa.kojima@linaro.org \
    --cc=sjg@chromium.org \
    --cc=takahiro.akashi@linaro.org \
    --cc=u-boot@lists.denx.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.