summaryrefslogtreecommitdiff
path: root/cmd/virtio.c
blob: 019e317e75588ff4322e5af32cd9f1a7a2421623 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// 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;

		uclass_first_device(UCLASS_VIRTIO, &bus);
		if (!bus)
			return CMD_RET_FAILURE;

		while (bus) {
			device_foreach_child_probe(child, bus)
				;
			uclass_next_device(&bus);
		}

		return CMD_RET_SUCCESS;
	}

	return blk_common_cmd(argc, argv, UCLASS_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'"
);