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 struct mod_hdcp_trace *trace = &hdcp->connection.trace; 52 53 if (is_dp_hdcp(hdcp)) 54 status = (hdcp->auth.msg.hdcp2.rxcaps_dp[0] == HDCP_2_2_RX_CAPS_VERSION_VAL) && 55 HDCP_2_2_DP_HDCP_CAPABLE(hdcp->auth.msg.hdcp2.rxcaps_dp[2]) ? 56 MOD_HDCP_STATUS_SUCCESS : 57 MOD_HDCP_STATUS_HDCP2_NOT_CAPABLE; 58 else 59 status = (hdcp->auth.msg.hdcp2.hdcp2version_hdmi 60 & HDCP_2_2_HDMI_SUPPORT_MASK) 61 ? MOD_HDCP_STATUS_SUCCESS 62 : MOD_HDCP_STATUS_HDCP2_NOT_CAPABLE; 63 64 if (status == MOD_HDCP_STATUS_SUCCESS) 65 trace->hdcp2.attempt_count++; 66 67 return status; 68 } 69 70 static inline enum mod_hdcp_status check_reauthentication_request( 71 struct mod_hdcp *hdcp) 72 { 73 uint8_t ret = 0; 74 75 if (is_dp_hdcp(hdcp)) 76 ret = HDCP_2_2_DP_RXSTATUS_REAUTH_REQ(hdcp->auth.msg.hdcp2.rxstatus_dp) ? 77 MOD_HDCP_STATUS_HDCP2_REAUTH_REQUEST : 78 MOD_HDCP_STATUS_SUCCESS; 79 else 80 ret = HDCP_2_2_HDMI_RXSTATUS_REAUTH_REQ(hdcp->auth.msg.hdcp2.rxstatus[1]) ? 81 MOD_HDCP_STATUS_HDCP2_REAUTH_REQUEST : 82 MOD_HDCP_STATUS_SUCCESS; 83 return ret; 84 } 85 86 static inline enum mod_hdcp_status check_link_integrity_failure_dp( 87 struct mod_hdcp *hdcp) 88 { 89 return HDCP_2_2_DP_RXSTATUS_LINK_FAILED(hdcp->auth.msg.hdcp2.rxstatus_dp) ? 90 MOD_HDCP_STATUS_HDCP2_REAUTH_LINK_INTEGRITY_FAILURE : 91 MOD_HDCP_STATUS_SUCCESS; 92 } 93 94 static enum mod_hdcp_status check_ake_cert_available(struct mod_hdcp *hdcp) 95 { 96 enum mod_hdcp_status status; 97 98 if (is_dp_hdcp(hdcp)) { 99 status = MOD_HDCP_STATUS_SUCCESS; 100 } else { 101 status = mod_hdcp_read_rxstatus(hdcp); 102 if (status == MOD_HDCP_STATUS_SUCCESS) { 103 const uint16_t size = get_hdmi_rxstatus_msg_size(hdcp->auth.msg.hdcp2.rxstatus); 104 status = (size == sizeof(hdcp->auth.msg.hdcp2.ake_cert)) ? 105 MOD_HDCP_STATUS_SUCCESS : 106 MOD_HDCP_STATUS_HDCP2_AKE_CERT_PENDING; 107 } 108 } 109 return status; 110 } 111 112 static enum mod_hdcp_status check_h_prime_available(struct mod_hdcp *hdcp) 113 { 114 enum mod_hdcp_status status; 115 116 status = mod_hdcp_read_rxstatus(hdcp); 117 if (status != MOD_HDCP_STATUS_SUCCESS) 118 goto out; 119 120 if (is_dp_hdcp(hdcp)) { 121 status = HDCP_2_2_DP_RXSTATUS_H_PRIME(hdcp->auth.msg.hdcp2.rxstatus_dp) ? 122 MOD_HDCP_STATUS_SUCCESS : 123 MOD_HDCP_STATUS_HDCP2_H_PRIME_PENDING; 124 } else { 125 const uint16_t size = get_hdmi_rxstatus_msg_size(hdcp->auth.msg.hdcp2.rxstatus); 126 status = (size == sizeof(hdcp->auth.msg.hdcp2.ake_h_prime)) ? 127 MOD_HDCP_STATUS_SUCCESS : 128 MOD_HDCP_STATUS_HDCP2_H_PRIME_PENDING; 129 } 130 out: 131 return status; 132 } 133 134 static enum mod_hdcp_status check_pairing_info_available(struct mod_hdcp *hdcp) 135 { 136 enum mod_hdcp_status status; 137 138 status = mod_hdcp_read_rxstatus(hdcp); 139 if (status != MOD_HDCP_STATUS_SUCCESS) 140 goto out; 141 142 if (is_dp_hdcp(hdcp)) { 143 status = HDCP_2_2_DP_RXSTATUS_PAIRING(hdcp->auth.msg.hdcp2.rxstatus_dp) ? 144 MOD_HDCP_STATUS_SUCCESS : 145 MOD_HDCP_STATUS_HDCP2_PAIRING_INFO_PENDING; 146 } else { 147 const uint16_t size = get_hdmi_rxstatus_msg_size(hdcp->auth.msg.hdcp2.rxstatus); 148 status = (size == sizeof(hdcp->auth.msg.hdcp2.ake_pairing_info)) ? 149 MOD_HDCP_STATUS_SUCCESS : 150 MOD_HDCP_STATUS_HDCP2_PAIRING_INFO_PENDING; 151 } 152 out: 153 return status; 154 } 155 156 static enum mod_hdcp_status poll_l_prime_available(struct mod_hdcp *hdcp) 157 { 158 enum mod_hdcp_status status = MOD_HDCP_STATUS_FAILURE; 159 uint16_t max_wait = 20; // units of ms 160 uint16_t num_polls = 5; 161 uint16_t wait_time = max_wait / num_polls; 162 163 if (is_dp_hdcp(hdcp)) 164 status = MOD_HDCP_STATUS_INVALID_OPERATION; 165 else 166 for (; num_polls; num_polls--) { 167 msleep(wait_time); 168 169 status = mod_hdcp_read_rxstatus(hdcp); 170 if (status != MOD_HDCP_STATUS_SUCCESS) 171 break; 172 173 const uint16_t size = get_hdmi_rxstatus_msg_size(hdcp->auth.msg.hdcp2.rxstatus); 174 status = (size == sizeof(hdcp->auth.msg.hdcp2.lc_l_prime)) ? 175 MOD_HDCP_STATUS_SUCCESS : 176 MOD_HDCP_STATUS_HDCP2_L_PRIME_PENDING; 177 if (status == MOD_HDCP_STATUS_SUCCESS) 178 break; 179 } 180 return status; 181 } 182 183 static enum mod_hdcp_status check_stream_ready_available(struct mod_hdcp *hdcp) 184 { 185 enum mod_hdcp_status status; 186 187 if (is_dp_hdcp(hdcp)) { 188 status = MOD_HDCP_STATUS_INVALID_OPERATION; 189 } else { 190 status = mod_hdcp_read_rxstatus(hdcp); 191 if (status != MOD_HDCP_STATUS_SUCCESS) 192 goto out; 193 const uint16_t size = get_hdmi_rxstatus_msg_size(hdcp->auth.msg.hdcp2.rxstatus); 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; 197 } 198 out: 199 return status; 200 } 201 202 static inline uint8_t get_device_count(struct mod_hdcp *hdcp) 203 { 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); 206 } 207 208 static enum mod_hdcp_status check_device_count(struct mod_hdcp *hdcp) 209 { 210 struct mod_hdcp_trace *trace = &hdcp->connection.trace; 211 212 /* Avoid device count == 0 to do authentication */ 213 if (get_device_count(hdcp) == 0) 214 return MOD_HDCP_STATUS_HDCP1_DEVICE_COUNT_MISMATCH_FAILURE; 215 216 trace->hdcp2.downstream_device_count = get_device_count(hdcp); 217 trace->hdcp2.hdcp1_device_downstream = 218 HDCP_2_2_HDCP1_DEVICE_CONNECTED(hdcp->auth.msg.hdcp2.rx_id_list[2]); 219 trace->hdcp2.hdcp2_legacy_device_downstream = 220 HDCP_2_2_HDCP_2_0_REP_CONNECTED(hdcp->auth.msg.hdcp2.rx_id_list[2]); 221 /* Some MST display may choose to report the internal panel as an HDCP RX. */ 222 /* To update this condition with 1(because the immediate repeater's internal */ 223 /* panel is possibly not included in DEVICE_COUNT) + get_device_count(hdcp). */ 224 /* Device count must be greater than or equal to tracked hdcp displays. */ 225 return ((1 + get_device_count(hdcp)) < get_active_display_count(hdcp)) ? 226 MOD_HDCP_STATUS_HDCP2_DEVICE_COUNT_MISMATCH_FAILURE : 227 MOD_HDCP_STATUS_SUCCESS; 228 } 229 230 static uint8_t process_rxstatus(struct mod_hdcp *hdcp, 231 struct mod_hdcp_event_context *event_ctx, 232 struct mod_hdcp_transition_input_hdcp2 *input, 233 enum mod_hdcp_status *status) 234 { 235 if (!mod_hdcp_execute_and_set(mod_hdcp_read_rxstatus, 236 &input->rxstatus_read, status, 237 hdcp, "rxstatus_read")) 238 goto out; 239 if (!mod_hdcp_execute_and_set(check_reauthentication_request, 240 &input->reauth_request_check, status, 241 hdcp, "reauth_request_check")) 242 goto out; 243 if (is_dp_hdcp(hdcp)) { 244 if (!mod_hdcp_execute_and_set(check_link_integrity_failure_dp, 245 &input->link_integrity_check_dp, status, 246 hdcp, "link_integrity_check_dp")) 247 goto out; 248 } 249 if (hdcp->connection.is_repeater) 250 if (check_receiver_id_list_ready(hdcp) == 251 MOD_HDCP_STATUS_SUCCESS) { 252 HDCP_INPUT_PASS_TRACE(hdcp, "rx_id_list_ready"); 253 event_ctx->rx_id_list_ready = 1; 254 if (is_dp_hdcp(hdcp)) 255 hdcp->auth.msg.hdcp2.rx_id_list_size = 256 sizeof(hdcp->auth.msg.hdcp2.rx_id_list); 257 else 258 hdcp->auth.msg.hdcp2.rx_id_list_size = 259 get_hdmi_rxstatus_msg_size(hdcp->auth.msg.hdcp2.rxstatus); 260 } 261 out: 262 return (*status == MOD_HDCP_STATUS_SUCCESS); 263 } 264 265 static enum mod_hdcp_status known_hdcp2_capable_rx(struct mod_hdcp *hdcp, 266 struct mod_hdcp_event_context *event_ctx, 267 struct mod_hdcp_transition_input_hdcp2 *input) 268 { 269 enum mod_hdcp_status status = MOD_HDCP_STATUS_SUCCESS; 270 271 if (event_ctx->event != MOD_HDCP_EVENT_CALLBACK) { 272 event_ctx->unexpected_event = 1; 273 goto out; 274 } 275 276 if (!mod_hdcp_execute_and_set(mod_hdcp_read_hdcp2version, 277 &input->hdcp2version_read, &status, 278 hdcp, "hdcp2version_read")) 279 goto out; 280 if (!mod_hdcp_execute_and_set(check_hdcp2_capable, 281 &input->hdcp2_capable_check, &status, 282 hdcp, "hdcp2_capable")) 283 goto out; 284 out: 285 return status; 286 } 287 288 static enum mod_hdcp_status send_ake_init(struct mod_hdcp *hdcp, 289 struct mod_hdcp_event_context *event_ctx, 290 struct mod_hdcp_transition_input_hdcp2 *input) 291 { 292 enum mod_hdcp_status status = MOD_HDCP_STATUS_SUCCESS; 293 294 if (event_ctx->event != MOD_HDCP_EVENT_CALLBACK) { 295 event_ctx->unexpected_event = 1; 296 goto out; 297 } 298 299 if (!mod_hdcp_execute_and_set(mod_hdcp_hdcp2_create_session, 300 &input->create_session, &status, 301 hdcp, "create_session")) 302 goto out; 303 if (!mod_hdcp_execute_and_set(mod_hdcp_hdcp2_prepare_ake_init, 304 &input->ake_init_prepare, &status, 305 hdcp, "ake_init_prepare")) 306 goto out; 307 if (!mod_hdcp_execute_and_set(mod_hdcp_write_ake_init, 308 &input->ake_init_write, &status, 309 hdcp, "ake_init_write")) 310 goto out; 311 out: 312 return status; 313 } 314 315 static enum mod_hdcp_status validate_ake_cert(struct mod_hdcp *hdcp, 316 struct mod_hdcp_event_context *event_ctx, 317 struct mod_hdcp_transition_input_hdcp2 *input) 318 { 319 enum mod_hdcp_status status = MOD_HDCP_STATUS_SUCCESS; 320 321 322 if (event_ctx->event != MOD_HDCP_EVENT_CALLBACK && 323 event_ctx->event != MOD_HDCP_EVENT_WATCHDOG_TIMEOUT) { 324 event_ctx->unexpected_event = 1; 325 goto out; 326 } 327 328 if (is_hdmi_dvi_sl_hdcp(hdcp)) 329 if (!mod_hdcp_execute_and_set(check_ake_cert_available, 330 &input->ake_cert_available, &status, 331 hdcp, "ake_cert_available")) 332 goto out; 333 if (!mod_hdcp_execute_and_set(mod_hdcp_read_ake_cert, 334 &input->ake_cert_read, &status, 335 hdcp, "ake_cert_read")) 336 goto out; 337 if (!mod_hdcp_execute_and_set(mod_hdcp_hdcp2_validate_ake_cert, 338 &input->ake_cert_validation, &status, 339 hdcp, "ake_cert_validation")) 340 goto out; 341 out: 342 return status; 343 } 344 345 static enum mod_hdcp_status send_no_stored_km(struct mod_hdcp *hdcp, 346 struct mod_hdcp_event_context *event_ctx, 347 struct mod_hdcp_transition_input_hdcp2 *input) 348 { 349 enum mod_hdcp_status status = MOD_HDCP_STATUS_SUCCESS; 350 351 if (event_ctx->event != MOD_HDCP_EVENT_CALLBACK) { 352 event_ctx->unexpected_event = 1; 353 goto out; 354 } 355 356 if (!mod_hdcp_execute_and_set(mod_hdcp_write_no_stored_km, 357 &input->no_stored_km_write, &status, 358 hdcp, "no_stored_km_write")) 359 goto out; 360 out: 361 return status; 362 } 363 364 static enum mod_hdcp_status read_h_prime(struct mod_hdcp *hdcp, 365 struct mod_hdcp_event_context *event_ctx, 366 struct mod_hdcp_transition_input_hdcp2 *input) 367 { 368 enum mod_hdcp_status status = MOD_HDCP_STATUS_SUCCESS; 369 370 if (event_ctx->event != MOD_HDCP_EVENT_CALLBACK && 371 event_ctx->event != MOD_HDCP_EVENT_CPIRQ && 372 event_ctx->event != MOD_HDCP_EVENT_WATCHDOG_TIMEOUT) { 373 event_ctx->unexpected_event = 1; 374 goto out; 375 } 376 377 if (!mod_hdcp_execute_and_set(check_h_prime_available, 378 &input->h_prime_available, &status, 379 hdcp, "h_prime_available")) 380 goto out; 381 382 if (!mod_hdcp_execute_and_set(mod_hdcp_read_h_prime, 383 &input->h_prime_read, &status, 384 hdcp, "h_prime_read")) 385 goto out; 386 out: 387 return status; 388 } 389 390 static enum mod_hdcp_status read_pairing_info_and_validate_h_prime( 391 struct mod_hdcp *hdcp, 392 struct mod_hdcp_event_context *event_ctx, 393 struct mod_hdcp_transition_input_hdcp2 *input) 394 { 395 enum mod_hdcp_status status = MOD_HDCP_STATUS_SUCCESS; 396 397 if (event_ctx->event != MOD_HDCP_EVENT_CALLBACK && 398 event_ctx->event != MOD_HDCP_EVENT_CPIRQ && 399 event_ctx->event != MOD_HDCP_EVENT_WATCHDOG_TIMEOUT) { 400 event_ctx->unexpected_event = 1; 401 goto out; 402 } 403 404 if (!mod_hdcp_execute_and_set(check_pairing_info_available, 405 &input->pairing_available, &status, 406 hdcp, "pairing_available")) 407 goto out; 408 if (!mod_hdcp_execute_and_set(mod_hdcp_read_pairing_info, 409 &input->pairing_info_read, &status, 410 hdcp, "pairing_info_read")) 411 goto out; 412 if (!mod_hdcp_execute_and_set(mod_hdcp_hdcp2_validate_h_prime, 413 &input->h_prime_validation, &status, 414 hdcp, "h_prime_validation")) 415 goto out; 416 out: 417 return status; 418 } 419 420 static enum mod_hdcp_status send_stored_km(struct mod_hdcp *hdcp, 421 struct mod_hdcp_event_context *event_ctx, 422 struct mod_hdcp_transition_input_hdcp2 *input) 423 { 424 enum mod_hdcp_status status = MOD_HDCP_STATUS_SUCCESS; 425 426 if (event_ctx->event != MOD_HDCP_EVENT_CALLBACK) { 427 event_ctx->unexpected_event = 1; 428 goto out; 429 } 430 431 if (!mod_hdcp_execute_and_set(mod_hdcp_write_stored_km, 432 &input->stored_km_write, &status, 433 hdcp, "stored_km_write")) 434 goto out; 435 out: 436 return status; 437 } 438 439 static enum mod_hdcp_status validate_h_prime(struct mod_hdcp *hdcp, 440 struct mod_hdcp_event_context *event_ctx, 441 struct mod_hdcp_transition_input_hdcp2 *input) 442 { 443 enum mod_hdcp_status status = MOD_HDCP_STATUS_SUCCESS; 444 445 if (event_ctx->event != MOD_HDCP_EVENT_CALLBACK && 446 event_ctx->event != MOD_HDCP_EVENT_CPIRQ && 447 event_ctx->event != MOD_HDCP_EVENT_WATCHDOG_TIMEOUT) { 448 event_ctx->unexpected_event = 1; 449 goto out; 450 } 451 452 if (!mod_hdcp_execute_and_set(check_h_prime_available, 453 &input->h_prime_available, &status, 454 hdcp, "h_prime_available")) 455 goto out; 456 if (!mod_hdcp_execute_and_set(mod_hdcp_read_h_prime, 457 &input->h_prime_read, &status, 458 hdcp, "h_prime_read")) 459 goto out; 460 if (!mod_hdcp_execute_and_set(mod_hdcp_hdcp2_validate_h_prime, 461 &input->h_prime_validation, &status, 462 hdcp, "h_prime_validation")) 463 goto out; 464 out: 465 return status; 466 } 467 468 static enum mod_hdcp_status locality_check_sw(struct mod_hdcp *hdcp, 469 struct mod_hdcp_event_context *event_ctx, 470 struct mod_hdcp_transition_input_hdcp2 *input) 471 { 472 enum mod_hdcp_status status = MOD_HDCP_STATUS_SUCCESS; 473 474 if (!mod_hdcp_execute_and_set(mod_hdcp_write_lc_init, 475 &input->lc_init_write, &status, 476 hdcp, "lc_init_write")) 477 goto out; 478 if (is_dp_hdcp(hdcp)) 479 msleep(16); 480 else 481 if (!mod_hdcp_execute_and_set(poll_l_prime_available, 482 &input->l_prime_available_poll, &status, 483 hdcp, "l_prime_available_poll")) 484 goto out; 485 if (!mod_hdcp_execute_and_set(mod_hdcp_read_l_prime, 486 &input->l_prime_read, &status, 487 hdcp, "l_prime_read")) 488 goto out; 489 out: 490 return status; 491 } 492 493 static enum mod_hdcp_status locality_check_fw(struct mod_hdcp *hdcp, 494 struct mod_hdcp_event_context *event_ctx, 495 struct mod_hdcp_transition_input_hdcp2 *input) 496 { 497 enum mod_hdcp_status status = MOD_HDCP_STATUS_SUCCESS; 498 499 if (!mod_hdcp_execute_and_set(mod_hdcp_write_poll_read_lc_fw, 500 &input->l_prime_read, &status, 501 hdcp, "l_prime_read")) 502 goto out; 503 504 out: 505 return status; 506 } 507 508 static enum mod_hdcp_status locality_check(struct mod_hdcp *hdcp, 509 struct mod_hdcp_event_context *event_ctx, 510 struct mod_hdcp_transition_input_hdcp2 *input) 511 { 512 enum mod_hdcp_status status = MOD_HDCP_STATUS_SUCCESS; 513 const bool use_fw = hdcp->config.ddc.funcs.atomic_write_poll_read_i2c 514 && hdcp->config.ddc.funcs.atomic_write_poll_read_aux 515 && !hdcp->connection.link.adjust.hdcp2.force_sw_locality_check; 516 517 if (event_ctx->event != MOD_HDCP_EVENT_CALLBACK) { 518 event_ctx->unexpected_event = 1; 519 goto out; 520 } 521 522 if (!mod_hdcp_execute_and_set(mod_hdcp_hdcp2_prepare_lc_init, 523 &input->lc_init_prepare, &status, 524 hdcp, "lc_init_prepare")) 525 goto out; 526 527 status = (use_fw ? locality_check_fw : locality_check_sw)(hdcp, event_ctx, input); 528 if (status != MOD_HDCP_STATUS_SUCCESS) 529 goto out; 530 531 if (!mod_hdcp_execute_and_set(mod_hdcp_hdcp2_validate_l_prime, 532 &input->l_prime_validation, &status, 533 hdcp, "l_prime_validation")) 534 goto out; 535 out: 536 return status; 537 } 538 539 static enum mod_hdcp_status exchange_ks_and_test_for_repeater(struct mod_hdcp *hdcp, 540 struct mod_hdcp_event_context *event_ctx, 541 struct mod_hdcp_transition_input_hdcp2 *input) 542 { 543 enum mod_hdcp_status status = MOD_HDCP_STATUS_SUCCESS; 544 545 if (event_ctx->event != MOD_HDCP_EVENT_CALLBACK) { 546 event_ctx->unexpected_event = 1; 547 goto out; 548 } 549 550 if (!mod_hdcp_execute_and_set(mod_hdcp_hdcp2_prepare_eks, 551 &input->eks_prepare, &status, 552 hdcp, "eks_prepare")) 553 goto out; 554 if (!mod_hdcp_execute_and_set(mod_hdcp_write_eks, 555 &input->eks_write, &status, 556 hdcp, "eks_write")) 557 goto out; 558 out: 559 return status; 560 } 561 562 static enum mod_hdcp_status enable_encryption(struct mod_hdcp *hdcp, 563 struct mod_hdcp_event_context *event_ctx, 564 struct mod_hdcp_transition_input_hdcp2 *input) 565 { 566 enum mod_hdcp_status status = MOD_HDCP_STATUS_SUCCESS; 567 568 if (event_ctx->event != MOD_HDCP_EVENT_CALLBACK && 569 event_ctx->event != MOD_HDCP_EVENT_CPIRQ) { 570 event_ctx->unexpected_event = 1; 571 goto out; 572 } 573 if (event_ctx->event == MOD_HDCP_EVENT_CPIRQ) { 574 process_rxstatus(hdcp, event_ctx, input, &status); 575 goto out; 576 } 577 578 if (is_hdmi_dvi_sl_hdcp(hdcp)) { 579 if (!process_rxstatus(hdcp, event_ctx, input, &status)) 580 goto out; 581 if (event_ctx->rx_id_list_ready) 582 goto out; 583 } 584 if (!mod_hdcp_execute_and_set(mod_hdcp_hdcp2_enable_encryption, 585 &input->enable_encryption, &status, 586 hdcp, "enable_encryption")) 587 goto out; 588 if (is_dp_mst_hdcp(hdcp)) { 589 if (!mod_hdcp_execute_and_set( 590 mod_hdcp_hdcp2_enable_dp_stream_encryption, 591 &input->stream_encryption_dp, &status, 592 hdcp, "stream_encryption_dp")) 593 goto out; 594 } 595 out: 596 return status; 597 } 598 599 static enum mod_hdcp_status authenticated(struct mod_hdcp *hdcp, 600 struct mod_hdcp_event_context *event_ctx, 601 struct mod_hdcp_transition_input_hdcp2 *input) 602 { 603 enum mod_hdcp_status status = MOD_HDCP_STATUS_SUCCESS; 604 605 if (event_ctx->event != MOD_HDCP_EVENT_CALLBACK && 606 event_ctx->event != MOD_HDCP_EVENT_CPIRQ) { 607 event_ctx->unexpected_event = 1; 608 goto out; 609 } 610 611 process_rxstatus(hdcp, event_ctx, input, &status); 612 out: 613 return status; 614 } 615 616 static enum mod_hdcp_status wait_for_rx_id_list(struct mod_hdcp *hdcp, 617 struct mod_hdcp_event_context *event_ctx, 618 struct mod_hdcp_transition_input_hdcp2 *input) 619 { 620 enum mod_hdcp_status status = MOD_HDCP_STATUS_SUCCESS; 621 622 if (event_ctx->event != MOD_HDCP_EVENT_CALLBACK && 623 event_ctx->event != MOD_HDCP_EVENT_CPIRQ && 624 event_ctx->event != MOD_HDCP_EVENT_WATCHDOG_TIMEOUT) { 625 event_ctx->unexpected_event = 1; 626 goto out; 627 } 628 629 if (!process_rxstatus(hdcp, event_ctx, input, &status)) 630 goto out; 631 if (!event_ctx->rx_id_list_ready) { 632 status = MOD_HDCP_STATUS_HDCP2_RX_ID_LIST_NOT_READY; 633 goto out; 634 } 635 out: 636 return status; 637 } 638 639 static enum mod_hdcp_status verify_rx_id_list_and_send_ack(struct mod_hdcp *hdcp, 640 struct mod_hdcp_event_context *event_ctx, 641 struct mod_hdcp_transition_input_hdcp2 *input) 642 { 643 enum mod_hdcp_status status = MOD_HDCP_STATUS_SUCCESS; 644 645 if (event_ctx->event != MOD_HDCP_EVENT_CALLBACK && 646 event_ctx->event != MOD_HDCP_EVENT_CPIRQ) { 647 event_ctx->unexpected_event = 1; 648 goto out; 649 } 650 if (event_ctx->event == MOD_HDCP_EVENT_CPIRQ) { 651 process_rxstatus(hdcp, event_ctx, input, &status); 652 goto out; 653 } 654 655 if (!mod_hdcp_execute_and_set(mod_hdcp_read_rx_id_list, 656 &input->rx_id_list_read, 657 &status, hdcp, "receiver_id_list_read")) 658 goto out; 659 if (!mod_hdcp_execute_and_set(check_device_count, 660 &input->device_count_check, 661 &status, hdcp, "device_count_check")) 662 goto out; 663 if (!mod_hdcp_execute_and_set(mod_hdcp_hdcp2_validate_rx_id_list, 664 &input->rx_id_list_validation, 665 &status, hdcp, "rx_id_list_validation")) 666 goto out; 667 if (!mod_hdcp_execute_and_set(mod_hdcp_write_repeater_auth_ack, 668 &input->repeater_auth_ack_write, 669 &status, hdcp, "repeater_auth_ack_write")) 670 goto out; 671 out: 672 return status; 673 } 674 675 static enum mod_hdcp_status send_stream_management(struct mod_hdcp *hdcp, 676 struct mod_hdcp_event_context *event_ctx, 677 struct mod_hdcp_transition_input_hdcp2 *input) 678 { 679 enum mod_hdcp_status status = MOD_HDCP_STATUS_SUCCESS; 680 681 if (event_ctx->event != MOD_HDCP_EVENT_CALLBACK && 682 event_ctx->event != MOD_HDCP_EVENT_CPIRQ) { 683 event_ctx->unexpected_event = 1; 684 goto out; 685 } 686 if (event_ctx->event == MOD_HDCP_EVENT_CPIRQ) { 687 process_rxstatus(hdcp, event_ctx, input, &status); 688 goto out; 689 } 690 691 if (is_hdmi_dvi_sl_hdcp(hdcp)) { 692 if (!process_rxstatus(hdcp, event_ctx, input, &status)) 693 goto out; 694 if (event_ctx->rx_id_list_ready) 695 goto out; 696 } 697 if (!mod_hdcp_execute_and_set(mod_hdcp_hdcp2_prepare_stream_management, 698 &input->prepare_stream_manage, 699 &status, hdcp, "prepare_stream_manage")) 700 goto out; 701 702 if (!mod_hdcp_execute_and_set(mod_hdcp_write_stream_manage, 703 &input->stream_manage_write, 704 &status, hdcp, "stream_manage_write")) 705 goto out; 706 out: 707 return status; 708 } 709 710 static enum mod_hdcp_status validate_stream_ready(struct mod_hdcp *hdcp, 711 struct mod_hdcp_event_context *event_ctx, 712 struct mod_hdcp_transition_input_hdcp2 *input) 713 { 714 enum mod_hdcp_status status = MOD_HDCP_STATUS_SUCCESS; 715 716 if (event_ctx->event != MOD_HDCP_EVENT_CALLBACK && 717 event_ctx->event != MOD_HDCP_EVENT_CPIRQ && 718 event_ctx->event != MOD_HDCP_EVENT_WATCHDOG_TIMEOUT) { 719 event_ctx->unexpected_event = 1; 720 goto out; 721 } 722 if (event_ctx->event == MOD_HDCP_EVENT_CPIRQ) { 723 process_rxstatus(hdcp, event_ctx, input, &status); 724 goto out; 725 } 726 727 if (is_hdmi_dvi_sl_hdcp(hdcp)) { 728 if (!process_rxstatus(hdcp, event_ctx, input, &status)) 729 goto out; 730 if (event_ctx->rx_id_list_ready) 731 goto out; 732 } 733 if (is_hdmi_dvi_sl_hdcp(hdcp)) 734 if (!mod_hdcp_execute_and_set(check_stream_ready_available, 735 &input->stream_ready_available, 736 &status, hdcp, "stream_ready_available")) 737 goto out; 738 if (!mod_hdcp_execute_and_set(mod_hdcp_read_stream_ready, 739 &input->stream_ready_read, 740 &status, hdcp, "stream_ready_read")) 741 goto out; 742 if (!mod_hdcp_execute_and_set(mod_hdcp_hdcp2_validate_stream_ready, 743 &input->stream_ready_validation, 744 &status, hdcp, "stream_ready_validation")) 745 goto out; 746 747 out: 748 return status; 749 } 750 751 static enum mod_hdcp_status determine_rx_hdcp_capable_dp(struct mod_hdcp *hdcp, 752 struct mod_hdcp_event_context *event_ctx, 753 struct mod_hdcp_transition_input_hdcp2 *input) 754 { 755 enum mod_hdcp_status status = MOD_HDCP_STATUS_SUCCESS; 756 757 if (event_ctx->event != MOD_HDCP_EVENT_CALLBACK) { 758 event_ctx->unexpected_event = 1; 759 goto out; 760 } 761 762 if (!mod_hdcp_execute_and_set(mod_hdcp_read_rxcaps, 763 &input->rx_caps_read_dp, 764 &status, hdcp, "rx_caps_read_dp")) 765 goto out; 766 if (!mod_hdcp_execute_and_set(check_hdcp2_capable, 767 &input->hdcp2_capable_check, &status, 768 hdcp, "hdcp2_capable_check")) 769 goto out; 770 out: 771 return status; 772 } 773 774 static enum mod_hdcp_status send_content_stream_type_dp(struct mod_hdcp *hdcp, 775 struct mod_hdcp_event_context *event_ctx, 776 struct mod_hdcp_transition_input_hdcp2 *input) 777 { 778 enum mod_hdcp_status status = MOD_HDCP_STATUS_SUCCESS; 779 780 if (event_ctx->event != MOD_HDCP_EVENT_CALLBACK && 781 event_ctx->event != MOD_HDCP_EVENT_CPIRQ) { 782 event_ctx->unexpected_event = 1; 783 goto out; 784 } 785 786 if (!process_rxstatus(hdcp, event_ctx, input, &status)) 787 goto out; 788 if (!mod_hdcp_execute_and_set(mod_hdcp_write_content_type, 789 &input->content_stream_type_write, &status, 790 hdcp, "content_stream_type_write")) 791 goto out; 792 out: 793 return status; 794 } 795 796 enum mod_hdcp_status mod_hdcp_hdcp2_execution(struct mod_hdcp *hdcp, 797 struct mod_hdcp_event_context *event_ctx, 798 struct mod_hdcp_transition_input_hdcp2 *input) 799 { 800 enum mod_hdcp_status status = MOD_HDCP_STATUS_SUCCESS; 801 802 switch (current_state(hdcp)) { 803 case H2_A0_KNOWN_HDCP2_CAPABLE_RX: 804 status = known_hdcp2_capable_rx(hdcp, event_ctx, input); 805 break; 806 case H2_A1_SEND_AKE_INIT: 807 status = send_ake_init(hdcp, event_ctx, input); 808 break; 809 case H2_A1_VALIDATE_AKE_CERT: 810 status = validate_ake_cert(hdcp, event_ctx, input); 811 break; 812 case H2_A1_SEND_NO_STORED_KM: 813 status = send_no_stored_km(hdcp, event_ctx, input); 814 break; 815 case H2_A1_READ_H_PRIME: 816 status = read_h_prime(hdcp, event_ctx, input); 817 break; 818 case H2_A1_READ_PAIRING_INFO_AND_VALIDATE_H_PRIME: 819 status = read_pairing_info_and_validate_h_prime(hdcp, 820 event_ctx, input); 821 break; 822 case H2_A1_SEND_STORED_KM: 823 status = send_stored_km(hdcp, event_ctx, input); 824 break; 825 case H2_A1_VALIDATE_H_PRIME: 826 status = validate_h_prime(hdcp, event_ctx, input); 827 break; 828 case H2_A2_LOCALITY_CHECK: 829 status = locality_check(hdcp, event_ctx, input); 830 break; 831 case H2_A3_EXCHANGE_KS_AND_TEST_FOR_REPEATER: 832 status = exchange_ks_and_test_for_repeater(hdcp, event_ctx, input); 833 break; 834 case H2_ENABLE_ENCRYPTION: 835 status = enable_encryption(hdcp, event_ctx, input); 836 break; 837 case H2_A5_AUTHENTICATED: 838 status = authenticated(hdcp, event_ctx, input); 839 break; 840 case H2_A6_WAIT_FOR_RX_ID_LIST: 841 status = wait_for_rx_id_list(hdcp, event_ctx, input); 842 break; 843 case H2_A78_VERIFY_RX_ID_LIST_AND_SEND_ACK: 844 status = verify_rx_id_list_and_send_ack(hdcp, event_ctx, input); 845 break; 846 case H2_A9_SEND_STREAM_MANAGEMENT: 847 status = send_stream_management(hdcp, event_ctx, input); 848 break; 849 case H2_A9_VALIDATE_STREAM_READY: 850 status = validate_stream_ready(hdcp, event_ctx, input); 851 break; 852 default: 853 status = MOD_HDCP_STATUS_INVALID_STATE; 854 break; 855 } 856 857 return status; 858 } 859 860 enum mod_hdcp_status mod_hdcp_hdcp2_dp_execution(struct mod_hdcp *hdcp, 861 struct mod_hdcp_event_context *event_ctx, 862 struct mod_hdcp_transition_input_hdcp2 *input) 863 { 864 enum mod_hdcp_status status = MOD_HDCP_STATUS_SUCCESS; 865 866 switch (current_state(hdcp)) { 867 case D2_A0_DETERMINE_RX_HDCP_CAPABLE: 868 status = determine_rx_hdcp_capable_dp(hdcp, event_ctx, input); 869 break; 870 case D2_A1_SEND_AKE_INIT: 871 status = send_ake_init(hdcp, event_ctx, input); 872 break; 873 case D2_A1_VALIDATE_AKE_CERT: 874 status = validate_ake_cert(hdcp, event_ctx, input); 875 break; 876 case D2_A1_SEND_NO_STORED_KM: 877 status = send_no_stored_km(hdcp, event_ctx, input); 878 break; 879 case D2_A1_READ_H_PRIME: 880 status = read_h_prime(hdcp, event_ctx, input); 881 break; 882 case D2_A1_READ_PAIRING_INFO_AND_VALIDATE_H_PRIME: 883 status = read_pairing_info_and_validate_h_prime(hdcp, 884 event_ctx, input); 885 break; 886 case D2_A1_SEND_STORED_KM: 887 status = send_stored_km(hdcp, event_ctx, input); 888 break; 889 case D2_A1_VALIDATE_H_PRIME: 890 status = validate_h_prime(hdcp, event_ctx, input); 891 break; 892 case D2_A2_LOCALITY_CHECK: 893 status = locality_check(hdcp, event_ctx, input); 894 break; 895 case D2_A34_EXCHANGE_KS_AND_TEST_FOR_REPEATER: 896 status = exchange_ks_and_test_for_repeater(hdcp, 897 event_ctx, input); 898 break; 899 case D2_SEND_CONTENT_STREAM_TYPE: 900 status = send_content_stream_type_dp(hdcp, event_ctx, input); 901 break; 902 case D2_ENABLE_ENCRYPTION: 903 status = enable_encryption(hdcp, event_ctx, input); 904 break; 905 case D2_A5_AUTHENTICATED: 906 status = authenticated(hdcp, event_ctx, input); 907 break; 908 case D2_A6_WAIT_FOR_RX_ID_LIST: 909 status = wait_for_rx_id_list(hdcp, event_ctx, input); 910 break; 911 case D2_A78_VERIFY_RX_ID_LIST_AND_SEND_ACK: 912 status = verify_rx_id_list_and_send_ack(hdcp, event_ctx, input); 913 break; 914 case D2_A9_SEND_STREAM_MANAGEMENT: 915 status = send_stream_management(hdcp, event_ctx, input); 916 break; 917 case D2_A9_VALIDATE_STREAM_READY: 918 status = validate_stream_ready(hdcp, event_ctx, input); 919 break; 920 default: 921 status = MOD_HDCP_STATUS_INVALID_STATE; 922 break; 923 } 924 925 return status; 926 } 927