xref: /openbmc/linux/drivers/gpu/drm/amd/display/dc/dc_stream.h (revision e33bbe69149b802c0c77bfb822685772f85388ca)
1 /*
2  * Copyright 2012-14 Advanced Micro Devices, Inc.
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a
5  * copy of this software and associated documentation files (the "Software"),
6  * to deal in the Software without restriction, including without limitation
7  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8  * and/or sell copies of the Software, and to permit persons to whom the
9  * Software is furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be included in
12  * all copies or substantial portions of the Software.
13  *
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
17  * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20  * OTHER DEALINGS IN THE SOFTWARE.
21  *
22  * Authors: AMD
23  *
24  */
25 
26 #ifndef DC_STREAM_H_
27 #define DC_STREAM_H_
28 
29 #include "dc_types.h"
30 #include "grph_object_defs.h"
31 
32 /*******************************************************************************
33  * Stream Interfaces
34  ******************************************************************************/
35 
36 struct dc_stream_status {
37 	int primary_otg_inst;
38 	int stream_enc_inst;
39 	int plane_count;
40 	struct dc_plane_state *plane_states[MAX_SURFACE_NUM];
41 
42 	/*
43 	 * link this stream passes through
44 	 */
45 	struct dc_link *link;
46 };
47 
48 struct dc_stream_state {
49 	struct dc_sink *sink;
50 	struct dc_crtc_timing timing;
51 	struct dc_crtc_timing_adjust timing_adjust;
52 	struct vrr_params vrr_params;
53 
54 	struct rect src; /* composition area */
55 	struct rect dst; /* stream addressable area */
56 
57 	struct audio_info audio_info;
58 
59 	struct freesync_context freesync_ctx;
60 
61 	struct dc_hdr_static_metadata hdr_static_metadata;
62 	struct dc_transfer_func *out_transfer_func;
63 	struct colorspace_transform gamut_remap_matrix;
64 	struct csc_transform csc_color_matrix;
65 
66 	enum dc_color_space output_color_space;
67 	enum dc_dither_option dither_option;
68 
69 	enum view_3d_format view_format;
70 	enum color_transfer_func output_tf;
71 
72 	bool ignore_msa_timing_param;
73 	/* TODO: custom INFO packets */
74 	/* TODO: ABM info (DMCU) */
75 	/* PSR info */
76 	unsigned char psr_version;
77 	/* TODO: CEA VIC */
78 
79 	/* DMCU info */
80 	unsigned int abm_level;
81 	unsigned int bl_pwm_level;
82 
83 	/* from core_stream struct */
84 	struct dc_context *ctx;
85 
86 	/* used by DCP and FMT */
87 	struct bit_depth_reduction_params bit_depth_params;
88 	struct clamping_and_pixel_encoding_params clamping;
89 
90 	int phy_pix_clk;
91 	enum signal_type signal;
92 	bool dpms_off;
93 
94 	struct dc_stream_status status;
95 
96 	struct dc_cursor_attributes cursor_attributes;
97 	struct dc_cursor_position cursor_position;
98 
99 	/* from stream struct */
100 	struct kref refcount;
101 
102 	struct crtc_trigger_info triggered_crtc_reset;
103 
104 	/* Computed state bits */
105 	bool mode_changed : 1;
106 
107 };
108 
109 struct dc_stream_update {
110 	struct rect src;
111 	struct rect dst;
112 	struct dc_transfer_func *out_transfer_func;
113 	struct dc_hdr_static_metadata *hdr_static_metadata;
114 	enum color_transfer_func color_output_tf;
115 	unsigned int *abm_level;
116 };
117 
118 bool dc_is_stream_unchanged(
119 	struct dc_stream_state *old_stream, struct dc_stream_state *stream);
120 bool dc_is_stream_scaling_unchanged(
121 	struct dc_stream_state *old_stream, struct dc_stream_state *stream);
122 
123 /*
124  * Set up surface attributes and associate to a stream
125  * The surfaces parameter is an absolute set of all surface active for the stream.
126  * If no surfaces are provided, the stream will be blanked; no memory read.
127  * Any flip related attribute changes must be done through this interface.
128  *
129  * After this call:
130  *   Surfaces attributes are programmed and configured to be composed into stream.
131  *   This does not trigger a flip.  No surface address is programmed.
132  */
133 
134 bool dc_commit_planes_to_stream(
135 		struct dc *dc,
136 		struct dc_plane_state **plane_states,
137 		uint8_t new_plane_count,
138 		struct dc_stream_state *dc_stream,
139 		struct dc_state *state);
140 
141 void dc_commit_updates_for_stream(struct dc *dc,
142 		struct dc_surface_update *srf_updates,
143 		int surface_count,
144 		struct dc_stream_state *stream,
145 		struct dc_stream_update *stream_update,
146 		struct dc_plane_state **plane_states,
147 		struct dc_state *state);
148 /*
149  * Log the current stream state.
150  */
151 void dc_stream_log(
152 	const struct dc_stream_state *stream,
153 	struct dal_logger *dc_logger,
154 	enum dc_log_type log_type);
155 
156 uint8_t dc_get_current_stream_count(struct dc *dc);
157 struct dc_stream_state *dc_get_stream_at_index(struct dc *dc, uint8_t i);
158 
159 /*
160  * Return the current frame counter.
161  */
162 uint32_t dc_stream_get_vblank_counter(const struct dc_stream_state *stream);
163 
164 /* TODO: Return parsed values rather than direct register read
165  * This has a dependency on the caller (amdgpu_display_get_crtc_scanoutpos)
166  * being refactored properly to be dce-specific
167  */
168 bool dc_stream_get_scanoutpos(const struct dc_stream_state *stream,
169 				  uint32_t *v_blank_start,
170 				  uint32_t *v_blank_end,
171 				  uint32_t *h_position,
172 				  uint32_t *v_position);
173 
174 enum dc_status dc_add_stream_to_ctx(
175 			struct dc *dc,
176 		struct dc_state *new_ctx,
177 		struct dc_stream_state *stream);
178 
179 enum dc_status dc_remove_stream_from_ctx(
180 		struct dc *dc,
181 			struct dc_state *new_ctx,
182 			struct dc_stream_state *stream);
183 
184 
185 bool dc_add_plane_to_context(
186 		const struct dc *dc,
187 		struct dc_stream_state *stream,
188 		struct dc_plane_state *plane_state,
189 		struct dc_state *context);
190 
191 bool dc_remove_plane_from_context(
192 		const struct dc *dc,
193 		struct dc_stream_state *stream,
194 		struct dc_plane_state *plane_state,
195 		struct dc_state *context);
196 
197 bool dc_rem_all_planes_for_stream(
198 		const struct dc *dc,
199 		struct dc_stream_state *stream,
200 		struct dc_state *context);
201 
202 bool dc_add_all_planes_for_stream(
203 		const struct dc *dc,
204 		struct dc_stream_state *stream,
205 		struct dc_plane_state * const *plane_states,
206 		int plane_count,
207 		struct dc_state *context);
208 
209 enum dc_status dc_validate_stream(struct dc *dc, struct dc_stream_state *stream);
210 
211 /*
212  * This function takes a stream and checks if it is guaranteed to be supported.
213  * Guaranteed means that MAX_COFUNC similar streams are supported.
214  *
215  * After this call:
216  *   No hardware is programmed for call.  Only validation is done.
217  */
218 
219 /*
220  * Set up streams and links associated to drive sinks
221  * The streams parameter is an absolute set of all active streams.
222  *
223  * After this call:
224  *   Phy, Encoder, Timing Generator are programmed and enabled.
225  *   New streams are enabled with blank stream; no memory read.
226  */
227 /*
228  * Enable stereo when commit_streams is not required,
229  * for example, frame alternate.
230  */
231 bool dc_enable_stereo(
232 	struct dc *dc,
233 	struct dc_state *context,
234 	struct dc_stream_state *streams[],
235 	uint8_t stream_count);
236 
237 
238 enum surface_update_type dc_check_update_surfaces_for_stream(
239 		struct dc *dc,
240 		struct dc_surface_update *updates,
241 		int surface_count,
242 		struct dc_stream_update *stream_update,
243 		const struct dc_stream_status *stream_status);
244 
245 /**
246  * Create a new default stream for the requested sink
247  */
248 struct dc_stream_state *dc_create_stream_for_sink(struct dc_sink *dc_sink);
249 
250 void update_stream_signal(struct dc_stream_state *stream);
251 
252 void dc_stream_retain(struct dc_stream_state *dc_stream);
253 void dc_stream_release(struct dc_stream_state *dc_stream);
254 
255 struct dc_stream_status *dc_stream_get_status(
256 	struct dc_stream_state *dc_stream);
257 
258 /*******************************************************************************
259  * Cursor interfaces - To manages the cursor within a stream
260  ******************************************************************************/
261 /* TODO: Deprecated once we switch to dc_set_cursor_position */
262 bool dc_stream_set_cursor_attributes(
263 	struct dc_stream_state *stream,
264 	const struct dc_cursor_attributes *attributes);
265 
266 bool dc_stream_set_cursor_position(
267 	struct dc_stream_state *stream,
268 	const struct dc_cursor_position *position);
269 
270 bool dc_stream_adjust_vmin_vmax(struct dc *dc,
271 				struct dc_stream_state **stream,
272 				int num_streams,
273 				int vmin,
274 				int vmax);
275 
276 bool dc_stream_get_crtc_position(struct dc *dc,
277 				 struct dc_stream_state **stream,
278 				 int num_streams,
279 				 unsigned int *v_pos,
280 				 unsigned int *nom_v_pos);
281 
282 bool dc_stream_configure_crc(struct dc *dc,
283 			     struct dc_stream_state *stream,
284 			     bool enable,
285 			     bool continuous);
286 
287 bool dc_stream_get_crc(struct dc *dc,
288 		       struct dc_stream_state *stream,
289 		       uint32_t *r_cr,
290 		       uint32_t *g_y,
291 		       uint32_t *b_cb);
292 
293 void dc_stream_set_static_screen_events(struct dc *dc,
294 					struct dc_stream_state **stream,
295 					int num_streams,
296 					const struct dc_static_screen_events *events);
297 
298 void dc_stream_set_dither_option(struct dc_stream_state *stream,
299 				 enum dc_dither_option option);
300 
301 
302 bool dc_stream_adjust_vmin_vmax(struct dc *dc,
303 				struct dc_stream_state **stream,
304 				int num_streams,
305 				int vmin,
306 				int vmax);
307 
308 bool dc_stream_get_crtc_position(struct dc *dc,
309 				 struct dc_stream_state **stream,
310 				 int num_streams,
311 				 unsigned int *v_pos,
312 				 unsigned int *nom_v_pos);
313 
314 void dc_stream_set_static_screen_events(struct dc *dc,
315 					struct dc_stream_state **stream,
316 					int num_streams,
317 					const struct dc_static_screen_events *events);
318 
319 #endif /* DC_STREAM_H_ */
320