mmiotrace.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. #ifndef _LINUX_MMIOTRACE_H
  2. #define _LINUX_MMIOTRACE_H
  3. #include <linux/types.h>
  4. #include <linux/list.h>
  5. struct kmmio_probe;
  6. struct pt_regs;
  7. typedef void (*kmmio_pre_handler_t)(struct kmmio_probe *,
  8. struct pt_regs *, unsigned long addr);
  9. typedef void (*kmmio_post_handler_t)(struct kmmio_probe *,
  10. unsigned long condition, struct pt_regs *);
  11. struct kmmio_probe {
  12. /* kmmio internal list: */
  13. struct list_head list;
  14. /* start location of the probe point: */
  15. unsigned long addr;
  16. /* length of the probe region: */
  17. unsigned long len;
  18. /* Called before addr is executed: */
  19. kmmio_pre_handler_t pre_handler;
  20. /* Called after addr is executed: */
  21. kmmio_post_handler_t post_handler;
  22. void *private;
  23. };
  24. extern unsigned int kmmio_count;
  25. extern int register_kmmio_probe(struct kmmio_probe *p);
  26. extern void unregister_kmmio_probe(struct kmmio_probe *p);
  27. extern int kmmio_init(void);
  28. extern void kmmio_cleanup(void);
  29. #ifdef CONFIG_MMIOTRACE
  30. /* kmmio is active by some kmmio_probes? */
  31. static inline int is_kmmio_active(void)
  32. {
  33. return kmmio_count;
  34. }
  35. /* Called from page fault handler. */
  36. extern int kmmio_handler(struct pt_regs *regs, unsigned long addr);
  37. /* Called from ioremap.c */
  38. extern void mmiotrace_ioremap(resource_size_t offset, unsigned long size,
  39. void __iomem *addr);
  40. extern void mmiotrace_iounmap(volatile void __iomem *addr);
  41. /* For anyone to insert markers. Remember trailing newline. */
  42. extern __printf(1, 2) int mmiotrace_printk(const char *fmt, ...);
  43. #else /* !CONFIG_MMIOTRACE: */
  44. static inline int is_kmmio_active(void)
  45. {
  46. return 0;
  47. }
  48. static inline int kmmio_handler(struct pt_regs *regs, unsigned long addr)
  49. {
  50. return 0;
  51. }
  52. static inline void mmiotrace_ioremap(resource_size_t offset,
  53. unsigned long size, void __iomem *addr)
  54. {
  55. }
  56. static inline void mmiotrace_iounmap(volatile void __iomem *addr)
  57. {
  58. }
  59. static inline __printf(1, 2) int mmiotrace_printk(const char *fmt, ...)
  60. {
  61. return 0;
  62. }
  63. #endif /* CONFIG_MMIOTRACE */
  64. enum mm_io_opcode {
  65. MMIO_READ = 0x1, /* struct mmiotrace_rw */
  66. MMIO_WRITE = 0x2, /* struct mmiotrace_rw */
  67. MMIO_PROBE = 0x3, /* struct mmiotrace_map */
  68. MMIO_UNPROBE = 0x4, /* struct mmiotrace_map */
  69. MMIO_UNKNOWN_OP = 0x5, /* struct mmiotrace_rw */
  70. };
  71. struct mmiotrace_rw {
  72. resource_size_t phys; /* PCI address of register */
  73. unsigned long value;
  74. unsigned long pc; /* optional program counter */
  75. int map_id;
  76. unsigned char opcode; /* one of MMIO_{READ,WRITE,UNKNOWN_OP} */
  77. unsigned char width; /* size of register access in bytes */
  78. };
  79. struct mmiotrace_map {
  80. resource_size_t phys; /* base address in PCI space */
  81. unsigned long virt; /* base virtual address */
  82. unsigned long len; /* mapping size */
  83. int map_id;
  84. unsigned char opcode; /* MMIO_PROBE or MMIO_UNPROBE */
  85. };
  86. /* in kernel/trace/trace_mmiotrace.c */
  87. extern void enable_mmiotrace(void);
  88. extern void disable_mmiotrace(void);
  89. extern void mmio_trace_rw(struct mmiotrace_rw *rw);
  90. extern void mmio_trace_mapping(struct mmiotrace_map *map);
  91. extern __printf(1, 0) int mmio_trace_printk(const char *fmt, va_list args);
  92. #endif /* _LINUX_MMIOTRACE_H */