From aead036da110062df01a7a4f92592e95f3970a18 Mon Sep 17 00:00:00 2001 From: Ahung Cheng Date: Fri, 26 Nov 2021 19:17:13 +0800 Subject: tegra: hdcp: update policy init value Update hdcp policy init value based on availability of HDCP TA for L4T Bug 3167119 Change-Id: I81e4f02b20214fb23c94756804448fa0ae80246b Signed-off-by: Ahung Cheng Reviewed-on: https://git-master.nvidia.com/r/c/linux-nvidia/+/2632879 Reviewed-by: Ilhan Gurel Reviewed-by: Bibek Basu Reviewed-by: mobile promotions Tested-by: mobile promotions GVS: Gerrit_Virtual_Submit --- drivers/video/tegra/dc/hdcp/dphdcp.c | 22 +++++- drivers/video/tegra/dc/hdcp/dphdcp.h | 3 +- drivers/video/tegra/dc/hdcp/hdmihdcp.c | 137 ++++++++++++++++----------------- drivers/video/tegra/dc/hdcp/hdmihdcp.h | 3 +- 4 files changed, 92 insertions(+), 73 deletions(-) diff --git a/drivers/video/tegra/dc/hdcp/dphdcp.c b/drivers/video/tegra/dc/hdcp/dphdcp.c index 260a20018..b81e6b162 100644 --- a/drivers/video/tegra/dc/hdcp/dphdcp.c +++ b/drivers/video/tegra/dc/hdcp/dphdcp.c @@ -1,7 +1,7 @@ /* * dphdcp.c: dp hdcp driver. * - * Copyright (c) 2015-2020, NVIDIA CORPORATION, All rights reserved. + * Copyright (c) 2015-2021, NVIDIA CORPORATION, All rights reserved. * * This software is licensed under the terms of the GNU General Public * License version 2, as published by the Free Software Foundation, and @@ -2196,7 +2196,27 @@ static int dphdcp_dev_open(struct inode *inode, struct file *filp) struct miscdevice *miscdev = filp->private_data; struct tegra_dphdcp *dphdcp = container_of(miscdev, struct tegra_dphdcp, miscdev); +#ifndef CONFIG_ANDROID + int err = 0; +#endif filp->private_data = dphdcp; + +/* enable policy only if HDCP TA is ready */ +#ifndef CONFIG_ANDROID + if (!dphdcp->policy_initialized) { + dphdcp->policy_initialized = true; + + err = te_open_trusted_session(HDCP_PORT_NAME, &dphdcp->ta_ctx); + if (!err) + tegra_dphdcp_set_policy(dphdcp, + TEGRA_DC_HDCP_POLICY_ALWAYS_ON); + + if (dphdcp->ta_ctx) { + te_close_trusted_session(dphdcp->ta_ctx); + dphdcp->ta_ctx = NULL; + } + } +#endif return 0; } diff --git a/drivers/video/tegra/dc/hdcp/dphdcp.h b/drivers/video/tegra/dc/hdcp/dphdcp.h index 21ad10d3e..0293cfb73 100644 --- a/drivers/video/tegra/dc/hdcp/dphdcp.h +++ b/drivers/video/tegra/dc/hdcp/dphdcp.h @@ -1,7 +1,7 @@ /* * dphdcp.h: dp hdcp driver. * - * Copyright (c) 2015-2019, NVIDIA CORPORATION, All rights reserved. + * Copyright (c) 2015-2021, NVIDIA CORPORATION, All rights reserved. * * This software is licensed under the terms of the GNU General Public * License version 2, as published by the Free Software Foundation, and @@ -75,6 +75,7 @@ struct tegra_dphdcp { u8 hpd; u8 repeater; void *ta_ctx; + bool policy_initialized; }; #ifdef CONFIG_DPHDCP diff --git a/drivers/video/tegra/dc/hdcp/hdmihdcp.c b/drivers/video/tegra/dc/hdcp/hdmihdcp.c index 89dd5ef5a..97398e8bc 100644 --- a/drivers/video/tegra/dc/hdcp/hdmihdcp.c +++ b/drivers/video/tegra/dc/hdcp/hdmihdcp.c @@ -847,7 +847,6 @@ static int get_srm_signature(struct hdcp_context_t *hdcp_context, #else err = te_launch_trusted_oper(pkt, PKT_SIZE, HDCP_CMD_GEN_CMAC, ta_ctx); #endif - if (err) nvhdcp_err("te launch operation failed with error %d\n", err); return err; @@ -1037,6 +1036,51 @@ static int get_repeater_info(struct tegra_nvhdcp *nvhdcp) return 0; } +static int nvhdcp_te_open(struct tegra_nvhdcp *nvhdcp) +{ + int err = 0; + +#ifdef CONFIG_TRUSTED_LITTLE_KERNEL + /* differentiate between TLK and trusty */ + if (te_is_secos_dev_enabled()) { + err = te_open_trusted_session_tlk(hdcp_uuid, sizeof(hdcp_uuid), + &session_id); + } else { + nvhdcp->ta_ctx = NULL; + /* Open a trusted sesion with HDCP TA */ + err = te_open_trusted_session(HDCP_PORT_NAME, &nvhdcp->ta_ctx); + } +#else + nvhdcp->ta_ctx = NULL; + /* Open a trusted sesion with HDCP TA */ + err = te_open_trusted_session(HDCP_PORT_NAME, &nvhdcp->ta_ctx); +#endif + return err; +} + +static void nvhdcp_te_close(struct tegra_nvhdcp *nvhdcp) +{ +#ifdef CONFIG_TRUSTED_LITTLE_KERNEL + if (te_is_secos_dev_enabled()) { + if (session_id) { + te_close_trusted_session_tlk(session_id, hdcp_uuid, + sizeof(hdcp_uuid)); + session_id = 0; + } + } else { + if (nvhdcp->ta_ctx) { + te_close_trusted_session(nvhdcp->ta_ctx); + nvhdcp->ta_ctx = NULL; + } + } +#else + if (nvhdcp->ta_ctx) { + te_close_trusted_session(nvhdcp->ta_ctx); + nvhdcp->ta_ctx = NULL; + } +#endif +} + static int nvhdcp_ake_init_send(struct tegra_nvhdcp *nvhdcp, u8 *buf) { int e; @@ -1286,22 +1330,7 @@ static int tsec_hdcp_authentication(struct tegra_nvhdcp *nvhdcp, if (err) goto exit; -#ifdef CONFIG_TRUSTED_LITTLE_KERNEL - /* differentiate between TLK and trusty */ - if (te_is_secos_dev_enabled()) { - err = te_open_trusted_session_tlk(hdcp_uuid, sizeof(hdcp_uuid), - &session_id); - } else { - nvhdcp->ta_ctx = NULL; - /* Open a trusted sesion with HDCP TA */ - err = te_open_trusted_session(HDCP_PORT_NAME, &nvhdcp->ta_ctx); - } -#else - nvhdcp->ta_ctx = NULL; - /* Open a trusted sesion with HDCP TA */ - err = te_open_trusted_session(HDCP_PORT_NAME, &nvhdcp->ta_ctx); -#endif - + err = nvhdcp_te_open(nvhdcp); if (err) { nvhdcp_err("Error opening trusted session\n"); goto exit; @@ -1476,27 +1505,7 @@ exit: if (err) nvhdcp_err("HDCP authentication failed with err %d\n", err); kfree(pkt); - -#ifdef CONFIG_TRUSTED_LITTLE_KERNEL - if (te_is_secos_dev_enabled()) { - if (session_id) { - te_close_trusted_session_tlk(session_id, hdcp_uuid, - sizeof(hdcp_uuid)); - session_id = 0; - } - } else { - if (nvhdcp->ta_ctx) { - te_close_trusted_session(nvhdcp->ta_ctx); - nvhdcp->ta_ctx = NULL; - } - } -#else - if (nvhdcp->ta_ctx) { - te_close_trusted_session(nvhdcp->ta_ctx); - nvhdcp->ta_ctx = NULL; - } -#endif - + nvhdcp_te_close(nvhdcp); return err; } @@ -1594,11 +1603,7 @@ static void nvhdcp1_downstream_worker(struct work_struct *work) nvhdcp_vdbg("read Bcaps = 0x%02x\n", b_caps); nvhdcp->ta_ctx = NULL; - e = te_open_trusted_session(HDCP_PORT_NAME, &nvhdcp->ta_ctx); - if (e) { - nvhdcp_err("Error opening trusted session\n"); - goto failure; - } + e = nvhdcp_te_open(nvhdcp); if (tegra_dc_is_nvdisplay()) { /* if session successfully opened, launch operations @@ -1929,19 +1934,13 @@ lost_hdmi: err: mutex_unlock(&nvhdcp->lock); kfree(pkt); - if (nvhdcp->ta_ctx) { - te_close_trusted_session(nvhdcp->ta_ctx); - nvhdcp->ta_ctx = NULL; - } + nvhdcp_te_close(nvhdcp); tegra_dc_io_end(dc); return; disable: nvhdcp->state = STATE_OFF; kfree(pkt); - if (nvhdcp->ta_ctx) { - te_close_trusted_session(nvhdcp->ta_ctx); - nvhdcp->ta_ctx = NULL; - } + nvhdcp_te_close(nvhdcp); nvhdcp_set_plugged(nvhdcp, false); mutex_unlock(&nvhdcp->lock); tegra_dc_io_end(dc); @@ -1986,21 +1985,7 @@ static int link_integrity_check(struct tegra_nvhdcp *nvhdcp, msecs_to_jiffies(10)); goto exit; } -#ifdef CONFIG_TRUSTED_LITTLE_KERNEL - /* differentiate between TLK and trusty */ - if (te_is_secos_dev_enabled()) { - err = te_open_trusted_session_tlk(hdcp_uuid, sizeof(hdcp_uuid), - &session_id); - } else { - nvhdcp->ta_ctx = NULL; - /* Open a trusted sesion with HDCP TA */ - err = te_open_trusted_session(HDCP_PORT_NAME, &nvhdcp->ta_ctx); - } -#else - nvhdcp->ta_ctx = NULL; - /* Open a trusted sesion with HDCP TA */ - err = te_open_trusted_session(HDCP_PORT_NAME, &nvhdcp->ta_ctx); -#endif + err = nvhdcp_te_open(nvhdcp); if (err) { nvhdcp_err("Error opening trusted session\n"); goto exit; @@ -2026,10 +2011,7 @@ static int link_integrity_check(struct tegra_nvhdcp *nvhdcp, err = (rx_status & HDCP_RX_STATUS_MSG_REAUTH_REQ); exit: kfree(pkt); - if (nvhdcp->ta_ctx) { - te_close_trusted_session(nvhdcp->ta_ctx); - nvhdcp->ta_ctx = NULL; - } + nvhdcp_te_close(nvhdcp); return err; } @@ -2423,7 +2405,22 @@ static int nvhdcp_dev_open(struct inode *inode, struct file *filp) struct miscdevice *miscdev = filp->private_data; struct tegra_nvhdcp *nvhdcp = container_of(miscdev, struct tegra_nvhdcp, miscdev); +#ifndef CONFIG_ANDROID + int err = 0; +#endif filp->private_data = nvhdcp; + +/* enable policy only if HDCP TA is ready */ +#ifndef CONFIG_ANDROID + if (!nvhdcp->policy_initialized) { + nvhdcp->policy_initialized = true; + err = nvhdcp_te_open(nvhdcp); + if (!err) + tegra_nvhdcp_set_policy(nvhdcp, + TEGRA_DC_HDCP_POLICY_ALWAYS_ON); + nvhdcp_te_close(nvhdcp); + } +#endif return 0; } diff --git a/drivers/video/tegra/dc/hdcp/hdmihdcp.h b/drivers/video/tegra/dc/hdcp/hdmihdcp.h index e8320afea..01d85a7cc 100644 --- a/drivers/video/tegra/dc/hdcp/hdmihdcp.h +++ b/drivers/video/tegra/dc/hdcp/hdmihdcp.h @@ -1,7 +1,7 @@ /* * hdmihdcp.h: hdmi hdcp interface. * - * Copyright (c) 2015-2019, NVIDIA CORPORATION, All rights reserved. + * Copyright (c) 2015-2021, NVIDIA CORPORATION, All rights reserved. * * This software is licensed under the terms of the GNU General Public * License version 2, as published by the Free Software Foundation, and @@ -78,6 +78,7 @@ struct tegra_nvhdcp { struct workqueue_struct *fallback_wq; struct delayed_work fallback_work; void *ta_ctx; + bool policy_initialized; }; #ifdef CONFIG_HDCP -- cgit v1.2.2