Repository navigation
Expand file tree
/
Copy path0088-sysfs.c.patch
More file actions
161 lines (161 loc) · 4.34 KB
/
Copy path0088-sysfs.c.patch
File metadata and controls
161 lines (161 loc) · 4.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
--- /home/rossierd/soo/git/micofe/build/tmp/work/linux-6.12-r0/linux-6.12/soo/kernel/sysfs.c 1970-01-01 01:00:00.000000000 +0100
+++ ./soo/kernel/sysfs.c 2025-08-29 08:46:41.394665675 +0200
@@ -0,0 +1,158 @@
+
+/*
+ * Copyright (C) 2020 Daniel Rossier <daniel.rossier@heig-vd.ch>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ */
+
+#include <linux/kobject.h>
+#include <linux/types.h>
+#include <linux/list.h>
+#include <linux/slab.h>
+
+#include <soo/sysfs.h>
+
+#include <soo/uapi/console.h>
+
+/* Required to have a real string for each attribute. */
+char *soo_sysfs_names[] = {
+ [agencyUID] = "agencyUID",
+ [name] = "name",
+ [vsensej_js]= "vsensej_js",
+};
+
+static struct kobject *root_kobj;
+
+static struct kobject *backend_kobj;
+static struct kobject *backend_vsensej_kobj;
+
+
+/* Internal list structure to manage the diversity of callback functions related to attributes */
+typedef struct {
+ soo_sysfs_attr_t attr;
+ sysfs_handler_t show_handler, store_handler;
+ struct list_head list;
+} handler_list_t;
+
+static struct list_head handlers;
+
+void soo_sysfs_register(soo_sysfs_attr_t attr, sysfs_handler_t show_handler, sysfs_handler_t store_handler) {
+ handler_list_t *handler;
+
+ handler = kmalloc(sizeof(handler_list_t), GFP_ATOMIC);
+ BUG_ON(!handler);
+
+ handler->attr = attr;
+ handler->show_handler = show_handler;
+ handler->store_handler = store_handler;
+
+ list_add(&handler->list, &handlers);
+}
+
+static ssize_t attr_show(struct kobject *kobj, struct kobj_attribute *attr, char *str) {
+ handler_list_t *handler;
+
+ list_for_each_entry(handler, &handlers, list) {
+
+ if (!strcmp(attr->attr.name, soo_sysfs_names[handler->attr])) {
+ if (handler->show_handler) {
+ handler->show_handler(str);
+
+ return strlen(str);
+ }
+ }
+ }
+
+ return 0;
+}
+
+
+static ssize_t attr_store(struct kobject *kobj, struct kobj_attribute *attr, const char *str, size_t len) {
+ handler_list_t *handler;
+
+ list_for_each_entry(handler, &handlers, list) {
+
+ if (!strcmp(attr->attr.name, soo_sysfs_names[handler->attr])) {
+ if (handler->store_handler)
+ handler->store_handler((char *) str);
+ }
+ }
+
+ return len;
+}
+
+/***** Attributes declaration *****/
+
+/* SOO */
+static struct kobj_attribute agencyUID_attr = __ATTR(agencyUID, 0664, attr_show, attr_store);
+static struct kobj_attribute name_attr = __ATTR(name, 0664, attr_show, attr_store);
+
+/** Backends **/
+
+/**** vsensej ****/
+static struct kobj_attribute vsensej_js_attr = __ATTR(vsensej_js, 0664, attr_show, attr_store);
+
+
+/* Groups of attributes for SOO (root) */
+static struct attribute *soo_attrs[] = {
+ &agencyUID_attr.attr,
+ &name_attr.attr,
+ NULL, /* need to NULL terminate the list of attributes */
+};
+
+static struct attribute_group soo_group = {
+ .attrs = soo_attrs,
+};
+
+
+/* Group of attributes for Backends */
+static struct attribute *backend_vsensej_attrs[] = {
+ &vsensej_js_attr.attr,
+ NULL, /* need to NULL terminate the list of attributes */
+};
+
+static struct attribute_group backend_vsensej_group = {
+ .attrs = backend_vsensej_attrs,
+};
+
+void soo_sysfs_init(void) {
+ int ret;
+
+ INIT_LIST_HEAD(&handlers);
+
+ /* Create the entry in /sys to access the information
+ * which will be exposed to the user space.
+ */
+
+ /* SOO root */
+ root_kobj = kobject_create_and_add("soo", NULL);
+ BUG_ON(!root_kobj);
+
+ ret = sysfs_create_group(root_kobj, &soo_group);
+ BUG_ON(ret);
+
+ /** Backends **/
+ backend_kobj = kobject_create_and_add("backend", root_kobj);
+ BUG_ON(!backend_kobj);
+
+ /**** vsensej ****/
+ backend_vsensej_kobj = kobject_create_and_add("vsensej", backend_kobj);
+ BUG_ON(!backend_vsensej_kobj);
+
+ ret = sysfs_create_group(backend_vsensej_kobj, &backend_vsensej_group);
+ BUG_ON(ret);
+}
+
+