1 /* 2 * Copyright 2018 Advanced Micro Devices, Inc. 3 * 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: 10 * 11 * The above copyright notice and this permission notice shall be included in 12 * all copies or substantial portions of the Software. 13 * 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. 21 * 22 * Authors: AMD 23 * 24 */ 25 26 #include <linux/delay.h> 27 28 #include "hdcp.h" 29 30 static inline uint16_t get_hdmi_rxstatus_msg_size(const uint8_t rxstatus[2]) 31 { 32 return HDCP_2_2_HDMI_RXSTATUS_MSG_SZ_HI(rxstatus[1]) << 8 | rxstatus[0]; 33 } 34 35 static inline enum mod_hdcp_status check_receiver_id_list_ready(struct mod_hdcp *hdcp) 36 { 37 uint8_t is_ready = 0; 38 39 if (is_dp_hdcp(hdcp)) 40 is_ready = HDCP_2_2_DP_RXSTATUS_READY(hdcp->auth.msg.hdcp2.rxstatus_dp) ? 1 : 0; 41 else 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; 46 } 47 48 static inline enum mod_hdcp_status check_hdcp2_capable(struct mod_hdcp *hdcp) 49 { 50 enum mod_hdcp_status status; 51 52 if (is_dp_hdcp(hdcp)) 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; 57 else 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; 61 return status; 62 } 63 64 static inline enum mod_hdcp_status check_reauthentication_request( 65 struct mod_hdcp *hdcp) 66 { 67 uint8_t ret = 0; 68 69 if (is_dp_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; 73 else 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; 77 return ret; 78 } 79 80 static inline enum mod_hdcp_status check_link_integrity_failure_dp( 81 struct mod_hdcp *hdcp) 82 { 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; 86 } 87 88 static enum mod_hdcp_status check_ake_cert_available(struct mod_hdcp *hdcp) 89 { 90 enum mod_hdcp_status status; 91 92 if (is_dp_hdcp(hdcp)) { 93 status = MOD_HDCP_STATUS_SUCCESS; 94 } else { 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; 101 } 102 } 103 return status; 104 } 105 106 static enum mod_hdcp_status check_h_prime_available(struct mod_hdcp *hdcp) 107 { 108 enum mod_hdcp_status status; 109 110 status = mod_hdcp_read_rxstatus(hdcp); 111 if (status != MOD_HDCP_STATUS_SUCCESS) 112 goto out; 113 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; 118 } else { 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; 123 } 124 out: 125 return status; 126 } 127 128 static enum mod_hdcp_status check_pairing_info_available(struct mod_hdcp *hdcp) 129 { 130 enum mod_hdcp_status status; 131 132 status = mod_hdcp_read_rxstatus(hdcp); 133 if (status != MOD_HDCP_STATUS_SUCCESS) 134 goto out; 135 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; 140 } else { 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; 145 } 146 out: 147 return status; 148 } 149 150 static enum mod_hdcp_status poll_l_prime_available(struct mod_hdcp *hdcp) 151 { 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; 156 157 if (is_dp_hdcp(hdcp)) 158 status = MOD_HDCP_STATUS_INVALID_OPERATION; 159 else 160 for (; num_polls; num_polls--) { 161 msleep(wait_time); 162 163 status = mod_hdcp_read_rxstatus(hdcp); 164 if (status != MOD_HDCP_STATUS_SUCCESS) 165 break; 166 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) 172 break; 173 } 174 return status; 175 } 176 177 static enum mod_hdcp_status check_stream_ready_available(struct mod_hdcp *hdcp) 178 { 179 enum mod_hdcp_status status; 180 181 if (is_dp_hdcp(hdcp)) { 182 status = MOD_HDCP_STATUS_INVALID_OPERATION; 183 } else { 184 status = mod_hdcp_read_rxstatus(hdcp); 185 if (status != MOD_HDCP_STATUS_SUCCESS) 186 goto out; 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; 191 } 192 out: 193 return status; 194 } 195 196 static inline uint8_t get_device_count(struct mod_hdcp *hdcp) 197 { 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); 200 } 201 202 static enum mod_hdcp_status check_device_count(struct mod_hdcp *hdcp) 203 { 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; 207 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; 215 } 216 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) 221 { 222 if (!mod_hdcp_execute_and_set(mod_hdcp_read_rxstatus, 223 &input->rxstatus_read, status, 224 hdcp, "rxstatus_read")) 225 goto out; 226 if (!mod_hdcp_execute_and_set(check_reauthentication_request, 227 &input->reauth_request_check, status, 228 hdcp, "reauth_request_check")) 229 goto out; 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")) 234 goto out; 235 } 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); 244 else 245 hdcp->auth.msg.hdcp2.rx_id_list_size = 246 get_hdmi_rxstatus_msg_size(hdcp->auth.msg.hdcp2.rxstatus); 247 } 248 out: 249 return (*status == MOD_HDCP_STATUS_SUCCESS); 250 } 251 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) 255 { 256 enum mod_hdcp_status status = MOD_HDCP_STATUS_SUCCESS; 257 258 if (event_ctx->event != MOD_HDCP_EVENT_CALLBACK) { 259 event_ctx->unexpected_event = 1; 260 goto out; 261 } 262 263 if (!mod_hdcp_execute_and_set(mod_hdcp_read_hdcp2version, 264 &input->hdcp2version_read, &status, 265 hdcp, "hdcp2version_read")) 266 goto out; 267 if (!mod_hdcp_execute_and_set(check_hdcp2_capable, 268 &input->hdcp2_capable_check, &status, 269 hdcp, "hdcp2_capable")) 270 goto out; 271 out: 272 return status; 273 } 274 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) 278 { 279 enum mod_hdcp_status status = MOD_HDCP_STATUS_SUCCESS; 280 281 if (event_ctx->event != MOD_HDCP_EVENT_CALLBACK) { 282 event_ctx->unexpected_event = 1; 283 goto out; 284 } 285 286 if (!mod_hdcp_execute_and_set(mod_hdcp_hdcp2_create_session, 287 &input->create_session, &status, 288 hdcp, "create_session")) 289 goto out; 290 if (!mod_hdcp_execute_and_set(mod_hdcp_hdcp2_prepare_ake_init, 291 &input->ake_init_prepare, &status, 292 hdcp, "ake_init_prepare")) 293 goto out; 294 if (!mod_hdcp_execute_and_set(mod_hdcp_write_ake_init, 295 &input->ake_init_write, &status, 296 hdcp, "ake_init_write")) 297 goto out; 298 out: 299 return status; 300 } 301 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) 305 { 306 enum mod_hdcp_status status = MOD_HDCP_STATUS_SUCCESS; 307 308 309 if (event_ctx->event != MOD_HDCP_EVENT_CALLBACK && 310 event_ctx->event != MOD_HDCP_EVENT_WATCHDOG_TIMEOUT) { 311 event_ctx->unexpected_event = 1; 312 goto out; 313 } 314 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")) 319 goto out; 320 if (!mod_hdcp_execute_and_set(mod_hdcp_read_ake_cert, 321 &input->ake_cert_read, &status, 322 hdcp, "ake_cert_read")) 323 goto out; 324 if (!mod_hdcp_execute_and_set(mod_hdcp_hdcp2_validate_ake_cert, 325 &input->ake_cert_validation, &status, 326 hdcp, "ake_cert_validation")) 327 goto out; 328 out: 329 return status; 330 } 331 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) 335 { 336 enum mod_hdcp_status status = MOD_HDCP_STATUS_SUCCESS; 337 338 if (event_ctx->event != MOD_HDCP_EVENT_CALLBACK) { 339 event_ctx->unexpected_event = 1; 340 goto out; 341 } 342 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")) 346 goto out; 347 out: 348 return status; 349 } 350 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) 354 { 355 enum mod_hdcp_status status = MOD_HDCP_STATUS_SUCCESS; 356 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; 361 goto out; 362 } 363 364 if (!mod_hdcp_execute_and_set(check_h_prime_available, 365 &input->h_prime_available, &status, 366 hdcp, "h_prime_available")) 367 goto out; 368 369 if (!mod_hdcp_execute_and_set(mod_hdcp_read_h_prime, 370 &input->h_prime_read, &status, 371 hdcp, "h_prime_read")) 372 goto out; 373 out: 374 return status; 375 } 376 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) 381 { 382 enum mod_hdcp_status status = MOD_HDCP_STATUS_SUCCESS; 383 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; 388 goto out; 389 } 390 391 if (!mod_hdcp_execute_and_set(check_pairing_info_available, 392 &input->pairing_available, &status, 393 hdcp, "pairing_available")) 394 goto out; 395 if (!mod_hdcp_execute_and_set(mod_hdcp_read_pairing_info, 396 &input->pairing_info_read, &status, 397 hdcp, "pairing_info_read")) 398 goto out; 399 if (!mod_hdcp_execute_and_set(mod_hdcp_hdcp2_validate_h_prime, 400 &input->h_prime_validation, &status, 401 hdcp, "h_prime_validation")) 402 goto out; 403 out: 404 return status; 405 } 406 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) 410 { 411 enum mod_hdcp_status status = MOD_HDCP_STATUS_SUCCESS; 412 413 if (event_ctx->event != MOD_HDCP_EVENT_CALLBACK) { 414 event_ctx->unexpected_event = 1; 415 goto out; 416 } 417 418 if (!mod_hdcp_execute_and_set(mod_hdcp_write_stored_km, 419 &input->stored_km_write, &status, 420 hdcp, "stored_km_write")) 421 goto out; 422 out: 423 return status; 424 } 425 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) 429 { 430 enum mod_hdcp_status status = MOD_HDCP_STATUS_SUCCESS; 431 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; 436 goto out; 437 } 438 439 if (!mod_hdcp_execute_and_set(check_h_prime_available, 440 &input->h_prime_available, &status, 441 hdcp, "h_prime_available")) 442 goto out; 443 if (!mod_hdcp_execute_and_set(mod_hdcp_read_h_prime, 444 &input->h_prime_read, &status, 445 hdcp, "h_prime_read")) 446 goto out; 447 if (!mod_hdcp_execute_and_set(mod_hdcp_hdcp2_validate_h_prime, 448 &input->h_prime_validation, &status, 449 hdcp, "h_prime_validation")) 450 goto out; 451 out: 452 return status; 453 } 454 455 static enum mod_hdcp_status locality_check_sw(struct mod_hdcp *hdcp, 456 struct mod_hdcp_event_context *event_ctx, 457 struct mod_hdcp_transition_input_hdcp2 *input) 458 { 459 enum mod_hdcp_status status = MOD_HDCP_STATUS_SUCCESS; 460 461 if (!mod_hdcp_execute_and_set(mod_hdcp_write_lc_init, 462 &input->lc_init_write, &status, 463 hdcp, "lc_init_write")) 464 goto out; 465 if (is_dp_hdcp(hdcp)) 466 msleep(16); 467 else 468 if (!mod_hdcp_execute_and_set(poll_l_prime_available, 469 &input->l_prime_available_poll, &status, 470 hdcp, "l_prime_available_poll")) 471 goto out; 472 if (!mod_hdcp_execute_and_set(mod_hdcp_read_l_prime, 473 &input->l_prime_read, &status, 474 hdcp, "l_prime_read")) 475 goto out; 476 out: 477 return status; 478 } 479 480 static enum mod_hdcp_status locality_check_fw(struct mod_hdcp *hdcp, 481 struct mod_hdcp_event_context *event_ctx, 482 struct mod_hdcp_transition_input_hdcp2 *input) 483 { 484 enum mod_hdcp_status status = MOD_HDCP_STATUS_SUCCESS; 485 486 if (!mod_hdcp_execute_and_set(mod_hdcp_write_poll_read_lc_fw, 487 &input->l_prime_read, &status, 488 hdcp, "l_prime_read")) 489 goto out; 490 491 out: 492 return status; 493 } 494 495 static enum mod_hdcp_status locality_check(struct mod_hdcp *hdcp, 496 struct mod_hdcp_event_context *event_ctx, 497 struct mod_hdcp_transition_input_hdcp2 *input) 498 { 499 enum mod_hdcp_status status = MOD_HDCP_STATUS_SUCCESS; 500 const bool use_fw = hdcp->config.ddc.funcs.atomic_write_poll_read_i2c 501 && hdcp->config.ddc.funcs.atomic_write_poll_read_aux 502 && !hdcp->connection.link.adjust.hdcp2.force_sw_locality_check; 503 504 if (event_ctx->event != MOD_HDCP_EVENT_CALLBACK) { 505 event_ctx->unexpected_event = 1; 506 goto out; 507 } 508 509 if (!mod_hdcp_execute_and_set(mod_hdcp_hdcp2_prepare_lc_init, 510 &input->lc_init_prepare, &status, 511 hdcp, "lc_init_prepare")) 512 goto out; 513 514 status = (use_fw ? locality_check_fw : locality_check_sw)(hdcp, event_ctx, input); 515 if (status != MOD_HDCP_STATUS_SUCCESS) 516 goto out; 517 518 if (!mod_hdcp_execute_and_set(mod_hdcp_hdcp2_validate_l_prime, 519 &input->l_prime_validation, &status, 520 hdcp, "l_prime_validation")) 521 goto out; 522 out: 523 return status; 524 } 525 526 static enum mod_hdcp_status exchange_ks_and_test_for_repeater(struct mod_hdcp *hdcp, 527 struct mod_hdcp_event_context *event_ctx, 528 struct mod_hdcp_transition_input_hdcp2 *input) 529 { 530 enum mod_hdcp_status status = MOD_HDCP_STATUS_SUCCESS; 531 532 if (event_ctx->event != MOD_HDCP_EVENT_CALLBACK) { 533 event_ctx->unexpected_event = 1; 534 goto out; 535 } 536 537 if (!mod_hdcp_execute_and_set(mod_hdcp_hdcp2_prepare_eks, 538 &input->eks_prepare, &status, 539 hdcp, "eks_prepare")) 540 goto out; 541 if (!mod_hdcp_execute_and_set(mod_hdcp_write_eks, 542 &input->eks_write, &status, 543 hdcp, "eks_write")) 544 goto out; 545 out: 546 return status; 547 } 548 549 static enum mod_hdcp_status enable_encryption(struct mod_hdcp *hdcp, 550 struct mod_hdcp_event_context *event_ctx, 551 struct mod_hdcp_transition_input_hdcp2 *input) 552 { 553 enum mod_hdcp_status status = MOD_HDCP_STATUS_SUCCESS; 554 555 if (event_ctx->event != MOD_HDCP_EVENT_CALLBACK && 556 event_ctx->event != MOD_HDCP_EVENT_CPIRQ) { 557 event_ctx->unexpected_event = 1; 558 goto out; 559 } 560 if (event_ctx->event == MOD_HDCP_EVENT_CPIRQ) { 561 process_rxstatus(hdcp, event_ctx, input, &status); 562 goto out; 563 } 564 565 if (is_hdmi_dvi_sl_hdcp(hdcp)) { 566 if (!process_rxstatus(hdcp, event_ctx, input, &status)) 567 goto out; 568 if (event_ctx->rx_id_list_ready) 569 goto out; 570 } 571 if (!mod_hdcp_execute_and_set(mod_hdcp_hdcp2_enable_encryption, 572 &input->enable_encryption, &status, 573 hdcp, "enable_encryption")) 574 goto out; 575 if (is_dp_mst_hdcp(hdcp)) { 576 if (!mod_hdcp_execute_and_set( 577 mod_hdcp_hdcp2_enable_dp_stream_encryption, 578 &input->stream_encryption_dp, &status, 579 hdcp, "stream_encryption_dp")) 580 goto out; 581 } 582 out: 583 return status; 584 } 585 586 static enum mod_hdcp_status authenticated(struct mod_hdcp *hdcp, 587 struct mod_hdcp_event_context *event_ctx, 588 struct mod_hdcp_transition_input_hdcp2 *input) 589 { 590 enum mod_hdcp_status status = MOD_HDCP_STATUS_SUCCESS; 591 592 if (event_ctx->event != MOD_HDCP_EVENT_CALLBACK && 593 event_ctx->event != MOD_HDCP_EVENT_CPIRQ) { 594 event_ctx->unexpected_event = 1; 595 goto out; 596 } 597 598 process_rxstatus(hdcp, event_ctx, input, &status); 599 out: 600 return status; 601 } 602 603 static enum mod_hdcp_status wait_for_rx_id_list(struct mod_hdcp *hdcp, 604 struct mod_hdcp_event_context *event_ctx, 605 struct mod_hdcp_transition_input_hdcp2 *input) 606 { 607 enum mod_hdcp_status status = MOD_HDCP_STATUS_SUCCESS; 608 609 if (event_ctx->event != MOD_HDCP_EVENT_CALLBACK && 610 event_ctx->event != MOD_HDCP_EVENT_CPIRQ && 611 event_ctx->event != MOD_HDCP_EVENT_WATCHDOG_TIMEOUT) { 612 event_ctx->unexpected_event = 1; 613 goto out; 614 } 615 616 if (!process_rxstatus(hdcp, event_ctx, input, &status)) 617 goto out; 618 if (!event_ctx->rx_id_list_ready) { 619 status = MOD_HDCP_STATUS_HDCP2_RX_ID_LIST_NOT_READY; 620 goto out; 621 } 622 out: 623 return status; 624 } 625 626 static enum mod_hdcp_status verify_rx_id_list_and_send_ack(struct mod_hdcp *hdcp, 627 struct mod_hdcp_event_context *event_ctx, 628 struct mod_hdcp_transition_input_hdcp2 *input) 629 { 630 enum mod_hdcp_status status = MOD_HDCP_STATUS_SUCCESS; 631 632 if (event_ctx->event != MOD_HDCP_EVENT_CALLBACK && 633 event_ctx->event != MOD_HDCP_EVENT_CPIRQ) { 634 event_ctx->unexpected_event = 1; 635 goto out; 636 } 637 if (event_ctx->event == MOD_HDCP_EVENT_CPIRQ) { 638 process_rxstatus(hdcp, event_ctx, input, &status); 639 goto out; 640 } 641 642 if (!mod_hdcp_execute_and_set(mod_hdcp_read_rx_id_list, 643 &input->rx_id_list_read, 644 &status, hdcp, "receiver_id_list_read")) 645 goto out; 646 if (!mod_hdcp_execute_and_set(check_device_count, 647 &input->device_count_check, 648 &status, hdcp, "device_count_check")) 649 goto out; 650 if (!mod_hdcp_execute_and_set(mod_hdcp_hdcp2_validate_rx_id_list, 651 &input->rx_id_list_validation, 652 &status, hdcp, "rx_id_list_validation")) 653 goto out; 654 if (!mod_hdcp_execute_and_set(mod_hdcp_write_repeater_auth_ack, 655 &input->repeater_auth_ack_write, 656 &status, hdcp, "repeater_auth_ack_write")) 657 goto out; 658 out: 659 return status; 660 } 661 662 static enum mod_hdcp_status send_stream_management(struct mod_hdcp *hdcp, 663 struct mod_hdcp_event_context *event_ctx, 664 struct mod_hdcp_transition_input_hdcp2 *input) 665 { 666 enum mod_hdcp_status status = MOD_HDCP_STATUS_SUCCESS; 667 668 if (event_ctx->event != MOD_HDCP_EVENT_CALLBACK && 669 event_ctx->event != MOD_HDCP_EVENT_CPIRQ) { 670 event_ctx->unexpected_event = 1; 671 goto out; 672 } 673 if (event_ctx->event == MOD_HDCP_EVENT_CPIRQ) { 674 process_rxstatus(hdcp, event_ctx, input, &status); 675 goto out; 676 } 677 678 if (is_hdmi_dvi_sl_hdcp(hdcp)) { 679 if (!process_rxstatus(hdcp, event_ctx, input, &status)) 680 goto out; 681 if (event_ctx->rx_id_list_ready) 682 goto out; 683 } 684 if (!mod_hdcp_execute_and_set(mod_hdcp_hdcp2_prepare_stream_management, 685 &input->prepare_stream_manage, 686 &status, hdcp, "prepare_stream_manage")) 687 goto out; 688 689 if (!mod_hdcp_execute_and_set(mod_hdcp_write_stream_manage, 690 &input->stream_manage_write, 691 &status, hdcp, "stream_manage_write")) 692 goto out; 693 out: 694 return status; 695 } 696 697 static enum mod_hdcp_status validate_stream_ready(struct mod_hdcp *hdcp, 698 struct mod_hdcp_event_context *event_ctx, 699 struct mod_hdcp_transition_input_hdcp2 *input) 700 { 701 enum mod_hdcp_status status = MOD_HDCP_STATUS_SUCCESS; 702 703 if (event_ctx->event != MOD_HDCP_EVENT_CALLBACK && 704 event_ctx->event != MOD_HDCP_EVENT_CPIRQ && 705 event_ctx->event != MOD_HDCP_EVENT_WATCHDOG_TIMEOUT) { 706 event_ctx->unexpected_event = 1; 707 goto out; 708 } 709 if (event_ctx->event == MOD_HDCP_EVENT_CPIRQ) { 710 process_rxstatus(hdcp, event_ctx, input, &status); 711 goto out; 712 } 713 714 if (is_hdmi_dvi_sl_hdcp(hdcp)) { 715 if (!process_rxstatus(hdcp, event_ctx, input, &status)) 716 goto out; 717 if (event_ctx->rx_id_list_ready) 718 goto out; 719 } 720 if (is_hdmi_dvi_sl_hdcp(hdcp)) 721 if (!mod_hdcp_execute_and_set(check_stream_ready_available, 722 &input->stream_ready_available, 723 &status, hdcp, "stream_ready_available")) 724 goto out; 725 if (!mod_hdcp_execute_and_set(mod_hdcp_read_stream_ready, 726 &input->stream_ready_read, 727 &status, hdcp, "stream_ready_read")) 728 goto out; 729 if (!mod_hdcp_execute_and_set(mod_hdcp_hdcp2_validate_stream_ready, 730 &input->stream_ready_validation, 731 &status, hdcp, "stream_ready_validation")) 732 goto out; 733 734 out: 735 return status; 736 } 737 738 static enum mod_hdcp_status determine_rx_hdcp_capable_dp(struct mod_hdcp *hdcp, 739 struct mod_hdcp_event_context *event_ctx, 740 struct mod_hdcp_transition_input_hdcp2 *input) 741 { 742 enum mod_hdcp_status status = MOD_HDCP_STATUS_SUCCESS; 743 744 if (event_ctx->event != MOD_HDCP_EVENT_CALLBACK) { 745 event_ctx->unexpected_event = 1; 746 goto out; 747 } 748 749 if (!mod_hdcp_execute_and_set(mod_hdcp_read_rxcaps, 750 &input->rx_caps_read_dp, 751 &status, hdcp, "rx_caps_read_dp")) 752 goto out; 753 if (!mod_hdcp_execute_and_set(check_hdcp2_capable, 754 &input->hdcp2_capable_check, &status, 755 hdcp, "hdcp2_capable_check")) 756 goto out; 757 out: 758 return status; 759 } 760 761 static enum mod_hdcp_status send_content_stream_type_dp(struct mod_hdcp *hdcp, 762 struct mod_hdcp_event_context *event_ctx, 763 struct mod_hdcp_transition_input_hdcp2 *input) 764 { 765 enum mod_hdcp_status status = MOD_HDCP_STATUS_SUCCESS; 766 767 if (event_ctx->event != MOD_HDCP_EVENT_CALLBACK && 768 event_ctx->event != MOD_HDCP_EVENT_CPIRQ) { 769 event_ctx->unexpected_event = 1; 770 goto out; 771 } 772 773 if (!process_rxstatus(hdcp, event_ctx, input, &status)) 774 goto out; 775 if (!mod_hdcp_execute_and_set(mod_hdcp_write_content_type, 776 &input->content_stream_type_write, &status, 777 hdcp, "content_stream_type_write")) 778 goto out; 779 out: 780 return status; 781 } 782 783 enum mod_hdcp_status mod_hdcp_hdcp2_execution(struct mod_hdcp *hdcp, 784 struct mod_hdcp_event_context *event_ctx, 785 struct mod_hdcp_transition_input_hdcp2 *input) 786 { 787 enum mod_hdcp_status status = MOD_HDCP_STATUS_SUCCESS; 788 789 switch (current_state(hdcp)) { 790 case H2_A0_KNOWN_HDCP2_CAPABLE_RX: 791 status = known_hdcp2_capable_rx(hdcp, event_ctx, input); 792 break; 793 case H2_A1_SEND_AKE_INIT: 794 status = send_ake_init(hdcp, event_ctx, input); 795 break; 796 case H2_A1_VALIDATE_AKE_CERT: 797 status = validate_ake_cert(hdcp, event_ctx, input); 798 break; 799 case H2_A1_SEND_NO_STORED_KM: 800 status = send_no_stored_km(hdcp, event_ctx, input); 801 break; 802 case H2_A1_READ_H_PRIME: 803 status = read_h_prime(hdcp, event_ctx, input); 804 break; 805 case H2_A1_READ_PAIRING_INFO_AND_VALIDATE_H_PRIME: 806 status = read_pairing_info_and_validate_h_prime(hdcp, 807 event_ctx, input); 808 break; 809 case H2_A1_SEND_STORED_KM: 810 status = send_stored_km(hdcp, event_ctx, input); 811 break; 812 case H2_A1_VALIDATE_H_PRIME: 813 status = validate_h_prime(hdcp, event_ctx, input); 814 break; 815 case H2_A2_LOCALITY_CHECK: 816 status = locality_check(hdcp, event_ctx, input); 817 break; 818 case H2_A3_EXCHANGE_KS_AND_TEST_FOR_REPEATER: 819 status = exchange_ks_and_test_for_repeater(hdcp, event_ctx, input); 820 break; 821 case H2_ENABLE_ENCRYPTION: 822 status = enable_encryption(hdcp, event_ctx, input); 823 break; 824 case H2_A5_AUTHENTICATED: 825 status = authenticated(hdcp, event_ctx, input); 826 break; 827 case H2_A6_WAIT_FOR_RX_ID_LIST: 828 status = wait_for_rx_id_list(hdcp, event_ctx, input); 829 break; 830 case H2_A78_VERIFY_RX_ID_LIST_AND_SEND_ACK: 831 status = verify_rx_id_list_and_send_ack(hdcp, event_ctx, input); 832 break; 833 case H2_A9_SEND_STREAM_MANAGEMENT: 834 status = send_stream_management(hdcp, event_ctx, input); 835 break; 836 case H2_A9_VALIDATE_STREAM_READY: 837 status = validate_stream_ready(hdcp, event_ctx, input); 838 break; 839 default: 840 status = MOD_HDCP_STATUS_INVALID_STATE; 841 break; 842 } 843 844 return status; 845 } 846 847 enum mod_hdcp_status mod_hdcp_hdcp2_dp_execution(struct mod_hdcp *hdcp, 848 struct mod_hdcp_event_context *event_ctx, 849 struct mod_hdcp_transition_input_hdcp2 *input) 850 { 851 enum mod_hdcp_status status = MOD_HDCP_STATUS_SUCCESS; 852 853 switch (current_state(hdcp)) { 854 case D2_A0_DETERMINE_RX_HDCP_CAPABLE: 855 status = determine_rx_hdcp_capable_dp(hdcp, event_ctx, input); 856 break; 857 case D2_A1_SEND_AKE_INIT: 858 status = send_ake_init(hdcp, event_ctx, input); 859 break; 860 case D2_A1_VALIDATE_AKE_CERT: 861 status = validate_ake_cert(hdcp, event_ctx, input); 862 break; 863 case D2_A1_SEND_NO_STORED_KM: 864 status = send_no_stored_km(hdcp, event_ctx, input); 865 break; 866 case D2_A1_READ_H_PRIME: 867 status = read_h_prime(hdcp, event_ctx, input); 868 break; 869 case D2_A1_READ_PAIRING_INFO_AND_VALIDATE_H_PRIME: 870 status = read_pairing_info_and_validate_h_prime(hdcp, 871 event_ctx, input); 872 break; 873 case D2_A1_SEND_STORED_KM: 874 status = send_stored_km(hdcp, event_ctx, input); 875 break; 876 case D2_A1_VALIDATE_H_PRIME: 877 status = validate_h_prime(hdcp, event_ctx, input); 878 break; 879 case D2_A2_LOCALITY_CHECK: 880 status = locality_check(hdcp, event_ctx, input); 881 break; 882 case D2_A34_EXCHANGE_KS_AND_TEST_FOR_REPEATER: 883 status = exchange_ks_and_test_for_repeater(hdcp, 884 event_ctx, input); 885 break; 886 case D2_SEND_CONTENT_STREAM_TYPE: 887 status = send_content_stream_type_dp(hdcp, event_ctx, input); 888 break; 889 case D2_ENABLE_ENCRYPTION: 890 status = enable_encryption(hdcp, event_ctx, input); 891 break; 892 case D2_A5_AUTHENTICATED: 893 status = authenticated(hdcp, event_ctx, input); 894 break; 895 case D2_A6_WAIT_FOR_RX_ID_LIST: 896 status = wait_for_rx_id_list(hdcp, event_ctx, input); 897 break; 898 case D2_A78_VERIFY_RX_ID_LIST_AND_SEND_ACK: 899 status = verify_rx_id_list_and_send_ack(hdcp, event_ctx, input); 900 break; 901 case D2_A9_SEND_STREAM_MANAGEMENT: 902 status = send_stream_management(hdcp, event_ctx, input); 903 break; 904 case D2_A9_VALIDATE_STREAM_READY: 905 status = validate_stream_ready(hdcp, event_ctx, input); 906 break; 907 default: 908 status = MOD_HDCP_STATUS_INVALID_STATE; 909 break; 910 } 911 912 return status; 913 } 914