diff mbox series

[v2,03/13] drm/hdcp: Update property value on content type and user changes

Message ID 20210915203834.1439-4-sean@poorly.run (mailing list archive)
State New, archived
Headers show
Series drm/hdcp: Pull HDCP auth/exchange/check into helpers | expand

Commit Message

Sean Paul Sept. 15, 2021, 8:38 p.m. UTC
From: Sean Paul <seanpaul@chromium.org>

This patch updates the connector's property value in 2 cases which were
previously missed:

1- Content type changes. The value should revert back to DESIRED from
   ENABLED in case the driver must re-authenticate the link due to the
   new content type.

2- Userspace sets value to DESIRED while ENABLED. In this case, the
   value should be reset immediately to ENABLED since the link is
   actively being encrypted.

To accommodate these changes, I've split up the conditionals to make
things a bit more clear (as much as one can with this mess of state).

Signed-off-by: Sean Paul <seanpaul@chromium.org>
Link: https://patchwork.freedesktop.org/patch/msgid/20210913175747.47456-4-sean@poorly.run #v1

Changes in v2:
-None
---
 drivers/gpu/drm/drm_hdcp.c | 26 +++++++++++++++++---------
 1 file changed, 17 insertions(+), 9 deletions(-)

Comments

kernel test robot Sept. 16, 2021, 10:48 p.m. UTC | #1
Hi Sean,

I love your patch! Perhaps something to improve:

[auto build test WARNING on drm-intel/for-linux-next]
[also build test WARNING on drm-tip/drm-tip robh/for-next linus/master v5.15-rc1 next-20210916]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Sean-Paul/drm-hdcp-Pull-HDCP-auth-exchange-check-into-helpers/20210916-044145
base:   git://anongit.freedesktop.org/drm-intel for-linux-next
config: x86_64-randconfig-m001-20210916 (attached as .config)
compiler: gcc-9 (Debian 9.3.0-22) 9.3.0

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>

smatch warnings:
drivers/gpu/drm/drm_hdcp.c:509 drm_hdcp_atomic_check() warn: inconsistent indenting

vim +509 drivers/gpu/drm/drm_hdcp.c

