blob: 56cc47baca11e42de1730e9795d9b4e42e07f2e5 [file] [log] [blame]
Adrian Hunterf4aa0812015-07-17 19:33:40 +03001/*
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)
28
29enum intel_pt_sample_type {
30 INTEL_PT_BRANCH = 1 << 0,
31 INTEL_PT_INSTRUCTION = 1 << 1,
32 INTEL_PT_TRANSACTION = 1 << 2,
33};
34
35enum intel_pt_period_type {
36 INTEL_PT_PERIOD_NONE,
37 INTEL_PT_PERIOD_INSTRUCTIONS,
38 INTEL_PT_PERIOD_TICKS,
39};
40
41enum {
42 INTEL_PT_ERR_NOMEM = 1,
43 INTEL_PT_ERR_INTERN,
44 INTEL_PT_ERR_BADPKT,
45 INTEL_PT_ERR_NODATA,
46 INTEL_PT_ERR_NOINSN,
47 INTEL_PT_ERR_MISMAT,
48 INTEL_PT_ERR_OVR,
49 INTEL_PT_ERR_LOST,
50 INTEL_PT_ERR_UNK,
51 INTEL_PT_ERR_NELOOP,
52 INTEL_PT_ERR_MAX,
53};
54
55struct intel_pt_state {
56 enum intel_pt_sample_type type;
57 int err;
58 uint64_t from_ip;
59 uint64_t to_ip;
60 uint64_t cr3;
Adrian Hunter2a21d032015-07-17 19:33:48 +030061 uint64_t tot_insn_cnt;
Adrian Hunterf4aa0812015-07-17 19:33:40 +030062 uint64_t timestamp;
63 uint64_t est_timestamp;
64 uint64_t trace_nr;
65 uint32_t flags;
66 enum intel_pt_insn_op insn_op;
67 int insn_len;
68};
69
70struct intel_pt_insn;
71
72struct intel_pt_buffer {
73 const unsigned char *buf;
74 size_t len;
75 bool consecutive;
76 uint64_t ref_timestamp;
77 uint64_t trace_nr;
78};
79
80struct intel_pt_params {
81 int (*get_trace)(struct intel_pt_buffer *buffer, void *data);
82 int (*walk_insn)(struct intel_pt_insn *intel_pt_insn,
83 uint64_t *insn_cnt_ptr, uint64_t *ip, uint64_t to_ip,
84 uint64_t max_insn_cnt, void *data);
85 void *data;
86 bool return_compression;
87 uint64_t period;
88 enum intel_pt_period_type period_type;
89 unsigned max_non_turbo_ratio;
Adrian Hunter11fa7cb2015-07-17 19:33:54 +030090 unsigned int mtc_period;
91 uint32_t tsc_ctc_ratio_n;
92 uint32_t tsc_ctc_ratio_d;
Adrian Hunterf4aa0812015-07-17 19:33:40 +030093};
94
95struct intel_pt_decoder;
96
97struct intel_pt_decoder *intel_pt_decoder_new(struct intel_pt_params *params);
98void intel_pt_decoder_free(struct intel_pt_decoder *decoder);
99
100const struct intel_pt_state *intel_pt_decode(struct intel_pt_decoder *decoder);
101
102unsigned char *intel_pt_find_overlap(unsigned char *buf_a, size_t len_a,
103 unsigned char *buf_b, size_t len_b,
104 bool have_tsc);
105
106int intel_pt__strerror(int code, char *buf, size_t buflen);
107
108#endif