xref: /freebsd/contrib/processor-trace/libipt/internal/include/pt_query_decoder.h (revision 7fdf597e96a02165cfe22ff357b857d5fa15ed8a)
1 /*
2  * Copyright (c) 2014-2019, Intel Corporation
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are met:
6  *
7  *  * Redistributions of source code must retain the above copyright notice,
8  *    this list of conditions and the following disclaimer.
9  *  * Redistributions in binary form must reproduce the above copyright notice,
10  *    this list of conditions and the following disclaimer in the documentation
11  *    and/or other materials provided with the distribution.
12  *  * Neither the name of Intel Corporation nor the names of its contributors
13  *    may be used to endorse or promote products derived from this software
14  *    without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
20  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26  * POSSIBILITY OF SUCH DAMAGE.
27  */
28 
29 #ifndef PT_QUERY_DECODER_H
30 #define PT_QUERY_DECODER_H
31 
32 #include "pt_last_ip.h"
33 #include "pt_tnt_cache.h"
34 #include "pt_time.h"
35 #include "pt_event_queue.h"
36 
37 #include "intel-pt.h"
38 
39 struct pt_decoder_function;
40 
41 
42 /* An Intel PT query decoder. */
43 struct pt_query_decoder {
44 	/* The decoder configuration. */
45 	struct pt_config config;
46 
47 	/* The current position in the trace buffer. */
48 	const uint8_t *pos;
49 
50 	/* The position of the last PSB packet. */
51 	const uint8_t *sync;
52 
53 	/* The decoding function for the next packet. */
54 	const struct pt_decoder_function *next;
55 
56 	/* The last-ip. */
57 	struct pt_last_ip ip;
58 
59 	/* The cached tnt indicators. */
60 	struct pt_tnt_cache tnt;
61 
62 	/* Timing information. */
63 	struct pt_time time;
64 
65 	/* The time at the last query (before reading ahead). */
66 	struct pt_time last_time;
67 
68 	/* Timing calibration. */
69 	struct pt_time_cal tcal;
70 
71 	/* Pending (incomplete) events. */
72 	struct pt_event_queue evq;
73 
74 	/* The current event. */
75 	struct pt_event *event;
76 
77 	/* A collection of flags relevant for decoding:
78 	 *
79 	 * - tracing is enabled.
80 	 */
81 	uint32_t enabled:1;
82 
83 	/* - consume the current packet. */
84 	uint32_t consume_packet:1;
85 };
86 
87 /* Initialize the query decoder.
88  *
89  * Returns zero on success, a negative error code otherwise.
90  */
91 extern int pt_qry_decoder_init(struct pt_query_decoder *,
92 			       const struct pt_config *);
93 
94 /* Finalize the query decoder. */
95 extern void pt_qry_decoder_fini(struct pt_query_decoder *);
96 
97 /* Decoder functions (tracing context). */
98 extern int pt_qry_decode_unknown(struct pt_query_decoder *);
99 extern int pt_qry_decode_pad(struct pt_query_decoder *);
100 extern int pt_qry_decode_psb(struct pt_query_decoder *);
101 extern int pt_qry_decode_tip(struct pt_query_decoder *);
102 extern int pt_qry_decode_tnt_8(struct pt_query_decoder *);
103 extern int pt_qry_decode_tnt_64(struct pt_query_decoder *);
104 extern int pt_qry_decode_tip_pge(struct pt_query_decoder *);
105 extern int pt_qry_decode_tip_pgd(struct pt_query_decoder *);
106 extern int pt_qry_decode_fup(struct pt_query_decoder *);
107 extern int pt_qry_decode_pip(struct pt_query_decoder *);
108 extern int pt_qry_decode_ovf(struct pt_query_decoder *);
109 extern int pt_qry_decode_mode(struct pt_query_decoder *);
110 extern int pt_qry_decode_psbend(struct pt_query_decoder *);
111 extern int pt_qry_decode_tsc(struct pt_query_decoder *);
112 extern int pt_qry_header_tsc(struct pt_query_decoder *);
113 extern int pt_qry_decode_cbr(struct pt_query_decoder *);
114 extern int pt_qry_header_cbr(struct pt_query_decoder *);
115 extern int pt_qry_decode_tma(struct pt_query_decoder *);
116 extern int pt_qry_decode_mtc(struct pt_query_decoder *);
117 extern int pt_qry_decode_cyc(struct pt_query_decoder *);
118 extern int pt_qry_decode_stop(struct pt_query_decoder *);
119 extern int pt_qry_decode_vmcs(struct pt_query_decoder *);
120 extern int pt_qry_decode_mnt(struct pt_query_decoder *);
121 extern int pt_qry_decode_exstop(struct pt_query_decoder *);
122 extern int pt_qry_decode_mwait(struct pt_query_decoder *);
123 extern int pt_qry_decode_pwre(struct pt_query_decoder *);
124 extern int pt_qry_decode_pwrx(struct pt_query_decoder *);
125 extern int pt_qry_decode_ptw(struct pt_query_decoder *);
126 
127 /* Decoder functions (header context). */
128 extern int pt_qry_header_fup(struct pt_query_decoder *);
129 extern int pt_qry_header_pip(struct pt_query_decoder *);
130 extern int pt_qry_header_mode(struct pt_query_decoder *);
131 extern int pt_qry_header_vmcs(struct pt_query_decoder *);
132 extern int pt_qry_header_mnt(struct pt_query_decoder *);
133 
134 #endif /* PT_QUERY_DECODER_H */
135