HDCP: export nvhdcp state using ioctl
James Zhao [Fri, 4 Jan 2013 01:02:01 +0000 (17:02 -0800)]
Export nvhdcp state to user land to check hdcp
link is verified before doing anything else.

Reviewed-on: http://git-master/r/188466
(cherry picked from commit 4305e7007e73e361fc351d94eb76ce52ff074ed5)

Change-Id: I2d40ce69d0726e6d7817462519a47e68a800c21d
Signed-off-by: James Zhao <jamesz@nvidia.com>
Reviewed-on: http://git-master/r/200908
Reviewed-by: Jon Mayo <jmayo@nvidia.com>

drivers/video/tegra/dc/nvhdcp.c
include/video/nvhdcp.h

index 10c451d..261d1a8 100644 (file)
@@ -470,6 +470,20 @@ static int verify_ksv(u64 k)
        return  (i != 20) ? -EINVAL : 0;
 }
 
+static int get_nvhdcp_state(struct tegra_nvhdcp *nvhdcp,
+                       struct tegra_nvhdcp_packet *pkt)
+{
+       mutex_lock(&nvhdcp->lock);
+       if (nvhdcp->state != STATE_LINK_VERIFY) {
+               memset(pkt, 0, sizeof *pkt);
+               pkt->packet_results = TEGRA_NVHDCP_RESULT_LINK_FAILED;
+       } else {
+               pkt->packet_results = TEGRA_NVHDCP_RESULT_SUCCESS;
+       }
+       mutex_unlock(&nvhdcp->lock);
+       return 0;
+}
+
 /* get Status and Kprime signature - READ_S on TMDS0_LINK0 only */
 static int get_s_prime(struct tegra_nvhdcp *nvhdcp, struct tegra_nvhdcp_packet *pkt)
 {
@@ -1158,6 +1172,18 @@ static long nvhdcp_dev_ioctl(struct file *filp,
        case TEGRAIO_NVHDCP_RENEGOTIATE:
                e = tegra_nvhdcp_renegotiate(nvhdcp);
                break;
+
+       case TEGRAIO_NVHDCP_HDCP_STATE:
+               pkt = kmalloc(sizeof(*pkt), GFP_KERNEL);
+               if (!pkt)
+                       return -ENOMEM;
+               e = get_nvhdcp_state(nvhdcp, pkt);
+               if (copy_to_user((void __user *)arg, pkt, sizeof(*pkt))) {
+                       e = -EFAULT;
+                       goto kfree_pkt;
+               }
+               kfree(pkt);
+               return e;
        }
 
        return e;
index f282ff8..cf27ee5 100644 (file)
@@ -87,5 +87,6 @@ struct tegra_nvhdcp_packet {
 #define TEGRAIO_NVHDCP_READ_M          _IOWR('F', 0x73, struct tegra_nvhdcp_packet)
 #define TEGRAIO_NVHDCP_READ_S          _IOWR('F', 0x74, struct tegra_nvhdcp_packet)
 #define TEGRAIO_NVHDCP_RENEGOTIATE     _IO('F', 0x75)
+#define TEGRAIO_NVHDCP_HDCP_STATE      _IOR('F', 0x76, struct tegra_nvhdcp_packet)
 
 #endif