All of lore.kernel.org
 help / color / mirror / Atom feed
From: Simon Glass <sjg@chromium.org>
To: U-Boot Mailing List <u-boot@lists.denx.de>
Cc: Tom Rini <trini@konsulko.com>,
	Heinrich Schuchardt <xypron.glpk@gmx.de>,
	Simon Glass <sjg@chromium.org>,
	AKASHI Takahiro <takahiro.akashi@linaro.org>,
	Marcel Ziswiler <marcel.ziswiler@toradex.com>,
	Masahisa Kojima <masahisa.kojima@linaro.org>,
	Oleksandr Suvorov <oleksandr.suvorov@foundries.io>,
	Oleksii Bidnichenko <oleksii.bidnichenko@toradex.com>,
	Ricardo Salveti <ricardo@foundries.io>,
	Sean Anderson <sean.anderson@seco.com>, schspa <schspa@gmail.com>
Subject: [PATCH v2 06/24] blk: Use a function for whether block devices are available
Date: Thu, 11 Aug 2022 19:34:45 -0600	[thread overview]
Message-ID: <20220812013503.1724919-7-sjg@chromium.org> (raw)
In-Reply-To: <20220812013503.1724919-1-sjg@chromium.org>

At present we use HAVE_BLOCK_DEVICE to indicate when block devices are
available.

This is a very strange option, since it partially duplicates the BLK
option used by driver model. It also covers both U-Boot proper and SPL,
even though one might have block devices and another not.

As a first step towards correcting this, create a new inline function
called blk_enabled() which indicates if block devices are available.
This cannot be used in Makefiles, or #if clauses, but can be used in C
code.

A function is useful because we cannot use CONFIG_IS_ENABLED(BLK) to
decide if block devices are needed, since we must consider the legacy
block interface, enabled by HAVE_BLOCK_DEVICE

Update a few places where it can be used and drop some unnecessary #if
checks around some functions in disk/part.c - rely on the compiler's
dead-code elimination instead.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

(no changes since v1)

 disk/part.c                | 80 ++++++++++++++++----------------------
 drivers/block/blk-uclass.c |  3 +-
 fs/fat/fat.c               |  2 +-
 include/blk.h              |  5 +++
 4 files changed, 40 insertions(+), 50 deletions(-)

diff --git a/disk/part.c b/disk/part.c
index 79955c7fb00..9594bb432c4 100644
--- a/disk/part.c
+++ b/disk/part.c
@@ -54,12 +54,13 @@ static struct part_driver *part_driver_lookup_type(struct blk_desc *dev_desc)
 	return NULL;
 }
 
