cca1d6fa64cdae099eb6b678b298189a3e20e27f
[mesa.git] / src / broadcom / cle / v3d_decoder.h
1 /*
2 * Copyright © 2016 Intel Corporation
3 * Copyright © 2017 Broadcom
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice (including the next
13 * paragraph) shall be included in all copies or substantial portions of the
14 * Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
22 * IN THE SOFTWARE.
23 */
24
25 #ifndef V3D_DECODER_H
26 #define V3D_DECODER_H
27
28 #include <stdint.h>
29 #include <stdio.h>
30 #include <stdbool.h>
31
32 #include "broadcom/common/v3d_device_info.h"
33
34 struct v3d_spec;
35 struct v3d_group;
36 struct v3d_field;
37
38 struct v3d_group *v3d_spec_find_struct(struct v3d_spec *spec, const char *name);
39 struct v3d_spec *v3d_spec_load(const struct v3d_device_info *devinfo);
40 struct v3d_group *v3d_spec_find_instruction(struct v3d_spec *spec, const uint8_t *p);
41 struct v3d_group *v3d_spec_find_register(struct v3d_spec *spec, uint32_t offset);
42 struct v3d_group *v3d_spec_find_register_by_name(struct v3d_spec *spec, const char *name);
43 int v3d_group_get_length(struct v3d_group *group);
44 const char *v3d_group_get_name(struct v3d_group *group);
45 uint8_t v3d_group_get_opcode(struct v3d_group *group);
46 struct v3d_enum *v3d_spec_find_enum(struct v3d_spec *spec, const char *name);
47
48 struct v3d_field_iterator {
49 struct v3d_group *group;
50 char name[128];
51 char value[128];
52 struct v3d_group *struct_desc;
53 const uint8_t *p;
54 int offset; /**< current field starts at &p[offset] */
55
56 int field_iter;
57 int group_iter;
58
59 struct v3d_field *field;
60 bool print_colors;
61 };
62
63 struct v3d_group {
64 struct v3d_spec *spec;
65 char *name;
66
67 struct v3d_field **fields;
68 uint32_t nfields;
69 uint32_t fields_size;
70
71 uint32_t group_offset, group_count;
72 uint32_t group_size;
73 bool variable;
74
75 struct v3d_group *parent;
76 struct v3d_group *next;
77
78 uint8_t opcode;
79
80 /* Register specific */
81 uint32_t register_offset;
82 };
83
84 struct v3d_value {
85 char *name;
86 uint64_t value;
87 };
88
89 struct v3d_enum {
90 char *name;
91 int nvalues;
92 struct v3d_value **values;
93 };
94
95 struct v3d_type {
96 enum {
97 V3D_TYPE_UNKNOWN,
98 V3D_TYPE_INT,
99 V3D_TYPE_UINT,
100 V3D_TYPE_BOOL,
101 V3D_TYPE_FLOAT,
102 V3D_TYPE_ADDRESS,
103 V3D_TYPE_OFFSET,
104 V3D_TYPE_STRUCT,
105 V3D_TYPE_UFIXED,
106 V3D_TYPE_SFIXED,
107 V3D_TYPE_MBO,
108 V3D_TYPE_ENUM
109 } kind;
110
111 /* Struct definition for V3D_TYPE_STRUCT */
112 union {
113 struct v3d_group *v3d_struct;
114 struct v3d_enum *v3d_enum;
115 struct {
116 /* Integer and fractional sizes for V3D_TYPE_UFIXED and
117 * V3D_TYPE_SFIXED
118 */
119 int i, f;
120 };
121 };
122 };
123
124 struct v3d_field {
125 char *name;
126 int start, end;
127 struct v3d_type type;
128 bool minus_one;
129 bool has_default;
130 uint32_t default_value;
131
132 struct v3d_enum inline_enum;
133 };
134
135 void v3d_field_iterator_init(struct v3d_field_iterator *iter,
136 struct v3d_group *group,
137 const uint8_t *p,
138 bool print_colors);
139
140 bool v3d_field_iterator_next(struct v3d_field_iterator *iter);
141
142 void v3d_print_group(FILE *out,
143 struct v3d_group *group,
144 uint64_t offset, const uint8_t *p,
145 bool color);
146
147 #endif /* V3D_DECODER_H */