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