v3d: we always have at least one output segment
[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 };
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_F187,
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
140 bool v3d_field_iterator_next(struct clif_dump *clif,
141 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
147 #endif /* V3D_DECODER_H */