14562236bSHarry Wentland /*
24562236bSHarry Wentland  * Copyright 2015 Advanced Micro Devices, Inc.
34562236bSHarry Wentland  *
44562236bSHarry Wentland  * Permission is hereby granted, free of charge, to any person obtaining a
54562236bSHarry Wentland  * copy of this software and associated documentation files (the "Software"),
64562236bSHarry Wentland  * to deal in the Software without restriction, including without limitation
74562236bSHarry Wentland  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
84562236bSHarry Wentland  * and/or sell copies of the Software, and to permit persons to whom the
94562236bSHarry Wentland  * Software is furnished to do so, subject to the following conditions:
104562236bSHarry Wentland  *
114562236bSHarry Wentland  * The above copyright notice and this permission notice shall be included in
124562236bSHarry Wentland  * all copies or substantial portions of the Software.
134562236bSHarry Wentland  *
144562236bSHarry Wentland  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
154562236bSHarry Wentland  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
164562236bSHarry Wentland  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
174562236bSHarry Wentland  * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
184562236bSHarry Wentland  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
194562236bSHarry Wentland  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
204562236bSHarry Wentland  * OTHER DEALINGS IN THE SOFTWARE.
214562236bSHarry Wentland  *
224562236bSHarry Wentland  * Authors: AMD
234562236bSHarry Wentland  *
244562236bSHarry Wentland  */
254562236bSHarry Wentland 
264562236bSHarry Wentland #ifndef _CORE_TYPES_H_
274562236bSHarry Wentland #define _CORE_TYPES_H_
284562236bSHarry Wentland 
294562236bSHarry Wentland #include "dc.h"
305e141de4SHarry Wentland #include "dce_calcs.h"
31ff5ef992SAlex Deucher #include "dcn_calcs.h"
324562236bSHarry Wentland #include "ddc_service_types.h"
334562236bSHarry Wentland #include "dc_bios_types.h"
34ff5ef992SAlex Deucher #include "mem_input.h"
358feabd03SYue Hin Lau #include "hubp.h"
36391e20d8SDuke Du #if defined(CONFIG_DRM_AMD_DC_DCN1_0)
37ff5ef992SAlex Deucher #include "mpc.h"
38391e20d8SDuke Du #endif
394562236bSHarry Wentland 
404562236bSHarry Wentland #define MAX_CLOCK_SOURCES 7
414562236bSHarry Wentland 
423be5262eSHarry Wentland void enable_surface_flip_reporting(struct dc_plane_state *plane_state,
434562236bSHarry Wentland 		uint32_t controller_id);
444562236bSHarry Wentland 
454562236bSHarry Wentland #include "grph_object_id.h"
464562236bSHarry Wentland #include "link_encoder.h"
474562236bSHarry Wentland #include "stream_encoder.h"
484562236bSHarry Wentland #include "clock_source.h"
494562236bSHarry Wentland #include "audio.h"
50a185048cSTony Cheng #include "dm_pp_smu.h"
514562236bSHarry Wentland 
524562236bSHarry Wentland 
534562236bSHarry Wentland /************ link *****************/
544562236bSHarry Wentland struct link_init_data {
55fb3466a4SBhawanpreet Lakha 	const struct dc *dc;
564562236bSHarry Wentland 	struct dc_context *ctx; /* TODO: remove 'dal' when DC is complete. */
574562236bSHarry Wentland 	uint32_t connector_index; /* this will be mapped to the HPD pins */
584562236bSHarry Wentland 	uint32_t link_index; /* this is mapped to DAL display_index
594562236bSHarry Wentland 				TODO: remove it when DC is complete. */
604562236bSHarry Wentland };
614562236bSHarry Wentland 
624176664bSCharlene Liu enum {
634176664bSCharlene Liu 	FREE_ACQUIRED_RESOURCE = 0,
644176664bSCharlene Liu 	KEEP_ACQUIRED_RESOURCE = 1,
654176664bSCharlene Liu };
664176664bSCharlene Liu 
67d0778ebfSHarry Wentland struct dc_link *link_create(const struct link_init_data *init_params);
68d0778ebfSHarry Wentland void link_destroy(struct dc_link **link);
694562236bSHarry Wentland 
704562236bSHarry Wentland enum dc_status dc_link_validate_mode_timing(
710971c40eSHarry Wentland 		const struct dc_stream_state *stream,
72d0778ebfSHarry Wentland 		struct dc_link *link,
734562236bSHarry Wentland 		const struct dc_crtc_timing *timing);
744562236bSHarry Wentland 
75d0778ebfSHarry Wentland void core_link_resume(struct dc_link *link);
764562236bSHarry Wentland 
77ab8db3e1SAndrey Grodzovsky void core_link_enable_stream(
78ab8db3e1SAndrey Grodzovsky 		struct dc_state *state,
79ab8db3e1SAndrey Grodzovsky 		struct pipe_ctx *pipe_ctx);
804562236bSHarry Wentland 
814176664bSCharlene Liu void core_link_disable_stream(struct pipe_ctx *pipe_ctx, int option);
824562236bSHarry Wentland 
8315e17335SCharlene Liu void core_link_set_avmute(struct pipe_ctx *pipe_ctx, bool enable);
844562236bSHarry Wentland /********** DAL Core*********************/
85e11b86adSDmytro Laktyushkin #include "display_clock.h"
864562236bSHarry Wentland #include "transform.h"
874562236bSHarry Wentland 
884562236bSHarry Wentland struct resource_pool;
89608ac7bbSJerry Zuo struct dc_state;
904562236bSHarry Wentland struct resource_context;
914562236bSHarry Wentland 
924562236bSHarry Wentland struct resource_funcs {
934562236bSHarry Wentland 	void (*destroy)(struct resource_pool **pool);
944562236bSHarry Wentland 	struct link_encoder *(*link_enc_create)(
954562236bSHarry Wentland 			const struct encoder_init_data *init);
964562236bSHarry Wentland 
974562236bSHarry Wentland 	enum dc_status (*validate_guaranteed)(
98fb3466a4SBhawanpreet Lakha 					struct dc *dc,
990971c40eSHarry Wentland 					struct dc_stream_state *stream,
100608ac7bbSJerry Zuo 					struct dc_state *context);
1014562236bSHarry Wentland 
10245209ef7SDmytro Laktyushkin 	bool (*validate_bandwidth)(
103fb3466a4SBhawanpreet Lakha 					struct dc *dc,
104608ac7bbSJerry Zuo 					struct dc_state *context);
1054562236bSHarry Wentland 
1061dc90497SAndrey Grodzovsky 	enum dc_status (*validate_global)(
1071dc90497SAndrey Grodzovsky 		struct dc *dc,
108608ac7bbSJerry Zuo 		struct dc_state *context);
1091dc90497SAndrey Grodzovsky 
1104562236bSHarry Wentland 	struct pipe_ctx *(*acquire_idle_pipe_for_layer)(
111608ac7bbSJerry Zuo 			struct dc_state *context,
112a2b8659dSTony Cheng 			const struct resource_pool *pool,
1130971c40eSHarry Wentland 			struct dc_stream_state *stream);
1141dc90497SAndrey Grodzovsky 
1158e7095b9SDmytro Laktyushkin 	enum dc_status (*validate_plane)(const struct dc_plane_state *plane_state, struct dc_caps *caps);
1161dc90497SAndrey Grodzovsky 
1171dc90497SAndrey Grodzovsky 	enum dc_status (*add_stream_to_ctx)(
1181dc90497SAndrey Grodzovsky 			struct dc *dc,
119608ac7bbSJerry Zuo 			struct dc_state *new_ctx,
1201dc90497SAndrey Grodzovsky 			struct dc_stream_state *dc_stream);
1214562236bSHarry Wentland };
1224562236bSHarry Wentland 
1234562236bSHarry Wentland struct audio_support{
1244562236bSHarry Wentland 	bool dp_audio;
1254562236bSHarry Wentland 	bool hdmi_audio_on_dongle;
1264562236bSHarry Wentland 	bool hdmi_audio_native;
1274562236bSHarry Wentland };
1284562236bSHarry Wentland 
129f0e3db90SHarry Wentland #define NO_UNDERLAY_PIPE -1
130f0e3db90SHarry Wentland 
1314562236bSHarry Wentland struct resource_pool {
1324562236bSHarry Wentland 	struct mem_input *mis[MAX_PIPES];
1338feabd03SYue Hin Lau 	struct hubp *hubps[MAX_PIPES];
1344562236bSHarry Wentland 	struct input_pixel_processor *ipps[MAX_PIPES];
1354562236bSHarry Wentland 	struct transform *transforms[MAX_PIPES];
1364562236bSHarry Wentland 	struct output_pixel_processor *opps[MAX_PIPES];
1374562236bSHarry Wentland 	struct timing_generator *timing_generators[MAX_PIPES];
1384562236bSHarry Wentland 	struct stream_encoder *stream_enc[MAX_PIPES * 2];
1395f06b3cfSTony Cheng 
140cc408d72SDmytro Laktyushkin 	struct mpc *mpc;
141a185048cSTony Cheng 	struct pp_smu_funcs_rv *pp_smu;
1425f06b3cfSTony Cheng 	struct pp_smu_display_requirement_rv pp_smu_req;
1434562236bSHarry Wentland 
1444562236bSHarry Wentland 	unsigned int pipe_count;
1454562236bSHarry Wentland 	unsigned int underlay_pipe_index;
1464562236bSHarry Wentland 	unsigned int stream_enc_count;
1475ac3d3c9SCharlene Liu 	unsigned int ref_clock_inKhz;
1484562236bSHarry Wentland 
1494562236bSHarry Wentland 	/*
1504562236bSHarry Wentland 	 * reserved clock source for DP
1514562236bSHarry Wentland 	 */
1524562236bSHarry Wentland 	struct clock_source *dp_clock_source;
1534562236bSHarry Wentland 
1544562236bSHarry Wentland 	struct clock_source *clock_sources[MAX_CLOCK_SOURCES];
1554562236bSHarry Wentland 	unsigned int clk_src_count;
1564562236bSHarry Wentland 
1574562236bSHarry Wentland 	struct audio *audios[MAX_PIPES];
1584562236bSHarry Wentland 	unsigned int audio_count;
1594562236bSHarry Wentland 	struct audio_support audio_support;
1604562236bSHarry Wentland 
1614562236bSHarry Wentland 	struct display_clock *display_clock;
1624562236bSHarry Wentland 	struct irq_service *irqs;
1634562236bSHarry Wentland 
1645e7773a2SAnthony Koo 	struct abm *abm;
1655e7773a2SAnthony Koo 	struct dmcu *dmcu;
1665e7773a2SAnthony Koo 
1674562236bSHarry Wentland 	const struct resource_funcs *funcs;
1684562236bSHarry Wentland 	const struct resource_caps *res_cap;
1694562236bSHarry Wentland };
1704562236bSHarry Wentland 
17179b06f0cSHarry Wentland struct stream_resource {
172a6a6cb34SHarry Wentland 	struct output_pixel_processor *opp;
1736b670fa9SHarry Wentland 	struct timing_generator *tg;
1748e9c4c8cSHarry Wentland 	struct stream_encoder *stream_enc;
175afaacef4SHarry Wentland 	struct audio *audio;
17610688217SHarry Wentland 
17710688217SHarry Wentland 	struct pixel_clk_params pix_clk_params;
17896c50c0dSHarry Wentland 	struct encoder_info_frame encoder_info_frame;
17979b06f0cSHarry Wentland };
18079b06f0cSHarry Wentland 
18179b06f0cSHarry Wentland struct plane_resource {
1826702a9acSHarry Wentland 	struct scaler_data scl_data;
1838feabd03SYue Hin Lau 	struct hubp *hubp;
18486a66c4eSHarry Wentland 	struct mem_input *mi;
18586a66c4eSHarry Wentland 	struct input_pixel_processor *ipp;
18686a66c4eSHarry Wentland 	struct transform *xfm;
18779b06f0cSHarry Wentland };
18879b06f0cSHarry Wentland 
1894562236bSHarry Wentland struct pipe_ctx {
1903be5262eSHarry Wentland 	struct dc_plane_state *plane_state;
1910971c40eSHarry Wentland 	struct dc_stream_state *stream;
1924562236bSHarry Wentland 
19379b06f0cSHarry Wentland 	struct plane_resource plane_res;
19479b06f0cSHarry Wentland 	struct stream_resource stream_res;
19579b06f0cSHarry Wentland 
1964562236bSHarry Wentland 	struct clock_source *clock_source;
1974562236bSHarry Wentland 
1984562236bSHarry Wentland 	struct pll_settings pll_settings;
1994562236bSHarry Wentland 
2004562236bSHarry Wentland 	uint8_t pipe_idx;
2014562236bSHarry Wentland 
2024562236bSHarry Wentland 	struct pipe_ctx *top_pipe;
2034562236bSHarry Wentland 	struct pipe_ctx *bottom_pipe;
204f0558542SDmytro Laktyushkin 
205ff5ef992SAlex Deucher #ifdef CONFIG_DRM_AMD_DC_DCN1_0
206ff5ef992SAlex Deucher 	struct _vcs_dpi_display_dlg_regs_st dlg_regs;
207ff5ef992SAlex Deucher 	struct _vcs_dpi_display_ttu_regs_st ttu_regs;
208ff5ef992SAlex Deucher 	struct _vcs_dpi_display_rq_regs_st rq_regs;
209ff5ef992SAlex Deucher 	struct _vcs_dpi_display_pipe_dest_params_st pipe_dlg_param;
210ff5ef992SAlex Deucher #endif
211391e20d8SDuke Du 	struct dwbc *dwbc;
2124562236bSHarry Wentland };
2134562236bSHarry Wentland 
2144562236bSHarry Wentland struct resource_context {
2154562236bSHarry Wentland 	struct pipe_ctx pipe_ctx[MAX_PIPES];
2164562236bSHarry Wentland 	bool is_stream_enc_acquired[MAX_PIPES * 2];
2174562236bSHarry Wentland 	bool is_audio_acquired[MAX_PIPES];
2184562236bSHarry Wentland 	uint8_t clock_source_ref_count[MAX_CLOCK_SOURCES];
2194562236bSHarry Wentland 	uint8_t dp_clock_source_ref_count;
2204562236bSHarry Wentland };
2214562236bSHarry Wentland 
2229037d802SDmytro Laktyushkin struct dce_bw_output {
2239037d802SDmytro Laktyushkin 	bool cpuc_state_change_enable;
2249037d802SDmytro Laktyushkin 	bool cpup_state_change_enable;
2259037d802SDmytro Laktyushkin 	bool stutter_mode_enable;
2269037d802SDmytro Laktyushkin 	bool nbp_state_change_enable;
2279037d802SDmytro Laktyushkin 	bool all_displays_in_sync;
2289037d802SDmytro Laktyushkin 	struct dce_watermarks urgent_wm_ns[MAX_PIPES];
2299037d802SDmytro Laktyushkin 	struct dce_watermarks stutter_exit_wm_ns[MAX_PIPES];
2309037d802SDmytro Laktyushkin 	struct dce_watermarks nbp_state_change_wm_ns[MAX_PIPES];
2319037d802SDmytro Laktyushkin 	int sclk_khz;
2329037d802SDmytro Laktyushkin 	int sclk_deep_sleep_khz;
2339037d802SDmytro Laktyushkin 	int yclk_khz;
2349037d802SDmytro Laktyushkin 	int dispclk_khz;
2359037d802SDmytro Laktyushkin 	int blackout_recovery_time_us;
2369037d802SDmytro Laktyushkin };
2379037d802SDmytro Laktyushkin 
2389037d802SDmytro Laktyushkin struct dcn_bw_clocks {
2399037d802SDmytro Laktyushkin 	int dispclk_khz;
2409037d802SDmytro Laktyushkin 	bool dppclk_div;
2419037d802SDmytro Laktyushkin 	int dcfclk_khz;
2429037d802SDmytro Laktyushkin 	int dcfclk_deep_sleep_khz;
2439037d802SDmytro Laktyushkin 	int fclk_khz;
2449037d802SDmytro Laktyushkin 	int dram_ccm_us;
2459037d802SDmytro Laktyushkin 	int min_active_dram_ccm_us;
2469037d802SDmytro Laktyushkin };
2479037d802SDmytro Laktyushkin 
2489037d802SDmytro Laktyushkin struct dcn_bw_output {
2499037d802SDmytro Laktyushkin 	struct dcn_bw_clocks cur_clk;
2509037d802SDmytro Laktyushkin 	struct dcn_bw_clocks calc_clk;
2519037d802SDmytro Laktyushkin 	struct dcn_watermark_set watermarks;
2529037d802SDmytro Laktyushkin };
2539037d802SDmytro Laktyushkin 
2549037d802SDmytro Laktyushkin union bw_context {
2559037d802SDmytro Laktyushkin 	struct dcn_bw_output dcn;
2569037d802SDmytro Laktyushkin 	struct dce_bw_output dce;
2579037d802SDmytro Laktyushkin };
2589037d802SDmytro Laktyushkin 
259608ac7bbSJerry Zuo struct dc_state {
2600971c40eSHarry Wentland 	struct dc_stream_state *streams[MAX_PIPES];
261ab2541b6SAric Cyr 	struct dc_stream_status stream_status[MAX_PIPES];
262ab2541b6SAric Cyr 	uint8_t stream_count;
2634562236bSHarry Wentland 
2644562236bSHarry Wentland 	struct resource_context res_ctx;
2654562236bSHarry Wentland 
2664562236bSHarry Wentland 	/* The output from BW and WM calculations. */
2679037d802SDmytro Laktyushkin 	union bw_context bw;
2689037d802SDmytro Laktyushkin 
2695ea81b91SDmytro Laktyushkin 	/* Note: these are big structures, do *not* put on stack! */
2704562236bSHarry Wentland 	struct dm_pp_display_configuration pp_display_cfg;
271ff5ef992SAlex Deucher #ifdef CONFIG_DRM_AMD_DC_DCN1_0
272ff5ef992SAlex Deucher 	struct dcn_bw_internal_vars dcn_bw_vars;
273ff5ef992SAlex Deucher #endif
2748a76708eSAndrey Grodzovsky 
275ab8db3e1SAndrey Grodzovsky 	struct display_clock *dis_clk;
276ab8db3e1SAndrey Grodzovsky 
2778ee5702aSDave Airlie 	struct kref refcount;
2784562236bSHarry Wentland };
2794562236bSHarry Wentland 
2804562236bSHarry Wentland #endif /* _CORE_TYPES_H_ */
281