virtio.c 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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. #include <common.h>
  7. #include <blk.h>
  8. #include <command.h>
  9. #include <dm.h>
  10. #include <virtio_types.h>
  11. #include <virtio.h>
  12. static int virtio_curr_dev;
  13. static int do_virtio(struct cmd_tbl *cmdtp, int flag, int argc,
  14. char *const argv[])
  15. {
  16. if (argc == 2 && !strcmp(argv[1], "scan")) {
  17. /*
  18. * make sure all virtio devices are enumerated.
  19. * Do the same as virtio_init(), but also call
  20. * device_probe() for children (i.e. virtio devices)
  21. */
  22. struct udevice *bus, *child;
  23. uclass_first_device(UCLASS_VIRTIO, &bus);
  24. if (!bus)
  25. return CMD_RET_FAILURE;
  26. while (bus) {
  27. device_foreach_child_probe(child, bus)
  28. ;
  29. uclass_next_device(&bus);
  30. }
  31. return CMD_RET_SUCCESS;
  32. }
  33. return blk_common_cmd(argc, argv, UCLASS_VIRTIO, &virtio_curr_dev);
  34. }
  35. U_BOOT_CMD(
  36. virtio, 8, 1, do_virtio,
  37. "virtio block devices sub-system",
  38. "scan - initialize virtio bus\n"
  39. "virtio info - show all available virtio block devices\n"
  40. "virtio device [dev] - show or set current virtio block device\n"
  41. "virtio part [dev] - print partition table of one or all virtio block devices\n"
  42. "virtio read addr blk# cnt - read `cnt' blocks starting at block\n"
  43. " `blk#' to memory address `addr'\n"
  44. "virtio write addr blk# cnt - write `cnt' blocks starting at block\n"
  45. " `blk#' from memory address `addr'"
  46. );