From patchwork Tue Apr 11 19:21:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Yacoub X-Patchwork-Id: 13208155 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 69E05C76196 for ; Tue, 11 Apr 2023 19:21:51 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 230BA10E617; Tue, 11 Apr 2023 19:21:44 +0000 (UTC) Received: from mail-yb1-xb2a.google.com (mail-yb1-xb2a.google.com [IPv6:2607:f8b0:4864:20::b2a]) by gabe.freedesktop.org (Postfix) with ESMTPS id 4E50F10E617 for ; Tue, 11 Apr 2023 19:21:41 +0000 (UTC) Received: by mail-yb1-xb2a.google.com with SMTP id i20so13049549ybg.10 for ; Tue, 11 Apr 2023 12:21:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1681240900; x=1683832900; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=qVRn7naFUXAsjRb1O1mTo/7nJkom64M8Cx1cVOIuZhs=; b=TEcZrNbPpsbyhp8jNcU8le+hVDgfaEohnav5TXU7903HkjiEPMreQuw5yT+M0qanNB v1XWv54XYxhHHhi5ASdYs3L01NJHvf9pPF52o2ND0kloJ6CbeBuaK0fL/sflI/RfFKcy ArQnilI7fwzLJ7+ReeJ3HSHpj3v1uEtBjbKuE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1681240900; x=1683832900; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=qVRn7naFUXAsjRb1O1mTo/7nJkom64M8Cx1cVOIuZhs=; b=Y6B1dIkZH0dh4Suxkfy66B9f3UGI/0VJB9CsBBgEj6Q6alYbRe6zXMJMZxGQdkBs/U CwSXAcgiChNcs7m/zTzweekiTTTXn1JHyEUxhOlXei6aQeb+XXAkJm/RPdS/GJbPONyA 826fpMViKxV+hSIUpErG0GL144xgjb6QGxdZz52LS2XGZK1ix8+/VrTW6vDuu5eD2fZb jaaNbFqiAjh5FLUe+Akt8YrgEeDPrXE+T3V2uQ6kFdTcGdhKtLZMiMcwGQ1Wv6bTNMrc kMOXDbempK1upeI9ooKXVU4zFdHpRbBL5hLfLEHudjjqzYqndiGvUMsaT9tNNBrl4zss e2WA== X-Gm-Message-State: AAQBX9fTUrpQ7Lez65DiAy5e/w0xy+Ryn8Dy/gsmAtcejxJn19G3R0Ty usdX0bRZ+9Hpd2dzMVUXbDOJwA== X-Google-Smtp-Source: AKy350aKYkAHJtc3ynAkKkouXLTXQxYPnd+mgZjVCcq0RoDatBZYCZYMOLqcniHn3E7xoTK7VWhxLg== X-Received: by 2002:a25:ada1:0:b0:b67:412e:a81e with SMTP id z33-20020a25ada1000000b00b67412ea81emr13563829ybi.17.1681240900095; Tue, 11 Apr 2023 12:21:40 -0700 (PDT) Received: from localhost ([2620:0:1035:15:2991:9b76:4e62:65bf]) by smtp.gmail.com with UTF8SMTPSA id b2-20020a251b02000000b00b8692cfdfa6sm3814886ybb.27.2023.04.11.12.21.39 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 11 Apr 2023 12:21:39 -0700 (PDT) From: Mark Yacoub X-Google-Original-From: Mark Yacoub To: David Airlie , Daniel Vetter , Jani Nikula , Joonas Lahtinen , Rodrigo Vivi , Tvrtko Ursulin Date: Tue, 11 Apr 2023 15:21:25 -0400 Message-Id: <20230411192134.508113-2-markyacoub@google.com> X-Mailer: git-send-email 2.40.0.577.gac1e443424-goog In-Reply-To: <20230411192134.508113-1-markyacoub@google.com> References: <20230411192134.508113-1-markyacoub@google.com> MIME-Version: 1.0 Subject: [Intel-gfx] [PATCH v9 01/10] drm/hdcp: Add drm_hdcp_atomic_check() X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Jani Nikula , Mark Yacoub , intel-gfx@lists.freedesktop.org, dianders@chromium.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, seanpaul@chromium.org, dmitry.baryshkov@linaro.org, freedreno@lists.freedesktop.org Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" From: Sean Paul Move the hdcp atomic check from i915 to drm_hdcp so other drivers can use it. No functional changes, just cleaned up some of the code when moving it over. Acked-by: Jani Nikula Reviewed-by: Rodrigo Vivi Reviewed-by: Dmitry Baryshkov Signed-off-by: Sean Paul Signed-off-by: Mark Yacoub --- Changes in v2: -None Changes in v3: -None Changes in v4: -None Changes in v5: -None Changes in v6: -Rebase: move helper from drm_hdcp.c to drm_hdcp_helper.c Changes in v7: -Removed links to patch from commit msg (Dmitry Baryshkov) drivers/gpu/drm/display/drm_hdcp_helper.c | 64 +++++++++++++++++++++ drivers/gpu/drm/i915/display/intel_atomic.c | 4 +- drivers/gpu/drm/i915/display/intel_hdcp.c | 47 --------------- drivers/gpu/drm/i915/display/intel_hdcp.h | 3 - include/drm/display/drm_hdcp_helper.h | 3 + 5 files changed, 69 insertions(+), 52 deletions(-) diff --git a/drivers/gpu/drm/display/drm_hdcp_helper.c b/drivers/gpu/drm/display/drm_hdcp_helper.c index e78999c72bd77..7ca390b3ea106 100644 --- a/drivers/gpu/drm/display/drm_hdcp_helper.c +++ b/drivers/gpu/drm/display/drm_hdcp_helper.c @@ -20,6 +20,7 @@ #include #include #include +#include static inline void drm_hdcp_print_ksv(const u8 *ksv) { @@ -419,3 +420,66 @@ void drm_hdcp_update_content_protection(struct drm_connector *connector, dev->mode_config.content_protection_property); } EXPORT_SYMBOL(drm_hdcp_update_content_protection); + +/** + * drm_hdcp_atomic_check - Helper for drivers to call during connector->atomic_check + * + * @state: pointer to the atomic state being checked + * @connector: drm_connector on which content protection state needs an update + * + * This function can be used by display drivers to perform an atomic check on the + * hdcp state elements. If hdcp state has changed, this function will set + * mode_changed on the crtc driving the connector so it can update its hardware + * to match the hdcp state. + */ +void drm_hdcp_atomic_check(struct drm_connector *connector, + struct drm_atomic_state *state) +{ + struct drm_connector_state *new_conn_state, *old_conn_state; + struct drm_crtc_state *new_crtc_state; + u64 old_hdcp, new_hdcp; + + old_conn_state = drm_atomic_get_old_connector_state(state, connector); + old_hdcp = old_conn_state->content_protection; + + new_conn_state = drm_atomic_get_new_connector_state(state, connector); + new_hdcp = new_conn_state->content_protection; + + if (!new_conn_state->crtc) { + /* + * If the connector is being disabled with CP enabled, mark it + * desired so it's re-enabled when the connector is brought back + */ + if (old_hdcp == DRM_MODE_CONTENT_PROTECTION_ENABLED) + new_conn_state->content_protection = + DRM_MODE_CONTENT_PROTECTION_DESIRED; + return; + } + + new_crtc_state = + drm_atomic_get_new_crtc_state(state, new_conn_state->crtc); + if (drm_atomic_crtc_needs_modeset(new_crtc_state) && + (old_hdcp == DRM_MODE_CONTENT_PROTECTION_ENABLED && + new_hdcp != DRM_MODE_CONTENT_PROTECTION_UNDESIRED)) + new_conn_state->content_protection = + DRM_MODE_CONTENT_PROTECTION_DESIRED; + + /* + * Nothing to do if content type is unchanged and one of: + * - state didn't change + * - HDCP was activated since the last commit + * - attempting to set to desired while already enabled + */ + if (old_hdcp == new_hdcp || + (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; + } + + new_crtc_state->mode_changed = true; +} +EXPORT_SYMBOL(drm_hdcp_atomic_check); diff --git a/drivers/gpu/drm/i915/display/intel_atomic.c b/drivers/gpu/drm/i915/display/intel_atomic.c index a9a3f3715279d..e9d00b6a63d39 100644 --- a/drivers/gpu/drm/i915/display/intel_atomic.c +++ b/drivers/gpu/drm/i915/display/intel_atomic.c @@ -32,6 +32,7 @@ #include #include #include +#include #include "i915_drv.h" #include "i915_reg.h" @@ -39,7 +40,6 @@ #include "intel_cdclk.h" #include "intel_display_types.h" #include "intel_global_state.h" -#include "intel_hdcp.h" #include "intel_psr.h" #include "intel_fb.h" #include "skl_universal_plane.h" @@ -124,7 +124,7 @@ int intel_digital_connector_atomic_check(struct drm_connector *conn, to_intel_digital_connector_state(old_state); struct drm_crtc_state *crtc_state; - intel_hdcp_atomic_check(conn, old_state, new_state); + drm_hdcp_atomic_check(conn, state); if (!new_state->crtc) return 0; diff --git a/drivers/gpu/drm/i915/display/intel_hdcp.c b/drivers/gpu/drm/i915/display/intel_hdcp.c index 6406fd487ee52..396d2cef000aa 100644 --- a/drivers/gpu/drm/i915/display/intel_hdcp.c +++ b/drivers/gpu/drm/i915/display/intel_hdcp.c @@ -2524,53 +2524,6 @@ void intel_hdcp_cleanup(struct intel_connector *connector) mutex_unlock(&hdcp->mutex); } -void intel_hdcp_atomic_check(struct drm_connector *connector, - struct drm_connector_state *old_state, - struct drm_connector_state *new_state) -{ - u64 old_cp = old_state->content_protection; - u64 new_cp = new_state->content_protection; - struct drm_crtc_state *crtc_state; - - if (!new_state->crtc) { - /* - * If the connector is being disabled with CP enabled, mark it - * desired so it's re-enabled when the connector is brought back - */ - if (old_cp == DRM_MODE_CONTENT_PROTECTION_ENABLED) - new_state->content_protection = - DRM_MODE_CONTENT_PROTECTION_DESIRED; - return; - } - - crtc_state = drm_atomic_get_new_crtc_state(new_state->state, - new_state->crtc); - /* - * Fix the HDCP uapi content protection state in case of modeset. - * FIXME: As per HDCP content protection property uapi doc, an uevent() - * need to be sent if there is transition from ENABLED->DESIRED. - */ - if (drm_atomic_crtc_needs_modeset(crtc_state) && - (old_cp == DRM_MODE_CONTENT_PROTECTION_ENABLED && - new_cp != DRM_MODE_CONTENT_PROTECTION_UNDESIRED)) - new_state->content_protection = - DRM_MODE_CONTENT_PROTECTION_DESIRED; - - /* - * Nothing to do if the state didn't change, or HDCP was activated since - * the last commit. And also no change in hdcp content type. - */ - if (old_cp == new_cp || - (old_cp == DRM_MODE_CONTENT_PROTECTION_DESIRED && - new_cp == DRM_MODE_CONTENT_PROTECTION_ENABLED)) { - if (old_state->hdcp_content_type == - new_state->hdcp_content_type) - return; - } - - crtc_state->mode_changed = true; -} - /* Handles the CP_IRQ raised from the DP HDCP sink */ void intel_hdcp_handle_cp_irq(struct intel_connector *connector) { diff --git a/drivers/gpu/drm/i915/display/intel_hdcp.h b/drivers/gpu/drm/i915/display/intel_hdcp.h index 8f53b0c7fe5cf..7c5fd84a7b65a 100644 --- a/drivers/gpu/drm/i915/display/intel_hdcp.h +++ b/drivers/gpu/drm/i915/display/intel_hdcp.h @@ -22,9 +22,6 @@ struct intel_digital_port; enum port; enum transcoder; -void intel_hdcp_atomic_check(struct drm_connector *connector, - struct drm_connector_state *old_state, - struct drm_connector_state *new_state); int intel_hdcp_init(struct intel_connector *connector, struct intel_digital_port *dig_port, const struct intel_hdcp_shim *hdcp_shim); diff --git a/include/drm/display/drm_hdcp_helper.h b/include/drm/display/drm_hdcp_helper.h index 8aaf87bf27351..dd02b2e72a502 100644 --- a/include/drm/display/drm_hdcp_helper.h +++ b/include/drm/display/drm_hdcp_helper.h @@ -11,6 +11,7 @@ #include +struct drm_atomic_state; struct drm_device; struct drm_connector; @@ -18,5 +19,7 @@ int drm_hdcp_check_ksvs_revoked(struct drm_device *dev, u8 *ksvs, u32 ksv_count) int drm_connector_attach_content_protection_property(struct drm_connector *connector, bool hdcp_content_type); void drm_hdcp_update_content_protection(struct drm_connector *connector, u64 val); +void drm_hdcp_atomic_check(struct drm_connector *connector, + struct drm_atomic_state *state); #endif From patchwork Tue Apr 11 19:21:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Yacoub X-Patchwork-Id: 13208156 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id E476CC7619A for ; Tue, 11 Apr 2023 19:21:54 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id B9EC010E632; Tue, 11 Apr 2023 19:21:45 +0000 (UTC) Received: from mail-yw1-x1136.google.com (mail-yw1-x1136.google.com [IPv6:2607:f8b0:4864:20::1136]) by gabe.freedesktop.org (Postfix) with ESMTPS id 94EF810E635 for ; Tue, 11 Apr 2023 19:21:43 +0000 (UTC) Received: by mail-yw1-x1136.google.com with SMTP id 00721157ae682-54f21cdfadbso126165947b3.7 for ; Tue, 11 Apr 2023 12:21:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1681240902; x=1683832902; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=ZjdjabgEtko0J4aqL2ZO2CszCX4BKlzuYclS6+pvDLc=; b=JcoDjnevnIfKruLibPsiVr/AWbaWYtfSXoAO2Tl/xuSc1vthjjAQBPIueuukUzC3ia +BKHU/immmcaMFOeuNpH7GUPY5eGovXplWzrrrBFMH5MIdBOKIYHX7LRGD3iDNxZz9ez yUlN3YkwFBEEcYGEsLcb0s/+rAbi4nVAjhQlI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1681240902; x=1683832902; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ZjdjabgEtko0J4aqL2ZO2CszCX4BKlzuYclS6+pvDLc=; b=BonSndc4F5rj27sPFEdMfgJlB+FzEWKSYWYfKHdB/kPt5ZZJxAnNGaThnVwPajEnQK LJ4y822UOcEMcRvOUeUSPqyYQJ3nDBLcUjV6CdxcHTsXaD9d5TX4WMknhZZ41jjEzjpv g08cbAhsyIW5oAFcnpap90xPljsjzBRd7YxidNFiqSYcEXm5AclFOMubk++Kk6b2Mv5E +Jg3/0aaFE8/FRrk+TobZeZT3JLPNie1ABi/jOcUfsKpl8XgsuybQlLuxQRys/5j/zHy S0Ur2Okb+PG9D+TyLSKkznm29PW//lP7o2LVEBWk8XtAMPxmboobHhd53wFzidMa9L+8 DSjA== X-Gm-Message-State: AAQBX9cYSUumtnb2T8jAp+88bSdDw9WmWvqJ8yxsFSmH5BcEmxI/XvAC YgK05mDyFvLJT8aeZl6Cc2CxWw== X-Google-Smtp-Source: AKy350ael7iD8wEhYWMRKt2LZ319JSjzC7z7zYpRK6e+GLI+Itd/gGAYhwpEWt/8IWSB4aAEG7Waig== X-Received: by 2002:a81:838c:0:b0:54e:84a1:45b0 with SMTP id t134-20020a81838c000000b0054e84a145b0mr2652020ywf.51.1681240902246; Tue, 11 Apr 2023 12:21:42 -0700 (PDT) Received: from localhost ([2620:0:1035:15:2991:9b76:4e62:65bf]) by smtp.gmail.com with UTF8SMTPSA id bo5-20020a05690c058500b00545a08184fesm3637600ywb.142.2023.04.11.12.21.41 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 11 Apr 2023 12:21:42 -0700 (PDT) From: Mark Yacoub X-Google-Original-From: Mark Yacoub To: David Airlie , Daniel Vetter , Jani Nikula , Joonas Lahtinen , Rodrigo Vivi , Tvrtko Ursulin Date: Tue, 11 Apr 2023 15:21:26 -0400 Message-Id: <20230411192134.508113-3-markyacoub@google.com> X-Mailer: git-send-email 2.40.0.577.gac1e443424-goog In-Reply-To: <20230411192134.508113-1-markyacoub@google.com> References: <20230411192134.508113-1-markyacoub@google.com> MIME-Version: 1.0 Subject: [Intel-gfx] [PATCH v9 02/10] drm/hdcp: Avoid changing crtc state in hdcp atomic check X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Jani Nikula , Mark Yacoub , intel-gfx@lists.freedesktop.org, dianders@chromium.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, seanpaul@chromium.org, dmitry.baryshkov@linaro.org, freedreno@lists.freedesktop.org Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" From: Sean Paul Instead of forcing a modeset in the hdcp atomic check, rename to drm_hdcp_has_changed and return true if the content protection value is changing and let the driver decide whether a modeset is required or not. Acked-by: Jani Nikula Reviewed-by: Rodrigo Vivi Signed-off-by: Sean Paul Signed-off-by: Mark Yacoub --- Changes in v2: -None Changes in v3: -None Changes in v4: -None Changes in v5: -None Changes in v6: -Rebase: modifications in drm_hdcp_helper.c instead of drm_hdcp.c Changes in v7: -Renamed the function from drm_hdcp_atomic_check to drm_hdcp_has_changed (Dmitry Baryshkov) drivers/gpu/drm/display/drm_hdcp_helper.c | 39 ++++++++++++++------- drivers/gpu/drm/i915/display/intel_atomic.c | 6 ++-- include/drm/display/drm_hdcp_helper.h | 2 +- 3 files changed, 30 insertions(+), 17 deletions(-) diff --git a/drivers/gpu/drm/display/drm_hdcp_helper.c b/drivers/gpu/drm/display/drm_hdcp_helper.c index 7ca390b3ea106..34baf2b97cd87 100644 --- a/drivers/gpu/drm/display/drm_hdcp_helper.c +++ b/drivers/gpu/drm/display/drm_hdcp_helper.c @@ -422,18 +422,21 @@ void drm_hdcp_update_content_protection(struct drm_connector *connector, EXPORT_SYMBOL(drm_hdcp_update_content_protection); /** - * drm_hdcp_atomic_check - Helper for drivers to call during connector->atomic_check + * drm_hdcp_has_changed - Helper for drivers to call during connector->atomic_check * * @state: pointer to the atomic state being checked * @connector: drm_connector on which content protection state needs an update * * This function can be used by display drivers to perform an atomic check on the - * hdcp state elements. If hdcp state has changed, this function will set - * mode_changed on the crtc driving the connector so it can update its hardware - * to match the hdcp state. + * hdcp state elements. If hdcp state has changed in a manner which requires the + * driver to enable or disable content protection, this function will return + * true. + * + * Returns: + * true if the driver must enable/disable hdcp, false otherwise */ -void drm_hdcp_atomic_check(struct drm_connector *connector, - struct drm_atomic_state *state) +bool drm_hdcp_has_changed(struct drm_connector *connector, + struct drm_atomic_state *state) { struct drm_connector_state *new_conn_state, *old_conn_state; struct drm_crtc_state *new_crtc_state; @@ -450,19 +453,31 @@ void drm_hdcp_atomic_check(struct drm_connector *connector, * If the connector is being disabled with CP enabled, mark it * desired so it's re-enabled when the connector is brought back */ - if (old_hdcp == DRM_MODE_CONTENT_PROTECTION_ENABLED) + if (old_hdcp == DRM_MODE_CONTENT_PROTECTION_ENABLED) { new_conn_state->content_protection = DRM_MODE_CONTENT_PROTECTION_DESIRED; - return; + return true; + } + return false; } new_crtc_state = drm_atomic_get_new_crtc_state(state, new_conn_state->crtc); if (drm_atomic_crtc_needs_modeset(new_crtc_state) && (old_hdcp == DRM_MODE_CONTENT_PROTECTION_ENABLED && - new_hdcp != DRM_MODE_CONTENT_PROTECTION_UNDESIRED)) + new_hdcp != DRM_MODE_CONTENT_PROTECTION_UNDESIRED)) { new_conn_state->content_protection = DRM_MODE_CONTENT_PROTECTION_DESIRED; + return true; + } + + /* + * Coming back from UNDESIRED state, CRTC change or re-enablement requires + * the driver to try CP enable. + */ + if (new_hdcp == DRM_MODE_CONTENT_PROTECTION_DESIRED && + new_conn_state->crtc != old_conn_state->crtc) + return true; /* * Nothing to do if content type is unchanged and one of: @@ -477,9 +492,9 @@ void drm_hdcp_atomic_check(struct drm_connector *connector, new_hdcp == DRM_MODE_CONTENT_PROTECTION_DESIRED)) { if (old_conn_state->hdcp_content_type == new_conn_state->hdcp_content_type) - return; + return false; } - new_crtc_state->mode_changed = true; + return true; } -EXPORT_SYMBOL(drm_hdcp_atomic_check); +EXPORT_SYMBOL(drm_hdcp_has_changed); diff --git a/drivers/gpu/drm/i915/display/intel_atomic.c b/drivers/gpu/drm/i915/display/intel_atomic.c index e9d00b6a63d39..23a6ba315a22e 100644 --- a/drivers/gpu/drm/i915/display/intel_atomic.c +++ b/drivers/gpu/drm/i915/display/intel_atomic.c @@ -124,8 +124,6 @@ int intel_digital_connector_atomic_check(struct drm_connector *conn, to_intel_digital_connector_state(old_state); struct drm_crtc_state *crtc_state; - drm_hdcp_atomic_check(conn, state); - if (!new_state->crtc) return 0; @@ -141,8 +139,8 @@ int intel_digital_connector_atomic_check(struct drm_connector *conn, new_conn_state->base.picture_aspect_ratio != old_conn_state->base.picture_aspect_ratio || new_conn_state->base.content_type != old_conn_state->base.content_type || new_conn_state->base.scaling_mode != old_conn_state->base.scaling_mode || - new_conn_state->base.privacy_screen_sw_state != old_conn_state->base.privacy_screen_sw_state || - !drm_connector_atomic_hdr_metadata_equal(old_state, new_state)) + !drm_connector_atomic_hdr_metadata_equal(old_state, new_state) || + drm_hdcp_has_changed(conn, state)) crtc_state->mode_changed = true; return 0; diff --git a/include/drm/display/drm_hdcp_helper.h b/include/drm/display/drm_hdcp_helper.h index dd02b2e72a502..703421fcdf96c 100644 --- a/include/drm/display/drm_hdcp_helper.h +++ b/include/drm/display/drm_hdcp_helper.h @@ -19,7 +19,7 @@ int drm_hdcp_check_ksvs_revoked(struct drm_device *dev, u8 *ksvs, u32 ksv_count) int drm_connector_attach_content_protection_property(struct drm_connector *connector, bool hdcp_content_type); void drm_hdcp_update_content_protection(struct drm_connector *connector, u64 val); -void drm_hdcp_atomic_check(struct drm_connector *connector, +bool drm_hdcp_has_changed(struct drm_connector *connector, struct drm_atomic_state *state); #endif From patchwork Tue Apr 11 19:21:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Yacoub X-Patchwork-Id: 13208157 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id C8A8AC77B6F for ; Tue, 11 Apr 2023 19:21:55 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id EDD7110E635; Tue, 11 Apr 2023 19:21:46 +0000 (UTC) Received: from mail-yb1-xb2c.google.com (mail-yb1-xb2c.google.com [IPv6:2607:f8b0:4864:20::b2c]) by gabe.freedesktop.org (Postfix) with ESMTPS id 36EF910E631 for ; Tue, 11 Apr 2023 19:21:45 +0000 (UTC) Received: by mail-yb1-xb2c.google.com with SMTP id d204so966074ybh.6 for ; Tue, 11 Apr 2023 12:21:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1681240904; x=1683832904; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=FeKha53f0k4bkkLO2dosUj09FTrVxWlUDNH1WTM2b9U=; b=G2Z+paoTiwP/7rYfsV2ErD88qTHJUNNvgN9fOc0XaaBxkdsbP0xqzqz4ToIxE93XKC N1zduCfaMZUf7nvwe/fbfznQ/2EwU85XS2D/9ikuQMCpwA/1OvikO+IZAUfuMvDFIqI2 bj6yNu7zDh7jq1/qk5ZKF7bzfFow3rhdcELfs= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1681240904; x=1683832904; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=FeKha53f0k4bkkLO2dosUj09FTrVxWlUDNH1WTM2b9U=; b=V2qlq1dw/Kd0GanICNtDpUmXGWFO2Nwyd/n1Rw3JD59h0Sa9SjHgt50L42J4Bm7E3y BDUvzzdlBFdofGMl4/JT8ifVIpJU1qwMiwssvMKqafxWfc73F3Tb506dwgsaXhuWtlc7 8YE+R1BRpeTNdHKYR2hJC/4vqfcCrJqy09ffwBP8t6NpPuRnho1qpcyfzCiowxc/MF7Y +sZ7qcxszKkoqMuDfInQVTIrzZPxOp17t2a1I9pmt1kDsuQ2WGjulUiaD7+XhFp0mbmv tw/CJbe9aZMnIENf/zPY5bKkvKdmF5jBWaVrOMw4NhnwK0ITllTs5Slkk6hsGdzEGSzn xcqQ== X-Gm-Message-State: AAQBX9eAlcKLFHvoVg11OuOGqpy2FPaJIz6j2mC/BuzQ5UA+vn/DGl5y oojwyxHyPWlWVPQ8RmXgUmkq51FySerUBD3SD4w= X-Google-Smtp-Source: AKy350ZluJDOFpd1AfULKx22Egaoc8rniZgjGxaSiTV1kSN57HEq33GJfYfvuLjFtNJ/h1PIr681mg== X-Received: by 2002:a25:6545:0:b0:b8b:d5d7:69cb with SMTP id z66-20020a256545000000b00b8bd5d769cbmr8610485ybb.47.1681240904084; Tue, 11 Apr 2023 12:21:44 -0700 (PDT) Received: from localhost ([2620:0:1035:15:2991:9b76:4e62:65bf]) by smtp.gmail.com with UTF8SMTPSA id n127-20020a25d685000000b00b8ec81d8d90sm2888837ybg.37.2023.04.11.12.21.43 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 11 Apr 2023 12:21:43 -0700 (PDT) From: Mark Yacoub X-Google-Original-From: Mark Yacoub To: David Airlie , Daniel Vetter Date: Tue, 11 Apr 2023 15:21:27 -0400 Message-Id: <20230411192134.508113-4-markyacoub@google.com> X-Mailer: git-send-email 2.40.0.577.gac1e443424-goog In-Reply-To: <20230411192134.508113-1-markyacoub@google.com> References: <20230411192134.508113-1-markyacoub@google.com> MIME-Version: 1.0 Subject: [Intel-gfx] [PATCH v9 03/10] drm/hdcp: Update property value on content type and user changes X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Jani Nikula , Mark Yacoub , intel-gfx@lists.freedesktop.org, dianders@chromium.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, seanpaul@chromium.org, Rodrigo Vivi , dmitry.baryshkov@linaro.org, freedreno@lists.freedesktop.org Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" From: Sean Paul Update 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). Acked-by: Jani Nikula Reviewed-by: Rodrigo Vivi Signed-off-by: Sean Paul Signed-off-by: Mark Yacoub --- Changes in v2: -None Changes in v3: -Fixed indentation issue identified by 0-day Changes in v4: -None Changes in v5: -None Changes in v6: -Rebased: modifications in drm_hdcp_helper.c instead of drm_hdcp.c Changes in v7: -Rebased as function name has changed. drivers/gpu/drm/display/drm_hdcp_helper.c | 29 +++++++++++++++-------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/drivers/gpu/drm/display/drm_hdcp_helper.c b/drivers/gpu/drm/display/drm_hdcp_helper.c index 34baf2b97cd87..3ee1a6ae26c53 100644 --- a/drivers/gpu/drm/display/drm_hdcp_helper.c +++ b/drivers/gpu/drm/display/drm_hdcp_helper.c @@ -480,21 +480,30 @@ bool drm_hdcp_has_changed(struct drm_connector *connector, return true; /* - * Nothing to do if content type is unchanged and one of: - * - state didn't change - * - HDCP was activated since the last commit - * - attempting to set to desired while already enabled + * Content type changes require an HDCP disable/enable cycle. */ - if (old_hdcp == new_hdcp || - (old_hdcp == DRM_MODE_CONTENT_PROTECTION_DESIRED && + 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 + */ + 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_has_changed); From patchwork Tue Apr 11 19:21:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Yacoub X-Patchwork-Id: 13208158 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 9D713C7619A for ; Tue, 11 Apr 2023 19:21:58 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 1465C10E642; Tue, 11 Apr 2023 19:21:51 +0000 (UTC) Received: from mail-yb1-xb2d.google.com (mail-yb1-xb2d.google.com [IPv6:2607:f8b0:4864:20::b2d]) by gabe.freedesktop.org (Postfix) with ESMTPS id 5A3D110E61D for ; Tue, 11 Apr 2023 19:21:48 +0000 (UTC) Received: by mail-yb1-xb2d.google.com with SMTP id q5so12199855ybk.7 for ; Tue, 11 Apr 2023 12:21:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1681240907; x=1683832907; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=eRpn68FgI1hY0kejzCxPGD1bOOlJ0s37GCU7vMBkaEw=; b=C940RjgcLxNrTvSdi5+dctGkLiHdDocSs7NqVbl8/zYahOEwNEgqxTTbJ2cLaln36d 74JG3fOqcll3VE+EJRd8jg6jOV0kWqTmtnXgzo4CUrggwmCZLTgP88vHGmBIOOc0V4od y+JOfjIbYdTrlKm1zJcgLyE1U4Z9wLDt8AU8Q= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1681240907; x=1683832907; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=eRpn68FgI1hY0kejzCxPGD1bOOlJ0s37GCU7vMBkaEw=; b=wiN2r3ouqTqy7mKh1YvJb1KfBZqhJdInAUnG8mJ7Nhm/Zo9nG/bADo/vxdJuykMdkc qJ6tGvbzBI3QDcFK4P/7loeDSNajBtT/haxTTnbMJCaemNXJwziPoy3Wc0gP8yJ1tFyU LR878gAcuhR6Z/KIg6kBRS8Cp/VcuEAabtAL+eZbeCYLMzxkW2sa3Mkch+Vz9xG7hUut DmZybp3aJmsmTQ+lj9j9QMZYP/le499MY3ChBOR23P1LeMO5pxvB9AecBb55Y+MhSfoK dnXvdsW5pqoQiemIsHrhTpvOrbqq8TboNKadyefNpGJdQu4u74a74gxzOFRAeFS0schN 9ZNg== X-Gm-Message-State: AAQBX9f6YyLb03H6zvwDTBfDpKpwBYwfSo01PjnIW7VtAlnJr/pMfu6/ MR/Lhdc01jlgU8UwkwIcbcFXiQ== X-Google-Smtp-Source: AKy350Y0/oB259pFlNDEhcscirsZpUk67cQGuNKH4AGLJrBvmW5AHq3SzWt2M613zyHLM/wQAy9cYQ== X-Received: by 2002:a25:b199:0:b0:afe:e13e:6379 with SMTP id h25-20020a25b199000000b00afee13e6379mr12771123ybj.13.1681240906886; Tue, 11 Apr 2023 12:21:46 -0700 (PDT) Received: from localhost ([2620:0:1035:15:2991:9b76:4e62:65bf]) by smtp.gmail.com with UTF8SMTPSA id x13-20020a056902138d00b00b8ed4e15acbsm2359272ybu.63.2023.04.11.12.21.45 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 11 Apr 2023 12:21:46 -0700 (PDT) From: Mark Yacoub X-Google-Original-From: Mark Yacoub To: David Airlie , Daniel Vetter Date: Tue, 11 Apr 2023 15:21:28 -0400 Message-Id: <20230411192134.508113-5-markyacoub@google.com> X-Mailer: git-send-email 2.40.0.577.gac1e443424-goog In-Reply-To: <20230411192134.508113-1-markyacoub@google.com> References: <20230411192134.508113-1-markyacoub@google.com> MIME-Version: 1.0 Subject: [Intel-gfx] [PATCH v9 04/10] drm/hdcp: Expand HDCP helper library for enable/disable/check X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Jani Nikula , Mark Yacoub , intel-gfx@lists.freedesktop.org, dianders@chromium.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, seanpaul@chromium.org, dmitry.baryshkov@linaro.org, freedreno@lists.freedesktop.org Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" From: Sean Paul Expand upon the HDCP helper library to manage HDCP enable, disable, and check. Previous to this patch, the majority of the state management and sink interaction is tucked inside the Intel driver with the understanding that once a new platform supported HDCP we could make good decisions about what should be centralized. With the addition of HDCP support for Qualcomm, it's time to migrate the protocol-specific bits of HDCP authentication, key exchange, and link checks to the HDCP helper. In terms of functionality, this migration is 1:1 with the Intel driver, however things are laid out a bit differently than with intel_hdcp.c, which is why this is a separate patch from the i915 transition to the helper. On i915, the shim vtable is used to account for HDMI vs. DP vs. DP-MST differences whereas the helper library uses a LUT to account for the register offsets and a remote read function to route the messages. On i915, storing the sink information in the source is done inline whereas now we use the new drm_hdcp_helper_funcs vtable to store and fetch information to/from source hw. Finally, instead of calling enable/disable directly from the driver, we'll leave that decision to the helper and by calling drm_hdcp_helper_atomic_commit() from the driver. All told, this will centralize the protocol and state handling in the helper, ensuring we collect all of our bugs^Wlogic in one place. Acked-by: Jani Nikula Signed-off-by: Sean Paul Signed-off-by: Mark Yacoub --- Changes in v2: -Fixed set-but-unused variable identified by 0-day Changes in v3: -Fixed uninitialized variable warning identified by 0-day Changes in v4: -None Changes in v5: -None Changes in v6: -Fixed typo in function descriptions -Rebased: Moved the new code between drm_hdcp.h and drm_hdcp_helper.c/h -Add missing headers. Reported-by: kernel test robot Changes in v7: - Add a |driver_data| field to some functions in drm_hdcp_helper_funcs that are called by the driver so drivers can pass anything they such as bridges - Isolate all non-common code between HDMI and DP into separate functions instead of manually checking for datra->aux Changes in v8 (suraj): -Try hdcp 1.x if hdcp2_capable returns an error instead of goto out. -set the enabled type to either 1 or 0 depending on the prop as hdcp2 can support either. Changes in v9: -Replace the drm_err by drm_dbg_kms -Assign data->enabled_type without if-statement -Moved display type specific func init into the drm helper drivers/gpu/drm/display/drm_hdcp_helper.c | 1136 +++++++++++++++++++++ include/drm/display/drm_hdcp.h | 296 ++++++ include/drm/display/drm_hdcp_helper.h | 22 +- 3 files changed, 1453 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/display/drm_hdcp_helper.c b/drivers/gpu/drm/display/drm_hdcp_helper.c index 3ee1a6ae26c53..9b62e476d21b4 100644 --- a/drivers/gpu/drm/display/drm_hdcp_helper.c +++ b/drivers/gpu/drm/display/drm_hdcp_helper.c @@ -6,13 +6,18 @@ * Ramalingam C */ +#include #include #include #include +#include +#include #include #include #include +#include +#include #include #include #include @@ -507,3 +512,1134 @@ bool drm_hdcp_has_changed(struct drm_connector *connector, return old_hdcp != new_hdcp; } EXPORT_SYMBOL(drm_hdcp_has_changed); + +struct drm_hdcp_hdcp1_receiver_reg_lut { + unsigned int bksv; + unsigned int ri; + unsigned int aksv; + unsigned int an; + unsigned int ainfo; + unsigned int v[5]; + unsigned int bcaps; + unsigned int bcaps_mask_repeater_present; + unsigned int bstatus; +}; + +static const struct drm_hdcp_hdcp1_receiver_reg_lut drm_hdcp_hdcp1_ddc_lut = { + .bksv = DRM_HDCP_DDC_BKSV, + .ri = DRM_HDCP_DDC_RI_PRIME, + .aksv = DRM_HDCP_DDC_AKSV, + .an = DRM_HDCP_DDC_AN, + .ainfo = DRM_HDCP_DDC_AINFO, + .v = { DRM_HDCP_DDC_V_PRIME(0), DRM_HDCP_DDC_V_PRIME(1), + DRM_HDCP_DDC_V_PRIME(2), DRM_HDCP_DDC_V_PRIME(3), + DRM_HDCP_DDC_V_PRIME(4) }, + .bcaps = DRM_HDCP_DDC_BCAPS, + .bcaps_mask_repeater_present = DRM_HDCP_DDC_BCAPS_REPEATER_PRESENT, + .bstatus = DRM_HDCP_DDC_BSTATUS, +}; + +static const struct drm_hdcp_hdcp1_receiver_reg_lut drm_hdcp_hdcp1_dpcd_lut = { + .bksv = DP_AUX_HDCP_BKSV, + .ri = DP_AUX_HDCP_RI_PRIME, + .aksv = DP_AUX_HDCP_AKSV, + .an = DP_AUX_HDCP_AN, + .ainfo = DP_AUX_HDCP_AINFO, + .v = { DP_AUX_HDCP_V_PRIME(0), DP_AUX_HDCP_V_PRIME(1), + DP_AUX_HDCP_V_PRIME(2), DP_AUX_HDCP_V_PRIME(3), + DP_AUX_HDCP_V_PRIME(4) }, + .bcaps = DP_AUX_HDCP_BCAPS, + .bcaps_mask_repeater_present = DP_BCAPS_REPEATER_PRESENT, + + /* + * For some reason the HDMI and DP HDCP specs call this register + * definition by different names. In the HDMI spec, it's called BSTATUS, + * but in DP it's called BINFO. + */ + .bstatus = DP_AUX_HDCP_BINFO, +}; + +static int drm_hdcp_remote_dpcd_read(struct drm_hdcp_helper_data *data, + unsigned int offset, u8 *value, size_t len) +{ + ssize_t ret; + struct drm_dp_aux *aux = data->aux; + + ret = drm_dp_dpcd_read(aux, offset, value, len); + if (ret != len) { + if (ret >= 0) + return -EIO; + return ret; + } + + return 0; +} + +static int drm_hdcp_remote_ddc_read(struct drm_hdcp_helper_data *data, + unsigned int offset, u8 *value, size_t len) +{ + int ret; + struct i2c_adapter *i2c = data->connector->ddc; + u8 start = offset & 0xff; + struct i2c_msg msgs[] = { { .addr = DRM_HDCP_DDC_ADDR, + .flags = 0, + .len = 1, + .buf = &start }, + { .addr = DRM_HDCP_DDC_ADDR, + .flags = I2C_M_RD, + .len = len, + .buf = value } }; + ret = i2c_transfer(i2c, msgs, ARRAY_SIZE(msgs)); + if (ret == ARRAY_SIZE(msgs)) + return 0; + return ret >= 0 ? -EIO : ret; +} + +static int drm_hdcp_remote_dpcd_write(struct drm_hdcp_helper_data *data, + unsigned int offset, u8 *value, + size_t len) +{ + ssize_t ret; + struct drm_dp_aux *aux = data->aux; + + ret = drm_dp_dpcd_write(aux, offset, value, len); + if (ret != len) { + if (ret >= 0) + return -EIO; + return ret; + } + + return 0; +} + +static int drm_hdcp_remote_ddc_write(struct drm_hdcp_helper_data *data, + unsigned int offset, u8 *buffer, + size_t len) +{ + int ret; + u8 *write_buf; + struct i2c_msg msg; + struct i2c_adapter *i2c = data->connector->ddc; + + write_buf = kzalloc(len + 1, GFP_KERNEL); + if (!write_buf) + return -ENOMEM; + + write_buf[0] = offset & 0xff; + memcpy(&write_buf[1], buffer, len); + + msg.addr = DRM_HDCP_DDC_ADDR; + msg.flags = 0, msg.len = len + 1, msg.buf = write_buf; + + ret = i2c_transfer(i2c, &msg, 1); + if (ret == 1) + ret = 0; + else if (ret >= 0) + ret = -EIO; + + kfree(write_buf); + return ret; +} + +static bool drm_hdcp_is_ksv_valid(struct drm_hdcp_ksv *ksv) +{ + /* Valid Ksv has 20 0's and 20 1's */ + return hweight32(ksv->words[0]) + hweight32(ksv->words[1]) == 20; +} + +static int drm_hdcp_read_valid_bksv(struct drm_hdcp_helper_data *data, + struct drm_hdcp_ksv *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 = data->display_type_funcs->remote_read( + data, data->hdcp1_lut->bksv, bksv->bytes, + DRM_HDCP_KSV_LEN); + if (ret) + return ret; + + if (drm_hdcp_is_ksv_valid(bksv)) + break; + } + if (i == tries) { + drm_dbg_kms(data->connector->dev, "Bksv is invalid %*ph\n", + DRM_HDCP_KSV_LEN, bksv->bytes); + return -ENODEV; + } + + return 0; +} + +int drm_hdcp_helper_hdcp1_capable_dp(struct drm_hdcp_helper_data *data, + bool *capable) +{ + int ret; + u8 bcaps; + + ret = data->display_type_funcs->remote_read( + data, data->hdcp1_lut->bcaps, &bcaps, 1); + *capable = !ret && (bcaps & DP_BCAPS_HDCP_CAPABLE); + + return 0; +} + +static int drm_hdcp_helper_hdcp1_capable_hdmi(struct drm_hdcp_helper_data *data, + bool *capable) +{ + struct drm_hdcp_ksv bksv; + *capable = drm_hdcp_read_valid_bksv(data, &bksv) == 0; + + return 0; +} + +static void drm_hdcp_update_value(struct drm_hdcp_helper_data *data, u64 value, + bool update_property) +{ + WARN_ON(!mutex_is_locked(&data->mutex)); + + data->value = value; + if (update_property) { + drm_connector_get(data->connector); + schedule_work(&data->prop_work); + } +} + +static int +drm_hdcp_helper_hdcp1_ksv_fifo_ready_dp(struct drm_hdcp_helper_data *data) +{ + u8 val; + u8 mask = DP_BSTATUS_READY; + int ret = drm_hdcp_remote_dpcd_read(data, DP_AUX_HDCP_BSTATUS, &val, 1); + + if (ret) + return ret; + if (val & mask) + return 0; + + return -EAGAIN; +} + +static int +drm_hdcp_helper_hdcp1_ksv_fifo_ready_hdmi(struct drm_hdcp_helper_data *data) +{ + u8 val; + u8 mask = DRM_HDCP_DDC_BCAPS_KSV_FIFO_READY; + int ret = drm_hdcp_remote_ddc_read(data, DRM_HDCP_DDC_BCAPS, &val, 1); + + if (ret) + return ret; + if (val & mask) + return 0; + + return -EAGAIN; +} + +static int +drm_hdcp_helper_hdcp1_read_ksv_fifo_dp(struct drm_hdcp_helper_data *data, + u8 *fifo, u8 num_downstream) +{ + struct drm_device *dev = data->connector->dev; + int i; + + for (i = 0; i < num_downstream; i += 3) { + size_t len = min(num_downstream - i, 3) * DRM_HDCP_KSV_LEN; + int ret = drm_hdcp_remote_dpcd_read(data, DP_AUX_HDCP_KSV_FIFO, + fifo + i * DRM_HDCP_KSV_LEN, + len); + if (ret) { + drm_err(dev, "Read ksv[%d] from DP/AUX failed (%d)\n", + i, ret); + return ret; + } + } + + return 0; +} + +static int +drm_hdcp_helper_hdcp1_read_ksv_fifo_hdmi(struct drm_hdcp_helper_data *data, + u8 *fifo, u8 num_downstream) +{ + struct drm_device *dev = data->connector->dev; + + int ret = drm_hdcp_remote_ddc_read(data, DRM_HDCP_DDC_KSV_FIFO, fifo, + num_downstream * DRM_HDCP_KSV_LEN); + if (ret) + drm_err(dev, "DDC ksv fifo read failed (%d)\n", ret); + return ret; +} + +static int drm_hdcp_helper_hdcp1_read_v_prime(struct drm_hdcp_helper_data *data, + u32 *v_prime) +{ + struct drm_device *dev = data->connector->dev; + int ret, i; + + for (i = 0; i < DRM_HDCP_V_PRIME_NUM_PARTS; i++) { + ret = data->display_type_funcs->remote_read( + data, data->hdcp1_lut->v[i], (u8 *)&v_prime[i], + DRM_HDCP_V_PRIME_PART_LEN); + if (ret) { + drm_dbg_kms(dev, "Read v'[%d] from failed (%d)\n", i, + ret); + return ret >= 0 ? -EIO : ret; + } + } + return 0; +} + +static int +drm_hdcp_helper_hdcp1_authenticate_downstream(struct drm_hdcp_helper_data *data) +{ + struct drm_connector *connector = data->connector; + struct drm_device *dev = connector->dev; + u32 v_prime[DRM_HDCP_V_PRIME_NUM_PARTS]; + u8 bstatus[DRM_HDCP_BSTATUS_LEN]; + u8 num_downstream, *ksv_fifo; + int ret, i, tries = 3; + + ret = read_poll_timeout(data->display_type_funcs->hdcp1_ksv_fifo_ready, + ret, !ret, 10 * 1000, 5 * 1000 * 1000, false, + data); + if (ret) { + drm_err(dev, "Failed to poll ksv ready, %d\n", ret); + return ret; + } + + ret = data->display_type_funcs->remote_read( + data, data->hdcp1_lut->bstatus, bstatus, DRM_HDCP_BSTATUS_LEN); + if (ret) + return ret; + + /* + * When repeater reports 0 device count, HDCP1.4 spec allows disabling + * the HDCP encryption. That implies that repeater can't have its own + * display. As there is no consumption of encrypted content in the + * repeater with 0 downstream devices, we are failing the + * authentication. + */ + num_downstream = DRM_HDCP_NUM_DOWNSTREAM(bstatus[0]); + if (num_downstream == 0) { + drm_err(dev, "Repeater with zero downstream devices, %*ph\n", + DRM_HDCP_BSTATUS_LEN, bstatus); + return -EINVAL; + } + + ksv_fifo = kcalloc(DRM_HDCP_KSV_LEN, num_downstream, GFP_KERNEL); + if (!ksv_fifo) + return -ENOMEM; + + ret = data->display_type_funcs->hdcp1_read_ksv_fifo(data, ksv_fifo, + num_downstream); + if (ret) { + drm_err(dev, "Failed to read ksv fifo, %d/%d\n", num_downstream, + ret); + goto out; + } + + if (drm_hdcp_check_ksvs_revoked(dev, ksv_fifo, num_downstream)) { + drm_err(dev, "Revoked Ksv(s) in ksv_fifo\n"); + ret = -EPERM; + goto out; + } + + /* + * When V prime mismatches, DP Spec mandates re-read of + * V prime at least twice. + */ + for (i = 0; i < tries; i++) { + ret = drm_hdcp_helper_hdcp1_read_v_prime(data, v_prime); + if (ret) + continue; + + ret = data->funcs->hdcp1_store_ksv_fifo(connector, ksv_fifo, + num_downstream, bstatus, + v_prime, + data->driver_data); + if (!ret) + break; + } + if (ret) + drm_err(dev, "Could not validate KSV FIFO with V' %d\n", ret); + +out: + if (!ret) + drm_dbg_kms(dev, "HDCP is enabled (%d downstream devices)\n", + num_downstream); + + kfree(ksv_fifo); + return ret; +} + +static int drm_hdcp_helper_hdcp1_validate_ri(struct drm_hdcp_helper_data *data) +{ + union { + u32 word; + u8 bytes[DRM_HDCP_RI_LEN]; + } ri_prime = { .word = 0 }; + struct drm_connector *connector = data->connector; + struct drm_device *dev = connector->dev; + int ret; + + ret = data->display_type_funcs->remote_read( + data, data->hdcp1_lut->ri, ri_prime.bytes, DRM_HDCP_RI_LEN); + if (ret) { + drm_err(dev, "Failed to read R0' %d\n", ret); + return ret; + } + + return data->funcs->hdcp1_match_ri(connector, ri_prime.word, + data->driver_data); +} + +static int drm_hdcp_helper_wait_r0_dp(struct drm_hdcp_helper_data *data, + unsigned long r0_prime_remaining_us) +{ + u8 val; + int ret = 0; + + ret = read_poll_timeout(drm_hdcp_remote_dpcd_read, ret, + !ret && (val & DP_BSTATUS_R0_PRIME_READY), 1000, + r0_prime_remaining_us, false, data, + DP_AUX_HDCP_BSTATUS, &val, 1); + return ret; +} + +static int drm_hdcp_helper_wait_r0_hdmi(struct drm_hdcp_helper_data *data, + unsigned long r0_prime_remaining_us) +{ + usleep_range(r0_prime_remaining_us, r0_prime_remaining_us + 1000); + return 0; +} + +static int drm_hdcp_helper_hdcp1_authenticate(struct drm_hdcp_helper_data *data) +{ + union { + u32 word; + u8 bytes[DRM_HDCP_BSTATUS_LEN]; + } bstatus; + const struct drm_hdcp_helper_funcs *funcs = data->funcs; + const struct drm_hdcp_helper_display_type_funcs *display_type_funcs = + data->display_type_funcs; + struct drm_connector *connector = data->connector; + struct drm_device *dev = connector->dev; + unsigned long r0_prime_timeout, r0_prime_remaining_us = 0, tmp_jiffies; + struct drm_hdcp_ksv aksv; + struct drm_hdcp_ksv bksv; + struct drm_hdcp_an an; + bool repeater_present; + int ret, i, tries = 3; + u8 bcaps; + + if (funcs->hdcp1_read_an_aksv) { + ret = funcs->hdcp1_read_an_aksv(connector, an.words, aksv.words, + data->driver_data); + if (ret) { + drm_err(dev, "Failed to read An/Aksv values, %d\n", + ret); + return ret; + } + + ret = display_type_funcs->remote_write( + data, data->hdcp1_lut->an, an.bytes, DRM_HDCP_AN_LEN); + if (ret) { + drm_err(dev, "Failed to write An to receiver, %d\n", + ret); + return ret; + } + + ret = display_type_funcs->remote_write(data, + data->hdcp1_lut->aksv, + aksv.bytes, + DRM_HDCP_KSV_LEN); + if (ret) { + drm_err(dev, "Failed to write Aksv to receiver, %d\n", + ret); + return ret; + } + } else { + ret = funcs->hdcp1_send_an_aksv(connector, data->driver_data); + if (ret) { + drm_err(dev, "Failed to read An/Aksv values, %d\n", + ret); + return ret; + } + } + + /* + * Timeout for R0' to become available. The spec says 100ms from Aksv, + * but some monitors can take longer than this. We'll set the timeout at + * 300ms just to be sure. + */ + r0_prime_timeout = jiffies + msecs_to_jiffies(300); + + memset(&bksv, 0, sizeof(bksv)); + + ret = drm_hdcp_read_valid_bksv(data, &bksv); + if (ret < 0) + return ret; + + if (drm_hdcp_check_ksvs_revoked(dev, bksv.bytes, 1)) { + drm_err(dev, "BKSV is revoked\n"); + return -EPERM; + } + + ret = display_type_funcs->remote_read(data, data->hdcp1_lut->bcaps, + &bcaps, 1); + if (ret) + return ret; + + memset(&bstatus, 0, sizeof(bstatus)); + + ret = display_type_funcs->remote_read(data, data->hdcp1_lut->bstatus, + bstatus.bytes, + DRM_HDCP_BSTATUS_LEN); + if (ret) + return ret; + + if (DRM_HDCP_MAX_DEVICE_EXCEEDED(bstatus.bytes[0]) || + DRM_HDCP_MAX_CASCADE_EXCEEDED(bstatus.bytes[1])) { + drm_err(dev, "Max Topology Limit Exceeded, bstatus=%*ph\n", + DRM_HDCP_BSTATUS_LEN, bstatus.bytes); + return -EPERM; + } + + repeater_present = bcaps & data->hdcp1_lut->bcaps_mask_repeater_present; + + ret = funcs->hdcp1_store_receiver_info(connector, bksv.words, + bstatus.word, bcaps, + repeater_present, + data->driver_data); + if (ret) { + drm_err(dev, "Failed to store bksv, %d\n", ret); + return ret; + } + + ret = funcs->hdcp1_enable_encryption(connector, data->driver_data); + if (ret) + return ret; + + ret = funcs->hdcp1_wait_for_r0(connector, data->driver_data); + if (ret) + return ret; + + tmp_jiffies = jiffies; + if (time_before(tmp_jiffies, r0_prime_timeout)) + r0_prime_remaining_us = + jiffies_to_usecs(r0_prime_timeout - tmp_jiffies); + + ret = display_type_funcs->wait_r0(data, r0_prime_remaining_us); + if (ret) { + drm_err(dev, "R0' did not become ready %d\n", ret); + return ret; + } + + /* + * DP HDCP Spec mandates the two more reattempt to read R0, in case + * of R0 mismatch. + */ + for (i = 0; i < tries; i++) { + ret = drm_hdcp_helper_hdcp1_validate_ri(data); + if (!ret) + break; + } + if (ret) { + drm_err(dev, "Failed to match R0/R0', aborting HDCP %d\n", ret); + return ret; + } + + if (repeater_present) + return drm_hdcp_helper_hdcp1_authenticate_downstream(data); + + drm_dbg_kms(dev, "HDCP is enabled (no repeater present)\n"); + return 0; +} + +static int drm_hdcp_helper_hdcp1_enable(struct drm_hdcp_helper_data *data) +{ + struct drm_connector *connector = data->connector; + struct drm_device *dev = connector->dev; + int i, ret, tries = 3; + + drm_dbg_kms(dev, "[%s:%d] HDCP is being enabled...\n", connector->name, + connector->base.id); + + /* In case of authentication failures, HDCP spec expects reauth. */ + for (i = 0; i < tries; i++) { + ret = drm_hdcp_helper_hdcp1_authenticate(data); + if (!ret) + return 0; + + drm_dbg_kms(dev, "HDCP Auth failure (%d)\n", ret); + + /* Ensuring HDCP encryption and signalling are stopped. */ + data->funcs->hdcp1_disable(data->connector, data->driver_data); + } + + drm_err(dev, "HDCP authentication failed (%d tries/%d)\n", tries, ret); + return ret; +} + +static inline void +drm_hdcp_helper_driver_lock(struct drm_hdcp_helper_data *data) +{ + if (data->driver_mutex) + mutex_lock(data->driver_mutex); +} + +static inline void +drm_hdcp_helper_driver_unlock(struct drm_hdcp_helper_data *data) +{ + if (data->driver_mutex) + mutex_unlock(data->driver_mutex); +} + +static int drm_hdcp_helper_enable_hdcp(struct drm_hdcp_helper_data *data, + struct drm_atomic_state *state, + struct mutex *driver_mutex) +{ + struct drm_connector *connector = data->connector; + struct drm_connector_state *conn_state; + struct drm_device *dev = connector->dev; + unsigned long check_link_interval = DRM_HDCP2_CHECK_PERIOD_MS; + bool capable; + int ret = 0; + + conn_state = drm_atomic_get_new_connector_state(state, connector); + + mutex_lock(&data->mutex); + + if (data->value == DRM_MODE_CONTENT_PROTECTION_ENABLED) { + drm_hdcp_update_value(data, DRM_MODE_CONTENT_PROTECTION_ENABLED, + true); + goto out_data_mutex; + } + + drm_WARN_ON(dev, data->driver_mutex != NULL); + data->driver_mutex = driver_mutex; + + drm_hdcp_helper_driver_lock(data); + + if (data->funcs->setup) { + ret = data->funcs->setup(connector, state, data->driver_data); + if (ret) { + drm_dbg_kms(dev, "Failed to setup HDCP %d\n", ret); + goto out; + } + } + + if (!data->funcs->are_keys_valid || + !data->funcs->are_keys_valid(connector, data->driver_data)) { + if (data->funcs->load_keys) { + ret = data->funcs->load_keys(connector, + data->driver_data); + if (ret) { + drm_err(dev, "Failed to load HDCP keys %d\n", + ret); + goto out; + } + } + } + + /* + * 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. + */ + ret = data->funcs->hdcp2_capable(connector, &capable, + data->driver_data); + if (ret) + drm_err(dev, "HDCP 2.x capability check failed %d\n", ret); + + if (!ret && capable) { + data->enabled_type = conn_state->content_type; + ret = data->funcs->hdcp2_enable(connector, data->driver_data); + if (!ret) { + check_link_interval = DRM_HDCP2_CHECK_PERIOD_MS; + goto out; + } + } + + /* + * When HDCP2.2 fails and Content Type is not Type1, HDCP1.4 will + * be attempted. + */ + ret = data->display_type_funcs->hdcp1_capable(data, &capable); + if (ret) { + drm_dbg_kms(dev, "HDCP 1.x capability check failed %d\n", ret); + goto out; + } + if (capable && + conn_state->content_type != DRM_MODE_HDCP_CONTENT_TYPE1) { + data->enabled_type = DRM_MODE_HDCP_CONTENT_TYPE0; + ret = drm_hdcp_helper_hdcp1_enable(data); + if (!ret) + check_link_interval = DRM_HDCP_CHECK_PERIOD_MS; + } + +out: + if (!ret) { + schedule_delayed_work(&data->check_work, check_link_interval); + drm_hdcp_update_value(data, DRM_MODE_CONTENT_PROTECTION_ENABLED, + true); + } + + drm_hdcp_helper_driver_unlock(data); + if (ret) + data->driver_mutex = NULL; + +out_data_mutex: + mutex_unlock(&data->mutex); + return ret; +} + +static int drm_hdcp_helper_disable_hdcp(struct drm_hdcp_helper_data *data) +{ + int ret = 0; + + mutex_lock(&data->mutex); + drm_hdcp_helper_driver_lock(data); + + if (data->value == DRM_MODE_CONTENT_PROTECTION_UNDESIRED) + goto out; + + drm_dbg_kms(data->connector->dev, "[%s:%d] HDCP is being disabled...\n", + data->connector->name, data->connector->base.id); + + drm_hdcp_update_value(data, DRM_MODE_CONTENT_PROTECTION_UNDESIRED, + true); + + if (data->enabled_type == DRM_MODE_HDCP_CONTENT_TYPE1) + ret = data->funcs->hdcp2_disable(data->connector, + data->driver_data); + else + ret = data->funcs->hdcp1_disable(data->connector, + data->driver_data); + + drm_dbg_kms(data->connector->dev, "HDCP is disabled\n"); + +out: + drm_hdcp_helper_driver_unlock(data); + data->driver_mutex = NULL; + mutex_unlock(&data->mutex); + cancel_delayed_work_sync(&data->check_work); + return ret; +} + +/** + * drm_hdcp_helper_atomic_commit - Helper for drivers to call during commit to + * enable/disable HDCP + * + * @data: pointer to the @drm_hdcp_helper_data for the connector + * @state: pointer to the atomic state being committed + * @driver_mutex: driver-provided lock to be used while interacting with the driver + * + * This function can be used by display drivers to determine when HDCP should be + * enabled or disabled based on the connector state. It should be called during + * steady-state commits as well as connector enable/disable. The function will + * handle the HDCP authentication/encryption logic, calling back into the driver + * when source operations are necessary. + * + * @driver_mutex will be retained and used for the duration of the HDCP session + * since it will be needed for link checks and retries. This mutex is useful if + * the driver has shared resources across connectors which must be serialized. + * For example, driver_mutex can be used for MST connectors sharing a common + * encoder which should not be accessed/changed concurrently. When the + * connector's session is torn down, the mutex will be forgotten by the helper + * for this connector until the next session. + */ +void drm_hdcp_helper_atomic_commit(struct drm_hdcp_helper_data *data, + struct drm_atomic_state *state, + struct mutex *driver_mutex) +{ + struct drm_connector *connector = data->connector; + struct drm_connector_state *conn_state; + bool type_changed; + + conn_state = drm_atomic_get_new_connector_state(state, connector); + if (!conn_state) + return; + + type_changed = conn_state->hdcp_content_type != data->enabled_type; + + if (conn_state->content_protection == + DRM_MODE_CONTENT_PROTECTION_UNDESIRED) { + drm_hdcp_helper_disable_hdcp(data); + return; + } + + if (!conn_state->crtc) { + drm_hdcp_helper_disable_hdcp(data); + + /* Restore property to DESIRED so it's retried later */ + if (conn_state->content_protection == + DRM_MODE_CONTENT_PROTECTION_ENABLED) { + mutex_lock(&data->mutex); + drm_hdcp_update_value( + data, DRM_MODE_CONTENT_PROTECTION_DESIRED, + true); + mutex_unlock(&data->mutex); + } + return; + } + + /* Already enabled */ + if (conn_state->content_protection == + DRM_MODE_CONTENT_PROTECTION_ENABLED) + return; + + /* Disable and re-enable HDCP on content type change */ + if (type_changed) + drm_hdcp_helper_disable_hdcp(data); + + drm_hdcp_helper_enable_hdcp(data, state, driver_mutex); +} +EXPORT_SYMBOL(drm_hdcp_helper_atomic_commit); + +static void drm_hdcp_helper_prop_work(struct work_struct *work) +{ + struct drm_hdcp_helper_data *data = + container_of(work, struct drm_hdcp_helper_data, prop_work); + struct drm_connector *connector = data->connector; + struct drm_device *dev = connector->dev; + + drm_modeset_lock(&dev->mode_config.connection_mutex, NULL); + mutex_lock(&data->mutex); + + /* + * This worker is only used to flip between ENABLED/DESIRED. Either of + * those to UNDESIRED is handled by core. If value == UNDESIRED, + * we're running just after hdcp has been disabled, so just exit + */ + if (data->value != DRM_MODE_CONTENT_PROTECTION_UNDESIRED) + drm_hdcp_update_content_protection(connector, data->value); + + mutex_unlock(&data->mutex); + drm_modeset_unlock(&dev->mode_config.connection_mutex); +} + +/* + * Check the link registers for HDCP 1.x for DP. + */ +int drm_hdcp_hdcp1_check_link_registers_dp(struct drm_device *dev, + struct drm_hdcp_helper_data *data, + bool *shoud_retry) +{ + u8 bstatus; + int ret = drm_hdcp_remote_dpcd_read(data, DP_AUX_HDCP_BSTATUS, &bstatus, + 1); + *shoud_retry = true; + + if (ret) { + *shoud_retry = false; + drm_err(dev, "Failed to read dpcd bstatus, %d\n", ret); + return ret; + } + if (bstatus & (DP_BSTATUS_LINK_FAILURE | DP_BSTATUS_REAUTH_REQ)) + return -EINVAL; + + return 0; +} +EXPORT_SYMBOL(drm_hdcp_hdcp1_check_link_registers_dp); + +static int +drm_hdcp_hdcp1_check_link_registers_hdmi(struct drm_device *dev, + struct drm_hdcp_helper_data *data, + bool *shoud_retry) +{ + int ret = drm_hdcp_helper_hdcp1_validate_ri(data); + *shoud_retry = true; + + if (ret) + drm_err(dev, "Ri' mismatch, check failed (%d)\n", ret); + + return ret; +} + +static int drm_hdcp_hdcp1_check_link(struct drm_hdcp_helper_data *data) +{ + struct drm_connector *connector = data->connector; + struct drm_device *dev = connector->dev; + int ret; + bool should_retry = false; + + if (data->funcs->hdcp1_check_link) { + ret = data->funcs->hdcp1_check_link(connector, + data->driver_data); + if (ret) + goto retry; + } + + ret = data->display_type_funcs->hdcp1_check_link_registers( + connector->dev, data, &should_retry); + if (!ret) + return 0; + else if (!should_retry) + return ret; + +retry: + drm_err(dev, "[%s:%d] HDCP link failed, retrying authentication\n", + connector->name, connector->base.id); + + ret = data->funcs->hdcp1_disable(connector, data->driver_data); + if (ret) { + drm_err(dev, "Failed to disable hdcp (%d)\n", ret); + drm_hdcp_update_value(data, DRM_MODE_CONTENT_PROTECTION_DESIRED, + true); + return ret; + } + + ret = drm_hdcp_helper_hdcp1_enable(data); + if (ret) { + drm_err(dev, "Failed to enable hdcp (%d)\n", ret); + drm_hdcp_update_value(data, DRM_MODE_CONTENT_PROTECTION_DESIRED, + true); + return ret; + } + + return 0; +} + +static int drm_hdcp_hdcp2_check_link(struct drm_hdcp_helper_data *data) +{ + struct drm_connector *connector = data->connector; + struct drm_device *dev = connector->dev; + int ret; + + ret = data->funcs->hdcp2_check_link(connector, data->driver_data); + if (!ret) + return 0; + + drm_err(dev, "[%s:%d] HDCP2 link failed, retrying authentication\n", + connector->name, connector->base.id); + + ret = data->funcs->hdcp2_disable(connector, data->driver_data); + if (ret) { + drm_err(dev, "Failed to disable hdcp2 (%d)\n", ret); + drm_hdcp_update_value(data, DRM_MODE_CONTENT_PROTECTION_DESIRED, + true); + return ret; + } + + ret = data->funcs->hdcp2_enable(connector, data->driver_data); + if (ret) { + drm_err(dev, "Failed to enable hdcp2 (%d)\n", ret); + drm_hdcp_update_value(data, DRM_MODE_CONTENT_PROTECTION_DESIRED, + true); + return ret; + } + + return 0; +} + +static void drm_hdcp_helper_check_work(struct work_struct *work) +{ + struct drm_hdcp_helper_data *data = container_of( + to_delayed_work(work), struct drm_hdcp_helper_data, check_work); + unsigned long check_link_interval; + + mutex_lock(&data->mutex); + if (data->value != DRM_MODE_CONTENT_PROTECTION_ENABLED) + goto out_data_mutex; + + drm_hdcp_helper_driver_lock(data); + + if (data->enabled_type == DRM_MODE_HDCP_CONTENT_TYPE1) { + if (drm_hdcp_hdcp2_check_link(data)) + goto out; + check_link_interval = DRM_HDCP2_CHECK_PERIOD_MS; + } else { + if (drm_hdcp_hdcp1_check_link(data)) + goto out; + check_link_interval = DRM_HDCP_CHECK_PERIOD_MS; + } + schedule_delayed_work(&data->check_work, check_link_interval); + +out: + drm_hdcp_helper_driver_unlock(data); +out_data_mutex: + mutex_unlock(&data->mutex); +} + +static const struct drm_hdcp_helper_display_type_funcs dp_hdcp_helper_funcs = { + .remote_read = drm_hdcp_remote_dpcd_read, + .remote_write = drm_hdcp_remote_dpcd_write, + .hdcp1_capable = drm_hdcp_helper_hdcp1_capable_dp, + .hdcp1_ksv_fifo_ready = drm_hdcp_helper_hdcp1_ksv_fifo_ready_dp, + .wait_r0 = drm_hdcp_helper_wait_r0_dp, + .hdcp1_check_link_registers = drm_hdcp_hdcp1_check_link_registers_dp, + .hdcp1_read_ksv_fifo = drm_hdcp_helper_hdcp1_read_ksv_fifo_dp +}; + +static const struct drm_hdcp_helper_display_type_funcs hdmi_hdcp_helper_funcs = { + .remote_read = drm_hdcp_remote_ddc_read, + .remote_write = drm_hdcp_remote_ddc_write, + .hdcp1_capable = drm_hdcp_helper_hdcp1_capable_hdmi, + .hdcp1_ksv_fifo_ready = drm_hdcp_helper_hdcp1_ksv_fifo_ready_hdmi, + .wait_r0 = drm_hdcp_helper_wait_r0_hdmi, + .hdcp1_check_link_registers = drm_hdcp_hdcp1_check_link_registers_hdmi, + .hdcp1_read_ksv_fifo = drm_hdcp_helper_hdcp1_read_ksv_fifo_hdmi, +}; + +/** + * drm_hdcp_helper_schedule_hdcp_check - Schedule a check link cycle. + * + * @data: Pointer to the HDCP helper data. + * + * This function will kick off a check link cycle on behalf of the caller. This + * can be used by DP short hpd interrupt handlers, where the driver must poke + * the helper to check the link is still valid. + */ +void drm_hdcp_helper_schedule_hdcp_check(struct drm_hdcp_helper_data *data) +{ + schedule_delayed_work(&data->check_work, 0); +} +EXPORT_SYMBOL(drm_hdcp_helper_schedule_hdcp_check); + +static struct drm_hdcp_helper_data * +drm_hdcp_helper_initialize(struct drm_connector *connector, + const struct drm_hdcp_helper_funcs *funcs, + bool hdcp_content_type) +{ + struct drm_hdcp_helper_data *out; + int ret; + + out = kzalloc(sizeof(*out), GFP_KERNEL); + if (!out) + return ERR_PTR(-ENOMEM); + + out->connector = connector; + out->funcs = funcs; + + mutex_init(&out->mutex); + out->value = DRM_MODE_CONTENT_PROTECTION_UNDESIRED; + + INIT_DELAYED_WORK(&out->check_work, drm_hdcp_helper_check_work); + INIT_WORK(&out->prop_work, drm_hdcp_helper_prop_work); + + ret = drm_connector_attach_content_protection_property( + connector, hdcp_content_type); + if (ret) { + drm_hdcp_helper_destroy(out); + return ERR_PTR(ret); + } + + return out; +} + +/** + * drm_hdcp_helper_initialize_dp - Initializes the HDCP helpers for a + * DisplayPort connector + * + * @connector: pointer to the DisplayPort connector. + * @aux: pointer to the DisplayPort AUX channel. + * @funcs: pointer to the vtable of HDCP helper funcs for this connector. + * @hdcp_content_type: True if the content_type property should be attached. + * + * This function initializes the HDCP helper for the given DisplayPort connector. + * This involves creating the Content Protection property as well as the Content + * Type property (if desired). Upon success, it will return a pointer to the + * HDCP helper data. Ownership of the underlying memory is ttransferredto the + * caller and should be freed using drm_hdcp_helper_destroy(). + * + * Returns: + * Pointer to newly created HDCP helper data. PTR_ERR on failure. + */ +struct drm_hdcp_helper_data *drm_hdcp_helper_initialize_dp( + struct drm_connector *connector, struct drm_dp_aux *aux, + const struct drm_hdcp_helper_funcs *funcs, bool hdcp_content_type) +{ + struct drm_hdcp_helper_data *out; + + out = drm_hdcp_helper_initialize(connector, funcs, hdcp_content_type); + if (IS_ERR(out)) + return out; + + out->display_type_funcs = &dp_hdcp_helper_funcs; + out->aux = aux; + out->hdcp1_lut = &drm_hdcp_hdcp1_dpcd_lut; + + return out; +} +EXPORT_SYMBOL(drm_hdcp_helper_initialize_dp); + +/** + * drm_hdcp_helper_initialize_hdmi - Initializes the HDCP helpers for an HDMI + * connector + * + * @connector: pointer to the HDMI connector. + * @funcs: pointer to the vtable of HDCP helper funcs for this connector. + * @hdcp_content_type: True if the content_type property should be attached. + * + * This function initializes the HDCP helper for the given HDMI connector. This + * involves creating the Content Protection property as well as the Content Type + * property (if desired). Upon success, it will return a pointer to the HDCP + * helper data. Ownership of the underlying memory is transferred to the caller + * and should be freed using drm_hdcp_helper_destroy(). + * + * Returns: + * Pointer to newly created HDCP helper data. PTR_ERR on failure. + */ +struct drm_hdcp_helper_data * +drm_hdcp_helper_initialize_hdmi(struct drm_connector *connector, + const struct drm_hdcp_helper_funcs *funcs, + bool hdcp_content_type) +{ + struct drm_hdcp_helper_data *out; + + out = drm_hdcp_helper_initialize(connector, funcs, hdcp_content_type); + if (IS_ERR(out)) + return out; + + out->display_type_funcs = &hdmi_hdcp_helper_funcs; + out->hdcp1_lut = &drm_hdcp_hdcp1_ddc_lut; + + return out; +} +EXPORT_SYMBOL(drm_hdcp_helper_initialize_hdmi); + +/** + * drm_hdcp_helper_destroy - Destroys the given HDCP helper data. + * + * @data: Pointer to the HDCP helper data. + * + * This function cleans up and destroys the HDCP helper data created by + * drm_hdcp_helper_initialize_dp() or drm_hdcp_helper_initialize_hdmi(). + */ +void drm_hdcp_helper_destroy(struct drm_hdcp_helper_data *data) +{ + struct drm_connector *connector; + + if (!data) + return; + + connector = data->connector; + + /* + * If the connector is registered, it's possible userspace could kick + * off another HDCP enable, which would re-spawn the workers. + */ + drm_WARN_ON(connector->dev, + connector->registration_state == DRM_CONNECTOR_REGISTERED); + + /* + * Now that the connector is not registered, check_work won't be run, + * but cancel any outstanding instances of it + */ + cancel_delayed_work_sync(&data->check_work); + + /* + * We don't cancel prop_work in the same way as check_work since it + * requires connection_mutex which could be held while calling this + * function. Instead, we rely on the connector references grabbed before + * scheduling prop_work to ensure the connector is alive when prop_work + * is run. So if we're in the destroy path (which is where this + * function should be called), we're "guaranteed" that prop_work is not + * active (tl;dr This Should Never Happen). + */ + drm_WARN_ON(connector->dev, work_pending(&data->prop_work)); + + kfree(data); +} +EXPORT_SYMBOL(drm_hdcp_helper_destroy); diff --git a/include/drm/display/drm_hdcp.h b/include/drm/display/drm_hdcp.h index 96a99b1377c0e..15af800b6d2b8 100644 --- a/include/drm/display/drm_hdcp.h +++ b/include/drm/display/drm_hdcp.h @@ -9,8 +9,12 @@ #ifndef _DRM_HDCP_H_ #define _DRM_HDCP_H_ +#include "linux/mutex.h" +#include "linux/workqueue.h" #include +#include + /* Period of hdcp checks (to ensure we're still authenticated) */ #define DRM_HDCP_CHECK_PERIOD_MS (128 * 16) #define DRM_HDCP2_CHECK_PERIOD_MS 500 @@ -36,6 +40,7 @@ #define DRM_HDCP_DDC_BKSV 0x00 #define DRM_HDCP_DDC_RI_PRIME 0x08 #define DRM_HDCP_DDC_AKSV 0x10 +#define DRM_HDCP_DDC_AINFO 0x15 #define DRM_HDCP_DDC_AN 0x18 #define DRM_HDCP_DDC_V_PRIME(h) (0x20 + h * 4) #define DRM_HDCP_DDC_BCAPS 0x40 @@ -123,6 +128,19 @@ #define HDCP_2_2_DEV_COUNT_HI(x) ((x) & BIT(0)) #define HDCP_2_2_DEPTH(x) (((x) & (0x7 << 1)) >> 1) +struct drm_hdcp_ksv { + union { + u32 words[2]; + u8 bytes[DRM_HDCP_KSV_LEN]; + }; +}; +struct drm_hdcp_an { + union { + u32 words[2]; + u8 bytes[DRM_HDCP_AN_LEN]; + }; +}; + struct hdcp2_cert_rx { u8 receiver_id[HDCP_2_2_RECEIVER_ID_LEN]; u8 kpub_rx[HDCP_2_2_K_PUB_RX_LEN]; @@ -295,4 +313,282 @@ struct hdcp_srm_header { #define DRM_MODE_HDCP_CONTENT_TYPE0 0 #define DRM_MODE_HDCP_CONTENT_TYPE1 1 +struct drm_connector; +struct drm_atomic_state; + +struct drm_hdcp_helper_data { + struct mutex mutex; + struct mutex *driver_mutex; + + struct drm_connector *connector; + const struct drm_hdcp_helper_funcs *funcs; + const struct drm_hdcp_helper_display_type_funcs *display_type_funcs; + + u64 value; + unsigned int enabled_type; + + struct delayed_work check_work; + struct work_struct prop_work; + + struct drm_dp_aux *aux; + const struct drm_hdcp_hdcp1_receiver_reg_lut *hdcp1_lut; + + void *driver_data; +}; + +/** + * struct drm_hdcp_helper_funcs - A vtable of function hooks for the hdcp helper + * + * These hooks are used by the hdcp helper to call into the driver/connector + * code to read/write to hw. + */ +struct drm_hdcp_helper_funcs { + /** + * @setup - Performs driver-specific setup before hdcp is enabled + * + * Returns: 0 on success, -errno on failure + */ + int (*setup)(struct drm_connector *connector, + struct drm_atomic_state *state, void *driver_data); + + /** + * @are_keys_valid - Checks if the HDCP transmitter keys are valid + * + * Returns: true if the display controller has valid keys loaded + */ + bool (*are_keys_valid)(struct drm_connector *connector, + void *driver_data); + + /** + * @load_keys - Instructs the driver to load its HDCP transmitter keys + * + * Returns: 0 on success, -errno on failure + */ + int (*load_keys)(struct drm_connector *connector, void *driver_data); + + /** + * @hdcp2_capable - Checks if both source and sink support HDCP 2.x + * + * Returns: 0 on success, -errno on failure + */ + int (*hdcp2_capable)(struct drm_connector *connector, bool *capable, + void *driver_data); + + /** + * @hdcp2_enable - Enables HDCP 2.x on the specified connector + * + * Since we don't have multiple examples of HDCP 2.x enablement, we + * provide the bare minimum support for HDCP 2.x help. Once we have + * more examples, perhaps we can be more helpful. + * + * Returns: 0 on success, -errno on failure + */ + int (*hdcp2_enable)(struct drm_connector *connector, void *driver_data); + + /** + * @hdcp2_check_link - Checks the HDCP 2.x link on a specified connector + * + * Returns: 0 on success, -errno on failure + */ + int (*hdcp2_check_link)(struct drm_connector *connector, + void *driver_data); + + /** + * @hdcp2_disable - Disables HDCP 2.x on the specified connector + * + * Returns: 0 on success, -errno on failure + */ + int (*hdcp2_disable)(struct drm_connector *connector, + void *driver_data); + + /** + * @hdcp1_read_an_aksv - Reads transmitter's An & Aksv from hardware + * + * Use this function if hardware allows reading the transmitter's An and + * Aksv values from the kernel. If your hardware will not allow this, + * use hdcp1_send_an_aksv() and implement the transmission in the + * driver. + * + * Returns: 0 on success, -errno on failure + */ + int (*hdcp1_read_an_aksv)(struct drm_connector *connector, u32 *an, + u32 *aksv, void *driver_data); + + /** + * @hdcp1_send_an_aksv - Sends transmitter's An & Aksv to the receiver + * + * Only implement this on hardware where An or Aksv are not accessible + * from the kernel. If these values can be read, use + * hdcp1_read_an_aksv() instead. + * + * Returns: 0 on success, -errno on failure + */ + int (*hdcp1_send_an_aksv)(struct drm_connector *connector, + void *driver_data); + + /** + * @hdcp1_store_receiver_info - Stores the receiver's info in the transmitter + * + * Returns: 0 on success, -errno on failure + */ + int (*hdcp1_store_receiver_info)(struct drm_connector *connector, + u32 *ksv, u32 status, u8 caps, + bool repeater_present, + void *driver_data); + + /** + * @hdcp1_enable_encryption - Enables encryption of the outgoing signal + * + * Returns: 0 on success, -errno on failure + */ + int (*hdcp1_enable_encryption)(struct drm_connector *connector, + void *driver_data); + + /** + * @hdcp1_wait_for_r0 - Wait for transmitter to calculate R0 + * + * Returns: 0 on success, -errno on failure + */ + int (*hdcp1_wait_for_r0)(struct drm_connector *connector, + void *driver_data); + + /** + * @hdcp1_match_ri - Matches the given Ri from the receiver with Ri in + * the transmitter + * + * Returns: 0 on success, -errno on failure + */ + int (*hdcp1_match_ri)(struct drm_connector *connector, u32 ri_prime, + void *driver_data); + + /** + * @hdcp1_post_encryption - Allows the driver to confirm encryption and + * perform any post-processing + * + * Returns: 0 on success, -errno on failure + */ + int (*hdcp1_post_encryption)(struct drm_connector *connector, + void *driver_data); + + /** + * @hdcp1_store_ksv_fifo - Write the receiver's KSV list to transmitter + * + * Returns: 0 on success, -errno on failure + */ + int (*hdcp1_store_ksv_fifo)(struct drm_connector *connector, + u8 *ksv_fifo, u8 num_downstream, + u8 *bstatus, u32 *vprime, + void *driver_data); + + /** + * @hdcp1_check_link - Allows the driver to check the HDCP 1.x status + * on a specified connector + * + * Returns: 0 on success, -errno on failure + */ + int (*hdcp1_check_link)(struct drm_connector *connector, + void *driver_data); + + /** + * @hdcp1_disable - Disables HDCP 1.x on the specified connector + * + * Returns: 0 on success, -errno on failure + */ + int (*hdcp1_disable)(struct drm_connector *connector, + void *driver_data); +}; + +/** + * struct drm_hdcp_helper_display_type_funcs - A vtable of function hooks for the + * HDCP that is unique to a display type (e.g. DP, HDMI, etc.) + * + * The driver doesn't have to initialize this, it's being taken care of in init. + */ +struct drm_hdcp_helper_display_type_funcs { + /** + * @remote_read - Read HDCP keys from the remote HDCP engine + + * @data: drm_hdcp_helper_data containing the adapter + * @offset: address of the register to read + * @value: Pointer to the value to be filled + * @len: The length of the data to be read + * + * Return 0 on success + */ + int (*remote_read)(struct drm_hdcp_helper_data *data, + unsigned int offset, u8 *value, size_t len); + + /** + * @remote_write - Write HDCP keys to the remote HDCP engine + + * @data: drm_hdcp_helper_data containing the adapter + * @offset: address of the register to read + * @value: Pointer to the value to be filled + * @len: The length of the data to be read + * + * Return 0 on success + */ + int (*remote_write)(struct drm_hdcp_helper_data *data, + unsigned int offset, u8 *value, size_t len); + + /** + * @hdcp1_capable - Checks if the sink is capable of HDCP 1.x. + * + * @data: pointer to the HDCP helper data. + * @capable: pointer to a bool which will contain true if the sink is capable. + * + * Returns: + * -errno if the transacation between source and sink fails. + */ + int (*hdcp1_capable)(struct drm_hdcp_helper_data *data, bool *capable); + + /** + * @hdcp1_ksv_fifo_ready - Read KSV FIFO ready bit. + * + * @data: pointer to the HDCP helper data. + * + * Returns: + * -errno if the transacation between source and sink fails. + * 0 on success. + * -EAGAIN otherwise. + */ + int (*hdcp1_ksv_fifo_ready)(struct drm_hdcp_helper_data *data); + + /** + * @wait_r0 - Wait for R0' to become available. + * + * @data: pointer to the HDCP helper data. + * @r0_prime_remaining_us: time remaining for R0' to become available. + * + * Returns 0 on success. + */ + int (*wait_r0)(struct drm_hdcp_helper_data *data, + unsigned long r0_prime_remaining_us); + + /* + * @hdcp1_check_link_registers - This function checks the HDCP1 + * link registers and returns true if the link is valid and false otherwise. + * + * @dev: DRM device for printing error messages + * @data: HDCP helper data + * @should_retry: if true, the caller will retry checking the registers + * + * Returns 0 on success. + */ + int (*hdcp1_check_link_registers)(struct drm_device *dev, + struct drm_hdcp_helper_data *data, + bool *shoud_retry); + + /** + * @hdcp1_read_ksv_fifo - Read HDCP1.x KSV FIFO + * @data: Helper data + * @fifo: Buffer to store values + * @num_downstream: Number of downstream devices + * + * Return: Zero on success or negative error code on failure. + */ + int (*hdcp1_read_ksv_fifo)(struct drm_hdcp_helper_data *data, u8 *fifo, + u8 num_downstream); +}; + #endif diff --git a/include/drm/display/drm_hdcp_helper.h b/include/drm/display/drm_hdcp_helper.h index 703421fcdf96c..ad574f8c6e8e0 100644 --- a/include/drm/display/drm_hdcp_helper.h +++ b/include/drm/display/drm_hdcp_helper.h @@ -15,11 +15,31 @@ struct drm_atomic_state; struct drm_device; struct drm_connector; +struct drm_hdcp_helper_data; +struct drm_dp_aux; +struct i2c_adapter; +struct mutex; + int drm_hdcp_check_ksvs_revoked(struct drm_device *dev, u8 *ksvs, u32 ksv_count); int drm_connector_attach_content_protection_property(struct drm_connector *connector, bool hdcp_content_type); void drm_hdcp_update_content_protection(struct drm_connector *connector, u64 val); bool drm_hdcp_has_changed(struct drm_connector *connector, - struct drm_atomic_state *state); + struct drm_atomic_state *state); + +void drm_hdcp_helper_atomic_commit(struct drm_hdcp_helper_data *data, + struct drm_atomic_state *state, + struct mutex *driver_mutex); + +void drm_hdcp_helper_schedule_hdcp_check(struct drm_hdcp_helper_data *data); + +struct drm_hdcp_helper_data *drm_hdcp_helper_initialize_dp( + struct drm_connector *connector, struct drm_dp_aux *aux, + const struct drm_hdcp_helper_funcs *funcs, bool hdcp_content_type); +struct drm_hdcp_helper_data * +drm_hdcp_helper_initialize_hdmi(struct drm_connector *connector, + const struct drm_hdcp_helper_funcs *funcs, + bool hdcp_content_type); +void drm_hdcp_helper_destroy(struct drm_hdcp_helper_data *data); #endif From patchwork Tue Apr 11 19:21:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Yacoub X-Patchwork-Id: 13208159 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 12C87C77B75 for ; Tue, 11 Apr 2023 19:22:03 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 2DDD810E64C; Tue, 11 Apr 2023 19:21:53 +0000 (UTC) Received: from mail-yb1-xb33.google.com (mail-yb1-xb33.google.com [IPv6:2607:f8b0:4864:20::b33]) by gabe.freedesktop.org (Postfix) with ESMTPS id 5C18310E642 for ; Tue, 11 Apr 2023 19:21:50 +0000 (UTC) Received: by mail-yb1-xb33.google.com with SMTP id e127so9362638ybf.8 for ; Tue, 11 Apr 2023 12:21:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1681240909; x=1683832909; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=fK7kJoAVmrfbc0th2W+DXCykp+0RZfhoVtxEFpE2/s8=; b=Ri93NLxAlikAO17pHOq5fp8DZ670310ThBxsxobK+tkw5T2muPpqnCOWgLaaEuTbTe WSxoPatm9qhJan/CBHiLMpHye3Snn2fjehhgL/cMwJApKiZCw0MWfPM8Bwvh3FU35ltE IiUHVv8Kayl6ke7jCcmaQlI0QVsQN5x5UpqZI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1681240909; x=1683832909; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=fK7kJoAVmrfbc0th2W+DXCykp+0RZfhoVtxEFpE2/s8=; b=lbTdC56gRs9DYVlxdGPsDHvOgpBRAGv18SpseIMQELSe1HBd35GxQWvtTkytcuruRg 8eDReQc7MUckqtHJcz5Ab2zjjhtBGJ6hQYzWD93dB42RoMll6tRnyEqH34rqQvlVec2K G68cXKvFVv6xH34wJTCbtVhlRphsG6lz5Xo6gZfzJ+gnJt7fmKuCmw12iuK90yjtmEMc slTbVXXpLrIRdpMoanMyhyvcgR00y6lkXUH/q9kmu34Elk1ZazxdC3WYC6kxsFT/e0lq 6ZsuC8sT6EAEYFZ6KCn+flVuVaTP4zFF8rMBHJibHlaei69R7ZX0lU4PM23DzCtRkEKK RmdA== X-Gm-Message-State: AAQBX9f09qtYMKWIsZsOUKjbEY3vaFtXZkoUzDYrTwE02tqpNPXw+xmj Cp852+3Fsnh4d+BggXP89+njKw== X-Google-Smtp-Source: AKy350a+IH+whfG6A/JcjJpGfASQTm7HlLPVSpckZE07tztF/zgLvBN/SBJticsRyVzsaQKMZtrZYw== X-Received: by 2002:a25:6808:0:b0:b8e:d4e2:a122 with SMTP id d8-20020a256808000000b00b8ed4e2a122mr8764716ybc.35.1681240909145; Tue, 11 Apr 2023 12:21:49 -0700 (PDT) Received: from localhost ([2620:0:1035:15:2991:9b76:4e62:65bf]) by smtp.gmail.com with UTF8SMTPSA id e73-20020a25374c000000b00b7767ca7476sm3871816yba.19.2023.04.11.12.21.48 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 11 Apr 2023 12:21:48 -0700 (PDT) From: Mark Yacoub X-Google-Original-From: Mark Yacoub To: Jani Nikula , Joonas Lahtinen , Rodrigo Vivi , Tvrtko Ursulin , David Airlie , Daniel Vetter Date: Tue, 11 Apr 2023 15:21:29 -0400 Message-Id: <20230411192134.508113-6-markyacoub@google.com> X-Mailer: git-send-email 2.40.0.577.gac1e443424-goog In-Reply-To: <20230411192134.508113-1-markyacoub@google.com> References: <20230411192134.508113-1-markyacoub@google.com> MIME-Version: 1.0 Subject: [Intel-gfx] [PATCH v9 05/10] drm/i915/hdcp: Consolidate HDCP setup/state cache X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Jani Nikula , intel-gfx@lists.freedesktop.org, dianders@chromium.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, seanpaul@chromium.org, dmitry.baryshkov@linaro.org, freedreno@lists.freedesktop.org Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" From: Sean Paul Stick all of the setup for HDCP into a dedicated function. No functional change, but this will facilitate moving HDCP logic into helpers. Acked-by: Jani Nikula Reviewed-by: Rodrigo Vivi Signed-off-by: Sean Paul --- Changes in v2: -None Changes in v3: -None Changes in v4: -None Changes in v5: -None Changes in v6: -None Changes in v7: - None drivers/gpu/drm/i915/display/intel_hdcp.c | 52 +++++++++++++++-------- 1 file changed, 35 insertions(+), 17 deletions(-) diff --git a/drivers/gpu/drm/i915/display/intel_hdcp.c b/drivers/gpu/drm/i915/display/intel_hdcp.c index 396d2cef000aa..0a20bc41be55d 100644 --- a/drivers/gpu/drm/i915/display/intel_hdcp.c +++ b/drivers/gpu/drm/i915/display/intel_hdcp.c @@ -2190,6 +2190,37 @@ static enum mei_fw_tc intel_get_mei_fw_tc(enum transcoder cpu_transcoder) } } +static int +_intel_hdcp_setup(struct intel_connector *connector, + const struct intel_crtc_state *pipe_config, u8 content_type) +{ + struct drm_i915_private *dev_priv = to_i915(connector->base.dev); + struct intel_digital_port *dig_port = intel_attached_dig_port(connector); + struct intel_hdcp *hdcp = &connector->hdcp; + int ret = 0; + + if (!connector->encoder) { + drm_err(&dev_priv->drm, "[%s:%d] encoder is not initialized\n", + connector->base.name, connector->base.base.id); + return -ENODEV; + } + + hdcp->content_type = content_type; + + if (intel_crtc_has_type(pipe_config, INTEL_OUTPUT_DP_MST)) { + hdcp->cpu_transcoder = pipe_config->mst_master_transcoder; + hdcp->stream_transcoder = pipe_config->cpu_transcoder; + } else { + hdcp->cpu_transcoder = pipe_config->cpu_transcoder; + hdcp->stream_transcoder = INVALID_TRANSCODER; + } + + if (DISPLAY_VER(dev_priv) >= 12) + dig_port->hdcp_port_data.fw_tc = intel_get_mei_fw_tc(hdcp->cpu_transcoder); + + return ret; +} + static int initialize_hdcp_port_data(struct intel_connector *connector, struct intel_digital_port *dig_port, const struct intel_hdcp_shim *shim) @@ -2329,28 +2360,14 @@ int intel_hdcp_enable(struct intel_connector *connector, if (!hdcp->shim) return -ENOENT; - if (!connector->encoder) { - drm_err(&dev_priv->drm, "[%s:%d] encoder is not initialized\n", - connector->base.name, connector->base.base.id); - return -ENODEV; - } - mutex_lock(&hdcp->mutex); mutex_lock(&dig_port->hdcp_mutex); drm_WARN_ON(&dev_priv->drm, hdcp->value == DRM_MODE_CONTENT_PROTECTION_ENABLED); - hdcp->content_type = content_type; - - if (intel_crtc_has_type(pipe_config, INTEL_OUTPUT_DP_MST)) { - hdcp->cpu_transcoder = pipe_config->mst_master_transcoder; - hdcp->stream_transcoder = pipe_config->cpu_transcoder; - } else { - hdcp->cpu_transcoder = pipe_config->cpu_transcoder; - hdcp->stream_transcoder = INVALID_TRANSCODER; - } - if (DISPLAY_VER(dev_priv) >= 12) - dig_port->hdcp_port_data.fw_tc = intel_get_mei_fw_tc(hdcp->cpu_transcoder); + ret = _intel_hdcp_setup(connector, pipe_config, content_type); + if (ret) + goto out; /* * Considering that HDCP2.2 is more secure than HDCP1.4, If the setup @@ -2378,6 +2395,7 @@ int intel_hdcp_enable(struct intel_connector *connector, true); } +out: mutex_unlock(&dig_port->hdcp_mutex); mutex_unlock(&hdcp->mutex); return ret; From patchwork Tue Apr 11 19:21:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Yacoub X-Patchwork-Id: 13208160 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 024F6C7619A for ; Tue, 11 Apr 2023 19:22:03 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 6952A10E649; Tue, 11 Apr 2023 19:21:54 +0000 (UTC) Received: from mail-yw1-x1131.google.com (mail-yw1-x1131.google.com [IPv6:2607:f8b0:4864:20::1131]) by gabe.freedesktop.org (Postfix) with ESMTPS id BD95210E644 for ; Tue, 11 Apr 2023 19:21:51 +0000 (UTC) Received: by mail-yw1-x1131.google.com with SMTP id 00721157ae682-54ee17a659bso178350087b3.4 for ; Tue, 11 Apr 2023 12:21:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1681240911; x=1683832911; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=zVHiVP8EvuttBlNQVBSyj+2lbyO+JHeWpdD8QHL+Aow=; b=TNS3tRR0DwXVG5AInyhzSs1ZALoc8O+EvEfYp4fQZRyVS+No08cnpDXmVkq536S+EZ ticG5kGq9LJjWwxrFlIXF+W4YPam/txFVsDXLeWk58gIN80uwMYFr8SnXF8XoB2OyOaA +6//JJCwKgUZ7uueflenx0CV7D7ybRHD326hY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1681240911; x=1683832911; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=zVHiVP8EvuttBlNQVBSyj+2lbyO+JHeWpdD8QHL+Aow=; b=UqwP0/no5oi55IqUqw8slmkZ9WXizTP4m2jlENd4CAZOaEEfAfFea+lYXRTxJXPYKW RoouoJ9ICpWOYyuA0BnURpFxKnFG1oyw9S7Ty8do+/M0+TDtBvE0vygJDHxKdLKfVjuY Qw91wywhTKrr0pr5Y/aprWOYAfswP7gHRfbiDI6Xz2GX0qTd0wST4S5SyQm8+ZgQD4S5 Ya1dxMtIgvLljxmiE+1WXIJ4wDfvpKP7EYy7CCWfwmeFyPA4mldGvuXD8IJ2g9GjGbgf YabwReyahGKOcRIshgZKxbWUNtghguyGUxayFx/O6VcCSjFmOV7mXD5LeUOMR6gnADBk 18YA== X-Gm-Message-State: AAQBX9ckKl+vR+FztmmCu/PfneD8lR3kOb07VWVFhzOVrXOZN3cp8QSC pMa3ovE1K6vA04tkvP1Bi6NcfQ== X-Google-Smtp-Source: AKy350Zn9rnYFx3i9yajOBA1njXQi71phMI51nkv7IGODWm5kh9ambz5NNWBtDdG7fhTIg1W8vfTJw== X-Received: by 2002:a81:1c9:0:b0:54e:ff2f:484c with SMTP id 192-20020a8101c9000000b0054eff2f484cmr199723ywb.15.1681240911422; Tue, 11 Apr 2023 12:21:51 -0700 (PDT) Received: from localhost ([2620:0:1035:15:2991:9b76:4e62:65bf]) by smtp.gmail.com with UTF8SMTPSA id bo18-20020a05690c059200b00545a08184fdsm3645120ywb.141.2023.04.11.12.21.50 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 11 Apr 2023 12:21:51 -0700 (PDT) From: Mark Yacoub X-Google-Original-From: Mark Yacoub To: Jani Nikula , Joonas Lahtinen , Rodrigo Vivi , Tvrtko Ursulin , David Airlie , Daniel Vetter Date: Tue, 11 Apr 2023 15:21:30 -0400 Message-Id: <20230411192134.508113-7-markyacoub@google.com> X-Mailer: git-send-email 2.40.0.577.gac1e443424-goog In-Reply-To: <20230411192134.508113-1-markyacoub@google.com> References: <20230411192134.508113-1-markyacoub@google.com> MIME-Version: 1.0 Subject: [Intel-gfx] [PATCH v9 06/10] drm/i915/hdcp: Retain hdcp_capable return codes X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Jani Nikula , Mark Yacoub , intel-gfx@lists.freedesktop.org, dianders@chromium.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, seanpaul@chromium.org, dmitry.baryshkov@linaro.org, freedreno@lists.freedesktop.org Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" From: Sean Paul The shim functions return error codes, but they are discarded in intel_hdcp.c. This patch plumbs the return codes through so they are properly handled. Acked-by: Jani Nikula Reviewed-by: Rodrigo Vivi Reviewed-by: Suraj Kandpal Signed-off-by: Sean Paul Signed-off-by: Mark Yacoub --- Changes in v2: -None Changes in v3: -None Changes in v4: -None Changes in v5: -None Changes in v6: -Rebased Changes in v7: -None .../drm/i915/display/intel_display_debugfs.c | 9 +++- drivers/gpu/drm/i915/display/intel_hdcp.c | 51 ++++++++++--------- drivers/gpu/drm/i915/display/intel_hdcp.h | 4 +- 3 files changed, 37 insertions(+), 27 deletions(-) diff --git a/drivers/gpu/drm/i915/display/intel_display_debugfs.c b/drivers/gpu/drm/i915/display/intel_display_debugfs.c index 7bcd90384a46d..a14b86a07e545 100644 --- a/drivers/gpu/drm/i915/display/intel_display_debugfs.c +++ b/drivers/gpu/drm/i915/display/intel_display_debugfs.c @@ -494,6 +494,7 @@ static void intel_panel_info(struct seq_file *m, static void intel_hdcp_info(struct seq_file *m, struct intel_connector *intel_connector) { + int ret; bool hdcp_cap, hdcp2_cap; if (!intel_connector->hdcp.shim) { @@ -501,8 +502,12 @@ static void intel_hdcp_info(struct seq_file *m, goto out; } - hdcp_cap = intel_hdcp_capable(intel_connector); - hdcp2_cap = intel_hdcp2_capable(intel_connector); + ret = intel_hdcp_capable(intel_connector, &hdcp_cap); + if (ret) + hdcp_cap = false; + ret = intel_hdcp2_capable(intel_connector, &hdcp2_cap); + if (ret) + hdcp2_cap = false; if (hdcp_cap) seq_puts(m, "HDCP1.4 "); diff --git a/drivers/gpu/drm/i915/display/intel_hdcp.c b/drivers/gpu/drm/i915/display/intel_hdcp.c index 0a20bc41be55d..61a862ae1f286 100644 --- a/drivers/gpu/drm/i915/display/intel_hdcp.c +++ b/drivers/gpu/drm/i915/display/intel_hdcp.c @@ -177,50 +177,49 @@ int intel_hdcp_read_valid_bksv(struct intel_digital_port *dig_port, } /* Is HDCP1.4 capable on Platform and Sink */ -bool intel_hdcp_capable(struct intel_connector *connector) +int intel_hdcp_capable(struct intel_connector *connector, bool *capable) { struct intel_digital_port *dig_port = intel_attached_dig_port(connector); const struct intel_hdcp_shim *shim = connector->hdcp.shim; - bool capable = false; u8 bksv[5]; + *capable = false; + if (!shim) - return capable; + return 0; - if (shim->hdcp_capable) { - shim->hdcp_capable(dig_port, &capable); - } else { - if (!intel_hdcp_read_valid_bksv(dig_port, shim, bksv)) - capable = true; - } + if (shim->hdcp_capable) + return shim->hdcp_capable(dig_port, capable); + + if (!intel_hdcp_read_valid_bksv(dig_port, shim, bksv)) + *capable = true; - return capable; + return 0; } /* Is HDCP2.2 capable on Platform and Sink */ -bool intel_hdcp2_capable(struct intel_connector *connector) +int intel_hdcp2_capable(struct intel_connector *connector, bool *capable) { struct intel_digital_port *dig_port = intel_attached_dig_port(connector); struct drm_i915_private *dev_priv = to_i915(connector->base.dev); struct intel_hdcp *hdcp = &connector->hdcp; - bool capable = false; + + *capable = false; /* I915 support for HDCP2.2 */ if (!hdcp->hdcp2_supported) - return false; + return 0; /* MEI interface is solid */ mutex_lock(&dev_priv->display.hdcp.comp_mutex); if (!dev_priv->display.hdcp.comp_added || !dev_priv->display.hdcp.master) { mutex_unlock(&dev_priv->display.hdcp.comp_mutex); - return false; + return 0; } mutex_unlock(&dev_priv->display.hdcp.comp_mutex); /* Sink's capability for HDCP2.2 */ - hdcp->shim->hdcp_2_2_capable(dig_port, &capable); - - return capable; + return hdcp->shim->hdcp_2_2_capable(dig_port, capable); } static bool intel_hdcp_in_use(struct drm_i915_private *dev_priv, @@ -2355,6 +2354,7 @@ int intel_hdcp_enable(struct intel_connector *connector, struct intel_digital_port *dig_port = intel_attached_dig_port(connector); struct intel_hdcp *hdcp = &connector->hdcp; unsigned long check_link_interval = DRM_HDCP_CHECK_PERIOD_MS; + bool capable; int ret = -EINVAL; if (!hdcp->shim) @@ -2373,21 +2373,27 @@ 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)) { + ret = intel_hdcp2_capable(connector, &capable); + if (capable) { ret = _intel_hdcp2_enable(connector); - if (!ret) + if (!ret) { check_link_interval = DRM_HDCP2_CHECK_PERIOD_MS; + goto out; + } } /* * When HDCP2.2 fails and Content Type is not Type1, HDCP1.4 will * be attempted. */ - if (ret && intel_hdcp_capable(connector) && - hdcp->content_type != DRM_MODE_HDCP_CONTENT_TYPE1) { + ret = intel_hdcp_capable(connector, &capable); + if (ret) + goto out; + + if (capable && hdcp->content_type != DRM_MODE_HDCP_CONTENT_TYPE1) ret = _intel_hdcp_enable(connector); - } +out: if (!ret) { schedule_delayed_work(&hdcp->check_work, check_link_interval); intel_hdcp_update_value(connector, @@ -2395,7 +2401,6 @@ int intel_hdcp_enable(struct intel_connector *connector, true); } -out: mutex_unlock(&dig_port->hdcp_mutex); mutex_unlock(&hdcp->mutex); return ret; diff --git a/drivers/gpu/drm/i915/display/intel_hdcp.h b/drivers/gpu/drm/i915/display/intel_hdcp.h index 7c5fd84a7b65a..f06f6e5a2b1ad 100644 --- a/drivers/gpu/drm/i915/display/intel_hdcp.h +++ b/drivers/gpu/drm/i915/display/intel_hdcp.h @@ -33,8 +33,8 @@ void intel_hdcp_update_pipe(struct intel_atomic_state *state, const struct intel_crtc_state *crtc_state, const struct drm_connector_state *conn_state); bool is_hdcp_supported(struct drm_i915_private *dev_priv, enum port port); -bool intel_hdcp_capable(struct intel_connector *connector); -bool intel_hdcp2_capable(struct intel_connector *connector); +int intel_hdcp_capable(struct intel_connector *connector, bool *capable); +int intel_hdcp2_capable(struct intel_connector *connector, bool *capable); void intel_hdcp_component_init(struct drm_i915_private *dev_priv); void intel_hdcp_component_fini(struct drm_i915_private *dev_priv); void intel_hdcp_cleanup(struct intel_connector *connector); From patchwork Tue Apr 11 19:21:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Yacoub X-Patchwork-Id: 13208162 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id A6851C76196 for ; Tue, 11 Apr 2023 19:22:07 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id A2EC310E64B; Tue, 11 Apr 2023 19:21:59 +0000 (UTC) Received: from mail-yw1-x112e.google.com (mail-yw1-x112e.google.com [IPv6:2607:f8b0:4864:20::112e]) by gabe.freedesktop.org (Postfix) with ESMTPS id EC1B610E64B for ; Tue, 11 Apr 2023 19:21:56 +0000 (UTC) Received: by mail-yw1-x112e.google.com with SMTP id 00721157ae682-54f64b29207so69053727b3.8 for ; Tue, 11 Apr 2023 12:21:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1681240915; x=1683832915; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=oue/HYlfovppqgzzbdjv9DnjrBnK5EoV43Qm6LSjyBQ=; b=jG72sufKMVw5mPEM4PnEYYKuF3oXSgrOGeiLxkellM1QlMBEtJl0+hPnSfm97cSRGi TuTclBzDXPq0Z6J0PnUhfic7FATOV65ZLrHWBJr2tORhUHm5yLLAB4HZyFl3VBu3CzQW rge1fkb7sTC+N7h0U9vBLjkwCpl6I54RuLZAs= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1681240915; x=1683832915; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=oue/HYlfovppqgzzbdjv9DnjrBnK5EoV43Qm6LSjyBQ=; b=Z6RoG0eyXt/2sui3GupVsQd9Fzq4tW8YQjGBCDpGSmsm1e6aEDWhFdjaAPDgD6DN5j WWxhq6IBW5YfcCRUl33XyhVsafpY3DzbSfDDTNUoFpmfQcj7D+Xha/RJkvx8TW2+Rk93 dFqeaQa9kNZAchFBJn5leO9emKzZyobwnc+5eVBJoDWWREJE9lhWClgpEvm2rbOTYA7o YKnF4SN8W+9iXRH3MYbu0ch8ZCpfzxoeX0yuXIrAOMNFXja4S8j3+PKjV8RQzvVh/Hzr 9RMa2LRcFsRypt/UYwfvr8zFPYUV4HaL/Ss0LOcLFznffhd47+z/3LnYWNdkwL5H2zI+ sevw== X-Gm-Message-State: AAQBX9eHARE7o5SHqXh3XYpPc2K94Ig/P28MzAWLSkttjTfB4jkqcIAI qRrcdUJM0ZanqlYsW00KZQFUwQ== X-Google-Smtp-Source: AKy350ZjUKusj+b4Am6DLLWCGHcl3mPSTynls3PQKx3/jo453wVPzWz6n9CSVRIMLUCM5V57RdCYvg== X-Received: by 2002:a0d:d694:0:b0:54f:8860:8d0f with SMTP id y142-20020a0dd694000000b0054f88608d0fmr709364ywd.32.1681240915047; Tue, 11 Apr 2023 12:21:55 -0700 (PDT) Received: from localhost ([2620:0:1035:15:2991:9b76:4e62:65bf]) by smtp.gmail.com with UTF8SMTPSA id eh25-20020a05690c299900b0054f6f65f258sm685881ywb.16.2023.04.11.12.21.53 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 11 Apr 2023 12:21:54 -0700 (PDT) From: Mark Yacoub X-Google-Original-From: Mark Yacoub To: Jani Nikula , Joonas Lahtinen , Rodrigo Vivi , Tvrtko Ursulin , David Airlie , Daniel Vetter Date: Tue, 11 Apr 2023 15:21:31 -0400 Message-Id: <20230411192134.508113-8-markyacoub@google.com> X-Mailer: git-send-email 2.40.0.577.gac1e443424-goog In-Reply-To: <20230411192134.508113-1-markyacoub@google.com> References: <20230411192134.508113-1-markyacoub@google.com> MIME-Version: 1.0 Subject: [Intel-gfx] [PATCH v9 07/10] drm/i915/hdcp: Use HDCP helpers for i915 X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Jani Nikula , Mark Yacoub , intel-gfx@lists.freedesktop.org, dianders@chromium.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, seanpaul@chromium.org, dmitry.baryshkov@linaro.org, freedreno@lists.freedesktop.org Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" From: Sean Paul Now that all of the HDCP 1.x logic has been migrated to the central HDCP helpers, use it in the i915 driver. The majority of the driver code for HDCP 1.x will live in intel_hdcp.c, however there are a few helper hooks which are connector-specific and need to be partially or fully implemented in the intel_dp_hdcp.c or intel_hdmi.c. We'll leave most of the HDCP 2.x code alone since we don't have another implementation of HDCP 2.x to use as reference for what should and should not live in the drm helpers. The helper will call the overly general enable/disable/is_capable HDCP 2.x callbacks and leave the interesting stuff for the driver. Once we have another HDCP 2.x implementation, we should do a similar migration. Acked-by: Jani Nikula Acked-by: Rodrigo Vivi Signed-off-by: Sean Paul Signed-off-by: Mark Yacoub --- Changes in v2: -Fix mst helper function pointer reported by 0-day Changes in v3: -Add forward declaration for drm_atomic_state in intel_hdcp.h identified by 0-day Changes in v4: -None Changes in v5: -None Changes in v6: -Rebased. Changes in v7: -Added to drm_hdcp_helper_funcs new functions that are unique between DP and HDMI -Adjusted the function signatures to take "driver data" Changes in v8: -None Changes in v9: -rename dev_priv to i915 -remove display type specific hdcp calls init from driver drivers/gpu/drm/i915/display/intel_ddi.c | 32 +- .../drm/i915/display/intel_display_debugfs.c | 7 +- .../drm/i915/display/intel_display_types.h | 51 +- drivers/gpu/drm/i915/display/intel_dp_hdcp.c | 352 +++---- drivers/gpu/drm/i915/display/intel_dp_mst.c | 16 +- drivers/gpu/drm/i915/display/intel_hdcp.c | 984 ++++-------------- drivers/gpu/drm/i915/display/intel_hdcp.h | 43 +- drivers/gpu/drm/i915/display/intel_hdmi.c | 267 ++--- 8 files changed, 475 insertions(+), 1277 deletions(-) diff --git a/drivers/gpu/drm/i915/display/intel_ddi.c b/drivers/gpu/drm/i915/display/intel_ddi.c index 254559abedfba..8a2f20c929e9c 100644 --- a/drivers/gpu/drm/i915/display/intel_ddi.c +++ b/drivers/gpu/drm/i915/display/intel_ddi.c @@ -28,6 +28,7 @@ #include #include +#include #include #include "i915_drv.h" @@ -2956,6 +2957,10 @@ static void intel_enable_ddi(struct intel_atomic_state *state, const struct intel_crtc_state *crtc_state, const struct drm_connector_state *conn_state) { + struct intel_connector *connector = + to_intel_connector(conn_state->connector); + struct intel_digital_port *dig_port = enc_to_dig_port(encoder); + drm_WARN_ON(state->base.dev, crtc_state->has_pch_encoder); if (!intel_crtc_is_bigjoiner_slave(crtc_state)) @@ -2975,12 +2980,10 @@ 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(to_intel_connector(conn_state->connector), - crtc_state, - (u8)conn_state->hdcp_content_type); + if (connector->hdcp_helper_data) + drm_hdcp_helper_atomic_commit(connector->hdcp_helper_data, + &state->base, + &dig_port->hdcp_mutex); } static void intel_disable_ddi_dp(struct intel_atomic_state *state, @@ -3026,7 +3029,14 @@ static void intel_disable_ddi(struct intel_atomic_state *state, const struct intel_crtc_state *old_crtc_state, const struct drm_connector_state *old_conn_state) { - intel_hdcp_disable(to_intel_connector(old_conn_state->connector)); + struct intel_connector *connector = + to_intel_connector(old_conn_state->connector); + struct intel_digital_port *dig_port = enc_to_dig_port(encoder); + + if (connector->hdcp_helper_data) + drm_hdcp_helper_atomic_commit(connector->hdcp_helper_data, + &state->base, + &dig_port->hdcp_mutex); if (intel_crtc_has_type(old_crtc_state, INTEL_OUTPUT_HDMI)) intel_disable_ddi_hdmi(state, encoder, old_crtc_state, @@ -3054,13 +3064,19 @@ void intel_ddi_update_pipe(struct intel_atomic_state *state, const struct intel_crtc_state *crtc_state, const struct drm_connector_state *conn_state) { + struct intel_connector *connector = + to_intel_connector(conn_state->connector); + struct intel_digital_port *dig_port = enc_to_dig_port(encoder); if (!intel_crtc_has_type(crtc_state, INTEL_OUTPUT_HDMI) && !intel_encoder_is_mst(encoder)) intel_ddi_update_pipe_dp(state, encoder, crtc_state, conn_state); - intel_hdcp_update_pipe(state, encoder, crtc_state, conn_state); + if (connector->hdcp_helper_data) + drm_hdcp_helper_atomic_commit(connector->hdcp_helper_data, + &state->base, + &dig_port->hdcp_mutex); } static void diff --git a/drivers/gpu/drm/i915/display/intel_display_debugfs.c b/drivers/gpu/drm/i915/display/intel_display_debugfs.c index a14b86a07e545..6dcfbe2b7eca5 100644 --- a/drivers/gpu/drm/i915/display/intel_display_debugfs.c +++ b/drivers/gpu/drm/i915/display/intel_display_debugfs.c @@ -7,6 +7,7 @@ #include #include +#include #include "i915_debugfs.h" #include "i915_irq.h" @@ -502,10 +503,12 @@ static void intel_hdcp_info(struct seq_file *m, goto out; } - ret = intel_hdcp_capable(intel_connector, &hdcp_cap); + ret = intel_connector->hdcp_helper_data->display_type_funcs + ->hdcp1_capable(intel_connector->hdcp_helper_data, + &hdcp_cap); if (ret) hdcp_cap = false; - ret = intel_hdcp2_capable(intel_connector, &hdcp2_cap); + ret = intel_hdcp2_capable(&intel_connector->base, &hdcp2_cap); if (ret) hdcp2_cap = false; diff --git a/drivers/gpu/drm/i915/display/intel_display_types.h b/drivers/gpu/drm/i915/display/intel_display_types.h index 582234f0c49ac..1867a1becdf43 100644 --- a/drivers/gpu/drm/i915/display/intel_display_types.h +++ b/drivers/gpu/drm/i915/display/intel_display_types.h @@ -432,64 +432,14 @@ enum check_link_response { * to send it over DP AUX vs DDC */ struct intel_hdcp_shim { - /* Outputs the transmitter's An and Aksv values to the receiver. */ - int (*write_an_aksv)(struct intel_digital_port *dig_port, u8 *an); - - /* Reads the receiver's key selection vector */ - int (*read_bksv)(struct intel_digital_port *dig_port, u8 *bksv); - - /* - * Reads BINFO from DP receivers and BSTATUS from HDMI receivers. The - * definitions are the same in the respective specs, but the names are - * different. Call it BSTATUS since that's the name the HDMI spec - * uses and it was there first. - */ - int (*read_bstatus)(struct intel_digital_port *dig_port, - u8 *bstatus); - - /* Determines whether a repeater is present downstream */ - int (*repeater_present)(struct intel_digital_port *dig_port, - bool *repeater_present); - - /* Reads the receiver's Ri' value */ - int (*read_ri_prime)(struct intel_digital_port *dig_port, u8 *ri); - - /* Determines if the receiver's KSV FIFO is ready for consumption */ - int (*read_ksv_ready)(struct intel_digital_port *dig_port, - bool *ksv_ready); - - /* Reads the ksv fifo for num_downstream devices */ - int (*read_ksv_fifo)(struct intel_digital_port *dig_port, - int num_downstream, u8 *ksv_fifo); - - /* Reads a 32-bit part of V' from the receiver */ - int (*read_v_prime_part)(struct intel_digital_port *dig_port, - int i, u32 *part); - /* Enables HDCP signalling on the port */ int (*toggle_signalling)(struct intel_digital_port *dig_port, enum transcoder cpu_transcoder, bool enable); - /* Enable/Disable stream encryption on DP MST Transport Link */ - int (*stream_encryption)(struct intel_connector *connector, - bool enable); - - /* Ensures the link is still protected */ - bool (*check_link)(struct intel_digital_port *dig_port, - struct intel_connector *connector); - - /* Detects panel's hdcp capability. This is optional for HDMI. */ - int (*hdcp_capable)(struct intel_digital_port *dig_port, - bool *hdcp_capable); - /* HDCP adaptation(DP/HDMI) required on the port */ enum hdcp_wired_protocol protocol; - /* Detects whether sink is HDCP2.2 capable */ - int (*hdcp_2_2_capable)(struct intel_digital_port *dig_port, - bool *capable); - /* Write HDCP2.2 messages */ int (*write_2_2_msg)(struct intel_digital_port *dig_port, void *buf, size_t size); @@ -611,6 +561,7 @@ struct intel_connector { struct work_struct modeset_retry_work; struct intel_hdcp hdcp; + struct drm_hdcp_helper_data *hdcp_helper_data; }; struct intel_digital_connector_state { diff --git a/drivers/gpu/drm/i915/display/intel_dp_hdcp.c b/drivers/gpu/drm/i915/display/intel_dp_hdcp.c index e0c1771614072..0b54ef3b96a9c 100644 --- a/drivers/gpu/drm/i915/display/intel_dp_hdcp.c +++ b/drivers/gpu/drm/i915/display/intel_dp_hdcp.c @@ -48,17 +48,24 @@ static void intel_dp_hdcp_wait_for_cp_irq(struct intel_hdcp *hdcp, int timeout) DRM_DEBUG_KMS("Timedout at waiting for CP_IRQ\n"); } -static -int intel_dp_hdcp_write_an_aksv(struct intel_digital_port *dig_port, - u8 *an) +static int intel_dp_hdcp_send_an_aksv(struct drm_connector *drm_connector, + void *driver_data) { + struct intel_connector *connector = to_intel_connector(drm_connector); + struct intel_digital_port *dig_port = + intel_attached_dig_port(connector); struct drm_i915_private *i915 = to_i915(dig_port->base.base.dev); + struct drm_hdcp_an an; u8 aksv[DRM_HDCP_KSV_LEN] = {}; ssize_t dpcd_ret; + int ret; + + ret = intel_hdcp1_read_an(drm_connector, &an); + if (ret) + return ret; - /* Output An first, that's easy */ dpcd_ret = drm_dp_dpcd_write(&dig_port->dp.aux, DP_AUX_HDCP_AN, - an, DRM_HDCP_AN_LEN); + an.bytes, DRM_HDCP_AN_LEN); if (dpcd_ret != DRM_HDCP_AN_LEN) { drm_dbg_kms(&i915->drm, "Failed to write An over DP/AUX (%zd)\n", @@ -84,158 +91,6 @@ int intel_dp_hdcp_write_an_aksv(struct intel_digital_port *dig_port, return 0; } -static int intel_dp_hdcp_read_bksv(struct intel_digital_port *dig_port, - u8 *bksv) -{ - struct drm_i915_private *i915 = to_i915(dig_port->base.base.dev); - ssize_t ret; - - ret = drm_dp_dpcd_read(&dig_port->dp.aux, DP_AUX_HDCP_BKSV, bksv, - DRM_HDCP_KSV_LEN); - if (ret != DRM_HDCP_KSV_LEN) { - drm_dbg_kms(&i915->drm, - "Read Bksv from DP/AUX failed (%zd)\n", ret); - return ret >= 0 ? -EIO : ret; - } - return 0; -} - -static int intel_dp_hdcp_read_bstatus(struct intel_digital_port *dig_port, - u8 *bstatus) -{ - struct drm_i915_private *i915 = to_i915(dig_port->base.base.dev); - ssize_t ret; - - /* - * For some reason the HDMI and DP HDCP specs call this register - * definition by different names. In the HDMI spec, it's called BSTATUS, - * but in DP it's called BINFO. - */ - ret = drm_dp_dpcd_read(&dig_port->dp.aux, DP_AUX_HDCP_BINFO, - bstatus, DRM_HDCP_BSTATUS_LEN); - if (ret != DRM_HDCP_BSTATUS_LEN) { - drm_dbg_kms(&i915->drm, - "Read bstatus from DP/AUX failed (%zd)\n", ret); - return ret >= 0 ? -EIO : ret; - } - return 0; -} - -static -int intel_dp_hdcp_read_bcaps(struct intel_digital_port *dig_port, - u8 *bcaps) -{ - struct drm_i915_private *i915 = to_i915(dig_port->base.base.dev); - ssize_t ret; - - ret = drm_dp_dpcd_read(&dig_port->dp.aux, DP_AUX_HDCP_BCAPS, - bcaps, 1); - if (ret != 1) { - drm_dbg_kms(&i915->drm, - "Read bcaps from DP/AUX failed (%zd)\n", ret); - return ret >= 0 ? -EIO : ret; - } - - return 0; -} - -static -int intel_dp_hdcp_repeater_present(struct intel_digital_port *dig_port, - bool *repeater_present) -{ - ssize_t ret; - u8 bcaps; - - ret = intel_dp_hdcp_read_bcaps(dig_port, &bcaps); - if (ret) - return ret; - - *repeater_present = bcaps & DP_BCAPS_REPEATER_PRESENT; - return 0; -} - -static -int intel_dp_hdcp_read_ri_prime(struct intel_digital_port *dig_port, - u8 *ri_prime) -{ - struct drm_i915_private *i915 = to_i915(dig_port->base.base.dev); - ssize_t ret; - - ret = drm_dp_dpcd_read(&dig_port->dp.aux, DP_AUX_HDCP_RI_PRIME, - ri_prime, DRM_HDCP_RI_LEN); - if (ret != DRM_HDCP_RI_LEN) { - drm_dbg_kms(&i915->drm, "Read Ri' from DP/AUX failed (%zd)\n", - ret); - return ret >= 0 ? -EIO : ret; - } - return 0; -} - -static -int intel_dp_hdcp_read_ksv_ready(struct intel_digital_port *dig_port, - bool *ksv_ready) -{ - struct drm_i915_private *i915 = to_i915(dig_port->base.base.dev); - ssize_t ret; - u8 bstatus; - - ret = drm_dp_dpcd_read(&dig_port->dp.aux, DP_AUX_HDCP_BSTATUS, - &bstatus, 1); - if (ret != 1) { - drm_dbg_kms(&i915->drm, - "Read bstatus from DP/AUX failed (%zd)\n", ret); - return ret >= 0 ? -EIO : ret; - } - *ksv_ready = bstatus & DP_BSTATUS_READY; - return 0; -} - -static -int intel_dp_hdcp_read_ksv_fifo(struct intel_digital_port *dig_port, - int num_downstream, u8 *ksv_fifo) -{ - struct drm_i915_private *i915 = to_i915(dig_port->base.base.dev); - ssize_t ret; - int i; - - /* KSV list is read via 15 byte window (3 entries @ 5 bytes each) */ - for (i = 0; i < num_downstream; i += 3) { - size_t len = min(num_downstream - i, 3) * DRM_HDCP_KSV_LEN; - ret = drm_dp_dpcd_read(&dig_port->dp.aux, - DP_AUX_HDCP_KSV_FIFO, - ksv_fifo + i * DRM_HDCP_KSV_LEN, - len); - if (ret != len) { - drm_dbg_kms(&i915->drm, - "Read ksv[%d] from DP/AUX failed (%zd)\n", - i, ret); - return ret >= 0 ? -EIO : ret; - } - } - return 0; -} - -static -int intel_dp_hdcp_read_v_prime_part(struct intel_digital_port *dig_port, - int i, u32 *part) -{ - struct drm_i915_private *i915 = to_i915(dig_port->base.base.dev); - ssize_t ret; - - if (i >= DRM_HDCP_V_PRIME_NUM_PARTS) - return -EINVAL; - - ret = drm_dp_dpcd_read(&dig_port->dp.aux, - DP_AUX_HDCP_V_PRIME(i), part, - DRM_HDCP_V_PRIME_PART_LEN); - if (ret != DRM_HDCP_V_PRIME_PART_LEN) { - drm_dbg_kms(&i915->drm, - "Read v'[%d] from DP/AUX failed (%zd)\n", i, ret); - return ret >= 0 ? -EIO : ret; - } - return 0; -} - static int intel_dp_hdcp_toggle_signalling(struct intel_digital_port *dig_port, enum transcoder cpu_transcoder, @@ -245,40 +100,6 @@ int intel_dp_hdcp_toggle_signalling(struct intel_digital_port *dig_port, return 0; } -static -bool intel_dp_hdcp_check_link(struct intel_digital_port *dig_port, - struct intel_connector *connector) -{ - struct drm_i915_private *i915 = to_i915(dig_port->base.base.dev); - ssize_t ret; - u8 bstatus; - - ret = drm_dp_dpcd_read(&dig_port->dp.aux, DP_AUX_HDCP_BSTATUS, - &bstatus, 1); - if (ret != 1) { - drm_dbg_kms(&i915->drm, - "Read bstatus from DP/AUX failed (%zd)\n", ret); - return false; - } - - return !(bstatus & (DP_BSTATUS_LINK_FAILURE | DP_BSTATUS_REAUTH_REQ)); -} - -static -int intel_dp_hdcp_capable(struct intel_digital_port *dig_port, - bool *hdcp_capable) -{ - ssize_t ret; - u8 bcaps; - - ret = intel_dp_hdcp_read_bcaps(dig_port, &bcaps); - if (ret) - return ret; - - *hdcp_capable = bcaps & DP_BCAPS_HDCP_CAPABLE; - return 0; -} - struct hdcp2_dp_errata_stream_type { u8 msg_id; u8 stream_type; @@ -621,13 +442,19 @@ int intel_dp_hdcp2_check_link(struct intel_digital_port *dig_port, return ret; } -static -int intel_dp_hdcp2_capable(struct intel_digital_port *dig_port, - bool *capable) +static int intel_dp_hdcp2_capable(struct drm_connector *drm_connector, + bool *capable, void *driver_data) { + struct intel_connector *connector = to_intel_connector(drm_connector); + struct intel_digital_port *dig_port = + intel_attached_dig_port(connector); u8 rx_caps[3]; int ret; + ret = intel_hdcp2_capable(drm_connector, capable); + if (ret || !capable) + return ret; + *capable = false; ret = drm_dp_dpcd_read(&dig_port->dp.aux, DP_HDCP_2_2_REG_RX_CAPS_OFFSET, @@ -643,22 +470,11 @@ int intel_dp_hdcp2_capable(struct intel_digital_port *dig_port, } static const struct intel_hdcp_shim intel_dp_hdcp_shim = { - .write_an_aksv = intel_dp_hdcp_write_an_aksv, - .read_bksv = intel_dp_hdcp_read_bksv, - .read_bstatus = intel_dp_hdcp_read_bstatus, - .repeater_present = intel_dp_hdcp_repeater_present, - .read_ri_prime = intel_dp_hdcp_read_ri_prime, - .read_ksv_ready = intel_dp_hdcp_read_ksv_ready, - .read_ksv_fifo = intel_dp_hdcp_read_ksv_fifo, - .read_v_prime_part = intel_dp_hdcp_read_v_prime_part, .toggle_signalling = intel_dp_hdcp_toggle_signalling, - .check_link = intel_dp_hdcp_check_link, - .hdcp_capable = intel_dp_hdcp_capable, .write_2_2_msg = intel_dp_hdcp2_write_msg, .read_2_2_msg = intel_dp_hdcp2_read_msg, .config_stream_type = intel_dp_hdcp2_config_stream_type, .check_2_2_link = intel_dp_hdcp2_check_link, - .hdcp_2_2_capable = intel_dp_hdcp2_capable, .protocol = HDCP_PROTOCOL_DP, }; @@ -714,6 +530,48 @@ intel_dp_mst_hdcp_stream_encryption(struct intel_connector *connector, return 0; } +static int +intel_dp_mst_hdcp1_post_encryption(struct drm_connector *drm_connector, + void *driver_data) +{ + struct intel_connector *connector = to_intel_connector(drm_connector); + int ret; + + ret = intel_hdcp1_post_encryption(drm_connector, driver_data); + if (ret) + return ret; + + return intel_dp_mst_hdcp_stream_encryption(connector, true); +} + +static int intel_dp_mst_hdcp1_disable(struct drm_connector *drm_connector, + void *driver_data) +{ + struct intel_connector *connector = to_intel_connector(drm_connector); + struct intel_digital_port *dig_port = + intel_attached_dig_port(connector); + struct drm_i915_private *i915 = to_i915(connector->base.dev); + int ret; + + ret = intel_dp_mst_hdcp_stream_encryption(connector, true); + if (ret) { + drm_err(&i915->drm, + "[%s:%d] Failed to disable HDCP 1.4 stream enc\n", + connector->base.name, connector->base.base.id); + return ret; + } + + /* + * If there are other connectors on this port using HDCP, + * don't disable it until it disabled HDCP encryption for + * all connectors in MST topology. + */ + if (dig_port->num_hdcp_streams > 0) + return 0; + + return intel_hdcp1_disable(drm_connector, driver_data); +} + static int intel_dp_mst_hdcp2_stream_encryption(struct intel_connector *connector, bool enable) @@ -772,45 +630,85 @@ int intel_dp_mst_hdcp2_check_link(struct intel_digital_port *dig_port, } static const struct intel_hdcp_shim intel_dp_mst_hdcp_shim = { - .write_an_aksv = intel_dp_hdcp_write_an_aksv, - .read_bksv = intel_dp_hdcp_read_bksv, - .read_bstatus = intel_dp_hdcp_read_bstatus, - .repeater_present = intel_dp_hdcp_repeater_present, - .read_ri_prime = intel_dp_hdcp_read_ri_prime, - .read_ksv_ready = intel_dp_hdcp_read_ksv_ready, - .read_ksv_fifo = intel_dp_hdcp_read_ksv_fifo, - .read_v_prime_part = intel_dp_hdcp_read_v_prime_part, .toggle_signalling = intel_dp_hdcp_toggle_signalling, - .stream_encryption = intel_dp_mst_hdcp_stream_encryption, - .check_link = intel_dp_hdcp_check_link, - .hdcp_capable = intel_dp_hdcp_capable, .write_2_2_msg = intel_dp_hdcp2_write_msg, .read_2_2_msg = intel_dp_hdcp2_read_msg, .config_stream_type = intel_dp_hdcp2_config_stream_type, .stream_2_2_encryption = intel_dp_mst_hdcp2_stream_encryption, .check_2_2_link = intel_dp_mst_hdcp2_check_link, - .hdcp_2_2_capable = intel_dp_hdcp2_capable, .protocol = HDCP_PROTOCOL_DP, }; +static const struct drm_hdcp_helper_funcs intel_dp_hdcp_helper_funcs = { + .setup = intel_hdcp_setup, + .load_keys = intel_hdcp_load_keys, + .hdcp2_capable = intel_dp_hdcp2_capable, + .hdcp2_enable = intel_hdcp2_enable, + .hdcp2_check_link = intel_hdcp2_check_link, + .hdcp2_disable = intel_hdcp2_disable, + .hdcp1_send_an_aksv = intel_dp_hdcp_send_an_aksv, + .hdcp1_store_receiver_info = intel_hdcp1_store_receiver_info, + .hdcp1_enable_encryption = intel_hdcp1_enable_encryption, + .hdcp1_wait_for_r0 = intel_hdcp1_wait_for_r0, + .hdcp1_match_ri = intel_hdcp1_match_ri, + .hdcp1_post_encryption = intel_hdcp1_post_encryption, + .hdcp1_store_ksv_fifo = intel_hdcp1_store_ksv_fifo, + .hdcp1_disable = intel_hdcp1_disable, +}; + +static const struct drm_hdcp_helper_funcs intel_dp_mst_hdcp_helper_funcs = { + .setup = intel_hdcp_setup, + .load_keys = intel_hdcp_load_keys, + .hdcp2_capable = intel_dp_hdcp2_capable, + .hdcp2_enable = intel_hdcp2_enable, + .hdcp2_check_link = intel_hdcp2_check_link, + .hdcp2_disable = intel_hdcp2_disable, + .hdcp1_send_an_aksv = intel_dp_hdcp_send_an_aksv, + .hdcp1_store_receiver_info = intel_hdcp1_store_receiver_info, + .hdcp1_enable_encryption = intel_hdcp1_enable_encryption, + .hdcp1_wait_for_r0 = intel_hdcp1_wait_for_r0, + .hdcp1_match_ri = intel_hdcp1_match_ri, + .hdcp1_post_encryption = intel_dp_mst_hdcp1_post_encryption, + .hdcp1_store_ksv_fifo = intel_hdcp1_store_ksv_fifo, + .hdcp1_disable = intel_dp_mst_hdcp1_disable, +}; + int intel_dp_hdcp_init(struct intel_digital_port *dig_port, - struct intel_connector *intel_connector) + struct intel_connector *connector) { - struct drm_device *dev = intel_connector->base.dev; - struct drm_i915_private *dev_priv = to_i915(dev); + struct drm_i915_private *dev_priv = to_i915(connector->base.dev); struct intel_encoder *intel_encoder = &dig_port->base; enum port port = intel_encoder->port; struct intel_dp *intel_dp = &dig_port->dp; + struct drm_hdcp_helper_data *data; + const struct drm_hdcp_helper_funcs *helper_funcs; + const struct intel_hdcp_shim *intel_shim; + int ret; - if (!is_hdcp_supported(dev_priv, port)) + if (!is_hdcp_supported(dev_priv, port) || intel_dp_is_edp(intel_dp)) return 0; - if (intel_connector->mst_port) - return intel_hdcp_init(intel_connector, dig_port, - &intel_dp_mst_hdcp_shim); - else if (!intel_dp_is_edp(intel_dp)) - return intel_hdcp_init(intel_connector, dig_port, - &intel_dp_hdcp_shim); + if (connector->mst_port) { + helper_funcs = &intel_dp_mst_hdcp_helper_funcs; + intel_shim = &intel_dp_mst_hdcp_shim; + } else { + helper_funcs = &intel_dp_hdcp_helper_funcs; + intel_shim = &intel_dp_hdcp_shim; + } + + data = drm_hdcp_helper_initialize_dp(&connector->base, &dig_port->dp.aux, + helper_funcs, true); + if (IS_ERR(data)) { + drm_dbg_kms(&dev_priv->drm, "HDCP init failed, skipping.\n"); + return PTR_ERR(data); + } + + ret = intel_hdcp_init(connector, dig_port, intel_shim); + if (ret) { + drm_hdcp_helper_destroy(data); + return ret; + } + connector->hdcp_helper_data = data; return 0; } diff --git a/drivers/gpu/drm/i915/display/intel_dp_mst.c b/drivers/gpu/drm/i915/display/intel_dp_mst.c index 2106b3de225a0..489dd91f933d6 100644 --- a/drivers/gpu/drm/i915/display/intel_dp_mst.c +++ b/drivers/gpu/drm/i915/display/intel_dp_mst.c @@ -23,6 +23,7 @@ * */ +#include #include #include #include @@ -41,7 +42,6 @@ #include "intel_dp_hdcp.h" #include "intel_dp_mst.h" #include "intel_dpio_phy.h" -#include "intel_hdcp.h" #include "intel_hotplug.h" #include "skl_scaler.h" @@ -544,7 +544,10 @@ static void intel_mst_disable_dp(struct intel_atomic_state *state, drm_dbg_kms(&i915->drm, "active links %d\n", intel_dp->active_mst_links); - intel_hdcp_disable(intel_mst->connector); + if (connector->hdcp_helper_data) + drm_hdcp_helper_atomic_commit(connector->hdcp_helper_data, + &state->base, + &dig_port->hdcp_mutex); drm_dp_remove_payload(&intel_dp->mst_mgr, new_mst_state, old_payload, new_payload); @@ -752,11 +755,10 @@ 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(to_intel_connector(conn_state->connector), - pipe_config, - (u8)conn_state->hdcp_content_type); + if (connector->hdcp_helper_data) + drm_hdcp_helper_atomic_commit(connector->hdcp_helper_data, + &state->base, + &dig_port->hdcp_mutex); } 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 61a862ae1f286..ea77afae9740b 100644 --- a/drivers/gpu/drm/i915/display/intel_hdcp.c +++ b/drivers/gpu/drm/i915/display/intel_hdcp.c @@ -140,67 +140,10 @@ static int intel_hdcp_prepare_streams(struct intel_connector *connector) return 0; } -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 *dig_port, - const struct intel_hdcp_shim *shim, u8 *bksv) -{ - struct drm_i915_private *i915 = to_i915(dig_port->base.base.dev); - 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(dig_port, bksv); - if (ret) - return ret; - if (intel_hdcp_is_ksv_valid(bksv)) - break; - } - if (i == tries) { - drm_dbg_kms(&i915->drm, "Bksv is invalid\n"); - return -ENODEV; - } - - return 0; -} - -/* Is HDCP1.4 capable on Platform and Sink */ -int intel_hdcp_capable(struct intel_connector *connector, bool *capable) -{ - struct intel_digital_port *dig_port = intel_attached_dig_port(connector); - const struct intel_hdcp_shim *shim = connector->hdcp.shim; - u8 bksv[5]; - - *capable = false; - - if (!shim) - return 0; - - if (shim->hdcp_capable) - return shim->hdcp_capable(dig_port, capable); - - if (!intel_hdcp_read_valid_bksv(dig_port, shim, bksv)) - *capable = true; - - return 0; -} - /* Is HDCP2.2 capable on Platform and Sink */ -int intel_hdcp2_capable(struct intel_connector *connector, bool *capable) +int intel_hdcp2_capable(struct drm_connector *drm_connector, bool *capable) { - struct intel_digital_port *dig_port = intel_attached_dig_port(connector); + struct intel_connector *connector = to_intel_connector(drm_connector); struct drm_i915_private *dev_priv = to_i915(connector->base.dev); struct intel_hdcp *hdcp = &connector->hdcp; @@ -218,16 +161,26 @@ int intel_hdcp2_capable(struct intel_connector *connector, bool *capable) } mutex_unlock(&dev_priv->display.hdcp.comp_mutex); - /* Sink's capability for HDCP2.2 */ - return hdcp->shim->hdcp_2_2_capable(dig_port, capable); + return 0; } -static bool intel_hdcp_in_use(struct drm_i915_private *dev_priv, - enum transcoder cpu_transcoder, enum port port) +int intel_hdcp1_check_link(struct drm_connector *drm_connector) { - return intel_de_read(dev_priv, - HDCP_STATUS(dev_priv, cpu_transcoder, port)) & - HDCP_STATUS_ENC; + struct intel_connector *connector = to_intel_connector(drm_connector); + struct intel_digital_port *dig_port = + intel_attached_dig_port(connector); + struct drm_i915_private *i915 = to_i915(connector->base.dev); + enum transcoder cpu_transcoder = connector->hdcp.cpu_transcoder; + enum port port = dig_port->base.port; + u32 val; + + val = intel_de_read(i915, + HDCP_STATUS(i915, cpu_transcoder, port)); + + if (val & HDCP_STATUS_ENC) + return 0; + + return -EINVAL; } static bool intel_hdcp2_in_use(struct drm_i915_private *dev_priv, @@ -238,27 +191,6 @@ static bool intel_hdcp2_in_use(struct drm_i915_private *dev_priv, LINK_ENCRYPTION_STATUS; } -static int intel_hdcp_poll_ksv_fifo(struct intel_digital_port *dig_port, - const struct intel_hdcp_shim *shim) -{ - int ret, read_ret; - bool ksv_ready; - - /* Poll for ksv list ready (spec says max time allowed is 5s) */ - ret = __wait_for(read_ret = shim->read_ksv_ready(dig_port, - &ksv_ready), - read_ret || ksv_ready, 5 * 1000 * 1000, 1000, - 100 * 1000); - if (ret) - return ret; - if (read_ret) - return read_ret; - if (!ksv_ready) - return -ETIMEDOUT; - - return 0; -} - static bool hdcp_key_loadable(struct drm_i915_private *dev_priv) { enum i915_power_well_id id; @@ -294,12 +226,19 @@ static void intel_hdcp_clear_keys(struct drm_i915_private *dev_priv) HDCP_KEY_LOAD_DONE | HDCP_KEY_LOAD_STATUS | HDCP_FUSE_IN_PROGRESS | HDCP_FUSE_ERROR | HDCP_FUSE_DONE); } -static int intel_hdcp_load_keys(struct drm_i915_private *dev_priv) +int intel_hdcp_load_keys(struct drm_connector *drm_connector, void *driver_data) { + struct intel_connector *connector = to_intel_connector(drm_connector); + struct drm_i915_private *i915 = to_i915(connector->base.dev); int ret; u32 val; - val = intel_de_read(dev_priv, HDCP_KEY_STATUS); + if (!hdcp_key_loadable(i915)) { + drm_err(&i915->drm, "HDCP key Load is not possible\n"); + return -ENXIO; + } + + val = intel_de_read(i915, HDCP_KEY_STATUS); if ((val & HDCP_KEY_LOAD_DONE) && (val & HDCP_KEY_LOAD_STATUS)) return 0; @@ -307,9 +246,12 @@ static int intel_hdcp_load_keys(struct drm_i915_private *dev_priv) * On HSW and BDW HW loads the HDCP1.4 Key when Display comes * out of reset. So if Key is not already loaded, its an error state. */ - if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) - if (!(intel_de_read(dev_priv, HDCP_KEY_STATUS) & HDCP_KEY_LOAD_DONE)) - return -ENXIO; + if (IS_HASWELL(i915) || IS_BROADWELL(i915)) + if (!(intel_de_read(i915, HDCP_KEY_STATUS) & + HDCP_KEY_LOAD_DONE)) { + ret = -ENXIO; + goto err; + } /* * Initiate loading the HDCP key from fuses. @@ -319,31 +261,37 @@ static int intel_hdcp_load_keys(struct drm_i915_private *dev_priv) * process from other platforms. These platforms use the GT Driver * Mailbox interface. */ - if (DISPLAY_VER(dev_priv) == 9 && !IS_BROXTON(dev_priv)) { - ret = snb_pcode_write(&dev_priv->uncore, SKL_PCODE_LOAD_HDCP_KEYS, 1); + if (DISPLAY_VER(i915) == 9 && !IS_BROXTON(i915)) { + ret = snb_pcode_write(&i915->uncore, SKL_PCODE_LOAD_HDCP_KEYS, 1); if (ret) { - drm_err(&dev_priv->drm, + drm_err(&i915->drm, "Failed to initiate HDCP key load (%d)\n", ret); - return ret; + goto err; } } else { - intel_de_write(dev_priv, HDCP_KEY_CONF, HDCP_KEY_LOAD_TRIGGER); + intel_de_write(i915, HDCP_KEY_CONF, HDCP_KEY_LOAD_TRIGGER); } /* Wait for the keys to load (500us) */ - ret = __intel_wait_for_register(&dev_priv->uncore, HDCP_KEY_STATUS, + ret = __intel_wait_for_register(&i915->uncore, HDCP_KEY_STATUS, HDCP_KEY_LOAD_DONE, HDCP_KEY_LOAD_DONE, 10, 1, &val); - if (ret) - return ret; - else if (!(val & HDCP_KEY_LOAD_STATUS)) - return -ENXIO; + if (ret) { + goto err; + } else if (!(val & HDCP_KEY_LOAD_STATUS)) { + ret = -ENXIO; + goto err; + } /* Send Aksv over to PCH display for use in authentication */ - intel_de_write(dev_priv, HDCP_KEY_CONF, HDCP_AKSV_SEND_TRIGGER); + intel_de_write(i915, HDCP_KEY_CONF, HDCP_AKSV_SEND_TRIGGER); return 0; + +err: + intel_hdcp_clear_keys(i915); + return ret; } /* Returns updated SHA-1 index */ @@ -399,25 +347,21 @@ u32 intel_hdcp_get_repeater_ctl(struct drm_i915_private *dev_priv, } } -static -int intel_hdcp_validate_v_prime(struct intel_connector *connector, - const struct intel_hdcp_shim *shim, - u8 *ksv_fifo, u8 num_downstream, u8 *bstatus) +int intel_hdcp1_store_ksv_fifo(struct drm_connector *drm_connector, + u8 *ksv_fifo, u8 num_downstream, u8 *bstatus, + u32 *v_prime, void *driver_data) { + struct intel_connector *connector = to_intel_connector(drm_connector); struct intel_digital_port *dig_port = intel_attached_dig_port(connector); struct drm_i915_private *dev_priv = to_i915(connector->base.dev); enum transcoder cpu_transcoder = connector->hdcp.cpu_transcoder; enum port port = dig_port->base.port; - u32 vprime, sha_text, sha_leftovers, rep_ctl; + u32 sha_text, sha_leftovers, rep_ctl; int ret, i, j, sha_idx; /* Process V' values from the receiver */ - for (i = 0; i < DRM_HDCP_V_PRIME_NUM_PARTS; i++) { - ret = shim->read_v_prime_part(dig_port, i, &vprime); - if (ret) - return ret; - intel_de_write(dev_priv, HDCP_SHA_V_PRIME(i), vprime); - } + for (i = 0; i < DRM_HDCP_V_PRIME_NUM_PARTS; i++) + intel_de_write(dev_priv, HDCP_SHA_V_PRIME(i), v_prime[i]); /* * We need to write the concatenation of all device KSVs, BINFO (DP) || @@ -642,131 +586,38 @@ int intel_hdcp_validate_v_prime(struct intel_connector *connector, return 0; } -/* Implements Part 2 of the HDCP authorization procedure */ -static -int intel_hdcp_auth_downstream(struct intel_connector *connector) +int intel_hdcp1_store_receiver_info(struct drm_connector *drm_connector, + u32 *ksv, u32 status, u8 caps, + bool repeater_present, void *driver_data) { + struct intel_connector *connector = to_intel_connector(drm_connector); struct intel_digital_port *dig_port = intel_attached_dig_port(connector); struct drm_i915_private *dev_priv = to_i915(connector->base.dev); - const struct intel_hdcp_shim *shim = connector->hdcp.shim; - u8 bstatus[2], num_downstream, *ksv_fifo; - int ret, i, tries = 3; - - ret = intel_hdcp_poll_ksv_fifo(dig_port, shim); - if (ret) { - drm_dbg_kms(&dev_priv->drm, - "KSV list failed to become ready (%d)\n", ret); - return ret; - } - - ret = shim->read_bstatus(dig_port, bstatus); - if (ret) - return ret; - - if (DRM_HDCP_MAX_DEVICE_EXCEEDED(bstatus[0]) || - DRM_HDCP_MAX_CASCADE_EXCEEDED(bstatus[1])) { - drm_dbg_kms(&dev_priv->drm, "Max Topology Limit Exceeded\n"); - return -EPERM; - } - - /* - * When repeater reports 0 device count, HDCP1.4 spec allows disabling - * the HDCP encryption. That implies that repeater can't have its own - * display. As there is no consumption of encrypted content in the - * repeater with 0 downstream devices, we are failing the - * authentication. - */ - num_downstream = DRM_HDCP_NUM_DOWNSTREAM(bstatus[0]); - if (num_downstream == 0) { - drm_dbg_kms(&dev_priv->drm, - "Repeater with zero downstream devices\n"); - return -EINVAL; - } - - ksv_fifo = kcalloc(DRM_HDCP_KSV_LEN, num_downstream, GFP_KERNEL); - if (!ksv_fifo) { - drm_dbg_kms(&dev_priv->drm, "Out of mem: ksv_fifo\n"); - return -ENOMEM; - } - - ret = shim->read_ksv_fifo(dig_port, num_downstream, ksv_fifo); - if (ret) - goto err; - - if (drm_hdcp_check_ksvs_revoked(&dev_priv->drm, ksv_fifo, - num_downstream) > 0) { - drm_err(&dev_priv->drm, "Revoked Ksv(s) in ksv_fifo\n"); - ret = -EPERM; - goto err; - } + enum transcoder cpu_transcoder = connector->hdcp.cpu_transcoder; + enum port port = dig_port->base.port; - /* - * When V prime mismatches, DP Spec mandates re-read of - * V prime atleast twice. - */ - for (i = 0; i < tries; i++) { - ret = intel_hdcp_validate_v_prime(connector, shim, - ksv_fifo, num_downstream, - bstatus); - if (!ret) - break; - } + intel_de_write(dev_priv, HDCP_BKSVLO(dev_priv, cpu_transcoder, port), + ksv[0]); + intel_de_write(dev_priv, HDCP_BKSVHI(dev_priv, cpu_transcoder, port), + ksv[1]); - if (i == tries) { - drm_dbg_kms(&dev_priv->drm, - "V Prime validation failed.(%d)\n", ret); - goto err; - } + if (repeater_present) + intel_de_write(dev_priv, HDCP_REP_CTL, + intel_hdcp_get_repeater_ctl( + dev_priv, cpu_transcoder, port)); - drm_dbg_kms(&dev_priv->drm, "HDCP is enabled (%d downstream devices)\n", - num_downstream); - ret = 0; -err: - kfree(ksv_fifo); - return ret; + return 0; } -/* Implements Part 1 of the HDCP authorization procedure */ -static int intel_hdcp_auth(struct intel_connector *connector) +int intel_hdcp1_read_an(struct drm_connector *drm_connector, + struct drm_hdcp_an *an) { + struct intel_connector *connector = to_intel_connector(drm_connector); struct intel_digital_port *dig_port = intel_attached_dig_port(connector); struct drm_i915_private *dev_priv = to_i915(connector->base.dev); - struct intel_hdcp *hdcp = &connector->hdcp; - const struct intel_hdcp_shim *shim = hdcp->shim; enum transcoder cpu_transcoder = connector->hdcp.cpu_transcoder; enum port port = dig_port->base.port; - unsigned long r0_prime_gen_start; - int ret, i, tries = 2; - union { - u32 reg[2]; - u8 shim[DRM_HDCP_AN_LEN]; - } an; - union { - u32 reg[2]; - u8 shim[DRM_HDCP_KSV_LEN]; - } bksv; - union { - u32 reg; - u8 shim[DRM_HDCP_RI_LEN]; - } ri; - bool repeater_present, hdcp_capable; - - /* - * Detects whether the display is HDCP capable. Although we check for - * valid Bksv below, the HDCP over DP spec requires that we check - * whether the display supports HDCP before we write An. For HDMI - * displays, this is not necessary. - */ - if (shim->hdcp_capable) { - ret = shim->hdcp_capable(dig_port, &hdcp_capable); - if (ret) - return ret; - if (!hdcp_capable) { - drm_dbg_kms(&dev_priv->drm, - "Panel is not HDCP capable\n"); - return -EINVAL; - } - } + int i; /* Initialize An with 2 random values and acquire it */ for (i = 0; i < 2; i++) @@ -784,152 +635,109 @@ static int intel_hdcp_auth(struct intel_connector *connector) return -ETIMEDOUT; } - an.reg[0] = intel_de_read(dev_priv, - HDCP_ANLO(dev_priv, cpu_transcoder, port)); - an.reg[1] = intel_de_read(dev_priv, - HDCP_ANHI(dev_priv, cpu_transcoder, port)); - ret = shim->write_an_aksv(dig_port, an.shim); - if (ret) - return ret; + an->words[0] = intel_de_read(dev_priv, + HDCP_ANLO(dev_priv, cpu_transcoder, port)); + an->words[1] = intel_de_read(dev_priv, + HDCP_ANHI(dev_priv, cpu_transcoder, port)); - r0_prime_gen_start = jiffies; - - memset(&bksv, 0, sizeof(bksv)); - - ret = intel_hdcp_read_valid_bksv(dig_port, shim, bksv.shim); - if (ret < 0) - return ret; - - if (drm_hdcp_check_ksvs_revoked(&dev_priv->drm, bksv.shim, 1) > 0) { - drm_err(&dev_priv->drm, "BKSV is revoked\n"); - return -EPERM; - } + return 0; +} - intel_de_write(dev_priv, HDCP_BKSVLO(dev_priv, cpu_transcoder, port), - bksv.reg[0]); - intel_de_write(dev_priv, HDCP_BKSVHI(dev_priv, cpu_transcoder, port), - bksv.reg[1]); +int intel_hdcp1_enable_encryption(struct drm_connector *drm_connector, + void *driver_data) +{ + struct intel_connector *connector = to_intel_connector(drm_connector); + struct intel_digital_port *dig_port = + intel_attached_dig_port(connector); + struct drm_i915_private *i915 = to_i915(connector->base.dev); + enum transcoder cpu_transcoder = connector->hdcp.cpu_transcoder; + enum port port = dig_port->base.port; - ret = shim->repeater_present(dig_port, &repeater_present); - if (ret) - return ret; - if (repeater_present) - intel_de_write(dev_priv, HDCP_REP_CTL, - intel_hdcp_get_repeater_ctl(dev_priv, cpu_transcoder, port)); + intel_de_write(i915, HDCP_CONF(i915, cpu_transcoder, port), + HDCP_CONF_AUTH_AND_ENC); - ret = shim->toggle_signalling(dig_port, cpu_transcoder, true); - if (ret) - return ret; + return 0; +} - intel_de_write(dev_priv, HDCP_CONF(dev_priv, cpu_transcoder, port), - HDCP_CONF_AUTH_AND_ENC); +int intel_hdcp1_wait_for_r0(struct drm_connector *drm_connector, + void *driver_data) +{ + struct intel_connector *connector = to_intel_connector(drm_connector); + struct intel_digital_port *dig_port = + intel_attached_dig_port(connector); + struct drm_i915_private *i915 = to_i915(connector->base.dev); + enum transcoder cpu_transcoder = connector->hdcp.cpu_transcoder; + enum port port = dig_port->base.port; /* Wait for R0 ready */ - if (wait_for(intel_de_read(dev_priv, HDCP_STATUS(dev_priv, cpu_transcoder, port)) & - (HDCP_STATUS_R0_READY | HDCP_STATUS_ENC), 1)) { - drm_err(&dev_priv->drm, "Timed out waiting for R0 ready\n"); + if (wait_for((intel_de_read(i915, + HDCP_STATUS(i915, cpu_transcoder, port))) & + (HDCP_STATUS_R0_READY | HDCP_STATUS_ENC), 1)) { + drm_err(&i915->drm, "Timed out waiting for R0 ready\n"); return -ETIMEDOUT; } - /* - * Wait for R0' to become available. The spec says 100ms from Aksv, but - * some monitors can take longer than this. We'll set the timeout at - * 300ms just to be sure. - * - * On DP, there's an R0_READY bit available but no such bit - * exists on HDMI. Since the upper-bound is the same, we'll just do - * the stupid thing instead of polling on one and not the other. - */ - wait_remaining_ms_from_jiffies(r0_prime_gen_start, 300); - - tries = 3; + return 0; +} - /* - * DP HDCP Spec mandates the two more reattempt to read R0, incase - * of R0 mismatch. - */ - for (i = 0; i < tries; i++) { - ri.reg = 0; - ret = shim->read_ri_prime(dig_port, ri.shim); - if (ret) - return ret; - intel_de_write(dev_priv, - HDCP_RPRIME(dev_priv, cpu_transcoder, port), - ri.reg); +int intel_hdcp1_match_ri(struct drm_connector *drm_connector, u32 ri_prime, + void *driver_data) +{ + struct intel_connector *connector = to_intel_connector(drm_connector); + struct intel_digital_port *dig_port = + intel_attached_dig_port(connector); + struct drm_i915_private *i915 = to_i915(connector->base.dev); + enum transcoder cpu_transcoder = connector->hdcp.cpu_transcoder; + enum port port = dig_port->base.port; - /* Wait for Ri prime match */ - if (!wait_for(intel_de_read(dev_priv, HDCP_STATUS(dev_priv, cpu_transcoder, port)) & - (HDCP_STATUS_RI_MATCH | HDCP_STATUS_ENC), 1)) - break; - } + intel_de_write(i915, HDCP_RPRIME(i915, cpu_transcoder, port), + ri_prime); - if (i == tries) { - drm_dbg_kms(&dev_priv->drm, - "Timed out waiting for Ri prime match (%x)\n", - intel_de_read(dev_priv, HDCP_STATUS(dev_priv, - cpu_transcoder, port))); + /* Wait for Ri prime match */ + if (wait_for(intel_de_read(i915, + HDCP_STATUS(i915, cpu_transcoder, port)) & + (HDCP_STATUS_RI_MATCH | HDCP_STATUS_ENC), + 1)) return -ETIMEDOUT; - } + + return 0; +} + +int intel_hdcp1_post_encryption(struct drm_connector *drm_connector, + void *driver_data) +{ + struct intel_connector *connector = to_intel_connector(drm_connector); + struct intel_digital_port *dig_port = + intel_attached_dig_port(connector); + struct drm_i915_private *i915 = to_i915(connector->base.dev); + enum transcoder cpu_transcoder = connector->hdcp.cpu_transcoder; + enum port port = dig_port->base.port; /* Wait for encryption confirmation */ - if (intel_de_wait_for_set(dev_priv, - HDCP_STATUS(dev_priv, cpu_transcoder, port), + if (intel_de_wait_for_set(i915, + HDCP_STATUS(i915, cpu_transcoder, port), HDCP_STATUS_ENC, HDCP_ENCRYPT_STATUS_CHANGE_TIMEOUT_MS)) { - drm_err(&dev_priv->drm, "Timed out waiting for encryption\n"); + drm_err(&i915->drm, "Timed out waiting for encryption\n"); return -ETIMEDOUT; } - /* DP MST Auth Part 1 Step 2.a and Step 2.b */ - if (shim->stream_encryption) { - ret = shim->stream_encryption(connector, true); - if (ret) { - drm_err(&dev_priv->drm, "[%s:%d] Failed to enable HDCP 1.4 stream enc\n", - connector->base.name, connector->base.base.id); - return ret; - } - drm_dbg_kms(&dev_priv->drm, "HDCP 1.4 transcoder: %s stream encrypted\n", - transcoder_name(hdcp->stream_transcoder)); - } - - if (repeater_present) - return intel_hdcp_auth_downstream(connector); - - drm_dbg_kms(&dev_priv->drm, "HDCP is enabled (no repeater present)\n"); return 0; } -static int _intel_hdcp_disable(struct intel_connector *connector) +int intel_hdcp1_disable(struct drm_connector *drm_connector, void *driver_data) { + struct intel_connector *connector = to_intel_connector(drm_connector); struct intel_digital_port *dig_port = intel_attached_dig_port(connector); struct drm_i915_private *dev_priv = to_i915(connector->base.dev); struct intel_hdcp *hdcp = &connector->hdcp; enum port port = dig_port->base.port; enum transcoder cpu_transcoder = hdcp->cpu_transcoder; u32 repeater_ctl; - int ret; drm_dbg_kms(&dev_priv->drm, "[%s:%d] HDCP is being disabled...\n", connector->base.name, connector->base.base.id); - if (hdcp->shim->stream_encryption) { - ret = hdcp->shim->stream_encryption(connector, false); - if (ret) { - drm_err(&dev_priv->drm, "[%s:%d] Failed to disable HDCP 1.4 stream enc\n", - connector->base.name, connector->base.base.id); - return ret; - } - drm_dbg_kms(&dev_priv->drm, "HDCP 1.4 transcoder: %s stream encryption disabled\n", - transcoder_name(hdcp->stream_transcoder)); - /* - * If there are other connectors on this port using HDCP, - * don't disable it until it disabled HDCP encryption for - * all connectors in MST topology. - */ - if (dig_port->num_hdcp_streams > 0) - return 0; - } - hdcp->hdcp_encrypted = false; intel_de_write(dev_priv, HDCP_CONF(dev_priv, cpu_transcoder, port), 0); if (intel_de_wait_for_clear(dev_priv, @@ -945,190 +753,9 @@ static int _intel_hdcp_disable(struct intel_connector *connector) intel_de_write(dev_priv, HDCP_REP_CTL, intel_de_read(dev_priv, HDCP_REP_CTL) & ~repeater_ctl); - ret = hdcp->shim->toggle_signalling(dig_port, cpu_transcoder, false); - if (ret) { - drm_err(&dev_priv->drm, "Failed to disable HDCP signalling\n"); - return ret; - } - - drm_dbg_kms(&dev_priv->drm, "HDCP is disabled\n"); return 0; } -static int _intel_hdcp_enable(struct intel_connector *connector) -{ - struct drm_i915_private *dev_priv = to_i915(connector->base.dev); - struct intel_hdcp *hdcp = &connector->hdcp; - int i, ret, tries = 3; - - drm_dbg_kms(&dev_priv->drm, "[%s:%d] HDCP is being enabled...\n", - connector->base.name, connector->base.base.id); - - if (!hdcp_key_loadable(dev_priv)) { - drm_err(&dev_priv->drm, "HDCP key Load is not possible\n"); - return -ENXIO; - } - - for (i = 0; i < KEY_LOAD_TRIES; i++) { - ret = intel_hdcp_load_keys(dev_priv); - if (!ret) - break; - intel_hdcp_clear_keys(dev_priv); - } - if (ret) { - drm_err(&dev_priv->drm, "Could not load HDCP keys, (%d)\n", - ret); - return ret; - } - - /* Incase of authentication failures, HDCP spec expects reauth. */ - for (i = 0; i < tries; i++) { - ret = intel_hdcp_auth(connector); - if (!ret) { - hdcp->hdcp_encrypted = true; - return 0; - } - - drm_dbg_kms(&dev_priv->drm, "HDCP Auth failure (%d)\n", ret); - - /* Ensuring HDCP encryption and signalling are stopped. */ - _intel_hdcp_disable(connector); - } - - drm_dbg_kms(&dev_priv->drm, - "HDCP authentication failed (%d tries/%d)\n", tries, ret); - return ret; -} - -static struct intel_connector *intel_hdcp_to_connector(struct intel_hdcp *hdcp) -{ - return container_of(hdcp, struct intel_connector, hdcp); -} - -static void intel_hdcp_update_value(struct intel_connector *connector, - u64 value, bool update_property) -{ - struct drm_device *dev = connector->base.dev; - struct intel_digital_port *dig_port = intel_attached_dig_port(connector); - struct intel_hdcp *hdcp = &connector->hdcp; - - drm_WARN_ON(connector->base.dev, !mutex_is_locked(&hdcp->mutex)); - - if (hdcp->value == value) - return; - - drm_WARN_ON(dev, !mutex_is_locked(&dig_port->hdcp_mutex)); - - if (hdcp->value == DRM_MODE_CONTENT_PROTECTION_ENABLED) { - if (!drm_WARN_ON(dev, dig_port->num_hdcp_streams == 0)) - dig_port->num_hdcp_streams--; - } else if (value == DRM_MODE_CONTENT_PROTECTION_ENABLED) { - dig_port->num_hdcp_streams++; - } - - hdcp->value = value; - if (update_property) { - drm_connector_get(&connector->base); - schedule_work(&hdcp->prop_work); - } -} - -/* Implements Part 3 of the HDCP authorization procedure */ -static int intel_hdcp_check_link(struct intel_connector *connector) -{ - struct intel_digital_port *dig_port = intel_attached_dig_port(connector); - struct drm_i915_private *dev_priv = to_i915(connector->base.dev); - struct intel_hdcp *hdcp = &connector->hdcp; - enum port port = dig_port->base.port; - enum transcoder cpu_transcoder; - int ret = 0; - - mutex_lock(&hdcp->mutex); - mutex_lock(&dig_port->hdcp_mutex); - - cpu_transcoder = hdcp->cpu_transcoder; - - /* Check_link valid only when HDCP1.4 is enabled */ - if (hdcp->value != DRM_MODE_CONTENT_PROTECTION_ENABLED || - !hdcp->hdcp_encrypted) { - ret = -EINVAL; - goto out; - } - - if (drm_WARN_ON(&dev_priv->drm, - !intel_hdcp_in_use(dev_priv, cpu_transcoder, port))) { - drm_err(&dev_priv->drm, - "%s:%d HDCP link stopped encryption,%x\n", - connector->base.name, connector->base.base.id, - intel_de_read(dev_priv, HDCP_STATUS(dev_priv, cpu_transcoder, port))); - ret = -ENXIO; - intel_hdcp_update_value(connector, - DRM_MODE_CONTENT_PROTECTION_DESIRED, - true); - goto out; - } - - if (hdcp->shim->check_link(dig_port, connector)) { - if (hdcp->value != DRM_MODE_CONTENT_PROTECTION_UNDESIRED) { - intel_hdcp_update_value(connector, - DRM_MODE_CONTENT_PROTECTION_ENABLED, true); - } - goto out; - } - - drm_dbg_kms(&dev_priv->drm, - "[%s:%d] HDCP link failed, retrying authentication\n", - connector->base.name, connector->base.base.id); - - ret = _intel_hdcp_disable(connector); - if (ret) { - drm_err(&dev_priv->drm, "Failed to disable hdcp (%d)\n", ret); - intel_hdcp_update_value(connector, - DRM_MODE_CONTENT_PROTECTION_DESIRED, - true); - goto out; - } - - ret = _intel_hdcp_enable(connector); - if (ret) { - drm_err(&dev_priv->drm, "Failed to enable hdcp (%d)\n", ret); - intel_hdcp_update_value(connector, - DRM_MODE_CONTENT_PROTECTION_DESIRED, - true); - goto out; - } - -out: - mutex_unlock(&dig_port->hdcp_mutex); - mutex_unlock(&hdcp->mutex); - return ret; -} - -static void intel_hdcp_prop_work(struct work_struct *work) -{ - struct intel_hdcp *hdcp = container_of(work, struct intel_hdcp, - prop_work); - struct intel_connector *connector = intel_hdcp_to_connector(hdcp); - struct drm_i915_private *dev_priv = to_i915(connector->base.dev); - - drm_modeset_lock(&dev_priv->drm.mode_config.connection_mutex, NULL); - mutex_lock(&hdcp->mutex); - - /* - * This worker is only used to flip between ENABLED/DESIRED. Either of - * those to UNDESIRED is handled by core. If value == UNDESIRED, - * we're running just after hdcp has been disabled, so just exit - */ - if (hdcp->value != DRM_MODE_CONTENT_PROTECTION_UNDESIRED) - drm_hdcp_update_content_protection(&connector->base, - hdcp->value); - - mutex_unlock(&hdcp->mutex); - drm_modeset_unlock(&dev_priv->drm.mode_config.connection_mutex); - - drm_connector_put(&connector->base); -} - bool is_hdcp_supported(struct drm_i915_private *dev_priv, enum port port) { return RUNTIME_INFO(dev_priv)->has_hdcp && @@ -1961,8 +1588,9 @@ static int hdcp2_authenticate_and_encrypt(struct intel_connector *connector) return ret; } -static int _intel_hdcp2_enable(struct intel_connector *connector) +int intel_hdcp2_enable(struct drm_connector *drm_connector, void *driver_data) { + struct intel_connector *connector = to_intel_connector(drm_connector); struct drm_i915_private *i915 = to_i915(connector->base.dev); struct intel_hdcp *hdcp = &connector->hdcp; int ret; @@ -1986,8 +1614,8 @@ static int _intel_hdcp2_enable(struct intel_connector *connector) return 0; } -static int -_intel_hdcp2_disable(struct intel_connector *connector, bool hdcp2_link_recovery) +static int _intel_hdcp2_disable(struct intel_connector *connector, + bool hdcp2_link_recovery, void *driver_data) { struct intel_digital_port *dig_port = intel_attached_dig_port(connector); struct drm_i915_private *i915 = to_i915(connector->base.dev); @@ -2024,9 +1652,17 @@ _intel_hdcp2_disable(struct intel_connector *connector, bool hdcp2_link_recovery return ret; } +int intel_hdcp2_disable(struct drm_connector *drm_connector, void *driver_data) +{ + return _intel_hdcp2_disable(to_intel_connector(drm_connector), false, + driver_data); +} + /* Implements the Link Integrity Check for HDCP2.2 */ -static int intel_hdcp2_check_link(struct intel_connector *connector) +int intel_hdcp2_check_link(struct drm_connector *drm_connector, + void *driver_data) { + struct intel_connector *connector = to_intel_connector(drm_connector); struct intel_digital_port *dig_port = intel_attached_dig_port(connector); struct drm_i915_private *dev_priv = to_i915(connector->base.dev); struct intel_hdcp *hdcp = &connector->hdcp; @@ -2034,109 +1670,39 @@ static int intel_hdcp2_check_link(struct intel_connector *connector) enum transcoder cpu_transcoder; int ret = 0; - mutex_lock(&hdcp->mutex); - mutex_lock(&dig_port->hdcp_mutex); cpu_transcoder = hdcp->cpu_transcoder; /* 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 (!hdcp->hdcp2_encrypted) + return -EINVAL; if (drm_WARN_ON(&dev_priv->drm, !intel_hdcp2_in_use(dev_priv, cpu_transcoder, port))) { drm_err(&dev_priv->drm, "HDCP2.2 link stopped the encryption, %x\n", intel_de_read(dev_priv, HDCP2_STATUS(dev_priv, cpu_transcoder, port))); - ret = -ENXIO; - _intel_hdcp2_disable(connector, true); - intel_hdcp_update_value(connector, - DRM_MODE_CONTENT_PROTECTION_DESIRED, - true); - goto out; + return -ENXIO; } ret = hdcp->shim->check_2_2_link(dig_port, connector); - if (ret == HDCP_LINK_PROTECTED) { - if (hdcp->value != DRM_MODE_CONTENT_PROTECTION_UNDESIRED) { - intel_hdcp_update_value(connector, - DRM_MODE_CONTENT_PROTECTION_ENABLED, - true); - } - goto out; - } + if (ret == HDCP_LINK_PROTECTED) + return 0; if (ret == HDCP_TOPOLOGY_CHANGE) { - if (hdcp->value == DRM_MODE_CONTENT_PROTECTION_UNDESIRED) - goto out; - drm_dbg_kms(&dev_priv->drm, "HDCP2.2 Downstream topology change\n"); ret = hdcp2_authenticate_repeater_topology(connector); - if (!ret) { - intel_hdcp_update_value(connector, - DRM_MODE_CONTENT_PROTECTION_ENABLED, - true); - goto out; - } - drm_dbg_kms(&dev_priv->drm, - "[%s:%d] Repeater topology auth failed.(%d)\n", - connector->base.name, connector->base.base.id, - ret); - } else { - drm_dbg_kms(&dev_priv->drm, - "[%s:%d] HDCP2.2 link failed, retrying auth\n", - connector->base.name, connector->base.base.id); - } - - ret = _intel_hdcp2_disable(connector, true); - if (ret) { - drm_err(&dev_priv->drm, - "[%s:%d] Failed to disable hdcp2.2 (%d)\n", - connector->base.name, connector->base.base.id, ret); - intel_hdcp_update_value(connector, - DRM_MODE_CONTENT_PROTECTION_DESIRED, true); - goto out; - } + if (!ret) + return 0; - ret = _intel_hdcp2_enable(connector); - if (ret) { drm_dbg_kms(&dev_priv->drm, - "[%s:%d] Failed to enable hdcp2.2 (%d)\n", - connector->base.name, connector->base.base.id, - ret); - intel_hdcp_update_value(connector, - DRM_MODE_CONTENT_PROTECTION_DESIRED, - true); - goto out; + "[%s:%d] Repeater topology auth failed.(%d)\n", + connector->base.name, connector->base.base.id, ret); } -out: - mutex_unlock(&dig_port->hdcp_mutex); - 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), - struct intel_hdcp, - check_work); - struct intel_connector *connector = intel_hdcp_to_connector(hdcp); - - if (drm_connector_is_unregistered(&connector->base)) - return; - - 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); -} - static int i915_hdcp_component_bind(struct device *i915_kdev, struct device *mei_kdev, void *data) { @@ -2189,22 +1755,28 @@ static enum mei_fw_tc intel_get_mei_fw_tc(enum transcoder cpu_transcoder) } } -static int -_intel_hdcp_setup(struct intel_connector *connector, - const struct intel_crtc_state *pipe_config, u8 content_type) +int intel_hdcp_setup(struct drm_connector *connector, + struct drm_atomic_state *state, void *driver_data) { - struct drm_i915_private *dev_priv = to_i915(connector->base.dev); - struct intel_digital_port *dig_port = intel_attached_dig_port(connector); - struct intel_hdcp *hdcp = &connector->hdcp; + struct drm_i915_private *dev_priv = to_i915(connector->dev); + struct intel_connector *intel_connector = to_intel_connector(connector); + struct intel_digital_port *dig_port = + intel_attached_dig_port(intel_connector); + struct drm_connector_state *conn_state; + struct drm_crtc_state *crtc_state; + struct intel_crtc_state *pipe_config; + struct intel_hdcp *hdcp = &intel_connector->hdcp; int ret = 0; - if (!connector->encoder) { + if (!intel_connector->encoder) { drm_err(&dev_priv->drm, "[%s:%d] encoder is not initialized\n", - connector->base.name, connector->base.base.id); + connector->name, connector->base.id); return -ENODEV; } - hdcp->content_type = content_type; + conn_state = drm_atomic_get_new_connector_state(state, connector); + crtc_state = drm_atomic_get_new_crtc_state(state, conn_state->crtc); + pipe_config = to_intel_crtc_state(crtc_state); if (intel_crtc_has_type(pipe_config, INTEL_OUTPUT_DP_MST)) { hdcp->cpu_transcoder = pipe_config->mst_master_transcoder; @@ -2321,7 +1893,6 @@ int intel_hdcp_init(struct intel_connector *connector, { struct drm_i915_private *dev_priv = to_i915(connector->base.dev); struct intel_hdcp *hdcp = &connector->hdcp; - int ret; if (!shim) return -EINVAL; @@ -2329,174 +1900,12 @@ int intel_hdcp_init(struct intel_connector *connector, if (is_hdcp2_supported(dev_priv)) intel_hdcp2_init(connector, dig_port, shim); - ret = - drm_connector_attach_content_protection_property(&connector->base, - hdcp->hdcp2_supported); - if (ret) { - hdcp->hdcp2_supported = false; - kfree(dig_port->hdcp_port_data.streams); - return ret; - } - hdcp->shim = shim; - mutex_init(&hdcp->mutex); - INIT_DELAYED_WORK(&hdcp->check_work, intel_hdcp_check_work); - INIT_WORK(&hdcp->prop_work, intel_hdcp_prop_work); init_waitqueue_head(&hdcp->cp_irq_queue); return 0; } -int intel_hdcp_enable(struct intel_connector *connector, - const struct intel_crtc_state *pipe_config, u8 content_type) -{ - struct drm_i915_private *dev_priv = to_i915(connector->base.dev); - struct intel_digital_port *dig_port = intel_attached_dig_port(connector); - struct intel_hdcp *hdcp = &connector->hdcp; - unsigned long check_link_interval = DRM_HDCP_CHECK_PERIOD_MS; - bool capable; - int ret = -EINVAL; - - if (!hdcp->shim) - return -ENOENT; - - mutex_lock(&hdcp->mutex); - mutex_lock(&dig_port->hdcp_mutex); - drm_WARN_ON(&dev_priv->drm, - hdcp->value == DRM_MODE_CONTENT_PROTECTION_ENABLED); - - ret = _intel_hdcp_setup(connector, pipe_config, content_type); - if (ret) - goto out; - - /* - * 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. - */ - ret = intel_hdcp2_capable(connector, &capable); - if (capable) { - ret = _intel_hdcp2_enable(connector); - if (!ret) { - check_link_interval = DRM_HDCP2_CHECK_PERIOD_MS; - goto out; - } - } - - /* - * When HDCP2.2 fails and Content Type is not Type1, HDCP1.4 will - * be attempted. - */ - ret = intel_hdcp_capable(connector, &capable); - if (ret) - goto out; - - if (capable && hdcp->content_type != DRM_MODE_HDCP_CONTENT_TYPE1) - ret = _intel_hdcp_enable(connector); - -out: - if (!ret) { - schedule_delayed_work(&hdcp->check_work, check_link_interval); - intel_hdcp_update_value(connector, - DRM_MODE_CONTENT_PROTECTION_ENABLED, - true); - } - - mutex_unlock(&dig_port->hdcp_mutex); - mutex_unlock(&hdcp->mutex); - return ret; -} - -int intel_hdcp_disable(struct intel_connector *connector) -{ - struct intel_digital_port *dig_port = intel_attached_dig_port(connector); - struct intel_hdcp *hdcp = &connector->hdcp; - int ret = 0; - - if (!hdcp->shim) - return -ENOENT; - - mutex_lock(&hdcp->mutex); - mutex_lock(&dig_port->hdcp_mutex); - - if (hdcp->value == DRM_MODE_CONTENT_PROTECTION_UNDESIRED) - goto out; - - intel_hdcp_update_value(connector, - DRM_MODE_CONTENT_PROTECTION_UNDESIRED, false); - if (hdcp->hdcp2_encrypted) - ret = _intel_hdcp2_disable(connector, false); - else if (hdcp->hdcp_encrypted) - ret = _intel_hdcp_disable(connector); - -out: - mutex_unlock(&dig_port->hdcp_mutex); - mutex_unlock(&hdcp->mutex); - cancel_delayed_work_sync(&hdcp->check_work); - return ret; -} - -void intel_hdcp_update_pipe(struct intel_atomic_state *state, - struct intel_encoder *encoder, - const struct intel_crtc_state *crtc_state, - const struct drm_connector_state *conn_state) -{ - struct intel_connector *connector = - to_intel_connector(conn_state->connector); - struct intel_hdcp *hdcp = &connector->hdcp; - bool content_protection_type_changed, desired_and_not_enabled = false; - - if (!connector->hdcp.shim) - return; - - content_protection_type_changed = - (conn_state->hdcp_content_type != hdcp->content_type && - conn_state->content_protection != - DRM_MODE_CONTENT_PROTECTION_UNDESIRED); - - /* - * During the HDCP encryption session if Type change is requested, - * disable the HDCP and reenable it with new TYPE value. - */ - if (conn_state->content_protection == - DRM_MODE_CONTENT_PROTECTION_UNDESIRED || - content_protection_type_changed) - intel_hdcp_disable(connector); - - /* - * Mark the hdcp state as DESIRED after the hdcp disable of type - * change procedure. - */ - if (content_protection_type_changed) { - mutex_lock(&hdcp->mutex); - hdcp->value = DRM_MODE_CONTENT_PROTECTION_DESIRED; - drm_connector_get(&connector->base); - schedule_work(&hdcp->prop_work); - mutex_unlock(&hdcp->mutex); - } - - if (conn_state->content_protection == - DRM_MODE_CONTENT_PROTECTION_DESIRED) { - mutex_lock(&hdcp->mutex); - /* Avoid enabling hdcp, if it already ENABLED */ - desired_and_not_enabled = - hdcp->value != DRM_MODE_CONTENT_PROTECTION_ENABLED; - mutex_unlock(&hdcp->mutex); - /* - * If HDCP already ENABLED and CP property is DESIRED, schedule - * prop_work to update correct CP property to user space. - */ - if (!desired_and_not_enabled && !content_protection_type_changed) { - drm_connector_get(&connector->base); - schedule_work(&hdcp->prop_work); - } - } - - if (desired_and_not_enabled || content_protection_type_changed) - intel_hdcp_enable(connector, - crtc_state, - (u8)conn_state->hdcp_content_type); -} - void intel_hdcp_component_fini(struct drm_i915_private *dev_priv) { mutex_lock(&dev_priv->display.hdcp.comp_mutex); @@ -2518,33 +1927,8 @@ void intel_hdcp_cleanup(struct intel_connector *connector) if (!hdcp->shim) return; - /* - * If the connector is registered, it's possible userspace could kick - * off another HDCP enable, which would re-spawn the workers. - */ - drm_WARN_ON(connector->base.dev, - connector->base.registration_state == DRM_CONNECTOR_REGISTERED); - - /* - * Now that the connector is not registered, check_work won't be run, - * but cancel any outstanding instances of it - */ - cancel_delayed_work_sync(&hdcp->check_work); - - /* - * We don't cancel prop_work in the same way as check_work since it - * requires connection_mutex which could be held while calling this - * function. Instead, we rely on the connector references grabbed before - * scheduling prop_work to ensure the connector is alive when prop_work - * is run. So if we're in the destroy path (which is where this - * function should be called), we're "guaranteed" that prop_work is not - * active (tl;dr This Should Never Happen). - */ - drm_WARN_ON(connector->base.dev, work_pending(&hdcp->prop_work)); - - mutex_lock(&hdcp->mutex); + drm_hdcp_helper_destroy(connector->hdcp_helper_data); hdcp->shim = NULL; - mutex_unlock(&hdcp->mutex); } /* Handles the CP_IRQ raised from the DP HDCP sink */ @@ -2558,5 +1942,5 @@ void intel_hdcp_handle_cp_irq(struct intel_connector *connector) atomic_inc(&connector->hdcp.cp_irq_count); wake_up_all(&connector->hdcp.cp_irq_queue); - schedule_delayed_work(&hdcp->check_work, 0); + drm_hdcp_helper_schedule_hdcp_check(connector->hdcp_helper_data); } diff --git a/drivers/gpu/drm/i915/display/intel_hdcp.h b/drivers/gpu/drm/i915/display/intel_hdcp.h index f06f6e5a2b1ad..fa677ccfc8507 100644 --- a/drivers/gpu/drm/i915/display/intel_hdcp.h +++ b/drivers/gpu/drm/i915/display/intel_hdcp.h @@ -10,8 +10,10 @@ #define HDCP_ENCRYPT_STATUS_CHANGE_TIMEOUT_MS 50 +struct drm_atomic_state; struct drm_connector; struct drm_connector_state; +struct drm_hdcp_an; struct drm_i915_private; struct intel_atomic_state; struct intel_connector; @@ -25,18 +27,37 @@ enum transcoder; int intel_hdcp_init(struct intel_connector *connector, struct intel_digital_port *dig_port, const struct intel_hdcp_shim *hdcp_shim); -int intel_hdcp_enable(struct intel_connector *connector, - const struct intel_crtc_state *pipe_config, u8 content_type); -int intel_hdcp_disable(struct intel_connector *connector); -void intel_hdcp_update_pipe(struct intel_atomic_state *state, - struct intel_encoder *encoder, - const struct intel_crtc_state *crtc_state, - const struct drm_connector_state *conn_state); -bool is_hdcp_supported(struct drm_i915_private *dev_priv, enum port port); +int intel_hdcp_setup(struct drm_connector *drm_connector, + struct drm_atomic_state *state, void *driver_data); +int intel_hdcp_load_keys(struct drm_connector *drm_connector, + void *driver_data); +bool is_hdcp_supported(struct drm_i915_private *i915, enum port port); int intel_hdcp_capable(struct intel_connector *connector, bool *capable); -int intel_hdcp2_capable(struct intel_connector *connector, bool *capable); -void intel_hdcp_component_init(struct drm_i915_private *dev_priv); -void intel_hdcp_component_fini(struct drm_i915_private *dev_priv); +int intel_hdcp2_capable(struct drm_connector *drm_connector, bool *capable); +int intel_hdcp2_enable(struct drm_connector *drm_connector, void *driver_data); +int intel_hdcp2_disable(struct drm_connector *drm_connector, void *driver_data); +int intel_hdcp2_check_link(struct drm_connector *drm_connector, + void *driver_data); +int intel_hdcp1_store_receiver_info(struct drm_connector *drm_connector, + u32 *ksv, u32 status, u8 caps, + bool repeater_present, void *driver_data); +int intel_hdcp1_read_an(struct drm_connector *drm_connector, + struct drm_hdcp_an *an); +int intel_hdcp1_enable_encryption(struct drm_connector *drm_connector, + void *driver_data); +int intel_hdcp1_wait_for_r0(struct drm_connector *drm_connector, + void *driver_data); +int intel_hdcp1_match_ri(struct drm_connector *drm_connector, u32 ri_prime, + void *driver_data); +int intel_hdcp1_post_encryption(struct drm_connector *drm_connector, + void *driver_data); +int intel_hdcp1_store_ksv_fifo(struct drm_connector *drm_connector, + u8 *ksv_fifo, u8 num_downstream, u8 *bstatus, + u32 *v_prime, void *driver_data); +int intel_hdcp1_check_link(struct drm_connector *drm_connector); +int intel_hdcp1_disable(struct drm_connector *drm_connector, void *driver_data); +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); diff --git a/drivers/gpu/drm/i915/display/intel_hdmi.c b/drivers/gpu/drm/i915/display/intel_hdmi.c index c0ce6d3dc5056..db7772e1f391d 100644 --- a/drivers/gpu/drm/i915/display/intel_hdmi.c +++ b/drivers/gpu/drm/i915/display/intel_hdmi.c @@ -1330,17 +1330,25 @@ static int intel_hdmi_hdcp_write(struct intel_digital_port *dig_port, return ret; } -static -int intel_hdmi_hdcp_write_an_aksv(struct intel_digital_port *dig_port, - u8 *an) +static int intel_hdmi_hdcp1_send_an_aksv(struct drm_connector *drm_connector, + void *driver_data) { + struct intel_connector *connector = to_intel_connector(drm_connector); + struct intel_digital_port *dig_port = + intel_attached_dig_port(connector); struct drm_i915_private *i915 = to_i915(dig_port->base.base.dev); struct intel_hdmi *hdmi = &dig_port->hdmi; struct i2c_adapter *adapter = intel_gmbus_get_adapter(i915, hdmi->ddc_bus); + struct drm_hdcp_an an; int ret; - ret = intel_hdmi_hdcp_write(dig_port, DRM_HDCP_DDC_AN, an, + /* Output An first, that's easy */ + ret = intel_hdcp1_read_an(drm_connector, &an); + if (ret) + return ret; + + ret = intel_hdmi_hdcp_write(dig_port, DRM_HDCP_DDC_AN, an.bytes, DRM_HDCP_AN_LEN); if (ret) { drm_dbg_kms(&i915->drm, "Write An over DDC failed (%d)\n", @@ -1356,120 +1364,6 @@ int intel_hdmi_hdcp_write_an_aksv(struct intel_digital_port *dig_port, return 0; } -static int intel_hdmi_hdcp_read_bksv(struct intel_digital_port *dig_port, - u8 *bksv) -{ - struct drm_i915_private *i915 = to_i915(dig_port->base.base.dev); - - int ret; - ret = intel_hdmi_hdcp_read(dig_port, DRM_HDCP_DDC_BKSV, bksv, - DRM_HDCP_KSV_LEN); - if (ret) - drm_dbg_kms(&i915->drm, "Read Bksv over DDC failed (%d)\n", - ret); - return ret; -} - -static -int intel_hdmi_hdcp_read_bstatus(struct intel_digital_port *dig_port, - u8 *bstatus) -{ - struct drm_i915_private *i915 = to_i915(dig_port->base.base.dev); - - int ret; - ret = intel_hdmi_hdcp_read(dig_port, DRM_HDCP_DDC_BSTATUS, - bstatus, DRM_HDCP_BSTATUS_LEN); - if (ret) - drm_dbg_kms(&i915->drm, "Read bstatus over DDC failed (%d)\n", - ret); - return ret; -} - -static -int intel_hdmi_hdcp_repeater_present(struct intel_digital_port *dig_port, - bool *repeater_present) -{ - struct drm_i915_private *i915 = to_i915(dig_port->base.base.dev); - int ret; - u8 val; - - ret = intel_hdmi_hdcp_read(dig_port, DRM_HDCP_DDC_BCAPS, &val, 1); - if (ret) { - drm_dbg_kms(&i915->drm, "Read bcaps over DDC failed (%d)\n", - ret); - return ret; - } - *repeater_present = val & DRM_HDCP_DDC_BCAPS_REPEATER_PRESENT; - return 0; -} - -static -int intel_hdmi_hdcp_read_ri_prime(struct intel_digital_port *dig_port, - u8 *ri_prime) -{ - struct drm_i915_private *i915 = to_i915(dig_port->base.base.dev); - - int ret; - ret = intel_hdmi_hdcp_read(dig_port, DRM_HDCP_DDC_RI_PRIME, - ri_prime, DRM_HDCP_RI_LEN); - if (ret) - drm_dbg_kms(&i915->drm, "Read Ri' over DDC failed (%d)\n", - ret); - return ret; -} - -static -int intel_hdmi_hdcp_read_ksv_ready(struct intel_digital_port *dig_port, - bool *ksv_ready) -{ - struct drm_i915_private *i915 = to_i915(dig_port->base.base.dev); - int ret; - u8 val; - - ret = intel_hdmi_hdcp_read(dig_port, DRM_HDCP_DDC_BCAPS, &val, 1); - if (ret) { - drm_dbg_kms(&i915->drm, "Read bcaps over DDC failed (%d)\n", - ret); - return ret; - } - *ksv_ready = val & DRM_HDCP_DDC_BCAPS_KSV_FIFO_READY; - return 0; -} - -static -int intel_hdmi_hdcp_read_ksv_fifo(struct intel_digital_port *dig_port, - int num_downstream, u8 *ksv_fifo) -{ - struct drm_i915_private *i915 = to_i915(dig_port->base.base.dev); - int ret; - ret = intel_hdmi_hdcp_read(dig_port, DRM_HDCP_DDC_KSV_FIFO, - ksv_fifo, num_downstream * DRM_HDCP_KSV_LEN); - if (ret) { - drm_dbg_kms(&i915->drm, - "Read ksv fifo over DDC failed (%d)\n", ret); - return ret; - } - return 0; -} - -static -int intel_hdmi_hdcp_read_v_prime_part(struct intel_digital_port *dig_port, - int i, u32 *part) -{ - struct drm_i915_private *i915 = to_i915(dig_port->base.base.dev); - int ret; - - if (i >= DRM_HDCP_V_PRIME_NUM_PARTS) - return -EINVAL; - - ret = intel_hdmi_hdcp_read(dig_port, DRM_HDCP_DDC_V_PRIME(i), - part, DRM_HDCP_V_PRIME_PART_LEN); - if (ret) - drm_dbg_kms(&i915->drm, "Read V'[%d] over DDC failed (%d)\n", - i, ret); - return ret; -} - static int kbl_repositioning_enc_en_signal(struct intel_connector *connector, enum transcoder cpu_transcoder) { @@ -1538,50 +1432,42 @@ int intel_hdmi_hdcp_toggle_signalling(struct intel_digital_port *dig_port, return 0; } -static -bool intel_hdmi_hdcp_check_link_once(struct intel_digital_port *dig_port, - struct intel_connector *connector) +static int +intel_hdmi_hdcp1_enable_encryption(struct drm_connector *drm_connector, + void *driver_data) { - struct drm_i915_private *i915 = to_i915(dig_port->base.base.dev); - enum port port = dig_port->base.port; + struct intel_connector *connector = to_intel_connector(drm_connector); + struct intel_digital_port *dig_port = + intel_attached_dig_port(connector); enum transcoder cpu_transcoder = connector->hdcp.cpu_transcoder; int ret; - union { - u32 reg; - u8 shim[DRM_HDCP_RI_LEN]; - } ri; - ret = intel_hdmi_hdcp_read_ri_prime(dig_port, ri.shim); + ret = intel_hdmi_hdcp_toggle_signalling(dig_port, cpu_transcoder, true); if (ret) - return false; - - intel_de_write(i915, HDCP_RPRIME(i915, cpu_transcoder, port), ri.reg); + return ret; - /* Wait for Ri prime match */ - if (wait_for((intel_de_read(i915, HDCP_STATUS(i915, cpu_transcoder, port)) & - (HDCP_STATUS_RI_MATCH | HDCP_STATUS_ENC)) == - (HDCP_STATUS_RI_MATCH | HDCP_STATUS_ENC), 1)) { - drm_dbg_kms(&i915->drm, "Ri' mismatch detected (%x)\n", - intel_de_read(i915, HDCP_STATUS(i915, cpu_transcoder, - port))); - return false; - } - return true; + return intel_hdcp1_enable_encryption(drm_connector, driver_data); } -static -bool intel_hdmi_hdcp_check_link(struct intel_digital_port *dig_port, - struct intel_connector *connector) +static int intel_hdmi_hdcp1_disable(struct drm_connector *drm_connector, + void *driver_data) { - struct drm_i915_private *i915 = to_i915(dig_port->base.base.dev); - int retry; + struct intel_connector *connector = to_intel_connector(drm_connector); + struct intel_digital_port *dig_port = + intel_attached_dig_port(connector); + enum transcoder cpu_transcoder = connector->hdcp.cpu_transcoder; + struct drm_i915_private *i915 = to_i915(connector->base.dev); + int ret; - for (retry = 0; retry < 3; retry++) - if (intel_hdmi_hdcp_check_link_once(dig_port, connector)) - return true; + ret = intel_hdcp1_disable(drm_connector, driver_data); + if (ret) { + drm_err(&i915->drm, "[%s:%d] Failed to disable HDCP 1.4\n", + connector->base.name, connector->base.base.id); + return ret; + } - drm_err(&i915->drm, "Link check failed\n"); - return false; + return intel_hdmi_hdcp_toggle_signalling(dig_port, cpu_transcoder, + false); } struct hdcp2_hdmi_msg_timeout { @@ -1747,13 +1633,19 @@ int intel_hdmi_hdcp2_check_link(struct intel_digital_port *dig_port, return ret; } -static -int intel_hdmi_hdcp2_capable(struct intel_digital_port *dig_port, - bool *capable) +static int intel_hdmi_hdcp2_capable(struct drm_connector *drm_connector, + bool *capable, void *driver_data) { + struct intel_connector *connector = to_intel_connector(drm_connector); + struct intel_digital_port *dig_port = + intel_attached_dig_port(connector); u8 hdcp2_version; int ret; + ret = intel_hdcp2_capable(drm_connector, capable); + if (ret || !capable) + return ret; + *capable = false; ret = intel_hdmi_hdcp_read(dig_port, HDCP_2_2_HDMI_REG_VER_OFFSET, &hdcp2_version, sizeof(hdcp2_version)); @@ -1764,23 +1656,30 @@ int intel_hdmi_hdcp2_capable(struct intel_digital_port *dig_port, } static const struct intel_hdcp_shim intel_hdmi_hdcp_shim = { - .write_an_aksv = intel_hdmi_hdcp_write_an_aksv, - .read_bksv = intel_hdmi_hdcp_read_bksv, - .read_bstatus = intel_hdmi_hdcp_read_bstatus, - .repeater_present = intel_hdmi_hdcp_repeater_present, - .read_ri_prime = intel_hdmi_hdcp_read_ri_prime, - .read_ksv_ready = intel_hdmi_hdcp_read_ksv_ready, - .read_ksv_fifo = intel_hdmi_hdcp_read_ksv_fifo, - .read_v_prime_part = intel_hdmi_hdcp_read_v_prime_part, .toggle_signalling = intel_hdmi_hdcp_toggle_signalling, - .check_link = intel_hdmi_hdcp_check_link, .write_2_2_msg = intel_hdmi_hdcp2_write_msg, .read_2_2_msg = intel_hdmi_hdcp2_read_msg, - .check_2_2_link = intel_hdmi_hdcp2_check_link, - .hdcp_2_2_capable = intel_hdmi_hdcp2_capable, + .check_2_2_link = intel_hdmi_hdcp2_check_link, .protocol = HDCP_PROTOCOL_HDMI, }; +static const struct drm_hdcp_helper_funcs intel_hdmi_hdcp_helper_funcs = { + .setup = intel_hdcp_setup, + .load_keys = intel_hdcp_load_keys, + .hdcp2_capable = intel_hdmi_hdcp2_capable, + .hdcp2_enable = intel_hdcp2_enable, + .hdcp2_check_link = intel_hdcp2_check_link, + .hdcp2_disable = intel_hdcp2_disable, + .hdcp1_send_an_aksv = intel_hdmi_hdcp1_send_an_aksv, + .hdcp1_store_receiver_info = intel_hdcp1_store_receiver_info, + .hdcp1_enable_encryption = intel_hdmi_hdcp1_enable_encryption, + .hdcp1_wait_for_r0 = intel_hdcp1_wait_for_r0, + .hdcp1_match_ri = intel_hdcp1_match_ri, + .hdcp1_post_encryption = intel_hdcp1_post_encryption, + .hdcp1_store_ksv_fifo = intel_hdcp1_store_ksv_fifo, + .hdcp1_disable = intel_hdmi_hdcp1_disable, +}; + static int intel_hdmi_source_max_tmds_clock(struct intel_encoder *encoder) { struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); @@ -2928,6 +2827,36 @@ void intel_infoframe_init(struct intel_digital_port *dig_port) } } +static void intel_hdmi_hdcp_init(struct intel_digital_port *dig_port, + struct intel_connector *connector) +{ + struct drm_i915_private *i915 = to_i915(connector->base.dev); + struct intel_encoder *intel_encoder = &dig_port->base; + enum port port = intel_encoder->port; + struct drm_hdcp_helper_data *data; + int ret; + + if (!is_hdcp_supported(i915, port)) + return; + + data = drm_hdcp_helper_initialize_hdmi( + &connector->base, &intel_hdmi_hdcp_helper_funcs, true); + if (IS_ERR(data)) { + drm_dbg_kms(&i915->drm, "HDCP init failed ret=%ld\n", + PTR_ERR(data)); + return; + } + + ret = intel_hdcp_init(connector, dig_port, &intel_hdmi_hdcp_shim); + if (ret) { + drm_hdcp_helper_destroy(data); + drm_dbg_kms(&i915->drm, "Intel HDCP init failed ret=%d\n", ret); + return; + } + + connector->hdcp_helper_data = data; +} + void intel_hdmi_init_connector(struct intel_digital_port *dig_port, struct intel_connector *intel_connector) { @@ -2982,13 +2911,7 @@ void intel_hdmi_init_connector(struct intel_digital_port *dig_port, intel_connector_attach_encoder(intel_connector, intel_encoder); intel_hdmi->attached_connector = intel_connector; - if (is_hdcp_supported(dev_priv, port)) { - int ret = intel_hdcp_init(intel_connector, dig_port, - &intel_hdmi_hdcp_shim); - if (ret) - drm_dbg_kms(&dev_priv->drm, - "HDCP init failed, skipping.\n"); - } + intel_hdmi_hdcp_init(dig_port, intel_connector); /* For G4X desktop chip, PEG_BAND_GAP_DATA 3:0 must first be written * 0xd. Failure to do so will result in spurious interrupts being From patchwork Tue Apr 11 19:21:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Yacoub X-Patchwork-Id: 13208161 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 63230C7619A for ; Tue, 11 Apr 2023 19:22:08 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 310F110E651; Tue, 11 Apr 2023 19:22:00 +0000 (UTC) Received: from mail-yw1-x112e.google.com (mail-yw1-x112e.google.com [IPv6:2607:f8b0:4864:20::112e]) by gabe.freedesktop.org (Postfix) with ESMTPS id A950010E650 for ; Tue, 11 Apr 2023 19:21:57 +0000 (UTC) Received: by mail-yw1-x112e.google.com with SMTP id 00721157ae682-54f64b29207so69054927b3.8 for ; Tue, 11 Apr 2023 12:21:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1681240917; x=1683832917; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=S78ehGNcDXdB6PvXIQgj+BoJDjok2LjR/kDyIilwHqs=; b=Zcp4fx46FuwusWTIR+qP9EPW1du53rK+VLJZ8OKLx6vaBLemzbuKKUYHg1D/nYrq+I dly/PO9Girb4taDpFZUw/38ozkZK2i0GRP/LhO6r3XhjUE6M/USnnxTxu9yp++SwDOXn KDeHYPnrFKoF2eF+IYXfOotPgLz+YNK/1Sdjc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1681240917; x=1683832917; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=S78ehGNcDXdB6PvXIQgj+BoJDjok2LjR/kDyIilwHqs=; b=U2sw7cePkLMfDoib0Uz3aHDwFvRMll2FXhK2kNAlRQlRBtyQvil6g4F+hrpT+LTOl6 PQwqsgUqCRvRPvRNWwKvPlPhTX/vczEhkeYY/uKOgVDLwciTfmSujwkQQuhCQnYlOBDI B8DTQQJxZIYxaTQHTLY4eKkplA+jKNXq9b35/mTMjam8UZ5uPN7K94or6Hvk1MhZsz4I QHtJHoI4dnQ7EErAh2lMEdSTRHORQVIomaSg02/UnDAsRMGGUkMo/gsvMnM9pA6OnSFf OlIKpGkWS9Jsmo7xgj9R97XmiBGrX3Bq7HEjCprkx4S5kCJSrLFMkk3czSYxOEJAaWqB NUFA== X-Gm-Message-State: AAQBX9eeWYBeLcDJuyKjo4RTPJ963K6UIG7nosCCqkjPNUvY17bcnGeu dJ4f2W6X7dsRqXsZOkHh7tQHRw== X-Google-Smtp-Source: AKy350bcTjzT51HoLIsG0FPcN3AEDdEgImgO14Esl7GpPfBp5hBRv9repUyxfbcdLPsrIq408XQMQA== X-Received: by 2002:a0d:e801:0:b0:541:a189:bc74 with SMTP id r1-20020a0de801000000b00541a189bc74mr2977093ywe.41.1681240917283; Tue, 11 Apr 2023 12:21:57 -0700 (PDT) Received: from localhost ([2620:0:1035:15:2991:9b76:4e62:65bf]) by smtp.gmail.com with UTF8SMTPSA id g34-20020a81ae62000000b0054f8a3624dbsm85546ywk.145.2023.04.11.12.21.56 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 11 Apr 2023 12:21:57 -0700 (PDT) From: Mark Yacoub X-Google-Original-From: Mark Yacoub To: Rob Clark , Abhinav Kumar , Dmitry Baryshkov , Sean Paul , David Airlie , Daniel Vetter , Rob Herring , Krzysztof Kozlowski , Kuogee Hsieh Date: Tue, 11 Apr 2023 15:21:32 -0400 Message-Id: <20230411192134.508113-9-markyacoub@google.com> X-Mailer: git-send-email 2.40.0.577.gac1e443424-goog In-Reply-To: <20230411192134.508113-1-markyacoub@google.com> References: <20230411192134.508113-1-markyacoub@google.com> MIME-Version: 1.0 Subject: [Intel-gfx] [PATCH v9 08/10] dt-bindings: msm/dp: Add bindings for HDCP registers X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Rob Herring , devicetree@vger.kernel.org, Mark Yacoub , intel-gfx@lists.freedesktop.org, dianders@chromium.org, dri-devel@lists.freedesktop.org, Stephen Boyd , seanpaul@chromium.org, linux-arm-msm@vger.kernel.org, freedreno@lists.freedesktop.org, linux-kernel@vger.kernel.org Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" From: Sean Paul Add the bindings for the MSM DisplayPort HDCP registers which are required to write the HDCP key into the display controller as well as the registers to enable HDCP authentication/key exchange/encryption. Cc: Rob Herring Cc: Stephen Boyd Reviewed-by: Rob Herring Reviewed-by: Douglas Anderson Signed-off-by: Sean Paul Signed-off-by: Mark Yacoub --- Changes in v2: -Drop register range names (Stephen) -Fix yaml errors (Rob) Changes in v3: -Add new compatible string for dp-hdcp -Add descriptions to reg -Add minItems/maxItems to reg -Make reg depend on the new hdcp compatible string Changes in v4: -Rebase on Bjorn's multi-dp patchset Changes in v4.5: -Remove maxItems from reg (Rob) -Remove leading zeros in example (Rob) Changes in v5: -None Changes in v6: -Rebased: modify minItems instead of adding it as new line. Changes in v7: -Revert the change to minItems -Added the maxItems to Reg .../devicetree/bindings/display/msm/dp-controller.yaml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Documentation/devicetree/bindings/display/msm/dp-controller.yaml b/Documentation/devicetree/bindings/display/msm/dp-controller.yaml index 0e8d8df686dc9..4763a2ff12fb7 100644 --- a/Documentation/devicetree/bindings/display/msm/dp-controller.yaml +++ b/Documentation/devicetree/bindings/display/msm/dp-controller.yaml @@ -34,6 +34,8 @@ properties: - description: link register block - description: p0 register block - description: p1 register block + - description: (Optional) Registers for HDCP device key injection + - description: (Optional) Registers for HDCP TrustZone interaction interrupts: maxItems: 1 @@ -159,6 +161,7 @@ allOf: aux-bus: false reg: minItems: 5 + maxItems: 7 required: - "#sound-dai-cells" @@ -176,7 +179,9 @@ examples: <0xae90200 0x200>, <0xae90400 0xc00>, <0xae91000 0x400>, - <0xae91400 0x400>; + <0xae91400 0x400>, + <0xaed1000 0x174>, + <0xaee1000 0x2c>; interrupt-parent = <&mdss>; interrupts = <12>; clocks = <&dispcc DISP_CC_MDSS_AHB_CLK>, From patchwork Tue Apr 11 19:21:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Yacoub X-Patchwork-Id: 13208163 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id CC2F9C77B73 for ; Tue, 11 Apr 2023 19:22:10 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id C75C110E652; Tue, 11 Apr 2023 19:22:03 +0000 (UTC) Received: from mail-yb1-xb35.google.com (mail-yb1-xb35.google.com [IPv6:2607:f8b0:4864:20::b35]) by gabe.freedesktop.org (Postfix) with ESMTPS id C9C4810E651 for ; Tue, 11 Apr 2023 19:21:59 +0000 (UTC) Received: by mail-yb1-xb35.google.com with SMTP id h198so15874219ybg.12 for ; Tue, 11 Apr 2023 12:21:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1681240919; x=1683832919; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=/UKK5UX1sxA/fn51ycSNCkY1kfW7huepZ1JtlF3gmCU=; b=MODAKOLAe1mrFHbVLmSTy4tXpGrI6txQIJfm5HU7lN1WAtmS7oqJ7klQsvQAaLo3Mv k8OMqRaomz/vkCR9BzzUkJJv28dzjJvu2nY8yN03/fbdeRP2ul5C3BOPODjVzN1fjkmK /WmeqkGRYSOVzBsjuQZyqTqHPf3MZiaBOuQN0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1681240919; x=1683832919; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=/UKK5UX1sxA/fn51ycSNCkY1kfW7huepZ1JtlF3gmCU=; b=VNPTAqEDbxhfUVSgWM1G/YG55bFmfyUsPOAiYa9vByi5vuBox4Af84xaBH5UzjC7vJ o8oREOGFyKyn/5Vuv52vBQYXlddWGNn68aCwTKL7sxezpkolkqYiVfIhpkSPgRKeuL6f n0xQllWqC1gyudYRYsr4mCZj9g1MSpz1dRwd1S9FqsGcc9/jXzC3w7Mlbdf4H7xpQKxo bydY6vK+y+2v69+d0bmbMTh2iV4X0uQFS2qAz7pX8c0sFdIQCm6G3TQTkOsyxHdLudXT Ou/oz4bQuzAdoxCv7RTDBJitS8c0WAgJyGaiFEG4b/lauVbfQJI8KlqlgDfkT5LucF2G 1SWA== X-Gm-Message-State: AAQBX9dqDGWjsW5c/PwsAEnJ4/G8nsYehRqHfSIKxIV3PlyDr4S4dVJF u2HNausYjR8HIWoSwTh8E+6SaQ== X-Google-Smtp-Source: AKy350Y0AFVRCh26uZEEXl/caeeSKSUSmctYd6tMGvN9clthojK4HZRfhP/DRCF/UTqrV0O1hw6atA== X-Received: by 2002:a25:6d87:0:b0:b8e:e918:33ac with SMTP id i129-20020a256d87000000b00b8ee91833acmr5372721ybc.1.1681240919489; Tue, 11 Apr 2023 12:21:59 -0700 (PDT) Received: from localhost ([2620:0:1035:15:2991:9b76:4e62:65bf]) by smtp.gmail.com with UTF8SMTPSA id u74-20020a25ab50000000b00b7767ca7485sm3834942ybi.34.2023.04.11.12.21.58 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 11 Apr 2023 12:21:59 -0700 (PDT) From: Mark Yacoub X-Google-Original-From: Mark Yacoub To: Andy Gross , Bjorn Andersson , Konrad Dybcio , Rob Herring , Krzysztof Kozlowski Date: Tue, 11 Apr 2023 15:21:33 -0400 Message-Id: <20230411192134.508113-10-markyacoub@google.com> X-Mailer: git-send-email 2.40.0.577.gac1e443424-goog In-Reply-To: <20230411192134.508113-1-markyacoub@google.com> References: <20230411192134.508113-1-markyacoub@google.com> MIME-Version: 1.0 Subject: [Intel-gfx] [PATCH v9 09/10] arm64: dts: qcom: sc7180: Add support for HDCP in dp-controller X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: devicetree@vger.kernel.org, Mark Yacoub , intel-gfx@lists.freedesktop.org, dianders@chromium.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, seanpaul@chromium.org, linux-arm-msm@vger.kernel.org, dmitry.baryshkov@linaro.org, freedreno@lists.freedesktop.org Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" From: Sean Paul Add the register ranges required for HDCP key injection and HDCP TrustZone interaction as described in the dt-bindings for the sc7180 dp controller. Reviewed-by: Dmitry Baryshkov Reviewed-by: Douglas Anderson Signed-off-by: Sean Paul Signed-off-by: Mark Yacoub --- Changes in v3: -Split off into a new patch containing just the dts change (Stephen) -Add hdcp compatible string (Stephen) Changes in v4: -Rebase on Bjorn's multi-dp patchset Changes in v5: -Put the tz register offsets in trogdor dtsi (Rob C) Changes in v6: -Rebased: Removed modifications in sc7180.dtsi as it's already upstream Changes in v7: -Change registers offset arch/arm64/boot/dts/qcom/sc7180-trogdor.dtsi | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/arch/arm64/boot/dts/qcom/sc7180-trogdor.dtsi b/arch/arm64/boot/dts/qcom/sc7180-trogdor.dtsi index 423630c4d02c7..89d913fa6e3eb 100644 --- a/arch/arm64/boot/dts/qcom/sc7180-trogdor.dtsi +++ b/arch/arm64/boot/dts/qcom/sc7180-trogdor.dtsi @@ -822,6 +822,14 @@ &mdss_dp { status = "okay"; pinctrl-names = "default"; pinctrl-0 = <&dp_hot_plug_det>; + + reg = <0 0x0ae90000 0 0x200>, + <0 0x0ae90200 0 0x200>, + <0 0x0ae90400 0 0xc00>, + <0 0x0ae91000 0 0x400>, + <0 0x0ae91400 0 0x400>, + <0 0x0aed1000 0 0x174>, + <0 0x0aee1000 0 0x2c>; }; &mdss_dp_out { From patchwork Tue Apr 11 19:21:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Yacoub X-Patchwork-Id: 13208164 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 50273C7619A for ; Tue, 11 Apr 2023 19:22:21 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 706A610E631; Tue, 11 Apr 2023 19:22:20 +0000 (UTC) Received: from mail-yb1-xb33.google.com (mail-yb1-xb33.google.com [IPv6:2607:f8b0:4864:20::b33]) by gabe.freedesktop.org (Postfix) with ESMTPS id 2091410E631 for ; Tue, 11 Apr 2023 19:22:19 +0000 (UTC) Received: by mail-yb1-xb33.google.com with SMTP id e127so9364222ybf.8 for ; Tue, 11 Apr 2023 12:22:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1681240939; x=1683832939; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=JFo0f1Sr1+yQ3QLGhxacntBMMbw5RN6UTvDoJXnJ62I=; b=RsFrEqtG4HporUh9/3w+k/W9443eV9+pJmn5QcOfBBCOs+tcaXPovsKWjoFop+CHcd Jq3IcOySgUotQtSSXzivOThUDArl/exLxnk9kalw/milzlwKJ9KrlxMl8v9Eg0VBbFDu QWzfKtn/gjz7bTp5zUoO72NuA/zNwVzzXnfuQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1681240939; x=1683832939; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=JFo0f1Sr1+yQ3QLGhxacntBMMbw5RN6UTvDoJXnJ62I=; b=YPIL5Fwq03l4Yi+LC2NNNELBZ7oteJlsVc1xQHoaIVhLn+nDJ3D1PBeAjrTUHkFIkL FuKh0mdW26rj/3pG2GoMO8SL4J3kNKO/EhYQTvS+a+4tSejD0OtcDEncJAswTAC6xYJ1 ogii+s6AHp/QmdCsu9CjAohP2ah90OfndJ+gE/1wsjrMwiX5+VLJIpUuCDdSHws89cAh G+FT107pn8HOkiuHW4mZbhkG25ayWQ1yhT32f5hXgljoKSIx/wvWZg4tn5kmLkHseiRd zVOom1pXt/w1mt66XNva+7pa2pJGS7O0Yu1d0ZBawed+dTViuhdbTgxonjkOQ57J/zsl gz2w== X-Gm-Message-State: AAQBX9dxUsGNxCWlYdqQSIa2AxXaPujCmf1ctCx2UUkVPcQETY2Hy1vw 3Am3lkbDZoIvTppq++2gnO7cwA== X-Google-Smtp-Source: AKy350YewVx7oxQIWCkA3iv9V+QhEdGnsSj/AULCRKYUBlUOrdw8ND56WLkjy17pgkx1IAZ/unzHrQ== X-Received: by 2002:a25:ae08:0:b0:b73:1eab:1723 with SMTP id a8-20020a25ae08000000b00b731eab1723mr9519126ybj.29.1681240938528; Tue, 11 Apr 2023 12:22:18 -0700 (PDT) Received: from localhost ([2620:0:1035:15:2991:9b76:4e62:65bf]) by smtp.gmail.com with UTF8SMTPSA id 130-20020a250a88000000b00b8bd10ad9b0sm3847876ybk.11.2023.04.11.12.22.17 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 11 Apr 2023 12:22:18 -0700 (PDT) From: Mark Yacoub X-Google-Original-From: Mark Yacoub To: Rob Clark , Abhinav Kumar , Dmitry Baryshkov , Sean Paul , David Airlie , Daniel Vetter Date: Tue, 11 Apr 2023 15:21:34 -0400 Message-Id: <20230411192134.508113-11-markyacoub@google.com> X-Mailer: git-send-email 2.40.0.577.gac1e443424-goog In-Reply-To: <20230411192134.508113-1-markyacoub@google.com> References: <20230411192134.508113-1-markyacoub@google.com> MIME-Version: 1.0 Subject: [Intel-gfx] [PATCH v9 10/10] drm/msm: Implement HDCP 1.x using the new drm HDCP helpers X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Yacoub , intel-gfx@lists.freedesktop.org, dianders@chromium.org, dri-devel@lists.freedesktop.org, Stephen Boyd , seanpaul@chromium.org, linux-arm-msm@vger.kernel.org, freedreno@lists.freedesktop.org, linux-kernel@vger.kernel.org Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" From: Sean Paul Add HDCP 1.x support to msm DP bridges using the new HDCP helpers. Cc: Stephen Boyd Reviewed-by: Stephen Boyd Signed-off-by: Sean Paul Signed-off-by: Mark Yacoub --- Changes in v2: -Squash [1] into this patch with the following changes (Stephen) -Update the sc7180 dtsi file -Remove resource names and just use index (Stephen) Changes in v3: -Split out the dtsi change from v2 (Stephen) -Fix set-but-unused warning identified by 0-day -Fix up a couple of style nits (Stephen) -Store HDCP key directly in dp_hdcp struct (Stephen) -Remove wmb in HDCP key initialization, move an_seed (Stephen) -Use FIELD_PREP for bstatus/bcaps (Stephen) -#define read_poll_timeout values (Stephen) -Remove unnecessary parentheses in dp_hdcp_store_ksv_fifo (Stephen) -Add compatible string for hdcp (Stephen) -Rename dp_hdcp_write_* functions (Abhinav) -Add 1us delay between An reads (Abhinav) -Delete unused dp_hdcp_read_* functions Changes in v4: -Rebase on Bjorn's multi-dp patchset Changes in v5: -Change return check of drm_hdcp_helper_initialize_dp() (Stephen) Changes in v6: -Change the tracking of the state from connector state to bridge as state as drm_connector_state is no longer tracked and the functionality has moved to msm_dp_bridge Changes in v7: -Use dp bridge to maintain the state with no use for connector Changes in v8: -Move the hdcp read/write to dp_catalog Changes in v9: -Remove display type specific helper funcs init from driver drivers/gpu/drm/msm/Kconfig | 1 + drivers/gpu/drm/msm/Makefile | 1 + drivers/gpu/drm/msm/dp/dp_catalog.c | 156 +++++++++++ drivers/gpu/drm/msm/dp/dp_catalog.h | 18 ++ drivers/gpu/drm/msm/dp/dp_debug.c | 46 +++- drivers/gpu/drm/msm/dp/dp_debug.h | 11 +- drivers/gpu/drm/msm/dp/dp_display.c | 39 ++- drivers/gpu/drm/msm/dp/dp_display.h | 5 + drivers/gpu/drm/msm/dp/dp_drm.c | 39 ++- drivers/gpu/drm/msm/dp/dp_drm.h | 7 + drivers/gpu/drm/msm/dp/dp_hdcp.c | 389 ++++++++++++++++++++++++++++ drivers/gpu/drm/msm/dp/dp_hdcp.h | 33 +++ drivers/gpu/drm/msm/dp/dp_parser.c | 14 + drivers/gpu/drm/msm/dp/dp_parser.h | 4 + drivers/gpu/drm/msm/dp/dp_reg.h | 30 ++- drivers/gpu/drm/msm/msm_atomic.c | 19 ++ 16 files changed, 800 insertions(+), 12 deletions(-) create mode 100644 drivers/gpu/drm/msm/dp/dp_hdcp.c create mode 100644 drivers/gpu/drm/msm/dp/dp_hdcp.h diff --git a/drivers/gpu/drm/msm/Kconfig b/drivers/gpu/drm/msm/Kconfig index 4d8fddbdcd9e0..1c369ca2ea6e3 100644 --- a/drivers/gpu/drm/msm/Kconfig +++ b/drivers/gpu/drm/msm/Kconfig @@ -15,6 +15,7 @@ config DRM_MSM select REGULATOR select DRM_DP_AUX_BUS select DRM_DISPLAY_DP_HELPER + select DRM_DISPLAY_HDCP_HELPER select DRM_DISPLAY_HELPER select DRM_KMS_HELPER select DRM_PANEL diff --git a/drivers/gpu/drm/msm/Makefile b/drivers/gpu/drm/msm/Makefile index 7274c41228ed9..a73e7b858af27 100644 --- a/drivers/gpu/drm/msm/Makefile +++ b/drivers/gpu/drm/msm/Makefile @@ -122,6 +122,7 @@ msm-$(CONFIG_DRM_MSM_DP)+= dp/dp_aux.o \ dp/dp_ctrl.o \ dp/dp_display.o \ dp/dp_drm.o \ + dp/dp_hdcp.o \ dp/dp_hpd.o \ dp/dp_link.o \ dp/dp_panel.o \ diff --git a/drivers/gpu/drm/msm/dp/dp_catalog.c b/drivers/gpu/drm/msm/dp/dp_catalog.c index 676279d0ca8d9..a1395e0c67d56 100644 --- a/drivers/gpu/drm/msm/dp/dp_catalog.c +++ b/drivers/gpu/drm/msm/dp/dp_catalog.c @@ -16,6 +16,8 @@ #include "dp_catalog.h" #include "dp_reg.h" +#include + #define POLLING_SLEEP_US 1000 #define POLLING_TIMEOUT_US 10000 @@ -47,6 +49,14 @@ #define DP_INTERRUPT_STATUS2_MASK \ (DP_INTERRUPT_STATUS2 << DP_INTERRUPT_STATUS_MASK_SHIFT) +#define DP_AN_READ_DELAY_US 1 +/* Key offsets based on hdcp_key mmio */ +#define DP_HDCP_KEY_BASE 0x30 +#define DP_HDCP_KEY_MSB(x) (DP_HDCP_KEY_BASE + (x * 8)) +#define DP_HDCP_KEY_LSB(x) (DP_HDCP_KEY_MSB(x) + 4) +#define DP_HDCP_KEY_VALID 0x170 +#define DP_HDCP_SW_KEY_VALID BIT(0) + struct dp_catalog_private { struct device *dev; struct drm_device *drm_dev; @@ -133,6 +143,18 @@ static inline void dp_write_link(struct dp_catalog_private *catalog, writel(data, catalog->io->dp_controller.link.base + offset); } +static inline void dp_write_hdcp_key(struct dp_catalog_private *catalog, + u32 offset, u32 val) +{ + writel(val, catalog->io->dp_controller.hdcp_key.base + offset); +} + +static inline void dp_write_hdcp_tz(struct dp_catalog_private *catalog, + u32 offset, u32 val) +{ + writel(val, catalog->io->dp_controller.hdcp_tz.base + offset); +} + /* aux related catalog functions */ u32 dp_catalog_aux_read_data(struct dp_catalog *dp_catalog) { @@ -1094,3 +1116,137 @@ void dp_catalog_audio_sfe_level(struct dp_catalog *dp_catalog) dp_write_link(catalog, REG_DP_MAINLINK_LEVELS, mainlink_levels); } + +u32 dp_catalog_hdcp_read_ahb(struct dp_catalog *dp_catalog, u32 offset) +{ + struct dp_catalog_private *catalog = + container_of(dp_catalog, struct dp_catalog_private, dp_catalog); + + return dp_read_ahb(catalog, offset); +} + +void dp_catalog_hdcp_write_ahb(struct dp_catalog *dp_catalog, u32 offset, + u32 val) +{ + struct dp_catalog_private *catalog = + container_of(dp_catalog, struct dp_catalog_private, dp_catalog); + + dp_write_ahb(catalog, offset, val); +} + +void dp_catalog_hdcp_disable_hdcp1(struct dp_catalog *dp_catalog) +{ + struct dp_catalog_private *catalog = + container_of(dp_catalog, struct dp_catalog_private, dp_catalog); + + u32 val = dp_read_ahb(catalog, REG_DP_SW_RESET); + dp_write_ahb(catalog, REG_DP_SW_RESET, val | DP_HDCP_SW_RESET); + + /* Disable encryption and disable the HDCP block */ + dp_write_ahb(catalog, DP_HDCP_CTRL, 0); + dp_write_ahb(catalog, REG_DP_SW_RESET, val); +} + +void dp_catalog_hdcp_read_aksv(struct dp_catalog *dp_catalog, u32 *aksv) +{ + struct dp_catalog_private *catalog = + container_of(dp_catalog, struct dp_catalog_private, dp_catalog); + + aksv[0] = dp_read_aux(catalog, DP_HDCP_RCVPORT_DATA3); + aksv[1] = GENMASK(7, 0) & dp_read_aux(catalog, DP_HDCP_RCVPORT_DATA4); +} + +void dp_catalog_hdcp_write_aksv(struct dp_catalog *dp_catalog, u32 *aksv) +{ + struct dp_catalog_private *catalog = + container_of(dp_catalog, struct dp_catalog_private, dp_catalog); + dp_write_aux(catalog, DP_HDCP_SW_LOWER_AKSV, aksv[0]); + dp_write_aux(catalog, DP_HDCP_SW_UPPER_AKSV, aksv[1]); +} + +void dp_catalog_hdcp_read_an(struct dp_catalog *dp_catalog, u32 *an) +{ + struct dp_catalog_private *catalog = + container_of(dp_catalog, struct dp_catalog_private, dp_catalog); + /* + * Get An from hardware, for unknown reasons we need to read the reg + * twice to get valid data. + */ + dp_read_ahb(catalog, DP_HDCP_RCVPORT_DATA5); + an[0] = dp_read_ahb(catalog, DP_HDCP_RCVPORT_DATA5); + + udelay(DP_AN_READ_DELAY_US); + + dp_read_ahb(catalog, DP_HDCP_RCVPORT_DATA6); + an[1] = dp_read_ahb(catalog, DP_HDCP_RCVPORT_DATA6); +} + +void dp_catalog_hdcp_clear_a_info(struct dp_catalog *dp_catalog) +{ + struct dp_catalog_private *catalog = + container_of(dp_catalog, struct dp_catalog_private, dp_catalog); + dp_write_ahb(catalog, DP_HDCP_RCVPORT_DATA4, 0); +} + +void dp_catalog_hdcp_write_key_words(struct dp_catalog *dp_catalog, + int key_offset, u32 *words) +{ + struct dp_catalog_private *catalog = + container_of(dp_catalog, struct dp_catalog_private, dp_catalog); + + dp_write_hdcp_key(catalog, DP_HDCP_KEY_LSB(key_offset), words[0]); + dp_write_hdcp_key(catalog, DP_HDCP_KEY_MSB(key_offset), words[1]); +} + +void dp_catalog_hdcp_post_write_key(struct dp_catalog *dp_catalog) +{ + struct dp_catalog_private *catalog = + container_of(dp_catalog, struct dp_catalog_private, dp_catalog); + u64 an_seed = get_random_u64(); + + dp_write_hdcp_key(catalog, DP_HDCP_KEY_VALID, DP_HDCP_SW_KEY_VALID); + + dp_write_link(catalog, DP_HDCP_ENTROPY_CTRL0, + FIELD_GET(GENMASK(31, 0), an_seed)); + dp_write_link(catalog, DP_HDCP_ENTROPY_CTRL1, + FIELD_GET(GENMASK_ULL(63, 32), an_seed)); +} + +void dp_catalog_hdcp_hdcp1_store_receiver_info(struct dp_catalog *dp_catalog, + u32 *ksv, u32 status, u8 bcaps) +{ + struct dp_catalog_private *catalog = + container_of(dp_catalog, struct dp_catalog_private, dp_catalog); + + u32 val; + + dp_write_hdcp_tz(catalog, HDCP_SEC_DP_TZ_HV_HLOS_HDCP_RCVPORT_DATA0, + ksv[0]); + dp_write_hdcp_tz(catalog, HDCP_SEC_DP_TZ_HV_HLOS_HDCP_RCVPORT_DATA1, + ksv[1]); + + val = FIELD_PREP(GENMASK(23, 8), status) | + FIELD_PREP(GENMASK(7, 0), bcaps); + + dp_write_hdcp_tz(catalog, HDCP_SEC_DP_TZ_HV_HLOS_HDCP_RCVPORT_DATA12, + val); +} + +void dp_catalog_hdcp_reset_sha_comp_block(struct dp_catalog *dp_catalog) +{ + struct dp_catalog_private *catalog = + container_of(dp_catalog, struct dp_catalog_private, dp_catalog); + + dp_write_hdcp_tz(catalog, HDCP_SEC_DP_TZ_HV_HLOS_HDCP_SHA_CTRL, + DP_HDCP_SHA_CTRL_RESET); + dp_write_hdcp_tz(catalog, HDCP_SEC_DP_TZ_HV_HLOS_HDCP_SHA_CTRL, 0); +} + +void dp_catalog_hdcp_write_tz(struct dp_catalog *dp_catalog, u32 offset, + u32 val) +{ + struct dp_catalog_private *catalog = + container_of(dp_catalog, struct dp_catalog_private, dp_catalog); + + dp_write_hdcp_tz(catalog, offset, val); +} diff --git a/drivers/gpu/drm/msm/dp/dp_catalog.h b/drivers/gpu/drm/msm/dp/dp_catalog.h index 1f717f45c1158..565dbe3d802e3 100644 --- a/drivers/gpu/drm/msm/dp/dp_catalog.h +++ b/drivers/gpu/drm/msm/dp/dp_catalog.h @@ -135,4 +135,22 @@ void dp_catalog_audio_config_sdp(struct dp_catalog *catalog); void dp_catalog_audio_init(struct dp_catalog *catalog); void dp_catalog_audio_sfe_level(struct dp_catalog *catalog); +/* HDCP APIs */ +u32 dp_catalog_hdcp_read_ahb(struct dp_catalog *dp_catalog, u32 offset); +void dp_catalog_hdcp_write_ahb(struct dp_catalog *dp_catalog, u32 offset, + u32 val); +void dp_catalog_hdcp_disable_hdcp1(struct dp_catalog *dp_catalog); +void dp_catalog_hdcp_read_aksv(struct dp_catalog *dp_catalog, u32 *aksv); +void dp_catalog_hdcp_write_aksv(struct dp_catalog *dp_catalog, u32 *aksv); +void dp_catalog_hdcp_read_an(struct dp_catalog *dp_catalog, u32 *an); +void dp_catalog_hdcp_clear_a_info(struct dp_catalog *dp_catalog); +void dp_catalog_hdcp_write_key_words(struct dp_catalog *dp_catalog, + int key_offset, u32 *words); +void dp_catalog_hdcp_post_write_key(struct dp_catalog *dp_catalog); +void dp_catalog_hdcp_hdcp1_store_receiver_info(struct dp_catalog *dp_catalog, + u32 *ksv, u32 status, u8 bcaps); +void dp_catalog_hdcp_reset_sha_comp_block(struct dp_catalog *dp_catalog); +void dp_catalog_hdcp_write_tz(struct dp_catalog *dp_catalog, u32 offset, + u32 val); + #endif /* _DP_CATALOG_H_ */ diff --git a/drivers/gpu/drm/msm/dp/dp_debug.c b/drivers/gpu/drm/msm/dp/dp_debug.c index 5e35033ba3e43..bfef65b0c0f92 100644 --- a/drivers/gpu/drm/msm/dp/dp_debug.c +++ b/drivers/gpu/drm/msm/dp/dp_debug.c @@ -8,6 +8,7 @@ #include #include #include +#include #include "dp_parser.h" #include "dp_catalog.h" @@ -15,6 +16,7 @@ #include "dp_ctrl.h" #include "dp_debug.h" #include "dp_display.h" +#include "dp_hdcp.h" #define DEBUG_NAME "msm_dp" @@ -25,6 +27,7 @@ struct dp_debug_private { struct dp_link *link; struct dp_panel *panel; struct drm_connector *connector; + struct dp_hdcp *hdcp; struct device *dev; struct drm_device *drm_dev; @@ -196,6 +199,35 @@ static int dp_test_active_open(struct inode *inode, inode->i_private); } +static ssize_t dp_hdcp_key_write(struct file *file, const char __user *ubuf, + size_t len, loff_t *offp) +{ + char *input_buffer; + int ret; + struct dp_debug_private *debug = file->private_data; + + if (len != (DRM_HDCP_KSV_LEN + DP_HDCP_NUM_KEYS * DP_HDCP_KEY_LEN)) + return -EINVAL; + + if (!debug->hdcp) + return -ENOENT; + + input_buffer = memdup_user_nul(ubuf, len); + if (IS_ERR(input_buffer)) + return PTR_ERR(input_buffer); + + ret = dp_hdcp_ingest_key(debug->hdcp, input_buffer, len); + + kfree(input_buffer); + if (ret < 0) { + DRM_ERROR("Could not ingest HDCP key, ret=%d\n", ret); + return ret; + } + + *offp += len; + return len; +} + static const struct file_operations test_active_fops = { .owner = THIS_MODULE, .open = dp_test_active_open, @@ -205,6 +237,12 @@ static const struct file_operations test_active_fops = { .write = dp_test_active_write }; +static const struct file_operations dp_hdcp_key_fops = { + .owner = THIS_MODULE, + .open = simple_open, + .write = dp_hdcp_key_write, +}; + static void dp_debug_init(struct dp_debug *dp_debug, struct drm_minor *minor) { char path[64]; @@ -229,11 +267,14 @@ static void dp_debug_init(struct dp_debug *dp_debug, struct drm_minor *minor) debugfs_create_file("msm_dp_test_type", 0444, debug->root, debug, &dp_test_type_fops); + + debugfs_create_file("msm_dp_hdcp_key", 0222, minor->debugfs_root, debug, + &dp_hdcp_key_fops); } struct dp_debug *dp_debug_get(struct device *dev, struct dp_panel *panel, - struct dp_usbpd *usbpd, struct dp_link *link, - struct drm_connector *connector, struct drm_minor *minor) + struct dp_usbpd *usbpd, struct dp_link *link, struct dp_hdcp *hdcp, + struct drm_connector *connector, struct drm_minor *minor) { struct dp_debug_private *debug; struct dp_debug *dp_debug; @@ -255,6 +296,7 @@ struct dp_debug *dp_debug_get(struct device *dev, struct dp_panel *panel, debug->usbpd = usbpd; debug->link = link; debug->panel = panel; + debug->hdcp = hdcp; debug->dev = dev; debug->drm_dev = minor->dev; debug->connector = connector; diff --git a/drivers/gpu/drm/msm/dp/dp_debug.h b/drivers/gpu/drm/msm/dp/dp_debug.h index 8c0d0b5178fdf..ab6c5e8e5ea63 100644 --- a/drivers/gpu/drm/msm/dp/dp_debug.h +++ b/drivers/gpu/drm/msm/dp/dp_debug.h @@ -6,6 +6,7 @@ #ifndef _DP_DEBUG_H_ #define _DP_DEBUG_H_ +#include "dp_hdcp.h" #include "dp_panel.h" #include "dp_link.h" @@ -34,6 +35,7 @@ struct dp_debug { * @panel: instance of panel module * @usbpd: instance of usbpd module * @link: instance of link module + * @hdcp: instance of hdcp module * @connector: double pointer to display connector * @minor: pointer to drm minor number after device registration * return: pointer to allocated debug module data @@ -42,9 +44,10 @@ struct dp_debug { * for debugfs input to be communicated with existing modules */ struct dp_debug *dp_debug_get(struct device *dev, struct dp_panel *panel, - struct dp_usbpd *usbpd, struct dp_link *link, - struct drm_connector *connector, - struct drm_minor *minor); + struct dp_usbpd *usbpd, struct dp_link *link, + struct dp_hdcp *hdcp, + struct drm_connector *connector, + struct drm_minor *minor); /** * dp_debug_put() @@ -59,7 +62,7 @@ void dp_debug_put(struct dp_debug *dp_debug); static inline struct dp_debug *dp_debug_get(struct device *dev, struct dp_panel *panel, - struct dp_usbpd *usbpd, struct dp_link *link, + struct dp_usbpd *usbpd, struct dp_link *link, struct dp_hdcp *hdcp, struct drm_connector *connector, struct drm_minor *minor) { return ERR_PTR(-EINVAL); diff --git a/drivers/gpu/drm/msm/dp/dp_display.c b/drivers/gpu/drm/msm/dp/dp_display.c index bde1a7ce442ff..7c90d7cefedbc 100644 --- a/drivers/gpu/drm/msm/dp/dp_display.c +++ b/drivers/gpu/drm/msm/dp/dp_display.c @@ -27,6 +27,7 @@ #include "dp_drm.h" #include "dp_audio.h" #include "dp_debug.h" +#include "dp_hdcp.h" #define HPD_STRING_SIZE 30 @@ -97,6 +98,7 @@ struct dp_display_private { struct dp_panel *panel; struct dp_ctrl *ctrl; struct dp_debug *debug; + struct dp_hdcp *hdcp; struct dp_usbpd_cb usbpd_cb; struct dp_display_mode dp_mode; @@ -190,6 +192,14 @@ static struct dp_display_private *dev_get_dp_display_private(struct device *dev) return container_of(dp, struct dp_display_private, dp_display); } +struct dp_hdcp *dp_display_bridge_to_hdcp(struct drm_bridge *bridge) +{ + struct msm_dp *dp_display = msm_dp_from_bridge(bridge); + struct dp_display_private *dp = + container_of(dp_display, struct dp_display_private, dp_display); + return dp->hdcp; +} + static int dp_add_event(struct dp_display_private *dp_priv, u32 event, u32 data, u32 delay) { @@ -752,6 +762,7 @@ static int dp_irq_hpd_handle(struct dp_display_private *dp, u32 data) static void dp_display_deinit_sub_modules(struct dp_display_private *dp) { dp_debug_put(dp->debug); + dp_hdcp_put(dp->hdcp); dp_audio_put(dp->audio); dp_panel_put(dp->panel); dp_aux_put(dp->aux); @@ -852,8 +863,18 @@ static int dp_init_sub_modules(struct dp_display_private *dp) dp->ctrl->wide_bus_en = dp->wide_bus_en; dp->catalog->wide_bus_en = dp->wide_bus_en; + dp->hdcp = dp_hdcp_get(dp->parser, dp->aux); + if (IS_ERR(dp->hdcp)) { + rc = PTR_ERR(dp->hdcp); + DRM_ERROR("failed to initialize hdcp, rc = %d\n", rc); + dp->hdcp = NULL; + goto error_hdcp; + } + return rc; +error_hdcp: + dp_audio_put(dp->audio); error_ctrl: dp_panel_put(dp->panel); error_link: @@ -965,6 +986,15 @@ int dp_display_set_plugged_cb(struct msm_dp *dp_display, return 0; } +void dp_display_hdcp_commit(struct msm_dp *dp, struct drm_atomic_state *state) +{ + struct dp_display_private *dp_display = + container_of(dp, struct dp_display_private, dp_display); + + if (dp_display->hdcp) + dp_hdcp_commit(dp_display->hdcp, state); +} + /** * dp_bridge_mode_valid - callback to determine if specified mode is valid * @bridge: Pointer to drm bridge structure @@ -1528,7 +1558,7 @@ void msm_dp_debugfs_init(struct msm_dp *dp_display, struct drm_minor *minor) dev = &dp->pdev->dev; dp->debug = dp_debug_get(dev, dp->panel, dp->usbpd, - dp->link, dp->dp_display.connector, + dp->link, dp->hdcp, dp->dp_display.connector, minor); if (IS_ERR(dp->debug)) { rc = PTR_ERR(dp->debug); @@ -1649,6 +1679,13 @@ int msm_dp_modeset_init(struct msm_dp *dp_display, struct drm_device *dev, dp_priv->panel->connector = dp_display->connector; + ret = dp_hdcp_attach(dp_priv->hdcp, dp_display->connector, + dp_display->bridge, dp_priv->catalog); + if (ret) { + DRM_ERROR("Failed to attach hdcp, ret=%d\n", ret); + return ret; + } + return 0; } diff --git a/drivers/gpu/drm/msm/dp/dp_display.h b/drivers/gpu/drm/msm/dp/dp_display.h index 371337d0fae26..1d64b86b0b354 100644 --- a/drivers/gpu/drm/msm/dp/dp_display.h +++ b/drivers/gpu/drm/msm/dp/dp_display.h @@ -31,8 +31,13 @@ struct msm_dp { struct dp_audio *dp_audio; }; +struct drm_atomic_state; + int dp_display_set_plugged_cb(struct msm_dp *dp_display, hdmi_codec_plugged_cb fn, struct device *codec_dev); +struct dp_hdcp *dp_display_bridge_to_hdcp(struct drm_bridge *bridge); +void dp_display_hdcp_commit(struct msm_dp *dp_display, + struct drm_atomic_state *state); int dp_display_get_modes(struct msm_dp *dp_display); int dp_display_request_irq(struct msm_dp *dp_display); bool dp_display_check_video_test(struct msm_dp *dp_display); diff --git a/drivers/gpu/drm/msm/dp/dp_drm.c b/drivers/gpu/drm/msm/dp/dp_drm.c index 275370f211159..6bf3b224ccaef 100644 --- a/drivers/gpu/drm/msm/dp/dp_drm.c +++ b/drivers/gpu/drm/msm/dp/dp_drm.c @@ -7,11 +7,19 @@ #include #include #include +#include #include +#include #include "msm_drv.h" #include "msm_kms.h" #include "dp_drm.h" +#include "dp_hdcp.h" + +struct msm_dp *msm_dp_from_bridge(struct drm_bridge *bridge) +{ + return to_dp_bridge(bridge)->dp_display; +} /** * dp_bridge_detect - callback to determine if connector is connected @@ -37,8 +45,8 @@ static int dp_bridge_atomic_check(struct drm_bridge *bridge, struct drm_connector_state *conn_state) { struct msm_dp *dp; - - dp = to_dp_bridge(bridge)->dp_display; + struct msm_dp_bridge *dp_bridge = to_dp_bridge(bridge); + dp = dp_bridge->dp_display; drm_dbg_dp(dp->drm_dev, "is_connected = %s\n", (dp->is_connected) ? "true" : "false"); @@ -54,8 +62,11 @@ static int dp_bridge_atomic_check(struct drm_bridge *bridge, * disabled by the hardware and thus all access to it should be forbidden. * After that this piece of code can be removed. */ - if (bridge->ops & DRM_BRIDGE_OP_HPD) - return (dp->is_connected) ? 0 : -ENOTCONN; + if (bridge->ops & DRM_BRIDGE_OP_HPD && !dp->is_connected) + return -ENOTCONN; + + dp_bridge->hdcp_transition = + drm_hdcp_has_changed(conn_state->connector, conn_state->state); return 0; } @@ -107,6 +118,25 @@ static const struct drm_bridge_funcs dp_bridge_ops = { .hpd_notify = dp_bridge_hpd_notify, }; +bool dp_drm_is_bridge_msm_dp(struct drm_bridge *bridge) +{ + return bridge->funcs == &dp_bridge_ops; +} + +void dp_drm_atomic_commit(struct drm_bridge *bridge, + struct drm_atomic_state *state) +{ + struct msm_dp_bridge *dp_bridge = to_dp_bridge(bridge); + struct msm_dp *dp_disp; + + if (!dp_bridge->hdcp_transition) + return; + + dp_disp = msm_dp_from_bridge(bridge); + + dp_display_hdcp_commit(dp_disp, state); +} + struct drm_bridge *dp_bridge_init(struct msm_dp *dp_display, struct drm_device *dev, struct drm_encoder *encoder) { @@ -119,6 +149,7 @@ struct drm_bridge *dp_bridge_init(struct msm_dp *dp_display, struct drm_device * return ERR_PTR(-ENOMEM); dp_bridge->dp_display = dp_display; + dp_bridge->hdcp_transition = false; bridge = &dp_bridge->bridge; bridge->funcs = &dp_bridge_ops; diff --git a/drivers/gpu/drm/msm/dp/dp_drm.h b/drivers/gpu/drm/msm/dp/dp_drm.h index 250f7c66201f2..9b3f81cf2e139 100644 --- a/drivers/gpu/drm/msm/dp/dp_drm.h +++ b/drivers/gpu/drm/msm/dp/dp_drm.h @@ -15,11 +15,18 @@ struct msm_dp_bridge { struct drm_bridge bridge; struct msm_dp *dp_display; + bool hdcp_transition; }; #define to_dp_bridge(x) container_of((x), struct msm_dp_bridge, bridge) +struct msm_dp *msm_dp_from_bridge(struct drm_bridge *bridge); + struct drm_connector *dp_drm_connector_init(struct msm_dp *dp_display, struct drm_encoder *encoder); +bool dp_drm_is_bridge_msm_dp(struct drm_bridge *bridge); +void dp_drm_atomic_commit(struct drm_bridge *bridge, + struct drm_atomic_state *state); + struct drm_bridge *dp_bridge_init(struct msm_dp *dp_display, struct drm_device *dev, struct drm_encoder *encoder); diff --git a/drivers/gpu/drm/msm/dp/dp_hdcp.c b/drivers/gpu/drm/msm/dp/dp_hdcp.c new file mode 100644 index 0000000000000..191340971f943 --- /dev/null +++ b/drivers/gpu/drm/msm/dp/dp_hdcp.c @@ -0,0 +1,389 @@ +// SPDX-License-Identifier: MIT +/* + * Copyright (C) 2023 Google, Inc. + * + * Authors: + * Sean Paul + */ + +#include "dp_display.h" +#include "dp_drm.h" +#include "dp_hdcp.h" +#include "dp_reg.h" + +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +/* Timeouts */ +#define DP_KEYS_VALID_SLEEP_US (20 * 1000) +#define DP_KEYS_VALID_TIMEOUT_US (100 * 1000) +#define DP_AN_READY_SLEEP_US 100 +#define DP_AN_READY_TIMEOUT_US (10 * 1000) +#define DP_R0_READY_SLEEP_US 100 +#define DP_R0_READY_TIMEOUT_US (10 * 1000) +#define DP_RI_MATCH_SLEEP_US (20 * 1000) +#define DP_RI_MATCH_TIMEOUT_US (100 * 1000) +#define DP_KSV_WRITTEN_SLEEP_US 100 +#define DP_KSV_WRITTEN_TIMEOUT_US (100 * 1000) +#define DP_SHA_COMPUTATION_SLEEP_US 100 +#define DP_SHA_COMPUTATION_TIMEOUT_US (100 * 1000) + +/* + * dp_hdcp_key - structure which contains an HDCP key set + * @ksv: The key selection vector + * @keys: Contains 40 keys + */ +struct dp_hdcp_key { + struct drm_hdcp_ksv ksv; + union { + u32 words[2]; + u8 bytes[DP_HDCP_KEY_LEN]; + } keys[DP_HDCP_NUM_KEYS]; + bool valid; +}; + +struct dp_hdcp { + struct drm_device *dev; + struct drm_connector *connector; + + struct drm_dp_aux *aux; + struct dp_parser *parser; + + struct drm_hdcp_helper_data *helper_data; + + struct mutex key_lock; + struct dp_hdcp_key key; + + struct dp_catalog *catalog; +}; + +int dp_hdcp_ingest_key(struct dp_hdcp *hdcp, const u8 *raw_key, int raw_len) +{ + unsigned int ksv_weight; + int i, ret = 0; + int expected_len = + DRM_HDCP_KSV_LEN + DP_HDCP_NUM_KEYS * DP_HDCP_KEY_LEN; + + if (raw_len != expected_len) { + DRM_ERROR("Invalid HDCP key length expected=%d actual=%d\n", + expected_len, raw_len); + return -EINVAL; + } + + mutex_lock(&hdcp->key_lock); + + memcpy(hdcp->key.ksv.bytes, raw_key, DRM_HDCP_KSV_LEN); + ksv_weight = hweight32(hdcp->key.ksv.words[0]) + + hweight32(hdcp->key.ksv.words[1]); + if (ksv_weight != 20) { + DRM_ERROR("Invalid ksv weight, expected=20 actual=%d\n", + ksv_weight); + ret = -EINVAL; + goto out; + } + + raw_key += DRM_HDCP_KSV_LEN; + for (i = 0; i < DP_HDCP_NUM_KEYS; i++) { + memcpy(hdcp->key.keys[i].bytes, raw_key, DP_HDCP_KEY_LEN); + raw_key += DP_HDCP_KEY_LEN; + } + + DRM_DEBUG_DRIVER("Successfully ingested HDCP key\n"); + hdcp->key.valid = true; + +out: + mutex_unlock(&hdcp->key_lock); + return ret; +} + +static bool dp_hdcp_are_keys_valid(struct drm_connector *connector, + void *driver_data) +{ + struct drm_bridge *bridge = (struct drm_bridge *)driver_data; + struct dp_hdcp *hdcp = dp_display_bridge_to_hdcp(bridge); + u32 val; + + val = dp_catalog_hdcp_read_ahb(hdcp->catalog, DP_HDCP_STATUS); + return FIELD_GET(DP_HDCP_KEY_STATUS, val) == DP_HDCP_KEY_STATUS_VALID; +} + +static int dp_hdcp_load_keys(struct drm_connector *connector, void *driver_data) +{ + struct drm_bridge *bridge = (struct drm_bridge *)driver_data; + struct dp_hdcp *hdcp = dp_display_bridge_to_hdcp(bridge); + int i, ret = 0; + + mutex_lock(&hdcp->key_lock); + + if (!hdcp->key.valid) { + ret = -ENOENT; + goto out; + } + + dp_catalog_hdcp_write_aksv(hdcp->catalog, hdcp->key.ksv.words); + + + for (i = 0; i < DP_HDCP_NUM_KEYS; i++) { + dp_catalog_hdcp_write_key_words(hdcp->catalog, i, + hdcp->key.keys[i].words); + } + dp_catalog_hdcp_post_write_key(hdcp->catalog); + +out: + mutex_unlock(&hdcp->key_lock); + return ret; +} + +static int dp_hdcp_hdcp2_capable(struct drm_connector *connector, bool *capable, + void *driver_data) +{ + *capable = false; + return 0; +} + +static int dp_hdcp_hdcp1_read_an_aksv(struct drm_connector *connector, u32 *an, + u32 *aksv, void *driver_data) +{ + struct drm_bridge *bridge = (struct drm_bridge *)driver_data; + struct dp_hdcp *hdcp = dp_display_bridge_to_hdcp(bridge); + bool keys_valid; + int ret; + u32 val; + + dp_catalog_hdcp_write_ahb(hdcp->catalog, DP_HDCP_CTRL, 1); + + ret = read_poll_timeout(dp_hdcp_are_keys_valid, keys_valid, keys_valid, + DP_KEYS_VALID_SLEEP_US, + DP_KEYS_VALID_TIMEOUT_US, false, connector, + driver_data); + if (ret) { + drm_err(hdcp->dev, "HDCP keys invalid %d\n", ret); + return ret; + } + + /* Clear AInfo */ + dp_catalog_hdcp_clear_a_info(hdcp->catalog); + + dp_catalog_hdcp_read_aksv(hdcp->catalog, aksv); + + ret = read_poll_timeout(dp_catalog_hdcp_read_ahb, val, + (val & DP_HDCP_AN_READY_MASK) == + DP_HDCP_AN_READY_MASK, + DP_AN_READY_SLEEP_US, DP_AN_READY_TIMEOUT_US, + false, hdcp->catalog, DP_HDCP_STATUS); + if (ret) { + drm_err(hdcp->dev, "AN failed to become ready %x/%d\n", val, + ret); + return ret; + } + + dp_catalog_hdcp_read_an(hdcp->catalog, an); + + return 0; +} + +static int dp_hdcp_hdcp1_store_receiver_info(struct drm_connector *connector, + u32 *ksv, u32 status, u8 bcaps, + bool is_repeater, + void *driver_data) +{ + struct drm_bridge *bridge = (struct drm_bridge *)driver_data; + struct dp_hdcp *hdcp = dp_display_bridge_to_hdcp(bridge); + + dp_catalog_hdcp_hdcp1_store_receiver_info(hdcp->catalog, ksv, status, + bcaps); + + return 0; +} + +static int dp_hdcp_hdcp1_enable_encryption(struct drm_connector *connector, + void *driver_data) +{ + /* + * On Qcom hardware, there is nothing explicit about enabling encryption + * like it is the case in other drivers. It gets enabled by default. + */ + return 0; +} + +static int dp_hdcp_hdcp1_wait_for_r0(struct drm_connector *connector, + void *driver_data) +{ + struct drm_bridge *bridge = (struct drm_bridge *)driver_data; + struct dp_hdcp *hdcp = dp_display_bridge_to_hdcp(bridge); + int ret; + u32 val; + + ret = read_poll_timeout(dp_catalog_hdcp_read_ahb, val, + (val & DP_HDCP_R0_READY), DP_R0_READY_SLEEP_US, + DP_R0_READY_TIMEOUT_US, false, hdcp->catalog, + DP_HDCP_STATUS); + if (ret) { + drm_err(hdcp->dev, "HDCP R0 not ready %x/%d\n", val, ret); + return ret; + } + + return 0; +} + +static int dp_hdcp_hdcp1_match_ri(struct drm_connector *connector, u32 ri_prime, + void *driver_data) +{ + struct drm_bridge *bridge = (struct drm_bridge *)driver_data; + struct dp_hdcp *hdcp = dp_display_bridge_to_hdcp(bridge); + int ret; + u32 val; + + dp_catalog_hdcp_write_ahb(hdcp->catalog, DP_HDCP_RCVPORT_DATA2_0, + ri_prime); + + ret = read_poll_timeout(dp_catalog_hdcp_read_ahb, val, + (val & DP_HDCP_RI_MATCH), DP_RI_MATCH_SLEEP_US, + DP_RI_MATCH_TIMEOUT_US, false, hdcp->catalog, + DP_HDCP_STATUS); + if (ret) { + drm_err(hdcp->dev, + "Failed to match Ri and Ri` (%08x) %08x/%d\n", ri_prime, + val, ret); + return ret; + } + return 0; +} + +static int dp_hdcp_hdcp1_store_ksv_fifo(struct drm_connector *connector, + u8 *ksv_fifo, u8 num_downstream, + u8 *bstatus, u32 *vprime, + void *driver_data) +{ + struct drm_bridge *bridge = (struct drm_bridge *)driver_data; + struct dp_hdcp *hdcp = dp_display_bridge_to_hdcp(bridge); + int num_bytes = num_downstream * DRM_HDCP_KSV_LEN; + int ret, i; + u32 val; + + dp_catalog_hdcp_reset_sha_comp_block(hdcp->catalog); + + /* + * KSV info gets written a byte at a time in the same order it was + * received. Every 64 bytes, we need to wait for the SHA_BLOCK_DONE + * bit to be set in SHA_CTRL. + */ + for (i = 0; i < num_bytes; i++) { + val = FIELD_PREP(DP_HDCP_SHA_DATA_MASK, ksv_fifo[i]); + + if (i == (num_bytes - 1)) + val |= DP_HDCP_SHA_DATA_DONE; + + dp_catalog_hdcp_write_tz(hdcp->catalog, + HDCP_SEC_DP_TZ_HV_HLOS_HDCP_SHA_DATA, + val); + + if ((i + 1) % 64 != 0) + continue; + + ret = read_poll_timeout(dp_catalog_hdcp_read_ahb, val, + (val & DP_HDCP_SHA_DONE), + DP_KSV_WRITTEN_SLEEP_US, + DP_KSV_WRITTEN_TIMEOUT_US, false, + hdcp->catalog, DP_HDCP_SHA_STATUS); + if (ret) { + drm_err(hdcp->dev, "SHA block incomplete %d\n", ret); + return ret; + } + } + + ret = read_poll_timeout(dp_catalog_hdcp_read_ahb, val, + (val & DP_HDCP_SHA_COMP_DONE), + DP_SHA_COMPUTATION_SLEEP_US, + DP_SHA_COMPUTATION_TIMEOUT_US, false, + hdcp->catalog, DP_HDCP_SHA_STATUS); + if (ret) { + drm_err(hdcp->dev, "SHA computation incomplete %d\n", ret); + return ret; + } + + return 0; +} + +static int dp_hdcp_hdcp1_disable(struct drm_connector *connector, + void *driver_data) +{ + struct drm_bridge *bridge = (struct drm_bridge *)driver_data; + struct dp_hdcp *hdcp = dp_display_bridge_to_hdcp(bridge); + dp_catalog_hdcp_disable_hdcp1(hdcp->catalog); + return 0; +} + +void dp_hdcp_commit(struct dp_hdcp *hdcp, struct drm_atomic_state *state) +{ + drm_hdcp_helper_atomic_commit(hdcp->helper_data, state, NULL); +} + +static const struct drm_hdcp_helper_funcs dp_hdcp_funcs = { + .are_keys_valid = dp_hdcp_are_keys_valid, + .load_keys = dp_hdcp_load_keys, + .hdcp2_capable = dp_hdcp_hdcp2_capable, + .hdcp1_read_an_aksv = dp_hdcp_hdcp1_read_an_aksv, + .hdcp1_store_receiver_info = dp_hdcp_hdcp1_store_receiver_info, + .hdcp1_enable_encryption = dp_hdcp_hdcp1_enable_encryption, + .hdcp1_wait_for_r0 = dp_hdcp_hdcp1_wait_for_r0, + .hdcp1_match_ri = dp_hdcp_hdcp1_match_ri, + .hdcp1_store_ksv_fifo = dp_hdcp_hdcp1_store_ksv_fifo, + .hdcp1_disable = dp_hdcp_hdcp1_disable +}; + +int dp_hdcp_attach(struct dp_hdcp *hdcp, struct drm_connector *connector, + struct drm_bridge *bridge, struct dp_catalog *catalog) +{ + struct drm_hdcp_helper_data *helper_data; + + /* HDCP is not configured for this device */ + if (!hdcp->parser->io.dp_controller.hdcp_key.base) + return 0; + + helper_data = drm_hdcp_helper_initialize_dp(connector, hdcp->aux, + &dp_hdcp_funcs, false); + if (IS_ERR(helper_data)) + return PTR_ERR(helper_data); + + helper_data->driver_data = bridge; + hdcp->dev = connector->dev; + hdcp->connector = connector; + hdcp->helper_data = helper_data; + hdcp->catalog = catalog; + + return 0; +} + +struct dp_hdcp *dp_hdcp_get(struct dp_parser *parser, struct drm_dp_aux *aux) +{ + struct device *dev = &parser->pdev->dev; + struct dp_hdcp *hdcp; + + hdcp = devm_kzalloc(dev, sizeof(*hdcp), GFP_KERNEL); + if (!hdcp) + return ERR_PTR(-ENOMEM); + + hdcp->parser = parser; + hdcp->aux = aux; + + mutex_init(&hdcp->key_lock); + + return hdcp; +} + +void dp_hdcp_put(struct dp_hdcp *hdcp) +{ + if (hdcp) + drm_hdcp_helper_destroy(hdcp->helper_data); +} diff --git a/drivers/gpu/drm/msm/dp/dp_hdcp.h b/drivers/gpu/drm/msm/dp/dp_hdcp.h new file mode 100644 index 0000000000000..4586e45d14d26 --- /dev/null +++ b/drivers/gpu/drm/msm/dp/dp_hdcp.h @@ -0,0 +1,33 @@ +// SPDX-License-Identifier: MIT +/* + * Copyright (C) 2021 Google, Inc. + * + * Authors: + * Sean Paul + */ + +#ifndef DP_HDCP_H_ +#define DP_HDCP_H_ + +#include +#include + +#include "dp_catalog.h" + +#define DP_HDCP_KEY_LEN 7 +#define DP_HDCP_NUM_KEYS 40 + +struct dp_hdcp; +struct dp_parser; +struct drm_atomic_state; +struct drm_dp_aux; + +struct dp_hdcp *dp_hdcp_get(struct dp_parser *parser, struct drm_dp_aux *aux); +void dp_hdcp_put(struct dp_hdcp *hdcp); + +int dp_hdcp_attach(struct dp_hdcp *hdcp, struct drm_connector *connector, + struct drm_bridge *bridgem, struct dp_catalog *catalog); +int dp_hdcp_ingest_key(struct dp_hdcp *hdcp, const u8 *raw_key, int raw_len); +void dp_hdcp_commit(struct dp_hdcp *hdcp, struct drm_atomic_state *state); + +#endif /* _DP_HDCP_H_ */ diff --git a/drivers/gpu/drm/msm/dp/dp_parser.c b/drivers/gpu/drm/msm/dp/dp_parser.c index 7032dcc8842b3..1f9bb001aebc3 100644 --- a/drivers/gpu/drm/msm/dp/dp_parser.c +++ b/drivers/gpu/drm/msm/dp/dp_parser.c @@ -39,6 +39,8 @@ static int dp_parser_ctrl_res(struct dp_parser *parser) struct platform_device *pdev = parser->pdev; struct dp_io *io = &parser->io; struct dss_io_data *dss = &io->dp_controller; + void __iomem *dss_hdcp_key; + size_t dss_hdcp_key_len; dss->ahb.base = dp_ioremap(pdev, 0, &dss->ahb.len); if (IS_ERR(dss->ahb.base)) @@ -84,6 +86,18 @@ static int dp_parser_ctrl_res(struct dp_parser *parser) } } + dss_hdcp_key = dp_ioremap(pdev, 5, &dss_hdcp_key_len); + if (!IS_ERR(dss_hdcp_key)) { + dss->hdcp_key.base = dss_hdcp_key; + dss->hdcp_key.len = dss_hdcp_key_len; + dss->hdcp_tz.base = dp_ioremap(pdev, 6, &dss->hdcp_tz.len); + if (IS_ERR(dss->hdcp_tz.base)) { + DRM_ERROR("unable to remap hdcp_tz region: %pe\n", + dss->hdcp_tz.base); + return PTR_ERR(dss->hdcp_tz.base); + } + } + io->phy = devm_phy_get(&pdev->dev, "dp"); if (IS_ERR(io->phy)) return PTR_ERR(io->phy); diff --git a/drivers/gpu/drm/msm/dp/dp_parser.h b/drivers/gpu/drm/msm/dp/dp_parser.h index 1f068626d445e..8b5dd3deb85ff 100644 --- a/drivers/gpu/drm/msm/dp/dp_parser.h +++ b/drivers/gpu/drm/msm/dp/dp_parser.h @@ -35,6 +35,8 @@ struct dss_io_data { struct dss_io_region aux; struct dss_io_region link; struct dss_io_region p0; + struct dss_io_region hdcp_key; + struct dss_io_region hdcp_tz; }; static inline const char *dp_parser_pm_name(enum dp_pm_type module) @@ -69,6 +71,8 @@ struct dp_display_data { * struct dp_ctrl_resource - controller's IO related data * * @dp_controller: Display Port controller mapped memory address + * @hdcp_key: mapped memory for HDCP key ingestion + * @hdcp_tz: mapped memory for HDCP TZ interaction * @phy_io: phy's mapped memory address */ struct dp_io { diff --git a/drivers/gpu/drm/msm/dp/dp_reg.h b/drivers/gpu/drm/msm/dp/dp_reg.h index 268602803d9a3..d2ac60ce7ae50 100644 --- a/drivers/gpu/drm/msm/dp/dp_reg.h +++ b/drivers/gpu/drm/msm/dp/dp_reg.h @@ -10,7 +10,8 @@ #define REG_DP_HW_VERSION (0x00000000) #define REG_DP_SW_RESET (0x00000010) -#define DP_SW_RESET (0x00000001) +#define DP_SW_RESET BIT(0) +#define DP_HDCP_SW_RESET BIT(1) #define REG_DP_PHY_CTRL (0x00000014) #define DP_PHY_CTRL_SW_RESET_PLL (0x00000001) @@ -283,19 +284,46 @@ /* DP HDCP 1.3 registers */ #define DP_HDCP_CTRL (0x0A0) #define DP_HDCP_STATUS (0x0A4) +#define DP_HDCP_KEY_STATUS GENMASK(18, 16) +#define DP_HDCP_KEY_STATUS_NO_KEYS 0 +#define DP_HDCP_KEY_STATUS_NOT_CHECKED 1 +#define DP_HDCP_KEY_STATUS_CHECKING 2 +#define DP_HDCP_KEY_STATUS_VALID 3 +#define DP_HDCP_KEY_STATUS_INVALID_AKSV 4 +#define DP_HDCP_KEY_STATUS_BAD_CHECKSUM 5 +#define DP_HDCP_KEY_STATUS_PROD_AKSV 6 +#define DP_HDCP_KEY_STATUS_RESV 7 +#define DP_HDCP_R0_READY BIT(14) +#define DP_HDCP_SHA_V_MATCH BIT(13) +#define DP_HDCP_RI_MATCH BIT(12) +#define DP_HDCP_AN_MSB_READY BIT(9) +#define DP_HDCP_AN_LSB_READY BIT(8) +#define DP_HDCP_AN_READY_MASK (DP_HDCP_AN_MSB_READY | DP_HDCP_AN_LSB_READY) +#define DP_HDCP_AUTH_FAIL_INFO GENMASK(7, 4) +#define DP_HDCP_AUTH_FAIL_INVALID_AKSV 3 +#define DP_HDCP_AUTH_FAIL_INVALID_BKSV 4 +#define DP_HDCP_AUTH_FAIL_RI_MISMATCH 5 +#define DP_HDCP_AUTH_FAIL BIT(2) +#define DP_HDCP_AUTH_SUCCESS BIT(0) #define DP_HDCP_SW_UPPER_AKSV (0x098) #define DP_HDCP_SW_LOWER_AKSV (0x09C) #define DP_HDCP_ENTROPY_CTRL0 (0x350) #define DP_HDCP_ENTROPY_CTRL1 (0x35C) #define DP_HDCP_SHA_STATUS (0x0C8) +#define DP_HDCP_SHA_COMP_DONE BIT(4) +#define DP_HDCP_SHA_DONE BIT(0) #define DP_HDCP_RCVPORT_DATA2_0 (0x0B0) #define DP_HDCP_RCVPORT_DATA3 (0x0A4) #define DP_HDCP_RCVPORT_DATA4 (0x0A8) #define DP_HDCP_RCVPORT_DATA5 (0x0C0) #define DP_HDCP_RCVPORT_DATA6 (0x0C4) +#define DP_HDCP_RCVPORT_DATA7 (0x0C8) #define HDCP_SEC_DP_TZ_HV_HLOS_HDCP_SHA_CTRL (0x024) +#define DP_HDCP_SHA_CTRL_RESET BIT(0) #define HDCP_SEC_DP_TZ_HV_HLOS_HDCP_SHA_DATA (0x028) +#define DP_HDCP_SHA_DATA_MASK GENMASK(23, 16) +#define DP_HDCP_SHA_DATA_DONE BIT(0) #define HDCP_SEC_DP_TZ_HV_HLOS_HDCP_RCVPORT_DATA0 (0x004) #define HDCP_SEC_DP_TZ_HV_HLOS_HDCP_RCVPORT_DATA1 (0x008) #define HDCP_SEC_DP_TZ_HV_HLOS_HDCP_RCVPORT_DATA7 (0x00C) diff --git a/drivers/gpu/drm/msm/msm_atomic.c b/drivers/gpu/drm/msm/msm_atomic.c index 1686fbb611fd7..f5ca7fab083d2 100644 --- a/drivers/gpu/drm/msm/msm_atomic.c +++ b/drivers/gpu/drm/msm/msm_atomic.c @@ -5,8 +5,11 @@ */ #include +#include +#include #include +#include "dp_drm.h" #include "msm_atomic_trace.h" #include "msm_drv.h" #include "msm_gem.h" @@ -179,6 +182,20 @@ static unsigned get_crtc_mask(struct drm_atomic_state *state) return mask; } +static void msm_atomic_commit_connectors(struct drm_atomic_state *state) +{ + struct drm_device *dev = state->dev; + struct msm_drm_private *priv = dev->dev_private; + int i; + + for (i = 0; i < priv->num_bridges; ++i) { + struct drm_bridge *bridge = priv->bridges[i]; + if (dp_drm_is_bridge_msm_dp(bridge)) { + dp_drm_atomic_commit(bridge, state); + } + } +} + void msm_atomic_commit_tail(struct drm_atomic_state *state) { struct drm_device *dev = state->dev; @@ -215,6 +232,8 @@ void msm_atomic_commit_tail(struct drm_atomic_state *state) drm_atomic_helper_commit_planes(dev, state, 0); drm_atomic_helper_commit_modeset_enables(dev, state); + msm_atomic_commit_connectors(state); + if (async) { struct msm_pending_timer *timer = &kms->pending_timers[drm_crtc_index(async_crtc)];