coresight-tmc.h 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312
  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/dma-mapping.h>
  9. #include <linux/miscdevice.h>
  10. #define TMC_RSZ 0x004
  11. #define TMC_STS 0x00c
  12. #define TMC_RRD 0x010
  13. #define TMC_RRP 0x014
  14. #define TMC_RWP 0x018
  15. #define TMC_TRG 0x01c
  16. #define TMC_CTL 0x020
  17. #define TMC_RWD 0x024
  18. #define TMC_MODE 0x028
  19. #define TMC_LBUFLEVEL 0x02c
  20. #define TMC_CBUFLEVEL 0x030
  21. #define TMC_BUFWM 0x034
  22. #define TMC_RRPHI 0x038
  23. #define TMC_RWPHI 0x03c
  24. #define TMC_AXICTL 0x110
  25. #define TMC_DBALO 0x118
  26. #define TMC_DBAHI 0x11c
  27. #define TMC_FFSR 0x300
  28. #define TMC_FFCR 0x304
  29. #define TMC_PSCR 0x308
  30. #define TMC_ITMISCOP0 0xee0
  31. #define TMC_ITTRFLIN 0xee8
  32. #define TMC_ITATBDATA0 0xeec
  33. #define TMC_ITATBCTR2 0xef0
  34. #define TMC_ITATBCTR1 0xef4
  35. #define TMC_ITATBCTR0 0xef8
  36. /* register description */
  37. /* TMC_CTL - 0x020 */
  38. #define TMC_CTL_CAPT_EN BIT(0)
  39. /* TMC_STS - 0x00C */
  40. #define TMC_STS_TMCREADY_BIT 2
  41. #define TMC_STS_FULL BIT(0)
  42. #define TMC_STS_TRIGGERED BIT(1)
  43. /*
  44. * TMC_AXICTL - 0x110
  45. *
  46. * TMC AXICTL format for SoC-400
  47. * Bits [0-1] : ProtCtrlBit0-1
  48. * Bits [2-5] : CacheCtrlBits 0-3 (AXCACHE)
  49. * Bit 6 : Reserved
  50. * Bit 7 : ScatterGatherMode
  51. * Bits [8-11] : WrBurstLen
  52. * Bits [12-31] : Reserved.
  53. * TMC AXICTL format for SoC-600, as above except:
  54. * Bits [2-5] : AXI WCACHE
  55. * Bits [16-19] : AXI RCACHE
  56. * Bits [20-31] : Reserved
  57. */
  58. #define TMC_AXICTL_CLEAR_MASK 0xfbf
  59. #define TMC_AXICTL_ARCACHE_MASK (0xf << 16)
  60. #define TMC_AXICTL_PROT_CTL_B0 BIT(0)
  61. #define TMC_AXICTL_PROT_CTL_B1 BIT(1)
  62. #define TMC_AXICTL_SCT_GAT_MODE BIT(7)
  63. #define TMC_AXICTL_WR_BURST_16 0xF00
  64. /* Write-back Read and Write-allocate */
  65. #define TMC_AXICTL_AXCACHE_OS (0xf << 2)
  66. #define TMC_AXICTL_ARCACHE_OS (0xf << 16)
  67. /* TMC_FFCR - 0x304 */
  68. #define TMC_FFCR_FLUSHMAN_BIT 6
  69. #define TMC_FFCR_EN_FMT BIT(0)
  70. #define TMC_FFCR_EN_TI BIT(1)
  71. #define TMC_FFCR_FON_FLIN BIT(4)
  72. #define TMC_FFCR_FON_TRIG_EVT BIT(5)
  73. #define TMC_FFCR_TRIGON_TRIGIN BIT(8)
  74. #define TMC_FFCR_STOP_ON_FLUSH BIT(12)
  75. #define TMC_DEVID_NOSCAT BIT(24)
  76. #define TMC_DEVID_AXIAW_VALID BIT(16)
  77. #define TMC_DEVID_AXIAW_SHIFT 17
  78. #define TMC_DEVID_AXIAW_MASK 0x7f
  79. enum tmc_config_type {
  80. TMC_CONFIG_TYPE_ETB,
  81. TMC_CONFIG_TYPE_ETR,
  82. TMC_CONFIG_TYPE_ETF,
  83. };
  84. enum tmc_mode {
  85. TMC_MODE_CIRCULAR_BUFFER,
  86. TMC_MODE_SOFTWARE_FIFO,
  87. TMC_MODE_HARDWARE_FIFO,
  88. };
  89. enum tmc_mem_intf_width {
  90. TMC_MEM_INTF_WIDTH_32BITS = 1,
  91. TMC_MEM_INTF_WIDTH_64BITS = 2,
  92. TMC_MEM_INTF_WIDTH_128BITS = 4,
  93. TMC_MEM_INTF_WIDTH_256BITS = 8,
  94. };
  95. /* TMC ETR Capability bit definitions */
  96. #define TMC_ETR_SG (0x1U << 0)
  97. /* ETR has separate read/write cache encodings */
  98. #define TMC_ETR_AXI_ARCACHE (0x1U << 1)
  99. /*
  100. * TMC_ETR_SAVE_RESTORE - Values of RRP/RWP/STS.Full are
  101. * retained when TMC leaves Disabled state, allowing us to continue
  102. * the tracing from a point where we stopped. This also implies that
  103. * the RRP/RWP/STS.Full should always be programmed to the correct
  104. * value. Unfortunately this is not advertised by the hardware,
  105. * so we have to rely on PID of the IP to detect the functionality.
  106. */
  107. #define TMC_ETR_SAVE_RESTORE (0x1U << 2)
  108. /* Coresight SoC-600 TMC-ETR unadvertised capabilities */
  109. #define CORESIGHT_SOC_600_ETR_CAPS \
  110. (TMC_ETR_SAVE_RESTORE | TMC_ETR_AXI_ARCACHE)
  111. enum etr_mode {
  112. ETR_MODE_FLAT, /* Uses contiguous flat buffer */
  113. ETR_MODE_ETR_SG, /* Uses in-built TMC ETR SG mechanism */
  114. ETR_MODE_CATU, /* Use SG mechanism in CATU */
  115. };
  116. struct etr_buf_operations;
  117. /**
  118. * struct etr_buf - Details of the buffer used by ETR
  119. * @mode : Mode of the ETR buffer, contiguous, Scatter Gather etc.
  120. * @full : Trace data overflow
  121. * @size : Size of the buffer.
  122. * @hwaddr : Address to be programmed in the TMC:DBA{LO,HI}
  123. * @offset : Offset of the trace data in the buffer for consumption.
  124. * @len : Available trace data @buf (may round up to the beginning).
  125. * @ops : ETR buffer operations for the mode.
  126. * @private : Backend specific information for the buf
  127. */
  128. struct etr_buf {
  129. enum etr_mode mode;
  130. bool full;
  131. ssize_t size;
  132. dma_addr_t hwaddr;
  133. unsigned long offset;
  134. s64 len;
  135. const struct etr_buf_operations *ops;
  136. void *private;
  137. };
  138. /**
  139. * struct tmc_drvdata - specifics associated to an TMC component
  140. * @base: memory mapped base address for this component.
  141. * @dev: the device entity associated to this component.
  142. * @csdev: component vitals needed by the framework.
  143. * @miscdev: specifics to handle "/dev/xyz.tmc" entry.
  144. * @spinlock: only one at a time pls.
  145. * @buf: Snapshot of the trace data for ETF/ETB.
  146. * @etr_buf: details of buffer used in TMC-ETR
  147. * @len: size of the available trace for ETF/ETB.
  148. * @size: trace buffer size for this TMC (common for all modes).
  149. * @mode: how this TMC is being used.
  150. * @config_type: TMC variant, must be of type @tmc_config_type.
  151. * @memwidth: width of the memory interface databus, in bytes.
  152. * @trigger_cntr: amount of words to store after a trigger.
  153. * @etr_caps: Bitmask of capabilities of the TMC ETR, inferred from the
  154. * device configuration register (DEVID)
  155. * @sysfs_data: SYSFS buffer for ETR.
  156. */
  157. struct tmc_drvdata {
  158. void __iomem *base;
  159. struct device *dev;
  160. struct coresight_device *csdev;
  161. struct miscdevice miscdev;
  162. spinlock_t spinlock;
  163. bool reading;
  164. union {
  165. char *buf; /* TMC ETB */
  166. struct etr_buf *etr_buf; /* TMC ETR */
  167. };
  168. u32 len;
  169. u32 size;
  170. u32 mode;
  171. enum tmc_config_type config_type;
  172. enum tmc_mem_intf_width memwidth;
  173. u32 trigger_cntr;
  174. u32 etr_caps;
  175. struct etr_buf *sysfs_buf;
  176. };
  177. struct etr_buf_operations {
  178. int (*alloc)(struct tmc_drvdata *drvdata, struct etr_buf *etr_buf,
  179. int node, void **pages);
  180. void (*sync)(struct etr_buf *etr_buf, u64 rrp, u64 rwp);
  181. ssize_t (*get_data)(struct etr_buf *etr_buf, u64 offset, size_t len,
  182. char **bufpp);
  183. void (*free)(struct etr_buf *etr_buf);
  184. };
  185. /**
  186. * struct tmc_pages - Collection of pages used for SG.
  187. * @nr_pages: Number of pages in the list.
  188. * @daddrs: Array of DMA'able page address.
  189. * @pages: Array pages for the buffer.
  190. */
  191. struct tmc_pages {
  192. int nr_pages;
  193. dma_addr_t *daddrs;
  194. struct page **pages;
  195. };
  196. /*
  197. * struct tmc_sg_table - Generic SG table for TMC
  198. * @dev: Device for DMA allocations
  199. * @table_vaddr: Contiguous Virtual address for PageTable
  200. * @data_vaddr: Contiguous Virtual address for Data Buffer
  201. * @table_daddr: DMA address of the PageTable base
  202. * @node: Node for Page allocations
  203. * @table_pages: List of pages & dma address for Table
  204. * @data_pages: List of pages & dma address for Data
  205. */
  206. struct tmc_sg_table {
  207. struct device *dev;
  208. void *table_vaddr;
  209. void *data_vaddr;
  210. dma_addr_t table_daddr;
  211. int node;
  212. struct tmc_pages table_pages;
  213. struct tmc_pages data_pages;
  214. };
  215. /* Generic functions */
  216. void tmc_wait_for_tmcready(struct tmc_drvdata *drvdata);
  217. void tmc_flush_and_stop(struct tmc_drvdata *drvdata);
  218. void tmc_enable_hw(struct tmc_drvdata *drvdata);
  219. void tmc_disable_hw(struct tmc_drvdata *drvdata);
  220. /* ETB/ETF functions */
  221. int tmc_read_prepare_etb(struct tmc_drvdata *drvdata);
  222. int tmc_read_unprepare_etb(struct tmc_drvdata *drvdata);
  223. extern const struct coresight_ops tmc_etb_cs_ops;
  224. extern const struct coresight_ops tmc_etf_cs_ops;
  225. ssize_t tmc_etb_get_sysfs_trace(struct tmc_drvdata *drvdata,
  226. loff_t pos, size_t len, char **bufpp);
  227. /* ETR functions */
  228. int tmc_read_prepare_etr(struct tmc_drvdata *drvdata);
  229. int tmc_read_unprepare_etr(struct tmc_drvdata *drvdata);
  230. extern const struct coresight_ops tmc_etr_cs_ops;
  231. ssize_t tmc_etr_get_sysfs_trace(struct tmc_drvdata *drvdata,
  232. loff_t pos, size_t len, char **bufpp);
  233. #define TMC_REG_PAIR(name, lo_off, hi_off) \
  234. static inline u64 \
  235. tmc_read_##name(struct tmc_drvdata *drvdata) \
  236. { \
  237. return coresight_read_reg_pair(drvdata->base, lo_off, hi_off); \
  238. } \
  239. static inline void \
  240. tmc_write_##name(struct tmc_drvdata *drvdata, u64 val) \
  241. { \
  242. coresight_write_reg_pair(drvdata->base, val, lo_off, hi_off); \
  243. }
  244. TMC_REG_PAIR(rrp, TMC_RRP, TMC_RRPHI)
  245. TMC_REG_PAIR(rwp, TMC_RWP, TMC_RWPHI)
  246. TMC_REG_PAIR(dba, TMC_DBALO, TMC_DBAHI)
  247. /* Initialise the caps from unadvertised static capabilities of the device */
  248. static inline void tmc_etr_init_caps(struct tmc_drvdata *drvdata, u32 dev_caps)
  249. {
  250. WARN_ON(drvdata->etr_caps);
  251. drvdata->etr_caps = dev_caps;
  252. }
  253. static inline void tmc_etr_set_cap(struct tmc_drvdata *drvdata, u32 cap)
  254. {
  255. drvdata->etr_caps |= cap;
  256. }
  257. static inline bool tmc_etr_has_cap(struct tmc_drvdata *drvdata, u32 cap)
  258. {
  259. return !!(drvdata->etr_caps & cap);
  260. }
  261. struct tmc_sg_table *tmc_alloc_sg_table(struct device *dev,
  262. int node,
  263. int nr_tpages,
  264. int nr_dpages,
  265. void **pages);
  266. void tmc_free_sg_table(struct tmc_sg_table *sg_table);
  267. void tmc_sg_table_sync_table(struct tmc_sg_table *sg_table);
  268. void tmc_sg_table_sync_data_range(struct tmc_sg_table *table,
  269. u64 offset, u64 size);
  270. ssize_t tmc_sg_table_get_data(struct tmc_sg_table *sg_table,
  271. u64 offset, size_t len, char **bufpp);
  272. static inline unsigned long
  273. tmc_sg_table_buf_size(struct tmc_sg_table *sg_table)
  274. {
  275. return sg_table->data_pages.nr_pages << PAGE_SHIFT;
  276. }
  277. struct coresight_device *tmc_etr_get_catu_device(struct tmc_drvdata *drvdata);
  278. #endif