Adrian Hunter | f4aa081 | 2015-07-17 19:33:40 +0300 | [diff] [blame] | 1 | /* |
| 2 | * intel_pt_decoder.h: Intel Processor Trace support |
| 3 | * Copyright (c) 2013-2014, Intel Corporation. |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify it |
| 6 | * under the terms and conditions of the GNU General Public License, |
| 7 | * version 2, as published by the Free Software Foundation. |
| 8 | * |
| 9 | * This program is distributed in the hope it will be useful, but WITHOUT |
| 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
| 12 | * more details. |
| 13 | * |
| 14 | */ |
| 15 | |
| 16 | #ifndef INCLUDE__INTEL_PT_DECODER_H__ |
| 17 | #define INCLUDE__INTEL_PT_DECODER_H__ |
| 18 | |
| 19 | #include <stdint.h> |
| 20 | #include <stddef.h> |
| 21 | #include <stdbool.h> |
| 22 | |
| 23 | #include "intel-pt-insn-decoder.h" |
| 24 | |
| 25 | #define INTEL_PT_IN_TX (1 << 0) |
| 26 | #define INTEL_PT_ABORT_TX (1 << 1) |
| 27 | #define INTEL_PT_ASYNC (1 << 2) |
Adrian Hunter | a472e65 | 2017-05-26 11:17:14 +0300 | [diff] [blame] | 28 | #define INTEL_PT_FUP_IP (1 << 3) |
Adrian Hunter | f4aa081 | 2015-07-17 19:33:40 +0300 | [diff] [blame] | 29 | |
| 30 | enum intel_pt_sample_type { |
| 31 | INTEL_PT_BRANCH = 1 << 0, |
| 32 | INTEL_PT_INSTRUCTION = 1 << 1, |
| 33 | INTEL_PT_TRANSACTION = 1 << 2, |
Adrian Hunter | a472e65 | 2017-05-26 11:17:14 +0300 | [diff] [blame] | 34 | INTEL_PT_PTW = 1 << 3, |
| 35 | INTEL_PT_MWAIT_OP = 1 << 4, |
| 36 | INTEL_PT_PWR_ENTRY = 1 << 5, |
| 37 | INTEL_PT_EX_STOP = 1 << 6, |
| 38 | INTEL_PT_PWR_EXIT = 1 << 7, |
Adrian Hunter | 0a7c700d | 2017-05-26 11:17:16 +0300 | [diff] [blame] | 39 | INTEL_PT_CBR_CHG = 1 << 8, |
Adrian Hunter | f4aa081 | 2015-07-17 19:33:40 +0300 | [diff] [blame] | 40 | }; |
| 41 | |
| 42 | enum intel_pt_period_type { |
| 43 | INTEL_PT_PERIOD_NONE, |
| 44 | INTEL_PT_PERIOD_INSTRUCTIONS, |
| 45 | INTEL_PT_PERIOD_TICKS, |
Adrian Hunter | 79b5842 | 2015-07-17 19:33:55 +0300 | [diff] [blame] | 46 | INTEL_PT_PERIOD_MTC, |
Adrian Hunter | f4aa081 | 2015-07-17 19:33:40 +0300 | [diff] [blame] | 47 | }; |
| 48 | |
| 49 | enum { |
| 50 | INTEL_PT_ERR_NOMEM = 1, |
| 51 | INTEL_PT_ERR_INTERN, |
| 52 | INTEL_PT_ERR_BADPKT, |
| 53 | INTEL_PT_ERR_NODATA, |
| 54 | INTEL_PT_ERR_NOINSN, |
| 55 | INTEL_PT_ERR_MISMAT, |
| 56 | INTEL_PT_ERR_OVR, |
| 57 | INTEL_PT_ERR_LOST, |
| 58 | INTEL_PT_ERR_UNK, |
| 59 | INTEL_PT_ERR_NELOOP, |
| 60 | INTEL_PT_ERR_MAX, |
| 61 | }; |
| 62 | |
| 63 | struct intel_pt_state { |
| 64 | enum intel_pt_sample_type type; |
| 65 | int err; |
| 66 | uint64_t from_ip; |
| 67 | uint64_t to_ip; |
| 68 | uint64_t cr3; |
Adrian Hunter | 2a21d03 | 2015-07-17 19:33:48 +0300 | [diff] [blame] | 69 | uint64_t tot_insn_cnt; |
Adrian Hunter | f4aa081 | 2015-07-17 19:33:40 +0300 | [diff] [blame] | 70 | uint64_t timestamp; |
| 71 | uint64_t est_timestamp; |
| 72 | uint64_t trace_nr; |
Adrian Hunter | a472e65 | 2017-05-26 11:17:14 +0300 | [diff] [blame] | 73 | uint64_t ptw_payload; |
| 74 | uint64_t mwait_payload; |
| 75 | uint64_t pwre_payload; |
| 76 | uint64_t pwrx_payload; |
Adrian Hunter | 0a7c700d | 2017-05-26 11:17:16 +0300 | [diff] [blame] | 77 | uint64_t cbr_payload; |
Adrian Hunter | f4aa081 | 2015-07-17 19:33:40 +0300 | [diff] [blame] | 78 | uint32_t flags; |
| 79 | enum intel_pt_insn_op insn_op; |
| 80 | int insn_len; |
Andi Kleen | faaa876 | 2016-10-07 16:42:26 +0300 | [diff] [blame] | 81 | char insn[INTEL_PT_INSN_BUF_SZ]; |
Adrian Hunter | f4aa081 | 2015-07-17 19:33:40 +0300 | [diff] [blame] | 82 | }; |
| 83 | |
| 84 | struct intel_pt_insn; |
| 85 | |
| 86 | struct intel_pt_buffer { |
| 87 | const unsigned char *buf; |
| 88 | size_t len; |
| 89 | bool consecutive; |
| 90 | uint64_t ref_timestamp; |
| 91 | uint64_t trace_nr; |
| 92 | }; |
| 93 | |
| 94 | struct intel_pt_params { |
| 95 | int (*get_trace)(struct intel_pt_buffer *buffer, void *data); |
| 96 | int (*walk_insn)(struct intel_pt_insn *intel_pt_insn, |
| 97 | uint64_t *insn_cnt_ptr, uint64_t *ip, uint64_t to_ip, |
| 98 | uint64_t max_insn_cnt, void *data); |
Adrian Hunter | 9f1d122 | 2016-09-23 17:38:47 +0300 | [diff] [blame] | 99 | bool (*pgd_ip)(uint64_t ip, void *data); |
Adrian Hunter | f4aa081 | 2015-07-17 19:33:40 +0300 | [diff] [blame] | 100 | void *data; |
| 101 | bool return_compression; |
Adrian Hunter | 8395981 | 2017-05-26 11:17:11 +0300 | [diff] [blame] | 102 | bool branch_enable; |
Adrian Hunter | f4aa081 | 2015-07-17 19:33:40 +0300 | [diff] [blame] | 103 | uint64_t period; |
| 104 | enum intel_pt_period_type period_type; |
| 105 | unsigned max_non_turbo_ratio; |
Adrian Hunter | 11fa7cb | 2015-07-17 19:33:54 +0300 | [diff] [blame] | 106 | unsigned int mtc_period; |
| 107 | uint32_t tsc_ctc_ratio_n; |
| 108 | uint32_t tsc_ctc_ratio_d; |
Adrian Hunter | f4aa081 | 2015-07-17 19:33:40 +0300 | [diff] [blame] | 109 | }; |
| 110 | |
| 111 | struct intel_pt_decoder; |
| 112 | |
| 113 | struct intel_pt_decoder *intel_pt_decoder_new(struct intel_pt_params *params); |
| 114 | void intel_pt_decoder_free(struct intel_pt_decoder *decoder); |
| 115 | |
| 116 | const struct intel_pt_state *intel_pt_decode(struct intel_pt_decoder *decoder); |
| 117 | |
| 118 | unsigned char *intel_pt_find_overlap(unsigned char *buf_a, size_t len_a, |
| 119 | unsigned char *buf_b, size_t len_b, |
Adrian Hunter | 117db4b | 2018-03-07 16:02:21 +0200 | [diff] [blame] | 120 | bool have_tsc, bool *consecutive); |
Adrian Hunter | f4aa081 | 2015-07-17 19:33:40 +0300 | [diff] [blame] | 121 | |
| 122 | int intel_pt__strerror(int code, char *buf, size_t buflen); |
| 123 | |
| 124 | #endif |