Blame SOURCES/kvm-hmat-acpi-Build-Memory-Proximity-Domain-Attributes-S.patch

ddf19c
From a0816e4374759048cb24b9b3549a093a2ccb6240 Mon Sep 17 00:00:00 2001
ddf19c
From: "plai@redhat.com" <plai@redhat.com>
ddf19c
Date: Thu, 21 May 2020 23:56:50 +0100
ddf19c
Subject: [PATCH 07/12] hmat acpi: Build Memory Proximity Domain Attributes
ddf19c
 Structure(s)
ddf19c
ddf19c
RH-Author: plai@redhat.com
ddf19c
Message-id: <20200521235655.27141-7-plai@redhat.com>
ddf19c
Patchwork-id: 96734
ddf19c
O-Subject: [RHEL8.2.1 AV qemu-kvm PATCH 06/11] hmat acpi: Build Memory Proximity Domain Attributes Structure(s)
ddf19c
Bugzilla: 1600217
ddf19c
RH-Acked-by: Michael S. Tsirkin <mst@redhat.com>
ddf19c
RH-Acked-by: Igor Mammedov <imammedo@redhat.com>
ddf19c
RH-Acked-by: Eduardo Habkost <ehabkost@redhat.com>
ddf19c
ddf19c
From: Liu Jingqi <jingqi.liu@intel.com>
ddf19c
ddf19c
HMAT is defined in ACPI 6.3: 5.2.27 Heterogeneous Memory Attribute Table
ddf19c
(HMAT). The specification references below link:
ddf19c
http://www.uefi.org/sites/default/files/resources/ACPI_6_3_final_Jan30.pdf
ddf19c
ddf19c
It describes the memory attributes, such as memory side cache
ddf19c
attributes and bandwidth and latency details, related to the
ddf19c
Memory Proximity Domain. The software is
ddf19c
expected to use this information as hint for optimization.
ddf19c
ddf19c
This structure describes Memory Proximity Domain Attributes by memory
ddf19c
subsystem and its associativity with processor proximity domain as well as
ddf19c
hint for memory usage.
ddf19c
ddf19c
In the linux kernel, the codes in drivers/acpi/hmat/hmat.c parse and report
ddf19c
the platform's HMAT tables.
ddf19c
ddf19c
Acked-by: Markus Armbruster <armbru@redhat.com>
ddf19c
Reviewed-by: Igor Mammedov <imammedo@redhat.com>
ddf19c
Reviewed-by: Daniel Black <daniel@linux.ibm.com>
ddf19c
Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
ddf19c
Signed-off-by: Liu Jingqi <jingqi.liu@intel.com>
ddf19c
Signed-off-by: Tao Xu <tao3.xu@intel.com>
ddf19c
Message-Id: <20191213011929.2520-5-tao3.xu@intel.com>
ddf19c
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
ddf19c
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
ddf19c
(cherry picked from commit e6f123c3b81241be33f1b763d0ff8b36d1ae9c1e)
ddf19c
Signed-off-by: Paul Lai <plai@redhat.com>
ddf19c
Signed-off-by: Danilo C. L. de Paula <ddepaula@redhat.com>
ddf19c
---
ddf19c
 hw/acpi/Kconfig       |  7 ++--
ddf19c
 hw/acpi/Makefile.objs |  1 +
ddf19c
 hw/acpi/hmat.c        | 99 +++++++++++++++++++++++++++++++++++++++++++++++++++
ddf19c
 hw/acpi/hmat.h        | 42 ++++++++++++++++++++++
ddf19c
 hw/i386/acpi-build.c  |  5 +++
ddf19c
 5 files changed, 152 insertions(+), 2 deletions(-)
ddf19c
 create mode 100644 hw/acpi/hmat.c
ddf19c
 create mode 100644 hw/acpi/hmat.h
