fc9decc0a8fc40787aa0013ba3d7baade66fcb77
[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 #if defined(CONFIG_DRM_AMD_DC_DCN1_0)
37 #include "mpc.h"
38 #endif
39 #if defined(CONFIG_DRM_AMD_DC_DCN2_0)
40 #include "dwb.h"
41 #include "mcif_wb.h"
42 #endif
43
44 #define MAX_CLOCK_SOURCES 7
45
46 void enable_surface_flip_reporting(struct dc_plane_state *plane_state,
47                 uint32_t controller_id);
48
49 #include "grph_object_id.h"
50 #include "link_encoder.h"
51 #include "stream_encoder.h"
52 #include "clock_source.h"
53 #include "audio.h"
54 #include "dm_pp_smu.h"
55 #ifdef CONFIG_DRM_AMD_DC_HDCP
56 #include "dm_cp_psp.h"
57 #endif
58
59 /************ link *****************/
60 struct link_init_data {
61         const struct dc *dc;
62         struct dc_context *ctx; /* TODO: remove 'dal' when DC is complete. */
63         uint32_t connector_index; /* this will be mapped to the HPD pins */
64         uint32_t link_index; /* this is mapped to DAL display_index
65                                 TODO: remove it when DC is complete. */
66 };
67
68 struct dc_link *link_create(const struct link_init_data *init_params);
69 void link_destroy(struct dc_link **link);
70
71 enum dc_status dc_link_validate_mode_timing(
72                 const struct dc_stream_state *stream,
73                 struct dc_link *link,
74                 const struct dc_crtc_timing *timing);
75
76 void core_link_resume(struct dc_link *link);
77
78 void core_link_enable_stream(
79                 struct dc_state *state,
80                 struct pipe_ctx *pipe_ctx);
81
82 void core_link_disable_stream(struct pipe_ctx *pipe_ctx);
83
84 void core_link_set_avmute(struct pipe_ctx *pipe_ctx, bool enable);
85 /********** DAL Core*********************/
86 #include "transform.h"
87 #include "dpp.h"
88
89 struct resource_pool;
90 struct dc_state;
91 struct resource_context;
92 #if defined(CONFIG_DRM_AMD_DC_DCN2_1)
93 struct clk_bw_params;
94 #endif
95
96 struct resource_funcs {
97         void (*destroy)(struct resource_pool **pool);
98         void (*link_init)(struct dc_link *link);
99         struct link_encoder *(*link_enc_create)(
100                         const struct encoder_init_data *init);
101         bool (*validate_bandwidth)(
102                                         struct dc *dc,
103                                         struct dc_state *context,
104                                         bool fast_validate);
105
106         int (*populate_dml_pipes)(
107                 struct dc *dc,
108                 struct resource_context *res_ctx,
109                 display_e2e_pipe_params_st *pipes);
110
111         enum dc_status (*validate_global)(
112                 struct dc *dc,
113                 struct dc_state *context);
114
115         struct pipe_ctx *(*acquire_idle_pipe_for_layer)(
116                         struct dc_state *context,
117                         const struct resource_pool *pool,
118                         struct dc_stream_state *stream);
119
120         enum dc_status (*validate_plane)(const struct dc_plane_state *plane_state, struct dc_caps *caps);
121
122         enum dc_status (*add_stream_to_ctx)(
123                         struct dc *dc,
124                         struct dc_state *new_ctx,
125                         struct dc_stream_state *dc_stream);
126
127         enum dc_status (*remove_stream_from_ctx)(
128                                 struct dc *dc,
129                                 struct dc_state *new_ctx,
130                                 struct dc_stream_state *stream);
131         enum dc_status (*get_default_swizzle_mode)(
132                         struct dc_plane_state *plane_state);
133
134         struct stream_encoder *(*find_first_free_match_stream_enc_for_link)(
135                         struct resource_context *res_ctx,
136                         const struct resource_pool *pool,
137                         struct dc_stream_state *stream);
138 #if defined(CONFIG_DRM_AMD_DC_DCN2_0)
139         void (*populate_dml_writeback_from_context)(
140                         struct dc *dc,
141                         struct resource_context *res_ctx,
142                         display_e2e_pipe_params_st *pipes);
143
144         void (*set_mcif_arb_params)(
145                         struct dc *dc,
146                         struct dc_state *context,
147                         display_e2e_pipe_params_st *pipes,
148                         int pipe_cnt);
149 #endif
150 #if defined(CONFIG_DRM_AMD_DC_DCN2_1)
151         void (*update_bw_bounding_box)(
152                         struct dc *dc,
153                         struct clk_bw_params *bw_params);
154 #endif
155
156 };
157
158 struct audio_support{
159         bool dp_audio;
160         bool hdmi_audio_on_dongle;
161         bool hdmi_audio_native;
162 };
163
164 #define NO_UNDERLAY_PIPE -1
165
166 struct resource_pool {
167         struct mem_input *mis[MAX_PIPES];
168         struct hubp *hubps[MAX_PIPES];
169         struct input_pixel_processor *ipps[MAX_PIPES];
170         struct transform *transforms[MAX_PIPES];
171         struct dpp *dpps[MAX_PIPES];
172         struct output_pixel_processor *opps[MAX_PIPES];
173         struct timing_generator *timing_generators[MAX_PIPES];
174         struct stream_encoder *stream_enc[MAX_PIPES * 2];
175         struct hubbub *hubbub;
176         struct mpc *mpc;
177         struct pp_smu_funcs *pp_smu;
178         struct dce_aux *engines[MAX_PIPES];
179         struct dce_i2c_hw *hw_i2cs[MAX_PIPES];
180         struct dce_i2c_sw *sw_i2cs[MAX_PIPES];
181         bool i2c_hw_buffer_in_use;
182
183 #if defined(CONFIG_DRM_AMD_DC_DCN2_0)
184         struct dwbc *dwbc[MAX_DWB_PIPES];
185         struct mcif_wb *mcif_wb[MAX_DWB_PIPES];
186         struct {
187                 unsigned int gsl_0:1;
188                 unsigned int gsl_1:1;
189                 unsigned int gsl_2:1;
190         } gsl_groups;
191 #endif
192
193 #ifdef CONFIG_DRM_AMD_DC_DSC_SUPPORT
194         struct display_stream_compressor *dscs[MAX_PIPES];
195 #endif
196
197         unsigned int pipe_count;
198         unsigned int underlay_pipe_index;
199         unsigned int stream_enc_count;
200
201         struct {
202                 unsigned int xtalin_clock_inKhz;
203                 unsigned int dccg_ref_clock_inKhz;
204                 unsigned int dchub_ref_clock_inKhz;
205         } ref_clocks;
206         unsigned int timing_generator_count;
207         unsigned int mpcc_count;
208
209 #if defined(CONFIG_DRM_AMD_DC_DCN2_0)
210         unsigned int writeback_pipe_count;
211 #endif
212         /*
213          * reserved clock source for DP
214          */
215         struct clock_source *dp_clock_source;
216
217         struct clock_source *clock_sources[MAX_CLOCK_SOURCES];
218         unsigned int clk_src_count;
219
220         struct audio *audios[MAX_AUDIOS];
221         unsigned int audio_count;
222         struct audio_support audio_support;
223
224         struct dccg *dccg;
225         struct irq_service *irqs;
226
227         struct abm *abm;
228         struct dmcu *dmcu;
229
230         const struct resource_funcs *funcs;
231         const struct resource_caps *res_cap;
232
233         struct ddc_service *oem_device;
234 };
235
236 struct dcn_fe_bandwidth {
237         int dppclk_khz;
238
239 };
240
241 struct stream_resource {
242         struct output_pixel_processor *opp;
243 #ifdef CONFIG_DRM_AMD_DC_DSC_SUPPORT
244         struct display_stream_compressor *dsc;
245 #endif
246         struct timing_generator *tg;
247         struct stream_encoder *stream_enc;
248         struct audio *audio;
249
250         struct pixel_clk_params pix_clk_params;
251         struct encoder_info_frame encoder_info_frame;
252
253         struct abm *abm;
254 #if defined(CONFIG_DRM_AMD_DC_DCN2_0)
255         /* There are only (num_pipes+1)/2 groups. 0 means unassigned,
256          * otherwise it's using group number 'gsl_group-1'
257          */
258         uint8_t gsl_group;
259 #endif
260 };
261
262 struct plane_resource {
263         struct scaler_data scl_data;
264         struct hubp *hubp;
265         struct mem_input *mi;
266         struct input_pixel_processor *ipp;
267         struct transform *xfm;
268         struct dpp *dpp;
269         uint8_t mpcc_inst;
270
271         struct dcn_fe_bandwidth bw;
272 };
273
274 union pipe_update_flags {
275         struct {
276                 uint32_t enable : 1;
277                 uint32_t disable : 1;
278                 uint32_t odm : 1;
279                 uint32_t global_sync : 1;
280                 uint32_t opp_changed : 1;
281                 uint32_t tg_changed : 1;
282                 uint32_t mpcc : 1;
283                 uint32_t dppclk : 1;
284                 uint32_t hubp_interdependent : 1;
285                 uint32_t hubp_rq_dlg_ttu : 1;
286                 uint32_t gamut_remap : 1;
287                 uint32_t scaler : 1;
288                 uint32_t viewport : 1;
289         } bits;
290         uint32_t raw;
291 };
292
293 struct pipe_ctx {
294         struct dc_plane_state *plane_state;
295         struct dc_stream_state *stream;
296
297         struct plane_resource plane_res;
298         struct stream_resource stream_res;
299
300         struct clock_source *clock_source;
301
302         struct pll_settings pll_settings;
303
304         uint8_t pipe_idx;
305
306         struct pipe_ctx *top_pipe;
307         struct pipe_ctx *bottom_pipe;
308         struct pipe_ctx *next_odm_pipe;
309         struct pipe_ctx *prev_odm_pipe;
310
311 #ifdef CONFIG_DRM_AMD_DC_DCN1_0
312         struct _vcs_dpi_display_dlg_regs_st dlg_regs;
313         struct _vcs_dpi_display_ttu_regs_st ttu_regs;
314         struct _vcs_dpi_display_rq_regs_st rq_regs;
315         struct _vcs_dpi_display_pipe_dest_params_st pipe_dlg_param;
316 #endif
317         union pipe_update_flags update_flags;
318 #ifdef CONFIG_DRM_AMD_DC_DCN2_0
319         struct dwbc *dwbc;
320         struct mcif_wb *mcif_wb;
321 #endif
322 };
323
324 struct resource_context {
325         struct pipe_ctx pipe_ctx[MAX_PIPES];
326         bool is_stream_enc_acquired[MAX_PIPES * 2];
327         bool is_audio_acquired[MAX_PIPES];
328         uint8_t clock_source_ref_count[MAX_CLOCK_SOURCES];
329         uint8_t dp_clock_source_ref_count;
330 #ifdef CONFIG_DRM_AMD_DC_DCN2_0
331         bool is_dsc_acquired[MAX_PIPES];
332 #endif
333 };
334
335 struct dce_bw_output {
336         bool cpuc_state_change_enable;
337         bool cpup_state_change_enable;
338         bool stutter_mode_enable;
339         bool nbp_state_change_enable;
340         bool all_displays_in_sync;
341         struct dce_watermarks urgent_wm_ns[MAX_PIPES];
342         struct dce_watermarks stutter_exit_wm_ns[MAX_PIPES];
343         struct dce_watermarks stutter_entry_wm_ns[MAX_PIPES];
344         struct dce_watermarks nbp_state_change_wm_ns[MAX_PIPES];
345         int sclk_khz;
346         int sclk_deep_sleep_khz;
347         int yclk_khz;
348         int dispclk_khz;
349         int blackout_recovery_time_us;
350 };
351
352 #if defined(CONFIG_DRM_AMD_DC_DCN2_0)
353 struct dcn_bw_writeback {
354         struct mcif_arb_params mcif_wb_arb[MAX_DWB_PIPES];
355 };
356 #endif
357
358 struct dcn_bw_output {
359         struct dc_clocks clk;
360         struct dcn_watermark_set watermarks;
361 #if defined(CONFIG_DRM_AMD_DC_DCN2_0)
362         struct dcn_bw_writeback bw_writeback;
363 #endif
364 };
365
366 union bw_output {
367         struct dcn_bw_output dcn;
368         struct dce_bw_output dce;
369 };
370
371 struct bw_context {
372         union bw_output bw;
373         struct display_mode_lib dml;
374 };
375 /**
376  * struct dc_state - The full description of a state requested by a user
377  *
378  * @streams: Stream properties
379  * @stream_status: The planes on a given stream
380  * @res_ctx: Persistent state of resources
381  * @bw_ctx: The output from bandwidth and watermark calculations and the DML
382  * @pp_display_cfg: PowerPlay clocks and settings
383  * @dcn_bw_vars: non-stack memory to support bandwidth calculations
384  *
385  */
386 struct dc_state {
387         struct dc_stream_state *streams[MAX_PIPES];
388         struct dc_stream_status stream_status[MAX_PIPES];
389         uint8_t stream_count;
390
391         struct resource_context res_ctx;
392
393         struct bw_context bw_ctx;
394
395         /* Note: these are big structures, do *not* put on stack! */
396         struct dm_pp_display_configuration pp_display_cfg;
397 #ifdef CONFIG_DRM_AMD_DC_DCN1_0
398         struct dcn_bw_internal_vars dcn_bw_vars;
399 #endif
400
401         struct clk_mgr *clk_mgr;
402
403         struct kref refcount;
404 };
405
406 #endif /* _CORE_TYPES_H_ */