xref: /openbmc/linux/drivers/peci/sysfs.c (revision 8dd3cdea)
1 // SPDX-License-Identifier: GPL-2.0-only
2 // Copyright (c) 2021 Intel Corporation
3 
4 #include <linux/device.h>
5 #include <linux/kernel.h>
6 #include <linux/peci.h>
7 
8 #include "internal.h"
9 
10 static int rescan_controller(struct device *dev, void *data)
11 {
12 	if (dev->type != &peci_controller_type)
13 		return 0;
14 
15 	return peci_controller_scan_devices(to_peci_controller(dev));
16 }
17 
18 static ssize_t rescan_store(struct bus_type *bus, const char *buf, size_t count)
19 {
20 	bool res;
21 	int ret;
22 
23 	ret = kstrtobool(buf, &res);
24 	if (ret)
25 		return ret;
26 
27 	if (!res)
28 		return count;
29 
30 	ret = bus_for_each_dev(&peci_bus_type, NULL, NULL, rescan_controller);
31 	if (ret)
32 		return ret;
33 
34 	return count;
35 }
36 static BUS_ATTR_WO(rescan);
37 
38 static struct attribute *peci_bus_attrs[] = {
39 	&bus_attr_rescan.attr,
40 	NULL
41 };
42 
43 static const struct attribute_group peci_bus_group = {
44 	.attrs = peci_bus_attrs,
45 };
46 
47 const struct attribute_group *peci_bus_groups[] = {
48 	&peci_bus_group,
49 	NULL
50 };
51 
52 static ssize_t remove_store(struct device *dev, struct device_attribute *attr,
53 			    const char *buf, size_t count)
54 {
55 	struct peci_device *device = to_peci_device(dev);
56 	bool res;
57 	int ret;
58 
59 	ret = kstrtobool(buf, &res);
60 	if (ret)
61 		return ret;
62 
63 	if (res && device_remove_file_self(dev, attr))
64 		peci_device_destroy(device);
65 
66 	return count;
67 }
68 static DEVICE_ATTR_IGNORE_LOCKDEP(remove, 0200, NULL, remove_store);
69 
70 static struct attribute *peci_device_attrs[] = {
71 	&dev_attr_remove.attr,
72 	NULL
73 };
74 
75 static const struct attribute_group peci_device_group = {
76 	.attrs = peci_device_attrs,
77 };
78 
79 const struct attribute_group *peci_device_groups[] = {
80 	&peci_device_group,
81 	NULL
82 };
83