]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
kvm tools: Separate BIOS specifics into own file
authorCyrill Gorcunov <gorcunov@gmail.com>
Tue, 5 Apr 2011 17:44:57 +0000 (20:44 +0300)
committerPekka Enberg <penberg@kernel.org>
Tue, 5 Apr 2011 17:44:57 +0000 (20:44 +0300)
Instead of calling various BIOS routines from kvm.c better to have all BIOS
specifics sit in bios.c.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
tools/kvm/bios.c
tools/kvm/include/kvm/boot-protocol.h [new file with mode: 0644]
tools/kvm/include/kvm/e820.h
tools/kvm/include/kvm/kvm.h
tools/kvm/include/kvm/util.h
tools/kvm/kvm.c
tools/kvm/main.c

index 4081769059d53a1a338b0352c04ad4254a7736fe..2199c0c2e30f11b6619f4c49414b2ef5c4e50391 100644 (file)
@@ -1,4 +1,6 @@
 #include "kvm/kvm.h"
+#include "kvm/boot-protocol.h"
+#include "kvm/e820.h"
 #include "kvm/interrupt.h"
 #include "kvm/util.h"
 
@@ -46,6 +48,49 @@ static void setup_irq_handler(struct kvm *kvm, struct irq_handler *handler)
        interrupt_table__set(&kvm->interrupt_table, &intr_desc, handler->irq);
 }
 
