1 ===============================================
2 ETMv4 sysfs linux driver programming reference.
3 ===============================================
5 :Author: Mike Leach <mike.leach@linaro.org>
6 :Date: October 11th, 2019
8 Supplement to existing ETMv4 driver documentation.
10 Sysfs files and directories
11 ---------------------------
13 Root: ``/sys/bus/coresight/devices/etm<N>``
16 The following paragraphs explain the association between sysfs files and the
17 ETMv4 registers that they effect. Note the register names are given without
23 :Trace Registers: {CONFIGR + others}
25 Bit select trace features. See ‘mode’ section below. Bits
26 in this will cause equivalent programming of trace config and
27 other registers to enable the features requested.
30 ``echo bitfield > mode``
32 bitfield up to 32 bits setting trace features.
35 ``$> echo 0x012 > mode``
42 Reset all programming to trace nothing / no logic programmed.
49 :File: ``enable_source`` (wo)
50 :Trace Registers: PRGCTLR, All hardware regs.
52 - > 0 : Programs up the hardware with the current values held in the driver
55 - = 0 : disable trace hardware.
58 ``echo 1 > enable_source``
63 :Trace Registers: None.
65 CPU ID that this ETM is attached to.
74 :File: ``ts_source`` (ro)
75 :Trace Registers: None.
77 When FEAT_TRF is implemented, value of TRFCR_ELx.TS used for trace session. Otherwise -1
78 indicates an unknown time source. Check trcidr0.tssize to see if a global timestamp is
88 :File: ``addr_idx`` (rw)
89 :Trace Registers: None.
91 Virtual register to index address comparator and range
92 features. Set index for first of the pair in a range.
95 ``echo idx > addr_idx``
97 Where idx < nr_addr_cmp x 2
101 :File: ``addr_range`` (rw)
102 :Trace Registers: ACVR[idx, idx+1], VIIECTLR
104 Pair of addresses for a range selected by addr_idx. Include
105 / exclude according to the optional parameter, or if omitted
106 uses the current ‘mode’ setting. Select comparator range in
107 control register. Error if index is odd value.
109 :Depends: ``mode, addr_idx``
111 ``echo addr1 addr2 [exclude] > addr_range``
113 Where addr1 and addr2 define the range and addr1 < addr2.
115 Optional exclude value:-
120 ``$> echo 0x0000 0x2000 0 > addr_range``
124 :File: ``addr_single`` (rw)
125 :Trace Registers: ACVR[idx]
127 Set a single address comparator according to addr_idx. This
128 is used if the address comparator is used as part of event
129 generation logic etc.
131 :Depends: ``addr_idx``
133 ``echo addr1 > addr_single``
137 :File: ``addr_start`` (rw)
138 :Trace Registers: ACVR[idx], VISSCTLR
140 Set a trace start address comparator according to addr_idx.
141 Select comparator in control register.
143 :Depends: ``addr_idx``
145 ``echo addr1 > addr_start``
149 :File: ``addr_stop`` (rw)
150 :Trace Registers: ACVR[idx], VISSCTLR
152 Set a trace stop address comparator according to addr_idx.
153 Select comparator in control register.
155 :Depends: ``addr_idx``
157 ``echo addr1 > addr_stop``
161 :File: ``addr_context`` (rw)
162 :Trace Registers: ACATR[idx,{6:4}]
164 Link context ID comparator to address comparator addr_idx
166 :Depends: ``addr_idx``
168 ``echo ctxt_idx > addr_context``
170 Where ctxt_idx is the index of the linked context id / vmid
175 :File: ``addr_ctxtype`` (rw)
176 :Trace Registers: ACATR[idx,{3:2}]
178 Input value string. Set type for linked context ID comparator
180 :Depends: ``addr_idx``
182 ``echo type > addr_ctxtype``
184 Type one of {all, vmid, ctxid, none}
186 ``$> echo ctxid > addr_ctxtype``
190 :File: ``addr_exlevel_s_ns`` (rw)
191 :Trace Registers: ACATR[idx,{14:8}]
193 Set the ELx secure and non-secure matching bits for the
194 selected address comparator
196 :Depends: ``addr_idx``
198 ``echo val > addr_exlevel_s_ns``
200 val is a 7 bit value for exception levels to exclude. Input
201 value shifted to correct bits in register.
203 ``$> echo 0x4F > addr_exlevel_s_ns``
207 :File: ``addr_instdatatype`` (rw)
208 :Trace Registers: ACATR[idx,{1:0}]
210 Set the comparator address type for matching. Driver only
211 supports setting instruction address type.
213 :Depends: ``addr_idx``
217 :File: ``addr_cmp_view`` (ro)
218 :Trace Registers: ACVR[idx, idx+1], ACATR[idx], VIIECTLR
220 Read the currently selected address comparator. If part of
221 address range then display both addresses.
223 :Depends: ``addr_idx``
225 ``cat addr_cmp_view``
227 ``$> cat addr_cmp_view``
229 ``addr_cmp[0] range 0x0 0xffffffffffffffff include ctrl(0x4b00)``
233 :File: ``nr_addr_cmp`` (ro)
234 :Trace Registers: From IDR4
236 Number of address comparator pairs
240 :File: ``sshot_idx`` (rw)
241 :Trace Registers: None
243 Select single shot register set.
247 :File: ``sshot_ctrl`` (rw)
248 :Trace Registers: SSCCR[idx]
250 Access a single shot comparator control register.
252 :Depends: ``sshot_idx``
254 ``echo val > sshot_ctrl``
256 Writes val into the selected control register.
260 :File: ``sshot_status`` (ro)
261 :Trace Registers: SSCSR[idx]
263 Read a single shot comparator status register
265 :Depends: ``sshot_idx``
271 ``$> cat sshot_status``
277 :File: ``sshot_pe_ctrl`` (rw)
278 :Trace Registers: SSPCICR[idx]
280 Access a single shot PE comparator input control register.
282 :Depends: ``sshot_idx``
284 ``echo val > sshot_pe_ctrl``
286 Writes val into the selected control register.
290 :File: ``ns_exlevel_vinst`` (rw)
291 :Trace Registers: VICTLR{23:20}
293 Program non-secure exception level filters. Set / clear NS
294 exception filter bits. Setting ‘1’ excludes trace from the
298 ``echo bitfield > ns_exlevel_viinst``
300 Where bitfield contains bits to set clear for EL0 to EL2
302 ``%> echo 0x4 > ns_exlevel_viinst``
304 Excludes EL2 NS trace.
308 :File: ``vinst_pe_cmp_start_stop`` (rw)
309 :Trace Registers: VIPCSSCTLR
311 Access PE start stop comparator input control registers
315 :File: ``bb_ctrl`` (rw)
316 :Trace Registers: BBCTLR
318 Define ranges that Branch Broadcast will operate in.
319 Default (0x0) is all addresses.
321 :Depends: BB enabled.
325 :File: ``cyc_threshold`` (rw)
326 :Trace Registers: CCCTLR
328 Set the threshold for which cycle counts will be emitted.
329 Error if attempt to set below minimum defined in IDR3, masked
330 to width of valid bits.
332 :Depends: CC enabled.
336 :File: ``syncfreq`` (rw)
337 :Trace Registers: SYNCPR
339 Set trace synchronisation period. Power of 2 value, 0 (off)
340 or 8-20. Driver defaults to 12 (every 4096 bytes).
344 :File: ``cntr_idx`` (rw)
345 :Trace Registers: none
347 Select the counter to access
350 ``echo idx > cntr_idx``
356 :File: ``cntr_ctrl`` (rw)
357 :Trace Registers: CNTCTLR[idx]
359 Set counter control value.
361 :Depends: ``cntr_idx``
363 ``echo val > cntr_ctrl``
365 Where val is per ETMv4 spec.
369 :File: ``cntrldvr`` (rw)
370 :Trace Registers: CNTRLDVR[idx]
372 Set counter reload value.
374 :Depends: ``cntr_idx``
376 ``echo val > cntrldvr``
378 Where val is per ETMv4 spec.
382 :File: ``nr_cntr`` (ro)
383 :Trace Registers: From IDR5
386 Number of counters implemented.
390 :File: ``ctxid_idx`` (rw)
391 :Trace Registers: None
393 Select the context ID comparator to access
396 ``echo idx > ctxid_idx``
402 :File: ``ctxid_pid`` (rw)
403 :Trace Registers: CIDCVR[idx]
405 Set the context ID comparator value
407 :Depends: ``ctxid_idx``
411 :File: ``ctxid_masks`` (rw)
412 :Trace Registers: CIDCCTLR0, CIDCCTLR1, CIDCVR<0-7>
414 Pair of values to set the byte masks for 1-8 context ID
415 comparators. Automatically clears masked bytes to 0 in CID
419 ``echo m3m2m1m0 [m7m6m5m4] > ctxid_masks``
421 32 bit values made up of mask bytes, where mN represents a
422 byte mask value for Context ID comparator N.
424 Second value not required on systems that have fewer than 4
425 context ID comparators
429 :File: ``numcidc`` (ro)
430 :Trace Registers: From IDR4
432 Number of Context ID comparators
436 :File: ``vmid_idx`` (rw)
437 :Trace Registers: None
439 Select the VM ID comparator to access.
442 ``echo idx > vmid_idx``
448 :File: ``vmid_val`` (rw)
449 :Trace Registers: VMIDCVR[idx]
451 Set the VM ID comparator value
453 :Depends: ``vmid_idx``
457 :File: ``vmid_masks`` (rw)
458 :Trace Registers: VMIDCCTLR0, VMIDCCTLR1, VMIDCVR<0-7>
460 Pair of values to set the byte masks for 1-8 VM ID comparators.
461 Automatically clears masked bytes to 0 in VMID value registers.
464 ``echo m3m2m1m0 [m7m6m5m4] > vmid_masks``
466 Where mN represents a byte mask value for VMID comparator N.
467 Second value not required on systems that have fewer than 4
472 :File: ``numvmidc`` (ro)
473 :Trace Registers: From IDR4
475 Number of VMID comparators
479 :File: ``res_idx`` (rw)
480 :Trace Registers: None.
482 Select the resource selector control to access. Must be 2 or
483 higher as selectors 0 and 1 are hardwired.
486 ``echo idx > res_idx``
488 Where 2 <= idx < nr_resource x 2
492 :File: ``res_ctrl`` (rw)
493 :Trace Registers: RSCTLR[idx]
495 Set resource selector control value. Value per ETMv4 spec.
497 :Depends: ``res_idx``
499 ``echo val > res_cntr``
501 Where val is per ETMv4 spec.
505 :File: ``nr_resource`` (ro)
506 :Trace Registers: From IDR4
508 Number of resource selector pairs
512 :File: ``event`` (rw)
513 :Trace Registers: EVENTCTRL0R
515 Set up to 4 implemented event fields.
518 ``echo ev3ev2ev1ev0 > event``
520 Where evN is an 8 bit event field. Up to 4 event fields make up the
521 32-bit input value. Number of valid fields is implementation dependent,
526 :File: ``event_instren`` (rw)
527 :Trace Registers: EVENTCTRL1R
529 Choose events which insert event packets into trace stream.
531 :Depends: EVENTCTRL0R
533 ``echo bitfield > event_instren``
535 Where bitfield is up to 4 bits according to number of event fields.
539 :File: ``event_ts`` (rw)
540 :Trace Registers: TSCTLR
542 Set the event that will generate timestamp requests.
544 :Depends: ``TS activated``
546 ``echo evfield > event_ts``
548 Where evfield is an 8 bit event selector.
552 :File: ``seq_idx`` (rw)
553 :Trace Registers: None
555 Sequencer event register select - 0 to 2
559 :File: ``seq_state`` (rw)
560 :Trace Registers: SEQSTR
562 Sequencer current state - 0 to 3.
566 :File: ``seq_event`` (rw)
567 :Trace Registers: SEQEVR[idx]
569 State transition event registers
571 :Depends: ``seq_idx``
573 ``echo evBevF > seq_event``
575 Where evBevF is a 16 bit value made up of two event selectors,
582 :File: ``seq_reset_event`` (rw)
583 :Trace Registers: SEQRSTEVR
585 Sequencer reset event
588 ``echo evfield > seq_reset_event``
590 Where evfield is an 8 bit event selector.
594 :File: ``nrseqstate`` (ro)
595 :Trace Registers: From IDR5
597 Number of sequencer states (0 or 4)
601 :File: ``nr_pe_cmp`` (ro)
602 :Trace Registers: From IDR4
604 Number of PE comparator inputs
608 :File: ``nr_ext_inp`` (ro)
609 :Trace Registers: From IDR5
611 Number of external inputs
615 :File: ``nr_ss_cmp`` (ro)
616 :Trace Registers: From IDR4
618 Number of Single Shot control registers
622 *Note:* When programming any address comparator the driver will tag the
623 comparator with a type used - i.e. RANGE, SINGLE, START, STOP. Once this tag
624 is set, then only the values can be changed using the same sysfs file / type
629 % echo 0 > addr_idx ; select address comparator 0
630 % echo 0x1000 0x5000 0 > addr_range ; set address range on comparators 0, 1.
631 % echo 0x2000 > addr_start ; error as comparator 0 is a range comparator
632 % echo 2 > addr_idx ; select address comparator 2
633 % echo 0x2000 > addr_start ; this is OK as comparator 2 is unused.
634 % echo 0x3000 > addr_stop ; error as comparator 2 set as start address.
635 % echo 2 > addr_idx ; select address comparator 3
636 % echo 0x3000 > addr_stop ; this is OK
638 To remove programming on all the comparators (and all the other hardware) use
639 the reset parameter::
645 The ‘mode’ sysfs parameter.
646 ---------------------------
648 This is a bitfield selection parameter that sets the overall trace mode for the
649 ETM. The table below describes the bits, using the defines from the driver
650 source file, along with a description of the feature these represent. Many
651 features are optional and therefore dependent on implementation in the
654 Bit assignments shown below:-
662 This is the default value for the include / exclude function when
663 setting address ranges. Set 1 for exclude range. When the mode
664 parameter is set this value is applied to the currently indexed
667 .. _coresight-branch-broadcast:
673 Set to enable branch broadcast if supported in hardware [IDR0]. The primary use for this feature
674 is when code is patched dynamically at run time and the full program flow may not be able to be
675 reconstructed using only conditional branches.
677 There is currently no support in Perf for supplying modified binaries to the decoder, so this
678 feature is only intended to be used for debugging purposes or with a 3rd party tool.
680 Choosing this option will result in a significant increase in the amount of trace generated -
681 possible danger of overflows, or fewer instructions covered. Note, that this option also
682 overrides any setting of :ref:`ETM_MODE_RETURNSTACK <coresight-return-stack>`, so where a branch
683 broadcast range overlaps a return stack range, return stacks will not be available for that
686 .. _coresight-cycle-accurate:
692 Set to enable cycle accurate trace if supported [IDR0].
699 Set to enable context ID tracing if supported in hardware [IDR2].
706 Set to enable virtual machine ID tracing if supported [IDR2].
708 .. _coresight-timestamp:
714 Set to enable timestamp generation if supported [IDR0].
716 .. _coresight-return-stack:
721 Set to enable trace return stack use if supported [IDR0].
728 ‘val’ determines level of Q element support enabled if
729 implemented by the ETM [IDR0]
736 Set to enable the ATBTRIGGER bit in the event control register
737 [EVENTCTLR1] if supported [IDR5].
744 Set to enable the LPOVERRIDE bit in the event control register
745 [EVENTCTLR1], if supported [IDR5].
752 Set to enable the ISTALL bit in the stall control register
760 Set to enable the INSTPRIORITY bit in the stall control register
761 [STALLCTLR] , if supported [IDR0].
768 Set to enable the NOOVERFLOW bit in the stall control register
769 [STALLCTLR], if supported [IDR3].
776 Set to enable the TRCRESET bit in the viewinst control register
777 [VICTLR] , if supported [IDR3].
784 Set to enable the TRCCTRL bit in the viewinst control register
789 ETM_MODE_VIEWINST_STARTSTOP
792 Set the initial state value of the ViewInst start / stop logic
793 in the viewinst control register [VICTLR]
800 Set default trace setup to exclude kernel mode trace (see note a)
807 Set default trace setup to exclude user space trace (see note a)
811 *Note a)* On startup the ETM is programmed to trace the complete address space
812 using address range comparator 0. ‘mode’ bits 30 / 31 modify this setting to
813 set EL exclude bits for NS state in either user space (EL0) or kernel space
814 (EL1) in the address range comparator. (the default setting excludes all
815 secure EL, and NS EL2)
817 Once the reset parameter has been used, and/or custom programming has been
818 implemented - using these bits will result in the EL bits for address
819 comparator 0 being set in the same way.
821 *Note b)* Bits 2-3, 8-10, 15-16, 18, 22, control features that only work with
822 data trace. As A-profile data trace is architecturally prohibited in ETMv4,
823 these have been omitted here. Possible uses could be where a kernel has
824 support for control of R or M profile infrastructure as part of a heterogeneous
827 Bits 17, 28-29 are unused.