Skip to contentSkip to conversation

Add HDCP feature for DisplayPort

PATCH In review mac.shen 2 participants 21 messages Jun 8, 2024 – Nov 7, 2024

Subsystems (3)
lore
Share & tools
lore

mac.shen

author
#0 lore raw

v3 cover Add HDCP feature for DisplayPort

Add tee client application, HDCP 1.x and 2.x authentication for DisplayPort to support the HDCP feature.

mac.shen (3):
Subject: [PATCH] drm/mediatek/dp: Add tee client application for HDCP
feature
Subject: [PATCH] drm/mediatek/dp: Add HDCP2.x feature for DisplayPort
Subject: [PATCH] drm/mediatek/dp: Add HDCP1.x feature for DisplayPort

 drivers/gpu/drm/mediatek/Makefile        |   7 +-
 drivers/gpu/drm/mediatek/mtk_dp.c        | 332 ++++++--
 drivers/gpu/drm/mediatek/mtk_dp.h        | 103 +++
 drivers/gpu/drm/mediatek/mtk_dp_hdcp1x.c | 577 ++++++++++++++
 drivers/gpu/drm/mediatek/mtk_dp_hdcp1x.h |  17 +
 drivers/gpu/drm/mediatek/mtk_dp_hdcp2.c  | 944 +++++++++++++++++++++++
 drivers/gpu/drm/mediatek/mtk_dp_hdcp2.h  |  25 +
 drivers/gpu/drm/mediatek/mtk_dp_reg.h    |  11 +-
 drivers/gpu/drm/mediatek/mtk_dpi.c       |   3 +
 drivers/gpu/drm/mediatek/tci.h           | 143 ++++
 drivers/gpu/drm/mediatek/tlc_dp_hdcp.c   | 595 ++++++++++++++
 drivers/gpu/drm/mediatek/tlc_dp_hdcp.h   | 133 ++++
 12 files changed, 2805 insertions(+), 85 deletions(-)
 create mode 100644 drivers/gpu/drm/mediatek/mtk_dp.h
 create mode 100644 drivers/gpu/drm/mediatek/mtk_dp_hdcp1x.c
 create mode 100644 drivers/gpu/drm/mediatek/mtk_dp_hdcp1x.h
 create mode 100644 drivers/gpu/drm/mediatek/mtk_dp_hdcp2.c
 create mode 100644 drivers/gpu/drm/mediatek/mtk_dp_hdcp2.h
 create mode 100644 drivers/gpu/drm/mediatek/tci.h
 create mode 100644 drivers/gpu/drm/mediatek/tlc_dp_hdcp.c
 create mode 100644 drivers/gpu/drm/mediatek/tlc_dp_hdcp.h
Signature · 1 line
2.43.0
author
#1 lore raw

PATCH v3 1/3 Subject: [PATCH] drm/mediatek/dp: Add tee client application for HDCP feature

Add tee client application which will be used for
HDCP 1.x and 2.x authentication in DisplayPort.

Changes in v3:
- remove useless define
- refine the return value
- remove the define which control the log output
- remove the struct hdcp2_handler for HDCP 2.X
- refine the struct for the HDCP information per suggestion from the previous thread:
https://patchwork.kernel.org/project/linux-mediatek
/patch/[email protected]/

---
 drivers/gpu/drm/mediatek/Makefile      |   5 +-
 drivers/gpu/drm/mediatek/tci.h         | 143 ++++++
 drivers/gpu/drm/mediatek/tlc_dp_hdcp.c | 595 +++++++++++++++++++++++++
 drivers/gpu/drm/mediatek/tlc_dp_hdcp.h | 133 ++++++
 4 files changed, 875 insertions(+), 1 deletion(-)
 create mode 100644 drivers/gpu/drm/mediatek/tci.h
 create mode 100644 drivers/gpu/drm/mediatek/tlc_dp_hdcp.c
 create mode 100644 drivers/gpu/drm/mediatek/tlc_dp_hdcp.h
drivers/gpu/drm/mediatek/Makefile +4 -1
index 32a2ed6c0cfe..f27ddfbd2e12 100644
@@ -27,4 +27,7 @@ mediatek-drm-hdmi-objs := mtk_cec.o \
 
 obj-$(CONFIG_DRM_MEDIATEK_HDMI) += mediatek-drm-hdmi.o
 
-obj-$(CONFIG_DRM_MEDIATEK_DP) += mtk_dp.o
+mtk-dp-objs := tlc_dp_hdcp.o \
+		  mtk_dp.o
+
+obj-$(CONFIG_DRM_MEDIATEK_DP) += mtk-dp.o
drivers/gpu/drm/mediatek/tci.h new file +143 -0

143 lines not on this page · raw message

drivers/gpu/drm/mediatek/tlc_dp_hdcp.c new file +595 -0

595 lines not on this page · raw message

drivers/gpu/drm/mediatek/tlc_dp_hdcp.h new file +133 -0

133 lines not on this page · raw message

Signature · 1 line
2.43.0
author
#2 lore raw

PATCH v3 2/3 Subject: [PATCH] drm/mediatek/dp: Add HDCP2.x feature for DisplayPort

In reply to mac.shen

Changes in v3:
- refine the function to get system time
- refine the flow to do HDCP with content type and protection value which set by user space
- refine the flow to update content protection
- refine the flow to do HDCP2.x authentication per suggestion from the previous thread:
https://patchwork.kernel.org/project/linux-mediatek
/patch/[email protected]/

---
 drivers/gpu/drm/mediatek/Makefile       |   1 +
 drivers/gpu/drm/mediatek/mtk_dp.c       | 321 +++++---
 drivers/gpu/drm/mediatek/mtk_dp.h       | 103 +++
 drivers/gpu/drm/mediatek/mtk_dp_hdcp2.c | 944 ++++++++++++++++++++++++
 drivers/gpu/drm/mediatek/mtk_dp_hdcp2.h |  25 +
 drivers/gpu/drm/mediatek/mtk_dp_reg.h   |   8 +-
 drivers/gpu/drm/mediatek/mtk_dpi.c      |   3 +
 7 files changed, 1321 insertions(+), 84 deletions(-)
 create mode 100644 drivers/gpu/drm/mediatek/mtk_dp.h
 create mode 100644 drivers/gpu/drm/mediatek/mtk_dp_hdcp2.c
 create mode 100644 drivers/gpu/drm/mediatek/mtk_dp_hdcp2.h
drivers/gpu/drm/mediatek/Makefile +1 -0
index f27ddfbd2e12..19b7625ae573 100644
@@ -28,6 +28,7 @@ mediatek-drm-hdmi-objs := mtk_cec.o \
 obj-$(CONFIG_DRM_MEDIATEK_HDMI) += mediatek-drm-hdmi.o
 
 mtk-dp-objs := tlc_dp_hdcp.o \
+		  mtk_dp_hdcp2.o \
 		  mtk_dp.o
 
 obj-$(CONFIG_DRM_MEDIATEK_DP) += mtk-dp.o
drivers/gpu/drm/mediatek/mtk_dp.c +238 -83

423 lines not on this page · raw message

drivers/gpu/drm/mediatek/mtk_dp.h new file +103 -0

103 lines not on this page · raw message

drivers/gpu/drm/mediatek/mtk_dp_hdcp2.c new file +944 -0

944 lines not on this page · raw message

drivers/gpu/drm/mediatek/mtk_dp_hdcp2.h new file +25 -0
new file mode 100644
index 000000000000..0532bcb9958b
@@ -0,0 +1,25 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (c) 2019-2024 MediaTek Inc.
+ */
+
+#ifndef _MTK_dp_HDCP2_H_
+#define _MTK_dp_HDCP2_H_
+
+#include "tlc_dp_hdcp.h"
+
+#define HDCP_VERSION_2X 2
+
+enum check_link {
+	LINK_PROTECTED	= 0,
+	TOPOLOGY_CHANGE,
+	LINK_INTEGRITY_FAILURE,
+	REAUTH_REQUEST
+};
+
+void dp_tx_hdcp2x_get_info(struct mtk_hdcp_info *hdcp_info);
+int dp_tx_hdcp2x_enable(struct mtk_hdcp_info *hdcp_info);
+int dp_tx_hdcp2x_disabel(struct mtk_hdcp_info *hdcp_info);
+int dp_tx_hdcp2x_check_link(struct mtk_hdcp_info *hdcp_info);
+void dp_tx_hdcp2x_irq(struct mtk_hdcp_info *hdcp_info);
+#endif /* _MTK_dp_HDCP2_H_ */
drivers/gpu/drm/mediatek/mtk_dp_reg.h +7 -1
index 709b79480693..8c60983a26ed 100644
@@ -1,6 +1,6 @@
 /* SPDX-License-Identifier: GPL-2.0 */
 /*
- * Copyright (c) 2019-2022 MediaTek Inc.
+ * Copyright (c) 2019-2024 MediaTek Inc.
  * Copyright (c) 2022 BayLibre
  */
 #ifndef _MTK_DP_REG_H_
@@ -83,6 +83,7 @@
 #define VIDEO_MUTE_SW_DP_ENC0_P0			BIT(2)
 #define VIDEO_MUTE_SEL_DP_ENC0_P0			BIT(3)
 #define ENHANCED_FRAME_EN_DP_ENC0_P0			BIT(4)
