18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * Intel(R) Trace Hub data structures for implementing buffer sinks.
48c2ecf20Sopenharmony_ci *
58c2ecf20Sopenharmony_ci * Copyright (C) 2019 Intel Corporation.
68c2ecf20Sopenharmony_ci */
78c2ecf20Sopenharmony_ci
88c2ecf20Sopenharmony_ci#ifndef _INTEL_TH_H_
98c2ecf20Sopenharmony_ci#define _INTEL_TH_H_
108c2ecf20Sopenharmony_ci
118c2ecf20Sopenharmony_ci#include <linux/scatterlist.h>
128c2ecf20Sopenharmony_ci
138c2ecf20Sopenharmony_ci/* MSC operating modes (MSC_MODE) */
148c2ecf20Sopenharmony_cienum {
158c2ecf20Sopenharmony_ci	MSC_MODE_SINGLE	= 0,
168c2ecf20Sopenharmony_ci	MSC_MODE_MULTI,
178c2ecf20Sopenharmony_ci	MSC_MODE_EXI,
188c2ecf20Sopenharmony_ci	MSC_MODE_DEBUG,
198c2ecf20Sopenharmony_ci};
208c2ecf20Sopenharmony_ci
218c2ecf20Sopenharmony_cistruct msu_buffer {
228c2ecf20Sopenharmony_ci	const char	*name;
238c2ecf20Sopenharmony_ci	/*
248c2ecf20Sopenharmony_ci	 * ->assign() called when buffer 'mode' is set to this driver
258c2ecf20Sopenharmony_ci	 *   (aka mode_store())
268c2ecf20Sopenharmony_ci	 * @device:	struct device * of the msc
278c2ecf20Sopenharmony_ci	 * @mode:	allows the driver to set HW mode (see the enum above)
288c2ecf20Sopenharmony_ci	 * Returns:	a pointer to a private structure associated with this
298c2ecf20Sopenharmony_ci	 *		msc or NULL in case of error. This private structure
308c2ecf20Sopenharmony_ci	 *		will then be passed into all other callbacks.
318c2ecf20Sopenharmony_ci	 */
328c2ecf20Sopenharmony_ci	void	*(*assign)(struct device *dev, int *mode);
338c2ecf20Sopenharmony_ci	/* ->unassign():	some other mode is selected, clean up */
348c2ecf20Sopenharmony_ci	void	(*unassign)(void *priv);
358c2ecf20Sopenharmony_ci	/*
368c2ecf20Sopenharmony_ci	 * ->alloc_window(): allocate memory for the window of a given
378c2ecf20Sopenharmony_ci	 *		size
388c2ecf20Sopenharmony_ci	 * @sgt:	pointer to sg_table, can be overridden by the buffer
398c2ecf20Sopenharmony_ci	 *		driver, or kept intact
408c2ecf20Sopenharmony_ci	 * Returns:	number of sg table entries <= number of pages;
418c2ecf20Sopenharmony_ci	 *		0 is treated as an allocation failure.
428c2ecf20Sopenharmony_ci	 */
438c2ecf20Sopenharmony_ci	int	(*alloc_window)(void *priv, struct sg_table **sgt,
448c2ecf20Sopenharmony_ci				size_t size);
458c2ecf20Sopenharmony_ci	void	(*free_window)(void *priv, struct sg_table *sgt);
468c2ecf20Sopenharmony_ci	/* ->activate():	trace has started */
478c2ecf20Sopenharmony_ci	void	(*activate)(void *priv);
488c2ecf20Sopenharmony_ci	/* ->deactivate():	trace is about to stop */
498c2ecf20Sopenharmony_ci	void	(*deactivate)(void *priv);
508c2ecf20Sopenharmony_ci	/*
518c2ecf20Sopenharmony_ci	 * ->ready():	window @sgt is filled up to the last block OR
528c2ecf20Sopenharmony_ci	 *		tracing is stopped by the user; this window contains
538c2ecf20Sopenharmony_ci	 *		@bytes data. The window in question transitions into
548c2ecf20Sopenharmony_ci	 *		the "LOCKED" state, indicating that it can't be used
558c2ecf20Sopenharmony_ci	 *		by hardware. To clear this state and make the window
568c2ecf20Sopenharmony_ci	 *		available to the hardware again, call
578c2ecf20Sopenharmony_ci	 *		intel_th_msc_window_unlock().
588c2ecf20Sopenharmony_ci	 */
598c2ecf20Sopenharmony_ci	int	(*ready)(void *priv, struct sg_table *sgt, size_t bytes);
608c2ecf20Sopenharmony_ci};
618c2ecf20Sopenharmony_ci
628c2ecf20Sopenharmony_ciint intel_th_msu_buffer_register(const struct msu_buffer *mbuf,
638c2ecf20Sopenharmony_ci				 struct module *owner);
648c2ecf20Sopenharmony_civoid intel_th_msu_buffer_unregister(const struct msu_buffer *mbuf);
658c2ecf20Sopenharmony_civoid intel_th_msc_window_unlock(struct device *dev, struct sg_table *sgt);
668c2ecf20Sopenharmony_ci
678c2ecf20Sopenharmony_ci#define module_intel_th_msu_buffer(__buffer) \
688c2ecf20Sopenharmony_cistatic int __init __buffer##_init(void) \
698c2ecf20Sopenharmony_ci{ \
708c2ecf20Sopenharmony_ci	return intel_th_msu_buffer_register(&(__buffer), THIS_MODULE); \
718c2ecf20Sopenharmony_ci} \
728c2ecf20Sopenharmony_cimodule_init(__buffer##_init); \
738c2ecf20Sopenharmony_cistatic void __exit __buffer##_exit(void) \
748c2ecf20Sopenharmony_ci{ \
758c2ecf20Sopenharmony_ci	intel_th_msu_buffer_unregister(&(__buffer)); \
768c2ecf20Sopenharmony_ci} \
778c2ecf20Sopenharmony_cimodule_exit(__buffer##_exit);
788c2ecf20Sopenharmony_ci
798c2ecf20Sopenharmony_ci#endif /* _INTEL_TH_H_ */
80