ddf19c
ddf19c
diff --git a/hw/acpi/Kconfig b/hw/acpi/Kconfig
ddf19c
index 12e3f1e..54209c6 100644
ddf19c
--- a/hw/acpi/Kconfig
ddf19c
+++ b/hw/acpi/Kconfig
ddf19c
@@ -7,6 +7,7 @@ config ACPI_X86
ddf19c
     select ACPI_NVDIMM
ddf19c
     select ACPI_CPU_HOTPLUG
ddf19c
     select ACPI_MEMORY_HOTPLUG
ddf19c
+    select ACPI_HMAT
ddf19c
 
ddf19c
 config ACPI_X86_ICH
ddf19c
     bool
ddf19c
@@ -23,6 +24,10 @@ config ACPI_NVDIMM
ddf19c
     bool
ddf19c
     depends on ACPI
ddf19c
 
ddf19c
+config ACPI_HMAT
ddf19c
+    bool
ddf19c
+    depends on ACPI
ddf19c
+
ddf19c
 config ACPI_PCI
ddf19c
     bool
ddf19c
     depends on ACPI && PCI
ddf19c
@@ -33,5 +38,3 @@ config ACPI_VMGENID
ddf19c
     depends on PC
ddf19c
 
ddf19c
 config ACPI_HW_REDUCED
ddf19c
-    bool
ddf19c
-    depends on ACPI
ddf19c
diff --git a/hw/acpi/Makefile.objs b/hw/acpi/Makefile.objs
ddf19c
index 655a9c1..517bd88 100644
ddf19c
--- a/hw/acpi/Makefile.objs
ddf19c
+++ b/hw/acpi/Makefile.objs
ddf19c
@@ -7,6 +7,7 @@ common-obj-$(CONFIG_ACPI_CPU_HOTPLUG) += cpu.o
ddf19c
 common-obj-$(CONFIG_ACPI_NVDIMM) += nvdimm.o
ddf19c
 common-obj-$(CONFIG_ACPI_VMGENID) += vmgenid.o
ddf19c
 common-obj-$(CONFIG_ACPI_HW_REDUCED) += generic_event_device.o
ddf19c
+common-obj-$(CONFIG_ACPI_HMAT) += hmat.o
ddf19c
 common-obj-$(call lnot,$(CONFIG_ACPI_X86)) += acpi-stub.o
ddf19c
 
ddf19c
 common-obj-y += acpi_interface.o
