From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1ME3oS-0008QS-O7 for qemu-devel@nongnu.org; Tue, 09 Jun 2009 12:04:36 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1ME3oN-0008Ls-IE for qemu-devel@nongnu.org; Tue, 09 Jun 2009 12:04:35 -0400 Received: from [199.232.76.173] (port=35600 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1ME3oM-0008Lf-CY for qemu-devel@nongnu.org; Tue, 09 Jun 2009 12:04:31 -0400 Received: from mx2.redhat.com ([66.187.237.31]:50201) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1ME3oL-0007la-OV for qemu-devel@nongnu.org; Tue, 09 Jun 2009 12:04:30 -0400 From: Glauber Costa Date: Tue, 9 Jun 2009 12:04:26 -0400 Message-Id: <1244563466-32598-1-git-send-email-glommer@redhat.com> Subject: [Qemu-devel] [PATCH] create kvm-shared-all.c and kvm-shared.h List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: jan.kiszka@siemens.com, aliguori@us.ibm.com Following a suggestion given by Jan, the idea here is to move shared pieces between qemu and qemu-kvm.git into a common file, so we can do sharing while avoid clashes. In the future, this files should disappear. Signed-off-by: Glauber Costa --- Makefile.target | 3 +- kvm-all.c | 73 ------------------------------------------------------ kvm-shared-all.c | 58 ++++++++++++++++++++++++++++++++++++++++++ kvm-shared.h | 38 ++++++++++++++++++++++++++++ kvm.h | 10 +------ 5 files changed, 99 insertions(+), 83 deletions(-) create mode 100644 kvm-shared-all.c create mode 100644 kvm-shared.h diff --git a/Makefile.target b/Makefile.target index 27de4b9..d78db27 100644 --- a/Makefile.target +++ b/Makefile.target @@ -126,6 +126,7 @@ endif kvm.o: CFLAGS+=$(KVM_CFLAGS) kvm-all.o: CFLAGS+=$(KVM_CFLAGS) +kvm-shared-all.o: CFLAGS+=$(KVM_CFLAGS) all: $(PROGS) # Dummy command so that make thinks it has done something @@ -499,7 +500,7 @@ OBJS=vl.o osdep.o monitor.o pci.o loader.o isa_mmio.o machine.o \ # need to fix this properly OBJS+=virtio-blk.o virtio-balloon.o virtio-net.o virtio-console.o ifdef CONFIG_KVM -OBJS+=kvm.o kvm-all.o +OBJS+=kvm.o kvm-all.o kvm-shared-all.o endif LIBS+=-lz diff --git a/kvm-all.c b/kvm-all.c index b24d876..258d41a 100644 --- a/kvm-all.c +++ b/kvm-all.c @@ -39,32 +39,10 @@ do { } while (0) #endif -typedef struct KVMSlot -{ - target_phys_addr_t start_addr; - ram_addr_t memory_size; - ram_addr_t phys_offset; - int slot; - int flags; -} KVMSlot; - typedef struct kvm_dirty_log KVMDirtyLog; int kvm_allowed = 0; -struct KVMState -{ - KVMSlot slots[32]; - int fd; - int vmfd; - int coalesced_mmio; - int broken_set_mem_region; - int migration_log; -#ifdef KVM_CAP_SET_GUEST_DEBUG - struct kvm_sw_breakpoint_head kvm_sw_breakpoints; -#endif -}; - static KVMState *kvm_state; static KVMSlot *kvm_alloc_slot(KVMState *s) @@ -803,57 +781,6 @@ void kvm_set_phys_mem(target_phys_addr_t start_addr, } } -int kvm_ioctl(KVMState *s, int type, ...) -{ - int ret; - void *arg; - va_list ap; - - va_start(ap, type); - arg = va_arg(ap, void *); - va_end(ap); - - ret = ioctl(s->fd, type, arg); - if (ret == -1) - ret = -errno; - - return ret; -} - -int kvm_vm_ioctl(KVMState *s, int type, ...) -{ - int ret; - void *arg; - va_list ap; - - va_start(ap, type); - arg = va_arg(ap, void *); - va_end(ap); - - ret = ioctl(s->vmfd, type, arg); - if (ret == -1) - ret = -errno; - - return ret; -} - -int kvm_vcpu_ioctl(CPUState *env, int type, ...) -{ - int ret; - void *arg; - va_list ap; - - va_start(ap, type); - arg = va_arg(ap, void *); - va_end(ap); - - ret = ioctl(env->kvm_fd, type, arg); - if (ret == -1) - ret = -errno; - - return ret; -} - int kvm_has_sync_mmu(void) { #ifdef KVM_CAP_SYNC_MMU diff --git a/kvm-shared-all.c b/kvm-shared-all.c new file mode 100644 index 0000000..ca94155 --- /dev/null +++ b/kvm-shared-all.c @@ -0,0 +1,58 @@ + +#include + +#include "sysemu.h" +#include "kvm.h" + +int kvm_ioctl(KVMState *s, int type, ...) +{ + int ret; + void *arg; + va_list ap; + + va_start(ap, type); + arg = va_arg(ap, void *); + va_end(ap); + + ret = ioctl(s->fd, type, arg); + if (ret == -1) + ret = -errno; + + return ret; +} + +int kvm_vm_ioctl(KVMState *s, int type, ...) +{ + int ret; + void *arg; + va_list ap; + + va_start(ap, type); + arg = va_arg(ap, void *); + va_end(ap); + + ret = ioctl(s->vmfd, type, arg); + if (ret == -1) + ret = -errno; + + return ret; +} + +int kvm_vcpu_ioctl(CPUState *env, int type, ...) +{ + int ret; + void *arg; + va_list ap; + + va_start(ap, type); + arg = va_arg(ap, void *); + va_end(ap); + + ret = ioctl(env->kvm_fd, type, arg); + if (ret == -1) + ret = -errno; + + return ret; +} + + diff --git a/kvm-shared.h b/kvm-shared.h new file mode 100644 index 0000000..c8364ff --- /dev/null +++ b/kvm-shared.h @@ -0,0 +1,38 @@ +/* This file is temporary by nature. It exists to aid merging of + * qemu-kvm.git, and should go away once it is in + */ +#ifndef QEMU_KVM_SHARED_H +#define QEMU_KVM_SHARED_H + +typedef struct KVMSlot +{ + target_phys_addr_t start_addr; + ram_addr_t memory_size; + ram_addr_t phys_offset; + int slot; + int flags; +} KVMSlot; + +struct kvm_sw_breakpoint { + target_ulong pc; + target_ulong saved_insn; + int use_count; + TAILQ_ENTRY(kvm_sw_breakpoint) entry; +}; + +TAILQ_HEAD(kvm_sw_breakpoint_head, kvm_sw_breakpoint); + +struct KVMState +{ + KVMSlot slots[32]; + int fd; + int vmfd; + int coalesced_mmio; + int broken_set_mem_region; + int migration_log; +#ifdef KVM_CAP_SET_GUEST_DEBUG + struct kvm_sw_breakpoint_head kvm_sw_breakpoints; +#endif +}; + +#endif diff --git a/kvm.h b/kvm.h index 560aef3..9cc64ac 100644 --- a/kvm.h +++ b/kvm.h @@ -16,6 +16,7 @@ #include "config.h" #include "sys-queue.h" +#include "kvm-shared.h" #ifdef CONFIG_KVM extern int kvm_allowed; @@ -94,15 +95,6 @@ int kvm_arch_init_vcpu(CPUState *env); struct kvm_guest_debug; struct kvm_debug_exit_arch; -struct kvm_sw_breakpoint { - target_ulong pc; - target_ulong saved_insn; - int use_count; - TAILQ_ENTRY(kvm_sw_breakpoint) entry; -}; - -TAILQ_HEAD(kvm_sw_breakpoint_head, kvm_sw_breakpoint); - int kvm_arch_debug(struct kvm_debug_exit_arch *arch_info); struct kvm_sw_breakpoint *kvm_find_sw_breakpoint(CPUState *env, -- 1.5.6.6