2987f3920a190ada5ad8c4c5dd79e3e0b2427fa3
[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 struct clif_dump;
38
39 struct v3d_group *v3d_spec_find_struct(struct v3d_spec *spec, const char *name);
40 struct v3d_spec *v3d_spec_load(const struct v3d_device_info *devinfo);
41 struct v3d_group *v3d_spec_find_instruction(struct v3d_spec *spec, const uint8_t *p);
42 struct v3d_group *v3d_spec_find_register(struct v3d_spec *spec, uint32_t offset);
43 struct v3d_group *v3d_spec_find_register_by_name(struct v3d_spec *spec, const char *name);
44 int v3d_group_get_length(struct v3d_group *group);
45 const char *v3d_group_get_name(struct v3d_group *group);
46 uint8_t v3d_group_get_opcode(struct v3d_group *group);
47 struct v3d_enum *v3d_spec_find_enum(struct v3d_spec *spec, const char *name);
48
49 struct v3d_field_iterator {
50 struct v3d_group *group;
51 char name[128];
52 char value[128];
53 struct v3d_group *struct_desc;
54 const uint8_t *p;
55 int offset; /**< current field starts at &p[offset] */
56
57 int field_iter;
58 int group_iter;
59
60 struct v3d_field *field;
61 bool print_colors;
62 };
63
64 struct v3d_group {
65 struct v3d_spec *spec;
66 char *name;
67
68 struct v3d_field **fields;
69 uint32_t nfields;
70 uint32_t fields_size;
71
72 uint32_t group_offset, group_count;
73 uint32_t group_size;
74 bool variable;
75
76 struct v3d_group *parent;
77 struct v3d_group *next;
78
79 uint8_t opcode;
80
81 /* Register specific */
82 uint32_t register_offset;
83 };
84
85 struct v3d_value {
86 char *name;
87 uint64_t value;
88 };
89
90 struct v3d_enum {
91 char *name;
92 int nvalues;
93 struct v3d_value **values;
94 };
95
96 struct v3d_type {
97 enum {
98 V3D_TYPE_UNKNOWN,
99 V3D_TYPE_INT,
100 V3D_TYPE_UINT,
101 V3D_TYPE_BOOL,
102 V3D_TYPE_FLOAT,
103 V3D_TYPE_ADDRESS,
104 V3D_TYPE_OFFSET,
105 V3D_TYPE_STRUCT,
106 V3D_TYPE_UFIXED,
107 V3D_TYPE_SFIXED,
108 V3D_TYPE_MBO,
109 V3D_TYPE_ENUM
110 } kind;
111
112 /* Struct definition for V3D_TYPE_STRUCT */
113 union {
114 struct v3d_group *v3d_struct;
115 struct v3d_enum *v3d_enum;
116 struct {
117 /* Integer and fractional sizes for V3D_TYPE_UFIXED and
118 * V3D_TYPE_SFIXED
119 */
120 int i, f;
121 };
122 };
123 };
124
125 struct v3d_field {
126 char *name;
127 int start, end;
128 struct v3d_type type;
129 bool minus_one;
130 bool has_default;
131 uint32_t default_value;
132
133 struct v3d_enum inline_enum;
134 };
135
136 void v3d_field_iterator_init(struct v3d_field_iterator *iter,
137 struct v3d_group *group,
138 const uint8_t *p,
139 bool print_colors);
140
141 bool v3d_field_iterator_next(struct v3d_field_iterator *iter);
142
143 void v3d_print_group(struct clif_dump *clif,
144 struct v3d_group *group,
145 uint64_t offset, const uint8_t *p,
146 bool color);
147
148 #endif /* V3D_DECODER_H */