-#ifdef CONFIG_HAVE_BLOCK_DEVICE
 static struct blk_desc *get_dev_hwpart(const char *ifname, int dev, int hwpart)
 {
 	struct blk_desc *dev_desc;
 	int ret;
 
+	if (!blk_enabled())
+		return NULL;
 	dev_desc = blk_get_devnum_by_typename(ifname, dev);
 	if (!dev_desc) {
 		debug("%s: No device for iface '%s', dev %d\n", __func__,
@@ -78,21 +79,11 @@ static struct blk_desc *get_dev_hwpart(const char *ifname, int dev, int hwpart)
 
 struct blk_desc *blk_get_dev(const char *ifname, int dev)
 {
-	return get_dev_hwpart(ifname, dev, 0);
-}
-#else
-struct blk_desc *get_dev_hwpart(const char *ifname, int dev, int hwpart)
-{
-	return NULL;
-}
+	if (!blk_enabled())
+		return NULL;
 
-struct blk_desc *blk_get_dev(const char *ifname, int dev)
-{
-	return NULL;
+	return get_dev_hwpart(ifname, dev, 0);
 }
-#endif
-
-#ifdef CONFIG_HAVE_BLOCK_DEVICE
 
 /* ------------------------------------------------------------------------- */
 /*
@@ -228,9 +219,6 @@ void dev_print (struct blk_desc *dev_desc)
 		puts ("            Capacity: not available\n");
 	}
 }
-#endif
-
-#ifdef CONFIG_HAVE_BLOCK_DEVICE
 
 void part_init(struct blk_desc *dev_desc)
 {
@@ -325,38 +313,36 @@ void part_print(struct blk_desc *dev_desc)
 		drv->print(dev_desc);
 }
 
-#endif /* CONFIG_HAVE_BLOCK_DEVICE */
-
 int part_get_info(struct blk_desc *dev_desc, int part,
 		       struct disk_partition *info)
 {
-#ifdef CONFIG_HAVE_BLOCK_DEVICE
 	struct part_driver *drv;
 
+	if (blk_enabled()) {
 #if CONFIG_IS_ENABLED(PARTITION_UUIDS)
-	/* The common case is no UUID support */
-	info->uuid[0] = 0;
+		/* The common case is no UUID support */
+		info->uuid[0] = 0;
 #endif
 #ifdef CONFIG_PARTITION_TYPE_GUID
-	info->type_guid[0] = 0;
+		info->type_guid[0] = 0;
 #endif
 
-	drv = part_driver_lookup_type(dev_desc);
-	if (!drv) {
-		debug("## Unknown partition table type %x\n",
-		      dev_desc->part_type);
-		return -EPROTONOSUPPORT;
-	}
-	if (!drv->get_info) {
-		PRINTF("## Driver %s does not have the get_info() method\n",
-		       drv->name);
-		return -ENOSYS;
-	}
-	if (drv->get_info(dev_desc, part, info) == 0) {
-		PRINTF("## Valid %s partition found ##\n", drv->name);
-		return 0;
+		drv = part_driver_lookup_type(dev_desc);
+		if (!drv) {
+			debug("## Unknown partition table type %x\n",
+			      dev_desc->part_type);
+			return -EPROTONOSUPPORT;
+		}
+		if (!drv->get_info) {
+			PRINTF("## Driver %s does not have the get_info() method\n",
+			       drv->name);
+			return -ENOSYS;
+		}
+		if (drv->get_info(dev_desc, part, info) == 0) {
+			PRINTF("## Valid %s partition found ##\n", drv->name);
+			return 0;
+		}
 	}
-#endif /* CONFIG_HAVE_BLOCK_DEVICE */
 
 	return -ENOENT;
 }
@@ -424,15 +410,15 @@ int blk_get_device_by_str(const char *ifname, const char *dev_hwpart_str,
 		goto cleanup;
 	}
 
-#ifdef CONFIG_HAVE_BLOCK_DEVICE
-	/*
-	 * Updates the partition table for the specified hw partition.
-	 * Always should be done, otherwise hw partition 0 will return stale
-	 * data after displaying a non-zero hw partition.
-	 */
-	if ((*dev_desc)->if_type == IF_TYPE_MMC)
-		part_init(*dev_desc);
-#endif
+	if (blk_enabled()) {
+		/*
+		 * Updates the partition table for the specified hw partition.
+		 * Always should be done, otherwise hw partition 0 will return
+		 * stale data after displaying a non-zero hw partition.
+		 */
+		if ((*dev_desc)->if_type == IF_TYPE_MMC)
+			part_init(*dev_desc);
+	}
 
 cleanup:
 	free(dup_str);
diff --git a/drivers/block/blk-uclass.c b/drivers/block/blk-uclass.c
index 21c5209bb63..1a6e8f8c29d 100644
--- a/drivers/block/blk-uclass.c
+++ b/drivers/block/blk-uclass.c
@@ -743,8 +743,7 @@ int blk_unbind_all(int if_type)
 
 static int blk_post_probe(struct udevice *dev)
 {
-	if (CONFIG_IS_ENABLED(PARTITIONS) &&
-	    IS_ENABLED(CONFIG_HAVE_BLOCK_DEVICE)) {
+	if (CONFIG_IS_ENABLED(PARTITIONS) && blk_enabled()) {
 		struct blk_desc *desc = dev_get_uclass_plat(dev);
 
 		part_init(desc);
diff --git a/fs/fat/fat.c b/fs/fat/fat.c
index df9ea2c028f..c64e253abd4 100644
--- a/fs/fat/fat.c
+++ b/fs/fat/fat.c
@@ -1144,7 +1144,7 @@ int file_fat_detectfs(void)
 		return 1;
 	}
 
-	if (IS_ENABLED(CONFIG_HAVE_BLOCK_DEVICE)) {
+	if (blk_enabled()) {
 		printf("Interface:  %s\n", blk_get_if_type_name(cur_dev->if_type));
 		printf("  Device %d: ", cur_dev->devnum);
 		dev_print(cur_dev);
diff --git a/include/blk.h b/include/blk.h
index 9503369db83..332481a90b8 100644
--- a/include/blk.h
+++ b/include/blk.h
@@ -21,6 +21,11 @@ typedef ulong lbaint_t;
 
 struct udevice;
 
+static inline bool blk_enabled(void)
+{
+	return CONFIG_IS_ENABLED(BLK) || IS_ENABLED(CONFIG_HAVE_BLOCK_DEVICE);
+}
+
 /* Interface types: */
 enum if_type {
 	IF_TYPE_UNKNOWN = 0,
-- 
2.37.1.595.g718a3a8f04-goog


  parent reply	other threads:[~2022-08-12  1:37 UTC|newest]

Thread overview: 42+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-12  1:34 [PATCH v2 00/24] blk: Rationalise the block interface Simon Glass
2022-08-12  1:34 ` [PATCH v2 01/24] disk: Correct help for TPL_PARTITIONS Simon Glass
2022-09-16 19:37   ` Tom Rini
2022-08-12  1:34 ` [PATCH v2 02/24] blk: Enable CONFIG_BLK for all media Simon Glass
2022-08-12  1:34 ` [PATCH v2 03/24] ata: Fix an instance of SPL_SATA_SUPPORT Simon Glass
2022-08-12  1:34 ` [PATCH v2 04/24] sandbox: Avoid defining HAVE_BLOCK_DEVICE in Konfig Simon Glass
2022-08-12  1:34 ` [PATCH v2 05/24] disk: Use Makefile to omit partition drivers Simon Glass
2022-08-12  1:34 ` Simon Glass [this message]
2022-08-12  1:34 ` [PATCH v2 07/24] cmd: Drop use of HAVE_BLOCK_DEVICE Simon Glass
2022-08-12  1:34 ` [PATCH v2 08/24] blk: Drop unnecessary #ifdef in in blk_legacy Simon Glass
2022-08-12  1:34 ` [PATCH v2 09/24] blk: Rename HAVE_BLOCK_DEVICE Simon Glass
2022-09-14  1:42   ` AKASHI Takahiro
2022-09-14  7:34     ` Heinrich Schuchardt
2022-09-14 17:10       ` Simon Glass
2022-08-12  1:34 ` [PATCH v2 10/24] blk: Select SPL_LEGACY_BLOCK automatically Simon Glass
2022-08-12  1:34 ` [PATCH v2 11/24] blk: Drop unnecessary CONFIG_SPL_LEGACY_BLOCK in defconfigs Simon Glass
2022-08-12  1:34 ` [PATCH v2 12/24] blk: Hide the BLK and SPL_LEGACY_BLOCK options Simon Glass
2022-08-12  1:34 ` [PATCH v2 13/24] blk: Drop IF_TYPE_DOC Simon Glass
2022-08-12  1:34 ` [PATCH v2 14/24] ide: Use a flag for an ATAPI device Simon Glass
2022-08-12  1:34 ` [PATCH v2 15/24] blk: Drop IF_TYPE_ATAPI Simon Glass
2022-08-12  1:34 ` [PATCH v2 16/24] blk: Drop IF_TYPE_SD Simon Glass
2022-08-12  1:34 ` [PATCH v2 17/24] blk: Rename var in blk_get_devnum_by_typename() Simon Glass
2022-08-12  1:34 ` [PATCH v2 18/24] blk: Rewrite if_type to name functions Simon Glass
2022-08-12  1:34 ` [PATCH v2 19/24] efi: Correct assumption about if_type Simon Glass
2022-08-12  1:34 ` [PATCH v2 20/24] blk: Switch over to using uclass IDs Simon Glass
2022-08-12  1:35 ` [PATCH v2 21/24] disk: Handle UCLASS_EFI_MEDIA in dev_print() Simon Glass
2022-08-12  1:35 ` [PATCH v2 22/24] blk: Drop if_type Simon Glass
2022-09-13 16:27   ` Heinrich Schuchardt
2022-09-14  2:08     ` AKASHI Takahiro
2022-09-14  7:45       ` Heinrich Schuchardt
2022-09-14  8:20         ` AKASHI Takahiro
2022-09-14 17:10     ` Simon Glass
2022-08-12  1:35 ` [PATCH v2 23/24] efi: Drop ifname field from struct efi_disk_obj Simon Glass
2022-09-13 16:17   ` Heinrich Schuchardt
2022-08-12  1:35 ` [PATCH v2 24/24] blk: Rename if_type to uclass_id Simon Glass
2022-09-13 16:03   ` Tom Rini
2022-09-14 17:09     ` Simon Glass
2022-09-14  1:22   ` AKASHI Takahiro
2022-08-12 13:51 ` [PATCH v2 00/24] blk: Rationalise the block interface Johan Jonker
2022-08-12 15:11   ` Simon Glass
2022-08-14  6:33     ` Johan Jonker
2022-08-15 17:37       ` 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=20220812013503.1724919-7-sjg@chromium.org \
    --to=sjg@chromium.org \
    --cc=marcel.ziswiler@toradex.com \
    --cc=masahisa.kojima@linaro.org \
    --cc=oleksandr.suvorov@foundries.io \
    --cc=oleksii.bidnichenko@toradex.com \
    --cc=ricardo@foundries.io \
    --cc=schspa@gmail.com \
    --cc=sean.anderson@seco.com \
    --cc=takahiro.akashi@linaro.org \
    --cc=trini@konsulko.com \
    --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.