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