2 * Copyright 2015 Advanced Micro Devices, Inc.
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:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
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.
25 #include "dm_services.h"
31 #include "core_status.h"
32 #include "core_types.h"
33 #include "hw_sequencer.h"
34 #include "dce/dce_hwseq.h"
38 #include "dc_state_priv.h"
40 #include "gpio_service_interface.h"
42 #include "clock_source.h"
43 #include "dc_bios_types.h"
45 #include "bios_parser_interface.h"
46 #include "bios/bios_parser_helper.h"
47 #include "include/irq_service_interface.h"
48 #include "transform.h"
51 #include "timing_generator.h"
53 #include "virtual/virtual_link_encoder.h"
56 #include "link_hwss.h"
57 #include "link_encoder.h"
58 #include "link_enc_cfg.h"
61 #include "dm_helpers.h"
62 #include "mem_input.h"
64 #include "dc_dmub_srv.h"
68 #include "vm_helper.h"
70 #include "dce/dce_i2c.h"
72 #include "dmub/dmub_srv.h"
74 #include "dce/dmub_psr.h"
76 #include "dce/dmub_hw_lock_mgr.h"
80 #include "hw_sequencer_private.h"
82 #include "dml2/dml2_internal_types.h"
84 #include "dce/dmub_outbox.h"
92 static const char DC_BUILD_ID[] = "production-build";
97 * DC is the OS-agnostic component of the amdgpu DC driver.
99 * DC maintains and validates a set of structs representing the state of the
100 * driver and writes that state to AMD hardware
102 * Main DC HW structs:
104 * struct dc - The central struct. One per driver. Created on driver load,
105 * destroyed on driver unload.
107 * struct dc_context - One per driver.
108 * Used as a backpointer by most other structs in dc.
110 * struct dc_link - One per connector (the physical DP, HDMI, miniDP, or eDP
111 * plugpoints). Created on driver load, destroyed on driver unload.
113 * struct dc_sink - One per display. Created on boot or hotplug.
114 * Destroyed on shutdown or hotunplug. A dc_link can have a local sink
115 * (the display directly attached). It may also have one or more remote
116 * sinks (in the Multi-Stream Transport case)
118 * struct resource_pool - One per driver. Represents the hw blocks not in the
119 * main pipeline. Not directly accessible by dm.
121 * Main dc state structs:
123 * These structs can be created and destroyed as needed. There is a full set of
124 * these structs in dc->current_state representing the currently programmed state.
126 * struct dc_state - The global DC state to track global state information,
127 * such as bandwidth values.
129 * struct dc_stream_state - Represents the hw configuration for the pipeline from
130 * a framebuffer to a display. Maps one-to-one with dc_sink.
132 * struct dc_plane_state - Represents a framebuffer. Each stream has at least one,
133 * and may have more in the Multi-Plane Overlay case.
135 * struct resource_context - Represents the programmable state of everything in
136 * the resource_pool. Not directly accessible by dm.
138 * struct pipe_ctx - A member of struct resource_context. Represents the
139 * internal hardware pipeline components. Each dc_plane_state has either
140 * one or two (in the pipe-split case).
143 /* Private functions */
145 static inline void elevate_update_type(enum surface_update_type *original, enum surface_update_type new)
151 static void destroy_links(struct dc *dc)
155 for (i = 0; i < dc->link_count; i++) {
156 if (NULL != dc->links[i])
157 dc->link_srv->destroy_link(&dc->links[i]);
161 static uint32_t get_num_of_internal_disp(struct dc_link **links, uint32_t num_links)
166 for (i = 0; i < num_links; i++) {
167 if (links[i]->connector_signal == SIGNAL_TYPE_EDP ||
168 links[i]->is_internal_display)
175 static int get_seamless_boot_stream_count(struct dc_state *ctx)
178 uint8_t seamless_boot_stream_count = 0;
180 for (i = 0; i < ctx->stream_count; i++)
181 if (ctx->streams[i]->apply_seamless_boot_optimization)
182 seamless_boot_stream_count++;
184 return seamless_boot_stream_count;
187 static bool create_links(
189 uint32_t num_virtual_links)
193 struct dc_bios *bios = dc->ctx->dc_bios;
197 connectors_num = bios->funcs->get_connectors_number(bios);
199 DC_LOG_DC("BIOS object table - number of connectors: %d", connectors_num);
201 if (connectors_num > ENUM_ID_COUNT) {
203 "DC: Number of connectors %d exceeds maximum of %d!\n",
209 dm_output_to_console(
210 "DC: %s: connectors_num: physical:%d, virtual:%d\n",
215 for (i = 0; i < connectors_num; i++) {
216 struct link_init_data link_init_params = {0};
217 struct dc_link *link;
219 DC_LOG_DC("BIOS object table - printing link object info for connector number: %d, link_index: %d", i, dc->link_count);
221 link_init_params.ctx = dc->ctx;
222 /* next BIOS object table connector */
223 link_init_params.connector_index = i;
224 link_init_params.link_index = dc->link_count;
225 link_init_params.dc = dc;
226 link = dc->link_srv->create_link(&link_init_params);
229 dc->links[dc->link_count] = link;
235 DC_LOG_DC("BIOS object table - end");
237 /* Create a link for each usb4 dpia port */
238 for (i = 0; i < dc->res_pool->usb4_dpia_count; i++) {
239 struct link_init_data link_init_params = {0};
240 struct dc_link *link;
242 link_init_params.ctx = dc->ctx;
243 link_init_params.connector_index = i;
244 link_init_params.link_index = dc->link_count;
245 link_init_params.dc = dc;
246 link_init_params.is_dpia_link = true;
248 link = dc->link_srv->create_link(&link_init_params);
250 dc->links[dc->link_count] = link;
256 for (i = 0; i < num_virtual_links; i++) {
257 struct dc_link *link = kzalloc(sizeof(*link), GFP_KERNEL);
258 struct encoder_init_data enc_init = {0};
265 link->link_index = dc->link_count;
266 dc->links[dc->link_count] = link;
271 link->connector_signal = SIGNAL_TYPE_VIRTUAL;
272 link->link_id.type = OBJECT_TYPE_CONNECTOR;
273 link->link_id.id = CONNECTOR_ID_VIRTUAL;
274 link->link_id.enum_id = ENUM_ID_1;
275 link->link_enc = kzalloc(sizeof(*link->link_enc), GFP_KERNEL);
277 if (!link->link_enc) {
282 link->link_status.dpcd_caps = &link->dpcd_caps;
284 enc_init.ctx = dc->ctx;
285 enc_init.channel = CHANNEL_ID_UNKNOWN;
286 enc_init.hpd_source = HPD_SOURCEID_UNKNOWN;
287 enc_init.transmitter = TRANSMITTER_UNKNOWN;
288 enc_init.connector = link->link_id;
289 enc_init.encoder.type = OBJECT_TYPE_ENCODER;
290 enc_init.encoder.id = ENCODER_ID_INTERNAL_VIRTUAL;
291 enc_init.encoder.enum_id = ENUM_ID_1;
292 virtual_link_encoder_construct(link->link_enc, &enc_init);
295 dc->caps.num_of_internal_disp = get_num_of_internal_disp(dc->links, dc->link_count);
303 /* Create additional DIG link encoder objects if fewer than the platform
304 * supports were created during link construction. This can happen if the
305 * number of physical connectors is less than the number of DIGs.
307 static bool create_link_encoders(struct dc *dc)
310 unsigned int num_usb4_dpia = dc->res_pool->res_cap->num_usb4_dpia;
311 unsigned int num_dig_link_enc = dc->res_pool->res_cap->num_dig_link_enc;
314 /* A platform without USB4 DPIA endpoints has a fixed mapping between DIG
315 * link encoders and physical display endpoints and does not require
316 * additional link encoder objects.
318 if (num_usb4_dpia == 0)
321 /* Create as many link encoder objects as the platform supports. DPIA
322 * endpoints can be programmably mapped to any DIG.
324 if (num_dig_link_enc > dc->res_pool->dig_link_enc_count) {
325 for (i = 0; i < num_dig_link_enc; i++) {
326 struct link_encoder *link_enc = dc->res_pool->link_encoders[i];
328 if (!link_enc && dc->res_pool->funcs->link_enc_create_minimal) {
329 link_enc = dc->res_pool->funcs->link_enc_create_minimal(dc->ctx,
330 (enum engine_id)(ENGINE_ID_DIGA + i));
332 dc->res_pool->link_encoders[i] = link_enc;
333 dc->res_pool->dig_link_enc_count++;
344 /* Destroy any additional DIG link encoder objects created by
345 * create_link_encoders().
346 * NB: Must only be called after destroy_links().
348 static void destroy_link_encoders(struct dc *dc)
350 unsigned int num_usb4_dpia;
351 unsigned int num_dig_link_enc;
357 num_usb4_dpia = dc->res_pool->res_cap->num_usb4_dpia;
358 num_dig_link_enc = dc->res_pool->res_cap->num_dig_link_enc;
360 /* A platform without USB4 DPIA endpoints has a fixed mapping between DIG
361 * link encoders and physical display endpoints and does not require
362 * additional link encoder objects.
364 if (num_usb4_dpia == 0)
367 for (i = 0; i < num_dig_link_enc; i++) {
368 struct link_encoder *link_enc = dc->res_pool->link_encoders[i];
371 link_enc->funcs->destroy(&link_enc);
372 dc->res_pool->link_encoders[i] = NULL;
373 dc->res_pool->dig_link_enc_count--;
378 static struct dc_perf_trace *dc_perf_trace_create(void)
380 return kzalloc(sizeof(struct dc_perf_trace), GFP_KERNEL);
383 static void dc_perf_trace_destroy(struct dc_perf_trace **perf_trace)
390 * dc_stream_adjust_vmin_vmax - look up pipe context & update parts of DRR
392 * @stream: Initial dc stream state
393 * @adjust: Updated parameters for vertical_total_min and vertical_total_max
395 * Looks up the pipe context of dc_stream_state and updates the
396 * vertical_total_min and vertical_total_max of the DRR, Dynamic Refresh
397 * Rate, which is a power-saving feature that targets reducing panel
398 * refresh rate while the screen is static
400 * Return: %true if the pipe context is found and adjusted;
401 * %false if the pipe context is not found.
403 bool dc_stream_adjust_vmin_vmax(struct dc *dc,
404 struct dc_stream_state *stream,
405 struct dc_crtc_timing_adjust *adjust)
410 * Don't adjust DRR while there's bandwidth optimizations pending to
411 * avoid conflicting with firmware updates.
413 if (dc->ctx->dce_version > DCE_VERSION_MAX)
414 if (dc->optimized_required || dc->wm_optimized_required)
417 stream->adjust.v_total_max = adjust->v_total_max;
418 stream->adjust.v_total_mid = adjust->v_total_mid;
419 stream->adjust.v_total_mid_frame_num = adjust->v_total_mid_frame_num;
420 stream->adjust.v_total_min = adjust->v_total_min;
422 for (i = 0; i < MAX_PIPES; i++) {
423 struct pipe_ctx *pipe = &dc->current_state->res_ctx.pipe_ctx[i];
425 if (pipe->stream == stream && pipe->stream_res.tg) {
426 dc->hwss.set_drr(&pipe,
437 * dc_stream_get_last_used_drr_vtotal - Looks up the pipe context of
438 * dc_stream_state and gets the last VTOTAL used by DRR (Dynamic Refresh Rate)
440 * @dc: [in] dc reference
441 * @stream: [in] Initial dc stream state
442 * @refresh_rate: [in] new refresh_rate
444 * Return: %true if the pipe context is found and there is an associated
445 * timing_generator for the DC;
446 * %false if the pipe context is not found or there is no
447 * timing_generator for the DC.
449 bool dc_stream_get_last_used_drr_vtotal(struct dc *dc,
450 struct dc_stream_state *stream,
451 uint32_t *refresh_rate)
457 for (i = 0; i < MAX_PIPES; i++) {
458 struct pipe_ctx *pipe = &dc->current_state->res_ctx.pipe_ctx[i];
460 if (pipe->stream == stream && pipe->stream_res.tg) {
461 /* Only execute if a function pointer has been defined for
462 * the DC version in question
464 if (pipe->stream_res.tg->funcs->get_last_used_drr_vtotal) {
465 pipe->stream_res.tg->funcs->get_last_used_drr_vtotal(pipe->stream_res.tg, refresh_rate);
477 bool dc_stream_get_crtc_position(struct dc *dc,
478 struct dc_stream_state **streams, int num_streams,
479 unsigned int *v_pos, unsigned int *nom_v_pos)
481 /* TODO: Support multiple streams */
482 const struct dc_stream_state *stream = streams[0];
485 struct crtc_position position;
487 for (i = 0; i < MAX_PIPES; i++) {
488 struct pipe_ctx *pipe =
489 &dc->current_state->res_ctx.pipe_ctx[i];
491 if (pipe->stream == stream && pipe->stream_res.stream_enc) {
492 dc->hwss.get_position(&pipe, 1, &position);
494 *v_pos = position.vertical_count;
495 *nom_v_pos = position.nominal_vcount;
502 #if defined(CONFIG_DRM_AMD_SECURE_DISPLAY)
504 dc_stream_forward_dmub_crc_window(struct dc_dmub_srv *dmub_srv,
505 struct rect *rect, struct otg_phy_mux *mux_mapping, bool is_stop)
507 union dmub_rb_cmd cmd = {0};
509 cmd.secure_display.roi_info.phy_id = mux_mapping->phy_output_num;
510 cmd.secure_display.roi_info.otg_id = mux_mapping->otg_output_num;
513 cmd.secure_display.header.type = DMUB_CMD__SECURE_DISPLAY;
514 cmd.secure_display.header.sub_type = DMUB_CMD__SECURE_DISPLAY_CRC_STOP_UPDATE;
516 cmd.secure_display.header.type = DMUB_CMD__SECURE_DISPLAY;
517 cmd.secure_display.header.sub_type = DMUB_CMD__SECURE_DISPLAY_CRC_WIN_NOTIFY;
518 cmd.secure_display.roi_info.x_start = rect->x;
519 cmd.secure_display.roi_info.y_start = rect->y;
520 cmd.secure_display.roi_info.x_end = rect->x + rect->width;
521 cmd.secure_display.roi_info.y_end = rect->y + rect->height;
524 dc_wake_and_execute_dmub_cmd(dmub_srv->ctx, &cmd, DM_DMUB_WAIT_TYPE_NO_WAIT);
528 dc_stream_forward_dmcu_crc_window(struct dmcu *dmcu,
529 struct rect *rect, struct otg_phy_mux *mux_mapping, bool is_stop)
532 dmcu->funcs->stop_crc_win_update(dmcu, mux_mapping);
534 dmcu->funcs->forward_crc_window(dmcu, rect, mux_mapping);
538 dc_stream_forward_crc_window(struct dc_stream_state *stream,
539 struct rect *rect, bool is_stop)
542 struct dc_dmub_srv *dmub_srv;
543 struct otg_phy_mux mux_mapping;
544 struct pipe_ctx *pipe;
546 struct dc *dc = stream->ctx->dc;
548 for (i = 0; i < MAX_PIPES; i++) {
549 pipe = &dc->current_state->res_ctx.pipe_ctx[i];
550 if (pipe->stream == stream && !pipe->top_pipe && !pipe->prev_odm_pipe)
554 /* Stream not found */
558 mux_mapping.phy_output_num = stream->link->link_enc_hw_inst;
559 mux_mapping.otg_output_num = pipe->stream_res.tg->inst;
561 dmcu = dc->res_pool->dmcu;
562 dmub_srv = dc->ctx->dmub_srv;
564 /* forward to dmub */
566 dc_stream_forward_dmub_crc_window(dmub_srv, rect, &mux_mapping, is_stop);
567 /* forward to dmcu */
568 else if (dmcu && dmcu->funcs->is_dmcu_initialized(dmcu))
569 dc_stream_forward_dmcu_crc_window(dmcu, rect, &mux_mapping, is_stop);
575 #endif /* CONFIG_DRM_AMD_SECURE_DISPLAY */
578 * dc_stream_configure_crc() - Configure CRC capture for the given stream.
580 * @stream: The stream to configure CRC on.
581 * @enable: Enable CRC if true, disable otherwise.
582 * @crc_window: CRC window (x/y start/end) information
583 * @continuous: Capture CRC on every frame if true. Otherwise, only capture
586 * By default, only CRC0 is configured, and the entire frame is used to
589 * Return: %false if the stream is not found or CRC capture is not supported;
590 * %true if the stream has been configured.
592 bool dc_stream_configure_crc(struct dc *dc, struct dc_stream_state *stream,
593 struct crc_params *crc_window, bool enable, bool continuous)
595 struct pipe_ctx *pipe;
596 struct crc_params param;
597 struct timing_generator *tg;
599 pipe = resource_get_otg_master_for_stream(
600 &dc->current_state->res_ctx, stream);
602 /* Stream not found */
606 /* By default, capture the full frame */
607 param.windowa_x_start = 0;
608 param.windowa_y_start = 0;
609 param.windowa_x_end = pipe->stream->timing.h_addressable;
610 param.windowa_y_end = pipe->stream->timing.v_addressable;
611 param.windowb_x_start = 0;
612 param.windowb_y_start = 0;
613 param.windowb_x_end = pipe->stream->timing.h_addressable;
614 param.windowb_y_end = pipe->stream->timing.v_addressable;
617 param.windowa_x_start = crc_window->windowa_x_start;
618 param.windowa_y_start = crc_window->windowa_y_start;
619 param.windowa_x_end = crc_window->windowa_x_end;
620 param.windowa_y_end = crc_window->windowa_y_end;
621 param.windowb_x_start = crc_window->windowb_x_start;
622 param.windowb_y_start = crc_window->windowb_y_start;
623 param.windowb_x_end = crc_window->windowb_x_end;
624 param.windowb_y_end = crc_window->windowb_y_end;
627 param.dsc_mode = pipe->stream->timing.flags.DSC ? 1:0;
628 param.odm_mode = pipe->next_odm_pipe ? 1:0;
630 /* Default to the union of both windows */
631 param.selection = UNION_WINDOW_A_B;
632 param.continuous_mode = continuous;
633 param.enable = enable;
635 tg = pipe->stream_res.tg;
637 /* Only call if supported */
638 if (tg->funcs->configure_crc)
639 return tg->funcs->configure_crc(tg, ¶m);
640 DC_LOG_WARNING("CRC capture not supported.");
645 * dc_stream_get_crc() - Get CRC values for the given stream.
648 * @stream: The DC stream state of the stream to get CRCs from.
649 * @r_cr: CRC value for the red component.
650 * @g_y: CRC value for the green component.
651 * @b_cb: CRC value for the blue component.
653 * dc_stream_configure_crc needs to be called beforehand to enable CRCs.
656 * %false if stream is not found, or if CRCs are not enabled.
658 bool dc_stream_get_crc(struct dc *dc, struct dc_stream_state *stream,
659 uint32_t *r_cr, uint32_t *g_y, uint32_t *b_cb)
662 struct pipe_ctx *pipe;
663 struct timing_generator *tg;
665 for (i = 0; i < MAX_PIPES; i++) {
666 pipe = &dc->current_state->res_ctx.pipe_ctx[i];
667 if (pipe->stream == stream)
670 /* Stream not found */
674 tg = pipe->stream_res.tg;
676 if (tg->funcs->get_crc)
677 return tg->funcs->get_crc(tg, r_cr, g_y, b_cb);
678 DC_LOG_WARNING("CRC capture not supported.");
682 void dc_stream_set_dyn_expansion(struct dc *dc, struct dc_stream_state *stream,
683 enum dc_dynamic_expansion option)
685 /* OPP FMT dyn expansion updates*/
687 struct pipe_ctx *pipe_ctx;
689 for (i = 0; i < MAX_PIPES; i++) {
690 if (dc->current_state->res_ctx.pipe_ctx[i].stream
692 pipe_ctx = &dc->current_state->res_ctx.pipe_ctx[i];
693 pipe_ctx->stream_res.opp->dyn_expansion = option;
694 pipe_ctx->stream_res.opp->funcs->opp_set_dyn_expansion(
695 pipe_ctx->stream_res.opp,
696 COLOR_SPACE_YCBCR601,
697 stream->timing.display_color_depth,
703 void dc_stream_set_dither_option(struct dc_stream_state *stream,
704 enum dc_dither_option option)
706 struct bit_depth_reduction_params params;
707 struct dc_link *link = stream->link;
708 struct pipe_ctx *pipes = NULL;
711 for (i = 0; i < MAX_PIPES; i++) {
712 if (link->dc->current_state->res_ctx.pipe_ctx[i].stream ==
714 pipes = &link->dc->current_state->res_ctx.pipe_ctx[i];
721 if (option > DITHER_OPTION_MAX)
724 stream->dither_option = option;
726 memset(¶ms, 0, sizeof(params));
727 resource_build_bit_depth_reduction_params(stream, ¶ms);
728 stream->bit_depth_params = params;
730 if (pipes->plane_res.xfm &&
731 pipes->plane_res.xfm->funcs->transform_set_pixel_storage_depth) {
732 pipes->plane_res.xfm->funcs->transform_set_pixel_storage_depth(
733 pipes->plane_res.xfm,
734 pipes->plane_res.scl_data.lb_params.depth,
735 &stream->bit_depth_params);
738 pipes->stream_res.opp->funcs->
739 opp_program_bit_depth_reduction(pipes->stream_res.opp, ¶ms);
742 bool dc_stream_set_gamut_remap(struct dc *dc, const struct dc_stream_state *stream)
746 struct pipe_ctx *pipes;
748 for (i = 0; i < MAX_PIPES; i++) {
749 if (dc->current_state->res_ctx.pipe_ctx[i].stream == stream) {
750 pipes = &dc->current_state->res_ctx.pipe_ctx[i];
751 dc->hwss.program_gamut_remap(pipes);
759 bool dc_stream_program_csc_matrix(struct dc *dc, struct dc_stream_state *stream)
763 struct pipe_ctx *pipes;
765 for (i = 0; i < MAX_PIPES; i++) {
766 if (dc->current_state->res_ctx.pipe_ctx[i].stream
769 pipes = &dc->current_state->res_ctx.pipe_ctx[i];
770 dc->hwss.program_output_csc(dc,
772 stream->output_color_space,
773 stream->csc_color_matrix.matrix,
774 pipes->stream_res.opp->inst);
782 void dc_stream_set_static_screen_params(struct dc *dc,
783 struct dc_stream_state **streams,
785 const struct dc_static_screen_params *params)
788 struct pipe_ctx *pipes_affected[MAX_PIPES];
789 int num_pipes_affected = 0;
791 for (i = 0; i < num_streams; i++) {
792 struct dc_stream_state *stream = streams[i];
794 for (j = 0; j < MAX_PIPES; j++) {
795 if (dc->current_state->res_ctx.pipe_ctx[j].stream
797 pipes_affected[num_pipes_affected++] =
798 &dc->current_state->res_ctx.pipe_ctx[j];
803 dc->hwss.set_static_screen_control(pipes_affected, num_pipes_affected, params);
806 static void dc_destruct(struct dc *dc)
808 // reset link encoder assignment table on destruct
809 if (dc->res_pool && dc->res_pool->funcs->link_encs_assign)
810 link_enc_cfg_init(dc, dc->current_state);
812 if (dc->current_state) {
813 dc_state_release(dc->current_state);
814 dc->current_state = NULL;
819 destroy_link_encoders(dc);
822 dc_destroy_clk_mgr(dc->clk_mgr);
826 dc_destroy_resource_pool(dc);
829 link_destroy_link_service(&dc->link_srv);
831 if (dc->ctx->gpio_service)
832 dal_gpio_service_destroy(&dc->ctx->gpio_service);
834 if (dc->ctx->created_bios)
835 dal_bios_parser_destroy(&dc->ctx->dc_bios);
837 kfree(dc->ctx->logger);
838 dc_perf_trace_destroy(&dc->ctx->perf_trace);
855 kfree(dc->vm_helper);
856 dc->vm_helper = NULL;
860 static bool dc_construct_ctx(struct dc *dc,
861 const struct dc_init_data *init_params)
863 struct dc_context *dc_ctx;
865 dc_ctx = kzalloc(sizeof(*dc_ctx), GFP_KERNEL);
869 dc_ctx->cgs_device = init_params->cgs_device;
870 dc_ctx->driver_context = init_params->driver;
872 dc_ctx->asic_id = init_params->asic_id;
873 dc_ctx->dc_sink_id_count = 0;
874 dc_ctx->dc_stream_id_count = 0;
875 dc_ctx->dce_environment = init_params->dce_environment;
876 dc_ctx->dcn_reg_offsets = init_params->dcn_reg_offsets;
877 dc_ctx->nbio_reg_offsets = init_params->nbio_reg_offsets;
878 dc_ctx->clk_reg_offsets = init_params->clk_reg_offsets;
881 dc_ctx->logger = kmalloc(sizeof(*dc_ctx->logger), GFP_KERNEL);
883 if (!dc_ctx->logger) {
888 dc_ctx->logger->dev = adev_to_drm(init_params->driver);
889 dc->dml.logger = dc_ctx->logger;
891 dc_ctx->dce_version = resource_parse_asic_id(init_params->asic_id);
893 dc_ctx->perf_trace = dc_perf_trace_create();
894 if (!dc_ctx->perf_trace) {
896 ASSERT_CRITICAL(false);
902 dc->link_srv = link_create_link_service();
909 static bool dc_construct(struct dc *dc,
910 const struct dc_init_data *init_params)
912 struct dc_context *dc_ctx;
913 struct bw_calcs_dceip *dc_dceip;
914 struct bw_calcs_vbios *dc_vbios;
915 struct dcn_soc_bounding_box *dcn_soc;
916 struct dcn_ip_params *dcn_ip;
918 dc->config = init_params->flags;
920 // Allocate memory for the vm_helper
921 dc->vm_helper = kzalloc(sizeof(struct vm_helper), GFP_KERNEL);
922 if (!dc->vm_helper) {
923 dm_error("%s: failed to create dc->vm_helper\n", __func__);
927 memcpy(&dc->bb_overrides, &init_params->bb_overrides, sizeof(dc->bb_overrides));
929 dc_dceip = kzalloc(sizeof(*dc_dceip), GFP_KERNEL);
931 dm_error("%s: failed to create dceip\n", __func__);
935 dc->bw_dceip = dc_dceip;
937 dc_vbios = kzalloc(sizeof(*dc_vbios), GFP_KERNEL);
939 dm_error("%s: failed to create vbios\n", __func__);
943 dc->bw_vbios = dc_vbios;
944 dcn_soc = kzalloc(sizeof(*dcn_soc), GFP_KERNEL);
946 dm_error("%s: failed to create dcn_soc\n", __func__);
950 dc->dcn_soc = dcn_soc;
952 dcn_ip = kzalloc(sizeof(*dcn_ip), GFP_KERNEL);
954 dm_error("%s: failed to create dcn_ip\n", __func__);
960 if (!dc_construct_ctx(dc, init_params)) {
961 dm_error("%s: failed to create ctx\n", __func__);
967 /* Resource should construct all asic specific resources.
968 * This should be the only place where we need to parse the asic id
970 if (init_params->vbios_override)
971 dc_ctx->dc_bios = init_params->vbios_override;
973 /* Create BIOS parser */
974 struct bp_init_data bp_init_data;
976 bp_init_data.ctx = dc_ctx;
977 bp_init_data.bios = init_params->asic_id.atombios_base_address;
979 dc_ctx->dc_bios = dal_bios_parser_create(
980 &bp_init_data, dc_ctx->dce_version);
982 if (!dc_ctx->dc_bios) {
983 ASSERT_CRITICAL(false);
987 dc_ctx->created_bios = true;
990 dc->vendor_signature = init_params->vendor_signature;
992 /* Create GPIO service */
993 dc_ctx->gpio_service = dal_gpio_service_create(
995 dc_ctx->dce_environment,
998 if (!dc_ctx->gpio_service) {
999 ASSERT_CRITICAL(false);
1003 dc->res_pool = dc_create_resource_pool(dc, init_params, dc_ctx->dce_version);
1007 /* set i2c speed if not done by the respective dcnxxx__resource.c */
1008 if (dc->caps.i2c_speed_in_khz_hdcp == 0)
1009 dc->caps.i2c_speed_in_khz_hdcp = dc->caps.i2c_speed_in_khz;
1010 if (dc->caps.max_optimizable_video_width == 0)
1011 dc->caps.max_optimizable_video_width = 5120;
1012 dc->clk_mgr = dc_clk_mgr_create(dc->ctx, dc->res_pool->pp_smu, dc->res_pool->dccg);
1015 #ifdef CONFIG_DRM_AMD_DC_FP
1016 dc->clk_mgr->force_smu_not_present = init_params->force_smu_not_present;
1018 if (dc->res_pool->funcs->update_bw_bounding_box) {
1020 dc->res_pool->funcs->update_bw_bounding_box(dc, dc->clk_mgr->bw_params);
1025 if (!create_links(dc, init_params->num_virtual_links))
1028 /* Create additional DIG link encoder objects if fewer than the platform
1029 * supports were created during link construction.
1031 if (!create_link_encoders(dc))
1034 /* Creation of current_state must occur after dc->dml
1035 * is initialized in dc_create_resource_pool because
1036 * on creation it copies the contents of dc->dml
1039 dc->current_state = dc_state_create(dc);
1041 if (!dc->current_state) {
1042 dm_error("%s: failed to create validate ctx\n", __func__);
1052 static void disable_all_writeback_pipes_for_stream(
1053 const struct dc *dc,
1054 struct dc_stream_state *stream,
1055 struct dc_state *context)
1059 for (i = 0; i < stream->num_wb_info; i++)
1060 stream->writeback_info[i].wb_enabled = false;
1063 static void apply_ctx_interdependent_lock(struct dc *dc,
1064 struct dc_state *context,
1065 struct dc_stream_state *stream,
1070 /* Checks if interdependent update function pointer is NULL or not, takes care of DCE110 case */
1071 if (dc->hwss.interdependent_update_lock)
1072 dc->hwss.interdependent_update_lock(dc, context, lock);
1074 for (i = 0; i < dc->res_pool->pipe_count; i++) {
1075 struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[i];
1076 struct pipe_ctx *old_pipe_ctx = &dc->current_state->res_ctx.pipe_ctx[i];
1078 // Copied conditions that were previously in dce110_apply_ctx_for_surface
1079 if (stream == pipe_ctx->stream) {
1080 if (resource_is_pipe_type(pipe_ctx, OPP_HEAD) &&
1081 (pipe_ctx->plane_state || old_pipe_ctx->plane_state))
1082 dc->hwss.pipe_control_lock(dc, pipe_ctx, lock);
1088 static void dc_update_visual_confirm_color(struct dc *dc, struct dc_state *context, struct pipe_ctx *pipe_ctx)
1090 if (dc->ctx->dce_version >= DCN_VERSION_1_0) {
1091 memset(&pipe_ctx->visual_confirm_color, 0, sizeof(struct tg_color));
1093 if (dc->debug.visual_confirm == VISUAL_CONFIRM_HDR)
1094 get_hdr_visual_confirm_color(pipe_ctx, &(pipe_ctx->visual_confirm_color));
1095 else if (dc->debug.visual_confirm == VISUAL_CONFIRM_SURFACE)
1096 get_surface_visual_confirm_color(pipe_ctx, &(pipe_ctx->visual_confirm_color));
1097 else if (dc->debug.visual_confirm == VISUAL_CONFIRM_SWIZZLE)
1098 get_surface_tile_visual_confirm_color(pipe_ctx, &(pipe_ctx->visual_confirm_color));
1100 if (dc->ctx->dce_version < DCN_VERSION_2_0)
1101 color_space_to_black_color(
1102 dc, pipe_ctx->stream->output_color_space, &(pipe_ctx->visual_confirm_color));
1104 if (dc->ctx->dce_version >= DCN_VERSION_2_0) {
1105 if (dc->debug.visual_confirm == VISUAL_CONFIRM_MPCTREE)
1106 get_mpctree_visual_confirm_color(pipe_ctx, &(pipe_ctx->visual_confirm_color));
1107 else if (dc->debug.visual_confirm == VISUAL_CONFIRM_SUBVP)
1108 get_subvp_visual_confirm_color(pipe_ctx, &(pipe_ctx->visual_confirm_color));
1109 else if (dc->debug.visual_confirm == VISUAL_CONFIRM_MCLK_SWITCH)
1110 get_mclk_switch_visual_confirm_color(pipe_ctx, &(pipe_ctx->visual_confirm_color));
1115 static void disable_dangling_plane(struct dc *dc, struct dc_state *context)
1118 struct dc_state *dangling_context = dc_state_create_current_copy(dc);
1119 struct dc_state *current_ctx;
1120 struct pipe_ctx *pipe;
1121 struct timing_generator *tg;
1123 if (dangling_context == NULL)
1126 for (i = 0; i < dc->res_pool->pipe_count; i++) {
1127 struct dc_stream_state *old_stream =
1128 dc->current_state->res_ctx.pipe_ctx[i].stream;
1129 bool should_disable = true;
1130 bool pipe_split_change = false;
1132 if ((context->res_ctx.pipe_ctx[i].top_pipe) &&
1133 (dc->current_state->res_ctx.pipe_ctx[i].top_pipe))
1134 pipe_split_change = context->res_ctx.pipe_ctx[i].top_pipe->pipe_idx !=
1135 dc->current_state->res_ctx.pipe_ctx[i].top_pipe->pipe_idx;
1137 pipe_split_change = context->res_ctx.pipe_ctx[i].top_pipe !=
1138 dc->current_state->res_ctx.pipe_ctx[i].top_pipe;
1140 for (j = 0; j < context->stream_count; j++) {
1141 if (old_stream == context->streams[j]) {
1142 should_disable = false;
1146 if (!should_disable && pipe_split_change &&
1147 dc->current_state->stream_count != context->stream_count)
1148 should_disable = true;
1150 if (old_stream && !dc->current_state->res_ctx.pipe_ctx[i].top_pipe &&
1151 !dc->current_state->res_ctx.pipe_ctx[i].prev_odm_pipe) {
1152 struct pipe_ctx *old_pipe, *new_pipe;
1154 old_pipe = &dc->current_state->res_ctx.pipe_ctx[i];
1155 new_pipe = &context->res_ctx.pipe_ctx[i];
1157 if (old_pipe->plane_state && !new_pipe->plane_state)
1158 should_disable = true;
1161 if (should_disable && old_stream) {
1162 bool is_phantom = dc_state_get_stream_subvp_type(dc->current_state, old_stream) == SUBVP_PHANTOM;
1163 pipe = &dc->current_state->res_ctx.pipe_ctx[i];
1164 tg = pipe->stream_res.tg;
1165 /* When disabling plane for a phantom pipe, we must turn on the
1166 * phantom OTG so the disable programming gets the double buffer
1167 * update. Otherwise the pipe will be left in a partially disabled
1168 * state that can result in underflow or hang when enabling it
1169 * again for different use.
1172 if (tg->funcs->enable_crtc) {
1173 int main_pipe_width, main_pipe_height;
1174 struct dc_stream_state *old_paired_stream = dc_state_get_paired_subvp_stream(dc->current_state, old_stream);
1176 main_pipe_width = old_paired_stream->dst.width;
1177 main_pipe_height = old_paired_stream->dst.height;
1178 if (dc->hwss.blank_phantom)
1179 dc->hwss.blank_phantom(dc, tg, main_pipe_width, main_pipe_height);
1180 tg->funcs->enable_crtc(tg);
1185 dc_state_rem_all_phantom_planes_for_stream(dc, old_stream, dangling_context, true);
1187 dc_state_rem_all_planes_for_stream(dc, old_stream, dangling_context);
1188 disable_all_writeback_pipes_for_stream(dc, old_stream, dangling_context);
1190 if (pipe->stream && pipe->plane_state) {
1191 set_p_state_switch_method(dc, context, pipe);
1192 dc_update_visual_confirm_color(dc, context, pipe);
1195 if (dc->hwss.apply_ctx_for_surface) {
1196 apply_ctx_interdependent_lock(dc, dc->current_state, old_stream, true);
1197 dc->hwss.apply_ctx_for_surface(dc, old_stream, 0, dangling_context);
1198 apply_ctx_interdependent_lock(dc, dc->current_state, old_stream, false);
1199 dc->hwss.post_unlock_program_front_end(dc, dangling_context);
1201 if (dc->hwss.program_front_end_for_ctx) {
1202 dc->hwss.interdependent_update_lock(dc, dc->current_state, true);
1203 dc->hwss.program_front_end_for_ctx(dc, dangling_context);
1204 dc->hwss.interdependent_update_lock(dc, dc->current_state, false);
1205 dc->hwss.post_unlock_program_front_end(dc, dangling_context);
1207 /* We need to put the phantom OTG back into it's default (disabled) state or we
1208 * can get corruption when transition from one SubVP config to a different one.
1209 * The OTG is set to disable on falling edge of VUPDATE so the plane disable
1210 * will still get it's double buffer update.
1213 if (tg->funcs->disable_phantom_crtc)
1214 tg->funcs->disable_phantom_crtc(tg);
1219 current_ctx = dc->current_state;
1220 dc->current_state = dangling_context;
1221 dc_state_release(current_ctx);
1224 static void disable_vbios_mode_if_required(
1226 struct dc_state *context)
1230 /* check if timing_changed, disable stream*/
1231 for (i = 0; i < dc->res_pool->pipe_count; i++) {
1232 struct dc_stream_state *stream = NULL;
1233 struct dc_link *link = NULL;
1234 struct pipe_ctx *pipe = NULL;
1236 pipe = &context->res_ctx.pipe_ctx[i];
1237 stream = pipe->stream;
1241 if (stream->apply_seamless_boot_optimization)
1244 // only looking for first odm pipe
1245 if (pipe->prev_odm_pipe)
1248 if (stream->link->local_sink &&
1249 stream->link->local_sink->sink_signal == SIGNAL_TYPE_EDP) {
1250 link = stream->link;
1253 if (link != NULL && link->link_enc->funcs->is_dig_enabled(link->link_enc)) {
1254 unsigned int enc_inst, tg_inst = 0;
1255 unsigned int pix_clk_100hz;
1257 enc_inst = link->link_enc->funcs->get_dig_frontend(link->link_enc);
1258 if (enc_inst != ENGINE_ID_UNKNOWN) {
1259 for (j = 0; j < dc->res_pool->stream_enc_count; j++) {
1260 if (dc->res_pool->stream_enc[j]->id == enc_inst) {
1261 tg_inst = dc->res_pool->stream_enc[j]->funcs->dig_source_otg(
1262 dc->res_pool->stream_enc[j]);
1267 dc->res_pool->dp_clock_source->funcs->get_pixel_clk_frequency_100hz(
1268 dc->res_pool->dp_clock_source,
1269 tg_inst, &pix_clk_100hz);
1271 if (link->link_status.link_active) {
1272 uint32_t requested_pix_clk_100hz =
1273 pipe->stream_res.pix_clk_params.requested_pix_clk_100hz;
1275 if (pix_clk_100hz != requested_pix_clk_100hz) {
1276 dc->link_srv->set_dpms_off(pipe);
1277 pipe->stream->dpms_off = false;
1285 static void wait_for_no_pipes_pending(struct dc *dc, struct dc_state *context)
1289 for (i = 0; i < MAX_PIPES; i++) {
1291 struct pipe_ctx *pipe = &context->res_ctx.pipe_ctx[i];
1293 if (!pipe->plane_state || dc_state_get_pipe_subvp_type(context, pipe) == SUBVP_PHANTOM)
1296 /* Timeout 100 ms */
1297 while (count < 100000) {
1298 /* Must set to false to start with, due to OR in update function */
1299 pipe->plane_state->status.is_flip_pending = false;
1300 dc->hwss.update_pending_status(pipe);
1301 if (!pipe->plane_state->status.is_flip_pending)
1306 ASSERT(!pipe->plane_state->status.is_flip_pending);
1311 /* Public functions */
1313 struct dc *dc_create(const struct dc_init_data *init_params)
1315 struct dc *dc = kzalloc(sizeof(*dc), GFP_KERNEL);
1316 unsigned int full_pipe_count;
1321 if (init_params->dce_environment == DCE_ENV_VIRTUAL_HW) {
1322 if (!dc_construct_ctx(dc, init_params))
1325 if (!dc_construct(dc, init_params))
1328 full_pipe_count = dc->res_pool->pipe_count;
1329 if (dc->res_pool->underlay_pipe_index != NO_UNDERLAY_PIPE)
1331 dc->caps.max_streams = min(
1333 dc->res_pool->stream_enc_count);
1335 dc->caps.max_links = dc->link_count;
1336 dc->caps.max_audios = dc->res_pool->audio_count;
1337 dc->caps.linear_pitch_alignment = 64;
1339 dc->caps.max_dp_protocol_version = DP_VERSION_1_4;
1341 dc->caps.max_otg_num = dc->res_pool->res_cap->num_timing_generator;
1343 if (dc->res_pool->dmcu != NULL)
1344 dc->versions.dmcu_version = dc->res_pool->dmcu->dmcu_version;
1347 dc->dcn_reg_offsets = init_params->dcn_reg_offsets;
1348 dc->nbio_reg_offsets = init_params->nbio_reg_offsets;
1349 dc->clk_reg_offsets = init_params->clk_reg_offsets;
1351 /* Populate versioning information */
1352 dc->versions.dc_ver = DC_VER;
1354 dc->build_id = DC_BUILD_ID;
1356 DC_LOG_DC("Display Core initialized\n");
1368 static void detect_edp_presence(struct dc *dc)
1370 struct dc_link *edp_links[MAX_NUM_EDP];
1371 struct dc_link *edp_link = NULL;
1372 enum dc_connection_type type;
1376 dc_get_edp_links(dc, edp_links, &edp_num);
1380 for (i = 0; i < edp_num; i++) {
1381 edp_link = edp_links[i];
1382 if (dc->config.edp_not_connected) {
1383 edp_link->edp_sink_present = false;
1385 dc_link_detect_connection_type(edp_link, &type);
1386 edp_link->edp_sink_present = (type != dc_connection_none);
1391 void dc_hardware_init(struct dc *dc)
1394 detect_edp_presence(dc);
1395 if (dc->ctx->dce_environment != DCE_ENV_VIRTUAL_HW)
1396 dc->hwss.init_hw(dc);
1399 void dc_init_callbacks(struct dc *dc,
1400 const struct dc_callback_init *init_params)
1402 dc->ctx->cp_psp = init_params->cp_psp;
1405 void dc_deinit_callbacks(struct dc *dc)
1407 memset(&dc->ctx->cp_psp, 0, sizeof(dc->ctx->cp_psp));
1410 void dc_destroy(struct dc **dc)
1417 static void enable_timing_multisync(
1419 struct dc_state *ctx)
1421 int i, multisync_count = 0;
1422 int pipe_count = dc->res_pool->pipe_count;
1423 struct pipe_ctx *multisync_pipes[MAX_PIPES] = { NULL };
1425 for (i = 0; i < pipe_count; i++) {
1426 if (!ctx->res_ctx.pipe_ctx[i].stream ||
1427 !ctx->res_ctx.pipe_ctx[i].stream->triggered_crtc_reset.enabled)
1429 if (ctx->res_ctx.pipe_ctx[i].stream == ctx->res_ctx.pipe_ctx[i].stream->triggered_crtc_reset.event_source)
1431 multisync_pipes[multisync_count] = &ctx->res_ctx.pipe_ctx[i];
1435 if (multisync_count > 0) {
1436 dc->hwss.enable_per_frame_crtc_position_reset(
1437 dc, multisync_count, multisync_pipes);
1441 static void program_timing_sync(
1443 struct dc_state *ctx)
1446 int group_index = 0;
1448 int pipe_count = dc->res_pool->pipe_count;
1449 struct pipe_ctx *unsynced_pipes[MAX_PIPES] = { NULL };
1451 for (i = 0; i < pipe_count; i++) {
1452 if (!ctx->res_ctx.pipe_ctx[i].stream
1453 || ctx->res_ctx.pipe_ctx[i].top_pipe
1454 || ctx->res_ctx.pipe_ctx[i].prev_odm_pipe)
1457 unsynced_pipes[i] = &ctx->res_ctx.pipe_ctx[i];
1460 for (i = 0; i < pipe_count; i++) {
1462 enum timing_synchronization_type sync_type = NOT_SYNCHRONIZABLE;
1463 struct pipe_ctx *pipe_set[MAX_PIPES];
1465 if (!unsynced_pipes[i])
1468 pipe_set[0] = unsynced_pipes[i];
1469 unsynced_pipes[i] = NULL;
1471 /* Add tg to the set, search rest of the tg's for ones with
1472 * same timing, add all tgs with same timing to the group
1474 for (j = i + 1; j < pipe_count; j++) {
1475 if (!unsynced_pipes[j])
1477 if (sync_type != TIMING_SYNCHRONIZABLE &&
1478 dc->hwss.enable_vblanks_synchronization &&
1479 unsynced_pipes[j]->stream_res.tg->funcs->align_vblanks &&
1480 resource_are_vblanks_synchronizable(
1481 unsynced_pipes[j]->stream,
1482 pipe_set[0]->stream)) {
1483 sync_type = VBLANK_SYNCHRONIZABLE;
1484 pipe_set[group_size] = unsynced_pipes[j];
1485 unsynced_pipes[j] = NULL;
1488 if (sync_type != VBLANK_SYNCHRONIZABLE &&
1489 resource_are_streams_timing_synchronizable(
1490 unsynced_pipes[j]->stream,
1491 pipe_set[0]->stream)) {
1492 sync_type = TIMING_SYNCHRONIZABLE;
1493 pipe_set[group_size] = unsynced_pipes[j];
1494 unsynced_pipes[j] = NULL;
1499 /* set first unblanked pipe as master */
1500 for (j = 0; j < group_size; j++) {
1503 if (pipe_set[j]->stream_res.opp->funcs->dpg_is_blanked)
1505 pipe_set[j]->stream_res.opp->funcs->dpg_is_blanked(pipe_set[j]->stream_res.opp);
1508 pipe_set[j]->stream_res.tg->funcs->is_blanked(pipe_set[j]->stream_res.tg);
1513 swap(pipe_set[0], pipe_set[j]);
1518 for (k = 0; k < group_size; k++) {
1519 struct dc_stream_status *status = dc_state_get_stream_status(ctx, pipe_set[k]->stream);
1521 status->timing_sync_info.group_id = num_group;
1522 status->timing_sync_info.group_size = group_size;
1524 status->timing_sync_info.master = true;
1526 status->timing_sync_info.master = false;
1530 /* remove any other unblanked pipes as they have already been synced */
1531 if (dc->config.use_pipe_ctx_sync_logic) {
1532 /* check pipe's syncd to decide which pipe to be removed */
1533 for (j = 1; j < group_size; j++) {
1534 if (pipe_set[j]->pipe_idx_syncd == pipe_set[0]->pipe_idx_syncd) {
1536 pipe_set[j] = pipe_set[group_size];
1539 /* link slave pipe's syncd with master pipe */
1540 pipe_set[j]->pipe_idx_syncd = pipe_set[0]->pipe_idx_syncd;
1543 /* remove any other pipes by checking valid plane */
1544 for (j = j + 1; j < group_size; j++) {
1547 if (pipe_set[j]->stream_res.opp->funcs->dpg_is_blanked)
1549 pipe_set[j]->stream_res.opp->funcs->dpg_is_blanked(pipe_set[j]->stream_res.opp);
1552 pipe_set[j]->stream_res.tg->funcs->is_blanked(pipe_set[j]->stream_res.tg);
1555 pipe_set[j] = pipe_set[group_size];
1561 if (group_size > 1) {
1562 if (sync_type == TIMING_SYNCHRONIZABLE) {
1563 dc->hwss.enable_timing_synchronization(
1564 dc, ctx, group_index, group_size, pipe_set);
1566 if (sync_type == VBLANK_SYNCHRONIZABLE) {
1567 dc->hwss.enable_vblanks_synchronization(
1568 dc, group_index, group_size, pipe_set);
1576 static bool streams_changed(struct dc *dc,
1577 struct dc_stream_state *streams[],
1578 uint8_t stream_count)
1582 if (stream_count != dc->current_state->stream_count)
1585 for (i = 0; i < dc->current_state->stream_count; i++) {
1586 if (dc->current_state->streams[i] != streams[i])
1588 if (!streams[i]->link->link_state_valid)
1595 bool dc_validate_boot_timing(const struct dc *dc,
1596 const struct dc_sink *sink,
1597 struct dc_crtc_timing *crtc_timing)
1599 struct timing_generator *tg;
1600 struct stream_encoder *se = NULL;
1602 struct dc_crtc_timing hw_crtc_timing = {0};
1604 struct dc_link *link = sink->link;
1605 unsigned int i, enc_inst, tg_inst = 0;
1607 /* Support seamless boot on EDP displays only */
1608 if (sink->sink_signal != SIGNAL_TYPE_EDP) {
1612 if (dc->debug.force_odm_combine)
1615 /* Check for enabled DIG to identify enabled display */
1616 if (!link->link_enc->funcs->is_dig_enabled(link->link_enc))
1619 enc_inst = link->link_enc->funcs->get_dig_frontend(link->link_enc);
1621 if (enc_inst == ENGINE_ID_UNKNOWN)
1624 for (i = 0; i < dc->res_pool->stream_enc_count; i++) {
1625 if (dc->res_pool->stream_enc[i]->id == enc_inst) {
1627 se = dc->res_pool->stream_enc[i];
1629 tg_inst = dc->res_pool->stream_enc[i]->funcs->dig_source_otg(
1630 dc->res_pool->stream_enc[i]);
1635 // tg_inst not found
1636 if (i == dc->res_pool->stream_enc_count)
1639 if (tg_inst >= dc->res_pool->timing_generator_count)
1642 if (tg_inst != link->link_enc->preferred_engine)
1645 tg = dc->res_pool->timing_generators[tg_inst];
1647 if (!tg->funcs->get_hw_timing)
1650 if (!tg->funcs->get_hw_timing(tg, &hw_crtc_timing))
1653 if (crtc_timing->h_total != hw_crtc_timing.h_total)
1656 if (crtc_timing->h_border_left != hw_crtc_timing.h_border_left)
1659 if (crtc_timing->h_addressable != hw_crtc_timing.h_addressable)
1662 if (crtc_timing->h_border_right != hw_crtc_timing.h_border_right)
1665 if (crtc_timing->h_front_porch != hw_crtc_timing.h_front_porch)
1668 if (crtc_timing->h_sync_width != hw_crtc_timing.h_sync_width)
1671 if (crtc_timing->v_total != hw_crtc_timing.v_total)
1674 if (crtc_timing->v_border_top != hw_crtc_timing.v_border_top)
1677 if (crtc_timing->v_addressable != hw_crtc_timing.v_addressable)
1680 if (crtc_timing->v_border_bottom != hw_crtc_timing.v_border_bottom)
1683 if (crtc_timing->v_front_porch != hw_crtc_timing.v_front_porch)
1686 if (crtc_timing->v_sync_width != hw_crtc_timing.v_sync_width)
1689 /* block DSC for now, as VBIOS does not currently support DSC timings */
1690 if (crtc_timing->flags.DSC)
1693 if (dc_is_dp_signal(link->connector_signal)) {
1694 unsigned int pix_clk_100hz;
1695 uint32_t numOdmPipes = 1;
1696 uint32_t id_src[4] = {0};
1698 dc->res_pool->dp_clock_source->funcs->get_pixel_clk_frequency_100hz(
1699 dc->res_pool->dp_clock_source,
1700 tg_inst, &pix_clk_100hz);
1702 if (tg->funcs->get_optc_source)
1703 tg->funcs->get_optc_source(tg,
1704 &numOdmPipes, &id_src[0], &id_src[1]);
1706 if (numOdmPipes == 2)
1708 if (numOdmPipes == 4)
1711 // Note: In rare cases, HW pixclk may differ from crtc's pixclk
1712 // slightly due to rounding issues in 10 kHz units.
1713 if (crtc_timing->pix_clk_100hz != pix_clk_100hz)
1716 if (!se->funcs->dp_get_pixel_format)
1719 if (!se->funcs->dp_get_pixel_format(
1721 &hw_crtc_timing.pixel_encoding,
1722 &hw_crtc_timing.display_color_depth))
1725 if (hw_crtc_timing.display_color_depth != crtc_timing->display_color_depth)
1728 if (hw_crtc_timing.pixel_encoding != crtc_timing->pixel_encoding)
1732 if (link->dpcd_caps.dprx_feature.bits.VSC_SDP_COLORIMETRY_SUPPORTED) {
1736 if (dc->link_srv->edp_is_ilr_optimization_required(link, crtc_timing)) {
1737 DC_LOG_EVENT_LINK_TRAINING("Seamless boot disabled to optimize eDP link rate\n");
1744 static inline bool should_update_pipe_for_stream(
1745 struct dc_state *context,
1746 struct pipe_ctx *pipe_ctx,
1747 struct dc_stream_state *stream)
1749 return (pipe_ctx->stream && pipe_ctx->stream == stream);
1752 static inline bool should_update_pipe_for_plane(
1753 struct dc_state *context,
1754 struct pipe_ctx *pipe_ctx,
1755 struct dc_plane_state *plane_state)
1757 return (pipe_ctx->plane_state == plane_state);
1760 void dc_enable_stereo(
1762 struct dc_state *context,
1763 struct dc_stream_state *streams[],
1764 uint8_t stream_count)
1767 struct pipe_ctx *pipe;
1769 for (i = 0; i < MAX_PIPES; i++) {
1770 if (context != NULL) {
1771 pipe = &context->res_ctx.pipe_ctx[i];
1773 context = dc->current_state;
1774 pipe = &dc->current_state->res_ctx.pipe_ctx[i];
1777 for (j = 0; pipe && j < stream_count; j++) {
1778 if (should_update_pipe_for_stream(context, pipe, streams[j]) &&
1779 dc->hwss.setup_stereo)
1780 dc->hwss.setup_stereo(pipe, dc);
1785 void dc_trigger_sync(struct dc *dc, struct dc_state *context)
1787 if (context->stream_count > 1 && !dc->debug.disable_timing_sync) {
1788 enable_timing_multisync(dc, context);
1789 program_timing_sync(dc, context);
1793 static uint8_t get_stream_mask(struct dc *dc, struct dc_state *context)
1796 unsigned int stream_mask = 0;
1798 for (i = 0; i < dc->res_pool->pipe_count; i++) {
1799 if (context->res_ctx.pipe_ctx[i].stream)
1800 stream_mask |= 1 << i;
1806 void dc_z10_restore(const struct dc *dc)
1808 if (dc->hwss.z10_restore)
1809 dc->hwss.z10_restore(dc);
1812 void dc_z10_save_init(struct dc *dc)
1814 if (dc->hwss.z10_save_init)
1815 dc->hwss.z10_save_init(dc);
1819 * dc_commit_state_no_check - Apply context to the hardware
1821 * @dc: DC object with the current status to be updated
1822 * @context: New state that will become the current status at the end of this function
1824 * Applies given context to the hardware and copy it into current context.
1825 * It's up to the user to release the src context afterwards.
1827 * Return: an enum dc_status result code for the operation
1829 static enum dc_status dc_commit_state_no_check(struct dc *dc, struct dc_state *context)
1831 struct dc_bios *dcb = dc->ctx->dc_bios;
1832 enum dc_status result = DC_ERROR_UNEXPECTED;
1833 struct pipe_ctx *pipe;
1835 struct dc_stream_state *dc_streams[MAX_STREAMS] = {0};
1836 struct dc_state *old_state;
1837 bool subvp_prev_use = false;
1840 dc_allow_idle_optimizations(dc, false);
1842 for (i = 0; i < dc->res_pool->pipe_count; i++) {
1843 struct pipe_ctx *old_pipe = &dc->current_state->res_ctx.pipe_ctx[i];
1845 /* Check old context for SubVP */
1846 subvp_prev_use |= (dc_state_get_pipe_subvp_type(dc->current_state, old_pipe) == SUBVP_PHANTOM);
1851 for (i = 0; i < context->stream_count; i++)
1852 dc_streams[i] = context->streams[i];
1854 if (!dcb->funcs->is_accelerated_mode(dcb)) {
1855 disable_vbios_mode_if_required(dc, context);
1856 dc->hwss.enable_accelerated_mode(dc, context);
1859 if (context->stream_count > get_seamless_boot_stream_count(context) ||
1860 context->stream_count == 0)
1861 dc->hwss.prepare_bandwidth(dc, context);
1863 /* When SubVP is active, all HW programming must be done while
1864 * SubVP lock is acquired
1866 if (dc->hwss.subvp_pipe_control_lock)
1867 dc->hwss.subvp_pipe_control_lock(dc, context, true, true, NULL, subvp_prev_use);
1869 if (dc->hwss.update_dsc_pg)
1870 dc->hwss.update_dsc_pg(dc, context, false);
1872 disable_dangling_plane(dc, context);
1873 /* re-program planes for existing stream, in case we need to
1874 * free up plane resource for later use
1876 if (dc->hwss.apply_ctx_for_surface) {
1877 for (i = 0; i < context->stream_count; i++) {
1878 if (context->streams[i]->mode_changed)
1880 apply_ctx_interdependent_lock(dc, context, context->streams[i], true);
1881 dc->hwss.apply_ctx_for_surface(
1882 dc, context->streams[i],
1883 context->stream_status[i].plane_count,
1884 context); /* use new pipe config in new context */
1885 apply_ctx_interdependent_lock(dc, context, context->streams[i], false);
1886 dc->hwss.post_unlock_program_front_end(dc, context);
1890 /* Program hardware */
1891 for (i = 0; i < dc->res_pool->pipe_count; i++) {
1892 pipe = &context->res_ctx.pipe_ctx[i];
1893 dc->hwss.wait_for_mpcc_disconnect(dc, dc->res_pool, pipe);
1896 result = dc->hwss.apply_ctx_to_hw(dc, context);
1898 if (result != DC_OK) {
1899 /* Application of dc_state to hardware stopped. */
1900 dc->current_state->res_ctx.link_enc_cfg_ctx.mode = LINK_ENC_CFG_STEADY;
1904 dc_trigger_sync(dc, context);
1906 /* Full update should unconditionally be triggered when dc_commit_state_no_check is called */
1907 for (i = 0; i < context->stream_count; i++) {
1908 uint32_t prev_dsc_changed = context->streams[i]->update_flags.bits.dsc_changed;
1910 context->streams[i]->update_flags.raw = 0xFFFFFFFF;
1911 context->streams[i]->update_flags.bits.dsc_changed = prev_dsc_changed;
1914 /* Program all planes within new context*/
1915 if (dc->hwss.program_front_end_for_ctx) {
1916 dc->hwss.interdependent_update_lock(dc, context, true);
1917 dc->hwss.program_front_end_for_ctx(dc, context);
1918 dc->hwss.interdependent_update_lock(dc, context, false);
1919 dc->hwss.post_unlock_program_front_end(dc, context);
1922 if (dc->hwss.commit_subvp_config)
1923 dc->hwss.commit_subvp_config(dc, context);
1924 if (dc->hwss.subvp_pipe_control_lock)
1925 dc->hwss.subvp_pipe_control_lock(dc, context, false, true, NULL, subvp_prev_use);
1927 for (i = 0; i < context->stream_count; i++) {
1928 const struct dc_link *link = context->streams[i]->link;
1930 if (!context->streams[i]->mode_changed)
1933 if (dc->hwss.apply_ctx_for_surface) {
1934 apply_ctx_interdependent_lock(dc, context, context->streams[i], true);
1935 dc->hwss.apply_ctx_for_surface(
1936 dc, context->streams[i],
1937 context->stream_status[i].plane_count,
1939 apply_ctx_interdependent_lock(dc, context, context->streams[i], false);
1940 dc->hwss.post_unlock_program_front_end(dc, context);
1945 * TODO rework dc_enable_stereo call to work with validation sets?
1947 for (k = 0; k < MAX_PIPES; k++) {
1948 pipe = &context->res_ctx.pipe_ctx[k];
1950 for (l = 0 ; pipe && l < context->stream_count; l++) {
1951 if (context->streams[l] &&
1952 context->streams[l] == pipe->stream &&
1953 dc->hwss.setup_stereo)
1954 dc->hwss.setup_stereo(pipe, dc);
1958 CONN_MSG_MODE(link, "{%dx%d, %dx%d@%dKhz}",
1959 context->streams[i]->timing.h_addressable,
1960 context->streams[i]->timing.v_addressable,
1961 context->streams[i]->timing.h_total,
1962 context->streams[i]->timing.v_total,
1963 context->streams[i]->timing.pix_clk_100hz / 10);
1966 dc_enable_stereo(dc, context, dc_streams, context->stream_count);
1968 if (context->stream_count > get_seamless_boot_stream_count(context) ||
1969 context->stream_count == 0) {
1970 /* Must wait for no flips to be pending before doing optimize bw */
1971 wait_for_no_pipes_pending(dc, context);
1972 /* pplib is notified if disp_num changed */
1973 dc->hwss.optimize_bandwidth(dc, context);
1974 /* Need to do otg sync again as otg could be out of sync due to otg
1975 * workaround applied during clock update
1977 dc_trigger_sync(dc, context);
1980 if (dc->hwss.update_dsc_pg)
1981 dc->hwss.update_dsc_pg(dc, context, true);
1983 if (dc->ctx->dce_version >= DCE_VERSION_MAX)
1984 TRACE_DCN_CLOCK_STATE(&context->bw_ctx.bw.dcn.clk);
1986 TRACE_DCE_CLOCK_STATE(&context->bw_ctx.bw.dce);
1988 context->stream_mask = get_stream_mask(dc, context);
1990 if (context->stream_mask != dc->current_state->stream_mask)
1991 dc_dmub_srv_notify_stream_mask(dc->ctx->dmub_srv, context->stream_mask);
1993 for (i = 0; i < context->stream_count; i++)
1994 context->streams[i]->mode_changed = false;
1996 /* Clear update flags that were set earlier to avoid redundant programming */
1997 for (i = 0; i < context->stream_count; i++) {
1998 context->streams[i]->update_flags.raw = 0x0;
2001 old_state = dc->current_state;
2002 dc->current_state = context;
2004 dc_state_release(old_state);
2006 dc_state_retain(dc->current_state);
2011 static bool commit_minimal_transition_state(struct dc *dc,
2012 struct dc_state *transition_base_context);
2015 * dc_commit_streams - Commit current stream state
2017 * @dc: DC object with the commit state to be configured in the hardware
2018 * @streams: Array with a list of stream state
2019 * @stream_count: Total of streams
2021 * Function responsible for commit streams change to the hardware.
2024 * Return DC_OK if everything work as expected, otherwise, return a dc_status
2027 enum dc_status dc_commit_streams(struct dc *dc,
2028 struct dc_stream_state *streams[],
2029 uint8_t stream_count)
2032 struct dc_state *context;
2033 enum dc_status res = DC_OK;
2034 struct dc_validation_set set[MAX_STREAMS] = {0};
2035 struct pipe_ctx *pipe;
2036 bool handle_exit_odm2to1 = false;
2038 if (dc->ctx->dce_environment == DCE_ENV_VIRTUAL_HW)
2041 if (!streams_changed(dc, streams, stream_count))
2044 DC_LOG_DC("%s: %d streams\n", __func__, stream_count);
2046 for (i = 0; i < stream_count; i++) {
2047 struct dc_stream_state *stream = streams[i];
2048 struct dc_stream_status *status = dc_stream_get_status(stream);
2050 dc_stream_log(dc, stream);
2052 set[i].stream = stream;
2055 set[i].plane_count = status->plane_count;
2056 for (j = 0; j < status->plane_count; j++)
2057 set[i].plane_states[j] = status->plane_states[j];
2061 /* ODM Combine 2:1 power optimization is only applied for single stream
2062 * scenario, it uses extra pipes than needed to reduce power consumption
2063 * We need to switch off this feature to make room for new streams.
2065 if (stream_count > dc->current_state->stream_count &&
2066 dc->current_state->stream_count == 1) {
2067 for (i = 0; i < dc->res_pool->pipe_count; i++) {
2068 pipe = &dc->current_state->res_ctx.pipe_ctx[i];
2069 if (pipe->next_odm_pipe)
2070 handle_exit_odm2to1 = true;
2074 if (handle_exit_odm2to1)
2075 res = commit_minimal_transition_state(dc, dc->current_state);
2077 context = dc_state_create_current_copy(dc);
2079 goto context_alloc_fail;
2081 res = dc_validate_with_context(dc, set, stream_count, context, false);
2083 BREAK_TO_DEBUGGER();
2087 res = dc_commit_state_no_check(dc, context);
2089 for (i = 0; i < stream_count; i++) {
2090 for (j = 0; j < context->stream_count; j++) {
2091 if (streams[i]->stream_id == context->streams[j]->stream_id)
2092 streams[i]->out.otg_offset = context->stream_status[j].primary_otg_inst;
2094 if (dc_is_embedded_signal(streams[i]->signal)) {
2095 struct dc_stream_status *status = dc_state_get_stream_status(context, streams[i]);
2097 if (dc->hwss.is_abm_supported)
2098 status->is_abm_supported = dc->hwss.is_abm_supported(dc, context, streams[i]);
2100 status->is_abm_supported = true;
2106 dc_state_release(context);
2110 DC_LOG_DC("%s Finished.\n", __func__);
2115 bool dc_acquire_release_mpc_3dlut(
2116 struct dc *dc, bool acquire,
2117 struct dc_stream_state *stream,
2118 struct dc_3dlut **lut,
2119 struct dc_transfer_func **shaper)
2123 bool found_pipe_idx = false;
2124 const struct resource_pool *pool = dc->res_pool;
2125 struct resource_context *res_ctx = &dc->current_state->res_ctx;
2128 if (pool && res_ctx) {
2130 /*find pipe idx for the given stream*/
2131 for (pipe_idx = 0; pipe_idx < pool->pipe_count; pipe_idx++) {
2132 if (res_ctx->pipe_ctx[pipe_idx].stream == stream) {
2133 found_pipe_idx = true;
2134 mpcc_id = res_ctx->pipe_ctx[pipe_idx].plane_res.hubp->inst;
2139 found_pipe_idx = true;/*for release pipe_idx is not required*/
2141 if (found_pipe_idx) {
2142 if (acquire && pool->funcs->acquire_post_bldn_3dlut)
2143 ret = pool->funcs->acquire_post_bldn_3dlut(res_ctx, pool, mpcc_id, lut, shaper);
2144 else if (!acquire && pool->funcs->release_post_bldn_3dlut)
2145 ret = pool->funcs->release_post_bldn_3dlut(res_ctx, pool, lut, shaper);
2151 static bool is_flip_pending_in_pipes(struct dc *dc, struct dc_state *context)
2154 struct pipe_ctx *pipe;
2156 for (i = 0; i < MAX_PIPES; i++) {
2157 pipe = &context->res_ctx.pipe_ctx[i];
2159 // Don't check flip pending on phantom pipes
2160 if (!pipe->plane_state || (dc_state_get_pipe_subvp_type(context, pipe) == SUBVP_PHANTOM))
2163 /* Must set to false to start with, due to OR in update function */
2164 pipe->plane_state->status.is_flip_pending = false;
2165 dc->hwss.update_pending_status(pipe);
2166 if (pipe->plane_state->status.is_flip_pending)
2172 /* Perform updates here which need to be deferred until next vupdate
2174 * i.e. blnd lut, 3dlut, and shaper lut bypass regs are double buffered
2175 * but forcing lut memory to shutdown state is immediate. This causes
2176 * single frame corruption as lut gets disabled mid-frame unless shutdown
2177 * is deferred until after entering bypass.
2179 static void process_deferred_updates(struct dc *dc)
2183 if (dc->debug.enable_mem_low_power.bits.cm) {
2184 ASSERT(dc->dcn_ip->max_num_dpp);
2185 for (i = 0; i < dc->dcn_ip->max_num_dpp; i++)
2186 if (dc->res_pool->dpps[i]->funcs->dpp_deferred_update)
2187 dc->res_pool->dpps[i]->funcs->dpp_deferred_update(dc->res_pool->dpps[i]);
2191 void dc_post_update_surfaces_to_stream(struct dc *dc)
2194 struct dc_state *context = dc->current_state;
2196 if ((!dc->optimized_required) || get_seamless_boot_stream_count(context) > 0)
2199 post_surface_trace(dc);
2202 * Only relevant for DCN behavior where we can guarantee the optimization
2203 * is safe to apply - retain the legacy behavior for DCE.
2206 if (dc->ctx->dce_version < DCE_VERSION_MAX)
2207 TRACE_DCE_CLOCK_STATE(&context->bw_ctx.bw.dce);
2209 TRACE_DCN_CLOCK_STATE(&context->bw_ctx.bw.dcn.clk);
2211 if (is_flip_pending_in_pipes(dc, context))
2214 for (i = 0; i < dc->res_pool->pipe_count; i++)
2215 if (context->res_ctx.pipe_ctx[i].stream == NULL ||
2216 context->res_ctx.pipe_ctx[i].plane_state == NULL) {
2217 context->res_ctx.pipe_ctx[i].pipe_idx = i;
2218 dc->hwss.disable_plane(dc, context, &context->res_ctx.pipe_ctx[i]);
2221 process_deferred_updates(dc);
2223 dc->hwss.optimize_bandwidth(dc, context);
2225 if (dc->hwss.update_dsc_pg)
2226 dc->hwss.update_dsc_pg(dc, context, true);
2229 dc->optimized_required = false;
2230 dc->wm_optimized_required = false;
2233 bool dc_set_generic_gpio_for_stereo(bool enable,
2234 struct gpio_service *gpio_service)
2236 enum gpio_result gpio_result = GPIO_RESULT_NON_SPECIFIC_ERROR;
2237 struct gpio_pin_info pin_info;
2238 struct gpio *generic;
2239 struct gpio_generic_mux_config *config = kzalloc(sizeof(struct gpio_generic_mux_config),
2244 pin_info = dal_gpio_get_generic_pin_info(gpio_service, GPIO_ID_GENERIC, 0);
2246 if (pin_info.mask == 0xFFFFFFFF || pin_info.offset == 0xFFFFFFFF) {
2250 generic = dal_gpio_service_create_generic_mux(
2261 gpio_result = dal_gpio_open(generic, GPIO_MODE_OUTPUT);
2263 config->enable_output_from_mux = enable;
2264 config->mux_select = GPIO_SIGNAL_SOURCE_PASS_THROUGH_STEREO_SYNC;
2266 if (gpio_result == GPIO_RESULT_OK)
2267 gpio_result = dal_mux_setup_config(generic, config);
2269 if (gpio_result == GPIO_RESULT_OK) {
2270 dal_gpio_close(generic);
2271 dal_gpio_destroy_generic_mux(&generic);
2275 dal_gpio_close(generic);
2276 dal_gpio_destroy_generic_mux(&generic);
2282 static bool is_surface_in_context(
2283 const struct dc_state *context,
2284 const struct dc_plane_state *plane_state)
2288 for (j = 0; j < MAX_PIPES; j++) {
2289 const struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[j];
2291 if (plane_state == pipe_ctx->plane_state) {
2299 static enum surface_update_type get_plane_info_update_type(const struct dc_surface_update *u)
2301 union surface_update_flags *update_flags = &u->surface->update_flags;
2302 enum surface_update_type update_type = UPDATE_TYPE_FAST;
2305 return UPDATE_TYPE_FAST;
2307 if (u->plane_info->color_space != u->surface->color_space) {
2308 update_flags->bits.color_space_change = 1;
2309 elevate_update_type(&update_type, UPDATE_TYPE_MED);
2312 if (u->plane_info->horizontal_mirror != u->surface->horizontal_mirror) {
2313 update_flags->bits.horizontal_mirror_change = 1;
2314 elevate_update_type(&update_type, UPDATE_TYPE_MED);
2317 if (u->plane_info->rotation != u->surface->rotation) {
2318 update_flags->bits.rotation_change = 1;
2319 elevate_update_type(&update_type, UPDATE_TYPE_FULL);
2322 if (u->plane_info->format != u->surface->format) {
2323 update_flags->bits.pixel_format_change = 1;
2324 elevate_update_type(&update_type, UPDATE_TYPE_FULL);
2327 if (u->plane_info->stereo_format != u->surface->stereo_format) {
2328 update_flags->bits.stereo_format_change = 1;
2329 elevate_update_type(&update_type, UPDATE_TYPE_FULL);
2332 if (u->plane_info->per_pixel_alpha != u->surface->per_pixel_alpha) {
2333 update_flags->bits.per_pixel_alpha_change = 1;
2334 elevate_update_type(&update_type, UPDATE_TYPE_MED);
2337 if (u->plane_info->global_alpha_value != u->surface->global_alpha_value) {
2338 update_flags->bits.global_alpha_change = 1;
2339 elevate_update_type(&update_type, UPDATE_TYPE_MED);
2342 if (u->plane_info->dcc.enable != u->surface->dcc.enable
2343 || u->plane_info->dcc.dcc_ind_blk != u->surface->dcc.dcc_ind_blk
2344 || u->plane_info->dcc.meta_pitch != u->surface->dcc.meta_pitch) {
2345 /* During DCC on/off, stutter period is calculated before
2346 * DCC has fully transitioned. This results in incorrect
2347 * stutter period calculation. Triggering a full update will
2348 * recalculate stutter period.
2350 update_flags->bits.dcc_change = 1;
2351 elevate_update_type(&update_type, UPDATE_TYPE_FULL);
2354 if (resource_pixel_format_to_bpp(u->plane_info->format) !=
2355 resource_pixel_format_to_bpp(u->surface->format)) {
2356 /* different bytes per element will require full bandwidth
2357 * and DML calculation
2359 update_flags->bits.bpp_change = 1;
2360 elevate_update_type(&update_type, UPDATE_TYPE_FULL);
2363 if (u->plane_info->plane_size.surface_pitch != u->surface->plane_size.surface_pitch
2364 || u->plane_info->plane_size.chroma_pitch != u->surface->plane_size.chroma_pitch) {
2365 update_flags->bits.plane_size_change = 1;
2366 elevate_update_type(&update_type, UPDATE_TYPE_MED);
2370 if (memcmp(&u->plane_info->tiling_info, &u->surface->tiling_info,
2371 sizeof(union dc_tiling_info)) != 0) {
2372 update_flags->bits.swizzle_change = 1;
2373 elevate_update_type(&update_type, UPDATE_TYPE_MED);
2375 /* todo: below are HW dependent, we should add a hook to
2376 * DCE/N resource and validated there.
2378 if (u->plane_info->tiling_info.gfx9.swizzle != DC_SW_LINEAR) {
2379 /* swizzled mode requires RQ to be setup properly,
2380 * thus need to run DML to calculate RQ settings
2382 update_flags->bits.bandwidth_change = 1;
2383 elevate_update_type(&update_type, UPDATE_TYPE_FULL);
2387 /* This should be UPDATE_TYPE_FAST if nothing has changed. */
2391 static enum surface_update_type get_scaling_info_update_type(
2392 const struct dc *dc,
2393 const struct dc_surface_update *u)
2395 union surface_update_flags *update_flags = &u->surface->update_flags;
2397 if (!u->scaling_info)
2398 return UPDATE_TYPE_FAST;
2400 if (u->scaling_info->dst_rect.width != u->surface->dst_rect.width
2401 || u->scaling_info->dst_rect.height != u->surface->dst_rect.height
2402 || u->scaling_info->scaling_quality.integer_scaling !=
2403 u->surface->scaling_quality.integer_scaling
2405 update_flags->bits.scaling_change = 1;
2407 if ((u->scaling_info->dst_rect.width < u->surface->dst_rect.width
2408 || u->scaling_info->dst_rect.height < u->surface->dst_rect.height)
2409 && (u->scaling_info->dst_rect.width < u->surface->src_rect.width
2410 || u->scaling_info->dst_rect.height < u->surface->src_rect.height))
2411 /* Making dst rect smaller requires a bandwidth change */
2412 update_flags->bits.bandwidth_change = 1;
2415 if (u->scaling_info->src_rect.width != u->surface->src_rect.width
2416 || u->scaling_info->src_rect.height != u->surface->src_rect.height) {
2418 update_flags->bits.scaling_change = 1;
2419 if (u->scaling_info->src_rect.width > u->surface->src_rect.width
2420 || u->scaling_info->src_rect.height > u->surface->src_rect.height)
2421 /* Making src rect bigger requires a bandwidth change */
2422 update_flags->bits.clock_change = 1;
2425 if (u->scaling_info->src_rect.width > dc->caps.max_optimizable_video_width &&
2426 (u->scaling_info->clip_rect.width > u->surface->clip_rect.width ||
2427 u->scaling_info->clip_rect.height > u->surface->clip_rect.height))
2428 /* Changing clip size of a large surface may result in MPC slice count change */
2429 update_flags->bits.bandwidth_change = 1;
2431 if (u->scaling_info->src_rect.x != u->surface->src_rect.x
2432 || u->scaling_info->src_rect.y != u->surface->src_rect.y
2433 || u->scaling_info->clip_rect.x != u->surface->clip_rect.x
2434 || u->scaling_info->clip_rect.y != u->surface->clip_rect.y
2435 || u->scaling_info->dst_rect.x != u->surface->dst_rect.x
2436 || u->scaling_info->dst_rect.y != u->surface->dst_rect.y)
2437 update_flags->bits.position_change = 1;
2439 if (update_flags->bits.clock_change
2440 || update_flags->bits.bandwidth_change
2441 || update_flags->bits.scaling_change)
2442 return UPDATE_TYPE_FULL;
2444 if (update_flags->bits.position_change)
2445 return UPDATE_TYPE_MED;
2447 return UPDATE_TYPE_FAST;
2450 static enum surface_update_type det_surface_update(const struct dc *dc,
2451 const struct dc_surface_update *u)
2453 const struct dc_state *context = dc->current_state;
2454 enum surface_update_type type;
2455 enum surface_update_type overall_type = UPDATE_TYPE_FAST;
2456 union surface_update_flags *update_flags = &u->surface->update_flags;
2458 if (!is_surface_in_context(context, u->surface) || u->surface->force_full_update) {
2459 update_flags->raw = 0xFFFFFFFF;
2460 return UPDATE_TYPE_FULL;
2463 update_flags->raw = 0; // Reset all flags
2465 type = get_plane_info_update_type(u);
2466 elevate_update_type(&overall_type, type);
2468 type = get_scaling_info_update_type(dc, u);
2469 elevate_update_type(&overall_type, type);
2472 update_flags->bits.addr_update = 1;
2473 if (u->flip_addr->address.tmz_surface != u->surface->address.tmz_surface) {
2474 update_flags->bits.tmz_changed = 1;
2475 elevate_update_type(&overall_type, UPDATE_TYPE_FULL);
2478 if (u->in_transfer_func)
2479 update_flags->bits.in_transfer_func_change = 1;
2481 if (u->input_csc_color_matrix)
2482 update_flags->bits.input_csc_change = 1;
2484 if (u->coeff_reduction_factor)
2485 update_flags->bits.coeff_reduction_change = 1;
2487 if (u->gamut_remap_matrix)
2488 update_flags->bits.gamut_remap_change = 1;
2491 update_flags->bits.gamma_change = 1;
2494 enum surface_pixel_format format = SURFACE_PIXEL_FORMAT_GRPH_BEGIN;
2497 format = u->plane_info->format;
2498 else if (u->surface)
2499 format = u->surface->format;
2501 if (dce_use_lut(format))
2502 update_flags->bits.gamma_change = 1;
2505 if (u->lut3d_func || u->func_shaper)
2506 update_flags->bits.lut_3d = 1;
2508 if (u->hdr_mult.value)
2509 if (u->hdr_mult.value != u->surface->hdr_mult.value) {
2510 update_flags->bits.hdr_mult = 1;
2511 elevate_update_type(&overall_type, UPDATE_TYPE_MED);
2514 if (update_flags->bits.in_transfer_func_change) {
2515 type = UPDATE_TYPE_MED;
2516 elevate_update_type(&overall_type, type);
2519 if (update_flags->bits.lut_3d) {
2520 type = UPDATE_TYPE_FULL;
2521 elevate_update_type(&overall_type, type);
2524 if (dc->debug.enable_legacy_fast_update &&
2525 (update_flags->bits.gamma_change ||
2526 update_flags->bits.gamut_remap_change ||
2527 update_flags->bits.input_csc_change ||
2528 update_flags->bits.coeff_reduction_change)) {
2529 type = UPDATE_TYPE_FULL;
2530 elevate_update_type(&overall_type, type);
2532 return overall_type;
2535 static enum surface_update_type check_update_surfaces_for_stream(
2537 struct dc_surface_update *updates,
2539 struct dc_stream_update *stream_update,
2540 const struct dc_stream_status *stream_status)
2543 enum surface_update_type overall_type = UPDATE_TYPE_FAST;
2545 if (dc->idle_optimizations_allowed)
2546 overall_type = UPDATE_TYPE_FULL;
2548 if (stream_status == NULL || stream_status->plane_count != surface_count)
2549 overall_type = UPDATE_TYPE_FULL;
2551 if (stream_update && stream_update->pending_test_pattern) {
2552 overall_type = UPDATE_TYPE_FULL;
2555 /* some stream updates require passive update */
2556 if (stream_update) {
2557 union stream_update_flags *su_flags = &stream_update->stream->update_flags;
2559 if ((stream_update->src.height != 0 && stream_update->src.width != 0) ||
2560 (stream_update->dst.height != 0 && stream_update->dst.width != 0) ||
2561 stream_update->integer_scaling_update)
2562 su_flags->bits.scaling = 1;
2564 if (dc->debug.enable_legacy_fast_update && stream_update->out_transfer_func)
2565 su_flags->bits.out_tf = 1;
2567 if (stream_update->abm_level)
2568 su_flags->bits.abm_level = 1;
2570 if (stream_update->dpms_off)
2571 su_flags->bits.dpms_off = 1;
2573 if (stream_update->gamut_remap)
2574 su_flags->bits.gamut_remap = 1;
2576 if (stream_update->wb_update)
2577 su_flags->bits.wb_update = 1;
2579 if (stream_update->dsc_config)
2580 su_flags->bits.dsc_changed = 1;
2582 if (stream_update->mst_bw_update)
2583 su_flags->bits.mst_bw = 1;
2585 if (stream_update->stream && stream_update->stream->freesync_on_desktop &&
2586 (stream_update->vrr_infopacket || stream_update->allow_freesync ||
2587 stream_update->vrr_active_variable || stream_update->vrr_active_fixed))
2588 su_flags->bits.fams_changed = 1;
2590 if (su_flags->raw != 0)
2591 overall_type = UPDATE_TYPE_FULL;
2593 if (stream_update->output_csc_transform || stream_update->output_color_space)
2594 su_flags->bits.out_csc = 1;
2596 /* Output transfer function changes do not require bandwidth recalculation,
2597 * so don't trigger a full update
2599 if (!dc->debug.enable_legacy_fast_update && stream_update->out_transfer_func)
2600 su_flags->bits.out_tf = 1;
2603 for (i = 0 ; i < surface_count; i++) {
2604 enum surface_update_type type =
2605 det_surface_update(dc, &updates[i]);
2607 elevate_update_type(&overall_type, type);
2610 return overall_type;
2614 * dc_check_update_surfaces_for_stream() - Determine update type (fast, med, or full)
2616 * See :c:type:`enum surface_update_type <surface_update_type>` for explanation of update types
2618 enum surface_update_type dc_check_update_surfaces_for_stream(
2620 struct dc_surface_update *updates,
2622 struct dc_stream_update *stream_update,
2623 const struct dc_stream_status *stream_status)
2626 enum surface_update_type type;
2629 stream_update->stream->update_flags.raw = 0;
2630 for (i = 0; i < surface_count; i++)
2631 updates[i].surface->update_flags.raw = 0;
2633 type = check_update_surfaces_for_stream(dc, updates, surface_count, stream_update, stream_status);
2634 if (type == UPDATE_TYPE_FULL) {
2635 if (stream_update) {
2636 uint32_t dsc_changed = stream_update->stream->update_flags.bits.dsc_changed;
2637 stream_update->stream->update_flags.raw = 0xFFFFFFFF;
2638 stream_update->stream->update_flags.bits.dsc_changed = dsc_changed;
2640 for (i = 0; i < surface_count; i++)
2641 updates[i].surface->update_flags.raw = 0xFFFFFFFF;
2644 if (type == UPDATE_TYPE_FAST) {
2645 // If there's an available clock comparator, we use that.
2646 if (dc->clk_mgr->funcs->are_clock_states_equal) {
2647 if (!dc->clk_mgr->funcs->are_clock_states_equal(&dc->clk_mgr->clks, &dc->current_state->bw_ctx.bw.dcn.clk))
2648 dc->optimized_required = true;
2649 // Else we fallback to mem compare.
2650 } else if (memcmp(&dc->current_state->bw_ctx.bw.dcn.clk, &dc->clk_mgr->clks, offsetof(struct dc_clocks, prev_p_state_change_support)) != 0) {
2651 dc->optimized_required = true;
2654 dc->optimized_required |= dc->wm_optimized_required;
2660 static struct dc_stream_status *stream_get_status(
2661 struct dc_state *ctx,
2662 struct dc_stream_state *stream)
2666 for (i = 0; i < ctx->stream_count; i++) {
2667 if (stream == ctx->streams[i]) {
2668 return &ctx->stream_status[i];
2675 static const enum surface_update_type update_surface_trace_level = UPDATE_TYPE_FULL;
2677 static void copy_surface_update_to_plane(
2678 struct dc_plane_state *surface,
2679 struct dc_surface_update *srf_update)
2681 if (srf_update->flip_addr) {
2682 surface->address = srf_update->flip_addr->address;
2683 surface->flip_immediate =
2684 srf_update->flip_addr->flip_immediate;
2685 surface->time.time_elapsed_in_us[surface->time.index] =
2686 srf_update->flip_addr->flip_timestamp_in_us -
2687 surface->time.prev_update_time_in_us;
2688 surface->time.prev_update_time_in_us =
2689 srf_update->flip_addr->flip_timestamp_in_us;
2690 surface->time.index++;
2691 if (surface->time.index >= DC_PLANE_UPDATE_TIMES_MAX)
2692 surface->time.index = 0;
2694 surface->triplebuffer_flips = srf_update->flip_addr->triplebuffer_flips;
2697 if (srf_update->scaling_info) {
2698 surface->scaling_quality =
2699 srf_update->scaling_info->scaling_quality;
2701 srf_update->scaling_info->dst_rect;
2703 srf_update->scaling_info->src_rect;
2704 surface->clip_rect =
2705 srf_update->scaling_info->clip_rect;
2708 if (srf_update->plane_info) {
2709 surface->color_space =
2710 srf_update->plane_info->color_space;
2712 srf_update->plane_info->format;
2713 surface->plane_size =
2714 srf_update->plane_info->plane_size;
2716 srf_update->plane_info->rotation;
2717 surface->horizontal_mirror =
2718 srf_update->plane_info->horizontal_mirror;
2719 surface->stereo_format =
2720 srf_update->plane_info->stereo_format;
2721 surface->tiling_info =
2722 srf_update->plane_info->tiling_info;
2724 srf_update->plane_info->visible;
2725 surface->per_pixel_alpha =
2726 srf_update->plane_info->per_pixel_alpha;
2727 surface->global_alpha =
2728 srf_update->plane_info->global_alpha;
2729 surface->global_alpha_value =
2730 srf_update->plane_info->global_alpha_value;
2732 srf_update->plane_info->dcc;
2733 surface->layer_index =
2734 srf_update->plane_info->layer_index;
2737 if (srf_update->gamma &&
2738 (surface->gamma_correction !=
2739 srf_update->gamma)) {
2740 memcpy(&surface->gamma_correction->entries,
2741 &srf_update->gamma->entries,
2742 sizeof(struct dc_gamma_entries));
2743 surface->gamma_correction->is_identity =
2744 srf_update->gamma->is_identity;
2745 surface->gamma_correction->num_entries =
2746 srf_update->gamma->num_entries;
2747 surface->gamma_correction->type =
2748 srf_update->gamma->type;
2751 if (srf_update->in_transfer_func &&
2752 (surface->in_transfer_func !=
2753 srf_update->in_transfer_func)) {
2754 surface->in_transfer_func->sdr_ref_white_level =
2755 srf_update->in_transfer_func->sdr_ref_white_level;
2756 surface->in_transfer_func->tf =
2757 srf_update->in_transfer_func->tf;
2758 surface->in_transfer_func->type =
2759 srf_update->in_transfer_func->type;
2760 memcpy(&surface->in_transfer_func->tf_pts,
2761 &srf_update->in_transfer_func->tf_pts,
2762 sizeof(struct dc_transfer_func_distributed_points));
2765 if (srf_update->func_shaper &&
2766 (surface->in_shaper_func !=
2767 srf_update->func_shaper))
2768 memcpy(surface->in_shaper_func, srf_update->func_shaper,
2769 sizeof(*surface->in_shaper_func));
2771 if (srf_update->lut3d_func &&
2772 (surface->lut3d_func !=
2773 srf_update->lut3d_func))
2774 memcpy(surface->lut3d_func, srf_update->lut3d_func,
2775 sizeof(*surface->lut3d_func));
2777 if (srf_update->hdr_mult.value)
2779 srf_update->hdr_mult;
2781 if (srf_update->blend_tf &&
2782 (surface->blend_tf !=
2783 srf_update->blend_tf))
2784 memcpy(surface->blend_tf, srf_update->blend_tf,
2785 sizeof(*surface->blend_tf));
2787 if (srf_update->input_csc_color_matrix)
2788 surface->input_csc_color_matrix =
2789 *srf_update->input_csc_color_matrix;
2791 if (srf_update->coeff_reduction_factor)
2792 surface->coeff_reduction_factor =
2793 *srf_update->coeff_reduction_factor;
2795 if (srf_update->gamut_remap_matrix)
2796 surface->gamut_remap_matrix =
2797 *srf_update->gamut_remap_matrix;
2800 static void copy_stream_update_to_stream(struct dc *dc,
2801 struct dc_state *context,
2802 struct dc_stream_state *stream,
2803 struct dc_stream_update *update)
2805 struct dc_context *dc_ctx = dc->ctx;
2807 if (update == NULL || stream == NULL)
2810 if (update->src.height && update->src.width)
2811 stream->src = update->src;
2813 if (update->dst.height && update->dst.width)
2814 stream->dst = update->dst;
2816 if (update->out_transfer_func &&
2817 stream->out_transfer_func != update->out_transfer_func) {
2818 stream->out_transfer_func->sdr_ref_white_level =
2819 update->out_transfer_func->sdr_ref_white_level;
2820 stream->out_transfer_func->tf = update->out_transfer_func->tf;
2821 stream->out_transfer_func->type =
2822 update->out_transfer_func->type;
2823 memcpy(&stream->out_transfer_func->tf_pts,
2824 &update->out_transfer_func->tf_pts,
2825 sizeof(struct dc_transfer_func_distributed_points));
2828 if (update->hdr_static_metadata)
2829 stream->hdr_static_metadata = *update->hdr_static_metadata;
2831 if (update->abm_level)
2832 stream->abm_level = *update->abm_level;
2834 if (update->periodic_interrupt)
2835 stream->periodic_interrupt = *update->periodic_interrupt;
2837 if (update->gamut_remap)
2838 stream->gamut_remap_matrix = *update->gamut_remap;
2840 /* Note: this being updated after mode set is currently not a use case
2841 * however if it arises OCSC would need to be reprogrammed at the
2844 if (update->output_color_space)
2845 stream->output_color_space = *update->output_color_space;
2847 if (update->output_csc_transform)
2848 stream->csc_color_matrix = *update->output_csc_transform;
2850 if (update->vrr_infopacket)
2851 stream->vrr_infopacket = *update->vrr_infopacket;
2853 if (update->allow_freesync)
2854 stream->allow_freesync = *update->allow_freesync;
2856 if (update->vrr_active_variable)
2857 stream->vrr_active_variable = *update->vrr_active_variable;
2859 if (update->vrr_active_fixed)
2860 stream->vrr_active_fixed = *update->vrr_active_fixed;
2862 if (update->crtc_timing_adjust)
2863 stream->adjust = *update->crtc_timing_adjust;
2865 if (update->dpms_off)
2866 stream->dpms_off = *update->dpms_off;
2868 if (update->hfvsif_infopacket)
2869 stream->hfvsif_infopacket = *update->hfvsif_infopacket;
2871 if (update->vtem_infopacket)
2872 stream->vtem_infopacket = *update->vtem_infopacket;
2874 if (update->vsc_infopacket)
2875 stream->vsc_infopacket = *update->vsc_infopacket;
2877 if (update->vsp_infopacket)
2878 stream->vsp_infopacket = *update->vsp_infopacket;
2880 if (update->adaptive_sync_infopacket)
2881 stream->adaptive_sync_infopacket = *update->adaptive_sync_infopacket;
2883 if (update->dither_option)
2884 stream->dither_option = *update->dither_option;
2886 if (update->pending_test_pattern)
2887 stream->test_pattern = *update->pending_test_pattern;
2888 /* update current stream with writeback info */
2889 if (update->wb_update) {
2892 stream->num_wb_info = update->wb_update->num_wb_info;
2893 ASSERT(stream->num_wb_info <= MAX_DWB_PIPES);
2894 for (i = 0; i < stream->num_wb_info; i++)
2895 stream->writeback_info[i] =
2896 update->wb_update->writeback_info[i];
2898 if (update->dsc_config) {
2899 struct dc_dsc_config old_dsc_cfg = stream->timing.dsc_cfg;
2900 uint32_t old_dsc_enabled = stream->timing.flags.DSC;
2901 uint32_t enable_dsc = (update->dsc_config->num_slices_h != 0 &&
2902 update->dsc_config->num_slices_v != 0);
2904 /* Use temporarry context for validating new DSC config */
2905 struct dc_state *dsc_validate_context = dc_state_create_copy(dc->current_state);
2907 if (dsc_validate_context) {
2908 stream->timing.dsc_cfg = *update->dsc_config;
2909 stream->timing.flags.DSC = enable_dsc;
2910 if (!dc->res_pool->funcs->validate_bandwidth(dc, dsc_validate_context, true)) {
2911 stream->timing.dsc_cfg = old_dsc_cfg;
2912 stream->timing.flags.DSC = old_dsc_enabled;
2913 update->dsc_config = NULL;
2916 dc_state_release(dsc_validate_context);
2918 DC_ERROR("Failed to allocate new validate context for DSC change\n");
2919 update->dsc_config = NULL;
2924 static void backup_plane_states_for_stream(
2925 struct dc_plane_state plane_states[MAX_SURFACE_NUM],
2926 struct dc_stream_state *stream)
2929 struct dc_stream_status *status = dc_stream_get_status(stream);
2934 for (i = 0; i < status->plane_count; i++)
2935 plane_states[i] = *status->plane_states[i];
2938 static void restore_plane_states_for_stream(
2939 struct dc_plane_state plane_states[MAX_SURFACE_NUM],
2940 struct dc_stream_state *stream)
2943 struct dc_stream_status *status = dc_stream_get_status(stream);
2948 for (i = 0; i < status->plane_count; i++)
2949 *status->plane_states[i] = plane_states[i];
2952 static bool update_planes_and_stream_state(struct dc *dc,
2953 struct dc_surface_update *srf_updates, int surface_count,
2954 struct dc_stream_state *stream,
2955 struct dc_stream_update *stream_update,
2956 enum surface_update_type *new_update_type,
2957 struct dc_state **new_context)
2959 struct dc_state *context;
2961 enum surface_update_type update_type;
2962 const struct dc_stream_status *stream_status;
2963 struct dc_context *dc_ctx = dc->ctx;
2965 stream_status = dc_stream_get_status(stream);
2967 if (!stream_status) {
2968 if (surface_count) /* Only an error condition if surf_count non-zero*/
2971 return false; /* Cannot commit surface to stream that is not committed */
2974 context = dc->current_state;
2975 backup_plane_states_for_stream(dc->current_state->scratch.plane_states, stream);
2976 update_type = dc_check_update_surfaces_for_stream(
2977 dc, srf_updates, surface_count, stream_update, stream_status);
2979 /* update current stream with the new updates */
2980 copy_stream_update_to_stream(dc, context, stream, stream_update);
2982 /* do not perform surface update if surface has invalid dimensions
2983 * (all zero) and no scaling_info is provided
2985 if (surface_count > 0) {
2986 for (i = 0; i < surface_count; i++) {
2987 if ((srf_updates[i].surface->src_rect.width == 0 ||
2988 srf_updates[i].surface->src_rect.height == 0 ||
2989 srf_updates[i].surface->dst_rect.width == 0 ||
2990 srf_updates[i].surface->dst_rect.height == 0) &&
2991 (!srf_updates[i].scaling_info ||
2992 srf_updates[i].scaling_info->src_rect.width == 0 ||
2993 srf_updates[i].scaling_info->src_rect.height == 0 ||
2994 srf_updates[i].scaling_info->dst_rect.width == 0 ||
2995 srf_updates[i].scaling_info->dst_rect.height == 0)) {
2996 DC_ERROR("Invalid src/dst rects in surface update!\n");
3002 if (update_type >= update_surface_trace_level)
3003 update_surface_trace(dc, srf_updates, surface_count);
3005 for (i = 0; i < surface_count; i++)
3006 copy_surface_update_to_plane(srf_updates[i].surface, &srf_updates[i]);
3008 if (update_type >= UPDATE_TYPE_FULL) {
3009 struct dc_plane_state *new_planes[MAX_SURFACES] = {0};
3011 for (i = 0; i < surface_count; i++)
3012 new_planes[i] = srf_updates[i].surface;
3014 /* initialize scratch memory for building context */
3015 context = dc_state_create_copy(dc->current_state);
3016 if (context == NULL) {
3017 DC_ERROR("Failed to allocate new validate context!\n");
3021 /* For each full update, remove all existing phantom pipes first.
3022 * Ensures that we have enough pipes for newly added MPO planes
3024 dc_state_remove_phantom_streams_and_planes(dc, context);
3025 dc_state_release_phantom_streams_and_planes(dc, context);
3027 /*remove old surfaces from context */
3028 if (!dc_state_rem_all_planes_for_stream(dc, stream, context)) {
3030 BREAK_TO_DEBUGGER();
3034 /* add surface to context */
3035 if (!dc_state_add_all_planes_for_stream(dc, stream, new_planes, surface_count, context)) {
3037 BREAK_TO_DEBUGGER();
3042 /* save update parameters into surface */
3043 for (i = 0; i < surface_count; i++) {
3044 struct dc_plane_state *surface = srf_updates[i].surface;
3046 if (update_type >= UPDATE_TYPE_MED) {
3047 for (j = 0; j < dc->res_pool->pipe_count; j++) {
3048 struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[j];
3050 if (pipe_ctx->plane_state != surface)
3053 resource_build_scaling_params(pipe_ctx);
3058 if (update_type == UPDATE_TYPE_FULL) {
3059 if (!dc->res_pool->funcs->validate_bandwidth(dc, context, false)) {
3060 BREAK_TO_DEBUGGER();
3064 for (i = 0; i < context->stream_count; i++) {
3065 struct pipe_ctx *otg_master = resource_get_otg_master_for_stream(&context->res_ctx,
3066 context->streams[i]);
3068 if (otg_master && otg_master->stream->test_pattern.type != DP_TEST_PATTERN_VIDEO_MODE)
3069 resource_build_test_pattern_params(&context->res_ctx, otg_master);
3073 *new_context = context;
3074 *new_update_type = update_type;
3075 backup_plane_states_for_stream(context->scratch.plane_states, stream);
3080 dc_state_release(context);
3086 static void commit_planes_do_stream_update(struct dc *dc,
3087 struct dc_stream_state *stream,
3088 struct dc_stream_update *stream_update,
3089 enum surface_update_type update_type,
3090 struct dc_state *context)
3095 for (j = 0; j < dc->res_pool->pipe_count; j++) {
3096 struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[j];
3098 if (resource_is_pipe_type(pipe_ctx, OTG_MASTER) && pipe_ctx->stream == stream) {
3100 if (stream_update->periodic_interrupt && dc->hwss.setup_periodic_interrupt)
3101 dc->hwss.setup_periodic_interrupt(dc, pipe_ctx);
3103 if ((stream_update->hdr_static_metadata && !stream->use_dynamic_meta) ||
3104 stream_update->vrr_infopacket ||
3105 stream_update->vsc_infopacket ||
3106 stream_update->vsp_infopacket ||
3107 stream_update->hfvsif_infopacket ||
3108 stream_update->adaptive_sync_infopacket ||
3109 stream_update->vtem_infopacket) {
3110 resource_build_info_frame(pipe_ctx);
3111 dc->hwss.update_info_frame(pipe_ctx);
3113 if (dc_is_dp_signal(pipe_ctx->stream->signal))
3114 dc->link_srv->dp_trace_source_sequence(
3115 pipe_ctx->stream->link,
3116 DPCD_SOURCE_SEQ_AFTER_UPDATE_INFO_FRAME);
3119 if (stream_update->hdr_static_metadata &&
3120 stream->use_dynamic_meta &&
3121 dc->hwss.set_dmdata_attributes &&
3122 pipe_ctx->stream->dmdata_address.quad_part != 0)
3123 dc->hwss.set_dmdata_attributes(pipe_ctx);
3125 if (stream_update->gamut_remap)
3126 dc_stream_set_gamut_remap(dc, stream);
3128 if (stream_update->output_csc_transform)
3129 dc_stream_program_csc_matrix(dc, stream);
3131 if (stream_update->dither_option) {
3132 struct pipe_ctx *odm_pipe = pipe_ctx->next_odm_pipe;
3133 resource_build_bit_depth_reduction_params(pipe_ctx->stream,
3134 &pipe_ctx->stream->bit_depth_params);
3135 pipe_ctx->stream_res.opp->funcs->opp_program_fmt(pipe_ctx->stream_res.opp,
3136 &stream->bit_depth_params,
3139 odm_pipe->stream_res.opp->funcs->opp_program_fmt(odm_pipe->stream_res.opp,
3140 &stream->bit_depth_params,
3142 odm_pipe = odm_pipe->next_odm_pipe;
3148 if (update_type == UPDATE_TYPE_FAST)
3151 if (stream_update->dsc_config)
3152 dc->link_srv->update_dsc_config(pipe_ctx);
3154 if (stream_update->mst_bw_update) {
3155 if (stream_update->mst_bw_update->is_increase)
3156 dc->link_srv->increase_mst_payload(pipe_ctx,
3157 stream_update->mst_bw_update->mst_stream_bw);
3159 dc->link_srv->reduce_mst_payload(pipe_ctx,
3160 stream_update->mst_bw_update->mst_stream_bw);
3163 if (stream_update->pending_test_pattern) {
3164 dc_link_dp_set_test_pattern(stream->link,
3165 stream->test_pattern.type,
3166 stream->test_pattern.color_space,
3167 stream->test_pattern.p_link_settings,
3168 stream->test_pattern.p_custom_pattern,
3169 stream->test_pattern.cust_pattern_size);
3172 if (stream_update->dpms_off) {
3173 if (*stream_update->dpms_off) {
3174 dc->link_srv->set_dpms_off(pipe_ctx);
3175 /* for dpms, keep acquired resources*/
3176 if (pipe_ctx->stream_res.audio && !dc->debug.az_endpoint_mute_only)
3177 pipe_ctx->stream_res.audio->funcs->az_disable(pipe_ctx->stream_res.audio);
3179 dc->optimized_required = true;
3182 if (get_seamless_boot_stream_count(context) == 0)
3183 dc->hwss.prepare_bandwidth(dc, dc->current_state);
3184 dc->link_srv->set_dpms_on(dc->current_state, pipe_ctx);
3186 } else if (pipe_ctx->stream->link->wa_flags.blank_stream_on_ocs_change && stream_update->output_color_space
3187 && !stream->dpms_off && dc_is_dp_signal(pipe_ctx->stream->signal)) {
3189 * Workaround for firmware issue in some receivers where they don't pick up
3190 * correct output color space unless DP link is disabled/re-enabled
3192 dc->link_srv->set_dpms_on(dc->current_state, pipe_ctx);
3195 if (stream_update->abm_level && pipe_ctx->stream_res.abm) {
3196 bool should_program_abm = true;
3198 // if otg funcs defined check if blanked before programming
3199 if (pipe_ctx->stream_res.tg->funcs->is_blanked)
3200 if (pipe_ctx->stream_res.tg->funcs->is_blanked(pipe_ctx->stream_res.tg))
3201 should_program_abm = false;
3203 if (should_program_abm) {
3204 if (*stream_update->abm_level == ABM_LEVEL_IMMEDIATE_DISABLE) {
3205 dc->hwss.set_abm_immediate_disable(pipe_ctx);
3207 pipe_ctx->stream_res.abm->funcs->set_abm_level(
3208 pipe_ctx->stream_res.abm, stream->abm_level);
3216 static bool dc_dmub_should_send_dirty_rect_cmd(struct dc *dc, struct dc_stream_state *stream)
3218 if ((stream->link->psr_settings.psr_version == DC_PSR_VERSION_SU_1
3219 || stream->link->psr_settings.psr_version == DC_PSR_VERSION_1)
3220 && stream->ctx->dce_version >= DCN_VERSION_3_1)
3223 if (stream->link->replay_settings.config.replay_supported)
3229 void dc_dmub_update_dirty_rect(struct dc *dc,
3231 struct dc_stream_state *stream,
3232 struct dc_surface_update *srf_updates,
3233 struct dc_state *context)
3235 union dmub_rb_cmd cmd;
3236 struct dmub_cmd_update_dirty_rect_data *update_dirty_rect;
3238 unsigned int panel_inst = 0;
3240 if (!dc_dmub_should_send_dirty_rect_cmd(dc, stream))
3243 if (!dc_get_edp_link_panel_inst(dc, stream->link, &panel_inst))
3246 memset(&cmd, 0x0, sizeof(cmd));
3247 cmd.update_dirty_rect.header.type = DMUB_CMD__UPDATE_DIRTY_RECT;
3248 cmd.update_dirty_rect.header.sub_type = 0;
3249 cmd.update_dirty_rect.header.payload_bytes =
3250 sizeof(cmd.update_dirty_rect) -
3251 sizeof(cmd.update_dirty_rect.header);
3252 update_dirty_rect = &cmd.update_dirty_rect.update_dirty_rect_data;
3253 for (i = 0; i < surface_count; i++) {
3254 struct dc_plane_state *plane_state = srf_updates[i].surface;
3255 const struct dc_flip_addrs *flip_addr = srf_updates[i].flip_addr;
3257 if (!srf_updates[i].surface || !flip_addr)
3259 /* Do not send in immediate flip mode */
3260 if (srf_updates[i].surface->flip_immediate)
3263 update_dirty_rect->dirty_rect_count = flip_addr->dirty_rect_count;
3264 memcpy(update_dirty_rect->src_dirty_rects, flip_addr->dirty_rects,
3265 sizeof(flip_addr->dirty_rects));
3266 for (j = 0; j < dc->res_pool->pipe_count; j++) {
3267 struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[j];
3269 if (pipe_ctx->stream != stream)
3271 if (pipe_ctx->plane_state != plane_state)
3274 update_dirty_rect->panel_inst = panel_inst;
3275 update_dirty_rect->pipe_idx = j;
3276 dc_wake_and_execute_dmub_cmd(dc->ctx, &cmd, DM_DMUB_WAIT_TYPE_NO_WAIT);
3281 static void build_dmub_update_dirty_rect(
3284 struct dc_stream_state *stream,
3285 struct dc_surface_update *srf_updates,
3286 struct dc_state *context,
3287 struct dc_dmub_cmd dc_dmub_cmd[],
3288 unsigned int *dmub_cmd_count)
3290 union dmub_rb_cmd cmd;
3291 struct dmub_cmd_update_dirty_rect_data *update_dirty_rect;
3293 unsigned int panel_inst = 0;
3295 if (!dc_dmub_should_send_dirty_rect_cmd(dc, stream))
3298 if (!dc_get_edp_link_panel_inst(dc, stream->link, &panel_inst))
3301 memset(&cmd, 0x0, sizeof(cmd));
3302 cmd.update_dirty_rect.header.type = DMUB_CMD__UPDATE_DIRTY_RECT;
3303 cmd.update_dirty_rect.header.sub_type = 0;
3304 cmd.update_dirty_rect.header.payload_bytes =
3305 sizeof(cmd.update_dirty_rect) -
3306 sizeof(cmd.update_dirty_rect.header);
3307 update_dirty_rect = &cmd.update_dirty_rect.update_dirty_rect_data;
3308 for (i = 0; i < surface_count; i++) {
3309 struct dc_plane_state *plane_state = srf_updates[i].surface;
3310 const struct dc_flip_addrs *flip_addr = srf_updates[i].flip_addr;
3312 if (!srf_updates[i].surface || !flip_addr)
3314 /* Do not send in immediate flip mode */
3315 if (srf_updates[i].surface->flip_immediate)
3317 update_dirty_rect->cmd_version = DMUB_CMD_PSR_CONTROL_VERSION_1;
3318 update_dirty_rect->dirty_rect_count = flip_addr->dirty_rect_count;
3319 memcpy(update_dirty_rect->src_dirty_rects, flip_addr->dirty_rects,
3320 sizeof(flip_addr->dirty_rects));
3321 for (j = 0; j < dc->res_pool->pipe_count; j++) {
3322 struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[j];
3324 if (pipe_ctx->stream != stream)
3326 if (pipe_ctx->plane_state != plane_state)
3328 update_dirty_rect->panel_inst = panel_inst;
3329 update_dirty_rect->pipe_idx = j;
3330 dc_dmub_cmd[*dmub_cmd_count].dmub_cmd = cmd;
3331 dc_dmub_cmd[*dmub_cmd_count].wait_type = DM_DMUB_WAIT_TYPE_NO_WAIT;
3332 (*dmub_cmd_count)++;
3339 * build_dmub_cmd_list() - Build an array of DMCUB commands to be sent to DMCUB
3341 * @dc: Current DC state
3342 * @srf_updates: Array of surface updates
3343 * @surface_count: Number of surfaces that have an updated
3344 * @stream: Corresponding stream to be updated in the current flip
3345 * @context: New DC state to be programmed
3347 * @dc_dmub_cmd: Array of DMCUB commands to be sent to DMCUB
3348 * @dmub_cmd_count: Count indicating the number of DMCUB commands in dc_dmub_cmd array
3350 * This function builds an array of DMCUB commands to be sent to DMCUB. This function is required
3351 * to build an array of commands and have them sent while the OTG lock is acquired.
3355 static void build_dmub_cmd_list(struct dc *dc,
3356 struct dc_surface_update *srf_updates,
3358 struct dc_stream_state *stream,
3359 struct dc_state *context,
3360 struct dc_dmub_cmd dc_dmub_cmd[],
3361 unsigned int *dmub_cmd_count)
3363 // Initialize cmd count to 0
3364 *dmub_cmd_count = 0;
3365 build_dmub_update_dirty_rect(dc, surface_count, stream, srf_updates, context, dc_dmub_cmd, dmub_cmd_count);
3368 static void commit_planes_for_stream_fast(struct dc *dc,
3369 struct dc_surface_update *srf_updates,
3371 struct dc_stream_state *stream,
3372 struct dc_stream_update *stream_update,
3373 enum surface_update_type update_type,
3374 struct dc_state *context)
3377 struct pipe_ctx *top_pipe_to_program = NULL;
3378 struct dc_stream_status *stream_status = NULL;
3381 top_pipe_to_program = resource_get_otg_master_for_stream(
3385 if (!top_pipe_to_program)
3388 for (i = 0; i < dc->res_pool->pipe_count; i++) {
3389 struct pipe_ctx *pipe = &context->res_ctx.pipe_ctx[i];
3391 if (pipe->stream && pipe->plane_state) {
3392 set_p_state_switch_method(dc, context, pipe);
3394 if (dc->debug.visual_confirm)
3395 dc_update_visual_confirm_color(dc, context, pipe);
3399 for (i = 0; i < surface_count; i++) {
3400 struct dc_plane_state *plane_state = srf_updates[i].surface;
3401 /*set logical flag for lock/unlock use*/
3402 for (j = 0; j < dc->res_pool->pipe_count; j++) {
3403 struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[j];
3405 if (!pipe_ctx->plane_state)
3407 if (should_update_pipe_for_plane(context, pipe_ctx, plane_state))
3409 pipe_ctx->plane_state->triplebuffer_flips = false;
3410 if (update_type == UPDATE_TYPE_FAST &&
3411 dc->hwss.program_triplebuffer &&
3412 !pipe_ctx->plane_state->flip_immediate && dc->debug.enable_tri_buf) {
3413 /*triple buffer for VUpdate only*/
3414 pipe_ctx->plane_state->triplebuffer_flips = true;
3419 stream_status = dc_state_get_stream_status(context, stream);
3421 build_dmub_cmd_list(dc,
3426 context->dc_dmub_cmd,
3427 &(context->dmub_cmd_count));
3428 hwss_build_fast_sequence(dc,
3429 context->dc_dmub_cmd,
3430 context->dmub_cmd_count,
3431 context->block_sequence,
3432 &(context->block_sequence_steps),
3433 top_pipe_to_program,
3435 hwss_execute_sequence(dc,
3436 context->block_sequence,
3437 context->block_sequence_steps);
3438 /* Clear update flags so next flip doesn't have redundant programming
3439 * (if there's no stream update, the update flags are not cleared).
3440 * Surface updates are cleared unconditionally at the beginning of each flip,
3441 * so no need to clear here.
3443 if (top_pipe_to_program->stream)
3444 top_pipe_to_program->stream->update_flags.raw = 0;
3447 static void wait_for_outstanding_hw_updates(struct dc *dc, const struct dc_state *dc_context)
3450 * This function calls HWSS to wait for any potentially double buffered
3451 * operations to complete. It should be invoked as a pre-amble prior
3452 * to full update programming before asserting any HW locks.
3456 int opp_count = dc->res_pool->res_cap->num_opp;
3459 const struct pipe_ctx *pipe_ctx;
3461 for (pipe_idx = 0; pipe_idx < dc->res_pool->pipe_count; pipe_idx++) {
3462 pipe_ctx = &dc_context->res_ctx.pipe_ctx[pipe_idx];
3464 if (!pipe_ctx->stream)
3467 if (pipe_ctx->stream_res.tg->funcs->wait_drr_doublebuffer_pending_clear)
3468 pipe_ctx->stream_res.tg->funcs->wait_drr_doublebuffer_pending_clear(pipe_ctx->stream_res.tg);
3470 hubp = pipe_ctx->plane_res.hubp;
3474 mpcc_inst = hubp->inst;
3475 // MPCC inst is equal to pipe index in practice
3476 for (opp_inst = 0; opp_inst < opp_count; opp_inst++) {
3477 if ((dc->res_pool->opps[opp_inst] != NULL) &&
3478 (dc->res_pool->opps[opp_inst]->mpcc_disconnect_pending[mpcc_inst])) {
3479 dc->res_pool->mpc->funcs->wait_for_idle(dc->res_pool->mpc, mpcc_inst);
3480 dc->res_pool->opps[opp_inst]->mpcc_disconnect_pending[mpcc_inst] = false;
3487 static void commit_planes_for_stream(struct dc *dc,
3488 struct dc_surface_update *srf_updates,
3490 struct dc_stream_state *stream,
3491 struct dc_stream_update *stream_update,
3492 enum surface_update_type update_type,
3493 struct dc_state *context)
3496 struct pipe_ctx *top_pipe_to_program = NULL;
3497 bool should_lock_all_pipes = (update_type != UPDATE_TYPE_FAST);
3498 bool subvp_prev_use = false;
3499 bool subvp_curr_use = false;
3500 uint8_t current_stream_mask = 0;
3502 // Once we apply the new subvp context to hardware it won't be in the
3503 // dc->current_state anymore, so we have to cache it before we apply
3504 // the new SubVP context
3505 subvp_prev_use = false;
3507 if (update_type == UPDATE_TYPE_FULL)
3508 wait_for_outstanding_hw_updates(dc, context);
3510 if (update_type == UPDATE_TYPE_FULL) {
3511 dc_allow_idle_optimizations(dc, false);
3513 if (get_seamless_boot_stream_count(context) == 0)
3514 dc->hwss.prepare_bandwidth(dc, context);
3516 if (dc->hwss.update_dsc_pg)
3517 dc->hwss.update_dsc_pg(dc, context, false);
3519 context_clock_trace(dc, context);
3522 top_pipe_to_program = resource_get_otg_master_for_stream(
3525 ASSERT(top_pipe_to_program != NULL);
3526 for (i = 0; i < dc->res_pool->pipe_count; i++) {
3527 struct pipe_ctx *old_pipe = &dc->current_state->res_ctx.pipe_ctx[i];
3529 // Check old context for SubVP
3530 subvp_prev_use |= (dc_state_get_pipe_subvp_type(dc->current_state, old_pipe) == SUBVP_PHANTOM);
3535 for (i = 0; i < dc->res_pool->pipe_count; i++) {
3536 struct pipe_ctx *pipe = &context->res_ctx.pipe_ctx[i];
3538 if (dc_state_get_pipe_subvp_type(context, pipe) == SUBVP_PHANTOM) {
3539 subvp_curr_use = true;
3544 for (i = 0; i < dc->res_pool->pipe_count; i++) {
3545 struct pipe_ctx *pipe = &context->res_ctx.pipe_ctx[i];
3547 if (pipe->stream && pipe->plane_state) {
3548 set_p_state_switch_method(dc, context, pipe);
3550 if (dc->debug.visual_confirm)
3551 dc_update_visual_confirm_color(dc, context, pipe);
3555 if (stream->test_pattern.type != DP_TEST_PATTERN_VIDEO_MODE) {
3556 struct pipe_ctx *mpcc_pipe;
3557 struct pipe_ctx *odm_pipe;
3559 for (mpcc_pipe = top_pipe_to_program; mpcc_pipe; mpcc_pipe = mpcc_pipe->bottom_pipe)
3560 for (odm_pipe = mpcc_pipe; odm_pipe; odm_pipe = odm_pipe->next_odm_pipe)
3561 odm_pipe->ttu_regs.min_ttu_vblank = MAX_TTU;
3564 if ((update_type != UPDATE_TYPE_FAST) && stream->update_flags.bits.dsc_changed)
3565 if (top_pipe_to_program &&
3566 top_pipe_to_program->stream_res.tg->funcs->lock_doublebuffer_enable) {
3567 if (should_use_dmub_lock(stream->link)) {
3568 union dmub_hw_lock_flags hw_locks = { 0 };
3569 struct dmub_hw_lock_inst_flags inst_flags = { 0 };
3571 hw_locks.bits.lock_dig = 1;
3572 inst_flags.dig_inst = top_pipe_to_program->stream_res.tg->inst;
3574 dmub_hw_lock_mgr_cmd(dc->ctx->dmub_srv,
3579 top_pipe_to_program->stream_res.tg->funcs->lock_doublebuffer_enable(
3580 top_pipe_to_program->stream_res.tg);
3583 if (should_lock_all_pipes && dc->hwss.interdependent_update_lock) {
3584 if (dc->hwss.subvp_pipe_control_lock)
3585 dc->hwss.subvp_pipe_control_lock(dc, context, true, should_lock_all_pipes, NULL, subvp_prev_use);
3586 dc->hwss.interdependent_update_lock(dc, context, true);
3589 if (dc->hwss.subvp_pipe_control_lock)
3590 dc->hwss.subvp_pipe_control_lock(dc, context, true, should_lock_all_pipes, top_pipe_to_program, subvp_prev_use);
3591 /* Lock the top pipe while updating plane addrs, since freesync requires
3592 * plane addr update event triggers to be synchronized.
3593 * top_pipe_to_program is expected to never be NULL
3595 dc->hwss.pipe_control_lock(dc, top_pipe_to_program, true);
3598 dc_dmub_update_dirty_rect(dc, surface_count, stream, srf_updates, context);
3602 commit_planes_do_stream_update(dc, stream, stream_update, update_type, context);
3604 if (surface_count == 0) {
3606 * In case of turning off screen, no need to program front end a second time.
3607 * just return after program blank.
3609 if (dc->hwss.apply_ctx_for_surface)
3610 dc->hwss.apply_ctx_for_surface(dc, stream, 0, context);
3611 if (dc->hwss.program_front_end_for_ctx)
3612 dc->hwss.program_front_end_for_ctx(dc, context);
3614 if (should_lock_all_pipes && dc->hwss.interdependent_update_lock) {
3615 dc->hwss.interdependent_update_lock(dc, context, false);
3617 dc->hwss.pipe_control_lock(dc, top_pipe_to_program, false);
3619 dc->hwss.post_unlock_program_front_end(dc, context);
3621 if (update_type != UPDATE_TYPE_FAST)
3622 if (dc->hwss.commit_subvp_config)
3623 dc->hwss.commit_subvp_config(dc, context);
3625 /* Since phantom pipe programming is moved to post_unlock_program_front_end,
3626 * move the SubVP lock to after the phantom pipes have been setup
3628 if (dc->hwss.subvp_pipe_control_lock)
3629 dc->hwss.subvp_pipe_control_lock(dc, context, false, should_lock_all_pipes,
3630 NULL, subvp_prev_use);
3634 if (update_type != UPDATE_TYPE_FAST) {
3635 for (j = 0; j < dc->res_pool->pipe_count; j++) {
3636 struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[j];
3638 if ((dc->debug.visual_confirm == VISUAL_CONFIRM_SUBVP ||
3639 dc->debug.visual_confirm == VISUAL_CONFIRM_MCLK_SWITCH) &&
3640 pipe_ctx->stream && pipe_ctx->plane_state) {
3641 /* Only update visual confirm for SUBVP and Mclk switching here.
3642 * The bar appears on all pipes, so we need to update the bar on all displays,
3643 * so the information doesn't get stale.
3645 dc->hwss.update_visual_confirm_color(dc, pipe_ctx,
3646 pipe_ctx->plane_res.hubp->inst);
3651 for (i = 0; i < surface_count; i++) {
3652 struct dc_plane_state *plane_state = srf_updates[i].surface;
3653 /*set logical flag for lock/unlock use*/
3654 for (j = 0; j < dc->res_pool->pipe_count; j++) {
3655 struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[j];
3656 if (!pipe_ctx->plane_state)
3658 if (should_update_pipe_for_plane(context, pipe_ctx, plane_state))
3660 pipe_ctx->plane_state->triplebuffer_flips = false;
3661 if (update_type == UPDATE_TYPE_FAST &&
3662 dc->hwss.program_triplebuffer != NULL &&
3663 !pipe_ctx->plane_state->flip_immediate && dc->debug.enable_tri_buf) {
3664 /*triple buffer for VUpdate only*/
3665 pipe_ctx->plane_state->triplebuffer_flips = true;
3668 if (update_type == UPDATE_TYPE_FULL) {
3669 /* force vsync flip when reconfiguring pipes to prevent underflow */
3670 plane_state->flip_immediate = false;
3674 // Update Type FULL, Surface updates
3675 for (j = 0; j < dc->res_pool->pipe_count; j++) {
3676 struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[j];
3678 if (!pipe_ctx->top_pipe &&
3679 !pipe_ctx->prev_odm_pipe &&
3680 should_update_pipe_for_stream(context, pipe_ctx, stream)) {
3681 struct dc_stream_status *stream_status = NULL;
3683 if (!pipe_ctx->plane_state)
3687 if (update_type == UPDATE_TYPE_FAST)
3690 ASSERT(!pipe_ctx->plane_state->triplebuffer_flips);
3692 if (dc->hwss.program_triplebuffer != NULL && dc->debug.enable_tri_buf) {
3693 /*turn off triple buffer for full update*/
3694 dc->hwss.program_triplebuffer(
3695 dc, pipe_ctx, pipe_ctx->plane_state->triplebuffer_flips);
3698 stream_get_status(context, pipe_ctx->stream);
3700 if (dc->hwss.apply_ctx_for_surface)
3701 dc->hwss.apply_ctx_for_surface(
3702 dc, pipe_ctx->stream, stream_status->plane_count, context);
3705 if (dc->hwss.program_front_end_for_ctx && update_type != UPDATE_TYPE_FAST) {
3706 dc->hwss.program_front_end_for_ctx(dc, context);
3707 if (dc->debug.validate_dml_output) {
3708 for (i = 0; i < dc->res_pool->pipe_count; i++) {
3709 struct pipe_ctx *cur_pipe = &context->res_ctx.pipe_ctx[i];
3710 if (cur_pipe->stream == NULL)
3713 cur_pipe->plane_res.hubp->funcs->validate_dml_output(
3714 cur_pipe->plane_res.hubp, dc->ctx,
3715 &context->res_ctx.pipe_ctx[i].rq_regs,
3716 &context->res_ctx.pipe_ctx[i].dlg_regs,
3717 &context->res_ctx.pipe_ctx[i].ttu_regs);
3722 // Update Type FAST, Surface updates
3723 if (update_type == UPDATE_TYPE_FAST) {
3724 if (dc->hwss.set_flip_control_gsl)
3725 for (i = 0; i < surface_count; i++) {
3726 struct dc_plane_state *plane_state = srf_updates[i].surface;
3728 for (j = 0; j < dc->res_pool->pipe_count; j++) {
3729 struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[j];
3731 if (!should_update_pipe_for_stream(context, pipe_ctx, stream))
3734 if (!should_update_pipe_for_plane(context, pipe_ctx, plane_state))
3737 // GSL has to be used for flip immediate
3738 dc->hwss.set_flip_control_gsl(pipe_ctx,
3739 pipe_ctx->plane_state->flip_immediate);
3743 /* Perform requested Updates */
3744 for (i = 0; i < surface_count; i++) {
3745 struct dc_plane_state *plane_state = srf_updates[i].surface;
3747 for (j = 0; j < dc->res_pool->pipe_count; j++) {
3748 struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[j];
3750 if (!should_update_pipe_for_stream(context, pipe_ctx, stream))
3753 if (!should_update_pipe_for_plane(context, pipe_ctx, plane_state))
3756 /*program triple buffer after lock based on flip type*/
3757 if (dc->hwss.program_triplebuffer != NULL && dc->debug.enable_tri_buf) {
3758 /*only enable triplebuffer for fast_update*/
3759 dc->hwss.program_triplebuffer(
3760 dc, pipe_ctx, pipe_ctx->plane_state->triplebuffer_flips);
3762 if (pipe_ctx->plane_state->update_flags.bits.addr_update)
3763 dc->hwss.update_plane_addr(dc, pipe_ctx);
3768 if (should_lock_all_pipes && dc->hwss.interdependent_update_lock) {
3769 dc->hwss.interdependent_update_lock(dc, context, false);
3771 dc->hwss.pipe_control_lock(dc, top_pipe_to_program, false);
3774 if ((update_type != UPDATE_TYPE_FAST) && stream->update_flags.bits.dsc_changed)
3775 if (top_pipe_to_program->stream_res.tg->funcs->lock_doublebuffer_enable) {
3776 top_pipe_to_program->stream_res.tg->funcs->wait_for_state(
3777 top_pipe_to_program->stream_res.tg,
3778 CRTC_STATE_VACTIVE);
3779 top_pipe_to_program->stream_res.tg->funcs->wait_for_state(
3780 top_pipe_to_program->stream_res.tg,
3782 top_pipe_to_program->stream_res.tg->funcs->wait_for_state(
3783 top_pipe_to_program->stream_res.tg,
3784 CRTC_STATE_VACTIVE);
3786 if (should_use_dmub_lock(stream->link)) {
3787 union dmub_hw_lock_flags hw_locks = { 0 };
3788 struct dmub_hw_lock_inst_flags inst_flags = { 0 };
3790 hw_locks.bits.lock_dig = 1;
3791 inst_flags.dig_inst = top_pipe_to_program->stream_res.tg->inst;
3793 dmub_hw_lock_mgr_cmd(dc->ctx->dmub_srv,
3798 top_pipe_to_program->stream_res.tg->funcs->lock_doublebuffer_disable(
3799 top_pipe_to_program->stream_res.tg);
3802 if (subvp_curr_use) {
3803 /* If enabling subvp or transitioning from subvp->subvp, enable the
3804 * phantom streams before we program front end for the phantom pipes.
3806 if (update_type != UPDATE_TYPE_FAST) {
3807 if (dc->hwss.enable_phantom_streams)
3808 dc->hwss.enable_phantom_streams(dc, context);
3812 if (update_type != UPDATE_TYPE_FAST)
3813 dc->hwss.post_unlock_program_front_end(dc, context);
3815 if (subvp_prev_use && !subvp_curr_use) {
3816 /* If disabling subvp, disable phantom streams after front end
3817 * programming has completed (we turn on phantom OTG in order
3818 * to complete the plane disable for phantom pipes).
3821 if (dc->hwss.disable_phantom_streams)
3822 dc->hwss.disable_phantom_streams(dc, context);
3825 if (update_type != UPDATE_TYPE_FAST)
3826 if (dc->hwss.commit_subvp_config)
3827 dc->hwss.commit_subvp_config(dc, context);
3828 /* Since phantom pipe programming is moved to post_unlock_program_front_end,
3829 * move the SubVP lock to after the phantom pipes have been setup
3831 if (should_lock_all_pipes && dc->hwss.interdependent_update_lock) {
3832 if (dc->hwss.subvp_pipe_control_lock)
3833 dc->hwss.subvp_pipe_control_lock(dc, context, false, should_lock_all_pipes, NULL, subvp_prev_use);
3835 if (dc->hwss.subvp_pipe_control_lock)
3836 dc->hwss.subvp_pipe_control_lock(dc, context, false, should_lock_all_pipes, top_pipe_to_program, subvp_prev_use);
3839 // Fire manual trigger only when bottom plane is flipped
3840 for (j = 0; j < dc->res_pool->pipe_count; j++) {
3841 struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[j];
3843 if (!pipe_ctx->plane_state)
3846 if (pipe_ctx->bottom_pipe || pipe_ctx->next_odm_pipe ||
3847 !pipe_ctx->stream || !should_update_pipe_for_stream(context, pipe_ctx, stream) ||
3848 !pipe_ctx->plane_state->update_flags.bits.addr_update ||
3849 pipe_ctx->plane_state->skip_manual_trigger)
3852 if (pipe_ctx->stream_res.tg->funcs->program_manual_trigger)
3853 pipe_ctx->stream_res.tg->funcs->program_manual_trigger(pipe_ctx->stream_res.tg);
3856 current_stream_mask = get_stream_mask(dc, context);
3857 if (current_stream_mask != context->stream_mask) {
3858 context->stream_mask = current_stream_mask;
3859 dc_dmub_srv_notify_stream_mask(dc->ctx->dmub_srv, current_stream_mask);
3864 * could_mpcc_tree_change_for_active_pipes - Check if an OPP associated with MPCC might change
3866 * @dc: Used to get the current state status
3867 * @stream: Target stream, which we want to remove the attached planes
3868 * @srf_updates: Array of surface updates
3869 * @surface_count: Number of surface update
3870 * @is_plane_addition: [in] Fill out with true if it is a plane addition case
3872 * DCN32x and newer support a feature named Dynamic ODM which can conflict with
3873 * the MPO if used simultaneously in some specific configurations (e.g.,
3874 * 4k@144). This function checks if the incoming context requires applying a
3875 * transition state with unnecessary pipe splitting and ODM disabled to
3876 * circumvent our hardware limitations to prevent this edge case. If the OPP
3877 * associated with an MPCC might change due to plane additions, this function
3881 * Return true if OPP and MPCC might change, otherwise, return false.
3883 static bool could_mpcc_tree_change_for_active_pipes(struct dc *dc,
3884 struct dc_stream_state *stream,
3885 struct dc_surface_update *srf_updates,
3887 bool *is_plane_addition)
3890 struct dc_stream_status *cur_stream_status = stream_get_status(dc->current_state, stream);
3891 bool force_minimal_pipe_splitting = false;
3892 bool subvp_active = false;
3895 *is_plane_addition = false;
3897 if (cur_stream_status &&
3898 dc->current_state->stream_count > 0 &&
3899 dc->debug.pipe_split_policy != MPC_SPLIT_AVOID) {
3900 /* determine if minimal transition is required due to MPC*/
3901 if (surface_count > 0) {
3902 if (cur_stream_status->plane_count > surface_count) {
3903 force_minimal_pipe_splitting = true;
3904 } else if (cur_stream_status->plane_count < surface_count) {
3905 force_minimal_pipe_splitting = true;
3906 *is_plane_addition = true;
3911 if (cur_stream_status &&
3912 dc->current_state->stream_count == 1 &&
3913 dc->debug.enable_single_display_2to1_odm_policy) {
3914 /* determine if minimal transition is required due to dynamic ODM*/
3915 if (surface_count > 0) {
3916 if (cur_stream_status->plane_count > 2 && cur_stream_status->plane_count > surface_count) {
3917 force_minimal_pipe_splitting = true;
3918 } else if (surface_count > 2 && cur_stream_status->plane_count < surface_count) {
3919 force_minimal_pipe_splitting = true;
3920 *is_plane_addition = true;
3925 for (i = 0; i < dc->res_pool->pipe_count; i++) {
3926 struct pipe_ctx *pipe = &dc->current_state->res_ctx.pipe_ctx[i];
3928 if (dc_state_get_pipe_subvp_type(dc->current_state, pipe) != SUBVP_NONE) {
3929 subvp_active = true;
3934 /* For SubVP when adding or removing planes we need to add a minimal transition
3935 * (even when disabling all planes). Whenever disabling a phantom pipe, we
3936 * must use the minimal transition path to disable the pipe correctly.
3938 * We want to use the minimal transition whenever subvp is active, not only if
3939 * a plane is being added / removed from a subvp stream (MPO plane can be added
3940 * to a DRR pipe of SubVP + DRR config, in which case we still want to run through
3941 * a min transition to disable subvp.
3943 if (cur_stream_status && subvp_active) {
3944 /* determine if minimal transition is required due to SubVP*/
3945 if (cur_stream_status->plane_count > surface_count) {
3946 force_minimal_pipe_splitting = true;
3947 } else if (cur_stream_status->plane_count < surface_count) {
3948 force_minimal_pipe_splitting = true;
3949 *is_plane_addition = true;
3953 return force_minimal_pipe_splitting;
3956 struct pipe_split_policy_backup {
3957 bool dynamic_odm_policy;
3959 enum pipe_split_policy mpc_policy;
3962 static void release_minimal_transition_state(struct dc *dc,
3963 struct dc_state *context, struct pipe_split_policy_backup *policy)
3965 dc_state_release(context);
3966 /* restore previous pipe split and odm policy */
3967 if (!dc->config.is_vmin_only_asic)
3968 dc->debug.pipe_split_policy = policy->mpc_policy;
3969 dc->debug.enable_single_display_2to1_odm_policy = policy->dynamic_odm_policy;
3970 dc->debug.force_disable_subvp = policy->subvp_policy;
3973 static struct dc_state *create_minimal_transition_state(struct dc *dc,
3974 struct dc_state *base_context, struct pipe_split_policy_backup *policy)
3976 struct dc_state *minimal_transition_context = NULL;
3979 if (!dc->config.is_vmin_only_asic) {
3980 policy->mpc_policy = dc->debug.pipe_split_policy;
3981 dc->debug.pipe_split_policy = MPC_SPLIT_AVOID;
3983 policy->dynamic_odm_policy = dc->debug.enable_single_display_2to1_odm_policy;
3984 dc->debug.enable_single_display_2to1_odm_policy = false;
3985 policy->subvp_policy = dc->debug.force_disable_subvp;
3986 dc->debug.force_disable_subvp = true;
3988 minimal_transition_context = dc_state_create_copy(base_context);
3989 if (!minimal_transition_context)
3992 /* commit minimal state */
3993 if (dc->res_pool->funcs->validate_bandwidth(dc, minimal_transition_context, false)) {
3994 for (i = 0; i < minimal_transition_context->stream_count; i++) {
3995 struct dc_stream_status *stream_status = &minimal_transition_context->stream_status[i];
3997 for (j = 0; j < stream_status->plane_count; j++) {
3998 struct dc_plane_state *plane_state = stream_status->plane_states[j];
4000 /* force vsync flip when reconfiguring pipes to prevent underflow
4003 plane_state->flip_immediate = false;
4007 /* this should never happen */
4008 release_minimal_transition_state(dc, minimal_transition_context, policy);
4009 BREAK_TO_DEBUGGER();
4010 minimal_transition_context = NULL;
4012 return minimal_transition_context;
4015 static bool commit_minimal_transition_state_for_windowed_mpo_odm(struct dc *dc,
4016 struct dc_state *context,
4017 struct dc_stream_state *stream)
4019 bool success = false;
4020 struct dc_state *minimal_transition_context;
4021 struct pipe_split_policy_backup policy;
4023 /* commit based on new context */
4024 /* Since all phantom pipes are removed in full validation,
4025 * we have to save and restore the subvp/mall config when
4026 * we do a minimal transition since the flags marking the
4027 * pipe as subvp/phantom will be cleared (dc copy constructor
4028 * creates a shallow copy).
4030 minimal_transition_context = create_minimal_transition_state(dc,
4032 if (minimal_transition_context) {
4033 if (dc->hwss.is_pipe_topology_transition_seamless(
4034 dc, dc->current_state, minimal_transition_context) &&
4035 dc->hwss.is_pipe_topology_transition_seamless(
4036 dc, minimal_transition_context, context)) {
4037 DC_LOG_DC("%s base = new state\n", __func__);
4039 success = dc_commit_state_no_check(dc, minimal_transition_context) == DC_OK;
4041 release_minimal_transition_state(dc, minimal_transition_context, &policy);
4045 /* commit based on current context */
4046 restore_plane_states_for_stream(dc->current_state->scratch.plane_states, stream);
4047 minimal_transition_context = create_minimal_transition_state(dc,
4048 dc->current_state, &policy);
4049 if (minimal_transition_context) {
4050 if (dc->hwss.is_pipe_topology_transition_seamless(
4051 dc, dc->current_state, minimal_transition_context) &&
4052 dc->hwss.is_pipe_topology_transition_seamless(
4053 dc, minimal_transition_context, context)) {
4054 DC_LOG_DC("%s base = current state\n", __func__);
4055 success = dc_commit_state_no_check(dc, minimal_transition_context) == DC_OK;
4057 release_minimal_transition_state(dc, minimal_transition_context, &policy);
4059 restore_plane_states_for_stream(context->scratch.plane_states, stream);
4067 * commit_minimal_transition_state - Create a transition pipe split state
4069 * @dc: Used to get the current state status
4070 * @transition_base_context: New transition state
4072 * In some specific configurations, such as pipe split on multi-display with
4073 * MPO and/or Dynamic ODM, removing a plane may cause unsupported pipe
4074 * programming when moving to new planes. To mitigate those types of problems,
4075 * this function adds a transition state that minimizes pipe usage before
4076 * programming the new configuration. When adding a new plane, the current
4077 * state requires the least pipes, so it is applied without splitting. When
4078 * removing a plane, the new state requires the least pipes, so it is applied
4079 * without splitting.
4082 * Return false if something is wrong in the transition state.
4084 static bool commit_minimal_transition_state(struct dc *dc,
4085 struct dc_state *transition_base_context)
4087 struct dc_state *transition_context;
4088 struct pipe_split_policy_backup policy;
4089 enum dc_status ret = DC_ERROR_UNEXPECTED;
4091 unsigned int pipe_in_use = 0;
4092 bool subvp_in_use = false;
4093 bool odm_in_use = false;
4095 /* check current pipes in use*/
4096 for (i = 0; i < dc->res_pool->pipe_count; i++) {
4097 struct pipe_ctx *pipe = &transition_base_context->res_ctx.pipe_ctx[i];
4099 if (pipe->plane_state)
4103 /* If SubVP is enabled and we are adding or removing planes from any main subvp
4104 * pipe, we must use the minimal transition.
4106 for (i = 0; i < dc->res_pool->pipe_count; i++) {
4107 struct pipe_ctx *pipe = &dc->current_state->res_ctx.pipe_ctx[i];
4109 if (pipe->stream && dc_state_get_pipe_subvp_type(dc->current_state, pipe) == SUBVP_PHANTOM) {
4110 subvp_in_use = true;
4115 /* If ODM is enabled and we are adding or removing planes from any ODM
4116 * pipe, we must use the minimal transition.
4118 for (i = 0; i < dc->res_pool->pipe_count; i++) {
4119 struct pipe_ctx *pipe = &transition_base_context->res_ctx.pipe_ctx[i];
4121 if (resource_is_pipe_type(pipe, OTG_MASTER)) {
4122 odm_in_use = resource_get_odm_slice_count(pipe) > 1;
4127 /* When the OS add a new surface if we have been used all of pipes with odm combine
4128 * and mpc split feature, it need use commit_minimal_transition_state to transition safely.
4129 * After OS exit MPO, it will back to use odm and mpc split with all of pipes, we need
4130 * call it again. Otherwise return true to skip.
4132 * Reduce the scenarios to use dc_commit_state_no_check in the stage of flip. Especially
4133 * enter/exit MPO when DCN still have enough resources.
4135 if (pipe_in_use != dc->res_pool->pipe_count && !subvp_in_use && !odm_in_use)
4138 DC_LOG_DC("%s base = %s state, reason = %s\n", __func__,
4139 dc->current_state == transition_base_context ? "current" : "new",
4140 subvp_in_use ? "Subvp In Use" :
4141 odm_in_use ? "ODM in Use" :
4142 dc->debug.pipe_split_policy != MPC_SPLIT_AVOID ? "MPC in Use" :
4145 transition_context = create_minimal_transition_state(dc,
4146 transition_base_context, &policy);
4147 if (transition_context) {
4148 ret = dc_commit_state_no_check(dc, transition_context);
4149 release_minimal_transition_state(dc, transition_context, &policy);
4153 /* this should never happen */
4154 BREAK_TO_DEBUGGER();
4158 /* force full surface update */
4159 for (i = 0; i < dc->current_state->stream_count; i++) {
4160 for (j = 0; j < dc->current_state->stream_status[i].plane_count; j++) {
4161 dc->current_state->stream_status[i].plane_states[j]->update_flags.raw = 0xFFFFFFFF;
4169 * update_seamless_boot_flags() - Helper function for updating seamless boot flags
4171 * @dc: Current DC state
4172 * @context: New DC state to be programmed
4173 * @surface_count: Number of surfaces that have an updated
4174 * @stream: Corresponding stream to be updated in the current flip
4176 * Updating seamless boot flags do not need to be part of the commit sequence. This
4177 * helper function will update the seamless boot flags on each flip (if required)
4178 * outside of the HW commit sequence (fast or slow).
4182 static void update_seamless_boot_flags(struct dc *dc,
4183 struct dc_state *context,
4185 struct dc_stream_state *stream)
4187 if (get_seamless_boot_stream_count(context) > 0 && surface_count > 0) {
4188 /* Optimize seamless boot flag keeps clocks and watermarks high until
4189 * first flip. After first flip, optimization is required to lower
4190 * bandwidth. Important to note that it is expected UEFI will
4191 * only light up a single display on POST, therefore we only expect
4192 * one stream with seamless boot flag set.
4194 if (stream->apply_seamless_boot_optimization) {
4195 stream->apply_seamless_boot_optimization = false;
4197 if (get_seamless_boot_stream_count(context) == 0)
4198 dc->optimized_required = true;
4203 static void populate_fast_updates(struct dc_fast_update *fast_update,
4204 struct dc_surface_update *srf_updates,
4206 struct dc_stream_update *stream_update)
4210 if (stream_update) {
4211 fast_update[0].out_transfer_func = stream_update->out_transfer_func;
4212 fast_update[0].output_csc_transform = stream_update->output_csc_transform;
4215 for (i = 0; i < surface_count; i++) {
4216 fast_update[i].flip_addr = srf_updates[i].flip_addr;
4217 fast_update[i].gamma = srf_updates[i].gamma;
4218 fast_update[i].gamut_remap_matrix = srf_updates[i].gamut_remap_matrix;
4219 fast_update[i].input_csc_color_matrix = srf_updates[i].input_csc_color_matrix;
4220 fast_update[i].coeff_reduction_factor = srf_updates[i].coeff_reduction_factor;
4224 static bool fast_updates_exist(struct dc_fast_update *fast_update, int surface_count)
4228 if (fast_update[0].out_transfer_func ||
4229 fast_update[0].output_csc_transform)
4232 for (i = 0; i < surface_count; i++) {
4233 if (fast_update[i].flip_addr ||
4234 fast_update[i].gamma ||
4235 fast_update[i].gamut_remap_matrix ||
4236 fast_update[i].input_csc_color_matrix ||
4237 fast_update[i].coeff_reduction_factor)
4244 static bool full_update_required(struct dc *dc,
4245 struct dc_surface_update *srf_updates,
4247 struct dc_stream_update *stream_update,
4248 struct dc_stream_state *stream)
4252 struct dc_stream_status *stream_status;
4253 const struct dc_state *context = dc->current_state;
4255 for (i = 0; i < surface_count; i++) {
4257 (srf_updates[i].plane_info ||
4258 srf_updates[i].scaling_info ||
4259 (srf_updates[i].hdr_mult.value &&
4260 srf_updates[i].hdr_mult.value != srf_updates->surface->hdr_mult.value) ||
4261 srf_updates[i].in_transfer_func ||
4262 srf_updates[i].func_shaper ||
4263 srf_updates[i].lut3d_func ||
4264 srf_updates[i].surface->force_full_update ||
4265 (srf_updates[i].flip_addr &&
4266 srf_updates[i].flip_addr->address.tmz_surface != srf_updates[i].surface->address.tmz_surface) ||
4267 !is_surface_in_context(context, srf_updates[i].surface)))
4271 if (stream_update &&
4272 (((stream_update->src.height != 0 && stream_update->src.width != 0) ||
4273 (stream_update->dst.height != 0 && stream_update->dst.width != 0) ||
4274 stream_update->integer_scaling_update) ||
4275 stream_update->hdr_static_metadata ||
4276 stream_update->abm_level ||
4277 stream_update->periodic_interrupt ||
4278 stream_update->vrr_infopacket ||
4279 stream_update->vsc_infopacket ||
4280 stream_update->vsp_infopacket ||
4281 stream_update->hfvsif_infopacket ||
4282 stream_update->vtem_infopacket ||
4283 stream_update->adaptive_sync_infopacket ||
4284 stream_update->dpms_off ||
4285 stream_update->allow_freesync ||
4286 stream_update->vrr_active_variable ||
4287 stream_update->vrr_active_fixed ||
4288 stream_update->gamut_remap ||
4289 stream_update->output_color_space ||
4290 stream_update->dither_option ||
4291 stream_update->wb_update ||
4292 stream_update->dsc_config ||
4293 stream_update->mst_bw_update ||
4294 stream_update->func_shaper ||
4295 stream_update->lut3d_func ||
4296 stream_update->pending_test_pattern ||
4297 stream_update->crtc_timing_adjust))
4301 stream_status = dc_stream_get_status(stream);
4302 if (stream_status == NULL || stream_status->plane_count != surface_count)
4305 if (dc->idle_optimizations_allowed)
4311 static bool fast_update_only(struct dc *dc,
4312 struct dc_fast_update *fast_update,
4313 struct dc_surface_update *srf_updates,
4315 struct dc_stream_update *stream_update,
4316 struct dc_stream_state *stream)
4318 return fast_updates_exist(fast_update, surface_count)
4319 && !full_update_required(dc, srf_updates, surface_count, stream_update, stream);
4322 static bool should_commit_minimal_transition_for_windowed_mpo_odm(struct dc *dc,
4323 struct dc_stream_state *stream,
4324 struct dc_state *context)
4326 struct pipe_ctx *cur_pipe, *new_pipe;
4327 bool cur_is_odm_in_use, new_is_odm_in_use;
4328 struct dc_stream_status *cur_stream_status = stream_get_status(dc->current_state, stream);
4329 struct dc_stream_status *new_stream_status = stream_get_status(context, stream);
4331 if (!dc->debug.enable_single_display_2to1_odm_policy ||
4332 !dc->config.enable_windowed_mpo_odm)
4333 /* skip the check if windowed MPO ODM or dynamic ODM is turned
4338 if (context == dc->current_state)
4339 /* skip the check for fast update */
4342 if (new_stream_status->plane_count != cur_stream_status->plane_count)
4343 /* plane count changed, not a plane scaling update so not the
4344 * case we are looking for
4348 cur_pipe = resource_get_otg_master_for_stream(&dc->current_state->res_ctx, stream);
4349 new_pipe = resource_get_otg_master_for_stream(&context->res_ctx, stream);
4350 if (!cur_pipe || !new_pipe)
4352 cur_is_odm_in_use = resource_get_odm_slice_count(cur_pipe) > 1;
4353 new_is_odm_in_use = resource_get_odm_slice_count(new_pipe) > 1;
4354 if (cur_is_odm_in_use == new_is_odm_in_use)
4355 /* ODM state isn't changed, not the case we are looking for */
4358 if (dc->hwss.is_pipe_topology_transition_seamless &&
4359 dc->hwss.is_pipe_topology_transition_seamless(
4360 dc, dc->current_state, context))
4361 /* transition can be achieved without the need for committing
4362 * minimal transition state first
4369 bool dc_update_planes_and_stream(struct dc *dc,
4370 struct dc_surface_update *srf_updates, int surface_count,
4371 struct dc_stream_state *stream,
4372 struct dc_stream_update *stream_update)
4374 struct dc_state *context;
4375 enum surface_update_type update_type;
4377 struct dc_fast_update fast_update[MAX_SURFACES] = {0};
4379 /* In cases where MPO and split or ODM are used transitions can
4380 * cause underflow. Apply stream configuration with minimal pipe
4381 * split first to avoid unsupported transitions for active pipes.
4383 bool force_minimal_pipe_splitting = 0;
4384 bool is_plane_addition = 0;
4385 bool is_fast_update_only;
4387 populate_fast_updates(fast_update, srf_updates, surface_count, stream_update);
4388 is_fast_update_only = fast_update_only(dc, fast_update, srf_updates,
4389 surface_count, stream_update, stream);
4390 force_minimal_pipe_splitting = could_mpcc_tree_change_for_active_pipes(
4395 &is_plane_addition);
4397 /* on plane addition, minimal state is the current one */
4398 if (force_minimal_pipe_splitting && is_plane_addition &&
4399 !commit_minimal_transition_state(dc, dc->current_state))
4402 if (!update_planes_and_stream_state(
4412 /* on plane removal, minimal state is the new one */
4413 if (force_minimal_pipe_splitting && !is_plane_addition) {
4414 /* Since all phantom pipes are removed in full validation,
4415 * we have to save and restore the subvp/mall config when
4416 * we do a minimal transition since the flags marking the
4417 * pipe as subvp/phantom will be cleared (dc copy constructor
4418 * creates a shallow copy).
4420 if (!commit_minimal_transition_state(dc, context)) {
4421 dc_state_release(context);
4424 update_type = UPDATE_TYPE_FULL;
4427 /* when windowed MPO ODM is supported, we need to handle a special case
4428 * where we can transition between ODM combine and MPC combine due to
4429 * plane scaling update. This transition will require us to commit
4430 * minimal transition state. The condition to trigger this update can't
4431 * be predicted by could_mpcc_tree_change_for_active_pipes because we
4432 * can only determine it after DML validation. Therefore we can't rely
4433 * on the existing commit minimal transition state sequence. Instead
4434 * we have to add additional handling here to handle this transition
4435 * with its own special sequence.
4437 if (should_commit_minimal_transition_for_windowed_mpo_odm(dc, stream, context))
4438 commit_minimal_transition_state_for_windowed_mpo_odm(dc,
4440 update_seamless_boot_flags(dc, context, surface_count, stream);
4441 if (is_fast_update_only && !dc->debug.enable_legacy_fast_update) {
4442 commit_planes_for_stream_fast(dc,
4450 if (!stream_update &&
4451 dc->hwss.is_pipe_topology_transition_seamless &&
4452 !dc->hwss.is_pipe_topology_transition_seamless(
4453 dc, dc->current_state, context)) {
4454 DC_LOG_ERROR("performing non-seamless pipe topology transition with surface only update!\n");
4455 BREAK_TO_DEBUGGER();
4457 commit_planes_for_stream(
4467 if (dc->current_state != context) {
4469 /* Since memory free requires elevated IRQL, an interrupt
4470 * request is generated by mem free. If this happens
4471 * between freeing and reassigning the context, our vsync
4472 * interrupt will call into dc and cause a memory
4473 * corruption BSOD. Hence, we first reassign the context,
4474 * then free the old context.
4477 struct dc_state *old = dc->current_state;
4479 dc->current_state = context;
4480 dc_state_release(old);
4482 // clear any forced full updates
4483 for (i = 0; i < dc->res_pool->pipe_count; i++) {
4484 struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[i];
4486 if (pipe_ctx->plane_state && pipe_ctx->stream == stream)
4487 pipe_ctx->plane_state->force_full_update = false;
4493 void dc_commit_updates_for_stream(struct dc *dc,
4494 struct dc_surface_update *srf_updates,
4496 struct dc_stream_state *stream,
4497 struct dc_stream_update *stream_update,
4498 struct dc_state *state)
4500 const struct dc_stream_status *stream_status;
4501 enum surface_update_type update_type;
4502 struct dc_state *context;
4503 struct dc_context *dc_ctx = dc->ctx;
4505 struct dc_fast_update fast_update[MAX_SURFACES] = {0};
4507 populate_fast_updates(fast_update, srf_updates, surface_count, stream_update);
4508 stream_status = dc_stream_get_status(stream);
4509 context = dc->current_state;
4511 update_type = dc_check_update_surfaces_for_stream(
4512 dc, srf_updates, surface_count, stream_update, stream_status);
4514 /* TODO: Since change commit sequence can have a huge impact,
4515 * we decided to only enable it for DCN3x. However, as soon as
4516 * we get more confident about this change we'll need to enable
4517 * the new sequence for all ASICs.
4519 if (dc->ctx->dce_version >= DCN_VERSION_3_2) {
4521 * Previous frame finished and HW is ready for optimization.
4523 if (update_type == UPDATE_TYPE_FAST)
4524 dc_post_update_surfaces_to_stream(dc);
4526 dc_update_planes_and_stream(dc, srf_updates,
4527 surface_count, stream,
4532 if (update_type >= update_surface_trace_level)
4533 update_surface_trace(dc, srf_updates, surface_count);
4536 if (update_type >= UPDATE_TYPE_FULL) {
4538 /* initialize scratch memory for building context */
4539 context = dc_state_create_copy(state);
4540 if (context == NULL) {
4541 DC_ERROR("Failed to allocate new validate context!\n");
4545 for (i = 0; i < dc->res_pool->pipe_count; i++) {
4546 struct pipe_ctx *new_pipe = &context->res_ctx.pipe_ctx[i];
4547 struct pipe_ctx *old_pipe = &dc->current_state->res_ctx.pipe_ctx[i];
4549 if (new_pipe->plane_state && new_pipe->plane_state != old_pipe->plane_state)
4550 new_pipe->plane_state->force_full_update = true;
4552 } else if (update_type == UPDATE_TYPE_FAST) {
4554 * Previous frame finished and HW is ready for optimization.
4556 dc_post_update_surfaces_to_stream(dc);
4560 for (i = 0; i < surface_count; i++) {
4561 struct dc_plane_state *surface = srf_updates[i].surface;
4563 copy_surface_update_to_plane(surface, &srf_updates[i]);
4565 if (update_type >= UPDATE_TYPE_MED) {
4566 for (j = 0; j < dc->res_pool->pipe_count; j++) {
4567 struct pipe_ctx *pipe_ctx =
4568 &context->res_ctx.pipe_ctx[j];
4570 if (pipe_ctx->plane_state != surface)
4573 resource_build_scaling_params(pipe_ctx);
4578 copy_stream_update_to_stream(dc, context, stream, stream_update);
4580 if (update_type >= UPDATE_TYPE_FULL) {
4581 if (!dc->res_pool->funcs->validate_bandwidth(dc, context, false)) {
4582 DC_ERROR("Mode validation failed for stream update!\n");
4583 dc_state_release(context);
4588 TRACE_DC_PIPE_STATE(pipe_ctx, i, MAX_PIPES);
4590 update_seamless_boot_flags(dc, context, surface_count, stream);
4591 if (fast_update_only(dc, fast_update, srf_updates, surface_count, stream_update, stream) &&
4592 !dc->debug.enable_legacy_fast_update) {
4593 commit_planes_for_stream_fast(dc,
4601 commit_planes_for_stream(
4610 /*update current_State*/
4611 if (dc->current_state != context) {
4613 struct dc_state *old = dc->current_state;
4615 dc->current_state = context;
4616 dc_state_release(old);
4618 for (i = 0; i < dc->res_pool->pipe_count; i++) {
4619 struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[i];
4621 if (pipe_ctx->plane_state && pipe_ctx->stream == stream)
4622 pipe_ctx->plane_state->force_full_update = false;
4626 /* Legacy optimization path for DCE. */
4627 if (update_type >= UPDATE_TYPE_FULL && dc_ctx->dce_version < DCE_VERSION_MAX) {
4628 dc_post_update_surfaces_to_stream(dc);
4629 TRACE_DCE_CLOCK_STATE(&context->bw_ctx.bw.dce);
4636 uint8_t dc_get_current_stream_count(struct dc *dc)
4638 return dc->current_state->stream_count;
4641 struct dc_stream_state *dc_get_stream_at_index(struct dc *dc, uint8_t i)
4643 if (i < dc->current_state->stream_count)
4644 return dc->current_state->streams[i];
4648 enum dc_irq_source dc_interrupt_to_irq_source(
4653 return dal_irq_service_to_irq_source(dc->res_pool->irqs, src_id, ext_id);
4657 * dc_interrupt_set() - Enable/disable an AMD hw interrupt source
4659 bool dc_interrupt_set(struct dc *dc, enum dc_irq_source src, bool enable)
4665 return dal_irq_service_set(dc->res_pool->irqs, src, enable);
4668 void dc_interrupt_ack(struct dc *dc, enum dc_irq_source src)
4670 dal_irq_service_ack(dc->res_pool->irqs, src);
4673 void dc_power_down_on_boot(struct dc *dc)
4675 if (dc->ctx->dce_environment != DCE_ENV_VIRTUAL_HW &&
4676 dc->hwss.power_down_on_boot)
4677 dc->hwss.power_down_on_boot(dc);
4680 void dc_set_power_state(
4682 enum dc_acpi_cm_power_state power_state)
4684 if (!dc->current_state)
4687 switch (power_state) {
4688 case DC_ACPI_CM_POWER_STATE_D0:
4689 dc_state_construct(dc, dc->current_state);
4693 dc->hwss.init_hw(dc);
4695 if (dc->hwss.init_sys_ctx != NULL &&
4696 dc->vm_pa_config.valid) {
4697 dc->hwss.init_sys_ctx(dc->hwseq, dc, &dc->vm_pa_config);
4702 ASSERT(dc->current_state->stream_count == 0);
4704 dc_state_destruct(dc->current_state);
4710 void dc_resume(struct dc *dc)
4714 for (i = 0; i < dc->link_count; i++)
4715 dc->link_srv->resume(dc->links[i]);
4718 bool dc_is_dmcu_initialized(struct dc *dc)
4720 struct dmcu *dmcu = dc->res_pool->dmcu;
4723 return dmcu->funcs->is_dmcu_initialized(dmcu);
4727 void get_clock_requirements_for_state(struct dc_state *state, struct AsicStateEx *info)
4729 info->displayClock = (unsigned int)state->bw_ctx.bw.dcn.clk.dispclk_khz;
4730 info->engineClock = (unsigned int)state->bw_ctx.bw.dcn.clk.dcfclk_khz;
4731 info->memoryClock = (unsigned int)state->bw_ctx.bw.dcn.clk.dramclk_khz;
4732 info->maxSupportedDppClock = (unsigned int)state->bw_ctx.bw.dcn.clk.max_supported_dppclk_khz;
4733 info->dppClock = (unsigned int)state->bw_ctx.bw.dcn.clk.dppclk_khz;
4734 info->socClock = (unsigned int)state->bw_ctx.bw.dcn.clk.socclk_khz;
4735 info->dcfClockDeepSleep = (unsigned int)state->bw_ctx.bw.dcn.clk.dcfclk_deep_sleep_khz;
4736 info->fClock = (unsigned int)state->bw_ctx.bw.dcn.clk.fclk_khz;
4737 info->phyClock = (unsigned int)state->bw_ctx.bw.dcn.clk.phyclk_khz;
4739 enum dc_status dc_set_clock(struct dc *dc, enum dc_clock_type clock_type, uint32_t clk_khz, uint32_t stepping)
4741 if (dc->hwss.set_clock)
4742 return dc->hwss.set_clock(dc, clock_type, clk_khz, stepping);
4743 return DC_ERROR_UNEXPECTED;
4745 void dc_get_clock(struct dc *dc, enum dc_clock_type clock_type, struct dc_clock_config *clock_cfg)
4747 if (dc->hwss.get_clock)
4748 dc->hwss.get_clock(dc, clock_type, clock_cfg);
4751 /* enable/disable eDP PSR without specify stream for eDP */
4752 bool dc_set_psr_allow_active(struct dc *dc, bool enable)
4757 for (i = 0; i < dc->current_state->stream_count ; i++) {
4758 struct dc_link *link;
4759 struct dc_stream_state *stream = dc->current_state->streams[i];
4761 link = stream->link;
4765 if (link->psr_settings.psr_feature_enabled) {
4766 if (enable && !link->psr_settings.psr_allow_active) {
4767 allow_active = true;
4768 if (!dc_link_set_psr_allow_active(link, &allow_active, false, false, NULL))
4770 } else if (!enable && link->psr_settings.psr_allow_active) {
4771 allow_active = false;
4772 if (!dc_link_set_psr_allow_active(link, &allow_active, true, false, NULL))
4781 /* enable/disable eDP Replay without specify stream for eDP */
4782 bool dc_set_replay_allow_active(struct dc *dc, bool active)
4787 for (i = 0; i < dc->current_state->stream_count; i++) {
4788 struct dc_link *link;
4789 struct dc_stream_state *stream = dc->current_state->streams[i];
4791 link = stream->link;
4795 if (link->replay_settings.replay_feature_enabled) {
4796 if (active && !link->replay_settings.replay_allow_active) {
4797 allow_active = true;
4798 if (!dc_link_set_replay_allow_active(link, &allow_active,
4799 false, false, NULL))
4801 } else if (!active && link->replay_settings.replay_allow_active) {
4802 allow_active = false;
4803 if (!dc_link_set_replay_allow_active(link, &allow_active,
4813 void dc_allow_idle_optimizations(struct dc *dc, bool allow)
4815 if (dc->debug.disable_idle_power_optimizations)
4818 if (dc->caps.ips_support && (dc->config.disable_ips == DMUB_IPS_DISABLE_ALL))
4821 if (dc->clk_mgr != NULL && dc->clk_mgr->funcs->is_smu_present)
4822 if (!dc->clk_mgr->funcs->is_smu_present(dc->clk_mgr))
4825 if (allow == dc->idle_optimizations_allowed)
4828 if (dc->hwss.apply_idle_power_optimizations && dc->hwss.apply_idle_power_optimizations(dc, allow))
4829 dc->idle_optimizations_allowed = allow;
4832 bool dc_dmub_is_ips_idle_state(struct dc *dc)
4834 uint32_t idle_state = 0;
4836 if (dc->debug.disable_idle_power_optimizations)
4839 if (!dc->caps.ips_support || (dc->config.disable_ips == DMUB_IPS_DISABLE_ALL))
4842 if (dc->hwss.get_idle_state)
4843 idle_state = dc->hwss.get_idle_state(dc);
4845 if (!(idle_state & DMUB_IPS1_ALLOW_MASK) ||
4846 !(idle_state & DMUB_IPS2_ALLOW_MASK))
4852 /* set min and max memory clock to lowest and highest DPM level, respectively */
4853 void dc_unlock_memory_clock_frequency(struct dc *dc)
4855 if (dc->clk_mgr->funcs->set_hard_min_memclk)
4856 dc->clk_mgr->funcs->set_hard_min_memclk(dc->clk_mgr, false);
4858 if (dc->clk_mgr->funcs->set_hard_max_memclk)
4859 dc->clk_mgr->funcs->set_hard_max_memclk(dc->clk_mgr);
4862 /* set min memory clock to the min required for current mode, max to maxDPM */
4863 void dc_lock_memory_clock_frequency(struct dc *dc)
4865 if (dc->clk_mgr->funcs->get_memclk_states_from_smu)
4866 dc->clk_mgr->funcs->get_memclk_states_from_smu(dc->clk_mgr);
4868 if (dc->clk_mgr->funcs->set_hard_min_memclk)
4869 dc->clk_mgr->funcs->set_hard_min_memclk(dc->clk_mgr, true);
4871 if (dc->clk_mgr->funcs->set_hard_max_memclk)
4872 dc->clk_mgr->funcs->set_hard_max_memclk(dc->clk_mgr);
4875 static void blank_and_force_memclk(struct dc *dc, bool apply, unsigned int memclk_mhz)
4877 struct dc_state *context = dc->current_state;
4879 struct pipe_ctx *pipe;
4882 for (i = 0; i < dc->res_pool->pipe_count; i++) {
4883 pipe = &context->res_ctx.pipe_ctx[i];
4885 if (pipe->stream != NULL) {
4886 dc->hwss.disable_pixel_data(dc, pipe, true);
4888 // wait for double buffer
4889 pipe->stream_res.tg->funcs->wait_for_state(pipe->stream_res.tg, CRTC_STATE_VACTIVE);
4890 pipe->stream_res.tg->funcs->wait_for_state(pipe->stream_res.tg, CRTC_STATE_VBLANK);
4891 pipe->stream_res.tg->funcs->wait_for_state(pipe->stream_res.tg, CRTC_STATE_VACTIVE);
4893 hubp = pipe->plane_res.hubp;
4894 hubp->funcs->set_blank_regs(hubp, true);
4898 dc->clk_mgr->funcs->set_max_memclk(dc->clk_mgr, memclk_mhz);
4899 dc->clk_mgr->funcs->set_min_memclk(dc->clk_mgr, memclk_mhz);
4901 for (i = 0; i < dc->res_pool->pipe_count; i++) {
4902 pipe = &context->res_ctx.pipe_ctx[i];
4904 if (pipe->stream != NULL) {
4905 dc->hwss.disable_pixel_data(dc, pipe, false);
4907 hubp = pipe->plane_res.hubp;
4908 hubp->funcs->set_blank_regs(hubp, false);
4915 * dc_enable_dcmode_clk_limit() - lower clocks in dc (battery) mode
4916 * @dc: pointer to dc of the dm calling this
4917 * @enable: True = transition to DC mode, false = transition back to AC mode
4919 * Some SoCs define additional clock limits when in DC mode, DM should
4920 * invoke this function when the platform undergoes a power source transition
4921 * so DC can apply/unapply the limit. This interface may be disruptive to
4922 * the onscreen content.
4924 * Context: Triggered by OS through DM interface, or manually by escape calls.
4925 * Need to hold a dclock when doing so.
4927 * Return: none (void function)
4930 void dc_enable_dcmode_clk_limit(struct dc *dc, bool enable)
4932 unsigned int softMax = 0, maxDPM = 0, funcMin = 0, i;
4933 bool p_state_change_support;
4935 if (!dc->config.dc_mode_clk_limit_support)
4938 softMax = dc->clk_mgr->bw_params->dc_mode_softmax_memclk;
4939 for (i = 0; i < dc->clk_mgr->bw_params->clk_table.num_entries; i++) {
4940 if (dc->clk_mgr->bw_params->clk_table.entries[i].memclk_mhz > maxDPM)
4941 maxDPM = dc->clk_mgr->bw_params->clk_table.entries[i].memclk_mhz;
4943 funcMin = (dc->clk_mgr->clks.dramclk_khz + 999) / 1000;
4944 p_state_change_support = dc->clk_mgr->clks.p_state_change_support;
4946 if (enable && !dc->clk_mgr->dc_mode_softmax_enabled) {
4947 if (p_state_change_support) {
4948 if (funcMin <= softMax)
4949 dc->clk_mgr->funcs->set_max_memclk(dc->clk_mgr, softMax);
4952 if (funcMin <= softMax)
4953 blank_and_force_memclk(dc, true, softMax);
4956 } else if (!enable && dc->clk_mgr->dc_mode_softmax_enabled) {
4957 if (p_state_change_support) {
4958 if (funcMin <= softMax)
4959 dc->clk_mgr->funcs->set_max_memclk(dc->clk_mgr, maxDPM);
4962 if (funcMin <= softMax)
4963 blank_and_force_memclk(dc, true, maxDPM);
4967 dc->clk_mgr->dc_mode_softmax_enabled = enable;
4969 bool dc_is_plane_eligible_for_idle_optimizations(struct dc *dc, struct dc_plane_state *plane,
4970 struct dc_cursor_attributes *cursor_attr)
4972 if (dc->hwss.does_plane_fit_in_mall && dc->hwss.does_plane_fit_in_mall(dc, plane, cursor_attr))
4977 /* cleanup on driver unload */
4978 void dc_hardware_release(struct dc *dc)
4980 dc_mclk_switch_using_fw_based_vblank_stretch_shut_down(dc);
4982 if (dc->hwss.hardware_release)
4983 dc->hwss.hardware_release(dc);
4986 void dc_mclk_switch_using_fw_based_vblank_stretch_shut_down(struct dc *dc)
4988 if (dc->current_state)
4989 dc->current_state->bw_ctx.bw.dcn.clk.fw_based_mclk_switching_shut_down = true;
4993 * dc_is_dmub_outbox_supported - Check if DMUB firmware support outbox notification
4995 * @dc: [in] dc structure
4997 * Checks whether DMUB FW supports outbox notifications, if supported DM
4998 * should register outbox interrupt prior to actually enabling interrupts
4999 * via dc_enable_dmub_outbox
5002 * True if DMUB FW supports outbox notifications, False otherwise
5004 bool dc_is_dmub_outbox_supported(struct dc *dc)
5006 switch (dc->ctx->asic_id.chip_family) {
5008 case FAMILY_YELLOW_CARP:
5009 /* DCN31 B0 USB4 DPIA needs dmub notifications for interrupts */
5010 if (dc->ctx->asic_id.hw_internal_rev == YELLOW_CARP_B0 &&
5011 !dc->debug.dpia_debug.bits.disable_dpia)
5015 case AMDGPU_FAMILY_GC_11_0_1:
5016 case AMDGPU_FAMILY_GC_11_5_0:
5017 if (!dc->debug.dpia_debug.bits.disable_dpia)
5025 /* dmub aux needs dmub notifications to be enabled */
5026 return dc->debug.enable_dmub_aux_for_legacy_ddc;
5031 * dc_enable_dmub_notifications - Check if dmub fw supports outbox
5033 * @dc: [in] dc structure
5035 * Calls dc_is_dmub_outbox_supported to check if dmub fw supports outbox
5036 * notifications. All DMs shall switch to dc_is_dmub_outbox_supported. This
5037 * API shall be removed after switching.
5040 * True if DMUB FW supports outbox notifications, False otherwise
5042 bool dc_enable_dmub_notifications(struct dc *dc)
5044 return dc_is_dmub_outbox_supported(dc);
5048 * dc_enable_dmub_outbox - Enables DMUB unsolicited notification
5050 * @dc: [in] dc structure
5052 * Enables DMUB unsolicited notifications to x86 via outbox.
5054 void dc_enable_dmub_outbox(struct dc *dc)
5056 struct dc_context *dc_ctx = dc->ctx;
5058 dmub_enable_outbox_notification(dc_ctx->dmub_srv);
5059 DC_LOG_DC("%s: dmub outbox notifications enabled\n", __func__);
5063 * dc_process_dmub_aux_transfer_async - Submits aux command to dmub via inbox message
5064 * Sets port index appropriately for legacy DDC
5066 * @link_index: link index
5067 * @payload: aux payload
5069 * Returns: True if successful, False if failure
5071 bool dc_process_dmub_aux_transfer_async(struct dc *dc,
5072 uint32_t link_index,
5073 struct aux_payload *payload)
5076 union dmub_rb_cmd cmd = {0};
5078 ASSERT(payload->length <= 16);
5080 cmd.dp_aux_access.header.type = DMUB_CMD__DP_AUX_ACCESS;
5081 cmd.dp_aux_access.header.payload_bytes = 0;
5082 /* For dpia, ddc_pin is set to NULL */
5083 if (!dc->links[link_index]->ddc->ddc_pin)
5084 cmd.dp_aux_access.aux_control.type = AUX_CHANNEL_DPIA;
5086 cmd.dp_aux_access.aux_control.type = AUX_CHANNEL_LEGACY_DDC;
5088 cmd.dp_aux_access.aux_control.instance = dc->links[link_index]->ddc_hw_inst;
5089 cmd.dp_aux_access.aux_control.sw_crc_enabled = 0;
5090 cmd.dp_aux_access.aux_control.timeout = 0;
5091 cmd.dp_aux_access.aux_control.dpaux.address = payload->address;
5092 cmd.dp_aux_access.aux_control.dpaux.is_i2c_over_aux = payload->i2c_over_aux;
5093 cmd.dp_aux_access.aux_control.dpaux.length = payload->length;
5095 /* set aux action */
5096 if (payload->i2c_over_aux) {
5097 if (payload->write) {
5099 action = DP_AUX_REQ_ACTION_I2C_WRITE_MOT;
5101 action = DP_AUX_REQ_ACTION_I2C_WRITE;
5104 action = DP_AUX_REQ_ACTION_I2C_READ_MOT;
5106 action = DP_AUX_REQ_ACTION_I2C_READ;
5110 action = DP_AUX_REQ_ACTION_DPCD_WRITE;
5112 action = DP_AUX_REQ_ACTION_DPCD_READ;
5115 cmd.dp_aux_access.aux_control.dpaux.action = action;
5117 if (payload->length && payload->write) {
5118 memcpy(cmd.dp_aux_access.aux_control.dpaux.data,
5124 dc_wake_and_execute_dmub_cmd(dc->ctx, &cmd, DM_DMUB_WAIT_TYPE_WAIT);
5129 uint8_t get_link_index_from_dpia_port_index(const struct dc *dc,
5130 uint8_t dpia_port_index)
5132 uint8_t index, link_index = 0xFF;
5134 for (index = 0; index < dc->link_count; index++) {
5135 /* ddc_hw_inst has dpia port index for dpia links
5136 * and ddc instance for legacy links
5138 if (!dc->links[index]->ddc->ddc_pin) {
5139 if (dc->links[index]->ddc_hw_inst == dpia_port_index) {
5145 ASSERT(link_index != 0xFF);
5150 * dc_process_dmub_set_config_async - Submits set_config command
5152 * @dc: [in] dc structure
5153 * @link_index: [in] link_index: link index
5154 * @payload: [in] aux payload
5155 * @notify: [out] set_config immediate reply
5157 * Submits set_config command to dmub via inbox message.
5160 * True if successful, False if failure
5162 bool dc_process_dmub_set_config_async(struct dc *dc,
5163 uint32_t link_index,
5164 struct set_config_cmd_payload *payload,
5165 struct dmub_notification *notify)
5167 union dmub_rb_cmd cmd = {0};
5168 bool is_cmd_complete = true;
5170 /* prepare SET_CONFIG command */
5171 cmd.set_config_access.header.type = DMUB_CMD__DPIA;
5172 cmd.set_config_access.header.sub_type = DMUB_CMD__DPIA_SET_CONFIG_ACCESS;
5174 cmd.set_config_access.set_config_control.instance = dc->links[link_index]->ddc_hw_inst;
5175 cmd.set_config_access.set_config_control.cmd_pkt.msg_type = payload->msg_type;
5176 cmd.set_config_access.set_config_control.cmd_pkt.msg_data = payload->msg_data;
5178 if (!dc_wake_and_execute_dmub_cmd(dc->ctx, &cmd, DM_DMUB_WAIT_TYPE_WAIT_WITH_REPLY)) {
5179 /* command is not processed by dmub */
5180 notify->sc_status = SET_CONFIG_UNKNOWN_ERROR;
5181 return is_cmd_complete;
5184 /* command processed by dmub, if ret_status is 1, it is completed instantly */
5185 if (cmd.set_config_access.header.ret_status == 1)
5186 notify->sc_status = cmd.set_config_access.set_config_control.immed_status;
5188 /* cmd pending, will receive notification via outbox */
5189 is_cmd_complete = false;
5191 return is_cmd_complete;
5195 * dc_process_dmub_set_mst_slots - Submits MST solt allocation
5197 * @dc: [in] dc structure
5198 * @link_index: [in] link index
5199 * @mst_alloc_slots: [in] mst slots to be allotted
5200 * @mst_slots_in_use: [out] mst slots in use returned in failure case
5202 * Submits mst slot allocation command to dmub via inbox message
5205 * DC_OK if successful, DC_ERROR if failure
5207 enum dc_status dc_process_dmub_set_mst_slots(const struct dc *dc,
5208 uint32_t link_index,
5209 uint8_t mst_alloc_slots,
5210 uint8_t *mst_slots_in_use)
5212 union dmub_rb_cmd cmd = {0};
5214 /* prepare MST_ALLOC_SLOTS command */
5215 cmd.set_mst_alloc_slots.header.type = DMUB_CMD__DPIA;
5216 cmd.set_mst_alloc_slots.header.sub_type = DMUB_CMD__DPIA_MST_ALLOC_SLOTS;
5218 cmd.set_mst_alloc_slots.mst_slots_control.instance = dc->links[link_index]->ddc_hw_inst;
5219 cmd.set_mst_alloc_slots.mst_slots_control.mst_alloc_slots = mst_alloc_slots;
5221 if (!dc_wake_and_execute_dmub_cmd(dc->ctx, &cmd, DM_DMUB_WAIT_TYPE_WAIT_WITH_REPLY))
5222 /* command is not processed by dmub */
5223 return DC_ERROR_UNEXPECTED;
5225 /* command processed by dmub, if ret_status is 1 */
5226 if (cmd.set_config_access.header.ret_status != 1)
5227 /* command processing error */
5228 return DC_ERROR_UNEXPECTED;
5230 /* command processed and we have a status of 2, mst not enabled in dpia */
5231 if (cmd.set_mst_alloc_slots.mst_slots_control.immed_status == 2)
5232 return DC_FAIL_UNSUPPORTED_1;
5234 /* previously configured mst alloc and used slots did not match */
5235 if (cmd.set_mst_alloc_slots.mst_slots_control.immed_status == 3) {
5236 *mst_slots_in_use = cmd.set_mst_alloc_slots.mst_slots_control.mst_slots_in_use;
5237 return DC_NOT_SUPPORTED;
5244 * dc_process_dmub_dpia_hpd_int_enable - Submits DPIA DPD interruption
5246 * @dc: [in] dc structure
5247 * @hpd_int_enable: [in] 1 for hpd int enable, 0 to disable
5249 * Submits dpia hpd int enable command to dmub via inbox message
5251 void dc_process_dmub_dpia_hpd_int_enable(const struct dc *dc,
5252 uint32_t hpd_int_enable)
5254 union dmub_rb_cmd cmd = {0};
5256 cmd.dpia_hpd_int_enable.header.type = DMUB_CMD__DPIA_HPD_INT_ENABLE;
5257 cmd.dpia_hpd_int_enable.enable = hpd_int_enable;
5259 dc_wake_and_execute_dmub_cmd(dc->ctx, &cmd, DM_DMUB_WAIT_TYPE_WAIT);
5261 DC_LOG_DEBUG("%s: hpd_int_enable(%d)\n", __func__, hpd_int_enable);
5265 * dc_print_dmub_diagnostic_data - Print DMUB diagnostic data for debugging
5267 * @dc: [in] dc structure
5271 void dc_print_dmub_diagnostic_data(const struct dc *dc)
5273 dc_dmub_srv_log_diagnostic_data(dc->ctx->dmub_srv);
5277 * dc_disable_accelerated_mode - disable accelerated mode
5280 void dc_disable_accelerated_mode(struct dc *dc)
5282 bios_set_scratch_acc_mode_change(dc->ctx->dc_bios, 0);
5287 * dc_notify_vsync_int_state - notifies vsync enable/disable state
5289 * @stream: stream where vsync int state changed
5290 * @enable: whether vsync is enabled or disabled
5292 * Called when vsync is enabled/disabled Will notify DMUB to start/stop ABM
5293 * interrupts after steady state is reached.
5295 void dc_notify_vsync_int_state(struct dc *dc, struct dc_stream_state *stream, bool enable)
5299 struct pipe_ctx *pipe = NULL;
5300 struct dc_link *link = stream->sink->link;
5301 struct dc_link *edp_links[MAX_NUM_EDP];
5304 if (link->psr_settings.psr_feature_enabled)
5307 if (link->replay_settings.replay_feature_enabled)
5310 /*find primary pipe associated with stream*/
5311 for (i = 0; i < MAX_PIPES; i++) {
5312 pipe = &dc->current_state->res_ctx.pipe_ctx[i];
5314 if (pipe->stream == stream && pipe->stream_res.tg)
5318 if (i == MAX_PIPES) {
5323 dc_get_edp_links(dc, edp_links, &edp_num);
5325 /* Determine panel inst */
5326 for (i = 0; i < edp_num; i++) {
5327 if (edp_links[i] == link)
5335 if (pipe->stream_res.abm && pipe->stream_res.abm->funcs->set_abm_pause)
5336 pipe->stream_res.abm->funcs->set_abm_pause(pipe->stream_res.abm, !enable, i, pipe->stream_res.tg->inst);
5339 /*****************************************************************************
5340 * dc_abm_save_restore() - Interface to DC for save+pause and restore+un-pause
5343 * @stream: stream where vsync int state changed
5344 * @pData: abm hw states
5346 ****************************************************************************/
5347 bool dc_abm_save_restore(
5349 struct dc_stream_state *stream,
5350 struct abm_save_restore *pData)
5354 struct pipe_ctx *pipe = NULL;
5355 struct dc_link *link = stream->sink->link;
5356 struct dc_link *edp_links[MAX_NUM_EDP];
5358 if (link->replay_settings.replay_feature_enabled)
5361 /*find primary pipe associated with stream*/
5362 for (i = 0; i < MAX_PIPES; i++) {
5363 pipe = &dc->current_state->res_ctx.pipe_ctx[i];
5365 if (pipe->stream == stream && pipe->stream_res.tg)
5369 if (i == MAX_PIPES) {
5374 dc_get_edp_links(dc, edp_links, &edp_num);
5376 /* Determine panel inst */
5377 for (i = 0; i < edp_num; i++)
5378 if (edp_links[i] == link)
5384 if (pipe->stream_res.abm &&
5385 pipe->stream_res.abm->funcs->save_restore)
5386 return pipe->stream_res.abm->funcs->save_restore(
5387 pipe->stream_res.abm,
5393 void dc_query_current_properties(struct dc *dc, struct dc_current_properties *properties)
5396 bool subvp_sw_cursor_req = false;
5398 for (i = 0; i < dc->current_state->stream_count; i++) {
5399 if (check_subvp_sw_cursor_fallback_req(dc, dc->current_state->streams[i])) {
5400 subvp_sw_cursor_req = true;
5404 properties->cursor_size_limit = subvp_sw_cursor_req ? 64 : dc->caps.max_cursor_size;
5408 * dc_set_edp_power() - DM controls eDP power to be ON/OFF
5410 * Called when DM wants to power on/off eDP.
5411 * Only work on links with flag skip_implict_edp_power_control is set.
5413 * @dc: Current DC state
5414 * @edp_link: a link with eDP connector signal type
5415 * @powerOn: power on/off eDP
5419 void dc_set_edp_power(const struct dc *dc, struct dc_link *edp_link,
5422 if (edp_link->connector_signal != SIGNAL_TYPE_EDP)
5425 if (edp_link->skip_implict_edp_power_control == false)
5428 edp_link->dc->link_srv->edp_set_panel_power(edp_link, powerOn);
5432 *****************************************************************************
5433 * dc_get_power_profile_for_dc_state() - extracts power profile from dc state
5435 * Called when DM wants to make power policy decisions based on dc_state
5437 *****************************************************************************
5439 struct dc_power_profile dc_get_power_profile_for_dc_state(const struct dc_state *context)
5441 struct dc_power_profile profile = { 0 };
5443 profile.power_level += !context->bw_ctx.bw.dcn.clk.p_state_change_support;