mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Richard Henderson <rth@twiddle.net>
To: linux-kernel@vger.kernel.org
Cc: ink@jurassic.park.msu.ru, mattst88@gmail.com,
	linux-alpha@vger.kernel.org
Subject: [RFC PATCH 07/10] alpha: Add an rtc driver for the qemu wallclock PALcall
Date: Tue, 16 Jul 2013 10:34:15 -0700	[thread overview]
Message-ID: <1373996058-13399-8-git-send-email-rth@twiddle.net> (raw)
In-Reply-To: <1373996058-13399-1-git-send-email-rth@twiddle.net>

In the normal case, one wants the guest to follow the host time.
QEMU has a cserve call that retrieves the wall clock.

Signed-off-by: Richard Henderson <rth@twiddle.net>
---
 arch/alpha/include/asm/pal.h | 56 ++++++++++++++++++++++++++++++++++++++
 arch/alpha/kernel/Makefile   |  3 +-
 arch/alpha/kernel/rtc.c      | 65 +++++++++++++++++++++++++++++++++++++++-----
 drivers/rtc/Kconfig          |  7 +++++
 4 files changed, 122 insertions(+), 9 deletions(-)

diff --git a/arch/alpha/include/asm/pal.h b/arch/alpha/include/asm/pal.h
index e78ec9b..ccaa49a 100644
--- a/arch/alpha/include/asm/pal.h
+++ b/arch/alpha/include/asm/pal.h
@@ -112,5 +112,61 @@ __CALL_PAL_RW1(wtint, unsigned long, unsigned long);
 #define tbiap()		__tbi(-1, /* no second argument */)
 #define tbia()		__tbi(-2, /* no second argument */)
 
+/*
+ * QEMU Cserv routines..
+ */
+
+static inline unsigned long
+qemu_get_walltime(void)
+{
+	register unsigned long v0 __asm__("$0");
+	register unsigned long a0 __asm__("$16") = 3;
+
+	asm("call_pal %2 # cserve get_time"
+	    : "=r"(v0), "+r"(a0)
+	    : "i"(PAL_cserve)
+	    : "$17", "$18", "$19", "$20", "$21");
+
+	return v0;
+}
+
+static inline unsigned long
+qemu_get_alarm(void)
+{
+	register unsigned long v0 __asm__("$0");
+	register unsigned long a0 __asm__("$16") = 4;
+
+	asm("call_pal %2 # cserve get_alarm"
+	    : "=r"(v0), "+r"(a0)
+	    : "i"(PAL_cserve)
+	    : "$17", "$18", "$19", "$20", "$21");
+
+	return v0;
+}
+
+static inline void
+qemu_set_alarm_rel(unsigned long expire)
+{
+	register unsigned long a0 __asm__("$16") = 5;
+	register unsigned long a1 __asm__("$17") = expire;
+
+	asm volatile("call_pal %2 # cserve set_alarm_rel"
+		     : "+r"(a0), "+r"(a1)
+		     : "i"(PAL_cserve)
+		     : "$0", "$18", "$19", "$20", "$21");
+}
+
+static inline void
+qemu_set_alarm_abs(unsigned long expire)
+{
+	register unsigned long a0 __asm__("$16") = 6;
+	register unsigned long a1 __asm__("$17") = expire;
+
+	asm volatile("call_pal %2 # cserve set_alarm_abs"
+		     : "+r"(a0), "+r"(a1)
+		     : "i"(PAL_cserve)
+		     : "$0", "$18", "$19", "$20", "$21");
+}
+
 #endif /* !__ASSEMBLY__ */
 #endif /* __ALPHA_PAL_H */
diff --git a/arch/alpha/kernel/Makefile b/arch/alpha/kernel/Makefile
index 0d54650..bf04ee8 100644
--- a/arch/alpha/kernel/Makefile
+++ b/arch/alpha/kernel/Makefile
@@ -8,7 +8,7 @@ ccflags-y	:= -Wno-sign-compare
 
 obj-y    := entry.o traps.o process.o osf_sys.o irq.o \
 	    irq_alpha.o signal.o setup.o ptrace.o time.o \
