1 // SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note
2 /*
3 *
4 * (C) COPYRIGHT 2020-2022 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 #include <mali_kbase.h>
23 #include "debug/mali_kbase_debug_ktrace_internal.h"
24 #include "debug/backend/mali_kbase_debug_ktrace_jm.h"
25
26 #if KBASE_KTRACE_TARGET_RBUF
27
kbasep_ktrace_backend_format_header(char * buffer,int sz,s32 * written)28 void kbasep_ktrace_backend_format_header(char *buffer, int sz, s32 *written)
29 {
30 *written += MAX(snprintf(buffer + *written, MAX(sz - *written, 0),
31 "katom,gpu_addr,jobslot,refcount"), 0);
32 }
33
kbasep_ktrace_backend_format_msg(struct kbase_ktrace_msg * trace_msg,char * buffer,int sz,s32 * written)34 void kbasep_ktrace_backend_format_msg(struct kbase_ktrace_msg *trace_msg,
35 char *buffer, int sz, s32 *written)
36 {
37 /* katom */
38 if (trace_msg->backend.gpu.flags & KBASE_KTRACE_FLAG_JM_ATOM)
39 *written += MAX(snprintf(buffer + *written,
40 MAX(sz - *written, 0),
41 "atom %d (ud: 0x%llx 0x%llx)",
42 trace_msg->backend.gpu.atom_number,
43 trace_msg->backend.gpu.atom_udata[0],
44 trace_msg->backend.gpu.atom_udata[1]), 0);
45
46 /* gpu_addr */
47 if (trace_msg->backend.gpu.flags & KBASE_KTRACE_FLAG_BACKEND)
48 *written += MAX(snprintf(buffer + *written,
49 MAX(sz - *written, 0),
50 ",%.8llx,", trace_msg->backend.gpu.gpu_addr),
51 0);
52 else
53 *written += MAX(snprintf(buffer + *written,
54 MAX(sz - *written, 0),
55 ",,"), 0);
56
57 /* jobslot */
58 if (trace_msg->backend.gpu.flags & KBASE_KTRACE_FLAG_JM_JOBSLOT)
59 *written += MAX(snprintf(buffer + *written,
60 MAX(sz - *written, 0),
61 "%d", trace_msg->backend.gpu.jobslot), 0);
62
63 *written += MAX(snprintf(buffer + *written, MAX(sz - *written, 0),
64 ","), 0);
65
66 /* refcount */
67 if (trace_msg->backend.gpu.flags & KBASE_KTRACE_FLAG_JM_REFCOUNT)
68 *written += MAX(snprintf(buffer + *written,
69 MAX(sz - *written, 0),
70 "%d", trace_msg->backend.gpu.refcount), 0);
71 }
72
kbasep_ktrace_add_jm(struct kbase_device * kbdev,enum kbase_ktrace_code code,struct kbase_context * kctx,const struct kbase_jd_atom * katom,u64 gpu_addr,kbase_ktrace_flag_t flags,int refcount,int jobslot,u64 info_val)73 void kbasep_ktrace_add_jm(struct kbase_device *kbdev,
74 enum kbase_ktrace_code code,
75 struct kbase_context *kctx,
76 const struct kbase_jd_atom *katom, u64 gpu_addr,
77 kbase_ktrace_flag_t flags, int refcount, int jobslot,
78 u64 info_val)
79 {
80 unsigned long irqflags;
81 struct kbase_ktrace_msg *trace_msg;
82
83 if (unlikely(!kbasep_ktrace_initialized(&kbdev->ktrace)))
84 return;
85
86 spin_lock_irqsave(&kbdev->ktrace.lock, irqflags);
87
88 /* Reserve and update indices */
89 trace_msg = kbasep_ktrace_reserve(&kbdev->ktrace);
90
91 /* Fill the common part of the message (including backend.gpu.flags) */
92 kbasep_ktrace_msg_init(&kbdev->ktrace, trace_msg, code, kctx, flags,
93 info_val);
94
95 /* Indicate to the common code that backend-specific parts will be
96 * valid
97 */
98 trace_msg->backend.gpu.flags |= KBASE_KTRACE_FLAG_BACKEND;
99
100 /* Fill the JM-specific parts of the message */
101 if (katom) {
102 trace_msg->backend.gpu.flags |= KBASE_KTRACE_FLAG_JM_ATOM;
103
104 trace_msg->backend.gpu.atom_number =
105 kbase_jd_atom_id(katom->kctx, katom);
106 trace_msg->backend.gpu.atom_udata[0] = katom->udata.blob[0];
107 trace_msg->backend.gpu.atom_udata[1] = katom->udata.blob[1];
108 }
109
110 trace_msg->backend.gpu.gpu_addr = gpu_addr;
111 trace_msg->backend.gpu.jobslot = jobslot;
112 /* Clamp refcount */
113 trace_msg->backend.gpu.refcount = MIN((unsigned int)refcount, 0xFF);
114
115 WARN_ON((trace_msg->backend.gpu.flags & ~KBASE_KTRACE_FLAG_ALL));
116
117 /* Done */
118 spin_unlock_irqrestore(&kbdev->ktrace.lock, irqflags);
119 }
120
121 #endif /* KBASE_KTRACE_TARGET_RBUF */
122