• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright © 2016-2018 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 #ifndef CLIF_PRIVATE_H
25 #define CLIF_PRIVATE_H
26 
27 #include <stdint.h>
28 #include <stdarg.h>
29 #include "util/list.h"
30 
31 struct clif_bo {
32         const char *name;
33         uint32_t offset;
34         uint32_t size;
35         void *vaddr;
36         bool dumped;
37 };
38 
39 struct clif_dump {
40         const struct v3d_device_info *devinfo;
41         FILE *out;
42 
43         struct v3d_spec *spec;
44 
45         /* List of struct reloc_worklist_entry */
46         struct list_head worklist;
47 
48         struct clif_bo *bo;
49         int bo_count;
50         int bo_array_size;
51 
52         /**
53          * Flag to switch from CLIF ABI to slightly more human-readable
54          * output.
55          */
56         bool pretty;
57 
58         /**
59          * Flag to no dump the binary resources.
60          */
61         bool nobin;
62 };
63 
64 enum reloc_worklist_type {
65         reloc_cl,
66         reloc_gl_shader_state,
67         reloc_gl_including_gs_shader_state,
68         reloc_generic_tile_list,
69 };
70 
71 struct reloc_worklist_entry {
72         struct list_head link;
73 
74         enum reloc_worklist_type type;
75         uint32_t addr;
76 
77         union {
78                 struct {
79                         uint32_t end;
80                 } cl;
81                 struct {
82                         uint32_t num_attrs;
83                 } shader_state;
84                 struct {
85                         uint32_t end;
86                 } generic_tile_list;
87         };
88 };
89 
90 struct clif_bo *
91 clif_lookup_bo(struct clif_dump *clif, uint32_t addr);
92 
93 struct reloc_worklist_entry *
94 clif_dump_add_address_to_worklist(struct clif_dump *clif,
95                                   enum reloc_worklist_type type,
96                                   uint32_t addr);
97 
98 bool v3d33_clif_dump_packet(struct clif_dump *clif, uint32_t offset,
99                             const uint8_t *cl, uint32_t *size, bool reloc_mode);
100 bool v3d41_clif_dump_packet(struct clif_dump *clif, uint32_t offset,
101                             const uint8_t *cl, uint32_t *size, bool reloc_mode);
102 bool v3d42_clif_dump_packet(struct clif_dump *clif, uint32_t offset,
103                             const uint8_t *cl, uint32_t *size, bool reloc_mode);
104 
105 static inline void
out(struct clif_dump * clif,const char * fmt,...)106 out(struct clif_dump *clif, const char *fmt, ...)
107 {
108         va_list args;
109 
110         va_start(args, fmt);
111         vfprintf(clif->out, fmt, args);
112         va_end(args);
113 }
114 
115 static inline void
out_address(struct clif_dump * clif,uint32_t addr)116 out_address(struct clif_dump *clif, uint32_t addr)
117 {
118         struct clif_bo *bo = clif_lookup_bo(clif, addr);
119         if (bo) {
120                 out(clif, "[%s+0x%08x] /* 0x%08x */",
121                     bo->name, addr - bo->offset, addr);
122         } else if (addr) {
123                 out(clif, "/* XXX: BO unknown */ 0x%08x", addr);
124         } else {
125                 out(clif, "[null]");
126         }
127 }
128 
129 #endif /* CLIF_PRIVATE_H */
130