public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
From: Marcelo Tosatti <mtosatti@redhat.com>
To: Avi Kivity <avi@qumranet.com>
Cc: Chris Wright <chrisw@redhat.com>,
	Glauber Costa <gcosta@redhat.com>,
	Anthony Liguori <aliguori@us.ibm.com>,
	kvm@vger.kernel.org, Marcelo Tosatti <mtosatti@redhat.com>,
	john stultz <johnstul@us.ibm.com>,
	Thomas Gleixner <tglx@linutronix.de>
Subject: [patch 01/12] expose ACPI pmtimer to userspace (/dev/pmtimer)
Date: Thu, 29 May 2008 19:22:50 -0300	[thread overview]
Message-ID: <20080529222828.541115340@localhost.localdomain> (raw)
In-Reply-To: 20080529222249.563011248@localhost.localdomain

[-- Attachment #1: pmtimer-dev --]
[-- Type: text/plain, Size: 4032 bytes --]

KVM wishes to allow direct guest access to the ACPI pmtimer. In that
case QEMU/KVM has to read the current value for migration, so the proper
syncing can be done on the destination.

This patch will not register the device if the chipset has an unreliable
timer.

Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>

CC: john stultz <johnstul@us.ibm.com>
CC: Thomas Gleixner <tglx@linutronix.de>

Index: kvm/drivers/char/Kconfig
===================================================================
--- kvm.orig/drivers/char/Kconfig
+++ kvm/drivers/char/Kconfig
@@ -1057,6 +1057,13 @@ config HPET_MMAP
 	  exposed to the user.  If this applies to your hardware,
 	  say N here.
 
+config ACPI_PMTIMER_DEV
+	tristate "ACPI PM-Timer device"
+	default n
+	depends on ACPI && X86_PM_TIMER
+	help
+	 Allow userspace to read the ACPI PM-Timer value.
+
 config HANGCHECK_TIMER
 	tristate "Hangcheck timer"
 	depends on X86 || IA64 || PPC64 || S390
Index: kvm/drivers/char/Makefile
===================================================================
--- kvm.orig/drivers/char/Makefile
+++ kvm/drivers/char/Makefile
@@ -112,6 +112,7 @@ obj-$(CONFIG_PS3_FLASH)		+= ps3flash.o
 
 obj-$(CONFIG_JS_RTC)		+= js-rtc.o
 js-rtc-y = rtc.o
+obj-$(CONFIG_ACPI_PMTIMER_DEV)	+= acpi_pmtimer.o
 
 # Files generated that shall be removed upon make clean
 clean-files := consolemap_deftbl.c defkeymap.c
Index: kvm/drivers/char/acpi_pmtimer.c
===================================================================
--- /dev/null
+++ kvm/drivers/char/acpi_pmtimer.c
@@ -0,0 +1,61 @@
+#include <linux/types.h>
+#include <linux/module.h>
+#include <linux/fs.h>
+#include <linux/miscdevice.h>
+#include <linux/acpi_pmtmr.h>
+
+#include <asm/io.h>
+#include <asm/uaccess.h>
+
+static ssize_t pmtimer_read(struct file *file, char __user *buf, size_t count,
+			    loff_t *ppos)
+{
+	int ret;
+	__u32 value;
+
+	ret = -EINVAL;
+	if (count < sizeof(u32))
+		goto out;
+
+	value = inl(pmtmr_ioport) & ACPI_PM_MASK;
+
+	ret = -EFAULT;
+	if (put_user(value, (u32 __user *)buf))
+		goto out;
+
+	ret = sizeof(value);
+out:
+	return ret;
+}
+
+static const struct file_operations acpi_pmtimer_fops = {
+	.owner =	THIS_MODULE,
+	.read =		pmtimer_read,
+};
+
+static struct miscdevice pmtimer_miscdev = {
+	MISC_DYNAMIC_MINOR,
+	"pmtimer",
+	&acpi_pmtimer_fops,
+};
+
+static int __init pmtimer_init(void)
+{
+	if (!pmtmr_ioport || !pmtimer_is_reliable())
+		return -ENODEV;
+
+	return misc_register(&pmtimer_miscdev);
+}
+
+static void __exit pmtimer_exit(void)
+{
+	if (pmtmr_ioport && pmtimer_is_reliable())
+		misc_deregister(&pmtimer_miscdev);
+}
+
+module_init(pmtimer_init);
+module_exit(pmtimer_exit);
+MODULE_AUTHOR ("Marcelo Tosatti <mtosatti@redhat.com>");
+MODULE_DESCRIPTION("ACPI PM-Timer");
+MODULE_LICENSE ("GPL");
+
Index: kvm/drivers/clocksource/acpi_pm.c
===================================================================
--- kvm.orig/drivers/clocksource/acpi_pm.c
+++ kvm/drivers/clocksource/acpi_pm.c
@@ -30,6 +30,8 @@
  */
 u32 pmtmr_ioport __read_mostly;
 
+static int reliable_pmtimer;
+
 static inline u32 read_pmtmr(void)
 {
 	/* mask the output to 24 bits */
@@ -208,10 +210,21 @@ pm_good:
 	if (verify_pmtmr_rate() != 0)
 		return -ENODEV;
 
+	if (clocksource_acpi_pm.read == acpi_pm_read)
+		reliable_pmtimer = 1;
+
 	return clocksource_register(&clocksource_acpi_pm);
 }
 
+int pmtimer_is_reliable(void)
+{
+	return reliable_pmtimer;
+}
+
 /* We use fs_initcall because we want the PCI fixups to have run
  * but we still need to load before device_initcall
  */
 fs_initcall(init_acpi_pm_clocksource);
+
+EXPORT_SYMBOL(pmtmr_ioport);
+EXPORT_SYMBOL(pmtimer_is_reliable);
Index: kvm/include/linux/acpi_pmtmr.h
===================================================================
--- kvm.orig/include/linux/acpi_pmtmr.h
+++ kvm/include/linux/acpi_pmtmr.h
@@ -27,6 +27,8 @@ static inline u32 acpi_pm_read_early(voi
 
 extern void pmtimer_wait(unsigned);
 
+int pmtimer_is_reliable(void);
+
 #else
 
 static inline u32 acpi_pm_read_early(void)

-- 


  reply	other threads:[~2008-05-29 22:34 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-05-29 22:22 [patch 00/12] fake ACPI C2 emulation v2 Marcelo Tosatti
2008-05-29 22:22 ` Marcelo Tosatti [this message]
2008-06-01 16:34   ` [patch 01/12] expose ACPI pmtimer to userspace (/dev/pmtimer) Thomas Gleixner
2008-06-01 16:56     ` Anthony Liguori
2008-06-04  9:53       ` Avi Kivity
2008-06-04 10:01         ` Thomas Gleixner
2008-06-04 10:35           ` Avi Kivity
2008-06-01 17:56     ` Marcelo Tosatti
2008-06-01 18:17       ` Thomas Gleixner
2008-06-02 16:43       ` John Stultz
2008-06-03  4:09         ` Marcelo Tosatti
2008-05-29 22:22 ` [patch 02/12] KVM: allow multiple IO bitmap pages, provide userspace interface Marcelo Tosatti
2008-05-29 22:22 ` [patch 03/12] KVM: allow userspace to open access to ACPI pmtimer Marcelo Tosatti
2008-05-29 22:22 ` [patch 04/12] KVM: move muldiv64 to x86.c, export Marcelo Tosatti
2008-05-29 22:22 ` [patch 05/12] KVM: in-kernel ACPI timer emulation Marcelo Tosatti
2008-05-29 22:22 ` [patch 06/12] QEMU/KVM: self-disabling C2 emulation Marcelo Tosatti
2008-05-29 22:22 ` [patch 07/12] libkvm: interface to KVM_SET_OPEN_IOPORT Marcelo Tosatti
2008-05-29 22:22 ` [patch 08/12] QEMU/KVM: non-virtualized ACPI PMTimer support Marcelo Tosatti
2008-05-29 22:22 ` [patch 09/12] libkvm: in-kernel ACPI pmtimer interface Marcelo Tosatti
2008-05-29 22:22 ` [patch 10/12] QEMU/KVM: add option to disable in-kernel pmtimer emulation Marcelo Tosatti
2008-05-29 22:23 ` [patch 11/12] libkvm: interface for pmtimer save/restore Marcelo Tosatti
2008-05-29 22:23 ` [patch 12/12] QEMU/KVM: in-kernel pmtimer save/restore support Marcelo Tosatti
2008-06-01  9:21 ` [patch 00/12] fake ACPI C2 emulation v2 Avi Kivity
2008-06-02 16:08   ` Marcelo Tosatti
2008-06-04 10:49     ` Avi Kivity
2008-06-05  3:12       ` Marcelo Tosatti
2008-06-05  7:56         ` Avi Kivity

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=20080529222828.541115340@localhost.localdomain \
    --to=mtosatti@redhat.com \
    --cc=aliguori@us.ibm.com \
    --cc=avi@qumranet.com \
    --cc=chrisw@redhat.com \
    --cc=gcosta@redhat.com \
    --cc=johnstul@us.ibm.com \
    --cc=kvm@vger.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