2 * Copyright © 2016 Broadcom
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:
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
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
27 #include "clif_dump.h"
28 #include "util/list.h"
29 #include "util/ralloc.h"
31 #include "broadcom/cle/v3d_decoder.h"
33 #define __gen_user_data void
34 #define __gen_address_type uint32_t
35 #define __gen_address_offset(reloc) (*reloc)
36 #define __gen_emit_reloc(cl, reloc)
37 #define __gen_unpack_address(cl, s, e) (__gen_unpack_uint(cl, s, e) << (31 - (e - s)))
39 enum reloc_worklist_type
{
40 reloc_gl_shader_state
,
43 struct reloc_worklist_entry
{
44 struct list_head link
;
46 enum reloc_worklist_type type
;
57 const struct v3d_device_info
*devinfo
;
58 bool (*lookup_vaddr
)(void *data
, uint32_t addr
, void **vaddr
);
60 /* Opaque data from the caller that is passed to the callbacks. */
63 struct v3d_spec
*spec
;
65 /* List of struct reloc_worklist_entry */
66 struct list_head worklist
;
70 out(struct clif_dump
*clif
, const char *fmt
, ...)
75 vfprintf(clif
->out
, fmt
, args
);
79 #include "broadcom/cle/v3d_packet_v33_pack.h"
81 static struct reloc_worklist_entry
*
82 clif_dump_add_address_to_worklist(struct clif_dump
*clif
,
83 enum reloc_worklist_type type
,
86 struct reloc_worklist_entry
*entry
=
87 rzalloc(clif
, struct reloc_worklist_entry
);
94 list_addtail(&entry
->link
, &clif
->worklist
);
100 clif_dump_init(const struct v3d_device_info
*devinfo
,
102 bool (*lookup_vaddr
)(void *data
, uint32_t addr
, void **vaddr
),
105 struct clif_dump
*clif
= rzalloc(NULL
, struct clif_dump
);
107 clif
->devinfo
= devinfo
;
108 clif
->lookup_vaddr
= lookup_vaddr
;
111 clif
->spec
= v3d_spec_load(devinfo
);
113 list_inithead(&clif
->worklist
);
119 clif_dump_destroy(struct clif_dump
*clif
)
124 #define out_uint(_clif, field) out(_clif, " /* %s = */ %u\n", \
125 #field, values-> field);
128 clif_dump_packet(struct clif_dump
*clif
, uint32_t offset
, const uint8_t *cl
,
131 struct v3d_group
*inst
= v3d_spec_find_instruction(clif
->spec
, cl
);
133 out(clif
, "0x%08x: Unknown packet %d!\n", offset
, *cl
);
137 *size
= v3d_group_get_length(inst
);
139 out(clif
, "%s\n", v3d_group_get_name(inst
));
140 v3d_print_group(clif
->out
, inst
, 0, cl
, "");
143 case V3D33_GL_SHADER_STATE_opcode
: {
144 struct V3D33_GL_SHADER_STATE values
;
145 V3D33_GL_SHADER_STATE_unpack(cl
, &values
);
147 struct reloc_worklist_entry
*reloc
=
148 clif_dump_add_address_to_worklist(clif
,
149 reloc_gl_shader_state
,
152 reloc
->shader_state
.num_attrs
=
153 values
.number_of_attribute_arrays
;
158 case V3D33_STORE_MULTI_SAMPLE_RESOLVED_TILE_COLOR_BUFFER_EXTENDED_opcode
: {
159 struct V3D33_STORE_MULTI_SAMPLE_RESOLVED_TILE_COLOR_BUFFER_EXTENDED values
;
160 V3D33_STORE_MULTI_SAMPLE_RESOLVED_TILE_COLOR_BUFFER_EXTENDED_unpack(cl
, &values
);
162 if (values
.last_tile_of_frame
)
167 case V3D33_TRANSFORM_FEEDBACK_ENABLE_opcode
: {
168 struct V3D33_TRANSFORM_FEEDBACK_ENABLE values
;
169 V3D33_TRANSFORM_FEEDBACK_ENABLE_unpack(cl
, &values
);
170 struct v3d_group
*spec
= v3d_spec_find_struct(clif
->spec
,
171 "Transform Feedback Output Data Spec");
172 struct v3d_group
*addr
= v3d_spec_find_struct(clif
->spec
,
173 "Transform Feedback Output Address");
179 for (int i
= 0; i
< values
.number_of_16_bit_output_data_specs_following
; i
++) {
180 v3d_print_group(clif
->out
, spec
, 0, cl
, "");
181 cl
+= v3d_group_get_length(spec
);
182 *size
+= v3d_group_get_length(spec
);
185 for (int i
= 0; i
< values
.number_of_32_bit_output_buffer_address_following
; i
++) {
186 v3d_print_group(clif
->out
, addr
, 0, cl
, "");
187 cl
+= v3d_group_get_length(addr
);
188 *size
+= v3d_group_get_length(addr
);
193 case V3D33_HALT_opcode
:
201 clif_dump_gl_shader_state_record(struct clif_dump
*clif
,
202 struct reloc_worklist_entry
*reloc
, void *vaddr
)
204 struct v3d_group
*state
= v3d_spec_find_struct(clif
->spec
,
205 "GL Shader State Record");
206 struct v3d_group
*attr
= v3d_spec_find_struct(clif
->spec
,
207 "GL Shader State Attribute Record");
211 out(clif
, "GL Shader State Record at 0x%08x\n", reloc
->addr
);
212 v3d_print_group(clif
->out
, state
, 0, vaddr
, "");
213 vaddr
+= v3d_group_get_length(state
);
215 for (int i
= 0; i
< reloc
->shader_state
.num_attrs
; i
++) {
216 out(clif
, " Attribute %d\n", i
);
217 v3d_print_group(clif
->out
, attr
, 0, vaddr
, "");
218 vaddr
+= v3d_group_get_length(attr
);
223 clif_process_worklist(struct clif_dump
*clif
)
225 while (!list_empty(&clif
->worklist
)) {
226 struct reloc_worklist_entry
*reloc
=
227 list_first_entry(&clif
->worklist
,
228 struct reloc_worklist_entry
, link
);
229 list_del(&reloc
->link
);
232 if (!clif
->lookup_vaddr(clif
->data
, reloc
->addr
, &vaddr
)) {
233 out(clif
, "Failed to look up address 0x%08x\n",
238 switch (reloc
->type
) {
239 case reloc_gl_shader_state
:
240 clif_dump_gl_shader_state_record(clif
, reloc
, vaddr
);
248 clif_dump_add_cl(struct clif_dump
*clif
, uint32_t start
, uint32_t end
)
253 if (!clif
->lookup_vaddr(clif
->data
, start
, &start_vaddr
)) {
254 out(clif
, "Failed to look up address 0x%08x\n",
259 /* The end address is optional (for example, a BRANCH instruction
260 * won't set an end), but is used for BCL/RCL termination.
262 void *end_vaddr
= NULL
;
263 if (end
&& !clif
->lookup_vaddr(clif
->data
, end
, &end_vaddr
)) {
264 out(clif
, "Failed to look up address 0x%08x\n",
269 uint8_t *cl
= start_vaddr
;
270 while (clif_dump_packet(clif
, start
, cl
, &size
)) {
280 clif_process_worklist(clif
);