1 // SPDX-License-Identifier: GPL-2.0-only
2 /* Copyright(c) 2022 Intel Corporation. */
4 #include <linux/bitfield.h>
5 #include <linux/module.h>
6 #include <linux/kdev_t.h>
7 #include <linux/semaphore.h>
8 #include <linux/slab.h>
10 #include <asm/cpu_device_id.h>
14 #define X86_MATCH(model, array_gen) \
15 X86_MATCH_VENDOR_FAM_MODEL_FEATURE(INTEL, 6, \
16 INTEL_FAM6_##model, X86_FEATURE_CORE_CAPABILITIES, array_gen)
18 static const struct x86_cpu_id ifs_cpu_ids[] __initconst = {
19 X86_MATCH(SAPPHIRERAPIDS_X, ARRAY_GEN0),
20 X86_MATCH(EMERALDRAPIDS_X, ARRAY_GEN0),
21 X86_MATCH(GRANITERAPIDS_X, ARRAY_GEN0),
22 X86_MATCH(GRANITERAPIDS_D, ARRAY_GEN0),
23 X86_MATCH(ATOM_CRESTMONT_X, ARRAY_GEN1),
26 MODULE_DEVICE_TABLE(x86cpu, ifs_cpu_ids);
28 ATTRIBUTE_GROUPS(plat_ifs);
29 ATTRIBUTE_GROUPS(plat_ifs_array);
33 static const struct ifs_test_caps scan_test = {
34 .integrity_cap_bit = MSR_INTEGRITY_CAPS_PERIODIC_BIST_BIT,
35 .test_num = IFS_TYPE_SAF,
38 static const struct ifs_test_caps array_test = {
39 .integrity_cap_bit = MSR_INTEGRITY_CAPS_ARRAY_BIST_BIT,
40 .test_num = IFS_TYPE_ARRAY_BIST,
43 static struct ifs_device ifs_devices[] = {
45 .test_caps = &scan_test,
47 .name = "intel_ifs_0",
48 .minor = MISC_DYNAMIC_MINOR,
49 .groups = plat_ifs_groups,
52 [IFS_TYPE_ARRAY_BIST] = {
53 .test_caps = &array_test,
55 .name = "intel_ifs_1",
56 .minor = MISC_DYNAMIC_MINOR,
57 .groups = plat_ifs_array_groups,
62 #define IFS_NUMTESTS ARRAY_SIZE(ifs_devices)
64 static void ifs_cleanup(void)
68 for (i = 0; i < IFS_NUMTESTS; i++) {
69 if (ifs_devices[i].misc.this_device)
70 misc_deregister(&ifs_devices[i].misc);
75 static int __init ifs_init(void)
77 const struct x86_cpu_id *m;
81 m = x86_match_cpu(ifs_cpu_ids);
85 if (rdmsrl_safe(MSR_IA32_CORE_CAPS, &msrval))
88 if (!(msrval & MSR_IA32_CORE_CAPS_INTEGRITY_CAPS))
91 if (rdmsrl_safe(MSR_INTEGRITY_CAPS, &msrval))
94 ifs_pkg_auth = kmalloc_array(topology_max_packages(), sizeof(bool), GFP_KERNEL);
98 for (i = 0; i < IFS_NUMTESTS; i++) {
99 if (!(msrval & BIT(ifs_devices[i].test_caps->integrity_cap_bit)))
101 ifs_devices[i].rw_data.generation = FIELD_GET(MSR_INTEGRITY_CAPS_SAF_GEN_MASK,
103 ifs_devices[i].rw_data.array_gen = (u32)m->driver_data;
104 ret = misc_register(&ifs_devices[i].misc);
115 static void __exit ifs_exit(void)
120 module_init(ifs_init);
121 module_exit(ifs_exit);
123 MODULE_LICENSE("GPL");
124 MODULE_DESCRIPTION("Intel In Field Scan (IFS) device");