1 // SPDX-License-Identifier: GPL-2.0-only
2 /* Copyright(c) 2022 Intel Corporation. */
5 #include <linux/delay.h>
7 #include <linux/semaphore.h>
8 #include <linux/slab.h>
13 * Protects against simultaneous tests on multiple cores, or
14 * reloading can file while a test is in progress
16 DEFINE_SEMAPHORE(ifs_sem);
19 * The sysfs interface to check additional details of last test
20 * cat /sys/devices/system/platform/ifs/details
22 static ssize_t details_show(struct device *dev,
23 struct device_attribute *attr,
26 struct ifs_data *ifsd = ifs_get_data(dev);
28 return sysfs_emit(buf, "%#llx\n", ifsd->scan_details);
31 static DEVICE_ATTR_RO(details);
33 static const char * const status_msg[] = {
34 [SCAN_NOT_TESTED] = "untested",
35 [SCAN_TEST_PASS] = "pass",
36 [SCAN_TEST_FAIL] = "fail"
40 * The sysfs interface to check the test status:
41 * To check the status of last test
42 * cat /sys/devices/platform/ifs/status
44 static ssize_t status_show(struct device *dev,
45 struct device_attribute *attr,
48 struct ifs_data *ifsd = ifs_get_data(dev);
50 return sysfs_emit(buf, "%s\n", status_msg[ifsd->status]);
53 static DEVICE_ATTR_RO(status);
56 * The sysfs interface for single core testing
57 * To start test, for example, cpu5
58 * echo 5 > /sys/devices/platform/ifs/run_test
59 * To check the result:
60 * cat /sys/devices/platform/ifs/result
61 * The sibling core gets tested at the same time.
63 static ssize_t run_test_store(struct device *dev,
64 struct device_attribute *attr,
65 const char *buf, size_t count)
67 struct ifs_data *ifsd = ifs_get_data(dev);
71 rc = kstrtouint(buf, 0, &cpu);
72 if (rc < 0 || cpu >= nr_cpu_ids)
75 if (down_interruptible(&ifs_sem))
81 rc = do_core_test(cpu, dev);
85 return rc ? rc : count;
88 static DEVICE_ATTR_WO(run_test);
91 * Reload the IFS image. When user wants to install new IFS image
93 static ssize_t reload_store(struct device *dev,
94 struct device_attribute *attr,
95 const char *buf, size_t count)
97 struct ifs_data *ifsd = ifs_get_data(dev);
101 if (kstrtobool(buf, &res))
106 if (down_interruptible(&ifs_sem))
109 ifs_load_firmware(dev);
113 return ifsd->loaded ? count : -ENODEV;
116 static DEVICE_ATTR_WO(reload);
119 * Display currently loaded IFS image version.
121 static ssize_t image_version_show(struct device *dev,
122 struct device_attribute *attr, char *buf)
124 struct ifs_data *ifsd = ifs_get_data(dev);
127 return sysfs_emit(buf, "%s\n", "none");
129 return sysfs_emit(buf, "%#x\n", ifsd->loaded_version);
132 static DEVICE_ATTR_RO(image_version);
134 /* global scan sysfs attributes */
135 static struct attribute *plat_ifs_attrs[] = {
136 &dev_attr_details.attr,
137 &dev_attr_status.attr,
138 &dev_attr_run_test.attr,
139 &dev_attr_reload.attr,
140 &dev_attr_image_version.attr,
144 ATTRIBUTE_GROUPS(plat_ifs);
146 const struct attribute_group **ifs_get_groups(void)
148 return plat_ifs_groups;