diff options
author | Simon Glass <sjg@chromium.org> | 2022-08-11 19:34:59 -0600 |
---|---|---|
committer | Tom Rini <trini@konsulko.com> | 2022-09-16 11:05:16 -0400 |
commit | e33a5c6be55e7c012b2851f9bdf90e7f607e72bf (patch) | |
tree | 19041e9f1b54a5d2811c96e88132ba44fe31243b /drivers/block | |
parent | adbfe8edc3389ba635229195a95217d8b0dfa182 (diff) | |
download | u-boot-e33a5c6be55e7c012b2851f9bdf90e7f607e72bf.zip u-boot-e33a5c6be55e7c012b2851f9bdf90e7f607e72bf.tar.gz u-boot-e33a5c6be55e7c012b2851f9bdf90e7f607e72bf.tar.bz2 |
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>
Diffstat (limited to 'drivers/block')
-rw-r--r-- | drivers/block/blk-uclass.c | 64 | ||||
-rw-r--r-- | drivers/block/efi_blk.c | 2 | ||||
-rw-r--r-- | drivers/block/ide.c | 8 | ||||
-rw-r--r-- | drivers/block/sandbox.c | 12 |
4 files changed, 46 insertions, 40 deletions
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,31 +21,17 @@ static struct { 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" }, -}; - -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, + { 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 if_type if_typename_to_iftype(const char *if_typename) @@ -57,12 +43,32 @@ static enum if_type if_typename_to_iftype(const char *if_typename) 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 @@ const char *blk_get_if_type_name(enum if_type if_type) 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 @@ struct blk_desc *blk_get_devnum_by_typename(const char *if_typename, int devnum) 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 @@ static int efi_media_bind(struct udevice *dev) 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 @@ static void ide_ident(struct blk_desc *dev_desc) /* 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 @@ void ide_init(void) 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 @@ static int ide_probe(struct udevice *udev) 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 @@ UCLASS_DRIVER(ide) = { #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 host_dev_bind(int devnum, char *filename, bool removable) 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 @@ int host_dev_bind(int devnum, char *filename, bool removable) } } 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 @@ int host_dev_bind(int devnum, char *filename, bool removable) 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 @@ int host_dev_bind(int dev, char *filename, bool removable) } 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 @@ int host_get_dev_err(int devnum, struct blk_desc **blk_devp) 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 @@ U_BOOT_DRIVER(sandbox_host_blk) = { #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, }; |