xref: /OK3568_Linux_fs/kernel/drivers/remoteproc/remoteproc_debugfs.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun // SPDX-License-Identifier: GPL-2.0-only
2*4882a593Smuzhiyun /*
3*4882a593Smuzhiyun  * Remote Processor Framework
4*4882a593Smuzhiyun  *
5*4882a593Smuzhiyun  * Copyright (C) 2011 Texas Instruments, Inc.
6*4882a593Smuzhiyun  * Copyright (C) 2011 Google, Inc.
7*4882a593Smuzhiyun  *
8*4882a593Smuzhiyun  * Ohad Ben-Cohen <ohad@wizery.com>
9*4882a593Smuzhiyun  * Mark Grosen <mgrosen@ti.com>
10*4882a593Smuzhiyun  * Brian Swetland <swetland@google.com>
11*4882a593Smuzhiyun  * Fernando Guzman Lugo <fernando.lugo@ti.com>
12*4882a593Smuzhiyun  * Suman Anna <s-anna@ti.com>
13*4882a593Smuzhiyun  * Robert Tivy <rtivy@ti.com>
14*4882a593Smuzhiyun  * Armando Uribe De Leon <x0095078@ti.com>
15*4882a593Smuzhiyun  */
16*4882a593Smuzhiyun 
17*4882a593Smuzhiyun #define pr_fmt(fmt)    "%s: " fmt, __func__
18*4882a593Smuzhiyun 
19*4882a593Smuzhiyun #include <linux/kernel.h>
20*4882a593Smuzhiyun #include <linux/debugfs.h>
21*4882a593Smuzhiyun #include <linux/remoteproc.h>
22*4882a593Smuzhiyun #include <linux/device.h>
23*4882a593Smuzhiyun #include <linux/uaccess.h>
24*4882a593Smuzhiyun 
25*4882a593Smuzhiyun #include "remoteproc_internal.h"
26*4882a593Smuzhiyun 
27*4882a593Smuzhiyun /* remoteproc debugfs parent dir */
28*4882a593Smuzhiyun static struct dentry *rproc_dbg;
29*4882a593Smuzhiyun 
30*4882a593Smuzhiyun /*
31*4882a593Smuzhiyun  * A coredump-configuration-to-string lookup table, for exposing a
32*4882a593Smuzhiyun  * human readable configuration via debugfs. Always keep in sync with
33*4882a593Smuzhiyun  * enum rproc_coredump_mechanism
34*4882a593Smuzhiyun  */
35*4882a593Smuzhiyun static const char * const rproc_coredump_str[] = {
36*4882a593Smuzhiyun 	[RPROC_COREDUMP_DISABLED]	= "disabled",
37*4882a593Smuzhiyun 	[RPROC_COREDUMP_ENABLED]	= "enabled",
38*4882a593Smuzhiyun 	[RPROC_COREDUMP_INLINE]		= "inline",
39*4882a593Smuzhiyun };
40*4882a593Smuzhiyun 
41*4882a593Smuzhiyun /* Expose the current coredump configuration via debugfs */
rproc_coredump_read(struct file * filp,char __user * userbuf,size_t count,loff_t * ppos)42*4882a593Smuzhiyun static ssize_t rproc_coredump_read(struct file *filp, char __user *userbuf,
43*4882a593Smuzhiyun 				   size_t count, loff_t *ppos)
44*4882a593Smuzhiyun {
45*4882a593Smuzhiyun 	struct rproc *rproc = filp->private_data;
46*4882a593Smuzhiyun 	char buf[20];
47*4882a593Smuzhiyun 	int len;
48*4882a593Smuzhiyun 
49*4882a593Smuzhiyun 	len = scnprintf(buf, sizeof(buf), "%s\n",
50*4882a593Smuzhiyun 			rproc_coredump_str[rproc->dump_conf]);
51*4882a593Smuzhiyun 
52*4882a593Smuzhiyun 	return simple_read_from_buffer(userbuf, count, ppos, buf, len);
53*4882a593Smuzhiyun }
54*4882a593Smuzhiyun 
55*4882a593Smuzhiyun /*
56*4882a593Smuzhiyun  * By writing to the 'coredump' debugfs entry, we control the behavior of the
57*4882a593Smuzhiyun  * coredump mechanism dynamically. The default value of this entry is "disabled".
58*4882a593Smuzhiyun  *
59*4882a593Smuzhiyun  * The 'coredump' debugfs entry supports these commands:
60*4882a593Smuzhiyun  *
61*4882a593Smuzhiyun  * disabled:	By default coredump collection is disabled. Recovery will
62*4882a593Smuzhiyun  *		proceed without collecting any dump.
63*4882a593Smuzhiyun  *
64*4882a593Smuzhiyun  * enabled:	When the remoteproc crashes the entire coredump will be copied
65*4882a593Smuzhiyun  *		to a separate buffer and exposed to userspace.
66*4882a593Smuzhiyun  *
67*4882a593Smuzhiyun  * inline:	The coredump will not be copied to a separate buffer and the
68*4882a593Smuzhiyun  *		recovery process will have to wait until data is read by
69*4882a593Smuzhiyun  *		userspace. But this avoid usage of extra memory.
70*4882a593Smuzhiyun  */
rproc_coredump_write(struct file * filp,const char __user * user_buf,size_t count,loff_t * ppos)71*4882a593Smuzhiyun static ssize_t rproc_coredump_write(struct file *filp,
72*4882a593Smuzhiyun 				    const char __user *user_buf, size_t count,
73*4882a593Smuzhiyun 				    loff_t *ppos)
74*4882a593Smuzhiyun {
75*4882a593Smuzhiyun 	struct rproc *rproc = filp->private_data;
76*4882a593Smuzhiyun 	int ret, err = 0;
77*4882a593Smuzhiyun 	char buf[20];
78*4882a593Smuzhiyun 
79*4882a593Smuzhiyun 	if (count < 1 || count > sizeof(buf))
80*4882a593Smuzhiyun 		return -EINVAL;
81*4882a593Smuzhiyun 
82*4882a593Smuzhiyun 	ret = copy_from_user(buf, user_buf, count);
83*4882a593Smuzhiyun 	if (ret)
84*4882a593Smuzhiyun 		return -EFAULT;
85*4882a593Smuzhiyun 
86*4882a593Smuzhiyun 	/* remove end of line */
87*4882a593Smuzhiyun 	if (buf[count - 1] == '\n')
88*4882a593Smuzhiyun 		buf[count - 1] = '\0';
89*4882a593Smuzhiyun 
90*4882a593Smuzhiyun 	if (rproc->state == RPROC_CRASHED) {
91*4882a593Smuzhiyun 		dev_err(&rproc->dev, "can't change coredump configuration\n");
92*4882a593Smuzhiyun 		err = -EBUSY;
93*4882a593Smuzhiyun 		goto out;
94*4882a593Smuzhiyun 	}
95*4882a593Smuzhiyun 
96*4882a593Smuzhiyun 	if (!strncmp(buf, "disabled", count)) {
97*4882a593Smuzhiyun 		rproc->dump_conf = RPROC_COREDUMP_DISABLED;
98*4882a593Smuzhiyun 	} else if (!strncmp(buf, "enabled", count)) {
99*4882a593Smuzhiyun 		rproc->dump_conf = RPROC_COREDUMP_ENABLED;
100*4882a593Smuzhiyun 	} else if (!strncmp(buf, "inline", count)) {
101*4882a593Smuzhiyun 		rproc->dump_conf = RPROC_COREDUMP_INLINE;
102*4882a593Smuzhiyun 	} else {
103*4882a593Smuzhiyun 		dev_err(&rproc->dev, "Invalid coredump configuration\n");
104*4882a593Smuzhiyun 		err = -EINVAL;
105*4882a593Smuzhiyun 	}
106*4882a593Smuzhiyun out:
107*4882a593Smuzhiyun 	return err ? err : count;
108*4882a593Smuzhiyun }
109*4882a593Smuzhiyun 
110*4882a593Smuzhiyun static const struct file_operations rproc_coredump_fops = {
111*4882a593Smuzhiyun 	.read = rproc_coredump_read,
112*4882a593Smuzhiyun 	.write = rproc_coredump_write,
113*4882a593Smuzhiyun 	.open = simple_open,
114*4882a593Smuzhiyun 	.llseek = generic_file_llseek,
115*4882a593Smuzhiyun };
116*4882a593Smuzhiyun 
117*4882a593Smuzhiyun /*
118*4882a593Smuzhiyun  * Some remote processors may support dumping trace logs into a shared
119*4882a593Smuzhiyun  * memory buffer. We expose this trace buffer using debugfs, so users
120*4882a593Smuzhiyun  * can easily tell what's going on remotely.
121*4882a593Smuzhiyun  *
122*4882a593Smuzhiyun  * We will most probably improve the rproc tracing facilities later on,
123*4882a593Smuzhiyun  * but this kind of lightweight and simple mechanism is always good to have,
124*4882a593Smuzhiyun  * as it provides very early tracing with little to no dependencies at all.
125*4882a593Smuzhiyun  */
rproc_trace_read(struct file * filp,char __user * userbuf,size_t count,loff_t * ppos)126*4882a593Smuzhiyun static ssize_t rproc_trace_read(struct file *filp, char __user *userbuf,
127*4882a593Smuzhiyun 				size_t count, loff_t *ppos)
128*4882a593Smuzhiyun {
129*4882a593Smuzhiyun 	struct rproc_debug_trace *data = filp->private_data;
130*4882a593Smuzhiyun 	struct rproc_mem_entry *trace = &data->trace_mem;
131*4882a593Smuzhiyun 	void *va;
132*4882a593Smuzhiyun 	char buf[100];
133*4882a593Smuzhiyun 	int len;
134*4882a593Smuzhiyun 
135*4882a593Smuzhiyun 	va = rproc_da_to_va(data->rproc, trace->da, trace->len, NULL);
136*4882a593Smuzhiyun 
137*4882a593Smuzhiyun 	if (!va) {
138*4882a593Smuzhiyun 		len = scnprintf(buf, sizeof(buf), "Trace %s not available\n",
139*4882a593Smuzhiyun 				trace->name);
140*4882a593Smuzhiyun 		va = buf;
141*4882a593Smuzhiyun 	} else {
142*4882a593Smuzhiyun 		len = strnlen(va, trace->len);
143*4882a593Smuzhiyun 	}
144*4882a593Smuzhiyun 
145*4882a593Smuzhiyun 	return simple_read_from_buffer(userbuf, count, ppos, va, len);
146*4882a593Smuzhiyun }
147*4882a593Smuzhiyun 
148*4882a593Smuzhiyun static const struct file_operations trace_rproc_ops = {
149*4882a593Smuzhiyun 	.read = rproc_trace_read,
150*4882a593Smuzhiyun 	.open = simple_open,
151*4882a593Smuzhiyun 	.llseek	= generic_file_llseek,
152*4882a593Smuzhiyun };
153*4882a593Smuzhiyun 
154*4882a593Smuzhiyun /* expose the name of the remote processor via debugfs */
rproc_name_read(struct file * filp,char __user * userbuf,size_t count,loff_t * ppos)155*4882a593Smuzhiyun static ssize_t rproc_name_read(struct file *filp, char __user *userbuf,
156*4882a593Smuzhiyun 			       size_t count, loff_t *ppos)
157*4882a593Smuzhiyun {
158*4882a593Smuzhiyun 	struct rproc *rproc = filp->private_data;
159*4882a593Smuzhiyun 	/* need room for the name, a newline and a terminating null */
160*4882a593Smuzhiyun 	char buf[100];
161*4882a593Smuzhiyun 	int i;
162*4882a593Smuzhiyun 
163*4882a593Smuzhiyun 	i = scnprintf(buf, sizeof(buf), "%.98s\n", rproc->name);
164*4882a593Smuzhiyun 
165*4882a593Smuzhiyun 	return simple_read_from_buffer(userbuf, count, ppos, buf, i);
166*4882a593Smuzhiyun }
167*4882a593Smuzhiyun 
168*4882a593Smuzhiyun static const struct file_operations rproc_name_ops = {
169*4882a593Smuzhiyun 	.read = rproc_name_read,
170*4882a593Smuzhiyun 	.open = simple_open,
171*4882a593Smuzhiyun 	.llseek	= generic_file_llseek,
172*4882a593Smuzhiyun };
173*4882a593Smuzhiyun 
174*4882a593Smuzhiyun /* expose recovery flag via debugfs */
rproc_recovery_read(struct file * filp,char __user * userbuf,size_t count,loff_t * ppos)175*4882a593Smuzhiyun static ssize_t rproc_recovery_read(struct file *filp, char __user *userbuf,
176*4882a593Smuzhiyun 				   size_t count, loff_t *ppos)
177*4882a593Smuzhiyun {
178*4882a593Smuzhiyun 	struct rproc *rproc = filp->private_data;
179*4882a593Smuzhiyun 	char *buf = rproc->recovery_disabled ? "disabled\n" : "enabled\n";
180*4882a593Smuzhiyun 
181*4882a593Smuzhiyun 	return simple_read_from_buffer(userbuf, count, ppos, buf, strlen(buf));
182*4882a593Smuzhiyun }
183*4882a593Smuzhiyun 
184*4882a593Smuzhiyun /*
185*4882a593Smuzhiyun  * By writing to the 'recovery' debugfs entry, we control the behavior of the
186*4882a593Smuzhiyun  * recovery mechanism dynamically. The default value of this entry is "enabled".
187*4882a593Smuzhiyun  *
188*4882a593Smuzhiyun  * The 'recovery' debugfs entry supports these commands:
189*4882a593Smuzhiyun  *
190*4882a593Smuzhiyun  * enabled:	When enabled, the remote processor will be automatically
191*4882a593Smuzhiyun  *		recovered whenever it crashes. Moreover, if the remote
192*4882a593Smuzhiyun  *		processor crashes while recovery is disabled, it will
193*4882a593Smuzhiyun  *		be automatically recovered too as soon as recovery is enabled.
194*4882a593Smuzhiyun  *
195*4882a593Smuzhiyun  * disabled:	When disabled, a remote processor will remain in a crashed
196*4882a593Smuzhiyun  *		state if it crashes. This is useful for debugging purposes;
197*4882a593Smuzhiyun  *		without it, debugging a crash is substantially harder.
198*4882a593Smuzhiyun  *
199*4882a593Smuzhiyun  * recover:	This function will trigger an immediate recovery if the
200*4882a593Smuzhiyun  *		remote processor is in a crashed state, without changing
201*4882a593Smuzhiyun  *		or checking the recovery state (enabled/disabled).
202*4882a593Smuzhiyun  *		This is useful during debugging sessions, when one expects
203*4882a593Smuzhiyun  *		additional crashes to happen after enabling recovery. In this
204*4882a593Smuzhiyun  *		case, enabling recovery will make it hard to debug subsequent
205*4882a593Smuzhiyun  *		crashes, so it's recommended to keep recovery disabled, and
206*4882a593Smuzhiyun  *		instead use the "recover" command as needed.
207*4882a593Smuzhiyun  */
208*4882a593Smuzhiyun static ssize_t
rproc_recovery_write(struct file * filp,const char __user * user_buf,size_t count,loff_t * ppos)209*4882a593Smuzhiyun rproc_recovery_write(struct file *filp, const char __user *user_buf,
210*4882a593Smuzhiyun 		     size_t count, loff_t *ppos)
211*4882a593Smuzhiyun {
212*4882a593Smuzhiyun 	struct rproc *rproc = filp->private_data;
213*4882a593Smuzhiyun 	char buf[10];
214*4882a593Smuzhiyun 	int ret;
215*4882a593Smuzhiyun 
216*4882a593Smuzhiyun 	if (count < 1 || count > sizeof(buf))
217*4882a593Smuzhiyun 		return -EINVAL;
218*4882a593Smuzhiyun 
219*4882a593Smuzhiyun 	ret = copy_from_user(buf, user_buf, count);
220*4882a593Smuzhiyun 	if (ret)
221*4882a593Smuzhiyun 		return -EFAULT;
222*4882a593Smuzhiyun 
223*4882a593Smuzhiyun 	/* remove end of line */
224*4882a593Smuzhiyun 	if (buf[count - 1] == '\n')
225*4882a593Smuzhiyun 		buf[count - 1] = '\0';
226*4882a593Smuzhiyun 
227*4882a593Smuzhiyun 	if (!strncmp(buf, "enabled", count)) {
228*4882a593Smuzhiyun 		/* change the flag and begin the recovery process if needed */
229*4882a593Smuzhiyun 		rproc->recovery_disabled = false;
230*4882a593Smuzhiyun 		rproc_trigger_recovery(rproc);
231*4882a593Smuzhiyun 	} else if (!strncmp(buf, "disabled", count)) {
232*4882a593Smuzhiyun 		rproc->recovery_disabled = true;
233*4882a593Smuzhiyun 	} else if (!strncmp(buf, "recover", count)) {
234*4882a593Smuzhiyun 		/* begin the recovery process without changing the flag */
235*4882a593Smuzhiyun 		rproc_trigger_recovery(rproc);
236*4882a593Smuzhiyun 	} else {
237*4882a593Smuzhiyun 		return -EINVAL;
238*4882a593Smuzhiyun 	}
239*4882a593Smuzhiyun 
240*4882a593Smuzhiyun 	return count;
241*4882a593Smuzhiyun }
242*4882a593Smuzhiyun 
243*4882a593Smuzhiyun static const struct file_operations rproc_recovery_ops = {
244*4882a593Smuzhiyun 	.read = rproc_recovery_read,
245*4882a593Smuzhiyun 	.write = rproc_recovery_write,
246*4882a593Smuzhiyun 	.open = simple_open,
247*4882a593Smuzhiyun 	.llseek = generic_file_llseek,
248*4882a593Smuzhiyun };
249*4882a593Smuzhiyun 
250*4882a593Smuzhiyun /* expose the crash trigger via debugfs */
251*4882a593Smuzhiyun static ssize_t
rproc_crash_write(struct file * filp,const char __user * user_buf,size_t count,loff_t * ppos)252*4882a593Smuzhiyun rproc_crash_write(struct file *filp, const char __user *user_buf,
253*4882a593Smuzhiyun 		  size_t count, loff_t *ppos)
254*4882a593Smuzhiyun {
255*4882a593Smuzhiyun 	struct rproc *rproc = filp->private_data;
256*4882a593Smuzhiyun 	unsigned int type;
257*4882a593Smuzhiyun 	int ret;
258*4882a593Smuzhiyun 
259*4882a593Smuzhiyun 	ret = kstrtouint_from_user(user_buf, count, 0, &type);
260*4882a593Smuzhiyun 	if (ret < 0)
261*4882a593Smuzhiyun 		return ret;
262*4882a593Smuzhiyun 
263*4882a593Smuzhiyun 	rproc_report_crash(rproc, type);
264*4882a593Smuzhiyun 
265*4882a593Smuzhiyun 	return count;
266*4882a593Smuzhiyun }
267*4882a593Smuzhiyun 
268*4882a593Smuzhiyun static const struct file_operations rproc_crash_ops = {
269*4882a593Smuzhiyun 	.write = rproc_crash_write,
270*4882a593Smuzhiyun 	.open = simple_open,
271*4882a593Smuzhiyun 	.llseek = generic_file_llseek,
272*4882a593Smuzhiyun };
273*4882a593Smuzhiyun 
274*4882a593Smuzhiyun /* Expose resource table content via debugfs */
rproc_rsc_table_show(struct seq_file * seq,void * p)275*4882a593Smuzhiyun static int rproc_rsc_table_show(struct seq_file *seq, void *p)
276*4882a593Smuzhiyun {
277*4882a593Smuzhiyun 	static const char * const types[] = {"carveout", "devmem", "trace", "vdev"};
278*4882a593Smuzhiyun 	struct rproc *rproc = seq->private;
279*4882a593Smuzhiyun 	struct resource_table *table = rproc->table_ptr;
280*4882a593Smuzhiyun 	struct fw_rsc_carveout *c;
281*4882a593Smuzhiyun 	struct fw_rsc_devmem *d;
282*4882a593Smuzhiyun 	struct fw_rsc_trace *t;
283*4882a593Smuzhiyun 	struct fw_rsc_vdev *v;
284*4882a593Smuzhiyun 	int i, j;
285*4882a593Smuzhiyun 
286*4882a593Smuzhiyun 	if (!table) {
287*4882a593Smuzhiyun 		seq_puts(seq, "No resource table found\n");
288*4882a593Smuzhiyun 		return 0;
289*4882a593Smuzhiyun 	}
290*4882a593Smuzhiyun 
291*4882a593Smuzhiyun 	for (i = 0; i < table->num; i++) {
292*4882a593Smuzhiyun 		int offset = table->offset[i];
293*4882a593Smuzhiyun 		struct fw_rsc_hdr *hdr = (void *)table + offset;
294*4882a593Smuzhiyun 		void *rsc = (void *)hdr + sizeof(*hdr);
295*4882a593Smuzhiyun 
296*4882a593Smuzhiyun 		switch (hdr->type) {
297*4882a593Smuzhiyun 		case RSC_CARVEOUT:
298*4882a593Smuzhiyun 			c = rsc;
299*4882a593Smuzhiyun 			seq_printf(seq, "Entry %d is of type %s\n", i, types[hdr->type]);
300*4882a593Smuzhiyun 			seq_printf(seq, "  Device Address 0x%x\n", c->da);
301*4882a593Smuzhiyun 			seq_printf(seq, "  Physical Address 0x%x\n", c->pa);
302*4882a593Smuzhiyun 			seq_printf(seq, "  Length 0x%x Bytes\n", c->len);
303*4882a593Smuzhiyun 			seq_printf(seq, "  Flags 0x%x\n", c->flags);
304*4882a593Smuzhiyun 			seq_printf(seq, "  Reserved (should be zero) [%d]\n", c->reserved);
305*4882a593Smuzhiyun 			seq_printf(seq, "  Name %s\n\n", c->name);
306*4882a593Smuzhiyun 			break;
307*4882a593Smuzhiyun 		case RSC_DEVMEM:
308*4882a593Smuzhiyun 			d = rsc;
309*4882a593Smuzhiyun 			seq_printf(seq, "Entry %d is of type %s\n", i, types[hdr->type]);
310*4882a593Smuzhiyun 			seq_printf(seq, "  Device Address 0x%x\n", d->da);
311*4882a593Smuzhiyun 			seq_printf(seq, "  Physical Address 0x%x\n", d->pa);
312*4882a593Smuzhiyun 			seq_printf(seq, "  Length 0x%x Bytes\n", d->len);
313*4882a593Smuzhiyun 			seq_printf(seq, "  Flags 0x%x\n", d->flags);
314*4882a593Smuzhiyun 			seq_printf(seq, "  Reserved (should be zero) [%d]\n", d->reserved);
315*4882a593Smuzhiyun 			seq_printf(seq, "  Name %s\n\n", d->name);
316*4882a593Smuzhiyun 			break;
317*4882a593Smuzhiyun 		case RSC_TRACE:
318*4882a593Smuzhiyun 			t = rsc;
319*4882a593Smuzhiyun 			seq_printf(seq, "Entry %d is of type %s\n", i, types[hdr->type]);
320*4882a593Smuzhiyun 			seq_printf(seq, "  Device Address 0x%x\n", t->da);
321*4882a593Smuzhiyun 			seq_printf(seq, "  Length 0x%x Bytes\n", t->len);
322*4882a593Smuzhiyun 			seq_printf(seq, "  Reserved (should be zero) [%d]\n", t->reserved);
323*4882a593Smuzhiyun 			seq_printf(seq, "  Name %s\n\n", t->name);
324*4882a593Smuzhiyun 			break;
325*4882a593Smuzhiyun 		case RSC_VDEV:
326*4882a593Smuzhiyun 			v = rsc;
327*4882a593Smuzhiyun 			seq_printf(seq, "Entry %d is of type %s\n", i, types[hdr->type]);
328*4882a593Smuzhiyun 
329*4882a593Smuzhiyun 			seq_printf(seq, "  ID %d\n", v->id);
330*4882a593Smuzhiyun 			seq_printf(seq, "  Notify ID %d\n", v->notifyid);
331*4882a593Smuzhiyun 			seq_printf(seq, "  Device features 0x%x\n", v->dfeatures);
332*4882a593Smuzhiyun 			seq_printf(seq, "  Guest features 0x%x\n", v->gfeatures);
333*4882a593Smuzhiyun 			seq_printf(seq, "  Config length 0x%x\n", v->config_len);
334*4882a593Smuzhiyun 			seq_printf(seq, "  Status 0x%x\n", v->status);
335*4882a593Smuzhiyun 			seq_printf(seq, "  Number of vrings %d\n", v->num_of_vrings);
336*4882a593Smuzhiyun 			seq_printf(seq, "  Reserved (should be zero) [%d][%d]\n\n",
337*4882a593Smuzhiyun 				   v->reserved[0], v->reserved[1]);
338*4882a593Smuzhiyun 
339*4882a593Smuzhiyun 			for (j = 0; j < v->num_of_vrings; j++) {
340*4882a593Smuzhiyun 				seq_printf(seq, "  Vring %d\n", j);
341*4882a593Smuzhiyun 				seq_printf(seq, "    Device Address 0x%x\n", v->vring[j].da);
342*4882a593Smuzhiyun 				seq_printf(seq, "    Alignment %d\n", v->vring[j].align);
343*4882a593Smuzhiyun 				seq_printf(seq, "    Number of buffers %d\n", v->vring[j].num);
344*4882a593Smuzhiyun 				seq_printf(seq, "    Notify ID %d\n", v->vring[j].notifyid);
345*4882a593Smuzhiyun 				seq_printf(seq, "    Physical Address 0x%x\n\n",
346*4882a593Smuzhiyun 					   v->vring[j].pa);
347*4882a593Smuzhiyun 			}
348*4882a593Smuzhiyun 			break;
349*4882a593Smuzhiyun 		default:
350*4882a593Smuzhiyun 			seq_printf(seq, "Unknown resource type found: %d [hdr: %pK]\n",
351*4882a593Smuzhiyun 				   hdr->type, hdr);
352*4882a593Smuzhiyun 			break;
353*4882a593Smuzhiyun 		}
354*4882a593Smuzhiyun 	}
355*4882a593Smuzhiyun 
356*4882a593Smuzhiyun 	return 0;
357*4882a593Smuzhiyun }
358*4882a593Smuzhiyun 
359*4882a593Smuzhiyun DEFINE_SHOW_ATTRIBUTE(rproc_rsc_table);
360*4882a593Smuzhiyun 
361*4882a593Smuzhiyun /* Expose carveout content via debugfs */
rproc_carveouts_show(struct seq_file * seq,void * p)362*4882a593Smuzhiyun static int rproc_carveouts_show(struct seq_file *seq, void *p)
363*4882a593Smuzhiyun {
364*4882a593Smuzhiyun 	struct rproc *rproc = seq->private;
365*4882a593Smuzhiyun 	struct rproc_mem_entry *carveout;
366*4882a593Smuzhiyun 
367*4882a593Smuzhiyun 	list_for_each_entry(carveout, &rproc->carveouts, node) {
368*4882a593Smuzhiyun 		seq_puts(seq, "Carveout memory entry:\n");
369*4882a593Smuzhiyun 		seq_printf(seq, "\tName: %s\n", carveout->name);
370*4882a593Smuzhiyun 		seq_printf(seq, "\tVirtual address: %pK\n", carveout->va);
371*4882a593Smuzhiyun 		seq_printf(seq, "\tDMA address: %pad\n", &carveout->dma);
372*4882a593Smuzhiyun 		seq_printf(seq, "\tDevice address: 0x%x\n", carveout->da);
373*4882a593Smuzhiyun 		seq_printf(seq, "\tLength: 0x%zx Bytes\n\n", carveout->len);
374*4882a593Smuzhiyun 	}
375*4882a593Smuzhiyun 
376*4882a593Smuzhiyun 	return 0;
377*4882a593Smuzhiyun }
378*4882a593Smuzhiyun 
379*4882a593Smuzhiyun DEFINE_SHOW_ATTRIBUTE(rproc_carveouts);
380*4882a593Smuzhiyun 
rproc_remove_trace_file(struct dentry * tfile)381*4882a593Smuzhiyun void rproc_remove_trace_file(struct dentry *tfile)
382*4882a593Smuzhiyun {
383*4882a593Smuzhiyun 	debugfs_remove(tfile);
384*4882a593Smuzhiyun }
385*4882a593Smuzhiyun 
rproc_create_trace_file(const char * name,struct rproc * rproc,struct rproc_debug_trace * trace)386*4882a593Smuzhiyun struct dentry *rproc_create_trace_file(const char *name, struct rproc *rproc,
387*4882a593Smuzhiyun 				       struct rproc_debug_trace *trace)
388*4882a593Smuzhiyun {
389*4882a593Smuzhiyun 	struct dentry *tfile;
390*4882a593Smuzhiyun 
391*4882a593Smuzhiyun 	tfile = debugfs_create_file(name, 0400, rproc->dbg_dir, trace,
392*4882a593Smuzhiyun 				    &trace_rproc_ops);
393*4882a593Smuzhiyun 	if (!tfile) {
394*4882a593Smuzhiyun 		dev_err(&rproc->dev, "failed to create debugfs trace entry\n");
395*4882a593Smuzhiyun 		return NULL;
396*4882a593Smuzhiyun 	}
397*4882a593Smuzhiyun 
398*4882a593Smuzhiyun 	return tfile;
399*4882a593Smuzhiyun }
400*4882a593Smuzhiyun 
rproc_delete_debug_dir(struct rproc * rproc)401*4882a593Smuzhiyun void rproc_delete_debug_dir(struct rproc *rproc)
402*4882a593Smuzhiyun {
403*4882a593Smuzhiyun 	debugfs_remove_recursive(rproc->dbg_dir);
404*4882a593Smuzhiyun }
405*4882a593Smuzhiyun 
rproc_create_debug_dir(struct rproc * rproc)406*4882a593Smuzhiyun void rproc_create_debug_dir(struct rproc *rproc)
407*4882a593Smuzhiyun {
408*4882a593Smuzhiyun 	struct device *dev = &rproc->dev;
409*4882a593Smuzhiyun 
410*4882a593Smuzhiyun 	if (!rproc_dbg)
411*4882a593Smuzhiyun 		return;
412*4882a593Smuzhiyun 
413*4882a593Smuzhiyun 	rproc->dbg_dir = debugfs_create_dir(dev_name(dev), rproc_dbg);
414*4882a593Smuzhiyun 	if (!rproc->dbg_dir)
415*4882a593Smuzhiyun 		return;
416*4882a593Smuzhiyun 
417*4882a593Smuzhiyun 	debugfs_create_file("name", 0400, rproc->dbg_dir,
418*4882a593Smuzhiyun 			    rproc, &rproc_name_ops);
419*4882a593Smuzhiyun 	debugfs_create_file("recovery", 0600, rproc->dbg_dir,
420*4882a593Smuzhiyun 			    rproc, &rproc_recovery_ops);
421*4882a593Smuzhiyun 	debugfs_create_file("crash", 0200, rproc->dbg_dir,
422*4882a593Smuzhiyun 			    rproc, &rproc_crash_ops);
423*4882a593Smuzhiyun 	debugfs_create_file("resource_table", 0400, rproc->dbg_dir,
424*4882a593Smuzhiyun 			    rproc, &rproc_rsc_table_fops);
425*4882a593Smuzhiyun 	debugfs_create_file("carveout_memories", 0400, rproc->dbg_dir,
426*4882a593Smuzhiyun 			    rproc, &rproc_carveouts_fops);
427*4882a593Smuzhiyun 	debugfs_create_file("coredump", 0600, rproc->dbg_dir,
428*4882a593Smuzhiyun 			    rproc, &rproc_coredump_fops);
429*4882a593Smuzhiyun }
430*4882a593Smuzhiyun 
rproc_init_debugfs(void)431*4882a593Smuzhiyun void __init rproc_init_debugfs(void)
432*4882a593Smuzhiyun {
433*4882a593Smuzhiyun 	if (debugfs_initialized()) {
434*4882a593Smuzhiyun 		rproc_dbg = debugfs_create_dir(KBUILD_MODNAME, NULL);
435*4882a593Smuzhiyun 		if (!rproc_dbg)
436*4882a593Smuzhiyun 			pr_err("can't create debugfs dir\n");
437*4882a593Smuzhiyun 	}
438*4882a593Smuzhiyun }
439*4882a593Smuzhiyun 
rproc_exit_debugfs(void)440*4882a593Smuzhiyun void __exit rproc_exit_debugfs(void)
441*4882a593Smuzhiyun {
442*4882a593Smuzhiyun 	debugfs_remove(rproc_dbg);
443*4882a593Smuzhiyun }
444