0001
0002
0003
0004 #include <linux/module.h>
0005 #include <linux/kdev_t.h>
0006 #include <linux/semaphore.h>
0007
0008 #include <asm/cpu_device_id.h>
0009
0010 #include "ifs.h"
0011
0012 #define X86_MATCH(model) \
0013 X86_MATCH_VENDOR_FAM_MODEL_FEATURE(INTEL, 6, \
0014 INTEL_FAM6_##model, X86_FEATURE_CORE_CAPABILITIES, NULL)
0015
0016 static const struct x86_cpu_id ifs_cpu_ids[] __initconst = {
0017 X86_MATCH(SAPPHIRERAPIDS_X),
0018 {}
0019 };
0020 MODULE_DEVICE_TABLE(x86cpu, ifs_cpu_ids);
0021
0022 static struct ifs_device ifs_device = {
0023 .data = {
0024 .integrity_cap_bit = MSR_INTEGRITY_CAPS_PERIODIC_BIST_BIT,
0025 },
0026 .misc = {
0027 .name = "intel_ifs_0",
0028 .nodename = "intel_ifs/0",
0029 .minor = MISC_DYNAMIC_MINOR,
0030 },
0031 };
0032
0033 static int __init ifs_init(void)
0034 {
0035 const struct x86_cpu_id *m;
0036 u64 msrval;
0037
0038 m = x86_match_cpu(ifs_cpu_ids);
0039 if (!m)
0040 return -ENODEV;
0041
0042 if (rdmsrl_safe(MSR_IA32_CORE_CAPS, &msrval))
0043 return -ENODEV;
0044
0045 if (!(msrval & MSR_IA32_CORE_CAPS_INTEGRITY_CAPS))
0046 return -ENODEV;
0047
0048 if (rdmsrl_safe(MSR_INTEGRITY_CAPS, &msrval))
0049 return -ENODEV;
0050
0051 ifs_device.misc.groups = ifs_get_groups();
0052
0053 if ((msrval & BIT(ifs_device.data.integrity_cap_bit)) &&
0054 !misc_register(&ifs_device.misc)) {
0055 down(&ifs_sem);
0056 ifs_load_firmware(ifs_device.misc.this_device);
0057 up(&ifs_sem);
0058 return 0;
0059 }
0060
0061 return -ENODEV;
0062 }
0063
0064 static void __exit ifs_exit(void)
0065 {
0066 misc_deregister(&ifs_device.misc);
0067 }
0068
0069 module_init(ifs_init);
0070 module_exit(ifs_exit);
0071
0072 MODULE_LICENSE("GPL");
0073 MODULE_DESCRIPTION("Intel In Field Scan (IFS) device");