summaryrefslogtreecommitdiff
path: root/include/trace/events/dma.h
blob: f57f05331d73851ba535e44d5f8d10b9e57b4577 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
/* SPDX-License-Identifier: GPL-2.0 */
#undef TRACE_SYSTEM
#define TRACE_SYSTEM dma

#if !defined(_TRACE_DMA_H) || defined(TRACE_HEADER_MULTI_READ)
#define _TRACE_DMA_H

#include <linux/tracepoint.h>
#include <linux/dma-direction.h>
#include <linux/dma-mapping.h>
#include <trace/events/mmflags.h>

TRACE_DEFINE_ENUM(DMA_BIDIRECTIONAL);
TRACE_DEFINE_ENUM(DMA_TO_DEVICE);
TRACE_DEFINE_ENUM(DMA_FROM_DEVICE);
TRACE_DEFINE_ENUM(DMA_NONE);

#define decode_dma_data_direction(dir) \
	__print_symbolic(dir, \
		{ DMA_BIDIRECTIONAL, "BIDIRECTIONAL" }, \
		{ DMA_TO_DEVICE, "TO_DEVICE" }, \
		{ DMA_FROM_DEVICE, "FROM_DEVICE" }, \
		{ DMA_NONE, "NONE" })

#define decode_dma_attrs(attrs) \
	__print_flags(attrs, "|", \
		{ DMA_ATTR_WEAK_ORDERING, "WEAK_ORDERING" }, \
		{ DMA_ATTR_WRITE_COMBINE, "WRITE_COMBINE" }, \
		{ DMA_ATTR_NO_KERNEL_MAPPING, "NO_KERNEL_MAPPING" }, \
		{ DMA_ATTR_SKIP_CPU_SYNC, "SKIP_CPU_SYNC" }, \
		{ DMA_ATTR_FORCE_CONTIGUOUS, "FORCE_CONTIGUOUS" }, \
		{ DMA_ATTR_ALLOC_SINGLE_PAGES, "ALLOC_SINGLE_PAGES" }, \
		{ DMA_ATTR_NO_WARN, "NO_WARN" }, \
		{ DMA_ATTR_PRIVILEGED, "PRIVILEGED" })

DECLARE_EVENT_CLASS(dma_map,
	TP_PROTO(struct device *dev, phys_addr_t phys_addr, dma_addr_t dma_addr,
		 size_t size, enum dma_data_direction dir, unsigned long attrs),
	TP_ARGS(dev, phys_addr, dma_addr, size, dir, attrs),

	TP_STRUCT__entry(
		__string(device, dev_name(dev))
		__field(u64, phys_addr)
		__field(u64, dma_addr)
		__field(size_t, size)
		__field(enum dma_data_direction, dir)
		__field(unsigned long, attrs)
	),

	TP_fast_assign(
		__assign_str(device);
		__entry->phys_addr = phys_addr;
		__entry->dma_addr = dma_addr;
		__entry->size = size;
		__entry->dir = dir;
		__entry->attrs = attrs;
	),

	TP_printk("%s dir=%s dma_addr=%llx size=%zu phys_addr=%llx attrs=%s",
		__get_str(device),
		decode_dma_data_direction(__entry->dir),
		__entry->dma_addr,
		__entry->size,
		__entry->phys_addr,
		decode_dma_attrs(__entry->attrs))
);

DEFINE_EVENT(dma_map, dma_map_page,
	TP_PROTO(struct device *dev, phys_addr_t phys_addr, dma_addr_t dma_addr,
		 size_t size, enum dma_data_direction dir, unsigned long attrs),
	TP_ARGS(dev, phys_addr, dma_addr, size, dir, attrs));

DEFINE_EVENT(dma_map, dma_map_resource,
	TP_PROTO(struct device *dev, phys_addr_t phys_addr, dma_addr_t dma_addr,
		 size_t size, enum dma_data_direction dir, unsigned long attrs),
	TP_ARGS(dev, phys_addr, dma_addr, size, dir, attrs));

DECLARE_EVENT_CLASS(dma_unmap,
	TP_PROTO(struct device *dev, dma_addr_t addr, size_t size,
		 enum dma_data_direction dir, unsigned long attrs),
	TP_ARGS(dev, addr, size, dir, attrs),

	TP_STRUCT__entry(
		__string(device, dev_name(dev))
		__field(u64, addr)
		__field(size_t, size)
		__field(enum dma_data_direction, dir)
		__field(unsigned long, attrs)
	),

	TP_fast_assign(
		__assign_str(device);
		__entry->addr = addr;
		__entry->size = size;
		__entry->dir = dir;
		__entry->attrs = attrs;
	),

	TP_printk("%s dir=%s dma_addr=%llx size=%zu attrs=%s",
		__get_str(device),
		decode_dma_data_direction(__entry->dir),
		__entry->addr,
		__entry->size,
		decode_dma_attrs(__entry->attrs))
);