a46c52c65fdbf76 Sean Paul 2021-09-15  425  
a46c52c65fdbf76 Sean Paul 2021-09-15  426  /**
a46c52c65fdbf76 Sean Paul 2021-09-15  427   * drm_hdcp_atomic_check - Helper for drivers to call during connector->atomic_check
a46c52c65fdbf76 Sean Paul 2021-09-15  428   *
a46c52c65fdbf76 Sean Paul 2021-09-15  429   * @state: pointer to the atomic state being checked
a46c52c65fdbf76 Sean Paul 2021-09-15  430   * @connector: drm_connector on which content protection state needs an update
a46c52c65fdbf76 Sean Paul 2021-09-15  431   *
a46c52c65fdbf76 Sean Paul 2021-09-15  432   * This function can be used by display drivers to perform an atomic check on the
d0cdceca77739a6 Sean Paul 2021-09-15  433   * hdcp state elements. If hdcp state has changed in a manner which requires the
d0cdceca77739a6 Sean Paul 2021-09-15  434   * driver to enable or disable content protection, this function will return
d0cdceca77739a6 Sean Paul 2021-09-15  435   * true.
d0cdceca77739a6 Sean Paul 2021-09-15  436   *
d0cdceca77739a6 Sean Paul 2021-09-15  437   * Returns:
d0cdceca77739a6 Sean Paul 2021-09-15  438   * true if the driver must enable/disable hdcp, false otherwise
a46c52c65fdbf76 Sean Paul 2021-09-15  439   */
d0cdceca77739a6 Sean Paul 2021-09-15  440  bool drm_hdcp_atomic_check(struct drm_connector *connector,
a46c52c65fdbf76 Sean Paul 2021-09-15  441  			   struct drm_atomic_state *state)
a46c52c65fdbf76 Sean Paul 2021-09-15  442  {
a46c52c65fdbf76 Sean Paul 2021-09-15  443  	struct drm_connector_state *new_conn_state, *old_conn_state;
a46c52c65fdbf76 Sean Paul 2021-09-15  444  	struct drm_crtc_state *new_crtc_state;
a46c52c65fdbf76 Sean Paul 2021-09-15  445  	u64 old_hdcp, new_hdcp;
a46c52c65fdbf76 Sean Paul 2021-09-15  446  
a46c52c65fdbf76 Sean Paul 2021-09-15  447  	old_conn_state = drm_atomic_get_old_connector_state(state, connector);
a46c52c65fdbf76 Sean Paul 2021-09-15  448  	old_hdcp = old_conn_state->content_protection;
a46c52c65fdbf76 Sean Paul 2021-09-15  449  
a46c52c65fdbf76 Sean Paul 2021-09-15  450  	new_conn_state = drm_atomic_get_new_connector_state(state, connector);
a46c52c65fdbf76 Sean Paul 2021-09-15  451  	new_hdcp = new_conn_state->content_protection;
a46c52c65fdbf76 Sean Paul 2021-09-15  452  
a46c52c65fdbf76 Sean Paul 2021-09-15  453  	if (!new_conn_state->crtc) {
a46c52c65fdbf76 Sean Paul 2021-09-15  454  		/*
a46c52c65fdbf76 Sean Paul 2021-09-15  455  		 * If the connector is being disabled with CP enabled, mark it
a46c52c65fdbf76 Sean Paul 2021-09-15  456  		 * desired so it's re-enabled when the connector is brought back
a46c52c65fdbf76 Sean Paul 2021-09-15  457  		 */
d0cdceca77739a6 Sean Paul 2021-09-15  458  		if (old_hdcp == DRM_MODE_CONTENT_PROTECTION_ENABLED) {
a46c52c65fdbf76 Sean Paul 2021-09-15  459  			new_conn_state->content_protection =
a46c52c65fdbf76 Sean Paul 2021-09-15  460  				DRM_MODE_CONTENT_PROTECTION_DESIRED;
d0cdceca77739a6 Sean Paul 2021-09-15  461  			return true;
d0cdceca77739a6 Sean Paul 2021-09-15  462  		}
d0cdceca77739a6 Sean Paul 2021-09-15  463  		return false;
a46c52c65fdbf76 Sean Paul 2021-09-15  464  	}
a46c52c65fdbf76 Sean Paul 2021-09-15  465  
a46c52c65fdbf76 Sean Paul 2021-09-15  466  	new_crtc_state = drm_atomic_get_new_crtc_state(state,
a46c52c65fdbf76 Sean Paul 2021-09-15  467  						       new_conn_state->crtc);
a46c52c65fdbf76 Sean Paul 2021-09-15  468  	/*
a46c52c65fdbf76 Sean Paul 2021-09-15  469  	* Fix the HDCP uapi content protection state in case of modeset.
a46c52c65fdbf76 Sean Paul 2021-09-15  470  	* FIXME: As per HDCP content protection property uapi doc, an uevent()
a46c52c65fdbf76 Sean Paul 2021-09-15  471  	* need to be sent if there is transition from ENABLED->DESIRED.
a46c52c65fdbf76 Sean Paul 2021-09-15  472  	*/
a46c52c65fdbf76 Sean Paul 2021-09-15  473  	if (drm_atomic_crtc_needs_modeset(new_crtc_state) &&
a46c52c65fdbf76 Sean Paul 2021-09-15  474  	    (old_hdcp == DRM_MODE_CONTENT_PROTECTION_ENABLED &&
d0cdceca77739a6 Sean Paul 2021-09-15  475  	     new_hdcp != DRM_MODE_CONTENT_PROTECTION_UNDESIRED)) {
a46c52c65fdbf76 Sean Paul 2021-09-15  476  		new_conn_state->content_protection =
a46c52c65fdbf76 Sean Paul 2021-09-15  477  			DRM_MODE_CONTENT_PROTECTION_DESIRED;
d0cdceca77739a6 Sean Paul 2021-09-15  478  		return true;
d0cdceca77739a6 Sean Paul 2021-09-15  479  	}
d0cdceca77739a6 Sean Paul 2021-09-15  480  
d0cdceca77739a6 Sean Paul 2021-09-15  481  	/*
d0cdceca77739a6 Sean Paul 2021-09-15  482  	 * Coming back from disable or changing CRTC with DESIRED state requires
d0cdceca77739a6 Sean Paul 2021-09-15  483  	 * that the driver try CP enable.
d0cdceca77739a6 Sean Paul 2021-09-15  484  	 */
d0cdceca77739a6 Sean Paul 2021-09-15  485  	if (new_hdcp == DRM_MODE_CONTENT_PROTECTION_DESIRED &&
d0cdceca77739a6 Sean Paul 2021-09-15  486  	    new_conn_state->crtc != old_conn_state->crtc)
d0cdceca77739a6 Sean Paul 2021-09-15  487  		return true;
a46c52c65fdbf76 Sean Paul 2021-09-15  488  
a46c52c65fdbf76 Sean Paul 2021-09-15  489  	/*
6c538fd0f0a55b2 Sean Paul 2021-09-15  490  	 * Content type changes require an HDCP disable/enable cycle.
6c538fd0f0a55b2 Sean Paul 2021-09-15  491  	 */
6c538fd0f0a55b2 Sean Paul 2021-09-15  492  	if (new_conn_state->hdcp_content_type != old_conn_state->hdcp_content_type) {
6c538fd0f0a55b2 Sean Paul 2021-09-15  493  		new_conn_state->content_protection =
6c538fd0f0a55b2 Sean Paul 2021-09-15  494  			DRM_MODE_CONTENT_PROTECTION_DESIRED;
6c538fd0f0a55b2 Sean Paul 2021-09-15  495  		return true;
6c538fd0f0a55b2 Sean Paul 2021-09-15  496  	}
6c538fd0f0a55b2 Sean Paul 2021-09-15  497  
6c538fd0f0a55b2 Sean Paul 2021-09-15  498  	/*
6c538fd0f0a55b2 Sean Paul 2021-09-15  499  	 * Ignore meaningless state changes:
a46c52c65fdbf76 Sean Paul 2021-09-15  500  	 *  - HDCP was activated since the last commit
6c538fd0f0a55b2 Sean Paul 2021-09-15  501  	 *  - Attempting to set to desired while already enabled
a46c52c65fdbf76 Sean Paul 2021-09-15  502  	 */
6c538fd0f0a55b2 Sean Paul 2021-09-15  503  	if ((old_hdcp == DRM_MODE_CONTENT_PROTECTION_DESIRED &&
a46c52c65fdbf76 Sean Paul 2021-09-15  504  	     new_hdcp == DRM_MODE_CONTENT_PROTECTION_ENABLED) ||
a46c52c65fdbf76 Sean Paul 2021-09-15  505  	    (old_hdcp == DRM_MODE_CONTENT_PROTECTION_ENABLED &&
a46c52c65fdbf76 Sean Paul 2021-09-15  506  	     new_hdcp == DRM_MODE_CONTENT_PROTECTION_DESIRED)) {
6c538fd0f0a55b2 Sean Paul 2021-09-15  507  		new_conn_state->content_protection =
6c538fd0f0a55b2 Sean Paul 2021-09-15  508  			DRM_MODE_CONTENT_PROTECTION_ENABLED;
d0cdceca77739a6 Sean Paul 2021-09-15 @509  	     return false;

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org
diff mbox series

Patch

diff --git a/drivers/gpu/drm/drm_hdcp.c b/drivers/gpu/drm/drm_hdcp.c
index dd8fa91c51d6..742313ce8f6f 100644
--- a/drivers/gpu/drm/drm_hdcp.c
+++ b/drivers/gpu/drm/drm_hdcp.c
@@ -487,21 +487,29 @@  bool drm_hdcp_atomic_check(struct drm_connector *connector,
 		return true;
 
 	/*
-	 * Nothing to do if content type is unchanged and one of:
-	 *  - state didn't change
+	 * Content type changes require an HDCP disable/enable cycle.
+	 */
+	if (new_conn_state->hdcp_content_type != old_conn_state->hdcp_content_type) {
+		new_conn_state->content_protection =
+			DRM_MODE_CONTENT_PROTECTION_DESIRED;
+		return true;
+	}
+
+	/*
+	 * Ignore meaningless state changes:
 	 *  - HDCP was activated since the last commit
-	 *  - attempting to set to desired while already enabled
+	 *  - Attempting to set to desired while already enabled
 	 */
-	if (old_hdcp == new_hdcp ||
-	    (old_hdcp == DRM_MODE_CONTENT_PROTECTION_DESIRED &&
+	if ((old_hdcp == DRM_MODE_CONTENT_PROTECTION_DESIRED &&
 	     new_hdcp == DRM_MODE_CONTENT_PROTECTION_ENABLED) ||
 	    (old_hdcp == DRM_MODE_CONTENT_PROTECTION_ENABLED &&
 	     new_hdcp == DRM_MODE_CONTENT_PROTECTION_DESIRED)) {
-		if (old_conn_state->hdcp_content_type ==
-				new_conn_state->hdcp_content_type)
-			return false;
+		new_conn_state->content_protection =
+			DRM_MODE_CONTENT_PROTECTION_ENABLED;
+	     return false;
 	}
 
-	return true;
+	/* Finally, if state changes, we need action */
+	return old_hdcp != new_hdcp;
 }
 EXPORT_SYMBOL(drm_hdcp_atomic_check);