mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Peter Hilber <peter.hilber@opensynergy.com>
To: linux-arm-kernel@lists.infradead.org
Cc: Peter Hilber <peter.hilber@opensynergy.com>,
	linux-kernel@vger.kernel.org, Mark Rutland <mark.rutland@arm.com>,
	Marc Zyngier <maz@kernel.org>,
	Daniel Lezcano <daniel.lezcano@linaro.org>,
	Thomas Gleixner <tglx@linutronix.de>
Subject: [RFC PATCH 4/7] clocksource: arm_arch_timer: Export counter type, clocksource
Date: Fri, 30 Jun 2023 19:10:47 +0200	[thread overview]
Message-ID: <20230630171052.985577-5-peter.hilber@opensynergy.com> (raw)
In-Reply-To: <20230630171052.985577-1-peter.hilber@opensynergy.com>

Export helper functions to allow other code to

- determine the counter type in use (virtual or physical, CP15 or memory),

- get a pointer to the arm_arch_timer clocksource, which can be compared
  with the current clocksource.

The virtio_rtc driver will require the clocksource pointer when using
get_device_system_crosststamp(), and should communicate the actual Arm
counter type to the Virtio RTC device (cf. spec draft [1]).

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

Signed-off-by: Peter Hilber <peter.hilber@opensynergy.com>
---
 drivers/clocksource/arm_arch_timer.c | 16 ++++++++++++++++
 include/clocksource/arm_arch_timer.h | 19 +++++++++++++++++++
 2 files changed, 35 insertions(+)

diff --git a/drivers/clocksource/arm_arch_timer.c b/drivers/clocksource/arm_arch_timer.c
index e733a2a1927a..cebdc1b2db4c 100644
--- a/drivers/clocksource/arm_arch_timer.c
+++ b/drivers/clocksource/arm_arch_timer.c
@@ -92,6 +92,7 @@ static enum vdso_clock_mode vdso_default = VDSO_CLOCKMODE_ARCHTIMER;
 #else
 static enum vdso_clock_mode vdso_default = VDSO_CLOCKMODE_NONE;
 #endif /* CONFIG_GENERIC_GETTIMEOFDAY */
+static enum arch_timer_counter_type arch_counter_type __ro_after_init = ARCH_COUNTER_CP15_VIRT;
 
 static cpumask_t evtstrm_available = CPU_MASK_NONE;
 static bool evtstrm_enable __ro_after_init = IS_ENABLED(CONFIG_ARM_ARCH_TIMER_EVTSTREAM);
@@ -1109,6 +1110,7 @@ static void __init arch_counter_register(unsigned type)
 				rd = arch_counter_get_cntvct;
 				scr = arch_counter_get_cntvct;
 			}
+			arch_counter_type = ARCH_COUNTER_CP15_VIRT;
 		} else {
 			if (arch_timer_counter_has_wa()) {
 				rd = arch_counter_get_cntpct_stable;
@@ -1117,6 +1119,7 @@ static void __init arch_counter_register(unsigned type)
 				rd = arch_counter_get_cntpct;
 				scr = arch_counter_get_cntpct;
 			}
+			arch_counter_type = ARCH_COUNTER_CP15_PHYS;
 		}
 
 		arch_timer_read_counter = rd;
@@ -1124,6 +1127,7 @@ static void __init arch_counter_register(unsigned type)
 	} else {
 		arch_timer_read_counter = arch_counter_get_cntvct_mem;
 		scr = arch_counter_get_cntvct_mem;
+		arch_counter_type = ARCH_COUNTER_MEM_VIRT;
 	}
 
 	width = arch_counter_get_width();
@@ -1777,6 +1781,18 @@ static int __init arch_timer_acpi_init(struct acpi_table_header *table)
 TIMER_ACPI_DECLARE(arch_timer, ACPI_SIG_GTDT, arch_timer_acpi_init);
 #endif
 
