coresight-etm.h 9.3 KB

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