coresight-etm4x.h 14 KB

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