drm/amd/display: Add dependant changes for DCN32/321
[linux-2.6-microblaze.git] / drivers / gpu / drm / amd / display / dc / inc / core_types.h
1 /*
2  * Copyright 2015 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 _CORE_TYPES_H_
27 #define _CORE_TYPES_H_
28
29 #include "dc.h"
30 #include "dce_calcs.h"
31 #include "dcn_calcs.h"
32 #include "ddc_service_types.h"
33 #include "dc_bios_types.h"
34 #include "mem_input.h"
35 #include "hubp.h"
36 #include "mpc.h"
37 #include "dwb.h"
38 #include "mcif_wb.h"
39 #include "panel_cntl.h"
40
41 #define MAX_CLOCK_SOURCES 7
42
43 void enable_surface_flip_reporting(struct dc_plane_state *plane_state,
44                 uint32_t controller_id);
45
46 #include "grph_object_id.h"
47 #include "link_encoder.h"
48 #include "stream_encoder.h"
49 #include "clock_source.h"
50 #include "audio.h"
51 #include "dm_pp_smu.h"
52 #ifdef CONFIG_DRM_AMD_DC_HDCP
53 #include "dm_cp_psp.h"
54 #endif
55 #include "link_hwss.h"
56
57 /************ link *****************/
58 struct link_init_data {
59         const struct dc *dc;
60         struct dc_context *ctx; /* TODO: remove 'dal' when DC is complete. */
61         uint32_t connector_index; /* this will be mapped to the HPD pins */
62         uint32_t link_index; /* this is mapped to DAL display_index
63                                 TODO: remove it when DC is complete. */
64         bool is_dpia_link;
65 };
66
67 struct dc_link *link_create(const struct link_init_data *init_params);
68 void link_destroy(struct dc_link **link);
69
70 enum dc_status dc_link_validate_mode_timing(
71                 const struct dc_stream_state *stream,
72                 struct dc_link *link,
73                 const struct dc_crtc_timing *timing);
74
75 void core_link_resume(struct dc_link *link);
76
77 void core_link_enable_stream(
78                 struct dc_state *state,
79                 struct pipe_ctx *pipe_ctx);
80
81 void core_link_disable_stream(struct pipe_ctx *pipe_ctx);
82
83 void core_link_set_avmute(struct pipe_ctx *pipe_ctx, bool enable);
84 /********** DAL Core*********************/
85 #include "transform.h"
86 #include "dpp.h"
87
88 struct resource_pool;
89 struct dc_state;
90 struct resource_context;
91 struct clk_bw_params;
92
93 struct resource_funcs {
94         void (*destroy)(struct resource_pool **pool);
95         void (*link_init)(struct dc_link *link);
96         struct panel_cntl*(*panel_cntl_create)(
97                 const struct panel_cntl_init_data *panel_cntl_init_data);
98         struct link_encoder *(*link_enc_create)(
99                         const struct encoder_init_data *init);
100         /* Create a minimal link encoder object with no dc_link object
101          * associated with it. */
102         struct link_encoder *(*link_enc_create_minimal)(struct dc_context *ctx, enum engine_id eng_id);
103
104         bool (*validate_bandwidth)(
105                                         struct dc *dc,
106                                         struct dc_state *context,
107                                         bool fast_validate);
108         void (*calculate_wm_and_dlg)(
109                                 struct dc *dc, struct dc_state *context,
110                                 display_e2e_pipe_params_st *pipes,
111                                 int pipe_cnt,
112                                 int vlevel);
113         void (*update_soc_for_wm_a)(
114                                 struct dc *dc, struct dc_state *context);
115         int (*populate_dml_pipes)(
116                 struct dc *dc,
117                 struct dc_state *context,
118                 display_e2e_pipe_params_st *pipes,
119                 bool fast_validate);
120
121         /*
122          * Algorithm for assigning available link encoders to links.
123          *
124          * Update link_enc_assignments table and link_enc_avail list accordingly in
125          * struct resource_context.
126          */
127         void (*link_encs_assign)(
128                         struct dc *dc,
129                         struct dc_state *state,
130                         struct dc_stream_state *streams[],
131                         uint8_t stream_count);
132         /*
133          * Unassign a link encoder from a stream.
134          *
135          * Update link_enc_assignments table and link_enc_avail list accordingly in
136          * struct resource_context.
137          */
138         void (*link_enc_unassign)(
139                         struct dc_state *state,
140                         struct dc_stream_state *stream);
141
142         enum dc_status (*validate_global)(
143                 struct dc *dc,
144                 struct dc_state *context);
145
146         struct pipe_ctx *(*acquire_idle_pipe_for_layer)(
147                         struct dc_state *context,
148                         const struct resource_pool *pool,
149                         struct dc_stream_state *stream);
150
151         enum dc_status (*validate_plane)(const struct dc_plane_state *plane_state, struct dc_caps *caps);
152
153         enum dc_status (*add_stream_to_ctx)(
154                         struct dc *dc,
155                         struct dc_state *new_ctx,
156                         struct dc_stream_state *dc_stream);
157
158         enum dc_status (*remove_stream_from_ctx)(
159                                 struct dc *dc,
160                                 struct dc_state *new_ctx,
161                                 struct dc_stream_state *stream);
162         enum dc_status (*patch_unknown_plane_state)(
163                         struct dc_plane_state *plane_state);
164
165         struct stream_encoder *(*find_first_free_match_stream_enc_for_link)(
166                         struct resource_context *res_ctx,
167                         const struct resource_pool *pool,
168                         struct dc_stream_state *stream);
169         void (*populate_dml_writeback_from_context)(
170                         struct dc *dc,
171                         struct resource_context *res_ctx,
172                         display_e2e_pipe_params_st *pipes);
173
174         void (*set_mcif_arb_params)(
175                         struct dc *dc,
176                         struct dc_state *context,
177                         display_e2e_pipe_params_st *pipes,
178                         int pipe_cnt);
179         void (*update_bw_bounding_box)(
180                         struct dc *dc,
181                         struct clk_bw_params *bw_params);
182         bool (*acquire_post_bldn_3dlut)(
183                         struct resource_context *res_ctx,
184                         const struct resource_pool *pool,
185                         int mpcc_id,
186                         struct dc_3dlut **lut,
187                         struct dc_transfer_func **shaper);
188
189         bool (*release_post_bldn_3dlut)(
190                         struct resource_context *res_ctx,
191                         const struct resource_pool *pool,
192                         struct dc_3dlut **lut,
193                         struct dc_transfer_func **shaper);
194
195         enum dc_status (*add_dsc_to_stream_resource)(
196                         struct dc *dc, struct dc_state *state,
197                         struct dc_stream_state *stream);
198
199         void (*add_phantom_pipes)(
200             struct dc *dc,
201             struct dc_state *context,
202             display_e2e_pipe_params_st *pipes,
203                         unsigned int pipe_cnt,
204             unsigned int index);
205         void (*remove_phantom_pipes)(
206             struct dc *dc,
207             struct dc_state *context);
208 };
209
210 struct audio_support{
211         bool dp_audio;
212         bool hdmi_audio_on_dongle;
213         bool hdmi_audio_native;
214 };
215
216 #define NO_UNDERLAY_PIPE -1
217
218 struct resource_pool {
219         struct mem_input *mis[MAX_PIPES];
220         struct hubp *hubps[MAX_PIPES];
221         struct input_pixel_processor *ipps[MAX_PIPES];
222         struct transform *transforms[MAX_PIPES];
223         struct dpp *dpps[MAX_PIPES];
224         struct output_pixel_processor *opps[MAX_PIPES];
225         struct timing_generator *timing_generators[MAX_PIPES];
226         struct stream_encoder *stream_enc[MAX_PIPES * 2];
227         struct hubbub *hubbub;
228         struct mpc *mpc;
229         struct pp_smu_funcs *pp_smu;
230         struct dce_aux *engines[MAX_PIPES];
231         struct dce_i2c_hw *hw_i2cs[MAX_PIPES];
232         struct dce_i2c_sw *sw_i2cs[MAX_PIPES];
233         bool i2c_hw_buffer_in_use;
234
235         struct dwbc *dwbc[MAX_DWB_PIPES];
236         struct mcif_wb *mcif_wb[MAX_DWB_PIPES];
237         struct {
238                 unsigned int gsl_0:1;
239                 unsigned int gsl_1:1;
240                 unsigned int gsl_2:1;
241         } gsl_groups;
242
243         struct display_stream_compressor *dscs[MAX_PIPES];
244
245         unsigned int pipe_count;
246         unsigned int underlay_pipe_index;
247         unsigned int stream_enc_count;
248
249         /* An array for accessing the link encoder objects that have been created.
250          * Index in array corresponds to engine ID - viz. 0: ENGINE_ID_DIGA
251          */
252         struct link_encoder *link_encoders[MAX_DIG_LINK_ENCODERS];
253         /* Number of DIG link encoder objects created - i.e. number of valid
254          * entries in link_encoders array.
255          */
256         unsigned int dig_link_enc_count;
257         /* Number of USB4 DPIA (DisplayPort Input Adapter) link objects created.*/
258         unsigned int usb4_dpia_count;
259
260         unsigned int hpo_dp_stream_enc_count;
261         struct hpo_dp_stream_encoder *hpo_dp_stream_enc[MAX_HPO_DP2_ENCODERS];
262         unsigned int hpo_dp_link_enc_count;
263         struct hpo_dp_link_encoder *hpo_dp_link_enc[MAX_HPO_DP2_LINK_ENCODERS];
264         struct dc_3dlut *mpc_lut[MAX_PIPES];
265         struct dc_transfer_func *mpc_shaper[MAX_PIPES];
266
267         struct {
268                 unsigned int xtalin_clock_inKhz;
269                 unsigned int dccg_ref_clock_inKhz;
270                 unsigned int dchub_ref_clock_inKhz;
271         } ref_clocks;
272         unsigned int timing_generator_count;
273         unsigned int mpcc_count;
274
275         unsigned int writeback_pipe_count;
276         /*
277          * reserved clock source for DP
278          */
279         struct clock_source *dp_clock_source;
280
281         struct clock_source *clock_sources[MAX_CLOCK_SOURCES];
282         unsigned int clk_src_count;
283
284         struct audio *audios[MAX_AUDIOS];
285         unsigned int audio_count;
286         struct audio_support audio_support;
287
288         struct dccg *dccg;
289         struct irq_service *irqs;
290
291         struct abm *abm;
292         struct dmcu *dmcu;
293         struct dmub_psr *psr;
294
295         struct abm *multiple_abms[MAX_PIPES];
296
297         const struct resource_funcs *funcs;
298         const struct resource_caps *res_cap;
299
300         struct ddc_service *oem_device;
301 };
302
303 struct dcn_fe_bandwidth {
304         int dppclk_khz;
305
306 };
307
308 struct stream_resource {
309         struct output_pixel_processor *opp;
310         struct display_stream_compressor *dsc;
311         struct timing_generator *tg;
312         struct stream_encoder *stream_enc;
313         struct hpo_dp_stream_encoder *hpo_dp_stream_enc;
314         struct audio *audio;
315
316         struct pixel_clk_params pix_clk_params;
317         struct encoder_info_frame encoder_info_frame;
318
319         struct abm *abm;
320         /* There are only (num_pipes+1)/2 groups. 0 means unassigned,
321          * otherwise it's using group number 'gsl_group-1'
322          */
323         uint8_t gsl_group;
324 };
325
326 struct plane_resource {
327         struct scaler_data scl_data;
328         struct hubp *hubp;
329         struct mem_input *mi;
330         struct input_pixel_processor *ipp;
331         struct transform *xfm;
332         struct dpp *dpp;
333         uint8_t mpcc_inst;
334
335         struct dcn_fe_bandwidth bw;
336 };
337
338 #define LINK_RES_HPO_DP_REC_MAP__MASK 0xFFFF
339 #define LINK_RES_HPO_DP_REC_MAP__SHIFT 0
340
341 /* all mappable hardware resources used to enable a link */
342 struct link_resource {
343         struct hpo_dp_link_encoder *hpo_dp_link_enc;
344 };
345
346 union pipe_update_flags {
347         struct {
348                 uint32_t enable : 1;
349                 uint32_t disable : 1;
350                 uint32_t odm : 1;
351                 uint32_t global_sync : 1;
352                 uint32_t opp_changed : 1;
353                 uint32_t tg_changed : 1;
354                 uint32_t mpcc : 1;
355                 uint32_t dppclk : 1;
356                 uint32_t hubp_interdependent : 1;
357                 uint32_t hubp_rq_dlg_ttu : 1;
358                 uint32_t gamut_remap : 1;
359                 uint32_t scaler : 1;
360                 uint32_t viewport : 1;
361                 uint32_t plane_changed : 1;
362                 uint32_t det_size : 1;
363         } bits;
364         uint32_t raw;
365 };
366
367 struct pipe_ctx {
368         struct dc_plane_state *plane_state;
369         struct dc_stream_state *stream;
370
371         struct plane_resource plane_res;
372         struct stream_resource stream_res;
373         struct link_resource link_res;
374
375         struct clock_source *clock_source;
376
377         struct pll_settings pll_settings;
378
379         uint8_t pipe_idx;
380         uint8_t pipe_idx_syncd;
381
382         struct pipe_ctx *top_pipe;
383         struct pipe_ctx *bottom_pipe;
384         struct pipe_ctx *next_odm_pipe;
385         struct pipe_ctx *prev_odm_pipe;
386
387         struct _vcs_dpi_display_dlg_regs_st dlg_regs;
388         struct _vcs_dpi_display_ttu_regs_st ttu_regs;
389         struct _vcs_dpi_display_rq_regs_st rq_regs;
390         struct _vcs_dpi_display_pipe_dest_params_st pipe_dlg_param;
391         struct _vcs_dpi_display_rq_params_st dml_rq_param;
392         struct _vcs_dpi_display_dlg_sys_params_st dml_dlg_sys_param;
393         struct _vcs_dpi_display_e2e_pipe_params_st dml_input;
394         int det_buffer_size_kb;
395         bool unbounded_req;
396
397         union pipe_update_flags update_flags;
398         struct dwbc *dwbc;
399         struct mcif_wb *mcif_wb;
400         bool vtp_locked;
401 };
402
403 /* Data used for dynamic link encoder assignment.
404  * Tracks current and future assignments; available link encoders;
405  * and mode of operation (whether to use current or future assignments).
406  */
407 struct link_enc_cfg_context {
408         enum link_enc_cfg_mode mode;
409         struct link_enc_assignment link_enc_assignments[MAX_PIPES];
410         enum engine_id link_enc_avail[MAX_DIG_LINK_ENCODERS];
411         struct link_enc_assignment transient_assignments[MAX_PIPES];
412 };
413
414 struct resource_context {
415         struct pipe_ctx pipe_ctx[MAX_PIPES];
416         bool is_stream_enc_acquired[MAX_PIPES * 2];
417         bool is_audio_acquired[MAX_PIPES];
418         uint8_t clock_source_ref_count[MAX_CLOCK_SOURCES];
419         uint8_t dp_clock_source_ref_count;
420         bool is_dsc_acquired[MAX_PIPES];
421         struct link_enc_cfg_context link_enc_cfg_ctx;
422         bool is_hpo_dp_stream_enc_acquired[MAX_HPO_DP2_ENCODERS];
423         unsigned int hpo_dp_link_enc_to_link_idx[MAX_HPO_DP2_LINK_ENCODERS];
424         int hpo_dp_link_enc_ref_cnts[MAX_HPO_DP2_LINK_ENCODERS];
425         bool is_mpc_3dlut_acquired[MAX_PIPES];
426 };
427
428 struct dce_bw_output {
429         bool cpuc_state_change_enable;
430         bool cpup_state_change_enable;
431         bool stutter_mode_enable;
432         bool nbp_state_change_enable;
433         bool all_displays_in_sync;
434         struct dce_watermarks urgent_wm_ns[MAX_PIPES];
435         struct dce_watermarks stutter_exit_wm_ns[MAX_PIPES];
436         struct dce_watermarks stutter_entry_wm_ns[MAX_PIPES];
437         struct dce_watermarks nbp_state_change_wm_ns[MAX_PIPES];
438         int sclk_khz;
439         int sclk_deep_sleep_khz;
440         int yclk_khz;
441         int dispclk_khz;
442         int blackout_recovery_time_us;
443 };
444
445 struct dcn_bw_writeback {
446         struct mcif_arb_params mcif_wb_arb[MAX_DWB_PIPES];
447 };
448
449 struct dcn_bw_output {
450         struct dc_clocks clk;
451         struct dcn_watermark_set watermarks;
452         struct dcn_bw_writeback bw_writeback;
453         int compbuf_size_kb;
454 };
455
456 union bw_output {
457         struct dcn_bw_output dcn;
458         struct dce_bw_output dce;
459 };
460
461 struct bw_context {
462         union bw_output bw;
463         struct display_mode_lib dml;
464 };
465 /**
466  * struct dc_state - The full description of a state requested by a user
467  *
468  * @streams: Stream properties
469  * @stream_status: The planes on a given stream
470  * @res_ctx: Persistent state of resources
471  * @bw_ctx: The output from bandwidth and watermark calculations and the DML
472  * @pp_display_cfg: PowerPlay clocks and settings
473  * @dcn_bw_vars: non-stack memory to support bandwidth calculations
474  *
475  */
476 struct dc_state {
477         struct dc_stream_state *streams[MAX_PIPES];
478         struct dc_stream_status stream_status[MAX_PIPES];
479         uint8_t stream_count;
480         uint8_t stream_mask;
481
482         struct resource_context res_ctx;
483
484         struct bw_context bw_ctx;
485
486         /* Note: these are big structures, do *not* put on stack! */
487         struct dm_pp_display_configuration pp_display_cfg;
488         struct dcn_bw_internal_vars dcn_bw_vars;
489
490         struct clk_mgr *clk_mgr;
491
492         struct kref refcount;
493
494         struct {
495                 unsigned int stutter_period_us;
496         } perf_params;
497 };
498
499 struct dc_bounding_box_max_clk {
500         int max_dcfclk_mhz;
501         int max_dispclk_mhz;
502         int max_dppclk_mhz;
503         int max_phyclk_mhz;
504 };
505
506 #endif /* _CORE_TYPES_H_ */