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; 8698e6436dSAnthony Koo }; 874562236bSHarry Wentland 8898e6436dSAnthony Koo struct mod_vrr_params_btr { 8998e6436dSAnthony Koo bool btr_enabled; 9098e6436dSAnthony Koo bool btr_active; 9198e6436dSAnthony Koo uint32_t mid_point_in_us; 9298e6436dSAnthony Koo uint32_t inserted_duration_in_us; 9398e6436dSAnthony Koo uint32_t frames_to_insert; 9498e6436dSAnthony Koo uint32_t frame_counter; 95ded6119eSAmanda Liu uint32_t margin_in_us; 9698e6436dSAnthony Koo }; 974562236bSHarry Wentland 9898e6436dSAnthony Koo struct mod_vrr_params_fixed_refresh { 9998e6436dSAnthony Koo bool fixed_active; 10098e6436dSAnthony Koo bool ramping_active; 10198e6436dSAnthony Koo bool ramping_done; 10298e6436dSAnthony Koo uint32_t target_refresh_in_uhz; 10398e6436dSAnthony Koo uint32_t frame_counter; 10498e6436dSAnthony Koo }; 1054562236bSHarry Wentland 10698e6436dSAnthony Koo struct mod_vrr_params { 10798e6436dSAnthony Koo bool supported; 108ca35899cSBayan Zabihiyan bool send_info_frame; 10998e6436dSAnthony Koo enum mod_vrr_state state; 1104562236bSHarry Wentland 11198e6436dSAnthony Koo uint32_t min_refresh_in_uhz; 11298e6436dSAnthony Koo uint32_t max_duration_in_us; 11398e6436dSAnthony Koo uint32_t max_refresh_in_uhz; 11498e6436dSAnthony Koo uint32_t min_duration_in_us; 1154562236bSHarry Wentland 11698e6436dSAnthony Koo struct dc_crtc_timing_adjust adjust; 1174562236bSHarry Wentland 11898e6436dSAnthony Koo struct mod_vrr_params_fixed_refresh fixed; 1191a87fbfeSAmy Zhang 12098e6436dSAnthony Koo struct mod_vrr_params_btr btr; 12198e6436dSAnthony Koo }; 12272ada5f7SEric Cook 12398e6436dSAnthony Koo struct mod_freesync *mod_freesync_create(struct dc *dc); 12498e6436dSAnthony Koo void mod_freesync_destroy(struct mod_freesync *mod_freesync); 12572ada5f7SEric Cook 12672ada5f7SEric Cook bool mod_freesync_get_vmin_vmax(struct mod_freesync *mod_freesync, 12798e6436dSAnthony Koo const struct dc_stream_state *stream, 12872ada5f7SEric Cook unsigned int *vmin, 12972ada5f7SEric Cook unsigned int *vmax); 13072ada5f7SEric Cook 13172ada5f7SEric Cook bool mod_freesync_get_v_position(struct mod_freesync *mod_freesync, 1320971c40eSHarry Wentland struct dc_stream_state *stream, 13372ada5f7SEric Cook unsigned int *nom_v_pos, 13472ada5f7SEric Cook unsigned int *v_pos); 13572ada5f7SEric Cook 136a3e1737eSAnthony Koo void mod_freesync_get_settings(struct mod_freesync *mod_freesync, 13798e6436dSAnthony Koo const struct mod_vrr_params *vrr, 138a3e1737eSAnthony Koo unsigned int *v_total_min, unsigned int *v_total_max, 139a3e1737eSAnthony Koo unsigned int *event_triggers, 140a3e1737eSAnthony Koo unsigned int *window_min, unsigned int *window_max, 141a3e1737eSAnthony Koo unsigned int *lfc_mid_point_in_us, 142a3e1737eSAnthony Koo unsigned int *inserted_frames, 143a3e1737eSAnthony Koo unsigned int *inserted_duration_in_us); 144a3e1737eSAnthony Koo 14598e6436dSAnthony Koo void mod_freesync_build_vrr_infopacket(struct mod_freesync *mod_freesync, 14698e6436dSAnthony Koo const struct dc_stream_state *stream, 14798e6436dSAnthony Koo const struct mod_vrr_params *vrr, 148c2791297SSivapiriyanKumarasamy enum vrr_packet_type packet_type, 149672e78caSNathan Chancellor enum color_transfer_func app_tf, 15098e6436dSAnthony Koo struct dc_info_packet *infopacket); 15198e6436dSAnthony Koo 15298e6436dSAnthony Koo void mod_freesync_build_vrr_params(struct mod_freesync *mod_freesync, 15398e6436dSAnthony Koo const struct dc_stream_state *stream, 15498e6436dSAnthony Koo struct mod_freesync_config *in_config, 15598e6436dSAnthony Koo struct mod_vrr_params *in_out_vrr); 15698e6436dSAnthony Koo 15798e6436dSAnthony Koo void mod_freesync_handle_preflip(struct mod_freesync *mod_freesync, 15898e6436dSAnthony Koo const struct dc_plane_state *plane, 15998e6436dSAnthony Koo const struct dc_stream_state *stream, 16098e6436dSAnthony Koo unsigned int curr_time_stamp_in_us, 16198e6436dSAnthony Koo struct mod_vrr_params *in_out_vrr); 16298e6436dSAnthony Koo 16398e6436dSAnthony Koo void mod_freesync_handle_v_update(struct mod_freesync *mod_freesync, 16498e6436dSAnthony Koo const struct dc_stream_state *stream, 16598e6436dSAnthony Koo struct mod_vrr_params *in_out_vrr); 16698e6436dSAnthony Koo 167ff6014d6SAnthony Koo unsigned long long mod_freesync_calc_nominal_field_rate( 168ff6014d6SAnthony Koo const struct dc_stream_state *stream); 169ff6014d6SAnthony Koo 170e80e9446SAnthony Koo bool mod_freesync_is_valid_range(struct mod_freesync *mod_freesync, 171e80e9446SAnthony Koo const struct dc_stream_state *stream, 172e80e9446SAnthony Koo uint32_t min_refresh_cap_in_uhz, 173e80e9446SAnthony Koo uint32_t max_refresh_cap_in_uhz, 174e80e9446SAnthony Koo uint32_t min_refresh_request_in_uhz, 175e80e9446SAnthony Koo uint32_t max_refresh_request_in_uhz); 176e80e9446SAnthony Koo 177a9f54ce3SAhmad Othman 178a9f54ce3SAhmad Othman 1794562236bSHarry Wentland #endif 180