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

CK Hu (胡俊光)
2024-02-22T07:44:02Z

Hi, Mac:

On Mon, 2024-02-05 at 13:50 +0800, mac.shen wrote:
> Add HDCP2.x feature for DisplayPort.
> When userspace request the kernel protect future content communicated
> over the link with Content_Protection property, the feature will do
> HDCP2.x authentication if the sink support HDCP2.X.
>
> Changes in v2:
> - remove switch case, and refine code to make more clear
> - remove some definitions, and use the definitions in
> include/drm/drm_hdcp.h
> - use the struct which defined in include/drm/drm_hdcp.h
> - do HDCP2.x authentication when userspace request the
> kernel protect future content communicated
> per suggestion from the previous thread:
> https://lore.kernel.org/all/8fff59b5567449d8201dd1138c8fa
> 9218a545c46.camel@mediatek.com/
>
> Signed-off-by: mac.shen <mac.shen@mediatek.com>
> ---

[snip]

> +
> +static bool dp_tx_hdcp2_write_msg(struct mtk_hdcp_info *hdcp_info,
> u8 cmd_ID)
> +{
> + struct mtk_dp *mtk_dp = container_of(hdcp_info, struct mtk_dp,
> hdcp_info);
> + bool ret = false;
> +

It seems no common part for each case, so I would like to separate each
case to an independent function.

Regards,
CK

> + switch (cmd_ID) {
> + case HDCP_2_2_AKE_INIT:
> + tee_hdcp2_soft_rst(hdcp_info);
> + drm_dp_dpcd_write(&mtk_dp->aux,
> DP_HDCP_2_2_REG_RTX_OFFSET,
> + hdcp_info-
> >hdcp2_info.hdcp_tx.ake_init.r_tx, HDCP_2_2_RTX_LEN);
> + drm_dp_dpcd_write(&mtk_dp->aux,
> DP_HDCP_2_2_REG_TXCAPS_OFFSET,
> + (void *)&hdcp_info-
> >hdcp2_info.hdcp_tx.tx_caps,
> + HDCP_2_2_TXCAPS_LEN);
> +
> + ret = true;
> + DPTXHDCPMSG("2.x: HDCP_2_2_AKE_Init !\n");
> + break;
> +
> + case HDCP_2_2_AKE_NO_STORED_KM:
> + drm_dp_dpcd_write(&mtk_dp->aux,
> DP_HDCP_2_2_REG_EKPUB_KM_OFFSET,
> + hdcp_info-
> >hdcp2_info.hdcp_tx.no_stored_km.e_kpub_km,
> + HDCP_2_2_E_KPUB_KM_LEN);
> +
> + ret = true;
> +
> + DPTXHDCPMSG("2.x: HDCP_2_2_AKE_NO_STORED_KM !\n");
> + break;
> +
> + case HDCP_2_2_AKE_STORED_KM:
> + drm_dp_dpcd_write(&mtk_dp->aux,
> DP_HDCP_2_2_REG_EKH_KM_WR_OFFSET,
> + hdcp_info-
> >hdcp2_info.ake_stored_km.e_kh_km_m,
> + HDCP_2_2_E_KH_KM_LEN);
> + 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);
> +
> + ret = true;
> +
> + DPTXHDCPMSG("2.x: DPTX_HDCP_2_2_AKE_STORED_KM !\n");
> + break;
> +
> + case HDCP_2_2_LC_INIT:
> + drm_dp_dpcd_write(&mtk_dp->aux,
> DP_HDCP_2_2_REG_RN_OFFSET,
> + hdcp_info-
> >hdcp2_info.hdcp_tx.lc_init.r_n, HDCP_2_2_RN_LEN);
> +
> + hdcp_info->hdcp2_info.read_l_prime = true;
> + ret = true;
> +
> + DPTXHDCPMSG("2.x: HDCP_2_2_LC_INIT !\n");
> + break;
> +
> + case HDCP_2_2_SKE_SEND_EKS:
> + drm_dp_dpcd_write(&mtk_dp->aux,
> DP_HDCP_2_2_REG_EDKEY_KS_OFFSET,
> + hdcp_info-
> >hdcp2_info.hdcp_tx.send_eks.e_dkey_ks,
> + HDCP_2_2_E_DKEY_KS_LEN);
> + 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);
> +
> + hdcp_info->hdcp2_info.ks_exchange_done = true;
> +
> + ret = true;
> + DPTXHDCPMSG("2.x: HDCP_2_2_SKE_SEND_EKS !\n");
> + break;
> +
> + case HDCP_2_2_STREAM_TYPE:
> + drm_dp_dpcd_write(&mtk_dp->aux,
> DP_HDCP_2_2_REG_STREAM_TYPE_OFFSET,
> + hdcp_info-
> >hdcp2_info.hdcp_tx.stream_id_type, 1);
> +
> + ret = true;
> + DPTXHDCPMSG("HDCP2_MSG_DP_STREAM_TYPE !\n");
> + break;
> +
> + case HDCP_2_2_REP_SEND_ACK:
> + drm_dp_dpcd_write(&mtk_dp->aux,
> DP_HDCP_2_2_REG_V_OFFSET,
> + hdcp_info-
> >hdcp2_info.hdcp_tx.send_ack.v,
> + HDCP_2_2_V_PRIME_HALF_LEN);
> +
> + ret = true;
> + DPTXHDCPMSG("2.x: HDCP_2_2_SEND_ACK !\n");
> + break;
> +
> + case HDCP_2_2_REP_STREAM_MANAGE:
> + drm_dp_dpcd_write(&mtk_dp->aux,
> DP_HDCP_2_2_REG_SEQ_NUM_M_OFFSET,
> + hdcp_info-
> >hdcp2_info.hdcp_tx.stream_manage.seq_num_m,
> + HDCP_2_2_SEQ_NUM_LEN);
> + drm_dp_dpcd_write(&mtk_dp->aux,
> DP_HDCP_2_2_REG_K_OFFSET,
> + hdcp_info->hdcp2_info.hdcp_tx.k,
> HDCP2_K_LEN);
> + drm_dp_dpcd_write(&mtk_dp->aux,
> DP_HDCP_2_2_REG_STREAM_ID_TYPE_OFFSET,
> + hdcp_info-
> >hdcp2_info.hdcp_tx.stream_id_type,
> + HDCP2_STREAMID_TYPE_LEN);
> +
> + dp_tx_hdcp2_fill_stream_type(hdcp_info, hdcp_info-
> >hdcp2_info.stream_id_type);
> +
> + ret = true;
> + DPTXHDCPMSG("2.x: HDCP_2_2_STREAM_MANAGE !\n");
> + break;
> +
> + default:
> + DPTXHDCPMSG("2.x: Invalid HDCP2_OffSETADDR_WriteMessage
> !\n");
> + break;
> + }
> +
> + return ret;
> +}