1 /* 2 * Copyright © 2013 Intel Corporation 3 * 4 * Permission is hereby granted, free of charge, to any person obtaining a 5 * copy of this software and associated documentation files (the "Software"), 6 * to deal in the Software without restriction, including without limitation 7 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 * and/or sell copies of the Software, and to permit persons to whom the 9 * Software is furnished to do so, subject to the following conditions: 10 * 11 * The above copyright notice and this permission notice (including the next 12 * paragraph) shall be included in all copies or substantial portions of the 13 * Software. 14 * 15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 21 * IN THE SOFTWARE. 22 */ 23 24 #include <drm/drm_managed.h> 25 #include <linux/pm_runtime.h> 26 27 #include "gt/intel_engine_regs.h" 28 #include "gt/intel_gt_regs.h" 29 30 #include "i915_drv.h" 31 #include "i915_iosf_mbi.h" 32 #include "i915_reg.h" 33 #include "i915_trace.h" 34 #include "i915_vgpu.h" 35 36 #define FORCEWAKE_ACK_TIMEOUT_MS 50 37 #define GT_FIFO_TIMEOUT_MS 10 38 39 #define __raw_posting_read(...) ((void)__raw_uncore_read32(__VA_ARGS__)) 40 41 static void 42 fw_domains_get(struct intel_uncore *uncore, enum forcewake_domains fw_domains) 43 { 44 uncore->fw_get_funcs->force_wake_get(uncore, fw_domains); 45 } 46 47 void 48 intel_uncore_mmio_debug_init_early(struct drm_i915_private *i915) 49 { 50 spin_lock_init(&i915->mmio_debug.lock); 51 i915->mmio_debug.unclaimed_mmio_check = 1; 52 53 i915->uncore.debug = &i915->mmio_debug; 54 } 55 56 static void mmio_debug_suspend(struct intel_uncore *uncore) 57 { 58 if (!uncore->debug) 59 return; 60 61 spin_lock(&uncore->debug->lock); 62 63 /* Save and disable mmio debugging for the user bypass */ 64 if (!uncore->debug->suspend_count++) { 65 uncore->debug->saved_mmio_check = uncore->debug->unclaimed_mmio_check; 66 uncore->debug->unclaimed_mmio_check = 0; 67 } 68 69 spin_unlock(&uncore->debug->lock); 70 } 71 72 static bool check_for_unclaimed_mmio(struct intel_uncore *uncore); 73 74 static void mmio_debug_resume(struct intel_uncore *uncore) 75 { 76 if (!uncore->debug) 77 return; 78 79 spin_lock(&uncore->debug->lock); 80 81 if (!--uncore->debug->suspend_count) 82 uncore->debug->unclaimed_mmio_check = uncore->debug->saved_mmio_check; 83 84 if (check_for_unclaimed_mmio(uncore)) 85 drm_info(&uncore->i915->drm, 86 "Invalid mmio detected during user access\n"); 87 88 spin_unlock(&uncore->debug->lock); 89 } 90 91 static const char * const forcewake_domain_names[] = { 92 "render", 93 "gt", 94 "media", 95 "vdbox0", 96 "vdbox1", 97 "vdbox2", 98 "vdbox3", 99 "vdbox4", 100 "vdbox5", 101 "vdbox6", 102 "vdbox7", 103 "vebox0", 104 "vebox1", 105 "vebox2", 106 "vebox3", 107 "gsc", 108 }; 109 110 const char * 111 intel_uncore_forcewake_domain_to_str(const enum forcewake_domain_id id) 112 { 113 BUILD_BUG_ON(ARRAY_SIZE(forcewake_domain_names) != FW_DOMAIN_ID_COUNT); 114 115 if (id >= 0 && id < FW_DOMAIN_ID_COUNT) 116 return forcewake_domain_names[id]; 117 118 WARN_ON(id); 119 120 return "unknown"; 121 } 122 123 #define fw_ack(d) readl((d)->reg_ack) 124 #define fw_set(d, val) writel(_MASKED_BIT_ENABLE((val)), (d)->reg_set) 125 #define fw_clear(d, val) writel(_MASKED_BIT_DISABLE((val)), (d)->reg_set) 126 127 static inline void 128 fw_domain_reset(const struct intel_uncore_forcewake_domain *d) 129 { 130 /* 131 * We don't really know if the powerwell for the forcewake domain we are 132 * trying to reset here does exist at this point (engines could be fused 133 * off in ICL+), so no waiting for acks 134 */ 135 /* WaRsClearFWBitsAtReset */ 136 if (GRAPHICS_VER(d->uncore->i915) >= 12) 137 fw_clear(d, 0xefff); 138 else 139 fw_clear(d, 0xffff); 140 } 141 142 static inline void 143 fw_domain_arm_timer(struct intel_uncore_forcewake_domain *d) 144 { 145 GEM_BUG_ON(d->uncore->fw_domains_timer & d->mask); 146 d->uncore->fw_domains_timer |= d->mask; 147 d->wake_count++; 148 hrtimer_start_range_ns(&d->timer, 149 NSEC_PER_MSEC, 150 NSEC_PER_MSEC, 151 HRTIMER_MODE_REL); 152 } 153 154 static inline int 155 __wait_for_ack(const struct intel_uncore_forcewake_domain *d, 156 const u32 ack, 157 const u32 value) 158 { 159 return wait_for_atomic((fw_ack(d) & ack) == value, 160 FORCEWAKE_ACK_TIMEOUT_MS); 161 } 162 163 static inline int 164 wait_ack_clear(const struct intel_uncore_forcewake_domain *d, 165 const u32 ack) 166 { 167 return __wait_for_ack(d, ack, 0); 168 } 169 170 static inline int 171 wait_ack_set(const struct intel_uncore_forcewake_domain *d, 172 const u32 ack) 173 { 174 return __wait_for_ack(d, ack, ack); 175 } 176 177 static inline void 178 fw_domain_wait_ack_clear(const struct intel_uncore_forcewake_domain *d) 179 { 180 if (wait_ack_clear(d, FORCEWAKE_KERNEL)) { 181 drm_err(&d->uncore->i915->drm, 182 "%s: timed out waiting for forcewake ack to clear.\n", 183 intel_uncore_forcewake_domain_to_str(d->id)); 184 add_taint_for_CI(d->uncore->i915, TAINT_WARN); /* CI now unreliable */ 185 } 186 } 187 188 enum ack_type { 189 ACK_CLEAR = 0, 190 ACK_SET 191 }; 192 193 static int 194 fw_domain_wait_ack_with_fallback(const struct intel_uncore_forcewake_domain *d, 195 const enum ack_type type) 196 { 197 const u32 ack_bit = FORCEWAKE_KERNEL; 198 const u32 value = type == ACK_SET ? ack_bit : 0; 199 unsigned int pass; 200 bool ack_detected; 201 202 /* 203 * There is a possibility of driver's wake request colliding 204 * with hardware's own wake requests and that can cause 205 * hardware to not deliver the driver's ack message. 206 * 207 * Use a fallback bit toggle to kick the gpu state machine 208 * in the hope that the original ack will be delivered along with 209 * the fallback ack. 210 * 211 * This workaround is described in HSDES #1604254524 and it's known as: 212 * WaRsForcewakeAddDelayForAck:skl,bxt,kbl,glk,cfl,cnl,icl 213 * although the name is a bit misleading. 214 */ 215 216 pass = 1; 217 do { 218 wait_ack_clear(d, FORCEWAKE_KERNEL_FALLBACK); 219 220 fw_set(d, FORCEWAKE_KERNEL_FALLBACK); 221 /* Give gt some time to relax before the polling frenzy */ 222 udelay(10 * pass); 223 wait_ack_set(d, FORCEWAKE_KERNEL_FALLBACK); 224 225 ack_detected = (fw_ack(d) & ack_bit) == value; 226 227 fw_clear(d, FORCEWAKE_KERNEL_FALLBACK); 228 } while (!ack_detected && pass++ < 10); 229 230 drm_dbg(&d->uncore->i915->drm, 231 "%s had to use fallback to %s ack, 0x%x (passes %u)\n", 232 intel_uncore_forcewake_domain_to_str(d->id), 233 type == ACK_SET ? "set" : "clear", 234 fw_ack(d), 235 pass); 236 237 return ack_detected ? 0 : -ETIMEDOUT; 238 } 239 240 static inline void 241 fw_domain_wait_ack_clear_fallback(const struct intel_uncore_forcewake_domain *d) 242 { 243 if (likely(!wait_ack_clear(d, FORCEWAKE_KERNEL))) 244 return; 245 246 if (fw_domain_wait_ack_with_fallback(d, ACK_CLEAR)) 247 fw_domain_wait_ack_clear(d); 248 } 249 250 static inline void 251 fw_domain_get(const struct intel_uncore_forcewake_domain *d) 252 { 253 fw_set(d, FORCEWAKE_KERNEL); 254 } 255 256 static inline void 257 fw_domain_wait_ack_set(const struct intel_uncore_forcewake_domain *d) 258 { 259 if (wait_ack_set(d, FORCEWAKE_KERNEL)) { 260 drm_err(&d->uncore->i915->drm, 261 "%s: timed out waiting for forcewake ack request.\n", 262 intel_uncore_forcewake_domain_to_str(d->id)); 263 add_taint_for_CI(d->uncore->i915, TAINT_WARN); /* CI now unreliable */ 264 } 265 } 266 267 static inline void 268 fw_domain_wait_ack_set_fallback(const struct intel_uncore_forcewake_domain *d) 269 { 270 if (likely(!wait_ack_set(d, FORCEWAKE_KERNEL))) 271 return; 272 273 if (fw_domain_wait_ack_with_fallback(d, ACK_SET)) 274 fw_domain_wait_ack_set(d); 275 } 276 277 static inline void 278 fw_domain_put(const struct intel_uncore_forcewake_domain *d) 279 { 280 fw_clear(d, FORCEWAKE_KERNEL); 281 } 282 283 static void 284 fw_domains_get_normal(struct intel_uncore *uncore, enum forcewake_domains fw_domains) 285 { 286 struct intel_uncore_forcewake_domain *d; 287 unsigned int tmp; 288 289 GEM_BUG_ON(fw_domains & ~uncore->fw_domains); 290 291 for_each_fw_domain_masked(d, fw_domains, uncore, tmp) { 292 fw_domain_wait_ack_clear(d); 293 fw_domain_get(d); 294 } 295 296 for_each_fw_domain_masked(d, fw_domains, uncore, tmp) 297 fw_domain_wait_ack_set(d); 298 299 uncore->fw_domains_active |= fw_domains; 300 } 301 302 static void 303 fw_domains_get_with_fallback(struct intel_uncore *uncore, 304 enum forcewake_domains fw_domains) 305 { 306 struct intel_uncore_forcewake_domain *d; 307 unsigned int tmp; 308 309 GEM_BUG_ON(fw_domains & ~uncore->fw_domains); 310 311 for_each_fw_domain_masked(d, fw_domains, uncore, tmp) { 312 fw_domain_wait_ack_clear_fallback(d); 313 fw_domain_get(d); 314 } 315 316 for_each_fw_domain_masked(d, fw_domains, uncore, tmp) 317 fw_domain_wait_ack_set_fallback(d); 318 319 uncore->fw_domains_active |= fw_domains; 320 } 321 322 static void 323 fw_domains_put(struct intel_uncore *uncore, enum forcewake_domains fw_domains) 324 { 325 struct intel_uncore_forcewake_domain *d; 326 unsigned int tmp; 327 328 GEM_BUG_ON(fw_domains & ~uncore->fw_domains); 329 330 for_each_fw_domain_masked(d, fw_domains, uncore, tmp) 331 fw_domain_put(d); 332 333 uncore->fw_domains_active &= ~fw_domains; 334 } 335 336 static void 337 fw_domains_reset(struct intel_uncore *uncore, 338 enum forcewake_domains fw_domains) 339 { 340 struct intel_uncore_forcewake_domain *d; 341 unsigned int tmp; 342 343 if (!fw_domains) 344 return; 345 346 GEM_BUG_ON(fw_domains & ~uncore->fw_domains); 347 348 for_each_fw_domain_masked(d, fw_domains, uncore, tmp) 349 fw_domain_reset(d); 350 } 351 352 static inline u32 gt_thread_status(struct intel_uncore *uncore) 353 { 354 u32 val; 355 356 val = __raw_uncore_read32(uncore, GEN6_GT_THREAD_STATUS_REG); 357 val &= GEN6_GT_THREAD_STATUS_CORE_MASK; 358 359 return val; 360 } 361 362 static void __gen6_gt_wait_for_thread_c0(struct intel_uncore *uncore) 363 { 364 /* 365 * w/a for a sporadic read returning 0 by waiting for the GT 366 * thread to wake up. 367 */ 368 drm_WARN_ONCE(&uncore->i915->drm, 369 wait_for_atomic_us(gt_thread_status(uncore) == 0, 5000), 370 "GT thread status wait timed out\n"); 371 } 372 373 static void fw_domains_get_with_thread_status(struct intel_uncore *uncore, 374 enum forcewake_domains fw_domains) 375 { 376 fw_domains_get_normal(uncore, fw_domains); 377 378 /* WaRsForcewakeWaitTC0:snb,ivb,hsw,bdw,vlv */ 379 __gen6_gt_wait_for_thread_c0(uncore); 380 } 381 382 static inline u32 fifo_free_entries(struct intel_uncore *uncore) 383 { 384 u32 count = __raw_uncore_read32(uncore, GTFIFOCTL); 385 386 return count & GT_FIFO_FREE_ENTRIES_MASK; 387 } 388 389 static void __gen6_gt_wait_for_fifo(struct intel_uncore *uncore) 390 { 391 u32 n; 392 393 /* On VLV, FIFO will be shared by both SW and HW. 394 * So, we need to read the FREE_ENTRIES everytime */ 395 if (IS_VALLEYVIEW(uncore->i915)) 396 n = fifo_free_entries(uncore); 397 else 398 n = uncore->fifo_count; 399 400 if (n <= GT_FIFO_NUM_RESERVED_ENTRIES) { 401 if (wait_for_atomic((n = fifo_free_entries(uncore)) > 402 GT_FIFO_NUM_RESERVED_ENTRIES, 403 GT_FIFO_TIMEOUT_MS)) { 404 drm_dbg(&uncore->i915->drm, 405 "GT_FIFO timeout, entries: %u\n", n); 406 return; 407 } 408 } 409 410 uncore->fifo_count = n - 1; 411 } 412 413 static enum hrtimer_restart 414 intel_uncore_fw_release_timer(struct hrtimer *timer) 415 { 416 struct intel_uncore_forcewake_domain *domain = 417 container_of(timer, struct intel_uncore_forcewake_domain, timer); 418 struct intel_uncore *uncore = domain->uncore; 419 unsigned long irqflags; 420 421 assert_rpm_device_not_suspended(uncore->rpm); 422 423 if (xchg(&domain->active, false)) 424 return HRTIMER_RESTART; 425 426 spin_lock_irqsave(&uncore->lock, irqflags); 427 428 uncore->fw_domains_timer &= ~domain->mask; 429 430 GEM_BUG_ON(!domain->wake_count); 431 if (--domain->wake_count == 0) 432 fw_domains_put(uncore, domain->mask); 433 434 spin_unlock_irqrestore(&uncore->lock, irqflags); 435 436 return HRTIMER_NORESTART; 437 } 438 439 /* Note callers must have acquired the PUNIT->PMIC bus, before calling this. */ 440 static unsigned int 441 intel_uncore_forcewake_reset(struct intel_uncore *uncore) 442 { 443 unsigned long irqflags; 444 struct intel_uncore_forcewake_domain *domain; 445 int retry_count = 100; 446 enum forcewake_domains fw, active_domains; 447 448 iosf_mbi_assert_punit_acquired(); 449 450 /* Hold uncore.lock across reset to prevent any register access 451 * with forcewake not set correctly. Wait until all pending 452 * timers are run before holding. 453 */ 454 while (1) { 455 unsigned int tmp; 456 457 active_domains = 0; 458 459 for_each_fw_domain(domain, uncore, tmp) { 460 smp_store_mb(domain->active, false); 461 if (hrtimer_cancel(&domain->timer) == 0) 462 continue; 463 464 intel_uncore_fw_release_timer(&domain->timer); 465 } 466 467 spin_lock_irqsave(&uncore->lock, irqflags); 468 469 for_each_fw_domain(domain, uncore, tmp) { 470 if (hrtimer_active(&domain->timer)) 471 active_domains |= domain->mask; 472 } 473 474 if (active_domains == 0) 475 break; 476 477 if (--retry_count == 0) { 478 drm_err(&uncore->i915->drm, "Timed out waiting for forcewake timers to finish\n"); 479 break; 480 } 481 482 spin_unlock_irqrestore(&uncore->lock, irqflags); 483 cond_resched(); 484 } 485 486 drm_WARN_ON(&uncore->i915->drm, active_domains); 487 488 fw = uncore->fw_domains_active; 489 if (fw) 490 fw_domains_put(uncore, fw); 491 492 fw_domains_reset(uncore, uncore->fw_domains); 493 assert_forcewakes_inactive(uncore); 494 495 spin_unlock_irqrestore(&uncore->lock, irqflags); 496 497 return fw; /* track the lost user forcewake domains */ 498 } 499 500 static bool 501 fpga_check_for_unclaimed_mmio(struct intel_uncore *uncore) 502 { 503 u32 dbg; 504 505 dbg = __raw_uncore_read32(uncore, FPGA_DBG); 506 if (likely(!(dbg & FPGA_DBG_RM_NOCLAIM))) 507 return false; 508 509 /* 510 * Bugs in PCI programming (or failing hardware) can occasionally cause 511 * us to lose access to the MMIO BAR. When this happens, register 512 * reads will come back with 0xFFFFFFFF for every register and things 513 * go bad very quickly. Let's try to detect that special case and at 514 * least try to print a more informative message about what has 515 * happened. 516 * 517 * During normal operation the FPGA_DBG register has several unused 518 * bits that will always read back as 0's so we can use them as canaries 519 * to recognize when MMIO accesses are just busted. 520 */ 521 if (unlikely(dbg == ~0)) 522 drm_err(&uncore->i915->drm, 523 "Lost access to MMIO BAR; all registers now read back as 0xFFFFFFFF!\n"); 524 525 __raw_uncore_write32(uncore, FPGA_DBG, FPGA_DBG_RM_NOCLAIM); 526 527 return true; 528 } 529 530 static bool 531 vlv_check_for_unclaimed_mmio(struct intel_uncore *uncore) 532 { 533 u32 cer; 534 535 cer = __raw_uncore_read32(uncore, CLAIM_ER); 536 if (likely(!(cer & (CLAIM_ER_OVERFLOW | CLAIM_ER_CTR_MASK)))) 537 return false; 538 539 __raw_uncore_write32(uncore, CLAIM_ER, CLAIM_ER_CLR); 540 541 return true; 542 } 543 544 static bool 545 gen6_check_for_fifo_debug(struct intel_uncore *uncore) 546 { 547 u32 fifodbg; 548 549 fifodbg = __raw_uncore_read32(uncore, GTFIFODBG); 550 551 if (unlikely(fifodbg)) { 552 drm_dbg(&uncore->i915->drm, "GTFIFODBG = 0x08%x\n", fifodbg); 553 __raw_uncore_write32(uncore, GTFIFODBG, fifodbg); 554 } 555 556 return fifodbg; 557 } 558 559 static bool 560 check_for_unclaimed_mmio(struct intel_uncore *uncore) 561 { 562 bool ret = false; 563 564 lockdep_assert_held(&uncore->debug->lock); 565 566 if (uncore->debug->suspend_count) 567 return false; 568 569 if (intel_uncore_has_fpga_dbg_unclaimed(uncore)) 570 ret |= fpga_check_for_unclaimed_mmio(uncore); 571 572 if (intel_uncore_has_dbg_unclaimed(uncore)) 573 ret |= vlv_check_for_unclaimed_mmio(uncore); 574 575 if (intel_uncore_has_fifo(uncore)) 576 ret |= gen6_check_for_fifo_debug(uncore); 577 578 return ret; 579 } 580 581 static void forcewake_early_sanitize(struct intel_uncore *uncore, 582 unsigned int restore_forcewake) 583 { 584 GEM_BUG_ON(!intel_uncore_has_forcewake(uncore)); 585 586 /* WaDisableShadowRegForCpd:chv */ 587 if (IS_CHERRYVIEW(uncore->i915)) { 588 __raw_uncore_write32(uncore, GTFIFOCTL, 589 __raw_uncore_read32(uncore, GTFIFOCTL) | 590 GT_FIFO_CTL_BLOCK_ALL_POLICY_STALL | 591 GT_FIFO_CTL_RC6_POLICY_STALL); 592 } 593 594 iosf_mbi_punit_acquire(); 595 intel_uncore_forcewake_reset(uncore); 596 if (restore_forcewake) { 597 spin_lock_irq(&uncore->lock); 598 fw_domains_get(uncore, restore_forcewake); 599 600 if (intel_uncore_has_fifo(uncore)) 601 uncore->fifo_count = fifo_free_entries(uncore); 602 spin_unlock_irq(&uncore->lock); 603 } 604 iosf_mbi_punit_release(); 605 } 606 607 void intel_uncore_suspend(struct intel_uncore *uncore) 608 { 609 if (!intel_uncore_has_forcewake(uncore)) 610 return; 611 612 iosf_mbi_punit_acquire(); 613 iosf_mbi_unregister_pmic_bus_access_notifier_unlocked( 614 &uncore->pmic_bus_access_nb); 615 uncore->fw_domains_saved = intel_uncore_forcewake_reset(uncore); 616 iosf_mbi_punit_release(); 617 } 618 619 void intel_uncore_resume_early(struct intel_uncore *uncore) 620 { 621 unsigned int restore_forcewake; 622 623 if (intel_uncore_unclaimed_mmio(uncore)) 624 drm_dbg(&uncore->i915->drm, "unclaimed mmio detected on resume, clearing\n"); 625 626 if (!intel_uncore_has_forcewake(uncore)) 627 return; 628 629 restore_forcewake = fetch_and_zero(&uncore->fw_domains_saved); 630 forcewake_early_sanitize(uncore, restore_forcewake); 631 632 iosf_mbi_register_pmic_bus_access_notifier(&uncore->pmic_bus_access_nb); 633 } 634 635 void intel_uncore_runtime_resume(struct intel_uncore *uncore) 636 { 637 if (!intel_uncore_has_forcewake(uncore)) 638 return; 639 640 iosf_mbi_register_pmic_bus_access_notifier(&uncore->pmic_bus_access_nb); 641 } 642 643 static void __intel_uncore_forcewake_get(struct intel_uncore *uncore, 644 enum forcewake_domains fw_domains) 645 { 646 struct intel_uncore_forcewake_domain *domain; 647 unsigned int tmp; 648 649 fw_domains &= uncore->fw_domains; 650 651 for_each_fw_domain_masked(domain, fw_domains, uncore, tmp) { 652 if (domain->wake_count++) { 653 fw_domains &= ~domain->mask; 654 domain->active = true; 655 } 656 } 657 658 if (fw_domains) 659 fw_domains_get(uncore, fw_domains); 660 } 661 662 /** 663 * intel_uncore_forcewake_get - grab forcewake domain references 664 * @uncore: the intel_uncore structure 665 * @fw_domains: forcewake domains to get reference on 666 * 667 * This function can be used get GT's forcewake domain references. 668 * Normal register access will handle the forcewake domains automatically. 669 * However if some sequence requires the GT to not power down a particular 670 * forcewake domains this function should be called at the beginning of the 671 * sequence. And subsequently the reference should be dropped by symmetric 672 * call to intel_unforce_forcewake_put(). Usually caller wants all the domains 673 * to be kept awake so the @fw_domains would be then FORCEWAKE_ALL. 674 */ 675 void intel_uncore_forcewake_get(struct intel_uncore *uncore, 676 enum forcewake_domains fw_domains) 677 { 678 unsigned long irqflags; 679 680 if (!uncore->fw_get_funcs) 681 return; 682 683 assert_rpm_wakelock_held(uncore->rpm); 684 685 spin_lock_irqsave(&uncore->lock, irqflags); 686 __intel_uncore_forcewake_get(uncore, fw_domains); 687 spin_unlock_irqrestore(&uncore->lock, irqflags); 688 } 689 690 /** 691 * intel_uncore_forcewake_user_get - claim forcewake on behalf of userspace 692 * @uncore: the intel_uncore structure 693 * 694 * This function is a wrapper around intel_uncore_forcewake_get() to acquire 695 * the GT powerwell and in the process disable our debugging for the 696 * duration of userspace's bypass. 697 */ 698 void intel_uncore_forcewake_user_get(struct intel_uncore *uncore) 699 { 700 spin_lock_irq(&uncore->lock); 701 if (!uncore->user_forcewake_count++) { 702 intel_uncore_forcewake_get__locked(uncore, FORCEWAKE_ALL); 703 mmio_debug_suspend(uncore); 704 } 705 spin_unlock_irq(&uncore->lock); 706 } 707 708 /** 709 * intel_uncore_forcewake_user_put - release forcewake on behalf of userspace 710 * @uncore: the intel_uncore structure 711 * 712 * This function complements intel_uncore_forcewake_user_get() and releases 713 * the GT powerwell taken on behalf of the userspace bypass. 714 */ 715 void intel_uncore_forcewake_user_put(struct intel_uncore *uncore) 716 { 717 spin_lock_irq(&uncore->lock); 718 if (!--uncore->user_forcewake_count) { 719 mmio_debug_resume(uncore); 720 intel_uncore_forcewake_put__locked(uncore, FORCEWAKE_ALL); 721 } 722 spin_unlock_irq(&uncore->lock); 723 } 724 725 /** 726 * intel_uncore_forcewake_get__locked - grab forcewake domain references 727 * @uncore: the intel_uncore structure 728 * @fw_domains: forcewake domains to get reference on 729 * 730 * See intel_uncore_forcewake_get(). This variant places the onus 731 * on the caller to explicitly handle the dev_priv->uncore.lock spinlock. 732 */ 733 void intel_uncore_forcewake_get__locked(struct intel_uncore *uncore, 734 enum forcewake_domains fw_domains) 735 { 736 lockdep_assert_held(&uncore->lock); 737 738 if (!uncore->fw_get_funcs) 739 return; 740 741 __intel_uncore_forcewake_get(uncore, fw_domains); 742 } 743 744 static void __intel_uncore_forcewake_put(struct intel_uncore *uncore, 745 enum forcewake_domains fw_domains, 746 bool delayed) 747 { 748 struct intel_uncore_forcewake_domain *domain; 749 unsigned int tmp; 750 751 fw_domains &= uncore->fw_domains; 752 753 for_each_fw_domain_masked(domain, fw_domains, uncore, tmp) { 754 GEM_BUG_ON(!domain->wake_count); 755 756 if (--domain->wake_count) { 757 domain->active = true; 758 continue; 759 } 760 761 if (delayed && 762 !(domain->uncore->fw_domains_timer & domain->mask)) 763 fw_domain_arm_timer(domain); 764 else 765 fw_domains_put(uncore, domain->mask); 766 } 767 } 768 769 /** 770 * intel_uncore_forcewake_put - release a forcewake domain reference 771 * @uncore: the intel_uncore structure 772 * @fw_domains: forcewake domains to put references 773 * 774 * This function drops the device-level forcewakes for specified 775 * domains obtained by intel_uncore_forcewake_get(). 776 */ 777 void intel_uncore_forcewake_put(struct intel_uncore *uncore, 778 enum forcewake_domains fw_domains) 779 { 780 unsigned long irqflags; 781 782 if (!uncore->fw_get_funcs) 783 return; 784 785 spin_lock_irqsave(&uncore->lock, irqflags); 786 __intel_uncore_forcewake_put(uncore, fw_domains, false); 787 spin_unlock_irqrestore(&uncore->lock, irqflags); 788 } 789 790 void intel_uncore_forcewake_put_delayed(struct intel_uncore *uncore, 791 enum forcewake_domains fw_domains) 792 { 793 unsigned long irqflags; 794 795 if (!uncore->fw_get_funcs) 796 return; 797 798 spin_lock_irqsave(&uncore->lock, irqflags); 799 __intel_uncore_forcewake_put(uncore, fw_domains, true); 800 spin_unlock_irqrestore(&uncore->lock, irqflags); 801 } 802 803 /** 804 * intel_uncore_forcewake_flush - flush the delayed release 805 * @uncore: the intel_uncore structure 806 * @fw_domains: forcewake domains to flush 807 */ 808 void intel_uncore_forcewake_flush(struct intel_uncore *uncore, 809 enum forcewake_domains fw_domains) 810 { 811 struct intel_uncore_forcewake_domain *domain; 812 unsigned int tmp; 813 814 if (!uncore->fw_get_funcs) 815 return; 816 817 fw_domains &= uncore->fw_domains; 818 for_each_fw_domain_masked(domain, fw_domains, uncore, tmp) { 819 WRITE_ONCE(domain->active, false); 820 if (hrtimer_cancel(&domain->timer)) 821 intel_uncore_fw_release_timer(&domain->timer); 822 } 823 } 824 825 /** 826 * intel_uncore_forcewake_put__locked - release forcewake domain references 827 * @uncore: the intel_uncore structure 828 * @fw_domains: forcewake domains to put references 829 * 830 * See intel_uncore_forcewake_put(). This variant places the onus 831 * on the caller to explicitly handle the dev_priv->uncore.lock spinlock. 832 */ 833 void intel_uncore_forcewake_put__locked(struct intel_uncore *uncore, 834 enum forcewake_domains fw_domains) 835 { 836 lockdep_assert_held(&uncore->lock); 837 838 if (!uncore->fw_get_funcs) 839 return; 840 841 __intel_uncore_forcewake_put(uncore, fw_domains, false); 842 } 843 844 void assert_forcewakes_inactive(struct intel_uncore *uncore) 845 { 846 if (!uncore->fw_get_funcs) 847 return; 848 849 drm_WARN(&uncore->i915->drm, uncore->fw_domains_active, 850 "Expected all fw_domains to be inactive, but %08x are still on\n", 851 uncore->fw_domains_active); 852 } 853 854 void assert_forcewakes_active(struct intel_uncore *uncore, 855 enum forcewake_domains fw_domains) 856 { 857 struct intel_uncore_forcewake_domain *domain; 858 unsigned int tmp; 859 860 if (!IS_ENABLED(CONFIG_DRM_I915_DEBUG_RUNTIME_PM)) 861 return; 862 863 if (!uncore->fw_get_funcs) 864 return; 865 866 spin_lock_irq(&uncore->lock); 867 868 assert_rpm_wakelock_held(uncore->rpm); 869 870 fw_domains &= uncore->fw_domains; 871 drm_WARN(&uncore->i915->drm, fw_domains & ~uncore->fw_domains_active, 872 "Expected %08x fw_domains to be active, but %08x are off\n", 873 fw_domains, fw_domains & ~uncore->fw_domains_active); 874 875 /* 876 * Check that the caller has an explicit wakeref and we don't mistake 877 * it for the auto wakeref. 878 */ 879 for_each_fw_domain_masked(domain, fw_domains, uncore, tmp) { 880 unsigned int actual = READ_ONCE(domain->wake_count); 881 unsigned int expect = 1; 882 883 if (uncore->fw_domains_timer & domain->mask) 884 expect++; /* pending automatic release */ 885 886 if (drm_WARN(&uncore->i915->drm, actual < expect, 887 "Expected domain %d to be held awake by caller, count=%d\n", 888 domain->id, actual)) 889 break; 890 } 891 892 spin_unlock_irq(&uncore->lock); 893 } 894 895 /* 896 * We give fast paths for the really cool registers. The second range includes 897 * media domains (and the GSC starting from Xe_LPM+) 898 */ 899 #define NEEDS_FORCE_WAKE(reg) ({ \ 900 u32 __reg = (reg); \ 901 __reg < 0x40000 || __reg >= 0x116000; \ 902 }) 903 904 static int fw_range_cmp(u32 offset, const struct intel_forcewake_range *entry) 905 { 906 if (offset < entry->start) 907 return -1; 908 else if (offset > entry->end) 909 return 1; 910 else 911 return 0; 912 } 913 914 /* Copied and "macroized" from lib/bsearch.c */ 915 #define BSEARCH(key, base, num, cmp) ({ \ 916 unsigned int start__ = 0, end__ = (num); \ 917 typeof(base) result__ = NULL; \ 918 while (start__ < end__) { \ 919 unsigned int mid__ = start__ + (end__ - start__) / 2; \ 920 int ret__ = (cmp)((key), (base) + mid__); \ 921 if (ret__ < 0) { \ 922 end__ = mid__; \ 923 } else if (ret__ > 0) { \ 924 start__ = mid__ + 1; \ 925 } else { \ 926 result__ = (base) + mid__; \ 927 break; \ 928 } \ 929 } \ 930 result__; \ 931 }) 932 933 static enum forcewake_domains 934 find_fw_domain(struct intel_uncore *uncore, u32 offset) 935 { 936 const struct intel_forcewake_range *entry; 937 938 if (IS_GSI_REG(offset)) 939 offset += uncore->gsi_offset; 940 941 entry = BSEARCH(offset, 942 uncore->fw_domains_table, 943 uncore->fw_domains_table_entries, 944 fw_range_cmp); 945 946 if (!entry) 947 return 0; 948 949 /* 950 * The list of FW domains depends on the SKU in gen11+ so we 951 * can't determine it statically. We use FORCEWAKE_ALL and 952 * translate it here to the list of available domains. 953 */ 954 if (entry->domains == FORCEWAKE_ALL) 955 return uncore->fw_domains; 956 957 drm_WARN(&uncore->i915->drm, entry->domains & ~uncore->fw_domains, 958 "Uninitialized forcewake domain(s) 0x%x accessed at 0x%x\n", 959 entry->domains & ~uncore->fw_domains, offset); 960 961 return entry->domains; 962 } 963 964 /* 965 * Shadowed register tables describe special register ranges that i915 is 966 * allowed to write to without acquiring forcewake. If these registers' power 967 * wells are down, the hardware will save values written by i915 to a shadow 968 * copy and automatically transfer them into the real register the next time 969 * the power well is woken up. Shadowing only applies to writes; forcewake 970 * must still be acquired when reading from registers in these ranges. 971 * 972 * The documentation for shadowed registers is somewhat spotty on older 973 * platforms. However missing registers from these lists is non-fatal; it just 974 * means we'll wake up the hardware for some register accesses where we didn't 975 * really need to. 976 * 977 * The ranges listed in these tables must be sorted by offset. 978 * 979 * When adding new tables here, please also add them to 980 * intel_shadow_table_check() in selftests/intel_uncore.c so that they will be 981 * scanned for obvious mistakes or typos by the selftests. 982 */ 983 984 static const struct i915_range gen8_shadowed_regs[] = { 985 { .start = 0x2030, .end = 0x2030 }, 986 { .start = 0xA008, .end = 0xA00C }, 987 { .start = 0x12030, .end = 0x12030 }, 988 { .start = 0x1a030, .end = 0x1a030 }, 989 { .start = 0x22030, .end = 0x22030 }, 990 }; 991 992 static const struct i915_range gen11_shadowed_regs[] = { 993 { .start = 0x2030, .end = 0x2030 }, 994 { .start = 0x2550, .end = 0x2550 }, 995 { .start = 0xA008, .end = 0xA00C }, 996 { .start = 0x22030, .end = 0x22030 }, 997 { .start = 0x22230, .end = 0x22230 }, 998 { .start = 0x22510, .end = 0x22550 }, 999 { .start = 0x1C0030, .end = 0x1C0030 }, 1000 { .start = 0x1C0230, .end = 0x1C0230 }, 1001 { .start = 0x1C0510, .end = 0x1C0550 }, 1002 { .start = 0x1C4030, .end = 0x1C4030 }, 1003 { .start = 0x1C4230, .end = 0x1C4230 }, 1004 { .start = 0x1C4510, .end = 0x1C4550 }, 1005 { .start = 0x1C8030, .end = 0x1C8030 }, 1006 { .start = 0x1C8230, .end = 0x1C8230 }, 1007 { .start = 0x1C8510, .end = 0x1C8550 }, 1008 { .start = 0x1D0030, .end = 0x1D0030 }, 1009 { .start = 0x1D0230, .end = 0x1D0230 }, 1010 { .start = 0x1D0510, .end = 0x1D0550 }, 1011 { .start = 0x1D4030, .end = 0x1D4030 }, 1012 { .start = 0x1D4230, .end = 0x1D4230 }, 1013 { .start = 0x1D4510, .end = 0x1D4550 }, 1014 { .start = 0x1D8030, .end = 0x1D8030 }, 1015 { .start = 0x1D8230, .end = 0x1D8230 }, 1016 { .start = 0x1D8510, .end = 0x1D8550 }, 1017 }; 1018 1019 static const struct i915_range gen12_shadowed_regs[] = { 1020 { .start = 0x2030, .end = 0x2030 }, 1021 { .start = 0x2510, .end = 0x2550 }, 1022 { .start = 0xA008, .end = 0xA00C }, 1023 { .start = 0xA188, .end = 0xA188 }, 1024 { .start = 0xA278, .end = 0xA278 }, 1025 { .start = 0xA540, .end = 0xA56C }, 1026 { .start = 0xC4C8, .end = 0xC4C8 }, 1027 { .start = 0xC4D4, .end = 0xC4D4 }, 1028 { .start = 0xC600, .end = 0xC600 }, 1029 { .start = 0x22030, .end = 0x22030 }, 1030 { .start = 0x22510, .end = 0x22550 }, 1031 { .start = 0x1C0030, .end = 0x1C0030 }, 1032 { .start = 0x1C0510, .end = 0x1C0550 }, 1033 { .start = 0x1C4030, .end = 0x1C4030 }, 1034 { .start = 0x1C4510, .end = 0x1C4550 }, 1035 { .start = 0x1C8030, .end = 0x1C8030 }, 1036 { .start = 0x1C8510, .end = 0x1C8550 }, 1037 { .start = 0x1D0030, .end = 0x1D0030 }, 1038 { .start = 0x1D0510, .end = 0x1D0550 }, 1039 { .start = 0x1D4030, .end = 0x1D4030 }, 1040 { .start = 0x1D4510, .end = 0x1D4550 }, 1041 { .start = 0x1D8030, .end = 0x1D8030 }, 1042 { .start = 0x1D8510, .end = 0x1D8550 }, 1043 1044 /* 1045 * The rest of these ranges are specific to Xe_HP and beyond, but 1046 * are reserved/unused ranges on earlier gen12 platforms, so they can 1047 * be safely added to the gen12 table. 1048 */ 1049 { .start = 0x1E0030, .end = 0x1E0030 }, 1050 { .start = 0x1E0510, .end = 0x1E0550 }, 1051 { .start = 0x1E4030, .end = 0x1E4030 }, 1052 { .start = 0x1E4510, .end = 0x1E4550 }, 1053 { .start = 0x1E8030, .end = 0x1E8030 }, 1054 { .start = 0x1E8510, .end = 0x1E8550 }, 1055 { .start = 0x1F0030, .end = 0x1F0030 }, 1056 { .start = 0x1F0510, .end = 0x1F0550 }, 1057 { .start = 0x1F4030, .end = 0x1F4030 }, 1058 { .start = 0x1F4510, .end = 0x1F4550 }, 1059 { .start = 0x1F8030, .end = 0x1F8030 }, 1060 { .start = 0x1F8510, .end = 0x1F8550 }, 1061 }; 1062 1063 static const struct i915_range dg2_shadowed_regs[] = { 1064 { .start = 0x2030, .end = 0x2030 }, 1065 { .start = 0x2510, .end = 0x2550 }, 1066 { .start = 0xA008, .end = 0xA00C }, 1067 { .start = 0xA188, .end = 0xA188 }, 1068 { .start = 0xA278, .end = 0xA278 }, 1069 { .start = 0xA540, .end = 0xA56C }, 1070 { .start = 0xC4C8, .end = 0xC4C8 }, 1071 { .start = 0xC4E0, .end = 0xC4E0 }, 1072 { .start = 0xC600, .end = 0xC600 }, 1073 { .start = 0xC658, .end = 0xC658 }, 1074 { .start = 0x22030, .end = 0x22030 }, 1075 { .start = 0x22510, .end = 0x22550 }, 1076 { .start = 0x1C0030, .end = 0x1C0030 }, 1077 { .start = 0x1C0510, .end = 0x1C0550 }, 1078 { .start = 0x1C4030, .end = 0x1C4030 }, 1079 { .start = 0x1C4510, .end = 0x1C4550 }, 1080 { .start = 0x1C8030, .end = 0x1C8030 }, 1081 { .start = 0x1C8510, .end = 0x1C8550 }, 1082 { .start = 0x1D0030, .end = 0x1D0030 }, 1083 { .start = 0x1D0510, .end = 0x1D0550 }, 1084 { .start = 0x1D4030, .end = 0x1D4030 }, 1085 { .start = 0x1D4510, .end = 0x1D4550 }, 1086 { .start = 0x1D8030, .end = 0x1D8030 }, 1087 { .start = 0x1D8510, .end = 0x1D8550 }, 1088 { .start = 0x1E0030, .end = 0x1E0030 }, 1089 { .start = 0x1E0510, .end = 0x1E0550 }, 1090 { .start = 0x1E4030, .end = 0x1E4030 }, 1091 { .start = 0x1E4510, .end = 0x1E4550 }, 1092 { .start = 0x1E8030, .end = 0x1E8030 }, 1093 { .start = 0x1E8510, .end = 0x1E8550 }, 1094 { .start = 0x1F0030, .end = 0x1F0030 }, 1095 { .start = 0x1F0510, .end = 0x1F0550 }, 1096 { .start = 0x1F4030, .end = 0x1F4030 }, 1097 { .start = 0x1F4510, .end = 0x1F4550 }, 1098 { .start = 0x1F8030, .end = 0x1F8030 }, 1099 { .start = 0x1F8510, .end = 0x1F8550 }, 1100 }; 1101 1102 static const struct i915_range pvc_shadowed_regs[] = { 1103 { .start = 0x2030, .end = 0x2030 }, 1104 { .start = 0x2510, .end = 0x2550 }, 1105 { .start = 0xA008, .end = 0xA00C }, 1106 { .start = 0xA188, .end = 0xA188 }, 1107 { .start = 0xA278, .end = 0xA278 }, 1108 { .start = 0xA540, .end = 0xA56C }, 1109 { .start = 0xC4C8, .end = 0xC4C8 }, 1110 { .start = 0xC4E0, .end = 0xC4E0 }, 1111 { .start = 0xC600, .end = 0xC600 }, 1112 { .start = 0xC658, .end = 0xC658 }, 1113 { .start = 0x22030, .end = 0x22030 }, 1114 { .start = 0x22510, .end = 0x22550 }, 1115 { .start = 0x1C0030, .end = 0x1C0030 }, 1116 { .start = 0x1C0510, .end = 0x1C0550 }, 1117 { .start = 0x1C4030, .end = 0x1C4030 }, 1118 { .start = 0x1C4510, .end = 0x1C4550 }, 1119 { .start = 0x1C8030, .end = 0x1C8030 }, 1120 { .start = 0x1C8510, .end = 0x1C8550 }, 1121 { .start = 0x1D0030, .end = 0x1D0030 }, 1122 { .start = 0x1D0510, .end = 0x1D0550 }, 1123 { .start = 0x1D4030, .end = 0x1D4030 }, 1124 { .start = 0x1D4510, .end = 0x1D4550 }, 1125 { .start = 0x1D8030, .end = 0x1D8030 }, 1126 { .start = 0x1D8510, .end = 0x1D8550 }, 1127 { .start = 0x1E0030, .end = 0x1E0030 }, 1128 { .start = 0x1E0510, .end = 0x1E0550 }, 1129 { .start = 0x1E4030, .end = 0x1E4030 }, 1130 { .start = 0x1E4510, .end = 0x1E4550 }, 1131 { .start = 0x1E8030, .end = 0x1E8030 }, 1132 { .start = 0x1E8510, .end = 0x1E8550 }, 1133 { .start = 0x1F0030, .end = 0x1F0030 }, 1134 { .start = 0x1F0510, .end = 0x1F0550 }, 1135 { .start = 0x1F4030, .end = 0x1F4030 }, 1136 { .start = 0x1F4510, .end = 0x1F4550 }, 1137 { .start = 0x1F8030, .end = 0x1F8030 }, 1138 { .start = 0x1F8510, .end = 0x1F8550 }, 1139 }; 1140 1141 static const struct i915_range mtl_shadowed_regs[] = { 1142 { .start = 0x2030, .end = 0x2030 }, 1143 { .start = 0x2510, .end = 0x2550 }, 1144 { .start = 0xA008, .end = 0xA00C }, 1145 { .start = 0xA188, .end = 0xA188 }, 1146 { .start = 0xA278, .end = 0xA278 }, 1147 { .start = 0xA540, .end = 0xA56C }, 1148 { .start = 0xC050, .end = 0xC050 }, 1149 { .start = 0xC340, .end = 0xC340 }, 1150 { .start = 0xC4C8, .end = 0xC4C8 }, 1151 { .start = 0xC4E0, .end = 0xC4E0 }, 1152 { .start = 0xC600, .end = 0xC600 }, 1153 { .start = 0xC658, .end = 0xC658 }, 1154 { .start = 0xCFD4, .end = 0xCFDC }, 1155 { .start = 0x22030, .end = 0x22030 }, 1156 { .start = 0x22510, .end = 0x22550 }, 1157 }; 1158 1159 static const struct i915_range xelpmp_shadowed_regs[] = { 1160 { .start = 0x1C0030, .end = 0x1C0030 }, 1161 { .start = 0x1C0510, .end = 0x1C0550 }, 1162 { .start = 0x1C8030, .end = 0x1C8030 }, 1163 { .start = 0x1C8510, .end = 0x1C8550 }, 1164 { .start = 0x1D0030, .end = 0x1D0030 }, 1165 { .start = 0x1D0510, .end = 0x1D0550 }, 1166 { .start = 0x38A008, .end = 0x38A00C }, 1167 { .start = 0x38A188, .end = 0x38A188 }, 1168 { .start = 0x38A278, .end = 0x38A278 }, 1169 { .start = 0x38A540, .end = 0x38A56C }, 1170 { .start = 0x38A618, .end = 0x38A618 }, 1171 { .start = 0x38C050, .end = 0x38C050 }, 1172 { .start = 0x38C340, .end = 0x38C340 }, 1173 { .start = 0x38C4C8, .end = 0x38C4C8 }, 1174 { .start = 0x38C4E0, .end = 0x38C4E4 }, 1175 { .start = 0x38C600, .end = 0x38C600 }, 1176 { .start = 0x38C658, .end = 0x38C658 }, 1177 { .start = 0x38CFD4, .end = 0x38CFDC }, 1178 }; 1179 1180 static int mmio_range_cmp(u32 key, const struct i915_range *range) 1181 { 1182 if (key < range->start) 1183 return -1; 1184 else if (key > range->end) 1185 return 1; 1186 else 1187 return 0; 1188 } 1189 1190 static bool is_shadowed(struct intel_uncore *uncore, u32 offset) 1191 { 1192 if (drm_WARN_ON(&uncore->i915->drm, !uncore->shadowed_reg_table)) 1193 return false; 1194 1195 if (IS_GSI_REG(offset)) 1196 offset += uncore->gsi_offset; 1197 1198 return BSEARCH(offset, 1199 uncore->shadowed_reg_table, 1200 uncore->shadowed_reg_table_entries, 1201 mmio_range_cmp); 1202 } 1203 1204 static enum forcewake_domains 1205 gen6_reg_write_fw_domains(struct intel_uncore *uncore, i915_reg_t reg) 1206 { 1207 return FORCEWAKE_RENDER; 1208 } 1209 1210 #define __fwtable_reg_read_fw_domains(uncore, offset) \ 1211 ({ \ 1212 enum forcewake_domains __fwd = 0; \ 1213 if (NEEDS_FORCE_WAKE((offset))) \ 1214 __fwd = find_fw_domain(uncore, offset); \ 1215 __fwd; \ 1216 }) 1217 1218 #define __fwtable_reg_write_fw_domains(uncore, offset) \ 1219 ({ \ 1220 enum forcewake_domains __fwd = 0; \ 1221 const u32 __offset = (offset); \ 1222 if (NEEDS_FORCE_WAKE((__offset)) && !is_shadowed(uncore, __offset)) \ 1223 __fwd = find_fw_domain(uncore, __offset); \ 1224 __fwd; \ 1225 }) 1226 1227 #define GEN_FW_RANGE(s, e, d) \ 1228 { .start = (s), .end = (e), .domains = (d) } 1229 1230 /* 1231 * All platforms' forcewake tables below must be sorted by offset ranges. 1232 * Furthermore, new forcewake tables added should be "watertight" and have 1233 * no gaps between ranges. 1234 * 1235 * When there are multiple consecutive ranges listed in the bspec with 1236 * the same forcewake domain, it is customary to combine them into a single 1237 * row in the tables below to keep the tables small and lookups fast. 1238 * Likewise, reserved/unused ranges may be combined with the preceding and/or 1239 * following ranges since the driver will never be making MMIO accesses in 1240 * those ranges. 1241 * 1242 * For example, if the bspec were to list: 1243 * 1244 * ... 1245 * 0x1000 - 0x1fff: GT 1246 * 0x2000 - 0x2cff: GT 1247 * 0x2d00 - 0x2fff: unused/reserved 1248 * 0x3000 - 0xffff: GT 1249 * ... 1250 * 1251 * these could all be represented by a single line in the code: 1252 * 1253 * GEN_FW_RANGE(0x1000, 0xffff, FORCEWAKE_GT) 1254 * 1255 * When adding new forcewake tables here, please also add them to 1256 * intel_uncore_mock_selftests in selftests/intel_uncore.c so that they will be 1257 * scanned for obvious mistakes or typos by the selftests. 1258 */ 1259 1260 static const struct intel_forcewake_range __gen6_fw_ranges[] = { 1261 GEN_FW_RANGE(0x0, 0x3ffff, FORCEWAKE_RENDER), 1262 }; 1263 1264 static const struct intel_forcewake_range __vlv_fw_ranges[] = { 1265 GEN_FW_RANGE(0x2000, 0x3fff, FORCEWAKE_RENDER), 1266 GEN_FW_RANGE(0x5000, 0x7fff, FORCEWAKE_RENDER), 1267 GEN_FW_RANGE(0xb000, 0x11fff, FORCEWAKE_RENDER), 1268 GEN_FW_RANGE(0x12000, 0x13fff, FORCEWAKE_MEDIA), 1269 GEN_FW_RANGE(0x22000, 0x23fff, FORCEWAKE_MEDIA), 1270 GEN_FW_RANGE(0x2e000, 0x2ffff, FORCEWAKE_RENDER), 1271 GEN_FW_RANGE(0x30000, 0x3ffff, FORCEWAKE_MEDIA), 1272 }; 1273 1274 static const struct intel_forcewake_range __chv_fw_ranges[] = { 1275 GEN_FW_RANGE(0x2000, 0x3fff, FORCEWAKE_RENDER), 1276 GEN_FW_RANGE(0x4000, 0x4fff, FORCEWAKE_RENDER | FORCEWAKE_MEDIA), 1277 GEN_FW_RANGE(0x5200, 0x7fff, FORCEWAKE_RENDER), 1278 GEN_FW_RANGE(0x8000, 0x82ff, FORCEWAKE_RENDER | FORCEWAKE_MEDIA), 1279 GEN_FW_RANGE(0x8300, 0x84ff, FORCEWAKE_RENDER), 1280 GEN_FW_RANGE(0x8500, 0x85ff, FORCEWAKE_RENDER | FORCEWAKE_MEDIA), 1281 GEN_FW_RANGE(0x8800, 0x88ff, FORCEWAKE_MEDIA), 1282 GEN_FW_RANGE(0x9000, 0xafff, FORCEWAKE_RENDER | FORCEWAKE_MEDIA), 1283 GEN_FW_RANGE(0xb000, 0xb47f, FORCEWAKE_RENDER), 1284 GEN_FW_RANGE(0xd000, 0xd7ff, FORCEWAKE_MEDIA), 1285 GEN_FW_RANGE(0xe000, 0xe7ff, FORCEWAKE_RENDER), 1286 GEN_FW_RANGE(0xf000, 0xffff, FORCEWAKE_RENDER | FORCEWAKE_MEDIA), 1287 GEN_FW_RANGE(0x12000, 0x13fff, FORCEWAKE_MEDIA), 1288 GEN_FW_RANGE(0x1a000, 0x1bfff, FORCEWAKE_MEDIA), 1289 GEN_FW_RANGE(0x1e800, 0x1e9ff, FORCEWAKE_MEDIA), 1290 GEN_FW_RANGE(0x30000, 0x37fff, FORCEWAKE_MEDIA), 1291 }; 1292 1293 static const struct intel_forcewake_range __gen9_fw_ranges[] = { 1294 GEN_FW_RANGE(0x0, 0xaff, FORCEWAKE_GT), 1295 GEN_FW_RANGE(0xb00, 0x1fff, 0), /* uncore range */ 1296 GEN_FW_RANGE(0x2000, 0x26ff, FORCEWAKE_RENDER), 1297 GEN_FW_RANGE(0x2700, 0x2fff, FORCEWAKE_GT), 1298 GEN_FW_RANGE(0x3000, 0x3fff, FORCEWAKE_RENDER), 1299 GEN_FW_RANGE(0x4000, 0x51ff, FORCEWAKE_GT), 1300 GEN_FW_RANGE(0x5200, 0x7fff, FORCEWAKE_RENDER), 1301 GEN_FW_RANGE(0x8000, 0x812f, FORCEWAKE_GT), 1302 GEN_FW_RANGE(0x8130, 0x813f, FORCEWAKE_MEDIA), 1303 GEN_FW_RANGE(0x8140, 0x815f, FORCEWAKE_RENDER), 1304 GEN_FW_RANGE(0x8160, 0x82ff, FORCEWAKE_GT), 1305 GEN_FW_RANGE(0x8300, 0x84ff, FORCEWAKE_RENDER), 1306 GEN_FW_RANGE(0x8500, 0x87ff, FORCEWAKE_GT), 1307 GEN_FW_RANGE(0x8800, 0x89ff, FORCEWAKE_MEDIA), 1308 GEN_FW_RANGE(0x8a00, 0x8bff, FORCEWAKE_GT), 1309 GEN_FW_RANGE(0x8c00, 0x8cff, FORCEWAKE_RENDER), 1310 GEN_FW_RANGE(0x8d00, 0x93ff, FORCEWAKE_GT), 1311 GEN_FW_RANGE(0x9400, 0x97ff, FORCEWAKE_RENDER | FORCEWAKE_MEDIA), 1312 GEN_FW_RANGE(0x9800, 0xafff, FORCEWAKE_GT), 1313 GEN_FW_RANGE(0xb000, 0xb47f, FORCEWAKE_RENDER), 1314 GEN_FW_RANGE(0xb480, 0xcfff, FORCEWAKE_GT), 1315 GEN_FW_RANGE(0xd000, 0xd7ff, FORCEWAKE_MEDIA), 1316 GEN_FW_RANGE(0xd800, 0xdfff, FORCEWAKE_GT), 1317 GEN_FW_RANGE(0xe000, 0xe8ff, FORCEWAKE_RENDER), 1318 GEN_FW_RANGE(0xe900, 0x11fff, FORCEWAKE_GT), 1319 GEN_FW_RANGE(0x12000, 0x13fff, FORCEWAKE_MEDIA), 1320 GEN_FW_RANGE(0x14000, 0x19fff, FORCEWAKE_GT), 1321 GEN_FW_RANGE(0x1a000, 0x1e9ff, FORCEWAKE_MEDIA), 1322 GEN_FW_RANGE(0x1ea00, 0x243ff, FORCEWAKE_GT), 1323 GEN_FW_RANGE(0x24400, 0x247ff, FORCEWAKE_RENDER), 1324 GEN_FW_RANGE(0x24800, 0x2ffff, FORCEWAKE_GT), 1325 GEN_FW_RANGE(0x30000, 0x3ffff, FORCEWAKE_MEDIA), 1326 }; 1327 1328 static const struct intel_forcewake_range __gen11_fw_ranges[] = { 1329 GEN_FW_RANGE(0x0, 0x1fff, 0), /* uncore range */ 1330 GEN_FW_RANGE(0x2000, 0x26ff, FORCEWAKE_RENDER), 1331 GEN_FW_RANGE(0x2700, 0x2fff, FORCEWAKE_GT), 1332 GEN_FW_RANGE(0x3000, 0x3fff, FORCEWAKE_RENDER), 1333 GEN_FW_RANGE(0x4000, 0x51ff, FORCEWAKE_GT), 1334 GEN_FW_RANGE(0x5200, 0x7fff, FORCEWAKE_RENDER), 1335 GEN_FW_RANGE(0x8000, 0x813f, FORCEWAKE_GT), 1336 GEN_FW_RANGE(0x8140, 0x815f, FORCEWAKE_RENDER), 1337 GEN_FW_RANGE(0x8160, 0x82ff, FORCEWAKE_GT), 1338 GEN_FW_RANGE(0x8300, 0x84ff, FORCEWAKE_RENDER), 1339 GEN_FW_RANGE(0x8500, 0x87ff, FORCEWAKE_GT), 1340 GEN_FW_RANGE(0x8800, 0x8bff, 0), 1341 GEN_FW_RANGE(0x8c00, 0x8cff, FORCEWAKE_RENDER), 1342 GEN_FW_RANGE(0x8d00, 0x94cf, FORCEWAKE_GT), 1343 GEN_FW_RANGE(0x94d0, 0x955f, FORCEWAKE_RENDER), 1344 GEN_FW_RANGE(0x9560, 0x95ff, 0), 1345 GEN_FW_RANGE(0x9600, 0xafff, FORCEWAKE_GT), 1346 GEN_FW_RANGE(0xb000, 0xb47f, FORCEWAKE_RENDER), 1347 GEN_FW_RANGE(0xb480, 0xdeff, FORCEWAKE_GT), 1348 GEN_FW_RANGE(0xdf00, 0xe8ff, FORCEWAKE_RENDER), 1349 GEN_FW_RANGE(0xe900, 0x16dff, FORCEWAKE_GT), 1350 GEN_FW_RANGE(0x16e00, 0x19fff, FORCEWAKE_RENDER), 1351 GEN_FW_RANGE(0x1a000, 0x23fff, FORCEWAKE_GT), 1352 GEN_FW_RANGE(0x24000, 0x2407f, 0), 1353 GEN_FW_RANGE(0x24080, 0x2417f, FORCEWAKE_GT), 1354 GEN_FW_RANGE(0x24180, 0x242ff, FORCEWAKE_RENDER), 1355 GEN_FW_RANGE(0x24300, 0x243ff, FORCEWAKE_GT), 1356 GEN_FW_RANGE(0x24400, 0x24fff, FORCEWAKE_RENDER), 1357 GEN_FW_RANGE(0x25000, 0x3ffff, FORCEWAKE_GT), 1358 GEN_FW_RANGE(0x40000, 0x1bffff, 0), 1359 GEN_FW_RANGE(0x1c0000, 0x1c3fff, FORCEWAKE_MEDIA_VDBOX0), 1360 GEN_FW_RANGE(0x1c4000, 0x1c7fff, 0), 1361 GEN_FW_RANGE(0x1c8000, 0x1cffff, FORCEWAKE_MEDIA_VEBOX0), 1362 GEN_FW_RANGE(0x1d0000, 0x1d3fff, FORCEWAKE_MEDIA_VDBOX2), 1363 GEN_FW_RANGE(0x1d4000, 0x1dbfff, 0) 1364 }; 1365 1366 static const struct intel_forcewake_range __gen12_fw_ranges[] = { 1367 GEN_FW_RANGE(0x0, 0x1fff, 0), /* 1368 0x0 - 0xaff: reserved 1369 0xb00 - 0x1fff: always on */ 1370 GEN_FW_RANGE(0x2000, 0x26ff, FORCEWAKE_RENDER), 1371 GEN_FW_RANGE(0x2700, 0x27ff, FORCEWAKE_GT), 1372 GEN_FW_RANGE(0x2800, 0x2aff, FORCEWAKE_RENDER), 1373 GEN_FW_RANGE(0x2b00, 0x2fff, FORCEWAKE_GT), 1374 GEN_FW_RANGE(0x3000, 0x3fff, FORCEWAKE_RENDER), 1375 GEN_FW_RANGE(0x4000, 0x51ff, FORCEWAKE_GT), /* 1376 0x4000 - 0x48ff: gt 1377 0x4900 - 0x51ff: reserved */ 1378 GEN_FW_RANGE(0x5200, 0x7fff, FORCEWAKE_RENDER), /* 1379 0x5200 - 0x53ff: render 1380 0x5400 - 0x54ff: reserved 1381 0x5500 - 0x7fff: render */ 1382 GEN_FW_RANGE(0x8000, 0x813f, FORCEWAKE_GT), 1383 GEN_FW_RANGE(0x8140, 0x815f, FORCEWAKE_RENDER), 1384 GEN_FW_RANGE(0x8160, 0x81ff, 0), /* 1385 0x8160 - 0x817f: reserved 1386 0x8180 - 0x81ff: always on */ 1387 GEN_FW_RANGE(0x8200, 0x82ff, FORCEWAKE_GT), 1388 GEN_FW_RANGE(0x8300, 0x84ff, FORCEWAKE_RENDER), 1389 GEN_FW_RANGE(0x8500, 0x94cf, FORCEWAKE_GT), /* 1390 0x8500 - 0x87ff: gt 1391 0x8800 - 0x8fff: reserved 1392 0x9000 - 0x947f: gt 1393 0x9480 - 0x94cf: reserved */ 1394 GEN_FW_RANGE(0x94d0, 0x955f, FORCEWAKE_RENDER), 1395 GEN_FW_RANGE(0x9560, 0x97ff, 0), /* 1396 0x9560 - 0x95ff: always on 1397 0x9600 - 0x97ff: reserved */ 1398 GEN_FW_RANGE(0x9800, 0xafff, FORCEWAKE_GT), 1399 GEN_FW_RANGE(0xb000, 0xb3ff, FORCEWAKE_RENDER), 1400 GEN_FW_RANGE(0xb400, 0xcfff, FORCEWAKE_GT), /* 1401 0xb400 - 0xbf7f: gt 1402 0xb480 - 0xbfff: reserved 1403 0xc000 - 0xcfff: gt */ 1404 GEN_FW_RANGE(0xd000, 0xd7ff, 0), 1405 GEN_FW_RANGE(0xd800, 0xd8ff, FORCEWAKE_RENDER), 1406 GEN_FW_RANGE(0xd900, 0xdbff, FORCEWAKE_GT), 1407 GEN_FW_RANGE(0xdc00, 0xefff, FORCEWAKE_RENDER), /* 1408 0xdc00 - 0xddff: render 1409 0xde00 - 0xde7f: reserved 1410 0xde80 - 0xe8ff: render 1411 0xe900 - 0xefff: reserved */ 1412 GEN_FW_RANGE(0xf000, 0x147ff, FORCEWAKE_GT), /* 1413 0xf000 - 0xffff: gt 1414 0x10000 - 0x147ff: reserved */ 1415 GEN_FW_RANGE(0x14800, 0x1ffff, FORCEWAKE_RENDER), /* 1416 0x14800 - 0x14fff: render 1417 0x15000 - 0x16dff: reserved 1418 0x16e00 - 0x1bfff: render 1419 0x1c000 - 0x1ffff: reserved */ 1420 GEN_FW_RANGE(0x20000, 0x20fff, FORCEWAKE_MEDIA_VDBOX0), 1421 GEN_FW_RANGE(0x21000, 0x21fff, FORCEWAKE_MEDIA_VDBOX2), 1422 GEN_FW_RANGE(0x22000, 0x23fff, FORCEWAKE_GT), 1423 GEN_FW_RANGE(0x24000, 0x2417f, 0), /* 1424 0x24000 - 0x2407f: always on 1425 0x24080 - 0x2417f: reserved */ 1426 GEN_FW_RANGE(0x24180, 0x249ff, FORCEWAKE_GT), /* 1427 0x24180 - 0x241ff: gt 1428 0x24200 - 0x249ff: reserved */ 1429 GEN_FW_RANGE(0x24a00, 0x251ff, FORCEWAKE_RENDER), /* 1430 0x24a00 - 0x24a7f: render 1431 0x24a80 - 0x251ff: reserved */ 1432 GEN_FW_RANGE(0x25200, 0x255ff, FORCEWAKE_GT), /* 1433 0x25200 - 0x252ff: gt 1434 0x25300 - 0x255ff: reserved */ 1435 GEN_FW_RANGE(0x25600, 0x2567f, FORCEWAKE_MEDIA_VDBOX0), 1436 GEN_FW_RANGE(0x25680, 0x259ff, FORCEWAKE_MEDIA_VDBOX2), /* 1437 0x25680 - 0x256ff: VD2 1438 0x25700 - 0x259ff: reserved */ 1439 GEN_FW_RANGE(0x25a00, 0x25a7f, FORCEWAKE_MEDIA_VDBOX0), 1440 GEN_FW_RANGE(0x25a80, 0x2ffff, FORCEWAKE_MEDIA_VDBOX2), /* 1441 0x25a80 - 0x25aff: VD2 1442 0x25b00 - 0x2ffff: reserved */ 1443 GEN_FW_RANGE(0x30000, 0x3ffff, FORCEWAKE_GT), 1444 GEN_FW_RANGE(0x40000, 0x1bffff, 0), 1445 GEN_FW_RANGE(0x1c0000, 0x1c3fff, FORCEWAKE_MEDIA_VDBOX0), /* 1446 0x1c0000 - 0x1c2bff: VD0 1447 0x1c2c00 - 0x1c2cff: reserved 1448 0x1c2d00 - 0x1c2dff: VD0 1449 0x1c2e00 - 0x1c3eff: reserved 1450 0x1c3f00 - 0x1c3fff: VD0 */ 1451 GEN_FW_RANGE(0x1c4000, 0x1c7fff, 0), 1452 GEN_FW_RANGE(0x1c8000, 0x1cbfff, FORCEWAKE_MEDIA_VEBOX0), /* 1453 0x1c8000 - 0x1ca0ff: VE0 1454 0x1ca100 - 0x1cbeff: reserved 1455 0x1cbf00 - 0x1cbfff: VE0 */ 1456 GEN_FW_RANGE(0x1cc000, 0x1cffff, FORCEWAKE_MEDIA_VDBOX0), /* 1457 0x1cc000 - 0x1ccfff: VD0 1458 0x1cd000 - 0x1cffff: reserved */ 1459 GEN_FW_RANGE(0x1d0000, 0x1d3fff, FORCEWAKE_MEDIA_VDBOX2), /* 1460 0x1d0000 - 0x1d2bff: VD2 1461 0x1d2c00 - 0x1d2cff: reserved 1462 0x1d2d00 - 0x1d2dff: VD2 1463 0x1d2e00 - 0x1d3eff: reserved 1464 0x1d3f00 - 0x1d3fff: VD2 */ 1465 }; 1466 1467 /* 1468 * Graphics IP version 12.55 brings a slight change to the 0xd800 range, 1469 * switching it from the GT domain to the render domain. 1470 */ 1471 #define XEHP_FWRANGES(FW_RANGE_D800) \ 1472 GEN_FW_RANGE(0x0, 0x1fff, 0), /* \ 1473 0x0 - 0xaff: reserved \ 1474 0xb00 - 0x1fff: always on */ \ 1475 GEN_FW_RANGE(0x2000, 0x26ff, FORCEWAKE_RENDER), \ 1476 GEN_FW_RANGE(0x2700, 0x4aff, FORCEWAKE_GT), \ 1477 GEN_FW_RANGE(0x4b00, 0x51ff, 0), /* \ 1478 0x4b00 - 0x4fff: reserved \ 1479 0x5000 - 0x51ff: always on */ \ 1480 GEN_FW_RANGE(0x5200, 0x7fff, FORCEWAKE_RENDER), \ 1481 GEN_FW_RANGE(0x8000, 0x813f, FORCEWAKE_GT), \ 1482 GEN_FW_RANGE(0x8140, 0x815f, FORCEWAKE_RENDER), \ 1483 GEN_FW_RANGE(0x8160, 0x81ff, 0), /* \ 1484 0x8160 - 0x817f: reserved \ 1485 0x8180 - 0x81ff: always on */ \ 1486 GEN_FW_RANGE(0x8200, 0x82ff, FORCEWAKE_GT), \ 1487 GEN_FW_RANGE(0x8300, 0x84ff, FORCEWAKE_RENDER), \ 1488 GEN_FW_RANGE(0x8500, 0x8cff, FORCEWAKE_GT), /* \ 1489 0x8500 - 0x87ff: gt \ 1490 0x8800 - 0x8c7f: reserved \ 1491 0x8c80 - 0x8cff: gt (DG2 only) */ \ 1492 GEN_FW_RANGE(0x8d00, 0x8fff, FORCEWAKE_RENDER), /* \ 1493 0x8d00 - 0x8dff: render (DG2 only) \ 1494 0x8e00 - 0x8fff: reserved */ \ 1495 GEN_FW_RANGE(0x9000, 0x94cf, FORCEWAKE_GT), /* \ 1496 0x9000 - 0x947f: gt \ 1497 0x9480 - 0x94cf: reserved */ \ 1498 GEN_FW_RANGE(0x94d0, 0x955f, FORCEWAKE_RENDER), \ 1499 GEN_FW_RANGE(0x9560, 0x967f, 0), /* \ 1500 0x9560 - 0x95ff: always on \ 1501 0x9600 - 0x967f: reserved */ \ 1502 GEN_FW_RANGE(0x9680, 0x97ff, FORCEWAKE_RENDER), /* \ 1503 0x9680 - 0x96ff: render (DG2 only) \ 1504 0x9700 - 0x97ff: reserved */ \ 1505 GEN_FW_RANGE(0x9800, 0xcfff, FORCEWAKE_GT), /* \ 1506 0x9800 - 0xb4ff: gt \ 1507 0xb500 - 0xbfff: reserved \ 1508 0xc000 - 0xcfff: gt */ \ 1509 GEN_FW_RANGE(0xd000, 0xd7ff, 0), \ 1510 GEN_FW_RANGE(0xd800, 0xd87f, FW_RANGE_D800), \ 1511 GEN_FW_RANGE(0xd880, 0xdbff, FORCEWAKE_GT), \ 1512 GEN_FW_RANGE(0xdc00, 0xdcff, FORCEWAKE_RENDER), \ 1513 GEN_FW_RANGE(0xdd00, 0xde7f, FORCEWAKE_GT), /* \ 1514 0xdd00 - 0xddff: gt \ 1515 0xde00 - 0xde7f: reserved */ \ 1516 GEN_FW_RANGE(0xde80, 0xe8ff, FORCEWAKE_RENDER), /* \ 1517 0xde80 - 0xdfff: render \ 1518 0xe000 - 0xe0ff: reserved \ 1519 0xe100 - 0xe8ff: render */ \ 1520 GEN_FW_RANGE(0xe900, 0xffff, FORCEWAKE_GT), /* \ 1521 0xe900 - 0xe9ff: gt \ 1522 0xea00 - 0xefff: reserved \ 1523 0xf000 - 0xffff: gt */ \ 1524 GEN_FW_RANGE(0x10000, 0x12fff, 0), /* \ 1525 0x10000 - 0x11fff: reserved \ 1526 0x12000 - 0x127ff: always on \ 1527 0x12800 - 0x12fff: reserved */ \ 1528 GEN_FW_RANGE(0x13000, 0x131ff, FORCEWAKE_MEDIA_VDBOX0), /* DG2 only */ \ 1529 GEN_FW_RANGE(0x13200, 0x13fff, FORCEWAKE_MEDIA_VDBOX2), /* \ 1530 0x13200 - 0x133ff: VD2 (DG2 only) \ 1531 0x13400 - 0x13fff: reserved */ \ 1532 GEN_FW_RANGE(0x14000, 0x141ff, FORCEWAKE_MEDIA_VDBOX0), /* XEHPSDV only */ \ 1533 GEN_FW_RANGE(0x14200, 0x143ff, FORCEWAKE_MEDIA_VDBOX2), /* XEHPSDV only */ \ 1534 GEN_FW_RANGE(0x14400, 0x145ff, FORCEWAKE_MEDIA_VDBOX4), /* XEHPSDV only */ \ 1535 GEN_FW_RANGE(0x14600, 0x147ff, FORCEWAKE_MEDIA_VDBOX6), /* XEHPSDV only */ \ 1536 GEN_FW_RANGE(0x14800, 0x14fff, FORCEWAKE_RENDER), \ 1537 GEN_FW_RANGE(0x15000, 0x16dff, FORCEWAKE_GT), /* \ 1538 0x15000 - 0x15fff: gt (DG2 only) \ 1539 0x16000 - 0x16dff: reserved */ \ 1540 GEN_FW_RANGE(0x16e00, 0x1ffff, FORCEWAKE_RENDER), \ 1541 GEN_FW_RANGE(0x20000, 0x21fff, FORCEWAKE_MEDIA_VDBOX0), /* \ 1542 0x20000 - 0x20fff: VD0 (XEHPSDV only) \ 1543 0x21000 - 0x21fff: reserved */ \ 1544 GEN_FW_RANGE(0x22000, 0x23fff, FORCEWAKE_GT), \ 1545 GEN_FW_RANGE(0x24000, 0x2417f, 0), /* \ 1546 0x24000 - 0x2407f: always on \ 1547 0x24080 - 0x2417f: reserved */ \ 1548 GEN_FW_RANGE(0x24180, 0x249ff, FORCEWAKE_GT), /* \ 1549 0x24180 - 0x241ff: gt \ 1550 0x24200 - 0x249ff: reserved */ \ 1551 GEN_FW_RANGE(0x24a00, 0x251ff, FORCEWAKE_RENDER), /* \ 1552 0x24a00 - 0x24a7f: render \ 1553 0x24a80 - 0x251ff: reserved */ \ 1554 GEN_FW_RANGE(0x25200, 0x25fff, FORCEWAKE_GT), /* \ 1555 0x25200 - 0x252ff: gt \ 1556 0x25300 - 0x25fff: reserved */ \ 1557 GEN_FW_RANGE(0x26000, 0x2ffff, FORCEWAKE_RENDER), /* \ 1558 0x26000 - 0x27fff: render \ 1559 0x28000 - 0x29fff: reserved \ 1560 0x2a000 - 0x2ffff: undocumented */ \ 1561 GEN_FW_RANGE(0x30000, 0x3ffff, FORCEWAKE_GT), \ 1562 GEN_FW_RANGE(0x40000, 0x1bffff, 0), \ 1563 GEN_FW_RANGE(0x1c0000, 0x1c3fff, FORCEWAKE_MEDIA_VDBOX0), /* \ 1564 0x1c0000 - 0x1c2bff: VD0 \ 1565 0x1c2c00 - 0x1c2cff: reserved \ 1566 0x1c2d00 - 0x1c2dff: VD0 \ 1567 0x1c2e00 - 0x1c3eff: VD0 (DG2 only) \ 1568 0x1c3f00 - 0x1c3fff: VD0 */ \ 1569 GEN_FW_RANGE(0x1c4000, 0x1c7fff, FORCEWAKE_MEDIA_VDBOX1), /* \ 1570 0x1c4000 - 0x1c6bff: VD1 \ 1571 0x1c6c00 - 0x1c6cff: reserved \ 1572 0x1c6d00 - 0x1c6dff: VD1 \ 1573 0x1c6e00 - 0x1c7fff: reserved */ \ 1574 GEN_FW_RANGE(0x1c8000, 0x1cbfff, FORCEWAKE_MEDIA_VEBOX0), /* \ 1575 0x1c8000 - 0x1ca0ff: VE0 \ 1576 0x1ca100 - 0x1cbfff: reserved */ \ 1577 GEN_FW_RANGE(0x1cc000, 0x1ccfff, FORCEWAKE_MEDIA_VDBOX0), \ 1578 GEN_FW_RANGE(0x1cd000, 0x1cdfff, FORCEWAKE_MEDIA_VDBOX2), \ 1579 GEN_FW_RANGE(0x1ce000, 0x1cefff, FORCEWAKE_MEDIA_VDBOX4), \ 1580 GEN_FW_RANGE(0x1cf000, 0x1cffff, FORCEWAKE_MEDIA_VDBOX6), \ 1581 GEN_FW_RANGE(0x1d0000, 0x1d3fff, FORCEWAKE_MEDIA_VDBOX2), /* \ 1582 0x1d0000 - 0x1d2bff: VD2 \ 1583 0x1d2c00 - 0x1d2cff: reserved \ 1584 0x1d2d00 - 0x1d2dff: VD2 \ 1585 0x1d2e00 - 0x1d3dff: VD2 (DG2 only) \ 1586 0x1d3e00 - 0x1d3eff: reserved \ 1587 0x1d3f00 - 0x1d3fff: VD2 */ \ 1588 GEN_FW_RANGE(0x1d4000, 0x1d7fff, FORCEWAKE_MEDIA_VDBOX3), /* \ 1589 0x1d4000 - 0x1d6bff: VD3 \ 1590 0x1d6c00 - 0x1d6cff: reserved \ 1591 0x1d6d00 - 0x1d6dff: VD3 \ 1592 0x1d6e00 - 0x1d7fff: reserved */ \ 1593 GEN_FW_RANGE(0x1d8000, 0x1dffff, FORCEWAKE_MEDIA_VEBOX1), /* \ 1594 0x1d8000 - 0x1da0ff: VE1 \ 1595 0x1da100 - 0x1dffff: reserved */ \ 1596 GEN_FW_RANGE(0x1e0000, 0x1e3fff, FORCEWAKE_MEDIA_VDBOX4), /* \ 1597 0x1e0000 - 0x1e2bff: VD4 \ 1598 0x1e2c00 - 0x1e2cff: reserved \ 1599 0x1e2d00 - 0x1e2dff: VD4 \ 1600 0x1e2e00 - 0x1e3eff: reserved \ 1601 0x1e3f00 - 0x1e3fff: VD4 */ \ 1602 GEN_FW_RANGE(0x1e4000, 0x1e7fff, FORCEWAKE_MEDIA_VDBOX5), /* \ 1603 0x1e4000 - 0x1e6bff: VD5 \ 1604 0x1e6c00 - 0x1e6cff: reserved \ 1605 0x1e6d00 - 0x1e6dff: VD5 \ 1606 0x1e6e00 - 0x1e7fff: reserved */ \ 1607 GEN_FW_RANGE(0x1e8000, 0x1effff, FORCEWAKE_MEDIA_VEBOX2), /* \ 1608 0x1e8000 - 0x1ea0ff: VE2 \ 1609 0x1ea100 - 0x1effff: reserved */ \ 1610 GEN_FW_RANGE(0x1f0000, 0x1f3fff, FORCEWAKE_MEDIA_VDBOX6), /* \ 1611 0x1f0000 - 0x1f2bff: VD6 \ 1612 0x1f2c00 - 0x1f2cff: reserved \ 1613 0x1f2d00 - 0x1f2dff: VD6 \ 1614 0x1f2e00 - 0x1f3eff: reserved \ 1615 0x1f3f00 - 0x1f3fff: VD6 */ \ 1616 GEN_FW_RANGE(0x1f4000, 0x1f7fff, FORCEWAKE_MEDIA_VDBOX7), /* \ 1617 0x1f4000 - 0x1f6bff: VD7 \ 1618 0x1f6c00 - 0x1f6cff: reserved \ 1619 0x1f6d00 - 0x1f6dff: VD7 \ 1620 0x1f6e00 - 0x1f7fff: reserved */ \ 1621 GEN_FW_RANGE(0x1f8000, 0x1fa0ff, FORCEWAKE_MEDIA_VEBOX3), 1622 1623 static const struct intel_forcewake_range __xehp_fw_ranges[] = { 1624 XEHP_FWRANGES(FORCEWAKE_GT) 1625 }; 1626 1627 static const struct intel_forcewake_range __dg2_fw_ranges[] = { 1628 XEHP_FWRANGES(FORCEWAKE_RENDER) 1629 }; 1630 1631 static const struct intel_forcewake_range __pvc_fw_ranges[] = { 1632 GEN_FW_RANGE(0x0, 0xaff, 0), 1633 GEN_FW_RANGE(0xb00, 0xbff, FORCEWAKE_GT), 1634 GEN_FW_RANGE(0xc00, 0xfff, 0), 1635 GEN_FW_RANGE(0x1000, 0x1fff, FORCEWAKE_GT), 1636 GEN_FW_RANGE(0x2000, 0x26ff, FORCEWAKE_RENDER), 1637 GEN_FW_RANGE(0x2700, 0x2fff, FORCEWAKE_GT), 1638 GEN_FW_RANGE(0x3000, 0x3fff, FORCEWAKE_RENDER), 1639 GEN_FW_RANGE(0x4000, 0x813f, FORCEWAKE_GT), /* 1640 0x4000 - 0x4aff: gt 1641 0x4b00 - 0x4fff: reserved 1642 0x5000 - 0x51ff: gt 1643 0x5200 - 0x52ff: reserved 1644 0x5300 - 0x53ff: gt 1645 0x5400 - 0x7fff: reserved 1646 0x8000 - 0x813f: gt */ 1647 GEN_FW_RANGE(0x8140, 0x817f, FORCEWAKE_RENDER), 1648 GEN_FW_RANGE(0x8180, 0x81ff, 0), 1649 GEN_FW_RANGE(0x8200, 0x94cf, FORCEWAKE_GT), /* 1650 0x8200 - 0x82ff: gt 1651 0x8300 - 0x84ff: reserved 1652 0x8500 - 0x887f: gt 1653 0x8880 - 0x8a7f: reserved 1654 0x8a80 - 0x8aff: gt 1655 0x8b00 - 0x8fff: reserved 1656 0x9000 - 0x947f: gt 1657 0x9480 - 0x94cf: reserved */ 1658 GEN_FW_RANGE(0x94d0, 0x955f, FORCEWAKE_RENDER), 1659 GEN_FW_RANGE(0x9560, 0x967f, 0), /* 1660 0x9560 - 0x95ff: always on 1661 0x9600 - 0x967f: reserved */ 1662 GEN_FW_RANGE(0x9680, 0x97ff, FORCEWAKE_RENDER), /* 1663 0x9680 - 0x96ff: render 1664 0x9700 - 0x97ff: reserved */ 1665 GEN_FW_RANGE(0x9800, 0xcfff, FORCEWAKE_GT), /* 1666 0x9800 - 0xb4ff: gt 1667 0xb500 - 0xbfff: reserved 1668 0xc000 - 0xcfff: gt */ 1669 GEN_FW_RANGE(0xd000, 0xd3ff, 0), 1670 GEN_FW_RANGE(0xd400, 0xdbff, FORCEWAKE_GT), 1671 GEN_FW_RANGE(0xdc00, 0xdcff, FORCEWAKE_RENDER), 1672 GEN_FW_RANGE(0xdd00, 0xde7f, FORCEWAKE_GT), /* 1673 0xdd00 - 0xddff: gt 1674 0xde00 - 0xde7f: reserved */ 1675 GEN_FW_RANGE(0xde80, 0xe8ff, FORCEWAKE_RENDER), /* 1676 0xde80 - 0xdeff: render 1677 0xdf00 - 0xe1ff: reserved 1678 0xe200 - 0xe7ff: render 1679 0xe800 - 0xe8ff: reserved */ 1680 GEN_FW_RANGE(0xe900, 0x11fff, FORCEWAKE_GT), /* 1681 0xe900 - 0xe9ff: gt 1682 0xea00 - 0xebff: reserved 1683 0xec00 - 0xffff: gt 1684 0x10000 - 0x11fff: reserved */ 1685 GEN_FW_RANGE(0x12000, 0x12fff, 0), /* 1686 0x12000 - 0x127ff: always on 1687 0x12800 - 0x12fff: reserved */ 1688 GEN_FW_RANGE(0x13000, 0x19fff, FORCEWAKE_GT), /* 1689 0x13000 - 0x135ff: gt 1690 0x13600 - 0x147ff: reserved 1691 0x14800 - 0x153ff: gt 1692 0x15400 - 0x19fff: reserved */ 1693 GEN_FW_RANGE(0x1a000, 0x21fff, FORCEWAKE_RENDER), /* 1694 0x1a000 - 0x1ffff: render 1695 0x20000 - 0x21fff: reserved */ 1696 GEN_FW_RANGE(0x22000, 0x23fff, FORCEWAKE_GT), 1697 GEN_FW_RANGE(0x24000, 0x2417f, 0), /* 1698 24000 - 0x2407f: always on 1699 24080 - 0x2417f: reserved */ 1700 GEN_FW_RANGE(0x24180, 0x25fff, FORCEWAKE_GT), /* 1701 0x24180 - 0x241ff: gt 1702 0x24200 - 0x251ff: reserved 1703 0x25200 - 0x252ff: gt 1704 0x25300 - 0x25fff: reserved */ 1705 GEN_FW_RANGE(0x26000, 0x2ffff, FORCEWAKE_RENDER), /* 1706 0x26000 - 0x27fff: render 1707 0x28000 - 0x2ffff: reserved */ 1708 GEN_FW_RANGE(0x30000, 0x3ffff, FORCEWAKE_GT), 1709 GEN_FW_RANGE(0x40000, 0x1bffff, 0), 1710 GEN_FW_RANGE(0x1c0000, 0x1c3fff, FORCEWAKE_MEDIA_VDBOX0), /* 1711 0x1c0000 - 0x1c2bff: VD0 1712 0x1c2c00 - 0x1c2cff: reserved 1713 0x1c2d00 - 0x1c2dff: VD0 1714 0x1c2e00 - 0x1c3eff: reserved 1715 0x1c3f00 - 0x1c3fff: VD0 */ 1716 GEN_FW_RANGE(0x1c4000, 0x1cffff, FORCEWAKE_MEDIA_VDBOX1), /* 1717 0x1c4000 - 0x1c6aff: VD1 1718 0x1c6b00 - 0x1c7eff: reserved 1719 0x1c7f00 - 0x1c7fff: VD1 1720 0x1c8000 - 0x1cffff: reserved */ 1721 GEN_FW_RANGE(0x1d0000, 0x23ffff, FORCEWAKE_MEDIA_VDBOX2), /* 1722 0x1d0000 - 0x1d2aff: VD2 1723 0x1d2b00 - 0x1d3eff: reserved 1724 0x1d3f00 - 0x1d3fff: VD2 1725 0x1d4000 - 0x23ffff: reserved */ 1726 GEN_FW_RANGE(0x240000, 0x3dffff, 0), 1727 GEN_FW_RANGE(0x3e0000, 0x3effff, FORCEWAKE_GT), 1728 }; 1729 1730 static const struct intel_forcewake_range __mtl_fw_ranges[] = { 1731 GEN_FW_RANGE(0x0, 0xaff, 0), 1732 GEN_FW_RANGE(0xb00, 0xbff, FORCEWAKE_GT), 1733 GEN_FW_RANGE(0xc00, 0xfff, 0), 1734 GEN_FW_RANGE(0x1000, 0x1fff, FORCEWAKE_GT), 1735 GEN_FW_RANGE(0x2000, 0x26ff, FORCEWAKE_RENDER), 1736 GEN_FW_RANGE(0x2700, 0x2fff, FORCEWAKE_GT), 1737 GEN_FW_RANGE(0x3000, 0x3fff, FORCEWAKE_RENDER), 1738 GEN_FW_RANGE(0x4000, 0x51ff, FORCEWAKE_GT), /* 1739 0x4000 - 0x48ff: render 1740 0x4900 - 0x51ff: reserved */ 1741 GEN_FW_RANGE(0x5200, 0x7fff, FORCEWAKE_RENDER), /* 1742 0x5200 - 0x53ff: render 1743 0x5400 - 0x54ff: reserved 1744 0x5500 - 0x7fff: render */ 1745 GEN_FW_RANGE(0x8000, 0x813f, FORCEWAKE_GT), 1746 GEN_FW_RANGE(0x8140, 0x817f, FORCEWAKE_RENDER), /* 1747 0x8140 - 0x815f: render 1748 0x8160 - 0x817f: reserved */ 1749 GEN_FW_RANGE(0x8180, 0x81ff, 0), 1750 GEN_FW_RANGE(0x8200, 0x94cf, FORCEWAKE_GT), /* 1751 0x8200 - 0x87ff: gt 1752 0x8800 - 0x8dff: reserved 1753 0x8e00 - 0x8f7f: gt 1754 0x8f80 - 0x8fff: reserved 1755 0x9000 - 0x947f: gt 1756 0x9480 - 0x94cf: reserved */ 1757 GEN_FW_RANGE(0x94d0, 0x955f, FORCEWAKE_RENDER), 1758 GEN_FW_RANGE(0x9560, 0x967f, 0), /* 1759 0x9560 - 0x95ff: always on 1760 0x9600 - 0x967f: reserved */ 1761 GEN_FW_RANGE(0x9680, 0x97ff, FORCEWAKE_RENDER), /* 1762 0x9680 - 0x96ff: render 1763 0x9700 - 0x97ff: reserved */ 1764 GEN_FW_RANGE(0x9800, 0xcfff, FORCEWAKE_GT), /* 1765 0x9800 - 0xb4ff: gt 1766 0xb500 - 0xbfff: reserved 1767 0xc000 - 0xcfff: gt */ 1768 GEN_FW_RANGE(0xd000, 0xd7ff, 0), /* 1769 0xd000 - 0xd3ff: always on 1770 0xd400 - 0xd7ff: reserved */ 1771 GEN_FW_RANGE(0xd800, 0xd87f, FORCEWAKE_RENDER), 1772 GEN_FW_RANGE(0xd880, 0xdbff, FORCEWAKE_GT), 1773 GEN_FW_RANGE(0xdc00, 0xdcff, FORCEWAKE_RENDER), 1774 GEN_FW_RANGE(0xdd00, 0xde7f, FORCEWAKE_GT), /* 1775 0xdd00 - 0xddff: gt 1776 0xde00 - 0xde7f: reserved */ 1777 GEN_FW_RANGE(0xde80, 0xe8ff, FORCEWAKE_RENDER), /* 1778 0xde80 - 0xdfff: render 1779 0xe000 - 0xe0ff: reserved 1780 0xe100 - 0xe8ff: render */ 1781 GEN_FW_RANGE(0xe900, 0xe9ff, FORCEWAKE_GT), 1782 GEN_FW_RANGE(0xea00, 0x147ff, 0), /* 1783 0xea00 - 0x11fff: reserved 1784 0x12000 - 0x127ff: always on 1785 0x12800 - 0x147ff: reserved */ 1786 GEN_FW_RANGE(0x14800, 0x19fff, FORCEWAKE_GT), /* 1787 0x14800 - 0x153ff: gt 1788 0x15400 - 0x19fff: reserved */ 1789 GEN_FW_RANGE(0x1a000, 0x21fff, FORCEWAKE_RENDER), /* 1790 0x1a000 - 0x1bfff: render 1791 0x1c000 - 0x21fff: reserved */ 1792 GEN_FW_RANGE(0x22000, 0x23fff, FORCEWAKE_GT), 1793 GEN_FW_RANGE(0x24000, 0x2ffff, 0), /* 1794 0x24000 - 0x2407f: always on 1795 0x24080 - 0x2ffff: reserved */ 1796 GEN_FW_RANGE(0x30000, 0x3ffff, FORCEWAKE_GT) 1797 }; 1798 1799 /* 1800 * Note that the register ranges here are the final offsets after 1801 * translation of the GSI block to the 0x380000 offset. 1802 * 1803 * NOTE: There are a couple MCR ranges near the bottom of this table 1804 * that need to power up either VD0 or VD2 depending on which replicated 1805 * instance of the register we're trying to access. Our forcewake logic 1806 * at the moment doesn't have a good way to take steering into consideration, 1807 * and the driver doesn't even access any registers in those ranges today, 1808 * so for now we just mark those ranges as FORCEWAKE_ALL. That will ensure 1809 * proper operation if we do start using the ranges in the future, and we 1810 * can determine at that time whether it's worth adding extra complexity to 1811 * the forcewake handling to take steering into consideration. 1812 */ 1813 static const struct intel_forcewake_range __xelpmp_fw_ranges[] = { 1814 GEN_FW_RANGE(0x0, 0x115fff, 0), /* render GT range */ 1815 GEN_FW_RANGE(0x116000, 0x11ffff, FORCEWAKE_GSC), /* 1816 0x116000 - 0x117fff: gsc 1817 0x118000 - 0x119fff: reserved 1818 0x11a000 - 0x11efff: gsc 1819 0x11f000 - 0x11ffff: reserved */ 1820 GEN_FW_RANGE(0x120000, 0x1bffff, 0), /* non-GT range */ 1821 GEN_FW_RANGE(0x1c0000, 0x1c7fff, FORCEWAKE_MEDIA_VDBOX0), /* 1822 0x1c0000 - 0x1c3dff: VD0 1823 0x1c3e00 - 0x1c3eff: reserved 1824 0x1c3f00 - 0x1c3fff: VD0 1825 0x1c4000 - 0x1c7fff: reserved */ 1826 GEN_FW_RANGE(0x1c8000, 0x1cbfff, FORCEWAKE_MEDIA_VEBOX0), /* 1827 0x1c8000 - 0x1ca0ff: VE0 1828 0x1ca100 - 0x1cbfff: reserved */ 1829 GEN_FW_RANGE(0x1cc000, 0x1cffff, FORCEWAKE_MEDIA_VDBOX0), /* 1830 0x1cc000 - 0x1cdfff: VD0 1831 0x1ce000 - 0x1cffff: reserved */ 1832 GEN_FW_RANGE(0x1d0000, 0x1d7fff, FORCEWAKE_MEDIA_VDBOX2), /* 1833 0x1d0000 - 0x1d3dff: VD2 1834 0x1d3e00 - 0x1d3eff: reserved 1835 0x1d4000 - 0x1d7fff: VD2 */ 1836 GEN_FW_RANGE(0x1d8000, 0x1da0ff, FORCEWAKE_MEDIA_VEBOX1), 1837 GEN_FW_RANGE(0x1da100, 0x380aff, 0), /* 1838 0x1da100 - 0x23ffff: reserved 1839 0x240000 - 0x37ffff: non-GT range 1840 0x380000 - 0x380aff: reserved */ 1841 GEN_FW_RANGE(0x380b00, 0x380bff, FORCEWAKE_GT), 1842 GEN_FW_RANGE(0x380c00, 0x380fff, 0), 1843 GEN_FW_RANGE(0x381000, 0x38817f, FORCEWAKE_GT), /* 1844 0x381000 - 0x381fff: gt 1845 0x382000 - 0x383fff: reserved 1846 0x384000 - 0x384aff: gt 1847 0x384b00 - 0x3851ff: reserved 1848 0x385200 - 0x3871ff: gt 1849 0x387200 - 0x387fff: reserved 1850 0x388000 - 0x38813f: gt 1851 0x388140 - 0x38817f: reserved */ 1852 GEN_FW_RANGE(0x388180, 0x3882ff, 0), /* 1853 0x388180 - 0x3881ff: always on 1854 0x388200 - 0x3882ff: reserved */ 1855 GEN_FW_RANGE(0x388300, 0x38955f, FORCEWAKE_GT), /* 1856 0x388300 - 0x38887f: gt 1857 0x388880 - 0x388fff: reserved 1858 0x389000 - 0x38947f: gt 1859 0x389480 - 0x38955f: reserved */ 1860 GEN_FW_RANGE(0x389560, 0x389fff, 0), /* 1861 0x389560 - 0x3895ff: always on 1862 0x389600 - 0x389fff: reserved */ 1863 GEN_FW_RANGE(0x38a000, 0x38cfff, FORCEWAKE_GT), /* 1864 0x38a000 - 0x38afff: gt 1865 0x38b000 - 0x38bfff: reserved 1866 0x38c000 - 0x38cfff: gt */ 1867 GEN_FW_RANGE(0x38d000, 0x38d11f, 0), 1868 GEN_FW_RANGE(0x38d120, 0x391fff, FORCEWAKE_GT), /* 1869 0x38d120 - 0x38dfff: gt 1870 0x38e000 - 0x38efff: reserved 1871 0x38f000 - 0x38ffff: gt 1872 0x389000 - 0x391fff: reserved */ 1873 GEN_FW_RANGE(0x392000, 0x392fff, 0), /* 1874 0x392000 - 0x3927ff: always on 1875 0x392800 - 0x292fff: reserved */ 1876 GEN_FW_RANGE(0x393000, 0x3931ff, FORCEWAKE_GT), 1877 GEN_FW_RANGE(0x393200, 0x39323f, FORCEWAKE_ALL), /* instance-based, see note above */ 1878 GEN_FW_RANGE(0x393240, 0x3933ff, FORCEWAKE_GT), 1879 GEN_FW_RANGE(0x393400, 0x3934ff, FORCEWAKE_ALL), /* instance-based, see note above */ 1880 GEN_FW_RANGE(0x393500, 0x393c7f, 0), /* 1881 0x393500 - 0x393bff: reserved 1882 0x393c00 - 0x393c7f: always on */ 1883 GEN_FW_RANGE(0x393c80, 0x393dff, FORCEWAKE_GT), 1884 }; 1885 1886 static void 1887 ilk_dummy_write(struct intel_uncore *uncore) 1888 { 1889 /* WaIssueDummyWriteToWakeupFromRC6:ilk Issue a dummy write to wake up 1890 * the chip from rc6 before touching it for real. MI_MODE is masked, 1891 * hence harmless to write 0 into. */ 1892 __raw_uncore_write32(uncore, RING_MI_MODE(RENDER_RING_BASE), 0); 1893 } 1894 1895 static void 1896 __unclaimed_reg_debug(struct intel_uncore *uncore, 1897 const i915_reg_t reg, 1898 const bool read) 1899 { 1900 if (drm_WARN(&uncore->i915->drm, 1901 check_for_unclaimed_mmio(uncore), 1902 "Unclaimed %s register 0x%x\n", 1903 read ? "read from" : "write to", 1904 i915_mmio_reg_offset(reg))) 1905 /* Only report the first N failures */ 1906 uncore->i915->params.mmio_debug--; 1907 } 1908 1909 static void 1910 __unclaimed_previous_reg_debug(struct intel_uncore *uncore, 1911 const i915_reg_t reg, 1912 const bool read) 1913 { 1914 if (check_for_unclaimed_mmio(uncore)) 1915 drm_dbg(&uncore->i915->drm, 1916 "Unclaimed access detected before %s register 0x%x\n", 1917 read ? "read from" : "write to", 1918 i915_mmio_reg_offset(reg)); 1919 } 1920 1921 static inline void 1922 unclaimed_reg_debug(struct intel_uncore *uncore, 1923 const i915_reg_t reg, 1924 const bool read, 1925 const bool before) 1926 { 1927 if (likely(!uncore->i915->params.mmio_debug) || !uncore->debug) 1928 return; 1929 1930 /* interrupts are disabled and re-enabled around uncore->lock usage */ 1931 lockdep_assert_held(&uncore->lock); 1932 1933 if (before) { 1934 spin_lock(&uncore->debug->lock); 1935 __unclaimed_previous_reg_debug(uncore, reg, read); 1936 } else { 1937 __unclaimed_reg_debug(uncore, reg, read); 1938 spin_unlock(&uncore->debug->lock); 1939 } 1940 } 1941 1942 #define __vgpu_read(x) \ 1943 static u##x \ 1944 vgpu_read##x(struct intel_uncore *uncore, i915_reg_t reg, bool trace) { \ 1945 u##x val = __raw_uncore_read##x(uncore, reg); \ 1946 trace_i915_reg_rw(false, reg, val, sizeof(val), trace); \ 1947 return val; \ 1948 } 1949 __vgpu_read(8) 1950 __vgpu_read(16) 1951 __vgpu_read(32) 1952 __vgpu_read(64) 1953 1954 #define GEN2_READ_HEADER(x) \ 1955 u##x val = 0; \ 1956 assert_rpm_wakelock_held(uncore->rpm); 1957 1958 #define GEN2_READ_FOOTER \ 1959 trace_i915_reg_rw(false, reg, val, sizeof(val), trace); \ 1960 return val 1961 1962 #define __gen2_read(x) \ 1963 static u##x \ 1964 gen2_read##x(struct intel_uncore *uncore, i915_reg_t reg, bool trace) { \ 1965 GEN2_READ_HEADER(x); \ 1966 val = __raw_uncore_read##x(uncore, reg); \ 1967 GEN2_READ_FOOTER; \ 1968 } 1969 1970 #define __gen5_read(x) \ 1971 static u##x \ 1972 gen5_read##x(struct intel_uncore *uncore, i915_reg_t reg, bool trace) { \ 1973 GEN2_READ_HEADER(x); \ 1974 ilk_dummy_write(uncore); \ 1975 val = __raw_uncore_read##x(uncore, reg); \ 1976 GEN2_READ_FOOTER; \ 1977 } 1978 1979 __gen5_read(8) 1980 __gen5_read(16) 1981 __gen5_read(32) 1982 __gen5_read(64) 1983 __gen2_read(8) 1984 __gen2_read(16) 1985 __gen2_read(32) 1986 __gen2_read(64) 1987 1988 #undef __gen5_read 1989 #undef __gen2_read 1990 1991 #undef GEN2_READ_FOOTER 1992 #undef GEN2_READ_HEADER 1993 1994 #define GEN6_READ_HEADER(x) \ 1995 u32 offset = i915_mmio_reg_offset(reg); \ 1996 unsigned long irqflags; \ 1997 u##x val = 0; \ 1998 assert_rpm_wakelock_held(uncore->rpm); \ 1999 spin_lock_irqsave(&uncore->lock, irqflags); \ 2000 unclaimed_reg_debug(uncore, reg, true, true) 2001 2002 #define GEN6_READ_FOOTER \ 2003 unclaimed_reg_debug(uncore, reg, true, false); \ 2004 spin_unlock_irqrestore(&uncore->lock, irqflags); \ 2005 trace_i915_reg_rw(false, reg, val, sizeof(val), trace); \ 2006 return val 2007 2008 static noinline void ___force_wake_auto(struct intel_uncore *uncore, 2009 enum forcewake_domains fw_domains) 2010 { 2011 struct intel_uncore_forcewake_domain *domain; 2012 unsigned int tmp; 2013 2014 GEM_BUG_ON(fw_domains & ~uncore->fw_domains); 2015 2016 for_each_fw_domain_masked(domain, fw_domains, uncore, tmp) 2017 fw_domain_arm_timer(domain); 2018 2019 fw_domains_get(uncore, fw_domains); 2020 } 2021 2022 static inline void __force_wake_auto(struct intel_uncore *uncore, 2023 enum forcewake_domains fw_domains) 2024 { 2025 GEM_BUG_ON(!fw_domains); 2026 2027 /* Turn on all requested but inactive supported forcewake domains. */ 2028 fw_domains &= uncore->fw_domains; 2029 fw_domains &= ~uncore->fw_domains_active; 2030 2031 if (fw_domains) 2032 ___force_wake_auto(uncore, fw_domains); 2033 } 2034 2035 #define __gen_fwtable_read(x) \ 2036 static u##x \ 2037 fwtable_read##x(struct intel_uncore *uncore, i915_reg_t reg, bool trace) \ 2038 { \ 2039 enum forcewake_domains fw_engine; \ 2040 GEN6_READ_HEADER(x); \ 2041 fw_engine = __fwtable_reg_read_fw_domains(uncore, offset); \ 2042 if (fw_engine) \ 2043 __force_wake_auto(uncore, fw_engine); \ 2044 val = __raw_uncore_read##x(uncore, reg); \ 2045 GEN6_READ_FOOTER; \ 2046 } 2047 2048 static enum forcewake_domains 2049 fwtable_reg_read_fw_domains(struct intel_uncore *uncore, i915_reg_t reg) { 2050 return __fwtable_reg_read_fw_domains(uncore, i915_mmio_reg_offset(reg)); 2051 } 2052 2053 __gen_fwtable_read(8) 2054 __gen_fwtable_read(16) 2055 __gen_fwtable_read(32) 2056 __gen_fwtable_read(64) 2057 2058 #undef __gen_fwtable_read 2059 #undef GEN6_READ_FOOTER 2060 #undef GEN6_READ_HEADER 2061 2062 #define GEN2_WRITE_HEADER \ 2063 trace_i915_reg_rw(true, reg, val, sizeof(val), trace); \ 2064 assert_rpm_wakelock_held(uncore->rpm); \ 2065 2066 #define GEN2_WRITE_FOOTER 2067 2068 #define __gen2_write(x) \ 2069 static void \ 2070 gen2_write##x(struct intel_uncore *uncore, i915_reg_t reg, u##x val, bool trace) { \ 2071 GEN2_WRITE_HEADER; \ 2072 __raw_uncore_write##x(uncore, reg, val); \ 2073 GEN2_WRITE_FOOTER; \ 2074 } 2075 2076 #define __gen5_write(x) \ 2077 static void \ 2078 gen5_write##x(struct intel_uncore *uncore, i915_reg_t reg, u##x val, bool trace) { \ 2079 GEN2_WRITE_HEADER; \ 2080 ilk_dummy_write(uncore); \ 2081 __raw_uncore_write##x(uncore, reg, val); \ 2082 GEN2_WRITE_FOOTER; \ 2083 } 2084 2085 __gen5_write(8) 2086 __gen5_write(16) 2087 __gen5_write(32) 2088 __gen2_write(8) 2089 __gen2_write(16) 2090 __gen2_write(32) 2091 2092 #undef __gen5_write 2093 #undef __gen2_write 2094 2095 #undef GEN2_WRITE_FOOTER 2096 #undef GEN2_WRITE_HEADER 2097 2098 #define GEN6_WRITE_HEADER \ 2099 u32 offset = i915_mmio_reg_offset(reg); \ 2100 unsigned long irqflags; \ 2101 trace_i915_reg_rw(true, reg, val, sizeof(val), trace); \ 2102 assert_rpm_wakelock_held(uncore->rpm); \ 2103 spin_lock_irqsave(&uncore->lock, irqflags); \ 2104 unclaimed_reg_debug(uncore, reg, false, true) 2105 2106 #define GEN6_WRITE_FOOTER \ 2107 unclaimed_reg_debug(uncore, reg, false, false); \ 2108 spin_unlock_irqrestore(&uncore->lock, irqflags) 2109 2110 #define __gen6_write(x) \ 2111 static void \ 2112 gen6_write##x(struct intel_uncore *uncore, i915_reg_t reg, u##x val, bool trace) { \ 2113 GEN6_WRITE_HEADER; \ 2114 if (NEEDS_FORCE_WAKE(offset)) \ 2115 __gen6_gt_wait_for_fifo(uncore); \ 2116 __raw_uncore_write##x(uncore, reg, val); \ 2117 GEN6_WRITE_FOOTER; \ 2118 } 2119 __gen6_write(8) 2120 __gen6_write(16) 2121 __gen6_write(32) 2122 2123 #define __gen_fwtable_write(x) \ 2124 static void \ 2125 fwtable_write##x(struct intel_uncore *uncore, i915_reg_t reg, u##x val, bool trace) { \ 2126 enum forcewake_domains fw_engine; \ 2127 GEN6_WRITE_HEADER; \ 2128 fw_engine = __fwtable_reg_write_fw_domains(uncore, offset); \ 2129 if (fw_engine) \ 2130 __force_wake_auto(uncore, fw_engine); \ 2131 __raw_uncore_write##x(uncore, reg, val); \ 2132 GEN6_WRITE_FOOTER; \ 2133 } 2134 2135 static enum forcewake_domains 2136 fwtable_reg_write_fw_domains(struct intel_uncore *uncore, i915_reg_t reg) 2137 { 2138 return __fwtable_reg_write_fw_domains(uncore, i915_mmio_reg_offset(reg)); 2139 } 2140 2141 __gen_fwtable_write(8) 2142 __gen_fwtable_write(16) 2143 __gen_fwtable_write(32) 2144 2145 #undef __gen_fwtable_write 2146 #undef GEN6_WRITE_FOOTER 2147 #undef GEN6_WRITE_HEADER 2148 2149 #define __vgpu_write(x) \ 2150 static void \ 2151 vgpu_write##x(struct intel_uncore *uncore, i915_reg_t reg, u##x val, bool trace) { \ 2152 trace_i915_reg_rw(true, reg, val, sizeof(val), trace); \ 2153 __raw_uncore_write##x(uncore, reg, val); \ 2154 } 2155 __vgpu_write(8) 2156 __vgpu_write(16) 2157 __vgpu_write(32) 2158 2159 #define ASSIGN_RAW_WRITE_MMIO_VFUNCS(uncore, x) \ 2160 do { \ 2161 (uncore)->funcs.mmio_writeb = x##_write8; \ 2162 (uncore)->funcs.mmio_writew = x##_write16; \ 2163 (uncore)->funcs.mmio_writel = x##_write32; \ 2164 } while (0) 2165 2166 #define ASSIGN_RAW_READ_MMIO_VFUNCS(uncore, x) \ 2167 do { \ 2168 (uncore)->funcs.mmio_readb = x##_read8; \ 2169 (uncore)->funcs.mmio_readw = x##_read16; \ 2170 (uncore)->funcs.mmio_readl = x##_read32; \ 2171 (uncore)->funcs.mmio_readq = x##_read64; \ 2172 } while (0) 2173 2174 #define ASSIGN_WRITE_MMIO_VFUNCS(uncore, x) \ 2175 do { \ 2176 ASSIGN_RAW_WRITE_MMIO_VFUNCS((uncore), x); \ 2177 (uncore)->funcs.write_fw_domains = x##_reg_write_fw_domains; \ 2178 } while (0) 2179 2180 #define ASSIGN_READ_MMIO_VFUNCS(uncore, x) \ 2181 do { \ 2182 ASSIGN_RAW_READ_MMIO_VFUNCS(uncore, x); \ 2183 (uncore)->funcs.read_fw_domains = x##_reg_read_fw_domains; \ 2184 } while (0) 2185 2186 static int __fw_domain_init(struct intel_uncore *uncore, 2187 enum forcewake_domain_id domain_id, 2188 i915_reg_t reg_set, 2189 i915_reg_t reg_ack) 2190 { 2191 struct intel_uncore_forcewake_domain *d; 2192 2193 GEM_BUG_ON(domain_id >= FW_DOMAIN_ID_COUNT); 2194 GEM_BUG_ON(uncore->fw_domain[domain_id]); 2195 2196 if (i915_inject_probe_failure(uncore->i915)) 2197 return -ENOMEM; 2198 2199 d = kzalloc(sizeof(*d), GFP_KERNEL); 2200 if (!d) 2201 return -ENOMEM; 2202 2203 drm_WARN_ON(&uncore->i915->drm, !i915_mmio_reg_valid(reg_set)); 2204 drm_WARN_ON(&uncore->i915->drm, !i915_mmio_reg_valid(reg_ack)); 2205 2206 d->uncore = uncore; 2207 d->wake_count = 0; 2208 d->reg_set = uncore->regs + i915_mmio_reg_offset(reg_set) + uncore->gsi_offset; 2209 d->reg_ack = uncore->regs + i915_mmio_reg_offset(reg_ack) + uncore->gsi_offset; 2210 2211 d->id = domain_id; 2212 2213 BUILD_BUG_ON(FORCEWAKE_RENDER != (1 << FW_DOMAIN_ID_RENDER)); 2214 BUILD_BUG_ON(FORCEWAKE_GT != (1 << FW_DOMAIN_ID_GT)); 2215 BUILD_BUG_ON(FORCEWAKE_MEDIA != (1 << FW_DOMAIN_ID_MEDIA)); 2216 BUILD_BUG_ON(FORCEWAKE_MEDIA_VDBOX0 != (1 << FW_DOMAIN_ID_MEDIA_VDBOX0)); 2217 BUILD_BUG_ON(FORCEWAKE_MEDIA_VDBOX1 != (1 << FW_DOMAIN_ID_MEDIA_VDBOX1)); 2218 BUILD_BUG_ON(FORCEWAKE_MEDIA_VDBOX2 != (1 << FW_DOMAIN_ID_MEDIA_VDBOX2)); 2219 BUILD_BUG_ON(FORCEWAKE_MEDIA_VDBOX3 != (1 << FW_DOMAIN_ID_MEDIA_VDBOX3)); 2220 BUILD_BUG_ON(FORCEWAKE_MEDIA_VDBOX4 != (1 << FW_DOMAIN_ID_MEDIA_VDBOX4)); 2221 BUILD_BUG_ON(FORCEWAKE_MEDIA_VDBOX5 != (1 << FW_DOMAIN_ID_MEDIA_VDBOX5)); 2222 BUILD_BUG_ON(FORCEWAKE_MEDIA_VDBOX6 != (1 << FW_DOMAIN_ID_MEDIA_VDBOX6)); 2223 BUILD_BUG_ON(FORCEWAKE_MEDIA_VDBOX7 != (1 << FW_DOMAIN_ID_MEDIA_VDBOX7)); 2224 BUILD_BUG_ON(FORCEWAKE_MEDIA_VEBOX0 != (1 << FW_DOMAIN_ID_MEDIA_VEBOX0)); 2225 BUILD_BUG_ON(FORCEWAKE_MEDIA_VEBOX1 != (1 << FW_DOMAIN_ID_MEDIA_VEBOX1)); 2226 BUILD_BUG_ON(FORCEWAKE_MEDIA_VEBOX2 != (1 << FW_DOMAIN_ID_MEDIA_VEBOX2)); 2227 BUILD_BUG_ON(FORCEWAKE_MEDIA_VEBOX3 != (1 << FW_DOMAIN_ID_MEDIA_VEBOX3)); 2228 BUILD_BUG_ON(FORCEWAKE_GSC != (1 << FW_DOMAIN_ID_GSC)); 2229 2230 d->mask = BIT(domain_id); 2231 2232 hrtimer_init(&d->timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL); 2233 d->timer.function = intel_uncore_fw_release_timer; 2234 2235 uncore->fw_domains |= BIT(domain_id); 2236 2237 fw_domain_reset(d); 2238 2239 uncore->fw_domain[domain_id] = d; 2240 2241 return 0; 2242 } 2243 2244 static void fw_domain_fini(struct intel_uncore *uncore, 2245 enum forcewake_domain_id domain_id) 2246 { 2247 struct intel_uncore_forcewake_domain *d; 2248 2249 GEM_BUG_ON(domain_id >= FW_DOMAIN_ID_COUNT); 2250 2251 d = fetch_and_zero(&uncore->fw_domain[domain_id]); 2252 if (!d) 2253 return; 2254 2255 uncore->fw_domains &= ~BIT(domain_id); 2256 drm_WARN_ON(&uncore->i915->drm, d->wake_count); 2257 drm_WARN_ON(&uncore->i915->drm, hrtimer_cancel(&d->timer)); 2258 kfree(d); 2259 } 2260 2261 static void intel_uncore_fw_domains_fini(struct intel_uncore *uncore) 2262 { 2263 struct intel_uncore_forcewake_domain *d; 2264 int tmp; 2265 2266 for_each_fw_domain(d, uncore, tmp) 2267 fw_domain_fini(uncore, d->id); 2268 } 2269 2270 static const struct intel_uncore_fw_get uncore_get_fallback = { 2271 .force_wake_get = fw_domains_get_with_fallback 2272 }; 2273 2274 static const struct intel_uncore_fw_get uncore_get_normal = { 2275 .force_wake_get = fw_domains_get_normal, 2276 }; 2277 2278 static const struct intel_uncore_fw_get uncore_get_thread_status = { 2279 .force_wake_get = fw_domains_get_with_thread_status 2280 }; 2281 2282 static int intel_uncore_fw_domains_init(struct intel_uncore *uncore) 2283 { 2284 struct drm_i915_private *i915 = uncore->i915; 2285 int ret = 0; 2286 2287 GEM_BUG_ON(!intel_uncore_has_forcewake(uncore)); 2288 2289 #define fw_domain_init(uncore__, id__, set__, ack__) \ 2290 (ret ?: (ret = __fw_domain_init((uncore__), (id__), (set__), (ack__)))) 2291 2292 if (GRAPHICS_VER(i915) >= 11) { 2293 intel_engine_mask_t emask; 2294 int i; 2295 2296 /* we'll prune the domains of missing engines later */ 2297 emask = uncore->gt->info.engine_mask; 2298 2299 uncore->fw_get_funcs = &uncore_get_fallback; 2300 if (GRAPHICS_VER_FULL(i915) >= IP_VER(12, 70)) 2301 fw_domain_init(uncore, FW_DOMAIN_ID_GT, 2302 FORCEWAKE_GT_GEN9, 2303 FORCEWAKE_ACK_GT_MTL); 2304 else 2305 fw_domain_init(uncore, FW_DOMAIN_ID_GT, 2306 FORCEWAKE_GT_GEN9, 2307 FORCEWAKE_ACK_GT_GEN9); 2308 2309 if (RCS_MASK(uncore->gt) || CCS_MASK(uncore->gt)) 2310 fw_domain_init(uncore, FW_DOMAIN_ID_RENDER, 2311 FORCEWAKE_RENDER_GEN9, 2312 FORCEWAKE_ACK_RENDER_GEN9); 2313 2314 for (i = 0; i < I915_MAX_VCS; i++) { 2315 if (!__HAS_ENGINE(emask, _VCS(i))) 2316 continue; 2317 2318 fw_domain_init(uncore, FW_DOMAIN_ID_MEDIA_VDBOX0 + i, 2319 FORCEWAKE_MEDIA_VDBOX_GEN11(i), 2320 FORCEWAKE_ACK_MEDIA_VDBOX_GEN11(i)); 2321 } 2322 for (i = 0; i < I915_MAX_VECS; i++) { 2323 if (!__HAS_ENGINE(emask, _VECS(i))) 2324 continue; 2325 2326 fw_domain_init(uncore, FW_DOMAIN_ID_MEDIA_VEBOX0 + i, 2327 FORCEWAKE_MEDIA_VEBOX_GEN11(i), 2328 FORCEWAKE_ACK_MEDIA_VEBOX_GEN11(i)); 2329 } 2330 2331 if (uncore->gt->type == GT_MEDIA) 2332 fw_domain_init(uncore, FW_DOMAIN_ID_GSC, 2333 FORCEWAKE_REQ_GSC, FORCEWAKE_ACK_GSC); 2334 } else if (IS_GRAPHICS_VER(i915, 9, 10)) { 2335 uncore->fw_get_funcs = &uncore_get_fallback; 2336 fw_domain_init(uncore, FW_DOMAIN_ID_RENDER, 2337 FORCEWAKE_RENDER_GEN9, 2338 FORCEWAKE_ACK_RENDER_GEN9); 2339 fw_domain_init(uncore, FW_DOMAIN_ID_GT, 2340 FORCEWAKE_GT_GEN9, 2341 FORCEWAKE_ACK_GT_GEN9); 2342 fw_domain_init(uncore, FW_DOMAIN_ID_MEDIA, 2343 FORCEWAKE_MEDIA_GEN9, FORCEWAKE_ACK_MEDIA_GEN9); 2344 } else if (IS_VALLEYVIEW(i915) || IS_CHERRYVIEW(i915)) { 2345 uncore->fw_get_funcs = &uncore_get_normal; 2346 fw_domain_init(uncore, FW_DOMAIN_ID_RENDER, 2347 FORCEWAKE_VLV, FORCEWAKE_ACK_VLV); 2348 fw_domain_init(uncore, FW_DOMAIN_ID_MEDIA, 2349 FORCEWAKE_MEDIA_VLV, FORCEWAKE_ACK_MEDIA_VLV); 2350 } else if (IS_HASWELL(i915) || IS_BROADWELL(i915)) { 2351 uncore->fw_get_funcs = &uncore_get_thread_status; 2352 fw_domain_init(uncore, FW_DOMAIN_ID_RENDER, 2353 FORCEWAKE_MT, FORCEWAKE_ACK_HSW); 2354 } else if (IS_IVYBRIDGE(i915)) { 2355 u32 ecobus; 2356 2357 /* IVB configs may use multi-threaded forcewake */ 2358 2359 /* A small trick here - if the bios hasn't configured 2360 * MT forcewake, and if the device is in RC6, then 2361 * force_wake_mt_get will not wake the device and the 2362 * ECOBUS read will return zero. Which will be 2363 * (correctly) interpreted by the test below as MT 2364 * forcewake being disabled. 2365 */ 2366 uncore->fw_get_funcs = &uncore_get_thread_status; 2367 2368 /* We need to init first for ECOBUS access and then 2369 * determine later if we want to reinit, in case of MT access is 2370 * not working. In this stage we don't know which flavour this 2371 * ivb is, so it is better to reset also the gen6 fw registers 2372 * before the ecobus check. 2373 */ 2374 2375 __raw_uncore_write32(uncore, FORCEWAKE, 0); 2376 __raw_posting_read(uncore, ECOBUS); 2377 2378 ret = __fw_domain_init(uncore, FW_DOMAIN_ID_RENDER, 2379 FORCEWAKE_MT, FORCEWAKE_MT_ACK); 2380 if (ret) 2381 goto out; 2382 2383 spin_lock_irq(&uncore->lock); 2384 fw_domains_get_with_thread_status(uncore, FORCEWAKE_RENDER); 2385 ecobus = __raw_uncore_read32(uncore, ECOBUS); 2386 fw_domains_put(uncore, FORCEWAKE_RENDER); 2387 spin_unlock_irq(&uncore->lock); 2388 2389 if (!(ecobus & FORCEWAKE_MT_ENABLE)) { 2390 drm_info(&i915->drm, "No MT forcewake available on Ivybridge, this can result in issues\n"); 2391 drm_info(&i915->drm, "when using vblank-synced partial screen updates.\n"); 2392 fw_domain_fini(uncore, FW_DOMAIN_ID_RENDER); 2393 fw_domain_init(uncore, FW_DOMAIN_ID_RENDER, 2394 FORCEWAKE, FORCEWAKE_ACK); 2395 } 2396 } else if (GRAPHICS_VER(i915) == 6) { 2397 uncore->fw_get_funcs = &uncore_get_thread_status; 2398 fw_domain_init(uncore, FW_DOMAIN_ID_RENDER, 2399 FORCEWAKE, FORCEWAKE_ACK); 2400 } 2401 2402 #undef fw_domain_init 2403 2404 /* All future platforms are expected to require complex power gating */ 2405 drm_WARN_ON(&i915->drm, !ret && uncore->fw_domains == 0); 2406 2407 out: 2408 if (ret) 2409 intel_uncore_fw_domains_fini(uncore); 2410 2411 return ret; 2412 } 2413 2414 #define ASSIGN_FW_DOMAINS_TABLE(uncore, d) \ 2415 { \ 2416 (uncore)->fw_domains_table = \ 2417 (struct intel_forcewake_range *)(d); \ 2418 (uncore)->fw_domains_table_entries = ARRAY_SIZE((d)); \ 2419 } 2420 2421 #define ASSIGN_SHADOW_TABLE(uncore, d) \ 2422 { \ 2423 (uncore)->shadowed_reg_table = d; \ 2424 (uncore)->shadowed_reg_table_entries = ARRAY_SIZE((d)); \ 2425 } 2426 2427 static int i915_pmic_bus_access_notifier(struct notifier_block *nb, 2428 unsigned long action, void *data) 2429 { 2430 struct intel_uncore *uncore = container_of(nb, 2431 struct intel_uncore, pmic_bus_access_nb); 2432 2433 switch (action) { 2434 case MBI_PMIC_BUS_ACCESS_BEGIN: 2435 /* 2436 * forcewake all now to make sure that we don't need to do a 2437 * forcewake later which on systems where this notifier gets 2438 * called requires the punit to access to the shared pmic i2c 2439 * bus, which will be busy after this notification, leading to: 2440 * "render: timed out waiting for forcewake ack request." 2441 * errors. 2442 * 2443 * The notifier is unregistered during intel_runtime_suspend(), 2444 * so it's ok to access the HW here without holding a RPM 2445 * wake reference -> disable wakeref asserts for the time of 2446 * the access. 2447 */ 2448 disable_rpm_wakeref_asserts(uncore->rpm); 2449 intel_uncore_forcewake_get(uncore, FORCEWAKE_ALL); 2450 enable_rpm_wakeref_asserts(uncore->rpm); 2451 break; 2452 case MBI_PMIC_BUS_ACCESS_END: 2453 intel_uncore_forcewake_put(uncore, FORCEWAKE_ALL); 2454 break; 2455 } 2456 2457 return NOTIFY_OK; 2458 } 2459 2460 static void uncore_unmap_mmio(struct drm_device *drm, void *regs) 2461 { 2462 iounmap((void __iomem *)regs); 2463 } 2464 2465 int intel_uncore_setup_mmio(struct intel_uncore *uncore, phys_addr_t phys_addr) 2466 { 2467 struct drm_i915_private *i915 = uncore->i915; 2468 int mmio_size; 2469 2470 /* 2471 * Before gen4, the registers and the GTT are behind different BARs. 2472 * However, from gen4 onwards, the registers and the GTT are shared 2473 * in the same BAR, so we want to restrict this ioremap from 2474 * clobbering the GTT which we want ioremap_wc instead. Fortunately, 2475 * the register BAR remains the same size for all the earlier 2476 * generations up to Ironlake. 2477 * For dgfx chips register range is expanded to 4MB, and this larger 2478 * range is also used for integrated gpus beginning with Meteor Lake. 2479 */ 2480 if (IS_DGFX(i915) || GRAPHICS_VER_FULL(i915) >= IP_VER(12, 70)) 2481 mmio_size = 4 * 1024 * 1024; 2482 else if (GRAPHICS_VER(i915) >= 5) 2483 mmio_size = 2 * 1024 * 1024; 2484 else 2485 mmio_size = 512 * 1024; 2486 2487 uncore->regs = ioremap(phys_addr, mmio_size); 2488 if (uncore->regs == NULL) { 2489 drm_err(&i915->drm, "failed to map registers\n"); 2490 return -EIO; 2491 } 2492 2493 return drmm_add_action_or_reset(&i915->drm, uncore_unmap_mmio, 2494 (void __force *)uncore->regs); 2495 } 2496 2497 void intel_uncore_init_early(struct intel_uncore *uncore, 2498 struct intel_gt *gt) 2499 { 2500 spin_lock_init(&uncore->lock); 2501 uncore->i915 = gt->i915; 2502 uncore->gt = gt; 2503 uncore->rpm = >->i915->runtime_pm; 2504 } 2505 2506 static void uncore_raw_init(struct intel_uncore *uncore) 2507 { 2508 GEM_BUG_ON(intel_uncore_has_forcewake(uncore)); 2509 2510 if (intel_vgpu_active(uncore->i915)) { 2511 ASSIGN_RAW_WRITE_MMIO_VFUNCS(uncore, vgpu); 2512 ASSIGN_RAW_READ_MMIO_VFUNCS(uncore, vgpu); 2513 } else if (GRAPHICS_VER(uncore->i915) == 5) { 2514 ASSIGN_RAW_WRITE_MMIO_VFUNCS(uncore, gen5); 2515 ASSIGN_RAW_READ_MMIO_VFUNCS(uncore, gen5); 2516 } else { 2517 ASSIGN_RAW_WRITE_MMIO_VFUNCS(uncore, gen2); 2518 ASSIGN_RAW_READ_MMIO_VFUNCS(uncore, gen2); 2519 } 2520 } 2521 2522 static int uncore_media_forcewake_init(struct intel_uncore *uncore) 2523 { 2524 struct drm_i915_private *i915 = uncore->i915; 2525 2526 if (MEDIA_VER(i915) >= 13) { 2527 ASSIGN_FW_DOMAINS_TABLE(uncore, __xelpmp_fw_ranges); 2528 ASSIGN_SHADOW_TABLE(uncore, xelpmp_shadowed_regs); 2529 ASSIGN_WRITE_MMIO_VFUNCS(uncore, fwtable); 2530 } else { 2531 MISSING_CASE(MEDIA_VER(i915)); 2532 return -ENODEV; 2533 } 2534 2535 return 0; 2536 } 2537 2538 static int uncore_forcewake_init(struct intel_uncore *uncore) 2539 { 2540 struct drm_i915_private *i915 = uncore->i915; 2541 int ret; 2542 2543 GEM_BUG_ON(!intel_uncore_has_forcewake(uncore)); 2544 2545 ret = intel_uncore_fw_domains_init(uncore); 2546 if (ret) 2547 return ret; 2548 forcewake_early_sanitize(uncore, 0); 2549 2550 ASSIGN_READ_MMIO_VFUNCS(uncore, fwtable); 2551 2552 if (uncore->gt->type == GT_MEDIA) 2553 return uncore_media_forcewake_init(uncore); 2554 2555 if (GRAPHICS_VER_FULL(i915) >= IP_VER(12, 70)) { 2556 ASSIGN_FW_DOMAINS_TABLE(uncore, __mtl_fw_ranges); 2557 ASSIGN_SHADOW_TABLE(uncore, mtl_shadowed_regs); 2558 ASSIGN_WRITE_MMIO_VFUNCS(uncore, fwtable); 2559 } else if (GRAPHICS_VER_FULL(i915) >= IP_VER(12, 60)) { 2560 ASSIGN_FW_DOMAINS_TABLE(uncore, __pvc_fw_ranges); 2561 ASSIGN_SHADOW_TABLE(uncore, pvc_shadowed_regs); 2562 ASSIGN_WRITE_MMIO_VFUNCS(uncore, fwtable); 2563 } else if (GRAPHICS_VER_FULL(i915) >= IP_VER(12, 55)) { 2564 ASSIGN_FW_DOMAINS_TABLE(uncore, __dg2_fw_ranges); 2565 ASSIGN_SHADOW_TABLE(uncore, dg2_shadowed_regs); 2566 ASSIGN_WRITE_MMIO_VFUNCS(uncore, fwtable); 2567 } else if (GRAPHICS_VER_FULL(i915) >= IP_VER(12, 50)) { 2568 ASSIGN_FW_DOMAINS_TABLE(uncore, __xehp_fw_ranges); 2569 ASSIGN_SHADOW_TABLE(uncore, gen12_shadowed_regs); 2570 ASSIGN_WRITE_MMIO_VFUNCS(uncore, fwtable); 2571 } else if (GRAPHICS_VER(i915) >= 12) { 2572 ASSIGN_FW_DOMAINS_TABLE(uncore, __gen12_fw_ranges); 2573 ASSIGN_SHADOW_TABLE(uncore, gen12_shadowed_regs); 2574 ASSIGN_WRITE_MMIO_VFUNCS(uncore, fwtable); 2575 } else if (GRAPHICS_VER(i915) == 11) { 2576 ASSIGN_FW_DOMAINS_TABLE(uncore, __gen11_fw_ranges); 2577 ASSIGN_SHADOW_TABLE(uncore, gen11_shadowed_regs); 2578 ASSIGN_WRITE_MMIO_VFUNCS(uncore, fwtable); 2579 } else if (IS_GRAPHICS_VER(i915, 9, 10)) { 2580 ASSIGN_FW_DOMAINS_TABLE(uncore, __gen9_fw_ranges); 2581 ASSIGN_SHADOW_TABLE(uncore, gen8_shadowed_regs); 2582 ASSIGN_WRITE_MMIO_VFUNCS(uncore, fwtable); 2583 } else if (IS_CHERRYVIEW(i915)) { 2584 ASSIGN_FW_DOMAINS_TABLE(uncore, __chv_fw_ranges); 2585 ASSIGN_SHADOW_TABLE(uncore, gen8_shadowed_regs); 2586 ASSIGN_WRITE_MMIO_VFUNCS(uncore, fwtable); 2587 } else if (GRAPHICS_VER(i915) == 8) { 2588 ASSIGN_FW_DOMAINS_TABLE(uncore, __gen6_fw_ranges); 2589 ASSIGN_SHADOW_TABLE(uncore, gen8_shadowed_regs); 2590 ASSIGN_WRITE_MMIO_VFUNCS(uncore, fwtable); 2591 } else if (IS_VALLEYVIEW(i915)) { 2592 ASSIGN_FW_DOMAINS_TABLE(uncore, __vlv_fw_ranges); 2593 ASSIGN_WRITE_MMIO_VFUNCS(uncore, gen6); 2594 } else if (IS_GRAPHICS_VER(i915, 6, 7)) { 2595 ASSIGN_FW_DOMAINS_TABLE(uncore, __gen6_fw_ranges); 2596 ASSIGN_WRITE_MMIO_VFUNCS(uncore, gen6); 2597 } 2598 2599 uncore->pmic_bus_access_nb.notifier_call = i915_pmic_bus_access_notifier; 2600 iosf_mbi_register_pmic_bus_access_notifier(&uncore->pmic_bus_access_nb); 2601 2602 return 0; 2603 } 2604 2605 int intel_uncore_init_mmio(struct intel_uncore *uncore) 2606 { 2607 struct drm_i915_private *i915 = uncore->i915; 2608 int ret; 2609 2610 /* 2611 * The boot firmware initializes local memory and assesses its health. 2612 * If memory training fails, the punit will have been instructed to 2613 * keep the GT powered down; we won't be able to communicate with it 2614 * and we should not continue with driver initialization. 2615 */ 2616 if (IS_DGFX(i915) && 2617 !(__raw_uncore_read32(uncore, GU_CNTL) & LMEM_INIT)) { 2618 drm_err(&i915->drm, "LMEM not initialized by firmware\n"); 2619 return -ENODEV; 2620 } 2621 2622 if (GRAPHICS_VER(i915) > 5 && !intel_vgpu_active(i915)) 2623 uncore->flags |= UNCORE_HAS_FORCEWAKE; 2624 2625 if (!intel_uncore_has_forcewake(uncore)) { 2626 uncore_raw_init(uncore); 2627 } else { 2628 ret = uncore_forcewake_init(uncore); 2629 if (ret) 2630 return ret; 2631 } 2632 2633 /* make sure fw funcs are set if and only if we have fw*/ 2634 GEM_BUG_ON(intel_uncore_has_forcewake(uncore) != !!uncore->fw_get_funcs); 2635 GEM_BUG_ON(intel_uncore_has_forcewake(uncore) != !!uncore->funcs.read_fw_domains); 2636 GEM_BUG_ON(intel_uncore_has_forcewake(uncore) != !!uncore->funcs.write_fw_domains); 2637 2638 if (HAS_FPGA_DBG_UNCLAIMED(i915)) 2639 uncore->flags |= UNCORE_HAS_FPGA_DBG_UNCLAIMED; 2640 2641 if (IS_VALLEYVIEW(i915) || IS_CHERRYVIEW(i915)) 2642 uncore->flags |= UNCORE_HAS_DBG_UNCLAIMED; 2643 2644 if (IS_GRAPHICS_VER(i915, 6, 7)) 2645 uncore->flags |= UNCORE_HAS_FIFO; 2646 2647 /* clear out unclaimed reg detection bit */ 2648 if (intel_uncore_unclaimed_mmio(uncore)) 2649 drm_dbg(&i915->drm, "unclaimed mmio detected on uncore init, clearing\n"); 2650 2651 return 0; 2652 } 2653 2654 /* 2655 * We might have detected that some engines are fused off after we initialized 2656 * the forcewake domains. Prune them, to make sure they only reference existing 2657 * engines. 2658 */ 2659 void intel_uncore_prune_engine_fw_domains(struct intel_uncore *uncore, 2660 struct intel_gt *gt) 2661 { 2662 enum forcewake_domains fw_domains = uncore->fw_domains; 2663 enum forcewake_domain_id domain_id; 2664 int i; 2665 2666 if (!intel_uncore_has_forcewake(uncore) || GRAPHICS_VER(uncore->i915) < 11) 2667 return; 2668 2669 for (i = 0; i < I915_MAX_VCS; i++) { 2670 domain_id = FW_DOMAIN_ID_MEDIA_VDBOX0 + i; 2671 2672 if (HAS_ENGINE(gt, _VCS(i))) 2673 continue; 2674 2675 /* 2676 * Starting with XeHP, the power well for an even-numbered 2677 * VDBOX is also used for shared units within the 2678 * media slice such as SFC. So even if the engine 2679 * itself is fused off, we still need to initialize 2680 * the forcewake domain if any of the other engines 2681 * in the same media slice are present. 2682 */ 2683 if (GRAPHICS_VER_FULL(uncore->i915) >= IP_VER(12, 50) && i % 2 == 0) { 2684 if ((i + 1 < I915_MAX_VCS) && HAS_ENGINE(gt, _VCS(i + 1))) 2685 continue; 2686 2687 if (HAS_ENGINE(gt, _VECS(i / 2))) 2688 continue; 2689 } 2690 2691 if (fw_domains & BIT(domain_id)) 2692 fw_domain_fini(uncore, domain_id); 2693 } 2694 2695 for (i = 0; i < I915_MAX_VECS; i++) { 2696 domain_id = FW_DOMAIN_ID_MEDIA_VEBOX0 + i; 2697 2698 if (HAS_ENGINE(gt, _VECS(i))) 2699 continue; 2700 2701 if (fw_domains & BIT(domain_id)) 2702 fw_domain_fini(uncore, domain_id); 2703 } 2704 2705 if ((fw_domains & BIT(FW_DOMAIN_ID_GSC)) && !HAS_ENGINE(gt, GSC0)) 2706 fw_domain_fini(uncore, FW_DOMAIN_ID_GSC); 2707 } 2708 2709 /* 2710 * The driver-initiated FLR is the highest level of reset that we can trigger 2711 * from within the driver. It is different from the PCI FLR in that it doesn't 2712 * fully reset the SGUnit and doesn't modify the PCI config space and therefore 2713 * it doesn't require a re-enumeration of the PCI BARs. However, the 2714 * driver-initiated FLR does still cause a reset of both GT and display and a 2715 * memory wipe of local and stolen memory, so recovery would require a full HW 2716 * re-init and saving/restoring (or re-populating) the wiped memory. Since we 2717 * perform the FLR as the very last action before releasing access to the HW 2718 * during the driver release flow, we don't attempt recovery at all, because 2719 * if/when a new instance of i915 is bound to the device it will do a full 2720 * re-init anyway. 2721 */ 2722 static void driver_initiated_flr(struct intel_uncore *uncore) 2723 { 2724 struct drm_i915_private *i915 = uncore->i915; 2725 const unsigned int flr_timeout_ms = 3000; /* specs recommend a 3s wait */ 2726 int ret; 2727 2728 drm_dbg(&i915->drm, "Triggering Driver-FLR\n"); 2729 2730 /* 2731 * Make sure any pending FLR requests have cleared by waiting for the 2732 * FLR trigger bit to go to zero. Also clear GU_DEBUG's DRIVERFLR_STATUS 2733 * to make sure it's not still set from a prior attempt (it's a write to 2734 * clear bit). 2735 * Note that we should never be in a situation where a previous attempt 2736 * is still pending (unless the HW is totally dead), but better to be 2737 * safe in case something unexpected happens 2738 */ 2739 ret = intel_wait_for_register_fw(uncore, GU_CNTL, DRIVERFLR, 0, flr_timeout_ms); 2740 if (ret) { 2741 drm_err(&i915->drm, 2742 "Failed to wait for Driver-FLR bit to clear! %d\n", 2743 ret); 2744 return; 2745 } 2746 intel_uncore_write_fw(uncore, GU_DEBUG, DRIVERFLR_STATUS); 2747 2748 /* Trigger the actual Driver-FLR */ 2749 intel_uncore_rmw_fw(uncore, GU_CNTL, 0, DRIVERFLR); 2750 2751 ret = intel_wait_for_register_fw(uncore, GU_DEBUG, 2752 DRIVERFLR_STATUS, DRIVERFLR_STATUS, 2753 flr_timeout_ms); 2754 if (ret) { 2755 drm_err(&i915->drm, "wait for Driver-FLR completion failed! %d\n", ret); 2756 return; 2757 } 2758 2759 intel_uncore_write_fw(uncore, GU_DEBUG, DRIVERFLR_STATUS); 2760 } 2761 2762 /* Called via drm-managed action */ 2763 void intel_uncore_fini_mmio(struct drm_device *dev, void *data) 2764 { 2765 struct intel_uncore *uncore = data; 2766 2767 if (intel_uncore_has_forcewake(uncore)) { 2768 iosf_mbi_punit_acquire(); 2769 iosf_mbi_unregister_pmic_bus_access_notifier_unlocked( 2770 &uncore->pmic_bus_access_nb); 2771 intel_uncore_forcewake_reset(uncore); 2772 intel_uncore_fw_domains_fini(uncore); 2773 iosf_mbi_punit_release(); 2774 } 2775 2776 if (intel_uncore_needs_flr_on_fini(uncore)) 2777 driver_initiated_flr(uncore); 2778 } 2779 2780 /** 2781 * __intel_wait_for_register_fw - wait until register matches expected state 2782 * @uncore: the struct intel_uncore 2783 * @reg: the register to read 2784 * @mask: mask to apply to register value 2785 * @value: expected value 2786 * @fast_timeout_us: fast timeout in microsecond for atomic/tight wait 2787 * @slow_timeout_ms: slow timeout in millisecond 2788 * @out_value: optional placeholder to hold registry value 2789 * 2790 * This routine waits until the target register @reg contains the expected 2791 * @value after applying the @mask, i.e. it waits until :: 2792 * 2793 * (intel_uncore_read_fw(uncore, reg) & mask) == value 2794 * 2795 * Otherwise, the wait will timeout after @slow_timeout_ms milliseconds. 2796 * For atomic context @slow_timeout_ms must be zero and @fast_timeout_us 2797 * must be not larger than 20,0000 microseconds. 2798 * 2799 * Note that this routine assumes the caller holds forcewake asserted, it is 2800 * not suitable for very long waits. See intel_wait_for_register() if you 2801 * wish to wait without holding forcewake for the duration (i.e. you expect 2802 * the wait to be slow). 2803 * 2804 * Return: 0 if the register matches the desired condition, or -ETIMEDOUT. 2805 */ 2806 int __intel_wait_for_register_fw(struct intel_uncore *uncore, 2807 i915_reg_t reg, 2808 u32 mask, 2809 u32 value, 2810 unsigned int fast_timeout_us, 2811 unsigned int slow_timeout_ms, 2812 u32 *out_value) 2813 { 2814 u32 reg_value = 0; 2815 #define done (((reg_value = intel_uncore_read_fw(uncore, reg)) & mask) == value) 2816 int ret; 2817 2818 /* Catch any overuse of this function */ 2819 might_sleep_if(slow_timeout_ms); 2820 GEM_BUG_ON(fast_timeout_us > 20000); 2821 GEM_BUG_ON(!fast_timeout_us && !slow_timeout_ms); 2822 2823 ret = -ETIMEDOUT; 2824 if (fast_timeout_us && fast_timeout_us <= 20000) 2825 ret = _wait_for_atomic(done, fast_timeout_us, 0); 2826 if (ret && slow_timeout_ms) 2827 ret = wait_for(done, slow_timeout_ms); 2828 2829 if (out_value) 2830 *out_value = reg_value; 2831 2832 return ret; 2833 #undef done 2834 } 2835 2836 /** 2837 * __intel_wait_for_register - wait until register matches expected state 2838 * @uncore: the struct intel_uncore 2839 * @reg: the register to read 2840 * @mask: mask to apply to register value 2841 * @value: expected value 2842 * @fast_timeout_us: fast timeout in microsecond for atomic/tight wait 2843 * @slow_timeout_ms: slow timeout in millisecond 2844 * @out_value: optional placeholder to hold registry value 2845 * 2846 * This routine waits until the target register @reg contains the expected 2847 * @value after applying the @mask, i.e. it waits until :: 2848 * 2849 * (intel_uncore_read(uncore, reg) & mask) == value 2850 * 2851 * Otherwise, the wait will timeout after @timeout_ms milliseconds. 2852 * 2853 * Return: 0 if the register matches the desired condition, or -ETIMEDOUT. 2854 */ 2855 int __intel_wait_for_register(struct intel_uncore *uncore, 2856 i915_reg_t reg, 2857 u32 mask, 2858 u32 value, 2859 unsigned int fast_timeout_us, 2860 unsigned int slow_timeout_ms, 2861 u32 *out_value) 2862 { 2863 unsigned fw = 2864 intel_uncore_forcewake_for_reg(uncore, reg, FW_REG_READ); 2865 u32 reg_value; 2866 int ret; 2867 2868 might_sleep_if(slow_timeout_ms); 2869 2870 spin_lock_irq(&uncore->lock); 2871 intel_uncore_forcewake_get__locked(uncore, fw); 2872 2873 ret = __intel_wait_for_register_fw(uncore, 2874 reg, mask, value, 2875 fast_timeout_us, 0, ®_value); 2876 2877 intel_uncore_forcewake_put__locked(uncore, fw); 2878 spin_unlock_irq(&uncore->lock); 2879 2880 if (ret && slow_timeout_ms) 2881 ret = __wait_for(reg_value = intel_uncore_read_notrace(uncore, 2882 reg), 2883 (reg_value & mask) == value, 2884 slow_timeout_ms * 1000, 10, 1000); 2885 2886 /* just trace the final value */ 2887 trace_i915_reg_rw(false, reg, reg_value, sizeof(reg_value), true); 2888 2889 if (out_value) 2890 *out_value = reg_value; 2891 2892 return ret; 2893 } 2894 2895 bool intel_uncore_unclaimed_mmio(struct intel_uncore *uncore) 2896 { 2897 bool ret; 2898 2899 if (!uncore->debug) 2900 return false; 2901 2902 spin_lock_irq(&uncore->debug->lock); 2903 ret = check_for_unclaimed_mmio(uncore); 2904 spin_unlock_irq(&uncore->debug->lock); 2905 2906 return ret; 2907 } 2908 2909 bool 2910 intel_uncore_arm_unclaimed_mmio_detection(struct intel_uncore *uncore) 2911 { 2912 bool ret = false; 2913 2914 if (drm_WARN_ON(&uncore->i915->drm, !uncore->debug)) 2915 return false; 2916 2917 spin_lock_irq(&uncore->debug->lock); 2918 2919 if (unlikely(uncore->debug->unclaimed_mmio_check <= 0)) 2920 goto out; 2921 2922 if (unlikely(check_for_unclaimed_mmio(uncore))) { 2923 if (!uncore->i915->params.mmio_debug) { 2924 drm_dbg(&uncore->i915->drm, 2925 "Unclaimed register detected, " 2926 "enabling oneshot unclaimed register reporting. " 2927 "Please use i915.mmio_debug=N for more information.\n"); 2928 uncore->i915->params.mmio_debug++; 2929 } 2930 uncore->debug->unclaimed_mmio_check--; 2931 ret = true; 2932 } 2933 2934 out: 2935 spin_unlock_irq(&uncore->debug->lock); 2936 2937 return ret; 2938 } 2939 2940 /** 2941 * intel_uncore_forcewake_for_reg - which forcewake domains are needed to access 2942 * a register 2943 * @uncore: pointer to struct intel_uncore 2944 * @reg: register in question 2945 * @op: operation bitmask of FW_REG_READ and/or FW_REG_WRITE 2946 * 2947 * Returns a set of forcewake domains required to be taken with for example 2948 * intel_uncore_forcewake_get for the specified register to be accessible in the 2949 * specified mode (read, write or read/write) with raw mmio accessors. 2950 * 2951 * NOTE: On Gen6 and Gen7 write forcewake domain (FORCEWAKE_RENDER) requires the 2952 * callers to do FIFO management on their own or risk losing writes. 2953 */ 2954 enum forcewake_domains 2955 intel_uncore_forcewake_for_reg(struct intel_uncore *uncore, 2956 i915_reg_t reg, unsigned int op) 2957 { 2958 enum forcewake_domains fw_domains = 0; 2959 2960 drm_WARN_ON(&uncore->i915->drm, !op); 2961 2962 if (!intel_uncore_has_forcewake(uncore)) 2963 return 0; 2964 2965 if (op & FW_REG_READ) 2966 fw_domains = uncore->funcs.read_fw_domains(uncore, reg); 2967 2968 if (op & FW_REG_WRITE) 2969 fw_domains |= uncore->funcs.write_fw_domains(uncore, reg); 2970 2971 drm_WARN_ON(&uncore->i915->drm, fw_domains & ~uncore->fw_domains); 2972 2973 return fw_domains; 2974 } 2975 2976 #if IS_ENABLED(CONFIG_DRM_I915_SELFTEST) 2977 #include "selftests/mock_uncore.c" 2978 #include "selftests/intel_uncore.c" 2979 #endif 2980