+enum arch_timer_counter_type arch_timer_counter_get_type(void)
+{
+	return arch_counter_type;
+}
+EXPORT_SYMBOL_GPL(arch_timer_counter_get_type);
+
+struct clocksource *arch_timer_get_cs(void)
+{
+	return &clocksource_counter;
+}
+EXPORT_SYMBOL_GPL(arch_timer_get_cs);
+
 int kvm_arch_ptp_get_crosststamp(u64 *cycle, struct timespec64 *ts,
 				 struct clocksource **cs)
 {
diff --git a/include/clocksource/arm_arch_timer.h b/include/clocksource/arm_arch_timer.h
index cbbc9a6dc571..b442db0b5ca0 100644
--- a/include/clocksource/arm_arch_timer.h
+++ b/include/clocksource/arm_arch_timer.h
@@ -43,6 +43,13 @@ enum arch_timer_spi_nr {
 	ARCH_TIMER_MAX_TIMER_SPI
 };
 
+enum arch_timer_counter_type {
+	ARCH_COUNTER_CP15_VIRT,
+	ARCH_COUNTER_CP15_PHYS,
+	ARCH_COUNTER_MEM_VIRT,
+	ARCH_COUNTER_MEM_PHYS,
+};
+
 #define ARCH_TIMER_PHYS_ACCESS		0
 #define ARCH_TIMER_VIRT_ACCESS		1
 #define ARCH_TIMER_MEM_PHYS_ACCESS	2
@@ -89,6 +96,8 @@ extern u32 arch_timer_get_rate(void);
 extern u64 (*arch_timer_read_counter)(void);
 extern struct arch_timer_kvm_info *arch_timer_get_kvm_info(void);
 extern bool arch_timer_evtstrm_available(void);
+extern enum arch_timer_counter_type arch_timer_counter_get_type(void);
+extern struct clocksource *arch_timer_get_cs(void);
 
 #else
 
@@ -107,6 +116,16 @@ static inline bool arch_timer_evtstrm_available(void)
 	return false;
 }
 
+static inline enum arch_timer_counter_type arch_timer_counter_get_type(void)
+{
+	return ARCH_COUNTER_CP15_VIRT;
+}
+
+static inline struct clocksource *arch_timer_get_cs(void)
+{
+	return NULL;
+}
+
 #endif
 
 #endif
-- 
2.39.2


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

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-30 17:10 [RFC PATCH 0/7] Add virtio_rtc module and related changes Peter Hilber
2023-06-30 17:10 ` [RFC PATCH 1/7] timekeeping: Fix cross-timestamp interpolation on counter wrap Peter Hilber
2023-07-07 22:51   ` John Stultz
2023-07-27 10:21     ` Peter Hilber
2023-06-30 17:10 ` [RFC PATCH 2/7] timekeeping: Fix cross-timestamp interpolation corner case decision Peter Hilber
2023-07-07 23:02   ` John Stultz
2023-07-27 10:21     ` Peter Hilber
2023-06-30 17:10 ` [RFC PATCH 3/7] timekeeping: Fix cross-timestamp interpolation for non-x86 Peter Hilber
2023-07-07 23:31   ` John Stultz
2023-07-27 10:21     ` Peter Hilber
2023-06-30 17:10 ` Peter Hilber [this message]
2023-07-03  8:13   ` [RFC PATCH 4/7] clocksource: arm_arch_timer: Export counter type, clocksource Marc Zyngier
2023-07-27 10:22     ` Peter Hilber
2023-07-28  8:11       ` Marc Zyngier
2023-07-31 16:15         ` Peter Hilber
2023-06-30 17:10 ` [RFC PATCH 5/7] virtio_rtc: Add module and driver core Peter Hilber
2023-06-30 17:10 ` [RFC PATCH 6/7] virtio_rtc: Add PTP clocks Peter Hilber
2023-06-30 17:10 ` [RFC PATCH 7/7] virtio_rtc: Add Arm Generic Timer cross-timestamping Peter Hilber

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-5-peter.hilber@opensynergy.com \
    --to=peter.hilber@opensynergy.com \
    --cc=daniel.lezcano@linaro.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=maz@kernel.org \
    --cc=tglx@linutronix.de \
    /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

all inboxes | Powered by JetHome®