From: Liu Jingqi <address@hidden>
HMAT is defined in ACPI 6.2: 5.2.27 Heterogeneous Memory Attribute Table (HMAT).
The specification references below link:
http://www.uefi.org/sites/default/files/resources/ACPI_6_2.pdf
It describes the memory attributes, such as memory side cache
attributes and bandwidth and latency details, related to the
System Physical Address (SPA) Memory Ranges. The software is
expected to use this information as hint for optimization.
This structure describes the System Physical Address(SPA) range
occupied by memory subsystem and its associativity with processor
proximity domain as well as hint for memory usage.
Signed-off-by: Liu Jingqi <address@hidden>
Signed-off-by: Tao Xu <address@hidden>
---
Changes in v5 -> v4:
- Add more descriptions from ACPI spec (Igor)
- Remove all the dependcy on PCMachineState (Igor)
---
hw/acpi/Kconfig | 5 ++
hw/acpi/Makefile.objs | 1 +
hw/acpi/hmat.c | 153 ++++++++++++++++++++++++++++++++++++++++++
hw/acpi/hmat.h | 43 ++++++++++++
hw/core/machine.c | 2 +
hw/i386/acpi-build.c | 3 +
include/sysemu/numa.h | 2 +
numa.c | 6 ++
8 files changed, 215 insertions(+)
create mode 100644 hw/acpi/hmat.c
create mode 100644 hw/acpi/hmat.h
diff --git a/hw/acpi/Kconfig b/hw/acpi/Kconfig
index 7c59cf900b..039bb99efa 100644
--- a/hw/acpi/Kconfig
+++ b/hw/acpi/Kconfig
@@ -7,6 +7,7 @@ config ACPI_X86
select ACPI_NVDIMM
select ACPI_CPU_HOTPLUG
select ACPI_MEMORY_HOTPLUG
+ select ACPI_HMAT
config ACPI_X86_ICH
bool
@@ -31,3 +32,7 @@ config ACPI_VMGENID
bool
default y
depends on PC
+
+config ACPI_HMAT
+ bool
+ depends on ACPI
diff --git a/hw/acpi/Makefile.objs b/hw/acpi/Makefile.objs
index 661a9b8c2f..20cc2fb124 100644
--- a/hw/acpi/Makefile.objs
+++ b/hw/acpi/Makefile.objs
@@ -6,6 +6,7 @@ common-obj-$(CONFIG_ACPI_MEMORY_HOTPLUG) += memory_hotplug.o
common-obj-$(CONFIG_ACPI_CPU_HOTPLUG) += cpu.o
common-obj-$(CONFIG_ACPI_NVDIMM) += nvdimm.o
common-obj-$(CONFIG_ACPI_VMGENID) += vmgenid.o
+common-obj-$(CONFIG_ACPI_HMAT) += hmat.o
common-obj-$(call lnot,$(CONFIG_ACPI_X86)) += acpi-stub.o
common-obj-y += acpi_interface.o
diff --git a/hw/acpi/hmat.c b/hw/acpi/hmat.c
new file mode 100644
index 0000000000..6fd434c4d9
--- /dev/null
+++ b/hw/acpi/hmat.c
@@ -0,0 +1,153 @@
+/*
+ * HMAT ACPI Implementation
+ *
+ * Copyright(C) 2019 Intel Corporation.
+ *
+ * Author:
+ * Liu jingqi <address@hidden>
+ * Tao Xu <address@hidden>
+ *
+ * HMAT is defined in ACPI 6.2: 5.2.27 Heterogeneous Memory Attribute Table
+ * (HMAT)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, see <http://www.gnu.org/licenses/>
+ */
+
+#include "qemu/osdep.h"
+#include "sysemu/numa.h"
+#include "hw/acpi/hmat.h"
+#include "hw/mem/pc-dimm.h"
+
+/* ACPI 6.2: 5.2.27.3 Memory Subsystem Address Range Structure: Table 5-141 */
+static void build_hmat_spa(GArray *table_data, uint16_t flags,
+ uint64_t base, uint64_t length, int node)
+{
+
+ /* Memory Subsystem Address Range Structure */
+ /* Type */
+ build_append_int_noprefix(table_data, 0, 2);
+ /* Reserved */
+ build_append_int_noprefix(table_data, 0, 2);
+ /* Length */
+ build_append_int_noprefix(table_data, 40, 4);
+ /* Flags */
+ build_append_int_noprefix(table_data, flags, 2);
+ /* Reserved */
+ build_append_int_noprefix(table_data, 0, 2);
+ /* Process Proximity Domain */
+ build_append_int_noprefix(table_data, node, 4);
+ /* Memory Proximity Domain */
+ build_append_int_noprefix(table_data, node, 4);
+ /* Reserved */
+ build_append_int_noprefix(table_data, 0, 4);
+ /* System Physical Address Range Base */
+ build_append_int_noprefix(table_data, base, 8);
+ /* System Physical Address Range Length */
+ build_append_int_noprefix(table_data, length, 8);
+}
+
+static int pc_dimm_device_list(Object *obj, void *opaque)
+{
+ GSList **list = opaque;
+
+ if (object_dynamic_cast(obj, TYPE_PC_DIMM)) {
+ DeviceState *dev = DEVICE(obj);
+ if (dev->realized) { /* only realized memory devices matter */
+ *list = g_slist_append(*list, DEVICE(obj));
+ }
+ }
+
+ object_child_foreach(obj, pc_dimm_device_list, opaque);
+ return 0;
+}
+
+/* Build HMAT sub table structures */
+static void hmat_build_table_structs(GArray *table_data, MachineState *ms)
+{
+ GSList *device_list = NULL;
+ uint16_t flags;
+ uint64_t mem_base, mem_len;
+ int i;
+ NumaState *nstat = ms->numa_state;
+ NumaMemRange *mem_range;
+
+ Object *obj = object_resolve_path_type("", TYPE_ACPI_DEVICE_IF, NULL);
+ AcpiDeviceIfClass *adevc = ACPI_DEVICE_IF_GET_CLASS(obj);
+ AcpiDeviceIf *adev = ACPI_DEVICE_IF(obj);
+
+ /*
+ * ACPI 6.2: 5.2.27.3 Memory Subsystem Address Range Structure:
+ * Table 5-141. The Proximity Domain of System Physical Address
+ * ranges defined in the HMAT, NFIT and SRAT tables shall match
+ * each other.
+ */
+ if (nstat->num_nodes && !nstat->mem_ranges_num) {
+ nstat->mem_ranges = g_array_new(false, true /* clear */,
+ sizeof *mem_range);
+ adevc->build_mem_ranges(adev, ms);
+ }
+
+ for (i = 0; i < nstat->mem_ranges_num; i++) {
+ mem_range = &g_array_index(nstat->mem_ranges, NumaMemRange, i);
+ flags = 0;
+
+ if (nstat->nodes[mem_range->node].is_initiator) {
+ flags |= HMAT_SPA_PROC_VALID;
+ }
+ if (nstat->nodes[mem_range->node].is_target) {
+ flags |= HMAT_SPA_MEM_VALID;
+ }
+
+ build_hmat_spa(table_data, flags, mem_range->base,
+ mem_range->length,
+ mem_range->node);
+ }
+
+ /* Build HMAT SPA structures for PC-DIMM devices. */
+ object_child_foreach(OBJECT(ms), pc_dimm_device_list, &device_list);
+
+ for (; device_list; device_list = device_list->next) {
+ PCDIMMDevice *dimm = device_list->data;
+ mem_base = object_property_get_uint(OBJECT(dimm), PC_DIMM_ADDR_PROP,
+ NULL);
+ mem_len = object_property_get_uint(OBJECT(dimm), PC_DIMM_SIZE_PROP,
+ NULL);
+ i = object_property_get_uint(OBJECT(dimm), PC_DIMM_NODE_PROP, NULL);
+ flags = 0;
+
+ if (nstat->nodes[i].is_initiator) {
+ flags |= HMAT_SPA_PROC_VALID;
+ }
+ if (nstat->nodes[i].is_target) {
+ flags |= HMAT_SPA_MEM_VALID;
+ }
+ build_hmat_spa(table_data, flags, mem_base, mem_len, i);
+ }