Loading...
Note: File does not exist in v4.6.
1// SPDX-License-Identifier: GPL-2.0-only
2/* Copyright(c) 2022 Intel Corporation. */
3
4#include <linux/module.h>
5#include <linux/kdev_t.h>
6#include <linux/semaphore.h>
7#include <linux/slab.h>
8
9#include <asm/cpu_device_id.h>
10
11#include "ifs.h"
12
13#define X86_MATCH(model) \
14 X86_MATCH_VENDOR_FAM_MODEL_FEATURE(INTEL, 6, \
15 INTEL_FAM6_##model, X86_FEATURE_CORE_CAPABILITIES, NULL)
16
17static const struct x86_cpu_id ifs_cpu_ids[] __initconst = {
18 X86_MATCH(SAPPHIRERAPIDS_X),
19 {}
20};
21MODULE_DEVICE_TABLE(x86cpu, ifs_cpu_ids);
22
23static struct ifs_device ifs_device = {
24 .data = {
25 .integrity_cap_bit = MSR_INTEGRITY_CAPS_PERIODIC_BIST_BIT,
26 .test_num = 0,
27 },
28 .misc = {
29 .name = "intel_ifs_0",
30 .nodename = "intel_ifs/0",
31 .minor = MISC_DYNAMIC_MINOR,
32 },
33};
34
35static int __init ifs_init(void)
36{
37 const struct x86_cpu_id *m;
38 u64 msrval;
39 int ret;
40
41 m = x86_match_cpu(ifs_cpu_ids);
42 if (!m)
43 return -ENODEV;
44
45 if (rdmsrl_safe(MSR_IA32_CORE_CAPS, &msrval))
46 return -ENODEV;
47
48 if (!(msrval & MSR_IA32_CORE_CAPS_INTEGRITY_CAPS))
49 return -ENODEV;
50
51 if (rdmsrl_safe(MSR_INTEGRITY_CAPS, &msrval))
52 return -ENODEV;
53
54 ifs_device.misc.groups = ifs_get_groups();
55
56 if (!(msrval & BIT(ifs_device.data.integrity_cap_bit)))
57 return -ENODEV;
58
59 ifs_device.data.pkg_auth = kmalloc_array(topology_max_packages(), sizeof(bool), GFP_KERNEL);
60 if (!ifs_device.data.pkg_auth)
61 return -ENOMEM;
62
63 ret = misc_register(&ifs_device.misc);
64 if (ret) {
65 kfree(ifs_device.data.pkg_auth);
66 return ret;
67 }
68
69 return 0;
70}
71
72static void __exit ifs_exit(void)
73{
74 misc_deregister(&ifs_device.misc);
75 kfree(ifs_device.data.pkg_auth);
76}
77
78module_init(ifs_init);
79module_exit(ifs_exit);
80
81MODULE_LICENSE("GPL");
82MODULE_DESCRIPTION("Intel In Field Scan (IFS) device");