Tuomas Tynkkynen | 78e1290 | 2018-10-15 02:21:12 -0700 | [diff] [blame] | 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 | |
Simon Glass | e6f6f9e | 2020-05-10 11:39:58 -0600 | [diff] [blame] | 7 | #include <blk.h> |
Tuomas Tynkkynen | 78e1290 | 2018-10-15 02:21:12 -0700 | [diff] [blame] | 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 | |
Simon Glass | 0914011 | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 15 | static int do_virtio(struct cmd_tbl *cmdtp, int flag, int argc, |
| 16 | char *const argv[]) |
Tuomas Tynkkynen | 78e1290 | 2018-10-15 02:21:12 -0700 | [diff] [blame] | 17 | { |
| 18 | if (argc == 2 && !strcmp(argv[1], "scan")) { |
AKASHI Takahiro | 75a9d75 | 2022-03-08 20:36:45 +0900 | [diff] [blame] | 19 | /* |
| 20 | * make sure all virtio devices are enumerated. |
| 21 | * Do the same as virtio_init(), but also call |
| 22 | * device_probe() for children (i.e. virtio devices) |
| 23 | */ |
| 24 | struct udevice *bus, *child; |
AKASHI Takahiro | 75a9d75 | 2022-03-08 20:36:45 +0900 | [diff] [blame] | 25 | |
Michal Suchanek | 4954937 | 2022-10-12 21:58:08 +0200 | [diff] [blame] | 26 | uclass_first_device(UCLASS_VIRTIO, &bus); |
| 27 | if (!bus) |
AKASHI Takahiro | 75a9d75 | 2022-03-08 20:36:45 +0900 | [diff] [blame] | 28 | return CMD_RET_FAILURE; |
| 29 | |
| 30 | while (bus) { |
| 31 | device_foreach_child_probe(child, bus) |
| 32 | ; |
Michal Suchanek | 4954937 | 2022-10-12 21:58:08 +0200 | [diff] [blame] | 33 | uclass_next_device(&bus); |
AKASHI Takahiro | 75a9d75 | 2022-03-08 20:36:45 +0900 | [diff] [blame] | 34 | } |
Tuomas Tynkkynen | 78e1290 | 2018-10-15 02:21:12 -0700 | [diff] [blame] | 35 | |
| 36 | return CMD_RET_SUCCESS; |
| 37 | } |
| 38 | |
Simon Glass | e33a5c6 | 2022-08-11 19:34:59 -0600 | [diff] [blame] | 39 | return blk_common_cmd(argc, argv, UCLASS_VIRTIO, &virtio_curr_dev); |
Tuomas Tynkkynen | 78e1290 | 2018-10-15 02:21:12 -0700 | [diff] [blame] | 40 | } |
| 41 | |
| 42 | U_BOOT_CMD( |
| 43 | virtio, 8, 1, do_virtio, |
| 44 | "virtio block devices sub-system", |
| 45 | "scan - initialize virtio bus\n" |
| 46 | "virtio info - show all available virtio block devices\n" |
| 47 | "virtio device [dev] - show or set current virtio block device\n" |
| 48 | "virtio part [dev] - print partition table of one or all virtio block devices\n" |
| 49 | "virtio read addr blk# cnt - read `cnt' blocks starting at block\n" |
| 50 | " `blk#' to memory address `addr'\n" |
| 51 | "virtio write addr blk# cnt - write `cnt' blocks starting at block\n" |
| 52 | " `blk#' from memory address `addr'" |
| 53 | ); |