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"
87d94585a0SYue Hin Lau #include "dpp.h"
884562236bSHarry Wentland 
894562236bSHarry Wentland struct resource_pool;
90608ac7bbSJerry Zuo struct dc_state;
914562236bSHarry Wentland struct resource_context;
924562236bSHarry Wentland 
934562236bSHarry Wentland struct resource_funcs {
944562236bSHarry Wentland 	void (*destroy)(struct resource_pool **pool);
954562236bSHarry Wentland 	struct link_encoder *(*link_enc_create)(
964562236bSHarry Wentland 			const struct encoder_init_data *init);
974562236bSHarry Wentland 
9845209ef7SDmytro Laktyushkin 	bool (*validate_bandwidth)(
99fb3466a4SBhawanpreet Lakha 					struct dc *dc,
100608ac7bbSJerry Zuo 					struct dc_state *context);
1014562236bSHarry Wentland 
1021dc90497SAndrey Grodzovsky 	enum dc_status (*validate_global)(
1031dc90497SAndrey Grodzovsky 		struct dc *dc,
104608ac7bbSJerry Zuo 		struct dc_state *context);
1051dc90497SAndrey Grodzovsky 
1064562236bSHarry Wentland 	struct pipe_ctx *(*acquire_idle_pipe_for_layer)(
107608ac7bbSJerry Zuo 			struct dc_state *context,
108a2b8659dSTony Cheng 			const struct resource_pool *pool,
1090971c40eSHarry Wentland 			struct dc_stream_state *stream);
1101dc90497SAndrey Grodzovsky 
1118e7095b9SDmytro Laktyushkin 	enum dc_status (*validate_plane)(const struct dc_plane_state *plane_state, struct dc_caps *caps);
1121dc90497SAndrey Grodzovsky 
1131dc90497SAndrey Grodzovsky 	enum dc_status (*add_stream_to_ctx)(
1141dc90497SAndrey Grodzovsky 			struct dc *dc,
115608ac7bbSJerry Zuo 			struct dc_state *new_ctx,
1161dc90497SAndrey Grodzovsky 			struct dc_stream_state *dc_stream);
117e56ae556SNikola Cornij 
118e56ae556SNikola Cornij 	enum dc_status (*remove_stream_from_ctx)(
119e56ae556SNikola Cornij 				struct dc *dc,
120e56ae556SNikola Cornij 				struct dc_state *new_ctx,
121e56ae556SNikola Cornij 				struct dc_stream_state *stream);
1224562236bSHarry Wentland };
1234562236bSHarry Wentland 
1244562236bSHarry Wentland struct audio_support{
1254562236bSHarry Wentland 	bool dp_audio;
1264562236bSHarry Wentland 	bool hdmi_audio_on_dongle;
1274562236bSHarry Wentland 	bool hdmi_audio_native;
1284562236bSHarry Wentland };
1294562236bSHarry Wentland 
130f0e3db90SHarry Wentland #define NO_UNDERLAY_PIPE -1
131f0e3db90SHarry Wentland 
1324562236bSHarry Wentland struct resource_pool {
1334562236bSHarry Wentland 	struct mem_input *mis[MAX_PIPES];
1348feabd03SYue Hin Lau 	struct hubp *hubps[MAX_PIPES];
1354562236bSHarry Wentland 	struct input_pixel_processor *ipps[MAX_PIPES];
1364562236bSHarry Wentland 	struct transform *transforms[MAX_PIPES];
137d94585a0SYue Hin Lau 	struct dpp *dpps[MAX_PIPES];
1384562236bSHarry Wentland 	struct output_pixel_processor *opps[MAX_PIPES];
1394562236bSHarry Wentland 	struct timing_generator *timing_generators[MAX_PIPES];
1404562236bSHarry Wentland 	struct stream_encoder *stream_enc[MAX_PIPES * 2];
1415f06b3cfSTony Cheng 
142c9ef081dSYue Hin Lau 	struct hubbub *hubbub;
143cc408d72SDmytro Laktyushkin 	struct mpc *mpc;
144a185048cSTony Cheng 	struct pp_smu_funcs_rv *pp_smu;
1455f06b3cfSTony Cheng 	struct pp_smu_display_requirement_rv pp_smu_req;
1464562236bSHarry Wentland 
1474562236bSHarry Wentland 	unsigned int pipe_count;
1484562236bSHarry Wentland 	unsigned int underlay_pipe_index;
1494562236bSHarry Wentland 	unsigned int stream_enc_count;
1505ac3d3c9SCharlene Liu 	unsigned int ref_clock_inKhz;
1510dd6cfe1SDmytro Laktyushkin 	unsigned int dentist_vco_freq_khz;
1523be1406aSYongqiang Sun 	unsigned int timing_generator_count;
1534562236bSHarry Wentland 
1544562236bSHarry Wentland 	/*
1554562236bSHarry Wentland 	 * reserved clock source for DP
1564562236bSHarry Wentland 	 */
1574562236bSHarry Wentland 	struct clock_source *dp_clock_source;
1584562236bSHarry Wentland 
1594562236bSHarry Wentland 	struct clock_source *clock_sources[MAX_CLOCK_SOURCES];
1604562236bSHarry Wentland 	unsigned int clk_src_count;
1614562236bSHarry Wentland 
1624562236bSHarry Wentland 	struct audio *audios[MAX_PIPES];
1634562236bSHarry Wentland 	unsigned int audio_count;
1644562236bSHarry Wentland 	struct audio_support audio_support;
1654562236bSHarry Wentland 
1666ca11246SDmytro Laktyushkin 	struct dccg *dccg;
1674562236bSHarry Wentland 	struct irq_service *irqs;
1684562236bSHarry Wentland 
1695e7773a2SAnthony Koo 	struct abm *abm;
1705e7773a2SAnthony Koo 	struct dmcu *dmcu;
1715e7773a2SAnthony Koo 
1724562236bSHarry Wentland 	const struct resource_funcs *funcs;
1734562236bSHarry Wentland 	const struct resource_caps *res_cap;
1744562236bSHarry Wentland };
1754562236bSHarry Wentland 
176f553e681SDmytro Laktyushkin struct dcn_fe_clocks {
177f553e681SDmytro Laktyushkin 	int dppclk_khz;
178f553e681SDmytro Laktyushkin };
179f553e681SDmytro Laktyushkin 
180f553e681SDmytro Laktyushkin struct dcn_fe_bandwidth {
181f553e681SDmytro Laktyushkin 	struct dcn_fe_clocks calc;
182f553e681SDmytro Laktyushkin 	struct dcn_fe_clocks cur;
183f553e681SDmytro Laktyushkin };
184f553e681SDmytro Laktyushkin 
18579b06f0cSHarry Wentland struct stream_resource {
186a6a6cb34SHarry Wentland 	struct output_pixel_processor *opp;
1876b670fa9SHarry Wentland 	struct timing_generator *tg;
1888e9c4c8cSHarry Wentland 	struct stream_encoder *stream_enc;
189afaacef4SHarry Wentland 	struct audio *audio;
19010688217SHarry Wentland 
19110688217SHarry Wentland 	struct pixel_clk_params pix_clk_params;
19296c50c0dSHarry Wentland 	struct encoder_info_frame encoder_info_frame;
1939aef1a31SSivapiriyanKumarasamy 
1949aef1a31SSivapiriyanKumarasamy 	struct abm *abm;
19579b06f0cSHarry Wentland };
19679b06f0cSHarry Wentland 
19779b06f0cSHarry Wentland struct plane_resource {
1986702a9acSHarry Wentland 	struct scaler_data scl_data;
1998feabd03SYue Hin Lau 	struct hubp *hubp;
20086a66c4eSHarry Wentland 	struct mem_input *mi;
20186a66c4eSHarry Wentland 	struct input_pixel_processor *ipp;
20286a66c4eSHarry Wentland 	struct transform *xfm;
203d94585a0SYue Hin Lau 	struct dpp *dpp;
204e07f541fSYongqiang Sun 	uint8_t mpcc_inst;
205f553e681SDmytro Laktyushkin 
206f553e681SDmytro Laktyushkin 	struct dcn_fe_bandwidth bw;
20779b06f0cSHarry Wentland };
20879b06f0cSHarry Wentland 
2094562236bSHarry Wentland struct pipe_ctx {
2103be5262eSHarry Wentland 	struct dc_plane_state *plane_state;
2110971c40eSHarry Wentland 	struct dc_stream_state *stream;
2124562236bSHarry Wentland 
21379b06f0cSHarry Wentland 	struct plane_resource plane_res;
21479b06f0cSHarry Wentland 	struct stream_resource stream_res;
21579b06f0cSHarry Wentland 
2164562236bSHarry Wentland 	struct clock_source *clock_source;
2174562236bSHarry Wentland 
2184562236bSHarry Wentland 	struct pll_settings pll_settings;
2194562236bSHarry Wentland 
2204562236bSHarry Wentland 	uint8_t pipe_idx;
2214562236bSHarry Wentland 
2224562236bSHarry Wentland 	struct pipe_ctx *top_pipe;
2234562236bSHarry Wentland 	struct pipe_ctx *bottom_pipe;
224f0558542SDmytro Laktyushkin 
225ff5ef992SAlex Deucher #ifdef CONFIG_DRM_AMD_DC_DCN1_0
226ff5ef992SAlex Deucher 	struct _vcs_dpi_display_dlg_regs_st dlg_regs;
227ff5ef992SAlex Deucher 	struct _vcs_dpi_display_ttu_regs_st ttu_regs;
228ff5ef992SAlex Deucher 	struct _vcs_dpi_display_rq_regs_st rq_regs;
229ff5ef992SAlex Deucher 	struct _vcs_dpi_display_pipe_dest_params_st pipe_dlg_param;
230ff5ef992SAlex Deucher #endif
2314562236bSHarry Wentland };
2324562236bSHarry Wentland 
2334562236bSHarry Wentland struct resource_context {
2344562236bSHarry Wentland 	struct pipe_ctx pipe_ctx[MAX_PIPES];
2354562236bSHarry Wentland 	bool is_stream_enc_acquired[MAX_PIPES * 2];
2364562236bSHarry Wentland 	bool is_audio_acquired[MAX_PIPES];
2374562236bSHarry Wentland 	uint8_t clock_source_ref_count[MAX_CLOCK_SOURCES];
2384562236bSHarry Wentland 	uint8_t dp_clock_source_ref_count;
2394562236bSHarry Wentland };
2404562236bSHarry Wentland 
2419037d802SDmytro Laktyushkin struct dce_bw_output {
2429037d802SDmytro Laktyushkin 	bool cpuc_state_change_enable;
2439037d802SDmytro Laktyushkin 	bool cpup_state_change_enable;
2449037d802SDmytro Laktyushkin 	bool stutter_mode_enable;
2459037d802SDmytro Laktyushkin 	bool nbp_state_change_enable;
2469037d802SDmytro Laktyushkin 	bool all_displays_in_sync;
2479037d802SDmytro Laktyushkin 	struct dce_watermarks urgent_wm_ns[MAX_PIPES];
2489037d802SDmytro Laktyushkin 	struct dce_watermarks stutter_exit_wm_ns[MAX_PIPES];
249b361521fSMikita Lipski 	struct dce_watermarks stutter_entry_wm_ns[MAX_PIPES];
2509037d802SDmytro Laktyushkin 	struct dce_watermarks nbp_state_change_wm_ns[MAX_PIPES];
2519037d802SDmytro Laktyushkin 	int sclk_khz;
2529037d802SDmytro Laktyushkin 	int sclk_deep_sleep_khz;
2539037d802SDmytro Laktyushkin 	int yclk_khz;
2549037d802SDmytro Laktyushkin 	int dispclk_khz;
2559037d802SDmytro Laktyushkin 	int blackout_recovery_time_us;
2569037d802SDmytro Laktyushkin };
2579037d802SDmytro Laktyushkin 
2589037d802SDmytro Laktyushkin struct dcn_bw_output {
259d578839cSDmytro Laktyushkin 	struct dc_clocks clk;
2609037d802SDmytro Laktyushkin 	struct dcn_watermark_set watermarks;
2619037d802SDmytro Laktyushkin };
2629037d802SDmytro Laktyushkin 
2639037d802SDmytro Laktyushkin union bw_context {
2649037d802SDmytro Laktyushkin 	struct dcn_bw_output dcn;
2659037d802SDmytro Laktyushkin 	struct dce_bw_output dce;
2669037d802SDmytro Laktyushkin };
2679037d802SDmytro Laktyushkin 
268608ac7bbSJerry Zuo struct dc_state {
2690971c40eSHarry Wentland 	struct dc_stream_state *streams[MAX_PIPES];
270ab2541b6SAric Cyr 	struct dc_stream_status stream_status[MAX_PIPES];
271ab2541b6SAric Cyr 	uint8_t stream_count;
2724562236bSHarry Wentland 
2734562236bSHarry Wentland 	struct resource_context res_ctx;
2744562236bSHarry Wentland 
2754562236bSHarry Wentland 	/* The output from BW and WM calculations. */
2769037d802SDmytro Laktyushkin 	union bw_context bw;
2779037d802SDmytro Laktyushkin 
2785ea81b91SDmytro Laktyushkin 	/* Note: these are big structures, do *not* put on stack! */
2794562236bSHarry Wentland 	struct dm_pp_display_configuration pp_display_cfg;
280ff5ef992SAlex Deucher #ifdef CONFIG_DRM_AMD_DC_DCN1_0
281ff5ef992SAlex Deucher 	struct dcn_bw_internal_vars dcn_bw_vars;
282ff5ef992SAlex Deucher #endif
2838a76708eSAndrey Grodzovsky 
2846ca11246SDmytro Laktyushkin 	struct dccg *dis_clk;
285ab8db3e1SAndrey Grodzovsky 
2868ee5702aSDave Airlie 	struct kref refcount;
2874562236bSHarry Wentland };
2884562236bSHarry Wentland 
2894562236bSHarry Wentland #endif /* _CORE_TYPES_H_ */
290