14562236bSHarry Wentland /* 24562236bSHarry Wentland * Copyright 2016 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 284562236bSHarry Wentland 294562236bSHarry Wentland /* 304562236bSHarry Wentland * Copyright 2016 Advanced Micro Devices, Inc. 314562236bSHarry Wentland * 324562236bSHarry Wentland * Permission is hereby granted, free of charge, to any person obtaining a 334562236bSHarry Wentland * copy of this software and associated documentation files (the "Software"), 344562236bSHarry Wentland * to deal in the Software without restriction, including without limitation 354562236bSHarry Wentland * the rights to use, copy, modify, merge, publish, distribute, sublicense, 364562236bSHarry Wentland * and/or sell copies of the Software, and to permit persons to whom the 374562236bSHarry Wentland * Software is furnished to do so, subject to the following conditions: 384562236bSHarry Wentland * 394562236bSHarry Wentland * The above copyright notice and this permission notice shall be included in 404562236bSHarry Wentland * all copies or substantial portions of the Software. 414562236bSHarry Wentland * 424562236bSHarry Wentland * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 434562236bSHarry Wentland * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 444562236bSHarry Wentland * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 454562236bSHarry Wentland * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR 464562236bSHarry Wentland * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 474562236bSHarry Wentland * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 484562236bSHarry Wentland * OTHER DEALINGS IN THE SOFTWARE. 494562236bSHarry Wentland * 504562236bSHarry Wentland * Authors: AMD 514562236bSHarry Wentland * 524562236bSHarry Wentland */ 534562236bSHarry Wentland 544562236bSHarry Wentland #ifndef MOD_FREESYNC_H_ 554562236bSHarry Wentland #define MOD_FREESYNC_H_ 564562236bSHarry Wentland 57c2791297SSivapiriyanKumarasamy #include "mod_shared.h" 584562236bSHarry Wentland 5998e6436dSAnthony Koo // Access structures 604562236bSHarry Wentland struct mod_freesync { 614562236bSHarry Wentland int dummy; 624562236bSHarry Wentland }; 634562236bSHarry Wentland 6498e6436dSAnthony Koo // TODO: References to this should be removed 654562236bSHarry Wentland struct mod_freesync_caps { 664562236bSHarry Wentland bool supported; 674562236bSHarry Wentland unsigned int min_refresh_in_micro_hz; 684562236bSHarry Wentland unsigned int max_refresh_in_micro_hz; 694562236bSHarry Wentland }; 704562236bSHarry Wentland 7198e6436dSAnthony Koo enum mod_vrr_state { 7298e6436dSAnthony Koo VRR_STATE_UNSUPPORTED = 0, 7398e6436dSAnthony Koo VRR_STATE_DISABLED, 7498e6436dSAnthony Koo VRR_STATE_INACTIVE, 7598e6436dSAnthony Koo VRR_STATE_ACTIVE_VARIABLE, 7698e6436dSAnthony Koo VRR_STATE_ACTIVE_FIXED 774562236bSHarry Wentland }; 784562236bSHarry Wentland 7998e6436dSAnthony Koo struct mod_freesync_config { 8098e6436dSAnthony Koo enum mod_vrr_state state; 8169ff8845SAnthony Koo bool vsif_supported; 8298e6436dSAnthony Koo bool ramping; 8398e6436dSAnthony Koo bool btr; 8498e6436dSAnthony Koo unsigned int min_refresh_in_uhz; 8598e6436dSAnthony Koo unsigned int max_refresh_in_uhz; 86d2bacc38SHaiyi Zhou unsigned int fixed_refresh_in_uhz; 87d2bacc38SHaiyi Zhou 8898e6436dSAnthony Koo }; 894562236bSHarry Wentland 9098e6436dSAnthony Koo struct mod_vrr_params_btr { 9198e6436dSAnthony Koo bool btr_enabled; 9298e6436dSAnthony Koo bool btr_active; 9398e6436dSAnthony Koo uint32_t mid_point_in_us; 9498e6436dSAnthony Koo uint32_t inserted_duration_in_us; 9598e6436dSAnthony Koo uint32_t frames_to_insert; 9698e6436dSAnthony Koo uint32_t frame_counter; 97ded6119eSAmanda Liu uint32_t margin_in_us; 9898e6436dSAnthony Koo }; 994562236bSHarry Wentland 10098e6436dSAnthony Koo struct mod_vrr_params_fixed_refresh { 10198e6436dSAnthony Koo bool fixed_active; 10298e6436dSAnthony Koo bool ramping_active; 10398e6436dSAnthony Koo bool ramping_done; 10498e6436dSAnthony Koo uint32_t target_refresh_in_uhz; 10598e6436dSAnthony Koo uint32_t frame_counter; 10698e6436dSAnthony Koo }; 1074562236bSHarry Wentland 1083fe5739dSAngus Wang struct mod_vrr_params_flip_interval { 1093fe5739dSAngus Wang bool flip_interval_workaround_active; 1103fe5739dSAngus Wang bool program_flip_interval_workaround; 1113fe5739dSAngus Wang bool do_flip_interval_workaround_cleanup; 1123fe5739dSAngus Wang uint32_t flip_interval_detect_counter; 1133fe5739dSAngus Wang uint32_t vsyncs_between_flip; 1143fe5739dSAngus Wang uint32_t vsync_to_flip_in_us; 1153fe5739dSAngus Wang uint32_t v_update_timestamp_in_us; 1163fe5739dSAngus Wang }; 1173fe5739dSAngus Wang 11898e6436dSAnthony Koo struct mod_vrr_params { 11998e6436dSAnthony Koo bool supported; 120ca35899cSBayan Zabihiyan bool send_info_frame; 12198e6436dSAnthony Koo enum mod_vrr_state state; 1224562236bSHarry Wentland 12398e6436dSAnthony Koo uint32_t min_refresh_in_uhz; 12498e6436dSAnthony Koo uint32_t max_duration_in_us; 12598e6436dSAnthony Koo uint32_t max_refresh_in_uhz; 12698e6436dSAnthony Koo uint32_t min_duration_in_us; 127d2bacc38SHaiyi Zhou uint32_t fixed_refresh_in_uhz; 1284562236bSHarry Wentland 12998e6436dSAnthony Koo struct dc_crtc_timing_adjust adjust; 1304562236bSHarry Wentland 13198e6436dSAnthony Koo struct mod_vrr_params_fixed_refresh fixed; 1321a87fbfeSAmy Zhang 13398e6436dSAnthony Koo struct mod_vrr_params_btr btr; 1343fe5739dSAngus Wang 1353fe5739dSAngus Wang struct mod_vrr_params_flip_interval flip_interval; 13698e6436dSAnthony Koo }; 13772ada5f7SEric Cook 13898e6436dSAnthony Koo struct mod_freesync *mod_freesync_create(struct dc *dc); 13998e6436dSAnthony Koo void mod_freesync_destroy(struct mod_freesync *mod_freesync); 14072ada5f7SEric Cook 14172ada5f7SEric Cook bool mod_freesync_get_vmin_vmax(struct mod_freesync *mod_freesync, 14298e6436dSAnthony Koo const struct dc_stream_state *stream, 14372ada5f7SEric Cook unsigned int *vmin, 14472ada5f7SEric Cook unsigned int *vmax); 14572ada5f7SEric Cook 14672ada5f7SEric Cook bool mod_freesync_get_v_position(struct mod_freesync *mod_freesync, 1470971c40eSHarry Wentland struct dc_stream_state *stream, 14872ada5f7SEric Cook unsigned int *nom_v_pos, 14972ada5f7SEric Cook unsigned int *v_pos); 15072ada5f7SEric Cook 151a3e1737eSAnthony Koo void mod_freesync_get_settings(struct mod_freesync *mod_freesync, 15298e6436dSAnthony Koo const struct mod_vrr_params *vrr, 153a3e1737eSAnthony Koo unsigned int *v_total_min, unsigned int *v_total_max, 154a3e1737eSAnthony Koo unsigned int *event_triggers, 155a3e1737eSAnthony Koo unsigned int *window_min, unsigned int *window_max, 156a3e1737eSAnthony Koo unsigned int *lfc_mid_point_in_us, 157a3e1737eSAnthony Koo unsigned int *inserted_frames, 158a3e1737eSAnthony Koo unsigned int *inserted_duration_in_us); 159a3e1737eSAnthony Koo 16098e6436dSAnthony Koo void mod_freesync_build_vrr_infopacket(struct mod_freesync *mod_freesync, 16198e6436dSAnthony Koo const struct dc_stream_state *stream, 16298e6436dSAnthony Koo const struct mod_vrr_params *vrr, 163c2791297SSivapiriyanKumarasamy enum vrr_packet_type packet_type, 164672e78caSNathan Chancellor enum color_transfer_func app_tf, 1654cda3243SMax.Tseng struct dc_info_packet *infopacket, 1664cda3243SMax.Tseng bool pack_sdp_v1_3); 16798e6436dSAnthony Koo 16898e6436dSAnthony Koo void mod_freesync_build_vrr_params(struct mod_freesync *mod_freesync, 16998e6436dSAnthony Koo const struct dc_stream_state *stream, 17098e6436dSAnthony Koo struct mod_freesync_config *in_config, 17198e6436dSAnthony Koo struct mod_vrr_params *in_out_vrr); 17298e6436dSAnthony Koo 17398e6436dSAnthony Koo void mod_freesync_handle_preflip(struct mod_freesync *mod_freesync, 17498e6436dSAnthony Koo const struct dc_plane_state *plane, 17598e6436dSAnthony Koo const struct dc_stream_state *stream, 17698e6436dSAnthony Koo unsigned int curr_time_stamp_in_us, 17798e6436dSAnthony Koo struct mod_vrr_params *in_out_vrr); 17898e6436dSAnthony Koo 17998e6436dSAnthony Koo void mod_freesync_handle_v_update(struct mod_freesync *mod_freesync, 18098e6436dSAnthony Koo const struct dc_stream_state *stream, 18198e6436dSAnthony Koo struct mod_vrr_params *in_out_vrr); 18298e6436dSAnthony Koo 183ff6014d6SAnthony Koo unsigned long long mod_freesync_calc_nominal_field_rate( 184ff6014d6SAnthony Koo const struct dc_stream_state *stream); 185ff6014d6SAnthony Koo 18649c70eceSAlvin Lee unsigned long long mod_freesync_calc_field_rate_from_timing( 18749c70eceSAlvin Lee unsigned int vtotal, unsigned int htotal, unsigned int pix_clk); 18849c70eceSAlvin Lee 189ad339f69SJaehyun Chung bool mod_freesync_is_valid_range(uint32_t min_refresh_cap_in_uhz, 190e80e9446SAnthony Koo uint32_t max_refresh_cap_in_uhz, 191ad339f69SJaehyun Chung uint32_t nominal_field_rate_in_uhz); 192e80e9446SAnthony Koo 19349c70eceSAlvin Lee unsigned int mod_freesync_calc_v_total_from_refresh( 19449c70eceSAlvin Lee const struct dc_stream_state *stream, 19549c70eceSAlvin Lee unsigned int refresh_in_uhz); 196a9f54ce3SAhmad Othman 197c2fbe663SFelipe Clark // Returns true when FreeSync is supported and enabled (even if it is inactive) 198*ebfb1526SHarry VanZyllDeJong bool mod_freesync_get_freesync_enabled(struct mod_vrr_params *pVrr); 199c2fbe663SFelipe Clark 2004562236bSHarry Wentland #endif 201