xref: /linux/drivers/gpu/drm/amd/display/dc/dc_stream.h (revision ab93e0dd72c37d378dd936f031ffb83ff2bd87ce)
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 mall_stream_config {
42 	/* MALL stream config to indicate if the stream is phantom or not.
43 	 * We will use a phantom stream to indicate that the pipe is phantom.
44 	 */
45 	enum mall_stream_type type;
46 	struct dc_stream_state *paired_stream;	// master / slave stream
47 	bool subvp_limit_cursor_size; /* stream has/is using subvp limiting hw cursor support */
48 	bool cursor_size_limit_subvp; /* stream is using hw cursor config preventing subvp */
49 };
50 
51 struct dc_stream_status {
52 	int primary_otg_inst;
53 	int stream_enc_inst;
54 
55 	/**
56 	 * @plane_count: Total of planes attached to a single stream
57 	 */
58 	int plane_count;
59 	int audio_inst;
60 	struct timing_sync_info timing_sync_info;
61 	struct dc_plane_state *plane_states[MAX_SURFACES];
62 	bool is_abm_supported;
63 	struct mall_stream_config mall_stream_config;
64 	bool fpo_in_use;
65 };
66 
67 enum hubp_dmdata_mode {
68 	DMDATA_SW_MODE,
69 	DMDATA_HW_MODE
70 };
71 
72 struct dc_dmdata_attributes {
73 	/* Specifies whether dynamic meta data will be updated by software
74 	 * or has to be fetched by hardware (DMA mode)
75 	 */
76 	enum hubp_dmdata_mode dmdata_mode;
77 	/* Specifies if current dynamic meta data is to be used only for the current frame */
78 	bool dmdata_repeat;
79 	/* Specifies the size of Dynamic Metadata surface in byte.  Size of 0 means no Dynamic metadata is fetched */
80 	uint32_t dmdata_size;
81 	/* Specifies if a new dynamic meta data should be fetched for an upcoming frame */
82 	bool dmdata_updated;
83 	/* If hardware mode is used, the base address where DMDATA surface is located */
84 	PHYSICAL_ADDRESS_LOC address;
85 	/* Specifies whether QOS level will be provided by TTU or it will come from DMDATA_QOS_LEVEL */
86 	bool dmdata_qos_mode;
87 	/* If qos_mode = 1, this is the QOS value to be used: */
88 	uint32_t dmdata_qos_level;
89 	/* Specifies the value in unit of REFCLK cycles to be added to the
90 	 * current time to produce the Amortized deadline for Dynamic Metadata chunk request
91 	 */
92 	uint32_t dmdata_dl_delta;
93 	/* An unbounded array of uint32s, represents software dmdata to be loaded */
94 	uint32_t *dmdata_sw_data;
95 };
96 
97 struct dc_writeback_info {
98 	bool wb_enabled;
99 	int dwb_pipe_inst;
100 	struct dc_dwb_params dwb_params;
101 	struct mcif_buf_params mcif_buf_params;
102 	struct mcif_warmup_params mcif_warmup_params;
103 	/* the plane that is the input to TOP_MUX for MPCC that is the DWB source */
104 	struct dc_plane_state *writeback_source_plane;
105 	/* source MPCC instance.  for use by internally by dc */
106 	int mpcc_inst;
107 };
108 
109 struct dc_writeback_update {
110 	unsigned int num_wb_info;
111 	struct dc_writeback_info writeback_info[MAX_DWB_PIPES];
112 };
113 
114 enum vertical_interrupt_ref_point {
115 	START_V_UPDATE = 0,
116 	START_V_SYNC,
117 	INVALID_POINT
118 
119 	//For now, only v_update interrupt is used.
120 	//START_V_BLANK,
121 	//START_V_ACTIVE
122 };
123 
124 struct periodic_interrupt_config {
125 	enum vertical_interrupt_ref_point ref_point;
126 	int lines_offset;
127 };
128 
129 struct dc_mst_stream_bw_update {
130 	bool is_increase; // is bandwidth reduced or increased
131 	uint32_t mst_stream_bw; // new mst bandwidth in kbps
132 };
133 
134 union stream_update_flags {
135 	struct {
136 		uint32_t scaling:1;
137 		uint32_t out_tf:1;
138 		uint32_t out_csc:1;
139 		uint32_t abm_level:1;
140 		uint32_t dpms_off:1;
141 		uint32_t gamut_remap:1;
142 		uint32_t wb_update:1;
143 		uint32_t dsc_changed : 1;
144 		uint32_t mst_bw : 1;
145 		uint32_t crtc_timing_adjust : 1;
146 		uint32_t fams_changed : 1;
147 		uint32_t scaler_sharpener : 1;
148 		uint32_t sharpening_required : 1;
149 	} bits;
150 
151 	uint32_t raw;
152 };
153 
154 struct test_pattern {
155 	enum dp_test_pattern type;
156 	enum dp_test_pattern_color_space color_space;
157 	struct link_training_settings const *p_link_settings;
158 	unsigned char const *p_custom_pattern;
159 	unsigned int cust_pattern_size;
160 };
161 
162 #define SUBVP_DRR_MARGIN_US 100 // 100us for DRR margin (SubVP + DRR)
163 
164 struct dc_stream_debug_options {
165 	char force_odm_combine_segments;
166 	/*
167 	 * When force_odm_combine_segments is non zero, allow dc to
168 	 * temporarily transition to ODM bypass when minimal transition state
169 	 * is required to prevent visual glitches showing on the screen
170 	 */
171 	char allow_transition_for_forced_odm;
172 };
173 
174 #define LUMINANCE_DATA_TABLE_SIZE 10
175 
176 struct luminance_data {
177 	bool is_valid;
178 	int refresh_rate_hz[LUMINANCE_DATA_TABLE_SIZE];
179 	int luminance_millinits[LUMINANCE_DATA_TABLE_SIZE];
180 	int flicker_criteria_milli_nits_GAMING;
181 	int flicker_criteria_milli_nits_STATIC;
182 	int nominal_refresh_rate;
183 	int dm_max_decrease_from_nominal;
184 };
185 
186 struct dc_stream_state {
187 	// sink is deprecated, new code should not reference
188 	// this pointer
189 	struct dc_sink *sink;
190 
191 	struct dc_link *link;
192 	/* For dynamic link encoder assignment, update the link encoder assigned to
193 	 * a stream via the volatile dc_state rather than the static dc_link.
194 	 */
195 	struct link_encoder *link_enc;
196 	struct dc_stream_debug_options debug;
197 	struct dc_panel_patch sink_patches;
198 	struct dc_crtc_timing timing;
199 	struct dc_crtc_timing_adjust adjust;
200 	struct dc_info_packet vrr_infopacket;
201 	struct dc_info_packet vsc_infopacket;
202 	struct dc_info_packet vsp_infopacket;
203 	struct dc_info_packet hfvsif_infopacket;
204 	struct dc_info_packet vtem_infopacket;
205 	struct dc_info_packet adaptive_sync_infopacket;
206 	uint8_t dsc_packed_pps[128];
207 	struct rect src; /* composition area */
208 	struct rect dst; /* stream addressable area */
209 
210 	struct audio_info audio_info;
211 
212 	struct dc_info_packet hdr_static_metadata;
213 	PHYSICAL_ADDRESS_LOC dmdata_address;
214 	bool   use_dynamic_meta;
215 
216 	struct dc_transfer_func out_transfer_func;
217 	struct colorspace_transform gamut_remap_matrix;
218 	struct dc_csc_transform csc_color_matrix;
219 
220 	enum dc_color_space output_color_space;
221 	enum display_content_type content_type;
222 	enum dc_dither_option dither_option;
223 
224 	enum view_3d_format view_format;
225 
226 	bool use_vsc_sdp_for_colorimetry;
227 	bool ignore_msa_timing_param;
228 
229 	/**
230 	 * @allow_freesync:
231 	 *
232 	 * It say if Freesync is enabled or not.
233 	 */
234 	bool allow_freesync;
235 
236 	/**
237 	 * @vrr_active_variable:
238 	 *
239 	 * It describes if VRR is in use.
240 	 */
241 	bool vrr_active_variable;
242 	bool freesync_on_desktop;
243 	bool vrr_active_fixed;
244 
245 	bool converter_disable_audio;
246 	uint8_t qs_bit;
247 	uint8_t qy_bit;
248 
249 	/* TODO: custom INFO packets */
250 	/* TODO: ABM info (DMCU) */
251 	/* TODO: CEA VIC */
252 
253 	/* DMCU info */
254 	unsigned int abm_level;
255 
256 	struct periodic_interrupt_config periodic_interrupt;
257 
258 	/* from core_stream struct */
259 	struct dc_context *ctx;
260 
261 	/* used by DCP and FMT */
262 	struct bit_depth_reduction_params bit_depth_params;
263 	struct clamping_and_pixel_encoding_params clamping;
264 
265 	int phy_pix_clk;
266 	enum signal_type signal;
267 	bool dpms_off;
268 
269 	void *dm_stream_context;
270 
271 	struct dc_cursor_attributes cursor_attributes;
272 	struct dc_cursor_position cursor_position;
273 	bool hw_cursor_req;
274 
275 	uint32_t sdr_white_level; // for boosting (SDR) cursor in HDR mode
276 
277 	/* from stream struct */
278 	struct kref refcount;
279 
280 	struct crtc_trigger_info triggered_crtc_reset;
281 
282 	/* writeback */
283 	unsigned int num_wb_info;
284 	struct dc_writeback_info writeback_info[MAX_DWB_PIPES];
285 	const struct dc_transfer_func *func_shaper;
286 	const struct dc_3dlut *lut3d_func;
287 	/* Computed state bits */
288 	bool mode_changed : 1;
289 
290 	/* Output from DC when stream state is committed or altered
291 	 * DC may only access these values during:
292 	 * dc_commit_state, dc_commit_state_no_check, dc_commit_streams
293 	 * values may not change outside of those calls
294 	 */
295 	struct {
296 		// For interrupt management, some hardware instance
297 		// offsets need to be exposed to DM
298 		uint8_t otg_offset;
299 	} out;
300 
301 	bool apply_edp_fast_boot_optimization;
302 	bool apply_seamless_boot_optimization;
303 	uint32_t apply_boot_odm_mode;
304 
305 	uint32_t stream_id;
306 
307 	struct test_pattern test_pattern;
308 	union stream_update_flags update_flags;
309 
310 	bool has_non_synchronizable_pclk;
311 	bool vblank_synchronized;
312 	bool is_phantom;
313 
314 	struct luminance_data lumin_data;
315 	bool scaler_sharpener_update;
316 	bool sharpening_required;
317 };
318 
319 #define ABM_LEVEL_IMMEDIATE_DISABLE 255
320 
321 struct dc_stream_update {
322 	struct dc_stream_state *stream;
323 
324 	struct rect src;
325 	struct rect dst;
326 	struct dc_transfer_func *out_transfer_func;
327 	struct dc_info_packet *hdr_static_metadata;
328 	unsigned int *abm_level;
329 
330 	struct periodic_interrupt_config *periodic_interrupt;
331 
332 	struct dc_info_packet *vrr_infopacket;
333 	struct dc_info_packet *vsc_infopacket;
334 	struct dc_info_packet *vsp_infopacket;
335 	struct dc_info_packet *hfvsif_infopacket;
336 	struct dc_info_packet *vtem_infopacket;
337 	struct dc_info_packet *adaptive_sync_infopacket;
338 	bool *dpms_off;
339 	bool integer_scaling_update;
340 	bool *allow_freesync;
341 	bool *vrr_active_variable;
342 	bool *vrr_active_fixed;
343 
344 	struct colorspace_transform *gamut_remap;
345 	enum dc_color_space *output_color_space;
346 	enum dc_dither_option *dither_option;
347 
348 	struct dc_csc_transform *output_csc_transform;
349 
350 	struct dc_writeback_update *wb_update;
351 	struct dc_dsc_config *dsc_config;
352 	struct dc_mst_stream_bw_update *mst_bw_update;
353 	struct dc_transfer_func *func_shaper;
354 	struct dc_3dlut *lut3d_func;
355 
356 	struct test_pattern *pending_test_pattern;
357 	struct dc_crtc_timing_adjust *crtc_timing_adjust;
358 
359 	struct dc_cursor_attributes *cursor_attributes;
360 	struct dc_cursor_position *cursor_position;
361 	bool *hw_cursor_req;
362 	bool *scaler_sharpener_update;
363 	bool *sharpening_required;
364 };
365 
366 bool dc_is_stream_unchanged(
367 	struct dc_stream_state *old_stream, struct dc_stream_state *stream);
368 bool dc_is_stream_scaling_unchanged(
369 	struct dc_stream_state *old_stream, struct dc_stream_state *stream);
370 
371 /*
372  * Setup stream attributes if no stream updates are provided
373  * there will be no impact on the stream parameters
374  *
375  * Set up surface attributes and associate to a stream
376  * The surfaces parameter is an absolute set of all surface active for the stream.
377  * If no surfaces are provided, the stream will be blanked; no memory read.
378  * Any flip related attribute changes must be done through this interface.
379  *
380  * After this call:
381  *   Surfaces attributes are programmed and configured to be composed into stream.
382  *   This does not trigger a flip.  No surface address is programmed.
383  *
384  */
385 bool dc_update_planes_and_stream(struct dc *dc,
386 		struct dc_surface_update *surface_updates, int surface_count,
387 		struct dc_stream_state *dc_stream,
388 		struct dc_stream_update *stream_update);
389 
390 /*
391  * Set up surface attributes and associate to a stream
392  * The surfaces parameter is an absolute set of all surface active for the stream.
393  * If no surfaces are provided, the stream will be blanked; no memory read.
394  * Any flip related attribute changes must be done through this interface.
395  *
396  * After this call:
397  *   Surfaces attributes are programmed and configured to be composed into stream.
398  *   This does not trigger a flip.  No surface address is programmed.
399  */
400 void dc_commit_updates_for_stream(struct dc *dc,
401 		struct dc_surface_update *srf_updates,
402 		int surface_count,
403 		struct dc_stream_state *stream,
404 		struct dc_stream_update *stream_update,
405 		struct dc_state *state);
406 /*
407  * Log the current stream state.
408  */
409 void dc_stream_log(const struct dc *dc, const struct dc_stream_state *stream);
410 
411 uint8_t dc_get_current_stream_count(struct dc *dc);
412 struct dc_stream_state *dc_get_stream_at_index(struct dc *dc, uint8_t i);
413 
414 /*
415  * Return the current frame counter.
416  */
417 uint32_t dc_stream_get_vblank_counter(const struct dc_stream_state *stream);
418 
419 /*
420  * Send dp sdp message.
421  */
422 bool dc_stream_send_dp_sdp(const struct dc_stream_state *stream,
423 		const uint8_t *custom_sdp_message,
424 		unsigned int sdp_message_size);
425 
426 /* TODO: Return parsed values rather than direct register read
427  * This has a dependency on the caller (amdgpu_display_get_crtc_scanoutpos)
428  * being refactored properly to be dce-specific
429  */
430 bool dc_stream_get_scanoutpos(const struct dc_stream_state *stream,
431 				  uint32_t *v_blank_start,
432 				  uint32_t *v_blank_end,
433 				  uint32_t *h_position,
434 				  uint32_t *v_position);
435 
436 bool dc_stream_add_writeback(struct dc *dc,
437 		struct dc_stream_state *stream,
438 		struct dc_writeback_info *wb_info);
439 
440 bool dc_stream_fc_disable_writeback(struct dc *dc,
441 		struct dc_stream_state *stream,
442 		uint32_t dwb_pipe_inst);
443 
444 bool dc_stream_remove_writeback(struct dc *dc,
445 		struct dc_stream_state *stream,
446 		uint32_t dwb_pipe_inst);
447 
448 enum dc_status dc_stream_add_dsc_to_resource(struct dc *dc,
449 		struct dc_state *state,
450 		struct dc_stream_state *stream);
451 
452 bool dc_stream_dmdata_status_done(struct dc *dc, struct dc_stream_state *stream);
453 
454 bool dc_stream_set_dynamic_metadata(struct dc *dc,
455 		struct dc_stream_state *stream,
456 		struct dc_dmdata_attributes *dmdata_attr);
457 
458 enum dc_status dc_validate_stream(struct dc *dc, struct dc_stream_state *stream);
459 
460 /*
461  * Enable stereo when commit_streams is not required,
462  * for example, frame alternate.
463  */
464 void dc_enable_stereo(
465 	struct dc *dc,
466 	struct dc_state *context,
467 	struct dc_stream_state *streams[],
468 	uint8_t stream_count);
469 
470 /* Triggers multi-stream synchronization. */
471 void dc_trigger_sync(struct dc *dc, struct dc_state *context);
472 
473 enum surface_update_type dc_check_update_surfaces_for_stream(
474 		struct dc *dc,
475 		struct dc_surface_update *updates,
476 		int surface_count,
477 		struct dc_stream_update *stream_update,
478 		const struct dc_stream_status *stream_status);
479 
480 /**
481  * Create a new default stream for the requested sink
482  */
483 struct dc_stream_state *dc_create_stream_for_sink(struct dc_sink *dc_sink);
484 
485 struct dc_stream_state *dc_copy_stream(const struct dc_stream_state *stream);
486 
487 void update_stream_signal(struct dc_stream_state *stream, struct dc_sink *sink);
488 
489 void dc_stream_retain(struct dc_stream_state *dc_stream);
490 void dc_stream_release(struct dc_stream_state *dc_stream);
491 
492 struct dc_stream_status *dc_stream_get_status(
493 	struct dc_stream_state *dc_stream);
494 
495 /*******************************************************************************
496  * Cursor interfaces - To manages the cursor within a stream
497  ******************************************************************************/
498 /* TODO: Deprecated once we switch to dc_set_cursor_position */
499 
500 void program_cursor_attributes(
501 	struct dc *dc,
502 	struct dc_stream_state *stream);
503 
504 void program_cursor_position(
505 	struct dc *dc,
506 	struct dc_stream_state *stream);
507 
508 bool dc_stream_check_cursor_attributes(
509 	const struct dc_stream_state *stream,
510 	struct dc_state *state,
511 	const struct dc_cursor_attributes *attributes);
512 
513 bool dc_stream_set_cursor_attributes(
514 	struct dc_stream_state *stream,
515 	const struct dc_cursor_attributes *attributes);
516 
517 bool dc_stream_program_cursor_attributes(
518 	struct dc_stream_state *stream,
519 	const struct dc_cursor_attributes *attributes);
520 
521 bool dc_stream_set_cursor_position(
522 	struct dc_stream_state *stream,
523 	const struct dc_cursor_position *position);
524 
525 bool dc_stream_program_cursor_position(
526 	struct dc_stream_state *stream,
527 	const struct dc_cursor_position *position);
528 
529 
530 bool dc_stream_adjust_vmin_vmax(struct dc *dc,
531 				struct dc_stream_state *stream,
532 				struct dc_crtc_timing_adjust *adjust);
533 
534 bool dc_stream_get_last_used_drr_vtotal(struct dc *dc,
535 		struct dc_stream_state *stream,
536 		uint32_t *refresh_rate);
537 
538 #if defined(CONFIG_DRM_AMD_SECURE_DISPLAY)
539 bool dc_stream_forward_crc_window(struct dc_stream_state *stream,
540 		struct rect *rect,
541 		uint8_t phy_id,
542 		bool is_stop);
543 
544 bool dc_stream_forward_multiple_crc_window(struct dc_stream_state *stream,
545 		struct crc_window *window,
546 		uint8_t phy_id,
547 		bool stop);
548 #endif
549 
550 bool dc_stream_configure_crc(struct dc *dc,
551 			     struct dc_stream_state *stream,
552 			     struct crc_params *crc_window,
553 			     bool enable,
554 			     bool continuous,
555 			     uint8_t idx,
556 			     bool reset);
557 
558 bool dc_stream_get_crc(struct dc *dc,
559 		       struct dc_stream_state *stream,
560 		       uint8_t idx,
561 		       uint32_t *r_cr,
562 		       uint32_t *g_y,
563 		       uint32_t *b_cb);
564 
565 void dc_stream_set_static_screen_params(struct dc *dc,
566 					struct dc_stream_state **stream,
567 					int num_streams,
568 					const struct dc_static_screen_params *params);
569 
570 void dc_stream_set_dyn_expansion(struct dc *dc, struct dc_stream_state *stream,
571 		enum dc_dynamic_expansion option);
572 
573 void dc_stream_set_dither_option(struct dc_stream_state *stream,
574 				 enum dc_dither_option option);
575 
576 bool dc_stream_set_gamut_remap(struct dc *dc,
577 			       const struct dc_stream_state *stream);
578 
579 bool dc_stream_program_csc_matrix(struct dc *dc,
580 				  struct dc_stream_state *stream);
581 
582 struct dc_rmcm_3dlut *dc_stream_get_3dlut_for_stream(
583 	const struct dc *dc,
584 	const struct dc_stream_state *stream,
585 	bool allocate_one);
586 
587 void dc_stream_release_3dlut_for_stream(
588 	const struct dc *dc,
589 	const struct dc_stream_state *stream);
590 
591 void dc_stream_init_rmcm_3dlut(struct dc *dc);
592 
593 struct pipe_ctx *dc_stream_get_pipe_ctx(struct dc_stream_state *stream);
594 
595 void dc_dmub_update_dirty_rect(struct dc *dc,
596 			       int surface_count,
597 			       struct dc_stream_state *stream,
598 			       struct dc_surface_update *srf_updates,
599 			       struct dc_state *context);
600 
601 bool dc_stream_is_cursor_limit_pending(struct dc *dc, struct dc_stream_state *stream);
602 bool dc_stream_can_clear_cursor_limit(struct dc *dc, struct dc_stream_state *stream);
603 
604 #endif /* DC_STREAM_H_ */
605