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