Skip to contentSkip to conversation

Further SeaBIOS support

PATCH New Ian Campbell 4 participants 21 messages Jun 1, 2011 – Jun 2, 2011

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Further SeaBIOS support

The following series further updates hvmloader to support SeaBIOS.

It undoes a bunch of premature-refactoring from my previous series and adds generation of BIOS tables, plus a mechanism for passing those through to SeaBIOS.

#1 lore raw

PATCH 1/1 hvmloader: allow per-BIOS decision on loading option ROMS

# HG changeset patch
# User Ian Campbell <[email protected]>
# Date 1306916275 -3600
# Node ID 253a38db096bdc72b4e266ed103643210a739d93 # Parent cdc873250db270f1d7593eb7381cc308aa5c517f
hvmloader: allow per-BIOS decision on loading option ROMS

SeaBIOS has functionality to load ROMs from the PCI device directly, it makes sense to use this when it is available.

tools/firmware/hvmloader/config-seabios.h +0 -3
diff -r cdc873250db2 -r 253a38db096b tools/firmware/hvmloader/config-seabios.h
@@ -1,9 +1,6 @@
 #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 +2 -1
diff -r cdc873250db2 -r 253a38db096b tools/firmware/hvmloader/config.h
@@ -19,7 +19,8 @@ struct bios_config {
     /* SMBIOS */
     unsigned int smbios_start, smbios_end;
 
-    /* Option ROMs */
+    /* ROMS */
+    int load_roms;
     unsigned int optionrom_start, optionrom_end;
 
     /* ACPI tables */
tools/firmware/hvmloader/hvmloader.c +35 -32

82 lines not on this page · raw message

tools/firmware/hvmloader/rombios.c +2 -0
diff -r cdc873250db2 -r 253a38db096b tools/firmware/hvmloader/rombios.c
@@ -372,6 +372,8 @@ struct bios_config rombios_config =  {
     .smbios_start = SMBIOS_PHYSICAL_ADDRESS,
     .smbios_end = SMBIOS_PHYSICAL_END,
 
+    .load_roms = 1,
+
     .optionrom_start = OPTIONROM_PHYSICAL_ADDRESS,
     .optionrom_end = OPTIONROM_PHYSICAL_END,
 
tools/firmware/hvmloader/seabios.c +4 -2
diff -r cdc873250db2 -r 253a38db096b tools/firmware/hvmloader/seabios.c
@@ -46,8 +46,10 @@ struct bios_config seabios_config = {
     .smbios_start = 0,
     .smbios_end = 0,
 
-    .optionrom_start = OPTIONROM_PHYSICAL_ADDRESS,
-    .optionrom_end = OPTIONROM_PHYSICAL_END,
+    .load_roms = 0,
+
+    .optionrom_start = 0,
+    .optionrom_end = 0,
 
     .acpi_start = 0,
#2 lore raw

PATCH 1/1 hvmloader: enable PCI_COMMAND_IO on primary VGA device

In reply to Ian Campbell

# HG changeset patch
# User Ian Campbell <[email protected]> # Date 1306916791 -3600
# Node ID 062bc0a35d9933cc64c11f861609559e11994778 # Parent 253a38db096bdc72b4e266ed103643210a739d93
hvmloader: enable PCI_COMMAND_IO on primary VGA device

There is an implicit assumption in the PCI spec that the primary VGA device (e.g. something with class==VGA) will have I/O enabled in order to make the standard VGA I/O registers (e.g. at 0x3xx) available, even though the device has no explicit I/O BARS.

The qemu device model for the Cirrus VGA card does not actually enforce this but SeaBIOS looks for a VGA device with I/O enabled before running the VGA ROM. Coreboot has similar behaviour and I verified on a physical Cirrus GD 5446 that the BIOS had enable I/O cycles.

The thread at http://www.seabios.org/pipermail/seabios/2011-May/001804.html
contains more info.

tools/firmware/hvmloader/rombios.c +15 -0
diff -r 253a38db096b -r 062bc0a35d99 tools/firmware/hvmloader/rombios.c
@@ -102,6 +102,7 @@ static void rombios_apic_setup(void)
 static void rombios_pci_setup(void)
 {
     uint32_t base, devfn, bar_reg, bar_data, bar_sz, cmd, mmio_total = 0;
+    uint32_t vga_devfn = 256;
     uint16_t class, vendor_id, device_id;
     unsigned int bar, pin, link, isa_irq;
 
@@ -146,6 +147,8 @@ static void rombios_pci_setup(void)
         {
         case 0x0300:
             /* If emulated VGA is found, preserve it as primary VGA. */
+            if ( virtual_vga == VGA_none )
+                vga_devfn = devfn;
             if ( (vendor_id == 0x1234) && (device_id == 0x1111) )
                 virtual_vga = VGA_std;
             else if ( (vendor_id == 0x1013) && (device_id == 0xb8) )
@@ -307,6 +310,18 @@ static void rombios_pci_setup(void)
             cmd |= PCI_COMMAND_IO;
         pci_writew(devfn, PCI_COMMAND, cmd);
     }
+
+    if ( vga_devfn != 256 )
+    {
+        /*
+         * VGA registers live in I/O space so ensure that primary VGA
+         * has IO enabled, even if there is no I/O BAR on that
+         * particular device.
+         */
+        cmd = pci_readw(vga_devfn, PCI_COMMAND);
+        cmd |= PCI_COMMAND_IO;
+        pci_writew(vga_devfn, PCI_COMMAND, cmd);
+    }
 }
 
 /*
#3 lore raw

Re: [PATCH 02 of 15] hvmloader: enable PCI_COMMAND_IO on primary VGA device

Quoted 18 lines · Ian Campbell

# HG changeset patch
# User Ian Campbell <[email protected]> # Date 1306916791 -3600
# Node ID 062bc0a35d9933cc64c11f861609559e11994778 # Parent 253a38db096bdc72b4e266ed103643210a739d93
hvmloader: enable PCI_COMMAND_IO on primary VGA device

There is an implicit assumption in the PCI spec that the primary VGA device (e.g. something with class==VGA) will have I/O enabled in order to make the standard VGA I/O registers (e.g. at 0x3xx) available, even though the device has no explicit I/O BARS.

The qemu device model for the Cirrus VGA card does not actually enforce this but SeaBIOS looks for a VGA device with I/O enabled before running the VGA ROM. Coreboot has similar behaviour and I verified on a physical Cirrus GD 5446 that the BIOS had enable I/O cycles.

Quoted 4 lines

The thread at http://www.seabios.org/pipermail/seabios/2011-May/001804.html
contains more info.

Actually, this doesn't do quite what I expected. The value of virtual_vga can change multiple times if an PT device is found before one of the emulated devices. Since we want this devfn to match the device we have chosen as primary we should always update both together.

The following does that. This change conflicts with 3/15 so I will repost that too shortly.

8<-------------------------------------------------

# HG changeset patch
# User Ian Campbell <[email protected]> # Date 1306922623 -3600
# Node ID e28514b40c909f882e7075d05e614a8814786ad2 # Parent 253a38db096bdc72b4e266ed103643210a739d93
hvmloader: enable PCI_COMMAND_IO on primary VGA device

There is an implicit assumption in the PCI spec that the primary VGA device (e.g. something with class==VGA) will have I/O enabled in order to make the standard VGA I/O registers (e.g. at 0x3xx) available, even though the device has no explicit I/O BARS.

The qemu device model for the Cirrus VGA card does not actually enforce this but SeaBIOS looks for a VGA device with I/O enabled before running the VGA ROM. Coreboot has similar behaviour and I verified on a physical Cirrus GD 5446 that the BIOS had enable I/O cycles.

The thread at http://www.seabios.org/pipermail/seabios/2011-May/001804.html
contains more info.

tools/firmware/hvmloader/rombios.c +23 -0
diff -r 253a38db096b -r e28514b40c90 tools/firmware/hvmloader/rombios.c
@@ -102,6 +102,7 @@ static void rombios_apic_setup(void)
 static void rombios_pci_setup(void)
 {
     uint32_t base, devfn, bar_reg, bar_data, bar_sz, cmd, mmio_total = 0;
+    uint32_t vga_devfn = 256;
     uint16_t class, vendor_id, device_id;
     unsigned int bar, pin, link, isa_irq;
 
@@ -146,12 +147,22 @@ static void rombios_pci_setup(void)
         {
         case 0x0300:
             /* If emulated VGA is found, preserve it as primary VGA. */
+            if ( virtual_vga == VGA_none )
             if ( (vendor_id == 0x1234) && (device_id == 0x1111) )
+            {
+                vga_devfn = devfn;
                 virtual_vga = VGA_std;
+            }
             else if ( (vendor_id == 0x1013) && (device_id == 0xb8) )
+            {
+                vga_devfn = devfn;
                 virtual_vga = VGA_cirrus;
+            }
             else if ( virtual_vga == VGA_none )
+            {
+                vga_devfn = devfn;
                 virtual_vga = VGA_pt;
+            }
             break;
         case 0x0680:
             /* PIIX4 ACPI PM. Special device with special PCI config space. */
@@ -307,6 +318,18 @@ static void rombios_pci_setup(void)
             cmd |= PCI_COMMAND_IO;
         pci_writew(devfn, PCI_COMMAND, cmd);
     }
+
+    if ( vga_devfn != 256 )
+    {
+        /*
+         * VGA registers live in I/O space so ensure that primary VGA
+         * has IO enabled, even if there is no I/O BAR on that
+         * particular device.
+         */
+        cmd = pci_readw(vga_devfn, PCI_COMMAND);
+        cmd |= PCI_COMMAND_IO;
+        pci_writew(vga_devfn, PCI_COMMAND, cmd);
+    }
 }
 
 /*
#4 lore raw

PATCH 1/1 hvmloader: setup PCI bus in a common function again

In reply to Ian Campbell

# HG changeset patch
# User Ian Campbell <[email protected]> # Date 1306916881 -3600
# Node ID 8a7fb25fff1980aa4fcf963da1aa82d4dfd34bda # Parent 062bc0a35d9933cc64c11f861609559e11994778
hvmloader: setup PCI bus in a common function again.

Previous refactoring was premature.

tools/firmware/hvmloader/Makefile +1 -1
diff -r 062bc0a35d99 -r 8a7fb25fff19 tools/firmware/hvmloader/Makefile
@@ -30,7 +30,7 @@ CFLAGS += $(CFLAGS_xeninclude)
 
 OBJS  = hvmloader.o mp_tables.o util.o smbios.o 
 OBJS += 32bitbios_support.o smp.o cacheattr.o xenbus.o
-OBJS += e820.o
+OBJS += e820.o pci.o
 ifeq ($(debug),y)
 OBJS += tests.o
 endif
tools/firmware/hvmloader/config.h +1 -2
diff -r 062bc0a35d99 -r 8a7fb25fff19 tools/firmware/hvmloader/config.h
@@ -3,7 +3,7 @@
 
 #include <stdint.h>
 
-enum virtual_vga { VGA_none, VGA_std, VGA_cirrus, VGA_pt } virtual_vga;
+enum virtual_vga { VGA_none, VGA_std, VGA_cirrus, VGA_pt };
 extern enum virtual_vga virtual_vga;
 
 struct bios_config {
@@ -27,7 +27,6 @@ struct bios_config {
     unsigned int acpi_start;
 
     void (*apic_setup)(void);
-    void (*pci_setup)(void);
     void (*smp_setup)(void);
 
     uint32_t (*bios_high_setup)(void);
tools/firmware/hvmloader/hvmloader.c +1 -7
diff -r 062bc0a35d99 -r 8a7fb25fff19 tools/firmware/hvmloader/hvmloader.c
@@ -109,11 +109,6 @@ asm (
     "    .text                       \n"
     );
 
-unsigned long pci_mem_start = PCI_MEM_START;
-unsigned long pci_mem_end = PCI_MEM_END;
-
-enum virtual_vga virtual_vga = VGA_none;
-
 static void init_hypercalls(void)
 {
     uint32_t eax, ebx, ecx, edx;
@@ -391,8 +386,7 @@ int main(void)
 
     if (bios->apic_setup)
         bios->apic_setup();
-    if (bios->pci_setup)
-        bios->pci_setup();
+    pci_setup();
 
     if (bios->smp_setup)
         bios->smp_setup();
tools/firmware/hvmloader/pci.c new file +260 -0

260 lines not on this page · raw message

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

246 lines not on this page · raw message

tools/firmware/hvmloader/seabios.c +0 -6
diff -r 062bc0a35d99 -r 8a7fb25fff19 tools/firmware/hvmloader/seabios.c
@@ -28,11 +28,6 @@
 #define ROM_INCLUDE_SEABIOS
 #include "roms.inc"
 
-static void seabios_pci_setup(void)
-{
-    virtual_vga = VGA_cirrus;
-}
-
 //BUILD_BUG_ON(sizeof(seabios) > (0x00100000U - SEABIOS_PHYSICAL_ADDRESS));
 
 struct bios_config seabios_config = {
@@ -56,7 +51,6 @@ struct bios_config seabios_config = {
     .bios_info_setup = NULL,
 
     .apic_setup = NULL,
-    .pci_setup = seabios_pci_setup,
     .smp_setup = NULL,
 
     .vm86_setup = NULL,
tools/firmware/hvmloader/util.h +3 -0
diff -r 062bc0a35d99 -r 8a7fb25fff19 tools/firmware/hvmloader/util.h
@@ -180,6 +180,9 @@ void xenbus_shutdown(void);
  * static buffer, so only valid until the next xenstore/xenbus operation. */
 char *xenstore_read(char *path);
 
+/* Setup PCI bus */
+void pci_setup(void);
+
 /* Prepare the 32bit BIOS */
 uint32_t rombios_highbios_setup(void);
#5 lore raw

Re: [PATCH 03 of 15] hvmloader: setup PCI bus in a common function again

Quoted 6 lines · Ian Campbell

# HG changeset patch
# User Ian Campbell <[email protected]> # Date 1306916881 -3600
# Node ID 8a7fb25fff1980aa4fcf963da1aa82d4dfd34bda # Parent 062bc0a35d9933cc64c11f861609559e11994778
hvmloader: setup PCI bus in a common function again.

Reposting, updated for changed patch 2/15.

8<----------------------------------------------------

# HG changeset patch
# User Ian Campbell <[email protected]> # Date 1306922653 -3600
# Node ID 3a17969b49e2d07ebf5cd302250bfcd31c88a758 # Parent e28514b40c909f882e7075d05e614a8814786ad2
hvmloader: setup PCI bus in a common function again.

Previous refactoring was premature.

tools/firmware/hvmloader/Makefile +1 -1
diff -r e28514b40c90 -r 3a17969b49e2 tools/firmware/hvmloader/Makefile
@@ -30,7 +30,7 @@ CFLAGS += $(CFLAGS_xeninclude)
 
 OBJS  = hvmloader.o mp_tables.o util.o smbios.o 
 OBJS += 32bitbios_support.o smp.o cacheattr.o xenbus.o
-OBJS += e820.o
+OBJS += e820.o pci.o
 ifeq ($(debug),y)
 OBJS += tests.o
 endif
tools/firmware/hvmloader/config.h +1 -2
diff -r e28514b40c90 -r 3a17969b49e2 tools/firmware/hvmloader/config.h
@@ -3,7 +3,7 @@
 
 #include <stdint.h>
 
-enum virtual_vga { VGA_none, VGA_std, VGA_cirrus, VGA_pt } virtual_vga;
+enum virtual_vga { VGA_none, VGA_std, VGA_cirrus, VGA_pt };
 extern enum virtual_vga virtual_vga;
 
 struct bios_config {
@@ -27,7 +27,6 @@ struct bios_config {
     unsigned int acpi_start;
 
     void (*apic_setup)(void);
-    void (*pci_setup)(void);
     void (*smp_setup)(void);
 
     uint32_t (*bios_high_setup)(void);
tools/firmware/hvmloader/hvmloader.c +1 -7
diff -r e28514b40c90 -r 3a17969b49e2 tools/firmware/hvmloader/hvmloader.c
@@ -109,11 +109,6 @@ asm (
     "    .text                       \n"
     );
 
-unsigned long pci_mem_start = PCI_MEM_START;
-unsigned long pci_mem_end = PCI_MEM_END;
-
-enum virtual_vga virtual_vga = VGA_none;
-
 static void init_hypercalls(void)
 {
     uint32_t eax, ebx, ecx, edx;
@@ -391,8 +386,7 @@ int main(void)
 
     if (bios->apic_setup)
         bios->apic_setup();
-    if (bios->pci_setup)
-        bios->pci_setup();
+    pci_setup();
 
     if (bios->smp_setup)
         bios->smp_setup();
tools/firmware/hvmloader/pci.c new file +267 -0

267 lines not on this page · raw message

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

254 lines not on this page · raw message

tools/firmware/hvmloader/seabios.c +0 -6
diff -r e28514b40c90 -r 3a17969b49e2 tools/firmware/hvmloader/seabios.c
@@ -28,11 +28,6 @@
 #define ROM_INCLUDE_SEABIOS
 #include "roms.inc"
 
-static void seabios_pci_setup(void)
-{
-    virtual_vga = VGA_cirrus;
-}
-
 //BUILD_BUG_ON(sizeof(seabios) > (0x00100000U - SEABIOS_PHYSICAL_ADDRESS));
 
 struct bios_config seabios_config = {
@@ -56,7 +51,6 @@ struct bios_config seabios_config = {
     .bios_info_setup = NULL,
 
     .apic_setup = NULL,
-    .pci_setup = seabios_pci_setup,
     .smp_setup = NULL,
 
     .vm86_setup = NULL,
tools/firmware/hvmloader/util.h +3 -0
diff -r e28514b40c90 -r 3a17969b49e2 tools/firmware/hvmloader/util.h
@@ -180,6 +180,9 @@ void xenbus_shutdown(void);
  * static buffer, so only valid until the next xenstore/xenbus operation. */
 char *xenstore_read(char *path);
 
+/* Setup PCI bus */
+void pci_setup(void);
+
 /* Prepare the 32bit BIOS */
 uint32_t rombios_highbios_setup(void);
#6 lore raw

Re: Re: [PATCH 03 of 15] hvmloader: setup PCI bus in a common function again

Quoted 9 lines · Ian Campbell
Quoted 6 lines · Ian Campbell

# HG changeset patch
# User Ian Campbell <[email protected]> # Date 1306916881 -3600
# Node ID 8a7fb25fff1980aa4fcf963da1aa82d4dfd34bda # Parent 062bc0a35d9933cc64c11f861609559e11994778
hvmloader: setup PCI bus in a common function again.

Reposting, updated for changed patch 2/15.

Gah, not sure what I build tested, but it obviously wasn't this code... Incremental fix (to avoid reposting both 2/15 and 3/15) below.

tools/firmware/hvmloader/pci.c +0 -1
diff -r 439f07b2d43e tools/firmware/hvmloader/pci.c
@@ -81,7 +81,6 @@ void pci_setup(void)
         {
         case 0x0300:
             /* If emulated VGA is found, preserve it as primary VGA. */
-            if ( virtual_vga == VGA_none )
             if ( (vendor_id == 0x1234) && (device_id == 0x1111) )
             {
                 vga_devfn = devfn;
#7 lore raw

PATCH 1/1 hvmloader: setup APICs in a common function again

In reply to Ian Campbell

# HG changeset patch
# User Ian Campbell <[email protected]> # Date 1306916889 -3600
# Node ID b76a45b26b062be8f376271b039698ef566ffab2 # Parent 8a7fb25fff1980aa4fcf963da1aa82d4dfd34bda
hvmloader: setup APICs in a common function again.

Previous refactoring was premature.

tools/firmware/hvmloader/config.h +0 -1
diff -r 8a7fb25fff19 -r b76a45b26b06 tools/firmware/hvmloader/config.h
@@ -26,7 +26,6 @@ struct bios_config {
     /* ACPI tables */
     unsigned int acpi_start;
 
-    void (*apic_setup)(void);
     void (*smp_setup)(void);
 
     uint32_t (*bios_high_setup)(void);
tools/firmware/hvmloader/hvmloader.c +17 -2
diff -r 8a7fb25fff19 -r b76a45b26b06 tools/firmware/hvmloader/hvmloader.c
@@ -25,6 +25,7 @@
 #include "config.h"
 #include "pci_regs.h"
 #include "option_rom.h"
+#include "apic_regs.h"
 #include <xen/version.h>
 #include <xen/hvm/params.h>
 
@@ -332,6 +333,21 @@ static void cmos_write_memory_size(void)
     cmos_outb(0x35, (uint8_t)( alt_mem >> 8));
 }
 
+static void apic_setup(void)
+{
+    /* Set the IOAPIC ID to the static value used in the MP/ACPI tables. */
+    ioapic_write(0x00, IOAPIC_ID);
+
+    /* NMIs are delivered direct to the BSP. */
+    lapic_write(APIC_SPIV, APIC_SPIV_APIC_ENABLED | 0xFF);
+    lapic_write(APIC_LVT0, (APIC_MODE_EXTINT << 8) | APIC_LVT_MASKED);
+    lapic_write(APIC_LVT1, APIC_MODE_NMI << 8);
+
+    /* 8259A ExtInts are delivered through IOAPIC pin 0 (Virtual Wire Mode). */
+    ioapic_write(0x10, APIC_DM_EXTINT);
+    ioapic_write(0x11, SET_APIC_ID(LAPIC_ID(0)));
+}
+
 struct bios_info {
     const char *key;
     const struct bios_config *bios;
@@ -384,8 +400,7 @@ int main(void)
 
     printf("CPU speed is %u MHz\n", get_cpu_mhz());
 
-    if (bios->apic_setup)
-        bios->apic_setup();
+    apic_setup();
     pci_setup();
 
     if (bios->smp_setup)
tools/firmware/hvmloader/rombios.c +0 -17
diff -r 8a7fb25fff19 -r b76a45b26b06 tools/firmware/hvmloader/rombios.c
@@ -25,7 +25,6 @@
 #include "../rombios/config.h"
 
 #include "acpi/acpi2_0.h"
-#include "apic_regs.h"
 #include "pci_regs.h"
 #include "util.h"
 #include "hypercall.h"
@@ -82,21 +81,6 @@ static void rombios_setup_bios_info(uint
     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. */
-    ioapic_write(0x00, IOAPIC_ID);
-
-    /* NMIs are delivered direct to the BSP. */
-    lapic_write(APIC_SPIV, APIC_SPIV_APIC_ENABLED | 0xFF);
-    lapic_write(APIC_LVT0, (APIC_MODE_EXTINT << 8) | APIC_LVT_MASKED);
-    lapic_write(APIC_LVT1, APIC_MODE_NMI << 8);
-
-    /* 8259A ExtInts are delivered through IOAPIC pin 0 (Virtual Wire Mode). */
-    ioapic_write(0x10, APIC_DM_EXTINT);
-    ioapic_write(0x11, SET_APIC_ID(LAPIC_ID(0)));
-}
-
 /*
  * find_mp_table_start - searchs through BIOS memory for '___HVMMP' signature
  *
@@ -167,7 +151,6 @@ struct bios_config rombios_config =  {
 
     .acpi_start = ACPI_PHYSICAL_ADDRESS,
 
-    .apic_setup = rombios_apic_setup,
     .smp_setup = smp_initialise,
 
     .bios_high_setup = rombios_highbios_setup,
tools/firmware/hvmloader/seabios.c +0 -1
diff -r 8a7fb25fff19 -r b76a45b26b06 tools/firmware/hvmloader/seabios.c
@@ -50,7 +50,6 @@ struct bios_config seabios_config = {
 
     .bios_info_setup = NULL,
 
-    .apic_setup = NULL,
     .smp_setup = NULL,
 
     .vm86_setup = NULL,
#8 lore raw

PATCH 1/1 hvmloader: call SMP setup from common code again

In reply to Ian Campbell

# HG changeset patch
# User Ian Campbell <[email protected]> # Date 1306916902 -3600
# Node ID ecc58aeac569ad6defd47cc068eb93df143a0b5c # Parent b76a45b26b062be8f376271b039698ef566ffab2
hvmloader: call SMP setup from common code again.

Previous refactoring was premature.

tools/firmware/hvmloader/config.h +0 -2
diff -r b76a45b26b06 -r ecc58aeac569 tools/firmware/hvmloader/config.h
@@ -26,8 +26,6 @@ struct bios_config {
     /* ACPI tables */
     unsigned int acpi_start;
 
-    void (*smp_setup)(void);
-
     uint32_t (*bios_high_setup)(void);
     void (*bios_info_setup)(uint32_t);
 
tools/firmware/hvmloader/hvmloader.c +1 -2
diff -r b76a45b26b06 -r ecc58aeac569 tools/firmware/hvmloader/hvmloader.c
@@ -403,8 +403,7 @@ int main(void)
     apic_setup();
     pci_setup();
 
-    if (bios->smp_setup)
-        bios->smp_setup();
+    smp_initialise();
 
     perform_tests();
 
tools/firmware/hvmloader/rombios.c +0 -2
diff -r b76a45b26b06 -r ecc58aeac569 tools/firmware/hvmloader/rombios.c
@@ -151,8 +151,6 @@ struct bios_config rombios_config =  {
 
     .acpi_start = ACPI_PHYSICAL_ADDRESS,
 
-    .smp_setup = smp_initialise,
-
     .bios_high_setup = rombios_highbios_setup,
     .bios_info_setup = rombios_setup_bios_info,
 
tools/firmware/hvmloader/seabios.c +0 -2
diff -r b76a45b26b06 -r ecc58aeac569 tools/firmware/hvmloader/seabios.c
@@ -50,8 +50,6 @@ struct bios_config seabios_config = {
 
     .bios_info_setup = NULL,
 
-    .smp_setup = NULL,
-
     .vm86_setup = NULL,
     .e820_setup = NULL,
#9 lore raw

PATCH 1/1 hvmloader: make ACPI initialisation hook more general

In reply to Ian Campbell

# HG changeset patch
# User Ian Campbell <[email protected]> # Date 1306916909 -3600
# Node ID 4d9116ca460ed18d23f2c04c28ea2b5a67586830 # Parent ecc58aeac569ad6defd47cc068eb93df143a0b5c
hvmloader: make ACPI initialisation hook more general.

tools/firmware/hvmloader/config.h +1 -4
diff -r ecc58aeac569 -r 4d9116ca460e tools/firmware/hvmloader/config.h
@@ -23,16 +23,13 @@ struct bios_config {
     int load_roms;
     unsigned int optionrom_start, optionrom_end;
 
-    /* ACPI tables */
-    unsigned int acpi_start;
-
     uint32_t (*bios_high_setup)(void);
     void (*bios_info_setup)(uint32_t);
 
     void (*vm86_setup)(void);
     void (*e820_setup)(void);
 
-    void (*acpi_build_tables)(unsigned int physical);
+    void (*acpi_build_tables)(void);
     void (*create_mp_tables)(void);
 };
 
tools/firmware/hvmloader/hvmloader.c +1 -1
diff -r ecc58aeac569 -r 4d9116ca460e tools/firmware/hvmloader/hvmloader.c
@@ -472,7 +472,7 @@ int main(void)
 
         if ( bios->acpi_build_tables ) {
             printf("Loading ACPI ...\n");
-            bios->acpi_build_tables(bios->acpi_start);
+            bios->acpi_build_tables();
         }
         hypercall_hvm_op(HVMOP_set_param, &p);
     }
tools/firmware/hvmloader/rombios.c +6 -3
diff -r ecc58aeac569 -r 4d9116ca460e tools/firmware/hvmloader/rombios.c
@@ -115,6 +115,11 @@ static void reset_bios_checksum(void)
     *((uint8_t *)(ROMBIOS_BEGIN + ROMBIOS_MAXOFFSET)) = -checksum;
 }
 
+static void rombios_acpi_build_tables(void)
+{
+    acpi_build_tables(ACPI_PHYSICAL_ADDRESS);
+}
+
 static void rombios_create_mp_tables(void)
 {
     /* Find the 'safe' place in ROMBIOS for the MP tables. */
@@ -149,15 +154,13 @@ struct bios_config rombios_config =  {
     .optionrom_start = OPTIONROM_PHYSICAL_ADDRESS,
     .optionrom_end = OPTIONROM_PHYSICAL_END,
 
-    .acpi_start = ACPI_PHYSICAL_ADDRESS,
-
     .bios_high_setup = rombios_highbios_setup,
     .bios_info_setup = rombios_setup_bios_info,
 
     .vm86_setup = rombios_init_vm86_tss,
     .e820_setup = rombios_setup_e820,
 
-    .acpi_build_tables = acpi_build_tables,
+    .acpi_build_tables = rombios_acpi_build_tables,
     .create_mp_tables = rombios_create_mp_tables,
 };
 
tools/firmware/hvmloader/seabios.c +0 -2
diff -r ecc58aeac569 -r 4d9116ca460e tools/firmware/hvmloader/seabios.c
@@ -46,8 +46,6 @@ struct bios_config seabios_config = {
     .optionrom_start = 0,
     .optionrom_end = 0,
 
-    .acpi_start = 0,
-
     .bios_info_setup = NULL,
 
     .vm86_setup = NULL,
#10 lore raw

PATCH 1/1 hvmloader: make SMBIOS initialisation more general

In reply to Ian Campbell

# HG changeset patch
# User Ian Campbell <[email protected]> # Date 1306917341 -3600
# Node ID 673d9039cd5972d496fa1dbdb2b783a6696c3fbb # Parent 4d9116ca460ed18d23f2c04c28ea2b5a67586830
hvmloader: make SMBIOS initialisation more general.

tools/firmware/hvmloader/config.h +1 -3
diff -r 4d9116ca460e -r 673d9039cd59 tools/firmware/hvmloader/config.h
@@ -16,9 +16,6 @@ struct bios_config {
     /* Physical address to load at */
     unsigned int bios_address;
 
-    /* SMBIOS */
-    unsigned int smbios_start, smbios_end;
-
     /* ROMS */
     int load_roms;
     unsigned int optionrom_start, optionrom_end;
@@ -31,6 +28,7 @@ struct bios_config {
 
     void (*acpi_build_tables)(void);
     void (*create_mp_tables)(void);
+    void (*create_smbios_tables)(void);
 };
 
 extern struct bios_config rombios_config;
tools/firmware/hvmloader/hvmloader.c +3 -9
diff -r 4d9116ca460e -r 673d9039cd59 tools/firmware/hvmloader/hvmloader.c
@@ -383,7 +383,7 @@ 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;
+    int option_rom_sz = 0, vgabios_sz = 0, etherboot_sz = 0;
     uint32_t etherboot_phys_addr = 0, option_rom_phys_addr = 0;
 
     /* Initialise hypercall stubs with RET, rendering them no-ops. */
@@ -407,11 +407,9 @@ int main(void)
 
     perform_tests();
 
-    if (bios->smbios_start) {
+    if (bios->create_smbios_tables) {
         printf("Writing SMBIOS tables ...\n");
-        smbios_sz = hvm_write_smbios_tables(SCRATCH_PHYSICAL_ADDRESS,
-                                            bios->smbios_start,
-                                            bios->smbios_end);
+        bios->create_smbios_tables();
     }
 
     printf("Loading %s ...\n", bios->name);
@@ -495,10 +493,6 @@ int main(void)
         printf(" %05x-%05x: PCI Option ROMs\n",
                option_rom_phys_addr,
                option_rom_phys_addr + option_rom_sz - 1);
-    if ( smbios_sz )
-        printf(" %05x-%05x: SMBIOS tables\n",
-               bios->smbios_start,
-               bios->smbios_start + smbios_sz - 1);
     printf(" %05x-%05x: Main BIOS\n",
            bios->bios_address,
            bios->bios_address + bios->image_size - 1);
tools/firmware/hvmloader/rombios.c +8 -3
diff -r 4d9116ca460e -r 673d9039cd59 tools/firmware/hvmloader/rombios.c
@@ -136,6 +136,13 @@ static void rombios_create_mp_tables(voi
     reset_bios_checksum();
 }
 
+static void rombios_create_smbios_tables(void)
+{
+    hvm_write_smbios_tables(SCRATCH_PHYSICAL_ADDRESS,
+                            SMBIOS_PHYSICAL_ADDRESS,
+                            SMBIOS_PHYSICAL_END);
+}
+
 //BUILD_BUG_ON(sizeof(rombios) > (0x00100000U - ROMBIOS_PHYSICAL_ADDRESS));
 
 struct bios_config rombios_config =  {
@@ -146,9 +153,6 @@ struct bios_config rombios_config =  {
 
     .bios_address = ROMBIOS_PHYSICAL_ADDRESS,
 
-    .smbios_start = SMBIOS_PHYSICAL_ADDRESS,
-    .smbios_end = SMBIOS_PHYSICAL_END,
-
     .load_roms = 1,
 
     .optionrom_start = OPTIONROM_PHYSICAL_ADDRESS,
@@ -162,6 +166,7 @@ struct bios_config rombios_config =  {
 
     .acpi_build_tables = rombios_acpi_build_tables,
     .create_mp_tables = rombios_create_mp_tables,
+    .create_smbios_tables = rombios_create_smbios_tables,
 };
 
 /*
tools/firmware/hvmloader/seabios.c +1 -3
diff -r 4d9116ca460e -r 673d9039cd59 tools/firmware/hvmloader/seabios.c
@@ -38,9 +38,6 @@ struct bios_config seabios_config = {
 
     .bios_address = SEABIOS_PHYSICAL_ADDRESS,
 
-    .smbios_start = 0,
-    .smbios_end = 0,
-
     .load_roms = 0,
 
     .optionrom_start = 0,
@@ -53,6 +50,7 @@ struct bios_config seabios_config = {
 
     .acpi_build_tables = NULL,
     .create_mp_tables = NULL,
+    .create_smbios_tables = NULL,
 };
 
 /*
#11 lore raw

PATCH 1/1 hvmloader: Add a simple "scratch allocator"

In reply to Ian Campbell

# HG changeset patch
# User Ian Campbell <[email protected]> # Date 1306917394 -3600
# Node ID 3c920f4ec4f24e1c134749972d5762aa009ee3dc # Parent 673d9039cd5972d496fa1dbdb2b783a6696c3fbb
hvmloader: Add a simple "scratch allocator"

Returns memory which is passed to the subsequent BIOS but can be reused once the contents is consumed. An example of this would be a BIOS table which the BIOS consumes by copying rather than simply referencing.

Users which need a temporary scratch buffer for internal use scratch_start which follows these allocations.

tools/firmware/hvmloader/config.h +2 -0
diff -r 673d9039cd59 -r 3c920f4ec4f2 tools/firmware/hvmloader/config.h
@@ -62,6 +62,8 @@ extern unsigned long pci_mem_start, pci_
 #define VGABIOS_PHYSICAL_ADDRESS      0x000C0000
 #define HVMLOADER_PHYSICAL_ADDRESS    0x00100000
 
+extern unsigned long scratch_start;
+
 #endif /* __HVMLOADER_CONFIG_H__ */
 
 /*
tools/firmware/hvmloader/hvmloader.c +5 -0
diff -r 673d9039cd59 -r 3c920f4ec4f2 tools/firmware/hvmloader/hvmloader.c
@@ -110,6 +110,8 @@ asm (
     "    .text                       \n"
     );
 
+unsigned long scratch_start = SCRATCH_PHYSICAL_ADDRESS;
+
 static void init_hypercalls(void)
 {
     uint32_t eax, ebx, ecx, edx;
@@ -481,6 +483,9 @@ int main(void)
     cmos_write_memory_size();
 
     printf("BIOS map:\n");
+    if ( SCRATCH_PHYSICAL_ADDRESS != scratch_start )
+        printf(" %05x-%05lx: Scratch space\n",
+               SCRATCH_PHYSICAL_ADDRESS, scratch_start);
     if ( vgabios_sz )
         printf(" %05x-%05x: VGA BIOS\n",
                VGABIOS_PHYSICAL_ADDRESS,
tools/firmware/hvmloader/pci.c +1 -1
diff -r 673d9039cd59 -r 3c920f4ec4f2 tools/firmware/hvmloader/pci.c
@@ -48,7 +48,7 @@ void pci_setup(void)
     /* Create a list of device BARs in descending order of size. */
     struct bars {
         uint32_t devfn, bar_reg, bar_sz;
-    } *bars = (struct bars *)SCRATCH_PHYSICAL_ADDRESS;
+    } *bars = (struct bars *)scratch_start;
     unsigned int i, nr_bars = 0;
 
     /* Program PCI-ISA bridge with appropriate link routes. */
tools/firmware/hvmloader/rombios.c +1 -1
diff -r 673d9039cd59 -r 3c920f4ec4f2 tools/firmware/hvmloader/rombios.c
@@ -138,7 +138,7 @@ static void rombios_create_mp_tables(voi
 
 static void rombios_create_smbios_tables(void)
 {
-    hvm_write_smbios_tables(SCRATCH_PHYSICAL_ADDRESS,
+    hvm_write_smbios_tables(scratch_start,
                             SMBIOS_PHYSICAL_ADDRESS,
                             SMBIOS_PHYSICAL_END);
 }
tools/firmware/hvmloader/util.c +18 -0
diff -r 673d9039cd59 -r 3c920f4ec4f2 tools/firmware/hvmloader/util.c
@@ -362,6 +362,24 @@ void *mem_alloc(uint32_t size, uint32_t 
     return (void *)(unsigned long)s;
 }
 
+void *scratch_alloc(uint32_t size, uint32_t align)
+{
+    uint32_t s, e;
+
+    /* Align to at least one kilobyte. */
+    if ( align < 1024 )
+        align = 1024;
+
+    s = (scratch_start + align - 1) & ~(align - 1);
+    e = s + size - 1;
+
+    BUG_ON(e < s);
+
+    scratch_start = e;
+
+    return (void *)(unsigned long)s;
+}
+
 uint32_t ioapic_read(uint32_t reg)
 {
     *(volatile uint32_t *)(IOAPIC_BASE_ADDRESS + 0x00) = reg;
tools/firmware/hvmloader/util.h +3 -0
diff -r 673d9039cd59 -r 3c920f4ec4f2 tools/firmware/hvmloader/util.h
@@ -168,6 +168,9 @@ int vprintf(const char *fmt, va_list ap)
 void *mem_alloc(uint32_t size, uint32_t align);
 #define virt_to_phys(v) ((unsigned long)(v))
 
+/* Allocate memory in a scratch region */
+void *scratch_alloc(uint32_t size, uint32_t align);
+
 /* Connect our xenbus client to the backend.  
  * Call once, before any other xenbus actions. */
 void xenbus_setup(void);
#12 lore raw

Re: [PATCH 08 of 15] hvmloader: Add a simple "scratch allocator"

Quoted 6 lines
tools/firmware/hvmloader/util.c +6 -0
+void *scratch_alloc(uint32_t size, uint32_t align)
+{
+    uint32_t s, e;
+
+    /* Align to at least one kilobyte. */
+    if ( align < 1024 )

tools/firmware/hvmloader/util.c void *mem_alloc(uint32_t size, uint32_t · line 380

Quoted 10 lines
tools/firmware/hvmloader/util.c +10 -0
+        align = 1024;
+
+    s = (scratch_start + align - 1) & ~(align - 1);
+    e = s + size - 1;
+
+    BUG_ON(e < s);
+
+    scratch_start = e;
+
+    return (void *)(unsigned long)s;

Why the double cast?

#13 lore raw

Re: [PATCH 08 of 15] hvmloader: Add a simple "scratch allocator"

Quoted 3 lines · Konrad Rzeszutek Wilk
Quoted 1 line

+ return (void *)(unsigned long)s;

Why the double cast?

gcc complains if you cast between a pointer and an integer of a different size. We assume in many places that a pointer is same size as a long, so we cast through a long when the original integer type may be different size. In this case, in hvmloader, we know that pointers/longs/uint32_t are all 32-bit, but still I quite like the principle of always casting through a long when the integer is not explicitly that type already.

-- Keir

#14 lore raw

PATCH 1/1 hvmloader: refactor BIOS info setup

In reply to Ian Campbell

# HG changeset patch
# User Ian Campbell <[email protected]> # Date 1306917395 -3600
# Node ID 99820702549e428fd961b160afa1dae75bc7010d # Parent 3c920f4ec4f24e1c134749972d5762aa009ee3dc
hvmloader: refactor BIOS info setup

Currently we have ->bios_high_setup, which is called relatively early and returns a cookie which is passed to ->bios_info_setup which runs towards the end and creates the BIOS info, incorporating the cookie which (in the case of ROMBIOS) happens to be the BIOS's high load address . This is rather ROMBIOS specific.

Refactor to have ->bios_info_setup which is called early and prepares the bios_info, ->bios_relocate which does any necessary relocation (updating the BIOS info as necessary) and ->bios_info_finish which finalises the info (e.g. by calculating the checksum).

tools/firmware/hvmloader/config.h +4 -2
diff -r 3c920f4ec4f2 -r 99820702549e tools/firmware/hvmloader/config.h
@@ -20,8 +20,10 @@ struct bios_config {
     int load_roms;
     unsigned int optionrom_start, optionrom_end;
 
-    uint32_t (*bios_high_setup)(void);
-    void (*bios_info_setup)(uint32_t);
+    void (*bios_info_setup)(void);
+    void (*bios_info_finish)(void);
+
+    void (*bios_relocate)(void);
 
     void (*vm86_setup)(void);
     void (*e820_setup)(void);
tools/firmware/hvmloader/hvmloader.c +7 -5
diff -r 3c920f4ec4f2 -r 99820702549e tools/firmware/hvmloader/hvmloader.c
@@ -383,7 +383,6 @@ 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;
     uint32_t etherboot_phys_addr = 0, option_rom_phys_addr = 0;
@@ -409,6 +408,9 @@ int main(void)
 
     perform_tests();
 
+    if (bios->bios_info_setup)
+        bios->bios_info_setup();
+
     if (bios->create_smbios_tables) {
         printf("Writing SMBIOS tables ...\n");
         bios->create_smbios_tables();
@@ -418,8 +420,8 @@ int main(void)
     memcpy((void *)bios->bios_address, bios->image,
            bios->image_size);
 
-    if (bios->bios_high_setup)
-        highbios = bios->bios_high_setup();
+    if (bios->bios_relocate)
+        bios->bios_relocate();
 
     if ( bios->create_mp_tables &&
          ( (hvm_info->nr_vcpus > 1) || hvm_info->apic_mode ) )
@@ -505,8 +507,8 @@ int main(void)
     if (bios->e820_setup)
         bios->e820_setup();
 
-    if (bios->bios_info_setup)
-        bios->bios_info_setup(highbios);
+    if (bios->bios_info_finish)
+        bios->bios_info_finish();
 
     xenbus_shutdown();
 
tools/firmware/hvmloader/rombios.c +24 -5
diff -r 3c920f4ec4f2 -r 99820702549e tools/firmware/hvmloader/rombios.c
@@ -64,7 +64,7 @@ static void rombios_setup_e820(void)
     dump_e820_table(E820, *E820_NR);
 }
 
-static void rombios_setup_bios_info(uint32_t bioshigh)
+static void rombios_setup_bios_info(void)
 {
     struct bios_info *bios_info;
 
@@ -74,11 +74,28 @@ static void rombios_setup_bios_info(uint
     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->madt_csum_addr = madt_csum_addr;
+    bios_info->madt_lapic0_addr = madt_lapic0_addr;
+}
+
+static void rombios_relocate(void)
+{
+    uint32_t bioshigh;
+    struct bios_info *bios_info;
+
+    bioshigh = rombios_highbios_setup();
+
+    bios_info = (struct bios_info *)BIOS_INFO_PHYSICAL_ADDRESS;
+    bios_info->bios32_entry = bioshigh;
+}
+
+static void rombios_finish_bios_info(void)
+{
+    struct bios_info *bios_info;
+
+    bios_info = (struct bios_info *)BIOS_INFO_PHYSICAL_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;
 }
 
 /*
@@ -158,8 +175,10 @@ struct bios_config rombios_config =  {
     .optionrom_start = OPTIONROM_PHYSICAL_ADDRESS,
     .optionrom_end = OPTIONROM_PHYSICAL_END,
 
-    .bios_high_setup = rombios_highbios_setup,
     .bios_info_setup = rombios_setup_bios_info,
+    .bios_info_finish = rombios_finish_bios_info,
+
+    .bios_relocate = rombios_relocate,
 
     .vm86_setup = rombios_init_vm86_tss,
     .e820_setup = rombios_setup_e820,
tools/firmware/hvmloader/seabios.c +3 -0
diff -r 3c920f4ec4f2 -r 99820702549e tools/firmware/hvmloader/seabios.c
@@ -44,6 +44,9 @@ struct bios_config seabios_config = {
     .optionrom_end = 0,
 
     .bios_info_setup = NULL,
+    .bios_info_finish = NULL,
+
+    .bios_relocate = NULL,
 
     .vm86_setup = NULL,
     .e820_setup = NULL,
#15 lore raw

PATCH 1/1 hvmloader: return MPFPS from create_mp_tables()

In reply to Ian Campbell

# HG changeset patch
# User Ian Campbell <[email protected]> # Date 1306917433 -3600
# Node ID 361304106d85f61cdeffd5805c46520feac19e89 # Parent 99820702549e428fd961b160afa1dae75bc7010d
hvmloader: return MPFPS from create_mp_tables()

This is the hook which the mptables hang off, so it is useful to know.

tools/firmware/hvmloader/mp_tables.c +10 -9
diff -r 99820702549e -r 361304106d85 tools/firmware/hvmloader/mp_tables.c
@@ -260,17 +260,21 @@ static void fill_mpfps(struct mp_floatin
 }
 
 /* create_mp_tables - creates MP tables for the guest based upon config data */
-void create_mp_tables(void *mp_table_base)
+unsigned long create_mp_tables(void *_mpfps)
 {
     char *p;
     int vcpu_nr, i, length;
+    void *base;
     struct mp_io_intr_entry *mpiie;
+    struct mp_floating_pointer_struct *mpfps = _mpfps;
 
     vcpu_nr = hvm_info->nr_vcpus;
 
     printf("Creating MP tables ...\n");
 
-    p = mp_table_base + sizeof(struct mp_config_table);
+    base = &mpfps[1];
+
+    p = base + sizeof(struct mp_config_table);
 
     for ( i = 0; i < vcpu_nr; i++ )
     {
@@ -308,14 +312,11 @@ void create_mp_tables(void *mp_table_bas
         p += sizeof(*mpiie);
     }
 
-    length = p - (char *)mp_table_base;
+    length = p - (char *)base;
 
-    /* find the next 16-byte boundary to place the mp floating pointer */
-    while ( (unsigned long)p & 0xF )
-        p++;
+    fill_mp_config_table((struct mp_config_table *)base, length);
 
-    fill_mpfps((struct mp_floating_pointer_struct *)p, 
-               (uint32_t)mp_table_base);
+    fill_mpfps(mpfps, (uint32_t)base);
 
-    fill_mp_config_table((struct mp_config_table *)mp_table_base, length);
+    return (unsigned long)mpfps;
 }
tools/firmware/hvmloader/util.h +1 -1
diff -r 99820702549e -r 361304106d85 tools/firmware/hvmloader/util.h
@@ -191,7 +191,7 @@ uint32_t rombios_highbios_setup(void);
 
 /* Miscellaneous. */
 void cacheattr_init(void);
-void create_mp_tables(void *table);
+unsigned long create_mp_tables(void *table);
 int hvm_write_smbios_tables(unsigned long scratch,
 			    unsigned long smbios_start,
 			    unsigned long smbios_end);
#16 lore raw

PATCH 1/1 hvmloader: allow create_mp_tables() to allocate the table

In reply to Ian Campbell

# HG changeset patch
# User Ian Campbell <[email protected]>
# Date 1306917709 -3600
# Node ID 5357077295f21154b076925d1d4687b076de6bfc # Parent 361304106d85f61cdeffd5805c46520feac19e89
hvmloader: allow create_mp_tables() to allocate the table

Will be used by SeaBIOS.

tools/firmware/hvmloader/mp_tables.c +16 -1
diff -r 361304106d85 -r 5357077295f2 tools/firmware/hvmloader/mp_tables.c
@@ -266,12 +266,27 @@ unsigned long create_mp_tables(void *_mp
     int vcpu_nr, i, length;
     void *base;
     struct mp_io_intr_entry *mpiie;
-    struct mp_floating_pointer_struct *mpfps = _mpfps;
+    struct mp_floating_pointer_struct *mpfps;
 
     vcpu_nr = hvm_info->nr_vcpus;
 
     printf("Creating MP tables ...\n");
 
+    if (!_mpfps) {
+        int sz;
+
+        sz  = sizeof(struct mp_floating_pointer_struct);
+        sz += sizeof(struct mp_config_table);
+        sz += sizeof(struct mp_proc_entry) * vcpu_nr;
+        sz += sizeof(struct mp_bus_entry);
+        sz += sizeof(struct mp_ioapic_entry);
+        sz += sizeof(struct mp_io_intr_entry) * 16;
+
+        base = mem_alloc(sz, 0);
+    }
+
+    mpfps = _mpfps;
+
     base = &mpfps[1];
 
     p = base + sizeof(struct mp_config_table);
#17 lore raw

PATCH 1/1 hvmloader: smbios: allow the entry point data structure to be located separately

In reply to Ian Campbell

# HG changeset patch
# User Ian Campbell <[email protected]>
# Date 1306917734 -3600
# Node ID 644a9208e3bb34e533ffeaf7001c48355e05a084
# Parent 5357077295f21154b076925d1d4687b076de6bfc
hvmloader: smbios: allow the entry point data structure to be located separately.

tools/firmware/hvmloader/rombios.c +3 -2
diff -r 5357077295f2 -r 644a9208e3bb tools/firmware/hvmloader/rombios.c
@@ -24,6 +24,7 @@
 
 #include "../rombios/config.h"
 
+#include "smbios_types.h"
 #include "acpi/acpi2_0.h"
 #include "pci_regs.h"
 #include "util.h"
@@ -155,8 +156,8 @@ static void rombios_create_mp_tables(voi
 
 static void rombios_create_smbios_tables(void)
 {
-    hvm_write_smbios_tables(scratch_start,
-                            SMBIOS_PHYSICAL_ADDRESS,
+    hvm_write_smbios_tables(SMBIOS_PHYSICAL_ADDRESS,
+                            SMBIOS_PHYSICAL_ADDRESS + sizeof(struct smbios_entry_point),
                             SMBIOS_PHYSICAL_END);
 }
 
tools/firmware/hvmloader/smbios.c +10 -12
diff -r 5357077295f2 -r 644a9208e3bb tools/firmware/hvmloader/smbios.c
@@ -28,7 +28,7 @@
 #include "hypercall.h"
 
 static int
-write_smbios_tables(void *start, unsigned long phys,
+write_smbios_tables(void *ep, 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, unsigned long phys,
+write_smbios_tables(void *ep, 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)
@@ -97,7 +97,7 @@ write_smbios_tables(void *start, unsigne
 
     get_cpu_manufacturer(cpu_manufacturer, 15);
 
-    p = (char *)start + sizeof(struct smbios_entry_point);
+    p = (char *)start;
 
 #define do_struct(fn) do {                      \
     q = (fn);                                   \
@@ -133,11 +133,9 @@ write_smbios_tables(void *start, unsigne
 
 #undef do_struct
 
-    smbios_entry_point_init(
-        start, max_struct_size,
-        (p - (char *)start) - sizeof(struct smbios_entry_point),
-        phys + sizeof(struct smbios_entry_point),
-        nr_structs);
+    smbios_entry_point_init(ep, max_struct_size,
+                            (p - (char *)start), phys,
+                            nr_structs);
 
     return ((char *)p - (char *)start);
 }
@@ -162,7 +160,7 @@ get_memsize(void)
 }
 
 int
-hvm_write_smbios_tables(unsigned long scratch, unsigned long smbios_start, unsigned long smbios_end)
+hvm_write_smbios_tables(unsigned long ep, unsigned long smbios_start, unsigned long smbios_end)
 {
     xen_domain_handle_t uuid;
     uint16_t xen_major_version, xen_minor_version;
@@ -221,15 +219,15 @@ hvm_write_smbios_tables(unsigned long sc
 
     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, smbios_start,
+    /* scratch_start is a safe large memory area for scratch. */
+    len = write_smbios_tables((void *)ep, (void *)scratch_start, smbios_start,
                               hvm_info->nr_vcpus, get_memsize(),
                               uuid, xen_version_str,
                               xen_major_version, xen_minor_version);
     if ( smbios_start + len > smbios_end )
         goto error_out;
     /* Okay, not too large: copy out of scratch to final location. */
-    memcpy((void *)smbios_start, (void *)scratch, len);
+    memcpy((void *)smbios_start, (void *)scratch_start, len);
 
     return len;
 
tools/firmware/hvmloader/util.h +1 -1
diff -r 5357077295f2 -r 644a9208e3bb tools/firmware/hvmloader/util.h
@@ -192,7 +192,7 @@ uint32_t rombios_highbios_setup(void);
 /* Miscellaneous. */
 void cacheattr_init(void);
 unsigned long create_mp_tables(void *table);
-int hvm_write_smbios_tables(unsigned long scratch,
+int hvm_write_smbios_tables(unsigned long ep,
 			    unsigned long smbios_start,
 			    unsigned long smbios_end);
 void smp_initialise(void);
#18 lore raw

PATCH 1/1 hvmloader: further support for SeaBIOS

In reply to Ian Campbell

# HG changeset patch
# User Ian Campbell <[email protected]> # Date 1306917958 -3600
# Node ID 5d695cfaded597bb9e70818a9225bde3a91d3355 # Parent 644a9208e3bb34e533ffeaf7001c48355e05a084
hvmloader: further support for SeaBIOS

Build the various BIOS tables and arrange for them to be passed to SeaBIOS. We define a simple data structure structure at a known physical address for this purpose.

tools/firmware/hvmloader/config-seabios.h +2 -0
diff -r 644a9208e3bb -r 5d695cfaded5 tools/firmware/hvmloader/config-seabios.h
@@ -1,6 +1,8 @@
 #ifndef __HVMLOADER_CONFIG_SEABIOS_H__
 #define __HVMLOADER_CONFIG_SEABIOS_H__
 
+#define BIOS_INFO_PHYSICAL_ADDRESS  0x00001000
+
 #define SEABIOS_PHYSICAL_ADDRESS    0x000E0000
 
 #endif /* __HVMLOADER_CONFIG_SEABIOS_H__ */
tools/firmware/hvmloader/seabios.c +95 -6

121 lines not on this page · raw message

#19 lore raw

PATCH 1/1 hvmloader: allow the possibility to allocate the size of smbios table we actually need

In reply to Ian Campbell

# HG changeset patch
# User Ian Campbell <[email protected]>
# Date 1306917980 -3600
# Node ID 7e6e8594316a62193f9ab629ee2b8848224cce22
# Parent 5d695cfaded597bb9e70818a9225bde3a91d3355
hvmloader: allow the possibility to allocate the size of smbios table we actually need.

tools/firmware/hvmloader/seabios.c +1 -2
diff -r 5d695cfaded5 -r 7e6e8594316a tools/firmware/hvmloader/seabios.c
@@ -103,8 +103,7 @@ static void seabios_create_mp_tables(voi
 static void seabios_create_smbios_tables(void)
 {
     uint32_t ep = (uint32_t)scratch_alloc(sizeof(struct smbios_entry_point), 0);
-    uint32_t t = (uint32_t)mem_alloc(32*1024, 0);
-    hvm_write_smbios_tables(ep, t, 32*1024);
+    hvm_write_smbios_tables(ep, 0UL, 0UL);
     add_table(ep);
 }
 
tools/firmware/hvmloader/smbios.c +23 -19

98 lines not on this page · raw message

tools/firmware/hvmloader/util.h +1 -1
diff -r 5d695cfaded5 -r 7e6e8594316a tools/firmware/hvmloader/util.h
@@ -192,7 +192,7 @@ uint32_t rombios_highbios_setup(void);
 /* Miscellaneous. */
 void cacheattr_init(void);
 unsigned long create_mp_tables(void *table);
-int hvm_write_smbios_tables(unsigned long ep,
+void hvm_write_smbios_tables(unsigned long ep,
 			    unsigned long smbios_start,
 			    unsigned long smbios_end);
 void smp_initialise(void);
#20 lore raw

PATCH 1/1 hvmloader: add code to generate a $PIR table

In reply to Ian Campbell

# HG changeset patch
# User Ian Campbell <[email protected]> # Date 1306918266 -3600
# Node ID b47bc708c79191ee7ca15d4e642a4609fe26d88b # Parent 7e6e8594316a62193f9ab629ee2b8848224cce22
hvmloader: add code to generate a $PIR table.

Does not replace the table hardcoded in ROMBIOS (it ain't broke) but is used for SeaBIOS.

tools/firmware/hvmloader/Makefile +1 -1
diff -r 7e6e8594316a -r b47bc708c791 tools/firmware/hvmloader/Makefile
@@ -30,7 +30,7 @@ CFLAGS += $(CFLAGS_xeninclude)
 
 OBJS  = hvmloader.o mp_tables.o util.o smbios.o 
 OBJS += 32bitbios_support.o smp.o cacheattr.o xenbus.o
-OBJS += e820.o pci.o
+OBJS += e820.o pci.o pir.o
 ifeq ($(debug),y)
 OBJS += tests.o
 endif
tools/firmware/hvmloader/config.h +1 -0
diff -r 7e6e8594316a -r b47bc708c791 tools/firmware/hvmloader/config.h
@@ -31,6 +31,7 @@ struct bios_config {
     void (*acpi_build_tables)(void);
     void (*create_mp_tables)(void);
     void (*create_smbios_tables)(void);
+    void (*create_pir_tables)(void);
 };
 
 extern struct bios_config rombios_config;
tools/firmware/hvmloader/hvmloader.c +6 -3
diff -r 7e6e8594316a -r b47bc708c791 tools/firmware/hvmloader/hvmloader.c
@@ -423,9 +423,12 @@ int main(void)
     if (bios->bios_relocate)
         bios->bios_relocate();
 
-    if ( bios->create_mp_tables &&
-         ( (hvm_info->nr_vcpus > 1) || hvm_info->apic_mode ) )
-        bios->create_mp_tables();
+    if ( (hvm_info->nr_vcpus > 1) || hvm_info->apic_mode ) {
+        if ( bios->create_mp_tables )
+            bios->create_mp_tables();
+        if ( bios->create_pir_tables )
+            bios->create_pir_tables();
+    }
 
     if ( bios->load_roms )
     {
tools/firmware/hvmloader/pir.c new file +67 -0

67 lines not on this page · raw message

tools/firmware/hvmloader/pir_types.h new file +61 -0

61 lines not on this page · raw message

tools/firmware/hvmloader/rombios.c +1 -0
diff -r 7e6e8594316a -r b47bc708c791 tools/firmware/hvmloader/rombios.c
@@ -187,6 +187,7 @@ struct bios_config rombios_config =  {
     .acpi_build_tables = rombios_acpi_build_tables,
     .create_mp_tables = rombios_create_mp_tables,
     .create_smbios_tables = rombios_create_smbios_tables,
+    .create_pir_tables = NULL, /* embedded in ROMBIOS */
 };
 
 /*
tools/firmware/hvmloader/seabios.c +6 -0
diff -r 7e6e8594316a -r b47bc708c791 tools/firmware/hvmloader/seabios.c
@@ -107,6 +107,11 @@ static void seabios_create_smbios_tables
     add_table(ep);
 }
 
+static void seabios_create_pir_tables(void)
+{
+    add_table(create_pir_tables());
+}
+
 static void seabios_setup_e820(void)
 {
     struct seabios_info *info = (void *)BIOS_INFO_PHYSICAL_ADDRESS;
@@ -142,6 +147,7 @@ struct bios_config seabios_config = {
     .acpi_build_tables = seabios_acpi_build_tables,
     .create_mp_tables = seabios_create_mp_tables,
     .create_smbios_tables = seabios_create_smbios_tables,
+    .create_pir_tables = seabios_create_pir_tables,
 };
 
 /*
tools/firmware/hvmloader/util.h +2 -0
diff -r 7e6e8594316a -r b47bc708c791 tools/firmware/hvmloader/util.h
@@ -195,6 +195,8 @@ unsigned long create_mp_tables(void *tab
 void hvm_write_smbios_tables(unsigned long ep,
 			    unsigned long smbios_start,
 			    unsigned long smbios_end);
+unsigned long create_pir_tables(void);
+
 void smp_initialise(void);
 
 #include "e820.h"