// SPDX-License-Identifier: GPL-2.0
/*
 * Simple kernel driver to link kernel Ftrace and an STM device
 * Copyright (c) 2016, Linaro Ltd.
 *
 * STM Ftrace will be registered as a trace_export.
 */

#include <linux/module.h>
#include <linux/stm.h>
#include <linux/trace.h>

#define STM_FTRACE_NR_CHANNELS 1
#define STM_FTRACE_CHAN 0

static int stm_ftrace_link(struct stm_source_data *data);
static void stm_ftrace_unlink(struct stm_source_data *data);

static struct stm_ftrace {
	struct stm_source_data	data;
	struct trace_export	ftrace;
} stm_ftrace = {
	.data	= {
		.name		= "ftrace",
		.nr_chans	= STM_FTRACE_NR_CHANNELS,
		.type		= STM_FTRACE,
		.link		= stm_ftrace_link,
		.unlink		= stm_ftrace_unlink,
	},
};

/**
 * stm_ftrace_write() - write data to STM via 'stm_ftrace' source
 * @buf:	buffer containing the data packet
 * @len:	length of the data packet
 */
static void notrace
stm_ftrace_write(struct trace_export *export, const void *buf, unsigned int len)
{
	struct stm_ftrace *stm = container_of(export, struct stm_ftrace, ftrace);
	/* This is called from trace system with preemption disabled */
	unsigned int cpu = smp_processor_id();

	stm_source_write(&stm->data, STM_FTRACE_CHAN + cpu, buf, len);
}

static int stm_ftrace_link(struct stm_source_data *data)
{
	struct stm_ftrace *sf = container_of(data, struct stm_ftrace, data);

	sf->ftrace.write = stm_ftrace_write;
	sf->ftrace.flags = TRACE_EXPORT_FUNCTION | TRACE_EXPORT_EVENT
			| TRACE_EXPORT_MARKER;

	return register_ftrace_export(&sf->ftrace);
}

static void stm_ftrace_unlink(struct stm_source_data *data)
{
	struct stm_ftrace *sf = container_of(data, struct stm_ftrace, data);

	unregister_ftrace_export(&sf->ftrace);
}

static int __init stm_ftrace_init(void)
{
	int ret;

	stm_ftrace.data.nr_chans = roundup_pow_of_two(num_possible_cpus());
	ret = stm_source_register_device(NULL, &stm_ftrace.data);
	if (ret)
		pr_err("Failed to register stm_source - ftrace.\n");

	return ret;
}

static void __exit stm_ftrace_exit(void)
{
	stm_source_unregister_device(&stm_ftrace.data);
}

module_init(stm_ftrace_init);
module_exit(stm_ftrace_exit);

MODULE_LICENSE("GPL v2");
MODULE_DESCRIPTION("stm_ftrace driver");
MODULE_AUTHOR("Chunyan Zhang <zhang.chunyan@linaro.org>");
