1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  * Intel IOMMU trace support
4  *
5  * Copyright (C) 2019 Intel Corporation
6  *
7  * Author: Lu Baolu <baolu.lu@linux.intel.com>
8  */
9 #ifdef CONFIG_INTEL_IOMMU
10 #undef TRACE_SYSTEM
11 #define TRACE_SYSTEM intel_iommu
12 
13 #if !defined(_TRACE_INTEL_IOMMU_H) || defined(TRACE_HEADER_MULTI_READ)
14 #define _TRACE_INTEL_IOMMU_H
15 
16 #include <linux/tracepoint.h>
17 #include <linux/intel-iommu.h>
18 
19 DECLARE_EVENT_CLASS(dma_map,
20 	TP_PROTO(struct device *dev, dma_addr_t dev_addr, phys_addr_t phys_addr,
21 		 size_t size),
22 
23 	TP_ARGS(dev, dev_addr, phys_addr, size),
24 
25 	TP_STRUCT__entry(
26 		__string(dev_name, dev_name(dev))
27 		__field(dma_addr_t, dev_addr)
28 		__field(phys_addr_t, phys_addr)
29 		__field(size_t,	size)
30 	),
31 
32 	TP_fast_assign(
33 		__assign_str(dev_name, dev_name(dev));
34 		__entry->dev_addr = dev_addr;
35 		__entry->phys_addr = phys_addr;
36 		__entry->size = size;
37 	),
38 
39 	TP_printk("dev=%s dev_addr=0x%llx phys_addr=0x%llx size=%zu",
40 		  __get_str(dev_name),
41 		  (unsigned long long)__entry->dev_addr,
42 		  (unsigned long long)__entry->phys_addr,
43 		  __entry->size)
44 );
45 
46 DEFINE_EVENT(dma_map, map_single,
47 	TP_PROTO(struct device *dev, dma_addr_t dev_addr, phys_addr_t phys_addr,
48 		 size_t size),
49 	TP_ARGS(dev, dev_addr, phys_addr, size)
50 );
51 
52 DEFINE_EVENT(dma_map, bounce_map_single,
53 	TP_PROTO(struct device *dev, dma_addr_t dev_addr, phys_addr_t phys_addr,
54 		 size_t size),
55 	TP_ARGS(dev, dev_addr, phys_addr, size)
56 );
57 
58 DECLARE_EVENT_CLASS(dma_unmap,
59 	TP_PROTO(struct device *dev, dma_addr_t dev_addr, size_t size),
60 
61 	TP_ARGS(dev, dev_addr, size),
62 
63 	TP_STRUCT__entry(
64 		__string(dev_name, dev_name(dev))
65 		__field(dma_addr_t, dev_addr)
66 		__field(size_t,	size)
67 	),
68 
69 	TP_fast_assign(
70 		__assign_str(dev_name, dev_name(dev));
71 		__entry->dev_addr = dev_addr;
72 		__entry->size = size;
73 	),
74 
75 	TP_printk("dev=%s dev_addr=0x%llx size=%zu",
76 		  __get_str(dev_name),
77 		  (unsigned long long)__entry->dev_addr,
78 		  __entry->size)
79 );
80 
81 DEFINE_EVENT(dma_unmap, unmap_single,
82 	TP_PROTO(struct device *dev, dma_addr_t dev_addr, size_t size),
83 	TP_ARGS(dev, dev_addr, size)
84 );
85 
86 DEFINE_EVENT(dma_unmap, unmap_sg,
87 	TP_PROTO(struct device *dev, dma_addr_t dev_addr, size_t size),
88 	TP_ARGS(dev, dev_addr, size)
89 );
90 
91 DEFINE_EVENT(dma_unmap, bounce_unmap_single,
92 	TP_PROTO(struct device *dev, dma_addr_t dev_addr, size_t size),
93 	TP_ARGS(dev, dev_addr, size)
94 );
95 
96 DECLARE_EVENT_CLASS(dma_map_sg,
97 	TP_PROTO(struct device *dev, int index, int total,
98 		 struct scatterlist *sg),
99 
100 	TP_ARGS(dev, index, total, sg),
101 
102 	TP_STRUCT__entry(
103 		__string(dev_name, dev_name(dev))
104 		__field(dma_addr_t, dev_addr)
105 		__field(phys_addr_t, phys_addr)
106 		__field(size_t,	size)
107 		__field(int, index)
108 		__field(int, total)
109 	),
110 
111 	TP_fast_assign(
112 		__assign_str(dev_name, dev_name(dev));
113 		__entry->dev_addr = sg->dma_address;
114 		__entry->phys_addr = sg_phys(sg);
115 		__entry->size = sg->dma_length;
116 		__entry->index = index;
117 		__entry->total = total;
118 	),
119 
120 	TP_printk("dev=%s [%d/%d] dev_addr=0x%llx phys_addr=0x%llx size=%zu",
121 		  __get_str(dev_name), __entry->index, __entry->total,
122 		  (unsigned long long)__entry->dev_addr,
123 		  (unsigned long long)__entry->phys_addr,
124 		  __entry->size)
125 );
126 
127 DEFINE_EVENT(dma_map_sg, map_sg,
128 	TP_PROTO(struct device *dev, int index, int total,
129 		 struct scatterlist *sg),
130 	TP_ARGS(dev, index, total, sg)
131 );
132 
133 DEFINE_EVENT(dma_map_sg, bounce_map_sg,
134 	TP_PROTO(struct device *dev, int index, int total,
135 		 struct scatterlist *sg),
136 	TP_ARGS(dev, index, total, sg)
137 );
138 #endif /* _TRACE_INTEL_IOMMU_H */
139 
140 /* This part must be outside protection */
141 #include <trace/define_trace.h>
142 #endif /* CONFIG_INTEL_IOMMU */
143