ddf19c
diff --git a/hw/acpi/hmat.c b/hw/acpi/hmat.c
ddf19c
new file mode 100644
ddf19c
index 0000000..9ff7930
ddf19c
--- /dev/null
ddf19c
+++ b/hw/acpi/hmat.c
ddf19c
@@ -0,0 +1,99 @@
ddf19c
+/*
ddf19c
+ * HMAT ACPI Implementation
ddf19c
+ *
ddf19c
+ * Copyright(C) 2019 Intel Corporation.
ddf19c
+ *
ddf19c
+ * Author:
ddf19c
+ *  Liu jingqi <jingqi.liu@linux.intel.com>
ddf19c
+ *  Tao Xu <tao3.xu@intel.com>
ddf19c
+ *
ddf19c
+ * HMAT is defined in ACPI 6.3: 5.2.27 Heterogeneous Memory Attribute Table
ddf19c
+ * (HMAT)
ddf19c
+ *
ddf19c
+ * This library is free software; you can redistribute it and/or
ddf19c
+ * modify it under the terms of the GNU Lesser General Public
ddf19c
+ * License as published by the Free Software Foundation; either
ddf19c
+ * version 2 of the License, or (at your option) any later version.
ddf19c
+ *
ddf19c
+ * This library is distributed in the hope that it will be useful,
ddf19c
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
ddf19c
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
ddf19c
+ * Lesser General Public License for more details.
ddf19c
+ *
ddf19c
+ * You should have received a copy of the GNU Lesser General Public
ddf19c
+ * License along with this library; if not, see <http://www.gnu.org/licenses/>
ddf19c
+ */
ddf19c
+
ddf19c
+#include "qemu/osdep.h"
ddf19c
+#include "sysemu/numa.h"
ddf19c
+#include "hw/acpi/hmat.h"
ddf19c
+
ddf19c
+/*
ddf19c
+ * ACPI 6.3:
ddf19c
+ * 5.2.27.3 Memory Proximity Domain Attributes Structure: Table 5-145
ddf19c
+ */
ddf19c
+static void build_hmat_mpda(GArray *table_data, uint16_t flags,
ddf19c
+                            uint32_t initiator, uint32_t mem_node)
ddf19c
+{
ddf19c
+
ddf19c
+    /* Memory Proximity Domain Attributes Structure */
ddf19c
+    /* Type */
ddf19c
+    build_append_int_noprefix(table_data, 0, 2);
ddf19c
+    /* Reserved */
ddf19c
+    build_append_int_noprefix(table_data, 0, 2);
ddf19c
+    /* Length */
ddf19c
+    build_append_int_noprefix(table_data, 40, 4);
ddf19c
+    /* Flags */
ddf19c
+    build_append_int_noprefix(table_data, flags, 2);
ddf19c
+    /* Reserved */
ddf19c
+    build_append_int_noprefix(table_data, 0, 2);
ddf19c
+    /* Proximity Domain for the Attached Initiator */
ddf19c
+    build_append_int_noprefix(table_data, initiator, 4);
ddf19c
+    /* Proximity Domain for the Memory */
ddf19c
+    build_append_int_noprefix(table_data, mem_node, 4);
ddf19c
+    /* Reserved */
ddf19c
+    build_append_int_noprefix(table_data, 0, 4);
ddf19c
+    /*
ddf19c
+     * Reserved:
ddf19c
+     * Previously defined as the Start Address of the System Physical
ddf19c
+     * Address Range. Deprecated since ACPI Spec 6.3.
ddf19c
+     */
ddf19c
+    build_append_int_noprefix(table_data, 0, 8);
ddf19c
+    /*
ddf19c
+     * Reserved:
ddf19c
+     * Previously defined as the Range Length of the region in bytes.
ddf19c
+     * Deprecated since ACPI Spec 6.3.
ddf19c
+     */
ddf19c
+    build_append_int_noprefix(table_data, 0, 8);
ddf19c
+}
ddf19c
+
ddf19c
+/* Build HMAT sub table structures */
ddf19c
+static void hmat_build_table_structs(GArray *table_data, NumaState *numa_state)
ddf19c
+{
ddf19c
+    uint16_t flags;
ddf19c
+    int i;
ddf19c
+
ddf19c
+    for (i = 0; i < numa_state->num_nodes; i++) {
ddf19c
+        flags = 0;
ddf19c
+
ddf19c
+        if (numa_state->nodes[i].initiator < MAX_NODES) {
ddf19c
+            flags |= HMAT_PROXIMITY_INITIATOR_VALID;
ddf19c
+        }
ddf19c
+
ddf19c
+        build_hmat_mpda(table_data, flags, numa_state->nodes[i].initiator, i);
ddf19c
+    }
ddf19c
+}
ddf19c
+
ddf19c
+void build_hmat(GArray *table_data, BIOSLinker *linker, NumaState *numa_state)
ddf19c
+{
ddf19c
+    int hmat_start = table_data->len;
ddf19c
+
ddf19c
+    /* reserve space for HMAT header  */
ddf19c
+    acpi_data_push(table_data, 40);
ddf19c
+
ddf19c
+    hmat_build_table_structs(table_data, numa_state);
ddf19c
+
ddf19c
+    build_header(linker, table_data,
ddf19c
+                 (void *)(table_data->data + hmat_start),
ddf19c
+                 "HMAT", table_data->len - hmat_start, 2, NULL, NULL);
ddf19c
+}
ddf19c
diff --git a/hw/acpi/hmat.h b/hw/acpi/hmat.h
ddf19c
new file mode 100644
ddf19c
index 0000000..437dbc6
ddf19c
--- /dev/null
ddf19c
+++ b/hw/acpi/hmat.h
ddf19c
@@ -0,0 +1,42 @@
ddf19c
+/*
ddf19c
+ * HMAT ACPI Implementation Header
ddf19c
+ *
ddf19c
+ * Copyright(C) 2019 Intel Corporation.
ddf19c
+ *
ddf19c
+ * Author:
ddf19c
+ *  Liu jingqi <jingqi.liu@linux.intel.com>
ddf19c
+ *  Tao Xu <tao3.xu@intel.com>
ddf19c
+ *
ddf19c
+ * HMAT is defined in ACPI 6.3: 5.2.27 Heterogeneous Memory Attribute Table
ddf19c
+ * (HMAT)
ddf19c
+ *
ddf19c
+ * This library is free software; you can redistribute it and/or
ddf19c
+ * modify it under the terms of the GNU Lesser General Public
ddf19c
+ * License as published by the Free Software Foundation; either
ddf19c
+ * version 2 of the License, or (at your option) any later version.
ddf19c
+ *
ddf19c
+ * This library is distributed in the hope that it will be useful,
ddf19c
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
ddf19c
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
ddf19c
+ * Lesser General Public License for more details.
ddf19c
+ *
ddf19c
+ * You should have received a copy of the GNU Lesser General Public
ddf19c
+ * License along with this library; if not, see <http://www.gnu.org/licenses/>
ddf19c
+ */
ddf19c
+
ddf19c
+#ifndef HMAT_H
ddf19c
+#define HMAT_H
ddf19c
+
ddf19c
+#include "hw/acpi/aml-build.h"
ddf19c
+
ddf19c
+/*
ddf19c
+ * ACPI 6.3: 5.2.27.3 Memory Proximity Domain Attributes Structure,
ddf19c
+ * Table 5-145, Field "flag", Bit [0]: set to 1 to indicate that data in
ddf19c
+ * the Proximity Domain for the Attached Initiator field is valid.
ddf19c
+ * Other bits reserved.
ddf19c
+ */
ddf19c
+#define HMAT_PROXIMITY_INITIATOR_VALID  0x1
ddf19c
+
ddf19c
+void build_hmat(GArray *table_data, BIOSLinker *linker, NumaState *numa_state);
ddf19c
+
ddf19c
+#endif
ddf19c
diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
ddf19c
index 6400189..b1f8c55 100644
ddf19c
--- a/hw/i386/acpi-build.c
ddf19c
+++ b/hw/i386/acpi-build.c
ddf19c
@@ -67,6 +67,7 @@
ddf19c
 #include "hw/i386/intel_iommu.h"
ddf19c
 
ddf19c
 #include "hw/acpi/ipmi.h"
ddf19c
+#include "hw/acpi/hmat.h"
ddf19c
 
ddf19c
 /* These are used to size the ACPI tables for -M pc-i440fx-1.7 and
ddf19c
  * -M pc-i440fx-2.0.  Even if the actual amount of AML generated grows
ddf19c
@@ -2837,6 +2838,10 @@ void acpi_build(AcpiBuildTables *tables, MachineState *machine)
ddf19c
             acpi_add_table(table_offsets, tables_blob);
ddf19c
             build_slit(tables_blob, tables->linker, machine);
ddf19c
         }
ddf19c
+        if (machine->numa_state->hmat_enabled) {
ddf19c
+            acpi_add_table(table_offsets, tables_blob);
ddf19c
+            build_hmat(tables_blob, tables->linker, machine->numa_state);
ddf19c
+        }
ddf19c
     }
ddf19c
     if (acpi_get_mcfg(&mcfg)) {
ddf19c
         acpi_add_table(table_offsets, tables_blob);
ddf19c
-- 
ddf19c
1.8.3.1
ddf19c