Skip to contentSkip to conversation

virtio: Add a virtio RTC driver

PATCH Superseded Hung-Chun Tseng 3 participants 13 messages Oct 28 – Nov 1 virtio core

v5 of 7 Superseded Latest is v7 →

lore
Share & tools
lore
#0 lore raw

v5 cover virtio: Add a virtio RTC driver

QEMU v11.1.0 added a virtio RTC device (virtio-rtc-pci and virtio-rtc-device), but U-Boot has no driver for it. This series adds one, so that "date" and anything else using dm_rtc_get() work on any virtio-capable QEMU target.

Patch 1 adds the driver, patch 2 updates the virtio documentation and patch 3 adds a MAINTAINERS entry. Patch 4 lets sandbox tests answer virtqueue requests as the device would, which patch 5 uses to test the driver.

v5 only changes the documentation in patch 2, following Kuan-Wei's review, and adds his Reviewed-by to patch 1. The code is unchanged from v4.

Tested with qemu-riscv64_smode_defconfig and RTC_GOLDFISH disabled, on QEMU v11.1.2, which reports a UTC clock, and on QEMU master, which reports a smeared UTC clock:

- With -device virtio-rtc-pci and with -device virtio-rtc-device, "date" reads the host time and advances between reads.
- Setting the time fails, as the clocks are read-only.
- With no virtio RTC device, "date" fails cleanly with err=-19.

On sandbox, "ut dm virtio_rtc*" passes.

Hung-Chun Tseng (5):
virtio: rtc: Add virtio RTC driver
doc: virtio: List the supported device types
MAINTAINERS: Add entry for virtio RTC
virtio: sandbox: Let tests emulate the device side of a virtqueue
test: dm: Add tests for the virtio RTC driver

 MAINTAINERS                         |   6 +
 arch/sandbox/dts/test.dts           |   5 +
 arch/sandbox/include/asm/test.h     |  25 +++
 doc/develop/driver-model/virtio.rst |  15 +-
 drivers/virtio/Kconfig              |  11 +
 drivers/virtio/Makefile             |   1 +
 drivers/virtio/virtio-uclass.c      |   1 +
 drivers/virtio/virtio_rtc.c         | 244 ++++++++++++++++++++++
 drivers/virtio/virtio_sandbox.c     |  15 ++
 include/virtio.h                    |   4 +-
 test/dm/Makefile                    |   1 +
 test/dm/virtio_rtc.c                | 306 ++++++++++++++++++++++++++++
 12 files changed, 629 insertions(+), 5 deletions(-)
 create mode 100644 drivers/virtio/virtio_rtc.c
 create mode 100644 test/dm/virtio_rtc.c
Signature · 1 line
2.43.0
#1 lore raw

PATCH v5 1/5 virtio: rtc: Add virtio RTC driver

QEMU provides a virtio RTC device (virtio-rtc-pci, virtio-rtc-device) since v11.1.0, but U-Boot has no driver for it.

The virtqueue must not be used before the virtio uclass sets DRIVER_OK, which happens after probe(), so the clock is looked up on the first read.

Like Linux, the driver prefers a VIRTIO_RTC_CLOCK_UTC_SMEARED clock, as it never steps on leap seconds. QEMU master reports such a clock since "virtio-rtc: Report smeared UTC clock type", but v11.1 reports VIRTIO_RTC_CLOCK_UTC, so the driver falls back to another UTC clock rather than leave U-Boot without an RTC there.

The set of clocks never changes, so if none of them is UTC, the driver remembers it and fails later reads at once.

---
(no changes since v4)

Changes in v4:
- Cut the commit message down to why the driver works as it does (Kuan-Wei)
- Say that QEMU master now reports a smeared UTC clock and that the fallback is for v11.1 (Kuan-Wei)
- Drop the comment on giving up after a failed request, which is plain error handling (Kuan-Wei)

Changes in v3:
- Give up on a request after one second instead of polling forever (Kuan-Wei)
- Remember that no clock is UTC, so that later reads fail at once (Simon)
- Expand the VIRTIO_RTC help text (Simon)
- Drop __packed from the message structs, which are naturally aligned (Kuan-Wei)
- Prefer a VIRTIO_RTC_CLOCK_UTC_SMEARED clock as Linux does, fall back to the first other UTC clock, and explain why in the commit message (Kuan-Wei)
- Stop looking for a clock as soon as a request fails, as Linux does (Kuan-Wei)
- Mention in the commit message that sandbox tests follow (Simon)

