1 // SPDX-License-Identifier: MIT
2 /*
3 * Copyright © 2023 Intel Corporation
4 */
5
6 #include <drm/drm_modeset_lock.h>
7
8 #include "intel_display_types.h"
9 #include "intel_modeset_lock.h"
10
_intel_modeset_lock_begin(struct drm_modeset_acquire_ctx * ctx,struct intel_atomic_state * state,unsigned int flags,int * ret)11 void _intel_modeset_lock_begin(struct drm_modeset_acquire_ctx *ctx,
12 struct intel_atomic_state *state,
13 unsigned int flags, int *ret)
14 {
15 drm_modeset_acquire_init(ctx, flags);
16
17 if (state)
18 state->base.acquire_ctx = ctx;
19
20 *ret = -EDEADLK;
21 }
22
_intel_modeset_lock_loop(int * ret)23 bool _intel_modeset_lock_loop(int *ret)
24 {
25 if (*ret == -EDEADLK) {
26 *ret = 0;
27 return true;
28 }
29
30 return false;
31 }
32
_intel_modeset_lock_end(struct drm_modeset_acquire_ctx * ctx,struct intel_atomic_state * state,int * ret)33 void _intel_modeset_lock_end(struct drm_modeset_acquire_ctx *ctx,
34 struct intel_atomic_state *state,
35 int *ret)
36 {
37 if (*ret == -EDEADLK) {
38 if (state)
39 drm_atomic_state_clear(&state->base);
40
41 *ret = drm_modeset_backoff(ctx);
42 if (*ret == 0) {
43 *ret = -EDEADLK;
44 return;
45 }
46 }
47
48 drm_modeset_drop_locks(ctx);
49 drm_modeset_acquire_fini(ctx);
50 }
51