The branch main has been updated by wulf:

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

commit b8c88a61750174f62db45784d6b4dc98de4073b1
Author:     Vladimir Kondratyev <w...@freebsd.org>
AuthorDate: 2023-12-24 08:20:00 +0000
Commit:     Vladimir Kondratyev <w...@freebsd.org>
CommitDate: 2023-12-24 08:20:00 +0000

    LinuxKPI: Add x86_vendor field to struct cpuinfo_x86
    
    and initialize it at linuxkpi module load.
    
    Sponsored by:   Serenity Cyber Security, LLC
    Reviewed by:    manu
    MFC after:      1 week
    Differential Revision:  https://reviews.freebsd.org/D42820
---
 sys/compat/linuxkpi/common/include/asm/processor.h | 13 +++++++++++++
 sys/compat/linuxkpi/common/src/linux_compat.c      | 21 +++++++++++++++++++++
 2 files changed, 34 insertions(+)

diff --git a/sys/compat/linuxkpi/common/include/asm/processor.h 
b/sys/compat/linuxkpi/common/include/asm/processor.h
index c55238d33505..2bc4b6532544 100644
--- a/sys/compat/linuxkpi/common/include/asm/processor.h
+++ b/sys/compat/linuxkpi/common/include/asm/processor.h
@@ -33,11 +33,24 @@
 #include <machine/cpu.h>
 
 #if defined(__i386__) || defined(__amd64__)
+#define        X86_VENDOR_INTEL        0
+#define        X86_VENDOR_CYRIX        1
+#define        X86_VENDOR_AMD          2
+#define        X86_VENDOR_UMC          3
+#define        X86_VENDOR_CENTAUR      5
+#define        X86_VENDOR_TRANSMETA    7
+#define        X86_VENDOR_NSC          8
+#define        X86_VENDOR_HYGON        9
+#define        X86_VENDOR_NUM          12
+
+#define        X86_VENDOR_UNKNOWN      0xff
+
 struct cpuinfo_x86 {
        uint8_t         x86;
        uint8_t         x86_model;
        uint16_t        x86_clflush_size;
        uint16_t        x86_max_cores;
+       uint8_t         x86_vendor;
 };
 
 extern struct cpuinfo_x86      boot_cpu_data;
diff --git a/sys/compat/linuxkpi/common/src/linux_compat.c 
b/sys/compat/linuxkpi/common/src/linux_compat.c
index 664ba220e721..4a998a557514 100644
--- a/sys/compat/linuxkpi/common/src/linux_compat.c
+++ b/sys/compat/linuxkpi/common/src/linux_compat.c
@@ -63,6 +63,7 @@
 #include <machine/stdarg.h>
 
 #if defined(__i386__) || defined(__amd64__)
+#include <machine/cputypes.h>
 #include <machine/md_var.h>
 #endif
 
@@ -2622,11 +2623,30 @@ linux_compat_init(void *arg)
        int i;
 
 #if defined(__i386__) || defined(__amd64__)
+       static const uint32_t x86_vendors[X86_VENDOR_NUM] = {
+               [X86_VENDOR_INTEL] = CPU_VENDOR_INTEL,
+               [X86_VENDOR_CYRIX] = CPU_VENDOR_CYRIX,
+               [X86_VENDOR_AMD] = CPU_VENDOR_AMD,
+               [X86_VENDOR_UMC] = CPU_VENDOR_UMC,
+               [X86_VENDOR_CENTAUR] = CPU_VENDOR_CENTAUR,
+               [X86_VENDOR_TRANSMETA] = CPU_VENDOR_TRANSMETA,
+               [X86_VENDOR_NSC] = CPU_VENDOR_NSC,
+               [X86_VENDOR_HYGON] = CPU_VENDOR_HYGON,
+       };
+       uint8_t x86_vendor = X86_VENDOR_UNKNOWN;
+
+       for (i = 0; i < X86_VENDOR_NUM; i++) {
+               if (cpu_vendor_id != 0 && cpu_vendor_id == x86_vendors[i]) {
+                       x86_vendor = i;
+                       break;
+               }
+       }
        linux_cpu_has_clflush = (cpu_feature & CPUID_CLFSH);
        boot_cpu_data.x86_clflush_size = cpu_clflush_line_size;
        boot_cpu_data.x86_max_cores = mp_ncpus;
        boot_cpu_data.x86 = CPUID_TO_FAMILY(cpu_id);
        boot_cpu_data.x86_model = CPUID_TO_MODEL(cpu_id);
+       boot_cpu_data.x86_vendor = x86_vendor;
 
        __cpu_data = mallocarray(mp_maxid + 1,
            sizeof(*__cpu_data), M_KMALLOC, M_WAITOK | M_ZERO);
@@ -2635,6 +2655,7 @@ linux_compat_init(void *arg)
                __cpu_data[i].x86_max_cores = mp_ncpus;
                __cpu_data[i].x86 = CPUID_TO_FAMILY(cpu_id);
                __cpu_data[i].x86_model = CPUID_TO_MODEL(cpu_id);
+               __cpu_data[i].x86_vendor = x86_vendor;
        }
 #endif
        rw_init(&linux_vma_lock, "lkpi-vma-lock");

Reply via email to