Changes in v2:
- Look for the UTC clock on the first virtio_rtc_get() instead of in probe(), as the virtqueue must not be used before DRIVER_OK (Bin)

 drivers/virtio/Kconfig         |  11 ++
 drivers/virtio/Makefile        |   1 +
 drivers/virtio/virtio-uclass.c |   1 +
 drivers/virtio/virtio_rtc.c    | 244 +++++++++++++++++++++++++++++++++
 include/virtio.h               |   4 +-
 5 files changed, 260 insertions(+), 1 deletion(-)
 create mode 100644 drivers/virtio/virtio_rtc.c
drivers/virtio/Kconfig +11 -0
index 55b444280..48ab669f3 100644
@@ -84,4 +84,15 @@ config VIRTIO_9P
 	help
 	  This enables the 9P transport driver over virtio.
 	  It can be used with QEMU based targets.
+
+config VIRTIO_RTC
+	bool "virtio RTC driver"
+	depends on DM_RTC
+	depends on VIRTIO
+	default y
+	help
+	  This enables the virtio RTC driver, which reads the UTC clock
+	  exposed by a virtio RTC device. QEMU v11.1.0 or later provides
+	  it as virtio-rtc-pci and virtio-rtc-device. The clocks are
+	  read-only, so the time cannot be set.
 endmenu
drivers/virtio/Makefile +1 -0
index 6e7bcfc8e..ddb5ce4eb 100644
@@ -12,3 +12,4 @@ obj-$(CONFIG_VIRTIO_NET) += virtio_net.o
 obj-$(CONFIG_VIRTIO_BLK) += virtio_blk.o
 obj-$(CONFIG_VIRTIO_RNG) += virtio_rng.o
 obj-$(CONFIG_VIRTIO_9P) += virtio_9p.o
+obj-$(CONFIG_VIRTIO_RTC) += virtio_rtc.o
drivers/virtio/virtio-uclass.c +1 -0
index c163b2fd7..c6cf55922 100644
@@ -31,6 +31,7 @@ static const char *const virtio_drv_name[VIRTIO_ID_MAX_NUM] = {
 	[VIRTIO_ID_BLOCK]	= VIRTIO_BLK_DRV_NAME,
 	[VIRTIO_ID_RNG]		= VIRTIO_RNG_DRV_NAME,
 	[VIRTIO_ID_9P]		= VIRTIO_9P_DRV_NAME,
+	[VIRTIO_ID_CLOCK]	= VIRTIO_RTC_DRV_NAME,
 };
 
 int virtio_get_config(struct udevice *vdev, unsigned int offset,
drivers/virtio/virtio_rtc.c new file +244 -0

244 lines not on this page · raw message

include/virtio.h +3 -1
index b981eead5..95069a2de 100644
@@ -32,12 +32,14 @@
 #define VIRTIO_ID_BLOCK		2 /* virtio block */
 #define VIRTIO_ID_RNG		4 /* virtio rng */
 #define VIRTIO_ID_9P		9 /* virtio 9p */
-#define VIRTIO_ID_MAX_NUM	10
+#define VIRTIO_ID_CLOCK		17 /* virtio clock/timer (rtc) */
+#define VIRTIO_ID_MAX_NUM	18
 
 #define VIRTIO_NET_DRV_NAME	"virtio-net"
 #define VIRTIO_BLK_DRV_NAME	"virtio-blk"
 #define VIRTIO_RNG_DRV_NAME	"virtio-rng"
 #define VIRTIO_9P_DRV_NAME	"virtio-9p"
+#define VIRTIO_RTC_DRV_NAME	"virtio-rtc"
 
 /* Feature bits for virtio 9P */
 #define VIRTIO_9P_MOUNT_TAG	0
Signature · 1 line
2.43.0
#2 lore raw

PATCH v5 2/5 doc: virtio: List the supported device types

In reply to Hung-Chun Tseng

The list of supported device types still only named network and block devices. Turn it into a bulleted list, which is easier to extend, and add the entropy, 9P and RTC devices. Also note that the virtio RTC device needs QEMU v11.1.0 or later.

The Development Flow section repeated the old list; point it to the one at the top instead.

---
Changes in v5:
- Point the Development Flow section to the list of supported devices instead of saying only network and block devices are supported (Kuan-Wei)
- Keep the Reviewed-by tags of Bin and Simon, as only one sentence changed

Changes in v3:
- Retitle from "doc: virtio: Mention the RTC device", as the patch lists other devices too (Kuan-Wei)
- Turn the list of devices into a bulleted list (Kuan-Wei)
- Keep the Reviewed-by tags of Bin and Simon, as only the layout changed

 doc/develop/driver-model/virtio.rst | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)
