xref: /openbmc/u-boot/cmd/virtio.c (revision b9553986)
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * Copyright (C) 2018, Tuomas Tynkkynen <tuomas.tynkkynen@iki.fi>
4  * Copyright (C) 2018, Bin Meng <bmeng.cn@gmail.com>
5  */
6 
7 #include <common.h>
8 #include <command.h>
9 #include <dm.h>
10 #include <virtio_types.h>
11 #include <virtio.h>
12 
13 static int virtio_curr_dev;
14 
15 static int do_virtio(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
16 {
17 	if (argc == 2 && !strcmp(argv[1], "scan")) {
18 		/* make sure all virtio devices are enumerated */
19 		virtio_init();
20 
21 		return CMD_RET_SUCCESS;
22 	}
23 
24 	return blk_common_cmd(argc, argv, IF_TYPE_VIRTIO, &virtio_curr_dev);
25 }
26 
27 U_BOOT_CMD(
28 	virtio, 8, 1, do_virtio,
29 	"virtio block devices sub-system",
30 	"scan - initialize virtio bus\n"
31 	"virtio info - show all available virtio block devices\n"
32 	"virtio device [dev] - show or set current virtio block device\n"
33 	"virtio part [dev] - print partition table of one or all virtio block devices\n"
34 	"virtio read addr blk# cnt - read `cnt' blocks starting at block\n"
35 	"     `blk#' to memory address `addr'\n"
36 	"virtio write addr blk# cnt - write `cnt' blocks starting at block\n"
37 	"     `blk#' from memory address `addr'"
38 );
39