u-boot/cmd/virtio.c
AKASHI Takahiro 75a9d75041 virtio: call device_probe() in scanning
virtio_init() enumerates all the peripherals that are to be materialised
with udevices(UCLASS_VIRIO) and creates particular device instances
(UCLASS_BlK or whatever else) as children.
On the other hand, device_probe() won't be invoked against those resultant
udevices unlike other ordinary device drivers do in the driver model.

This is particularly inconvenient when we want to add "event notification"
callback so that we will be able to automatically create all efi_disk
objects in a later patch.

With this patch applied, "virtio scan" will work in a similar way
to "scsi rescan", "usb start" or others in term of 'probe' semantics.

I didn't add this change to virtio_init() itself because this function
may be called in board_init_r() (indirectly in board_late_init())
before UEFI subsustem is initialized.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Simon Glass <sjg@chromium.org>
2022-04-09 21:06:31 +02:00

57 lines
1.5 KiB
C

// SPDX-License-Identifier: GPL-2.0+
/*
* Copyright (C) 2018, Tuomas Tynkkynen <tuomas.tynkkynen@iki.fi>
* Copyright (C) 2018, Bin Meng <bmeng.cn@gmail.com>
*/
#include <common.h>
#include <blk.h>
#include <command.h>
#include <dm.h>
#include <virtio_types.h>
#include <virtio.h>
static int virtio_curr_dev;
static int do_virtio(struct cmd_tbl *cmdtp, int flag, int argc,
char *const argv[])
{
if (argc == 2 && !strcmp(argv[1], "scan")) {
/*
* make sure all virtio devices are enumerated.
* Do the same as virtio_init(), but also call
* device_probe() for children (i.e. virtio devices)
*/
struct udevice *bus, *child;
int ret;
ret = uclass_first_device(UCLASS_VIRTIO, &bus);
if (ret)
return CMD_RET_FAILURE;
while (bus) {
device_foreach_child_probe(child, bus)
;
ret = uclass_next_device(&bus);
if (ret)
break;
}
return CMD_RET_SUCCESS;
}
return blk_common_cmd(argc, argv, IF_TYPE_VIRTIO, &virtio_curr_dev);
}
U_BOOT_CMD(
virtio, 8, 1, do_virtio,
"virtio block devices sub-system",
"scan - initialize virtio bus\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"
"virtio read addr blk# cnt - read `cnt' blocks starting at block\n"
" `blk#' to memory address `addr'\n"
"virtio write addr blk# cnt - write `cnt' blocks starting at block\n"
" `blk#' from memory address `addr'"
);