1 /*
2  * Copyright 2017 Advanced Micro Devices, Inc.
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a
5  * copy of this software and associated documentation files (the "Software"),
6  * to deal in the Software without restriction, including without limitation
7  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8  * and/or sell copies of the Software, and to permit persons to whom the
9  * Software is furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be included in
12  * all copies or substantial portions of the Software.
13  *
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
17  * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20  * OTHER DEALINGS IN THE SOFTWARE.
21  *
22  */
23 
24 #if !defined(_AMDGPU_TRACE_H) || defined(TRACE_HEADER_MULTI_READ)
25 #define _AMDGPU_TRACE_H_
26 
27 #include <linux/stringify.h>
28 #include <linux/types.h>
29 #include <linux/tracepoint.h>
30 
31 #include <drm/drmP.h>
32 
33 #undef TRACE_SYSTEM
34 #define TRACE_SYSTEM amdgpu
35 #define TRACE_INCLUDE_FILE amdgpu_trace
36 
37 #define AMDGPU_JOB_GET_TIMELINE_NAME(job) \
38 	 job->base.s_fence->finished.ops->get_timeline_name(&job->base.s_fence->finished)
39 
40 TRACE_EVENT(amdgpu_mm_rreg,
41 	    TP_PROTO(unsigned did, uint32_t reg, uint32_t value),
42 	    TP_ARGS(did, reg, value),
43 	    TP_STRUCT__entry(
44 				__field(unsigned, did)
45 				__field(uint32_t, reg)
46 				__field(uint32_t, value)
47 			    ),
48 	    TP_fast_assign(
49 			   __entry->did = did;
50 			   __entry->reg = reg;
51 			   __entry->value = value;
52 			   ),
53 	    TP_printk("0x%04lx, 0x%08lx, 0x%08lx",
54 		      (unsigned long)__entry->did,
55 		      (unsigned long)__entry->reg,
56 		      (unsigned long)__entry->value)
57 );
58 
59 TRACE_EVENT(amdgpu_mm_wreg,
60 	    TP_PROTO(unsigned did, uint32_t reg, uint32_t value),
61 	    TP_ARGS(did, reg, value),
62 	    TP_STRUCT__entry(
63 				__field(unsigned, did)
64 				__field(uint32_t, reg)
65 				__field(uint32_t, value)
66 			    ),
67 	    TP_fast_assign(
68 			   __entry->did = did;
69 			   __entry->reg = reg;
70 			   __entry->value = value;
71 			   ),
72 	    TP_printk("0x%04lx, 0x%08lx, 0x%08lx",
73 		      (unsigned long)__entry->did,
74 		      (unsigned long)__entry->reg,
75 		      (unsigned long)__entry->value)
76 );
77 
78 TRACE_EVENT(amdgpu_iv,
79 	    TP_PROTO(struct amdgpu_iv_entry *iv),
80 	    TP_ARGS(iv),
81 	    TP_STRUCT__entry(
82 			     __field(unsigned, client_id)
83 			     __field(unsigned, src_id)
84 			     __field(unsigned, ring_id)
85 			     __field(unsigned, vmid)
86 			     __field(unsigned, vmid_src)
87 			     __field(uint64_t, timestamp)
88 			     __field(unsigned, timestamp_src)
89 			     __field(unsigned, pasid)
90 			     __array(unsigned, src_data, 4)
91 			    ),
92 	    TP_fast_assign(
93 			   __entry->client_id = iv->client_id;
94 			   __entry->src_id = iv->src_id;
95 			   __entry->ring_id = iv->ring_id;
96 			   __entry->vmid = iv->vmid;
97 			   __entry->vmid_src = iv->vmid_src;
98 			   __entry->timestamp = iv->timestamp;
99 			   __entry->timestamp_src = iv->timestamp_src;
100 			   __entry->pasid = iv->pasid;
101 			   __entry->src_data[0] = iv->src_data[0];
102 			   __entry->src_data[1] = iv->src_data[1];
103 			   __entry->src_data[2] = iv->src_data[2];
104 			   __entry->src_data[3] = iv->src_data[3];
105 			   ),
106 	    TP_printk("client_id:%u src_id:%u ring:%u vmid:%u timestamp: %llu pasid:%u src_data: %08x %08x %08x %08x",
107 		      __entry->client_id, __entry->src_id,
108 		      __entry->ring_id, __entry->vmid,
109 		      __entry->timestamp, __entry->pasid,
110 		      __entry->src_data[0], __entry->src_data[1],
111 		      __entry->src_data[2], __entry->src_data[3])
112 );
113 
114 
115 TRACE_EVENT(amdgpu_bo_create,
116 	    TP_PROTO(struct amdgpu_bo *bo),
117 	    TP_ARGS(bo),
118 	    TP_STRUCT__entry(
119 			     __field(struct amdgpu_bo *, bo)
120 			     __field(u32, pages)
121 			     __field(u32, type)
122 			     __field(u32, prefer)
123 			     __field(u32, allow)
124 			     __field(u32, visible)
125 			     ),
126 
127 	    TP_fast_assign(
128 			   __entry->bo = bo;
129 			   __entry->pages = bo->tbo.num_pages;
130 			   __entry->type = bo->tbo.mem.mem_type;
131 			   __entry->prefer = bo->preferred_domains;
132 			   __entry->allow = bo->allowed_domains;
133 			   __entry->visible = bo->flags;
134 			   ),
135 
136 	    TP_printk("bo=%p, pages=%u, type=%d, preferred=%d, allowed=%d, visible=%d",
137 		       __entry->bo, __entry->pages, __entry->type,
138 		       __entry->prefer, __entry->allow, __entry->visible)
139 );
140 
141 TRACE_EVENT(amdgpu_cs,
142 	    TP_PROTO(struct amdgpu_cs_parser *p, int i),
143 	    TP_ARGS(p, i),
144 	    TP_STRUCT__entry(
145 			     __field(struct amdgpu_bo_list *, bo_list)
146 			     __field(u32, ring)
147 			     __field(u32, dw)
148 			     __field(u32, fences)
149 			     ),
150 
151 	    TP_fast_assign(
152 			   __entry->bo_list = p->bo_list;
153 			   __entry->ring = to_amdgpu_ring(p->entity->rq->sched)->idx;
154 			   __entry->dw = p->job->ibs[i].length_dw;
155 			   __entry->fences = amdgpu_fence_count_emitted(
156 				to_amdgpu_ring(p->entity->rq->sched));
157 			   ),
158 	    TP_printk("bo_list=%p, ring=%u, dw=%u, fences=%u",
159 		      __entry->bo_list, __entry->ring, __entry->dw,
160 		      __entry->fences)
161 );
162 
163 TRACE_EVENT(amdgpu_cs_ioctl,
164 	    TP_PROTO(struct amdgpu_job *job),
165 	    TP_ARGS(job),
166 	    TP_STRUCT__entry(
167 			     __field(uint64_t, sched_job_id)
168 			     __string(timeline, AMDGPU_JOB_GET_TIMELINE_NAME(job))
169 			     __field(unsigned int, context)
170 			     __field(unsigned int, seqno)
171 			     __field(struct dma_fence *, fence)
172 			     __field(char *, ring_name)
173 			     __field(u32, num_ibs)
174 			     ),
175 
176 	    TP_fast_assign(
177 			   __entry->sched_job_id = job->base.id;
178 			   __assign_str(timeline, AMDGPU_JOB_GET_TIMELINE_NAME(job))
179 			   __entry->context = job->base.s_fence->finished.context;
180 			   __entry->seqno = job->base.s_fence->finished.seqno;
181 			   __entry->ring_name = to_amdgpu_ring(job->base.sched)->name;
182 			   __entry->num_ibs = job->num_ibs;
183 			   ),
184 	    TP_printk("sched_job=%llu, timeline=%s, context=%u, seqno=%u, ring_name=%s, num_ibs=%u",
185 		      __entry->sched_job_id, __get_str(timeline), __entry->context,
186 		      __entry->seqno, __entry->ring_name, __entry->num_ibs)
187 );
188 
189 TRACE_EVENT(amdgpu_sched_run_job,
190 	    TP_PROTO(struct amdgpu_job *job),
191 	    TP_ARGS(job),
192 	    TP_STRUCT__entry(
193 			     __field(uint64_t, sched_job_id)
194 			     __string(timeline, AMDGPU_JOB_GET_TIMELINE_NAME(job))
195 			     __field(unsigned int, context)
196 			     __field(unsigned int, seqno)
197 			     __field(char *, ring_name)
198 			     __field(u32, num_ibs)
199 			     ),
200 
201 	    TP_fast_assign(
202 			   __entry->sched_job_id = job->base.id;
203 			   __assign_str(timeline, AMDGPU_JOB_GET_TIMELINE_NAME(job))
204 			   __entry->context = job->base.s_fence->finished.context;
205 			   __entry->seqno = job->base.s_fence->finished.seqno;
206 			   __entry->ring_name = to_amdgpu_ring(job->base.sched)->name;
207 			   __entry->num_ibs = job->num_ibs;
208 			   ),
209 	    TP_printk("sched_job=%llu, timeline=%s, context=%u, seqno=%u, ring_name=%s, num_ibs=%u",
210 		      __entry->sched_job_id, __get_str(timeline), __entry->context,
211 		      __entry->seqno, __entry->ring_name, __entry->num_ibs)
212 );
213 
214 
215 TRACE_EVENT(amdgpu_vm_grab_id,
216 	    TP_PROTO(struct amdgpu_vm *vm, struct amdgpu_ring *ring,
217 		     struct amdgpu_job *job),
218 	    TP_ARGS(vm, ring, job),
219 	    TP_STRUCT__entry(
220 			     __field(u32, pasid)
221 			     __string(ring, ring->name)
222 			     __field(u32, ring)
223 			     __field(u32, vmid)
224 			     __field(u32, vm_hub)
225 			     __field(u64, pd_addr)
226 			     __field(u32, needs_flush)
227 			     ),
228 
229 	    TP_fast_assign(
230 			   __entry->pasid = vm->pasid;
231 			   __assign_str(ring, ring->name)
232 			   __entry->vmid = job->vmid;
233 			   __entry->vm_hub = ring->funcs->vmhub,
234 			   __entry->pd_addr = job->vm_pd_addr;
235 			   __entry->needs_flush = job->vm_needs_flush;
236 			   ),
237 	    TP_printk("pasid=%d, ring=%s, id=%u, hub=%u, pd_addr=%010Lx needs_flush=%u",
238 		      __entry->pasid, __get_str(ring), __entry->vmid,
239 		      __entry->vm_hub, __entry->pd_addr, __entry->needs_flush)
240 );
241 
242 TRACE_EVENT(amdgpu_vm_bo_map,
243 	    TP_PROTO(struct amdgpu_bo_va *bo_va,
244 		     struct amdgpu_bo_va_mapping *mapping),
245 	    TP_ARGS(bo_va, mapping),
246 	    TP_STRUCT__entry(
247 			     __field(struct amdgpu_bo *, bo)
248 			     __field(long, start)
249 			     __field(long, last)
250 			     __field(u64, offset)
251 			     __field(u64, flags)
252 			     ),
253 
254 	    TP_fast_assign(
255 			   __entry->bo = bo_va ? bo_va->base.bo : NULL;
256 			   __entry->start = mapping->start;
257 			   __entry->last = mapping->last;
258 			   __entry->offset = mapping->offset;
259 			   __entry->flags = mapping->flags;
260 			   ),
261 	    TP_printk("bo=%p, start=%lx, last=%lx, offset=%010llx, flags=%llx",
262 		      __entry->bo, __entry->start, __entry->last,
263 		      __entry->offset, __entry->flags)
264 );
265 
266 TRACE_EVENT(amdgpu_vm_bo_unmap,
267 	    TP_PROTO(struct amdgpu_bo_va *bo_va,
268 		     struct amdgpu_bo_va_mapping *mapping),
269 	    TP_ARGS(bo_va, mapping),
270 	    TP_STRUCT__entry(
271 			     __field(struct amdgpu_bo *, bo)
272 			     __field(long, start)
273 			     __field(long, last)
274 			     __field(u64, offset)
275 			     __field(u64, flags)
276 			     ),
277 
278 	    TP_fast_assign(
279 			   __entry->bo = bo_va ? bo_va->base.bo : NULL;
280 			   __entry->start = mapping->start;
281 			   __entry->last = mapping->last;
282 			   __entry->offset = mapping->offset;
283 			   __entry->flags = mapping->flags;
284 			   ),
285 	    TP_printk("bo=%p, start=%lx, last=%lx, offset=%010llx, flags=%llx",
286 		      __entry->bo, __entry->start, __entry->last,
287 		      __entry->offset, __entry->flags)
288 );
289 
290 DECLARE_EVENT_CLASS(amdgpu_vm_mapping,
291 	    TP_PROTO(struct amdgpu_bo_va_mapping *mapping),
292 	    TP_ARGS(mapping),
293 	    TP_STRUCT__entry(
294 			     __field(u64, soffset)
295 			     __field(u64, eoffset)
296 			     __field(u64, flags)
297 			     ),
298 
299 	    TP_fast_assign(
300 			   __entry->soffset = mapping->start;
301 			   __entry->eoffset = mapping->last + 1;
302 			   __entry->flags = mapping->flags;
303 			   ),
304 	    TP_printk("soffs=%010llx, eoffs=%010llx, flags=%llx",
305 		      __entry->soffset, __entry->eoffset, __entry->flags)
306 );
307 
308 DEFINE_EVENT(amdgpu_vm_mapping, amdgpu_vm_bo_update,
309 	    TP_PROTO(struct amdgpu_bo_va_mapping *mapping),
310 	    TP_ARGS(mapping)
311 );
312 
313 DEFINE_EVENT(amdgpu_vm_mapping, amdgpu_vm_bo_mapping,
314 	    TP_PROTO(struct amdgpu_bo_va_mapping *mapping),
315 	    TP_ARGS(mapping)
316 );
317 
318 DEFINE_EVENT(amdgpu_vm_mapping, amdgpu_vm_bo_cs,
319 	    TP_PROTO(struct amdgpu_bo_va_mapping *mapping),
320 	    TP_ARGS(mapping)
321 );
322 
323 TRACE_EVENT(amdgpu_vm_set_ptes,
324 	    TP_PROTO(uint64_t pe, uint64_t addr, unsigned count,
325 		     uint32_t incr, uint64_t flags),
326 	    TP_ARGS(pe, addr, count, incr, flags),
327 	    TP_STRUCT__entry(
328 			     __field(u64, pe)
329 			     __field(u64, addr)
330 			     __field(u32, count)
331 			     __field(u32, incr)
332 			     __field(u64, flags)
333 			     ),
334 
335 	    TP_fast_assign(
336 			   __entry->pe = pe;
337 			   __entry->addr = addr;
338 			   __entry->count = count;
339 			   __entry->incr = incr;
340 			   __entry->flags = flags;
341 			   ),
342 	    TP_printk("pe=%010Lx, addr=%010Lx, incr=%u, flags=%llx, count=%u",
343 		      __entry->pe, __entry->addr, __entry->incr,
344 		      __entry->flags, __entry->count)
345 );
346 
347 TRACE_EVENT(amdgpu_vm_copy_ptes,
348 	    TP_PROTO(uint64_t pe, uint64_t src, unsigned count),
349 	    TP_ARGS(pe, src, count),
350 	    TP_STRUCT__entry(
351 			     __field(u64, pe)
352 			     __field(u64, src)
353 			     __field(u32, count)
354 			     ),
355 
356 	    TP_fast_assign(
357 			   __entry->pe = pe;
358 			   __entry->src = src;
359 			   __entry->count = count;
360 			   ),
361 	    TP_printk("pe=%010Lx, src=%010Lx, count=%u",
362 		      __entry->pe, __entry->src, __entry->count)
363 );
364 
365 TRACE_EVENT(amdgpu_vm_flush,
366 	    TP_PROTO(struct amdgpu_ring *ring, unsigned vmid,
367 		     uint64_t pd_addr),
368 	    TP_ARGS(ring, vmid, pd_addr),
369 	    TP_STRUCT__entry(
370 			     __string(ring, ring->name)
371 			     __field(u32, vmid)
372 			     __field(u32, vm_hub)
373 			     __field(u64, pd_addr)
374 			     ),
375 
376 	    TP_fast_assign(
377 			   __assign_str(ring, ring->name)
378 			   __entry->vmid = vmid;
379 			   __entry->vm_hub = ring->funcs->vmhub;
380 			   __entry->pd_addr = pd_addr;
381 			   ),
382 	    TP_printk("ring=%s, id=%u, hub=%u, pd_addr=%010Lx",
383 		      __get_str(ring), __entry->vmid,
384 		      __entry->vm_hub,__entry->pd_addr)
385 );
386 
387 DECLARE_EVENT_CLASS(amdgpu_pasid,
388 	    TP_PROTO(unsigned pasid),
389 	    TP_ARGS(pasid),
390 	    TP_STRUCT__entry(
391 			     __field(unsigned, pasid)
392 			     ),
393 	    TP_fast_assign(
394 			   __entry->pasid = pasid;
395 			   ),
396 	    TP_printk("pasid=%u", __entry->pasid)
397 );
398 
399 DEFINE_EVENT(amdgpu_pasid, amdgpu_pasid_allocated,
400 	    TP_PROTO(unsigned pasid),
401 	    TP_ARGS(pasid)
402 );
403 
404 DEFINE_EVENT(amdgpu_pasid, amdgpu_pasid_freed,
405 	    TP_PROTO(unsigned pasid),
406 	    TP_ARGS(pasid)
407 );
408 
409 TRACE_EVENT(amdgpu_bo_list_set,
410 	    TP_PROTO(struct amdgpu_bo_list *list, struct amdgpu_bo *bo),
411 	    TP_ARGS(list, bo),
412 	    TP_STRUCT__entry(
413 			     __field(struct amdgpu_bo_list *, list)
414 			     __field(struct amdgpu_bo *, bo)
415 			     __field(u64, bo_size)
416 			     ),
417 
418 	    TP_fast_assign(
419 			   __entry->list = list;
420 			   __entry->bo = bo;
421 			   __entry->bo_size = amdgpu_bo_size(bo);
422 			   ),
423 	    TP_printk("list=%p, bo=%p, bo_size=%Ld",
424 		      __entry->list,
425 		      __entry->bo,
426 		      __entry->bo_size)
427 );
428 
429 TRACE_EVENT(amdgpu_cs_bo_status,
430 	    TP_PROTO(uint64_t total_bo, uint64_t total_size),
431 	    TP_ARGS(total_bo, total_size),
432 	    TP_STRUCT__entry(
433 			__field(u64, total_bo)
434 			__field(u64, total_size)
435 			),
436 
437 	    TP_fast_assign(
438 			__entry->total_bo = total_bo;
439 			__entry->total_size = total_size;
440 			),
441 	    TP_printk("total_bo_size=%Ld, total_bo_count=%Ld",
442 			__entry->total_bo, __entry->total_size)
443 );
444 
445 TRACE_EVENT(amdgpu_bo_move,
446 	    TP_PROTO(struct amdgpu_bo* bo, uint32_t new_placement, uint32_t old_placement),
447 	    TP_ARGS(bo, new_placement, old_placement),
448 	    TP_STRUCT__entry(
449 			__field(struct amdgpu_bo *, bo)
450 			__field(u64, bo_size)
451 			__field(u32, new_placement)
452 			__field(u32, old_placement)
453 			),
454 
455 	    TP_fast_assign(
456 			__entry->bo      = bo;
457 			__entry->bo_size = amdgpu_bo_size(bo);
458 			__entry->new_placement = new_placement;
459 			__entry->old_placement = old_placement;
460 			),
461 	    TP_printk("bo=%p, from=%d, to=%d, size=%Ld",
462 			__entry->bo, __entry->old_placement,
463 			__entry->new_placement, __entry->bo_size)
464 );
465 
466 TRACE_EVENT(amdgpu_ib_pipe_sync,
467 	    TP_PROTO(struct amdgpu_job *sched_job, struct dma_fence *fence),
468 	    TP_ARGS(sched_job, fence),
469 	    TP_STRUCT__entry(
470 			     __field(const char *,name)
471 			     __field(uint64_t, id)
472 			     __field(struct dma_fence *, fence)
473 			     __field(uint64_t, ctx)
474 			     __field(unsigned, seqno)
475 			     ),
476 
477 	    TP_fast_assign(
478 			   __entry->name = sched_job->base.sched->name;
479 			   __entry->id = sched_job->base.id;
480 			   __entry->fence = fence;
481 			   __entry->ctx = fence->context;
482 			   __entry->seqno = fence->seqno;
483 			   ),
484 	    TP_printk("job ring=%s, id=%llu, need pipe sync to fence=%p, context=%llu, seq=%u",
485 		      __entry->name, __entry->id,
486 		      __entry->fence, __entry->ctx,
487 		      __entry->seqno)
488 );
489 
490 #undef AMDGPU_JOB_GET_TIMELINE_NAME
491 #endif
492 
493 /* This part must be outside protection */
494 #undef TRACE_INCLUDE_PATH
495 #define TRACE_INCLUDE_PATH ../../drivers/gpu/drm/amd/amdgpu
496 #include <trace/define_trace.h>
497