iotrace.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. /* SPDX-License-Identifier: GPL-2.0+ */
  2. /*
  3. * Copyright (c) 2014 Google, Inc.
  4. */
  5. #ifndef __IOTRACE_H
  6. #define __IOTRACE_H
  7. //#include <common.h>
  8. #include <linux/types.h>
  9. /* Support up to the machine word length for now */
  10. typedef ulong iovalue_t;
  11. enum iotrace_flags {
  12. IOT_8 = 0,
  13. IOT_16,
  14. IOT_32,
  15. IOT_READ = 0 << 3,
  16. IOT_WRITE = 1 << 3,
  17. };
  18. /**
  19. * struct iotrace_record - Holds a single I/O trace record
  20. *
  21. * @flags: I/O access type
  22. * @timestamp: Timestamp of access
  23. * @addr: Address of access
  24. * @value: Value written or read
  25. */
  26. struct iotrace_record {
  27. enum iotrace_flags flags;
  28. u64 timestamp;
  29. phys_addr_t addr;
  30. iovalue_t value;
  31. };
  32. /*
  33. * This file is designed to be included in arch/<arch>/include/asm/io.h.
  34. * It redirects all IO access through a tracing/checksumming feature for
  35. * testing purposes.
  36. */
  37. #if defined(CONFIG_IO_TRACE) && !defined(IOTRACE_IMPL) && \
  38. !defined(CONFIG_SPL_BUILD)
  39. #undef readl
  40. #define readl(addr) iotrace_readl((const void *)(addr))
  41. #undef writel
  42. #define writel(val, addr) iotrace_writel(val, (const void *)(addr))
  43. #undef readw
  44. #define readw(addr) iotrace_readw((const void *)(addr))
  45. #undef writew
  46. #define writew(val, addr) iotrace_writew(val, (const void *)(addr))
  47. #undef readb
  48. #define readb(addr) iotrace_readb((const void *)(uintptr_t)addr)
  49. #undef writeb
  50. #define writeb(val, addr) \
  51. iotrace_writeb(val, (const void *)(uintptr_t)addr)
  52. #endif
  53. /* Tracing functions which mirror their io.h counterparts */
  54. u32 iotrace_readl(const void *ptr);
  55. void iotrace_writel(ulong value, const void *ptr);
  56. u16 iotrace_readw(const void *ptr);
  57. void iotrace_writew(ulong value, const void *ptr);
  58. u8 iotrace_readb(const void *ptr);
  59. void iotrace_writeb(ulong value, const void *ptr);
  60. /**
  61. * iotrace_reset_checksum() - Reset the iotrace checksum
  62. */
  63. void iotrace_reset_checksum(void);
  64. /**
  65. * iotrace_get_checksum() - Get the current checksum value
  66. *
  67. * @return currect checksum value
  68. */
  69. u32 iotrace_get_checksum(void);
  70. /**
  71. * iotrace_set_region() - Set whether iotrace is limited to a specific
  72. * io region.
  73. *
  74. * Defines the address and size of the limited region.
  75. *
  76. * @start: address of the beginning of the region
  77. * @size: size of the region in bytes.
  78. */
  79. void iotrace_set_region(ulong start, ulong size);
  80. /**
  81. * iotrace_reset_region() - Reset the region limit
  82. */
  83. void iotrace_reset_region(void);
  84. /**
  85. * iotrace_get_region() - Get region information
  86. *
  87. * @start: Returns start address of region
  88. * @size: Returns size of region in bytes
  89. */
  90. void iotrace_get_region(ulong *start, ulong *size);
  91. /**
  92. * iotrace_set_enabled() - Set whether iotracing is enabled or not
  93. *
  94. * This controls whether the checksum is updated and a trace record added
  95. * for each I/O access.
  96. *
  97. * @enable: true to enable iotracing, false to disable
  98. */
  99. void iotrace_set_enabled(int enable);
  100. /**
  101. * iotrace_get_enabled() - Get whether iotracing is enabled or not
  102. *
  103. * @return true if enabled, false if disabled
  104. */
  105. int iotrace_get_enabled(void);
  106. /**
  107. * iotrace_set_buffer() - Set position and size of iotrace buffer
  108. *
  109. * Defines where the iotrace buffer goes, and resets the output pointer to
  110. * the start of the buffer.
  111. *
  112. * The buffer can be 0 size in which case the checksum is updated but no
  113. * trace records are writen. If the buffer is exhausted, the offset will
  114. * continue to increase but not new data will be written.
  115. *
  116. * @start: Start address of buffer
  117. * @size: Size of buffer in bytes
  118. */
  119. void iotrace_set_buffer(ulong start, ulong size);
  120. /**
  121. * iotrace_get_buffer() - Get buffer information
  122. *
  123. * @start: Returns start address of buffer
  124. * @size: Returns actual size of buffer in bytes
  125. * @needed_size: Returns needed size of buffer in bytes
  126. * @offset: Returns the byte offset where the next output trace record will
  127. * @count: Returns the number of trace records recorded
  128. * be written (or would be if the buffer was large enough)
  129. */
  130. void iotrace_get_buffer(ulong *start, ulong *size, ulong *needed_size, ulong *offset, ulong *count);
  131. #endif /* __IOTRACE_H */