Skip to content

Commit 1b27fbd

Browse files
pinchartlatseanpaul
authored andcommitted
drm: Add drm_atomic_get_(old|new)_connector_for_encoder() helpers
Add functions to the atomic core to retrieve the old and new connectors associated with an encoder in a drm_atomic_state. This is useful for encoders and bridges that need to access the connector, for instance for the drm_display_info. The CRTC associated with the encoder can also be retrieved through the connector state, and from it, the old and new CRTC states. Changed in v4: - Added to the set Changed in v5: - Fix up docbook (Daniel & Laurent) Changed in v6: - Updated commit subject (Sam) Link to v4: https://patchwork.freedesktop.org/patch/msgid/[email protected] Link to v5: https://patchwork.freedesktop.org/patch/msgid/[email protected] Cc: Daniel Vetter <[email protected]> Cc: Sam Ravnborg <[email protected]> Tested-by: Heiko Stuebner <[email protected]> Reviewed-by: Daniel Vetter <[email protected]> Signed-off-by: Laurent Pinchart <[email protected]> [seanpaul removed WARNs from helpers and added docs to explain why returning NULL might be valid] Signed-off-by: Sean Paul <[email protected]> Link: https://patchwork.freedesktop.org/patch/msgid/[email protected]
1 parent 43c76d7 commit 1b27fbd

File tree

3 files changed

+81
-0
lines changed

3 files changed

+81
-0
lines changed

drivers/gpu/drm/drm_atomic.c

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -846,6 +846,75 @@ drm_atomic_get_new_private_obj_state(struct drm_atomic_state *state,
846846
}
847847
EXPORT_SYMBOL(drm_atomic_get_new_private_obj_state);
848848

849+
/**
850+
* drm_atomic_get_old_connector_for_encoder - Get old connector for an encoder
851+
* @state: Atomic state
852+
* @encoder: The encoder to fetch the connector state for
853+
*
854+
* This function finds and returns the connector that was connected to @encoder
855+
* as specified by the @state.
856+
*
857+
* If there is no connector in @state which previously had @encoder connected to
858+
* it, this function will return NULL. While this may seem like an invalid use
859+
* case, it is sometimes useful to differentiate commits which had no prior
860+
* connectors attached to @encoder vs ones that did (and to inspect their
861+
* state). This is especially true in enable hooks because the pipeline has
862+
* changed.
863+
*
864+
* Returns: The old connector connected to @encoder, or NULL if the encoder is
865+
* not connected.
866+
*/
867+
struct drm_connector *
868+
drm_atomic_get_old_connector_for_encoder(struct drm_atomic_state *state,
869+
struct drm_encoder *encoder)
870+
{
871+
struct drm_connector_state *conn_state;
872+
struct drm_connector *connector;
873+
unsigned int i;
874+
875+
for_each_old_connector_in_state(state, connector, conn_state, i) {
876+
if (conn_state->best_encoder == encoder)
877+
return connector;
878+
}
879+
880+
return NULL;
881+
}
882+
EXPORT_SYMBOL(drm_atomic_get_old_connector_for_encoder);
883+
884+
/**
885+
* drm_atomic_get_new_connector_for_encoder - Get new connector for an encoder
886+
* @state: Atomic state
887+
* @encoder: The encoder to fetch the connector state for
888+
*
889+
* This function finds and returns the connector that will be connected to
890+
* @encoder as specified by the @state.
891+
*
892+
* If there is no connector in @state which will have @encoder connected to it,
893+
* this function will return NULL. While this may seem like an invalid use case,
894+
* it is sometimes useful to differentiate commits which have no connectors
895+
* attached to @encoder vs ones that do (and to inspect their state). This is
896+
* especially true in disable hooks because the pipeline will change.
897+
*
898+
* Returns: The new connector connected to @encoder, or NULL if the encoder is
899+
* not connected.
900+
*/
901+
struct drm_connector *
902+
drm_atomic_get_new_connector_for_encoder(struct drm_atomic_state *state,
903+
struct drm_encoder *encoder)
904+
{
905+
struct drm_connector_state *conn_state;
906+
struct drm_connector *connector;
907+
unsigned int i;
908+
909+
for_each_new_connector_in_state(state, connector, conn_state, i) {
910+
if (conn_state->best_encoder == encoder)
911+
return connector;
912+
}
913+
914+
return NULL;
915+
}
916+
EXPORT_SYMBOL(drm_atomic_get_new_connector_for_encoder);
917+
849918
/**
850919
* drm_atomic_get_connector_state - get connector state
851920
* @state: global atomic state object

include/drm/drm_atomic.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -459,6 +459,13 @@ struct drm_private_state *
459459
drm_atomic_get_new_private_obj_state(struct drm_atomic_state *state,
460460
struct drm_private_obj *obj);
461461

462+
struct drm_connector *
463+
drm_atomic_get_old_connector_for_encoder(struct drm_atomic_state *state,
464+
struct drm_encoder *encoder);
465+
struct drm_connector *
466+
drm_atomic_get_new_connector_for_encoder(struct drm_atomic_state *state,
467+
struct drm_encoder *encoder);
468+
462469
/**
463470
* drm_atomic_get_existing_crtc_state - get crtc state, if it exists
464471
* @state: global atomic state object

include/drm/drm_connector.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -518,6 +518,11 @@ struct drm_connector_state {
518518
* &drm_connector_helper_funcs.atomic_best_encoder or
519519
* &drm_connector_helper_funcs.best_encoder callbacks.
520520
*
521+
* This is also used in the atomic helpers to map encoders to their
522+
* current and previous connectors, see
523+
* &drm_atomic_get_old_connector_for_encoder() and
524+
* &drm_atomic_get_new_connector_for_encoder().
525+
*
521526
* NOTE: Atomic drivers must fill this out (either themselves or through
522527
* helpers), for otherwise the GETCONNECTOR and GETENCODER IOCTLs will
523528
* not return correct data to userspace.

0 commit comments

Comments
 (0)