]> git.baikalelectronics.ru Git - kernel.git/commitdiff
drm/i915: Implement HDCP2.2 link integrity check
authorRamalingam C <ramalingam.c@intel.com>
Sat, 16 Feb 2019 17:36:57 +0000 (23:06 +0530)
committerDaniel Vetter <daniel.vetter@ffwll.ch>
Wed, 20 Feb 2019 19:41:13 +0000 (20:41 +0100)
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]
v9:
  enum check_link_status is defined at intel_drv.h [Daniel]

Signed-off-by: Ramalingam C <ramalingam.c@intel.com>
Reviewed-by: Uma Shankar <uma.shankar@intel.com>
Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Link: https://patchwork.freedesktop.org/patch/msgid/1550338640-17470-11-git-send-email-ramalingam.c@intel.com
drivers/gpu/drm/i915/intel_drv.h
drivers/gpu/drm/i915/intel_hdcp.c

index 5aa50fe344716aebce8ac94d4002ca21ab540704..60f1a85ec38481d40f169d6f5356f8833618c488 100644 (file)
@@ -324,6 +324,13 @@ struct intel_panel {
 
 struct intel_digital_port;
 
+enum check_link_response {
+       HDCP_LINK_PROTECTED     = 0,
+       HDCP_TOPOLOGY_CHANGE,
+       HDCP_LINK_INTEGRITY_FAILURE,
+       HDCP_REAUTH_REQUEST
+};
+
 /*
  * This structure serves as a translation layer between the generic HDCP code
  * and the bus-specific code. What that means is that HDCP over HDMI differs
@@ -419,6 +426,9 @@ struct intel_hdcp_shim {
         */
        int (*config_stream_type)(struct intel_digital_port *intel_dig_port,
                                  bool is_repeater, u8 type);
+
+       /* HDCP2.2 Link Integrity Check */
+       int (*check_2_2_link)(struct intel_digital_port *intel_dig_port);
 };
 
 struct intel_hdcp {
index 24051120d3bbba5c85e32debaca4950ff0164a1a..00fae3963caf0ccbc958f7842296607f820817e0 100644 (file)
@@ -111,6 +111,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)
 {
@@ -1580,6 +1590,69 @@ 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 == 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 void intel_hdcp_check_work(struct work_struct *work)
 {
        struct intel_hdcp *hdcp = container_of(to_delayed_work(work),
@@ -1587,7 +1660,10 @@ static void intel_hdcp_check_work(struct work_struct *work)
                                               check_work);
        struct intel_connector *connector = intel_hdcp_to_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);
 }
@@ -1721,6 +1797,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)
@@ -1733,18 +1810,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);
        }