2 * Copyright 2019 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.
28 static inline enum mod_hdcp_status validate_bksv(struct mod_hdcp *hdcp)
32 u8 bksv[sizeof(n)] = { };
34 memcpy(bksv, hdcp->auth.msg.hdcp1.bksv, sizeof(hdcp->auth.msg.hdcp1.bksv));
35 n = *(uint64_t *)bksv;
41 return (count == 20) ? MOD_HDCP_STATUS_SUCCESS :
42 MOD_HDCP_STATUS_HDCP1_INVALID_BKSV;
45 static inline enum mod_hdcp_status check_ksv_ready(struct mod_hdcp *hdcp)
48 return (hdcp->auth.msg.hdcp1.bstatus & DP_BSTATUS_READY) ?
49 MOD_HDCP_STATUS_SUCCESS :
50 MOD_HDCP_STATUS_HDCP1_KSV_LIST_NOT_READY;
51 return (hdcp->auth.msg.hdcp1.bcaps & DRM_HDCP_DDC_BCAPS_KSV_FIFO_READY) ?
52 MOD_HDCP_STATUS_SUCCESS :
53 MOD_HDCP_STATUS_HDCP1_KSV_LIST_NOT_READY;
56 static inline enum mod_hdcp_status check_hdcp_capable_dp(struct mod_hdcp *hdcp)
58 return (hdcp->auth.msg.hdcp1.bcaps & DP_BCAPS_HDCP_CAPABLE) ?
59 MOD_HDCP_STATUS_SUCCESS :
60 MOD_HDCP_STATUS_HDCP1_NOT_CAPABLE;
63 static inline enum mod_hdcp_status check_r0p_available_dp(struct mod_hdcp *hdcp)
65 enum mod_hdcp_status status;
66 if (is_dp_hdcp(hdcp)) {
67 status = (hdcp->auth.msg.hdcp1.bstatus &
68 DP_BSTATUS_R0_PRIME_READY) ?
69 MOD_HDCP_STATUS_SUCCESS :
70 MOD_HDCP_STATUS_HDCP1_R0_PRIME_PENDING;
72 status = MOD_HDCP_STATUS_INVALID_OPERATION;
77 static inline enum mod_hdcp_status check_link_integrity_dp(
78 struct mod_hdcp *hdcp)
80 return (hdcp->auth.msg.hdcp1.bstatus &
81 DP_BSTATUS_LINK_FAILURE) ?
82 MOD_HDCP_STATUS_HDCP1_LINK_INTEGRITY_FAILURE :
83 MOD_HDCP_STATUS_SUCCESS;
86 static inline enum mod_hdcp_status check_no_reauthentication_request_dp(
87 struct mod_hdcp *hdcp)
89 return (hdcp->auth.msg.hdcp1.bstatus & DP_BSTATUS_REAUTH_REQ) ?
90 MOD_HDCP_STATUS_HDCP1_REAUTH_REQUEST_ISSUED :
91 MOD_HDCP_STATUS_SUCCESS;
94 static inline enum mod_hdcp_status check_no_max_cascade(struct mod_hdcp *hdcp)
96 enum mod_hdcp_status status;
99 status = DRM_HDCP_MAX_CASCADE_EXCEEDED(hdcp->auth.msg.hdcp1.binfo_dp >> 8)
100 ? MOD_HDCP_STATUS_HDCP1_MAX_CASCADE_EXCEEDED_FAILURE
101 : MOD_HDCP_STATUS_SUCCESS;
103 status = DRM_HDCP_MAX_CASCADE_EXCEEDED(hdcp->auth.msg.hdcp1.bstatus >> 8)
104 ? MOD_HDCP_STATUS_HDCP1_MAX_CASCADE_EXCEEDED_FAILURE
105 : MOD_HDCP_STATUS_SUCCESS;
109 static inline enum mod_hdcp_status check_no_max_devs(struct mod_hdcp *hdcp)
111 enum mod_hdcp_status status;
113 if (is_dp_hdcp(hdcp))
114 status = DRM_HDCP_MAX_DEVICE_EXCEEDED(hdcp->auth.msg.hdcp1.binfo_dp) ?
115 MOD_HDCP_STATUS_HDCP1_MAX_DEVS_EXCEEDED_FAILURE :
116 MOD_HDCP_STATUS_SUCCESS;
118 status = DRM_HDCP_MAX_DEVICE_EXCEEDED(hdcp->auth.msg.hdcp1.bstatus) ?
119 MOD_HDCP_STATUS_HDCP1_MAX_DEVS_EXCEEDED_FAILURE :
120 MOD_HDCP_STATUS_SUCCESS;
124 static inline uint8_t get_device_count(struct mod_hdcp *hdcp)
126 return is_dp_hdcp(hdcp) ?
127 DRM_HDCP_NUM_DOWNSTREAM(hdcp->auth.msg.hdcp1.binfo_dp) :
128 DRM_HDCP_NUM_DOWNSTREAM(hdcp->auth.msg.hdcp1.bstatus);
131 static inline enum mod_hdcp_status check_device_count(struct mod_hdcp *hdcp)
133 /* Avoid device count == 0 to do authentication */
134 if (0 == get_device_count(hdcp)) {
135 return MOD_HDCP_STATUS_HDCP1_DEVICE_COUNT_MISMATCH_FAILURE;
138 /* Some MST display may choose to report the internal panel as an HDCP RX.
139 * To update this condition with 1(because the immediate repeater's internal
140 * panel is possibly not included in DEVICE_COUNT) + get_device_count(hdcp).
141 * Device count must be greater than or equal to tracked hdcp displays.
143 return ((1 + get_device_count(hdcp)) < get_active_display_count(hdcp)) ?
144 MOD_HDCP_STATUS_HDCP1_DEVICE_COUNT_MISMATCH_FAILURE :
145 MOD_HDCP_STATUS_SUCCESS;
148 static enum mod_hdcp_status wait_for_active_rx(struct mod_hdcp *hdcp,
149 struct mod_hdcp_event_context *event_ctx,
150 struct mod_hdcp_transition_input_hdcp1 *input)
152 enum mod_hdcp_status status = MOD_HDCP_STATUS_SUCCESS;
154 if (event_ctx->event != MOD_HDCP_EVENT_CALLBACK) {
155 event_ctx->unexpected_event = 1;
159 if (!mod_hdcp_execute_and_set(mod_hdcp_read_bksv,
160 &input->bksv_read, &status,
163 if (!mod_hdcp_execute_and_set(mod_hdcp_read_bcaps,
164 &input->bcaps_read, &status,
171 static enum mod_hdcp_status exchange_ksvs(struct mod_hdcp *hdcp,
172 struct mod_hdcp_event_context *event_ctx,
173 struct mod_hdcp_transition_input_hdcp1 *input)
175 enum mod_hdcp_status status = MOD_HDCP_STATUS_SUCCESS;
177 if (event_ctx->event != MOD_HDCP_EVENT_CALLBACK) {
178 event_ctx->unexpected_event = 1;
182 if (!mod_hdcp_execute_and_set(mod_hdcp_hdcp1_create_session,
183 &input->create_session, &status,
184 hdcp, "create_session"))
186 if (!mod_hdcp_execute_and_set(mod_hdcp_write_an,
187 &input->an_write, &status,
190 if (!mod_hdcp_execute_and_set(mod_hdcp_write_aksv,
191 &input->aksv_write, &status,
194 if (!mod_hdcp_execute_and_set(mod_hdcp_read_bksv,
195 &input->bksv_read, &status,
198 if (!mod_hdcp_execute_and_set(validate_bksv,
199 &input->bksv_validation, &status,
200 hdcp, "bksv_validation"))
202 if (hdcp->auth.msg.hdcp1.ainfo) {
203 if (!mod_hdcp_execute_and_set(mod_hdcp_write_ainfo,
204 &input->ainfo_write, &status,
205 hdcp, "ainfo_write"))
212 static enum mod_hdcp_status computations_validate_rx_test_for_repeater(
213 struct mod_hdcp *hdcp,
214 struct mod_hdcp_event_context *event_ctx,
215 struct mod_hdcp_transition_input_hdcp1 *input)
217 enum mod_hdcp_status status = MOD_HDCP_STATUS_SUCCESS;
219 if (event_ctx->event != MOD_HDCP_EVENT_CALLBACK) {
220 event_ctx->unexpected_event = 1;
224 if (!mod_hdcp_execute_and_set(mod_hdcp_read_r0p,
225 &input->r0p_read, &status,
228 if (!mod_hdcp_execute_and_set(mod_hdcp_hdcp1_validate_rx,
229 &input->rx_validation, &status,
230 hdcp, "rx_validation"))
232 if (hdcp->connection.is_repeater) {
233 if (!hdcp->connection.link.adjust.hdcp1.postpone_encryption)
234 if (!mod_hdcp_execute_and_set(
235 mod_hdcp_hdcp1_enable_encryption,
236 &input->encryption, &status,
240 if (!mod_hdcp_execute_and_set(mod_hdcp_hdcp1_enable_encryption,
241 &input->encryption, &status,
244 if (is_dp_mst_hdcp(hdcp))
245 if (!mod_hdcp_execute_and_set(
246 mod_hdcp_hdcp1_enable_dp_stream_encryption,
247 &input->stream_encryption_dp, &status,
248 hdcp, "stream_encryption_dp"))
255 static enum mod_hdcp_status authenticated(struct mod_hdcp *hdcp,
256 struct mod_hdcp_event_context *event_ctx,
257 struct mod_hdcp_transition_input_hdcp1 *input)
259 enum mod_hdcp_status status = MOD_HDCP_STATUS_SUCCESS;
261 if (event_ctx->event != MOD_HDCP_EVENT_CALLBACK) {
262 event_ctx->unexpected_event = 1;
266 mod_hdcp_execute_and_set(mod_hdcp_hdcp1_link_maintenance,
267 &input->link_maintenance, &status,
268 hdcp, "link_maintenance");
270 if (status != MOD_HDCP_STATUS_SUCCESS)
271 mod_hdcp_save_current_encryption_states(hdcp);
276 static enum mod_hdcp_status wait_for_ready(struct mod_hdcp *hdcp,
277 struct mod_hdcp_event_context *event_ctx,
278 struct mod_hdcp_transition_input_hdcp1 *input)
280 enum mod_hdcp_status status = MOD_HDCP_STATUS_SUCCESS;
282 if (event_ctx->event != MOD_HDCP_EVENT_CALLBACK &&
283 event_ctx->event != MOD_HDCP_EVENT_CPIRQ &&
284 event_ctx->event != MOD_HDCP_EVENT_WATCHDOG_TIMEOUT) {
285 event_ctx->unexpected_event = 1;
289 if (is_dp_hdcp(hdcp)) {
290 if (!mod_hdcp_execute_and_set(mod_hdcp_read_bstatus,
291 &input->bstatus_read, &status,
292 hdcp, "bstatus_read"))
294 if (!mod_hdcp_execute_and_set(check_link_integrity_dp,
295 &input->link_integrity_check, &status,
296 hdcp, "link_integrity_check"))
298 if (!mod_hdcp_execute_and_set(check_no_reauthentication_request_dp,
299 &input->reauth_request_check, &status,
300 hdcp, "reauth_request_check"))
303 if (!mod_hdcp_execute_and_set(mod_hdcp_read_bcaps,
304 &input->bcaps_read, &status,
308 if (!mod_hdcp_execute_and_set(check_ksv_ready,
309 &input->ready_check, &status,
310 hdcp, "ready_check"))
316 static enum mod_hdcp_status read_ksv_list(struct mod_hdcp *hdcp,
317 struct mod_hdcp_event_context *event_ctx,
318 struct mod_hdcp_transition_input_hdcp1 *input)
320 enum mod_hdcp_status status = MOD_HDCP_STATUS_SUCCESS;
321 uint8_t device_count;
323 if (event_ctx->event != MOD_HDCP_EVENT_CALLBACK) {
324 event_ctx->unexpected_event = 1;
328 if (is_dp_hdcp(hdcp)) {
329 if (!mod_hdcp_execute_and_set(mod_hdcp_read_binfo,
330 &input->binfo_read_dp, &status,
331 hdcp, "binfo_read_dp"))
334 if (!mod_hdcp_execute_and_set(mod_hdcp_read_bstatus,
335 &input->bstatus_read, &status,
336 hdcp, "bstatus_read"))
339 if (!mod_hdcp_execute_and_set(check_no_max_cascade,
340 &input->max_cascade_check, &status,
341 hdcp, "max_cascade_check"))
343 if (!mod_hdcp_execute_and_set(check_no_max_devs,
344 &input->max_devs_check, &status,
345 hdcp, "max_devs_check"))
347 if (!mod_hdcp_execute_and_set(check_device_count,
348 &input->device_count_check, &status,
349 hdcp, "device_count_check"))
351 device_count = get_device_count(hdcp);
352 hdcp->auth.msg.hdcp1.ksvlist_size = device_count*5;
353 if (!mod_hdcp_execute_and_set(mod_hdcp_read_ksvlist,
354 &input->ksvlist_read, &status,
355 hdcp, "ksvlist_read"))
357 if (!mod_hdcp_execute_and_set(mod_hdcp_read_vp,
358 &input->vp_read, &status,
361 if (!mod_hdcp_execute_and_set(mod_hdcp_hdcp1_validate_ksvlist_vp,
362 &input->ksvlist_vp_validation, &status,
363 hdcp, "ksvlist_vp_validation"))
365 if (input->encryption != PASS)
366 if (!mod_hdcp_execute_and_set(mod_hdcp_hdcp1_enable_encryption,
367 &input->encryption, &status,
370 if (is_dp_mst_hdcp(hdcp))
371 if (!mod_hdcp_execute_and_set(
372 mod_hdcp_hdcp1_enable_dp_stream_encryption,
373 &input->stream_encryption_dp, &status,
374 hdcp, "stream_encryption_dp"))
380 static enum mod_hdcp_status determine_rx_hdcp_capable_dp(struct mod_hdcp *hdcp,
381 struct mod_hdcp_event_context *event_ctx,
382 struct mod_hdcp_transition_input_hdcp1 *input)
384 enum mod_hdcp_status status = MOD_HDCP_STATUS_SUCCESS;
386 if (event_ctx->event != MOD_HDCP_EVENT_CALLBACK) {
387 event_ctx->unexpected_event = 1;
391 if (!mod_hdcp_execute_and_set(mod_hdcp_read_bcaps,
392 &input->bcaps_read, &status,
395 if (!mod_hdcp_execute_and_set(check_hdcp_capable_dp,
396 &input->hdcp_capable_dp, &status,
397 hdcp, "hdcp_capable_dp"))
403 static enum mod_hdcp_status wait_for_r0_prime_dp(struct mod_hdcp *hdcp,
404 struct mod_hdcp_event_context *event_ctx,
405 struct mod_hdcp_transition_input_hdcp1 *input)
407 enum mod_hdcp_status status = MOD_HDCP_STATUS_SUCCESS;
409 if (event_ctx->event != MOD_HDCP_EVENT_CPIRQ &&
410 event_ctx->event != MOD_HDCP_EVENT_WATCHDOG_TIMEOUT) {
411 event_ctx->unexpected_event = 1;
415 if (!mod_hdcp_execute_and_set(mod_hdcp_read_bstatus,
416 &input->bstatus_read, &status,
417 hdcp, "bstatus_read"))
419 if (!mod_hdcp_execute_and_set(check_r0p_available_dp,
420 &input->r0p_available_dp, &status,
421 hdcp, "r0p_available_dp"))
427 static enum mod_hdcp_status authenticated_dp(struct mod_hdcp *hdcp,
428 struct mod_hdcp_event_context *event_ctx,
429 struct mod_hdcp_transition_input_hdcp1 *input)
431 enum mod_hdcp_status status = MOD_HDCP_STATUS_SUCCESS;
433 if (event_ctx->event != MOD_HDCP_EVENT_CPIRQ) {
434 event_ctx->unexpected_event = 1;
438 if (status == MOD_HDCP_STATUS_SUCCESS)
439 mod_hdcp_execute_and_set(mod_hdcp_read_bstatus,
440 &input->bstatus_read, &status,
441 hdcp, "bstatus_read");
442 if (status == MOD_HDCP_STATUS_SUCCESS)
443 mod_hdcp_execute_and_set(check_link_integrity_dp,
444 &input->link_integrity_check, &status,
445 hdcp, "link_integrity_check");
446 if (status == MOD_HDCP_STATUS_SUCCESS)
447 mod_hdcp_execute_and_set(check_no_reauthentication_request_dp,
448 &input->reauth_request_check, &status,
449 hdcp, "reauth_request_check");
451 if (status != MOD_HDCP_STATUS_SUCCESS)
452 mod_hdcp_save_current_encryption_states(hdcp);
457 uint8_t mod_hdcp_execute_and_set(
458 mod_hdcp_action func, uint8_t *flag,
459 enum mod_hdcp_status *status, struct mod_hdcp *hdcp, char *str)
461 *status = func(hdcp);
462 if (*status == MOD_HDCP_STATUS_SUCCESS && *flag != PASS) {
463 HDCP_INPUT_PASS_TRACE(hdcp, str);
465 } else if (*status != MOD_HDCP_STATUS_SUCCESS && *flag != FAIL) {
466 HDCP_INPUT_FAIL_TRACE(hdcp, str);
469 return (*status == MOD_HDCP_STATUS_SUCCESS);
472 enum mod_hdcp_status mod_hdcp_hdcp1_execution(struct mod_hdcp *hdcp,
473 struct mod_hdcp_event_context *event_ctx,
474 struct mod_hdcp_transition_input_hdcp1 *input)
476 enum mod_hdcp_status status = MOD_HDCP_STATUS_SUCCESS;
478 switch (current_state(hdcp)) {
479 case H1_A0_WAIT_FOR_ACTIVE_RX:
480 status = wait_for_active_rx(hdcp, event_ctx, input);
482 case H1_A1_EXCHANGE_KSVS:
483 status = exchange_ksvs(hdcp, event_ctx, input);
485 case H1_A2_COMPUTATIONS_A3_VALIDATE_RX_A6_TEST_FOR_REPEATER:
486 status = computations_validate_rx_test_for_repeater(hdcp,
489 case H1_A45_AUTHENTICATED:
490 status = authenticated(hdcp, event_ctx, input);
492 case H1_A8_WAIT_FOR_READY:
493 status = wait_for_ready(hdcp, event_ctx, input);
495 case H1_A9_READ_KSV_LIST:
496 status = read_ksv_list(hdcp, event_ctx, input);
499 status = MOD_HDCP_STATUS_INVALID_STATE;
506 extern enum mod_hdcp_status mod_hdcp_hdcp1_dp_execution(struct mod_hdcp *hdcp,
507 struct mod_hdcp_event_context *event_ctx,
508 struct mod_hdcp_transition_input_hdcp1 *input)
510 enum mod_hdcp_status status = MOD_HDCP_STATUS_SUCCESS;
512 switch (current_state(hdcp)) {
513 case D1_A0_DETERMINE_RX_HDCP_CAPABLE:
514 status = determine_rx_hdcp_capable_dp(hdcp, event_ctx, input);
516 case D1_A1_EXCHANGE_KSVS:
517 status = exchange_ksvs(hdcp, event_ctx, input);
519 case D1_A23_WAIT_FOR_R0_PRIME:
520 status = wait_for_r0_prime_dp(hdcp, event_ctx, input);
522 case D1_A2_COMPUTATIONS_A3_VALIDATE_RX_A5_TEST_FOR_REPEATER:
523 status = computations_validate_rx_test_for_repeater(
524 hdcp, event_ctx, input);
526 case D1_A4_AUTHENTICATED:
527 status = authenticated_dp(hdcp, event_ctx, input);
529 case D1_A6_WAIT_FOR_READY:
530 status = wait_for_ready(hdcp, event_ctx, input);
532 case D1_A7_READ_KSV_LIST:
533 status = read_ksv_list(hdcp, event_ctx, input);
536 status = MOD_HDCP_STATUS_INVALID_STATE;