drm/imagination: Implement power management
Subsystems (3)
PATCH v4 9/17 drm/imagination: Implement power management
Add power management to the driver, using runtime pm. The power off sequence depends on firmware commands which are not implemented in this patch.
Changes since v3:
- Don't power device when calling pvr_device_gpu_fini()
- Documentation for pvr_dev->lost has been improved
- pvr_power_init() renamed to pvr_watchdog_init()
- Use drm_dev_{enter,exit}
Changes since v2:
- Use runtime PM
- Implement watchdog
Signed-off-by Sarah Walker <[email protected]>
--- drivers/gpu/drm/imagination/Makefile | 1 + drivers/gpu/drm/imagination/pvr_device.c | 27 ++- drivers/gpu/drm/imagination/pvr_device.h | 22 ++ drivers/gpu/drm/imagination/pvr_drv.c | 19 +- drivers/gpu/drm/imagination/pvr_power.c | 271 +++++++++++++++++++++++ drivers/gpu/drm/imagination/pvr_power.h | 39 ++++ 6 files changed, 376 insertions(+), 3 deletions(-) create mode 100644 drivers/gpu/drm/imagination/pvr_power.c create mode 100644 drivers/gpu/drm/imagination/pvr_power.h
drivers/gpu/drm/imagination/Makefile +1 -0
@@ -9,6 +9,7 @@ powervr-y := \ pvr_drv.o \ pvr_gem.o \ pvr_mmu.o \ + pvr_power.o \ pvr_vm.o obj-$(CONFIG_DRM_POWERVR) += powervr.o
drivers/gpu/drm/imagination/pvr_device.c +25 -2
@@ -5,6 +5,7 @@#include "pvr_device_info.h" #include "pvr_fw.h" +#include "pvr_power.h" #include "pvr_rogue_cr_defs.h" #include "pvr_vm.h"
@@ -361,6 +362,8 @@ pvr_device_gpu_fini(struct pvr_device *pvr_dev)int pvr_device_init (struct pvr_device *pvr_dev) { +struct drm_device *drm_dev =from_pvr_device (pvr_dev); +struct device *dev = drm_dev->dev;int err;/* Enable and initialize clocks required for the device to operate. */
@@ -368,13 +371,29 @@ pvr_device_init(struct pvr_device *pvr_dev)if (err)return err; +/* Explicitly power the GPU so we can access control registers before the FW is booted. */ + err =pm_runtime_resume_and_get (dev); +if (err) +return err; +/* Map the control registers into memory. */ err =pvr_device_reg_init (pvr_dev);if (err) -return err; + goto err_pm_runtime_put;/* Perform GPU-specific initialization steps. */ -return pvr_device_gpu_init (pvr_dev); + err =pvr_device_gpu_init (pvr_dev); +if (err) + goto err_pm_runtime_put; + +pm_runtime_put (dev); + +return 0 ; + +err_pm_runtime_put: +pm_runtime_put_sync_suspend (dev); + +return err; }/**
@@ -384,11 +403,15 @@ pvr_device_init(struct pvr_device *pvr_dev)void pvr_device_fini (struct pvr_device *pvr_dev) { +struct drm_device *drm_dev =from_pvr_device (pvr_dev); +struct device *dev = drm_dev->dev; +/* * Deinitialization stages are performed in reverse order compared to * the initialization stages in pvr_device_init(). */ pvr_device_gpu_fini (pvr_dev); +pm_runtime_suspend (dev); }bool
drivers/gpu/drm/imagination/pvr_device.h +22 -0
@@ -135,6 +135,28 @@ struct pvr_device {/** @fw_dev: Firmware related data. */ struct pvr_fw_device fw_dev; + +struct { +/** @work: Work item for watchdog callback. */ +struct delayed_work work; + +/** @old_kccb_cmds_executed: KCCB command execution count at last watchdog poll. */ +u32 old_kccb_cmds_executed; + +/** @kccb_stall_count: Number of watchdog polls KCCB has been stalled for. */ +u32 kccb_stall_count; + } watchdog; + +/** +* @lost: %true if the device has been lost. +* +* This variable is set if the device has become irretrievably unavailable, e.g. if the +* firmware processor has stopped responding and can not be revived via a hard reset. +*/ +bool lost; + +/** @sched_wq: Workqueue for schedulers. */ +struct workqueue_struct *sched_wq; };/**
drivers/gpu/drm/imagination/pvr_drv.c +18 -1
@@ -4,6 +4,7 @@#include "pvr_device.h" #include "pvr_drv.h" #include "pvr_gem.h" +#include "pvr_power.h" #include "pvr_rogue_defs.h" #include "pvr_rogue_fwif_client.h" #include "pvr_rogue_fwif_shared.h"
@@ -1291,9 +1292,16 @@ pvr_probe(struct platform_device *plat_dev)platform_set_drvdata (plat_dev, drm_dev); +devm_pm_runtime_enable (&plat_dev->dev); +pm_runtime_mark_last_busy (&plat_dev->dev); + +pm_runtime_set_autosuspend_delay (&plat_dev->dev,50 ); +pm_runtime_use_autosuspend (&plat_dev->dev); +pvr_watchdog_init (pvr_dev); + err =pvr_device_init (pvr_dev);if (err) -return err; + goto err_watchdog_fini; err =drm_dev_register (drm_dev,0 );if (err)
@@ -1304,6 +1312,9 @@ pvr_probe(struct platform_device *plat_dev) err_device_fini:pvr_device_fini (pvr_dev); +err_watchdog_fini: +pvr_watchdog_fini (pvr_dev); +return err; }
@@ -1315,6 +1326,7 @@ pvr_remove(struct platform_device *plat_dev)drm_dev_unplug (drm_dev);pvr_device_fini (pvr_dev); +pvr_watchdog_fini (pvr_dev);return 0 ; }
@@ -1325,11 +1337,16 @@ static const struct of_device_id dt_match[] = { };MODULE_DEVICE_TABLE (of, dt_match); +static const struct dev_pm_ops pvr_pm_ops = { +SET_RUNTIME_PM_OPS (pvr_power_device_suspend, pvr_power_device_resume, pvr_power_device_idle) +}; +static struct platform_driver pvr_driver = { .probe = pvr_probe, .remove = pvr_remove, .driver = { .name =PVR_DRIVER_NAME , + .pm = &pvr_pm_ops, .of_match_table = dt_match, }, };
drivers/gpu/drm/imagination/pvr_power.c new file +271 -0
271 lines not on this page · raw message
drivers/gpu/drm/imagination/pvr_power.h new file +39 -0
@@ -0,0 +1,39 @@ +/* SPDX-License-Identifier: GPL-2.0 OR MIT */ +/* Copyright (c) 2022 Imagination Technologies Ltd. */ + +#ifndef PVR_POWER_H +#define PVR_POWER_H + +#include "pvr_device.h" + +#include <linux/mutex.h> +#include <linux/pm_runtime.h> + +int pvr_watchdog_init (struct pvr_device *pvr_dev); +void pvr_watchdog_fini (struct pvr_device *pvr_dev); + +bool pvr_power_is_idle (struct pvr_device *pvr_dev); + +int pvr_power_device_suspend (struct device *dev); +int pvr_power_device_resume (struct device *dev); +int pvr_power_device_idle (struct device *dev); + +int pvr_power_reset (struct pvr_device *pvr_dev,bool hard_reset); + +static __always_inline int +pvr_power_get (struct pvr_device *pvr_dev) +{ +struct drm_device *drm_dev =from_pvr_device (pvr_dev); + +return pm_runtime_resume_and_get (drm_dev->dev); +} + +static __always_inline int +pvr_power_put (struct pvr_device *pvr_dev) +{ +struct drm_device *drm_dev =from_pvr_device (pvr_dev); + +return pm_runtime_put (drm_dev->dev); +} + +#endif /* PVR_POWER_H */
Signature · 1 line
2.41.0
Quoted 7 lines · Sarah Walker
Add power management to the driver, using runtime pm. The power off sequence depends on firmware commands which are not implemented in this patch.
Changes since v3:
[ ... ]
Reviewed-by Maxime Ripard <[email protected]>
Thanks!
Maxime