Skip to content

Commit 727538a

Browse files
sarah-walker-imgtecmripard
authored andcommitted
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 v8: - Corrected license identifiers Changes since v5: - Use RUNTIME_PM_OPS() to declare PM callbacks - Add Kconfig dependency on CONFIG_PM Changes since v4: - Suspend runtime PM before unplugging device on rmmod 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]> Signed-off-by: Donald Robson <[email protected]> Reviewed-by: Maxime Ripard <[email protected]> Link: https://lore.kernel.org/r/e09af4ef1ff514e1d6d7f97c7c5032c643c56f9c.1700668843.git.donald.robson@imgtec.com Signed-off-by: Maxime Ripard <[email protected]>
1 parent ff5f643 commit 727538a

File tree

7 files changed

+374
-3
lines changed

7 files changed

+374
-3
lines changed

drivers/gpu/drm/imagination/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ config DRM_POWERVR
55
tristate "Imagination Technologies PowerVR (Series 6 and later) & IMG Graphics"
66
depends on ARM64
77
depends on DRM
8+
depends on PM
89
select DRM_GEM_SHMEM_HELPER
910
select DRM_SCHED
1011
select DRM_GPUVM

drivers/gpu/drm/imagination/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ powervr-y := \
1010
pvr_fw.o \
1111
pvr_gem.o \
1212
pvr_mmu.o \
13+
pvr_power.o \
1314
pvr_vm.o
1415

1516
obj-$(CONFIG_DRM_POWERVR) += powervr.o

drivers/gpu/drm/imagination/pvr_device.c

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include "pvr_device_info.h"
66

77
#include "pvr_fw.h"
8+
#include "pvr_power.h"
89
#include "pvr_rogue_cr_defs.h"
910
#include "pvr_vm.h"
1011

@@ -361,20 +362,38 @@ pvr_device_gpu_fini(struct pvr_device *pvr_dev)
361362
int
362363
pvr_device_init(struct pvr_device *pvr_dev)
363364
{
365+
struct drm_device *drm_dev = from_pvr_device(pvr_dev);
366+
struct device *dev = drm_dev->dev;
364367
int err;
365368

366369
/* Enable and initialize clocks required for the device to operate. */
367370
err = pvr_device_clk_init(pvr_dev);
368371
if (err)
369372
return err;
370373

374+
/* Explicitly power the GPU so we can access control registers before the FW is booted. */
375+
err = pm_runtime_resume_and_get(dev);
376+
if (err)
377+
return err;
378+
371379
/* Map the control registers into memory. */
372380
err = pvr_device_reg_init(pvr_dev);
373381
if (err)
374-
return err;
382+
goto err_pm_runtime_put;
375383

376384
/* Perform GPU-specific initialization steps. */
377-
return pvr_device_gpu_init(pvr_dev);
385+
err = pvr_device_gpu_init(pvr_dev);
386+
if (err)
387+
goto err_pm_runtime_put;
388+
389+
pm_runtime_put(dev);
390+
391+
return 0;
392+
393+
err_pm_runtime_put:
394+
pm_runtime_put_sync_suspend(dev);
395+
396+
return err;
378397
}
379398

380399
/**

drivers/gpu/drm/imagination/pvr_device.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,28 @@ struct pvr_device {
141141
* before submitting the next job.
142142
*/
143143
atomic_t mmu_flush_cache_flags;
144+
145+
struct {
146+
/** @work: Work item for watchdog callback. */
147+
struct delayed_work work;
148+
149+
/** @old_kccb_cmds_executed: KCCB command execution count at last watchdog poll. */
150+
u32 old_kccb_cmds_executed;
151+
152+
/** @kccb_stall_count: Number of watchdog polls KCCB has been stalled for. */
153+
u32 kccb_stall_count;
154+
} watchdog;
155+
156+
/**
157+
* @lost: %true if the device has been lost.
158+
*
159+
* This variable is set if the device has become irretrievably unavailable, e.g. if the
160+
* firmware processor has stopped responding and can not be revived via a hard reset.
161+
*/
162+
bool lost;
163+
164+
/** @sched_wq: Workqueue for schedulers. */
165+
struct workqueue_struct *sched_wq;
144166
};
145167

146168
/**

drivers/gpu/drm/imagination/pvr_drv.c

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include "pvr_drv.h"
66
#include "pvr_gem.h"
77
#include "pvr_mmu.h"
8+
#include "pvr_power.h"
89
#include "pvr_rogue_defs.h"
910
#include "pvr_rogue_fwif_client.h"
1011
#include "pvr_rogue_fwif_shared.h"
@@ -1265,9 +1266,16 @@ pvr_probe(struct platform_device *plat_dev)
12651266

12661267
platform_set_drvdata(plat_dev, drm_dev);
12671268

1269+
devm_pm_runtime_enable(&plat_dev->dev);
1270+
pm_runtime_mark_last_busy(&plat_dev->dev);
1271+
1272+
pm_runtime_set_autosuspend_delay(&plat_dev->dev, 50);
1273+
pm_runtime_use_autosuspend(&plat_dev->dev);
1274+
pvr_watchdog_init(pvr_dev);
1275+
12681276
err = pvr_device_init(pvr_dev);
12691277
if (err)
1270-
return err;
1278+
goto err_watchdog_fini;
12711279

12721280
err = drm_dev_register(drm_dev, 0);
12731281
if (err)
@@ -1278,6 +1286,9 @@ pvr_probe(struct platform_device *plat_dev)
12781286
err_device_fini:
12791287
pvr_device_fini(pvr_dev);
12801288

1289+
err_watchdog_fini:
1290+
pvr_watchdog_fini(pvr_dev);
1291+
12811292
return err;
12821293
}
12831294

@@ -1287,8 +1298,10 @@ pvr_remove(struct platform_device *plat_dev)
12871298
struct drm_device *drm_dev = platform_get_drvdata(plat_dev);
12881299
struct pvr_device *pvr_dev = to_pvr_device(drm_dev);
12891300

1301+
pm_runtime_suspend(drm_dev->dev);
12901302
pvr_device_fini(pvr_dev);
12911303
drm_dev_unplug(drm_dev);
1304+
pvr_watchdog_fini(pvr_dev);
12921305

12931306
return 0;
12941307
}
@@ -1299,11 +1312,16 @@ static const struct of_device_id dt_match[] = {
12991312
};
13001313
MODULE_DEVICE_TABLE(of, dt_match);
13011314

1315+
static const struct dev_pm_ops pvr_pm_ops = {
1316+
RUNTIME_PM_OPS(pvr_power_device_suspend, pvr_power_device_resume, pvr_power_device_idle)
1317+
};
1318+
13021319
static struct platform_driver pvr_driver = {
13031320
.probe = pvr_probe,
13041321
.remove = pvr_remove,
13051322
.driver = {
13061323
.name = PVR_DRIVER_NAME,
1324+
.pm = &pvr_pm_ops,
13071325
.of_match_table = dt_match,
13081326
},
13091327
};

0 commit comments

Comments
 (0)