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 uint16_t get_hdmi_rxstatus_msg_size(const uint8_t rxstatus[2])
32 return HDCP_2_2_HDMI_RXSTATUS_MSG_SZ_HI(rxstatus[1]) << 8 | rxstatus[0];
35 static inline enum mod_hdcp_status check_receiver_id_list_ready(struct mod_hdcp *hdcp)
40 is_ready = HDCP_2_2_DP_RXSTATUS_READY(hdcp->auth.msg.hdcp2.rxstatus_dp) ? 1 : 0;
42 is_ready = (HDCP_2_2_HDMI_RXSTATUS_READY(hdcp->auth.msg.hdcp2.rxstatus[1]) &&
43 get_hdmi_rxstatus_msg_size(hdcp->auth.msg.hdcp2.rxstatus) != 0) ? 1 : 0;
44 return is_ready ? MOD_HDCP_STATUS_SUCCESS :
45 MOD_HDCP_STATUS_HDCP2_RX_ID_LIST_NOT_READY;
48 static inline enum mod_hdcp_status check_hdcp2_capable(struct mod_hdcp *hdcp)
50 enum mod_hdcp_status status;
53 status = (hdcp->auth.msg.hdcp2.rxcaps_dp[0] == HDCP_2_2_RX_CAPS_VERSION_VAL) &&
54 HDCP_2_2_DP_HDCP_CAPABLE(hdcp->auth.msg.hdcp2.rxcaps_dp[2]) ?
55 MOD_HDCP_STATUS_SUCCESS :
56 MOD_HDCP_STATUS_HDCP2_NOT_CAPABLE;
58 status = (hdcp->auth.msg.hdcp2.hdcp2version_hdmi & HDCP_2_2_HDMI_SUPPORT_MASK) ?
59 MOD_HDCP_STATUS_SUCCESS :
60 MOD_HDCP_STATUS_HDCP2_NOT_CAPABLE;
64 static inline enum mod_hdcp_status check_reauthentication_request(
65 struct mod_hdcp *hdcp)
70 ret = HDCP_2_2_DP_RXSTATUS_REAUTH_REQ(hdcp->auth.msg.hdcp2.rxstatus_dp) ?
71 MOD_HDCP_STATUS_HDCP2_REAUTH_REQUEST :
72 MOD_HDCP_STATUS_SUCCESS;
74 ret = HDCP_2_2_HDMI_RXSTATUS_REAUTH_REQ(hdcp->auth.msg.hdcp2.rxstatus[1]) ?
75 MOD_HDCP_STATUS_HDCP2_REAUTH_REQUEST :
76 MOD_HDCP_STATUS_SUCCESS;
80 static inline enum mod_hdcp_status check_link_integrity_failure_dp(
81 struct mod_hdcp *hdcp)
83 return HDCP_2_2_DP_RXSTATUS_LINK_FAILED(hdcp->auth.msg.hdcp2.rxstatus_dp) ?
84 MOD_HDCP_STATUS_HDCP2_REAUTH_LINK_INTEGRITY_FAILURE :
85 MOD_HDCP_STATUS_SUCCESS;
88 static enum mod_hdcp_status check_ake_cert_available(struct mod_hdcp *hdcp)
90 enum mod_hdcp_status status;
92 if (is_dp_hdcp(hdcp)) {
93 status = MOD_HDCP_STATUS_SUCCESS;
95 status = mod_hdcp_read_rxstatus(hdcp);
96 if (status == MOD_HDCP_STATUS_SUCCESS) {
97 const uint16_t size = get_hdmi_rxstatus_msg_size(hdcp->auth.msg.hdcp2.rxstatus);
98 status = (size == sizeof(hdcp->auth.msg.hdcp2.ake_cert)) ?
99 MOD_HDCP_STATUS_SUCCESS :
100 MOD_HDCP_STATUS_HDCP2_AKE_CERT_PENDING;
106 static enum mod_hdcp_status check_h_prime_available(struct mod_hdcp *hdcp)
108 enum mod_hdcp_status status;
110 status = mod_hdcp_read_rxstatus(hdcp);
111 if (status != MOD_HDCP_STATUS_SUCCESS)
114 if (is_dp_hdcp(hdcp)) {
115 status = HDCP_2_2_DP_RXSTATUS_H_PRIME(hdcp->auth.msg.hdcp2.rxstatus_dp) ?
116 MOD_HDCP_STATUS_SUCCESS :
117 MOD_HDCP_STATUS_HDCP2_H_PRIME_PENDING;
119 const uint16_t size = get_hdmi_rxstatus_msg_size(hdcp->auth.msg.hdcp2.rxstatus);
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;
132 status = mod_hdcp_read_rxstatus(hdcp);
133 if (status != MOD_HDCP_STATUS_SUCCESS)
136 if (is_dp_hdcp(hdcp)) {
137 status = HDCP_2_2_DP_RXSTATUS_PAIRING(hdcp->auth.msg.hdcp2.rxstatus_dp) ?
138 MOD_HDCP_STATUS_SUCCESS :
139 MOD_HDCP_STATUS_HDCP2_PAIRING_INFO_PENDING;
141 const uint16_t size = get_hdmi_rxstatus_msg_size(hdcp->auth.msg.hdcp2.rxstatus);
142 status = (size == sizeof(hdcp->auth.msg.hdcp2.ake_pairing_info)) ?
143 MOD_HDCP_STATUS_SUCCESS :
144 MOD_HDCP_STATUS_HDCP2_PAIRING_INFO_PENDING;
150 static enum mod_hdcp_status poll_l_prime_available(struct mod_hdcp *hdcp)
152 enum mod_hdcp_status status = MOD_HDCP_STATUS_FAILURE;
153 uint16_t max_wait = 20; // units of ms
154 uint16_t num_polls = 5;
155 uint16_t wait_time = max_wait / num_polls;
157 if (is_dp_hdcp(hdcp))
158 status = MOD_HDCP_STATUS_INVALID_OPERATION;
160 for (; num_polls; num_polls--) {
163 status = mod_hdcp_read_rxstatus(hdcp);
164 if (status != MOD_HDCP_STATUS_SUCCESS)
167 const uint16_t size = get_hdmi_rxstatus_msg_size(hdcp->auth.msg.hdcp2.rxstatus);
168 status = (size == sizeof(hdcp->auth.msg.hdcp2.lc_l_prime)) ?
169 MOD_HDCP_STATUS_SUCCESS :
170 MOD_HDCP_STATUS_HDCP2_L_PRIME_PENDING;
171 if (status == MOD_HDCP_STATUS_SUCCESS)
177 static enum mod_hdcp_status check_stream_ready_available(struct mod_hdcp *hdcp)
179 enum mod_hdcp_status status;
181 if (is_dp_hdcp(hdcp)) {
182 status = MOD_HDCP_STATUS_INVALID_OPERATION;
184 status = mod_hdcp_read_rxstatus(hdcp);
185 if (status != MOD_HDCP_STATUS_SUCCESS)
187 const uint16_t size = get_hdmi_rxstatus_msg_size(hdcp->auth.msg.hdcp2.rxstatus);
188 status = (size == sizeof(hdcp->auth.msg.hdcp2.repeater_auth_stream_ready)) ?
189 MOD_HDCP_STATUS_SUCCESS :
190 MOD_HDCP_STATUS_HDCP2_STREAM_READY_PENDING;
196 static inline uint8_t get_device_count(struct mod_hdcp *hdcp)
198 return HDCP_2_2_DEV_COUNT_LO(hdcp->auth.msg.hdcp2.rx_id_list[2]) +
199 (HDCP_2_2_DEV_COUNT_HI(hdcp->auth.msg.hdcp2.rx_id_list[1]) << 4);
202 static enum mod_hdcp_status check_device_count(struct mod_hdcp *hdcp)
204 /* Avoid device count == 0 to do authentication */
205 if (get_device_count(hdcp) == 0)
206 return MOD_HDCP_STATUS_HDCP1_DEVICE_COUNT_MISMATCH_FAILURE;
208 /* Some MST display may choose to report the internal panel as an HDCP RX. */
209 /* To update this condition with 1(because the immediate repeater's internal */
210 /* panel is possibly not included in DEVICE_COUNT) + get_device_count(hdcp). */
211 /* Device count must be greater than or equal to tracked hdcp displays. */
212 return ((1 + get_device_count(hdcp)) < get_active_display_count(hdcp)) ?
213 MOD_HDCP_STATUS_HDCP2_DEVICE_COUNT_MISMATCH_FAILURE :
214 MOD_HDCP_STATUS_SUCCESS;
217 static uint8_t process_rxstatus(struct mod_hdcp *hdcp,
218 struct mod_hdcp_event_context *event_ctx,
219 struct mod_hdcp_transition_input_hdcp2 *input,
220 enum mod_hdcp_status *status)
222 if (!mod_hdcp_execute_and_set(mod_hdcp_read_rxstatus,
223 &input->rxstatus_read, status,
224 hdcp, "rxstatus_read"))
226 if (!mod_hdcp_execute_and_set(check_reauthentication_request,
227 &input->reauth_request_check, status,
228 hdcp, "reauth_request_check"))
230 if (is_dp_hdcp(hdcp)) {
231 if (!mod_hdcp_execute_and_set(check_link_integrity_failure_dp,
232 &input->link_integrity_check_dp, status,
233 hdcp, "link_integrity_check_dp"))
236 if (hdcp->connection.is_repeater)
237 if (check_receiver_id_list_ready(hdcp) ==
238 MOD_HDCP_STATUS_SUCCESS) {
239 HDCP_INPUT_PASS_TRACE(hdcp, "rx_id_list_ready");
240 event_ctx->rx_id_list_ready = 1;
241 if (is_dp_hdcp(hdcp))
242 hdcp->auth.msg.hdcp2.rx_id_list_size =
243 sizeof(hdcp->auth.msg.hdcp2.rx_id_list);
245 hdcp->auth.msg.hdcp2.rx_id_list_size =
246 get_hdmi_rxstatus_msg_size(hdcp->auth.msg.hdcp2.rxstatus);
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;
263 if (!mod_hdcp_execute_and_set(mod_hdcp_read_hdcp2version,
264 &input->hdcp2version_read, &status,
265 hdcp, "hdcp2version_read"))
267 if (!mod_hdcp_execute_and_set(check_hdcp2_capable,
268 &input->hdcp2_capable_check, &status,
269 hdcp, "hdcp2_capable"))
275 static enum mod_hdcp_status send_ake_init(struct mod_hdcp *hdcp,
276 struct mod_hdcp_event_context *event_ctx,
277 struct mod_hdcp_transition_input_hdcp2 *input)
279 enum mod_hdcp_status status = MOD_HDCP_STATUS_SUCCESS;
281 if (event_ctx->event != MOD_HDCP_EVENT_CALLBACK) {
282 event_ctx->unexpected_event = 1;
286 if (!mod_hdcp_execute_and_set(mod_hdcp_hdcp2_create_session,
287 &input->create_session, &status,
288 hdcp, "create_session"))
290 if (!mod_hdcp_execute_and_set(mod_hdcp_hdcp2_prepare_ake_init,
291 &input->ake_init_prepare, &status,
292 hdcp, "ake_init_prepare"))
294 if (!mod_hdcp_execute_and_set(mod_hdcp_write_ake_init,
295 &input->ake_init_write, &status,
296 hdcp, "ake_init_write"))
302 static enum mod_hdcp_status validate_ake_cert(struct mod_hdcp *hdcp,
303 struct mod_hdcp_event_context *event_ctx,
304 struct mod_hdcp_transition_input_hdcp2 *input)
306 enum mod_hdcp_status status = MOD_HDCP_STATUS_SUCCESS;
309 if (event_ctx->event != MOD_HDCP_EVENT_CALLBACK &&
310 event_ctx->event != MOD_HDCP_EVENT_WATCHDOG_TIMEOUT) {
311 event_ctx->unexpected_event = 1;
315 if (is_hdmi_dvi_sl_hdcp(hdcp))
316 if (!mod_hdcp_execute_and_set(check_ake_cert_available,
317 &input->ake_cert_available, &status,
318 hdcp, "ake_cert_available"))
320 if (!mod_hdcp_execute_and_set(mod_hdcp_read_ake_cert,
321 &input->ake_cert_read, &status,
322 hdcp, "ake_cert_read"))
324 if (!mod_hdcp_execute_and_set(mod_hdcp_hdcp2_validate_ake_cert,
325 &input->ake_cert_validation, &status,
326 hdcp, "ake_cert_validation"))
332 static enum mod_hdcp_status send_no_stored_km(struct mod_hdcp *hdcp,
333 struct mod_hdcp_event_context *event_ctx,
334 struct mod_hdcp_transition_input_hdcp2 *input)
336 enum mod_hdcp_status status = MOD_HDCP_STATUS_SUCCESS;
338 if (event_ctx->event != MOD_HDCP_EVENT_CALLBACK) {
339 event_ctx->unexpected_event = 1;
343 if (!mod_hdcp_execute_and_set(mod_hdcp_write_no_stored_km,
344 &input->no_stored_km_write, &status,
345 hdcp, "no_stored_km_write"))
351 static enum mod_hdcp_status read_h_prime(struct mod_hdcp *hdcp,
352 struct mod_hdcp_event_context *event_ctx,
353 struct mod_hdcp_transition_input_hdcp2 *input)
355 enum mod_hdcp_status status = MOD_HDCP_STATUS_SUCCESS;
357 if (event_ctx->event != MOD_HDCP_EVENT_CALLBACK &&
358 event_ctx->event != MOD_HDCP_EVENT_CPIRQ &&
359 event_ctx->event != MOD_HDCP_EVENT_WATCHDOG_TIMEOUT) {
360 event_ctx->unexpected_event = 1;
364 if (!mod_hdcp_execute_and_set(check_h_prime_available,
365 &input->h_prime_available, &status,
366 hdcp, "h_prime_available"))
369 if (!mod_hdcp_execute_and_set(mod_hdcp_read_h_prime,
370 &input->h_prime_read, &status,
371 hdcp, "h_prime_read"))
377 static enum mod_hdcp_status read_pairing_info_and_validate_h_prime(
378 struct mod_hdcp *hdcp,
379 struct mod_hdcp_event_context *event_ctx,
380 struct mod_hdcp_transition_input_hdcp2 *input)
382 enum mod_hdcp_status status = MOD_HDCP_STATUS_SUCCESS;
384 if (event_ctx->event != MOD_HDCP_EVENT_CALLBACK &&
385 event_ctx->event != MOD_HDCP_EVENT_CPIRQ &&
386 event_ctx->event != MOD_HDCP_EVENT_WATCHDOG_TIMEOUT) {
387 event_ctx->unexpected_event = 1;
391 if (!mod_hdcp_execute_and_set(check_pairing_info_available,
392 &input->pairing_available, &status,
393 hdcp, "pairing_available"))
395 if (!mod_hdcp_execute_and_set(mod_hdcp_read_pairing_info,
396 &input->pairing_info_read, &status,
397 hdcp, "pairing_info_read"))
399 if (!mod_hdcp_execute_and_set(mod_hdcp_hdcp2_validate_h_prime,
400 &input->h_prime_validation, &status,
401 hdcp, "h_prime_validation"))
407 static enum mod_hdcp_status send_stored_km(struct mod_hdcp *hdcp,
408 struct mod_hdcp_event_context *event_ctx,
409 struct mod_hdcp_transition_input_hdcp2 *input)
411 enum mod_hdcp_status status = MOD_HDCP_STATUS_SUCCESS;
413 if (event_ctx->event != MOD_HDCP_EVENT_CALLBACK) {
414 event_ctx->unexpected_event = 1;
418 if (!mod_hdcp_execute_and_set(mod_hdcp_write_stored_km,
419 &input->stored_km_write, &status,
420 hdcp, "stored_km_write"))
426 static enum mod_hdcp_status validate_h_prime(struct mod_hdcp *hdcp,
427 struct mod_hdcp_event_context *event_ctx,
428 struct mod_hdcp_transition_input_hdcp2 *input)
430 enum mod_hdcp_status status = MOD_HDCP_STATUS_SUCCESS;
432 if (event_ctx->event != MOD_HDCP_EVENT_CALLBACK &&
433 event_ctx->event != MOD_HDCP_EVENT_CPIRQ &&
434 event_ctx->event != MOD_HDCP_EVENT_WATCHDOG_TIMEOUT) {
435 event_ctx->unexpected_event = 1;
439 if (!mod_hdcp_execute_and_set(check_h_prime_available,
440 &input->h_prime_available, &status,
441 hdcp, "h_prime_available"))
443 if (!mod_hdcp_execute_and_set(mod_hdcp_read_h_prime,
444 &input->h_prime_read, &status,
445 hdcp, "h_prime_read"))
447 if (!mod_hdcp_execute_and_set(mod_hdcp_hdcp2_validate_h_prime,
448 &input->h_prime_validation, &status,
449 hdcp, "h_prime_validation"))
455 static enum mod_hdcp_status locality_check(struct mod_hdcp *hdcp,
456 struct mod_hdcp_event_context *event_ctx,
457 struct mod_hdcp_transition_input_hdcp2 *input)
459 enum mod_hdcp_status status = MOD_HDCP_STATUS_SUCCESS;
461 if (event_ctx->event != MOD_HDCP_EVENT_CALLBACK) {
462 event_ctx->unexpected_event = 1;
466 if (!mod_hdcp_execute_and_set(mod_hdcp_hdcp2_prepare_lc_init,
467 &input->lc_init_prepare, &status,
468 hdcp, "lc_init_prepare"))
470 if (!mod_hdcp_execute_and_set(mod_hdcp_write_lc_init,
471 &input->lc_init_write, &status,
472 hdcp, "lc_init_write"))
474 if (is_dp_hdcp(hdcp))
477 if (!mod_hdcp_execute_and_set(poll_l_prime_available,
478 &input->l_prime_available_poll, &status,
479 hdcp, "l_prime_available_poll"))
481 if (!mod_hdcp_execute_and_set(mod_hdcp_read_l_prime,
482 &input->l_prime_read, &status,
483 hdcp, "l_prime_read"))
485 if (!mod_hdcp_execute_and_set(mod_hdcp_hdcp2_validate_l_prime,
486 &input->l_prime_validation, &status,
487 hdcp, "l_prime_validation"))
493 static enum mod_hdcp_status exchange_ks_and_test_for_repeater(struct mod_hdcp *hdcp,
494 struct mod_hdcp_event_context *event_ctx,
495 struct mod_hdcp_transition_input_hdcp2 *input)
497 enum mod_hdcp_status status = MOD_HDCP_STATUS_SUCCESS;
499 if (event_ctx->event != MOD_HDCP_EVENT_CALLBACK) {
500 event_ctx->unexpected_event = 1;
504 if (!mod_hdcp_execute_and_set(mod_hdcp_hdcp2_prepare_eks,
505 &input->eks_prepare, &status,
506 hdcp, "eks_prepare"))
508 if (!mod_hdcp_execute_and_set(mod_hdcp_write_eks,
509 &input->eks_write, &status,
516 static enum mod_hdcp_status enable_encryption(struct mod_hdcp *hdcp,
517 struct mod_hdcp_event_context *event_ctx,
518 struct mod_hdcp_transition_input_hdcp2 *input)
520 enum mod_hdcp_status status = MOD_HDCP_STATUS_SUCCESS;
522 if (event_ctx->event != MOD_HDCP_EVENT_CALLBACK &&
523 event_ctx->event != MOD_HDCP_EVENT_CPIRQ) {
524 event_ctx->unexpected_event = 1;
527 if (event_ctx->event == MOD_HDCP_EVENT_CPIRQ) {
528 process_rxstatus(hdcp, event_ctx, input, &status);
532 if (is_hdmi_dvi_sl_hdcp(hdcp)) {
533 if (!process_rxstatus(hdcp, event_ctx, input, &status))
535 if (event_ctx->rx_id_list_ready)
538 if (!mod_hdcp_execute_and_set(mod_hdcp_hdcp2_enable_encryption,
539 &input->enable_encryption, &status,
540 hdcp, "enable_encryption"))
542 if (is_dp_mst_hdcp(hdcp)) {
543 if (!mod_hdcp_execute_and_set(
544 mod_hdcp_hdcp2_enable_dp_stream_encryption,
545 &input->stream_encryption_dp, &status,
546 hdcp, "stream_encryption_dp"))
553 static enum mod_hdcp_status authenticated(struct mod_hdcp *hdcp,
554 struct mod_hdcp_event_context *event_ctx,
555 struct mod_hdcp_transition_input_hdcp2 *input)
557 enum mod_hdcp_status status = MOD_HDCP_STATUS_SUCCESS;
559 if (event_ctx->event != MOD_HDCP_EVENT_CALLBACK &&
560 event_ctx->event != MOD_HDCP_EVENT_CPIRQ) {
561 event_ctx->unexpected_event = 1;
565 process_rxstatus(hdcp, event_ctx, input, &status);
570 static enum mod_hdcp_status wait_for_rx_id_list(struct mod_hdcp *hdcp,
571 struct mod_hdcp_event_context *event_ctx,
572 struct mod_hdcp_transition_input_hdcp2 *input)
574 enum mod_hdcp_status status = MOD_HDCP_STATUS_SUCCESS;
576 if (event_ctx->event != MOD_HDCP_EVENT_CALLBACK &&
577 event_ctx->event != MOD_HDCP_EVENT_CPIRQ &&
578 event_ctx->event != MOD_HDCP_EVENT_WATCHDOG_TIMEOUT) {
579 event_ctx->unexpected_event = 1;
583 if (!process_rxstatus(hdcp, event_ctx, input, &status))
585 if (!event_ctx->rx_id_list_ready) {
586 status = MOD_HDCP_STATUS_HDCP2_RX_ID_LIST_NOT_READY;
593 static enum mod_hdcp_status verify_rx_id_list_and_send_ack(struct mod_hdcp *hdcp,
594 struct mod_hdcp_event_context *event_ctx,
595 struct mod_hdcp_transition_input_hdcp2 *input)
597 enum mod_hdcp_status status = MOD_HDCP_STATUS_SUCCESS;
599 if (event_ctx->event != MOD_HDCP_EVENT_CALLBACK &&
600 event_ctx->event != MOD_HDCP_EVENT_CPIRQ) {
601 event_ctx->unexpected_event = 1;
604 if (event_ctx->event == MOD_HDCP_EVENT_CPIRQ) {
605 process_rxstatus(hdcp, event_ctx, input, &status);
609 if (!mod_hdcp_execute_and_set(mod_hdcp_read_rx_id_list,
610 &input->rx_id_list_read,
611 &status, hdcp, "receiver_id_list_read"))
613 if (!mod_hdcp_execute_and_set(check_device_count,
614 &input->device_count_check,
615 &status, hdcp, "device_count_check"))
617 if (!mod_hdcp_execute_and_set(mod_hdcp_hdcp2_validate_rx_id_list,
618 &input->rx_id_list_validation,
619 &status, hdcp, "rx_id_list_validation"))
621 if (!mod_hdcp_execute_and_set(mod_hdcp_write_repeater_auth_ack,
622 &input->repeater_auth_ack_write,
623 &status, hdcp, "repeater_auth_ack_write"))
629 static enum mod_hdcp_status send_stream_management(struct mod_hdcp *hdcp,
630 struct mod_hdcp_event_context *event_ctx,
631 struct mod_hdcp_transition_input_hdcp2 *input)
633 enum mod_hdcp_status status = MOD_HDCP_STATUS_SUCCESS;
635 if (event_ctx->event != MOD_HDCP_EVENT_CALLBACK &&
636 event_ctx->event != MOD_HDCP_EVENT_CPIRQ) {
637 event_ctx->unexpected_event = 1;
640 if (event_ctx->event == MOD_HDCP_EVENT_CPIRQ) {
641 process_rxstatus(hdcp, event_ctx, input, &status);
645 if (is_hdmi_dvi_sl_hdcp(hdcp)) {
646 if (!process_rxstatus(hdcp, event_ctx, input, &status))
648 if (event_ctx->rx_id_list_ready)
651 if (!mod_hdcp_execute_and_set(mod_hdcp_hdcp2_prepare_stream_management,
652 &input->prepare_stream_manage,
653 &status, hdcp, "prepare_stream_manage"))
656 if (!mod_hdcp_execute_and_set(mod_hdcp_write_stream_manage,
657 &input->stream_manage_write,
658 &status, hdcp, "stream_manage_write"))
664 static enum mod_hdcp_status validate_stream_ready(struct mod_hdcp *hdcp,
665 struct mod_hdcp_event_context *event_ctx,
666 struct mod_hdcp_transition_input_hdcp2 *input)
668 enum mod_hdcp_status status = MOD_HDCP_STATUS_SUCCESS;
670 if (event_ctx->event != MOD_HDCP_EVENT_CALLBACK &&
671 event_ctx->event != MOD_HDCP_EVENT_CPIRQ &&
672 event_ctx->event != MOD_HDCP_EVENT_WATCHDOG_TIMEOUT) {
673 event_ctx->unexpected_event = 1;
676 if (event_ctx->event == MOD_HDCP_EVENT_CPIRQ) {
677 process_rxstatus(hdcp, event_ctx, input, &status);
681 if (is_hdmi_dvi_sl_hdcp(hdcp)) {
682 if (!process_rxstatus(hdcp, event_ctx, input, &status))
684 if (event_ctx->rx_id_list_ready)
687 if (is_hdmi_dvi_sl_hdcp(hdcp))
688 if (!mod_hdcp_execute_and_set(check_stream_ready_available,
689 &input->stream_ready_available,
690 &status, hdcp, "stream_ready_available"))
692 if (!mod_hdcp_execute_and_set(mod_hdcp_read_stream_ready,
693 &input->stream_ready_read,
694 &status, hdcp, "stream_ready_read"))
696 if (!mod_hdcp_execute_and_set(mod_hdcp_hdcp2_validate_stream_ready,
697 &input->stream_ready_validation,
698 &status, hdcp, "stream_ready_validation"))
705 static enum mod_hdcp_status determine_rx_hdcp_capable_dp(struct mod_hdcp *hdcp,
706 struct mod_hdcp_event_context *event_ctx,
707 struct mod_hdcp_transition_input_hdcp2 *input)
709 enum mod_hdcp_status status = MOD_HDCP_STATUS_SUCCESS;
711 if (event_ctx->event != MOD_HDCP_EVENT_CALLBACK) {
712 event_ctx->unexpected_event = 1;
716 if (!mod_hdcp_execute_and_set(mod_hdcp_read_rxcaps,
717 &input->rx_caps_read_dp,
718 &status, hdcp, "rx_caps_read_dp"))
720 if (!mod_hdcp_execute_and_set(check_hdcp2_capable,
721 &input->hdcp2_capable_check, &status,
722 hdcp, "hdcp2_capable_check"))
728 static enum mod_hdcp_status send_content_stream_type_dp(struct mod_hdcp *hdcp,
729 struct mod_hdcp_event_context *event_ctx,
730 struct mod_hdcp_transition_input_hdcp2 *input)
732 enum mod_hdcp_status status = MOD_HDCP_STATUS_SUCCESS;
734 if (event_ctx->event != MOD_HDCP_EVENT_CALLBACK &&
735 event_ctx->event != MOD_HDCP_EVENT_CPIRQ) {
736 event_ctx->unexpected_event = 1;
740 if (!process_rxstatus(hdcp, event_ctx, input, &status))
742 if (!mod_hdcp_execute_and_set(mod_hdcp_write_content_type,
743 &input->content_stream_type_write, &status,
744 hdcp, "content_stream_type_write"))
750 enum mod_hdcp_status mod_hdcp_hdcp2_execution(struct mod_hdcp *hdcp,
751 struct mod_hdcp_event_context *event_ctx,
752 struct mod_hdcp_transition_input_hdcp2 *input)
754 enum mod_hdcp_status status = MOD_HDCP_STATUS_SUCCESS;
756 switch (current_state(hdcp)) {
757 case H2_A0_KNOWN_HDCP2_CAPABLE_RX:
758 status = known_hdcp2_capable_rx(hdcp, event_ctx, input);
760 case H2_A1_SEND_AKE_INIT:
761 status = send_ake_init(hdcp, event_ctx, input);
763 case H2_A1_VALIDATE_AKE_CERT:
764 status = validate_ake_cert(hdcp, event_ctx, input);
766 case H2_A1_SEND_NO_STORED_KM:
767 status = send_no_stored_km(hdcp, event_ctx, input);
769 case H2_A1_READ_H_PRIME:
770 status = read_h_prime(hdcp, event_ctx, input);
772 case H2_A1_READ_PAIRING_INFO_AND_VALIDATE_H_PRIME:
773 status = read_pairing_info_and_validate_h_prime(hdcp,
776 case H2_A1_SEND_STORED_KM:
777 status = send_stored_km(hdcp, event_ctx, input);
779 case H2_A1_VALIDATE_H_PRIME:
780 status = validate_h_prime(hdcp, event_ctx, input);
782 case H2_A2_LOCALITY_CHECK:
783 status = locality_check(hdcp, event_ctx, input);
785 case H2_A3_EXCHANGE_KS_AND_TEST_FOR_REPEATER:
786 status = exchange_ks_and_test_for_repeater(hdcp, event_ctx, input);
788 case H2_ENABLE_ENCRYPTION:
789 status = enable_encryption(hdcp, event_ctx, input);
791 case H2_A5_AUTHENTICATED:
792 status = authenticated(hdcp, event_ctx, input);
794 case H2_A6_WAIT_FOR_RX_ID_LIST:
795 status = wait_for_rx_id_list(hdcp, event_ctx, input);
797 case H2_A78_VERIFY_RX_ID_LIST_AND_SEND_ACK:
798 status = verify_rx_id_list_and_send_ack(hdcp, event_ctx, input);
800 case H2_A9_SEND_STREAM_MANAGEMENT:
801 status = send_stream_management(hdcp, event_ctx, input);
803 case H2_A9_VALIDATE_STREAM_READY:
804 status = validate_stream_ready(hdcp, event_ctx, input);
807 status = MOD_HDCP_STATUS_INVALID_STATE;
814 enum mod_hdcp_status mod_hdcp_hdcp2_dp_execution(struct mod_hdcp *hdcp,
815 struct mod_hdcp_event_context *event_ctx,
816 struct mod_hdcp_transition_input_hdcp2 *input)
818 enum mod_hdcp_status status = MOD_HDCP_STATUS_SUCCESS;
820 switch (current_state(hdcp)) {
821 case D2_A0_DETERMINE_RX_HDCP_CAPABLE:
822 status = determine_rx_hdcp_capable_dp(hdcp, event_ctx, input);
824 case D2_A1_SEND_AKE_INIT:
825 status = send_ake_init(hdcp, event_ctx, input);
827 case D2_A1_VALIDATE_AKE_CERT:
828 status = validate_ake_cert(hdcp, event_ctx, input);
830 case D2_A1_SEND_NO_STORED_KM:
831 status = send_no_stored_km(hdcp, event_ctx, input);
833 case D2_A1_READ_H_PRIME:
834 status = read_h_prime(hdcp, event_ctx, input);
836 case D2_A1_READ_PAIRING_INFO_AND_VALIDATE_H_PRIME:
837 status = read_pairing_info_and_validate_h_prime(hdcp,
840 case D2_A1_SEND_STORED_KM:
841 status = send_stored_km(hdcp, event_ctx, input);
843 case D2_A1_VALIDATE_H_PRIME:
844 status = validate_h_prime(hdcp, event_ctx, input);
846 case D2_A2_LOCALITY_CHECK:
847 status = locality_check(hdcp, event_ctx, input);
849 case D2_A34_EXCHANGE_KS_AND_TEST_FOR_REPEATER:
850 status = exchange_ks_and_test_for_repeater(hdcp,
853 case D2_SEND_CONTENT_STREAM_TYPE:
854 status = send_content_stream_type_dp(hdcp, event_ctx, input);
856 case D2_ENABLE_ENCRYPTION:
857 status = enable_encryption(hdcp, event_ctx, input);
859 case D2_A5_AUTHENTICATED:
860 status = authenticated(hdcp, event_ctx, input);
862 case D2_A6_WAIT_FOR_RX_ID_LIST:
863 status = wait_for_rx_id_list(hdcp, event_ctx, input);
865 case D2_A78_VERIFY_RX_ID_LIST_AND_SEND_ACK:
866 status = verify_rx_id_list_and_send_ack(hdcp, event_ctx, input);
868 case D2_A9_SEND_STREAM_MANAGEMENT:
869 status = send_stream_management(hdcp, event_ctx, input);
871 case D2_A9_VALIDATE_STREAM_READY:
872 status = validate_stream_ready(hdcp, event_ctx, input);
875 status = MOD_HDCP_STATUS_INVALID_STATE;