Blame SOURCES/kvm-i386-Add-support-for-CPUID_8000_001E-for-AMD.patch

1bdc94
From 31d4822f7d25e9438de3dc7d689cfe3dd5544cc7 Mon Sep 17 00:00:00 2001
1bdc94
From: Eduardo Habkost <ehabkost@redhat.com>
1bdc94
Date: Tue, 3 Jul 2018 17:23:53 +0200
1bdc94
Subject: [PATCH 08/89] i386: Add support for CPUID_8000_001E for AMD
1bdc94
1bdc94
RH-Author: Eduardo Habkost <ehabkost@redhat.com>
1bdc94
Message-id: <20180703172356.21038-8-ehabkost@redhat.com>
1bdc94
Patchwork-id: 81217
1bdc94
O-Subject: [RHEL-7.6 qemu-kvm-rhev PATCH v3 07/10] i386: Add support for CPUID_8000_001E for AMD
1bdc94
Bugzilla: 1481253
1bdc94
RH-Acked-by: Laurent Vivier <lvivier@redhat.com>
1bdc94
RH-Acked-by: Igor Mammedov <imammedo@redhat.com>
1bdc94
RH-Acked-by: Miroslav Rezanina <mrezanin@redhat.com>
1bdc94
1bdc94
From: Babu Moger <babu.moger@amd.com>
1bdc94
1bdc94
Add support for cpuid leaf CPUID_8000_001E. Build the config that closely
1bdc94
match the underlying hardware. Please refer to the Processor Programming
1bdc94
Reference (PPR) for AMD Family 17h Model for more details.
1bdc94
1bdc94
Signed-off-by: Babu Moger <babu.moger@amd.com>
1bdc94
Message-Id: <1528498581-131037-2-git-send-email-babu.moger@amd.com>
1bdc94
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
1bdc94
(cherry picked from commit ed78467a214595a63af7800a073a03ffe37cd7db)
1bdc94
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
1bdc94
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
1bdc94
---
1bdc94
 target/i386/cpu.c | 86 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
1bdc94
 1 file changed, 86 insertions(+)
1bdc94
1bdc94
diff --git a/target/i386/cpu.c b/target/i386/cpu.c
1bdc94
index 57f74c6..643d3b1 100644
1bdc94
--- a/target/i386/cpu.c
1bdc94
+++ b/target/i386/cpu.c
1bdc94
@@ -429,6 +429,87 @@ static void encode_cache_cpuid8000001d(CPUCacheInfo *cache, CPUState *cs,
1bdc94
            (cache->complex_indexing ? CACHE_COMPLEX_IDX : 0);
1bdc94
 }
1bdc94
 
