From 9df57feb102971e226455b84bd02df09902a4460 Mon Sep 17 00:00:00 2001 From: Sheng Yang Date: Sun, 27 Jan 2008 11:25:29 +0800 Subject: [PATCH] kvm: libkvm: Add Support for in-kernel PIT model Signed-off-by: Sheng Yang Signed-off-by: Avi Kivity --- kvm/kernel/Kbuild | 2 +- kvm/libkvm/kvm-common.h | 4 ++++ kvm/libkvm/libkvm-x86.c | 25 +++++++++++++++++++++++++ kvm/libkvm/libkvm.c | 5 +++++ 4 files changed, 35 insertions(+), 1 deletion(-) diff --git a/kvm/kernel/Kbuild b/kvm/kernel/Kbuild index ed02f5a7d2..014cc178f8 100644 --- a/kvm/kernel/Kbuild +++ b/kvm/kernel/Kbuild @@ -1,7 +1,7 @@ EXTRA_CFLAGS := -I$(src)/include -include $(src)/external-module-compat.h obj-m := kvm.o kvm-intel.o kvm-amd.o kvm-objs := kvm_main.o x86.o mmu.o x86_emulate.o anon_inodes.o irq.o i8259.o \ - lapic.o ioapic.o preempt.o + lapic.o ioapic.o preempt.o i8254.o kvm-intel-objs := vmx.o vmx-debug.o kvm-amd-objs := svm.o diff --git a/kvm/libkvm/kvm-common.h b/kvm/libkvm/kvm-common.h index d4df1a4f56..b8a88ee00e 100644 --- a/kvm/libkvm/kvm-common.h +++ b/kvm/libkvm/kvm-common.h @@ -47,6 +47,10 @@ struct kvm_context { int no_irqchip_creation; /// in-kernel irqchip status int irqchip_in_kernel; + /// do not create in-kernel pit if set + int no_pit_creation; + /// in-kernel pit status + int pit_in_kernel; }; void init_slots(void); diff --git a/kvm/libkvm/libkvm-x86.c b/kvm/libkvm/libkvm-x86.c index 4bd0e2f19a..b3a241e294 100644 --- a/kvm/libkvm/libkvm-x86.c +++ b/kvm/libkvm/libkvm-x86.c @@ -144,6 +144,27 @@ int kvm_arch_create_default_phys_mem(kvm_context_t kvm, return 0; } +int kvm_create_pit(kvm_context_t kvm) +{ +#ifdef KVM_CAP_PIT + int r; + + kvm->pit_in_kernel = 0; + if (!kvm->no_pit_creation) { + r = ioctl(kvm->fd, KVM_CHECK_EXTENSION, KVM_CAP_PIT); + if (r > 0) { + r = ioctl(kvm->vm_fd, KVM_CREATE_PIT); + if (r >= 0) + kvm->pit_in_kernel = 1; + else { + printf("Create kernel PIC irqchip failed\n"); + return r; + } + } + } +#endif + return 0; +} int kvm_arch_create(kvm_context_t kvm, unsigned long phys_mem_bytes, void **vm_mem) @@ -154,6 +175,10 @@ int kvm_arch_create(kvm_context_t kvm, unsigned long phys_mem_bytes, if (r < 0) return r; + r = kvm_create_pit(kvm); + if (r < 0) + return r; + return 0; } diff --git a/kvm/libkvm/libkvm.c b/kvm/libkvm/libkvm.c index 966501cb74..a7cc0e6fd2 100644 --- a/kvm/libkvm/libkvm.c +++ b/kvm/libkvm/libkvm.c @@ -271,6 +271,11 @@ void kvm_disable_irqchip_creation(kvm_context_t kvm) kvm->no_irqchip_creation = 1; } +void kvm_disable_pit_creation(kvm_context_t kvm) +{ + kvm->no_pit_creation = 1; +} + int kvm_create_vcpu(kvm_context_t kvm, int slot) { long mmap_size; -- 2.11.4.GIT