Implements the link integrity check once in 500mSec.

Once encryption is enabled, an ongoing Link Integrity Check is
performed by the HDCP Receiver to check that cipher synchronization
is maintained between the HDCP Transmitter and the HDCP Receiver.

On the detection of synchronization lost, the HDCP Receiver must assert
the corresponding bits of the RxStatus register. The Transmitter polls
the RxStatus register and it may initiate re-authentication.

v2:
  Rebased.
v3:
  enum check_link_response is used check the link status [Uma]
v4:
  Rebased as part of patch reordering.
v5:
  Required members of intel_hdcp is defined [Sean Paul]
v6:
  hdcp2_check_link is cancelled at required places.
v7:
  Rebased for the component i/f changes.
  Errors due to the sinks are reported as DEBUG logs.
v8:
  hdcp_check_work is used for both hdcp1 and hdcp2 check_link [Daniel]
  hdcp2.2 encryption status check is put under WARN_ON [Daniel]
  drm_hdcp.h changes are moved into separate patch [Daniel]

Signed-off-by: Ramalingam C <ramalinga...@intel.com>
Reviewed-by: Uma Shankar <uma.shan...@intel.com>
---
 drivers/gpu/drm/i915/intel_drv.h  |  3 ++
 drivers/gpu/drm/i915/intel_hdcp.c | 90 ++++++++++++++++++++++++++++++++++++---
 2 files changed, 87 insertions(+), 6 deletions(-)

diff --git a/drivers/gpu/drm/i915/intel_drv.h b/drivers/gpu/drm/i915/intel_drv.h
index a6b632d71490..60d1359e55f4 100644
--- a/drivers/gpu/drm/i915/intel_drv.h
+++ b/drivers/gpu/drm/i915/intel_drv.h
@@ -403,6 +403,9 @@ struct intel_hdcp_shim {
         */
        int (*config_stream_type)(struct intel_digital_port *intel_dig_port,
                                  void *buf, size_t size);
+
+       /* HDCP2.2 Link Integrity Check */
+       int (*check_2_2_link)(struct intel_digital_port *intel_dig_port);
 };
 
 struct intel_hdcp {
diff --git a/drivers/gpu/drm/i915/intel_hdcp.c 
b/drivers/gpu/drm/i915/intel_hdcp.c
index b52da5c3159d..6fac570fcbac 100644
--- a/drivers/gpu/drm/i915/intel_hdcp.c
+++ b/drivers/gpu/drm/i915/intel_hdcp.c
@@ -103,6 +103,16 @@ static inline bool intel_hdcp_in_use(struct 
intel_connector *connector)
        return reg & HDCP_STATUS_ENC;
 }
 
+static inline bool intel_hdcp2_in_use(struct intel_connector *connector)
+{
+       struct drm_i915_private *dev_priv = to_i915(connector->base.dev);
+       enum port port = connector->encoder->port;
+       u32 reg;
+
+       reg = I915_READ(HDCP2_STATUS_DDI(port));
+       return reg & LINK_ENCRYPTION_STATUS;
+}
+
 static int intel_hdcp_poll_ksv_fifo(struct intel_digital_port *intel_dig_port,
                                    const struct intel_hdcp_shim *shim)
 {
@@ -1491,11 +1501,77 @@ static int _intel_hdcp2_disable(struct intel_connector 
*connector)
        return ret;
 }
 
