xref: /linux/drivers/gpu/drm/amd/display/dc/dc_stream.h (revision 44f57d78)
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 struct timing_sync_info {
36 	int group_id;
37 	int group_size;
38 	bool master;
39 };
40 
41 struct dc_stream_status {
42 	int primary_otg_inst;
43 	int stream_enc_inst;
44 	int plane_count;
45 	struct timing_sync_info timing_sync_info;
46 	struct dc_plane_state *plane_states[MAX_SURFACE_NUM];
47 };
48 
49 // TODO: References to this needs to be removed..
50 struct freesync_context {
51 	bool dummy;
52 };
53 
54 enum vertical_interrupt_ref_point {
55 	START_V_UPDATE = 0,
56 	START_V_SYNC,
57 	INVALID_POINT
58 
59 	//For now, only v_update interrupt is used.
60 	//START_V_BLANK,
61 	//START_V_ACTIVE
62 };
63 
64 struct periodic_interrupt_config {
65 	enum vertical_interrupt_ref_point ref_point;
66 	int lines_offset;
67 };
68 
69 
70 struct dc_stream_state {
71 	// sink is deprecated, new code should not reference
72 	// this pointer
73 	struct dc_sink *sink;
74 
75 	struct dc_link *link;
76 	struct dc_panel_patch sink_patches;
77 	union display_content_support content_support;
78 	struct dc_crtc_timing timing;
79 	struct dc_crtc_timing_adjust adjust;
80 	struct dc_info_packet vrr_infopacket;
81 	struct dc_info_packet vsc_infopacket;
82 	struct dc_info_packet vsp_infopacket;
83 	struct dc_info_packet dpsdp_infopacket;
84 
85 	struct rect src; /* composition area */
86 	struct rect dst; /* stream addressable area */
87 
88 	// TODO: References to this needs to be removed..
89 	struct freesync_context freesync_ctx;
90 
91 	struct audio_info audio_info;
92 
93 	struct dc_info_packet hdr_static_metadata;
94 	PHYSICAL_ADDRESS_LOC dmdata_address;
95 	bool   use_dynamic_meta;
96 
97 	struct dc_transfer_func *out_transfer_func;
98 	struct colorspace_transform gamut_remap_matrix;
99 	struct dc_csc_transform csc_color_matrix;
100 
101 	enum dc_color_space output_color_space;
102 	enum dc_dither_option dither_option;
103 
104 	enum view_3d_format view_format;
105 
106 	bool ignore_msa_timing_param;
107 	bool converter_disable_audio;
108 	uint8_t qs_bit;
109 	uint8_t qy_bit;
110 
111 	/* TODO: custom INFO packets */
112 	/* TODO: ABM info (DMCU) */
113 	/* PSR info */
114 	unsigned char psr_version;
115 	/* TODO: CEA VIC */
116 
117 	/* DMCU info */
118 	unsigned int abm_level;
119 
120 	struct periodic_interrupt_config periodic_interrupt0;
121 	struct periodic_interrupt_config periodic_interrupt1;
122 
123 	/* from core_stream struct */
124 	struct dc_context *ctx;
125 
126 	/* used by DCP and FMT */
127 	struct bit_depth_reduction_params bit_depth_params;
128 	struct clamping_and_pixel_encoding_params clamping;
129 
130 	int phy_pix_clk;
131 	enum signal_type signal;
132 	bool dpms_off;
133 
134 	void *dm_stream_context;
135 
136 	struct dc_cursor_attributes cursor_attributes;
137 	struct dc_cursor_position cursor_position;
138 	uint32_t sdr_white_level; // for boosting (SDR) cursor in HDR mode
139 
140 	/* from stream struct */
141 	struct kref refcount;
142 
143 	struct crtc_trigger_info triggered_crtc_reset;
144 
145 	/* Computed state bits */
146 	bool mode_changed : 1;
147 
148 	/* Output from DC when stream state is committed or altered
149 	 * DC may only access these values during:
150 	 * dc_commit_state, dc_commit_state_no_check, dc_commit_streams
151 	 * values may not change outside of those calls
152 	 */
153 	struct {
154 		// For interrupt management, some hardware instance
155 		// offsets need to be exposed to DM
156 		uint8_t otg_offset;
157 	} out;
158 
159 	bool apply_edp_fast_boot_optimization;
160 	bool apply_seamless_boot_optimization;
161 
162 	uint32_t stream_id;
163 };
164 
165 struct dc_stream_update {
166 	struct rect src;
167 	struct rect dst;
168 	struct dc_transfer_func *out_transfer_func;
169 	struct dc_info_packet *hdr_static_metadata;
170 	unsigned int *abm_level;
171 
172 	struct periodic_interrupt_config *periodic_interrupt0;
173 	struct periodic_interrupt_config *periodic_interrupt1;
174 
175 	struct dc_crtc_timing_adjust *adjust;
176 	struct dc_info_packet *vrr_infopacket;
177 	struct dc_info_packet *vsc_infopacket;
178 	struct dc_info_packet *vsp_infopacket;
179 
180 	bool *dpms_off;
181 
182 	struct colorspace_transform *gamut_remap;
183 	enum dc_color_space *output_color_space;
184 	enum dc_dither_option *dither_option;
185 
186 	struct dc_csc_transform *output_csc_transform;
187 
188 };
189 
190 bool dc_is_stream_unchanged(
191 	struct dc_stream_state *old_stream, struct dc_stream_state *stream);
192 bool dc_is_stream_scaling_unchanged(
193 	struct dc_stream_state *old_stream, struct dc_stream_state *stream);
194 
195 /*
196  * Set up surface attributes and associate to a stream
197  * The surfaces parameter is an absolute set of all surface active for the stream.
198  * If no surfaces are provided, the stream will be blanked; no memory read.
199  * Any flip related attribute changes must be done through this interface.
200  *
201  * After this call:
202  *   Surfaces attributes are programmed and configured to be composed into stream.
203  *   This does not trigger a flip.  No surface address is programmed.
204  */
205 
206 void dc_commit_updates_for_stream(struct dc *dc,
207 		struct dc_surface_update *srf_updates,
208 		int surface_count,
209 		struct dc_stream_state *stream,
210 		struct dc_stream_update *stream_update,
211 		struct dc_state *state);
212 /*
213  * Log the current stream state.
214  */
215 void dc_stream_log(const struct dc *dc, const struct dc_stream_state *stream);
216 
217 uint8_t dc_get_current_stream_count(struct dc *dc);
218 struct dc_stream_state *dc_get_stream_at_index(struct dc *dc, uint8_t i);
219 
220 /*
221  * Return the current frame counter.
222  */
223 uint32_t dc_stream_get_vblank_counter(const struct dc_stream_state *stream);
224 
225 /*
226  * Send dp sdp message.
227  */
228 bool dc_stream_send_dp_sdp(const struct dc_stream_state *stream,
229 		const uint8_t *custom_sdp_message,
230 		unsigned int sdp_message_size);
231 
232 /* TODO: Return parsed values rather than direct register read
233  * This has a dependency on the caller (amdgpu_display_get_crtc_scanoutpos)
234  * being refactored properly to be dce-specific
235  */
236 bool dc_stream_get_scanoutpos(const struct dc_stream_state *stream,
237 				  uint32_t *v_blank_start,
238 				  uint32_t *v_blank_end,
239 				  uint32_t *h_position,
240 				  uint32_t *v_position);
241 
242 enum dc_status dc_add_stream_to_ctx(
243 			struct dc *dc,
244 		struct dc_state *new_ctx,
245 		struct dc_stream_state *stream);
246 
247 enum dc_status dc_remove_stream_from_ctx(
248 		struct dc *dc,
249 			struct dc_state *new_ctx,
250 			struct dc_stream_state *stream);
251 
252 
253 bool dc_add_plane_to_context(
254 		const struct dc *dc,
255 		struct dc_stream_state *stream,
256 		struct dc_plane_state *plane_state,
257 		struct dc_state *context);
258 
259 bool dc_remove_plane_from_context(
260 		const struct dc *dc,
261 		struct dc_stream_state *stream,
262 		struct dc_plane_state *plane_state,
263 		struct dc_state *context);
264 
265 bool dc_rem_all_planes_for_stream(
266 		const struct dc *dc,
267 		struct dc_stream_state *stream,
268 		struct dc_state *context);
269 
270 bool dc_add_all_planes_for_stream(
271 		const struct dc *dc,
272 		struct dc_stream_state *stream,
273 		struct dc_plane_state * const *plane_states,
274 		int plane_count,
275 		struct dc_state *context);
276 
277 enum dc_status dc_validate_stream(struct dc *dc, struct dc_stream_state *stream);
278 
279 /*
280  * Set up streams and links associated to drive sinks
281  * The streams parameter is an absolute set of all active streams.
282  *
283  * After this call:
284  *   Phy, Encoder, Timing Generator are programmed and enabled.
285  *   New streams are enabled with blank stream; no memory read.
286  */
287 /*
288  * Enable stereo when commit_streams is not required,
289  * for example, frame alternate.
290  */
291 bool dc_enable_stereo(
292 	struct dc *dc,
293 	struct dc_state *context,
294 	struct dc_stream_state *streams[],
295 	uint8_t stream_count);
296 
297 
298 enum surface_update_type dc_check_update_surfaces_for_stream(
299 		struct dc *dc,
300 		struct dc_surface_update *updates,
301 		int surface_count,
302 		struct dc_stream_update *stream_update,
303 		const struct dc_stream_status *stream_status);
304 
305 /**
306  * Create a new default stream for the requested sink
307  */
308 struct dc_stream_state *dc_create_stream_for_sink(struct dc_sink *dc_sink);
309 
310 struct dc_stream_state *dc_copy_stream(const struct dc_stream_state *stream);
311 
312 void update_stream_signal(struct dc_stream_state *stream, struct dc_sink *sink);
313 
314 void dc_stream_retain(struct dc_stream_state *dc_stream);
315 void dc_stream_release(struct dc_stream_state *dc_stream);
316 
317 struct dc_stream_status *dc_stream_get_status_from_state(
318 	struct dc_state *state,
319 	struct dc_stream_state *stream);
320 struct dc_stream_status *dc_stream_get_status(
321 	struct dc_stream_state *dc_stream);
322 
323 /*******************************************************************************
324  * Cursor interfaces - To manages the cursor within a stream
325  ******************************************************************************/
326 /* TODO: Deprecated once we switch to dc_set_cursor_position */
327 bool dc_stream_set_cursor_attributes(
328 	struct dc_stream_state *stream,
329 	const struct dc_cursor_attributes *attributes);
330 
331 bool dc_stream_set_cursor_position(
332 	struct dc_stream_state *stream,
333 	const struct dc_cursor_position *position);
334 
335 
336 bool dc_stream_adjust_vmin_vmax(struct dc *dc,
337 				struct dc_stream_state *stream,
338 				struct dc_crtc_timing_adjust *adjust);
339 
340 bool dc_stream_get_crtc_position(struct dc *dc,
341 				 struct dc_stream_state **stream,
342 				 int num_streams,
343 				 unsigned int *v_pos,
344 				 unsigned int *nom_v_pos);
345 
346 bool dc_stream_configure_crc(struct dc *dc,
347 			     struct dc_stream_state *stream,
348 			     bool enable,
349 			     bool continuous);
350 
351 bool dc_stream_get_crc(struct dc *dc,
352 		       struct dc_stream_state *stream,
353 		       uint32_t *r_cr,
354 		       uint32_t *g_y,
355 		       uint32_t *b_cb);
356 
357 void dc_stream_set_static_screen_events(struct dc *dc,
358 					struct dc_stream_state **stream,
359 					int num_streams,
360 					const struct dc_static_screen_events *events);
361 
362 void dc_stream_set_dither_option(struct dc_stream_state *stream,
363 				 enum dc_dither_option option);
364 
365 bool dc_stream_set_gamut_remap(struct dc *dc,
366 			       const struct dc_stream_state *stream);
367 
368 bool dc_stream_program_csc_matrix(struct dc *dc,
369 				  struct dc_stream_state *stream);
370 
371 bool dc_stream_get_crtc_position(struct dc *dc,
372 				 struct dc_stream_state **stream,
373 				 int num_streams,
374 				 unsigned int *v_pos,
375 				 unsigned int *nom_v_pos);
376 
377 #endif /* DC_STREAM_H_ */
378