2 * Simple kernel driver to link kernel Ftrace and an STM device
3 * Copyright (c) 2016, Linaro Ltd.
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms and conditions of the GNU General Public License,
7 * version 2, as published by the Free Software Foundation.
9 * This program is distributed in the hope it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 * STM Ftrace will be registered as a trace_export.
17 #include <linux/module.h>
18 #include <linux/stm.h>
19 #include <linux/trace.h>
21 #define STM_FTRACE_NR_CHANNELS 1
22 #define STM_FTRACE_CHAN 0
24 static int stm_ftrace_link(struct stm_source_data
*data
);
25 static void stm_ftrace_unlink(struct stm_source_data
*data
);
27 static struct stm_ftrace
{
28 struct stm_source_data data
;
29 struct trace_export ftrace
;
33 .nr_chans
= STM_FTRACE_NR_CHANNELS
,
34 .link
= stm_ftrace_link
,
35 .unlink
= stm_ftrace_unlink
,
40 * stm_ftrace_write() - write data to STM via 'stm_ftrace' source
41 * @buf: buffer containing the data packet
42 * @len: length of the data packet
45 stm_ftrace_write(struct trace_export
*export
, const void *buf
, unsigned int len
)
47 struct stm_ftrace
*stm
= container_of(export
, struct stm_ftrace
, ftrace
);
49 stm_source_write(&stm
->data
, STM_FTRACE_CHAN
, buf
, len
);
52 static int stm_ftrace_link(struct stm_source_data
*data
)
54 struct stm_ftrace
*sf
= container_of(data
, struct stm_ftrace
, data
);
56 sf
->ftrace
.write
= stm_ftrace_write
;
58 return register_ftrace_export(&sf
->ftrace
);
61 static void stm_ftrace_unlink(struct stm_source_data
*data
)
63 struct stm_ftrace
*sf
= container_of(data
, struct stm_ftrace
, data
);
65 unregister_ftrace_export(&sf
->ftrace
);
68 static int __init
stm_ftrace_init(void)
72 ret
= stm_source_register_device(NULL
, &stm_ftrace
.data
);
74 pr_err("Failed to register stm_source - ftrace.\n");
79 static void __exit
stm_ftrace_exit(void)
81 stm_source_unregister_device(&stm_ftrace
.data
);
84 module_init(stm_ftrace_init
);
85 module_exit(stm_ftrace_exit
);
87 MODULE_LICENSE("GPL v2");
88 MODULE_DESCRIPTION("stm_ftrace driver");
89 MODULE_AUTHOR("Chunyan Zhang <zhang.chunyan@linaro.org>");