@@ -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}
326330EXPORT_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+
328432static int drm_atomic_crtc_check (const struct drm_crtc_state * old_crtc_state ,
329433 const struct drm_crtc_state * new_crtc_state )
330434{
0 commit comments