doc/develop/driver-model/virtio.rst +11 -4
index e5da9f430..30df0e944 100644
@@ -28,7 +28,13 @@ queues configuration and buffer transfers are nearly identical. Both MMIO
 and PCI transport options are supported in U-Boot.
 
 The VirtIO spec defines a lots of VirtIO device types, however at present only
-network and block device, the most two commonly used devices, are supported.
+the following devices are supported.
+
+  - network
+  - block
+  - entropy (rng)
+  - 9P transport
+  - RTC
 
 The following QEMU targets are supported.
 
@@ -72,6 +78,8 @@ Requirements
 ------------
 It is required that QEMU v2.5.0+ should be used to test U-Boot VirtIO support
 on QEMU ARM and x86, and v2.12.0+ on QEMU RISC-V.
+The VirtIO RTC device (``-device virtio-rtc-pci`` or
+``-device virtio-rtc-device``) requires QEMU v11.1.0+.
 
 Testing
 -------
@@ -246,9 +254,8 @@ So it's easy to tell which device these functions are operating on.
 
 Development Flow
 ----------------
-At present only VirtIO network card (device ID 1) and block device (device
-ID 2) are supported. If you want to develop new driver for new devices,
-please follow the guideline below.
+The supported devices are listed at the top of this document. If you want
+to develop new driver for new devices, please follow the guideline below.
 
 1. add new device ID in virtio.h
 
Signature · 1 line
2.43.0
#3 lore raw

PATCH v5 3/5 MAINTAINERS: Add entry for virtio RTC

In reply to Hung-Chun Tseng

Add myself as the maintainer of the virtio RTC driver.

---
(no changes since v3)

Changes in v3:
- Add test/dm/virtio_rtc.c, which this version adds

 MAINTAINERS | 5 +++++
 1 file changed, 5 insertions(+)
MAINTAINERS +5 -0
index 95b1f3b5a..23a232689 100644
@@ -1885,6 +1885,11 @@ F:	include/virtio*.h
 F:	test/dm/virtio.c
 F:	doc/develop/driver-model/virtio.rst
 
+VIRTIO RTC
+M:	Hung-Chun Tseng <[email protected]>
+S:	Maintained
+F:	drivers/virtio/virtio_rtc.c
+
 WATCHDOG
 M:	Stefan Roese <[email protected]>
 S:	Maintained
Signature · 1 line
2.43.0
#4 lore raw

PATCH v5 4/5 virtio: sandbox: Let tests emulate the device side of a virtqueue

In reply to Hung-Chun Tseng

The sandbox virtio transport ignores notifications, so a driver that waits for the device to answer a request cannot be tested beyond its probe. The virtio-rng test works around this by writing to the used ring of the driver's virtqueue before reading.

Add sandbox_virtio_set_notify() so that a test can install a handler which is called when the driver kicks a virtqueue. The handler can then process the available ring and fill in the used ring, as a real device would. Without a handler, notifications are still ignored.

---
(no changes since v3)

Changes in v3:
- New patch, needed by the next one

 arch/sandbox/include/asm/test.h | 25 +++++++++++++++++++++++++
 drivers/virtio/virtio_sandbox.c | 15 +++++++++++++++
 2 files changed, 40 insertions(+)
arch/sandbox/include/asm/test.h +25 -0
index 043879002..d95de1095 100644
@@ -11,6 +11,8 @@
 #include <pci_ids.h>
 
 struct unit_test_state;
+struct udevice;
+struct virtqueue;
 
 /* The sandbox driver always permits an I2C device with this address */
 #define SANDBOX_I2C_TEST_ADDR		0x59
@@ -369,4 +371,27 @@ bool sandbox_sf_bootdev_enabled(void);
  */
 void sandbox_sf_set_enable_bootdevs(bool enable);
 
