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.
32 #define BCAPS_READY_MASK 0x20
33 #define BCAPS_REPEATER_MASK 0x40
34 #define BSTATUS_DEVICE_COUNT_MASK 0X007F
35 #define BSTATUS_MAX_DEVS_EXCEEDED_MASK 0x0080
36 #define BSTATUS_MAX_CASCADE_EXCEEDED_MASK 0x0800
37 #define BCAPS_HDCP_CAPABLE_MASK_DP 0x01
38 #define BCAPS_REPEATER_MASK_DP 0x02
39 #define BSTATUS_READY_MASK_DP 0x01
40 #define BSTATUS_R0_P_AVAILABLE_MASK_DP 0x02
41 #define BSTATUS_LINK_INTEGRITY_FAILURE_MASK_DP 0x04
42 #define BSTATUS_REAUTH_REQUEST_MASK_DP 0x08
43 #define BINFO_DEVICE_COUNT_MASK_DP 0X007F
44 #define BINFO_MAX_DEVS_EXCEEDED_MASK_DP 0x0080
45 #define BINFO_MAX_CASCADE_EXCEEDED_MASK_DP 0x0800
47 #define RXSTATUS_MSG_SIZE_MASK 0x03FF
48 #define RXSTATUS_READY_MASK 0x0400
49 #define RXSTATUS_REAUTH_REQUEST_MASK 0x0800
50 #define RXIDLIST_DEVICE_COUNT_LOWER_MASK 0xf0
51 #define RXIDLIST_DEVICE_COUNT_UPPER_MASK 0x01
52 #define RXCAPS_BYTE0_HDCP_CAPABLE_MASK_DP 0x02
53 #define RXSTATUS_READY_MASK_DP 0x0001
54 #define RXSTATUS_H_P_AVAILABLE_MASK_DP 0x0002
55 #define RXSTATUS_PAIRING_AVAILABLE_MASK_DP 0x0004
56 #define RXSTATUS_REAUTH_REQUEST_MASK_DP 0x0008
57 #define RXSTATUS_LINK_INTEGRITY_FAILURE_MASK_DP 0x0010
59 enum mod_hdcp_trans_input_result {
65 struct mod_hdcp_transition_input_hdcp1 {
67 uint8_t bksv_validation;
69 uint8_t create_session;
75 uint8_t rx_validation;
77 uint8_t link_maintenance;
80 uint8_t max_cascade_check;
81 uint8_t max_devs_check;
82 uint8_t device_count_check;
85 uint8_t ksvlist_vp_validation;
87 uint8_t hdcp_capable_dp;
88 uint8_t binfo_read_dp;
89 uint8_t r0p_available_dp;
90 uint8_t link_integiry_check;
91 uint8_t reauth_request_check;
92 uint8_t stream_encryption_dp;
95 union mod_hdcp_transition_input {
96 struct mod_hdcp_transition_input_hdcp1 hdcp1;
99 struct mod_hdcp_message_hdcp1 {
107 uint8_t ksvlist[635];
108 uint16_t ksvlist_size;
114 union mod_hdcp_message {
115 struct mod_hdcp_message_hdcp1 hdcp1;
118 struct mod_hdcp_auth_counters {
119 uint8_t stream_management_retry_count;
122 /* contains values per connection */
123 struct mod_hdcp_connection {
124 struct mod_hdcp_link link;
125 struct mod_hdcp_display displays[MAX_NUM_OF_DISPLAYS];
127 uint8_t is_km_stored;
128 struct mod_hdcp_trace trace;
129 uint8_t hdcp1_retry_count;
132 /* contains values per authentication cycle */
133 struct mod_hdcp_authentication {
135 union mod_hdcp_message msg;
136 union mod_hdcp_transition_input trans_input;
137 struct mod_hdcp_auth_counters count;
140 /* contains values per state change */
141 struct mod_hdcp_state {
146 /* per event in a state */
147 struct mod_hdcp_event_context {
148 enum mod_hdcp_event event;
149 uint8_t rx_id_list_ready;
150 uint8_t unexpected_event;
155 struct mod_hdcp_config config;
157 struct mod_hdcp_connection connection;
158 /* per authentication attempt */
159 struct mod_hdcp_authentication auth;
160 /* per state in an authentication */
161 struct mod_hdcp_state state;
162 /* reserved memory buffer */
166 enum mod_hdcp_initial_state_id {
167 HDCP_UNINITIALIZED = 0x0,
168 HDCP_INITIAL_STATE_START = HDCP_UNINITIALIZED,
171 HDCP_INITIAL_STATE_END = HDCP_CP_NOT_DESIRED
174 enum mod_hdcp_hdcp1_state_id {
175 HDCP1_STATE_START = HDCP_INITIAL_STATE_END,
176 H1_A0_WAIT_FOR_ACTIVE_RX,
178 H1_A2_COMPUTATIONS_A3_VALIDATE_RX_A6_TEST_FOR_REPEATER,
180 H1_A8_WAIT_FOR_READY,
182 HDCP1_STATE_END = H1_A9_READ_KSV_LIST
185 enum mod_hdcp_hdcp1_dp_state_id {
186 HDCP1_DP_STATE_START = HDCP1_STATE_END,
187 D1_A0_DETERMINE_RX_HDCP_CAPABLE,
189 D1_A23_WAIT_FOR_R0_PRIME,
190 D1_A2_COMPUTATIONS_A3_VALIDATE_RX_A5_TEST_FOR_REPEATER,
192 D1_A6_WAIT_FOR_READY,
194 HDCP1_DP_STATE_END = D1_A7_READ_KSV_LIST,
197 /* hdcp1 executions and transitions */
198 typedef enum mod_hdcp_status (*mod_hdcp_action)(struct mod_hdcp *hdcp);
199 uint8_t mod_hdcp_execute_and_set(
200 mod_hdcp_action func, uint8_t *flag,
201 enum mod_hdcp_status *status, struct mod_hdcp *hdcp, char *str);
202 enum mod_hdcp_status mod_hdcp_hdcp1_execution(struct mod_hdcp *hdcp,
203 struct mod_hdcp_event_context *event_ctx,
204 struct mod_hdcp_transition_input_hdcp1 *input);
205 enum mod_hdcp_status mod_hdcp_hdcp1_dp_execution(struct mod_hdcp *hdcp,
206 struct mod_hdcp_event_context *event_ctx,
207 struct mod_hdcp_transition_input_hdcp1 *input);
208 enum mod_hdcp_status mod_hdcp_hdcp1_transition(struct mod_hdcp *hdcp,
209 struct mod_hdcp_event_context *event_ctx,
210 struct mod_hdcp_transition_input_hdcp1 *input,
211 struct mod_hdcp_output *output);
212 enum mod_hdcp_status mod_hdcp_hdcp1_dp_transition(struct mod_hdcp *hdcp,
213 struct mod_hdcp_event_context *event_ctx,
214 struct mod_hdcp_transition_input_hdcp1 *input,
215 struct mod_hdcp_output *output);
218 void mod_hdcp_dump_binary_message(uint8_t *msg, uint32_t msg_size,
219 uint8_t *buf, uint32_t buf_size);
220 /* TODO: add adjustment log */
223 enum mod_hdcp_status mod_hdcp_add_display_topology(
224 struct mod_hdcp *hdcp);
225 enum mod_hdcp_status mod_hdcp_remove_display_topology(
226 struct mod_hdcp *hdcp);
227 enum mod_hdcp_status mod_hdcp_hdcp1_create_session(struct mod_hdcp *hdcp);
228 enum mod_hdcp_status mod_hdcp_hdcp1_destroy_session(struct mod_hdcp *hdcp);
229 enum mod_hdcp_status mod_hdcp_hdcp1_validate_rx(struct mod_hdcp *hdcp);
230 enum mod_hdcp_status mod_hdcp_hdcp1_enable_encryption(struct mod_hdcp *hdcp);
231 enum mod_hdcp_status mod_hdcp_hdcp1_validate_ksvlist_vp(struct mod_hdcp *hdcp);
232 enum mod_hdcp_status mod_hdcp_hdcp1_enable_dp_stream_encryption(
233 struct mod_hdcp *hdcp);
234 enum mod_hdcp_status mod_hdcp_hdcp1_link_maintenance(struct mod_hdcp *hdcp);
235 enum mod_hdcp_status mod_hdcp_hdcp1_get_link_encryption_status(struct mod_hdcp *hdcp,
236 enum mod_hdcp_encryption_status *encryption_status);
238 enum mod_hdcp_status mod_hdcp_read_bksv(struct mod_hdcp *hdcp);
239 enum mod_hdcp_status mod_hdcp_read_bcaps(struct mod_hdcp *hdcp);
240 enum mod_hdcp_status mod_hdcp_read_bstatus(struct mod_hdcp *hdcp);
241 enum mod_hdcp_status mod_hdcp_read_r0p(struct mod_hdcp *hdcp);
242 enum mod_hdcp_status mod_hdcp_read_ksvlist(struct mod_hdcp *hdcp);
243 enum mod_hdcp_status mod_hdcp_read_vp(struct mod_hdcp *hdcp);
244 enum mod_hdcp_status mod_hdcp_read_binfo(struct mod_hdcp *hdcp);
245 enum mod_hdcp_status mod_hdcp_write_aksv(struct mod_hdcp *hdcp);
246 enum mod_hdcp_status mod_hdcp_write_ainfo(struct mod_hdcp *hdcp);
247 enum mod_hdcp_status mod_hdcp_write_an(struct mod_hdcp *hdcp);
248 enum mod_hdcp_status mod_hdcp_read_rxcaps(struct mod_hdcp *hdcp);
249 enum mod_hdcp_status mod_hdcp_read_rxstatus(struct mod_hdcp *hdcp);
250 enum mod_hdcp_status mod_hdcp_read_ake_cert(struct mod_hdcp *hdcp);
251 enum mod_hdcp_status mod_hdcp_read_h_prime(struct mod_hdcp *hdcp);
252 enum mod_hdcp_status mod_hdcp_read_pairing_info(struct mod_hdcp *hdcp);
253 enum mod_hdcp_status mod_hdcp_read_l_prime(struct mod_hdcp *hdcp);
254 enum mod_hdcp_status mod_hdcp_read_rx_id_list(struct mod_hdcp *hdcp);
255 enum mod_hdcp_status mod_hdcp_read_stream_ready(struct mod_hdcp *hdcp);
256 enum mod_hdcp_status mod_hdcp_write_ake_init(struct mod_hdcp *hdcp);
257 enum mod_hdcp_status mod_hdcp_write_no_stored_km(struct mod_hdcp *hdcp);
258 enum mod_hdcp_status mod_hdcp_write_stored_km(struct mod_hdcp *hdcp);
259 enum mod_hdcp_status mod_hdcp_write_lc_init(struct mod_hdcp *hdcp);
260 enum mod_hdcp_status mod_hdcp_write_eks(struct mod_hdcp *hdcp);
261 enum mod_hdcp_status mod_hdcp_write_repeater_auth_ack(struct mod_hdcp *hdcp);
262 enum mod_hdcp_status mod_hdcp_write_stream_manage(struct mod_hdcp *hdcp);
263 enum mod_hdcp_status mod_hdcp_write_content_type(struct mod_hdcp *hdcp);
265 /* hdcp version helpers */
266 static inline uint8_t is_dp_hdcp(struct mod_hdcp *hdcp)
268 return (hdcp->connection.link.mode == MOD_HDCP_MODE_DP ||
269 hdcp->connection.link.mode == MOD_HDCP_MODE_DP_MST);
272 static inline uint8_t is_dp_mst_hdcp(struct mod_hdcp *hdcp)
274 return (hdcp->connection.link.mode == MOD_HDCP_MODE_DP_MST);
277 static inline uint8_t is_hdmi_dvi_sl_hdcp(struct mod_hdcp *hdcp)
279 return (hdcp->connection.link.mode == MOD_HDCP_MODE_DEFAULT);
282 /* hdcp state helpers */
283 static inline uint8_t current_state(struct mod_hdcp *hdcp)
285 return hdcp->state.id;
288 static inline void set_state_id(struct mod_hdcp *hdcp,
289 struct mod_hdcp_output *output, uint8_t id)
291 memset(&hdcp->state, 0, sizeof(hdcp->state));
293 /* callback timer should be reset per state */
294 output->callback_stop = 1;
295 output->watchdog_timer_stop = 1;
296 HDCP_NEXT_STATE_TRACE(hdcp, id, output);
299 static inline uint8_t is_in_hdcp1_states(struct mod_hdcp *hdcp)
301 return (current_state(hdcp) > HDCP1_STATE_START &&
302 current_state(hdcp) <= HDCP1_STATE_END);
305 static inline uint8_t is_in_hdcp1_dp_states(struct mod_hdcp *hdcp)
307 return (current_state(hdcp) > HDCP1_DP_STATE_START &&
308 current_state(hdcp) <= HDCP1_DP_STATE_END);
311 static inline uint8_t is_hdcp1(struct mod_hdcp *hdcp)
313 return (is_in_hdcp1_states(hdcp) || is_in_hdcp1_dp_states(hdcp));
316 static inline uint8_t is_in_cp_not_desired_state(struct mod_hdcp *hdcp)
318 return current_state(hdcp) == HDCP_CP_NOT_DESIRED;
321 static inline uint8_t is_in_initialized_state(struct mod_hdcp *hdcp)
323 return current_state(hdcp) == HDCP_INITIALIZED;
326 /* transition operation helpers */
327 static inline void increment_stay_counter(struct mod_hdcp *hdcp)
329 hdcp->state.stay_count++;
332 static inline void fail_and_restart_in_ms(uint16_t time,
333 enum mod_hdcp_status *status,
334 struct mod_hdcp_output *output)
336 output->callback_needed = 1;
337 output->callback_delay = time;
338 output->watchdog_timer_needed = 0;
339 output->watchdog_timer_delay = 0;
340 *status = MOD_HDCP_STATUS_RESET_NEEDED;
343 static inline void callback_in_ms(uint16_t time, struct mod_hdcp_output *output)
345 output->callback_needed = 1;
346 output->callback_delay = time;
349 static inline void set_watchdog_in_ms(struct mod_hdcp *hdcp, uint16_t time,
350 struct mod_hdcp_output *output)
352 output->watchdog_timer_needed = 1;
353 output->watchdog_timer_delay = time;
356 /* connection topology helpers */
357 static inline uint8_t is_display_active(struct mod_hdcp_display *display)
359 return display->state >= MOD_HDCP_DISPLAY_ACTIVE;
362 static inline uint8_t is_display_added(struct mod_hdcp_display *display)
364 return display->state >= MOD_HDCP_DISPLAY_ACTIVE_AND_ADDED;
367 static inline uint8_t is_display_encryption_enabled(struct mod_hdcp_display *display)
369 return display->state >= MOD_HDCP_DISPLAY_ENCRYPTION_ENABLED;
372 static inline uint8_t get_active_display_count(struct mod_hdcp *hdcp)
374 uint8_t added_count = 0;
377 for (i = 0; i < MAX_NUM_OF_DISPLAYS; i++)
378 if (is_display_active(&hdcp->connection.displays[i]))
383 static inline uint8_t get_added_display_count(struct mod_hdcp *hdcp)
385 uint8_t added_count = 0;
388 for (i = 0; i < MAX_NUM_OF_DISPLAYS; i++)
389 if (is_display_added(&hdcp->connection.displays[i]))
394 static inline struct mod_hdcp_display *get_first_added_display(
395 struct mod_hdcp *hdcp)
398 struct mod_hdcp_display *display = NULL;
400 for (i = 0; i < MAX_NUM_OF_DISPLAYS; i++)
401 if (is_display_added(&hdcp->connection.displays[i])) {
402 display = &hdcp->connection.displays[i];
408 static inline struct mod_hdcp_display *get_active_display_at_index(
409 struct mod_hdcp *hdcp, uint8_t index)
412 struct mod_hdcp_display *display = NULL;
414 for (i = 0; i < MAX_NUM_OF_DISPLAYS; i++)
415 if (hdcp->connection.displays[i].index == index &&
416 is_display_active(&hdcp->connection.displays[i])) {
417 display = &hdcp->connection.displays[i];
423 static inline struct mod_hdcp_display *get_empty_display_container(
424 struct mod_hdcp *hdcp)
427 struct mod_hdcp_display *display = NULL;
429 for (i = 0; i < MAX_NUM_OF_DISPLAYS; i++)
430 if (!is_display_active(&hdcp->connection.displays[i])) {
431 display = &hdcp->connection.displays[i];
437 static inline void reset_retry_counts(struct mod_hdcp *hdcp)
439 hdcp->connection.hdcp1_retry_count = 0;