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[1]) &&
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[0] == HDCP_2_2_RX_CAPS_VERSION_VAL) &&
50 HDCP_2_2_DP_HDCP_CAPABLE(hdcp->auth.msg.hdcp2.rxcaps_dp[2]) ?
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[1]) ?
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_active_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;
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 if (!process_rxstatus(hdcp, event_ctx, input, &status))
567 if (event_ctx->rx_id_list_ready)
573 static enum mod_hdcp_status wait_for_rx_id_list(struct mod_hdcp *hdcp,
574 struct mod_hdcp_event_context *event_ctx,
575 struct mod_hdcp_transition_input_hdcp2 *input)
577 enum mod_hdcp_status status = MOD_HDCP_STATUS_SUCCESS;
579 if (event_ctx->event != MOD_HDCP_EVENT_CALLBACK &&
580 event_ctx->event != MOD_HDCP_EVENT_CPIRQ &&
581 event_ctx->event != MOD_HDCP_EVENT_WATCHDOG_TIMEOUT) {
582 event_ctx->unexpected_event = 1;
586 if (!process_rxstatus(hdcp, event_ctx, input, &status))
588 if (!event_ctx->rx_id_list_ready) {
589 status = MOD_HDCP_STATUS_HDCP2_RX_ID_LIST_NOT_READY;
596 static enum mod_hdcp_status verify_rx_id_list_and_send_ack(struct mod_hdcp *hdcp,
597 struct mod_hdcp_event_context *event_ctx,
598 struct mod_hdcp_transition_input_hdcp2 *input)
600 enum mod_hdcp_status status = MOD_HDCP_STATUS_SUCCESS;
602 if (event_ctx->event != MOD_HDCP_EVENT_CALLBACK &&
603 event_ctx->event != MOD_HDCP_EVENT_CPIRQ) {
604 event_ctx->unexpected_event = 1;
607 if (event_ctx->event == MOD_HDCP_EVENT_CPIRQ) {
608 process_rxstatus(hdcp, event_ctx, input, &status);
612 if (!mod_hdcp_execute_and_set(mod_hdcp_read_rx_id_list,
613 &input->rx_id_list_read,
614 &status, hdcp, "receiver_id_list_read"))
616 if (!mod_hdcp_execute_and_set(check_device_count,
617 &input->device_count_check,
618 &status, hdcp, "device_count_check"))
620 if (!mod_hdcp_execute_and_set(mod_hdcp_hdcp2_validate_rx_id_list,
621 &input->rx_id_list_validation,
622 &status, hdcp, "rx_id_list_validation"))
624 if (!mod_hdcp_execute_and_set(mod_hdcp_write_repeater_auth_ack,
625 &input->repeater_auth_ack_write,
626 &status, hdcp, "repeater_auth_ack_write"))
632 static enum mod_hdcp_status send_stream_management(struct mod_hdcp *hdcp,
633 struct mod_hdcp_event_context *event_ctx,
634 struct mod_hdcp_transition_input_hdcp2 *input)
636 enum mod_hdcp_status status = MOD_HDCP_STATUS_SUCCESS;
638 if (event_ctx->event != MOD_HDCP_EVENT_CALLBACK &&
639 event_ctx->event != MOD_HDCP_EVENT_CPIRQ) {
640 event_ctx->unexpected_event = 1;
643 if (event_ctx->event == MOD_HDCP_EVENT_CPIRQ) {
644 process_rxstatus(hdcp, event_ctx, input, &status);
648 if (is_hdmi_dvi_sl_hdcp(hdcp)) {
649 if (!process_rxstatus(hdcp, event_ctx, input, &status))
651 if (event_ctx->rx_id_list_ready)
654 if (!mod_hdcp_execute_and_set(mod_hdcp_hdcp2_prepare_stream_management,
655 &input->prepare_stream_manage,
656 &status, hdcp, "prepare_stream_manage"))
659 if (!mod_hdcp_execute_and_set(mod_hdcp_write_stream_manage,
660 &input->stream_manage_write,
661 &status, hdcp, "stream_manage_write"))
667 static enum mod_hdcp_status validate_stream_ready(struct mod_hdcp *hdcp,
668 struct mod_hdcp_event_context *event_ctx,
669 struct mod_hdcp_transition_input_hdcp2 *input)
671 enum mod_hdcp_status status = MOD_HDCP_STATUS_SUCCESS;
673 if (event_ctx->event != MOD_HDCP_EVENT_CALLBACK &&
674 event_ctx->event != MOD_HDCP_EVENT_CPIRQ &&
675 event_ctx->event != MOD_HDCP_EVENT_WATCHDOG_TIMEOUT) {
676 event_ctx->unexpected_event = 1;
679 if (event_ctx->event == MOD_HDCP_EVENT_CPIRQ) {
680 process_rxstatus(hdcp, event_ctx, input, &status);
684 if (is_hdmi_dvi_sl_hdcp(hdcp)) {
685 if (!process_rxstatus(hdcp, event_ctx, input, &status))
687 if (event_ctx->rx_id_list_ready) {
691 if (is_hdmi_dvi_sl_hdcp(hdcp))
692 if (!mod_hdcp_execute_and_set(check_stream_ready_available,
693 &input->stream_ready_available,
694 &status, hdcp, "stream_ready_available"))
696 if (!mod_hdcp_execute_and_set(mod_hdcp_read_stream_ready,
697 &input->stream_ready_read,
698 &status, hdcp, "stream_ready_read"))
700 if (!mod_hdcp_execute_and_set(mod_hdcp_hdcp2_validate_stream_ready,
701 &input->stream_ready_validation,
702 &status, hdcp, "stream_ready_validation"))
709 static enum mod_hdcp_status determine_rx_hdcp_capable_dp(struct mod_hdcp *hdcp,
710 struct mod_hdcp_event_context *event_ctx,
711 struct mod_hdcp_transition_input_hdcp2 *input)
713 enum mod_hdcp_status status = MOD_HDCP_STATUS_SUCCESS;
715 if (event_ctx->event != MOD_HDCP_EVENT_CALLBACK) {
716 event_ctx->unexpected_event = 1;
720 if (!mod_hdcp_execute_and_set(mod_hdcp_read_rxcaps,
721 &input->rx_caps_read_dp,
722 &status, hdcp, "rx_caps_read_dp"))
724 if (!mod_hdcp_execute_and_set(check_hdcp2_capable,
725 &input->hdcp2_capable_check, &status,
726 hdcp, "hdcp2_capable_check"))
732 static enum mod_hdcp_status send_content_stream_type_dp(struct mod_hdcp *hdcp,
733 struct mod_hdcp_event_context *event_ctx,
734 struct mod_hdcp_transition_input_hdcp2 *input)
736 enum mod_hdcp_status status = MOD_HDCP_STATUS_SUCCESS;
738 if (event_ctx->event != MOD_HDCP_EVENT_CALLBACK &&
739 event_ctx->event != MOD_HDCP_EVENT_CPIRQ) {
740 event_ctx->unexpected_event = 1;
744 if (!process_rxstatus(hdcp, event_ctx, input, &status))
746 if (!mod_hdcp_execute_and_set(mod_hdcp_write_content_type,
747 &input->content_stream_type_write, &status,
748 hdcp, "content_stream_type_write"))
754 enum mod_hdcp_status mod_hdcp_hdcp2_execution(struct mod_hdcp *hdcp,
755 struct mod_hdcp_event_context *event_ctx,
756 struct mod_hdcp_transition_input_hdcp2 *input)
758 enum mod_hdcp_status status = MOD_HDCP_STATUS_SUCCESS;
760 switch (current_state(hdcp)) {
761 case H2_A0_KNOWN_HDCP2_CAPABLE_RX:
762 status = known_hdcp2_capable_rx(hdcp, event_ctx, input);
764 case H2_A1_SEND_AKE_INIT:
765 status = send_ake_init(hdcp, event_ctx, input);
767 case H2_A1_VALIDATE_AKE_CERT:
768 status = validate_ake_cert(hdcp, event_ctx, input);
770 case H2_A1_SEND_NO_STORED_KM:
771 status = send_no_stored_km(hdcp, event_ctx, input);
773 case H2_A1_READ_H_PRIME:
774 status = read_h_prime(hdcp, event_ctx, input);
776 case H2_A1_READ_PAIRING_INFO_AND_VALIDATE_H_PRIME:
777 status = read_pairing_info_and_validate_h_prime(hdcp,
780 case H2_A1_SEND_STORED_KM:
781 status = send_stored_km(hdcp, event_ctx, input);
783 case H2_A1_VALIDATE_H_PRIME:
784 status = validate_h_prime(hdcp, event_ctx, input);
786 case H2_A2_LOCALITY_CHECK:
787 status = locality_check(hdcp, event_ctx, input);
789 case H2_A3_EXCHANGE_KS_AND_TEST_FOR_REPEATER:
790 status = exchange_ks_and_test_for_repeater(hdcp, event_ctx, input);
792 case H2_ENABLE_ENCRYPTION:
793 status = enable_encryption(hdcp, event_ctx, input);
795 case H2_A5_AUTHENTICATED:
796 status = authenticated(hdcp, event_ctx, input);
798 case H2_A6_WAIT_FOR_RX_ID_LIST:
799 status = wait_for_rx_id_list(hdcp, event_ctx, input);
801 case H2_A78_VERIFY_RX_ID_LIST_AND_SEND_ACK:
802 status = verify_rx_id_list_and_send_ack(hdcp, event_ctx, input);
804 case H2_A9_SEND_STREAM_MANAGEMENT:
805 status = send_stream_management(hdcp, event_ctx, input);
807 case H2_A9_VALIDATE_STREAM_READY:
808 status = validate_stream_ready(hdcp, event_ctx, input);
811 status = MOD_HDCP_STATUS_INVALID_STATE;
818 enum mod_hdcp_status mod_hdcp_hdcp2_dp_execution(struct mod_hdcp *hdcp,
819 struct mod_hdcp_event_context *event_ctx,
820 struct mod_hdcp_transition_input_hdcp2 *input)
822 enum mod_hdcp_status status = MOD_HDCP_STATUS_SUCCESS;
824 switch (current_state(hdcp)) {
825 case D2_A0_DETERMINE_RX_HDCP_CAPABLE:
826 status = determine_rx_hdcp_capable_dp(hdcp, event_ctx, input);
828 case D2_A1_SEND_AKE_INIT:
829 status = send_ake_init(hdcp, event_ctx, input);
831 case D2_A1_VALIDATE_AKE_CERT:
832 status = validate_ake_cert(hdcp, event_ctx, input);
834 case D2_A1_SEND_NO_STORED_KM:
835 status = send_no_stored_km(hdcp, event_ctx, input);
837 case D2_A1_READ_H_PRIME:
838 status = read_h_prime(hdcp, event_ctx, input);
840 case D2_A1_READ_PAIRING_INFO_AND_VALIDATE_H_PRIME:
841 status = read_pairing_info_and_validate_h_prime(hdcp,
844 case D2_A1_SEND_STORED_KM:
845 status = send_stored_km(hdcp, event_ctx, input);
847 case D2_A1_VALIDATE_H_PRIME:
848 status = validate_h_prime(hdcp, event_ctx, input);
850 case D2_A2_LOCALITY_CHECK:
851 status = locality_check(hdcp, event_ctx, input);
853 case D2_A34_EXCHANGE_KS_AND_TEST_FOR_REPEATER:
854 status = exchange_ks_and_test_for_repeater(hdcp,
857 case D2_SEND_CONTENT_STREAM_TYPE:
858 status = send_content_stream_type_dp(hdcp, event_ctx, input);
860 case D2_ENABLE_ENCRYPTION:
861 status = enable_encryption(hdcp, event_ctx, input);
863 case D2_A5_AUTHENTICATED:
864 status = authenticated(hdcp, event_ctx, input);
866 case D2_A6_WAIT_FOR_RX_ID_LIST:
867 status = wait_for_rx_id_list(hdcp, event_ctx, input);
869 case D2_A78_VERIFY_RX_ID_LIST_AND_SEND_ACK:
870 status = verify_rx_id_list_and_send_ack(hdcp, event_ctx, input);
872 case D2_A9_SEND_STREAM_MANAGEMENT:
873 status = send_stream_management(hdcp, event_ctx, input);
875 case D2_A9_VALIDATE_STREAM_READY:
876 status = validate_stream_ready(hdcp, event_ctx, input);
879 status = MOD_HDCP_STATUS_INVALID_STATE;