Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

virtio_rtc: Add Arm Generic Timer cross-timestamping

For platforms using the Arm Generic Timer, add precise cross-timestamping
support to virtio_rtc.

Always report the CP15 virtual counter as the HW counter in use by
arm_arch_timer, since the Linux kernel's usage of the Arm Generic Timer
should always be compatible with this.

Signed-off-by: Peter Hilber <quic_philber@quicinc.com>
Message-Id: <20250509160734.1772-4-quic_philber@quicinc.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>

authored by

Peter Hilber and committed by
Michael S. Tsirkin
e2ef1675 9a17125a

+37
+13
drivers/virtio/Kconfig
··· 221 221 222 222 If unsure, say Y. 223 223 224 + config VIRTIO_RTC_ARM 225 + bool "Virtio RTC cross-timestamping using Arm Generic Timer" 226 + default y 227 + depends on VIRTIO_RTC_PTP && ARM_ARCH_TIMER 228 + help 229 + This enables Virtio RTC cross-timestamping using the Arm Generic Timer. 230 + It only has an effect if the Virtio RTC device also supports this. The 231 + cross-timestamp is available through the PTP clock driver precise 232 + cross-timestamp ioctl (PTP_SYS_OFFSET_PRECISE2 aka 233 + PTP_SYS_OFFSET_PRECISE). 234 + 235 + If unsure, say Y. 236 + 224 237 endif # VIRTIO_RTC 225 238 226 239 endif # VIRTIO_MENU
+1
drivers/virtio/Makefile
··· 17 17 obj-$(CONFIG_VIRTIO_RTC) += virtio_rtc.o 18 18 virtio_rtc-y := virtio_rtc_driver.o 19 19 virtio_rtc-$(CONFIG_VIRTIO_RTC_PTP) += virtio_rtc_ptp.o 20 + virtio_rtc-$(CONFIG_VIRTIO_RTC_ARM) += virtio_rtc_arm.o
+23
drivers/virtio/virtio_rtc_arm.c
··· 1 + // SPDX-License-Identifier: GPL-2.0-or-later 2 + /* 3 + * Provides cross-timestamp params for Arm. 4 + * 5 + * Copyright (C) 2022-2023 OpenSynergy GmbH 6 + * Copyright (c) 2024 Qualcomm Innovation Center, Inc. All rights reserved. 7 + */ 8 + 9 + #include <linux/clocksource_ids.h> 10 + 11 + #include <uapi/linux/virtio_rtc.h> 12 + 13 + #include "virtio_rtc_internal.h" 14 + 15 + /* see header for doc */ 16 + 17 + int viortc_hw_xtstamp_params(u8 *hw_counter, enum clocksource_ids *cs_id) 18 + { 19 + *hw_counter = VIRTIO_RTC_COUNTER_ARM_VCT; 20 + *cs_id = CSID_ARM_ARCH_COUNTER; 21 + 22 + return 0; 23 + }