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