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