virtio-dev.lists.oasis-open.org archive mirror
 help / color / mirror / Atom feed
From: Peter Hilber <peter.hilber@opensynergy.com>
To: virtualization@lists.linux-foundation.org,
	virtio-dev@lists.oasis-open.org
Cc: Peter Hilber <peter.hilber@opensynergy.com>,
	linux-kernel@vger.kernel.org,
	"Michael S. Tsirkin" <mst@redhat.com>,
	Jason Wang <jasowang@redhat.com>,
	Xuan Zhuo <xuanzhuo@linux.alibaba.com>
Subject: [virtio-dev] [RFC PATCH 7/7] virtio_rtc: Add Arm Generic Timer cross-timestamping
Date: Fri, 30 Jun 2023 19:10:50 +0200	[thread overview]
Message-ID: <20230630171052.985577-8-peter.hilber@opensynergy.com> (raw)
In-Reply-To: <20230630171052.985577-1-peter.hilber@opensynergy.com>

Add PTP_SYS_OFFSET_PRECISE2 support on platforms using the Arm Generic
Timer, by forwarding the clocksource information from arm_arch_timer.

Support only the CP15 counter interfaces, since the memory-mapped
interfaces are not supported by the Virtio RTC draft spec [1].

[1] https://lists.oasis-open.org/archives/virtio-comment/202306/msg00592.html

Signed-off-by: Peter Hilber <peter.hilber@opensynergy.com>
---
 drivers/virtio/Kconfig          | 13 ++++++++++
 drivers/virtio/Makefile         |  1 +
 drivers/virtio/virtio_rtc_arm.c | 44 +++++++++++++++++++++++++++++++++
 3 files changed, 58 insertions(+)
 create mode 100644 drivers/virtio/virtio_rtc_arm.c

diff --git a/drivers/virtio/Kconfig b/drivers/virtio/Kconfig
index 7369ecd7dd01..ed3f541032a0 100644
--- a/drivers/virtio/Kconfig
+++ b/drivers/virtio/Kconfig
@@ -203,4 +203,17 @@ config VIRTIO_RTC_PTP
 
 	 If unsure, say Y.
 
+config VIRTIO_RTC_ARM
+	bool "Virtio RTC cross-timestamping using Arm Generic Timer"
+	default y
+	depends on VIRTIO_RTC_PTP && ARM_ARCH_TIMER
+	help
+	 This enables Virtio RTC cross-timestamping using the Arm Generic Timer.
+	 It only has an effect if the Virtio RTC device also supports this. The
+	 cross-timestamp is available through the PTP clock driver precise
+	 cross-timestamp ioctl (PTP_SYS_OFFSET_PRECISE2 or
+	 PTP_SYS_OFFSET_PRECISE).
+
+	 If unsure, say Y.
+
 endif # VIRTIO_MENU
diff --git a/drivers/virtio/Makefile b/drivers/virtio/Makefile
index 4d48cbcae6bb..781dff9f8822 100644
--- a/drivers/virtio/Makefile
+++ b/drivers/virtio/Makefile
@@ -15,3 +15,4 @@ obj-$(CONFIG_VIRTIO_DMA_SHARED_BUFFER) += virtio_dma_buf.o
 obj-$(CONFIG_VIRTIO_RTC) += virtio_rtc.o
 virtio_rtc-y := virtio_rtc_driver.o
 virtio_rtc-$(CONFIG_VIRTIO_RTC_PTP) += virtio_rtc_ptp.o
+virtio_rtc-$(CONFIG_VIRTIO_RTC_ARM) += virtio_rtc_arm.o
diff --git a/drivers/virtio/virtio_rtc_arm.c b/drivers/virtio/virtio_rtc_arm.c
new file mode 100644
index 000000000000..2367f054081c
--- /dev/null
+++ b/drivers/virtio/virtio_rtc_arm.c
@@ -0,0 +1,44 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Provides cross-timestamp params for Arm.
+ *
+ * Copyright (C) 2022-2023 OpenSynergy GmbH
+ */
+
+#include <clocksource/arm_arch_timer.h>
+#include <linux/err.h>
+
+#include <uapi/linux/virtio_rtc.h>
+
+#include "virtio_rtc_internal.h"
+
+static const u16 viortc_hw_counters[] = { VIRTIO_RTC_COUNTER_ARM_VIRT,
+					  VIRTIO_RTC_COUNTER_ARM_PHYS };
+
+/* see header for doc */
+int viortc_hw_get_counters(const u16 **hw_counters, int *num_hw_counters)
+{
+	*hw_counters = viortc_hw_counters;
+	*num_hw_counters = ARRAY_SIZE(viortc_hw_counters);
+
+	return 0;
+}
+
+/* see header for doc */
+int viortc_hw_xtstamp_params(u16 *hw_counter, struct clocksource **cs)
+{
+	*cs = arch_timer_get_cs();
+
+	switch (arch_timer_counter_get_type()) {
+	case ARCH_COUNTER_CP15_VIRT:
+		*hw_counter = VIRTIO_RTC_COUNTER_ARM_VIRT;
+		break;
+	case ARCH_COUNTER_CP15_PHYS:
+		*hw_counter = VIRTIO_RTC_COUNTER_ARM_PHYS;
+		break;
+	default:
+		return -EINVAL;
+	}
+
+	return 0;
+}
-- 
2.39.2


---------------------------------------------------------------------
To unsubscribe, e-mail: virtio-dev-unsubscribe@lists.oasis-open.org
For additional commands, e-mail: virtio-dev-help@lists.oasis-open.org


      parent reply	other threads:[~2023-06-30 17:12 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-30 17:10 [virtio-dev] [RFC PATCH 0/7] Add virtio_rtc module and related changes Peter Hilber
2023-06-30 17:10 ` [virtio-dev] [RFC PATCH 5/7] virtio_rtc: Add module and driver core Peter Hilber
2023-06-30 17:10 ` [virtio-dev] [RFC PATCH 6/7] virtio_rtc: Add PTP clocks Peter Hilber
2023-06-30 17:10 ` Peter Hilber [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230630171052.985577-8-peter.hilber@opensynergy.com \
    --to=peter.hilber@opensynergy.com \
    --cc=jasowang@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mst@redhat.com \
    --cc=virtio-dev@lists.oasis-open.org \
    --cc=virtualization@lists.linux-foundation.org \
    --cc=xuanzhuo@linux.alibaba.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).