+#define HDCP_FRAME_EN_DP_ENC0_P0			BIT(5)
 #define MTK_DP_ENC0_P0_3004			0x3004
 #define VIDEO_M_CODE_SEL_DP_ENC0_P0_MASK		BIT(8)
 #define DP_TX_ENCODER_4P_RESET_SW_DP_ENC0_P0		BIT(9)
@@ -245,6 +246,7 @@
 
 /* offset: TRANS_OFFSET (0x3400) */
 #define MTK_DP_TRANS_P0_3400				0x3400
+#define HDCP_SEL_DP_TRANS_P0_MASK				BIT(11)
 #define PATTERN1_EN_DP_TRANS_P0_MASK				BIT(12)
 #define PATTERN2_EN_DP_TRANS_P0_MASK				BIT(13)
 #define PATTERN3_EN_DP_TRANS_P0_MASK				BIT(14)
@@ -276,7 +278,11 @@
 #define HPD_INT_THD_ECO_DP_TRANS_P0_MASK			GENMASK(1, 0)
 #define HPD_INT_THD_ECO_DP_TRANS_P0_HIGH_BOUND_EXT		BIT(1)
 #define MTK_DP_TRANS_P0_34A4				0x34a4
+#define HDCP22_AUTH_DONE_DP_TRANS_P0_MASK		BIT(4)
+#define R0_AVAILABLE_DP_TRANS_P0		BIT(12)
+#define REPEATER_I_DP_TRANS_P0_MASK		BIT(15)
 #define LANE_NUM_DP_TRANS_P0_MASK				GENMASK(3, 2)
+#define MTK_DP_TRANS_P0_34D0                0x34D0
 #define MTK_DP_TRANS_P0_3540				0x3540
 #define FEC_EN_DP_TRANS_P0_MASK					BIT(0)
 #define FEC_CLOCK_EN_MODE_DP_TRANS_P0				BIT(3)
drivers/gpu/drm/mediatek/mtk_dpi.c +3 -0
index bfe8653005db..6f85753c0c82 100644
@@ -25,6 +25,7 @@
 #include <drm/drm_edid.h>
 #include <drm/drm_of.h>
 #include <drm/drm_simple_kms_helper.h>
+#include <drm/display/drm_hdcp_helper.h>
 
 #include "mtk_ddp_comp.h"
 #include "mtk_disp_drv.h"
@@ -820,6 +821,8 @@ static int mtk_dpi_bind(struct device *dev, struct device *master, void *data)
 	}
 	drm_connector_attach_encoder(dpi->connector, &dpi->encoder);
 
+	drm_connector_attach_content_protection_property(dpi->connector, true);
+
 	return 0;
 
 err_cleanup:
Signature · 1 line
2.43.0
#3 lore raw

Re: [PATCH v3 2/3] Subject: [PATCH] drm/mediatek/dp: Add HDCP2.x feature for DisplayPort

Hi, Mac:

Quoted 12 lines · mac.shen

Changes in v3:
- refine the function to get system time
- refine the flow to do HDCP with content type and protection value which set by user space
- refine the flow to update content protection
- refine the flow to do HDCP2.x authentication per suggestion from the previous thread:
https://urldefense.com/v3/__https://patchwork.kernel.org/project/linux-mediatek__;!!CTRNKA9wMg0ARbw!md6xUiYN88D2YmETs8FQgaExM2zH8S1SmAEU9GRchwpNsXOyDFul3ziVKhRpCJaj8Rcn-gvM-801runjwA$
/patch/[email protected]/

---

[snip]

drivers/gpu/drm/mediatek/mtk_dp.c static void mtk_dp_init_port(struct mtk_dp *mtk_dp) · line 1843

Quoted 4 lines
drivers/gpu/drm/mediatek/mtk_dp.c +4 -0
+
+static void mtk_dp_hdcp_get_info(struct mtk_dp *mtk_dp)
+{
+	dp_tx_hdcp2x_get_info(&mtk_dp->hdcp_info);

dp_tx_hdcp2x_get_info() is only called by mtk_dp_hdcp_get_info() and mtk_dp_hdcp_get_info() only call mtk_dp_hdcp_get_info(), so merge these two function.

Regards,
CK

Quoted 2 lines
(quoted diff) +2 -0
+}
+
#4 lore raw

Re: [PATCH v3 2/3] Subject: [PATCH] drm/mediatek/dp: Add HDCP2.x feature for DisplayPort

In reply to mac.shen

Hi, Mac:

Quoted 12 lines · mac.shen

Changes in v3:
- refine the function to get system time
- refine the flow to do HDCP with content type and protection value which set by user space
- refine the flow to update content protection
- refine the flow to do HDCP2.x authentication per suggestion from the previous thread:
https://urldefense.com/v3/__https://patchwork.kernel.org/project/linux-mediatek__;!!CTRNKA9wMg0ARbw!md6xUiYN88D2YmETs8FQgaExM2zH8S1SmAEU9GRchwpNsXOyDFul3ziVKhRpCJaj8Rcn-gvM-801runjwA$
/patch/[email protected]/

---

[snip]

Quoted 59 lines
drivers/gpu/drm/mediatek/mtk_dp_hdcp2.c new file +59 -0
+/* Authentication flow starts from here */
+static int dp_tx_hdcp2x_key_exchange(struct mtk_hdcp_info *hdcp_info)
+{
+	struct mtk_dp *mtk_dp = container_of(hdcp_info, struct mtk_dp, hdcp_info);
+	bool stored;
+	int ret;
+
+	if (!hdcp_info->hdcp2_info.capable)
+		return -EAGAIN;
+
+	ret = dp_tx_hdcp2x_init(hdcp_info);
+	if (ret)
+		return ret;
+
+	ret = dp_tx_hdcp2x_write_ake_init(hdcp_info);
+	if (ret)
+		return ret;
+
+	ret = dp_tx_hdcp2x_read_ake_send_cert(hdcp_info);
+	if (ret)
+		return ret;
+
+	hdcp_info->hdcp2_info.repeater =
+		HDCP_2_2_RX_REPEATER(hdcp_info->hdcp2_info.hdcp_rx.send_cert.rx_caps[2]);
+
+	if (drm_hdcp_check_ksvs_revoked(mtk_dp->drm_dev,
+					hdcp_info->hdcp2_info.hdcp_rx.send_cert.cert_rx.receiver_id,
+					1) > 0) {
+		dev_err(mtk_dp->dev, "[HDCP2.X] Receiver ID is revoked\n");
+		return -EPERM;
+	}
+
+	ret = tee_ake_certificate(hdcp_info,
+				  (u8 *)&hdcp_info->hdcp2_info.hdcp_rx.cert_rx, &stored,
+		hdcp_info->hdcp2_info.ake_stored_km.e_kh_km_m +
+		HDCP_2_2_E_KH_KM_LEN,
+		hdcp_info->hdcp2_info.ake_stored_km.e_kh_km_m);
+	if (ret)
+		return ret;
+
+	hdcp_info->hdcp2_info.stored_km = stored;
+
+	if (!hdcp_info->hdcp2_info.stored_km) {
+		ret = tee_enc_rsaes_oaep(hdcp_info,
+					 hdcp_info->hdcp2_info.hdcp_tx.no_stored_km.e_kpub_km);
+		if (ret)
+			return ret;
+
+		ret = dp_tx_hdcp2x_write_ake_no_stored_km(hdcp_info);
+		if (ret)
+			return ret;
+
+	} else {
+		ret = dp_tx_hdcp2x_write_ake_stored_km(hdcp_info);
+		if (ret)
+			return ret;
+	}
+
+	ret = dp_tx_hdcp2x_read_ake_send_hprime(hdcp_info);

drivers/gpu/drm/mediatek/mtk_dp_hdcp2.c line 631

Quoted 10 lines
drivers/gpu/drm/mediatek/mtk_dp_hdcp2.c new file +10 -0
+	if (ret)
+		return ret;
+
+	ret = tee_ake_h_prime(hdcp_info,
+			      hdcp_info->hdcp2_info.hdcp_tx.ake_init.r_tx,
+		hdcp_info->hdcp2_info.hdcp_rx.send_cert.r_rx,
+		hdcp_info->hdcp2_info.hdcp_rx.send_cert.rx_caps,
+		(u8 *)&hdcp_info->hdcp2_info.hdcp_tx.tx_caps,
+		hdcp_info->hdcp2_info.hdcp_rx.send_hprime.h_prime,
+		HDCP_2_2_H_PRIME_LEN);

hdcp_info->hdcp2_info.hdcp_tx.ake_init,
hdcp_info->hdcp2_info.hdcp_rx.send_cert,
hdcp_info->hdcp2_info.hdcp_rx.send_hprime,
hdcp_info->hdcp2_info.hdcp_tx.no_stored_km,
hdcp_info->hdcp2_info.stored_km,
hdcp_info->hdcp2_info.hdcp_rx.pairing_info

are used only in dp_tx_hdcp2x_key_exchange(), so make them as local variable in dp_tx_hdcp2x_key_exchange().

hdcp_info->hdcp2_info.hdcp_tx.tx_caps is constant value, so use t_tx_caps[] directly instead of using hdcp_info->hdcp2_info.hdcp_tx.tx_caps.

Regards,
CK

Quoted 21 lines
drivers/gpu/drm/mediatek/mtk_dp_hdcp2.c new file +21 -0
+	if (ret) {
+		if (hdcp_info->hdcp2_info.stored_km)
+			tee_clear_paring(hdcp_info);
+		return ret;
+	}
+
+	if (!hdcp_info->hdcp2_info.stored_km) {
+		ret = dp_tx_hdcp2x_read_ake_send_pairing_info(hdcp_info);
+		if (ret)
+			return ret;
+
+		/* Store m, km, Ekh(km) */
+		ret = tee_ake_paring(hdcp_info,
+				     hdcp_info->hdcp2_info.hdcp_rx.pairing_info.e_kh_km);
+		if (ret)
+			return ret;
+	}
+
+	return 0;
+}
+
#5 lore raw

