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