intel/decoder: Engine parameter for instructions
[mesa.git] / src / intel / common / gen_decoder.h
1 /*
2 * Copyright © 2016 Intel Corporation
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21 * IN THE SOFTWARE.
22 */
23
24 #ifndef GEN_DECODER_H
25 #define GEN_DECODER_H
26
27 #include <stdint.h>
28 #include <stdbool.h>
29 #include <stdio.h>
30
31 #include "dev/gen_device_info.h"
32 #include "util/hash_table.h"
33 #include "util/bitset.h"
34
35 #include "drm-uapi/i915_drm.h"
36
37 #ifdef __cplusplus
38 extern "C" {
39 #endif
40
41 struct gen_spec;
42 struct gen_group;
43 struct gen_field;
44 union gen_field_value;
45
46 #define I915_ENGINE_CLASS_TO_MASK(x) BITSET_BIT(x)
47
48 static inline uint32_t gen_make_gen(uint32_t major, uint32_t minor)
49 {
50 return (major << 8) | minor;
51 }
52
53 struct gen_group *gen_spec_find_struct(struct gen_spec *spec, const char *name);
54 struct gen_spec *gen_spec_load(const struct gen_device_info *devinfo);
55 struct gen_spec *gen_spec_load_from_path(const struct gen_device_info *devinfo,
56 const char *path);
57 void gen_spec_destroy(struct gen_spec *spec);
58 uint32_t gen_spec_get_gen(struct gen_spec *spec);
59 struct gen_group *gen_spec_find_instruction(struct gen_spec *spec, const uint32_t *p);
60 struct gen_group *gen_spec_find_register(struct gen_spec *spec, uint32_t offset);
61 struct gen_group *gen_spec_find_register_by_name(struct gen_spec *spec, const char *name);
62 struct gen_enum *gen_spec_find_enum(struct gen_spec *spec, const char *name);
63
64 int gen_group_get_length(struct gen_group *group, const uint32_t *p);
65 const char *gen_group_get_name(struct gen_group *group);
66 uint32_t gen_group_get_opcode(struct gen_group *group);
67 struct gen_field *gen_group_find_field(struct gen_group *group, const char *name);
68 struct gen_enum *gen_spec_find_enum(struct gen_spec *spec, const char *name);
69
70 bool gen_field_is_header(struct gen_field *field);
71
72 struct gen_field_iterator {
73 struct gen_group *group;
74 char name[128];
75 char value[128];
76 uint64_t raw_value;
77 struct gen_group *struct_desc;
78 const uint32_t *p;
79 int p_bit; /**< bit offset into p */
80 const uint32_t *p_end;
81 int start_bit; /**< current field starts at this bit offset into p */
82 int end_bit; /**< current field ends at this bit offset into p */
83
84 int group_iter;
85
86 struct gen_field *field;
87 bool print_colors;
88 };
89
90 struct gen_spec {
91 uint32_t gen;
92
93 struct hash_table *commands;
94 struct hash_table *structs;
95 struct hash_table *registers_by_name;
96 struct hash_table *registers_by_offset;
97 struct hash_table *enums;
98
99 struct hash_table *access_cache;
100 };
101
102 struct gen_group {
103 struct gen_spec *spec;
104 char *name;
105
106 struct gen_field *fields; /* linked list of fields */
107 struct gen_field *dword_length_field; /* <instruction> specific */
108
109 uint32_t dw_length;
110 uint32_t engine_mask; /* <instruction> specific */
111 uint32_t bias; /* <instruction> specific */
112 uint32_t group_offset, group_count;
113 uint32_t group_size;
114 bool variable; /* <group> specific */
115 bool fixed_length; /* True for <struct> & <register> */
116
117 struct gen_group *parent;
118 struct gen_group *next;
119
120 uint32_t opcode_mask;
121 uint32_t opcode;
122
123 uint32_t register_offset; /* <register> specific */
124 };
125
126 struct gen_value {
127 char *name;
128 uint64_t value;
129 };
130
131 struct gen_enum {
132 char *name;
133 int nvalues;
134 struct gen_value **values;
135 };
136
137 struct gen_type {
138 enum {
139 GEN_TYPE_UNKNOWN,
140 GEN_TYPE_INT,
141 GEN_TYPE_UINT,
142 GEN_TYPE_BOOL,
143 GEN_TYPE_FLOAT,
144 GEN_TYPE_ADDRESS,
145 GEN_TYPE_OFFSET,
146 GEN_TYPE_STRUCT,
147 GEN_TYPE_UFIXED,
148 GEN_TYPE_SFIXED,
149 GEN_TYPE_MBO,
150 GEN_TYPE_ENUM
151 } kind;
152
153 /* Struct definition for GEN_TYPE_STRUCT */
154 union {
155 struct gen_group *gen_struct;
156 struct gen_enum *gen_enum;
157 struct {
158 /* Integer and fractional sizes for GEN_TYPE_UFIXED and GEN_TYPE_SFIXED */
159 int i, f;
160 };
161 };
162 };
163
164 union gen_field_value {
165 bool b32;
166 float f32;
167 uint64_t u64;
168 int64_t i64;
169 };
170
171 struct gen_field {
172 struct gen_group *parent;
173 struct gen_field *next;
174
175 char *name;
176 int start, end;
177 struct gen_type type;
178 bool has_default;
179 uint32_t default_value;
180
181 struct gen_enum inline_enum;
182 };
183
184 void gen_field_iterator_init(struct gen_field_iterator *iter,
185 struct gen_group *group,
186 const uint32_t *p, int p_bit,
187 bool print_colors);
188
189 bool gen_field_iterator_next(struct gen_field_iterator *iter);
190
191 void gen_print_group(FILE *out,
192 struct gen_group *group,
193 uint64_t offset, const uint32_t *p, int p_bit,
194 bool color);
195
196 enum gen_batch_decode_flags {
197 /** Print in color! */
198 GEN_BATCH_DECODE_IN_COLOR = (1 << 0),
199 /** Print everything, not just headers */
200 GEN_BATCH_DECODE_FULL = (1 << 1),
201 /** Print offsets along with the batch */
202 GEN_BATCH_DECODE_OFFSETS = (1 << 2),
203 /** Guess when a value is a float and print it as such */
204 GEN_BATCH_DECODE_FLOATS = (1 << 3),
205 };
206
207 struct gen_batch_decode_bo {
208 uint64_t addr;
209 uint32_t size;
210 const void *map;
211 };
212
213 struct gen_batch_decode_ctx {
214 /**
215 * Return information about the buffer containing the given address.
216 *
217 * If the given address is inside a buffer, the map pointer should be
218 * offset accordingly so it points at the data corresponding to address.
219 */
220 struct gen_batch_decode_bo (*get_bo)(void *user_data, uint64_t address);
221 unsigned (*get_state_size)(void *user_data,
222 uint32_t offset_from_dynamic_state_base_addr);
223 void *user_data;
224
225 FILE *fp;
226 struct gen_spec *spec;
227 enum gen_batch_decode_flags flags;
228
229 struct gen_disasm *disasm;
230
231 uint64_t surface_base;
232 uint64_t dynamic_base;
233 uint64_t instruction_base;
234
235 int max_vbo_decoded_lines;
236 };
237
238 void gen_batch_decode_ctx_init(struct gen_batch_decode_ctx *ctx,
239 const struct gen_device_info *devinfo,
240 FILE *fp, enum gen_batch_decode_flags flags,
241 const char *xml_path,
242 struct gen_batch_decode_bo (*get_bo)(void *,
243 uint64_t),
244
245 unsigned (*get_state_size)(void *, uint32_t),
246 void *user_data);
247 void gen_batch_decode_ctx_finish(struct gen_batch_decode_ctx *ctx);
248
249
250 void gen_print_batch(struct gen_batch_decode_ctx *ctx,
251 const uint32_t *batch, uint32_t batch_size,
252 uint64_t batch_addr);
253
254 #ifdef __cplusplus
255 }
256 #endif
257
258
259 #endif /* GEN_DECODER_H */