Re: [PATCH v3 2/3] Subject: [PATCH] drm/mediatek/dp: Add HDCP2.x feature for DisplayPort

In reply to mac.shen

Hi, Mac:

Quoted 12 lines · mac.shen

Changes in v3:
- refine the function to get system time
- refine the flow to do HDCP with content type and protection value which set by user space
- refine the flow to update content protection
- refine the flow to do HDCP2.x authentication per suggestion from the previous thread:
https://urldefense.com/v3/__https://patchwork.kernel.org/project/linux-mediatek__;!!CTRNKA9wMg0ARbw!md6xUiYN88D2YmETs8FQgaExM2zH8S1SmAEU9GRchwpNsXOyDFul3ziVKhRpCJaj8Rcn-gvM-801runjwA$
/patch/[email protected]/

---

[snip]

drivers/gpu/drm/mediatek/mtk_dp_hdcp2.c line 438

Quoted 12 lines
drivers/gpu/drm/mediatek/mtk_dp_hdcp2.c new file +12 -0
+
+static int dp_tx_hdcp2x_write_ake_no_stored_km(struct mtk_hdcp_info *hdcp_info)
+{
+	struct mtk_dp *mtk_dp = container_of(hdcp_info, struct mtk_dp, hdcp_info);
+	ssize_t ret;
+
+	dev_dbg(mtk_dp->dev, "[HDCP2.X] HDCP_2_2_AKE_NO_STORED_KM\n");
+
+	ret = drm_dp_dpcd_write(&mtk_dp->aux, DP_HDCP_2_2_AKE_NO_STORED_KM_OFFSET,
+				hdcp_info->hdcp2_info.hdcp_tx.no_stored_km.e_kpub_km,
+		HDCP_2_2_E_KPUB_KM_LEN);
+	if (ret < 0)

Directly return ret here.

Quoted 13 lines
drivers/gpu/drm/mediatek/mtk_dp_hdcp2.c new file +13 -0
+		return ret;
+
+	return 0;
+}
+
+static int dp_tx_hdcp2x_write_ake_stored_km(struct mtk_hdcp_info *hdcp_info)
+{
+	struct mtk_dp *mtk_dp = container_of(hdcp_info, struct mtk_dp, hdcp_info);
+	ssize_t ret;
+
+	dev_dbg(mtk_dp->dev, "[HDCP2.X] HDCP_2_2_AKE_STORED_KM\n");
+
+	ret = drm_dp_dpcd_write(&mtk_dp->aux, DP_HDCP_2_2_AKE_STORED_KM_OFFSET,

drivers/gpu/drm/mediatek/mtk_dp_hdcp2.c line 461

Quoted 10 lines
drivers/gpu/drm/mediatek/mtk_dp_hdcp2.c new file +10 -0
+				hdcp_info->hdcp2_info.ake_stored_km.e_kh_km_m,
+		HDCP_2_2_E_KH_KM_LEN);
+	if (ret < 0)
+		return ret;
+
+	ret = drm_dp_dpcd_write(&mtk_dp->aux, DP_HDCP_2_2_REG_M_OFFSET,
+				hdcp_info->hdcp2_info.ake_stored_km.e_kh_km_m +
+		HDCP_2_2_E_KH_KM_LEN,
+		HDCP_2_2_E_KH_KM_M_LEN - HDCP_2_2_E_KH_KM_LEN);
+	if (ret < 0)

Ditto.

Regards,
CK

Quoted 5 lines
drivers/gpu/drm/mediatek/mtk_dp.c +5 -0
+		return ret;
+
+	return 0;
+}
+
#6 lore raw

Re: [PATCH v3 2/3] Subject: [PATCH] drm/mediatek/dp: Add HDCP2.x feature for DisplayPort

In reply to mac.shen

Hi, Mac:

Quoted 12 lines · mac.shen

Changes in v3:
- refine the function to get system time
- refine the flow to do HDCP with content type and protection value which set by user space
- refine the flow to update content protection
- refine the flow to do HDCP2.x authentication per suggestion from the previous thread:
https://urldefense.com/v3/__https://patchwork.kernel.org/project/linux-mediatek__;!!CTRNKA9wMg0ARbw!md6xUiYN88D2YmETs8FQgaExM2zH8S1SmAEU9GRchwpNsXOyDFul3ziVKhRpCJaj8Rcn-gvM-801runjwA$
/patch/[email protected]/

---

[snip]

Quoted 8 lines
drivers/gpu/drm/mediatek/mtk_dp_hdcp2.c new file +8 -0
+static int dp_tx_hdcp2x_enable_auth(struct mtk_hdcp_info *hdcp_info, bool enable)
+{
+	struct mtk_dp *mtk_dp = container_of(hdcp_info, struct mtk_dp, hdcp_info);
+	u32 version;
+	int ret;
+
+	dp_tx_hdcp2x_set_auth_pass(hdcp_info, enable);
+	if (!enable) {

drivers/gpu/drm/mediatek/mtk_dp_hdcp2.c line 71

Quoted 10 lines
drivers/gpu/drm/mediatek/mtk_dp_hdcp2.c new file +10 -0
+		ret = tee_hdcp_enable_encrypt(hdcp_info, enable, HDCP_NONE);
+		if (ret)
+			return ret;
+		mtk_dp_update_bits(mtk_dp, MTK_DP_ENC0_P0_3000, 0, HDCP_FRAME_EN_DP_ENC0_P0);
+
+		return 0;
+	}
+
+	if (HDCP_2_2_HDCP1_DEVICE_CONNECTED(hdcp_info->hdcp2_info.hdcp_rx.recvid_list.rx_info[1]))
+		version = HDCP_V1;

dp_tx_hdcp2x_enable_auth() is called only when HDCP 2.x, but here detect that version is 1.
I don't know the specification of HDCP, is this is an error case?
Or if this is a normal case, please add some comment here to explain for someone who don't know HDCP specification.

Regards,
CK

Quoted 15 lines
drivers/gpu/drm/mediatek/mtk_dp_hdcp2.c new file +15 -0
+	else if (HDCP_2_2_HDCP_2_0_REP_CONNECTED
+		(hdcp_info->hdcp2_info.hdcp_rx.recvid_list.rx_info[1]))
+		version = HDCP_V2;
+	else
+		version = HDCP_V2_3;
+
+	ret = tee_hdcp_enable_encrypt(hdcp_info, enable, version);
+	if (ret)
+		return ret;
+	mtk_dp_update_bits(mtk_dp, MTK_DP_ENC0_P0_3000,
+			   HDCP_FRAME_EN_DP_ENC0_P0, HDCP_FRAME_EN_DP_ENC0_P0);
+
+	return 0;
+}
+
#7 lore raw

Re: [PATCH v3 2/3] Subject: [PATCH] drm/mediatek/dp: Add HDCP2.x feature for DisplayPort

In reply to mac.shen

Hi, Mac:

Quoted 12 lines · mac.shen

Changes in v3:
- refine the function to get system time
- refine the flow to do HDCP with content type and protection value which set by user space
- refine the flow to update content protection
- refine the flow to do HDCP2.x authentication per suggestion from the previous thread:
https://urldefense.com/v3/__https://patchwork.kernel.org/project/linux-mediatek__;!!CTRNKA9wMg0ARbw!md6xUiYN88D2YmETs8FQgaExM2zH8S1SmAEU9GRchwpNsXOyDFul3ziVKhRpCJaj8Rcn-gvM-801runjwA$
/patch/[email protected]/

---

[snip]

Quoted 4 lines
drivers/gpu/drm/mediatek/mtk_dp_hdcp2.c new file +4 -0
+
+static int dp_tx_hdcp2x_init(struct mtk_hdcp_info *hdcp_info)
+{
+	int ret;

drivers/gpu/drm/mediatek/mtk_dp_hdcp2.c line 99

Quoted 10 lines
drivers/gpu/drm/mediatek/mtk_dp_hdcp2.c new file +10 -0
+
+	memset(&hdcp_info->hdcp2_info.hdcp_tx, 0, sizeof(struct hdcp2_info_tx));
+	memset(&hdcp_info->hdcp2_info.hdcp_rx, 0, sizeof(struct hdcp2_info_rx));
+	memset(&hdcp_info->hdcp2_info.ake_stored_km, 0, sizeof(struct hdcp2_ake_stored_km));
+	memcpy(hdcp_info->hdcp2_info.hdcp_tx.ake_init.r_tx, t_rtx, HDCP_2_2_RTX_LEN);
+	memcpy(&hdcp_info->hdcp2_info.hdcp_tx.tx_caps, t_tx_caps, HDCP_2_2_TXCAPS_LEN);
+	memcpy(hdcp_info->hdcp2_info.hdcp_tx.lc_init.r_n, t_rn, HDCP_2_2_RN_LEN);
+	memcpy(hdcp_info->hdcp2_info.hdcp_tx.send_eks.riv, t_riv, HDCP_2_2_RIV_LEN);
+
+	ret = dp_tx_hdcp2x_enable_auth(hdcp_info, false);

By default, auth is disabled. So this is redundant.

Regards,
CK

Quoted 6 lines
drivers/gpu/drm/mediatek/mtk_dp_hdcp2.c new file +6 -0
+	if (ret)
+		return ret;
+
+	return 0;
+}
+
#8 lore raw