-	    alpha_ksyms.o systbls.o err_common.o io.o
+	    alpha_ksyms.o systbls.o err_common.o io.o rtc.o
 
 obj-$(CONFIG_VGA_HOSE)	+= console.o
 obj-$(CONFIG_SMP)	+= smp.o
@@ -16,7 +16,6 @@ obj-$(CONFIG_PCI)	+= pci.o pci_iommu.o pci-sysfs.o
 obj-$(CONFIG_SRM_ENV)	+= srm_env.o
 obj-$(CONFIG_MODULES)	+= module.o
 obj-$(CONFIG_PERF_EVENTS) += perf_event.o
-obj-$(CONFIG_RTC_DRV_ALPHA) += rtc.o
 
 ifdef CONFIG_ALPHA_GENERIC
 
diff --git a/arch/alpha/kernel/rtc.c b/arch/alpha/kernel/rtc.c
index c8d284d..fd910ff 100644
--- a/arch/alpha/kernel/rtc.c
+++ b/arch/alpha/kernel/rtc.c
@@ -16,10 +16,12 @@
 #include <linux/platform_device.h>
 
 #include <asm/rtc.h>
+#include <asm/pal.h>
 
 #include "proto.h"
 
 
+#ifdef CONFIG_RTC_DRV_ALPHA
 /*
  * Support for the RTC device.
  *
@@ -293,20 +295,68 @@ static const struct rtc_class_ops remote_rtc_ops = {
 	.set_mmss = remote_set_mmss,
 	.ioctl = alpha_rtc_ioctl,
 };
-#endif
+#endif /* HAVE_REMOTE_RTC */
+#endif /* CONFIG_RTC_DRV_ALPHA */
+
+#ifdef CONFIG_RTC_DRV_ALPHA_QEMU
+/*
+ * Support for the QEMU wall clock as an RTC device.
+ */
+
+static int
+qemu_rtc_read_time(struct device *dev, struct rtc_time *tm)
+{
+	unsigned long nsec = qemu_get_walltime();
+	unsigned long sec = nsec / NSEC_PER_SEC;
 
+	rtc_time_to_tm(sec, tm);
+	return 0;
+}
+
+static int
+qemu_rtc_set_time(struct device *dev, struct rtc_time *tm)
+{
+	return -EOPNOTSUPP;
+}
+
+static int
+qemu_rtc_set_mmss(struct device *dev, unsigned long sec)
+{
+	return -EOPNOTSUPP;
+}
+
+static const struct rtc_class_ops qemu_rtc_ops = {
+	.read_time = qemu_rtc_read_time,
+	.set_time = qemu_rtc_set_time,
+	.set_mmss = qemu_rtc_set_mmss,
+};
+#endif /* CONFIG_RTC_DRV_ALPHA_QEMU */
+
+#if defined(CONFIG_RTC_DRV_ALPHA) || defined(CONFIG_RTC_DRV_ALPHA_QEMU)
 static int __init
