Jordan Crouse | 156cfbc | 2012-01-24 09:32:04 -0700 | [diff] [blame] | 1 | /* Copyright (c) 2012, Code Aurora Forum. All rights reserved. |
| 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 | ea2c638 | 2012-03-16 14:53:42 -0600 | [diff] [blame] | 164 | static void ib_parse_load_state(struct kgsl_device *device, unsigned int *pkt, |
| 165 | unsigned int ptbase) |
| 166 | { |
| 167 | unsigned int block, source, type; |
| 168 | |
| 169 | /* |
| 170 | * The object here is to find indirect shaders i.e - shaders loaded from |
| 171 | * GPU memory instead of directly in the command. These should be added |
| 172 | * to the list of memory objects to dump. So look at the load state |
| 173 | * call and see if 1) the shader block is a shader (block = 4, 5 or 6) |
| 174 | * 2) that the block is indirect (source = 4). If these all match then |
| 175 | * add the memory address to the list. The size of the object will |
| 176 | * differ depending on the type. Type 0 (instructions) are 8 dwords per |
| 177 | * unit and type 1 (constants) are 2 dwords per unit. |
| 178 | */ |
| 179 | |
| 180 | if (type3_pkt_size(pkt[0]) < 2) |
| 181 | return; |
| 182 | |
| 183 | /* |
| 184 | * pkt[1] 18:16 - source |
| 185 | * pkt[1] 21:19 - state block |
| 186 | * pkt[1] 31:22 - size in units |
| 187 | * pkt[2] 0:1 - type |
| 188 | * pkt[2] 31:2 - GPU memory address |
| 189 | */ |
| 190 | |
| 191 | block = (pkt[1] >> 19) & 0x07; |
| 192 | source = (pkt[1] >> 16) & 0x07; |
| 193 | type = pkt[2] & 0x03; |
| 194 | |
| 195 | if ((block == 4 || block == 5 || block == 6) && source == 4) { |
| 196 | int unitsize = (type == 0) ? 8 : 2; |
| 197 | int ret; |
| 198 | |
| 199 | /* Freeze the GPU buffer containing the shader */ |
| 200 | |
| 201 | ret = kgsl_snapshot_get_object(device, ptbase, |
| 202 | pkt[2] & 0xFFFFFFFC, |
| 203 | (((pkt[1] >> 22) & 0x03FF) * unitsize) << 2, |
| 204 | SNAPSHOT_GPU_OBJECT_SHADER); |
| 205 | snapshot_frozen_objsize += ret; |
| 206 | } |
| 207 | } |
| 208 | |
| 209 | /* |
Jordan Crouse | e0879b1 | 2012-03-16 14:53:43 -0600 | [diff] [blame^] | 210 | * This opcode sets the base addresses for the visibilty stream buffer and the |
| 211 | * visiblity stream size buffer. |
| 212 | */ |
| 213 | |
| 214 | static void ib_parse_set_bin_data(struct kgsl_device *device, unsigned int *pkt, |
| 215 | unsigned int ptbase) |
| 216 | { |
| 217 | int ret; |
| 218 | |
| 219 | if (type3_pkt_size(pkt[0]) < 2) |
| 220 | return; |
| 221 | |
| 222 | /* Visiblity stream buffer */ |
| 223 | ret = kgsl_snapshot_get_object(device, ptbase, pkt[1], 0, |
| 224 | SNAPSHOT_GPU_OBJECT_GENERIC); |
| 225 | snapshot_frozen_objsize += ret; |
| 226 | |
| 227 | /* visiblity stream size buffer (fixed size 8 dwords) */ |
| 228 | ret = kgsl_snapshot_get_object(device, ptbase, pkt[2], 32, |
| 229 | SNAPSHOT_GPU_OBJECT_GENERIC); |
| 230 | snapshot_frozen_objsize += ret; |
| 231 | } |
| 232 | |
| 233 | /* |
| 234 | * This opcode writes to GPU memory - if the buffer is written to, there is a |
| 235 | * good chance that it would be valuable to capture in the snapshot, so mark all |
| 236 | * buffers that are written to as frozen |
| 237 | */ |
| 238 | |
| 239 | static void ib_parse_mem_write(struct kgsl_device *device, unsigned int *pkt, |
| 240 | unsigned int ptbase) |
| 241 | { |
| 242 | int ret; |
| 243 | |
| 244 | if (type3_pkt_size(pkt[0]) < 1) |
| 245 | return; |
| 246 | |
| 247 | /* |
| 248 | * The address is where the data in the rest of this packet is written |
| 249 | * to, but since that might be an offset into the larger buffer we need |
| 250 | * to get the whole thing. Pass a size of 0 kgsl_snapshot_get_object to |
| 251 | * capture the entire buffer. |
| 252 | */ |
| 253 | |
| 254 | ret = kgsl_snapshot_get_object(device, ptbase, pkt[1] & 0xFFFFFFFC, 0, |
| 255 | SNAPSHOT_GPU_OBJECT_GENERIC); |
| 256 | |
| 257 | snapshot_frozen_objsize += ret; |
| 258 | } |
| 259 | |
| 260 | /* |
| 261 | * The DRAW_INDX opcode sends a draw initator which starts a draw operation in |
| 262 | * the GPU, so this is the point where all the registers and buffers become |
| 263 | * "valid". The DRAW_INDX may also have an index buffer pointer that should be |
| 264 | * frozen with the others |
| 265 | */ |
| 266 | |
| 267 | static void ib_parse_draw_indx(struct kgsl_device *device, unsigned int *pkt, |
| 268 | unsigned int ptbase) |
| 269 | { |
| 270 | int ret, i; |
| 271 | |
| 272 | if (type3_pkt_size(pkt[0]) < 3) |
| 273 | return; |
| 274 | |
| 275 | /* DRAW_IDX may have a index buffer pointer */ |
| 276 | |
| 277 | if (type3_pkt_size(pkt[0]) > 3) { |
| 278 | ret = kgsl_snapshot_get_object(device, ptbase, pkt[4], pkt[5], |
| 279 | SNAPSHOT_GPU_OBJECT_GENERIC); |
| 280 | snapshot_frozen_objsize += ret; |
| 281 | } |
| 282 | |
| 283 | /* |
| 284 | * All of the type0 writes are valid at a draw initiator, so freeze |
| 285 | * the various buffers that we are tracking |
| 286 | */ |
| 287 | |
| 288 | /* First up the visiblity stream buffer */ |
| 289 | |
| 290 | for (i = 0; i < ARRAY_SIZE(vsc_pipe); i++) { |
| 291 | if (vsc_pipe[i].base != 0 && vsc_pipe[i].size != 0) { |
| 292 | ret = kgsl_snapshot_get_object(device, ptbase, |
| 293 | vsc_pipe[i].base, vsc_pipe[i].size, |
| 294 | SNAPSHOT_GPU_OBJECT_GENERIC); |
| 295 | snapshot_frozen_objsize += ret; |
| 296 | } |
| 297 | } |
| 298 | |
| 299 | /* Next the visibility stream size buffer */ |
| 300 | |
| 301 | if (vsc_size_address) { |
| 302 | ret = kgsl_snapshot_get_object(device, ptbase, |
| 303 | vsc_size_address, 32, |
| 304 | SNAPSHOT_GPU_OBJECT_GENERIC); |
| 305 | snapshot_frozen_objsize += ret; |
| 306 | } |
| 307 | |
| 308 | /* Next private shader buffer memory */ |
| 309 | if (sp_vs_pvt_mem_addr) { |
| 310 | ret = kgsl_snapshot_get_object(device, ptbase, |
| 311 | sp_vs_pvt_mem_addr, 8192, |
| 312 | SNAPSHOT_GPU_OBJECT_GENERIC); |
| 313 | |
| 314 | snapshot_frozen_objsize += ret; |
| 315 | } |
| 316 | |
| 317 | if (sp_fs_pvt_mem_addr) { |
| 318 | ret = kgsl_snapshot_get_object(device, ptbase, |
| 319 | sp_fs_pvt_mem_addr, 8192, |
| 320 | SNAPSHOT_GPU_OBJECT_GENERIC); |
| 321 | snapshot_frozen_objsize += ret; |
| 322 | } |
| 323 | |
| 324 | /* Finally: VBOs */ |
| 325 | |
| 326 | /* The number of active VBOs is stored in VFD_CONTROL_O[31:27] */ |
| 327 | for (i = 0; i < (vfd_control_0) >> 27; i++) { |
| 328 | int size; |
| 329 | |
| 330 | /* |
| 331 | * The size of the VBO is the stride stored in |
| 332 | * VFD_FETCH_INSTR_0_X.BUFSTRIDE * VFD_INDEX_MAX. The base |
| 333 | * is stored in VFD_FETCH_INSTR_1_X |
| 334 | */ |
| 335 | |
| 336 | if (vbo[i].base != 0) { |
| 337 | size = vbo[i].stride * vfd_index_max; |
| 338 | |
| 339 | ret = kgsl_snapshot_get_object(device, ptbase, |
| 340 | vbo[i].base, |
| 341 | 0, SNAPSHOT_GPU_OBJECT_GENERIC); |
| 342 | snapshot_frozen_objsize += ret; |
| 343 | } |
| 344 | } |
| 345 | } |
| 346 | |
| 347 | /* |
Jordan Crouse | ea2c638 | 2012-03-16 14:53:42 -0600 | [diff] [blame] | 348 | * Parse all the type3 opcode packets that may contain important information, |
Jordan Crouse | e0879b1 | 2012-03-16 14:53:43 -0600 | [diff] [blame^] | 349 | * such as additional GPU buffers to grab or a draw initator |
Jordan Crouse | ea2c638 | 2012-03-16 14:53:42 -0600 | [diff] [blame] | 350 | */ |
| 351 | |
| 352 | static void ib_parse_type3(struct kgsl_device *device, unsigned int *ptr, |
| 353 | unsigned int ptbase) |
| 354 | { |
| 355 | switch (cp_type3_opcode(*ptr)) { |
| 356 | case CP_LOAD_STATE: |
| 357 | ib_parse_load_state(device, ptr, ptbase); |
| 358 | break; |
Jordan Crouse | e0879b1 | 2012-03-16 14:53:43 -0600 | [diff] [blame^] | 359 | case CP_SET_BIN_DATA: |
| 360 | ib_parse_set_bin_data(device, ptr, ptbase); |
| 361 | break; |
| 362 | case CP_MEM_WRITE: |
| 363 | ib_parse_mem_write(device, ptr, ptbase); |
| 364 | break; |
| 365 | case CP_DRAW_INDX: |
| 366 | ib_parse_draw_indx(device, ptr, ptbase); |
| 367 | break; |
| 368 | } |
| 369 | } |
| 370 | |
| 371 | /* |
| 372 | * Parse type0 packets found in the stream. Some of the registers that are |
| 373 | * written are clues for GPU buffers that we need to freeze. Register writes |
| 374 | * are considred valid when a draw initator is called, so just cache the values |
| 375 | * here and freeze them when a CP_DRAW_INDX is seen. This protects against |
| 376 | * needlessly caching buffers that won't be used during a draw call |
| 377 | */ |
| 378 | |
| 379 | static void ib_parse_type0(struct kgsl_device *device, unsigned int *ptr, |
| 380 | unsigned int ptbase) |
| 381 | { |
| 382 | int size = type0_pkt_size(*ptr); |
| 383 | int offset = type0_pkt_offset(*ptr); |
| 384 | int i; |
| 385 | |
| 386 | for (i = 0; i < (size + 1); i++, offset++) { |
| 387 | |
| 388 | /* Visiblity stream buffer */ |
| 389 | |
| 390 | if (offset >= A3XX_VSC_PIPE_DATA_ADDRESS_0 && |
| 391 | offset <= A3XX_VSC_PIPE_DATA_LENGTH_7) { |
| 392 | int index = offset - A3XX_VSC_PIPE_DATA_ADDRESS_0; |
| 393 | |
| 394 | /* Each bank of address and length registers are |
| 395 | * interleaved with an empty register: |
| 396 | * |
| 397 | * address 0 |
| 398 | * length 0 |
| 399 | * empty |
| 400 | * address 1 |
| 401 | * length 1 |
| 402 | * empty |
| 403 | * ... |
| 404 | */ |
| 405 | |
| 406 | if (index % 3 == 0) |
| 407 | vsc_pipe[index / 3].base = ptr[i + 1]; |
| 408 | else if (index % 3 == 1) |
| 409 | vsc_pipe[index / 3].size = ptr[i + 1]; |
| 410 | } else if ((offset >= A3XX_VFD_FETCH_INSTR_0_0) && |
| 411 | (offset <= A3XX_VFD_FETCH_INSTR_1_F)) { |
| 412 | int index = offset - A3XX_VFD_FETCH_INSTR_0_0; |
| 413 | |
| 414 | /* |
| 415 | * FETCH_INSTR_0_X and FETCH_INSTR_1_X banks are |
| 416 | * interleaved as above but without the empty register |
| 417 | * in between |
| 418 | */ |
| 419 | |
| 420 | if (index % 2 == 0) |
| 421 | vbo[index >> 1].stride = |
| 422 | (ptr[i + 1] >> 7) & 0x1FF; |
| 423 | else |
| 424 | vbo[index >> 1].base = ptr[i + 1]; |
| 425 | } else { |
| 426 | /* |
| 427 | * Cache various support registers for calculating |
| 428 | * buffer sizes |
| 429 | */ |
| 430 | |
| 431 | switch (offset) { |
| 432 | case A3XX_VFD_CONTROL_0: |
| 433 | vfd_control_0 = ptr[i + 1]; |
| 434 | break; |
| 435 | case A3XX_VFD_INDEX_MAX: |
| 436 | vfd_index_max = ptr[i + 1]; |
| 437 | break; |
| 438 | case A3XX_VSC_SIZE_ADDRESS: |
| 439 | vsc_size_address = ptr[i + 1]; |
| 440 | break; |
| 441 | case A3XX_SP_VS_PVT_MEM_ADDR_REG: |
| 442 | sp_vs_pvt_mem_addr = ptr[i + 1]; |
| 443 | break; |
| 444 | case A3XX_SP_FS_PVT_MEM_ADDR_REG: |
| 445 | sp_fs_pvt_mem_addr = ptr[i + 1]; |
| 446 | break; |
| 447 | } |
| 448 | } |
Jordan Crouse | ea2c638 | 2012-03-16 14:53:42 -0600 | [diff] [blame] | 449 | } |
| 450 | } |
| 451 | |
Jordan Crouse | f99f5a66 | 2012-03-16 14:53:43 -0600 | [diff] [blame] | 452 | /* Add an IB as a GPU object, but first, parse it to find more goodies within */ |
| 453 | |
| 454 | static void ib_add_gpu_object(struct kgsl_device *device, unsigned int ptbase, |
| 455 | unsigned int gpuaddr, unsigned int dwords) |
| 456 | { |
Jordan Crouse | e0879b1 | 2012-03-16 14:53:43 -0600 | [diff] [blame^] | 457 | int i = 0, ret; |
Jordan Crouse | f99f5a66 | 2012-03-16 14:53:43 -0600 | [diff] [blame] | 458 | unsigned int *src = (unsigned int *) adreno_convertaddr(device, ptbase, |
| 459 | gpuaddr, dwords << 2); |
| 460 | |
| 461 | if (src == NULL) |
| 462 | return; |
| 463 | |
Jordan Crouse | e0879b1 | 2012-03-16 14:53:43 -0600 | [diff] [blame^] | 464 | while (i < dwords) { |
| 465 | |
Jordan Crouse | f99f5a66 | 2012-03-16 14:53:43 -0600 | [diff] [blame] | 466 | if (pkt_is_type3(src[i])) { |
| 467 | if ((dwords - i) < type3_pkt_size(src[i]) + 1) |
Jordan Crouse | e0879b1 | 2012-03-16 14:53:43 -0600 | [diff] [blame^] | 468 | goto skip; |
Jordan Crouse | f99f5a66 | 2012-03-16 14:53:43 -0600 | [diff] [blame] | 469 | |
| 470 | if (adreno_cmd_is_ib(src[i])) |
| 471 | ib_add_gpu_object(device, ptbase, |
| 472 | src[i + 1], src[i + 2]); |
| 473 | else |
| 474 | ib_parse_type3(device, &src[i], ptbase); |
Jordan Crouse | e0879b1 | 2012-03-16 14:53:43 -0600 | [diff] [blame^] | 475 | |
| 476 | i += type3_pkt_size(src[i]); |
| 477 | } else if (pkt_is_type0(src[i])) { |
| 478 | ib_parse_type0(device, &src[i], ptbase); |
| 479 | i += type0_pkt_size(src[i]); |
Jordan Crouse | f99f5a66 | 2012-03-16 14:53:43 -0600 | [diff] [blame] | 480 | } |
Jordan Crouse | e0879b1 | 2012-03-16 14:53:43 -0600 | [diff] [blame^] | 481 | |
| 482 | skip: |
| 483 | i++; |
Jordan Crouse | f99f5a66 | 2012-03-16 14:53:43 -0600 | [diff] [blame] | 484 | } |
| 485 | |
| 486 | ret = kgsl_snapshot_get_object(device, ptbase, gpuaddr, dwords << 2, |
| 487 | SNAPSHOT_GPU_OBJECT_IB); |
| 488 | |
| 489 | snapshot_frozen_objsize += ret; |
| 490 | } |
| 491 | |
Jordan Crouse | 156cfbc | 2012-01-24 09:32:04 -0700 | [diff] [blame] | 492 | /* Snapshot the istore memory */ |
| 493 | static int snapshot_istore(struct kgsl_device *device, void *snapshot, |
| 494 | int remain, void *priv) |
| 495 | { |
| 496 | struct kgsl_snapshot_istore *header = snapshot; |
| 497 | unsigned int *data = snapshot + sizeof(*header); |
| 498 | struct adreno_device *adreno_dev = ADRENO_DEVICE(device); |
| 499 | int count, i; |
| 500 | |
Jordan Crouse | c6b3a99 | 2012-02-04 10:23:51 -0700 | [diff] [blame] | 501 | count = adreno_dev->istore_size * adreno_dev->instruction_size; |
Jordan Crouse | 156cfbc | 2012-01-24 09:32:04 -0700 | [diff] [blame] | 502 | |
| 503 | if (remain < (count * 4) + sizeof(*header)) { |
| 504 | KGSL_DRV_ERR(device, |
| 505 | "snapshot: Not enough memory for the istore section"); |
| 506 | return 0; |
| 507 | } |
| 508 | |
| 509 | header->count = adreno_dev->istore_size; |
| 510 | |
| 511 | for (i = 0; i < count; i++) |
| 512 | kgsl_regread(device, ADRENO_ISTORE_START + i, &data[i]); |
| 513 | |
| 514 | return (count * 4) + sizeof(*header); |
| 515 | } |
| 516 | |
| 517 | /* Snapshot the ringbuffer memory */ |
| 518 | static int snapshot_rb(struct kgsl_device *device, void *snapshot, |
| 519 | int remain, void *priv) |
| 520 | { |
| 521 | struct kgsl_snapshot_rb *header = snapshot; |
| 522 | unsigned int *data = snapshot + sizeof(*header); |
| 523 | struct adreno_device *adreno_dev = ADRENO_DEVICE(device); |
| 524 | struct adreno_ringbuffer *rb = &adreno_dev->ringbuffer; |
Jordan Crouse | f99f5a66 | 2012-03-16 14:53:43 -0600 | [diff] [blame] | 525 | unsigned int rbbase, ptbase, rptr, *rbptr, ibbase; |
Jordan Crouse | 156cfbc | 2012-01-24 09:32:04 -0700 | [diff] [blame] | 526 | int start, stop, index; |
| 527 | int numitems, size; |
Jordan Crouse | e9e91bf | 2012-02-21 09:48:36 -0700 | [diff] [blame] | 528 | int parse_ibs = 0, ib_parse_start; |
Jordan Crouse | 156cfbc | 2012-01-24 09:32:04 -0700 | [diff] [blame] | 529 | |
| 530 | /* Get the GPU address of the ringbuffer */ |
| 531 | kgsl_regread(device, REG_CP_RB_BASE, &rbbase); |
| 532 | |
| 533 | /* Get the physical address of the MMU pagetable */ |
| 534 | ptbase = kgsl_mmu_get_current_ptbase(device); |
| 535 | |
| 536 | /* Get the current read pointers for the RB */ |
| 537 | kgsl_regread(device, REG_CP_RB_RPTR, &rptr); |
| 538 | |
Jordan Crouse | f99f5a66 | 2012-03-16 14:53:43 -0600 | [diff] [blame] | 539 | /* |
| 540 | * Get the address of the last executed IB1 so we can be sure to |
| 541 | * snapshot it |
| 542 | */ |
| 543 | |
| 544 | kgsl_regread(device, REG_CP_IB1_BASE, &ibbase); |
| 545 | |
Jordan Crouse | 156cfbc | 2012-01-24 09:32:04 -0700 | [diff] [blame] | 546 | /* start the dump at the rptr minus some history */ |
| 547 | start = (int) rptr - NUM_DWORDS_OF_RINGBUFFER_HISTORY; |
| 548 | if (start < 0) |
| 549 | start += rb->sizedwords; |
| 550 | |
| 551 | /* |
| 552 | * Stop the dump at the point where the software last wrote. Don't use |
| 553 | * the hardware value here on the chance that it didn't get properly |
| 554 | * updated |
| 555 | */ |
| 556 | |
| 557 | stop = (int) rb->wptr + 16; |
| 558 | if (stop > rb->sizedwords) |
| 559 | stop -= rb->sizedwords; |
| 560 | |
| 561 | /* Set up the header for the section */ |
| 562 | |
| 563 | numitems = (stop > start) ? stop - start : |
| 564 | (rb->sizedwords - start) + stop; |
| 565 | |
| 566 | size = (numitems << 2); |
| 567 | |
| 568 | if (remain < size + sizeof(*header)) { |
| 569 | KGSL_DRV_ERR(device, |
| 570 | "snapshot: Not enough memory for the rb section"); |
| 571 | return 0; |
| 572 | } |
| 573 | |
| 574 | /* Write the sub-header for the section */ |
| 575 | header->start = start; |
| 576 | header->end = stop; |
| 577 | header->wptr = rb->wptr; |
| 578 | header->rbsize = rb->sizedwords; |
| 579 | header->count = numitems; |
| 580 | |
Jordan Crouse | e9e91bf | 2012-02-21 09:48:36 -0700 | [diff] [blame] | 581 | /* |
| 582 | * We can only reliably dump IBs from the beginning of the context, |
| 583 | * and it turns out that for the vast majority of the time we really |
| 584 | * only care about the current context when it comes to diagnosing |
| 585 | * a hang. So, with an eye to limiting the buffer dumping to what is |
| 586 | * really useful find the beginning of the context and only dump |
| 587 | * IBs from that point |
| 588 | */ |
| 589 | |
| 590 | index = rptr; |
| 591 | ib_parse_start = start; |
Jordan Crouse | 156cfbc | 2012-01-24 09:32:04 -0700 | [diff] [blame] | 592 | rbptr = rb->buffer_desc.hostptr; |
| 593 | |
Jordan Crouse | e9e91bf | 2012-02-21 09:48:36 -0700 | [diff] [blame] | 594 | while (index != start) { |
| 595 | index--; |
| 596 | |
| 597 | if (index < 0) { |
| 598 | /* |
| 599 | * The marker we are looking for is 2 dwords long, so |
| 600 | * when wrapping, go back 2 from the end so we don't |
| 601 | * access out of range in the if statement below |
| 602 | */ |
| 603 | index = rb->sizedwords - 2; |
| 604 | |
| 605 | /* |
| 606 | * Account for the possibility that start might be at |
| 607 | * rb->sizedwords - 1 |
| 608 | */ |
| 609 | |
| 610 | if (start == rb->sizedwords - 1) |
| 611 | break; |
| 612 | } |
| 613 | |
| 614 | /* |
| 615 | * Look for a NOP packet with the context switch identifier in |
| 616 | * the second dword |
| 617 | */ |
| 618 | |
| 619 | if (rbptr[index] == cp_nop_packet(1) && |
| 620 | rbptr[index + 1] == KGSL_CONTEXT_TO_MEM_IDENTIFIER) { |
| 621 | ib_parse_start = index; |
| 622 | break; |
| 623 | } |
| 624 | } |
| 625 | |
| 626 | index = start; |
| 627 | |
Jordan Crouse | 156cfbc | 2012-01-24 09:32:04 -0700 | [diff] [blame] | 628 | /* |
| 629 | * Loop through the RB, copying the data and looking for indirect |
| 630 | * buffers and MMU pagetable changes |
| 631 | */ |
| 632 | |
| 633 | while (index != rb->wptr) { |
| 634 | *data = rbptr[index]; |
| 635 | |
Jordan Crouse | e9e91bf | 2012-02-21 09:48:36 -0700 | [diff] [blame] | 636 | /* Only parse IBs between the context start and the rptr */ |
| 637 | |
| 638 | if (index == ib_parse_start) |
| 639 | parse_ibs = 1; |
| 640 | |
| 641 | if (index == rptr) |
| 642 | parse_ibs = 0; |
| 643 | |
Jordan Crouse | f99f5a66 | 2012-03-16 14:53:43 -0600 | [diff] [blame] | 644 | if (parse_ibs && adreno_cmd_is_ib(rbptr[index])) { |
| 645 | /* |
| 646 | * The IB from CP_IB1_BASE goes into the snapshot, all |
| 647 | * others get marked at GPU objects |
| 648 | */ |
| 649 | if (rbptr[index + 1] == ibbase) |
| 650 | push_object(device, SNAPSHOT_OBJ_TYPE_IB, |
| 651 | ptbase, rbptr[index + 1], |
| 652 | rbptr[index + 2]); |
| 653 | else |
| 654 | ib_add_gpu_object(device, ptbase, |
| 655 | rbptr[index + 1], rbptr[index + 2]); |
| 656 | } |
Jordan Crouse | 156cfbc | 2012-01-24 09:32:04 -0700 | [diff] [blame] | 657 | |
Jordan Crouse | 156cfbc | 2012-01-24 09:32:04 -0700 | [diff] [blame] | 658 | index = index + 1; |
| 659 | |
| 660 | if (index == rb->sizedwords) |
| 661 | index = 0; |
| 662 | |
| 663 | data++; |
| 664 | } |
| 665 | |
| 666 | /* Dump 16 dwords past the wptr, but don't bother interpeting it */ |
| 667 | |
| 668 | while (index != stop) { |
| 669 | *data = rbptr[index]; |
| 670 | index = index + 1; |
| 671 | |
| 672 | if (index == rb->sizedwords) |
| 673 | index = 0; |
| 674 | |
| 675 | data++; |
| 676 | } |
| 677 | |
| 678 | /* Return the size of the section */ |
| 679 | return size + sizeof(*header); |
| 680 | } |
| 681 | |
Jordan Crouse | e0879b1 | 2012-03-16 14:53:43 -0600 | [diff] [blame^] | 682 | /* Snapshot the memory for an indirect buffer */ |
Jordan Crouse | 156cfbc | 2012-01-24 09:32:04 -0700 | [diff] [blame] | 683 | static int snapshot_ib(struct kgsl_device *device, void *snapshot, |
| 684 | int remain, void *priv) |
| 685 | { |
| 686 | struct kgsl_snapshot_ib *header = snapshot; |
| 687 | struct kgsl_snapshot_obj *obj = priv; |
| 688 | unsigned int *src = obj->ptr; |
| 689 | unsigned int *dst = snapshot + sizeof(*header); |
| 690 | int i; |
| 691 | |
| 692 | if (remain < (obj->dwords << 2) + sizeof(*header)) { |
| 693 | KGSL_DRV_ERR(device, |
| 694 | "snapshot: Not enough memory for the ib section"); |
| 695 | return 0; |
| 696 | } |
| 697 | |
| 698 | /* Write the sub-header for the section */ |
| 699 | header->gpuaddr = obj->gpuaddr; |
| 700 | header->ptbase = obj->ptbase; |
| 701 | header->size = obj->dwords; |
| 702 | |
| 703 | /* Write the contents of the ib */ |
Jordan Crouse | ea2c638 | 2012-03-16 14:53:42 -0600 | [diff] [blame] | 704 | for (i = 0; i < obj->dwords; i++, src++, dst++) { |
Jordan Crouse | 156cfbc | 2012-01-24 09:32:04 -0700 | [diff] [blame] | 705 | *dst = *src; |
Jordan Crouse | 156cfbc | 2012-01-24 09:32:04 -0700 | [diff] [blame] | 706 | |
Jordan Crouse | ea2c638 | 2012-03-16 14:53:42 -0600 | [diff] [blame] | 707 | if (pkt_is_type3(*src)) { |
| 708 | if ((obj->dwords - i) < type3_pkt_size(*src) + 1) |
| 709 | continue; |
Jordan Crouse | 156cfbc | 2012-01-24 09:32:04 -0700 | [diff] [blame] | 710 | |
Jordan Crouse | ea2c638 | 2012-03-16 14:53:42 -0600 | [diff] [blame] | 711 | if (adreno_cmd_is_ib(*src)) |
| 712 | push_object(device, SNAPSHOT_OBJ_TYPE_IB, |
| 713 | obj->ptbase, src[1], src[2]); |
| 714 | else |
| 715 | ib_parse_type3(device, src, obj->ptbase); |
| 716 | } |
Jordan Crouse | 156cfbc | 2012-01-24 09:32:04 -0700 | [diff] [blame] | 717 | } |
| 718 | |
| 719 | return (obj->dwords << 2) + sizeof(*header); |
| 720 | } |
| 721 | |
| 722 | /* Dump another item on the current pending list */ |
| 723 | static void *dump_object(struct kgsl_device *device, int obj, void *snapshot, |
| 724 | int *remain) |
| 725 | { |
| 726 | switch (objbuf[obj].type) { |
| 727 | case SNAPSHOT_OBJ_TYPE_IB: |
| 728 | snapshot = kgsl_snapshot_add_section(device, |
| 729 | KGSL_SNAPSHOT_SECTION_IB, snapshot, remain, |
| 730 | snapshot_ib, &objbuf[obj]); |
| 731 | break; |
| 732 | default: |
| 733 | KGSL_DRV_ERR(device, |
| 734 | "snapshot: Invalid snapshot object type: %d\n", |
| 735 | objbuf[obj].type); |
| 736 | break; |
| 737 | } |
| 738 | |
| 739 | return snapshot; |
| 740 | } |
| 741 | |
| 742 | /* adreno_snapshot - Snapshot the Adreno GPU state |
| 743 | * @device - KGSL device to snapshot |
| 744 | * @snapshot - Pointer to the start of memory to write into |
| 745 | * @remain - A pointer to how many bytes of memory are remaining in the snapshot |
| 746 | * @hang - set if this snapshot was automatically triggered by a GPU hang |
| 747 | * This is a hook function called by kgsl_snapshot to snapshot the |
| 748 | * Adreno specific information for the GPU snapshot. In turn, this function |
| 749 | * calls the GPU specific snapshot function to get core specific information. |
| 750 | */ |
| 751 | |
| 752 | void *adreno_snapshot(struct kgsl_device *device, void *snapshot, int *remain, |
| 753 | int hang) |
| 754 | { |
| 755 | int i; |
| 756 | uint32_t ptbase, ibbase, ibsize; |
| 757 | struct adreno_device *adreno_dev = ADRENO_DEVICE(device); |
| 758 | |
| 759 | /* Reset the list of objects */ |
| 760 | objbufptr = 0; |
| 761 | |
Jordan Crouse | 9610b6b | 2012-03-16 14:53:42 -0600 | [diff] [blame] | 762 | snapshot_frozen_objsize = 0; |
| 763 | |
Jordan Crouse | e0879b1 | 2012-03-16 14:53:43 -0600 | [diff] [blame^] | 764 | /* Clear the caches for the visibilty stream and VBO parsing */ |
| 765 | |
| 766 | vfd_control_0 = 0; |
| 767 | vfd_index_max = 0; |
| 768 | vsc_size_address = 0; |
| 769 | |
| 770 | memset(vsc_pipe, 0, sizeof(vsc_pipe)); |
| 771 | memset(vbo, 0, sizeof(vbo)); |
| 772 | |
Jordan Crouse | 156cfbc | 2012-01-24 09:32:04 -0700 | [diff] [blame] | 773 | /* Get the physical address of the MMU pagetable */ |
| 774 | ptbase = kgsl_mmu_get_current_ptbase(device); |
| 775 | |
| 776 | /* Dump the ringbuffer */ |
| 777 | snapshot = kgsl_snapshot_add_section(device, KGSL_SNAPSHOT_SECTION_RB, |
| 778 | snapshot, remain, snapshot_rb, NULL); |
| 779 | |
| 780 | /* |
Jordan Crouse | e9e91bf | 2012-02-21 09:48:36 -0700 | [diff] [blame] | 781 | * Make sure that the last IB1 that was being executed is dumped. |
| 782 | * Since this was the last IB1 that was processed, we should have |
| 783 | * already added it to the list during the ringbuffer parse but we |
| 784 | * want to be double plus sure. |
Jordan Crouse | 156cfbc | 2012-01-24 09:32:04 -0700 | [diff] [blame] | 785 | */ |
Jordan Crouse | e9e91bf | 2012-02-21 09:48:36 -0700 | [diff] [blame] | 786 | |
Jordan Crouse | 156cfbc | 2012-01-24 09:32:04 -0700 | [diff] [blame] | 787 | kgsl_regread(device, REG_CP_IB1_BASE, &ibbase); |
| 788 | kgsl_regread(device, REG_CP_IB1_BUFSZ, &ibsize); |
| 789 | |
Jordan Crouse | e9e91bf | 2012-02-21 09:48:36 -0700 | [diff] [blame] | 790 | /* |
| 791 | * The problem is that IB size from the register is the unprocessed size |
| 792 | * of the buffer not the original size, so if we didn't catch this |
| 793 | * buffer being directly used in the RB, then we might not be able to |
| 794 | * dump the whle thing. Print a warning message so we can try to |
| 795 | * figure how often this really happens. |
| 796 | */ |
| 797 | |
| 798 | if (!find_object(SNAPSHOT_OBJ_TYPE_IB, ibbase, ptbase) && ibsize) { |
Jordan Crouse | 156cfbc | 2012-01-24 09:32:04 -0700 | [diff] [blame] | 799 | push_object(device, SNAPSHOT_OBJ_TYPE_IB, ptbase, |
| 800 | ibbase, ibsize); |
Jordan Crouse | e9e91bf | 2012-02-21 09:48:36 -0700 | [diff] [blame] | 801 | KGSL_DRV_ERR(device, "CP_IB1_BASE not found in the ringbuffer. " |
| 802 | "Dumping %x dwords of the buffer.\n", ibsize); |
| 803 | } |
Jordan Crouse | 156cfbc | 2012-01-24 09:32:04 -0700 | [diff] [blame] | 804 | |
| 805 | kgsl_regread(device, REG_CP_IB2_BASE, &ibbase); |
| 806 | kgsl_regread(device, REG_CP_IB2_BUFSZ, &ibsize); |
| 807 | |
Jordan Crouse | e9e91bf | 2012-02-21 09:48:36 -0700 | [diff] [blame] | 808 | /* |
| 809 | * Add the last parsed IB2 to the list. The IB2 should be found as we |
| 810 | * parse the objects below, but we try to add it to the list first, so |
| 811 | * it too can be parsed. Don't print an error message in this case - if |
| 812 | * the IB2 is found during parsing, the list will be updated with the |
| 813 | * correct size. |
| 814 | */ |
| 815 | |
| 816 | if (!find_object(SNAPSHOT_OBJ_TYPE_IB, ibbase, ptbase) && ibsize) { |
Jordan Crouse | 156cfbc | 2012-01-24 09:32:04 -0700 | [diff] [blame] | 817 | push_object(device, SNAPSHOT_OBJ_TYPE_IB, ptbase, |
| 818 | ibbase, ibsize); |
Jordan Crouse | e9e91bf | 2012-02-21 09:48:36 -0700 | [diff] [blame] | 819 | } |
Jordan Crouse | 156cfbc | 2012-01-24 09:32:04 -0700 | [diff] [blame] | 820 | |
| 821 | /* |
| 822 | * Go through the list of found objects and dump each one. As the IBs |
| 823 | * are parsed, more objects might be found, and objbufptr will increase |
| 824 | */ |
| 825 | for (i = 0; i < objbufptr; i++) |
| 826 | snapshot = dump_object(device, i, snapshot, remain); |
| 827 | |
| 828 | /* |
| 829 | * Only dump the istore on a hang - reading it on a running system |
| 830 | * has a non 0 chance of hanging the GPU |
| 831 | */ |
| 832 | |
| 833 | if (hang) { |
| 834 | snapshot = kgsl_snapshot_add_section(device, |
| 835 | KGSL_SNAPSHOT_SECTION_ISTORE, snapshot, remain, |
| 836 | snapshot_istore, NULL); |
| 837 | } |
| 838 | |
| 839 | /* Add GPU specific sections - registers mainly, but other stuff too */ |
| 840 | if (adreno_dev->gpudev->snapshot) |
| 841 | snapshot = adreno_dev->gpudev->snapshot(adreno_dev, snapshot, |
| 842 | remain, hang); |
| 843 | |
Jordan Crouse | 9610b6b | 2012-03-16 14:53:42 -0600 | [diff] [blame] | 844 | if (snapshot_frozen_objsize) |
| 845 | KGSL_DRV_ERR(device, "GPU snapshot froze %dKb of GPU buffers\n", |
| 846 | snapshot_frozen_objsize / 1024); |
| 847 | |
Jordan Crouse | 156cfbc | 2012-01-24 09:32:04 -0700 | [diff] [blame] | 848 | return snapshot; |
| 849 | } |