xref: /OK3568_Linux_fs/kernel/drivers/gpu/arm/bifrost/debug/backend/mali_kbase_debug_ktrace_csf.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1 /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
2 /*
3  *
4  * (C) COPYRIGHT 2020-2021 ARM Limited. All rights reserved.
5  *
6  * This program is free software and is provided to you under the terms of the
7  * GNU General Public License version 2 as published by the Free Software
8  * Foundation, and any use by you of this program is subject to the terms
9  * of such GNU license.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, you can access it online at
18  * http://www.gnu.org/licenses/gpl-2.0.html.
19  *
20  */
21 
22 #ifndef _KBASE_DEBUG_KTRACE_CSF_H_
23 #define _KBASE_DEBUG_KTRACE_CSF_H_
24 
25 /*
26  * KTrace target for internal ringbuffer
27  */
28 #if KBASE_KTRACE_TARGET_RBUF
29 /**
30  * kbasep_ktrace_add_csf - internal function to add trace about CSF
31  * @kbdev:    kbase device
32  * @code:     trace code
33  * @group:    queue group, or NULL if no queue group
34  * @queue:    queue, or NULL if no queue
35  * @flags:    flags about the message
36  * @info_val: generic information about @code to add to the trace
37  *
38  * PRIVATE: do not use directly. Use KBASE_KTRACE_ADD_CSF() instead.
39  */
40 
41 void kbasep_ktrace_add_csf(struct kbase_device *kbdev,
42 		enum kbase_ktrace_code code, struct kbase_queue_group *group,
43 		struct kbase_queue *queue, kbase_ktrace_flag_t flags,
44 		u64 info_val);
45 
46 /**
47  * kbasep_ktrace_add_csf_kcpu - internal function to add trace about the CSF
48  *				KCPU queues.
49  * @kbdev:      kbase device
50  * @code:       trace code
51  * @queue:      queue, or NULL if no queue
52  * @info_val1:  Main infoval variable with information based on the KCPU
53  *              ktrace call. Refer to mali_kbase_debug_ktrace_codes_csf.h
54  *              for information on the infoval values.
55  * @info_val2:  Extra infoval variable with information based on the KCPU
56  *              ktrace call. Refer to mali_kbase_debug_ktrace_codes_csf.h
57  *              for information on the infoval values.
58  *
59  * PRIVATE: do not use directly. Use KBASE_KTRACE_ADD_CSF_KCPU() instead.
60  */
61 void kbasep_ktrace_add_csf_kcpu(struct kbase_device *kbdev,
62 				enum kbase_ktrace_code code,
63 				struct kbase_kcpu_command_queue *queue,
64 				u64 info_val1, u64 info_val2);
65 
66 #define KBASE_KTRACE_RBUF_ADD_CSF(kbdev, code, group, queue, flags, info_val) \
67 	kbasep_ktrace_add_csf(kbdev, KBASE_KTRACE_CODE(code), group, queue, \
68 	flags, info_val)
69 
70 #define KBASE_KTRACE_RBUF_ADD_CSF_KCPU(kbdev, code, queue, info_val1, \
71 	info_val2) kbasep_ktrace_add_csf_kcpu(kbdev, KBASE_KTRACE_CODE(code), \
72 	queue, info_val1, info_val2)
73 
74 #else /* KBASE_KTRACE_TARGET_RBUF */
75 
76 #define KBASE_KTRACE_RBUF_ADD_CSF(kbdev, code, group, queue, flags, info_val) \
77 	do {\
78 		CSTD_UNUSED(kbdev);\
79 		CSTD_NOP(code);\
80 		CSTD_UNUSED(group);\
81 		CSTD_UNUSED(queue);\
82 		CSTD_UNUSED(flags);\
83 		CSTD_UNUSED(info_val);\
84 		CSTD_NOP(0);\
85 	} while (0)
86 
87 #define KBASE_KTRACE_RBUF_ADD_CSF_KCPU(kbdev, code, queue, info_val1, info_val2) \
88 	do {\
89 		CSTD_UNUSED(kbdev);\
90 		CSTD_NOP(code);\
91 		CSTD_UNUSED(queue);\
92 		CSTD_UNUSED(info_val1);\
93 		CSTD_UNUSED(info_val2);\
94 	} while (0)
95 
96 #endif /* KBASE_KTRACE_TARGET_RBUF */
97 
98 /*
99  * KTrace target for Linux's ftrace
100  *
101  * Note: the header file(s) that define the trace_mali_<...> tracepoints are
102  * included by the parent header file
103  */
104 #if KBASE_KTRACE_TARGET_FTRACE
105 
106 #define KBASE_KTRACE_FTRACE_ADD_CSF(kbdev, code, group, queue, info_val) \
107 	trace_mali_##code(kbdev, group, queue, info_val)
108 
109 #define KBASE_KTRACE_FTRACE_ADD_KCPU(code, queue, info_val1, info_val2) \
110 	trace_mali_##code(queue, info_val1, info_val2)
111 
112 #else /* KBASE_KTRACE_TARGET_FTRACE */
113 
114 #define KBASE_KTRACE_FTRACE_ADD_CSF(kbdev, code, group, queue, info_val) \
115 	do {\
116 		CSTD_UNUSED(kbdev);\
117 		CSTD_NOP(code);\
118 		CSTD_UNUSED(group);\
119 		CSTD_UNUSED(queue);\
120 		CSTD_UNUSED(info_val);\
121 		CSTD_NOP(0);\
122 	} while (0)
123 
124 #define KBASE_KTRACE_FTRACE_ADD_KCPU(code, queue, info_val1, info_val2) \
125 	do {\
126 		CSTD_NOP(code);\
127 		CSTD_UNUSED(queue);\
128 		CSTD_UNUSED(info_val1);\
129 		CSTD_UNUSED(info_val2);\
130 	} while (0)
131 
132 #endif /* KBASE_KTRACE_TARGET_FTRACE */
133 
134 /*
135  * Master set of macros to route KTrace to any of the targets
136  */
137 
138 /**
139  * KBASE_KTRACE_ADD_CSF_GRP - Add trace values about a group, with info
140  * @kbdev:    kbase device
141  * @code:     trace code
142  * @group:    queue group, or NULL if no queue group
143  * @info_val: generic information about @code to add to the trace
144  *
145  * Note: Any functions called through this macro will still be evaluated in
146  * Release builds (CONFIG_MALI_BIFROST_DEBUG not defined). Therefore, when
147  * KBASE_KTRACE_ENABLE == 0 any functions called to get the parameters supplied
148  * to this macro must:
149  * a) be static or static inline, and
150  * b) just return 0 and have no other statements present in the body.
151  */
152 #define KBASE_KTRACE_ADD_CSF_GRP(kbdev, code, group, info_val) \
153 	do { \
154 		/* capture values that could come from non-pure fn calls */ \
155 		struct kbase_queue_group *__group = group; \
156 		u64 __info_val = info_val; \
157 		KBASE_KTRACE_RBUF_ADD_CSF(kbdev, code, __group, NULL, 0u, \
158 				__info_val); \
159 		KBASE_KTRACE_FTRACE_ADD_CSF(kbdev, code, __group, NULL, \
160 				__info_val); \
161 	} while (0)
162 
163 /**
164  * KBASE_KTRACE_ADD_CSF_GRP_Q - Add trace values about a group, queue, with info
165  * @kbdev:    kbase device
166  * @code:     trace code
167  * @group:    queue group, or NULL if no queue group
168  * @queue:    queue, or NULL if no queue
169  * @info_val: generic information about @code to add to the trace
170  *
171  * Note: Any functions called through this macro will still be evaluated in
172  * Release builds (CONFIG_MALI_BIFROST_DEBUG not defined). Therefore, when
173  * KBASE_KTRACE_ENABLE == 0 any functions called to get the parameters supplied
174  * to this macro must:
175  * a) be static or static inline, and
176  * b) just return 0 and have no other statements present in the body.
177  */
178 #define KBASE_KTRACE_ADD_CSF_GRP_Q(kbdev, code, group, queue, info_val) \
179 	do { \
180 		/* capture values that could come from non-pure fn calls */ \
181 		struct kbase_queue_group *__group = group; \
182 		struct kbase_queue *__queue = queue; \
183 		u64 __info_val = info_val; \
184 		KBASE_KTRACE_RBUF_ADD_CSF(kbdev, code, __group, __queue, 0u, \
185 				__info_val); \
186 		KBASE_KTRACE_FTRACE_ADD_CSF(kbdev, code, __group, \
187 				__queue, __info_val); \
188 	} while (0)
189 
190 
191 #define KBASE_KTRACE_ADD_CSF_KCPU(kbdev, code, queue, info_val1, info_val2) \
192 	do { \
193 		/* capture values that could come from non-pure fn calls */ \
194 		struct kbase_kcpu_command_queue *__queue = queue; \
195 		u64 __info_val1 = info_val1; \
196 		u64 __info_val2 = info_val2; \
197 		KBASE_KTRACE_RBUF_ADD_CSF_KCPU(kbdev, code, __queue, \
198 					       __info_val1, __info_val2); \
199 		KBASE_KTRACE_FTRACE_ADD_KCPU(code, __queue, \
200 					     __info_val1, __info_val2); \
201 	} while (0)
202 
203 #endif /* _KBASE_DEBUG_KTRACE_CSF_H_ */
204