DEFINE_EVENT(dma_unmap, dma_unmap_page,
	TP_PROTO(struct device *dev, dma_addr_t addr, size_t size,
		 enum dma_data_direction dir, unsigned long attrs),
	TP_ARGS(dev, addr, size, dir, attrs));

DEFINE_EVENT(dma_unmap, dma_unmap_resource,
	TP_PROTO(struct device *dev, dma_addr_t addr, size_t size,
		 enum dma_data_direction dir, unsigned long attrs),
	TP_ARGS(dev, addr, size, dir, attrs));

TRACE_EVENT(dma_alloc,
	TP_PROTO(struct device *dev, void *virt_addr, dma_addr_t dma_addr,
		 size_t size, gfp_t flags, unsigned long attrs),
	TP_ARGS(dev, virt_addr, dma_addr, size, flags, attrs),

	TP_STRUCT__entry(
		__string(device, dev_name(dev))
		__field(u64, phys_addr)
		__field(u64, dma_addr)
		__field(size_t, size)
		__field(gfp_t, flags)
		__field(unsigned long, attrs)
	),

	TP_fast_assign(
		__assign_str(device);
		__entry->phys_addr = virt_to_phys(virt_addr);
		__entry->dma_addr = dma_addr;
		__entry->size = size;
		__entry->flags = flags;
		__entry->attrs = attrs;
	),

	TP_printk("%s dma_addr=%llx size=%zu phys_addr=%llx flags=%s attrs=%s",
		__get_str(device),
		__entry->dma_addr,
		__entry->size,
		__entry->phys_addr,
		show_gfp_flags(__entry->flags),
		decode_dma_attrs(__entry->attrs))
);

TRACE_EVENT(dma_free,
	TP_PROTO(struct device *dev, void *virt_addr, dma_addr_t dma_addr,
		 size_t size, unsigned long attrs),
	TP_ARGS(dev, virt_addr, dma_addr, size, attrs),

	TP_STRUCT__entry(
		__string(device, dev_name(dev))
		__field(u64, phys_addr)
		__field(u64, dma_addr)
		__field(size_t, size)
		__field(unsigned long, attrs)
	),

	TP_fast_assign(
		__assign_str(device);
		__entry->phys_addr = virt_to_phys(virt_addr);
		__entry->dma_addr = dma_addr;
		__entry->size = size;
		__entry->attrs = attrs;
	),

	TP_printk("%s dma_addr=%llx size=%zu phys_addr=%llx attrs=%s",
		__get_str(device),
		__entry->dma_addr,
		__entry->size,
		__entry->phys_addr,
		decode_dma_attrs(__entry->attrs))
);

TRACE_EVENT(dma_map_sg,
	TP_PROTO(struct device *dev, struct scatterlist *sg, int nents,
		 int ents, enum dma_data_direction dir, unsigned long attrs),
	TP_ARGS(dev, sg, nents, ents, dir, attrs),

	TP_STRUCT__entry(
		__string(device, dev_name(dev))
		__dynamic_array(u64, phys_addrs, nents)
		__dynamic_array(u64, dma_addrs, ents)
		__dynamic_array(unsigned int, lengths, ents)
		__field(enum dma_data_direction, dir)
		__field(unsigned long, attrs)
	),

	TP_fast_assign(
		int i;

		__assign_str(device);
		for (i = 0; i < nents; i++)
			((u64 *)__get_dynamic_array(phys_addrs))[i] =
				sg_phys(sg + i);
		for (i = 0; i < ents; i++) {
			((u64 *)__get_dynamic_array(dma_addrs))[i] =
				sg_dma_address(sg + i);
			((unsigned int *)__get_dynamic_array(lengths))[i] =
				sg_dma_len(sg + i);
		}
		__entry->dir = dir;
		__entry->attrs = attrs;
	),

	TP_printk("%s dir=%s dma_addrs=%s sizes=%s phys_addrs=%s attrs=%s",
		__get_str(device),
		decode_dma_data_direction(__entry->dir),
		__print_array(__get_dynamic_array(dma_addrs),
			      __get_dynamic_array_len(dma_addrs) /
				sizeof(u64), sizeof(u64)),
		__print_array(__get_dynamic_array(lengths),
			      __get_dynamic_array_len(lengths) /
				sizeof(unsigned int), sizeof(unsigned int)),
		__print_array(__get_dynamic_array(phys_addrs),
			      __get_dynamic_array_len(phys_addrs) /
				sizeof(u64), sizeof(u64)),
		decode_dma_attrs(__entry->attrs))
);

