virtio: Provide a command to list virtio devices

U-Boot only supports a subset of the devices supported by QEMU. For
example, U-Boot does not currently support the vsock device.

It is helpful to see what devices are provided by QEMU and whether there
is a driver for it in U-Boot.

Add a new 'virtio list' command to provide this.

Signed-off-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
Simon Glass
2025-07-06 06:35:08 +02:00
parent 7013d9f2f1
commit bbd1cc14c1
4 changed files with 76 additions and 0 deletions

View File

@@ -34,6 +34,10 @@ static int do_virtio(struct cmd_tbl *cmdtp, int flag, int argc,
}
return CMD_RET_SUCCESS;
} else if (argc == 2 && !strcmp(argv[1], "list")) {
virtio_list();
return 0;
}
return blk_common_cmd(argc, argv, UCLASS_VIRTIO, &virtio_curr_dev);
@@ -43,6 +47,7 @@ U_BOOT_CMD(
virtio, 8, 1, do_virtio,
"virtio block devices sub-system",
"scan - initialize virtio bus\n"
"list - list virtio devices\n"
"virtio info - show all available virtio block devices\n"
"virtio device [dev] - show or set current virtio block device\n"
"virtio part [dev] - print partition table of one or all virtio block devices\n"

View File

@@ -13,6 +13,7 @@ Synopsis
virtio scan
virtio info
virtio list
virtio device
virtio part
virtio read <addr> <blk#> <cnt>
@@ -48,6 +49,12 @@ virtio info
This lists the available block devices (only), including the name, type and
capacity.
virtio list
~~~~~~~~~~~
This shows a list of QEMU devices along with U-Boot each attached to each. Note
that QEMU devices that U-Boot doesn't support will not be assigned a driver.
virtio device
~~~~~~~~~~~~~
@@ -148,6 +155,42 @@ warning indicates that device 1 does not have a valid filesystem.
cpu 0 [ ] cpu_qemu `-- cpu@0
=>
This shows listing QEMU devices before and after scanning. Note that devices
which show '(none)' in the Driver column are not supported by U-Boot.
::
=> virtio list
Name Type Driver
-------------------- -------------- ---------------
virtio-pci.m#0 0: (unknown) (none)
virtio-pci.m#1 0: (unknown) (none)
virtio-pci.m#2 0: (unknown) (none)
virtio-pci.m#3 0: (unknown) (none)
virtio-pci.m#4 0: (unknown) (none)
virtio-pci.m#5 0: (unknown) (none)
virtio-pci.m#6 0: (unknown) (none)
virtio-pci.m#7 0: (unknown) (none)
virtio-pci.m#8 0: (unknown) (none)
virtio-pci.m#9 0: (unknown) (none)
virtio-pci.m#10 0: (unknown) (none)
=> virtio scan
=> virtio list
Name Type Driver
-------------------- -------------- ---------------
virtio-pci.m#0 5: balloon (none)
virtio-pci.m#1 4: rng (none)
virtio-pci.m#2 12: input-host (none)
virtio-pci.m#3 12: input-host (none)
virtio-pci.m#4 13: vsock (none)
virtio-pci.m#5 3: serial (none)
virtio-pci.m#6 8: scsi virtio-scsi#6
virtio-pci.m#7 9: 9p (none)
virtio-pci.m#8 1a: fs virtio-fs#8
virtio-pci.m#9 10: gpu (none)
virtio-pci.m#10 1: net virtio-net#a
=>
This shows reading and displaying the partition table for device 0::
=> virtio part 0

View File

@@ -202,6 +202,29 @@ int virtio_init(void)
return uclass_probe_all(UCLASS_VIRTIO);
}
void virtio_list(void)
{
struct udevice *dev;
struct uclass *uc;
printf("%-20s %-14s %s\n", "Name", "Type", "Driver");
printf("-------------------- -------------- ---------------\n");
uclass_id_foreach_dev(UCLASS_VIRTIO, dev, uc) {
struct virtio_dev_priv *uc_priv = dev_get_uclass_priv(dev);
const char *typename = NULL; /* skip the 'virtio-' prefix */
struct udevice *child;
if (uc_priv->device < VIRTIO_ID_MAX_NUM)
typename = virtio_drv_name[uc_priv->device];
device_find_first_child(dev, &child);
printf("%-21.21s %2x: %-11.11s %s\n", dev->name,
uc_priv->device, typename ? typename + 7 : "(unknown)",
child ? child->name : "(none)");
}
}
static int virtio_uclass_pre_probe(struct udevice *udev)
{
struct dm_virtio_ops *ops;

View File

@@ -723,4 +723,9 @@ static inline void virtio_cwrite64(struct udevice *vdev,
_r; \
})
/**
* virtio_list() - list the available virtio devices and their status
*/
void virtio_list(void);
#endif /* __VIRTIO_H__ */