xref: /linux/drivers/gpu/drm/imagination/pvr_trace.h (revision 26ba30221c03364d6ed9910be8da4c1fd871b07b)
1 /* SPDX-License-Identifier: GPL-2.0 OR MIT */
2 /* Copyright (c) 2026 Imagination Technologies Ltd. */
3 
4 #undef TRACE_SYSTEM
5 #define TRACE_SYSTEM pvr
6 
7 #if !defined(PVR_TRACE_H) || defined(TRACE_HEADER_MULTI_READ)
8 #define PVR_TRACE_H
9 
10 #include "pvr_context.h"
11 #include "pvr_device.h"
12 #include "pvr_fw.h"
13 #include "pvr_hwrt.h"
14 #include "pvr_job.h"
15 #include "pvr_sync.h"
16 
17 #include <linux/stringify.h>
18 #include <linux/types.h>
19 #include <linux/tracepoint.h>
20 
21 /*
22  * NOTE:
23  * When adding trace points, or extra data to existing ones - you must capture
24  * all the data in the TP_fast_assign section that you wish to use in the
25  * TP_printk section. This is because the printk is performed on demand from the
26  * captured data when you `cat /sys/kernel/tracing/trace` and by the time this
27  * happens any pointers you captured will likely no longer point to valid data.
28  */
29 
30 /* Job submit */
31 
32 TRACE_EVENT(pvr_job_submit_ioctl,
33 	    TP_PROTO(struct pvr_device *pvr_dev, u32 count),
34 	    TP_ARGS(pvr_dev, count),
35 	    TP_STRUCT__entry(__field(struct pvr_device *, pvr_dev)
36 			     __field(u32, count)),
37 	    TP_fast_assign(__entry->pvr_dev = pvr_dev;
38 			   __entry->count = count;),
39 	    TP_printk("pvr_dev=%p count=%u",
40 		      __entry->pvr_dev,
41 		      __entry->count)
42 );
43 
44 #define PVR_JOB_GET_HWRT_FW_ADDR(job)                                                  \
45 	({                                                                             \
46 		struct pvr_job *_job = (job);                                          \
47 		u32 _hwrt_fw_addr = 0;                                                 \
48 										       \
49 		if (_job && _job->hwrt)                                                \
50 			pvr_fw_object_get_fw_addr(_job->hwrt->fw_obj, &_hwrt_fw_addr); \
51 										       \
52 		_hwrt_fw_addr;                                                         \
53 	})
54 
55 #define PVR_JOB_TYPE_TO_STR(val)                                         \
56 	__print_symbolic(val,                                            \
57 			 { DRM_PVR_JOB_TYPE_GEOMETRY, "geometry" },      \
58 			 { DRM_PVR_JOB_TYPE_FRAGMENT, "fragment" },      \
59 			 { DRM_PVR_JOB_TYPE_COMPUTE, "compute" },        \
60 			 { DRM_PVR_JOB_TYPE_TRANSFER_FRAG, "transfer" })
61 
62 TRACE_EVENT(pvr_job_create,
63 	    TP_PROTO(struct pvr_device *pvr_dev, struct pvr_job *job,
64 		     u32 sync_op_count),
65 	    TP_ARGS(pvr_dev, job, sync_op_count),
66 	    TP_STRUCT__entry(__field(struct pvr_device *, pvr_dev)
67 			     __field(struct pvr_context *, ctx)
68 			     __field(struct pvr_fw_object *, fw_obj)
69 			     __field(u32, fw_addr)
70 			     __field(u32, hwrt_addr)
71 			     __field(struct pvr_job *, job)
72 			     __field(enum drm_pvr_job_type, job_type)
73 			     __field(u32, sync_op_count)),
74 	    TP_fast_assign(__entry->pvr_dev = pvr_dev;
75 			   __entry->ctx = job->ctx;
76 			   __entry->fw_obj = job->ctx->fw_obj;
77 			   pvr_fw_object_get_fw_addr(job->ctx->fw_obj, &__entry->fw_addr);
78 			   __entry->hwrt_addr = PVR_JOB_GET_HWRT_FW_ADDR(job);
79 			   __entry->job = job;
80 			   __entry->job_type = job->type;
81 			   __entry->sync_op_count = sync_op_count;),
82 	    TP_printk("pvr_dev=%p ctx=%p fw_obj=%p fw_addr=0x%x hwrt_addr=0x%x job=%p job_type=%s sync_op_count=%u",
83 		      __entry->pvr_dev,
84 		      __entry->ctx,
85 		      __entry->fw_obj,
86 		      __entry->fw_addr,
87 		      __entry->hwrt_addr,
88 		      __entry->job,
89 		      PVR_JOB_TYPE_TO_STR(__entry->job_type),
90 		      __entry->sync_op_count)
91 );
92 
93 #undef PVR_JOB_TYPE_TO_STR
94 #undef PVR_JOB_GET_HWRT_FW_ADDR
95 
96 TRACE_EVENT(pvr_job_submit_fw,
97 	    TP_PROTO(struct pvr_job *job),
98 	    TP_ARGS(job),
99 	    TP_STRUCT__entry(__field(struct pvr_job *, job)
100 			     __field(u32, done_seqno)),
101 	    TP_fast_assign(__entry->job = job;
102 			   __entry->done_seqno = job->done_fence->seqno;),
103 	    TP_printk("job=%p done_seqno=%u",
104 		      __entry->job,
105 		      __entry->done_seqno)
106 );
107 
108 TRACE_EVENT(pvr_job_done,
109 	    TP_PROTO(struct pvr_job *job),
110 	    TP_ARGS(job),
111 	    TP_STRUCT__entry(__field(struct pvr_job *, job)),
112 	    TP_fast_assign(__entry->job = job;),
113 	    TP_printk("job=%p", __entry->job)
114 );
115 
116 #endif /* PVR_TRACE_H */
117 
118 /* This part must be outside protection */
119 #undef TRACE_INCLUDE_PATH
120 #undef TRACE_INCLUDE_FILE
121 #define TRACE_INCLUDE_PATH ../../drivers/gpu/drm/imagination
122 #define TRACE_INCLUDE_FILE pvr_trace
123 #include <trace/define_trace.h>
124