xref: /linux/drivers/gpu/drm/amd/display/modules/inc/mod_hdcp.h (revision face6a3615a649456eb4549f6d474221d877d604)
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 	MOD_HDCP_STATUS_HDCP2_LOCALITY_COMBO_READ_FAILURE,
102 };
103 
104 struct mod_hdcp_displayport {
105 	uint8_t rev;
106 	uint8_t assr_enabled;
107 	uint8_t mst_enabled;
108 	uint8_t dp2_enabled;
109 	uint8_t usb4_enabled;
110 };
111 
112 struct mod_hdcp_hdmi {
113 	uint8_t reserved;
114 };
115 enum mod_hdcp_operation_mode {
116 	MOD_HDCP_MODE_OFF,
117 	MOD_HDCP_MODE_DEFAULT,
118 	MOD_HDCP_MODE_DP
119 };
120 
121 enum mod_hdcp_display_state {
122 	MOD_HDCP_DISPLAY_INACTIVE = 0,
123 	MOD_HDCP_DISPLAY_ACTIVE,
124 	MOD_HDCP_DISPLAY_ENCRYPTION_ENABLED
125 };
126 
127 struct mod_hdcp_psp_caps {
128 	uint8_t dtm_v3_supported;
129 };
130 
131 enum mod_hdcp_display_disable_option {
132 	MOD_HDCP_DISPLAY_NOT_DISABLE = 0,
133 	MOD_HDCP_DISPLAY_DISABLE_AUTHENTICATION,
134 	MOD_HDCP_DISPLAY_DISABLE_ENCRYPTION,
135 };
136 
137 struct mod_hdcp_atomic_op_i2c {
138 	uint8_t address;
139 	uint8_t offset;
140 	uint8_t *data;
141 	uint32_t size;
142 };
143 
144 struct mod_hdcp_atomic_op_aux {
145 	uint32_t address;
146 	uint8_t *data;
147 	uint32_t size;
148 };
149 
150 struct mod_hdcp_ddc {
151 	void *handle;
152 	struct mod_hdcp_ddc_funcs {
153 		bool (*read_i2c)(void *handle,
154 				uint32_t address,
155 				uint8_t offset,
156 				uint8_t *data,
157 				uint32_t size);
158 		bool (*write_i2c)(void *handle,
159 				uint32_t address,
160 				const uint8_t *data,
161 				uint32_t size);
162 		bool (*read_dpcd)(void *handle,
163 				uint32_t address,
164 				uint8_t *data,
165 				uint32_t size);
166 		bool (*write_dpcd)(void *handle,
167 				uint32_t address,
168 				const uint8_t *data,
169 				uint32_t size);
170 		bool (*atomic_write_poll_read_i2c)(
171 				void *handle,
172 				const struct mod_hdcp_atomic_op_i2c *write,
173 				const struct mod_hdcp_atomic_op_i2c *poll,
174 				struct mod_hdcp_atomic_op_i2c *read,
175 				uint32_t poll_timeout_us,
176 				uint8_t poll_mask_msb
177 		);
178 		bool (*atomic_write_poll_read_aux)(
179 				void *handle,
180 				const struct mod_hdcp_atomic_op_aux *write,
181 				const struct mod_hdcp_atomic_op_aux *poll,
182 				struct mod_hdcp_atomic_op_aux *read,
183 				uint32_t poll_timeout_us,
184 				uint8_t poll_mask_msb
185 		);
186 	} funcs;
187 };
188 
189 struct mod_hdcp_psp {
190 	void *handle;
191 	void *funcs;
192 	struct mod_hdcp_psp_caps caps;
193 };
194 
195 struct mod_hdcp_display_adjustment {
196 	uint8_t disable			: 2;
197 	uint8_t reserved		: 6;
198 };
199 
200 struct mod_hdcp_link_adjustment_hdcp1 {
201 	uint8_t disable			: 1;
202 	uint8_t postpone_encryption	: 1;
203 	uint8_t min_auth_retries_wa : 1;
204 	uint8_t reserved		: 5;
205 };
206 
207 enum mod_hdcp_force_hdcp_type {
208 	MOD_HDCP_FORCE_TYPE_MAX = 0,
209 	MOD_HDCP_FORCE_TYPE_0,
210 	MOD_HDCP_FORCE_TYPE_1
211 };
212 
213 struct mod_hdcp_link_adjustment_hdcp2 {
214 	uint8_t disable			: 1;
215 	uint8_t force_type		: 2;
216 	uint8_t force_no_stored_km	: 1;
217 	uint8_t increase_h_prime_timeout: 1;
218 	uint8_t use_fw_locality_check 	: 1;
219 	uint8_t use_sw_locality_fallback: 1;
220 	uint8_t reserved		: 1;
221 };
222 
223 struct mod_hdcp_link_adjustment {
224 	uint8_t auth_delay;
225 	uint8_t retry_limit;
226 	struct mod_hdcp_link_adjustment_hdcp1 hdcp1;
227 	struct mod_hdcp_link_adjustment_hdcp2 hdcp2;
228 };
229 
230 struct mod_hdcp_error {
231 	enum mod_hdcp_status status;
232 	uint8_t state_id;
233 };
234 
235 struct mod_hdcp1_trace {
236 	uint8_t attempt_count;
237 	uint8_t downstream_device_count;
238 };
239 
240 struct mod_hdcp2_trace {
241 	uint8_t attempt_count;
242 	uint8_t downstream_device_count;
243 	uint8_t hdcp1_device_downstream;
244 	uint8_t hdcp2_legacy_device_downstream;
245 };
246 
247 struct mod_hdcp_trace {
248 	struct mod_hdcp_error errors[MAX_NUM_OF_ERROR_TRACE];
249 	uint8_t error_count;
250 	struct mod_hdcp1_trace hdcp1;
251 	struct mod_hdcp2_trace hdcp2;
252 };
253 
254 enum mod_hdcp_encryption_status {
255 	MOD_HDCP_ENCRYPTION_STATUS_HDCP_OFF = 0,
256 	MOD_HDCP_ENCRYPTION_STATUS_HDCP1_ON,
257 	MOD_HDCP_ENCRYPTION_STATUS_HDCP2_TYPE0_ON,
258 	MOD_HDCP_ENCRYPTION_STATUS_HDCP2_TYPE1_ON,
259 	MOD_HDCP_ENCRYPTION_STATUS_HDCP2_ON
260 };
261 
262 /* per link events dm has to notify to hdcp module */
263 enum mod_hdcp_event {
264 	MOD_HDCP_EVENT_CALLBACK = 0,
265 	MOD_HDCP_EVENT_WATCHDOG_TIMEOUT,
266 	MOD_HDCP_EVENT_CPIRQ
267 };
268 
269 /* output flags from module requesting timer operations */
270 struct mod_hdcp_output {
271 	uint8_t callback_needed;
272 	uint8_t callback_stop;
273 	uint8_t watchdog_timer_needed;
274 	uint8_t watchdog_timer_stop;
275 	uint16_t callback_delay;
276 	uint16_t watchdog_timer_delay;
277 	uint8_t auth_complete;
278 };
279 
280 /* used to represent per display info */
281 struct mod_hdcp_display {
282 	enum mod_hdcp_display_state state;
283 	uint8_t index;
284 	uint8_t controller;
285 	uint8_t dig_fe;
286 	uint8_t stream_enc_idx;
287 	union {
288 		uint8_t vc_id;
289 	};
290 	struct mod_hdcp_display_adjustment adjust;
291 };
292 
293 /* used to represent per link info */
294 /* in case a link has multiple displays, they share the same link info */
295 struct mod_hdcp_link {
296 	enum mod_hdcp_operation_mode mode;
297 	uint8_t dig_be;
298 	uint8_t ddc_line;
299 	uint8_t link_enc_idx;
300 	uint8_t phy_idx;
301 	uint8_t dio_output_id;
302 	uint8_t hdcp_supported_informational;
303 	union {
304 		struct mod_hdcp_displayport dp;
305 		struct mod_hdcp_hdmi hdmi;
306 	};
307 	struct mod_hdcp_link_adjustment adjust;
308 };
309 
310 /* a query structure for a display's hdcp information */
311 struct mod_hdcp_display_query {
312 	const struct mod_hdcp_display *display;
313 	const struct mod_hdcp_link *link;
314 	const struct mod_hdcp_trace *trace;
315 	enum mod_hdcp_encryption_status encryption_status;
316 };
317 
318 /* contains values per on external display configuration change */
319 struct mod_hdcp_config {
320 	struct mod_hdcp_psp psp;
321 	struct mod_hdcp_ddc ddc;
322 	uint8_t index;
323 };
324 
325 /* dm allocates memory of mod_hdcp per dc_link on dm init based on memory size*/
326 size_t mod_hdcp_get_memory_size(void);
327 
328 /* called per link on link creation */
329 enum mod_hdcp_status mod_hdcp_setup(struct mod_hdcp *hdcp,
330 		struct mod_hdcp_config *config);
331 
332 /* called per link on link destroy */
333 enum mod_hdcp_status mod_hdcp_teardown(struct mod_hdcp *hdcp);
334 
335 /* called per display after stream is enabled */
336 enum mod_hdcp_status mod_hdcp_add_display(struct mod_hdcp *hdcp,
337 		struct mod_hdcp_link *link, struct mod_hdcp_display *display,
338 		struct mod_hdcp_output *output);
339 
340 /* called per display before stream is disabled */
341 enum mod_hdcp_status mod_hdcp_remove_display(struct mod_hdcp *hdcp,
342 		uint8_t index, struct mod_hdcp_output *output);
343 
344 /* called per display to apply new authentication adjustment */
345 enum mod_hdcp_status mod_hdcp_update_display(struct mod_hdcp *hdcp,
346 		uint8_t index,
347 		struct mod_hdcp_link_adjustment *link_adjust,
348 		struct mod_hdcp_display_adjustment *display_adjust,
349 		struct mod_hdcp_output *output);
350 
351 /* called to query hdcp information on a specific index */
352 enum mod_hdcp_status mod_hdcp_query_display(struct mod_hdcp *hdcp,
353 		uint8_t index, struct mod_hdcp_display_query *query);
354 
355 /* called per link on connectivity change */
356 enum mod_hdcp_status mod_hdcp_reset_connection(struct mod_hdcp *hdcp,
357 		struct mod_hdcp_output *output);
358 
359 /* called per link on events (i.e. callback, watchdog, CP_IRQ) */
360 enum mod_hdcp_status mod_hdcp_process_event(struct mod_hdcp *hdcp,
361 		enum mod_hdcp_event event, struct mod_hdcp_output *output);
362 
363 /* called to convert enum mod_hdcp_status to c string */
364 char *mod_hdcp_status_to_str(int32_t status);
365 
366 /* called to convert state id to c string */
367 char *mod_hdcp_state_id_to_str(int32_t id);
368 
369 /* called to convert signal type to operation mode */
370 enum mod_hdcp_operation_mode mod_hdcp_signal_type_to_operation_mode(
371 		enum signal_type signal);
372 #endif /* MOD_HDCP_H_ */
373