TRACE_EVENT(dma_unmap_sg,
	TP_PROTO(struct device *dev, struct scatterlist *sg, int nents,
		 enum dma_data_direction dir, unsigned long attrs),
	TP_ARGS(dev, sg, nents, dir, attrs),

	TP_STRUCT__entry(
		__string(device, dev_name(dev))
		__dynamic_array(u64, addrs, nents)
		__field(enum dma_data_direction, dir)
		__field(unsigned long, attrs)
	),

	TP_fast_assign(
		int i;

		__assign_str(device);
		for (i = 0; i < nents; i++)
			((u64 *)__get_dynamic_array(addrs))[i] =
				sg_phys(sg + i);
		__entry->dir = dir;
		__entry->attrs = attrs;
	),

	TP_printk("%s dir=%s phys_addrs=%s attrs=%s",
		__get_str(device),
		decode_dma_data_direction(__entry->dir),
		__print_array(__get_dynamic_array(addrs),
			      __get_dynamic_array_len(addrs) /
				sizeof(u64), sizeof(u64)),
		decode_dma_attrs(__entry->attrs))
);

DECLARE_EVENT_CLASS(dma_sync_single,
	TP_PROTO(struct device *dev, dma_addr_t dma_addr, size_t size,
		 enum dma_data_direction dir),
	TP_ARGS(dev, dma_addr, size, dir),

	TP_STRUCT__entry(
		__string(device, dev_name(dev))
		__field(u64, dma_addr)
		__field(size_t, size)
		__field(enum dma_data_direction, dir)
	),

	TP_fast_assign(
		__assign_str(device);
		__entry->dma_addr = dma_addr;
		__entry->size = size;
		__entry->dir = dir;
	),

	TP_printk("%s dir=%s dma_addr=%llx size=%zu",
		__get_str(device),
		decode_dma_data_direction(__entry->dir),
		__entry->dma_addr,
		__entry->size)
);

DEFINE_EVENT(dma_sync_single, dma_sync_single_for_cpu,
	TP_PROTO(struct device *dev, dma_addr_t dma_addr, size_t size,
		 enum dma_data_direction dir),
	TP_ARGS(dev, dma_addr, size, dir));

DEFINE_EVENT(dma_sync_single, dma_sync_single_for_device,
	TP_PROTO(struct device *dev, dma_addr_t dma_addr, size_t size,
		 enum dma_data_direction dir),
	TP_ARGS(dev, dma_addr, size, dir));

DECLARE_EVENT_CLASS(dma_sync_sg,
	TP_PROTO(struct device *dev, struct scatterlist *sg, int nents,
		 enum dma_data_direction dir),
	TP_ARGS(dev, sg, nents, dir),

	TP_STRUCT__entry(
		__string(device, dev_name(dev))
		__dynamic_array(u64, dma_addrs, nents)
		__dynamic_array(unsigned int, lengths, nents)
		__field(enum dma_data_direction, dir)
	),

	TP_fast_assign(
		int i;

		__assign_str(device);
		for (i = 0; i < nents; i++) {
			((u64 *)__get_dynamic_array(dma_addrs))[i] =
				sg_dma_address(sg + i);
			((unsigned int *)__get_dynamic_array(lengths))[i] =
				sg_dma_len(sg + i);
		}
		__entry->dir = dir;
	),

	TP_printk("%s dir=%s dma_addrs=%s sizes=%s",
		__get_str(device),
		decode_dma_data_direction(__entry->dir),
		__print_array(__get_dynamic_array(dma_addrs),
			      __get_dynamic_array_len(dma_addrs) /
				sizeof(u64), sizeof(u64)),
		__print_array(__get_dynamic_array(lengths),
			      __get_dynamic_array_len(lengths) /
				sizeof(unsigned int), sizeof(unsigned int)))
);

DEFINE_EVENT(dma_sync_sg, dma_sync_sg_for_cpu,
	TP_PROTO(struct device *dev, struct scatterlist *sg, int nents,
		 enum dma_data_direction dir),
	TP_ARGS(dev, sg, nents, dir));

DEFINE_EVENT(dma_sync_sg, dma_sync_sg_for_device,
	TP_PROTO(struct device *dev, struct scatterlist *sg, int nents,
		 enum dma_data_direction dir),
	TP_ARGS(dev, sg, nents, dir));

#endif /*  _TRACE_DMA_H */

/* This part must be outside protection */
#include <trace/define_trace.h>