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
24
#ifndef INTEL_DECODER_H
25
#define INTEL_DECODER_H
31
#include "dev/intel_device_info.h"
32
#include "util/hash_table.h"
33
#include "util/bitset.h"
35
#include "drm-uapi/i915_drm.h"
44
union intel_field_value;
46
#define I915_ENGINE_CLASS_TO_MASK(x) BITSET_BIT(x)
48
static inline uint32_t intel_make_gen(uint32_t major, uint32_t minor)
50
return (major << 8) | minor;
53
struct intel_group *intel_spec_find_struct(struct intel_spec *spec, const char *name);
54
struct intel_spec *intel_spec_load(const struct intel_device_info *devinfo);
56
intel_spec_load_from_path(const struct intel_device_info *devinfo,
58
struct intel_spec *intel_spec_load_filename(const char *filename);
59
void intel_spec_destroy(struct intel_spec *spec);
60
uint32_t intel_spec_get_gen(struct intel_spec *spec);
61
struct intel_group *intel_spec_find_instruction(struct intel_spec *spec,
62
enum drm_i915_gem_engine_class engine,
64
struct intel_group *intel_spec_find_register(struct intel_spec *spec, uint32_t offset);
65
struct intel_group *intel_spec_find_register_by_name(struct intel_spec *spec, const char *name);
66
struct intel_enum *intel_spec_find_enum(struct intel_spec *spec, const char *name);
68
int intel_group_get_length(struct intel_group *group, const uint32_t *p);
69
const char *intel_group_get_name(struct intel_group *group);
70
uint32_t intel_group_get_opcode(struct intel_group *group);
71
struct intel_field *intel_group_find_field(struct intel_group *group, const char *name);
72
struct intel_enum *intel_spec_find_enum(struct intel_spec *spec, const char *name);
74
bool intel_field_is_header(struct intel_field *field);
76
/* Only allow 5 levels of subgroup'ing
78
#define DECODE_MAX_ARRAY_DEPTH 5
80
struct intel_field_iterator {
81
struct intel_group *group;
85
struct intel_group *struct_desc;
87
int p_bit; /**< bit offset into p */
88
const uint32_t *p_end;
89
int start_bit; /**< current field starts at this bit offset into p */
90
int end_bit; /**< current field ends at this bit offset into p */
92
struct intel_field *fields[DECODE_MAX_ARRAY_DEPTH];
93
struct intel_group *groups[DECODE_MAX_ARRAY_DEPTH];
94
int array_iter[DECODE_MAX_ARRAY_DEPTH];
97
struct intel_field *field;
104
struct hash_table *commands;
105
struct hash_table *structs;
106
struct hash_table *registers_by_name;
107
struct hash_table *registers_by_offset;
108
struct hash_table *enums;
110
struct hash_table *access_cache;
114
struct intel_spec *spec;
117
struct intel_field *fields; /* linked list of fields */
118
struct intel_field *dword_length_field; /* <instruction> specific */
121
uint32_t engine_mask; /* <instruction> specific */
122
uint32_t bias; /* <instruction> specific */
123
uint32_t array_offset; /* <group> specific */
124
uint32_t array_count; /* number of elements, <group> specific */
125
uint32_t array_item_size; /* <group> specific */
126
bool variable; /* <group> specific */
127
bool fixed_length; /* True for <struct> & <register> */
129
struct intel_group *parent;
130
struct intel_group *next;
132
uint32_t opcode_mask;
135
uint32_t register_offset; /* <register> specific */
146
struct intel_value **values;
166
/* Struct definition for INTEL_TYPE_STRUCT */
168
struct intel_group *intel_struct;
169
struct intel_enum *intel_enum;
171
/* Integer and fractional sizes for INTEL_TYPE_UFIXED and INTEL_TYPE_SFIXED */
177
union intel_field_value {
185
struct intel_group *parent;
186
struct intel_field *next;
187
struct intel_group *array;
191
struct intel_type type;
193
uint32_t default_value;
195
struct intel_enum inline_enum;
198
void intel_field_iterator_init(struct intel_field_iterator *iter,
199
struct intel_group *group,
200
const uint32_t *p, int p_bit,
203
bool intel_field_iterator_next(struct intel_field_iterator *iter);
205
void intel_print_group(FILE *out,
206
struct intel_group *group,
207
uint64_t offset, const uint32_t *p, int p_bit,
210
enum intel_batch_decode_flags {
211
/** Print in color! */
212
INTEL_BATCH_DECODE_IN_COLOR = (1 << 0),
213
/** Print everything, not just headers */
214
INTEL_BATCH_DECODE_FULL = (1 << 1),
215
/** Print offsets along with the batch */
216
INTEL_BATCH_DECODE_OFFSETS = (1 << 2),
217
/** Guess when a value is a float and print it as such */
218
INTEL_BATCH_DECODE_FLOATS = (1 << 3),
221
struct intel_batch_decode_bo {
227
struct intel_batch_decode_ctx {
229
* Return information about the buffer containing the given address.
231
* If the given address is inside a buffer, the map pointer should be
232
* offset accordingly so it points at the data corresponding to address.
234
struct intel_batch_decode_bo (*get_bo)(void *user_data, bool ppgtt, uint64_t address);
235
unsigned (*get_state_size)(void *user_data,
237
uint64_t base_address);
241
struct intel_device_info devinfo;
242
struct intel_spec *spec;
243
enum intel_batch_decode_flags flags;
245
bool use_256B_binding_tables;
246
uint64_t surface_base;
247
uint64_t bt_pool_base;
248
uint64_t dynamic_base;
249
uint64_t instruction_base;
251
int max_vbo_decoded_lines;
253
enum drm_i915_gem_engine_class engine;
255
int n_batch_buffer_start;
259
void intel_batch_decode_ctx_init(struct intel_batch_decode_ctx *ctx,
260
const struct intel_device_info *devinfo,
261
FILE *fp, enum intel_batch_decode_flags flags,
262
const char *xml_path,
263
struct intel_batch_decode_bo (*get_bo)(void *,
266
unsigned (*get_state_size)(void *, uint64_t,
269
void intel_batch_decode_ctx_finish(struct intel_batch_decode_ctx *ctx);
272
void intel_print_batch(struct intel_batch_decode_ctx *ctx,
273
const uint32_t *batch, uint32_t batch_size,
274
uint64_t batch_addr, bool from_ring);
281
#endif /* INTEL_DECODER_H */