1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  * Arm Statistical Profiling Extensions (SPE) support
4  * Copyright (c) 2017-2018, Arm Ltd.
5  */
6 
7 #ifndef INCLUDE__ARM_SPE_PKT_DECODER_H__
8 #define INCLUDE__ARM_SPE_PKT_DECODER_H__
9 
10 #include <stddef.h>
11 #include <stdint.h>
12 
13 #define ARM_SPE_PKT_DESC_MAX		256
14 
15 #define ARM_SPE_NEED_MORE_BYTES		-1
16 #define ARM_SPE_BAD_PACKET		-2
17 
18 #define ARM_SPE_PKT_MAX_SZ		16
19 
20 enum arm_spe_pkt_type {
21 	ARM_SPE_BAD,
22 	ARM_SPE_PAD,
23 	ARM_SPE_END,
24 	ARM_SPE_TIMESTAMP,
25 	ARM_SPE_ADDRESS,
26 	ARM_SPE_COUNTER,
27 	ARM_SPE_CONTEXT,
28 	ARM_SPE_OP_TYPE,
29 	ARM_SPE_EVENTS,
30 	ARM_SPE_DATA_SOURCE,
31 };
32 
33 struct arm_spe_pkt {
34 	enum arm_spe_pkt_type	type;
35 	unsigned char		index;
36 	uint64_t		payload;
37 };
38 
39 #define SPE_ADDR_PKT_HDR_INDEX_INS		(0x0)
40 #define SPE_ADDR_PKT_HDR_INDEX_BRANCH		(0x1)
41 #define SPE_ADDR_PKT_HDR_INDEX_DATA_VIRT	(0x2)
42 #define SPE_ADDR_PKT_HDR_INDEX_DATA_PHYS	(0x3)
43 
44 #define SPE_ADDR_PKT_NS				BIT(7)
45 #define SPE_ADDR_PKT_CH				BIT(6)
46 #define SPE_ADDR_PKT_EL_OFFSET			(5)
47 #define SPE_ADDR_PKT_EL_MASK			(0x3 << SPE_ADDR_PKT_EL_OFFSET)
48 #define SPE_ADDR_PKT_EL0			(0)
49 #define SPE_ADDR_PKT_EL1			(1)
50 #define SPE_ADDR_PKT_EL2			(2)
51 #define SPE_ADDR_PKT_EL3			(3)
52 
53 const char *arm_spe_pkt_name(enum arm_spe_pkt_type);
54 
55 int arm_spe_get_packet(const unsigned char *buf, size_t len,
56 		       struct arm_spe_pkt *packet);
57 
58 int arm_spe_pkt_desc(const struct arm_spe_pkt *packet, char *buf, size_t len);
59 #endif
60