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