x86: mmiotrace full patch, preview 1
[safe/jmp/linux-2.6] / include / linux / mmiotrace.h
1 #ifndef MMIOTRACE_H
2 #define MMIOTRACE_H
3
4 #include <asm/types.h>
5
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 {
19         struct list_head list;
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 */
24 };
25
26 /* kmmio is active by some kmmio_probes? */
27 static inline int is_kmmio_active(void)
28 {
29         extern unsigned int kmmio_count;
30         return kmmio_count;
31 }
32
33 extern void reference_kmmio(void);
34 extern void unreference_kmmio(void);
35 extern int register_kmmio_probe(struct kmmio_probe *p);
36 extern void unregister_kmmio_probe(struct kmmio_probe *p);
37
38 /* Called from page fault handler. */
39 extern int kmmio_handler(struct pt_regs *regs, unsigned long addr);
40
41 #endif /* __KERNEL__ */
42
43
44 /*
45  * If you change anything here, you must bump MMIO_VERSION.
46  * This is the relay data format for user space.
47  */
48 #define MMIO_VERSION 0x04
49
50 /* mm_io_header.type */
51 #define MMIO_OPCODE_MASK 0xff
52 #define MMIO_OPCODE_SHIFT 0
53 #define MMIO_WIDTH_MASK 0xff00
54 #define MMIO_WIDTH_SHIFT 8
55 #define MMIO_MAGIC (0x6f000000 | (MMIO_VERSION<<16))
56 #define MMIO_MAGIC_MASK 0xffff0000
57
58 enum mm_io_opcode {          /* payload type: */
59         MMIO_READ = 0x1,     /* struct mm_io_rw */
60         MMIO_WRITE = 0x2,    /* struct mm_io_rw */
61         MMIO_PROBE = 0x3,    /* struct mm_io_map */
62         MMIO_UNPROBE = 0x4,  /* struct mm_io_map */
63         MMIO_MARKER = 0x5,   /* raw char data */
64         MMIO_UNKNOWN_OP = 0x6, /* struct mm_io_rw */
65 };
66
67 struct mm_io_header {
68         __u32 type;     /* see MMIO_* macros above */
69         __u32 sec;      /* timestamp */
70         __u32 nsec;
71         __u32 pid;      /* PID of the process, or 0 for kernel core */
72         __u16 data_len; /* length of the following payload */
73 };
74
75 struct mm_io_rw {
76         __u64 address; /* virtual address of register */
77         __u64 value;
78         __u64 pc;      /* optional program counter */
79 };
80
81 struct mm_io_map {
82         __u64 phys;  /* base address in PCI space */
83         __u64 addr;  /* base virtual address */
84         __u64 len;   /* mapping size */
85         __u64 pc;    /* optional program counter */
86 };
87
88
89 /*
90  * These structures are used to allow a single relay_write()
91  * call to write a full packet.
92  */
93
94 struct mm_io_header_rw {
95         struct mm_io_header header;
96         struct mm_io_rw rw;
97 } __attribute__((packed));
98
99 struct mm_io_header_map {
100         struct mm_io_header header;
101         struct mm_io_map map;
102 } __attribute__((packed));
103
104 #endif /* MMIOTRACE_H */