1 /*
2 * Copyright 2012-15 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 #include "dm_services.h"
27 #include "basics/dc_common.h"
28 #include "dc.h"
29 #include "core_types.h"
30 #include "resource.h"
31 #include "ipp.h"
32 #include "timing_generator.h"
33 #include "dc_dmub_srv.h"
34 #include "dc_state_priv.h"
35 #include "dc_stream_priv.h"
36
37 #define DC_LOGGER dc->ctx->logger
38 #ifndef MIN
39 #define MIN(X, Y) ((X) < (Y) ? (X) : (Y))
40 #endif
41 #ifndef MAX
42 #define MAX(x, y) ((x > y) ? x : y)
43 #endif
44
45 /*******************************************************************************
46 * Private functions
47 ******************************************************************************/
update_stream_signal(struct dc_stream_state * stream,struct dc_sink * sink)48 void update_stream_signal(struct dc_stream_state *stream, struct dc_sink *sink)
49 {
50 if (sink->sink_signal == SIGNAL_TYPE_NONE)
51 stream->signal = stream->link->connector_signal;
52 else
53 stream->signal = sink->sink_signal;
54
55 if (dc_is_dvi_signal(stream->signal)) {
56 if (stream->ctx->dc->caps.dual_link_dvi &&
57 (stream->timing.pix_clk_100hz / 10) > TMDS_MAX_PIXEL_CLOCK &&
58 sink->sink_signal != SIGNAL_TYPE_DVI_SINGLE_LINK)
59 stream->signal = SIGNAL_TYPE_DVI_DUAL_LINK;
60 else
61 stream->signal = SIGNAL_TYPE_DVI_SINGLE_LINK;
62 }
63 }
64
dc_stream_construct(struct dc_stream_state * stream,struct dc_sink * dc_sink_data)65 bool dc_stream_construct(struct dc_stream_state *stream,
66 struct dc_sink *dc_sink_data)
67 {
68 uint32_t i = 0;
69
70 stream->sink = dc_sink_data;
71 dc_sink_retain(dc_sink_data);
72
73 stream->ctx = dc_sink_data->ctx;
74 stream->link = dc_sink_data->link;
75 stream->sink_patches = dc_sink_data->edid_caps.panel_patch;
76 stream->converter_disable_audio = dc_sink_data->converter_disable_audio;
77 stream->qs_bit = dc_sink_data->edid_caps.qs_bit;
78 stream->qy_bit = dc_sink_data->edid_caps.qy_bit;
79
80 /* Copy audio modes */
81 /* TODO - Remove this translation */
82 for (i = 0; i < (dc_sink_data->edid_caps.audio_mode_count); i++) {
83 stream->audio_info.modes[i].channel_count = dc_sink_data->edid_caps.audio_modes[i].channel_count;
84 stream->audio_info.modes[i].format_code = dc_sink_data->edid_caps.audio_modes[i].format_code;
85 stream->audio_info.modes[i].sample_rates.all = dc_sink_data->edid_caps.audio_modes[i].sample_rate;
86 stream->audio_info.modes[i].sample_size = dc_sink_data->edid_caps.audio_modes[i].sample_size;
87 }
88 stream->audio_info.mode_count = dc_sink_data->edid_caps.audio_mode_count;
89 stream->audio_info.audio_latency = dc_sink_data->edid_caps.audio_latency;
90 stream->audio_info.video_latency = dc_sink_data->edid_caps.video_latency;
91 memmove(
92 stream->audio_info.display_name,
93 dc_sink_data->edid_caps.display_name,
94 AUDIO_INFO_DISPLAY_NAME_SIZE_IN_CHARS);
95 stream->audio_info.manufacture_id = dc_sink_data->edid_caps.manufacturer_id;
96 stream->audio_info.product_id = dc_sink_data->edid_caps.product_id;
97 stream->audio_info.flags.all = dc_sink_data->edid_caps.speaker_flags;
98
99 if (dc_sink_data->dc_container_id != NULL) {
100 struct dc_container_id *dc_container_id = dc_sink_data->dc_container_id;
101
102 stream->audio_info.port_id[0] = dc_container_id->portId[0];
103 stream->audio_info.port_id[1] = dc_container_id->portId[1];
104 } else {
105 /* TODO - WindowDM has implemented,
106 other DMs need Unhardcode port_id */
107 stream->audio_info.port_id[0] = 0x5558859e;
108 stream->audio_info.port_id[1] = 0xd989449;
109 }
110
111 /* EDID CAP translation for HDMI 2.0 */
112 stream->timing.flags.LTE_340MCSC_SCRAMBLE = dc_sink_data->edid_caps.lte_340mcsc_scramble;
113
114 memset(&stream->timing.dsc_cfg, 0, sizeof(stream->timing.dsc_cfg));
115 stream->timing.dsc_cfg.num_slices_h = 0;
116 stream->timing.dsc_cfg.num_slices_v = 0;
117 stream->timing.dsc_cfg.bits_per_pixel = 128;
118 stream->timing.dsc_cfg.block_pred_enable = 1;
119 stream->timing.dsc_cfg.linebuf_depth = 9;
120 stream->timing.dsc_cfg.version_minor = 2;
121 stream->timing.dsc_cfg.ycbcr422_simple = 0;
122
123 update_stream_signal(stream, dc_sink_data);
124
125 stream->out_transfer_func.type = TF_TYPE_BYPASS;
126
127 dc_stream_assign_stream_id(stream);
128
129 return true;
130 }
131
dc_stream_destruct(struct dc_stream_state * stream)132 void dc_stream_destruct(struct dc_stream_state *stream)
133 {
134 dc_sink_release(stream->sink);
135 }
136
dc_stream_assign_stream_id(struct dc_stream_state * stream)137 void dc_stream_assign_stream_id(struct dc_stream_state *stream)
138 {
139 /* MSB is reserved to indicate phantoms */
140 stream->stream_id = stream->ctx->dc_stream_id_count;
141 stream->ctx->dc_stream_id_count++;
142 }
143
dc_stream_retain(struct dc_stream_state * stream)144 void dc_stream_retain(struct dc_stream_state *stream)
145 {
146 kref_get(&stream->refcount);
147 }
148
dc_stream_free(struct kref * kref)149 static void dc_stream_free(struct kref *kref)
150 {
151 struct dc_stream_state *stream = container_of(kref, struct dc_stream_state, refcount);
152
153 dc_stream_destruct(stream);
154 kfree(stream);
155 }
156
dc_stream_release(struct dc_stream_state * stream)157 void dc_stream_release(struct dc_stream_state *stream)
158 {
159 if (stream != NULL) {
160 kref_put(&stream->refcount, dc_stream_free);
161 }
162 }
163
dc_create_stream_for_sink(struct dc_sink * sink)164 struct dc_stream_state *dc_create_stream_for_sink(
165 struct dc_sink *sink)
166 {
167 struct dc_stream_state *stream;
168
169 if (sink == NULL)
170 return NULL;
171
172 stream = kzalloc(sizeof(struct dc_stream_state), GFP_KERNEL);
173 if (stream == NULL)
174 goto alloc_fail;
175
176 if (dc_stream_construct(stream, sink) == false)
177 goto construct_fail;
178
179 kref_init(&stream->refcount);
180
181 return stream;
182
183 construct_fail:
184 kfree(stream);
185
186 alloc_fail:
187 return NULL;
188 }
189
dc_copy_stream(const struct dc_stream_state * stream)190 struct dc_stream_state *dc_copy_stream(const struct dc_stream_state *stream)
191 {
192 struct dc_stream_state *new_stream;
193
194 new_stream = kmemdup(stream, sizeof(struct dc_stream_state), GFP_KERNEL);
195 if (!new_stream)
196 return NULL;
197
198 if (new_stream->sink)
199 dc_sink_retain(new_stream->sink);
200
201 dc_stream_assign_stream_id(new_stream);
202
203 /* If using dynamic encoder assignment, wait till stream committed to assign encoder. */
204 if (new_stream->ctx->dc->res_pool->funcs->link_encs_assign &&
205 !new_stream->ctx->dc->config.unify_link_enc_assignment)
206 new_stream->link_enc = NULL;
207
208 kref_init(&new_stream->refcount);
209
210 return new_stream;
211 }
212
213 /**
214 * dc_stream_get_status() - Get current stream status of the given stream state
215 * @stream: The stream to get the stream status for.
216 *
217 * The given stream is expected to exist in dc->current_state. Otherwise, NULL
218 * will be returned.
219 */
dc_stream_get_status(struct dc_stream_state * stream)220 struct dc_stream_status *dc_stream_get_status(
221 struct dc_stream_state *stream)
222 {
223 struct dc *dc = stream->ctx->dc;
224 return dc_state_get_stream_status(dc->current_state, stream);
225 }
226
program_cursor_attributes(struct dc * dc,struct dc_stream_state * stream)227 void program_cursor_attributes(
228 struct dc *dc,
229 struct dc_stream_state *stream)
230 {
231 int i;
232 struct resource_context *res_ctx;
233 struct pipe_ctx *pipe_to_program = NULL;
234
235 if (!stream)
236 return;
237
238 res_ctx = &dc->current_state->res_ctx;
239
240 for (i = 0; i < MAX_PIPES; i++) {
241 struct pipe_ctx *pipe_ctx = &res_ctx->pipe_ctx[i];
242
243 if (pipe_ctx->stream != stream)
244 continue;
245
246 if (!pipe_to_program) {
247 pipe_to_program = pipe_ctx;
248 dc->hwss.cursor_lock(dc, pipe_to_program, true);
249 if (pipe_to_program->next_odm_pipe)
250 dc->hwss.cursor_lock(dc, pipe_to_program->next_odm_pipe, true);
251 }
252
253 dc->hwss.set_cursor_attribute(pipe_ctx);
254 if (dc->ctx->dmub_srv)
255 dc_send_update_cursor_info_to_dmu(pipe_ctx, i);
256 if (dc->hwss.set_cursor_sdr_white_level)
257 dc->hwss.set_cursor_sdr_white_level(pipe_ctx);
258 }
259
260 if (pipe_to_program) {
261 dc->hwss.cursor_lock(dc, pipe_to_program, false);
262 if (pipe_to_program->next_odm_pipe)
263 dc->hwss.cursor_lock(dc, pipe_to_program->next_odm_pipe, false);
264 }
265 }
266
267 /*
268 * dc_stream_check_cursor_attributes() - Check validitity of cursor attributes and surface address
269 */
dc_stream_check_cursor_attributes(const struct dc_stream_state * stream,struct dc_state * state,const struct dc_cursor_attributes * attributes)270 bool dc_stream_check_cursor_attributes(
271 const struct dc_stream_state *stream,
272 struct dc_state *state,
273 const struct dc_cursor_attributes *attributes)
274 {
275 const struct dc *dc;
276
277 unsigned int max_cursor_size;
278
279 if (NULL == stream) {
280 dm_error("DC: dc_stream is NULL!\n");
281 return false;
282 }
283 if (NULL == attributes) {
284 dm_error("DC: attributes is NULL!\n");
285 return false;
286 }
287
288 if (attributes->address.quad_part == 0) {
289 dm_output_to_console("DC: Cursor address is 0!\n");
290 return false;
291 }
292
293 dc = stream->ctx->dc;
294
295 /* SubVP is not compatible with HW cursor larger than what can fit in cursor SRAM.
296 * Therefore, if cursor is greater than this, fallback to SW cursor.
297 */
298 if (dc->debug.allow_sw_cursor_fallback && dc->res_pool->funcs->get_max_hw_cursor_size) {
299 max_cursor_size = dc->res_pool->funcs->get_max_hw_cursor_size(dc, state, stream);
300 max_cursor_size = max_cursor_size * max_cursor_size * 4;
301
302 if (attributes->height * attributes->width * 4 > max_cursor_size) {
303 return false;
304 }
305 }
306
307 return true;
308 }
309
310 /*
311 * dc_stream_set_cursor_attributes() - Update cursor attributes and set cursor surface address
312 */
dc_stream_set_cursor_attributes(struct dc_stream_state * stream,const struct dc_cursor_attributes * attributes)313 bool dc_stream_set_cursor_attributes(
314 struct dc_stream_state *stream,
315 const struct dc_cursor_attributes *attributes)
316 {
317 bool result = false;
318
319 if (dc_stream_check_cursor_attributes(stream, stream->ctx->dc->current_state, attributes)) {
320 stream->cursor_attributes = *attributes;
321 result = true;
322 }
323
324 return result;
325 }
326
dc_stream_program_cursor_attributes(struct dc_stream_state * stream,const struct dc_cursor_attributes * attributes)327 bool dc_stream_program_cursor_attributes(
328 struct dc_stream_state *stream,
329 const struct dc_cursor_attributes *attributes)
330 {
331 struct dc *dc;
332 bool reset_idle_optimizations = false;
333
334 dc = stream ? stream->ctx->dc : NULL;
335
336 if (dc_stream_set_cursor_attributes(stream, attributes)) {
337 dc_z10_restore(dc);
338 /* disable idle optimizations while updating cursor */
339 if (dc->idle_optimizations_allowed) {
340 dc_allow_idle_optimizations(dc, false);
341 reset_idle_optimizations = true;
342 }
343
344 program_cursor_attributes(dc, stream);
345
346 /* re-enable idle optimizations if necessary */
347 if (reset_idle_optimizations && !dc->debug.disable_dmub_reallow_idle)
348 dc_allow_idle_optimizations(dc, true);
349
350 return true;
351 }
352
353 return false;
354 }
355
program_cursor_position(struct dc * dc,struct dc_stream_state * stream)356 void program_cursor_position(
357 struct dc *dc,
358 struct dc_stream_state *stream)
359 {
360 int i;
361 struct resource_context *res_ctx;
362 struct pipe_ctx *pipe_to_program = NULL;
363
364 if (!stream)
365 return;
366
367 res_ctx = &dc->current_state->res_ctx;
368
369 for (i = 0; i < MAX_PIPES; i++) {
370 struct pipe_ctx *pipe_ctx = &res_ctx->pipe_ctx[i];
371
372 if (pipe_ctx->stream != stream ||
373 (!pipe_ctx->plane_res.mi && !pipe_ctx->plane_res.hubp) ||
374 !pipe_ctx->plane_state ||
375 (!pipe_ctx->plane_res.xfm && !pipe_ctx->plane_res.dpp) ||
376 (!pipe_ctx->plane_res.ipp && !pipe_ctx->plane_res.dpp))
377 continue;
378
379 if (!pipe_to_program) {
380 pipe_to_program = pipe_ctx;
381 dc->hwss.cursor_lock(dc, pipe_to_program, true);
382 }
383
384 dc->hwss.set_cursor_position(pipe_ctx);
385 if (dc->ctx->dmub_srv)
386 dc_send_update_cursor_info_to_dmu(pipe_ctx, i);
387 }
388
389 if (pipe_to_program)
390 dc->hwss.cursor_lock(dc, pipe_to_program, false);
391 }
392
dc_stream_set_cursor_position(struct dc_stream_state * stream,const struct dc_cursor_position * position)393 bool dc_stream_set_cursor_position(
394 struct dc_stream_state *stream,
395 const struct dc_cursor_position *position)
396 {
397 if (NULL == stream) {
398 dm_error("DC: dc_stream is NULL!\n");
399 return false;
400 }
401
402 if (NULL == position) {
403 dm_error("DC: cursor position is NULL!\n");
404 return false;
405 }
406
407 stream->cursor_position = *position;
408
409
410 return true;
411 }
412
dc_stream_program_cursor_position(struct dc_stream_state * stream,const struct dc_cursor_position * position)413 bool dc_stream_program_cursor_position(
414 struct dc_stream_state *stream,
415 const struct dc_cursor_position *position)
416 {
417 struct dc *dc;
418 bool reset_idle_optimizations = false;
419 const struct dc_cursor_position *old_position;
420
421 if (!stream)
422 return false;
423
424 old_position = &stream->cursor_position;
425 dc = stream->ctx->dc;
426
427 if (dc_stream_set_cursor_position(stream, position)) {
428 dc_z10_restore(dc);
429
430 /* disable idle optimizations if enabling cursor */
431 if (dc->idle_optimizations_allowed &&
432 (!old_position->enable || dc->debug.exit_idle_opt_for_cursor_updates) &&
433 position->enable) {
434 dc_allow_idle_optimizations(dc, false);
435 reset_idle_optimizations = true;
436 }
437
438 program_cursor_position(dc, stream);
439 /* re-enable idle optimizations if necessary */
440 if (reset_idle_optimizations && !dc->debug.disable_dmub_reallow_idle)
441 dc_allow_idle_optimizations(dc, true);
442
443 /* apply/update visual confirm */
444 if (dc->debug.visual_confirm == VISUAL_CONFIRM_HW_CURSOR) {
445 /* update software state */
446 int i;
447
448 for (i = 0; i < dc->res_pool->pipe_count; i++) {
449 struct pipe_ctx *pipe_ctx = &dc->current_state->res_ctx.pipe_ctx[i];
450
451 /* adjust visual confirm color for all pipes with current stream */
452 if (stream == pipe_ctx->stream) {
453 get_cursor_visual_confirm_color(pipe_ctx, &(pipe_ctx->visual_confirm_color));
454
455 /* programming hardware */
456 if (pipe_ctx->plane_state)
457 dc->hwss.update_visual_confirm_color(dc, pipe_ctx,
458 pipe_ctx->plane_res.hubp->mpcc_id);
459 }
460 }
461 }
462
463 return true;
464 }
465
466 return false;
467 }
468
dc_stream_add_writeback(struct dc * dc,struct dc_stream_state * stream,struct dc_writeback_info * wb_info)469 bool dc_stream_add_writeback(struct dc *dc,
470 struct dc_stream_state *stream,
471 struct dc_writeback_info *wb_info)
472 {
473 bool isDrc = false;
474 int i = 0;
475 struct dwbc *dwb;
476
477 if (stream == NULL) {
478 dm_error("DC: dc_stream is NULL!\n");
479 return false;
480 }
481
482 if (wb_info == NULL) {
483 dm_error("DC: dc_writeback_info is NULL!\n");
484 return false;
485 }
486
487 if (wb_info->dwb_pipe_inst >= MAX_DWB_PIPES) {
488 dm_error("DC: writeback pipe is invalid!\n");
489 return false;
490 }
491
492 dc_exit_ips_for_hw_access(dc);
493
494 wb_info->dwb_params.out_transfer_func = &stream->out_transfer_func;
495
496 dwb = dc->res_pool->dwbc[wb_info->dwb_pipe_inst];
497 dwb->dwb_is_drc = false;
498
499 /* recalculate and apply DML parameters */
500
501 for (i = 0; i < stream->num_wb_info; i++) {
502 /*dynamic update*/
503 if (stream->writeback_info[i].wb_enabled &&
504 stream->writeback_info[i].dwb_pipe_inst == wb_info->dwb_pipe_inst) {
505 stream->writeback_info[i] = *wb_info;
506 isDrc = true;
507 }
508 }
509
510 if (!isDrc) {
511 ASSERT(stream->num_wb_info + 1 <= MAX_DWB_PIPES);
512 stream->writeback_info[stream->num_wb_info++] = *wb_info;
513 }
514
515 if (dc->hwss.enable_writeback) {
516 struct dc_stream_status *stream_status = dc_stream_get_status(stream);
517 struct dwbc *dwb = dc->res_pool->dwbc[wb_info->dwb_pipe_inst];
518 if (stream_status)
519 dwb->otg_inst = stream_status->primary_otg_inst;
520 }
521
522 if (!dc->hwss.update_bandwidth(dc, dc->current_state)) {
523 dm_error("DC: update_bandwidth failed!\n");
524 return false;
525 }
526
527 /* enable writeback */
528 if (dc->hwss.enable_writeback) {
529 struct dwbc *dwb = dc->res_pool->dwbc[wb_info->dwb_pipe_inst];
530
531 if (dwb->funcs->is_enabled(dwb)) {
532 /* writeback pipe already enabled, only need to update */
533 dc->hwss.update_writeback(dc, wb_info, dc->current_state);
534 } else {
535 /* Enable writeback pipe from scratch*/
536 dc->hwss.enable_writeback(dc, wb_info, dc->current_state);
537 }
538 }
539
540 return true;
541 }
542
dc_stream_fc_disable_writeback(struct dc * dc,struct dc_stream_state * stream,uint32_t dwb_pipe_inst)543 bool dc_stream_fc_disable_writeback(struct dc *dc,
544 struct dc_stream_state *stream,
545 uint32_t dwb_pipe_inst)
546 {
547 struct dwbc *dwb = dc->res_pool->dwbc[dwb_pipe_inst];
548
549 if (stream == NULL) {
550 dm_error("DC: dc_stream is NULL!\n");
551 return false;
552 }
553
554 if (dwb_pipe_inst >= MAX_DWB_PIPES) {
555 dm_error("DC: writeback pipe is invalid!\n");
556 return false;
557 }
558
559 if (stream->num_wb_info > MAX_DWB_PIPES) {
560 dm_error("DC: num_wb_info is invalid!\n");
561 return false;
562 }
563
564 dc_exit_ips_for_hw_access(dc);
565
566 if (dwb->funcs->set_fc_enable)
567 dwb->funcs->set_fc_enable(dwb, DWB_FRAME_CAPTURE_DISABLE);
568
569 return true;
570 }
571
572 /**
573 * dc_stream_remove_writeback() - Disables writeback and removes writeback info.
574 * @dc: Display core control structure.
575 * @stream: Display core stream state.
576 * @dwb_pipe_inst: Display writeback pipe.
577 *
578 * Return: returns true on success, false otherwise.
579 */
dc_stream_remove_writeback(struct dc * dc,struct dc_stream_state * stream,uint32_t dwb_pipe_inst)580 bool dc_stream_remove_writeback(struct dc *dc,
581 struct dc_stream_state *stream,
582 uint32_t dwb_pipe_inst)
583 {
584 unsigned int i, j;
585 if (stream == NULL) {
586 dm_error("DC: dc_stream is NULL!\n");
587 return false;
588 }
589
590 if (dwb_pipe_inst >= MAX_DWB_PIPES) {
591 dm_error("DC: writeback pipe is invalid!\n");
592 return false;
593 }
594
595 if (stream->num_wb_info > MAX_DWB_PIPES) {
596 dm_error("DC: num_wb_info is invalid!\n");
597 return false;
598 }
599
600 /* remove writeback info for disabled writeback pipes from stream */
601 for (i = 0, j = 0; i < stream->num_wb_info; i++) {
602 if (stream->writeback_info[i].wb_enabled) {
603
604 if (stream->writeback_info[i].dwb_pipe_inst == dwb_pipe_inst)
605 stream->writeback_info[i].wb_enabled = false;
606
607 /* trim the array */
608 if (j < i) {
609 memcpy(&stream->writeback_info[j], &stream->writeback_info[i],
610 sizeof(struct dc_writeback_info));
611 j++;
612 }
613 }
614 }
615 stream->num_wb_info = j;
616
617 /* recalculate and apply DML parameters */
618 if (!dc->hwss.update_bandwidth(dc, dc->current_state)) {
619 dm_error("DC: update_bandwidth failed!\n");
620 return false;
621 }
622
623 dc_exit_ips_for_hw_access(dc);
624
625 /* disable writeback */
626 if (dc->hwss.disable_writeback) {
627 struct dwbc *dwb = dc->res_pool->dwbc[dwb_pipe_inst];
628
629 if (dwb->funcs->is_enabled(dwb))
630 dc->hwss.disable_writeback(dc, dwb_pipe_inst);
631 }
632
633 return true;
634 }
635
dc_stream_get_vblank_counter(const struct dc_stream_state * stream)636 uint32_t dc_stream_get_vblank_counter(const struct dc_stream_state *stream)
637 {
638 uint8_t i;
639 struct dc *dc = stream->ctx->dc;
640 struct resource_context *res_ctx =
641 &dc->current_state->res_ctx;
642
643 dc_exit_ips_for_hw_access(dc);
644
645 for (i = 0; i < MAX_PIPES; i++) {
646 struct timing_generator *tg = res_ctx->pipe_ctx[i].stream_res.tg;
647
648 if (res_ctx->pipe_ctx[i].stream != stream || !tg)
649 continue;
650
651 return tg->funcs->get_frame_count(tg);
652 }
653
654 return 0;
655 }
656
dc_stream_send_dp_sdp(const struct dc_stream_state * stream,const uint8_t * custom_sdp_message,unsigned int sdp_message_size)657 bool dc_stream_send_dp_sdp(const struct dc_stream_state *stream,
658 const uint8_t *custom_sdp_message,
659 unsigned int sdp_message_size)
660 {
661 int i;
662 struct dc *dc;
663 struct resource_context *res_ctx;
664
665 if (stream == NULL) {
666 dm_error("DC: dc_stream is NULL!\n");
667 return false;
668 }
669
670 dc = stream->ctx->dc;
671 res_ctx = &dc->current_state->res_ctx;
672
673 dc_exit_ips_for_hw_access(dc);
674
675 for (i = 0; i < MAX_PIPES; i++) {
676 struct pipe_ctx *pipe_ctx = &res_ctx->pipe_ctx[i];
677
678 if (pipe_ctx->stream != stream)
679 continue;
680
681 if (dc->hwss.send_immediate_sdp_message != NULL)
682 dc->hwss.send_immediate_sdp_message(pipe_ctx,
683 custom_sdp_message,
684 sdp_message_size);
685 else
686 DC_LOG_WARNING("%s:send_immediate_sdp_message not implemented on this ASIC\n",
687 __func__);
688
689 }
690
691 return true;
692 }
693
dc_stream_get_scanoutpos(const struct dc_stream_state * stream,uint32_t * v_blank_start,uint32_t * v_blank_end,uint32_t * h_position,uint32_t * v_position)694 bool dc_stream_get_scanoutpos(const struct dc_stream_state *stream,
695 uint32_t *v_blank_start,
696 uint32_t *v_blank_end,
697 uint32_t *h_position,
698 uint32_t *v_position)
699 {
700 uint8_t i;
701 bool ret = false;
702 struct dc *dc = stream->ctx->dc;
703 struct resource_context *res_ctx =
704 &dc->current_state->res_ctx;
705
706 dc_exit_ips_for_hw_access(dc);
707
708 for (i = 0; i < MAX_PIPES; i++) {
709 struct timing_generator *tg = res_ctx->pipe_ctx[i].stream_res.tg;
710
711 if (res_ctx->pipe_ctx[i].stream != stream || !tg)
712 continue;
713
714 tg->funcs->get_scanoutpos(tg,
715 v_blank_start,
716 v_blank_end,
717 h_position,
718 v_position);
719
720 ret = true;
721 break;
722 }
723
724 return ret;
725 }
726
dc_stream_dmdata_status_done(struct dc * dc,struct dc_stream_state * stream)727 bool dc_stream_dmdata_status_done(struct dc *dc, struct dc_stream_state *stream)
728 {
729 struct pipe_ctx *pipe = NULL;
730 int i;
731
732 if (!dc->hwss.dmdata_status_done)
733 return false;
734
735 for (i = 0; i < MAX_PIPES; i++) {
736 pipe = &dc->current_state->res_ctx.pipe_ctx[i];
737 if (pipe->stream == stream)
738 break;
739 }
740 /* Stream not found, by default we'll assume HUBP fetched dm data */
741 if (i == MAX_PIPES)
742 return true;
743
744 dc_exit_ips_for_hw_access(dc);
745
746 return dc->hwss.dmdata_status_done(pipe);
747 }
748
dc_stream_set_dynamic_metadata(struct dc * dc,struct dc_stream_state * stream,struct dc_dmdata_attributes * attr)749 bool dc_stream_set_dynamic_metadata(struct dc *dc,
750 struct dc_stream_state *stream,
751 struct dc_dmdata_attributes *attr)
752 {
753 struct pipe_ctx *pipe_ctx = NULL;
754 struct hubp *hubp;
755 int i;
756
757 /* Dynamic metadata is only supported on HDMI or DP */
758 if (!dc_is_hdmi_signal(stream->signal) && !dc_is_dp_signal(stream->signal))
759 return false;
760
761 /* Check hardware support */
762 if (!dc->hwss.program_dmdata_engine)
763 return false;
764
765 for (i = 0; i < MAX_PIPES; i++) {
766 pipe_ctx = &dc->current_state->res_ctx.pipe_ctx[i];
767 if (pipe_ctx->stream == stream)
768 break;
769 }
770
771 if (i == MAX_PIPES)
772 return false;
773
774 hubp = pipe_ctx->plane_res.hubp;
775 if (hubp == NULL)
776 return false;
777
778 pipe_ctx->stream->dmdata_address = attr->address;
779
780 dc_exit_ips_for_hw_access(dc);
781
782 dc->hwss.program_dmdata_engine(pipe_ctx);
783
784 if (hubp->funcs->dmdata_set_attributes != NULL &&
785 pipe_ctx->stream->dmdata_address.quad_part != 0) {
786 hubp->funcs->dmdata_set_attributes(hubp, attr);
787 }
788
789 return true;
790 }
791
dc_stream_add_dsc_to_resource(struct dc * dc,struct dc_state * state,struct dc_stream_state * stream)792 enum dc_status dc_stream_add_dsc_to_resource(struct dc *dc,
793 struct dc_state *state,
794 struct dc_stream_state *stream)
795 {
796 if (dc->res_pool->funcs->add_dsc_to_stream_resource) {
797 return dc->res_pool->funcs->add_dsc_to_stream_resource(dc, state, stream);
798 } else {
799 return DC_NO_DSC_RESOURCE;
800 }
801 }
802
dc_stream_get_pipe_ctx(struct dc_stream_state * stream)803 struct pipe_ctx *dc_stream_get_pipe_ctx(struct dc_stream_state *stream)
804 {
805 int i = 0;
806
807 for (i = 0; i < MAX_PIPES; i++) {
808 struct pipe_ctx *pipe = &stream->ctx->dc->current_state->res_ctx.pipe_ctx[i];
809
810 if (pipe->stream == stream)
811 return pipe;
812 }
813
814 return NULL;
815 }
816
dc_stream_log(const struct dc * dc,const struct dc_stream_state * stream)817 void dc_stream_log(const struct dc *dc, const struct dc_stream_state *stream)
818 {
819 DC_LOG_DC(
820 "core_stream 0x%p: src: %d, %d, %d, %d; dst: %d, %d, %d, %d, colorSpace:%d\n",
821 stream,
822 stream->src.x,
823 stream->src.y,
824 stream->src.width,
825 stream->src.height,
826 stream->dst.x,
827 stream->dst.y,
828 stream->dst.width,
829 stream->dst.height,
830 stream->output_color_space);
831 DC_LOG_DC(
832 "\tpix_clk_khz: %d, h_total: %d, v_total: %d, pixel_encoding:%s, color_depth:%s\n",
833 stream->timing.pix_clk_100hz / 10,
834 stream->timing.h_total,
835 stream->timing.v_total,
836 dc_pixel_encoding_to_str(stream->timing.pixel_encoding),
837 dc_color_depth_to_str(stream->timing.display_color_depth));
838 DC_LOG_DC(
839 "\tlink: %d\n",
840 stream->link->link_index);
841
842 DC_LOG_DC(
843 "\tdsc: %d, mst_pbn: %d\n",
844 stream->timing.flags.DSC,
845 stream->timing.dsc_cfg.mst_pbn);
846
847 if (stream->sink) {
848 if (stream->sink->sink_signal != SIGNAL_TYPE_VIRTUAL &&
849 stream->sink->sink_signal != SIGNAL_TYPE_NONE) {
850
851 DC_LOG_DC(
852 "\tdispname: %s signal: %x\n",
853 stream->sink->edid_caps.display_name,
854 stream->signal);
855 }
856 }
857 }
858
859 /*
860 * dc_stream_get_3dlut()
861 * Requirements:
862 * 1. Is stream already owns an RMCM instance, return it.
863 * 2. If it doesn't and we don't need to allocate, return NULL.
864 * 3. If there's a free RMCM instance, assign to stream and return it.
865 * 4. If no free RMCM instances, return NULL.
866 */
867
dc_stream_get_3dlut_for_stream(const struct dc * dc,const struct dc_stream_state * stream,bool allocate_one)868 struct dc_rmcm_3dlut *dc_stream_get_3dlut_for_stream(
869 const struct dc *dc,
870 const struct dc_stream_state *stream,
871 bool allocate_one)
872 {
873 unsigned int num_rmcm = dc->caps.color.mpc.num_rmcm_3dluts;
874
875 // see if one is allocated for this stream
876 for (int i = 0; i < num_rmcm; i++) {
877 if (dc->res_pool->rmcm_3dlut[i].isInUse &&
878 dc->res_pool->rmcm_3dlut[i].stream == stream)
879 return &dc->res_pool->rmcm_3dlut[i];
880 }
881
882 //case: not found one, and dont need to allocate
883 if (!allocate_one)
884 return NULL;
885
886 //see if there is an unused 3dlut, allocate
887 for (int i = 0; i < num_rmcm; i++) {
888 if (!dc->res_pool->rmcm_3dlut[i].isInUse) {
889 dc->res_pool->rmcm_3dlut[i].isInUse = true;
890 dc->res_pool->rmcm_3dlut[i].stream = stream;
891 return &dc->res_pool->rmcm_3dlut[i];
892 }
893 }
894
895 //dont have a 3dlut
896 return NULL;
897 }
898
899
dc_stream_release_3dlut_for_stream(const struct dc * dc,const struct dc_stream_state * stream)900 void dc_stream_release_3dlut_for_stream(
901 const struct dc *dc,
902 const struct dc_stream_state *stream)
903 {
904 struct dc_rmcm_3dlut *rmcm_3dlut =
905 dc_stream_get_3dlut_for_stream(dc, stream, false);
906
907 if (rmcm_3dlut) {
908 rmcm_3dlut->isInUse = false;
909 rmcm_3dlut->stream = NULL;
910 rmcm_3dlut->protection_bits = 0;
911 }
912 }
913
914
dc_stream_init_rmcm_3dlut(struct dc * dc)915 void dc_stream_init_rmcm_3dlut(struct dc *dc)
916 {
917 unsigned int num_rmcm = dc->caps.color.mpc.num_rmcm_3dluts;
918
919 for (int i = 0; i < num_rmcm; i++) {
920 dc->res_pool->rmcm_3dlut[i].isInUse = false;
921 dc->res_pool->rmcm_3dlut[i].stream = NULL;
922 dc->res_pool->rmcm_3dlut[i].protection_bits = 0;
923 }
924 }
925
926 /*
927 * Finds the greatest index in refresh_rate_hz that contains a value <= refresh
928 */
dc_stream_get_nearest_smallest_index(struct dc_stream_state * stream,int refresh)929 static int dc_stream_get_nearest_smallest_index(struct dc_stream_state *stream, int refresh)
930 {
931 for (int i = 0; i < (LUMINANCE_DATA_TABLE_SIZE - 1); ++i) {
932 if ((stream->lumin_data.refresh_rate_hz[i] <= refresh) && (refresh < stream->lumin_data.refresh_rate_hz[i + 1])) {
933 return i;
934 }
935 }
936 return 9;
937 }
938
939 /*
940 * Finds a corresponding brightness for a given refresh rate between 2 given indices, where index1 < index2
941 */
dc_stream_get_brightness_millinits_linear_interpolation(struct dc_stream_state * stream,int index1,int index2,int refresh_hz)942 static int dc_stream_get_brightness_millinits_linear_interpolation (struct dc_stream_state *stream,
943 int index1,
944 int index2,
945 int refresh_hz)
946 {
947 long long slope = 0;
948 if (stream->lumin_data.refresh_rate_hz[index2] != stream->lumin_data.refresh_rate_hz[index1]) {
949 slope = (stream->lumin_data.luminance_millinits[index2] - stream->lumin_data.luminance_millinits[index1]) /
950 (stream->lumin_data.refresh_rate_hz[index2] - stream->lumin_data.refresh_rate_hz[index1]);
951 }
952
953 int y_intercept = stream->lumin_data.luminance_millinits[index2] - slope * stream->lumin_data.refresh_rate_hz[index2];
954
955 return (y_intercept + refresh_hz * slope);
956 }
957
958 /*
959 * Finds a corresponding refresh rate for a given brightness between 2 given indices, where index1 < index2
960 */
dc_stream_get_refresh_hz_linear_interpolation(struct dc_stream_state * stream,int index1,int index2,int brightness_millinits)961 static int dc_stream_get_refresh_hz_linear_interpolation (struct dc_stream_state *stream,
962 int index1,
963 int index2,
964 int brightness_millinits)
965 {
966 long long slope = 1;
967 if (stream->lumin_data.refresh_rate_hz[index2] != stream->lumin_data.refresh_rate_hz[index1]) {
968 slope = (stream->lumin_data.luminance_millinits[index2] - stream->lumin_data.luminance_millinits[index1]) /
969 (stream->lumin_data.refresh_rate_hz[index2] - stream->lumin_data.refresh_rate_hz[index1]);
970 }
971
972 int y_intercept = stream->lumin_data.luminance_millinits[index2] - slope * stream->lumin_data.refresh_rate_hz[index2];
973
974 return ((int)div64_s64((brightness_millinits - y_intercept), slope));
975 }
976
977 /*
978 * Finds the current brightness in millinits given a refresh rate
979 */
dc_stream_get_brightness_millinits_from_refresh(struct dc_stream_state * stream,int refresh_hz)980 static int dc_stream_get_brightness_millinits_from_refresh (struct dc_stream_state *stream, int refresh_hz)
981 {
982 int nearest_smallest_index = dc_stream_get_nearest_smallest_index(stream, refresh_hz);
983 int nearest_smallest_value = stream->lumin_data.refresh_rate_hz[nearest_smallest_index];
984
985 if (nearest_smallest_value == refresh_hz)
986 return stream->lumin_data.luminance_millinits[nearest_smallest_index];
987
988 if (nearest_smallest_index >= 9)
989 return dc_stream_get_brightness_millinits_linear_interpolation(stream, nearest_smallest_index - 1, nearest_smallest_index, refresh_hz);
990
991 if (nearest_smallest_value == stream->lumin_data.refresh_rate_hz[nearest_smallest_index + 1])
992 return stream->lumin_data.luminance_millinits[nearest_smallest_index];
993
994 return dc_stream_get_brightness_millinits_linear_interpolation(stream, nearest_smallest_index, nearest_smallest_index + 1, refresh_hz);
995 }
996
997 /*
998 * Finds the lowest/highest refresh rate (depending on search_for_max_increase)
999 * that can be achieved from starting_refresh_hz while staying
1000 * within flicker criteria
1001 */
dc_stream_calculate_flickerless_refresh_rate(struct dc_stream_state * stream,int current_brightness,int starting_refresh_hz,bool is_gaming,bool search_for_max_increase)1002 static int dc_stream_calculate_flickerless_refresh_rate(struct dc_stream_state *stream,
1003 int current_brightness,
1004 int starting_refresh_hz,
1005 bool is_gaming,
1006 bool search_for_max_increase)
1007 {
1008 int nearest_smallest_index = dc_stream_get_nearest_smallest_index(stream, starting_refresh_hz);
1009
1010 int flicker_criteria_millinits = is_gaming ?
1011 stream->lumin_data.flicker_criteria_milli_nits_GAMING :
1012 stream->lumin_data.flicker_criteria_milli_nits_STATIC;
1013
1014 int safe_upper_bound = current_brightness + flicker_criteria_millinits;
1015 int safe_lower_bound = current_brightness - flicker_criteria_millinits;
1016 int lumin_millinits_temp = 0;
1017
1018 int offset = -1;
1019 if (search_for_max_increase) {
1020 offset = 1;
1021 }
1022
1023 /*
1024 * Increments up or down by 1 depending on search_for_max_increase
1025 */
1026 for (int i = nearest_smallest_index; (i > 0 && !search_for_max_increase) || (i < (LUMINANCE_DATA_TABLE_SIZE - 1) && search_for_max_increase); i += offset) {
1027
1028 lumin_millinits_temp = stream->lumin_data.luminance_millinits[i + offset];
1029
1030 if ((lumin_millinits_temp >= safe_upper_bound) || (lumin_millinits_temp <= safe_lower_bound)) {
1031
1032 if (stream->lumin_data.refresh_rate_hz[i + offset] == stream->lumin_data.refresh_rate_hz[i])
1033 return stream->lumin_data.refresh_rate_hz[i];
1034
1035 int target_brightness = (stream->lumin_data.luminance_millinits[i + offset] >= (current_brightness + flicker_criteria_millinits)) ?
1036 current_brightness + flicker_criteria_millinits :
1037 current_brightness - flicker_criteria_millinits;
1038
1039 int refresh = 0;
1040
1041 /*
1042 * Need the second input to be < third input for dc_stream_get_refresh_hz_linear_interpolation
1043 */
1044 if (search_for_max_increase)
1045 refresh = dc_stream_get_refresh_hz_linear_interpolation(stream, i, i + offset, target_brightness);
1046 else
1047 refresh = dc_stream_get_refresh_hz_linear_interpolation(stream, i + offset, i, target_brightness);
1048
1049 if (refresh == stream->lumin_data.refresh_rate_hz[i + offset])
1050 return stream->lumin_data.refresh_rate_hz[i + offset];
1051
1052 return refresh;
1053 }
1054 }
1055
1056 if (search_for_max_increase)
1057 return (int)div64_s64((long long)stream->timing.pix_clk_100hz*100, stream->timing.v_total*(long long)stream->timing.h_total);
1058 else
1059 return stream->lumin_data.refresh_rate_hz[0];
1060 }
1061
1062 /*
1063 * Gets the max delta luminance within a specified refresh range
1064 */
dc_stream_get_max_delta_lumin_millinits(struct dc_stream_state * stream,int hz1,int hz2,bool isGaming)1065 static int dc_stream_get_max_delta_lumin_millinits(struct dc_stream_state *stream, int hz1, int hz2, bool isGaming)
1066 {
1067 int lower_refresh_brightness = dc_stream_get_brightness_millinits_from_refresh (stream, hz1);
1068 int higher_refresh_brightness = dc_stream_get_brightness_millinits_from_refresh (stream, hz2);
1069
1070 int min = lower_refresh_brightness;
1071 int max = higher_refresh_brightness;
1072
1073 /*
1074 * Static screen, therefore no need to scan through array
1075 */
1076 if (!isGaming) {
1077 if (lower_refresh_brightness >= higher_refresh_brightness) {
1078 return lower_refresh_brightness - higher_refresh_brightness;
1079 }
1080 return higher_refresh_brightness - lower_refresh_brightness;
1081 }
1082
1083 min = MIN(lower_refresh_brightness, higher_refresh_brightness);
1084 max = MAX(lower_refresh_brightness, higher_refresh_brightness);
1085
1086 int nearest_smallest_index = dc_stream_get_nearest_smallest_index(stream, hz1);
1087
1088 for (; nearest_smallest_index < (LUMINANCE_DATA_TABLE_SIZE - 1) &&
1089 stream->lumin_data.refresh_rate_hz[nearest_smallest_index + 1] <= hz2 ; nearest_smallest_index++) {
1090 min = MIN(min, stream->lumin_data.luminance_millinits[nearest_smallest_index + 1]);
1091 max = MAX(max, stream->lumin_data.luminance_millinits[nearest_smallest_index + 1]);
1092 }
1093
1094 return (max - min);
1095 }
1096
1097 /*
1098 * Determines the max flickerless instant vtotal delta for a stream.
1099 * Determines vtotal increase/decrease based on the bool "increase"
1100 */
dc_stream_get_max_flickerless_instant_vtotal_delta(struct dc_stream_state * stream,bool is_gaming,bool increase)1101 static unsigned int dc_stream_get_max_flickerless_instant_vtotal_delta(struct dc_stream_state *stream, bool is_gaming, bool increase)
1102 {
1103 if (stream->timing.v_total * stream->timing.h_total == 0)
1104 return 0;
1105
1106 int current_refresh_hz = (int)div64_s64((long long)stream->timing.pix_clk_100hz*100, stream->timing.v_total*(long long)stream->timing.h_total);
1107
1108 int safe_refresh_hz = dc_stream_calculate_flickerless_refresh_rate(stream,
1109 dc_stream_get_brightness_millinits_from_refresh(stream, current_refresh_hz),
1110 current_refresh_hz,
1111 is_gaming,
1112 increase);
1113
1114 int safe_refresh_v_total = (int)div64_s64((long long)stream->timing.pix_clk_100hz*100, safe_refresh_hz*(long long)stream->timing.h_total);
1115
1116 if (increase)
1117 return (((int) stream->timing.v_total - safe_refresh_v_total) >= 0) ? (stream->timing.v_total - safe_refresh_v_total) : 0;
1118
1119 return ((safe_refresh_v_total - (int) stream->timing.v_total) >= 0) ? (safe_refresh_v_total - stream->timing.v_total) : 0;
1120 }
1121
1122 /*
1123 * Finds the highest refresh rate that can be achieved
1124 * from starting_refresh_hz while staying within flicker criteria
1125 */
dc_stream_calculate_max_flickerless_refresh_rate(struct dc_stream_state * stream,int starting_refresh_hz,bool is_gaming)1126 int dc_stream_calculate_max_flickerless_refresh_rate(struct dc_stream_state *stream, int starting_refresh_hz, bool is_gaming)
1127 {
1128 if (!stream->lumin_data.is_valid)
1129 return 0;
1130
1131 int current_brightness = dc_stream_get_brightness_millinits_from_refresh(stream, starting_refresh_hz);
1132
1133 return dc_stream_calculate_flickerless_refresh_rate(stream,
1134 current_brightness,
1135 starting_refresh_hz,
1136 is_gaming,
1137 true);
1138 }
1139
1140 /*
1141 * Finds the lowest refresh rate that can be achieved
1142 * from starting_refresh_hz while staying within flicker criteria
1143 */
dc_stream_calculate_min_flickerless_refresh_rate(struct dc_stream_state * stream,int starting_refresh_hz,bool is_gaming)1144 int dc_stream_calculate_min_flickerless_refresh_rate(struct dc_stream_state *stream, int starting_refresh_hz, bool is_gaming)
1145 {
1146 if (!stream->lumin_data.is_valid)
1147 return 0;
1148
1149 int current_brightness = dc_stream_get_brightness_millinits_from_refresh(stream, starting_refresh_hz);
1150
1151 return dc_stream_calculate_flickerless_refresh_rate(stream,
1152 current_brightness,
1153 starting_refresh_hz,
1154 is_gaming,
1155 false);
1156 }
1157
1158 /*
1159 * Determines if there will be a flicker when moving between 2 refresh rates
1160 */
dc_stream_is_refresh_rate_range_flickerless(struct dc_stream_state * stream,int hz1,int hz2,bool is_gaming)1161 bool dc_stream_is_refresh_rate_range_flickerless(struct dc_stream_state *stream, int hz1, int hz2, bool is_gaming)
1162 {
1163
1164 /*
1165 * Assume that we wont flicker if there is invalid data
1166 */
1167 if (!stream->lumin_data.is_valid)
1168 return false;
1169
1170 int dl = dc_stream_get_max_delta_lumin_millinits(stream, hz1, hz2, is_gaming);
1171
1172 int flicker_criteria_millinits = (is_gaming) ?
1173 stream->lumin_data.flicker_criteria_milli_nits_GAMING :
1174 stream->lumin_data.flicker_criteria_milli_nits_STATIC;
1175
1176 return (dl <= flicker_criteria_millinits);
1177 }
1178
1179 /*
1180 * Determines the max instant vtotal delta increase that can be applied without
1181 * flickering for a given stream
1182 */
dc_stream_get_max_flickerless_instant_vtotal_decrease(struct dc_stream_state * stream,bool is_gaming)1183 unsigned int dc_stream_get_max_flickerless_instant_vtotal_decrease(struct dc_stream_state *stream,
1184 bool is_gaming)
1185 {
1186 if (!stream->lumin_data.is_valid)
1187 return 0;
1188
1189 return dc_stream_get_max_flickerless_instant_vtotal_delta(stream, is_gaming, true);
1190 }
1191
1192 /*
1193 * Determines the max instant vtotal delta decrease that can be applied without
1194 * flickering for a given stream
1195 */
dc_stream_get_max_flickerless_instant_vtotal_increase(struct dc_stream_state * stream,bool is_gaming)1196 unsigned int dc_stream_get_max_flickerless_instant_vtotal_increase(struct dc_stream_state *stream,
1197 bool is_gaming)
1198 {
1199 if (!stream->lumin_data.is_valid)
1200 return 0;
1201
1202 return dc_stream_get_max_flickerless_instant_vtotal_delta(stream, is_gaming, false);
1203 }
1204
dc_stream_is_cursor_limit_pending(struct dc * dc,struct dc_stream_state * stream)1205 bool dc_stream_is_cursor_limit_pending(struct dc *dc, struct dc_stream_state *stream)
1206 {
1207 bool is_limit_pending = false;
1208
1209 if (dc->current_state)
1210 is_limit_pending = dc_state_get_stream_cursor_subvp_limit(stream, dc->current_state);
1211
1212 return is_limit_pending;
1213 }
1214
dc_stream_can_clear_cursor_limit(struct dc * dc,struct dc_stream_state * stream)1215 bool dc_stream_can_clear_cursor_limit(struct dc *dc, struct dc_stream_state *stream)
1216 {
1217 bool can_clear_limit = false;
1218
1219 if (dc->current_state)
1220 can_clear_limit = dc_state_get_stream_cursor_subvp_limit(stream, dc->current_state) &&
1221 (stream->hw_cursor_req ||
1222 !stream->cursor_position.enable ||
1223 dc_stream_check_cursor_attributes(stream, dc->current_state, &stream->cursor_attributes));
1224
1225 return can_clear_limit;
1226 }
1227