[PATCH 42/71] virtio: Add a block device

Simon Glass sjg at chromium.org
Wed Dec 7 09:51:08 CET 2022


The test code for virtio is fairly simplistic and does not actually create
a block device. Add a way to specify the device type in the device tree.
Add a block device so that we can do more testing.

Signed-off-by: Simon Glass <sjg at chromium.org>
---

 arch/sandbox/dts/test.dts       | 6 ++++++
 drivers/virtio/virtio_sandbox.c | 3 ++-
 2 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/arch/sandbox/dts/test.dts b/arch/sandbox/dts/test.dts
index dffe10adbf4..72f3853b79f 100644
--- a/arch/sandbox/dts/test.dts
+++ b/arch/sandbox/dts/test.dts
@@ -1516,12 +1516,18 @@
 
 	sandbox_virtio1 {
 		compatible = "sandbox,virtio1";
+		virtio-type = <4>;	/* rng */
 	};
 
 	sandbox_virtio2 {
 		compatible = "sandbox,virtio2";
 	};
 
+	sandbox-virtio-blk {
+		compatible = "sandbox,virtio1";
+		virtio-type = <2>;	/* block */
+	};
+
 	sandbox_scmi {
 		compatible = "sandbox,scmi-devices";
 		clocks = <&clk_scmi 2>, <&clk_scmi 0>;
diff --git a/drivers/virtio/virtio_sandbox.c b/drivers/virtio/virtio_sandbox.c
index cf7761c75ee..b34f1d60455 100644
--- a/drivers/virtio/virtio_sandbox.c
+++ b/drivers/virtio/virtio_sandbox.c
@@ -161,7 +161,8 @@ static int virtio_sandbox_probe(struct udevice *udev)
 
 	/* fake some information for testing */
 	priv->device_features = BIT_ULL(VIRTIO_F_VERSION_1);
-	uc_priv->device = VIRTIO_ID_RNG;
+	uc_priv->device = dev_read_u32_default(udev, "virtio-type",
+					       VIRTIO_ID_RNG);
 	uc_priv->vendor = ('u' << 24) | ('b' << 16) | ('o' << 8) | 't';
 
 	return 0;
-- 
2.39.0.rc0.267.gcb52ba06e7-goog



More information about the U-Boot mailing list