+/* Implements the Link Integrity Check for HDCP2.2 */
+static int intel_hdcp2_check_link(struct intel_connector *connector)
+{
+       struct intel_digital_port *intel_dig_port = conn_to_dig_port(connector);
+       struct drm_i915_private *dev_priv = to_i915(connector->base.dev);
+       struct intel_hdcp *hdcp = &connector->hdcp;
+       enum port port = connector->encoder->port;
+       int ret = 0;
+
+       mutex_lock(&hdcp->mutex);
+
+       /* hdcp2_check_link is expected only when HDCP2.2 is Enabled */
+       if (hdcp->value != DRM_MODE_CONTENT_PROTECTION_ENABLED ||
+           !hdcp->hdcp2_encrypted) {
+               ret = -EINVAL;
+               goto out;
+       }
+
+       if (WARN_ON(!intel_hdcp2_in_use(connector))) {
+               DRM_ERROR("HDCP2.2 link stopped the encryption, %x\n",
+                         I915_READ(HDCP2_STATUS_DDI(port)));
+               ret = -ENXIO;
+               hdcp->value = DRM_MODE_CONTENT_PROTECTION_DESIRED;
+               schedule_work(&hdcp->prop_work);
+               goto out;
+       }
+
+       ret = hdcp->shim->check_2_2_link(intel_dig_port);
+       if (ret == DRM_HDCP_LINK_PROTECTED) {
+               if (hdcp->value != DRM_MODE_CONTENT_PROTECTION_UNDESIRED) {
+                       hdcp->value = DRM_MODE_CONTENT_PROTECTION_ENABLED;
+                       schedule_work(&hdcp->prop_work);
+               }
+               goto out;
+       }
+
+       DRM_DEBUG_KMS("[%s:%d] HDCP2.2 link failed, retrying auth\n",
+                     connector->base.name, connector->base.base.id);
+
+       ret = _intel_hdcp2_disable(connector);
+       if (ret) {
+               DRM_ERROR("[%s:%d] Failed to disable hdcp2.2 (%d)\n",
+                         connector->base.name, connector->base.base.id, ret);
+               hdcp->value = DRM_MODE_CONTENT_PROTECTION_DESIRED;
+               schedule_work(&hdcp->prop_work);
+               goto out;
+       }
+
+       ret = _intel_hdcp2_enable(connector);
+       if (ret) {
+               DRM_DEBUG_KMS("[%s:%d] Failed to enable hdcp2.2 (%d)\n",
+                             connector->base.name, connector->base.base.id,
+                             ret);
+               hdcp->value = DRM_MODE_CONTENT_PROTECTION_DESIRED;
+               schedule_work(&hdcp->prop_work);
+               goto out;
+       }
+
+out:
+       mutex_unlock(&hdcp->mutex);
+       return ret;
+}
+
 static inline void _intel_hdcp_check_work(struct intel_connector *connector)
 {
        struct intel_hdcp *hdcp = &connector->hdcp;
 
-       if (!intel_hdcp_check_link(connector))
+       if (!intel_hdcp2_check_link(connector))
+               schedule_delayed_work(&hdcp->check_work,
+                                     DRM_HDCP2_CHECK_PERIOD_MS);
+       else if (!intel_hdcp_check_link(connector))
                schedule_delayed_work(&hdcp->check_work,
                                      DRM_HDCP_CHECK_PERIOD_MS);
 }
@@ -1606,6 +1682,7 @@ int intel_hdcp_init(struct intel_connector *connector,
 int intel_hdcp_enable(struct intel_connector *connector)
 {
        struct intel_hdcp *hdcp = &connector->hdcp;
+       unsigned long check_link_interval = DRM_HDCP_CHECK_PERIOD_MS;
        int ret = -EINVAL;
 
        if (!hdcp->shim)
@@ -1617,18 +1694,19 @@ int intel_hdcp_enable(struct intel_connector *connector)
         * Considering that HDCP2.2 is more secure than HDCP1.4, If the setup
         * is capable of HDCP2.2, it is preferred to use HDCP2.2.
         */
-       if (intel_hdcp2_capable(connector))
+       if (intel_hdcp2_capable(connector)) {
                ret = _intel_hdcp2_enable(connector);
+               if (!ret)
+                       check_link_interval = DRM_HDCP2_CHECK_PERIOD_MS;
+       }
 
        /* When HDCP2.2 fails, HDCP1.4 will be attempted */
        if (ret && intel_hdcp_capable(connector)) {
                ret = _intel_hdcp_enable(connector);
-               if (!ret)
-                       schedule_delayed_work(&hdcp->check_work,
-                                             DRM_HDCP_CHECK_PERIOD_MS);
        }
 
        if (!ret) {
+               schedule_delayed_work(&hdcp->check_work, check_link_interval);
                hdcp->value = DRM_MODE_CONTENT_PROTECTION_ENABLED;
                schedule_work(&hdcp->prop_work);
        }
@@ -1713,7 +1791,7 @@ void intel_hdcp_handle_cp_irq(struct intel_connector 
*connector)
        if (!mutex_trylock(&hdcp->mutex))
                return;
 
-       if (!hdcp->hdcp_encrypted)
+       if (!hdcp->hdcp_encrypted && !hdcp->hdcp2_encrypted)
                return;
 
        mutex_unlock(&hdcp->mutex);
-- 
2.7.4

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

Reply via email to