2 * SPDX-License-Identifier: MIT
4 * Copyright © 2019 Intel Corporation
8 #include "i915_params.h"
9 #include "intel_context.h"
10 #include "intel_engine_pm.h"
12 #include "intel_gt_pm.h"
13 #include "intel_gt_requests.h"
15 #include "intel_rc6.h"
16 #include "intel_wakeref.h"
18 static void pm_notify(struct intel_gt *gt, int state)
20 blocking_notifier_call_chain(>->pm_notifications, state, gt->i915);
23 static int __gt_unpark(struct intel_wakeref *wf)
25 struct intel_gt *gt = container_of(wf, typeof(*gt), wakeref);
26 struct drm_i915_private *i915 = gt->i915;
31 * It seems that the DMC likes to transition between the DC states a lot
32 * when there are no connected displays (no active power domains) during
35 * This activity has negative impact on the performance of the chip with
36 * huge latencies observed in the interrupt handler and elsewhere.
38 * Work around it by grabbing a GT IRQ power domain whilst there is any
39 * GT activity, preventing any DC state transitions.
41 gt->awake = intel_display_power_get(i915, POWER_DOMAIN_GT_IRQ);
42 GEM_BUG_ON(!gt->awake);
44 intel_enable_gt_powersave(i915);
46 i915_update_gfx_val(i915);
47 if (INTEL_GEN(i915) >= 6)
50 i915_pmu_gt_unparked(i915);
52 intel_gt_queue_hangcheck(gt);
53 intel_gt_unpark_requests(gt);
55 pm_notify(gt, INTEL_GT_UNPARK);
60 static int __gt_park(struct intel_wakeref *wf)
62 struct intel_gt *gt = container_of(wf, typeof(*gt), wakeref);
63 intel_wakeref_t wakeref = fetch_and_zero(>->awake);
64 struct drm_i915_private *i915 = gt->i915;
68 pm_notify(gt, INTEL_GT_PARK);
69 intel_gt_park_requests(gt);
71 i915_pmu_gt_parked(i915);
72 if (INTEL_GEN(i915) >= 6)
75 /* Everything switched off, flush any residual interrupt just in case */
76 intel_synchronize_irq(i915);
79 intel_display_power_put(i915, POWER_DOMAIN_GT_IRQ, wakeref);
84 static const struct intel_wakeref_ops wf_ops = {
87 .flags = INTEL_WAKEREF_PUT_ASYNC,
90 void intel_gt_pm_init_early(struct intel_gt *gt)
92 intel_wakeref_init(>->wakeref, >->i915->runtime_pm, &wf_ops);
94 BLOCKING_INIT_NOTIFIER_HEAD(>->pm_notifications);
97 void intel_gt_pm_init(struct intel_gt *gt)
100 * Enabling power-management should be "self-healing". If we cannot
101 * enable a feature, simply leave it disabled with a notice to the
104 intel_rc6_init(>->rc6);
107 static bool reset_engines(struct intel_gt *gt)
109 if (INTEL_INFO(gt->i915)->gpu_reset_clobbers_display)
112 return __intel_gt_reset(gt, ALL_ENGINES) == 0;
116 * intel_gt_sanitize: called after the GPU has lost power
117 * @gt: the i915 GT container
118 * @force: ignore a failed reset and sanitize engine state anyway
120 * Anytime we reset the GPU, either with an explicit GPU reset or through a
121 * PCI power cycle, the GPU loses state and we must reset our state tracking
122 * to match. Note that calling intel_gt_sanitize() if the GPU has not
123 * been reset results in much confusion!
125 void intel_gt_sanitize(struct intel_gt *gt, bool force)
127 struct intel_engine_cs *engine;
128 enum intel_engine_id id;
132 intel_uc_sanitize(>->uc);
134 if (!reset_engines(gt) && !force)
137 for_each_engine(engine, gt->i915, id)
138 __intel_engine_reset(engine, false);
141 void intel_gt_pm_disable(struct intel_gt *gt)
144 intel_sanitize_gt_powersave(gt->i915);
147 void intel_gt_pm_fini(struct intel_gt *gt)
149 intel_rc6_fini(>->rc6);
152 int intel_gt_resume(struct intel_gt *gt)
154 struct intel_engine_cs *engine;
155 enum intel_engine_id id;
159 * After resume, we may need to poke into the pinned kernel
160 * contexts to paper over any damage caused by the sudden suspend.
161 * Only the kernel contexts should remain pinned over suspend,
162 * allowing us to fixup the user contexts on their first pin.
165 intel_uncore_forcewake_get(gt->uncore, FORCEWAKE_ALL);
166 intel_rc6_sanitize(>->rc6);
168 for_each_engine(engine, gt->i915, id) {
169 struct intel_context *ce;
171 intel_engine_pm_get(engine);
173 ce = engine->kernel_context;
175 GEM_BUG_ON(!intel_context_is_pinned(ce));
176 mutex_acquire(&ce->pin_mutex.dep_map, 0, 0, _THIS_IP_);
178 mutex_release(&ce->pin_mutex.dep_map, 0, _THIS_IP_);
181 engine->serial++; /* kernel context lost */
182 err = engine->resume(engine);
184 intel_engine_pm_put(engine);
186 dev_err(gt->i915->drm.dev,
187 "Failed to restart %s (%d)\n",
193 intel_rc6_enable(>->rc6);
194 intel_uncore_forcewake_put(gt->uncore, FORCEWAKE_ALL);
200 static void wait_for_idle(struct intel_gt *gt)
202 if (intel_gt_wait_for_idle(gt, I915_GEM_IDLE_TIMEOUT) == -ETIME) {
204 * Forcibly cancel outstanding work and leave
207 intel_gt_set_wedged(gt);
210 intel_gt_pm_wait_for_idle(gt);
213 void intel_gt_suspend(struct intel_gt *gt)
215 intel_wakeref_t wakeref;
217 /* We expect to be idle already; but also want to be independent */
220 with_intel_runtime_pm(>->i915->runtime_pm, wakeref)
221 intel_rc6_disable(>->rc6);
224 void intel_gt_runtime_suspend(struct intel_gt *gt)
226 intel_uc_runtime_suspend(>->uc);
229 int intel_gt_runtime_resume(struct intel_gt *gt)
231 intel_gt_init_swizzling(gt);
233 return intel_uc_runtime_resume(>->uc);
236 #if IS_ENABLED(CONFIG_DRM_I915_SELFTEST)
237 #include "selftest_gt_pm.c"