xref: /netbsd/sys/external/bsd/drm2/dist/drm/i915/gvt/trace.h (revision 677dec6e)
1 /*	$NetBSD: trace.h,v 1.2 2021/12/18 23:45:31 riastradh Exp $	*/
2 
3 /*
4  * Copyright © 2011-2016 Intel Corporation
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a
7  * copy of this software and associated documentation files (the "Software"),
8  * to deal in the Software without restriction, including without limitation
9  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10  * and/or sell copies of the Software, and to permit persons to whom the
11  * Software is furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice (including the next
14  * paragraph) shall be included in all copies or substantial portions of the
15  * Software.
16  *
17  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
20  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
23  * IN THE SOFTWARE.
24  *
25  * Authors:
26  *    Jike Song <jike.song@intel.com>
27  *
28  * Contributors:
29  *    Zhi Wang <zhi.a.wang@intel.com>
30  *
31  */
32 
33 #if !defined(_GVT_TRACE_H_) || defined(TRACE_HEADER_MULTI_READ)
34 #define _GVT_TRACE_H_
35 
36 #include <linux/types.h>
37 #include <linux/stringify.h>
38 #include <linux/tracepoint.h>
39 #include <asm/tsc.h>
40 
41 #undef TRACE_SYSTEM
42 #define TRACE_SYSTEM gvt
43 
44 TRACE_EVENT(spt_alloc,
45 	TP_PROTO(int id, void *spt, int type, unsigned long mfn,
46 		unsigned long gpt_gfn),
47 
48 	TP_ARGS(id, spt, type, mfn, gpt_gfn),
49 
50 	TP_STRUCT__entry(
51 		__field(int, id)
52 		__field(void *, spt)
53 		__field(int, type)
54 		__field(unsigned long, mfn)
55 		__field(unsigned long, gpt_gfn)
56 		),
57 
58 	TP_fast_assign(
59 		__entry->id = id;
60 		__entry->spt = spt;
61 		__entry->type = type;
62 		__entry->mfn = mfn;
63 		__entry->gpt_gfn = gpt_gfn;
64 	),
65 
66 	TP_printk("VM%d [alloc] spt %p type %d mfn 0x%lx gfn 0x%lx\n",
67 		__entry->id,
68 		__entry->spt,
69 		__entry->type,
70 		__entry->mfn,
71 		__entry->gpt_gfn)
72 );
73 
74 TRACE_EVENT(spt_free,
75 	TP_PROTO(int id, void *spt, int type),
76 
77 	TP_ARGS(id, spt, type),
78 
79 	TP_STRUCT__entry(
80 		__field(int, id)
81 		__field(void *, spt)
82 		__field(int, type)
83 		),
84 
85 	TP_fast_assign(
86 		__entry->id = id;
87 		__entry->spt = spt;
88 		__entry->type = type;
89 	),
90 
91 	TP_printk("VM%u [free] spt %p type %d\n",
92 		__entry->id,
93 		__entry->spt,
94 		__entry->type)
95 );
96 
97 #define MAX_BUF_LEN 256
98 
99 TRACE_EVENT(gma_index,
100 	TP_PROTO(const char *prefix, unsigned long gma,
101 		unsigned long index),
102 
103 	TP_ARGS(prefix, gma, index),
104 
105 	TP_STRUCT__entry(
106 		__array(char, buf, MAX_BUF_LEN)
107 	),
108 
109 	TP_fast_assign(
110 		snprintf(__entry->buf, MAX_BUF_LEN,
111 			"%s gma 0x%lx index 0x%lx\n", prefix, gma, index);
112 	),
113 
114 	TP_printk("%s", __entry->buf)
115 );
116 
117 TRACE_EVENT(gma_translate,
118 	TP_PROTO(int id, char *type, int ring_id, int root_entry_type,
119 		unsigned long gma, unsigned long gpa),
120 
121 	TP_ARGS(id, type, ring_id, root_entry_type, gma, gpa),
122 
123 	TP_STRUCT__entry(
124 		__array(char, buf, MAX_BUF_LEN)
125 	),
126 
127 	TP_fast_assign(
128 		snprintf(__entry->buf, MAX_BUF_LEN,
129 			"VM%d %s ring %d root_entry_type %d gma 0x%lx -> gpa 0x%lx\n",
130 			id, type, ring_id, root_entry_type, gma, gpa);
131 	),
132 
133 	TP_printk("%s", __entry->buf)
134 );
135 
136 TRACE_EVENT(spt_refcount,
137 	TP_PROTO(int id, char *action, void *spt, int before, int after),
138 
139 	TP_ARGS(id, action, spt, before, after),
140 
141 	TP_STRUCT__entry(
142 		__array(char, buf, MAX_BUF_LEN)
143 	),
144 
145 	TP_fast_assign(
146 		snprintf(__entry->buf, MAX_BUF_LEN,
147 			"VM%d [%s] spt %p before %d -> after %d\n",
148 				id, action, spt, before, after);
149 	),
150 
151 	TP_printk("%s", __entry->buf)
152 );
153 
154 TRACE_EVENT(spt_change,
155 	TP_PROTO(int id, char *action, void *spt, unsigned long gfn,
156 		int type),
157 
158 	TP_ARGS(id, action, spt, gfn, type),
159 
160 	TP_STRUCT__entry(
161 		__array(char, buf, MAX_BUF_LEN)
162 	),
163 
164 	TP_fast_assign(
165 		snprintf(__entry->buf, MAX_BUF_LEN,
166 			"VM%d [%s] spt %p gfn 0x%lx type %d\n",
167 				id, action, spt, gfn, type);
168 	),
169 
170 	TP_printk("%s", __entry->buf)
171 );
172 
173 TRACE_EVENT(spt_guest_change,
174 	TP_PROTO(int id, const char *tag, void *spt, int type, u64 v,
175 		unsigned long index),
176 
177 	TP_ARGS(id, tag, spt, type, v, index),
178 
179 	TP_STRUCT__entry(
180 		__array(char, buf, MAX_BUF_LEN)
181 	),
182 
183 	TP_fast_assign(
184 		snprintf(__entry->buf, MAX_BUF_LEN,
185 		"VM%d [%s] spt %p type %d entry 0x%llx index 0x%lx\n",
186 			id, tag, spt, type, v, index);
187 	),
188 
189 	TP_printk("%s", __entry->buf)
190 );
191 
192 TRACE_EVENT(oos_change,
193 	TP_PROTO(int id, const char *tag, int page_id, void *gpt, int type),
194 
195 	TP_ARGS(id, tag, page_id, gpt, type),
196 
197 	TP_STRUCT__entry(
198 		__array(char, buf, MAX_BUF_LEN)
199 	),
200 
201 	TP_fast_assign(
202 		snprintf(__entry->buf, MAX_BUF_LEN,
203 		"VM%d [oos %s] page id %d gpt %p type %d\n",
204 			id, tag, page_id, gpt, type);
205 	),
206 
207 	TP_printk("%s", __entry->buf)
208 );
209 
210 TRACE_EVENT(oos_sync,
211 	TP_PROTO(int id, int page_id, void *gpt, int type, u64 v,
212 		unsigned long index),
213 
214 	TP_ARGS(id, page_id, gpt, type, v, index),
215 
216 	TP_STRUCT__entry(
217 		__array(char, buf, MAX_BUF_LEN)
218 	),
219 
220 	TP_fast_assign(
221 	snprintf(__entry->buf, MAX_BUF_LEN,
222 	"VM%d [oos sync] page id %d gpt %p type %d entry 0x%llx index 0x%lx\n",
223 				id, page_id, gpt, type, v, index);
224 	),
225 
226 	TP_printk("%s", __entry->buf)
227 );
228 
229 #define GVT_CMD_STR_LEN 40
230 TRACE_EVENT(gvt_command,
231 	TP_PROTO(u8 vgpu_id, u8 ring_id, u32 ip_gma, u32 *cmd_va,
232 		u32 cmd_len,  u32 buf_type, u32 buf_addr_type,
233 		void *workload, const char *cmd_name),
234 
235 	TP_ARGS(vgpu_id, ring_id, ip_gma, cmd_va, cmd_len, buf_type,
236 		buf_addr_type, workload, cmd_name),
237 
238 	TP_STRUCT__entry(
239 		__field(u8, vgpu_id)
240 		__field(u8, ring_id)
241 		__field(u32, ip_gma)
242 		__field(u32, buf_type)
243 		__field(u32, buf_addr_type)
244 		__field(u32, cmd_len)
245 		__field(void*, workload)
246 		__dynamic_array(u32, raw_cmd, cmd_len)
247 		__array(char, cmd_name, GVT_CMD_STR_LEN)
248 	),
249 
250 	TP_fast_assign(
251 		__entry->vgpu_id = vgpu_id;
252 		__entry->ring_id = ring_id;
253 		__entry->ip_gma = ip_gma;
254 		__entry->buf_type = buf_type;
255 		__entry->buf_addr_type = buf_addr_type;
256 		__entry->cmd_len = cmd_len;
257 		__entry->workload = workload;
258 		snprintf(__entry->cmd_name, GVT_CMD_STR_LEN, "%s", cmd_name);
259 		memcpy(__get_dynamic_array(raw_cmd), cmd_va, cmd_len * sizeof(*cmd_va));
260 	),
261 
262 
263 	TP_printk("vgpu%d ring %d: address_type %u, buf_type %u, ip_gma %08x,cmd (name=%s,len=%u,raw cmd=%s), workload=%p\n",
264 		__entry->vgpu_id,
265 		__entry->ring_id,
266 		__entry->buf_addr_type,
267 		__entry->buf_type,
268 		__entry->ip_gma,
269 		__entry->cmd_name,
270 		__entry->cmd_len,
271 		__print_array(__get_dynamic_array(raw_cmd),
272 			__entry->cmd_len, 4),
273 		__entry->workload)
274 );
275 
276 #define GVT_TEMP_STR_LEN 10
277 TRACE_EVENT(write_ir,
278 	TP_PROTO(int id, char *reg_name, unsigned int reg, unsigned int new_val,
279 		 unsigned int old_val, bool changed),
280 
281 	TP_ARGS(id, reg_name, reg, new_val, old_val, changed),
282 
283 	TP_STRUCT__entry(
284 		__field(int, id)
285 		__array(char, buf, GVT_TEMP_STR_LEN)
286 		__field(unsigned int, reg)
287 		__field(unsigned int, new_val)
288 		__field(unsigned int, old_val)
289 		__field(bool, changed)
290 	),
291 
292 	TP_fast_assign(
293 		__entry->id = id;
294 		snprintf(__entry->buf, GVT_TEMP_STR_LEN, "%s", reg_name);
295 		__entry->reg = reg;
296 		__entry->new_val = new_val;
297 		__entry->old_val = old_val;
298 		__entry->changed = changed;
299 	),
300 
301 	TP_printk("VM%u write [%s] %x, new %08x, old %08x, changed %08x\n",
302 		  __entry->id, __entry->buf, __entry->reg, __entry->new_val,
303 		  __entry->old_val, __entry->changed)
304 );
305 
306 TRACE_EVENT(propagate_event,
307 	TP_PROTO(int id, const char *irq_name, int bit),
308 
309 	TP_ARGS(id, irq_name, bit),
310 
311 	TP_STRUCT__entry(
312 		__field(int, id)
313 		__array(char, buf, GVT_TEMP_STR_LEN)
314 		__field(int, bit)
315 	),
316 
317 	TP_fast_assign(
318 		__entry->id = id;
319 		snprintf(__entry->buf, GVT_TEMP_STR_LEN, "%s", irq_name);
320 		__entry->bit = bit;
321 	),
322 
323 	TP_printk("Set bit (%d) for (%s) for vgpu (%d)\n",
324 		  __entry->bit, __entry->buf, __entry->id)
325 );
326 
327 TRACE_EVENT(inject_msi,
328 	TP_PROTO(int id, unsigned int address, unsigned int data),
329 
330 	TP_ARGS(id, address, data),
331 
332 	TP_STRUCT__entry(
333 		__field(int, id)
334 		__field(unsigned int, address)
335 		__field(unsigned int, data)
336 	),
337 
338 	TP_fast_assign(
339 		__entry->id = id;
340 		__entry->address = address;
341 		__entry->data = data;
342 	),
343 
344 	TP_printk("vgpu%d:inject msi address %x data %x\n",
345 		  __entry->id, __entry->address, __entry->data)
346 );
347 
348 TRACE_EVENT(render_mmio,
349 	TP_PROTO(int old_id, int new_id, char *action, unsigned int reg,
350 		 unsigned int old_val, unsigned int new_val),
351 
352 	TP_ARGS(old_id, new_id, action, reg, old_val, new_val),
353 
354 	TP_STRUCT__entry(
355 		__field(int, old_id)
356 		__field(int, new_id)
357 		__array(char, buf, GVT_TEMP_STR_LEN)
358 		__field(unsigned int, reg)
359 		__field(unsigned int, old_val)
360 		__field(unsigned int, new_val)
361 	),
362 
363 	TP_fast_assign(
364 		__entry->old_id = old_id;
365 		__entry->new_id = new_id;
366 		snprintf(__entry->buf, GVT_TEMP_STR_LEN, "%s", action);
367 		__entry->reg = reg;
368 		__entry->old_val = old_val;
369 		__entry->new_val = new_val;
370 	),
371 
372 	TP_printk("VM%u -> VM%u %s reg %x, old %08x new %08x\n",
373 		  __entry->old_id, __entry->new_id,
374 		  __entry->buf, __entry->reg,
375 		  __entry->old_val, __entry->new_val)
376 );
377 
378 #endif /* _GVT_TRACE_H_ */
379 
380 /* This part must be out of protection */
381 #undef TRACE_INCLUDE_PATH
382 #define TRACE_INCLUDE_PATH .
383 #undef TRACE_INCLUDE_FILE
384 #define TRACE_INCLUDE_FILE trace
385 #include <trace/define_trace.h>
386