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 "clif_private.h"
29 #include "util/list.h"
30 #include "util/ralloc.h"
32 #include "broadcom/cle/v3d_decoder.h"
34 struct reloc_worklist_entry
*
35 clif_dump_add_address_to_worklist(struct clif_dump
*clif
,
36 enum reloc_worklist_type type
,
39 struct reloc_worklist_entry
*entry
=
40 rzalloc(clif
, struct reloc_worklist_entry
);
47 list_addtail(&entry
->link
, &clif
->worklist
);
53 clif_dump_init(const struct v3d_device_info
*devinfo
,
56 struct clif_dump
*clif
= rzalloc(NULL
, struct clif_dump
);
58 clif
->devinfo
= devinfo
;
60 clif
->spec
= v3d_spec_load(devinfo
);
62 list_inithead(&clif
->worklist
);
68 clif_dump_destroy(struct clif_dump
*clif
)
74 clif_lookup_bo(struct clif_dump
*clif
, uint32_t addr
)
76 for (int i
= 0; i
< clif
->bo_count
; i
++) {
77 struct clif_bo
*bo
= &clif
->bo
[i
];
79 if (addr
>= bo
->offset
&&
80 addr
< bo
->offset
+ bo
->size
) {
89 clif_lookup_vaddr(struct clif_dump
*clif
, uint32_t addr
, void **vaddr
)
91 struct clif_bo
*bo
= clif_lookup_bo(clif
, addr
);
95 *vaddr
= bo
->vaddr
+ addr
- bo
->offset
;
99 #define out_uint(_clif, field) out(_clif, " /* %s = */ %u\n", \
100 #field, values-> field);
103 clif_dump_packet(struct clif_dump
*clif
, uint32_t offset
, const uint8_t *cl
,
106 if (clif
->devinfo
->ver
>= 41)
107 return v3d41_clif_dump_packet(clif
, offset
, cl
, size
);
109 return v3d33_clif_dump_packet(clif
, offset
, cl
, size
);
113 clif_dump_cl(struct clif_dump
*clif
, uint32_t start
, uint32_t end
)
116 if (!clif_lookup_vaddr(clif
, start
, &start_vaddr
)) {
117 out(clif
, "Failed to look up address 0x%08x\n",
122 /* The end address is optional (for example, a BRANCH instruction
123 * won't set an end), but is used for BCL/RCL termination.
125 void *end_vaddr
= NULL
;
126 if (end
&& !clif_lookup_vaddr(clif
, end
, &end_vaddr
)) {
127 out(clif
, "Failed to look up address 0x%08x\n",
133 uint8_t *cl
= start_vaddr
;
134 while (clif_dump_packet(clif
, start
, cl
, &size
)) {
144 clif_dump_gl_shader_state_record(struct clif_dump
*clif
,
145 struct reloc_worklist_entry
*reloc
,
148 struct v3d_group
*state
= v3d_spec_find_struct(clif
->spec
,
149 "GL Shader State Record");
150 struct v3d_group
*attr
= v3d_spec_find_struct(clif
->spec
,
151 "GL Shader State Attribute Record");
155 out(clif
, "GL Shader State Record at 0x%08x\n", reloc
->addr
);
156 v3d_print_group(clif
, state
, 0, vaddr
);
157 vaddr
+= v3d_group_get_length(state
);
159 for (int i
= 0; i
< reloc
->shader_state
.num_attrs
; i
++) {
160 out(clif
, " Attribute %d\n", i
);
161 v3d_print_group(clif
, attr
, 0, vaddr
);
162 vaddr
+= v3d_group_get_length(attr
);
167 clif_process_worklist(struct clif_dump
*clif
)
169 while (!list_empty(&clif
->worklist
)) {
170 struct reloc_worklist_entry
*reloc
=
171 list_first_entry(&clif
->worklist
,
172 struct reloc_worklist_entry
, link
);
173 list_del(&reloc
->link
);
176 if (!clif_lookup_vaddr(clif
, reloc
->addr
, &vaddr
)) {
177 out(clif
, "Failed to look up address 0x%08x\n",
182 switch (reloc
->type
) {
184 clif_dump_cl(clif
, reloc
->addr
, reloc
->cl
.end
);
188 case reloc_gl_shader_state
:
189 clif_dump_gl_shader_state_record(clif
,
193 case reloc_generic_tile_list
:
194 clif_dump_cl(clif
, reloc
->addr
,
195 reloc
->generic_tile_list
.end
);
202 void clif_dump(struct clif_dump
*clif
)
204 clif_process_worklist(clif
);
208 clif_dump_add_cl(struct clif_dump
*clif
, uint32_t start
, uint32_t end
)
210 struct reloc_worklist_entry
*entry
=
211 clif_dump_add_address_to_worklist(clif
, reloc_cl
, start
);
217 clif_dump_add_bo(struct clif_dump
*clif
, const char *name
,
218 uint32_t offset
, uint32_t size
, void *vaddr
)
220 if (clif
->bo_count
>= clif
->bo_array_size
) {
221 clif
->bo_array_size
= MAX2(4, clif
->bo_array_size
* 2);
222 clif
->bo
= reralloc(clif
, clif
->bo
, struct clif_bo
,
223 clif
->bo_array_size
);
226 clif
->bo
[clif
->bo_count
].name
= ralloc_strdup(clif
, name
);
227 clif
->bo
[clif
->bo_count
].offset
= offset
;
228 clif
->bo
[clif
->bo_count
].size
= size
;
229 clif
->bo
[clif
->bo_count
].vaddr
= vaddr
;