intel/compiler: Get rid of the global compaction table pointers
[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 struct gen_spec *gen_spec_load_filename(const char *filename);
58 void gen_spec_destroy(struct gen_spec *spec);
59 uint32_t gen_spec_get_gen(struct gen_spec *spec);
60 struct gen_group *gen_spec_find_instruction(struct gen_spec *spec,
61 enum drm_i915_gem_engine_class engine,
62 const uint32_t *p);
63 struct gen_group *gen_spec_find_register(struct gen_spec *spec, uint32_t offset);
64 struct gen_group *gen_spec_find_register_by_name(struct gen_spec *spec, const char *name);
65 struct gen_enum *gen_spec_find_enum(struct gen_spec *spec, const char *name);
66
67 int gen_group_get_length(struct gen_group *group, const uint32_t *p);
68 const char *gen_group_get_name(struct gen_group *group);
69 uint32_t gen_group_get_opcode(struct gen_group *group);
70 struct gen_field *gen_group_find_field(struct gen_group *group, const char *name);
71 struct gen_enum *gen_spec_find_enum(struct gen_spec *spec, const char *name);
72
73 bool gen_field_is_header(struct gen_field *field);
74
75 /* Only allow 5 levels of subgroup'ing
76 */
77 #define DECODE_MAX_ARRAY_DEPTH 5
78
79 struct gen_field_iterator {
80 struct gen_group *group;
81 char name[128];
82 char value[128];
83 uint64_t raw_value;
84 struct gen_group *struct_desc;
85 const uint32_t *p;
86 int p_bit; /**< bit offset into p */
87 const uint32_t *p_end;
88 int start_bit; /**< current field starts at this bit offset into p */
89 int end_bit; /**< current field ends at this bit offset into p */
90
91 struct gen_field *fields[DECODE_MAX_ARRAY_DEPTH];
92 struct gen_group *groups[DECODE_MAX_ARRAY_DEPTH];
93 int array_iter[DECODE_MAX_ARRAY_DEPTH];
94 int level;
95
96 struct gen_field *field;
97 bool print_colors;
98 };
99
100 struct gen_spec {
101 uint32_t gen;
102
103 struct hash_table *commands;
104 struct hash_table *structs;
105 struct hash_table *registers_by_name;
106 struct hash_table *registers_by_offset;
107 struct hash_table *enums;
108
109 struct hash_table *access_cache;
110 };
111
112 struct gen_group {
113 struct gen_spec *spec;
114 char *name;
115
116 struct gen_field *fields; /* linked list of fields */
117 struct gen_field *dword_length_field; /* <instruction> specific */
118
119 uint32_t dw_length;
120 uint32_t engine_mask; /* <instruction> specific */
121 uint32_t bias; /* <instruction> specific */
122 uint32_t array_offset; /* <group> specific */
123 uint32_t array_count; /* number of elements, <group> specific */
124 uint32_t array_item_size; /* <group> specific */
125 bool variable; /* <group> specific */
126 bool fixed_length; /* True for <struct> & <register> */
127
128 struct gen_group *parent;
129 struct gen_group *next;
130
131 uint32_t opcode_mask;
132 uint32_t opcode;
133
134 uint32_t register_offset; /* <register> specific */
135 };
136
137 struct gen_value {
138 char *name;
139 uint64_t value;
140 };
141
142 struct gen_enum {
143 char *name;
144 int nvalues;
145 struct gen_value **values;
146 };
147
148 struct gen_type {
149 enum {
150 GEN_TYPE_UNKNOWN,
151 GEN_TYPE_INT,
152 GEN_TYPE_UINT,
153 GEN_TYPE_BOOL,
154 GEN_TYPE_FLOAT,
155 GEN_TYPE_ADDRESS,
156 GEN_TYPE_OFFSET,
157 GEN_TYPE_STRUCT,
158 GEN_TYPE_UFIXED,
159 GEN_TYPE_SFIXED,
160 GEN_TYPE_MBO,
161 GEN_TYPE_ENUM
162 } kind;
163
164 /* Struct definition for GEN_TYPE_STRUCT */
165 union {
166 struct gen_group *gen_struct;
167 struct gen_enum *gen_enum;
168 struct {
169 /* Integer and fractional sizes for GEN_TYPE_UFIXED and GEN_TYPE_SFIXED */
170 int i, f;
171 };
172 };
173 };
174
175 union gen_field_value {
176 bool b32;
177 float f32;
178 uint64_t u64;
179 int64_t i64;
180 };
181
182 struct gen_field {
183 struct gen_group *parent;
184 struct gen_field *next;
185 struct gen_group *array;
186
187 char *name;
188 int start, end;
189 struct gen_type type;
190 bool has_default;
191 uint32_t default_value;
192
193 struct gen_enum inline_enum;
194 };
195
196 void gen_field_iterator_init(struct gen_field_iterator *iter,
197 struct gen_group *group,
198 const uint32_t *p, int p_bit,
199 bool print_colors);
200
201 bool gen_field_iterator_next(struct gen_field_iterator *iter);
202
203 void gen_print_group(FILE *out,
204 struct gen_group *group,
205 uint64_t offset, const uint32_t *p, int p_bit,
206 bool color);
207
208 enum gen_batch_decode_flags {
209 /** Print in color! */
210 GEN_BATCH_DECODE_IN_COLOR = (1 << 0),
211 /** Print everything, not just headers */
212 GEN_BATCH_DECODE_FULL = (1 << 1),
213 /** Print offsets along with the batch */
214 GEN_BATCH_DECODE_OFFSETS = (1 << 2),
215 /** Guess when a value is a float and print it as such */
216 GEN_BATCH_DECODE_FLOATS = (1 << 3),
217 };
218
219 struct gen_batch_decode_bo {
220 uint64_t addr;
221 uint32_t size;
222 const void *map;
223 };
224
225 struct gen_batch_decode_ctx {
226 /**
227 * Return information about the buffer containing the given address.
228 *
229 * If the given address is inside a buffer, the map pointer should be
230 * offset accordingly so it points at the data corresponding to address.
231 */
232 struct gen_batch_decode_bo (*get_bo)(void *user_data, bool ppgtt, uint64_t address);
233 unsigned (*get_state_size)(void *user_data,
234 uint64_t address,
235 uint64_t base_address);
236 void *user_data;
237
238 FILE *fp;
239 struct gen_spec *spec;
240 enum gen_batch_decode_flags flags;
241
242 struct gen_disasm *disasm;
243
244 uint64_t surface_base;
245 uint64_t dynamic_base;
246 uint64_t instruction_base;
247
248 int max_vbo_decoded_lines;
249
250 enum drm_i915_gem_engine_class engine;
251
252 int n_batch_buffer_start;
253 };
254
255 void gen_batch_decode_ctx_init(struct gen_batch_decode_ctx *ctx,
256 const struct gen_device_info *devinfo,
257 FILE *fp, enum gen_batch_decode_flags flags,
258 const char *xml_path,
259 struct gen_batch_decode_bo (*get_bo)(void *,
260 bool,
261 uint64_t),
262
263 unsigned (*get_state_size)(void *, uint64_t,
264 uint64_t),
265 void *user_data);
266 void gen_batch_decode_ctx_finish(struct gen_batch_decode_ctx *ctx);
267
268
269 void gen_print_batch(struct gen_batch_decode_ctx *ctx,
270 const uint32_t *batch, uint32_t batch_size,
271 uint64_t batch_addr, bool from_ring);
272
273 #ifdef __cplusplus
274 }
275 #endif
276
277
278 #endif /* GEN_DECODER_H */