14562236bSHarry Wentland /*
24562236bSHarry Wentland  * Copyright 2012-15 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 /**
274562236bSHarry Wentland  * This file defines helper functions provided by the Display Manager to
284562236bSHarry Wentland  * Display Core.
294562236bSHarry Wentland  */
304562236bSHarry Wentland #ifndef __DM_HELPERS__
314562236bSHarry Wentland #define __DM_HELPERS__
324562236bSHarry Wentland 
334562236bSHarry Wentland #include "dc_types.h"
344562236bSHarry Wentland #include "dc.h"
354562236bSHarry Wentland 
368c5e9bbbSLyude Paul struct dc_dp_mst_stream_allocation_table;
3781927e28SJude Shih struct aux_payload;
3881927e28SJude Shih enum aux_return_code_type;
398e6a3116SRodrigo Siqueira enum set_config_status;
404562236bSHarry Wentland 
4179037324SBhawanpreet Lakha /*
4279037324SBhawanpreet Lakha  * Allocate memory accessible by the GPU
4379037324SBhawanpreet Lakha  *
4479037324SBhawanpreet Lakha  * frame buffer allocations must be aligned to a 4096-byte boundary
4579037324SBhawanpreet Lakha  *
4679037324SBhawanpreet Lakha  * Returns virtual address, sets addr to physical address
4779037324SBhawanpreet Lakha  */
4879037324SBhawanpreet Lakha void *dm_helpers_allocate_gpu_mem(
4979037324SBhawanpreet Lakha 		struct dc_context *ctx,
5079037324SBhawanpreet Lakha 		enum dc_gpu_mem_alloc_type type,
5179037324SBhawanpreet Lakha 		size_t size,
5279037324SBhawanpreet Lakha 		long long *addr);
5379037324SBhawanpreet Lakha 
5479037324SBhawanpreet Lakha /*
5579037324SBhawanpreet Lakha  * Free the GPU-accessible memory at the virtual address pvMem
5679037324SBhawanpreet Lakha  */
5779037324SBhawanpreet Lakha void dm_helpers_free_gpu_mem(
5879037324SBhawanpreet Lakha 		struct dc_context *ctx,
5979037324SBhawanpreet Lakha 		enum dc_gpu_mem_alloc_type type,
6079037324SBhawanpreet Lakha 		void *pvMem);
6179037324SBhawanpreet Lakha 
624562236bSHarry Wentland enum dc_edid_status dm_helpers_parse_edid_caps(
633c021931SClaudio Suarez 	struct dc_link *link,
644562236bSHarry Wentland 	const struct dc_edid *edid,
654562236bSHarry Wentland 	struct dc_edid_caps *edid_caps);
664562236bSHarry Wentland 
672068afe6SNikola Cornij 
682068afe6SNikola Cornij /*
692068afe6SNikola Cornij  * Update DP branch info
702068afe6SNikola Cornij  */
712068afe6SNikola Cornij void dm_helpers_dp_update_branch_info(
722068afe6SNikola Cornij 		struct dc_context *ctx,
732068afe6SNikola Cornij 		const struct dc_link *link);
742068afe6SNikola Cornij 
754562236bSHarry Wentland /*
764562236bSHarry Wentland  * Writes payload allocation table in immediate downstream device.
774562236bSHarry Wentland  */
784562236bSHarry Wentland bool dm_helpers_dp_mst_write_payload_allocation_table(
794562236bSHarry Wentland 		struct dc_context *ctx,
800971c40eSHarry Wentland 		const struct dc_stream_state *stream,
818c5e9bbbSLyude Paul 		struct dc_dp_mst_stream_allocation_table *proposed_table,
824562236bSHarry Wentland 		bool enable);
834562236bSHarry Wentland 
844562236bSHarry Wentland /*
859cc032b2SMartin Tsai  * poll pending down reply
8622051b63SMartin Tsai  */
8722051b63SMartin Tsai void dm_helpers_dp_mst_poll_pending_down_reply(
8822051b63SMartin Tsai 	struct dc_context *ctx,
8922051b63SMartin Tsai 	const struct dc_link *link);
9022051b63SMartin Tsai 
9122051b63SMartin Tsai /*
92fd92ac1bSHersen Wu  * Clear payload allocation table before enable MST DP link.
93fd92ac1bSHersen Wu  */
94fd92ac1bSHersen Wu void dm_helpers_dp_mst_clear_payload_allocation_table(
95fd92ac1bSHersen Wu 	struct dc_context *ctx,
96fd92ac1bSHersen Wu 	const struct dc_link *link);
97fd92ac1bSHersen Wu 
98fd92ac1bSHersen Wu /*
994562236bSHarry Wentland  * Polls for ACT (allocation change trigger) handled and
1004562236bSHarry Wentland  */
10148af9b91SAlvin Lee enum act_return_status dm_helpers_dp_mst_poll_for_allocation_change_trigger(
1024562236bSHarry Wentland 		struct dc_context *ctx,
1030971c40eSHarry Wentland 		const struct dc_stream_state *stream);
1044562236bSHarry Wentland /*
1054562236bSHarry Wentland  * Sends ALLOCATE_PAYLOAD message.
1064562236bSHarry Wentland  */
10783a79dd6SWayne Lin void dm_helpers_dp_mst_send_payload_allocation(
1084562236bSHarry Wentland 		struct dc_context *ctx,
10983a79dd6SWayne Lin 		const struct dc_stream_state *stream);
11083a79dd6SWayne Lin 
11183a79dd6SWayne Lin /*
11283a79dd6SWayne Lin  * Update mst manager relevant variables
11383a79dd6SWayne Lin  */
11483a79dd6SWayne Lin void dm_helpers_dp_mst_update_mst_mgr_for_deallocation(
11583a79dd6SWayne Lin 		struct dc_context *ctx,
11683a79dd6SWayne Lin 		const struct dc_stream_state *stream);
1174562236bSHarry Wentland 
1184562236bSHarry Wentland bool dm_helpers_dp_mst_start_top_mgr(
1194562236bSHarry Wentland 		struct dc_context *ctx,
1204562236bSHarry Wentland 		const struct dc_link *link,
1214562236bSHarry Wentland 		bool boot);
1224562236bSHarry Wentland 
12387e298d6SIan Chen bool dm_helpers_dp_mst_stop_top_mgr(
1244562236bSHarry Wentland 		struct dc_context *ctx,
1253f16ae82SAurabindo Pillai 		struct dc_link *link);
126ea192af5SMichael Strauss 
127ea192af5SMichael Strauss void dm_helpers_dp_mst_update_branch_bandwidth(
128ea192af5SMichael Strauss 		struct dc_context *ctx,
129ea192af5SMichael Strauss 		struct dc_link *link);
130ea192af5SMichael Strauss 
1314562236bSHarry Wentland /**
1324562236bSHarry Wentland  * OS specific aux read callback.
1334562236bSHarry Wentland  */
1344562236bSHarry Wentland bool dm_helpers_dp_read_dpcd(
1354562236bSHarry Wentland 		struct dc_context *ctx,
1364562236bSHarry Wentland 		const struct dc_link *link,
1374562236bSHarry Wentland 		uint32_t address,
1384562236bSHarry Wentland 		uint8_t *data,
1394562236bSHarry Wentland 		uint32_t size);
1404562236bSHarry Wentland 
1414562236bSHarry Wentland /**
1424562236bSHarry Wentland  * OS specific aux write callback.
1434562236bSHarry Wentland  */
1444562236bSHarry Wentland bool dm_helpers_dp_write_dpcd(
1454562236bSHarry Wentland 		struct dc_context *ctx,
1464562236bSHarry Wentland 		const struct dc_link *link,
1474562236bSHarry Wentland 		uint32_t address,
1484562236bSHarry Wentland 		const uint8_t *data,
1494562236bSHarry Wentland 		uint32_t size);
1504562236bSHarry Wentland 
1514562236bSHarry Wentland bool dm_helpers_submit_i2c(
1524562236bSHarry Wentland 		struct dc_context *ctx,
1534562236bSHarry Wentland 		const struct dc_link *link,
1544562236bSHarry Wentland 		struct i2c_command *cmd);
1554562236bSHarry Wentland 
15697bda032SHarry Wentland bool dm_helpers_dp_write_dsc_enable(
15797bda032SHarry Wentland 		struct dc_context *ctx,
15897bda032SHarry Wentland 		const struct dc_stream_state *stream,
15997bda032SHarry Wentland 		bool enable
16097bda032SHarry Wentland );
161*1619d416SGeorge Shen 
162*1619d416SGeorge Shen bool dm_helpers_dp_write_hblank_reduction(
163*1619d416SGeorge Shen 		struct dc_context *ctx,
164*1619d416SGeorge Shen 		const struct dc_stream_state *stream);
165*1619d416SGeorge Shen 
166aac5db82SHarry Wentland bool dm_helpers_is_dp_sink_present(
167aac5db82SHarry Wentland 		struct dc_link *link);
168aac5db82SHarry Wentland 
1696016cd9dSBing Guo void dm_helpers_mst_enable_stream_features(const struct dc_stream_state *stream);
1706016cd9dSBing Guo 
1717c7f5b15SAndrey Grodzovsky enum dc_edid_status dm_helpers_read_local_edid(
1727c7f5b15SAndrey Grodzovsky 		struct dc_context *ctx,
1737c7f5b15SAndrey Grodzovsky 		struct dc_link *link,
1747c7f5b15SAndrey Grodzovsky 		struct dc_sink *sink);
1757c7f5b15SAndrey Grodzovsky 
176028c4ccfSQingqing Zhuo bool dm_helpers_dp_handle_test_pattern_request(
177028c4ccfSQingqing Zhuo 		struct dc_context *ctx,
178028c4ccfSQingqing Zhuo 		const struct dc_link *link,
179028c4ccfSQingqing Zhuo 		union link_test_pattern dpcd_test_pattern,
180028c4ccfSQingqing Zhuo 		union test_misc dpcd_test_params);
181028c4ccfSQingqing Zhuo 
18215cf3974SDmytro Laktyushkin void dm_set_dcn_clocks(
18315cf3974SDmytro Laktyushkin 		struct dc_context *ctx,
18415cf3974SDmytro Laktyushkin 		struct dc_clocks *clks);
1857c7f5b15SAndrey Grodzovsky 
186ac02dc34SEric Yang void dm_helpers_enable_periodic_detection(struct dc_context *ctx, bool enable);
187ac02dc34SEric Yang 
188f01ee019SFangzhi Zuo void dm_set_phyd32clk(struct dc_context *ctx, int freq_khz);
189f01ee019SFangzhi Zuo 
19081927e28SJude Shih bool dm_helpers_dmub_outbox_interrupt_control(struct dc_context *ctx, bool enable);
19170732504SYongqiang Sun 
192118a3315SNicholas Kazlauskas void dm_helpers_smu_timeout(struct dc_context *ctx, unsigned int msg_id, unsigned int param, unsigned int timeout_us);
193118a3315SNicholas Kazlauskas 
194c1a20f70SIan Chen // 0x1 = Result_OK, 0xFE = Result_UnkmownCmd, 0x0 = Status_Busy
195118a3315SNicholas Kazlauskas #define IS_SMU_TIMEOUT(result) \
196c1a20f70SIan Chen 	(result == 0x0)
197c17a34e0SIan Chen void dm_helpers_init_panel_settings(
198c17a34e0SIan Chen 	struct dc_context *ctx,
199eccff6cdSIan Chen 	struct dc_panel_config *config,
200eccff6cdSIan Chen 	struct dc_sink *sink);
201c17a34e0SIan Chen void dm_helpers_override_panel_settings(
202c17a34e0SIan Chen 	struct dc_context *ctx,
203c17a34e0SIan Chen 	struct dc_panel_config *config);
20481927e28SJude Shih int dm_helper_dmub_aux_transfer_sync(
20581927e28SJude Shih 		struct dc_context *ctx,
20681927e28SJude Shih 		const struct dc_link *link,
20781927e28SJude Shih 		struct aux_payload *payload,
20881927e28SJude Shih 		enum aux_return_code_type *operation_result);
2098e6a3116SRodrigo Siqueira 
21071af9d46SMeenakshikumar Somasundaram int dm_helpers_dmub_set_config_sync(struct dc_context *ctx,
21171af9d46SMeenakshikumar Somasundaram 		const struct dc_link *link,
21271af9d46SMeenakshikumar Somasundaram 		struct set_config_cmd_payload *payload,
21371af9d46SMeenakshikumar Somasundaram 		enum set_config_status *operation_result);
2145b49da02SSung Joon Kim enum adaptive_sync_type dm_get_adaptive_sync_support_type(struct dc_link *link);
215575d0df6Sjinzh 
216575d0df6Sjinzh enum dc_edid_status dm_helpers_get_sbios_edid(struct dc_link *link, struct dc_edid *edid);
217575d0df6Sjinzh 
2185f30ee49SSamson Tam bool dm_helpers_is_fullscreen(struct dc_context *ctx, struct dc_stream_state *stream);
2195f30ee49SSamson Tam bool dm_helpers_is_hdr_on(struct dc_context *ctx, struct dc_stream_state *stream);
2205f30ee49SSamson Tam 
2214562236bSHarry Wentland #endif /* __DM_HELPERS__ */
222