drm/amd/display: Move dis_clk into dc_state.
[platform/kernel/linux-rpi.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 "dml/display_mode_lib.h"
40
41 #define DC_VER "3.1.01"
42
43 #define MAX_SURFACES 3
44 #define MAX_STREAMS 6
45 #define MAX_SINKS_PER_LINK 4
46
47
48 /*******************************************************************************
49  * Display Core Interfaces
50  ******************************************************************************/
51 struct dc_caps {
52         uint32_t max_streams;
53         uint32_t max_links;
54         uint32_t max_audios;
55         uint32_t max_slave_planes;
56         uint32_t max_planes;
57         uint32_t max_downscale_ratio;
58         uint32_t i2c_speed_in_khz;
59
60         unsigned int max_cursor_size;
61 };
62
63
64 struct dc_dcc_surface_param {
65         struct dc_size surface_size;
66         enum surface_pixel_format format;
67         enum swizzle_mode_values swizzle_mode;
68         enum dc_scan_direction scan;
69 };
70
71 struct dc_dcc_setting {
72         unsigned int max_compressed_blk_size;
73         unsigned int max_uncompressed_blk_size;
74         bool independent_64b_blks;
75 };
76
77 struct dc_surface_dcc_cap {
78         union {
79                 struct {
80                         struct dc_dcc_setting rgb;
81                 } grph;
82
83                 struct {
84                         struct dc_dcc_setting luma;
85                         struct dc_dcc_setting chroma;
86                 } video;
87         };
88
89         bool capable;
90         bool const_color_support;
91 };
92
93 struct dc_static_screen_events {
94         bool cursor_update;
95         bool surface_update;
96         bool overlay_update;
97 };
98
99 /* Forward declaration*/
100 struct dc;
101 struct dc_plane_state;
102 struct dc_state;
103
104 struct dc_cap_funcs {
105         bool (*get_dcc_compression_cap)(const struct dc *dc,
106                         const struct dc_dcc_surface_param *input,
107                         struct dc_surface_dcc_cap *output);
108 };
109
110 struct dc_stream_state_funcs {
111         bool (*adjust_vmin_vmax)(struct dc *dc,
112                         struct dc_stream_state **stream,
113                         int num_streams,
114                         int vmin,
115                         int vmax);
116         bool (*get_crtc_position)(struct dc *dc,
117                         struct dc_stream_state **stream,
118                         int num_streams,
119                         unsigned int *v_pos,
120                         unsigned int *nom_v_pos);
121
122         bool (*set_gamut_remap)(struct dc *dc,
123                         const struct dc_stream_state *stream);
124
125         bool (*program_csc_matrix)(struct dc *dc,
126                         struct dc_stream_state *stream);
127
128         void (*set_static_screen_events)(struct dc *dc,
129                         struct dc_stream_state **stream,
130                         int num_streams,
131                         const struct dc_static_screen_events *events);
132
133         void (*set_dither_option)(struct dc_stream_state *stream,
134                         enum dc_dither_option option);
135 };
136
137 struct link_training_settings;
138
139 struct dc_link_funcs {
140         void (*set_drive_settings)(struct dc *dc,
141                         struct link_training_settings *lt_settings,
142                         const struct dc_link *link);
143         void (*perform_link_training)(struct dc *dc,
144                         struct dc_link_settings *link_setting,
145                         bool skip_video_pattern);
146         void (*set_preferred_link_settings)(struct dc *dc,
147                         struct dc_link_settings *link_setting,
148                         struct dc_link *link);
149         void (*enable_hpd)(const struct dc_link *link);
150         void (*disable_hpd)(const struct dc_link *link);
151         void (*set_test_pattern)(
152                         struct dc_link *link,
153                         enum dp_test_pattern test_pattern,
154                         const struct link_training_settings *p_link_settings,
155                         const unsigned char *p_custom_pattern,
156                         unsigned int cust_pattern_size);
157 };
158
159 /* Structure to hold configuration flags set by dm at dc creation. */
160 struct dc_config {
161         bool gpu_vm_support;
162         bool disable_disp_pll_sharing;
163 };
164
165 struct dc_debug {
166         bool surface_visual_confirm;
167         bool sanity_checks;
168         bool max_disp_clk;
169         bool surface_trace;
170         bool timing_trace;
171         bool clock_trace;
172         bool validation_trace;
173         bool disable_stutter;
174         bool disable_dcc;
175         bool disable_dfs_bypass;
176         bool disable_dpp_power_gate;
177         bool disable_hubp_power_gate;
178         bool disable_pplib_wm_range;
179         bool use_dml_wm;
180         bool disable_pipe_split;
181         int sr_exit_time_dpm0_ns;
182         int sr_enter_plus_exit_time_dpm0_ns;
183         int sr_exit_time_ns;
184         int sr_enter_plus_exit_time_ns;
185         int urgent_latency_ns;
186         int percent_of_ideal_drambw;
187         int dram_clock_change_latency_ns;
188         int always_scale;
189         bool disable_pplib_clock_request;
190         bool disable_clock_gate;
191         bool disable_dmcu;
192         bool disable_psr;
193         bool force_abm_enable;
194 };
195 struct dc_state;
196 struct resource_pool;
197 struct dce_hwseq;
198 struct dc {
199         struct dc_caps caps;
200         struct dc_cap_funcs cap_funcs;
201         struct dc_stream_state_funcs stream_funcs;
202         struct dc_link_funcs link_funcs;
203         struct dc_config config;
204         struct dc_debug debug;
205
206         struct dc_context *ctx;
207
208         uint8_t link_count;
209         struct dc_link *links[MAX_PIPES * 2];
210
211         struct dc_state *current_state;
212         struct resource_pool *res_pool;
213
214         /* Display Engine Clock levels */
215         struct dm_pp_clock_levels sclk_lvls;
216
217         /* Inputs into BW and WM calculations. */
218         struct bw_calcs_dceip *bw_dceip;
219         struct bw_calcs_vbios *bw_vbios;
220 #ifdef CONFIG_DRM_AMD_DC_DCN1_0
221         struct dcn_soc_bounding_box *dcn_soc;
222         struct dcn_ip_params *dcn_ip;
223         struct display_mode_lib dml;
224 #endif
225
226         /* HW functions */
227         struct hw_sequencer_funcs hwss;
228         struct dce_hwseq *hwseq;
229
230         /* temp store of dm_pp_display_configuration
231          * to compare to see if display config changed
232          */
233         struct dm_pp_display_configuration prev_display_config;
234
235         /* FBC compressor */
236 #ifdef ENABLE_FBC
237         struct compressor *fbc_compressor;
238 #endif
239 };
240
241 enum frame_buffer_mode {
242         FRAME_BUFFER_MODE_LOCAL_ONLY = 0,
243         FRAME_BUFFER_MODE_ZFB_ONLY,
244         FRAME_BUFFER_MODE_MIXED_ZFB_AND_LOCAL,
245 } ;
246
247 struct dchub_init_data {
248         int64_t zfb_phys_addr_base;
249         int64_t zfb_mc_base_addr;
250         uint64_t zfb_size_in_byte;
251         enum frame_buffer_mode fb_mode;
252         bool dchub_initialzied;
253         bool dchub_info_valid;
254 };
255
256 struct dc_init_data {
257         struct hw_asic_id asic_id;
258         void *driver; /* ctx */
259         struct cgs_device *cgs_device;
260
261         int num_virtual_links;
262         /*
263          * If 'vbios_override' not NULL, it will be called instead
264          * of the real VBIOS. Intended use is Diagnostics on FPGA.
265          */
266         struct dc_bios *vbios_override;
267         enum dce_environment dce_environment;
268
269         struct dc_config flags;
270 #ifdef ENABLE_FBC
271         uint64_t fbc_gpu_addr;
272 #endif
273 };
274
275 struct dc *dc_create(const struct dc_init_data *init_params);
276
277 void dc_destroy(struct dc **dc);
278
279 bool dc_init_dchub(struct dc *dc, struct dchub_init_data *dh_data);
280
281 void dc_log_hw_state(struct dc *dc);
282
283 /*******************************************************************************
284  * Surface Interfaces
285  ******************************************************************************/
286
287 enum {
288         TRANSFER_FUNC_POINTS = 1025
289 };
290
291 struct dc_hdr_static_metadata {
292         /* display chromaticities and white point in units of 0.00001 */
293         unsigned int chromaticity_green_x;
294         unsigned int chromaticity_green_y;
295         unsigned int chromaticity_blue_x;
296         unsigned int chromaticity_blue_y;
297         unsigned int chromaticity_red_x;
298         unsigned int chromaticity_red_y;
299         unsigned int chromaticity_white_point_x;
300         unsigned int chromaticity_white_point_y;
301
302         uint32_t min_luminance;
303         uint32_t max_luminance;
304         uint32_t maximum_content_light_level;
305         uint32_t maximum_frame_average_light_level;
306
307         bool hdr_supported;
308         bool is_hdr;
309 };
310
311 enum dc_transfer_func_type {
312         TF_TYPE_PREDEFINED,
313         TF_TYPE_DISTRIBUTED_POINTS,
314         TF_TYPE_BYPASS
315 };
316
317 struct dc_transfer_func_distributed_points {
318         struct fixed31_32 red[TRANSFER_FUNC_POINTS];
319         struct fixed31_32 green[TRANSFER_FUNC_POINTS];
320         struct fixed31_32 blue[TRANSFER_FUNC_POINTS];
321
322         uint16_t end_exponent;
323         uint16_t x_point_at_y1_red;
324         uint16_t x_point_at_y1_green;
325         uint16_t x_point_at_y1_blue;
326 };
327
328 enum dc_transfer_func_predefined {
329         TRANSFER_FUNCTION_SRGB,
330         TRANSFER_FUNCTION_BT709,
331         TRANSFER_FUNCTION_PQ,
332         TRANSFER_FUNCTION_LINEAR,
333 };
334
335 struct dc_transfer_func {
336         struct dc_transfer_func_distributed_points tf_pts;
337         enum dc_transfer_func_type type;
338         enum dc_transfer_func_predefined tf;
339         struct dc_context *ctx;
340         atomic_t ref_count;
341 };
342
343 /*
344  * This structure is filled in by dc_surface_get_status and contains
345  * the last requested address and the currently active address so the called
346  * can determine if there are any outstanding flips
347  */
348 struct dc_plane_status {
349         struct dc_plane_address requested_address;
350         struct dc_plane_address current_address;
351         bool is_flip_pending;
352         bool is_right_eye;
353 };
354
355 struct dc_plane_state {
356         struct dc_plane_address address;
357         struct scaling_taps scaling_quality;
358         struct rect src_rect;
359         struct rect dst_rect;
360         struct rect clip_rect;
361
362         union plane_size plane_size;
363         union dc_tiling_info tiling_info;
364
365         struct dc_plane_dcc_param dcc;
366         struct dc_hdr_static_metadata hdr_static_ctx;
367
368         struct dc_gamma *gamma_correction;
369         struct dc_transfer_func *in_transfer_func;
370
371         enum dc_color_space color_space;
372         enum surface_pixel_format format;
373         enum dc_rotation_angle rotation;
374         enum plane_stereo_format stereo_format;
375
376         bool per_pixel_alpha;
377         bool visible;
378         bool flip_immediate;
379         bool horizontal_mirror;
380
381         /* private to DC core */
382         struct dc_plane_status status;
383         struct dc_context *ctx;
384
385         /* private to dc_surface.c */
386         enum dc_irq_source irq_source;
387         atomic_t ref_count;
388 };
389
390 struct dc_plane_info {
391         union plane_size plane_size;
392         union dc_tiling_info tiling_info;
393         struct dc_plane_dcc_param dcc;
394         enum surface_pixel_format format;
395         enum dc_rotation_angle rotation;
396         enum plane_stereo_format stereo_format;
397         enum dc_color_space color_space; /*todo: wrong place, fits in scaling info*/
398         bool horizontal_mirror;
399         bool visible;
400         bool per_pixel_alpha;
401 };
402
403 struct dc_scaling_info {
404         struct rect src_rect;
405         struct rect dst_rect;
406         struct rect clip_rect;
407         struct scaling_taps scaling_quality;
408 };
409
410 struct dc_surface_update {
411         struct dc_plane_state *surface;
412
413         /* isr safe update parameters.  null means no updates */
414         struct dc_flip_addrs *flip_addr;
415         struct dc_plane_info *plane_info;
416         struct dc_scaling_info *scaling_info;
417         /* following updates require alloc/sleep/spin that is not isr safe,
418          * null means no updates
419          */
420         /* gamma TO BE REMOVED */
421         struct dc_gamma *gamma;
422         struct dc_transfer_func *in_transfer_func;
423         struct dc_hdr_static_metadata *hdr_static_metadata;
424 };
425
426 /*
427  * Create a new surface with default parameters;
428  */
429 struct dc_plane_state *dc_create_plane_state(struct dc *dc);
430 const struct dc_plane_status *dc_plane_get_status(
431                 const struct dc_plane_state *plane_state);
432
433 void dc_plane_state_retain(struct dc_plane_state *plane_state);
434 void dc_plane_state_release(struct dc_plane_state *plane_state);
435
436 void dc_gamma_retain(struct dc_gamma *dc_gamma);
437 void dc_gamma_release(struct dc_gamma **dc_gamma);
438 struct dc_gamma *dc_create_gamma(void);
439
440 void dc_transfer_func_retain(struct dc_transfer_func *dc_tf);
441 void dc_transfer_func_release(struct dc_transfer_func *dc_tf);
442 struct dc_transfer_func *dc_create_transfer_func(void);
443
444 /*
445  * This structure holds a surface address.  There could be multiple addresses
446  * in cases such as Stereo 3D, Planar YUV, etc.  Other per-flip attributes such
447  * as frame durations and DCC format can also be set.
448  */
449 struct dc_flip_addrs {
450         struct dc_plane_address address;
451         bool flip_immediate;
452         /* TODO: add flip duration for FreeSync */
453 };
454
455 /*
456  * Set up surface attributes and associate to a stream
457  * The surfaces parameter is an absolute set of all surface active for the stream.
458  * If no surfaces are provided, the stream will be blanked; no memory read.
459  * Any flip related attribute changes must be done through this interface.
460  *
461  * After this call:
462  *   Surfaces attributes are programmed and configured to be composed into stream.
463  *   This does not trigger a flip.  No surface address is programmed.
464  */
465
466 bool dc_commit_planes_to_stream(
467                 struct dc *dc,
468                 struct dc_plane_state **plane_states,
469                 uint8_t new_plane_count,
470                 struct dc_stream_state *stream);
471
472 bool dc_post_update_surfaces_to_stream(
473                 struct dc *dc);
474
475 /* Surface update type is used by dc_update_surfaces_and_stream
476  * The update type is determined at the very beginning of the function based
477  * on parameters passed in and decides how much programming (or updating) is
478  * going to be done during the call.
479  *
480  * UPDATE_TYPE_FAST is used for really fast updates that do not require much
481  * logical calculations or hardware register programming. This update MUST be
482  * ISR safe on windows. Currently fast update will only be used to flip surface
483  * address.
484  *
485  * UPDATE_TYPE_MED is used for slower updates which require significant hw
486  * re-programming however do not affect bandwidth consumption or clock
487  * requirements. At present, this is the level at which front end updates
488  * that do not require us to run bw_calcs happen. These are in/out transfer func
489  * updates, viewport offset changes, recout size changes and pixel depth changes.
490  * This update can be done at ISR, but we want to minimize how often this happens.
491  *
492  * UPDATE_TYPE_FULL is slow. Really slow. This requires us to recalculate our
493  * bandwidth and clocks, possibly rearrange some pipes and reprogram anything front
494  * end related. Any time viewport dimensions, recout dimensions, scaling ratios or
495  * gamma need to be adjusted or pipe needs to be turned on (or disconnected) we do
496  * a full update. This cannot be done at ISR level and should be a rare event.
497  * Unless someone is stress testing mpo enter/exit, playing with colour or adjusting
498  * underscan we don't expect to see this call at all.
499  */
500
501 enum surface_update_type {
502         UPDATE_TYPE_FAST, /* super fast, safe to execute in isr */
503         UPDATE_TYPE_MED,  /* ISR safe, most of programming needed, no bw/clk change*/
504         UPDATE_TYPE_FULL, /* may need to shuffle resources */
505 };
506
507 /*******************************************************************************
508  * Stream Interfaces
509  ******************************************************************************/
510
511 struct dc_stream_status {
512         int primary_otg_inst;
513         int stream_enc_inst;
514         int plane_count;
515         struct dc_plane_state *plane_states[MAX_SURFACE_NUM];
516
517         /*
518          * link this stream passes through
519          */
520         struct dc_link *link;
521 };
522
523 struct dc_stream_state {
524         struct dc_sink *sink;
525         struct dc_crtc_timing timing;
526
527         struct rect src; /* composition area */
528         struct rect dst; /* stream addressable area */
529
530         struct audio_info audio_info;
531
532         struct freesync_context freesync_ctx;
533
534         struct dc_transfer_func *out_transfer_func;
535         struct colorspace_transform gamut_remap_matrix;
536         struct csc_transform csc_color_matrix;
537
538         enum signal_type output_signal;
539
540         enum dc_color_space output_color_space;
541         enum dc_dither_option dither_option;
542
543         enum view_3d_format view_format;
544
545         bool ignore_msa_timing_param;
546         /* TODO: custom INFO packets */
547         /* TODO: ABM info (DMCU) */
548         /* TODO: PSR info */
549         /* TODO: CEA VIC */
550
551         /* from core_stream struct */
552         struct dc_context *ctx;
553
554         /* used by DCP and FMT */
555         struct bit_depth_reduction_params bit_depth_params;
556         struct clamping_and_pixel_encoding_params clamping;
557
558         int phy_pix_clk;
559         enum signal_type signal;
560
561         struct dc_stream_status status;
562
563         /* from stream struct */
564         atomic_t ref_count;
565 };
566
567 struct dc_stream_update {
568         struct rect src;
569         struct rect dst;
570         struct dc_transfer_func *out_transfer_func;
571 };
572
573 bool dc_is_stream_unchanged(
574         struct dc_stream_state *old_stream, struct dc_stream_state *stream);
575
576 /*
577  * Setup stream attributes if no stream updates are provided
578  * there will be no impact on the stream parameters
579  *
580  * Set up surface attributes and associate to a stream
581  * The surfaces parameter is an absolute set of all surface active for the stream.
582  * If no surfaces are provided, the stream will be blanked; no memory read.
583  * Any flip related attribute changes must be done through this interface.
584  *
585  * After this call:
586  *   Surfaces attributes are programmed and configured to be composed into stream.
587  *   This does not trigger a flip.  No surface address is programmed.
588  *
589  */
590
591 void dc_update_planes_and_stream(struct dc *dc,
592                 struct dc_surface_update *surface_updates, int surface_count,
593                 struct dc_stream_state *dc_stream,
594                 struct dc_stream_update *stream_update);
595
596 /*
597  * Log the current stream state.
598  */
599 void dc_stream_log(
600         const struct dc_stream_state *stream,
601         struct dal_logger *dc_logger,
602         enum dc_log_type log_type);
603
604 uint8_t dc_get_current_stream_count(struct dc *dc);
605 struct dc_stream_state *dc_get_stream_at_index(struct dc *dc, uint8_t i);
606
607 /*
608  * Return the current frame counter.
609  */
610 uint32_t dc_stream_get_vblank_counter(const struct dc_stream_state *stream);
611
612 /* TODO: Return parsed values rather than direct register read
613  * This has a dependency on the caller (amdgpu_get_crtc_scanoutpos)
614  * being refactored properly to be dce-specific
615  */
616 bool dc_stream_get_scanoutpos(const struct dc_stream_state *stream,
617                                   uint32_t *v_blank_start,
618                                   uint32_t *v_blank_end,
619                                   uint32_t *h_position,
620                                   uint32_t *v_position);
621
622 bool dc_add_stream_to_ctx(
623                         struct dc *dc,
624                 struct dc_state *new_ctx,
625                 struct dc_stream_state *stream);
626
627 bool dc_remove_stream_from_ctx(
628                 struct dc *dc,
629                         struct dc_state *new_ctx,
630                         struct dc_stream_state *stream);
631
632
633 bool dc_add_plane_to_context(
634                 const struct dc *dc,
635                 struct dc_stream_state *stream,
636                 struct dc_plane_state *plane_state,
637                 struct dc_state *context);
638
639 bool dc_remove_plane_from_context(
640                 const struct dc *dc,
641                 struct dc_stream_state *stream,
642                 struct dc_plane_state *plane_state,
643                 struct dc_state *context);
644
645 bool dc_rem_all_planes_for_stream(
646                 const struct dc *dc,
647                 struct dc_stream_state *stream,
648                 struct dc_state *context);
649
650 bool dc_add_all_planes_for_stream(
651                 const struct dc *dc,
652                 struct dc_stream_state *stream,
653                 struct dc_plane_state * const *plane_states,
654                 int plane_count,
655                 struct dc_state *context);
656
657 /*
658  * Structure to store surface/stream associations for validation
659  */
660 struct dc_validation_set {
661         struct dc_stream_state *stream;
662         struct dc_plane_state *plane_states[MAX_SURFACES];
663         uint8_t plane_count;
664 };
665
666 bool dc_validate_stream(struct dc *dc, struct dc_stream_state *stream);
667
668 bool dc_validate_plane(struct dc *dc, const struct dc_plane_state *plane_state);
669
670 bool dc_validate_global_state(
671                 struct dc *dc,
672                 struct dc_state *new_ctx);
673
674 /*
675  * This function takes a stream and checks if it is guaranteed to be supported.
676  * Guaranteed means that MAX_COFUNC similar streams are supported.
677  *
678  * After this call:
679  *   No hardware is programmed for call.  Only validation is done.
680  */
681
682
683 void dc_resource_state_construct(
684                 const struct dc *dc,
685                 struct dc_state *dst_ctx);
686
687 void dc_resource_state_copy_construct(
688                 const struct dc_state *src_ctx,
689                 struct dc_state *dst_ctx);
690
691 void dc_resource_state_copy_construct_current(
692                 const struct dc *dc,
693                 struct dc_state *dst_ctx);
694
695 void dc_resource_state_destruct(struct dc_state *context);
696
697 /*
698  * TODO update to make it about validation sets
699  * Set up streams and links associated to drive sinks
700  * The streams parameter is an absolute set of all active streams.
701  *
702  * After this call:
703  *   Phy, Encoder, Timing Generator are programmed and enabled.
704  *   New streams are enabled with blank stream; no memory read.
705  */
706 bool dc_commit_state(struct dc *dc, struct dc_state *context);
707
708 /*
709  * Set up streams and links associated to drive sinks
710  * The streams parameter is an absolute set of all active streams.
711  *
712  * After this call:
713  *   Phy, Encoder, Timing Generator are programmed and enabled.
714  *   New streams are enabled with blank stream; no memory read.
715  */
716 /*
717  * Enable stereo when commit_streams is not required,
718  * for example, frame alternate.
719  */
720 bool dc_enable_stereo(
721         struct dc *dc,
722         struct dc_state *context,
723         struct dc_stream_state *streams[],
724         uint8_t stream_count);
725
726 /**
727  * Create a new default stream for the requested sink
728  */
729 struct dc_stream_state *dc_create_stream_for_sink(struct dc_sink *dc_sink);
730
731 void dc_stream_retain(struct dc_stream_state *dc_stream);
732 void dc_stream_release(struct dc_stream_state *dc_stream);
733
734 struct dc_stream_status *dc_stream_get_status(
735         struct dc_stream_state *dc_stream);
736
737 enum surface_update_type dc_check_update_surfaces_for_stream(
738                 struct dc *dc,
739                 struct dc_surface_update *updates,
740                 int surface_count,
741                 struct dc_stream_update *stream_update,
742                 const struct dc_stream_status *stream_status);
743
744
745 struct dc_state *dc_create_state(void);
746 void dc_retain_state(struct dc_state *context);
747 void dc_release_state(struct dc_state *context);
748
749 /*******************************************************************************
750  * Link Interfaces
751  ******************************************************************************/
752
753 struct dpcd_caps {
754         union dpcd_rev dpcd_rev;
755         union max_lane_count max_ln_count;
756         union max_down_spread max_down_spread;
757
758         /* dongle type (DP converter, CV smart dongle) */
759         enum display_dongle_type dongle_type;
760         /* Dongle's downstream count. */
761         union sink_count sink_count;
762         /* If dongle_type == DISPLAY_DONGLE_DP_HDMI_CONVERTER,
763         indicates 'Frame Sequential-to-lllFrame Pack' conversion capability.*/
764         struct dc_dongle_caps dongle_caps;
765
766         uint32_t sink_dev_id;
767         uint32_t branch_dev_id;
768         int8_t branch_dev_name[6];
769         int8_t branch_hw_revision;
770
771         bool allow_invalid_MSA_timing_param;
772         bool panel_mode_edp;
773         bool dpcd_display_control_capable;
774 };
775
776 struct dc_link_status {
777         struct dpcd_caps *dpcd_caps;
778 };
779
780 /* DP MST stream allocation (payload bandwidth number) */
781 struct link_mst_stream_allocation {
782         /* DIG front */
783         const struct stream_encoder *stream_enc;
784         /* associate DRM payload table with DC stream encoder */
785         uint8_t vcp_id;
786         /* number of slots required for the DP stream in transport packet */
787         uint8_t slot_count;
788 };
789
790 /* DP MST stream allocation table */
791 struct link_mst_stream_allocation_table {
792         /* number of DP video streams */
793         int stream_count;
794         /* array of stream allocations */
795         struct link_mst_stream_allocation stream_allocations[MAX_CONTROLLER_NUM];
796 };
797
798 /*
799  * A link contains one or more sinks and their connected status.
800  * The currently active signal type (HDMI, DP-SST, DP-MST) is also reported.
801  */
802 struct dc_link {
803         struct dc_sink *remote_sinks[MAX_SINKS_PER_LINK];
804         unsigned int sink_count;
805         struct dc_sink *local_sink;
806         unsigned int link_index;
807         enum dc_connection_type type;
808         enum signal_type connector_signal;
809         enum dc_irq_source irq_source_hpd;
810         enum dc_irq_source irq_source_hpd_rx;/* aka DP Short Pulse  */
811         /* caps is the same as reported_link_cap. link_traing use
812          * reported_link_cap. Will clean up.  TODO
813          */
814         struct dc_link_settings reported_link_cap;
815         struct dc_link_settings verified_link_cap;
816         struct dc_link_settings cur_link_settings;
817         struct dc_lane_settings cur_lane_setting;
818         struct dc_link_settings preferred_link_setting;
819
820         uint8_t ddc_hw_inst;
821
822         uint8_t hpd_src;
823
824         uint8_t link_enc_hw_inst;
825
826         bool test_pattern_enabled;
827         union compliance_test_state compliance_test_state;
828
829         void *priv;
830
831         struct ddc_service *ddc;
832
833         bool aux_mode;
834
835         /* Private to DC core */
836
837         const struct dc *dc;
838
839         struct dc_context *ctx;
840
841         struct link_encoder *link_enc;
842         struct graphics_object_id link_id;
843         union ddi_channel_mapping ddi_channel_mapping;
844         struct connector_device_tag_info device_tag;
845         struct dpcd_caps dpcd_caps;
846         unsigned short chip_caps;
847         unsigned int dpcd_sink_count;
848         enum edp_revision edp_revision;
849         bool psr_enabled;
850
851         /* MST record stream using this link */
852         struct link_flags {
853                 bool dp_keep_receiver_powered;
854         } wa_flags;
855         struct link_mst_stream_allocation_table mst_stream_alloc_table;
856
857         struct dc_link_status link_status;
858
859 };
860
861 const struct dc_link_status *dc_link_get_status(const struct dc_link *dc_link);
862
863 /*
864  * Return an enumerated dc_link.  dc_link order is constant and determined at
865  * boot time.  They cannot be created or destroyed.
866  * Use dc_get_caps() to get number of links.
867  */
868 struct dc_link *dc_get_link_at_index(struct dc *dc, uint32_t link_index);
869
870 /* Set backlight level of an embedded panel (eDP, LVDS). */
871 bool dc_link_set_backlight_level(const struct dc_link *dc_link, uint32_t level,
872                 uint32_t frame_ramp, const struct dc_stream_state *stream);
873
874 bool dc_link_set_psr_enable(const struct dc_link *dc_link, bool enable);
875
876 bool dc_link_get_psr_state(const struct dc_link *dc_link, uint32_t *psr_state);
877
878 bool dc_link_setup_psr(struct dc_link *dc_link,
879                 const struct dc_stream_state *stream, struct psr_config *psr_config,
880                 struct psr_context *psr_context);
881
882 /* Request DC to detect if there is a Panel connected.
883  * boot - If this call is during initial boot.
884  * Return false for any type of detection failure or MST detection
885  * true otherwise. True meaning further action is required (status update
886  * and OS notification).
887  */
888 bool dc_link_detect(struct dc_link *dc_link, bool boot);
889
890 /* Notify DC about DP RX Interrupt (aka Short Pulse Interrupt).
891  * Return:
892  * true - Downstream port status changed. DM should call DC to do the
893  * detection.
894  * false - no change in Downstream port status. No further action required
895  * from DM. */
896 bool dc_link_handle_hpd_rx_irq(struct dc_link *dc_link,
897                 union hpd_irq_data *hpd_irq_dpcd_data);
898
899 struct dc_sink_init_data;
900
901 struct dc_sink *dc_link_add_remote_sink(
902                 struct dc_link *dc_link,
903                 const uint8_t *edid,
904                 int len,
905                 struct dc_sink_init_data *init_data);
906
907 void dc_link_remove_remote_sink(
908         struct dc_link *link,
909         struct dc_sink *sink);
910
911 /* Used by diagnostics for virtual link at the moment */
912
913 void dc_link_dp_set_drive_settings(
914         struct dc_link *link,
915         struct link_training_settings *lt_settings);
916
917 enum link_training_result dc_link_dp_perform_link_training(
918         struct dc_link *link,
919         const struct dc_link_settings *link_setting,
920         bool skip_video_pattern);
921
922 void dc_link_dp_enable_hpd(const struct dc_link *link);
923
924 void dc_link_dp_disable_hpd(const struct dc_link *link);
925
926 bool dc_link_dp_set_test_pattern(
927         struct dc_link *link,
928         enum dp_test_pattern test_pattern,
929         const struct link_training_settings *p_link_settings,
930         const unsigned char *p_custom_pattern,
931         unsigned int cust_pattern_size);
932
933 /*******************************************************************************
934  * Sink Interfaces - A sink corresponds to a display output device
935  ******************************************************************************/
936
937 struct dc_container_id {
938         // 128bit GUID in binary form
939         unsigned char  guid[16];
940         // 8 byte port ID -> ELD.PortID
941         unsigned int   portId[2];
942         // 128bit GUID in binary formufacturer name -> ELD.ManufacturerName
943         unsigned short manufacturerName;
944         // 2 byte product code -> ELD.ProductCode
945         unsigned short productCode;
946 };
947
948
949
950 /*
951  * The sink structure contains EDID and other display device properties
952  */
953 struct dc_sink {
954         enum signal_type sink_signal;
955         struct dc_edid dc_edid; /* raw edid */
956         struct dc_edid_caps edid_caps; /* parse display caps */
957         struct dc_container_id *dc_container_id;
958         uint32_t dongle_max_pix_clk;
959         void *priv;
960         struct stereo_3d_features features_3d[TIMING_3D_FORMAT_MAX];
961         bool converter_disable_audio;
962
963         /* private to DC core */
964         struct dc_link *link;
965         struct dc_context *ctx;
966
967         /* private to dc_sink.c */
968         atomic_t ref_count;
969 };
970
971 void dc_sink_retain(struct dc_sink *sink);
972 void dc_sink_release(struct dc_sink *sink);
973
974 struct dc_sink_init_data {
975         enum signal_type sink_signal;
976         struct dc_link *link;
977         uint32_t dongle_max_pix_clk;
978         bool converter_disable_audio;
979 };
980
981 struct dc_sink *dc_sink_create(const struct dc_sink_init_data *init_params);
982
983 /*******************************************************************************
984  * Cursor interfaces - To manages the cursor within a stream
985  ******************************************************************************/
986 /* TODO: Deprecated once we switch to dc_set_cursor_position */
987 bool dc_stream_set_cursor_attributes(
988         const struct dc_stream_state *stream,
989         const struct dc_cursor_attributes *attributes);
990
991 bool dc_stream_set_cursor_position(
992         struct dc_stream_state *stream,
993         const struct dc_cursor_position *position);
994
995 /* Newer interfaces  */
996 struct dc_cursor {
997         struct dc_plane_address address;
998         struct dc_cursor_attributes attributes;
999 };
1000
1001 /*******************************************************************************
1002  * Interrupt interfaces
1003  ******************************************************************************/
1004 enum dc_irq_source dc_interrupt_to_irq_source(
1005                 struct dc *dc,
1006                 uint32_t src_id,
1007                 uint32_t ext_id);
1008 void dc_interrupt_set(struct dc *dc, enum dc_irq_source src, bool enable);
1009 void dc_interrupt_ack(struct dc *dc, enum dc_irq_source src);
1010 enum dc_irq_source dc_get_hpd_irq_source_at_index(
1011                 struct dc *dc, uint32_t link_index);
1012
1013 /*******************************************************************************
1014  * Power Interfaces
1015  ******************************************************************************/
1016
1017 void dc_set_power_state(
1018                 struct dc *dc,
1019                 enum dc_acpi_cm_power_state power_state);
1020 void dc_resume(struct dc *dc);
1021
1022 /*
1023  * DPCD access interfaces
1024  */
1025
1026 bool dc_submit_i2c(
1027                 struct dc *dc,
1028                 uint32_t link_index,
1029                 struct i2c_command *cmd);
1030
1031
1032 #endif /* DC_INTERFACE_H_ */