0001 ===============================================
0002 ETMv4 sysfs linux driver programming reference.
0003 ===============================================
0004
0005 :Author: Mike Leach <mike.leach@linaro.org>
0006 :Date: October 11th, 2019
0007
0008 Supplement to existing ETMv4 driver documentation.
0009
0010 Sysfs files and directories
0011 ---------------------------
0012
0013 Root: ``/sys/bus/coresight/devices/etm<N>``
0014
0015
0016 The following paragraphs explain the association between sysfs files and the
0017 ETMv4 registers that they effect. Note the register names are given without
0018 the ‘TRC’ prefix.
0019
0020 ----
0021
0022 :File: ``mode`` (rw)
0023 :Trace Registers: {CONFIGR + others}
0024 :Notes:
0025 Bit select trace features. See ‘mode’ section below. Bits
0026 in this will cause equivalent programming of trace config and
0027 other registers to enable the features requested.
0028
0029 :Syntax & eg:
0030 ``echo bitfield > mode``
0031
0032 bitfield up to 32 bits setting trace features.
0033
0034 :Example:
0035 ``$> echo 0x012 > mode``
0036
0037 ----
0038
0039 :File: ``reset`` (wo)
0040 :Trace Registers: All
0041 :Notes:
0042 Reset all programming to trace nothing / no logic programmed.
0043
0044 :Syntax:
0045 ``echo 1 > reset``
0046
0047 ----
0048
0049 :File: ``enable_source`` (wo)
0050 :Trace Registers: PRGCTLR, All hardware regs.
0051 :Notes:
0052 - > 0 : Programs up the hardware with the current values held in the driver
0053 and enables trace.
0054
0055 - = 0 : disable trace hardware.
0056
0057 :Syntax:
0058 ``echo 1 > enable_source``
0059
0060 ----
0061
0062 :File: ``cpu`` (ro)
0063 :Trace Registers: None.
0064 :Notes:
0065 CPU ID that this ETM is attached to.
0066
0067 :Example:
0068 ``$> cat cpu``
0069
0070 ``$> 0``
0071
0072 ----
0073
0074 :File: ``addr_idx`` (rw)
0075 :Trace Registers: None.
0076 :Notes:
0077 Virtual register to index address comparator and range
0078 features. Set index for first of the pair in a range.
0079
0080 :Syntax:
0081 ``echo idx > addr_idx``
0082
0083 Where idx < nr_addr_cmp x 2
0084
0085 ----
0086
0087 :File: ``addr_range`` (rw)
0088 :Trace Registers: ACVR[idx, idx+1], VIIECTLR
0089 :Notes:
0090 Pair of addresses for a range selected by addr_idx. Include
0091 / exclude according to the optional parameter, or if omitted
0092 uses the current ‘mode’ setting. Select comparator range in
0093 control register. Error if index is odd value.
0094
0095 :Depends: ``mode, addr_idx``
0096 :Syntax:
0097 ``echo addr1 addr2 [exclude] > addr_range``
0098
0099 Where addr1 and addr2 define the range and addr1 < addr2.
0100
0101 Optional exclude value:-
0102
0103 - 0 for include
0104 - 1 for exclude.
0105 :Example:
0106 ``$> echo 0x0000 0x2000 0 > addr_range``
0107
0108 ----
0109
0110 :File: ``addr_single`` (rw)
0111 :Trace Registers: ACVR[idx]
0112 :Notes:
0113 Set a single address comparator according to addr_idx. This
0114 is used if the address comparator is used as part of event
0115 generation logic etc.
0116
0117 :Depends: ``addr_idx``
0118 :Syntax:
0119 ``echo addr1 > addr_single``
0120
0121 ----
0122
0123 :File: ``addr_start`` (rw)
0124 :Trace Registers: ACVR[idx], VISSCTLR
0125 :Notes:
0126 Set a trace start address comparator according to addr_idx.
0127 Select comparator in control register.
0128
0129 :Depends: ``addr_idx``
0130 :Syntax:
0131 ``echo addr1 > addr_start``
0132
0133 ----
0134
0135 :File: ``addr_stop`` (rw)
0136 :Trace Registers: ACVR[idx], VISSCTLR
0137 :Notes:
0138 Set a trace stop address comparator according to addr_idx.
0139 Select comparator in control register.
0140
0141 :Depends: ``addr_idx``
0142 :Syntax:
0143 ``echo addr1 > addr_stop``
0144
0145 ----
0146
0147 :File: ``addr_context`` (rw)
0148 :Trace Registers: ACATR[idx,{6:4}]
0149 :Notes:
0150 Link context ID comparator to address comparator addr_idx
0151
0152 :Depends: ``addr_idx``
0153 :Syntax:
0154 ``echo ctxt_idx > addr_context``
0155
0156 Where ctxt_idx is the index of the linked context id / vmid
0157 comparator.
0158
0159 ----
0160
0161 :File: ``addr_ctxtype`` (rw)
0162 :Trace Registers: ACATR[idx,{3:2}]
0163 :Notes:
0164 Input value string. Set type for linked context ID comparator
0165
0166 :Depends: ``addr_idx``
0167 :Syntax:
0168 ``echo type > addr_ctxtype``
0169
0170 Type one of {all, vmid, ctxid, none}
0171 :Example:
0172 ``$> echo ctxid > addr_ctxtype``
0173
0174 ----
0175
0176 :File: ``addr_exlevel_s_ns`` (rw)
0177 :Trace Registers: ACATR[idx,{14:8}]
0178 :Notes:
0179 Set the ELx secure and non-secure matching bits for the
0180 selected address comparator
0181
0182 :Depends: ``addr_idx``
0183 :Syntax:
0184 ``echo val > addr_exlevel_s_ns``
0185
0186 val is a 7 bit value for exception levels to exclude. Input
0187 value shifted to correct bits in register.
0188 :Example:
0189 ``$> echo 0x4F > addr_exlevel_s_ns``
0190
0191 ----
0192
0193 :File: ``addr_instdatatype`` (rw)
0194 :Trace Registers: ACATR[idx,{1:0}]
0195 :Notes:
0196 Set the comparator address type for matching. Driver only
0197 supports setting instruction address type.
0198
0199 :Depends: ``addr_idx``
0200
0201 ----
0202
0203 :File: ``addr_cmp_view`` (ro)
0204 :Trace Registers: ACVR[idx, idx+1], ACATR[idx], VIIECTLR
0205 :Notes:
0206 Read the currently selected address comparator. If part of
0207 address range then display both addresses.
0208
0209 :Depends: ``addr_idx``
0210 :Syntax:
0211 ``cat addr_cmp_view``
0212 :Example:
0213 ``$> cat addr_cmp_view``
0214
0215 ``addr_cmp[0] range 0x0 0xffffffffffffffff include ctrl(0x4b00)``
0216
0217 ----
0218
0219 :File: ``nr_addr_cmp`` (ro)
0220 :Trace Registers: From IDR4
0221 :Notes:
0222 Number of address comparator pairs
0223
0224 ----
0225
0226 :File: ``sshot_idx`` (rw)
0227 :Trace Registers: None
0228 :Notes:
0229 Select single shot register set.
0230
0231 ----
0232
0233 :File: ``sshot_ctrl`` (rw)
0234 :Trace Registers: SSCCR[idx]
0235 :Notes:
0236 Access a single shot comparator control register.
0237
0238 :Depends: ``sshot_idx``
0239 :Syntax:
0240 ``echo val > sshot_ctrl``
0241
0242 Writes val into the selected control register.
0243
0244 ----
0245
0246 :File: ``sshot_status`` (ro)
0247 :Trace Registers: SSCSR[idx]
0248 :Notes:
0249 Read a single shot comparator status register
0250
0251 :Depends: ``sshot_idx``
0252 :Syntax:
0253 ``cat sshot_status``
0254
0255 Read status.
0256 :Example:
0257 ``$> cat sshot_status``
0258
0259 ``0x1``
0260
0261 ----
0262
0263 :File: ``sshot_pe_ctrl`` (rw)
0264 :Trace Registers: SSPCICR[idx]
0265 :Notes:
0266 Access a single shot PE comparator input control register.
0267
0268 :Depends: ``sshot_idx``
0269 :Syntax:
0270 ``echo val > sshot_pe_ctrl``
0271
0272 Writes val into the selected control register.
0273
0274 ----
0275
0276 :File: ``ns_exlevel_vinst`` (rw)
0277 :Trace Registers: VICTLR{23:20}
0278 :Notes:
0279 Program non-secure exception level filters. Set / clear NS
0280 exception filter bits. Setting ‘1’ excludes trace from the
0281 exception level.
0282
0283 :Syntax:
0284 ``echo bitfield > ns_exlevel_viinst``
0285
0286 Where bitfield contains bits to set clear for EL0 to EL2
0287 :Example:
0288 ``%> echo 0x4 > ns_exlevel_viinst``
0289
0290 Excludes EL2 NS trace.
0291
0292 ----
0293
0294 :File: ``vinst_pe_cmp_start_stop`` (rw)
0295 :Trace Registers: VIPCSSCTLR
0296 :Notes:
0297 Access PE start stop comparator input control registers
0298
0299 ----
0300
0301 :File: ``bb_ctrl`` (rw)
0302 :Trace Registers: BBCTLR
0303 :Notes:
0304 Define ranges that Branch Broadcast will operate in.
0305 Default (0x0) is all addresses.
0306
0307 :Depends: BB enabled.
0308
0309 ----
0310
0311 :File: ``cyc_threshold`` (rw)
0312 :Trace Registers: CCCTLR
0313 :Notes:
0314 Set the threshold for which cycle counts will be emitted.
0315 Error if attempt to set below minimum defined in IDR3, masked
0316 to width of valid bits.
0317
0318 :Depends: CC enabled.
0319
0320 ----
0321
0322 :File: ``syncfreq`` (rw)
0323 :Trace Registers: SYNCPR
0324 :Notes:
0325 Set trace synchronisation period. Power of 2 value, 0 (off)
0326 or 8-20. Driver defaults to 12 (every 4096 bytes).
0327
0328 ----
0329
0330 :File: ``cntr_idx`` (rw)
0331 :Trace Registers: none
0332 :Notes:
0333 Select the counter to access
0334
0335 :Syntax:
0336 ``echo idx > cntr_idx``
0337
0338 Where idx < nr_cntr
0339
0340 ----
0341
0342 :File: ``cntr_ctrl`` (rw)
0343 :Trace Registers: CNTCTLR[idx]
0344 :Notes:
0345 Set counter control value.
0346
0347 :Depends: ``cntr_idx``
0348 :Syntax:
0349 ``echo val > cntr_ctrl``
0350
0351 Where val is per ETMv4 spec.
0352
0353 ----
0354
0355 :File: ``cntrldvr`` (rw)
0356 :Trace Registers: CNTRLDVR[idx]
0357 :Notes:
0358 Set counter reload value.
0359
0360 :Depends: ``cntr_idx``
0361 :Syntax:
0362 ``echo val > cntrldvr``
0363
0364 Where val is per ETMv4 spec.
0365
0366 ----
0367
0368 :File: ``nr_cntr`` (ro)
0369 :Trace Registers: From IDR5
0370
0371 :Notes:
0372 Number of counters implemented.
0373
0374 ----
0375
0376 :File: ``ctxid_idx`` (rw)
0377 :Trace Registers: None
0378 :Notes:
0379 Select the context ID comparator to access
0380
0381 :Syntax:
0382 ``echo idx > ctxid_idx``
0383
0384 Where idx < numcidc
0385
0386 ----
0387
0388 :File: ``ctxid_pid`` (rw)
0389 :Trace Registers: CIDCVR[idx]
0390 :Notes:
0391 Set the context ID comparator value
0392
0393 :Depends: ``ctxid_idx``
0394
0395 ----
0396
0397 :File: ``ctxid_masks`` (rw)
0398 :Trace Registers: CIDCCTLR0, CIDCCTLR1, CIDCVR<0-7>
0399 :Notes:
0400 Pair of values to set the byte masks for 1-8 context ID
0401 comparators. Automatically clears masked bytes to 0 in CID
0402 value registers.
0403
0404 :Syntax:
0405 ``echo m3m2m1m0 [m7m6m5m4] > ctxid_masks``
0406
0407 32 bit values made up of mask bytes, where mN represents a
0408 byte mask value for Context ID comparator N.
0409
0410 Second value not required on systems that have fewer than 4
0411 context ID comparators
0412
0413 ----
0414
0415 :File: ``numcidc`` (ro)
0416 :Trace Registers: From IDR4
0417 :Notes:
0418 Number of Context ID comparators
0419
0420 ----
0421
0422 :File: ``vmid_idx`` (rw)
0423 :Trace Registers: None
0424 :Notes:
0425 Select the VM ID comparator to access.
0426
0427 :Syntax:
0428 ``echo idx > vmid_idx``
0429
0430 Where idx < numvmidc
0431
0432 ----
0433
0434 :File: ``vmid_val`` (rw)
0435 :Trace Registers: VMIDCVR[idx]
0436 :Notes:
0437 Set the VM ID comparator value
0438
0439 :Depends: ``vmid_idx``
0440
0441 ----
0442
0443 :File: ``vmid_masks`` (rw)
0444 :Trace Registers: VMIDCCTLR0, VMIDCCTLR1, VMIDCVR<0-7>
0445 :Notes:
0446 Pair of values to set the byte masks for 1-8 VM ID comparators.
0447 Automatically clears masked bytes to 0 in VMID value registers.
0448
0449 :Syntax:
0450 ``echo m3m2m1m0 [m7m6m5m4] > vmid_masks``
0451
0452 Where mN represents a byte mask value for VMID comparator N.
0453 Second value not required on systems that have fewer than 4
0454 VMID comparators.
0455
0456 ----
0457
0458 :File: ``numvmidc`` (ro)
0459 :Trace Registers: From IDR4
0460 :Notes:
0461 Number of VMID comparators
0462
0463 ----
0464
0465 :File: ``res_idx`` (rw)
0466 :Trace Registers: None.
0467 :Notes:
0468 Select the resource selector control to access. Must be 2 or
0469 higher as selectors 0 and 1 are hardwired.
0470
0471 :Syntax:
0472 ``echo idx > res_idx``
0473
0474 Where 2 <= idx < nr_resource x 2
0475
0476 ----
0477
0478 :File: ``res_ctrl`` (rw)
0479 :Trace Registers: RSCTLR[idx]
0480 :Notes:
0481 Set resource selector control value. Value per ETMv4 spec.
0482
0483 :Depends: ``res_idx``
0484 :Syntax:
0485 ``echo val > res_cntr``
0486
0487 Where val is per ETMv4 spec.
0488
0489 ----
0490
0491 :File: ``nr_resource`` (ro)
0492 :Trace Registers: From IDR4
0493 :Notes:
0494 Number of resource selector pairs
0495
0496 ----
0497
0498 :File: ``event`` (rw)
0499 :Trace Registers: EVENTCTRL0R
0500 :Notes:
0501 Set up to 4 implemented event fields.
0502
0503 :Syntax:
0504 ``echo ev3ev2ev1ev0 > event``
0505
0506 Where evN is an 8 bit event field. Up to 4 event fields make up the
0507 32-bit input value. Number of valid fields is implementation dependent,
0508 defined in IDR0.
0509
0510 ----
0511
0512 :File: ``event_instren`` (rw)
0513 :Trace Registers: EVENTCTRL1R
0514 :Notes:
0515 Choose events which insert event packets into trace stream.
0516
0517 :Depends: EVENTCTRL0R
0518 :Syntax:
0519 ``echo bitfield > event_instren``
0520
0521 Where bitfield is up to 4 bits according to number of event fields.
0522
0523 ----
0524
0525 :File: ``event_ts`` (rw)
0526 :Trace Registers: TSCTLR
0527 :Notes:
0528 Set the event that will generate timestamp requests.
0529
0530 :Depends: ``TS activated``
0531 :Syntax:
0532 ``echo evfield > event_ts``
0533
0534 Where evfield is an 8 bit event selector.
0535
0536 ----
0537
0538 :File: ``seq_idx`` (rw)
0539 :Trace Registers: None
0540 :Notes:
0541 Sequencer event register select - 0 to 2
0542
0543 ----
0544
0545 :File: ``seq_state`` (rw)
0546 :Trace Registers: SEQSTR
0547 :Notes:
0548 Sequencer current state - 0 to 3.
0549
0550 ----
0551
0552 :File: ``seq_event`` (rw)
0553 :Trace Registers: SEQEVR[idx]
0554 :Notes:
0555 State transition event registers
0556
0557 :Depends: ``seq_idx``
0558 :Syntax:
0559 ``echo evBevF > seq_event``
0560
0561 Where evBevF is a 16 bit value made up of two event selectors,
0562
0563 - evB : back
0564 - evF : forwards.
0565
0566 ----
0567
0568 :File: ``seq_reset_event`` (rw)
0569 :Trace Registers: SEQRSTEVR
0570 :Notes:
0571 Sequencer reset event
0572
0573 :Syntax:
0574 ``echo evfield > seq_reset_event``
0575
0576 Where evfield is an 8 bit event selector.
0577
0578 ----
0579
0580 :File: ``nrseqstate`` (ro)
0581 :Trace Registers: From IDR5
0582 :Notes:
0583 Number of sequencer states (0 or 4)
0584
0585 ----
0586
0587 :File: ``nr_pe_cmp`` (ro)
0588 :Trace Registers: From IDR4
0589 :Notes:
0590 Number of PE comparator inputs
0591
0592 ----
0593
0594 :File: ``nr_ext_inp`` (ro)
0595 :Trace Registers: From IDR5
0596 :Notes:
0597 Number of external inputs
0598
0599 ----
0600
0601 :File: ``nr_ss_cmp`` (ro)
0602 :Trace Registers: From IDR4
0603 :Notes:
0604 Number of Single Shot control registers
0605
0606 ----
0607
0608 *Note:* When programming any address comparator the driver will tag the
0609 comparator with a type used - i.e. RANGE, SINGLE, START, STOP. Once this tag
0610 is set, then only the values can be changed using the same sysfs file / type
0611 used to program it.
0612
0613 Thus::
0614
0615 % echo 0 > addr_idx ; select address comparator 0
0616 % echo 0x1000 0x5000 0 > addr_range ; set address range on comparators 0, 1.
0617 % echo 0x2000 > addr_start ; error as comparator 0 is a range comparator
0618 % echo 2 > addr_idx ; select address comparator 2
0619 % echo 0x2000 > addr_start ; this is OK as comparator 2 is unused.
0620 % echo 0x3000 > addr_stop ; error as comparator 2 set as start address.
0621 % echo 2 > addr_idx ; select address comparator 3
0622 % echo 0x3000 > addr_stop ; this is OK
0623
0624 To remove programming on all the comparators (and all the other hardware) use
0625 the reset parameter::
0626
0627 % echo 1 > reset
0628
0629
0630
0631 The ‘mode’ sysfs parameter.
0632 ---------------------------
0633
0634 This is a bitfield selection parameter that sets the overall trace mode for the
0635 ETM. The table below describes the bits, using the defines from the driver
0636 source file, along with a description of the feature these represent. Many
0637 features are optional and therefore dependent on implementation in the
0638 hardware.
0639
0640 Bit assignments shown below:-
0641
0642 ----
0643
0644 **bit (0):**
0645 ETM_MODE_EXCLUDE
0646
0647 **description:**
0648 This is the default value for the include / exclude function when
0649 setting address ranges. Set 1 for exclude range. When the mode
0650 parameter is set this value is applied to the currently indexed
0651 address range.
0652
0653 .. _coresight-branch-broadcast:
0654
0655 **bit (4):**
0656 ETM_MODE_BB
0657
0658 **description:**
0659 Set to enable branch broadcast if supported in hardware [IDR0]. The primary use for this feature
0660 is when code is patched dynamically at run time and the full program flow may not be able to be
0661 reconstructed using only conditional branches.
0662
0663 There is currently no support in Perf for supplying modified binaries to the decoder, so this
0664 feature is only inteded to be used for debugging purposes or with a 3rd party tool.
0665
0666 Choosing this option will result in a significant increase in the amount of trace generated -
0667 possible danger of overflows, or fewer instructions covered. Note, that this option also
0668 overrides any setting of :ref:`ETM_MODE_RETURNSTACK <coresight-return-stack>`, so where a branch
0669 broadcast range overlaps a return stack range, return stacks will not be available for that
0670 range.
0671
0672 .. _coresight-cycle-accurate:
0673
0674 **bit (5):**
0675 ETMv4_MODE_CYCACC
0676
0677 **description:**
0678 Set to enable cycle accurate trace if supported [IDR0].
0679
0680
0681 **bit (6):**
0682 ETMv4_MODE_CTXID
0683
0684 **description:**
0685 Set to enable context ID tracing if supported in hardware [IDR2].
0686
0687
0688 **bit (7):**
0689 ETM_MODE_VMID
0690
0691 **description:**
0692 Set to enable virtual machine ID tracing if supported [IDR2].
0693
0694 .. _coresight-timestamp:
0695
0696 **bit (11):**
0697 ETMv4_MODE_TIMESTAMP
0698
0699 **description:**
0700 Set to enable timestamp generation if supported [IDR0].
0701
0702 .. _coresight-return-stack:
0703
0704 **bit (12):**
0705 ETM_MODE_RETURNSTACK
0706 **description:**
0707 Set to enable trace return stack use if supported [IDR0].
0708
0709
0710 **bit (13-14):**
0711 ETM_MODE_QELEM(val)
0712
0713 **description:**
0714 ‘val’ determines level of Q element support enabled if
0715 implemented by the ETM [IDR0]
0716
0717
0718 **bit (19):**
0719 ETM_MODE_ATB_TRIGGER
0720
0721 **description:**
0722 Set to enable the ATBTRIGGER bit in the event control register
0723 [EVENTCTLR1] if supported [IDR5].
0724
0725
0726 **bit (20):**
0727 ETM_MODE_LPOVERRIDE
0728
0729 **description:**
0730 Set to enable the LPOVERRIDE bit in the event control register
0731 [EVENTCTLR1], if supported [IDR5].
0732
0733
0734 **bit (21):**
0735 ETM_MODE_ISTALL_EN
0736
0737 **description:**
0738 Set to enable the ISTALL bit in the stall control register
0739 [STALLCTLR]
0740
0741
0742 **bit (23):**
0743 ETM_MODE_INSTPRIO
0744
0745 **description:**
0746 Set to enable the INSTPRIORITY bit in the stall control register
0747 [STALLCTLR] , if supported [IDR0].
0748
0749
0750 **bit (24):**
0751 ETM_MODE_NOOVERFLOW
0752
0753 **description:**
0754 Set to enable the NOOVERFLOW bit in the stall control register
0755 [STALLCTLR], if supported [IDR3].
0756
0757
0758 **bit (25):**
0759 ETM_MODE_TRACE_RESET
0760
0761 **description:**
0762 Set to enable the TRCRESET bit in the viewinst control register
0763 [VICTLR] , if supported [IDR3].
0764
0765
0766 **bit (26):**
0767 ETM_MODE_TRACE_ERR
0768
0769 **description:**
0770 Set to enable the TRCCTRL bit in the viewinst control register
0771 [VICTLR].
0772
0773
0774 **bit (27):**
0775 ETM_MODE_VIEWINST_STARTSTOP
0776
0777 **description:**
0778 Set the initial state value of the ViewInst start / stop logic
0779 in the viewinst control register [VICTLR]
0780
0781
0782 **bit (30):**
0783 ETM_MODE_EXCL_KERN
0784
0785 **description:**
0786 Set default trace setup to exclude kernel mode trace (see note a)
0787
0788
0789 **bit (31):**
0790 ETM_MODE_EXCL_USER
0791
0792 **description:**
0793 Set default trace setup to exclude user space trace (see note a)
0794
0795 ----
0796
0797 *Note a)* On startup the ETM is programmed to trace the complete address space
0798 using address range comparator 0. ‘mode’ bits 30 / 31 modify this setting to
0799 set EL exclude bits for NS state in either user space (EL0) or kernel space
0800 (EL1) in the address range comparator. (the default setting excludes all
0801 secure EL, and NS EL2)
0802
0803 Once the reset parameter has been used, and/or custom programming has been
0804 implemented - using these bits will result in the EL bits for address
0805 comparator 0 being set in the same way.
0806
0807 *Note b)* Bits 2-3, 8-10, 15-16, 18, 22, control features that only work with
0808 data trace. As A-profile data trace is architecturally prohibited in ETMv4,
0809 these have been omitted here. Possible uses could be where a kernel has
0810 support for control of R or M profile infrastructure as part of a heterogeneous
0811 system.
0812
0813 Bits 17, 28-29 are unused.