1 /* SPDX-License-Identifier: GPL-2.0 */
3 #define TRACE_SYSTEM dma
5 #if !defined(_TRACE_DMA_H) || defined(TRACE_HEADER_MULTI_READ)
8 #include <linux/tracepoint.h>
9 #include <linux/dma-direction.h>
10 #include <linux/dma-mapping.h>
11 #include <trace/events/mmflags.h>
13 TRACE_DEFINE_ENUM(DMA_BIDIRECTIONAL
);
14 TRACE_DEFINE_ENUM(DMA_TO_DEVICE
);
15 TRACE_DEFINE_ENUM(DMA_FROM_DEVICE
);
16 TRACE_DEFINE_ENUM(DMA_NONE
);
18 #define decode_dma_data_direction(dir) \
19 __print_symbolic(dir, \
20 { DMA_BIDIRECTIONAL, "BIDIRECTIONAL" }, \
21 { DMA_TO_DEVICE, "TO_DEVICE" }, \
22 { DMA_FROM_DEVICE, "FROM_DEVICE" }, \
25 #define decode_dma_attrs(attrs) \
26 __print_flags(attrs, "|", \
27 { DMA_ATTR_WEAK_ORDERING, "WEAK_ORDERING" }, \
28 { DMA_ATTR_WRITE_COMBINE, "WRITE_COMBINE" }, \
29 { DMA_ATTR_NO_KERNEL_MAPPING, "NO_KERNEL_MAPPING" }, \
30 { DMA_ATTR_SKIP_CPU_SYNC, "SKIP_CPU_SYNC" }, \
31 { DMA_ATTR_FORCE_CONTIGUOUS, "FORCE_CONTIGUOUS" }, \
32 { DMA_ATTR_ALLOC_SINGLE_PAGES, "ALLOC_SINGLE_PAGES" }, \
33 { DMA_ATTR_NO_WARN, "NO_WARN" }, \
34 { DMA_ATTR_PRIVILEGED, "PRIVILEGED" })
36 DECLARE_EVENT_CLASS(dma_map
,
37 TP_PROTO(struct device
*dev
, phys_addr_t phys_addr
, dma_addr_t dma_addr
,
38 size_t size
, enum dma_data_direction dir
, unsigned long attrs
),
39 TP_ARGS(dev
, phys_addr
, dma_addr
, size
, dir
, attrs
),
42 __string(device
, dev_name(dev
))
43 __field(u64
, phys_addr
)
44 __field(u64
, dma_addr
)
46 __field(enum dma_data_direction
, dir
)
47 __field(unsigned long, attrs
)
52 __entry
->phys_addr
= phys_addr
;
53 __entry
->dma_addr
= dma_addr
;
56 __entry
->attrs
= attrs
;
59 TP_printk("%s dir=%s dma_addr=%llx size=%zu phys_addr=%llx attrs=%s",
61 decode_dma_data_direction(__entry
->dir
),
65 decode_dma_attrs(__entry
->attrs
))
68 #define DEFINE_MAP_EVENT(name) \
69 DEFINE_EVENT(dma_map, name, \
70 TP_PROTO(struct device *dev, phys_addr_t phys_addr, dma_addr_t dma_addr, \
71 size_t size, enum dma_data_direction dir, unsigned long attrs), \
72 TP_ARGS(dev, phys_addr, dma_addr, size, dir, attrs))
74 DEFINE_MAP_EVENT(dma_map_page
);
75 DEFINE_MAP_EVENT(dma_map_resource
);
77 DECLARE_EVENT_CLASS(dma_unmap
,
78 TP_PROTO(struct device
*dev
, dma_addr_t addr
, size_t size
,
79 enum dma_data_direction dir
, unsigned long attrs
),
80 TP_ARGS(dev
, addr
, size
, dir
, attrs
),
83 __string(device
, dev_name(dev
))
86 __field(enum dma_data_direction
, dir
)
87 __field(unsigned long, attrs
)
95 __entry
->attrs
= attrs
;
98 TP_printk("%s dir=%s dma_addr=%llx size=%zu attrs=%s",
100 decode_dma_data_direction(__entry
->dir
),
103 decode_dma_attrs(__entry
->attrs
))
106 #define DEFINE_UNMAP_EVENT(name) \
107 DEFINE_EVENT(dma_unmap, name, \
108 TP_PROTO(struct device *dev, dma_addr_t addr, size_t size, \
109 enum dma_data_direction dir, unsigned long attrs), \
110 TP_ARGS(dev, addr, size, dir, attrs))
112 DEFINE_UNMAP_EVENT(dma_unmap_page
);
113 DEFINE_UNMAP_EVENT(dma_unmap_resource
);
115 DECLARE_EVENT_CLASS(dma_alloc_class
,
116 TP_PROTO(struct device
*dev
, void *virt_addr
, dma_addr_t dma_addr
,
117 size_t size
, enum dma_data_direction dir
, gfp_t flags
,
118 unsigned long attrs
),
119 TP_ARGS(dev
, virt_addr
, dma_addr
, size
, dir
, flags
, attrs
),
122 __string(device
, dev_name(dev
))
123 __field(void *, virt_addr
)
124 __field(u64
, dma_addr
)
125 __field(size_t, size
)
126 __field(gfp_t
, flags
)
127 __field(enum dma_data_direction
, dir
)
128 __field(unsigned long, attrs
)
132 __assign_str(device
);
133 __entry
->virt_addr
= virt_addr
;
134 __entry
->dma_addr
= dma_addr
;
135 __entry
->size
= size
;
136 __entry
->flags
= flags
;
137 __entry
->attrs
= attrs
;
140 TP_printk("%s dir=%s dma_addr=%llx size=%zu virt_addr=%p flags=%s attrs=%s",
142 decode_dma_data_direction(__entry
->dir
),
146 show_gfp_flags(__entry
->flags
),
147 decode_dma_attrs(__entry
->attrs
))
150 #define DEFINE_ALLOC_EVENT(name) \
151 DEFINE_EVENT(dma_alloc_class, name, \
152 TP_PROTO(struct device *dev, void *virt_addr, dma_addr_t dma_addr, \
153 size_t size, enum dma_data_direction dir, gfp_t flags, \
154 unsigned long attrs), \
155 TP_ARGS(dev, virt_addr, dma_addr, size, dir, flags, attrs))
157 DEFINE_ALLOC_EVENT(dma_alloc
);
158 DEFINE_ALLOC_EVENT(dma_alloc_pages
);
159 DEFINE_ALLOC_EVENT(dma_alloc_sgt_err
);
161 TRACE_EVENT(dma_alloc_sgt
,
162 TP_PROTO(struct device
*dev
, struct sg_table
*sgt
, size_t size
,
163 enum dma_data_direction dir
, gfp_t flags
, unsigned long attrs
),
164 TP_ARGS(dev
, sgt
, size
, dir
, flags
, attrs
),
167 __string(device
, dev_name(dev
))
168 __dynamic_array(u64
, phys_addrs
, sgt
->orig_nents
)
169 __field(u64
, dma_addr
)
170 __field(size_t, size
)
171 __field(enum dma_data_direction
, dir
)
172 __field(gfp_t
, flags
)
173 __field(unsigned long, attrs
)
177 struct scatterlist
*sg
;
180 __assign_str(device
);
181 for_each_sg(sgt
->sgl
, sg
, sgt
->orig_nents
, i
)
182 ((u64
*)__get_dynamic_array(phys_addrs
))[i
] = sg_phys(sg
);
183 __entry
->dma_addr
= sg_dma_address(sgt
->sgl
);
184 __entry
->size
= size
;
186 __entry
->flags
= flags
;
187 __entry
->attrs
= attrs
;
190 TP_printk("%s dir=%s dma_addr=%llx size=%zu phys_addrs=%s flags=%s attrs=%s",
192 decode_dma_data_direction(__entry
->dir
),
195 __print_array(__get_dynamic_array(phys_addrs
),
196 __get_dynamic_array_len(phys_addrs
) /
197 sizeof(u64
), sizeof(u64
)),
198 show_gfp_flags(__entry
->flags
),
199 decode_dma_attrs(__entry
->attrs
))
202 DECLARE_EVENT_CLASS(dma_free_class
,
203 TP_PROTO(struct device
*dev
, void *virt_addr
, dma_addr_t dma_addr
,
204 size_t size
, enum dma_data_direction dir
, unsigned long attrs
),
205 TP_ARGS(dev
, virt_addr
, dma_addr
, size
, dir
, attrs
),
208 __string(device
, dev_name(dev
))
209 __field(void *, virt_addr
)
210 __field(u64
, dma_addr
)
211 __field(size_t, size
)
212 __field(enum dma_data_direction
, dir
)
213 __field(unsigned long, attrs
)
217 __assign_str(device
);
218 __entry
->virt_addr
= virt_addr
;
219 __entry
->dma_addr
= dma_addr
;
220 __entry
->size
= size
;
222 __entry
->attrs
= attrs
;
225 TP_printk("%s dir=%s dma_addr=%llx size=%zu virt_addr=%p attrs=%s",
227 decode_dma_data_direction(__entry
->dir
),
231 decode_dma_attrs(__entry
->attrs
))
234 #define DEFINE_FREE_EVENT(name) \
235 DEFINE_EVENT(dma_free_class, name, \
236 TP_PROTO(struct device *dev, void *virt_addr, dma_addr_t dma_addr, \
237 size_t size, enum dma_data_direction dir, unsigned long attrs), \
238 TP_ARGS(dev, virt_addr, dma_addr, size, dir, attrs))
240 DEFINE_FREE_EVENT(dma_free
);
241 DEFINE_FREE_EVENT(dma_free_pages
);
243 TRACE_EVENT(dma_free_sgt
,
244 TP_PROTO(struct device
*dev
, struct sg_table
*sgt
, size_t size
,
245 enum dma_data_direction dir
),
246 TP_ARGS(dev
, sgt
, size
, dir
),
249 __string(device
, dev_name(dev
))
250 __dynamic_array(u64
, phys_addrs
, sgt
->orig_nents
)
251 __field(u64
, dma_addr
)
252 __field(size_t, size
)
253 __field(enum dma_data_direction
, dir
)
257 struct scatterlist
*sg
;
260 __assign_str(device
);
261 for_each_sg(sgt
->sgl
, sg
, sgt
->orig_nents
, i
)
262 ((u64
*)__get_dynamic_array(phys_addrs
))[i
] = sg_phys(sg
);
263 __entry
->dma_addr
= sg_dma_address(sgt
->sgl
);
264 __entry
->size
= size
;
268 TP_printk("%s dir=%s dma_addr=%llx size=%zu phys_addrs=%s",
270 decode_dma_data_direction(__entry
->dir
),
273 __print_array(__get_dynamic_array(phys_addrs
),
274 __get_dynamic_array_len(phys_addrs
) /
275 sizeof(u64
), sizeof(u64
)))
278 TRACE_EVENT(dma_map_sg
,
279 TP_PROTO(struct device
*dev
, struct scatterlist
*sgl
, int nents
,
280 int ents
, enum dma_data_direction dir
, unsigned long attrs
),
281 TP_ARGS(dev
, sgl
, nents
, ents
, dir
, attrs
),
284 __string(device
, dev_name(dev
))
285 __dynamic_array(u64
, phys_addrs
, nents
)
286 __dynamic_array(u64
, dma_addrs
, ents
)
287 __dynamic_array(unsigned int, lengths
, ents
)
288 __field(enum dma_data_direction
, dir
)
289 __field(unsigned long, attrs
)
293 struct scatterlist
*sg
;
296 __assign_str(device
);
297 for_each_sg(sgl
, sg
, nents
, i
)
298 ((u64
*)__get_dynamic_array(phys_addrs
))[i
] = sg_phys(sg
);
299 for_each_sg(sgl
, sg
, ents
, i
) {
300 ((u64
*)__get_dynamic_array(dma_addrs
))[i
] =
302 ((unsigned int *)__get_dynamic_array(lengths
))[i
] =
306 __entry
->attrs
= attrs
;
309 TP_printk("%s dir=%s dma_addrs=%s sizes=%s phys_addrs=%s attrs=%s",
311 decode_dma_data_direction(__entry
->dir
),
312 __print_array(__get_dynamic_array(dma_addrs
),
313 __get_dynamic_array_len(dma_addrs
) /
314 sizeof(u64
), sizeof(u64
)),
315 __print_array(__get_dynamic_array(lengths
),
316 __get_dynamic_array_len(lengths
) /
317 sizeof(unsigned int), sizeof(unsigned int)),
318 __print_array(__get_dynamic_array(phys_addrs
),
319 __get_dynamic_array_len(phys_addrs
) /
320 sizeof(u64
), sizeof(u64
)),
321 decode_dma_attrs(__entry
->attrs
))
324 TRACE_EVENT(dma_map_sg_err
,
325 TP_PROTO(struct device
*dev
, struct scatterlist
*sgl
, int nents
,
326 int err
, enum dma_data_direction dir
, unsigned long attrs
),
327 TP_ARGS(dev
, sgl
, nents
, err
, dir
, attrs
),
330 __string(device
, dev_name(dev
))
331 __dynamic_array(u64
, phys_addrs
, nents
)
333 __field(enum dma_data_direction
, dir
)
334 __field(unsigned long, attrs
)
338 struct scatterlist
*sg
;
341 __assign_str(device
);
342 for_each_sg(sgl
, sg
, nents
, i
)
343 ((u64
*)__get_dynamic_array(phys_addrs
))[i
] = sg_phys(sg
);
346 __entry
->attrs
= attrs
;
349 TP_printk("%s dir=%s dma_addrs=%s err=%d attrs=%s",
351 decode_dma_data_direction(__entry
->dir
),
352 __print_array(__get_dynamic_array(phys_addrs
),
353 __get_dynamic_array_len(phys_addrs
) /
354 sizeof(u64
), sizeof(u64
)),
356 decode_dma_attrs(__entry
->attrs
))
359 TRACE_EVENT(dma_unmap_sg
,
360 TP_PROTO(struct device
*dev
, struct scatterlist
*sgl
, int nents
,
361 enum dma_data_direction dir
, unsigned long attrs
),
362 TP_ARGS(dev
, sgl
, nents
, dir
, attrs
),
365 __string(device
, dev_name(dev
))
366 __dynamic_array(u64
, addrs
, nents
)
367 __field(enum dma_data_direction
, dir
)
368 __field(unsigned long, attrs
)
372 struct scatterlist
*sg
;
375 __assign_str(device
);
376 for_each_sg(sgl
, sg
, nents
, i
)
377 ((u64
*)__get_dynamic_array(addrs
))[i
] = sg_phys(sg
);
379 __entry
->attrs
= attrs
;
382 TP_printk("%s dir=%s phys_addrs=%s attrs=%s",
384 decode_dma_data_direction(__entry
->dir
),
385 __print_array(__get_dynamic_array(addrs
),
386 __get_dynamic_array_len(addrs
) /
387 sizeof(u64
), sizeof(u64
)),
388 decode_dma_attrs(__entry
->attrs
))
391 DECLARE_EVENT_CLASS(dma_sync_single
,
392 TP_PROTO(struct device
*dev
, dma_addr_t dma_addr
, size_t size
,
393 enum dma_data_direction dir
),
394 TP_ARGS(dev
, dma_addr
, size
, dir
),
397 __string(device
, dev_name(dev
))
398 __field(u64
, dma_addr
)
399 __field(size_t, size
)
400 __field(enum dma_data_direction
, dir
)
404 __assign_str(device
);
405 __entry
->dma_addr
= dma_addr
;
406 __entry
->size
= size
;
410 TP_printk("%s dir=%s dma_addr=%llx size=%zu",
412 decode_dma_data_direction(__entry
->dir
),
417 #define DEFINE_SYNC_SINGLE_EVENT(name) \
418 DEFINE_EVENT(dma_sync_single, name, \
419 TP_PROTO(struct device *dev, dma_addr_t dma_addr, size_t size, \
420 enum dma_data_direction dir), \
421 TP_ARGS(dev, dma_addr, size, dir))
423 DEFINE_SYNC_SINGLE_EVENT(dma_sync_single_for_cpu
);
424 DEFINE_SYNC_SINGLE_EVENT(dma_sync_single_for_device
);
426 DECLARE_EVENT_CLASS(dma_sync_sg
,
427 TP_PROTO(struct device
*dev
, struct scatterlist
*sgl
, int nents
,
428 enum dma_data_direction dir
),
429 TP_ARGS(dev
, sgl
, nents
, dir
),
432 __string(device
, dev_name(dev
))
433 __dynamic_array(u64
, dma_addrs
, nents
)
434 __dynamic_array(unsigned int, lengths
, nents
)
435 __field(enum dma_data_direction
, dir
)
439 struct scatterlist
*sg
;
442 __assign_str(device
);
443 for_each_sg(sgl
, sg
, nents
, i
) {
444 ((u64
*)__get_dynamic_array(dma_addrs
))[i
] =
446 ((unsigned int *)__get_dynamic_array(lengths
))[i
] =
452 TP_printk("%s dir=%s dma_addrs=%s sizes=%s",
454 decode_dma_data_direction(__entry
->dir
),
455 __print_array(__get_dynamic_array(dma_addrs
),
456 __get_dynamic_array_len(dma_addrs
) /
457 sizeof(u64
), sizeof(u64
)),
458 __print_array(__get_dynamic_array(lengths
),
459 __get_dynamic_array_len(lengths
) /
460 sizeof(unsigned int), sizeof(unsigned int)))
463 #define DEFINE_SYNC_SG_EVENT(name) \
464 DEFINE_EVENT(dma_sync_sg, name, \
465 TP_PROTO(struct device *dev, struct scatterlist *sg, int nents, \
466 enum dma_data_direction dir), \
467 TP_ARGS(dev, sg, nents, dir))
469 DEFINE_SYNC_SG_EVENT(dma_sync_sg_for_cpu
);
470 DEFINE_SYNC_SG_EVENT(dma_sync_sg_for_device
);
472 #endif /* _TRACE_DMA_H */
474 /* This part must be outside protection */
475 #include <trace/define_trace.h>