Pekka Paalanen | 8b7d89d | 2008-05-12 21:20:56 +0200 | [diff] [blame] | 1 | #ifndef MMIOTRACE_H |
| 2 | #define MMIOTRACE_H |
| 3 | |
| 4 | #include <asm/types.h> |
| 5 | |
Pekka Paalanen | 0fd0e3d | 2008-05-12 21:20:57 +0200 | [diff] [blame] | 6 | #ifdef __KERNEL__ |
| 7 | |
| 8 | #include <linux/list.h> |
| 9 | |
| 10 | struct kmmio_probe; |
| 11 | struct pt_regs; |
| 12 | |
| 13 | typedef void (*kmmio_pre_handler_t)(struct kmmio_probe *, |
| 14 | struct pt_regs *, unsigned long addr); |
| 15 | typedef void (*kmmio_post_handler_t)(struct kmmio_probe *, |
| 16 | unsigned long condition, struct pt_regs *); |
| 17 | |
| 18 | struct kmmio_probe { |
Pekka Paalanen | d61fc44 | 2008-05-12 21:20:57 +0200 | [diff] [blame] | 19 | struct list_head list; /* kmmio internal list */ |
Pekka Paalanen | 0fd0e3d | 2008-05-12 21:20:57 +0200 | [diff] [blame] | 20 | unsigned long addr; /* start location of the probe point */ |
| 21 | unsigned long len; /* length of the probe region */ |
| 22 | kmmio_pre_handler_t pre_handler; /* Called before addr is executed. */ |
| 23 | kmmio_post_handler_t post_handler; /* Called after addr is executed */ |
Pekka Paalanen | d61fc44 | 2008-05-12 21:20:57 +0200 | [diff] [blame] | 24 | void *user_data; |
Pekka Paalanen | 0fd0e3d | 2008-05-12 21:20:57 +0200 | [diff] [blame] | 25 | }; |
| 26 | |
| 27 | /* kmmio is active by some kmmio_probes? */ |
| 28 | static inline int is_kmmio_active(void) |
| 29 | { |
| 30 | extern unsigned int kmmio_count; |
| 31 | return kmmio_count; |
| 32 | } |
| 33 | |
| 34 | extern void reference_kmmio(void); |
| 35 | extern void unreference_kmmio(void); |
| 36 | extern int register_kmmio_probe(struct kmmio_probe *p); |
| 37 | extern void unregister_kmmio_probe(struct kmmio_probe *p); |
| 38 | |
| 39 | /* Called from page fault handler. */ |
| 40 | extern int kmmio_handler(struct pt_regs *regs, unsigned long addr); |
| 41 | |
Pekka Paalanen | d61fc44 | 2008-05-12 21:20:57 +0200 | [diff] [blame] | 42 | /* Called from ioremap.c */ |
| 43 | #ifdef CONFIG_MMIOTRACE |
| 44 | extern void |
| 45 | mmiotrace_ioremap(unsigned long offset, unsigned long size, void __iomem *addr); |
| 46 | extern void mmiotrace_iounmap(volatile void __iomem *addr); |
| 47 | #else |
| 48 | static inline void |
| 49 | mmiotrace_ioremap(unsigned long offset, unsigned long size, void __iomem *addr) |
| 50 | { |
| 51 | } |
| 52 | static inline void mmiotrace_iounmap(volatile void __iomem *addr) |
| 53 | { |
| 54 | } |
| 55 | #endif /* CONFIG_MMIOTRACE_HOOKS */ |
| 56 | |
Pekka Paalanen | f984b51 | 2008-05-12 21:20:57 +0200 | [diff] [blame^] | 57 | /* in kernel/trace/trace_mmiotrace.c */ |
| 58 | extern int __init init_mmiotrace(void); |
| 59 | extern void enable_mmiotrace(void); |
| 60 | extern void disable_mmiotrace(void); |
| 61 | extern void mmio_trace_record(u32 type, unsigned long addr, unsigned long arg); |
| 62 | |
Pekka Paalanen | 0fd0e3d | 2008-05-12 21:20:57 +0200 | [diff] [blame] | 63 | #endif /* __KERNEL__ */ |
| 64 | |
| 65 | |
Pekka Paalanen | 63ffa3e | 2008-05-12 21:20:57 +0200 | [diff] [blame] | 66 | /* |
| 67 | * If you change anything here, you must bump MMIO_VERSION. |
| 68 | * This is the relay data format for user space. |
| 69 | */ |
Pekka Paalanen | 8b7d89d | 2008-05-12 21:20:56 +0200 | [diff] [blame] | 70 | #define MMIO_VERSION 0x04 |
| 71 | |
| 72 | /* mm_io_header.type */ |
| 73 | #define MMIO_OPCODE_MASK 0xff |
| 74 | #define MMIO_OPCODE_SHIFT 0 |
| 75 | #define MMIO_WIDTH_MASK 0xff00 |
| 76 | #define MMIO_WIDTH_SHIFT 8 |
| 77 | #define MMIO_MAGIC (0x6f000000 | (MMIO_VERSION<<16)) |
| 78 | #define MMIO_MAGIC_MASK 0xffff0000 |
| 79 | |
| 80 | enum mm_io_opcode { /* payload type: */ |
| 81 | MMIO_READ = 0x1, /* struct mm_io_rw */ |
| 82 | MMIO_WRITE = 0x2, /* struct mm_io_rw */ |
| 83 | MMIO_PROBE = 0x3, /* struct mm_io_map */ |
| 84 | MMIO_UNPROBE = 0x4, /* struct mm_io_map */ |
| 85 | MMIO_MARKER = 0x5, /* raw char data */ |
| 86 | MMIO_UNKNOWN_OP = 0x6, /* struct mm_io_rw */ |
| 87 | }; |
| 88 | |
| 89 | struct mm_io_header { |
Pekka Paalanen | 63ffa3e | 2008-05-12 21:20:57 +0200 | [diff] [blame] | 90 | __u32 type; /* see MMIO_* macros above */ |
Pekka Paalanen | 8b7d89d | 2008-05-12 21:20:56 +0200 | [diff] [blame] | 91 | __u32 sec; /* timestamp */ |
| 92 | __u32 nsec; |
| 93 | __u32 pid; /* PID of the process, or 0 for kernel core */ |
| 94 | __u16 data_len; /* length of the following payload */ |
| 95 | }; |
| 96 | |
| 97 | struct mm_io_rw { |
| 98 | __u64 address; /* virtual address of register */ |
| 99 | __u64 value; |
| 100 | __u64 pc; /* optional program counter */ |
| 101 | }; |
| 102 | |
| 103 | struct mm_io_map { |
| 104 | __u64 phys; /* base address in PCI space */ |
| 105 | __u64 addr; /* base virtual address */ |
| 106 | __u64 len; /* mapping size */ |
| 107 | __u64 pc; /* optional program counter */ |
| 108 | }; |
| 109 | |
| 110 | |
| 111 | /* |
| 112 | * These structures are used to allow a single relay_write() |
| 113 | * call to write a full packet. |
| 114 | */ |
| 115 | |
| 116 | struct mm_io_header_rw { |
| 117 | struct mm_io_header header; |
| 118 | struct mm_io_rw rw; |
| 119 | } __attribute__((packed)); |
| 120 | |
| 121 | struct mm_io_header_map { |
| 122 | struct mm_io_header header; |
| 123 | struct mm_io_map map; |
| 124 | } __attribute__((packed)); |
| 125 | |
| 126 | #endif /* MMIOTRACE_H */ |