1 /* SPDX-License-Identifier: GPL-2.0-only */ 2 /* 3 * Copyright (C) 2013 Red Hat 4 * Author: Rob Clark <robdclark@gmail.com> 5 * 6 * Copyright (c) 2014,2017, 2019 The Linux Foundation. All rights reserved. 7 */ 8 9 #ifndef __ADRENO_GPU_H__ 10 #define __ADRENO_GPU_H__ 11 12 #include <linux/firmware.h> 13 #include <linux/iopoll.h> 14 15 #include <linux/soc/qcom/ubwc.h> 16 17 #include "msm_gpu.h" 18 19 #include "adreno_common.xml.h" 20 #include "adreno_pm4.xml.h" 21 22 extern bool snapshot_debugbus; 23 24 enum { 25 ADRENO_FW_PM4 = 0, 26 ADRENO_FW_SQE = 0, /* a6xx */ 27 ADRENO_FW_PFP = 1, 28 ADRENO_FW_GMU = 1, /* a6xx */ 29 ADRENO_FW_GPMU = 2, 30 ADRENO_FW_AQE = 3, 31 ADRENO_FW_MAX, 32 }; 33 34 /** 35 * @enum adreno_family: identify generation and possibly sub-generation 36 * 37 * In some cases there are distinct sub-generations within a major revision 38 * so it helps to be able to group the GPU devices by generation and if 39 * necessary sub-generation. 40 */ 41 enum adreno_family { 42 ADRENO_2XX_GEN1, /* a20x */ 43 ADRENO_2XX_GEN2, /* a22x */ 44 ADRENO_3XX, 45 ADRENO_4XX, 46 ADRENO_5XX, 47 ADRENO_6XX_GEN1, /* a630 family */ 48 ADRENO_6XX_GEN2, /* a640 family */ 49 ADRENO_6XX_GEN3, /* a650 family */ 50 ADRENO_6XX_GEN4, /* a660 family */ 51 ADRENO_7XX_GEN1, /* a730 family */ 52 ADRENO_7XX_GEN2, /* a740 family */ 53 ADRENO_7XX_GEN3, /* a750 family */ 54 ADRENO_8XX_GEN1, /* a830 family */ 55 ADRENO_8XX_GEN2, /* a840 family */ 56 }; 57 58 #define ADRENO_QUIRK_TWO_PASS_USE_WFI BIT(0) 59 #define ADRENO_QUIRK_FAULT_DETECT_MASK BIT(1) 60 #define ADRENO_QUIRK_LMLOADKILL_DISABLE BIT(2) 61 #define ADRENO_QUIRK_HAS_HW_APRIV BIT(3) 62 #define ADRENO_QUIRK_HAS_CACHED_COHERENT BIT(4) 63 #define ADRENO_QUIRK_PREEMPTION BIT(5) 64 #define ADRENO_QUIRK_4GB_VA BIT(6) 65 #define ADRENO_QUIRK_IFPC BIT(7) 66 #define ADRENO_QUIRK_SOFTFUSE BIT(8) 67 68 /* Helper for formating the chip_id in the way that userspace tools like 69 * crashdec expect. 70 */ 71 #define ADRENO_CHIPID_FMT "08x" 72 #define ADRENO_CHIPID_ARGS(_c) (_c) 73 74 struct adreno_gpu; 75 76 struct adreno_gpu_funcs { 77 struct msm_gpu_funcs base; 78 struct msm_gpu *(*init)(struct drm_device *dev); 79 u64 (*get_timestamp)(struct msm_gpu *gpu); 80 void (*bus_halt)(struct adreno_gpu *adreno_gpu, bool gx_off); 81 int (*mmu_fault_handler)(void *arg, unsigned long iova, int flags, void *data); 82 bool (*gx_is_on)(struct adreno_gpu *adreno_gpu); 83 bool (*aqe_is_enabled)(struct adreno_gpu *adreno_gpu); 84 }; 85 86 struct adreno_reglist { 87 u32 offset; 88 u32 value; 89 }; 90 91 /* Reglist with pipe information */ 92 struct adreno_reglist_pipe { 93 u32 offset; 94 u32 value; 95 u32 pipe; 96 }; 97 98 struct adreno_speedbin { 99 uint16_t fuse; 100 uint16_t speedbin; 101 }; 102 103 struct a6xx_info; 104 105 struct adreno_info { 106 const char *machine; 107 /** 108 * @chipids: Table of matching chip-ids 109 * 110 * Terminated with 0 sentinal 111 */ 112 uint32_t *chip_ids; 113 enum adreno_family family; 114 uint32_t revn; 115 const char *fw[ADRENO_FW_MAX]; 116 uint32_t gmem; 117 u64 quirks; 118 const struct adreno_gpu_funcs *funcs; 119 const char *zapfw; 120 u32 inactive_period; 121 union { 122 const struct a6xx_info *a6xx; 123 }; 124 /** 125 * @speedbins: Optional table of fuse to speedbin mappings 126 * 127 * Consists of pairs of fuse, index mappings, terminated with 128 * {SHRT_MAX, 0} sentinal. 129 */ 130 struct adreno_speedbin *speedbins; 131 u64 preempt_record_size; 132 }; 133 134 #define ADRENO_CHIP_IDS(tbl...) (uint32_t[]) { tbl, 0 } 135 136 struct adreno_gpulist { 137 const struct adreno_info *gpus; 138 unsigned gpus_count; 139 }; 140 141 #define DECLARE_ADRENO_GPULIST(name) \ 142 const struct adreno_gpulist name ## _gpulist = { \ 143 name ## _gpus, ARRAY_SIZE(name ## _gpus) \ 144 } 145 146 /* 147 * Helper to build a speedbin table, ie. the table: 148 * fuse | speedbin 149 * -----+--------- 150 * 0 | 0 151 * 169 | 1 152 * 174 | 2 153 * 154 * would be declared as: 155 * 156 * .speedbins = ADRENO_SPEEDBINS( 157 * { 0, 0 }, 158 * { 169, 1 }, 159 * { 174, 2 }, 160 * ), 161 */ 162 #define ADRENO_SPEEDBINS(tbl...) (struct adreno_speedbin[]) { tbl {SHRT_MAX, 0} } 163 164 struct adreno_protect { 165 const uint32_t *regs; 166 uint32_t count; 167 uint32_t count_max; 168 }; 169 170 #define DECLARE_ADRENO_PROTECT(name, __count_max) \ 171 static const struct adreno_protect name = { \ 172 .regs = name ## _regs, \ 173 .count = ARRAY_SIZE(name ## _regs), \ 174 .count_max = __count_max, \ 175 }; 176 177 struct adreno_reglist_list { 178 /** @reg: List of register **/ 179 const u32 *regs; 180 /** @count: Number of registers in the list **/ 181 u32 count; 182 }; 183 184 #define DECLARE_ADRENO_REGLIST_LIST(name) \ 185 static const struct adreno_reglist_list name = { \ 186 .regs = name ## _regs, \ 187 .count = ARRAY_SIZE(name ## _regs), \ 188 }; 189 190 struct adreno_reglist_pipe_list { 191 /** @reg: List of register **/ 192 const struct adreno_reglist_pipe *regs; 193 /** @count: Number of registers in the list **/ 194 u32 count; 195 }; 196 197 #define DECLARE_ADRENO_REGLIST_PIPE_LIST(name) \ 198 static const struct adreno_reglist_pipe_list name = { \ 199 .regs = name ## _regs, \ 200 .count = ARRAY_SIZE(name ## _regs), \ 201 }; 202 203 struct adreno_gpu { 204 struct msm_gpu base; 205 const struct adreno_info *info; 206 uint32_t chip_id; 207 /* GMEM size available to userspace, see a8xx_gpu_get_slice_info(): */ 208 uint32_t gmem; 209 uint16_t speedbin; 210 const struct adreno_gpu_funcs *funcs; 211 212 struct completion fault_coredump_done; 213 214 /* interesting register offsets to dump: */ 215 const unsigned int *registers; 216 217 /* 218 * Are we loading fw from legacy path? Prior to addition 219 * of gpu firmware to linux-firmware, the fw files were 220 * placed in toplevel firmware directory, following qcom's 221 * android kernel. But linux-firmware preferred they be 222 * placed in a 'qcom' subdirectory. 223 * 224 * For backwards compatibility, we try first to load from 225 * the new path, using request_firmware_direct() to avoid 226 * any potential timeout waiting for usermode helper, then 227 * fall back to the old path (with direct load). And 228 * finally fall back to request_firmware() with the new 229 * path to allow the usermode helper. 230 */ 231 enum { 232 FW_LOCATION_UNKNOWN = 0, 233 FW_LOCATION_NEW, /* /lib/firmware/qcom/$fwfile */ 234 FW_LOCATION_LEGACY, /* /lib/firmware/$fwfile */ 235 FW_LOCATION_HELPER, 236 } fwloc; 237 238 /* firmware: */ 239 const struct firmware *fw[ADRENO_FW_MAX]; 240 241 const struct qcom_ubwc_cfg_data *ubwc_config; 242 243 /* 244 * Register offsets are different between some GPUs. 245 * GPU specific offsets will be exported by GPU specific 246 * code (a3xx_gpu.c) and stored in this common location. 247 */ 248 const unsigned int *reg_offsets; 249 bool gmu_is_wrapper; 250 251 bool has_ray_tracing; 252 253 u64 uche_trap_base; 254 }; 255 #define to_adreno_gpu(x) container_of(x, struct adreno_gpu, base) 256 257 struct adreno_ocmem { 258 struct ocmem *ocmem; 259 unsigned long base; 260 void *hdl; 261 }; 262 263 /* platform config data (ie. from DT, or pdata) */ 264 struct adreno_platform_config { 265 uint32_t chip_id; 266 const struct adreno_info *info; 267 }; 268 269 #define ADRENO_IDLE_TIMEOUT msecs_to_jiffies(1000) 270 271 #define spin_until(X) ({ \ 272 int __ret = -ETIMEDOUT; \ 273 unsigned long __t = jiffies + ADRENO_IDLE_TIMEOUT; \ 274 do { \ 275 if (X) { \ 276 __ret = 0; \ 277 break; \ 278 } \ 279 } while (time_before(jiffies, __t)); \ 280 __ret; \ 281 }) 282 283 static inline uint8_t adreno_patchid(const struct adreno_gpu *gpu) 284 { 285 /* It is probably ok to assume legacy "adreno_rev" format 286 * for all a6xx devices, but probably best to limit this 287 * to older things. 288 */ 289 WARN_ON_ONCE(gpu->info->family >= ADRENO_6XX_GEN1); 290 return gpu->chip_id & 0xff; 291 } 292 293 static inline bool adreno_is_revn(const struct adreno_gpu *gpu, uint32_t revn) 294 { 295 if (WARN_ON_ONCE(!gpu->info)) 296 return false; 297 return gpu->info->revn == revn; 298 } 299 300 static inline bool adreno_has_gmu_wrapper(const struct adreno_gpu *gpu) 301 { 302 return gpu->gmu_is_wrapper; 303 } 304 305 static inline bool adreno_is_a2xx(const struct adreno_gpu *gpu) 306 { 307 if (WARN_ON_ONCE(!gpu->info)) 308 return false; 309 return gpu->info->family <= ADRENO_2XX_GEN2; 310 } 311 312 static inline bool adreno_is_a20x(const struct adreno_gpu *gpu) 313 { 314 if (WARN_ON_ONCE(!gpu->info)) 315 return false; 316 return gpu->info->family == ADRENO_2XX_GEN1; 317 } 318 319 static inline bool adreno_is_a225(const struct adreno_gpu *gpu) 320 { 321 return adreno_is_revn(gpu, 225); 322 } 323 324 static inline bool adreno_is_a305(const struct adreno_gpu *gpu) 325 { 326 return adreno_is_revn(gpu, 305); 327 } 328 329 static inline bool adreno_is_a305b(const struct adreno_gpu *gpu) 330 { 331 return gpu->info->chip_ids[0] == 0x03000512; 332 } 333 334 static inline bool adreno_is_a306(const struct adreno_gpu *gpu) 335 { 336 /* yes, 307, because a305c is 306 */ 337 return adreno_is_revn(gpu, 307); 338 } 339 340 static inline bool adreno_is_a306a(const struct adreno_gpu *gpu) 341 { 342 /* a306a (marketing name is a308) */ 343 return adreno_is_revn(gpu, 308); 344 } 345 346 static inline bool adreno_is_a320(const struct adreno_gpu *gpu) 347 { 348 return adreno_is_revn(gpu, 320); 349 } 350 351 static inline bool adreno_is_a330(const struct adreno_gpu *gpu) 352 { 353 return adreno_is_revn(gpu, 330); 354 } 355 356 static inline bool adreno_is_a330v2(const struct adreno_gpu *gpu) 357 { 358 return adreno_is_a330(gpu) && (adreno_patchid(gpu) > 0); 359 } 360 361 static inline int adreno_is_a405(const struct adreno_gpu *gpu) 362 { 363 return adreno_is_revn(gpu, 405); 364 } 365 366 static inline int adreno_is_a420(const struct adreno_gpu *gpu) 367 { 368 return adreno_is_revn(gpu, 420); 369 } 370 371 static inline int adreno_is_a430(const struct adreno_gpu *gpu) 372 { 373 return adreno_is_revn(gpu, 430); 374 } 375 376 static inline int adreno_is_a505(const struct adreno_gpu *gpu) 377 { 378 return adreno_is_revn(gpu, 505); 379 } 380 381 static inline int adreno_is_a506(const struct adreno_gpu *gpu) 382 { 383 return adreno_is_revn(gpu, 506); 384 } 385 386 static inline int adreno_is_a508(const struct adreno_gpu *gpu) 387 { 388 return adreno_is_revn(gpu, 508); 389 } 390 391 static inline int adreno_is_a509(const struct adreno_gpu *gpu) 392 { 393 return adreno_is_revn(gpu, 509); 394 } 395 396 static inline int adreno_is_a510(const struct adreno_gpu *gpu) 397 { 398 return adreno_is_revn(gpu, 510); 399 } 400 401 static inline int adreno_is_a512(const struct adreno_gpu *gpu) 402 { 403 return adreno_is_revn(gpu, 512); 404 } 405 406 static inline int adreno_is_a530(const struct adreno_gpu *gpu) 407 { 408 return adreno_is_revn(gpu, 530); 409 } 410 411 static inline int adreno_is_a540(const struct adreno_gpu *gpu) 412 { 413 return adreno_is_revn(gpu, 540); 414 } 415 416 static inline int adreno_is_a610(const struct adreno_gpu *gpu) 417 { 418 return adreno_is_revn(gpu, 610); 419 } 420 421 static inline int adreno_is_a612(const struct adreno_gpu *gpu) 422 { 423 return gpu->info->chip_ids[0] == 0x06010200; 424 } 425 426 static inline bool adreno_has_rgmu(const struct adreno_gpu *gpu) 427 { 428 return adreno_is_a612(gpu); 429 } 430 431 static inline int adreno_is_a618(const struct adreno_gpu *gpu) 432 { 433 return adreno_is_revn(gpu, 618); 434 } 435 436 static inline int adreno_is_a619(const struct adreno_gpu *gpu) 437 { 438 return adreno_is_revn(gpu, 619); 439 } 440 441 static inline int adreno_is_a619_holi(const struct adreno_gpu *gpu) 442 { 443 return adreno_is_a619(gpu) && adreno_has_gmu_wrapper(gpu); 444 } 445 446 static inline int adreno_is_a621(const struct adreno_gpu *gpu) 447 { 448 return gpu->info->chip_ids[0] == 0x06020100; 449 } 450 451 static inline int adreno_is_a623(const struct adreno_gpu *gpu) 452 { 453 return gpu->info->chip_ids[0] == 0x06020300; 454 } 455 456 static inline int adreno_is_a630(const struct adreno_gpu *gpu) 457 { 458 return adreno_is_revn(gpu, 630); 459 } 460 461 static inline int adreno_is_a640(const struct adreno_gpu *gpu) 462 { 463 return adreno_is_revn(gpu, 640); 464 } 465 466 static inline int adreno_is_a650(const struct adreno_gpu *gpu) 467 { 468 return adreno_is_revn(gpu, 650); 469 } 470 471 static inline int adreno_is_7c3(const struct adreno_gpu *gpu) 472 { 473 return gpu->info->chip_ids[0] == 0x06030500; 474 } 475 476 static inline int adreno_is_a660(const struct adreno_gpu *gpu) 477 { 478 return adreno_is_revn(gpu, 660); 479 } 480 481 static inline int adreno_is_a680(const struct adreno_gpu *gpu) 482 { 483 return adreno_is_revn(gpu, 680); 484 } 485 486 static inline int adreno_is_a663(const struct adreno_gpu *gpu) 487 { 488 return gpu->info->chip_ids[0] == 0x06060300; 489 } 490 491 static inline int adreno_is_a690(const struct adreno_gpu *gpu) 492 { 493 return gpu->info->chip_ids[0] == 0x06090000; 494 } 495 496 static inline int adreno_is_a702(const struct adreno_gpu *gpu) 497 { 498 return gpu->info->chip_ids[0] == 0x07000200; 499 } 500 501 static inline int adreno_is_a610_family(const struct adreno_gpu *gpu) 502 { 503 if (WARN_ON_ONCE(!gpu->info)) 504 return false; 505 return adreno_is_a610(gpu) || 506 adreno_is_a612(gpu) || 507 adreno_is_a702(gpu); 508 } 509 510 /* TODO: 615/616 */ 511 static inline int adreno_is_a615_family(const struct adreno_gpu *gpu) 512 { 513 return adreno_is_a618(gpu) || 514 adreno_is_a619(gpu); 515 } 516 517 static inline int adreno_is_a630_family(const struct adreno_gpu *gpu) 518 { 519 if (WARN_ON_ONCE(!gpu->info)) 520 return false; 521 return gpu->info->family == ADRENO_6XX_GEN1; 522 } 523 524 static inline int adreno_is_a660_family(const struct adreno_gpu *gpu) 525 { 526 if (WARN_ON_ONCE(!gpu->info)) 527 return false; 528 return gpu->info->family == ADRENO_6XX_GEN4; 529 } 530 531 /* check for a650, a660, or any derivatives */ 532 static inline int adreno_is_a650_family(const struct adreno_gpu *gpu) 533 { 534 if (WARN_ON_ONCE(!gpu->info)) 535 return false; 536 return gpu->info->family == ADRENO_6XX_GEN3 || 537 gpu->info->family == ADRENO_6XX_GEN4; 538 } 539 540 static inline int adreno_is_a640_family(const struct adreno_gpu *gpu) 541 { 542 if (WARN_ON_ONCE(!gpu->info)) 543 return false; 544 return gpu->info->family == ADRENO_6XX_GEN2; 545 } 546 547 static inline int adreno_is_a730(struct adreno_gpu *gpu) 548 { 549 return gpu->info->chip_ids[0] == 0x07030001; 550 } 551 552 static inline int adreno_is_a740(struct adreno_gpu *gpu) 553 { 554 return gpu->info->chip_ids[0] == 0x43050a01; 555 } 556 557 static inline int adreno_is_a750(struct adreno_gpu *gpu) 558 { 559 return gpu->info->chip_ids[0] == 0x43051401; 560 } 561 562 static inline int adreno_is_x185(struct adreno_gpu *gpu) 563 { 564 return gpu->info->chip_ids[0] == 0x43050c01; 565 } 566 567 static inline int adreno_is_a722(struct adreno_gpu *gpu) 568 { 569 return gpu->info->chip_ids[0] == 0x43020100; 570 } 571 572 static inline int adreno_is_a740_family(struct adreno_gpu *gpu) 573 { 574 if (WARN_ON_ONCE(!gpu->info)) 575 return false; 576 return gpu->info->family == ADRENO_7XX_GEN2 || 577 gpu->info->family == ADRENO_7XX_GEN3; 578 } 579 580 static inline int adreno_is_a750_family(struct adreno_gpu *gpu) 581 { 582 return gpu->info->family == ADRENO_7XX_GEN3; 583 } 584 585 static inline int adreno_is_a6xx(struct adreno_gpu *gpu) 586 { 587 return (gpu->info->family >= ADRENO_6XX_GEN1) && (gpu->info->family < ADRENO_7XX_GEN1); 588 } 589 590 static inline int adreno_is_a7xx(struct adreno_gpu *gpu) 591 { 592 /* Update with non-fake (i.e. non-A702) Gen 7 GPUs */ 593 return gpu->info->family == ADRENO_7XX_GEN1 || 594 adreno_is_a740_family(gpu); 595 } 596 597 static inline int adreno_is_a8xx(struct adreno_gpu *gpu) 598 { 599 return gpu->info->family >= ADRENO_8XX_GEN1; 600 } 601 602 static inline int adreno_is_a810(struct adreno_gpu *gpu) 603 { 604 return gpu->info->chip_ids[0] == 0x44010000; 605 } 606 607 static inline int adreno_is_x285_family(const struct adreno_gpu *gpu) 608 { 609 if (WARN_ON_ONCE(!gpu->info)) 610 return false; 611 return gpu->info->chip_ids[0] == 0x44060000 || 612 gpu->info->chip_ids[0] == 0x44070001; 613 } 614 615 static inline int adreno_is_a830(struct adreno_gpu *gpu) 616 { 617 return gpu->info->chip_ids[0] == 0x44050001; 618 } 619 620 static inline int adreno_is_a840(struct adreno_gpu *gpu) 621 { 622 return gpu->info->chip_ids[0] == 0x44050a01; 623 } 624 625 static inline int adreno_is_a845(struct adreno_gpu *gpu) 626 { 627 return gpu->info->chip_ids[0] == 0x44041400; 628 } 629 630 static inline int adreno_is_a850(struct adreno_gpu *gpu) 631 { 632 return gpu->info->chip_ids[0] == 0x44051401; 633 } 634 635 static inline int adreno_is_a850_family(struct adreno_gpu *gpu) 636 { 637 return adreno_is_a845(gpu) || 638 adreno_is_a850(gpu); 639 } 640 641 /* Put vm_start above 32b to catch issues with not setting xyz_BASE_HI */ 642 #define ADRENO_VM_START 0x100000000ULL 643 u64 adreno_private_vm_size(struct msm_gpu *gpu); 644 int adreno_get_param(struct msm_gpu *gpu, struct msm_context *ctx, 645 uint32_t param, uint64_t *value, uint32_t *len); 646 int adreno_set_param(struct msm_gpu *gpu, struct msm_context *ctx, 647 uint32_t param, uint64_t value, uint32_t len); 648 const struct firmware *adreno_request_fw(struct adreno_gpu *adreno_gpu, 649 const char *fwname); 650 struct drm_gem_object *adreno_fw_create_bo(struct msm_gpu *gpu, 651 const struct firmware *fw, u64 *iova); 652 int adreno_hw_init(struct msm_gpu *gpu); 653 void adreno_recover(struct msm_gpu *gpu); 654 void adreno_flush(struct msm_gpu *gpu, struct msm_ringbuffer *ring, u32 reg); 655 bool adreno_idle(struct msm_gpu *gpu, struct msm_ringbuffer *ring); 656 #if defined(CONFIG_DEBUG_FS) || defined(CONFIG_DEV_COREDUMP) 657 void adreno_show(struct msm_gpu *gpu, struct msm_gpu_state *state, 658 struct drm_printer *p); 659 #endif 660 void adreno_dump_info(struct msm_gpu *gpu); 661 void adreno_dump(struct msm_gpu *gpu); 662 void adreno_wait_ring(struct msm_ringbuffer *ring, uint32_t ndwords); 663 struct msm_ringbuffer *adreno_active_ring(struct msm_gpu *gpu); 664 665 int adreno_gpu_ocmem_init(struct device *dev, struct adreno_gpu *adreno_gpu, 666 struct adreno_ocmem *ocmem); 667 void adreno_gpu_ocmem_cleanup(struct adreno_ocmem *ocmem); 668 669 int adreno_gpu_init(struct drm_device *drm, struct platform_device *pdev, 670 struct adreno_gpu *gpu, const struct adreno_gpu_funcs *funcs, 671 int nr_rings); 672 void adreno_gpu_cleanup(struct adreno_gpu *gpu); 673 int adreno_load_fw(struct adreno_gpu *adreno_gpu); 674 675 void adreno_gpu_state_destroy(struct msm_gpu_state *state); 676 677 int adreno_gpu_state_get(struct msm_gpu *gpu, struct msm_gpu_state *state); 678 int adreno_gpu_state_put(struct msm_gpu_state *state); 679 void adreno_show_object(struct drm_printer *p, void **ptr, int len, 680 bool *encoded); 681 682 /* 683 * Common helper function to initialize the default address space for arm-smmu 684 * attached targets 685 */ 686 struct drm_gpuvm * 687 adreno_create_vm(struct msm_gpu *gpu, 688 struct platform_device *pdev); 689 690 struct drm_gpuvm * 691 adreno_iommu_create_vm(struct msm_gpu *gpu, 692 struct platform_device *pdev, 693 unsigned long quirks); 694 695 int adreno_fault_handler(struct msm_gpu *gpu, unsigned long iova, int flags, 696 struct adreno_smmu_fault_info *info, const char *block, 697 u32 scratch[4]); 698 699 void adreno_check_and_reenable_stall(struct adreno_gpu *gpu); 700 701 int adreno_read_speedbin(struct device *dev, u32 *speedbin); 702 703 /* 704 * For a5xx and a6xx targets load the zap shader that is used to pull the GPU 705 * out of secure mode 706 */ 707 int adreno_zap_shader_load(struct msm_gpu *gpu, u32 pasid); 708 709 /* ringbuffer helpers (the parts that are adreno specific) */ 710 711 static inline void 712 OUT_PKT0(struct msm_ringbuffer *ring, uint16_t regindx, uint16_t cnt) 713 { 714 adreno_wait_ring(ring, cnt+1); 715 OUT_RING(ring, CP_TYPE0_PKT | ((cnt-1) << 16) | (regindx & 0x7FFF)); 716 } 717 718 /* no-op packet: */ 719 static inline void 720 OUT_PKT2(struct msm_ringbuffer *ring) 721 { 722 adreno_wait_ring(ring, 1); 723 OUT_RING(ring, CP_TYPE2_PKT); 724 } 725 726 static inline void 727 OUT_PKT3(struct msm_ringbuffer *ring, uint8_t opcode, uint16_t cnt) 728 { 729 adreno_wait_ring(ring, cnt+1); 730 OUT_RING(ring, CP_TYPE3_PKT | ((cnt-1) << 16) | ((opcode & 0xFF) << 8)); 731 } 732 733 static inline u32 PM4_PARITY(u32 val) 734 { 735 return (0x9669 >> (0xF & (val ^ 736 (val >> 4) ^ (val >> 8) ^ (val >> 12) ^ 737 (val >> 16) ^ ((val) >> 20) ^ (val >> 24) ^ 738 (val >> 28)))) & 1; 739 } 740 741 /* Maximum number of values that can be executed for one opcode */ 742 #define TYPE4_MAX_PAYLOAD 127 743 744 #define PKT4(_reg, _cnt) \ 745 (CP_TYPE4_PKT | ((_cnt) << 0) | (PM4_PARITY((_cnt)) << 7) | \ 746 (((_reg) & 0x3FFFF) << 8) | (PM4_PARITY((_reg)) << 27)) 747 748 static inline void 749 OUT_PKT4(struct msm_ringbuffer *ring, uint16_t regindx, uint16_t cnt) 750 { 751 adreno_wait_ring(ring, cnt + 1); 752 OUT_RING(ring, PKT4(regindx, cnt)); 753 } 754 755 #define PKT7(opcode, cnt) \ 756 (CP_TYPE7_PKT | (cnt << 0) | (PM4_PARITY(cnt) << 15) | \ 757 ((opcode & 0x7F) << 16) | (PM4_PARITY(opcode) << 23)) 758 759 static inline void 760 OUT_PKT7(struct msm_ringbuffer *ring, uint8_t opcode, uint16_t cnt) 761 { 762 adreno_wait_ring(ring, cnt + 1); 763 OUT_RING(ring, PKT7(opcode, cnt)); 764 } 765 766 static inline uint32_t get_wptr(struct msm_ringbuffer *ring) 767 { 768 return (ring->cur - ring->start) % (MSM_GPU_RINGBUFFER_SZ >> 2); 769 } 770 771 /* 772 * Given a register and a count, return a value to program into 773 * REG_CP_PROTECT_REG(n) - this will block both reads and writes for _len 774 * registers starting at _reg. 775 * 776 * The register base needs to be a multiple of the length. If it is not, the 777 * hardware will quietly mask off the bits for you and shift the size. For 778 * example, if you intend the protection to start at 0x07 for a length of 4 779 * (0x07-0x0A) the hardware will actually protect (0x04-0x07) which might 780 * expose registers you intended to protect! 781 */ 782 #define ADRENO_PROTECT_RW(_reg, _len) \ 783 ((1 << 30) | (1 << 29) | \ 784 ((ilog2((_len)) & 0x1F) << 24) | (((_reg) << 2) & 0xFFFFF)) 785 786 /* 787 * Same as above, but allow reads over the range. For areas of mixed use (such 788 * as performance counters) this allows us to protect a much larger range with a 789 * single register 790 */ 791 #define ADRENO_PROTECT_RDONLY(_reg, _len) \ 792 ((1 << 29) \ 793 ((ilog2((_len)) & 0x1F) << 24) | (((_reg) << 2) & 0xFFFFF)) 794 795 796 #define gpu_poll_timeout(gpu, addr, val, cond, interval, timeout) \ 797 readl_poll_timeout((gpu)->mmio + ((addr) << 2), val, cond, \ 798 interval, timeout) 799 800 #endif /* __ADRENO_GPU_H__ */ 801