mmiotrace.h 3.3 KB

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