Linux Audio

Check our new training course

Loading...
v6.8
 1// SPDX-License-Identifier: GPL-2.0
 2/*
 3 * Simple kernel driver to link kernel Ftrace and an STM device
 4 * Copyright (c) 2016, Linaro Ltd.
 5 *
 
 
 
 
 
 
 
 
 
 6 * STM Ftrace will be registered as a trace_export.
 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 * stm_ftrace_write() - write data to STM via 'stm_ftrace' source
33 * @buf:	buffer containing the data packet
34 * @len:	length of the data packet
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	/* This is called from trace system with preemption disabled */
41	unsigned int cpu = smp_processor_id();
42
43	stm_source_write(&stm->data, STM_FTRACE_CHAN + cpu, buf, len);
44}
45
46static int stm_ftrace_link(struct stm_source_data *data)
47{
48	struct stm_ftrace *sf = container_of(data, struct stm_ftrace, data);
49
50	sf->ftrace.write = stm_ftrace_write;
51	sf->ftrace.flags = TRACE_EXPORT_FUNCTION | TRACE_EXPORT_EVENT
52			| TRACE_EXPORT_MARKER;
53
54	return register_ftrace_export(&sf->ftrace);
55}
56
57static void stm_ftrace_unlink(struct stm_source_data *data)
58{
59	struct stm_ftrace *sf = container_of(data, struct stm_ftrace, data);
60
61	unregister_ftrace_export(&sf->ftrace);
62}
63
64static int __init stm_ftrace_init(void)
65{
66	int ret;
67
68	stm_ftrace.data.nr_chans = roundup_pow_of_two(num_possible_cpus());
69	ret = stm_source_register_device(NULL, &stm_ftrace.data);
70	if (ret)
71		pr_err("Failed to register stm_source - ftrace.\n");
72
73	return ret;
74}
75
76static void __exit stm_ftrace_exit(void)
77{
78	stm_source_unregister_device(&stm_ftrace.data);
79}
80
81module_init(stm_ftrace_init);
82module_exit(stm_ftrace_exit);
83
84MODULE_LICENSE("GPL v2");
85MODULE_DESCRIPTION("stm_ftrace driver");
86MODULE_AUTHOR("Chunyan Zhang <zhang.chunyan@linaro.org>");
v4.10.11
 
 1/*
 2 * Simple kernel driver to link kernel Ftrace and an STM device
 3 * Copyright (c) 2016, Linaro Ltd.
 4 *
 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.
 8 *
 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
12 * more details.
13 *
14 * STM Ftrace will be registered as a trace_export.
15 */
16
17#include <linux/module.h>
18#include <linux/stm.h>
19#include <linux/trace.h>
20
21#define STM_FTRACE_NR_CHANNELS 1
22#define STM_FTRACE_CHAN 0
23
24static int stm_ftrace_link(struct stm_source_data *data);
25static void stm_ftrace_unlink(struct stm_source_data *data);
26
27static struct stm_ftrace {
28	struct stm_source_data	data;
29	struct trace_export	ftrace;
30} stm_ftrace = {
31	.data	= {
32		.name		= "ftrace",
33		.nr_chans	= STM_FTRACE_NR_CHANNELS,
34		.link		= stm_ftrace_link,
35		.unlink		= stm_ftrace_unlink,
36	},
37};
38
39/**
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
43 */
44static void notrace
45stm_ftrace_write(const void *buf, unsigned int len)
46{
47	stm_source_write(&stm_ftrace.data, STM_FTRACE_CHAN, buf, len);
 
 
 
 
48}
49
50static int stm_ftrace_link(struct stm_source_data *data)
51{
52	struct stm_ftrace *sf = container_of(data, struct stm_ftrace, data);
53
54	sf->ftrace.write = stm_ftrace_write;
 
 
55
56	return register_ftrace_export(&sf->ftrace);
57}
58
59static void stm_ftrace_unlink(struct stm_source_data *data)
60{
61	struct stm_ftrace *sf = container_of(data, struct stm_ftrace, data);
62
63	unregister_ftrace_export(&sf->ftrace);
64}
65
66static int __init stm_ftrace_init(void)
67{
68	int ret;
69
 
70	ret = stm_source_register_device(NULL, &stm_ftrace.data);
71	if (ret)
72		pr_err("Failed to register stm_source - ftrace.\n");
73
74	return ret;
75}
76
77static void __exit stm_ftrace_exit(void)
78{
79	stm_source_unregister_device(&stm_ftrace.data);
80}
81
82module_init(stm_ftrace_init);
83module_exit(stm_ftrace_exit);
84
85MODULE_LICENSE("GPL v2");
86MODULE_DESCRIPTION("stm_ftrace driver");
87MODULE_AUTHOR("Chunyan Zhang <zhang.chunyan@linaro.org>");