Flemmard | 9fc1014 | 2013-04-10 15:59:59 +0200 | [diff] [blame] | 1 | /* Copyright (c) 2002,2007-2013, The Linux Foundation. All rights reserved. |
Nicholas Flintham | 1e3d311 | 2013-04-10 10:48:38 +0100 | [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 <linux/firmware.h> |
| 14 | #include <linux/slab.h> |
| 15 | #include <linux/sched.h> |
| 16 | #include <linux/log2.h> |
| 17 | |
| 18 | #include "kgsl.h" |
| 19 | #include "kgsl_sharedmem.h" |
| 20 | #include "kgsl_cffdump.h" |
Nicholas Flintham | 1e3d311 | 2013-04-10 10:48:38 +0100 | [diff] [blame] | 21 | |
| 22 | #include "adreno.h" |
| 23 | #include "adreno_pm4types.h" |
| 24 | #include "adreno_ringbuffer.h" |
Nicholas Flintham | 1e3d311 | 2013-04-10 10:48:38 +0100 | [diff] [blame] | 25 | |
| 26 | #include "a2xx_reg.h" |
| 27 | #include "a3xx_reg.h" |
| 28 | |
| 29 | #define GSL_RB_NOP_SIZEDWORDS 2 |
| 30 | |
Flemmard | 9fc1014 | 2013-04-10 15:59:59 +0200 | [diff] [blame] | 31 | /* |
| 32 | * CP DEBUG settings for all cores: |
| 33 | * DYNAMIC_CLK_DISABLE [27] - turn off the dynamic clock control |
| 34 | * PROG_END_PTR_ENABLE [25] - Allow 128 bit writes to the VBIF |
| 35 | */ |
| 36 | |
| 37 | #define CP_DEBUG_DEFAULT ((1 << 27) | (1 << 25)) |
Nicholas Flintham | 1e3d311 | 2013-04-10 10:48:38 +0100 | [diff] [blame] | 38 | |
| 39 | void adreno_ringbuffer_submit(struct adreno_ringbuffer *rb) |
| 40 | { |
| 41 | BUG_ON(rb->wptr == 0); |
| 42 | |
Flemmard | 9fc1014 | 2013-04-10 15:59:59 +0200 | [diff] [blame] | 43 | /* Let the pwrscale policy know that new commands have |
| 44 | been submitted. */ |
Nicholas Flintham | 1e3d311 | 2013-04-10 10:48:38 +0100 | [diff] [blame] | 45 | kgsl_pwrscale_busy(rb->device); |
| 46 | |
Flemmard | 9fc1014 | 2013-04-10 15:59:59 +0200 | [diff] [blame] | 47 | /*synchronize memory before informing the hardware of the |
| 48 | *new commands. |
| 49 | */ |
Nicholas Flintham | 1e3d311 | 2013-04-10 10:48:38 +0100 | [diff] [blame] | 50 | mb(); |
| 51 | |
| 52 | adreno_regwrite(rb->device, REG_CP_RB_WPTR, rb->wptr); |
| 53 | } |
| 54 | |
Flemmard | 9fc1014 | 2013-04-10 15:59:59 +0200 | [diff] [blame] | 55 | static int |
| 56 | adreno_ringbuffer_waitspace(struct adreno_ringbuffer *rb, |
| 57 | struct adreno_context *context, |
| 58 | unsigned int numcmds, int wptr_ahead) |
Nicholas Flintham | 1e3d311 | 2013-04-10 10:48:38 +0100 | [diff] [blame] | 59 | { |
| 60 | int nopcount; |
| 61 | unsigned int freecmds; |
| 62 | unsigned int *cmds; |
| 63 | uint cmds_gpu; |
| 64 | unsigned long wait_time; |
| 65 | unsigned long wait_timeout = msecs_to_jiffies(ADRENO_IDLE_TIMEOUT); |
| 66 | unsigned long wait_time_part; |
Flemmard | 9fc1014 | 2013-04-10 15:59:59 +0200 | [diff] [blame] | 67 | unsigned int prev_reg_val[ft_detect_regs_count]; |
Nicholas Flintham | 1e3d311 | 2013-04-10 10:48:38 +0100 | [diff] [blame] | 68 | |
| 69 | memset(prev_reg_val, 0, sizeof(prev_reg_val)); |
| 70 | |
Flemmard | 9fc1014 | 2013-04-10 15:59:59 +0200 | [diff] [blame] | 71 | /* if wptr ahead, fill the remaining with NOPs */ |
Nicholas Flintham | 1e3d311 | 2013-04-10 10:48:38 +0100 | [diff] [blame] | 72 | if (wptr_ahead) { |
Flemmard | 9fc1014 | 2013-04-10 15:59:59 +0200 | [diff] [blame] | 73 | /* -1 for header */ |
Nicholas Flintham | 1e3d311 | 2013-04-10 10:48:38 +0100 | [diff] [blame] | 74 | nopcount = rb->sizedwords - rb->wptr - 1; |
| 75 | |
| 76 | cmds = (unsigned int *)rb->buffer_desc.hostptr + rb->wptr; |
| 77 | cmds_gpu = rb->buffer_desc.gpuaddr + sizeof(uint)*rb->wptr; |
| 78 | |
| 79 | GSL_RB_WRITE(cmds, cmds_gpu, cp_nop_packet(nopcount)); |
| 80 | |
Flemmard | 9fc1014 | 2013-04-10 15:59:59 +0200 | [diff] [blame] | 81 | /* Make sure that rptr is not 0 before submitting |
| 82 | * commands at the end of ringbuffer. We do not |
| 83 | * want the rptr and wptr to become equal when |
| 84 | * the ringbuffer is not empty */ |
Nicholas Flintham | 1e3d311 | 2013-04-10 10:48:38 +0100 | [diff] [blame] | 85 | do { |
| 86 | GSL_RB_GET_READPTR(rb, &rb->rptr); |
| 87 | } while (!rb->rptr); |
| 88 | |
| 89 | rb->wptr++; |
| 90 | |
| 91 | adreno_ringbuffer_submit(rb); |
| 92 | |
| 93 | rb->wptr = 0; |
| 94 | } |
| 95 | |
| 96 | wait_time = jiffies + wait_timeout; |
| 97 | wait_time_part = jiffies + msecs_to_jiffies(KGSL_TIMEOUT_PART); |
Flemmard | 9fc1014 | 2013-04-10 15:59:59 +0200 | [diff] [blame] | 98 | /* wait for space in ringbuffer */ |
Nicholas Flintham | 1e3d311 | 2013-04-10 10:48:38 +0100 | [diff] [blame] | 99 | while (1) { |
| 100 | GSL_RB_GET_READPTR(rb, &rb->rptr); |
| 101 | |
| 102 | freecmds = rb->rptr - rb->wptr; |
| 103 | |
| 104 | if (freecmds == 0 || freecmds > numcmds) |
| 105 | break; |
| 106 | |
Flemmard | 9fc1014 | 2013-04-10 15:59:59 +0200 | [diff] [blame] | 107 | /* Dont wait for timeout, detect hang faster. |
| 108 | */ |
Nicholas Flintham | 1e3d311 | 2013-04-10 10:48:38 +0100 | [diff] [blame] | 109 | if (time_after(jiffies, wait_time_part)) { |
| 110 | wait_time_part = jiffies + |
| 111 | msecs_to_jiffies(KGSL_TIMEOUT_PART); |
Flemmard | 9fc1014 | 2013-04-10 15:59:59 +0200 | [diff] [blame] | 112 | if ((adreno_ft_detect(rb->device, |
Nicholas Flintham | 1e3d311 | 2013-04-10 10:48:38 +0100 | [diff] [blame] | 113 | prev_reg_val))){ |
| 114 | KGSL_DRV_ERR(rb->device, |
| 115 | "Hang detected while waiting for freespace in" |
| 116 | "ringbuffer rptr: 0x%x, wptr: 0x%x\n", |
| 117 | rb->rptr, rb->wptr); |
| 118 | goto err; |
| 119 | } |
| 120 | } |
| 121 | |
| 122 | if (time_after(jiffies, wait_time)) { |
| 123 | KGSL_DRV_ERR(rb->device, |
| 124 | "Timed out while waiting for freespace in ringbuffer " |
| 125 | "rptr: 0x%x, wptr: 0x%x\n", rb->rptr, rb->wptr); |
| 126 | goto err; |
| 127 | } |
| 128 | |
| 129 | continue; |
| 130 | |
| 131 | err: |
Flemmard | 9fc1014 | 2013-04-10 15:59:59 +0200 | [diff] [blame] | 132 | if (!adreno_dump_and_exec_ft(rb->device)) { |
| 133 | if (context && context->flags & CTXT_FLAGS_GPU_HANG) { |
| 134 | KGSL_CTXT_WARN(rb->device, |
| 135 | "Context %p caused a gpu hang. Will not accept commands for context %d\n", |
| 136 | context, context->id); |
| 137 | return -EDEADLK; |
| 138 | } |
Nicholas Flintham | 1e3d311 | 2013-04-10 10:48:38 +0100 | [diff] [blame] | 139 | wait_time = jiffies + wait_timeout; |
| 140 | } else { |
Flemmard | 9fc1014 | 2013-04-10 15:59:59 +0200 | [diff] [blame] | 141 | /* GPU is hung and fault tolerance failed */ |
Nicholas Flintham | 1e3d311 | 2013-04-10 10:48:38 +0100 | [diff] [blame] | 142 | BUG(); |
| 143 | } |
| 144 | } |
Flemmard | 9fc1014 | 2013-04-10 15:59:59 +0200 | [diff] [blame] | 145 | return 0; |
Nicholas Flintham | 1e3d311 | 2013-04-10 10:48:38 +0100 | [diff] [blame] | 146 | } |
| 147 | |
| 148 | unsigned int *adreno_ringbuffer_allocspace(struct adreno_ringbuffer *rb, |
Flemmard | 9fc1014 | 2013-04-10 15:59:59 +0200 | [diff] [blame] | 149 | struct adreno_context *context, |
| 150 | unsigned int numcmds) |
Nicholas Flintham | 1e3d311 | 2013-04-10 10:48:38 +0100 | [diff] [blame] | 151 | { |
Flemmard | 9fc1014 | 2013-04-10 15:59:59 +0200 | [diff] [blame] | 152 | unsigned int *ptr = NULL; |
| 153 | int ret = 0; |
Nicholas Flintham | 1e3d311 | 2013-04-10 10:48:38 +0100 | [diff] [blame] | 154 | BUG_ON(numcmds >= rb->sizedwords); |
| 155 | |
| 156 | GSL_RB_GET_READPTR(rb, &rb->rptr); |
Flemmard | 9fc1014 | 2013-04-10 15:59:59 +0200 | [diff] [blame] | 157 | /* check for available space */ |
Nicholas Flintham | 1e3d311 | 2013-04-10 10:48:38 +0100 | [diff] [blame] | 158 | if (rb->wptr >= rb->rptr) { |
Flemmard | 9fc1014 | 2013-04-10 15:59:59 +0200 | [diff] [blame] | 159 | /* wptr ahead or equal to rptr */ |
| 160 | /* reserve dwords for nop packet */ |
Nicholas Flintham | 1e3d311 | 2013-04-10 10:48:38 +0100 | [diff] [blame] | 161 | if ((rb->wptr + numcmds) > (rb->sizedwords - |
| 162 | GSL_RB_NOP_SIZEDWORDS)) |
Flemmard | 9fc1014 | 2013-04-10 15:59:59 +0200 | [diff] [blame] | 163 | ret = adreno_ringbuffer_waitspace(rb, context, |
| 164 | numcmds, 1); |
Nicholas Flintham | 1e3d311 | 2013-04-10 10:48:38 +0100 | [diff] [blame] | 165 | } else { |
Flemmard | 9fc1014 | 2013-04-10 15:59:59 +0200 | [diff] [blame] | 166 | /* wptr behind rptr */ |
Nicholas Flintham | 1e3d311 | 2013-04-10 10:48:38 +0100 | [diff] [blame] | 167 | if ((rb->wptr + numcmds) >= rb->rptr) |
Flemmard | 9fc1014 | 2013-04-10 15:59:59 +0200 | [diff] [blame] | 168 | ret = adreno_ringbuffer_waitspace(rb, context, |
| 169 | numcmds, 0); |
| 170 | /* check for remaining space */ |
| 171 | /* reserve dwords for nop packet */ |
| 172 | if (!ret && (rb->wptr + numcmds) > (rb->sizedwords - |
Nicholas Flintham | 1e3d311 | 2013-04-10 10:48:38 +0100 | [diff] [blame] | 173 | GSL_RB_NOP_SIZEDWORDS)) |
Flemmard | 9fc1014 | 2013-04-10 15:59:59 +0200 | [diff] [blame] | 174 | ret = adreno_ringbuffer_waitspace(rb, context, |
| 175 | numcmds, 1); |
Nicholas Flintham | 1e3d311 | 2013-04-10 10:48:38 +0100 | [diff] [blame] | 176 | } |
| 177 | |
Flemmard | 9fc1014 | 2013-04-10 15:59:59 +0200 | [diff] [blame] | 178 | if (!ret) { |
| 179 | ptr = (unsigned int *)rb->buffer_desc.hostptr + rb->wptr; |
| 180 | rb->wptr += numcmds; |
| 181 | } |
Nicholas Flintham | 1e3d311 | 2013-04-10 10:48:38 +0100 | [diff] [blame] | 182 | |
| 183 | return ptr; |
| 184 | } |
| 185 | |
| 186 | static int _load_firmware(struct kgsl_device *device, const char *fwfile, |
| 187 | void **data, int *len) |
| 188 | { |
| 189 | const struct firmware *fw = NULL; |
| 190 | int ret; |
| 191 | |
| 192 | ret = request_firmware(&fw, fwfile, device->dev); |
| 193 | |
| 194 | if (ret) { |
| 195 | KGSL_DRV_ERR(device, "request_firmware(%s) failed: %d\n", |
| 196 | fwfile, ret); |
| 197 | return ret; |
| 198 | } |
| 199 | |
| 200 | *data = kmalloc(fw->size, GFP_KERNEL); |
| 201 | |
| 202 | if (*data) { |
| 203 | memcpy(*data, fw->data, fw->size); |
| 204 | *len = fw->size; |
| 205 | } else |
| 206 | KGSL_MEM_ERR(device, "kmalloc(%d) failed\n", fw->size); |
| 207 | |
| 208 | release_firmware(fw); |
| 209 | return (*data != NULL) ? 0 : -ENOMEM; |
| 210 | } |
| 211 | |
| 212 | int adreno_ringbuffer_read_pm4_ucode(struct kgsl_device *device) |
| 213 | { |
| 214 | struct adreno_device *adreno_dev = ADRENO_DEVICE(device); |
| 215 | int ret = 0; |
| 216 | |
| 217 | if (adreno_dev->pm4_fw == NULL) { |
| 218 | int len; |
| 219 | void *ptr; |
| 220 | |
| 221 | ret = _load_firmware(device, adreno_dev->pm4_fwfile, |
| 222 | &ptr, &len); |
| 223 | |
| 224 | if (ret) |
| 225 | goto err; |
| 226 | |
Flemmard | 9fc1014 | 2013-04-10 15:59:59 +0200 | [diff] [blame] | 227 | /* PM4 size is 3 dword aligned plus 1 dword of version */ |
Nicholas Flintham | 1e3d311 | 2013-04-10 10:48:38 +0100 | [diff] [blame] | 228 | if (len % ((sizeof(uint32_t) * 3)) != sizeof(uint32_t)) { |
| 229 | KGSL_DRV_ERR(device, "Bad firmware size: %d\n", len); |
| 230 | ret = -EINVAL; |
| 231 | kfree(ptr); |
| 232 | goto err; |
| 233 | } |
| 234 | |
| 235 | adreno_dev->pm4_fw_size = len / sizeof(uint32_t); |
| 236 | adreno_dev->pm4_fw = ptr; |
| 237 | adreno_dev->pm4_fw_version = adreno_dev->pm4_fw[1]; |
| 238 | } |
| 239 | |
| 240 | err: |
| 241 | return ret; |
| 242 | } |
| 243 | |
| 244 | |
| 245 | int adreno_ringbuffer_load_pm4_ucode(struct kgsl_device *device) |
| 246 | { |
| 247 | struct adreno_device *adreno_dev = ADRENO_DEVICE(device); |
| 248 | int i; |
| 249 | |
| 250 | if (adreno_dev->pm4_fw == NULL) { |
| 251 | int ret = adreno_ringbuffer_read_pm4_ucode(device); |
| 252 | if (ret) |
| 253 | return ret; |
| 254 | } |
| 255 | |
| 256 | KGSL_DRV_INFO(device, "loading pm4 ucode version: %d\n", |
| 257 | adreno_dev->pm4_fw_version); |
Flemmard | 9fc1014 | 2013-04-10 15:59:59 +0200 | [diff] [blame] | 258 | |
| 259 | adreno_regwrite(device, REG_CP_DEBUG, CP_DEBUG_DEFAULT); |
Nicholas Flintham | 1e3d311 | 2013-04-10 10:48:38 +0100 | [diff] [blame] | 260 | adreno_regwrite(device, REG_CP_ME_RAM_WADDR, 0); |
| 261 | for (i = 1; i < adreno_dev->pm4_fw_size; i++) |
| 262 | adreno_regwrite(device, REG_CP_ME_RAM_DATA, |
| 263 | adreno_dev->pm4_fw[i]); |
| 264 | |
| 265 | return 0; |
| 266 | } |
| 267 | |
| 268 | int adreno_ringbuffer_read_pfp_ucode(struct kgsl_device *device) |
| 269 | { |
| 270 | struct adreno_device *adreno_dev = ADRENO_DEVICE(device); |
| 271 | int ret = 0; |
| 272 | |
| 273 | if (adreno_dev->pfp_fw == NULL) { |
| 274 | int len; |
| 275 | void *ptr; |
| 276 | |
| 277 | ret = _load_firmware(device, adreno_dev->pfp_fwfile, |
| 278 | &ptr, &len); |
| 279 | if (ret) |
| 280 | goto err; |
| 281 | |
Flemmard | 9fc1014 | 2013-04-10 15:59:59 +0200 | [diff] [blame] | 282 | /* PFP size shold be dword aligned */ |
Nicholas Flintham | 1e3d311 | 2013-04-10 10:48:38 +0100 | [diff] [blame] | 283 | if (len % sizeof(uint32_t) != 0) { |
| 284 | KGSL_DRV_ERR(device, "Bad firmware size: %d\n", len); |
| 285 | ret = -EINVAL; |
| 286 | kfree(ptr); |
| 287 | goto err; |
| 288 | } |
| 289 | |
| 290 | adreno_dev->pfp_fw_size = len / sizeof(uint32_t); |
| 291 | adreno_dev->pfp_fw = ptr; |
| 292 | adreno_dev->pfp_fw_version = adreno_dev->pfp_fw[5]; |
| 293 | } |
| 294 | |
| 295 | err: |
| 296 | return ret; |
| 297 | } |
| 298 | |
| 299 | int adreno_ringbuffer_load_pfp_ucode(struct kgsl_device *device) |
| 300 | { |
| 301 | struct adreno_device *adreno_dev = ADRENO_DEVICE(device); |
| 302 | int i; |
| 303 | |
| 304 | if (adreno_dev->pfp_fw == NULL) { |
| 305 | int ret = adreno_ringbuffer_read_pfp_ucode(device); |
| 306 | if (ret) |
| 307 | return ret; |
| 308 | } |
| 309 | |
| 310 | KGSL_DRV_INFO(device, "loading pfp ucode version: %d\n", |
Flemmard | 9fc1014 | 2013-04-10 15:59:59 +0200 | [diff] [blame] | 311 | adreno_dev->pfp_fw_version); |
Nicholas Flintham | 1e3d311 | 2013-04-10 10:48:38 +0100 | [diff] [blame] | 312 | |
| 313 | adreno_regwrite(device, adreno_dev->gpudev->reg_cp_pfp_ucode_addr, 0); |
| 314 | for (i = 1; i < adreno_dev->pfp_fw_size; i++) |
| 315 | adreno_regwrite(device, |
Flemmard | 9fc1014 | 2013-04-10 15:59:59 +0200 | [diff] [blame] | 316 | adreno_dev->gpudev->reg_cp_pfp_ucode_data, |
| 317 | adreno_dev->pfp_fw[i]); |
| 318 | |
Nicholas Flintham | 1e3d311 | 2013-04-10 10:48:38 +0100 | [diff] [blame] | 319 | return 0; |
| 320 | } |
| 321 | |
Nicholas Flintham | 8c6a490 | 2013-04-30 13:56:09 +0100 | [diff] [blame^] | 322 | int adreno_ringbuffer_start(struct adreno_ringbuffer *rb, unsigned int init_ram) |
Nicholas Flintham | 1e3d311 | 2013-04-10 10:48:38 +0100 | [diff] [blame] | 323 | { |
| 324 | int status; |
Flemmard | 9fc1014 | 2013-04-10 15:59:59 +0200 | [diff] [blame] | 325 | /*cp_rb_cntl_u cp_rb_cntl; */ |
Nicholas Flintham | 1e3d311 | 2013-04-10 10:48:38 +0100 | [diff] [blame] | 326 | union reg_cp_rb_cntl cp_rb_cntl; |
| 327 | unsigned int rb_cntl; |
| 328 | struct kgsl_device *device = rb->device; |
| 329 | struct adreno_device *adreno_dev = ADRENO_DEVICE(device); |
| 330 | |
| 331 | if (rb->flags & KGSL_FLAGS_STARTED) |
| 332 | return 0; |
| 333 | |
Nicholas Flintham | 8c6a490 | 2013-04-30 13:56:09 +0100 | [diff] [blame^] | 334 | if (init_ram) |
| 335 | rb->timestamp[KGSL_MEMSTORE_GLOBAL] = 0; |
| 336 | |
Nicholas Flintham | 1e3d311 | 2013-04-10 10:48:38 +0100 | [diff] [blame] | 337 | kgsl_sharedmem_set(&rb->memptrs_desc, 0, 0, |
| 338 | sizeof(struct kgsl_rbmemptrs)); |
| 339 | |
| 340 | kgsl_sharedmem_set(&rb->buffer_desc, 0, 0xAA, |
| 341 | (rb->sizedwords << 2)); |
| 342 | |
| 343 | if (adreno_is_a2xx(adreno_dev)) { |
| 344 | adreno_regwrite(device, REG_CP_RB_WPTR_BASE, |
| 345 | (rb->memptrs_desc.gpuaddr |
| 346 | + GSL_RB_MEMPTRS_WPTRPOLL_OFFSET)); |
| 347 | |
Flemmard | 9fc1014 | 2013-04-10 15:59:59 +0200 | [diff] [blame] | 348 | /* setup WPTR delay */ |
Nicholas Flintham | 1e3d311 | 2013-04-10 10:48:38 +0100 | [diff] [blame] | 349 | adreno_regwrite(device, REG_CP_RB_WPTR_DELAY, |
Flemmard | 9fc1014 | 2013-04-10 15:59:59 +0200 | [diff] [blame] | 350 | 0 /*0x70000010 */); |
Nicholas Flintham | 1e3d311 | 2013-04-10 10:48:38 +0100 | [diff] [blame] | 351 | } |
| 352 | |
Flemmard | 9fc1014 | 2013-04-10 15:59:59 +0200 | [diff] [blame] | 353 | /*setup REG_CP_RB_CNTL */ |
Nicholas Flintham | 1e3d311 | 2013-04-10 10:48:38 +0100 | [diff] [blame] | 354 | adreno_regread(device, REG_CP_RB_CNTL, &rb_cntl); |
| 355 | cp_rb_cntl.val = rb_cntl; |
| 356 | |
Flemmard | 9fc1014 | 2013-04-10 15:59:59 +0200 | [diff] [blame] | 357 | /* |
| 358 | * The size of the ringbuffer in the hardware is the log2 |
| 359 | * representation of the size in quadwords (sizedwords / 2) |
| 360 | */ |
Nicholas Flintham | 1e3d311 | 2013-04-10 10:48:38 +0100 | [diff] [blame] | 361 | cp_rb_cntl.f.rb_bufsz = ilog2(rb->sizedwords >> 1); |
| 362 | |
Flemmard | 9fc1014 | 2013-04-10 15:59:59 +0200 | [diff] [blame] | 363 | /* |
| 364 | * Specify the quadwords to read before updating mem RPTR. |
| 365 | * Like above, pass the log2 representation of the blocksize |
| 366 | * in quadwords. |
| 367 | */ |
Nicholas Flintham | 1e3d311 | 2013-04-10 10:48:38 +0100 | [diff] [blame] | 368 | cp_rb_cntl.f.rb_blksz = ilog2(KGSL_RB_BLKSIZE >> 3); |
| 369 | |
| 370 | if (adreno_is_a2xx(adreno_dev)) { |
Flemmard | 9fc1014 | 2013-04-10 15:59:59 +0200 | [diff] [blame] | 371 | /* WPTR polling */ |
Nicholas Flintham | 1e3d311 | 2013-04-10 10:48:38 +0100 | [diff] [blame] | 372 | cp_rb_cntl.f.rb_poll_en = GSL_RB_CNTL_POLL_EN; |
| 373 | } |
| 374 | |
Flemmard | 9fc1014 | 2013-04-10 15:59:59 +0200 | [diff] [blame] | 375 | /* mem RPTR writebacks */ |
Nicholas Flintham | 1e3d311 | 2013-04-10 10:48:38 +0100 | [diff] [blame] | 376 | cp_rb_cntl.f.rb_no_update = GSL_RB_CNTL_NO_UPDATE; |
| 377 | |
| 378 | adreno_regwrite(device, REG_CP_RB_CNTL, cp_rb_cntl.val); |
| 379 | |
| 380 | adreno_regwrite(device, REG_CP_RB_BASE, rb->buffer_desc.gpuaddr); |
| 381 | |
| 382 | adreno_regwrite(device, REG_CP_RB_RPTR_ADDR, |
| 383 | rb->memptrs_desc.gpuaddr + |
| 384 | GSL_RB_MEMPTRS_RPTR_OFFSET); |
| 385 | |
| 386 | if (adreno_is_a3xx(adreno_dev)) { |
Flemmard | 9fc1014 | 2013-04-10 15:59:59 +0200 | [diff] [blame] | 387 | /* enable access protection to privileged registers */ |
Nicholas Flintham | 1e3d311 | 2013-04-10 10:48:38 +0100 | [diff] [blame] | 388 | adreno_regwrite(device, A3XX_CP_PROTECT_CTRL, 0x00000007); |
| 389 | |
Flemmard | 9fc1014 | 2013-04-10 15:59:59 +0200 | [diff] [blame] | 390 | /* RBBM registers */ |
Nicholas Flintham | 1e3d311 | 2013-04-10 10:48:38 +0100 | [diff] [blame] | 391 | adreno_regwrite(device, A3XX_CP_PROTECT_REG_0, 0x63000040); |
| 392 | adreno_regwrite(device, A3XX_CP_PROTECT_REG_1, 0x62000080); |
| 393 | adreno_regwrite(device, A3XX_CP_PROTECT_REG_2, 0x600000CC); |
| 394 | adreno_regwrite(device, A3XX_CP_PROTECT_REG_3, 0x60000108); |
| 395 | adreno_regwrite(device, A3XX_CP_PROTECT_REG_4, 0x64000140); |
| 396 | adreno_regwrite(device, A3XX_CP_PROTECT_REG_5, 0x66000400); |
| 397 | |
Flemmard | 9fc1014 | 2013-04-10 15:59:59 +0200 | [diff] [blame] | 398 | /* CP registers */ |
Nicholas Flintham | 1e3d311 | 2013-04-10 10:48:38 +0100 | [diff] [blame] | 399 | adreno_regwrite(device, A3XX_CP_PROTECT_REG_6, 0x65000700); |
| 400 | adreno_regwrite(device, A3XX_CP_PROTECT_REG_7, 0x610007D8); |
| 401 | adreno_regwrite(device, A3XX_CP_PROTECT_REG_8, 0x620007E0); |
| 402 | adreno_regwrite(device, A3XX_CP_PROTECT_REG_9, 0x61001178); |
| 403 | adreno_regwrite(device, A3XX_CP_PROTECT_REG_A, 0x64001180); |
| 404 | |
Flemmard | 9fc1014 | 2013-04-10 15:59:59 +0200 | [diff] [blame] | 405 | /* RB registers */ |
Nicholas Flintham | 1e3d311 | 2013-04-10 10:48:38 +0100 | [diff] [blame] | 406 | adreno_regwrite(device, A3XX_CP_PROTECT_REG_B, 0x60003300); |
| 407 | |
Flemmard | 9fc1014 | 2013-04-10 15:59:59 +0200 | [diff] [blame] | 408 | /* VBIF registers */ |
Nicholas Flintham | 1e3d311 | 2013-04-10 10:48:38 +0100 | [diff] [blame] | 409 | adreno_regwrite(device, A3XX_CP_PROTECT_REG_C, 0x6B00C000); |
| 410 | } |
| 411 | |
| 412 | if (adreno_is_a2xx(adreno_dev)) { |
Flemmard | 9fc1014 | 2013-04-10 15:59:59 +0200 | [diff] [blame] | 413 | /* explicitly clear all cp interrupts */ |
Nicholas Flintham | 1e3d311 | 2013-04-10 10:48:38 +0100 | [diff] [blame] | 414 | adreno_regwrite(device, REG_CP_INT_ACK, 0xFFFFFFFF); |
| 415 | } |
| 416 | |
Flemmard | 9fc1014 | 2013-04-10 15:59:59 +0200 | [diff] [blame] | 417 | /* setup scratch/timestamp */ |
Nicholas Flintham | 1e3d311 | 2013-04-10 10:48:38 +0100 | [diff] [blame] | 418 | adreno_regwrite(device, REG_SCRATCH_ADDR, device->memstore.gpuaddr + |
| 419 | KGSL_MEMSTORE_OFFSET(KGSL_MEMSTORE_GLOBAL, |
| 420 | soptimestamp)); |
| 421 | |
| 422 | adreno_regwrite(device, REG_SCRATCH_UMSK, |
| 423 | GSL_RB_MEMPTRS_SCRATCH_MASK); |
| 424 | |
Flemmard | 9fc1014 | 2013-04-10 15:59:59 +0200 | [diff] [blame] | 425 | /* load the CP ucode */ |
Nicholas Flintham | 1e3d311 | 2013-04-10 10:48:38 +0100 | [diff] [blame] | 426 | status = adreno_ringbuffer_load_pm4_ucode(device); |
| 427 | if (status != 0) |
| 428 | return status; |
| 429 | |
Flemmard | 9fc1014 | 2013-04-10 15:59:59 +0200 | [diff] [blame] | 430 | /* load the prefetch parser ucode */ |
Nicholas Flintham | 1e3d311 | 2013-04-10 10:48:38 +0100 | [diff] [blame] | 431 | status = adreno_ringbuffer_load_pfp_ucode(device); |
| 432 | if (status != 0) |
| 433 | return status; |
| 434 | |
Flemmard | 9fc1014 | 2013-04-10 15:59:59 +0200 | [diff] [blame] | 435 | /* CP ROQ queue sizes (bytes) - RB:16, ST:16, IB1:32, IB2:64 */ |
Nicholas Flintham | 8c6a490 | 2013-04-30 13:56:09 +0100 | [diff] [blame^] | 436 | if (adreno_is_a305(adreno_dev) || adreno_is_a320(adreno_dev)) |
Nicholas Flintham | 1e3d311 | 2013-04-10 10:48:38 +0100 | [diff] [blame] | 437 | adreno_regwrite(device, REG_CP_QUEUE_THRESHOLDS, 0x000E0602); |
| 438 | |
| 439 | rb->rptr = 0; |
| 440 | rb->wptr = 0; |
| 441 | |
Flemmard | 9fc1014 | 2013-04-10 15:59:59 +0200 | [diff] [blame] | 442 | /* clear ME_HALT to start micro engine */ |
Nicholas Flintham | 1e3d311 | 2013-04-10 10:48:38 +0100 | [diff] [blame] | 443 | adreno_regwrite(device, REG_CP_ME_CNTL, 0); |
| 444 | |
Flemmard | 9fc1014 | 2013-04-10 15:59:59 +0200 | [diff] [blame] | 445 | /* ME init is GPU specific, so jump into the sub-function */ |
Nicholas Flintham | 8c6a490 | 2013-04-30 13:56:09 +0100 | [diff] [blame^] | 446 | adreno_dev->gpudev->rb_init(adreno_dev, rb); |
Nicholas Flintham | 1e3d311 | 2013-04-10 10:48:38 +0100 | [diff] [blame] | 447 | |
Flemmard | 9fc1014 | 2013-04-10 15:59:59 +0200 | [diff] [blame] | 448 | /* idle device to validate ME INIT */ |
Nicholas Flintham | 1e3d311 | 2013-04-10 10:48:38 +0100 | [diff] [blame] | 449 | status = adreno_idle(device); |
| 450 | |
| 451 | if (status == 0) |
| 452 | rb->flags |= KGSL_FLAGS_STARTED; |
| 453 | |
| 454 | return status; |
| 455 | } |
| 456 | |
| 457 | void adreno_ringbuffer_stop(struct adreno_ringbuffer *rb) |
| 458 | { |
Flemmard | 9fc1014 | 2013-04-10 15:59:59 +0200 | [diff] [blame] | 459 | struct kgsl_device *device = rb->device; |
| 460 | struct adreno_device *adreno_dev = ADRENO_DEVICE(device); |
| 461 | |
Nicholas Flintham | 1e3d311 | 2013-04-10 10:48:38 +0100 | [diff] [blame] | 462 | if (rb->flags & KGSL_FLAGS_STARTED) { |
Flemmard | 9fc1014 | 2013-04-10 15:59:59 +0200 | [diff] [blame] | 463 | if (adreno_is_a200(adreno_dev)) |
| 464 | adreno_regwrite(rb->device, REG_CP_ME_CNTL, 0x10000000); |
| 465 | |
Nicholas Flintham | 1e3d311 | 2013-04-10 10:48:38 +0100 | [diff] [blame] | 466 | rb->flags &= ~KGSL_FLAGS_STARTED; |
| 467 | } |
| 468 | } |
| 469 | |
| 470 | int adreno_ringbuffer_init(struct kgsl_device *device) |
| 471 | { |
| 472 | int status; |
| 473 | struct adreno_device *adreno_dev = ADRENO_DEVICE(device); |
| 474 | struct adreno_ringbuffer *rb = &adreno_dev->ringbuffer; |
| 475 | |
| 476 | rb->device = device; |
Flemmard | 9fc1014 | 2013-04-10 15:59:59 +0200 | [diff] [blame] | 477 | /* |
| 478 | * It is silly to convert this to words and then back to bytes |
| 479 | * immediately below, but most of the rest of the code deals |
| 480 | * in words, so we might as well only do the math once |
| 481 | */ |
Nicholas Flintham | 1e3d311 | 2013-04-10 10:48:38 +0100 | [diff] [blame] | 482 | rb->sizedwords = KGSL_RB_SIZE >> 2; |
| 483 | |
Flemmard | 9fc1014 | 2013-04-10 15:59:59 +0200 | [diff] [blame] | 484 | /* allocate memory for ringbuffer */ |
Nicholas Flintham | 1e3d311 | 2013-04-10 10:48:38 +0100 | [diff] [blame] | 485 | status = kgsl_allocate_contiguous(&rb->buffer_desc, |
| 486 | (rb->sizedwords << 2)); |
| 487 | |
| 488 | if (status != 0) { |
| 489 | adreno_ringbuffer_close(rb); |
| 490 | return status; |
| 491 | } |
| 492 | |
Flemmard | 9fc1014 | 2013-04-10 15:59:59 +0200 | [diff] [blame] | 493 | /* allocate memory for polling and timestamps */ |
| 494 | /* This really can be at 4 byte alignment boundry but for using MMU |
| 495 | * we need to make it at page boundary */ |
Nicholas Flintham | 1e3d311 | 2013-04-10 10:48:38 +0100 | [diff] [blame] | 496 | status = kgsl_allocate_contiguous(&rb->memptrs_desc, |
| 497 | sizeof(struct kgsl_rbmemptrs)); |
| 498 | |
| 499 | if (status != 0) { |
| 500 | adreno_ringbuffer_close(rb); |
| 501 | return status; |
| 502 | } |
| 503 | |
Flemmard | 9fc1014 | 2013-04-10 15:59:59 +0200 | [diff] [blame] | 504 | /* overlay structure on memptrs memory */ |
Nicholas Flintham | 1e3d311 | 2013-04-10 10:48:38 +0100 | [diff] [blame] | 505 | rb->memptrs = (struct kgsl_rbmemptrs *) rb->memptrs_desc.hostptr; |
| 506 | |
| 507 | return 0; |
| 508 | } |
| 509 | |
| 510 | void adreno_ringbuffer_close(struct adreno_ringbuffer *rb) |
| 511 | { |
| 512 | struct adreno_device *adreno_dev = ADRENO_DEVICE(rb->device); |
| 513 | |
| 514 | kgsl_sharedmem_free(&rb->buffer_desc); |
| 515 | kgsl_sharedmem_free(&rb->memptrs_desc); |
| 516 | |
| 517 | kfree(adreno_dev->pfp_fw); |
| 518 | kfree(adreno_dev->pm4_fw); |
| 519 | |
| 520 | adreno_dev->pfp_fw = NULL; |
| 521 | adreno_dev->pm4_fw = NULL; |
| 522 | |
| 523 | memset(rb, 0, sizeof(struct adreno_ringbuffer)); |
| 524 | } |
| 525 | |
| 526 | static uint32_t |
| 527 | adreno_ringbuffer_addcmds(struct adreno_ringbuffer *rb, |
| 528 | struct adreno_context *context, |
| 529 | unsigned int flags, unsigned int *cmds, |
Flemmard | 9fc1014 | 2013-04-10 15:59:59 +0200 | [diff] [blame] | 530 | int sizedwords, uint32_t timestamp) |
Nicholas Flintham | 1e3d311 | 2013-04-10 10:48:38 +0100 | [diff] [blame] | 531 | { |
| 532 | struct adreno_device *adreno_dev = ADRENO_DEVICE(rb->device); |
| 533 | unsigned int *ringcmds; |
Nicholas Flintham | 1e3d311 | 2013-04-10 10:48:38 +0100 | [diff] [blame] | 534 | unsigned int total_sizedwords = sizedwords; |
| 535 | unsigned int i; |
| 536 | unsigned int rcmd_gpu; |
| 537 | unsigned int context_id = KGSL_MEMSTORE_GLOBAL; |
| 538 | unsigned int gpuaddr = rb->device->memstore.gpuaddr; |
| 539 | |
Flemmard | 9fc1014 | 2013-04-10 15:59:59 +0200 | [diff] [blame] | 540 | /* |
| 541 | * if the context was not created with per context timestamp |
| 542 | * support, we must use the global timestamp since issueibcmds |
| 543 | * will be returning that one. |
| 544 | */ |
| 545 | if (context && context->flags & CTXT_FLAGS_PER_CONTEXT_TS) |
Nicholas Flintham | 1e3d311 | 2013-04-10 10:48:38 +0100 | [diff] [blame] | 546 | context_id = context->id; |
| 547 | |
Flemmard | 9fc1014 | 2013-04-10 15:59:59 +0200 | [diff] [blame] | 548 | if ((context && context->flags & CTXT_FLAGS_USER_GENERATED_TS) && |
| 549 | (!(flags & KGSL_CMD_FLAGS_INTERNAL_ISSUE))) { |
| 550 | if (timestamp_cmp(rb->timestamp[context_id], |
| 551 | timestamp) >= 0) { |
| 552 | KGSL_DRV_ERR(rb->device, |
| 553 | "Invalid user generated ts <%d:0x%x>, " |
| 554 | "less than last issued ts <%d:0x%x>\n", |
| 555 | context_id, timestamp, context_id, |
| 556 | rb->timestamp[context_id]); |
| 557 | return -ERANGE; |
| 558 | } |
| 559 | } |
| 560 | |
| 561 | /* reserve space to temporarily turn off protected mode |
| 562 | * error checking if needed |
| 563 | */ |
Nicholas Flintham | 1e3d311 | 2013-04-10 10:48:38 +0100 | [diff] [blame] | 564 | total_sizedwords += flags & KGSL_CMD_FLAGS_PMODE ? 4 : 0; |
Flemmard | 9fc1014 | 2013-04-10 15:59:59 +0200 | [diff] [blame] | 565 | /* 2 dwords to store the start of command sequence */ |
Nicholas Flintham | 1e3d311 | 2013-04-10 10:48:38 +0100 | [diff] [blame] | 566 | total_sizedwords += 2; |
| 567 | |
Flemmard | 9fc1014 | 2013-04-10 15:59:59 +0200 | [diff] [blame] | 568 | /* Add CP_COND_EXEC commands to generate CP_INTERRUPT */ |
| 569 | total_sizedwords += context ? 13 : 0; |
| 570 | |
Nicholas Flintham | 1e3d311 | 2013-04-10 10:48:38 +0100 | [diff] [blame] | 571 | if (adreno_is_a3xx(adreno_dev)) |
| 572 | total_sizedwords += 7; |
| 573 | |
Flemmard | 877127b | 2013-04-11 18:33:24 +0200 | [diff] [blame] | 574 | if (adreno_is_a2xx(adreno_dev)) |
| 575 | total_sizedwords += 2; /* CP_WAIT_FOR_IDLE */ |
| 576 | |
Flemmard | 9fc1014 | 2013-04-10 15:59:59 +0200 | [diff] [blame] | 577 | total_sizedwords += 2; /* scratchpad ts for fault tolerance */ |
| 578 | if (context && context->flags & CTXT_FLAGS_PER_CONTEXT_TS && |
| 579 | !(flags & KGSL_CMD_FLAGS_INTERNAL_ISSUE)) { |
Nicholas Flintham | 8c6a490 | 2013-04-30 13:56:09 +0100 | [diff] [blame^] | 580 | total_sizedwords += 3; /* sop timestamp */ |
| 581 | total_sizedwords += 4; /* eop timestamp */ |
Flemmard | 9fc1014 | 2013-04-10 15:59:59 +0200 | [diff] [blame] | 582 | total_sizedwords += 3; /* global timestamp without cache |
| 583 | * flush for non-zero context */ |
Nicholas Flintham | 8c6a490 | 2013-04-30 13:56:09 +0100 | [diff] [blame^] | 584 | } else { |
| 585 | total_sizedwords += 4; /* global timestamp for fault tolerance*/ |
Nicholas Flintham | 1e3d311 | 2013-04-10 10:48:38 +0100 | [diff] [blame] | 586 | } |
| 587 | |
Flemmard | 877127b | 2013-04-11 18:33:24 +0200 | [diff] [blame] | 588 | if (flags & KGSL_CMD_FLAGS_EOF) |
| 589 | total_sizedwords += 2; |
| 590 | |
Flemmard | 9fc1014 | 2013-04-10 15:59:59 +0200 | [diff] [blame] | 591 | ringcmds = adreno_ringbuffer_allocspace(rb, context, total_sizedwords); |
| 592 | if (!ringcmds) { |
| 593 | /* |
| 594 | * We could not allocate space in ringbuffer, just return the |
| 595 | * last timestamp |
| 596 | */ |
Nicholas Flintham | 1e3d311 | 2013-04-10 10:48:38 +0100 | [diff] [blame] | 597 | return rb->timestamp[context_id]; |
| 598 | } |
| 599 | |
| 600 | rcmd_gpu = rb->buffer_desc.gpuaddr |
| 601 | + sizeof(uint)*(rb->wptr-total_sizedwords); |
| 602 | |
| 603 | GSL_RB_WRITE(ringcmds, rcmd_gpu, cp_nop_packet(1)); |
| 604 | GSL_RB_WRITE(ringcmds, rcmd_gpu, KGSL_CMD_IDENTIFIER); |
| 605 | |
Flemmard | 877127b | 2013-04-11 18:33:24 +0200 | [diff] [blame] | 606 | if (flags & KGSL_CMD_FLAGS_PMODE) { |
| 607 | /* disable protected mode error checking */ |
| 608 | GSL_RB_WRITE(ringcmds, rcmd_gpu, |
| 609 | cp_type3_packet(CP_SET_PROTECTED_MODE, 1)); |
| 610 | GSL_RB_WRITE(ringcmds, rcmd_gpu, 0); |
| 611 | } |
| 612 | |
| 613 | for (i = 0; i < sizedwords; i++) { |
| 614 | GSL_RB_WRITE(ringcmds, rcmd_gpu, *cmds); |
| 615 | cmds++; |
| 616 | } |
| 617 | |
| 618 | if (flags & KGSL_CMD_FLAGS_PMODE) { |
| 619 | /* re-enable protected mode error checking */ |
| 620 | GSL_RB_WRITE(ringcmds, rcmd_gpu, |
| 621 | cp_type3_packet(CP_SET_PROTECTED_MODE, 1)); |
| 622 | GSL_RB_WRITE(ringcmds, rcmd_gpu, 1); |
| 623 | } |
| 624 | |
Nicholas Flintham | 8c6a490 | 2013-04-30 13:56:09 +0100 | [diff] [blame^] | 625 | /* always increment the global timestamp. once. */ |
| 626 | rb->timestamp[KGSL_MEMSTORE_GLOBAL]++; |
| 627 | |
| 628 | /* Do not update context's timestamp for internal submissions */ |
| 629 | if (context && !(flags & KGSL_CMD_FLAGS_INTERNAL_ISSUE)) { |
| 630 | if (context_id == KGSL_MEMSTORE_GLOBAL) |
| 631 | rb->timestamp[context->id] = |
| 632 | rb->timestamp[KGSL_MEMSTORE_GLOBAL]; |
| 633 | else if (context->flags & CTXT_FLAGS_USER_GENERATED_TS) |
| 634 | rb->timestamp[context_id] = timestamp; |
| 635 | else |
| 636 | rb->timestamp[context_id]++; |
| 637 | } |
| 638 | timestamp = rb->timestamp[context_id]; |
| 639 | |
Flemmard | 877127b | 2013-04-11 18:33:24 +0200 | [diff] [blame] | 640 | /* HW Workaround for MMU Page fault |
| 641 | * due to memory getting free early before |
| 642 | * GPU completes it. |
| 643 | */ |
| 644 | if (adreno_is_a2xx(adreno_dev)) { |
| 645 | GSL_RB_WRITE(ringcmds, rcmd_gpu, |
| 646 | cp_type3_packet(CP_WAIT_FOR_IDLE, 1)); |
| 647 | GSL_RB_WRITE(ringcmds, rcmd_gpu, 0x00); |
| 648 | } |
| 649 | |
Nicholas Flintham | 8c6a490 | 2013-04-30 13:56:09 +0100 | [diff] [blame^] | 650 | /* scratchpad ts for fault tolerance */ |
| 651 | GSL_RB_WRITE(ringcmds, rcmd_gpu, cp_type0_packet(REG_CP_TIMESTAMP, 1)); |
| 652 | GSL_RB_WRITE(ringcmds, rcmd_gpu, rb->timestamp[KGSL_MEMSTORE_GLOBAL]); |
| 653 | |
Nicholas Flintham | 1e3d311 | 2013-04-10 10:48:38 +0100 | [diff] [blame] | 654 | if (adreno_is_a3xx(adreno_dev)) { |
Flemmard | 9fc1014 | 2013-04-10 15:59:59 +0200 | [diff] [blame] | 655 | /* |
Nicholas Flintham | 8c6a490 | 2013-04-30 13:56:09 +0100 | [diff] [blame^] | 656 | * FLush HLSQ lazy updates to make sure there are no |
| 657 | * rsources pending for indirect loads after the timestamp |
Flemmard | 9fc1014 | 2013-04-10 15:59:59 +0200 | [diff] [blame] | 658 | */ |
Nicholas Flintham | 1e3d311 | 2013-04-10 10:48:38 +0100 | [diff] [blame] | 659 | |
| 660 | GSL_RB_WRITE(ringcmds, rcmd_gpu, |
| 661 | cp_type3_packet(CP_EVENT_WRITE, 1)); |
Flemmard | 9fc1014 | 2013-04-10 15:59:59 +0200 | [diff] [blame] | 662 | GSL_RB_WRITE(ringcmds, rcmd_gpu, 0x07); /* HLSQ_FLUSH */ |
Nicholas Flintham | 1e3d311 | 2013-04-10 10:48:38 +0100 | [diff] [blame] | 663 | GSL_RB_WRITE(ringcmds, rcmd_gpu, |
| 664 | cp_type3_packet(CP_WAIT_FOR_IDLE, 1)); |
| 665 | GSL_RB_WRITE(ringcmds, rcmd_gpu, 0x00); |
| 666 | } |
| 667 | |
Flemmard | 9fc1014 | 2013-04-10 15:59:59 +0200 | [diff] [blame] | 668 | if (context && context->flags & CTXT_FLAGS_PER_CONTEXT_TS |
| 669 | && !(flags & KGSL_CMD_FLAGS_INTERNAL_ISSUE)) { |
Nicholas Flintham | 8c6a490 | 2013-04-30 13:56:09 +0100 | [diff] [blame^] | 670 | /* start-of-pipeline timestamp */ |
| 671 | GSL_RB_WRITE(ringcmds, rcmd_gpu, |
| 672 | cp_type3_packet(CP_MEM_WRITE, 2)); |
| 673 | GSL_RB_WRITE(ringcmds, rcmd_gpu, (gpuaddr + |
| 674 | KGSL_MEMSTORE_OFFSET(context_id, soptimestamp))); |
| 675 | GSL_RB_WRITE(ringcmds, rcmd_gpu, timestamp); |
| 676 | |
| 677 | /* end-of-pipeline timestamp */ |
| 678 | GSL_RB_WRITE(ringcmds, rcmd_gpu, |
| 679 | cp_type3_packet(CP_EVENT_WRITE, 3)); |
| 680 | GSL_RB_WRITE(ringcmds, rcmd_gpu, CACHE_FLUSH_TS); |
| 681 | GSL_RB_WRITE(ringcmds, rcmd_gpu, (gpuaddr + |
| 682 | KGSL_MEMSTORE_OFFSET(context_id, eoptimestamp))); |
| 683 | GSL_RB_WRITE(ringcmds, rcmd_gpu, timestamp); |
Nicholas Flintham | 1e3d311 | 2013-04-10 10:48:38 +0100 | [diff] [blame] | 684 | |
| 685 | GSL_RB_WRITE(ringcmds, rcmd_gpu, |
| 686 | cp_type3_packet(CP_MEM_WRITE, 2)); |
| 687 | GSL_RB_WRITE(ringcmds, rcmd_gpu, (gpuaddr + |
Flemmard | 9fc1014 | 2013-04-10 15:59:59 +0200 | [diff] [blame] | 688 | KGSL_MEMSTORE_OFFSET(KGSL_MEMSTORE_GLOBAL, |
| 689 | eoptimestamp))); |
Nicholas Flintham | 1e3d311 | 2013-04-10 10:48:38 +0100 | [diff] [blame] | 690 | GSL_RB_WRITE(ringcmds, rcmd_gpu, |
| 691 | rb->timestamp[KGSL_MEMSTORE_GLOBAL]); |
Nicholas Flintham | 8c6a490 | 2013-04-30 13:56:09 +0100 | [diff] [blame^] | 692 | } else { |
Flemmard | 877127b | 2013-04-11 18:33:24 +0200 | [diff] [blame] | 693 | GSL_RB_WRITE(ringcmds, rcmd_gpu, |
Nicholas Flintham | 8c6a490 | 2013-04-30 13:56:09 +0100 | [diff] [blame^] | 694 | cp_type3_packet(CP_EVENT_WRITE, 3)); |
| 695 | GSL_RB_WRITE(ringcmds, rcmd_gpu, CACHE_FLUSH_TS); |
| 696 | GSL_RB_WRITE(ringcmds, rcmd_gpu, (gpuaddr + |
| 697 | KGSL_MEMSTORE_OFFSET(KGSL_MEMSTORE_GLOBAL, |
| 698 | eoptimestamp))); |
| 699 | GSL_RB_WRITE(ringcmds, rcmd_gpu, |
| 700 | rb->timestamp[KGSL_MEMSTORE_GLOBAL]); |
Flemmard | 877127b | 2013-04-11 18:33:24 +0200 | [diff] [blame] | 701 | } |
Flemmard | 9fc1014 | 2013-04-10 15:59:59 +0200 | [diff] [blame] | 702 | if (context) { |
| 703 | /* Conditional execution based on memory values */ |
Nicholas Flintham | 1e3d311 | 2013-04-10 10:48:38 +0100 | [diff] [blame] | 704 | GSL_RB_WRITE(ringcmds, rcmd_gpu, |
| 705 | cp_type3_packet(CP_COND_EXEC, 4)); |
| 706 | GSL_RB_WRITE(ringcmds, rcmd_gpu, (gpuaddr + |
| 707 | KGSL_MEMSTORE_OFFSET( |
| 708 | context_id, ts_cmp_enable)) >> 2); |
| 709 | GSL_RB_WRITE(ringcmds, rcmd_gpu, (gpuaddr + |
| 710 | KGSL_MEMSTORE_OFFSET( |
| 711 | context_id, ref_wait_ts)) >> 2); |
| 712 | GSL_RB_WRITE(ringcmds, rcmd_gpu, timestamp); |
Flemmard | 9fc1014 | 2013-04-10 15:59:59 +0200 | [diff] [blame] | 713 | /* # of conditional command DWORDs */ |
| 714 | GSL_RB_WRITE(ringcmds, rcmd_gpu, 8); |
| 715 | |
| 716 | /* Clear the ts_cmp_enable for the context */ |
| 717 | GSL_RB_WRITE(ringcmds, rcmd_gpu, |
| 718 | cp_type3_packet(CP_MEM_WRITE, 2)); |
| 719 | GSL_RB_WRITE(ringcmds, rcmd_gpu, gpuaddr + |
| 720 | KGSL_MEMSTORE_OFFSET( |
| 721 | context_id, ts_cmp_enable)); |
| 722 | GSL_RB_WRITE(ringcmds, rcmd_gpu, 0x0); |
| 723 | |
| 724 | /* Clear the ts_cmp_enable for the global timestamp */ |
| 725 | GSL_RB_WRITE(ringcmds, rcmd_gpu, |
| 726 | cp_type3_packet(CP_MEM_WRITE, 2)); |
| 727 | GSL_RB_WRITE(ringcmds, rcmd_gpu, gpuaddr + |
| 728 | KGSL_MEMSTORE_OFFSET( |
| 729 | KGSL_MEMSTORE_GLOBAL, ts_cmp_enable)); |
| 730 | GSL_RB_WRITE(ringcmds, rcmd_gpu, 0x0); |
| 731 | |
| 732 | /* Trigger the interrupt */ |
Nicholas Flintham | 1e3d311 | 2013-04-10 10:48:38 +0100 | [diff] [blame] | 733 | GSL_RB_WRITE(ringcmds, rcmd_gpu, |
| 734 | cp_type3_packet(CP_INTERRUPT, 1)); |
| 735 | GSL_RB_WRITE(ringcmds, rcmd_gpu, CP_INT_CNTL__RB_INT_MASK); |
| 736 | } |
| 737 | |
| 738 | if (adreno_is_a3xx(adreno_dev)) { |
Flemmard | 9fc1014 | 2013-04-10 15:59:59 +0200 | [diff] [blame] | 739 | /* Dummy set-constant to trigger context rollover */ |
Nicholas Flintham | 1e3d311 | 2013-04-10 10:48:38 +0100 | [diff] [blame] | 740 | GSL_RB_WRITE(ringcmds, rcmd_gpu, |
| 741 | cp_type3_packet(CP_SET_CONSTANT, 2)); |
| 742 | GSL_RB_WRITE(ringcmds, rcmd_gpu, |
| 743 | (0x4<<16)|(A3XX_HLSQ_CL_KERNEL_GROUP_X_REG - 0x2000)); |
| 744 | GSL_RB_WRITE(ringcmds, rcmd_gpu, 0); |
| 745 | } |
| 746 | |
Flemmard | 9fc1014 | 2013-04-10 15:59:59 +0200 | [diff] [blame] | 747 | if (flags & KGSL_CMD_FLAGS_EOF) { |
| 748 | GSL_RB_WRITE(ringcmds, rcmd_gpu, cp_nop_packet(1)); |
| 749 | GSL_RB_WRITE(ringcmds, rcmd_gpu, KGSL_END_OF_FRAME_IDENTIFIER); |
| 750 | } |
| 751 | |
Nicholas Flintham | 1e3d311 | 2013-04-10 10:48:38 +0100 | [diff] [blame] | 752 | adreno_ringbuffer_submit(rb); |
| 753 | |
| 754 | return timestamp; |
| 755 | } |
| 756 | |
| 757 | unsigned int |
| 758 | adreno_ringbuffer_issuecmds(struct kgsl_device *device, |
| 759 | struct adreno_context *drawctxt, |
| 760 | unsigned int flags, |
| 761 | unsigned int *cmds, |
| 762 | int sizedwords) |
| 763 | { |
| 764 | struct adreno_device *adreno_dev = ADRENO_DEVICE(device); |
| 765 | struct adreno_ringbuffer *rb = &adreno_dev->ringbuffer; |
| 766 | |
| 767 | if (device->state & KGSL_STATE_HUNG) |
| 768 | return kgsl_readtimestamp(device, KGSL_MEMSTORE_GLOBAL, |
| 769 | KGSL_TIMESTAMP_RETIRED); |
Flemmard | 9fc1014 | 2013-04-10 15:59:59 +0200 | [diff] [blame] | 770 | |
| 771 | flags |= KGSL_CMD_FLAGS_INTERNAL_ISSUE; |
| 772 | |
| 773 | return adreno_ringbuffer_addcmds(rb, drawctxt, flags, cmds, |
| 774 | sizedwords, 0); |
Nicholas Flintham | 1e3d311 | 2013-04-10 10:48:38 +0100 | [diff] [blame] | 775 | } |
| 776 | |
| 777 | static bool _parse_ibs(struct kgsl_device_private *dev_priv, uint gpuaddr, |
| 778 | int sizedwords); |
| 779 | |
| 780 | static bool |
| 781 | _handle_type3(struct kgsl_device_private *dev_priv, uint *hostaddr) |
| 782 | { |
| 783 | unsigned int opcode = cp_type3_opcode(*hostaddr); |
| 784 | switch (opcode) { |
| 785 | case CP_INDIRECT_BUFFER_PFD: |
| 786 | case CP_INDIRECT_BUFFER_PFE: |
| 787 | case CP_COND_INDIRECT_BUFFER_PFE: |
| 788 | case CP_COND_INDIRECT_BUFFER_PFD: |
| 789 | return _parse_ibs(dev_priv, hostaddr[1], hostaddr[2]); |
| 790 | case CP_NOP: |
| 791 | case CP_WAIT_FOR_IDLE: |
| 792 | case CP_WAIT_REG_MEM: |
| 793 | case CP_WAIT_REG_EQ: |
| 794 | case CP_WAT_REG_GTE: |
| 795 | case CP_WAIT_UNTIL_READ: |
| 796 | case CP_WAIT_IB_PFD_COMPLETE: |
| 797 | case CP_REG_RMW: |
| 798 | case CP_REG_TO_MEM: |
| 799 | case CP_MEM_WRITE: |
| 800 | case CP_MEM_WRITE_CNTR: |
| 801 | case CP_COND_EXEC: |
| 802 | case CP_COND_WRITE: |
| 803 | case CP_EVENT_WRITE: |
| 804 | case CP_EVENT_WRITE_SHD: |
| 805 | case CP_EVENT_WRITE_CFL: |
| 806 | case CP_EVENT_WRITE_ZPD: |
| 807 | case CP_DRAW_INDX: |
| 808 | case CP_DRAW_INDX_2: |
| 809 | case CP_DRAW_INDX_BIN: |
| 810 | case CP_DRAW_INDX_2_BIN: |
| 811 | case CP_VIZ_QUERY: |
| 812 | case CP_SET_STATE: |
| 813 | case CP_SET_CONSTANT: |
| 814 | case CP_IM_LOAD: |
| 815 | case CP_IM_LOAD_IMMEDIATE: |
| 816 | case CP_LOAD_CONSTANT_CONTEXT: |
| 817 | case CP_INVALIDATE_STATE: |
| 818 | case CP_SET_SHADER_BASES: |
| 819 | case CP_SET_BIN_MASK: |
| 820 | case CP_SET_BIN_SELECT: |
| 821 | case CP_SET_BIN_BASE_OFFSET: |
| 822 | case CP_SET_BIN_DATA: |
| 823 | case CP_CONTEXT_UPDATE: |
| 824 | case CP_INTERRUPT: |
| 825 | case CP_IM_STORE: |
| 826 | case CP_LOAD_STATE: |
| 827 | break; |
Flemmard | 9fc1014 | 2013-04-10 15:59:59 +0200 | [diff] [blame] | 828 | /* these shouldn't come from userspace */ |
Nicholas Flintham | 1e3d311 | 2013-04-10 10:48:38 +0100 | [diff] [blame] | 829 | case CP_ME_INIT: |
| 830 | case CP_SET_PROTECTED_MODE: |
| 831 | default: |
| 832 | KGSL_CMD_ERR(dev_priv->device, "bad CP opcode %0x\n", opcode); |
| 833 | return false; |
| 834 | break; |
| 835 | } |
| 836 | |
| 837 | return true; |
| 838 | } |
| 839 | |
| 840 | static bool |
| 841 | _handle_type0(struct kgsl_device_private *dev_priv, uint *hostaddr) |
| 842 | { |
| 843 | unsigned int reg = type0_pkt_offset(*hostaddr); |
| 844 | unsigned int cnt = type0_pkt_size(*hostaddr); |
| 845 | if (reg < 0x0192 || (reg + cnt) >= 0x8000) { |
| 846 | KGSL_CMD_ERR(dev_priv->device, "bad type0 reg: 0x%0x cnt: %d\n", |
| 847 | reg, cnt); |
| 848 | return false; |
| 849 | } |
| 850 | return true; |
| 851 | } |
| 852 | |
Flemmard | 9fc1014 | 2013-04-10 15:59:59 +0200 | [diff] [blame] | 853 | /* |
| 854 | * Traverse IBs and dump them to test vector. Detect swap by inspecting |
| 855 | * register writes, keeping note of the current state, and dump |
| 856 | * framebuffer config to test vector |
| 857 | */ |
Nicholas Flintham | 1e3d311 | 2013-04-10 10:48:38 +0100 | [diff] [blame] | 858 | static bool _parse_ibs(struct kgsl_device_private *dev_priv, |
| 859 | uint gpuaddr, int sizedwords) |
| 860 | { |
Flemmard | 9fc1014 | 2013-04-10 15:59:59 +0200 | [diff] [blame] | 861 | static uint level; /* recursion level */ |
Nicholas Flintham | 1e3d311 | 2013-04-10 10:48:38 +0100 | [diff] [blame] | 862 | bool ret = false; |
| 863 | uint *hostaddr, *hoststart; |
Flemmard | 9fc1014 | 2013-04-10 15:59:59 +0200 | [diff] [blame] | 864 | int dwords_left = sizedwords; /* dwords left in the current command |
| 865 | buffer */ |
Nicholas Flintham | 1e3d311 | 2013-04-10 10:48:38 +0100 | [diff] [blame] | 866 | struct kgsl_mem_entry *entry; |
| 867 | |
| 868 | spin_lock(&dev_priv->process_priv->mem_lock); |
| 869 | entry = kgsl_sharedmem_find_region(dev_priv->process_priv, |
| 870 | gpuaddr, sizedwords * sizeof(uint)); |
| 871 | spin_unlock(&dev_priv->process_priv->mem_lock); |
| 872 | if (entry == NULL) { |
| 873 | KGSL_CMD_ERR(dev_priv->device, |
| 874 | "no mapping for gpuaddr: 0x%08x\n", gpuaddr); |
| 875 | return false; |
| 876 | } |
| 877 | |
| 878 | hostaddr = (uint *)kgsl_gpuaddr_to_vaddr(&entry->memdesc, gpuaddr); |
| 879 | if (hostaddr == NULL) { |
| 880 | KGSL_CMD_ERR(dev_priv->device, |
| 881 | "no mapping for gpuaddr: 0x%08x\n", gpuaddr); |
| 882 | return false; |
| 883 | } |
| 884 | |
| 885 | hoststart = hostaddr; |
| 886 | |
| 887 | level++; |
| 888 | |
| 889 | KGSL_CMD_INFO(dev_priv->device, "ib: gpuaddr:0x%08x, wc:%d, hptr:%p\n", |
| 890 | gpuaddr, sizedwords, hostaddr); |
| 891 | |
| 892 | mb(); |
| 893 | while (dwords_left > 0) { |
| 894 | bool cur_ret = true; |
Flemmard | 9fc1014 | 2013-04-10 15:59:59 +0200 | [diff] [blame] | 895 | int count = 0; /* dword count including packet header */ |
Nicholas Flintham | 1e3d311 | 2013-04-10 10:48:38 +0100 | [diff] [blame] | 896 | |
| 897 | switch (*hostaddr >> 30) { |
Flemmard | 9fc1014 | 2013-04-10 15:59:59 +0200 | [diff] [blame] | 898 | case 0x0: /* type-0 */ |
Nicholas Flintham | 1e3d311 | 2013-04-10 10:48:38 +0100 | [diff] [blame] | 899 | count = (*hostaddr >> 16)+2; |
| 900 | cur_ret = _handle_type0(dev_priv, hostaddr); |
| 901 | break; |
Flemmard | 9fc1014 | 2013-04-10 15:59:59 +0200 | [diff] [blame] | 902 | case 0x1: /* type-1 */ |
Nicholas Flintham | 1e3d311 | 2013-04-10 10:48:38 +0100 | [diff] [blame] | 903 | count = 2; |
| 904 | break; |
Flemmard | 9fc1014 | 2013-04-10 15:59:59 +0200 | [diff] [blame] | 905 | case 0x3: /* type-3 */ |
Nicholas Flintham | 1e3d311 | 2013-04-10 10:48:38 +0100 | [diff] [blame] | 906 | count = ((*hostaddr >> 16) & 0x3fff) + 2; |
| 907 | cur_ret = _handle_type3(dev_priv, hostaddr); |
| 908 | break; |
| 909 | default: |
| 910 | KGSL_CMD_ERR(dev_priv->device, "unexpected type: " |
| 911 | "type:%d, word:0x%08x @ 0x%p, gpu:0x%08x\n", |
| 912 | *hostaddr >> 30, *hostaddr, hostaddr, |
| 913 | gpuaddr+4*(sizedwords-dwords_left)); |
| 914 | cur_ret = false; |
| 915 | count = dwords_left; |
| 916 | break; |
| 917 | } |
| 918 | |
| 919 | if (!cur_ret) { |
| 920 | KGSL_CMD_ERR(dev_priv->device, |
| 921 | "bad sub-type: #:%d/%d, v:0x%08x" |
| 922 | " @ 0x%p[gb:0x%08x], level:%d\n", |
| 923 | sizedwords-dwords_left, sizedwords, *hostaddr, |
| 924 | hostaddr, gpuaddr+4*(sizedwords-dwords_left), |
| 925 | level); |
| 926 | |
| 927 | if (ADRENO_DEVICE(dev_priv->device)->ib_check_level |
| 928 | >= 2) |
| 929 | print_hex_dump(KERN_ERR, |
| 930 | level == 1 ? "IB1:" : "IB2:", |
| 931 | DUMP_PREFIX_OFFSET, 32, 4, hoststart, |
| 932 | sizedwords*4, 0); |
| 933 | goto done; |
| 934 | } |
| 935 | |
Flemmard | 9fc1014 | 2013-04-10 15:59:59 +0200 | [diff] [blame] | 936 | /* jump to next packet */ |
Nicholas Flintham | 1e3d311 | 2013-04-10 10:48:38 +0100 | [diff] [blame] | 937 | dwords_left -= count; |
| 938 | hostaddr += count; |
| 939 | if (dwords_left < 0) { |
| 940 | KGSL_CMD_ERR(dev_priv->device, |
| 941 | "bad count: c:%d, #:%d/%d, " |
| 942 | "v:0x%08x @ 0x%p[gb:0x%08x], level:%d\n", |
| 943 | count, sizedwords-(dwords_left+count), |
| 944 | sizedwords, *(hostaddr-count), hostaddr-count, |
| 945 | gpuaddr+4*(sizedwords-(dwords_left+count)), |
| 946 | level); |
| 947 | if (ADRENO_DEVICE(dev_priv->device)->ib_check_level |
| 948 | >= 2) |
| 949 | print_hex_dump(KERN_ERR, |
| 950 | level == 1 ? "IB1:" : "IB2:", |
| 951 | DUMP_PREFIX_OFFSET, 32, 4, hoststart, |
| 952 | sizedwords*4, 0); |
| 953 | goto done; |
| 954 | } |
| 955 | } |
| 956 | |
| 957 | ret = true; |
| 958 | done: |
| 959 | if (!ret) |
| 960 | KGSL_DRV_ERR(dev_priv->device, |
| 961 | "parsing failed: gpuaddr:0x%08x, " |
| 962 | "host:0x%p, wc:%d\n", gpuaddr, hoststart, sizedwords); |
| 963 | |
| 964 | level--; |
| 965 | |
| 966 | return ret; |
| 967 | } |
| 968 | |
| 969 | int |
| 970 | adreno_ringbuffer_issueibcmds(struct kgsl_device_private *dev_priv, |
| 971 | struct kgsl_context *context, |
| 972 | struct kgsl_ibdesc *ibdesc, |
| 973 | unsigned int numibs, |
| 974 | uint32_t *timestamp, |
| 975 | unsigned int flags) |
| 976 | { |
| 977 | struct kgsl_device *device = dev_priv->device; |
| 978 | struct adreno_device *adreno_dev = ADRENO_DEVICE(device); |
Nicholas Flintham | 8c6a490 | 2013-04-30 13:56:09 +0100 | [diff] [blame^] | 979 | unsigned int *link; |
Nicholas Flintham | 1e3d311 | 2013-04-10 10:48:38 +0100 | [diff] [blame] | 980 | unsigned int *cmds; |
| 981 | unsigned int i; |
Nicholas Flintham | 8c6a490 | 2013-04-30 13:56:09 +0100 | [diff] [blame^] | 982 | struct adreno_context *drawctxt; |
Nicholas Flintham | 1e3d311 | 2013-04-10 10:48:38 +0100 | [diff] [blame] | 983 | unsigned int start_index = 0; |
Nicholas Flintham | 1e3d311 | 2013-04-10 10:48:38 +0100 | [diff] [blame] | 984 | |
Nicholas Flintham | 8c6a490 | 2013-04-30 13:56:09 +0100 | [diff] [blame^] | 985 | if (device->state & KGSL_STATE_HUNG) |
| 986 | return -EBUSY; |
Nicholas Flintham | 1e3d311 | 2013-04-10 10:48:38 +0100 | [diff] [blame] | 987 | if (!(adreno_dev->ringbuffer.flags & KGSL_FLAGS_STARTED) || |
Nicholas Flintham | 8c6a490 | 2013-04-30 13:56:09 +0100 | [diff] [blame^] | 988 | context == NULL || ibdesc == 0 || numibs == 0) |
| 989 | return -EINVAL; |
| 990 | |
Nicholas Flintham | 1e3d311 | 2013-04-10 10:48:38 +0100 | [diff] [blame] | 991 | drawctxt = context->devctxt; |
| 992 | |
| 993 | if (drawctxt->flags & CTXT_FLAGS_GPU_HANG) { |
Flemmard | 9fc1014 | 2013-04-10 15:59:59 +0200 | [diff] [blame] | 994 | KGSL_CTXT_ERR(device, "proc %s failed fault tolerance" |
Nicholas Flintham | 1e3d311 | 2013-04-10 10:48:38 +0100 | [diff] [blame] | 995 | " will not accept commands for context %d\n", |
Flemmard | 9fc1014 | 2013-04-10 15:59:59 +0200 | [diff] [blame] | 996 | drawctxt->pid_name, drawctxt->id); |
Nicholas Flintham | 8c6a490 | 2013-04-30 13:56:09 +0100 | [diff] [blame^] | 997 | return -EDEADLK; |
| 998 | } |
| 999 | |
| 1000 | if (drawctxt->flags & CTXT_FLAGS_SKIP_EOF) { |
| 1001 | KGSL_CTXT_ERR(device, |
| 1002 | "proc %s triggered fault tolerance" |
| 1003 | " skipping commands for context till EOF %d\n", |
| 1004 | drawctxt->pid_name, drawctxt->id); |
| 1005 | if (flags & KGSL_CMD_FLAGS_EOF) |
| 1006 | drawctxt->flags &= ~CTXT_FLAGS_SKIP_EOF; |
| 1007 | numibs = 0; |
| 1008 | } |
| 1009 | |
| 1010 | cmds = link = kzalloc(sizeof(unsigned int) * (numibs * 3 + 4), |
| 1011 | GFP_KERNEL); |
| 1012 | if (!link) { |
| 1013 | KGSL_CORE_ERR("kzalloc(%d) failed\n", |
| 1014 | sizeof(unsigned int) * (numibs * 3 + 4)); |
| 1015 | return -ENOMEM; |
Nicholas Flintham | 1e3d311 | 2013-04-10 10:48:38 +0100 | [diff] [blame] | 1016 | } |
| 1017 | |
Flemmard | 9fc1014 | 2013-04-10 15:59:59 +0200 | [diff] [blame] | 1018 | /*When preamble is enabled, the preamble buffer with state restoration |
| 1019 | commands are stored in the first node of the IB chain. We can skip that |
| 1020 | if a context switch hasn't occured */ |
Nicholas Flintham | 1e3d311 | 2013-04-10 10:48:38 +0100 | [diff] [blame] | 1021 | |
| 1022 | if (drawctxt->flags & CTXT_FLAGS_PREAMBLE && |
| 1023 | adreno_dev->drawctxt_active == drawctxt) |
| 1024 | start_index = 1; |
| 1025 | |
| 1026 | if (!start_index) { |
| 1027 | *cmds++ = cp_nop_packet(1); |
| 1028 | *cmds++ = KGSL_START_OF_IB_IDENTIFIER; |
| 1029 | } else { |
| 1030 | *cmds++ = cp_nop_packet(4); |
| 1031 | *cmds++ = KGSL_START_OF_IB_IDENTIFIER; |
| 1032 | *cmds++ = CP_HDR_INDIRECT_BUFFER_PFD; |
| 1033 | *cmds++ = ibdesc[0].gpuaddr; |
| 1034 | *cmds++ = ibdesc[0].sizedwords; |
| 1035 | } |
| 1036 | for (i = start_index; i < numibs; i++) { |
| 1037 | if (unlikely(adreno_dev->ib_check_level >= 1 && |
| 1038 | !_parse_ibs(dev_priv, ibdesc[i].gpuaddr, |
| 1039 | ibdesc[i].sizedwords))) { |
Nicholas Flintham | 8c6a490 | 2013-04-30 13:56:09 +0100 | [diff] [blame^] | 1040 | kfree(link); |
| 1041 | return -EINVAL; |
Nicholas Flintham | 1e3d311 | 2013-04-10 10:48:38 +0100 | [diff] [blame] | 1042 | } |
| 1043 | *cmds++ = CP_HDR_INDIRECT_BUFFER_PFD; |
| 1044 | *cmds++ = ibdesc[i].gpuaddr; |
| 1045 | *cmds++ = ibdesc[i].sizedwords; |
| 1046 | } |
| 1047 | |
| 1048 | *cmds++ = cp_nop_packet(1); |
| 1049 | *cmds++ = KGSL_END_OF_IB_IDENTIFIER; |
| 1050 | |
| 1051 | kgsl_setstate(&device->mmu, context->id, |
| 1052 | kgsl_mmu_pt_get_flags(device->mmu.hwpagetable, |
| 1053 | device->id)); |
| 1054 | |
Nicholas Flintham | 1e3d311 | 2013-04-10 10:48:38 +0100 | [diff] [blame] | 1055 | adreno_drawctxt_switch(adreno_dev, drawctxt, flags); |
| 1056 | |
| 1057 | *timestamp = adreno_ringbuffer_addcmds(&adreno_dev->ringbuffer, |
Flemmard | 9fc1014 | 2013-04-10 15:59:59 +0200 | [diff] [blame] | 1058 | drawctxt, |
| 1059 | (flags & KGSL_CMD_FLAGS_EOF), |
| 1060 | &link[0], (cmds - link), *timestamp); |
Nicholas Flintham | 1e3d311 | 2013-04-10 10:48:38 +0100 | [diff] [blame] | 1061 | |
Nicholas Flintham | 8c6a490 | 2013-04-30 13:56:09 +0100 | [diff] [blame^] | 1062 | KGSL_CMD_INFO(device, "ctxt %d g %08x numibs %d ts %d\n", |
| 1063 | context->id, (unsigned int)ibdesc, numibs, *timestamp); |
| 1064 | |
| 1065 | kfree(link); |
| 1066 | |
Nicholas Flintham | 1e3d311 | 2013-04-10 10:48:38 +0100 | [diff] [blame] | 1067 | #ifdef CONFIG_MSM_KGSL_CFF_DUMP |
Flemmard | 9fc1014 | 2013-04-10 15:59:59 +0200 | [diff] [blame] | 1068 | /* |
| 1069 | * insert wait for idle after every IB1 |
| 1070 | * this is conservative but works reliably and is ok |
| 1071 | * even for performance simulations |
| 1072 | */ |
Nicholas Flintham | 1e3d311 | 2013-04-10 10:48:38 +0100 | [diff] [blame] | 1073 | adreno_idle(device); |
| 1074 | #endif |
Flemmard | 9fc1014 | 2013-04-10 15:59:59 +0200 | [diff] [blame] | 1075 | |
| 1076 | /* |
| 1077 | * If context hung and recovered then return error so that the |
| 1078 | * application may handle it |
| 1079 | */ |
| 1080 | if (drawctxt->flags & CTXT_FLAGS_GPU_HANG_FT) { |
| 1081 | drawctxt->flags &= ~CTXT_FLAGS_GPU_HANG_FT; |
Nicholas Flintham | 8c6a490 | 2013-04-30 13:56:09 +0100 | [diff] [blame^] | 1082 | return -EPROTO; |
Flemmard | 9fc1014 | 2013-04-10 15:59:59 +0200 | [diff] [blame] | 1083 | } else |
Nicholas Flintham | 8c6a490 | 2013-04-30 13:56:09 +0100 | [diff] [blame^] | 1084 | return 0; |
Nicholas Flintham | 1e3d311 | 2013-04-10 10:48:38 +0100 | [diff] [blame] | 1085 | } |
| 1086 | |
| 1087 | static void _turn_preamble_on_for_ib_seq(struct adreno_ringbuffer *rb, |
| 1088 | unsigned int rb_rptr) |
| 1089 | { |
| 1090 | unsigned int temp_rb_rptr = rb_rptr; |
| 1091 | unsigned int size = rb->buffer_desc.size; |
| 1092 | unsigned int val[2]; |
| 1093 | int i = 0; |
| 1094 | bool check = false; |
| 1095 | bool cmd_start = false; |
| 1096 | |
Flemmard | 9fc1014 | 2013-04-10 15:59:59 +0200 | [diff] [blame] | 1097 | /* Go till the start of the ib sequence and turn on preamble */ |
Nicholas Flintham | 1e3d311 | 2013-04-10 10:48:38 +0100 | [diff] [blame] | 1098 | while (temp_rb_rptr / sizeof(unsigned int) != rb->wptr) { |
| 1099 | kgsl_sharedmem_readl(&rb->buffer_desc, &val[i], temp_rb_rptr); |
| 1100 | if (check && KGSL_START_OF_IB_IDENTIFIER == val[i]) { |
Flemmard | 9fc1014 | 2013-04-10 15:59:59 +0200 | [diff] [blame] | 1101 | /* decrement i */ |
Nicholas Flintham | 1e3d311 | 2013-04-10 10:48:38 +0100 | [diff] [blame] | 1102 | i = (i + 1) % 2; |
| 1103 | if (val[i] == cp_nop_packet(4)) { |
| 1104 | temp_rb_rptr = adreno_ringbuffer_dec_wrapped( |
| 1105 | temp_rb_rptr, size); |
| 1106 | kgsl_sharedmem_writel(&rb->buffer_desc, |
| 1107 | temp_rb_rptr, cp_nop_packet(1)); |
| 1108 | } |
Flemmard | 9fc1014 | 2013-04-10 15:59:59 +0200 | [diff] [blame] | 1109 | KGSL_FT_INFO(rb->device, |
Nicholas Flintham | 1e3d311 | 2013-04-10 10:48:38 +0100 | [diff] [blame] | 1110 | "Turned preamble on at offset 0x%x\n", |
| 1111 | temp_rb_rptr / 4); |
| 1112 | break; |
| 1113 | } |
Flemmard | 9fc1014 | 2013-04-10 15:59:59 +0200 | [diff] [blame] | 1114 | /* If you reach beginning of next command sequence then exit |
| 1115 | * First command encountered is the current one so don't break |
| 1116 | * on that. */ |
Nicholas Flintham | 1e3d311 | 2013-04-10 10:48:38 +0100 | [diff] [blame] | 1117 | if (KGSL_CMD_IDENTIFIER == val[i]) { |
| 1118 | if (cmd_start) |
| 1119 | break; |
| 1120 | cmd_start = true; |
| 1121 | } |
| 1122 | |
| 1123 | i = (i + 1) % 2; |
| 1124 | if (1 == i) |
| 1125 | check = true; |
| 1126 | temp_rb_rptr = adreno_ringbuffer_inc_wrapped(temp_rb_rptr, |
| 1127 | size); |
| 1128 | } |
| 1129 | } |
| 1130 | |
Flemmard | 9fc1014 | 2013-04-10 15:59:59 +0200 | [diff] [blame] | 1131 | void adreno_ringbuffer_extract(struct adreno_ringbuffer *rb, |
| 1132 | struct adreno_ft_data *ft_data) |
Nicholas Flintham | 1e3d311 | 2013-04-10 10:48:38 +0100 | [diff] [blame] | 1133 | { |
Flemmard | 9fc1014 | 2013-04-10 15:59:59 +0200 | [diff] [blame] | 1134 | struct kgsl_device *device = rb->device; |
| 1135 | unsigned int rb_rptr = ft_data->start_of_replay_cmds; |
| 1136 | unsigned int good_rb_idx = 0, bad_rb_idx = 0, temp_rb_idx = 0; |
| 1137 | unsigned int last_good_cmd_end_idx = 0, last_bad_cmd_end_idx = 0; |
| 1138 | unsigned int cmd_start_idx = 0; |
Nicholas Flintham | 1e3d311 | 2013-04-10 10:48:38 +0100 | [diff] [blame] | 1139 | unsigned int val1 = 0; |
Nicholas Flintham | 1e3d311 | 2013-04-10 10:48:38 +0100 | [diff] [blame] | 1140 | int copy_rb_contents = 0; |
| 1141 | unsigned int temp_rb_rptr; |
Flemmard | 9fc1014 | 2013-04-10 15:59:59 +0200 | [diff] [blame] | 1142 | struct kgsl_context *k_ctxt; |
| 1143 | struct adreno_context *a_ctxt; |
Nicholas Flintham | 1e3d311 | 2013-04-10 10:48:38 +0100 | [diff] [blame] | 1144 | unsigned int size = rb->buffer_desc.size; |
Flemmard | 9fc1014 | 2013-04-10 15:59:59 +0200 | [diff] [blame] | 1145 | unsigned int *temp_rb_buffer = ft_data->rb_buffer; |
| 1146 | int *rb_size = &ft_data->rb_size; |
| 1147 | unsigned int *bad_rb_buffer = ft_data->bad_rb_buffer; |
| 1148 | int *bad_rb_size = &ft_data->bad_rb_size; |
| 1149 | unsigned int *good_rb_buffer = ft_data->good_rb_buffer; |
| 1150 | int *good_rb_size = &ft_data->good_rb_size; |
Nicholas Flintham | 1e3d311 | 2013-04-10 10:48:38 +0100 | [diff] [blame] | 1151 | |
Flemmard | 9fc1014 | 2013-04-10 15:59:59 +0200 | [diff] [blame] | 1152 | /* |
| 1153 | * If the start index from where commands need to be copied is invalid |
| 1154 | * then no need to save off any commands |
| 1155 | */ |
| 1156 | if (0xFFFFFFFF == ft_data->start_of_replay_cmds) |
| 1157 | return; |
| 1158 | |
| 1159 | k_ctxt = idr_find(&device->context_idr, ft_data->context_id); |
| 1160 | if (k_ctxt) { |
| 1161 | a_ctxt = k_ctxt->devctxt; |
| 1162 | if (a_ctxt->flags & CTXT_FLAGS_PREAMBLE) |
| 1163 | _turn_preamble_on_for_ib_seq(rb, rb_rptr); |
| 1164 | } |
| 1165 | k_ctxt = NULL; |
| 1166 | |
| 1167 | /* Walk the rb from the context switch. Omit any commands |
| 1168 | * for an invalid context. */ |
Nicholas Flintham | 1e3d311 | 2013-04-10 10:48:38 +0100 | [diff] [blame] | 1169 | while ((rb_rptr / sizeof(unsigned int)) != rb->wptr) { |
| 1170 | kgsl_sharedmem_readl(&rb->buffer_desc, &val1, rb_rptr); |
| 1171 | |
| 1172 | if (KGSL_CMD_IDENTIFIER == val1) { |
Flemmard | 9fc1014 | 2013-04-10 15:59:59 +0200 | [diff] [blame] | 1173 | /* Start is the NOP dword that comes before |
| 1174 | * KGSL_CMD_IDENTIFIER */ |
| 1175 | cmd_start_idx = temp_rb_idx - 1; |
| 1176 | if ((copy_rb_contents) && (good_rb_idx)) |
| 1177 | last_good_cmd_end_idx = good_rb_idx - 1; |
| 1178 | if ((!copy_rb_contents) && (bad_rb_idx)) |
| 1179 | last_bad_cmd_end_idx = bad_rb_idx - 1; |
Nicholas Flintham | 1e3d311 | 2013-04-10 10:48:38 +0100 | [diff] [blame] | 1180 | } |
| 1181 | |
Flemmard | 9fc1014 | 2013-04-10 15:59:59 +0200 | [diff] [blame] | 1182 | /* check for context switch indicator */ |
Nicholas Flintham | 1e3d311 | 2013-04-10 10:48:38 +0100 | [diff] [blame] | 1183 | if (val1 == KGSL_CONTEXT_TO_MEM_IDENTIFIER) { |
| 1184 | unsigned int temp_idx, val2; |
Flemmard | 9fc1014 | 2013-04-10 15:59:59 +0200 | [diff] [blame] | 1185 | /* increment by 3 to get to the context_id */ |
Nicholas Flintham | 1e3d311 | 2013-04-10 10:48:38 +0100 | [diff] [blame] | 1186 | temp_rb_rptr = rb_rptr + (3 * sizeof(unsigned int)) % |
| 1187 | size; |
| 1188 | kgsl_sharedmem_readl(&rb->buffer_desc, &val2, |
| 1189 | temp_rb_rptr); |
| 1190 | |
Flemmard | 9fc1014 | 2013-04-10 15:59:59 +0200 | [diff] [blame] | 1191 | /* if context switches to a context that did not cause |
| 1192 | * hang then start saving the rb contents as those |
| 1193 | * commands can be executed */ |
Nicholas Flintham | 1e3d311 | 2013-04-10 10:48:38 +0100 | [diff] [blame] | 1194 | k_ctxt = idr_find(&rb->device->context_idr, val2); |
| 1195 | if (k_ctxt) { |
| 1196 | a_ctxt = k_ctxt->devctxt; |
| 1197 | |
Flemmard | 9fc1014 | 2013-04-10 15:59:59 +0200 | [diff] [blame] | 1198 | /* If we are changing to a good context and were not |
| 1199 | * copying commands then copy over commands to the good |
| 1200 | * context */ |
Nicholas Flintham | 1e3d311 | 2013-04-10 10:48:38 +0100 | [diff] [blame] | 1201 | if (!copy_rb_contents && ((k_ctxt && |
| 1202 | !(a_ctxt->flags & CTXT_FLAGS_GPU_HANG)) || |
| 1203 | !k_ctxt)) { |
| 1204 | for (temp_idx = cmd_start_idx; |
Flemmard | 9fc1014 | 2013-04-10 15:59:59 +0200 | [diff] [blame] | 1205 | temp_idx < temp_rb_idx; |
Nicholas Flintham | 1e3d311 | 2013-04-10 10:48:38 +0100 | [diff] [blame] | 1206 | temp_idx++) |
Flemmard | 9fc1014 | 2013-04-10 15:59:59 +0200 | [diff] [blame] | 1207 | good_rb_buffer[good_rb_idx++] = |
| 1208 | temp_rb_buffer[temp_idx]; |
| 1209 | ft_data->last_valid_ctx_id = val2; |
Nicholas Flintham | 1e3d311 | 2013-04-10 10:48:38 +0100 | [diff] [blame] | 1210 | copy_rb_contents = 1; |
Flemmard | 9fc1014 | 2013-04-10 15:59:59 +0200 | [diff] [blame] | 1211 | /* remove the good commands from bad buffer */ |
| 1212 | bad_rb_idx = last_bad_cmd_end_idx; |
Nicholas Flintham | 1e3d311 | 2013-04-10 10:48:38 +0100 | [diff] [blame] | 1213 | } else if (copy_rb_contents && k_ctxt && |
| 1214 | (a_ctxt->flags & CTXT_FLAGS_GPU_HANG)) { |
Flemmard | 9fc1014 | 2013-04-10 15:59:59 +0200 | [diff] [blame] | 1215 | |
| 1216 | /* If we are changing back to a bad context |
| 1217 | * from good ctxt and were not copying commands |
| 1218 | * to bad ctxt then copy over commands to |
| 1219 | * the bad context */ |
| 1220 | for (temp_idx = cmd_start_idx; |
| 1221 | temp_idx < temp_rb_idx; |
| 1222 | temp_idx++) |
| 1223 | bad_rb_buffer[bad_rb_idx++] = |
| 1224 | temp_rb_buffer[temp_idx]; |
| 1225 | /* If we are changing to bad context then |
| 1226 | * remove the dwords we copied for this |
| 1227 | * sequence from the good buffer */ |
| 1228 | good_rb_idx = last_good_cmd_end_idx; |
Nicholas Flintham | 1e3d311 | 2013-04-10 10:48:38 +0100 | [diff] [blame] | 1229 | copy_rb_contents = 0; |
| 1230 | } |
| 1231 | } |
| 1232 | } |
| 1233 | |
| 1234 | if (copy_rb_contents) |
Flemmard | 9fc1014 | 2013-04-10 15:59:59 +0200 | [diff] [blame] | 1235 | good_rb_buffer[good_rb_idx++] = val1; |
| 1236 | else |
| 1237 | bad_rb_buffer[bad_rb_idx++] = val1; |
| 1238 | |
| 1239 | /* Copy both good and bad commands to temp buffer */ |
| 1240 | temp_rb_buffer[temp_rb_idx++] = val1; |
Nicholas Flintham | 1e3d311 | 2013-04-10 10:48:38 +0100 | [diff] [blame] | 1241 | |
| 1242 | rb_rptr = adreno_ringbuffer_inc_wrapped(rb_rptr, size); |
| 1243 | } |
Flemmard | 9fc1014 | 2013-04-10 15:59:59 +0200 | [diff] [blame] | 1244 | *good_rb_size = good_rb_idx; |
Nicholas Flintham | 1e3d311 | 2013-04-10 10:48:38 +0100 | [diff] [blame] | 1245 | *bad_rb_size = bad_rb_idx; |
Flemmard | 9fc1014 | 2013-04-10 15:59:59 +0200 | [diff] [blame] | 1246 | *rb_size = temp_rb_idx; |
Nicholas Flintham | 1e3d311 | 2013-04-10 10:48:38 +0100 | [diff] [blame] | 1247 | } |
| 1248 | |
| 1249 | void |
| 1250 | adreno_ringbuffer_restore(struct adreno_ringbuffer *rb, unsigned int *rb_buff, |
| 1251 | int num_rb_contents) |
| 1252 | { |
| 1253 | int i; |
| 1254 | unsigned int *ringcmds; |
| 1255 | unsigned int rcmd_gpu; |
| 1256 | |
| 1257 | if (!num_rb_contents) |
| 1258 | return; |
| 1259 | |
| 1260 | if (num_rb_contents > (rb->buffer_desc.size - rb->wptr)) { |
| 1261 | adreno_regwrite(rb->device, REG_CP_RB_RPTR, 0); |
| 1262 | rb->rptr = 0; |
| 1263 | BUG_ON(num_rb_contents > rb->buffer_desc.size); |
| 1264 | } |
| 1265 | ringcmds = (unsigned int *)rb->buffer_desc.hostptr + rb->wptr; |
| 1266 | rcmd_gpu = rb->buffer_desc.gpuaddr + sizeof(unsigned int) * rb->wptr; |
| 1267 | for (i = 0; i < num_rb_contents; i++) |
| 1268 | GSL_RB_WRITE(ringcmds, rcmd_gpu, rb_buff[i]); |
| 1269 | rb->wptr += num_rb_contents; |
| 1270 | adreno_ringbuffer_submit(rb); |
| 1271 | } |