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