]> git.baikalelectronics.ru Git - uboot.git/commitdiff
bootstd: Add a virtio bootdev
authorSimon Glass <sjg@chromium.org>
Tue, 17 Jan 2023 17:47:52 +0000 (10:47 -0700)
committerTom Rini <trini@konsulko.com>
Mon, 23 Jan 2023 23:11:40 +0000 (18:11 -0500)
Add a bootdev for virtio so that these devices can be used with standard
boot.

Signed-off-by: Simon Glass <sjg@chromium.org>
drivers/virtio/virtio-uclass.c
test/boot/bootdev.c

index a6bff630ca8bac514f4abb26eb1863d3e19a12a4..27efac0d48e9044adef5b2f5ace1198e76d900d5 100644 (file)
@@ -18,6 +18,7 @@
 #define LOG_CATEGORY UCLASS_VIRTIO
 
 #include <common.h>
+#include <bootdev.h>
 #include <dm.h>
 #include <log.h>
 #include <malloc.h>
@@ -246,6 +247,12 @@ static int virtio_uclass_post_probe(struct udevice *udev)
        }
        device_set_name_alloced(vdev);
 
+       if (uc_priv->device == VIRTIO_ID_BLOCK) {
+               ret = bootdev_setup_for_dev(udev, name);
+               if (ret)
+                       return log_msg_ret("bootdev", ret);
+       }
+
        INIT_LIST_HEAD(&uc_priv->vqs);
 
        return 0;
@@ -349,6 +356,26 @@ static int virtio_uclass_child_post_probe(struct udevice *vdev)
        return 0;
 }
 
+static int virtio_bootdev_bind(struct udevice *dev)
+{
+       struct bootdev_uc_plat *ucp = dev_get_uclass_plat(dev);
+
+       ucp->prio = BOOTDEVP_2_SCAN_FAST;
+
+       return 0;
+}
+
+static int virtio_bootdev_hunt(struct bootdev_hunter *info, bool show)
+{
+       int ret;
+
+       ret = uclass_probe_all(UCLASS_VIRTIO);
+       if (ret && ret != -ENOENT)
+               return log_msg_ret("vir", ret);
+
+       return 0;
+}
+
 UCLASS_DRIVER(virtio) = {
        .name   = "virtio",
        .id     = UCLASS_VIRTIO,
@@ -360,3 +387,26 @@ UCLASS_DRIVER(virtio) = {
        .child_post_probe = virtio_uclass_child_post_probe,
        .per_device_auto        = sizeof(struct virtio_dev_priv),
 };
+
+struct bootdev_ops virtio_bootdev_ops = {
+};
+
+static const struct udevice_id virtio_bootdev_ids[] = {
+       { .compatible = "u-boot,bootdev-virtio" },
+       { }
+};
+
+U_BOOT_DRIVER(virtio_bootdev) = {
+       .name           = "virtio_bootdev",
+       .id             = UCLASS_BOOTDEV,
+       .ops            = &virtio_bootdev_ops,
+       .bind           = virtio_bootdev_bind,
+       .of_match       = virtio_bootdev_ids,
+};
+
+BOOTDEV_HUNTER(virtio_bootdev_hunter) = {
+       .prio           = BOOTDEVP_2_SCAN_FAST,
+       .uclass         = UCLASS_VIRTIO,
+       .hunt           = virtio_bootdev_hunt,
+       .drv            = DM_DRIVER_REF(virtio_bootdev),
+};
index 6f150175f699f027704288bf800bb8b1ec7bcc79..2ad31a0ef66aae9ecf1fcec9852a10559a835a50 100644 (file)
@@ -244,7 +244,8 @@ static int bootdev_test_hunter(struct unit_test_state *uts)
        ut_assert_nextline("  30        nvme             nvme_bootdev");
        ut_assert_nextline("  30        scsi             scsi_bootdev");
        ut_assert_nextline("  40        usb              usb_bootdev");
-       ut_assert_nextline("(total hunters: 6)");
+       ut_assert_nextline("  30        virtio           virtio_bootdev");
+       ut_assert_nextline("(total hunters: 7)");
        ut_assert_console_end();
 
        ut_assertok(bootdev_hunt("usb1", false));
@@ -273,7 +274,7 @@ static int bootdev_test_cmd_hunt(struct unit_test_state *uts)
        ut_assertok(run_command("bootdev hunt -l", 0));
        ut_assert_nextline("Prio  Used  Uclass           Hunter");
        ut_assert_nextlinen("----");
-       ut_assert_skip_to_line("(total hunters: 6)");
+       ut_assert_skip_to_line("(total hunters: 7)");
        ut_assert_console_end();
 
        /* Scan all hunters */
@@ -290,6 +291,7 @@ static int bootdev_test_cmd_hunt(struct unit_test_state *uts)
        ut_assert_skip_to_line("Hunting with: usb");
        ut_assert_nextline(
                "Bus usb@1: scanning bus usb@1 for devices... 5 USB Device(s) found");
+       ut_assert_skip_to_line("Hunting with: virtio");
        ut_assert_console_end();
 
        /* List available hunters */
@@ -302,11 +304,11 @@ static int bootdev_test_cmd_hunt(struct unit_test_state *uts)
        ut_assert_nextline("  30     *  nvme             nvme_bootdev");
        ut_assert_nextline("  30     *  scsi             scsi_bootdev");
        ut_assert_nextline("  40     *  usb              usb_bootdev");
-
-       ut_assert_nextline("(total hunters: 6)");
+       ut_assert_nextline("  30     *  virtio           virtio_bootdev");
+       ut_assert_nextline("(total hunters: 7)");
        ut_assert_console_end();
 
-       ut_asserteq(GENMASK(5, 0), std->hunters_used);
+       ut_asserteq(GENMASK(6, 0), std->hunters_used);
 
        return 0;
 }