10
10
#include <asm/page.h> /* I/O is all done through memory accesses */
11
11
#include <linux/string.h> /* for memset() and memcpy() */
12
12
#include <linux/types.h>
13
+ #include <linux/instruction_pointer.h>
13
14
14
15
#ifdef CONFIG_GENERIC_IOMAP
15
16
#include <asm-generic/iomap.h>
61
62
#define __io_par (v ) __io_ar(v)
62
63
#endif
63
64
65
+ /*
66
+ * "__DISABLE_TRACE_MMIO__" flag can be used to disable MMIO tracing for
67
+ * specific kernel drivers in case of excessive/unwanted logging.
68
+ *
69
+ * Usage: Add a #define flag at the beginning of the driver file.
70
+ * Ex: #define __DISABLE_TRACE_MMIO__
71
+ * #include <...>
72
+ * ...
73
+ */
74
+ #if IS_ENABLED (CONFIG_TRACE_MMIO_ACCESS ) && !(defined(__DISABLE_TRACE_MMIO__ ))
75
+ #include <linux/tracepoint-defs.h>
76
+
77
+ DECLARE_TRACEPOINT (rwmmio_write );
78
+ DECLARE_TRACEPOINT (rwmmio_post_write );
79
+ DECLARE_TRACEPOINT (rwmmio_read );
80
+ DECLARE_TRACEPOINT (rwmmio_post_read );
81
+
82
+ void log_write_mmio (u64 val , u8 width , volatile void __iomem * addr ,
83
+ unsigned long caller_addr );
84
+ void log_post_write_mmio (u64 val , u8 width , volatile void __iomem * addr ,
85
+ unsigned long caller_addr );
86
+ void log_read_mmio (u8 width , const volatile void __iomem * addr ,
87
+ unsigned long caller_addr );
88
+ void log_post_read_mmio (u64 val , u8 width , const volatile void __iomem * addr ,
89
+ unsigned long caller_addr );
90
+
91
+ #else
92
+
93
+ static inline void log_write_mmio (u64 val , u8 width , volatile void __iomem * addr ,
94
+ unsigned long caller_addr ) {}
95
+ static inline void log_post_write_mmio (u64 val , u8 width , volatile void __iomem * addr ,
96
+ unsigned long caller_addr ) {}
97
+ static inline void log_read_mmio (u8 width , const volatile void __iomem * addr ,
98
+ unsigned long caller_addr ) {}
99
+ static inline void log_post_read_mmio (u64 val , u8 width , const volatile void __iomem * addr ,
100
+ unsigned long caller_addr ) {}
101
+
102
+ #endif /* CONFIG_TRACE_MMIO_ACCESS */
64
103
65
104
/*
66
105
* __raw_{read,write}{b,w,l,q}() access memory in native endianness.
@@ -149,9 +188,11 @@ static inline u8 readb(const volatile void __iomem *addr)
149
188
{
150
189
u8 val ;
151
190
191
+ log_read_mmio (8 , addr , _THIS_IP_ );
152
192
__io_br ();
153
193
val = __raw_readb (addr );
154
194
__io_ar (val );
195
+ log_post_read_mmio (val , 8 , addr , _THIS_IP_ );
155
196
return val ;
156
197
}
157
198
#endif
@@ -162,9 +203,11 @@ static inline u16 readw(const volatile void __iomem *addr)
162
203
{
163
204
u16 val ;
164
205
206
+ log_read_mmio (16 , addr , _THIS_IP_ );
165
207
__io_br ();
166
208
val = __le16_to_cpu ((__le16 __force )__raw_readw (addr ));
167
209
__io_ar (val );
210
+ log_post_read_mmio (val , 16 , addr , _THIS_IP_ );
168
211
return val ;
169
212
}
170
213
#endif
@@ -175,9 +218,11 @@ static inline u32 readl(const volatile void __iomem *addr)
175
218
{
176
219
u32 val ;
177
220
221
+ log_read_mmio (32 , addr , _THIS_IP_ );
178
222
__io_br ();
179
223
val = __le32_to_cpu ((__le32 __force )__raw_readl (addr ));
180
224
__io_ar (val );
225
+ log_post_read_mmio (val , 32 , addr , _THIS_IP_ );
181
226
return val ;
182
227
}
183
228
#endif
@@ -189,9 +234,11 @@ static inline u64 readq(const volatile void __iomem *addr)
189
234
{
190
235
u64 val ;
191
236
237
+ log_read_mmio (64 , addr , _THIS_IP_ );
192
238
__io_br ();
193
239
val = __le64_to_cpu (__raw_readq (addr ));
194
240
__io_ar (val );
241
+ log_post_read_mmio (val , 64 , addr , _THIS_IP_ );
195
242
return val ;
196
243
}
197
244
#endif
@@ -201,29 +248,35 @@ static inline u64 readq(const volatile void __iomem *addr)
201
248
#define writeb writeb
202
249
static inline void writeb (u8 value , volatile void __iomem * addr )
203
250
{
251
+ log_write_mmio (value , 8 , addr , _THIS_IP_ );
204
252
__io_bw ();
205
253
__raw_writeb (value , addr );
206
254
__io_aw ();
255
+ log_post_write_mmio (value , 8 , addr , _THIS_IP_ );
207
256
}
208
257
#endif
209
258
210
259
#ifndef writew
211
260
#define writew writew
212
261
static inline void writew (u16 value , volatile void __iomem * addr )
213
262
{
263
+ log_write_mmio (value , 16 , addr , _THIS_IP_ );
214
264
__io_bw ();
215
265
__raw_writew ((u16 __force )cpu_to_le16 (value ), addr );
216
266
__io_aw ();
267
+ log_post_write_mmio (value , 16 , addr , _THIS_IP_ );
217
268
}
218
269
#endif
219
270
220
271
#ifndef writel
221
272
#define writel writel
222
273
static inline void writel (u32 value , volatile void __iomem * addr )
223
274
{
275
+ log_write_mmio (value , 32 , addr , _THIS_IP_ );
224
276
__io_bw ();
225
277
__raw_writel ((u32 __force )__cpu_to_le32 (value ), addr );
226
278
__io_aw ();
279
+ log_post_write_mmio (value , 32 , addr , _THIS_IP_ );
227
280
}
228
281
#endif
229
282
@@ -232,9 +285,11 @@ static inline void writel(u32 value, volatile void __iomem *addr)
232
285
#define writeq writeq
233
286
static inline void writeq (u64 value , volatile void __iomem * addr )
234
287
{
288
+ log_write_mmio (value , 64 , addr , _THIS_IP_ );
235
289
__io_bw ();
236
290
__raw_writeq (__cpu_to_le64 (value ), addr );
237
291
__io_aw ();
292
+ log_post_write_mmio (value , 64 , addr , _THIS_IP_ );
238
293
}
239
294
#endif
240
295
#endif /* CONFIG_64BIT */
@@ -248,63 +303,91 @@ static inline void writeq(u64 value, volatile void __iomem *addr)
248
303
#define readb_relaxed readb_relaxed
249
304
static inline u8 readb_relaxed (const volatile void __iomem * addr )
250
305
{
251
- return __raw_readb (addr );
306
+ u8 val ;
307
+
308
+ log_read_mmio (8 , addr , _THIS_IP_ );
309
+ val = __raw_readb (addr );
310
+ log_post_read_mmio (val , 8 , addr , _THIS_IP_ );
311
+ return val ;
252
312
}
253
313
#endif
254
314
255
315
#ifndef readw_relaxed
256
316
#define readw_relaxed readw_relaxed
257
317
static inline u16 readw_relaxed (const volatile void __iomem * addr )
258
318
{
259
- return __le16_to_cpu (__raw_readw (addr ));
319
+ u16 val ;
320
+
321
+ log_read_mmio (16 , addr , _THIS_IP_ );
322
+ val = __le16_to_cpu (__raw_readw (addr ));
323
+ log_post_read_mmio (val , 16 , addr , _THIS_IP_ );
324
+ return val ;
260
325
}
261
326
#endif
262
327
263
328
#ifndef readl_relaxed
264
329
#define readl_relaxed readl_relaxed
265
330
static inline u32 readl_relaxed (const volatile void __iomem * addr )
266
331
{
267
- return __le32_to_cpu (__raw_readl (addr ));
332
+ u32 val ;
333
+
334
+ log_read_mmio (32 , addr , _THIS_IP_ );
335
+ val = __le32_to_cpu (__raw_readl (addr ));
336
+ log_post_read_mmio (val , 32 , addr , _THIS_IP_ );
337
+ return val ;
268
338
}
269
339
#endif
270
340
271
341
#if defined(readq ) && !defined(readq_relaxed )
272
342
#define readq_relaxed readq_relaxed
273
343
static inline u64 readq_relaxed (const volatile void __iomem * addr )
274
344
{
275
- return __le64_to_cpu (__raw_readq (addr ));
345
+ u64 val ;
346
+
347
+ log_read_mmio (64 , addr , _THIS_IP_ );
348
+ val = __le64_to_cpu (__raw_readq (addr ));
349
+ log_post_read_mmio (val , 64 , addr , _THIS_IP_ );
350
+ return val ;
276
351
}
277
352
#endif
278
353
279
354
#ifndef writeb_relaxed
280
355
#define writeb_relaxed writeb_relaxed
281
356
static inline void writeb_relaxed (u8 value , volatile void __iomem * addr )
282
357
{
358
+ log_write_mmio (value , 8 , addr , _THIS_IP_ );
283
359
__raw_writeb (value , addr );
360
+ log_post_write_mmio (value , 8 , addr , _THIS_IP_ );
284
361
}
285
362
#endif
286
363
287
364
#ifndef writew_relaxed
288
365
#define writew_relaxed writew_relaxed
289
366
static inline void writew_relaxed (u16 value , volatile void __iomem * addr )
290
367
{
368
+ log_write_mmio (value , 16 , addr , _THIS_IP_ );
291
369
__raw_writew (cpu_to_le16 (value ), addr );
370
+ log_post_write_mmio (value , 16 , addr , _THIS_IP_ );
292
371
}
293
372
#endif
294
373
295
374
#ifndef writel_relaxed
296
375
#define writel_relaxed writel_relaxed
297
376
static inline void writel_relaxed (u32 value , volatile void __iomem * addr )
298
377
{
378
+ log_write_mmio (value , 32 , addr , _THIS_IP_ );
299
379
__raw_writel (__cpu_to_le32 (value ), addr );
380
+ log_post_write_mmio (value , 32 , addr , _THIS_IP_ );
300
381
}
301
382
#endif
302
383
303
384
#if defined(writeq ) && !defined(writeq_relaxed )
304
385
#define writeq_relaxed writeq_relaxed
305
386
static inline void writeq_relaxed (u64 value , volatile void __iomem * addr )
306
387
{
388
+ log_write_mmio (value , 64 , addr , _THIS_IP_ );
307
389
__raw_writeq (__cpu_to_le64 (value ), addr );
390
+ log_post_write_mmio (value , 64 , addr , _THIS_IP_ );
308
391
}
309
392
#endif
310
393
0 commit comments