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)
33 memcpy(&n, hdcp->auth.msg.hdcp1.bksv, sizeof(uint64_t));
39 return (count == 20) ? MOD_HDCP_STATUS_SUCCESS :
40 MOD_HDCP_STATUS_HDCP1_INVALID_BKSV;
43 static inline enum mod_hdcp_status check_ksv_ready(struct mod_hdcp *hdcp)
46 return (hdcp->auth.msg.hdcp1.bstatus & DP_BSTATUS_READY) ?
47 MOD_HDCP_STATUS_SUCCESS :
48 MOD_HDCP_STATUS_HDCP1_KSV_LIST_NOT_READY;
49 return (hdcp->auth.msg.hdcp1.bcaps & DRM_HDCP_DDC_BCAPS_KSV_FIFO_READY) ?
50 MOD_HDCP_STATUS_SUCCESS :
51 MOD_HDCP_STATUS_HDCP1_KSV_LIST_NOT_READY;
54 static inline enum mod_hdcp_status check_hdcp_capable_dp(struct mod_hdcp *hdcp)
56 return (hdcp->auth.msg.hdcp1.bcaps & DP_BCAPS_HDCP_CAPABLE) ?
57 MOD_HDCP_STATUS_SUCCESS :
58 MOD_HDCP_STATUS_HDCP1_NOT_CAPABLE;
61 static inline enum mod_hdcp_status check_r0p_available_dp(struct mod_hdcp *hdcp)
63 enum mod_hdcp_status status;
64 if (is_dp_hdcp(hdcp)) {
65 status = (hdcp->auth.msg.hdcp1.bstatus &
66 DP_BSTATUS_R0_PRIME_READY) ?
67 MOD_HDCP_STATUS_SUCCESS :
68 MOD_HDCP_STATUS_HDCP1_R0_PRIME_PENDING;
70 status = MOD_HDCP_STATUS_INVALID_OPERATION;
75 static inline enum mod_hdcp_status check_link_integrity_dp(
76 struct mod_hdcp *hdcp)
78 return (hdcp->auth.msg.hdcp1.bstatus &
79 DP_BSTATUS_LINK_FAILURE) ?
80 MOD_HDCP_STATUS_HDCP1_LINK_INTEGRITY_FAILURE :
81 MOD_HDCP_STATUS_SUCCESS;
84 static inline enum mod_hdcp_status check_no_reauthentication_request_dp(
85 struct mod_hdcp *hdcp)
87 return (hdcp->auth.msg.hdcp1.bstatus & DP_BSTATUS_REAUTH_REQ) ?
88 MOD_HDCP_STATUS_HDCP1_REAUTH_REQUEST_ISSUED :
89 MOD_HDCP_STATUS_SUCCESS;
92 static inline enum mod_hdcp_status check_no_max_cascade(struct mod_hdcp *hdcp)
94 enum mod_hdcp_status status;
97 status = DRM_HDCP_MAX_CASCADE_EXCEEDED(hdcp->auth.msg.hdcp1.binfo_dp >> 8)
98 ? MOD_HDCP_STATUS_HDCP1_MAX_CASCADE_EXCEEDED_FAILURE
99 : MOD_HDCP_STATUS_SUCCESS;
101 status = DRM_HDCP_MAX_CASCADE_EXCEEDED(hdcp->auth.msg.hdcp1.bstatus >> 8)
102 ? MOD_HDCP_STATUS_HDCP1_MAX_CASCADE_EXCEEDED_FAILURE
103 : MOD_HDCP_STATUS_SUCCESS;
107 static inline enum mod_hdcp_status check_no_max_devs(struct mod_hdcp *hdcp)
109 enum mod_hdcp_status status;
111 if (is_dp_hdcp(hdcp))
112 status = DRM_HDCP_MAX_DEVICE_EXCEEDED(hdcp->auth.msg.hdcp1.binfo_dp) ?
113 MOD_HDCP_STATUS_HDCP1_MAX_DEVS_EXCEEDED_FAILURE :
114 MOD_HDCP_STATUS_SUCCESS;
116 status = DRM_HDCP_MAX_DEVICE_EXCEEDED(hdcp->auth.msg.hdcp1.bstatus) ?
117 MOD_HDCP_STATUS_HDCP1_MAX_DEVS_EXCEEDED_FAILURE :
118 MOD_HDCP_STATUS_SUCCESS;
122 static inline uint8_t get_device_count(struct mod_hdcp *hdcp)
124 return is_dp_hdcp(hdcp) ?
125 DRM_HDCP_NUM_DOWNSTREAM(hdcp->auth.msg.hdcp1.binfo_dp) :
126 DRM_HDCP_NUM_DOWNSTREAM(hdcp->auth.msg.hdcp1.bstatus);
129 static inline enum mod_hdcp_status check_device_count(struct mod_hdcp *hdcp)
131 /* Some MST display may choose to report the internal panel as an HDCP RX.
132 * To update this condition with 1(because the immediate repeater's internal
133 * panel is possibly not included in DEVICE_COUNT) + get_device_count(hdcp).
134 * Device count must be greater than or equal to tracked hdcp displays.
136 return ((1 + get_device_count(hdcp)) < get_active_display_count(hdcp)) ?
137 MOD_HDCP_STATUS_HDCP1_DEVICE_COUNT_MISMATCH_FAILURE :
138 MOD_HDCP_STATUS_SUCCESS;
141 static enum mod_hdcp_status wait_for_active_rx(struct mod_hdcp *hdcp,
142 struct mod_hdcp_event_context *event_ctx,
143 struct mod_hdcp_transition_input_hdcp1 *input)
145 enum mod_hdcp_status status = MOD_HDCP_STATUS_SUCCESS;
147 if (event_ctx->event != MOD_HDCP_EVENT_CALLBACK) {
148 event_ctx->unexpected_event = 1;
152 if (!mod_hdcp_execute_and_set(mod_hdcp_read_bksv,
153 &input->bksv_read, &status,
156 if (!mod_hdcp_execute_and_set(mod_hdcp_read_bcaps,
157 &input->bcaps_read, &status,
164 static enum mod_hdcp_status exchange_ksvs(struct mod_hdcp *hdcp,
165 struct mod_hdcp_event_context *event_ctx,
166 struct mod_hdcp_transition_input_hdcp1 *input)
168 enum mod_hdcp_status status = MOD_HDCP_STATUS_SUCCESS;
170 if (event_ctx->event != MOD_HDCP_EVENT_CALLBACK) {
171 event_ctx->unexpected_event = 1;
175 if (!mod_hdcp_execute_and_set(mod_hdcp_hdcp1_create_session,
176 &input->create_session, &status,
177 hdcp, "create_session"))
179 if (!mod_hdcp_execute_and_set(mod_hdcp_write_an,
180 &input->an_write, &status,
183 if (!mod_hdcp_execute_and_set(mod_hdcp_write_aksv,
184 &input->aksv_write, &status,
187 if (!mod_hdcp_execute_and_set(mod_hdcp_read_bksv,
188 &input->bksv_read, &status,
191 if (!mod_hdcp_execute_and_set(validate_bksv,
192 &input->bksv_validation, &status,
193 hdcp, "bksv_validation"))
195 if (hdcp->auth.msg.hdcp1.ainfo) {
196 if (!mod_hdcp_execute_and_set(mod_hdcp_write_ainfo,
197 &input->ainfo_write, &status,
198 hdcp, "ainfo_write"))
205 static enum mod_hdcp_status computations_validate_rx_test_for_repeater(
206 struct mod_hdcp *hdcp,
207 struct mod_hdcp_event_context *event_ctx,
208 struct mod_hdcp_transition_input_hdcp1 *input)
210 enum mod_hdcp_status status = MOD_HDCP_STATUS_SUCCESS;
212 if (event_ctx->event != MOD_HDCP_EVENT_CALLBACK) {
213 event_ctx->unexpected_event = 1;
217 if (!mod_hdcp_execute_and_set(mod_hdcp_read_r0p,
218 &input->r0p_read, &status,
221 if (!mod_hdcp_execute_and_set(mod_hdcp_hdcp1_validate_rx,
222 &input->rx_validation, &status,
223 hdcp, "rx_validation"))
225 if (hdcp->connection.is_repeater) {
226 if (!hdcp->connection.link.adjust.hdcp1.postpone_encryption)
227 if (!mod_hdcp_execute_and_set(
228 mod_hdcp_hdcp1_enable_encryption,
229 &input->encryption, &status,
233 if (!mod_hdcp_execute_and_set(mod_hdcp_hdcp1_enable_encryption,
234 &input->encryption, &status,
237 if (is_dp_mst_hdcp(hdcp))
238 if (!mod_hdcp_execute_and_set(
239 mod_hdcp_hdcp1_enable_dp_stream_encryption,
240 &input->stream_encryption_dp, &status,
241 hdcp, "stream_encryption_dp"))
248 static enum mod_hdcp_status authenticated(struct mod_hdcp *hdcp,
249 struct mod_hdcp_event_context *event_ctx,
250 struct mod_hdcp_transition_input_hdcp1 *input)
252 enum mod_hdcp_status status = MOD_HDCP_STATUS_SUCCESS;
254 if (event_ctx->event != MOD_HDCP_EVENT_CALLBACK) {
255 event_ctx->unexpected_event = 1;
259 mod_hdcp_execute_and_set(mod_hdcp_hdcp1_link_maintenance,
260 &input->link_maintenance, &status,
261 hdcp, "link_maintenance");
263 if (status != MOD_HDCP_STATUS_SUCCESS)
264 mod_hdcp_save_current_encryption_states(hdcp);
269 static enum mod_hdcp_status wait_for_ready(struct mod_hdcp *hdcp,
270 struct mod_hdcp_event_context *event_ctx,
271 struct mod_hdcp_transition_input_hdcp1 *input)
273 enum mod_hdcp_status status = MOD_HDCP_STATUS_SUCCESS;
275 if (event_ctx->event != MOD_HDCP_EVENT_CALLBACK &&
276 event_ctx->event != MOD_HDCP_EVENT_CPIRQ &&
277 event_ctx->event != MOD_HDCP_EVENT_WATCHDOG_TIMEOUT) {
278 event_ctx->unexpected_event = 1;
282 if (is_dp_hdcp(hdcp)) {
283 if (!mod_hdcp_execute_and_set(mod_hdcp_read_bstatus,
284 &input->bstatus_read, &status,
285 hdcp, "bstatus_read"))
287 if (!mod_hdcp_execute_and_set(check_link_integrity_dp,
288 &input->link_integrity_check, &status,
289 hdcp, "link_integrity_check"))
291 if (!mod_hdcp_execute_and_set(check_no_reauthentication_request_dp,
292 &input->reauth_request_check, &status,
293 hdcp, "reauth_request_check"))
296 if (!mod_hdcp_execute_and_set(mod_hdcp_read_bcaps,
297 &input->bcaps_read, &status,
301 if (!mod_hdcp_execute_and_set(check_ksv_ready,
302 &input->ready_check, &status,
303 hdcp, "ready_check"))
309 static enum mod_hdcp_status read_ksv_list(struct mod_hdcp *hdcp,
310 struct mod_hdcp_event_context *event_ctx,
311 struct mod_hdcp_transition_input_hdcp1 *input)
313 enum mod_hdcp_status status = MOD_HDCP_STATUS_SUCCESS;
314 uint8_t device_count;
316 if (event_ctx->event != MOD_HDCP_EVENT_CALLBACK) {
317 event_ctx->unexpected_event = 1;
321 if (is_dp_hdcp(hdcp)) {
322 if (!mod_hdcp_execute_and_set(mod_hdcp_read_binfo,
323 &input->binfo_read_dp, &status,
324 hdcp, "binfo_read_dp"))
327 if (!mod_hdcp_execute_and_set(mod_hdcp_read_bstatus,
328 &input->bstatus_read, &status,
329 hdcp, "bstatus_read"))
332 if (!mod_hdcp_execute_and_set(check_no_max_cascade,
333 &input->max_cascade_check, &status,
334 hdcp, "max_cascade_check"))
336 if (!mod_hdcp_execute_and_set(check_no_max_devs,
337 &input->max_devs_check, &status,
338 hdcp, "max_devs_check"))
340 if (!mod_hdcp_execute_and_set(check_device_count,
341 &input->device_count_check, &status,
342 hdcp, "device_count_check"))
344 device_count = get_device_count(hdcp);
345 hdcp->auth.msg.hdcp1.ksvlist_size = device_count*5;
346 if (!mod_hdcp_execute_and_set(mod_hdcp_read_ksvlist,
347 &input->ksvlist_read, &status,
348 hdcp, "ksvlist_read"))
350 if (!mod_hdcp_execute_and_set(mod_hdcp_read_vp,
351 &input->vp_read, &status,
354 if (!mod_hdcp_execute_and_set(mod_hdcp_hdcp1_validate_ksvlist_vp,
355 &input->ksvlist_vp_validation, &status,
356 hdcp, "ksvlist_vp_validation"))
358 if (input->encryption != PASS)
359 if (!mod_hdcp_execute_and_set(mod_hdcp_hdcp1_enable_encryption,
360 &input->encryption, &status,
363 if (is_dp_mst_hdcp(hdcp))
364 if (!mod_hdcp_execute_and_set(
365 mod_hdcp_hdcp1_enable_dp_stream_encryption,
366 &input->stream_encryption_dp, &status,
367 hdcp, "stream_encryption_dp"))
373 static enum mod_hdcp_status determine_rx_hdcp_capable_dp(struct mod_hdcp *hdcp,
374 struct mod_hdcp_event_context *event_ctx,
375 struct mod_hdcp_transition_input_hdcp1 *input)
377 enum mod_hdcp_status status = MOD_HDCP_STATUS_SUCCESS;
379 if (event_ctx->event != MOD_HDCP_EVENT_CALLBACK) {
380 event_ctx->unexpected_event = 1;
384 if (!mod_hdcp_execute_and_set(mod_hdcp_read_bcaps,
385 &input->bcaps_read, &status,
388 if (!mod_hdcp_execute_and_set(check_hdcp_capable_dp,
389 &input->hdcp_capable_dp, &status,
390 hdcp, "hdcp_capable_dp"))
396 static enum mod_hdcp_status wait_for_r0_prime_dp(struct mod_hdcp *hdcp,
397 struct mod_hdcp_event_context *event_ctx,
398 struct mod_hdcp_transition_input_hdcp1 *input)
400 enum mod_hdcp_status status = MOD_HDCP_STATUS_SUCCESS;
402 if (event_ctx->event != MOD_HDCP_EVENT_CPIRQ &&
403 event_ctx->event != MOD_HDCP_EVENT_WATCHDOG_TIMEOUT) {
404 event_ctx->unexpected_event = 1;
408 if (!mod_hdcp_execute_and_set(mod_hdcp_read_bstatus,
409 &input->bstatus_read, &status,
410 hdcp, "bstatus_read"))
412 if (!mod_hdcp_execute_and_set(check_r0p_available_dp,
413 &input->r0p_available_dp, &status,
414 hdcp, "r0p_available_dp"))
420 static enum mod_hdcp_status authenticated_dp(struct mod_hdcp *hdcp,
421 struct mod_hdcp_event_context *event_ctx,
422 struct mod_hdcp_transition_input_hdcp1 *input)
424 enum mod_hdcp_status status = MOD_HDCP_STATUS_SUCCESS;
426 if (event_ctx->event != MOD_HDCP_EVENT_CPIRQ) {
427 event_ctx->unexpected_event = 1;
431 if (status == MOD_HDCP_STATUS_SUCCESS)
432 mod_hdcp_execute_and_set(mod_hdcp_read_bstatus,
433 &input->bstatus_read, &status,
434 hdcp, "bstatus_read");
435 if (status == MOD_HDCP_STATUS_SUCCESS)
436 mod_hdcp_execute_and_set(check_link_integrity_dp,
437 &input->link_integrity_check, &status,
438 hdcp, "link_integrity_check");
439 if (status == MOD_HDCP_STATUS_SUCCESS)
440 mod_hdcp_execute_and_set(check_no_reauthentication_request_dp,
441 &input->reauth_request_check, &status,
442 hdcp, "reauth_request_check");
444 if (status != MOD_HDCP_STATUS_SUCCESS)
445 mod_hdcp_save_current_encryption_states(hdcp);
450 uint8_t mod_hdcp_execute_and_set(
451 mod_hdcp_action func, uint8_t *flag,
452 enum mod_hdcp_status *status, struct mod_hdcp *hdcp, char *str)
454 *status = func(hdcp);
455 if (*status == MOD_HDCP_STATUS_SUCCESS && *flag != PASS) {
456 HDCP_INPUT_PASS_TRACE(hdcp, str);
458 } else if (*status != MOD_HDCP_STATUS_SUCCESS && *flag != FAIL) {
459 HDCP_INPUT_FAIL_TRACE(hdcp, str);
462 return (*status == MOD_HDCP_STATUS_SUCCESS);
465 enum mod_hdcp_status mod_hdcp_hdcp1_execution(struct mod_hdcp *hdcp,
466 struct mod_hdcp_event_context *event_ctx,
467 struct mod_hdcp_transition_input_hdcp1 *input)
469 enum mod_hdcp_status status = MOD_HDCP_STATUS_SUCCESS;
471 switch (current_state(hdcp)) {
472 case H1_A0_WAIT_FOR_ACTIVE_RX:
473 status = wait_for_active_rx(hdcp, event_ctx, input);
475 case H1_A1_EXCHANGE_KSVS:
476 status = exchange_ksvs(hdcp, event_ctx, input);
478 case H1_A2_COMPUTATIONS_A3_VALIDATE_RX_A6_TEST_FOR_REPEATER:
479 status = computations_validate_rx_test_for_repeater(hdcp,
482 case H1_A45_AUTHENTICATED:
483 status = authenticated(hdcp, event_ctx, input);
485 case H1_A8_WAIT_FOR_READY:
486 status = wait_for_ready(hdcp, event_ctx, input);
488 case H1_A9_READ_KSV_LIST:
489 status = read_ksv_list(hdcp, event_ctx, input);
492 status = MOD_HDCP_STATUS_INVALID_STATE;
499 extern enum mod_hdcp_status mod_hdcp_hdcp1_dp_execution(struct mod_hdcp *hdcp,
500 struct mod_hdcp_event_context *event_ctx,
501 struct mod_hdcp_transition_input_hdcp1 *input)
503 enum mod_hdcp_status status = MOD_HDCP_STATUS_SUCCESS;
505 switch (current_state(hdcp)) {
506 case D1_A0_DETERMINE_RX_HDCP_CAPABLE:
507 status = determine_rx_hdcp_capable_dp(hdcp, event_ctx, input);
509 case D1_A1_EXCHANGE_KSVS:
510 status = exchange_ksvs(hdcp, event_ctx, input);
512 case D1_A23_WAIT_FOR_R0_PRIME:
513 status = wait_for_r0_prime_dp(hdcp, event_ctx, input);
515 case D1_A2_COMPUTATIONS_A3_VALIDATE_RX_A5_TEST_FOR_REPEATER:
516 status = computations_validate_rx_test_for_repeater(
517 hdcp, event_ctx, input);
519 case D1_A4_AUTHENTICATED:
520 status = authenticated_dp(hdcp, event_ctx, input);
522 case D1_A6_WAIT_FOR_READY:
523 status = wait_for_ready(hdcp, event_ctx, input);
525 case D1_A7_READ_KSV_LIST:
526 status = read_ksv_list(hdcp, event_ctx, input);
529 status = MOD_HDCP_STATUS_INVALID_STATE;