1 /* SPDX-License-Identifier: MIT */
3 * Copyright © 2019 Intel Corporation
6 #include <linux/string_helpers.h>
10 #include "intel_backlight_regs.h"
11 #include "intel_cdclk.h"
12 #include "intel_combo_phy.h"
14 #include "intel_display_power.h"
15 #include "intel_display_power_map.h"
16 #include "intel_display_power_well.h"
17 #include "intel_display_types.h"
18 #include "intel_dmc.h"
19 #include "intel_mchbar_regs.h"
20 #include "intel_pch_refclk.h"
21 #include "intel_pcode.h"
22 #include "intel_pps_regs.h"
23 #include "intel_snps_phy.h"
24 #include "skl_watermark.h"
25 #include "skl_watermark_regs.h"
26 #include "vlv_sideband.h"
28 #define for_each_power_domain_well(__dev_priv, __power_well, __domain) \
29 for_each_power_well(__dev_priv, __power_well) \
30 for_each_if(test_bit((__domain), (__power_well)->domains.bits))
32 #define for_each_power_domain_well_reverse(__dev_priv, __power_well, __domain) \
33 for_each_power_well_reverse(__dev_priv, __power_well) \
34 for_each_if(test_bit((__domain), (__power_well)->domains.bits))
37 intel_display_power_domain_str(enum intel_display_power_domain domain)
40 case POWER_DOMAIN_DISPLAY_CORE:
41 return "DISPLAY_CORE";
42 case POWER_DOMAIN_PIPE_A:
44 case POWER_DOMAIN_PIPE_B:
46 case POWER_DOMAIN_PIPE_C:
48 case POWER_DOMAIN_PIPE_D:
50 case POWER_DOMAIN_PIPE_PANEL_FITTER_A:
51 return "PIPE_PANEL_FITTER_A";
52 case POWER_DOMAIN_PIPE_PANEL_FITTER_B:
53 return "PIPE_PANEL_FITTER_B";
54 case POWER_DOMAIN_PIPE_PANEL_FITTER_C:
55 return "PIPE_PANEL_FITTER_C";
56 case POWER_DOMAIN_PIPE_PANEL_FITTER_D:
57 return "PIPE_PANEL_FITTER_D";
58 case POWER_DOMAIN_TRANSCODER_A:
59 return "TRANSCODER_A";
60 case POWER_DOMAIN_TRANSCODER_B:
61 return "TRANSCODER_B";
62 case POWER_DOMAIN_TRANSCODER_C:
63 return "TRANSCODER_C";
64 case POWER_DOMAIN_TRANSCODER_D:
65 return "TRANSCODER_D";
66 case POWER_DOMAIN_TRANSCODER_EDP:
67 return "TRANSCODER_EDP";
68 case POWER_DOMAIN_TRANSCODER_DSI_A:
69 return "TRANSCODER_DSI_A";
70 case POWER_DOMAIN_TRANSCODER_DSI_C:
71 return "TRANSCODER_DSI_C";
72 case POWER_DOMAIN_TRANSCODER_VDSC_PW2:
73 return "TRANSCODER_VDSC_PW2";
74 case POWER_DOMAIN_PORT_DDI_LANES_A:
75 return "PORT_DDI_LANES_A";
76 case POWER_DOMAIN_PORT_DDI_LANES_B:
77 return "PORT_DDI_LANES_B";
78 case POWER_DOMAIN_PORT_DDI_LANES_C:
79 return "PORT_DDI_LANES_C";
80 case POWER_DOMAIN_PORT_DDI_LANES_D:
81 return "PORT_DDI_LANES_D";
82 case POWER_DOMAIN_PORT_DDI_LANES_E:
83 return "PORT_DDI_LANES_E";
84 case POWER_DOMAIN_PORT_DDI_LANES_F:
85 return "PORT_DDI_LANES_F";
86 case POWER_DOMAIN_PORT_DDI_LANES_TC1:
87 return "PORT_DDI_LANES_TC1";
88 case POWER_DOMAIN_PORT_DDI_LANES_TC2:
89 return "PORT_DDI_LANES_TC2";
90 case POWER_DOMAIN_PORT_DDI_LANES_TC3:
91 return "PORT_DDI_LANES_TC3";
92 case POWER_DOMAIN_PORT_DDI_LANES_TC4:
93 return "PORT_DDI_LANES_TC4";
94 case POWER_DOMAIN_PORT_DDI_LANES_TC5:
95 return "PORT_DDI_LANES_TC5";
96 case POWER_DOMAIN_PORT_DDI_LANES_TC6:
97 return "PORT_DDI_LANES_TC6";
98 case POWER_DOMAIN_PORT_DDI_IO_A:
99 return "PORT_DDI_IO_A";
100 case POWER_DOMAIN_PORT_DDI_IO_B:
101 return "PORT_DDI_IO_B";
102 case POWER_DOMAIN_PORT_DDI_IO_C:
103 return "PORT_DDI_IO_C";
104 case POWER_DOMAIN_PORT_DDI_IO_D:
105 return "PORT_DDI_IO_D";
106 case POWER_DOMAIN_PORT_DDI_IO_E:
107 return "PORT_DDI_IO_E";
108 case POWER_DOMAIN_PORT_DDI_IO_F:
109 return "PORT_DDI_IO_F";
110 case POWER_DOMAIN_PORT_DDI_IO_TC1:
111 return "PORT_DDI_IO_TC1";
112 case POWER_DOMAIN_PORT_DDI_IO_TC2:
113 return "PORT_DDI_IO_TC2";
114 case POWER_DOMAIN_PORT_DDI_IO_TC3:
115 return "PORT_DDI_IO_TC3";
116 case POWER_DOMAIN_PORT_DDI_IO_TC4:
117 return "PORT_DDI_IO_TC4";
118 case POWER_DOMAIN_PORT_DDI_IO_TC5:
119 return "PORT_DDI_IO_TC5";
120 case POWER_DOMAIN_PORT_DDI_IO_TC6:
121 return "PORT_DDI_IO_TC6";
122 case POWER_DOMAIN_PORT_DSI:
124 case POWER_DOMAIN_PORT_CRT:
126 case POWER_DOMAIN_PORT_OTHER:
128 case POWER_DOMAIN_VGA:
130 case POWER_DOMAIN_AUDIO_MMIO:
132 case POWER_DOMAIN_AUDIO_PLAYBACK:
133 return "AUDIO_PLAYBACK";
134 case POWER_DOMAIN_AUX_IO_A:
136 case POWER_DOMAIN_AUX_IO_B:
138 case POWER_DOMAIN_AUX_IO_C:
140 case POWER_DOMAIN_AUX_IO_D:
142 case POWER_DOMAIN_AUX_IO_E:
144 case POWER_DOMAIN_AUX_IO_F:
146 case POWER_DOMAIN_AUX_A:
148 case POWER_DOMAIN_AUX_B:
150 case POWER_DOMAIN_AUX_C:
152 case POWER_DOMAIN_AUX_D:
154 case POWER_DOMAIN_AUX_E:
156 case POWER_DOMAIN_AUX_F:
158 case POWER_DOMAIN_AUX_USBC1:
160 case POWER_DOMAIN_AUX_USBC2:
162 case POWER_DOMAIN_AUX_USBC3:
164 case POWER_DOMAIN_AUX_USBC4:
166 case POWER_DOMAIN_AUX_USBC5:
168 case POWER_DOMAIN_AUX_USBC6:
170 case POWER_DOMAIN_AUX_TBT1:
172 case POWER_DOMAIN_AUX_TBT2:
174 case POWER_DOMAIN_AUX_TBT3:
176 case POWER_DOMAIN_AUX_TBT4:
178 case POWER_DOMAIN_AUX_TBT5:
180 case POWER_DOMAIN_AUX_TBT6:
182 case POWER_DOMAIN_GMBUS:
184 case POWER_DOMAIN_INIT:
186 case POWER_DOMAIN_MODESET:
188 case POWER_DOMAIN_GT_IRQ:
190 case POWER_DOMAIN_DC_OFF:
192 case POWER_DOMAIN_TC_COLD_OFF:
193 return "TC_COLD_OFF";
195 MISSING_CASE(domain);
201 * __intel_display_power_is_enabled - unlocked check for a power domain
202 * @dev_priv: i915 device instance
203 * @domain: power domain to check
205 * This is the unlocked version of intel_display_power_is_enabled() and should
206 * only be used from error capture and recovery code where deadlocks are
210 * True when the power domain is enabled, false otherwise.
212 bool __intel_display_power_is_enabled(struct drm_i915_private *dev_priv,
213 enum intel_display_power_domain domain)
215 struct i915_power_well *power_well;
218 if (dev_priv->runtime_pm.suspended)
223 for_each_power_domain_well_reverse(dev_priv, power_well, domain) {
224 if (intel_power_well_is_always_on(power_well))
227 if (!intel_power_well_is_enabled_cached(power_well)) {
237 * intel_display_power_is_enabled - check for a power domain
238 * @dev_priv: i915 device instance
239 * @domain: power domain to check
241 * This function can be used to check the hw power domain state. It is mostly
242 * used in hardware state readout functions. Everywhere else code should rely
243 * upon explicit power domain reference counting to ensure that the hardware
244 * block is powered up before accessing it.
246 * Callers must hold the relevant modesetting locks to ensure that concurrent
247 * threads can't disable the power well while the caller tries to read a few
251 * True when the power domain is enabled, false otherwise.
253 bool intel_display_power_is_enabled(struct drm_i915_private *dev_priv,
254 enum intel_display_power_domain domain)
256 struct i915_power_domains *power_domains;
259 power_domains = &dev_priv->display.power.domains;
261 mutex_lock(&power_domains->lock);
262 ret = __intel_display_power_is_enabled(dev_priv, domain);
263 mutex_unlock(&power_domains->lock);
269 sanitize_target_dc_state(struct drm_i915_private *i915,
272 struct i915_power_domains *power_domains = &i915->display.power.domains;
273 static const u32 states[] = {
274 DC_STATE_EN_UPTO_DC6,
275 DC_STATE_EN_UPTO_DC5,
281 for (i = 0; i < ARRAY_SIZE(states) - 1; i++) {
282 if (target_dc_state != states[i])
285 if (power_domains->allowed_dc_mask & target_dc_state)
288 target_dc_state = states[i + 1];
291 return target_dc_state;
295 * intel_display_power_set_target_dc_state - Set target dc state.
296 * @dev_priv: i915 device
297 * @state: state which needs to be set as target_dc_state.
299 * This function set the "DC off" power well target_dc_state,
300 * based upon this target_dc_stste, "DC off" power well will
301 * enable desired DC state.
303 void intel_display_power_set_target_dc_state(struct drm_i915_private *dev_priv,
306 struct i915_power_well *power_well;
308 struct i915_power_domains *power_domains = &dev_priv->display.power.domains;
310 mutex_lock(&power_domains->lock);
311 power_well = lookup_power_well(dev_priv, SKL_DISP_DC_OFF);
313 if (drm_WARN_ON(&dev_priv->drm, !power_well))
316 state = sanitize_target_dc_state(dev_priv, state);
318 if (state == power_domains->target_dc_state)
321 dc_off_enabled = intel_power_well_is_enabled(dev_priv, power_well);
323 * If DC off power well is disabled, need to enable and disable the
324 * DC off power well to effect target DC state.
327 intel_power_well_enable(dev_priv, power_well);
329 power_domains->target_dc_state = state;
332 intel_power_well_disable(dev_priv, power_well);
335 mutex_unlock(&power_domains->lock);
338 #define POWER_DOMAIN_MASK (GENMASK_ULL(POWER_DOMAIN_NUM - 1, 0))
340 static void __async_put_domains_mask(struct i915_power_domains *power_domains,
341 struct intel_power_domain_mask *mask)
343 bitmap_or(mask->bits,
344 power_domains->async_put_domains[0].bits,
345 power_domains->async_put_domains[1].bits,
349 #if IS_ENABLED(CONFIG_DRM_I915_DEBUG_RUNTIME_PM)
352 assert_async_put_domain_masks_disjoint(struct i915_power_domains *power_domains)
354 struct drm_i915_private *i915 = container_of(power_domains,
355 struct drm_i915_private,
356 display.power.domains);
358 return !drm_WARN_ON(&i915->drm,
359 bitmap_intersects(power_domains->async_put_domains[0].bits,
360 power_domains->async_put_domains[1].bits,
365 __async_put_domains_state_ok(struct i915_power_domains *power_domains)
367 struct drm_i915_private *i915 = container_of(power_domains,
368 struct drm_i915_private,
369 display.power.domains);
370 struct intel_power_domain_mask async_put_mask;
371 enum intel_display_power_domain domain;
374 err |= !assert_async_put_domain_masks_disjoint(power_domains);
375 __async_put_domains_mask(power_domains, &async_put_mask);
376 err |= drm_WARN_ON(&i915->drm,
377 !!power_domains->async_put_wakeref !=
378 !bitmap_empty(async_put_mask.bits, POWER_DOMAIN_NUM));
380 for_each_power_domain(domain, &async_put_mask)
381 err |= drm_WARN_ON(&i915->drm,
382 power_domains->domain_use_count[domain] != 1);
387 static void print_power_domains(struct i915_power_domains *power_domains,
388 const char *prefix, struct intel_power_domain_mask *mask)
390 struct drm_i915_private *i915 = container_of(power_domains,
391 struct drm_i915_private,
392 display.power.domains);
393 enum intel_display_power_domain domain;
395 drm_dbg(&i915->drm, "%s (%d):\n", prefix, bitmap_weight(mask->bits, POWER_DOMAIN_NUM));
396 for_each_power_domain(domain, mask)
397 drm_dbg(&i915->drm, "%s use_count %d\n",
398 intel_display_power_domain_str(domain),
399 power_domains->domain_use_count[domain]);
403 print_async_put_domains_state(struct i915_power_domains *power_domains)
405 struct drm_i915_private *i915 = container_of(power_domains,
406 struct drm_i915_private,
407 display.power.domains);
409 drm_dbg(&i915->drm, "async_put_wakeref %u\n",
410 power_domains->async_put_wakeref);
412 print_power_domains(power_domains, "async_put_domains[0]",
413 &power_domains->async_put_domains[0]);
414 print_power_domains(power_domains, "async_put_domains[1]",
415 &power_domains->async_put_domains[1]);
419 verify_async_put_domains_state(struct i915_power_domains *power_domains)
421 if (!__async_put_domains_state_ok(power_domains))
422 print_async_put_domains_state(power_domains);
428 assert_async_put_domain_masks_disjoint(struct i915_power_domains *power_domains)
433 verify_async_put_domains_state(struct i915_power_domains *power_domains)
437 #endif /* CONFIG_DRM_I915_DEBUG_RUNTIME_PM */
439 static void async_put_domains_mask(struct i915_power_domains *power_domains,
440 struct intel_power_domain_mask *mask)
443 assert_async_put_domain_masks_disjoint(power_domains);
445 __async_put_domains_mask(power_domains, mask);
449 async_put_domains_clear_domain(struct i915_power_domains *power_domains,
450 enum intel_display_power_domain domain)
452 assert_async_put_domain_masks_disjoint(power_domains);
454 clear_bit(domain, power_domains->async_put_domains[0].bits);
455 clear_bit(domain, power_domains->async_put_domains[1].bits);
459 intel_display_power_grab_async_put_ref(struct drm_i915_private *dev_priv,
460 enum intel_display_power_domain domain)
462 struct i915_power_domains *power_domains = &dev_priv->display.power.domains;
463 struct intel_power_domain_mask async_put_mask;
466 async_put_domains_mask(power_domains, &async_put_mask);
467 if (!test_bit(domain, async_put_mask.bits))
470 async_put_domains_clear_domain(power_domains, domain);
474 async_put_domains_mask(power_domains, &async_put_mask);
475 if (!bitmap_empty(async_put_mask.bits, POWER_DOMAIN_NUM))
478 cancel_delayed_work(&power_domains->async_put_work);
479 intel_runtime_pm_put_raw(&dev_priv->runtime_pm,
480 fetch_and_zero(&power_domains->async_put_wakeref));
482 verify_async_put_domains_state(power_domains);
488 __intel_display_power_get_domain(struct drm_i915_private *dev_priv,
489 enum intel_display_power_domain domain)
491 struct i915_power_domains *power_domains = &dev_priv->display.power.domains;
492 struct i915_power_well *power_well;
494 if (intel_display_power_grab_async_put_ref(dev_priv, domain))
497 for_each_power_domain_well(dev_priv, power_well, domain)
498 intel_power_well_get(dev_priv, power_well);
500 power_domains->domain_use_count[domain]++;
504 * intel_display_power_get - grab a power domain reference
505 * @dev_priv: i915 device instance
506 * @domain: power domain to reference
508 * This function grabs a power domain reference for @domain and ensures that the
509 * power domain and all its parents are powered up. Therefore users should only
510 * grab a reference to the innermost power domain they need.
512 * Any power domain reference obtained by this function must have a symmetric
513 * call to intel_display_power_put() to release the reference again.
515 intel_wakeref_t intel_display_power_get(struct drm_i915_private *dev_priv,
516 enum intel_display_power_domain domain)
518 struct i915_power_domains *power_domains = &dev_priv->display.power.domains;
519 intel_wakeref_t wakeref = intel_runtime_pm_get(&dev_priv->runtime_pm);
521 mutex_lock(&power_domains->lock);
522 __intel_display_power_get_domain(dev_priv, domain);
523 mutex_unlock(&power_domains->lock);
529 * intel_display_power_get_if_enabled - grab a reference for an enabled display power domain
530 * @dev_priv: i915 device instance
531 * @domain: power domain to reference
533 * This function grabs a power domain reference for @domain and ensures that the
534 * power domain and all its parents are powered up. Therefore users should only
535 * grab a reference to the innermost power domain they need.
537 * Any power domain reference obtained by this function must have a symmetric
538 * call to intel_display_power_put() to release the reference again.
541 intel_display_power_get_if_enabled(struct drm_i915_private *dev_priv,
542 enum intel_display_power_domain domain)
544 struct i915_power_domains *power_domains = &dev_priv->display.power.domains;
545 intel_wakeref_t wakeref;
548 wakeref = intel_runtime_pm_get_if_in_use(&dev_priv->runtime_pm);
552 mutex_lock(&power_domains->lock);
554 if (__intel_display_power_is_enabled(dev_priv, domain)) {
555 __intel_display_power_get_domain(dev_priv, domain);
561 mutex_unlock(&power_domains->lock);
564 intel_runtime_pm_put(&dev_priv->runtime_pm, wakeref);
572 __intel_display_power_put_domain(struct drm_i915_private *dev_priv,
573 enum intel_display_power_domain domain)
575 struct i915_power_domains *power_domains;
576 struct i915_power_well *power_well;
577 const char *name = intel_display_power_domain_str(domain);
578 struct intel_power_domain_mask async_put_mask;
580 power_domains = &dev_priv->display.power.domains;
582 drm_WARN(&dev_priv->drm, !power_domains->domain_use_count[domain],
583 "Use count on domain %s is already zero\n",
585 async_put_domains_mask(power_domains, &async_put_mask);
586 drm_WARN(&dev_priv->drm,
587 test_bit(domain, async_put_mask.bits),
588 "Async disabling of domain %s is pending\n",
591 power_domains->domain_use_count[domain]--;
593 for_each_power_domain_well_reverse(dev_priv, power_well, domain)
594 intel_power_well_put(dev_priv, power_well);
597 static void __intel_display_power_put(struct drm_i915_private *dev_priv,
598 enum intel_display_power_domain domain)
600 struct i915_power_domains *power_domains = &dev_priv->display.power.domains;
602 mutex_lock(&power_domains->lock);
603 __intel_display_power_put_domain(dev_priv, domain);
604 mutex_unlock(&power_domains->lock);
608 queue_async_put_domains_work(struct i915_power_domains *power_domains,
609 intel_wakeref_t wakeref)
611 struct drm_i915_private *i915 = container_of(power_domains,
612 struct drm_i915_private,
613 display.power.domains);
614 drm_WARN_ON(&i915->drm, power_domains->async_put_wakeref);
615 power_domains->async_put_wakeref = wakeref;
616 drm_WARN_ON(&i915->drm, !queue_delayed_work(system_unbound_wq,
617 &power_domains->async_put_work,
618 msecs_to_jiffies(100)));
622 release_async_put_domains(struct i915_power_domains *power_domains,
623 struct intel_power_domain_mask *mask)
625 struct drm_i915_private *dev_priv =
626 container_of(power_domains, struct drm_i915_private,
627 display.power.domains);
628 struct intel_runtime_pm *rpm = &dev_priv->runtime_pm;
629 enum intel_display_power_domain domain;
630 intel_wakeref_t wakeref;
633 * The caller must hold already raw wakeref, upgrade that to a proper
634 * wakeref to make the state checker happy about the HW access during
635 * power well disabling.
637 assert_rpm_raw_wakeref_held(rpm);
638 wakeref = intel_runtime_pm_get(rpm);
640 for_each_power_domain(domain, mask) {
641 /* Clear before put, so put's sanity check is happy. */
642 async_put_domains_clear_domain(power_domains, domain);
643 __intel_display_power_put_domain(dev_priv, domain);
646 intel_runtime_pm_put(rpm, wakeref);
650 intel_display_power_put_async_work(struct work_struct *work)
652 struct drm_i915_private *dev_priv =
653 container_of(work, struct drm_i915_private,
654 display.power.domains.async_put_work.work);
655 struct i915_power_domains *power_domains = &dev_priv->display.power.domains;
656 struct intel_runtime_pm *rpm = &dev_priv->runtime_pm;
657 intel_wakeref_t new_work_wakeref = intel_runtime_pm_get_raw(rpm);
658 intel_wakeref_t old_work_wakeref = 0;
660 mutex_lock(&power_domains->lock);
663 * Bail out if all the domain refs pending to be released were grabbed
664 * by subsequent gets or a flush_work.
666 old_work_wakeref = fetch_and_zero(&power_domains->async_put_wakeref);
667 if (!old_work_wakeref)
670 release_async_put_domains(power_domains,
671 &power_domains->async_put_domains[0]);
673 /* Requeue the work if more domains were async put meanwhile. */
674 if (!bitmap_empty(power_domains->async_put_domains[1].bits, POWER_DOMAIN_NUM)) {
675 bitmap_copy(power_domains->async_put_domains[0].bits,
676 power_domains->async_put_domains[1].bits,
678 bitmap_zero(power_domains->async_put_domains[1].bits,
680 queue_async_put_domains_work(power_domains,
681 fetch_and_zero(&new_work_wakeref));
684 * Cancel the work that got queued after this one got dequeued,
685 * since here we released the corresponding async-put reference.
687 cancel_delayed_work(&power_domains->async_put_work);
691 verify_async_put_domains_state(power_domains);
693 mutex_unlock(&power_domains->lock);
695 if (old_work_wakeref)
696 intel_runtime_pm_put_raw(rpm, old_work_wakeref);
697 if (new_work_wakeref)
698 intel_runtime_pm_put_raw(rpm, new_work_wakeref);
702 * __intel_display_power_put_async - release a power domain reference asynchronously
703 * @i915: i915 device instance
704 * @domain: power domain to reference
705 * @wakeref: wakeref acquired for the reference that is being released
707 * This function drops the power domain reference obtained by
708 * intel_display_power_get*() and schedules a work to power down the
709 * corresponding hardware block if this is the last reference.
711 void __intel_display_power_put_async(struct drm_i915_private *i915,
712 enum intel_display_power_domain domain,
713 intel_wakeref_t wakeref)
715 struct i915_power_domains *power_domains = &i915->display.power.domains;
716 struct intel_runtime_pm *rpm = &i915->runtime_pm;
717 intel_wakeref_t work_wakeref = intel_runtime_pm_get_raw(rpm);
719 mutex_lock(&power_domains->lock);
721 if (power_domains->domain_use_count[domain] > 1) {
722 __intel_display_power_put_domain(i915, domain);
727 drm_WARN_ON(&i915->drm, power_domains->domain_use_count[domain] != 1);
729 /* Let a pending work requeue itself or queue a new one. */
730 if (power_domains->async_put_wakeref) {
731 set_bit(domain, power_domains->async_put_domains[1].bits);
733 set_bit(domain, power_domains->async_put_domains[0].bits);
734 queue_async_put_domains_work(power_domains,
735 fetch_and_zero(&work_wakeref));
739 verify_async_put_domains_state(power_domains);
741 mutex_unlock(&power_domains->lock);
744 intel_runtime_pm_put_raw(rpm, work_wakeref);
746 intel_runtime_pm_put(rpm, wakeref);
750 * intel_display_power_flush_work - flushes the async display power disabling work
751 * @i915: i915 device instance
753 * Flushes any pending work that was scheduled by a preceding
754 * intel_display_power_put_async() call, completing the disabling of the
755 * corresponding power domains.
757 * Note that the work handler function may still be running after this
758 * function returns; to ensure that the work handler isn't running use
759 * intel_display_power_flush_work_sync() instead.
761 void intel_display_power_flush_work(struct drm_i915_private *i915)
763 struct i915_power_domains *power_domains = &i915->display.power.domains;
764 struct intel_power_domain_mask async_put_mask;
765 intel_wakeref_t work_wakeref;
767 mutex_lock(&power_domains->lock);
769 work_wakeref = fetch_and_zero(&power_domains->async_put_wakeref);
773 async_put_domains_mask(power_domains, &async_put_mask);
774 release_async_put_domains(power_domains, &async_put_mask);
775 cancel_delayed_work(&power_domains->async_put_work);
778 verify_async_put_domains_state(power_domains);
780 mutex_unlock(&power_domains->lock);
783 intel_runtime_pm_put_raw(&i915->runtime_pm, work_wakeref);
787 * intel_display_power_flush_work_sync - flushes and syncs the async display power disabling work
788 * @i915: i915 device instance
790 * Like intel_display_power_flush_work(), but also ensure that the work
791 * handler function is not running any more when this function returns.
794 intel_display_power_flush_work_sync(struct drm_i915_private *i915)
796 struct i915_power_domains *power_domains = &i915->display.power.domains;
798 intel_display_power_flush_work(i915);
799 cancel_delayed_work_sync(&power_domains->async_put_work);
801 verify_async_put_domains_state(power_domains);
803 drm_WARN_ON(&i915->drm, power_domains->async_put_wakeref);
806 #if IS_ENABLED(CONFIG_DRM_I915_DEBUG_RUNTIME_PM)
808 * intel_display_power_put - release a power domain reference
809 * @dev_priv: i915 device instance
810 * @domain: power domain to reference
811 * @wakeref: wakeref acquired for the reference that is being released
813 * This function drops the power domain reference obtained by
814 * intel_display_power_get() and might power down the corresponding hardware
815 * block right away if this is the last reference.
817 void intel_display_power_put(struct drm_i915_private *dev_priv,
818 enum intel_display_power_domain domain,
819 intel_wakeref_t wakeref)
821 __intel_display_power_put(dev_priv, domain);
822 intel_runtime_pm_put(&dev_priv->runtime_pm, wakeref);
826 * intel_display_power_put_unchecked - release an unchecked power domain reference
827 * @dev_priv: i915 device instance
828 * @domain: power domain to reference
830 * This function drops the power domain reference obtained by
831 * intel_display_power_get() and might power down the corresponding hardware
832 * block right away if this is the last reference.
834 * This function is only for the power domain code's internal use to suppress wakeref
835 * tracking when the correspondig debug kconfig option is disabled, should not
838 void intel_display_power_put_unchecked(struct drm_i915_private *dev_priv,
839 enum intel_display_power_domain domain)
841 __intel_display_power_put(dev_priv, domain);
842 intel_runtime_pm_put_unchecked(&dev_priv->runtime_pm);
847 intel_display_power_get_in_set(struct drm_i915_private *i915,
848 struct intel_display_power_domain_set *power_domain_set,
849 enum intel_display_power_domain domain)
851 intel_wakeref_t __maybe_unused wf;
853 drm_WARN_ON(&i915->drm, test_bit(domain, power_domain_set->mask.bits));
855 wf = intel_display_power_get(i915, domain);
856 #if IS_ENABLED(CONFIG_DRM_I915_DEBUG_RUNTIME_PM)
857 power_domain_set->wakerefs[domain] = wf;
859 set_bit(domain, power_domain_set->mask.bits);
863 intel_display_power_get_in_set_if_enabled(struct drm_i915_private *i915,
864 struct intel_display_power_domain_set *power_domain_set,
865 enum intel_display_power_domain domain)
869 drm_WARN_ON(&i915->drm, test_bit(domain, power_domain_set->mask.bits));
871 wf = intel_display_power_get_if_enabled(i915, domain);
875 #if IS_ENABLED(CONFIG_DRM_I915_DEBUG_RUNTIME_PM)
876 power_domain_set->wakerefs[domain] = wf;
878 set_bit(domain, power_domain_set->mask.bits);
884 intel_display_power_put_mask_in_set(struct drm_i915_private *i915,
885 struct intel_display_power_domain_set *power_domain_set,
886 struct intel_power_domain_mask *mask)
888 enum intel_display_power_domain domain;
890 drm_WARN_ON(&i915->drm,
891 !bitmap_subset(mask->bits, power_domain_set->mask.bits, POWER_DOMAIN_NUM));
893 for_each_power_domain(domain, mask) {
894 intel_wakeref_t __maybe_unused wf = -1;
896 #if IS_ENABLED(CONFIG_DRM_I915_DEBUG_RUNTIME_PM)
897 wf = fetch_and_zero(&power_domain_set->wakerefs[domain]);
899 intel_display_power_put(i915, domain, wf);
900 clear_bit(domain, power_domain_set->mask.bits);
905 sanitize_disable_power_well_option(const struct drm_i915_private *dev_priv,
906 int disable_power_well)
908 if (disable_power_well >= 0)
909 return !!disable_power_well;
914 static u32 get_allowed_dc_mask(const struct drm_i915_private *dev_priv,
921 if (!HAS_DISPLAY(dev_priv))
924 if (IS_DG2(dev_priv))
926 else if (IS_DG1(dev_priv))
928 else if (DISPLAY_VER(dev_priv) >= 12)
930 else if (IS_GEMINILAKE(dev_priv) || IS_BROXTON(dev_priv))
932 else if (DISPLAY_VER(dev_priv) >= 9)
938 * DC9 has a separate HW flow from the rest of the DC states,
939 * not depending on the DMC firmware. It's needed by system
940 * suspend/resume, so allow it unconditionally.
942 mask = IS_GEMINILAKE(dev_priv) || IS_BROXTON(dev_priv) ||
943 DISPLAY_VER(dev_priv) >= 11 ?
946 if (!dev_priv->params.disable_power_well)
949 if (enable_dc >= 0 && enable_dc <= max_dc) {
950 requested_dc = enable_dc;
951 } else if (enable_dc == -1) {
952 requested_dc = max_dc;
953 } else if (enable_dc > max_dc && enable_dc <= 4) {
954 drm_dbg_kms(&dev_priv->drm,
955 "Adjusting requested max DC state (%d->%d)\n",
957 requested_dc = max_dc;
959 drm_err(&dev_priv->drm,
960 "Unexpected value for enable_dc (%d)\n", enable_dc);
961 requested_dc = max_dc;
964 switch (requested_dc) {
966 mask |= DC_STATE_EN_DC3CO | DC_STATE_EN_UPTO_DC6;
969 mask |= DC_STATE_EN_DC3CO | DC_STATE_EN_UPTO_DC5;
972 mask |= DC_STATE_EN_UPTO_DC6;
975 mask |= DC_STATE_EN_UPTO_DC5;
979 drm_dbg_kms(&dev_priv->drm, "Allowed DC state mask %02x\n", mask);
985 * intel_power_domains_init - initializes the power domain structures
986 * @dev_priv: i915 device instance
988 * Initializes the power domain structures for @dev_priv depending upon the
989 * supported platform.
991 int intel_power_domains_init(struct drm_i915_private *dev_priv)
993 struct i915_power_domains *power_domains = &dev_priv->display.power.domains;
995 dev_priv->params.disable_power_well =
996 sanitize_disable_power_well_option(dev_priv,
997 dev_priv->params.disable_power_well);
998 power_domains->allowed_dc_mask =
999 get_allowed_dc_mask(dev_priv, dev_priv->params.enable_dc);
1001 power_domains->target_dc_state =
1002 sanitize_target_dc_state(dev_priv, DC_STATE_EN_UPTO_DC6);
1004 mutex_init(&power_domains->lock);
1006 INIT_DELAYED_WORK(&power_domains->async_put_work,
1007 intel_display_power_put_async_work);
1009 return intel_display_power_map_init(power_domains);
1013 * intel_power_domains_cleanup - clean up power domains resources
1014 * @dev_priv: i915 device instance
1016 * Release any resources acquired by intel_power_domains_init()
1018 void intel_power_domains_cleanup(struct drm_i915_private *dev_priv)
1020 intel_display_power_map_cleanup(&dev_priv->display.power.domains);
1023 static void intel_power_domains_sync_hw(struct drm_i915_private *dev_priv)
1025 struct i915_power_domains *power_domains = &dev_priv->display.power.domains;
1026 struct i915_power_well *power_well;
1028 mutex_lock(&power_domains->lock);
1029 for_each_power_well(dev_priv, power_well)
1030 intel_power_well_sync_hw(dev_priv, power_well);
1031 mutex_unlock(&power_domains->lock);
1034 static void gen9_dbuf_slice_set(struct drm_i915_private *dev_priv,
1035 enum dbuf_slice slice, bool enable)
1037 i915_reg_t reg = DBUF_CTL_S(slice);
1040 intel_de_rmw(dev_priv, reg, DBUF_POWER_REQUEST,
1041 enable ? DBUF_POWER_REQUEST : 0);
1042 intel_de_posting_read(dev_priv, reg);
1045 state = intel_de_read(dev_priv, reg) & DBUF_POWER_STATE;
1046 drm_WARN(&dev_priv->drm, enable != state,
1047 "DBuf slice %d power %s timeout!\n",
1048 slice, str_enable_disable(enable));
1051 void gen9_dbuf_slices_update(struct drm_i915_private *dev_priv,
1054 struct i915_power_domains *power_domains = &dev_priv->display.power.domains;
1055 u8 slice_mask = INTEL_INFO(dev_priv)->display.dbuf.slice_mask;
1056 enum dbuf_slice slice;
1058 drm_WARN(&dev_priv->drm, req_slices & ~slice_mask,
1059 "Invalid set of dbuf slices (0x%x) requested (total dbuf slices 0x%x)\n",
1060 req_slices, slice_mask);
1062 drm_dbg_kms(&dev_priv->drm, "Updating dbuf slices to 0x%x\n",
1066 * Might be running this in parallel to gen9_dc_off_power_well_enable
1067 * being called from intel_dp_detect for instance,
1068 * which causes assertion triggered by race condition,
1069 * as gen9_assert_dbuf_enabled might preempt this when registers
1070 * were already updated, while dev_priv was not.
1072 mutex_lock(&power_domains->lock);
1074 for_each_dbuf_slice(dev_priv, slice)
1075 gen9_dbuf_slice_set(dev_priv, slice, req_slices & BIT(slice));
1077 dev_priv->display.dbuf.enabled_slices = req_slices;
1079 mutex_unlock(&power_domains->lock);
1082 static void gen9_dbuf_enable(struct drm_i915_private *dev_priv)
1084 dev_priv->display.dbuf.enabled_slices =
1085 intel_enabled_dbuf_slices_mask(dev_priv);
1088 * Just power up at least 1 slice, we will
1089 * figure out later which slices we have and what we need.
1091 gen9_dbuf_slices_update(dev_priv, BIT(DBUF_S1) |
1092 dev_priv->display.dbuf.enabled_slices);
1095 static void gen9_dbuf_disable(struct drm_i915_private *dev_priv)
1097 gen9_dbuf_slices_update(dev_priv, 0);
1100 static void gen12_dbuf_slices_config(struct drm_i915_private *dev_priv)
1102 enum dbuf_slice slice;
1104 if (IS_ALDERLAKE_P(dev_priv))
1107 for_each_dbuf_slice(dev_priv, slice)
1108 intel_de_rmw(dev_priv, DBUF_CTL_S(slice),
1109 DBUF_TRACKER_STATE_SERVICE_MASK,
1110 DBUF_TRACKER_STATE_SERVICE(8));
1113 static void icl_mbus_init(struct drm_i915_private *dev_priv)
1115 unsigned long abox_regs = INTEL_INFO(dev_priv)->display.abox_mask;
1118 if (IS_ALDERLAKE_P(dev_priv) || DISPLAY_VER(dev_priv) >= 14)
1121 mask = MBUS_ABOX_BT_CREDIT_POOL1_MASK |
1122 MBUS_ABOX_BT_CREDIT_POOL2_MASK |
1123 MBUS_ABOX_B_CREDIT_MASK |
1124 MBUS_ABOX_BW_CREDIT_MASK;
1125 val = MBUS_ABOX_BT_CREDIT_POOL1(16) |
1126 MBUS_ABOX_BT_CREDIT_POOL2(16) |
1127 MBUS_ABOX_B_CREDIT(1) |
1128 MBUS_ABOX_BW_CREDIT(1);
1131 * gen12 platforms that use abox1 and abox2 for pixel data reads still
1132 * expect us to program the abox_ctl0 register as well, even though
1133 * we don't have to program other instance-0 registers like BW_BUDDY.
1135 if (DISPLAY_VER(dev_priv) == 12)
1136 abox_regs |= BIT(0);
1138 for_each_set_bit(i, &abox_regs, sizeof(abox_regs))
1139 intel_de_rmw(dev_priv, MBUS_ABOX_CTL(i), mask, val);
1142 static void hsw_assert_cdclk(struct drm_i915_private *dev_priv)
1144 u32 val = intel_de_read(dev_priv, LCPLL_CTL);
1147 * The LCPLL register should be turned on by the BIOS. For now
1148 * let's just check its state and print errors in case
1149 * something is wrong. Don't even try to turn it on.
1152 if (val & LCPLL_CD_SOURCE_FCLK)
1153 drm_err(&dev_priv->drm, "CDCLK source is not LCPLL\n");
1155 if (val & LCPLL_PLL_DISABLE)
1156 drm_err(&dev_priv->drm, "LCPLL is disabled\n");
1158 if ((val & LCPLL_REF_MASK) != LCPLL_REF_NON_SSC)
1159 drm_err(&dev_priv->drm, "LCPLL not using non-SSC reference\n");
1162 static void assert_can_disable_lcpll(struct drm_i915_private *dev_priv)
1164 struct intel_crtc *crtc;
1166 for_each_intel_crtc(&dev_priv->drm, crtc)
1167 I915_STATE_WARN(crtc->active, "CRTC for pipe %c enabled\n",
1168 pipe_name(crtc->pipe));
1170 I915_STATE_WARN(intel_de_read(dev_priv, HSW_PWR_WELL_CTL2),
1171 "Display power well on\n");
1172 I915_STATE_WARN(intel_de_read(dev_priv, SPLL_CTL) & SPLL_PLL_ENABLE,
1174 I915_STATE_WARN(intel_de_read(dev_priv, WRPLL_CTL(0)) & WRPLL_PLL_ENABLE,
1175 "WRPLL1 enabled\n");
1176 I915_STATE_WARN(intel_de_read(dev_priv, WRPLL_CTL(1)) & WRPLL_PLL_ENABLE,
1177 "WRPLL2 enabled\n");
1178 I915_STATE_WARN(intel_de_read(dev_priv, PP_STATUS(0)) & PP_ON,
1179 "Panel power on\n");
1180 I915_STATE_WARN(intel_de_read(dev_priv, BLC_PWM_CPU_CTL2) & BLM_PWM_ENABLE,
1181 "CPU PWM1 enabled\n");
1182 if (IS_HASWELL(dev_priv))
1183 I915_STATE_WARN(intel_de_read(dev_priv, HSW_BLC_PWM2_CTL) & BLM_PWM_ENABLE,
1184 "CPU PWM2 enabled\n");
1185 I915_STATE_WARN(intel_de_read(dev_priv, BLC_PWM_PCH_CTL1) & BLM_PCH_PWM_ENABLE,
1186 "PCH PWM1 enabled\n");
1187 I915_STATE_WARN((intel_de_read(dev_priv, UTIL_PIN_CTL) &
1188 (UTIL_PIN_ENABLE | UTIL_PIN_MODE_MASK)) ==
1189 (UTIL_PIN_ENABLE | UTIL_PIN_MODE_PWM),
1190 "Utility pin enabled in PWM mode\n");
1191 I915_STATE_WARN(intel_de_read(dev_priv, PCH_GTC_CTL) & PCH_GTC_ENABLE,
1192 "PCH GTC enabled\n");
1195 * In theory we can still leave IRQs enabled, as long as only the HPD
1196 * interrupts remain enabled. We used to check for that, but since it's
1197 * gen-specific and since we only disable LCPLL after we fully disable
1198 * the interrupts, the check below should be enough.
1200 I915_STATE_WARN(intel_irqs_enabled(dev_priv), "IRQs enabled\n");
1203 static u32 hsw_read_dcomp(struct drm_i915_private *dev_priv)
1205 if (IS_HASWELL(dev_priv))
1206 return intel_de_read(dev_priv, D_COMP_HSW);
1208 return intel_de_read(dev_priv, D_COMP_BDW);
1211 static void hsw_write_dcomp(struct drm_i915_private *dev_priv, u32 val)
1213 if (IS_HASWELL(dev_priv)) {
1214 if (snb_pcode_write(&dev_priv->uncore, GEN6_PCODE_WRITE_D_COMP, val))
1215 drm_dbg_kms(&dev_priv->drm,
1216 "Failed to write to D_COMP\n");
1218 intel_de_write(dev_priv, D_COMP_BDW, val);
1219 intel_de_posting_read(dev_priv, D_COMP_BDW);
1224 * This function implements pieces of two sequences from BSpec:
1225 * - Sequence for display software to disable LCPLL
1226 * - Sequence for display software to allow package C8+
1227 * The steps implemented here are just the steps that actually touch the LCPLL
1228 * register. Callers should take care of disabling all the display engine
1229 * functions, doing the mode unset, fixing interrupts, etc.
1231 static void hsw_disable_lcpll(struct drm_i915_private *dev_priv,
1232 bool switch_to_fclk, bool allow_power_down)
1236 assert_can_disable_lcpll(dev_priv);
1238 val = intel_de_read(dev_priv, LCPLL_CTL);
1240 if (switch_to_fclk) {
1241 val |= LCPLL_CD_SOURCE_FCLK;
1242 intel_de_write(dev_priv, LCPLL_CTL, val);
1244 if (wait_for_us(intel_de_read(dev_priv, LCPLL_CTL) &
1245 LCPLL_CD_SOURCE_FCLK_DONE, 1))
1246 drm_err(&dev_priv->drm, "Switching to FCLK failed\n");
1248 val = intel_de_read(dev_priv, LCPLL_CTL);
1251 val |= LCPLL_PLL_DISABLE;
1252 intel_de_write(dev_priv, LCPLL_CTL, val);
1253 intel_de_posting_read(dev_priv, LCPLL_CTL);
1255 if (intel_de_wait_for_clear(dev_priv, LCPLL_CTL, LCPLL_PLL_LOCK, 1))
1256 drm_err(&dev_priv->drm, "LCPLL still locked\n");
1258 val = hsw_read_dcomp(dev_priv);
1259 val |= D_COMP_COMP_DISABLE;
1260 hsw_write_dcomp(dev_priv, val);
1263 if (wait_for((hsw_read_dcomp(dev_priv) &
1264 D_COMP_RCOMP_IN_PROGRESS) == 0, 1))
1265 drm_err(&dev_priv->drm, "D_COMP RCOMP still in progress\n");
1267 if (allow_power_down) {
1268 intel_de_rmw(dev_priv, LCPLL_CTL, 0, LCPLL_POWER_DOWN_ALLOW);
1269 intel_de_posting_read(dev_priv, LCPLL_CTL);
1274 * Fully restores LCPLL, disallowing power down and switching back to LCPLL
1277 static void hsw_restore_lcpll(struct drm_i915_private *dev_priv)
1281 val = intel_de_read(dev_priv, LCPLL_CTL);
1283 if ((val & (LCPLL_PLL_LOCK | LCPLL_PLL_DISABLE | LCPLL_CD_SOURCE_FCLK |
1284 LCPLL_POWER_DOWN_ALLOW)) == LCPLL_PLL_LOCK)
1288 * Make sure we're not on PC8 state before disabling PC8, otherwise
1289 * we'll hang the machine. To prevent PC8 state, just enable force_wake.
1291 intel_uncore_forcewake_get(&dev_priv->uncore, FORCEWAKE_ALL);
1293 if (val & LCPLL_POWER_DOWN_ALLOW) {
1294 val &= ~LCPLL_POWER_DOWN_ALLOW;
1295 intel_de_write(dev_priv, LCPLL_CTL, val);
1296 intel_de_posting_read(dev_priv, LCPLL_CTL);
1299 val = hsw_read_dcomp(dev_priv);
1300 val |= D_COMP_COMP_FORCE;
1301 val &= ~D_COMP_COMP_DISABLE;
1302 hsw_write_dcomp(dev_priv, val);
1304 val = intel_de_read(dev_priv, LCPLL_CTL);
1305 val &= ~LCPLL_PLL_DISABLE;
1306 intel_de_write(dev_priv, LCPLL_CTL, val);
1308 if (intel_de_wait_for_set(dev_priv, LCPLL_CTL, LCPLL_PLL_LOCK, 5))
1309 drm_err(&dev_priv->drm, "LCPLL not locked yet\n");
1311 if (val & LCPLL_CD_SOURCE_FCLK) {
1312 intel_de_rmw(dev_priv, LCPLL_CTL, LCPLL_CD_SOURCE_FCLK, 0);
1314 if (wait_for_us((intel_de_read(dev_priv, LCPLL_CTL) &
1315 LCPLL_CD_SOURCE_FCLK_DONE) == 0, 1))
1316 drm_err(&dev_priv->drm,
1317 "Switching back to LCPLL failed\n");
1320 intel_uncore_forcewake_put(&dev_priv->uncore, FORCEWAKE_ALL);
1322 intel_update_cdclk(dev_priv);
1323 intel_cdclk_dump_config(dev_priv, &dev_priv->display.cdclk.hw, "Current CDCLK");
1327 * Package states C8 and deeper are really deep PC states that can only be
1328 * reached when all the devices on the system allow it, so even if the graphics
1329 * device allows PC8+, it doesn't mean the system will actually get to these
1330 * states. Our driver only allows PC8+ when going into runtime PM.
1332 * The requirements for PC8+ are that all the outputs are disabled, the power
1333 * well is disabled and most interrupts are disabled, and these are also
1334 * requirements for runtime PM. When these conditions are met, we manually do
1335 * the other conditions: disable the interrupts, clocks and switch LCPLL refclk
1336 * to Fclk. If we're in PC8+ and we get an non-hotplug interrupt, we can hard
1339 * When we really reach PC8 or deeper states (not just when we allow it) we lose
1340 * the state of some registers, so when we come back from PC8+ we need to
1341 * restore this state. We don't get into PC8+ if we're not in RC6, so we don't
1342 * need to take care of the registers kept by RC6. Notice that this happens even
1343 * if we don't put the device in PCI D3 state (which is what currently happens
1344 * because of the runtime PM support).
1346 * For more, read "Display Sequences for Package C8" on the hardware
1349 static void hsw_enable_pc8(struct drm_i915_private *dev_priv)
1351 drm_dbg_kms(&dev_priv->drm, "Enabling package C8+\n");
1353 if (HAS_PCH_LPT_LP(dev_priv))
1354 intel_de_rmw(dev_priv, SOUTH_DSPCLK_GATE_D,
1355 PCH_LP_PARTITION_LEVEL_DISABLE, 0);
1357 lpt_disable_clkout_dp(dev_priv);
1358 hsw_disable_lcpll(dev_priv, true, true);
1361 static void hsw_disable_pc8(struct drm_i915_private *dev_priv)
1363 drm_dbg_kms(&dev_priv->drm, "Disabling package C8+\n");
1365 hsw_restore_lcpll(dev_priv);
1366 intel_init_pch_refclk(dev_priv);
1368 if (HAS_PCH_LPT_LP(dev_priv))
1369 intel_de_rmw(dev_priv, SOUTH_DSPCLK_GATE_D,
1370 0, PCH_LP_PARTITION_LEVEL_DISABLE);
1373 static void intel_pch_reset_handshake(struct drm_i915_private *dev_priv,
1379 if (IS_IVYBRIDGE(dev_priv)) {
1381 reset_bits = WAIT_FOR_PCH_FLR_ACK | WAIT_FOR_PCH_RESET_ACK;
1383 reg = HSW_NDE_RSTWRN_OPT;
1384 reset_bits = RESET_PCH_HANDSHAKE_ENABLE;
1387 if (DISPLAY_VER(dev_priv) >= 14)
1388 reset_bits |= MTL_RESET_PICA_HANDSHAKE_EN;
1390 intel_de_rmw(dev_priv, reg, reset_bits, enable ? reset_bits : 0);
1393 static void skl_display_core_init(struct drm_i915_private *dev_priv,
1396 struct i915_power_domains *power_domains = &dev_priv->display.power.domains;
1397 struct i915_power_well *well;
1399 gen9_set_dc_state(dev_priv, DC_STATE_DISABLE);
1401 /* enable PCH reset handshake */
1402 intel_pch_reset_handshake(dev_priv, !HAS_PCH_NOP(dev_priv));
1404 if (!HAS_DISPLAY(dev_priv))
1407 /* enable PG1 and Misc I/O */
1408 mutex_lock(&power_domains->lock);
1410 well = lookup_power_well(dev_priv, SKL_DISP_PW_1);
1411 intel_power_well_enable(dev_priv, well);
1413 well = lookup_power_well(dev_priv, SKL_DISP_PW_MISC_IO);
1414 intel_power_well_enable(dev_priv, well);
1416 mutex_unlock(&power_domains->lock);
1418 intel_cdclk_init_hw(dev_priv);
1420 gen9_dbuf_enable(dev_priv);
1423 intel_dmc_load_program(dev_priv);
1426 static void skl_display_core_uninit(struct drm_i915_private *dev_priv)
1428 struct i915_power_domains *power_domains = &dev_priv->display.power.domains;
1429 struct i915_power_well *well;
1431 if (!HAS_DISPLAY(dev_priv))
1434 gen9_disable_dc_states(dev_priv);
1435 /* TODO: disable DMC program */
1437 gen9_dbuf_disable(dev_priv);
1439 intel_cdclk_uninit_hw(dev_priv);
1441 /* The spec doesn't call for removing the reset handshake flag */
1442 /* disable PG1 and Misc I/O */
1444 mutex_lock(&power_domains->lock);
1447 * BSpec says to keep the MISC IO power well enabled here, only
1448 * remove our request for power well 1.
1449 * Note that even though the driver's request is removed power well 1
1450 * may stay enabled after this due to DMC's own request on it.
1452 well = lookup_power_well(dev_priv, SKL_DISP_PW_1);
1453 intel_power_well_disable(dev_priv, well);
1455 mutex_unlock(&power_domains->lock);
1457 usleep_range(10, 30); /* 10 us delay per Bspec */
1460 static void bxt_display_core_init(struct drm_i915_private *dev_priv, bool resume)
1462 struct i915_power_domains *power_domains = &dev_priv->display.power.domains;
1463 struct i915_power_well *well;
1465 gen9_set_dc_state(dev_priv, DC_STATE_DISABLE);
1468 * NDE_RSTWRN_OPT RST PCH Handshake En must always be 0b on BXT
1469 * or else the reset will hang because there is no PCH to respond.
1470 * Move the handshake programming to initialization sequence.
1471 * Previously was left up to BIOS.
1473 intel_pch_reset_handshake(dev_priv, false);
1475 if (!HAS_DISPLAY(dev_priv))
1479 mutex_lock(&power_domains->lock);
1481 well = lookup_power_well(dev_priv, SKL_DISP_PW_1);
1482 intel_power_well_enable(dev_priv, well);
1484 mutex_unlock(&power_domains->lock);
1486 intel_cdclk_init_hw(dev_priv);
1488 gen9_dbuf_enable(dev_priv);
1491 intel_dmc_load_program(dev_priv);
1494 static void bxt_display_core_uninit(struct drm_i915_private *dev_priv)
1496 struct i915_power_domains *power_domains = &dev_priv->display.power.domains;
1497 struct i915_power_well *well;
1499 if (!HAS_DISPLAY(dev_priv))
1502 gen9_disable_dc_states(dev_priv);
1503 /* TODO: disable DMC program */
1505 gen9_dbuf_disable(dev_priv);
1507 intel_cdclk_uninit_hw(dev_priv);
1509 /* The spec doesn't call for removing the reset handshake flag */
1512 * Disable PW1 (PG1).
1513 * Note that even though the driver's request is removed power well 1
1514 * may stay enabled after this due to DMC's own request on it.
1516 mutex_lock(&power_domains->lock);
1518 well = lookup_power_well(dev_priv, SKL_DISP_PW_1);
1519 intel_power_well_disable(dev_priv, well);
1521 mutex_unlock(&power_domains->lock);
1523 usleep_range(10, 30); /* 10 us delay per Bspec */
1526 struct buddy_page_mask {
1532 static const struct buddy_page_mask tgl_buddy_page_masks[] = {
1533 { .num_channels = 1, .type = INTEL_DRAM_DDR4, .page_mask = 0xF },
1534 { .num_channels = 1, .type = INTEL_DRAM_DDR5, .page_mask = 0xF },
1535 { .num_channels = 2, .type = INTEL_DRAM_LPDDR4, .page_mask = 0x1C },
1536 { .num_channels = 2, .type = INTEL_DRAM_LPDDR5, .page_mask = 0x1C },
1537 { .num_channels = 2, .type = INTEL_DRAM_DDR4, .page_mask = 0x1F },
1538 { .num_channels = 2, .type = INTEL_DRAM_DDR5, .page_mask = 0x1E },
1539 { .num_channels = 4, .type = INTEL_DRAM_LPDDR4, .page_mask = 0x38 },
1540 { .num_channels = 4, .type = INTEL_DRAM_LPDDR5, .page_mask = 0x38 },
1544 static const struct buddy_page_mask wa_1409767108_buddy_page_masks[] = {
1545 { .num_channels = 1, .type = INTEL_DRAM_LPDDR4, .page_mask = 0x1 },
1546 { .num_channels = 1, .type = INTEL_DRAM_DDR4, .page_mask = 0x1 },
1547 { .num_channels = 1, .type = INTEL_DRAM_DDR5, .page_mask = 0x1 },
1548 { .num_channels = 1, .type = INTEL_DRAM_LPDDR5, .page_mask = 0x1 },
1549 { .num_channels = 2, .type = INTEL_DRAM_LPDDR4, .page_mask = 0x3 },
1550 { .num_channels = 2, .type = INTEL_DRAM_DDR4, .page_mask = 0x3 },
1551 { .num_channels = 2, .type = INTEL_DRAM_DDR5, .page_mask = 0x3 },
1552 { .num_channels = 2, .type = INTEL_DRAM_LPDDR5, .page_mask = 0x3 },
1556 static void tgl_bw_buddy_init(struct drm_i915_private *dev_priv)
1558 enum intel_dram_type type = dev_priv->dram_info.type;
1559 u8 num_channels = dev_priv->dram_info.num_channels;
1560 const struct buddy_page_mask *table;
1561 unsigned long abox_mask = INTEL_INFO(dev_priv)->display.abox_mask;
1564 /* BW_BUDDY registers are not used on dgpu's beyond DG1 */
1565 if (IS_DGFX(dev_priv) && !IS_DG1(dev_priv))
1568 if (IS_ALDERLAKE_S(dev_priv) ||
1569 IS_RKL_DISPLAY_STEP(dev_priv, STEP_A0, STEP_B0))
1571 table = wa_1409767108_buddy_page_masks;
1573 table = tgl_buddy_page_masks;
1575 for (config = 0; table[config].page_mask != 0; config++)
1576 if (table[config].num_channels == num_channels &&
1577 table[config].type == type)
1580 if (table[config].page_mask == 0) {
1581 drm_dbg(&dev_priv->drm,
1582 "Unknown memory configuration; disabling address buddy logic.\n");
1583 for_each_set_bit(i, &abox_mask, sizeof(abox_mask))
1584 intel_de_write(dev_priv, BW_BUDDY_CTL(i),
1587 for_each_set_bit(i, &abox_mask, sizeof(abox_mask)) {
1588 intel_de_write(dev_priv, BW_BUDDY_PAGE_MASK(i),
1589 table[config].page_mask);
1591 /* Wa_22010178259:tgl,dg1,rkl,adl-s */
1592 if (DISPLAY_VER(dev_priv) == 12)
1593 intel_de_rmw(dev_priv, BW_BUDDY_CTL(i),
1594 BW_BUDDY_TLB_REQ_TIMER_MASK,
1595 BW_BUDDY_TLB_REQ_TIMER(0x8));
1600 static void icl_display_core_init(struct drm_i915_private *dev_priv,
1603 struct i915_power_domains *power_domains = &dev_priv->display.power.domains;
1604 struct i915_power_well *well;
1606 gen9_set_dc_state(dev_priv, DC_STATE_DISABLE);
1608 /* Wa_14011294188:ehl,jsl,tgl,rkl,adl-s */
1609 if (INTEL_PCH_TYPE(dev_priv) >= PCH_TGP &&
1610 INTEL_PCH_TYPE(dev_priv) < PCH_DG1)
1611 intel_de_rmw(dev_priv, SOUTH_DSPCLK_GATE_D, 0,
1612 PCH_DPMGUNIT_CLOCK_GATE_DISABLE);
1614 /* 1. Enable PCH reset handshake. */
1615 intel_pch_reset_handshake(dev_priv, !HAS_PCH_NOP(dev_priv));
1617 if (!HAS_DISPLAY(dev_priv))
1620 /* 2. Initialize all combo phys */
1621 intel_combo_phy_init(dev_priv);
1624 * 3. Enable Power Well 1 (PG1).
1625 * The AUX IO power wells will be enabled on demand.
1627 mutex_lock(&power_domains->lock);
1628 well = lookup_power_well(dev_priv, SKL_DISP_PW_1);
1629 intel_power_well_enable(dev_priv, well);
1630 mutex_unlock(&power_domains->lock);
1632 if (DISPLAY_VER(dev_priv) == 14)
1633 intel_de_rmw(dev_priv, DC_STATE_EN,
1634 HOLD_PHY_PG1_LATCH | HOLD_PHY_CLKREQ_PG1_LATCH, 0);
1636 /* 4. Enable CDCLK. */
1637 intel_cdclk_init_hw(dev_priv);
1639 if (DISPLAY_VER(dev_priv) >= 12)
1640 gen12_dbuf_slices_config(dev_priv);
1642 /* 5. Enable DBUF. */
1643 gen9_dbuf_enable(dev_priv);
1645 /* 6. Setup MBUS. */
1646 icl_mbus_init(dev_priv);
1648 /* 7. Program arbiter BW_BUDDY registers */
1649 if (DISPLAY_VER(dev_priv) >= 12)
1650 tgl_bw_buddy_init(dev_priv);
1652 /* 8. Ensure PHYs have completed calibration and adaptation */
1653 if (IS_DG2(dev_priv))
1654 intel_snps_phy_wait_for_calibration(dev_priv);
1657 intel_dmc_load_program(dev_priv);
1659 /* Wa_14011508470:tgl,dg1,rkl,adl-s,adl-p */
1660 if (DISPLAY_VER(dev_priv) >= 12)
1661 intel_de_rmw(dev_priv, GEN11_CHICKEN_DCPR_2, 0,
1662 DCPR_CLEAR_MEMSTAT_DIS | DCPR_SEND_RESP_IMM |
1663 DCPR_MASK_LPMODE | DCPR_MASK_MAXLATENCY_MEMUP_CLR);
1665 /* Wa_14011503030:xelpd */
1666 if (DISPLAY_VER(dev_priv) >= 13)
1667 intel_de_write(dev_priv, XELPD_DISPLAY_ERR_FATAL_MASK, ~0);
1670 static void icl_display_core_uninit(struct drm_i915_private *dev_priv)
1672 struct i915_power_domains *power_domains = &dev_priv->display.power.domains;
1673 struct i915_power_well *well;
1675 if (!HAS_DISPLAY(dev_priv))
1678 gen9_disable_dc_states(dev_priv);
1679 intel_dmc_disable_program(dev_priv);
1681 /* 1. Disable all display engine functions -> aready done */
1683 /* 2. Disable DBUF */
1684 gen9_dbuf_disable(dev_priv);
1686 /* 3. Disable CD clock */
1687 intel_cdclk_uninit_hw(dev_priv);
1689 if (DISPLAY_VER(dev_priv) == 14)
1690 intel_de_rmw(dev_priv, DC_STATE_EN, 0,
1691 HOLD_PHY_PG1_LATCH | HOLD_PHY_CLKREQ_PG1_LATCH);
1694 * 4. Disable Power Well 1 (PG1).
1695 * The AUX IO power wells are toggled on demand, so they are already
1696 * disabled at this point.
1698 mutex_lock(&power_domains->lock);
1699 well = lookup_power_well(dev_priv, SKL_DISP_PW_1);
1700 intel_power_well_disable(dev_priv, well);
1701 mutex_unlock(&power_domains->lock);
1704 intel_combo_phy_uninit(dev_priv);
1707 static void chv_phy_control_init(struct drm_i915_private *dev_priv)
1709 struct i915_power_well *cmn_bc =
1710 lookup_power_well(dev_priv, VLV_DISP_PW_DPIO_CMN_BC);
1711 struct i915_power_well *cmn_d =
1712 lookup_power_well(dev_priv, CHV_DISP_PW_DPIO_CMN_D);
1715 * DISPLAY_PHY_CONTROL can get corrupted if read. As a
1716 * workaround never ever read DISPLAY_PHY_CONTROL, and
1717 * instead maintain a shadow copy ourselves. Use the actual
1718 * power well state and lane status to reconstruct the
1719 * expected initial value.
1721 dev_priv->display.power.chv_phy_control =
1722 PHY_LDO_SEQ_DELAY(PHY_LDO_DELAY_600NS, DPIO_PHY0) |
1723 PHY_LDO_SEQ_DELAY(PHY_LDO_DELAY_600NS, DPIO_PHY1) |
1724 PHY_CH_POWER_MODE(PHY_CH_DEEP_PSR, DPIO_PHY0, DPIO_CH0) |
1725 PHY_CH_POWER_MODE(PHY_CH_DEEP_PSR, DPIO_PHY0, DPIO_CH1) |
1726 PHY_CH_POWER_MODE(PHY_CH_DEEP_PSR, DPIO_PHY1, DPIO_CH0);
1729 * If all lanes are disabled we leave the override disabled
1730 * with all power down bits cleared to match the state we
1731 * would use after disabling the port. Otherwise enable the
1732 * override and set the lane powerdown bits accding to the
1733 * current lane status.
1735 if (intel_power_well_is_enabled(dev_priv, cmn_bc)) {
1736 u32 status = intel_de_read(dev_priv, DPLL(PIPE_A));
1739 mask = status & DPLL_PORTB_READY_MASK;
1743 dev_priv->display.power.chv_phy_control |=
1744 PHY_CH_POWER_DOWN_OVRD_EN(DPIO_PHY0, DPIO_CH0);
1746 dev_priv->display.power.chv_phy_control |=
1747 PHY_CH_POWER_DOWN_OVRD(mask, DPIO_PHY0, DPIO_CH0);
1749 mask = (status & DPLL_PORTC_READY_MASK) >> 4;
1753 dev_priv->display.power.chv_phy_control |=
1754 PHY_CH_POWER_DOWN_OVRD_EN(DPIO_PHY0, DPIO_CH1);
1756 dev_priv->display.power.chv_phy_control |=
1757 PHY_CH_POWER_DOWN_OVRD(mask, DPIO_PHY0, DPIO_CH1);
1759 dev_priv->display.power.chv_phy_control |= PHY_COM_LANE_RESET_DEASSERT(DPIO_PHY0);
1761 dev_priv->display.power.chv_phy_assert[DPIO_PHY0] = false;
1763 dev_priv->display.power.chv_phy_assert[DPIO_PHY0] = true;
1766 if (intel_power_well_is_enabled(dev_priv, cmn_d)) {
1767 u32 status = intel_de_read(dev_priv, DPIO_PHY_STATUS);
1770 mask = status & DPLL_PORTD_READY_MASK;
1775 dev_priv->display.power.chv_phy_control |=
1776 PHY_CH_POWER_DOWN_OVRD_EN(DPIO_PHY1, DPIO_CH0);
1778 dev_priv->display.power.chv_phy_control |=
1779 PHY_CH_POWER_DOWN_OVRD(mask, DPIO_PHY1, DPIO_CH0);
1781 dev_priv->display.power.chv_phy_control |= PHY_COM_LANE_RESET_DEASSERT(DPIO_PHY1);
1783 dev_priv->display.power.chv_phy_assert[DPIO_PHY1] = false;
1785 dev_priv->display.power.chv_phy_assert[DPIO_PHY1] = true;
1788 drm_dbg_kms(&dev_priv->drm, "Initial PHY_CONTROL=0x%08x\n",
1789 dev_priv->display.power.chv_phy_control);
1791 /* Defer application of initial phy_control to enabling the powerwell */
1794 static void vlv_cmnlane_wa(struct drm_i915_private *dev_priv)
1796 struct i915_power_well *cmn =
1797 lookup_power_well(dev_priv, VLV_DISP_PW_DPIO_CMN_BC);
1798 struct i915_power_well *disp2d =
1799 lookup_power_well(dev_priv, VLV_DISP_PW_DISP2D);
1801 /* If the display might be already active skip this */
1802 if (intel_power_well_is_enabled(dev_priv, cmn) &&
1803 intel_power_well_is_enabled(dev_priv, disp2d) &&
1804 intel_de_read(dev_priv, DPIO_CTL) & DPIO_CMNRST)
1807 drm_dbg_kms(&dev_priv->drm, "toggling display PHY side reset\n");
1809 /* cmnlane needs DPLL registers */
1810 intel_power_well_enable(dev_priv, disp2d);
1813 * From VLV2A0_DP_eDP_HDMI_DPIO_driver_vbios_notes_11.docx:
1814 * Need to assert and de-assert PHY SB reset by gating the
1815 * common lane power, then un-gating it.
1816 * Simply ungating isn't enough to reset the PHY enough to get
1817 * ports and lanes running.
1819 intel_power_well_disable(dev_priv, cmn);
1822 static bool vlv_punit_is_power_gated(struct drm_i915_private *dev_priv, u32 reg0)
1826 vlv_punit_get(dev_priv);
1827 ret = (vlv_punit_read(dev_priv, reg0) & SSPM0_SSC_MASK) == SSPM0_SSC_PWR_GATE;
1828 vlv_punit_put(dev_priv);
1833 static void assert_ved_power_gated(struct drm_i915_private *dev_priv)
1835 drm_WARN(&dev_priv->drm,
1836 !vlv_punit_is_power_gated(dev_priv, PUNIT_REG_VEDSSPM0),
1837 "VED not power gated\n");
1840 static void assert_isp_power_gated(struct drm_i915_private *dev_priv)
1842 static const struct pci_device_id isp_ids[] = {
1843 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x0f38)},
1844 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x22b8)},
1848 drm_WARN(&dev_priv->drm, !pci_dev_present(isp_ids) &&
1849 !vlv_punit_is_power_gated(dev_priv, PUNIT_REG_ISPSSPM0),
1850 "ISP not power gated\n");
1853 static void intel_power_domains_verify_state(struct drm_i915_private *dev_priv);
1856 * intel_power_domains_init_hw - initialize hardware power domain state
1857 * @i915: i915 device instance
1858 * @resume: Called from resume code paths or not
1860 * This function initializes the hardware power domain state and enables all
1861 * power wells belonging to the INIT power domain. Power wells in other
1862 * domains (and not in the INIT domain) are referenced or disabled by
1863 * intel_modeset_readout_hw_state(). After that the reference count of each
1864 * power well must match its HW enabled state, see
1865 * intel_power_domains_verify_state().
1867 * It will return with power domains disabled (to be enabled later by
1868 * intel_power_domains_enable()) and must be paired with
1869 * intel_power_domains_driver_remove().
1871 void intel_power_domains_init_hw(struct drm_i915_private *i915, bool resume)
1873 struct i915_power_domains *power_domains = &i915->display.power.domains;
1875 power_domains->initializing = true;
1877 if (DISPLAY_VER(i915) >= 11) {
1878 icl_display_core_init(i915, resume);
1879 } else if (IS_GEMINILAKE(i915) || IS_BROXTON(i915)) {
1880 bxt_display_core_init(i915, resume);
1881 } else if (DISPLAY_VER(i915) == 9) {
1882 skl_display_core_init(i915, resume);
1883 } else if (IS_CHERRYVIEW(i915)) {
1884 mutex_lock(&power_domains->lock);
1885 chv_phy_control_init(i915);
1886 mutex_unlock(&power_domains->lock);
1887 assert_isp_power_gated(i915);
1888 } else if (IS_VALLEYVIEW(i915)) {
1889 mutex_lock(&power_domains->lock);
1890 vlv_cmnlane_wa(i915);
1891 mutex_unlock(&power_domains->lock);
1892 assert_ved_power_gated(i915);
1893 assert_isp_power_gated(i915);
1894 } else if (IS_BROADWELL(i915) || IS_HASWELL(i915)) {
1895 hsw_assert_cdclk(i915);
1896 intel_pch_reset_handshake(i915, !HAS_PCH_NOP(i915));
1897 } else if (IS_IVYBRIDGE(i915)) {
1898 intel_pch_reset_handshake(i915, !HAS_PCH_NOP(i915));
1902 * Keep all power wells enabled for any dependent HW access during
1903 * initialization and to make sure we keep BIOS enabled display HW
1904 * resources powered until display HW readout is complete. We drop
1905 * this reference in intel_power_domains_enable().
1907 drm_WARN_ON(&i915->drm, power_domains->init_wakeref);
1908 power_domains->init_wakeref =
1909 intel_display_power_get(i915, POWER_DOMAIN_INIT);
1911 /* Disable power support if the user asked so. */
1912 if (!i915->params.disable_power_well) {
1913 drm_WARN_ON(&i915->drm, power_domains->disable_wakeref);
1914 i915->display.power.domains.disable_wakeref = intel_display_power_get(i915,
1917 intel_power_domains_sync_hw(i915);
1919 power_domains->initializing = false;
1923 * intel_power_domains_driver_remove - deinitialize hw power domain state
1924 * @i915: i915 device instance
1926 * De-initializes the display power domain HW state. It also ensures that the
1927 * device stays powered up so that the driver can be reloaded.
1929 * It must be called with power domains already disabled (after a call to
1930 * intel_power_domains_disable()) and must be paired with
1931 * intel_power_domains_init_hw().
1933 void intel_power_domains_driver_remove(struct drm_i915_private *i915)
1935 intel_wakeref_t wakeref __maybe_unused =
1936 fetch_and_zero(&i915->display.power.domains.init_wakeref);
1938 /* Remove the refcount we took to keep power well support disabled. */
1939 if (!i915->params.disable_power_well)
1940 intel_display_power_put(i915, POWER_DOMAIN_INIT,
1941 fetch_and_zero(&i915->display.power.domains.disable_wakeref));
1943 intel_display_power_flush_work_sync(i915);
1945 intel_power_domains_verify_state(i915);
1947 /* Keep the power well enabled, but cancel its rpm wakeref. */
1948 intel_runtime_pm_put(&i915->runtime_pm, wakeref);
1952 * intel_power_domains_sanitize_state - sanitize power domains state
1953 * @i915: i915 device instance
1955 * Sanitize the power domains state during driver loading and system resume.
1956 * The function will disable all display power wells that BIOS has enabled
1957 * without a user for it (any user for a power well has taken a reference
1958 * on it by the time this function is called, after the state of all the
1959 * pipe, encoder, etc. HW resources have been sanitized).
1961 void intel_power_domains_sanitize_state(struct drm_i915_private *i915)
1963 struct i915_power_domains *power_domains = &i915->display.power.domains;
1964 struct i915_power_well *power_well;
1966 mutex_lock(&power_domains->lock);
1968 for_each_power_well_reverse(i915, power_well) {
1969 if (power_well->desc->always_on || power_well->count ||
1970 !intel_power_well_is_enabled(i915, power_well))
1973 drm_dbg_kms(&i915->drm,
1974 "BIOS left unused %s power well enabled, disabling it\n",
1975 intel_power_well_name(power_well));
1976 intel_power_well_disable(i915, power_well);
1979 mutex_unlock(&power_domains->lock);
1983 * intel_power_domains_enable - enable toggling of display power wells
1984 * @i915: i915 device instance
1986 * Enable the ondemand enabling/disabling of the display power wells. Note that
1987 * power wells not belonging to POWER_DOMAIN_INIT are allowed to be toggled
1988 * only at specific points of the display modeset sequence, thus they are not
1989 * affected by the intel_power_domains_enable()/disable() calls. The purpose
1990 * of these function is to keep the rest of power wells enabled until the end
1991 * of display HW readout (which will acquire the power references reflecting
1992 * the current HW state).
1994 void intel_power_domains_enable(struct drm_i915_private *i915)
1996 intel_wakeref_t wakeref __maybe_unused =
1997 fetch_and_zero(&i915->display.power.domains.init_wakeref);
1999 intel_display_power_put(i915, POWER_DOMAIN_INIT, wakeref);
2000 intel_power_domains_verify_state(i915);
2004 * intel_power_domains_disable - disable toggling of display power wells
2005 * @i915: i915 device instance
2007 * Disable the ondemand enabling/disabling of the display power wells. See
2008 * intel_power_domains_enable() for which power wells this call controls.
2010 void intel_power_domains_disable(struct drm_i915_private *i915)
2012 struct i915_power_domains *power_domains = &i915->display.power.domains;
2014 drm_WARN_ON(&i915->drm, power_domains->init_wakeref);
2015 power_domains->init_wakeref =
2016 intel_display_power_get(i915, POWER_DOMAIN_INIT);
2018 intel_power_domains_verify_state(i915);
2022 * intel_power_domains_suspend - suspend power domain state
2023 * @i915: i915 device instance
2024 * @suspend_mode: specifies the target suspend state (idle, mem, hibernation)
2026 * This function prepares the hardware power domain state before entering
2029 * It must be called with power domains already disabled (after a call to
2030 * intel_power_domains_disable()) and paired with intel_power_domains_resume().
2032 void intel_power_domains_suspend(struct drm_i915_private *i915,
2033 enum i915_drm_suspend_mode suspend_mode)
2035 struct i915_power_domains *power_domains = &i915->display.power.domains;
2036 intel_wakeref_t wakeref __maybe_unused =
2037 fetch_and_zero(&power_domains->init_wakeref);
2039 intel_display_power_put(i915, POWER_DOMAIN_INIT, wakeref);
2042 * In case of suspend-to-idle (aka S0ix) on a DMC platform without DC9
2043 * support don't manually deinit the power domains. This also means the
2044 * DMC firmware will stay active, it will power down any HW
2045 * resources as required and also enable deeper system power states
2046 * that would be blocked if the firmware was inactive.
2048 if (!(power_domains->allowed_dc_mask & DC_STATE_EN_DC9) &&
2049 suspend_mode == I915_DRM_SUSPEND_IDLE &&
2050 intel_dmc_has_payload(i915)) {
2051 intel_display_power_flush_work(i915);
2052 intel_power_domains_verify_state(i915);
2057 * Even if power well support was disabled we still want to disable
2058 * power wells if power domains must be deinitialized for suspend.
2060 if (!i915->params.disable_power_well)
2061 intel_display_power_put(i915, POWER_DOMAIN_INIT,
2062 fetch_and_zero(&i915->display.power.domains.disable_wakeref));
2064 intel_display_power_flush_work(i915);
2065 intel_power_domains_verify_state(i915);
2067 if (DISPLAY_VER(i915) >= 11)
2068 icl_display_core_uninit(i915);
2069 else if (IS_GEMINILAKE(i915) || IS_BROXTON(i915))
2070 bxt_display_core_uninit(i915);
2071 else if (DISPLAY_VER(i915) == 9)
2072 skl_display_core_uninit(i915);
2074 power_domains->display_core_suspended = true;
2078 * intel_power_domains_resume - resume power domain state
2079 * @i915: i915 device instance
2081 * This function resume the hardware power domain state during system resume.
2083 * It will return with power domain support disabled (to be enabled later by
2084 * intel_power_domains_enable()) and must be paired with
2085 * intel_power_domains_suspend().
2087 void intel_power_domains_resume(struct drm_i915_private *i915)
2089 struct i915_power_domains *power_domains = &i915->display.power.domains;
2091 if (power_domains->display_core_suspended) {
2092 intel_power_domains_init_hw(i915, true);
2093 power_domains->display_core_suspended = false;
2095 drm_WARN_ON(&i915->drm, power_domains->init_wakeref);
2096 power_domains->init_wakeref =
2097 intel_display_power_get(i915, POWER_DOMAIN_INIT);
2100 intel_power_domains_verify_state(i915);
2103 #if IS_ENABLED(CONFIG_DRM_I915_DEBUG_RUNTIME_PM)
2105 static void intel_power_domains_dump_info(struct drm_i915_private *i915)
2107 struct i915_power_domains *power_domains = &i915->display.power.domains;
2108 struct i915_power_well *power_well;
2110 for_each_power_well(i915, power_well) {
2111 enum intel_display_power_domain domain;
2113 drm_dbg(&i915->drm, "%-25s %d\n",
2114 intel_power_well_name(power_well), intel_power_well_refcount(power_well));
2116 for_each_power_domain(domain, intel_power_well_domains(power_well))
2117 drm_dbg(&i915->drm, " %-23s %d\n",
2118 intel_display_power_domain_str(domain),
2119 power_domains->domain_use_count[domain]);
2124 * intel_power_domains_verify_state - verify the HW/SW state for all power wells
2125 * @i915: i915 device instance
2127 * Verify if the reference count of each power well matches its HW enabled
2128 * state and the total refcount of the domains it belongs to. This must be
2129 * called after modeset HW state sanitization, which is responsible for
2130 * acquiring reference counts for any power wells in use and disabling the
2131 * ones left on by BIOS but not required by any active output.
2133 static void intel_power_domains_verify_state(struct drm_i915_private *i915)
2135 struct i915_power_domains *power_domains = &i915->display.power.domains;
2136 struct i915_power_well *power_well;
2137 bool dump_domain_info;
2139 mutex_lock(&power_domains->lock);
2141 verify_async_put_domains_state(power_domains);
2143 dump_domain_info = false;
2144 for_each_power_well(i915, power_well) {
2145 enum intel_display_power_domain domain;
2149 enabled = intel_power_well_is_enabled(i915, power_well);
2150 if ((intel_power_well_refcount(power_well) ||
2151 intel_power_well_is_always_on(power_well)) !=
2154 "power well %s state mismatch (refcount %d/enabled %d)",
2155 intel_power_well_name(power_well),
2156 intel_power_well_refcount(power_well), enabled);
2159 for_each_power_domain(domain, intel_power_well_domains(power_well))
2160 domains_count += power_domains->domain_use_count[domain];
2162 if (intel_power_well_refcount(power_well) != domains_count) {
2164 "power well %s refcount/domain refcount mismatch "
2165 "(refcount %d/domains refcount %d)\n",
2166 intel_power_well_name(power_well),
2167 intel_power_well_refcount(power_well),
2169 dump_domain_info = true;
2173 if (dump_domain_info) {
2177 intel_power_domains_dump_info(i915);
2182 mutex_unlock(&power_domains->lock);
2187 static void intel_power_domains_verify_state(struct drm_i915_private *i915)
2193 void intel_display_power_suspend_late(struct drm_i915_private *i915)
2195 if (DISPLAY_VER(i915) >= 11 || IS_GEMINILAKE(i915) ||
2197 bxt_enable_dc9(i915);
2198 } else if (IS_HASWELL(i915) || IS_BROADWELL(i915)) {
2199 hsw_enable_pc8(i915);
2202 /* Tweaked Wa_14010685332:cnp,icp,jsp,mcc,tgp,adp */
2203 if (INTEL_PCH_TYPE(i915) >= PCH_CNP && INTEL_PCH_TYPE(i915) < PCH_DG1)
2204 intel_de_rmw(i915, SOUTH_CHICKEN1, SBCLK_RUN_REFCLK_DIS, SBCLK_RUN_REFCLK_DIS);
2207 void intel_display_power_resume_early(struct drm_i915_private *i915)
2209 if (DISPLAY_VER(i915) >= 11 || IS_GEMINILAKE(i915) ||
2211 gen9_sanitize_dc_state(i915);
2212 bxt_disable_dc9(i915);
2213 } else if (IS_HASWELL(i915) || IS_BROADWELL(i915)) {
2214 hsw_disable_pc8(i915);
2217 /* Tweaked Wa_14010685332:cnp,icp,jsp,mcc,tgp,adp */
2218 if (INTEL_PCH_TYPE(i915) >= PCH_CNP && INTEL_PCH_TYPE(i915) < PCH_DG1)
2219 intel_de_rmw(i915, SOUTH_CHICKEN1, SBCLK_RUN_REFCLK_DIS, 0);
2222 void intel_display_power_suspend(struct drm_i915_private *i915)
2224 if (DISPLAY_VER(i915) >= 11) {
2225 icl_display_core_uninit(i915);
2226 bxt_enable_dc9(i915);
2227 } else if (IS_GEMINILAKE(i915) || IS_BROXTON(i915)) {
2228 bxt_display_core_uninit(i915);
2229 bxt_enable_dc9(i915);
2230 } else if (IS_HASWELL(i915) || IS_BROADWELL(i915)) {
2231 hsw_enable_pc8(i915);
2235 void intel_display_power_resume(struct drm_i915_private *i915)
2237 struct i915_power_domains *power_domains = &i915->display.power.domains;
2239 if (DISPLAY_VER(i915) >= 11) {
2240 bxt_disable_dc9(i915);
2241 icl_display_core_init(i915, true);
2242 if (intel_dmc_has_payload(i915)) {
2243 if (power_domains->allowed_dc_mask & DC_STATE_EN_UPTO_DC6)
2244 skl_enable_dc6(i915);
2245 else if (power_domains->allowed_dc_mask & DC_STATE_EN_UPTO_DC5)
2246 gen9_enable_dc5(i915);
2248 } else if (IS_GEMINILAKE(i915) || IS_BROXTON(i915)) {
2249 bxt_disable_dc9(i915);
2250 bxt_display_core_init(i915, true);
2251 if (intel_dmc_has_payload(i915) &&
2252 (power_domains->allowed_dc_mask & DC_STATE_EN_UPTO_DC5))
2253 gen9_enable_dc5(i915);
2254 } else if (IS_HASWELL(i915) || IS_BROADWELL(i915)) {
2255 hsw_disable_pc8(i915);
2259 void intel_display_power_debug(struct drm_i915_private *i915, struct seq_file *m)
2261 struct i915_power_domains *power_domains = &i915->display.power.domains;
2264 mutex_lock(&power_domains->lock);
2266 seq_printf(m, "%-25s %s\n", "Power well/domain", "Use count");
2267 for (i = 0; i < power_domains->power_well_count; i++) {
2268 struct i915_power_well *power_well;
2269 enum intel_display_power_domain power_domain;
2271 power_well = &power_domains->power_wells[i];
2272 seq_printf(m, "%-25s %d\n", intel_power_well_name(power_well),
2273 intel_power_well_refcount(power_well));
2275 for_each_power_domain(power_domain, intel_power_well_domains(power_well))
2276 seq_printf(m, " %-23s %d\n",
2277 intel_display_power_domain_str(power_domain),
2278 power_domains->domain_use_count[power_domain]);
2281 mutex_unlock(&power_domains->lock);
2284 struct intel_ddi_port_domains {
2285 enum port port_start;
2287 enum aux_ch aux_ch_start;
2288 enum aux_ch aux_ch_end;
2290 enum intel_display_power_domain ddi_lanes;
2291 enum intel_display_power_domain ddi_io;
2292 enum intel_display_power_domain aux_io;
2293 enum intel_display_power_domain aux_legacy_usbc;
2294 enum intel_display_power_domain aux_tbt;
2297 static const struct intel_ddi_port_domains
2298 i9xx_port_domains[] = {
2300 .port_start = PORT_A,
2302 .aux_ch_start = AUX_CH_A,
2303 .aux_ch_end = AUX_CH_F,
2305 .ddi_lanes = POWER_DOMAIN_PORT_DDI_LANES_A,
2306 .ddi_io = POWER_DOMAIN_PORT_DDI_IO_A,
2307 .aux_io = POWER_DOMAIN_AUX_IO_A,
2308 .aux_legacy_usbc = POWER_DOMAIN_AUX_A,
2309 .aux_tbt = POWER_DOMAIN_INVALID,
2313 static const struct intel_ddi_port_domains
2314 d11_port_domains[] = {
2316 .port_start = PORT_A,
2318 .aux_ch_start = AUX_CH_A,
2319 .aux_ch_end = AUX_CH_B,
2321 .ddi_lanes = POWER_DOMAIN_PORT_DDI_LANES_A,
2322 .ddi_io = POWER_DOMAIN_PORT_DDI_IO_A,
2323 .aux_io = POWER_DOMAIN_AUX_IO_A,
2324 .aux_legacy_usbc = POWER_DOMAIN_AUX_A,
2325 .aux_tbt = POWER_DOMAIN_INVALID,
2327 .port_start = PORT_C,
2329 .aux_ch_start = AUX_CH_C,
2330 .aux_ch_end = AUX_CH_F,
2332 .ddi_lanes = POWER_DOMAIN_PORT_DDI_LANES_C,
2333 .ddi_io = POWER_DOMAIN_PORT_DDI_IO_C,
2334 .aux_io = POWER_DOMAIN_AUX_IO_C,
2335 .aux_legacy_usbc = POWER_DOMAIN_AUX_C,
2336 .aux_tbt = POWER_DOMAIN_AUX_TBT1,
2340 static const struct intel_ddi_port_domains
2341 d12_port_domains[] = {
2343 .port_start = PORT_A,
2345 .aux_ch_start = AUX_CH_A,
2346 .aux_ch_end = AUX_CH_C,
2348 .ddi_lanes = POWER_DOMAIN_PORT_DDI_LANES_A,
2349 .ddi_io = POWER_DOMAIN_PORT_DDI_IO_A,
2350 .aux_io = POWER_DOMAIN_AUX_IO_A,
2351 .aux_legacy_usbc = POWER_DOMAIN_AUX_A,
2352 .aux_tbt = POWER_DOMAIN_INVALID,
2354 .port_start = PORT_TC1,
2355 .port_end = PORT_TC6,
2356 .aux_ch_start = AUX_CH_USBC1,
2357 .aux_ch_end = AUX_CH_USBC6,
2359 .ddi_lanes = POWER_DOMAIN_PORT_DDI_LANES_TC1,
2360 .ddi_io = POWER_DOMAIN_PORT_DDI_IO_TC1,
2361 .aux_io = POWER_DOMAIN_INVALID,
2362 .aux_legacy_usbc = POWER_DOMAIN_AUX_USBC1,
2363 .aux_tbt = POWER_DOMAIN_AUX_TBT1,
2367 static const struct intel_ddi_port_domains
2368 d13_port_domains[] = {
2370 .port_start = PORT_A,
2372 .aux_ch_start = AUX_CH_A,
2373 .aux_ch_end = AUX_CH_C,
2375 .ddi_lanes = POWER_DOMAIN_PORT_DDI_LANES_A,
2376 .ddi_io = POWER_DOMAIN_PORT_DDI_IO_A,
2377 .aux_io = POWER_DOMAIN_AUX_IO_A,
2378 .aux_legacy_usbc = POWER_DOMAIN_AUX_A,
2379 .aux_tbt = POWER_DOMAIN_INVALID,
2381 .port_start = PORT_TC1,
2382 .port_end = PORT_TC4,
2383 .aux_ch_start = AUX_CH_USBC1,
2384 .aux_ch_end = AUX_CH_USBC4,
2386 .ddi_lanes = POWER_DOMAIN_PORT_DDI_LANES_TC1,
2387 .ddi_io = POWER_DOMAIN_PORT_DDI_IO_TC1,
2388 .aux_io = POWER_DOMAIN_INVALID,
2389 .aux_legacy_usbc = POWER_DOMAIN_AUX_USBC1,
2390 .aux_tbt = POWER_DOMAIN_AUX_TBT1,
2392 .port_start = PORT_D_XELPD,
2393 .port_end = PORT_E_XELPD,
2394 .aux_ch_start = AUX_CH_D_XELPD,
2395 .aux_ch_end = AUX_CH_E_XELPD,
2397 .ddi_lanes = POWER_DOMAIN_PORT_DDI_LANES_D,
2398 .ddi_io = POWER_DOMAIN_PORT_DDI_IO_D,
2399 .aux_io = POWER_DOMAIN_AUX_IO_D,
2400 .aux_legacy_usbc = POWER_DOMAIN_AUX_D,
2401 .aux_tbt = POWER_DOMAIN_INVALID,
2406 intel_port_domains_for_platform(struct drm_i915_private *i915,
2407 const struct intel_ddi_port_domains **domains,
2410 if (DISPLAY_VER(i915) >= 13) {
2411 *domains = d13_port_domains;
2412 *domains_size = ARRAY_SIZE(d13_port_domains);
2413 } else if (DISPLAY_VER(i915) >= 12) {
2414 *domains = d12_port_domains;
2415 *domains_size = ARRAY_SIZE(d12_port_domains);
2416 } else if (DISPLAY_VER(i915) >= 11) {
2417 *domains = d11_port_domains;
2418 *domains_size = ARRAY_SIZE(d11_port_domains);
2420 *domains = i9xx_port_domains;
2421 *domains_size = ARRAY_SIZE(i9xx_port_domains);
2425 static const struct intel_ddi_port_domains *
2426 intel_port_domains_for_port(struct drm_i915_private *i915, enum port port)
2428 const struct intel_ddi_port_domains *domains;
2432 intel_port_domains_for_platform(i915, &domains, &domains_size);
2433 for (i = 0; i < domains_size; i++)
2434 if (port >= domains[i].port_start && port <= domains[i].port_end)
2440 enum intel_display_power_domain
2441 intel_display_power_ddi_io_domain(struct drm_i915_private *i915, enum port port)
2443 const struct intel_ddi_port_domains *domains = intel_port_domains_for_port(i915, port);
2445 if (drm_WARN_ON(&i915->drm, !domains || domains->ddi_io == POWER_DOMAIN_INVALID))
2446 return POWER_DOMAIN_PORT_DDI_IO_A;
2448 return domains->ddi_io + (int)(port - domains->port_start);
2451 enum intel_display_power_domain
2452 intel_display_power_ddi_lanes_domain(struct drm_i915_private *i915, enum port port)
2454 const struct intel_ddi_port_domains *domains = intel_port_domains_for_port(i915, port);
2456 if (drm_WARN_ON(&i915->drm, !domains || domains->ddi_lanes == POWER_DOMAIN_INVALID))
2457 return POWER_DOMAIN_PORT_DDI_LANES_A;
2459 return domains->ddi_lanes + (int)(port - domains->port_start);
2462 static const struct intel_ddi_port_domains *
2463 intel_port_domains_for_aux_ch(struct drm_i915_private *i915, enum aux_ch aux_ch)
2465 const struct intel_ddi_port_domains *domains;
2469 intel_port_domains_for_platform(i915, &domains, &domains_size);
2470 for (i = 0; i < domains_size; i++)
2471 if (aux_ch >= domains[i].aux_ch_start && aux_ch <= domains[i].aux_ch_end)
2477 enum intel_display_power_domain
2478 intel_display_power_aux_io_domain(struct drm_i915_private *i915, enum aux_ch aux_ch)
2480 const struct intel_ddi_port_domains *domains = intel_port_domains_for_aux_ch(i915, aux_ch);
2482 if (drm_WARN_ON(&i915->drm, !domains || domains->aux_io == POWER_DOMAIN_INVALID))
2483 return POWER_DOMAIN_AUX_IO_A;
2485 return domains->aux_io + (int)(aux_ch - domains->aux_ch_start);
2488 enum intel_display_power_domain
2489 intel_display_power_legacy_aux_domain(struct drm_i915_private *i915, enum aux_ch aux_ch)
2491 const struct intel_ddi_port_domains *domains = intel_port_domains_for_aux_ch(i915, aux_ch);
2493 if (drm_WARN_ON(&i915->drm, !domains || domains->aux_legacy_usbc == POWER_DOMAIN_INVALID))
2494 return POWER_DOMAIN_AUX_A;
2496 return domains->aux_legacy_usbc + (int)(aux_ch - domains->aux_ch_start);
2499 enum intel_display_power_domain
2500 intel_display_power_tbt_aux_domain(struct drm_i915_private *i915, enum aux_ch aux_ch)
2502 const struct intel_ddi_port_domains *domains = intel_port_domains_for_aux_ch(i915, aux_ch);
2504 if (drm_WARN_ON(&i915->drm, !domains || domains->aux_tbt == POWER_DOMAIN_INVALID))
2505 return POWER_DOMAIN_AUX_TBT1;
2507 return domains->aux_tbt + (int)(aux_ch - domains->aux_ch_start);