# Commit 350bc1a9d4ebc03b18a43cdafcb626618caace55
# Date 2016-08-04 10:52:49 +0200
# Author Jan Beulich <jbeulich@suse.com>
# Committer Jan Beulich <jbeulich@suse.com>
x86: support newer Intel CPU models

... as per the June 2016 edition of the SDM.

Also remove a couple of dead break statements as well as unused
*MSR_PM_LASTBRANCH* #define-s.

Signed-off-by: Jan Beulich <jbeulich@suse.com>
Acked-by: Andrew Cooper <andrew.cooper3@citrix.com>
Acked-by: Kevin Tian <kevin.tian@intel.com>

--- a/xen/arch/x86/acpi/cpu_idle.c
+++ b/xen/arch/x86/acpi/cpu_idle.c
@@ -145,9 +145,11 @@ static void do_get_hw_residencies(void *
     /* Broadwell */
     case 0x3D:
     case 0x4F:
+    case 0x47:
     case 0x56:
-    /* future */
+    /* Skylake */
     case 0x4E:
+    case 0x5E:
         GET_PC2_RES(hw_res->pc2);
         GET_CC7_RES(hw_res->cc7);
         /* fall through */
--- a/xen/arch/x86/hvm/vmx/vmx.c
+++ b/xen/arch/x86/hvm/vmx/vmx.c
@@ -1922,6 +1922,14 @@ static const struct lbr_info {
     { MSR_P4_LASTBRANCH_0_FROM_LIP, NUM_MSR_P4_LASTBRANCH_FROM_TO },
     { MSR_P4_LASTBRANCH_0_TO_LIP,   NUM_MSR_P4_LASTBRANCH_FROM_TO },
     { 0, 0 }
+}, sk_lbr[] = {
+    { MSR_IA32_LASTINTFROMIP,       1 },
+    { MSR_IA32_LASTINTTOIP,         1 },
+    { MSR_SKL_LASTBRANCH_TOS,       1 },
+    { MSR_SKL_LASTBRANCH_0_FROM_IP, NUM_MSR_SKL_LASTBRANCH },
+    { MSR_SKL_LASTBRANCH_0_TO_IP,   NUM_MSR_SKL_LASTBRANCH },
+    { MSR_SKL_LASTBRANCH_0_INFO,    NUM_MSR_SKL_LASTBRANCH },
+    { 0, 0 }
 }, at_lbr[] = {
     { MSR_IA32_LASTINTFROMIP,       1 },
     { MSR_IA32_LASTINTTOIP,         1 },
@@ -1929,6 +1937,13 @@ static const struct lbr_info {
     { MSR_C2_LASTBRANCH_0_FROM_IP,  NUM_MSR_ATOM_LASTBRANCH_FROM_TO },
     { MSR_C2_LASTBRANCH_0_TO_IP,    NUM_MSR_ATOM_LASTBRANCH_FROM_TO },
     { 0, 0 }
+}, gm_lbr[] = {
+    { MSR_IA32_LASTINTFROMIP,       1 },
+    { MSR_IA32_LASTINTTOIP,         1 },
+    { MSR_GM_LASTBRANCH_TOS,        1 },
+    { MSR_GM_LASTBRANCH_0_FROM_IP,  NUM_MSR_GM_LASTBRANCH_FROM_TO },
+    { MSR_GM_LASTBRANCH_0_TO_IP,    NUM_MSR_GM_LASTBRANCH_FROM_TO },
+    { 0, 0 }
 };
 
 static const struct lbr_info *last_branch_msr_get(void)
@@ -1943,7 +1958,6 @@ static const struct lbr_info *last_branc
         /* Enhanced Core */
         case 23:
             return c2_lbr;
-            break;
         /* Nehalem */
         case 26: case 30: case 31: case 46:
         /* Westmere */
@@ -1955,11 +1969,13 @@ static const struct lbr_info *last_branc
         /* Haswell */
         case 60: case 63: case 69: case 70:
         /* Broadwell */
-        case 61: case 79: case 86:
-        /* future */
-        case 78:
+        case 61: case 71: case 79: case 86:
             return nh_lbr;
-            break;
+        /* Skylake */
+        case 78: case 94:
+        /* future */
+        case 142: case 158:
+            return sk_lbr;
         /* Atom */
         case 28: case 38: case 39: case 53: case 54:
         /* Silvermont */
@@ -1969,7 +1985,9 @@ static const struct lbr_info *last_branc
         /* Airmont */
         case 76:
             return at_lbr;
-            break;
+        /* Goldmont */
+        case 92: case 95:
+            return gm_lbr;
         }
         break;
 
@@ -1979,7 +1997,6 @@ static const struct lbr_info *last_branc
         /* Pentium4/Xeon with em64t */
         case 3: case 4: case 6:
             return p4_lbr;
-            break;
         }
         break;
     }
--- a/xen/arch/x86/hvm/vmx/vpmu_core2.c
+++ b/xen/arch/x86/hvm/vmx/vpmu_core2.c
@@ -917,11 +917,15 @@ int vmx_vpmu_initialise(struct vcpu *v,
 
         /* Broadwell */
         case 0x3d:
+        case 0x47:
         case 0x4f:
         case 0x56:
 
-        /* future: */
-        case 0x4e:
+        /* Skylake */
+        case 0x4e: case 0x5e:
+
+        /* future */
+        case 0x8e: case 0x9e:
 
         /* next gen Xeon Phi */
         case 0x57:
--- a/xen/include/asm-x86/msr-index.h
+++ b/xen/include/asm-x86/msr-index.h
@@ -454,11 +454,6 @@
 #define MSR_P4_LASTBRANCH_0_TO_LIP	0x000006c0
 #define NUM_MSR_P4_LASTBRANCH_FROM_TO	16
 
-/* Pentium M (and Core) last-branch recording */
-#define MSR_PM_LASTBRANCH_TOS		0x000001c9
-#define MSR_PM_LASTBRANCH_0		0x00000040
-#define NUM_MSR_PM_LASTBRANCH		8
-
 /* Core 2 and Atom last-branch recording */
 #define MSR_C2_LASTBRANCH_TOS		0x000001c9
 #define MSR_C2_LASTBRANCH_0_FROM_IP	0x00000040
@@ -466,6 +461,19 @@
 #define NUM_MSR_C2_LASTBRANCH_FROM_TO	4
 #define NUM_MSR_ATOM_LASTBRANCH_FROM_TO	8
 
+/* Skylake (and newer) last-branch recording */
+#define MSR_SKL_LASTBRANCH_TOS		0x000001c9
+#define MSR_SKL_LASTBRANCH_0_FROM_IP	0x00000680
+#define MSR_SKL_LASTBRANCH_0_TO_IP	0x000006c0
+#define MSR_SKL_LASTBRANCH_0_INFO	0x00000dc0
+#define NUM_MSR_SKL_LASTBRANCH		32
+
+/* Goldmont last-branch recording */
+#define MSR_GM_LASTBRANCH_TOS		0x000001c9
+#define MSR_GM_LASTBRANCH_0_FROM_IP	0x00000680
+#define MSR_GM_LASTBRANCH_0_TO_IP	0x000006c0
+#define NUM_MSR_GM_LASTBRANCH_FROM_TO	32
+
 /* Intel Core-based CPU performance counters */
 #define MSR_CORE_PERF_FIXED_CTR0	0x00000309
 #define MSR_CORE_PERF_FIXED_CTR1	0x0000030a
