Skip to content

Commit cb74f6e

Browse files
committed
drm/vc4: Add helpers for pm get/put.
This makes sure the vc4_reset doesn't hit an obscure race with the GET_PARAM ioctl, fixes a decrement outside of the lock, and prevents future code from making mistakes with the weird return value of pm_runtime_get_sync(). Signed-off-by: Eric Anholt <[email protected]> Link: https://patchwork.freedesktop.org/patch/msgid/[email protected] Reviewed-by: Paul Kocialkowski <[email protected]>
1 parent 13f0ec3 commit cb74f6e

File tree

4 files changed

+49
-28
lines changed

4 files changed

+49
-28
lines changed

drivers/gpu/drm/vc4/vc4_drv.c

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -74,28 +74,25 @@ static int vc4_get_param_ioctl(struct drm_device *dev, void *data,
7474

7575
switch (args->param) {
7676
case DRM_VC4_PARAM_V3D_IDENT0:
77-
ret = pm_runtime_get_sync(&vc4->v3d->pdev->dev);
78-
if (ret < 0)
77+
ret = vc4_v3d_pm_get(vc4);
78+
if (ret)
7979
return ret;
8080
args->value = V3D_READ(V3D_IDENT0);
81-
pm_runtime_mark_last_busy(&vc4->v3d->pdev->dev);
82-
pm_runtime_put_autosuspend(&vc4->v3d->pdev->dev);
81+
vc4_v3d_pm_put(vc4);
8382
break;
8483
case DRM_VC4_PARAM_V3D_IDENT1:
85-
ret = pm_runtime_get_sync(&vc4->v3d->pdev->dev);
86-
if (ret < 0)
84+
ret = vc4_v3d_pm_get(vc4);
85+
if (ret)
8786
return ret;
8887
args->value = V3D_READ(V3D_IDENT1);
89-
pm_runtime_mark_last_busy(&vc4->v3d->pdev->dev);
90-
pm_runtime_put_autosuspend(&vc4->v3d->pdev->dev);
88+
vc4_v3d_pm_put(vc4);
9189
break;
9290
case DRM_VC4_PARAM_V3D_IDENT2:
93-
ret = pm_runtime_get_sync(&vc4->v3d->pdev->dev);
94-
if (ret < 0)
91+
ret = vc4_v3d_pm_get(vc4);
92+
if (ret)
9593
return ret;
9694
args->value = V3D_READ(V3D_IDENT2);
97-
pm_runtime_mark_last_busy(&vc4->v3d->pdev->dev);
98-
pm_runtime_put_autosuspend(&vc4->v3d->pdev->dev);
95+
vc4_v3d_pm_put(vc4);
9996
break;
10097
case DRM_VC4_PARAM_SUPPORTS_BRANCHES:
10198
case DRM_VC4_PARAM_SUPPORTS_ETC1:

drivers/gpu/drm/vc4/vc4_drv.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -815,6 +815,8 @@ extern struct platform_driver vc4_v3d_driver;
815815
int vc4_v3d_debugfs_ident(struct seq_file *m, void *unused);
816816
int vc4_v3d_debugfs_regs(struct seq_file *m, void *unused);
817817
int vc4_v3d_get_bin_slot(struct vc4_dev *vc4);
818+
int vc4_v3d_pm_get(struct vc4_dev *vc4);
819+
void vc4_v3d_pm_put(struct vc4_dev *vc4);
818820

819821
/* vc4_validate.c */
820822
int

drivers/gpu/drm/vc4/vc4_gem.c

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -964,12 +964,7 @@ vc4_complete_exec(struct drm_device *dev, struct vc4_exec_info *exec)
964964
/* Release the reference we had on the perf monitor. */
965965
vc4_perfmon_put(exec->perfmon);
966966

967-
mutex_lock(&vc4->power_lock);
968-
if (--vc4->power_refcount == 0) {
969-
pm_runtime_mark_last_busy(&vc4->v3d->pdev->dev);
970-
pm_runtime_put_autosuspend(&vc4->v3d->pdev->dev);
971-
}
972-
mutex_unlock(&vc4->power_lock);
967+
vc4_v3d_pm_put(vc4);
973968

974969
kfree(exec);
975970
}
@@ -1143,17 +1138,11 @@ vc4_submit_cl_ioctl(struct drm_device *dev, void *data,
11431138
return -ENOMEM;
11441139
}
11451140

1146-
mutex_lock(&vc4->power_lock);
1147-
if (vc4->power_refcount++ == 0) {
1148-
ret = pm_runtime_get_sync(&vc4->v3d->pdev->dev);
1149-
if (ret < 0) {
1150-
mutex_unlock(&vc4->power_lock);
1151-
vc4->power_refcount--;
1152-
kfree(exec);
1153-
return ret;
1154-
}
1141+
ret = vc4_v3d_pm_get(vc4);
1142+
if (ret) {
1143+
kfree(exec);
1144+
return ret;
11551145
}
1156-
mutex_unlock(&vc4->power_lock);
11571146

11581147
exec->args = args;
11591148
INIT_LIST_HEAD(&exec->unref_list);

drivers/gpu/drm/vc4/vc4_v3d.c

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,39 @@ int vc4_v3d_debugfs_ident(struct seq_file *m, void *unused)
138138
}
139139
#endif /* CONFIG_DEBUG_FS */
140140

141+
/**
142+
* Wraps pm_runtime_get_sync() in a refcount, so that we can reliably
143+
* get the pm_runtime refcount to 0 in vc4_reset().
144+
*/
145+
int
146+
vc4_v3d_pm_get(struct vc4_dev *vc4)
147+
{
148+
mutex_lock(&vc4->power_lock);
149+
if (vc4->power_refcount++ == 0) {
150+
int ret = pm_runtime_get_sync(&vc4->v3d->pdev->dev);
151+
152+
if (ret < 0) {
153+
vc4->power_refcount--;
154+
mutex_unlock(&vc4->power_lock);
155+
return ret;
156+
}
157+
}
158+
mutex_unlock(&vc4->power_lock);
159+
160+
return 0;
161+
}
162+
163+
void
164+
vc4_v3d_pm_put(struct vc4_dev *vc4)
165+
{
166+
mutex_lock(&vc4->power_lock);
167+
if (--vc4->power_refcount == 0) {
168+
pm_runtime_mark_last_busy(&vc4->v3d->pdev->dev);
169+
pm_runtime_put_autosuspend(&vc4->v3d->pdev->dev);
170+
}
171+
mutex_unlock(&vc4->power_lock);
172+
}
173+
141174
static void vc4_v3d_init_hw(struct drm_device *dev)
142175
{
143176
struct vc4_dev *vc4 = to_vc4_dev(dev);

0 commit comments

Comments
 (0)