blob: 3ba327af055cc43e4d38517fda8557420238f7f0 [file] [log] [blame]
Ingo Molnarb814d412009-02-20 22:32:10 +01001#ifndef _LINUX_MMIOTRACE_H
2#define _LINUX_MMIOTRACE_H
Pekka Paalanen8b7d89d2008-05-12 21:20:56 +02003
Pekka Paalanen970e6fa2008-05-12 21:21:03 +02004#include <linux/types.h>
Pekka Paalanen0fd0e3d2008-05-12 21:20:57 +02005#include <linux/list.h>
6
7struct kmmio_probe;
8struct pt_regs;
9
10typedef void (*kmmio_pre_handler_t)(struct kmmio_probe *,
11 struct pt_regs *, unsigned long addr);
12typedef void (*kmmio_post_handler_t)(struct kmmio_probe *,
13 unsigned long condition, struct pt_regs *);
14
15struct kmmio_probe {
Ingo Molnarb814d412009-02-20 22:32:10 +010016 /* kmmio internal list: */
17 struct list_head list;
18 /* start location of the probe point: */
19 unsigned long addr;
20 /* length of the probe region: */
21 unsigned long len;
22 /* Called before addr is executed: */
23 kmmio_pre_handler_t pre_handler;
24 /* Called after addr is executed: */
25 kmmio_post_handler_t post_handler;
26 void *private;
Pekka Paalanen0fd0e3d2008-05-12 21:20:57 +020027};
28
Ingo Molnarb814d412009-02-20 22:32:10 +010029extern unsigned int kmmio_count;
Pekka Paalanen0fd0e3d2008-05-12 21:20:57 +020030
Pekka Paalanen0fd0e3d2008-05-12 21:20:57 +020031extern int register_kmmio_probe(struct kmmio_probe *p);
32extern void unregister_kmmio_probe(struct kmmio_probe *p);
Stuart Bennett0f9a6232009-04-28 20:17:51 +010033extern int kmmio_init(void);
34extern void kmmio_cleanup(void);
Pekka Paalanen0fd0e3d2008-05-12 21:20:57 +020035
Ingo Molnarb814d412009-02-20 22:32:10 +010036#ifdef CONFIG_MMIOTRACE
37/* kmmio is active by some kmmio_probes? */
38static inline int is_kmmio_active(void)
39{
40 return kmmio_count;
41}
42
Pekka Paalanen0fd0e3d2008-05-12 21:20:57 +020043/* Called from page fault handler. */
44extern int kmmio_handler(struct pt_regs *regs, unsigned long addr);
45
Pekka Paalanen9e57fb32008-09-16 22:00:34 +030046/* Called from ioremap.c */
Pekka Paalanendee310d2008-05-12 21:21:03 +020047extern void mmiotrace_ioremap(resource_size_t offset, unsigned long size,
48 void __iomem *addr);
Pekka Paalanend61fc442008-05-12 21:20:57 +020049extern void mmiotrace_iounmap(volatile void __iomem *addr);
Pekka Paalanen9e57fb32008-09-16 22:00:34 +030050
51/* For anyone to insert markers. Remember trailing newline. */
Joe Perchesb9075fa2011-10-31 17:11:33 -070052extern __printf(1, 2) int mmiotrace_printk(const char *fmt, ...);
Ingo Molnarb814d412009-02-20 22:32:10 +010053#else /* !CONFIG_MMIOTRACE: */
54static inline int is_kmmio_active(void)
55{
56 return 0;
57}
58
59static inline int kmmio_handler(struct pt_regs *regs, unsigned long addr)
60{
61 return 0;
62}
63
Pekka Paalanendee310d2008-05-12 21:21:03 +020064static inline void mmiotrace_ioremap(resource_size_t offset,
65 unsigned long size, void __iomem *addr)
Pekka Paalanend61fc442008-05-12 21:20:57 +020066{
67}
Pekka Paalanendee310d2008-05-12 21:21:03 +020068
Pekka Paalanend61fc442008-05-12 21:20:57 +020069static inline void mmiotrace_iounmap(volatile void __iomem *addr)
70{
71}
Pekka Paalanen9e57fb32008-09-16 22:00:34 +030072
Joe Perchesb9075fa2011-10-31 17:11:33 -070073static inline __printf(1, 2) int mmiotrace_printk(const char *fmt, ...)
Pekka Paalanen9e57fb32008-09-16 22:00:34 +030074{
75 return 0;
76}
77#endif /* CONFIG_MMIOTRACE */
Pekka Paalanend61fc442008-05-12 21:20:57 +020078
Pekka Paalanenbd8ac682008-05-12 21:20:57 +020079enum mm_io_opcode {
Ingo Molnarb814d412009-02-20 22:32:10 +010080 MMIO_READ = 0x1, /* struct mmiotrace_rw */
81 MMIO_WRITE = 0x2, /* struct mmiotrace_rw */
82 MMIO_PROBE = 0x3, /* struct mmiotrace_map */
83 MMIO_UNPROBE = 0x4, /* struct mmiotrace_map */
84 MMIO_UNKNOWN_OP = 0x5, /* struct mmiotrace_rw */
Pekka Paalanenbd8ac682008-05-12 21:20:57 +020085};
86
87struct mmiotrace_rw {
Ingo Molnarb814d412009-02-20 22:32:10 +010088 resource_size_t phys; /* PCI address of register */
89 unsigned long value;
90 unsigned long pc; /* optional program counter */
91 int map_id;
92 unsigned char opcode; /* one of MMIO_{READ,WRITE,UNKNOWN_OP} */
93 unsigned char width; /* size of register access in bytes */
Pekka Paalanenbd8ac682008-05-12 21:20:57 +020094};
95
96struct mmiotrace_map {
Ingo Molnarb814d412009-02-20 22:32:10 +010097 resource_size_t phys; /* base address in PCI space */
98 unsigned long virt; /* base virtual address */
99 unsigned long len; /* mapping size */
100 int map_id;
101 unsigned char opcode; /* MMIO_PROBE or MMIO_UNPROBE */
Pekka Paalanenbd8ac682008-05-12 21:20:57 +0200102};
103
Pekka Paalanenf984b512008-05-12 21:20:57 +0200104/* in kernel/trace/trace_mmiotrace.c */
Pekka Paalanenf984b512008-05-12 21:20:57 +0200105extern void enable_mmiotrace(void);
106extern void disable_mmiotrace(void);
Pekka Paalanenbd8ac682008-05-12 21:20:57 +0200107extern void mmio_trace_rw(struct mmiotrace_rw *rw);
108extern void mmio_trace_mapping(struct mmiotrace_map *map);
Nicolas Iooss8db14862015-07-17 16:23:42 -0700109extern __printf(1, 0) int mmio_trace_printk(const char *fmt, va_list args);
Pekka Paalanenf984b512008-05-12 21:20:57 +0200110
Ingo Molnarb814d412009-02-20 22:32:10 +0100111#endif /* _LINUX_MMIOTRACE_H */