xref: /linux/drivers/gpu/drm/amd/display/dc/dc.h (revision c6618fa8b926fadf356612f5242057c2d761b1ab)
1 /*
2  * Copyright 2012-2023 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_INTERFACE_H_
27 #define DC_INTERFACE_H_
28 
29 #include "dc_types.h"
30 #include "dc_state.h"
31 #include "dc_plane.h"
32 #include "grph_object_defs.h"
33 #include "logger_types.h"
34 #include "hdcp_msg_types.h"
35 #include "gpio_types.h"
36 #include "link_service_types.h"
37 #include "grph_object_ctrl_defs.h"
38 #include <inc/hw/opp.h>
39 
40 #include "hwss/hw_sequencer.h"
41 #include "inc/compressor.h"
42 #include "inc/hw/dmcu.h"
43 #include "dml/display_mode_lib.h"
44 
45 #include "dml2/dml2_wrapper.h"
46 
47 #include "dmub/inc/dmub_cmd.h"
48 
49 #include "sspl/dc_spl_types.h"
50 
51 struct abm_save_restore;
52 
53 /* forward declaration */
54 struct aux_payload;
55 struct set_config_cmd_payload;
56 struct dmub_notification;
57 
58 #define DC_VER "3.2.336"
59 
60 /**
61  * MAX_SURFACES - representative of the upper bound of surfaces that can be piped to a single CRTC
62  */
63 #define MAX_SURFACES 4
64 /**
65  * MAX_PLANES - representative of the upper bound of planes that are supported by the HW
66  */
67 #define MAX_PLANES 6
68 #define MAX_STREAMS 6
69 #define MIN_VIEWPORT_SIZE 12
70 #define MAX_NUM_EDP 2
71 #define MAX_HOST_ROUTERS_NUM 3
72 #define MAX_DPIA_PER_HOST_ROUTER 2
73 #define MAX_SUPPORTED_FORMATS 7
74 
75 /* Display Core Interfaces */
76 struct dc_versions {
77 	const char *dc_ver;
78 	struct dmcu_version dmcu_version;
79 };
80 
81 enum dp_protocol_version {
82 	DP_VERSION_1_4 = 0,
83 	DP_VERSION_2_1,
84 	DP_VERSION_UNKNOWN,
85 };
86 
87 enum dc_plane_type {
88 	DC_PLANE_TYPE_INVALID,
89 	DC_PLANE_TYPE_DCE_RGB,
90 	DC_PLANE_TYPE_DCE_UNDERLAY,
91 	DC_PLANE_TYPE_DCN_UNIVERSAL,
92 };
93 
94 // Sizes defined as multiples of 64KB
95 enum det_size {
96 	DET_SIZE_DEFAULT = 0,
97 	DET_SIZE_192KB = 3,
98 	DET_SIZE_256KB = 4,
99 	DET_SIZE_320KB = 5,
100 	DET_SIZE_384KB = 6
101 };
102 
103 
104 struct dc_plane_cap {
105 	enum dc_plane_type type;
106 	uint32_t per_pixel_alpha : 1;
107 	struct {
108 		uint32_t argb8888 : 1;
109 		uint32_t nv12 : 1;
110 		uint32_t fp16 : 1;
111 		uint32_t p010 : 1;
112 		uint32_t ayuv : 1;
113 	} pixel_format_support;
114 	// max upscaling factor x1000
115 	// upscaling factors are always >= 1
116 	// for example, 1080p -> 8K is 4.0, or 4000 raw value
117 	struct {
118 		uint32_t argb8888;
119 		uint32_t nv12;
120 		uint32_t fp16;
121 	} max_upscale_factor;
122 	// max downscale factor x1000
123 	// downscale factors are always <= 1
124 	// for example, 8K -> 1080p is 0.25, or 250 raw value
125 	struct {
126 		uint32_t argb8888;
127 		uint32_t nv12;
128 		uint32_t fp16;
129 	} max_downscale_factor;
130 	// minimal width/height
131 	uint32_t min_width;
132 	uint32_t min_height;
133 };
134 
135 /**
136  * DOC: color-management-caps
137  *
138  * **Color management caps (DPP and MPC)**
139  *
140  * Modules/color calculates various color operations which are translated to
141  * abstracted HW. DCE 5-12 had almost no important changes, but starting with
142  * DCN1, every new generation comes with fairly major differences in color
143  * pipeline. Therefore, we abstract color pipe capabilities so modules/DM can
144  * decide mapping to HW block based on logical capabilities.
145  */
146 
147 /**
148  * struct rom_curve_caps - predefined transfer function caps for degamma and regamma
149  * @srgb: RGB color space transfer func
150  * @bt2020: BT.2020 transfer func
151  * @gamma2_2: standard gamma
152  * @pq: perceptual quantizer transfer function
153  * @hlg: hybrid log–gamma transfer function
154  */
155 struct rom_curve_caps {
156 	uint16_t srgb : 1;
157 	uint16_t bt2020 : 1;
158 	uint16_t gamma2_2 : 1;
159 	uint16_t pq : 1;
160 	uint16_t hlg : 1;
161 };
162 
163 /**
164  * struct dpp_color_caps - color pipeline capabilities for display pipe and
165  * plane blocks
166  *
167  * @dcn_arch: all DCE generations treated the same
168  * @input_lut_shared: shared with DGAM. Input LUT is different than most LUTs,
169  * just plain 256-entry lookup
170  * @icsc: input color space conversion
171  * @dgam_ram: programmable degamma LUT
172  * @post_csc: post color space conversion, before gamut remap
173  * @gamma_corr: degamma correction
174  * @hw_3d_lut: 3D LUT support. It implies a shaper LUT before. It may be shared
175  * with MPC by setting mpc:shared_3d_lut flag
176  * @ogam_ram: programmable out/blend gamma LUT
177  * @ocsc: output color space conversion
178  * @dgam_rom_for_yuv: pre-defined degamma LUT for YUV planes
179  * @dgam_rom_caps: pre-definied curve caps for degamma 1D LUT
180  * @ogam_rom_caps: pre-definied curve caps for regamma 1D LUT
181  *
182  * Note: hdr_mult and gamut remap (CTM) are always available in DPP (in that order)
183  */
184 struct dpp_color_caps {
185 	uint16_t dcn_arch : 1;
186 	uint16_t input_lut_shared : 1;
187 	uint16_t icsc : 1;
188 	uint16_t dgam_ram : 1;
189 	uint16_t post_csc : 1;
190 	uint16_t gamma_corr : 1;
191 	uint16_t hw_3d_lut : 1;
192 	uint16_t ogam_ram : 1;
193 	uint16_t ocsc : 1;
194 	uint16_t dgam_rom_for_yuv : 1;
195 	struct rom_curve_caps dgam_rom_caps;
196 	struct rom_curve_caps ogam_rom_caps;
197 };
198 
199 /* Below structure is to describe the HW support for mem layout, extend support
200 	range to match what OS could handle in the roadmap */
201 struct lut3d_caps {
202 	uint32_t dma_3d_lut : 1; /*< DMA mode support for 3D LUT */
203 	struct {
204 		uint32_t swizzle_3d_rgb : 1;
205 		uint32_t swizzle_3d_bgr : 1;
206 		uint32_t linear_1d : 1;
207 	} mem_layout_support;
208 	struct {
209 		uint32_t unorm_12msb : 1;
210 		uint32_t unorm_12lsb : 1;
211 		uint32_t float_fp1_5_10 : 1;
212 	} mem_format_support;
213 	struct {
214 		uint32_t order_rgba : 1;
215 		uint32_t order_bgra : 1;
216 	} mem_pixel_order_support;
217 	/*< size options are 9, 17, 33, 45, 65 */
218 	struct {
219 		uint32_t dim_9 : 1; /* 3D LUT support for 9x9x9 */
220 		uint32_t dim_17 : 1; /* 3D LUT support for 17x17x17 */
221 		uint32_t dim_33 : 1; /* 3D LUT support for 33x33x33 */
222 		uint32_t dim_45 : 1; /* 3D LUT support for 45x45x45 */
223 		uint32_t dim_65 : 1; /* 3D LUT support for 65x65x65 */
224 	} lut_dim_caps;
225 };
226 
227 /**
228  * struct mpc_color_caps - color pipeline capabilities for multiple pipe and
229  * plane combined blocks
230  *
231  * @gamut_remap: color transformation matrix
232  * @ogam_ram: programmable out gamma LUT
233  * @ocsc: output color space conversion matrix
234  * @num_3dluts: MPC 3D LUT; always assumes a preceding shaper LUT
235  * @shared_3d_lut: shared 3D LUT flag. Can be either DPP or MPC, but single
236  * instance
237  * @ogam_rom_caps: pre-definied curve caps for regamma 1D LUT
238  */
239 struct mpc_color_caps {
240 	uint16_t gamut_remap : 1;
241 	uint16_t ogam_ram : 1;
242 	uint16_t ocsc : 1;
243 	uint16_t num_3dluts : 3;
244 	uint16_t shared_3d_lut:1;
245 	struct rom_curve_caps ogam_rom_caps;
246 	struct lut3d_caps mcm_3d_lut_caps;
247 	struct lut3d_caps rmcm_3d_lut_caps;
248 };
249 
250 /**
251  * struct dc_color_caps - color pipes capabilities for DPP and MPC hw blocks
252  * @dpp: color pipes caps for DPP
253  * @mpc: color pipes caps for MPC
254  */
255 struct dc_color_caps {
256 	struct dpp_color_caps dpp;
257 	struct mpc_color_caps mpc;
258 };
259 
260 struct dc_dmub_caps {
261 	bool psr;
262 	bool mclk_sw;
263 	bool subvp_psr;
264 	bool gecc_enable;
265 	uint8_t fams_ver;
266 	bool aux_backlight_support;
267 };
268 
269 struct dc_scl_caps {
270 	bool sharpener_support;
271 };
272 
273 struct dc_caps {
274 	uint32_t max_streams;
275 	uint32_t max_links;
276 	uint32_t max_audios;
277 	uint32_t max_slave_planes;
278 	uint32_t max_slave_yuv_planes;
279 	uint32_t max_slave_rgb_planes;
280 	uint32_t max_planes;
281 	uint32_t max_downscale_ratio;
282 	uint32_t i2c_speed_in_khz;
283 	uint32_t i2c_speed_in_khz_hdcp;
284 	uint32_t dmdata_alloc_size;
285 	unsigned int max_cursor_size;
286 	unsigned int max_buffered_cursor_size;
287 	unsigned int max_video_width;
288 	/*
289 	 * max video plane width that can be safely assumed to be always
290 	 * supported by single DPP pipe.
291 	 */
292 	unsigned int max_optimizable_video_width;
293 	unsigned int min_horizontal_blanking_period;
294 	int linear_pitch_alignment;
295 	bool dcc_const_color;
296 	bool dynamic_audio;
297 	bool is_apu;
298 	bool dual_link_dvi;
299 	bool post_blend_color_processing;
300 	bool force_dp_tps4_for_cp2520;
301 	bool disable_dp_clk_share;
302 	bool psp_setup_panel_mode;
303 	bool extended_aux_timeout_support;
304 	bool dmcub_support;
305 	bool zstate_support;
306 	bool ips_support;
307 	uint32_t num_of_internal_disp;
308 	enum dp_protocol_version max_dp_protocol_version;
309 	unsigned int mall_size_per_mem_channel;
310 	unsigned int mall_size_total;
311 	unsigned int cursor_cache_size;
312 	struct dc_plane_cap planes[MAX_PLANES];
313 	struct dc_color_caps color;
314 	struct dc_dmub_caps dmub_caps;
315 	bool dp_hpo;
316 	bool dp_hdmi21_pcon_support;
317 	bool edp_dsc_support;
318 	bool vbios_lttpr_aware;
319 	bool vbios_lttpr_enable;
320 	bool fused_io_supported;
321 	uint32_t max_otg_num;
322 	uint32_t max_cab_allocation_bytes;
323 	uint32_t cache_line_size;
324 	uint32_t cache_num_ways;
325 	uint16_t subvp_fw_processing_delay_us;
326 	uint8_t subvp_drr_max_vblank_margin_us;
327 	uint16_t subvp_prefetch_end_to_mall_start_us;
328 	uint8_t subvp_swath_height_margin_lines; // subvp start line must be aligned to 2 x swath height
329 	uint16_t subvp_pstate_allow_width_us;
330 	uint16_t subvp_vertical_int_margin_us;
331 	bool seamless_odm;
332 	uint32_t max_v_total;
333 	bool vtotal_limited_by_fp2;
334 	uint32_t max_disp_clock_khz_at_vmin;
335 	uint8_t subvp_drr_vblank_start_margin_us;
336 	bool cursor_not_scaled;
337 	bool dcmode_power_limits_present;
338 	bool sequential_ono;
339 	/* Conservative limit for DCC cases which require ODM4:1 to support*/
340 	uint32_t dcc_plane_width_limit;
341 	struct dc_scl_caps scl_caps;
342 	uint8_t num_of_host_routers;
343 	uint8_t num_of_dpias_per_host_router;
344 };
345 
346 struct dc_bug_wa {
347 	bool no_connect_phy_config;
348 	bool dedcn20_305_wa;
349 	bool skip_clock_update;
350 	bool lt_early_cr_pattern;
351 	struct {
352 		uint8_t uclk : 1;
353 		uint8_t fclk : 1;
354 		uint8_t dcfclk : 1;
355 		uint8_t dcfclk_ds: 1;
356 	} clock_update_disable_mask;
357 	bool skip_psr_ips_crtc_disable;
358 };
359 struct dc_dcc_surface_param {
360 	struct dc_size surface_size;
361 	enum surface_pixel_format format;
362 	unsigned int plane0_pitch;
363 	struct dc_size plane1_size;
364 	unsigned int plane1_pitch;
365 	union {
366 		enum swizzle_mode_values swizzle_mode;
367 		enum swizzle_mode_addr3_values swizzle_mode_addr3;
368 	};
369 	enum dc_scan_direction scan;
370 };
371 
372 struct dc_dcc_setting {
373 	unsigned int max_compressed_blk_size;
374 	unsigned int max_uncompressed_blk_size;
375 	bool independent_64b_blks;
376 	//These bitfields to be used starting with DCN 3.0
377 	struct {
378 		uint32_t dcc_256_64_64 : 1;//available in ASICs before DCN 3.0 (the worst compression case)
379 		uint32_t dcc_128_128_uncontrained : 1;  //available in ASICs before DCN 3.0
380 		uint32_t dcc_256_128_128 : 1;		//available starting with DCN 3.0
381 		uint32_t dcc_256_256_unconstrained : 1;  //available in ASICs before DCN 3.0 (the best compression case)
382 		uint32_t dcc_256_256 : 1;  //available in ASICs starting with DCN 4.0x (the best compression case)
383 		uint32_t dcc_256_128 : 1;  //available in ASICs starting with DCN 4.0x
384 		uint32_t dcc_256_64 : 1;   //available in ASICs starting with DCN 4.0x (the worst compression case)
385 	} dcc_controls;
386 };
387 
388 struct dc_surface_dcc_cap {
389 	union {
390 		struct {
391 			struct dc_dcc_setting rgb;
392 		} grph;
393 
394 		struct {
395 			struct dc_dcc_setting luma;
396 			struct dc_dcc_setting chroma;
397 		} video;
398 	};
399 
400 	bool capable;
401 	bool const_color_support;
402 };
403 
404 struct dc_static_screen_params {
405 	struct {
406 		bool force_trigger;
407 		bool cursor_update;
408 		bool surface_update;
409 		bool overlay_update;
410 	} triggers;
411 	unsigned int num_frames;
412 };
413 
414 
415 /* Surface update type is used by dc_update_surfaces_and_stream
416  * The update type is determined at the very beginning of the function based
417  * on parameters passed in and decides how much programming (or updating) is
418  * going to be done during the call.
419  *
420  * UPDATE_TYPE_FAST is used for really fast updates that do not require much
421  * logical calculations or hardware register programming. This update MUST be
422  * ISR safe on windows. Currently fast update will only be used to flip surface
423  * address.
424  *
425  * UPDATE_TYPE_MED is used for slower updates which require significant hw
426  * re-programming however do not affect bandwidth consumption or clock
427  * requirements. At present, this is the level at which front end updates
428  * that do not require us to run bw_calcs happen. These are in/out transfer func
429  * updates, viewport offset changes, recout size changes and pixel depth changes.
430  * This update can be done at ISR, but we want to minimize how often this happens.
431  *
432  * UPDATE_TYPE_FULL is slow. Really slow. This requires us to recalculate our
433  * bandwidth and clocks, possibly rearrange some pipes and reprogram anything front
434  * end related. Any time viewport dimensions, recout dimensions, scaling ratios or
435  * gamma need to be adjusted or pipe needs to be turned on (or disconnected) we do
436  * a full update. This cannot be done at ISR level and should be a rare event.
437  * Unless someone is stress testing mpo enter/exit, playing with colour or adjusting
438  * underscan we don't expect to see this call at all.
439  */
440 
441 enum surface_update_type {
442 	UPDATE_TYPE_FAST, /* super fast, safe to execute in isr */
443 	UPDATE_TYPE_MED,  /* ISR safe, most of programming needed, no bw/clk change*/
444 	UPDATE_TYPE_FULL, /* may need to shuffle resources */
445 };
446 
447 /* Forward declaration*/
448 struct dc;
449 struct dc_plane_state;
450 struct dc_state;
451 
452 struct dc_cap_funcs {
453 	bool (*get_dcc_compression_cap)(const struct dc *dc,
454 			const struct dc_dcc_surface_param *input,
455 			struct dc_surface_dcc_cap *output);
456 	bool (*get_subvp_en)(struct dc *dc, struct dc_state *context);
457 };
458 
459 struct link_training_settings;
460 
461 union allow_lttpr_non_transparent_mode {
462 	struct {
463 		bool DP1_4A : 1;
464 		bool DP2_0 : 1;
465 	} bits;
466 	unsigned char raw;
467 };
468 
469 /* Structure to hold configuration flags set by dm at dc creation. */
470 struct dc_config {
471 	bool gpu_vm_support;
472 	bool disable_disp_pll_sharing;
473 	bool fbc_support;
474 	bool disable_fractional_pwm;
475 	bool allow_seamless_boot_optimization;
476 	bool seamless_boot_edp_requested;
477 	bool edp_not_connected;
478 	bool edp_no_power_sequencing;
479 	bool force_enum_edp;
480 	bool forced_clocks;
481 	union allow_lttpr_non_transparent_mode allow_lttpr_non_transparent_mode;
482 	bool multi_mon_pp_mclk_switch;
483 	bool disable_dmcu;
484 	bool enable_4to1MPC;
485 	bool enable_windowed_mpo_odm;
486 	bool forceHBR2CP2520; // Used for switching between test patterns TPS4 and CP2520
487 	uint32_t allow_edp_hotplug_detection;
488 	bool skip_riommu_prefetch_wa;
489 	bool clamp_min_dcfclk;
490 	uint64_t vblank_alignment_dto_params;
491 	uint8_t  vblank_alignment_max_frame_time_diff;
492 	bool is_asymmetric_memory;
493 	bool is_single_rank_dimm;
494 	bool is_vmin_only_asic;
495 	bool use_spl;
496 	bool prefer_easf;
497 	bool use_pipe_ctx_sync_logic;
498 	bool ignore_dpref_ss;
499 	bool enable_mipi_converter_optimization;
500 	bool use_default_clock_table;
501 	bool force_bios_enable_lttpr;
502 	uint8_t force_bios_fixed_vs;
503 	int sdpif_request_limit_words_per_umc;
504 	bool dc_mode_clk_limit_support;
505 	bool EnableMinDispClkODM;
506 	bool enable_auto_dpm_test_logs;
507 	unsigned int disable_ips;
508 	unsigned int disable_ips_in_vpb;
509 	bool disable_ips_in_dpms_off;
510 	bool usb4_bw_alloc_support;
511 	bool allow_0_dtb_clk;
512 	bool use_assr_psp_message;
513 	bool support_edp0_on_dp1;
514 	unsigned int enable_fpo_flicker_detection;
515 	bool disable_hbr_audio_dp2;
516 	bool consolidated_dpia_dp_lt;
517 	bool set_pipe_unlock_order;
518 	bool enable_dpia_pre_training;
519 	bool unify_link_enc_assignment;
520 	struct spl_sharpness_range dcn_sharpness_range;
521 	struct spl_sharpness_range dcn_override_sharpness_range;
522 };
523 
524 enum visual_confirm {
525 	VISUAL_CONFIRM_DISABLE = 0,
526 	VISUAL_CONFIRM_SURFACE = 1,
527 	VISUAL_CONFIRM_HDR = 2,
528 	VISUAL_CONFIRM_MPCTREE = 4,
529 	VISUAL_CONFIRM_PSR = 5,
530 	VISUAL_CONFIRM_SWAPCHAIN = 6,
531 	VISUAL_CONFIRM_FAMS = 7,
532 	VISUAL_CONFIRM_SWIZZLE = 9,
533 	VISUAL_CONFIRM_REPLAY = 12,
534 	VISUAL_CONFIRM_SUBVP = 14,
535 	VISUAL_CONFIRM_MCLK_SWITCH = 16,
536 	VISUAL_CONFIRM_FAMS2 = 19,
537 	VISUAL_CONFIRM_HW_CURSOR = 20,
538 	VISUAL_CONFIRM_VABC = 21,
539 	VISUAL_CONFIRM_DCC = 22,
540 	VISUAL_CONFIRM_EXPLICIT = 0x80000000,
541 };
542 
543 enum dc_psr_power_opts {
544 	psr_power_opt_invalid = 0x0,
545 	psr_power_opt_smu_opt_static_screen = 0x1,
546 	psr_power_opt_z10_static_screen = 0x10,
547 	psr_power_opt_ds_disable_allow = 0x100,
548 };
549 
550 enum dml_hostvm_override_opts {
551 	DML_HOSTVM_NO_OVERRIDE = 0x0,
552 	DML_HOSTVM_OVERRIDE_FALSE = 0x1,
553 	DML_HOSTVM_OVERRIDE_TRUE = 0x2,
554 };
555 
556 enum dc_replay_power_opts {
557 	replay_power_opt_invalid		= 0x0,
558 	replay_power_opt_smu_opt_static_screen	= 0x1,
559 	replay_power_opt_z10_static_screen	= 0x10,
560 };
561 
562 enum dcc_option {
563 	DCC_ENABLE = 0,
564 	DCC_DISABLE = 1,
565 	DCC_HALF_REQ_DISALBE = 2,
566 };
567 
568 enum in_game_fams_config {
569 	INGAME_FAMS_SINGLE_DISP_ENABLE, // enable in-game fams
570 	INGAME_FAMS_DISABLE, // disable in-game fams
571 	INGAME_FAMS_MULTI_DISP_ENABLE, //enable in-game fams for multi-display
572 	INGAME_FAMS_MULTI_DISP_CLAMPED_ONLY, //enable in-game fams for multi-display only for clamped RR strategies
573 };
574 
575 /**
576  * enum pipe_split_policy - Pipe split strategy supported by DCN
577  *
578  * This enum is used to define the pipe split policy supported by DCN. By
579  * default, DC favors MPC_SPLIT_DYNAMIC.
580  */
581 enum pipe_split_policy {
582 	/**
583 	 * @MPC_SPLIT_DYNAMIC: DC will automatically decide how to split the
584 	 * pipe in order to bring the best trade-off between performance and
585 	 * power consumption. This is the recommended option.
586 	 */
587 	MPC_SPLIT_DYNAMIC = 0,
588 
589 	/**
590 	 * @MPC_SPLIT_AVOID: Avoid pipe split, which means that DC will not
591 	 * try any sort of split optimization.
592 	 */
593 	MPC_SPLIT_AVOID = 1,
594 
595 	/**
596 	 * @MPC_SPLIT_AVOID_MULT_DISP: With this option, DC will only try to
597 	 * optimize the pipe utilization when using a single display; if the
598 	 * user connects to a second display, DC will avoid pipe split.
599 	 */
600 	MPC_SPLIT_AVOID_MULT_DISP = 2,
601 };
602 
603 enum wm_report_mode {
604 	WM_REPORT_DEFAULT = 0,
605 	WM_REPORT_OVERRIDE = 1,
606 };
607 enum dtm_pstate{
608 	dtm_level_p0 = 0,/*highest voltage*/
609 	dtm_level_p1,
610 	dtm_level_p2,
611 	dtm_level_p3,
612 	dtm_level_p4,/*when active_display_count = 0*/
613 };
614 
615 enum dcn_pwr_state {
616 	DCN_PWR_STATE_UNKNOWN = -1,
617 	DCN_PWR_STATE_MISSION_MODE = 0,
618 	DCN_PWR_STATE_LOW_POWER = 3,
619 };
620 
621 enum dcn_zstate_support_state {
622 	DCN_ZSTATE_SUPPORT_UNKNOWN,
623 	DCN_ZSTATE_SUPPORT_ALLOW,
624 	DCN_ZSTATE_SUPPORT_ALLOW_Z8_ONLY,
625 	DCN_ZSTATE_SUPPORT_ALLOW_Z8_Z10_ONLY,
626 	DCN_ZSTATE_SUPPORT_ALLOW_Z10_ONLY,
627 	DCN_ZSTATE_SUPPORT_DISALLOW,
628 };
629 
630 /*
631  * struct dc_clocks - DC pipe clocks
632  *
633  * For any clocks that may differ per pipe only the max is stored in this
634  * structure
635  */
636 struct dc_clocks {
637 	int dispclk_khz;
638 	int actual_dispclk_khz;
639 	int dppclk_khz;
640 	int actual_dppclk_khz;
641 	int disp_dpp_voltage_level_khz;
642 	int dcfclk_khz;
643 	int socclk_khz;
644 	int dcfclk_deep_sleep_khz;
645 	int fclk_khz;
646 	int phyclk_khz;
647 	int dramclk_khz;
648 	bool p_state_change_support;
649 	enum dcn_zstate_support_state zstate_support;
650 	bool dtbclk_en;
651 	int ref_dtbclk_khz;
652 	bool fclk_p_state_change_support;
653 	enum dcn_pwr_state pwr_state;
654 	/*
655 	 * Elements below are not compared for the purposes of
656 	 * optimization required
657 	 */
658 	bool prev_p_state_change_support;
659 	bool fclk_prev_p_state_change_support;
660 	int num_ways;
661 	int host_router_bw_kbps[MAX_HOST_ROUTERS_NUM];
662 
663 	/*
664 	 * @fw_based_mclk_switching
665 	 *
666 	 * DC has a mechanism that leverage the variable refresh rate to switch
667 	 * memory clock in cases that we have a large latency to achieve the
668 	 * memory clock change and a short vblank window. DC has some
669 	 * requirements to enable this feature, and this field describes if the
670 	 * system support or not such a feature.
671 	 */
672 	bool fw_based_mclk_switching;
673 	bool fw_based_mclk_switching_shut_down;
674 	int prev_num_ways;
675 	enum dtm_pstate dtm_level;
676 	int max_supported_dppclk_khz;
677 	int max_supported_dispclk_khz;
678 	int bw_dppclk_khz; /*a copy of dppclk_khz*/
679 	int bw_dispclk_khz;
680 	int idle_dramclk_khz;
681 	int idle_fclk_khz;
682 	int subvp_prefetch_dramclk_khz;
683 	int subvp_prefetch_fclk_khz;
684 };
685 
686 struct dc_bw_validation_profile {
687 	bool enable;
688 
689 	unsigned long long total_ticks;
690 	unsigned long long voltage_level_ticks;
691 	unsigned long long watermark_ticks;
692 	unsigned long long rq_dlg_ticks;
693 
694 	unsigned long long total_count;
695 	unsigned long long skip_fast_count;
696 	unsigned long long skip_pass_count;
697 	unsigned long long skip_fail_count;
698 };
699 
700 #define BW_VAL_TRACE_SETUP() \
701 		unsigned long long end_tick = 0; \
702 		unsigned long long voltage_level_tick = 0; \
703 		unsigned long long watermark_tick = 0; \
704 		unsigned long long start_tick = dc->debug.bw_val_profile.enable ? \
705 				dm_get_timestamp(dc->ctx) : 0
706 
707 #define BW_VAL_TRACE_COUNT() \
708 		if (dc->debug.bw_val_profile.enable) \
709 			dc->debug.bw_val_profile.total_count++
710 
711 #define BW_VAL_TRACE_SKIP(status) \
712 		if (dc->debug.bw_val_profile.enable) { \
713 			if (!voltage_level_tick) \
714 				voltage_level_tick = dm_get_timestamp(dc->ctx); \
715 			dc->debug.bw_val_profile.skip_ ## status ## _count++; \
716 		}
717 
718 #define BW_VAL_TRACE_END_VOLTAGE_LEVEL() \
719 		if (dc->debug.bw_val_profile.enable) \
720 			voltage_level_tick = dm_get_timestamp(dc->ctx)
721 
722 #define BW_VAL_TRACE_END_WATERMARKS() \
723 		if (dc->debug.bw_val_profile.enable) \
724 			watermark_tick = dm_get_timestamp(dc->ctx)
725 
726 #define BW_VAL_TRACE_FINISH() \
727 		if (dc->debug.bw_val_profile.enable) { \
728 			end_tick = dm_get_timestamp(dc->ctx); \
729 			dc->debug.bw_val_profile.total_ticks += end_tick - start_tick; \
730 			dc->debug.bw_val_profile.voltage_level_ticks += voltage_level_tick - start_tick; \
731 			if (watermark_tick) { \
732 				dc->debug.bw_val_profile.watermark_ticks += watermark_tick - voltage_level_tick; \
733 				dc->debug.bw_val_profile.rq_dlg_ticks += end_tick - watermark_tick; \
734 			} \
735 		}
736 
737 union mem_low_power_enable_options {
738 	struct {
739 		bool vga: 1;
740 		bool i2c: 1;
741 		bool dmcu: 1;
742 		bool dscl: 1;
743 		bool cm: 1;
744 		bool mpc: 1;
745 		bool optc: 1;
746 		bool vpg: 1;
747 		bool afmt: 1;
748 	} bits;
749 	uint32_t u32All;
750 };
751 
752 union root_clock_optimization_options {
753 	struct {
754 		bool dpp: 1;
755 		bool dsc: 1;
756 		bool hdmistream: 1;
757 		bool hdmichar: 1;
758 		bool dpstream: 1;
759 		bool symclk32_se: 1;
760 		bool symclk32_le: 1;
761 		bool symclk_fe: 1;
762 		bool physymclk: 1;
763 		bool dpiasymclk: 1;
764 		uint32_t reserved: 22;
765 	} bits;
766 	uint32_t u32All;
767 };
768 
769 union fine_grain_clock_gating_enable_options {
770 	struct {
771 		bool dccg_global_fgcg_rep : 1; /* Global fine grain clock gating of repeaters */
772 		bool dchub : 1;	   /* Display controller hub */
773 		bool dchubbub : 1;
774 		bool dpp : 1;	   /* Display pipes and planes */
775 		bool opp : 1;	   /* Output pixel processing */
776 		bool optc : 1;	   /* Output pipe timing combiner */
777 		bool dio : 1;	   /* Display output */
778 		bool dwb : 1;	   /* Display writeback */
779 		bool mmhubbub : 1; /* Multimedia hub */
780 		bool dmu : 1;	   /* Display core management unit */
781 		bool az : 1;	   /* Azalia */
782 		bool dchvm : 1;
783 		bool dsc : 1;	   /* Display stream compression */
784 
785 		uint32_t reserved : 19;
786 	} bits;
787 	uint32_t u32All;
788 };
789 
790 enum pg_hw_pipe_resources {
791 	PG_HUBP = 0,
792 	PG_DPP,
793 	PG_DSC,
794 	PG_MPCC,
795 	PG_OPP,
796 	PG_OPTC,
797 	PG_DPSTREAM,
798 	PG_HDMISTREAM,
799 	PG_PHYSYMCLK,
800 	PG_HW_PIPE_RESOURCES_NUM_ELEMENT
801 };
802 
803 enum pg_hw_resources {
804 	PG_DCCG = 0,
805 	PG_DCIO,
806 	PG_DIO,
807 	PG_DCHUBBUB,
808 	PG_DCHVM,
809 	PG_DWB,
810 	PG_HPO,
811 	PG_HW_RESOURCES_NUM_ELEMENT
812 };
813 
814 struct pg_block_update {
815 	bool pg_pipe_res_update[PG_HW_PIPE_RESOURCES_NUM_ELEMENT][MAX_PIPES];
816 	bool pg_res_update[PG_HW_RESOURCES_NUM_ELEMENT];
817 };
818 
819 union dpia_debug_options {
820 	struct {
821 		uint32_t disable_dpia:1; /* bit 0 */
822 		uint32_t force_non_lttpr:1; /* bit 1 */
823 		uint32_t extend_aux_rd_interval:1; /* bit 2 */
824 		uint32_t disable_mst_dsc_work_around:1; /* bit 3 */
825 		uint32_t enable_force_tbt3_work_around:1; /* bit 4 */
826 		uint32_t disable_usb4_pm_support:1; /* bit 5 */
827 		uint32_t enable_usb4_bw_zero_alloc_patch:1; /* bit 6 */
828 		uint32_t reserved:25;
829 	} bits;
830 	uint32_t raw;
831 };
832 
833 /* AUX wake work around options
834  * 0: enable/disable work around
835  * 1: use default timeout LINK_AUX_WAKE_TIMEOUT_MS
836  * 15-2: reserved
837  * 31-16: timeout in ms
838  */
839 union aux_wake_wa_options {
840 	struct {
841 		uint32_t enable_wa : 1;
842 		uint32_t use_default_timeout : 1;
843 		uint32_t rsvd: 14;
844 		uint32_t timeout_ms : 16;
845 	} bits;
846 	uint32_t raw;
847 };
848 
849 struct dc_debug_data {
850 	uint32_t ltFailCount;
851 	uint32_t i2cErrorCount;
852 	uint32_t auxErrorCount;
853 };
854 
855 struct dc_phy_addr_space_config {
856 	struct {
857 		uint64_t start_addr;
858 		uint64_t end_addr;
859 		uint64_t fb_top;
860 		uint64_t fb_offset;
861 		uint64_t fb_base;
862 		uint64_t agp_top;
863 		uint64_t agp_bot;
864 		uint64_t agp_base;
865 	} system_aperture;
866 
867 	struct {
868 		uint64_t page_table_start_addr;
869 		uint64_t page_table_end_addr;
870 		uint64_t page_table_base_addr;
871 		bool base_addr_is_mc_addr;
872 	} gart_config;
873 
874 	bool valid;
875 	bool is_hvm_enabled;
876 	uint64_t page_table_default_page_addr;
877 };
878 
879 struct dc_virtual_addr_space_config {
880 	uint64_t	page_table_base_addr;
881 	uint64_t	page_table_start_addr;
882 	uint64_t	page_table_end_addr;
883 	uint32_t	page_table_block_size_in_bytes;
884 	uint8_t		page_table_depth; // 1 = 1 level, 2 = 2 level, etc.  0 = invalid
885 };
886 
887 struct dc_bounding_box_overrides {
888 	int sr_exit_time_ns;
889 	int sr_enter_plus_exit_time_ns;
890 	int sr_exit_z8_time_ns;
891 	int sr_enter_plus_exit_z8_time_ns;
892 	int urgent_latency_ns;
893 	int percent_of_ideal_drambw;
894 	int dram_clock_change_latency_ns;
895 	int dummy_clock_change_latency_ns;
896 	int fclk_clock_change_latency_ns;
897 	/* This forces a hard min on the DCFCLK we use
898 	 * for DML.  Unlike the debug option for forcing
899 	 * DCFCLK, this override affects watermark calculations
900 	 */
901 	int min_dcfclk_mhz;
902 };
903 
904 struct dc_state;
905 struct resource_pool;
906 struct dce_hwseq;
907 struct link_service;
908 
909 /*
910  * struct dc_debug_options - DC debug struct
911  *
912  * This struct provides a simple mechanism for developers to change some
913  * configurations, enable/disable features, and activate extra debug options.
914  * This can be very handy to narrow down whether some specific feature is
915  * causing an issue or not.
916  */
917 struct dc_debug_options {
918 	bool native422_support;
919 	bool disable_dsc;
920 	enum visual_confirm visual_confirm;
921 	int visual_confirm_rect_height;
922 
923 	bool sanity_checks;
924 	bool max_disp_clk;
925 	bool surface_trace;
926 	bool clock_trace;
927 	bool validation_trace;
928 	bool bandwidth_calcs_trace;
929 	int max_downscale_src_width;
930 
931 	/* stutter efficiency related */
932 	bool disable_stutter;
933 	bool use_max_lb;
934 	enum dcc_option disable_dcc;
935 
936 	/*
937 	 * @pipe_split_policy: Define which pipe split policy is used by the
938 	 * display core.
939 	 */
940 	enum pipe_split_policy pipe_split_policy;
941 	bool force_single_disp_pipe_split;
942 	bool voltage_align_fclk;
943 	bool disable_min_fclk;
944 
945 	bool hdcp_lc_force_fw_enable;
946 	bool hdcp_lc_enable_sw_fallback;
947 
948 	bool disable_dfs_bypass;
949 	bool disable_dpp_power_gate;
950 	bool disable_hubp_power_gate;
951 	bool disable_dsc_power_gate;
952 	bool disable_optc_power_gate;
953 	bool disable_hpo_power_gate;
954 	int dsc_min_slice_height_override;
955 	int dsc_bpp_increment_div;
956 	bool disable_pplib_wm_range;
957 	enum wm_report_mode pplib_wm_report_mode;
958 	unsigned int min_disp_clk_khz;
959 	unsigned int min_dpp_clk_khz;
960 	unsigned int min_dram_clk_khz;
961 	int sr_exit_time_dpm0_ns;
962 	int sr_enter_plus_exit_time_dpm0_ns;
963 	int sr_exit_time_ns;
964 	int sr_enter_plus_exit_time_ns;
965 	int sr_exit_z8_time_ns;
966 	int sr_enter_plus_exit_z8_time_ns;
967 	int urgent_latency_ns;
968 	uint32_t underflow_assert_delay_us;
969 	int percent_of_ideal_drambw;
970 	int dram_clock_change_latency_ns;
971 	bool optimized_watermark;
972 	int always_scale;
973 	bool disable_pplib_clock_request;
974 	bool disable_clock_gate;
975 	bool disable_mem_low_power;
976 	bool pstate_enabled;
977 	bool disable_dmcu;
978 	bool force_abm_enable;
979 	bool disable_stereo_support;
980 	bool vsr_support;
981 	bool performance_trace;
982 	bool az_endpoint_mute_only;
983 	bool always_use_regamma;
984 	bool recovery_enabled;
985 	bool avoid_vbios_exec_table;
986 	bool scl_reset_length10;
987 	bool hdmi20_disable;
988 	bool skip_detection_link_training;
989 	uint32_t edid_read_retry_times;
990 	unsigned int force_odm_combine; //bit vector based on otg inst
991 	unsigned int seamless_boot_odm_combine;
992 	unsigned int force_odm_combine_4to1; //bit vector based on otg inst
993 	int minimum_z8_residency_time;
994 	int minimum_z10_residency_time;
995 	bool disable_z9_mpc;
996 	unsigned int force_fclk_khz;
997 	bool enable_tri_buf;
998 	bool ips_disallow_entry;
999 	bool dmub_offload_enabled;
1000 	bool dmcub_emulation;
1001 	bool disable_idle_power_optimizations;
1002 	unsigned int mall_size_override;
1003 	unsigned int mall_additional_timer_percent;
1004 	bool mall_error_as_fatal;
1005 	bool dmub_command_table; /* for testing only */
1006 	struct dc_bw_validation_profile bw_val_profile;
1007 	bool disable_fec;
1008 	bool disable_48mhz_pwrdwn;
1009 	/* This forces a hard min on the DCFCLK requested to SMU/PP
1010 	 * watermarks are not affected.
1011 	 */
1012 	unsigned int force_min_dcfclk_mhz;
1013 	int dwb_fi_phase;
1014 	bool disable_timing_sync;
1015 	bool cm_in_bypass;
1016 	int force_clock_mode;/*every mode change.*/
1017 
1018 	bool disable_dram_clock_change_vactive_support;
1019 	bool validate_dml_output;
1020 	bool enable_dmcub_surface_flip;
1021 	bool usbc_combo_phy_reset_wa;
1022 	bool enable_dram_clock_change_one_display_vactive;
1023 	/* TODO - remove once tested */
1024 	bool legacy_dp2_lt;
1025 	bool set_mst_en_for_sst;
1026 	bool disable_uhbr;
1027 	bool force_dp2_lt_fallback_method;
1028 	bool ignore_cable_id;
1029 	union mem_low_power_enable_options enable_mem_low_power;
1030 	union root_clock_optimization_options root_clock_optimization;
1031 	union fine_grain_clock_gating_enable_options enable_fine_grain_clock_gating;
1032 	bool hpo_optimization;
1033 	bool force_vblank_alignment;
1034 
1035 	/* Enable dmub aux for legacy ddc */
1036 	bool enable_dmub_aux_for_legacy_ddc;
1037 	bool disable_fams;
1038 	enum in_game_fams_config disable_fams_gaming;
1039 	/* FEC/PSR1 sequence enable delay in 100us */
1040 	uint8_t fec_enable_delay_in100us;
1041 	bool enable_driver_sequence_debug;
1042 	enum det_size crb_alloc_policy;
1043 	int crb_alloc_policy_min_disp_count;
1044 	bool disable_z10;
1045 	bool enable_z9_disable_interface;
1046 	bool psr_skip_crtc_disable;
1047 	uint32_t ips_skip_crtc_disable_mask;
1048 	union dpia_debug_options dpia_debug;
1049 	bool disable_fixed_vs_aux_timeout_wa;
1050 	uint32_t fixed_vs_aux_delay_config_wa;
1051 	bool force_disable_subvp;
1052 	bool force_subvp_mclk_switch;
1053 	bool allow_sw_cursor_fallback;
1054 	unsigned int force_subvp_num_ways;
1055 	unsigned int force_mall_ss_num_ways;
1056 	bool alloc_extra_way_for_cursor;
1057 	uint32_t subvp_extra_lines;
1058 	bool force_usr_allow;
1059 	/* uses value at boot and disables switch */
1060 	bool disable_dtb_ref_clk_switch;
1061 	bool extended_blank_optimization;
1062 	union aux_wake_wa_options aux_wake_wa;
1063 	uint32_t mst_start_top_delay;
1064 	uint8_t psr_power_use_phy_fsm;
1065 	enum dml_hostvm_override_opts dml_hostvm_override;
1066 	bool dml_disallow_alternate_prefetch_modes;
1067 	bool use_legacy_soc_bb_mechanism;
1068 	bool exit_idle_opt_for_cursor_updates;
1069 	bool using_dml2;
1070 	bool enable_single_display_2to1_odm_policy;
1071 	bool enable_double_buffered_dsc_pg_support;
1072 	bool enable_dp_dig_pixel_rate_div_policy;
1073 	bool using_dml21;
1074 	enum lttpr_mode lttpr_mode_override;
1075 	unsigned int dsc_delay_factor_wa_x1000;
1076 	unsigned int min_prefetch_in_strobe_ns;
1077 	bool disable_unbounded_requesting;
1078 	bool dig_fifo_off_in_blank;
1079 	bool override_dispclk_programming;
1080 	bool otg_crc_db;
1081 	bool disallow_dispclk_dppclk_ds;
1082 	bool disable_fpo_optimizations;
1083 	bool support_eDP1_5;
1084 	uint32_t fpo_vactive_margin_us;
1085 	bool disable_fpo_vactive;
1086 	bool disable_boot_optimizations;
1087 	bool override_odm_optimization;
1088 	bool minimize_dispclk_using_odm;
1089 	bool disable_subvp_high_refresh;
1090 	bool disable_dp_plus_plus_wa;
1091 	uint32_t fpo_vactive_min_active_margin_us;
1092 	uint32_t fpo_vactive_max_blank_us;
1093 	bool enable_hpo_pg_support;
1094 	bool enable_legacy_fast_update;
1095 	bool disable_dc_mode_overwrite;
1096 	bool replay_skip_crtc_disabled;
1097 	bool ignore_pg;/*do nothing, let pmfw control it*/
1098 	bool psp_disabled_wa;
1099 	unsigned int ips2_eval_delay_us;
1100 	unsigned int ips2_entry_delay_us;
1101 	bool optimize_ips_handshake;
1102 	bool disable_dmub_reallow_idle;
1103 	bool disable_timeout;
1104 	bool disable_extblankadj;
1105 	bool enable_idle_reg_checks;
1106 	unsigned int static_screen_wait_frames;
1107 	uint32_t pwm_freq;
1108 	bool force_chroma_subsampling_1tap;
1109 	unsigned int dcc_meta_propagation_delay_us;
1110 	bool disable_422_left_edge_pixel;
1111 	bool dml21_force_pstate_method;
1112 	uint32_t dml21_force_pstate_method_values[MAX_PIPES];
1113 	uint32_t dml21_disable_pstate_method_mask;
1114 	union fw_assisted_mclk_switch_version fams_version;
1115 	union dmub_fams2_global_feature_config fams2_config;
1116 	unsigned int force_cositing;
1117 	unsigned int disable_spl;
1118 	unsigned int force_easf;
1119 	unsigned int force_sharpness;
1120 	unsigned int force_sharpness_level;
1121 	unsigned int force_lls;
1122 	bool notify_dpia_hr_bw;
1123 	bool enable_ips_visual_confirm;
1124 	unsigned int sharpen_policy;
1125 	unsigned int scale_to_sharpness_policy;
1126 	bool skip_full_updated_if_possible;
1127 	unsigned int enable_oled_edp_power_up_opt;
1128 	bool enable_hblank_borrow;
1129 	bool force_subvp_df_throttle;
1130 	uint32_t acpi_transition_bitmasks[MAX_PIPES];
1131 };
1132 
1133 
1134 /* Generic structure that can be used to query properties of DC. More fields
1135  * can be added as required.
1136  */
1137 struct dc_current_properties {
1138 	unsigned int cursor_size_limit;
1139 };
1140 
1141 enum frame_buffer_mode {
1142 	FRAME_BUFFER_MODE_LOCAL_ONLY = 0,
1143 	FRAME_BUFFER_MODE_ZFB_ONLY,
1144 	FRAME_BUFFER_MODE_MIXED_ZFB_AND_LOCAL,
1145 } ;
1146 
1147 struct dchub_init_data {
1148 	int64_t zfb_phys_addr_base;
1149 	int64_t zfb_mc_base_addr;
1150 	uint64_t zfb_size_in_byte;
1151 	enum frame_buffer_mode fb_mode;
1152 	bool dchub_initialzied;
1153 	bool dchub_info_valid;
1154 };
1155 
1156 struct dml2_soc_bb;
1157 
1158 struct dc_init_data {
1159 	struct hw_asic_id asic_id;
1160 	void *driver; /* ctx */
1161 	struct cgs_device *cgs_device;
1162 	struct dc_bounding_box_overrides bb_overrides;
1163 
1164 	int num_virtual_links;
1165 	/*
1166 	 * If 'vbios_override' not NULL, it will be called instead
1167 	 * of the real VBIOS. Intended use is Diagnostics on FPGA.
1168 	 */
1169 	struct dc_bios *vbios_override;
1170 	enum dce_environment dce_environment;
1171 
1172 	struct dmub_offload_funcs *dmub_if;
1173 	struct dc_reg_helper_state *dmub_offload;
1174 
1175 	struct dc_config flags;
1176 	uint64_t log_mask;
1177 
1178 	struct dpcd_vendor_signature vendor_signature;
1179 	bool force_smu_not_present;
1180 	/*
1181 	 * IP offset for run time initializaion of register addresses
1182 	 *
1183 	 * DCN3.5+ will fail dc_create() if these fields are null for them. They are
1184 	 * applicable starting with DCN32/321 and are not used for ASICs upstreamed
1185 	 * before them.
1186 	 */
1187 	uint32_t *dcn_reg_offsets;
1188 	uint32_t *nbio_reg_offsets;
1189 	uint32_t *clk_reg_offsets;
1190 	struct dml2_soc_bb *bb_from_dmub;
1191 };
1192 
1193 struct dc_callback_init {
1194 	struct cp_psp cp_psp;
1195 };
1196 
1197 struct dc *dc_create(const struct dc_init_data *init_params);
1198 void dc_hardware_init(struct dc *dc);
1199 
1200 int dc_get_vmid_use_vector(struct dc *dc);
1201 void dc_setup_vm_context(struct dc *dc, struct dc_virtual_addr_space_config *va_config, int vmid);
1202 /* Returns the number of vmids supported */
1203 int dc_setup_system_context(struct dc *dc, struct dc_phy_addr_space_config *pa_config);
1204 void dc_init_callbacks(struct dc *dc,
1205 		const struct dc_callback_init *init_params);
1206 void dc_deinit_callbacks(struct dc *dc);
1207 void dc_destroy(struct dc **dc);
1208 
1209 /* Surface Interfaces */
1210 
1211 enum {
1212 	TRANSFER_FUNC_POINTS = 1025
1213 };
1214 
1215 struct dc_hdr_static_metadata {
1216 	/* display chromaticities and white point in units of 0.00001 */
1217 	unsigned int chromaticity_green_x;
1218 	unsigned int chromaticity_green_y;
1219 	unsigned int chromaticity_blue_x;
1220 	unsigned int chromaticity_blue_y;
1221 	unsigned int chromaticity_red_x;
1222 	unsigned int chromaticity_red_y;
1223 	unsigned int chromaticity_white_point_x;
1224 	unsigned int chromaticity_white_point_y;
1225 
1226 	uint32_t min_luminance;
1227 	uint32_t max_luminance;
1228 	uint32_t maximum_content_light_level;
1229 	uint32_t maximum_frame_average_light_level;
1230 };
1231 
1232 enum dc_transfer_func_type {
1233 	TF_TYPE_PREDEFINED,
1234 	TF_TYPE_DISTRIBUTED_POINTS,
1235 	TF_TYPE_BYPASS,
1236 	TF_TYPE_HWPWL
1237 };
1238 
1239 struct dc_transfer_func_distributed_points {
1240 	struct fixed31_32 red[TRANSFER_FUNC_POINTS];
1241 	struct fixed31_32 green[TRANSFER_FUNC_POINTS];
1242 	struct fixed31_32 blue[TRANSFER_FUNC_POINTS];
1243 
1244 	uint16_t end_exponent;
1245 	uint16_t x_point_at_y1_red;
1246 	uint16_t x_point_at_y1_green;
1247 	uint16_t x_point_at_y1_blue;
1248 };
1249 
1250 enum dc_transfer_func_predefined {
1251 	TRANSFER_FUNCTION_SRGB,
1252 	TRANSFER_FUNCTION_BT709,
1253 	TRANSFER_FUNCTION_PQ,
1254 	TRANSFER_FUNCTION_LINEAR,
1255 	TRANSFER_FUNCTION_UNITY,
1256 	TRANSFER_FUNCTION_HLG,
1257 	TRANSFER_FUNCTION_HLG12,
1258 	TRANSFER_FUNCTION_GAMMA22,
1259 	TRANSFER_FUNCTION_GAMMA24,
1260 	TRANSFER_FUNCTION_GAMMA26
1261 };
1262 
1263 
1264 struct dc_transfer_func {
1265 	struct kref refcount;
1266 	enum dc_transfer_func_type type;
1267 	enum dc_transfer_func_predefined tf;
1268 	/* FP16 1.0 reference level in nits, default is 80 nits, only for PQ*/
1269 	uint32_t sdr_ref_white_level;
1270 	union {
1271 		struct pwl_params pwl;
1272 		struct dc_transfer_func_distributed_points tf_pts;
1273 	};
1274 };
1275 
1276 
1277 union dc_3dlut_state {
1278 	struct {
1279 		uint32_t initialized:1;		/*if 3dlut is went through color module for initialization */
1280 		uint32_t rmu_idx_valid:1;	/*if mux settings are valid*/
1281 		uint32_t rmu_mux_num:3;		/*index of mux to use*/
1282 		uint32_t mpc_rmu0_mux:4;	/*select mpcc on mux, one of the following : mpcc0, mpcc1, mpcc2, mpcc3*/
1283 		uint32_t mpc_rmu1_mux:4;
1284 		uint32_t mpc_rmu2_mux:4;
1285 		uint32_t reserved:15;
1286 	} bits;
1287 	uint32_t raw;
1288 };
1289 
1290 
1291 struct dc_3dlut {
1292 	struct kref refcount;
1293 	struct tetrahedral_params lut_3d;
1294 	struct fixed31_32 hdr_multiplier;
1295 	union dc_3dlut_state state;
1296 };
1297 /*
1298  * This structure is filled in by dc_surface_get_status and contains
1299  * the last requested address and the currently active address so the called
1300  * can determine if there are any outstanding flips
1301  */
1302 struct dc_plane_status {
1303 	struct dc_plane_address requested_address;
1304 	struct dc_plane_address current_address;
1305 	bool is_flip_pending;
1306 	bool is_right_eye;
1307 };
1308 
1309 union surface_update_flags {
1310 
1311 	struct {
1312 		uint32_t addr_update:1;
1313 		/* Medium updates */
1314 		uint32_t dcc_change:1;
1315 		uint32_t color_space_change:1;
1316 		uint32_t horizontal_mirror_change:1;
1317 		uint32_t per_pixel_alpha_change:1;
1318 		uint32_t global_alpha_change:1;
1319 		uint32_t hdr_mult:1;
1320 		uint32_t rotation_change:1;
1321 		uint32_t swizzle_change:1;
1322 		uint32_t scaling_change:1;
1323 		uint32_t position_change:1;
1324 		uint32_t in_transfer_func_change:1;
1325 		uint32_t input_csc_change:1;
1326 		uint32_t coeff_reduction_change:1;
1327 		uint32_t output_tf_change:1;
1328 		uint32_t pixel_format_change:1;
1329 		uint32_t plane_size_change:1;
1330 		uint32_t gamut_remap_change:1;
1331 
1332 		/* Full updates */
1333 		uint32_t new_plane:1;
1334 		uint32_t bpp_change:1;
1335 		uint32_t gamma_change:1;
1336 		uint32_t bandwidth_change:1;
1337 		uint32_t clock_change:1;
1338 		uint32_t stereo_format_change:1;
1339 		uint32_t lut_3d:1;
1340 		uint32_t tmz_changed:1;
1341 		uint32_t mcm_transfer_function_enable_change:1; /* disable or enable MCM transfer func */
1342 		uint32_t full_update:1;
1343 		uint32_t sdr_white_level_nits:1;
1344 	} bits;
1345 
1346 	uint32_t raw;
1347 };
1348 
1349 #define DC_REMOVE_PLANE_POINTERS 1
1350 
1351 struct dc_plane_state {
1352 	struct dc_plane_address address;
1353 	struct dc_plane_flip_time time;
1354 	bool triplebuffer_flips;
1355 	struct scaling_taps scaling_quality;
1356 	struct rect src_rect;
1357 	struct rect dst_rect;
1358 	struct rect clip_rect;
1359 
1360 	struct plane_size plane_size;
1361 	struct dc_tiling_info tiling_info;
1362 
1363 	struct dc_plane_dcc_param dcc;
1364 
1365 	struct dc_gamma gamma_correction;
1366 	struct dc_transfer_func in_transfer_func;
1367 	struct dc_bias_and_scale bias_and_scale;
1368 	struct dc_csc_transform input_csc_color_matrix;
1369 	struct fixed31_32 coeff_reduction_factor;
1370 	struct fixed31_32 hdr_mult;
1371 	struct colorspace_transform gamut_remap_matrix;
1372 
1373 	// TODO: No longer used, remove
1374 	struct dc_hdr_static_metadata hdr_static_ctx;
1375 
1376 	enum dc_color_space color_space;
1377 
1378 	struct dc_3dlut lut3d_func;
1379 	struct dc_transfer_func in_shaper_func;
1380 	struct dc_transfer_func blend_tf;
1381 
1382 	struct dc_transfer_func *gamcor_tf;
1383 	enum surface_pixel_format format;
1384 	enum dc_rotation_angle rotation;
1385 	enum plane_stereo_format stereo_format;
1386 
1387 	bool is_tiling_rotated;
1388 	bool per_pixel_alpha;
1389 	bool pre_multiplied_alpha;
1390 	bool global_alpha;
1391 	int  global_alpha_value;
1392 	bool visible;
1393 	bool flip_immediate;
1394 	bool horizontal_mirror;
1395 	int layer_index;
1396 
1397 	union surface_update_flags update_flags;
1398 	bool flip_int_enabled;
1399 	bool skip_manual_trigger;
1400 
1401 	/* private to DC core */
1402 	struct dc_plane_status status;
1403 	struct dc_context *ctx;
1404 
1405 	/* HACK: Workaround for forcing full reprogramming under some conditions */
1406 	bool force_full_update;
1407 
1408 	bool is_phantom; // TODO: Change mall_stream_config into mall_plane_config instead
1409 
1410 	/* private to dc_surface.c */
1411 	enum dc_irq_source irq_source;
1412 	struct kref refcount;
1413 	struct tg_color visual_confirm_color;
1414 
1415 	bool is_statically_allocated;
1416 	enum chroma_cositing cositing;
1417 	enum dc_cm2_shaper_3dlut_setting mcm_shaper_3dlut_setting;
1418 	bool mcm_lut1d_enable;
1419 	struct dc_cm2_func_luts mcm_luts;
1420 	bool lut_bank_a;
1421 	enum mpcc_movable_cm_location mcm_location;
1422 	struct dc_csc_transform cursor_csc_color_matrix;
1423 	bool adaptive_sharpness_en;
1424 	int adaptive_sharpness_policy;
1425 	int sharpness_level;
1426 	enum linear_light_scaling linear_light_scaling;
1427 	unsigned int sdr_white_level_nits;
1428 	struct spl_sharpness_range sharpness_range;
1429 	enum sharpness_range_source sharpness_source;
1430 };
1431 
1432 struct dc_plane_info {
1433 	struct plane_size plane_size;
1434 	struct dc_tiling_info tiling_info;
1435 	struct dc_plane_dcc_param dcc;
1436 	enum surface_pixel_format format;
1437 	enum dc_rotation_angle rotation;
1438 	enum plane_stereo_format stereo_format;
1439 	enum dc_color_space color_space;
1440 	bool horizontal_mirror;
1441 	bool visible;
1442 	bool per_pixel_alpha;
1443 	bool pre_multiplied_alpha;
1444 	bool global_alpha;
1445 	int  global_alpha_value;
1446 	bool input_csc_enabled;
1447 	int layer_index;
1448 	enum chroma_cositing cositing;
1449 };
1450 
1451 #include "dc_stream.h"
1452 
1453 struct dc_scratch_space {
1454 	/* used to temporarily backup plane states of a stream during
1455 	 * dc update. The reason is that plane states are overwritten
1456 	 * with surface updates in dc update. Once they are overwritten
1457 	 * current state is no longer valid. We want to temporarily
1458 	 * store current value in plane states so we can still recover
1459 	 * a valid current state during dc update.
1460 	 */
1461 	struct dc_plane_state plane_states[MAX_SURFACES];
1462 
1463 	struct dc_stream_state stream_state;
1464 };
1465 
1466 /*
1467  * A link contains one or more sinks and their connected status.
1468  * The currently active signal type (HDMI, DP-SST, DP-MST) is also reported.
1469  */
1470  struct dc_link {
1471 	struct dc_sink *remote_sinks[MAX_SINKS_PER_LINK];
1472 	unsigned int sink_count;
1473 	struct dc_sink *local_sink;
1474 	unsigned int link_index;
1475 	enum dc_connection_type type;
1476 	enum signal_type connector_signal;
1477 	enum dc_irq_source irq_source_hpd;
1478 	enum dc_irq_source irq_source_hpd_rx;/* aka DP Short Pulse  */
1479 	enum dc_irq_source irq_source_read_request;/* Read Request */
1480 
1481 	bool is_hpd_filter_disabled;
1482 	bool dp_ss_off;
1483 
1484 	/**
1485 	 * @link_state_valid:
1486 	 *
1487 	 * If there is no link and local sink, this variable should be set to
1488 	 * false. Otherwise, it should be set to true; usually, the function
1489 	 * core_link_enable_stream sets this field to true.
1490 	 */
1491 	bool link_state_valid;
1492 	bool aux_access_disabled;
1493 	bool sync_lt_in_progress;
1494 	bool skip_stream_reenable;
1495 	bool is_internal_display;
1496 	/** @todo Rename. Flag an endpoint as having a programmable mapping to a DIG encoder. */
1497 	bool is_dig_mapping_flexible;
1498 	bool hpd_status; /* HPD status of link without physical HPD pin. */
1499 	bool is_hpd_pending; /* Indicates a new received hpd */
1500 
1501 	/* USB4 DPIA links skip verifying link cap, instead performing the fallback method
1502 	 * for every link training. This is incompatible with DP LL compliance automation,
1503 	 * which expects the same link settings to be used every retry on a link loss.
1504 	 * This flag is used to skip the fallback when link loss occurs during automation.
1505 	 */
1506 	bool skip_fallback_on_link_loss;
1507 
1508 	bool edp_sink_present;
1509 
1510 	struct dp_trace dp_trace;
1511 
1512 	/* caps is the same as reported_link_cap. link_traing use
1513 	 * reported_link_cap. Will clean up.  TODO
1514 	 */
1515 	struct dc_link_settings reported_link_cap;
1516 	struct dc_link_settings verified_link_cap;
1517 	struct dc_link_settings cur_link_settings;
1518 	struct dc_lane_settings cur_lane_setting[LANE_COUNT_DP_MAX];
1519 	struct dc_link_settings preferred_link_setting;
1520 	/* preferred_training_settings are override values that
1521 	 * come from DM. DM is responsible for the memory
1522 	 * management of the override pointers.
1523 	 */
1524 	struct dc_link_training_overrides preferred_training_settings;
1525 	struct dp_audio_test_data audio_test_data;
1526 
1527 	uint8_t ddc_hw_inst;
1528 
1529 	uint8_t hpd_src;
1530 
1531 	uint8_t link_enc_hw_inst;
1532 	/* DIG link encoder ID. Used as index in link encoder resource pool.
1533 	 * For links with fixed mapping to DIG, this is not changed after dc_link
1534 	 * object creation.
1535 	 */
1536 	enum engine_id eng_id;
1537 	enum engine_id dpia_preferred_eng_id;
1538 
1539 	bool test_pattern_enabled;
1540 	/* Pending/Current test pattern are only used to perform and track
1541 	 * FIXED_VS retimer test pattern/lane adjustment override state.
1542 	 * Pending allows link HWSS to differentiate PHY vs non-PHY pattern,
1543 	 * to perform specific lane adjust overrides before setting certain
1544 	 * PHY test patterns. In cases when lane adjust and set test pattern
1545 	 * calls are not performed atomically (i.e. performing link training),
1546 	 * pending_test_pattern will be invalid or contain a non-PHY test pattern
1547 	 * and current_test_pattern will contain required context for any future
1548 	 * set pattern/set lane adjust to transition between override state(s).
1549 	 * */
1550 	enum dp_test_pattern current_test_pattern;
1551 	enum dp_test_pattern pending_test_pattern;
1552 
1553 	union compliance_test_state compliance_test_state;
1554 
1555 	void *priv;
1556 
1557 	struct ddc_service *ddc;
1558 
1559 	enum dp_panel_mode panel_mode;
1560 	bool aux_mode;
1561 
1562 	/* Private to DC core */
1563 
1564 	const struct dc *dc;
1565 
1566 	struct dc_context *ctx;
1567 
1568 	struct panel_cntl *panel_cntl;
1569 	struct link_encoder *link_enc;
1570 	struct graphics_object_id link_id;
1571 	/* Endpoint type distinguishes display endpoints which do not have entries
1572 	 * in the BIOS connector table from those that do. Helps when tracking link
1573 	 * encoder to display endpoint assignments.
1574 	 */
1575 	enum display_endpoint_type ep_type;
1576 	union ddi_channel_mapping ddi_channel_mapping;
1577 	struct connector_device_tag_info device_tag;
1578 	struct dpcd_caps dpcd_caps;
1579 	uint32_t dongle_max_pix_clk;
1580 	unsigned short chip_caps;
1581 	unsigned int dpcd_sink_count;
1582 	struct hdcp_caps hdcp_caps;
1583 	enum edp_revision edp_revision;
1584 	union dpcd_sink_ext_caps dpcd_sink_ext_caps;
1585 
1586 	struct psr_settings psr_settings;
1587 	struct replay_settings replay_settings;
1588 
1589 	/* Drive settings read from integrated info table */
1590 	struct dc_lane_settings bios_forced_drive_settings;
1591 
1592 	/* Vendor specific LTTPR workaround variables */
1593 	uint8_t vendor_specific_lttpr_link_rate_wa;
1594 	bool apply_vendor_specific_lttpr_link_rate_wa;
1595 
1596 	/* MST record stream using this link */
1597 	struct link_flags {
1598 		bool dp_keep_receiver_powered;
1599 		bool dp_skip_DID2;
1600 		bool dp_skip_reset_segment;
1601 		bool dp_skip_fs_144hz;
1602 		bool dp_mot_reset_segment;
1603 		/* Some USB4 docks do not handle turning off MST DSC once it has been enabled. */
1604 		bool dpia_mst_dsc_always_on;
1605 		/* Forced DPIA into TBT3 compatibility mode. */
1606 		bool dpia_forced_tbt3_mode;
1607 		bool dongle_mode_timing_override;
1608 		bool blank_stream_on_ocs_change;
1609 		bool read_dpcd204h_on_irq_hpd;
1610 		bool force_dp_ffe_preset;
1611 	} wa_flags;
1612 	union dc_dp_ffe_preset forced_dp_ffe_preset;
1613 	struct link_mst_stream_allocation_table mst_stream_alloc_table;
1614 
1615 	struct dc_link_status link_status;
1616 	struct dprx_states dprx_states;
1617 
1618 	struct gpio *hpd_gpio;
1619 	enum dc_link_fec_state fec_state;
1620 	bool link_powered_externally;	// Used to bypass hardware sequencing delays when panel is powered down forcibly
1621 
1622 	struct dc_panel_config panel_config;
1623 	struct phy_state phy_state;
1624 	uint32_t phy_transition_bitmask;
1625 	// BW ALLOCATON USB4 ONLY
1626 	struct dc_dpia_bw_alloc dpia_bw_alloc_config;
1627 	bool skip_implict_edp_power_control;
1628 	enum backlight_control_type backlight_control_type;
1629 };
1630 
1631 struct dc {
1632 	struct dc_debug_options debug;
1633 	struct dc_versions versions;
1634 	struct dc_caps caps;
1635 	struct dc_cap_funcs cap_funcs;
1636 	struct dc_config config;
1637 	struct dc_bounding_box_overrides bb_overrides;
1638 	struct dc_bug_wa work_arounds;
1639 	struct dc_context *ctx;
1640 	struct dc_phy_addr_space_config vm_pa_config;
1641 
1642 	uint8_t link_count;
1643 	struct dc_link *links[MAX_LINKS];
1644 	uint8_t lowest_dpia_link_index;
1645 	struct link_service *link_srv;
1646 
1647 	struct dc_state *current_state;
1648 	struct resource_pool *res_pool;
1649 
1650 	struct clk_mgr *clk_mgr;
1651 
1652 	/* Display Engine Clock levels */
1653 	struct dm_pp_clock_levels sclk_lvls;
1654 
1655 	/* Inputs into BW and WM calculations. */
1656 	struct bw_calcs_dceip *bw_dceip;
1657 	struct bw_calcs_vbios *bw_vbios;
1658 	struct dcn_soc_bounding_box *dcn_soc;
1659 	struct dcn_ip_params *dcn_ip;
1660 	struct display_mode_lib dml;
1661 
1662 	/* HW functions */
1663 	struct hw_sequencer_funcs hwss;
1664 	struct dce_hwseq *hwseq;
1665 
1666 	/* Require to optimize clocks and bandwidth for added/removed planes */
1667 	bool optimized_required;
1668 	bool wm_optimized_required;
1669 	bool idle_optimizations_allowed;
1670 	bool enable_c20_dtm_b0;
1671 
1672 	/* Require to maintain clocks and bandwidth for UEFI enabled HW */
1673 
1674 	/* FBC compressor */
1675 	struct compressor *fbc_compressor;
1676 
1677 	struct dc_debug_data debug_data;
1678 	struct dpcd_vendor_signature vendor_signature;
1679 
1680 	const char *build_id;
1681 	struct vm_helper *vm_helper;
1682 
1683 	uint32_t *dcn_reg_offsets;
1684 	uint32_t *nbio_reg_offsets;
1685 	uint32_t *clk_reg_offsets;
1686 
1687 	/* Scratch memory */
1688 	struct {
1689 		struct {
1690 			/*
1691 			 * For matching clock_limits table in driver with table
1692 			 * from PMFW.
1693 			 */
1694 			struct _vcs_dpi_voltage_scaling_st clock_limits[DC__VOLTAGE_STATES];
1695 		} update_bw_bounding_box;
1696 		struct dc_scratch_space current_state;
1697 		struct dc_scratch_space new_state;
1698 		struct dc_stream_state temp_stream; // Used so we don't need to allocate stream on the stack
1699 		struct dc_link temp_link;
1700 		bool pipes_to_unlock_first[MAX_PIPES]; /* Any of the pipes indicated here should be unlocked first */
1701 	} scratch;
1702 
1703 	struct dml2_configuration_options dml2_options;
1704 	struct dml2_configuration_options dml2_tmp;
1705 	enum dc_acpi_cm_power_state power_state;
1706 
1707 };
1708 
1709 struct dc_scaling_info {
1710 	struct rect src_rect;
1711 	struct rect dst_rect;
1712 	struct rect clip_rect;
1713 	struct scaling_taps scaling_quality;
1714 };
1715 
1716 struct dc_fast_update {
1717 	const struct dc_flip_addrs *flip_addr;
1718 	const struct dc_gamma *gamma;
1719 	const struct colorspace_transform *gamut_remap_matrix;
1720 	const struct dc_csc_transform *input_csc_color_matrix;
1721 	const struct fixed31_32 *coeff_reduction_factor;
1722 	struct dc_transfer_func *out_transfer_func;
1723 	struct dc_csc_transform *output_csc_transform;
1724 	const struct dc_csc_transform *cursor_csc_color_matrix;
1725 };
1726 
1727 struct dc_surface_update {
1728 	struct dc_plane_state *surface;
1729 
1730 	/* isr safe update parameters.  null means no updates */
1731 	const struct dc_flip_addrs *flip_addr;
1732 	const struct dc_plane_info *plane_info;
1733 	const struct dc_scaling_info *scaling_info;
1734 	struct fixed31_32 hdr_mult;
1735 	/* following updates require alloc/sleep/spin that is not isr safe,
1736 	 * null means no updates
1737 	 */
1738 	const struct dc_gamma *gamma;
1739 	const struct dc_transfer_func *in_transfer_func;
1740 
1741 	const struct dc_csc_transform *input_csc_color_matrix;
1742 	const struct fixed31_32 *coeff_reduction_factor;
1743 	const struct dc_transfer_func *func_shaper;
1744 	const struct dc_3dlut *lut3d_func;
1745 	const struct dc_transfer_func *blend_tf;
1746 	const struct colorspace_transform *gamut_remap_matrix;
1747 	/*
1748 	 * Color Transformations for pre-blend MCM (Shaper, 3DLUT, 1DLUT)
1749 	 *
1750 	 * change cm2_params.component_settings: Full update
1751 	 * change cm2_params.cm2_luts: Fast update
1752 	 */
1753 	const struct dc_cm2_parameters *cm2_params;
1754 	const struct dc_csc_transform *cursor_csc_color_matrix;
1755 	unsigned int sdr_white_level_nits;
1756 	struct dc_bias_and_scale bias_and_scale;
1757 };
1758 
1759 /*
1760  * Create a new surface with default parameters;
1761  */
1762 void dc_gamma_retain(struct dc_gamma *dc_gamma);
1763 void dc_gamma_release(struct dc_gamma **dc_gamma);
1764 struct dc_gamma *dc_create_gamma(void);
1765 
1766 void dc_transfer_func_retain(struct dc_transfer_func *dc_tf);
1767 void dc_transfer_func_release(struct dc_transfer_func *dc_tf);
1768 struct dc_transfer_func *dc_create_transfer_func(void);
1769 
1770 struct dc_3dlut *dc_create_3dlut_func(void);
1771 void dc_3dlut_func_release(struct dc_3dlut *lut);
1772 void dc_3dlut_func_retain(struct dc_3dlut *lut);
1773 
1774 void dc_post_update_surfaces_to_stream(
1775 		struct dc *dc);
1776 
1777 #include "dc_stream.h"
1778 
1779 /**
1780  * struct dc_validation_set - Struct to store surface/stream associations for validation
1781  */
1782 struct dc_validation_set {
1783 	/**
1784 	 * @stream: Stream state properties
1785 	 */
1786 	struct dc_stream_state *stream;
1787 
1788 	/**
1789 	 * @plane_states: Surface state
1790 	 */
1791 	struct dc_plane_state *plane_states[MAX_SURFACES];
1792 
1793 	/**
1794 	 * @plane_count: Total of active planes
1795 	 */
1796 	uint8_t plane_count;
1797 };
1798 
1799 bool dc_validate_boot_timing(const struct dc *dc,
1800 				const struct dc_sink *sink,
1801 				struct dc_crtc_timing *crtc_timing);
1802 
1803 enum dc_status dc_validate_plane(struct dc *dc, const struct dc_plane_state *plane_state);
1804 
1805 enum dc_status dc_validate_with_context(struct dc *dc,
1806 					const struct dc_validation_set set[],
1807 					int set_count,
1808 					struct dc_state *context,
1809 					enum dc_validate_mode validate_mode);
1810 
1811 bool dc_set_generic_gpio_for_stereo(bool enable,
1812 		struct gpio_service *gpio_service);
1813 
1814 enum dc_status dc_validate_global_state(
1815 		struct dc *dc,
1816 		struct dc_state *new_ctx,
1817 		enum dc_validate_mode validate_mode);
1818 
1819 bool dc_acquire_release_mpc_3dlut(
1820 		struct dc *dc, bool acquire,
1821 		struct dc_stream_state *stream,
1822 		struct dc_3dlut **lut,
1823 		struct dc_transfer_func **shaper);
1824 
1825 bool dc_resource_is_dsc_encoding_supported(const struct dc *dc);
1826 void get_audio_check(struct audio_info *aud_modes,
1827 	struct audio_check *aud_chk);
1828 
1829 bool fast_nonaddr_updates_exist(struct dc_fast_update *fast_update, int surface_count);
1830 void populate_fast_updates(struct dc_fast_update *fast_update,
1831 		struct dc_surface_update *srf_updates,
1832 		int surface_count,
1833 		struct dc_stream_update *stream_update);
1834 /*
1835  * Set up streams and links associated to drive sinks
1836  * The streams parameter is an absolute set of all active streams.
1837  *
1838  * After this call:
1839  *   Phy, Encoder, Timing Generator are programmed and enabled.
1840  *   New streams are enabled with blank stream; no memory read.
1841  */
1842 enum dc_status dc_commit_streams(struct dc *dc, struct dc_commit_streams_params *params);
1843 
1844 
1845 struct dc_plane_state *dc_get_surface_for_mpcc(struct dc *dc,
1846 		struct dc_stream_state *stream,
1847 		int mpcc_inst);
1848 
1849 
1850 uint32_t dc_get_opp_for_plane(struct dc *dc, struct dc_plane_state *plane);
1851 
1852 void dc_set_disable_128b_132b_stream_overhead(bool disable);
1853 
1854 /* The function returns minimum bandwidth required to drive a given timing
1855  * return - minimum required timing bandwidth in kbps.
1856  */
1857 uint32_t dc_bandwidth_in_kbps_from_timing(
1858 		const struct dc_crtc_timing *timing,
1859 		const enum dc_link_encoding_format link_encoding);
1860 
1861 /* Link Interfaces */
1862 /* Return an enumerated dc_link.
1863  * dc_link order is constant and determined at
1864  * boot time.  They cannot be created or destroyed.
1865  * Use dc_get_caps() to get number of links.
1866  */
1867 struct dc_link *dc_get_link_at_index(struct dc *dc, uint32_t link_index);
1868 
1869 /* Return instance id of the edp link. Inst 0 is primary edp link. */
1870 bool dc_get_edp_link_panel_inst(const struct dc *dc,
1871 		const struct dc_link *link,
1872 		unsigned int *inst_out);
1873 
1874 /* Return an array of link pointers to edp links. */
1875 void dc_get_edp_links(const struct dc *dc,
1876 		struct dc_link **edp_links,
1877 		int *edp_num);
1878 
1879 void dc_set_edp_power(const struct dc *dc, struct dc_link *edp_link,
1880 				 bool powerOn);
1881 
1882 /* The function initiates detection handshake over the given link. It first
1883  * determines if there are display connections over the link. If so it initiates
1884  * detection protocols supported by the connected receiver device. The function
1885  * contains protocol specific handshake sequences which are sometimes mandatory
1886  * to establish a proper connection between TX and RX. So it is always
1887  * recommended to call this function as the first link operation upon HPD event
1888  * or power up event. Upon completion, the function will update link structure
1889  * in place based on latest RX capabilities. The function may also cause dpms
1890  * to be reset to off for all currently enabled streams to the link. It is DM's
1891  * responsibility to serialize detection and DPMS updates.
1892  *
1893  * @reason - Indicate which event triggers this detection. dc may customize
1894  * detection flow depending on the triggering events.
1895  * return false - if detection is not fully completed. This could happen when
1896  * there is an unrecoverable error during detection or detection is partially
1897  * completed (detection has been delegated to dm mst manager ie.
1898  * link->connection_type == dc_connection_mst_branch when returning false).
1899  * return true - detection is completed, link has been fully updated with latest
1900  * detection result.
1901  */
1902 bool dc_link_detect(struct dc_link *link, enum dc_detect_reason reason);
1903 
1904 struct dc_sink_init_data;
1905 
1906 /* When link connection type is dc_connection_mst_branch, remote sink can be
1907  * added to the link. The interface creates a remote sink and associates it with
1908  * current link. The sink will be retained by link until remove remote sink is
1909  * called.
1910  *
1911  * @dc_link - link the remote sink will be added to.
1912  * @edid - byte array of EDID raw data.
1913  * @len - size of the edid in byte
1914  * @init_data -
1915  */
1916 struct dc_sink *dc_link_add_remote_sink(
1917 		struct dc_link *dc_link,
1918 		const uint8_t *edid,
1919 		int len,
1920 		struct dc_sink_init_data *init_data);
1921 
1922 /* Remove remote sink from a link with dc_connection_mst_branch connection type.
1923  * @link - link the sink should be removed from
1924  * @sink - sink to be removed.
1925  */
1926 void dc_link_remove_remote_sink(
1927 	struct dc_link *link,
1928 	struct dc_sink *sink);
1929 
1930 /* Enable HPD interrupt handler for a given link */
1931 void dc_link_enable_hpd(const struct dc_link *link);
1932 
1933 /* Disable HPD interrupt handler for a given link */
1934 void dc_link_disable_hpd(const struct dc_link *link);
1935 
1936 /* determine if there is a sink connected to the link
1937  *
1938  * @type - dc_connection_single if connected, dc_connection_none otherwise.
1939  * return - false if an unexpected error occurs, true otherwise.
1940  *
1941  * NOTE: This function doesn't detect downstream sink connections i.e
1942  * dc_connection_mst_branch, dc_connection_sst_branch. In this case, it will
1943  * return dc_connection_single if the branch device is connected despite of
1944  * downstream sink's connection status.
1945  */
1946 bool dc_link_detect_connection_type(struct dc_link *link,
1947 		enum dc_connection_type *type);
1948 
1949 /* query current hpd pin value
1950  * return - true HPD is asserted (HPD high), false otherwise (HPD low)
1951  *
1952  */
1953 bool dc_link_get_hpd_state(struct dc_link *link);
1954 
1955 /* Getter for cached link status from given link */
1956 const struct dc_link_status *dc_link_get_status(const struct dc_link *link);
1957 
1958 /* enable/disable hardware HPD filter.
1959  *
1960  * @link - The link the HPD pin is associated with.
1961  * @enable = true - enable hardware HPD filter. HPD event will only queued to irq
1962  * handler once after no HPD change has been detected within dc default HPD
1963  * filtering interval since last HPD event. i.e if display keeps toggling hpd
1964  * pulses within default HPD interval, no HPD event will be received until HPD
1965  * toggles have stopped. Then HPD event will be queued to irq handler once after
1966  * dc default HPD filtering interval since last HPD event.
1967  *
1968  * @enable = false - disable hardware HPD filter. HPD event will be queued
1969  * immediately to irq handler after no HPD change has been detected within
1970  * IRQ_HPD (aka HPD short pulse) interval (i.e 2ms).
1971  */
1972 void dc_link_enable_hpd_filter(struct dc_link *link, bool enable);
1973 
1974 /* submit i2c read/write payloads through ddc channel
1975  * @link_index - index to a link with ddc in i2c mode
1976  * @cmd - i2c command structure
1977  * return - true if success, false otherwise.
1978  */
1979 bool dc_submit_i2c(
1980 		struct dc *dc,
1981 		uint32_t link_index,
1982 		struct i2c_command *cmd);
1983 
1984 /* submit i2c read/write payloads through oem channel
1985  * @link_index - index to a link with ddc in i2c mode
1986  * @cmd - i2c command structure
1987  * return - true if success, false otherwise.
1988  */
1989 bool dc_submit_i2c_oem(
1990 		struct dc *dc,
1991 		struct i2c_command *cmd);
1992 
1993 enum aux_return_code_type;
1994 /* Attempt to transfer the given aux payload. This function does not perform
1995  * retries or handle error states. The reply is returned in the payload->reply
1996  * and the result through operation_result. Returns the number of bytes
1997  * transferred,or -1 on a failure.
1998  */
1999 int dc_link_aux_transfer_raw(struct ddc_service *ddc,
2000 		struct aux_payload *payload,
2001 		enum aux_return_code_type *operation_result);
2002 
2003 struct ddc_service *
2004 dc_get_oem_i2c_device(struct dc *dc);
2005 
2006 bool dc_is_oem_i2c_device_present(
2007 	struct dc *dc,
2008 	size_t slave_address
2009 );
2010 
2011 /* return true if the connected receiver supports the hdcp version */
2012 bool dc_link_is_hdcp14(struct dc_link *link, enum signal_type signal);
2013 bool dc_link_is_hdcp22(struct dc_link *link, enum signal_type signal);
2014 
2015 /* Notify DC about DP RX Interrupt (aka DP IRQ_HPD).
2016  *
2017  * TODO - When defer_handling is true the function will have a different purpose.
2018  * It no longer does complete hpd rx irq handling. We should create a separate
2019  * interface specifically for this case.
2020  *
2021  * Return:
2022  * true - Downstream port status changed. DM should call DC to do the
2023  * detection.
2024  * false - no change in Downstream port status. No further action required
2025  * from DM.
2026  */
2027 bool dc_link_handle_hpd_rx_irq(struct dc_link *dc_link,
2028 		union hpd_irq_data *hpd_irq_dpcd_data, bool *out_link_loss,
2029 		bool defer_handling, bool *has_left_work);
2030 /* handle DP specs define test automation sequence*/
2031 void dc_link_dp_handle_automated_test(struct dc_link *link);
2032 
2033 /* handle DP Link loss sequence and try to recover RX link loss with best
2034  * effort
2035  */
2036 void dc_link_dp_handle_link_loss(struct dc_link *link);
2037 
2038 /* Determine if hpd rx irq should be handled or ignored
2039  * return true - hpd rx irq should be handled.
2040  * return false - it is safe to ignore hpd rx irq event
2041  */
2042 bool dc_link_dp_allow_hpd_rx_irq(const struct dc_link *link);
2043 
2044 /* Determine if link loss is indicated with a given hpd_irq_dpcd_data.
2045  * @link - link the hpd irq data associated with
2046  * @hpd_irq_dpcd_data - input hpd irq data
2047  * return - true if hpd irq data indicates a link lost
2048  */
2049 bool dc_link_check_link_loss_status(struct dc_link *link,
2050 		union hpd_irq_data *hpd_irq_dpcd_data);
2051 
2052 /* Read hpd rx irq data from a given link
2053  * @link - link where the hpd irq data should be read from
2054  * @irq_data - output hpd irq data
2055  * return - DC_OK if hpd irq data is read successfully, otherwise hpd irq data
2056  * read has failed.
2057  */
2058 enum dc_status dc_link_dp_read_hpd_rx_irq_data(
2059 	struct dc_link *link,
2060 	union hpd_irq_data *irq_data);
2061 
2062 /* The function clears recorded DP RX states in the link. DM should call this
2063  * function when it is resuming from S3 power state to previously connected links.
2064  *
2065  * TODO - in the future we should consider to expand link resume interface to
2066  * support clearing previous rx states. So we don't have to rely on dm to call
2067  * this interface explicitly.
2068  */
2069 void dc_link_clear_dprx_states(struct dc_link *link);
2070 
2071 /* Destruct the mst topology of the link and reset the allocated payload table
2072  *
2073  * NOTE: this should only be called if DM chooses not to call dc_link_detect but
2074  * still wants to reset MST topology on an unplug event */
2075 bool dc_link_reset_cur_dp_mst_topology(struct dc_link *link);
2076 
2077 /* The function calculates effective DP link bandwidth when a given link is
2078  * using the given link settings.
2079  *
2080  * return - total effective link bandwidth in kbps.
2081  */
2082 uint32_t dc_link_bandwidth_kbps(
2083 	const struct dc_link *link,
2084 	const struct dc_link_settings *link_setting);
2085 
2086 struct dp_audio_bandwidth_params {
2087 	const struct dc_crtc_timing *crtc_timing;
2088 	enum dp_link_encoding link_encoding;
2089 	uint32_t channel_count;
2090 	uint32_t sample_rate_hz;
2091 };
2092 
2093 /* The function calculates the minimum size of hblank (in bytes) needed to
2094  * support the specified channel count and sample rate combination, given the
2095  * link encoding and timing to be used. This calculation is not supported
2096  * for 8b/10b SST.
2097  *
2098  * return - min hblank size in bytes, 0 if 8b/10b SST.
2099  */
2100 uint32_t dc_link_required_hblank_size_bytes(
2101 	const struct dc_link *link,
2102 	struct dp_audio_bandwidth_params *audio_params);
2103 
2104 /* The function takes a snapshot of current link resource allocation state
2105  * @dc: pointer to dc of the dm calling this
2106  * @map: a dc link resource snapshot defined internally to dc.
2107  *
2108  * DM needs to capture a snapshot of current link resource allocation mapping
2109  * and store it in its persistent storage.
2110  *
2111  * Some of the link resource is using first come first serve policy.
2112  * The allocation mapping depends on original hotplug order. This information
2113  * is lost after driver is loaded next time. The snapshot is used in order to
2114  * restore link resource to its previous state so user will get consistent
2115  * link capability allocation across reboot.
2116  *
2117  */
2118 void dc_get_cur_link_res_map(const struct dc *dc, uint32_t *map);
2119 
2120 /* This function restores link resource allocation state from a snapshot
2121  * @dc: pointer to dc of the dm calling this
2122  * @map: a dc link resource snapshot defined internally to dc.
2123  *
2124  * DM needs to call this function after initial link detection on boot and
2125  * before first commit streams to restore link resource allocation state
2126  * from previous boot session.
2127  *
2128  * Some of the link resource is using first come first serve policy.
2129  * The allocation mapping depends on original hotplug order. This information
2130  * is lost after driver is loaded next time. The snapshot is used in order to
2131  * restore link resource to its previous state so user will get consistent
2132  * link capability allocation across reboot.
2133  *
2134  */
2135 void dc_restore_link_res_map(const struct dc *dc, uint32_t *map);
2136 
2137 /* TODO: this is not meant to be exposed to DM. Should switch to stream update
2138  * interface i.e stream_update->dsc_config
2139  */
2140 bool dc_link_update_dsc_config(struct pipe_ctx *pipe_ctx);
2141 
2142 /* translate a raw link rate data to bandwidth in kbps */
2143 uint32_t dc_link_bw_kbps_from_raw_frl_link_rate_data(const struct dc *dc, uint8_t bw);
2144 
2145 /* determine the optimal bandwidth given link and required bw.
2146  * @link - current detected link
2147  * @req_bw - requested bandwidth in kbps
2148  * @link_settings - returned most optimal link settings that can fit the
2149  * requested bandwidth
2150  * return - false if link can't support requested bandwidth, true if link
2151  * settings is found.
2152  */
2153 bool dc_link_decide_edp_link_settings(struct dc_link *link,
2154 		struct dc_link_settings *link_settings,
2155 		uint32_t req_bw);
2156 
2157 /* return the max dp link settings can be driven by the link without considering
2158  * connected RX device and its capability
2159  */
2160 bool dc_link_dp_get_max_link_enc_cap(const struct dc_link *link,
2161 		struct dc_link_settings *max_link_enc_cap);
2162 
2163 /* determine when the link is driving MST mode, what DP link channel coding
2164  * format will be used. The decision will remain unchanged until next HPD event.
2165  *
2166  * @link -  a link with DP RX connection
2167  * return - if stream is committed to this link with MST signal type, type of
2168  * channel coding format dc will choose.
2169  */
2170 enum dp_link_encoding dc_link_dp_mst_decide_link_encoding_format(
2171 		const struct dc_link *link);
2172 
2173 /* get max dp link settings the link can enable with all things considered. (i.e
2174  * TX/RX/Cable capabilities and dp override policies.
2175  *
2176  * @link - a link with DP RX connection
2177  * return - max dp link settings the link can enable.
2178  *
2179  */
2180 const struct dc_link_settings *dc_link_get_link_cap(const struct dc_link *link);
2181 
2182 /* Get the highest encoding format that the link supports; highest meaning the
2183  * encoding format which supports the maximum bandwidth.
2184  *
2185  * @link - a link with DP RX connection
2186  * return - highest encoding format link supports.
2187  */
2188 enum dc_link_encoding_format dc_link_get_highest_encoding_format(const struct dc_link *link);
2189 
2190 /* Check if a RX (ex. DP sink, MST hub, passive or active dongle) is connected
2191  * to a link with dp connector signal type.
2192  * @link - a link with dp connector signal type
2193  * return - true if connected, false otherwise
2194  */
2195 bool dc_link_is_dp_sink_present(struct dc_link *link);
2196 
2197 /* Force DP lane settings update to main-link video signal and notify the change
2198  * to DP RX via DPCD. This is a debug interface used for video signal integrity
2199  * tuning purpose. The interface assumes link has already been enabled with DP
2200  * signal.
2201  *
2202  * @lt_settings - a container structure with desired hw_lane_settings
2203  */
2204 void dc_link_set_drive_settings(struct dc *dc,
2205 				struct link_training_settings *lt_settings,
2206 				struct dc_link *link);
2207 
2208 /* Enable a test pattern in Link or PHY layer in an active link for compliance
2209  * test or debugging purpose. The test pattern will remain until next un-plug.
2210  *
2211  * @link - active link with DP signal output enabled.
2212  * @test_pattern - desired test pattern to output.
2213  * NOTE: set to DP_TEST_PATTERN_VIDEO_MODE to disable previous test pattern.
2214  * @test_pattern_color_space - for video test pattern choose a desired color
2215  * space.
2216  * @p_link_settings - For PHY pattern choose a desired link settings
2217  * @p_custom_pattern - some test pattern will require a custom input to
2218  * customize some pattern details. Otherwise keep it to NULL.
2219  * @cust_pattern_size - size of the custom pattern input.
2220  *
2221  */
2222 bool dc_link_dp_set_test_pattern(
2223 	struct dc_link *link,
2224 	enum dp_test_pattern test_pattern,
2225 	enum dp_test_pattern_color_space test_pattern_color_space,
2226 	const struct link_training_settings *p_link_settings,
2227 	const unsigned char *p_custom_pattern,
2228 	unsigned int cust_pattern_size);
2229 
2230 /* Force DP link settings to always use a specific value until reboot to a
2231  * specific link. If link has already been enabled, the interface will also
2232  * switch to desired link settings immediately. This is a debug interface to
2233  * generic dp issue trouble shooting.
2234  */
2235 void dc_link_set_preferred_link_settings(struct dc *dc,
2236 		struct dc_link_settings *link_setting,
2237 		struct dc_link *link);
2238 
2239 /* Force DP link to customize a specific link training behavior by overriding to
2240  * standard DP specs defined protocol. This is a debug interface to trouble shoot
2241  * display specific link training issues or apply some display specific
2242  * workaround in link training.
2243  *
2244  * @link_settings - if not NULL, force preferred link settings to the link.
2245  * @lt_override - a set of override pointers. If any pointer is none NULL, dc
2246  * will apply this particular override in future link training. If NULL is
2247  * passed in, dc resets previous overrides.
2248  * NOTE: DM must keep the memory from override pointers until DM resets preferred
2249  * training settings.
2250  */
2251 void dc_link_set_preferred_training_settings(struct dc *dc,
2252 		struct dc_link_settings *link_setting,
2253 		struct dc_link_training_overrides *lt_overrides,
2254 		struct dc_link *link,
2255 		bool skip_immediate_retrain);
2256 
2257 /* return - true if FEC is supported with connected DP RX, false otherwise */
2258 bool dc_link_is_fec_supported(const struct dc_link *link);
2259 
2260 /* query FEC enablement policy to determine if FEC will be enabled by dc during
2261  * link enablement.
2262  * return - true if FEC should be enabled, false otherwise.
2263  */
2264 bool dc_link_should_enable_fec(const struct dc_link *link);
2265 
2266 /* determine lttpr mode the current link should be enabled with a specific link
2267  * settings.
2268  */
2269 enum lttpr_mode dc_link_decide_lttpr_mode(struct dc_link *link,
2270 		struct dc_link_settings *link_setting);
2271 
2272 /* Force DP RX to update its power state.
2273  * NOTE: this interface doesn't update dp main-link. Calling this function will
2274  * cause DP TX main-link and DP RX power states out of sync. DM has to restore
2275  * RX power state back upon finish DM specific execution requiring DP RX in a
2276  * specific power state.
2277  * @on - true to set DP RX in D0 power state, false to set DP RX in D3 power
2278  * state.
2279  */
2280 void dc_link_dp_receiver_power_ctrl(struct dc_link *link, bool on);
2281 
2282 /* Force link to read base dp receiver caps from dpcd 000h - 00Fh and overwrite
2283  * current value read from extended receiver cap from 02200h - 0220Fh.
2284  * Some DP RX has problems of providing accurate DP receiver caps from extended
2285  * field, this interface is a workaround to revert link back to use base caps.
2286  */
2287 void dc_link_overwrite_extended_receiver_cap(
2288 		struct dc_link *link);
2289 
2290 void dc_link_edp_panel_backlight_power_on(struct dc_link *link,
2291 		bool wait_for_hpd);
2292 
2293 /* Set backlight level of an embedded panel (eDP, LVDS).
2294  * backlight_pwm_u16_16 is unsigned 32 bit with 16 bit integer
2295  * and 16 bit fractional, where 1.0 is max backlight value.
2296  */
2297 bool dc_link_set_backlight_level(const struct dc_link *dc_link,
2298 		struct set_backlight_level_params *backlight_level_params);
2299 
2300 /* Set/get nits-based backlight level of an embedded panel (eDP, LVDS). */
2301 bool dc_link_set_backlight_level_nits(struct dc_link *link,
2302 		bool isHDR,
2303 		uint32_t backlight_millinits,
2304 		uint32_t transition_time_in_ms);
2305 
2306 bool dc_link_get_backlight_level_nits(struct dc_link *link,
2307 		uint32_t *backlight_millinits,
2308 		uint32_t *backlight_millinits_peak);
2309 
2310 int dc_link_get_backlight_level(const struct dc_link *dc_link);
2311 
2312 int dc_link_get_target_backlight_pwm(const struct dc_link *link);
2313 
2314 bool dc_link_set_psr_allow_active(struct dc_link *dc_link, const bool *enable,
2315 		bool wait, bool force_static, const unsigned int *power_opts);
2316 
2317 bool dc_link_get_psr_state(const struct dc_link *dc_link, enum dc_psr_state *state);
2318 
2319 bool dc_link_setup_psr(struct dc_link *dc_link,
2320 		const struct dc_stream_state *stream, struct psr_config *psr_config,
2321 		struct psr_context *psr_context);
2322 
2323 /*
2324  * Communicate with DMUB to allow or disallow Panel Replay on the specified link:
2325  *
2326  * @link: pointer to the dc_link struct instance
2327  * @enable: enable(active) or disable(inactive) replay
2328  * @wait: state transition need to wait the active set completed.
2329  * @force_static: force disable(inactive) the replay
2330  * @power_opts: set power optimazation parameters to DMUB.
2331  *
2332  * return: allow Replay active will return true, else will return false.
2333  */
2334 bool dc_link_set_replay_allow_active(struct dc_link *dc_link, const bool *enable,
2335 		bool wait, bool force_static, const unsigned int *power_opts);
2336 
2337 bool dc_link_get_replay_state(const struct dc_link *dc_link, uint64_t *state);
2338 
2339 /* On eDP links this function call will stall until T12 has elapsed.
2340  * If the panel is not in power off state, this function will return
2341  * immediately.
2342  */
2343 bool dc_link_wait_for_t12(struct dc_link *link);
2344 
2345 /* Determine if dp trace has been initialized to reflect upto date result *
2346  * return - true if trace is initialized and has valid data. False dp trace
2347  * doesn't have valid result.
2348  */
2349 bool dc_dp_trace_is_initialized(struct dc_link *link);
2350 
2351 /* Query a dp trace flag to indicate if the current dp trace data has been
2352  * logged before
2353  */
2354 bool dc_dp_trace_is_logged(struct dc_link *link,
2355 		bool in_detection);
2356 
2357 /* Set dp trace flag to indicate whether DM has already logged the current dp
2358  * trace data. DM can set is_logged to true upon logging and check
2359  * dc_dp_trace_is_logged before logging to avoid logging the same result twice.
2360  */
2361 void dc_dp_trace_set_is_logged_flag(struct dc_link *link,
2362 		bool in_detection,
2363 		bool is_logged);
2364 
2365 /* Obtain driver time stamp for last dp link training end. The time stamp is
2366  * formatted based on dm_get_timestamp DM function.
2367  * @in_detection - true to get link training end time stamp of last link
2368  * training in detection sequence. false to get link training end time stamp
2369  * of last link training in commit (dpms) sequence
2370  */
2371 unsigned long long dc_dp_trace_get_lt_end_timestamp(struct dc_link *link,
2372 		bool in_detection);
2373 
2374 /* Get how many link training attempts dc has done with latest sequence.
2375  * @in_detection - true to get link training count of last link
2376  * training in detection sequence. false to get link training count of last link
2377  * training in commit (dpms) sequence
2378  */
2379 const struct dp_trace_lt_counts *dc_dp_trace_get_lt_counts(struct dc_link *link,
2380 		bool in_detection);
2381 
2382 /* Get how many link loss has happened since last link training attempts */
2383 unsigned int dc_dp_trace_get_link_loss_count(struct dc_link *link);
2384 
2385 /*
2386  *  USB4 DPIA BW ALLOCATION PUBLIC FUNCTIONS
2387  */
2388 /*
2389  * Send a request from DP-Tx requesting to allocate BW remotely after
2390  * allocating it locally. This will get processed by CM and a CB function
2391  * will be called.
2392  *
2393  * @link: pointer to the dc_link struct instance
2394  * @req_bw: The requested bw in Kbyte to allocated
2395  *
2396  * return: none
2397  */
2398 void dc_link_set_usb4_req_bw_req(struct dc_link *link, int req_bw);
2399 
2400 /*
2401  * Handle the USB4 BW Allocation related functionality here:
2402  * Plug => Try to allocate max bw from timing parameters supported by the sink
2403  * Unplug => de-allocate bw
2404  *
2405  * @link: pointer to the dc_link struct instance
2406  * @peak_bw: Peak bw used by the link/sink
2407  *
2408  */
2409 void dc_link_dp_dpia_handle_usb4_bandwidth_allocation_for_link(
2410 		struct dc_link *link, int peak_bw);
2411 
2412 /*
2413  * Validate the BW of all the valid DPIA links to make sure it doesn't exceed
2414  * available BW for each host router
2415  *
2416  * @dc: pointer to dc struct
2417  * @stream: pointer to all possible streams
2418  * @count: number of valid DPIA streams
2419  *
2420  * return: TRUE if bw used by DPIAs doesn't exceed available BW else return FALSE
2421  */
2422 bool dc_link_dp_dpia_validate(struct dc *dc, const struct dc_stream_state *streams,
2423 		const unsigned int count);
2424 
2425 /* Sink Interfaces - A sink corresponds to a display output device */
2426 
2427 struct dc_container_id {
2428 	// 128bit GUID in binary form
2429 	unsigned char  guid[16];
2430 	// 8 byte port ID -> ELD.PortID
2431 	unsigned int   portId[2];
2432 	// 128bit GUID in binary formufacturer name -> ELD.ManufacturerName
2433 	unsigned short manufacturerName;
2434 	// 2 byte product code -> ELD.ProductCode
2435 	unsigned short productCode;
2436 };
2437 
2438 
2439 struct dc_sink_dsc_caps {
2440 	// 'true' if these are virtual DPCD's DSC caps (immediately upstream of sink in MST topology),
2441 	// 'false' if they are sink's DSC caps
2442 	bool is_virtual_dpcd_dsc;
2443 	// 'true' if MST topology supports DSC passthrough for sink
2444 	// 'false' if MST topology does not support DSC passthrough
2445 	bool is_dsc_passthrough_supported;
2446 	struct dsc_dec_dpcd_caps dsc_dec_caps;
2447 };
2448 
2449 struct dc_sink_hblank_expansion_caps {
2450 	// 'true' if these are virtual DPCD's HBlank expansion caps (immediately upstream of sink in MST topology),
2451 	// 'false' if they are sink's HBlank expansion caps
2452 	bool is_virtual_dpcd_hblank_expansion;
2453 	struct hblank_expansion_dpcd_caps dpcd_caps;
2454 };
2455 
2456 struct dc_sink_fec_caps {
2457 	bool is_rx_fec_supported;
2458 	bool is_topology_fec_supported;
2459 };
2460 
2461 struct scdc_caps {
2462 	union hdmi_scdc_manufacturer_OUI_data manufacturer_OUI;
2463 	union hdmi_scdc_device_id_data device_id;
2464 };
2465 
2466 /*
2467  * The sink structure contains EDID and other display device properties
2468  */
2469 struct dc_sink {
2470 	enum signal_type sink_signal;
2471 	struct dc_edid dc_edid; /* raw edid */
2472 	struct dc_edid_caps edid_caps; /* parse display caps */
2473 	struct dc_container_id *dc_container_id;
2474 	uint32_t dongle_max_pix_clk;
2475 	void *priv;
2476 	struct stereo_3d_features features_3d[TIMING_3D_FORMAT_MAX];
2477 	bool converter_disable_audio;
2478 
2479 	struct scdc_caps scdc_caps;
2480 	struct dc_sink_dsc_caps dsc_caps;
2481 	struct dc_sink_fec_caps fec_caps;
2482 	struct dc_sink_hblank_expansion_caps hblank_expansion_caps;
2483 
2484 	bool is_vsc_sdp_colorimetry_supported;
2485 
2486 	/* private to DC core */
2487 	struct dc_link *link;
2488 	struct dc_context *ctx;
2489 
2490 	uint32_t sink_id;
2491 
2492 	/* private to dc_sink.c */
2493 	// refcount must be the last member in dc_sink, since we want the
2494 	// sink structure to be logically cloneable up to (but not including)
2495 	// refcount
2496 	struct kref refcount;
2497 };
2498 
2499 void dc_sink_retain(struct dc_sink *sink);
2500 void dc_sink_release(struct dc_sink *sink);
2501 
2502 struct dc_sink_init_data {
2503 	enum signal_type sink_signal;
2504 	struct dc_link *link;
2505 	uint32_t dongle_max_pix_clk;
2506 	bool converter_disable_audio;
2507 };
2508 
2509 struct dc_sink *dc_sink_create(const struct dc_sink_init_data *init_params);
2510 
2511 /* Newer interfaces  */
2512 struct dc_cursor {
2513 	struct dc_plane_address address;
2514 	struct dc_cursor_attributes attributes;
2515 };
2516 
2517 
2518 /* Interrupt interfaces */
2519 enum dc_irq_source dc_interrupt_to_irq_source(
2520 		struct dc *dc,
2521 		uint32_t src_id,
2522 		uint32_t ext_id);
2523 bool dc_interrupt_set(struct dc *dc, enum dc_irq_source src, bool enable);
2524 void dc_interrupt_ack(struct dc *dc, enum dc_irq_source src);
2525 enum dc_irq_source dc_get_hpd_irq_source_at_index(
2526 		struct dc *dc, uint32_t link_index);
2527 
2528 void dc_notify_vsync_int_state(struct dc *dc, struct dc_stream_state *stream, bool enable);
2529 
2530 /* Power Interfaces */
2531 
2532 void dc_set_power_state(
2533 		struct dc *dc,
2534 		enum dc_acpi_cm_power_state power_state);
2535 void dc_resume(struct dc *dc);
2536 
2537 void dc_power_down_on_boot(struct dc *dc);
2538 
2539 /*
2540  * HDCP Interfaces
2541  */
2542 enum hdcp_message_status dc_process_hdcp_msg(
2543 		enum signal_type signal,
2544 		struct dc_link *link,
2545 		struct hdcp_protection_message *message_info);
2546 bool dc_is_dmcu_initialized(struct dc *dc);
2547 
2548 enum dc_status dc_set_clock(struct dc *dc, enum dc_clock_type clock_type, uint32_t clk_khz, uint32_t stepping);
2549 void dc_get_clock(struct dc *dc, enum dc_clock_type clock_type, struct dc_clock_config *clock_cfg);
2550 
2551 bool dc_is_plane_eligible_for_idle_optimizations(struct dc *dc,
2552 		unsigned int pitch,
2553 		unsigned int height,
2554 		enum surface_pixel_format format,
2555 		struct dc_cursor_attributes *cursor_attr);
2556 
2557 #define dc_allow_idle_optimizations(dc, allow) dc_allow_idle_optimizations_internal(dc, allow, __func__)
2558 #define dc_exit_ips_for_hw_access(dc) dc_exit_ips_for_hw_access_internal(dc, __func__)
2559 
2560 void dc_allow_idle_optimizations_internal(struct dc *dc, bool allow, const char *caller_name);
2561 void dc_exit_ips_for_hw_access_internal(struct dc *dc, const char *caller_name);
2562 bool dc_dmub_is_ips_idle_state(struct dc *dc);
2563 
2564 /* set min and max memory clock to lowest and highest DPM level, respectively */
2565 void dc_unlock_memory_clock_frequency(struct dc *dc);
2566 
2567 /* set min memory clock to the min required for current mode, max to maxDPM */
2568 void dc_lock_memory_clock_frequency(struct dc *dc);
2569 
2570 /* set soft max for memclk, to be used for AC/DC switching clock limitations */
2571 void dc_enable_dcmode_clk_limit(struct dc *dc, bool enable);
2572 
2573 /* cleanup on driver unload */
2574 void dc_hardware_release(struct dc *dc);
2575 
2576 /* disables fw based mclk switch */
2577 void dc_mclk_switch_using_fw_based_vblank_stretch_shut_down(struct dc *dc);
2578 
2579 bool dc_set_psr_allow_active(struct dc *dc, bool enable);
2580 
2581 bool dc_set_replay_allow_active(struct dc *dc, bool active);
2582 
2583 bool dc_set_ips_disable(struct dc *dc, unsigned int disable_ips);
2584 
2585 void dc_z10_restore(const struct dc *dc);
2586 void dc_z10_save_init(struct dc *dc);
2587 
2588 bool dc_is_dmub_outbox_supported(struct dc *dc);
2589 bool dc_enable_dmub_notifications(struct dc *dc);
2590 
2591 bool dc_abm_save_restore(
2592 		struct dc *dc,
2593 		struct dc_stream_state *stream,
2594 		struct abm_save_restore *pData);
2595 
2596 void dc_enable_dmub_outbox(struct dc *dc);
2597 
2598 bool dc_process_dmub_aux_transfer_async(struct dc *dc,
2599 				uint32_t link_index,
2600 				struct aux_payload *payload);
2601 
2602 /* Get dc link index from dpia port index */
2603 uint8_t get_link_index_from_dpia_port_index(const struct dc *dc,
2604 				uint8_t dpia_port_index);
2605 
2606 bool dc_process_dmub_set_config_async(struct dc *dc,
2607 				uint32_t link_index,
2608 				struct set_config_cmd_payload *payload,
2609 				struct dmub_notification *notify);
2610 
2611 enum dc_status dc_process_dmub_set_mst_slots(const struct dc *dc,
2612 				uint32_t link_index,
2613 				uint8_t mst_alloc_slots,
2614 				uint8_t *mst_slots_in_use);
2615 
2616 void dc_process_dmub_dpia_set_tps_notification(const struct dc *dc, uint32_t link_index, uint8_t tps);
2617 
2618 void dc_process_dmub_dpia_hpd_int_enable(const struct dc *dc,
2619 				uint32_t hpd_int_enable);
2620 
2621 void dc_print_dmub_diagnostic_data(const struct dc *dc);
2622 
2623 void dc_query_current_properties(struct dc *dc, struct dc_current_properties *properties);
2624 
2625 struct dc_power_profile {
2626 	int power_level; /* Lower is better */
2627 };
2628 
2629 struct dc_power_profile dc_get_power_profile_for_dc_state(const struct dc_state *context);
2630 
2631 unsigned int dc_get_det_buffer_size_from_state(const struct dc_state *context);
2632 
2633 bool dc_get_host_router_index(const struct dc_link *link, unsigned int *host_router_index);
2634 
2635 /* DSC Interfaces */
2636 #include "dc_dsc.h"
2637 
2638 void dc_get_visual_confirm_for_stream(
2639 	struct dc *dc,
2640 	struct dc_stream_state *stream_state,
2641 	struct tg_color *color);
2642 
2643 /* Disable acc mode Interfaces */
2644 void dc_disable_accelerated_mode(struct dc *dc);
2645 
2646 bool dc_is_timing_changed(struct dc_stream_state *cur_stream,
2647 		       struct dc_stream_state *new_stream);
2648 
2649 bool dc_is_cursor_limit_pending(struct dc *dc);
2650 bool dc_can_clear_cursor_limit(struct dc *dc);
2651 
2652 #endif /* DC_INTERFACE_H_ */
2653