Skip to content

Commit 040d0dd

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 4bdb6aa commit 040d0dd

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
@@ -281,6 +281,10 @@ EXPORT_SYMBOL(__drm_atomic_state_free);
281281
* needed. It will also grab the relevant CRTC lock to make sure that the state
282282
* is consistent.
283283
*
284+
* This function is deprecated,
285+
* @drm_atomic_get_old_or_current_crtc_state or
286+
* @drm_atomic_get_new_or_current_crtc_state should be used instead.
287+
*
284288
* Returns:
285289
*
286290
* Either the allocated state or the error code encoded into the pointer. When
@@ -321,6 +325,106 @@ drm_atomic_get_crtc_state(struct drm_atomic_state *state,
321325
}
322326
EXPORT_SYMBOL(drm_atomic_get_crtc_state);
323327

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

‎include/drm/drm_atomic.h‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,13 @@ void drm_atomic_state_default_release(struct drm_atomic_state *state);
445445
struct drm_crtc_state * __must_check
446446
drm_atomic_get_crtc_state(struct drm_atomic_state *state,
447447
struct drm_crtc *crtc);
448+
struct drm_crtc_state * __must_check
449+
drm_atomic_get_new_or_current_crtc_state(struct drm_atomic_state *state,
450+
struct drm_crtc *crtc);
451+
struct drm_crtc_state * __must_check
452+
drm_atomic_get_old_or_current_crtc_state(struct drm_atomic_state *state,
453+
struct drm_crtc *crtc);
454+
448455
struct drm_plane_state * __must_check
449456
drm_atomic_get_plane_state(struct drm_atomic_state *state,
450457
struct drm_plane *plane);

0 commit comments

Comments
 (0)