blob: 88236849894dd4aea8d54a8b1bc92dac1b161473 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001/* SPDX-License-Identifier: GPL-2.0 */
Ingo Molnarb814d412009-02-20 22:32:10 +01002#ifndef _LINUX_MMIOTRACE_H
3#define _LINUX_MMIOTRACE_H
Pekka Paalanen8b7d89d2008-05-12 21:20:56 +02004
Pekka Paalanen970e6fa2008-05-12 21:21:03 +02005#include <linux/types.h>
Pekka Paalanen0fd0e3d2008-05-12 21:20:57 +02006#include <linux/list.h>
7
8struct kmmio_probe;
9struct pt_regs;
10
11typedef void (*kmmio_pre_handler_t)(struct kmmio_probe *,
12 struct pt_regs *, unsigned long addr);
13typedef void (*kmmio_post_handler_t)(struct kmmio_probe *,
14 unsigned long condition, struct pt_regs *);
15
16struct kmmio_probe {
Ingo Molnarb814d412009-02-20 22:32:10 +010017 /* kmmio internal list: */
18 struct list_head list;
19 /* start location of the probe point: */
20 unsigned long addr;
21 /* length of the probe region: */
22 unsigned long len;
23 /* Called before addr is executed: */
24 kmmio_pre_handler_t pre_handler;
25 /* Called after addr is executed: */
26 kmmio_post_handler_t post_handler;
27 void *private;
Pekka Paalanen0fd0e3d2008-05-12 21:20:57 +020028};
29
Ingo Molnarb814d412009-02-20 22:32:10 +010030extern unsigned int kmmio_count;
Pekka Paalanen0fd0e3d2008-05-12 21:20:57 +020031
Pekka Paalanen0fd0e3d2008-05-12 21:20:57 +020032extern int register_kmmio_probe(struct kmmio_probe *p);
33extern void unregister_kmmio_probe(struct kmmio_probe *p);
Stuart Bennett0f9a6232009-04-28 20:17:51 +010034extern int kmmio_init(void);
35extern void kmmio_cleanup(void);
Pekka Paalanen0fd0e3d2008-05-12 21:20:57 +020036
Ingo Molnarb814d412009-02-20 22:32:10 +010037#ifdef CONFIG_MMIOTRACE
38/* kmmio is active by some kmmio_probes? */
39static inline int is_kmmio_active(void)
40{
41 return kmmio_count;
42}
43
Pekka Paalanen0fd0e3d2008-05-12 21:20:57 +020044/* Called from page fault handler. */
45extern int kmmio_handler(struct pt_regs *regs, unsigned long addr);
46
Pekka Paalanen9e57fb32008-09-16 22:00:34 +030047/* Called from ioremap.c */
Pekka Paalanendee310d2008-05-12 21:21:03 +020048extern void mmiotrace_ioremap(resource_size_t offset, unsigned long size,
49 void __iomem *addr);
Pekka Paalanend61fc442008-05-12 21:20:57 +020050extern void mmiotrace_iounmap(volatile void __iomem *addr);
Pekka Paalanen9e57fb32008-09-16 22:00:34 +030051
52/* For anyone to insert markers. Remember trailing newline. */
Joe Perchesb9075fa2011-10-31 17:11:33 -070053extern __printf(1, 2) int mmiotrace_printk(const char *fmt, ...);
Ingo Molnarb814d412009-02-20 22:32:10 +010054#else /* !CONFIG_MMIOTRACE: */
55static inline int is_kmmio_active(void)
56{
57 return 0;
58}
59
60static inline int kmmio_handler(struct pt_regs *regs, unsigned long addr)
61{
62 return 0;
63}
64
Pekka Paalanendee310d2008-05-12 21:21:03 +020065static inline void mmiotrace_ioremap(resource_size_t offset,
66 unsigned long size, void __iomem *addr)
Pekka Paalanend61fc442008-05-12 21:20:57 +020067{
68}
Pekka Paalanendee310d2008-05-12 21:21:03 +020069
Pekka Paalanend61fc442008-05-12 21:20:57 +020070static inline void mmiotrace_iounmap(volatile void __iomem *addr)
71{
72}
Pekka Paalanen9e57fb32008-09-16 22:00:34 +030073
Joe Perchesb9075fa2011-10-31 17:11:33 -070074static inline __printf(1, 2) int mmiotrace_printk(const char *fmt, ...)
Pekka Paalanen9e57fb32008-09-16 22:00:34 +030075{
76 return 0;
77}
78#endif /* CONFIG_MMIOTRACE */
Pekka Paalanend61fc442008-05-12 21:20:57 +020079
Pekka Paalanenbd8ac682008-05-12 21:20:57 +020080enum mm_io_opcode {
Ingo Molnarb814d412009-02-20 22:32:10 +010081 MMIO_READ = 0x1, /* struct mmiotrace_rw */
82 MMIO_WRITE = 0x2, /* struct mmiotrace_rw */
83 MMIO_PROBE = 0x3, /* struct mmiotrace_map */
84 MMIO_UNPROBE = 0x4, /* struct mmiotrace_map */
85 MMIO_UNKNOWN_OP = 0x5, /* struct mmiotrace_rw */
Pekka Paalanenbd8ac682008-05-12 21:20:57 +020086};
87
88struct mmiotrace_rw {
Ingo Molnarb814d412009-02-20 22:32:10 +010089 resource_size_t phys; /* PCI address of register */
90 unsigned long value;
91 unsigned long pc; /* optional program counter */
92 int map_id;
93 unsigned char opcode; /* one of MMIO_{READ,WRITE,UNKNOWN_OP} */
94 unsigned char width; /* size of register access in bytes */
Pekka Paalanenbd8ac682008-05-12 21:20:57 +020095};
96
97struct mmiotrace_map {
Ingo Molnarb814d412009-02-20 22:32:10 +010098 resource_size_t phys; /* base address in PCI space */
99 unsigned long virt; /* base virtual address */
100 unsigned long len; /* mapping size */
101 int map_id;
102 unsigned char opcode; /* MMIO_PROBE or MMIO_UNPROBE */
Pekka Paalanenbd8ac682008-05-12 21:20:57 +0200103};
104
Pekka Paalanenf984b512008-05-12 21:20:57 +0200105/* in kernel/trace/trace_mmiotrace.c */
Pekka Paalanenf984b512008-05-12 21:20:57 +0200106extern void enable_mmiotrace(void);
107extern void disable_mmiotrace(void);
Pekka Paalanenbd8ac682008-05-12 21:20:57 +0200108extern void mmio_trace_rw(struct mmiotrace_rw *rw);
109extern void mmio_trace_mapping(struct mmiotrace_map *map);
Nicolas Iooss8db14862015-07-17 16:23:42 -0700110extern __printf(1, 0) int mmio_trace_printk(const char *fmt, va_list args);
Pekka Paalanenf984b512008-05-12 21:20:57 +0200111
Ingo Molnarb814d412009-02-20 22:32:10 +0100112#endif /* _LINUX_MMIOTRACE_H */