Skip to content

Commit 1aea1f4

Browse files
mripardpelwell
authored andcommitted
drm: Introduce new state accessors in place of drm_atomic_get_crtc_state
drm_atomic_get_crtc_state relies on drm_atomic_get_existing_crtc_state that is deprecated and isn't really clear on which state it provides. Even worse, after the states have been swapped, if the CRTC is present in the state drm_atomic_get_existing_crtc_state will return the old state, whereas if the CRTC is not present, we'll use a copy of crtc->state. crtc->state for the CRTC that is there at that point is the new state though, which leads to confusion. Let's provide two new helpers that make it clear what our expectations are. Signed-off-by: Maxime Ripard <maxime@cerno.tech>
1 parent 98583c5 commit 1aea1f4

2 files changed

Lines changed: 111 additions & 0 deletions

File tree

‎drivers/gpu/drm/drm_atomic.c‎

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,10 @@ EXPORT_SYMBOL(__drm_atomic_state_free);
285285
* drm_atomic_state.allow_modeset is set, or if it's a driver-internal commit
286286
* not created by userspace through an IOCTL call.
287287
*
288+
* This function is deprecated,
289+
* @drm_atomic_get_old_or_current_crtc_state or
290+
* @drm_atomic_get_new_or_current_crtc_state should be used instead.
291+
*
288292
* Returns:
289293
*
290294
* Either the allocated state or the error code encoded into the pointer. When
@@ -325,6 +329,106 @@ drm_atomic_get_crtc_state(struct drm_atomic_state *state,
325329
}
326330
EXPORT_SYMBOL(drm_atomic_get_crtc_state);
327331

332+
/**
333+
* drm_atomic_get_old_or_current_crtc_state - get CRTC state
334+
* @state: global atomic state object
335+
* @crtc: CRTC to get state object for
336+
*
337+
* This function returns the old CRTC state for the given CRTC if it's
338+
* part of the state, or allocating a copy of the current state
339+
* otherwise. It will also grab the relevant CRTC lock to make sure that
340+
* the state is consistent.
341+
*
342+
* Returns:
343+
*
344+
* Either the allocated state or the error code encoded into the pointer. When
345+
* the error is EDEADLK then the w/w mutex code has detected a deadlock and the
346+
* entire atomic sequence must be restarted. All other errors are fatal.
347+
*/
348+
struct drm_crtc_state *
349+
drm_atomic_get_old_or_current_crtc_state(struct drm_atomic_state *state,
350+
struct drm_crtc *crtc)
351+
{
352+
int ret, index = drm_crtc_index(crtc);
353+
struct drm_crtc_state *crtc_state;
354+
355+
WARN_ON(!state->acquire_ctx);
356+
357+
crtc_state = drm_atomic_get_old_crtc_state(state, crtc);
358+
if (crtc_state)
359+
return crtc_state;
360+
361+
ret = drm_modeset_lock(&crtc->mutex, state->acquire_ctx);
362+
if (ret)
363+
return ERR_PTR(ret);
364+
365+
crtc_state = crtc->funcs->atomic_duplicate_state(crtc);
366+
if (!crtc_state)
367+
return ERR_PTR(-ENOMEM);
368+
369+
state->crtcs[index].state = crtc_state;
370+
state->crtcs[index].old_state = crtc->state;
371+
state->crtcs[index].new_state = crtc_state;
372+
state->crtcs[index].ptr = crtc;
373+
crtc_state->state = state;
374+
375+
DRM_DEBUG_ATOMIC("Added [CRTC:%d:%s] %p state to %p\n",
376+
crtc->base.id, crtc->name, crtc_state, state);
377+
378+
return crtc_state;
379+
}
380+
EXPORT_SYMBOL(drm_atomic_get_old_or_current_crtc_state);
381+
382+
/**
383+
* drm_atomic_get_new_or_current_crtc_state - get CRTC state
384+
* @state: global atomic state object
385+
* @crtc: CRTC to get state object for
386+
*
387+
* This function returns the new CRTC state for the given CRTC if it's
388+
* part of the state, or allocating a copy of the current state
389+
* otherwise. It will also grab the relevant CRTC lock to make sure that
390+
* the state is consistent.
391+
*
392+
* Returns:
393+
*
394+
* Either the allocated state or the error code encoded into the pointer. When
395+
* the error is EDEADLK then the w/w mutex code has detected a deadlock and the
396+
* entire atomic sequence must be restarted. All other errors are fatal.
397+
*/
398+
struct drm_crtc_state *
399+
drm_atomic_get_new_or_current_crtc_state(struct drm_atomic_state *state,
400+
struct drm_crtc *crtc)
401+
{
402+
int ret, index = drm_crtc_index(crtc);
403+
struct drm_crtc_state *crtc_state;
404+
405+
WARN_ON(!state->acquire_ctx);
406+
407+
crtc_state = drm_atomic_get_new_crtc_state(state, crtc);
408+
if (crtc_state)
409+
return crtc_state;
410+
411+
ret = drm_modeset_lock(&crtc->mutex, state->acquire_ctx);
412+
if (ret)
413+
return ERR_PTR(ret);
414+
415+
crtc_state = crtc->funcs->atomic_duplicate_state(crtc);
416+
if (!crtc_state)
417+
return ERR_PTR(-ENOMEM);
418+
419+
state->crtcs[index].state = crtc_state;
420+
state->crtcs[index].old_state = crtc->state;
421+
state->crtcs[index].new_state = crtc_state;
422+
state->crtcs[index].ptr = crtc;
423+
crtc_state->state = state;
424+
425+
DRM_DEBUG_ATOMIC("Added [CRTC:%d:%s] %p state to %p\n",
426+
crtc->base.id, crtc->name, crtc_state, state);
427+
428+
return crtc_state;
429+
}
430+
EXPORT_SYMBOL(drm_atomic_get_new_or_current_crtc_state);
431+
328432
static int drm_atomic_crtc_check(const struct drm_crtc_state *old_crtc_state,
329433
const struct drm_crtc_state *new_crtc_state)
330434
{

‎include/drm/drm_atomic.h‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,13 @@ void drm_atomic_state_default_release(struct drm_atomic_state *state);
455455
struct drm_crtc_state * __must_check
456456
drm_atomic_get_crtc_state(struct drm_atomic_state *state,
457457
struct drm_crtc *crtc);
458+
struct drm_crtc_state * __must_check
459+
drm_atomic_get_new_or_current_crtc_state(struct drm_atomic_state *state,
460+
struct drm_crtc *crtc);
461+
struct drm_crtc_state * __must_check
462+
drm_atomic_get_old_or_current_crtc_state(struct drm_atomic_state *state,
463+
struct drm_crtc *crtc);
464+
458465
struct drm_plane_state * __must_check
459466
drm_atomic_get_plane_state(struct drm_atomic_state *state,
460467
struct drm_plane *plane);

0 commit comments

Comments
 (0)