[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-devel] [RFC PATCH 1/5] libxc: Load BIOS and ACPI table into guest memory.



---
 tools/libxc/include/xenguest.h |  4 ++++
 tools/libxc/xc_hvm_build_x86.c | 46 +++++++++++++++++++++++++++++++++---------
 2 files changed, 41 insertions(+), 9 deletions(-)

diff --git a/tools/libxc/include/xenguest.h b/tools/libxc/include/xenguest.h
index 1a1a185..42acbfd 100644
--- a/tools/libxc/include/xenguest.h
+++ b/tools/libxc/include/xenguest.h
@@ -229,6 +229,10 @@ struct xc_hvm_build_args {
     uint64_t lowmem_end;
     uint64_t highmem_end;
     uint64_t mmio_start;
+
+    /* BIOS as module */
+    struct xc_hvm_firmware_module bios_module;
+    struct xc_hvm_firmware_module acpi_table_module;
 };
 
 /**
diff --git a/tools/libxc/xc_hvm_build_x86.c b/tools/libxc/xc_hvm_build_x86.c
index ea250dd..a444d83 100644
--- a/tools/libxc/xc_hvm_build_x86.c
+++ b/tools/libxc/xc_hvm_build_x86.c
@@ -53,6 +53,15 @@
 
 #define VGA_HOLE_SIZE (0x20)
 
+static uint64_t module_init(struct xc_hvm_firmware_module *x, uint64_t mstart)
+{
+#define MODULE_ALIGN 1UL << 7
+#define MKALIGN(x, a) (((uint64_t)(x) + (a) - 1) & ~(uint64_t)((a) - 1))
+    if ( x->length != 0 )
+        x->guest_addr_out = mstart;
+    return MKALIGN(x->length, MODULE_ALIGN);
+}
+
 static int modules_init(struct xc_hvm_build_args *args,
                         uint64_t vend, struct elf_binary *elf,
                         uint64_t *mstart_out, uint64_t *mend_out)
@@ -60,27 +69,29 @@ static int modules_init(struct xc_hvm_build_args *args,
 #define MODULE_ALIGN 1UL << 7
 #define MB_ALIGN     1UL << 20
 #define MKALIGN(x, a) (((uint64_t)(x) + (a) - 1) & ~(uint64_t)((a) - 1))
-    uint64_t total_len = 0, offset1 = 0;
+    uint64_t total_len = 0, offset1 = 0, offset0;
 
-    if ( (args->acpi_module.length == 0)&&(args->smbios_module.length == 0) )
-        return 0;
+
+    /* Want to place the modules 1Mb+change behind the loader image. */
+    *mstart_out = MKALIGN(elf->pend, MB_ALIGN) + (MB_ALIGN);
 
     /* Find the total length for the firmware modules with a reasonable large
      * alignment size to align each the modules.
      */
-    total_len = MKALIGN(args->acpi_module.length, MODULE_ALIGN);
+    total_len += module_init(&args->bios_module, *mstart_out + total_len);
+    total_len += module_init(&args->acpi_table_module, *mstart_out + 
total_len);
+    offset0 = total_len;
+    total_len += MKALIGN(args->acpi_module.length, MODULE_ALIGN);
     offset1 = total_len;
     total_len += MKALIGN(args->smbios_module.length, MODULE_ALIGN);
 
-    /* Want to place the modules 1Mb+change behind the loader image. */
-    *mstart_out = MKALIGN(elf->pend, MB_ALIGN) + (MB_ALIGN);
     *mend_out = *mstart_out + total_len;
 
-    if ( *mend_out > vend )    
+    if ( *mend_out > vend )
         return -1;
 
     if ( args->acpi_module.length != 0 )
-        args->acpi_module.guest_addr_out = *mstart_out;
+        args->acpi_module.guest_addr_out = *mstart_out + offset0;
     if ( args->smbios_module.length != 0 )
         args->smbios_module.guest_addr_out = *mstart_out + offset1;
 
@@ -158,6 +169,17 @@ static int loadelfimage(xc_interface *xch, struct 
elf_binary *elf,
     return rc;
 }
 
+static void loadmodule(struct xc_hvm_firmware_module *x,
+                       uint8_t *dest, uint64_t mstart)
+{
+    if ( x->length != 0 )
+    {
+        memcpy(dest + (x->guest_addr_out - mstart),
+               x->data,
+               x->length);
+    }
+}
+
 static int loadmodules(xc_interface *xch,
                        struct xc_hvm_build_args *args,
                        uint64_t mstart, uint64_t mend,
@@ -196,9 +218,11 @@ static int loadmodules(xc_interface *xch,
     memset(dest, 0, pages << PAGE_SHIFT);
 
     /* Load modules into range */    
+    loadmodule(&args->bios_module, dest, mstart);
+    loadmodule(&args->acpi_table_module, dest, mstart);
     if ( args->acpi_module.length != 0 )
     {
-        memcpy(dest,
+        memcpy(dest + (args->acpi_module.guest_addr_out - mstart),
                args->acpi_module.data,
                args->acpi_module.length);
     }
@@ -729,6 +753,10 @@ int xc_hvm_build(xc_interface *xch, uint32_t domid,
             args.acpi_module.guest_addr_out;
         hvm_args->smbios_module.guest_addr_out = 
             args.smbios_module.guest_addr_out;
+        hvm_args->bios_module.guest_addr_out =
+            args.bios_module.guest_addr_out;
+        hvm_args->acpi_table_module.guest_addr_out =
+            args.acpi_table_module.guest_addr_out;
     }
 
     free(image);
-- 
Anthony PERARD


_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxx
http://lists.xen.org/xen-devel


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.