Skip to contentSkip to conversation

pc: Initialization and compat function cleanup

PATCH Superseded Eduardo Habkost 2 participants 6 messages Aug 17, 2015 – Aug 25, 2015

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

v2 cover pc: Initialization and compat function cleanup

Changes v1 -> v2:
* Fix build error on patch 1/4

This implements some extras code cleanups in the PC code:

* Move some local variables from pc_init1() and pc_q35_init() to PCMachineState, so initialization functions can get that info from a PCMachineState* argument directly
* Move some compat global variables to PCMachineClass,
and move compatibility code from pc_compat_*() functions to the corresponding *_machine_options() function

Eduardo Habkost (4):
pc: Remove redundant arguments from xen_hvm_init()
pc: Move compat boolean globals to PCMachineClass
pc: Move legacy_acpi_table_size global to PCMachineClass
pc: Move acpi_data_size global to PCMachineClass

 hw/i386/pc.c         |  25 +++++-----
 hw/i386/pc_piix.c    | 130 ++++++++++++++++++++++++---------------------------
 hw/i386/pc_q35.c     |  60 +++++++++++-------------
 include/hw/i386/pc.h |  21 ++++++++-
 include/hw/xen/xen.h |   4 +-
 xen-hvm-stub.c       |   3 +-
 xen-hvm.c            |  25 +++++-----
 7 files changed, 135 insertions(+), 133 deletions(-)
Signature · 1 line
2.1.0
#1 lore raw

PATCH v2 1/4 pc: Remove redundant arguments from xen_hvm_init()

Remove arguments that can be found in PCMachineState.

---
Changes v1 -> v2:
* Change prototype on xen-hvm-stub.c too

---
 hw/i386/pc_piix.c    |  4 +---
 hw/i386/pc_q35.c     |  4 +---
 include/hw/xen/xen.h |  4 ++--
 xen-hvm-stub.c       |  3 +--
 xen-hvm.c            | 25 ++++++++++++-------------
 5 files changed, 17 insertions(+), 23 deletions(-)
hw/i386/pc_piix.c +1 -3
index 9558467..2b7afc8 100644
@@ -134,9 +134,7 @@ static void pc_init1(MachineState *machine)
         pcms->below_4g_mem_size = machine->ram_size;
     }
 
-    if (xen_enabled() && xen_hvm_init(&pcms->below_4g_mem_size,
-                                      &pcms->above_4g_mem_size,
-                                      &ram_memory) != 0) {
+    if (xen_enabled() && xen_hvm_init(pcms, &ram_memory) != 0) {
         fprintf(stderr, "xen hardware virtual machine initialisation failed\n");
         exit(1);
     }
hw/i386/pc_q35.c +1 -3
index c07d65b..36dd6a4 100644
@@ -125,9 +125,7 @@ static void pc_q35_init(MachineState *machine)
         pcms->below_4g_mem_size = machine->ram_size;
     }
 
