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; 9598e6436dSAnthony Koo }; 964562236bSHarry Wentland 9798e6436dSAnthony Koo struct mod_vrr_params_fixed_refresh { 9898e6436dSAnthony Koo bool fixed_active; 9998e6436dSAnthony Koo bool ramping_active; 10098e6436dSAnthony Koo bool ramping_done; 10198e6436dSAnthony Koo uint32_t target_refresh_in_uhz; 10298e6436dSAnthony Koo uint32_t frame_counter; 10398e6436dSAnthony Koo }; 1044562236bSHarry Wentland 10598e6436dSAnthony Koo struct mod_vrr_params { 10698e6436dSAnthony Koo bool supported; 10769ff8845SAnthony Koo bool send_vsif; 10898e6436dSAnthony Koo enum mod_vrr_state state; 1094562236bSHarry Wentland 11098e6436dSAnthony Koo uint32_t min_refresh_in_uhz; 11198e6436dSAnthony Koo uint32_t max_duration_in_us; 11298e6436dSAnthony Koo uint32_t max_refresh_in_uhz; 11398e6436dSAnthony Koo uint32_t min_duration_in_us; 1144562236bSHarry Wentland 11598e6436dSAnthony Koo struct dc_crtc_timing_adjust adjust; 1164562236bSHarry Wentland 11798e6436dSAnthony Koo struct mod_vrr_params_fixed_refresh fixed; 1181a87fbfeSAmy Zhang 11998e6436dSAnthony Koo struct mod_vrr_params_btr btr; 12098e6436dSAnthony Koo }; 12172ada5f7SEric Cook 12298e6436dSAnthony Koo struct mod_freesync *mod_freesync_create(struct dc *dc); 12398e6436dSAnthony Koo void mod_freesync_destroy(struct mod_freesync *mod_freesync); 12472ada5f7SEric Cook 12572ada5f7SEric Cook bool mod_freesync_get_vmin_vmax(struct mod_freesync *mod_freesync, 12698e6436dSAnthony Koo const struct dc_stream_state *stream, 12772ada5f7SEric Cook unsigned int *vmin, 12872ada5f7SEric Cook unsigned int *vmax); 12972ada5f7SEric Cook 13072ada5f7SEric Cook bool mod_freesync_get_v_position(struct mod_freesync *mod_freesync, 1310971c40eSHarry Wentland struct dc_stream_state *stream, 13272ada5f7SEric Cook unsigned int *nom_v_pos, 13372ada5f7SEric Cook unsigned int *v_pos); 13472ada5f7SEric Cook 135a3e1737eSAnthony Koo void mod_freesync_get_settings(struct mod_freesync *mod_freesync, 13698e6436dSAnthony Koo const struct mod_vrr_params *vrr, 137a3e1737eSAnthony Koo unsigned int *v_total_min, unsigned int *v_total_max, 138a3e1737eSAnthony Koo unsigned int *event_triggers, 139a3e1737eSAnthony Koo unsigned int *window_min, unsigned int *window_max, 140a3e1737eSAnthony Koo unsigned int *lfc_mid_point_in_us, 141a3e1737eSAnthony Koo unsigned int *inserted_frames, 142a3e1737eSAnthony Koo unsigned int *inserted_duration_in_us); 143a3e1737eSAnthony Koo 14498e6436dSAnthony Koo void mod_freesync_build_vrr_infopacket(struct mod_freesync *mod_freesync, 14598e6436dSAnthony Koo const struct dc_stream_state *stream, 14698e6436dSAnthony Koo const struct mod_vrr_params *vrr, 147c2791297SSivapiriyanKumarasamy enum vrr_packet_type packet_type, 148c2791297SSivapiriyanKumarasamy const enum color_transfer_func *app_tf, 14998e6436dSAnthony Koo struct dc_info_packet *infopacket); 15098e6436dSAnthony Koo 15198e6436dSAnthony Koo void mod_freesync_build_vrr_params(struct mod_freesync *mod_freesync, 15298e6436dSAnthony Koo const struct dc_stream_state *stream, 15398e6436dSAnthony Koo struct mod_freesync_config *in_config, 15498e6436dSAnthony Koo struct mod_vrr_params *in_out_vrr); 15598e6436dSAnthony Koo 15698e6436dSAnthony Koo void mod_freesync_handle_preflip(struct mod_freesync *mod_freesync, 15798e6436dSAnthony Koo const struct dc_plane_state *plane, 15898e6436dSAnthony Koo const struct dc_stream_state *stream, 15998e6436dSAnthony Koo unsigned int curr_time_stamp_in_us, 16098e6436dSAnthony Koo struct mod_vrr_params *in_out_vrr); 16198e6436dSAnthony Koo 16298e6436dSAnthony Koo void mod_freesync_handle_v_update(struct mod_freesync *mod_freesync, 16398e6436dSAnthony Koo const struct dc_stream_state *stream, 16498e6436dSAnthony Koo struct mod_vrr_params *in_out_vrr); 16598e6436dSAnthony Koo 166ff6014d6SAnthony Koo unsigned long long mod_freesync_calc_nominal_field_rate( 167ff6014d6SAnthony Koo const struct dc_stream_state *stream); 168ff6014d6SAnthony Koo 169e80e9446SAnthony Koo bool mod_freesync_is_valid_range(struct mod_freesync *mod_freesync, 170e80e9446SAnthony Koo const struct dc_stream_state *stream, 171e80e9446SAnthony Koo uint32_t min_refresh_cap_in_uhz, 172e80e9446SAnthony Koo uint32_t max_refresh_cap_in_uhz, 173e80e9446SAnthony Koo uint32_t min_refresh_request_in_uhz, 174e80e9446SAnthony Koo uint32_t max_refresh_request_in_uhz); 175e80e9446SAnthony Koo 1764562236bSHarry Wentland #endif 177