This source file includes following definitions.
- rproc_trace_read
- rproc_name_read
- rproc_recovery_read
- rproc_recovery_write
- rproc_crash_write
- rproc_rsc_table_show
- rproc_rsc_table_open
- rproc_carveouts_show
- rproc_carveouts_open
- rproc_remove_trace_file
- rproc_create_trace_file
- rproc_delete_debug_dir
- rproc_create_debug_dir
- rproc_init_debugfs
- rproc_exit_debugfs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 #define pr_fmt(fmt) "%s: " fmt, __func__
18
19 #include <linux/kernel.h>
20 #include <linux/debugfs.h>
21 #include <linux/remoteproc.h>
22 #include <linux/device.h>
23 #include <linux/uaccess.h>
24
25 #include "remoteproc_internal.h"
26
27
28 static struct dentry *rproc_dbg;
29
30
31
32
33
34
35
36
37
38
39 static ssize_t rproc_trace_read(struct file *filp, char __user *userbuf,
40 size_t count, loff_t *ppos)
41 {
42 struct rproc_debug_trace *data = filp->private_data;
43 struct rproc_mem_entry *trace = &data->trace_mem;
44 void *va;
45 char buf[100];
46 int len;
47
48 va = rproc_da_to_va(data->rproc, trace->da, trace->len);
49
50 if (!va) {
51 len = scnprintf(buf, sizeof(buf), "Trace %s not available\n",
52 trace->name);
53 va = buf;
54 } else {
55 len = strnlen(va, trace->len);
56 }
57
58 return simple_read_from_buffer(userbuf, count, ppos, va, len);
59 }
60
61 static const struct file_operations trace_rproc_ops = {
62 .read = rproc_trace_read,
63 .open = simple_open,
64 .llseek = generic_file_llseek,
65 };
66
67
68 static ssize_t rproc_name_read(struct file *filp, char __user *userbuf,
69 size_t count, loff_t *ppos)
70 {
71 struct rproc *rproc = filp->private_data;
72
73 char buf[100];
74 int i;
75
76 i = scnprintf(buf, sizeof(buf), "%.98s\n", rproc->name);
77
78 return simple_read_from_buffer(userbuf, count, ppos, buf, i);
79 }
80
81 static const struct file_operations rproc_name_ops = {
82 .read = rproc_name_read,
83 .open = simple_open,
84 .llseek = generic_file_llseek,
85 };
86
87
88 static ssize_t rproc_recovery_read(struct file *filp, char __user *userbuf,
89 size_t count, loff_t *ppos)
90 {
91 struct rproc *rproc = filp->private_data;
92 char *buf = rproc->recovery_disabled ? "disabled\n" : "enabled\n";
93
94 return simple_read_from_buffer(userbuf, count, ppos, buf, strlen(buf));
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 static ssize_t
122 rproc_recovery_write(struct file *filp, const char __user *user_buf,
123 size_t count, loff_t *ppos)
124 {
125 struct rproc *rproc = filp->private_data;
126 char buf[10];
127 int ret;
128
129 if (count < 1 || count > sizeof(buf))
130 return -EINVAL;
131
132 ret = copy_from_user(buf, user_buf, count);
133 if (ret)
134 return -EFAULT;
135
136
137 if (buf[count - 1] == '\n')
138 buf[count - 1] = '\0';
139
140 if (!strncmp(buf, "enabled", count)) {
141 rproc->recovery_disabled = false;
142
143 if (rproc->state == RPROC_CRASHED)
144 rproc_trigger_recovery(rproc);
145 } else if (!strncmp(buf, "disabled", count)) {
146 rproc->recovery_disabled = true;
147 } else if (!strncmp(buf, "recover", count)) {
148
149 if (rproc->state == RPROC_CRASHED)
150 rproc_trigger_recovery(rproc);
151 }
152
153 return count;
154 }
155
156 static const struct file_operations rproc_recovery_ops = {
157 .read = rproc_recovery_read,
158 .write = rproc_recovery_write,
159 .open = simple_open,
160 .llseek = generic_file_llseek,
161 };
162
163
164 static ssize_t
165 rproc_crash_write(struct file *filp, const char __user *user_buf,
166 size_t count, loff_t *ppos)
167 {
168 struct rproc *rproc = filp->private_data;
169 unsigned int type;
170 int ret;
171
172 ret = kstrtouint_from_user(user_buf, count, 0, &type);
173 if (ret < 0)
174 return ret;
175
176 rproc_report_crash(rproc, type);
177
178 return count;
179 }
180
181 static const struct file_operations rproc_crash_ops = {
182 .write = rproc_crash_write,
183 .open = simple_open,
184 .llseek = generic_file_llseek,
185 };
186
187
188 static int rproc_rsc_table_show(struct seq_file *seq, void *p)
189 {
190 static const char * const types[] = {"carveout", "devmem", "trace", "vdev"};
191 struct rproc *rproc = seq->private;
192 struct resource_table *table = rproc->table_ptr;
193 struct fw_rsc_carveout *c;
194 struct fw_rsc_devmem *d;
195 struct fw_rsc_trace *t;
196 struct fw_rsc_vdev *v;
197 int i, j;
198
199 if (!table) {
200 seq_puts(seq, "No resource table found\n");
201 return 0;
202 }
203
204 for (i = 0; i < table->num; i++) {
205 int offset = table->offset[i];
206 struct fw_rsc_hdr *hdr = (void *)table + offset;
207 void *rsc = (void *)hdr + sizeof(*hdr);
208
209 switch (hdr->type) {
210 case RSC_CARVEOUT:
211 c = rsc;
212 seq_printf(seq, "Entry %d is of type %s\n", i, types[hdr->type]);
213 seq_printf(seq, " Device Address 0x%x\n", c->da);
214 seq_printf(seq, " Physical Address 0x%x\n", c->pa);
215 seq_printf(seq, " Length 0x%x Bytes\n", c->len);
216 seq_printf(seq, " Flags 0x%x\n", c->flags);
217 seq_printf(seq, " Reserved (should be zero) [%d]\n", c->reserved);
218 seq_printf(seq, " Name %s\n\n", c->name);
219 break;
220 case RSC_DEVMEM:
221 d = rsc;
222 seq_printf(seq, "Entry %d is of type %s\n", i, types[hdr->type]);
223 seq_printf(seq, " Device Address 0x%x\n", d->da);
224 seq_printf(seq, " Physical Address 0x%x\n", d->pa);
225 seq_printf(seq, " Length 0x%x Bytes\n", d->len);
226 seq_printf(seq, " Flags 0x%x\n", d->flags);
227 seq_printf(seq, " Reserved (should be zero) [%d]\n", d->reserved);
228 seq_printf(seq, " Name %s\n\n", d->name);
229 break;
230 case RSC_TRACE:
231 t = rsc;
232 seq_printf(seq, "Entry %d is of type %s\n", i, types[hdr->type]);
233 seq_printf(seq, " Device Address 0x%x\n", t->da);
234 seq_printf(seq, " Length 0x%x Bytes\n", t->len);
235 seq_printf(seq, " Reserved (should be zero) [%d]\n", t->reserved);
236 seq_printf(seq, " Name %s\n\n", t->name);
237 break;
238 case RSC_VDEV:
239 v = rsc;
240 seq_printf(seq, "Entry %d is of type %s\n", i, types[hdr->type]);
241
242 seq_printf(seq, " ID %d\n", v->id);
243 seq_printf(seq, " Notify ID %d\n", v->notifyid);
244 seq_printf(seq, " Device features 0x%x\n", v->dfeatures);
245 seq_printf(seq, " Guest features 0x%x\n", v->gfeatures);
246 seq_printf(seq, " Config length 0x%x\n", v->config_len);
247 seq_printf(seq, " Status 0x%x\n", v->status);
248 seq_printf(seq, " Number of vrings %d\n", v->num_of_vrings);
249 seq_printf(seq, " Reserved (should be zero) [%d][%d]\n\n",
250 v->reserved[0], v->reserved[1]);
251
252 for (j = 0; j < v->num_of_vrings; j++) {
253 seq_printf(seq, " Vring %d\n", j);
254 seq_printf(seq, " Device Address 0x%x\n", v->vring[j].da);
255 seq_printf(seq, " Alignment %d\n", v->vring[j].align);
256 seq_printf(seq, " Number of buffers %d\n", v->vring[j].num);
257 seq_printf(seq, " Notify ID %d\n", v->vring[j].notifyid);
258 seq_printf(seq, " Physical Address 0x%x\n\n",
259 v->vring[j].pa);
260 }
261 break;
262 default:
263 seq_printf(seq, "Unknown resource type found: %d [hdr: %pK]\n",
264 hdr->type, hdr);
265 break;
266 }
267 }
268
269 return 0;
270 }
271
272 static int rproc_rsc_table_open(struct inode *inode, struct file *file)
273 {
274 return single_open(file, rproc_rsc_table_show, inode->i_private);
275 }
276
277 static const struct file_operations rproc_rsc_table_ops = {
278 .open = rproc_rsc_table_open,
279 .read = seq_read,
280 .llseek = seq_lseek,
281 .release = single_release,
282 };
283
284
285 static int rproc_carveouts_show(struct seq_file *seq, void *p)
286 {
287 struct rproc *rproc = seq->private;
288 struct rproc_mem_entry *carveout;
289
290 list_for_each_entry(carveout, &rproc->carveouts, node) {
291 seq_puts(seq, "Carveout memory entry:\n");
292 seq_printf(seq, "\tName: %s\n", carveout->name);
293 seq_printf(seq, "\tVirtual address: %pK\n", carveout->va);
294 seq_printf(seq, "\tDMA address: %pad\n", &carveout->dma);
295 seq_printf(seq, "\tDevice address: 0x%x\n", carveout->da);
296 seq_printf(seq, "\tLength: 0x%x Bytes\n\n", carveout->len);
297 }
298
299 return 0;
300 }
301
302 static int rproc_carveouts_open(struct inode *inode, struct file *file)
303 {
304 return single_open(file, rproc_carveouts_show, inode->i_private);
305 }
306
307 static const struct file_operations rproc_carveouts_ops = {
308 .open = rproc_carveouts_open,
309 .read = seq_read,
310 .llseek = seq_lseek,
311 .release = single_release,
312 };
313
314 void rproc_remove_trace_file(struct dentry *tfile)
315 {
316 debugfs_remove(tfile);
317 }
318
319 struct dentry *rproc_create_trace_file(const char *name, struct rproc *rproc,
320 struct rproc_debug_trace *trace)
321 {
322 struct dentry *tfile;
323
324 tfile = debugfs_create_file(name, 0400, rproc->dbg_dir, trace,
325 &trace_rproc_ops);
326 if (!tfile) {
327 dev_err(&rproc->dev, "failed to create debugfs trace entry\n");
328 return NULL;
329 }
330
331 return tfile;
332 }
333
334 void rproc_delete_debug_dir(struct rproc *rproc)
335 {
336 if (!rproc->dbg_dir)
337 return;
338
339 debugfs_remove_recursive(rproc->dbg_dir);
340 }
341
342 void rproc_create_debug_dir(struct rproc *rproc)
343 {
344 struct device *dev = &rproc->dev;
345
346 if (!rproc_dbg)
347 return;
348
349 rproc->dbg_dir = debugfs_create_dir(dev_name(dev), rproc_dbg);
350 if (!rproc->dbg_dir)
351 return;
352
353 debugfs_create_file("name", 0400, rproc->dbg_dir,
354 rproc, &rproc_name_ops);
355 debugfs_create_file("recovery", 0400, rproc->dbg_dir,
356 rproc, &rproc_recovery_ops);
357 debugfs_create_file("crash", 0200, rproc->dbg_dir,
358 rproc, &rproc_crash_ops);
359 debugfs_create_file("resource_table", 0400, rproc->dbg_dir,
360 rproc, &rproc_rsc_table_ops);
361 debugfs_create_file("carveout_memories", 0400, rproc->dbg_dir,
362 rproc, &rproc_carveouts_ops);
363 }
364
365 void __init rproc_init_debugfs(void)
366 {
367 if (debugfs_initialized()) {
368 rproc_dbg = debugfs_create_dir(KBUILD_MODNAME, NULL);
369 if (!rproc_dbg)
370 pr_err("can't create debugfs dir\n");
371 }
372 }
373
374 void __exit rproc_exit_debugfs(void)
375 {
376 debugfs_remove(rproc_dbg);
377 }