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 7#ifndef INCLUDE__ARM_SPE_DECODER_H__ 8#define INCLUDE__ARM_SPE_DECODER_H__ 9 10#include <stdbool.h> 11#include <stddef.h> 12#include <stdint.h> 13 14#include "arm-spe-pkt-decoder.h" 15 16enum arm_spe_sample_type { 17 ARM_SPE_L1D_ACCESS = 1 << 0, 18 ARM_SPE_L1D_MISS = 1 << 1, 19 ARM_SPE_LLC_ACCESS = 1 << 2, 20 ARM_SPE_LLC_MISS = 1 << 3, 21 ARM_SPE_TLB_ACCESS = 1 << 4, 22 ARM_SPE_TLB_MISS = 1 << 5, 23 ARM_SPE_BRANCH_MISS = 1 << 6, 24 ARM_SPE_REMOTE_ACCESS = 1 << 7, 25}; 26 27enum arm_spe_op_type { 28 ARM_SPE_LD = 1 << 0, 29 ARM_SPE_ST = 1 << 1, 30}; 31 32enum arm_spe_neoverse_data_source { 33 ARM_SPE_NV_L1D = 0x0, 34 ARM_SPE_NV_L2 = 0x8, 35 ARM_SPE_NV_PEER_CORE = 0x9, 36 ARM_SPE_NV_LOCAL_CLUSTER = 0xa, 37 ARM_SPE_NV_SYS_CACHE = 0xb, 38 ARM_SPE_NV_PEER_CLUSTER = 0xc, 39 ARM_SPE_NV_REMOTE = 0xd, 40 ARM_SPE_NV_DRAM = 0xe, 41}; 42 43struct arm_spe_record { 44 enum arm_spe_sample_type type; 45 int err; 46 u32 op; 47 u32 latency; 48 u64 from_ip; 49 u64 to_ip; 50 u64 timestamp; 51 u64 virt_addr; 52 u64 phys_addr; 53 u64 context_id; 54 u16 source; 55}; 56 57struct arm_spe_insn; 58 59struct arm_spe_buffer { 60 const unsigned char *buf; 61 size_t len; 62 u64 offset; 63 u64 trace_nr; 64}; 65 66struct arm_spe_params { 67 int (*get_trace)(struct arm_spe_buffer *buffer, void *data); 68 void *data; 69}; 70 71struct arm_spe_decoder { 72 int (*get_trace)(struct arm_spe_buffer *buffer, void *data); 73 void *data; 74 struct arm_spe_record record; 75 76 const unsigned char *buf; 77 size_t len; 78 79 struct arm_spe_pkt packet; 80}; 81 82struct arm_spe_decoder *arm_spe_decoder_new(struct arm_spe_params *params); 83void arm_spe_decoder_free(struct arm_spe_decoder *decoder); 84 85int arm_spe_decode(struct arm_spe_decoder *decoder); 86 87#endif