drm/i915: Pullout the bksv read and validation
authorRamalingam C <ramalingam.c@intel.com>
Tue, 23 Oct 2018 09:22:27 +0000 (14:52 +0530)
committerDaniel Vetter <daniel.vetter@ffwll.ch>
Wed, 24 Oct 2018 07:33:28 +0000 (09:33 +0200)
For reusability purpose, this patch implements the hdcp1.4 bksv's
read and validation as a functions.

For detecting the HDMI panel's HDCP capability this fucntions will be
used.

v2:
  Rebased.
v3:
  No Changes.
v4:
  inline tag is removed with modified error msg.
v5:
  No Changes.
v6:
  No Changes.
v7:
  Realigned the code.

Signed-off-by: Ramalingam C <ramalingam.c@intel.com>
Reviewed-by: Sean Paul <seanpaul@chromium.org>
Reviewed-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Link: https://patchwork.freedesktop.org/patch/msgid/1540286550-20399-2-git-send-email-ramalingam.c@intel.com
drivers/gpu/drm/i915/intel_hdcp.c

index 26e48fc95543244bb163f5f0f7d5370bda11ed59..20908ff018e692fa02d33c8f7d8b07a5cfca9be9 100644 (file)
 
 #define KEY_LOAD_TRIES 5
 
+static
+bool intel_hdcp_is_ksv_valid(u8 *ksv)
+{
+       int i, ones = 0;
+       /* KSV has 20 1's and 20 0's */
+       for (i = 0; i < DRM_HDCP_KSV_LEN; i++)
+               ones += hweight8(ksv[i]);
+       if (ones != 20)
+               return false;
+
+       return true;
+}
+
+static
+int intel_hdcp_read_valid_bksv(struct intel_digital_port *intel_dig_port,
+                              const struct intel_hdcp_shim *shim, u8 *bksv)
+{
+       int ret, i, tries = 2;
+
+       /* HDCP spec states that we must retry the bksv if it is invalid */
+       for (i = 0; i < tries; i++) {
+               ret = shim->read_bksv(intel_dig_port, bksv);
+               if (ret)
+                       return ret;
+               if (intel_hdcp_is_ksv_valid(bksv))
+                       break;
+       }
+       if (i == tries) {
+               DRM_ERROR("Bksv is invalid\n");
+               return -ENODEV;
+       }
+
+       return 0;
+}
+
 static int intel_hdcp_poll_ksv_fifo(struct intel_digital_port *intel_dig_port,
                                    const struct intel_hdcp_shim *shim)
 {
@@ -167,18 +202,6 @@ u32 intel_hdcp_get_repeater_ctl(struct intel_digital_port *intel_dig_port)
        return -EINVAL;
 }
 
-static
-bool intel_hdcp_is_ksv_valid(u8 *ksv)
-{
-       int i, ones = 0;
-       /* KSV has 20 1's and 20 0's */
-       for (i = 0; i < DRM_HDCP_KSV_LEN; i++)
-               ones += hweight8(ksv[i]);
-       if (ones != 20)
-               return false;
-       return true;
-}
-
 static
 int intel_hdcp_validate_v_prime(struct intel_digital_port *intel_dig_port,
                                const struct intel_hdcp_shim *shim,
@@ -527,18 +550,9 @@ static int intel_hdcp_auth(struct intel_digital_port *intel_dig_port,
 
        memset(&bksv, 0, sizeof(bksv));
 
-       /* HDCP spec states that we must retry the bksv if it is invalid */
-       for (i = 0; i < tries; i++) {
-               ret = shim->read_bksv(intel_dig_port, bksv.shim);
-               if (ret)
-                       return ret;
-               if (intel_hdcp_is_ksv_valid(bksv.shim))
-                       break;
-       }
-       if (i == tries) {
-               DRM_ERROR("HDCP failed, Bksv is invalid\n");
-               return -ENODEV;
-       }
+       ret = intel_hdcp_read_valid_bksv(intel_dig_port, shim, bksv.shim);
+       if (ret < 0)
+               return ret;
 
        I915_WRITE(PORT_HDCP_BKSVLO(port), bksv.reg[0]);
        I915_WRITE(PORT_HDCP_BKSVHI(port), bksv.reg[1]);