From mboxrd@z Thu Jan 1 00:00:00 1970 From: "Yang, Sheng" Subject: [PATCH 4/6] KVM: Add save/restore supporting of in kernel PIT Date: Fri, 7 Mar 2008 20:52:18 +0800 Message-ID: <200803072052.18203.sheng.yang@intel.com> Mime-Version: 1.0 Content-Type: Multipart/Mixed; boundary="Boundary-00=_CqT0Hz7QqHbDg91" To: kvm-devel@lists.sourceforge.net Return-path: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: kvm-devel-bounces@lists.sourceforge.net Errors-To: kvm-devel-bounces@lists.sourceforge.net List-Id: kvm.vger.kernel.org --Boundary-00=_CqT0Hz7QqHbDg91 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline =46rom a16353c6fd51d5057d748198ba24d272be73d86b Mon Sep 17 00:00:00 2001 =46rom: Sheng Yang Date: Tue, 4 Mar 2008 00:50:59 +0800 Subject: [PATCH] KVM: Add save/restore supporting of in kernel PIT Signed-off-by: Sheng Yang =2D-- arch/x86/kvm/i8254.c | 7 +++++++ arch/x86/kvm/i8254.h | 1 + arch/x86/kvm/x86.c | 48 +++++++++++++++++++++++++++++++++++++++++++++= +++ include/asm-x86/kvm.h | 21 +++++++++++++++++++++ include/linux/kvm.h | 2 ++ 5 files changed, 79 insertions(+), 0 deletions(-) diff --git a/arch/x86/kvm/i8254.c b/arch/x86/kvm/i8254.c index 1031901..7776f50 100644 =2D-- a/arch/x86/kvm/i8254.c +++ b/arch/x86/kvm/i8254.c @@ -286,6 +286,13 @@ static void pit_load_count(struct kvm *kvm, int channe= l,=20 u32 val) } } +void kvm_pit_load_count(struct kvm *kvm, int channel, u32 val) +{ + mutex_lock(&kvm->arch.vpit->pit_state.lock); + pit_load_count(kvm, channel, val); + mutex_unlock(&kvm->arch.vpit->pit_state.lock); +} + static void pit_ioport_write(struct kvm_io_device *this, gpa_t addr, int len, const void *data) { diff --git a/arch/x86/kvm/i8254.h b/arch/x86/kvm/i8254.h index 38184d5..586bbf0 100644 =2D-- a/arch/x86/kvm/i8254.h +++ b/arch/x86/kvm/i8254.h @@ -54,6 +54,7 @@ struct kvm_pit { void kvm_inject_pit_timer_irqs(struct kvm_vcpu *vcpu); void kvm_pit_timer_intr_post(struct kvm_vcpu *vcpu, int vec); +void kvm_pit_load_count(struct kvm *kvm, int channel, u32 val); struct kvm_pit *kvm_create_pit(struct kvm *kvm); void kvm_free_pit(struct kvm *kvm); diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 421b2b5..5339ab1 100644 =2D-- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -1501,6 +1501,23 @@ static int kvm_vm_ioctl_set_irqchip(struct kvm *kvm,= =20 struct kvm_irqchip *chip) return r; } +static int kvm_vm_ioctl_get_pit(struct kvm *kvm, struct kvm_pit_state *ps) +{ + int r =3D 0; + + memcpy(ps, &kvm->arch.vpit->pit_state, sizeof(struct kvm_pit_state)); + return r; +} + +static int kvm_vm_ioctl_set_pit(struct kvm *kvm, struct kvm_pit_state *ps) +{ + int r =3D 0; + + memcpy(&kvm->arch.vpit->pit_state, ps, sizeof(struct kvm_pit_state)); + kvm_pit_load_count(kvm, 0, ps->channels[0].count); + return r; +} + /* * Get (and clear) the dirty memory log for a memory slot. */ @@ -1654,6 +1671,37 @@ long kvm_arch_vm_ioctl(struct file *filp, r =3D 0; break; } + case KVM_GET_PIT: { + struct kvm_pit_state ps; + r =3D -EFAULT; + if (copy_from_user(&ps, argp, sizeof ps)) + goto out; + r =3D -ENXIO; + if (!kvm->arch.vpit) + goto out; + r =3D kvm_vm_ioctl_get_pit(kvm, &ps); + if (r) + goto out; + r =3D -EFAULT; + if (copy_to_user(argp, &ps, sizeof ps)) + goto out; + r =3D 0; + break; + } + case KVM_SET_PIT: { + struct kvm_pit_state ps; + r =3D -EFAULT; + if (copy_from_user(&ps, argp, sizeof ps)) + goto out; + r =3D -ENXIO; + if (!kvm->arch.vpit) + goto out; + r =3D kvm_vm_ioctl_set_pit(kvm, &ps); + if (r) + goto out; + r =3D 0; + break; + } default: ; } diff --git a/include/asm-x86/kvm.h b/include/asm-x86/kvm.h index 7a71120..12b4b25 100644 =2D-- a/include/asm-x86/kvm.h +++ b/include/asm-x86/kvm.h @@ -188,4 +188,25 @@ struct kvm_cpuid2 { struct kvm_cpuid_entry2 entries[0]; }; +/* for KVM_GET_PIT and KVM_SET_PIT */ +struct kvm_pit_channel_state { + __u32 count; /* can be 65536 */ + __u16 latched_count; + __u8 count_latched; + __u8 status_latched; + __u8 status; + __u8 read_state; + __u8 write_state; + __u8 write_latch; + __u8 rw_mode; + __u8 mode; + __u8 bcd; + __u8 gate; + __s64 count_load_time; +}; + +struct kvm_pit_state { + struct kvm_pit_channel_state channels[3]; +}; + #endif diff --git a/include/linux/kvm.h b/include/linux/kvm.h index cefa9a2..a2f3274 100644 =2D-- a/include/linux/kvm.h +++ b/include/linux/kvm.h @@ -260,6 +260,8 @@ struct kvm_vapic_addr { #define KVM_GET_IRQCHIP _IOWR(KVMIO, 0x62, struct kvm_irqchip) #define KVM_SET_IRQCHIP _IOR(KVMIO, 0x63, struct kvm_irqchip) #define KVM_CREATE_PIT _IO(KVMIO, 0x64) +#define KVM_GET_PIT _IOWR(KVMIO, 0x65, struct kvm_pit_state) +#define KVM_SET_PIT _IOR(KVMIO, 0x66, struct kvm_pit_state) /* * ioctls for vcpu fds =2D- debian.1.5.3.7.1-dirty --Boundary-00=_CqT0Hz7QqHbDg91 Content-Type: text/x-diff; charset="utf-8"; name="0002-KVM-Add-save-restore-supporting-of-in-kernel-PIT.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="0002-KVM-Add-save-restore-supporting-of-in-kernel-PIT.patch" =46rom a16353c6fd51d5057d748198ba24d272be73d86b Mon Sep 17 00:00:00 2001 =46rom: Sheng Yang Date: Tue, 4 Mar 2008 00:50:59 +0800 Subject: [PATCH] KVM: Add save/restore supporting of in kernel PIT Signed-off-by: Sheng Yang =2D-- arch/x86/kvm/i8254.c | 7 +++++++ arch/x86/kvm/i8254.h | 1 + arch/x86/kvm/x86.c | 48 +++++++++++++++++++++++++++++++++++++++++++++= +++ include/asm-x86/kvm.h | 21 +++++++++++++++++++++ include/linux/kvm.h | 2 ++ 5 files changed, 79 insertions(+), 0 deletions(-) diff --git a/arch/x86/kvm/i8254.c b/arch/x86/kvm/i8254.c index 1031901..7776f50 100644 =2D-- a/arch/x86/kvm/i8254.c +++ b/arch/x86/kvm/i8254.c @@ -286,6 +286,13 @@ static void pit_load_count(struct kvm *kvm, int channe= l, u32 val) } } =20 +void kvm_pit_load_count(struct kvm *kvm, int channel, u32 val) +{ + mutex_lock(&kvm->arch.vpit->pit_state.lock); + pit_load_count(kvm, channel, val); + mutex_unlock(&kvm->arch.vpit->pit_state.lock); +} + static void pit_ioport_write(struct kvm_io_device *this, gpa_t addr, int len, const void *data) { diff --git a/arch/x86/kvm/i8254.h b/arch/x86/kvm/i8254.h index 38184d5..586bbf0 100644 =2D-- a/arch/x86/kvm/i8254.h +++ b/arch/x86/kvm/i8254.h @@ -54,6 +54,7 @@ struct kvm_pit { =20 void kvm_inject_pit_timer_irqs(struct kvm_vcpu *vcpu); void kvm_pit_timer_intr_post(struct kvm_vcpu *vcpu, int vec); +void kvm_pit_load_count(struct kvm *kvm, int channel, u32 val); struct kvm_pit *kvm_create_pit(struct kvm *kvm); void kvm_free_pit(struct kvm *kvm); =20 diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 421b2b5..5339ab1 100644 =2D-- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -1501,6 +1501,23 @@ static int kvm_vm_ioctl_set_irqchip(struct kvm *kvm,= struct kvm_irqchip *chip) return r; } =20 +static int kvm_vm_ioctl_get_pit(struct kvm *kvm, struct kvm_pit_state *ps) +{ + int r =3D 0; + + memcpy(ps, &kvm->arch.vpit->pit_state, sizeof(struct kvm_pit_state)); + return r; +} + +static int kvm_vm_ioctl_set_pit(struct kvm *kvm, struct kvm_pit_state *ps) +{ + int r =3D 0; + + memcpy(&kvm->arch.vpit->pit_state, ps, sizeof(struct kvm_pit_state)); + kvm_pit_load_count(kvm, 0, ps->channels[0].count); + return r; +} + /* * Get (and clear) the dirty memory log for a memory slot. */ @@ -1654,6 +1671,37 @@ long kvm_arch_vm_ioctl(struct file *filp, r =3D 0; break; } + case KVM_GET_PIT: { + struct kvm_pit_state ps; + r =3D -EFAULT; + if (copy_from_user(&ps, argp, sizeof ps)) + goto out; + r =3D -ENXIO; + if (!kvm->arch.vpit) + goto out; + r =3D kvm_vm_ioctl_get_pit(kvm, &ps); + if (r) + goto out; + r =3D -EFAULT; + if (copy_to_user(argp, &ps, sizeof ps)) + goto out; + r =3D 0; + break; + } + case KVM_SET_PIT: { + struct kvm_pit_state ps; + r =3D -EFAULT; + if (copy_from_user(&ps, argp, sizeof ps)) + goto out; + r =3D -ENXIO; + if (!kvm->arch.vpit) + goto out; + r =3D kvm_vm_ioctl_set_pit(kvm, &ps); + if (r) + goto out; + r =3D 0; + break; + } default: ; } diff --git a/include/asm-x86/kvm.h b/include/asm-x86/kvm.h index 7a71120..12b4b25 100644 =2D-- a/include/asm-x86/kvm.h +++ b/include/asm-x86/kvm.h @@ -188,4 +188,25 @@ struct kvm_cpuid2 { struct kvm_cpuid_entry2 entries[0]; }; =20 +/* for KVM_GET_PIT and KVM_SET_PIT */ +struct kvm_pit_channel_state { + __u32 count; /* can be 65536 */ + __u16 latched_count; + __u8 count_latched; + __u8 status_latched; + __u8 status; + __u8 read_state; + __u8 write_state; + __u8 write_latch; + __u8 rw_mode; + __u8 mode; + __u8 bcd; + __u8 gate; + __s64 count_load_time; +}; + +struct kvm_pit_state { + struct kvm_pit_channel_state channels[3]; +}; + #endif diff --git a/include/linux/kvm.h b/include/linux/kvm.h index cefa9a2..a2f3274 100644 =2D-- a/include/linux/kvm.h +++ b/include/linux/kvm.h @@ -260,6 +260,8 @@ struct kvm_vapic_addr { #define KVM_GET_IRQCHIP _IOWR(KVMIO, 0x62, struct kvm_irqchip) #define KVM_SET_IRQCHIP _IOR(KVMIO, 0x63, struct kvm_irqchip) #define KVM_CREATE_PIT _IO(KVMIO, 0x64) +#define KVM_GET_PIT _IOWR(KVMIO, 0x65, struct kvm_pit_state) +#define KVM_SET_PIT _IOR(KVMIO, 0x66, struct kvm_pit_state) =20 /* * ioctls for vcpu fds =2D-=20 debian.1.5.3.7.1-dirty --Boundary-00=_CqT0Hz7QqHbDg91 Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline ------------------------------------------------------------------------- This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008. http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/ --Boundary-00=_CqT0Hz7QqHbDg91 Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ kvm-devel mailing list kvm-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/kvm-devel --Boundary-00=_CqT0Hz7QqHbDg91--