[RFC 3/7] dm: implement get_dp_node for block devices

Heinrich Schuchardt heinrich.schuchardt at canonical.com
Sun Mar 26 19:27:39 CEST 2023


Generate a Ctrl() node for block devices.

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt at canonical.com>
---
 drivers/block/blk-uclass.c | 56 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 56 insertions(+)

diff --git a/drivers/block/blk-uclass.c b/drivers/block/blk-uclass.c
index c69fc4d518..08202aaaba 100644
--- a/drivers/block/blk-uclass.c
+++ b/drivers/block/blk-uclass.c
@@ -9,6 +9,7 @@
 #include <common.h>
 #include <blk.h>
 #include <dm.h>
+#include <efi_loader.h>
 #include <log.h>
 #include <malloc.h>
 #include <part.h>
@@ -779,9 +780,64 @@ static int blk_post_probe(struct udevice *dev)
 	return 0;
 }
 
+#if CONFIG_IS_ENABLED(EFI_LOADER)
+__maybe_unused
+static struct efi_device_path *blk_scsi_get_dp_node(struct udevice *dev)
+{
+	struct efi_device_path_scsi *dp;
+	struct blk_desc *desc = dev_get_uclass_plat(dev);
+
+	dp = efi_alloc(sizeof(struct efi_device_path_scsi));
+	if (!dp)
+		return NULL;
+
+	dp->dp.type = DEVICE_PATH_TYPE_MESSAGING_DEVICE;
+	dp->dp.sub_type = DEVICE_PATH_SUB_TYPE_MSG_SCSI;
+	dp->dp.length = sizeof(*dp);
+	dp->logical_unit_number = desc->lun;
+	dp->target_id = desc->target;
+
+	return &dp->dp;
+}
+
+static struct efi_device_path *blk_get_dp_node(struct udevice *dev)
+{
+	struct efi_device_path_controller *dp;
+	struct blk_desc *desc = dev_get_uclass_plat(dev);
+	u32 controller_number;
+
+	switch (device_get_uclass_id(dev->parent)) {
+#if CONFIG_IS_ENABLED(SCSI)
+	case UCLASS_SCSI:
+		return blk_scsi_get_dp_node(dev);
+#endif
+	case UCLASS_MMC:
+		dp->controller_number = desc->hwpart;
+		break;
+	default:
+		dp->controller_number = desc->lun;
+		break;
+	}
+
+	dp = efi_alloc(sizeof(struct efi_device_path_controller));
+	if (!dp)
+		return NULL;
+
+	dp->dp.type	      = DEVICE_PATH_TYPE_HARDWARE_DEVICE;
+	dp->dp.sub_type	      = DEVICE_PATH_SUB_TYPE_CONTROLLER;
+	dp->dp.length	      = sizeof(*dp);
+	dp->controller_number = controller_number;
+
+	return &dp->dp;
+}
+#endif
+
 UCLASS_DRIVER(blk) = {
 	.id		= UCLASS_BLK,
 	.name		= "blk",
 	.post_probe	= blk_post_probe,
 	.per_device_plat_auto	= sizeof(struct blk_desc),
+#if CONFIG_IS_ENABLED(EFI_LOADER)
+	.get_dp_node	= blk_get_dp_node,
+#endif
 };
-- 
2.39.2



More information about the U-Boot mailing list