Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

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