Re: [PATCH v3 2/3] Subject: [PATCH] drm/mediatek/dp: Add HDCP2.x feature for DisplayPort

In reply to mac.shen

Hi, Mac:

Quoted 12 lines · mac.shen

Changes in v3:
- refine the function to get system time
- refine the flow to do HDCP with content type and protection value which set by user space
- refine the flow to update content protection
- refine the flow to do HDCP2.x authentication per suggestion from the previous thread:
https://urldefense.com/v3/__https://patchwork.kernel.org/project/linux-mediatek__;!!CTRNKA9wMg0ARbw!md6xUiYN88D2YmETs8FQgaExM2zH8S1SmAEU9GRchwpNsXOyDFul3ziVKhRpCJaj8Rcn-gvM-801runjwA$
/patch/[email protected]/

---

[snip]

Quoted 45 lines
drivers/gpu/drm/mediatek/mtk_dp_hdcp2.c new file +45 -0
+
+int dp_tx_hdcp2x_check_link(struct mtk_hdcp_info *hdcp_info)
+{
+	struct mtk_dp *mtk_dp = container_of(hdcp_info, struct mtk_dp, hdcp_info);
+	u8 rx_status;
+	int ret = -EINVAL;
+	int tmp = 0;
+
+	mutex_lock(&mtk_dp->hdcp_mutex);
+
+	if (mtk_dp->hdcp_info.auth_status != AUTH_PASS)
+		goto end;
+
+	if (!mtk_dp->train_info.cable_plugged_in || !mtk_dp->enabled)
+		goto disable;
+
+	ret = drm_dp_dpcd_read(&mtk_dp->aux, DP_HDCP_2_2_REG_RXSTATUS_OFFSET, &rx_status,
+			       HDCP_2_2_DP_RXSTATUS_LEN);
+	if (ret != HDCP_2_2_DP_RXSTATUS_LEN) {
+		dev_dbg(mtk_dp->dev, "[HDCP2.X] Read bstatus failed, reauth\n");
+		goto disable;
+	}
+
+	if (HDCP_2_2_DP_RXSTATUS_REAUTH_REQ(rx_status))
+		tmp = REAUTH_REQUEST;
+	else if (HDCP_2_2_DP_RXSTATUS_LINK_FAILED(rx_status))
+		tmp = LINK_INTEGRITY_FAILURE;
+	else if (HDCP_2_2_DP_RXSTATUS_READY(rx_status))
+		tmp = TOPOLOGY_CHANGE;
+
+	if (tmp == LINK_PROTECTED) {
+		mtk_dp_hdcp_update_value(mtk_dp, DRM_MODE_CONTENT_PROTECTION_ENABLED);
+		ret = 0;
+		goto end;
+	}
+
+	if (tmp == TOPOLOGY_CHANGE) {
+		ret = dp_tx_hdcp2x_authenticate_repeater(hdcp_info);
+		if (!ret) {
+			mtk_dp_hdcp_update_value(mtk_dp, DRM_MODE_CONTENT_PROTECTION_ENABLED);
+			goto end;
+		}
+	} else {
+		dev_info(mtk_dp->dev, "[HDCP2.X] link failed with:0x%x, retrying auth\n", tmp);
+	}

drivers/gpu/drm/mediatek/mtk_dp_hdcp2.c line 930

Quoted 10 lines
drivers/gpu/drm/mediatek/mtk_dp_hdcp2.c new file +10 -0
+
+disable:
+	ret = dp_tx_hdcp2x_disabel(hdcp_info);
+	if (ret || !mtk_dp->train_info.cable_plugged_in || !mtk_dp->enabled) {
+		ret = -EAGAIN;
+		mtk_dp_hdcp_update_value(mtk_dp, DRM_MODE_CONTENT_PROTECTION_DESIRED);
+		goto end;
+	}
+
+	ret = dp_tx_hdcp2x_enable(hdcp_info);

When something error then go here. Why enable hdcp?

Regards,
CK

Quoted 9 lines
drivers/gpu/drm/mediatek/mtk_dp_hdcp2.c new file +9 -0
+	if (ret)
+		mtk_dp_hdcp_update_value(mtk_dp, DRM_MODE_CONTENT_PROTECTION_DESIRED);
+
+end:
+	mutex_unlock(&mtk_dp->hdcp_mutex);
+
+	return ret;
+}
+
#9 lore raw

Re: [PATCH v3 2/3] Subject: [PATCH] drm/mediatek/dp: Add HDCP2.x feature for DisplayPort

In reply to mac.shen

Hi, Mac:

Quoted 12 lines · mac.shen

Changes in v3:
- refine the function to get system time
- refine the flow to do HDCP with content type and protection value which set by user space
- refine the flow to update content protection
- refine the flow to do HDCP2.x authentication per suggestion from the previous thread:
https://urldefense.com/v3/__https://patchwork.kernel.org/project/linux-mediatek__;!!CTRNKA9wMg0ARbw!md6xUiYN88D2YmETs8FQgaExM2zH8S1SmAEU9GRchwpNsXOyDFul3ziVKhRpCJaj8Rcn-gvM-801runjwA$
/patch/[email protected]/

---

[snip]

