FILE
ftrace.c
File preview with syntax highlighting.
linux-6.19.14/drivers/hwtracing/stm/ftrace.c
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 .type = STM_FTRACE, 27 .link = stm_ftrace_link, 28 .unlink = stm_ftrace_unlink, 29 }, 30}; 31 32/** 33 * stm_ftrace_write() - write data to STM via 'stm_ftrace' source 34 * @buf: buffer containing the data packet 35 * @len: length of the data packet 36 */ 37static void notrace 38stm_ftrace_write(struct trace_export *export, const void *buf, unsigned int len) 39{ 40 struct stm_ftrace *stm = container_of(export, struct stm_ftrace, ftrace); 41 /* This is called from trace system with preemption disabled */ 42 unsigned int cpu = smp_processor_id(); 43 44 stm_source_write(&stm->data, STM_FTRACE_CHAN + cpu, buf, len); 45} 46 47static int stm_ftrace_link(struct stm_source_data *data) 48{ 49 struct stm_ftrace *sf = container_of(data, struct stm_ftrace, data); 50 51 sf->ftrace.write = stm_ftrace_write; 52 sf->ftrace.flags = TRACE_EXPORT_FUNCTION | TRACE_EXPORT_EVENT 53 | TRACE_EXPORT_MARKER; 54 55 return register_ftrace_export(&sf->ftrace); 56} 57 58static void stm_ftrace_unlink(struct stm_source_data *data) 59{ 60 struct stm_ftrace *sf = container_of(data, struct stm_ftrace, data); 61 62 unregister_ftrace_export(&sf->ftrace); 63} 64 65static int __init stm_ftrace_init(void) 66{ 67 int ret; 68 69 stm_ftrace.data.nr_chans = roundup_pow_of_two(num_possible_cpus()); 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>");
~/
Read-only file preview.