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