Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id C600FC47089 for ; Wed, 7 Dec 2022 09:04:01 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 4C2C0856F1; Wed, 7 Dec 2022 09:56:33 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="gK4Ahfx4"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id ECB24856C8; Wed, 7 Dec 2022 09:56:30 +0100 (CET) Received: from mail-pg1-x534.google.com (mail-pg1-x534.google.com [IPv6:2607:f8b0:4864:20::534]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id B97D8856C1 for ; Wed, 7 Dec 2022 09:56:26 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=sjg@chromium.org Received: by mail-pg1-x534.google.com with SMTP id 142so260422pga.1 for ; Wed, 07 Dec 2022 00:56:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=IBDI5wDczVbVTKKMGqTazkdA7Cs8+BV0Ln/S5pRxIp8=; b=gK4Ahfx4e3lq7lR5n1DO9r9oqci8dxtDW865Yd1vSJWUON1wN4OMKBjiWgdJOt7piq oLr8w8T23FdNGTFWBiPoyrYiS3BAxQf+uNysQTxkxkT4ciF/is8u1Tccar5XBVdK33ET bT7arly3r3WadxcyIGqTpvLOB5s1eCD4AkSgc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=IBDI5wDczVbVTKKMGqTazkdA7Cs8+BV0Ln/S5pRxIp8=; b=IIK6JGj+NcufkfCzTQDyida51pBJjs/kZYHSCkMIooMFHmOSP2Lu+aQd9t82j626ni PF6QDpCwfiUYMM+hGyaaynOiEyCPFLsmf9LQSPrpIr5xuv4IVOZGbx25mhTQ7sjde4YJ wv8CKLKyBrvHMOpBxWW1oNetOVdMJZrhYDRHNPEdbhpwwGzhf2wBHaKFlJY7LVv1pa6X i6xYcrv3u1lc7ZJxL3bsZbtOCGfHxbqxbLAqhjA7Q0YufstwIAfpxObrdujeHulPrnMG jeZY0A5kIBqf7e0IRrIW8ZgOUuTJkpaQfKGcHahOPytr3MvlX2LqERYK9NTHAK8W8aY4 QUIQ== X-Gm-Message-State: ANoB5pk1ARO+2US7/s1suL1y6C3+/qcD38K48nb0GNdeqxiLSU3u8JY3 +eG+nBdQyMkI1ZYsTNkbvBjzP3h6DmWLg1Bn X-Google-Smtp-Source: AA0mqf4+hzNRpKc4c9JCYvMM9Y8Zttu3pj7ynFLC6H3uUToRgXe38s7YrQwfSYrP7LMuxz/InqsboQ== X-Received: by 2002:aa7:8d8f:0:b0:56b:b112:4a16 with SMTP id i15-20020aa78d8f000000b0056bb1124a16mr96950710pfr.66.1670403384903; Wed, 07 Dec 2022 00:56:24 -0800 (PST) Received: from localhost.localdomain ([27.110.126.54]) by smtp.gmail.com with ESMTPSA id l16-20020a170903121000b0018157b415dbsm14145514plh.63.2022.12.07.00.56.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Dec 2022 00:56:24 -0800 (PST) From: Simon Glass To: U-Boot Mailing List Cc: U-Boot Custodians , Simon Glass , Bin Meng Subject: [PATCH 43/71] bootstd: Add a virtio bootdev Date: Wed, 7 Dec 2022 21:51:09 +1300 Message-Id: <20221207085137.445249-44-sjg@chromium.org> X-Mailer: git-send-email 2.39.0.rc0.267.gcb52ba06e7-goog In-Reply-To: <20221207085137.445249-1-sjg@chromium.org> References: <20221207085137.445249-1-sjg@chromium.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.6 at phobos.denx.de X-Virus-Status: Clean Add a bootdev for virtio so that these devices can be used with standard boot. Signed-off-by: Simon Glass --- drivers/virtio/virtio-uclass.c | 50 ++++++++++++++++++++++++++++++++++ test/boot/bootdev.c | 12 ++++---- 2 files changed, 57 insertions(+), 5 deletions(-) diff --git a/drivers/virtio/virtio-uclass.c b/drivers/virtio/virtio-uclass.c index a6bff630ca8..27efac0d48e 100644 --- a/drivers/virtio/virtio-uclass.c +++ b/drivers/virtio/virtio-uclass.c @@ -18,6 +18,7 @@ #define LOG_CATEGORY UCLASS_VIRTIO #include +#include #include #include #include @@ -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), +}; diff --git a/test/boot/bootdev.c b/test/boot/bootdev.c index 6f150175f69..2ad31a0ef66 100644 --- a/test/boot/bootdev.c +++ b/test/boot/bootdev.c @@ -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; } -- 2.39.0.rc0.267.gcb52ba06e7-goog