broadcom/vc5: Move the body of CLIF dumping to a per-version file.
[mesa.git] / src / broadcom / clif / clif_dump.c
1 /*
2 * Copyright © 2016 Broadcom
3 *
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:
10 *
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
13 * Software.
14 *
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
21 * IN THE SOFTWARE.
22 */
23
24 #include <stdio.h>
25 #include <stdlib.h>
26 #include <string.h>
27 #include "clif_dump.h"
28 #include "clif_private.h"
29 #include "util/list.h"
30 #include "util/ralloc.h"
31
32 #include "broadcom/cle/v3d_decoder.h"
33
34 struct reloc_worklist_entry *
35 clif_dump_add_address_to_worklist(struct clif_dump *clif,
36 enum reloc_worklist_type type,
37 uint32_t addr)
38 {
39 struct reloc_worklist_entry *entry =
40 rzalloc(clif, struct reloc_worklist_entry);
41 if (!entry)
42 return NULL;
43
44 entry->type = type;
45 entry->addr = addr;
46
47 list_addtail(&entry->link, &clif->worklist);
48
49 return entry;
50 }
51
52 struct clif_dump *
53 clif_dump_init(const struct v3d_device_info *devinfo,
54 FILE *out,
55 bool (*lookup_vaddr)(void *data, uint32_t addr, void **vaddr),
56 void *data)
57 {
58 struct clif_dump *clif = rzalloc(NULL, struct clif_dump);
59
60 clif->devinfo = devinfo;
61 clif->lookup_vaddr = lookup_vaddr;
62 clif->out = out;
63 clif->data = data;
64 clif->spec = v3d_spec_load(devinfo);
65
66 list_inithead(&clif->worklist);
67
68 return clif;
69 }
70
71 void
72 clif_dump_destroy(struct clif_dump *clif)
73 {
74 ralloc_free(clif);
75 }
76
77 #define out_uint(_clif, field) out(_clif, " /* %s = */ %u\n", \
78 #field, values-> field);
79
80 static bool
81 clif_dump_packet(struct clif_dump *clif, uint32_t offset, const uint8_t *cl,
82 uint32_t *size)
83 {
84 return v3d33_clif_dump_packet(clif, offset, cl, size);
85 }
86
87 static void
88 clif_dump_cl(struct clif_dump *clif, uint32_t start, uint32_t end)
89 {
90 void *start_vaddr;
91 if (!clif->lookup_vaddr(clif->data, start, &start_vaddr)) {
92 out(clif, "Failed to look up address 0x%08x\n",
93 start);
94 return;
95 }
96
97 /* The end address is optional (for example, a BRANCH instruction
98 * won't set an end), but is used for BCL/RCL termination.
99 */
100 void *end_vaddr = NULL;
101 if (end && !clif->lookup_vaddr(clif->data, end, &end_vaddr)) {
102 out(clif, "Failed to look up address 0x%08x\n",
103 end);
104 return;
105 }
106
107 uint32_t size;
108 uint8_t *cl = start_vaddr;
109 while (clif_dump_packet(clif, start, cl, &size)) {
110 cl += size;
111 start += size;
112
113 if (cl == end_vaddr)
114 break;
115 }
116 }
117
118 static void
119 clif_process_worklist(struct clif_dump *clif)
120 {
121 while (!list_empty(&clif->worklist)) {
122 struct reloc_worklist_entry *reloc =
123 list_first_entry(&clif->worklist,
124 struct reloc_worklist_entry, link);
125 list_del(&reloc->link);
126
127 void *vaddr;
128 if (!clif->lookup_vaddr(clif->data, reloc->addr, &vaddr)) {
129 out(clif, "Failed to look up address 0x%08x\n",
130 reloc->addr);
131 continue;
132 }
133
134 switch (reloc->type) {
135 case reloc_gl_shader_state:
136 v3d33_clif_dump_gl_shader_state_record(clif, reloc,
137 vaddr);
138 break;
139 case reloc_generic_tile_list:
140 clif_dump_cl(clif, reloc->addr,
141 reloc->generic_tile_list.end);
142 break;
143 }
144 out(clif, "\n");
145 }
146 }
147
148 void
149 clif_dump_add_cl(struct clif_dump *clif, uint32_t start, uint32_t end)
150 {
151 clif_dump_cl(clif, start, end);
152 out(clif, "\n");
153
154 clif_process_worklist(clif);
155 }