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