-alpha_rtc_init(void)
+rtc_init(void)
 {
 	const struct rtc_class_ops *ops;
 	struct platform_device *pdev;
 	struct rtc_device *rtc;
 	const char *name;
 
+#ifdef CONFIG_RTC_DRV_ALPHA_QEMU
+	if (alpha_using_qemu) {
+		name = "rtc-qemu";
+		ops = &qemu_rtc_ops;
+
+		pdev = platform_device_register_simple(name, -1, NULL, 0);
+		rtc = devm_rtc_device_register(&pdev->dev, name, ops, NULL);
+		if (!IS_ERR(rtc))
+			platform_set_drvdata(pdev, rtc);
+	}
+#endif /* ALPHA_QEMU */
+
+#ifdef CONFIG_RTC_DRV_ALPHA
 	init_rtc_epoch();
 	name = "rtc-alpha";
 	ops = &alpha_rtc_ops;
-
 #ifdef HAVE_REMOTE_RTC
 	if (alpha_mv.rtc_boot_cpu_only)
 		ops = &remote_rtc_ops;
@@ -314,10 +364,11 @@ alpha_rtc_init(void)
 
 	pdev = platform_device_register_simple(name, -1, NULL, 0);
 	rtc = devm_rtc_device_register(&pdev->dev, name, ops, THIS_MODULE);
-	if (IS_ERR(rtc))
-		return PTR_ERR(rtc);
+	if (!IS_ERR(rtc))
+		platform_set_drvdata(pdev, rtc);
+#endif /* ALPHA */
 
-	platform_set_drvdata(pdev, rtc);
 	return 0;
 }
-device_initcall(alpha_rtc_init);
+device_initcall(rtc_init);
+#endif
diff --git a/drivers/rtc/Kconfig b/drivers/rtc/Kconfig
index a4d3f9a..1884ca4 100644
--- a/drivers/rtc/Kconfig
+++ b/drivers/rtc/Kconfig
@@ -631,6 +631,13 @@ config RTC_DRV_ALPHA
 	  Direct support for the real-time clock found on every Alpha
 	  system, specifically MC146818 compatibles.  If in doubt, say Y.
 
+config RTC_DRV_ALPHA_QEMU
+	bool "Alpha QEMU paravirtual RTC"
+	depends on ALPHA
+	default y if ALPHA_QEMU
+	help
+	  Support for the paravirtual real-time clock found in QEMU.
+
 config RTC_DRV_VRTC
 	tristate "Virtual RTC for Intel MID platforms"
 	depends on X86_INTEL_MID
-- 
1.8.1.4


  parent reply	other threads:[~2013-07-16 17:36 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-07-16 17:34 [RFC PATCH 00/10] Alpha support for QEMU Richard Henderson
2013-07-16 17:34 ` [RFC PATCH 01/10] alpha: Don't if-out dp264_device_interrupt Richard Henderson
2013-07-16 17:34 ` [RFC PATCH 02/10] alpha: Notice if we're being run under QEMU Richard Henderson
2013-07-16 17:34 ` [RFC PATCH 03/10] alpha: Force the user-visible HZ to a constant 1024 Richard Henderson
2013-07-16 17:34 ` [RFC PATCH 04/10] alpha: Allow HZ to be configured Richard Henderson
2013-07-16 17:34 ` [RFC PATCH 05/10] alpha: Primitive support for CPU power down Richard Henderson
2013-07-17  5:17   ` Matt Turner
2013-07-17 13:16     ` Richard Henderson
2013-07-16 17:34 ` [RFC PATCH 06/10] alpha: Reorganize rtc handling Richard Henderson
2013-07-16 17:34 ` Richard Henderson [this message]
2013-07-16 17:34 ` [RFC PATCH 08/10] alpha: Always enable the rpcc clocksource for single processor Richard Henderson
2013-07-16 17:34 ` [RFC PATCH 09/10] alpha: Switch to GENERIC_CLOCKEVENTS Richard Henderson
2013-07-16 17:34 ` [RFC PATCH 10/10] alpha: Use qemu+cserve provided high-res clock and alarm Richard Henderson
2013-07-18  1:14 ` [RFC PATCH 00/10] Alpha support for QEMU Michael Cree
2013-07-18 13:38   ` Richard Henderson
2013-07-18 21:28     ` Michael Cree
2013-07-18 22:04       ` Richard Henderson
2013-07-19 10:03         ` Michael Cree

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=1373996058-13399-8-git-send-email-rth@twiddle.net \
    --to=rth@twiddle.net \
    --cc=ink@jurassic.park.msu.ru \
    --cc=linux-alpha@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mattst88@gmail.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

all inboxes | Powered by JetHome®