hc
2024-10-22 8ac6c7a54ed1b98d142dce24b11c6de6a1e239a5
kernel/include/linux/debugfs.h
....@@ -35,11 +35,17 @@
3535 const struct debugfs_reg32 *regs;
3636 int nregs;
3737 void __iomem *base;
38
+ struct device *dev; /* Optional device for Runtime PM */
39
+};
40
+
41
+struct debugfs_u32_array {
42
+ u32 *array;
43
+ u32 n_elements;
3844 };
3945
4046 extern struct dentry *arch_debugfs_dir;
4147
42
-#define DEFINE_DEBUGFS_ATTRIBUTE(__fops, __get, __set, __fmt) \
48
+#define DEFINE_DEBUGFS_ATTRIBUTE_XSIGNED(__fops, __get, __set, __fmt, __is_signed) \
4349 static int __fops ## _open(struct inode *inode, struct file *file) \
4450 { \
4551 __simple_attr_check_format(__fmt, 0ull); \
....@@ -50,9 +56,15 @@
5056 .open = __fops ## _open, \
5157 .release = simple_attr_release, \
5258 .read = debugfs_attr_read, \
53
- .write = debugfs_attr_write, \
59
+ .write = (__is_signed) ? debugfs_attr_write_signed : debugfs_attr_write, \
5460 .llseek = no_llseek, \
5561 }
62
+
63
+#define DEFINE_DEBUGFS_ATTRIBUTE(__fops, __get, __set, __fmt) \
64
+ DEFINE_DEBUGFS_ATTRIBUTE_XSIGNED(__fops, __get, __set, __fmt, false)
65
+
66
+#define DEFINE_DEBUGFS_ATTRIBUTE_SIGNED(__fops, __get, __set, __fmt) \
67
+ DEFINE_DEBUGFS_ATTRIBUTE_XSIGNED(__fops, __get, __set, __fmt, true)
5668
5769 typedef struct vfsmount *(*debugfs_automount_t)(struct dentry *, void *);
5870
....@@ -67,10 +79,10 @@
6779 struct dentry *parent, void *data,
6880 const struct file_operations *fops);
6981
70
-struct dentry *debugfs_create_file_size(const char *name, umode_t mode,
71
- struct dentry *parent, void *data,
72
- const struct file_operations *fops,
73
- loff_t file_size);
82
+void debugfs_create_file_size(const char *name, umode_t mode,
83
+ struct dentry *parent, void *data,
84
+ const struct file_operations *fops,
85
+ loff_t file_size);
7486
7587 struct dentry *debugfs_create_dir(const char *name, struct dentry *parent);
7688
....@@ -83,7 +95,9 @@
8395 void *data);
8496
8597 void debugfs_remove(struct dentry *dentry);
86
-void debugfs_remove_recursive(struct dentry *dentry);
98
+#define debugfs_remove_recursive debugfs_remove
99
+
100
+void debugfs_lookup_and_remove(const char *name, struct dentry *parent);
87101
88102 const struct file_operations *debugfs_real_fops(const struct file *filp);
89103
....@@ -94,32 +108,34 @@
94108 size_t len, loff_t *ppos);
95109 ssize_t debugfs_attr_write(struct file *file, const char __user *buf,
96110 size_t len, loff_t *ppos);
111
+ssize_t debugfs_attr_write_signed(struct file *file, const char __user *buf,
112
+ size_t len, loff_t *ppos);
97113
98114 struct dentry *debugfs_rename(struct dentry *old_dir, struct dentry *old_dentry,
99115 struct dentry *new_dir, const char *new_name);
100116
101
-struct dentry *debugfs_create_u8(const char *name, umode_t mode,
102
- struct dentry *parent, u8 *value);
103
-struct dentry *debugfs_create_u16(const char *name, umode_t mode,
104
- struct dentry *parent, u16 *value);
105
-struct dentry *debugfs_create_u32(const char *name, umode_t mode,
106
- struct dentry *parent, u32 *value);
107
-struct dentry *debugfs_create_u64(const char *name, umode_t mode,
108
- struct dentry *parent, u64 *value);
117
+void debugfs_create_u8(const char *name, umode_t mode, struct dentry *parent,
118
+ u8 *value);
119
+void debugfs_create_u16(const char *name, umode_t mode, struct dentry *parent,
120
+ u16 *value);
121
+void debugfs_create_u32(const char *name, umode_t mode, struct dentry *parent,
122
+ u32 *value);
123
+void debugfs_create_u64(const char *name, umode_t mode, struct dentry *parent,
124
+ u64 *value);
109125 struct dentry *debugfs_create_ulong(const char *name, umode_t mode,
110126 struct dentry *parent, unsigned long *value);
111
-struct dentry *debugfs_create_x8(const char *name, umode_t mode,
112
- struct dentry *parent, u8 *value);
113
-struct dentry *debugfs_create_x16(const char *name, umode_t mode,
114
- struct dentry *parent, u16 *value);
115
-struct dentry *debugfs_create_x32(const char *name, umode_t mode,
116
- struct dentry *parent, u32 *value);
117
-struct dentry *debugfs_create_x64(const char *name, umode_t mode,
118
- struct dentry *parent, u64 *value);
119
-struct dentry *debugfs_create_size_t(const char *name, umode_t mode,
120
- struct dentry *parent, size_t *value);
121
-struct dentry *debugfs_create_atomic_t(const char *name, umode_t mode,
122
- struct dentry *parent, atomic_t *value);
127
+void debugfs_create_x8(const char *name, umode_t mode, struct dentry *parent,
128
+ u8 *value);
129
+void debugfs_create_x16(const char *name, umode_t mode, struct dentry *parent,
130
+ u16 *value);
131
+void debugfs_create_x32(const char *name, umode_t mode, struct dentry *parent,
132
+ u32 *value);
133
+void debugfs_create_x64(const char *name, umode_t mode, struct dentry *parent,
134
+ u64 *value);
135
+void debugfs_create_size_t(const char *name, umode_t mode,
136
+ struct dentry *parent, size_t *value);
137
+void debugfs_create_atomic_t(const char *name, umode_t mode,
138
+ struct dentry *parent, atomic_t *value);
123139 struct dentry *debugfs_create_bool(const char *name, umode_t mode,
124140 struct dentry *parent, bool *value);
125141
....@@ -127,25 +143,20 @@
127143 struct dentry *parent,
128144 struct debugfs_blob_wrapper *blob);
129145
130
-struct dentry *debugfs_create_regset32(const char *name, umode_t mode,
131
- struct dentry *parent,
132
- struct debugfs_regset32 *regset);
146
+void debugfs_create_regset32(const char *name, umode_t mode,
147
+ struct dentry *parent,
148
+ struct debugfs_regset32 *regset);
133149
134150 void debugfs_print_regs32(struct seq_file *s, const struct debugfs_reg32 *regs,
135151 int nregs, void __iomem *base, char *prefix);
136152
137
-struct dentry *debugfs_create_u32_array(const char *name, umode_t mode,
138
- struct dentry *parent,
139
- u32 *array, u32 elements);
153
+void debugfs_create_u32_array(const char *name, umode_t mode,
154
+ struct dentry *parent,
155
+ struct debugfs_u32_array *array);
140156
141
-struct dentry *debugfs_create_u32_array_hex(const char *name, umode_t mode,
142
- struct dentry *parent,
143
- u32 *array, u32 elements);
144
-
145
-struct dentry *debugfs_create_devm_seqfile(struct device *dev, const char *name,
146
- struct dentry *parent,
147
- int (*read_fn)(struct seq_file *s,
148
- void *data));
157
+void debugfs_create_devm_seqfile(struct device *dev, const char *name,
158
+ struct dentry *parent,
159
+ int (*read_fn)(struct seq_file *s, void *data));
149160
150161 bool debugfs_initialized(void);
151162
....@@ -186,13 +197,11 @@
186197 return ERR_PTR(-ENODEV);
187198 }
188199
189
-static inline struct dentry *debugfs_create_file_size(const char *name, umode_t mode,
190
- struct dentry *parent, void *data,
191
- const struct file_operations *fops,
192
- loff_t file_size)
193
-{
194
- return ERR_PTR(-ENODEV);
195
-}
200
+static inline void debugfs_create_file_size(const char *name, umode_t mode,
201
+ struct dentry *parent, void *data,
202
+ const struct file_operations *fops,
203
+ loff_t file_size)
204
+{ }
196205
197206 static inline struct dentry *debugfs_create_dir(const char *name,
198207 struct dentry *parent)
....@@ -221,6 +230,10 @@
221230 static inline void debugfs_remove_recursive(struct dentry *dentry)
222231 { }
223232
233
+static inline void debugfs_lookup_and_remove(const char *name,
234
+ struct dentry *parent)
235
+{ }
236
+
224237 const struct file_operations *debugfs_real_fops(const struct file *filp);
225238
226239 static inline int debugfs_file_get(struct dentry *dentry)
....@@ -244,39 +257,30 @@
244257 return -ENODEV;
245258 }
246259
260
+static inline ssize_t debugfs_attr_write_signed(struct file *file,
261
+ const char __user *buf,
262
+ size_t len, loff_t *ppos)
263
+{
264
+ return -ENODEV;
265
+}
266
+
247267 static inline struct dentry *debugfs_rename(struct dentry *old_dir, struct dentry *old_dentry,
248268 struct dentry *new_dir, char *new_name)
249269 {
250270 return ERR_PTR(-ENODEV);
251271 }
252272
253
-static inline struct dentry *debugfs_create_u8(const char *name, umode_t mode,
254
- struct dentry *parent,
255
- u8 *value)
256
-{
257
- return ERR_PTR(-ENODEV);
258
-}
273
+static inline void debugfs_create_u8(const char *name, umode_t mode,
274
+ struct dentry *parent, u8 *value) { }
259275
260
-static inline struct dentry *debugfs_create_u16(const char *name, umode_t mode,
261
- struct dentry *parent,
262
- u16 *value)
263
-{
264
- return ERR_PTR(-ENODEV);
265
-}
276
+static inline void debugfs_create_u16(const char *name, umode_t mode,
277
+ struct dentry *parent, u16 *value) { }
266278
267
-static inline struct dentry *debugfs_create_u32(const char *name, umode_t mode,
268
- struct dentry *parent,
269
- u32 *value)
270
-{
271
- return ERR_PTR(-ENODEV);
272
-}
279
+static inline void debugfs_create_u32(const char *name, umode_t mode,
280
+ struct dentry *parent, u32 *value) { }
273281
274
-static inline struct dentry *debugfs_create_u64(const char *name, umode_t mode,
275
- struct dentry *parent,
276
- u64 *value)
277
-{
278
- return ERR_PTR(-ENODEV);
279
-}
282
+static inline void debugfs_create_u64(const char *name, umode_t mode,
283
+ struct dentry *parent, u64 *value) { }
280284
281285 static inline struct dentry *debugfs_create_ulong(const char *name,
282286 umode_t mode,
....@@ -286,46 +290,26 @@
286290 return ERR_PTR(-ENODEV);
287291 }
288292
289
-static inline struct dentry *debugfs_create_x8(const char *name, umode_t mode,
290
- struct dentry *parent,
291
- u8 *value)
292
-{
293
- return ERR_PTR(-ENODEV);
294
-}
293
+static inline void debugfs_create_x8(const char *name, umode_t mode,
294
+ struct dentry *parent, u8 *value) { }
295295
296
-static inline struct dentry *debugfs_create_x16(const char *name, umode_t mode,
297
- struct dentry *parent,
298
- u16 *value)
299
-{
300
- return ERR_PTR(-ENODEV);
301
-}
296
+static inline void debugfs_create_x16(const char *name, umode_t mode,
297
+ struct dentry *parent, u16 *value) { }
302298
303
-static inline struct dentry *debugfs_create_x32(const char *name, umode_t mode,
304
- struct dentry *parent,
305
- u32 *value)
306
-{
307
- return ERR_PTR(-ENODEV);
308
-}
299
+static inline void debugfs_create_x32(const char *name, umode_t mode,
300
+ struct dentry *parent, u32 *value) { }
309301
310
-static inline struct dentry *debugfs_create_x64(const char *name, umode_t mode,
311
- struct dentry *parent,
312
- u64 *value)
313
-{
314
- return ERR_PTR(-ENODEV);
315
-}
302
+static inline void debugfs_create_x64(const char *name, umode_t mode,
303
+ struct dentry *parent, u64 *value) { }
316304
317
-static inline struct dentry *debugfs_create_size_t(const char *name, umode_t mode,
318
- struct dentry *parent,
319
- size_t *value)
320
-{
321
- return ERR_PTR(-ENODEV);
322
-}
305
+static inline void debugfs_create_size_t(const char *name, umode_t mode,
306
+ struct dentry *parent, size_t *value)
307
+{ }
323308
324
-static inline struct dentry *debugfs_create_atomic_t(const char *name, umode_t mode,
325
- struct dentry *parent, atomic_t *value)
326
-{
327
- return ERR_PTR(-ENODEV);
328
-}
309
+static inline void debugfs_create_atomic_t(const char *name, umode_t mode,
310
+ struct dentry *parent,
311
+ atomic_t *value)
312
+{ }
329313
330314 static inline struct dentry *debugfs_create_bool(const char *name, umode_t mode,
331315 struct dentry *parent,
....@@ -341,11 +325,10 @@
341325 return ERR_PTR(-ENODEV);
342326 }
343327
344
-static inline struct dentry *debugfs_create_regset32(const char *name,
345
- umode_t mode, struct dentry *parent,
346
- struct debugfs_regset32 *regset)
328
+static inline void debugfs_create_regset32(const char *name, umode_t mode,
329
+ struct dentry *parent,
330
+ struct debugfs_regset32 *regset)
347331 {
348
- return ERR_PTR(-ENODEV);
349332 }
350333
351334 static inline void debugfs_print_regs32(struct seq_file *s, const struct debugfs_reg32 *regs,
....@@ -358,27 +341,18 @@
358341 return false;
359342 }
360343
361
-static inline struct dentry *debugfs_create_u32_array(const char *name, umode_t mode,
362
- struct dentry *parent,
363
- u32 *array, u32 elements)
344
+static inline void debugfs_create_u32_array(const char *name, umode_t mode,
345
+ struct dentry *parent,
346
+ struct debugfs_u32_array *array)
364347 {
365
- return ERR_PTR(-ENODEV);
366348 }
367349
368
-static inline struct dentry *debugfs_create_u32_array_hex(const char *name, umode_t mode,
369
- struct dentry *parent,
370
- u32 *array, u32 elements)
350
+static inline void debugfs_create_devm_seqfile(struct device *dev,
351
+ const char *name,
352
+ struct dentry *parent,
353
+ int (*read_fn)(struct seq_file *s,
354
+ void *data))
371355 {
372
- return ERR_PTR(-ENODEV);
373
-}
374
-
375
-static inline struct dentry *debugfs_create_devm_seqfile(struct device *dev,
376
- const char *name,
377
- struct dentry *parent,
378
- int (*read_fn)(struct seq_file *s,
379
- void *data))
380
-{
381
- return ERR_PTR(-ENODEV);
382356 }
383357
384358 static inline ssize_t debugfs_read_file_bool(struct file *file,
....@@ -397,4 +371,25 @@
397371
398372 #endif
399373
374
+/**
375
+ * debugfs_create_xul - create a debugfs file that is used to read and write an
376
+ * unsigned long value, formatted in hexadecimal
377
+ * @name: a pointer to a string containing the name of the file to create.
378
+ * @mode: the permission that the file should have
379
+ * @parent: a pointer to the parent dentry for this file. This should be a
380
+ * directory dentry if set. If this parameter is %NULL, then the
381
+ * file will be created in the root of the debugfs filesystem.
382
+ * @value: a pointer to the variable that the file should read to and write
383
+ * from.
384
+ */
385
+static inline void debugfs_create_xul(const char *name, umode_t mode,
386
+ struct dentry *parent,
387
+ unsigned long *value)
388
+{
389
+ if (sizeof(*value) == sizeof(u32))
390
+ debugfs_create_x32(name, mode, parent, (u32 *)value);
391
+ else
392
+ debugfs_create_x64(name, mode, parent, (u64 *)value);
393
+}
394
+
400395 #endif