coresight-etm.h 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * Copyright (c) 2014-2015, The Linux Foundation. All rights reserved.
  4. */
  5. #ifndef _CORESIGHT_CORESIGHT_ETM_H
  6. #define _CORESIGHT_CORESIGHT_ETM_H
  7. #include <asm/local.h>
  8. #include <linux/spinlock.h>
  9. #include "coresight-priv.h"
  10. /*
  11. * Device registers:
  12. * 0x000 - 0x2FC: Trace registers
  13. * 0x300 - 0x314: Management registers
  14. * 0x318 - 0xEFC: Trace registers
  15. *
  16. * Coresight registers
  17. * 0xF00 - 0xF9C: Management registers
  18. * 0xFA0 - 0xFA4: Management registers in PFTv1.0
  19. * Trace registers in PFTv1.1
  20. * 0xFA8 - 0xFFC: Management registers
  21. */
  22. /* Trace registers (0x000-0x2FC) */
  23. #define ETMCR 0x000
  24. #define ETMCCR 0x004
  25. #define ETMTRIGGER 0x008
  26. #define ETMSR 0x010
  27. #define ETMSCR 0x014
  28. #define ETMTSSCR 0x018
  29. #define ETMTECR2 0x01c
  30. #define ETMTEEVR 0x020
  31. #define ETMTECR1 0x024
  32. #define ETMFFLR 0x02c
  33. #define ETMACVRn(n) (0x040 + (n * 4))
  34. #define ETMACTRn(n) (0x080 + (n * 4))
  35. #define ETMCNTRLDVRn(n) (0x140 + (n * 4))
  36. #define ETMCNTENRn(n) (0x150 + (n * 4))
  37. #define ETMCNTRLDEVRn(n) (0x160 + (n * 4))
  38. #define ETMCNTVRn(n) (0x170 + (n * 4))
  39. #define ETMSQ12EVR 0x180
  40. #define ETMSQ21EVR 0x184
  41. #define ETMSQ23EVR 0x188
  42. #define ETMSQ31EVR 0x18c
  43. #define ETMSQ32EVR 0x190
  44. #define ETMSQ13EVR 0x194
  45. #define ETMSQR 0x19c
  46. #define ETMEXTOUTEVRn(n) (0x1a0 + (n * 4))
  47. #define ETMCIDCVRn(n) (0x1b0 + (n * 4))
  48. #define ETMCIDCMR 0x1bc
  49. #define ETMIMPSPEC0 0x1c0
  50. #define ETMIMPSPEC1 0x1c4
  51. #define ETMIMPSPEC2 0x1c8
  52. #define ETMIMPSPEC3 0x1cc
  53. #define ETMIMPSPEC4 0x1d0
  54. #define ETMIMPSPEC5 0x1d4
  55. #define ETMIMPSPEC6 0x1d8
  56. #define ETMIMPSPEC7 0x1dc
  57. #define ETMSYNCFR 0x1e0
  58. #define ETMIDR 0x1e4
  59. #define ETMCCER 0x1e8
  60. #define ETMEXTINSELR 0x1ec
  61. #define ETMTESSEICR 0x1f0
  62. #define ETMEIBCR 0x1f4
  63. #define ETMTSEVR 0x1f8
  64. #define ETMAUXCR 0x1fc
  65. #define ETMTRACEIDR 0x200
  66. #define ETMVMIDCVR 0x240
  67. /* Management registers (0x300-0x314) */
  68. #define ETMOSLAR 0x300
  69. #define ETMOSLSR 0x304
  70. #define ETMOSSRR 0x308
  71. #define ETMPDCR 0x310
  72. #define ETMPDSR 0x314
  73. #define ETM_MAX_ADDR_CMP 16
  74. #define ETM_MAX_CNTR 4
  75. #define ETM_MAX_CTXID_CMP 3
  76. /* Register definition */
  77. /* ETMCR - 0x00 */
  78. #define ETMCR_PWD_DWN BIT(0)
  79. #define ETMCR_STALL_MODE BIT(7)
  80. #define ETMCR_BRANCH_BROADCAST BIT(8)
  81. #define ETMCR_ETM_PRG BIT(10)
  82. #define ETMCR_ETM_EN BIT(11)
  83. #define ETMCR_CYC_ACC BIT(12)
  84. #define ETMCR_CTXID_SIZE (BIT(14)|BIT(15))
  85. #define ETMCR_TIMESTAMP_EN BIT(28)
  86. #define ETMCR_RETURN_STACK BIT(29)
  87. /* ETMCCR - 0x04 */
  88. #define ETMCCR_FIFOFULL BIT(23)
  89. /* ETMPDCR - 0x310 */
  90. #define ETMPDCR_PWD_UP BIT(3)
  91. /* ETMTECR1 - 0x024 */
  92. #define ETMTECR1_ADDR_COMP_1 BIT(0)
  93. #define ETMTECR1_INC_EXC BIT(24)
  94. #define ETMTECR1_START_STOP BIT(25)
  95. /* ETMCCER - 0x1E8 */
  96. #define ETMCCER_TIMESTAMP BIT(22)
  97. #define ETMCCER_RETSTACK BIT(23)
  98. #define ETM_MODE_EXCLUDE BIT(0)
  99. #define ETM_MODE_CYCACC BIT(1)
  100. #define ETM_MODE_STALL BIT(2)
  101. #define ETM_MODE_TIMESTAMP BIT(3)
  102. #define ETM_MODE_CTXID BIT(4)
  103. #define ETM_MODE_BBROAD BIT(5)
  104. #define ETM_MODE_RET_STACK BIT(6)
  105. #define ETM_MODE_ALL (ETM_MODE_EXCLUDE | ETM_MODE_CYCACC | \
  106. ETM_MODE_STALL | ETM_MODE_TIMESTAMP | \
  107. ETM_MODE_BBROAD | ETM_MODE_RET_STACK | \
  108. ETM_MODE_CTXID | ETM_MODE_EXCL_KERN | \
  109. ETM_MODE_EXCL_USER)
  110. #define ETM_SQR_MASK 0x3
  111. #define ETM_TRACEID_MASK 0x3f
  112. #define ETM_EVENT_MASK 0x1ffff
  113. #define ETM_SYNC_MASK 0xfff
  114. #define ETM_ALL_MASK 0xffffffff
  115. #define ETMSR_PROG_BIT 1
  116. #define ETM_SEQ_STATE_MAX_VAL (0x2)
  117. #define PORT_SIZE_MASK (GENMASK(21, 21) | GENMASK(6, 4))
  118. #define ETM_HARD_WIRE_RES_A /* Hard wired, always true */ \
  119. ((0x0f << 0) | \
  120. /* Resource index A */ \
  121. (0x06 << 4))
  122. #define ETM_ADD_COMP_0 /* Single addr comparator 1 */ \
  123. ((0x00 << 7) | \
  124. /* Resource index B */ \
  125. (0x00 << 11))
  126. #define ETM_EVENT_NOT_A BIT(14) /* NOT(A) */
  127. #define ETM_DEFAULT_EVENT_VAL (ETM_HARD_WIRE_RES_A | \
  128. ETM_ADD_COMP_0 | \
  129. ETM_EVENT_NOT_A)
  130. /**
  131. * struct etm_config - configuration information related to an ETM
  132. * @mode: controls various modes supported by this ETM/PTM.
  133. * @ctrl: used in conjunction with @mode.
  134. * @trigger_event: setting for register ETMTRIGGER.
  135. * @startstop_ctrl: setting for register ETMTSSCR.
  136. * @enable_event: setting for register ETMTEEVR.
  137. * @enable_ctrl1: setting for register ETMTECR1.
  138. * @enable_ctrl2: setting for register ETMTECR2.
  139. * @fifofull_level: setting for register ETMFFLR.
  140. * @addr_idx: index for the address comparator selection.
  141. * @addr_val: value for address comparator register.
  142. * @addr_acctype: access type for address comparator register.
  143. * @addr_type: current status of the comparator register.
  144. * @cntr_idx: index for the counter register selection.
  145. * @cntr_rld_val: reload value of a counter register.
  146. * @cntr_event: control for counter enable register.
  147. * @cntr_rld_event: value for counter reload event register.
  148. * @cntr_val: counter value register.
  149. * @seq_12_event: event causing the transition from 1 to 2.
  150. * @seq_21_event: event causing the transition from 2 to 1.
  151. * @seq_23_event: event causing the transition from 2 to 3.
  152. * @seq_31_event: event causing the transition from 3 to 1.
  153. * @seq_32_event: event causing the transition from 3 to 2.
  154. * @seq_13_event: event causing the transition from 1 to 3.
  155. * @seq_curr_state: current value of the sequencer register.
  156. * @ctxid_idx: index for the context ID registers.
  157. * @ctxid_pid: value for the context ID to trigger on.
  158. * @ctxid_mask: mask applicable to all the context IDs.
  159. * @sync_freq: Synchronisation frequency.
  160. * @timestamp_event: Defines an event that requests the insertion
  161. * of a timestamp into the trace stream.
  162. */
  163. struct etm_config {
  164. u32 mode;
  165. u32 ctrl;
  166. u32 trigger_event;
  167. u32 startstop_ctrl;
  168. u32 enable_event;
  169. u32 enable_ctrl1;
  170. u32 enable_ctrl2;
  171. u32 fifofull_level;
  172. u8 addr_idx;
  173. u32 addr_val[ETM_MAX_ADDR_CMP];
  174. u32 addr_acctype[ETM_MAX_ADDR_CMP];
  175. u32 addr_type[ETM_MAX_ADDR_CMP];
  176. u8 cntr_idx;
  177. u32 cntr_rld_val[ETM_MAX_CNTR];
  178. u32 cntr_event[ETM_MAX_CNTR];
  179. u32 cntr_rld_event[ETM_MAX_CNTR];
  180. u32 cntr_val[ETM_MAX_CNTR];
  181. u32 seq_12_event;
  182. u32 seq_21_event;
  183. u32 seq_23_event;
  184. u32 seq_31_event;
  185. u32 seq_32_event;
  186. u32 seq_13_event;
  187. u32 seq_curr_state;
  188. u8 ctxid_idx;
  189. u32 ctxid_pid[ETM_MAX_CTXID_CMP];
  190. u32 ctxid_mask;
  191. u32 sync_freq;
  192. u32 timestamp_event;
  193. };
  194. /**
  195. * struct etm_drvdata - specifics associated to an ETM component
  196. * @base: memory mapped base address for this component.
  197. * @dev: the device entity associated to this component.
  198. * @atclk: optional clock for the core parts of the ETM.
  199. * @csdev: component vitals needed by the framework.
  200. * @spinlock: only one at a time pls.
  201. * @cpu: the cpu this component is affined to.
  202. * @port_size: port size as reported by ETMCR bit 4-6 and 21.
  203. * @arch: ETM/PTM version number.
  204. * @use_cpu14: true if management registers need to be accessed via CP14.
  205. * @mode: this tracer's mode, i.e sysFS, Perf or disabled.
  206. * @sticky_enable: true if ETM base configuration has been done.
  207. * @boot_enable:true if we should start tracing at boot time.
  208. * @os_unlock: true if access to management registers is allowed.
  209. * @nr_addr_cmp:Number of pairs of address comparators as found in ETMCCR.
  210. * @nr_cntr: Number of counters as found in ETMCCR bit 13-15.
  211. * @nr_ext_inp: Number of external input as found in ETMCCR bit 17-19.
  212. * @nr_ext_out: Number of external output as found in ETMCCR bit 20-22.
  213. * @nr_ctxid_cmp: Number of contextID comparators as found in ETMCCR bit 24-25.
  214. * @etmccr: value of register ETMCCR.
  215. * @etmccer: value of register ETMCCER.
  216. * @traceid: value of the current ID for this component.
  217. * @config: structure holding configuration parameters.
  218. */
  219. struct etm_drvdata {
  220. void __iomem *base;
  221. struct device *dev;
  222. struct clk *atclk;
  223. struct coresight_device *csdev;
  224. spinlock_t spinlock;
  225. int cpu;
  226. int port_size;
  227. u8 arch;
  228. bool use_cp14;
  229. local_t mode;
  230. bool sticky_enable;
  231. bool boot_enable;
  232. bool os_unlock;
  233. u8 nr_addr_cmp;
  234. u8 nr_cntr;
  235. u8 nr_ext_inp;
  236. u8 nr_ext_out;
  237. u8 nr_ctxid_cmp;
  238. u32 etmccr;
  239. u32 etmccer;
  240. u32 traceid;
  241. struct etm_config config;
  242. };
  243. static inline void etm_writel(struct etm_drvdata *drvdata,
  244. u32 val, u32 off)
  245. {
  246. if (drvdata->use_cp14) {
  247. if (etm_writel_cp14(off, val)) {
  248. dev_err(drvdata->dev,
  249. "invalid CP14 access to ETM reg: %#x", off);
  250. }
  251. } else {
  252. writel_relaxed(val, drvdata->base + off);
  253. }
  254. }
  255. static inline unsigned int etm_readl(struct etm_drvdata *drvdata, u32 off)
  256. {
  257. u32 val;
  258. if (drvdata->use_cp14) {
  259. if (etm_readl_cp14(off, &val)) {
  260. dev_err(drvdata->dev,
  261. "invalid CP14 access to ETM reg: %#x", off);
  262. }
  263. } else {
  264. val = readl_relaxed(drvdata->base + off);
  265. }
  266. return val;
  267. }
  268. extern const struct attribute_group *coresight_etm_groups[];
  269. int etm_get_trace_id(struct etm_drvdata *drvdata);
  270. void etm_set_default(struct etm_config *config);
  271. void etm_config_trace_mode(struct etm_config *config);
  272. struct etm_config *get_etm_config(struct etm_drvdata *drvdata);
  273. #endif