xref: /openbmc/linux/drivers/gpu/drm/amd/display/dc/dc.h (revision 165f2d28)
1 /*
2  * Copyright 2012-14 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 "grph_object_defs.h"
31 #include "logger_types.h"
32 #include "gpio_types.h"
33 #include "link_service_types.h"
34 #include "grph_object_ctrl_defs.h"
35 #include <inc/hw/opp.h>
36 
37 #include "inc/hw_sequencer.h"
38 #include "inc/compressor.h"
39 #include "inc/hw/dmcu.h"
40 #include "dml/display_mode_lib.h"
41 
42 #define DC_VER "3.2.76"
43 
44 #define MAX_SURFACES 3
45 #define MAX_PLANES 6
46 #define MAX_STREAMS 6
47 #define MAX_SINKS_PER_LINK 4
48 
49 /*******************************************************************************
50  * Display Core Interfaces
51  ******************************************************************************/
52 struct dc_versions {
53 	const char *dc_ver;
54 	struct dmcu_version dmcu_version;
55 };
56 
57 enum dp_protocol_version {
58 	DP_VERSION_1_4,
59 };
60 
61 enum dc_plane_type {
62 	DC_PLANE_TYPE_INVALID,
63 	DC_PLANE_TYPE_DCE_RGB,
64 	DC_PLANE_TYPE_DCE_UNDERLAY,
65 	DC_PLANE_TYPE_DCN_UNIVERSAL,
66 };
67 
68 struct dc_plane_cap {
69 	enum dc_plane_type type;
70 	uint32_t blends_with_above : 1;
71 	uint32_t blends_with_below : 1;
72 	uint32_t per_pixel_alpha : 1;
73 	struct {
74 		uint32_t argb8888 : 1;
75 		uint32_t nv12 : 1;
76 		uint32_t fp16 : 1;
77 		uint32_t p010 : 1;
78 		uint32_t ayuv : 1;
79 	} pixel_format_support;
80 	// max upscaling factor x1000
81 	// upscaling factors are always >= 1
82 	// for example, 1080p -> 8K is 4.0, or 4000 raw value
83 	struct {
84 		uint32_t argb8888;
85 		uint32_t nv12;
86 		uint32_t fp16;
87 	} max_upscale_factor;
88 	// max downscale factor x1000
89 	// downscale factors are always <= 1
90 	// for example, 8K -> 1080p is 0.25, or 250 raw value
91 	struct {
92 		uint32_t argb8888;
93 		uint32_t nv12;
94 		uint32_t fp16;
95 	} max_downscale_factor;
96 };
97 
98 struct dc_caps {
99 	uint32_t max_streams;
100 	uint32_t max_links;
101 	uint32_t max_audios;
102 	uint32_t max_slave_planes;
103 	uint32_t max_planes;
104 	uint32_t max_downscale_ratio;
105 	uint32_t i2c_speed_in_khz;
106 	uint32_t dmdata_alloc_size;
107 	unsigned int max_cursor_size;
108 	unsigned int max_video_width;
109 	int linear_pitch_alignment;
110 	bool dcc_const_color;
111 	bool dynamic_audio;
112 	bool is_apu;
113 	bool dual_link_dvi;
114 	bool post_blend_color_processing;
115 	bool force_dp_tps4_for_cp2520;
116 	bool disable_dp_clk_share;
117 	bool psp_setup_panel_mode;
118 	bool extended_aux_timeout_support;
119 	bool dmcub_support;
120 	bool hw_3d_lut;
121 	enum dp_protocol_version max_dp_protocol_version;
122 	struct dc_plane_cap planes[MAX_PLANES];
123 };
124 
125 struct dc_bug_wa {
126 	bool no_connect_phy_config;
127 	bool dedcn20_305_wa;
128 	bool skip_clock_update;
129 	bool lt_early_cr_pattern;
130 };
131 
132 struct dc_dcc_surface_param {
133 	struct dc_size surface_size;
134 	enum surface_pixel_format format;
135 	enum swizzle_mode_values swizzle_mode;
136 	enum dc_scan_direction scan;
137 };
138 
139 struct dc_dcc_setting {
140 	unsigned int max_compressed_blk_size;
141 	unsigned int max_uncompressed_blk_size;
142 	bool independent_64b_blks;
143 };
144 
145 struct dc_surface_dcc_cap {
146 	union {
147 		struct {
148 			struct dc_dcc_setting rgb;
149 		} grph;
150 
151 		struct {
152 			struct dc_dcc_setting luma;
153 			struct dc_dcc_setting chroma;
154 		} video;
155 	};
156 
157 	bool capable;
158 	bool const_color_support;
159 };
160 
161 struct dc_static_screen_params {
162 	struct {
163 		bool force_trigger;
164 		bool cursor_update;
165 		bool surface_update;
166 		bool overlay_update;
167 	} triggers;
168 	unsigned int num_frames;
169 };
170 
171 
172 /* Surface update type is used by dc_update_surfaces_and_stream
173  * The update type is determined at the very beginning of the function based
174  * on parameters passed in and decides how much programming (or updating) is
175  * going to be done during the call.
176  *
177  * UPDATE_TYPE_FAST is used for really fast updates that do not require much
178  * logical calculations or hardware register programming. This update MUST be
179  * ISR safe on windows. Currently fast update will only be used to flip surface
180  * address.
181  *
182  * UPDATE_TYPE_MED is used for slower updates which require significant hw
183  * re-programming however do not affect bandwidth consumption or clock
184  * requirements. At present, this is the level at which front end updates
185  * that do not require us to run bw_calcs happen. These are in/out transfer func
186  * updates, viewport offset changes, recout size changes and pixel depth changes.
187  * This update can be done at ISR, but we want to minimize how often this happens.
188  *
189  * UPDATE_TYPE_FULL is slow. Really slow. This requires us to recalculate our
190  * bandwidth and clocks, possibly rearrange some pipes and reprogram anything front
191  * end related. Any time viewport dimensions, recout dimensions, scaling ratios or
192  * gamma need to be adjusted or pipe needs to be turned on (or disconnected) we do
193  * a full update. This cannot be done at ISR level and should be a rare event.
194  * Unless someone is stress testing mpo enter/exit, playing with colour or adjusting
195  * underscan we don't expect to see this call at all.
196  */
197 
198 enum surface_update_type {
199 	UPDATE_TYPE_FAST, /* super fast, safe to execute in isr */
200 	UPDATE_TYPE_MED,  /* ISR safe, most of programming needed, no bw/clk change*/
201 	UPDATE_TYPE_FULL, /* may need to shuffle resources */
202 };
203 
204 /* Forward declaration*/
205 struct dc;
206 struct dc_plane_state;
207 struct dc_state;
208 
209 
210 struct dc_cap_funcs {
211 	bool (*get_dcc_compression_cap)(const struct dc *dc,
212 			const struct dc_dcc_surface_param *input,
213 			struct dc_surface_dcc_cap *output);
214 };
215 
216 struct link_training_settings;
217 
218 
219 /* Structure to hold configuration flags set by dm at dc creation. */
220 struct dc_config {
221 	bool gpu_vm_support;
222 	bool disable_disp_pll_sharing;
223 	bool fbc_support;
224 	bool optimize_edp_link_rate;
225 	bool disable_fractional_pwm;
226 	bool allow_seamless_boot_optimization;
227 	bool power_down_display_on_boot;
228 	bool edp_not_connected;
229 	bool force_enum_edp;
230 	bool forced_clocks;
231 	bool disable_extended_timeout_support; // Used to disable extended timeout and lttpr feature as well
232 	bool multi_mon_pp_mclk_switch;
233 	bool psr_on_dmub;
234 };
235 
236 enum visual_confirm {
237 	VISUAL_CONFIRM_DISABLE = 0,
238 	VISUAL_CONFIRM_SURFACE = 1,
239 	VISUAL_CONFIRM_HDR = 2,
240 	VISUAL_CONFIRM_MPCTREE = 4,
241 };
242 
243 enum dcc_option {
244 	DCC_ENABLE = 0,
245 	DCC_DISABLE = 1,
246 	DCC_HALF_REQ_DISALBE = 2,
247 };
248 
249 enum pipe_split_policy {
250 	MPC_SPLIT_DYNAMIC = 0,
251 	MPC_SPLIT_AVOID = 1,
252 	MPC_SPLIT_AVOID_MULT_DISP = 2,
253 };
254 
255 enum wm_report_mode {
256 	WM_REPORT_DEFAULT = 0,
257 	WM_REPORT_OVERRIDE = 1,
258 };
259 enum dtm_pstate{
260 	dtm_level_p0 = 0,/*highest voltage*/
261 	dtm_level_p1,
262 	dtm_level_p2,
263 	dtm_level_p3,
264 	dtm_level_p4,/*when active_display_count = 0*/
265 };
266 
267 enum dcn_pwr_state {
268 	DCN_PWR_STATE_UNKNOWN = -1,
269 	DCN_PWR_STATE_MISSION_MODE = 0,
270 	DCN_PWR_STATE_LOW_POWER = 3,
271 };
272 
273 /*
274  * For any clocks that may differ per pipe
275  * only the max is stored in this structure
276  */
277 struct dc_clocks {
278 	int dispclk_khz;
279 	int dppclk_khz;
280 	int dcfclk_khz;
281 	int socclk_khz;
282 	int dcfclk_deep_sleep_khz;
283 	int fclk_khz;
284 	int phyclk_khz;
285 	int dramclk_khz;
286 	bool p_state_change_support;
287 	enum dcn_pwr_state pwr_state;
288 	/*
289 	 * Elements below are not compared for the purposes of
290 	 * optimization required
291 	 */
292 	bool prev_p_state_change_support;
293 	enum dtm_pstate dtm_level;
294 	int max_supported_dppclk_khz;
295 	int max_supported_dispclk_khz;
296 	int bw_dppclk_khz; /*a copy of dppclk_khz*/
297 	int bw_dispclk_khz;
298 };
299 
300 struct dc_bw_validation_profile {
301 	bool enable;
302 
303 	unsigned long long total_ticks;
304 	unsigned long long voltage_level_ticks;
305 	unsigned long long watermark_ticks;
306 	unsigned long long rq_dlg_ticks;
307 
308 	unsigned long long total_count;
309 	unsigned long long skip_fast_count;
310 	unsigned long long skip_pass_count;
311 	unsigned long long skip_fail_count;
312 };
313 
314 #define BW_VAL_TRACE_SETUP() \
315 		unsigned long long end_tick = 0; \
316 		unsigned long long voltage_level_tick = 0; \
317 		unsigned long long watermark_tick = 0; \
318 		unsigned long long start_tick = dc->debug.bw_val_profile.enable ? \
319 				dm_get_timestamp(dc->ctx) : 0
320 
321 #define BW_VAL_TRACE_COUNT() \
322 		if (dc->debug.bw_val_profile.enable) \
323 			dc->debug.bw_val_profile.total_count++
324 
325 #define BW_VAL_TRACE_SKIP(status) \
326 		if (dc->debug.bw_val_profile.enable) { \
327 			if (!voltage_level_tick) \
328 				voltage_level_tick = dm_get_timestamp(dc->ctx); \
329 			dc->debug.bw_val_profile.skip_ ## status ## _count++; \
330 		}
331 
332 #define BW_VAL_TRACE_END_VOLTAGE_LEVEL() \
333 		if (dc->debug.bw_val_profile.enable) \
334 			voltage_level_tick = dm_get_timestamp(dc->ctx)
335 
336 #define BW_VAL_TRACE_END_WATERMARKS() \
337 		if (dc->debug.bw_val_profile.enable) \
338 			watermark_tick = dm_get_timestamp(dc->ctx)
339 
340 #define BW_VAL_TRACE_FINISH() \
341 		if (dc->debug.bw_val_profile.enable) { \
342 			end_tick = dm_get_timestamp(dc->ctx); \
343 			dc->debug.bw_val_profile.total_ticks += end_tick - start_tick; \
344 			dc->debug.bw_val_profile.voltage_level_ticks += voltage_level_tick - start_tick; \
345 			if (watermark_tick) { \
346 				dc->debug.bw_val_profile.watermark_ticks += watermark_tick - voltage_level_tick; \
347 				dc->debug.bw_val_profile.rq_dlg_ticks += end_tick - watermark_tick; \
348 			} \
349 		}
350 
351 struct dc_debug_options {
352 	enum visual_confirm visual_confirm;
353 	bool sanity_checks;
354 	bool max_disp_clk;
355 	bool surface_trace;
356 	bool timing_trace;
357 	bool clock_trace;
358 	bool validation_trace;
359 	bool bandwidth_calcs_trace;
360 	int max_downscale_src_width;
361 
362 	/* stutter efficiency related */
363 	bool disable_stutter;
364 	bool use_max_lb;
365 	enum dcc_option disable_dcc;
366 	enum pipe_split_policy pipe_split_policy;
367 	bool force_single_disp_pipe_split;
368 	bool voltage_align_fclk;
369 
370 	bool disable_dfs_bypass;
371 	bool disable_dpp_power_gate;
372 	bool disable_hubp_power_gate;
373 	bool disable_dsc_power_gate;
374 	int dsc_min_slice_height_override;
375 	int dsc_bpp_increment_div;
376 	bool native422_support;
377 	bool disable_pplib_wm_range;
378 	enum wm_report_mode pplib_wm_report_mode;
379 	unsigned int min_disp_clk_khz;
380 	unsigned int min_dpp_clk_khz;
381 	int sr_exit_time_dpm0_ns;
382 	int sr_enter_plus_exit_time_dpm0_ns;
383 	int sr_exit_time_ns;
384 	int sr_enter_plus_exit_time_ns;
385 	int urgent_latency_ns;
386 	uint32_t underflow_assert_delay_us;
387 	int percent_of_ideal_drambw;
388 	int dram_clock_change_latency_ns;
389 	bool optimized_watermark;
390 	int always_scale;
391 	bool disable_pplib_clock_request;
392 	bool disable_clock_gate;
393 	bool disable_mem_low_power;
394 	bool disable_dmcu;
395 	bool disable_psr;
396 	bool force_abm_enable;
397 	bool disable_stereo_support;
398 	bool vsr_support;
399 	bool performance_trace;
400 	bool az_endpoint_mute_only;
401 	bool always_use_regamma;
402 	bool p010_mpo_support;
403 	bool recovery_enabled;
404 	bool avoid_vbios_exec_table;
405 	bool scl_reset_length10;
406 	bool hdmi20_disable;
407 	bool skip_detection_link_training;
408 	bool remove_disconnect_edp;
409 	unsigned int force_odm_combine; //bit vector based on otg inst
410 	unsigned int force_fclk_khz;
411 	bool disable_tri_buf;
412 	bool dmub_offload_enabled;
413 	bool dmcub_emulation;
414 	bool dmub_command_table; /* for testing only */
415 	struct dc_bw_validation_profile bw_val_profile;
416 	bool disable_fec;
417 	bool disable_48mhz_pwrdwn;
418 	/* This forces a hard min on the DCFCLK requested to SMU/PP
419 	 * watermarks are not affected.
420 	 */
421 	unsigned int force_min_dcfclk_mhz;
422 	bool disable_timing_sync;
423 	bool cm_in_bypass;
424 	int force_clock_mode;/*every mode change.*/
425 
426 	bool nv12_iflip_vm_wa;
427 	bool disable_dram_clock_change_vactive_support;
428 	bool validate_dml_output;
429 	bool enable_dmcub_surface_flip;
430 	bool usbc_combo_phy_reset_wa;
431 	bool disable_dsc;
432 };
433 
434 struct dc_debug_data {
435 	uint32_t ltFailCount;
436 	uint32_t i2cErrorCount;
437 	uint32_t auxErrorCount;
438 };
439 
440 struct dc_phy_addr_space_config {
441 	struct {
442 		uint64_t start_addr;
443 		uint64_t end_addr;
444 		uint64_t fb_top;
445 		uint64_t fb_offset;
446 		uint64_t fb_base;
447 		uint64_t agp_top;
448 		uint64_t agp_bot;
449 		uint64_t agp_base;
450 	} system_aperture;
451 
452 	struct {
453 		uint64_t page_table_start_addr;
454 		uint64_t page_table_end_addr;
455 		uint64_t page_table_base_addr;
456 	} gart_config;
457 
458 	bool valid;
459 	bool is_hvm_enabled;
460 	uint64_t page_table_default_page_addr;
461 };
462 
463 struct dc_virtual_addr_space_config {
464 	uint64_t	page_table_base_addr;
465 	uint64_t	page_table_start_addr;
466 	uint64_t	page_table_end_addr;
467 	uint32_t	page_table_block_size_in_bytes;
468 	uint8_t		page_table_depth; // 1 = 1 level, 2 = 2 level, etc.  0 = invalid
469 };
470 
471 struct dc_bounding_box_overrides {
472 	int sr_exit_time_ns;
473 	int sr_enter_plus_exit_time_ns;
474 	int urgent_latency_ns;
475 	int percent_of_ideal_drambw;
476 	int dram_clock_change_latency_ns;
477 	/* This forces a hard min on the DCFCLK we use
478 	 * for DML.  Unlike the debug option for forcing
479 	 * DCFCLK, this override affects watermark calculations
480 	 */
481 	int min_dcfclk_mhz;
482 };
483 
484 struct dc_state;
485 struct resource_pool;
486 struct dce_hwseq;
487 struct gpu_info_soc_bounding_box_v1_0;
488 struct dc {
489 	struct dc_versions versions;
490 	struct dc_caps caps;
491 	struct dc_cap_funcs cap_funcs;
492 	struct dc_config config;
493 	struct dc_debug_options debug;
494 	struct dc_bounding_box_overrides bb_overrides;
495 	struct dc_bug_wa work_arounds;
496 	struct dc_context *ctx;
497 	struct dc_phy_addr_space_config vm_pa_config;
498 
499 	uint8_t link_count;
500 	struct dc_link *links[MAX_PIPES * 2];
501 
502 	struct dc_state *current_state;
503 	struct resource_pool *res_pool;
504 
505 	struct clk_mgr *clk_mgr;
506 
507 	/* Display Engine Clock levels */
508 	struct dm_pp_clock_levels sclk_lvls;
509 
510 	/* Inputs into BW and WM calculations. */
511 	struct bw_calcs_dceip *bw_dceip;
512 	struct bw_calcs_vbios *bw_vbios;
513 #ifdef CONFIG_DRM_AMD_DC_DCN
514 	struct dcn_soc_bounding_box *dcn_soc;
515 	struct dcn_ip_params *dcn_ip;
516 	struct display_mode_lib dml;
517 #endif
518 
519 	/* HW functions */
520 	struct hw_sequencer_funcs hwss;
521 	struct dce_hwseq *hwseq;
522 
523 	/* Require to optimize clocks and bandwidth for added/removed planes */
524 	bool optimized_required;
525 	bool wm_optimized_required;
526 
527 	/* Require to maintain clocks and bandwidth for UEFI enabled HW */
528 	int optimize_seamless_boot_streams;
529 
530 	/* FBC compressor */
531 	struct compressor *fbc_compressor;
532 
533 	struct dc_debug_data debug_data;
534 	struct dpcd_vendor_signature vendor_signature;
535 
536 	const char *build_id;
537 	struct vm_helper *vm_helper;
538 	const struct gpu_info_soc_bounding_box_v1_0 *soc_bounding_box;
539 };
540 
541 enum frame_buffer_mode {
542 	FRAME_BUFFER_MODE_LOCAL_ONLY = 0,
543 	FRAME_BUFFER_MODE_ZFB_ONLY,
544 	FRAME_BUFFER_MODE_MIXED_ZFB_AND_LOCAL,
545 } ;
546 
547 struct dchub_init_data {
548 	int64_t zfb_phys_addr_base;
549 	int64_t zfb_mc_base_addr;
550 	uint64_t zfb_size_in_byte;
551 	enum frame_buffer_mode fb_mode;
552 	bool dchub_initialzied;
553 	bool dchub_info_valid;
554 };
555 
556 struct dc_init_data {
557 	struct hw_asic_id asic_id;
558 	void *driver; /* ctx */
559 	struct cgs_device *cgs_device;
560 	struct dc_bounding_box_overrides bb_overrides;
561 
562 	int num_virtual_links;
563 	/*
564 	 * If 'vbios_override' not NULL, it will be called instead
565 	 * of the real VBIOS. Intended use is Diagnostics on FPGA.
566 	 */
567 	struct dc_bios *vbios_override;
568 	enum dce_environment dce_environment;
569 
570 	struct dmub_offload_funcs *dmub_if;
571 	struct dc_reg_helper_state *dmub_offload;
572 
573 	struct dc_config flags;
574 	uint64_t log_mask;
575 
576 	/**
577 	 * gpu_info FW provided soc bounding box struct or 0 if not
578 	 * available in FW
579 	 */
580 	const struct gpu_info_soc_bounding_box_v1_0 *soc_bounding_box;
581 	struct dpcd_vendor_signature vendor_signature;
582 };
583 
584 struct dc_callback_init {
585 #ifdef CONFIG_DRM_AMD_DC_HDCP
586 	struct cp_psp cp_psp;
587 #else
588 	uint8_t reserved;
589 #endif
590 };
591 
592 struct dc *dc_create(const struct dc_init_data *init_params);
593 void dc_hardware_init(struct dc *dc);
594 
595 int dc_get_vmid_use_vector(struct dc *dc);
596 void dc_setup_vm_context(struct dc *dc, struct dc_virtual_addr_space_config *va_config, int vmid);
597 /* Returns the number of vmids supported */
598 int dc_setup_system_context(struct dc *dc, struct dc_phy_addr_space_config *pa_config);
599 void dc_init_callbacks(struct dc *dc,
600 		const struct dc_callback_init *init_params);
601 void dc_deinit_callbacks(struct dc *dc);
602 void dc_destroy(struct dc **dc);
603 
604 /*******************************************************************************
605  * Surface Interfaces
606  ******************************************************************************/
607 
608 enum {
609 	TRANSFER_FUNC_POINTS = 1025
610 };
611 
612 struct dc_hdr_static_metadata {
613 	/* display chromaticities and white point in units of 0.00001 */
614 	unsigned int chromaticity_green_x;
615 	unsigned int chromaticity_green_y;
616 	unsigned int chromaticity_blue_x;
617 	unsigned int chromaticity_blue_y;
618 	unsigned int chromaticity_red_x;
619 	unsigned int chromaticity_red_y;
620 	unsigned int chromaticity_white_point_x;
621 	unsigned int chromaticity_white_point_y;
622 
623 	uint32_t min_luminance;
624 	uint32_t max_luminance;
625 	uint32_t maximum_content_light_level;
626 	uint32_t maximum_frame_average_light_level;
627 };
628 
629 enum dc_transfer_func_type {
630 	TF_TYPE_PREDEFINED,
631 	TF_TYPE_DISTRIBUTED_POINTS,
632 	TF_TYPE_BYPASS,
633 	TF_TYPE_HWPWL
634 };
635 
636 struct dc_transfer_func_distributed_points {
637 	struct fixed31_32 red[TRANSFER_FUNC_POINTS];
638 	struct fixed31_32 green[TRANSFER_FUNC_POINTS];
639 	struct fixed31_32 blue[TRANSFER_FUNC_POINTS];
640 
641 	uint16_t end_exponent;
642 	uint16_t x_point_at_y1_red;
643 	uint16_t x_point_at_y1_green;
644 	uint16_t x_point_at_y1_blue;
645 };
646 
647 enum dc_transfer_func_predefined {
648 	TRANSFER_FUNCTION_SRGB,
649 	TRANSFER_FUNCTION_BT709,
650 	TRANSFER_FUNCTION_PQ,
651 	TRANSFER_FUNCTION_LINEAR,
652 	TRANSFER_FUNCTION_UNITY,
653 	TRANSFER_FUNCTION_HLG,
654 	TRANSFER_FUNCTION_HLG12,
655 	TRANSFER_FUNCTION_GAMMA22,
656 	TRANSFER_FUNCTION_GAMMA24,
657 	TRANSFER_FUNCTION_GAMMA26
658 };
659 
660 
661 struct dc_transfer_func {
662 	struct kref refcount;
663 	enum dc_transfer_func_type type;
664 	enum dc_transfer_func_predefined tf;
665 	/* FP16 1.0 reference level in nits, default is 80 nits, only for PQ*/
666 	uint32_t sdr_ref_white_level;
667 	struct dc_context *ctx;
668 	union {
669 		struct pwl_params pwl;
670 		struct dc_transfer_func_distributed_points tf_pts;
671 	};
672 };
673 
674 
675 union dc_3dlut_state {
676 	struct {
677 		uint32_t initialized:1;		/*if 3dlut is went through color module for initialization */
678 		uint32_t rmu_idx_valid:1;	/*if mux settings are valid*/
679 		uint32_t rmu_mux_num:3;		/*index of mux to use*/
680 		uint32_t mpc_rmu0_mux:4;	/*select mpcc on mux, one of the following : mpcc0, mpcc1, mpcc2, mpcc3*/
681 		uint32_t mpc_rmu1_mux:4;
682 		uint32_t mpc_rmu2_mux:4;
683 		uint32_t reserved:15;
684 	} bits;
685 	uint32_t raw;
686 };
687 
688 
689 struct dc_3dlut {
690 	struct kref refcount;
691 	struct tetrahedral_params lut_3d;
692 	struct fixed31_32 hdr_multiplier;
693 	union dc_3dlut_state state;
694 	struct dc_context *ctx;
695 };
696 /*
697  * This structure is filled in by dc_surface_get_status and contains
698  * the last requested address and the currently active address so the called
699  * can determine if there are any outstanding flips
700  */
701 struct dc_plane_status {
702 	struct dc_plane_address requested_address;
703 	struct dc_plane_address current_address;
704 	bool is_flip_pending;
705 	bool is_right_eye;
706 };
707 
708 union surface_update_flags {
709 
710 	struct {
711 		uint32_t addr_update:1;
712 		/* Medium updates */
713 		uint32_t dcc_change:1;
714 		uint32_t color_space_change:1;
715 		uint32_t horizontal_mirror_change:1;
716 		uint32_t per_pixel_alpha_change:1;
717 		uint32_t global_alpha_change:1;
718 		uint32_t hdr_mult:1;
719 		uint32_t rotation_change:1;
720 		uint32_t swizzle_change:1;
721 		uint32_t scaling_change:1;
722 		uint32_t position_change:1;
723 		uint32_t in_transfer_func_change:1;
724 		uint32_t input_csc_change:1;
725 		uint32_t coeff_reduction_change:1;
726 		uint32_t output_tf_change:1;
727 		uint32_t pixel_format_change:1;
728 		uint32_t plane_size_change:1;
729 		uint32_t gamut_remap_change:1;
730 
731 		/* Full updates */
732 		uint32_t new_plane:1;
733 		uint32_t bpp_change:1;
734 		uint32_t gamma_change:1;
735 		uint32_t bandwidth_change:1;
736 		uint32_t clock_change:1;
737 		uint32_t stereo_format_change:1;
738 		uint32_t full_update:1;
739 	} bits;
740 
741 	uint32_t raw;
742 };
743 
744 struct dc_plane_state {
745 	struct dc_plane_address address;
746 	struct dc_plane_flip_time time;
747 	bool triplebuffer_flips;
748 	struct scaling_taps scaling_quality;
749 	struct rect src_rect;
750 	struct rect dst_rect;
751 	struct rect clip_rect;
752 
753 	struct plane_size plane_size;
754 	union dc_tiling_info tiling_info;
755 
756 	struct dc_plane_dcc_param dcc;
757 
758 	struct dc_gamma *gamma_correction;
759 	struct dc_transfer_func *in_transfer_func;
760 	struct dc_bias_and_scale *bias_and_scale;
761 	struct dc_csc_transform input_csc_color_matrix;
762 	struct fixed31_32 coeff_reduction_factor;
763 	struct fixed31_32 hdr_mult;
764 	struct colorspace_transform gamut_remap_matrix;
765 
766 	// TODO: No longer used, remove
767 	struct dc_hdr_static_metadata hdr_static_ctx;
768 
769 	enum dc_color_space color_space;
770 
771 	struct dc_3dlut *lut3d_func;
772 	struct dc_transfer_func *in_shaper_func;
773 	struct dc_transfer_func *blend_tf;
774 
775 	enum surface_pixel_format format;
776 	enum dc_rotation_angle rotation;
777 	enum plane_stereo_format stereo_format;
778 
779 	bool is_tiling_rotated;
780 	bool per_pixel_alpha;
781 	bool global_alpha;
782 	int  global_alpha_value;
783 	bool visible;
784 	bool flip_immediate;
785 	bool horizontal_mirror;
786 	int layer_index;
787 
788 	union surface_update_flags update_flags;
789 	/* private to DC core */
790 	struct dc_plane_status status;
791 	struct dc_context *ctx;
792 
793 	/* HACK: Workaround for forcing full reprogramming under some conditions */
794 	bool force_full_update;
795 
796 	/* private to dc_surface.c */
797 	enum dc_irq_source irq_source;
798 	struct kref refcount;
799 };
800 
801 struct dc_plane_info {
802 	struct plane_size plane_size;
803 	union dc_tiling_info tiling_info;
804 	struct dc_plane_dcc_param dcc;
805 	enum surface_pixel_format format;
806 	enum dc_rotation_angle rotation;
807 	enum plane_stereo_format stereo_format;
808 	enum dc_color_space color_space;
809 	bool horizontal_mirror;
810 	bool visible;
811 	bool per_pixel_alpha;
812 	bool global_alpha;
813 	int  global_alpha_value;
814 	bool input_csc_enabled;
815 	int layer_index;
816 };
817 
818 struct dc_scaling_info {
819 	struct rect src_rect;
820 	struct rect dst_rect;
821 	struct rect clip_rect;
822 	struct scaling_taps scaling_quality;
823 };
824 
825 struct dc_surface_update {
826 	struct dc_plane_state *surface;
827 
828 	/* isr safe update parameters.  null means no updates */
829 	const struct dc_flip_addrs *flip_addr;
830 	const struct dc_plane_info *plane_info;
831 	const struct dc_scaling_info *scaling_info;
832 	struct fixed31_32 hdr_mult;
833 	/* following updates require alloc/sleep/spin that is not isr safe,
834 	 * null means no updates
835 	 */
836 	const struct dc_gamma *gamma;
837 	const struct dc_transfer_func *in_transfer_func;
838 
839 	const struct dc_csc_transform *input_csc_color_matrix;
840 	const struct fixed31_32 *coeff_reduction_factor;
841 	const struct dc_transfer_func *func_shaper;
842 	const struct dc_3dlut *lut3d_func;
843 	const struct dc_transfer_func *blend_tf;
844 	const struct colorspace_transform *gamut_remap_matrix;
845 };
846 
847 /*
848  * Create a new surface with default parameters;
849  */
850 struct dc_plane_state *dc_create_plane_state(struct dc *dc);
851 const struct dc_plane_status *dc_plane_get_status(
852 		const struct dc_plane_state *plane_state);
853 
854 void dc_plane_state_retain(struct dc_plane_state *plane_state);
855 void dc_plane_state_release(struct dc_plane_state *plane_state);
856 
857 void dc_gamma_retain(struct dc_gamma *dc_gamma);
858 void dc_gamma_release(struct dc_gamma **dc_gamma);
859 struct dc_gamma *dc_create_gamma(void);
860 
861 void dc_transfer_func_retain(struct dc_transfer_func *dc_tf);
862 void dc_transfer_func_release(struct dc_transfer_func *dc_tf);
863 struct dc_transfer_func *dc_create_transfer_func(void);
864 
865 struct dc_3dlut *dc_create_3dlut_func(void);
866 void dc_3dlut_func_release(struct dc_3dlut *lut);
867 void dc_3dlut_func_retain(struct dc_3dlut *lut);
868 /*
869  * This structure holds a surface address.  There could be multiple addresses
870  * in cases such as Stereo 3D, Planar YUV, etc.  Other per-flip attributes such
871  * as frame durations and DCC format can also be set.
872  */
873 struct dc_flip_addrs {
874 	struct dc_plane_address address;
875 	unsigned int flip_timestamp_in_us;
876 	bool flip_immediate;
877 	/* TODO: add flip duration for FreeSync */
878 	bool triplebuffer_flips;
879 };
880 
881 bool dc_post_update_surfaces_to_stream(
882 		struct dc *dc);
883 
884 #include "dc_stream.h"
885 
886 /*
887  * Structure to store surface/stream associations for validation
888  */
889 struct dc_validation_set {
890 	struct dc_stream_state *stream;
891 	struct dc_plane_state *plane_states[MAX_SURFACES];
892 	uint8_t plane_count;
893 };
894 
895 bool dc_validate_seamless_boot_timing(const struct dc *dc,
896 				const struct dc_sink *sink,
897 				struct dc_crtc_timing *crtc_timing);
898 
899 enum dc_status dc_validate_plane(struct dc *dc, const struct dc_plane_state *plane_state);
900 
901 void get_clock_requirements_for_state(struct dc_state *state, struct AsicStateEx *info);
902 
903 bool dc_set_generic_gpio_for_stereo(bool enable,
904 		struct gpio_service *gpio_service);
905 
906 /*
907  * fast_validate: we return after determining if we can support the new state,
908  * but before we populate the programming info
909  */
910 enum dc_status dc_validate_global_state(
911 		struct dc *dc,
912 		struct dc_state *new_ctx,
913 		bool fast_validate);
914 
915 
916 void dc_resource_state_construct(
917 		const struct dc *dc,
918 		struct dc_state *dst_ctx);
919 
920 void dc_resource_state_copy_construct(
921 		const struct dc_state *src_ctx,
922 		struct dc_state *dst_ctx);
923 
924 void dc_resource_state_copy_construct_current(
925 		const struct dc *dc,
926 		struct dc_state *dst_ctx);
927 
928 void dc_resource_state_destruct(struct dc_state *context);
929 
930 bool dc_resource_is_dsc_encoding_supported(const struct dc *dc);
931 
932 /*
933  * TODO update to make it about validation sets
934  * Set up streams and links associated to drive sinks
935  * The streams parameter is an absolute set of all active streams.
936  *
937  * After this call:
938  *   Phy, Encoder, Timing Generator are programmed and enabled.
939  *   New streams are enabled with blank stream; no memory read.
940  */
941 bool dc_commit_state(struct dc *dc, struct dc_state *context);
942 
943 
944 struct dc_state *dc_create_state(struct dc *dc);
945 struct dc_state *dc_copy_state(struct dc_state *src_ctx);
946 void dc_retain_state(struct dc_state *context);
947 void dc_release_state(struct dc_state *context);
948 
949 /*******************************************************************************
950  * Link Interfaces
951  ******************************************************************************/
952 
953 struct dpcd_caps {
954 	union dpcd_rev dpcd_rev;
955 	union max_lane_count max_ln_count;
956 	union max_down_spread max_down_spread;
957 	union dprx_feature dprx_feature;
958 
959 	/* valid only for eDP v1.4 or higher*/
960 	uint8_t edp_supported_link_rates_count;
961 	enum dc_link_rate edp_supported_link_rates[8];
962 
963 	/* dongle type (DP converter, CV smart dongle) */
964 	enum display_dongle_type dongle_type;
965 	/* branch device or sink device */
966 	bool is_branch_dev;
967 	/* Dongle's downstream count. */
968 	union sink_count sink_count;
969 	/* If dongle_type == DISPLAY_DONGLE_DP_HDMI_CONVERTER,
970 	indicates 'Frame Sequential-to-lllFrame Pack' conversion capability.*/
971 	struct dc_dongle_caps dongle_caps;
972 
973 	uint32_t sink_dev_id;
974 	int8_t sink_dev_id_str[6];
975 	int8_t sink_hw_revision;
976 	int8_t sink_fw_revision[2];
977 
978 	uint32_t branch_dev_id;
979 	int8_t branch_dev_name[6];
980 	int8_t branch_hw_revision;
981 	int8_t branch_fw_revision[2];
982 
983 	bool allow_invalid_MSA_timing_param;
984 	bool panel_mode_edp;
985 	bool dpcd_display_control_capable;
986 	bool ext_receiver_cap_field_present;
987 	union dpcd_fec_capability fec_cap;
988 	struct dpcd_dsc_capabilities dsc_caps;
989 	struct dc_lttpr_caps lttpr_caps;
990 
991 };
992 
993 union dpcd_sink_ext_caps {
994 	struct {
995 		/* 0 - Sink supports backlight adjust via PWM during SDR/HDR mode
996 		 * 1 - Sink supports backlight adjust via AUX during SDR/HDR mode.
997 		 */
998 		uint8_t sdr_aux_backlight_control : 1;
999 		uint8_t hdr_aux_backlight_control : 1;
1000 		uint8_t reserved_1 : 2;
1001 		uint8_t oled : 1;
1002 		uint8_t reserved : 3;
1003 	} bits;
1004 	uint8_t raw;
1005 };
1006 
1007 #include "dc_link.h"
1008 
1009 /*******************************************************************************
1010  * Sink Interfaces - A sink corresponds to a display output device
1011  ******************************************************************************/
1012 
1013 struct dc_container_id {
1014 	// 128bit GUID in binary form
1015 	unsigned char  guid[16];
1016 	// 8 byte port ID -> ELD.PortID
1017 	unsigned int   portId[2];
1018 	// 128bit GUID in binary formufacturer name -> ELD.ManufacturerName
1019 	unsigned short manufacturerName;
1020 	// 2 byte product code -> ELD.ProductCode
1021 	unsigned short productCode;
1022 };
1023 
1024 
1025 struct dc_sink_dsc_caps {
1026 	// 'true' if these are virtual DPCD's DSC caps (immediately upstream of sink in MST topology),
1027 	// 'false' if they are sink's DSC caps
1028 	bool is_virtual_dpcd_dsc;
1029 	struct dsc_dec_dpcd_caps dsc_dec_caps;
1030 };
1031 
1032 struct dc_sink_fec_caps {
1033 	bool is_rx_fec_supported;
1034 	bool is_topology_fec_supported;
1035 };
1036 
1037 /*
1038  * The sink structure contains EDID and other display device properties
1039  */
1040 struct dc_sink {
1041 	enum signal_type sink_signal;
1042 	struct dc_edid dc_edid; /* raw edid */
1043 	struct dc_edid_caps edid_caps; /* parse display caps */
1044 	struct dc_container_id *dc_container_id;
1045 	uint32_t dongle_max_pix_clk;
1046 	void *priv;
1047 	struct stereo_3d_features features_3d[TIMING_3D_FORMAT_MAX];
1048 	bool converter_disable_audio;
1049 
1050 	struct dc_sink_dsc_caps dsc_caps;
1051 	struct dc_sink_fec_caps fec_caps;
1052 
1053 	bool is_vsc_sdp_colorimetry_supported;
1054 
1055 	/* private to DC core */
1056 	struct dc_link *link;
1057 	struct dc_context *ctx;
1058 
1059 	uint32_t sink_id;
1060 
1061 	/* private to dc_sink.c */
1062 	// refcount must be the last member in dc_sink, since we want the
1063 	// sink structure to be logically cloneable up to (but not including)
1064 	// refcount
1065 	struct kref refcount;
1066 };
1067 
1068 void dc_sink_retain(struct dc_sink *sink);
1069 void dc_sink_release(struct dc_sink *sink);
1070 
1071 struct dc_sink_init_data {
1072 	enum signal_type sink_signal;
1073 	struct dc_link *link;
1074 	uint32_t dongle_max_pix_clk;
1075 	bool converter_disable_audio;
1076 };
1077 
1078 struct dc_sink *dc_sink_create(const struct dc_sink_init_data *init_params);
1079 
1080 /* Newer interfaces  */
1081 struct dc_cursor {
1082 	struct dc_plane_address address;
1083 	struct dc_cursor_attributes attributes;
1084 };
1085 
1086 
1087 /*******************************************************************************
1088  * Interrupt interfaces
1089  ******************************************************************************/
1090 enum dc_irq_source dc_interrupt_to_irq_source(
1091 		struct dc *dc,
1092 		uint32_t src_id,
1093 		uint32_t ext_id);
1094 bool dc_interrupt_set(struct dc *dc, enum dc_irq_source src, bool enable);
1095 void dc_interrupt_ack(struct dc *dc, enum dc_irq_source src);
1096 enum dc_irq_source dc_get_hpd_irq_source_at_index(
1097 		struct dc *dc, uint32_t link_index);
1098 
1099 /*******************************************************************************
1100  * Power Interfaces
1101  ******************************************************************************/
1102 
1103 void dc_set_power_state(
1104 		struct dc *dc,
1105 		enum dc_acpi_cm_power_state power_state);
1106 void dc_resume(struct dc *dc);
1107 unsigned int dc_get_current_backlight_pwm(struct dc *dc);
1108 unsigned int dc_get_target_backlight_pwm(struct dc *dc);
1109 
1110 bool dc_is_dmcu_initialized(struct dc *dc);
1111 
1112 enum dc_status dc_set_clock(struct dc *dc, enum dc_clock_type clock_type, uint32_t clk_khz, uint32_t stepping);
1113 void dc_get_clock(struct dc *dc, enum dc_clock_type clock_type, struct dc_clock_config *clock_cfg);
1114 /*******************************************************************************
1115  * DSC Interfaces
1116  ******************************************************************************/
1117 #include "dc_dsc.h"
1118 #endif /* DC_INTERFACE_H_ */
1119