Skip to content

Commit d83af04

Browse files
committed
drm/apple: Relax locking for back light updates
Locking all modeset locks was the obviously correct solution and the overlocking wasn't much of an issue when only a single CRTC/display output was supported. Now with more output the over locking is becomming an issue and I even ran into a deadlock. Ideally the backlight related data either should live in a private object or in sub-classed CRTC state. In practice just locking the CRTC for the internal display with backlight should be good enough. Signed-off-by: Janne Grunau <j@jannau.net>
1 parent f82c6c1 commit d83af04

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

drivers/gpu/drm/apple/dcp_backlight.c

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,14 @@ static int drm_crtc_set_brightness(struct apple_dcp *dcp)
144144
struct drm_crtc *crtc = &dcp->crtc->base;
145145
int ret = 0;
146146

147-
DRM_MODESET_LOCK_ALL_BEGIN(crtc->dev, ctx, 0, ret);
147+
drm_modeset_acquire_init(&ctx, DRM_MODESET_ACQUIRE_INTERRUPTIBLE);
148+
ret = drm_modeset_lock(&crtc->mutex, &ctx);
149+
if (ret == -EDEADLK) {
150+
drm_modeset_backoff(&ctx);
151+
return -EDEADLK;
152+
} else if (ret == -ERESTARTSYS) {
153+
return -ERESTARTSYS;
154+
}
148155

149156
if (!dcp->brightness.update)
150157
goto done;
@@ -169,7 +176,7 @@ static int drm_crtc_set_brightness(struct apple_dcp *dcp)
169176
fail:
170177
drm_atomic_state_put(state);
171178
done:
172-
DRM_MODESET_LOCK_ALL_END(crtc->dev, ctx, ret);
179+
drm_modeset_drop_locks(&ctx);
173180

174181
return ret;
175182
}
@@ -199,12 +206,19 @@ static int dcp_set_brightness(struct backlight_device *bd)
199206
struct drm_modeset_acquire_ctx ctx;
200207
int brightness = backlight_get_brightness(bd);
201208

202-
DRM_MODESET_LOCK_ALL_BEGIN(dcp->crtc->base.dev, ctx, 0, ret);
209+
drm_modeset_acquire_init(&ctx, DRM_MODESET_ACQUIRE_INTERRUPTIBLE);
210+
ret = drm_modeset_lock(&dcp->crtc->base.mutex, &ctx);
211+
if (ret == -EDEADLK) {
212+
drm_modeset_backoff(&ctx);
213+
return -EDEADLK;
214+
} else if (ret == -ERESTARTSYS) {
215+
return -ERESTARTSYS;
216+
}
203217

204218
dcp->brightness.dac = calculate_dac(dcp, brightness);
205219
dcp->brightness.update = true;
206220

207-
DRM_MODESET_LOCK_ALL_END(dcp->crtc->base.dev, ctx, ret);
221+
drm_modeset_drop_locks(&ctx);
208222

209223
return dcp_backlight_update(dcp);
210224
}

0 commit comments

Comments
 (0)