Skip to contentSkip to conversation

tools: SeaBIOS integration

PATCH New Ian Campbell 3 participants 22 messages Apr 12, 2011 – Apr 15, 2011

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tools: SeaBIOS integration

Based on the feedback to my previous patchset to multiply-compile hvmloader the following patchset enables a single hvmloader binary to be built with support for SeaBIOS as well as ROMBIOS. SeaBIOS support is optional.

The SeaBIOS integration is only semi-complete and is targetted at developers and very early adopters who don't mind some rough edges. In particular the user must clone, patch as necessary and compile SeaBIOS themselves since this patchset does not cover any of that.

The bulk of the patchset is refactoring hvmloader to allow it to support multiple BIOS configurations. I've aimed to separate things into core hvmloader, helper routines (e.g. "create an e820 table") and BIOS specific glue to bring the two together.

It's rather function-pointer -happy at the moment and since SeaBIOS support is very much a WIP and it is not yet clear which abstractions will actually be necessary. Also many of the callbacks are not implemented for SeaBIOS yet for the same reason. I hope that this work will also simplify any future integration of tioanocore or similar as well.

The series also includes changes to libxl/xl to hide the selection of specific hvmloader and device-model binaries from the user by default.

#1 lore raw

PATCH 1/1 tools: hvmloader: move ROMBIOS configuration into tools/firmware/rombios/

# HG changeset patch
# User Ian Campbell <[email protected]>
# Date 1302597969 -3600
# Node ID d9ee229bada7659019b88ae6b75dd0a8a488714f
# Parent c1d2834bdc3008e0c1f326c85a21d63279932ce5
tools: hvmloader: move ROMBIOS configuration into tools/firmware/rombios/

Currently rombios and hvmloader are rather intertwined. Separate the ROMBIOS configuration options out into a ROMBIOS provided file so that the dependency can become strictly from hvmloader to rombios.

tools/firmware/hvmloader/config.h +2 -33
diff -r c1d2834bdc30 -r d9ee229bada7 tools/firmware/hvmloader/config.h
@@ -23,44 +23,13 @@ extern unsigned long pci_mem_start, pci_
 #define RESERVED_MEMBASE    0xfc000000
 #define RESERVED_MEMSIZE    0x01000000
 
-#define ROMBIOS_SEG            0xF000
 #define ROMBIOS_BEGIN          0x000F0000
 #define ROMBIOS_SIZE           0x00010000
 #define ROMBIOS_MAXOFFSET      0x0000FFFF
 #define ROMBIOS_END            (ROMBIOS_BEGIN + ROMBIOS_SIZE)
 
-/* Memory map. */
-#define SCRATCH_PHYSICAL_ADDRESS      0x00010000
-#define HYPERCALL_PHYSICAL_ADDRESS    0x00080000
+#include "../rombios/config.h"
+
 #define VGABIOS_PHYSICAL_ADDRESS      0x000C0000
-#define OPTIONROM_PHYSICAL_ADDRESS    0x000C8000
-#define OPTIONROM_PHYSICAL_END        0x000EA000
-#define BIOS_INFO_PHYSICAL_ADDRESS    0x000EA000
-#define ACPI_PHYSICAL_ADDRESS         0x000EA020
-#define E820_PHYSICAL_ADDRESS         0x000EA100
-#define SMBIOS_PHYSICAL_ADDRESS       0x000EB000
-#define SMBIOS_MAXIMUM_SIZE           0x00005000
-#define ROMBIOS_PHYSICAL_ADDRESS      0x000F0000
-
-/* Offsets from E820_PHYSICAL_ADDRESS. */
-#define E820_NR_OFFSET                0x0
-#define E820_OFFSET                   0x8
-
-/* Xen Platform Device */
-#define XEN_PF_IOBASE   0x10
-#define PFFLAG_ROM_LOCK 1 /* Sets whether ROM memory area is RW or RO */
-
-/* Located at BIOS_INFO_PHYSICAL_ADDRESS. */
-struct bios_info {
-    uint8_t  com1_present:1;    /* 0[0] - System has COM1? */
-    uint8_t  com2_present:1;    /* 0[1] - System has COM2? */
-    uint8_t  lpt1_present:1;    /* 0[2] - System has LPT1? */
-    uint8_t  hpet_present:1;    /* 0[3] - System has HPET? */
-    uint32_t pci_min, pci_len;  /* 4, 8 - PCI I/O hole boundaries */
-    uint32_t madt_csum_addr;    /* 12   - Address of MADT checksum */
-    uint32_t madt_lapic0_addr;  /* 16   - Address of first MADT LAPIC struct */
-    uint32_t bios32_entry;      /* 20   - Entry point for 32-bit BIOS */
-};
-#define BIOSINFO_OFF_bios32_entry 20
 
 #endif /* __HVMLOADER_CONFIG_H__ */
tools/firmware/rombios/32bit/pmm.c +1 -1
diff -r c1d2834bdc30 -r d9ee229bada7 tools/firmware/rombios/32bit/pmm.c
@@ -65,7 +65,7 @@
 
 #include <stdint.h>
 #include <stddef.h>
-#include <../hvmloader/config.h>
+#include "config.h"
 #include <../hvmloader/e820.h>
 #include "util.h"
 
tools/firmware/rombios/config.h new file +39 -0
diff -r c1d2834bdc30 -r d9ee229bada7 tools/firmware/rombios/config.h
@@ -0,0 +1,39 @@
+#ifndef _ROMBIOS_CONFIG_H
+#define _ROMBIOS_CONFIG_H
+
+/* Memory map. */
+#define SCRATCH_PHYSICAL_ADDRESS      0x00010000
+#define HYPERCALL_PHYSICAL_ADDRESS    0x00080000
+
+#define OPTIONROM_PHYSICAL_ADDRESS    0x000C8000
+#define OPTIONROM_PHYSICAL_END        0x000EA000
+#define BIOS_INFO_PHYSICAL_ADDRESS    0x000EA000
+#define ACPI_PHYSICAL_ADDRESS         0x000EA020
+#define E820_PHYSICAL_ADDRESS         0x000EA100
+#define SMBIOS_PHYSICAL_ADDRESS       0x000EB000
+#define SMBIOS_MAXIMUM_SIZE           0x00005000
+#define ROMBIOS_PHYSICAL_ADDRESS      0x000F0000
+
+/* Offsets from E820_PHYSICAL_ADDRESS. */
+#define E820_NR_OFFSET                0x0
+#define E820_OFFSET                   0x8
+
+/* Xen Platform Device */
+#define XEN_PF_IOBASE   0x10
+#define PFFLAG_ROM_LOCK 1 /* Sets whether ROM memory area is RW or RO */
+
+/* Located at BIOS_INFO_PHYSICAL_ADDRESS. */
+struct bios_info {
+    uint8_t  com1_present:1;    /* 0[0] - System has COM1? */
+    uint8_t  com2_present:1;    /* 0[1] - System has COM2? */
+    uint8_t  lpt1_present:1;    /* 0[2] - System has LPT1? */
+    uint8_t  hpet_present:1;    /* 0[3] - System has HPET? */
+    uint32_t pci_min, pci_len;  /* 4, 8 - PCI I/O hole boundaries */
+    uint32_t madt_csum_addr;    /* 12   - Address of MADT checksum */
+    uint32_t madt_lapic0_addr;  /* 16   - Address of first MADT LAPIC struct */
+    uint32_t bios32_entry;      /* 20   - Entry point for 32-bit BIOS */
+};
+#define BIOSINFO_OFF_bios32_entry 20
+
+#endif
+
tools/firmware/rombios/rombios.c +1 -1
diff -r c1d2834bdc30 -r d9ee229bada7 tools/firmware/rombios/rombios.c
@@ -29,7 +29,7 @@
 #define uint8_t unsigned char
 #define uint16_t unsigned short
 #define uint32_t unsigned long
-#include "../hvmloader/config.h"
+#include "config.h"
 
 #define HVMASSIST
 #undef HVMTEST
#2 lore raw

PATCH 1/1 tools: hvmloader: split e820 support into its own code module

In reply to Ian Campbell

# HG changeset patch
# User Ian Campbell <[email protected]>
# Date 1302598647 -3600
# Node ID 17184d148ff5b507710561cd62cb2987fb531c47
# Parent d9ee229bada7659019b88ae6b75dd0a8a488714f
tools: hvmloader: split e820 support into its own code module.

Pass the table address as a paramter to the build function and cause it to return the number of entries. Pass both base and offset as parameters to the dump function.

This adds a duplicated e820.h header to ROMBIOS. Since the e820 data structure is well defined by existing BIOS implementations I think this is OK and simplifies the cross talk between hvmloader and ROMBIOS.

Reduces the cross talk between ROMBIOS and hvmloader.

tools/firmware/hvmloader/Makefile +1 -0
diff -r d9ee229bada7 -r 17184d148ff5 tools/firmware/hvmloader/Makefile
@@ -30,6 +30,7 @@ CFLAGS += $(CFLAGS_xeninclude)
 
 SRCS  = hvmloader.c mp_tables.c util.c smbios.c 
 SRCS += 32bitbios_support.c smp.c cacheattr.c xenbus.c
+SRCS += e820.c
 ifeq ($(debug),y)
 SRCS += tests.c
 endif
tools/firmware/hvmloader/config.h +3 -0
diff -r d9ee229bada7 -r 17184d148ff5 tools/firmware/hvmloader/config.h
@@ -1,6 +1,8 @@
 #ifndef __HVMLOADER_CONFIG_H__
 #define __HVMLOADER_CONFIG_H__
 
+#include <stdint.h>
+
 #define PAGE_SHIFT 12
 #define PAGE_SIZE  (1ul << PAGE_SHIFT)
 
@@ -28,6 +30,7 @@ extern unsigned long pci_mem_start, pci_
 #define ROMBIOS_MAXOFFSET      0x0000FFFF
 #define ROMBIOS_END            (ROMBIOS_BEGIN + ROMBIOS_SIZE)
 
+#include "e820.h"
 #include "../rombios/config.h"
 
 #define VGABIOS_PHYSICAL_ADDRESS      0x000C0000
tools/firmware/hvmloader/e820.c new file +141 -0

141 lines not on this page · raw message

tools/firmware/hvmloader/e820.h +0 -5
diff -r d9ee229bada7 -r 17184d148ff5 tools/firmware/hvmloader/e820.h
@@ -1,8 +1,6 @@
 #ifndef __HVMLOADER_E820_H__
 #define __HVMLOADER_E820_H__
 
-#include <xen/hvm/e820.h>
-
 /*
  * PC BIOS standard E820 types and structure.
  */
@@ -17,7 +15,4 @@ struct e820entry {
     uint32_t type;
 } __attribute__((packed));
 
-#define E820_NR ((uint16_t *)(E820_PHYSICAL_ADDRESS + E820_NR_OFFSET))
-#define E820    ((struct e820entry *)(E820_PHYSICAL_ADDRESS + E820_OFFSET))
-
 #endif /* __HVMLOADER_E820_H__ */
tools/firmware/hvmloader/hvmloader.c +2 -122

142 lines not on this page · raw message

tools/firmware/hvmloader/smbios.c +0 -1
diff -r d9ee229bada7 -r 17184d148ff5 tools/firmware/hvmloader/smbios.c
@@ -26,7 +26,6 @@
 #include "smbios_types.h"
 #include "util.h"
 #include "hypercall.h"
