2018-10-15 09:21:12 +00:00
|
|
|
// 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>
|
2020-05-10 17:39:58 +00:00
|
|
|
#include <blk.h>
|
2018-10-15 09:21:12 +00:00
|
|
|
#include <command.h>
|
|
|
|
#include <dm.h>
|
|
|
|
#include <virtio_types.h>
|
|
|
|
#include <virtio.h>
|
|
|
|
|
|
|
|
static int virtio_curr_dev;
|
|
|
|
|
2020-05-10 17:40:03 +00:00
|
|
|
static int do_virtio(struct cmd_tbl *cmdtp, int flag, int argc,
|
|
|
|
char *const argv[])
|
2018-10-15 09:21:12 +00:00
|
|
|
{
|
|
|
|
if (argc == 2 && !strcmp(argv[1], "scan")) {
|
2022-03-08 11:36:45 +00:00
|
|
|
/*
|
|
|
|
* 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;
|
|
|
|
}
|
2018-10-15 09:21:12 +00:00
|
|
|
|
|
|
|
return CMD_RET_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2022-08-12 01:34:59 +00:00
|
|
|
return blk_common_cmd(argc, argv, UCLASS_VIRTIO, &virtio_curr_dev);
|
2018-10-15 09:21:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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'"
|
|
|
|
);
|