2 * Remote Processor Framework
4 * Copyright (C) 2011 Texas Instruments, Inc.
5 * Copyright (C) 2011 Google, Inc.
7 * Ohad Ben-Cohen <ohad@wizery.com>
8 * Mark Grosen <mgrosen@ti.com>
9 * Brian Swetland <swetland@google.com>
10 * Fernando Guzman Lugo <fernando.lugo@ti.com>
11 * Suman Anna <s-anna@ti.com>
12 * Robert Tivy <rtivy@ti.com>
13 * Armando Uribe De Leon <x0095078@ti.com>
15 * This program is free software; you can redistribute it and/or
16 * modify it under the terms of the GNU General Public License
17 * version 2 as published by the Free Software Foundation.
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
25 #define pr_fmt(fmt) "%s: " fmt, __func__
27 #include <linux/kernel.h>
28 #include <linux/debugfs.h>
29 #include <linux/remoteproc.h>
30 #include <linux/device.h>
31 #include <linux/uaccess.h>
33 #include "remoteproc_internal.h"
35 /* remoteproc debugfs parent dir */
36 static struct dentry
*rproc_dbg
;
39 * Some remote processors may support dumping trace logs into a shared
40 * memory buffer. We expose this trace buffer using debugfs, so users
41 * can easily tell what's going on remotely.
43 * We will most probably improve the rproc tracing facilities later on,
44 * but this kind of lightweight and simple mechanism is always good to have,
45 * as it provides very early tracing with little to no dependencies at all.
47 static ssize_t
rproc_trace_read(struct file
*filp
, char __user
*userbuf
,
48 size_t count
, loff_t
*ppos
)
50 struct rproc_mem_entry
*trace
= filp
->private_data
;
51 int len
= strnlen(trace
->va
, trace
->len
);
53 return simple_read_from_buffer(userbuf
, count
, ppos
, trace
->va
, len
);
56 static const struct file_operations trace_rproc_ops
= {
57 .read
= rproc_trace_read
,
59 .llseek
= generic_file_llseek
,
62 /* expose the name of the remote processor via debugfs */
63 static ssize_t
rproc_name_read(struct file
*filp
, char __user
*userbuf
,
64 size_t count
, loff_t
*ppos
)
66 struct rproc
*rproc
= filp
->private_data
;
67 /* need room for the name, a newline and a terminating null */
71 i
= scnprintf(buf
, sizeof(buf
), "%.98s\n", rproc
->name
);
73 return simple_read_from_buffer(userbuf
, count
, ppos
, buf
, i
);
76 static const struct file_operations rproc_name_ops
= {
77 .read
= rproc_name_read
,
79 .llseek
= generic_file_llseek
,
82 /* expose recovery flag via debugfs */
83 static ssize_t
rproc_recovery_read(struct file
*filp
, char __user
*userbuf
,
84 size_t count
, loff_t
*ppos
)
86 struct rproc
*rproc
= filp
->private_data
;
87 char *buf
= rproc
->recovery_disabled
? "disabled\n" : "enabled\n";
89 return simple_read_from_buffer(userbuf
, count
, ppos
, buf
, strlen(buf
));
93 * By writing to the 'recovery' debugfs entry, we control the behavior of the
94 * recovery mechanism dynamically. The default value of this entry is "enabled".
96 * The 'recovery' debugfs entry supports these commands:
98 * enabled: When enabled, the remote processor will be automatically
99 * recovered whenever it crashes. Moreover, if the remote
100 * processor crashes while recovery is disabled, it will
101 * be automatically recovered too as soon as recovery is enabled.
103 * disabled: When disabled, a remote processor will remain in a crashed
104 * state if it crashes. This is useful for debugging purposes;
105 * without it, debugging a crash is substantially harder.
107 * recover: This function will trigger an immediate recovery if the
108 * remote processor is in a crashed state, without changing
109 * or checking the recovery state (enabled/disabled).
110 * This is useful during debugging sessions, when one expects
111 * additional crashes to happen after enabling recovery. In this
112 * case, enabling recovery will make it hard to debug subsequent
113 * crashes, so it's recommended to keep recovery disabled, and
114 * instead use the "recover" command as needed.
117 rproc_recovery_write(struct file
*filp
, const char __user
*user_buf
,
118 size_t count
, loff_t
*ppos
)
120 struct rproc
*rproc
= filp
->private_data
;
124 if (count
< 1 || count
> sizeof(buf
))
127 ret
= copy_from_user(buf
, user_buf
, count
);
131 /* remove end of line */
132 if (buf
[count
- 1] == '\n')
133 buf
[count
- 1] = '\0';
135 if (!strncmp(buf
, "enabled", count
)) {
136 rproc
->recovery_disabled
= false;
137 /* if rproc has crashed, trigger recovery */
138 if (rproc
->state
== RPROC_CRASHED
)
139 rproc_trigger_recovery(rproc
);
140 } else if (!strncmp(buf
, "disabled", count
)) {
141 rproc
->recovery_disabled
= true;
142 } else if (!strncmp(buf
, "recover", count
)) {
143 /* if rproc has crashed, trigger recovery */
144 if (rproc
->state
== RPROC_CRASHED
)
145 rproc_trigger_recovery(rproc
);
151 static const struct file_operations rproc_recovery_ops
= {
152 .read
= rproc_recovery_read
,
153 .write
= rproc_recovery_write
,
155 .llseek
= generic_file_llseek
,
158 void rproc_remove_trace_file(struct dentry
*tfile
)
160 debugfs_remove(tfile
);
163 struct dentry
*rproc_create_trace_file(const char *name
, struct rproc
*rproc
,
164 struct rproc_mem_entry
*trace
)
166 struct dentry
*tfile
;
168 tfile
= debugfs_create_file(name
, 0400, rproc
->dbg_dir
, trace
,
171 dev_err(&rproc
->dev
, "failed to create debugfs trace entry\n");
178 void rproc_delete_debug_dir(struct rproc
*rproc
)
183 debugfs_remove_recursive(rproc
->dbg_dir
);
186 void rproc_create_debug_dir(struct rproc
*rproc
)
188 struct device
*dev
= &rproc
->dev
;
193 rproc
->dbg_dir
= debugfs_create_dir(dev_name(dev
), rproc_dbg
);
197 debugfs_create_file("name", 0400, rproc
->dbg_dir
,
198 rproc
, &rproc_name_ops
);
199 debugfs_create_file("recovery", 0400, rproc
->dbg_dir
,
200 rproc
, &rproc_recovery_ops
);
203 void __init
rproc_init_debugfs(void)
205 if (debugfs_initialized()) {
206 rproc_dbg
= debugfs_create_dir(KBUILD_MODNAME
, NULL
);
208 pr_err("can't create debugfs dir\n");
212 void __exit
rproc_exit_debugfs(void)
214 debugfs_remove(rproc_dbg
);