+/**
+ * e820_setup - setup some simple E820 memory map
+ * @kvm - guest system descriptor
+ */
+static void e820_setup(struct kvm *kvm)
+{
+       struct e820_entry *mem_map;
+       unsigned char *size;
+       unsigned int i = 0;
+
+       size            = guest_flat_to_host(kvm, E820_MAP_SIZE);
+       mem_map         = guest_flat_to_host(kvm, E820_MAP_START);
+
+       *size           = E820_MEM_AREAS;
+
+       mem_map[i++]    = (struct e820_entry) {
+               .addr           = REAL_MODE_IVT_BEGIN,
+               .size           = EBDA_START - REAL_MODE_IVT_BEGIN,
+               .type           = E820_MEM_USABLE,
+       };
+       mem_map[i++]    = (struct e820_entry) {
+               .addr           = EBDA_START,
+               .size           = VGA_RAM_BEGIN - EBDA_START,
+               .type           = E820_MEM_RESERVED,
+       };
+       mem_map[i++]    = (struct e820_entry) {
+               .addr           = MB_BIOS_BEGIN,
+               .size           = MB_BIOS_END - MB_BIOS_BEGIN,
+               .type           = E820_MEM_RESERVED,
+       };
+       mem_map[i++]    = (struct e820_entry) {
+               .addr           = BZ_KERNEL_START,
+               .size           = kvm->ram_size - BZ_KERNEL_START,
+               .type           = E820_MEM_USABLE,
+       };
+
+       BUILD_BUG_ON(i > E820_MEM_AREAS);
+}
+
+/**
+ * setup_bios - inject BIOS into guest memory
+ * @kvm - guest system descriptor
+ */
 void setup_bios(struct kvm *kvm)
 {
        unsigned long address = MB_BIOS_BEGIN;
@@ -73,6 +118,9 @@ void setup_bios(struct kvm *kvm)
        p = guest_flat_to_host(kvm, MB_BIOS_BEGIN);
        memcpy(p, bios_rom, bios_rom_size);
 
+       /* E820 memory map must be present */
+       e820_setup(kvm);
+
        /*
         * Setup a *fake* real mode vector table, it has only
         * one real hadler which does just iret
diff --git a/tools/kvm/include/kvm/boot-protocol.h b/tools/kvm/include/kvm/boot-protocol.h
new file mode 100644 (file)
index 0000000..85b637f
--- /dev/null
@@ -0,0 +1,16 @@
+/*
+ * Linux boot protocol specifics
+ */
+
+#ifndef BOOT_PROTOCOL_H_
+#define BOOT_PROTOCOL_H_
+
+/*
+ * The protected mode kernel part of a modern bzImage is loaded
+ * at 1 MB by default.
+ */
+#define BZ_DEFAULT_SETUP_SECTS         4
+#define BZ_KERNEL_START                        0x100000UL
+#define INITRD_START                   0x1000000UL
+
+#endif /* BOOT_PROTOCOL_H_ */
index 8cde73835fde223fbef4d7d476f5ca1cfb256abe..7482eb5ed54cbbc81c5e33ae22d48675f044617a 100644 (file)
@@ -8,6 +8,8 @@
 #define E820_MEM_USABLE                1
 #define E820_MEM_RESERVED      2
 
+#define E820_MEM_AREAS         4
+
 struct e820_entry {
        uint64_t addr;  /* start of memory segment */
        uint64_t size;  /* size of memory segment */
index 34fcc9618ee209e443f8a5608a52813f660bfaf3..a1af42f00ba6bfd886cb6e762258208ff3f9c612 100644 (file)
@@ -41,7 +41,7 @@ void kvm__enable_singlestep(struct kvm *self);
 bool kvm__load_kernel(struct kvm *kvm, const char *kernel_filename,
                        const char *initrd_filename, const char *kernel_cmdline);
 void kvm__reset_vcpu(struct kvm *self);
-void kvm__setup_mem(struct kvm *self);
+void kvm__setup_bios(struct kvm *self);
 void kvm__start_timer(struct kvm *self);
 void kvm__run(struct kvm *self);
 void kvm__irq_line(struct kvm *self, int irq, int level);
index fbc58f912f21bcbf4dcd6ed3ec91eeeef9c962b6..8c80777f6b25e5bc8891d336566765b31ce1aa9a 100644 (file)
@@ -37,6 +37,8 @@ extern void warning(const char *err, ...) __attribute__((format (printf, 1, 2)))
 extern void info(const char *err, ...) __attribute__((format (printf, 1, 2)));
 extern void set_die_routine(void (*routine)(const char *err, va_list params) NORETURN);
 
+#define BUILD_BUG_ON(condition) ((void)sizeof(char[1 - 2*!!(condition)]))
+
 #define DIE_IF(cnd)                                            \
 do {                                                           \
        if (cnd)                                                \
index be0841b2ef03c8c2c7c93fcdad95b1e0add26816..1740e1ff74b31bf8bfcd9d5d9174d8ef3d5c3536 100644 (file)
@@ -2,7 +2,7 @@
 
 #include "kvm/cpufeature.h"
 #include "kvm/interrupt.h"
-#include "kvm/e820.h"
+#include "kvm/boot-protocol.h"
 #include "kvm/util.h"
 
 #include <linux/kvm.h>
@@ -273,13 +273,6 @@ static int load_flat_binary(struct kvm *self, int fd)
        return true;
 }
 
-/*
- * The protected mode kernel part of a modern bzImage is loaded at 1 MB by
- * default.
- */
-#define BZ_KERNEL_START                        0x100000UL
-#define INITRD_START                   0x1000000UL
-#define BZ_DEFAULT_SETUP_SECTS         4
 static const char *BZIMAGE_MAGIC       = "HdrS";
 
 static bool load_bzimage(struct kvm *self, int fd_kernel,
@@ -571,36 +564,19 @@ void kvm__reset_vcpu(struct kvm *self)
        kvm__setup_msrs(self);
 }
 
-void kvm__setup_mem(struct kvm *self)
+/**
+ * kvm__setup_bios - inject BIOS into guest system memory
+ * @self - guest system descriptor
+ *
+ * This function is a main routine where we poke guest memory
+ * and install BIOS there.
+ */
+void kvm__setup_bios(struct kvm *self)
 {
-       struct e820_entry *mem_map;
-       unsigned char *size;
-
-       size            = guest_flat_to_host(self, E820_MAP_SIZE);
-       mem_map         = guest_flat_to_host(self, E820_MAP_START);
+       /* standart minimal configuration */
+       setup_bios(self);
 
-       *size           = 4;
-
-       mem_map[0]      = (struct e820_entry) {
-               .addr           = REAL_MODE_IVT_BEGIN,
-               .size           = EBDA_START - REAL_MODE_IVT_BEGIN,
-               .type           = E820_MEM_USABLE,
-       };
-       mem_map[1]      = (struct e820_entry) {
-               .addr           = EBDA_START,
-               .size           = VGA_RAM_BEGIN - EBDA_START,
-               .type           = E820_MEM_RESERVED,
-       };
-       mem_map[2]      = (struct e820_entry) {
-               .addr           = MB_BIOS_BEGIN,
-               .size           = MB_BIOS_END - MB_BIOS_BEGIN,
-               .type           = E820_MEM_RESERVED,
-       };
-       mem_map[3]      = (struct e820_entry) {
-               .addr           = BZ_KERNEL_START,
-               .size           = self->ram_size - BZ_KERNEL_START,
-               .type           = E820_MEM_USABLE,
-       };
+       /* FIXME: SMP, ACPI and friends here */
 }
 
 #define TIMER_INTERVAL_NS 1000000      /* 1 msec */
index f755804397edbbfb375e49bfba4701b2ad8406fe..1eeb311337a7db89e13aa1ace6fdb7e17c1faa2f 100644 (file)
@@ -162,9 +162,7 @@ int main(int argc, char *argv[])
 
        kvm__reset_vcpu(kvm);
 
-       setup_bios(kvm);
-
-       kvm__setup_mem(kvm);
+       kvm__setup_bios(kvm);
 
        if (single_step)
                kvm__enable_singlestep(kvm);