xref: /linux/drivers/gpu/drm/amd/display/dc/inc/link_service.h (revision bba2c3615bd6cfee7456d1130f2e6b01b3f4e9ba)
1 /*
2  * Copyright 2022 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 __DC_LINK_H__
27 #define __DC_LINK_H__
28 
29 /* FILE POLICY AND INTENDED USAGE:
30  *
31  * This header defines link component function interfaces aka link_service.
32  * link_service provides the only entry point to link functions with function
33  * pointer style. This header is strictly private in dc and should never be
34  * included by DM because it exposes too much dc detail including all dc
35  * private types defined in core_types.h. Otherwise it will break DM - DC
36  * encapsulation and turn DM into a maintenance nightmare.
37  *
38  * The following shows a link component relation map.
39  *
40  * DM to DC:
41  * DM includes dc.h
42  * dc_link_exports.c or other dc files implement dc.h
43  *
44  * DC to Link:
45  * dc_link_exports.c or other dc files include link_service.h
46  * link_factory.c implements link_service.h
47  *
48  * Link sub-component to Link sub-component:
49  * link_factory.c includes --> link_xxx.h
50  * link_xxx.c implements link_xxx.h
51 
52  * As you can see if you ever need to add a new dc link function and call it on
53  * DM/dc side, it is very difficult because you will need layers of translation.
54  * The most appropriate approach to implement new requirements on DM/dc side is
55  * to extend or generalize the functionality of existing link function
56  * interfaces so minimal modification is needed outside link component to
57  * achieve your new requirements. This approach reduces or even eliminates the
58  * effort needed outside link component to support a new link feature. This also
59  * reduces code discrepancy among DMs to support the same link feature. If we
60  * test full code path on one version of DM, and there is no feature specific
61  * modification required on other DMs, then we can have higher confidence that
62  * the feature will run on other DMs and produce the same result. The following
63  * are some good examples to start with:
64  *
65  * - detect_link --> to add new link detection or capability retrieval routines
66  *
67  * - validate_mode_timing --> to add new timing validation conditions
68  *
69  * - set_dpms_on/set_dpms_off --> to include new link enablement sequences
70  *
71  * If you must add new link functions, you will need to:
72  * 1. declare the function pointer here under the suitable commented category.
73  * 2. Implement your function in the suitable link_xxx.c file.
74  * 3. Assign the function to link_service in link_factory.c
75  * 4. NEVER include link_xxx.h headers outside link component.
76  * 5. NEVER include link_service.h on DM side.
77  */
78 #include "core_types.h"
79 
80 struct link_service *link_create_link_service(void);
81 void link_destroy_link_service(struct link_service **link_srv);
82 
83 struct link_init_data {
84 	const struct dc *dc;
85 	struct dc_context *ctx; /* TODO: remove 'dal' when DC is complete. */
86 	uint32_t connector_index; /* this will be mapped to the HPD pins */
87 	uint32_t link_index; /* this is mapped to DAL display_index
88 				TODO: remove it when DC is complete. */
89 	bool is_dpia_link;
90 };
91 
92 struct ddc_service_init_data {
93 	struct graphics_object_id id;
94 	struct dc_context *ctx;
95 	struct dc_link *link;
96 	bool is_dpia_link;
97 };
98 
99 struct link_service {
100 	/************************** Factory ***********************************/
101 	struct dc_link *(*create_link)(
102 			const struct link_init_data *init_params);
103 	void (*destroy_link)(struct dc_link **link);
104 
105 
106 	/************************** Detection *********************************/
107 	bool (*detect_link)(struct dc_link *link, enum dc_detect_reason reason);
108 	bool (*detect_connection_type)(struct dc_link *link,
109 			enum dc_connection_type *type);
110 	struct dc_sink *(*add_remote_sink)(
111 			struct dc_link *link,
112 			const uint8_t *edid,
113 			unsigned int len,
114 			struct dc_sink_init_data *init_data);
115 	void (*remove_remote_sink)(struct dc_link *link, struct dc_sink *sink);
116 	bool (*get_hpd_state)(struct dc_link *link);
117 	void (*enable_hpd)(const struct dc_link *link);
118 	void (*disable_hpd)(const struct dc_link *link);
119 	void (*enable_hpd_filter)(struct dc_link *link, bool enable);
120 	bool (*reset_cur_dp_mst_topology)(struct dc_link *link);
121 	const struct dc_link_status *(*get_status)(const struct dc_link *link);
122 	bool (*is_hdcp1x_supported)(struct dc_link *link,
123 			enum signal_type signal);
124 	bool (*is_hdcp2x_supported)(struct dc_link *link,
125 			enum signal_type signal);
126 	void (*clear_dprx_states)(struct dc_link *link);
127 
128 
129 	/*************************** Resource *********************************/
130 	void (*get_cur_res_map)(const struct dc *dc, uint32_t *map);
131 	void (*restore_res_map)(const struct dc *dc, uint32_t *map);
132 	void (*get_cur_link_res)(const struct dc_link *link,
133 			struct link_resource *link_res);
134 
135 
136 	/*************************** Validation *******************************/
137 	enum dc_status (*validate_mode_timing)(
138 			const struct dc_stream_state *stream,
139 			struct dc_link *link,
140 			const struct dc_crtc_timing *timing);
141 	uint32_t (*dp_link_bandwidth_kbps)(
142 		const struct dc_link *link,
143 		const struct dc_link_settings *link_settings);
144 	enum dc_status (*validate_dp_tunnel_bandwidth)(
145 		const struct dc *dc,
146 		const struct dc_state *new_ctx);
147 	uint32_t (*frl_link_bandwidth_kbps)(enum hdmi_frl_link_rate link_rate);
148 	bool (*frl_margin_check_uncompressed_video)(
149 		struct frl_cap_chk_params_fixed31_32 *params,
150 		struct frl_cap_chk_intermediates_fixed31_32 *inter);
151 
152 	uint32_t (*dp_required_hblank_size_bytes)(
153 		const struct dc_link *link,
154 		struct dp_audio_bandwidth_params *audio_params);
155 
156 
157 	/*************************** DPMS *************************************/
158 	void (*set_dpms_on)(struct dc_state *state, struct pipe_ctx *pipe_ctx);
159 	void (*set_dpms_off)(struct pipe_ctx *pipe_ctx);
160 	void (*resume)(struct dc_link *link);
161 	void (*blank_all_dp_displays)(struct dc *dc);
162 	void (*blank_all_edp_displays)(struct dc *dc);
163 	void (*blank_dp_stream)(struct dc_link *link, bool hw_init);
164 	enum dc_status (*increase_mst_payload)(
165 			struct pipe_ctx *pipe_ctx, uint32_t req_pbn);
166 	enum dc_status (*reduce_mst_payload)(
167 			struct pipe_ctx *pipe_ctx, uint32_t req_pbn);
168 	void (*set_dsc_on_stream)(struct pipe_ctx *pipe_ctx, bool enable);
169 	bool (*set_dsc_enable)(struct pipe_ctx *pipe_ctx, bool enable);
170 	bool (*update_dsc_config)(struct pipe_ctx *pipe_ctx);
171 	void (*wait_for_unlocked)(struct dc_link *link);
172 
173 
174 	/*************************** DDC **************************************/
175 	struct ddc_service *(*create_ddc_service)(
176 			struct ddc_service_init_data *ddc_init_data);
177 	void (*destroy_ddc_service)(struct ddc_service **ddc);
178 	bool (*query_ddc_data)(
179 			struct ddc_service *ddc,
180 			uint32_t address,
181 			uint8_t *write_buf,
182 			uint32_t write_size,
183 			uint8_t *read_buf,
184 			uint32_t read_size);
185 	int (*aux_transfer_raw)(struct ddc_service *ddc,
186 			struct aux_payload *payload,
187 			enum aux_return_code_type *operation_result);
188 	bool (*configure_fixed_vs_pe_retimer)(
189 			struct ddc_service *ddc,
190 			const uint8_t *data,
191 			uint32_t len);
192 	bool (*aux_transfer_with_retries_no_mutex)(struct ddc_service *ddc,
193 			struct aux_payload *payload);
194 	bool (*is_in_aux_transaction_mode)(struct ddc_service *ddc);
195 	uint32_t (*get_aux_defer_delay)(struct ddc_service *ddc);
196 
197 
198 	/*************************** DP Capability ****************************/
199 	bool (*dp_is_sink_present)(struct dc_link *link);
200 	bool (*dp_is_fec_supported)(const struct dc_link *link);
201 	bool (*dp_is_128b_132b_signal)(struct pipe_ctx *pipe_ctx);
202 	bool (*dp_get_max_link_enc_cap)(const struct dc_link *link,
203 			struct dc_link_settings *max_link_enc_cap);
204 	const struct dc_link_settings *(*dp_get_verified_link_cap)(
205 			const struct dc_link *link);
206 	enum dp_link_encoding (*dp_get_encoding_format)(
207 			const struct dc_link_settings *link_settings);
208 	bool (*dp_should_enable_fec)(const struct dc_link *link);
209 	bool (*dp_decide_link_settings)(
210 		struct dc_stream_state *stream,
211 		struct dc_link_settings *link_setting);
212 	void (*dp_decide_tunnel_settings)(
213 		struct dc_stream_state *stream,
214 		struct dc_tunnel_settings *dp_tunnel_setting);
215 	enum dp_link_encoding (*mst_decide_link_encoding_format)(
216 			const struct dc_link *link);
217 	bool (*edp_decide_link_settings)(struct dc_link *link,
218 			struct dc_link_settings *link_setting, uint32_t req_bw);
219 	uint32_t (*bw_kbps_from_raw_frl_link_rate_data)(uint8_t bw);
220 	bool (*dp_overwrite_extended_receiver_cap)(struct dc_link *link);
221 	enum lttpr_mode (*dp_decide_lttpr_mode)(struct dc_link *link,
222 			struct dc_link_settings *link_setting);
223 	uint8_t (*dp_get_lttpr_count)(struct dc_link *link);
224 	void (*edp_get_alpm_support)(struct dc_link *link,
225 		bool *auxless_support,
226 		bool *auxwake_support);
227 
228 	/*************************** DP DPIA/PHY ******************************/
229 	void (*dpia_handle_usb4_bandwidth_allocation_for_link)(
230 			struct dc_link *link, int peak_bw);
231 	void (*dp_set_drive_settings)(
232 		struct dc_link *link,
233 		const struct link_resource *link_res,
234 		struct link_training_settings *lt_settings);
235 	void (*dpcd_write_rx_power_ctrl)(struct dc_link *link, bool on);
236 
237 
238 	/*************************** DP IRQ Handler ***************************/
239 	bool (*dp_parse_link_loss_status)(
240 		struct dc_link *link,
241 		union hpd_irq_data *hpd_irq_dpcd_data);
242 	bool (*dp_should_allow_hpd_rx_irq)(const struct dc_link *link);
243 	void (*dp_handle_link_loss)(struct dc_link *link);
244 	enum dc_status (*dp_read_hpd_rx_irq_data)(
245 		struct dc_link *link,
246 		union hpd_irq_data *irq_data);
247 	bool (*dp_handle_hpd_rx_irq)(struct dc_link *link,
248 			union hpd_irq_data *out_hpd_irq_dpcd_data,
249 			bool *out_link_loss,
250 			bool defer_handling, bool *has_left_work);
251 
252 
253 	/*************************** eDP Panel Control ************************/
254 	void (*edp_panel_backlight_power_on)(
255 			struct dc_link *link, bool wait_for_hpd);
256 	int (*edp_get_backlight_level)(const struct dc_link *link);
257 	bool (*edp_get_backlight_level_nits)(struct dc_link *link,
258 			uint32_t *backlight_millinits_avg,
259 			uint32_t *backlight_millinits_peak);
260 	bool (*edp_set_backlight_level)(const struct dc_link *link,
261 			struct set_backlight_level_params *backlight_level_params);
262 	bool (*edp_set_backlight_level_nits)(struct dc_link *link,
263 			bool isHDR,
264 			uint32_t backlight_millinits,
265 			uint32_t transition_time_in_ms);
266 	int (*edp_get_target_backlight_pwm)(const struct dc_link *link);
267 	bool (*edp_get_psr_state)(
268 			const struct dc_link *link, enum dc_psr_state *state);
269 	bool (*edp_set_psr_allow_active)(
270 			struct dc_link *link,
271 			const bool *allow_active,
272 			bool wait,
273 			bool force_static,
274 			const unsigned int *power_opts);
275 	bool (*edp_setup_psr)(struct dc_link *link,
276 			const struct dc_stream_state *stream,
277 			struct psr_config *psr_config,
278 			struct psr_context *psr_context);
279 	bool (*edp_set_sink_vtotal_in_psr_active)(
280 			const struct dc_link *link,
281 			uint16_t psr_vtotal_idle,
282 			uint16_t psr_vtotal_su);
283 	void (*edp_get_psr_residency)(
284 			const struct dc_link *link, uint32_t *residency, enum psr_residency_mode mode);
285 
286 	bool (*edp_get_replay_state)(
287 			const struct dc_link *link, uint64_t *state);
288 	bool (*edp_set_replay_allow_active)(struct dc_link *dc_link,
289 			const bool *enable, bool wait, bool force_static,
290 			const unsigned int *power_opts);
291 	bool (*edp_send_replay_cmd)(struct dc_link *link,
292 			enum replay_FW_Message_type msg,
293 			union dmub_replay_cmd_set *cmd_data);
294 	bool (*edp_set_coasting_vtotal)(
295 			struct dc_link *link, uint32_t coasting_vtotal, uint16_t frame_skip_number);
296 	bool (*edp_replay_residency)(const struct dc_link *link,
297 			unsigned int *residency, const bool is_start,
298 			const enum pr_residency_mode mode);
299 	bool (*edp_set_replay_power_opt_and_coasting_vtotal)(struct dc_link *link,
300 			const unsigned int *power_opts, uint32_t coasting_vtotal, uint16_t frame_skip_number);
301 
302 	bool (*edp_wait_for_t12)(struct dc_link *link);
303 	bool (*edp_is_ilr_optimization_required)(struct dc_link *link,
304 			struct dc_crtc_timing *crtc_timing);
305 	bool (*edp_backlight_enable_aux)(struct dc_link *link, bool enable);
306 	void (*edp_add_delay_for_T9)(struct dc_link *link);
307 	bool (*edp_receiver_ready_T9)(struct dc_link *link);
308 	bool (*edp_receiver_ready_T7)(struct dc_link *link);
309 	bool (*edp_power_alpm_dpcd_enable)(struct dc_link *link, bool enable);
310 	bool (*dp_setup_replay)(struct dc_link *link, const struct dc_stream_state *stream);
311 	bool (*dp_pr_get_panel_inst)(const struct dc *dc, const struct dc_link *link, unsigned int *inst_out);
312 	bool (*dp_pr_enable)(struct dc_link *link, bool enable);
313 	bool (*dp_pr_update_state)(struct dc_link *link, struct dmub_cmd_pr_update_state_data *update_state_data);
314 	bool (*dp_pr_set_general_cmd)(struct dc_link *link, struct dmub_cmd_pr_general_cmd_data *general_cmd_data);
315 	bool (*dp_pr_get_state)(const struct dc_link *link, uint64_t *state);
316 	void (*edp_set_panel_power)(struct dc_link *link, bool powerOn);
317 
318 
319 	/*************************** HDMI FRL *********************************/
320 	bool (*hdmi_frl_poll_status_flag)(struct dc_link *link);
321 	struct dc_hdmi_frl_link_settings *(*hdmi_frl_get_verified_link_cap)(
322 			struct dc_link *link);
323 	void (*hdmi_frl_set_preferred_link_settings)(struct dc *dc,
324 			struct dc_hdmi_frl_link_settings *link_setting,
325 			struct dc_hdmi_frl_link_training_overrides *lt_overrides,
326 			struct dc_link *link);
327 
328 
329 	/*************************** DP CTS ************************************/
330 	void (*dp_handle_automated_test)(struct dc_link *link);
331 	bool (*dp_set_test_pattern)(
332 			struct dc_link *link,
333 			enum dp_test_pattern test_pattern,
334 			enum dp_test_pattern_color_space test_pattern_color_space,
335 			const struct link_training_settings *p_link_settings,
336 			const unsigned char *p_custom_pattern,
337 			unsigned int cust_pattern_size);
338 	void (*dp_set_preferred_link_settings)(struct dc *dc,
339 			struct dc_link_settings *link_setting,
340 			struct dc_link *link);
341 	void (*dp_set_preferred_training_settings)(struct dc *dc,
342 			struct dc_link_settings *link_setting,
343 			struct dc_link_training_overrides *lt_overrides,
344 			struct dc_link *link,
345 			bool skip_immediate_retrain);
346 
347 
348 	/*************************** DP Trace *********************************/
349 	bool (*dp_trace_is_initialized)(struct dc_link *link);
350 	void (*dp_trace_set_is_logged_flag)(struct dc_link *link,
351 			bool in_detection,
352 			bool is_logged);
353 	bool (*dp_trace_is_logged)(struct dc_link *link, bool in_detection);
354 	unsigned long long (*dp_trace_get_lt_end_timestamp)(
355 			struct dc_link *link, bool in_detection);
356 	const struct dp_trace_lt_counts *(*dp_trace_get_lt_counts)(
357 			struct dc_link *link, bool in_detection);
358 	unsigned int (*dp_trace_get_link_loss_count)(struct dc_link *link);
359 	void (*dp_trace_set_edp_power_timestamp)(struct dc_link *link,
360 			bool power_up);
361 	uint64_t (*dp_trace_get_edp_poweron_timestamp)(struct dc_link *link);
362 	uint64_t (*dp_trace_get_edp_poweroff_timestamp)(struct dc_link *link);
363 	void (*dp_trace_source_sequence)(
364 			struct dc_link *link, uint8_t dp_test_mode);
365 };
366 #endif /* __DC_LINK_HPD_H__ */
367