Skip to content

Commit 07d8057

Browse files
ickleideak
authored andcommitted
drm/i915: Introduce intel_runtime_pm_disable to pair intel_runtime_pm_enable
Currently, we cancel the extra wakeref we have for !runtime-pm devices inside power_wells_fini_hw. However, this is not strictly paired with the acquisition of that wakeref in runtime_pm_enable (as the fini_hw may be called on errors paths before we even call runtime_pm_enable). Make the symmetry more explicit and include a check that we do release all of our rpm wakerefs. v2: Fixup transfer of ownership back to core whilst keeping our wakeref count balanced. Signed-off-by: Chris Wilson <[email protected]> Cc: Imre Deak <[email protected]> Reviewed-by: Imre Deak <[email protected]> Signed-off-by: Imre Deak <[email protected]> Link: https://patchwork.freedesktop.org/patch/msgid/[email protected]
1 parent a4417b7 commit 07d8057

File tree

3 files changed

+37
-28
lines changed

3 files changed

+37
-28
lines changed

drivers/gpu/drm/i915/i915_drv.c

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1281,6 +1281,8 @@ static void i915_driver_register(struct drm_i915_private *dev_priv)
12811281
*/
12821282
if (INTEL_INFO(dev_priv)->num_pipes)
12831283
drm_kms_helper_poll_init(dev);
1284+
1285+
intel_runtime_pm_enable(dev_priv);
12841286
}
12851287

12861288
/**
@@ -1289,6 +1291,8 @@ static void i915_driver_register(struct drm_i915_private *dev_priv)
12891291
*/
12901292
static void i915_driver_unregister(struct drm_i915_private *dev_priv)
12911293
{
1294+
intel_runtime_pm_disable(dev_priv);
1295+
12921296
intel_fbdev_unregister(dev_priv);
12931297
intel_audio_deinit(dev_priv);
12941298

@@ -1366,16 +1370,6 @@ int i915_driver_load(struct pci_dev *pdev, const struct pci_device_id *ent)
13661370
goto out_fini;
13671371

13681372
pci_set_drvdata(pdev, &dev_priv->drm);
1369-
/*
1370-
* Disable the system suspend direct complete optimization, which can
1371-
* leave the device suspended skipping the driver's suspend handlers
1372-
* if the device was already runtime suspended. This is needed due to
1373-
* the difference in our runtime and system suspend sequence and
1374-
* becaue the HDA driver may require us to enable the audio power
1375-
* domain during system suspend.
1376-
*/
1377-
dev_pm_set_driver_flags(&pdev->dev, DPM_FLAG_NEVER_SKIP);
1378-
13791373
ret = i915_driver_init_early(dev_priv, ent);
13801374
if (ret < 0)
13811375
goto out_pci_disable;
@@ -1408,8 +1402,6 @@ int i915_driver_load(struct pci_dev *pdev, const struct pci_device_id *ent)
14081402

14091403
i915_driver_register(dev_priv);
14101404

1411-
intel_runtime_pm_enable(dev_priv);
1412-
14131405
intel_init_ipc(dev_priv);
14141406

14151407
intel_runtime_pm_put(dev_priv);
@@ -1441,13 +1433,13 @@ void i915_driver_unload(struct drm_device *dev)
14411433
struct drm_i915_private *dev_priv = to_i915(dev);
14421434
struct pci_dev *pdev = dev_priv->drm.pdev;
14431435

1436+
intel_display_power_get(dev_priv, POWER_DOMAIN_INIT);
1437+
14441438
i915_driver_unregister(dev_priv);
14451439

14461440
if (i915_gem_suspend(dev_priv))
14471441
DRM_ERROR("failed to idle hardware; continuing to unload!\n");
14481442

1449-
intel_display_power_get(dev_priv, POWER_DOMAIN_INIT);
1450-
14511443
drm_atomic_helper_shutdown(dev);
14521444

14531445
intel_gvt_cleanup(dev_priv);
@@ -1474,6 +1466,7 @@ void i915_driver_unload(struct drm_device *dev)
14741466
i915_driver_cleanup_mmio(dev_priv);
14751467

14761468
intel_display_power_put(dev_priv, POWER_DOMAIN_INIT);
1469+
WARN_ON(atomic_read(&dev_priv->runtime_pm.wakeref_count));
14771470
}
14781471

