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"
36dc37a9a0SLeo (Sunpeng) Li #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*********************/
8584e7fc05SDmytro Laktyushkin #include "hw/clk_mgr.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);
9566b198ffSDmytro Laktyushkin 	void (*link_init)(struct dc_link *link);
964562236bSHarry Wentland 	struct link_encoder *(*link_enc_create)(
974562236bSHarry Wentland 			const struct encoder_init_data *init);
984562236bSHarry Wentland 
9945209ef7SDmytro Laktyushkin 	bool (*validate_bandwidth)(
100fb3466a4SBhawanpreet Lakha 					struct dc *dc,
101608ac7bbSJerry Zuo 					struct dc_state *context);
1024562236bSHarry Wentland 
1031dc90497SAndrey Grodzovsky 	enum dc_status (*validate_global)(
1041dc90497SAndrey Grodzovsky 		struct dc *dc,
105608ac7bbSJerry Zuo 		struct dc_state *context);
1061dc90497SAndrey Grodzovsky 
1074562236bSHarry Wentland 	struct pipe_ctx *(*acquire_idle_pipe_for_layer)(
108608ac7bbSJerry Zuo 			struct dc_state *context,
109a2b8659dSTony Cheng 			const struct resource_pool *pool,
1100971c40eSHarry Wentland 			struct dc_stream_state *stream);
1111dc90497SAndrey Grodzovsky 
1128e7095b9SDmytro Laktyushkin 	enum dc_status (*validate_plane)(const struct dc_plane_state *plane_state, struct dc_caps *caps);
1131dc90497SAndrey Grodzovsky 
1141dc90497SAndrey Grodzovsky 	enum dc_status (*add_stream_to_ctx)(
1151dc90497SAndrey Grodzovsky 			struct dc *dc,
116608ac7bbSJerry Zuo 			struct dc_state *new_ctx,
1171dc90497SAndrey Grodzovsky 			struct dc_stream_state *dc_stream);
118e56ae556SNikola Cornij 
119e56ae556SNikola Cornij 	enum dc_status (*remove_stream_from_ctx)(
120e56ae556SNikola Cornij 				struct dc *dc,
121e56ae556SNikola Cornij 				struct dc_state *new_ctx,
122e56ae556SNikola Cornij 				struct dc_stream_state *stream);
12374eac5f3SSu Sung Chung 	enum dc_status (*get_default_swizzle_mode)(
12474eac5f3SSu Sung Chung 			struct dc_plane_state *plane_state);
12574eac5f3SSu Sung Chung 
1264562236bSHarry Wentland };
1274562236bSHarry Wentland 
1284562236bSHarry Wentland struct audio_support{
1294562236bSHarry Wentland 	bool dp_audio;
1304562236bSHarry Wentland 	bool hdmi_audio_on_dongle;
1314562236bSHarry Wentland 	bool hdmi_audio_native;
1324562236bSHarry Wentland };
1334562236bSHarry Wentland 
134f0e3db90SHarry Wentland #define NO_UNDERLAY_PIPE -1
135f0e3db90SHarry Wentland 
1364562236bSHarry Wentland struct resource_pool {
1374562236bSHarry Wentland 	struct mem_input *mis[MAX_PIPES];
1388feabd03SYue Hin Lau 	struct hubp *hubps[MAX_PIPES];
1394562236bSHarry Wentland 	struct input_pixel_processor *ipps[MAX_PIPES];
1404562236bSHarry Wentland 	struct transform *transforms[MAX_PIPES];
141d94585a0SYue Hin Lau 	struct dpp *dpps[MAX_PIPES];
1424562236bSHarry Wentland 	struct output_pixel_processor *opps[MAX_PIPES];
1434562236bSHarry Wentland 	struct timing_generator *timing_generators[MAX_PIPES];
1444562236bSHarry Wentland 	struct stream_encoder *stream_enc[MAX_PIPES * 2];
145c9ef081dSYue Hin Lau 	struct hubbub *hubbub;
146cc408d72SDmytro Laktyushkin 	struct mpc *mpc;
1470f1a6ad7SJun Lei 	struct pp_smu_funcs *pp_smu;
1485f06b3cfSTony Cheng 	struct pp_smu_display_requirement_rv pp_smu_req;
1491877ccf6SDavid Francis 	struct dce_aux *engines[MAX_PIPES];
150c85e6e54SDavid Francis 	struct dce_i2c_hw *hw_i2cs[MAX_PIPES];
151c85e6e54SDavid Francis 	struct dce_i2c_sw *sw_i2cs[MAX_PIPES];
152c85e6e54SDavid Francis 	bool i2c_hw_buffer_in_use;
1534562236bSHarry Wentland 
1544562236bSHarry Wentland 	unsigned int pipe_count;
1554562236bSHarry Wentland 	unsigned int underlay_pipe_index;
1564562236bSHarry Wentland 	unsigned int stream_enc_count;
157929c3aaaSEric Bernstein 
1585ac3d3c9SCharlene Liu 	unsigned int ref_clock_inKhz;
1593be1406aSYongqiang Sun 	unsigned int timing_generator_count;
1604562236bSHarry Wentland 
1614562236bSHarry Wentland 	/*
1624562236bSHarry Wentland 	 * reserved clock source for DP
1634562236bSHarry Wentland 	 */
1644562236bSHarry Wentland 	struct clock_source *dp_clock_source;
1654562236bSHarry Wentland 
1664562236bSHarry Wentland 	struct clock_source *clock_sources[MAX_CLOCK_SOURCES];
1674562236bSHarry Wentland 	unsigned int clk_src_count;
1684562236bSHarry Wentland 
1694562236bSHarry Wentland 	struct audio *audios[MAX_PIPES];
1704562236bSHarry Wentland 	unsigned int audio_count;
1714562236bSHarry Wentland 	struct audio_support audio_support;
1724562236bSHarry Wentland 
17384e7fc05SDmytro Laktyushkin 	struct clk_mgr *clk_mgr;
174ea2e8d92SDmytro Laktyushkin 	struct dccg *dccg;
1754562236bSHarry Wentland 	struct irq_service *irqs;
1764562236bSHarry Wentland 
1775e7773a2SAnthony Koo 	struct abm *abm;
1785e7773a2SAnthony Koo 	struct dmcu *dmcu;
1795e7773a2SAnthony Koo 
1804562236bSHarry Wentland 	const struct resource_funcs *funcs;
1814562236bSHarry Wentland 	const struct resource_caps *res_cap;
1824562236bSHarry Wentland };
1834562236bSHarry Wentland 
184f553e681SDmytro Laktyushkin struct dcn_fe_bandwidth {
18569338c1fSDmytro Laktyushkin 	int dppclk_khz;
186f553e681SDmytro Laktyushkin };
187f553e681SDmytro Laktyushkin 
18879b06f0cSHarry Wentland struct stream_resource {
189a6a6cb34SHarry Wentland 	struct output_pixel_processor *opp;
1906b670fa9SHarry Wentland 	struct timing_generator *tg;
1918e9c4c8cSHarry Wentland 	struct stream_encoder *stream_enc;
192afaacef4SHarry Wentland 	struct audio *audio;
19310688217SHarry Wentland 
19410688217SHarry Wentland 	struct pixel_clk_params pix_clk_params;
19596c50c0dSHarry Wentland 	struct encoder_info_frame encoder_info_frame;
1969aef1a31SSivapiriyanKumarasamy 
1979aef1a31SSivapiriyanKumarasamy 	struct abm *abm;
19879b06f0cSHarry Wentland };
19979b06f0cSHarry Wentland 
20079b06f0cSHarry Wentland struct plane_resource {
2016702a9acSHarry Wentland 	struct scaler_data scl_data;
2028feabd03SYue Hin Lau 	struct hubp *hubp;
20386a66c4eSHarry Wentland 	struct mem_input *mi;
20486a66c4eSHarry Wentland 	struct input_pixel_processor *ipp;
20586a66c4eSHarry Wentland 	struct transform *xfm;
206d94585a0SYue Hin Lau 	struct dpp *dpp;
207e07f541fSYongqiang Sun 	uint8_t mpcc_inst;
208f553e681SDmytro Laktyushkin 
209f553e681SDmytro Laktyushkin 	struct dcn_fe_bandwidth bw;
21079b06f0cSHarry Wentland };
21179b06f0cSHarry Wentland 
2124562236bSHarry Wentland struct pipe_ctx {
2133be5262eSHarry Wentland 	struct dc_plane_state *plane_state;
2140971c40eSHarry Wentland 	struct dc_stream_state *stream;
2154562236bSHarry Wentland 
21679b06f0cSHarry Wentland 	struct plane_resource plane_res;
21779b06f0cSHarry Wentland 	struct stream_resource stream_res;
21879b06f0cSHarry Wentland 
2194562236bSHarry Wentland 	struct clock_source *clock_source;
2204562236bSHarry Wentland 
2214562236bSHarry Wentland 	struct pll_settings pll_settings;
2224562236bSHarry Wentland 
2234562236bSHarry Wentland 	uint8_t pipe_idx;
2244562236bSHarry Wentland 
2254562236bSHarry Wentland 	struct pipe_ctx *top_pipe;
2264562236bSHarry Wentland 	struct pipe_ctx *bottom_pipe;
227f0558542SDmytro Laktyushkin 
228dc37a9a0SLeo (Sunpeng) Li #ifdef CONFIG_DRM_AMD_DC_DCN1_0
229ff5ef992SAlex Deucher 	struct _vcs_dpi_display_dlg_regs_st dlg_regs;
230ff5ef992SAlex Deucher 	struct _vcs_dpi_display_ttu_regs_st ttu_regs;
231ff5ef992SAlex Deucher 	struct _vcs_dpi_display_rq_regs_st rq_regs;
232ff5ef992SAlex Deucher 	struct _vcs_dpi_display_pipe_dest_params_st pipe_dlg_param;
233ff5ef992SAlex Deucher #endif
2344562236bSHarry Wentland };
2354562236bSHarry Wentland 
2364562236bSHarry Wentland struct resource_context {
2374562236bSHarry Wentland 	struct pipe_ctx pipe_ctx[MAX_PIPES];
2384562236bSHarry Wentland 	bool is_stream_enc_acquired[MAX_PIPES * 2];
2394562236bSHarry Wentland 	bool is_audio_acquired[MAX_PIPES];
2404562236bSHarry Wentland 	uint8_t clock_source_ref_count[MAX_CLOCK_SOURCES];
2414562236bSHarry Wentland 	uint8_t dp_clock_source_ref_count;
2424562236bSHarry Wentland };
2434562236bSHarry Wentland 
2449037d802SDmytro Laktyushkin struct dce_bw_output {
2459037d802SDmytro Laktyushkin 	bool cpuc_state_change_enable;
2469037d802SDmytro Laktyushkin 	bool cpup_state_change_enable;
2479037d802SDmytro Laktyushkin 	bool stutter_mode_enable;
2489037d802SDmytro Laktyushkin 	bool nbp_state_change_enable;
2499037d802SDmytro Laktyushkin 	bool all_displays_in_sync;
2509037d802SDmytro Laktyushkin 	struct dce_watermarks urgent_wm_ns[MAX_PIPES];
2519037d802SDmytro Laktyushkin 	struct dce_watermarks stutter_exit_wm_ns[MAX_PIPES];
252b361521fSMikita Lipski 	struct dce_watermarks stutter_entry_wm_ns[MAX_PIPES];
2539037d802SDmytro Laktyushkin 	struct dce_watermarks nbp_state_change_wm_ns[MAX_PIPES];
2549037d802SDmytro Laktyushkin 	int sclk_khz;
2559037d802SDmytro Laktyushkin 	int sclk_deep_sleep_khz;
2569037d802SDmytro Laktyushkin 	int yclk_khz;
2579037d802SDmytro Laktyushkin 	int dispclk_khz;
2589037d802SDmytro Laktyushkin 	int blackout_recovery_time_us;
2599037d802SDmytro Laktyushkin };
2609037d802SDmytro Laktyushkin 
2619037d802SDmytro Laktyushkin struct dcn_bw_output {
262d578839cSDmytro Laktyushkin 	struct dc_clocks clk;
2639037d802SDmytro Laktyushkin 	struct dcn_watermark_set watermarks;
2649037d802SDmytro Laktyushkin };
2659037d802SDmytro Laktyushkin 
2669037d802SDmytro Laktyushkin union bw_context {
2679037d802SDmytro Laktyushkin 	struct dcn_bw_output dcn;
2689037d802SDmytro Laktyushkin 	struct dce_bw_output dce;
2699037d802SDmytro Laktyushkin };
2709037d802SDmytro Laktyushkin 
2712119aa17SDavid Francis /**
2722119aa17SDavid Francis  * struct dc_state - The full description of a state requested by a user
2732119aa17SDavid Francis  *
2742119aa17SDavid Francis  * @streams: Stream properties
2752119aa17SDavid Francis  * @stream_status: The planes on a given stream
2762119aa17SDavid Francis  * @res_ctx: Persistent state of resources
2772119aa17SDavid Francis  * @bw: The output from bandwidth and watermark calculations
2782119aa17SDavid Francis  * @pp_display_cfg: PowerPlay clocks and settings
2792119aa17SDavid Francis  * @dcn_bw_vars: non-stack memory to support bandwidth calculations
2802119aa17SDavid Francis  *
2812119aa17SDavid Francis  */
282608ac7bbSJerry Zuo struct dc_state {
2830971c40eSHarry Wentland 	struct dc_stream_state *streams[MAX_PIPES];
284ab2541b6SAric Cyr 	struct dc_stream_status stream_status[MAX_PIPES];
285ab2541b6SAric Cyr 	uint8_t stream_count;
2864562236bSHarry Wentland 
2874562236bSHarry Wentland 	struct resource_context res_ctx;
2884562236bSHarry Wentland 
2899037d802SDmytro Laktyushkin 	union bw_context bw;
2909037d802SDmytro Laktyushkin 
2915ea81b91SDmytro Laktyushkin 	/* Note: these are big structures, do *not* put on stack! */
2924562236bSHarry Wentland 	struct dm_pp_display_configuration pp_display_cfg;
293dc37a9a0SLeo (Sunpeng) Li #ifdef CONFIG_DRM_AMD_DC_DCN1_0
294ff5ef992SAlex Deucher 	struct dcn_bw_internal_vars dcn_bw_vars;
295ff5ef992SAlex Deucher #endif
2968a76708eSAndrey Grodzovsky 
29784e7fc05SDmytro Laktyushkin 	struct clk_mgr *dccg;
298ab8db3e1SAndrey Grodzovsky 
299e85c2d63SJun Lei 	struct {
300e85c2d63SJun Lei 		bool full_update_needed : 1;
301e85c2d63SJun Lei 	} commit_hints;
302e85c2d63SJun Lei 
3038ee5702aSDave Airlie 	struct kref refcount;
3044562236bSHarry Wentland };
3054562236bSHarry Wentland 
3064562236bSHarry Wentland #endif /* _CORE_TYPES_H_ */
307