arm-spe-decoder.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * arm_spe_decoder.h: Arm Statistical Profiling Extensions support
  4. * Copyright (c) 2019-2020, Arm Ltd.
  5. */
  6. #ifndef INCLUDE__ARM_SPE_DECODER_H__
  7. #define INCLUDE__ARM_SPE_DECODER_H__
  8. #include <stdbool.h>
  9. #include <stddef.h>
  10. #include <stdint.h>
  11. #include "arm-spe-pkt-decoder.h"
  12. #define ARM_SPE_L1D_ACCESS BIT(EV_L1D_ACCESS)
  13. #define ARM_SPE_L1D_MISS BIT(EV_L1D_REFILL)
  14. #define ARM_SPE_LLC_ACCESS BIT(EV_LLC_ACCESS)
  15. #define ARM_SPE_LLC_MISS BIT(EV_LLC_MISS)
  16. #define ARM_SPE_TLB_ACCESS BIT(EV_TLB_ACCESS)
  17. #define ARM_SPE_TLB_MISS BIT(EV_TLB_WALK)
  18. #define ARM_SPE_BRANCH_MISS BIT(EV_MISPRED)
  19. #define ARM_SPE_BRANCH_NOT_TAKEN BIT(EV_NOT_TAKEN)
  20. #define ARM_SPE_REMOTE_ACCESS BIT(EV_REMOTE_ACCESS)
  21. #define ARM_SPE_SVE_PARTIAL_PRED BIT(EV_PARTIAL_PREDICATE)
  22. #define ARM_SPE_SVE_EMPTY_PRED BIT(EV_EMPTY_PREDICATE)
  23. #define ARM_SPE_IN_TXN BIT(EV_TRANSACTIONAL)
  24. #define ARM_SPE_L2D_ACCESS BIT(EV_L2D_ACCESS)
  25. #define ARM_SPE_L2D_MISS BIT(EV_L2D_MISS)
  26. #define ARM_SPE_RECENTLY_FETCHED BIT(EV_RECENTLY_FETCHED)
  27. #define ARM_SPE_DATA_SNOOPED BIT(EV_DATA_SNOOPED)
  28. #define ARM_SPE_HITM BIT(EV_CACHE_DATA_MODIFIED)
  29. enum arm_spe_op_type {
  30. /* First level operation type */
  31. ARM_SPE_OP_OTHER = 1 << 0,
  32. ARM_SPE_OP_LDST = 1 << 1,
  33. ARM_SPE_OP_BRANCH_ERET = 1 << 2,
  34. };
  35. enum arm_spe_2nd_op_ldst {
  36. ARM_SPE_OP_GP_REG = 1 << 8,
  37. ARM_SPE_OP_UNSPEC_REG = 1 << 9,
  38. ARM_SPE_OP_NV_SYSREG = 1 << 10,
  39. ARM_SPE_OP_SIMD_FP = 1 << 11,
  40. ARM_SPE_OP_SVE = 1 << 12,
  41. ARM_SPE_OP_MTE_TAG = 1 << 13,
  42. ARM_SPE_OP_MEMCPY = 1 << 14,
  43. ARM_SPE_OP_MEMSET = 1 << 15,
  44. ARM_SPE_OP_GCS = 1 << 16,
  45. ARM_SPE_OP_SME = 1 << 17,
  46. ARM_SPE_OP_ASE = 1 << 18,
  47. /* Assisted information for memory / SIMD */
  48. ARM_SPE_OP_LD = 1 << 20,
  49. ARM_SPE_OP_ST = 1 << 21,
  50. ARM_SPE_OP_ATOMIC = 1 << 22,
  51. ARM_SPE_OP_EXCL = 1 << 23,
  52. ARM_SPE_OP_AR = 1 << 24,
  53. ARM_SPE_OP_DP = 1 << 25, /* Data processing */
  54. ARM_SPE_OP_PRED = 1 << 26, /* Predicated */
  55. ARM_SPE_OP_SG = 1 << 27, /* Gather/Scatter */
  56. ARM_SPE_OP_COMM = 1 << 28, /* Common */
  57. ARM_SPE_OP_FP = 1 << 29, /* Floating-point */
  58. ARM_SPE_OP_COND = 1 << 30, /* Conditional */
  59. };
  60. enum arm_spe_2nd_op_branch {
  61. ARM_SPE_OP_BR_COND = 1 << 8,
  62. ARM_SPE_OP_BR_INDIRECT = 1 << 9,
  63. ARM_SPE_OP_BR_GCS = 1 << 10,
  64. ARM_SPE_OP_BR_CR_BL = 1 << 11,
  65. ARM_SPE_OP_BR_CR_RET = 1 << 12,
  66. ARM_SPE_OP_BR_CR_NON_BL_RET = 1 << 13,
  67. };
  68. enum arm_spe_common_data_source {
  69. ARM_SPE_COMMON_DS_L1D = 0x0,
  70. ARM_SPE_COMMON_DS_L2 = 0x8,
  71. ARM_SPE_COMMON_DS_PEER_CORE = 0x9,
  72. ARM_SPE_COMMON_DS_LOCAL_CLUSTER = 0xa,
  73. ARM_SPE_COMMON_DS_SYS_CACHE = 0xb,
  74. ARM_SPE_COMMON_DS_PEER_CLUSTER = 0xc,
  75. ARM_SPE_COMMON_DS_REMOTE = 0xd,
  76. ARM_SPE_COMMON_DS_DRAM = 0xe,
  77. };
  78. enum arm_spe_ampereone_data_source {
  79. ARM_SPE_AMPEREONE_LOCAL_CHIP_CACHE_OR_DEVICE = 0x0,
  80. ARM_SPE_AMPEREONE_SLC = 0x3,
  81. ARM_SPE_AMPEREONE_REMOTE_CHIP_CACHE = 0x5,
  82. ARM_SPE_AMPEREONE_DDR = 0x7,
  83. ARM_SPE_AMPEREONE_L1D = 0x8,
  84. ARM_SPE_AMPEREONE_L2D = 0x9,
  85. };
  86. enum arm_spe_hisi_hip_data_source {
  87. ARM_SPE_HISI_HIP_PEER_CPU = 0,
  88. ARM_SPE_HISI_HIP_PEER_CPU_HITM = 1,
  89. ARM_SPE_HISI_HIP_L3 = 2,
  90. ARM_SPE_HISI_HIP_L3_HITM = 3,
  91. ARM_SPE_HISI_HIP_PEER_CLUSTER = 4,
  92. ARM_SPE_HISI_HIP_PEER_CLUSTER_HITM = 5,
  93. ARM_SPE_HISI_HIP_REMOTE_SOCKET = 6,
  94. ARM_SPE_HISI_HIP_REMOTE_SOCKET_HITM = 7,
  95. ARM_SPE_HISI_HIP_LOCAL_MEM = 8,
  96. ARM_SPE_HISI_HIP_REMOTE_MEM = 9,
  97. ARM_SPE_HISI_HIP_NC_DEV = 13,
  98. ARM_SPE_HISI_HIP_L2 = 16,
  99. ARM_SPE_HISI_HIP_L2_HITM = 17,
  100. ARM_SPE_HISI_HIP_L1 = 18,
  101. };
  102. struct arm_spe_record {
  103. u64 type;
  104. int err;
  105. u32 op;
  106. u32 latency;
  107. u64 from_ip;
  108. u64 to_ip;
  109. u64 prev_br_tgt;
  110. u64 timestamp;
  111. u64 virt_addr;
  112. u64 phys_addr;
  113. u64 context_id;
  114. u16 source;
  115. };
  116. struct arm_spe_insn;
  117. struct arm_spe_buffer {
  118. const unsigned char *buf;
  119. size_t len;
  120. u64 offset;
  121. u64 trace_nr;
  122. };
  123. struct arm_spe_params {
  124. int (*get_trace)(struct arm_spe_buffer *buffer, void *data);
  125. void *data;
  126. };
  127. struct arm_spe_decoder {
  128. int (*get_trace)(struct arm_spe_buffer *buffer, void *data);
  129. void *data;
  130. struct arm_spe_record record;
  131. const unsigned char *buf;
  132. size_t len;
  133. struct arm_spe_pkt packet;
  134. };
  135. struct arm_spe_decoder *arm_spe_decoder_new(struct arm_spe_params *params);
  136. void arm_spe_decoder_free(struct arm_spe_decoder *decoder);
  137. int arm_spe_decode(struct arm_spe_decoder *decoder);
  138. #endif