hdcp.h 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584
  1. /*
  2. * Copyright 2019 Advanced Micro Devices, Inc.
  3. *
  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:
  10. *
  11. * The above copyright notice and this permission notice shall be included in
  12. * all copies or substantial portions of the Software.
  13. *
  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.
  21. *
  22. * Authors: AMD
  23. *
  24. */
  25. #ifndef HDCP_H_
  26. #define HDCP_H_
  27. #include "mod_hdcp.h"
  28. #include "hdcp_log.h"
  29. #include <drm/display/drm_dp_helper.h>
  30. #include <drm/display/drm_hdcp_helper.h>
  31. enum mod_hdcp_trans_input_result {
  32. UNKNOWN = 0,
  33. PASS,
  34. FAIL
  35. };
  36. struct mod_hdcp_transition_input_hdcp1 {
  37. uint8_t bksv_read;
  38. uint8_t bksv_validation;
  39. uint8_t create_session;
  40. uint8_t an_write;
  41. uint8_t aksv_write;
  42. uint8_t ainfo_write;
  43. uint8_t bcaps_read;
  44. uint8_t r0p_read;
  45. uint8_t rx_validation;
  46. uint8_t encryption;
  47. uint8_t link_maintenance;
  48. uint8_t ready_check;
  49. uint8_t bstatus_read;
  50. uint8_t max_cascade_check;
  51. uint8_t max_devs_check;
  52. uint8_t device_count_check;
  53. uint8_t ksvlist_read;
  54. uint8_t vp_read;
  55. uint8_t ksvlist_vp_validation;
  56. uint8_t hdcp_capable_dp;
  57. uint8_t binfo_read_dp;
  58. uint8_t r0p_available_dp;
  59. uint8_t link_integrity_check;
  60. uint8_t reauth_request_check;
  61. uint8_t stream_encryption_dp;
  62. };
  63. struct mod_hdcp_transition_input_hdcp2 {
  64. uint8_t hdcp2version_read;
  65. uint8_t hdcp2_capable_check;
  66. uint8_t create_session;
  67. uint8_t ake_init_prepare;
  68. uint8_t ake_init_write;
  69. uint8_t rxstatus_read;
  70. uint8_t ake_cert_available;
  71. uint8_t ake_cert_read;
  72. uint8_t ake_cert_validation;
  73. uint8_t stored_km_write;
  74. uint8_t no_stored_km_write;
  75. uint8_t h_prime_available;
  76. uint8_t h_prime_read;
  77. uint8_t pairing_available;
  78. uint8_t pairing_info_read;
  79. uint8_t h_prime_validation;
  80. uint8_t lc_init_prepare;
  81. uint8_t lc_init_write;
  82. uint8_t l_prime_available_poll;
  83. uint8_t l_prime_read;
  84. uint8_t l_prime_validation;
  85. uint8_t eks_prepare;
  86. uint8_t eks_write;
  87. uint8_t enable_encryption;
  88. uint8_t reauth_request_check;
  89. uint8_t rx_id_list_read;
  90. uint8_t device_count_check;
  91. uint8_t rx_id_list_validation;
  92. uint8_t repeater_auth_ack_write;
  93. uint8_t prepare_stream_manage;
  94. uint8_t stream_manage_write;
  95. uint8_t stream_ready_available;
  96. uint8_t stream_ready_read;
  97. uint8_t stream_ready_validation;
  98. uint8_t rx_caps_read_dp;
  99. uint8_t content_stream_type_write;
  100. uint8_t link_integrity_check_dp;
  101. uint8_t stream_encryption_dp;
  102. };
  103. union mod_hdcp_transition_input {
  104. struct mod_hdcp_transition_input_hdcp1 hdcp1;
  105. struct mod_hdcp_transition_input_hdcp2 hdcp2;
  106. };
  107. struct mod_hdcp_message_hdcp1 {
  108. uint8_t an[8];
  109. uint8_t aksv[5];
  110. uint8_t ainfo;
  111. uint8_t bksv[5];
  112. uint16_t r0p;
  113. uint8_t bcaps;
  114. uint16_t bstatus;
  115. uint8_t ksvlist[635];
  116. uint16_t ksvlist_size;
  117. uint8_t vp[20];
  118. uint16_t binfo_dp;
  119. };
  120. struct mod_hdcp_message_hdcp2 {
  121. uint8_t hdcp2version_hdmi;
  122. uint8_t rxcaps_dp[3];
  123. uint8_t rxstatus[2];
  124. uint8_t ake_init[12];
  125. uint8_t ake_cert[534];
  126. uint8_t ake_no_stored_km[129];
  127. uint8_t ake_stored_km[33];
  128. uint8_t ake_h_prime[33];
  129. uint8_t ake_pairing_info[17];
  130. uint8_t lc_init[9];
  131. uint8_t lc_l_prime[33];
  132. uint8_t ske_eks[25];
  133. uint8_t rx_id_list[177]; // 22 + 5 * 31
  134. uint16_t rx_id_list_size;
  135. uint8_t repeater_auth_ack[17];
  136. uint8_t repeater_auth_stream_manage[68]; // 6 + 2 * 31
  137. uint16_t stream_manage_size;
  138. uint8_t repeater_auth_stream_ready[33];
  139. uint8_t rxstatus_dp;
  140. uint8_t content_stream_type_dp[2];
  141. };
  142. union mod_hdcp_message {
  143. struct mod_hdcp_message_hdcp1 hdcp1;
  144. struct mod_hdcp_message_hdcp2 hdcp2;
  145. };
  146. struct mod_hdcp_auth_counters {
  147. uint8_t stream_management_retry_count;
  148. };
  149. /* contains values per connection */
  150. struct mod_hdcp_connection {
  151. struct mod_hdcp_link link;
  152. uint8_t is_repeater;
  153. uint8_t is_km_stored;
  154. uint8_t is_hdcp1_revoked;
  155. uint8_t is_hdcp2_revoked;
  156. struct mod_hdcp_trace trace;
  157. uint8_t hdcp1_retry_count;
  158. uint8_t hdcp2_retry_count;
  159. };
  160. /* contains values per authentication cycle */
  161. struct mod_hdcp_authentication {
  162. uint32_t id;
  163. union mod_hdcp_message msg;
  164. union mod_hdcp_transition_input trans_input;
  165. struct mod_hdcp_auth_counters count;
  166. };
  167. /* contains values per state change */
  168. struct mod_hdcp_state {
  169. uint8_t id;
  170. uint32_t stay_count;
  171. };
  172. /* per event in a state */
  173. struct mod_hdcp_event_context {
  174. enum mod_hdcp_event event;
  175. uint8_t rx_id_list_ready;
  176. uint8_t unexpected_event;
  177. };
  178. struct mod_hdcp {
  179. /* per link */
  180. struct mod_hdcp_config config;
  181. /* per connection */
  182. struct mod_hdcp_connection connection;
  183. /* per displays */
  184. struct mod_hdcp_display displays[MAX_NUM_OF_DISPLAYS];
  185. /* per authentication attempt */
  186. struct mod_hdcp_authentication auth;
  187. /* per state in an authentication */
  188. struct mod_hdcp_state state;
  189. /* reserved memory buffer */
  190. uint8_t buf[2025];
  191. };
  192. enum mod_hdcp_initial_state_id {
  193. HDCP_UNINITIALIZED = 0x0,
  194. HDCP_INITIAL_STATE_START = HDCP_UNINITIALIZED,
  195. HDCP_INITIALIZED,
  196. HDCP_CP_NOT_DESIRED,
  197. HDCP_INITIAL_STATE_END = HDCP_CP_NOT_DESIRED
  198. };
  199. enum mod_hdcp_hdcp1_state_id {
  200. HDCP1_STATE_START = HDCP_INITIAL_STATE_END,
  201. H1_A0_WAIT_FOR_ACTIVE_RX,
  202. H1_A1_EXCHANGE_KSVS,
  203. H1_A2_COMPUTATIONS_A3_VALIDATE_RX_A6_TEST_FOR_REPEATER,
  204. H1_A45_AUTHENTICATED,
  205. H1_A8_WAIT_FOR_READY,
  206. H1_A9_READ_KSV_LIST,
  207. HDCP1_STATE_END = H1_A9_READ_KSV_LIST
  208. };
  209. enum mod_hdcp_hdcp1_dp_state_id {
  210. HDCP1_DP_STATE_START = HDCP1_STATE_END,
  211. D1_A0_DETERMINE_RX_HDCP_CAPABLE,
  212. D1_A1_EXCHANGE_KSVS,
  213. D1_A23_WAIT_FOR_R0_PRIME,
  214. D1_A2_COMPUTATIONS_A3_VALIDATE_RX_A5_TEST_FOR_REPEATER,
  215. D1_A4_AUTHENTICATED,
  216. D1_A6_WAIT_FOR_READY,
  217. D1_A7_READ_KSV_LIST,
  218. HDCP1_DP_STATE_END = D1_A7_READ_KSV_LIST,
  219. };
  220. enum mod_hdcp_hdcp2_state_id {
  221. HDCP2_STATE_START = HDCP1_DP_STATE_END,
  222. H2_A0_KNOWN_HDCP2_CAPABLE_RX,
  223. H2_A1_SEND_AKE_INIT,
  224. H2_A1_VALIDATE_AKE_CERT,
  225. H2_A1_SEND_NO_STORED_KM,
  226. H2_A1_READ_H_PRIME,
  227. H2_A1_READ_PAIRING_INFO_AND_VALIDATE_H_PRIME,
  228. H2_A1_SEND_STORED_KM,
  229. H2_A1_VALIDATE_H_PRIME,
  230. H2_A2_LOCALITY_CHECK,
  231. H2_A3_EXCHANGE_KS_AND_TEST_FOR_REPEATER,
  232. H2_ENABLE_ENCRYPTION,
  233. H2_A5_AUTHENTICATED,
  234. H2_A6_WAIT_FOR_RX_ID_LIST,
  235. H2_A78_VERIFY_RX_ID_LIST_AND_SEND_ACK,
  236. H2_A9_SEND_STREAM_MANAGEMENT,
  237. H2_A9_VALIDATE_STREAM_READY,
  238. HDCP2_STATE_END = H2_A9_VALIDATE_STREAM_READY,
  239. };
  240. enum mod_hdcp_hdcp2_dp_state_id {
  241. HDCP2_DP_STATE_START = HDCP2_STATE_END,
  242. D2_A0_DETERMINE_RX_HDCP_CAPABLE,
  243. D2_A1_SEND_AKE_INIT,
  244. D2_A1_VALIDATE_AKE_CERT,
  245. D2_A1_SEND_NO_STORED_KM,
  246. D2_A1_READ_H_PRIME,
  247. D2_A1_READ_PAIRING_INFO_AND_VALIDATE_H_PRIME,
  248. D2_A1_SEND_STORED_KM,
  249. D2_A1_VALIDATE_H_PRIME,
  250. D2_A2_LOCALITY_CHECK,
  251. D2_A34_EXCHANGE_KS_AND_TEST_FOR_REPEATER,
  252. D2_SEND_CONTENT_STREAM_TYPE,
  253. D2_ENABLE_ENCRYPTION,
  254. D2_A5_AUTHENTICATED,
  255. D2_A6_WAIT_FOR_RX_ID_LIST,
  256. D2_A78_VERIFY_RX_ID_LIST_AND_SEND_ACK,
  257. D2_A9_SEND_STREAM_MANAGEMENT,
  258. D2_A9_VALIDATE_STREAM_READY,
  259. HDCP2_DP_STATE_END = D2_A9_VALIDATE_STREAM_READY,
  260. HDCP_STATE_END = HDCP2_DP_STATE_END,
  261. };
  262. /* hdcp1 executions and transitions */
  263. typedef enum mod_hdcp_status (*mod_hdcp_action)(struct mod_hdcp *hdcp);
  264. uint8_t mod_hdcp_execute_and_set(
  265. mod_hdcp_action func, uint8_t *flag,
  266. enum mod_hdcp_status *status, struct mod_hdcp *hdcp, char *str);
  267. enum mod_hdcp_status mod_hdcp_hdcp1_execution(struct mod_hdcp *hdcp,
  268. struct mod_hdcp_event_context *event_ctx,
  269. struct mod_hdcp_transition_input_hdcp1 *input);
  270. enum mod_hdcp_status mod_hdcp_hdcp1_dp_execution(struct mod_hdcp *hdcp,
  271. struct mod_hdcp_event_context *event_ctx,
  272. struct mod_hdcp_transition_input_hdcp1 *input);
  273. enum mod_hdcp_status mod_hdcp_hdcp1_transition(struct mod_hdcp *hdcp,
  274. struct mod_hdcp_event_context *event_ctx,
  275. struct mod_hdcp_transition_input_hdcp1 *input,
  276. struct mod_hdcp_output *output);
  277. enum mod_hdcp_status mod_hdcp_hdcp1_dp_transition(struct mod_hdcp *hdcp,
  278. struct mod_hdcp_event_context *event_ctx,
  279. struct mod_hdcp_transition_input_hdcp1 *input,
  280. struct mod_hdcp_output *output);
  281. /* hdcp2 executions and transitions */
  282. enum mod_hdcp_status mod_hdcp_hdcp2_execution(struct mod_hdcp *hdcp,
  283. struct mod_hdcp_event_context *event_ctx,
  284. struct mod_hdcp_transition_input_hdcp2 *input);
  285. enum mod_hdcp_status mod_hdcp_hdcp2_dp_execution(struct mod_hdcp *hdcp,
  286. struct mod_hdcp_event_context *event_ctx,
  287. struct mod_hdcp_transition_input_hdcp2 *input);
  288. enum mod_hdcp_status mod_hdcp_hdcp2_transition(struct mod_hdcp *hdcp,
  289. struct mod_hdcp_event_context *event_ctx,
  290. struct mod_hdcp_transition_input_hdcp2 *input,
  291. struct mod_hdcp_output *output);
  292. enum mod_hdcp_status mod_hdcp_hdcp2_dp_transition(struct mod_hdcp *hdcp,
  293. struct mod_hdcp_event_context *event_ctx,
  294. struct mod_hdcp_transition_input_hdcp2 *input,
  295. struct mod_hdcp_output *output);
  296. /* log functions */
  297. void mod_hdcp_dump_binary_message(uint8_t *msg, uint32_t msg_size,
  298. uint8_t *buf, uint32_t buf_size);
  299. void mod_hdcp_log_ddc_trace(struct mod_hdcp *hdcp);
  300. /* TODO: add adjustment log */
  301. /* psp functions */
  302. enum mod_hdcp_status mod_hdcp_add_display_to_topology(
  303. struct mod_hdcp *hdcp, struct mod_hdcp_display *display);
  304. enum mod_hdcp_status mod_hdcp_remove_display_from_topology(
  305. struct mod_hdcp *hdcp, uint8_t index);
  306. enum mod_hdcp_status mod_hdcp_hdcp1_create_session(struct mod_hdcp *hdcp);
  307. enum mod_hdcp_status mod_hdcp_hdcp1_destroy_session(struct mod_hdcp *hdcp);
  308. enum mod_hdcp_status mod_hdcp_hdcp1_validate_rx(struct mod_hdcp *hdcp);
  309. enum mod_hdcp_status mod_hdcp_hdcp1_enable_encryption(struct mod_hdcp *hdcp);
  310. enum mod_hdcp_status mod_hdcp_hdcp1_validate_ksvlist_vp(struct mod_hdcp *hdcp);
  311. enum mod_hdcp_status mod_hdcp_hdcp1_enable_dp_stream_encryption(
  312. struct mod_hdcp *hdcp);
  313. enum mod_hdcp_status mod_hdcp_hdcp1_link_maintenance(struct mod_hdcp *hdcp);
  314. enum mod_hdcp_status mod_hdcp_hdcp2_create_session(struct mod_hdcp *hdcp);
  315. enum mod_hdcp_status mod_hdcp_hdcp2_destroy_session(struct mod_hdcp *hdcp);
  316. enum mod_hdcp_status mod_hdcp_hdcp2_prepare_ake_init(struct mod_hdcp *hdcp);
  317. enum mod_hdcp_status mod_hdcp_hdcp2_validate_ake_cert(struct mod_hdcp *hdcp);
  318. enum mod_hdcp_status mod_hdcp_hdcp2_validate_h_prime(struct mod_hdcp *hdcp);
  319. enum mod_hdcp_status mod_hdcp_hdcp2_prepare_lc_init(struct mod_hdcp *hdcp);
  320. enum mod_hdcp_status mod_hdcp_hdcp2_validate_l_prime(struct mod_hdcp *hdcp);
  321. enum mod_hdcp_status mod_hdcp_hdcp2_prepare_eks(struct mod_hdcp *hdcp);
  322. enum mod_hdcp_status mod_hdcp_hdcp2_enable_encryption(struct mod_hdcp *hdcp);
  323. enum mod_hdcp_status mod_hdcp_hdcp2_validate_rx_id_list(struct mod_hdcp *hdcp);
  324. enum mod_hdcp_status mod_hdcp_hdcp2_enable_dp_stream_encryption(
  325. struct mod_hdcp *hdcp);
  326. enum mod_hdcp_status mod_hdcp_hdcp2_prepare_stream_management(
  327. struct mod_hdcp *hdcp);
  328. enum mod_hdcp_status mod_hdcp_hdcp2_validate_stream_ready(
  329. struct mod_hdcp *hdcp);
  330. /* ddc functions */
  331. enum mod_hdcp_status mod_hdcp_read_bksv(struct mod_hdcp *hdcp);
  332. enum mod_hdcp_status mod_hdcp_read_bcaps(struct mod_hdcp *hdcp);
  333. enum mod_hdcp_status mod_hdcp_read_bstatus(struct mod_hdcp *hdcp);
  334. enum mod_hdcp_status mod_hdcp_read_r0p(struct mod_hdcp *hdcp);
  335. enum mod_hdcp_status mod_hdcp_read_ksvlist(struct mod_hdcp *hdcp);
  336. enum mod_hdcp_status mod_hdcp_read_vp(struct mod_hdcp *hdcp);
  337. enum mod_hdcp_status mod_hdcp_read_binfo(struct mod_hdcp *hdcp);
  338. enum mod_hdcp_status mod_hdcp_write_aksv(struct mod_hdcp *hdcp);
  339. enum mod_hdcp_status mod_hdcp_write_ainfo(struct mod_hdcp *hdcp);
  340. enum mod_hdcp_status mod_hdcp_write_an(struct mod_hdcp *hdcp);
  341. enum mod_hdcp_status mod_hdcp_read_hdcp2version(struct mod_hdcp *hdcp);
  342. enum mod_hdcp_status mod_hdcp_read_rxcaps(struct mod_hdcp *hdcp);
  343. enum mod_hdcp_status mod_hdcp_read_rxstatus(struct mod_hdcp *hdcp);
  344. enum mod_hdcp_status mod_hdcp_read_ake_cert(struct mod_hdcp *hdcp);
  345. enum mod_hdcp_status mod_hdcp_read_h_prime(struct mod_hdcp *hdcp);
  346. enum mod_hdcp_status mod_hdcp_read_pairing_info(struct mod_hdcp *hdcp);
  347. enum mod_hdcp_status mod_hdcp_read_l_prime(struct mod_hdcp *hdcp);
  348. enum mod_hdcp_status mod_hdcp_read_rx_id_list(struct mod_hdcp *hdcp);
  349. enum mod_hdcp_status mod_hdcp_read_stream_ready(struct mod_hdcp *hdcp);
  350. enum mod_hdcp_status mod_hdcp_write_ake_init(struct mod_hdcp *hdcp);
  351. enum mod_hdcp_status mod_hdcp_write_no_stored_km(struct mod_hdcp *hdcp);
  352. enum mod_hdcp_status mod_hdcp_write_stored_km(struct mod_hdcp *hdcp);
  353. enum mod_hdcp_status mod_hdcp_write_lc_init(struct mod_hdcp *hdcp);
  354. enum mod_hdcp_status mod_hdcp_write_eks(struct mod_hdcp *hdcp);
  355. enum mod_hdcp_status mod_hdcp_write_repeater_auth_ack(struct mod_hdcp *hdcp);
  356. enum mod_hdcp_status mod_hdcp_write_stream_manage(struct mod_hdcp *hdcp);
  357. enum mod_hdcp_status mod_hdcp_write_content_type(struct mod_hdcp *hdcp);
  358. enum mod_hdcp_status mod_hdcp_clear_cp_irq_status(struct mod_hdcp *hdcp);
  359. /* hdcp version helpers */
  360. static inline uint8_t is_dp_hdcp(struct mod_hdcp *hdcp)
  361. {
  362. return (hdcp->connection.link.mode == MOD_HDCP_MODE_DP);
  363. }
  364. static inline uint8_t is_dp_mst_hdcp(struct mod_hdcp *hdcp)
  365. {
  366. return (hdcp->connection.link.mode == MOD_HDCP_MODE_DP &&
  367. hdcp->connection.link.dp.mst_enabled);
  368. }
  369. static inline uint8_t is_hdmi_dvi_sl_hdcp(struct mod_hdcp *hdcp)
  370. {
  371. return (hdcp->connection.link.mode == MOD_HDCP_MODE_DEFAULT);
  372. }
  373. /* hdcp state helpers */
  374. static inline uint8_t current_state(struct mod_hdcp *hdcp)
  375. {
  376. return hdcp->state.id;
  377. }
  378. static inline void set_state_id(struct mod_hdcp *hdcp,
  379. struct mod_hdcp_output *output, uint8_t id)
  380. {
  381. memset(&hdcp->state, 0, sizeof(hdcp->state));
  382. hdcp->state.id = id;
  383. /* callback timer should be reset per state */
  384. output->callback_stop = 1;
  385. output->watchdog_timer_stop = 1;
  386. HDCP_NEXT_STATE_TRACE(hdcp, id, output);
  387. }
  388. static inline uint8_t is_in_hdcp1_states(struct mod_hdcp *hdcp)
  389. {
  390. return (current_state(hdcp) > HDCP1_STATE_START &&
  391. current_state(hdcp) <= HDCP1_STATE_END);
  392. }
  393. static inline uint8_t is_in_hdcp1_dp_states(struct mod_hdcp *hdcp)
  394. {
  395. return (current_state(hdcp) > HDCP1_DP_STATE_START &&
  396. current_state(hdcp) <= HDCP1_DP_STATE_END);
  397. }
  398. static inline uint8_t is_in_hdcp2_states(struct mod_hdcp *hdcp)
  399. {
  400. return (current_state(hdcp) > HDCP2_STATE_START &&
  401. current_state(hdcp) <= HDCP2_STATE_END);
  402. }
  403. static inline uint8_t is_in_hdcp2_dp_states(struct mod_hdcp *hdcp)
  404. {
  405. return (current_state(hdcp) > HDCP2_DP_STATE_START &&
  406. current_state(hdcp) <= HDCP2_DP_STATE_END);
  407. }
  408. static inline uint8_t is_in_authenticated_states(struct mod_hdcp *hdcp)
  409. {
  410. return (current_state(hdcp) == D1_A4_AUTHENTICATED ||
  411. current_state(hdcp) == H1_A45_AUTHENTICATED ||
  412. current_state(hdcp) == D2_A5_AUTHENTICATED ||
  413. current_state(hdcp) == H2_A5_AUTHENTICATED);
  414. }
  415. static inline uint8_t is_hdcp1(struct mod_hdcp *hdcp)
  416. {
  417. return (is_in_hdcp1_states(hdcp) || is_in_hdcp1_dp_states(hdcp));
  418. }
  419. static inline uint8_t is_hdcp2(struct mod_hdcp *hdcp)
  420. {
  421. return (is_in_hdcp2_states(hdcp) || is_in_hdcp2_dp_states(hdcp));
  422. }
  423. static inline uint8_t is_in_cp_not_desired_state(struct mod_hdcp *hdcp)
  424. {
  425. return current_state(hdcp) == HDCP_CP_NOT_DESIRED;
  426. }
  427. static inline uint8_t is_in_initialized_state(struct mod_hdcp *hdcp)
  428. {
  429. return current_state(hdcp) == HDCP_INITIALIZED;
  430. }
  431. /* transition operation helpers */
  432. static inline void increment_stay_counter(struct mod_hdcp *hdcp)
  433. {
  434. hdcp->state.stay_count++;
  435. }
  436. static inline void fail_and_restart_in_ms(uint16_t time,
  437. enum mod_hdcp_status *status,
  438. struct mod_hdcp_output *output)
  439. {
  440. output->callback_needed = 1;
  441. output->callback_delay = time;
  442. output->watchdog_timer_needed = 0;
  443. output->watchdog_timer_delay = 0;
  444. *status = MOD_HDCP_STATUS_RESET_NEEDED;
  445. }
  446. static inline void callback_in_ms(uint16_t time, struct mod_hdcp_output *output)
  447. {
  448. output->callback_needed = 1;
  449. output->callback_delay = time;
  450. }
  451. static inline void set_watchdog_in_ms(struct mod_hdcp *hdcp, uint16_t time,
  452. struct mod_hdcp_output *output)
  453. {
  454. output->watchdog_timer_needed = 1;
  455. output->watchdog_timer_delay = time;
  456. }
  457. static inline void set_auth_complete(struct mod_hdcp *hdcp,
  458. struct mod_hdcp_output *output)
  459. {
  460. output->auth_complete = 1;
  461. mod_hdcp_log_ddc_trace(hdcp);
  462. }
  463. /* connection topology helpers */
  464. static inline uint8_t is_display_active(struct mod_hdcp_display *display)
  465. {
  466. return display->state >= MOD_HDCP_DISPLAY_ACTIVE;
  467. }
  468. static inline uint8_t is_display_encryption_enabled(struct mod_hdcp_display *display)
  469. {
  470. return display->state >= MOD_HDCP_DISPLAY_ENCRYPTION_ENABLED;
  471. }
  472. static inline uint8_t get_active_display_count(struct mod_hdcp *hdcp)
  473. {
  474. uint8_t active_count = 0;
  475. uint8_t i;
  476. for (i = 0; i < MAX_NUM_OF_DISPLAYS; i++)
  477. if (is_display_active(&hdcp->displays[i]))
  478. active_count++;
  479. return active_count;
  480. }
  481. static inline struct mod_hdcp_display *get_first_active_display(
  482. struct mod_hdcp *hdcp)
  483. {
  484. uint8_t i;
  485. struct mod_hdcp_display *display = NULL;
  486. for (i = 0; i < MAX_NUM_OF_DISPLAYS; i++)
  487. if (is_display_active(&hdcp->displays[i])) {
  488. display = &hdcp->displays[i];
  489. break;
  490. }
  491. return display;
  492. }
  493. static inline struct mod_hdcp_display *get_active_display_at_index(
  494. struct mod_hdcp *hdcp, uint8_t index)
  495. {
  496. uint8_t i;
  497. struct mod_hdcp_display *display = NULL;
  498. for (i = 0; i < MAX_NUM_OF_DISPLAYS; i++)
  499. if (hdcp->displays[i].index == index &&
  500. is_display_active(&hdcp->displays[i])) {
  501. display = &hdcp->displays[i];
  502. break;
  503. }
  504. return display;
  505. }
  506. static inline struct mod_hdcp_display *get_empty_display_container(
  507. struct mod_hdcp *hdcp)
  508. {
  509. uint8_t i;
  510. struct mod_hdcp_display *display = NULL;
  511. for (i = 0; i < MAX_NUM_OF_DISPLAYS; i++)
  512. if (!is_display_active(&hdcp->displays[i])) {
  513. display = &hdcp->displays[i];
  514. break;
  515. }
  516. return display;
  517. }
  518. static inline void reset_retry_counts(struct mod_hdcp *hdcp)
  519. {
  520. hdcp->connection.hdcp1_retry_count = 0;
  521. hdcp->connection.hdcp2_retry_count = 0;
  522. }
  523. #endif /* HDCP_H_ */