Pekka Paalanen | 8b7d89d | 2008-05-12 21:20:56 +0200 | [diff] [blame] | 1 | #ifndef MMIOTRACE_H |
| 2 | #define MMIOTRACE_H |
| 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 { |
Pekka Paalanen | d61fc44 | 2008-05-12 21:20:57 +0200 | [diff] [blame] | 16 | struct list_head list; /* kmmio internal list */ |
Pekka Paalanen | 0fd0e3d | 2008-05-12 21:20:57 +0200 | [diff] [blame] | 17 | unsigned long addr; /* start location of the probe point */ |
| 18 | unsigned long len; /* length of the probe region */ |
| 19 | kmmio_pre_handler_t pre_handler; /* Called before addr is executed. */ |
| 20 | kmmio_post_handler_t post_handler; /* Called after addr is executed */ |
Pekka Paalanen | a50445d | 2008-05-12 21:21:03 +0200 | [diff] [blame] | 21 | void *private; |
Pekka Paalanen | 0fd0e3d | 2008-05-12 21:20:57 +0200 | [diff] [blame] | 22 | }; |
| 23 | |
| 24 | /* kmmio is active by some kmmio_probes? */ |
| 25 | static inline int is_kmmio_active(void) |
| 26 | { |
| 27 | extern unsigned int kmmio_count; |
| 28 | return kmmio_count; |
| 29 | } |
| 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); |
| 33 | |
| 34 | /* Called from page fault handler. */ |
| 35 | extern int kmmio_handler(struct pt_regs *regs, unsigned long addr); |
| 36 | |
Pekka Paalanen | d61fc44 | 2008-05-12 21:20:57 +0200 | [diff] [blame] | 37 | #ifdef CONFIG_MMIOTRACE |
Pekka Paalanen | 9e57fb3 | 2008-09-16 22:00:34 +0300 | [diff] [blame^] | 38 | /* Called from ioremap.c */ |
Pekka Paalanen | dee310d | 2008-05-12 21:21:03 +0200 | [diff] [blame] | 39 | extern void mmiotrace_ioremap(resource_size_t offset, unsigned long size, |
| 40 | void __iomem *addr); |
Pekka Paalanen | d61fc44 | 2008-05-12 21:20:57 +0200 | [diff] [blame] | 41 | extern void mmiotrace_iounmap(volatile void __iomem *addr); |
Pekka Paalanen | 9e57fb3 | 2008-09-16 22:00:34 +0300 | [diff] [blame^] | 42 | |
| 43 | /* For anyone to insert markers. Remember trailing newline. */ |
| 44 | extern int mmiotrace_printk(const char *fmt, ...) |
| 45 | __attribute__ ((format (printf, 1, 2))); |
Pekka Paalanen | d61fc44 | 2008-05-12 21:20:57 +0200 | [diff] [blame] | 46 | #else |
Pekka Paalanen | dee310d | 2008-05-12 21:21:03 +0200 | [diff] [blame] | 47 | static inline void mmiotrace_ioremap(resource_size_t offset, |
| 48 | unsigned long size, void __iomem *addr) |
Pekka Paalanen | d61fc44 | 2008-05-12 21:20:57 +0200 | [diff] [blame] | 49 | { |
| 50 | } |
Pekka Paalanen | dee310d | 2008-05-12 21:21:03 +0200 | [diff] [blame] | 51 | |
Pekka Paalanen | d61fc44 | 2008-05-12 21:20:57 +0200 | [diff] [blame] | 52 | static inline void mmiotrace_iounmap(volatile void __iomem *addr) |
| 53 | { |
| 54 | } |
Pekka Paalanen | 9e57fb3 | 2008-09-16 22:00:34 +0300 | [diff] [blame^] | 55 | |
| 56 | static inline int mmiotrace_printk(const char *fmt, ...) |
| 57 | __attribute__ ((format (printf, 1, 0))); |
| 58 | |
| 59 | static inline int mmiotrace_printk(const char *fmt, ...) |
| 60 | { |
| 61 | return 0; |
| 62 | } |
| 63 | #endif /* CONFIG_MMIOTRACE */ |
Pekka Paalanen | d61fc44 | 2008-05-12 21:20:57 +0200 | [diff] [blame] | 64 | |
Pekka Paalanen | bd8ac68 | 2008-05-12 21:20:57 +0200 | [diff] [blame] | 65 | enum mm_io_opcode { |
| 66 | MMIO_READ = 0x1, /* struct mmiotrace_rw */ |
| 67 | MMIO_WRITE = 0x2, /* struct mmiotrace_rw */ |
| 68 | MMIO_PROBE = 0x3, /* struct mmiotrace_map */ |
| 69 | MMIO_UNPROBE = 0x4, /* struct mmiotrace_map */ |
| 70 | MMIO_MARKER = 0x5, /* raw char data */ |
| 71 | MMIO_UNKNOWN_OP = 0x6, /* struct mmiotrace_rw */ |
| 72 | }; |
| 73 | |
| 74 | struct mmiotrace_rw { |
Pekka Paalanen | dee310d | 2008-05-12 21:21:03 +0200 | [diff] [blame] | 75 | resource_size_t phys; /* PCI address of register */ |
Pekka Paalanen | bd8ac68 | 2008-05-12 21:20:57 +0200 | [diff] [blame] | 76 | unsigned long value; |
| 77 | unsigned long pc; /* optional program counter */ |
| 78 | int map_id; |
| 79 | unsigned char opcode; /* one of MMIO_{READ,WRITE,UNKNOWN_OP} */ |
| 80 | unsigned char width; /* size of register access in bytes */ |
| 81 | }; |
| 82 | |
| 83 | struct mmiotrace_map { |
Pekka Paalanen | dee310d | 2008-05-12 21:21:03 +0200 | [diff] [blame] | 84 | resource_size_t phys; /* base address in PCI space */ |
Pekka Paalanen | bd8ac68 | 2008-05-12 21:20:57 +0200 | [diff] [blame] | 85 | unsigned long virt; /* base virtual address */ |
| 86 | unsigned long len; /* mapping size */ |
| 87 | int map_id; |
| 88 | unsigned char opcode; /* MMIO_PROBE or MMIO_UNPROBE */ |
| 89 | }; |
| 90 | |
Pekka Paalanen | f984b51 | 2008-05-12 21:20:57 +0200 | [diff] [blame] | 91 | /* in kernel/trace/trace_mmiotrace.c */ |
Pekka Paalanen | f984b51 | 2008-05-12 21:20:57 +0200 | [diff] [blame] | 92 | extern void enable_mmiotrace(void); |
| 93 | extern void disable_mmiotrace(void); |
Pekka Paalanen | bd8ac68 | 2008-05-12 21:20:57 +0200 | [diff] [blame] | 94 | extern void mmio_trace_rw(struct mmiotrace_rw *rw); |
| 95 | extern void mmio_trace_mapping(struct mmiotrace_map *map); |
Pekka Paalanen | 9e57fb3 | 2008-09-16 22:00:34 +0300 | [diff] [blame^] | 96 | extern int mmio_trace_printk(const char *fmt, va_list args); |
Pekka Paalanen | f984b51 | 2008-05-12 21:20:57 +0200 | [diff] [blame] | 97 | |
Pekka Paalanen | 8b7d89d | 2008-05-12 21:20:56 +0200 | [diff] [blame] | 98 | #endif /* MMIOTRACE_H */ |