diff mbox series

[1/2] drm/i915/hdcp: Create a blanket hdcp enable function

Message ID 20231026071540.974755-2-suraj.kandpal@intel.com (mailing list archive)
State New, archived
Headers show
Series drm/i915/hdcp: Additional conditions to enable hdcp | expand

Commit Message

Kandpal, Suraj Oct. 26, 2023, 7:15 a.m. UTC
Let's create a blanket function which just has some conditions
which need to be checked before connectors enable hdcp.
This cleans up code and avoids code duplication.

Signed-off-by: Suraj Kandpal <suraj.kandpal@intel.com>
---
 drivers/gpu/drm/i915/display/intel_ddi.c    |  5 +----
 drivers/gpu/drm/i915/display/intel_dp_mst.c |  5 +----
 drivers/gpu/drm/i915/display/intel_hdcp.c   | 11 +++++++++++
 drivers/gpu/drm/i915/display/intel_hdcp.h   |  4 ++++
 4 files changed, 17 insertions(+), 8 deletions(-)

Comments

Jani Nikula Oct. 26, 2023, 7:32 a.m. UTC | #1
On Thu, 26 Oct 2023, Suraj Kandpal <suraj.kandpal@intel.com> wrote:
> Let's create a blanket function which just has some conditions
> which need to be checked before connectors enable hdcp.
> This cleans up code and avoids code duplication.

Let's call that function intel_hdcp_enable(), and hide all the details
inside intel_hdcp.c. These are the only callers outside of intel_hdcp.c.

BR,
Jani.