-    if (xen_enabled() && xen_hvm_init(&pcms->below_4g_mem_size,
-                                      &pcms->above_4g_mem_size,
-                                      &ram_memory) != 0) {
+    if (xen_enabled() && xen_hvm_init(pcms, &ram_memory) != 0) {
         fprintf(stderr, "xen hardware virtual machine initialisation failed\n");
         exit(1);
     }
include/hw/xen/xen.h +2 -2
index 4356af4..e90931a 100644
@@ -10,6 +10,7 @@
 
 #include "hw/irq.h"
 #include "qemu-common.h"
+#include "qemu/typedefs.h"
 
 /* xen-machine.c */
 enum xen_mode {
@@ -38,8 +39,7 @@ qemu_irq *xen_interrupt_controller_init(void);
 void xenstore_store_pv_console_info(int i, struct CharDriverState *chr);
 
 #if defined(NEED_CPU_H) && !defined(CONFIG_USER_ONLY)
-int xen_hvm_init(ram_addr_t *below_4g_mem_size, ram_addr_t *above_4g_mem_size,
-                 MemoryRegion **ram_memory);
+int xen_hvm_init(PCMachineState *pcms, MemoryRegion **ram_memory);
 void xen_ram_alloc(ram_addr_t ram_addr, ram_addr_t size,
                    struct MemoryRegion *mr);
 void xen_modified_memory(ram_addr_t start, ram_addr_t length);
xen-hvm-stub.c +1 -2
index 46867d8..6a39425 100644
@@ -47,8 +47,7 @@ void xen_modified_memory(ram_addr_t start, ram_addr_t length)
 {
 }
 
-int xen_hvm_init(ram_addr_t *below_4g_mem_size, ram_addr_t *above_4g_mem_size,
-                 MemoryRegion **ram_memory)
+int xen_hvm_init(PCMachineState *pcms, MemoryRegion **ram_memory)
 {
     return 0;
 }
xen-hvm.c +12 -13
index 0408462..55bce3a 100644
@@ -180,8 +180,7 @@ qemu_irq *xen_interrupt_controller_init(void)
 
 /* Memory Ops */
 
-static void xen_ram_init(ram_addr_t *below_4g_mem_size,
-                         ram_addr_t *above_4g_mem_size,
+static void xen_ram_init(PCMachineState *pcms,
                          ram_addr_t ram_size, MemoryRegion **ram_memory_p)
 {
     MemoryRegion *sysmem = get_system_memory();
@@ -198,20 +197,20 @@ static void xen_ram_init(ram_addr_t *below_4g_mem_size,
     }
 
     if (ram_size >= user_lowmem) {
-        *above_4g_mem_size = ram_size - user_lowmem;
-        *below_4g_mem_size = user_lowmem;
+        pcms->above_4g_mem_size = ram_size - user_lowmem;
+        pcms->below_4g_mem_size = user_lowmem;
     } else {
-        *above_4g_mem_size = 0;
-        *below_4g_mem_size = ram_size;
+        pcms->above_4g_mem_size = 0;
+        pcms->below_4g_mem_size = ram_size;
     }
-    if (!*above_4g_mem_size) {
+    if (!pcms->above_4g_mem_size) {
         block_len = ram_size;
     } else {
         /*
          * Xen does not allocate the memory continuously, it keeps a
          * hole of the size computed above or passed in.
          */
-        block_len = (1ULL << 32) + *above_4g_mem_size;
+        block_len = (1ULL << 32) + pcms->above_4g_mem_size;
     }
     memory_region_init_ram(&ram_memory, NULL, "xen.ram", block_len,
                            &error_abort);
@@ -229,12 +228,12 @@ static void xen_ram_init(ram_addr_t *below_4g_mem_size,
      */
     memory_region_init_alias(&ram_lo, NULL, "xen.ram.lo",
                              &ram_memory, 0xc0000,
-                             *below_4g_mem_size - 0xc0000);
+                             pcms->below_4g_mem_size - 0xc0000);
     memory_region_add_subregion(sysmem, 0xc0000, &ram_lo);
-    if (*above_4g_mem_size > 0) {
+    if (pcms->above_4g_mem_size > 0) {
         memory_region_init_alias(&ram_hi, NULL, "xen.ram.hi",
                                  &ram_memory, 0x100000000ULL,
-                                 *above_4g_mem_size);
+                                 pcms->above_4g_mem_size);
         memory_region_add_subregion(sysmem, 0x100000000ULL, &ram_hi);
     }
 }
@@ -1159,7 +1158,7 @@ static void xen_wakeup_notifier(Notifier *notifier, void *data)
 }
 
 /* return 0 means OK, or -1 means critical issue -- will exit(1) */
-int xen_hvm_init(ram_addr_t *below_4g_mem_size, ram_addr_t *above_4g_mem_size,
+int xen_hvm_init(PCMachineState *pcms,
                  MemoryRegion **ram_memory)
 {
     int i, rc;
@@ -1270,7 +1269,7 @@ int xen_hvm_init(ram_addr_t *below_4g_mem_size, ram_addr_t *above_4g_mem_size,
 
     /* Init RAM management */
     xen_map_cache_init(xen_phys_offset_to_gaddr, state);
-    xen_ram_init(below_4g_mem_size, above_4g_mem_size, ram_size, ram_memory);
+    xen_ram_init(pcms, ram_size, ram_memory);
 
     qemu_add_vm_change_state_handler(xen_hvm_change_state_handler, state);
 
Signature · 1 line
2.1.0
Reviewed-by on v2 1/4
#2 lore raw

Re: [Qemu-devel] [PATCH v2 1/4] pc: Remove redundant arguments from xen_hvm_init()

Quoted 148 lines · Eduardo Habkost

Remove arguments that can be found in PCMachineState.

---
Changes v1 -> v2:
* Change prototype on xen-hvm-stub.c too

---
  hw/i386/pc_piix.c    |  4 +---
  hw/i386/pc_q35.c     |  4 +---
  include/hw/xen/xen.h |  4 ++--
  xen-hvm-stub.c       |  3 +--
  xen-hvm.c            | 25 ++++++++++++-------------
  5 files changed, 17 insertions(+), 23 deletions(-)
hw/i386/pc_piix.c +1 -3
index 9558467..2b7afc8 100644
@@ -134,9 +134,7 @@ static void pc_init1(MachineState *machine)
          pcms->below_4g_mem_size = machine->ram_size;
      }
 
-    if (xen_enabled() && xen_hvm_init(&pcms->below_4g_mem_size,
-                                      &pcms->above_4g_mem_size,
-                                      &ram_memory) != 0) {
+    if (xen_enabled() && xen_hvm_init(pcms, &ram_memory) != 0) {
          fprintf(stderr, "xen hardware virtual machine initialisation failed\n");
          exit(1);
      }
hw/i386/pc_q35.c +1 -3
index c07d65b..36dd6a4 100644
@@ -125,9 +125,7 @@ static void pc_q35_init(MachineState *machine)
          pcms->below_4g_mem_size = machine->ram_size;
      }
 
-    if (xen_enabled() && xen_hvm_init(&pcms->below_4g_mem_size,
-                                      &pcms->above_4g_mem_size,
-                                      &ram_memory) != 0) {
+    if (xen_enabled() && xen_hvm_init(pcms, &ram_memory) != 0) {
          fprintf(stderr, "xen hardware virtual machine initialisation failed\n");
          exit(1);
      }
include/hw/xen/xen.h +2 -2
index 4356af4..e90931a 100644
@@ -10,6 +10,7 @@
 
  #include "hw/irq.h"
  #include "qemu-common.h"
+#include "qemu/typedefs.h"
 
  /* xen-machine.c */
  enum xen_mode {
@@ -38,8 +39,7 @@ qemu_irq *xen_interrupt_controller_init(void);
  void xenstore_store_pv_console_info(int i, struct CharDriverState *chr);
 
  #if defined(NEED_CPU_H) && !defined(CONFIG_USER_ONLY)
-int xen_hvm_init(ram_addr_t *below_4g_mem_size, ram_addr_t *above_4g_mem_size,
-                 MemoryRegion **ram_memory);
+int xen_hvm_init(PCMachineState *pcms, MemoryRegion **ram_memory);
  void xen_ram_alloc(ram_addr_t ram_addr, ram_addr_t size,
                     struct MemoryRegion *mr);
  void xen_modified_memory(ram_addr_t start, ram_addr_t length);
xen-hvm-stub.c +1 -2
index 46867d8..6a39425 100644
@@ -47,8 +47,7 @@ void xen_modified_memory(ram_addr_t start, ram_addr_t length)
  {
  }
 
-int xen_hvm_init(ram_addr_t *below_4g_mem_size, ram_addr_t *above_4g_mem_size,
-                 MemoryRegion **ram_memory)
+int xen_hvm_init(PCMachineState *pcms, MemoryRegion **ram_memory)
  {
      return 0;
  }
xen-hvm.c +11 -12
index 0408462..55bce3a 100644
@@ -180,8 +180,7 @@ qemu_irq *xen_interrupt_controller_init(void)
 
  /* Memory Ops */
 
-static void xen_ram_init(ram_addr_t *below_4g_mem_size,
-                         ram_addr_t *above_4g_mem_size,
+static void xen_ram_init(PCMachineState *pcms,
                           ram_addr_t ram_size, MemoryRegion **ram_memory_p)
  {
      MemoryRegion *sysmem = get_system_memory();
@@ -198,20 +197,20 @@ static void xen_ram_init(ram_addr_t *below_4g_mem_size,
      }
 
      if (ram_size >= user_lowmem) {
-        *above_4g_mem_size = ram_size - user_lowmem;
-        *below_4g_mem_size = user_lowmem;
+        pcms->above_4g_mem_size = ram_size - user_lowmem;
+        pcms->below_4g_mem_size = user_lowmem;
      } else {
-        *above_4g_mem_size = 0;
-        *below_4g_mem_size = ram_size;
+        pcms->above_4g_mem_size = 0;
+        pcms->below_4g_mem_size = ram_size;
      }
-    if (!*above_4g_mem_size) {
+    if (!pcms->above_4g_mem_size) {
          block_len = ram_size;
      } else {
          /*
           * Xen does not allocate the memory continuously, it keeps a
           * hole of the size computed above or passed in.
           */
-        block_len = (1ULL << 32) + *above_4g_mem_size;
+        block_len = (1ULL << 32) + pcms->above_4g_mem_size;
      }
      memory_region_init_ram(&ram_memory, NULL, "xen.ram", block_len,
                             &error_abort);
@@ -229,12 +228,12 @@ static void xen_ram_init(ram_addr_t *below_4g_mem_size,
       */
      memory_region_init_alias(&ram_lo, NULL, "xen.ram.lo",
                               &ram_memory, 0xc0000,
-                             *below_4g_mem_size - 0xc0000);
+                             pcms->below_4g_mem_size - 0xc0000);
      memory_region_add_subregion(sysmem, 0xc0000, &ram_lo);
-    if (*above_4g_mem_size > 0) {
+    if (pcms->above_4g_mem_size > 0) {
          memory_region_init_alias(&ram_hi, NULL, "xen.ram.hi",
                                   &ram_memory, 0x100000000ULL,
-                                 *above_4g_mem_size);
+                                 pcms->above_4g_mem_size);
          memory_region_add_subregion(sysmem, 0x100000000ULL, &ram_hi);
      }
  }
@@ -1159,7 +1158,7 @@ static void xen_wakeup_notifier(Notifier *notifier, void *data)
  }
 
  /* return 0 means OK, or -1 means critical issue -- will exit(1) */
-int xen_hvm_init(ram_addr_t *below_4g_mem_size, ram_addr_t *above_4g_mem_size,
+int xen_hvm_init(PCMachineState *pcms,
                   MemoryRegion **ram_memory)
  {
      int i, rc;

xen-hvm.c int xen_hvm_init(ram_addr_t *below_4g_mem_size, ram_addr_t *above_4g_mem_size, · line 1275

Quoted 8 lines
xen-hvm.c +1 -1
@@ -1270,7 +1269,7 @@ int xen_hvm_init(ram_addr_t *below_4g_mem_size, ram_addr_t *above_4g_mem_size,
 
      /* Init RAM management */
      xen_map_cache_init(xen_phys_offset_to_gaddr, state);
-    xen_ram_init(below_4g_mem_size, above_4g_mem_size, ram_size, ram_memory);
+    xen_ram_init(pcms, ram_size, ram_memory);
 
      qemu_add_vm_change_state_handler(xen_hvm_change_state_handler, state);
 

Thanks,
Marcel

#3 lore raw

PATCH v2 2/4 pc: Move compat boolean globals to PCMachineClass

In reply to Eduardo Habkost

This way the compat flags can be initialized in the machine_options() function. This will help us to eventually eliminate the pc_compat_*() functions.

---
 hw/i386/pc.c         |  8 +++++
 hw/i386/pc_piix.c    | 84 +++++++++++++++++++++++++---------------------------
 hw/i386/pc_q35.c     | 54 +++++++++++++++------------------
 include/hw/i386/pc.h | 14 +++++++++
 4 files changed, 86 insertions(+), 74 deletions(-)
hw/i386/pc.c +8 -0
index 9f2924e..430cd5c 100644
@@ -1951,6 +1951,14 @@ static void pc_machine_class_init(ObjectClass *oc, void *data)
     HotplugHandlerClass *hc = HOTPLUG_HANDLER_CLASS(oc);
 
     pcmc->get_hotplug_handler = mc->get_hotplug_handler;
+    pcmc->pci_enabled = true;
+    pcmc->has_acpi_build = true;
+    pcmc->rsdp_in_ram = true;
+    pcmc->smbios_defaults = true;
+    pcmc->smbios_uuid_encoded = true;
+    pcmc->gigabyte_align = true;
+    pcmc->has_reserved_memory = true;
+    pcmc->kvmclock_enabled = true;
     mc->get_hotplug_handler = pc_get_hotpug_handler;
     mc->cpu_index_to_socket_id = pc_cpu_index_to_socket_id;
     mc->default_boot_order = "cad";
hw/i386/pc_piix.c +40 -44

267 lines not on this page · raw message

hw/i386/pc_q35.c +24 -30

186 lines not on this page · raw message

include/hw/i386/pc.h +14 -0
index d0cad87..b09c652 100644
@@ -61,6 +61,20 @@ struct PCMachineClass {
     /*< public >*/
     HotplugHandler *(*get_hotplug_handler)(MachineState *machine,
                                            DeviceState *dev);
+
+    bool pci_enabled;
+    bool has_acpi_build;
+    bool rsdp_in_ram;
+    bool smbios_defaults;
+    bool smbios_legacy_mode;
+    bool smbios_uuid_encoded;
+    /* Make sure that guest addresses aligned at 1Gbyte boundaries get
+     * mapped to host addresses aligned at 1Gbyte boundaries.  This way
+     * we can use 1GByte pages in the host.
+     */
+    bool gigabyte_align;
+    bool has_reserved_memory;
+    bool kvmclock_enabled;
 };
 
 #define TYPE_PC_MACHINE "generic-pc-machine"
Signature · 1 line
2.1.0
#4 lore raw

PATCH v2 3/4 pc: Move legacy_acpi_table_size global to PCMachineClass

In reply to Eduardo Habkost

This way we can set legacy_acpi_table_size on the machine_options() functions, instead of requirng code in pc_compat_*() functions.

---
 hw/i386/pc_piix.c    | 40 +++++++++++++++++++---------------------
 include/hw/i386/pc.h |  1 +
 2 files changed, 20 insertions(+), 21 deletions(-)
hw/i386/pc_piix.c +19 -21
index 3b80ade..ea544fa 100644
@@ -60,8 +60,6 @@ static const int ide_iobase[MAX_IDE_BUS] = { 0x1f0, 0x170 };
 static const int ide_iobase2[MAX_IDE_BUS] = { 0x3f6, 0x376 };
 static const int ide_irq[MAX_IDE_BUS] = { 14, 15 };
 
-static int legacy_acpi_table_size;
-
 /* PC hardware initialisation */
 static void pc_init1(MachineState *machine)
 {
@@ -149,7 +147,7 @@ static void pc_init1(MachineState *machine)
     guest_info = pc_guest_info_init(pcms);
 
     guest_info->has_acpi_build = pcmc->has_acpi_build;
-    guest_info->legacy_acpi_table_size = legacy_acpi_table_size;
+    guest_info->legacy_acpi_table_size = pcmc->legacy_acpi_table_size;
 
     guest_info->isapc_ram_fw = !pcmc->pci_enabled;
     guest_info->has_reserved_memory = pcmc->has_reserved_memory;
@@ -314,23 +312,6 @@ static void pc_compat_2_1(MachineState *machine)
 static void pc_compat_2_0(MachineState *machine)
 {
     pc_compat_2_1(machine);
-    /* This value depends on the actual DSDT and SSDT compiled into
-     * the source QEMU; unfortunately it depends on the binary and
-     * not on the machine type, so we cannot make pc-i440fx-1.7 work on
-     * both QEMU 1.7 and QEMU 2.0.
-     *
-     * Large variations cause migration to fail for more than one
-     * consecutive value of the "-smp" maxcpus option.
-     *
-     * For small variations of the kind caused by different iasl versions,
-     * the 4k rounding usually leaves slack.  However, there could be still
-     * one or two values that break.  For QEMU 1.7 and QEMU 2.0 the
-     * slack is only ~10 bytes before one "-smp maxcpus" value breaks!
-     *
-     * 6652 is valid for QEMU 2.0, the right value for pc-i440fx-1.7 on
-     * QEMU 1.7 it is 6414.  For RHEL/CentOS 7.0 it is 6418.
-     */
-    legacy_acpi_table_size = 6652;
     pc_set_legacy_acpi_data_size();
 }
 
@@ -338,7 +319,6 @@ static void pc_compat_1_7(MachineState *machine)
 {
     pc_compat_2_0(machine);
     option_rom_has_mr = true;
-    legacy_acpi_table_size = 6414;
     x86_cpu_compat_kvm_no_autoenable(FEAT_1_ECX, CPUID_EXT_X2APIC);
 }
 
@@ -479,6 +459,23 @@ static void pc_i440fx_2_0_machine_options(MachineClass *m)
     SET_MACHINE_COMPAT(m, PC_COMPAT_2_0);
     pcmc->smbios_legacy_mode = true;
     pcmc->has_reserved_memory = false;
+    /* This value depends on the actual DSDT and SSDT compiled into
+     * the source QEMU; unfortunately it depends on the binary and
+     * not on the machine type, so we cannot make pc-i440fx-1.7 work on
+     * both QEMU 1.7 and QEMU 2.0.
+     *
+     * Large variations cause migration to fail for more than one
+     * consecutive value of the "-smp" maxcpus option.
+     *
+     * For small variations of the kind caused by different iasl versions,
+     * the 4k rounding usually leaves slack.  However, there could be still
+     * one or two values that break.  For QEMU 1.7 and QEMU 2.0 the
+     * slack is only ~10 bytes before one "-smp maxcpus" value breaks!
+     *
+     * 6652 is valid for QEMU 2.0, the right value for pc-i440fx-1.7 on
+     * QEMU 1.7 it is 6414.  For RHEL/CentOS 7.0 it is 6418.
+     */
+    pcmc->legacy_acpi_table_size = 6652;
 }
 
 DEFINE_I440FX_MACHINE(v2_0, "pc-i440fx-2.0", pc_compat_2_0,
@@ -493,6 +490,7 @@ static void pc_i440fx_1_7_machine_options(MachineClass *m)
     SET_MACHINE_COMPAT(m, PC_COMPAT_1_7);
     pcmc->smbios_defaults = false;
     pcmc->gigabyte_align = false;
+    pcmc->legacy_acpi_table_size = 6414;
 }
 
 DEFINE_I440FX_MACHINE(v1_7, "pc-i440fx-1.7", pc_compat_1_7,
include/hw/i386/pc.h +1 -0
index b09c652..b812968 100644
@@ -75,6 +75,7 @@ struct PCMachineClass {
     bool gigabyte_align;
     bool has_reserved_memory;
     bool kvmclock_enabled;
+    int legacy_acpi_table_size;
 };
 
 #define TYPE_PC_MACHINE "generic-pc-machine"
Signature · 1 line
2.1.0
#5 lore raw

PATCH v2 4/4 pc: Move acpi_data_size global to PCMachineClass

In reply to Eduardo Habkost

This way we don't need code in pc_compat_*() functions to set the legacy acpi_data_size value.

---
 hw/i386/pc.c         | 17 ++++++-----------
 hw/i386/pc_piix.c    |  2 +-
 hw/i386/pc_q35.c     |  2 +-
 include/hw/i386/pc.h |  6 ++++--
 4 files changed, 12 insertions(+), 15 deletions(-)
hw/i386/pc.c +6 -11
index 430cd5c..dea41e7 100644
@@ -77,15 +77,6 @@
 #define DPRINTF(fmt, ...)
 #endif
 
-/* Leave a chunk of memory at the top of RAM for the BIOS ACPI tables
- * (128K) and other BIOS datastructures (less than 4K reported to be used at
- * the moment, 32K should be enough for a while).  */
-static unsigned acpi_data_size = 0x20000 + 0x8000;
-void pc_set_legacy_acpi_data_size(void)
-{
-    acpi_data_size = 0x10000;
-}
-
 #define BIOS_CFG_IOPORT 0x510
 #define FW_CFG_ACPI_TABLES (FW_CFG_ARCH_LOCAL + 0)
 #define FW_CFG_SMBIOS_ENTRIES (FW_CFG_ARCH_LOCAL + 1)
@@ -840,6 +831,7 @@ static void load_linux(PCMachineState *pcms,
     FILE *f;
     char *vmode;
     MachineState *machine = MACHINE(pcms);
+    PCMachineClass *pcmc = PC_MACHINE_GET_CLASS(pcms);
     const char *kernel_filename = machine->kernel_filename;
     const char *initrd_filename = machine->initrd_filename;
     const char *kernel_cmdline = machine->kernel_cmdline;
@@ -907,8 +899,8 @@ static void load_linux(PCMachineState *pcms,
         initrd_max = 0x37ffffff;
     }
 
-    if (initrd_max >= pcms->below_4g_mem_size - acpi_data_size) {
-        initrd_max = pcms->below_4g_mem_size - acpi_data_size - 1;
+    if (initrd_max >= pcms->below_4g_mem_size - pcmc->acpi_data_size) {
+        initrd_max = pcms->below_4g_mem_size - pcmc->acpi_data_size - 1;
     }
 
     fw_cfg_add_i32(fw_cfg, FW_CFG_CMDLINE_ADDR, cmdline_addr);
@@ -1959,6 +1951,9 @@ static void pc_machine_class_init(ObjectClass *oc, void *data)
     pcmc->gigabyte_align = true;
     pcmc->has_reserved_memory = true;
     pcmc->kvmclock_enabled = true;
+    /* BIOS ACPI tables: 128K. Other BIOS datastructures: less than 4K reported
+     * to be used at the moment, 32K should be enough for a while.  */
+    pcmc->acpi_data_size = 0x20000 + 0x8000;
     mc->get_hotplug_handler = pc_get_hotpug_handler;
     mc->cpu_index_to_socket_id = pc_cpu_index_to_socket_id;
     mc->default_boot_order = "cad";
hw/i386/pc_piix.c +1 -1
index ea544fa..bfa0e45 100644
@@ -312,7 +312,6 @@ static void pc_compat_2_1(MachineState *machine)
 static void pc_compat_2_0(MachineState *machine)
 {
     pc_compat_2_1(machine);
-    pc_set_legacy_acpi_data_size();
 }
 
 static void pc_compat_1_7(MachineState *machine)
@@ -476,6 +475,7 @@ static void pc_i440fx_2_0_machine_options(MachineClass *m)
      * QEMU 1.7 it is 6414.  For RHEL/CentOS 7.0 it is 6418.
      */
     pcmc->legacy_acpi_table_size = 6652;
+    pcmc->acpi_data_size = 0x10000;
 }
 
 DEFINE_I440FX_MACHINE(v2_0, "pc-i440fx-2.0", pc_compat_2_0,
hw/i386/pc_q35.c +1 -1
index b9e931c..4ee653e 100644
@@ -301,7 +301,6 @@ static void pc_compat_2_1(MachineState *machine)
 static void pc_compat_2_0(MachineState *machine)
 {
     pc_compat_2_1(machine);
-    pc_set_legacy_acpi_data_size();
 }
 
 static void pc_compat_1_7(MachineState *machine)
@@ -406,6 +405,7 @@ static void pc_q35_2_0_machine_options(MachineClass *m)
     SET_MACHINE_COMPAT(m, PC_COMPAT_2_0);
     pcmc->has_reserved_memory = false;
     pcmc->smbios_legacy_mode = true;
+    pcmc->acpi_data_size = 0x10000;
 }
 
 DEFINE_Q35_MACHINE(v2_0, "pc-q35-2.0", pc_compat_2_0,
include/hw/i386/pc.h +4 -2
index b812968..e3ecc21 100644
@@ -76,6 +76,10 @@ struct PCMachineClass {
     bool has_reserved_memory;
     bool kvmclock_enabled;
     int legacy_acpi_table_size;
+    /* Leave a chunk of memory at the top of RAM for the BIOS ACPI tables
+     * and other BIOS datastructures.
+     */
+    unsigned acpi_data_size;
 };
 
 #define TYPE_PC_MACHINE "generic-pc-machine"
@@ -182,8 +186,6 @@ void pc_acpi_init(const char *default_dsdt);
 
 PcGuestInfo *pc_guest_info_init(PCMachineState *pcms);
 
-void pc_set_legacy_acpi_data_size(void);
-
 #define PCI_HOST_PROP_PCI_HOLE_START   "pci-hole-start"
 #define PCI_HOST_PROP_PCI_HOLE_END     "pci-hole-end"
 #define PCI_HOST_PROP_PCI_HOLE64_START "pci-hole64-start"
Signature · 1 line
2.1.0