14791472
static void i915_driver_release(struct drm_device *dev)

drivers/gpu/drm/i915/intel_drv.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1959,6 +1959,7 @@ void intel_power_domains_verify_state(struct drm_i915_private *dev_priv);
19591959
void bxt_display_core_init(struct drm_i915_private *dev_priv, bool resume);
19601960
void bxt_display_core_uninit(struct drm_i915_private *dev_priv);
19611961
void intel_runtime_pm_enable(struct drm_i915_private *dev_priv);
1962+
void intel_runtime_pm_disable(struct drm_i915_private *dev_priv);
19621963
const char *
19631964
intel_display_power_domain_str(enum intel_display_power_domain domain);
19641965

drivers/gpu/drm/i915/intel_runtime_pm.c

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3793,29 +3793,19 @@ void intel_power_domains_init_hw(struct drm_i915_private *dev_priv, bool resume)
37933793
*/
37943794
void intel_power_domains_fini_hw(struct drm_i915_private *dev_priv)
37953795
{
3796-
struct device *kdev = &dev_priv->drm.pdev->dev;
3797-
37983796
/*
37993797
* The i915.ko module is still not prepared to be loaded when
38003798
* the power well is not enabled, so just enable it in case
38013799
* we're going to unload/reload.
3802-
* The following also reacquires the RPM reference the core passed
3803-
* to the driver during loading, which is dropped in
3804-
* intel_runtime_pm_enable(). We have to hand back the control of the
3805-
* device to the core with this reference held.
38063800
*/
3807-
intel_display_set_init_power(dev_priv, true);
3801+
intel_display_power_get(dev_priv, POWER_DOMAIN_INIT);
3802+
3803+
/* Keep the power well enabled, but cancel its rpm wakeref. */
3804+
intel_runtime_pm_put(dev_priv);
38083805

38093806
/* Remove the refcount we took to keep power well support disabled. */
38103807
if (!i915_modparams.disable_power_well)
38113808
intel_display_power_put(dev_priv, POWER_DOMAIN_INIT);
3812-
3813-
/*
3814-
* Remove the refcount we took in intel_runtime_pm_enable() in case
3815-
* the platform doesn't support runtime PM.
3816-
*/
3817-
if (!HAS_RUNTIME_PM(dev_priv))
3818-
pm_runtime_put(kdev);
38193809
}
38203810

38213811
/**
@@ -4048,6 +4038,16 @@ void intel_runtime_pm_enable(struct drm_i915_private *dev_priv)
40484038
struct pci_dev *pdev = dev_priv->drm.pdev;
40494039
struct device *kdev = &pdev->dev;
40504040

4041+
/*
4042+
* Disable the system suspend direct complete optimization, which can
4043+
* leave the device suspended skipping the driver's suspend handlers
4044+
* if the device was already runtime suspended. This is needed due to
4045+
* the difference in our runtime and system suspend sequence and
4046+
* becaue the HDA driver may require us to enable the audio power
4047+
* domain during system suspend.
4048+
*/
4049+
dev_pm_set_driver_flags(kdev, DPM_FLAG_NEVER_SKIP);
4050+
40514051
pm_runtime_set_autosuspend_delay(kdev, 10000); /* 10s */
40524052
pm_runtime_mark_last_busy(kdev);
40534053

@@ -4074,3 +4074,18 @@ void intel_runtime_pm_enable(struct drm_i915_private *dev_priv)
40744074
*/
40754075
pm_runtime_put_autosuspend(kdev);
40764076
}
4077+
4078+
void intel_runtime_pm_disable(struct drm_i915_private *dev_priv)
4079+
{
4080+
struct pci_dev *pdev = dev_priv->drm.pdev;
4081+
struct device *kdev = &pdev->dev;
4082+
4083+
/* Transfer rpm ownership back to core */
4084+
WARN(pm_runtime_get_sync(&dev_priv->drm.pdev->dev) < 0,
4085+
"Failed to pass rpm ownership back to core\n");
4086+
4087+
pm_runtime_dont_use_autosuspend(kdev);
4088+
4089+
if (!HAS_RUNTIME_PM(dev_priv))
4090+
pm_runtime_put(kdev);
4091+
}

0 commit comments

Comments
 (0)