• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2017-2019 Lyude Paul
3  * Copyright (C) 2017-2019 Alyssa Rosenzweig
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 FROM,
21  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22  * SOFTWARE.
23  *
24  */
25 
26 #ifndef __PAN_DECODE_H__
27 #define __PAN_DECODE_H__
28 
29 #include "genxml/gen_macros.h"
30 #include "util/rb_tree.h"
31 #include "util/simple_mtx.h"
32 #include "util/u_dynarray.h"
33 
34 #include "wrap.h"
35 
36 struct pandecode_context {
37    int id; /* only used for the filename */
38    FILE *dump_stream;
39    unsigned indent;
40    struct rb_tree mmap_tree;
41    struct util_dynarray ro_mappings;
42    int dump_frame_count;
43    simple_mtx_t lock;
44 };
45 
46 void pandecode_dump_file_open(struct pandecode_context *ctx);
47 
48 struct pandecode_mapped_memory {
49    struct rb_node node;
50    size_t length;
51    void *addr;
52    uint64_t gpu_va;
53    bool ro;
54    char name[32];
55 };
56 
57 char *pointer_as_memory_reference(struct pandecode_context *ctx, uint64_t ptr);
58 
59 struct pandecode_mapped_memory *
60 pandecode_find_mapped_gpu_mem_containing(struct pandecode_context *ctx,
61                                          uint64_t addr);
62 
63 void pandecode_map_read_write(struct pandecode_context *ctx);
64 
65 void pandecode_dump_mappings(struct pandecode_context *ctx);
66 
67 static inline void *
__pandecode_fetch_gpu_mem(struct pandecode_context * ctx,uint64_t gpu_va,size_t size,int line,const char * filename)68 __pandecode_fetch_gpu_mem(struct pandecode_context *ctx, uint64_t gpu_va,
69                           size_t size, int line, const char *filename)
70 {
71    const struct pandecode_mapped_memory *mem =
72       pandecode_find_mapped_gpu_mem_containing(ctx, gpu_va);
73 
74    if (!mem) {
75       fprintf(stderr, "Access to unknown memory %" PRIx64 " in %s:%d\n", gpu_va,
76               filename, line);
77       assert(0);
78    }
79 
80    assert(size + (gpu_va - mem->gpu_va) <= mem->length);
81 
82    return mem->addr + gpu_va - mem->gpu_va;
83 }
84 
85 #define pandecode_fetch_gpu_mem(ctx, gpu_va, size)                             \
86    __pandecode_fetch_gpu_mem(ctx, gpu_va, size, __LINE__, __FILE__)
87 
88 /* Returns a validated pointer to mapped GPU memory with the given pointer type,
89  * size automatically determined from the pointer type
90  */
91 #define PANDECODE_PTR(ctx, gpu_va, type)                                       \
92    ((type *)(__pandecode_fetch_gpu_mem(ctx, gpu_va, sizeof(type), __LINE__,    \
93                                        __FILE__)))
94 
95 /* Usage: <variable type> PANDECODE_PTR_VAR(name, gpu_va) */
96 #define PANDECODE_PTR_VAR(ctx, name, gpu_va)                                   \
97    name = __pandecode_fetch_gpu_mem(ctx, gpu_va, sizeof(*name), __LINE__,      \
98                                     __FILE__)
99 
100 void pandecode_validate_buffer(struct pandecode_context *ctx, mali_ptr addr,
101                                size_t sz);
102 
103 /* Forward declare for all supported gens to permit thunking */
104 void pandecode_jc_v4(struct pandecode_context *ctx, mali_ptr jc_gpu_va,
105                      unsigned gpu_id);
106 void pandecode_jc_v5(struct pandecode_context *ctx, mali_ptr jc_gpu_va,
107                      unsigned gpu_id);
108 void pandecode_jc_v6(struct pandecode_context *ctx, mali_ptr jc_gpu_va,
109                      unsigned gpu_id);
110 void pandecode_jc_v7(struct pandecode_context *ctx, mali_ptr jc_gpu_va,
111                      unsigned gpu_id);
112 void pandecode_jc_v9(struct pandecode_context *ctx, mali_ptr jc_gpu_va,
113                      unsigned gpu_id);
114 
115 void pandecode_abort_on_fault_v4(struct pandecode_context *ctx,
116                                  mali_ptr jc_gpu_va);
117 void pandecode_abort_on_fault_v5(struct pandecode_context *ctx,
118                                  mali_ptr jc_gpu_va);
119 void pandecode_abort_on_fault_v6(struct pandecode_context *ctx,
120                                  mali_ptr jc_gpu_va);
121 void pandecode_abort_on_fault_v7(struct pandecode_context *ctx,
122                                  mali_ptr jc_gpu_va);
123 void pandecode_abort_on_fault_v9(struct pandecode_context *ctx,
124                                  mali_ptr jc_gpu_va);
125 
126 void pandecode_cs_v10(struct pandecode_context *ctx, mali_ptr queue,
127                       uint32_t size, unsigned gpu_id, uint32_t *regs);
128 
129 /* Logging infrastructure */
130 static void
pandecode_make_indent(struct pandecode_context * ctx)131 pandecode_make_indent(struct pandecode_context *ctx)
132 {
133    for (unsigned i = 0; i < ctx->indent; ++i)
134       fprintf(ctx->dump_stream, "  ");
135 }
136 
137 static inline void PRINTFLIKE(2, 3)
pandecode_log(struct pandecode_context * ctx,const char * format,...)138    pandecode_log(struct pandecode_context *ctx, const char *format, ...)
139 {
140    va_list ap;
141 
142    pandecode_make_indent(ctx);
143    va_start(ap, format);
144    vfprintf(ctx->dump_stream, format, ap);
145    va_end(ap);
146 }
147 
148 static inline void
pandecode_log_cont(struct pandecode_context * ctx,const char * format,...)149 pandecode_log_cont(struct pandecode_context *ctx, const char *format, ...)
150 {
151    va_list ap;
152 
153    va_start(ap, format);
154    vfprintf(ctx->dump_stream, format, ap);
155    va_end(ap);
156 }
157 
158 /* Convenience methods */
159 #define DUMP_UNPACKED(ctx, T, var, ...)                                        \
160    {                                                                           \
161       pandecode_log(ctx, __VA_ARGS__);                                         \
162       pan_print(ctx->dump_stream, T, var, (ctx->indent + 1) * 2);              \
163    }
164 
165 #define DUMP_CL(ctx, T, cl, ...)                                               \
166    {                                                                           \
167       pan_unpack(cl, T, temp);                                                 \
168       DUMP_UNPACKED(ctx, T, temp, __VA_ARGS__);                                \
169    }
170 
171 #define DUMP_SECTION(ctx, A, S, cl, ...)                                       \
172    {                                                                           \
173       pan_section_unpack(cl, A, S, temp);                                      \
174       pandecode_log(ctx, __VA_ARGS__);                                         \
175       pan_section_print(ctx->dump_stream, A, S, temp, (ctx->indent + 1) * 2);  \
176    }
177 
178 #define MAP_ADDR(ctx, T, addr, cl)                                             \
179    const uint8_t *cl = pandecode_fetch_gpu_mem(ctx, addr, pan_size(T));
180 
181 #define DUMP_ADDR(ctx, T, addr, ...)                                           \
182    {                                                                           \
183       MAP_ADDR(ctx, T, addr, cl)                                               \
184       DUMP_CL(ctx, T, cl, __VA_ARGS__);                                        \
185    }
186 
187 void pandecode_shader_disassemble(struct pandecode_context *ctx,
188                                   mali_ptr shader_ptr, unsigned gpu_id);
189 
190 #ifdef PAN_ARCH
191 
192 /* Information about the framebuffer passed back for additional analysis */
193 struct pandecode_fbd {
194    unsigned rt_count;
195    bool has_extra;
196 };
197 
198 struct pandecode_fbd GENX(pandecode_fbd)(struct pandecode_context *ctx,
199                                          uint64_t gpu_va, bool is_fragment,
200                                          unsigned gpu_id);
201 
202 #if PAN_ARCH >= 9
203 void GENX(pandecode_dcd)(struct pandecode_context *ctx,
204                          const struct MALI_DRAW *p, unsigned unused,
205                          unsigned gpu_id);
206 #else
207 void GENX(pandecode_dcd)(struct pandecode_context *ctx,
208                          const struct MALI_DRAW *p, enum mali_job_type job_type,
209                          unsigned gpu_id);
210 #endif
211 
212 #if PAN_ARCH <= 5
213 void GENX(pandecode_texture)(struct pandecode_context *ctx, mali_ptr u,
214                              unsigned tex);
215 #else
216 void GENX(pandecode_texture)(struct pandecode_context *ctx, const void *cl,
217                              unsigned tex);
218 #endif
219 
220 #if PAN_ARCH >= 5
221 mali_ptr GENX(pandecode_blend)(struct pandecode_context *ctx, void *descs,
222                                int rt_no, mali_ptr frag_shader);
223 #endif
224 
225 #if PAN_ARCH >= 6
226 void GENX(pandecode_tiler)(struct pandecode_context *ctx, mali_ptr gpu_va,
227                            unsigned gpu_id);
228 #endif
229 
230 #if PAN_ARCH >= 9
231 void GENX(pandecode_shader_environment)(struct pandecode_context *ctx,
232                                         const struct MALI_SHADER_ENVIRONMENT *p,
233                                         unsigned gpu_id);
234 
235 void GENX(pandecode_resource_tables)(struct pandecode_context *ctx,
236                                      mali_ptr addr, const char *label);
237 
238 void GENX(pandecode_fau)(struct pandecode_context *ctx, mali_ptr addr,
239                          unsigned count, const char *name);
240 
241 mali_ptr GENX(pandecode_shader)(struct pandecode_context *ctx, mali_ptr addr,
242                                 const char *label, unsigned gpu_id);
243 
244 void GENX(pandecode_blend_descs)(struct pandecode_context *ctx, mali_ptr blend,
245                                  unsigned count, mali_ptr frag_shader,
246                                  unsigned gpu_id);
247 
248 void GENX(pandecode_depth_stencil)(struct pandecode_context *ctx,
249                                    mali_ptr addr);
250 #endif
251 
252 #endif
253 
254 #endif /* __MMAP_TRACE_H__ */
255