xref: /OK3568_Linux_fs/kernel/include/linux/intel_th.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /* SPDX-License-Identifier: GPL-2.0 */
2*4882a593Smuzhiyun /*
3*4882a593Smuzhiyun  * Intel(R) Trace Hub data structures for implementing buffer sinks.
4*4882a593Smuzhiyun  *
5*4882a593Smuzhiyun  * Copyright (C) 2019 Intel Corporation.
6*4882a593Smuzhiyun  */
7*4882a593Smuzhiyun 
8*4882a593Smuzhiyun #ifndef _INTEL_TH_H_
9*4882a593Smuzhiyun #define _INTEL_TH_H_
10*4882a593Smuzhiyun 
11*4882a593Smuzhiyun #include <linux/scatterlist.h>
12*4882a593Smuzhiyun 
13*4882a593Smuzhiyun /* MSC operating modes (MSC_MODE) */
14*4882a593Smuzhiyun enum {
15*4882a593Smuzhiyun 	MSC_MODE_SINGLE	= 0,
16*4882a593Smuzhiyun 	MSC_MODE_MULTI,
17*4882a593Smuzhiyun 	MSC_MODE_EXI,
18*4882a593Smuzhiyun 	MSC_MODE_DEBUG,
19*4882a593Smuzhiyun };
20*4882a593Smuzhiyun 
21*4882a593Smuzhiyun struct msu_buffer {
22*4882a593Smuzhiyun 	const char	*name;
23*4882a593Smuzhiyun 	/*
24*4882a593Smuzhiyun 	 * ->assign() called when buffer 'mode' is set to this driver
25*4882a593Smuzhiyun 	 *   (aka mode_store())
26*4882a593Smuzhiyun 	 * @device:	struct device * of the msc
27*4882a593Smuzhiyun 	 * @mode:	allows the driver to set HW mode (see the enum above)
28*4882a593Smuzhiyun 	 * Returns:	a pointer to a private structure associated with this
29*4882a593Smuzhiyun 	 *		msc or NULL in case of error. This private structure
30*4882a593Smuzhiyun 	 *		will then be passed into all other callbacks.
31*4882a593Smuzhiyun 	 */
32*4882a593Smuzhiyun 	void	*(*assign)(struct device *dev, int *mode);
33*4882a593Smuzhiyun 	/* ->unassign():	some other mode is selected, clean up */
34*4882a593Smuzhiyun 	void	(*unassign)(void *priv);
35*4882a593Smuzhiyun 	/*
36*4882a593Smuzhiyun 	 * ->alloc_window(): allocate memory for the window of a given
37*4882a593Smuzhiyun 	 *		size
38*4882a593Smuzhiyun 	 * @sgt:	pointer to sg_table, can be overridden by the buffer
39*4882a593Smuzhiyun 	 *		driver, or kept intact
40*4882a593Smuzhiyun 	 * Returns:	number of sg table entries <= number of pages;
41*4882a593Smuzhiyun 	 *		0 is treated as an allocation failure.
42*4882a593Smuzhiyun 	 */
43*4882a593Smuzhiyun 	int	(*alloc_window)(void *priv, struct sg_table **sgt,
44*4882a593Smuzhiyun 				size_t size);
45*4882a593Smuzhiyun 	void	(*free_window)(void *priv, struct sg_table *sgt);
46*4882a593Smuzhiyun 	/* ->activate():	trace has started */
47*4882a593Smuzhiyun 	void	(*activate)(void *priv);
48*4882a593Smuzhiyun 	/* ->deactivate():	trace is about to stop */
49*4882a593Smuzhiyun 	void	(*deactivate)(void *priv);
50*4882a593Smuzhiyun 	/*
51*4882a593Smuzhiyun 	 * ->ready():	window @sgt is filled up to the last block OR
52*4882a593Smuzhiyun 	 *		tracing is stopped by the user; this window contains
53*4882a593Smuzhiyun 	 *		@bytes data. The window in question transitions into
54*4882a593Smuzhiyun 	 *		the "LOCKED" state, indicating that it can't be used
55*4882a593Smuzhiyun 	 *		by hardware. To clear this state and make the window
56*4882a593Smuzhiyun 	 *		available to the hardware again, call
57*4882a593Smuzhiyun 	 *		intel_th_msc_window_unlock().
58*4882a593Smuzhiyun 	 */
59*4882a593Smuzhiyun 	int	(*ready)(void *priv, struct sg_table *sgt, size_t bytes);
60*4882a593Smuzhiyun };
61*4882a593Smuzhiyun 
62*4882a593Smuzhiyun int intel_th_msu_buffer_register(const struct msu_buffer *mbuf,
63*4882a593Smuzhiyun 				 struct module *owner);
64*4882a593Smuzhiyun void intel_th_msu_buffer_unregister(const struct msu_buffer *mbuf);
65*4882a593Smuzhiyun void intel_th_msc_window_unlock(struct device *dev, struct sg_table *sgt);
66*4882a593Smuzhiyun 
67*4882a593Smuzhiyun #define module_intel_th_msu_buffer(__buffer) \
68*4882a593Smuzhiyun static int __init __buffer##_init(void) \
69*4882a593Smuzhiyun { \
70*4882a593Smuzhiyun 	return intel_th_msu_buffer_register(&(__buffer), THIS_MODULE); \
71*4882a593Smuzhiyun } \
72*4882a593Smuzhiyun module_init(__buffer##_init); \
73*4882a593Smuzhiyun static void __exit __buffer##_exit(void) \
74*4882a593Smuzhiyun { \
75*4882a593Smuzhiyun 	intel_th_msu_buffer_unregister(&(__buffer)); \
76*4882a593Smuzhiyun } \
77*4882a593Smuzhiyun module_exit(__buffer##_exit);
78*4882a593Smuzhiyun 
79*4882a593Smuzhiyun #endif /* _INTEL_TH_H_ */
80