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