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");
273 static enum mod_hdcp_status wait_for_ready(struct mod_hdcp *hdcp,
274 struct mod_hdcp_event_context *event_ctx,
275 struct mod_hdcp_transition_input_hdcp1 *input)
277 enum mod_hdcp_status status = MOD_HDCP_STATUS_SUCCESS;
279 if (event_ctx->event != MOD_HDCP_EVENT_CALLBACK &&
280 event_ctx->event != MOD_HDCP_EVENT_CPIRQ &&
281 event_ctx->event != MOD_HDCP_EVENT_WATCHDOG_TIMEOUT) {
282 event_ctx->unexpected_event = 1;
286 if (is_dp_hdcp(hdcp)) {
287 if (!mod_hdcp_execute_and_set(mod_hdcp_read_bstatus,
288 &input->bstatus_read, &status,
289 hdcp, "bstatus_read"))
291 if (!mod_hdcp_execute_and_set(check_link_integrity_dp,
292 &input->link_integrity_check, &status,
293 hdcp, "link_integrity_check"))
295 if (!mod_hdcp_execute_and_set(check_no_reauthentication_request_dp,
296 &input->reauth_request_check, &status,
297 hdcp, "reauth_request_check"))
300 if (!mod_hdcp_execute_and_set(mod_hdcp_read_bcaps,
301 &input->bcaps_read, &status,
305 if (!mod_hdcp_execute_and_set(check_ksv_ready,
306 &input->ready_check, &status,
307 hdcp, "ready_check"))
313 static enum mod_hdcp_status read_ksv_list(struct mod_hdcp *hdcp,
314 struct mod_hdcp_event_context *event_ctx,
315 struct mod_hdcp_transition_input_hdcp1 *input)
317 enum mod_hdcp_status status = MOD_HDCP_STATUS_SUCCESS;
318 uint8_t device_count;
320 if (event_ctx->event != MOD_HDCP_EVENT_CALLBACK) {
321 event_ctx->unexpected_event = 1;
325 if (is_dp_hdcp(hdcp)) {
326 if (!mod_hdcp_execute_and_set(mod_hdcp_read_binfo,
327 &input->binfo_read_dp, &status,
328 hdcp, "binfo_read_dp"))
331 if (!mod_hdcp_execute_and_set(mod_hdcp_read_bstatus,
332 &input->bstatus_read, &status,
333 hdcp, "bstatus_read"))
336 if (!mod_hdcp_execute_and_set(check_no_max_cascade,
337 &input->max_cascade_check, &status,
338 hdcp, "max_cascade_check"))
340 if (!mod_hdcp_execute_and_set(check_no_max_devs,
341 &input->max_devs_check, &status,
342 hdcp, "max_devs_check"))
344 if (!mod_hdcp_execute_and_set(check_device_count,
345 &input->device_count_check, &status,
346 hdcp, "device_count_check"))
348 device_count = get_device_count(hdcp);
349 hdcp->auth.msg.hdcp1.ksvlist_size = device_count*5;
350 if (!mod_hdcp_execute_and_set(mod_hdcp_read_ksvlist,
351 &input->ksvlist_read, &status,
352 hdcp, "ksvlist_read"))
354 if (!mod_hdcp_execute_and_set(mod_hdcp_read_vp,
355 &input->vp_read, &status,
358 if (!mod_hdcp_execute_and_set(mod_hdcp_hdcp1_validate_ksvlist_vp,
359 &input->ksvlist_vp_validation, &status,
360 hdcp, "ksvlist_vp_validation"))
362 if (input->encryption != PASS)
363 if (!mod_hdcp_execute_and_set(mod_hdcp_hdcp1_enable_encryption,
364 &input->encryption, &status,
367 if (is_dp_mst_hdcp(hdcp))
368 if (!mod_hdcp_execute_and_set(
369 mod_hdcp_hdcp1_enable_dp_stream_encryption,
370 &input->stream_encryption_dp, &status,
371 hdcp, "stream_encryption_dp"))
377 static enum mod_hdcp_status determine_rx_hdcp_capable_dp(struct mod_hdcp *hdcp,
378 struct mod_hdcp_event_context *event_ctx,
379 struct mod_hdcp_transition_input_hdcp1 *input)
381 enum mod_hdcp_status status = MOD_HDCP_STATUS_SUCCESS;
383 if (event_ctx->event != MOD_HDCP_EVENT_CALLBACK) {
384 event_ctx->unexpected_event = 1;
388 if (!mod_hdcp_execute_and_set(mod_hdcp_read_bcaps,
389 &input->bcaps_read, &status,
392 if (!mod_hdcp_execute_and_set(check_hdcp_capable_dp,
393 &input->hdcp_capable_dp, &status,
394 hdcp, "hdcp_capable_dp"))
400 static enum mod_hdcp_status wait_for_r0_prime_dp(struct mod_hdcp *hdcp,
401 struct mod_hdcp_event_context *event_ctx,
402 struct mod_hdcp_transition_input_hdcp1 *input)
404 enum mod_hdcp_status status = MOD_HDCP_STATUS_SUCCESS;
406 if (event_ctx->event != MOD_HDCP_EVENT_CPIRQ &&
407 event_ctx->event != MOD_HDCP_EVENT_WATCHDOG_TIMEOUT) {
408 event_ctx->unexpected_event = 1;
412 if (!mod_hdcp_execute_and_set(mod_hdcp_read_bstatus,
413 &input->bstatus_read, &status,
414 hdcp, "bstatus_read"))
416 if (!mod_hdcp_execute_and_set(check_r0p_available_dp,
417 &input->r0p_available_dp, &status,
418 hdcp, "r0p_available_dp"))
424 static enum mod_hdcp_status authenticated_dp(struct mod_hdcp *hdcp,
425 struct mod_hdcp_event_context *event_ctx,
426 struct mod_hdcp_transition_input_hdcp1 *input)
428 enum mod_hdcp_status status = MOD_HDCP_STATUS_SUCCESS;
430 if (event_ctx->event != MOD_HDCP_EVENT_CPIRQ) {
431 event_ctx->unexpected_event = 1;
435 if (status == MOD_HDCP_STATUS_SUCCESS)
436 mod_hdcp_execute_and_set(mod_hdcp_read_bstatus,
437 &input->bstatus_read, &status,
438 hdcp, "bstatus_read");
439 if (status == MOD_HDCP_STATUS_SUCCESS)
440 mod_hdcp_execute_and_set(check_link_integrity_dp,
441 &input->link_integrity_check, &status,
442 hdcp, "link_integrity_check");
443 if (status == MOD_HDCP_STATUS_SUCCESS)
444 mod_hdcp_execute_and_set(check_no_reauthentication_request_dp,
445 &input->reauth_request_check, &status,
446 hdcp, "reauth_request_check");
451 uint8_t mod_hdcp_execute_and_set(
452 mod_hdcp_action func, uint8_t *flag,
453 enum mod_hdcp_status *status, struct mod_hdcp *hdcp, char *str)
455 *status = func(hdcp);
456 if (*status == MOD_HDCP_STATUS_SUCCESS && *flag != PASS) {
457 HDCP_INPUT_PASS_TRACE(hdcp, str);
459 } else if (*status != MOD_HDCP_STATUS_SUCCESS && *flag != FAIL) {
460 HDCP_INPUT_FAIL_TRACE(hdcp, str);
463 return (*status == MOD_HDCP_STATUS_SUCCESS);
466 enum mod_hdcp_status mod_hdcp_hdcp1_execution(struct mod_hdcp *hdcp,
467 struct mod_hdcp_event_context *event_ctx,
468 struct mod_hdcp_transition_input_hdcp1 *input)
470 enum mod_hdcp_status status = MOD_HDCP_STATUS_SUCCESS;
472 switch (current_state(hdcp)) {
473 case H1_A0_WAIT_FOR_ACTIVE_RX:
474 status = wait_for_active_rx(hdcp, event_ctx, input);
476 case H1_A1_EXCHANGE_KSVS:
477 status = exchange_ksvs(hdcp, event_ctx, input);
479 case H1_A2_COMPUTATIONS_A3_VALIDATE_RX_A6_TEST_FOR_REPEATER:
480 status = computations_validate_rx_test_for_repeater(hdcp,
483 case H1_A45_AUTHENTICATED:
484 status = authenticated(hdcp, event_ctx, input);
486 case H1_A8_WAIT_FOR_READY:
487 status = wait_for_ready(hdcp, event_ctx, input);
489 case H1_A9_READ_KSV_LIST:
490 status = read_ksv_list(hdcp, event_ctx, input);
493 status = MOD_HDCP_STATUS_INVALID_STATE;
500 enum mod_hdcp_status mod_hdcp_hdcp1_dp_execution(struct mod_hdcp *hdcp,
501 struct mod_hdcp_event_context *event_ctx,
502 struct mod_hdcp_transition_input_hdcp1 *input)
504 enum mod_hdcp_status status = MOD_HDCP_STATUS_SUCCESS;
506 switch (current_state(hdcp)) {
507 case D1_A0_DETERMINE_RX_HDCP_CAPABLE:
508 status = determine_rx_hdcp_capable_dp(hdcp, event_ctx, input);
510 case D1_A1_EXCHANGE_KSVS:
511 status = exchange_ksvs(hdcp, event_ctx, input);
513 case D1_A23_WAIT_FOR_R0_PRIME:
514 status = wait_for_r0_prime_dp(hdcp, event_ctx, input);
516 case D1_A2_COMPUTATIONS_A3_VALIDATE_RX_A5_TEST_FOR_REPEATER:
517 status = computations_validate_rx_test_for_repeater(
518 hdcp, event_ctx, input);
520 case D1_A4_AUTHENTICATED:
521 status = authenticated_dp(hdcp, event_ctx, input);
523 case D1_A6_WAIT_FOR_READY:
524 status = wait_for_ready(hdcp, event_ctx, input);
526 case D1_A7_READ_KSV_LIST:
527 status = read_ksv_list(hdcp, event_ctx, input);
530 status = MOD_HDCP_STATUS_INVALID_STATE;