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: ``addr_idx`` (rw)
75 :Trace Registers: None.
77 Virtual register to index address comparator and range
78 features. Set index for first of the pair in a range.
81 ``echo idx > addr_idx``
83 Where idx < nr_addr_cmp x 2
87 :File: ``addr_range`` (rw)
88 :Trace Registers: ACVR[idx, idx+1], VIIECTLR
90 Pair of addresses for a range selected by addr_idx. Include
91 / exclude according to the optional parameter, or if omitted
92 uses the current ‘mode’ setting. Select comparator range in
93 control register. Error if index is odd value.
95 :Depends: ``mode, addr_idx``
97 ``echo addr1 addr2 [exclude] > addr_range``
99 Where addr1 and addr2 define the range and addr1 < addr2.
101 Optional exclude value:-
106 ``$> echo 0x0000 0x2000 0 > addr_range``
110 :File: ``addr_single`` (rw)
111 :Trace Registers: ACVR[idx]
113 Set a single address comparator according to addr_idx. This
114 is used if the address comparator is used as part of event
115 generation logic etc.
117 :Depends: ``addr_idx``
119 ``echo addr1 > addr_single``
123 :File: ``addr_start`` (rw)
124 :Trace Registers: ACVR[idx], VISSCTLR
126 Set a trace start address comparator according to addr_idx.
127 Select comparator in control register.
129 :Depends: ``addr_idx``
131 ``echo addr1 > addr_start``
135 :File: ``addr_stop`` (rw)
136 :Trace Registers: ACVR[idx], VISSCTLR
138 Set a trace stop address comparator according to addr_idx.
139 Select comparator in control register.
141 :Depends: ``addr_idx``
143 ``echo addr1 > addr_stop``
147 :File: ``addr_context`` (rw)
148 :Trace Registers: ACATR[idx,{6:4}]
150 Link context ID comparator to address comparator addr_idx
152 :Depends: ``addr_idx``
154 ``echo ctxt_idx > addr_context``
156 Where ctxt_idx is the index of the linked context id / vmid
161 :File: ``addr_ctxtype`` (rw)
162 :Trace Registers: ACATR[idx,{3:2}]
164 Input value string. Set type for linked context ID comparator
166 :Depends: ``addr_idx``
168 ``echo type > addr_ctxtype``
170 Type one of {all, vmid, ctxid, none}
172 ``$> echo ctxid > addr_ctxtype``
176 :File: ``addr_exlevel_s_ns`` (rw)
177 :Trace Registers: ACATR[idx,{14:8}]
179 Set the ELx secure and non-secure matching bits for the
180 selected address comparator
182 :Depends: ``addr_idx``
184 ``echo val > addr_exlevel_s_ns``
186 val is a 7 bit value for exception levels to exclude. Input
187 value shifted to correct bits in register.
189 ``$> echo 0x4F > addr_exlevel_s_ns``
193 :File: ``addr_instdatatype`` (rw)
194 :Trace Registers: ACATR[idx,{1:0}]
196 Set the comparator address type for matching. Driver only
197 supports setting instruction address type.
199 :Depends: ``addr_idx``
203 :File: ``addr_cmp_view`` (ro)
204 :Trace Registers: ACVR[idx, idx+1], ACATR[idx], VIIECTLR
206 Read the currently selected address comparator. If part of
207 address range then display both addresses.
209 :Depends: ``addr_idx``
211 ``cat addr_cmp_view``
213 ``$> cat addr_cmp_view``
215 ``addr_cmp[0] range 0x0 0xffffffffffffffff include ctrl(0x4b00)``
219 :File: ``nr_addr_cmp`` (ro)
220 :Trace Registers: From IDR4
222 Number of address comparator pairs
226 :File: ``sshot_idx`` (rw)
227 :Trace Registers: None
229 Select single shot register set.
233 :File: ``sshot_ctrl`` (rw)
234 :Trace Registers: SSCCR[idx]
236 Access a single shot comparator control register.
238 :Depends: ``sshot_idx``
240 ``echo val > sshot_ctrl``
242 Writes val into the selected control register.
246 :File: ``sshot_status`` (ro)
247 :Trace Registers: SSCSR[idx]
249 Read a single shot comparator status register
251 :Depends: ``sshot_idx``
257 ``$> cat sshot_status``
263 :File: ``sshot_pe_ctrl`` (rw)
264 :Trace Registers: SSPCICR[idx]
266 Access a single shot PE comparator input control register.
268 :Depends: ``sshot_idx``
270 ``echo val > sshot_pe_ctrl``
272 Writes val into the selected control register.
276 :File: ``ns_exlevel_vinst`` (rw)
277 :Trace Registers: VICTLR{23:20}
279 Program non-secure exception level filters. Set / clear NS
280 exception filter bits. Setting ‘1’ excludes trace from the
284 ``echo bitfield > ns_exlevel_viinst``
286 Where bitfield contains bits to set clear for EL0 to EL2
288 ``%> echo 0x4 > ns_exlevel_viinst``
290 Excludes EL2 NS trace.
294 :File: ``vinst_pe_cmp_start_stop`` (rw)
295 :Trace Registers: VIPCSSCTLR
297 Access PE start stop comparator input control registers
301 :File: ``bb_ctrl`` (rw)
302 :Trace Registers: BBCTLR
304 Define ranges that Branch Broadcast will operate in.
305 Default (0x0) is all addresses.
307 :Depends: BB enabled.
311 :File: ``cyc_threshold`` (rw)
312 :Trace Registers: CCCTLR
314 Set the threshold for which cycle counts will be emitted.
315 Error if attempt to set below minimum defined in IDR3, masked
316 to width of valid bits.
318 :Depends: CC enabled.
322 :File: ``syncfreq`` (rw)
323 :Trace Registers: SYNCPR
325 Set trace synchronisation period. Power of 2 value, 0 (off)
326 or 8-20. Driver defaults to 12 (every 4096 bytes).
330 :File: ``cntr_idx`` (rw)
331 :Trace Registers: none
333 Select the counter to access
336 ``echo idx > cntr_idx``
342 :File: ``cntr_ctrl`` (rw)
343 :Trace Registers: CNTCTLR[idx]
345 Set counter control value.
347 :Depends: ``cntr_idx``
349 ``echo val > cntr_ctrl``
351 Where val is per ETMv4 spec.
355 :File: ``cntrldvr`` (rw)
356 :Trace Registers: CNTRLDVR[idx]
358 Set counter reload value.
360 :Depends: ``cntr_idx``
362 ``echo val > cntrldvr``
364 Where val is per ETMv4 spec.
368 :File: ``nr_cntr`` (ro)
369 :Trace Registers: From IDR5
372 Number of counters implemented.
376 :File: ``ctxid_idx`` (rw)
377 :Trace Registers: None
379 Select the context ID comparator to access
382 ``echo idx > ctxid_idx``
388 :File: ``ctxid_pid`` (rw)
389 :Trace Registers: CIDCVR[idx]
391 Set the context ID comparator value
393 :Depends: ``ctxid_idx``
397 :File: ``ctxid_masks`` (rw)
398 :Trace Registers: CIDCCTLR0, CIDCCTLR1, CIDCVR<0-7>
400 Pair of values to set the byte masks for 1-8 context ID
401 comparators. Automatically clears masked bytes to 0 in CID
405 ``echo m3m2m1m0 [m7m6m5m4] > ctxid_masks``
407 32 bit values made up of mask bytes, where mN represents a
408 byte mask value for Context ID comparator N.
410 Second value not required on systems that have fewer than 4
411 context ID comparators
415 :File: ``numcidc`` (ro)
416 :Trace Registers: From IDR4
418 Number of Context ID comparators
422 :File: ``vmid_idx`` (rw)
423 :Trace Registers: None
425 Select the VM ID comparator to access.
428 ``echo idx > vmid_idx``
434 :File: ``vmid_val`` (rw)
435 :Trace Registers: VMIDCVR[idx]
437 Set the VM ID comparator value
439 :Depends: ``vmid_idx``
443 :File: ``vmid_masks`` (rw)
444 :Trace Registers: VMIDCCTLR0, VMIDCCTLR1, VMIDCVR<0-7>
446 Pair of values to set the byte masks for 1-8 VM ID comparators.
447 Automatically clears masked bytes to 0 in VMID value registers.
450 ``echo m3m2m1m0 [m7m6m5m4] > vmid_masks``
452 Where mN represents a byte mask value for VMID comparator N.
453 Second value not required on systems that have fewer than 4
458 :File: ``numvmidc`` (ro)
459 :Trace Registers: From IDR4
461 Number of VMID comparators
465 :File: ``res_idx`` (rw)
466 :Trace Registers: None.
468 Select the resource selector control to access. Must be 2 or
469 higher as selectors 0 and 1 are hardwired.
472 ``echo idx > res_idx``
474 Where 2 <= idx < nr_resource x 2
478 :File: ``res_ctrl`` (rw)
479 :Trace Registers: RSCTLR[idx]
481 Set resource selector control value. Value per ETMv4 spec.
483 :Depends: ``res_idx``
485 ``echo val > res_cntr``
487 Where val is per ETMv4 spec.
491 :File: ``nr_resource`` (ro)
492 :Trace Registers: From IDR4
494 Number of resource selector pairs
498 :File: ``event`` (rw)
499 :Trace Registers: EVENTCTRL0R
501 Set up to 4 implemented event fields.
504 ``echo ev3ev2ev1ev0 > event``
506 Where evN is an 8 bit event field. Up to 4 event fields make up the
507 32-bit input value. Number of valid fields is implementation dependent,
512 :File: ``event_instren`` (rw)
513 :Trace Registers: EVENTCTRL1R
515 Choose events which insert event packets into trace stream.
517 :Depends: EVENTCTRL0R
519 ``echo bitfield > event_instren``
521 Where bitfield is up to 4 bits according to number of event fields.
525 :File: ``event_ts`` (rw)
526 :Trace Registers: TSCTLR
528 Set the event that will generate timestamp requests.
530 :Depends: ``TS activated``
532 ``echo evfield > event_ts``
534 Where evfield is an 8 bit event selector.
538 :File: ``seq_idx`` (rw)
539 :Trace Registers: None
541 Sequencer event register select - 0 to 2
545 :File: ``seq_state`` (rw)
546 :Trace Registers: SEQSTR
548 Sequencer current state - 0 to 3.
552 :File: ``seq_event`` (rw)
553 :Trace Registers: SEQEVR[idx]
555 State transition event registers
557 :Depends: ``seq_idx``
559 ``echo evBevF > seq_event``
561 Where evBevF is a 16 bit value made up of two event selectors,
568 :File: ``seq_reset_event`` (rw)
569 :Trace Registers: SEQRSTEVR
571 Sequencer reset event
574 ``echo evfield > seq_reset_event``
576 Where evfield is an 8 bit event selector.
580 :File: ``nrseqstate`` (ro)
581 :Trace Registers: From IDR5
583 Number of sequencer states (0 or 4)
587 :File: ``nr_pe_cmp`` (ro)
588 :Trace Registers: From IDR4
590 Number of PE comparator inputs
594 :File: ``nr_ext_inp`` (ro)
595 :Trace Registers: From IDR5
597 Number of external inputs
601 :File: ``nr_ss_cmp`` (ro)
602 :Trace Registers: From IDR4
604 Number of Single Shot control registers
608 *Note:* When programming any address comparator the driver will tag the
609 comparator with a type used - i.e. RANGE, SINGLE, START, STOP. Once this tag
610 is set, then only the values can be changed using the same sysfs file / type
615 % echo 0 > addr_idx ; select address comparator 0
616 % echo 0x1000 0x5000 0 > addr_range ; set address range on comparators 0, 1.
617 % echo 0x2000 > addr_start ; error as comparator 0 is a range comparator
618 % echo 2 > addr_idx ; select address comparator 2
619 % echo 0x2000 > addr_start ; this is OK as comparator 2 is unused.
620 % echo 0x3000 > addr_stop ; error as comparator 2 set as start address.
621 % echo 2 > addr_idx ; select address comparator 3
622 % echo 0x3000 > addr_stop ; this is OK
624 To remove programming on all the comparators (and all the other hardware) use
625 the reset parameter::
631 The ‘mode’ sysfs parameter.
632 ---------------------------
634 This is a bitfield selection parameter that sets the overall trace mode for the
635 ETM. The table below describes the bits, using the defines from the driver
636 source file, along with a description of the feature these represent. Many
637 features are optional and therefore dependent on implementation in the
640 Bit assignments shown below:-
648 This is the default value for the include / exclude function when
649 setting address ranges. Set 1 for exclude range. When the mode
650 parameter is set this value is applied to the currently indexed
658 Set to enable branch broadcast if supported in hardware [IDR0].
665 Set to enable cycle accurate trace if supported [IDR0].
672 Set to enable context ID tracing if supported in hardware [IDR2].
679 Set to enable virtual machine ID tracing if supported [IDR2].
686 Set to enable timestamp generation if supported [IDR0].
692 Set to enable trace return stack use if supported [IDR0].
699 ‘val’ determines level of Q element support enabled if
700 implemented by the ETM [IDR0]
707 Set to enable the ATBTRIGGER bit in the event control register
708 [EVENTCTLR1] if supported [IDR5].
715 Set to enable the LPOVERRIDE bit in the event control register
716 [EVENTCTLR1], if supported [IDR5].
723 Set to enable the ISTALL bit in the stall control register
731 Set to enable the INSTPRIORITY bit in the stall control register
732 [STALLCTLR] , if supported [IDR0].
739 Set to enable the NOOVERFLOW bit in the stall control register
740 [STALLCTLR], if supported [IDR3].
747 Set to enable the TRCRESET bit in the viewinst control register
748 [VICTLR] , if supported [IDR3].
755 Set to enable the TRCCTRL bit in the viewinst control register
760 ETM_MODE_VIEWINST_STARTSTOP
763 Set the initial state value of the ViewInst start / stop logic
764 in the viewinst control register [VICTLR]
771 Set default trace setup to exclude kernel mode trace (see note a)
778 Set default trace setup to exclude user space trace (see note a)
782 *Note a)* On startup the ETM is programmed to trace the complete address space
783 using address range comparator 0. ‘mode’ bits 30 / 31 modify this setting to
784 set EL exclude bits for NS state in either user space (EL0) or kernel space
785 (EL1) in the address range comparator. (the default setting excludes all
786 secure EL, and NS EL2)
788 Once the reset parameter has been used, and/or custom programming has been
789 implemented - using these bits will result in the EL bits for address
790 comparator 0 being set in the same way.
792 *Note b)* Bits 2-3, 8-10, 15-16, 18, 22, control features that only work with
793 data trace. As A-profile data trace is architecturally prohibited in ETMv4,
794 these have been omitted here. Possible uses could be where a kernel has
795 support for control of R or M profile infrastructure as part of a heterogeneous
798 Bits 17, 28-29 are unused.