Back to home page

OSCL-LXR

 
 

    


0001 /*
0002  * Copyright 2019 Advanced Micro Devices, Inc.
0003  *
0004  * Permission is hereby granted, free of charge, to any person obtaining a
0005  * copy of this software and associated documentation files (the "Software"),
0006  * to deal in the Software without restriction, including without limitation
0007  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
0008  * and/or sell copies of the Software, and to permit persons to whom the
0009  * Software is furnished to do so, subject to the following conditions:
0010  *
0011  * The above copyright notice and this permission notice shall be included in
0012  * all copies or substantial portions of the Software.
0013  *
0014  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
0015  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
0016  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
0017  * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
0018  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
0019  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
0020  * OTHER DEALINGS IN THE SOFTWARE.
0021  *
0022  * Authors: AMD
0023  *
0024  */
0025 
0026 #ifndef HDCP_H_
0027 #define HDCP_H_
0028 
0029 #include "mod_hdcp.h"
0030 #include "hdcp_log.h"
0031 
0032 #include <drm/display/drm_dp_helper.h>
0033 #include <drm/display/drm_hdcp_helper.h>
0034 
0035 enum mod_hdcp_trans_input_result {
0036     UNKNOWN = 0,
0037     PASS,
0038     FAIL
0039 };
0040 
0041 struct mod_hdcp_transition_input_hdcp1 {
0042     uint8_t bksv_read;
0043     uint8_t bksv_validation;
0044     uint8_t create_session;
0045     uint8_t an_write;
0046     uint8_t aksv_write;
0047     uint8_t ainfo_write;
0048     uint8_t bcaps_read;
0049     uint8_t r0p_read;
0050     uint8_t rx_validation;
0051     uint8_t encryption;
0052     uint8_t link_maintenance;
0053     uint8_t ready_check;
0054     uint8_t bstatus_read;
0055     uint8_t max_cascade_check;
0056     uint8_t max_devs_check;
0057     uint8_t device_count_check;
0058     uint8_t ksvlist_read;
0059     uint8_t vp_read;
0060     uint8_t ksvlist_vp_validation;
0061 
0062     uint8_t hdcp_capable_dp;
0063     uint8_t binfo_read_dp;
0064     uint8_t r0p_available_dp;
0065     uint8_t link_integrity_check;
0066     uint8_t reauth_request_check;
0067     uint8_t stream_encryption_dp;
0068 };
0069 
0070 struct mod_hdcp_transition_input_hdcp2 {
0071     uint8_t hdcp2version_read;
0072     uint8_t hdcp2_capable_check;
0073     uint8_t create_session;
0074     uint8_t ake_init_prepare;
0075     uint8_t ake_init_write;
0076     uint8_t rxstatus_read;
0077     uint8_t ake_cert_available;
0078     uint8_t ake_cert_read;
0079     uint8_t ake_cert_validation;
0080     uint8_t stored_km_write;
0081     uint8_t no_stored_km_write;
0082     uint8_t h_prime_available;
0083     uint8_t h_prime_read;
0084     uint8_t pairing_available;
0085     uint8_t pairing_info_read;
0086     uint8_t h_prime_validation;
0087     uint8_t lc_init_prepare;
0088     uint8_t lc_init_write;
0089     uint8_t l_prime_available_poll;
0090     uint8_t l_prime_read;
0091     uint8_t l_prime_validation;
0092     uint8_t eks_prepare;
0093     uint8_t eks_write;
0094     uint8_t enable_encryption;
0095     uint8_t reauth_request_check;
0096     uint8_t rx_id_list_read;
0097     uint8_t device_count_check;
0098     uint8_t rx_id_list_validation;
0099     uint8_t repeater_auth_ack_write;
0100     uint8_t prepare_stream_manage;
0101     uint8_t stream_manage_write;
0102     uint8_t stream_ready_available;
0103     uint8_t stream_ready_read;
0104     uint8_t stream_ready_validation;
0105 
0106     uint8_t rx_caps_read_dp;
0107     uint8_t content_stream_type_write;
0108     uint8_t link_integrity_check_dp;
0109     uint8_t stream_encryption_dp;
0110 };
0111 
0112 union mod_hdcp_transition_input {
0113     struct mod_hdcp_transition_input_hdcp1 hdcp1;
0114     struct mod_hdcp_transition_input_hdcp2 hdcp2;
0115 };
0116 
0117 struct mod_hdcp_message_hdcp1 {
0118     uint8_t     an[8];
0119     uint8_t     aksv[5];
0120     uint8_t     ainfo;
0121     uint8_t     bksv[5];
0122     uint16_t    r0p;
0123     uint8_t     bcaps;
0124     uint16_t    bstatus;
0125     uint8_t     ksvlist[635];
0126     uint16_t    ksvlist_size;
0127     uint8_t     vp[20];
0128 
0129     uint16_t    binfo_dp;
0130 };
0131 
0132 struct mod_hdcp_message_hdcp2 {
0133     uint8_t     hdcp2version_hdmi;
0134     uint8_t     rxcaps_dp[3];
0135     uint8_t     rxstatus[2];
0136 
0137     uint8_t     ake_init[12];
0138     uint8_t     ake_cert[534];
0139     uint8_t     ake_no_stored_km[129];
0140     uint8_t     ake_stored_km[33];
0141     uint8_t     ake_h_prime[33];
0142     uint8_t     ake_pairing_info[17];
0143     uint8_t     lc_init[9];
0144     uint8_t     lc_l_prime[33];
0145     uint8_t     ske_eks[25];
0146     uint8_t     rx_id_list[177]; // 22 + 5 * 31
0147     uint16_t    rx_id_list_size;
0148     uint8_t     repeater_auth_ack[17];
0149     uint8_t     repeater_auth_stream_manage[68]; // 6 + 2 * 31
0150     uint16_t    stream_manage_size;
0151     uint8_t     repeater_auth_stream_ready[33];
0152     uint8_t     rxstatus_dp;
0153     uint8_t     content_stream_type_dp[2];
0154 };
0155 
0156 union mod_hdcp_message {
0157     struct mod_hdcp_message_hdcp1 hdcp1;
0158     struct mod_hdcp_message_hdcp2 hdcp2;
0159 };
0160 
0161 struct mod_hdcp_auth_counters {
0162     uint8_t stream_management_retry_count;
0163 };
0164 
0165 /* contains values per connection */
0166 struct mod_hdcp_connection {
0167     struct mod_hdcp_link link;
0168     uint8_t is_repeater;
0169     uint8_t is_km_stored;
0170     uint8_t is_hdcp1_revoked;
0171     uint8_t is_hdcp2_revoked;
0172     struct mod_hdcp_trace trace;
0173     uint8_t hdcp1_retry_count;
0174     uint8_t hdcp2_retry_count;
0175 };
0176 
0177 /* contains values per authentication cycle */
0178 struct mod_hdcp_authentication {
0179     uint32_t id;
0180     union mod_hdcp_message msg;
0181     union mod_hdcp_transition_input trans_input;
0182     struct mod_hdcp_auth_counters count;
0183 };
0184 
0185 /* contains values per state change */
0186 struct mod_hdcp_state {
0187     uint8_t id;
0188     uint32_t stay_count;
0189 };
0190 
0191 /* per event in a state */
0192 struct mod_hdcp_event_context {
0193     enum mod_hdcp_event event;
0194     uint8_t rx_id_list_ready;
0195     uint8_t unexpected_event;
0196 };
0197 
0198 struct mod_hdcp {
0199     /* per link */
0200     struct mod_hdcp_config config;
0201     /* per connection */
0202     struct mod_hdcp_connection connection;
0203     /* per displays */
0204     struct mod_hdcp_display displays[MAX_NUM_OF_DISPLAYS];
0205     /* per authentication attempt */
0206     struct mod_hdcp_authentication auth;
0207     /* per state in an authentication */
0208     struct mod_hdcp_state state;
0209     /* reserved memory buffer */
0210     uint8_t buf[2025];
0211 };
0212 
0213 enum mod_hdcp_initial_state_id {
0214     HDCP_UNINITIALIZED = 0x0,
0215     HDCP_INITIAL_STATE_START = HDCP_UNINITIALIZED,
0216     HDCP_INITIALIZED,
0217     HDCP_CP_NOT_DESIRED,
0218     HDCP_INITIAL_STATE_END = HDCP_CP_NOT_DESIRED
0219 };
0220 
0221 enum mod_hdcp_hdcp1_state_id {
0222     HDCP1_STATE_START = HDCP_INITIAL_STATE_END,
0223     H1_A0_WAIT_FOR_ACTIVE_RX,
0224     H1_A1_EXCHANGE_KSVS,
0225     H1_A2_COMPUTATIONS_A3_VALIDATE_RX_A6_TEST_FOR_REPEATER,
0226     H1_A45_AUTHENTICATED,
0227     H1_A8_WAIT_FOR_READY,
0228     H1_A9_READ_KSV_LIST,
0229     HDCP1_STATE_END = H1_A9_READ_KSV_LIST
0230 };
0231 
0232 enum mod_hdcp_hdcp1_dp_state_id {
0233     HDCP1_DP_STATE_START = HDCP1_STATE_END,
0234     D1_A0_DETERMINE_RX_HDCP_CAPABLE,
0235     D1_A1_EXCHANGE_KSVS,
0236     D1_A23_WAIT_FOR_R0_PRIME,
0237     D1_A2_COMPUTATIONS_A3_VALIDATE_RX_A5_TEST_FOR_REPEATER,
0238     D1_A4_AUTHENTICATED,
0239     D1_A6_WAIT_FOR_READY,
0240     D1_A7_READ_KSV_LIST,
0241     HDCP1_DP_STATE_END = D1_A7_READ_KSV_LIST,
0242 };
0243 
0244 enum mod_hdcp_hdcp2_state_id {
0245     HDCP2_STATE_START = HDCP1_DP_STATE_END,
0246     H2_A0_KNOWN_HDCP2_CAPABLE_RX,
0247     H2_A1_SEND_AKE_INIT,
0248     H2_A1_VALIDATE_AKE_CERT,
0249     H2_A1_SEND_NO_STORED_KM,
0250     H2_A1_READ_H_PRIME,
0251     H2_A1_READ_PAIRING_INFO_AND_VALIDATE_H_PRIME,
0252     H2_A1_SEND_STORED_KM,
0253     H2_A1_VALIDATE_H_PRIME,
0254     H2_A2_LOCALITY_CHECK,
0255     H2_A3_EXCHANGE_KS_AND_TEST_FOR_REPEATER,
0256     H2_ENABLE_ENCRYPTION,
0257     H2_A5_AUTHENTICATED,
0258     H2_A6_WAIT_FOR_RX_ID_LIST,
0259     H2_A78_VERIFY_RX_ID_LIST_AND_SEND_ACK,
0260     H2_A9_SEND_STREAM_MANAGEMENT,
0261     H2_A9_VALIDATE_STREAM_READY,
0262     HDCP2_STATE_END = H2_A9_VALIDATE_STREAM_READY,
0263 };
0264 
0265 enum mod_hdcp_hdcp2_dp_state_id {
0266     HDCP2_DP_STATE_START = HDCP2_STATE_END,
0267     D2_A0_DETERMINE_RX_HDCP_CAPABLE,
0268     D2_A1_SEND_AKE_INIT,
0269     D2_A1_VALIDATE_AKE_CERT,
0270     D2_A1_SEND_NO_STORED_KM,
0271     D2_A1_READ_H_PRIME,
0272     D2_A1_READ_PAIRING_INFO_AND_VALIDATE_H_PRIME,
0273     D2_A1_SEND_STORED_KM,
0274     D2_A1_VALIDATE_H_PRIME,
0275     D2_A2_LOCALITY_CHECK,
0276     D2_A34_EXCHANGE_KS_AND_TEST_FOR_REPEATER,
0277     D2_SEND_CONTENT_STREAM_TYPE,
0278     D2_ENABLE_ENCRYPTION,
0279     D2_A5_AUTHENTICATED,
0280     D2_A6_WAIT_FOR_RX_ID_LIST,
0281     D2_A78_VERIFY_RX_ID_LIST_AND_SEND_ACK,
0282     D2_A9_SEND_STREAM_MANAGEMENT,
0283     D2_A9_VALIDATE_STREAM_READY,
0284     HDCP2_DP_STATE_END = D2_A9_VALIDATE_STREAM_READY,
0285     HDCP_STATE_END = HDCP2_DP_STATE_END,
0286 };
0287 
0288 /* hdcp1 executions and transitions */
0289 typedef enum mod_hdcp_status (*mod_hdcp_action)(struct mod_hdcp *hdcp);
0290 uint8_t mod_hdcp_execute_and_set(
0291         mod_hdcp_action func, uint8_t *flag,
0292         enum mod_hdcp_status *status, struct mod_hdcp *hdcp, char *str);
0293 enum mod_hdcp_status mod_hdcp_hdcp1_execution(struct mod_hdcp *hdcp,
0294     struct mod_hdcp_event_context *event_ctx,
0295     struct mod_hdcp_transition_input_hdcp1 *input);
0296 enum mod_hdcp_status mod_hdcp_hdcp1_dp_execution(struct mod_hdcp *hdcp,
0297     struct mod_hdcp_event_context *event_ctx,
0298     struct mod_hdcp_transition_input_hdcp1 *input);
0299 enum mod_hdcp_status mod_hdcp_hdcp1_transition(struct mod_hdcp *hdcp,
0300     struct mod_hdcp_event_context *event_ctx,
0301     struct mod_hdcp_transition_input_hdcp1 *input,
0302     struct mod_hdcp_output *output);
0303 enum mod_hdcp_status mod_hdcp_hdcp1_dp_transition(struct mod_hdcp *hdcp,
0304     struct mod_hdcp_event_context *event_ctx,
0305     struct mod_hdcp_transition_input_hdcp1 *input,
0306     struct mod_hdcp_output *output);
0307 
0308 /* hdcp2 executions and transitions */
0309 enum mod_hdcp_status mod_hdcp_hdcp2_execution(struct mod_hdcp *hdcp,
0310     struct mod_hdcp_event_context *event_ctx,
0311     struct mod_hdcp_transition_input_hdcp2 *input);
0312 enum mod_hdcp_status mod_hdcp_hdcp2_dp_execution(struct mod_hdcp *hdcp,
0313     struct mod_hdcp_event_context *event_ctx,
0314     struct mod_hdcp_transition_input_hdcp2 *input);
0315 enum mod_hdcp_status mod_hdcp_hdcp2_transition(struct mod_hdcp *hdcp,
0316     struct mod_hdcp_event_context *event_ctx,
0317     struct mod_hdcp_transition_input_hdcp2 *input,
0318     struct mod_hdcp_output *output);
0319 enum mod_hdcp_status mod_hdcp_hdcp2_dp_transition(struct mod_hdcp *hdcp,
0320     struct mod_hdcp_event_context *event_ctx,
0321     struct mod_hdcp_transition_input_hdcp2 *input,
0322     struct mod_hdcp_output *output);
0323 
0324 /* log functions */
0325 void mod_hdcp_dump_binary_message(uint8_t *msg, uint32_t msg_size,
0326         uint8_t *buf, uint32_t buf_size);
0327 void mod_hdcp_log_ddc_trace(struct mod_hdcp *hdcp);
0328 /* TODO: add adjustment log */
0329 
0330 /* psp functions */
0331 enum mod_hdcp_status mod_hdcp_add_display_to_topology(
0332         struct mod_hdcp *hdcp, struct mod_hdcp_display *display);
0333 enum mod_hdcp_status mod_hdcp_remove_display_from_topology(
0334         struct mod_hdcp *hdcp, uint8_t index);
0335 enum mod_hdcp_status mod_hdcp_hdcp1_create_session(struct mod_hdcp *hdcp);
0336 enum mod_hdcp_status mod_hdcp_hdcp1_destroy_session(struct mod_hdcp *hdcp);
0337 enum mod_hdcp_status mod_hdcp_hdcp1_validate_rx(struct mod_hdcp *hdcp);
0338 enum mod_hdcp_status mod_hdcp_hdcp1_enable_encryption(struct mod_hdcp *hdcp);
0339 enum mod_hdcp_status mod_hdcp_hdcp1_validate_ksvlist_vp(struct mod_hdcp *hdcp);
0340 enum mod_hdcp_status mod_hdcp_hdcp1_enable_dp_stream_encryption(
0341     struct mod_hdcp *hdcp);
0342 enum mod_hdcp_status mod_hdcp_hdcp1_link_maintenance(struct mod_hdcp *hdcp);
0343 enum mod_hdcp_status mod_hdcp_hdcp2_create_session(struct mod_hdcp *hdcp);
0344 enum mod_hdcp_status mod_hdcp_hdcp2_destroy_session(struct mod_hdcp *hdcp);
0345 enum mod_hdcp_status mod_hdcp_hdcp2_prepare_ake_init(struct mod_hdcp *hdcp);
0346 enum mod_hdcp_status mod_hdcp_hdcp2_validate_ake_cert(struct mod_hdcp *hdcp);
0347 enum mod_hdcp_status mod_hdcp_hdcp2_validate_h_prime(struct mod_hdcp *hdcp);
0348 enum mod_hdcp_status mod_hdcp_hdcp2_prepare_lc_init(struct mod_hdcp *hdcp);
0349 enum mod_hdcp_status mod_hdcp_hdcp2_validate_l_prime(struct mod_hdcp *hdcp);
0350 enum mod_hdcp_status mod_hdcp_hdcp2_prepare_eks(struct mod_hdcp *hdcp);
0351 enum mod_hdcp_status mod_hdcp_hdcp2_enable_encryption(struct mod_hdcp *hdcp);
0352 enum mod_hdcp_status mod_hdcp_hdcp2_validate_rx_id_list(struct mod_hdcp *hdcp);
0353 enum mod_hdcp_status mod_hdcp_hdcp2_enable_dp_stream_encryption(
0354         struct mod_hdcp *hdcp);
0355 enum mod_hdcp_status mod_hdcp_hdcp2_prepare_stream_management(
0356         struct mod_hdcp *hdcp);
0357 enum mod_hdcp_status mod_hdcp_hdcp2_validate_stream_ready(
0358         struct mod_hdcp *hdcp);
0359 
0360 /* ddc functions */
0361 enum mod_hdcp_status mod_hdcp_read_bksv(struct mod_hdcp *hdcp);
0362 enum mod_hdcp_status mod_hdcp_read_bcaps(struct mod_hdcp *hdcp);
0363 enum mod_hdcp_status mod_hdcp_read_bstatus(struct mod_hdcp *hdcp);
0364 enum mod_hdcp_status mod_hdcp_read_r0p(struct mod_hdcp *hdcp);
0365 enum mod_hdcp_status mod_hdcp_read_ksvlist(struct mod_hdcp *hdcp);
0366 enum mod_hdcp_status mod_hdcp_read_vp(struct mod_hdcp *hdcp);
0367 enum mod_hdcp_status mod_hdcp_read_binfo(struct mod_hdcp *hdcp);
0368 enum mod_hdcp_status mod_hdcp_write_aksv(struct mod_hdcp *hdcp);
0369 enum mod_hdcp_status mod_hdcp_write_ainfo(struct mod_hdcp *hdcp);
0370 enum mod_hdcp_status mod_hdcp_write_an(struct mod_hdcp *hdcp);
0371 enum mod_hdcp_status mod_hdcp_read_hdcp2version(struct mod_hdcp *hdcp);
0372 enum mod_hdcp_status mod_hdcp_read_rxcaps(struct mod_hdcp *hdcp);
0373 enum mod_hdcp_status mod_hdcp_read_rxstatus(struct mod_hdcp *hdcp);
0374 enum mod_hdcp_status mod_hdcp_read_ake_cert(struct mod_hdcp *hdcp);
0375 enum mod_hdcp_status mod_hdcp_read_h_prime(struct mod_hdcp *hdcp);
0376 enum mod_hdcp_status mod_hdcp_read_pairing_info(struct mod_hdcp *hdcp);
0377 enum mod_hdcp_status mod_hdcp_read_l_prime(struct mod_hdcp *hdcp);
0378 enum mod_hdcp_status mod_hdcp_read_rx_id_list(struct mod_hdcp *hdcp);
0379 enum mod_hdcp_status mod_hdcp_read_stream_ready(struct mod_hdcp *hdcp);
0380 enum mod_hdcp_status mod_hdcp_write_ake_init(struct mod_hdcp *hdcp);
0381 enum mod_hdcp_status mod_hdcp_write_no_stored_km(struct mod_hdcp *hdcp);
0382 enum mod_hdcp_status mod_hdcp_write_stored_km(struct mod_hdcp *hdcp);
0383 enum mod_hdcp_status mod_hdcp_write_lc_init(struct mod_hdcp *hdcp);
0384 enum mod_hdcp_status mod_hdcp_write_eks(struct mod_hdcp *hdcp);
0385 enum mod_hdcp_status mod_hdcp_write_repeater_auth_ack(struct mod_hdcp *hdcp);
0386 enum mod_hdcp_status mod_hdcp_write_stream_manage(struct mod_hdcp *hdcp);
0387 enum mod_hdcp_status mod_hdcp_write_content_type(struct mod_hdcp *hdcp);
0388 enum mod_hdcp_status mod_hdcp_clear_cp_irq_status(struct mod_hdcp *hdcp);
0389 
0390 /* hdcp version helpers */
0391 static inline uint8_t is_dp_hdcp(struct mod_hdcp *hdcp)
0392 {
0393     return (hdcp->connection.link.mode == MOD_HDCP_MODE_DP);
0394 }
0395 
0396 static inline uint8_t is_dp_mst_hdcp(struct mod_hdcp *hdcp)
0397 {
0398     return (hdcp->connection.link.mode == MOD_HDCP_MODE_DP &&
0399             hdcp->connection.link.dp.mst_enabled);
0400 }
0401 
0402 static inline uint8_t is_hdmi_dvi_sl_hdcp(struct mod_hdcp *hdcp)
0403 {
0404     return (hdcp->connection.link.mode == MOD_HDCP_MODE_DEFAULT);
0405 }
0406 
0407 /* hdcp state helpers */
0408 static inline uint8_t current_state(struct mod_hdcp *hdcp)
0409 {
0410     return hdcp->state.id;
0411 }
0412 
0413 static inline void set_state_id(struct mod_hdcp *hdcp,
0414         struct mod_hdcp_output *output, uint8_t id)
0415 {
0416     memset(&hdcp->state, 0, sizeof(hdcp->state));
0417     hdcp->state.id = id;
0418     /* callback timer should be reset per state */
0419     output->callback_stop = 1;
0420     output->watchdog_timer_stop = 1;
0421     HDCP_NEXT_STATE_TRACE(hdcp, id, output);
0422 }
0423 
0424 static inline uint8_t is_in_hdcp1_states(struct mod_hdcp *hdcp)
0425 {
0426     return (current_state(hdcp) > HDCP1_STATE_START &&
0427             current_state(hdcp) <= HDCP1_STATE_END);
0428 }
0429 
0430 static inline uint8_t is_in_hdcp1_dp_states(struct mod_hdcp *hdcp)
0431 {
0432     return (current_state(hdcp) > HDCP1_DP_STATE_START &&
0433             current_state(hdcp) <= HDCP1_DP_STATE_END);
0434 }
0435 
0436 static inline uint8_t is_in_hdcp2_states(struct mod_hdcp *hdcp)
0437 {
0438     return (current_state(hdcp) > HDCP2_STATE_START &&
0439             current_state(hdcp) <= HDCP2_STATE_END);
0440 }
0441 
0442 static inline uint8_t is_in_hdcp2_dp_states(struct mod_hdcp *hdcp)
0443 {
0444     return (current_state(hdcp) > HDCP2_DP_STATE_START &&
0445             current_state(hdcp) <= HDCP2_DP_STATE_END);
0446 }
0447 
0448 static inline uint8_t is_in_authenticated_states(struct mod_hdcp *hdcp)
0449 {
0450     return (current_state(hdcp) == D1_A4_AUTHENTICATED ||
0451     current_state(hdcp) == H1_A45_AUTHENTICATED ||
0452     current_state(hdcp) == D2_A5_AUTHENTICATED ||
0453     current_state(hdcp) == H2_A5_AUTHENTICATED);
0454 }
0455 
0456 static inline uint8_t is_hdcp1(struct mod_hdcp *hdcp)
0457 {
0458     return (is_in_hdcp1_states(hdcp) || is_in_hdcp1_dp_states(hdcp));
0459 }
0460 
0461 static inline uint8_t is_hdcp2(struct mod_hdcp *hdcp)
0462 {
0463     return (is_in_hdcp2_states(hdcp) || is_in_hdcp2_dp_states(hdcp));
0464 }
0465 
0466 static inline uint8_t is_in_cp_not_desired_state(struct mod_hdcp *hdcp)
0467 {
0468     return current_state(hdcp) == HDCP_CP_NOT_DESIRED;
0469 }
0470 
0471 static inline uint8_t is_in_initialized_state(struct mod_hdcp *hdcp)
0472 {
0473     return current_state(hdcp) == HDCP_INITIALIZED;
0474 }
0475 
0476 /* transition operation helpers */
0477 static inline void increment_stay_counter(struct mod_hdcp *hdcp)
0478 {
0479     hdcp->state.stay_count++;
0480 }
0481 
0482 static inline void fail_and_restart_in_ms(uint16_t time,
0483         enum mod_hdcp_status *status,
0484         struct mod_hdcp_output *output)
0485 {
0486     output->callback_needed = 1;
0487     output->callback_delay = time;
0488     output->watchdog_timer_needed = 0;
0489     output->watchdog_timer_delay = 0;
0490     *status = MOD_HDCP_STATUS_RESET_NEEDED;
0491 }
0492 
0493 static inline void callback_in_ms(uint16_t time, struct mod_hdcp_output *output)
0494 {
0495     output->callback_needed = 1;
0496     output->callback_delay = time;
0497 }
0498 
0499 static inline void set_watchdog_in_ms(struct mod_hdcp *hdcp, uint16_t time,
0500         struct mod_hdcp_output *output)
0501 {
0502     output->watchdog_timer_needed = 1;
0503     output->watchdog_timer_delay = time;
0504 }
0505 
0506 static inline void set_auth_complete(struct mod_hdcp *hdcp,
0507         struct mod_hdcp_output *output)
0508 {
0509     output->auth_complete = 1;
0510     mod_hdcp_log_ddc_trace(hdcp);
0511 }
0512 
0513 /* connection topology helpers */
0514 static inline uint8_t is_display_active(struct mod_hdcp_display *display)
0515 {
0516     return display->state >= MOD_HDCP_DISPLAY_ACTIVE;
0517 }
0518 
0519 static inline uint8_t is_display_encryption_enabled(struct mod_hdcp_display *display)
0520 {
0521     return display->state >= MOD_HDCP_DISPLAY_ENCRYPTION_ENABLED;
0522 }
0523 
0524 static inline uint8_t get_active_display_count(struct mod_hdcp *hdcp)
0525 {
0526     uint8_t active_count = 0;
0527     uint8_t i;
0528 
0529     for (i = 0; i < MAX_NUM_OF_DISPLAYS; i++)
0530         if (is_display_active(&hdcp->displays[i]))
0531             active_count++;
0532     return active_count;
0533 }
0534 
0535 static inline struct mod_hdcp_display *get_first_active_display(
0536         struct mod_hdcp *hdcp)
0537 {
0538     uint8_t i;
0539     struct mod_hdcp_display *display = NULL;
0540 
0541     for (i = 0; i < MAX_NUM_OF_DISPLAYS; i++)
0542         if (is_display_active(&hdcp->displays[i])) {
0543             display = &hdcp->displays[i];
0544             break;
0545         }
0546     return display;
0547 }
0548 
0549 static inline struct mod_hdcp_display *get_active_display_at_index(
0550         struct mod_hdcp *hdcp, uint8_t index)
0551 {
0552     uint8_t i;
0553     struct mod_hdcp_display *display = NULL;
0554 
0555     for (i = 0; i < MAX_NUM_OF_DISPLAYS; i++)
0556         if (hdcp->displays[i].index == index &&
0557                 is_display_active(&hdcp->displays[i])) {
0558             display = &hdcp->displays[i];
0559             break;
0560         }
0561     return display;
0562 }
0563 
0564 static inline struct mod_hdcp_display *get_empty_display_container(
0565         struct mod_hdcp *hdcp)
0566 {
0567     uint8_t i;
0568     struct mod_hdcp_display *display = NULL;
0569 
0570     for (i = 0; i < MAX_NUM_OF_DISPLAYS; i++)
0571         if (!is_display_active(&hdcp->displays[i])) {
0572             display = &hdcp->displays[i];
0573             break;
0574         }
0575     return display;
0576 }
0577 
0578 static inline void reset_retry_counts(struct mod_hdcp *hdcp)
0579 {
0580     hdcp->connection.hdcp1_retry_count = 0;
0581     hdcp->connection.hdcp2_retry_count = 0;
0582 }
0583 
0584 #endif /* HDCP_H_ */