Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-only
0002 /* Copyright(c) 2022 Intel Corporation. */
0003 
0004 #include <linux/cpu.h>
0005 #include <linux/delay.h>
0006 #include <linux/fs.h>
0007 #include <linux/semaphore.h>
0008 #include <linux/slab.h>
0009 
0010 #include "ifs.h"
0011 
0012 /*
0013  * Protects against simultaneous tests on multiple cores, or
0014  * reloading can file while a test is in progress
0015  */
0016 DEFINE_SEMAPHORE(ifs_sem);
0017 
0018 /*
0019  * The sysfs interface to check additional details of last test
0020  * cat /sys/devices/system/platform/ifs/details
0021  */
0022 static ssize_t details_show(struct device *dev,
0023                 struct device_attribute *attr,
0024                 char *buf)
0025 {
0026     struct ifs_data *ifsd = ifs_get_data(dev);
0027 
0028     return sysfs_emit(buf, "%#llx\n", ifsd->scan_details);
0029 }
0030 
0031 static DEVICE_ATTR_RO(details);
0032 
0033 static const char * const status_msg[] = {
0034     [SCAN_NOT_TESTED] = "untested",
0035     [SCAN_TEST_PASS] = "pass",
0036     [SCAN_TEST_FAIL] = "fail"
0037 };
0038 
0039 /*
0040  * The sysfs interface to check the test status:
0041  * To check the status of last test
0042  * cat /sys/devices/platform/ifs/status
0043  */
0044 static ssize_t status_show(struct device *dev,
0045                struct device_attribute *attr,
0046                char *buf)
0047 {
0048     struct ifs_data *ifsd = ifs_get_data(dev);
0049 
0050     return sysfs_emit(buf, "%s\n", status_msg[ifsd->status]);
0051 }
0052 
0053 static DEVICE_ATTR_RO(status);
0054 
0055 /*
0056  * The sysfs interface for single core testing
0057  * To start test, for example, cpu5
0058  * echo 5 > /sys/devices/platform/ifs/run_test
0059  * To check the result:
0060  * cat /sys/devices/platform/ifs/result
0061  * The sibling core gets tested at the same time.
0062  */
0063 static ssize_t run_test_store(struct device *dev,
0064                   struct device_attribute *attr,
0065                   const char *buf, size_t count)
0066 {
0067     struct ifs_data *ifsd = ifs_get_data(dev);
0068     unsigned int cpu;
0069     int rc;
0070 
0071     rc = kstrtouint(buf, 0, &cpu);
0072     if (rc < 0 || cpu >= nr_cpu_ids)
0073         return -EINVAL;
0074 
0075     if (down_interruptible(&ifs_sem))
0076         return -EINTR;
0077 
0078     if (!ifsd->loaded)
0079         rc = -EPERM;
0080     else
0081         rc = do_core_test(cpu, dev);
0082 
0083     up(&ifs_sem);
0084 
0085     return rc ? rc : count;
0086 }
0087 
0088 static DEVICE_ATTR_WO(run_test);
0089 
0090 /*
0091  * Reload the IFS image. When user wants to install new IFS image
0092  */
0093 static ssize_t reload_store(struct device *dev,
0094                 struct device_attribute *attr,
0095                 const char *buf, size_t count)
0096 {
0097     struct ifs_data *ifsd = ifs_get_data(dev);
0098     bool res;
0099 
0100 
0101     if (kstrtobool(buf, &res))
0102         return -EINVAL;
0103     if (!res)
0104         return count;
0105 
0106     if (down_interruptible(&ifs_sem))
0107         return -EINTR;
0108 
0109     ifs_load_firmware(dev);
0110 
0111     up(&ifs_sem);
0112 
0113     return ifsd->loaded ? count : -ENODEV;
0114 }
0115 
0116 static DEVICE_ATTR_WO(reload);
0117 
0118 /*
0119  * Display currently loaded IFS image version.
0120  */
0121 static ssize_t image_version_show(struct device *dev,
0122                   struct device_attribute *attr, char *buf)
0123 {
0124     struct ifs_data *ifsd = ifs_get_data(dev);
0125 
0126     if (!ifsd->loaded)
0127         return sysfs_emit(buf, "%s\n", "none");
0128     else
0129         return sysfs_emit(buf, "%#x\n", ifsd->loaded_version);
0130 }
0131 
0132 static DEVICE_ATTR_RO(image_version);
0133 
0134 /* global scan sysfs attributes */
0135 static struct attribute *plat_ifs_attrs[] = {
0136     &dev_attr_details.attr,
0137     &dev_attr_status.attr,
0138     &dev_attr_run_test.attr,
0139     &dev_attr_reload.attr,
0140     &dev_attr_image_version.attr,
0141     NULL
0142 };
0143 
0144 ATTRIBUTE_GROUPS(plat_ifs);
0145 
0146 const struct attribute_group **ifs_get_groups(void)
0147 {
0148     return plat_ifs_groups;
0149 }