coresight-etm4x.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394
  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 <linux/spinlock.h>
  15. #include "coresight-priv.h"
  16. /*
  17. * Device registers:
  18. * 0x000 - 0x2FC: Trace registers
  19. * 0x300 - 0x314: Management registers
  20. * 0x318 - 0xEFC: Trace registers
  21. * 0xF00: Management registers
  22. * 0xFA0 - 0xFA4: Trace registers
  23. * 0xFA8 - 0xFFC: Management registers
  24. */
  25. /* Trace registers (0x000-0x2FC) */
  26. /* Main control and configuration registers */
  27. #define TRCPRGCTLR 0x004
  28. #define TRCPROCSELR 0x008
  29. #define TRCSTATR 0x00C
  30. #define TRCCONFIGR 0x010
  31. #define TRCAUXCTLR 0x018
  32. #define TRCEVENTCTL0R 0x020
  33. #define TRCEVENTCTL1R 0x024
  34. #define TRCSTALLCTLR 0x02C
  35. #define TRCTSCTLR 0x030
  36. #define TRCSYNCPR 0x034
  37. #define TRCCCCTLR 0x038
  38. #define TRCBBCTLR 0x03C
  39. #define TRCTRACEIDR 0x040
  40. #define TRCQCTLR 0x044
  41. /* Filtering control registers */
  42. #define TRCVICTLR 0x080
  43. #define TRCVIIECTLR 0x084
  44. #define TRCVISSCTLR 0x088
  45. #define TRCVIPCSSCTLR 0x08C
  46. #define TRCVDCTLR 0x0A0
  47. #define TRCVDSACCTLR 0x0A4
  48. #define TRCVDARCCTLR 0x0A8
  49. /* Derived resources registers */
  50. #define TRCSEQEVRn(n) (0x100 + (n * 4))
  51. #define TRCSEQRSTEVR 0x118
  52. #define TRCSEQSTR 0x11C
  53. #define TRCEXTINSELR 0x120
  54. #define TRCCNTRLDVRn(n) (0x140 + (n * 4))
  55. #define TRCCNTCTLRn(n) (0x150 + (n * 4))
  56. #define TRCCNTVRn(n) (0x160 + (n * 4))
  57. /* ID registers */
  58. #define TRCIDR8 0x180
  59. #define TRCIDR9 0x184
  60. #define TRCIDR10 0x188
  61. #define TRCIDR11 0x18C
  62. #define TRCIDR12 0x190
  63. #define TRCIDR13 0x194
  64. #define TRCIMSPEC0 0x1C0
  65. #define TRCIMSPECn(n) (0x1C0 + (n * 4))
  66. #define TRCIDR0 0x1E0
  67. #define TRCIDR1 0x1E4
  68. #define TRCIDR2 0x1E8
  69. #define TRCIDR3 0x1EC
  70. #define TRCIDR4 0x1F0
  71. #define TRCIDR5 0x1F4
  72. #define TRCIDR6 0x1F8
  73. #define TRCIDR7 0x1FC
  74. /* Resource selection registers */
  75. #define TRCRSCTLRn(n) (0x200 + (n * 4))
  76. /* Single-shot comparator registers */
  77. #define TRCSSCCRn(n) (0x280 + (n * 4))
  78. #define TRCSSCSRn(n) (0x2A0 + (n * 4))
  79. #define TRCSSPCICRn(n) (0x2C0 + (n * 4))
  80. /* Management registers (0x300-0x314) */
  81. #define TRCOSLAR 0x300
  82. #define TRCOSLSR 0x304
  83. #define TRCPDCR 0x310
  84. #define TRCPDSR 0x314
  85. /* Trace registers (0x318-0xEFC) */
  86. /* Comparator registers */
  87. #define TRCACVRn(n) (0x400 + (n * 8))
  88. #define TRCACATRn(n) (0x480 + (n * 8))
  89. #define TRCDVCVRn(n) (0x500 + (n * 16))
  90. #define TRCDVCMRn(n) (0x580 + (n * 16))
  91. #define TRCCIDCVRn(n) (0x600 + (n * 8))
  92. #define TRCVMIDCVRn(n) (0x640 + (n * 8))
  93. #define TRCCIDCCTLR0 0x680
  94. #define TRCCIDCCTLR1 0x684
  95. #define TRCVMIDCCTLR0 0x688
  96. #define TRCVMIDCCTLR1 0x68C
  97. /* Management register (0xF00) */
  98. /* Integration control registers */
  99. #define TRCITCTRL 0xF00
  100. /* Trace registers (0xFA0-0xFA4) */
  101. /* Claim tag registers */
  102. #define TRCCLAIMSET 0xFA0
  103. #define TRCCLAIMCLR 0xFA4
  104. /* Management registers (0xFA8-0xFFC) */
  105. #define TRCDEVAFF0 0xFA8
  106. #define TRCDEVAFF1 0xFAC
  107. #define TRCLAR 0xFB0
  108. #define TRCLSR 0xFB4
  109. #define TRCAUTHSTATUS 0xFB8
  110. #define TRCDEVARCH 0xFBC
  111. #define TRCDEVID 0xFC8
  112. #define TRCDEVTYPE 0xFCC
  113. #define TRCPIDR4 0xFD0
  114. #define TRCPIDR5 0xFD4
  115. #define TRCPIDR6 0xFD8
  116. #define TRCPIDR7 0xFDC
  117. #define TRCPIDR0 0xFE0
  118. #define TRCPIDR1 0xFE4
  119. #define TRCPIDR2 0xFE8
  120. #define TRCPIDR3 0xFEC
  121. #define TRCCIDR0 0xFF0
  122. #define TRCCIDR1 0xFF4
  123. #define TRCCIDR2 0xFF8
  124. #define TRCCIDR3 0xFFC
  125. /* ETMv4 resources */
  126. #define ETM_MAX_NR_PE 8
  127. #define ETMv4_MAX_CNTR 4
  128. #define ETM_MAX_SEQ_STATES 4
  129. #define ETM_MAX_EXT_INP_SEL 4
  130. #define ETM_MAX_EXT_INP 256
  131. #define ETM_MAX_EXT_OUT 4
  132. #define ETM_MAX_SINGLE_ADDR_CMP 16
  133. #define ETM_MAX_ADDR_RANGE_CMP (ETM_MAX_SINGLE_ADDR_CMP / 2)
  134. #define ETM_MAX_DATA_VAL_CMP 8
  135. #define ETMv4_MAX_CTXID_CMP 8
  136. #define ETM_MAX_VMID_CMP 8
  137. #define ETM_MAX_PE_CMP 8
  138. #define ETM_MAX_RES_SEL 16
  139. #define ETM_MAX_SS_CMP 8
  140. #define ETM_ARCH_V4 0x40
  141. #define ETMv4_SYNC_MASK 0x1F
  142. #define ETM_CYC_THRESHOLD_MASK 0xFFF
  143. #define ETMv4_EVENT_MASK 0xFF
  144. #define ETM_CNTR_MAX_VAL 0xFFFF
  145. #define ETM_TRACEID_MASK 0x3f
  146. /* ETMv4 programming modes */
  147. #define ETM_MODE_EXCLUDE BIT(0)
  148. #define ETM_MODE_LOAD BIT(1)
  149. #define ETM_MODE_STORE BIT(2)
  150. #define ETM_MODE_LOAD_STORE BIT(3)
  151. #define ETM_MODE_BB BIT(4)
  152. #define ETMv4_MODE_CYCACC BIT(5)
  153. #define ETMv4_MODE_CTXID BIT(6)
  154. #define ETM_MODE_VMID BIT(7)
  155. #define ETM_MODE_COND(val) BMVAL(val, 8, 10)
  156. #define ETMv4_MODE_TIMESTAMP BIT(11)
  157. #define ETM_MODE_RETURNSTACK BIT(12)
  158. #define ETM_MODE_QELEM(val) BMVAL(val, 13, 14)
  159. #define ETM_MODE_DATA_TRACE_ADDR BIT(15)
  160. #define ETM_MODE_DATA_TRACE_VAL BIT(16)
  161. #define ETM_MODE_ISTALL BIT(17)
  162. #define ETM_MODE_DSTALL BIT(18)
  163. #define ETM_MODE_ATB_TRIGGER BIT(19)
  164. #define ETM_MODE_LPOVERRIDE BIT(20)
  165. #define ETM_MODE_ISTALL_EN BIT(21)
  166. #define ETM_MODE_DSTALL_EN BIT(22)
  167. #define ETM_MODE_INSTPRIO BIT(23)
  168. #define ETM_MODE_NOOVERFLOW BIT(24)
  169. #define ETM_MODE_TRACE_RESET BIT(25)
  170. #define ETM_MODE_TRACE_ERR BIT(26)
  171. #define ETM_MODE_VIEWINST_STARTSTOP BIT(27)
  172. #define ETMv4_MODE_ALL 0xFFFFFFF
  173. #define TRCSTATR_IDLE_BIT 0
  174. /**
  175. * struct etm4_drvdata - specifics associated to an ETM component
  176. * @base: Memory mapped base address for this component.
  177. * @dev: The device entity associated to this component.
  178. * @csdev: Component vitals needed by the framework.
  179. * @spinlock: Only one at a time pls.
  180. * @cpu: The cpu this component is affined to.
  181. * @arch: ETM version number.
  182. * @enable: Is this ETM currently tracing.
  183. * @sticky_enable: true if ETM base configuration has been done.
  184. * @boot_enable:True if we should start tracing at boot time.
  185. * @os_unlock: True if access to management registers is allowed.
  186. * @nr_pe: The number of processing entity available for tracing.
  187. * @nr_pe_cmp: The number of processing entity comparator inputs that are
  188. * available for tracing.
  189. * @nr_addr_cmp:Number of pairs of address comparators available
  190. * as found in ETMIDR4 0-3.
  191. * @nr_cntr: Number of counters as found in ETMIDR5 bit 28-30.
  192. * @nr_ext_inp: Number of external input.
  193. * @numcidc: Number of contextID comparators.
  194. * @numvmidc: Number of VMID comparators.
  195. * @nrseqstate: The number of sequencer states that are implemented.
  196. * @nr_event: Indicates how many events the trace unit support.
  197. * @nr_resource:The number of resource selection pairs available for tracing.
  198. * @nr_ss_cmp: Number of single-shot comparator controls that are available.
  199. * @mode: Controls various modes supported by this ETM.
  200. * @trcid: value of the current ID for this component.
  201. * @trcid_size: Indicates the trace ID width.
  202. * @instrp0: Tracing of load and store instructions
  203. * as P0 elements is supported.
  204. * @trccond: If the trace unit supports conditional
  205. * instruction tracing.
  206. * @retstack: Indicates if the implementation supports a return stack.
  207. * @trc_error: Whether a trace unit can trace a system
  208. * error exception.
  209. * @atbtrig: If the implementation can support ATB triggers
  210. * @lpoverride: If the implementation can support low-power state over.
  211. * @pe_sel: Controls which PE to trace.
  212. * @cfg: Controls the tracing options.
  213. * @eventctrl0: Controls the tracing of arbitrary events.
  214. * @eventctrl1: Controls the behavior of the events that @event_ctrl0 selects.
  215. * @stallctl: If functionality that prevents trace unit buffer overflows
  216. * is available.
  217. * @sysstall: Does the system support stall control of the PE?
  218. * @nooverflow: Indicate if overflow prevention is supported.
  219. * @stall_ctrl: Enables trace unit functionality that prevents trace
  220. * unit buffer overflows.
  221. * @ts_size: Global timestamp size field.
  222. * @ts_ctrl: Controls the insertion of global timestamps in the
  223. * trace streams.
  224. * @syncpr: Indicates if an implementation has a fixed
  225. * synchronization period.
  226. * @syncfreq: Controls how often trace synchronization requests occur.
  227. * @trccci: Indicates if the trace unit supports cycle counting
  228. * for instruction.
  229. * @ccsize: Indicates the size of the cycle counter in bits.
  230. * @ccitmin: minimum value that can be programmed in
  231. * the TRCCCCTLR register.
  232. * @ccctlr: Sets the threshold value for cycle counting.
  233. * @trcbb: Indicates if the trace unit supports branch broadcast tracing.
  234. * @q_support: Q element support characteristics.
  235. * @vinst_ctrl: Controls instruction trace filtering.
  236. * @viiectlr: Set or read, the address range comparators.
  237. * @vissctlr: Set, or read, the single address comparators that control the
  238. * ViewInst start-stop logic.
  239. * @vipcssctlr: Set, or read, which PE comparator inputs can control the
  240. * ViewInst start-stop logic.
  241. * @seq_idx: Sequencor index selector.
  242. * @seq_ctrl: Control for the sequencer state transition control register.
  243. * @seq_rst: Moves the sequencer to state 0 when a programmed event occurs.
  244. * @seq_state: Set, or read the sequencer state.
  245. * @cntr_idx: Counter index seletor.
  246. * @cntrldvr: Sets or returns the reload count value for a counter.
  247. * @cntr_ctrl: Controls the operation of a counter.
  248. * @cntr_val: Sets or returns the value for a counter.
  249. * @res_idx: Resource index selector.
  250. * @res_ctrl: Controls the selection of the resources in the trace unit.
  251. * @ss_ctrl: Controls the corresponding single-shot comparator resource.
  252. * @ss_status: The status of the corresponding single-shot comparator.
  253. * @ss_pe_cmp: Selects the PE comparator inputs for Single-shot control.
  254. * @addr_idx: Address comparator index selector.
  255. * @addr_val: Value for address comparator.
  256. * @addr_acc: Address comparator access type.
  257. * @addr_type: Current status of the comparator register.
  258. * @ctxid_idx: Context ID index selector.
  259. * @ctxid_size: Size of the context ID field to consider.
  260. * @ctxid_pid: Value of the context ID comparator.
  261. * @ctxid_vpid: Virtual PID seen by users if PID namespace is enabled, otherwise
  262. * the same value of ctxid_pid.
  263. * @ctxid_mask0:Context ID comparator mask for comparator 0-3.
  264. * @ctxid_mask1:Context ID comparator mask for comparator 4-7.
  265. * @vmid_idx: VM ID index selector.
  266. * @vmid_size: Size of the VM ID comparator to consider.
  267. * @vmid_val: Value of the VM ID comparator.
  268. * @vmid_mask0: VM ID comparator mask for comparator 0-3.
  269. * @vmid_mask1: VM ID comparator mask for comparator 4-7.
  270. * @s_ex_level: In secure state, indicates whether instruction tracing is
  271. * supported for the corresponding Exception level.
  272. * @ns_ex_level:In non-secure state, indicates whether instruction tracing is
  273. * supported for the corresponding Exception level.
  274. * @ext_inp: External input selection.
  275. */
  276. struct etmv4_drvdata {
  277. void __iomem *base;
  278. struct device *dev;
  279. struct coresight_device *csdev;
  280. spinlock_t spinlock;
  281. int cpu;
  282. u8 arch;
  283. bool enable;
  284. bool sticky_enable;
  285. bool boot_enable;
  286. bool os_unlock;
  287. u8 nr_pe;
  288. u8 nr_pe_cmp;
  289. u8 nr_addr_cmp;
  290. u8 nr_cntr;
  291. u8 nr_ext_inp;
  292. u8 numcidc;
  293. u8 numvmidc;
  294. u8 nrseqstate;
  295. u8 nr_event;
  296. u8 nr_resource;
  297. u8 nr_ss_cmp;
  298. u32 mode;
  299. u8 trcid;
  300. u8 trcid_size;
  301. bool instrp0;
  302. bool trccond;
  303. bool retstack;
  304. bool trc_error;
  305. bool atbtrig;
  306. bool lpoverride;
  307. u32 pe_sel;
  308. u32 cfg;
  309. u32 eventctrl0;
  310. u32 eventctrl1;
  311. bool stallctl;
  312. bool sysstall;
  313. bool nooverflow;
  314. u32 stall_ctrl;
  315. u8 ts_size;
  316. u32 ts_ctrl;
  317. bool syncpr;
  318. u32 syncfreq;
  319. bool trccci;
  320. u8 ccsize;
  321. u8 ccitmin;
  322. u32 ccctlr;
  323. bool trcbb;
  324. u32 bb_ctrl;
  325. bool q_support;
  326. u32 vinst_ctrl;
  327. u32 viiectlr;
  328. u32 vissctlr;
  329. u32 vipcssctlr;
  330. u8 seq_idx;
  331. u32 seq_ctrl[ETM_MAX_SEQ_STATES];
  332. u32 seq_rst;
  333. u32 seq_state;
  334. u8 cntr_idx;
  335. u32 cntrldvr[ETMv4_MAX_CNTR];
  336. u32 cntr_ctrl[ETMv4_MAX_CNTR];
  337. u32 cntr_val[ETMv4_MAX_CNTR];
  338. u8 res_idx;
  339. u32 res_ctrl[ETM_MAX_RES_SEL];
  340. u32 ss_ctrl[ETM_MAX_SS_CMP];
  341. u32 ss_status[ETM_MAX_SS_CMP];
  342. u32 ss_pe_cmp[ETM_MAX_SS_CMP];
  343. u8 addr_idx;
  344. u64 addr_val[ETM_MAX_SINGLE_ADDR_CMP];
  345. u64 addr_acc[ETM_MAX_SINGLE_ADDR_CMP];
  346. u8 addr_type[ETM_MAX_SINGLE_ADDR_CMP];
  347. u8 ctxid_idx;
  348. u8 ctxid_size;
  349. u64 ctxid_pid[ETMv4_MAX_CTXID_CMP];
  350. u64 ctxid_vpid[ETMv4_MAX_CTXID_CMP];
  351. u32 ctxid_mask0;
  352. u32 ctxid_mask1;
  353. u8 vmid_idx;
  354. u8 vmid_size;
  355. u64 vmid_val[ETM_MAX_VMID_CMP];
  356. u32 vmid_mask0;
  357. u32 vmid_mask1;
  358. u8 s_ex_level;
  359. u8 ns_ex_level;
  360. u32 ext_inp;
  361. };
  362. /* Address comparator access types */
  363. enum etm_addr_acctype {
  364. ETM_INSTR_ADDR,
  365. ETM_DATA_LOAD_ADDR,
  366. ETM_DATA_STORE_ADDR,
  367. ETM_DATA_LOAD_STORE_ADDR,
  368. };
  369. /* Address comparator context types */
  370. enum etm_addr_ctxtype {
  371. ETM_CTX_NONE,
  372. ETM_CTX_CTXID,
  373. ETM_CTX_VMID,
  374. ETM_CTX_CTXID_VMID,
  375. };
  376. enum etm_addr_type {
  377. ETM_ADDR_TYPE_NONE,
  378. ETM_ADDR_TYPE_SINGLE,
  379. ETM_ADDR_TYPE_RANGE,
  380. ETM_ADDR_TYPE_START,
  381. ETM_ADDR_TYPE_STOP,
  382. };
  383. #endif