1 /*	$NetBSD: mod_freesync.h,v 1.2 2021/12/18 23:45:07 riastradh Exp $	*/
2 
3 /*
4  * Copyright 2016 Advanced Micro Devices, Inc.
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a
7  * copy of this software and associated documentation files (the "Software"),
8  * to deal in the Software without restriction, including without limitation
9  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10  * and/or sell copies of the Software, and to permit persons to whom the
11  * Software is furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in
14  * all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
19  * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
20  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22  * OTHER DEALINGS IN THE SOFTWARE.
23  *
24  * Authors: AMD
25  *
26  */
27 
28 
29 
30 
31 /*
32  * Copyright 2016 Advanced Micro Devices, Inc.
33  *
34  * Permission is hereby granted, free of charge, to any person obtaining a
35  * copy of this software and associated documentation files (the "Software"),
36  * to deal in the Software without restriction, including without limitation
37  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
38  * and/or sell copies of the Software, and to permit persons to whom the
39  * Software is furnished to do so, subject to the following conditions:
40  *
41  * The above copyright notice and this permission notice shall be included in
42  * all copies or substantial portions of the Software.
43  *
44  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
45  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
46  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
47  * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
48  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
49  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
50  * OTHER DEALINGS IN THE SOFTWARE.
51  *
52  * Authors: AMD
53  *
54  */
55 
56 #ifndef MOD_FREESYNC_H_
57 #define MOD_FREESYNC_H_
58 
59 #include "mod_shared.h"
60 
61 // Access structures
62 struct mod_freesync {
63 	int dummy;
64 };
65 
66 // TODO: References to this should be removed
67 struct mod_freesync_caps {
68 	bool supported;
69 	unsigned int min_refresh_in_micro_hz;
70 	unsigned int max_refresh_in_micro_hz;
71 };
72 
73 enum mod_vrr_state {
74 	VRR_STATE_UNSUPPORTED = 0,
75 	VRR_STATE_DISABLED,
76 	VRR_STATE_INACTIVE,
77 	VRR_STATE_ACTIVE_VARIABLE,
78 	VRR_STATE_ACTIVE_FIXED
79 };
80 
81 struct mod_freesync_config {
82 	enum mod_vrr_state state;
83 	bool vsif_supported;
84 	bool ramping;
85 	bool btr;
86 	unsigned int min_refresh_in_uhz;
87 	unsigned int max_refresh_in_uhz;
88 };
89 
90 struct mod_vrr_params_btr {
91 	bool btr_enabled;
92 	bool btr_active;
93 	uint32_t mid_point_in_us;
94 	uint32_t inserted_duration_in_us;
95 	uint32_t frames_to_insert;
96 	uint32_t frame_counter;
97 	uint32_t margin_in_us;
98 };
99 
100 struct mod_vrr_params_fixed_refresh {
101 	bool fixed_active;
102 	bool ramping_active;
103 	bool ramping_done;
104 	uint32_t target_refresh_in_uhz;
105 	uint32_t frame_counter;
106 };
107 
108 struct mod_vrr_params {
109 	bool supported;
110 	bool send_info_frame;
111 	enum mod_vrr_state state;
112 
113 	uint32_t min_refresh_in_uhz;
114 	uint32_t max_duration_in_us;
115 	uint32_t max_refresh_in_uhz;
116 	uint32_t min_duration_in_us;
117 
118 	struct dc_crtc_timing_adjust adjust;
119 
120 	struct mod_vrr_params_fixed_refresh fixed;
121 
122 	struct mod_vrr_params_btr btr;
123 };
124 
125 struct mod_freesync *mod_freesync_create(struct dc *dc);
126 void mod_freesync_destroy(struct mod_freesync *mod_freesync);
127 
128 bool mod_freesync_get_vmin_vmax(struct mod_freesync *mod_freesync,
129 		const struct dc_stream_state *stream,
130 		unsigned int *vmin,
131 		unsigned int *vmax);
132 
133 bool mod_freesync_get_v_position(struct mod_freesync *mod_freesync,
134 		struct dc_stream_state *stream,
135 		unsigned int *nom_v_pos,
136 		unsigned int *v_pos);
137 
138 void mod_freesync_get_settings(struct mod_freesync *mod_freesync,
139 		const struct mod_vrr_params *vrr,
140 		unsigned int *v_total_min, unsigned int *v_total_max,
141 		unsigned int *event_triggers,
142 		unsigned int *window_min, unsigned int *window_max,
143 		unsigned int *lfc_mid_point_in_us,
144 		unsigned int *inserted_frames,
145 		unsigned int *inserted_duration_in_us);
146 
147 void mod_freesync_build_vrr_infopacket(struct mod_freesync *mod_freesync,
148 		const struct dc_stream_state *stream,
149 		const struct mod_vrr_params *vrr,
150 		enum vrr_packet_type packet_type,
151 		enum color_transfer_func app_tf,
152 		struct dc_info_packet *infopacket);
153 
154 void mod_freesync_build_vrr_params(struct mod_freesync *mod_freesync,
155 		const struct dc_stream_state *stream,
156 		struct mod_freesync_config *in_config,
157 		struct mod_vrr_params *in_out_vrr);
158 
159 void mod_freesync_handle_preflip(struct mod_freesync *mod_freesync,
160 		const struct dc_plane_state *plane,
161 		const struct dc_stream_state *stream,
162 		unsigned int curr_time_stamp_in_us,
163 		struct mod_vrr_params *in_out_vrr);
164 
165 void mod_freesync_handle_v_update(struct mod_freesync *mod_freesync,
166 		const struct dc_stream_state *stream,
167 		struct mod_vrr_params *in_out_vrr);
168 
169 unsigned long long mod_freesync_calc_nominal_field_rate(
170 			const struct dc_stream_state *stream);
171 
172 bool mod_freesync_is_valid_range(struct mod_freesync *mod_freesync,
173 		const struct dc_stream_state *stream,
174 		uint32_t min_refresh_cap_in_uhz,
175 		uint32_t max_refresh_cap_in_uhz,
176 		uint32_t min_refresh_request_in_uhz,
177 		uint32_t max_refresh_request_in_uhz);
178 
179 
180 
181 #endif
182