Quoted 33 lines
drivers/gpu/drm/mediatek/mtk_dp.c +11 -0
@@ -2242,6 +2373,7 @@ static void mtk_dp_bridge_atomic_enable(struct drm_bridge *bridge,
 					struct drm_bridge_state *old_state)
 {
 	struct mtk_dp *mtk_dp = mtk_dp_from_bridge(bridge);
+	struct drm_connector_state *connector_state;
 	int ret;
 
 	mtk_dp->conn = drm_atomic_get_new_connector_for_encoder(old_state->base.state,
@@ -2252,6 +2384,8 @@ static void mtk_dp_bridge_atomic_enable(struct drm_bridge *bridge,
 		return;
 	}
 
+	connector_state = drm_atomic_get_connector_state(old_state->base.state, mtk_dp->conn);
+
 	mtk_dp_aux_panel_poweron(mtk_dp, true);
 
 	/* Training */
@@ -2281,6 +2415,14 @@ static void mtk_dp_bridge_atomic_enable(struct drm_bridge *bridge,
 	mtk_dp->enabled = true;
 	mtk_dp_update_plugged_status(mtk_dp);
 
+	/* Enable hdcp if it's desired */
+	dev_dbg(mtk_dp->dev, "hdcp_content_type:%d, content protection: %d",
+		connector_state->hdcp_content_type, connector_state->content_protection);
+	if (connector_state->content_protection == DRM_MODE_CONTENT_PROTECTION_DESIRED) {
+		mtk_dp->hdcp_info.hdcp_content_type = connector_state->hdcp_content_type;
+		mtk_dp_hdcp_enable(mtk_dp);
+	}
+
 	return;
 power_off_aux:
 	mtk_dp_update_bits(mtk_dp, MTK_DP_TOP_PWR_STATE,

drivers/gpu/drm/mediatek/mtk_dp.c static int mtk_dp_bridge_atomic_check(struct drm_bridge *bridge, · line 2575

Quoted 7 lines
drivers/gpu/drm/mediatek/mtk_dp.c +2 -0
@@ -2427,6 +2569,8 @@ static int mtk_dp_bridge_atomic_check(struct drm_bridge *bridge,
 
 	drm_display_mode_to_videomode(&crtc_state->adjusted_mode, &mtk_dp->info.vm);
 
+	mtk_dp_hdcp_atomic_check(mtk_dp, conn_state);
+
 	return 0;
 }

In mtk_dp_bridge_atomic_enable(), you enable hdcp. So in mtk_dp_bridge_atomic_disable(), you should disable hdcp.

Regards,
CK

Quoted 1 line
#10 lore raw

Re: [PATCH v3 2/3] Subject: [PATCH] drm/mediatek/dp: Add HDCP2.x feature for DisplayPort

In reply to mac.shen

Hi, Mac:

Quoted 12 lines · mac.shen

Changes in v3:
- refine the function to get system time
- refine the flow to do HDCP with content type and protection value which set by user space
- refine the flow to update content protection
- refine the flow to do HDCP2.x authentication per suggestion from the previous thread:
https://urldefense.com/v3/__https://patchwork.kernel.org/project/linux-mediatek__;!!CTRNKA9wMg0ARbw!md6xUiYN88D2YmETs8FQgaExM2zH8S1SmAEU9GRchwpNsXOyDFul3ziVKhRpCJaj8Rcn-gvM-801runjwA$
/patch/[email protected]/

---

[snip]

Quoted 4 lines
drivers/gpu/drm/mediatek/mtk_dp_hdcp2.c new file +4 -0
+
+static int dp_tx_hdcp2x_write_lc_init(struct mtk_hdcp_info *hdcp_info)
+{
+	struct mtk_dp *mtk_dp = container_of(hdcp_info, struct mtk_dp, hdcp_info);

drivers/gpu/drm/mediatek/mtk_dp_hdcp2.c line 479

Quoted 10 lines
drivers/gpu/drm/mediatek/mtk_dp_hdcp2.c new file +10 -0
+	ssize_t ret;
+
+	dev_dbg(mtk_dp->dev, "[HDCP2.X] HDCP_2_2_LC_INIT\n");
+
+	ret = drm_dp_dpcd_write(&mtk_dp->aux, DP_HDCP_2_2_LC_INIT_OFFSET,
+				hdcp_info->hdcp2_info.hdcp_tx.lc_init.r_n, HDCP_2_2_RN_LEN);
+	if (ret < 0)
+		return ret;
+
+	return 0;

This function is called only by dp_tx_hdcp2x_locality_check() and this function just does one thing. So merge this function into dp_tx_hdcp2x_locality_check().

Regards,
CK

Quoted 2 lines
(quoted diff) +2 -0
+}
+
#11 lore raw

Re: [PATCH v3 2/3] Subject: [PATCH] drm/mediatek/dp: Add HDCP2.x feature for DisplayPort

In reply to mac.shen

Hi, Mac:

Quoted 12 lines · mac.shen

Changes in v3:
- refine the function to get system time
- refine the flow to do HDCP with content type and protection value which set by user space
- refine the flow to update content protection
- refine the flow to do HDCP2.x authentication per suggestion from the previous thread:
https://urldefense.com/v3/__https://patchwork.kernel.org/project/linux-mediatek__;!!CTRNKA9wMg0ARbw!md6xUiYN88D2YmETs8FQgaExM2zH8S1SmAEU9GRchwpNsXOyDFul3ziVKhRpCJaj8Rcn-gvM-801runjwA$
/patch/[email protected]/

---

[snip]

Quoted 7 lines
drivers/gpu/drm/mediatek/mtk_dp_hdcp2.c new file +7 -0
+
+static int dp_tx_hdcp2x_read_lc_send_lprime(struct mtk_hdcp_info *hdcp_info)
+{
+	struct mtk_dp *mtk_dp = container_of(hdcp_info, struct mtk_dp, hdcp_info);
+	ssize_t ret;
+
+	dev_dbg(mtk_dp->dev, "[HDCP2.X] HDCP_2_2_LC_SEND_LPRIME\n");

drivers/gpu/drm/mediatek/mtk_dp_hdcp2.c line 330

Quoted 10 lines
drivers/gpu/drm/mediatek/mtk_dp_hdcp2.c new file +10 -0
+
+	mdelay(HDCP_2_2_DP_LPRIME_TIMEOUT_MS);
+
+	ret = drm_dp_dpcd_read(&mtk_dp->aux, DP_HDCP_2_2_LC_SEND_LPRIME_OFFSET,
+			       hdcp_info->hdcp2_info.hdcp_rx.send_lprime.l_prime,
+		HDCP_2_2_L_PRIME_LEN);
+	if (ret < 0)
+		return ret;
+
+	return 0;

This function is called only by dp_tx_hdcp2x_locality_check(), and this function just does two things. So merge this function into dp_tx_hdcp2x_locality_check().

Regards,
CK

Quoted 2 lines
(quoted diff) +2 -0
+}
+
#12 lore raw

Re: [PATCH v3 2/3] Subject: [PATCH] drm/mediatek/dp: Add HDCP2.x feature for DisplayPort

In reply to mac.shen

Hi, Mac:

Quoted 12 lines · mac.shen

Changes in v3:
- refine the function to get system time
- refine the flow to do HDCP with content type and protection value which set by user space
- refine the flow to update content protection
- refine the flow to do HDCP2.x authentication per suggestion from the previous thread:
https://urldefense.com/v3/__https://patchwork.kernel.org/project/linux-mediatek__;!!CTRNKA9wMg0ARbw!md6xUiYN88D2YmETs8FQgaExM2zH8S1SmAEU9GRchwpNsXOyDFul3ziVKhRpCJaj8Rcn-gvM-801runjwA$
/patch/[email protected]/

---

[snip]

Quoted 5 lines
drivers/gpu/drm/mediatek/mtk_dp_hdcp2.c new file +5 -0
+static int dp_tx_hdcp2x_write_ske_send_eks(struct mtk_hdcp_info *hdcp_info)
+{
+	struct mtk_dp *mtk_dp = container_of(hdcp_info, struct mtk_dp, hdcp_info);
+	ssize_t ret;
+

drivers/gpu/drm/mediatek/mtk_dp_hdcp2.c line 496

Quoted 10 lines
drivers/gpu/drm/mediatek/mtk_dp_hdcp2.c new file +10 -0
+	dev_dbg(mtk_dp->dev, "[HDCP2.X] HDCP_2_2_SKE_SEND_EKS\n");
+
+	ret = drm_dp_dpcd_write(&mtk_dp->aux, DP_HDCP_2_2_SKE_SEND_EKS_OFFSET,
+				hdcp_info->hdcp2_info.hdcp_tx.send_eks.e_dkey_ks,
+		HDCP_2_2_E_DKEY_KS_LEN);
+	if (ret < 0)
+		return ret;
+
+	ret = drm_dp_dpcd_write(&mtk_dp->aux, DP_HDCP_2_2_REG_RIV_OFFSET,
+				hdcp_info->hdcp2_info.hdcp_tx.send_eks.riv, HDCP_2_2_RIV_LEN);

riv is constant, so remove hdcp_info->hdcp2_info.hdcp_tx.send_eks.riv and use t_riv directly.

drivers/gpu/drm/mediatek/mtk_dp_hdcp2.c line 681

Quoted 12 lines
drivers/gpu/drm/mediatek/mtk_dp_hdcp2.c new file +12 -0
+	if (ret < 0)
+		return ret;
+
+	return 0;
+}
+
+static int dp_tx_hdcp2x_session_key_exchange(struct mtk_hdcp_info *hdcp_info)
+{
+	int ret;
+
+	ret = tee_ske_enc_ks(hdcp_info, hdcp_info->hdcp2_info.hdcp_tx.send_eks.riv,
+			     hdcp_info->hdcp2_info.hdcp_tx.send_eks.e_dkey_ks);

Ditto.

Regards,
CK

Quoted 10 lines
drivers/gpu/drm/mediatek/mtk_dp_hdcp2.c new file +10 -0
+	if (ret)
+		return ret;
+
+	ret = dp_tx_hdcp2x_write_ske_send_eks(hdcp_info);
+	if (ret)
+		return ret;
+
+	return 0;
+}
+
#13 lore raw

Re: [PATCH v3 2/3] Subject: [PATCH] drm/mediatek/dp: Add HDCP2.x feature for DisplayPort

In reply to mac.shen

Hi, Mac:

Quoted 12 lines · mac.shen

Changes in v3:
- refine the function to get system time
- refine the flow to do HDCP with content type and protection value which set by user space
- refine the flow to update content protection
- refine the flow to do HDCP2.x authentication per suggestion from the previous thread:
https://urldefense.com/v3/__https://patchwork.kernel.org/project/linux-mediatek__;!!CTRNKA9wMg0ARbw!md6xUiYN88D2YmETs8FQgaExM2zH8S1SmAEU9GRchwpNsXOyDFul3ziVKhRpCJaj8Rcn-gvM-801runjwA$
/patch/[email protected]/

---

[snip]

Quoted 9 lines
drivers/gpu/drm/mediatek/mtk_dp_hdcp2.c new file +9 -0
+static int dp_tx_hdcp2x_write_ske_send_eks(struct mtk_hdcp_info *hdcp_info)
+{
+	struct mtk_dp *mtk_dp = container_of(hdcp_info, struct mtk_dp, hdcp_info);
+	ssize_t ret;
+
+	dev_dbg(mtk_dp->dev, "[HDCP2.X] HDCP_2_2_SKE_SEND_EKS\n");
+
+	ret = drm_dp_dpcd_write(&mtk_dp->aux, DP_HDCP_2_2_SKE_SEND_EKS_OFFSET,
+				hdcp_info->hdcp2_info.hdcp_tx.send_eks.e_dkey_ks,

drivers/gpu/drm/mediatek/mtk_dp_hdcp2.c line 500

Quoted 10 lines
drivers/gpu/drm/mediatek/mtk_dp_hdcp2.c new file +10 -0
+		HDCP_2_2_E_DKEY_KS_LEN);
+	if (ret < 0)
+		return ret;
+
+	ret = drm_dp_dpcd_write(&mtk_dp->aux, DP_HDCP_2_2_REG_RIV_OFFSET,
+				hdcp_info->hdcp2_info.hdcp_tx.send_eks.riv, HDCP_2_2_RIV_LEN);
+	if (ret < 0)
+		return ret;
+
+	return 0;

This function is called only by dp_tx_hdcp2x_session_key_exchange() and only does two things. So merge this function into dp_tx_hdcp2x_session_key_exchange().

Regards,
CK

Quoted 2 lines
(quoted diff) +2 -0
+}
+
#14 lore raw

Re: [PATCH v3 2/3] Subject: [PATCH] drm/mediatek/dp: Add HDCP2.x feature for DisplayPort

In reply to mac.shen

Hi, Mac:

Quoted 12 lines · mac.shen

Changes in v3:
- refine the function to get system time
- refine the flow to do HDCP with content type and protection value which set by user space
- refine the flow to update content protection
- refine the flow to do HDCP2.x authentication per suggestion from the previous thread:
https://urldefense.com/v3/__https://patchwork.kernel.org/project/linux-mediatek__;!!CTRNKA9wMg0ARbw!md6xUiYN88D2YmETs8FQgaExM2zH8S1SmAEU9GRchwpNsXOyDFul3ziVKhRpCJaj8Rcn-gvM-801runjwA$
/patch/[email protected]/

---

[snip]

Quoted 6 lines
drivers/gpu/drm/mediatek/mtk_dp_hdcp2.c new file +6 -0
+static int dp_tx_hdcp2x_read_ake_send_hprime(struct mtk_hdcp_info *hdcp_info)
+{
+	struct mtk_dp *mtk_dp = container_of(hdcp_info, struct mtk_dp, hdcp_info);
+	ktime_t msg_end;
+	bool msg_expired;
+	u8 rx_status = 0;

drivers/gpu/drm/mediatek/mtk_dp_hdcp2.c line 254

Quoted 10 lines
drivers/gpu/drm/mediatek/mtk_dp_hdcp2.c new file +10 -0
+	int timeout;
+	ssize_t ret;
+
+	dev_dbg(mtk_dp->dev, "[HDCP2.X] HDCP_2_2_AKE_SEND_HPRIME\n");
+
+	timeout = hdcp_info->hdcp2_info.stored_km ?
+		HDCP_2_2_HPRIME_PAIRED_TIMEOUT_MS : HDCP_2_2_HPRIME_NO_PAIRED_TIMEOUT_MS;
+
+	dp_tx_hdcp2x_wait_for_cp_irq(hdcp_info, timeout);
+	hdcp_info->hdcp2_info.cp_irq_cached = atomic_read(&hdcp_info->hdcp2_info.cp_irq);

cp_irq_cached is updated always after dp_tx_hdcp2x_wait_for_cp_irq(), and cp_irq_cached is only used in dp_tx_hdcp2x_wait_for_cp_irq(), so move this update into dp_tx_hdcp2x_wait_for_cp_irq().

Regards,
CK

Quoted 24 lines
drivers/gpu/drm/mediatek/mtk_dp_hdcp2.c new file +24 -0
+
+	ret = drm_dp_dpcd_read(&mtk_dp->aux, DP_HDCP_2_2_REG_RXSTATUS_OFFSET, &rx_status,
+			       HDCP_2_2_DP_RXSTATUS_LEN);
+	if (ret != HDCP_2_2_DP_RXSTATUS_LEN)
+		return ret >= 0 ? -EIO : ret;
+
+	if (!HDCP_2_2_DP_RXSTATUS_H_PRIME(rx_status))
+		return -EAGAIN;
+
+	msg_end = ktime_add_ms(ktime_get_raw(), HDCP_2_2_DP_HPRIME_READ_TIMEOUT_MS);
+
+	ret = drm_dp_dpcd_read(&mtk_dp->aux, DP_HDCP_2_2_AKE_SEND_HPRIME_OFFSET,
+			       hdcp_info->hdcp2_info.hdcp_rx.send_hprime.h_prime,
+		HDCP_2_2_H_PRIME_LEN);
+	if (ret < 0)
+		return ret;
+
+	msg_expired = ktime_after(ktime_get_raw(), msg_end);
+	if (msg_expired)
+		dev_dbg(mtk_dp->dev, "[HDCP2.X] Timeout to read AKE hprime\n");
+
+	return 0;
+}
+
#15 lore raw

Re: [PATCH v3 2/3] Subject: [PATCH] drm/mediatek/dp: Add HDCP2.x feature for DisplayPort

In reply to mac.shen

Hi, Mac:

Quoted 12 lines · mac.shen

Changes in v3:
- refine the function to get system time
- refine the flow to do HDCP with content type and protection value which set by user space
- refine the flow to update content protection
- refine the flow to do HDCP2.x authentication per suggestion from the previous thread:
https://urldefense.com/v3/__https://patchwork.kernel.org/project/linux-mediatek__;!!CTRNKA9wMg0ARbw!md6xUiYN88D2YmETs8FQgaExM2zH8S1SmAEU9GRchwpNsXOyDFul3ziVKhRpCJaj8Rcn-gvM-801runjwA$
/patch/[email protected]/

---

[snip]

Quoted 10 lines
drivers/gpu/drm/mediatek/mtk_dp_hdcp2.c new file +10 -0
+
+static int dp_tx_hdcp2x_read_rep_send_recvid_list(struct mtk_hdcp_info *hdcp_info)
+{
+	struct mtk_dp *mtk_dp = container_of(hdcp_info, struct mtk_dp, hdcp_info);
+	u8 rx_status = 0;
+	ssize_t ret;
+
+	dev_dbg(mtk_dp->dev, "[HDCP2.X] HDCP_2_2_REP_SEND_RECVID_LIST\n");
+
+	dp_tx_hdcp2x_wait_for_cp_irq(hdcp_info, HDCP_2_2_RECVID_LIST_TIMEOUT_MS);

drivers/gpu/drm/mediatek/mtk_dp_hdcp2.c line 351

Quoted 10 lines
drivers/gpu/drm/mediatek/mtk_dp_hdcp2.c new file +10 -0
+	hdcp_info->hdcp2_info.cp_irq_cached = atomic_read(&hdcp_info->hdcp2_info.cp_irq);
+
+	ret = drm_dp_dpcd_read(&mtk_dp->aux, DP_HDCP_2_2_REG_RXSTATUS_OFFSET, &rx_status,
+			       HDCP_2_2_DP_RXSTATUS_LEN);
+	if (ret != HDCP_2_2_DP_RXSTATUS_LEN)
+		return ret >= 0 ? -EIO : ret;
+
+	if (!HDCP_2_2_DP_RXSTATUS_READY(rx_status)) {
+		dev_err(mtk_dp->dev, "[HDCP2.X] RX status no ready\n");
+		return -EAGAIN;

In [1], intel return -ETIMEOUT and not retry. Maybe return -ETIMEOUT is better?

[1] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/gpu/drm/i915/display/intel_dp_hdcp.c?h=v6.12-rc5#n428

Regards,
CK

Quoted 33 lines
drivers/gpu/drm/mediatek/mtk_dp_hdcp2.c new file +33 -0
+	}
+
+	ret = drm_dp_dpcd_read(&mtk_dp->aux, DP_HDCP_2_2_REP_SEND_RECVID_LIST_OFFSET,
+			       hdcp_info->hdcp2_info.hdcp_rx.recvid_list.rx_info,
+		HDCP_2_2_RXINFO_LEN);
+	if (ret < 0)
+		return ret;
+
+	hdcp_info->hdcp2_info.device_count =
+	(HDCP_2_2_DEV_COUNT_HI(hdcp_info->hdcp2_info.hdcp_rx.recvid_list.rx_info[0]) << 4 |
+	HDCP_2_2_DEV_COUNT_LO(hdcp_info->hdcp2_info.hdcp_rx.recvid_list.rx_info[1]));
+
+	ret = drm_dp_dpcd_read(&mtk_dp->aux, DP_HDCP_2_2_REG_SEQ_NUM_V_OFFSET,
+			       hdcp_info->hdcp2_info.hdcp_rx.recvid_list.seq_num_v,
+		HDCP_2_2_SEQ_NUM_LEN);
+	if (ret < 0)
+		return ret;
+
+	ret = drm_dp_dpcd_read(&mtk_dp->aux, DP_HDCP_2_2_REG_VPRIME_OFFSET,
+			       hdcp_info->hdcp2_info.hdcp_rx.recvid_list.v_prime,
+		HDCP_2_2_V_PRIME_HALF_LEN);
+	if (ret < 0)
+		return ret;
+
+	ret = drm_dp_dpcd_read(&mtk_dp->aux, DP_HDCP_2_2_REG_RECV_ID_LIST_OFFSET,
+			       hdcp_info->hdcp2_info.hdcp_rx.recvid_list.receiver_ids,
+		hdcp_info->hdcp2_info.device_count * HDCP_2_2_RECEIVER_ID_LEN);
+	if (ret < 0)
+		return ret;
+
+	return 0;
+}
+
#16 lore raw

Re: [PATCH v3 2/3] Subject: [PATCH] drm/mediatek/dp: Add HDCP2.x feature for DisplayPort

In reply to mac.shen

Hi, Mac:

Quoted 12 lines · mac.shen

Changes in v3:
- refine the function to get system time
- refine the flow to do HDCP with content type and protection value which set by user space
- refine the flow to update content protection
- refine the flow to do HDCP2.x authentication per suggestion from the previous thread:
https://urldefense.com/v3/__https://patchwork.kernel.org/project/linux-mediatek__;!!CTRNKA9wMg0ARbw!md6xUiYN88D2YmETs8FQgaExM2zH8S1SmAEU9GRchwpNsXOyDFul3ziVKhRpCJaj8Rcn-gvM-801runjwA$
/patch/[email protected]/

---

[snip]

Quoted 15 lines
drivers/gpu/drm/mediatek/mtk_dp_hdcp2.c new file +15 -0
+
+static int dp_tx_hdcp2x_read_rep_send_recvid_list(struct mtk_hdcp_info *hdcp_info)
+{
+	struct mtk_dp *mtk_dp = container_of(hdcp_info, struct mtk_dp, hdcp_info);
+	u8 rx_status = 0;
+	ssize_t ret;
+
+	dev_dbg(mtk_dp->dev, "[HDCP2.X] HDCP_2_2_REP_SEND_RECVID_LIST\n");
+
+	dp_tx_hdcp2x_wait_for_cp_irq(hdcp_info, HDCP_2_2_RECVID_LIST_TIMEOUT_MS);
+	hdcp_info->hdcp2_info.cp_irq_cached = atomic_read(&hdcp_info->hdcp2_info.cp_irq);
+
+	ret = drm_dp_dpcd_read(&mtk_dp->aux, DP_HDCP_2_2_REG_RXSTATUS_OFFSET, &rx_status,
+			       HDCP_2_2_DP_RXSTATUS_LEN);
+	if (ret != HDCP_2_2_DP_RXSTATUS_LEN)

drivers/gpu/drm/mediatek/mtk_dp_hdcp2.c line 356

Quoted 10 lines
drivers/gpu/drm/mediatek/mtk_dp_hdcp2.c new file +10 -0
+		return ret >= 0 ? -EIO : ret;
+
+	if (!HDCP_2_2_DP_RXSTATUS_READY(rx_status)) {
+		dev_err(mtk_dp->dev, "[HDCP2.X] RX status no ready\n");
+		return -EAGAIN;
+	}
+
+	ret = drm_dp_dpcd_read(&mtk_dp->aux, DP_HDCP_2_2_REP_SEND_RECVID_LIST_OFFSET,
+			       hdcp_info->hdcp2_info.hdcp_rx.recvid_list.rx_info,
+		HDCP_2_2_RXINFO_LEN);

In [1], intel use DP_HDCP_2_2_REG_RXINFO_OFFSET to get device count. But here you use DP_HDCP_2_2_REP_SEND_RECVID_LIST_OFFSET to get device count. So both command can get device count? Or something wrong?

[1] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/gpu/drm/i915/display/intel_dp_hdcp.c?h=v6.12-rc5#n497

Regards,
CK

Quoted 28 lines
drivers/gpu/drm/mediatek/mtk_dp_hdcp2.c new file +28 -0
+	if (ret < 0)
+		return ret;
+
+	hdcp_info->hdcp2_info.device_count =
+	(HDCP_2_2_DEV_COUNT_HI(hdcp_info->hdcp2_info.hdcp_rx.recvid_list.rx_info[0]) << 4 |
+	HDCP_2_2_DEV_COUNT_LO(hdcp_info->hdcp2_info.hdcp_rx.recvid_list.rx_info[1]));
+
+	ret = drm_dp_dpcd_read(&mtk_dp->aux, DP_HDCP_2_2_REG_SEQ_NUM_V_OFFSET,
+			       hdcp_info->hdcp2_info.hdcp_rx.recvid_list.seq_num_v,
+		HDCP_2_2_SEQ_NUM_LEN);
+	if (ret < 0)
+		return ret;
+
+	ret = drm_dp_dpcd_read(&mtk_dp->aux, DP_HDCP_2_2_REG_VPRIME_OFFSET,
+			       hdcp_info->hdcp2_info.hdcp_rx.recvid_list.v_prime,
+		HDCP_2_2_V_PRIME_HALF_LEN);
+	if (ret < 0)
+		return ret;
+
+	ret = drm_dp_dpcd_read(&mtk_dp->aux, DP_HDCP_2_2_REG_RECV_ID_LIST_OFFSET,
+			       hdcp_info->hdcp2_info.hdcp_rx.recvid_list.receiver_ids,
+		hdcp_info->hdcp2_info.device_count * HDCP_2_2_RECEIVER_ID_LEN);
+	if (ret < 0)
+		return ret;
+
+	return 0;
+}
+
#17 lore raw

Re: [PATCH v3 2/3] Subject: [PATCH] drm/mediatek/dp: Add HDCP2.x feature for DisplayPort

Hi, Mac:

Quoted 39 lines · CK Hu

Hi, Mac:

Quoted 12 lines · mac.shen

Changes in v3:
- refine the function to get system time
- refine the flow to do HDCP with content type and protection value which set by user space
- refine the flow to update content protection
- refine the flow to do HDCP2.x authentication per suggestion from the previous thread:
https://urldefense.com/v3/__https://patchwork.kernel.org/project/linux-mediatek__;!!CTRNKA9wMg0ARbw!md6xUiYN88D2YmETs8FQgaExM2zH8S1SmAEU9GRchwpNsXOyDFul3ziVKhRpCJaj8Rcn-gvM-801runjwA$
/patch/[email protected]/

---

[snip]

Quoted 21 lines
drivers/gpu/drm/mediatek/mtk_dp_hdcp2.c new file +21 -0
+
+static int dp_tx_hdcp2x_read_rep_send_recvid_list(struct mtk_hdcp_info *hdcp_info)
+{
+	struct mtk_dp *mtk_dp = container_of(hdcp_info, struct mtk_dp, hdcp_info);
+	u8 rx_status = 0;
+	ssize_t ret;
+
+	dev_dbg(mtk_dp->dev, "[HDCP2.X] HDCP_2_2_REP_SEND_RECVID_LIST\n");
+
+	dp_tx_hdcp2x_wait_for_cp_irq(hdcp_info, HDCP_2_2_RECVID_LIST_TIMEOUT_MS);
+	hdcp_info->hdcp2_info.cp_irq_cached = atomic_read(&hdcp_info->hdcp2_info.cp_irq);
+
+	ret = drm_dp_dpcd_read(&mtk_dp->aux, DP_HDCP_2_2_REG_RXSTATUS_OFFSET, &rx_status,
+			       HDCP_2_2_DP_RXSTATUS_LEN);
+	if (ret != HDCP_2_2_DP_RXSTATUS_LEN)
+		return ret >= 0 ? -EIO : ret;
+
+	if (!HDCP_2_2_DP_RXSTATUS_READY(rx_status)) {
+		dev_err(mtk_dp->dev, "[HDCP2.X] RX status no ready\n");
+		return -EAGAIN;
+	}
Quoted 8 lines

drivers/gpu/drm/mediatek/mtk_dp_hdcp2.c line 356

Quoted 4 lines
drivers/gpu/drm/mediatek/mtk_dp_hdcp2.c new file +4 -0
+
+	ret = drm_dp_dpcd_read(&mtk_dp->aux, DP_HDCP_2_2_REP_SEND_RECVID_LIST_OFFSET,
+			       hdcp_info->hdcp2_info.hdcp_rx.recvid_list.rx_info,
+		HDCP_2_2_RXINFO_LEN);

In [1], intel use DP_HDCP_2_2_REG_RXINFO_OFFSET to get device count. But here you use DP_HDCP_2_2_REP_SEND_RECVID_LIST_OFFSET to get device count. So both command can get device count? Or something wrong?

Forget my previous comment. In [2], intel use DP_HDCP_2_2_REP_SEND_RECVID_LIST_OFFSET to get device count.

[2] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/gpu/drm/i915/display/intel_hdcp.c?h=v6.12-rc6#n1749

Regards,
CK

Quoted 36 lines

[1] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/gpu/drm/i915/display/intel_dp_hdcp.c?h=v6.12-rc5#n497

Regards,
CK

Quoted 28 lines
drivers/gpu/drm/mediatek/mtk_dp_hdcp2.c new file +28 -0
+	if (ret < 0)
+		return ret;
+
+	hdcp_info->hdcp2_info.device_count =
+	(HDCP_2_2_DEV_COUNT_HI(hdcp_info->hdcp2_info.hdcp_rx.recvid_list.rx_info[0]) << 4 |
+	HDCP_2_2_DEV_COUNT_LO(hdcp_info->hdcp2_info.hdcp_rx.recvid_list.rx_info[1]));
+
+	ret = drm_dp_dpcd_read(&mtk_dp->aux, DP_HDCP_2_2_REG_SEQ_NUM_V_OFFSET,
+			       hdcp_info->hdcp2_info.hdcp_rx.recvid_list.seq_num_v,
+		HDCP_2_2_SEQ_NUM_LEN);
+	if (ret < 0)
+		return ret;
+
+	ret = drm_dp_dpcd_read(&mtk_dp->aux, DP_HDCP_2_2_REG_VPRIME_OFFSET,
+			       hdcp_info->hdcp2_info.hdcp_rx.recvid_list.v_prime,
+		HDCP_2_2_V_PRIME_HALF_LEN);
+	if (ret < 0)
+		return ret;
+
+	ret = drm_dp_dpcd_read(&mtk_dp->aux, DP_HDCP_2_2_REG_RECV_ID_LIST_OFFSET,
+			       hdcp_info->hdcp2_info.hdcp_rx.recvid_list.receiver_ids,
+		hdcp_info->hdcp2_info.device_count * HDCP_2_2_RECEIVER_ID_LEN);
+	if (ret < 0)
+		return ret;
+
+	return 0;
+}
+
#18 lore raw

Re: [PATCH v3 2/3] Subject: [PATCH] drm/mediatek/dp: Add HDCP2.x feature for DisplayPort

In reply to mac.shen

Hi, Mac:

Quoted 12 lines · mac.shen

Changes in v3:
- refine the function to get system time
- refine the flow to do HDCP with content type and protection value which set by user space
- refine the flow to update content protection
- refine the flow to do HDCP2.x authentication per suggestion from the previous thread:
https://urldefense.com/v3/__https://patchwork.kernel.org/project/linux-mediatek__;!!CTRNKA9wMg0ARbw!md6xUiYN88D2YmETs8FQgaExM2zH8S1SmAEU9GRchwpNsXOyDFul3ziVKhRpCJaj8Rcn-gvM-801runjwA$
/patch/[email protected]/

---

[snip]

drivers/gpu/drm/mediatek/mtk_dp_hdcp2.c line 519

Quoted 2 lines
drivers/gpu/drm/mediatek/mtk_dp_hdcp2.c new file +2 -0
+static int dp_tx_hdcp2x_write_send_ack(struct mtk_hdcp_info *hdcp_info)
+{

This function is only called by one place and this function just does one thing, so merge this function into caller function.

Regards,
CK

Quoted 14 lines
drivers/gpu/drm/mediatek/mtk_dp_hdcp2.c new file +14 -0
+	struct mtk_dp *mtk_dp = container_of(hdcp_info, struct mtk_dp, hdcp_info);
+	ssize_t ret;
+
+	dev_dbg(mtk_dp->dev, "[HDCP2.X] HDCP_2_2_SEND_ACK\n");
+
+	ret = drm_dp_dpcd_write(&mtk_dp->aux, DP_HDCP_2_2_REP_SEND_ACK_OFFSET,
+				hdcp_info->hdcp2_info.hdcp_tx.send_ack.v,
+		HDCP_2_2_V_PRIME_HALF_LEN);
+	if (ret < 0)
+		return ret;
+
+	return 0;
+}
+
author
#19 lore raw

PATCH v3 3/3 Subject: [PATCH] drm/mediatek/dp: Add HDCP1.x feature for DisplayPort

In reply to mac.shen

Changes in v3:
- remove useless code
- remove magic number
- refine the flow to do HDCP1.x authentication per suggestion from the previous thread:
https://patchwork.kernel.org/project/linux-mediatek
/patch/[email protected]/

---
 drivers/gpu/drm/mediatek/Makefile        |   1 +
 drivers/gpu/drm/mediatek/mtk_dp.c        |  11 +
 drivers/gpu/drm/mediatek/mtk_dp_hdcp1x.c | 577 +++++++++++++++++++++++
 drivers/gpu/drm/mediatek/mtk_dp_hdcp1x.h |  17 +
 drivers/gpu/drm/mediatek/mtk_dp_reg.h    |   3 +
 5 files changed, 609 insertions(+)
 create mode 100644 drivers/gpu/drm/mediatek/mtk_dp_hdcp1x.c
 create mode 100644 drivers/gpu/drm/mediatek/mtk_dp_hdcp1x.h
drivers/gpu/drm/mediatek/Makefile +1 -0
index 19b7625ae573..a90c3294bfbe 100644
@@ -28,6 +28,7 @@ mediatek-drm-hdmi-objs := mtk_cec.o \
 obj-$(CONFIG_DRM_MEDIATEK_HDMI) += mediatek-drm-hdmi.o
 
 mtk-dp-objs := tlc_dp_hdcp.o \
+		  mtk_dp_hdcp1x.o \
 		  mtk_dp_hdcp2.o \
 		  mtk_dp.o
 
drivers/gpu/drm/mediatek/mtk_dp.c +11 -0
index 12854a04622f..3925eb2be064 100644
@@ -33,6 +33,7 @@
 
 #include "mtk_dp.h"
 #include "mtk_dp_reg.h"
+#include "mtk_dp_hdcp1x.h"
 #include "mtk_dp_hdcp2.h"
 
 #define MTK_DP_SIP_CONTROL_AARCH32	MTK_SIP_SMC_CMD(0x523)
@@ -1841,6 +1842,7 @@ static int mtk_dp_hpd_sink_event(struct mtk_dp *mtk_dp)
 static void mtk_dp_hdcp_get_info(struct mtk_dp *mtk_dp)
 {
 	dp_tx_hdcp2x_get_info(&mtk_dp->hdcp_info);
+	dp_tx_hdcp1x_get_info(&mtk_dp->hdcp_info);
 }
 
 static void mtk_dp_hdcp_disable(struct mtk_dp *mtk_dp)
@@ -1852,6 +1854,8 @@ static void mtk_dp_hdcp_disable(struct mtk_dp *mtk_dp)
 
 	if (mtk_dp->hdcp_info.auth_version == HDCP_VERSION_2X)
 		dp_tx_hdcp2x_disabel(&mtk_dp->hdcp_info);
+	else if (mtk_dp->hdcp_info.auth_version == HDCP_VERSION_1X)
+		dp_tx_hdcp1x_disabel(&mtk_dp->hdcp_info);
 
 end:
 	cancel_delayed_work_sync(&mtk_dp->check_work);
@@ -1868,6 +1872,9 @@ static void mtk_dp_hdcp_check_work(struct work_struct *work)
 	if (mtk_dp->hdcp_info.auth_version == HDCP_VERSION_2X &&
 	    (!dp_tx_hdcp2x_check_link(&mtk_dp->hdcp_info))) {
 		schedule_delayed_work(&mtk_dp->check_work, DRM_HDCP2_CHECK_PERIOD_MS);
+	} else if (mtk_dp->hdcp_info.auth_version == HDCP_VERSION_1X &&
+		(!dp_tx_hdcp1x_check_link(&mtk_dp->hdcp_info))) {
+		schedule_delayed_work(&mtk_dp->check_work, DRM_HDCP_CHECK_PERIOD_MS);
 	}
 }
 
@@ -1890,6 +1897,10 @@ static void mtk_dp_hdcp_handle(struct work_struct *data)
 			check_link_interval = DRM_HDCP2_CHECK_PERIOD_MS;
 	}
 
+	if (ret && mtk_dp->hdcp_info.hdcp1x_info.capable &&
+	    mtk_dp->hdcp_info.hdcp_content_type != DRM_MODE_HDCP_CONTENT_TYPE1)
+		ret = dp_tx_hdcp1x_enable(&mtk_dp->hdcp_info);
+
 	if (!ret) {
 		schedule_delayed_work(&mtk_dp->check_work, check_link_interval);
 		mtk_dp_hdcp_update_value(mtk_dp, DRM_MODE_CONTENT_PROTECTION_ENABLED);
drivers/gpu/drm/mediatek/mtk_dp_hdcp1x.c new file +577 -0

577 lines not on this page · raw message

drivers/gpu/drm/mediatek/mtk_dp_hdcp1x.h new file +17 -0
new file mode 100644
index 000000000000..f0a19c491791
@@ -0,0 +1,17 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (c) 2019-2024 MediaTek Inc.
+ */
+
+#ifndef _MTK_DP_HDCP1X_H_
+#define _MTK_DP_HDCP1X_H_
+
+#include "tlc_dp_hdcp.h"
+
+#define HDCP_VERSION_1X 1
+
+void dp_tx_hdcp1x_get_info(struct mtk_hdcp_info *hdcp_info);
+int dp_tx_hdcp1x_enable(struct mtk_hdcp_info *hdcp_info);
+int dp_tx_hdcp1x_disabel(struct mtk_hdcp_info *hdcp_info);
+int dp_tx_hdcp1x_check_link(struct mtk_hdcp_info *hdcp_info);
+#endif /* _MTK_DP_HDCP1X_H_ */
drivers/gpu/drm/mediatek/mtk_dp_reg.h +3 -0
index 8c60983a26ed..c04ea5dda6bd 100644
@@ -277,6 +277,9 @@
 #define MTK_DP_TRANS_P0_3430				0x3430
 #define HPD_INT_THD_ECO_DP_TRANS_P0_MASK			GENMASK(1, 0)
 #define HPD_INT_THD_ECO_DP_TRANS_P0_HIGH_BOUND_EXT		BIT(1)
+#define MTK_DP_TRANS_P0_3480                0x3480
+#define REQ_BLOCK_CIPHER_AUTH                           BIT(12)
+#define KM_GENERATED                                    BIT(4)
 #define MTK_DP_TRANS_P0_34A4				0x34a4
 #define HDCP22_AUTH_DONE_DP_TRANS_P0_MASK		BIT(4)
 #define R0_AVAILABLE_DP_TRANS_P0		BIT(12)
Signature · 1 line
2.43.0
#20 lore raw

Re: [PATCH v3 3/3] Subject: [PATCH] drm/mediatek/dp: Add HDCP1.x feature for DisplayPort

Quoted 7 lines · mac.shen

Changes in v3:
- remove useless code
- remove magic number
- refine the flow to do HDCP1.x authentication per suggestion from the previous thread:
https://urldefense.com/v3/__https://patchwork.kernel.org/project/linux-mediatek__;!!CTRNKA9wMg0ARbw!l3mVePuKN038rd5XoCuION0zP40BtWBb7148hHsXs7hCWDTRgESIkfNHuEtPQ1Rb4P9MOpJZstgE4j2LJg$
/patch/[email protected]/

Move the version change information after '---'.

In here, describe HDCP1.x.
Does MediaTek DP has some limitation? If so, describe it.

I would like to HDCP1.x patch in front of HDCP2.x because the spec development is from 1.x to 2.x. So move this patch before HDCP2.x patch.

Regards,
CK

Quoted 3 lines

---