blob: eab93cc82c911d0e0148ddb030a1e28fe4b54ddf [file] [log] [blame]
Tatenda Chipeperekwa65935362017-06-07 13:44:11 -07001/* Copyright (c) 2015-2017, The Linux Foundation. All rights reserved.
2 *
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License version 2 and
5 * only version 2 as published by the Free Software Foundation.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 */
12
13#define pr_fmt(fmt) "[hdcp-lib] %s: " fmt, __func__
14
15#include <linux/platform_device.h>
16#include <linux/kernel.h>
17#include <linux/slab.h>
18#include <linux/module.h>
19#include <linux/fs.h>
20#include <linux/file.h>
21#include <linux/uaccess.h>
22#include <linux/cdev.h>
23#include <linux/sched.h>
24#include <linux/list.h>
25#include <linux/mutex.h>
26#include <linux/io.h>
27#include <linux/ion.h>
28#include <linux/types.h>
29#include <linux/device.h>
30#include <linux/sched.h>
31#include <linux/delay.h>
32#include <linux/completion.h>
33#include <linux/errno.h>
34#include <linux/hdcp_qseecom.h>
35#include <linux/kthread.h>
36#include <linux/of.h>
37#include <video/msm_hdmi_hdcp_mgr.h>
38
39#include "qseecom_kernel.h"
40
41#define CLASS_NAME "hdcp"
42#define DRIVER_NAME "msm_hdcp"
43#define TZAPP_NAME "hdcp2p2"
44#define HDCP1_APP_NAME "hdcp1"
45#define QSEECOM_SBUFF_SIZE 0x1000
46
47#define MAX_TX_MESSAGE_SIZE 129
48#define MAX_RX_MESSAGE_SIZE 534
49#define MAX_TOPOLOGY_ELEMS 32
50#define HDCP1_AKSV_SIZE 8
51
52/* parameters related to LC_Init message */
53#define MESSAGE_ID_SIZE 1
54#define LC_INIT_MESSAGE_SIZE (MESSAGE_ID_SIZE+BITS_64_IN_BYTES)
55
56/* parameters related to SKE_Send_EKS message */
57#define SKE_SEND_EKS_MESSAGE_SIZE \
58 (MESSAGE_ID_SIZE+BITS_128_IN_BYTES+BITS_64_IN_BYTES)
59
60/* all message IDs */
61#define INVALID_MESSAGE_ID 0
62#define AKE_INIT_MESSAGE_ID 2
63#define AKE_SEND_CERT_MESSAGE_ID 3
64#define AKE_NO_STORED_KM_MESSAGE_ID 4
65#define AKE_STORED_KM_MESSAGE_ID 5
66#define AKE_SEND_H_PRIME_MESSAGE_ID 7
67#define AKE_SEND_PAIRING_INFO_MESSAGE_ID 8
68#define LC_INIT_MESSAGE_ID 9
69#define LC_SEND_L_PRIME_MESSAGE_ID 10
70#define SKE_SEND_EKS_MESSAGE_ID 11
71#define REPEATER_AUTH_SEND_RECEIVERID_LIST_MESSAGE_ID 12
72#define REPEATER_AUTH_SEND_ACK_MESSAGE_ID 15
73#define REPEATER_AUTH_STREAM_MANAGE_MESSAGE_ID 16
74#define REPEATER_AUTH_STREAM_READY_MESSAGE_ID 17
75#define SKE_SEND_TYPE_ID 18
76#define HDCP2P2_MAX_MESSAGES 19
77
78#define HDCP1_SET_KEY_MESSAGE_ID 202
79#define HDCP1_SET_ENC_MESSAGE_ID 205
80
81#define BITS_40_IN_BYTES 5
82#define BITS_64_IN_BYTES 8
83#define BITS_128_IN_BYTES 16
84#define RXCAPS_SIZE 3
85#define RXINFO_SIZE 2
86#define SEQ_NUM_V_SIZE 3
87
88#define RCVR_ID_SIZE BITS_40_IN_BYTES
89#define MAX_RCVR_IDS_ALLOWED_IN_LIST 31
90#define MAX_RCVR_ID_LIST_SIZE \
91 (RCVR_ID_SIZE * MAX_RCVR_IDS_ALLOWED_IN_LIST)
92/*
93 * Minimum wait as per standard is 200 ms. Keep it 220 ms
94 * to be on safe side.
95 */
96#define SLEEP_SET_HW_KEY_MS 220
97
98/* hdcp command status */
99#define HDCP_SUCCESS 0
100
101/* flags set by tz in response message */
102#define HDCP_TXMTR_SUBSTATE_WAITING_FOR_RECIEVERID_LIST 1
103
104#define HDCP_TXMTR_SERVICE_ID 0x0001000
105#define SERVICE_CREATE_CMD(x) (HDCP_TXMTR_SERVICE_ID | x)
106
107#define HDCP_TXMTR_INIT SERVICE_CREATE_CMD(1)
108#define HDCP_TXMTR_DEINIT SERVICE_CREATE_CMD(2)
109#define HDCP_TXMTR_PROCESS_RECEIVED_MESSAGE SERVICE_CREATE_CMD(3)
110#define HDCP_TXMTR_SEND_MESSAGE_TIMEOUT SERVICE_CREATE_CMD(4)
111#define HDCP_TXMTR_SET_HW_KEY SERVICE_CREATE_CMD(5)
112#define HDCP_TXMTR_QUERY_STREAM_TYPE SERVICE_CREATE_CMD(6)
113#define HDCP_LIB_INIT SERVICE_CREATE_CMD(11)
114#define HDCP_LIB_DEINIT SERVICE_CREATE_CMD(12)
115#define HDCP_TXMTR_GET_VERSION SERVICE_CREATE_CMD(14)
116#define HDCP_TXMTR_VERIFY_KEY SERVICE_CREATE_CMD(15)
117#define HDCP_SESSION_INIT SERVICE_CREATE_CMD(16)
118#define HDCP_SESSION_DEINIT SERVICE_CREATE_CMD(17)
119#define HDCP_TXMTR_START_AUTHENTICATE SERVICE_CREATE_CMD(18)
120
121#define HCDP_TXMTR_GET_MAJOR_VERSION(v) (((v) >> 16) & 0xFF)
122#define HCDP_TXMTR_GET_MINOR_VERSION(v) (((v) >> 8) & 0xFF)
123#define HCDP_TXMTR_GET_PATCH_VERSION(v) ((v) & 0xFF)
124
125#define HDCP_CLIENT_MAJOR_VERSION 2
126#define HDCP_CLIENT_MINOR_VERSION 1
127#define HDCP_CLIENT_PATCH_VERSION 0
128#define HDCP_CLIENT_MAKE_VERSION(maj, min, patch) \
129 ((((maj) & 0xFF) << 16) | (((min) & 0xFF) << 8) | ((patch) & 0xFF))
130
131#define REAUTH_REQ BIT(3)
132#define LINK_INTEGRITY_FAILURE BIT(4)
133
134#define HDCP_LIB_EXECUTE(x) {\
135 kthread_queue_work(&handle->worker, &handle->wk_##x);\
136}
137
138static const struct hdcp_msg_data hdcp_msg_lookup[HDCP2P2_MAX_MESSAGES] = {
139 [AKE_INIT_MESSAGE_ID] = { 2,
140 { {"rtx", 0x69000, 8}, {"TxCaps", 0x69008, 3} },
141 0 },
142 [AKE_SEND_CERT_MESSAGE_ID] = { 3,
143 { {"cert-rx", 0x6900B, 522}, {"rrx", 0x69215, 8},
144 {"RxCaps", 0x6921D, 3} },
145 0 },
146 [AKE_NO_STORED_KM_MESSAGE_ID] = { 1,
147 { {"Ekpub_km", 0x69220, 128} },
148 0 },
149 [AKE_STORED_KM_MESSAGE_ID] = { 2,
150 { {"Ekh_km", 0x692A0, 16}, {"m", 0x692B0, 16} },
151 0 },
152 [AKE_SEND_H_PRIME_MESSAGE_ID] = { 1,
153 { {"H'", 0x692C0, 32} },
154 (1 << 1) },
155 [AKE_SEND_PAIRING_INFO_MESSAGE_ID] = { 1,
156 { {"Ekh_km", 0x692E0, 16} },
157 (1 << 2) },
158 [LC_INIT_MESSAGE_ID] = { 1,
159 { {"rn", 0x692F0, 8} },
160 0 },
161 [LC_SEND_L_PRIME_MESSAGE_ID] = { 1,
162 { {"L'", 0x692F8, 32} },
163 0 },
164 [SKE_SEND_EKS_MESSAGE_ID] = { 2,
165 { {"Edkey_ks", 0x69318, 16}, {"riv", 0x69328, 8} },
166 0 },
167 [SKE_SEND_TYPE_ID] = { 1,
168 { {"type", 0x69494, 1} },
169 0 },
170 [REPEATER_AUTH_SEND_RECEIVERID_LIST_MESSAGE_ID] = { 4,
171 { {"RxInfo", 0x69330, 2}, {"seq_num_V", 0x69332, 3},
172 {"V'", 0x69335, 16}, {"ridlist", 0x69345, 155} },
173 (1 << 0) },
174 [REPEATER_AUTH_SEND_ACK_MESSAGE_ID] = { 1,
175 { {"V", 0x693E0, 16} },
176 0 },
177 [REPEATER_AUTH_STREAM_MANAGE_MESSAGE_ID] = { 3,
178 { {"seq_num_M", 0x693F0, 3}, {"k", 0x693F3, 2},
179 {"streamID_Type", 0x693F5, 126} },
180 0 },
181 [REPEATER_AUTH_STREAM_READY_MESSAGE_ID] = { 1,
182 { {"M'", 0x69473, 32} },
183 0 }
184};
185
186enum hdcp_state {
187 HDCP_STATE_INIT = 0x00,
188 HDCP_STATE_APP_LOADED = 0x01,
189 HDCP_STATE_SESSION_INIT = 0x02,
190 HDCP_STATE_TXMTR_INIT = 0x04,
191 HDCP_STATE_AUTHENTICATED = 0x08,
192 HDCP_STATE_ERROR = 0x10
193};
194
195enum hdcp_element {
196 HDCP_TYPE_UNKNOWN,
197 HDCP_TYPE_RECEIVER,
198 HDCP_TYPE_REPEATER,
199};
200
201enum hdcp_version {
202 HDCP_VERSION_UNKNOWN,
203 HDCP_VERSION_2_2,
204 HDCP_VERSION_1_4
205};
206
207struct receiver_info {
208 unsigned char rcvrInfo[RCVR_ID_SIZE];
209 enum hdcp_element elem_type;
210 enum hdcp_version hdcp_version;
211};
212
213struct topology_info {
214 unsigned int nNumRcvrs;
215 struct receiver_info rcvinfo[MAX_TOPOLOGY_ELEMS];
216};
217
218struct __attribute__ ((__packed__)) hdcp1_key_set_req {
219 uint32_t commandid;
220};
221
222struct __attribute__ ((__packed__)) hdcp1_key_set_rsp {
223 uint32_t commandid;
224 uint32_t ret;
225 uint8_t ksv[HDCP1_AKSV_SIZE];
226};
227
228struct __attribute__ ((__packed__)) hdcp_version_req {
229 uint32_t commandid;
230};
231
232struct __attribute__ ((__packed__)) hdcp_version_rsp {
233 uint32_t commandid;
234 uint32_t commandId;
235 uint32_t appversion;
236};
237
238struct __attribute__ ((__packed__)) hdcp_verify_key_req {
239 uint32_t commandid;
240};
241
242struct __attribute__ ((__packed__)) hdcp_verify_key_rsp {
243 uint32_t status;
244 uint32_t commandId;
245};
246
247struct __attribute__ ((__packed__)) hdcp_lib_init_req_v1 {
248 uint32_t commandid;
249};
250
251struct __attribute__ ((__packed__)) hdcp_lib_init_rsp_v1 {
252 uint32_t status;
253 uint32_t commandid;
254 uint32_t ctxhandle;
255 uint32_t timeout;
256 uint32_t msglen;
257 uint8_t message[MAX_TX_MESSAGE_SIZE];
258};
259
260struct __attribute__ ((__packed__)) hdcp_lib_init_req {
261 uint32_t commandid;
262 uint32_t clientversion;
263};
264
265struct __attribute__ ((__packed__)) hdcp_lib_init_rsp {
266 uint32_t status;
267 uint32_t commandid;
268 uint32_t appversion;
269};
270
271struct __attribute__ ((__packed__)) hdcp_lib_deinit_req {
272 uint32_t commandid;
273};
274
275struct __attribute__ ((__packed__)) hdcp_lib_deinit_rsp {
276 uint32_t status;
277 uint32_t commandid;
278};
279
280struct __attribute__ ((__packed__)) hdcp_lib_session_init_req {
281 uint32_t commandid;
282 uint32_t deviceid;
283};
284
285struct __attribute__ ((__packed__)) hdcp_lib_session_init_rsp {
286 uint32_t status;
287 uint32_t commandid;
288 uint32_t sessionid;
289};
290
291struct __attribute__ ((__packed__)) hdcp_lib_session_deinit_req {
292 uint32_t commandid;
293 uint32_t sessionid;
294};
295
296struct __attribute__ ((__packed__)) hdcp_lib_session_deinit_rsp {
297 uint32_t status;
298 uint32_t commandid;
299};
300
301struct __attribute__ ((__packed__)) hdcp_tx_init_req_v1 {
302 uint32_t commandid;
303};
304
305struct __attribute__ ((__packed__)) hdcp_tx_init_rsp_v1 {
306 uint32_t status;
307 uint32_t commandid;
308 uint32_t ctxhandle;
309 uint32_t timeout;
310 uint32_t msglen;
311 uint8_t message[MAX_TX_MESSAGE_SIZE];
312};
313
314struct __attribute__ ((__packed__)) hdcp_tx_init_req {
315 uint32_t commandid;
316 uint32_t sessionid;
317};
318
319struct __attribute__ ((__packed__)) hdcp_tx_init_rsp {
320 uint32_t status;
321 uint32_t commandid;
322 uint32_t ctxhandle;
323};
324
325struct __attribute__ ((__packed__)) hdcp_deinit_req {
326 uint32_t commandid;
327 uint32_t ctxhandle;
328};
329
330struct __attribute__ ((__packed__)) hdcp_deinit_rsp {
331 uint32_t status;
332 uint32_t commandid;
333};
334
335struct __attribute__ ((__packed__)) hdcp_rcvd_msg_req {
336 uint32_t commandid;
337 uint32_t ctxhandle;
338 uint32_t msglen;
339 uint8_t msg[MAX_RX_MESSAGE_SIZE];
340};
341
342struct __attribute__ ((__packed__)) hdcp_rcvd_msg_rsp {
343 uint32_t status;
344 uint32_t commandid;
345 uint32_t state;
346 uint32_t timeout;
347 uint32_t flag;
348 uint32_t msglen;
349 uint8_t msg[MAX_TX_MESSAGE_SIZE];
350};
351
352struct __attribute__ ((__packed__)) hdcp_set_hw_key_req {
353 uint32_t commandid;
354 uint32_t ctxhandle;
355};
356
357struct __attribute__ ((__packed__)) hdcp_set_hw_key_rsp {
358 uint32_t status;
359 uint32_t commandid;
360};
361
362struct __attribute__ ((__packed__)) hdcp_send_timeout_req {
363 uint32_t commandid;
364 uint32_t ctxhandle;
365};
366
367struct __attribute__ ((__packed__)) hdcp_send_timeout_rsp {
368 uint32_t status;
369 uint32_t commandid;
370 uint32_t timeout;
371 uint32_t msglen;
372 uint8_t message[MAX_TX_MESSAGE_SIZE];
373};
374
375struct __attribute__ ((__packed__)) hdcp_query_stream_type_req {
376 uint32_t commandid;
377 uint32_t ctxhandle;
378};
379
380struct __attribute__ ((__packed__)) hdcp_query_stream_type_rsp {
381 uint32_t status;
382 uint32_t commandid;
383 uint32_t timeout;
384 uint32_t msglen;
385 uint8_t msg[MAX_TX_MESSAGE_SIZE];
386};
387
388struct __attribute__ ((__packed__)) hdcp_set_stream_type_req {
389 uint32_t commandid;
390 uint32_t ctxhandle;
391 uint8_t streamtype;
392};
393
394struct __attribute__ ((__packed__)) hdcp_set_stream_type_rsp {
395 uint32_t status;
396 uint32_t commandid;
397 uint32_t timeout;
398 uint32_t msglen;
399 uint8_t message[MAX_TX_MESSAGE_SIZE];
400};
401
402struct __attribute__ ((__packed__)) hdcp_update_srm_req {
403 uint32_t commandid;
404 uint32_t ctxhandle;
405 uint32_t srmoffset;
406 uint32_t srmlength;
407};
408
409struct __attribute__ ((__packed__)) hdcp_update_srm_rsp {
410 uint32_t status;
411 uint32_t commandid;
412};
413
414struct __attribute__ ((__packed__)) hdcp_get_topology_req {
415 uint32_t commandid;
416 uint32_t ctxhandle;
417};
418
419struct __attribute__ ((__packed__)) hdcp_get_topology_rsp {
420 uint32_t status;
421 uint32_t commandid;
422 struct topology_info topologyinfo;
423};
424
425struct __attribute__ ((__packed__)) rxvr_info_struct {
426 uint8_t rcvrCert[522];
427 uint8_t rrx[BITS_64_IN_BYTES];
428 uint8_t rxcaps[RXCAPS_SIZE];
429 bool repeater;
430};
431
432struct __attribute__ ((__packed__)) repeater_info_struct {
433 uint8_t RxInfo[RXINFO_SIZE];
434 uint8_t seq_num_V[SEQ_NUM_V_SIZE];
435 bool seq_num_V_Rollover_flag;
436 uint8_t ReceiverIDList[MAX_RCVR_ID_LIST_SIZE];
437 uint32_t ReceiverIDListLen;
438};
439
440struct __attribute__ ((__packed__)) hdcp1_set_enc_req {
441 uint32_t commandid;
442 uint32_t enable;
443};
444
445struct __attribute__ ((__packed__)) hdcp1_set_enc_rsp {
446 uint32_t commandid;
447 uint32_t ret;
448};
449
450struct __attribute__ ((__packed__)) hdcp_start_auth_req {
451 uint32_t commandid;
452 uint32_t ctxHandle;
453};
454
455struct __attribute__ ((__packed__)) hdcp_start_auth_rsp {
456 uint32_t status;
457 uint32_t commandid;
458 uint32_t ctxhandle;
459 uint32_t timeout;
460 uint32_t msglen;
461 uint8_t message[MAX_TX_MESSAGE_SIZE];
462};
463
464struct hdcp_lib_handle {
465 unsigned char *listener_buf;
466 uint32_t msglen;
467 uint32_t tz_ctxhandle;
468 uint32_t hdcp_timeout;
469 uint32_t timeout_left;
470 uint32_t wait_timeout;
471 bool no_stored_km_flag;
472 bool feature_supported;
473 bool authenticated;
474 void *client_ctx;
475 struct hdcp_client_ops *client_ops;
476 struct mutex msg_lock;
477 struct mutex wakeup_mutex;
478 enum hdcp_state hdcp_state;
479 enum hdcp_lib_wakeup_cmd wakeup_cmd;
480 bool repeater_flag;
481 bool update_stream;
482 struct qseecom_handle *qseecom_handle;
483 int last_msg_sent;
484 int last_msg;
485 char *last_msg_recvd_buf;
486 uint32_t last_msg_recvd_len;
487 atomic_t hdcp_off;
488 uint32_t session_id;
489 enum hdcp_device_type device_type;
490
491 struct task_struct *thread;
492 struct completion poll_wait;
493
494 struct kthread_worker worker;
495 struct kthread_work wk_init;
496 struct kthread_work wk_msg_sent;
497 struct kthread_work wk_msg_recvd;
498 struct kthread_work wk_timeout;
499 struct kthread_work wk_clean;
500 struct kthread_work wk_wait;
501 struct kthread_work wk_stream;
502
503 int (*hdcp_app_init)(struct hdcp_lib_handle *handle);
504 int (*hdcp_txmtr_init)(struct hdcp_lib_handle *handle);
505};
506
507struct hdcp_lib_message_map {
508 int msg_id;
509 const char *msg_name;
510};
511
512struct msm_hdcp_mgr {
513 struct platform_device *pdev;
514 dev_t dev_num;
515 struct cdev cdev;
516 struct class *class;
517 struct device *device;
518 struct HDCP_V2V1_MSG_TOPOLOGY cached_tp;
519 u32 tp_msgid;
520 void *client_ctx;
521 struct hdcp_lib_handle *handle;
522};
523
524static struct msm_hdcp_mgr *hdcp_drv_mgr;
525static struct hdcp_lib_handle *drv_client_handle;
526
527static void hdcp_lib_clean(struct hdcp_lib_handle *handle);
528static void hdcp_lib_init(struct hdcp_lib_handle *handle);
529static void hdcp_lib_msg_sent(struct hdcp_lib_handle *handle);
530static void hdcp_lib_msg_recvd(struct hdcp_lib_handle *handle);
531static void hdcp_lib_timeout(struct hdcp_lib_handle *handle);
532static void hdcp_lib_stream(struct hdcp_lib_handle *handle);
533static int hdcp_lib_txmtr_init(struct hdcp_lib_handle *handle);
534
535static struct qseecom_handle *hdcp1_handle;
536static bool hdcp1_supported = true;
537static bool hdcp1_enc_enabled;
538static struct mutex hdcp1_ta_cmd_lock;
539
540static const char *hdcp_lib_message_name(int msg_id)
541{
542 /*
543 * Message ID map. The first number indicates the message number
544 * assigned to the message by the HDCP 2.2 spec. This is also the first
545 * byte of every HDCP 2.2 authentication protocol message.
546 */
547 static struct hdcp_lib_message_map hdcp_lib_msg_map[] = {
548 {2, "AKE_INIT"},
549 {3, "AKE_SEND_CERT"},
550 {4, "AKE_NO_STORED_KM"},
551 {5, "AKE_STORED_KM"},
552 {7, "AKE_SEND_H_PRIME"},
553 {8, "AKE_SEND_PAIRING_INFO"},
554 {9, "LC_INIT"},
555 {10, "LC_SEND_L_PRIME"},
556 {11, "SKE_SEND_EKS"},
557 {12, "REPEATER_AUTH_SEND_RECEIVERID_LIST"},
558 {15, "REPEATER_AUTH_SEND_ACK"},
559 {16, "REPEATER_AUTH_STREAM_MANAGE"},
560 {17, "REPEATER_AUTH_STREAM_READY"},
561 {18, "SKE_SEND_TYPE_ID"},
562 };
563 int i;
564
565 for (i = 0; i < ARRAY_SIZE(hdcp_lib_msg_map); i++) {
566 if (msg_id == hdcp_lib_msg_map[i].msg_id)
567 return hdcp_lib_msg_map[i].msg_name;
568 }
569 return "UNKNOWN";
570}
571
572static int hdcp_lib_get_next_message(struct hdcp_lib_handle *handle,
573 struct hdcp_wakeup_data *data)
574{
575 switch (handle->last_msg) {
576 case INVALID_MESSAGE_ID:
577 return AKE_INIT_MESSAGE_ID;
578 case AKE_INIT_MESSAGE_ID:
579 return AKE_SEND_CERT_MESSAGE_ID;
580 case AKE_SEND_CERT_MESSAGE_ID:
581 if (handle->no_stored_km_flag)
582 return AKE_NO_STORED_KM_MESSAGE_ID;
583 else
584 return AKE_STORED_KM_MESSAGE_ID;
585 case AKE_STORED_KM_MESSAGE_ID:
586 case AKE_NO_STORED_KM_MESSAGE_ID:
587 return AKE_SEND_H_PRIME_MESSAGE_ID;
588 case AKE_SEND_H_PRIME_MESSAGE_ID:
589 if (handle->no_stored_km_flag)
590 return AKE_SEND_PAIRING_INFO_MESSAGE_ID;
591 else
592 return LC_INIT_MESSAGE_ID;
593 case AKE_SEND_PAIRING_INFO_MESSAGE_ID:
594 return LC_INIT_MESSAGE_ID;
595 case LC_INIT_MESSAGE_ID:
596 return LC_SEND_L_PRIME_MESSAGE_ID;
597 case LC_SEND_L_PRIME_MESSAGE_ID:
598 return SKE_SEND_EKS_MESSAGE_ID;
599 case SKE_SEND_EKS_MESSAGE_ID:
600 if (!handle->repeater_flag)
601 return SKE_SEND_TYPE_ID;
602 case SKE_SEND_TYPE_ID:
603 case REPEATER_AUTH_STREAM_READY_MESSAGE_ID:
604 case REPEATER_AUTH_SEND_ACK_MESSAGE_ID:
605 if (!handle->repeater_flag)
606 return INVALID_MESSAGE_ID;
607
608 if (data->cmd == HDCP_WKUP_CMD_SEND_MESSAGE)
609 return REPEATER_AUTH_STREAM_MANAGE_MESSAGE_ID;
610 else
611 return REPEATER_AUTH_SEND_RECEIVERID_LIST_MESSAGE_ID;
612 case REPEATER_AUTH_SEND_RECEIVERID_LIST_MESSAGE_ID:
613 return REPEATER_AUTH_SEND_ACK_MESSAGE_ID;
614 case REPEATER_AUTH_STREAM_MANAGE_MESSAGE_ID:
615 return REPEATER_AUTH_STREAM_READY_MESSAGE_ID;
616 default:
617 pr_err("Uknown message ID (%d)", handle->last_msg);
618 return -EINVAL;
619 }
620}
621
622static void hdcp_lib_wait_for_response(struct hdcp_lib_handle *handle,
623 struct hdcp_wakeup_data *data)
624{
625 switch (handle->last_msg) {
626 case AKE_SEND_H_PRIME_MESSAGE_ID:
627 if (handle->no_stored_km_flag)
628 handle->wait_timeout = HZ;
629 else
630 handle->wait_timeout = HZ / 4;
631 break;
632 case AKE_SEND_PAIRING_INFO_MESSAGE_ID:
633 handle->wait_timeout = HZ / 4;
634 break;
635 case REPEATER_AUTH_SEND_RECEIVERID_LIST_MESSAGE_ID:
636 if (!handle->authenticated)
637 handle->wait_timeout = HZ * 3;
638 else
639 handle->wait_timeout = 0;
640 break;
641 default:
642 handle->wait_timeout = 0;
643 }
644
645 if (handle->wait_timeout)
646 kthread_queue_work(&handle->worker, &handle->wk_wait);
647}
648
649static void hdcp_lib_wakeup_client(struct hdcp_lib_handle *handle,
650 struct hdcp_wakeup_data *data)
651{
652 int rc = 0, i;
653
654 if (!handle || !handle->client_ops || !handle->client_ops->wakeup ||
655 !data || (data->cmd == HDCP_WKUP_CMD_INVALID))
656 return;
657
658 data->abort_mask = REAUTH_REQ | LINK_INTEGRITY_FAILURE;
659
660 if (data->cmd == HDCP_WKUP_CMD_RECV_MESSAGE ||
661 data->cmd == HDCP_WKUP_CMD_LINK_POLL)
662 handle->last_msg = hdcp_lib_get_next_message(handle, data);
663
664 if (handle->last_msg != INVALID_MESSAGE_ID &&
665 data->cmd != HDCP_WKUP_CMD_STATUS_SUCCESS &&
666 data->cmd != HDCP_WKUP_CMD_STATUS_FAILED) {
667 u32 msg_num, rx_status;
668 const struct hdcp_msg_part *msg;
669
670 pr_debug("lib->client: %s (%s)\n",
671 hdcp_cmd_to_str(data->cmd),
672 hdcp_lib_message_name(handle->last_msg));
673
674 data->message_data = &hdcp_msg_lookup[handle->last_msg];
675
676 msg_num = data->message_data->num_messages;
677 msg = data->message_data->messages;
678 rx_status = data->message_data->rx_status;
679
680 pr_debug("%10s | %6s | %4s\n", "name", "offset", "len");
681
682 for (i = 0; i < msg_num; i++)
683 pr_debug("%10s | %6x | %4d\n",
684 msg[i].name, msg[i].offset,
685 msg[i].length);
686 } else {
687 pr_debug("lib->client: %s\n", hdcp_cmd_to_str(data->cmd));
688 }
689
690 rc = handle->client_ops->wakeup(data);
691 if (rc)
692 pr_err("error sending %s to client\n",
693 hdcp_cmd_to_str(data->cmd));
694
695 hdcp_lib_wait_for_response(handle, data);
696}
697
698static inline void hdcp_lib_send_message(struct hdcp_lib_handle *handle)
699{
700 char msg_name[50];
701 struct hdcp_wakeup_data cdata = {
702 HDCP_WKUP_CMD_SEND_MESSAGE
703 };
704
705 cdata.context = handle->client_ctx;
706 cdata.send_msg_buf = handle->listener_buf;
707 cdata.send_msg_len = handle->msglen;
708 cdata.timeout = handle->hdcp_timeout;
709
710 snprintf(msg_name, sizeof(msg_name), "%s: ",
711 hdcp_lib_message_name((int)cdata.send_msg_buf[0]));
712
713 print_hex_dump(KERN_DEBUG, msg_name,
714 DUMP_PREFIX_NONE, 16, 1, cdata.send_msg_buf,
715 cdata.send_msg_len, false);
716
717 hdcp_lib_wakeup_client(handle, &cdata);
718}
719
720static int hdcp_lib_enable_encryption(struct hdcp_lib_handle *handle)
721{
722 int rc = 0;
723 struct hdcp_set_hw_key_req *req_buf;
724 struct hdcp_set_hw_key_rsp *rsp_buf;
725
726 if (!handle || !handle->qseecom_handle ||
727 !handle->qseecom_handle->sbuf) {
728 pr_err("invalid handle\n");
729 rc = -EINVAL;
730 goto error;
731 }
732
733 /*
734 * wait at least 200ms before enabling encryption
735 * as per hdcp2p2 sepcifications.
736 */
737 msleep(SLEEP_SET_HW_KEY_MS);
738
739 req_buf = (struct hdcp_set_hw_key_req *)(handle->qseecom_handle->sbuf);
740 req_buf->commandid = HDCP_TXMTR_SET_HW_KEY;
741 req_buf->ctxhandle = handle->tz_ctxhandle;
742
743 rsp_buf = (struct hdcp_set_hw_key_rsp *)
744 (handle->qseecom_handle->sbuf +
745 QSEECOM_ALIGN(sizeof(struct hdcp_set_hw_key_req)));
746
747 rc = qseecom_send_command(handle->qseecom_handle, req_buf,
748 QSEECOM_ALIGN(sizeof
749 (struct hdcp_set_hw_key_req)),
750 rsp_buf,
751 QSEECOM_ALIGN(sizeof
752 (struct hdcp_set_hw_key_rsp)));
753
754 if ((rc < 0) || (rsp_buf->status < 0)) {
755 pr_err("qseecom cmd failed with err = %d status = %d\n",
756 rc, rsp_buf->status);
757 rc = -EINVAL;
758 goto error;
759 }
760
761 /* reached an authenticated state */
762 handle->hdcp_state |= HDCP_STATE_AUTHENTICATED;
763
764 pr_debug("success\n");
765 return 0;
766error:
767 if (handle && !atomic_read(&handle->hdcp_off))
768 HDCP_LIB_EXECUTE(clean);
769
770 return rc;
771}
772
773static int hdcp_lib_get_version(struct hdcp_lib_handle *handle)
774{
775 int rc = 0;
776 struct hdcp_version_req *req_buf;
777 struct hdcp_version_rsp *rsp_buf;
778 uint32_t app_major_version = 0;
779
780 if (!handle) {
781 pr_err("invalid input\n");
782 rc = -EINVAL;
783 goto exit;
784 }
785
786 if (!(handle->hdcp_state & HDCP_STATE_APP_LOADED)) {
787 pr_err("library not loaded\n");
788 rc = -EINVAL;
789 goto exit;
790 }
791
792 /* get the TZ hdcp2p2 app version */
793 req_buf = (struct hdcp_version_req *)handle->qseecom_handle->sbuf;
794 req_buf->commandid = HDCP_TXMTR_GET_VERSION;
795
796 rsp_buf = (struct hdcp_version_rsp *)
797 (handle->qseecom_handle->sbuf +
798 QSEECOM_ALIGN(sizeof(struct hdcp_version_req)));
799
800 rc = qseecom_send_command(handle->qseecom_handle,
801 req_buf,
802 QSEECOM_ALIGN(sizeof
803 (struct hdcp_lib_init_req)),
804 rsp_buf,
805 QSEECOM_ALIGN(sizeof
806 (struct hdcp_lib_init_rsp)));
807
808 if (rc < 0) {
809 pr_err("qseecom cmd failed err = %d\n", rc);
810 goto exit;
811 }
812
813 app_major_version = HCDP_TXMTR_GET_MAJOR_VERSION(rsp_buf->appversion);
814
815 pr_debug("hdcp2p2 app major version %d, app version %d\n",
816 app_major_version, rsp_buf->appversion);
817
818exit:
819 return rc;
820}
821
822static int hdcp_lib_verify_keys(struct hdcp_lib_handle *handle)
823{
824 int rc = -EINVAL;
825 struct hdcp_verify_key_req *req_buf;
826 struct hdcp_verify_key_rsp *rsp_buf;
827
828 if (!handle) {
829 pr_err("invalid input\n");
830 goto exit;
831 }
832
833 if (!(handle->hdcp_state & HDCP_STATE_APP_LOADED)) {
834 pr_err("app not loaded\n");
835 goto exit;
836 }
837
838 req_buf = (struct hdcp_verify_key_req *)handle->qseecom_handle->sbuf;
839 req_buf->commandid = HDCP_TXMTR_VERIFY_KEY;
840
841 rsp_buf = (struct hdcp_verify_key_rsp *)
842 (handle->qseecom_handle->sbuf +
843 QSEECOM_ALIGN(sizeof(struct hdcp_verify_key_req)));
844
845 rc = qseecom_send_command(handle->qseecom_handle,
846 req_buf,
847 QSEECOM_ALIGN(sizeof
848 (struct hdcp_verify_key_req)),
849 rsp_buf,
850 QSEECOM_ALIGN(sizeof
851 (struct hdcp_verify_key_rsp)));
852
853 if (rc < 0) {
854 pr_err("qseecom cmd failed err = %d\n", rc);
855 goto exit;
856 }
857
858 return rsp_buf->status;
859exit:
860 return rc;
861}
862
863static int hdcp_app_init(struct hdcp_lib_handle *handle)
864{
865 int rc = 0;
866 struct hdcp_lib_init_req *req_buf;
867 struct hdcp_lib_init_rsp *rsp_buf;
868 uint32_t app_minor_version = 0;
869
870 if (!handle) {
871 pr_err("invalid input\n");
872 goto exit;
873 }
874
875 if (!(handle->hdcp_state & HDCP_STATE_APP_LOADED)) {
876 pr_err("library not loaded\n");
877 goto exit;
878 }
879
880 /* now load the app by sending hdcp_lib_init */
881 req_buf = (struct hdcp_lib_init_req *)handle->qseecom_handle->sbuf;
882 req_buf->commandid = HDCP_LIB_INIT;
883 req_buf->clientversion =
884 HDCP_CLIENT_MAKE_VERSION(HDCP_CLIENT_MAJOR_VERSION,
885 HDCP_CLIENT_MINOR_VERSION,
886 HDCP_CLIENT_PATCH_VERSION);
887 rsp_buf = (struct hdcp_lib_init_rsp *)
888 (handle->qseecom_handle->sbuf +
889 QSEECOM_ALIGN(sizeof(struct hdcp_lib_init_req)));
890
891 rc = qseecom_send_command(handle->qseecom_handle,
892 req_buf,
893 QSEECOM_ALIGN(sizeof
894 (struct hdcp_lib_init_req)),
895 rsp_buf,
896 QSEECOM_ALIGN(sizeof
897 (struct hdcp_lib_init_rsp)));
898
899 if (rc < 0) {
900 pr_err("qseecom cmd failed err = %d\n", rc);
901 goto exit;
902 }
903
904 app_minor_version = HCDP_TXMTR_GET_MINOR_VERSION(rsp_buf->appversion);
905 if (app_minor_version != HDCP_CLIENT_MINOR_VERSION) {
906 pr_err
907 ("client-app minor version mismatch app(%d), client(%d)\n",
908 app_minor_version, HDCP_CLIENT_MINOR_VERSION);
909 rc = -1;
910 goto exit;
911 }
912 pr_debug("success\n");
913 pr_debug("client version major(%d), minor(%d), patch(%d)\n",
914 HDCP_CLIENT_MAJOR_VERSION, HDCP_CLIENT_MINOR_VERSION,
915 HDCP_CLIENT_PATCH_VERSION);
916 pr_debug("app version major(%d), minor(%d), patch(%d)\n",
917 HCDP_TXMTR_GET_MAJOR_VERSION(rsp_buf->appversion),
918 HCDP_TXMTR_GET_MINOR_VERSION(rsp_buf->appversion),
919 HCDP_TXMTR_GET_PATCH_VERSION(rsp_buf->appversion));
920
921exit:
922 return rc;
923}
924
925static int hdcp_lib_library_load(struct hdcp_lib_handle *handle)
926{
927 int rc = 0;
928
929 if (!handle) {
930 pr_err("invalid input\n");
931 goto exit;
932 }
933
934 if (handle->hdcp_state & HDCP_STATE_APP_LOADED) {
935 pr_err("library already loaded\n");
936 goto exit;
937 }
938
939 /*
940 * allocating resource for qseecom handle
941 * the app is not loaded here
942 */
943 rc = qseecom_start_app(&(handle->qseecom_handle),
944 TZAPP_NAME, QSEECOM_SBUFF_SIZE);
945 if (rc) {
946 pr_err("qseecom_start_app failed %d\n", rc);
947 goto exit;
948 }
949
950 handle->hdcp_state |= HDCP_STATE_APP_LOADED;
951 pr_debug("qseecom_start_app success\n");
952
953 rc = hdcp_lib_get_version(handle);
954 if (rc) {
955 pr_err("library get version failed\n");
956 goto exit;
957 }
958
959 handle->hdcp_app_init = hdcp_app_init;
960 handle->hdcp_txmtr_init = hdcp_lib_txmtr_init;
961
962 if (handle->hdcp_app_init == NULL) {
963 pr_err("invalid app init function pointer\n");
964 goto exit;
965 }
966
967 rc = handle->hdcp_app_init(handle);
968 if (rc) {
969 pr_err("app init failed\n");
970 goto exit;
971 }
972exit:
973 return rc;
974}
975
976static int hdcp_lib_library_unload(struct hdcp_lib_handle *handle)
977{
978 int rc = 0;
979 struct hdcp_lib_deinit_req *req_buf;
980 struct hdcp_lib_deinit_rsp *rsp_buf;
981
982 if (!handle || !handle->qseecom_handle ||
983 !handle->qseecom_handle->sbuf) {
984 pr_err("invalid handle\n");
985 rc = -EINVAL;
986 goto exit;
987 }
988
989 if (!(handle->hdcp_state & HDCP_STATE_APP_LOADED)) {
990 pr_err("library not loaded\n");
991 return rc;
992 }
993
994 /* unloading app by sending hdcp_lib_deinit cmd */
995 req_buf = (struct hdcp_lib_deinit_req *)handle->qseecom_handle->sbuf;
996 req_buf->commandid = HDCP_LIB_DEINIT;
997 rsp_buf = (struct hdcp_lib_deinit_rsp *)
998 (handle->qseecom_handle->sbuf +
999 QSEECOM_ALIGN(sizeof(struct hdcp_lib_deinit_req)));
1000
1001 rc = qseecom_send_command(handle->qseecom_handle,
1002 req_buf,
1003 QSEECOM_ALIGN(sizeof
1004 (struct hdcp_lib_deinit_req)),
1005 rsp_buf,
1006 QSEECOM_ALIGN(sizeof
1007 (struct hdcp_lib_deinit_rsp)));
1008
1009 if (rc < 0) {
1010 pr_err("qseecom cmd failed err = %d\n", rc);
1011 goto exit;
1012 }
1013
1014 /* deallocate the resources for qseecom handle */
1015 rc = qseecom_shutdown_app(&handle->qseecom_handle);
1016 if (rc) {
1017 pr_err("qseecom_shutdown_app failed err: %d\n", rc);
1018 goto exit;
1019 }
1020
1021 handle->hdcp_state &= ~HDCP_STATE_APP_LOADED;
1022 pr_debug("success\n");
1023exit:
1024 return rc;
1025}
1026
1027static int hdcp_lib_session_init(struct hdcp_lib_handle *handle)
1028{
1029 int rc = 0;
1030 struct hdcp_lib_session_init_req *req_buf;
1031 struct hdcp_lib_session_init_rsp *rsp_buf;
1032
1033 if (!handle || !handle->qseecom_handle ||
1034 !handle->qseecom_handle->sbuf) {
1035 pr_err("invalid handle\n");
1036 rc = -EINVAL;
1037 goto exit;
1038 }
1039
1040 if (!(handle->hdcp_state & HDCP_STATE_APP_LOADED)) {
1041 pr_err("app not loaded\n");
1042 goto exit;
1043 }
1044
1045 if (handle->hdcp_state & HDCP_STATE_SESSION_INIT) {
1046 pr_err("session already initialized\n");
1047 goto exit;
1048 }
1049
1050 /* send HDCP_Session_Init command to TZ */
1051 req_buf =
1052 (struct hdcp_lib_session_init_req *)handle->qseecom_handle->sbuf;
1053 req_buf->commandid = HDCP_SESSION_INIT;
1054 req_buf->deviceid = handle->device_type;
1055 rsp_buf = (struct hdcp_lib_session_init_rsp *)
1056 (handle->qseecom_handle->sbuf +
1057 QSEECOM_ALIGN(sizeof(struct hdcp_lib_session_init_req)));
1058
1059 rc = qseecom_send_command(handle->qseecom_handle, req_buf,
1060 QSEECOM_ALIGN(sizeof
1061 (struct
1062 hdcp_lib_session_init_req)),
1063 rsp_buf,
1064 QSEECOM_ALIGN(sizeof
1065 (struct
1066 hdcp_lib_session_init_rsp)));
1067
1068 if ((rc < 0) || (rsp_buf->status != HDCP_SUCCESS) ||
1069 (rsp_buf->commandid != HDCP_SESSION_INIT)) {
1070 pr_err("qseecom cmd failed with err = %d, status = %d\n",
1071 rc, rsp_buf->status);
1072 rc = -EINVAL;
1073 goto exit;
1074 }
1075
1076 pr_debug("session id %d\n", rsp_buf->sessionid);
1077
1078 handle->session_id = rsp_buf->sessionid;
1079 handle->hdcp_state |= HDCP_STATE_SESSION_INIT;
1080
1081 pr_debug("success\n");
1082exit:
1083 return rc;
1084}
1085
1086static int hdcp_lib_session_deinit(struct hdcp_lib_handle *handle)
1087{
1088 int rc = 0;
1089 struct hdcp_lib_session_deinit_req *req_buf;
1090 struct hdcp_lib_session_deinit_rsp *rsp_buf;
1091
1092 if (!handle || !handle->qseecom_handle ||
1093 !handle->qseecom_handle->sbuf) {
1094 pr_err("invalid handle\n");
1095 rc = -EINVAL;
1096 goto exit;
1097 }
1098
1099 if (!(handle->hdcp_state & HDCP_STATE_APP_LOADED)) {
1100 pr_err("app not loaded\n");
1101 goto exit;
1102 }
1103
1104 if (!(handle->hdcp_state & HDCP_STATE_SESSION_INIT)) {
1105 /* unload library here */
1106 pr_err("session not initialized\n");
1107 goto exit;
1108 }
1109
1110 /* send command to TZ */
1111 req_buf =
1112 (struct hdcp_lib_session_deinit_req *)handle->qseecom_handle->sbuf;
1113 req_buf->commandid = HDCP_SESSION_DEINIT;
1114 req_buf->sessionid = handle->session_id;
1115 rsp_buf = (struct hdcp_lib_session_deinit_rsp *)
1116 (handle->qseecom_handle->sbuf +
1117 QSEECOM_ALIGN(sizeof(struct hdcp_lib_session_deinit_req)));
1118
1119 rc = qseecom_send_command(handle->qseecom_handle, req_buf,
1120 QSEECOM_ALIGN(sizeof
1121 (struct
1122 hdcp_lib_session_deinit_req)),
1123 rsp_buf,
1124 QSEECOM_ALIGN(sizeof
1125 (struct
1126 hdcp_lib_session_deinit_rsp)));
1127
1128 if ((rc < 0) || (rsp_buf->status < 0) ||
1129 (rsp_buf->commandid != HDCP_SESSION_DEINIT)) {
1130 pr_err("qseecom cmd failed with err = %d status = %d\n",
1131 rc, rsp_buf->status);
1132 rc = -EINVAL;
1133 goto exit;
1134 }
1135
1136 handle->hdcp_state &= ~HDCP_STATE_SESSION_INIT;
1137 pr_debug("success\n");
1138exit:
1139 return rc;
1140}
1141
1142static int hdcp_lib_txmtr_init(struct hdcp_lib_handle *handle)
1143{
1144 int rc = 0;
1145 struct hdcp_tx_init_req *req_buf;
1146 struct hdcp_tx_init_rsp *rsp_buf;
1147
1148 if (!handle || !handle->qseecom_handle ||
1149 !handle->qseecom_handle->sbuf) {
1150 pr_err("invalid handle\n");
1151 rc = -EINVAL;
1152 goto exit;
1153 }
1154
1155 if (!(handle->hdcp_state & HDCP_STATE_SESSION_INIT)) {
1156 pr_err("session not initialized\n");
1157 goto exit;
1158 }
1159
1160 if (!(handle->hdcp_state & HDCP_STATE_APP_LOADED)) {
1161 pr_err("library not loaded\n");
1162 goto exit;
1163 }
1164
1165 /* send HDCP_Txmtr_Init command to TZ */
1166 req_buf = (struct hdcp_tx_init_req *)handle->qseecom_handle->sbuf;
1167 req_buf->commandid = HDCP_TXMTR_INIT;
1168 req_buf->sessionid = handle->session_id;
1169 rsp_buf = (struct hdcp_tx_init_rsp *)
1170 (handle->qseecom_handle->sbuf +
1171 QSEECOM_ALIGN(sizeof(struct hdcp_tx_init_req)));
1172
1173 rc = qseecom_send_command(handle->qseecom_handle, req_buf,
1174 QSEECOM_ALIGN(sizeof
1175 (struct hdcp_tx_init_req)),
1176 rsp_buf,
1177 QSEECOM_ALIGN(sizeof
1178 (struct hdcp_tx_init_rsp)));
1179
1180 if ((rc < 0) || (rsp_buf->status != HDCP_SUCCESS) ||
1181 (rsp_buf->commandid != HDCP_TXMTR_INIT)) {
1182 pr_err("qseecom cmd failed with err = %d, status = %d\n",
1183 rc, rsp_buf->status);
1184 rc = -EINVAL;
1185 goto exit;
1186 }
1187
1188 handle->tz_ctxhandle = rsp_buf->ctxhandle;
1189 handle->hdcp_state |= HDCP_STATE_TXMTR_INIT;
1190
1191 pr_debug("success\n");
1192exit:
1193 return rc;
1194}
1195
1196static int hdcp_lib_txmtr_deinit(struct hdcp_lib_handle *handle)
1197{
1198 int rc = 0;
1199 struct hdcp_deinit_req *req_buf;
1200 struct hdcp_deinit_rsp *rsp_buf;
1201
1202 if (!handle || !handle->qseecom_handle ||
1203 !handle->qseecom_handle->sbuf) {
1204 pr_err("invalid handle\n");
1205 rc = -EINVAL;
1206 goto exit;
1207 }
1208
1209 if (!(handle->hdcp_state & HDCP_STATE_APP_LOADED)) {
1210 pr_err("app not loaded\n");
1211 goto exit;
1212 }
1213
1214 if (!(handle->hdcp_state & HDCP_STATE_TXMTR_INIT)) {
1215 /* unload library here */
1216 pr_err("txmtr not initialized\n");
1217 goto exit;
1218 }
1219
1220 /* send command to TZ */
1221 req_buf = (struct hdcp_deinit_req *)handle->qseecom_handle->sbuf;
1222 req_buf->commandid = HDCP_TXMTR_DEINIT;
1223 req_buf->ctxhandle = handle->tz_ctxhandle;
1224 rsp_buf = (struct hdcp_deinit_rsp *)
1225 (handle->qseecom_handle->sbuf +
1226 QSEECOM_ALIGN(sizeof(struct hdcp_deinit_req)));
1227
1228 rc = qseecom_send_command(handle->qseecom_handle, req_buf,
1229 QSEECOM_ALIGN(sizeof(struct hdcp_deinit_req)),
1230 rsp_buf,
1231 QSEECOM_ALIGN(sizeof
1232 (struct hdcp_deinit_rsp)));
1233
1234 if ((rc < 0) || (rsp_buf->status < 0) ||
1235 (rsp_buf->commandid != HDCP_TXMTR_DEINIT)) {
1236 pr_err("qseecom cmd failed with err = %d status = %d\n",
1237 rc, rsp_buf->status);
1238 rc = -EINVAL;
1239 goto exit;
1240 }
1241
1242 handle->hdcp_state &= ~HDCP_STATE_TXMTR_INIT;
1243 pr_debug("success\n");
1244exit:
1245 return rc;
1246}
1247
1248static int hdcp_lib_start_auth(struct hdcp_lib_handle *handle)
1249{
1250 int rc = 0;
1251 struct hdcp_start_auth_req *req_buf;
1252 struct hdcp_start_auth_rsp *rsp_buf;
1253
1254 if (!handle || !handle->qseecom_handle ||
1255 !handle->qseecom_handle->sbuf) {
1256 pr_err("invalid handle\n");
1257 rc = -EINVAL;
1258 goto exit;
1259 }
1260
1261 if (!(handle->hdcp_state & HDCP_STATE_SESSION_INIT)) {
1262 pr_err("session not initialized\n");
1263 goto exit;
1264 }
1265
1266 if (!(handle->hdcp_state & HDCP_STATE_TXMTR_INIT)) {
1267 pr_err("txmtr not initialized\n");
1268 goto exit;
1269 }
1270
1271 /* send HDCP_Txmtr_Start_Auth command to TZ */
1272 req_buf = (struct hdcp_start_auth_req *)handle->qseecom_handle->sbuf;
1273 req_buf->commandid = HDCP_TXMTR_START_AUTHENTICATE;
1274 req_buf->ctxHandle = handle->tz_ctxhandle;
1275 rsp_buf = (struct hdcp_start_auth_rsp *)
1276 (handle->qseecom_handle->sbuf +
1277 QSEECOM_ALIGN(sizeof(struct hdcp_start_auth_req)));
1278
1279 rc = qseecom_send_command(handle->qseecom_handle, req_buf,
1280 QSEECOM_ALIGN(sizeof
1281 (struct hdcp_start_auth_req)),
1282 rsp_buf,
1283 QSEECOM_ALIGN(sizeof
1284 (struct hdcp_start_auth_rsp)));
1285
1286 if ((rc < 0) || (rsp_buf->status != HDCP_SUCCESS) ||
1287 (rsp_buf->commandid != HDCP_TXMTR_START_AUTHENTICATE) ||
1288 (rsp_buf->msglen <= 0) || (rsp_buf->message == NULL)) {
1289 pr_err("qseecom cmd failed with err = %d, status = %d\n",
1290 rc, rsp_buf->status);
1291 rc = -EINVAL;
1292 goto exit;
1293 }
1294
1295 pr_debug("recvd %s from TZ at %dms\n",
1296 hdcp_lib_message_name((int)rsp_buf->message[0]),
1297 jiffies_to_msecs(jiffies));
1298
1299 handle->last_msg = (int)rsp_buf->message[0];
1300
1301 /* send the response to HDMI driver */
1302 memset(handle->listener_buf, 0, MAX_TX_MESSAGE_SIZE);
1303 memcpy(handle->listener_buf, (unsigned char *)rsp_buf->message,
1304 rsp_buf->msglen);
1305 handle->msglen = rsp_buf->msglen;
1306 handle->hdcp_timeout = rsp_buf->timeout;
1307
1308 handle->tz_ctxhandle = rsp_buf->ctxhandle;
1309
1310 pr_debug("success\n");
1311exit:
1312 return rc;
1313}
1314
1315static void hdcp_lib_stream(struct hdcp_lib_handle *handle)
1316{
1317 int rc = 0;
1318 struct hdcp_query_stream_type_req *req_buf;
1319 struct hdcp_query_stream_type_rsp *rsp_buf;
1320
1321 if (!handle || !handle->qseecom_handle ||
1322 !handle->qseecom_handle->sbuf) {
1323 pr_err("invalid handle\n");
1324 return;
1325 }
1326
1327 if (atomic_read(&handle->hdcp_off)) {
1328 pr_debug("invalid state, hdcp off\n");
1329 return;
1330 }
1331
1332 if (!handle->repeater_flag) {
1333 pr_debug("invalid state, not a repeater\n");
1334 return;
1335 }
1336
1337 /* send command to TZ */
1338 req_buf =
1339 (struct hdcp_query_stream_type_req *)handle->qseecom_handle->sbuf;
1340 req_buf->commandid = HDCP_TXMTR_QUERY_STREAM_TYPE;
1341 req_buf->ctxhandle = handle->tz_ctxhandle;
1342 rsp_buf = (struct hdcp_query_stream_type_rsp *)
1343 (handle->qseecom_handle->sbuf +
1344 QSEECOM_ALIGN(sizeof(struct hdcp_query_stream_type_req)));
1345
1346 rc = qseecom_send_command(handle->qseecom_handle, req_buf,
1347 QSEECOM_ALIGN(sizeof
1348 (struct
1349 hdcp_query_stream_type_req)),
1350 rsp_buf,
1351 QSEECOM_ALIGN(sizeof
1352 (struct
1353 hdcp_query_stream_type_rsp)));
1354
1355 if ((rc < 0) || (rsp_buf->status < 0) || (rsp_buf->msglen <= 0) ||
1356 (rsp_buf->commandid != HDCP_TXMTR_QUERY_STREAM_TYPE) ||
1357 (rsp_buf->msg == NULL)) {
1358 pr_err("qseecom cmd failed with err=%d status=%d\n",
1359 rc, rsp_buf->status);
1360 rc = -EINVAL;
1361 goto exit;
1362 }
1363
1364 pr_debug("message received from TZ: %s\n",
1365 hdcp_lib_message_name((int)rsp_buf->msg[0]));
1366
1367 handle->last_msg = (int)rsp_buf->msg[0];
1368
1369 memset(handle->listener_buf, 0, MAX_TX_MESSAGE_SIZE);
1370 memcpy(handle->listener_buf, (unsigned char *)rsp_buf->msg,
1371 rsp_buf->msglen);
1372 handle->hdcp_timeout = rsp_buf->timeout;
1373 handle->msglen = rsp_buf->msglen;
1374exit:
1375 if (!rc && !atomic_read(&handle->hdcp_off))
1376 hdcp_lib_send_message(handle);
1377}
1378
1379static void hdcp_lib_query_stream_work(struct kthread_work *work)
1380{
1381 struct hdcp_lib_handle *handle = container_of(work,
1382 struct hdcp_lib_handle,
1383 wk_stream);
1384
1385 hdcp_lib_stream(handle);
1386}
1387
1388static bool hdcp_lib_client_feature_supported(void *phdcpcontext)
1389{
1390 int rc = 0;
1391 bool supported = false;
1392 struct hdcp_lib_handle *handle = phdcpcontext;
1393
1394 if (!handle) {
1395 pr_err("invalid input\n");
1396 goto exit;
1397 }
1398
1399 if (handle->feature_supported) {
1400 supported = true;
1401 goto exit;
1402 }
1403
1404 rc = hdcp_lib_library_load(handle);
1405 if (!rc) {
1406 if (!hdcp_lib_verify_keys(handle)) {
1407 pr_debug("HDCP2p2 supported\n");
1408 handle->feature_supported = true;
1409 supported = true;
1410 }
1411 hdcp_lib_library_unload(handle);
1412 }
1413exit:
1414 return supported;
1415}
1416
1417static void hdcp_lib_check_worker_status(struct hdcp_lib_handle *handle)
1418{
1419 if (!list_empty(&handle->wk_init.node))
1420 pr_debug("init work queued\n");
1421
1422 if (handle->worker.current_work == &handle->wk_init)
1423 pr_debug("init work executing\n");
1424
1425 if (!list_empty(&handle->wk_msg_sent.node))
1426 pr_debug("msg_sent work queued\n");
1427
1428 if (handle->worker.current_work == &handle->wk_msg_sent)
1429 pr_debug("msg_sent work executing\n");
1430
1431 if (!list_empty(&handle->wk_msg_recvd.node))
1432 pr_debug("msg_recvd work queued\n");
1433
1434 if (handle->worker.current_work == &handle->wk_msg_recvd)
1435 pr_debug("msg_recvd work executing\n");
1436
1437 if (!list_empty(&handle->wk_timeout.node))
1438 pr_debug("timeout work queued\n");
1439
1440 if (handle->worker.current_work == &handle->wk_timeout)
1441 pr_debug("timeout work executing\n");
1442
1443 if (!list_empty(&handle->wk_clean.node))
1444 pr_debug("clean work queued\n");
1445
1446 if (handle->worker.current_work == &handle->wk_clean)
1447 pr_debug("clean work executing\n");
1448
1449 if (!list_empty(&handle->wk_wait.node))
1450 pr_debug("wait work queued\n");
1451
1452 if (handle->worker.current_work == &handle->wk_wait)
1453 pr_debug("wait work executing\n");
1454
1455 if (!list_empty(&handle->wk_stream.node))
1456 pr_debug("stream work queued\n");
1457
1458 if (handle->worker.current_work == &handle->wk_stream)
1459 pr_debug("stream work executing\n");
1460}
1461
1462static int hdcp_lib_check_valid_state(struct hdcp_lib_handle *handle)
1463{
1464 int rc = 0;
1465
1466 if (!list_empty(&handle->worker.work_list))
1467 hdcp_lib_check_worker_status(handle);
1468
1469 if (handle->wakeup_cmd == HDCP_LIB_WKUP_CMD_START) {
1470 if (!list_empty(&handle->worker.work_list)) {
1471 pr_debug("error: queue not empty\n");
1472 rc = -EBUSY;
1473 goto exit;
1474 }
1475
1476 if (handle->hdcp_state & HDCP_STATE_APP_LOADED) {
1477 pr_debug("library already loaded\n");
1478 rc = -EBUSY;
1479 goto exit;
1480 }
1481 } else {
1482 if (atomic_read(&handle->hdcp_off)) {
1483 pr_debug("hdcp2.2 session tearing down\n");
1484 goto exit;
1485 }
1486
1487 if (!(handle->hdcp_state & HDCP_STATE_APP_LOADED)) {
1488 pr_debug("hdcp 2.2 app not loaded\n");
1489 goto exit;
1490 }
1491 }
1492exit:
1493 return rc;
1494}
1495
1496static int hdcp_lib_wakeup_thread(struct hdcp_lib_wakeup_data *data)
1497{
1498 struct hdcp_lib_handle *handle;
1499 int rc = 0;
1500
1501 if (!data)
1502 return -EINVAL;
1503
1504 handle = data->context;
1505 if (!handle)
1506 return -EINVAL;
1507
1508 mutex_lock(&handle->wakeup_mutex);
1509
1510 handle->wakeup_cmd = data->cmd;
1511 handle->timeout_left = data->timeout;
1512
1513 pr_debug("client->lib: %s (%s)\n",
1514 hdcp_lib_cmd_to_str(data->cmd),
1515 hdcp_lib_message_name(handle->last_msg));
1516
1517 rc = hdcp_lib_check_valid_state(handle);
1518 if (rc)
1519 goto exit;
1520
1521 mutex_lock(&handle->msg_lock);
1522 if (data->recvd_msg_len) {
1523 kzfree(handle->last_msg_recvd_buf);
1524
1525 handle->last_msg_recvd_len = data->recvd_msg_len;
1526 handle->last_msg_recvd_buf = kzalloc(data->recvd_msg_len,
1527 GFP_KERNEL);
1528 if (!handle->last_msg_recvd_buf) {
1529 rc = -ENOMEM;
1530 mutex_unlock(&handle->msg_lock);
1531 goto exit;
1532 }
1533
1534 memcpy(handle->last_msg_recvd_buf, data->recvd_msg_buf,
1535 data->recvd_msg_len);
1536 }
1537 mutex_unlock(&handle->msg_lock);
1538
1539 if (!completion_done(&handle->poll_wait))
1540 complete_all(&handle->poll_wait);
1541
1542 switch (handle->wakeup_cmd) {
1543 case HDCP_LIB_WKUP_CMD_START:
1544 handle->no_stored_km_flag = 0;
1545 handle->repeater_flag = false;
1546 handle->update_stream = false;
1547 handle->last_msg_sent = 0;
1548 handle->last_msg = INVALID_MESSAGE_ID;
1549 handle->hdcp_timeout = 0;
1550 handle->timeout_left = 0;
1551 atomic_set(&handle->hdcp_off, 0);
1552 handle->hdcp_state = HDCP_STATE_INIT;
1553
1554 HDCP_LIB_EXECUTE(init);
1555 break;
1556 case HDCP_LIB_WKUP_CMD_STOP:
1557 atomic_set(&handle->hdcp_off, 1);
1558
1559 HDCP_LIB_EXECUTE(clean);
1560 break;
1561 case HDCP_LIB_WKUP_CMD_MSG_SEND_SUCCESS:
1562 handle->last_msg_sent = handle->listener_buf[0];
1563
1564 HDCP_LIB_EXECUTE(msg_sent);
1565 break;
1566 case HDCP_LIB_WKUP_CMD_MSG_SEND_FAILED:
1567 case HDCP_LIB_WKUP_CMD_MSG_RECV_FAILED:
1568 case HDCP_LIB_WKUP_CMD_LINK_FAILED:
1569 handle->hdcp_state |= HDCP_STATE_ERROR;
1570 HDCP_LIB_EXECUTE(clean);
1571 break;
1572 case HDCP_LIB_WKUP_CMD_MSG_RECV_SUCCESS:
1573 HDCP_LIB_EXECUTE(msg_recvd);
1574 break;
1575 case HDCP_LIB_WKUP_CMD_MSG_RECV_TIMEOUT:
1576 HDCP_LIB_EXECUTE(timeout);
1577 break;
1578 case HDCP_LIB_WKUP_CMD_QUERY_STREAM_TYPE:
1579 HDCP_LIB_EXECUTE(stream);
1580 break;
1581 default:
1582 pr_err("invalid wakeup command %d\n", handle->wakeup_cmd);
1583 }
1584exit:
1585 mutex_unlock(&handle->wakeup_mutex);
1586
1587 return rc;
1588}
1589
1590static void hdcp_lib_msg_sent(struct hdcp_lib_handle *handle)
1591{
1592 struct hdcp_wakeup_data cdata = { HDCP_WKUP_CMD_INVALID };
1593
1594 if (!handle) {
1595 pr_err("invalid handle\n");
1596 return;
1597 }
1598
1599 cdata.context = handle->client_ctx;
1600
1601 switch (handle->last_msg_sent) {
1602 case SKE_SEND_TYPE_ID:
1603 if (!hdcp_lib_enable_encryption(handle)) {
1604 handle->authenticated = true;
1605
1606 cdata.cmd = HDCP_WKUP_CMD_STATUS_SUCCESS;
1607 hdcp_lib_wakeup_client(handle, &cdata);
1608 }
1609
1610 /* poll for link check */
1611 cdata.cmd = HDCP_WKUP_CMD_LINK_POLL;
1612 break;
1613 case SKE_SEND_EKS_MESSAGE_ID:
1614 if (handle->repeater_flag) {
1615 /* poll for link check */
1616 cdata.cmd = HDCP_WKUP_CMD_LINK_POLL;
1617 } else {
1618 memset(handle->listener_buf, 0, MAX_TX_MESSAGE_SIZE);
1619 handle->listener_buf[0] = SKE_SEND_TYPE_ID;
1620 handle->msglen = 2;
1621 cdata.cmd = HDCP_WKUP_CMD_SEND_MESSAGE;
1622 cdata.send_msg_buf = handle->listener_buf;
1623 cdata.send_msg_len = handle->msglen;
1624 handle->last_msg = hdcp_lib_get_next_message(handle,
1625 &cdata);
1626 }
1627 break;
1628 case REPEATER_AUTH_SEND_ACK_MESSAGE_ID:
1629 pr_debug("Repeater authentication successful\n");
1630
1631 if (handle->update_stream) {
1632 HDCP_LIB_EXECUTE(stream);
1633 handle->update_stream = false;
1634 } else {
1635 cdata.cmd = HDCP_WKUP_CMD_LINK_POLL;
1636 }
1637 break;
1638 default:
1639 cdata.cmd = HDCP_WKUP_CMD_RECV_MESSAGE;
1640 cdata.timeout = handle->timeout_left;
1641 }
1642
1643 hdcp_lib_wakeup_client(handle, &cdata);
1644}
1645
1646static void hdcp_lib_msg_sent_work(struct kthread_work *work)
1647{
1648 struct hdcp_lib_handle *handle = container_of(work,
1649 struct hdcp_lib_handle,
1650 wk_msg_sent);
1651
1652 if (handle->wakeup_cmd != HDCP_LIB_WKUP_CMD_MSG_SEND_SUCCESS) {
1653 pr_err("invalid wakeup command %d\n", handle->wakeup_cmd);
1654 return;
1655 }
1656
1657 hdcp_lib_msg_sent(handle);
1658}
1659
1660static void hdcp_lib_init(struct hdcp_lib_handle *handle)
1661{
1662 int rc = 0;
1663
1664 if (!handle) {
1665 pr_err("invalid handle\n");
1666 return;
1667 }
1668
1669 if (handle->wakeup_cmd != HDCP_LIB_WKUP_CMD_START) {
1670 pr_err("invalid wakeup command %d\n", handle->wakeup_cmd);
1671 return;
1672 }
1673
1674 rc = hdcp_lib_library_load(handle);
1675 if (rc)
1676 goto exit;
1677
1678 rc = hdcp_lib_session_init(handle);
1679 if (rc)
1680 goto exit;
1681
1682 if (handle->hdcp_txmtr_init == NULL) {
1683 pr_err("invalid txmtr init function pointer\n");
1684 return;
1685 }
1686
1687 rc = handle->hdcp_txmtr_init(handle);
1688 if (rc)
1689 goto exit;
1690
1691 rc = hdcp_lib_start_auth(handle);
1692 if (rc)
1693 goto exit;
1694
1695 hdcp_lib_send_message(handle);
1696
1697 return;
1698exit:
1699 HDCP_LIB_EXECUTE(clean);
1700}
1701
1702static void hdcp_lib_init_work(struct kthread_work *work)
1703{
1704 struct hdcp_lib_handle *handle = container_of(work,
1705 struct hdcp_lib_handle,
1706 wk_init);
1707
1708 hdcp_lib_init(handle);
1709}
1710
1711static void hdcp_lib_timeout(struct hdcp_lib_handle *handle)
1712{
1713 int rc = 0;
1714 struct hdcp_send_timeout_req *req_buf;
1715 struct hdcp_send_timeout_rsp *rsp_buf;
1716
1717 if (!handle || !handle->qseecom_handle ||
1718 !handle->qseecom_handle->sbuf) {
1719 pr_debug("invalid handle\n");
1720 return;
1721 }
1722
1723 if (atomic_read(&handle->hdcp_off)) {
1724 pr_debug("invalid state, hdcp off\n");
1725 return;
1726 }
1727
1728 req_buf = (struct hdcp_send_timeout_req *)
1729 (handle->qseecom_handle->sbuf);
1730 req_buf->commandid = HDCP_TXMTR_SEND_MESSAGE_TIMEOUT;
1731 req_buf->ctxhandle = handle->tz_ctxhandle;
1732
1733 rsp_buf = (struct hdcp_send_timeout_rsp *)
1734 (handle->qseecom_handle->sbuf +
1735 QSEECOM_ALIGN(sizeof(struct hdcp_send_timeout_req)));
1736
1737 rc = qseecom_send_command(handle->qseecom_handle, req_buf,
1738 QSEECOM_ALIGN(sizeof
1739 (struct hdcp_send_timeout_req)),
1740 rsp_buf,
1741 QSEECOM_ALIGN(sizeof
1742 (struct
1743 hdcp_send_timeout_rsp)));
1744
1745 if ((rc < 0) || (rsp_buf->status != HDCP_SUCCESS)) {
1746 pr_err("qseecom cmd failed for with err = %d status = %d\n",
1747 rc, rsp_buf->status);
1748 rc = -EINVAL;
1749 goto error;
1750 }
1751
1752 if (rsp_buf->commandid == HDCP_TXMTR_SEND_MESSAGE_TIMEOUT) {
1753 pr_err("HDCP_TXMTR_SEND_MESSAGE_TIMEOUT\n");
1754 rc = -EINVAL;
1755 goto error;
1756 }
1757
1758 /*
1759 * if the response contains LC_Init message
1760 * send the message again to TZ
1761 */
1762 if ((rsp_buf->commandid == HDCP_TXMTR_PROCESS_RECEIVED_MESSAGE) &&
1763 ((int)rsp_buf->message[0] == LC_INIT_MESSAGE_ID) &&
1764 (rsp_buf->msglen == LC_INIT_MESSAGE_SIZE)) {
1765 if (!atomic_read(&handle->hdcp_off)) {
1766 /* keep local copy of TZ response */
1767 memset(handle->listener_buf, 0, MAX_TX_MESSAGE_SIZE);
1768 memcpy(handle->listener_buf,
1769 (unsigned char *)rsp_buf->message,
1770 rsp_buf->msglen);
1771 handle->hdcp_timeout = rsp_buf->timeout;
1772 handle->msglen = rsp_buf->msglen;
1773
1774 hdcp_lib_send_message(handle);
1775 }
1776 }
1777
1778 return;
1779error:
1780 if (!atomic_read(&handle->hdcp_off))
1781 HDCP_LIB_EXECUTE(clean);
1782}
1783
1784static void hdcp_lib_manage_timeout_work(struct kthread_work *work)
1785{
1786 struct hdcp_lib_handle *handle = container_of(work,
1787 struct hdcp_lib_handle,
1788 wk_timeout);
1789
1790 hdcp_lib_timeout(handle);
1791}
1792
1793static void hdcp_lib_clean(struct hdcp_lib_handle *handle)
1794{
1795 struct hdcp_wakeup_data cdata = { HDCP_WKUP_CMD_INVALID };
1796
1797 if (!handle) {
1798 pr_err("invalid input\n");
1799 return;
1800 }
1801
1802 handle->authenticated = false;
1803
1804 hdcp_lib_txmtr_deinit(handle);
1805 hdcp_lib_session_deinit(handle);
1806 hdcp_lib_library_unload(handle);
1807
1808 cdata.context = handle->client_ctx;
1809 cdata.cmd = HDCP_WKUP_CMD_STATUS_FAILED;
1810
1811 if (!atomic_read(&handle->hdcp_off))
1812 hdcp_lib_wakeup_client(handle, &cdata);
1813
1814 atomic_set(&handle->hdcp_off, 1);
1815}
1816
1817static void hdcp_lib_cleanup_work(struct kthread_work *work)
1818{
1819
1820 struct hdcp_lib_handle *handle = container_of(work,
1821 struct hdcp_lib_handle,
1822 wk_clean);
1823
1824 hdcp_lib_clean(handle);
1825}
1826
1827static void hdcp_lib_msg_recvd(struct hdcp_lib_handle *handle)
1828{
1829 int rc = 0;
1830 struct hdcp_wakeup_data cdata = { HDCP_WKUP_CMD_INVALID };
1831 struct hdcp_rcvd_msg_req *req_buf;
1832 struct hdcp_rcvd_msg_rsp *rsp_buf;
1833 uint32_t msglen;
1834 char *msg = NULL;
1835 char msg_name[50];
1836 uint32_t message_id_bytes = 0;
1837
1838 if (!handle || !handle->qseecom_handle ||
1839 !handle->qseecom_handle->sbuf) {
1840 pr_err("invalid handle\n");
1841 return;
1842 }
1843
1844 if (atomic_read(&handle->hdcp_off)) {
1845 pr_debug("invalid state, hdcp off\n");
1846 return;
1847 }
1848
1849 cdata.context = handle->client_ctx;
1850
1851 mutex_lock(&handle->msg_lock);
1852 msglen = handle->last_msg_recvd_len;
1853
1854 if (msglen <= 0) {
1855 pr_err("invalid msg len\n");
1856 mutex_unlock(&handle->msg_lock);
1857 rc = -EINVAL;
1858 goto exit;
1859 }
1860
1861 /* If the client is DP then allocate extra byte for message ID. */
1862 if (handle->device_type == HDCP_TXMTR_DP)
1863 message_id_bytes = 1;
1864
1865 msglen += message_id_bytes;
1866
1867 msg = kzalloc(msglen, GFP_KERNEL);
1868 if (!msg) {
1869 mutex_unlock(&handle->msg_lock);
1870 rc = -ENOMEM;
1871 goto exit;
1872 }
1873
1874 /* copy the message id if needed */
1875 if (message_id_bytes)
1876 memcpy(msg, &handle->last_msg, message_id_bytes);
1877
1878 memcpy(msg + message_id_bytes,
1879 handle->last_msg_recvd_buf,
1880 handle->last_msg_recvd_len);
1881
1882 mutex_unlock(&handle->msg_lock);
1883
1884 snprintf(msg_name, sizeof(msg_name), "%s: ",
1885 hdcp_lib_message_name((int)msg[0]));
1886
1887 print_hex_dump(KERN_DEBUG, msg_name,
1888 DUMP_PREFIX_NONE, 16, 1, msg, msglen, false);
1889
1890 /* send the message to QSEECOM */
1891 req_buf = (struct hdcp_rcvd_msg_req *)(handle->qseecom_handle->sbuf);
1892 req_buf->commandid = HDCP_TXMTR_PROCESS_RECEIVED_MESSAGE;
1893 memcpy(req_buf->msg, msg, msglen);
1894 req_buf->msglen = msglen;
1895 req_buf->ctxhandle = handle->tz_ctxhandle;
1896
1897 rsp_buf =
1898 (struct hdcp_rcvd_msg_rsp *)(handle->qseecom_handle->sbuf +
1899 QSEECOM_ALIGN(sizeof
1900 (struct
1901 hdcp_rcvd_msg_req)));
1902
1903 pr_debug("writing %s to TZ at %dms\n",
1904 hdcp_lib_message_name((int)msg[0]), jiffies_to_msecs(jiffies));
1905
1906 rc = qseecom_send_command(handle->qseecom_handle, req_buf,
1907 QSEECOM_ALIGN(sizeof
1908 (struct hdcp_rcvd_msg_req)),
1909 rsp_buf,
1910 QSEECOM_ALIGN(sizeof
1911 (struct hdcp_rcvd_msg_rsp)));
1912
1913 /* get next message from sink if we receive H PRIME on no store km */
1914 if ((msg[0] == AKE_SEND_H_PRIME_MESSAGE_ID) &&
1915 handle->no_stored_km_flag) {
1916 handle->hdcp_timeout = rsp_buf->timeout;
1917
1918 cdata.cmd = HDCP_WKUP_CMD_RECV_MESSAGE;
1919 cdata.timeout = handle->hdcp_timeout;
1920
1921 goto exit;
1922 }
1923
1924 if ((msg[0] == REPEATER_AUTH_STREAM_READY_MESSAGE_ID) &&
1925 (rc == 0) && (rsp_buf->status == 0)) {
1926 pr_debug("Got Auth_Stream_Ready, nothing sent to rx\n");
1927
1928 if (!handle->authenticated &&
1929 !hdcp_lib_enable_encryption(handle)) {
1930 handle->authenticated = true;
1931
1932 cdata.cmd = HDCP_WKUP_CMD_STATUS_SUCCESS;
1933 hdcp_lib_wakeup_client(handle, &cdata);
1934 }
1935
1936 cdata.cmd = HDCP_WKUP_CMD_LINK_POLL;
1937 goto exit;
1938 }
1939
1940 if ((rc < 0) || (rsp_buf->status != 0) || (rsp_buf->msglen <= 0) ||
1941 (rsp_buf->commandid != HDCP_TXMTR_PROCESS_RECEIVED_MESSAGE) ||
1942 (rsp_buf->msg == NULL)) {
1943 pr_err("qseecom cmd failed with err=%d status=%d\n",
1944 rc, rsp_buf->status);
1945 rc = -EINVAL;
1946 goto exit;
1947 }
1948
1949 pr_debug("recvd %s from TZ at %dms\n",
1950 hdcp_lib_message_name((int)rsp_buf->msg[0]),
1951 jiffies_to_msecs(jiffies));
1952
1953 handle->last_msg = (int)rsp_buf->msg[0];
1954
1955 /* set the flag if response is AKE_No_Stored_km */
1956 if (((int)rsp_buf->msg[0] == AKE_NO_STORED_KM_MESSAGE_ID)) {
1957 pr_debug("Setting no_stored_km_flag\n");
1958 handle->no_stored_km_flag = 1;
1959 } else {
1960 handle->no_stored_km_flag = 0;
1961 }
1962
1963 /* check if it's a repeater */
1964 if ((rsp_buf->msg[0] == SKE_SEND_EKS_MESSAGE_ID) &&
1965 (rsp_buf->msglen == SKE_SEND_EKS_MESSAGE_SIZE)) {
1966 if ((rsp_buf->flag ==
1967 HDCP_TXMTR_SUBSTATE_WAITING_FOR_RECIEVERID_LIST) &&
1968 (rsp_buf->timeout > 0))
1969 handle->repeater_flag = true;
1970 handle->update_stream = true;
1971 }
1972
1973 memset(handle->listener_buf, 0, MAX_TX_MESSAGE_SIZE);
1974 memcpy(handle->listener_buf, (unsigned char *)rsp_buf->msg,
1975 rsp_buf->msglen);
1976 handle->hdcp_timeout = rsp_buf->timeout;
1977 handle->msglen = rsp_buf->msglen;
1978
1979 if (!atomic_read(&handle->hdcp_off))
1980 hdcp_lib_send_message(handle);
1981exit:
1982 kzfree(msg);
1983
1984 hdcp_lib_wakeup_client(handle, &cdata);
1985
1986 if (rc && !atomic_read(&handle->hdcp_off))
1987 HDCP_LIB_EXECUTE(clean);
1988}
1989
1990static void hdcp_lib_msg_recvd_work(struct kthread_work *work)
1991{
1992 struct hdcp_lib_handle *handle = container_of(work,
1993 struct hdcp_lib_handle,
1994 wk_msg_recvd);
1995
1996 hdcp_lib_msg_recvd(handle);
1997}
1998
1999static void hdcp_lib_wait_work(struct kthread_work *work)
2000{
2001 u32 timeout;
2002 struct hdcp_lib_handle *handle = container_of(work,
2003 struct hdcp_lib_handle, wk_wait);
2004
2005 if (!handle) {
2006 pr_err("invalid input\n");
2007 return;
2008 }
2009
2010 if (atomic_read(&handle->hdcp_off)) {
2011 pr_debug("invalid state: hdcp off\n");
2012 return;
2013 }
2014
2015 if (handle->hdcp_state & HDCP_STATE_ERROR) {
2016 pr_debug("invalid state: hdcp error\n");
2017 return;
2018 }
2019
2020 reinit_completion(&handle->poll_wait);
2021 timeout = wait_for_completion_timeout(&handle->poll_wait,
2022 handle->wait_timeout);
2023 if (!timeout) {
2024 pr_err("wait timeout\n");
2025
2026 if (!atomic_read(&handle->hdcp_off))
2027 HDCP_LIB_EXECUTE(clean);
2028 }
2029
2030 handle->wait_timeout = 0;
2031}
2032
2033bool hdcp1_check_if_supported_load_app(void)
2034{
2035 int rc = 0;
2036
2037 /* start hdcp1 app */
2038 if (hdcp1_supported && !hdcp1_handle) {
2039 rc = qseecom_start_app(&hdcp1_handle, HDCP1_APP_NAME,
2040 QSEECOM_SBUFF_SIZE);
2041 if (rc) {
2042 pr_err("qseecom_start_app failed %d\n", rc);
2043 hdcp1_supported = false;
2044 } else {
2045 mutex_init(&hdcp1_ta_cmd_lock);
2046 }
2047 }
2048
2049 pr_debug("hdcp1 app %s loaded\n",
2050 hdcp1_supported ? "successfully" : "not");
2051
2052 return hdcp1_supported;
2053}
2054
2055/* APIs exposed to all clients */
2056int hdcp1_set_keys(uint32_t *aksv_msb, uint32_t *aksv_lsb)
2057{
2058 int rc = 0;
2059 struct hdcp1_key_set_req *key_set_req;
2060 struct hdcp1_key_set_rsp *key_set_rsp;
2061
2062 if (aksv_msb == NULL || aksv_lsb == NULL)
2063 return -EINVAL;
2064
2065 if (!hdcp1_supported || !hdcp1_handle)
2066 return -EINVAL;
2067
2068 /* set keys and request aksv */
2069 key_set_req = (struct hdcp1_key_set_req *)hdcp1_handle->sbuf;
2070 key_set_req->commandid = HDCP1_SET_KEY_MESSAGE_ID;
2071 key_set_rsp = (struct hdcp1_key_set_rsp *)(hdcp1_handle->sbuf +
2072 QSEECOM_ALIGN(sizeof(struct hdcp1_key_set_req)));
2073 rc = qseecom_send_command(hdcp1_handle, key_set_req,
2074 QSEECOM_ALIGN(sizeof
2075 (struct hdcp1_key_set_req)),
2076 key_set_rsp,
2077 QSEECOM_ALIGN(sizeof
2078 (struct hdcp1_key_set_rsp)));
2079
2080 if (rc < 0) {
2081 pr_err("qseecom cmd failed err=%d\n", rc);
2082 return -ENOKEY;
2083 }
2084
2085 rc = key_set_rsp->ret;
2086 if (rc) {
2087 pr_err("set key cmd failed, rsp=%d\n", key_set_rsp->ret);
2088 return -ENOKEY;
2089 }
2090
2091 /* copy bytes into msb and lsb */
2092 *aksv_msb = key_set_rsp->ksv[0] << 24;
2093 *aksv_msb |= key_set_rsp->ksv[1] << 16;
2094 *aksv_msb |= key_set_rsp->ksv[2] << 8;
2095 *aksv_msb |= key_set_rsp->ksv[3];
2096 *aksv_lsb = key_set_rsp->ksv[4] << 24;
2097 *aksv_lsb |= key_set_rsp->ksv[5] << 16;
2098 *aksv_lsb |= key_set_rsp->ksv[6] << 8;
2099 *aksv_lsb |= key_set_rsp->ksv[7];
2100
2101 return 0;
2102}
2103
2104int hdcp1_set_enc(bool enable)
2105{
2106 int rc = 0;
2107 struct hdcp1_set_enc_req *set_enc_req;
2108 struct hdcp1_set_enc_rsp *set_enc_rsp;
2109
2110 mutex_lock(&hdcp1_ta_cmd_lock);
2111
2112 if (!hdcp1_supported || !hdcp1_handle) {
2113 rc = -EINVAL;
2114 goto end;
2115 }
2116
2117 if (hdcp1_enc_enabled == enable) {
2118 pr_info("already %s\n", enable ? "enabled" : "disabled");
2119 goto end;
2120 }
2121
2122 /* set keys and request aksv */
2123 set_enc_req = (struct hdcp1_set_enc_req *)hdcp1_handle->sbuf;
2124 set_enc_req->commandid = HDCP1_SET_ENC_MESSAGE_ID;
2125 set_enc_req->enable = enable;
2126 set_enc_rsp = (struct hdcp1_set_enc_rsp *)(hdcp1_handle->sbuf +
2127 QSEECOM_ALIGN(sizeof(struct hdcp1_set_enc_req)));
2128 rc = qseecom_send_command(hdcp1_handle, set_enc_req,
2129 QSEECOM_ALIGN(sizeof
2130 (struct hdcp1_set_enc_req)),
2131 set_enc_rsp,
2132 QSEECOM_ALIGN(sizeof
2133 (struct hdcp1_set_enc_rsp)));
2134
2135 if (rc < 0) {
2136 pr_err("qseecom cmd failed err=%d\n", rc);
2137 goto end;
2138 }
2139
2140 rc = set_enc_rsp->ret;
2141 if (rc) {
2142 pr_err("enc cmd failed, rsp=%d\n", set_enc_rsp->ret);
2143 rc = -EINVAL;
2144 goto end;
2145 }
2146
2147 hdcp1_enc_enabled = enable;
2148 pr_info("%s success\n", enable ? "enable" : "disable");
2149end:
2150 mutex_unlock(&hdcp1_ta_cmd_lock);
2151 return rc;
2152}
2153
2154int hdcp_library_register(struct hdcp_register_data *data)
2155{
2156 int rc = 0;
2157 struct hdcp_lib_handle *handle = NULL;
2158
2159 if (!data) {
2160 pr_err("invalid input\n");
2161 return -EINVAL;
2162 }
2163
2164 if (!data->txmtr_ops) {
2165 pr_err("invalid input: txmtr context\n");
2166 return -EINVAL;
2167 }
2168
2169 if (!data->client_ops) {
2170 pr_err("invalid input: client_ops\n");
2171 return -EINVAL;
2172 }
2173
2174 if (!data->hdcp_ctx) {
2175 pr_err("invalid input: hdcp_ctx\n");
2176 return -EINVAL;
2177 }
2178
2179 /* populate ops to be called by client */
2180 data->txmtr_ops->feature_supported = hdcp_lib_client_feature_supported;
2181 data->txmtr_ops->wakeup = hdcp_lib_wakeup_thread;
2182
2183 handle = kzalloc(sizeof(*handle), GFP_KERNEL);
2184 if (!handle) {
2185 rc = -ENOMEM;
2186 goto unlock;
2187 }
2188
2189 handle->client_ctx = data->client_ctx;
2190 handle->client_ops = data->client_ops;
2191 handle->hdcp_app_init = NULL;
2192 handle->hdcp_txmtr_init = NULL;
2193 handle->device_type = data->device_type;
2194
2195 atomic_set(&handle->hdcp_off, 0);
2196
2197 mutex_init(&handle->msg_lock);
2198 mutex_init(&handle->wakeup_mutex);
2199
2200 kthread_init_worker(&handle->worker);
2201
2202 kthread_init_work(&handle->wk_init, hdcp_lib_init_work);
2203 kthread_init_work(&handle->wk_msg_sent, hdcp_lib_msg_sent_work);
2204 kthread_init_work(&handle->wk_msg_recvd, hdcp_lib_msg_recvd_work);
2205 kthread_init_work(&handle->wk_timeout, hdcp_lib_manage_timeout_work);
2206 kthread_init_work(&handle->wk_clean, hdcp_lib_cleanup_work);
2207 kthread_init_work(&handle->wk_wait, hdcp_lib_wait_work);
2208 kthread_init_work(&handle->wk_stream, hdcp_lib_query_stream_work);
2209
2210 init_completion(&handle->poll_wait);
2211
2212 handle->listener_buf = kzalloc(MAX_TX_MESSAGE_SIZE, GFP_KERNEL);
2213 if (!(handle->listener_buf)) {
2214 rc = -ENOMEM;
2215 goto error;
2216 }
2217
2218 *data->hdcp_ctx = handle;
2219 /* Cache the client ctx to be used later
2220 * HDCP driver probe happens earlier than
2221 * SDE driver probe hence caching it to
2222 * be used later.
2223 */
2224
2225 drv_client_handle = handle;
2226 handle->thread = kthread_run(kthread_worker_fn,
2227 &handle->worker, "hdcp_tz_lib");
2228
2229 if (IS_ERR(handle->thread)) {
2230 pr_err("unable to start lib thread\n");
2231 rc = PTR_ERR(handle->thread);
2232 handle->thread = NULL;
2233 goto error;
2234 }
2235
2236 return 0;
2237error:
2238 kzfree(handle->listener_buf);
2239 handle->listener_buf = NULL;
2240 kzfree(handle);
2241 handle = NULL;
2242unlock:
2243 return rc;
2244}
2245EXPORT_SYMBOL(hdcp_library_register);
2246
2247void hdcp_library_deregister(void *phdcpcontext)
2248{
2249 struct hdcp_lib_handle *handle = phdcpcontext;
2250
2251 if (!handle)
2252 return;
2253
2254 kthread_stop(handle->thread);
2255
2256 kzfree(handle->qseecom_handle);
2257 kzfree(handle->last_msg_recvd_buf);
2258
2259 mutex_destroy(&handle->wakeup_mutex);
2260
2261 kzfree(handle->listener_buf);
2262 kzfree(handle);
2263}
2264EXPORT_SYMBOL(hdcp_library_deregister);
2265
2266void hdcp1_notify_topology(void)
2267{
2268 char *envp[4];
2269 char *a;
2270 char *b;
2271
2272 if (!hdcp_drv_mgr) {
2273 pr_err("invalid input\n");
2274 return;
2275 }
2276
2277 a = kzalloc(SZ_16, GFP_KERNEL);
2278
2279 if (!a)
2280 return;
2281
2282 b = kzalloc(SZ_16, GFP_KERNEL);
2283
2284 if (!b) {
2285 kfree(a);
2286 return;
2287 }
2288
2289 envp[0] = "HDCP_MGR_EVENT=MSG_READY";
2290 envp[1] = a;
2291 envp[2] = b;
2292 envp[3] = NULL;
2293
2294 snprintf(envp[1], 16, "%d", (int)DOWN_CHECK_TOPOLOGY);
2295 snprintf(envp[2], 16, "%d", (int)HDCP_V1_TX);
2296
2297 kobject_uevent_env(&hdcp_drv_mgr->device->kobj, KOBJ_CHANGE, envp);
2298 kfree(a);
2299 kfree(b);
2300}
2301
2302static ssize_t msm_hdcp_1x_sysfs_rda_tp(struct device *dev,
2303struct device_attribute *attr, char *buf)
2304{
2305 ssize_t ret = 0;
2306
2307 if (!hdcp_drv_mgr) {
2308 pr_err("invalid input\n");
2309 return -EINVAL;
2310 }
2311
2312 switch (hdcp_drv_mgr->tp_msgid) {
2313 case DOWN_CHECK_TOPOLOGY:
2314 case DOWN_REQUEST_TOPOLOGY:
2315 buf[MSG_ID_IDX] = hdcp_drv_mgr->tp_msgid;
2316 buf[RET_CODE_IDX] = HDCP_AUTHED;
2317 ret = HEADER_LEN;
2318
2319 memcpy(buf + HEADER_LEN, &hdcp_drv_mgr->cached_tp,
2320 sizeof(struct HDCP_V2V1_MSG_TOPOLOGY));
2321
2322 ret += sizeof(struct HDCP_V2V1_MSG_TOPOLOGY);
2323
2324 /* clear the flag once data is read back to user space*/
2325 hdcp_drv_mgr->tp_msgid = -1;
2326 break;
2327 default:
2328 ret = -EINVAL;
2329 }
2330
2331 return ret;
2332}
2333
2334static ssize_t msm_hdcp_1x_sysfs_wta_tp(struct device *dev,
2335 struct device_attribute *attr, const char *buf, size_t count)
2336{
2337 int msgid = 0;
2338 ssize_t ret = count;
2339
2340 if (!hdcp_drv_mgr || !buf) {
2341 pr_err("invalid input\n");
2342 return -EINVAL;
2343 }
2344
2345 msgid = buf[0];
2346
2347 switch (msgid) {
2348 case DOWN_CHECK_TOPOLOGY:
2349 case DOWN_REQUEST_TOPOLOGY:
2350 hdcp_drv_mgr->tp_msgid = msgid;
2351 break;
2352 /* more cases added here */
2353 default:
2354 ret = -EINVAL;
2355 }
2356
2357 return ret;
2358}
2359
2360static ssize_t hdcp2p2_sysfs_wta_min_level_change(struct device *dev,
2361 struct device_attribute *attr, const char *buf, size_t count)
2362{
2363 int rc;
2364 int min_enc_lvl;
2365 struct hdcp_lib_handle *handle;
2366 ssize_t ret = count;
2367
2368 if (!hdcp_drv_mgr) {
2369 pr_err("invalid input\n");
2370 return -EINVAL;
2371 }
2372
2373 handle = hdcp_drv_mgr->handle;
2374
2375 rc = kstrtoint(buf, 10, &min_enc_lvl);
2376 if (rc) {
2377 pr_err("%s: kstrtoint failed. rc=%d\n", __func__, rc);
2378 return -EINVAL;
2379 }
2380
2381 if (handle && handle->client_ops->notify_lvl_change) {
2382 handle->client_ops->notify_lvl_change(handle->client_ctx,
2383 min_enc_lvl);
2384 }
2385
2386 return ret;
2387}
2388
2389static DEVICE_ATTR(tp, 0644, msm_hdcp_1x_sysfs_rda_tp,
2390 msm_hdcp_1x_sysfs_wta_tp);
2391
2392static DEVICE_ATTR(min_level_change, 0200, NULL,
2393 hdcp2p2_sysfs_wta_min_level_change);
2394
2395void hdcp1_cache_repeater_topology(void *hdcp1_cached_tp)
2396{
2397 if (!hdcp_drv_mgr) {
2398 pr_err("invalid input\n");
2399 return;
2400 }
2401
2402 memcpy((void *)&hdcp_drv_mgr->cached_tp,
2403 hdcp1_cached_tp,
2404 sizeof(struct HDCP_V2V1_MSG_TOPOLOGY));
2405}
2406
2407static struct attribute *msm_hdcp_fs_attrs[] = {
2408 &dev_attr_tp.attr,
2409 &dev_attr_min_level_change.attr,
2410 NULL
2411};
2412
2413static struct attribute_group msm_hdcp_fs_attr_group = {
2414 .attrs = msm_hdcp_fs_attrs
2415};
2416
2417static int msm_hdcp_open(struct inode *inode, struct file *file)
2418{
2419 return 0;
2420}
2421
2422static int msm_hdcp_close(struct inode *inode, struct file *file)
2423{
2424 return 0;
2425}
2426
2427static const struct file_operations msm_hdcp_fops = {
2428 .owner = THIS_MODULE,
2429 .open = msm_hdcp_open,
2430 .release = msm_hdcp_close,
2431};
2432
2433static const struct of_device_id msm_hdcp_dt_match[] = {
2434 { .compatible = "qcom,msm-hdcp",},
2435 {}
2436};
2437
2438MODULE_DEVICE_TABLE(of, msm_hdcp_dt_match);
2439
2440static int msm_hdcp_probe(struct platform_device *pdev)
2441{
2442 int ret;
2443
2444 hdcp_drv_mgr = devm_kzalloc(&pdev->dev, sizeof(struct msm_hdcp_mgr),
2445 GFP_KERNEL);
2446 if (!hdcp_drv_mgr)
2447 return -ENOMEM;
2448
2449 hdcp_drv_mgr->pdev = pdev;
2450
2451 platform_set_drvdata(pdev, hdcp_drv_mgr);
2452
2453 ret = alloc_chrdev_region(&hdcp_drv_mgr->dev_num, 0, 1, DRIVER_NAME);
2454 if (ret < 0) {
2455 pr_err("alloc_chrdev_region failed ret = %d\n", ret);
2456 goto error_get_dev_num;
2457 }
2458
2459 hdcp_drv_mgr->class = class_create(THIS_MODULE, CLASS_NAME);
2460 if (IS_ERR(hdcp_drv_mgr->class)) {
2461 ret = PTR_ERR(hdcp_drv_mgr->class);
2462 pr_err("couldn't create class rc = %d\n", ret);
2463 goto error_class_create;
2464 }
2465
2466 hdcp_drv_mgr->device = device_create(hdcp_drv_mgr->class, NULL,
2467 hdcp_drv_mgr->dev_num, NULL, DRIVER_NAME);
2468 if (IS_ERR(hdcp_drv_mgr->device)) {
2469 ret = PTR_ERR(hdcp_drv_mgr->device);
2470 pr_err("device_create failed %d\n", ret);
2471 goto error_class_device_create;
2472 }
2473
2474 cdev_init(&hdcp_drv_mgr->cdev, &msm_hdcp_fops);
2475 ret = cdev_add(&hdcp_drv_mgr->cdev,
2476 MKDEV(MAJOR(hdcp_drv_mgr->dev_num), 0), 1);
2477 if (ret < 0) {
2478 pr_err("cdev_add failed %d\n", ret);
2479 goto error_cdev_add;
2480 }
2481
2482 ret = sysfs_create_group(&hdcp_drv_mgr->device->kobj,
2483 &msm_hdcp_fs_attr_group);
2484 if (ret)
2485 pr_err("unable to register rotator sysfs nodes\n");
2486
2487 /* Store the handle in the hdcp drv mgr
2488 * to be used for the sysfs notifications
2489 */
2490 hdcp_drv_mgr->handle = drv_client_handle;
2491
2492 return 0;
2493error_cdev_add:
2494 device_destroy(hdcp_drv_mgr->class, hdcp_drv_mgr->dev_num);
2495error_class_device_create:
2496 class_destroy(hdcp_drv_mgr->class);
2497error_class_create:
2498 unregister_chrdev_region(hdcp_drv_mgr->dev_num, 1);
2499error_get_dev_num:
2500 devm_kfree(&pdev->dev, hdcp_drv_mgr);
2501 hdcp_drv_mgr = NULL;
2502 return ret;
2503}
2504
2505static int msm_hdcp_remove(struct platform_device *pdev)
2506{
2507 struct msm_hdcp_mgr *mgr;
2508
2509 mgr = (struct msm_hdcp_mgr *)platform_get_drvdata(pdev);
2510 if (!mgr)
2511 return -ENODEV;
2512
2513 sysfs_remove_group(&hdcp_drv_mgr->device->kobj,
2514 &msm_hdcp_fs_attr_group);
2515 cdev_del(&hdcp_drv_mgr->cdev);
2516 device_destroy(hdcp_drv_mgr->class, hdcp_drv_mgr->dev_num);
2517 class_destroy(hdcp_drv_mgr->class);
2518 unregister_chrdev_region(hdcp_drv_mgr->dev_num, 1);
2519
2520 devm_kfree(&pdev->dev, hdcp_drv_mgr);
2521 hdcp_drv_mgr = NULL;
2522 return 0;
2523}
2524
2525static struct platform_driver msm_hdcp_driver = {
2526 .probe = msm_hdcp_probe,
2527 .remove = msm_hdcp_remove,
2528 .driver = {
2529 .name = "msm_hdcp",
2530 .of_match_table = msm_hdcp_dt_match,
2531 .pm = NULL,
2532 }
2533};
2534
2535static int __init msm_hdcp_init(void)
2536{
2537 return platform_driver_register(&msm_hdcp_driver);
2538}
2539
2540static void __exit msm_hdcp_exit(void)
2541{
2542 return platform_driver_unregister(&msm_hdcp_driver);
2543}
2544
2545module_init(msm_hdcp_init);
2546module_exit(msm_hdcp_exit);
2547
2548MODULE_DESCRIPTION("MSM HDCP driver");
2549MODULE_LICENSE("GPL v2");