Ethan Chen | 7b18590 | 2014-11-16 16:48:31 -0800 | [diff] [blame^] | 1 | /* Copyright (c) 2002,2007-2014, The Linux Foundation. All rights reserved. |
Steve Kondik | f7652b3 | 2013-11-26 15:20:51 -0800 | [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 | #include <linux/time.h> |
| 18 | #include <linux/delay.h> |
| 19 | |
| 20 | #include "kgsl.h" |
| 21 | #include "kgsl_sharedmem.h" |
| 22 | #include "kgsl_cffdump.h" |
Ethan Chen | 7b18590 | 2014-11-16 16:48:31 -0800 | [diff] [blame^] | 23 | #include "kgsl_trace.h" |
Steve Kondik | f7652b3 | 2013-11-26 15:20:51 -0800 | [diff] [blame] | 24 | |
| 25 | #include "adreno.h" |
| 26 | #include "adreno_pm4types.h" |
| 27 | #include "adreno_ringbuffer.h" |
| 28 | |
| 29 | #include "a2xx_reg.h" |
| 30 | #include "a3xx_reg.h" |
| 31 | |
| 32 | #define GSL_RB_NOP_SIZEDWORDS 2 |
| 33 | |
Steve Kondik | f7652b3 | 2013-11-26 15:20:51 -0800 | [diff] [blame] | 34 | void adreno_ringbuffer_submit(struct adreno_ringbuffer *rb) |
| 35 | { |
| 36 | struct adreno_device *adreno_dev = ADRENO_DEVICE(rb->device); |
| 37 | BUG_ON(rb->wptr == 0); |
| 38 | |
| 39 | /* Let the pwrscale policy know that new commands have |
| 40 | been submitted. */ |
| 41 | kgsl_pwrscale_busy(rb->device); |
| 42 | |
| 43 | /*synchronize memory before informing the hardware of the |
| 44 | *new commands. |
| 45 | */ |
| 46 | mb(); |
| 47 | |
| 48 | adreno_writereg(adreno_dev, ADRENO_REG_CP_RB_WPTR, rb->wptr); |
| 49 | } |
| 50 | |
| 51 | static int |
| 52 | adreno_ringbuffer_waitspace(struct adreno_ringbuffer *rb, |
| 53 | struct adreno_context *context, |
| 54 | unsigned int numcmds, int wptr_ahead) |
| 55 | { |
| 56 | int nopcount; |
| 57 | unsigned int freecmds; |
| 58 | unsigned int *cmds; |
| 59 | uint cmds_gpu; |
| 60 | unsigned long wait_time; |
| 61 | unsigned long wait_timeout = msecs_to_jiffies(ADRENO_IDLE_TIMEOUT); |
| 62 | unsigned long wait_time_part; |
| 63 | unsigned int rptr; |
| 64 | |
| 65 | /* if wptr ahead, fill the remaining with NOPs */ |
| 66 | if (wptr_ahead) { |
| 67 | /* -1 for header */ |
| 68 | nopcount = rb->sizedwords - rb->wptr - 1; |
| 69 | |
| 70 | cmds = (unsigned int *)rb->buffer_desc.hostptr + rb->wptr; |
| 71 | cmds_gpu = rb->buffer_desc.gpuaddr + sizeof(uint)*rb->wptr; |
| 72 | |
| 73 | GSL_RB_WRITE(rb->device, cmds, cmds_gpu, |
| 74 | cp_nop_packet(nopcount)); |
| 75 | |
| 76 | /* Make sure that rptr is not 0 before submitting |
| 77 | * commands at the end of ringbuffer. We do not |
| 78 | * want the rptr and wptr to become equal when |
| 79 | * the ringbuffer is not empty */ |
| 80 | do { |
| 81 | rptr = adreno_get_rptr(rb); |
| 82 | } while (!rptr); |
| 83 | |
| 84 | rb->wptr = 0; |
| 85 | } |
| 86 | |
| 87 | wait_time = jiffies + wait_timeout; |
| 88 | wait_time_part = jiffies + msecs_to_jiffies(KGSL_TIMEOUT_PART); |
| 89 | /* wait for space in ringbuffer */ |
| 90 | while (1) { |
| 91 | rptr = adreno_get_rptr(rb); |
| 92 | |
| 93 | freecmds = rptr - rb->wptr; |
| 94 | |
| 95 | if (freecmds == 0 || freecmds > numcmds) |
| 96 | break; |
| 97 | |
| 98 | if (time_after(jiffies, wait_time)) { |
| 99 | KGSL_DRV_ERR(rb->device, |
| 100 | "Timed out while waiting for freespace in ringbuffer " |
| 101 | "rptr: 0x%x, wptr: 0x%x\n", rptr, rb->wptr); |
| 102 | return -ETIMEDOUT; |
| 103 | } |
| 104 | |
| 105 | } |
| 106 | return 0; |
| 107 | } |
| 108 | |
| 109 | unsigned int *adreno_ringbuffer_allocspace(struct adreno_ringbuffer *rb, |
| 110 | struct adreno_context *context, |
| 111 | unsigned int numcmds) |
| 112 | { |
| 113 | unsigned int *ptr = NULL; |
| 114 | int ret = 0; |
| 115 | unsigned int rptr; |
| 116 | BUG_ON(numcmds >= rb->sizedwords); |
| 117 | |
| 118 | rptr = adreno_get_rptr(rb); |
| 119 | /* check for available space */ |
| 120 | if (rb->wptr >= rptr) { |
| 121 | /* wptr ahead or equal to rptr */ |
| 122 | /* reserve dwords for nop packet */ |
| 123 | if ((rb->wptr + numcmds) > (rb->sizedwords - |
| 124 | GSL_RB_NOP_SIZEDWORDS)) |
| 125 | ret = adreno_ringbuffer_waitspace(rb, context, |
| 126 | numcmds, 1); |
| 127 | } else { |
| 128 | /* wptr behind rptr */ |
| 129 | if ((rb->wptr + numcmds) >= rptr) |
| 130 | ret = adreno_ringbuffer_waitspace(rb, context, |
| 131 | numcmds, 0); |
| 132 | /* check for remaining space */ |
| 133 | /* reserve dwords for nop packet */ |
| 134 | if (!ret && (rb->wptr + numcmds) > (rb->sizedwords - |
| 135 | GSL_RB_NOP_SIZEDWORDS)) |
| 136 | ret = adreno_ringbuffer_waitspace(rb, context, |
| 137 | numcmds, 1); |
| 138 | } |
| 139 | |
| 140 | if (!ret) { |
| 141 | ptr = (unsigned int *)rb->buffer_desc.hostptr + rb->wptr; |
| 142 | rb->wptr += numcmds; |
| 143 | } else |
| 144 | ptr = ERR_PTR(ret); |
| 145 | |
| 146 | return ptr; |
| 147 | } |
| 148 | |
| 149 | static int _load_firmware(struct kgsl_device *device, const char *fwfile, |
| 150 | void **data, int *len) |
| 151 | { |
| 152 | const struct firmware *fw = NULL; |
| 153 | int ret; |
| 154 | |
| 155 | ret = request_firmware(&fw, fwfile, device->dev); |
| 156 | |
| 157 | if (ret) { |
| 158 | KGSL_DRV_ERR(device, "request_firmware(%s) failed: %d\n", |
| 159 | fwfile, ret); |
| 160 | return ret; |
| 161 | } |
| 162 | |
| 163 | *data = kmalloc(fw->size, GFP_KERNEL); |
| 164 | |
| 165 | if (*data) { |
| 166 | memcpy(*data, fw->data, fw->size); |
| 167 | *len = fw->size; |
| 168 | } else |
| 169 | KGSL_MEM_ERR(device, "kmalloc(%d) failed\n", fw->size); |
| 170 | |
| 171 | release_firmware(fw); |
| 172 | return (*data != NULL) ? 0 : -ENOMEM; |
| 173 | } |
| 174 | |
| 175 | int adreno_ringbuffer_read_pm4_ucode(struct kgsl_device *device) |
| 176 | { |
| 177 | struct adreno_device *adreno_dev = ADRENO_DEVICE(device); |
| 178 | int ret = 0; |
| 179 | |
| 180 | if (adreno_dev->pm4_fw == NULL) { |
| 181 | int len; |
| 182 | void *ptr; |
| 183 | |
| 184 | ret = _load_firmware(device, adreno_dev->pm4_fwfile, |
| 185 | &ptr, &len); |
| 186 | |
| 187 | if (ret) |
| 188 | goto err; |
| 189 | |
| 190 | /* PM4 size is 3 dword aligned plus 1 dword of version */ |
| 191 | if (len % ((sizeof(uint32_t) * 3)) != sizeof(uint32_t)) { |
| 192 | KGSL_DRV_ERR(device, "Bad firmware size: %d\n", len); |
| 193 | ret = -EINVAL; |
| 194 | kfree(ptr); |
| 195 | goto err; |
| 196 | } |
| 197 | |
| 198 | adreno_dev->pm4_fw_size = len / sizeof(uint32_t); |
| 199 | adreno_dev->pm4_fw = ptr; |
| 200 | adreno_dev->pm4_fw_version = adreno_dev->pm4_fw[1]; |
| 201 | } |
| 202 | |
| 203 | err: |
| 204 | return ret; |
| 205 | } |
| 206 | |
| 207 | /** |
| 208 | * adreno_ringbuffer_load_pm4_ucode() - Load pm4 ucode |
| 209 | * @device: Pointer to a KGSL device |
| 210 | * @start: Starting index in pm4 ucode to load |
Ethan Chen | 7b18590 | 2014-11-16 16:48:31 -0800 | [diff] [blame^] | 211 | * @end: Ending index of pm4 ucode to load |
Steve Kondik | f7652b3 | 2013-11-26 15:20:51 -0800 | [diff] [blame] | 212 | * @addr: Address to load the pm4 ucode |
| 213 | * |
| 214 | * Load the pm4 ucode from @start at @addr. |
| 215 | */ |
Ethan Chen | 7b18590 | 2014-11-16 16:48:31 -0800 | [diff] [blame^] | 216 | inline int adreno_ringbuffer_load_pm4_ucode(struct kgsl_device *device, |
| 217 | unsigned int start, unsigned int end, unsigned int addr) |
Steve Kondik | f7652b3 | 2013-11-26 15:20:51 -0800 | [diff] [blame] | 218 | { |
| 219 | struct adreno_device *adreno_dev = ADRENO_DEVICE(device); |
| 220 | int i; |
| 221 | |
Steve Kondik | f7652b3 | 2013-11-26 15:20:51 -0800 | [diff] [blame] | 222 | adreno_writereg(adreno_dev, ADRENO_REG_CP_ME_RAM_WADDR, addr); |
Ethan Chen | 7b18590 | 2014-11-16 16:48:31 -0800 | [diff] [blame^] | 223 | for (i = start; i < end; i++) |
Steve Kondik | f7652b3 | 2013-11-26 15:20:51 -0800 | [diff] [blame] | 224 | adreno_writereg(adreno_dev, ADRENO_REG_CP_ME_RAM_DATA, |
| 225 | adreno_dev->pm4_fw[i]); |
| 226 | |
| 227 | return 0; |
| 228 | } |
| 229 | |
| 230 | int adreno_ringbuffer_read_pfp_ucode(struct kgsl_device *device) |
| 231 | { |
| 232 | struct adreno_device *adreno_dev = ADRENO_DEVICE(device); |
| 233 | int ret = 0; |
| 234 | |
| 235 | if (adreno_dev->pfp_fw == NULL) { |
| 236 | int len; |
| 237 | void *ptr; |
| 238 | |
| 239 | ret = _load_firmware(device, adreno_dev->pfp_fwfile, |
| 240 | &ptr, &len); |
| 241 | if (ret) |
| 242 | goto err; |
| 243 | |
| 244 | /* PFP size shold be dword aligned */ |
| 245 | if (len % sizeof(uint32_t) != 0) { |
| 246 | KGSL_DRV_ERR(device, "Bad firmware size: %d\n", len); |
| 247 | ret = -EINVAL; |
| 248 | kfree(ptr); |
| 249 | goto err; |
| 250 | } |
| 251 | |
| 252 | adreno_dev->pfp_fw_size = len / sizeof(uint32_t); |
| 253 | adreno_dev->pfp_fw = ptr; |
| 254 | adreno_dev->pfp_fw_version = adreno_dev->pfp_fw[5]; |
| 255 | } |
| 256 | |
| 257 | err: |
| 258 | return ret; |
| 259 | } |
| 260 | |
| 261 | /** |
| 262 | * adreno_ringbuffer_load_pfp_ucode() - Load pfp ucode |
| 263 | * @device: Pointer to a KGSL device |
| 264 | * @start: Starting index in pfp ucode to load |
Ethan Chen | 7b18590 | 2014-11-16 16:48:31 -0800 | [diff] [blame^] | 265 | * @end: Ending index of pfp ucode to load |
Steve Kondik | f7652b3 | 2013-11-26 15:20:51 -0800 | [diff] [blame] | 266 | * @addr: Address to load the pfp ucode |
| 267 | * |
| 268 | * Load the pfp ucode from @start at @addr. |
| 269 | */ |
Ethan Chen | 7b18590 | 2014-11-16 16:48:31 -0800 | [diff] [blame^] | 270 | inline int adreno_ringbuffer_load_pfp_ucode(struct kgsl_device *device, |
| 271 | unsigned int start, unsigned int end, unsigned int addr) |
Steve Kondik | f7652b3 | 2013-11-26 15:20:51 -0800 | [diff] [blame] | 272 | { |
| 273 | struct adreno_device *adreno_dev = ADRENO_DEVICE(device); |
| 274 | int i; |
| 275 | |
Steve Kondik | f7652b3 | 2013-11-26 15:20:51 -0800 | [diff] [blame] | 276 | adreno_writereg(adreno_dev, ADRENO_REG_CP_PFP_UCODE_ADDR, addr); |
Ethan Chen | 7b18590 | 2014-11-16 16:48:31 -0800 | [diff] [blame^] | 277 | for (i = start; i < end; i++) |
Steve Kondik | f7652b3 | 2013-11-26 15:20:51 -0800 | [diff] [blame] | 278 | adreno_writereg(adreno_dev, ADRENO_REG_CP_PFP_UCODE_DATA, |
| 279 | adreno_dev->pfp_fw[i]); |
| 280 | |
| 281 | return 0; |
| 282 | } |
| 283 | |
| 284 | /** |
Ethan Chen | 7b18590 | 2014-11-16 16:48:31 -0800 | [diff] [blame^] | 285 | * _ringbuffer_bootstrap_ucode() - Bootstrap GPU Ucode |
| 286 | * @rb: Pointer to adreno ringbuffer |
| 287 | * @load_jt: If non zero only load Jump tables |
| 288 | * |
| 289 | * Bootstrap ucode for GPU |
| 290 | * load_jt == 0, bootstrap full microcode |
| 291 | * load_jt == 1, bootstrap jump tables of microcode |
| 292 | * |
| 293 | * For example a bootstrap packet would like below |
| 294 | * Setup a type3 bootstrap packet |
| 295 | * PFP size to bootstrap |
| 296 | * PFP addr to write the PFP data |
| 297 | * PM4 size to bootstrap |
| 298 | * PM4 addr to write the PM4 data |
| 299 | * PFP dwords from microcode to bootstrap |
| 300 | * PM4 size dwords from microcode to bootstrap |
| 301 | */ |
| 302 | static int _ringbuffer_bootstrap_ucode(struct adreno_ringbuffer *rb, |
| 303 | unsigned int load_jt) |
| 304 | { |
| 305 | unsigned int *cmds, cmds_gpu, bootstrap_size; |
| 306 | int i = 0; |
| 307 | struct kgsl_device *device = rb->device; |
| 308 | struct adreno_device *adreno_dev = ADRENO_DEVICE(device); |
| 309 | unsigned int pm4_size, pm4_idx, pm4_addr, pfp_size, pfp_idx, pfp_addr; |
| 310 | |
| 311 | /* Only bootstrap jump tables of ucode */ |
| 312 | if (load_jt) { |
| 313 | pm4_idx = adreno_dev->pm4_jt_idx; |
| 314 | pm4_addr = adreno_dev->pm4_jt_addr; |
| 315 | pfp_idx = adreno_dev->pfp_jt_idx; |
| 316 | pfp_addr = adreno_dev->pfp_jt_addr; |
| 317 | } else { |
| 318 | /* Bootstrap full ucode */ |
| 319 | pm4_idx = 1; |
| 320 | pm4_addr = 0; |
| 321 | pfp_idx = 1; |
| 322 | pfp_addr = 0; |
| 323 | } |
| 324 | |
| 325 | pm4_size = (adreno_dev->pm4_fw_size - pm4_idx); |
| 326 | pfp_size = (adreno_dev->pfp_fw_size - pfp_idx); |
| 327 | |
| 328 | /* |
| 329 | * Below set of commands register with PFP that 6f is the |
| 330 | * opcode for bootstrapping |
| 331 | */ |
| 332 | adreno_writereg(adreno_dev, ADRENO_REG_CP_PFP_UCODE_ADDR, 0x200); |
| 333 | adreno_writereg(adreno_dev, ADRENO_REG_CP_PFP_UCODE_DATA, 0x6f0005); |
| 334 | |
| 335 | /* clear ME_HALT to start micro engine */ |
| 336 | adreno_writereg(adreno_dev, ADRENO_REG_CP_ME_CNTL, 0); |
| 337 | |
| 338 | bootstrap_size = (pm4_size + pfp_size + 5); |
| 339 | |
| 340 | cmds = adreno_ringbuffer_allocspace(rb, NULL, bootstrap_size); |
| 341 | if (cmds == NULL) |
| 342 | return -ENOMEM; |
| 343 | |
| 344 | cmds_gpu = rb->buffer_desc.gpuaddr + |
| 345 | sizeof(uint) * (rb->wptr - bootstrap_size); |
| 346 | /* Construct the packet that bootsraps the ucode */ |
| 347 | GSL_RB_WRITE(rb->device, cmds, cmds_gpu, |
| 348 | cp_type3_packet(CP_BOOTSTRAP_UCODE, |
| 349 | (bootstrap_size - 1))); |
| 350 | GSL_RB_WRITE(rb->device, cmds, cmds_gpu, pfp_size); |
| 351 | GSL_RB_WRITE(rb->device, cmds, cmds_gpu, pfp_addr); |
| 352 | GSL_RB_WRITE(rb->device, cmds, cmds_gpu, pm4_size); |
| 353 | GSL_RB_WRITE(rb->device, cmds, cmds_gpu, pm4_addr); |
| 354 | for (i = pfp_idx; i < adreno_dev->pfp_fw_size; i++) |
| 355 | GSL_RB_WRITE(rb->device, cmds, cmds_gpu, adreno_dev->pfp_fw[i]); |
| 356 | for (i = pm4_idx; i < adreno_dev->pm4_fw_size; i++) |
| 357 | GSL_RB_WRITE(rb->device, cmds, cmds_gpu, adreno_dev->pm4_fw[i]); |
| 358 | |
| 359 | adreno_ringbuffer_submit(rb); |
| 360 | /* idle device to validate bootstrap */ |
| 361 | return adreno_idle(device); |
| 362 | } |
| 363 | |
| 364 | /** |
| 365 | * _ringbuffer_setup_common() - Ringbuffer start |
Steve Kondik | f7652b3 | 2013-11-26 15:20:51 -0800 | [diff] [blame] | 366 | * @rb: Pointer to adreno ringbuffer |
| 367 | * |
| 368 | * Setup ringbuffer for GPU. |
| 369 | */ |
Ethan Chen | 7b18590 | 2014-11-16 16:48:31 -0800 | [diff] [blame^] | 370 | void _ringbuffer_setup_common(struct adreno_ringbuffer *rb) |
Steve Kondik | f7652b3 | 2013-11-26 15:20:51 -0800 | [diff] [blame] | 371 | { |
Steve Kondik | f7652b3 | 2013-11-26 15:20:51 -0800 | [diff] [blame] | 372 | struct kgsl_device *device = rb->device; |
| 373 | struct adreno_device *adreno_dev = ADRENO_DEVICE(device); |
| 374 | |
Steve Kondik | f7652b3 | 2013-11-26 15:20:51 -0800 | [diff] [blame] | 375 | kgsl_sharedmem_set(rb->device, &rb->buffer_desc, 0, 0xAA, |
| 376 | (rb->sizedwords << 2)); |
| 377 | |
Steve Kondik | f7652b3 | 2013-11-26 15:20:51 -0800 | [diff] [blame] | 378 | /* |
| 379 | * The size of the ringbuffer in the hardware is the log2 |
Ethan Chen | 7b18590 | 2014-11-16 16:48:31 -0800 | [diff] [blame^] | 380 | * representation of the size in quadwords (sizedwords / 2). |
| 381 | * Also disable the host RPTR shadow register as it might be unreliable |
| 382 | * in certain circumstances. |
Steve Kondik | f7652b3 | 2013-11-26 15:20:51 -0800 | [diff] [blame] | 383 | */ |
Steve Kondik | f7652b3 | 2013-11-26 15:20:51 -0800 | [diff] [blame] | 384 | |
Ethan Chen | 7b18590 | 2014-11-16 16:48:31 -0800 | [diff] [blame^] | 385 | adreno_writereg(adreno_dev, ADRENO_REG_CP_RB_CNTL, |
| 386 | (ilog2(rb->sizedwords >> 1) & 0x3F) | |
| 387 | (1 << 27)); |
Steve Kondik | f7652b3 | 2013-11-26 15:20:51 -0800 | [diff] [blame] | 388 | |
| 389 | adreno_writereg(adreno_dev, ADRENO_REG_CP_RB_BASE, |
| 390 | rb->buffer_desc.gpuaddr); |
| 391 | |
Steve Kondik | f7652b3 | 2013-11-26 15:20:51 -0800 | [diff] [blame] | 392 | if (adreno_is_a2xx(adreno_dev)) { |
| 393 | /* explicitly clear all cp interrupts */ |
| 394 | kgsl_regwrite(device, REG_CP_INT_ACK, 0xFFFFFFFF); |
| 395 | } |
| 396 | |
| 397 | /* setup scratch/timestamp */ |
| 398 | adreno_writereg(adreno_dev, ADRENO_REG_SCRATCH_ADDR, |
| 399 | device->memstore.gpuaddr + |
| 400 | KGSL_MEMSTORE_OFFSET(KGSL_MEMSTORE_GLOBAL, |
| 401 | soptimestamp)); |
| 402 | |
| 403 | adreno_writereg(adreno_dev, ADRENO_REG_SCRATCH_UMSK, |
| 404 | GSL_RB_MEMPTRS_SCRATCH_MASK); |
| 405 | |
| 406 | /* CP ROQ queue sizes (bytes) - RB:16, ST:16, IB1:32, IB2:64 */ |
| 407 | if (adreno_is_a305(adreno_dev) || adreno_is_a305c(adreno_dev) || |
| 408 | adreno_is_a320(adreno_dev)) |
| 409 | kgsl_regwrite(device, REG_CP_QUEUE_THRESHOLDS, 0x000E0602); |
| 410 | else if (adreno_is_a330(adreno_dev) || adreno_is_a305b(adreno_dev)) |
| 411 | kgsl_regwrite(device, REG_CP_QUEUE_THRESHOLDS, 0x003E2008); |
| 412 | |
| 413 | rb->wptr = 0; |
Ethan Chen | 7b18590 | 2014-11-16 16:48:31 -0800 | [diff] [blame^] | 414 | } |
| 415 | |
| 416 | /** |
| 417 | * _ringbuffer_start_common() - Ringbuffer start |
| 418 | * @rb: Pointer to adreno ringbuffer |
| 419 | * |
| 420 | * Start ringbuffer for GPU. |
| 421 | */ |
| 422 | int _ringbuffer_start_common(struct adreno_ringbuffer *rb) |
| 423 | { |
| 424 | int status; |
| 425 | struct kgsl_device *device = rb->device; |
| 426 | struct adreno_device *adreno_dev = ADRENO_DEVICE(device); |
Steve Kondik | f7652b3 | 2013-11-26 15:20:51 -0800 | [diff] [blame] | 427 | |
| 428 | /* clear ME_HALT to start micro engine */ |
| 429 | adreno_writereg(adreno_dev, ADRENO_REG_CP_ME_CNTL, 0); |
| 430 | |
| 431 | /* ME init is GPU specific, so jump into the sub-function */ |
| 432 | status = adreno_dev->gpudev->rb_init(adreno_dev, rb); |
| 433 | if (status) |
| 434 | return status; |
| 435 | |
| 436 | /* idle device to validate ME INIT */ |
| 437 | status = adreno_idle(device); |
| 438 | |
| 439 | if (status == 0) |
| 440 | rb->flags |= KGSL_FLAGS_STARTED; |
| 441 | |
| 442 | return status; |
| 443 | } |
| 444 | |
| 445 | /** |
| 446 | * adreno_ringbuffer_warm_start() - Ringbuffer warm start |
| 447 | * @rb: Pointer to adreno ringbuffer |
| 448 | * |
| 449 | * Start the ringbuffer but load only jump tables part of the |
| 450 | * microcode. |
| 451 | */ |
| 452 | int adreno_ringbuffer_warm_start(struct adreno_ringbuffer *rb) |
| 453 | { |
| 454 | int status; |
| 455 | struct kgsl_device *device = rb->device; |
| 456 | struct adreno_device *adreno_dev = ADRENO_DEVICE(device); |
| 457 | |
Ethan Chen | 7b18590 | 2014-11-16 16:48:31 -0800 | [diff] [blame^] | 458 | if (rb->flags & KGSL_FLAGS_STARTED) |
| 459 | return 0; |
Steve Kondik | f7652b3 | 2013-11-26 15:20:51 -0800 | [diff] [blame] | 460 | |
Ethan Chen | 7b18590 | 2014-11-16 16:48:31 -0800 | [diff] [blame^] | 461 | _ringbuffer_setup_common(rb); |
Steve Kondik | f7652b3 | 2013-11-26 15:20:51 -0800 | [diff] [blame] | 462 | |
Ethan Chen | 7b18590 | 2014-11-16 16:48:31 -0800 | [diff] [blame^] | 463 | /* If bootstrapping if supported to load jump tables */ |
| 464 | if (adreno_bootstrap_ucode(adreno_dev)) { |
| 465 | status = _ringbuffer_bootstrap_ucode(rb, 1); |
| 466 | if (status != 0) |
| 467 | return status; |
| 468 | |
| 469 | } else { |
| 470 | /* load the CP jump tables using AHB writes */ |
| 471 | status = adreno_ringbuffer_load_pm4_ucode(device, |
| 472 | adreno_dev->pm4_jt_idx, adreno_dev->pm4_fw_size, |
| 473 | adreno_dev->pm4_jt_addr); |
| 474 | if (status != 0) |
| 475 | return status; |
| 476 | |
| 477 | /* load the prefetch parser jump tables using AHB writes */ |
| 478 | status = adreno_ringbuffer_load_pfp_ucode(device, |
| 479 | adreno_dev->pfp_jt_idx, adreno_dev->pfp_fw_size, |
| 480 | adreno_dev->pfp_jt_addr); |
| 481 | if (status != 0) |
| 482 | return status; |
| 483 | } |
| 484 | |
| 485 | status = _ringbuffer_start_common(rb); |
| 486 | |
| 487 | return status; |
Steve Kondik | f7652b3 | 2013-11-26 15:20:51 -0800 | [diff] [blame] | 488 | } |
| 489 | |
Ethan Chen | 7b18590 | 2014-11-16 16:48:31 -0800 | [diff] [blame^] | 490 | /** |
| 491 | * adreno_ringbuffer_cold_start() - Ringbuffer cold start |
| 492 | * @rb: Pointer to adreno ringbuffer |
| 493 | * |
| 494 | * Start the ringbuffer from power collapse. |
| 495 | */ |
| 496 | int adreno_ringbuffer_cold_start(struct adreno_ringbuffer *rb) |
Steve Kondik | f7652b3 | 2013-11-26 15:20:51 -0800 | [diff] [blame] | 497 | { |
| 498 | int status; |
Ethan Chen | 7b18590 | 2014-11-16 16:48:31 -0800 | [diff] [blame^] | 499 | struct kgsl_device *device = rb->device; |
| 500 | struct adreno_device *adreno_dev = ADRENO_DEVICE(device); |
Steve Kondik | f7652b3 | 2013-11-26 15:20:51 -0800 | [diff] [blame] | 501 | |
| 502 | if (rb->flags & KGSL_FLAGS_STARTED) |
| 503 | return 0; |
| 504 | |
Ethan Chen | 7b18590 | 2014-11-16 16:48:31 -0800 | [diff] [blame^] | 505 | _ringbuffer_setup_common(rb); |
Steve Kondik | f7652b3 | 2013-11-26 15:20:51 -0800 | [diff] [blame] | 506 | |
Ethan Chen | 7b18590 | 2014-11-16 16:48:31 -0800 | [diff] [blame^] | 507 | /* If bootstrapping if supported to load ucode */ |
| 508 | if (adreno_bootstrap_ucode(adreno_dev)) { |
Steve Kondik | f7652b3 | 2013-11-26 15:20:51 -0800 | [diff] [blame] | 509 | |
Ethan Chen | 7b18590 | 2014-11-16 16:48:31 -0800 | [diff] [blame^] | 510 | /* |
| 511 | * load first adreno_dev->pm4_bstrp_size + |
| 512 | * adreno_dev->pfp_bstrp_size microcode dwords using AHB write, |
| 513 | * this small microcode has dispatcher + booter, this initial |
| 514 | * microcode enables CP to understand CP_BOOTSTRAP_UCODE packet |
| 515 | * in function _ringbuffer_bootstrap_ucode. CP_BOOTSTRAP_UCODE |
| 516 | * packet loads rest of the microcode. |
| 517 | */ |
| 518 | |
| 519 | status = adreno_ringbuffer_load_pm4_ucode(rb->device, 1, |
| 520 | adreno_dev->pm4_bstrp_size+1, 0); |
| 521 | if (status != 0) |
| 522 | return status; |
| 523 | |
| 524 | status = adreno_ringbuffer_load_pfp_ucode(rb->device, 1, |
| 525 | adreno_dev->pfp_bstrp_size+1, 0); |
| 526 | if (status != 0) |
| 527 | return status; |
| 528 | |
| 529 | /* Bootstrap rest of the ucode here */ |
| 530 | status = _ringbuffer_bootstrap_ucode(rb, 0); |
| 531 | if (status != 0) |
| 532 | return status; |
| 533 | |
| 534 | } else { |
| 535 | /* load the CP ucode using AHB writes */ |
| 536 | status = adreno_ringbuffer_load_pm4_ucode(rb->device, 1, |
| 537 | adreno_dev->pm4_fw_size, 0); |
| 538 | if (status != 0) |
| 539 | return status; |
| 540 | |
| 541 | /* load the prefetch parser ucode using AHB writes */ |
| 542 | status = adreno_ringbuffer_load_pfp_ucode(rb->device, 1, |
| 543 | adreno_dev->pfp_fw_size, 0); |
| 544 | if (status != 0) |
| 545 | return status; |
| 546 | } |
| 547 | |
| 548 | status = _ringbuffer_start_common(rb); |
| 549 | |
| 550 | return status; |
Steve Kondik | f7652b3 | 2013-11-26 15:20:51 -0800 | [diff] [blame] | 551 | } |
| 552 | |
| 553 | void adreno_ringbuffer_stop(struct adreno_ringbuffer *rb) |
| 554 | { |
| 555 | struct kgsl_device *device = rb->device; |
| 556 | struct adreno_device *adreno_dev = ADRENO_DEVICE(device); |
| 557 | |
| 558 | if (rb->flags & KGSL_FLAGS_STARTED) { |
| 559 | if (adreno_is_a200(adreno_dev)) |
| 560 | kgsl_regwrite(rb->device, REG_CP_ME_CNTL, 0x10000000); |
| 561 | |
| 562 | rb->flags &= ~KGSL_FLAGS_STARTED; |
| 563 | } |
| 564 | } |
| 565 | |
| 566 | int adreno_ringbuffer_init(struct kgsl_device *device) |
| 567 | { |
| 568 | int status; |
| 569 | struct adreno_device *adreno_dev = ADRENO_DEVICE(device); |
| 570 | struct adreno_ringbuffer *rb = &adreno_dev->ringbuffer; |
| 571 | |
| 572 | rb->device = device; |
| 573 | /* |
| 574 | * It is silly to convert this to words and then back to bytes |
| 575 | * immediately below, but most of the rest of the code deals |
| 576 | * in words, so we might as well only do the math once |
| 577 | */ |
| 578 | rb->sizedwords = KGSL_RB_SIZE >> 2; |
| 579 | |
| 580 | rb->buffer_desc.flags = KGSL_MEMFLAGS_GPUREADONLY; |
| 581 | /* allocate memory for ringbuffer */ |
| 582 | status = kgsl_allocate_contiguous(&rb->buffer_desc, |
| 583 | (rb->sizedwords << 2)); |
| 584 | |
| 585 | if (status != 0) { |
| 586 | adreno_ringbuffer_close(rb); |
| 587 | return status; |
| 588 | } |
| 589 | |
Steve Kondik | f7652b3 | 2013-11-26 15:20:51 -0800 | [diff] [blame] | 590 | rb->global_ts = 0; |
| 591 | |
| 592 | return 0; |
| 593 | } |
| 594 | |
| 595 | void adreno_ringbuffer_close(struct adreno_ringbuffer *rb) |
| 596 | { |
| 597 | struct adreno_device *adreno_dev = ADRENO_DEVICE(rb->device); |
| 598 | |
| 599 | kgsl_sharedmem_free(&rb->buffer_desc); |
Steve Kondik | f7652b3 | 2013-11-26 15:20:51 -0800 | [diff] [blame] | 600 | |
| 601 | kfree(adreno_dev->pfp_fw); |
| 602 | kfree(adreno_dev->pm4_fw); |
| 603 | |
| 604 | adreno_dev->pfp_fw = NULL; |
| 605 | adreno_dev->pm4_fw = NULL; |
| 606 | |
| 607 | memset(rb, 0, sizeof(struct adreno_ringbuffer)); |
| 608 | } |
| 609 | |
| 610 | static int |
| 611 | adreno_ringbuffer_addcmds(struct adreno_ringbuffer *rb, |
| 612 | struct adreno_context *drawctxt, |
| 613 | unsigned int flags, unsigned int *cmds, |
| 614 | int sizedwords, uint32_t timestamp) |
| 615 | { |
| 616 | struct adreno_device *adreno_dev = ADRENO_DEVICE(rb->device); |
| 617 | unsigned int *ringcmds; |
| 618 | unsigned int total_sizedwords = sizedwords; |
| 619 | unsigned int i; |
| 620 | unsigned int rcmd_gpu; |
| 621 | unsigned int context_id; |
| 622 | unsigned int gpuaddr = rb->device->memstore.gpuaddr; |
| 623 | |
| 624 | if (drawctxt != NULL && kgsl_context_detached(&drawctxt->base)) |
| 625 | return -EINVAL; |
| 626 | |
| 627 | rb->global_ts++; |
| 628 | |
| 629 | /* If this is a internal IB, use the global timestamp for it */ |
| 630 | if (!drawctxt || (flags & KGSL_CMD_FLAGS_INTERNAL_ISSUE)) { |
| 631 | timestamp = rb->global_ts; |
| 632 | context_id = KGSL_MEMSTORE_GLOBAL; |
| 633 | } else { |
| 634 | context_id = drawctxt->base.id; |
| 635 | } |
| 636 | |
| 637 | /* |
| 638 | * Note that we cannot safely take drawctxt->mutex here without |
| 639 | * potential mutex inversion with device->mutex which is held |
| 640 | * here. As a result, any other code that accesses this variable |
| 641 | * must also use device->mutex. |
| 642 | */ |
| 643 | if (drawctxt) |
| 644 | drawctxt->internal_timestamp = rb->global_ts; |
| 645 | |
| 646 | /* reserve space to temporarily turn off protected mode |
| 647 | * error checking if needed |
| 648 | */ |
| 649 | total_sizedwords += flags & KGSL_CMD_FLAGS_PMODE ? 4 : 0; |
| 650 | /* 2 dwords to store the start of command sequence */ |
| 651 | total_sizedwords += 2; |
| 652 | /* internal ib command identifier for the ringbuffer */ |
| 653 | total_sizedwords += (flags & KGSL_CMD_FLAGS_INTERNAL_ISSUE) ? 2 : 0; |
| 654 | |
| 655 | /* Add two dwords for the CP_INTERRUPT */ |
Ethan Chen | 7b18590 | 2014-11-16 16:48:31 -0800 | [diff] [blame^] | 656 | total_sizedwords += |
| 657 | (drawctxt || (flags & KGSL_CMD_FLAGS_INTERNAL_ISSUE)) ? 2 : 0; |
Steve Kondik | f7652b3 | 2013-11-26 15:20:51 -0800 | [diff] [blame] | 658 | |
| 659 | /* context rollover */ |
| 660 | if (adreno_is_a3xx(adreno_dev)) |
| 661 | total_sizedwords += 3; |
| 662 | |
| 663 | /* For HLSQ updates below */ |
| 664 | if (adreno_is_a4xx(adreno_dev) || adreno_is_a3xx(adreno_dev)) |
| 665 | total_sizedwords += 4; |
| 666 | |
| 667 | if (adreno_is_a2xx(adreno_dev)) |
| 668 | total_sizedwords += 2; /* CP_WAIT_FOR_IDLE */ |
| 669 | |
| 670 | total_sizedwords += 3; /* sop timestamp */ |
| 671 | total_sizedwords += 4; /* eop timestamp */ |
| 672 | |
Ethan Chen | 7b18590 | 2014-11-16 16:48:31 -0800 | [diff] [blame^] | 673 | if (adreno_is_a20x(adreno_dev)) |
| 674 | total_sizedwords += 2; /* CACHE_FLUSH */ |
| 675 | |
Steve Kondik | f7652b3 | 2013-11-26 15:20:51 -0800 | [diff] [blame] | 676 | if (drawctxt) { |
| 677 | total_sizedwords += 3; /* global timestamp without cache |
| 678 | * flush for non-zero context */ |
| 679 | } |
| 680 | |
| 681 | if (adreno_is_a20x(adreno_dev)) |
| 682 | total_sizedwords += 2; /* CACHE_FLUSH */ |
| 683 | |
| 684 | if (flags & KGSL_CMD_FLAGS_WFI) |
| 685 | total_sizedwords += 2; /* WFI */ |
| 686 | |
| 687 | /* Add space for the power on shader fixup if we need it */ |
| 688 | if (flags & KGSL_CMD_FLAGS_PWRON_FIXUP) |
Ethan Chen | 7b18590 | 2014-11-16 16:48:31 -0800 | [diff] [blame^] | 689 | total_sizedwords += 9; |
Steve Kondik | f7652b3 | 2013-11-26 15:20:51 -0800 | [diff] [blame] | 690 | |
| 691 | ringcmds = adreno_ringbuffer_allocspace(rb, drawctxt, total_sizedwords); |
| 692 | |
| 693 | if (IS_ERR(ringcmds)) |
| 694 | return PTR_ERR(ringcmds); |
| 695 | if (ringcmds == NULL) |
| 696 | return -ENOSPC; |
| 697 | |
| 698 | rcmd_gpu = rb->buffer_desc.gpuaddr |
| 699 | + sizeof(uint)*(rb->wptr-total_sizedwords); |
| 700 | |
| 701 | GSL_RB_WRITE(rb->device, ringcmds, rcmd_gpu, cp_nop_packet(1)); |
| 702 | GSL_RB_WRITE(rb->device, ringcmds, rcmd_gpu, KGSL_CMD_IDENTIFIER); |
| 703 | |
| 704 | if (flags & KGSL_CMD_FLAGS_INTERNAL_ISSUE) { |
| 705 | GSL_RB_WRITE(rb->device, ringcmds, rcmd_gpu, cp_nop_packet(1)); |
| 706 | GSL_RB_WRITE(rb->device, ringcmds, rcmd_gpu, |
| 707 | KGSL_CMD_INTERNAL_IDENTIFIER); |
| 708 | } |
| 709 | |
| 710 | if (flags & KGSL_CMD_FLAGS_PWRON_FIXUP) { |
Ethan Chen | 7b18590 | 2014-11-16 16:48:31 -0800 | [diff] [blame^] | 711 | /* Disable protected mode for the fixup */ |
| 712 | GSL_RB_WRITE(rb->device, ringcmds, rcmd_gpu, |
| 713 | cp_type3_packet(CP_SET_PROTECTED_MODE, 1)); |
| 714 | GSL_RB_WRITE(rb->device, ringcmds, rcmd_gpu, 0); |
| 715 | |
Steve Kondik | f7652b3 | 2013-11-26 15:20:51 -0800 | [diff] [blame] | 716 | GSL_RB_WRITE(rb->device, ringcmds, rcmd_gpu, cp_nop_packet(1)); |
| 717 | GSL_RB_WRITE(rb->device, ringcmds, rcmd_gpu, |
| 718 | KGSL_PWRON_FIXUP_IDENTIFIER); |
| 719 | GSL_RB_WRITE(rb->device, ringcmds, rcmd_gpu, |
| 720 | CP_HDR_INDIRECT_BUFFER_PFD); |
| 721 | GSL_RB_WRITE(rb->device, ringcmds, rcmd_gpu, |
| 722 | adreno_dev->pwron_fixup.gpuaddr); |
| 723 | GSL_RB_WRITE(rb->device, ringcmds, rcmd_gpu, |
| 724 | adreno_dev->pwron_fixup_dwords); |
Ethan Chen | 7b18590 | 2014-11-16 16:48:31 -0800 | [diff] [blame^] | 725 | |
| 726 | /* Re-enable protected mode */ |
| 727 | GSL_RB_WRITE(rb->device, ringcmds, rcmd_gpu, |
| 728 | cp_type3_packet(CP_SET_PROTECTED_MODE, 1)); |
| 729 | GSL_RB_WRITE(rb->device, ringcmds, rcmd_gpu, 1); |
Steve Kondik | f7652b3 | 2013-11-26 15:20:51 -0800 | [diff] [blame] | 730 | } |
| 731 | |
| 732 | /* start-of-pipeline timestamp */ |
| 733 | GSL_RB_WRITE(rb->device, ringcmds, rcmd_gpu, |
| 734 | cp_type3_packet(CP_MEM_WRITE, 2)); |
| 735 | GSL_RB_WRITE(rb->device, ringcmds, rcmd_gpu, (gpuaddr + |
| 736 | KGSL_MEMSTORE_OFFSET(context_id, soptimestamp))); |
| 737 | GSL_RB_WRITE(rb->device, ringcmds, rcmd_gpu, timestamp); |
| 738 | |
| 739 | if (flags & KGSL_CMD_FLAGS_PMODE) { |
| 740 | /* disable protected mode error checking */ |
| 741 | GSL_RB_WRITE(rb->device, ringcmds, rcmd_gpu, |
| 742 | cp_type3_packet(CP_SET_PROTECTED_MODE, 1)); |
| 743 | GSL_RB_WRITE(rb->device, ringcmds, rcmd_gpu, 0); |
| 744 | } |
| 745 | |
| 746 | for (i = 0; i < sizedwords; i++) { |
| 747 | GSL_RB_WRITE(rb->device, ringcmds, rcmd_gpu, *cmds); |
| 748 | cmds++; |
| 749 | } |
| 750 | |
| 751 | if (flags & KGSL_CMD_FLAGS_PMODE) { |
| 752 | /* re-enable protected mode error checking */ |
| 753 | GSL_RB_WRITE(rb->device, ringcmds, rcmd_gpu, |
| 754 | cp_type3_packet(CP_SET_PROTECTED_MODE, 1)); |
| 755 | GSL_RB_WRITE(rb->device, ringcmds, rcmd_gpu, 1); |
| 756 | } |
| 757 | |
| 758 | /* HW Workaround for MMU Page fault |
| 759 | * due to memory getting free early before |
| 760 | * GPU completes it. |
| 761 | */ |
| 762 | if (adreno_is_a2xx(adreno_dev)) { |
| 763 | GSL_RB_WRITE(rb->device, ringcmds, rcmd_gpu, |
| 764 | cp_type3_packet(CP_WAIT_FOR_IDLE, 1)); |
| 765 | GSL_RB_WRITE(rb->device, ringcmds, rcmd_gpu, 0x00); |
| 766 | } |
| 767 | |
| 768 | if (adreno_is_a3xx(adreno_dev) || adreno_is_a4xx(adreno_dev)) { |
| 769 | /* |
| 770 | * Flush HLSQ lazy updates to make sure there are no |
| 771 | * resources pending for indirect loads after the timestamp |
| 772 | */ |
| 773 | |
| 774 | GSL_RB_WRITE(rb->device, ringcmds, rcmd_gpu, |
| 775 | cp_type3_packet(CP_EVENT_WRITE, 1)); |
| 776 | GSL_RB_WRITE(rb->device, ringcmds, |
| 777 | rcmd_gpu, 0x07); /* HLSQ_FLUSH */ |
| 778 | GSL_RB_WRITE(rb->device, ringcmds, rcmd_gpu, |
| 779 | cp_type3_packet(CP_WAIT_FOR_IDLE, 1)); |
| 780 | GSL_RB_WRITE(rb->device, ringcmds, rcmd_gpu, 0x00); |
| 781 | } |
| 782 | |
| 783 | /* |
| 784 | * end-of-pipeline timestamp. If per context timestamps is not |
| 785 | * enabled, then context_id will be KGSL_MEMSTORE_GLOBAL so all |
| 786 | * eop timestamps will work out. |
| 787 | */ |
| 788 | GSL_RB_WRITE(rb->device, ringcmds, rcmd_gpu, |
| 789 | cp_type3_packet(CP_EVENT_WRITE, 3)); |
| 790 | GSL_RB_WRITE(rb->device, ringcmds, rcmd_gpu, CACHE_FLUSH_TS); |
| 791 | GSL_RB_WRITE(rb->device, ringcmds, rcmd_gpu, (gpuaddr + |
| 792 | KGSL_MEMSTORE_OFFSET(context_id, eoptimestamp))); |
| 793 | GSL_RB_WRITE(rb->device, ringcmds, rcmd_gpu, timestamp); |
| 794 | |
| 795 | if (drawctxt) { |
| 796 | GSL_RB_WRITE(rb->device, ringcmds, rcmd_gpu, |
| 797 | cp_type3_packet(CP_MEM_WRITE, 2)); |
| 798 | GSL_RB_WRITE(rb->device, ringcmds, rcmd_gpu, (gpuaddr + |
| 799 | KGSL_MEMSTORE_OFFSET(KGSL_MEMSTORE_GLOBAL, |
| 800 | eoptimestamp))); |
Ethan Chen | 7b18590 | 2014-11-16 16:48:31 -0800 | [diff] [blame^] | 801 | GSL_RB_WRITE(rb->device, ringcmds, rcmd_gpu, |
| 802 | rb->global_ts); |
Steve Kondik | f7652b3 | 2013-11-26 15:20:51 -0800 | [diff] [blame] | 803 | } |
| 804 | |
| 805 | if (adreno_is_a20x(adreno_dev)) { |
| 806 | GSL_RB_WRITE(rb->device, ringcmds, rcmd_gpu, |
| 807 | cp_type3_packet(CP_EVENT_WRITE, 1)); |
| 808 | GSL_RB_WRITE(rb->device, ringcmds, rcmd_gpu, CACHE_FLUSH); |
| 809 | } |
| 810 | |
| 811 | if (drawctxt || (flags & KGSL_CMD_FLAGS_INTERNAL_ISSUE)) { |
| 812 | GSL_RB_WRITE(rb->device, ringcmds, rcmd_gpu, |
| 813 | cp_type3_packet(CP_INTERRUPT, 1)); |
| 814 | GSL_RB_WRITE(rb->device, ringcmds, rcmd_gpu, |
| 815 | CP_INT_CNTL__RB_INT_MASK); |
| 816 | } |
| 817 | |
| 818 | if (adreno_is_a3xx(adreno_dev)) { |
| 819 | /* Dummy set-constant to trigger context rollover */ |
| 820 | GSL_RB_WRITE(rb->device, ringcmds, rcmd_gpu, |
| 821 | cp_type3_packet(CP_SET_CONSTANT, 2)); |
| 822 | GSL_RB_WRITE(rb->device, ringcmds, rcmd_gpu, |
| 823 | (0x4<<16)|(A3XX_HLSQ_CL_KERNEL_GROUP_X_REG - 0x2000)); |
| 824 | GSL_RB_WRITE(rb->device, ringcmds, rcmd_gpu, 0); |
| 825 | } |
| 826 | |
| 827 | if (flags & KGSL_CMD_FLAGS_WFI) { |
| 828 | GSL_RB_WRITE(rb->device, ringcmds, rcmd_gpu, |
| 829 | cp_type3_packet(CP_WAIT_FOR_IDLE, 1)); |
| 830 | GSL_RB_WRITE(rb->device, ringcmds, rcmd_gpu, 0x00000000); |
| 831 | } |
| 832 | |
| 833 | adreno_ringbuffer_submit(rb); |
| 834 | |
| 835 | return 0; |
| 836 | } |
| 837 | |
| 838 | unsigned int |
| 839 | adreno_ringbuffer_issuecmds(struct kgsl_device *device, |
| 840 | struct adreno_context *drawctxt, |
| 841 | unsigned int flags, |
| 842 | unsigned int *cmds, |
| 843 | int sizedwords) |
| 844 | { |
| 845 | struct adreno_device *adreno_dev = ADRENO_DEVICE(device); |
| 846 | struct adreno_ringbuffer *rb = &adreno_dev->ringbuffer; |
| 847 | |
| 848 | flags |= KGSL_CMD_FLAGS_INTERNAL_ISSUE; |
| 849 | |
| 850 | return adreno_ringbuffer_addcmds(rb, drawctxt, flags, cmds, |
| 851 | sizedwords, 0); |
| 852 | } |
| 853 | |
| 854 | static bool _parse_ibs(struct kgsl_device_private *dev_priv, uint gpuaddr, |
| 855 | int sizedwords); |
| 856 | |
| 857 | static bool |
| 858 | _handle_type3(struct kgsl_device_private *dev_priv, uint *hostaddr) |
| 859 | { |
| 860 | unsigned int opcode = cp_type3_opcode(*hostaddr); |
| 861 | switch (opcode) { |
| 862 | case CP_INDIRECT_BUFFER_PFD: |
| 863 | case CP_INDIRECT_BUFFER_PFE: |
| 864 | case CP_COND_INDIRECT_BUFFER_PFE: |
| 865 | case CP_COND_INDIRECT_BUFFER_PFD: |
| 866 | return _parse_ibs(dev_priv, hostaddr[1], hostaddr[2]); |
| 867 | case CP_NOP: |
| 868 | case CP_WAIT_FOR_IDLE: |
| 869 | case CP_WAIT_REG_MEM: |
| 870 | case CP_WAIT_REG_EQ: |
| 871 | case CP_WAT_REG_GTE: |
| 872 | case CP_WAIT_UNTIL_READ: |
| 873 | case CP_WAIT_IB_PFD_COMPLETE: |
| 874 | case CP_REG_RMW: |
| 875 | case CP_REG_TO_MEM: |
| 876 | case CP_MEM_WRITE: |
| 877 | case CP_MEM_WRITE_CNTR: |
| 878 | case CP_COND_EXEC: |
| 879 | case CP_COND_WRITE: |
| 880 | case CP_EVENT_WRITE: |
| 881 | case CP_EVENT_WRITE_SHD: |
| 882 | case CP_EVENT_WRITE_CFL: |
| 883 | case CP_EVENT_WRITE_ZPD: |
| 884 | case CP_DRAW_INDX: |
| 885 | case CP_DRAW_INDX_2: |
| 886 | case CP_DRAW_INDX_BIN: |
| 887 | case CP_DRAW_INDX_2_BIN: |
| 888 | case CP_VIZ_QUERY: |
| 889 | case CP_SET_STATE: |
| 890 | case CP_SET_CONSTANT: |
| 891 | case CP_IM_LOAD: |
| 892 | case CP_IM_LOAD_IMMEDIATE: |
| 893 | case CP_LOAD_CONSTANT_CONTEXT: |
| 894 | case CP_INVALIDATE_STATE: |
| 895 | case CP_SET_SHADER_BASES: |
| 896 | case CP_SET_BIN_MASK: |
| 897 | case CP_SET_BIN_SELECT: |
| 898 | case CP_SET_BIN_BASE_OFFSET: |
| 899 | case CP_SET_BIN_DATA: |
| 900 | case CP_CONTEXT_UPDATE: |
| 901 | case CP_INTERRUPT: |
| 902 | case CP_IM_STORE: |
| 903 | case CP_LOAD_STATE: |
| 904 | break; |
| 905 | /* these shouldn't come from userspace */ |
| 906 | case CP_ME_INIT: |
| 907 | case CP_SET_PROTECTED_MODE: |
| 908 | default: |
| 909 | KGSL_CMD_ERR(dev_priv->device, "bad CP opcode %0x\n", opcode); |
| 910 | return false; |
| 911 | break; |
| 912 | } |
| 913 | |
| 914 | return true; |
| 915 | } |
| 916 | |
| 917 | static bool |
| 918 | _handle_type0(struct kgsl_device_private *dev_priv, uint *hostaddr) |
| 919 | { |
| 920 | unsigned int reg = type0_pkt_offset(*hostaddr); |
| 921 | unsigned int cnt = type0_pkt_size(*hostaddr); |
| 922 | if (reg < 0x0192 || (reg + cnt) >= 0x8000) { |
| 923 | KGSL_CMD_ERR(dev_priv->device, "bad type0 reg: 0x%0x cnt: %d\n", |
| 924 | reg, cnt); |
| 925 | return false; |
| 926 | } |
| 927 | return true; |
| 928 | } |
| 929 | |
| 930 | /* |
| 931 | * Traverse IBs and dump them to test vector. Detect swap by inspecting |
| 932 | * register writes, keeping note of the current state, and dump |
| 933 | * framebuffer config to test vector |
| 934 | */ |
| 935 | static bool _parse_ibs(struct kgsl_device_private *dev_priv, |
| 936 | uint gpuaddr, int sizedwords) |
| 937 | { |
| 938 | static uint level; /* recursion level */ |
| 939 | bool ret = false; |
| 940 | uint *hostaddr, *hoststart; |
| 941 | int dwords_left = sizedwords; /* dwords left in the current command |
| 942 | buffer */ |
| 943 | struct kgsl_mem_entry *entry; |
| 944 | |
| 945 | entry = kgsl_sharedmem_find_region(dev_priv->process_priv, |
| 946 | gpuaddr, sizedwords * sizeof(uint)); |
| 947 | if (entry == NULL) { |
| 948 | KGSL_CMD_ERR(dev_priv->device, |
| 949 | "no mapping for gpuaddr: 0x%08x\n", gpuaddr); |
| 950 | return false; |
| 951 | } |
| 952 | |
| 953 | hostaddr = (uint *)kgsl_gpuaddr_to_vaddr(&entry->memdesc, gpuaddr); |
| 954 | if (hostaddr == NULL) { |
| 955 | KGSL_CMD_ERR(dev_priv->device, |
| 956 | "no mapping for gpuaddr: 0x%08x\n", gpuaddr); |
| 957 | return false; |
| 958 | } |
| 959 | |
| 960 | hoststart = hostaddr; |
| 961 | |
| 962 | level++; |
| 963 | |
| 964 | KGSL_CMD_INFO(dev_priv->device, "ib: gpuaddr:0x%08x, wc:%d, hptr:%p\n", |
| 965 | gpuaddr, sizedwords, hostaddr); |
| 966 | |
| 967 | mb(); |
| 968 | while (dwords_left > 0) { |
| 969 | bool cur_ret = true; |
| 970 | int count = 0; /* dword count including packet header */ |
| 971 | |
| 972 | switch (*hostaddr >> 30) { |
| 973 | case 0x0: /* type-0 */ |
| 974 | count = (*hostaddr >> 16)+2; |
| 975 | cur_ret = _handle_type0(dev_priv, hostaddr); |
| 976 | break; |
| 977 | case 0x1: /* type-1 */ |
| 978 | count = 2; |
| 979 | break; |
| 980 | case 0x3: /* type-3 */ |
| 981 | count = ((*hostaddr >> 16) & 0x3fff) + 2; |
| 982 | cur_ret = _handle_type3(dev_priv, hostaddr); |
| 983 | break; |
| 984 | default: |
| 985 | KGSL_CMD_ERR(dev_priv->device, "unexpected type: " |
| 986 | "type:%d, word:0x%08x @ 0x%p, gpu:0x%08x\n", |
| 987 | *hostaddr >> 30, *hostaddr, hostaddr, |
| 988 | gpuaddr+4*(sizedwords-dwords_left)); |
| 989 | cur_ret = false; |
| 990 | count = dwords_left; |
| 991 | break; |
| 992 | } |
| 993 | |
| 994 | if (!cur_ret) { |
| 995 | KGSL_CMD_ERR(dev_priv->device, |
| 996 | "bad sub-type: #:%d/%d, v:0x%08x" |
| 997 | " @ 0x%p[gb:0x%08x], level:%d\n", |
| 998 | sizedwords-dwords_left, sizedwords, *hostaddr, |
| 999 | hostaddr, gpuaddr+4*(sizedwords-dwords_left), |
| 1000 | level); |
| 1001 | |
| 1002 | if (ADRENO_DEVICE(dev_priv->device)->ib_check_level |
| 1003 | >= 2) |
| 1004 | print_hex_dump(KERN_ERR, |
| 1005 | level == 1 ? "IB1:" : "IB2:", |
| 1006 | DUMP_PREFIX_OFFSET, 32, 4, hoststart, |
| 1007 | sizedwords*4, 0); |
| 1008 | goto done; |
| 1009 | } |
| 1010 | |
| 1011 | /* jump to next packet */ |
| 1012 | dwords_left -= count; |
| 1013 | hostaddr += count; |
| 1014 | if (dwords_left < 0) { |
| 1015 | KGSL_CMD_ERR(dev_priv->device, |
| 1016 | "bad count: c:%d, #:%d/%d, " |
| 1017 | "v:0x%08x @ 0x%p[gb:0x%08x], level:%d\n", |
| 1018 | count, sizedwords-(dwords_left+count), |
| 1019 | sizedwords, *(hostaddr-count), hostaddr-count, |
| 1020 | gpuaddr+4*(sizedwords-(dwords_left+count)), |
| 1021 | level); |
| 1022 | if (ADRENO_DEVICE(dev_priv->device)->ib_check_level |
| 1023 | >= 2) |
| 1024 | print_hex_dump(KERN_ERR, |
| 1025 | level == 1 ? "IB1:" : "IB2:", |
| 1026 | DUMP_PREFIX_OFFSET, 32, 4, hoststart, |
| 1027 | sizedwords*4, 0); |
| 1028 | goto done; |
| 1029 | } |
| 1030 | } |
| 1031 | |
| 1032 | ret = true; |
| 1033 | done: |
| 1034 | if (!ret) |
| 1035 | KGSL_DRV_ERR(dev_priv->device, |
| 1036 | "parsing failed: gpuaddr:0x%08x, " |
| 1037 | "host:0x%p, wc:%d\n", gpuaddr, hoststart, sizedwords); |
| 1038 | |
| 1039 | level--; |
| 1040 | |
| 1041 | return ret; |
| 1042 | } |
| 1043 | |
| 1044 | /** |
| 1045 | * _ringbuffer_verify_ib() - parse an IB and verify that it is correct |
| 1046 | * @dev_priv: Pointer to the process struct |
| 1047 | * @ibdesc: Pointer to the IB descriptor |
| 1048 | * |
| 1049 | * This function only gets called if debugging is enabled - it walks the IB and |
| 1050 | * does additional level parsing and verification above and beyond what KGSL |
| 1051 | * core does |
| 1052 | */ |
| 1053 | static inline bool _ringbuffer_verify_ib(struct kgsl_device_private *dev_priv, |
| 1054 | struct kgsl_ibdesc *ibdesc) |
| 1055 | { |
| 1056 | struct kgsl_device *device = dev_priv->device; |
| 1057 | struct adreno_device *adreno_dev = ADRENO_DEVICE(device); |
| 1058 | |
| 1059 | /* Check that the size of the IBs is under the allowable limit */ |
| 1060 | if (ibdesc->sizedwords == 0 || ibdesc->sizedwords > 0xFFFFF) { |
| 1061 | KGSL_DRV_ERR(device, "Invalid IB size 0x%X\n", |
| 1062 | ibdesc->sizedwords); |
| 1063 | return false; |
| 1064 | } |
| 1065 | |
| 1066 | if (unlikely(adreno_dev->ib_check_level >= 1) && |
| 1067 | !_parse_ibs(dev_priv, ibdesc->gpuaddr, ibdesc->sizedwords)) { |
| 1068 | KGSL_DRV_ERR(device, "Could not verify the IBs\n"); |
| 1069 | return false; |
| 1070 | } |
| 1071 | |
| 1072 | return true; |
| 1073 | } |
| 1074 | |
| 1075 | int |
| 1076 | adreno_ringbuffer_issueibcmds(struct kgsl_device_private *dev_priv, |
| 1077 | struct kgsl_context *context, |
| 1078 | struct kgsl_cmdbatch *cmdbatch, |
| 1079 | uint32_t *timestamp) |
| 1080 | { |
| 1081 | struct kgsl_device *device = dev_priv->device; |
| 1082 | struct adreno_device *adreno_dev = ADRENO_DEVICE(device); |
| 1083 | struct adreno_context *drawctxt = ADRENO_CONTEXT(context); |
| 1084 | int i, ret; |
| 1085 | |
| 1086 | if (drawctxt->state == ADRENO_CONTEXT_STATE_INVALID) |
| 1087 | return -EDEADLK; |
| 1088 | |
| 1089 | /* Verify the IBs before they get queued */ |
| 1090 | |
| 1091 | for (i = 0; i < cmdbatch->ibcount; i++) { |
| 1092 | if (!_ringbuffer_verify_ib(dev_priv, &cmdbatch->ibdesc[i])) |
| 1093 | return -EINVAL; |
| 1094 | } |
| 1095 | |
| 1096 | /* For now everybody has the same priority */ |
| 1097 | cmdbatch->priority = ADRENO_CONTEXT_DEFAULT_PRIORITY; |
| 1098 | |
Steve Kondik | 2deaf4b | 2014-03-20 22:29:09 -0700 | [diff] [blame] | 1099 | /* wait for the suspend gate */ |
| 1100 | wait_for_completion(&device->cmdbatch_gate); |
| 1101 | |
Steve Kondik | f7652b3 | 2013-11-26 15:20:51 -0800 | [diff] [blame] | 1102 | /* Queue the command in the ringbuffer */ |
| 1103 | ret = adreno_dispatcher_queue_cmd(adreno_dev, drawctxt, cmdbatch, |
| 1104 | timestamp); |
| 1105 | |
| 1106 | if (ret) |
Ethan Chen | 7b18590 | 2014-11-16 16:48:31 -0800 | [diff] [blame^] | 1107 | KGSL_DRV_ERR(device, "adreno_context_queue_cmd returned %d\n", |
Steve Kondik | f7652b3 | 2013-11-26 15:20:51 -0800 | [diff] [blame] | 1108 | ret); |
| 1109 | else { |
| 1110 | /* |
| 1111 | * only call trace_gpu_job_enqueue for actual commands - dummy |
| 1112 | * sync command batches won't get scheduled on the GPU |
| 1113 | */ |
| 1114 | |
| 1115 | if (!(cmdbatch->flags & KGSL_CONTEXT_SYNC)) { |
| 1116 | const char *str = "3D"; |
| 1117 | if (drawctxt->type == KGSL_CONTEXT_TYPE_CL || |
| 1118 | drawctxt->type == KGSL_CONTEXT_TYPE_RS) |
| 1119 | str = "compute"; |
| 1120 | |
| 1121 | kgsl_trace_gpu_job_enqueue(drawctxt->base.id, |
| 1122 | cmdbatch->timestamp, str); |
| 1123 | } |
| 1124 | } |
| 1125 | |
Ethan Chen | 7b18590 | 2014-11-16 16:48:31 -0800 | [diff] [blame^] | 1126 | /* |
| 1127 | * Return -EPROTO if the device has faulted since the last time we |
| 1128 | * checked - userspace uses this to perform post-fault activities |
| 1129 | */ |
| 1130 | if (!ret && test_and_clear_bit(ADRENO_CONTEXT_FAULT, &drawctxt->priv)) |
| 1131 | ret = -EPROTO; |
| 1132 | |
Steve Kondik | f7652b3 | 2013-11-26 15:20:51 -0800 | [diff] [blame] | 1133 | return ret; |
| 1134 | } |
| 1135 | |
Ethan Chen | 7b18590 | 2014-11-16 16:48:31 -0800 | [diff] [blame^] | 1136 | unsigned int adreno_ringbuffer_get_constraint(struct kgsl_device *device, |
| 1137 | struct kgsl_context *context) |
| 1138 | { |
| 1139 | unsigned int pwrlevel = device->pwrctrl.active_pwrlevel; |
| 1140 | |
| 1141 | switch (context->pwr_constraint.type) { |
| 1142 | case KGSL_CONSTRAINT_PWRLEVEL: { |
| 1143 | switch (context->pwr_constraint.sub_type) { |
| 1144 | case KGSL_CONSTRAINT_PWR_MAX: |
| 1145 | pwrlevel = device->pwrctrl.max_pwrlevel; |
| 1146 | break; |
| 1147 | case KGSL_CONSTRAINT_PWR_MIN: |
| 1148 | pwrlevel = device->pwrctrl.min_pwrlevel; |
| 1149 | break; |
| 1150 | default: |
| 1151 | break; |
| 1152 | } |
| 1153 | } |
| 1154 | break; |
| 1155 | |
| 1156 | } |
| 1157 | |
| 1158 | return pwrlevel; |
| 1159 | } |
| 1160 | |
| 1161 | void adreno_ringbuffer_set_constraint(struct kgsl_device *device, |
| 1162 | struct kgsl_cmdbatch *cmdbatch) |
| 1163 | { |
| 1164 | unsigned int constraint; |
| 1165 | struct kgsl_context *context = cmdbatch->context; |
| 1166 | /* |
| 1167 | * Check if the context has a constraint and constraint flags are |
| 1168 | * set. |
| 1169 | */ |
| 1170 | if (context->pwr_constraint.type && |
| 1171 | ((context->flags & KGSL_CONTEXT_PWR_CONSTRAINT) || |
| 1172 | (cmdbatch->flags & KGSL_CONTEXT_PWR_CONSTRAINT))) { |
| 1173 | |
| 1174 | constraint = adreno_ringbuffer_get_constraint(device, context); |
| 1175 | |
| 1176 | /* |
| 1177 | * If a constraint is already set, set a new constraint only |
| 1178 | * if it is faster. If the requested constraint is the same |
| 1179 | * as the current one, update ownership and timestamp. |
| 1180 | */ |
| 1181 | if ((device->pwrctrl.constraint.type == |
| 1182 | KGSL_CONSTRAINT_NONE) || (constraint < |
| 1183 | device->pwrctrl.constraint.hint.pwrlevel.level)) { |
| 1184 | |
| 1185 | kgsl_pwrctrl_pwrlevel_change(device, constraint); |
| 1186 | device->pwrctrl.constraint.type = |
| 1187 | context->pwr_constraint.type; |
| 1188 | device->pwrctrl.constraint.hint. |
| 1189 | pwrlevel.level = constraint; |
| 1190 | device->pwrctrl.constraint.owner_id = context->id; |
| 1191 | device->pwrctrl.constraint.expires = jiffies + |
| 1192 | device->pwrctrl.interval_timeout; |
| 1193 | /* Trace the constraint being set by the driver */ |
| 1194 | trace_kgsl_constraint(device, |
| 1195 | device->pwrctrl.constraint.type, |
| 1196 | constraint, 1); |
| 1197 | } else if ((device->pwrctrl.constraint.type == |
| 1198 | context->pwr_constraint.type) && |
| 1199 | (device->pwrctrl.constraint.hint.pwrlevel.level == |
| 1200 | constraint)) { |
| 1201 | device->pwrctrl.constraint.owner_id = context->id; |
| 1202 | device->pwrctrl.constraint.expires = jiffies + |
| 1203 | device->pwrctrl.interval_timeout; |
| 1204 | } |
| 1205 | } |
| 1206 | |
| 1207 | } |
| 1208 | |
Steve Kondik | f7652b3 | 2013-11-26 15:20:51 -0800 | [diff] [blame] | 1209 | /* adreno_rindbuffer_submitcmd - submit userspace IBs to the GPU */ |
| 1210 | int adreno_ringbuffer_submitcmd(struct adreno_device *adreno_dev, |
| 1211 | struct kgsl_cmdbatch *cmdbatch) |
| 1212 | { |
| 1213 | struct kgsl_device *device = &adreno_dev->dev; |
| 1214 | struct kgsl_ibdesc *ibdesc; |
| 1215 | unsigned int numibs; |
| 1216 | unsigned int *link; |
| 1217 | unsigned int *cmds; |
| 1218 | unsigned int i; |
| 1219 | struct kgsl_context *context; |
| 1220 | struct adreno_context *drawctxt; |
| 1221 | unsigned int start_index = 0; |
| 1222 | int flags = KGSL_CMD_FLAGS_NONE; |
| 1223 | int ret; |
| 1224 | |
| 1225 | context = cmdbatch->context; |
| 1226 | drawctxt = ADRENO_CONTEXT(context); |
| 1227 | |
| 1228 | ibdesc = cmdbatch->ibdesc; |
| 1229 | numibs = cmdbatch->ibcount; |
| 1230 | |
| 1231 | /*When preamble is enabled, the preamble buffer with state restoration |
| 1232 | commands are stored in the first node of the IB chain. We can skip that |
| 1233 | if a context switch hasn't occured */ |
| 1234 | |
Ethan Chen | 7b18590 | 2014-11-16 16:48:31 -0800 | [diff] [blame^] | 1235 | if ((drawctxt->base.flags & KGSL_CONTEXT_PREAMBLE) && |
Steve Kondik | f7652b3 | 2013-11-26 15:20:51 -0800 | [diff] [blame] | 1236 | !test_bit(CMDBATCH_FLAG_FORCE_PREAMBLE, &cmdbatch->priv) && |
| 1237 | (adreno_dev->drawctxt_active == drawctxt)) |
| 1238 | start_index = 1; |
| 1239 | |
| 1240 | /* |
| 1241 | * In skip mode don't issue the draw IBs but keep all the other |
| 1242 | * accoutrements of a submision (including the interrupt) to keep |
| 1243 | * the accounting sane. Set start_index and numibs to 0 to just |
| 1244 | * generate the start and end markers and skip everything else |
| 1245 | */ |
| 1246 | |
| 1247 | if (test_bit(CMDBATCH_FLAG_SKIP, &cmdbatch->priv)) { |
| 1248 | start_index = 0; |
| 1249 | numibs = 0; |
| 1250 | } |
| 1251 | |
| 1252 | cmds = link = kzalloc(sizeof(unsigned int) * (numibs * 3 + 4), |
| 1253 | GFP_KERNEL); |
| 1254 | if (!link) { |
| 1255 | ret = -ENOMEM; |
| 1256 | goto done; |
| 1257 | } |
| 1258 | |
| 1259 | if (!start_index) { |
| 1260 | *cmds++ = cp_nop_packet(1); |
| 1261 | *cmds++ = KGSL_START_OF_IB_IDENTIFIER; |
| 1262 | } else { |
| 1263 | *cmds++ = cp_nop_packet(4); |
| 1264 | *cmds++ = KGSL_START_OF_IB_IDENTIFIER; |
| 1265 | *cmds++ = CP_HDR_INDIRECT_BUFFER_PFD; |
| 1266 | *cmds++ = ibdesc[0].gpuaddr; |
| 1267 | *cmds++ = ibdesc[0].sizedwords; |
| 1268 | } |
| 1269 | for (i = start_index; i < numibs; i++) { |
| 1270 | |
| 1271 | /* |
| 1272 | * Skip 0 sized IBs - these are presumed to have been removed |
| 1273 | * from consideration by the FT policy |
| 1274 | */ |
| 1275 | |
| 1276 | if (ibdesc[i].sizedwords == 0) |
| 1277 | *cmds++ = cp_nop_packet(2); |
| 1278 | else |
| 1279 | *cmds++ = CP_HDR_INDIRECT_BUFFER_PFD; |
| 1280 | |
| 1281 | *cmds++ = ibdesc[i].gpuaddr; |
| 1282 | *cmds++ = ibdesc[i].sizedwords; |
| 1283 | } |
| 1284 | |
| 1285 | *cmds++ = cp_nop_packet(1); |
| 1286 | *cmds++ = KGSL_END_OF_IB_IDENTIFIER; |
| 1287 | |
| 1288 | ret = kgsl_setstate(&device->mmu, context->id, |
| 1289 | kgsl_mmu_pt_get_flags(device->mmu.hwpagetable, |
| 1290 | device->id)); |
| 1291 | |
| 1292 | if (ret) |
| 1293 | goto done; |
| 1294 | |
| 1295 | ret = adreno_drawctxt_switch(adreno_dev, drawctxt, cmdbatch->flags); |
| 1296 | |
| 1297 | /* |
| 1298 | * In the unlikely event of an error in the drawctxt switch, |
| 1299 | * treat it like a hang |
| 1300 | */ |
| 1301 | if (ret) |
| 1302 | goto done; |
| 1303 | |
| 1304 | if (test_bit(CMDBATCH_FLAG_WFI, &cmdbatch->priv)) |
| 1305 | flags = KGSL_CMD_FLAGS_WFI; |
| 1306 | |
| 1307 | /* |
| 1308 | * For some targets, we need to execute a dummy shader operation after a |
| 1309 | * power collapse |
| 1310 | */ |
| 1311 | |
| 1312 | if (test_and_clear_bit(ADRENO_DEVICE_PWRON, &adreno_dev->priv) && |
| 1313 | test_bit(ADRENO_DEVICE_PWRON_FIXUP, &adreno_dev->priv)) |
| 1314 | flags |= KGSL_CMD_FLAGS_PWRON_FIXUP; |
| 1315 | |
Ethan Chen | 7b18590 | 2014-11-16 16:48:31 -0800 | [diff] [blame^] | 1316 | /* Set the constraints before adding to ringbuffer */ |
| 1317 | adreno_ringbuffer_set_constraint(device, cmdbatch); |
| 1318 | |
Steve Kondik | f7652b3 | 2013-11-26 15:20:51 -0800 | [diff] [blame] | 1319 | ret = adreno_ringbuffer_addcmds(&adreno_dev->ringbuffer, |
| 1320 | drawctxt, |
| 1321 | flags, |
| 1322 | &link[0], (cmds - link), |
| 1323 | cmdbatch->timestamp); |
| 1324 | |
| 1325 | #ifdef CONFIG_MSM_KGSL_CFF_DUMP |
Steve Kondik | 2deaf4b | 2014-03-20 22:29:09 -0700 | [diff] [blame] | 1326 | if (ret) |
| 1327 | goto done; |
Steve Kondik | f7652b3 | 2013-11-26 15:20:51 -0800 | [diff] [blame] | 1328 | /* |
| 1329 | * insert wait for idle after every IB1 |
| 1330 | * this is conservative but works reliably and is ok |
| 1331 | * even for performance simulations |
| 1332 | */ |
Steve Kondik | 2deaf4b | 2014-03-20 22:29:09 -0700 | [diff] [blame] | 1333 | ret = adreno_idle(device); |
Steve Kondik | f7652b3 | 2013-11-26 15:20:51 -0800 | [diff] [blame] | 1334 | #endif |
| 1335 | |
| 1336 | done: |
| 1337 | device->pwrctrl.irq_last = 0; |
| 1338 | kgsl_trace_issueibcmds(device, context->id, cmdbatch, |
| 1339 | cmdbatch->timestamp, cmdbatch->flags, ret, |
Ethan Chen | 7b18590 | 2014-11-16 16:48:31 -0800 | [diff] [blame^] | 1340 | drawctxt->type); |
Steve Kondik | f7652b3 | 2013-11-26 15:20:51 -0800 | [diff] [blame] | 1341 | |
| 1342 | kfree(link); |
| 1343 | return ret; |
| 1344 | } |