2 * Copyright 2018 Advanced Micro Devices, Inc.
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 * OTHER DEALINGS IN THE SOFTWARE.
26 #include <linux/delay.h>
30 static inline enum mod_hdcp_status
check_receiver_id_list_ready(struct mod_hdcp
*hdcp
)
35 is_ready
= HDCP_2_2_DP_RXSTATUS_READY(hdcp
->auth
.msg
.hdcp2
.rxstatus_dp
) ? 1 : 0;
37 is_ready
= (HDCP_2_2_HDMI_RXSTATUS_READY(hdcp
->auth
.msg
.hdcp2
.rxstatus
[0]) &&
38 (HDCP_2_2_HDMI_RXSTATUS_MSG_SZ_HI(hdcp
->auth
.msg
.hdcp2
.rxstatus
[1]) << 8 |
39 hdcp
->auth
.msg
.hdcp2
.rxstatus
[0])) ? 1 : 0;
40 return is_ready
? MOD_HDCP_STATUS_SUCCESS
:
41 MOD_HDCP_STATUS_HDCP2_RX_ID_LIST_NOT_READY
;
44 static inline enum mod_hdcp_status
check_hdcp2_capable(struct mod_hdcp
*hdcp
)
46 enum mod_hdcp_status status
;
49 status
= (hdcp
->auth
.msg
.hdcp2
.rxcaps_dp
[2] & HDCP_2_2_RX_CAPS_VERSION_VAL
) &&
50 HDCP_2_2_DP_HDCP_CAPABLE(hdcp
->auth
.msg
.hdcp2
.rxcaps_dp
[0]) ?
51 MOD_HDCP_STATUS_SUCCESS
:
52 MOD_HDCP_STATUS_HDCP2_NOT_CAPABLE
;
54 status
= (hdcp
->auth
.msg
.hdcp2
.hdcp2version_hdmi
& HDCP_2_2_HDMI_SUPPORT_MASK
) ?
55 MOD_HDCP_STATUS_SUCCESS
:
56 MOD_HDCP_STATUS_HDCP2_NOT_CAPABLE
;
60 static inline enum mod_hdcp_status
check_reauthentication_request(
61 struct mod_hdcp
*hdcp
)
66 ret
= HDCP_2_2_DP_RXSTATUS_REAUTH_REQ(hdcp
->auth
.msg
.hdcp2
.rxstatus_dp
) ?
67 MOD_HDCP_STATUS_HDCP2_REAUTH_REQUEST
:
68 MOD_HDCP_STATUS_SUCCESS
;
70 ret
= HDCP_2_2_HDMI_RXSTATUS_REAUTH_REQ(hdcp
->auth
.msg
.hdcp2
.rxstatus
[0]) ?
71 MOD_HDCP_STATUS_HDCP2_REAUTH_REQUEST
:
72 MOD_HDCP_STATUS_SUCCESS
;
76 static inline enum mod_hdcp_status
check_link_integrity_failure_dp(
77 struct mod_hdcp
*hdcp
)
79 return HDCP_2_2_DP_RXSTATUS_LINK_FAILED(hdcp
->auth
.msg
.hdcp2
.rxstatus_dp
) ?
80 MOD_HDCP_STATUS_HDCP2_REAUTH_LINK_INTEGRITY_FAILURE
:
81 MOD_HDCP_STATUS_SUCCESS
;
84 static enum mod_hdcp_status
check_ake_cert_available(struct mod_hdcp
*hdcp
)
86 enum mod_hdcp_status status
;
89 if (is_dp_hdcp(hdcp
)) {
90 status
= MOD_HDCP_STATUS_SUCCESS
;
92 status
= mod_hdcp_read_rxstatus(hdcp
);
93 if (status
== MOD_HDCP_STATUS_SUCCESS
) {
94 size
= HDCP_2_2_HDMI_RXSTATUS_MSG_SZ_HI(hdcp
->auth
.msg
.hdcp2
.rxstatus
[1]) << 8 |
95 hdcp
->auth
.msg
.hdcp2
.rxstatus
[0];
96 status
= (size
== sizeof(hdcp
->auth
.msg
.hdcp2
.ake_cert
)) ?
97 MOD_HDCP_STATUS_SUCCESS
:
98 MOD_HDCP_STATUS_HDCP2_AKE_CERT_PENDING
;
104 static enum mod_hdcp_status
check_h_prime_available(struct mod_hdcp
*hdcp
)
106 enum mod_hdcp_status status
;
109 status
= mod_hdcp_read_rxstatus(hdcp
);
110 if (status
!= MOD_HDCP_STATUS_SUCCESS
)
113 if (is_dp_hdcp(hdcp
)) {
114 status
= HDCP_2_2_DP_RXSTATUS_H_PRIME(hdcp
->auth
.msg
.hdcp2
.rxstatus_dp
) ?
115 MOD_HDCP_STATUS_SUCCESS
:
116 MOD_HDCP_STATUS_HDCP2_H_PRIME_PENDING
;
118 size
= HDCP_2_2_HDMI_RXSTATUS_MSG_SZ_HI(hdcp
->auth
.msg
.hdcp2
.rxstatus
[1]) << 8 |
119 hdcp
->auth
.msg
.hdcp2
.rxstatus
[0];
120 status
= (size
== sizeof(hdcp
->auth
.msg
.hdcp2
.ake_h_prime
)) ?
121 MOD_HDCP_STATUS_SUCCESS
:
122 MOD_HDCP_STATUS_HDCP2_H_PRIME_PENDING
;
128 static enum mod_hdcp_status
check_pairing_info_available(struct mod_hdcp
*hdcp
)
130 enum mod_hdcp_status status
;
133 status
= mod_hdcp_read_rxstatus(hdcp
);
134 if (status
!= MOD_HDCP_STATUS_SUCCESS
)
137 if (is_dp_hdcp(hdcp
)) {
138 status
= HDCP_2_2_DP_RXSTATUS_PAIRING(hdcp
->auth
.msg
.hdcp2
.rxstatus_dp
) ?
139 MOD_HDCP_STATUS_SUCCESS
:
140 MOD_HDCP_STATUS_HDCP2_PAIRING_INFO_PENDING
;
142 size
= HDCP_2_2_HDMI_RXSTATUS_MSG_SZ_HI(hdcp
->auth
.msg
.hdcp2
.rxstatus
[1]) << 8 |
143 hdcp
->auth
.msg
.hdcp2
.rxstatus
[0];
144 status
= (size
== sizeof(hdcp
->auth
.msg
.hdcp2
.ake_pairing_info
)) ?
145 MOD_HDCP_STATUS_SUCCESS
:
146 MOD_HDCP_STATUS_HDCP2_PAIRING_INFO_PENDING
;
152 static enum mod_hdcp_status
poll_l_prime_available(struct mod_hdcp
*hdcp
)
154 enum mod_hdcp_status status
;
156 uint16_t max_wait
= 20; // units of ms
157 uint16_t num_polls
= 5;
158 uint16_t wait_time
= max_wait
/ num_polls
;
160 if (is_dp_hdcp(hdcp
))
161 status
= MOD_HDCP_STATUS_INVALID_OPERATION
;
163 for (; num_polls
; num_polls
--) {
166 status
= mod_hdcp_read_rxstatus(hdcp
);
167 if (status
!= MOD_HDCP_STATUS_SUCCESS
)
170 size
= HDCP_2_2_HDMI_RXSTATUS_MSG_SZ_HI(hdcp
->auth
.msg
.hdcp2
.rxstatus
[1]) << 8 |
171 hdcp
->auth
.msg
.hdcp2
.rxstatus
[0];
172 status
= (size
== sizeof(hdcp
->auth
.msg
.hdcp2
.lc_l_prime
)) ?
173 MOD_HDCP_STATUS_SUCCESS
:
174 MOD_HDCP_STATUS_HDCP2_L_PRIME_PENDING
;
175 if (status
== MOD_HDCP_STATUS_SUCCESS
)
181 static enum mod_hdcp_status
check_stream_ready_available(struct mod_hdcp
*hdcp
)
183 enum mod_hdcp_status status
;
186 if (is_dp_hdcp(hdcp
)) {
187 status
= MOD_HDCP_STATUS_INVALID_OPERATION
;
189 status
= mod_hdcp_read_rxstatus(hdcp
);
190 if (status
!= MOD_HDCP_STATUS_SUCCESS
)
192 size
= HDCP_2_2_HDMI_RXSTATUS_MSG_SZ_HI(hdcp
->auth
.msg
.hdcp2
.rxstatus
[1]) << 8 |
193 hdcp
->auth
.msg
.hdcp2
.rxstatus
[0];
194 status
= (size
== sizeof(hdcp
->auth
.msg
.hdcp2
.repeater_auth_stream_ready
)) ?
195 MOD_HDCP_STATUS_SUCCESS
:
196 MOD_HDCP_STATUS_HDCP2_STREAM_READY_PENDING
;
202 static inline uint8_t get_device_count(struct mod_hdcp
*hdcp
)
204 return HDCP_2_2_DEV_COUNT_LO(hdcp
->auth
.msg
.hdcp2
.rx_id_list
[2]) +
205 (HDCP_2_2_DEV_COUNT_HI(hdcp
->auth
.msg
.hdcp2
.rx_id_list
[1]) << 4);
208 static enum mod_hdcp_status
check_device_count(struct mod_hdcp
*hdcp
)
210 /* device count must be greater than or equal to tracked hdcp displays */
211 return (get_device_count(hdcp
) < get_added_display_count(hdcp
)) ?
212 MOD_HDCP_STATUS_HDCP2_DEVICE_COUNT_MISMATCH_FAILURE
:
213 MOD_HDCP_STATUS_SUCCESS
;
216 static uint8_t process_rxstatus(struct mod_hdcp
*hdcp
,
217 struct mod_hdcp_event_context
*event_ctx
,
218 struct mod_hdcp_transition_input_hdcp2
*input
,
219 enum mod_hdcp_status
*status
)
221 if (!mod_hdcp_execute_and_set(mod_hdcp_read_rxstatus
,
222 &input
->rxstatus_read
, status
,
223 hdcp
, "rxstatus_read"))
225 if (!mod_hdcp_execute_and_set(check_reauthentication_request
,
226 &input
->reauth_request_check
, status
,
227 hdcp
, "reauth_request_check"))
229 if (is_dp_hdcp(hdcp
)) {
230 if (!mod_hdcp_execute_and_set(check_link_integrity_failure_dp
,
231 &input
->link_integrity_check_dp
, status
,
232 hdcp
, "link_integrity_check_dp"))
235 if (hdcp
->connection
.is_repeater
)
236 if (check_receiver_id_list_ready(hdcp
) ==
237 MOD_HDCP_STATUS_SUCCESS
) {
238 HDCP_INPUT_PASS_TRACE(hdcp
, "rx_id_list_ready");
239 event_ctx
->rx_id_list_ready
= 1;
240 if (is_dp_hdcp(hdcp
))
241 hdcp
->auth
.msg
.hdcp2
.rx_id_list_size
=
242 sizeof(hdcp
->auth
.msg
.hdcp2
.rx_id_list
);
244 hdcp
->auth
.msg
.hdcp2
.rx_id_list_size
=
245 HDCP_2_2_HDMI_RXSTATUS_MSG_SZ_HI(hdcp
->auth
.msg
.hdcp2
.rxstatus
[1]) << 8 |
246 hdcp
->auth
.msg
.hdcp2
.rxstatus
[0];
249 return (*status
== MOD_HDCP_STATUS_SUCCESS
);
252 static enum mod_hdcp_status
known_hdcp2_capable_rx(struct mod_hdcp
*hdcp
,
253 struct mod_hdcp_event_context
*event_ctx
,
254 struct mod_hdcp_transition_input_hdcp2
*input
)
256 enum mod_hdcp_status status
= MOD_HDCP_STATUS_SUCCESS
;
258 if (event_ctx
->event
!= MOD_HDCP_EVENT_CALLBACK
) {
259 event_ctx
->unexpected_event
= 1;
262 if (!mod_hdcp_execute_and_set(mod_hdcp_read_hdcp2version
,
263 &input
->hdcp2version_read
, &status
,
264 hdcp
, "hdcp2version_read"))
266 if (!mod_hdcp_execute_and_set(check_hdcp2_capable
,
267 &input
->hdcp2_capable_check
, &status
,
268 hdcp
, "hdcp2_capable"))
274 static enum mod_hdcp_status
send_ake_init(struct mod_hdcp
*hdcp
,
275 struct mod_hdcp_event_context
*event_ctx
,
276 struct mod_hdcp_transition_input_hdcp2
*input
)
278 enum mod_hdcp_status status
= MOD_HDCP_STATUS_SUCCESS
;
280 if (event_ctx
->event
!= MOD_HDCP_EVENT_CALLBACK
) {
281 event_ctx
->unexpected_event
= 1;
284 if (!mod_hdcp_execute_and_set(mod_hdcp_add_display_topology
,
285 &input
->add_topology
, &status
,
286 hdcp
, "add_topology"))
288 if (!mod_hdcp_execute_and_set(mod_hdcp_hdcp2_create_session
,
289 &input
->create_session
, &status
,
290 hdcp
, "create_session"))
292 if (!mod_hdcp_execute_and_set(mod_hdcp_hdcp2_prepare_ake_init
,
293 &input
->ake_init_prepare
, &status
,
294 hdcp
, "ake_init_prepare"))
296 if (!mod_hdcp_execute_and_set(mod_hdcp_write_ake_init
,
297 &input
->ake_init_write
, &status
,
298 hdcp
, "ake_init_write"))
304 static enum mod_hdcp_status
validate_ake_cert(struct mod_hdcp
*hdcp
,
305 struct mod_hdcp_event_context
*event_ctx
,
306 struct mod_hdcp_transition_input_hdcp2
*input
)
308 enum mod_hdcp_status status
= MOD_HDCP_STATUS_SUCCESS
;
311 if (event_ctx
->event
!= MOD_HDCP_EVENT_CALLBACK
&&
312 event_ctx
->event
!= MOD_HDCP_EVENT_WATCHDOG_TIMEOUT
) {
313 event_ctx
->unexpected_event
= 1;
317 if (is_hdmi_dvi_sl_hdcp(hdcp
))
318 if (!mod_hdcp_execute_and_set(check_ake_cert_available
,
319 &input
->ake_cert_available
, &status
,
320 hdcp
, "ake_cert_available"))
322 if (!mod_hdcp_execute_and_set(mod_hdcp_read_ake_cert
,
323 &input
->ake_cert_read
, &status
,
324 hdcp
, "ake_cert_read"))
326 if (!mod_hdcp_execute_and_set(mod_hdcp_hdcp2_validate_ake_cert
,
327 &input
->ake_cert_validation
, &status
,
328 hdcp
, "ake_cert_validation"))
334 static enum mod_hdcp_status
send_no_stored_km(struct mod_hdcp
*hdcp
,
335 struct mod_hdcp_event_context
*event_ctx
,
336 struct mod_hdcp_transition_input_hdcp2
*input
)
338 enum mod_hdcp_status status
= MOD_HDCP_STATUS_SUCCESS
;
340 if (event_ctx
->event
!= MOD_HDCP_EVENT_CALLBACK
) {
341 event_ctx
->unexpected_event
= 1;
345 if (!mod_hdcp_execute_and_set(mod_hdcp_write_no_stored_km
,
346 &input
->no_stored_km_write
, &status
,
347 hdcp
, "no_stored_km_write"))
353 static enum mod_hdcp_status
read_h_prime(struct mod_hdcp
*hdcp
,
354 struct mod_hdcp_event_context
*event_ctx
,
355 struct mod_hdcp_transition_input_hdcp2
*input
)
357 enum mod_hdcp_status status
= MOD_HDCP_STATUS_SUCCESS
;
359 if (event_ctx
->event
!= MOD_HDCP_EVENT_CALLBACK
&&
360 event_ctx
->event
!= MOD_HDCP_EVENT_CPIRQ
&&
361 event_ctx
->event
!= MOD_HDCP_EVENT_WATCHDOG_TIMEOUT
) {
362 event_ctx
->unexpected_event
= 1;
366 if (!mod_hdcp_execute_and_set(check_h_prime_available
,
367 &input
->h_prime_available
, &status
,
368 hdcp
, "h_prime_available"))
371 if (!mod_hdcp_execute_and_set(mod_hdcp_read_h_prime
,
372 &input
->h_prime_read
, &status
,
373 hdcp
, "h_prime_read"))
379 static enum mod_hdcp_status
read_pairing_info_and_validate_h_prime(
380 struct mod_hdcp
*hdcp
,
381 struct mod_hdcp_event_context
*event_ctx
,
382 struct mod_hdcp_transition_input_hdcp2
*input
)
384 enum mod_hdcp_status status
= MOD_HDCP_STATUS_SUCCESS
;
386 if (event_ctx
->event
!= MOD_HDCP_EVENT_CALLBACK
&&
387 event_ctx
->event
!= MOD_HDCP_EVENT_CPIRQ
&&
388 event_ctx
->event
!= MOD_HDCP_EVENT_WATCHDOG_TIMEOUT
) {
389 event_ctx
->unexpected_event
= 1;
393 if (!mod_hdcp_execute_and_set(check_pairing_info_available
,
394 &input
->pairing_available
, &status
,
395 hdcp
, "pairing_available"))
397 if (!mod_hdcp_execute_and_set(mod_hdcp_read_pairing_info
,
398 &input
->pairing_info_read
, &status
,
399 hdcp
, "pairing_info_read"))
401 if (!mod_hdcp_execute_and_set(mod_hdcp_hdcp2_validate_h_prime
,
402 &input
->h_prime_validation
, &status
,
403 hdcp
, "h_prime_validation"))
409 static enum mod_hdcp_status
send_stored_km(struct mod_hdcp
*hdcp
,
410 struct mod_hdcp_event_context
*event_ctx
,
411 struct mod_hdcp_transition_input_hdcp2
*input
)
413 enum mod_hdcp_status status
= MOD_HDCP_STATUS_SUCCESS
;
415 if (event_ctx
->event
!= MOD_HDCP_EVENT_CALLBACK
) {
416 event_ctx
->unexpected_event
= 1;
420 if (!mod_hdcp_execute_and_set(mod_hdcp_write_stored_km
,
421 &input
->stored_km_write
, &status
,
422 hdcp
, "stored_km_write"))
428 static enum mod_hdcp_status
validate_h_prime(struct mod_hdcp
*hdcp
,
429 struct mod_hdcp_event_context
*event_ctx
,
430 struct mod_hdcp_transition_input_hdcp2
*input
)
432 enum mod_hdcp_status status
= MOD_HDCP_STATUS_SUCCESS
;
434 if (event_ctx
->event
!= MOD_HDCP_EVENT_CALLBACK
&&
435 event_ctx
->event
!= MOD_HDCP_EVENT_CPIRQ
&&
436 event_ctx
->event
!= MOD_HDCP_EVENT_WATCHDOG_TIMEOUT
) {
437 event_ctx
->unexpected_event
= 1;
441 if (!mod_hdcp_execute_and_set(check_h_prime_available
,
442 &input
->h_prime_available
, &status
,
443 hdcp
, "h_prime_available"))
445 if (!mod_hdcp_execute_and_set(mod_hdcp_read_h_prime
,
446 &input
->h_prime_read
, &status
,
447 hdcp
, "h_prime_read"))
449 if (!mod_hdcp_execute_and_set(mod_hdcp_hdcp2_validate_h_prime
,
450 &input
->h_prime_validation
, &status
,
451 hdcp
, "h_prime_validation"))
457 static enum mod_hdcp_status
locality_check(struct mod_hdcp
*hdcp
,
458 struct mod_hdcp_event_context
*event_ctx
,
459 struct mod_hdcp_transition_input_hdcp2
*input
)
461 enum mod_hdcp_status status
= MOD_HDCP_STATUS_SUCCESS
;
463 if (event_ctx
->event
!= MOD_HDCP_EVENT_CALLBACK
) {
464 event_ctx
->unexpected_event
= 1;
468 if (!mod_hdcp_execute_and_set(mod_hdcp_hdcp2_prepare_lc_init
,
469 &input
->lc_init_prepare
, &status
,
470 hdcp
, "lc_init_prepare"))
472 if (!mod_hdcp_execute_and_set(mod_hdcp_write_lc_init
,
473 &input
->lc_init_write
, &status
,
474 hdcp
, "lc_init_write"))
476 if (is_dp_hdcp(hdcp
))
479 if (!mod_hdcp_execute_and_set(poll_l_prime_available
,
480 &input
->l_prime_available_poll
, &status
,
481 hdcp
, "l_prime_available_poll"))
483 if (!mod_hdcp_execute_and_set(mod_hdcp_read_l_prime
,
484 &input
->l_prime_read
, &status
,
485 hdcp
, "l_prime_read"))
487 if (!mod_hdcp_execute_and_set(mod_hdcp_hdcp2_validate_l_prime
,
488 &input
->l_prime_validation
, &status
,
489 hdcp
, "l_prime_validation"))
495 static enum mod_hdcp_status
exchange_ks_and_test_for_repeater(struct mod_hdcp
*hdcp
,
496 struct mod_hdcp_event_context
*event_ctx
,
497 struct mod_hdcp_transition_input_hdcp2
*input
)
499 enum mod_hdcp_status status
= MOD_HDCP_STATUS_SUCCESS
;
501 if (event_ctx
->event
!= MOD_HDCP_EVENT_CALLBACK
) {
502 event_ctx
->unexpected_event
= 1;
506 if (!mod_hdcp_execute_and_set(mod_hdcp_hdcp2_prepare_eks
,
507 &input
->eks_prepare
, &status
,
508 hdcp
, "eks_prepare"))
510 if (!mod_hdcp_execute_and_set(mod_hdcp_write_eks
,
511 &input
->eks_write
, &status
,
518 static enum mod_hdcp_status
enable_encryption(struct mod_hdcp
*hdcp
,
519 struct mod_hdcp_event_context
*event_ctx
,
520 struct mod_hdcp_transition_input_hdcp2
*input
)
522 enum mod_hdcp_status status
= MOD_HDCP_STATUS_SUCCESS
;
524 if (event_ctx
->event
!= MOD_HDCP_EVENT_CALLBACK
&&
525 event_ctx
->event
!= MOD_HDCP_EVENT_CPIRQ
) {
526 event_ctx
->unexpected_event
= 1;
529 if (event_ctx
->event
== MOD_HDCP_EVENT_CPIRQ
) {
530 process_rxstatus(hdcp
, event_ctx
, input
, &status
);
534 if (is_hdmi_dvi_sl_hdcp(hdcp
)) {
535 if (!process_rxstatus(hdcp
, event_ctx
, input
, &status
))
537 if (event_ctx
->rx_id_list_ready
)
540 if (!mod_hdcp_execute_and_set(mod_hdcp_hdcp2_enable_encryption
,
541 &input
->enable_encryption
, &status
,
542 hdcp
, "enable_encryption"))
544 if (is_dp_mst_hdcp(hdcp
)) {
545 if (!mod_hdcp_execute_and_set(
546 mod_hdcp_hdcp2_enable_dp_stream_encryption
,
547 &input
->stream_encryption_dp
, &status
,
548 hdcp
, "stream_encryption_dp"))
555 static enum mod_hdcp_status
authenticated(struct mod_hdcp
*hdcp
,
556 struct mod_hdcp_event_context
*event_ctx
,
557 struct mod_hdcp_transition_input_hdcp2
*input
)
559 enum mod_hdcp_status status
= MOD_HDCP_STATUS_SUCCESS
;
561 if (event_ctx
->event
!= MOD_HDCP_EVENT_CALLBACK
&&
562 event_ctx
->event
!= MOD_HDCP_EVENT_CPIRQ
) {
563 event_ctx
->unexpected_event
= 1;
567 if (!process_rxstatus(hdcp
, event_ctx
, input
, &status
))
569 if (event_ctx
->rx_id_list_ready
)
575 static enum mod_hdcp_status
wait_for_rx_id_list(struct mod_hdcp
*hdcp
,
576 struct mod_hdcp_event_context
*event_ctx
,
577 struct mod_hdcp_transition_input_hdcp2
*input
)
579 enum mod_hdcp_status status
= MOD_HDCP_STATUS_SUCCESS
;
581 if (event_ctx
->event
!= MOD_HDCP_EVENT_CALLBACK
&&
582 event_ctx
->event
!= MOD_HDCP_EVENT_CPIRQ
&&
583 event_ctx
->event
!= MOD_HDCP_EVENT_WATCHDOG_TIMEOUT
) {
584 event_ctx
->unexpected_event
= 1;
588 if (!process_rxstatus(hdcp
, event_ctx
, input
, &status
))
590 if (!event_ctx
->rx_id_list_ready
) {
591 status
= MOD_HDCP_STATUS_HDCP2_RX_ID_LIST_NOT_READY
;
598 static enum mod_hdcp_status
verify_rx_id_list_and_send_ack(struct mod_hdcp
*hdcp
,
599 struct mod_hdcp_event_context
*event_ctx
,
600 struct mod_hdcp_transition_input_hdcp2
*input
)
602 enum mod_hdcp_status status
= MOD_HDCP_STATUS_SUCCESS
;
604 if (event_ctx
->event
!= MOD_HDCP_EVENT_CALLBACK
&&
605 event_ctx
->event
!= MOD_HDCP_EVENT_CPIRQ
) {
606 event_ctx
->unexpected_event
= 1;
609 if (event_ctx
->event
== MOD_HDCP_EVENT_CPIRQ
) {
610 process_rxstatus(hdcp
, event_ctx
, input
, &status
);
614 if (!mod_hdcp_execute_and_set(mod_hdcp_read_rx_id_list
,
615 &input
->rx_id_list_read
,
616 &status
, hdcp
, "receiver_id_list_read"))
618 if (!mod_hdcp_execute_and_set(check_device_count
,
619 &input
->device_count_check
,
620 &status
, hdcp
, "device_count_check"))
622 if (!mod_hdcp_execute_and_set(mod_hdcp_hdcp2_validate_rx_id_list
,
623 &input
->rx_id_list_validation
,
624 &status
, hdcp
, "rx_id_list_validation"))
626 if (!mod_hdcp_execute_and_set(mod_hdcp_write_repeater_auth_ack
,
627 &input
->repeater_auth_ack_write
,
628 &status
, hdcp
, "repeater_auth_ack_write"))
634 static enum mod_hdcp_status
send_stream_management(struct mod_hdcp
*hdcp
,
635 struct mod_hdcp_event_context
*event_ctx
,
636 struct mod_hdcp_transition_input_hdcp2
*input
)
638 enum mod_hdcp_status status
= MOD_HDCP_STATUS_SUCCESS
;
640 if (event_ctx
->event
!= MOD_HDCP_EVENT_CALLBACK
&&
641 event_ctx
->event
!= MOD_HDCP_EVENT_CPIRQ
) {
642 event_ctx
->unexpected_event
= 1;
645 if (event_ctx
->event
== MOD_HDCP_EVENT_CPIRQ
) {
646 process_rxstatus(hdcp
, event_ctx
, input
, &status
);
650 if (is_hdmi_dvi_sl_hdcp(hdcp
)) {
651 if (!process_rxstatus(hdcp
, event_ctx
, input
, &status
))
653 if (event_ctx
->rx_id_list_ready
)
656 if (!mod_hdcp_execute_and_set(mod_hdcp_hdcp2_prepare_stream_management
,
657 &input
->prepare_stream_manage
,
658 &status
, hdcp
, "prepare_stream_manage"))
661 if (!mod_hdcp_execute_and_set(mod_hdcp_write_stream_manage
,
662 &input
->stream_manage_write
,
663 &status
, hdcp
, "stream_manage_write"))
669 static enum mod_hdcp_status
validate_stream_ready(struct mod_hdcp
*hdcp
,
670 struct mod_hdcp_event_context
*event_ctx
,
671 struct mod_hdcp_transition_input_hdcp2
*input
)
673 enum mod_hdcp_status status
= MOD_HDCP_STATUS_SUCCESS
;
675 if (event_ctx
->event
!= MOD_HDCP_EVENT_CALLBACK
&&
676 event_ctx
->event
!= MOD_HDCP_EVENT_CPIRQ
&&
677 event_ctx
->event
!= MOD_HDCP_EVENT_WATCHDOG_TIMEOUT
) {
678 event_ctx
->unexpected_event
= 1;
681 if (event_ctx
->event
== MOD_HDCP_EVENT_CPIRQ
) {
682 process_rxstatus(hdcp
, event_ctx
, input
, &status
);
686 if (is_hdmi_dvi_sl_hdcp(hdcp
)) {
687 if (!process_rxstatus(hdcp
, event_ctx
, input
, &status
))
689 if (event_ctx
->rx_id_list_ready
) {
693 if (is_hdmi_dvi_sl_hdcp(hdcp
))
694 if (!mod_hdcp_execute_and_set(check_stream_ready_available
,
695 &input
->stream_ready_available
,
696 &status
, hdcp
, "stream_ready_available"))
698 if (!mod_hdcp_execute_and_set(mod_hdcp_read_stream_ready
,
699 &input
->stream_ready_read
,
700 &status
, hdcp
, "stream_ready_read"))
702 if (!mod_hdcp_execute_and_set(mod_hdcp_hdcp2_validate_stream_ready
,
703 &input
->stream_ready_validation
,
704 &status
, hdcp
, "stream_ready_validation"))
711 static enum mod_hdcp_status
determine_rx_hdcp_capable_dp(struct mod_hdcp
*hdcp
,
712 struct mod_hdcp_event_context
*event_ctx
,
713 struct mod_hdcp_transition_input_hdcp2
*input
)
715 enum mod_hdcp_status status
= MOD_HDCP_STATUS_SUCCESS
;
717 if (event_ctx
->event
!= MOD_HDCP_EVENT_CALLBACK
) {
718 event_ctx
->unexpected_event
= 1;
722 if (!mod_hdcp_execute_and_set(mod_hdcp_read_rxcaps
,
723 &input
->rx_caps_read_dp
,
724 &status
, hdcp
, "rx_caps_read_dp"))
726 if (!mod_hdcp_execute_and_set(check_hdcp2_capable
,
727 &input
->hdcp2_capable_check
, &status
,
728 hdcp
, "hdcp2_capable_check"))
734 static enum mod_hdcp_status
send_content_stream_type_dp(struct mod_hdcp
*hdcp
,
735 struct mod_hdcp_event_context
*event_ctx
,
736 struct mod_hdcp_transition_input_hdcp2
*input
)
738 enum mod_hdcp_status status
= MOD_HDCP_STATUS_SUCCESS
;
740 if (event_ctx
->event
!= MOD_HDCP_EVENT_CALLBACK
&&
741 event_ctx
->event
!= MOD_HDCP_EVENT_CPIRQ
) {
742 event_ctx
->unexpected_event
= 1;
746 if (!process_rxstatus(hdcp
, event_ctx
, input
, &status
))
748 if (!mod_hdcp_execute_and_set(mod_hdcp_write_content_type
,
749 &input
->content_stream_type_write
, &status
,
750 hdcp
, "content_stream_type_write"))
756 enum mod_hdcp_status
mod_hdcp_hdcp2_execution(struct mod_hdcp
*hdcp
,
757 struct mod_hdcp_event_context
*event_ctx
,
758 struct mod_hdcp_transition_input_hdcp2
*input
)
760 enum mod_hdcp_status status
= MOD_HDCP_STATUS_SUCCESS
;
762 switch (current_state(hdcp
)) {
763 case H2_A0_KNOWN_HDCP2_CAPABLE_RX
:
764 status
= known_hdcp2_capable_rx(hdcp
, event_ctx
, input
);
766 case H2_A1_SEND_AKE_INIT
:
767 status
= send_ake_init(hdcp
, event_ctx
, input
);
769 case H2_A1_VALIDATE_AKE_CERT
:
770 status
= validate_ake_cert(hdcp
, event_ctx
, input
);
772 case H2_A1_SEND_NO_STORED_KM
:
773 status
= send_no_stored_km(hdcp
, event_ctx
, input
);
775 case H2_A1_READ_H_PRIME
:
776 status
= read_h_prime(hdcp
, event_ctx
, input
);
778 case H2_A1_READ_PAIRING_INFO_AND_VALIDATE_H_PRIME
:
779 status
= read_pairing_info_and_validate_h_prime(hdcp
,
782 case H2_A1_SEND_STORED_KM
:
783 status
= send_stored_km(hdcp
, event_ctx
, input
);
785 case H2_A1_VALIDATE_H_PRIME
:
786 status
= validate_h_prime(hdcp
, event_ctx
, input
);
788 case H2_A2_LOCALITY_CHECK
:
789 status
= locality_check(hdcp
, event_ctx
, input
);
791 case H2_A3_EXCHANGE_KS_AND_TEST_FOR_REPEATER
:
792 status
= exchange_ks_and_test_for_repeater(hdcp
, event_ctx
, input
);
794 case H2_ENABLE_ENCRYPTION
:
795 status
= enable_encryption(hdcp
, event_ctx
, input
);
797 case H2_A5_AUTHENTICATED
:
798 status
= authenticated(hdcp
, event_ctx
, input
);
800 case H2_A6_WAIT_FOR_RX_ID_LIST
:
801 status
= wait_for_rx_id_list(hdcp
, event_ctx
, input
);
803 case H2_A78_VERIFY_RX_ID_LIST_AND_SEND_ACK
:
804 status
= verify_rx_id_list_and_send_ack(hdcp
, event_ctx
, input
);
806 case H2_A9_SEND_STREAM_MANAGEMENT
:
807 status
= send_stream_management(hdcp
, event_ctx
, input
);
809 case H2_A9_VALIDATE_STREAM_READY
:
810 status
= validate_stream_ready(hdcp
, event_ctx
, input
);
813 status
= MOD_HDCP_STATUS_INVALID_STATE
;
820 enum mod_hdcp_status
mod_hdcp_hdcp2_dp_execution(struct mod_hdcp
*hdcp
,
821 struct mod_hdcp_event_context
*event_ctx
,
822 struct mod_hdcp_transition_input_hdcp2
*input
)
824 enum mod_hdcp_status status
= MOD_HDCP_STATUS_SUCCESS
;
826 switch (current_state(hdcp
)) {
827 case D2_A0_DETERMINE_RX_HDCP_CAPABLE
:
828 status
= determine_rx_hdcp_capable_dp(hdcp
, event_ctx
, input
);
830 case D2_A1_SEND_AKE_INIT
:
831 status
= send_ake_init(hdcp
, event_ctx
, input
);
833 case D2_A1_VALIDATE_AKE_CERT
:
834 status
= validate_ake_cert(hdcp
, event_ctx
, input
);
836 case D2_A1_SEND_NO_STORED_KM
:
837 status
= send_no_stored_km(hdcp
, event_ctx
, input
);
839 case D2_A1_READ_H_PRIME
:
840 status
= read_h_prime(hdcp
, event_ctx
, input
);
842 case D2_A1_READ_PAIRING_INFO_AND_VALIDATE_H_PRIME
:
843 status
= read_pairing_info_and_validate_h_prime(hdcp
,
846 case D2_A1_SEND_STORED_KM
:
847 status
= send_stored_km(hdcp
, event_ctx
, input
);
849 case D2_A1_VALIDATE_H_PRIME
:
850 status
= validate_h_prime(hdcp
, event_ctx
, input
);
852 case D2_A2_LOCALITY_CHECK
:
853 status
= locality_check(hdcp
, event_ctx
, input
);
855 case D2_A34_EXCHANGE_KS_AND_TEST_FOR_REPEATER
:
856 status
= exchange_ks_and_test_for_repeater(hdcp
,
859 case D2_SEND_CONTENT_STREAM_TYPE
:
860 status
= send_content_stream_type_dp(hdcp
, event_ctx
, input
);
862 case D2_ENABLE_ENCRYPTION
:
863 status
= enable_encryption(hdcp
, event_ctx
, input
);
865 case D2_A5_AUTHENTICATED
:
866 status
= authenticated(hdcp
, event_ctx
, input
);
868 case D2_A6_WAIT_FOR_RX_ID_LIST
:
869 status
= wait_for_rx_id_list(hdcp
, event_ctx
, input
);
871 case D2_A78_VERIFY_RX_ID_LIST_AND_SEND_ACK
:
872 status
= verify_rx_id_list_and_send_ack(hdcp
, event_ctx
, input
);
874 case D2_A9_SEND_STREAM_MANAGEMENT
:
875 status
= send_stream_management(hdcp
, event_ctx
, input
);
877 case D2_A9_VALIDATE_STREAM_READY
:
878 status
= validate_stream_ready(hdcp
, event_ctx
, input
);
881 status
= MOD_HDCP_STATUS_INVALID_STATE
;