iotrace.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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, (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, (void *)(addr))
  47. #undef readb
  48. #define readb(addr) iotrace_readb((const void *)(uintptr_t)addr)
  49. #undef writeb
  50. #define writeb(val, addr) iotrace_writeb(val, (void *)(uintptr_t)addr)
  51. #endif
  52. /* Tracing functions which mirror their io.h counterparts */
  53. u32 iotrace_readl(const void *ptr);
  54. void iotrace_writel(ulong value, void *ptr);
  55. u16 iotrace_readw(const void *ptr);
  56. void iotrace_writew(ulong value, void *ptr);
  57. u8 iotrace_readb(const void *ptr);
  58. void iotrace_writeb(ulong value, void *ptr);
  59. /**
  60. * iotrace_reset_checksum() - Reset the iotrace checksum
  61. */
  62. void iotrace_reset_checksum(void);
  63. /**
  64. * iotrace_get_checksum() - Get the current checksum value
  65. *
  66. * @return currect checksum value
  67. */
  68. u32 iotrace_get_checksum(void);
  69. /**
  70. * iotrace_set_region() - Set whether iotrace is limited to a specific
  71. * io region.
  72. *
  73. * Defines the address and size of the limited region.
  74. *
  75. * @start: address of the beginning of the region
  76. * @size: size of the region in bytes.
  77. */
  78. void iotrace_set_region(ulong start, ulong size);
  79. /**
  80. * iotrace_reset_region() - Reset the region limit
  81. */
  82. void iotrace_reset_region(void);
  83. /**
  84. * iotrace_get_region() - Get region information
  85. *
  86. * @start: Returns start address of region
  87. * @size: Returns size of region in bytes
  88. */
  89. void iotrace_get_region(ulong *start, ulong *size);
  90. /**
  91. * iotrace_set_enabled() - Set whether iotracing is enabled or not
  92. *
  93. * This controls whether the checksum is updated and a trace record added
  94. * for each I/O access.
  95. *
  96. * @enable: true to enable iotracing, false to disable
  97. */
  98. void iotrace_set_enabled(int enable);
  99. /**
  100. * iotrace_get_enabled() - Get whether iotracing is enabled or not
  101. *
  102. * @return true if enabled, false if disabled
  103. */
  104. int iotrace_get_enabled(void);
  105. /**
  106. * iotrace_set_buffer() - Set position and size of iotrace buffer
  107. *
  108. * Defines where the iotrace buffer goes, and resets the output pointer to
  109. * the start of the buffer.
  110. *
  111. * The buffer can be 0 size in which case the checksum is updated but no
  112. * trace records are writen. If the buffer is exhausted, the offset will
  113. * continue to increase but not new data will be written.
  114. *
  115. * @start: Start address of buffer
  116. * @size: Size of buffer in bytes
  117. */
  118. void iotrace_set_buffer(ulong start, ulong size);
  119. /**
  120. * iotrace_get_buffer() - Get buffer information
  121. *
  122. * @start: Returns start address of buffer
  123. * @size: Returns actual size of buffer in bytes
  124. * @needed_size: Returns needed size of buffer in bytes
  125. * @offset: Returns the byte offset where the next output trace record will
  126. * @count: Returns the number of trace records recorded
  127. * be written (or would be if the buffer was large enough)
  128. */
  129. void iotrace_get_buffer(ulong *start, ulong *size, ulong *needed_size, ulong *offset, ulong *count);
  130. #endif /* __IOTRACE_H */