1
2
3
4
5
6
7
8
9#include <linux/module.h>
10#include <linux/stm.h>
11#include <linux/trace.h>
12
13#define STM_FTRACE_NR_CHANNELS 1
14#define STM_FTRACE_CHAN 0
15
16static int stm_ftrace_link(struct stm_source_data *data);
17static void stm_ftrace_unlink(struct stm_source_data *data);
18
19static struct stm_ftrace {
20 struct stm_source_data data;
21 struct trace_export ftrace;
22} stm_ftrace = {
23 .data = {
24 .name = "ftrace",
25 .nr_chans = STM_FTRACE_NR_CHANNELS,
26 .link = stm_ftrace_link,
27 .unlink = stm_ftrace_unlink,
28 },
29};
30
31
32
33
34
35
36static void notrace
37stm_ftrace_write(struct trace_export *export, const void *buf, unsigned int len)
38{
39 struct stm_ftrace *stm = container_of(export, struct stm_ftrace, ftrace);
40
41 stm_source_write(&stm->data, STM_FTRACE_CHAN, buf, len);
42}
43
44static int stm_ftrace_link(struct stm_source_data *data)
45{
46 struct stm_ftrace *sf = container_of(data, struct stm_ftrace, data);
47
48 sf->ftrace.write = stm_ftrace_write;
49
50 return register_ftrace_export(&sf->ftrace);
51}
52
53static void stm_ftrace_unlink(struct stm_source_data *data)
54{
55 struct stm_ftrace *sf = container_of(data, struct stm_ftrace, data);
56
57 unregister_ftrace_export(&sf->ftrace);
58}
59
60static int __init stm_ftrace_init(void)
61{
62 int ret;
63
64 ret = stm_source_register_device(NULL, &stm_ftrace.data);
65 if (ret)
66 pr_err("Failed to register stm_source - ftrace.\n");
67
68 return ret;
69}
70
71static void __exit stm_ftrace_exit(void)
72{
73 stm_source_unregister_device(&stm_ftrace.data);
74}
75
76module_init(stm_ftrace_init);
77module_exit(stm_ftrace_exit);
78
79MODULE_LICENSE("GPL v2");
80MODULE_DESCRIPTION("stm_ftrace driver");
81MODULE_AUTHOR("Chunyan Zhang <zhang.chunyan@linaro.org>");
82