1 /* 2 * Copyright 2018 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 26 #ifndef MOD_HDCP_H_ 27 #define MOD_HDCP_H_ 28 29 #include "os_types.h" 30 #include "signal_types.h" 31 32 /* Forward Declarations */ 33 struct mod_hdcp; 34 35 #define MAX_NUM_OF_DISPLAYS 6 36 #define MAX_NUM_OF_ATTEMPTS 4 37 #define MAX_NUM_OF_ERROR_TRACE 10 38 39 /* detailed return status */ 40 enum mod_hdcp_status { 41 MOD_HDCP_STATUS_SUCCESS = 0, 42 MOD_HDCP_STATUS_FAILURE, 43 MOD_HDCP_STATUS_RESET_NEEDED, 44 MOD_HDCP_STATUS_DISPLAY_OUT_OF_BOUND, 45 MOD_HDCP_STATUS_DISPLAY_NOT_FOUND, 46 MOD_HDCP_STATUS_INVALID_STATE, 47 MOD_HDCP_STATUS_NOT_IMPLEMENTED, 48 MOD_HDCP_STATUS_INTERNAL_POLICY_FAILURE, 49 MOD_HDCP_STATUS_UPDATE_TOPOLOGY_FAILURE, 50 MOD_HDCP_STATUS_CREATE_PSP_SERVICE_FAILURE, 51 MOD_HDCP_STATUS_DESTROY_PSP_SERVICE_FAILURE, 52 MOD_HDCP_STATUS_HDCP1_CREATE_SESSION_FAILURE, 53 MOD_HDCP_STATUS_HDCP1_DESTROY_SESSION_FAILURE, 54 MOD_HDCP_STATUS_HDCP1_VALIDATE_ENCRYPTION_FAILURE, 55 MOD_HDCP_STATUS_HDCP1_NOT_HDCP_REPEATER, 56 MOD_HDCP_STATUS_HDCP1_NOT_CAPABLE, 57 MOD_HDCP_STATUS_HDCP1_R0_PRIME_PENDING, 58 MOD_HDCP_STATUS_HDCP1_VALIDATE_RX_FAILURE, 59 MOD_HDCP_STATUS_HDCP1_BKSV_REVOKED, 60 MOD_HDCP_STATUS_HDCP1_KSV_LIST_NOT_READY, 61 MOD_HDCP_STATUS_HDCP1_VALIDATE_KSV_LIST_FAILURE, 62 MOD_HDCP_STATUS_HDCP1_KSV_LIST_REVOKED, 63 MOD_HDCP_STATUS_HDCP1_ENABLE_ENCRYPTION_FAILURE, 64 MOD_HDCP_STATUS_HDCP1_ENABLE_STREAM_ENCRYPTION_FAILURE, 65 MOD_HDCP_STATUS_HDCP1_MAX_CASCADE_EXCEEDED_FAILURE, 66 MOD_HDCP_STATUS_HDCP1_MAX_DEVS_EXCEEDED_FAILURE, 67 MOD_HDCP_STATUS_HDCP1_DEVICE_COUNT_MISMATCH_FAILURE, 68 MOD_HDCP_STATUS_HDCP1_LINK_INTEGRITY_FAILURE, 69 MOD_HDCP_STATUS_HDCP1_REAUTH_REQUEST_ISSUED, 70 MOD_HDCP_STATUS_HDCP1_LINK_MAINTENANCE_FAILURE, 71 MOD_HDCP_STATUS_HDCP1_INVALID_BKSV, 72 MOD_HDCP_STATUS_DDC_FAILURE, /* TODO: specific errors */ 73 MOD_HDCP_STATUS_INVALID_OPERATION, 74 MOD_HDCP_STATUS_HDCP2_NOT_CAPABLE, 75 MOD_HDCP_STATUS_HDCP2_CREATE_SESSION_FAILURE, 76 MOD_HDCP_STATUS_HDCP2_DESTROY_SESSION_FAILURE, 77 MOD_HDCP_STATUS_HDCP2_PREP_AKE_INIT_FAILURE, 78 MOD_HDCP_STATUS_HDCP2_AKE_CERT_PENDING, 79 MOD_HDCP_STATUS_HDCP2_H_PRIME_PENDING, 80 MOD_HDCP_STATUS_HDCP2_PAIRING_INFO_PENDING, 81 MOD_HDCP_STATUS_HDCP2_VALIDATE_AKE_CERT_FAILURE, 82 MOD_HDCP_STATUS_HDCP2_AKE_CERT_REVOKED, 83 MOD_HDCP_STATUS_HDCP2_VALIDATE_H_PRIME_FAILURE, 84 MOD_HDCP_STATUS_HDCP2_VALIDATE_PAIRING_INFO_FAILURE, 85 MOD_HDCP_STATUS_HDCP2_PREP_LC_INIT_FAILURE, 86 MOD_HDCP_STATUS_HDCP2_L_PRIME_PENDING, 87 MOD_HDCP_STATUS_HDCP2_VALIDATE_L_PRIME_FAILURE, 88 MOD_HDCP_STATUS_HDCP2_PREP_EKS_FAILURE, 89 MOD_HDCP_STATUS_HDCP2_ENABLE_ENCRYPTION_FAILURE, 90 MOD_HDCP_STATUS_HDCP2_RX_ID_LIST_NOT_READY, 91 MOD_HDCP_STATUS_HDCP2_VALIDATE_RX_ID_LIST_FAILURE, 92 MOD_HDCP_STATUS_HDCP2_RX_ID_LIST_REVOKED, 93 MOD_HDCP_STATUS_HDCP2_ENABLE_STREAM_ENCRYPTION_FAILURE, 94 MOD_HDCP_STATUS_HDCP2_STREAM_READY_PENDING, 95 MOD_HDCP_STATUS_HDCP2_VALIDATE_STREAM_READY_FAILURE, 96 MOD_HDCP_STATUS_HDCP2_PREPARE_STREAM_MANAGEMENT_FAILURE, 97 MOD_HDCP_STATUS_HDCP2_REAUTH_REQUEST, 98 MOD_HDCP_STATUS_HDCP2_REAUTH_LINK_INTEGRITY_FAILURE, 99 MOD_HDCP_STATUS_HDCP2_DEVICE_COUNT_MISMATCH_FAILURE, 100 MOD_HDCP_STATUS_UNSUPPORTED_PSP_VER_FAILURE, 101 }; 102 103 struct mod_hdcp_displayport { 104 uint8_t rev; 105 uint8_t assr_enabled; 106 uint8_t mst_enabled; 107 uint8_t dp2_enabled; 108 uint8_t usb4_enabled; 109 }; 110 111 struct mod_hdcp_hdmi { 112 uint8_t reserved; 113 }; 114 enum mod_hdcp_operation_mode { 115 MOD_HDCP_MODE_OFF, 116 MOD_HDCP_MODE_DEFAULT, 117 MOD_HDCP_MODE_DP 118 }; 119 120 enum mod_hdcp_display_state { 121 MOD_HDCP_DISPLAY_INACTIVE = 0, 122 MOD_HDCP_DISPLAY_ACTIVE, 123 MOD_HDCP_DISPLAY_ENCRYPTION_ENABLED 124 }; 125 126 struct mod_hdcp_psp_caps { 127 uint8_t dtm_v3_supported; 128 }; 129 130 enum mod_hdcp_display_disable_option { 131 MOD_HDCP_DISPLAY_NOT_DISABLE = 0, 132 MOD_HDCP_DISPLAY_DISABLE_AUTHENTICATION, 133 MOD_HDCP_DISPLAY_DISABLE_ENCRYPTION, 134 }; 135 136 struct mod_hdcp_atomic_op_i2c { 137 uint8_t address; 138 uint8_t offset; 139 uint8_t *data; 140 uint32_t size; 141 }; 142 143 struct mod_hdcp_atomic_op_aux { 144 uint32_t address; 145 uint8_t *data; 146 uint32_t size; 147 }; 148 149 struct mod_hdcp_ddc { 150 void *handle; 151 struct mod_hdcp_ddc_funcs { 152 bool (*read_i2c)(void *handle, 153 uint32_t address, 154 uint8_t offset, 155 uint8_t *data, 156 uint32_t size); 157 bool (*write_i2c)(void *handle, 158 uint32_t address, 159 const uint8_t *data, 160 uint32_t size); 161 bool (*read_dpcd)(void *handle, 162 uint32_t address, 163 uint8_t *data, 164 uint32_t size); 165 bool (*write_dpcd)(void *handle, 166 uint32_t address, 167 const uint8_t *data, 168 uint32_t size); 169 bool (*atomic_write_poll_read_i2c)( 170 void *handle, 171 const struct mod_hdcp_atomic_op_i2c *write, 172 const struct mod_hdcp_atomic_op_i2c *poll, 173 struct mod_hdcp_atomic_op_i2c *read, 174 uint32_t poll_timeout_us, 175 uint8_t poll_mask_msb 176 ); 177 bool (*atomic_write_poll_read_aux)( 178 void *handle, 179 const struct mod_hdcp_atomic_op_aux *write, 180 const struct mod_hdcp_atomic_op_aux *poll, 181 struct mod_hdcp_atomic_op_aux *read, 182 uint32_t poll_timeout_us, 183 uint8_t poll_mask_msb 184 ); 185 } funcs; 186 }; 187 188 struct mod_hdcp_psp { 189 void *handle; 190 void *funcs; 191 struct mod_hdcp_psp_caps caps; 192 }; 193 194 struct mod_hdcp_display_adjustment { 195 uint8_t disable : 2; 196 uint8_t reserved : 6; 197 }; 198 199 struct mod_hdcp_link_adjustment_hdcp1 { 200 uint8_t disable : 1; 201 uint8_t postpone_encryption : 1; 202 uint8_t min_auth_retries_wa : 1; 203 uint8_t reserved : 5; 204 }; 205 206 enum mod_hdcp_force_hdcp_type { 207 MOD_HDCP_FORCE_TYPE_MAX = 0, 208 MOD_HDCP_FORCE_TYPE_0, 209 MOD_HDCP_FORCE_TYPE_1 210 }; 211 212 struct mod_hdcp_link_adjustment_hdcp2 { 213 uint8_t disable : 1; 214 uint8_t force_type : 2; 215 uint8_t force_no_stored_km : 1; 216 uint8_t increase_h_prime_timeout: 1; 217 uint8_t force_sw_locality_check : 1; 218 uint8_t reserved : 2; 219 }; 220 221 struct mod_hdcp_link_adjustment { 222 uint8_t auth_delay; 223 uint8_t retry_limit; 224 struct mod_hdcp_link_adjustment_hdcp1 hdcp1; 225 struct mod_hdcp_link_adjustment_hdcp2 hdcp2; 226 }; 227 228 struct mod_hdcp_error { 229 enum mod_hdcp_status status; 230 uint8_t state_id; 231 }; 232 233 struct mod_hdcp_trace { 234 struct mod_hdcp_error errors[MAX_NUM_OF_ERROR_TRACE]; 235 uint8_t error_count; 236 }; 237 238 enum mod_hdcp_encryption_status { 239 MOD_HDCP_ENCRYPTION_STATUS_HDCP_OFF = 0, 240 MOD_HDCP_ENCRYPTION_STATUS_HDCP1_ON, 241 MOD_HDCP_ENCRYPTION_STATUS_HDCP2_TYPE0_ON, 242 MOD_HDCP_ENCRYPTION_STATUS_HDCP2_TYPE1_ON, 243 MOD_HDCP_ENCRYPTION_STATUS_HDCP2_ON 244 }; 245 246 /* per link events dm has to notify to hdcp module */ 247 enum mod_hdcp_event { 248 MOD_HDCP_EVENT_CALLBACK = 0, 249 MOD_HDCP_EVENT_WATCHDOG_TIMEOUT, 250 MOD_HDCP_EVENT_CPIRQ 251 }; 252 253 /* output flags from module requesting timer operations */ 254 struct mod_hdcp_output { 255 uint8_t callback_needed; 256 uint8_t callback_stop; 257 uint8_t watchdog_timer_needed; 258 uint8_t watchdog_timer_stop; 259 uint16_t callback_delay; 260 uint16_t watchdog_timer_delay; 261 uint8_t auth_complete; 262 }; 263 264 /* used to represent per display info */ 265 struct mod_hdcp_display { 266 enum mod_hdcp_display_state state; 267 uint8_t index; 268 uint8_t controller; 269 uint8_t dig_fe; 270 uint8_t stream_enc_idx; 271 union { 272 uint8_t vc_id; 273 }; 274 struct mod_hdcp_display_adjustment adjust; 275 }; 276 277 /* used to represent per link info */ 278 /* in case a link has multiple displays, they share the same link info */ 279 struct mod_hdcp_link { 280 enum mod_hdcp_operation_mode mode; 281 uint8_t dig_be; 282 uint8_t ddc_line; 283 uint8_t link_enc_idx; 284 uint8_t phy_idx; 285 uint8_t dio_output_id; 286 uint8_t hdcp_supported_informational; 287 union { 288 struct mod_hdcp_displayport dp; 289 struct mod_hdcp_hdmi hdmi; 290 }; 291 struct mod_hdcp_link_adjustment adjust; 292 }; 293 294 /* a query structure for a display's hdcp information */ 295 struct mod_hdcp_display_query { 296 const struct mod_hdcp_display *display; 297 const struct mod_hdcp_link *link; 298 const struct mod_hdcp_trace *trace; 299 enum mod_hdcp_encryption_status encryption_status; 300 }; 301 302 /* contains values per on external display configuration change */ 303 struct mod_hdcp_config { 304 struct mod_hdcp_psp psp; 305 struct mod_hdcp_ddc ddc; 306 struct { 307 uint8_t lc_enable_sw_fallback : 1; 308 uint8_t reserved : 7; 309 } debug; 310 uint8_t index; 311 }; 312 313 /* dm allocates memory of mod_hdcp per dc_link on dm init based on memory size*/ 314 size_t mod_hdcp_get_memory_size(void); 315 316 /* called per link on link creation */ 317 enum mod_hdcp_status mod_hdcp_setup(struct mod_hdcp *hdcp, 318 struct mod_hdcp_config *config); 319 320 /* called per link on link destroy */ 321 enum mod_hdcp_status mod_hdcp_teardown(struct mod_hdcp *hdcp); 322 323 /* called per display after stream is enabled */ 324 enum mod_hdcp_status mod_hdcp_add_display(struct mod_hdcp *hdcp, 325 struct mod_hdcp_link *link, struct mod_hdcp_display *display, 326 struct mod_hdcp_output *output); 327 328 /* called per display before stream is disabled */ 329 enum mod_hdcp_status mod_hdcp_remove_display(struct mod_hdcp *hdcp, 330 uint8_t index, struct mod_hdcp_output *output); 331 332 /* called per display to apply new authentication adjustment */ 333 enum mod_hdcp_status mod_hdcp_update_display(struct mod_hdcp *hdcp, 334 uint8_t index, 335 struct mod_hdcp_link_adjustment *link_adjust, 336 struct mod_hdcp_display_adjustment *display_adjust, 337 struct mod_hdcp_output *output); 338 339 /* called to query hdcp information on a specific index */ 340 enum mod_hdcp_status mod_hdcp_query_display(struct mod_hdcp *hdcp, 341 uint8_t index, struct mod_hdcp_display_query *query); 342 343 /* called per link on connectivity change */ 344 enum mod_hdcp_status mod_hdcp_reset_connection(struct mod_hdcp *hdcp, 345 struct mod_hdcp_output *output); 346 347 /* called per link on events (i.e. callback, watchdog, CP_IRQ) */ 348 enum mod_hdcp_status mod_hdcp_process_event(struct mod_hdcp *hdcp, 349 enum mod_hdcp_event event, struct mod_hdcp_output *output); 350 351 /* called to convert enum mod_hdcp_status to c string */ 352 char *mod_hdcp_status_to_str(int32_t status); 353 354 /* called to convert state id to c string */ 355 char *mod_hdcp_state_id_to_str(int32_t id); 356 357 /* called to convert signal type to operation mode */ 358 enum mod_hdcp_operation_mode mod_hdcp_signal_type_to_operation_mode( 359 enum signal_type signal); 360 #endif /* MOD_HDCP_H_ */ 361