+/**
+ * typedef sandbox_virtio_notify_t - Emulate the device side of a virtqueue
+ *
+ * @dev: sandbox virtio transport device
+ * @vq: virtqueue that was kicked
+ * Returns: 0 on success, or -ve error code
+ */
+typedef int (*sandbox_virtio_notify_t)(struct udevice *dev,
+				       struct virtqueue *vq);
+
+/**
+ * sandbox_virtio_set_notify() - Set a handler for virtqueue notifications
+ *
+ * The sandbox virtio transport ignores notifications by default. A test can
+ * set a handler here to process the buffers the driver adds, like a real
+ * device would.
+ *
+ * @dev: sandbox virtio transport device
+ * @notify: handler to call, or NULL to ignore notifications again
+ */
+void sandbox_virtio_set_notify(struct udevice *dev,
+			       sandbox_virtio_notify_t notify);
+
 #endif
drivers/virtio/virtio_sandbox.c +15 -0
index 0f1ebef22..3b8a4d5a6 100644
@@ -13,6 +13,7 @@
 #include <linux/compat.h>
 #include <linux/err.h>
 #include <linux/io.h>
+#include <asm/test.h>
 
 struct virtio_sandbox_priv {
 	u8 id;
@@ -22,6 +23,7 @@ struct virtio_sandbox_priv {
 	ulong queue_desc;
 	ulong queue_available;
 	ulong queue_used;
+	sandbox_virtio_notify_t notify;
 };
 
 static int virtio_sandbox_get_config(struct udevice *udev, unsigned int offset,
@@ -150,9 +152,22 @@ static int virtio_sandbox_find_vqs(struct udevice *udev, unsigned int nvqs,
 
 static int virtio_sandbox_notify(struct udevice *udev, struct virtqueue *vq)
 {
+	struct virtio_sandbox_priv *priv = dev_get_priv(udev);
+
+	if (priv->notify)
+		return priv->notify(udev, vq);
+
 	return 0;
 }
 
+void sandbox_virtio_set_notify(struct udevice *udev,
+			       sandbox_virtio_notify_t notify)
+{
+	struct virtio_sandbox_priv *priv = dev_get_priv(udev);
+
+	priv->notify = notify;
+}
+
 static int virtio_sandbox_probe(struct udevice *udev)
 {
 	struct virtio_sandbox_priv *priv = dev_get_priv(udev);
Signature · 1 line
2.43.0
#5 lore raw

PATCH v5 5/5 test: dm: Add tests for the virtio RTC driver

In reply to Hung-Chun Tseng

Add a virtio RTC device to the sandbox test device tree and emulate it through the sandbox virtio transport. The emulated device answers the VIRTIO_RTC_REQ_CFG, VIRTIO_RTC_REQ_CLOCK_CAP and VIRTIO_RTC_REQ_READ requests from a configurable list of clocks.

The tests check that the driver:
- does not use the virtqueue in probe()
- reads the time from the first UTC clock and looks it up only once
- remembers that there is no UTC clock and does not ask again
- reports a failed request and looks for the clock again next time
- gives up with -ETIMEDOUT when the device does not answer

---
(no changes since v3)

Changes in v3:
- New patch (Simon)

 MAINTAINERS               |   1 +
 arch/sandbox/dts/test.dts |   5 +
 test/dm/Makefile          |   1 +
 test/dm/virtio_rtc.c      | 306 ++++++++++++++++++++++++++++++++++++++
 4 files changed, 313 insertions(+)
 create mode 100644 test/dm/virtio_rtc.c
MAINTAINERS +1 -0
index 23a232689..f45bcc353 100644
@@ -1889,6 +1889,7 @@ VIRTIO RTC
 M:	Hung-Chun Tseng <[email protected]>
 S:	Maintained
 F:	drivers/virtio/virtio_rtc.c
+F:	test/dm/virtio_rtc.c
 
 WATCHDOG
 M:	Stefan Roese <[email protected]>
arch/sandbox/dts/test.dts +5 -0
index 02a9ca29b..405f6921e 100644
@@ -1996,6 +1996,11 @@
 		virtio-type = <2>;	/* block */
 	};
 
+	sandbox-virtio-rtc {
+		compatible = "sandbox,virtio1";
+		virtio-type = <17>;	/* clock */
+	};
+
 	sandbox_scmi {
 		compatible = "sandbox,scmi-devices";
 		power-domains = <&pwrdom_scmi 2>;
test/dm/Makefile +1 -0
index 1b3a20aa9..d4a112c32 100644
@@ -155,6 +155,7 @@ ifeq ($(CONFIG_VIRTIO_SANDBOX),y)
 obj-y += virtio.o
 obj-$(CONFIG_VIRTIO_RNG) += virtio_device.o
 obj-$(CONFIG_VIRTIO_RNG) += virtio_rng.o
+obj-$(CONFIG_VIRTIO_RTC) += virtio_rtc.o
 endif
 ifeq ($(CONFIG_WDT_GPIO)$(CONFIG_WDT_SANDBOX),yy)
 obj-y += wdt.o
test/dm/virtio_rtc.c new file +306 -0

306 lines not on this page · raw message

Signature · 1 line
2.43.0
#6 lore raw
In reply to Hung-Chun Tseng

Hi Hung-Chun,

Quoted 2 lines · Hung-Chun Tseng

one, so that "date" and anything else using dm_rtc_get() work on any virtio-capable QEMU target.

Just to check, is this right in practice? The 'date' command uses RTC sequence 0. The ARM and RISC-V 'virt' machines always provide a PL031 or Goldfish RTC, and those boards imply DM_RTC with RTC_PL031 or RTC_GOLDFISH. So with the default configs the virtio RTC is the second RTC and 'date' never reads it, which I suspect is why you disabled RTC_GOLDFISH when testing. On qemu-x86, DM_RTC is not enabled in U-Boot proper, so the driver is not built at all.

It might be worth a follow-up adding a sentence to the virtio documentation on how to reach the virtio RTC when a platform RTC is present, e.g. with 'rtc dev', or with an alias if that suits your use case.

Regards,
Simon

#7 lore raw

Hi Simon,

Quoted 7 lines · Simon Glass

Just to check, is this right in practice? The 'date' command uses RTC sequence 0. The ARM and RISC-V 'virt' machines always provide a PL031 or Goldfish RTC, and those boards imply DM_RTC with RTC_PL031 or RTC_GOLDFISH. So with the default configs the virtio RTC is the second RTC and 'date' never reads it, which I suspect is why you disabled RTC_GOLDFISH when testing. On qemu-x86, DM_RTC is not enabled in U-Boot proper, so the driver is not built at all.

You're right, that sentence overstates it. With the default configs the virtio RTC is only the second RTC, and that is why I disabled RTC_GOLDFISH to test it with "date". On qemu-x86 it also needs DM_RTC enabled.

Quoted 4 lines

It might be worth a follow-up adding a sentence to the virtio documentation on how to reach the virtio RTC when a platform RTC is present, e.g. with 'rtc dev', or with an alias if that suits your use case.

Yes, I'll send that. One thing I found while checking: "rtc dev 1" selects it for "rtc read", but "date" still uses sequence 0. An alias does not work either, as the virtio device is bound by the transport and has no node of its own. So the doc would point to "rtc dev" and "rtc read", and say that "date" needs the platform RTC disabled.

Thanks,
Hung-Chun

#8 lore raw

PATCH 1/1 doc: virtio: Explain how to reach the virtio RTC

The date command only uses RTC sequence 0. On the ARM and RISC-V virt machines that is the PL031 or Goldfish RTC, so date never reads the virtio RTC unless that driver is disabled. rtc dev does not help, as rtc read reads raw registers, which the virtio RTC does not have.

Say this in the virtio documentation, and that x86 needs DM_RTC.

---
This is the follow-up Simon suggested on v5. It applies on top of the v5 series.

In my reply to the v5 cover letter I said the doc would point to "rtc dev" and "rtc read". That was wrong: "rtc dev 1" selects the virtio RTC, but "rtc read" then fails with -ENOSYS, as the driver has no register access.

 doc/develop/driver-model/virtio.rst | 8 ++++++++
 1 file changed, 8 insertions(+)
doc/develop/driver-model/virtio.rst +8 -0
index 30df0e944..94d3dabbd 100644
@@ -81,6 +81,14 @@ on QEMU ARM and x86, and v2.12.0+ on QEMU RISC-V.
 The VirtIO RTC device (``-device virtio-rtc-pci`` or
 ``-device virtio-rtc-device``) requires QEMU v11.1.0+.
 
+The ``date`` command only uses RTC sequence 0. The ARM and RISC-V ``virt``
+machines also have a PL031 or Goldfish RTC, which gets sequence 0, so
+``date`` reads the VirtIO RTC there only if ``CONFIG_RTC_PL031`` or
+``CONFIG_RTC_GOLDFISH`` is disabled. ``rtc list`` shows the sequence numbers.
+``rtc dev`` does not help, as ``rtc read`` reads raw registers, which the
+VirtIO RTC does not have. On x86, ``CONFIG_DM_RTC`` must be enabled for the
+driver to be built.
+
 Testing
 -------
 The following QEMU command line is used to get U-Boot up and running with
Signature · 1 line
2.43.0
#9 lore raw

PATCH 1/1 doc: virtio: Explain how to reach the virtio RTC

In reply to Hung-Chun Tseng

The date command only uses RTC sequence 0. On the ARM and RISC-V virt machines that is the PL031 or Goldfish RTC, so date never reads the virtio RTC unless that driver is disabled. rtc dev does not help, as rtc read reads raw registers, which the virtio RTC does not have.

Say this in the virtio documentation, and that x86 needs DM_RTC.

---
This is the follow-up Simon suggested on v5. It applies on top of the v5 series.

In my reply to the v5 cover letter I said the doc would point to "rtc dev" and "rtc read". That was wrong: "rtc dev 1" selects the virtio RTC, but "rtc read" then fails with -ENOSYS, as the driver has no register access.

 doc/develop/driver-model/virtio.rst | 8 ++++++++
 1 file changed, 8 insertions(+)
doc/develop/driver-model/virtio.rst +8 -0
index 30df0e944..94d3dabbd 100644
@@ -81,6 +81,14 @@ on QEMU ARM and x86, and v2.12.0+ on QEMU RISC-V.
 The VirtIO RTC device (``-device virtio-rtc-pci`` or
 ``-device virtio-rtc-device``) requires QEMU v11.1.0+.
 
+The ``date`` command only uses RTC sequence 0. The ARM and RISC-V ``virt``
+machines also have a PL031 or Goldfish RTC, which gets sequence 0, so
+``date`` reads the VirtIO RTC there only if ``CONFIG_RTC_PL031`` or
+``CONFIG_RTC_GOLDFISH`` is disabled. ``rtc list`` shows the sequence numbers.
+``rtc dev`` does not help, as ``rtc read`` reads raw registers, which the
+VirtIO RTC does not have. On x86, ``CONFIG_DM_RTC`` must be enabled for the
+driver to be built.
+
 Testing
 -------
 The following QEMU command line is used to get U-Boot up and running with
Signature · 1 line
2.43.0
#10 lore raw

PATCH 1/1 doc: virtio: Explain how to reach the virtio RTC

In reply to Hung-Chun Tseng

The date command only uses RTC sequence 0. On the ARM and RISC-V virt machines that is the PL031 or Goldfish RTC, so date never reads the virtio RTC unless that driver is disabled. rtc dev does not help, as rtc read reads raw registers, which the virtio RTC does not have.

Say this in the virtio documentation, and that x86 needs DM_RTC.

---
This is the follow-up Simon suggested on v5. It applies on top of the v5 series.

In my reply to the v5 cover letter I said the doc would point to "rtc dev" and "rtc read". That was wrong: "rtc dev 1" selects the virtio RTC, but "rtc read" then fails with -ENOSYS, as the driver has no register access.

 doc/develop/driver-model/virtio.rst | 8 ++++++++
 1 file changed, 8 insertions(+)
doc/develop/driver-model/virtio.rst +8 -0
index 30df0e944..94d3dabbd 100644
@@ -81,6 +81,14 @@ on QEMU ARM and x86, and v2.12.0+ on QEMU RISC-V.
 The VirtIO RTC device (``-device virtio-rtc-pci`` or
 ``-device virtio-rtc-device``) requires QEMU v11.1.0+.
 
+The ``date`` command only uses RTC sequence 0. The ARM and RISC-V ``virt``
+machines also have a PL031 or Goldfish RTC, which gets sequence 0, so
+``date`` reads the VirtIO RTC there only if ``CONFIG_RTC_PL031`` or
+``CONFIG_RTC_GOLDFISH`` is disabled. ``rtc list`` shows the sequence numbers.
+``rtc dev`` does not help, as ``rtc read`` reads raw registers, which the
+VirtIO RTC does not have. On x86, ``CONFIG_DM_RTC`` must be enabled for the
+driver to be built.
+
 Testing
 -------
 The following QEMU command line is used to get U-Boot up and running with
Signature · 1 line
2.43.0
#11 lore raw

Re: [PATCH] doc: virtio: Explain how to reach the virtio RTC

Quoted 5 lines · Hung-Chun Tseng

The date command only uses RTC sequence 0. On the ARM and RISC-V virt machines that is the PL031 or Goldfish RTC, so date never reads the virtio RTC unless that driver is disabled. rtc dev does not help, as rtc read reads raw registers, which the virtio RTC does not have.

Quoted 7 lines

Say this in the virtio documentation, and that x86 needs DM_RTC.

---
This is the follow-up Simon suggested on v5. It applies on top of the v5 series.

Why not send this as v6?

Regards,
Kuan-Wei

Quoted 31 lines

In my reply to the v5 cover letter I said the doc would point to "rtc dev" and "rtc read". That was wrong: "rtc dev 1" selects the virtio RTC, but "rtc read" then fails with -ENOSYS, as the driver has no register access.

 doc/develop/driver-model/virtio.rst | 8 ++++++++
 1 file changed, 8 insertions(+)
doc/develop/driver-model/virtio.rst +8 -0
index 30df0e944..94d3dabbd 100644
@@ -81,6 +81,14 @@ on QEMU ARM and x86, and v2.12.0+ on QEMU RISC-V.
 The VirtIO RTC device (``-device virtio-rtc-pci`` or
 ``-device virtio-rtc-device``) requires QEMU v11.1.0+.
 
+The ``date`` command only uses RTC sequence 0. The ARM and RISC-V ``virt``
+machines also have a PL031 or Goldfish RTC, which gets sequence 0, so
+``date`` reads the VirtIO RTC there only if ``CONFIG_RTC_PL031`` or
+``CONFIG_RTC_GOLDFISH`` is disabled. ``rtc list`` shows the sequence numbers.
+``rtc dev`` does not help, as ``rtc read`` reads raw registers, which the
+VirtIO RTC does not have. On x86, ``CONFIG_DM_RTC`` must be enabled for the
+driver to be built.
+
 Testing
 -------
 The following QEMU command line is used to get U-Boot up and running with
Signature · 1 line
2.43.0
#12 lore raw

Re: [PATCH] doc: virtio: Explain how to reach the virtio RTC

In reply to Hung-Chun Tseng

Hi Hung-Chun,

doc/develop/driver-model/virtio.rst Requirements · line 77

Quoted 7 lines · Hung-Chun Tseng
doc/develop/driver-model/virtio.rst +1 -0
@@ -73,6 +73,14 @@ Requirements
 It is required that QEMU v2.5.0+ should be used to test U-Boot VirtIO support
 on QEMU ARM and x86, and v2.12.0+ on QEMU RISC-V.
 
 
+The ``date`` command only uses RTC sequence 0. The ARM and RISC-V ``virt``

The 'Requirements' section is about QEMU versions, so this looks out of place. It would be worth giving the RTC its own short subsection, and moving the v5 paragraph about the virtio-rtc -device options into it too. If v5 does not already do this, please can you also update the 'Status' section near the top, which still says that only network and block devices are supported.

doc/develop/driver-model/virtio.rst Requirements · line 74

Quoted 4 lines
doc/develop/driver-model/virtio.rst +2 -0
@@ -73,6 +73,14 @@ Requirements
+VirtIO RTC does not have. On x86, ``CONFIG_DM_RTC`` must be enabled for the
+driver to be built.

I'm not sure x86 is any different. arch/Kconfig has 'imply RTC_MC146818' for X86 and the QEMU x86 devicetrees include rtc.dtsi, so with DM_RTC enabled I suspect the CMOS RTC binds early and gets sequence 0, while the VirtIO RTC turns up later on PCI. If so, 'date' would still not read the VirtIO RTC unless CONFIG_RTC_MC146818 is disabled. Please can you check this and, if it is right, describe all three architectures the same way.

Regards,
Simon