Needed for Windows to use hotplugged memory device, otherwise
it complains that server is not configured for memory hotplug.
Tests shows that aftewards it uses dynamically provided
proximity value from _PXM() method if available.

Signed-off-by: Igor Mammedov <imamm...@redhat.com>
---
 hw/i386/acpi-build.c |   33 +++++++++++++++++++++++++++++++++
 1 files changed, 33 insertions(+), 0 deletions(-)

diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
index 86c1372..ab8e923 100644
--- a/hw/i386/acpi-build.c
+++ b/hw/i386/acpi-build.c
@@ -50,6 +50,7 @@
 
 #include "qapi/qmp/qint.h"
 #include "qom/qom-qobject.h"
+#include "hw/mem/dimm.h"
 
 typedef struct AcpiCpuInfo {
     DECLARE_BITMAP(found_cpus, MAX_CPUMASK_BITS + 1);
@@ -1058,6 +1059,31 @@ acpi_build_srat_memory(AcpiSratMemoryAffinity *numamem, 
uint64_t base,
     numamem->range_length = cpu_to_le64(len);
 }
 
+typedef struct {
+    AcpiSratMemoryAffinity **numamem;
+    GArray *table_data;
+} AcpiSratHotplugMemoryArg;
+
+static int acpi_add_hotplug_memory_region_entry(Object *obj, void *opaque)
+{
+    AcpiSratHotplugMemoryArg *arg = opaque;
+    DimmBus *bus = (DimmBus *)object_dynamic_cast(obj, TYPE_DIMM_BUS);
+
+    if (bus) {
+        uint64_t size = memory_region_size(&bus->as);
+        if (size) {
+            *arg->numamem = acpi_data_push(arg->table_data,
+                                           sizeof **arg->numamem);
+            acpi_build_srat_memory(*arg->numamem, bus->base, size, 0,
+                                   HOT_PLUGGABLE_MEM | ENABLED_MEM);
+        }
+    }
+
+    object_child_foreach(obj, acpi_add_hotplug_memory_region_entry,
+                         opaque);
+   return 0;
+}
+
 static void
 build_srat(GArray *table_data, GArray *linker,
            AcpiCpuInfo *cpu, PcGuestInfo *guest_info)
@@ -1133,6 +1159,13 @@ build_srat(GArray *table_data, GArray *linker,
         acpi_build_srat_memory(numamem, 0, 0, 0, NOFLAGS_MEM);
     }
 
+    {
+        AcpiSratHotplugMemoryArg arg = { .numamem = &numamem,
+                                         .table_data = table_data };
+        object_child_foreach(qdev_get_machine(),
+                             acpi_add_hotplug_memory_region_entry, &arg);
+    }
+
     build_header(linker, table_data,
                  (void *)(table_data->data + srat_start),
                  ACPI_SRAT_SIGNATURE,
-- 
1.7.1


Reply via email to