>
> Signed-off-by: Suraj Kandpal <suraj.kandpal@intel.com>
> ---
>  drivers/gpu/drm/i915/display/intel_ddi.c    |  5 +----
>  drivers/gpu/drm/i915/display/intel_dp_mst.c |  5 +----
>  drivers/gpu/drm/i915/display/intel_hdcp.c   | 11 +++++++++++
>  drivers/gpu/drm/i915/display/intel_hdcp.h   |  4 ++++
>  4 files changed, 17 insertions(+), 8 deletions(-)
>
> diff --git a/drivers/gpu/drm/i915/display/intel_ddi.c b/drivers/gpu/drm/i915/display/intel_ddi.c
> index 9151d5add960..338049b66e9c 100644
> --- a/drivers/gpu/drm/i915/display/intel_ddi.c
> +++ b/drivers/gpu/drm/i915/display/intel_ddi.c
> @@ -3259,10 +3259,7 @@ static void intel_enable_ddi(struct intel_atomic_state *state,
>  	else
>  		intel_enable_ddi_dp(state, encoder, crtc_state, conn_state);
>  
> -	/* Enable hdcp if it's desired */
> -	if (conn_state->content_protection ==
> -	    DRM_MODE_CONTENT_PROTECTION_DESIRED)
> -		intel_hdcp_enable(state, encoder, crtc_state, conn_state);
> +	intel_hdcp_try_enable(state, encoder, crtc_state, conn_state);
>  }
>  
>  static void intel_disable_ddi_dp(struct intel_atomic_state *state,
> diff --git a/drivers/gpu/drm/i915/display/intel_dp_mst.c b/drivers/gpu/drm/i915/display/intel_dp_mst.c
> index 7b4628f4f124..cfcaf54a4a72 100644
> --- a/drivers/gpu/drm/i915/display/intel_dp_mst.c
> +++ b/drivers/gpu/drm/i915/display/intel_dp_mst.c
> @@ -836,10 +836,7 @@ static void intel_mst_enable_dp(struct intel_atomic_state *state,
>  
>  	intel_audio_codec_enable(encoder, pipe_config, conn_state);
>  
> -	/* Enable hdcp if it's desired */
> -	if (conn_state->content_protection ==
> -	    DRM_MODE_CONTENT_PROTECTION_DESIRED)
> -		intel_hdcp_enable(state, encoder, pipe_config, conn_state);
> +	intel_hdcp_try_enable(state, encoder, pipe_config, conn_state);
>  }
>  
>  static bool intel_dp_mst_enc_get_hw_state(struct intel_encoder *encoder,
> diff --git a/drivers/gpu/drm/i915/display/intel_hdcp.c b/drivers/gpu/drm/i915/display/intel_hdcp.c
> index c89da3568ebd..9d632a85309d 100644
> --- a/drivers/gpu/drm/i915/display/intel_hdcp.c
> +++ b/drivers/gpu/drm/i915/display/intel_hdcp.c
> @@ -2324,6 +2324,17 @@ intel_hdcp_set_streams(struct intel_digital_port *dig_port,
>  	return 0;
>  }
>  
> +void intel_hdcp_try_enable(struct intel_atomic_state *state,
> +			   struct intel_encoder *encoder,
> +			   const struct intel_crtc_state *crtc_state,
> +			   const struct drm_connector_state *conn_state)
> +{
> +	/* Enable hdcp if it's desired */
> +	if (conn_state->content_protection ==
> +	    DRM_MODE_CONTENT_PROTECTION_DESIRED)
> +		intel_hdcp_enable(state, encoder, crtc_state, conn_state);
> +}
> +
>  int intel_hdcp_enable(struct intel_atomic_state *state,
>  		      struct intel_encoder *encoder,
>  		      const struct intel_crtc_state *pipe_config,
> diff --git a/drivers/gpu/drm/i915/display/intel_hdcp.h b/drivers/gpu/drm/i915/display/intel_hdcp.h
> index 5997c52a0958..280eaa4d1010 100644
> --- a/drivers/gpu/drm/i915/display/intel_hdcp.h
> +++ b/drivers/gpu/drm/i915/display/intel_hdcp.h
> @@ -44,5 +44,9 @@ void intel_hdcp_component_init(struct drm_i915_private *i915);
>  void intel_hdcp_component_fini(struct drm_i915_private *i915);
>  void intel_hdcp_cleanup(struct intel_connector *connector);
>  void intel_hdcp_handle_cp_irq(struct intel_connector *connector);
> +void intel_hdcp_try_enable(struct intel_atomic_state *state,
> +			   struct intel_encoder *encoder,
> +			   const struct intel_crtc_state *crtc_state,
> +			   const struct drm_connector_state *conn_state);
>  
>  #endif /* __INTEL_HDCP_H__ */
Kandpal, Suraj Oct. 26, 2023, 7:40 a.m. UTC | #2
> -----Original Message-----
> From: Jani Nikula <jani.nikula@linux.intel.com>
> Sent: Thursday, October 26, 2023 1:02 PM
> To: Kandpal, Suraj <suraj.kandpal@intel.com>; intel-gfx@lists.freedesktop.org
> Cc: Shankar, Uma <uma.shankar@intel.com>; Nautiyal, Ankit K
> <ankit.k.nautiyal@intel.com>; Kandpal, Suraj <suraj.kandpal@intel.com>
> Subject: Re: [PATCH 1/2] drm/i915/hdcp: Create a blanket hdcp enable function
> 
> On Thu, 26 Oct 2023, Suraj Kandpal <suraj.kandpal@intel.com> wrote:
> > Let's create a blanket function which just has some conditions which
> > need to be checked before connectors enable hdcp.
> > This cleans up code and avoids code duplication.
> 
> Let's call that function intel_hdcp_enable(), and hide all the details inside
> intel_hdcp.c. These are the only callers outside of intel_hdcp.c.

Maybe the rename current intel_hdcp_enable() to something else as that also is called in
Intel_hdcp_update_pipe on which I wouldn't want these conditions to be enforced.
I thought of renaming the current intel_hdcp_enable() to _intel_hdcp_enable() but that is already
Being used as a function name to enable hdcp1.4
So any suggestions what I can rename it to?

Regards,
Suraj Kandpal
> 
> BR,
> Jani.
> 
> >
> > Signed-off-by: Suraj Kandpal <suraj.kandpal@intel.com>
> > ---
> >  drivers/gpu/drm/i915/display/intel_ddi.c    |  5 +----
> >  drivers/gpu/drm/i915/display/intel_dp_mst.c |  5 +----
> >  drivers/gpu/drm/i915/display/intel_hdcp.c   | 11 +++++++++++
> >  drivers/gpu/drm/i915/display/intel_hdcp.h   |  4 ++++
> >  4 files changed, 17 insertions(+), 8 deletions(-)
> >
> > diff --git a/drivers/gpu/drm/i915/display/intel_ddi.c
> > b/drivers/gpu/drm/i915/display/intel_ddi.c
> > index 9151d5add960..338049b66e9c 100644
> > --- a/drivers/gpu/drm/i915/display/intel_ddi.c
> > +++ b/drivers/gpu/drm/i915/display/intel_ddi.c
> > @@ -3259,10 +3259,7 @@ static void intel_enable_ddi(struct
> intel_atomic_state *state,
> >  	else
> >  		intel_enable_ddi_dp(state, encoder, crtc_state, conn_state);
> >
> > -	/* Enable hdcp if it's desired */
> > -	if (conn_state->content_protection ==
> > -	    DRM_MODE_CONTENT_PROTECTION_DESIRED)
> > -		intel_hdcp_enable(state, encoder, crtc_state, conn_state);
> > +	intel_hdcp_try_enable(state, encoder, crtc_state, conn_state);
> >  }
> >
> >  static void intel_disable_ddi_dp(struct intel_atomic_state *state,
> > diff --git a/drivers/gpu/drm/i915/display/intel_dp_mst.c
> > b/drivers/gpu/drm/i915/display/intel_dp_mst.c
> > index 7b4628f4f124..cfcaf54a4a72 100644
> > --- a/drivers/gpu/drm/i915/display/intel_dp_mst.c
> > +++ b/drivers/gpu/drm/i915/display/intel_dp_mst.c
> > @@ -836,10 +836,7 @@ static void intel_mst_enable_dp(struct
> > intel_atomic_state *state,
> >
> >  	intel_audio_codec_enable(encoder, pipe_config, conn_state);
> >
> > -	/* Enable hdcp if it's desired */
> > -	if (conn_state->content_protection ==
> > -	    DRM_MODE_CONTENT_PROTECTION_DESIRED)
> > -		intel_hdcp_enable(state, encoder, pipe_config, conn_state);
> > +	intel_hdcp_try_enable(state, encoder, pipe_config, conn_state);
> >  }
> >
> >  static bool intel_dp_mst_enc_get_hw_state(struct intel_encoder
> > *encoder, diff --git a/drivers/gpu/drm/i915/display/intel_hdcp.c
> > b/drivers/gpu/drm/i915/display/intel_hdcp.c
> > index c89da3568ebd..9d632a85309d 100644
> > --- a/drivers/gpu/drm/i915/display/intel_hdcp.c
> > +++ b/drivers/gpu/drm/i915/display/intel_hdcp.c
> > @@ -2324,6 +2324,17 @@ intel_hdcp_set_streams(struct intel_digital_port
> *dig_port,
> >  	return 0;
> >  }
> >
> > +void intel_hdcp_try_enable(struct intel_atomic_state *state,
> > +			   struct intel_encoder *encoder,
> > +			   const struct intel_crtc_state *crtc_state,
> > +			   const struct drm_connector_state *conn_state) {
> > +	/* Enable hdcp if it's desired */
> > +	if (conn_state->content_protection ==
> > +	    DRM_MODE_CONTENT_PROTECTION_DESIRED)
> > +		intel_hdcp_enable(state, encoder, crtc_state, conn_state); }
> > +
> >  int intel_hdcp_enable(struct intel_atomic_state *state,
> >  		      struct intel_encoder *encoder,
> >  		      const struct intel_crtc_state *pipe_config, diff --git
> > a/drivers/gpu/drm/i915/display/intel_hdcp.h
> > b/drivers/gpu/drm/i915/display/intel_hdcp.h
> > index 5997c52a0958..280eaa4d1010 100644
> > --- a/drivers/gpu/drm/i915/display/intel_hdcp.h
> > +++ b/drivers/gpu/drm/i915/display/intel_hdcp.h
> > @@ -44,5 +44,9 @@ void intel_hdcp_component_init(struct
> > drm_i915_private *i915);  void intel_hdcp_component_fini(struct
> > drm_i915_private *i915);  void intel_hdcp_cleanup(struct
> > intel_connector *connector);  void intel_hdcp_handle_cp_irq(struct
> > intel_connector *connector);
> > +void intel_hdcp_try_enable(struct intel_atomic_state *state,
> > +			   struct intel_encoder *encoder,
> > +			   const struct intel_crtc_state *crtc_state,
> > +			   const struct drm_connector_state *conn_state);
> >
> >  #endif /* __INTEL_HDCP_H__ */
> 
> --
> Jani Nikula, Intel
Jani Nikula Oct. 26, 2023, 7:54 a.m. UTC | #3
On Thu, 26 Oct 2023, "Kandpal, Suraj" <suraj.kandpal@intel.com> wrote:
>> -----Original Message-----
>> From: Jani Nikula <jani.nikula@linux.intel.com>
>> Sent: Thursday, October 26, 2023 1:02 PM
>> To: Kandpal, Suraj <suraj.kandpal@intel.com>; intel-gfx@lists.freedesktop.org
>> Cc: Shankar, Uma <uma.shankar@intel.com>; Nautiyal, Ankit K
>> <ankit.k.nautiyal@intel.com>; Kandpal, Suraj <suraj.kandpal@intel.com>
>> Subject: Re: [PATCH 1/2] drm/i915/hdcp: Create a blanket hdcp enable function
>> 
>> On Thu, 26 Oct 2023, Suraj Kandpal <suraj.kandpal@intel.com> wrote:
>> > Let's create a blanket function which just has some conditions which
>> > need to be checked before connectors enable hdcp.
>> > This cleans up code and avoids code duplication.
>> 
>> Let's call that function intel_hdcp_enable(), and hide all the details inside
>> intel_hdcp.c. These are the only callers outside of intel_hdcp.c.
>
> Maybe the rename current intel_hdcp_enable() to something else as that also is called in
> Intel_hdcp_update_pipe on which I wouldn't want these conditions to be enforced.
> I thought of renaming the current intel_hdcp_enable() to _intel_hdcp_enable() but that is already
> Being used as a function name to enable hdcp1.4
> So any suggestions what I can rename it to?

Please just call it intel_hdcp_enable(), and deal with the above
problems internally in intel_hdcp.c. Don't leak the problems outside of
intel_hdcp.c.

BR,
Jani.

>
> Regards,
> Suraj Kandpal
>> 
>> BR,
>> Jani.
>> 
>> >
>> > Signed-off-by: Suraj Kandpal <suraj.kandpal@intel.com>
>> > ---
>> >  drivers/gpu/drm/i915/display/intel_ddi.c    |  5 +----
>> >  drivers/gpu/drm/i915/display/intel_dp_mst.c |  5 +----
>> >  drivers/gpu/drm/i915/display/intel_hdcp.c   | 11 +++++++++++
>> >  drivers/gpu/drm/i915/display/intel_hdcp.h   |  4 ++++
>> >  4 files changed, 17 insertions(+), 8 deletions(-)
>> >
>> > diff --git a/drivers/gpu/drm/i915/display/intel_ddi.c
>> > b/drivers/gpu/drm/i915/display/intel_ddi.c
>> > index 9151d5add960..338049b66e9c 100644
>> > --- a/drivers/gpu/drm/i915/display/intel_ddi.c
>> > +++ b/drivers/gpu/drm/i915/display/intel_ddi.c
>> > @@ -3259,10 +3259,7 @@ static void intel_enable_ddi(struct
>> intel_atomic_state *state,
>> >  	else
>> >  		intel_enable_ddi_dp(state, encoder, crtc_state, conn_state);
>> >
>> > -	/* Enable hdcp if it's desired */
>> > -	if (conn_state->content_protection ==
>> > -	    DRM_MODE_CONTENT_PROTECTION_DESIRED)
>> > -		intel_hdcp_enable(state, encoder, crtc_state, conn_state);
>> > +	intel_hdcp_try_enable(state, encoder, crtc_state, conn_state);
>> >  }
>> >
>> >  static void intel_disable_ddi_dp(struct intel_atomic_state *state,
>> > diff --git a/drivers/gpu/drm/i915/display/intel_dp_mst.c
>> > b/drivers/gpu/drm/i915/display/intel_dp_mst.c
>> > index 7b4628f4f124..cfcaf54a4a72 100644
>> > --- a/drivers/gpu/drm/i915/display/intel_dp_mst.c
>> > +++ b/drivers/gpu/drm/i915/display/intel_dp_mst.c
>> > @@ -836,10 +836,7 @@ static void intel_mst_enable_dp(struct
>> > intel_atomic_state *state,
>> >
>> >  	intel_audio_codec_enable(encoder, pipe_config, conn_state);
>> >
>> > -	/* Enable hdcp if it's desired */
>> > -	if (conn_state->content_protection ==
>> > -	    DRM_MODE_CONTENT_PROTECTION_DESIRED)
>> > -		intel_hdcp_enable(state, encoder, pipe_config, conn_state);
>> > +	intel_hdcp_try_enable(state, encoder, pipe_config, conn_state);
>> >  }
>> >
>> >  static bool intel_dp_mst_enc_get_hw_state(struct intel_encoder
>> > *encoder, diff --git a/drivers/gpu/drm/i915/display/intel_hdcp.c
>> > b/drivers/gpu/drm/i915/display/intel_hdcp.c
>> > index c89da3568ebd..9d632a85309d 100644
>> > --- a/drivers/gpu/drm/i915/display/intel_hdcp.c
>> > +++ b/drivers/gpu/drm/i915/display/intel_hdcp.c
>> > @@ -2324,6 +2324,17 @@ intel_hdcp_set_streams(struct intel_digital_port
>> *dig_port,
>> >  	return 0;
>> >  }
>> >
>> > +void intel_hdcp_try_enable(struct intel_atomic_state *state,
>> > +			   struct intel_encoder *encoder,
>> > +			   const struct intel_crtc_state *crtc_state,
>> > +			   const struct drm_connector_state *conn_state) {
>> > +	/* Enable hdcp if it's desired */
>> > +	if (conn_state->content_protection ==
>> > +	    DRM_MODE_CONTENT_PROTECTION_DESIRED)
>> > +		intel_hdcp_enable(state, encoder, crtc_state, conn_state); }
>> > +
>> >  int intel_hdcp_enable(struct intel_atomic_state *state,
>> >  		      struct intel_encoder *encoder,
>> >  		      const struct intel_crtc_state *pipe_config, diff --git
>> > a/drivers/gpu/drm/i915/display/intel_hdcp.h
>> > b/drivers/gpu/drm/i915/display/intel_hdcp.h
>> > index 5997c52a0958..280eaa4d1010 100644
>> > --- a/drivers/gpu/drm/i915/display/intel_hdcp.h
>> > +++ b/drivers/gpu/drm/i915/display/intel_hdcp.h
>> > @@ -44,5 +44,9 @@ void intel_hdcp_component_init(struct
>> > drm_i915_private *i915);  void intel_hdcp_component_fini(struct
>> > drm_i915_private *i915);  void intel_hdcp_cleanup(struct
>> > intel_connector *connector);  void intel_hdcp_handle_cp_irq(struct
>> > intel_connector *connector);
>> > +void intel_hdcp_try_enable(struct intel_atomic_state *state,
>> > +			   struct intel_encoder *encoder,
>> > +			   const struct intel_crtc_state *crtc_state,
>> > +			   const struct drm_connector_state *conn_state);
>> >
>> >  #endif /* __INTEL_HDCP_H__ */
>> 
>> --
>> Jani Nikula, Intel
diff mbox series

Patch

diff --git a/drivers/gpu/drm/i915/display/intel_ddi.c b/drivers/gpu/drm/i915/display/intel_ddi.c
index 9151d5add960..338049b66e9c 100644
--- a/drivers/gpu/drm/i915/display/intel_ddi.c
+++ b/drivers/gpu/drm/i915/display/intel_ddi.c
@@ -3259,10 +3259,7 @@  static void intel_enable_ddi(struct intel_atomic_state *state,
 	else
 		intel_enable_ddi_dp(state, encoder, crtc_state, conn_state);
 
-	/* Enable hdcp if it's desired */
-	if (conn_state->content_protection ==
-	    DRM_MODE_CONTENT_PROTECTION_DESIRED)
-		intel_hdcp_enable(state, encoder, crtc_state, conn_state);
+	intel_hdcp_try_enable(state, encoder, crtc_state, conn_state);
 }
 
 static void intel_disable_ddi_dp(struct intel_atomic_state *state,
diff --git a/drivers/gpu/drm/i915/display/intel_dp_mst.c b/drivers/gpu/drm/i915/display/intel_dp_mst.c
index 7b4628f4f124..cfcaf54a4a72 100644
--- a/drivers/gpu/drm/i915/display/intel_dp_mst.c
+++ b/drivers/gpu/drm/i915/display/intel_dp_mst.c
@@ -836,10 +836,7 @@  static void intel_mst_enable_dp(struct intel_atomic_state *state,
 
 	intel_audio_codec_enable(encoder, pipe_config, conn_state);
 
-	/* Enable hdcp if it's desired */
-	if (conn_state->content_protection ==
-	    DRM_MODE_CONTENT_PROTECTION_DESIRED)
-		intel_hdcp_enable(state, encoder, pipe_config, conn_state);
+	intel_hdcp_try_enable(state, encoder, pipe_config, conn_state);
 }
 
 static bool intel_dp_mst_enc_get_hw_state(struct intel_encoder *encoder,
diff --git a/drivers/gpu/drm/i915/display/intel_hdcp.c b/drivers/gpu/drm/i915/display/intel_hdcp.c
index c89da3568ebd..9d632a85309d 100644
--- a/drivers/gpu/drm/i915/display/intel_hdcp.c
+++ b/drivers/gpu/drm/i915/display/intel_hdcp.c
@@ -2324,6 +2324,17 @@  intel_hdcp_set_streams(struct intel_digital_port *dig_port,
 	return 0;
 }
 
+void intel_hdcp_try_enable(struct intel_atomic_state *state,
+			   struct intel_encoder *encoder,
+			   const struct intel_crtc_state *crtc_state,
+			   const struct drm_connector_state *conn_state)
+{
+	/* Enable hdcp if it's desired */
+	if (conn_state->content_protection ==
+	    DRM_MODE_CONTENT_PROTECTION_DESIRED)
+		intel_hdcp_enable(state, encoder, crtc_state, conn_state);
+}
+
 int intel_hdcp_enable(struct intel_atomic_state *state,
 		      struct intel_encoder *encoder,
 		      const struct intel_crtc_state *pipe_config,
diff --git a/drivers/gpu/drm/i915/display/intel_hdcp.h b/drivers/gpu/drm/i915/display/intel_hdcp.h
index 5997c52a0958..280eaa4d1010 100644
--- a/drivers/gpu/drm/i915/display/intel_hdcp.h
+++ b/drivers/gpu/drm/i915/display/intel_hdcp.h
@@ -44,5 +44,9 @@  void intel_hdcp_component_init(struct drm_i915_private *i915);
 void intel_hdcp_component_fini(struct drm_i915_private *i915);
 void intel_hdcp_cleanup(struct intel_connector *connector);
 void intel_hdcp_handle_cp_irq(struct intel_connector *connector);
+void intel_hdcp_try_enable(struct intel_atomic_state *state,
+			   struct intel_encoder *encoder,
+			   const struct intel_crtc_state *crtc_state,
+			   const struct drm_connector_state *conn_state);
 
 #endif /* __INTEL_HDCP_H__ */