# HG changeset patch
# User Jerone Young <[EMAIL PROTECTED]>
# Date 1194027872 18000
# Node ID 7f802db02478d5d5ec63348e126b54e85681c66f
# Parent  486d6818fcf62f9fda006e9e090bf1eba40e0e14
Modify out arch specific code from kvm_create function

This function removes all x86 specific code and creates
a hook function kv_arch_create to accomidate for this code.

This patch also moves the following funcitons to libkvm-x86.c:
        kvm_set_tss_addr
        kvm_set_init_tss
        kvm_create_default_phys_mem

This patch moves function kvm_create_default_phys_mem to libkvm-x86.
This function is arch specific to x86 and also today no one allocates
guest memory in the kernel. To remove confusion the function has
been renameed kvm_x86_create_default_phys_mem

Signed-off-by: Jerone Young <[EMAIL PROTECTED]>

diff --git a/libkvm/kvm-x86.h b/libkvm/kvm-x86.h
--- a/libkvm/kvm-x86.h
+++ b/libkvm/kvm-x86.h
@@ -28,4 +28,9 @@ int kvm_alloc_userspace_memory(kvm_conte
 int kvm_alloc_userspace_memory(kvm_context_t kvm, unsigned long memory,
                                                                void **vm_mem);
 
+int kvm_set_tss_addr(kvm_context_t kvm, unsigned long addr);
+
+int kvm_arch_create(kvm_context_t kvm, unsigned long phys_mem_bytes,
+                       void **vm_mem);
+
 #endif
diff --git a/libkvm/libkvm-x86.c b/libkvm/libkvm-x86.c
--- a/libkvm/libkvm-x86.c
+++ b/libkvm/libkvm-x86.c
@@ -7,6 +7,10 @@
 #include <stropts.h>
 #include <sys/mman.h>
 #include <stdio.h>
+#include <errno.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
 
 int kvm_alloc_kernel_memory(kvm_context_t kvm, unsigned long memory,
                                                                void **vm_mem)
@@ -186,3 +190,87 @@ int kvm_alloc_userspace_memory(kvm_conte
 
 #endif
 
+int kvm_set_tss_addr(kvm_context_t kvm, unsigned long addr)
+{
+#ifdef KVM_CAP_SET_TSS_ADDR
+       int r;
+
+       r = ioctl(kvm->fd, KVM_CHECK_EXTENSION, KVM_CAP_SET_TSS_ADDR);
+       if (r > 0) {
+               r = ioctl(kvm->vm_fd, KVM_SET_TSS_ADDR, addr);
+               if (r == -1) {
+                       fprintf(stderr, "kvm_set_tss_addr: %m\n");
+                       return -errno;
+               }
+               return 0;
+       }
+#endif
+       return -ENOSYS;
+}
+
+static int kvm_init_tss(kvm_context_t kvm)
+{
+#ifdef KVM_CAP_SET_TSS_ADDR
+       int r;
+
+       r = ioctl(kvm->fd, KVM_CHECK_EXTENSION, KVM_CAP_SET_TSS_ADDR);
+       if (r > 0) {
+               /*
+                * this address is 3 pages before the bios, and the bios should 
present
+                * as unavaible memory
+                */
+               r = kvm_set_tss_addr(kvm, 0xfffbd000);
+               if (r < 0) {
+                       printf("kvm_init_tss: unable to set tss addr\n");
+                       return r;
+               }
+
+       }
+#endif
+       return 0;
+}
+
+static int kvm_x86_create_default_phys_mem(kvm_context_t kvm,
+                                      unsigned long phys_mem_bytes,
+                                      void **vm_mem)
+{
+       unsigned long memory = (phys_mem_bytes + PAGE_SIZE - 1) & PAGE_MASK;
+       int zfd;
+       int r;
+
+#ifdef KVM_CAP_USER_MEMORY
+       r = ioctl(kvm->fd, KVM_CHECK_EXTENSION, KVM_CAP_USER_MEMORY);
+       if (r > 0)
+               r = kvm_alloc_userspace_memory(kvm, memory, vm_mem);
+       else
+#endif
+               r = kvm_alloc_kernel_memory(kvm, memory, vm_mem);
+       if (r < 0)
+               return r;
+
+        zfd = open("/dev/zero", O_RDONLY);
+        mmap(*vm_mem + 0xa8000, 0x8000, PROT_READ|PROT_WRITE,
+             MAP_PRIVATE|MAP_FIXED, zfd, 0);
+        close(zfd);
+
+       kvm->physical_memory = *vm_mem;
+       return 0;
+}
+
+
+int kvm_arch_create(kvm_context_t kvm, unsigned long phys_mem_bytes,
+                       void **vm_mem)
+{
+       int r = 0;
+
+       r = kvm_init_tss(kvm);
+       if (r < 0)
+               return r;
+       r = kvm_x86_create_default_phys_mem(kvm, phys_mem_bytes, vm_mem);
+       if (r < 0)
+               return r;
+
+       return 0;
+}
+
+
diff --git a/libkvm/libkvm.c b/libkvm/libkvm.c
--- a/libkvm/libkvm.c
+++ b/libkvm/libkvm.c
@@ -333,72 +333,7 @@ int kvm_create_vm(kvm_context_t kvm)
        return 0;
 }
 
-int kvm_set_tss_addr(kvm_context_t kvm, unsigned long addr)
-{
-#ifdef KVM_CAP_SET_TSS_ADDR
-       int r;
-
-       r = ioctl(kvm->fd, KVM_CHECK_EXTENSION, KVM_CAP_SET_TSS_ADDR);
-       if (r > 0) {
-               r = ioctl(kvm->vm_fd, KVM_SET_TSS_ADDR, addr);
-               if (r == -1) {
-                       fprintf(stderr, "kvm_set_tss_addr: %m\n");
-                       return -errno;
-               }
-               return 0;
-       }
-#endif
-       return -ENOSYS;
-}
-
-static int kvm_init_tss(kvm_context_t kvm)
-{
-#ifdef KVM_CAP_SET_TSS_ADDR
-       int r;
-
-       r = ioctl(kvm->fd, KVM_CHECK_EXTENSION, KVM_CAP_SET_TSS_ADDR);
-       if (r > 0) {
-               /*
-                * this address is 3 pages before the bios, and the bios should 
present
-                * as unavaible memory
-                */
-               r = kvm_set_tss_addr(kvm, 0xfffbd000);
-               if (r < 0) {
-                       printf("kvm_init_tss: unable to set tss addr\n");
-                       return r;
-               }
-
-       }
-#endif
-       return 0;
-}
-
-static int kvm_create_default_phys_mem(kvm_context_t kvm,
-                                      unsigned long phys_mem_bytes,
-                                      void **vm_mem)
-{
-       unsigned long memory = (phys_mem_bytes + PAGE_SIZE - 1) & PAGE_MASK;
-       int zfd;
-       int r;
-
-#ifdef KVM_CAP_USER_MEMORY
-       r = ioctl(kvm->fd, KVM_CHECK_EXTENSION, KVM_CAP_USER_MEMORY);
-       if (r > 0)
-               r = kvm_alloc_userspace_memory(kvm, memory, vm_mem);
-       else
-#endif
-               r = kvm_alloc_kernel_memory(kvm, memory, vm_mem);
-       if (r < 0)
-               return r;
-
-        zfd = open("/dev/zero", O_RDONLY);
-        mmap(*vm_mem + 0xa8000, 0x8000, PROT_READ|PROT_WRITE,
-             MAP_PRIVATE|MAP_FIXED, zfd, 0);
-        close(zfd);
-
-       kvm->physical_memory = *vm_mem;
-       return 0;
-}
+
 
 void kvm_create_irqchip(kvm_context_t kvm)
 {
@@ -426,13 +361,10 @@ int kvm_create(kvm_context_t kvm, unsign
        r = kvm_create_vm(kvm);
        if (r < 0)
                return r;
-       r = kvm_init_tss(kvm);
+       r = kvm_arch_create(kvm, phys_mem_bytes, vm_mem);
        if (r < 0)
                return r;
        init_slots();
-       r = kvm_create_default_phys_mem(kvm, phys_mem_bytes, vm_mem);
-       if (r < 0)
-               return r;
        kvm_create_irqchip(kvm);
        r = kvm_create_vcpu(kvm, 0);
        if (r < 0)
diff --git a/libkvm/libkvm.h b/libkvm/libkvm.h
--- a/libkvm/libkvm.h
+++ b/libkvm/libkvm.h
@@ -412,7 +412,6 @@ int kvm_dump_vcpu(kvm_context_t kvm, int
  */
 void kvm_show_regs(kvm_context_t kvm, int vcpu);
 
-int kvm_set_tss_addr(kvm_context_t kvm, unsigned long addr);
 
 void *kvm_create_phys_mem(kvm_context_t, unsigned long phys_start, 
                          unsigned long len, int log, int writable);

-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________
kvm-devel mailing list
kvm-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/kvm-devel

Reply via email to