coresight-tmc.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * Copyright(C) 2015 Linaro Limited. All rights reserved.
  4. * Author: Mathieu Poirier <mathieu.poirier@linaro.org>
  5. */
  6. #ifndef _CORESIGHT_TMC_H
  7. #define _CORESIGHT_TMC_H
  8. #include <linux/miscdevice.h>
  9. #define TMC_RSZ 0x004
  10. #define TMC_STS 0x00c
  11. #define TMC_RRD 0x010
  12. #define TMC_RRP 0x014
  13. #define TMC_RWP 0x018
  14. #define TMC_TRG 0x01c
  15. #define TMC_CTL 0x020
  16. #define TMC_RWD 0x024
  17. #define TMC_MODE 0x028
  18. #define TMC_LBUFLEVEL 0x02c
  19. #define TMC_CBUFLEVEL 0x030
  20. #define TMC_BUFWM 0x034
  21. #define TMC_RRPHI 0x038
  22. #define TMC_RWPHI 0x03c
  23. #define TMC_AXICTL 0x110
  24. #define TMC_DBALO 0x118
  25. #define TMC_DBAHI 0x11c
  26. #define TMC_FFSR 0x300
  27. #define TMC_FFCR 0x304
  28. #define TMC_PSCR 0x308
  29. #define TMC_ITMISCOP0 0xee0
  30. #define TMC_ITTRFLIN 0xee8
  31. #define TMC_ITATBDATA0 0xeec
  32. #define TMC_ITATBCTR2 0xef0
  33. #define TMC_ITATBCTR1 0xef4
  34. #define TMC_ITATBCTR0 0xef8
  35. /* register description */
  36. /* TMC_CTL - 0x020 */
  37. #define TMC_CTL_CAPT_EN BIT(0)
  38. /* TMC_STS - 0x00C */
  39. #define TMC_STS_TMCREADY_BIT 2
  40. #define TMC_STS_FULL BIT(0)
  41. #define TMC_STS_TRIGGERED BIT(1)
  42. /*
  43. * TMC_AXICTL - 0x110
  44. *
  45. * TMC AXICTL format for SoC-400
  46. * Bits [0-1] : ProtCtrlBit0-1
  47. * Bits [2-5] : CacheCtrlBits 0-3 (AXCACHE)
  48. * Bit 6 : Reserved
  49. * Bit 7 : ScatterGatherMode
  50. * Bits [8-11] : WrBurstLen
  51. * Bits [12-31] : Reserved.
  52. * TMC AXICTL format for SoC-600, as above except:
  53. * Bits [2-5] : AXI WCACHE
  54. * Bits [16-19] : AXI RCACHE
  55. * Bits [20-31] : Reserved
  56. */
  57. #define TMC_AXICTL_CLEAR_MASK 0xfbf
  58. #define TMC_AXICTL_ARCACHE_MASK (0xf << 16)
  59. #define TMC_AXICTL_PROT_CTL_B0 BIT(0)
  60. #define TMC_AXICTL_PROT_CTL_B1 BIT(1)
  61. #define TMC_AXICTL_SCT_GAT_MODE BIT(7)
  62. #define TMC_AXICTL_WR_BURST_16 0xF00
  63. /* Write-back Read and Write-allocate */
  64. #define TMC_AXICTL_AXCACHE_OS (0xf << 2)
  65. #define TMC_AXICTL_ARCACHE_OS (0xf << 16)
  66. /* TMC_FFCR - 0x304 */
  67. #define TMC_FFCR_FLUSHMAN_BIT 6
  68. #define TMC_FFCR_EN_FMT BIT(0)
  69. #define TMC_FFCR_EN_TI BIT(1)
  70. #define TMC_FFCR_FON_FLIN BIT(4)
  71. #define TMC_FFCR_FON_TRIG_EVT BIT(5)
  72. #define TMC_FFCR_TRIGON_TRIGIN BIT(8)
  73. #define TMC_FFCR_STOP_ON_FLUSH BIT(12)
  74. #define TMC_DEVID_NOSCAT BIT(24)
  75. #define TMC_DEVID_AXIAW_VALID BIT(16)
  76. #define TMC_DEVID_AXIAW_SHIFT 17
  77. #define TMC_DEVID_AXIAW_MASK 0x7f
  78. enum tmc_config_type {
  79. TMC_CONFIG_TYPE_ETB,
  80. TMC_CONFIG_TYPE_ETR,
  81. TMC_CONFIG_TYPE_ETF,
  82. };
  83. enum tmc_mode {
  84. TMC_MODE_CIRCULAR_BUFFER,
  85. TMC_MODE_SOFTWARE_FIFO,
  86. TMC_MODE_HARDWARE_FIFO,
  87. };
  88. enum tmc_mem_intf_width {
  89. TMC_MEM_INTF_WIDTH_32BITS = 1,
  90. TMC_MEM_INTF_WIDTH_64BITS = 2,
  91. TMC_MEM_INTF_WIDTH_128BITS = 4,
  92. TMC_MEM_INTF_WIDTH_256BITS = 8,
  93. };
  94. /* TMC ETR Capability bit definitions */
  95. #define TMC_ETR_SG (0x1U << 0)
  96. /* ETR has separate read/write cache encodings */
  97. #define TMC_ETR_AXI_ARCACHE (0x1U << 1)
  98. /*
  99. * TMC_ETR_SAVE_RESTORE - Values of RRP/RWP/STS.Full are
  100. * retained when TMC leaves Disabled state, allowing us to continue
  101. * the tracing from a point where we stopped. This also implies that
  102. * the RRP/RWP/STS.Full should always be programmed to the correct
  103. * value. Unfortunately this is not advertised by the hardware,
  104. * so we have to rely on PID of the IP to detect the functionality.
  105. */
  106. #define TMC_ETR_SAVE_RESTORE (0x1U << 2)
  107. /* Coresight SoC-600 TMC-ETR unadvertised capabilities */
  108. #define CORESIGHT_SOC_600_ETR_CAPS \
  109. (TMC_ETR_SAVE_RESTORE | TMC_ETR_AXI_ARCACHE)
  110. /**
  111. * struct tmc_drvdata - specifics associated to an TMC component
  112. * @base: memory mapped base address for this component.
  113. * @dev: the device entity associated to this component.
  114. * @csdev: component vitals needed by the framework.
  115. * @miscdev: specifics to handle "/dev/xyz.tmc" entry.
  116. * @spinlock: only one at a time pls.
  117. * @buf: area of memory where trace data get sent.
  118. * @paddr: DMA start location in RAM.
  119. * @vaddr: virtual representation of @paddr.
  120. * @size: trace buffer size.
  121. * @len: size of the available trace.
  122. * @mode: how this TMC is being used.
  123. * @config_type: TMC variant, must be of type @tmc_config_type.
  124. * @memwidth: width of the memory interface databus, in bytes.
  125. * @trigger_cntr: amount of words to store after a trigger.
  126. * @etr_caps: Bitmask of capabilities of the TMC ETR, inferred from the
  127. * device configuration register (DEVID)
  128. */
  129. struct tmc_drvdata {
  130. void __iomem *base;
  131. struct device *dev;
  132. struct coresight_device *csdev;
  133. struct miscdevice miscdev;
  134. spinlock_t spinlock;
  135. bool reading;
  136. char *buf;
  137. dma_addr_t paddr;
  138. void __iomem *vaddr;
  139. u32 size;
  140. u32 len;
  141. u32 mode;
  142. enum tmc_config_type config_type;
  143. enum tmc_mem_intf_width memwidth;
  144. u32 trigger_cntr;
  145. u32 etr_caps;
  146. };
  147. /* Generic functions */
  148. void tmc_wait_for_tmcready(struct tmc_drvdata *drvdata);
  149. void tmc_flush_and_stop(struct tmc_drvdata *drvdata);
  150. void tmc_enable_hw(struct tmc_drvdata *drvdata);
  151. void tmc_disable_hw(struct tmc_drvdata *drvdata);
  152. /* ETB/ETF functions */
  153. int tmc_read_prepare_etb(struct tmc_drvdata *drvdata);
  154. int tmc_read_unprepare_etb(struct tmc_drvdata *drvdata);
  155. extern const struct coresight_ops tmc_etb_cs_ops;
  156. extern const struct coresight_ops tmc_etf_cs_ops;
  157. /* ETR functions */
  158. int tmc_read_prepare_etr(struct tmc_drvdata *drvdata);
  159. int tmc_read_unprepare_etr(struct tmc_drvdata *drvdata);
  160. extern const struct coresight_ops tmc_etr_cs_ops;
  161. #define TMC_REG_PAIR(name, lo_off, hi_off) \
  162. static inline u64 \
  163. tmc_read_##name(struct tmc_drvdata *drvdata) \
  164. { \
  165. return coresight_read_reg_pair(drvdata->base, lo_off, hi_off); \
  166. } \
  167. static inline void \
  168. tmc_write_##name(struct tmc_drvdata *drvdata, u64 val) \
  169. { \
  170. coresight_write_reg_pair(drvdata->base, val, lo_off, hi_off); \
  171. }
  172. TMC_REG_PAIR(rrp, TMC_RRP, TMC_RRPHI)
  173. TMC_REG_PAIR(rwp, TMC_RWP, TMC_RWPHI)
  174. TMC_REG_PAIR(dba, TMC_DBALO, TMC_DBAHI)
  175. /* Initialise the caps from unadvertised static capabilities of the device */
  176. static inline void tmc_etr_init_caps(struct tmc_drvdata *drvdata, u32 dev_caps)
  177. {
  178. WARN_ON(drvdata->etr_caps);
  179. drvdata->etr_caps = dev_caps;
  180. }
  181. static inline void tmc_etr_set_cap(struct tmc_drvdata *drvdata, u32 cap)
  182. {
  183. drvdata->etr_caps |= cap;
  184. }
  185. static inline bool tmc_etr_has_cap(struct tmc_drvdata *drvdata, u32 cap)
  186. {
  187. return !!(drvdata->etr_caps & cap);
  188. }
  189. #endif