From 3a383b21e3611b9cfb66d04fa2d340fd904869f3 Mon Sep 17 00:00:00 2001
From: Stefan Lankes <slankes@eonerc.rwth-aachen.de>
Date: Fri, 10 Mar 2017 09:05:12 +0100
Subject: [PATCH] add check for avx512bw and avx512vl

---
 arch/x86/include/asm/processor.h | 15 +++++++++++++++
 arch/x86/kernel/processor.c      |  7 +++++--
 2 files changed, 20 insertions(+), 2 deletions(-)

diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h
index 8f42a5413..24ae11b78 100644
--- a/arch/x86/include/asm/processor.h
+++ b/arch/x86/include/asm/processor.h
@@ -90,6 +90,7 @@ extern "C" {
 // feature list 0x00000007:0
 #define CPU_FEATURE_FSGSBASE			(1 << 0)
 #define CPU_FEATURE_TSC_ADJUST			(1 << 1)
+#define CPU_FEATURE_SGX			(1 << 2)
 #define CPU_FEATURE_BMI1			(1 << 3)
 #define CPU_FEATURE_HLE				(1 << 4)
 #define CPU_FEATURE_AVX2			(1 << 5)
@@ -111,6 +112,8 @@ extern "C" {
 #define CPU_FEATURE_AVX512ER			(1 << 27)
 #define CPU_FEATURE_AVX512CD			(1 << 28)
 #define CPU_FEATURE_SHA_NI			(1 << 29)
+#define CPU_FEATURE_AVX512BW		(1 << 30)
+#define CPU_FEATURE_AVX512VL		(1 <<31)
 
 // feature list 0x00000006
 #define CPU_FEATURE_IDA				(1 << 0)
@@ -408,6 +411,10 @@ inline static uint32_t has_fsgsbase(void) {
 	return (cpu_info.feature4 & CPU_FEATURE_FSGSBASE);
 }
 
+inline static uint32_t has_sgx(void) {
+	return (cpu_info.feature4 & CPU_FEATURE_SGX);
+}
+
 inline static uint32_t has_avx2(void) {
 	return (cpu_info.feature4 & CPU_FEATURE_AVX2);
 }
@@ -456,6 +463,14 @@ inline static uint32_t has_avx512cd(void) {
 	return (cpu_info.feature4 & CPU_FEATURE_AVX512CD);
 }
 
+inline static uint32_t has_avx512bw(void) {
+	return (cpu_info.feature4 & CPU_FEATURE_AVX512BW);
+}
+
+inline static uint32_t has_avx512vl(void) {
+	return (cpu_info.feature4 & CPU_FEATURE_AVX512VL);
+}
+
 inline static uint32_t has_rdtscp(void) {
 	return (cpu_info.feature3 & CPU_FEATURE_RDTSCP);
 }
diff --git a/arch/x86/kernel/processor.c b/arch/x86/kernel/processor.c
index 01b0bbfe3..1c3eeafe2 100644
--- a/arch/x86/kernel/processor.c
+++ b/arch/x86/kernel/processor.c
@@ -553,7 +553,7 @@ int cpu_detection(void) {
 		a = b = c = d = 0;
                 cpuid(1, &a, &b, &cpu_info.feature2, &cpu_info.feature1);
 
-		LOG_INFO("CPU features: %s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s\n",
+		LOG_INFO("CPU features: %s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s\n",
 			has_sse() ? "SSE " : "",
 			has_sse2() ? "SSE2 " : "",
 			has_sse3() ? "SSE3 " : "",
@@ -572,6 +572,7 @@ int cpu_detection(void) {
 			has_vmx() ? "VMX " : "",
 			has_rdtscp() ? "RDTSCP " : "",
 			has_fsgsbase() ? "FSGSBASE " : "",
+			has_sgx() ? "SGX " : "",
 			has_mwait() ? "MWAIT " : "",
 			has_clflush() ? "CLFLUSH " : "",
 			has_bmi1() ? "BMI1 " : "",
@@ -585,7 +586,9 @@ int cpu_detection(void) {
 			has_avx512f() ? "AVX512F " : "",
 			has_avx512cd() ? "AVX512CD " : "",
 			has_avx512pf() ? "AVX512PF " : "",
-			has_avx512er() ? "AVX512ER " : "");
+			has_avx512er() ? "AVX512ER " : "",
+			has_avx512vl() ? "AVX512VL " : "",
+			has_avx512bw() ? "AVX512BW " : "");
 	}
 
 	if (first_time && has_osxsave()) {