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 uint16_t speedbin; 208 const struct adreno_gpu_funcs *funcs; 209 210 struct completion fault_coredump_done; 211 212 /* interesting register offsets to dump: */ 213 const unsigned int *registers; 214 215 /* 216 * Are we loading fw from legacy path? Prior to addition 217 * of gpu firmware to linux-firmware, the fw files were 218 * placed in toplevel firmware directory, following qcom's 219 * android kernel. But linux-firmware preferred they be 220 * placed in a 'qcom' subdirectory. 221 * 222 * For backwards compatibility, we try first to load from 223 * the new path, using request_firmware_direct() to avoid 224 * any potential timeout waiting for usermode helper, then 225 * fall back to the old path (with direct load). And 226 * finally fall back to request_firmware() with the new 227 * path to allow the usermode helper. 228 */ 229 enum { 230 FW_LOCATION_UNKNOWN = 0, 231 FW_LOCATION_NEW, /* /lib/firmware/qcom/$fwfile */ 232 FW_LOCATION_LEGACY, /* /lib/firmware/$fwfile */ 233 FW_LOCATION_HELPER, 234 } fwloc; 235 236 /* firmware: */ 237 const struct firmware *fw[ADRENO_FW_MAX]; 238 239 /* 240 * The migration to the central UBWC config db is still in flight - keep 241 * a copy containing some local fixups until that's done. 242 */ 243 const struct qcom_ubwc_cfg_data *ubwc_config; 244 struct qcom_ubwc_cfg_data _ubwc_config; 245 246 /* 247 * Register offsets are different between some GPUs. 248 * GPU specific offsets will be exported by GPU specific 249 * code (a3xx_gpu.c) and stored in this common location. 250 */ 251 const unsigned int *reg_offsets; 252 bool gmu_is_wrapper; 253 254 bool has_ray_tracing; 255 256 u64 uche_trap_base; 257 }; 258 #define to_adreno_gpu(x) container_of(x, struct adreno_gpu, base) 259 260 struct adreno_ocmem { 261 struct ocmem *ocmem; 262 unsigned long base; 263 void *hdl; 264 }; 265 266 /* platform config data (ie. from DT, or pdata) */ 267 struct adreno_platform_config { 268 uint32_t chip_id; 269 const struct adreno_info *info; 270 }; 271 272 #define ADRENO_IDLE_TIMEOUT msecs_to_jiffies(1000) 273 274 #define spin_until(X) ({ \ 275 int __ret = -ETIMEDOUT; \ 276 unsigned long __t = jiffies + ADRENO_IDLE_TIMEOUT; \ 277 do { \ 278 if (X) { \ 279 __ret = 0; \ 280 break; \ 281 } \ 282 } while (time_before(jiffies, __t)); \ 283 __ret; \ 284 }) 285 286 static inline uint8_t adreno_patchid(const struct adreno_gpu *gpu) 287 { 288 /* It is probably ok to assume legacy "adreno_rev" format 289 * for all a6xx devices, but probably best to limit this 290 * to older things. 291 */ 292 WARN_ON_ONCE(gpu->info->family >= ADRENO_6XX_GEN1); 293 return gpu->chip_id & 0xff; 294 } 295 296 static inline bool adreno_is_revn(const struct adreno_gpu *gpu, uint32_t revn) 297 { 298 if (WARN_ON_ONCE(!gpu->info)) 299 return false; 300 return gpu->info->revn == revn; 301 } 302 303 static inline bool adreno_has_gmu_wrapper(const struct adreno_gpu *gpu) 304 { 305 return gpu->gmu_is_wrapper; 306 } 307 308 static inline bool adreno_is_a2xx(const struct adreno_gpu *gpu) 309 { 310 if (WARN_ON_ONCE(!gpu->info)) 311 return false; 312 return gpu->info->family <= ADRENO_2XX_GEN2; 313 } 314 315 static inline bool adreno_is_a20x(const struct adreno_gpu *gpu) 316 { 317 if (WARN_ON_ONCE(!gpu->info)) 318 return false; 319 return gpu->info->family == ADRENO_2XX_GEN1; 320 } 321 322 static inline bool adreno_is_a225(const struct adreno_gpu *gpu) 323 { 324 return adreno_is_revn(gpu, 225); 325 } 326 327 static inline bool adreno_is_a305(const struct adreno_gpu *gpu) 328 { 329 return adreno_is_revn(gpu, 305); 330 } 331 332 static inline bool adreno_is_a305b(const struct adreno_gpu *gpu) 333 { 334 return gpu->info->chip_ids[0] == 0x03000512; 335 } 336 337 static inline bool adreno_is_a306(const struct adreno_gpu *gpu) 338 { 339 /* yes, 307, because a305c is 306 */ 340 return adreno_is_revn(gpu, 307); 341 } 342 343 static inline bool adreno_is_a306a(const struct adreno_gpu *gpu) 344 { 345 /* a306a (marketing name is a308) */ 346 return adreno_is_revn(gpu, 308); 347 } 348 349 static inline bool adreno_is_a320(const struct adreno_gpu *gpu) 350 { 351 return adreno_is_revn(gpu, 320); 352 } 353 354 static inline bool adreno_is_a330(const struct adreno_gpu *gpu) 355 { 356 return adreno_is_revn(gpu, 330); 357 } 358 359 static inline bool adreno_is_a330v2(const struct adreno_gpu *gpu) 360 { 361 return adreno_is_a330(gpu) && (adreno_patchid(gpu) > 0); 362 } 363 364 static inline int adreno_is_a405(const struct adreno_gpu *gpu) 365 { 366 return adreno_is_revn(gpu, 405); 367 } 368 369 static inline int adreno_is_a420(const struct adreno_gpu *gpu) 370 { 371 return adreno_is_revn(gpu, 420); 372 } 373 374 static inline int adreno_is_a430(const struct adreno_gpu *gpu) 375 { 376 return adreno_is_revn(gpu, 430); 377 } 378 379 static inline int adreno_is_a505(const struct adreno_gpu *gpu) 380 { 381 return adreno_is_revn(gpu, 505); 382 } 383 384 static inline int adreno_is_a506(const struct adreno_gpu *gpu) 385 { 386 return adreno_is_revn(gpu, 506); 387 } 388 389 static inline int adreno_is_a508(const struct adreno_gpu *gpu) 390 { 391 return adreno_is_revn(gpu, 508); 392 } 393 394 static inline int adreno_is_a509(const struct adreno_gpu *gpu) 395 { 396 return adreno_is_revn(gpu, 509); 397 } 398 399 static inline int adreno_is_a510(const struct adreno_gpu *gpu) 400 { 401 return adreno_is_revn(gpu, 510); 402 } 403 404 static inline int adreno_is_a512(const struct adreno_gpu *gpu) 405 { 406 return adreno_is_revn(gpu, 512); 407 } 408 409 static inline int adreno_is_a530(const struct adreno_gpu *gpu) 410 { 411 return adreno_is_revn(gpu, 530); 412 } 413 414 static inline int adreno_is_a540(const struct adreno_gpu *gpu) 415 { 416 return adreno_is_revn(gpu, 540); 417 } 418 419 static inline int adreno_is_a610(const struct adreno_gpu *gpu) 420 { 421 return adreno_is_revn(gpu, 610); 422 } 423 424 static inline int adreno_is_a612(const struct adreno_gpu *gpu) 425 { 426 return gpu->info->chip_ids[0] == 0x06010200; 427 } 428 429 static inline bool adreno_has_rgmu(const struct adreno_gpu *gpu) 430 { 431 return adreno_is_a612(gpu); 432 } 433 434 static inline int adreno_is_a618(const struct adreno_gpu *gpu) 435 { 436 return adreno_is_revn(gpu, 618); 437 } 438 439 static inline int adreno_is_a619(const struct adreno_gpu *gpu) 440 { 441 return adreno_is_revn(gpu, 619); 442 } 443 444 static inline int adreno_is_a619_holi(const struct adreno_gpu *gpu) 445 { 446 return adreno_is_a619(gpu) && adreno_has_gmu_wrapper(gpu); 447 } 448 449 static inline int adreno_is_a621(const struct adreno_gpu *gpu) 450 { 451 return gpu->info->chip_ids[0] == 0x06020100; 452 } 453 454 static inline int adreno_is_a623(const struct adreno_gpu *gpu) 455 { 456 return gpu->info->chip_ids[0] == 0x06020300; 457 } 458 459 static inline int adreno_is_a630(const struct adreno_gpu *gpu) 460 { 461 return adreno_is_revn(gpu, 630); 462 } 463 464 static inline int adreno_is_a640(const struct adreno_gpu *gpu) 465 { 466 return adreno_is_revn(gpu, 640); 467 } 468 469 static inline int adreno_is_a650(const struct adreno_gpu *gpu) 470 { 471 return adreno_is_revn(gpu, 650); 472 } 473 474 static inline int adreno_is_7c3(const struct adreno_gpu *gpu) 475 { 476 return gpu->info->chip_ids[0] == 0x06030500; 477 } 478 479 static inline int adreno_is_a660(const struct adreno_gpu *gpu) 480 { 481 return adreno_is_revn(gpu, 660); 482 } 483 484 static inline int adreno_is_a680(const struct adreno_gpu *gpu) 485 { 486 return adreno_is_revn(gpu, 680); 487 } 488 489 static inline int adreno_is_a663(const struct adreno_gpu *gpu) 490 { 491 return gpu->info->chip_ids[0] == 0x06060300; 492 } 493 494 static inline int adreno_is_a690(const struct adreno_gpu *gpu) 495 { 496 return gpu->info->chip_ids[0] == 0x06090000; 497 } 498 499 static inline int adreno_is_a702(const struct adreno_gpu *gpu) 500 { 501 return gpu->info->chip_ids[0] == 0x07000200; 502 } 503 504 static inline int adreno_is_a610_family(const struct adreno_gpu *gpu) 505 { 506 if (WARN_ON_ONCE(!gpu->info)) 507 return false; 508 return adreno_is_a610(gpu) || 509 adreno_is_a612(gpu) || 510 adreno_is_a702(gpu); 511 } 512 513 /* TODO: 615/616 */ 514 static inline int adreno_is_a615_family(const struct adreno_gpu *gpu) 515 { 516 return adreno_is_a618(gpu) || 517 adreno_is_a619(gpu); 518 } 519 520 static inline int adreno_is_a630_family(const struct adreno_gpu *gpu) 521 { 522 if (WARN_ON_ONCE(!gpu->info)) 523 return false; 524 return gpu->info->family == ADRENO_6XX_GEN1; 525 } 526 527 static inline int adreno_is_a660_family(const struct adreno_gpu *gpu) 528 { 529 if (WARN_ON_ONCE(!gpu->info)) 530 return false; 531 return gpu->info->family == ADRENO_6XX_GEN4; 532 } 533 534 /* check for a650, a660, or any derivatives */ 535 static inline int adreno_is_a650_family(const struct adreno_gpu *gpu) 536 { 537 if (WARN_ON_ONCE(!gpu->info)) 538 return false; 539 return gpu->info->family == ADRENO_6XX_GEN3 || 540 gpu->info->family == ADRENO_6XX_GEN4; 541 } 542 543 static inline int adreno_is_a640_family(const struct adreno_gpu *gpu) 544 { 545 if (WARN_ON_ONCE(!gpu->info)) 546 return false; 547 return gpu->info->family == ADRENO_6XX_GEN2; 548 } 549 550 static inline int adreno_is_a730(struct adreno_gpu *gpu) 551 { 552 return gpu->info->chip_ids[0] == 0x07030001; 553 } 554 555 static inline int adreno_is_a740(struct adreno_gpu *gpu) 556 { 557 return gpu->info->chip_ids[0] == 0x43050a01; 558 } 559 560 static inline int adreno_is_a750(struct adreno_gpu *gpu) 561 { 562 return gpu->info->chip_ids[0] == 0x43051401; 563 } 564 565 static inline int adreno_is_x185(struct adreno_gpu *gpu) 566 { 567 return gpu->info->chip_ids[0] == 0x43050c01; 568 } 569 570 static inline int adreno_is_a740_family(struct adreno_gpu *gpu) 571 { 572 if (WARN_ON_ONCE(!gpu->info)) 573 return false; 574 return gpu->info->family == ADRENO_7XX_GEN2 || 575 gpu->info->family == ADRENO_7XX_GEN3; 576 } 577 578 static inline int adreno_is_a750_family(struct adreno_gpu *gpu) 579 { 580 return gpu->info->family == ADRENO_7XX_GEN3; 581 } 582 583 static inline int adreno_is_a7xx(struct adreno_gpu *gpu) 584 { 585 /* Update with non-fake (i.e. non-A702) Gen 7 GPUs */ 586 return gpu->info->family == ADRENO_7XX_GEN1 || 587 adreno_is_a740_family(gpu); 588 } 589 590 static inline int adreno_is_a8xx(struct adreno_gpu *gpu) 591 { 592 return gpu->info->family >= ADRENO_8XX_GEN1; 593 } 594 595 static inline int adreno_is_x285(struct adreno_gpu *gpu) 596 { 597 return gpu->info->chip_ids[0] == 0x44070001; 598 } 599 600 static inline int adreno_is_a840(struct adreno_gpu *gpu) 601 { 602 return gpu->info->chip_ids[0] == 0x44050a01; 603 } 604 605 /* Put vm_start above 32b to catch issues with not setting xyz_BASE_HI */ 606 #define ADRENO_VM_START 0x100000000ULL 607 u64 adreno_private_vm_size(struct msm_gpu *gpu); 608 int adreno_get_param(struct msm_gpu *gpu, struct msm_context *ctx, 609 uint32_t param, uint64_t *value, uint32_t *len); 610 int adreno_set_param(struct msm_gpu *gpu, struct msm_context *ctx, 611 uint32_t param, uint64_t value, uint32_t len); 612 const struct firmware *adreno_request_fw(struct adreno_gpu *adreno_gpu, 613 const char *fwname); 614 struct drm_gem_object *adreno_fw_create_bo(struct msm_gpu *gpu, 615 const struct firmware *fw, u64 *iova); 616 int adreno_hw_init(struct msm_gpu *gpu); 617 void adreno_recover(struct msm_gpu *gpu); 618 void adreno_flush(struct msm_gpu *gpu, struct msm_ringbuffer *ring, u32 reg); 619 bool adreno_idle(struct msm_gpu *gpu, struct msm_ringbuffer *ring); 620 #if defined(CONFIG_DEBUG_FS) || defined(CONFIG_DEV_COREDUMP) 621 void adreno_show(struct msm_gpu *gpu, struct msm_gpu_state *state, 622 struct drm_printer *p); 623 #endif 624 void adreno_dump_info(struct msm_gpu *gpu); 625 void adreno_dump(struct msm_gpu *gpu); 626 void adreno_wait_ring(struct msm_ringbuffer *ring, uint32_t ndwords); 627 struct msm_ringbuffer *adreno_active_ring(struct msm_gpu *gpu); 628 629 int adreno_gpu_ocmem_init(struct device *dev, struct adreno_gpu *adreno_gpu, 630 struct adreno_ocmem *ocmem); 631 void adreno_gpu_ocmem_cleanup(struct adreno_ocmem *ocmem); 632 633 int adreno_gpu_init(struct drm_device *drm, struct platform_device *pdev, 634 struct adreno_gpu *gpu, const struct adreno_gpu_funcs *funcs, 635 int nr_rings); 636 void adreno_gpu_cleanup(struct adreno_gpu *gpu); 637 int adreno_load_fw(struct adreno_gpu *adreno_gpu); 638 639 void adreno_gpu_state_destroy(struct msm_gpu_state *state); 640 641 int adreno_gpu_state_get(struct msm_gpu *gpu, struct msm_gpu_state *state); 642 int adreno_gpu_state_put(struct msm_gpu_state *state); 643 void adreno_show_object(struct drm_printer *p, void **ptr, int len, 644 bool *encoded); 645 646 /* 647 * Common helper function to initialize the default address space for arm-smmu 648 * attached targets 649 */ 650 struct drm_gpuvm * 651 adreno_create_vm(struct msm_gpu *gpu, 652 struct platform_device *pdev); 653 654 struct drm_gpuvm * 655 adreno_iommu_create_vm(struct msm_gpu *gpu, 656 struct platform_device *pdev, 657 unsigned long quirks); 658 659 int adreno_fault_handler(struct msm_gpu *gpu, unsigned long iova, int flags, 660 struct adreno_smmu_fault_info *info, const char *block, 661 u32 scratch[4]); 662 663 void adreno_check_and_reenable_stall(struct adreno_gpu *gpu); 664 665 int adreno_read_speedbin(struct device *dev, u32 *speedbin); 666 667 /* 668 * For a5xx and a6xx targets load the zap shader that is used to pull the GPU 669 * out of secure mode 670 */ 671 int adreno_zap_shader_load(struct msm_gpu *gpu, u32 pasid); 672 673 /* ringbuffer helpers (the parts that are adreno specific) */ 674 675 static inline void 676 OUT_PKT0(struct msm_ringbuffer *ring, uint16_t regindx, uint16_t cnt) 677 { 678 adreno_wait_ring(ring, cnt+1); 679 OUT_RING(ring, CP_TYPE0_PKT | ((cnt-1) << 16) | (regindx & 0x7FFF)); 680 } 681 682 /* no-op packet: */ 683 static inline void 684 OUT_PKT2(struct msm_ringbuffer *ring) 685 { 686 adreno_wait_ring(ring, 1); 687 OUT_RING(ring, CP_TYPE2_PKT); 688 } 689 690 static inline void 691 OUT_PKT3(struct msm_ringbuffer *ring, uint8_t opcode, uint16_t cnt) 692 { 693 adreno_wait_ring(ring, cnt+1); 694 OUT_RING(ring, CP_TYPE3_PKT | ((cnt-1) << 16) | ((opcode & 0xFF) << 8)); 695 } 696 697 static inline u32 PM4_PARITY(u32 val) 698 { 699 return (0x9669 >> (0xF & (val ^ 700 (val >> 4) ^ (val >> 8) ^ (val >> 12) ^ 701 (val >> 16) ^ ((val) >> 20) ^ (val >> 24) ^ 702 (val >> 28)))) & 1; 703 } 704 705 /* Maximum number of values that can be executed for one opcode */ 706 #define TYPE4_MAX_PAYLOAD 127 707 708 #define PKT4(_reg, _cnt) \ 709 (CP_TYPE4_PKT | ((_cnt) << 0) | (PM4_PARITY((_cnt)) << 7) | \ 710 (((_reg) & 0x3FFFF) << 8) | (PM4_PARITY((_reg)) << 27)) 711 712 static inline void 713 OUT_PKT4(struct msm_ringbuffer *ring, uint16_t regindx, uint16_t cnt) 714 { 715 adreno_wait_ring(ring, cnt + 1); 716 OUT_RING(ring, PKT4(regindx, cnt)); 717 } 718 719 #define PKT7(opcode, cnt) \ 720 (CP_TYPE7_PKT | (cnt << 0) | (PM4_PARITY(cnt) << 15) | \ 721 ((opcode & 0x7F) << 16) | (PM4_PARITY(opcode) << 23)) 722 723 static inline void 724 OUT_PKT7(struct msm_ringbuffer *ring, uint8_t opcode, uint16_t cnt) 725 { 726 adreno_wait_ring(ring, cnt + 1); 727 OUT_RING(ring, PKT7(opcode, cnt)); 728 } 729 730 static inline uint32_t get_wptr(struct msm_ringbuffer *ring) 731 { 732 return (ring->cur - ring->start) % (MSM_GPU_RINGBUFFER_SZ >> 2); 733 } 734 735 /* 736 * Given a register and a count, return a value to program into 737 * REG_CP_PROTECT_REG(n) - this will block both reads and writes for _len 738 * registers starting at _reg. 739 * 740 * The register base needs to be a multiple of the length. If it is not, the 741 * hardware will quietly mask off the bits for you and shift the size. For 742 * example, if you intend the protection to start at 0x07 for a length of 4 743 * (0x07-0x0A) the hardware will actually protect (0x04-0x07) which might 744 * expose registers you intended to protect! 745 */ 746 #define ADRENO_PROTECT_RW(_reg, _len) \ 747 ((1 << 30) | (1 << 29) | \ 748 ((ilog2((_len)) & 0x1F) << 24) | (((_reg) << 2) & 0xFFFFF)) 749 750 /* 751 * Same as above, but allow reads over the range. For areas of mixed use (such 752 * as performance counters) this allows us to protect a much larger range with a 753 * single register 754 */ 755 #define ADRENO_PROTECT_RDONLY(_reg, _len) \ 756 ((1 << 29) \ 757 ((ilog2((_len)) & 0x1F) << 24) | (((_reg) << 2) & 0xFFFFF)) 758 759 760 #define gpu_poll_timeout(gpu, addr, val, cond, interval, timeout) \ 761 readl_poll_timeout((gpu)->mmio + ((addr) << 2), val, cond, \ 762 interval, timeout) 763 764 #endif /* __ADRENO_GPU_H__ */ 765