1bdc94
+/* Data structure to hold the configuration info for a given core index */
1bdc94
+struct core_topology {
1bdc94
+    /* core complex id of the current core index */
1bdc94
+    int ccx_id;
1bdc94
+    /*
1bdc94
+     * Adjusted core index for this core in the topology
1bdc94
+     * This can be 0,1,2,3 with max 4 cores in a core complex
1bdc94
+     */
1bdc94
+    int core_id;
1bdc94
+    /* Node id for this core index */
1bdc94
+    int node_id;
1bdc94
+    /* Number of nodes in this config */
1bdc94
+    int num_nodes;
1bdc94
+};
1bdc94
+
1bdc94
+/*
1bdc94
+ * Build the configuration closely match the EPYC hardware. Using the EPYC
1bdc94
+ * hardware configuration values (MAX_CCX, MAX_CORES_IN_CCX, MAX_CORES_IN_NODE)
1bdc94
+ * right now. This could change in future.
1bdc94
+ * nr_cores : Total number of cores in the config
1bdc94
+ * core_id  : Core index of the current CPU
1bdc94
+ * topo     : Data structure to hold all the config info for this core index
1bdc94
+ */
1bdc94
+static void build_core_topology(int nr_cores, int core_id,
1bdc94
+                                struct core_topology *topo)
1bdc94
+{
1bdc94
+    int nodes, cores_in_ccx;
1bdc94
+
1bdc94
+    /* First get the number of nodes required */
1bdc94
+    nodes = nodes_in_socket(nr_cores);
1bdc94
+
1bdc94
+    cores_in_ccx = cores_in_core_complex(nr_cores);
1bdc94
+
1bdc94
+    topo->node_id = core_id / (cores_in_ccx * MAX_CCX);
1bdc94
+    topo->ccx_id = (core_id % (cores_in_ccx * MAX_CCX)) / cores_in_ccx;
1bdc94
+    topo->core_id = core_id % cores_in_ccx;
1bdc94
+    topo->num_nodes = nodes;
1bdc94
+}
1bdc94
+
1bdc94
+/* Encode cache info for CPUID[8000001E] */
1bdc94
+static void encode_topo_cpuid8000001e(CPUState *cs, X86CPU *cpu,
1bdc94
+                                       uint32_t *eax, uint32_t *ebx,
1bdc94
+                                       uint32_t *ecx, uint32_t *edx)
1bdc94
+{
1bdc94
+    struct core_topology topo = {0};
1bdc94
+
1bdc94
+    build_core_topology(cs->nr_cores, cpu->core_id, &topo;;
1bdc94
+    *eax = cpu->apic_id;
1bdc94
+    /*
1bdc94
+     * CPUID_Fn8000001E_EBX
1bdc94
+     * 31:16 Reserved
1bdc94
+     * 15:8  Threads per core (The number of threads per core is
1bdc94
+     *       Threads per core + 1)
1bdc94
+     *  7:0  Core id (see bit decoding below)
1bdc94
+     *       SMT:
1bdc94
+     *           4:3 node id
1bdc94
+     *             2 Core complex id
1bdc94
+     *           1:0 Core id
1bdc94
+     *       Non SMT:
1bdc94
+     *           5:4 node id
1bdc94
+     *             3 Core complex id
1bdc94
+     *           1:0 Core id
1bdc94
+     */
1bdc94
+    if (cs->nr_threads - 1) {
1bdc94
+        *ebx = ((cs->nr_threads - 1) << 8) | (topo.node_id << 3) |
1bdc94
+                (topo.ccx_id << 2) | topo.core_id;
1bdc94
+    } else {
1bdc94
+        *ebx = (topo.node_id << 4) | (topo.ccx_id << 3) | topo.core_id;
1bdc94
+    }
1bdc94
+    /*
1bdc94
+     * CPUID_Fn8000001E_ECX
1bdc94
+     * 31:11 Reserved
1bdc94
+     * 10:8  Nodes per processor (Nodes per processor is number of nodes + 1)
1bdc94
+     *  7:0  Node id (see bit decoding below)
1bdc94
+     *         2  Socket id
1bdc94
+     *       1:0  Node id
1bdc94
+     */
1bdc94
+    *ecx = ((topo.num_nodes - 1) << 8) | (cpu->socket_id << 2) | topo.node_id;
1bdc94
+    *edx = 0;
1bdc94
+}
1bdc94
+
1bdc94
 /*
1bdc94
  * Definitions of the hardcoded cache entries we expose:
1bdc94
  * These are legacy cache values. If there is a need to change any
1bdc94
@@ -4105,6 +4186,11 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index, uint32_t count,
1bdc94
             break;
1bdc94
         }
1bdc94
         break;
1bdc94
+    case 0x8000001E:
1bdc94
+        assert(cpu->core_id <= 255);
1bdc94
+        encode_topo_cpuid8000001e(cs, cpu,
1bdc94
+                                  eax, ebx, ecx, edx);
1bdc94
+        break;
1bdc94
     case 0xC0000000:
1bdc94
         *eax = env->cpuid_xlevel2;
1bdc94
         *ebx = 0;
1bdc94
-- 
1bdc94
1.8.3.1
1bdc94