blk: Switch over to using uclass IDs
We currently have an if_type (interface type) and a uclass id. These are
closely related and we don't need to have both.
Drop the if_type values and use the uclass ones instead.
Maintain the existing, subtle, one-way conversion between UCLASS_USB and
UCLASS_MASS_STORAGE for now, and add a comment.
Signed-off-by: Simon Glass <sjg@chromium.org>
diff --git a/arch/arm/mach-stm32mp/cmd_stm32prog/stm32prog.c b/arch/arm/mach-stm32mp/cmd_stm32prog/stm32prog.c
index c391b6c..a720d0b 100644
--- a/arch/arm/mach-stm32mp/cmd_stm32prog/stm32prog.c
+++ b/arch/arm/mach-stm32mp/cmd_stm32prog/stm32prog.c
@@ -1823,7 +1823,7 @@
* need to switch to associated hwpart 1 or 2
*/
if (part->part_id < 0)
- if (blk_select_hwpart_devnum(IF_TYPE_MMC,
+ if (blk_select_hwpart_devnum(UCLASS_MMC,
part->dev->dev_id,
-part->part_id))
return -1;
@@ -1832,7 +1832,7 @@
/* return to user partition */
if (part->part_id < 0)
- blk_select_hwpart_devnum(IF_TYPE_MMC,
+ blk_select_hwpart_devnum(UCLASS_MMC,
part->dev->dev_id, 0);
if (blks != blks_size) {
ret = -1;
diff --git a/board/toradex/common/tdx-cfg-block.c b/board/toradex/common/tdx-cfg-block.c
index 22c67c6..11f4d5e 100644
--- a/board/toradex/common/tdx-cfg-block.c
+++ b/board/toradex/common/tdx-cfg-block.c
@@ -211,7 +211,7 @@
return -EINVAL;
}
if (part != mmc_get_blk_desc(mmc)->hwpart) {
- if (blk_select_hwpart_devnum(IF_TYPE_MMC, dev, part)) {
+ if (blk_select_hwpart_devnum(UCLASS_MMC, dev, part)) {
puts("MMC partition switch failed\n");
ret = -ENODEV;
goto out;
@@ -239,7 +239,7 @@
out:
/* Switch back to regular eMMC user partition */
- blk_select_hwpart_devnum(IF_TYPE_MMC, 0, 0);
+ blk_select_hwpart_devnum(UCLASS_MMC, 0, 0);
return ret;
}
diff --git a/cmd/bcb.c b/cmd/bcb.c
index 1bbd1fa..8b87aa0 100644
--- a/cmd/bcb.c
+++ b/cmd/bcb.c
@@ -122,7 +122,7 @@
char *endp;
int part, ret;
- desc = blk_get_devnum_by_type(IF_TYPE_MMC, devnum);
+ desc = blk_get_devnum_by_type(UCLASS_MMC, devnum);
if (!desc) {
ret = -ENODEV;
goto err_read_fail;
@@ -287,7 +287,7 @@
u64 cnt;
int ret;
- desc = blk_get_devnum_by_type(IF_TYPE_MMC, bcb_dev);
+ desc = blk_get_devnum_by_type(UCLASS_MMC, bcb_dev);
if (!desc) {
ret = -ENODEV;
goto err;
diff --git a/cmd/ide.c b/cmd/ide.c
index b78c38e..6739f0b 100644
--- a/cmd/ide.c
+++ b/cmd/ide.c
@@ -37,7 +37,7 @@
}
}
- return blk_common_cmd(argc, argv, IF_TYPE_IDE, &curr_device);
+ return blk_common_cmd(argc, argv, UCLASS_IDE, &curr_device);
}
int do_diskboot(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
diff --git a/cmd/mmc.c b/cmd/mmc.c
index 7bd4cd9..0f1f4e0 100644
--- a/cmd/mmc.c
+++ b/cmd/mmc.c
@@ -331,13 +331,13 @@
#else
original_part = mmc_get_blk_desc(mmc)->hwpart;
#endif
- if (blk_select_hwpart_devnum(IF_TYPE_MMC, curr_device, MMC_PART_RPMB) !=
+ if (blk_select_hwpart_devnum(UCLASS_MMC, curr_device, MMC_PART_RPMB) !=
0)
return CMD_RET_FAILURE;
ret = cp->cmd(cmdtp, flag, argc, argv);
/* Return to original partition */
- if (blk_select_hwpart_devnum(IF_TYPE_MMC, curr_device, original_part) !=
+ if (blk_select_hwpart_devnum(UCLASS_MMC, curr_device, original_part) !=
0)
return CMD_RET_FAILURE;
return ret;
@@ -530,7 +530,7 @@
if (!mmc)
return CMD_RET_FAILURE;
- mmc_dev = blk_get_devnum_by_type(IF_TYPE_MMC, curr_device);
+ mmc_dev = blk_get_devnum_by_type(UCLASS_MMC, curr_device);
if (mmc_dev != NULL && mmc_dev->type != DEV_TYPE_UNKNOWN) {
part_print(mmc_dev);
return CMD_RET_SUCCESS;
@@ -580,7 +580,7 @@
if (!mmc)
return CMD_RET_FAILURE;
- ret = blk_select_hwpart_devnum(IF_TYPE_MMC, dev, part);
+ ret = blk_select_hwpart_devnum(UCLASS_MMC, dev, part);
printf("switch to partitions #%d, %s\n",
part, (!ret) ? "OK" : "ERROR");
if (ret)
diff --git a/cmd/mvebu/bubt.c b/cmd/mvebu/bubt.c
index 2136af6..825d4be 100644
--- a/cmd/mvebu/bubt.c
+++ b/cmd/mvebu/bubt.c
@@ -412,7 +412,7 @@
}
/* Try to recognize storage devices immediately */
- blk_first_device(IF_TYPE_USB, &dev);
+ blk_first_device(UCLASS_USB, &dev);
if (!dev) {
printf("Error: USB storage device not found\n");
return 0;
diff --git a/cmd/nvme.c b/cmd/nvme.c
index e715c57..09d5f43 100644
--- a/cmd/nvme.c
+++ b/cmd/nvme.c
@@ -28,7 +28,7 @@
if (strncmp(argv[1], "deta", 4) == 0) {
struct udevice *udev;
- ret = blk_get_device(IF_TYPE_NVME, nvme_curr_dev,
+ ret = blk_get_device(UCLASS_NVME, nvme_curr_dev,
&udev);
if (ret < 0)
return CMD_RET_FAILURE;
@@ -39,7 +39,7 @@
}
}
- return blk_common_cmd(argc, argv, IF_TYPE_NVME, &nvme_curr_dev);
+ return blk_common_cmd(argc, argv, UCLASS_NVME, &nvme_curr_dev);
}
U_BOOT_CMD(
diff --git a/cmd/pvblock.c b/cmd/pvblock.c
index 56ce8b1..1b604c3 100644
--- a/cmd/pvblock.c
+++ b/cmd/pvblock.c
@@ -14,7 +14,7 @@
int do_pvblock(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
{
- return blk_common_cmd(argc, argv, IF_TYPE_PVBLOCK,
+ return blk_common_cmd(argc, argv, UCLASS_PVBLOCK,
&pvblock_curr_device);
}
diff --git a/cmd/sata.c b/cmd/sata.c
index 76da190..9c9fe11 100644
--- a/cmd/sata.c
+++ b/cmd/sata.c
@@ -27,7 +27,7 @@
struct udevice *dev;
int rc;
- blk_unbind_all(IF_TYPE_SATA);
+ blk_unbind_all(UCLASS_AHCI);
rc = uclass_find_device(UCLASS_AHCI, devnum, &dev);
if (!rc && !dev)
@@ -111,7 +111,7 @@
sata_curr_device = 0;
}
- return blk_common_cmd(argc, argv, IF_TYPE_SATA, &sata_curr_device);
+ return blk_common_cmd(argc, argv, UCLASS_AHCI, &sata_curr_device);
}
U_BOOT_CMD(
diff --git a/cmd/scsi.c b/cmd/scsi.c
index 5f710d2..4549995 100644
--- a/cmd/scsi.c
+++ b/cmd/scsi.c
@@ -50,7 +50,7 @@
}
}
- return blk_common_cmd(argc, argv, IF_TYPE_SCSI, &scsi_curr_dev);
+ return blk_common_cmd(argc, argv, UCLASS_SCSI, &scsi_curr_dev);
}
U_BOOT_CMD(
diff --git a/cmd/usb.c b/cmd/usb.c
index 3d87376..2ba0569 100644
--- a/cmd/usb.c
+++ b/cmd/usb.c
@@ -719,7 +719,7 @@
if (strncmp(argv[1], "stor", 4) == 0)
return usb_stor_info();
- return blk_common_cmd(argc, argv, IF_TYPE_USB, &usb_stor_curr_dev);
+ return blk_common_cmd(argc, argv, UCLASS_USB, &usb_stor_curr_dev);
#else
return CMD_RET_USAGE;
#endif /* CONFIG_USB_STORAGE */
diff --git a/cmd/virtio.c b/cmd/virtio.c
index ea3ed2e..ec87d4f 100644
--- a/cmd/virtio.c
+++ b/cmd/virtio.c
@@ -40,7 +40,7 @@
return CMD_RET_SUCCESS;
}
- return blk_common_cmd(argc, argv, IF_TYPE_VIRTIO, &virtio_curr_dev);
+ return blk_common_cmd(argc, argv, UCLASS_VIRTIO, &virtio_curr_dev);
}
U_BOOT_CMD(
diff --git a/common/spl/spl_sata.c b/common/spl/spl_sata.c
index 1351d78..ea9f175 100644
--- a/common/spl/spl_sata.c
+++ b/common/spl/spl_sata.c
@@ -71,7 +71,7 @@
/* try to recognize storage devices immediately */
scsi_scan(false);
- stor_dev = blk_get_devnum_by_type(IF_TYPE_SCSI, 0);
+ stor_dev = blk_get_devnum_by_type(UCLASS_SCSI, 0);
if (!stor_dev)
return -ENODEV;
diff --git a/common/spl/spl_usb.c b/common/spl/spl_usb.c
index ccf01c8..63c00f8 100644
--- a/common/spl/spl_usb.c
+++ b/common/spl/spl_usb.c
@@ -41,7 +41,7 @@
/* try to recognize storage devices immediately */
usb_stor_curr_dev = usb_stor_scan(1);
- stor_dev = blk_get_devnum_by_type(IF_TYPE_USB, usb_stor_curr_dev);
+ stor_dev = blk_get_devnum_by_type(UCLASS_USB, usb_stor_curr_dev);
if (!stor_dev)
return -ENODEV;
diff --git a/common/usb_storage.c b/common/usb_storage.c
index eaa3137..7d42016 100644
--- a/common/usb_storage.c
+++ b/common/usb_storage.c
@@ -144,7 +144,7 @@
#if CONFIG_IS_ENABLED(BLK)
struct udevice *dev;
- for (blk_first_device(IF_TYPE_USB, &dev);
+ for (blk_first_device(UCLASS_USB, &dev);
dev;
blk_next_device(&dev)) {
struct blk_desc *desc = dev_get_uclass_plat(dev);
@@ -219,7 +219,7 @@
snprintf(str, sizeof(str), "lun%d", lun);
ret = blk_create_devicef(udev->dev, "usb_storage_blk", str,
- IF_TYPE_USB, usb_max_devs, 512, 0,
+ UCLASS_USB, usb_max_devs, 512, 0,
&dev);
if (ret) {
debug("Cannot bind driver\n");
@@ -279,7 +279,7 @@
blkdev = &usb_dev_desc[usb_max_devs];
memset(blkdev, '\0', sizeof(struct blk_desc));
- blkdev->if_type = IF_TYPE_USB;
+ blkdev->if_type = UCLASS_USB;
blkdev->devnum = usb_max_devs;
blkdev->part_type = PART_TYPE_UNKNOWN;
blkdev->target = 0xff;
@@ -1578,7 +1578,7 @@
#else
U_BOOT_LEGACY_BLK(usb) = {
.if_typename = "usb",
- .if_type = IF_TYPE_USB,
+ .if_type = UCLASS_USB,
.max_devs = USB_MAX_STOR_DEV,
.desc = usb_dev_desc,
};
diff --git a/disk/part.c b/disk/part.c
index 2bcc6f4..75aff7e 100644
--- a/disk/part.c
+++ b/disk/part.c
@@ -121,34 +121,34 @@
}
switch (dev_desc->if_type) {
- case IF_TYPE_SCSI:
+ case UCLASS_SCSI:
printf ("(%d:%d) Vendor: %s Prod.: %s Rev: %s\n",
dev_desc->target,dev_desc->lun,
dev_desc->vendor,
dev_desc->product,
dev_desc->revision);
break;
- case IF_TYPE_IDE:
- case IF_TYPE_SATA:
+ case UCLASS_IDE:
+ case UCLASS_AHCI:
printf ("Model: %s Firm: %s Ser#: %s\n",
dev_desc->vendor,
dev_desc->revision,
dev_desc->product);
break;
- case IF_TYPE_MMC:
- case IF_TYPE_USB:
- case IF_TYPE_NVME:
- case IF_TYPE_PVBLOCK:
- case IF_TYPE_HOST:
+ case UCLASS_MMC:
+ case UCLASS_USB:
+ case UCLASS_NVME:
+ case UCLASS_PVBLOCK:
+ case UCLASS_ROOT:
printf ("Vendor: %s Rev: %s Prod: %s\n",
dev_desc->vendor,
dev_desc->revision,
dev_desc->product);
break;
- case IF_TYPE_VIRTIO:
+ case UCLASS_VIRTIO:
printf("%s VirtIO Block Device\n", dev_desc->vendor);
break;
- case IF_TYPE_UNKNOWN:
+ case UCLASS_INVALID:
puts("device type unknown\n");
return;
default:
@@ -246,34 +246,34 @@
CONFIG_IS_ENABLED(EFI_PARTITION)
puts ("\nPartition Map for ");
switch (dev_desc->if_type) {
- case IF_TYPE_IDE:
+ case UCLASS_IDE:
puts ("IDE");
break;
- case IF_TYPE_SATA:
+ case UCLASS_AHCI:
puts ("SATA");
break;
- case IF_TYPE_SCSI:
+ case UCLASS_SCSI:
puts ("SCSI");
break;
- case IF_TYPE_USB:
+ case UCLASS_USB:
puts ("USB");
break;
- case IF_TYPE_MMC:
+ case UCLASS_MMC:
puts ("MMC");
break;
- case IF_TYPE_HOST:
+ case UCLASS_ROOT:
puts ("HOST");
break;
- case IF_TYPE_NVME:
+ case UCLASS_NVME:
puts ("NVMe");
break;
- case IF_TYPE_PVBLOCK:
+ case UCLASS_PVBLOCK:
puts("PV BLOCK");
break;
- case IF_TYPE_VIRTIO:
+ case UCLASS_VIRTIO:
puts("VirtIO");
break;
- case IF_TYPE_EFI_MEDIA:
+ case UCLASS_EFI_MEDIA:
puts("EFI");
break;
default:
@@ -405,7 +405,7 @@
* 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)
+ if ((*dev_desc)->if_type == UCLASS_MMC)
part_init(*dev_desc);
}
@@ -760,17 +760,17 @@
char *devtype;
switch (dev_desc->if_type) {
- case IF_TYPE_IDE:
- case IF_TYPE_SATA:
+ case UCLASS_IDE:
+ case UCLASS_AHCI:
devtype = "hd";
break;
- case IF_TYPE_SCSI:
+ case UCLASS_SCSI:
devtype = "sd";
break;
- case IF_TYPE_USB:
+ case UCLASS_USB:
devtype = "usbd";
break;
- case IF_TYPE_MMC:
+ case UCLASS_MMC:
devtype = "mmcsd";
break;
default:
diff --git a/doc/develop/uefi/uefi.rst b/doc/develop/uefi/uefi.rst
index 941e427..cd84706 100644
--- a/doc/develop/uefi/uefi.rst
+++ b/doc/develop/uefi/uefi.rst
@@ -748,7 +748,7 @@
The UEFI block IO driver supports devices exposing the EFI_BLOCK_IO_PROTOCOL.
When connected it creates a new U-Boot block IO device with interface type
-IF_TYPE_EFI_LOADER, adds child controllers mapping the partitions, and installs
+UCLASS_EFI_LOADER, adds child controllers mapping the partitions, and installs
the EFI_SIMPLE_FILE_SYSTEM_PROTOCOL on these. This can be used together with the
software iPXE to boot from iSCSI network drives [4].
diff --git a/drivers/ata/dwc_ahsata.c b/drivers/ata/dwc_ahsata.c
index 1a2c3c2..167b5a3 100644
--- a/drivers/ata/dwc_ahsata.c
+++ b/drivers/ata/dwc_ahsata.c
@@ -880,7 +880,7 @@
device_find_first_child(dev, &blk);
if (!blk) {
ret = blk_create_devicef(dev, "dwc_ahsata_blk", "blk",
- IF_TYPE_SATA, -1, 512, 0, &blk);
+ UCLASS_AHCI, -1, 512, 0, &blk);
if (ret) {
debug("Can't create device\n");
return ret;
diff --git a/drivers/ata/fsl_sata.c b/drivers/ata/fsl_sata.c
index 6db4247..972101b 100644
--- a/drivers/ata/fsl_sata.c
+++ b/drivers/ata/fsl_sata.c
@@ -888,7 +888,7 @@
for (i = 0; i < nr_ports; i++) {
snprintf(sata_name, sizeof(sata_name), "fsl_sata%d", i);
ret = blk_create_devicef(dev, "sata_fsl_blk", sata_name,
- IF_TYPE_SATA, -1, 512, 0, &blk);
+ UCLASS_AHCI, -1, 512, 0, &blk);
if (ret) {
debug("Can't create device\n");
return ret;
diff --git a/drivers/ata/sata.c b/drivers/ata/sata.c
index 0e6c8cd..604c721 100644
--- a/drivers/ata/sata.c
+++ b/drivers/ata/sata.c
@@ -79,7 +79,7 @@
for (i = 0; i < CONFIG_SYS_SATA_MAX_DEVICE; i++) {
memset(&sata_dev_desc[i], 0, sizeof(struct blk_desc));
- sata_dev_desc[i].if_type = IF_TYPE_SATA;
+ sata_dev_desc[i].if_type = UCLASS_AHCI;
sata_dev_desc[i].devnum = i;
sata_dev_desc[i].part_type = PART_TYPE_UNKNOWN;
sata_dev_desc[i].type = DEV_TYPE_HARDDISK;
diff --git a/drivers/ata/sata_mv.c b/drivers/ata/sata_mv.c
index a187796..18c7a66 100644
--- a/drivers/ata/sata_mv.c
+++ b/drivers/ata/sata_mv.c
@@ -1076,7 +1076,7 @@
for (i = 0; i < nr_ports; i++) {
ret = blk_create_devicef(dev, "sata_mv_blk", "blk",
- IF_TYPE_SATA, -1, 512, 0, &blk);
+ UCLASS_AHCI, -1, 512, 0, &blk);
if (ret) {
debug("Can't create device\n");
continue;
diff --git a/drivers/ata/sata_sil.c b/drivers/ata/sata_sil.c
index 7065154..b5e150d 100644
--- a/drivers/ata/sata_sil.c
+++ b/drivers/ata/sata_sil.c
@@ -730,7 +730,7 @@
for (i = sata_info.portbase; i < sata_info.maxport; i++) {
snprintf(sata_name, sizeof(sata_name), "sil_sata%d", i);
ret = blk_create_devicef(dev, "sata_sil_blk", sata_name,
- IF_TYPE_SATA, -1, 512, 0, &blk);
+ UCLASS_AHCI, -1, 512, 0, &blk);
if (ret) {
debug("Can't create device\n");
return ret;
diff --git a/drivers/block/blk-uclass.c b/drivers/block/blk-uclass.c
index a68158c..436af76 100644
--- a/drivers/block/blk-uclass.c
+++ b/drivers/block/blk-uclass.c
@@ -21,33 +21,19 @@
enum uclass_id id;
const char *name;
} if_typename_str[] = {
- { IF_TYPE_IDE, "ide" },
- { IF_TYPE_SCSI, "scsi" },
- { IF_TYPE_USB, "usb" },
- { IF_TYPE_MMC, "mmc" },
- { IF_TYPE_SCSI, "sata" },
- { IF_TYPE_HOST, "host" },
- { IF_TYPE_NVME, "nvme" },
- { IF_TYPE_EFI_MEDIA, "efi" },
- { IF_TYPE_EFI_LOADER, "efiloader" },
- { IF_TYPE_VIRTIO, "virtio" },
- { IF_TYPE_PVBLOCK, "pvblock" },
+ { UCLASS_IDE, "ide" },
+ { UCLASS_SCSI, "scsi" },
+ { UCLASS_USB, "usb" },
+ { UCLASS_MMC, "mmc" },
+ { UCLASS_AHCI, "sata" },
+ { UCLASS_ROOT, "host" },
+ { UCLASS_NVME, "nvme" },
+ { UCLASS_EFI_MEDIA, "efi" },
+ { UCLASS_EFI_LOADER, "efiloader" },
+ { UCLASS_VIRTIO, "virtio" },
+ { UCLASS_PVBLOCK, "pvblock" },
};
-static enum uclass_id if_type_uclass_id[IF_TYPE_COUNT] = {
- [IF_TYPE_IDE] = UCLASS_IDE,
- [IF_TYPE_SCSI] = UCLASS_SCSI,
- [IF_TYPE_USB] = UCLASS_MASS_STORAGE,
- [IF_TYPE_MMC] = UCLASS_MMC,
- [IF_TYPE_SATA] = UCLASS_AHCI,
- [IF_TYPE_HOST] = UCLASS_ROOT,
- [IF_TYPE_NVME] = UCLASS_NVME,
- [IF_TYPE_EFI_MEDIA] = UCLASS_EFI_MEDIA,
- [IF_TYPE_EFI_LOADER] = UCLASS_EFI_LOADER,
- [IF_TYPE_VIRTIO] = UCLASS_VIRTIO,
- [IF_TYPE_PVBLOCK] = UCLASS_PVBLOCK,
-};
-
static enum if_type if_typename_to_iftype(const char *if_typename)
{
int i;
@@ -57,12 +43,32 @@
return if_typename_str[i].id;
}
- return IF_TYPE_UNKNOWN;
+ return UCLASS_INVALID;
}
static enum uclass_id if_type_to_uclass_id(enum if_type if_type)
{
- return if_type_uclass_id[if_type];
+ /*
+ * This strange adjustment is used because we use UCLASS_MASS_STORAGE
+ * for USB storage devices, so need to return this as the uclass to
+ * use for USB. In fact USB_UCLASS is for USB controllers, not
+ * peripherals.
+ *
+ * The name of the UCLASS_MASS_STORAGE uclass driver is
+ * "usb_mass_storage", but we want to use "usb" in things like the
+ * 'part list' command and when showing interfaces.
+ *
+ * So for now we have this one-way conversion.
+ *
+ * The fix for this is possibly to:
+ * - rename UCLASS_MASS_STORAGE name to "usb"
+ * - rename UCLASS_USB name to "usb_ctlr"
+ * - use UCLASS_MASS_STORAGE instead of UCLASS_USB in if_typename_str
+ */
+ if (if_type == UCLASS_USB)
+ return UCLASS_MASS_STORAGE;
+
+ return if_type;
}
const char *blk_get_if_type_name(enum if_type if_type)
@@ -70,7 +76,7 @@
int i;
for (i = 0; i < ARRAY_SIZE(if_typename_str); i++) {
- if ((int)if_typename_str[i].id == if_type)
+ if (if_typename_str[i].id == if_type)
return if_typename_str[i].name;
}
@@ -105,7 +111,7 @@
int ret;
type = if_typename_to_iftype(if_typename);
- if (type == IF_TYPE_UNKNOWN) {
+ if (type == UCLASS_INVALID) {
debug("%s: Unknown interface type '%s'\n", __func__,
if_typename);
return NULL;
diff --git a/drivers/block/efi_blk.c b/drivers/block/efi_blk.c
index 9d25ecb..917a19f 100644
--- a/drivers/block/efi_blk.c
+++ b/drivers/block/efi_blk.c
@@ -94,7 +94,7 @@
struct udevice *blk;
int ret;
- ret = blk_create_devicef(dev, "efi_block", "blk", IF_TYPE_EFI_MEDIA,
+ ret = blk_create_devicef(dev, "efi_block", "blk", UCLASS_EFI_MEDIA,
dev_seq(dev), plat->blkio->media->block_size,
plat->blkio->media->last_block, &blk);
if (ret) {
diff --git a/drivers/block/ide.c b/drivers/block/ide.c
index 6bc48e3..73da29a 100644
--- a/drivers/block/ide.c
+++ b/drivers/block/ide.c
@@ -537,7 +537,7 @@
/* Select device
*/
ide_outb(device, ATA_DEV_HD, ATA_LBA | ATA_DEVICE(device));
- dev_desc->if_type = IF_TYPE_IDE;
+ dev_desc->if_type = UCLASS_IDE;
#ifdef CONFIG_ATAPI
retries = 0;
@@ -752,7 +752,7 @@
for (i = 0; i < CONFIG_SYS_IDE_MAXDEVICE; ++i) {
ide_dev_desc[i].type = DEV_TYPE_UNKNOWN;
- ide_dev_desc[i].if_type = IF_TYPE_IDE;
+ ide_dev_desc[i].if_type = UCLASS_IDE;
ide_dev_desc[i].devnum = i;
ide_dev_desc[i].part_type = PART_TYPE_UNKNOWN;
ide_dev_desc[i].blksz = 0;
@@ -1110,7 +1110,7 @@
if (!blksz)
continue;
ret = blk_create_devicef(udev, "ide_blk", name,
- IF_TYPE_IDE, i,
+ UCLASS_IDE, i,
blksz, size, &blk_dev);
if (ret)
return ret;
@@ -1144,7 +1144,7 @@
#else
U_BOOT_LEGACY_BLK(ide) = {
.if_typename = "ide",
- .if_type = IF_TYPE_IDE,
+ .if_type = UCLASS_IDE,
.max_devs = CONFIG_SYS_IDE_MAXDEVICE,
.desc = ide_dev_desc,
};
diff --git a/drivers/block/sandbox.c b/drivers/block/sandbox.c
index 1388498..2de12e0 100644
--- a/drivers/block/sandbox.c
+++ b/drivers/block/sandbox.c
@@ -98,7 +98,7 @@
int ret, fd;
/* Remove and unbind the old device, if any */
- ret = blk_get_device(IF_TYPE_HOST, devnum, &dev);
+ ret = blk_get_device(UCLASS_ROOT, devnum, &dev);
if (ret == 0) {
ret = device_remove(dev, DM_REMOVE_NORMAL);
if (ret)
@@ -135,7 +135,7 @@
}
}
ret = blk_create_device(gd->dm_root, "sandbox_host_blk", str,
- IF_TYPE_HOST, devnum, 512,
+ UCLASS_ROOT, devnum, 512,
os_lseek(fd, 0, OS_SEEK_END) / 512, &dev);
if (ret)
goto err_file;
@@ -150,7 +150,7 @@
goto err_file;
}
- desc = blk_get_devnum_by_type(IF_TYPE_HOST, devnum);
+ desc = blk_get_devnum_by_type(UCLASS_ROOT, devnum);
desc->removable = removable;
snprintf(desc->vendor, BLK_VEN_SIZE, "U-Boot");
snprintf(desc->product, BLK_PRD_SIZE, "hostfile");
@@ -192,7 +192,7 @@
}
struct blk_desc *blk_dev = &host_dev->blk_dev;
- blk_dev->if_type = IF_TYPE_HOST;
+ blk_dev->if_type = UCLASS_ROOT;
blk_dev->priv = host_dev;
blk_dev->blksz = 512;
blk_dev->lba = os_lseek(host_dev->fd, 0, OS_SEEK_END) / blk_dev->blksz;
@@ -216,7 +216,7 @@
struct udevice *dev;
int ret;
- ret = blk_get_device(IF_TYPE_HOST, devnum, &dev);
+ ret = blk_get_device(UCLASS_ROOT, devnum, &dev);
if (ret)
return ret;
*blk_devp = dev_get_uclass_plat(dev);
@@ -263,7 +263,7 @@
#else
U_BOOT_LEGACY_BLK(sandbox_host) = {
.if_typename = "host",
- .if_type = IF_TYPE_HOST,
+ .if_type = UCLASS_ROOT,
.max_devs = SANDBOX_HOST_MAX_DEVICES,
.get_dev = host_get_dev_err,
};
diff --git a/drivers/dfu/dfu_mmc.c b/drivers/dfu/dfu_mmc.c
index a91da97..f583208 100644
--- a/drivers/dfu/dfu_mmc.c
+++ b/drivers/dfu/dfu_mmc.c
@@ -52,7 +52,7 @@
if (dfu->data.mmc.hw_partition >= 0) {
part_num_bkp = mmc_get_blk_desc(mmc)->hwpart;
- ret = blk_select_hwpart_devnum(IF_TYPE_MMC,
+ ret = blk_select_hwpart_devnum(UCLASS_MMC,
dfu->data.mmc.dev_num,
dfu->data.mmc.hw_partition);
if (ret)
@@ -77,14 +77,14 @@
if (n != blk_count) {
pr_err("MMC operation failed");
if (dfu->data.mmc.hw_partition >= 0)
- blk_select_hwpart_devnum(IF_TYPE_MMC,
+ blk_select_hwpart_devnum(UCLASS_MMC,
dfu->data.mmc.dev_num,
part_num_bkp);
return -EIO;
}
if (dfu->data.mmc.hw_partition >= 0) {
- ret = blk_select_hwpart_devnum(IF_TYPE_MMC,
+ ret = blk_select_hwpart_devnum(UCLASS_MMC,
dfu->data.mmc.dev_num,
part_num_bkp);
if (ret)
diff --git a/drivers/mmc/mmc-uclass.c b/drivers/mmc/mmc-uclass.c
index 688bdc0..b1bd4ae 100644
--- a/drivers/mmc/mmc-uclass.c
+++ b/drivers/mmc/mmc-uclass.c
@@ -290,7 +290,7 @@
struct udevice *dev, *mmc_dev;
int ret;
- ret = blk_find_device(IF_TYPE_MMC, dev_num, &dev);
+ ret = blk_find_device(UCLASS_MMC, dev_num, &dev);
if (ret) {
#if !defined(CONFIG_SPL_BUILD) || defined(CONFIG_SPL_LIBCOMMON_SUPPORT)
@@ -308,12 +308,12 @@
int get_mmc_num(void)
{
- return max((blk_find_max_devnum(IF_TYPE_MMC) + 1), 0);
+ return max((blk_find_max_devnum(UCLASS_MMC) + 1), 0);
}
int mmc_get_next_devnum(void)
{
- return blk_find_max_devnum(IF_TYPE_MMC);
+ return blk_find_max_devnum(UCLASS_MMC);
}
int mmc_get_blk(struct udevice *dev, struct udevice **blkp)
@@ -411,8 +411,8 @@
/* Use the fixed index with aliases node's index */
debug("%s: alias devnum=%d\n", __func__, dev_seq(dev));
- ret = blk_create_devicef(dev, "mmc_blk", "blk", IF_TYPE_MMC,
- dev_seq(dev), 512, 0, &bdev);
+ ret = blk_create_devicef(dev, "mmc_blk", "blk", UCLASS_MMC,
+ dev_seq(dev), 512, 0, &bdev);
if (ret) {
debug("Cannot create block device\n");
return ret;
diff --git a/drivers/mmc/mmc_legacy.c b/drivers/mmc/mmc_legacy.c
index a05da6c..4e0891e 100644
--- a/drivers/mmc/mmc_legacy.c
+++ b/drivers/mmc/mmc_legacy.c
@@ -132,7 +132,7 @@
.dsr_imp = 0,
.dsr = 0xffffffff,
.block_dev = {
- .if_type = IF_TYPE_MMC,
+ .if_type = UCLASS_MMC,
.removable = 1,
.devnum = 0,
.block_read = mmc_bread,
@@ -194,7 +194,7 @@
mmc->dsr = 0xffffffff;
/* Setup the universal parts of the block interface just once */
bdesc = mmc_get_blk_desc(mmc);
- bdesc->if_type = IF_TYPE_MMC;
+ bdesc->if_type = UCLASS_MMC;
bdesc->removable = 1;
bdesc->devnum = mmc_get_next_devnum();
bdesc->block_read = mmc_bread;
@@ -254,7 +254,7 @@
U_BOOT_LEGACY_BLK(mmc) = {
.if_typename = "mmc",
- .if_type = IF_TYPE_MMC,
+ .if_type = UCLASS_MMC,
.max_devs = -1,
.get_dev = mmc_get_dev,
.select_hwpart = mmc_select_hwpartp,
diff --git a/drivers/mmc/mmc_write.c b/drivers/mmc/mmc_write.c
index eab94c7..5b7aeeb 100644
--- a/drivers/mmc/mmc_write.c
+++ b/drivers/mmc/mmc_write.c
@@ -85,7 +85,7 @@
if (!mmc)
return -1;
- err = blk_select_hwpart_devnum(IF_TYPE_MMC, dev_num,
+ err = blk_select_hwpart_devnum(UCLASS_MMC, dev_num,
block_dev->hwpart);
if (err < 0)
return -1;
@@ -203,7 +203,7 @@
if (!mmc)
return 0;
- err = blk_select_hwpart_devnum(IF_TYPE_MMC, dev_num, block_dev->hwpart);
+ err = blk_select_hwpart_devnum(UCLASS_MMC, dev_num, block_dev->hwpart);
if (err < 0)
return 0;
diff --git a/drivers/nvme/nvme.c b/drivers/nvme/nvme.c
index 31cf700..3510f79 100644
--- a/drivers/nvme/nvme.c
+++ b/drivers/nvme/nvme.c
@@ -880,7 +880,7 @@
sprintf(name, "blk#%d", i);
/* The real blksz and size will be set by nvme_blk_probe() */
- ret = blk_create_devicef(udev, "nvme-blk", name, IF_TYPE_NVME,
+ ret = blk_create_devicef(udev, "nvme-blk", name, UCLASS_NVME,
-1, 512, 0, &ns_udev);
if (ret)
goto free_id;
diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
index 78d729d..99be5ae 100644
--- a/drivers/scsi/scsi.c
+++ b/drivers/scsi/scsi.c
@@ -456,7 +456,7 @@
{
dev_desc->lba = 0;
dev_desc->blksz = 0;
- dev_desc->if_type = IF_TYPE_SCSI;
+ dev_desc->if_type = UCLASS_SCSI;
dev_desc->devnum = devnum;
dev_desc->part_type = PART_TYPE_UNKNOWN;
@@ -574,8 +574,8 @@
* block devices created
*/
snprintf(str, sizeof(str), "id%dlun%d", id, lun);
- ret = blk_create_devicef(dev, "scsi_blk", str, IF_TYPE_SCSI, -1,
- bd.blksz, bd.lba, &bdev);
+ ret = blk_create_devicef(dev, "scsi_blk", str, UCLASS_SCSI, -1,
+ bd.blksz, bd.lba, &bdev);
if (ret) {
debug("Can't create device\n");
return ret;
@@ -638,7 +638,7 @@
if (verbose)
printf("scanning bus for devices...\n");
- blk_unbind_all(IF_TYPE_SCSI);
+ blk_unbind_all(UCLASS_SCSI);
ret = uclass_get(UCLASS_SCSI, &uc);
if (ret)
@@ -707,7 +707,7 @@
#else
U_BOOT_LEGACY_BLK(scsi) = {
.if_typename = "scsi",
- .if_type = IF_TYPE_SCSI,
+ .if_type = UCLASS_SCSI,
.max_devs = SCSI_MAX_DEVICE,
.desc = scsi_dev_desc,
};
diff --git a/drivers/tee/optee/rpmb.c b/drivers/tee/optee/rpmb.c
index cf5e0a0..5bc1375 100644
--- a/drivers/tee/optee/rpmb.c
+++ b/drivers/tee/optee/rpmb.c
@@ -48,7 +48,7 @@
if (!priv->rpmb_mmc)
return;
- rc = blk_select_hwpart_devnum(IF_TYPE_MMC, priv->rpmb_dev_id,
+ rc = blk_select_hwpart_devnum(UCLASS_MMC, priv->rpmb_dev_id,
priv->rpmb_original_part);
if (rc)
debug("%s: blk_select_hwpart_devnum() failed: %d\n",
@@ -88,7 +88,7 @@
priv->rpmb_original_part = mmc_get_blk_desc(mmc)->hwpart;
- rc = blk_select_hwpart_devnum(IF_TYPE_MMC, dev_id, MMC_PART_RPMB);
+ rc = blk_select_hwpart_devnum(UCLASS_MMC, dev_id, MMC_PART_RPMB);
if (rc) {
debug("Device id %d: cannot select RPMB partition: %d\n",
dev_id, rc);
diff --git a/drivers/virtio/virtio_blk.c b/drivers/virtio/virtio_blk.c
index 3ff74f4..9710b79 100644
--- a/drivers/virtio/virtio_blk.c
+++ b/drivers/virtio/virtio_blk.c
@@ -75,14 +75,14 @@
struct blk_desc *desc = dev_get_uclass_plat(dev);
int devnum;
- desc->if_type = IF_TYPE_VIRTIO;
+ desc->if_type = UCLASS_VIRTIO;
/*
* Initialize the devnum to -ENODEV. This is to make sure that
* blk_next_free_devnum() works as expected, since the default
* value 0 is a valid devnum.
*/
desc->devnum = -ENODEV;
- devnum = blk_next_free_devnum(IF_TYPE_VIRTIO);
+ devnum = blk_next_free_devnum(UCLASS_VIRTIO);
if (devnum < 0)
return devnum;
desc->devnum = devnum;
diff --git a/drivers/xen/pvblock.c b/drivers/xen/pvblock.c
index c25c3ea..1090e52 100644
--- a/drivers/xen/pvblock.c
+++ b/drivers/xen/pvblock.c
@@ -665,14 +665,14 @@
struct blk_desc *desc = dev_get_uclass_plat(udev);
int devnum;
- desc->if_type = IF_TYPE_PVBLOCK;
+ desc->if_type = UCLASS_PVBLOCK;
/*
* Initialize the devnum to -ENODEV. This is to make sure that
* blk_next_free_devnum() works as expected, since the default
* value 0 is a valid devnum.
*/
desc->devnum = -ENODEV;
- devnum = blk_next_free_devnum(IF_TYPE_PVBLOCK);
+ devnum = blk_next_free_devnum(UCLASS_PVBLOCK);
if (devnum < 0)
return devnum;
desc->devnum = devnum;
@@ -804,7 +804,7 @@
const char *class_name;
class_name = uclass_get_name(UCLASS_PVBLOCK);
- for (blk_first_device(IF_TYPE_PVBLOCK, &udev); udev;
+ for (blk_first_device(UCLASS_PVBLOCK, &udev); udev;
blk_next_device(&udev), first = false) {
struct blk_desc *desc = dev_get_uclass_plat(udev);
diff --git a/env/mmc.c b/env/mmc.c
index 0c498d9..c28f4c6 100644
--- a/env/mmc.c
+++ b/env/mmc.c
@@ -143,7 +143,7 @@
int dev = mmc_get_env_dev();
int ret = 0;
- ret = blk_select_hwpart_devnum(IF_TYPE_MMC, dev, part);
+ ret = blk_select_hwpart_devnum(UCLASS_MMC, dev, part);
if (ret)
puts("MMC partition switch failed\n");
@@ -179,7 +179,7 @@
#ifdef CONFIG_SYS_MMC_ENV_PART
int dev = mmc_get_env_dev();
- blk_select_hwpart_devnum(IF_TYPE_MMC, dev, env_mmc_orig_hwpart);
+ blk_select_hwpart_devnum(UCLASS_MMC, dev, env_mmc_orig_hwpart);
#endif
}
diff --git a/include/blk.h b/include/blk.h
index cc30e38..548cd09 100644
--- a/include/blk.h
+++ b/include/blk.h
@@ -7,6 +7,7 @@
#ifndef BLK_H
#define BLK_H
+#include <dm/uclass-id.h>
#include <efi.h>
#ifdef CONFIG_SYS_64BIT_LBA
@@ -27,22 +28,7 @@
}
/* Interface types: */
-enum if_type {
- IF_TYPE_UNKNOWN = 0,
- IF_TYPE_IDE,
- IF_TYPE_SCSI,
- IF_TYPE_USB,
- IF_TYPE_MMC,
- IF_TYPE_SATA,
- IF_TYPE_HOST,
- IF_TYPE_NVME,
- IF_TYPE_EFI_LOADER,
- IF_TYPE_PVBLOCK,
- IF_TYPE_VIRTIO,
- IF_TYPE_EFI_MEDIA,
-
- IF_TYPE_COUNT, /* Number of interface types */
-};
+#define if_type uclass_id
#define BLK_VEN_SIZE 40
#define BLK_PRD_SIZE 20
diff --git a/include/mmc.h b/include/mmc.h
index f519d86..027e8bc 100644
--- a/include/mmc.h
+++ b/include/mmc.h
@@ -767,7 +767,7 @@
/**
* mmc_bind() - Set up a new MMC device ready for probing
*
- * A child block device is bound with the IF_TYPE_MMC interface type. This
+ * A child block device is bound with the UCLASS_MMC interface type. This
* allows the device to be used with CONFIG_BLK
*
* @dev: MMC device to set up
diff --git a/lib/efi_driver/efi_block_device.c b/lib/efi_driver/efi_block_device.c
index d57d281..3177ab6 100644
--- a/lib/efi_driver/efi_block_device.c
+++ b/lib/efi_driver/efi_block_device.c
@@ -128,7 +128,7 @@
if (!obj)
return -ENOENT;
- devnum = blk_find_max_devnum(IF_TYPE_EFI_LOADER);
+ devnum = blk_find_max_devnum(UCLASS_EFI_LOADER);
if (devnum == -ENODEV)
devnum = 0;
else if (devnum < 0)
@@ -140,7 +140,7 @@
sprintf(name, "efiblk#%d", devnum);
/* Create driver model udevice for the EFI block io device */
- ret = blk_create_device(parent, "efi_blk", name, IF_TYPE_EFI_LOADER,
+ ret = blk_create_device(parent, "efi_blk", name, UCLASS_EFI_LOADER,
devnum, io->media->block_size,
(lbaint_t)io->media->last_block, &bdev);
if (ret)
diff --git a/lib/efi_loader/efi_disk.c b/lib/efi_loader/efi_disk.c
index a34ca46..819dcb4 100644
--- a/lib/efi_loader/efi_disk.c
+++ b/lib/efi_loader/efi_disk.c
@@ -640,7 +640,7 @@
* has already created an efi_disk at this moment.
*/
desc = dev_get_uclass_plat(dev);
- if (desc->if_type != IF_TYPE_EFI_LOADER) {
+ if (desc->if_type != UCLASS_EFI_LOADER) {
ret = efi_disk_create_raw(dev);
if (ret)
return -1;
@@ -675,7 +675,7 @@
return -1;
desc = dev_get_uclass_plat(dev);
- if (desc->if_type != IF_TYPE_EFI_LOADER) {
+ if (desc->if_type != UCLASS_EFI_LOADER) {
diskobj = container_of(handle, struct efi_disk_obj, header);
efi_free_pool(diskobj->dp);
}
diff --git a/test/dm/blk.c b/test/dm/blk.c
index 85c3a3b..35bd531 100644
--- a/test/dm/blk.c
+++ b/test/dm/blk.c
@@ -25,19 +25,19 @@
/* Create two, one the parent of the other */
ut_assertok(blk_create_device(gd->dm_root, "sandbox_host_blk", "test",
- IF_TYPE_HOST, 1, 512, 2, &blk1));
+ UCLASS_ROOT, 1, 512, 2, &blk1));
ut_assertok(blk_create_device(blk1, "sandbox_host_blk", "test",
- IF_TYPE_HOST, 3, 512, 2, &blk3));
+ UCLASS_ROOT, 3, 512, 2, &blk3));
/* Check we can find them */
- ut_asserteq(-ENODEV, blk_get_device(IF_TYPE_HOST, 0, &dev));
- ut_assertok(blk_get_device(IF_TYPE_HOST, 1, &dev));
+ ut_asserteq(-ENODEV, blk_get_device(UCLASS_ROOT, 0, &dev));
+ ut_assertok(blk_get_device(UCLASS_ROOT, 1, &dev));
ut_asserteq_ptr(blk1, dev);
- ut_assertok(blk_get_device(IF_TYPE_HOST, 3, &dev));
+ ut_assertok(blk_get_device(UCLASS_ROOT, 3, &dev));
ut_asserteq_ptr(blk3, dev);
/* Check we can iterate */
- ut_assertok(blk_first_device(IF_TYPE_HOST, &dev));
+ ut_assertok(blk_first_device(UCLASS_ROOT, &dev));
ut_asserteq_ptr(blk1, dev);
ut_assertok(blk_next_device(&dev));
ut_asserteq_ptr(blk3, dev);
@@ -79,7 +79,7 @@
ut_assertok(blk_get_device_by_str("usb", "0", &dev_desc));
/* The parent should be a block device */
- ut_assertok(blk_get_device(IF_TYPE_USB, 0, &dev));
+ ut_assertok(blk_get_device(UCLASS_USB, 0, &dev));
ut_asserteq_ptr(usb_dev, dev_get_parent(dev));
/* Check we have one block device for each mass storage device */
@@ -101,14 +101,14 @@
struct udevice *blk, *dev;
ut_assertok(blk_create_device(gd->dm_root, "sandbox_host_blk", "test",
- IF_TYPE_HOST, 1, 512, 2, &blk));
- ut_asserteq(-ENODEV, blk_find_device(IF_TYPE_HOST, 0, &dev));
- ut_assertok(blk_find_device(IF_TYPE_HOST, 1, &dev));
+ UCLASS_ROOT, 1, 512, 2, &blk));
+ ut_asserteq(-ENODEV, blk_find_device(UCLASS_ROOT, 0, &dev));
+ ut_assertok(blk_find_device(UCLASS_ROOT, 1, &dev));
ut_asserteq_ptr(blk, dev);
ut_asserteq(false, device_active(dev));
/* Now activate it */
- ut_assertok(blk_get_device(IF_TYPE_HOST, 1, &dev));
+ ut_assertok(blk_get_device(UCLASS_ROOT, 1, &dev));
ut_asserteq_ptr(blk, dev);
ut_asserteq(true, device_active(dev));
@@ -134,7 +134,7 @@
/* Check that the bblock device is attached */
ut_assertok(uclass_get_device_by_seq(UCLASS_MMC, i, &mmc_dev));
- ut_assertok(blk_find_device(IF_TYPE_MMC, i, &dev));
+ ut_assertok(blk_find_device(UCLASS_MMC, i, &dev));
parent = dev_get_parent(dev);
ut_asserteq_ptr(parent, mmc_dev);
ut_asserteq(trailing_strtol(mmc_dev->name), i);