| Jordan Crouse | 64646c7 | 2013-05-28 17:10:27 -0600 | [diff] [blame] | 1 | /* Copyright (c) 2012-2013, The Linux Foundation. All rights reserved. |
| Jordan Crouse | 156cfbc | 2012-01-24 09:32:04 -0700 | [diff] [blame] | 2 | * |
| 3 | * This program is free software; you can redistribute it and/or modify |
| 4 | * it under the terms of the GNU General Public License version 2 and |
| 5 | * only version 2 as published by the Free Software Foundation. |
| 6 | * |
| 7 | * This program is distributed in the hope that it will be useful, |
| 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 10 | * GNU General Public License for more details. |
| 11 | */ |
| 12 | |
| 13 | #include "kgsl.h" |
| 14 | #include "kgsl_sharedmem.h" |
| 15 | #include "kgsl_snapshot.h" |
| 16 | |
| 17 | #include "adreno.h" |
| 18 | #include "adreno_pm4types.h" |
| 19 | #include "a2xx_reg.h" |
| Jordan Crouse | e0879b1 | 2012-03-16 14:53:43 -0600 | [diff] [blame] | 20 | #include "a3xx_reg.h" |
| Jordan Crouse | 156cfbc | 2012-01-24 09:32:04 -0700 | [diff] [blame] | 21 | |
| 22 | /* Number of dwords of ringbuffer history to record */ |
| 23 | #define NUM_DWORDS_OF_RINGBUFFER_HISTORY 100 |
| 24 | |
| 25 | /* Maintain a list of the objects we see during parsing */ |
| 26 | |
| 27 | #define SNAPSHOT_OBJ_BUFSIZE 64 |
| 28 | |
| 29 | #define SNAPSHOT_OBJ_TYPE_IB 0 |
| 30 | |
| Jordan Crouse | 9610b6b | 2012-03-16 14:53:42 -0600 | [diff] [blame] | 31 | /* Keep track of how many bytes are frozen after a snapshot and tell the user */ |
| 32 | static int snapshot_frozen_objsize; |
| 33 | |
| Jordan Crouse | 156cfbc | 2012-01-24 09:32:04 -0700 | [diff] [blame] | 34 | static struct kgsl_snapshot_obj { |
| 35 | int type; |
| 36 | uint32_t gpuaddr; |
| 37 | uint32_t ptbase; |
| 38 | void *ptr; |
| 39 | int dwords; |
| 40 | } objbuf[SNAPSHOT_OBJ_BUFSIZE]; |
| 41 | |
| 42 | /* Pointer to the next open entry in the object list */ |
| 43 | static int objbufptr; |
| 44 | |
| 45 | /* Push a new buffer object onto the list */ |
| 46 | static void push_object(struct kgsl_device *device, int type, uint32_t ptbase, |
| 47 | uint32_t gpuaddr, int dwords) |
| 48 | { |
| 49 | int index; |
| 50 | void *ptr; |
| 51 | |
| Jordan Crouse | e9e91bf | 2012-02-21 09:48:36 -0700 | [diff] [blame] | 52 | /* |
| 53 | * Sometimes IBs can be reused in the same dump. Because we parse from |
| 54 | * oldest to newest, if we come across an IB that has already been used, |
| 55 | * assume that it has been reused and update the list with the newest |
| 56 | * size. |
| 57 | */ |
| 58 | |
| Jordan Crouse | 156cfbc | 2012-01-24 09:32:04 -0700 | [diff] [blame] | 59 | for (index = 0; index < objbufptr; index++) { |
| 60 | if (objbuf[index].gpuaddr == gpuaddr && |
| Jordan Crouse | e9e91bf | 2012-02-21 09:48:36 -0700 | [diff] [blame] | 61 | objbuf[index].ptbase == ptbase) { |
| 62 | objbuf[index].dwords = dwords; |
| 63 | return; |
| 64 | } |
| Jordan Crouse | 156cfbc | 2012-01-24 09:32:04 -0700 | [diff] [blame] | 65 | } |
| 66 | |
| 67 | if (objbufptr == SNAPSHOT_OBJ_BUFSIZE) { |
| 68 | KGSL_DRV_ERR(device, "snapshot: too many snapshot objects\n"); |
| 69 | return; |
| 70 | } |
| 71 | |
| 72 | /* |
| 73 | * adreno_convertaddr verifies that the IB size is valid - at least in |
| 74 | * the context of it being smaller then the allocated memory space |
| 75 | */ |
| 76 | ptr = adreno_convertaddr(device, ptbase, gpuaddr, dwords << 2); |
| 77 | |
| 78 | if (ptr == NULL) { |
| 79 | KGSL_DRV_ERR(device, |
| 80 | "snapshot: Can't find GPU address for %x\n", gpuaddr); |
| 81 | return; |
| 82 | } |
| 83 | |
| 84 | /* Put it on the list of things to parse */ |
| 85 | objbuf[objbufptr].type = type; |
| 86 | objbuf[objbufptr].gpuaddr = gpuaddr; |
| 87 | objbuf[objbufptr].ptbase = ptbase; |
| 88 | objbuf[objbufptr].dwords = dwords; |
| 89 | objbuf[objbufptr++].ptr = ptr; |
| 90 | } |
| 91 | |
| Jordan Crouse | e9e91bf | 2012-02-21 09:48:36 -0700 | [diff] [blame] | 92 | /* |
| 93 | * Return a 1 if the specified object is already on the list of buffers |
| 94 | * to be dumped |
| 95 | */ |
| 96 | |
| 97 | static int find_object(int type, unsigned int gpuaddr, unsigned int ptbase) |
| 98 | { |
| 99 | int index; |
| 100 | |
| 101 | for (index = 0; index < objbufptr; index++) { |
| 102 | if (objbuf[index].gpuaddr == gpuaddr && |
| 103 | objbuf[index].ptbase == ptbase && |
| 104 | objbuf[index].type == type) |
| 105 | return 1; |
| 106 | } |
| 107 | |
| 108 | return 0; |
| 109 | } |
| 110 | |
| Jordan Crouse | e0879b1 | 2012-03-16 14:53:43 -0600 | [diff] [blame] | 111 | /* |
| 112 | * This structure keeps track of type0 writes to VSC_PIPE_DATA_ADDRESS_x and |
| 113 | * VSC_PIPE_DATA_LENGTH_x. When a draw initator is called these registers |
| 114 | * point to buffers that we need to freeze for a snapshot |
| 115 | */ |
| 116 | |
| 117 | static struct { |
| 118 | unsigned int base; |
| 119 | unsigned int size; |
| 120 | } vsc_pipe[8]; |
| 121 | |
| 122 | /* |
| 123 | * This is the cached value of type0 writes to the VSC_SIZE_ADDRESS which |
| 124 | * contains the buffer address of the visiblity stream size buffer during a |
| 125 | * binning pass |
| 126 | */ |
| 127 | |
| 128 | static unsigned int vsc_size_address; |
| 129 | |
| 130 | /* |
| 131 | * This struct keeps track of type0 writes to VFD_FETCH_INSTR_0_X and |
| 132 | * VFD_FETCH_INSTR_1_X registers. When a draw initator is called the addresses |
| 133 | * and sizes in these registers point to VBOs that we need to freeze for a |
| 134 | * snapshot |
| 135 | */ |
| 136 | |
| 137 | static struct { |
| 138 | unsigned int base; |
| 139 | unsigned int stride; |
| 140 | } vbo[16]; |
| 141 | |
| 142 | /* |
| 143 | * This is the cached value of type0 writes to VFD_INDEX_MAX. This will be used |
| 144 | * to calculate the size of the VBOs when the draw initator is called |
| 145 | */ |
| 146 | |
| 147 | static unsigned int vfd_index_max; |
| 148 | |
| 149 | /* |
| 150 | * This is the cached value of type0 writes to VFD_CONTROL_0 which tells us how |
| 151 | * many VBOs are active when the draw initator is called |
| 152 | */ |
| 153 | |
| 154 | static unsigned int vfd_control_0; |
| 155 | |
| 156 | /* |
| 157 | * Cached value of type0 writes to SP_VS_PVT_MEM_ADDR and SP_FS_PVT_MEM_ADDR. |
| 158 | * This is a buffer that contains private stack information for the shader |
| 159 | */ |
| 160 | |
| 161 | static unsigned int sp_vs_pvt_mem_addr; |
| 162 | static unsigned int sp_fs_pvt_mem_addr; |
| 163 | |
| Jordan Crouse | 361cc3d | 2012-06-20 08:22:14 -0600 | [diff] [blame] | 164 | /* |
| Shubhraprakash Das | 49f6ce1 | 2013-05-28 17:10:56 -0600 | [diff] [blame] | 165 | * Cached value of SP_VS_OBJ_START_REG and SP_FS_OBJ_START_REG. |
| 166 | */ |
| 167 | static unsigned int sp_vs_obj_start_reg; |
| 168 | static unsigned int sp_fs_obj_start_reg; |
| 169 | |
| 170 | /* |
| Jordan Crouse | 361cc3d | 2012-06-20 08:22:14 -0600 | [diff] [blame] | 171 | * Each load state block has two possible types. Each type has a different |
| 172 | * number of dwords per unit. Use this handy lookup table to make sure |
| 173 | * we dump the right amount of data from the indirect buffer |
| 174 | */ |
| 175 | |
| 176 | static int load_state_unit_sizes[7][2] = { |
| 177 | { 2, 4 }, |
| 178 | { 0, 1 }, |
| 179 | { 2, 4 }, |
| 180 | { 0, 1 }, |
| 181 | { 8, 2 }, |
| 182 | { 8, 2 }, |
| 183 | { 8, 2 }, |
| 184 | }; |
| 185 | |
| Jordan Crouse | 2cf6ec9 | 2013-02-14 14:46:11 -0700 | [diff] [blame] | 186 | static int ib_parse_load_state(struct kgsl_device *device, unsigned int *pkt, |
| Jordan Crouse | ea2c638 | 2012-03-16 14:53:42 -0600 | [diff] [blame] | 187 | unsigned int ptbase) |
| 188 | { |
| 189 | unsigned int block, source, type; |
| Jordan Crouse | 2cf6ec9 | 2013-02-14 14:46:11 -0700 | [diff] [blame] | 190 | int ret = 0; |
| Jordan Crouse | ea2c638 | 2012-03-16 14:53:42 -0600 | [diff] [blame] | 191 | |
| 192 | /* |
| 193 | * The object here is to find indirect shaders i.e - shaders loaded from |
| 194 | * GPU memory instead of directly in the command. These should be added |
| 195 | * to the list of memory objects to dump. So look at the load state |
| Jordan Crouse | 361cc3d | 2012-06-20 08:22:14 -0600 | [diff] [blame] | 196 | * if the block is indirect (source = 4). If so then add the memory |
| 197 | * address to the list. The size of the object differs depending on the |
| 198 | * type per the load_state_unit_sizes array above. |
| Jordan Crouse | ea2c638 | 2012-03-16 14:53:42 -0600 | [diff] [blame] | 199 | */ |
| 200 | |
| 201 | if (type3_pkt_size(pkt[0]) < 2) |
| Jordan Crouse | 2cf6ec9 | 2013-02-14 14:46:11 -0700 | [diff] [blame] | 202 | return 0; |
| Jordan Crouse | ea2c638 | 2012-03-16 14:53:42 -0600 | [diff] [blame] | 203 | |
| 204 | /* |
| 205 | * pkt[1] 18:16 - source |
| 206 | * pkt[1] 21:19 - state block |
| 207 | * pkt[1] 31:22 - size in units |
| 208 | * pkt[2] 0:1 - type |
| 209 | * pkt[2] 31:2 - GPU memory address |
| 210 | */ |
| 211 | |
| 212 | block = (pkt[1] >> 19) & 0x07; |
| 213 | source = (pkt[1] >> 16) & 0x07; |
| 214 | type = pkt[2] & 0x03; |
| 215 | |
| Jordan Crouse | 361cc3d | 2012-06-20 08:22:14 -0600 | [diff] [blame] | 216 | if (source == 4) { |
| 217 | int unitsize, ret; |
| 218 | |
| 219 | if (type == 0) |
| 220 | unitsize = load_state_unit_sizes[block][0]; |
| 221 | else |
| 222 | unitsize = load_state_unit_sizes[block][1]; |
| Jordan Crouse | ea2c638 | 2012-03-16 14:53:42 -0600 | [diff] [blame] | 223 | |
| 224 | /* Freeze the GPU buffer containing the shader */ |
| 225 | |
| 226 | ret = kgsl_snapshot_get_object(device, ptbase, |
| 227 | pkt[2] & 0xFFFFFFFC, |
| 228 | (((pkt[1] >> 22) & 0x03FF) * unitsize) << 2, |
| 229 | SNAPSHOT_GPU_OBJECT_SHADER); |
| Jordan Crouse | 2cf6ec9 | 2013-02-14 14:46:11 -0700 | [diff] [blame] | 230 | |
| 231 | if (ret < 0) |
| 232 | return -EINVAL; |
| 233 | |
| Jordan Crouse | ea2c638 | 2012-03-16 14:53:42 -0600 | [diff] [blame] | 234 | snapshot_frozen_objsize += ret; |
| 235 | } |
| Jordan Crouse | 2cf6ec9 | 2013-02-14 14:46:11 -0700 | [diff] [blame] | 236 | |
| 237 | return ret; |
| Jordan Crouse | ea2c638 | 2012-03-16 14:53:42 -0600 | [diff] [blame] | 238 | } |
| 239 | |
| 240 | /* |
| Jordan Crouse | e0879b1 | 2012-03-16 14:53:43 -0600 | [diff] [blame] | 241 | * This opcode sets the base addresses for the visibilty stream buffer and the |
| 242 | * visiblity stream size buffer. |
| 243 | */ |
| 244 | |
| Jordan Crouse | 2cf6ec9 | 2013-02-14 14:46:11 -0700 | [diff] [blame] | 245 | static int ib_parse_set_bin_data(struct kgsl_device *device, unsigned int *pkt, |
| Jordan Crouse | e0879b1 | 2012-03-16 14:53:43 -0600 | [diff] [blame] | 246 | unsigned int ptbase) |
| 247 | { |
| 248 | int ret; |
| 249 | |
| 250 | if (type3_pkt_size(pkt[0]) < 2) |
| Jordan Crouse | 2cf6ec9 | 2013-02-14 14:46:11 -0700 | [diff] [blame] | 251 | return 0; |
| Jordan Crouse | e0879b1 | 2012-03-16 14:53:43 -0600 | [diff] [blame] | 252 | |
| 253 | /* Visiblity stream buffer */ |
| 254 | ret = kgsl_snapshot_get_object(device, ptbase, pkt[1], 0, |
| 255 | SNAPSHOT_GPU_OBJECT_GENERIC); |
| Jordan Crouse | 2cf6ec9 | 2013-02-14 14:46:11 -0700 | [diff] [blame] | 256 | |
| 257 | if (ret < 0) |
| 258 | return -EINVAL; |
| 259 | |
| Jordan Crouse | e0879b1 | 2012-03-16 14:53:43 -0600 | [diff] [blame] | 260 | snapshot_frozen_objsize += ret; |
| 261 | |
| 262 | /* visiblity stream size buffer (fixed size 8 dwords) */ |
| 263 | ret = kgsl_snapshot_get_object(device, ptbase, pkt[2], 32, |
| 264 | SNAPSHOT_GPU_OBJECT_GENERIC); |
| Jordan Crouse | 2cf6ec9 | 2013-02-14 14:46:11 -0700 | [diff] [blame] | 265 | |
| 266 | if (ret >= 0) |
| 267 | snapshot_frozen_objsize += ret; |
| 268 | |
| 269 | return ret; |
| Jordan Crouse | e0879b1 | 2012-03-16 14:53:43 -0600 | [diff] [blame] | 270 | } |
| 271 | |
| 272 | /* |
| 273 | * This opcode writes to GPU memory - if the buffer is written to, there is a |
| 274 | * good chance that it would be valuable to capture in the snapshot, so mark all |
| 275 | * buffers that are written to as frozen |
| 276 | */ |
| 277 | |
| Jordan Crouse | 2cf6ec9 | 2013-02-14 14:46:11 -0700 | [diff] [blame] | 278 | static int ib_parse_mem_write(struct kgsl_device *device, unsigned int *pkt, |
| Jordan Crouse | e0879b1 | 2012-03-16 14:53:43 -0600 | [diff] [blame] | 279 | unsigned int ptbase) |
| 280 | { |
| 281 | int ret; |
| 282 | |
| 283 | if (type3_pkt_size(pkt[0]) < 1) |
| Jordan Crouse | 2cf6ec9 | 2013-02-14 14:46:11 -0700 | [diff] [blame] | 284 | return 0; |
| Jordan Crouse | e0879b1 | 2012-03-16 14:53:43 -0600 | [diff] [blame] | 285 | |
| 286 | /* |
| 287 | * The address is where the data in the rest of this packet is written |
| 288 | * to, but since that might be an offset into the larger buffer we need |
| 289 | * to get the whole thing. Pass a size of 0 kgsl_snapshot_get_object to |
| 290 | * capture the entire buffer. |
| 291 | */ |
| 292 | |
| 293 | ret = kgsl_snapshot_get_object(device, ptbase, pkt[1] & 0xFFFFFFFC, 0, |
| 294 | SNAPSHOT_GPU_OBJECT_GENERIC); |
| 295 | |
| Jordan Crouse | 2cf6ec9 | 2013-02-14 14:46:11 -0700 | [diff] [blame] | 296 | if (ret >= 0) |
| 297 | snapshot_frozen_objsize += ret; |
| 298 | |
| 299 | return ret; |
| Jordan Crouse | e0879b1 | 2012-03-16 14:53:43 -0600 | [diff] [blame] | 300 | } |
| 301 | |
| 302 | /* |
| 303 | * The DRAW_INDX opcode sends a draw initator which starts a draw operation in |
| 304 | * the GPU, so this is the point where all the registers and buffers become |
| 305 | * "valid". The DRAW_INDX may also have an index buffer pointer that should be |
| 306 | * frozen with the others |
| 307 | */ |
| 308 | |
| Jordan Crouse | 2cf6ec9 | 2013-02-14 14:46:11 -0700 | [diff] [blame] | 309 | static int ib_parse_draw_indx(struct kgsl_device *device, unsigned int *pkt, |
| Jordan Crouse | e0879b1 | 2012-03-16 14:53:43 -0600 | [diff] [blame] | 310 | unsigned int ptbase) |
| 311 | { |
| Jordan Crouse | 2cf6ec9 | 2013-02-14 14:46:11 -0700 | [diff] [blame] | 312 | int ret = 0, i; |
| Jordan Crouse | e0879b1 | 2012-03-16 14:53:43 -0600 | [diff] [blame] | 313 | |
| 314 | if (type3_pkt_size(pkt[0]) < 3) |
| Jordan Crouse | 2cf6ec9 | 2013-02-14 14:46:11 -0700 | [diff] [blame] | 315 | return 0; |
| Jordan Crouse | e0879b1 | 2012-03-16 14:53:43 -0600 | [diff] [blame] | 316 | |
| 317 | /* DRAW_IDX may have a index buffer pointer */ |
| 318 | |
| 319 | if (type3_pkt_size(pkt[0]) > 3) { |
| 320 | ret = kgsl_snapshot_get_object(device, ptbase, pkt[4], pkt[5], |
| 321 | SNAPSHOT_GPU_OBJECT_GENERIC); |
| Jordan Crouse | 2cf6ec9 | 2013-02-14 14:46:11 -0700 | [diff] [blame] | 322 | if (ret < 0) |
| 323 | return -EINVAL; |
| 324 | |
| Jordan Crouse | e0879b1 | 2012-03-16 14:53:43 -0600 | [diff] [blame] | 325 | snapshot_frozen_objsize += ret; |
| 326 | } |
| 327 | |
| 328 | /* |
| 329 | * All of the type0 writes are valid at a draw initiator, so freeze |
| 330 | * the various buffers that we are tracking |
| 331 | */ |
| 332 | |
| 333 | /* First up the visiblity stream buffer */ |
| 334 | |
| 335 | for (i = 0; i < ARRAY_SIZE(vsc_pipe); i++) { |
| 336 | if (vsc_pipe[i].base != 0 && vsc_pipe[i].size != 0) { |
| 337 | ret = kgsl_snapshot_get_object(device, ptbase, |
| 338 | vsc_pipe[i].base, vsc_pipe[i].size, |
| 339 | SNAPSHOT_GPU_OBJECT_GENERIC); |
| Jordan Crouse | 2cf6ec9 | 2013-02-14 14:46:11 -0700 | [diff] [blame] | 340 | if (ret < 0) |
| 341 | return -EINVAL; |
| 342 | |
| Jordan Crouse | e0879b1 | 2012-03-16 14:53:43 -0600 | [diff] [blame] | 343 | snapshot_frozen_objsize += ret; |
| 344 | } |
| 345 | } |
| 346 | |
| 347 | /* Next the visibility stream size buffer */ |
| 348 | |
| 349 | if (vsc_size_address) { |
| 350 | ret = kgsl_snapshot_get_object(device, ptbase, |
| 351 | vsc_size_address, 32, |
| 352 | SNAPSHOT_GPU_OBJECT_GENERIC); |
| Jordan Crouse | 2cf6ec9 | 2013-02-14 14:46:11 -0700 | [diff] [blame] | 353 | if (ret < 0) |
| 354 | return -EINVAL; |
| 355 | |
| Jordan Crouse | e0879b1 | 2012-03-16 14:53:43 -0600 | [diff] [blame] | 356 | snapshot_frozen_objsize += ret; |
| 357 | } |
| 358 | |
| 359 | /* Next private shader buffer memory */ |
| 360 | if (sp_vs_pvt_mem_addr) { |
| 361 | ret = kgsl_snapshot_get_object(device, ptbase, |
| 362 | sp_vs_pvt_mem_addr, 8192, |
| 363 | SNAPSHOT_GPU_OBJECT_GENERIC); |
| Jordan Crouse | 2cf6ec9 | 2013-02-14 14:46:11 -0700 | [diff] [blame] | 364 | if (ret < 0) |
| 365 | return -EINVAL; |
| 366 | |
| Jordan Crouse | e0879b1 | 2012-03-16 14:53:43 -0600 | [diff] [blame] | 367 | snapshot_frozen_objsize += ret; |
| Jordan Crouse | 21aaadf | 2012-09-11 16:38:15 -0600 | [diff] [blame] | 368 | sp_vs_pvt_mem_addr = 0; |
| Jordan Crouse | e0879b1 | 2012-03-16 14:53:43 -0600 | [diff] [blame] | 369 | } |
| 370 | |
| 371 | if (sp_fs_pvt_mem_addr) { |
| 372 | ret = kgsl_snapshot_get_object(device, ptbase, |
| 373 | sp_fs_pvt_mem_addr, 8192, |
| 374 | SNAPSHOT_GPU_OBJECT_GENERIC); |
| Jordan Crouse | 2cf6ec9 | 2013-02-14 14:46:11 -0700 | [diff] [blame] | 375 | if (ret < 0) |
| 376 | return -EINVAL; |
| 377 | |
| Jordan Crouse | e0879b1 | 2012-03-16 14:53:43 -0600 | [diff] [blame] | 378 | snapshot_frozen_objsize += ret; |
| Jordan Crouse | 21aaadf | 2012-09-11 16:38:15 -0600 | [diff] [blame] | 379 | sp_fs_pvt_mem_addr = 0; |
| Jordan Crouse | e0879b1 | 2012-03-16 14:53:43 -0600 | [diff] [blame] | 380 | } |
| 381 | |
| Shubhraprakash Das | 49f6ce1 | 2013-05-28 17:10:56 -0600 | [diff] [blame] | 382 | if (sp_vs_obj_start_reg) { |
| 383 | ret = kgsl_snapshot_get_object(device, ptbase, |
| 384 | sp_vs_obj_start_reg & 0xFFFFFFE0, 0, |
| 385 | SNAPSHOT_GPU_OBJECT_GENERIC); |
| 386 | if (ret < 0) |
| 387 | return -EINVAL; |
| 388 | snapshot_frozen_objsize += ret; |
| 389 | sp_vs_obj_start_reg = 0; |
| 390 | } |
| 391 | |
| 392 | if (sp_fs_obj_start_reg) { |
| 393 | ret = kgsl_snapshot_get_object(device, ptbase, |
| 394 | sp_fs_obj_start_reg & 0xFFFFFFE0, 0, |
| 395 | SNAPSHOT_GPU_OBJECT_GENERIC); |
| 396 | if (ret < 0) |
| 397 | return -EINVAL; |
| 398 | snapshot_frozen_objsize += ret; |
| 399 | sp_fs_obj_start_reg = 0; |
| 400 | } |
| 401 | |
| Jordan Crouse | e0879b1 | 2012-03-16 14:53:43 -0600 | [diff] [blame] | 402 | /* Finally: VBOs */ |
| 403 | |
| 404 | /* The number of active VBOs is stored in VFD_CONTROL_O[31:27] */ |
| 405 | for (i = 0; i < (vfd_control_0) >> 27; i++) { |
| 406 | int size; |
| 407 | |
| 408 | /* |
| 409 | * The size of the VBO is the stride stored in |
| 410 | * VFD_FETCH_INSTR_0_X.BUFSTRIDE * VFD_INDEX_MAX. The base |
| 411 | * is stored in VFD_FETCH_INSTR_1_X |
| 412 | */ |
| 413 | |
| 414 | if (vbo[i].base != 0) { |
| 415 | size = vbo[i].stride * vfd_index_max; |
| 416 | |
| 417 | ret = kgsl_snapshot_get_object(device, ptbase, |
| 418 | vbo[i].base, |
| 419 | 0, SNAPSHOT_GPU_OBJECT_GENERIC); |
| Jordan Crouse | 2cf6ec9 | 2013-02-14 14:46:11 -0700 | [diff] [blame] | 420 | if (ret < 0) |
| 421 | return -EINVAL; |
| 422 | |
| Jordan Crouse | e0879b1 | 2012-03-16 14:53:43 -0600 | [diff] [blame] | 423 | snapshot_frozen_objsize += ret; |
| 424 | } |
| Jordan Crouse | 21aaadf | 2012-09-11 16:38:15 -0600 | [diff] [blame] | 425 | |
| 426 | vbo[i].base = 0; |
| 427 | vbo[i].stride = 0; |
| Jordan Crouse | e0879b1 | 2012-03-16 14:53:43 -0600 | [diff] [blame] | 428 | } |
| Jordan Crouse | 21aaadf | 2012-09-11 16:38:15 -0600 | [diff] [blame] | 429 | |
| 430 | vfd_control_0 = 0; |
| 431 | vfd_index_max = 0; |
| Jordan Crouse | 2cf6ec9 | 2013-02-14 14:46:11 -0700 | [diff] [blame] | 432 | |
| 433 | return ret; |
| Jordan Crouse | e0879b1 | 2012-03-16 14:53:43 -0600 | [diff] [blame] | 434 | } |
| 435 | |
| 436 | /* |
| Jordan Crouse | ea2c638 | 2012-03-16 14:53:42 -0600 | [diff] [blame] | 437 | * Parse all the type3 opcode packets that may contain important information, |
| Jordan Crouse | e0879b1 | 2012-03-16 14:53:43 -0600 | [diff] [blame] | 438 | * such as additional GPU buffers to grab or a draw initator |
| Jordan Crouse | ea2c638 | 2012-03-16 14:53:42 -0600 | [diff] [blame] | 439 | */ |
| 440 | |
| Jordan Crouse | 2cf6ec9 | 2013-02-14 14:46:11 -0700 | [diff] [blame] | 441 | static int ib_parse_type3(struct kgsl_device *device, unsigned int *ptr, |
| Jordan Crouse | ea2c638 | 2012-03-16 14:53:42 -0600 | [diff] [blame] | 442 | unsigned int ptbase) |
| 443 | { |
| Jordan Crouse | 2cf6ec9 | 2013-02-14 14:46:11 -0700 | [diff] [blame] | 444 | int opcode = cp_type3_opcode(*ptr); |
| 445 | |
| 446 | if (opcode == CP_LOAD_STATE) |
| 447 | return ib_parse_load_state(device, ptr, ptbase); |
| 448 | else if (opcode == CP_SET_BIN_DATA) |
| 449 | return ib_parse_set_bin_data(device, ptr, ptbase); |
| 450 | else if (opcode == CP_MEM_WRITE) |
| 451 | return ib_parse_mem_write(device, ptr, ptbase); |
| 452 | else if (opcode == CP_DRAW_INDX) |
| 453 | return ib_parse_draw_indx(device, ptr, ptbase); |
| 454 | |
| 455 | return 0; |
| Jordan Crouse | e0879b1 | 2012-03-16 14:53:43 -0600 | [diff] [blame] | 456 | } |
| 457 | |
| 458 | /* |
| 459 | * Parse type0 packets found in the stream. Some of the registers that are |
| 460 | * written are clues for GPU buffers that we need to freeze. Register writes |
| 461 | * are considred valid when a draw initator is called, so just cache the values |
| 462 | * here and freeze them when a CP_DRAW_INDX is seen. This protects against |
| 463 | * needlessly caching buffers that won't be used during a draw call |
| 464 | */ |
| 465 | |
| 466 | static void ib_parse_type0(struct kgsl_device *device, unsigned int *ptr, |
| 467 | unsigned int ptbase) |
| 468 | { |
| 469 | int size = type0_pkt_size(*ptr); |
| 470 | int offset = type0_pkt_offset(*ptr); |
| 471 | int i; |
| 472 | |
| Shubhraprakash Das | 195b3ba | 2013-05-28 17:11:02 -0600 | [diff] [blame] | 473 | for (i = 0; i < size - 1; i++, offset++) { |
| Jordan Crouse | e0879b1 | 2012-03-16 14:53:43 -0600 | [diff] [blame] | 474 | |
| 475 | /* Visiblity stream buffer */ |
| 476 | |
| 477 | if (offset >= A3XX_VSC_PIPE_DATA_ADDRESS_0 && |
| 478 | offset <= A3XX_VSC_PIPE_DATA_LENGTH_7) { |
| 479 | int index = offset - A3XX_VSC_PIPE_DATA_ADDRESS_0; |
| 480 | |
| 481 | /* Each bank of address and length registers are |
| 482 | * interleaved with an empty register: |
| 483 | * |
| 484 | * address 0 |
| 485 | * length 0 |
| 486 | * empty |
| 487 | * address 1 |
| 488 | * length 1 |
| 489 | * empty |
| 490 | * ... |
| 491 | */ |
| 492 | |
| Jordan Crouse | 7f24c71 | 2012-04-05 16:55:55 -0600 | [diff] [blame] | 493 | if ((index % 3) == 0) |
| Jordan Crouse | e0879b1 | 2012-03-16 14:53:43 -0600 | [diff] [blame] | 494 | vsc_pipe[index / 3].base = ptr[i + 1]; |
| Jordan Crouse | 7f24c71 | 2012-04-05 16:55:55 -0600 | [diff] [blame] | 495 | else if ((index % 3) == 1) |
| Jordan Crouse | e0879b1 | 2012-03-16 14:53:43 -0600 | [diff] [blame] | 496 | vsc_pipe[index / 3].size = ptr[i + 1]; |
| 497 | } else if ((offset >= A3XX_VFD_FETCH_INSTR_0_0) && |
| 498 | (offset <= A3XX_VFD_FETCH_INSTR_1_F)) { |
| 499 | int index = offset - A3XX_VFD_FETCH_INSTR_0_0; |
| 500 | |
| 501 | /* |
| 502 | * FETCH_INSTR_0_X and FETCH_INSTR_1_X banks are |
| 503 | * interleaved as above but without the empty register |
| 504 | * in between |
| 505 | */ |
| 506 | |
| Jordan Crouse | 7f24c71 | 2012-04-05 16:55:55 -0600 | [diff] [blame] | 507 | if ((index % 2) == 0) |
| Jordan Crouse | e0879b1 | 2012-03-16 14:53:43 -0600 | [diff] [blame] | 508 | vbo[index >> 1].stride = |
| 509 | (ptr[i + 1] >> 7) & 0x1FF; |
| 510 | else |
| 511 | vbo[index >> 1].base = ptr[i + 1]; |
| 512 | } else { |
| 513 | /* |
| 514 | * Cache various support registers for calculating |
| 515 | * buffer sizes |
| 516 | */ |
| 517 | |
| 518 | switch (offset) { |
| 519 | case A3XX_VFD_CONTROL_0: |
| 520 | vfd_control_0 = ptr[i + 1]; |
| 521 | break; |
| 522 | case A3XX_VFD_INDEX_MAX: |
| 523 | vfd_index_max = ptr[i + 1]; |
| 524 | break; |
| 525 | case A3XX_VSC_SIZE_ADDRESS: |
| 526 | vsc_size_address = ptr[i + 1]; |
| 527 | break; |
| 528 | case A3XX_SP_VS_PVT_MEM_ADDR_REG: |
| 529 | sp_vs_pvt_mem_addr = ptr[i + 1]; |
| 530 | break; |
| 531 | case A3XX_SP_FS_PVT_MEM_ADDR_REG: |
| 532 | sp_fs_pvt_mem_addr = ptr[i + 1]; |
| 533 | break; |
| Shubhraprakash Das | 49f6ce1 | 2013-05-28 17:10:56 -0600 | [diff] [blame] | 534 | case A3XX_SP_VS_OBJ_START_REG: |
| 535 | sp_vs_obj_start_reg = ptr[i + 1]; |
| 536 | break; |
| 537 | case A3XX_SP_FS_OBJ_START_REG: |
| 538 | sp_fs_obj_start_reg = ptr[i + 1]; |
| 539 | break; |
| Jordan Crouse | e0879b1 | 2012-03-16 14:53:43 -0600 | [diff] [blame] | 540 | } |
| 541 | } |
| Jordan Crouse | ea2c638 | 2012-03-16 14:53:42 -0600 | [diff] [blame] | 542 | } |
| 543 | } |
| 544 | |
| Jordan Crouse | 2dc227b | 2013-05-28 17:10:34 -0600 | [diff] [blame] | 545 | static inline int parse_ib(struct kgsl_device *device, unsigned int ptbase, |
| 546 | unsigned int gpuaddr, unsigned int dwords); |
| 547 | |
| Jordan Crouse | f99f5a66 | 2012-03-16 14:53:43 -0600 | [diff] [blame] | 548 | /* Add an IB as a GPU object, but first, parse it to find more goodies within */ |
| 549 | |
| Jordan Crouse | 2cf6ec9 | 2013-02-14 14:46:11 -0700 | [diff] [blame] | 550 | static int ib_add_gpu_object(struct kgsl_device *device, unsigned int ptbase, |
| Jordan Crouse | f99f5a66 | 2012-03-16 14:53:43 -0600 | [diff] [blame] | 551 | unsigned int gpuaddr, unsigned int dwords) |
| 552 | { |
| Jordan Crouse | 17d6d8b | 2012-04-18 09:31:09 -0600 | [diff] [blame] | 553 | int i, ret, rem = dwords; |
| Jordan Crouse | 21aaadf | 2012-09-11 16:38:15 -0600 | [diff] [blame] | 554 | unsigned int *src; |
| 555 | |
| 556 | /* |
| 557 | * If the object is already in the list, we don't need to parse it again |
| 558 | */ |
| 559 | |
| 560 | if (kgsl_snapshot_have_object(device, ptbase, gpuaddr, dwords << 2)) |
| Jordan Crouse | 2cf6ec9 | 2013-02-14 14:46:11 -0700 | [diff] [blame] | 561 | return 0; |
| Jordan Crouse | 21aaadf | 2012-09-11 16:38:15 -0600 | [diff] [blame] | 562 | |
| 563 | src = (unsigned int *) adreno_convertaddr(device, ptbase, gpuaddr, |
| 564 | dwords << 2); |
| Jordan Crouse | f99f5a66 | 2012-03-16 14:53:43 -0600 | [diff] [blame] | 565 | |
| 566 | if (src == NULL) |
| Jordan Crouse | 2cf6ec9 | 2013-02-14 14:46:11 -0700 | [diff] [blame] | 567 | return -EINVAL; |
| Jordan Crouse | f99f5a66 | 2012-03-16 14:53:43 -0600 | [diff] [blame] | 568 | |
| Jordan Crouse | 21aaadf | 2012-09-11 16:38:15 -0600 | [diff] [blame] | 569 | for (i = 0; rem > 0; rem--, i++) { |
| Jordan Crouse | 17d6d8b | 2012-04-18 09:31:09 -0600 | [diff] [blame] | 570 | int pktsize; |
| 571 | |
| Jordan Crouse | 21aaadf | 2012-09-11 16:38:15 -0600 | [diff] [blame] | 572 | /* If the packet isn't a type 1 or a type 3, then don't bother |
| 573 | * parsing it - it is likely corrupted */ |
| 574 | |
| Jordan Crouse | 17d6d8b | 2012-04-18 09:31:09 -0600 | [diff] [blame] | 575 | if (!pkt_is_type0(src[i]) && !pkt_is_type3(src[i])) |
| Jordan Crouse | 21aaadf | 2012-09-11 16:38:15 -0600 | [diff] [blame] | 576 | break; |
| Jordan Crouse | 17d6d8b | 2012-04-18 09:31:09 -0600 | [diff] [blame] | 577 | |
| 578 | pktsize = type3_pkt_size(src[i]); |
| 579 | |
| Jordan Crouse | 21aaadf | 2012-09-11 16:38:15 -0600 | [diff] [blame] | 580 | if (!pktsize || (pktsize + 1) > rem) |
| Jordan Crouse | 17d6d8b | 2012-04-18 09:31:09 -0600 | [diff] [blame] | 581 | break; |
| Jordan Crouse | e0879b1 | 2012-03-16 14:53:43 -0600 | [diff] [blame] | 582 | |
| Jordan Crouse | f99f5a66 | 2012-03-16 14:53:43 -0600 | [diff] [blame] | 583 | if (pkt_is_type3(src[i])) { |
| Jordan Crouse | 3bbb56e | 2012-10-25 09:37:40 -0600 | [diff] [blame] | 584 | if (adreno_cmd_is_ib(src[i])) { |
| 585 | unsigned int gpuaddr = src[i + 1]; |
| 586 | unsigned int size = src[i + 2]; |
| Jordan Crouse | 3bbb56e | 2012-10-25 09:37:40 -0600 | [diff] [blame] | 587 | |
| Jordan Crouse | 2dc227b | 2013-05-28 17:10:34 -0600 | [diff] [blame] | 588 | ret = parse_ib(device, ptbase, gpuaddr, size); |
| Jordan Crouse | 3bbb56e | 2012-10-25 09:37:40 -0600 | [diff] [blame] | 589 | |
| Jordan Crouse | 2dc227b | 2013-05-28 17:10:34 -0600 | [diff] [blame] | 590 | /* If adding the IB failed then stop parsing */ |
| 591 | if (ret < 0) |
| 592 | goto done; |
| Jordan Crouse | 2cf6ec9 | 2013-02-14 14:46:11 -0700 | [diff] [blame] | 593 | } else { |
| 594 | ret = ib_parse_type3(device, &src[i], ptbase); |
| 595 | /* |
| 596 | * If the parse function failed (probably |
| 597 | * because of a bad decode) then bail out and |
| 598 | * just capture the binary IB data |
| 599 | */ |
| 600 | |
| 601 | if (ret < 0) |
| 602 | goto done; |
| 603 | } |
| Jordan Crouse | e0879b1 | 2012-03-16 14:53:43 -0600 | [diff] [blame] | 604 | } else if (pkt_is_type0(src[i])) { |
| 605 | ib_parse_type0(device, &src[i], ptbase); |
| Jordan Crouse | f99f5a66 | 2012-03-16 14:53:43 -0600 | [diff] [blame] | 606 | } |
| Jordan Crouse | e0879b1 | 2012-03-16 14:53:43 -0600 | [diff] [blame] | 607 | |
| Jordan Crouse | 17d6d8b | 2012-04-18 09:31:09 -0600 | [diff] [blame] | 608 | i += pktsize; |
| 609 | rem -= pktsize; |
| Jordan Crouse | f99f5a66 | 2012-03-16 14:53:43 -0600 | [diff] [blame] | 610 | } |
| 611 | |
| Jordan Crouse | 2cf6ec9 | 2013-02-14 14:46:11 -0700 | [diff] [blame] | 612 | done: |
| Jordan Crouse | f99f5a66 | 2012-03-16 14:53:43 -0600 | [diff] [blame] | 613 | ret = kgsl_snapshot_get_object(device, ptbase, gpuaddr, dwords << 2, |
| 614 | SNAPSHOT_GPU_OBJECT_IB); |
| 615 | |
| Jordan Crouse | 2cf6ec9 | 2013-02-14 14:46:11 -0700 | [diff] [blame] | 616 | if (ret >= 0) |
| 617 | snapshot_frozen_objsize += ret; |
| 618 | |
| 619 | return ret; |
| Jordan Crouse | f99f5a66 | 2012-03-16 14:53:43 -0600 | [diff] [blame] | 620 | } |
| 621 | |
| Jordan Crouse | 2dc227b | 2013-05-28 17:10:34 -0600 | [diff] [blame] | 622 | /* |
| 623 | * We want to store the last executed IB1 and IB2 in the static region to ensure |
| 624 | * that we get at least some information out of the snapshot even if we can't |
| 625 | * access the dynamic data from the sysfs file. Push all other IBs on the |
| 626 | * dynamic list |
| 627 | */ |
| 628 | static inline int parse_ib(struct kgsl_device *device, unsigned int ptbase, |
| 629 | unsigned int gpuaddr, unsigned int dwords) |
| 630 | { |
| 631 | unsigned int ib1base, ib2base; |
| 632 | int ret = 0; |
| 633 | |
| 634 | /* |
| 635 | * Check the IB address - if it is either the last executed IB1 or the |
| 636 | * last executed IB2 then push it into the static blob otherwise put |
| 637 | * it in the dynamic list |
| 638 | */ |
| 639 | |
| 640 | kgsl_regread(device, REG_CP_IB1_BASE, &ib1base); |
| 641 | kgsl_regread(device, REG_CP_IB2_BASE, &ib2base); |
| 642 | |
| 643 | if (gpuaddr == ib1base || gpuaddr == ib2base) |
| 644 | push_object(device, SNAPSHOT_OBJ_TYPE_IB, ptbase, |
| 645 | gpuaddr, dwords); |
| 646 | else |
| 647 | ret = ib_add_gpu_object(device, ptbase, gpuaddr, dwords); |
| 648 | |
| 649 | return ret; |
| 650 | } |
| 651 | |
| Jordan Crouse | 156cfbc | 2012-01-24 09:32:04 -0700 | [diff] [blame] | 652 | /* Snapshot the ringbuffer memory */ |
| 653 | static int snapshot_rb(struct kgsl_device *device, void *snapshot, |
| 654 | int remain, void *priv) |
| 655 | { |
| 656 | struct kgsl_snapshot_rb *header = snapshot; |
| 657 | unsigned int *data = snapshot + sizeof(*header); |
| 658 | struct adreno_device *adreno_dev = ADRENO_DEVICE(device); |
| 659 | struct adreno_ringbuffer *rb = &adreno_dev->ringbuffer; |
| Jordan Crouse | e6b7762 | 2012-04-05 16:55:54 -0600 | [diff] [blame] | 660 | unsigned int ptbase, rptr, *rbptr, ibbase; |
| 661 | int index, size, i; |
| Jordan Crouse | e9e91bf | 2012-02-21 09:48:36 -0700 | [diff] [blame] | 662 | int parse_ibs = 0, ib_parse_start; |
| Jordan Crouse | 156cfbc | 2012-01-24 09:32:04 -0700 | [diff] [blame] | 663 | |
| 664 | /* Get the physical address of the MMU pagetable */ |
| Shubhraprakash Das | 7944795 | 2012-04-26 18:12:23 -0600 | [diff] [blame] | 665 | ptbase = kgsl_mmu_get_current_ptbase(&device->mmu); |
| Jordan Crouse | 156cfbc | 2012-01-24 09:32:04 -0700 | [diff] [blame] | 666 | |
| 667 | /* Get the current read pointers for the RB */ |
| 668 | kgsl_regread(device, REG_CP_RB_RPTR, &rptr); |
| 669 | |
| Jordan Crouse | e6b7762 | 2012-04-05 16:55:54 -0600 | [diff] [blame] | 670 | /* Address of the last processed IB */ |
| Jordan Crouse | f99f5a66 | 2012-03-16 14:53:43 -0600 | [diff] [blame] | 671 | kgsl_regread(device, REG_CP_IB1_BASE, &ibbase); |
| 672 | |
| Jordan Crouse | 156cfbc | 2012-01-24 09:32:04 -0700 | [diff] [blame] | 673 | /* |
| Jordan Crouse | e6b7762 | 2012-04-05 16:55:54 -0600 | [diff] [blame] | 674 | * Figure out the window of ringbuffer data to dump. First we need to |
| Jordan Crouse | 6c214ba6 | 2012-06-20 08:22:16 -0600 | [diff] [blame] | 675 | * find where the last processed IB ws submitted. Start walking back |
| 676 | * from the rptr |
| Jordan Crouse | 156cfbc | 2012-01-24 09:32:04 -0700 | [diff] [blame] | 677 | */ |
| 678 | |
| Jordan Crouse | e6b7762 | 2012-04-05 16:55:54 -0600 | [diff] [blame] | 679 | index = rptr; |
| 680 | rbptr = rb->buffer_desc.hostptr; |
| Jordan Crouse | 156cfbc | 2012-01-24 09:32:04 -0700 | [diff] [blame] | 681 | |
| Jordan Crouse | 6c214ba6 | 2012-06-20 08:22:16 -0600 | [diff] [blame] | 682 | do { |
| Jordan Crouse | e6b7762 | 2012-04-05 16:55:54 -0600 | [diff] [blame] | 683 | index--; |
| Jordan Crouse | 156cfbc | 2012-01-24 09:32:04 -0700 | [diff] [blame] | 684 | |
| Jordan Crouse | e6b7762 | 2012-04-05 16:55:54 -0600 | [diff] [blame] | 685 | if (index < 0) { |
| 686 | index = rb->sizedwords - 3; |
| Jordan Crouse | 156cfbc | 2012-01-24 09:32:04 -0700 | [diff] [blame] | 687 | |
| Jordan Crouse | e6b7762 | 2012-04-05 16:55:54 -0600 | [diff] [blame] | 688 | /* We wrapped without finding what we wanted */ |
| 689 | if (index < rb->wptr) { |
| 690 | index = rb->wptr; |
| 691 | break; |
| 692 | } |
| 693 | } |
| 694 | |
| 695 | if (adreno_cmd_is_ib(rbptr[index]) && |
| 696 | rbptr[index + 1] == ibbase) |
| 697 | break; |
| Jordan Crouse | 6c214ba6 | 2012-06-20 08:22:16 -0600 | [diff] [blame] | 698 | } while (index != rb->wptr); |
| Jordan Crouse | e6b7762 | 2012-04-05 16:55:54 -0600 | [diff] [blame] | 699 | |
| 700 | /* |
| 701 | * index points at the last submitted IB. We can only trust that the |
| 702 | * memory between the context switch and the hanging IB is valid, so |
| 703 | * the next step is to find the context switch before the submission |
| 704 | */ |
| 705 | |
| 706 | while (index != rb->wptr) { |
| 707 | index--; |
| 708 | |
| Jordan Crouse | 17d6d8b | 2012-04-18 09:31:09 -0600 | [diff] [blame] | 709 | if (index < 0) { |
| Jordan Crouse | e6b7762 | 2012-04-05 16:55:54 -0600 | [diff] [blame] | 710 | index = rb->sizedwords - 2; |
| 711 | |
| 712 | /* |
| 713 | * Wrapped without finding the context switch. This is |
| 714 | * harmless - we should still have enough data to dump a |
| 715 | * valid state |
| 716 | */ |
| 717 | |
| 718 | if (index < rb->wptr) { |
| 719 | index = rb->wptr; |
| 720 | break; |
| 721 | } |
| 722 | } |
| 723 | |
| 724 | /* Break if the current packet is a context switch identifier */ |
| Jordan Crouse | 17d6d8b | 2012-04-18 09:31:09 -0600 | [diff] [blame] | 725 | if ((rbptr[index] == cp_nop_packet(1)) && |
| 726 | (rbptr[index + 1] == KGSL_CONTEXT_TO_MEM_IDENTIFIER)) |
| Jordan Crouse | e6b7762 | 2012-04-05 16:55:54 -0600 | [diff] [blame] | 727 | break; |
| 728 | } |
| 729 | |
| 730 | /* |
| 731 | * Index represents the start of the window of interest. We will try |
| 732 | * to dump all buffers between here and the rptr |
| 733 | */ |
| 734 | |
| 735 | ib_parse_start = index; |
| 736 | |
| 737 | /* |
| 738 | * Dump the entire ringbuffer - the parser can choose how much of it to |
| 739 | * process |
| 740 | */ |
| 741 | |
| 742 | size = (rb->sizedwords << 2); |
| Jordan Crouse | 156cfbc | 2012-01-24 09:32:04 -0700 | [diff] [blame] | 743 | |
| 744 | if (remain < size + sizeof(*header)) { |
| 745 | KGSL_DRV_ERR(device, |
| 746 | "snapshot: Not enough memory for the rb section"); |
| 747 | return 0; |
| 748 | } |
| 749 | |
| 750 | /* Write the sub-header for the section */ |
| Jordan Crouse | e6b7762 | 2012-04-05 16:55:54 -0600 | [diff] [blame] | 751 | header->start = rb->wptr; |
| 752 | header->end = rb->wptr; |
| Jordan Crouse | 156cfbc | 2012-01-24 09:32:04 -0700 | [diff] [blame] | 753 | header->wptr = rb->wptr; |
| 754 | header->rbsize = rb->sizedwords; |
| Jordan Crouse | e6b7762 | 2012-04-05 16:55:54 -0600 | [diff] [blame] | 755 | header->count = rb->sizedwords; |
| Jordan Crouse | e9e91bf | 2012-02-21 09:48:36 -0700 | [diff] [blame] | 756 | |
| Jordan Crouse | 156cfbc | 2012-01-24 09:32:04 -0700 | [diff] [blame] | 757 | /* |
| 758 | * Loop through the RB, copying the data and looking for indirect |
| 759 | * buffers and MMU pagetable changes |
| 760 | */ |
| 761 | |
| Jordan Crouse | e6b7762 | 2012-04-05 16:55:54 -0600 | [diff] [blame] | 762 | index = rb->wptr; |
| 763 | for (i = 0; i < rb->sizedwords; i++) { |
| Jordan Crouse | 156cfbc | 2012-01-24 09:32:04 -0700 | [diff] [blame] | 764 | *data = rbptr[index]; |
| 765 | |
| Jordan Crouse | e6b7762 | 2012-04-05 16:55:54 -0600 | [diff] [blame] | 766 | /* |
| Jordan Crouse | e6b7762 | 2012-04-05 16:55:54 -0600 | [diff] [blame] | 767 | * Only parse IBs between the start and the rptr or the next |
| 768 | * context switch, whichever comes first |
| 769 | */ |
| Jordan Crouse | e9e91bf | 2012-02-21 09:48:36 -0700 | [diff] [blame] | 770 | |
| Jordan Crouse | 21aaadf | 2012-09-11 16:38:15 -0600 | [diff] [blame] | 771 | if (parse_ibs == 0 && index == ib_parse_start) |
| Jordan Crouse | e9e91bf | 2012-02-21 09:48:36 -0700 | [diff] [blame] | 772 | parse_ibs = 1; |
| Jordan Crouse | e6b7762 | 2012-04-05 16:55:54 -0600 | [diff] [blame] | 773 | else if (index == rptr || adreno_rb_ctxtswitch(&rbptr[index])) |
| Jordan Crouse | e9e91bf | 2012-02-21 09:48:36 -0700 | [diff] [blame] | 774 | parse_ibs = 0; |
| 775 | |
| Jordan Crouse | f99f5a66 | 2012-03-16 14:53:43 -0600 | [diff] [blame] | 776 | if (parse_ibs && adreno_cmd_is_ib(rbptr[index])) { |
| Jordan Crouse | 233b209 | 2012-04-18 09:31:09 -0600 | [diff] [blame] | 777 | unsigned int ibaddr = rbptr[index + 1]; |
| 778 | unsigned int ibsize = rbptr[index + 2]; |
| 779 | |
| Jordan Crouse | f99f5a66 | 2012-03-16 14:53:43 -0600 | [diff] [blame] | 780 | /* |
| Jordan Crouse | 233b209 | 2012-04-18 09:31:09 -0600 | [diff] [blame] | 781 | * This will return non NULL if the IB happens to be |
| 782 | * part of the context memory (i.e - context switch |
| 783 | * command buffers) |
| 784 | */ |
| 785 | |
| 786 | struct kgsl_memdesc *memdesc = |
| 787 | adreno_find_ctxtmem(device, ptbase, ibaddr, |
| Jordan Crouse | 35ed68f | 2013-05-28 17:08:29 -0600 | [diff] [blame] | 788 | ibsize << 2); |
| Jordan Crouse | 233b209 | 2012-04-18 09:31:09 -0600 | [diff] [blame] | 789 | |
| Shubhraprakash Das | 3d784f5 | 2012-06-06 23:12:11 -0600 | [diff] [blame] | 790 | /* IOMMU uses a NOP IB placed in setsate memory */ |
| 791 | if (NULL == memdesc) |
| 792 | if (kgsl_gpuaddr_in_memdesc( |
| 793 | &device->mmu.setstate_memory, |
| Jordan Crouse | 35ed68f | 2013-05-28 17:08:29 -0600 | [diff] [blame] | 794 | ibaddr, ibsize << 2)) |
| Shubhraprakash Das | 3d784f5 | 2012-06-06 23:12:11 -0600 | [diff] [blame] | 795 | memdesc = &device->mmu.setstate_memory; |
| Jordan Crouse | 233b209 | 2012-04-18 09:31:09 -0600 | [diff] [blame] | 796 | /* |
| 797 | * The IB from CP_IB1_BASE and the IBs for legacy |
| 798 | * context switch go into the snapshot all |
| Jordan Crouse | f99f5a66 | 2012-03-16 14:53:43 -0600 | [diff] [blame] | 799 | * others get marked at GPU objects |
| 800 | */ |
| Jordan Crouse | 233b209 | 2012-04-18 09:31:09 -0600 | [diff] [blame] | 801 | |
| Jordan Crouse | 2dc227b | 2013-05-28 17:10:34 -0600 | [diff] [blame] | 802 | if (memdesc != NULL) |
| Jordan Crouse | f99f5a66 | 2012-03-16 14:53:43 -0600 | [diff] [blame] | 803 | push_object(device, SNAPSHOT_OBJ_TYPE_IB, |
| Jordan Crouse | 233b209 | 2012-04-18 09:31:09 -0600 | [diff] [blame] | 804 | ptbase, ibaddr, ibsize); |
| Jordan Crouse | f99f5a66 | 2012-03-16 14:53:43 -0600 | [diff] [blame] | 805 | else |
| Jordan Crouse | 2dc227b | 2013-05-28 17:10:34 -0600 | [diff] [blame] | 806 | parse_ib(device, ptbase, ibaddr, ibsize); |
| Jordan Crouse | f99f5a66 | 2012-03-16 14:53:43 -0600 | [diff] [blame] | 807 | } |
| Jordan Crouse | 156cfbc | 2012-01-24 09:32:04 -0700 | [diff] [blame] | 808 | |
| Jordan Crouse | 156cfbc | 2012-01-24 09:32:04 -0700 | [diff] [blame] | 809 | index = index + 1; |
| 810 | |
| 811 | if (index == rb->sizedwords) |
| 812 | index = 0; |
| 813 | |
| 814 | data++; |
| 815 | } |
| 816 | |
| Jordan Crouse | 156cfbc | 2012-01-24 09:32:04 -0700 | [diff] [blame] | 817 | /* Return the size of the section */ |
| 818 | return size + sizeof(*header); |
| 819 | } |
| 820 | |
| Shubhraprakash Das | e87e3df | 2013-01-17 00:53:26 -0800 | [diff] [blame] | 821 | static int snapshot_capture_mem_list(struct kgsl_device *device, void *snapshot, |
| 822 | int remain, void *priv) |
| 823 | { |
| 824 | struct kgsl_snapshot_replay_mem_list *header = snapshot; |
| 825 | struct kgsl_process_private *private; |
| 826 | unsigned int ptbase; |
| 827 | struct rb_node *node; |
| 828 | struct kgsl_mem_entry *entry = NULL; |
| 829 | int num_mem; |
| 830 | unsigned int *data = snapshot + sizeof(*header); |
| 831 | |
| 832 | ptbase = kgsl_mmu_get_current_ptbase(&device->mmu); |
| 833 | mutex_lock(&kgsl_driver.process_mutex); |
| 834 | list_for_each_entry(private, &kgsl_driver.process_list, list) { |
| 835 | if (kgsl_mmu_pt_equal(&device->mmu, private->pagetable, |
| 836 | ptbase)) |
| 837 | break; |
| 838 | } |
| 839 | mutex_unlock(&kgsl_driver.process_mutex); |
| 840 | if (!private) { |
| 841 | KGSL_DRV_ERR(device, |
| 842 | "Failed to get pointer to process private structure\n"); |
| 843 | return 0; |
| 844 | } |
| 845 | /* We need to know the number of memory objects that the process has */ |
| 846 | spin_lock(&private->mem_lock); |
| 847 | for (node = rb_first(&private->mem_rb), num_mem = 0; node; ) { |
| 848 | entry = rb_entry(node, struct kgsl_mem_entry, node); |
| 849 | node = rb_next(&entry->node); |
| 850 | num_mem++; |
| 851 | } |
| 852 | |
| 853 | if (remain < ((num_mem * 3 * sizeof(unsigned int)) + |
| 854 | sizeof(*header))) { |
| 855 | KGSL_DRV_ERR(device, |
| 856 | "snapshot: Not enough memory for the mem list section"); |
| 857 | spin_unlock(&private->mem_lock); |
| 858 | return 0; |
| 859 | } |
| 860 | header->num_entries = num_mem; |
| 861 | header->ptbase = ptbase; |
| 862 | /* |
| 863 | * Walk throught the memory list and store the |
| 864 | * tuples(gpuaddr, size, memtype) in snapshot |
| 865 | */ |
| 866 | for (node = rb_first(&private->mem_rb); node; ) { |
| 867 | entry = rb_entry(node, struct kgsl_mem_entry, node); |
| 868 | node = rb_next(&entry->node); |
| 869 | |
| 870 | *data++ = entry->memdesc.gpuaddr; |
| 871 | *data++ = entry->memdesc.size; |
| 872 | *data++ = (entry->memdesc.priv & KGSL_MEMTYPE_MASK) >> |
| 873 | KGSL_MEMTYPE_SHIFT; |
| 874 | } |
| 875 | spin_unlock(&private->mem_lock); |
| 876 | return sizeof(*header) + (num_mem * 3 * sizeof(unsigned int)); |
| 877 | } |
| 878 | |
| Jordan Crouse | e0879b1 | 2012-03-16 14:53:43 -0600 | [diff] [blame] | 879 | /* Snapshot the memory for an indirect buffer */ |
| Jordan Crouse | 156cfbc | 2012-01-24 09:32:04 -0700 | [diff] [blame] | 880 | static int snapshot_ib(struct kgsl_device *device, void *snapshot, |
| 881 | int remain, void *priv) |
| 882 | { |
| 883 | struct kgsl_snapshot_ib *header = snapshot; |
| 884 | struct kgsl_snapshot_obj *obj = priv; |
| 885 | unsigned int *src = obj->ptr; |
| 886 | unsigned int *dst = snapshot + sizeof(*header); |
| Jordan Crouse | 2cf6ec9 | 2013-02-14 14:46:11 -0700 | [diff] [blame] | 887 | int i, ret; |
| Jordan Crouse | 156cfbc | 2012-01-24 09:32:04 -0700 | [diff] [blame] | 888 | |
| 889 | if (remain < (obj->dwords << 2) + sizeof(*header)) { |
| 890 | KGSL_DRV_ERR(device, |
| 891 | "snapshot: Not enough memory for the ib section"); |
| 892 | return 0; |
| 893 | } |
| 894 | |
| 895 | /* Write the sub-header for the section */ |
| 896 | header->gpuaddr = obj->gpuaddr; |
| 897 | header->ptbase = obj->ptbase; |
| 898 | header->size = obj->dwords; |
| 899 | |
| 900 | /* Write the contents of the ib */ |
| Jordan Crouse | ea2c638 | 2012-03-16 14:53:42 -0600 | [diff] [blame] | 901 | for (i = 0; i < obj->dwords; i++, src++, dst++) { |
| Jordan Crouse | 156cfbc | 2012-01-24 09:32:04 -0700 | [diff] [blame] | 902 | *dst = *src; |
| Jordan Crouse | 156cfbc | 2012-01-24 09:32:04 -0700 | [diff] [blame] | 903 | |
| Jordan Crouse | ea2c638 | 2012-03-16 14:53:42 -0600 | [diff] [blame] | 904 | if (pkt_is_type3(*src)) { |
| 905 | if ((obj->dwords - i) < type3_pkt_size(*src) + 1) |
| 906 | continue; |
| Jordan Crouse | 156cfbc | 2012-01-24 09:32:04 -0700 | [diff] [blame] | 907 | |
| Jordan Crouse | ea2c638 | 2012-03-16 14:53:42 -0600 | [diff] [blame] | 908 | if (adreno_cmd_is_ib(*src)) |
| Jordan Crouse | 2dc227b | 2013-05-28 17:10:34 -0600 | [diff] [blame] | 909 | ret = parse_ib(device, obj->ptbase, src[1], |
| 910 | src[2]); |
| 911 | else |
| Jordan Crouse | 2cf6ec9 | 2013-02-14 14:46:11 -0700 | [diff] [blame] | 912 | ret = ib_parse_type3(device, src, obj->ptbase); |
| 913 | |
| Jordan Crouse | 2dc227b | 2013-05-28 17:10:34 -0600 | [diff] [blame] | 914 | /* Stop parsing if the type3 decode fails */ |
| 915 | if (ret < 0) |
| 916 | break; |
| Jordan Crouse | ea2c638 | 2012-03-16 14:53:42 -0600 | [diff] [blame] | 917 | } |
| Jordan Crouse | 156cfbc | 2012-01-24 09:32:04 -0700 | [diff] [blame] | 918 | } |
| 919 | |
| 920 | return (obj->dwords << 2) + sizeof(*header); |
| 921 | } |
| 922 | |
| 923 | /* Dump another item on the current pending list */ |
| 924 | static void *dump_object(struct kgsl_device *device, int obj, void *snapshot, |
| 925 | int *remain) |
| 926 | { |
| 927 | switch (objbuf[obj].type) { |
| 928 | case SNAPSHOT_OBJ_TYPE_IB: |
| 929 | snapshot = kgsl_snapshot_add_section(device, |
| 930 | KGSL_SNAPSHOT_SECTION_IB, snapshot, remain, |
| 931 | snapshot_ib, &objbuf[obj]); |
| 932 | break; |
| 933 | default: |
| 934 | KGSL_DRV_ERR(device, |
| 935 | "snapshot: Invalid snapshot object type: %d\n", |
| 936 | objbuf[obj].type); |
| 937 | break; |
| 938 | } |
| 939 | |
| 940 | return snapshot; |
| 941 | } |
| 942 | |
| 943 | /* adreno_snapshot - Snapshot the Adreno GPU state |
| 944 | * @device - KGSL device to snapshot |
| 945 | * @snapshot - Pointer to the start of memory to write into |
| 946 | * @remain - A pointer to how many bytes of memory are remaining in the snapshot |
| 947 | * @hang - set if this snapshot was automatically triggered by a GPU hang |
| 948 | * This is a hook function called by kgsl_snapshot to snapshot the |
| 949 | * Adreno specific information for the GPU snapshot. In turn, this function |
| 950 | * calls the GPU specific snapshot function to get core specific information. |
| 951 | */ |
| 952 | |
| 953 | void *adreno_snapshot(struct kgsl_device *device, void *snapshot, int *remain, |
| 954 | int hang) |
| 955 | { |
| 956 | int i; |
| 957 | uint32_t ptbase, ibbase, ibsize; |
| 958 | struct adreno_device *adreno_dev = ADRENO_DEVICE(device); |
| 959 | |
| 960 | /* Reset the list of objects */ |
| 961 | objbufptr = 0; |
| 962 | |
| Jordan Crouse | 9610b6b | 2012-03-16 14:53:42 -0600 | [diff] [blame] | 963 | snapshot_frozen_objsize = 0; |
| 964 | |
| Jordan Crouse | e0879b1 | 2012-03-16 14:53:43 -0600 | [diff] [blame] | 965 | /* Clear the caches for the visibilty stream and VBO parsing */ |
| 966 | |
| 967 | vfd_control_0 = 0; |
| 968 | vfd_index_max = 0; |
| 969 | vsc_size_address = 0; |
| 970 | |
| 971 | memset(vsc_pipe, 0, sizeof(vsc_pipe)); |
| 972 | memset(vbo, 0, sizeof(vbo)); |
| 973 | |
| Jordan Crouse | 156cfbc | 2012-01-24 09:32:04 -0700 | [diff] [blame] | 974 | /* Get the physical address of the MMU pagetable */ |
| Shubhraprakash Das | 7944795 | 2012-04-26 18:12:23 -0600 | [diff] [blame] | 975 | ptbase = kgsl_mmu_get_current_ptbase(&device->mmu); |
| Jordan Crouse | 156cfbc | 2012-01-24 09:32:04 -0700 | [diff] [blame] | 976 | |
| 977 | /* Dump the ringbuffer */ |
| 978 | snapshot = kgsl_snapshot_add_section(device, KGSL_SNAPSHOT_SECTION_RB, |
| 979 | snapshot, remain, snapshot_rb, NULL); |
| 980 | |
| 981 | /* |
| Shubhraprakash Das | e87e3df | 2013-01-17 00:53:26 -0800 | [diff] [blame] | 982 | * Add a section that lists (gpuaddr, size, memtype) tuples of the |
| 983 | * hanging process |
| 984 | */ |
| 985 | snapshot = kgsl_snapshot_add_section(device, |
| 986 | KGSL_SNAPSHOT_SECTION_MEMLIST, snapshot, remain, |
| 987 | snapshot_capture_mem_list, NULL); |
| 988 | /* |
| Jordan Crouse | e9e91bf | 2012-02-21 09:48:36 -0700 | [diff] [blame] | 989 | * Make sure that the last IB1 that was being executed is dumped. |
| 990 | * Since this was the last IB1 that was processed, we should have |
| 991 | * already added it to the list during the ringbuffer parse but we |
| 992 | * want to be double plus sure. |
| Jordan Crouse | 156cfbc | 2012-01-24 09:32:04 -0700 | [diff] [blame] | 993 | */ |
| Jordan Crouse | e9e91bf | 2012-02-21 09:48:36 -0700 | [diff] [blame] | 994 | |
| Jordan Crouse | 156cfbc | 2012-01-24 09:32:04 -0700 | [diff] [blame] | 995 | kgsl_regread(device, REG_CP_IB1_BASE, &ibbase); |
| 996 | kgsl_regread(device, REG_CP_IB1_BUFSZ, &ibsize); |
| 997 | |
| Jordan Crouse | e9e91bf | 2012-02-21 09:48:36 -0700 | [diff] [blame] | 998 | /* |
| 999 | * The problem is that IB size from the register is the unprocessed size |
| 1000 | * of the buffer not the original size, so if we didn't catch this |
| 1001 | * buffer being directly used in the RB, then we might not be able to |
| 1002 | * dump the whle thing. Print a warning message so we can try to |
| 1003 | * figure how often this really happens. |
| 1004 | */ |
| 1005 | |
| 1006 | if (!find_object(SNAPSHOT_OBJ_TYPE_IB, ibbase, ptbase) && ibsize) { |
| Jordan Crouse | 156cfbc | 2012-01-24 09:32:04 -0700 | [diff] [blame] | 1007 | push_object(device, SNAPSHOT_OBJ_TYPE_IB, ptbase, |
| 1008 | ibbase, ibsize); |
| Jordan Crouse | e9e91bf | 2012-02-21 09:48:36 -0700 | [diff] [blame] | 1009 | KGSL_DRV_ERR(device, "CP_IB1_BASE not found in the ringbuffer. " |
| 1010 | "Dumping %x dwords of the buffer.\n", ibsize); |
| 1011 | } |
| Jordan Crouse | 156cfbc | 2012-01-24 09:32:04 -0700 | [diff] [blame] | 1012 | |
| 1013 | kgsl_regread(device, REG_CP_IB2_BASE, &ibbase); |
| 1014 | kgsl_regread(device, REG_CP_IB2_BUFSZ, &ibsize); |
| 1015 | |
| Jordan Crouse | e9e91bf | 2012-02-21 09:48:36 -0700 | [diff] [blame] | 1016 | /* |
| 1017 | * Add the last parsed IB2 to the list. The IB2 should be found as we |
| 1018 | * parse the objects below, but we try to add it to the list first, so |
| 1019 | * it too can be parsed. Don't print an error message in this case - if |
| 1020 | * the IB2 is found during parsing, the list will be updated with the |
| 1021 | * correct size. |
| 1022 | */ |
| 1023 | |
| 1024 | if (!find_object(SNAPSHOT_OBJ_TYPE_IB, ibbase, ptbase) && ibsize) { |
| Jordan Crouse | 156cfbc | 2012-01-24 09:32:04 -0700 | [diff] [blame] | 1025 | push_object(device, SNAPSHOT_OBJ_TYPE_IB, ptbase, |
| 1026 | ibbase, ibsize); |
| Jordan Crouse | e9e91bf | 2012-02-21 09:48:36 -0700 | [diff] [blame] | 1027 | } |
| Jordan Crouse | 156cfbc | 2012-01-24 09:32:04 -0700 | [diff] [blame] | 1028 | |
| 1029 | /* |
| 1030 | * Go through the list of found objects and dump each one. As the IBs |
| 1031 | * are parsed, more objects might be found, and objbufptr will increase |
| 1032 | */ |
| 1033 | for (i = 0; i < objbufptr; i++) |
| 1034 | snapshot = dump_object(device, i, snapshot, remain); |
| 1035 | |
| Jordan Crouse | 156cfbc | 2012-01-24 09:32:04 -0700 | [diff] [blame] | 1036 | /* Add GPU specific sections - registers mainly, but other stuff too */ |
| 1037 | if (adreno_dev->gpudev->snapshot) |
| 1038 | snapshot = adreno_dev->gpudev->snapshot(adreno_dev, snapshot, |
| 1039 | remain, hang); |
| 1040 | |
| Jordan Crouse | 9610b6b | 2012-03-16 14:53:42 -0600 | [diff] [blame] | 1041 | if (snapshot_frozen_objsize) |
| 1042 | KGSL_DRV_ERR(device, "GPU snapshot froze %dKb of GPU buffers\n", |
| 1043 | snapshot_frozen_objsize / 1024); |
| 1044 | |
| Jordan Crouse | 156cfbc | 2012-01-24 09:32:04 -0700 | [diff] [blame] | 1045 | return snapshot; |
| 1046 | } |