37eebd7fcee8e9f0e739d634547a85c8f195bdcc
[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
30 #include "common/gen_device_info.h"
31 #include "util/hash_table.h"
32
33 #ifdef __cplusplus
34 extern "C" {
35 #endif
36
37 struct gen_spec;
38 struct gen_group;
39 struct gen_field;
40 union gen_field_value;
41
42 static inline uint32_t gen_make_gen(uint32_t major, uint32_t minor)
43 {
44 return (major << 8) | minor;
45 }
46
47 struct gen_group *gen_spec_find_struct(struct gen_spec *spec, const char *name);
48 struct gen_spec *gen_spec_load(const struct gen_device_info *devinfo);
49 struct gen_spec *gen_spec_load_from_path(const struct gen_device_info *devinfo,
50 const char *path);
51 void gen_spec_destroy(struct gen_spec *spec);
52 uint32_t gen_spec_get_gen(struct gen_spec *spec);
53 struct gen_group *gen_spec_find_instruction(struct gen_spec *spec, const uint32_t *p);
54 struct gen_group *gen_spec_find_register(struct gen_spec *spec, uint32_t offset);
55 struct gen_group *gen_spec_find_register_by_name(struct gen_spec *spec, const char *name);
56 struct gen_enum *gen_spec_find_enum(struct gen_spec *spec, const char *name);
57
58 int gen_group_get_length(struct gen_group *group, const uint32_t *p);
59 const char *gen_group_get_name(struct gen_group *group);
60 uint32_t gen_group_get_opcode(struct gen_group *group);
61 struct gen_field *gen_group_find_field(struct gen_group *group, const char *name);
62 struct gen_enum *gen_spec_find_enum(struct gen_spec *spec, const char *name);
63
64 bool gen_field_is_header(struct gen_field *field);
65
66 struct gen_field_iterator {
67 struct gen_group *group;
68 char name[128];
69 char value[128];
70 struct gen_group *struct_desc;
71 const uint32_t *p;
72 int p_bit; /**< bit offset into p */
73 const uint32_t *p_end;
74 int bit; /**< current field starts at this bit offset into p */
75
76 int group_iter;
77
78 struct gen_field *field;
79 bool print_colors;
80 };
81
82 struct gen_spec {
83 uint32_t gen;
84
85 struct hash_table *commands;
86 struct hash_table *structs;
87 struct hash_table *registers_by_name;
88 struct hash_table *registers_by_offset;
89 struct hash_table *enums;
90
91 struct hash_table *access_cache;
92 };
93
94 struct gen_group {
95 struct gen_spec *spec;
96 char *name;
97
98 struct gen_field *fields; /* linked list of fields */
99
100 uint32_t dw_length;
101 uint32_t group_offset, group_count;
102 uint32_t group_size;
103 bool variable;
104
105 struct gen_group *parent;
106 struct gen_group *next;
107
108 uint32_t opcode_mask;
109 uint32_t opcode;
110
111 /* Register specific */
112 uint32_t register_offset;
113 };
114
115 struct gen_value {
116 char *name;
117 uint64_t value;
118 };
119
120 struct gen_enum {
121 char *name;
122 int nvalues;
123 struct gen_value **values;
124 };
125
126 struct gen_type {
127 enum {
128 GEN_TYPE_UNKNOWN,
129 GEN_TYPE_INT,
130 GEN_TYPE_UINT,
131 GEN_TYPE_BOOL,
132 GEN_TYPE_FLOAT,
133 GEN_TYPE_ADDRESS,
134 GEN_TYPE_OFFSET,
135 GEN_TYPE_STRUCT,
136 GEN_TYPE_UFIXED,
137 GEN_TYPE_SFIXED,
138 GEN_TYPE_MBO,
139 GEN_TYPE_ENUM
140 } kind;
141
142 /* Struct definition for GEN_TYPE_STRUCT */
143 union {
144 struct gen_group *gen_struct;
145 struct gen_enum *gen_enum;
146 struct {
147 /* Integer and fractional sizes for GEN_TYPE_UFIXED and GEN_TYPE_SFIXED */
148 int i, f;
149 };
150 };
151 };
152
153 union gen_field_value {
154 bool b32;
155 float f32;
156 uint64_t u64;
157 int64_t i64;
158 };
159
160 struct gen_field {
161 struct gen_group *parent;
162 struct gen_field *next;
163
164 char *name;
165 int start, end;
166 struct gen_type type;
167 bool has_default;
168 uint32_t default_value;
169
170 struct gen_enum inline_enum;
171 };
172
173 void gen_field_iterator_init(struct gen_field_iterator *iter,
174 struct gen_group *group,
175 const uint32_t *p, int p_bit,
176 bool print_colors);
177
178 bool gen_field_iterator_next(struct gen_field_iterator *iter);
179
180 void gen_print_group(FILE *out,
181 struct gen_group *group,
182 uint64_t offset, const uint32_t *p, int p_bit,
183 bool color);
184
185 #ifdef __cplusplus
186 }
187 #endif
188
189
190 #endif /* GEN_DECODER_H */