git: f3ddb82d9a99 - main - LinuxKPI: Add static_cpu_has() implementation

From: Vladimir Kondratyev <wulf_at_FreeBSD.org>
Date: Mon, 10 Jan 2022 19:50:47 UTC
The branch main has been updated by wulf:

URL: https://cgit.FreeBSD.org/src/commit/?id=f3ddb82d9a99d36ea585d034ccbdea1dfc5b1def

commit f3ddb82d9a99d36ea585d034ccbdea1dfc5b1def
Author:     Vladimir Kondratyev <wulf@FreeBSD.org>
AuthorDate: 2021-12-06 10:18:03 +0000
Commit:     Vladimir Kondratyev <wulf@FreeBSD.org>
CommitDate: 2022-01-10 19:49:38 +0000

    LinuxKPI: Add static_cpu_has() implementation
    
    static_cpu_has returns true if CPU supports requested feature.
    
    Obtained from:  OpenBSD
    MFC after:      1 week
    Reviewed by:    hselasky, manu
    Differential Revision:  https://reviews.freebsd.org/D33301
---
 .../linuxkpi/common/include/asm/cpufeature.h       | 37 ++++++++++++++++++++++
 1 file changed, 37 insertions(+)

diff --git a/sys/compat/linuxkpi/common/include/asm/cpufeature.h b/sys/compat/linuxkpi/common/include/asm/cpufeature.h
new file mode 100644
index 000000000000..049088648aa3
--- /dev/null
+++ b/sys/compat/linuxkpi/common/include/asm/cpufeature.h
@@ -0,0 +1,37 @@
+/* Public domain. */
+
+#ifndef _ASM_CPUFEATURE_H
+#define _ASM_CPUFEATURE_H
+
+#if defined(__amd64__) || defined(__i386__)
+
+#include <sys/types.h>
+#include <machine/md_var.h>
+
+#define	X86_FEATURE_CLFLUSH	1
+#define	X86_FEATURE_XMM4_1	2
+#define	X86_FEATURE_PAT		3
+#define	X86_FEATURE_HYPERVISOR	4
+
+static inline bool
+static_cpu_has(uint16_t f)
+{
+	switch (f) {
+	case X86_FEATURE_CLFLUSH:
+		return ((cpu_feature & CPUID_CLFSH) != 0);
+	case X86_FEATURE_XMM4_1:
+		return ((cpu_feature2 & CPUID2_SSE41) != 0);
+	case X86_FEATURE_PAT:
+		return ((cpu_feature & CPUID_PAT) != 0);
+	case X86_FEATURE_HYPERVISOR:
+		return ((cpu_feature2 & CPUID2_HV) != 0);
+	default:
+		return (false);
+	}
+}
+
+#define	boot_cpu_has(x)	static_cpu_has(x)
+
+#endif
+
+#endif