2 * Copyright © 2016 Intel Corporation
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:
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
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
31 #include "dev/gen_device_info.h"
32 #include "util/hash_table.h"
33 #include "util/bitset.h"
35 #include "drm-uapi/i915_drm.h"
44 union gen_field_value
;
46 #define I915_ENGINE_CLASS_TO_MASK(x) BITSET_BIT(x)
48 static inline uint32_t gen_make_gen(uint32_t major
, uint32_t minor
)
50 return (major
<< 8) | minor
;
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
,
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
,
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
);
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
);
73 bool gen_field_is_header(struct gen_field
*field
);
75 /* Only allow 5 levels of subgroup'ing
77 #define DECODE_MAX_ARRAY_DEPTH 5
79 struct gen_field_iterator
{
80 struct gen_group
*group
;
84 struct gen_group
*struct_desc
;
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 */
91 int array_iter
[DECODE_MAX_ARRAY_DEPTH
];
94 struct gen_field
*field
;
101 struct hash_table
*commands
;
102 struct hash_table
*structs
;
103 struct hash_table
*registers_by_name
;
104 struct hash_table
*registers_by_offset
;
105 struct hash_table
*enums
;
107 struct hash_table
*access_cache
;
111 struct gen_spec
*spec
;
114 struct gen_field
*fields
; /* linked list of fields */
115 struct gen_field
*dword_length_field
; /* <instruction> specific */
118 uint32_t engine_mask
; /* <instruction> specific */
119 uint32_t bias
; /* <instruction> specific */
120 uint32_t array_offset
; /* <group> specific */
121 uint32_t array_count
; /* number of elements, <group> specific */
122 uint32_t array_item_size
; /* <group> specific */
123 bool variable
; /* <group> specific */
124 bool fixed_length
; /* True for <struct> & <register> */
126 struct gen_group
*parent
;
127 struct gen_group
*next
;
129 uint32_t opcode_mask
;
132 uint32_t register_offset
; /* <register> specific */
143 struct gen_value
**values
;
162 /* Struct definition for GEN_TYPE_STRUCT */
164 struct gen_group
*gen_struct
;
165 struct gen_enum
*gen_enum
;
167 /* Integer and fractional sizes for GEN_TYPE_UFIXED and GEN_TYPE_SFIXED */
173 union gen_field_value
{
181 struct gen_group
*parent
;
182 struct gen_field
*next
;
183 struct gen_group
*array
;
187 struct gen_type type
;
189 uint32_t default_value
;
191 struct gen_enum inline_enum
;
194 void gen_field_iterator_init(struct gen_field_iterator
*iter
,
195 struct gen_group
*group
,
196 const uint32_t *p
, int p_bit
,
199 bool gen_field_iterator_next(struct gen_field_iterator
*iter
);
201 void gen_print_group(FILE *out
,
202 struct gen_group
*group
,
203 uint64_t offset
, const uint32_t *p
, int p_bit
,
206 enum gen_batch_decode_flags
{
207 /** Print in color! */
208 GEN_BATCH_DECODE_IN_COLOR
= (1 << 0),
209 /** Print everything, not just headers */
210 GEN_BATCH_DECODE_FULL
= (1 << 1),
211 /** Print offsets along with the batch */
212 GEN_BATCH_DECODE_OFFSETS
= (1 << 2),
213 /** Guess when a value is a float and print it as such */
214 GEN_BATCH_DECODE_FLOATS
= (1 << 3),
217 struct gen_batch_decode_bo
{
223 struct gen_batch_decode_ctx
{
225 * Return information about the buffer containing the given address.
227 * If the given address is inside a buffer, the map pointer should be
228 * offset accordingly so it points at the data corresponding to address.
230 struct gen_batch_decode_bo (*get_bo
)(void *user_data
, bool ppgtt
, uint64_t address
);
231 unsigned (*get_state_size
)(void *user_data
,
232 uint32_t offset_from_dynamic_state_base_addr
);
236 struct gen_spec
*spec
;
237 enum gen_batch_decode_flags flags
;
239 struct gen_disasm
*disasm
;
241 uint64_t surface_base
;
242 uint64_t dynamic_base
;
243 uint64_t instruction_base
;
245 int max_vbo_decoded_lines
;
247 enum drm_i915_gem_engine_class engine
;
249 int n_batch_buffer_start
;
252 void gen_batch_decode_ctx_init(struct gen_batch_decode_ctx
*ctx
,
253 const struct gen_device_info
*devinfo
,
254 FILE *fp
, enum gen_batch_decode_flags flags
,
255 const char *xml_path
,
256 struct gen_batch_decode_bo (*get_bo
)(void *,
260 unsigned (*get_state_size
)(void *, uint32_t),
262 void gen_batch_decode_ctx_finish(struct gen_batch_decode_ctx
*ctx
);
265 void gen_print_batch(struct gen_batch_decode_ctx
*ctx
,
266 const uint32_t *batch
, uint32_t batch_size
,
267 uint64_t batch_addr
, bool from_ring
);
274 #endif /* GEN_DECODER_H */