Repository navigation
Expand file tree
/
Copy path0064-vbus.h.patch
More file actions
339 lines (339 loc) · 10.5 KB
/
Copy path0064-vbus.h.patch
File metadata and controls
339 lines (339 loc) · 10.5 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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
--- /home/rossierd/soo/git/micofe/build/tmp/work/linux-6.12-r0/linux-6.12/soo/include/soo/vbus.h 1970-01-01 01:00:00.000000000 +0100
+++ ./soo/include/soo/vbus.h 2025-08-29 08:46:41.396103436 +0200
@@ -0,0 +1,336 @@
+/*
+ * Copyright (C) 2014-2019 Daniel Rossier <daniel.rossier@heig-vd.ch>
+ * Copyright (C) 2016, 2018 Baptiste Delporte <bonel@bonel.net>
+ *
+ * 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
+ *
+ */
+
+#ifndef VBUS_H
+#define VBUS_H
+
+#include <linux/module.h>
+#include <linux/device.h>
+#include <linux/notifier.h>
+#include <linux/mutex.h>
+#include <linux/completion.h>
+#include <linux/init.h>
+
+#include <soo/hypervisor.h>
+#include <soo/vbstore.h>
+#include <soo/gnttab.h>
+
+#include <soo/uapi/soo.h>
+/*
+ * The following states are used to synchronize backend and frontend activities.
+ * Detailed description is given in the SOO Framework technical reference.
+ */
+
+enum vbus_state
+{
+ VbusStateUnknown = 0,
+ VbusStateInitialising = 1,
+ VbusStateInitWait = 2,
+ VbusStateInitialised = 3,
+ VbusStateConnected = 4,
+ VbusStateClosing = 5,
+ VbusStateClosed = 6,
+ VbusStateReconfiguring = 7,
+ VbusStateReconfigured = 8,
+ VbusStateSuspending = 9,
+ VbusStateSuspended = 10,
+ VbusStateResuming = 11
+
+};
+
+/* VBS_KEY_LENGTH as it is managed by vbstore */
+#define VBS_KEY_LENGTH 50
+#define VBUS_DEV_TYPE 32
+
+/* Register callback to watch this node. */
+struct vbus_watch
+{
+ struct list_head list;
+
+ /* Path being watched. */
+ char *node;
+
+ /* Callback (executed in a process context with no locks held). */
+ void (*callback)(struct vbus_watch *);
+
+ volatile bool pending;
+};
+
+struct vbus_type
+{
+ char *root;
+ unsigned int levels;
+ void (*get_bus_id)(char bus_id[VBS_KEY_LENGTH], const char *nodename);
+
+ int (*probe)(struct vbus_type *bus, const char *type, const char *dir);
+ void (*otherend_changed)(struct vbus_watch *watch);
+
+ void (*suspend)(void);
+ void (*resume)(void);
+
+ struct bus_type bus;
+};
+
+
+/* A vbus device. */
+struct vbus_device {
+ char devicetype[VBUS_DEV_TYPE];
+ char nodename[VBS_KEY_LENGTH];
+ char otherend[VBS_KEY_LENGTH];
+ int otherend_id;
+
+ struct vbus_watch otherend_watch;
+
+ struct device dev;
+
+ enum vbus_state state;
+
+ /*
+ * State of the associated frontend.
+ * As soon as the frontend state, we get a watch event on the state
+ * property from vbstore, and we are up-to-date.
+ */
+ enum vbus_state fe_state;
+
+ /* So far, only the S3C use this completion struct. On the agency side,
+ * the device can not be shutdown on live.
+ */
+ struct completion down;
+
+ /* This completion lock is used for synchronizing interactions during connecting, suspending and resuming activities. */
+ struct completion sync_backfront;
+
+ int resuming;
+};
+
+static inline struct vbus_device *to_vbus_device(struct device *dev)
+{
+ return container_of(dev, struct vbus_device, dev);
+}
+
+/* A vbus driver. */
+struct vbus_driver {
+ char *name;
+ struct module *owner;
+ char devicetype[32];
+
+ struct device_driver driver;
+
+ /* Private stucture for this vbus driver */
+ void *priv;
+
+ void (*probe)(struct vbus_device *dev);
+ void (*remove)(struct vbus_device *dev);
+
+ void (*otherend_changed)(struct vbus_device *dev, enum vbus_state backend_state);
+
+ int (*suspend)(struct vbus_device *dev);
+ int (*resume)(struct vbus_device *dev);
+
+ int (*uevent)(struct vbus_device *, struct kobj_uevent_env *);
+
+ void (*read_otherend_details)(struct vbus_device *dev);
+};
+
+static inline struct vbus_driver *to_vbus_driver(struct device_driver *drv)
+{
+ return container_of(drv, struct vbus_driver, driver);
+}
+
+/*
+ * Attach a private structure to a vbus driver
+ */
+static inline void vdrv_set_priv(struct vbus_driver *vdrv, void *priv) {
+ vdrv->priv = priv;
+}
+
+/*
+ * Retrieve the private structure attached to a specific vbus driver
+ */
+static inline const void *vdrv_get_priv(const struct vbus_driver *vdrv) {
+ return vdrv->priv;
+}
+
+/*
+ * Retrieve the private structure attached to a vbus driver from a particular vbus device
+ */
+static inline const void *vdrv_get_vdevpriv(const struct vbus_device *vdev) {
+ return vdrv_get_priv(to_vbus_driver(vdev->dev.driver));
+}
+
+void __vbus_register_frontend(struct vbus_driver *drv, struct module *owner, const char *mod_name);
+
+static inline void vbus_register_frontend(struct vbus_driver *drv)
+{
+ WARN_ON(drv->owner != THIS_MODULE);
+ return __vbus_register_frontend(drv, THIS_MODULE, KBUILD_MODNAME);
+}
+
+void __vbus_register_backend(struct vbus_driver *drv, struct module *owner, const char *mod_name);
+
+static inline void vbus_register_backend(struct vbus_driver *drv)
+{
+ WARN_ON(drv->owner != THIS_MODULE);
+ return __vbus_register_backend(drv, THIS_MODULE, KBUILD_MODNAME);
+}
+
+void vbus_unregister_driver(struct vbus_driver *drv);
+
+struct vbus_transaction
+{
+ u32 id; /* Unique non-zereo value to identify a transaction */
+};
+
+/* Nil transaction ID. */
+#define VBT_NIL ((struct vbus_transaction) { 0 })
+
+char **vbus_directory(struct vbus_transaction t, const char *dir, const char *node, unsigned int *num);
+int vbus_directory_exists(struct vbus_transaction t, const char *dir, const char *node);
+void *vbus_read(struct vbus_transaction t, const char *dir, const char *node, unsigned int *len);
+void vbus_write(struct vbus_transaction t, const char *dir, const char *node, const char *string);
+void vbus_mkdir(struct vbus_transaction t, const char *dir, const char *node);
+int vbus_exists(struct vbus_transaction t, const char *dir, const char *node);
+void vbus_rm(struct vbus_transaction t, const char *dir, const char *node);
+
+void vbus_transaction_start(struct vbus_transaction *t);
+void vbus_transaction_end(struct vbus_transaction t);
+
+/* Single read and scanf: returns -errno or num scanned if > 0. */
+int vbus_scanf(struct vbus_transaction t, const char *dir, const char *node, const char *fmt, ...)
+ __attribute__((format(scanf, 4, 5)));
+
+/* Single printf and write: returns -errno or 0. */
+void vbus_printf(struct vbus_transaction t, const char *dir, const char *node, const char *fmt, ...)
+ __attribute__((format(printf, 4, 5)));
+
+/* Generic read function: NULL-terminated triples of name,
+ * sprintf-style type string, and pointer. Returns 0 or errno.*/
+bool vbus_gather(struct vbus_transaction t, const char *dir, ...);
+
+void free_otherend_watch(struct vbus_device *dev, bool with_vbus);
+
+extern void vbstore_init(void);
+
+bool is_vbstore_populated(void);
+
+void register_vbus_watch(struct vbus_watch *watch);
+void unregister_vbus_watch_without_vbus(struct vbus_watch *watch);
+void unregister_vbus_watch(struct vbus_watch *watch);
+
+void remove_device(const char *path);
+void vbus_cleanup_device(const char *path, struct bus_type *bus);
+
+struct work_struct;
+
+extern struct completion backend_initialized;
+
+extern int vbus_match(struct device *_dev, const struct device_driver *_drv);
+extern int vbus_dev_probe(struct device *_dev);
+
+int vbus_probe_backend(int domid);
+int vbus_probe_backend_init(void);
+
+extern void vbus_dev_remove(struct device *_dev);
+extern void vbus_register_driver_common(struct vbus_driver *drv, struct vbus_type *bus, struct module *owner, const char *mod_name);
+
+extern int vbus_probe_devices(struct vbus_type *bus);
+
+extern void vbus_dev_changed(const char *node, char *type, struct vbus_type *bus);
+
+extern void vbus_dev_shutdown(struct device *_dev);
+
+extern int vbus_dev_suspend(struct device *dev, pm_message_t state);
+extern int vbus_dev_resume(struct device *dev);
+
+extern void vbus_otherend_changed(struct vbus_watch *watch);
+
+extern void vbus_read_otherend_details(struct vbus_device *vdev, char *id_node, char *path_node);
+extern int vbus_suspend_dev(struct bus_type *bus, unsigned int domID);
+extern int vbus_resume_dev(struct bus_type *bus, unsigned int domID);
+
+/* Prepare for domain suspend: then resume or cancel the suspend. */
+int vbus_suspend_devices(unsigned int domID);
+int vbus_resume_devices(unsigned int domID);
+
+int vdev_probe(char *node);
+void vbus_probe_frontend_init(void);
+
+#define VBUS_IS_ERR_READ(str) ({ \
+ if (!IS_ERR(str) && strlen(str) == 0) { \
+ kfree(str); \
+ str = ERR_PTR(-ERANGE); \
+ } \
+ IS_ERR(str); \
+})
+
+#define VBUS_EXIST_ERR(err) ((err) == -ENOENT || (err) == -ERANGE)
+
+void vbus_watch_path(char *path, struct vbus_watch *watch, void (*callback)(struct vbus_watch *));
+void vbus_watch_pathfmt(struct vbus_device *dev, struct vbus_watch *watch, void (*callback)(struct vbus_watch *), const char *pathfmt, ...)
+ __attribute__ ((format (printf, 4, 5)));
+
+void vbus_unmap_ring(struct vbus_device *dev, grant_ref_t ref);
+void vbus_map_ring(struct vbus_device *dev, grant_ref_t ref, void **vaddr);
+
+void vbus_alloc_evtchn(struct vbus_device *dev, uint32_t *port);
+void vbus_bind_evtchn(struct vbus_device *dev, uint32_t remote_port, uint32_t *port);
+void vbus_free_evtchn(struct vbus_device *dev, uint32_t port);
+
+enum vbus_state vbus_read_driver_state(const char *path);
+
+const char *vbus_strstate(enum vbus_state state);
+
+void remove_vbstore_entries(void);
+
+void vbuswatch_thread_sync(void);
+int get_vbstore_evtchn(void);
+
+void ping_remote_domain(int domID, void (*ping_callback)(void));
+
+void vbs_prepare_to_suspend(struct work_struct *unused);
+void vbs_prepare_to_resume(struct work_struct *unused);
+
+void vbs_suspend(void);
+void vbs_resume(void);
+
+void presetup_register_watch(struct vbus_watch *watch);
+void presetup_unregister_watch(struct vbus_watch *watch);
+
+void vbstore_devices_populate(void);
+void vbstore_trigger_dev_probe(void);
+int vbstore_uart_remove(unsigned int domID);
+
+void postresume_setup(void);
+int gnttab_remove(bool with_vbus);
+
+void remove_devices(void);
+
+void register_dc_event_callback(dc_event_t dc_event, dc_event_fn_t *callback);
+
+#ifdef DEBUG
+#undef DBG
+#define DBG(fmt, ...) \
+ do { \
+ printk("%s:%i > "fmt, __FUNCTION__, __LINE__, ##__VA_ARGS__); \
+ } while(0)
+#else
+#define DBG(fmt, ...)
+#endif
+
+#endif /* VBUS_H */