Ingo Molnar | b814d41 | 2009-02-20 22:32:10 +0100 | [diff] [blame] | 1 | #ifndef _LINUX_MMIOTRACE_H |
| 2 | #define _LINUX_MMIOTRACE_H |
Pekka Paalanen | 8b7d89d | 2008-05-12 21:20:56 +0200 | [diff] [blame] | 3 | |
Pekka Paalanen | 970e6fa | 2008-05-12 21:21:03 +0200 | [diff] [blame] | 4 | #include <linux/types.h> |
Pekka Paalanen | 0fd0e3d | 2008-05-12 21:20:57 +0200 | [diff] [blame] | 5 | #include <linux/list.h> |
| 6 | |
| 7 | struct kmmio_probe; |
| 8 | struct pt_regs; |
| 9 | |
| 10 | typedef void (*kmmio_pre_handler_t)(struct kmmio_probe *, |
| 11 | struct pt_regs *, unsigned long addr); |
| 12 | typedef void (*kmmio_post_handler_t)(struct kmmio_probe *, |
| 13 | unsigned long condition, struct pt_regs *); |
| 14 | |
| 15 | struct kmmio_probe { |
Ingo Molnar | b814d41 | 2009-02-20 22:32:10 +0100 | [diff] [blame] | 16 | /* 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 Paalanen | 0fd0e3d | 2008-05-12 21:20:57 +0200 | [diff] [blame] | 27 | }; |
| 28 | |
Ingo Molnar | b814d41 | 2009-02-20 22:32:10 +0100 | [diff] [blame] | 29 | extern unsigned int kmmio_count; |
Pekka Paalanen | 0fd0e3d | 2008-05-12 21:20:57 +0200 | [diff] [blame] | 30 | |
Pekka Paalanen | 0fd0e3d | 2008-05-12 21:20:57 +0200 | [diff] [blame] | 31 | extern int register_kmmio_probe(struct kmmio_probe *p); |
| 32 | extern void unregister_kmmio_probe(struct kmmio_probe *p); |
Stuart Bennett | 0f9a623 | 2009-04-28 20:17:51 +0100 | [diff] [blame] | 33 | extern int kmmio_init(void); |
| 34 | extern void kmmio_cleanup(void); |
Pekka Paalanen | 0fd0e3d | 2008-05-12 21:20:57 +0200 | [diff] [blame] | 35 | |
Ingo Molnar | b814d41 | 2009-02-20 22:32:10 +0100 | [diff] [blame] | 36 | #ifdef CONFIG_MMIOTRACE |
| 37 | /* kmmio is active by some kmmio_probes? */ |
| 38 | static inline int is_kmmio_active(void) |
| 39 | { |
| 40 | return kmmio_count; |
| 41 | } |
| 42 | |
Pekka Paalanen | 0fd0e3d | 2008-05-12 21:20:57 +0200 | [diff] [blame] | 43 | /* Called from page fault handler. */ |
| 44 | extern int kmmio_handler(struct pt_regs *regs, unsigned long addr); |
| 45 | |
Pekka Paalanen | 9e57fb3 | 2008-09-16 22:00:34 +0300 | [diff] [blame] | 46 | /* Called from ioremap.c */ |
Pekka Paalanen | dee310d | 2008-05-12 21:21:03 +0200 | [diff] [blame] | 47 | extern void mmiotrace_ioremap(resource_size_t offset, unsigned long size, |
| 48 | void __iomem *addr); |
Pekka Paalanen | d61fc44 | 2008-05-12 21:20:57 +0200 | [diff] [blame] | 49 | extern void mmiotrace_iounmap(volatile void __iomem *addr); |
Pekka Paalanen | 9e57fb3 | 2008-09-16 22:00:34 +0300 | [diff] [blame] | 50 | |
| 51 | /* For anyone to insert markers. Remember trailing newline. */ |
| 52 | extern int mmiotrace_printk(const char *fmt, ...) |
| 53 | __attribute__ ((format (printf, 1, 2))); |
Ingo Molnar | b814d41 | 2009-02-20 22:32:10 +0100 | [diff] [blame] | 54 | #else /* !CONFIG_MMIOTRACE: */ |
| 55 | static inline int is_kmmio_active(void) |
| 56 | { |
| 57 | return 0; |
| 58 | } |
| 59 | |
| 60 | static inline int kmmio_handler(struct pt_regs *regs, unsigned long addr) |
| 61 | { |
| 62 | return 0; |
| 63 | } |
| 64 | |
Pekka Paalanen | dee310d | 2008-05-12 21:21:03 +0200 | [diff] [blame] | 65 | static inline void mmiotrace_ioremap(resource_size_t offset, |
| 66 | unsigned long size, void __iomem *addr) |
Pekka Paalanen | d61fc44 | 2008-05-12 21:20:57 +0200 | [diff] [blame] | 67 | { |
| 68 | } |
Pekka Paalanen | dee310d | 2008-05-12 21:21:03 +0200 | [diff] [blame] | 69 | |
Pekka Paalanen | d61fc44 | 2008-05-12 21:20:57 +0200 | [diff] [blame] | 70 | static inline void mmiotrace_iounmap(volatile void __iomem *addr) |
| 71 | { |
| 72 | } |
Pekka Paalanen | 9e57fb3 | 2008-09-16 22:00:34 +0300 | [diff] [blame] | 73 | |
| 74 | static inline int mmiotrace_printk(const char *fmt, ...) |
| 75 | __attribute__ ((format (printf, 1, 0))); |
| 76 | |
| 77 | static inline int mmiotrace_printk(const char *fmt, ...) |
| 78 | { |
| 79 | return 0; |
| 80 | } |
| 81 | #endif /* CONFIG_MMIOTRACE */ |
Pekka Paalanen | d61fc44 | 2008-05-12 21:20:57 +0200 | [diff] [blame] | 82 | |
Pekka Paalanen | bd8ac68 | 2008-05-12 21:20:57 +0200 | [diff] [blame] | 83 | enum mm_io_opcode { |
Ingo Molnar | b814d41 | 2009-02-20 22:32:10 +0100 | [diff] [blame] | 84 | MMIO_READ = 0x1, /* struct mmiotrace_rw */ |
| 85 | MMIO_WRITE = 0x2, /* struct mmiotrace_rw */ |
| 86 | MMIO_PROBE = 0x3, /* struct mmiotrace_map */ |
| 87 | MMIO_UNPROBE = 0x4, /* struct mmiotrace_map */ |
| 88 | MMIO_UNKNOWN_OP = 0x5, /* struct mmiotrace_rw */ |
Pekka Paalanen | bd8ac68 | 2008-05-12 21:20:57 +0200 | [diff] [blame] | 89 | }; |
| 90 | |
| 91 | struct mmiotrace_rw { |
Ingo Molnar | b814d41 | 2009-02-20 22:32:10 +0100 | [diff] [blame] | 92 | resource_size_t phys; /* PCI address of register */ |
| 93 | unsigned long value; |
| 94 | unsigned long pc; /* optional program counter */ |
| 95 | int map_id; |
| 96 | unsigned char opcode; /* one of MMIO_{READ,WRITE,UNKNOWN_OP} */ |
| 97 | unsigned char width; /* size of register access in bytes */ |
Pekka Paalanen | bd8ac68 | 2008-05-12 21:20:57 +0200 | [diff] [blame] | 98 | }; |
| 99 | |
| 100 | struct mmiotrace_map { |
Ingo Molnar | b814d41 | 2009-02-20 22:32:10 +0100 | [diff] [blame] | 101 | resource_size_t phys; /* base address in PCI space */ |
| 102 | unsigned long virt; /* base virtual address */ |
| 103 | unsigned long len; /* mapping size */ |
| 104 | int map_id; |
| 105 | unsigned char opcode; /* MMIO_PROBE or MMIO_UNPROBE */ |
Pekka Paalanen | bd8ac68 | 2008-05-12 21:20:57 +0200 | [diff] [blame] | 106 | }; |
| 107 | |
Pekka Paalanen | f984b51 | 2008-05-12 21:20:57 +0200 | [diff] [blame] | 108 | /* in kernel/trace/trace_mmiotrace.c */ |
Pekka Paalanen | f984b51 | 2008-05-12 21:20:57 +0200 | [diff] [blame] | 109 | extern void enable_mmiotrace(void); |
| 110 | extern void disable_mmiotrace(void); |
Pekka Paalanen | bd8ac68 | 2008-05-12 21:20:57 +0200 | [diff] [blame] | 111 | extern void mmio_trace_rw(struct mmiotrace_rw *rw); |
| 112 | extern void mmio_trace_mapping(struct mmiotrace_map *map); |
Pekka Paalanen | 9e57fb3 | 2008-09-16 22:00:34 +0300 | [diff] [blame] | 113 | extern int mmio_trace_printk(const char *fmt, va_list args); |
Pekka Paalanen | f984b51 | 2008-05-12 21:20:57 +0200 | [diff] [blame] | 114 | |
Ingo Molnar | b814d41 | 2009-02-20 22:32:10 +0100 | [diff] [blame] | 115 | #endif /* _LINUX_MMIOTRACE_H */ |