xref: /OK3568_Linux_fs/kernel/drivers/gpu/arm/bifrost/debug/backend/mali_kbase_debug_ktrace_jm.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_JM_H_
23 #define _KBASE_DEBUG_KTRACE_JM_H_
24 
25 /*
26  * KTrace target for internal ringbuffer
27  */
28 #if KBASE_KTRACE_TARGET_RBUF
29 /**
30  * kbasep_ktrace_add_jm - internal function to add trace about Job Management
31  * @kbdev:    kbase device
32  * @code:     trace code
33  * @kctx:     kbase context, or NULL if no context
34  * @katom:    kbase atom, or NULL if no atom
35  * @gpu_addr: GPU address, usually related to @katom
36  * @flags:    flags about the message
37  * @refcount: reference count information to add to the trace
38  * @jobslot:  jobslot information to add to the trace
39  * @info_val: generic information about @code to add to the trace
40  *
41  * PRIVATE: do not use directly. Use KBASE_KTRACE_ADD_JM() instead.
42  */
43 void kbasep_ktrace_add_jm(struct kbase_device *kbdev,
44 			  enum kbase_ktrace_code code,
45 			  struct kbase_context *kctx,
46 			  const struct kbase_jd_atom *katom, u64 gpu_addr,
47 			  kbase_ktrace_flag_t flags, int refcount, int jobslot,
48 			  u64 info_val);
49 
50 #define KBASE_KTRACE_RBUF_ADD_JM(kbdev, code, kctx, katom, gpu_addr, flags, \
51 		refcount, jobslot, info_val) \
52 	kbasep_ktrace_add_jm(kbdev, KBASE_KTRACE_CODE(code), kctx, katom, \
53 			gpu_addr, flags, refcount, jobslot, info_val)
54 
55 #else /* KBASE_KTRACE_TARGET_RBUF */
56 
57 #define KBASE_KTRACE_RBUF_ADD_JM(kbdev, code, kctx, katom, gpu_addr, flags, \
58 		refcount, jobslot, info_val) \
59 	do {\
60 		CSTD_UNUSED(kbdev);\
61 		CSTD_NOP(code);\
62 		CSTD_UNUSED(kctx);\
63 		CSTD_UNUSED(katom);\
64 		CSTD_UNUSED(gpu_addr);\
65 		CSTD_UNUSED(flags);\
66 		CSTD_UNUSED(refcount);\
67 		CSTD_UNUSED(jobslot);\
68 		CSTD_UNUSED(info_val);\
69 		CSTD_NOP(0);\
70 	} while (0)
71 #endif /* KBASE_KTRACE_TARGET_RBUF */
72 
73 /*
74  * KTrace target for Linux's ftrace
75  *
76  * Note: the header file(s) that define the trace_mali_<...> tracepoints are
77  * included by the parent header file
78  */
79 #if KBASE_KTRACE_TARGET_FTRACE
80 #define KBASE_KTRACE_FTRACE_ADD_JM_SLOT(kbdev, code, kctx, katom, gpu_addr, \
81 		jobslot) \
82 	trace_mali_##code(kctx, jobslot, 0)
83 
84 #define KBASE_KTRACE_FTRACE_ADD_JM_SLOT_INFO(kbdev, code, kctx, katom, \
85 		gpu_addr, jobslot, info_val) \
86 	trace_mali_##code(kctx, jobslot, info_val)
87 
88 #define KBASE_KTRACE_FTRACE_ADD_JM_REFCOUNT(kbdev, code, kctx, katom, \
89 		gpu_addr, refcount) \
90 	trace_mali_##code(kctx, refcount, 0)
91 
92 #define KBASE_KTRACE_FTRACE_ADD_JM_REFCOUNT_INFO(kbdev, code, kctx, katom, \
93 		gpu_addr, refcount, info_val) \
94 	trace_mali_##code(kctx, refcount, info_val)
95 
96 #define KBASE_KTRACE_FTRACE_ADD_JM(kbdev, code, kctx, katom, gpu_addr, \
97 		info_val) \
98 	trace_mali_##code(kctx, gpu_addr, info_val)
99 #else /* KBASE_KTRACE_TARGET_FTRACE */
100 #define KBASE_KTRACE_FTRACE_ADD_JM_SLOT(kbdev, code, kctx, katom, gpu_addr, \
101 		jobslot) \
102 	do {\
103 		CSTD_UNUSED(kbdev);\
104 		CSTD_NOP(code);\
105 		CSTD_UNUSED(kctx);\
106 		CSTD_UNUSED(katom);\
107 		CSTD_UNUSED(gpu_addr);\
108 		CSTD_UNUSED(jobslot);\
109 		CSTD_NOP(0);\
110 	} while (0)
111 
112 #define KBASE_KTRACE_FTRACE_ADD_JM_SLOT_INFO(kbdev, code, kctx, katom, \
113 		gpu_addr, jobslot, info_val) \
114 	do {\
115 		CSTD_UNUSED(kbdev);\
116 		CSTD_NOP(code);\
117 		CSTD_UNUSED(kctx);\
118 		CSTD_UNUSED(katom);\
119 		CSTD_UNUSED(gpu_addr);\
120 		CSTD_UNUSED(jobslot);\
121 		CSTD_UNUSED(info_val);\
122 		CSTD_NOP(0);\
123 	} while (0)
124 
125 #define KBASE_KTRACE_FTRACE_ADD_JM_REFCOUNT(kbdev, code, kctx, katom, \
126 		gpu_addr, refcount) \
127 	do {\
128 		CSTD_UNUSED(kbdev);\
129 		CSTD_NOP(code);\
130 		CSTD_UNUSED(kctx);\
131 		CSTD_UNUSED(katom);\
132 		CSTD_UNUSED(gpu_addr);\
133 		CSTD_UNUSED(refcount);\
134 		CSTD_NOP(0);\
135 	} while (0)
136 
137 #define KBASE_KTRACE_FTRACE_ADD_JM_REFCOUNT_INFO(kbdev, code, kctx, katom, \
138 		gpu_addr, refcount, info_val) \
139 	do {\
140 		CSTD_UNUSED(kbdev);\
141 		CSTD_NOP(code);\
142 		CSTD_UNUSED(kctx);\
143 		CSTD_UNUSED(katom);\
144 		CSTD_UNUSED(gpu_addr);\
145 		CSTD_UNUSED(info_val);\
146 		CSTD_NOP(0);\
147 	} while (0)
148 
149 #define KBASE_KTRACE_FTRACE_ADD_JM(kbdev, code, kctx, katom, gpu_addr, \
150 		info_val)\
151 	do {\
152 		CSTD_UNUSED(kbdev);\
153 		CSTD_NOP(code);\
154 		CSTD_UNUSED(kctx);\
155 		CSTD_UNUSED(katom);\
156 		CSTD_UNUSED(gpu_addr);\
157 		CSTD_UNUSED(info_val);\
158 		CSTD_NOP(0);\
159 	} while (0)
160 #endif /* KBASE_KTRACE_TARGET_FTRACE */
161 
162 /*
163  * Master set of macros to route KTrace to any of the targets
164  */
165 
166 /**
167  * KBASE_KTRACE_ADD_JM_SLOT - Add trace values about a job-slot
168  * @kbdev:    kbase device
169  * @code:     trace code
170  * @kctx:     kbase context, or NULL if no context
171  * @katom:    kbase atom, or NULL if no atom
172  * @gpu_addr: GPU address, usually related to @katom
173  * @jobslot:  jobslot information to add to the trace
174  *
175  * Note: Any functions called through this macro will still be evaluated in
176  * Release builds (CONFIG_MALI_BIFROST_DEBUG not defined). Therefore, when
177  * KBASE_KTRACE_ENABLE == 0 any functions called to get the parameters supplied
178  * to this macro must:
179  * a) be static or static inline, and
180  * b) just return 0 and have no other statements present in the body.
181  */
182 #define KBASE_KTRACE_ADD_JM_SLOT(kbdev, code, kctx, katom, gpu_addr, \
183 		jobslot) \
184 	do { \
185 		/* capture values that could come from non-pure function calls */ \
186 		u64 __gpu_addr = gpu_addr; \
187 		int __jobslot = jobslot; \
188 		KBASE_KTRACE_RBUF_ADD_JM(kbdev, code, kctx, katom, __gpu_addr, \
189 				KBASE_KTRACE_FLAG_JM_JOBSLOT, 0, __jobslot, \
190 				0); \
191 		KBASE_KTRACE_FTRACE_ADD_JM_SLOT(kbdev, code, kctx, katom, __gpu_addr, __jobslot); \
192 	} while (0)
193 
194 /**
195  * KBASE_KTRACE_ADD_JM_SLOT_INFO - Add trace values about a job-slot, with info
196  * @kbdev:    kbase device
197  * @code:     trace code
198  * @kctx:     kbase context, or NULL if no context
199  * @katom:    kbase atom, or NULL if no atom
200  * @gpu_addr: GPU address, usually related to @katom
201  * @jobslot:  jobslot information to add to the trace
202  * @info_val: generic information about @code to add to the trace
203  *
204  * Note: Any functions called through this macro will still be evaluated in
205  * Release builds (CONFIG_MALI_BIFROST_DEBUG not defined). Therefore, when
206  * KBASE_KTRACE_ENABLE == 0 any functions called to get the parameters supplied
207  * to this macro must:
208  * a) be static or static inline, and
209  * b) just return 0 and have no other statements present in the body.
210  */
211 #define KBASE_KTRACE_ADD_JM_SLOT_INFO(kbdev, code, kctx, katom, gpu_addr, \
212 		jobslot, info_val) \
213 	do { \
214 		/* capture values that could come from non-pure function calls */ \
215 		u64 __gpu_addr = gpu_addr; \
216 		int __jobslot = jobslot; \
217 		u64 __info_val = info_val; \
218 		KBASE_KTRACE_RBUF_ADD_JM(kbdev, code, kctx, katom, __gpu_addr, \
219 				KBASE_KTRACE_FLAG_JM_JOBSLOT, 0, __jobslot, \
220 				__info_val); \
221 		KBASE_KTRACE_FTRACE_ADD_JM_SLOT_INFO(kbdev, code, kctx, katom, __gpu_addr, __jobslot, __info_val); \
222 	} while (0)
223 
224 /**
225  * KBASE_KTRACE_ADD_JM_REFCOUNT - Add trace values about a kctx refcount
226  * @kbdev:    kbase device
227  * @code:     trace code
228  * @kctx:     kbase context, or NULL if no context
229  * @katom:    kbase atom, or NULL if no atom
230  * @gpu_addr: GPU address, usually related to @katom
231  * @refcount: reference count information to add to the trace
232  *
233  * Note: Any functions called through this macro will still be evaluated in
234  * Release builds (CONFIG_MALI_BIFROST_DEBUG not defined). Therefore, when
235  * KBASE_KTRACE_ENABLE == 0 any functions called to get the parameters supplied
236  * to this macro must:
237  * a) be static or static inline, and
238  * b) just return 0 and have no other statements present in the body.
239  */
240 #define KBASE_KTRACE_ADD_JM_REFCOUNT(kbdev, code, kctx, katom, gpu_addr, \
241 		refcount) \
242 	do { \
243 		/* capture values that could come from non-pure function calls */ \
244 		u64 __gpu_addr = gpu_addr; \
245 		int __refcount = refcount; \
246 		KBASE_KTRACE_RBUF_ADD_JM(kbdev, code, kctx, katom, __gpu_addr, \
247 				KBASE_KTRACE_FLAG_JM_REFCOUNT, __refcount, 0, \
248 				0u); \
249 		KBASE_KTRACE_FTRACE_ADD_JM_REFCOUNT(kbdev, code, kctx, katom, __gpu_addr, __refcount); \
250 	} while (0)
251 
252 /**
253  * KBASE_KTRACE_ADD_JM_REFCOUNT_INFO - Add trace values about a kctx refcount,
254  *                                     and info
255  * @kbdev:    kbase device
256  * @code:     trace code
257  * @kctx:     kbase context, or NULL if no context
258  * @katom:    kbase atom, or NULL if no atom
259  * @gpu_addr: GPU address, usually related to @katom
260  * @refcount: reference count information to add to the trace
261  * @info_val: generic information about @code to add to the trace
262  *
263  * Note: Any functions called through this macro will still be evaluated in
264  * Release builds (CONFIG_MALI_BIFROST_DEBUG not defined). Therefore, when
265  * KBASE_KTRACE_ENABLE == 0 any functions called to get the parameters supplied
266  * to this macro must:
267  * a) be static or static inline, and
268  * b) just return 0 and have no other statements present in the body.
269  */
270 #define KBASE_KTRACE_ADD_JM_REFCOUNT_INFO(kbdev, code, kctx, katom, \
271 		gpu_addr, refcount, info_val) \
272 	do { \
273 		/* capture values that could come from non-pure function calls */ \
274 		u64 __gpu_addr = gpu_addr; \
275 		int __refcount = refcount; \
276 		u64 __info_val = info_val; \
277 		KBASE_KTRACE_RBUF_ADD_JM(kbdev, code, kctx, katom, __gpu_addr, \
278 				KBASE_KTRACE_FLAG_JM_REFCOUNT, __refcount, 0, \
279 				__info_val); \
280 		KBASE_KTRACE_FTRACE_ADD_JM_REFCOUNT(kbdev, code, kctx, katom, __gpu_addr, __refcount, __info_val); \
281 	} while (0)
282 
283 /**
284  * KBASE_KTRACE_ADD_JM - Add trace values (no slot or refcount)
285  * @kbdev:    kbase device
286  * @code:     trace code
287  * @kctx:     kbase context, or NULL if no context
288  * @katom:    kbase atom, or NULL if no atom
289  * @gpu_addr: GPU address, usually related to @katom
290  * @info_val: generic information about @code to add to the trace
291  *
292  * Note: Any functions called through this macro will still be evaluated in
293  * Release builds (CONFIG_MALI_BIFROST_DEBUG not defined). Therefore, when
294  * KBASE_KTRACE_ENABLE == 0 any functions called to get the parameters supplied
295  * to this macro must:
296  * a) be static or static inline, and
297  * b) just return 0 and have no other statements present in the body.
298  */
299 #define KBASE_KTRACE_ADD_JM(kbdev, code, kctx, katom, gpu_addr, info_val) \
300 	do { \
301 		/* capture values that could come from non-pure function calls */ \
302 		u64 __gpu_addr = gpu_addr; \
303 		u64 __info_val = info_val; \
304 		KBASE_KTRACE_RBUF_ADD_JM(kbdev, code, kctx, katom, __gpu_addr, \
305 				0u, 0, 0, __info_val); \
306 		KBASE_KTRACE_FTRACE_ADD_JM(kbdev, code, kctx, katom, __gpu_addr, __info_val); \
307 	} while (0)
308 
309 #endif /* _KBASE_DEBUG_KTRACE_JM_H_ */
310