1 /* SPDX-License-Identifier: GPL-2.0 */ 2 #undef TRACE_SYSTEM 3 #define TRACE_SYSTEM dma 4 5 #if !defined(_TRACE_DMA_H) || defined(TRACE_HEADER_MULTI_READ) 6 #define _TRACE_DMA_H 7 8 #include <linux/tracepoint.h> 9 #include <linux/dma-direction.h> 10 #include <linux/dma-mapping.h> 11 #include <trace/events/mmflags.h> 12 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); 17 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" }, \ 23 { DMA_NONE, "NONE" }) 24 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" }) 35 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), 40 41 TP_STRUCT__entry( 42 __string(device, dev_name(dev)) 43 __field(u64, phys_addr) 44 __field(u64, dma_addr) 45 __field(size_t, size) 46 __field(enum dma_data_direction, dir) 47 __field(unsigned long, attrs) 48 ), 49 50 TP_fast_assign( 51 __assign_str(device); 52 __entry->phys_addr = phys_addr; 53 __entry->dma_addr = dma_addr; 54 __entry->size = size; 55 __entry->dir = dir; 56 __entry->attrs = attrs; 57 ), 58 59 TP_printk("%s dir=%s dma_addr=%llx size=%zu phys_addr=%llx attrs=%s", 60 __get_str(device), 61 decode_dma_data_direction(__entry->dir), 62 __entry->dma_addr, 63 __entry->size, 64 __entry->phys_addr, 65 decode_dma_attrs(__entry->attrs)) 66 ); 67 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)) 73 74 DEFINE_MAP_EVENT(dma_map_page); 75 DEFINE_MAP_EVENT(dma_map_resource); 76 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), 81 82 TP_STRUCT__entry( 83 __string(device, dev_name(dev)) 84 __field(u64, addr) 85 __field(size_t, size) 86 __field(enum dma_data_direction, dir) 87 __field(unsigned long, attrs) 88 ), 89 90 TP_fast_assign( 91 __assign_str(device); 92 __entry->addr = addr; 93 __entry->size = size; 94 __entry->dir = dir; 95 __entry->attrs = attrs; 96 ), 97 98 TP_printk("%s dir=%s dma_addr=%llx size=%zu attrs=%s", 99 __get_str(device), 100 decode_dma_data_direction(__entry->dir), 101 __entry->addr, 102 __entry->size, 103 decode_dma_attrs(__entry->attrs)) 104 ); 105 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)) 111 112 DEFINE_UNMAP_EVENT(dma_unmap_page); 113 DEFINE_UNMAP_EVENT(dma_unmap_resource); 114 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), 120 121 TP_STRUCT__entry( 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) 129 ), 130 131 TP_fast_assign( 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; 138 ), 139 140 TP_printk("%s dir=%s dma_addr=%llx size=%zu virt_addr=%p flags=%s attrs=%s", 141 __get_str(device), 142 decode_dma_data_direction(__entry->dir), 143 __entry->dma_addr, 144 __entry->size, 145 __entry->virt_addr, 146 show_gfp_flags(__entry->flags), 147 decode_dma_attrs(__entry->attrs)) 148 ); 149 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)) 156 157 DEFINE_ALLOC_EVENT(dma_alloc); 158 DEFINE_ALLOC_EVENT(dma_alloc_pages); 159 DEFINE_ALLOC_EVENT(dma_alloc_sgt_err); 160 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), 165 166 TP_STRUCT__entry( 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) 174 ), 175 176 TP_fast_assign( 177 struct scatterlist *sg; 178 int i; 179 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; 185 __entry->dir = dir; 186 __entry->flags = flags; 187 __entry->attrs = attrs; 188 ), 189 190 TP_printk("%s dir=%s dma_addr=%llx size=%zu phys_addrs=%s flags=%s attrs=%s", 191 __get_str(device), 192 decode_dma_data_direction(__entry->dir), 193 __entry->dma_addr, 194 __entry->size, 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)) 200 ); 201 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), 206 207 TP_STRUCT__entry( 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) 214 ), 215 216 TP_fast_assign( 217 __assign_str(device); 218 __entry->virt_addr = virt_addr; 219 __entry->dma_addr = dma_addr; 220 __entry->size = size; 221 __entry->dir = dir; 222 __entry->attrs = attrs; 223 ), 224 225 TP_printk("%s dir=%s dma_addr=%llx size=%zu virt_addr=%p attrs=%s", 226 __get_str(device), 227 decode_dma_data_direction(__entry->dir), 228 __entry->dma_addr, 229 __entry->size, 230 __entry->virt_addr, 231 decode_dma_attrs(__entry->attrs)) 232 ); 233 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)) 239 240 DEFINE_FREE_EVENT(dma_free); 241 DEFINE_FREE_EVENT(dma_free_pages); 242 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), 247 248 TP_STRUCT__entry( 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) 254 ), 255 256 TP_fast_assign( 257 struct scatterlist *sg; 258 int i; 259 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; 265 __entry->dir = dir; 266 ), 267 268 TP_printk("%s dir=%s dma_addr=%llx size=%zu phys_addrs=%s", 269 __get_str(device), 270 decode_dma_data_direction(__entry->dir), 271 __entry->dma_addr, 272 __entry->size, 273 __print_array(__get_dynamic_array(phys_addrs), 274 __get_dynamic_array_len(phys_addrs) / 275 sizeof(u64), sizeof(u64))) 276 ); 277 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), 282 283 TP_STRUCT__entry( 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) 290 ), 291 292 TP_fast_assign( 293 struct scatterlist *sg; 294 int i; 295 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] = 301 sg_dma_address(sg); 302 ((unsigned int *)__get_dynamic_array(lengths))[i] = 303 sg_dma_len(sg); 304 } 305 __entry->dir = dir; 306 __entry->attrs = attrs; 307 ), 308 309 TP_printk("%s dir=%s dma_addrs=%s sizes=%s phys_addrs=%s attrs=%s", 310 __get_str(device), 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)) 322 ); 323 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), 328 329 TP_STRUCT__entry( 330 __string(device, dev_name(dev)) 331 __dynamic_array(u64, phys_addrs, nents) 332 __field(int, err) 333 __field(enum dma_data_direction, dir) 334 __field(unsigned long, attrs) 335 ), 336 337 TP_fast_assign( 338 struct scatterlist *sg; 339 int i; 340 341 __assign_str(device); 342 for_each_sg(sgl, sg, nents, i) 343 ((u64 *)__get_dynamic_array(phys_addrs))[i] = sg_phys(sg); 344 __entry->err = err; 345 __entry->dir = dir; 346 __entry->attrs = attrs; 347 ), 348 349 TP_printk("%s dir=%s dma_addrs=%s err=%d attrs=%s", 350 __get_str(device), 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)), 355 __entry->err, 356 decode_dma_attrs(__entry->attrs)) 357 ); 358 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), 363 364 TP_STRUCT__entry( 365 __string(device, dev_name(dev)) 366 __dynamic_array(u64, addrs, nents) 367 __field(enum dma_data_direction, dir) 368 __field(unsigned long, attrs) 369 ), 370 371 TP_fast_assign( 372 struct scatterlist *sg; 373 int i; 374 375 __assign_str(device); 376 for_each_sg(sgl, sg, nents, i) 377 ((u64 *)__get_dynamic_array(addrs))[i] = sg_phys(sg); 378 __entry->dir = dir; 379 __entry->attrs = attrs; 380 ), 381 382 TP_printk("%s dir=%s phys_addrs=%s attrs=%s", 383 __get_str(device), 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)) 389 ); 390 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), 395 396 TP_STRUCT__entry( 397 __string(device, dev_name(dev)) 398 __field(u64, dma_addr) 399 __field(size_t, size) 400 __field(enum dma_data_direction, dir) 401 ), 402 403 TP_fast_assign( 404 __assign_str(device); 405 __entry->dma_addr = dma_addr; 406 __entry->size = size; 407 __entry->dir = dir; 408 ), 409 410 TP_printk("%s dir=%s dma_addr=%llx size=%zu", 411 __get_str(device), 412 decode_dma_data_direction(__entry->dir), 413 __entry->dma_addr, 414 __entry->size) 415 ); 416 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)) 422 423 DEFINE_SYNC_SINGLE_EVENT(dma_sync_single_for_cpu); 424 DEFINE_SYNC_SINGLE_EVENT(dma_sync_single_for_device); 425 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), 430 431 TP_STRUCT__entry( 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) 436 ), 437 438 TP_fast_assign( 439 struct scatterlist *sg; 440 int i; 441 442 __assign_str(device); 443 for_each_sg(sgl, sg, nents, i) { 444 ((u64 *)__get_dynamic_array(dma_addrs))[i] = 445 sg_dma_address(sg); 446 ((unsigned int *)__get_dynamic_array(lengths))[i] = 447 sg_dma_len(sg); 448 } 449 __entry->dir = dir; 450 ), 451 452 TP_printk("%s dir=%s dma_addrs=%s sizes=%s", 453 __get_str(device), 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))) 461 ); 462 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)) 468 469 DEFINE_SYNC_SG_EVENT(dma_sync_sg_for_cpu); 470 DEFINE_SYNC_SG_EVENT(dma_sync_sg_for_device); 471 472 #endif /* _TRACE_DMA_H */ 473 474 /* This part must be outside protection */ 475 #include <trace/define_trace.h> 476