-#include "e820.h"
 
 static int
 write_smbios_tables(void *start,
tools/firmware/hvmloader/util.c +0 -1
diff -r d9ee229bada7 -r 17184d148ff5 tools/firmware/hvmloader/util.c
@@ -20,7 +20,6 @@
 
 #include "util.h"
 #include "config.h"
-#include "e820.h"
 #include "hypercall.h"
 #include <stdint.h>
 #include <xen/xen.h>
tools/firmware/hvmloader/util.h +4 -0
diff -r d9ee229bada7 -r 17184d148ff5 tools/firmware/hvmloader/util.h
@@ -189,6 +189,10 @@ void create_mp_tables(void);
 int hvm_write_smbios_tables(void);
 void smp_initialise(void);
 
+#include "e820.h"
+int build_e820_table(struct e820entry *e820);
+void dump_e820_table(struct e820entry *e820, unsigned int nr);
+
 #ifndef NDEBUG
 void perform_tests(void);
 #else
tools/firmware/rombios/32bit/pmm.c +1 -1
diff -r d9ee229bada7 -r 17184d148ff5 tools/firmware/rombios/32bit/pmm.c
@@ -66,7 +66,7 @@
 #include <stdint.h>
 #include <stddef.h>
 #include "config.h"
-#include <../hvmloader/e820.h>
+#include "e820.h"
 #include "util.h"
 
 #define DEBUG_PMM 0
tools/firmware/rombios/config.h +3 -0
diff -r d9ee229bada7 -r 17184d148ff5 tools/firmware/rombios/config.h
@@ -18,6 +18,9 @@
 #define E820_NR_OFFSET                0x0
 #define E820_OFFSET                   0x8
 
+#define E820_NR ((uint16_t *)(E820_PHYSICAL_ADDRESS + E820_NR_OFFSET))
+#define E820    ((struct e820entry *)(E820_PHYSICAL_ADDRESS + E820_OFFSET))
+
 /* Xen Platform Device */
 #define XEN_PF_IOBASE   0x10
 #define PFFLAG_ROM_LOCK 1 /* Sets whether ROM memory area is RW or RO */
tools/firmware/rombios/e820.h new file +18 -0
diff -r d9ee229bada7 -r 17184d148ff5 tools/firmware/rombios/e820.h
@@ -0,0 +1,18 @@
+#ifndef __ROMBIOS_E820_H__
+#define __ROMBIOS_E820_H__
+
+/*
+ * PC BIOS standard E820 types and structure.
+ */
+#define E820_RAM          1
+#define E820_RESERVED     2
+#define E820_ACPI         3
+#define E820_NVS          4
+
+struct e820entry {
+    uint64_t addr;
+    uint64_t size;
+    uint32_t type;
+} __attribute__((packed));
+
+#endif /* __ROMBIOS_E820_H__ */
#3 lore raw

PATCH 1/1 tools: hvmloader: pass ACPI_PHYSICAL_ADDRESS as a runtime parameter

In reply to Ian Campbell

# HG changeset patch
# User Ian Campbell <[email protected]>
# Date 1302598830 -3600
# Node ID b29f772657190d609c4f5df250f1ec1c9e87a972
# Parent 17184d148ff5b507710561cd62cb2987fb531c47
tools: hvmloader: pass ACPI_PHYSICAL_ADDRESS as a runtime parameter.

Instead of hardcoding in a header.

Reduces the cross talk between ROMBIOS and hvmloader.

tools/firmware/hvmloader/acpi/acpi2_0.h +1 -1
diff -r 17184d148ff5 -r b29f77265719 tools/firmware/hvmloader/acpi/acpi2_0.h
@@ -382,7 +382,7 @@ struct acpi_20_madt_intsrcovr {
 
 #pragma pack ()
 
-void acpi_build_tables(void);
+void acpi_build_tables(unsigned int physical);
 extern uint32_t madt_csum_addr, madt_lapic0_addr;
 
 #endif /* _ACPI_2_0_H_ */
tools/firmware/hvmloader/acpi/build.c +10 -9
diff -r 17184d148ff5 -r b29f77265719 tools/firmware/hvmloader/acpi/build.c
@@ -242,7 +242,9 @@ static int construct_secondary_tables(ui
     return align16(offset);
 }
 
-static void __acpi_build_tables(uint8_t *buf, int *low_sz, int *high_sz)
+static void __acpi_build_tables(unsigned int physical,
+                                uint8_t *buf,
+                                int *low_sz, int *high_sz)
 {
     struct acpi_20_rsdp *rsdp;
     struct acpi_20_rsdt *rsdt;
@@ -335,11 +337,11 @@ static void __acpi_build_tables(uint8_t 
     /*
      * Fill in low-memory data structures: bios_info_table and RSDP.
      */
-
-    buf = (uint8_t *)ACPI_PHYSICAL_ADDRESS;
+    buf = (uint8_t *)physical;
     offset = 0;
 
     rsdp = (struct acpi_20_rsdp *)&buf[offset];
+
     memcpy(rsdp, &Rsdp, sizeof(struct acpi_20_rsdp));
     offset += align16(sizeof(struct acpi_20_rsdp));
     rsdp->rsdt_address = (unsigned long)rsdt;
@@ -354,24 +356,23 @@ static void __acpi_build_tables(uint8_t 
     *low_sz = offset;
 }
 
-void acpi_build_tables(void)
+void acpi_build_tables(unsigned int physical)
 {
     int high_sz, low_sz;
     uint8_t *buf;
 
     /* Find out size of high-memory ACPI data area. */
     buf = (uint8_t *)&_end;
-    __acpi_build_tables(buf, &low_sz, &high_sz);
+    __acpi_build_tables(physical, buf, &low_sz, &high_sz);
     memset(buf, 0, high_sz);
 
     /* Allocate data area and set up ACPI tables there. */
     buf = mem_alloc(high_sz, 0);
-    __acpi_build_tables(buf, &low_sz, &high_sz);
+    __acpi_build_tables(physical, buf, &low_sz, &high_sz);
 
-    printf(" - Lo data: %08lx-%08lx\n"
+    printf(" - Lo data: %08x-%08x\n"
            " - Hi data: %08lx-%08lx\n",
-           (unsigned long)ACPI_PHYSICAL_ADDRESS,
-           (unsigned long)ACPI_PHYSICAL_ADDRESS + low_sz - 1,
+           physical, physical + low_sz - 1,
            (unsigned long)buf, (unsigned long)buf + high_sz - 1);
 }
 
tools/firmware/hvmloader/hvmloader.c +1 -1
diff -r 17184d148ff5 -r b29f77265719 tools/firmware/hvmloader/hvmloader.c
@@ -652,7 +652,7 @@ int main(void)
         };
 
         printf("Loading ACPI ...\n");
-        acpi_build_tables();
+        acpi_build_tables(ACPI_PHYSICAL_ADDRESS);
         hypercall_hvm_op(HVMOP_set_param, &p);
     }
#4 lore raw

PATCH 1/1 tools: hvmloader: pass SMBIOS location as a runtime parameter

In reply to Ian Campbell

# HG changeset patch
# User Ian Campbell <[email protected]>
# Date 1302599695 -3600
# Node ID 73653e949dbef093ddd72fa527e00aa3fea854c4
# Parent b29f772657190d609c4f5df250f1ec1c9e87a972
tools: hvmloader: pass SMBIOS location as a runtime parameter.

Instead of hardcoding in a header.

Reduces the cross talk between ROMBIOS and hvmloader.

tools/firmware/hvmloader/hvmloader.c +3 -1
diff -r b29f77265719 -r 73653e949dbe tools/firmware/hvmloader/hvmloader.c
@@ -599,7 +599,9 @@ int main(void)
     perform_tests();
 
     printf("Writing SMBIOS tables ...\n");
-    smbios_sz = hvm_write_smbios_tables();
+    smbios_sz = hvm_write_smbios_tables(SCRATCH_PHYSICAL_ADDRESS,
+                                        SMBIOS_PHYSICAL_ADDRESS,
+                                        SMBIOS_PHYSICAL_END);
 
     printf("Loading ROMBIOS ...\n");
     rombios_sz = sizeof(rombios);
tools/firmware/hvmloader/smbios.c +7 -8
diff -r b29f77265719 -r 73653e949dbe tools/firmware/hvmloader/smbios.c
@@ -28,7 +28,7 @@
 #include "hypercall.h"
 
 static int
-write_smbios_tables(void *start,
+write_smbios_tables(void *start, unsigned long phys,
                     uint32_t vcpus, uint64_t memsize,
                     uint8_t uuid[16], char *xen_version,
                     uint32_t xen_major_version, uint32_t xen_minor_version);
@@ -85,7 +85,7 @@ get_cpu_manufacturer(char *buf, int len)
 }
 
 static int
-write_smbios_tables(void *start,
+write_smbios_tables(void *start, unsigned long phys,
                     uint32_t vcpus, uint64_t memsize,
                     uint8_t uuid[16], char *xen_version,
                     uint32_t xen_major_version, uint32_t xen_minor_version)
@@ -136,7 +136,7 @@ write_smbios_tables(void *start,
     smbios_entry_point_init(
         start, max_struct_size,
         (p - (char *)start) - sizeof(struct smbios_entry_point),
-        SMBIOS_PHYSICAL_ADDRESS + sizeof(struct smbios_entry_point),
+        phys + sizeof(struct smbios_entry_point),
         nr_structs);
 
     return ((char *)p - (char *)start);
@@ -162,7 +162,7 @@ get_memsize(void)
 }
 
 int
-hvm_write_smbios_tables(void)
+hvm_write_smbios_tables(unsigned long scratch, unsigned long smbios_start, unsigned long smbios_end)
 {
     xen_domain_handle_t uuid;
     uint16_t xen_major_version, xen_minor_version;
@@ -222,15 +222,14 @@ hvm_write_smbios_tables(void)
     xen_version_str[sizeof(xen_version_str)-1] = '\0';
 
     /* SCRATCH_PHYSICAL_ADDRESS is a safe large memory area for scratch. */
-    len = write_smbios_tables((void *)SCRATCH_PHYSICAL_ADDRESS,
+    len = write_smbios_tables((void *)scratch, smbios_start,
                               hvm_info->nr_vcpus, get_memsize(),
                               uuid, xen_version_str,
                               xen_major_version, xen_minor_version);
-    if ( len > SMBIOS_MAXIMUM_SIZE )
+    if ( smbios_start + len > smbios_end )
         goto error_out;
     /* Okay, not too large: copy out of scratch to final location. */
-    memcpy((void *)SMBIOS_PHYSICAL_ADDRESS,
-           (void *)SCRATCH_PHYSICAL_ADDRESS, len);
+    memcpy((void *)smbios_start, (void *)scratch, len);
 
     return len;
 
tools/firmware/hvmloader/util.h +3 -1
diff -r b29f77265719 -r 73653e949dbe tools/firmware/hvmloader/util.h
@@ -186,7 +186,9 @@ uint32_t highbios_setup(void);
 /* Miscellaneous. */
 void cacheattr_init(void);
 void create_mp_tables(void);
-int hvm_write_smbios_tables(void);
+int hvm_write_smbios_tables(unsigned long scratch,
+			    unsigned long smbios_start,
+			    unsigned long smbios_end);
 void smp_initialise(void);
 
 #include "e820.h"
tools/firmware/rombios/config.h +2 -1
diff -r b29f77265719 -r 73653e949dbe tools/firmware/rombios/config.h
@@ -11,7 +11,8 @@
 #define ACPI_PHYSICAL_ADDRESS         0x000EA020
 #define E820_PHYSICAL_ADDRESS         0x000EA100
 #define SMBIOS_PHYSICAL_ADDRESS       0x000EB000
-#define SMBIOS_MAXIMUM_SIZE           0x00005000
+#define SMBIOS_PHYSICAL_END           0x000F0000
+
 #define ROMBIOS_PHYSICAL_ADDRESS      0x000F0000
 
 /* Offsets from E820_PHYSICAL_ADDRESS. */
#5 lore raw

PATCH 1/1 tools: hvmloader: pass option ROM end address around as a parameter

In reply to Ian Campbell

# HG changeset patch
# User Ian Campbell <[email protected]>
# Date 1302599957 -3600
# Node ID f3596ba54b29dec182f995e052f31ada0efd5f83
# Parent 73653e949dbef093ddd72fa527e00aa3fea854c4
tools: hvmloader: pass option ROM end address around as a parameter.

Reduces the cross talk between ROMBIOS and hvmloader.

tools/firmware/hvmloader/hvmloader.c +13 -6
diff -r 73653e949dbe -r f3596ba54b29 tools/firmware/hvmloader/hvmloader.c
@@ -378,10 +378,11 @@ static void pci_setup(void)
  * Scan the list of Option ROMs at @roms for one which supports 
  * PCI (@vendor_id, @device_id) found at slot @devfn. If one is found,
  * copy it to @dest and return its size rounded up to a multiple 2kB. This
- * function will not copy ROMs beyond address OPTIONROM_PHYSICAL_END.
+ * function will not copy ROMs beyond address option_rom_end.
  */
 #define round_option_rom(x) (((x) + 2047) & ~2047)
 static int scan_option_rom(
+    unsigned int option_rom_end,
     uint8_t devfn, uint16_t vendor_id, uint16_t device_id,
     void *roms, uint32_t dest)
 {
@@ -449,7 +450,7 @@ static int scan_option_rom(
         printf(" - Product name: %s\n",
                (char *)rom + pnph->product_name_offset);
 
-    if ( (dest + rom->rom_size * 512 + 1) > OPTIONROM_PHYSICAL_END )
+    if ( (dest + rom->rom_size * 512 + 1) > option_rom_end )
     {
         printf("Option ROM size %x exceeds available space\n",
                rom->rom_size * 512);
@@ -467,7 +468,8 @@ static int scan_option_rom(
  * the corresponding rom data to *copy_rom_dest. Returns the length of the
  * selected rom, or 0 if no NIC found.
  */
-static int scan_etherboot_nic(uint32_t copy_rom_dest)
+static int scan_etherboot_nic(unsigned int option_rom_end,
+                              uint32_t copy_rom_dest)
 {
     uint16_t class, vendor_id, device_id, devfn;
     int rom_size = 0;
@@ -483,6 +485,7 @@ static int scan_etherboot_nic(uint32_t c
              (device_id != 0xffff) &&
              (class == 0x0200) )
             rom_size = scan_option_rom(
+                option_rom_end,
                 devfn, vendor_id, device_id, etherboot, copy_rom_dest);
     }
 
@@ -493,7 +496,8 @@ static int scan_etherboot_nic(uint32_t c
  * Scan the PCI bus for the devices that have an option ROM, and copy
  * the corresponding rom data to rom_phys_addr.
  */
-static int pci_load_option_roms(uint32_t rom_base_addr)
+static int pci_load_option_roms(unsigned int option_rom_end,
+                                uint32_t rom_base_addr)
 {
     uint32_t option_rom_addr, rom_phys_addr = rom_base_addr;
     uint16_t vendor_id, device_id, devfn, class;
@@ -522,6 +526,7 @@ static int pci_load_option_roms(uint32_t
         pci_writel(devfn, PCI_ROM_ADDRESS, option_rom_addr | 0x1);
 
         rom_phys_addr += scan_option_rom(
+            option_rom_end,
             devfn, vendor_id, device_id,
             (void *)(option_rom_addr & ~2047), rom_phys_addr);
 
@@ -640,10 +645,12 @@ int main(void)
     etherboot_phys_addr = VGABIOS_PHYSICAL_ADDRESS + vgabios_sz;
     if ( etherboot_phys_addr < OPTIONROM_PHYSICAL_ADDRESS )
         etherboot_phys_addr = OPTIONROM_PHYSICAL_ADDRESS;
-    etherboot_sz = scan_etherboot_nic(etherboot_phys_addr);
+    etherboot_sz = scan_etherboot_nic(OPTIONROM_PHYSICAL_END,
+                                      etherboot_phys_addr);
 
     option_rom_phys_addr = etherboot_phys_addr + etherboot_sz;
-    option_rom_sz = pci_load_option_roms(option_rom_phys_addr);
+    option_rom_sz = pci_load_option_roms(OPTIONROM_PHYSICAL_END,
+                                         option_rom_phys_addr);
 
     if ( hvm_info->acpi_enabled )
     {
#6 lore raw

PATCH 1/1 tools: hvmloader: split scratch and hypercall addressing from ROMBIOS low heap

In reply to Ian Campbell

# HG changeset patch
# User Ian Campbell <[email protected]>
# Date 1302600167 -3600
# Node ID 170ca1c6603ce0cc1893125103c4666dfa303364
# Parent f3596ba54b29dec182f995e052f31ada0efd5f83
tools: hvmloader: split scratch and hypercall addressing from ROMBIOS low heap.

Although happen to live at the same physical address their lifespans do not overlap. The scratch and hypercall spaces are used only within hvmloader and the same area is reused as a heap within ROMBIOS. But each is free to make its own decisions about where to place things.

tools/firmware/hvmloader/config.h +3 -0
diff -r f3596ba54b29 -r 170ca1c6603c tools/firmware/hvmloader/config.h
@@ -33,6 +33,9 @@ extern unsigned long pci_mem_start, pci_
 #include "e820.h"
 #include "../rombios/config.h"
 
+#define SCRATCH_PHYSICAL_ADDRESS      0x00010000
+#define HYPERCALL_PHYSICAL_ADDRESS    0x00080000
+
 #define VGABIOS_PHYSICAL_ADDRESS      0x000C0000
 
 #endif /* __HVMLOADER_CONFIG_H__ */
tools/firmware/rombios/32bit/pmm.c +4 -3
diff -r f3596ba54b29 -r 170ca1c6603c tools/firmware/rombios/32bit/pmm.c
@@ -147,7 +147,7 @@ typedef struct heap {
  *
  * - conventional memroy (below 1MB)
  *    In HVM, the area is fixed. 0x00010000-0x0007FFFF
- *    (from SCRATCH_PHYSICAL_ADDRESS to HYPERCALL_PHYSICAL_ADDRESS)
+ *    (LOWHEAP_SIZE bytes from LOWHEAP_PHYSICAL_ADDRESS)
  *
  * - extended memory (start at 1MB, below 4GB)
  *    In HVM, the area starts at memory address 0x00100000.
@@ -283,8 +283,9 @@ pmm_initalize(void)
     }
 
     /* convectional memory: RAM below 1MB, 0x10000-0x7FFFF */
-    pmm_init_heap(&pmm_data.heap, SCRATCH_PHYSICAL_ADDRESS,
-                  HYPERCALL_PHYSICAL_ADDRESS);
+    pmm_init_heap(&pmm_data.heap,
+		  LOWHEAP_PHYSICAL_ADDRESS,
+		  LOWHEAP_PHYSICAL_ADDRESS+LOWHEAP_SIZE);
 }
 
 static uint32_t
tools/firmware/rombios/config.h +2 -2
diff -r f3596ba54b29 -r 170ca1c6603c tools/firmware/rombios/config.h
@@ -2,8 +2,8 @@
 #define _ROMBIOS_CONFIG_H
 
 /* Memory map. */
-#define SCRATCH_PHYSICAL_ADDRESS      0x00010000
-#define HYPERCALL_PHYSICAL_ADDRESS    0x00080000
+#define LOWHEAP_PHYSICAL_ADDRESS      0x00010000
+#define LOWHEAP_SIZE                  0x00070000
 
 #define OPTIONROM_PHYSICAL_ADDRESS    0x000C8000
 #define OPTIONROM_PHYSICAL_END        0x000EA000
#7 lore raw

PATCH 1/1 tools: hvmloader: refactor Makefile to move ROM filenames into variables

In reply to Ian Campbell

# HG changeset patch
# User Ian Campbell <[email protected]>
# Date 1302600838 -3600
# Node ID 70bf20a0b5462f3a1fa4213592bae076ec1a81ba
# Parent 170ca1c6603ce0cc1893125103c4666dfa303364
tools: hvmloader: refactor Makefile to move ROM filenames into variables.

Add an option to use debug Cirrus video BIOS, simply as a convenience.

tools/firmware/hvmloader/Makefile +22 -6
diff -r 170ca1c6603c -r 70bf20a0b546 tools/firmware/hvmloader/Makefile
@@ -36,6 +36,17 @@ SRCS += tests.c
 endif
 OBJS  = $(patsubst %.c,%.o,$(SRCS))
 
+CIRRUSVGA_DEBUG ?= n
+
+ROMBIOS_ROM   := ../rombios/BIOS-bochs-latest
+
+STDVGA_ROM    := ../vgabios/VGABIOS-lgpl-latest.bin
+ifeq ($(CIRRUSVGA_DEBUG),y)
+CIRRUSVGA_ROM := ../vgabios/VGABIOS-lgpl-latest.cirrus.debug.bin
+else
+CIRRUSVGA_ROM := ../vgabios/VGABIOS-lgpl-latest.cirrus.bin
+endif
+
 .PHONY: all
 all: subdirs-all
 	$(MAKE) hvmloader
@@ -48,12 +59,17 @@ hvmloader: $(OBJS) acpi/acpi.a
 	$(OBJCOPY) hvmloader.tmp hvmloader
 	rm -f hvmloader.tmp
 
-roms.h: ../rombios/BIOS-bochs-latest ../vgabios/VGABIOS-lgpl-latest.bin \
-	../vgabios/VGABIOS-lgpl-latest.cirrus.bin ../etherboot/eb-roms.h
-	sh ./mkhex rombios ../rombios/BIOS-bochs-latest > roms.h
-	sh ./mkhex vgabios_stdvga ../vgabios/VGABIOS-lgpl-latest.bin >> roms.h
-	sh ./mkhex vgabios_cirrusvga \
-		../vgabios/VGABIOS-lgpl-latest.cirrus.bin >> roms.h
+roms.h: $(ROMBIOS_ROM) $(STDVGA_ROM) $(CIRRUSVGA_ROM) ../etherboot/eb-roms.h
+ifneq ($(ROMBIOS_ROM),)
+	sh ./mkhex rombios $(ROMBIOS_ROM) > roms.h
+endif
+ifneq ($(STDVGA_ROM),)
+	sh ./mkhex vgabios_stdvga $(STDVGA_ROM) >> roms.h
+endif
+ifneq ($(CIRRUSVGA_ROM),)
+	sh ./mkhex vgabios_cirrusvga $(CIRRUSVGA_ROM) >> roms.h
+endif
+
 	cat ../etherboot/eb-roms.h >> roms.h
 
 .PHONY: clean
#8 lore raw

PATCH 1/1 tools: hvmloader: remove rombios_sz, just use sizeof(rombios)

In reply to Ian Campbell

# HG changeset patch
# User Ian Campbell <[email protected]>
# Date 1302601381 -3600
# Node ID bb3e40b2c856db6b0f3500625ff45a9d07377d1f # Parent 70bf20a0b5462f3a1fa4213592bae076ec1a81ba
tools: hvmloader: remove rombios_sz, just use sizeof(rombios)

tools/firmware/hvmloader/hvmloader.c +5 -9
diff -r 70bf20a0b546 -r bb3e40b2c856 tools/firmware/hvmloader/hvmloader.c
@@ -585,7 +585,7 @@ static void init_vm86_tss(void)
 int main(void)
 {
     int option_rom_sz = 0, vgabios_sz = 0, etherboot_sz = 0;
-    int rombios_sz, smbios_sz;
+    int smbios_sz;
     uint32_t etherboot_phys_addr, option_rom_phys_addr, bios32_addr;
     struct bios_info *bios_info;
 
@@ -609,10 +609,7 @@ int main(void)
                                         SMBIOS_PHYSICAL_END);
 
     printf("Loading ROMBIOS ...\n");
-    rombios_sz = sizeof(rombios);
-    if ( rombios_sz > 0x10000 )
-        rombios_sz = 0x10000;
-    memcpy((void *)ROMBIOS_PHYSICAL_ADDRESS, rombios, rombios_sz);
+    memcpy((void *)ROMBIOS_PHYSICAL_ADDRESS, rombios, sizeof(rombios));
     bios32_addr = highbios_setup();
 
     if ( (hvm_info->nr_vcpus > 1) || hvm_info->apic_mode )
@@ -686,10 +683,9 @@ int main(void)
         printf(" %05x-%05x: SMBIOS tables\n",
                SMBIOS_PHYSICAL_ADDRESS,
                SMBIOS_PHYSICAL_ADDRESS + smbios_sz - 1);
-    if ( rombios_sz )
-        printf(" %05x-%05x: Main BIOS\n",
-               ROMBIOS_PHYSICAL_ADDRESS,
-               ROMBIOS_PHYSICAL_ADDRESS + rombios_sz - 1);
+    printf(" %05x-%05x: Main BIOS\n",
+           ROMBIOS_PHYSICAL_ADDRESS,
+           ROMBIOS_PHYSICAL_ADDRESS + sizeof(rombios) - 1);
 
     *E820_NR = build_e820_table(E820);
     dump_e820_table(E820, *E820_NR);
#9 lore raw

PATCH 1/1 tools: hvmloader: rename roms.h to roms.inc

In reply to Ian Campbell

# HG changeset patch
# User Ian Campbell <[email protected]> # Date 1302601656 -3600
# Node ID 35d6dd63d96ee37c3fcf7690bac933c44a40b23c # Parent bb3e40b2c856db6b0f3500625ff45a9d07377d1f
tools: hvmloader: rename roms.h to roms.inc

It's not really a header, it's an autogenerated data file.

.hgignore +1 -1
diff -r bb3e40b2c856 -r 35d6dd63d96e .hgignore
@@ -143,7 +143,7 @@
 ^tools/firmware/hvmloader/acpi/dsdt.*\.c$
 ^tools/firmware/hvmloader/acpi/ssdt_.*\.h$
 ^tools/firmware/hvmloader/hvmloader$
-^tools/firmware/hvmloader/roms\.h$
+^tools/firmware/hvmloader/roms\.inc$
 ^tools/firmware/rombios/BIOS-bochs-[^/]*$
 ^tools/firmware/rombios/_rombios[^/]*_\.c$
 ^tools/firmware/rombios/rombios[^/]*\.s$
tools/firmware/hvmloader/Makefile +10 -7
diff -r bb3e40b2c856 -r 35d6dd63d96e tools/firmware/hvmloader/Makefile
@@ -51,7 +51,7 @@ endif
 all: subdirs-all
 	$(MAKE) hvmloader
 
-hvmloader.o: roms.h
+hvmloader.o: roms.inc
 smbios.o: CFLAGS += -D__SMBIOS_DATE__="\"$(shell date +%m/%d/%Y)\""
 
 hvmloader: $(OBJS) acpi/acpi.a
@@ -59,22 +59,25 @@ hvmloader: $(OBJS) acpi/acpi.a
 	$(OBJCOPY) hvmloader.tmp hvmloader
 	rm -f hvmloader.tmp
 
-roms.h: $(ROMBIOS_ROM) $(STDVGA_ROM) $(CIRRUSVGA_ROM) ../etherboot/eb-roms.h
+roms.inc: $(ROMBIOS_ROM) $(STDVGA_ROM) $(CIRRUSVGA_ROM) ../etherboot/eb-roms.h
+	echo "/* Autogenerated file. DO NOT EDIT */" > roms.inc
+
 ifneq ($(ROMBIOS_ROM),)
-	sh ./mkhex rombios $(ROMBIOS_ROM) > roms.h
+	sh ./mkhex rombios $(ROMBIOS_ROM) >> roms.inc
 endif
+
 ifneq ($(STDVGA_ROM),)
-	sh ./mkhex vgabios_stdvga $(STDVGA_ROM) >> roms.h
+	sh ./mkhex vgabios_stdvga $(STDVGA_ROM) >> roms.inc
 endif
 ifneq ($(CIRRUSVGA_ROM),)
-	sh ./mkhex vgabios_cirrusvga $(CIRRUSVGA_ROM) >> roms.h
+	sh ./mkhex vgabios_cirrusvga $(CIRRUSVGA_ROM) >> roms.inc
 endif
 
-	cat ../etherboot/eb-roms.h >> roms.h
+	cat ../etherboot/eb-roms.h >> roms.inc
 
 .PHONY: clean
 clean: subdirs-clean
-	rm -f roms.h acpi.h
+	rm -f roms.inc acpi.h
 	rm -f hvmloader hvmloader.tmp *.o $(DEPS)
 
 -include $(DEPS)
tools/firmware/hvmloader/hvmloader.c +2 -1
diff -r bb3e40b2c856 -r 35d6dd63d96e tools/firmware/hvmloader/hvmloader.c
@@ -20,7 +20,6 @@
  * Place - Suite 330, Boston, MA 02111-1307 USA.
  */
 
-#include "roms.h"
 #include "acpi/acpi2_0.h"
 #include "util.h"
 #include "hypercall.h"
@@ -33,6 +32,8 @@
 #include <xen/hvm/ioreq.h>
 #include <xen/memory.h>
 
+#include "roms.inc"
+
 asm (
     "    .text                       \n"
     "    .globl _start               \n"
#10 lore raw

PATCH 1/1 tools: hvmloader: Define $(OBJS) directly instead of via $(SRCS)

In reply to Ian Campbell

# HG changeset patch
# User Ian Campbell <[email protected]>
# Date 1302601741 -3600
# Node ID a25b909fed618dc7e8b95921a59a0db552d60612
# Parent 35d6dd63d96ee37c3fcf7690bac933c44a40b23c
tools: hvmloader: Define $(OBJS) directly instead of via $(SRCS)

$(SRCS) isn't used for anything else.

tools/firmware/hvmloader/Makefile +4 -5
diff -r 35d6dd63d96e -r a25b909fed61 tools/firmware/hvmloader/Makefile
@@ -28,13 +28,12 @@ LOADADDR = 0x100000
 
 CFLAGS += $(CFLAGS_xeninclude)
 
-SRCS  = hvmloader.c mp_tables.c util.c smbios.c 
-SRCS += 32bitbios_support.c smp.c cacheattr.c xenbus.c
-SRCS += e820.c
+OBJS  = hvmloader.o mp_tables.o util.o smbios.o 
+OBJS += 32bitbios_support.o smp.o cacheattr.o xenbus.o
+OBJS += e820.o
 ifeq ($(debug),y)
-SRCS += tests.c
+OBJS += tests.o
 endif
-OBJS  = $(patsubst %.c,%.o,$(SRCS))
 
 CIRRUSVGA_DEBUG ?= n
#11 lore raw

PATCH 1/1 tools: hvmloader: add bios_config data structure

In reply to Ian Campbell

# HG changeset patch
# User Ian Campbell <[email protected]> # Date 1302601994 -3600
# Node ID 700f2fd3d5fd5733a33aa038d090ffb8a6561294 # Parent a25b909fed618dc7e8b95921a59a0db552d60612
tools: hvmloader: add bios_config data structure

For now abstract away the actual ROM bits themselves and the various load addresses.

Create a rombios.c to contain the ROMBIOS specific parts. ROMBIOS is still statically selected for the time being.

tools/firmware/hvmloader/Makefile +13 -1
diff -r a25b909fed61 -r 700f2fd3d5fd tools/firmware/hvmloader/Makefile
@@ -37,7 +37,11 @@ endif
 
 CIRRUSVGA_DEBUG ?= n
 
-ROMBIOS_ROM   := ../rombios/BIOS-bochs-latest
+ROMBIOS_DIR := ../rombios
+ifneq ($(ROMBIOS_DIR),)
+OBJS += rombios.o
+ROMBIOS_ROM := $(ROMBIOS_DIR)/BIOS-bochs-latest
+endif
 
 STDVGA_ROM    := ../vgabios/VGABIOS-lgpl-latest.bin
 ifeq ($(CIRRUSVGA_DEBUG),y)
@@ -62,17 +66,25 @@ roms.inc: $(ROMBIOS_ROM) $(STDVGA_ROM) $
 	echo "/* Autogenerated file. DO NOT EDIT */" > roms.inc
 
 ifneq ($(ROMBIOS_ROM),)
+	echo "#ifdef ROM_INCLUDE_ROMBIOS" >> roms.inc
 	sh ./mkhex rombios $(ROMBIOS_ROM) >> roms.inc
+	echo "#endif" >> roms.inc
 endif
 
 ifneq ($(STDVGA_ROM),)
+	echo "#ifdef ROM_INCLUDE_VGABIOS" >> roms.inc
 	sh ./mkhex vgabios_stdvga $(STDVGA_ROM) >> roms.inc
+	echo "#endif" >> roms.inc
 endif
 ifneq ($(CIRRUSVGA_ROM),)
+	echo "#ifdef ROM_INCLUDE_VGABIOS" >> roms.inc
 	sh ./mkhex vgabios_cirrusvga $(CIRRUSVGA_ROM) >> roms.inc
+	echo "#endif" >> roms.inc
 endif
 
+	echo "#ifdef ROM_INCLUDE_ETHERBOOT" >> roms.inc
 	cat ../etherboot/eb-roms.h >> roms.inc
+	echo "#endif" >> roms.inc
 
 .PHONY: clean
 clean: subdirs-clean
tools/firmware/hvmloader/config.h +32 -0
diff -r a25b909fed61 -r 700f2fd3d5fd tools/firmware/hvmloader/config.h
@@ -3,6 +3,28 @@
 
 #include <stdint.h>
 
+struct bios_config {
+    const char *name;
+
+    /* BIOS ROM image bits */
+    void *image;
+    unsigned int image_size;
+
+    /* Physical address to load at */
+    unsigned int bios_address;
+
+    /* SMBIOS */
+    unsigned int smbios_start, smbios_end;
+
+    /* Option ROMs */
+    unsigned int optionrom_start, optionrom_end;
+
+    /* ACPI tables */
+    unsigned int acpi_start;
+};
+
+extern struct bios_config rombios_config;
+
 #define PAGE_SHIFT 12
 #define PAGE_SIZE  (1ul << PAGE_SHIFT)
 
@@ -39,3 +61,13 @@ extern unsigned long pci_mem_start, pci_
 #define VGABIOS_PHYSICAL_ADDRESS      0x000C0000
 
 #endif /* __HVMLOADER_CONFIG_H__ */
+
+/*
+ * Local variables:
+ * mode: C
+ * c-set-style: "BSD"
+ * c-basic-offset: 4
+ * tab-width: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
tools/firmware/hvmloader/hvmloader.c +33 -19

109 lines not on this page · raw message

tools/firmware/hvmloader/rombios.c new file +58 -0

58 lines not on this page · raw message

#12 lore raw

PATCH 1/1 tools: hvmloader: Refactor APIC, PCI and SMP setup into struct bios_config

In reply to Ian Campbell

# HG changeset patch
# User Ian Campbell <[email protected]>
# Date 1302602061 -3600
# Node ID f153a0d91b9f7cc9fe9d84bf7d97ac6371793b03
# Parent 700f2fd3d5fd5733a33aa038d090ffb8a6561294
tools: hvmloader: Refactor APIC, PCI and SMP setup into struct bios_config

tools/firmware/hvmloader/config.h +7 -0
diff -r 700f2fd3d5fd -r f153a0d91b9f tools/firmware/hvmloader/config.h
@@ -3,6 +3,9 @@
 
 #include <stdint.h>
 
+enum virtual_vga { VGA_none, VGA_std, VGA_cirrus, VGA_pt } virtual_vga;
+extern enum virtual_vga virtual_vga;
+
 struct bios_config {
     const char *name;
 
@@ -21,6 +24,10 @@ struct bios_config {
 
     /* ACPI tables */
     unsigned int acpi_start;
+
+    void (*apic_setup)(void);
+    void (*pci_setup)(void);
+    void (*smp_setup)(void);
 };
 
 extern struct bios_config rombios_config;
tools/firmware/hvmloader/hvmloader.c +7 -232

268 lines not on this page · raw message

tools/firmware/hvmloader/rombios.c +235 -0

250 lines not on this page · raw message

#13 lore raw

PATCH 1/1 tools: hvmloader: refactor highbios and bios_info setup into struct bios_config

In reply to Ian Campbell

# HG changeset patch
# User Ian Campbell <[email protected]>
# Date 1302602206 -3600
# Node ID 99d1e52175a3d7770ab0cfe286133cf84954cf8d
# Parent f153a0d91b9f7cc9fe9d84bf7d97ac6371793b03
tools: hvmloader: refactor highbios and bios_info setup into struct bios_config

tools/firmware/hvmloader/32bitbios_support.c +1 -1
diff -r f153a0d91b9f -r 99d1e52175a3 tools/firmware/hvmloader/32bitbios_support.c
@@ -144,7 +144,7 @@ static uint32_t relocate_32bitbios(char 
     return (uint32_t)highbiosarea;
 }
 
-uint32_t highbios_setup(void)
+uint32_t rombios_highbios_setup(void)
 {
     return relocate_32bitbios((char *)highbios_array, sizeof(highbios_array));
 }
tools/firmware/hvmloader/config.h +3 -0
diff -r f153a0d91b9f -r 99d1e52175a3 tools/firmware/hvmloader/config.h
@@ -28,6 +28,9 @@ struct bios_config {
     void (*apic_setup)(void);
     void (*pci_setup)(void);
     void (*smp_setup)(void);
+
+    uint32_t (*bios_high_setup)(void);
+    void (*bios_info_setup)(uint32_t);
 };
 
 extern struct bios_config rombios_config;
tools/firmware/hvmloader/hvmloader.c +7 -14
diff -r f153a0d91b9f -r 99d1e52175a3 tools/firmware/hvmloader/hvmloader.c
@@ -364,10 +364,10 @@ static const struct bios_config *detect_
 
 int main(void)
 {
+    uint32_t highbios = 0;
     const struct bios_config *bios;
     int option_rom_sz = 0, vgabios_sz = 0, etherboot_sz = 0, smbios_sz = 0;
-    uint32_t etherboot_phys_addr, option_rom_phys_addr, bios32_addr;
-    struct bios_info *bios_info;
+    uint32_t etherboot_phys_addr, option_rom_phys_addr;
 
     printf("HVM Loader\n");
 
@@ -400,7 +400,9 @@ int main(void)
     printf("Loading %s ...\n", bios->name);
     memcpy((void *)bios->bios_address, bios->image,
            bios->image_size);
-    bios32_addr = highbios_setup();
+
+    if (bios->bios_high_setup)
+        highbios = bios->bios_high_setup();
 
     if ( (hvm_info->nr_vcpus > 1) || hvm_info->apic_mode )
         create_mp_tables();
@@ -480,17 +482,8 @@ int main(void)
     *E820_NR = build_e820_table(E820);
     dump_e820_table(E820, *E820_NR);
 
-    bios_info = (struct bios_info *)BIOS_INFO_PHYSICAL_ADDRESS;
-    memset(bios_info, 0, sizeof(*bios_info));
-    bios_info->com1_present = uart_exists(0x3f8);
-    bios_info->com2_present = uart_exists(0x2f8);
-    bios_info->lpt1_present = lpt_exists(0x378);
-    bios_info->hpet_present = hpet_exists(ACPI_HPET_ADDRESS);
-    bios_info->pci_min = pci_mem_start;
-    bios_info->pci_len = pci_mem_end - pci_mem_start;
-    bios_info->madt_csum_addr = madt_csum_addr;
-    bios_info->madt_lapic0_addr = madt_lapic0_addr;
-    bios_info->bios32_entry = bios32_addr;
+    if (bios->bios_info_setup)
+        bios->bios_info_setup(highbios);
 
     xenbus_shutdown();
 
tools/firmware/hvmloader/rombios.c +21 -0
diff -r f153a0d91b9f -r 99d1e52175a3 tools/firmware/hvmloader/rombios.c
@@ -24,6 +24,7 @@
 
 #include "../rombios/config.h"
 
+#include "acpi/acpi2_0.h"
 #include "apic_regs.h"
 #include "pci_regs.h"
 #include "util.h"
@@ -35,6 +36,23 @@
 #define ROM_INCLUDE_ROMBIOS
 #include "roms.inc"
 
+static void rombios_setup_bios_info(uint32_t bioshigh)
+{
+    struct bios_info *bios_info;
+
+    bios_info = (struct bios_info *)BIOS_INFO_PHYSICAL_ADDRESS;
+    memset(bios_info, 0, sizeof(*bios_info));
+    bios_info->com1_present = uart_exists(0x3f8);
+    bios_info->com2_present = uart_exists(0x2f8);
+    bios_info->lpt1_present = lpt_exists(0x378);
+    bios_info->hpet_present = hpet_exists(ACPI_HPET_ADDRESS);
+    bios_info->pci_min = pci_mem_start;
+    bios_info->pci_len = pci_mem_end - pci_mem_start;
+    bios_info->madt_csum_addr = madt_csum_addr;
+    bios_info->madt_lapic0_addr = madt_lapic0_addr;
+    bios_info->bios32_entry = bioshigh;
+}
+
 static void rombios_apic_setup(void)
 {
     /* Set the IOAPIC ID to the static value used in the MP/ACPI tables. */
@@ -280,6 +298,9 @@ struct bios_config rombios_config =  {
     .apic_setup = rombios_apic_setup,
     .pci_setup = rombios_pci_setup,
     .smp_setup = smp_initialise,
+
+    .bios_high_setup = rombios_highbios_setup,
+    .bios_info_setup = rombios_setup_bios_info,
 };
 
 /*
tools/firmware/hvmloader/util.h +1 -1
diff -r f153a0d91b9f -r 99d1e52175a3 tools/firmware/hvmloader/util.h
@@ -181,7 +181,7 @@ void xenbus_shutdown(void);
 char *xenstore_read(char *path);
 
 /* Prepare the 32bit BIOS */
-uint32_t highbios_setup(void);
+uint32_t rombios_highbios_setup(void);
 
 /* Miscellaneous. */
 void cacheattr_init(void);
#14 lore raw

PATCH 1/1 tools: hvmloader: Refactor VM86 and E820 setup into struct bios_config

In reply to Ian Campbell

# HG changeset patch
# User Ian Campbell <[email protected]>
# Date 1302602711 -3600
# Node ID 31e9da762b1ebd22b5ed68d3a15ea56f4a41d63c
# Parent 99d1e52175a3d7770ab0cfe286133cf84954cf8d
tools: hvmloader: Refactor VM86 and E820 setup into struct bios_config

tools/firmware/hvmloader/config.h +3 -3
diff -r 99d1e52175a3 -r 31e9da762b1e tools/firmware/hvmloader/config.h
@@ -31,6 +31,9 @@ struct bios_config {
 
     uint32_t (*bios_high_setup)(void);
     void (*bios_info_setup)(uint32_t);
+
+    void (*vm86_setup)(void);
+    void (*e820_setup)(void);
 };
 
 extern struct bios_config rombios_config;
@@ -62,9 +65,6 @@ extern unsigned long pci_mem_start, pci_
 #define ROMBIOS_MAXOFFSET      0x0000FFFF
 #define ROMBIOS_END            (ROMBIOS_BEGIN + ROMBIOS_SIZE)
 
-#include "e820.h"
-#include "../rombios/config.h"
-
 #define SCRATCH_PHYSICAL_ADDRESS      0x00010000
 #define HYPERCALL_PHYSICAL_ADDRESS    0x00080000
 
tools/firmware/hvmloader/hvmloader.c +4 -21
diff -r 99d1e52175a3 -r 31e9da762b1e tools/firmware/hvmloader/hvmloader.c
@@ -338,24 +338,6 @@ static void cmos_write_memory_size(void)
     cmos_outb(0x35, (uint8_t)( alt_mem >> 8));
 }
 
-/*
- * Set up an empty TSS area for virtual 8086 mode to use. 
- * The only important thing is that it musn't have any bits set 
- * in the interrupt redirection bitmap, so all zeros will do.
- */
-static void init_vm86_tss(void)
-{
-    void *tss;
-    struct xen_hvm_param p;
-
-    tss = mem_alloc(128, 128);
-    memset(tss, 0, 128);
-    p.domid = DOMID_SELF;
-    p.index = HVM_PARAM_VM86_TSS;
-    p.value = virt_to_phys(tss);
-    hypercall_hvm_op(HVMOP_set_param, &p);
-    printf("vm86 TSS at %08lx\n", virt_to_phys(tss));
-}
 
 static const struct bios_config *detect_bios(void)
 {
@@ -454,7 +436,8 @@ int main(void)
         hypercall_hvm_op(HVMOP_set_param, &p);
     }
 
-    init_vm86_tss();
+    if (bios->vm86_setup)
+        bios->vm86_setup();
 
     cmos_write_memory_size();
 
@@ -479,8 +462,8 @@ int main(void)
            bios->bios_address,
            bios->bios_address + bios->image_size - 1);
 
-    *E820_NR = build_e820_table(E820);
-    dump_e820_table(E820, *E820_NR);
+    if (bios->e820_setup)
+        bios->e820_setup();
 
     if (bios->bios_info_setup)
         bios->bios_info_setup(highbios);
tools/firmware/hvmloader/rombios.c +29 -0
diff -r 99d1e52175a3 -r 31e9da762b1e tools/firmware/hvmloader/rombios.c
@@ -30,12 +30,38 @@
 #include "util.h"
 #include "hypercall.h"
 
+#include <xen/hvm/params.h>
 #include <xen/hvm/ioreq.h>
 #include <xen/memory.h>
 
 #define ROM_INCLUDE_ROMBIOS
 #include "roms.inc"
 
+/*
+ * Set up an empty TSS area for virtual 8086 mode to use. 
+ * The only important thing is that it musn't have any bits set 
+ * in the interrupt redirection bitmap, so all zeros will do.
+ */
+static void rombios_init_vm86_tss(void)
+{
+    void *tss;
+    struct xen_hvm_param p;
+
+    tss = mem_alloc(128, 128);
+    memset(tss, 0, 128);
+    p.domid = DOMID_SELF;
+    p.index = HVM_PARAM_VM86_TSS;
+    p.value = virt_to_phys(tss);
+    hypercall_hvm_op(HVMOP_set_param, &p);
+    printf("vm86 TSS at %08lx\n", virt_to_phys(tss));
+}
+
+static void rombios_setup_e820(void)
+{
+    *E820_NR = build_e820_table(E820);
+    dump_e820_table(E820, *E820_NR);
+}
+
 static void rombios_setup_bios_info(uint32_t bioshigh)
 {
     struct bios_info *bios_info;
@@ -301,6 +327,9 @@ struct bios_config rombios_config =  {
 
     .bios_high_setup = rombios_highbios_setup,
     .bios_info_setup = rombios_setup_bios_info,
+
+    .vm86_setup = rombios_init_vm86_tss,
+    .e820_setup = rombios_setup_e820,
 };
 
 /*
#15 lore raw

PATCH 1/1 tools: hvmloader: Refactor ACPI table setup into struct bios_config

In reply to Ian Campbell

# HG changeset patch
# User Ian Campbell <[email protected]>
# Date 1302603558 -3600
# Node ID 63da98f210b0f708a6bd2f85bc03de8826655784
# Parent 31e9da762b1ebd22b5ed68d3a15ea56f4a41d63c
tools: hvmloader: Refactor ACPI table setup into struct bios_config

tools/firmware/hvmloader/config.h +2 -0
diff -r 31e9da762b1e -r 63da98f210b0 tools/firmware/hvmloader/config.h
@@ -34,6 +34,8 @@ struct bios_config {
 
     void (*vm86_setup)(void);
     void (*e820_setup)(void);
+
+    void (*acpi_build_tables)(unsigned int physical);
 };
 
 extern struct bios_config rombios_config;
tools/firmware/hvmloader/hvmloader.c +4 -3
diff -r 31e9da762b1e -r 63da98f210b0 tools/firmware/hvmloader/hvmloader.c
@@ -20,7 +20,6 @@
  * Place - Suite 330, Boston, MA 02111-1307 USA.
  */
 
-#include "acpi/acpi2_0.h"
 #include "util.h"
 #include "hypercall.h"
 #include "config.h"
@@ -431,8 +430,10 @@ int main(void)
             .value = 1,
         };
 
-        printf("Loading ACPI ...\n");
-        acpi_build_tables(bios->acpi_start);
+        if ( bios->acpi_build_tables ) {
+            printf("Loading ACPI ...\n");
+            bios->acpi_build_tables(bios->acpi_start);
+        }
         hypercall_hvm_op(HVMOP_set_param, &p);
     }
 
tools/firmware/hvmloader/rombios.c +2 -0
diff -r 31e9da762b1e -r 63da98f210b0 tools/firmware/hvmloader/rombios.c
@@ -330,6 +330,8 @@ struct bios_config rombios_config =  {
 
     .vm86_setup = rombios_init_vm86_tss,
     .e820_setup = rombios_setup_e820,
+
+    .acpi_build_tables = acpi_build_tables,
 };
 
 /*
#16 lore raw

PATCH 1/1 tools: hvmloader: Refactor MP table setup into struct bios_config

In reply to Ian Campbell

# HG changeset patch
# User Ian Campbell <[email protected]>
# Date 1302603807 -3600
# Node ID 7bddcc4cfc8789cffe511b0b38645479d8d3490d
# Parent 63da98f210b0f708a6bd2f85bc03de8826655784
tools: hvmloader: Refactor MP table setup into struct bios_config

tools/firmware/hvmloader/config.h +1 -5
diff -r 63da98f210b0 -r 7bddcc4cfc87 tools/firmware/hvmloader/config.h
@@ -36,6 +36,7 @@ struct bios_config {
     void (*e820_setup)(void);
 
     void (*acpi_build_tables)(unsigned int physical);
+    void (*create_mp_tables)(void);
 };
 
 extern struct bios_config rombios_config;
@@ -62,11 +63,6 @@ extern unsigned long pci_mem_start, pci_
 #define RESERVED_MEMBASE    0xfc000000
 #define RESERVED_MEMSIZE    0x01000000
 
-#define ROMBIOS_BEGIN          0x000F0000
-#define ROMBIOS_SIZE           0x00010000
-#define ROMBIOS_MAXOFFSET      0x0000FFFF
-#define ROMBIOS_END            (ROMBIOS_BEGIN + ROMBIOS_SIZE)
-
 #define SCRATCH_PHYSICAL_ADDRESS      0x00010000
 #define HYPERCALL_PHYSICAL_ADDRESS    0x00080000
 
tools/firmware/hvmloader/hvmloader.c +3 -2
diff -r 63da98f210b0 -r 7bddcc4cfc87 tools/firmware/hvmloader/hvmloader.c
@@ -385,8 +385,9 @@ int main(void)
     if (bios->bios_high_setup)
         highbios = bios->bios_high_setup();
 
-    if ( (hvm_info->nr_vcpus > 1) || hvm_info->apic_mode )
-        create_mp_tables();
+    if ( bios->create_mp_tables &&
+         ( (hvm_info->nr_vcpus > 1) || hvm_info->apic_mode ) )
+        bios->create_mp_tables();
 
     switch ( virtual_vga )
     {
tools/firmware/hvmloader/mp_tables.c +2 -48

67 lines not on this page · raw message

tools/firmware/hvmloader/rombios.c +57 -0

75 lines not on this page · raw message

tools/firmware/hvmloader/util.h +1 -1
diff -r 63da98f210b0 -r 7bddcc4cfc87 tools/firmware/hvmloader/util.h
@@ -185,7 +185,7 @@ uint32_t rombios_highbios_setup(void);
 
 /* Miscellaneous. */
 void cacheattr_init(void);
-void create_mp_tables(void);
+void create_mp_tables(void *table);
 int hvm_write_smbios_tables(unsigned long scratch,
 			    unsigned long smbios_start,
 			    unsigned long smbios_end);
#17 lore raw

PATCH 1/1 tools: libxl: hide selection of device-model, hvmloader and BIOS by default

In reply to Ian Campbell

# HG changeset patch
# User Ian Campbell <[email protected]>
# Date 1302607225 -3600
# Node ID 20dcc3b31fd416636a69dc7c528ef486adc9dacc
# Parent 7bddcc4cfc8789cffe511b0b38645479d8d3490d
tools: libxl: hide selection of device-model, hvmloader and BIOS by default.

These should never have been exposed to users as something they are required to think about, unless they want to.

At the libxl API level:
* Move libxl_domain_build_info.kernel into the PV side of the tagged union (using this field to specify both PV kernel and hvmloader is confusing)
* Add hvmloader (a string) to the HVM side of the tagged union.
* Add libxl_device_model_info.device_model_version allowing the user to say which qemu version (e.g. old qemu-xen or qemu upstream) they want for a domain.
* Default both the hvmloader and device_model fields to NULL and DTRT when building a domain with that value in those fields, but still allow libxl users to specify something explicit if they want.
* Note that libxl_device_model_info.device_model, if specified, must now be a complete path.

At the xl level:
* WARN if an HVM guest cfg uses the "kernel" config option, and direct users to the "hvmloader_override" option if they really do not want the default hvmloader.
* WARN if an HVM guest cfg uses the "device_model" config option, and again direct users to the "device_model_override" option if they really do not want the default.
* Support a new "device_model_version" option which sets the new libxl_device_model_info.device_model_version field. This option is mandatory if device_model_override is used

(other toolstacks would do something similar presumably)

The default qemu remains the existing qemu-xen based qemu-dm.

I suspect that the vast majority of users only have these config options because they've copied them from somewhere and they normally have no interest in which specific hvmloader or device model is used. Renaming the fields and warning when they are used makes these decisions internal. This will allow us to make decisions at a platform level regarding the preferred hvmloader, device model, stub domain etc without requiring everyone to change their configuration files.

Adding a device model version to the API is intended to make it easy for users to select what they need without having to know about the paths to specific binaries etc. Most importantly it gets rid of the parsing of the output of qemu -h...

It's not clear where upstream qemu will eventually be installed, I went with /usr/bin/qemu for now.

tools/libxl/libxl.c +3 -1
diff -r 7bddcc4cfc87 -r 20dcc3b31fd4 tools/libxl/libxl.c
@@ -2276,15 +2276,17 @@ out:
 int libxl_domain_need_memory(libxl_ctx *ctx, libxl_domain_build_info *b_info,
         libxl_device_model_info *dm_info, uint32_t *need_memkb)
 {
+    libxl__gc gc = LIBXL_INIT_GC(ctx);
     *need_memkb = b_info->target_memkb;
     if (b_info->hvm) {
         *need_memkb += b_info->shadow_memkb + LIBXL_HVM_EXTRA_MEMORY;
-        if (strstr(dm_info->device_model, "stubdom-dm"))
+        if (strstr(libxl__domain_device_model(&gc, dm_info), "stubdom-dm"))
             *need_memkb += 32 * 1024;
     } else
         *need_memkb += b_info->shadow_memkb + LIBXL_PV_EXTRA_MEMORY;
     if (*need_memkb % (2 * 1024))
         *need_memkb += (2 * 1024) - (*need_memkb % (2 * 1024));
+    libxl__free_all(&gc);
     return 0;
 }
 
tools/libxl/libxl.h +6 -0
diff -r 7bddcc4cfc87 -r 20dcc3b31fd4 tools/libxl/libxl.h
@@ -257,6 +257,12 @@ typedef enum libxl_action_on_shutdown {
     LIBXL_ACTION_COREDUMP_RESTART,
 } libxl_action_on_shutdown;
 
+/*
+ * 1 - Historical qemu-xen device model (qemu-dm)
+ * 2 - Upstream qemu
+ */
+#define LIBXL_DEVICE_MODEL_VERSION_DEFAULT 1
+
 typedef struct {
     libxl_domain_create_info c_info;
     libxl_domain_build_info b_info;
tools/libxl/libxl.idl +6 -4
diff -r 7bddcc4cfc87 -r 20dcc3b31fd4 tools/libxl/libxl.idl
@@ -95,12 +95,12 @@ libxl_domain_build_info = Struct("domain
     ("video_memkb",     uint32),
     ("shadow_memkb",    uint32),
     ("disable_migrate", bool),
-    ("kernel",          libxl_file_reference),
     ("cpuid",           libxl_cpuid_policy_list),
     ("hvm",             integer),
     ("u", KeyedUnion(None, "hvm",
                 [("hvm", "%s", Struct(None,
-                                       [("pae", bool),
+                                       [("hvmloader", string),
+                                        ("pae", bool),
                                         ("apic", bool),
                                         ("acpi", bool),
                                         ("nx", bool),
@@ -112,7 +112,8 @@ libxl_domain_build_info = Struct("domain
                                         ("nested_hvm", bool),
                                         ])),
                  ("pv", "!%s", Struct(None,
-                                       [("slack_memkb", uint32),
+                                       [("kernel", libxl_file_reference),
+                                        ("slack_memkb", uint32),
                                         ("bootloader", string),
                                         ("bootloader_args", string),
                                         ("cmdline", string),
@@ -139,7 +140,8 @@ libxl_device_model_info = Struct("device
     ("domid",            integer),
     ("uuid",             libxl_uuid,  False, "this is use only with stubdom, and must be different from the domain uuid"),
     ("dom_name",         string),
-    ("device_model",     string),
+    ("device_model_version", integer),
+    ("device_model",     string, False, "if you set this you must set device_model_version too"),
     ("saved_state",      string),
     ("type",             libxl_qemu_machine_type),
     ("target_ram",       uint32),
tools/libxl/libxl_bootloader.c +7 -6
diff -r 7bddcc4cfc87 -r 20dcc3b31fd4 tools/libxl/libxl_bootloader.c
@@ -44,8 +44,9 @@ static char **make_bootloader_args(libxl
 
     flexarray_set(args, nr++, (char *)info->u.pv.bootloader);
 
-    if (info->kernel.path)
-        flexarray_set(args, nr++, libxl__sprintf(gc, "--kernel=%s", info->kernel.path));
+    if (info->u.pv.kernel.path)
+        flexarray_set(args, nr++, libxl__sprintf(gc, "--kernel=%s",
+                                                 info->u.pv.kernel.path));
     if (info->u.pv.ramdisk.path)
         flexarray_set(args, nr++, libxl__sprintf(gc, "--ramdisk=%s", info->u.pv.ramdisk.path));
     if (info->u.pv.cmdline && *info->u.pv.cmdline != '\0')
@@ -277,10 +278,10 @@ static void parse_bootloader_result(libx
 {
     while (*o != '\0') {
         if (strncmp("kernel ", o, strlen("kernel ")) == 0) {
-            free(info->kernel.path);
-            info->kernel.path = strdup(o + strlen("kernel "));
-            libxl__file_reference_map(&info->kernel);
-            unlink(info->kernel.path);
+            free(info->u.pv.kernel.path);
+            info->u.pv.kernel.path = strdup(o + strlen("kernel "));
+            libxl__file_reference_map(&info->u.pv.kernel);
+            unlink(info->u.pv.kernel.path);
         } else if (strncmp("ramdisk ", o, strlen("ramdisk ")) == 0) {
             free(info->u.pv.ramdisk.path);
             info->u.pv.ramdisk.path = strdup(o + strlen("ramdisk "));
tools/libxl/libxl_create.c +9 -7
diff -r 7bddcc4cfc87 -r 20dcc3b31fd4 tools/libxl/libxl_create.c
@@ -88,8 +88,8 @@ void libxl_init_build_info(libxl_domain_
     b_info->shadow_memkb = 0;
     if (c_info->hvm) {
         b_info->video_memkb = 8 * 1024;
-        b_info->kernel.path = strdup("hvmloader");
         b_info->hvm = 1;
+        b_info->u.hvm.hvmloader = NULL;
         b_info->u.hvm.pae = 1;
         b_info->u.hvm.apic = 1;
         b_info->u.hvm.acpi = 1;
@@ -112,7 +112,8 @@ void libxl_init_dm_info(libxl_device_mod
     libxl_uuid_generate(&dm_info->uuid);
 
     dm_info->dom_name = strdup(c_info->name);
-    dm_info->device_model = strdup("qemu-dm");
+    dm_info->device_model_version = LIBXL_DEVICE_MODEL_VERSION_DEFAULT;
+    dm_info->device_model = NULL;
     dm_info->target_ram = libxl__sizekb_to_mb(b_info->target_memkb);
     dm_info->videoram = libxl__sizekb_to_mb(b_info->video_memkb);
     dm_info->apic = b_info->u.hvm.apic;
@@ -182,7 +183,7 @@ int libxl__domain_build(libxl__gc *gc, l
         vments[i++] = "image/ostype";
         vments[i++] = "linux";
         vments[i++] = "image/kernel";
-        vments[i++] = (char*) info->kernel.path;
+        vments[i++] = (char*) info->u.pv.kernel.path;
         vments[i++] = "start_time";
         vments[i++] = libxl__sprintf(gc, "%lu.%02d", start_time.tv_sec,(int)start_time.tv_usec/10000);
         if (info->u.pv.ramdisk.path) {
@@ -232,7 +233,7 @@ static int domain_restore(libxl__gc *gc,
         vments[i++] = "image/ostype";
         vments[i++] = "linux";
         vments[i++] = "image/kernel";
-        vments[i++] = (char*) info->kernel.path;
+        vments[i++] = (char*) info->u.pv.kernel.path;
         vments[i++] = "start_time";
         vments[i++] = libxl__sprintf(gc, "%lu.%02d", start_time.tv_sec,(int)start_time.tv_usec/10000);
         if (info->u.pv.ramdisk.path) {
@@ -256,9 +257,10 @@ static int domain_restore(libxl__gc *gc,
     }
 
 out:
-    libxl__file_reference_unmap(&info->kernel);
-    if (!info->hvm)
-	    libxl__file_reference_unmap(&info->u.pv.ramdisk);
+    if (!info->hvm) {
+        libxl__file_reference_unmap(&info->u.pv.kernel);
+        libxl__file_reference_unmap(&info->u.pv.ramdisk);
+    }
 
     esave = errno;
 
tools/libxl/libxl_dm.c +70 -18

169 lines not on this page · raw message

tools/libxl/libxl_dom.c +16 -10
diff -r 7bddcc4cfc87 -r 20dcc3b31fd4 tools/libxl/libxl_dom.c
@@ -160,13 +160,17 @@ int libxl__build_pv(libxl__gc *gc, uint3
         return ERROR_FAIL;
     }
 
-    if (info->kernel.mapped) {
-        if ( (ret = xc_dom_kernel_mem(dom, info->kernel.data, info->kernel.size)) != 0) {
+    if (info->u.pv.kernel.mapped) {
+        ret = xc_dom_kernel_mem(dom,
+                                info->u.pv.kernel.data,
+                                info->u.pv.kernel.size);
+        if ( ret != 0) {
             LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR, "xc_dom_kernel_mem failed");
             goto out;
         }
     } else {
-        if ( (ret = xc_dom_kernel_file(dom, info->kernel.path)) != 0) {
+        ret = xc_dom_kernel_file(dom, info->u.pv.kernel.path);
+        if ( ret != 0) {
             LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR, "xc_dom_kernel_file failed");
             goto out;
         }
@@ -264,25 +268,27 @@ static int hvm_build_set_params(xc_inter
     return 0;
 }
 
+static const char *libxl__domain_hvmloader(libxl__gc *gc,
+                                           libxl_domain_build_info *info)
+{
+    return libxl__abs_path(gc,
+                           info->u.hvm.hvmloader ? : "hvmloader",
+                           libxl_xenfirmwaredir_path());
+}
+
 int libxl__build_hvm(libxl__gc *gc, uint32_t domid,
               libxl_domain_build_info *info, libxl_domain_build_state *state)
 {
     libxl_ctx *ctx = libxl__gc_owner(gc);
     int ret, rc = ERROR_INVAL;
 
-    if (info->kernel.mapped) {
-        LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR, "libxl__build_hvm kernel cannot be mmapped");
-        goto out;
-    }
-
     rc = ERROR_FAIL;
     ret = xc_hvm_build_target_mem(
         ctx->xch,
         domid,
         (info->max_memkb - info->video_memkb) / 1024,
         (info->target_memkb - info->video_memkb) / 1024,
-        libxl__abs_path(gc, (char *)info->kernel.path,
-                       libxl_xenfirmwaredir_path()));
+        libxl__domain_hvmloader(gc, info));
     if (ret) {
         LIBXL__LOG_ERRNOVAL(ctx, LIBXL__LOG_ERROR, ret, "hvm building failed");
         goto out;
tools/libxl/libxl_internal.c +2 -2
diff -r 7bddcc4cfc87 -r 20dcc3b31fd4 tools/libxl/libxl_internal.c
@@ -184,10 +184,10 @@ void libxl__log(libxl_ctx *ctx, xentooll
     va_end(ap);
 }
 
-char *libxl__abs_path(libxl__gc *gc, char *s, const char *path)
+char *libxl__abs_path(libxl__gc *gc, const char *s, const char *path)
 {
     if (!s || s[0] == '/')
-        return s;
+        return libxl__strdup(gc, s);
     return libxl__sprintf(gc, "%s/%s", path, s);
 }
 
tools/libxl/libxl_internal.h +3 -1
diff -r 7bddcc4cfc87 -r 20dcc3b31fd4 tools/libxl/libxl_internal.h
@@ -235,6 +235,8 @@ _hidden int libxl__domain_make(libxl__gc
 _hidden int libxl__domain_build(libxl__gc *gc, libxl_domain_build_info *info, uint32_t domid, /* out */ libxl_domain_build_state *state);
 
 /* for device model creation */
+_hidden const char *libxl__domain_device_model(libxl__gc *gc,
+                                               libxl_device_model_info *info);
 _hidden int libxl__create_device_model(libxl__gc *gc,
                               libxl_device_model_info *info,
                               libxl_device_disk *disk, int num_disks,
@@ -290,7 +292,7 @@ _hidden void libxl__exec(int stdinfd, in
 _hidden void libxl__log_child_exitstatus(libxl__gc *gc,
                                 const char *what, pid_t pid, int status);
 
-_hidden char *libxl__abs_path(libxl__gc *gc, char *s, const char *path);
+_hidden char *libxl__abs_path(libxl__gc *gc, const char *s, const char *path);
 
 #define LIBXL__LOG_DEBUG   XTL_DEBUG
 #define LIBXL__LOG_INFO    XTL_INFO
tools/libxl/libxl_utils.c +0 -83

89 lines not on this page · raw message

tools/libxl/libxl_utils.h +0 -6
diff -r 7bddcc4cfc87 -r 20dcc3b31fd4 tools/libxl/libxl_utils.h
@@ -71,12 +71,6 @@ int libxl_strtomac(const char *mac_s, ui
 int libxl_devid_to_device_net2(libxl_ctx *ctx, uint32_t domid,
                                const char *devid, libxl_device_net2 *net2);
 
-/* check the version of qemu
- * return 1 if is the new one
- * return 0 if is the old one
- * return -1 if there are an error */
-int libxl_check_device_model_version(libxl_ctx *ctx, char *path);
-
 int libxl_cpumap_alloc(libxl_ctx *ctx, libxl_cpumap *cpumap);
 int libxl_cpumap_test(libxl_cpumap *cpumap, int cpu);
 void libxl_cpumap_set(libxl_cpumap *cpumap, int cpu);
tools/libxl/xl_cmdimpl.c +23 -7
diff -r 7bddcc4cfc87 -r 20dcc3b31fd4 tools/libxl/xl_cmdimpl.c
@@ -337,7 +337,7 @@ static void printf_info(int domid,
     printf("\t(image\n");
     if (c_info->hvm) {
         printf("\t\t(hvm\n");
-        printf("\t\t\t(loader %s)\n", b_info->kernel.path);
+        printf("\t\t\t(loader %s)\n", b_info->u.hvm.hvmloader);
         printf("\t\t\t(video_memkb %d)\n", b_info->video_memkb);
         printf("\t\t\t(shadow_memkb %d)\n", b_info->shadow_memkb);
         printf("\t\t\t(pae %d)\n", b_info->u.hvm.pae);
@@ -350,7 +350,7 @@ static void printf_info(int domid,
         printf("\t\t\t(timer_mode %d)\n", b_info->u.hvm.timer_mode);
         printf("\t\t\t(nestedhvm %d)\n", b_info->u.hvm.nested_hvm);
 
-        printf("\t\t\t(device_model %s)\n", dm_info->device_model);
+        printf("\t\t\t(device_model %s)\n", dm_info->device_model ? : "default");
         printf("\t\t\t(videoram %d)\n", dm_info->videoram);
         printf("\t\t\t(stdvga %d)\n", dm_info->stdvga);
         printf("\t\t\t(vnc %d)\n", dm_info->vnc);
@@ -370,7 +370,7 @@ static void printf_info(int domid,
         printf("\t\t)\n");
     } else {
         printf("\t\t(linux %d)\n", b_info->hvm);
-        printf("\t\t\t(kernel %s)\n", b_info->kernel.path);
+        printf("\t\t\t(kernel %s)\n", b_info->u.pv.kernel.path);
         printf("\t\t\t(cmdline %s)\n", b_info->u.pv.cmdline);
         printf("\t\t\t(ramdisk %s)\n", b_info->u.pv.ramdisk.path);
         printf("\t\t)\n");
@@ -740,12 +740,16 @@ static void parse_config_data(const char
     if (!xlu_cfg_get_long (config, "videoram", &l))
         b_info->video_memkb = l * 1024;
 
-    xlu_cfg_replace_string (config, "kernel", &b_info->kernel.path);
-
     if (!xlu_cfg_get_long (config, "gfx_passthru", &l))
         dm_info->gfx_passthru = l;
 
     if (c_info->hvm == 1) {
+        if (!xlu_cfg_get_string (config, "kernel", &buf))
+            fprintf(stderr, "WARNING: ignoring \"kernel\" directive for HVM guest. "
+                    "Use \"hvmloader_override\" instead if you really want a non-default hvmloader\n");
+
+        xlu_cfg_replace_string (config, "hvmloader_override",
+                                &b_info->u.hvm.hvmloader);
         if (!xlu_cfg_get_long (config, "pae", &l))
             b_info->u.hvm.pae = l;
         if (!xlu_cfg_get_long (config, "apic", &l))
@@ -768,6 +772,8 @@ static void parse_config_data(const char
         char *cmdline = NULL;
         const char *root = NULL, *extra = "";
 
+        xlu_cfg_replace_string (config, "kernel", &b_info->u.pv.kernel.path);
+
         xlu_cfg_get_string (config, "root", &root);
         xlu_cfg_get_string (config, "extra", &extra);
 
@@ -786,7 +792,7 @@ static void parse_config_data(const char
         xlu_cfg_replace_string (config, "bootloader", &b_info->u.pv.bootloader);
         xlu_cfg_replace_string (config, "bootloader_args", &b_info->u.pv.bootloader_args);
 
-        if (!b_info->u.pv.bootloader && !b_info->kernel.path) {
+        if (!b_info->u.pv.bootloader && !b_info->u.pv.kernel.path) {
             fprintf(stderr, "Neither kernel nor bootloader specified\n");
             exit(1);
         }
@@ -1118,7 +1124,17 @@ skip_vfb:
         libxl_init_dm_info(dm_info, c_info, b_info);
 
         /* then process config related to dm */
-        xlu_cfg_replace_string (config, "device_model", &dm_info->device_model);
+        if (!xlu_cfg_get_string (config, "device_model", &buf))
+            fprintf(stderr, "WARNING: ignoring device_model directive. "
+                    "Use \"device_model_override\" instead if you really want a non-default device_model\n");
+
+        xlu_cfg_replace_string (config, "device_model_override",
+                                &dm_info->device_model);
+        if (!xlu_cfg_get_long (config, "device_model_version", &l))
+            dm_info->device_model_version = l;
+        else if (dm_info->device_model)
+            fprintf(stderr, "WARNING: device model override given without specific DM version, assuming latest\n");
+
         if (!xlu_cfg_get_long (config, "stdvga", &l))
             dm_info->stdvga = l;
         if (!xlu_cfg_get_long (config, "vnc", &l))
#20 lore raw

PATCH 1/1 tools: hvmloader: select BIOS through xenstore

In reply to Ian Campbell

# HG changeset patch
# User Ian Campbell <[email protected]> # Date 1302607403 -3600
# Node ID deeb1b89d8fd0dbdd3929ed203ce8dd9c2cf50db # Parent 20dcc3b31fd416636a69dc7c528ef486adc9dacc
tools: hvmloader: select BIOS through xenstore.

Allow the toolstack to select the BIOS to use via a xenstore key.

Defaults to "rombios" for compatibility with toolstacks which do not write the key (e.g. xend).

tools/firmware/hvmloader/hvmloader.c +25 -1
diff -r 20dcc3b31fd4 -r deeb1b89d8fd tools/firmware/hvmloader/hvmloader.c
@@ -337,10 +337,34 @@ static void cmos_write_memory_size(void)
     cmos_outb(0x35, (uint8_t)( alt_mem >> 8));
 }
 
+struct bios_info {
+    const char *key;
+    const struct bios_config *bios;
+} bios_configs[] = {
+    { "rombios", &rombios_config, },
+    { NULL, NULL }
+};
 
 static const struct bios_config *detect_bios(void)
 {
-    return &rombios_config;
+    const struct bios_info *b = &bios_configs[0];
+    const char *bios = xenstore_read("hvmloader/bios");
+
+    if (!bios)
+        bios = "rombios";
+
+    while(b->key != NULL) {
+        if (!strcmp(bios, b->key))
+            return b->bios;
+        b++;
+    }
+
+    /* oh dear */
+    printf("Unknown BIOS %s, no ROM image found\n", bios);
+    asm volatile (".text     \n"
+                  "1: hlt    \n"
+                  "   jmp 1b \n");
+    return NULL;
 }
 
 int main(void)
tools/libxl/libxl_dm.c +15 -0
diff -r 20dcc3b31fd4 -r deeb1b89d8fd tools/libxl/libxl_dm.c
@@ -66,6 +66,16 @@ const char *libxl__domain_device_model(l
     return dm;
 }
 
+static char *libxl__domain_bios(libxl__gc *gc,
+                                libxl_device_model_info *info)
+{
+    switch (info->device_model_version) {
+    case 1: return libxl__strdup(gc, "rombios");
+    case 2: return libxl__strdup(gc, "rombios");
+    default:return NULL;
+    }
+}
+
 static char ** libxl__build_device_model_args_old(libxl__gc *gc,
                                                   const char *dm,
                                                   libxl_device_model_info *info,
@@ -751,6 +761,11 @@ int libxl__create_device_model(libxl__gc
         goto out;
     }
 
+    path = libxl__sprintf(gc, "/local/domain/%d/hvmloader", info->domid);
+    xs_mkdir(ctx->xsh, XBT_NULL, path);
+    libxl__xs_write(gc, XBT_NULL, libxl__sprintf(gc, "%s/bios", path),
+                    libxl__domain_bios(gc, info));
+
     path = libxl__sprintf(gc, "/local/domain/0/device-model/%d", info->domid);
     xs_mkdir(ctx->xsh, XBT_NULL, path);
     libxl__xs_write(gc, XBT_NULL, libxl__sprintf(gc, "%s/disable_pf", path), "%d", !info->xen_platform_pci);
#21 lore raw

PATCH 1/1 tools: support SeaBIOS. Use by default when upstream qemu is configured

In reply to Ian Campbell

# HG changeset patch
# User Ian Campbell <[email protected]>
# Date 1302607447 -3600
# Node ID 5caa03e080fc311891df6516caf4747f6557a749
# Parent deeb1b89d8fd0dbdd3929ed203ce8dd9c2cf50db
tools: support SeaBIOS. Use by default when upstream qemu is configured.

The SeaBIOS integration here is only semi-complete and is targetted at developers and very early adopters who can be expected to cope with some rough edges. In particular the user must clone, patch as necessary and compile SeaBIOS themselves since this patchset does not cover any of that (in the same way we currently do not integrate upstream qemu clone+build). Include a big comment to that effect next to the Config.mk option.

Many of the bios_config callback functions are not yet used by SeaBIOS.

Config.mk +12 -0
diff -r deeb1b89d8fd -r 5caa03e080fc Config.mk
@@ -184,6 +184,18 @@ QEMU_TAG := xen-4.1.0-rc6
 # Fri Feb 11 17:54:51 2011 +0000
 # qemu-xen: fix segfault with empty cdroms
 
+# Short answer -- do not enable this unless you know what you are
+# doing and are prepared for some pain.
+
+# SeaBIOS integration is a work in progress. Before enabling this
+# option you must clone git://git.qemu.org/seabios.git/, possibly add
+# some development patches and then build it yourself before pointing
+# this variable to it (using an absolute path).
+#
+# Note that using SeaBIOS requires the use the upstream qemu as the
+# device model.
+SEABIOS_DIR ?= 
+
 # Optional components
 XENSTAT_XENTOP     ?= y
 VTPM_TOOLS         ?= n
tools/firmware/hvmloader/Makefile +14 -1
diff -r deeb1b89d8fd -r 5caa03e080fc tools/firmware/hvmloader/Makefile
@@ -40,9 +40,16 @@ CIRRUSVGA_DEBUG ?= n
 ROMBIOS_DIR := ../rombios
 ifneq ($(ROMBIOS_DIR),)
 OBJS += rombios.o
+CFLAGS += -DENABLE_ROMBIOS
 ROMBIOS_ROM := $(ROMBIOS_DIR)/BIOS-bochs-latest
 endif
 
+ifneq ($(SEABIOS_DIR),)
+OBJS += seabios.o
+CFLAGS += -DENABLE_SEABIOS
+SEABIOS_ROM := $(SEABIOS_DIR)/out/bios.bin
+endif
+
 STDVGA_ROM    := ../vgabios/VGABIOS-lgpl-latest.bin
 ifeq ($(CIRRUSVGA_DEBUG),y)
 CIRRUSVGA_ROM := ../vgabios/VGABIOS-lgpl-latest.cirrus.debug.bin
@@ -62,7 +69,7 @@ hvmloader: $(OBJS) acpi/acpi.a
 	$(OBJCOPY) hvmloader.tmp hvmloader
 	rm -f hvmloader.tmp
 
-roms.inc: $(ROMBIOS_ROM) $(STDVGA_ROM) $(CIRRUSVGA_ROM) ../etherboot/eb-roms.h
+roms.inc: $(ROMBIOS_ROM) $(SEABIOS_ROM) $(STDVGA_ROM) $(CIRRUSVGA_ROM) ../etherboot/eb-roms.h
 	echo "/* Autogenerated file. DO NOT EDIT */" > roms.inc
 
 ifneq ($(ROMBIOS_ROM),)
@@ -71,6 +78,12 @@ ifneq ($(ROMBIOS_ROM),)
 	echo "#endif" >> roms.inc
 endif
 
+ifneq ($(SEABIOS_ROM),)
+	echo "#ifdef ROM_INCLUDE_SEABIOS" >> roms.inc
+	sh ./mkhex seabios $(SEABIOS_ROM) >> roms.inc
+	echo "#endif" >> roms.inc
+endif
+
 ifneq ($(STDVGA_ROM),)
 	echo "#ifdef ROM_INCLUDE_VGABIOS" >> roms.inc
 	sh ./mkhex vgabios_stdvga $(STDVGA_ROM) >> roms.inc
tools/firmware/hvmloader/config-seabios.h new file +9 -0
diff -r deeb1b89d8fd -r 5caa03e080fc tools/firmware/hvmloader/config-seabios.h
@@ -0,0 +1,9 @@
+#ifndef __HVMLOADER_CONFIG_SEABIOS_H__
+#define __HVMLOADER_CONFIG_SEABIOS_H__
+
+#define OPTIONROM_PHYSICAL_ADDRESS  0x000C8000
+#define OPTIONROM_PHYSICAL_END      0x000E0000
+
+#define SEABIOS_PHYSICAL_ADDRESS    0x000E0000
+
+#endif /* __HVMLOADER_CONFIG_SEABIOS_H__ */
tools/firmware/hvmloader/config.h +1 -0
diff -r deeb1b89d8fd -r 5caa03e080fc tools/firmware/hvmloader/config.h
@@ -40,6 +40,7 @@ struct bios_config {
 };
 
 extern struct bios_config rombios_config;
+extern struct bios_config seabios_config;
 
 #define PAGE_SHIFT 12
 #define PAGE_SIZE  (1ul << PAGE_SHIFT)
tools/firmware/hvmloader/hvmloader.c +5 -0
diff -r deeb1b89d8fd -r 5caa03e080fc tools/firmware/hvmloader/hvmloader.c
@@ -341,7 +341,12 @@ struct bios_info {
     const char *key;
     const struct bios_config *bios;
 } bios_configs[] = {
+#ifdef ENABLE_ROMBIOS
     { "rombios", &rombios_config, },
+#endif
+#ifdef ENABLE_SEABIOS
+    { "seabios", &seabios_config, },
+#endif
     { NULL, NULL }
 };
 
tools/firmware/hvmloader/seabios.c new file +75 -0

75 lines not on this page · raw message

tools/libxl/libxl_dm.c +1 -2
diff -r deeb1b89d8fd -r 5caa03e080fc tools/libxl/libxl_dm.c
@@ -62,7 +62,6 @@ const char *libxl__domain_device_model(l
             break;
         }
     }
-
     return dm;
 }
 
@@ -71,7 +70,7 @@ static char *libxl__domain_bios(libxl__g
 {
     switch (info->device_model_version) {
     case 1: return libxl__strdup(gc, "rombios");
-    case 2: return libxl__strdup(gc, "rombios");
+    case 2: return libxl__strdup(gc, "seabios");
     default:return NULL;
     }
 }
#18 lore raw

Re: [PATCH 17 of 19] tools: libxl: hide selection of device-model, hvmloader and BIOS by default

In reply to Ian Campbell

Ian Campbell writes ("[Xen-devel] [PATCH 17 of 19] tools: libxl: hide selection of device-model, hvmloader and BIOS by default"):

Quoted 1 line

At the libxl API level:

...

Quoted 3 lines

* Add libxl_device_model_info.device_model_version allowing the user to say which qemu version (e.g. old qemu-xen or qemu upstream) they want for a domain.

Perhaps this ought to be a series of #defines, rather than an integer ? Integers have the virtue of sortability but it's not clear that that's important; a series of #defines and corresponding strings would be easier in the config file I think.

tools/libxl/libxl.c out: · line 2284

Quoted 3 lines
tools/libxl/libxl.c +1 -1
-        if (strstr(dm_info->device_model, "stubdom-dm"))
+        if (strstr(libxl__domain_device_model(&gc, dm_info), "stubdom-dm"))
             *need_memkb += 32 * 1024;

Surely this strstr(,"stubdom-dm",) can be got rid of too, in favour of "stubdom=1" or something ?

Ian.

#19 lore raw

Re: [PATCH 17 of 19] tools: libxl: hide selection of device-model, hvmloader and BIOS by default

Quoted 11 lines · Ian Jackson

Ian Campbell writes ("[Xen-devel] [PATCH 17 of 19] tools: libxl: hide selection of device-model, hvmloader and BIOS by default"):

Quoted 1 line

At the libxl API level:

...

Quoted 3 lines

* Add libxl_device_model_info.device_model_version allowing the user to say which qemu version (e.g. old qemu-xen or qemu upstream) they want for a domain.

Perhaps this ought to be a series of #defines, rather than an integer ? Integers have the virtue of sortability but it's not clear that that's important; a series of #defines and corresponding strings would be easier in the config file I think.

I agree but I had trouble figuring out what the strings/#define names should be. The current libxl code uses "old" and "new" which clearly falls apart if we need to support e.g. a new upstream command line syntax. I didn't like the "qemu-dm" vs. "upstream" distinction either.

So I'm open to suggestions...

(also, enum not #define, I think, maybe a #define for the default)

Quoted 6 lines

tools/libxl/libxl.c out: · line 2284

Quoted 3 lines
tools/libxl/libxl.c +1 -1
-        if (strstr(dm_info->device_model, "stubdom-dm"))
+        if (strstr(libxl__domain_device_model(&gc, dm_info), "stubdom-dm"))
             *need_memkb += 32 * 1024;

Surely this strstr(,"stubdom-dm",) can be got rid of too, in favour of "stubdom=1" or something ?

I don't want to expose the choice of stub or non-stub too directly so I think it would be better as a blahblah_override in the cfg file.

I'm undecided if this should be part of the set of values associated with device_model_version or if it is orthogonal enough to be a separate variable.

At the moment the only way the "stubdom-dm" string can arise is if the user used the device_model_override, since we are changing the field name anyway I guess we could also give a further warning if the device model given is "stubdom-dm" and point to the new syntax.

Ian.