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"
39 #include "dc_plane_priv.h"
41 #include "gpio_service_interface.h"
43 #include "clock_source.h"
44 #include "dc_bios_types.h"
46 #include "bios_parser_interface.h"
47 #include "bios/bios_parser_helper.h"
48 #include "include/irq_service_interface.h"
49 #include "transform.h"
52 #include "timing_generator.h"
54 #include "virtual/virtual_link_encoder.h"
57 #include "link_hwss.h"
58 #include "link_encoder.h"
59 #include "link_enc_cfg.h"
62 #include "dm_helpers.h"
63 #include "mem_input.h"
65 #include "dc_dmub_srv.h"
69 #include "vm_helper.h"
71 #include "dce/dce_i2c.h"
73 #include "dmub/dmub_srv.h"
75 #include "dce/dmub_psr.h"
77 #include "dce/dmub_hw_lock_mgr.h"
81 #include "hw_sequencer_private.h"
83 #if defined(CONFIG_DRM_AMD_DC_FP)
84 #include "dml2/dml2_internal_types.h"
87 #include "dce/dmub_outbox.h"
95 static const char DC_BUILD_ID[] = "production-build";
100 * DC is the OS-agnostic component of the amdgpu DC driver.
102 * DC maintains and validates a set of structs representing the state of the
103 * driver and writes that state to AMD hardware
105 * Main DC HW structs:
107 * struct dc - The central struct. One per driver. Created on driver load,
108 * destroyed on driver unload.
110 * struct dc_context - One per driver.
111 * Used as a backpointer by most other structs in dc.
113 * struct dc_link - One per connector (the physical DP, HDMI, miniDP, or eDP
114 * plugpoints). Created on driver load, destroyed on driver unload.
116 * struct dc_sink - One per display. Created on boot or hotplug.
117 * Destroyed on shutdown or hotunplug. A dc_link can have a local sink
118 * (the display directly attached). It may also have one or more remote
119 * sinks (in the Multi-Stream Transport case)
121 * struct resource_pool - One per driver. Represents the hw blocks not in the
122 * main pipeline. Not directly accessible by dm.
124 * Main dc state structs:
126 * These structs can be created and destroyed as needed. There is a full set of
127 * these structs in dc->current_state representing the currently programmed state.
129 * struct dc_state - The global DC state to track global state information,
130 * such as bandwidth values.
132 * struct dc_stream_state - Represents the hw configuration for the pipeline from
133 * a framebuffer to a display. Maps one-to-one with dc_sink.
135 * struct dc_plane_state - Represents a framebuffer. Each stream has at least one,
136 * and may have more in the Multi-Plane Overlay case.
138 * struct resource_context - Represents the programmable state of everything in
139 * the resource_pool. Not directly accessible by dm.
141 * struct pipe_ctx - A member of struct resource_context. Represents the
142 * internal hardware pipeline components. Each dc_plane_state has either
143 * one or two (in the pipe-split case).
146 /* Private functions */
148 static inline void elevate_update_type(enum surface_update_type *original, enum surface_update_type new)
154 static void destroy_links(struct dc *dc)
158 for (i = 0; i < dc->link_count; i++) {
159 if (NULL != dc->links[i])
160 dc->link_srv->destroy_link(&dc->links[i]);
164 static uint32_t get_num_of_internal_disp(struct dc_link **links, uint32_t num_links)
169 for (i = 0; i < num_links; i++) {
170 if (links[i]->connector_signal == SIGNAL_TYPE_EDP ||
171 links[i]->is_internal_display)
178 static int get_seamless_boot_stream_count(struct dc_state *ctx)
181 uint8_t seamless_boot_stream_count = 0;
183 for (i = 0; i < ctx->stream_count; i++)
184 if (ctx->streams[i]->apply_seamless_boot_optimization)
185 seamless_boot_stream_count++;
187 return seamless_boot_stream_count;
190 static bool create_links(
192 uint32_t num_virtual_links)
196 struct dc_bios *bios = dc->ctx->dc_bios;
200 connectors_num = bios->funcs->get_connectors_number(bios);
202 DC_LOG_DC("BIOS object table - number of connectors: %d", connectors_num);
204 if (connectors_num > ENUM_ID_COUNT) {
206 "DC: Number of connectors %d exceeds maximum of %d!\n",
212 dm_output_to_console(
213 "DC: %s: connectors_num: physical:%d, virtual:%d\n",
218 // condition loop on link_count to allow skipping invalid indices
219 for (i = 0; dc->link_count < connectors_num && i < MAX_LINKS; i++) {
220 struct link_init_data link_init_params = {0};
221 struct dc_link *link;
223 DC_LOG_DC("BIOS object table - printing link object info for connector number: %d, link_index: %d", i, dc->link_count);
225 link_init_params.ctx = dc->ctx;
226 /* next BIOS object table connector */
227 link_init_params.connector_index = i;
228 link_init_params.link_index = dc->link_count;
229 link_init_params.dc = dc;
230 link = dc->link_srv->create_link(&link_init_params);
233 dc->links[dc->link_count] = link;
239 DC_LOG_DC("BIOS object table - end");
241 /* Create a link for each usb4 dpia port */
242 for (i = 0; i < dc->res_pool->usb4_dpia_count; i++) {
243 struct link_init_data link_init_params = {0};
244 struct dc_link *link;
246 link_init_params.ctx = dc->ctx;
247 link_init_params.connector_index = i;
248 link_init_params.link_index = dc->link_count;
249 link_init_params.dc = dc;
250 link_init_params.is_dpia_link = true;
252 link = dc->link_srv->create_link(&link_init_params);
254 dc->links[dc->link_count] = link;
260 for (i = 0; i < num_virtual_links; i++) {
261 struct dc_link *link = kzalloc(sizeof(*link), GFP_KERNEL);
262 struct encoder_init_data enc_init = {0};
269 link->link_index = dc->link_count;
270 dc->links[dc->link_count] = link;
275 link->connector_signal = SIGNAL_TYPE_VIRTUAL;
276 link->link_id.type = OBJECT_TYPE_CONNECTOR;
277 link->link_id.id = CONNECTOR_ID_VIRTUAL;
278 link->link_id.enum_id = ENUM_ID_1;
279 link->link_enc = kzalloc(sizeof(*link->link_enc), GFP_KERNEL);
281 if (!link->link_enc) {
286 link->link_status.dpcd_caps = &link->dpcd_caps;
288 enc_init.ctx = dc->ctx;
289 enc_init.channel = CHANNEL_ID_UNKNOWN;
290 enc_init.hpd_source = HPD_SOURCEID_UNKNOWN;
291 enc_init.transmitter = TRANSMITTER_UNKNOWN;
292 enc_init.connector = link->link_id;
293 enc_init.encoder.type = OBJECT_TYPE_ENCODER;
294 enc_init.encoder.id = ENCODER_ID_INTERNAL_VIRTUAL;
295 enc_init.encoder.enum_id = ENUM_ID_1;
296 virtual_link_encoder_construct(link->link_enc, &enc_init);
299 dc->caps.num_of_internal_disp = get_num_of_internal_disp(dc->links, dc->link_count);
307 /* Create additional DIG link encoder objects if fewer than the platform
308 * supports were created during link construction. This can happen if the
309 * number of physical connectors is less than the number of DIGs.
311 static bool create_link_encoders(struct dc *dc)
314 unsigned int num_usb4_dpia = dc->res_pool->res_cap->num_usb4_dpia;
315 unsigned int num_dig_link_enc = dc->res_pool->res_cap->num_dig_link_enc;
318 /* A platform without USB4 DPIA endpoints has a fixed mapping between DIG
319 * link encoders and physical display endpoints and does not require
320 * additional link encoder objects.
322 if (num_usb4_dpia == 0)
325 /* Create as many link encoder objects as the platform supports. DPIA
326 * endpoints can be programmably mapped to any DIG.
328 if (num_dig_link_enc > dc->res_pool->dig_link_enc_count) {
329 for (i = 0; i < num_dig_link_enc; i++) {
330 struct link_encoder *link_enc = dc->res_pool->link_encoders[i];
332 if (!link_enc && dc->res_pool->funcs->link_enc_create_minimal) {
333 link_enc = dc->res_pool->funcs->link_enc_create_minimal(dc->ctx,
334 (enum engine_id)(ENGINE_ID_DIGA + i));
336 dc->res_pool->link_encoders[i] = link_enc;
337 dc->res_pool->dig_link_enc_count++;
348 /* Destroy any additional DIG link encoder objects created by
349 * create_link_encoders().
350 * NB: Must only be called after destroy_links().
352 static void destroy_link_encoders(struct dc *dc)
354 unsigned int num_usb4_dpia;
355 unsigned int num_dig_link_enc;
361 num_usb4_dpia = dc->res_pool->res_cap->num_usb4_dpia;
362 num_dig_link_enc = dc->res_pool->res_cap->num_dig_link_enc;
364 /* A platform without USB4 DPIA endpoints has a fixed mapping between DIG
365 * link encoders and physical display endpoints and does not require
366 * additional link encoder objects.
368 if (num_usb4_dpia == 0)
371 for (i = 0; i < num_dig_link_enc; i++) {
372 struct link_encoder *link_enc = dc->res_pool->link_encoders[i];
375 link_enc->funcs->destroy(&link_enc);
376 dc->res_pool->link_encoders[i] = NULL;
377 dc->res_pool->dig_link_enc_count--;
382 static struct dc_perf_trace *dc_perf_trace_create(void)
384 return kzalloc(sizeof(struct dc_perf_trace), GFP_KERNEL);
387 static void dc_perf_trace_destroy(struct dc_perf_trace **perf_trace)
393 static bool set_long_vtotal(struct dc *dc, struct dc_stream_state *stream, struct dc_crtc_timing_adjust *adjust)
395 if (!dc || !stream || !adjust)
398 if (!dc->current_state)
403 for (i = 0; i < MAX_PIPES; i++) {
404 struct pipe_ctx *pipe = &dc->current_state->res_ctx.pipe_ctx[i];
406 if (pipe->stream == stream && pipe->stream_res.tg) {
407 if (dc->hwss.set_long_vtotal)
408 dc->hwss.set_long_vtotal(&pipe, 1, adjust->v_total_min, adjust->v_total_max);
418 * dc_stream_adjust_vmin_vmax - look up pipe context & update parts of DRR
420 * @stream: Initial dc stream state
421 * @adjust: Updated parameters for vertical_total_min and vertical_total_max
423 * Looks up the pipe context of dc_stream_state and updates the
424 * vertical_total_min and vertical_total_max of the DRR, Dynamic Refresh
425 * Rate, which is a power-saving feature that targets reducing panel
426 * refresh rate while the screen is static
428 * Return: %true if the pipe context is found and adjusted;
429 * %false if the pipe context is not found.
431 bool dc_stream_adjust_vmin_vmax(struct dc *dc,
432 struct dc_stream_state *stream,
433 struct dc_crtc_timing_adjust *adjust)
438 * Don't adjust DRR while there's bandwidth optimizations pending to
439 * avoid conflicting with firmware updates.
441 if (dc->ctx->dce_version > DCE_VERSION_MAX)
442 if (dc->optimized_required || dc->wm_optimized_required)
445 dc_exit_ips_for_hw_access(dc);
447 stream->adjust.v_total_max = adjust->v_total_max;
448 stream->adjust.v_total_mid = adjust->v_total_mid;
449 stream->adjust.v_total_mid_frame_num = adjust->v_total_mid_frame_num;
450 stream->adjust.v_total_min = adjust->v_total_min;
451 stream->adjust.allow_otg_v_count_halt = adjust->allow_otg_v_count_halt;
453 if (dc->caps.max_v_total != 0 &&
454 (adjust->v_total_max > dc->caps.max_v_total || adjust->v_total_min > dc->caps.max_v_total)) {
455 if (adjust->allow_otg_v_count_halt)
456 return set_long_vtotal(dc, stream, adjust);
461 for (i = 0; i < MAX_PIPES; i++) {
462 struct pipe_ctx *pipe = &dc->current_state->res_ctx.pipe_ctx[i];
464 if (pipe->stream == stream && pipe->stream_res.tg) {
465 dc->hwss.set_drr(&pipe,
476 * dc_stream_get_last_used_drr_vtotal - Looks up the pipe context of
477 * dc_stream_state and gets the last VTOTAL used by DRR (Dynamic Refresh Rate)
479 * @dc: [in] dc reference
480 * @stream: [in] Initial dc stream state
481 * @refresh_rate: [in] new refresh_rate
483 * Return: %true if the pipe context is found and there is an associated
484 * timing_generator for the DC;
485 * %false if the pipe context is not found or there is no
486 * timing_generator for the DC.
488 bool dc_stream_get_last_used_drr_vtotal(struct dc *dc,
489 struct dc_stream_state *stream,
490 uint32_t *refresh_rate)
496 dc_exit_ips_for_hw_access(dc);
498 for (i = 0; i < MAX_PIPES; i++) {
499 struct pipe_ctx *pipe = &dc->current_state->res_ctx.pipe_ctx[i];
501 if (pipe->stream == stream && pipe->stream_res.tg) {
502 /* Only execute if a function pointer has been defined for
503 * the DC version in question
505 if (pipe->stream_res.tg->funcs->get_last_used_drr_vtotal) {
506 pipe->stream_res.tg->funcs->get_last_used_drr_vtotal(pipe->stream_res.tg, refresh_rate);
518 bool dc_stream_get_crtc_position(struct dc *dc,
519 struct dc_stream_state **streams, int num_streams,
520 unsigned int *v_pos, unsigned int *nom_v_pos)
522 /* TODO: Support multiple streams */
523 const struct dc_stream_state *stream = streams[0];
526 struct crtc_position position;
528 dc_exit_ips_for_hw_access(dc);
530 for (i = 0; i < MAX_PIPES; i++) {
531 struct pipe_ctx *pipe =
532 &dc->current_state->res_ctx.pipe_ctx[i];
534 if (pipe->stream == stream && pipe->stream_res.stream_enc) {
535 dc->hwss.get_position(&pipe, 1, &position);
537 *v_pos = position.vertical_count;
538 *nom_v_pos = position.nominal_vcount;
545 #if defined(CONFIG_DRM_AMD_SECURE_DISPLAY)
547 dc_stream_forward_dmub_crc_window(struct dc_dmub_srv *dmub_srv,
548 struct rect *rect, struct otg_phy_mux *mux_mapping, bool is_stop)
550 union dmub_rb_cmd cmd = {0};
552 cmd.secure_display.roi_info.phy_id = mux_mapping->phy_output_num;
553 cmd.secure_display.roi_info.otg_id = mux_mapping->otg_output_num;
556 cmd.secure_display.header.type = DMUB_CMD__SECURE_DISPLAY;
557 cmd.secure_display.header.sub_type = DMUB_CMD__SECURE_DISPLAY_CRC_STOP_UPDATE;
559 cmd.secure_display.header.type = DMUB_CMD__SECURE_DISPLAY;
560 cmd.secure_display.header.sub_type = DMUB_CMD__SECURE_DISPLAY_CRC_WIN_NOTIFY;
561 cmd.secure_display.roi_info.x_start = rect->x;
562 cmd.secure_display.roi_info.y_start = rect->y;
563 cmd.secure_display.roi_info.x_end = rect->x + rect->width;
564 cmd.secure_display.roi_info.y_end = rect->y + rect->height;
567 dc_wake_and_execute_dmub_cmd(dmub_srv->ctx, &cmd, DM_DMUB_WAIT_TYPE_NO_WAIT);
571 dc_stream_forward_dmcu_crc_window(struct dmcu *dmcu,
572 struct rect *rect, struct otg_phy_mux *mux_mapping, bool is_stop)
575 dmcu->funcs->stop_crc_win_update(dmcu, mux_mapping);
577 dmcu->funcs->forward_crc_window(dmcu, rect, mux_mapping);
581 dc_stream_forward_crc_window(struct dc_stream_state *stream,
582 struct rect *rect, bool is_stop)
585 struct dc_dmub_srv *dmub_srv;
586 struct otg_phy_mux mux_mapping;
587 struct pipe_ctx *pipe;
589 struct dc *dc = stream->ctx->dc;
591 for (i = 0; i < MAX_PIPES; i++) {
592 pipe = &dc->current_state->res_ctx.pipe_ctx[i];
593 if (pipe->stream == stream && !pipe->top_pipe && !pipe->prev_odm_pipe)
597 /* Stream not found */
601 mux_mapping.phy_output_num = stream->link->link_enc_hw_inst;
602 mux_mapping.otg_output_num = pipe->stream_res.tg->inst;
604 dmcu = dc->res_pool->dmcu;
605 dmub_srv = dc->ctx->dmub_srv;
607 /* forward to dmub */
609 dc_stream_forward_dmub_crc_window(dmub_srv, rect, &mux_mapping, is_stop);
610 /* forward to dmcu */
611 else if (dmcu && dmcu->funcs->is_dmcu_initialized(dmcu))
612 dc_stream_forward_dmcu_crc_window(dmcu, rect, &mux_mapping, is_stop);
618 #endif /* CONFIG_DRM_AMD_SECURE_DISPLAY */
621 * dc_stream_configure_crc() - Configure CRC capture for the given stream.
623 * @stream: The stream to configure CRC on.
624 * @enable: Enable CRC if true, disable otherwise.
625 * @crc_window: CRC window (x/y start/end) information
626 * @continuous: Capture CRC on every frame if true. Otherwise, only capture
629 * By default, only CRC0 is configured, and the entire frame is used to
632 * Return: %false if the stream is not found or CRC capture is not supported;
633 * %true if the stream has been configured.
635 bool dc_stream_configure_crc(struct dc *dc, struct dc_stream_state *stream,
636 struct crc_params *crc_window, bool enable, bool continuous)
638 struct pipe_ctx *pipe;
639 struct crc_params param;
640 struct timing_generator *tg;
642 pipe = resource_get_otg_master_for_stream(
643 &dc->current_state->res_ctx, stream);
645 /* Stream not found */
649 dc_exit_ips_for_hw_access(dc);
651 /* By default, capture the full frame */
652 param.windowa_x_start = 0;
653 param.windowa_y_start = 0;
654 param.windowa_x_end = pipe->stream->timing.h_addressable;
655 param.windowa_y_end = pipe->stream->timing.v_addressable;
656 param.windowb_x_start = 0;
657 param.windowb_y_start = 0;
658 param.windowb_x_end = pipe->stream->timing.h_addressable;
659 param.windowb_y_end = pipe->stream->timing.v_addressable;
662 param.windowa_x_start = crc_window->windowa_x_start;
663 param.windowa_y_start = crc_window->windowa_y_start;
664 param.windowa_x_end = crc_window->windowa_x_end;
665 param.windowa_y_end = crc_window->windowa_y_end;
666 param.windowb_x_start = crc_window->windowb_x_start;
667 param.windowb_y_start = crc_window->windowb_y_start;
668 param.windowb_x_end = crc_window->windowb_x_end;
669 param.windowb_y_end = crc_window->windowb_y_end;
672 param.dsc_mode = pipe->stream->timing.flags.DSC ? 1:0;
673 param.odm_mode = pipe->next_odm_pipe ? 1:0;
675 /* Default to the union of both windows */
676 param.selection = UNION_WINDOW_A_B;
677 param.continuous_mode = continuous;
678 param.enable = enable;
680 tg = pipe->stream_res.tg;
682 /* Only call if supported */
683 if (tg->funcs->configure_crc)
684 return tg->funcs->configure_crc(tg, ¶m);
685 DC_LOG_WARNING("CRC capture not supported.");
690 * dc_stream_get_crc() - Get CRC values for the given stream.
693 * @stream: The DC stream state of the stream to get CRCs from.
694 * @r_cr: CRC value for the red component.
695 * @g_y: CRC value for the green component.
696 * @b_cb: CRC value for the blue component.
698 * dc_stream_configure_crc needs to be called beforehand to enable CRCs.
701 * %false if stream is not found, or if CRCs are not enabled.
703 bool dc_stream_get_crc(struct dc *dc, struct dc_stream_state *stream,
704 uint32_t *r_cr, uint32_t *g_y, uint32_t *b_cb)
707 struct pipe_ctx *pipe;
708 struct timing_generator *tg;
710 dc_exit_ips_for_hw_access(dc);
712 for (i = 0; i < MAX_PIPES; i++) {
713 pipe = &dc->current_state->res_ctx.pipe_ctx[i];
714 if (pipe->stream == stream)
717 /* Stream not found */
721 tg = pipe->stream_res.tg;
723 if (tg->funcs->get_crc)
724 return tg->funcs->get_crc(tg, r_cr, g_y, b_cb);
725 DC_LOG_WARNING("CRC capture not supported.");
729 void dc_stream_set_dyn_expansion(struct dc *dc, struct dc_stream_state *stream,
730 enum dc_dynamic_expansion option)
732 /* OPP FMT dyn expansion updates*/
734 struct pipe_ctx *pipe_ctx;
736 dc_exit_ips_for_hw_access(dc);
738 for (i = 0; i < MAX_PIPES; i++) {
739 if (dc->current_state->res_ctx.pipe_ctx[i].stream
741 pipe_ctx = &dc->current_state->res_ctx.pipe_ctx[i];
742 pipe_ctx->stream_res.opp->dyn_expansion = option;
743 pipe_ctx->stream_res.opp->funcs->opp_set_dyn_expansion(
744 pipe_ctx->stream_res.opp,
745 COLOR_SPACE_YCBCR601,
746 stream->timing.display_color_depth,
752 void dc_stream_set_dither_option(struct dc_stream_state *stream,
753 enum dc_dither_option option)
755 struct bit_depth_reduction_params params;
756 struct dc_link *link = stream->link;
757 struct pipe_ctx *pipes = NULL;
760 for (i = 0; i < MAX_PIPES; i++) {
761 if (link->dc->current_state->res_ctx.pipe_ctx[i].stream ==
763 pipes = &link->dc->current_state->res_ctx.pipe_ctx[i];
770 if (option > DITHER_OPTION_MAX)
773 dc_exit_ips_for_hw_access(stream->ctx->dc);
775 stream->dither_option = option;
777 memset(¶ms, 0, sizeof(params));
778 resource_build_bit_depth_reduction_params(stream, ¶ms);
779 stream->bit_depth_params = params;
781 if (pipes->plane_res.xfm &&
782 pipes->plane_res.xfm->funcs->transform_set_pixel_storage_depth) {
783 pipes->plane_res.xfm->funcs->transform_set_pixel_storage_depth(
784 pipes->plane_res.xfm,
785 pipes->plane_res.scl_data.lb_params.depth,
786 &stream->bit_depth_params);
789 pipes->stream_res.opp->funcs->
790 opp_program_bit_depth_reduction(pipes->stream_res.opp, ¶ms);
793 bool dc_stream_set_gamut_remap(struct dc *dc, const struct dc_stream_state *stream)
797 struct pipe_ctx *pipes;
799 dc_exit_ips_for_hw_access(dc);
801 for (i = 0; i < MAX_PIPES; i++) {
802 if (dc->current_state->res_ctx.pipe_ctx[i].stream == stream) {
803 pipes = &dc->current_state->res_ctx.pipe_ctx[i];
804 dc->hwss.program_gamut_remap(pipes);
812 bool dc_stream_program_csc_matrix(struct dc *dc, struct dc_stream_state *stream)
816 struct pipe_ctx *pipes;
818 dc_exit_ips_for_hw_access(dc);
820 for (i = 0; i < MAX_PIPES; i++) {
821 if (dc->current_state->res_ctx.pipe_ctx[i].stream
824 pipes = &dc->current_state->res_ctx.pipe_ctx[i];
825 dc->hwss.program_output_csc(dc,
827 stream->output_color_space,
828 stream->csc_color_matrix.matrix,
829 pipes->stream_res.opp->inst);
837 void dc_stream_set_static_screen_params(struct dc *dc,
838 struct dc_stream_state **streams,
840 const struct dc_static_screen_params *params)
843 struct pipe_ctx *pipes_affected[MAX_PIPES];
844 int num_pipes_affected = 0;
846 dc_exit_ips_for_hw_access(dc);
848 for (i = 0; i < num_streams; i++) {
849 struct dc_stream_state *stream = streams[i];
851 for (j = 0; j < MAX_PIPES; j++) {
852 if (dc->current_state->res_ctx.pipe_ctx[j].stream
854 pipes_affected[num_pipes_affected++] =
855 &dc->current_state->res_ctx.pipe_ctx[j];
860 dc->hwss.set_static_screen_control(pipes_affected, num_pipes_affected, params);
863 static void dc_destruct(struct dc *dc)
865 // reset link encoder assignment table on destruct
866 if (dc->res_pool && dc->res_pool->funcs->link_encs_assign)
867 link_enc_cfg_init(dc, dc->current_state);
869 if (dc->current_state) {
870 dc_state_release(dc->current_state);
871 dc->current_state = NULL;
876 destroy_link_encoders(dc);
879 dc_destroy_clk_mgr(dc->clk_mgr);
883 dc_destroy_resource_pool(dc);
886 link_destroy_link_service(&dc->link_srv);
888 if (dc->ctx->gpio_service)
889 dal_gpio_service_destroy(&dc->ctx->gpio_service);
891 if (dc->ctx->created_bios)
892 dal_bios_parser_destroy(&dc->ctx->dc_bios);
894 kfree(dc->ctx->logger);
895 dc_perf_trace_destroy(&dc->ctx->perf_trace);
912 kfree(dc->vm_helper);
913 dc->vm_helper = NULL;
917 static bool dc_construct_ctx(struct dc *dc,
918 const struct dc_init_data *init_params)
920 struct dc_context *dc_ctx;
922 dc_ctx = kzalloc(sizeof(*dc_ctx), GFP_KERNEL);
926 dc_ctx->cgs_device = init_params->cgs_device;
927 dc_ctx->driver_context = init_params->driver;
929 dc_ctx->asic_id = init_params->asic_id;
930 dc_ctx->dc_sink_id_count = 0;
931 dc_ctx->dc_stream_id_count = 0;
932 dc_ctx->dce_environment = init_params->dce_environment;
933 dc_ctx->dcn_reg_offsets = init_params->dcn_reg_offsets;
934 dc_ctx->nbio_reg_offsets = init_params->nbio_reg_offsets;
935 dc_ctx->clk_reg_offsets = init_params->clk_reg_offsets;
938 dc_ctx->logger = kmalloc(sizeof(*dc_ctx->logger), GFP_KERNEL);
940 if (!dc_ctx->logger) {
945 dc_ctx->logger->dev = adev_to_drm(init_params->driver);
946 dc->dml.logger = dc_ctx->logger;
948 dc_ctx->dce_version = resource_parse_asic_id(init_params->asic_id);
950 dc_ctx->perf_trace = dc_perf_trace_create();
951 if (!dc_ctx->perf_trace) {
953 ASSERT_CRITICAL(false);
959 dc->link_srv = link_create_link_service();
966 static bool dc_construct(struct dc *dc,
967 const struct dc_init_data *init_params)
969 struct dc_context *dc_ctx;
970 struct bw_calcs_dceip *dc_dceip;
971 struct bw_calcs_vbios *dc_vbios;
972 struct dcn_soc_bounding_box *dcn_soc;
973 struct dcn_ip_params *dcn_ip;
975 dc->config = init_params->flags;
977 // Allocate memory for the vm_helper
978 dc->vm_helper = kzalloc(sizeof(struct vm_helper), GFP_KERNEL);
979 if (!dc->vm_helper) {
980 dm_error("%s: failed to create dc->vm_helper\n", __func__);
984 memcpy(&dc->bb_overrides, &init_params->bb_overrides, sizeof(dc->bb_overrides));
986 dc_dceip = kzalloc(sizeof(*dc_dceip), GFP_KERNEL);
988 dm_error("%s: failed to create dceip\n", __func__);
992 dc->bw_dceip = dc_dceip;
994 dc_vbios = kzalloc(sizeof(*dc_vbios), GFP_KERNEL);
996 dm_error("%s: failed to create vbios\n", __func__);
1000 dc->bw_vbios = dc_vbios;
1001 dcn_soc = kzalloc(sizeof(*dcn_soc), GFP_KERNEL);
1003 dm_error("%s: failed to create dcn_soc\n", __func__);
1007 dc->dcn_soc = dcn_soc;
1009 dcn_ip = kzalloc(sizeof(*dcn_ip), GFP_KERNEL);
1011 dm_error("%s: failed to create dcn_ip\n", __func__);
1015 dc->dcn_ip = dcn_ip;
1017 if (init_params->bb_from_dmub)
1018 dc->dml2_options.bb_from_dmub = init_params->bb_from_dmub;
1020 dc->dml2_options.bb_from_dmub = NULL;
1022 if (!dc_construct_ctx(dc, init_params)) {
1023 dm_error("%s: failed to create ctx\n", __func__);
1029 /* Resource should construct all asic specific resources.
1030 * This should be the only place where we need to parse the asic id
1032 if (init_params->vbios_override)
1033 dc_ctx->dc_bios = init_params->vbios_override;
1035 /* Create BIOS parser */
1036 struct bp_init_data bp_init_data;
1038 bp_init_data.ctx = dc_ctx;
1039 bp_init_data.bios = init_params->asic_id.atombios_base_address;
1041 dc_ctx->dc_bios = dal_bios_parser_create(
1042 &bp_init_data, dc_ctx->dce_version);
1044 if (!dc_ctx->dc_bios) {
1045 ASSERT_CRITICAL(false);
1049 dc_ctx->created_bios = true;
1052 dc->vendor_signature = init_params->vendor_signature;
1054 /* Create GPIO service */
1055 dc_ctx->gpio_service = dal_gpio_service_create(
1056 dc_ctx->dce_version,
1057 dc_ctx->dce_environment,
1060 if (!dc_ctx->gpio_service) {
1061 ASSERT_CRITICAL(false);
1065 dc->res_pool = dc_create_resource_pool(dc, init_params, dc_ctx->dce_version);
1069 /* set i2c speed if not done by the respective dcnxxx__resource.c */
1070 if (dc->caps.i2c_speed_in_khz_hdcp == 0)
1071 dc->caps.i2c_speed_in_khz_hdcp = dc->caps.i2c_speed_in_khz;
1072 if (dc->caps.max_optimizable_video_width == 0)
1073 dc->caps.max_optimizable_video_width = 5120;
1074 dc->clk_mgr = dc_clk_mgr_create(dc->ctx, dc->res_pool->pp_smu, dc->res_pool->dccg);
1077 #ifdef CONFIG_DRM_AMD_DC_FP
1078 dc->clk_mgr->force_smu_not_present = init_params->force_smu_not_present;
1080 if (dc->res_pool->funcs->update_bw_bounding_box) {
1082 dc->res_pool->funcs->update_bw_bounding_box(dc, dc->clk_mgr->bw_params);
1087 if (!create_links(dc, init_params->num_virtual_links))
1090 /* Create additional DIG link encoder objects if fewer than the platform
1091 * supports were created during link construction.
1093 if (!create_link_encoders(dc))
1096 /* Creation of current_state must occur after dc->dml
1097 * is initialized in dc_create_resource_pool because
1098 * on creation it copies the contents of dc->dml
1100 dc->current_state = dc_state_create(dc, NULL);
1102 if (!dc->current_state) {
1103 dm_error("%s: failed to create validate ctx\n", __func__);
1113 static void disable_all_writeback_pipes_for_stream(
1114 const struct dc *dc,
1115 struct dc_stream_state *stream,
1116 struct dc_state *context)
1120 for (i = 0; i < stream->num_wb_info; i++)
1121 stream->writeback_info[i].wb_enabled = false;
1124 static void apply_ctx_interdependent_lock(struct dc *dc,
1125 struct dc_state *context,
1126 struct dc_stream_state *stream,
1131 /* Checks if interdependent update function pointer is NULL or not, takes care of DCE110 case */
1132 if (dc->hwss.interdependent_update_lock)
1133 dc->hwss.interdependent_update_lock(dc, context, lock);
1135 for (i = 0; i < dc->res_pool->pipe_count; i++) {
1136 struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[i];
1137 struct pipe_ctx *old_pipe_ctx = &dc->current_state->res_ctx.pipe_ctx[i];
1139 // Copied conditions that were previously in dce110_apply_ctx_for_surface
1140 if (stream == pipe_ctx->stream) {
1141 if (resource_is_pipe_type(pipe_ctx, OPP_HEAD) &&
1142 (pipe_ctx->plane_state || old_pipe_ctx->plane_state))
1143 dc->hwss.pipe_control_lock(dc, pipe_ctx, lock);
1149 static void dc_update_visual_confirm_color(struct dc *dc, struct dc_state *context, struct pipe_ctx *pipe_ctx)
1151 if (dc->ctx->dce_version >= DCN_VERSION_1_0) {
1152 memset(&pipe_ctx->visual_confirm_color, 0, sizeof(struct tg_color));
1154 if (dc->debug.visual_confirm == VISUAL_CONFIRM_HDR)
1155 get_hdr_visual_confirm_color(pipe_ctx, &(pipe_ctx->visual_confirm_color));
1156 else if (dc->debug.visual_confirm == VISUAL_CONFIRM_SURFACE)
1157 get_surface_visual_confirm_color(pipe_ctx, &(pipe_ctx->visual_confirm_color));
1158 else if (dc->debug.visual_confirm == VISUAL_CONFIRM_SWIZZLE)
1159 get_surface_tile_visual_confirm_color(pipe_ctx, &(pipe_ctx->visual_confirm_color));
1161 if (dc->ctx->dce_version < DCN_VERSION_2_0)
1162 color_space_to_black_color(
1163 dc, pipe_ctx->stream->output_color_space, &(pipe_ctx->visual_confirm_color));
1165 if (dc->ctx->dce_version >= DCN_VERSION_2_0) {
1166 if (dc->debug.visual_confirm == VISUAL_CONFIRM_MPCTREE)
1167 get_mpctree_visual_confirm_color(pipe_ctx, &(pipe_ctx->visual_confirm_color));
1168 else if (dc->debug.visual_confirm == VISUAL_CONFIRM_SUBVP)
1169 get_subvp_visual_confirm_color(pipe_ctx, &(pipe_ctx->visual_confirm_color));
1170 else if (dc->debug.visual_confirm == VISUAL_CONFIRM_MCLK_SWITCH)
1171 get_mclk_switch_visual_confirm_color(pipe_ctx, &(pipe_ctx->visual_confirm_color));
1172 else if (dc->debug.visual_confirm == VISUAL_CONFIRM_FAMS2)
1173 get_fams2_visual_confirm_color(dc, context, pipe_ctx, &(pipe_ctx->visual_confirm_color));
1178 static void disable_dangling_plane(struct dc *dc, struct dc_state *context)
1181 struct dc_state *dangling_context = dc_state_create_current_copy(dc);
1182 struct dc_state *current_ctx;
1183 struct pipe_ctx *pipe;
1184 struct timing_generator *tg;
1186 if (dangling_context == NULL)
1189 for (i = 0; i < dc->res_pool->pipe_count; i++) {
1190 struct dc_stream_state *old_stream =
1191 dc->current_state->res_ctx.pipe_ctx[i].stream;
1192 bool should_disable = true;
1193 bool pipe_split_change = false;
1195 if ((context->res_ctx.pipe_ctx[i].top_pipe) &&
1196 (dc->current_state->res_ctx.pipe_ctx[i].top_pipe))
1197 pipe_split_change = context->res_ctx.pipe_ctx[i].top_pipe->pipe_idx !=
1198 dc->current_state->res_ctx.pipe_ctx[i].top_pipe->pipe_idx;
1200 pipe_split_change = context->res_ctx.pipe_ctx[i].top_pipe !=
1201 dc->current_state->res_ctx.pipe_ctx[i].top_pipe;
1203 for (j = 0; j < context->stream_count; j++) {
1204 if (old_stream == context->streams[j]) {
1205 should_disable = false;
1209 if (!should_disable && pipe_split_change &&
1210 dc->current_state->stream_count != context->stream_count)
1211 should_disable = true;
1213 if (old_stream && !dc->current_state->res_ctx.pipe_ctx[i].top_pipe &&
1214 !dc->current_state->res_ctx.pipe_ctx[i].prev_odm_pipe) {
1215 struct pipe_ctx *old_pipe, *new_pipe;
1217 old_pipe = &dc->current_state->res_ctx.pipe_ctx[i];
1218 new_pipe = &context->res_ctx.pipe_ctx[i];
1220 if (old_pipe->plane_state && !new_pipe->plane_state)
1221 should_disable = true;
1224 if (should_disable && old_stream) {
1225 bool is_phantom = dc_state_get_stream_subvp_type(dc->current_state, old_stream) == SUBVP_PHANTOM;
1226 pipe = &dc->current_state->res_ctx.pipe_ctx[i];
1227 tg = pipe->stream_res.tg;
1228 /* When disabling plane for a phantom pipe, we must turn on the
1229 * phantom OTG so the disable programming gets the double buffer
1230 * update. Otherwise the pipe will be left in a partially disabled
1231 * state that can result in underflow or hang when enabling it
1232 * again for different use.
1235 if (tg->funcs->enable_crtc) {
1236 int main_pipe_width = 0, main_pipe_height = 0;
1237 struct dc_stream_state *old_paired_stream = dc_state_get_paired_subvp_stream(dc->current_state, old_stream);
1239 if (old_paired_stream) {
1240 main_pipe_width = old_paired_stream->dst.width;
1241 main_pipe_height = old_paired_stream->dst.height;
1244 if (dc->hwss.blank_phantom)
1245 dc->hwss.blank_phantom(dc, tg, main_pipe_width, main_pipe_height);
1246 tg->funcs->enable_crtc(tg);
1251 dc_state_rem_all_phantom_planes_for_stream(dc, old_stream, dangling_context, true);
1253 dc_state_rem_all_planes_for_stream(dc, old_stream, dangling_context);
1254 disable_all_writeback_pipes_for_stream(dc, old_stream, dangling_context);
1256 if (pipe->stream && pipe->plane_state) {
1257 set_p_state_switch_method(dc, context, pipe);
1258 dc_update_visual_confirm_color(dc, context, pipe);
1261 if (dc->hwss.apply_ctx_for_surface) {
1262 apply_ctx_interdependent_lock(dc, dc->current_state, old_stream, true);
1263 dc->hwss.apply_ctx_for_surface(dc, old_stream, 0, dangling_context);
1264 apply_ctx_interdependent_lock(dc, dc->current_state, old_stream, false);
1265 dc->hwss.post_unlock_program_front_end(dc, dangling_context);
1268 if (dc->res_pool->funcs->prepare_mcache_programming)
1269 dc->res_pool->funcs->prepare_mcache_programming(dc, dangling_context);
1270 if (dc->hwss.program_front_end_for_ctx) {
1271 dc->hwss.interdependent_update_lock(dc, dc->current_state, true);
1272 dc->hwss.program_front_end_for_ctx(dc, dangling_context);
1273 dc->hwss.interdependent_update_lock(dc, dc->current_state, false);
1274 dc->hwss.post_unlock_program_front_end(dc, dangling_context);
1276 /* We need to put the phantom OTG back into it's default (disabled) state or we
1277 * can get corruption when transition from one SubVP config to a different one.
1278 * The OTG is set to disable on falling edge of VUPDATE so the plane disable
1279 * will still get it's double buffer update.
1282 if (tg->funcs->disable_phantom_crtc)
1283 tg->funcs->disable_phantom_crtc(tg);
1288 current_ctx = dc->current_state;
1289 dc->current_state = dangling_context;
1290 dc_state_release(current_ctx);
1293 static void disable_vbios_mode_if_required(
1295 struct dc_state *context)
1299 /* check if timing_changed, disable stream*/
1300 for (i = 0; i < dc->res_pool->pipe_count; i++) {
1301 struct dc_stream_state *stream = NULL;
1302 struct dc_link *link = NULL;
1303 struct pipe_ctx *pipe = NULL;
1305 pipe = &context->res_ctx.pipe_ctx[i];
1306 stream = pipe->stream;
1310 if (stream->apply_seamless_boot_optimization)
1313 // only looking for first odm pipe
1314 if (pipe->prev_odm_pipe)
1317 if (stream->link->local_sink &&
1318 stream->link->local_sink->sink_signal == SIGNAL_TYPE_EDP) {
1319 link = stream->link;
1322 if (link != NULL && link->link_enc->funcs->is_dig_enabled(link->link_enc)) {
1323 unsigned int enc_inst, tg_inst = 0;
1324 unsigned int pix_clk_100hz = 0;
1326 enc_inst = link->link_enc->funcs->get_dig_frontend(link->link_enc);
1327 if (enc_inst != ENGINE_ID_UNKNOWN) {
1328 for (j = 0; j < dc->res_pool->stream_enc_count; j++) {
1329 if (dc->res_pool->stream_enc[j]->id == enc_inst) {
1330 tg_inst = dc->res_pool->stream_enc[j]->funcs->dig_source_otg(
1331 dc->res_pool->stream_enc[j]);
1336 dc->res_pool->dp_clock_source->funcs->get_pixel_clk_frequency_100hz(
1337 dc->res_pool->dp_clock_source,
1338 tg_inst, &pix_clk_100hz);
1340 if (link->link_status.link_active) {
1341 uint32_t requested_pix_clk_100hz =
1342 pipe->stream_res.pix_clk_params.requested_pix_clk_100hz;
1344 if (pix_clk_100hz != requested_pix_clk_100hz) {
1345 dc->link_srv->set_dpms_off(pipe);
1346 pipe->stream->dpms_off = false;
1355 * wait_for_blank_complete - wait for all active OPPs to finish pending blank
1358 * @dc: [in] dc reference
1359 * @context: [in] hardware context in use
1361 static void wait_for_blank_complete(struct dc *dc,
1362 struct dc_state *context)
1364 struct pipe_ctx *opp_head;
1365 struct dce_hwseq *hws = dc->hwseq;
1368 if (!hws->funcs.wait_for_blank_complete)
1371 for (i = 0; i < MAX_PIPES; i++) {
1372 opp_head = &context->res_ctx.pipe_ctx[i];
1374 if (!resource_is_pipe_type(opp_head, OPP_HEAD) ||
1375 dc_state_get_pipe_subvp_type(context, opp_head) == SUBVP_PHANTOM)
1378 hws->funcs.wait_for_blank_complete(opp_head->stream_res.opp);
1382 static void wait_for_odm_update_pending_complete(struct dc *dc, struct dc_state *context)
1384 struct pipe_ctx *otg_master;
1385 struct timing_generator *tg;
1388 for (i = 0; i < MAX_PIPES; i++) {
1389 otg_master = &context->res_ctx.pipe_ctx[i];
1390 if (!resource_is_pipe_type(otg_master, OTG_MASTER) ||
1391 dc_state_get_pipe_subvp_type(context, otg_master) == SUBVP_PHANTOM)
1393 tg = otg_master->stream_res.tg;
1394 if (tg->funcs->wait_odm_doublebuffer_pending_clear)
1395 tg->funcs->wait_odm_doublebuffer_pending_clear(tg);
1398 /* ODM update may require to reprogram blank pattern for each OPP */
1399 wait_for_blank_complete(dc, context);
1402 static void wait_for_no_pipes_pending(struct dc *dc, struct dc_state *context)
1406 for (i = 0; i < MAX_PIPES; i++) {
1408 struct pipe_ctx *pipe = &context->res_ctx.pipe_ctx[i];
1410 if (!pipe->plane_state || dc_state_get_pipe_subvp_type(context, pipe) == SUBVP_PHANTOM)
1413 /* Timeout 100 ms */
1414 while (count < 100000) {
1415 /* Must set to false to start with, due to OR in update function */
1416 pipe->plane_state->status.is_flip_pending = false;
1417 dc->hwss.update_pending_status(pipe);
1418 if (!pipe->plane_state->status.is_flip_pending)
1423 ASSERT(!pipe->plane_state->status.is_flip_pending);
1428 /* Public functions */
1430 struct dc *dc_create(const struct dc_init_data *init_params)
1432 struct dc *dc = kzalloc(sizeof(*dc), GFP_KERNEL);
1433 unsigned int full_pipe_count;
1438 if (init_params->dce_environment == DCE_ENV_VIRTUAL_HW) {
1439 dc->caps.linear_pitch_alignment = 64;
1440 if (!dc_construct_ctx(dc, init_params))
1443 if (!dc_construct(dc, init_params))
1446 full_pipe_count = dc->res_pool->pipe_count;
1447 if (dc->res_pool->underlay_pipe_index != NO_UNDERLAY_PIPE)
1449 dc->caps.max_streams = min(
1451 dc->res_pool->stream_enc_count);
1453 dc->caps.max_links = dc->link_count;
1454 dc->caps.max_audios = dc->res_pool->audio_count;
1455 dc->caps.linear_pitch_alignment = 64;
1457 dc->caps.max_dp_protocol_version = DP_VERSION_1_4;
1459 dc->caps.max_otg_num = dc->res_pool->res_cap->num_timing_generator;
1461 if (dc->res_pool->dmcu != NULL)
1462 dc->versions.dmcu_version = dc->res_pool->dmcu->dmcu_version;
1465 dc->dcn_reg_offsets = init_params->dcn_reg_offsets;
1466 dc->nbio_reg_offsets = init_params->nbio_reg_offsets;
1467 dc->clk_reg_offsets = init_params->clk_reg_offsets;
1469 /* Populate versioning information */
1470 dc->versions.dc_ver = DC_VER;
1472 dc->build_id = DC_BUILD_ID;
1474 DC_LOG_DC("Display Core initialized\n");
1484 static void detect_edp_presence(struct dc *dc)
1486 struct dc_link *edp_links[MAX_NUM_EDP];
1487 struct dc_link *edp_link = NULL;
1488 enum dc_connection_type type;
1492 dc_get_edp_links(dc, edp_links, &edp_num);
1496 for (i = 0; i < edp_num; i++) {
1497 edp_link = edp_links[i];
1498 if (dc->config.edp_not_connected) {
1499 edp_link->edp_sink_present = false;
1501 dc_link_detect_connection_type(edp_link, &type);
1502 edp_link->edp_sink_present = (type != dc_connection_none);
1507 void dc_hardware_init(struct dc *dc)
1510 detect_edp_presence(dc);
1511 if (dc->ctx->dce_environment != DCE_ENV_VIRTUAL_HW)
1512 dc->hwss.init_hw(dc);
1515 void dc_init_callbacks(struct dc *dc,
1516 const struct dc_callback_init *init_params)
1518 dc->ctx->cp_psp = init_params->cp_psp;
1521 void dc_deinit_callbacks(struct dc *dc)
1523 memset(&dc->ctx->cp_psp, 0, sizeof(dc->ctx->cp_psp));
1526 void dc_destroy(struct dc **dc)
1533 static void enable_timing_multisync(
1535 struct dc_state *ctx)
1537 int i, multisync_count = 0;
1538 int pipe_count = dc->res_pool->pipe_count;
1539 struct pipe_ctx *multisync_pipes[MAX_PIPES] = { NULL };
1541 for (i = 0; i < pipe_count; i++) {
1542 if (!ctx->res_ctx.pipe_ctx[i].stream ||
1543 !ctx->res_ctx.pipe_ctx[i].stream->triggered_crtc_reset.enabled)
1545 if (ctx->res_ctx.pipe_ctx[i].stream == ctx->res_ctx.pipe_ctx[i].stream->triggered_crtc_reset.event_source)
1547 multisync_pipes[multisync_count] = &ctx->res_ctx.pipe_ctx[i];
1551 if (multisync_count > 0) {
1552 dc->hwss.enable_per_frame_crtc_position_reset(
1553 dc, multisync_count, multisync_pipes);
1557 static void program_timing_sync(
1559 struct dc_state *ctx)
1562 int group_index = 0;
1564 int pipe_count = dc->res_pool->pipe_count;
1565 struct pipe_ctx *unsynced_pipes[MAX_PIPES] = { NULL };
1567 for (i = 0; i < pipe_count; i++) {
1568 if (!ctx->res_ctx.pipe_ctx[i].stream
1569 || ctx->res_ctx.pipe_ctx[i].top_pipe
1570 || ctx->res_ctx.pipe_ctx[i].prev_odm_pipe)
1573 unsynced_pipes[i] = &ctx->res_ctx.pipe_ctx[i];
1576 for (i = 0; i < pipe_count; i++) {
1578 enum timing_synchronization_type sync_type = NOT_SYNCHRONIZABLE;
1579 struct pipe_ctx *pipe_set[MAX_PIPES];
1581 if (!unsynced_pipes[i])
1584 pipe_set[0] = unsynced_pipes[i];
1585 unsynced_pipes[i] = NULL;
1587 /* Add tg to the set, search rest of the tg's for ones with
1588 * same timing, add all tgs with same timing to the group
1590 for (j = i + 1; j < pipe_count; j++) {
1591 if (!unsynced_pipes[j])
1593 if (sync_type != TIMING_SYNCHRONIZABLE &&
1594 dc->hwss.enable_vblanks_synchronization &&
1595 unsynced_pipes[j]->stream_res.tg->funcs->align_vblanks &&
1596 resource_are_vblanks_synchronizable(
1597 unsynced_pipes[j]->stream,
1598 pipe_set[0]->stream)) {
1599 sync_type = VBLANK_SYNCHRONIZABLE;
1600 pipe_set[group_size] = unsynced_pipes[j];
1601 unsynced_pipes[j] = NULL;
1604 if (sync_type != VBLANK_SYNCHRONIZABLE &&
1605 resource_are_streams_timing_synchronizable(
1606 unsynced_pipes[j]->stream,
1607 pipe_set[0]->stream)) {
1608 sync_type = TIMING_SYNCHRONIZABLE;
1609 pipe_set[group_size] = unsynced_pipes[j];
1610 unsynced_pipes[j] = NULL;
1615 /* set first unblanked pipe as master */
1616 for (j = 0; j < group_size; j++) {
1619 if (pipe_set[j]->stream_res.opp->funcs->dpg_is_blanked)
1621 pipe_set[j]->stream_res.opp->funcs->dpg_is_blanked(pipe_set[j]->stream_res.opp);
1624 pipe_set[j]->stream_res.tg->funcs->is_blanked(pipe_set[j]->stream_res.tg);
1629 swap(pipe_set[0], pipe_set[j]);
1634 for (k = 0; k < group_size; k++) {
1635 struct dc_stream_status *status = dc_state_get_stream_status(ctx, pipe_set[k]->stream);
1640 status->timing_sync_info.group_id = num_group;
1641 status->timing_sync_info.group_size = group_size;
1643 status->timing_sync_info.master = true;
1645 status->timing_sync_info.master = false;
1649 /* remove any other unblanked pipes as they have already been synced */
1650 if (dc->config.use_pipe_ctx_sync_logic) {
1651 /* check pipe's syncd to decide which pipe to be removed */
1652 for (j = 1; j < group_size; j++) {
1653 if (pipe_set[j]->pipe_idx_syncd == pipe_set[0]->pipe_idx_syncd) {
1655 pipe_set[j] = pipe_set[group_size];
1658 /* link slave pipe's syncd with master pipe */
1659 pipe_set[j]->pipe_idx_syncd = pipe_set[0]->pipe_idx_syncd;
1662 /* remove any other pipes by checking valid plane */
1663 for (j = j + 1; j < group_size; j++) {
1666 if (pipe_set[j]->stream_res.opp->funcs->dpg_is_blanked)
1668 pipe_set[j]->stream_res.opp->funcs->dpg_is_blanked(pipe_set[j]->stream_res.opp);
1671 pipe_set[j]->stream_res.tg->funcs->is_blanked(pipe_set[j]->stream_res.tg);
1674 pipe_set[j] = pipe_set[group_size];
1680 if (group_size > 1) {
1681 if (sync_type == TIMING_SYNCHRONIZABLE) {
1682 dc->hwss.enable_timing_synchronization(
1683 dc, ctx, group_index, group_size, pipe_set);
1685 if (sync_type == VBLANK_SYNCHRONIZABLE) {
1686 dc->hwss.enable_vblanks_synchronization(
1687 dc, group_index, group_size, pipe_set);
1695 static bool streams_changed(struct dc *dc,
1696 struct dc_stream_state *streams[],
1697 uint8_t stream_count)
1701 if (stream_count != dc->current_state->stream_count)
1704 for (i = 0; i < dc->current_state->stream_count; i++) {
1705 if (dc->current_state->streams[i] != streams[i])
1707 if (!streams[i]->link->link_state_valid)
1714 bool dc_validate_boot_timing(const struct dc *dc,
1715 const struct dc_sink *sink,
1716 struct dc_crtc_timing *crtc_timing)
1718 struct timing_generator *tg;
1719 struct stream_encoder *se = NULL;
1721 struct dc_crtc_timing hw_crtc_timing = {0};
1723 struct dc_link *link = sink->link;
1724 unsigned int i, enc_inst, tg_inst = 0;
1726 /* Support seamless boot on EDP displays only */
1727 if (sink->sink_signal != SIGNAL_TYPE_EDP) {
1731 if (dc->debug.force_odm_combine)
1734 /* Check for enabled DIG to identify enabled display */
1735 if (!link->link_enc->funcs->is_dig_enabled(link->link_enc))
1738 enc_inst = link->link_enc->funcs->get_dig_frontend(link->link_enc);
1740 if (enc_inst == ENGINE_ID_UNKNOWN)
1743 for (i = 0; i < dc->res_pool->stream_enc_count; i++) {
1744 if (dc->res_pool->stream_enc[i]->id == enc_inst) {
1746 se = dc->res_pool->stream_enc[i];
1748 tg_inst = dc->res_pool->stream_enc[i]->funcs->dig_source_otg(
1749 dc->res_pool->stream_enc[i]);
1754 // tg_inst not found
1755 if (i == dc->res_pool->stream_enc_count)
1758 if (tg_inst >= dc->res_pool->timing_generator_count)
1761 if (tg_inst != link->link_enc->preferred_engine)
1764 tg = dc->res_pool->timing_generators[tg_inst];
1766 if (!tg->funcs->get_hw_timing)
1769 if (!tg->funcs->get_hw_timing(tg, &hw_crtc_timing))
1772 if (crtc_timing->h_total != hw_crtc_timing.h_total)
1775 if (crtc_timing->h_border_left != hw_crtc_timing.h_border_left)
1778 if (crtc_timing->h_addressable != hw_crtc_timing.h_addressable)
1781 if (crtc_timing->h_border_right != hw_crtc_timing.h_border_right)
1784 if (crtc_timing->h_front_porch != hw_crtc_timing.h_front_porch)
1787 if (crtc_timing->h_sync_width != hw_crtc_timing.h_sync_width)
1790 if (crtc_timing->v_total != hw_crtc_timing.v_total)
1793 if (crtc_timing->v_border_top != hw_crtc_timing.v_border_top)
1796 if (crtc_timing->v_addressable != hw_crtc_timing.v_addressable)
1799 if (crtc_timing->v_border_bottom != hw_crtc_timing.v_border_bottom)
1802 if (crtc_timing->v_front_porch != hw_crtc_timing.v_front_porch)
1805 if (crtc_timing->v_sync_width != hw_crtc_timing.v_sync_width)
1808 /* block DSC for now, as VBIOS does not currently support DSC timings */
1809 if (crtc_timing->flags.DSC)
1812 if (dc_is_dp_signal(link->connector_signal)) {
1813 unsigned int pix_clk_100hz = 0;
1814 uint32_t numOdmPipes = 1;
1815 uint32_t id_src[4] = {0};
1817 dc->res_pool->dp_clock_source->funcs->get_pixel_clk_frequency_100hz(
1818 dc->res_pool->dp_clock_source,
1819 tg_inst, &pix_clk_100hz);
1821 if (tg->funcs->get_optc_source)
1822 tg->funcs->get_optc_source(tg,
1823 &numOdmPipes, &id_src[0], &id_src[1]);
1825 if (numOdmPipes == 2)
1827 if (numOdmPipes == 4)
1830 // Note: In rare cases, HW pixclk may differ from crtc's pixclk
1831 // slightly due to rounding issues in 10 kHz units.
1832 if (crtc_timing->pix_clk_100hz != pix_clk_100hz)
1835 if (!se->funcs->dp_get_pixel_format)
1838 if (!se->funcs->dp_get_pixel_format(
1840 &hw_crtc_timing.pixel_encoding,
1841 &hw_crtc_timing.display_color_depth))
1844 if (hw_crtc_timing.display_color_depth != crtc_timing->display_color_depth)
1847 if (hw_crtc_timing.pixel_encoding != crtc_timing->pixel_encoding)
1851 if (link->dpcd_caps.dprx_feature.bits.VSC_SDP_COLORIMETRY_SUPPORTED) {
1855 if (link->dpcd_caps.channel_coding_cap.bits.DP_128b_132b_SUPPORTED)
1858 if (dc->link_srv->edp_is_ilr_optimization_required(link, crtc_timing)) {
1859 DC_LOG_EVENT_LINK_TRAINING("Seamless boot disabled to optimize eDP link rate\n");
1866 static inline bool should_update_pipe_for_stream(
1867 struct dc_state *context,
1868 struct pipe_ctx *pipe_ctx,
1869 struct dc_stream_state *stream)
1871 return (pipe_ctx->stream && pipe_ctx->stream == stream);
1874 static inline bool should_update_pipe_for_plane(
1875 struct dc_state *context,
1876 struct pipe_ctx *pipe_ctx,
1877 struct dc_plane_state *plane_state)
1879 return (pipe_ctx->plane_state == plane_state);
1882 void dc_enable_stereo(
1884 struct dc_state *context,
1885 struct dc_stream_state *streams[],
1886 uint8_t stream_count)
1889 struct pipe_ctx *pipe;
1891 dc_exit_ips_for_hw_access(dc);
1893 for (i = 0; i < MAX_PIPES; i++) {
1894 if (context != NULL) {
1895 pipe = &context->res_ctx.pipe_ctx[i];
1897 context = dc->current_state;
1898 pipe = &dc->current_state->res_ctx.pipe_ctx[i];
1901 for (j = 0; pipe && j < stream_count; j++) {
1902 if (should_update_pipe_for_stream(context, pipe, streams[j]) &&
1903 dc->hwss.setup_stereo)
1904 dc->hwss.setup_stereo(pipe, dc);
1909 void dc_trigger_sync(struct dc *dc, struct dc_state *context)
1911 if (context->stream_count > 1 && !dc->debug.disable_timing_sync) {
1912 dc_exit_ips_for_hw_access(dc);
1914 enable_timing_multisync(dc, context);
1915 program_timing_sync(dc, context);
1919 static uint8_t get_stream_mask(struct dc *dc, struct dc_state *context)
1922 unsigned int stream_mask = 0;
1924 for (i = 0; i < dc->res_pool->pipe_count; i++) {
1925 if (context->res_ctx.pipe_ctx[i].stream)
1926 stream_mask |= 1 << i;
1932 void dc_z10_restore(const struct dc *dc)
1934 if (dc->hwss.z10_restore)
1935 dc->hwss.z10_restore(dc);
1938 void dc_z10_save_init(struct dc *dc)
1940 if (dc->hwss.z10_save_init)
1941 dc->hwss.z10_save_init(dc);
1945 * dc_commit_state_no_check - Apply context to the hardware
1947 * @dc: DC object with the current status to be updated
1948 * @context: New state that will become the current status at the end of this function
1950 * Applies given context to the hardware and copy it into current context.
1951 * It's up to the user to release the src context afterwards.
1953 * Return: an enum dc_status result code for the operation
1955 static enum dc_status dc_commit_state_no_check(struct dc *dc, struct dc_state *context)
1957 struct dc_bios *dcb = dc->ctx->dc_bios;
1958 enum dc_status result = DC_ERROR_UNEXPECTED;
1959 struct pipe_ctx *pipe;
1961 struct dc_stream_state *dc_streams[MAX_STREAMS] = {0};
1962 struct dc_state *old_state;
1963 bool subvp_prev_use = false;
1966 dc_allow_idle_optimizations(dc, false);
1968 for (i = 0; i < dc->res_pool->pipe_count; i++) {
1969 struct pipe_ctx *old_pipe = &dc->current_state->res_ctx.pipe_ctx[i];
1971 /* Check old context for SubVP */
1972 subvp_prev_use |= (dc_state_get_pipe_subvp_type(dc->current_state, old_pipe) == SUBVP_PHANTOM);
1977 for (i = 0; i < context->stream_count; i++)
1978 dc_streams[i] = context->streams[i];
1980 if (!dcb->funcs->is_accelerated_mode(dcb)) {
1981 disable_vbios_mode_if_required(dc, context);
1982 dc->hwss.enable_accelerated_mode(dc, context);
1985 if (context->stream_count > get_seamless_boot_stream_count(context) ||
1986 context->stream_count == 0)
1987 dc->hwss.prepare_bandwidth(dc, context);
1989 /* When SubVP is active, all HW programming must be done while
1990 * SubVP lock is acquired
1992 if (dc->hwss.subvp_pipe_control_lock)
1993 dc->hwss.subvp_pipe_control_lock(dc, context, true, true, NULL, subvp_prev_use);
1994 if (dc->hwss.fams2_global_control_lock)
1995 dc->hwss.fams2_global_control_lock(dc, context, true);
1997 if (dc->hwss.update_dsc_pg)
1998 dc->hwss.update_dsc_pg(dc, context, false);
2000 disable_dangling_plane(dc, context);
2001 /* re-program planes for existing stream, in case we need to
2002 * free up plane resource for later use
2004 if (dc->hwss.apply_ctx_for_surface) {
2005 for (i = 0; i < context->stream_count; i++) {
2006 if (context->streams[i]->mode_changed)
2008 apply_ctx_interdependent_lock(dc, context, context->streams[i], true);
2009 dc->hwss.apply_ctx_for_surface(
2010 dc, context->streams[i],
2011 context->stream_status[i].plane_count,
2012 context); /* use new pipe config in new context */
2013 apply_ctx_interdependent_lock(dc, context, context->streams[i], false);
2014 dc->hwss.post_unlock_program_front_end(dc, context);
2018 /* Program hardware */
2019 for (i = 0; i < dc->res_pool->pipe_count; i++) {
2020 pipe = &context->res_ctx.pipe_ctx[i];
2021 dc->hwss.wait_for_mpcc_disconnect(dc, dc->res_pool, pipe);
2024 result = dc->hwss.apply_ctx_to_hw(dc, context);
2026 if (result != DC_OK) {
2027 /* Application of dc_state to hardware stopped. */
2028 dc->current_state->res_ctx.link_enc_cfg_ctx.mode = LINK_ENC_CFG_STEADY;
2032 dc_trigger_sync(dc, context);
2034 /* Full update should unconditionally be triggered when dc_commit_state_no_check is called */
2035 for (i = 0; i < context->stream_count; i++) {
2036 uint32_t prev_dsc_changed = context->streams[i]->update_flags.bits.dsc_changed;
2038 context->streams[i]->update_flags.raw = 0xFFFFFFFF;
2039 context->streams[i]->update_flags.bits.dsc_changed = prev_dsc_changed;
2042 /* Program all planes within new context*/
2043 if (dc->res_pool->funcs->prepare_mcache_programming)
2044 dc->res_pool->funcs->prepare_mcache_programming(dc, context);
2045 if (dc->hwss.program_front_end_for_ctx) {
2046 dc->hwss.interdependent_update_lock(dc, context, true);
2047 dc->hwss.program_front_end_for_ctx(dc, context);
2048 dc->hwss.interdependent_update_lock(dc, context, false);
2049 dc->hwss.post_unlock_program_front_end(dc, context);
2052 if (dc->hwss.commit_subvp_config)
2053 dc->hwss.commit_subvp_config(dc, context);
2054 if (dc->hwss.subvp_pipe_control_lock)
2055 dc->hwss.subvp_pipe_control_lock(dc, context, false, true, NULL, subvp_prev_use);
2056 if (dc->hwss.fams2_global_control_lock)
2057 dc->hwss.fams2_global_control_lock(dc, context, false);
2059 for (i = 0; i < context->stream_count; i++) {
2060 const struct dc_link *link = context->streams[i]->link;
2062 if (!context->streams[i]->mode_changed)
2065 if (dc->hwss.apply_ctx_for_surface) {
2066 apply_ctx_interdependent_lock(dc, context, context->streams[i], true);
2067 dc->hwss.apply_ctx_for_surface(
2068 dc, context->streams[i],
2069 context->stream_status[i].plane_count,
2071 apply_ctx_interdependent_lock(dc, context, context->streams[i], false);
2072 dc->hwss.post_unlock_program_front_end(dc, context);
2077 * TODO rework dc_enable_stereo call to work with validation sets?
2079 for (k = 0; k < MAX_PIPES; k++) {
2080 pipe = &context->res_ctx.pipe_ctx[k];
2082 for (l = 0 ; pipe && l < context->stream_count; l++) {
2083 if (context->streams[l] &&
2084 context->streams[l] == pipe->stream &&
2085 dc->hwss.setup_stereo)
2086 dc->hwss.setup_stereo(pipe, dc);
2090 CONN_MSG_MODE(link, "{%dx%d, %dx%d@%dKhz}",
2091 context->streams[i]->timing.h_addressable,
2092 context->streams[i]->timing.v_addressable,
2093 context->streams[i]->timing.h_total,
2094 context->streams[i]->timing.v_total,
2095 context->streams[i]->timing.pix_clk_100hz / 10);
2098 dc_enable_stereo(dc, context, dc_streams, context->stream_count);
2100 if (context->stream_count > get_seamless_boot_stream_count(context) ||
2101 context->stream_count == 0) {
2102 /* Must wait for no flips to be pending before doing optimize bw */
2103 wait_for_no_pipes_pending(dc, context);
2105 * optimized dispclk depends on ODM setup. Need to wait for ODM
2106 * update pending complete before optimizing bandwidth.
2108 wait_for_odm_update_pending_complete(dc, context);
2109 /* pplib is notified if disp_num changed */
2110 dc->hwss.optimize_bandwidth(dc, context);
2111 /* Need to do otg sync again as otg could be out of sync due to otg
2112 * workaround applied during clock update
2114 dc_trigger_sync(dc, context);
2117 if (dc->hwss.update_dsc_pg)
2118 dc->hwss.update_dsc_pg(dc, context, true);
2120 if (dc->ctx->dce_version >= DCE_VERSION_MAX)
2121 TRACE_DCN_CLOCK_STATE(&context->bw_ctx.bw.dcn.clk);
2123 TRACE_DCE_CLOCK_STATE(&context->bw_ctx.bw.dce);
2125 context->stream_mask = get_stream_mask(dc, context);
2127 if (context->stream_mask != dc->current_state->stream_mask)
2128 dc_dmub_srv_notify_stream_mask(dc->ctx->dmub_srv, context->stream_mask);
2130 for (i = 0; i < context->stream_count; i++)
2131 context->streams[i]->mode_changed = false;
2133 /* Clear update flags that were set earlier to avoid redundant programming */
2134 for (i = 0; i < context->stream_count; i++) {
2135 context->streams[i]->update_flags.raw = 0x0;
2138 old_state = dc->current_state;
2139 dc->current_state = context;
2141 dc_state_release(old_state);
2143 dc_state_retain(dc->current_state);
2148 static bool commit_minimal_transition_state(struct dc *dc,
2149 struct dc_state *transition_base_context);
2152 * dc_commit_streams - Commit current stream state
2154 * @dc: DC object with the commit state to be configured in the hardware
2155 * @params: Parameters for the commit, including the streams to be committed
2157 * Function responsible for commit streams change to the hardware.
2160 * Return DC_OK if everything work as expected, otherwise, return a dc_status
2163 enum dc_status dc_commit_streams(struct dc *dc, struct dc_commit_streams_params *params)
2166 struct dc_state *context;
2167 enum dc_status res = DC_OK;
2168 struct dc_validation_set set[MAX_STREAMS] = {0};
2169 struct pipe_ctx *pipe;
2170 bool handle_exit_odm2to1 = false;
2173 return DC_ERROR_UNEXPECTED;
2175 if (dc->ctx->dce_environment == DCE_ENV_VIRTUAL_HW)
2178 if (!streams_changed(dc, params->streams, params->stream_count) &&
2179 dc->current_state->power_source == params->power_source)
2182 dc_exit_ips_for_hw_access(dc);
2184 DC_LOG_DC("%s: %d streams\n", __func__, params->stream_count);
2186 for (i = 0; i < params->stream_count; i++) {
2187 struct dc_stream_state *stream = params->streams[i];
2188 struct dc_stream_status *status = dc_stream_get_status(stream);
2190 dc_stream_log(dc, stream);
2192 set[i].stream = stream;
2195 set[i].plane_count = status->plane_count;
2196 for (j = 0; j < status->plane_count; j++)
2197 set[i].plane_states[j] = status->plane_states[j];
2201 /* ODM Combine 2:1 power optimization is only applied for single stream
2202 * scenario, it uses extra pipes than needed to reduce power consumption
2203 * We need to switch off this feature to make room for new streams.
2205 if (params->stream_count > dc->current_state->stream_count &&
2206 dc->current_state->stream_count == 1) {
2207 for (i = 0; i < dc->res_pool->pipe_count; i++) {
2208 pipe = &dc->current_state->res_ctx.pipe_ctx[i];
2209 if (pipe->next_odm_pipe)
2210 handle_exit_odm2to1 = true;
2214 if (handle_exit_odm2to1)
2215 res = commit_minimal_transition_state(dc, dc->current_state);
2217 context = dc_state_create_current_copy(dc);
2219 goto context_alloc_fail;
2221 context->power_source = params->power_source;
2223 res = dc_validate_with_context(dc, set, params->stream_count, context, false);
2225 BREAK_TO_DEBUGGER();
2229 res = dc_commit_state_no_check(dc, context);
2231 for (i = 0; i < params->stream_count; i++) {
2232 for (j = 0; j < context->stream_count; j++) {
2233 if (params->streams[i]->stream_id == context->streams[j]->stream_id)
2234 params->streams[i]->out.otg_offset = context->stream_status[j].primary_otg_inst;
2236 if (dc_is_embedded_signal(params->streams[i]->signal)) {
2237 struct dc_stream_status *status = dc_state_get_stream_status(context, params->streams[i]);
2242 if (dc->hwss.is_abm_supported)
2243 status->is_abm_supported = dc->hwss.is_abm_supported(dc, context, params->streams[i]);
2245 status->is_abm_supported = true;
2251 dc_state_release(context);
2255 DC_LOG_DC("%s Finished.\n", __func__);
2260 bool dc_acquire_release_mpc_3dlut(
2261 struct dc *dc, bool acquire,
2262 struct dc_stream_state *stream,
2263 struct dc_3dlut **lut,
2264 struct dc_transfer_func **shaper)
2268 bool found_pipe_idx = false;
2269 const struct resource_pool *pool = dc->res_pool;
2270 struct resource_context *res_ctx = &dc->current_state->res_ctx;
2273 if (pool && res_ctx) {
2275 /*find pipe idx for the given stream*/
2276 for (pipe_idx = 0; pipe_idx < pool->pipe_count; pipe_idx++) {
2277 if (res_ctx->pipe_ctx[pipe_idx].stream == stream) {
2278 found_pipe_idx = true;
2279 mpcc_id = res_ctx->pipe_ctx[pipe_idx].plane_res.hubp->inst;
2284 found_pipe_idx = true;/*for release pipe_idx is not required*/
2286 if (found_pipe_idx) {
2287 if (acquire && pool->funcs->acquire_post_bldn_3dlut)
2288 ret = pool->funcs->acquire_post_bldn_3dlut(res_ctx, pool, mpcc_id, lut, shaper);
2289 else if (!acquire && pool->funcs->release_post_bldn_3dlut)
2290 ret = pool->funcs->release_post_bldn_3dlut(res_ctx, pool, lut, shaper);
2296 static bool is_flip_pending_in_pipes(struct dc *dc, struct dc_state *context)
2299 struct pipe_ctx *pipe;
2301 for (i = 0; i < MAX_PIPES; i++) {
2302 pipe = &context->res_ctx.pipe_ctx[i];
2304 // Don't check flip pending on phantom pipes
2305 if (!pipe->plane_state || (dc_state_get_pipe_subvp_type(context, pipe) == SUBVP_PHANTOM))
2308 /* Must set to false to start with, due to OR in update function */
2309 pipe->plane_state->status.is_flip_pending = false;
2310 dc->hwss.update_pending_status(pipe);
2311 if (pipe->plane_state->status.is_flip_pending)
2317 /* Perform updates here which need to be deferred until next vupdate
2319 * i.e. blnd lut, 3dlut, and shaper lut bypass regs are double buffered
2320 * but forcing lut memory to shutdown state is immediate. This causes
2321 * single frame corruption as lut gets disabled mid-frame unless shutdown
2322 * is deferred until after entering bypass.
2324 static void process_deferred_updates(struct dc *dc)
2328 if (dc->debug.enable_mem_low_power.bits.cm) {
2329 ASSERT(dc->dcn_ip->max_num_dpp);
2330 for (i = 0; i < dc->dcn_ip->max_num_dpp; i++)
2331 if (dc->res_pool->dpps[i]->funcs->dpp_deferred_update)
2332 dc->res_pool->dpps[i]->funcs->dpp_deferred_update(dc->res_pool->dpps[i]);
2336 void dc_post_update_surfaces_to_stream(struct dc *dc)
2339 struct dc_state *context = dc->current_state;
2341 if ((!dc->optimized_required) || get_seamless_boot_stream_count(context) > 0)
2344 post_surface_trace(dc);
2347 * Only relevant for DCN behavior where we can guarantee the optimization
2348 * is safe to apply - retain the legacy behavior for DCE.
2351 if (dc->ctx->dce_version < DCE_VERSION_MAX)
2352 TRACE_DCE_CLOCK_STATE(&context->bw_ctx.bw.dce);
2354 TRACE_DCN_CLOCK_STATE(&context->bw_ctx.bw.dcn.clk);
2356 if (is_flip_pending_in_pipes(dc, context))
2359 for (i = 0; i < dc->res_pool->pipe_count; i++)
2360 if (context->res_ctx.pipe_ctx[i].stream == NULL ||
2361 context->res_ctx.pipe_ctx[i].plane_state == NULL) {
2362 context->res_ctx.pipe_ctx[i].pipe_idx = i;
2363 dc->hwss.disable_plane(dc, context, &context->res_ctx.pipe_ctx[i]);
2366 process_deferred_updates(dc);
2368 dc->hwss.optimize_bandwidth(dc, context);
2370 if (dc->hwss.update_dsc_pg)
2371 dc->hwss.update_dsc_pg(dc, context, true);
2374 dc->optimized_required = false;
2375 dc->wm_optimized_required = false;
2378 bool dc_set_generic_gpio_for_stereo(bool enable,
2379 struct gpio_service *gpio_service)
2381 enum gpio_result gpio_result = GPIO_RESULT_NON_SPECIFIC_ERROR;
2382 struct gpio_pin_info pin_info;
2383 struct gpio *generic;
2384 struct gpio_generic_mux_config *config = kzalloc(sizeof(struct gpio_generic_mux_config),
2389 pin_info = dal_gpio_get_generic_pin_info(gpio_service, GPIO_ID_GENERIC, 0);
2391 if (pin_info.mask == 0xFFFFFFFF || pin_info.offset == 0xFFFFFFFF) {
2395 generic = dal_gpio_service_create_generic_mux(
2406 gpio_result = dal_gpio_open(generic, GPIO_MODE_OUTPUT);
2408 config->enable_output_from_mux = enable;
2409 config->mux_select = GPIO_SIGNAL_SOURCE_PASS_THROUGH_STEREO_SYNC;
2411 if (gpio_result == GPIO_RESULT_OK)
2412 gpio_result = dal_mux_setup_config(generic, config);
2414 if (gpio_result == GPIO_RESULT_OK) {
2415 dal_gpio_close(generic);
2416 dal_gpio_destroy_generic_mux(&generic);
2420 dal_gpio_close(generic);
2421 dal_gpio_destroy_generic_mux(&generic);
2427 static bool is_surface_in_context(
2428 const struct dc_state *context,
2429 const struct dc_plane_state *plane_state)
2433 for (j = 0; j < MAX_PIPES; j++) {
2434 const struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[j];
2436 if (plane_state == pipe_ctx->plane_state) {
2444 static enum surface_update_type get_plane_info_update_type(const struct dc_surface_update *u)
2446 union surface_update_flags *update_flags = &u->surface->update_flags;
2447 enum surface_update_type update_type = UPDATE_TYPE_FAST;
2450 return UPDATE_TYPE_FAST;
2452 if (u->plane_info->color_space != u->surface->color_space) {
2453 update_flags->bits.color_space_change = 1;
2454 elevate_update_type(&update_type, UPDATE_TYPE_MED);
2457 if (u->plane_info->horizontal_mirror != u->surface->horizontal_mirror) {
2458 update_flags->bits.horizontal_mirror_change = 1;
2459 elevate_update_type(&update_type, UPDATE_TYPE_MED);
2462 if (u->plane_info->rotation != u->surface->rotation) {
2463 update_flags->bits.rotation_change = 1;
2464 elevate_update_type(&update_type, UPDATE_TYPE_FULL);
2467 if (u->plane_info->format != u->surface->format) {
2468 update_flags->bits.pixel_format_change = 1;
2469 elevate_update_type(&update_type, UPDATE_TYPE_FULL);
2472 if (u->plane_info->stereo_format != u->surface->stereo_format) {
2473 update_flags->bits.stereo_format_change = 1;
2474 elevate_update_type(&update_type, UPDATE_TYPE_FULL);
2477 if (u->plane_info->per_pixel_alpha != u->surface->per_pixel_alpha) {
2478 update_flags->bits.per_pixel_alpha_change = 1;
2479 elevate_update_type(&update_type, UPDATE_TYPE_MED);
2482 if (u->plane_info->global_alpha_value != u->surface->global_alpha_value) {
2483 update_flags->bits.global_alpha_change = 1;
2484 elevate_update_type(&update_type, UPDATE_TYPE_MED);
2487 if (u->plane_info->dcc.enable != u->surface->dcc.enable
2488 || u->plane_info->dcc.dcc_ind_blk != u->surface->dcc.dcc_ind_blk
2489 || u->plane_info->dcc.meta_pitch != u->surface->dcc.meta_pitch) {
2490 /* During DCC on/off, stutter period is calculated before
2491 * DCC has fully transitioned. This results in incorrect
2492 * stutter period calculation. Triggering a full update will
2493 * recalculate stutter period.
2495 update_flags->bits.dcc_change = 1;
2496 elevate_update_type(&update_type, UPDATE_TYPE_FULL);
2499 if (resource_pixel_format_to_bpp(u->plane_info->format) !=
2500 resource_pixel_format_to_bpp(u->surface->format)) {
2501 /* different bytes per element will require full bandwidth
2502 * and DML calculation
2504 update_flags->bits.bpp_change = 1;
2505 elevate_update_type(&update_type, UPDATE_TYPE_FULL);
2508 if (u->plane_info->plane_size.surface_pitch != u->surface->plane_size.surface_pitch
2509 || u->plane_info->plane_size.chroma_pitch != u->surface->plane_size.chroma_pitch) {
2510 update_flags->bits.plane_size_change = 1;
2511 elevate_update_type(&update_type, UPDATE_TYPE_MED);
2515 if (memcmp(&u->plane_info->tiling_info, &u->surface->tiling_info,
2516 sizeof(union dc_tiling_info)) != 0) {
2517 update_flags->bits.swizzle_change = 1;
2518 elevate_update_type(&update_type, UPDATE_TYPE_MED);
2520 /* todo: below are HW dependent, we should add a hook to
2521 * DCE/N resource and validated there.
2523 if (u->plane_info->tiling_info.gfx9.swizzle != DC_SW_LINEAR) {
2524 /* swizzled mode requires RQ to be setup properly,
2525 * thus need to run DML to calculate RQ settings
2527 update_flags->bits.bandwidth_change = 1;
2528 elevate_update_type(&update_type, UPDATE_TYPE_FULL);
2532 /* This should be UPDATE_TYPE_FAST if nothing has changed. */
2536 static enum surface_update_type get_scaling_info_update_type(
2537 const struct dc *dc,
2538 const struct dc_surface_update *u)
2540 union surface_update_flags *update_flags = &u->surface->update_flags;
2542 if (!u->scaling_info)
2543 return UPDATE_TYPE_FAST;
2545 if (u->scaling_info->dst_rect.width != u->surface->dst_rect.width
2546 || u->scaling_info->dst_rect.height != u->surface->dst_rect.height
2547 || u->scaling_info->scaling_quality.integer_scaling !=
2548 u->surface->scaling_quality.integer_scaling
2550 update_flags->bits.scaling_change = 1;
2552 if ((u->scaling_info->dst_rect.width < u->surface->dst_rect.width
2553 || u->scaling_info->dst_rect.height < u->surface->dst_rect.height)
2554 && (u->scaling_info->dst_rect.width < u->surface->src_rect.width
2555 || u->scaling_info->dst_rect.height < u->surface->src_rect.height))
2556 /* Making dst rect smaller requires a bandwidth change */
2557 update_flags->bits.bandwidth_change = 1;
2560 if (u->scaling_info->src_rect.width != u->surface->src_rect.width
2561 || u->scaling_info->src_rect.height != u->surface->src_rect.height) {
2563 update_flags->bits.scaling_change = 1;
2564 if (u->scaling_info->src_rect.width > u->surface->src_rect.width
2565 || u->scaling_info->src_rect.height > u->surface->src_rect.height)
2566 /* Making src rect bigger requires a bandwidth change */
2567 update_flags->bits.clock_change = 1;
2570 if (u->scaling_info->src_rect.width > dc->caps.max_optimizable_video_width &&
2571 (u->scaling_info->clip_rect.width > u->surface->clip_rect.width ||
2572 u->scaling_info->clip_rect.height > u->surface->clip_rect.height))
2573 /* Changing clip size of a large surface may result in MPC slice count change */
2574 update_flags->bits.bandwidth_change = 1;
2576 if (u->scaling_info->clip_rect.width != u->surface->clip_rect.width ||
2577 u->scaling_info->clip_rect.height != u->surface->clip_rect.height)
2578 update_flags->bits.clip_size_change = 1;
2580 if (u->scaling_info->src_rect.x != u->surface->src_rect.x
2581 || u->scaling_info->src_rect.y != u->surface->src_rect.y
2582 || u->scaling_info->clip_rect.x != u->surface->clip_rect.x
2583 || u->scaling_info->clip_rect.y != u->surface->clip_rect.y
2584 || u->scaling_info->dst_rect.x != u->surface->dst_rect.x
2585 || u->scaling_info->dst_rect.y != u->surface->dst_rect.y)
2586 update_flags->bits.position_change = 1;
2588 if (update_flags->bits.clock_change
2589 || update_flags->bits.bandwidth_change
2590 || update_flags->bits.scaling_change)
2591 return UPDATE_TYPE_FULL;
2593 if (update_flags->bits.position_change ||
2594 update_flags->bits.clip_size_change)
2595 return UPDATE_TYPE_MED;
2597 return UPDATE_TYPE_FAST;
2600 static enum surface_update_type det_surface_update(const struct dc *dc,
2601 const struct dc_surface_update *u)
2603 const struct dc_state *context = dc->current_state;
2604 enum surface_update_type type;
2605 enum surface_update_type overall_type = UPDATE_TYPE_FAST;
2606 union surface_update_flags *update_flags = &u->surface->update_flags;
2608 if (!is_surface_in_context(context, u->surface) || u->surface->force_full_update) {
2609 update_flags->raw = 0xFFFFFFFF;
2610 return UPDATE_TYPE_FULL;
2613 update_flags->raw = 0; // Reset all flags
2615 type = get_plane_info_update_type(u);
2616 elevate_update_type(&overall_type, type);
2618 type = get_scaling_info_update_type(dc, u);
2619 elevate_update_type(&overall_type, type);
2622 update_flags->bits.addr_update = 1;
2623 if (u->flip_addr->address.tmz_surface != u->surface->address.tmz_surface) {
2624 update_flags->bits.tmz_changed = 1;
2625 elevate_update_type(&overall_type, UPDATE_TYPE_FULL);
2628 if (u->in_transfer_func)
2629 update_flags->bits.in_transfer_func_change = 1;
2631 if (u->input_csc_color_matrix)
2632 update_flags->bits.input_csc_change = 1;
2634 if (u->coeff_reduction_factor)
2635 update_flags->bits.coeff_reduction_change = 1;
2637 if (u->gamut_remap_matrix)
2638 update_flags->bits.gamut_remap_change = 1;
2641 update_flags->bits.gamma_change = 1;
2644 enum surface_pixel_format format = SURFACE_PIXEL_FORMAT_GRPH_BEGIN;
2647 format = u->plane_info->format;
2649 format = u->surface->format;
2651 if (dce_use_lut(format))
2652 update_flags->bits.gamma_change = 1;
2655 if (u->lut3d_func || u->func_shaper)
2656 update_flags->bits.lut_3d = 1;
2658 if (u->hdr_mult.value)
2659 if (u->hdr_mult.value != u->surface->hdr_mult.value) {
2660 update_flags->bits.hdr_mult = 1;
2661 elevate_update_type(&overall_type, UPDATE_TYPE_MED);
2664 if (u->cm2_params) {
2665 if ((u->cm2_params->component_settings.shaper_3dlut_setting
2666 != u->surface->mcm_shaper_3dlut_setting)
2667 || (u->cm2_params->component_settings.lut1d_enable
2668 != u->surface->mcm_lut1d_enable))
2669 update_flags->bits.mcm_transfer_function_enable_change = 1;
2670 if (u->cm2_params->cm2_luts.lut3d_data.lut3d_src
2671 != u->surface->mcm_luts.lut3d_data.lut3d_src)
2672 update_flags->bits.mcm_transfer_function_enable_change = 1;
2674 if (update_flags->bits.in_transfer_func_change) {
2675 type = UPDATE_TYPE_MED;
2676 elevate_update_type(&overall_type, type);
2679 if (update_flags->bits.lut_3d) {
2680 type = UPDATE_TYPE_FULL;
2681 elevate_update_type(&overall_type, type);
2683 if (update_flags->bits.mcm_transfer_function_enable_change) {
2684 type = UPDATE_TYPE_FULL;
2685 elevate_update_type(&overall_type, type);
2688 if (dc->debug.enable_legacy_fast_update &&
2689 (update_flags->bits.gamma_change ||
2690 update_flags->bits.gamut_remap_change ||
2691 update_flags->bits.input_csc_change ||
2692 update_flags->bits.coeff_reduction_change)) {
2693 type = UPDATE_TYPE_FULL;
2694 elevate_update_type(&overall_type, type);
2696 return overall_type;
2699 static enum surface_update_type check_update_surfaces_for_stream(
2701 struct dc_surface_update *updates,
2703 struct dc_stream_update *stream_update,
2704 const struct dc_stream_status *stream_status)
2707 enum surface_update_type overall_type = UPDATE_TYPE_FAST;
2709 if (dc->idle_optimizations_allowed)
2710 overall_type = UPDATE_TYPE_FULL;
2712 if (stream_status == NULL || stream_status->plane_count != surface_count)
2713 overall_type = UPDATE_TYPE_FULL;
2715 if (stream_update && stream_update->pending_test_pattern) {
2716 overall_type = UPDATE_TYPE_FULL;
2719 /* some stream updates require passive update */
2720 if (stream_update) {
2721 union stream_update_flags *su_flags = &stream_update->stream->update_flags;
2723 if ((stream_update->src.height != 0 && stream_update->src.width != 0) ||
2724 (stream_update->dst.height != 0 && stream_update->dst.width != 0) ||
2725 stream_update->integer_scaling_update)
2726 su_flags->bits.scaling = 1;
2728 if (dc->debug.enable_legacy_fast_update && stream_update->out_transfer_func)
2729 su_flags->bits.out_tf = 1;
2731 if (stream_update->abm_level)
2732 su_flags->bits.abm_level = 1;
2734 if (stream_update->dpms_off)
2735 su_flags->bits.dpms_off = 1;
2737 if (stream_update->gamut_remap)
2738 su_flags->bits.gamut_remap = 1;
2740 if (stream_update->wb_update)
2741 su_flags->bits.wb_update = 1;
2743 if (stream_update->dsc_config)
2744 su_flags->bits.dsc_changed = 1;
2746 if (stream_update->mst_bw_update)
2747 su_flags->bits.mst_bw = 1;
2749 if (stream_update->stream->freesync_on_desktop &&
2750 (stream_update->vrr_infopacket || stream_update->allow_freesync ||
2751 stream_update->vrr_active_variable || stream_update->vrr_active_fixed))
2752 su_flags->bits.fams_changed = 1;
2754 if (su_flags->raw != 0)
2755 overall_type = UPDATE_TYPE_FULL;
2757 if (stream_update->output_csc_transform || stream_update->output_color_space)
2758 su_flags->bits.out_csc = 1;
2760 /* Output transfer function changes do not require bandwidth recalculation,
2761 * so don't trigger a full update
2763 if (!dc->debug.enable_legacy_fast_update && stream_update->out_transfer_func)
2764 su_flags->bits.out_tf = 1;
2767 for (i = 0 ; i < surface_count; i++) {
2768 enum surface_update_type type =
2769 det_surface_update(dc, &updates[i]);
2771 elevate_update_type(&overall_type, type);
2774 return overall_type;
2778 * dc_check_update_surfaces_for_stream() - Determine update type (fast, med, or full)
2780 * See :c:type:`enum surface_update_type <surface_update_type>` for explanation of update types
2782 enum surface_update_type dc_check_update_surfaces_for_stream(
2784 struct dc_surface_update *updates,
2786 struct dc_stream_update *stream_update,
2787 const struct dc_stream_status *stream_status)
2790 enum surface_update_type type;
2793 stream_update->stream->update_flags.raw = 0;
2794 for (i = 0; i < surface_count; i++)
2795 updates[i].surface->update_flags.raw = 0;
2797 type = check_update_surfaces_for_stream(dc, updates, surface_count, stream_update, stream_status);
2798 if (type == UPDATE_TYPE_FULL) {
2799 if (stream_update) {
2800 uint32_t dsc_changed = stream_update->stream->update_flags.bits.dsc_changed;
2801 stream_update->stream->update_flags.raw = 0xFFFFFFFF;
2802 stream_update->stream->update_flags.bits.dsc_changed = dsc_changed;
2804 for (i = 0; i < surface_count; i++)
2805 updates[i].surface->update_flags.raw = 0xFFFFFFFF;
2808 if (type == UPDATE_TYPE_FAST) {
2809 // If there's an available clock comparator, we use that.
2810 if (dc->clk_mgr->funcs->are_clock_states_equal) {
2811 if (!dc->clk_mgr->funcs->are_clock_states_equal(&dc->clk_mgr->clks, &dc->current_state->bw_ctx.bw.dcn.clk))
2812 dc->optimized_required = true;
2813 // Else we fallback to mem compare.
2814 } 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) {
2815 dc->optimized_required = true;
2818 dc->optimized_required |= dc->wm_optimized_required;
2824 static struct dc_stream_status *stream_get_status(
2825 struct dc_state *ctx,
2826 struct dc_stream_state *stream)
2830 for (i = 0; i < ctx->stream_count; i++) {
2831 if (stream == ctx->streams[i]) {
2832 return &ctx->stream_status[i];
2839 static const enum surface_update_type update_surface_trace_level = UPDATE_TYPE_FULL;
2841 static void copy_surface_update_to_plane(
2842 struct dc_plane_state *surface,
2843 struct dc_surface_update *srf_update)
2845 if (srf_update->flip_addr) {
2846 surface->address = srf_update->flip_addr->address;
2847 surface->flip_immediate =
2848 srf_update->flip_addr->flip_immediate;
2849 surface->time.time_elapsed_in_us[surface->time.index] =
2850 srf_update->flip_addr->flip_timestamp_in_us -
2851 surface->time.prev_update_time_in_us;
2852 surface->time.prev_update_time_in_us =
2853 srf_update->flip_addr->flip_timestamp_in_us;
2854 surface->time.index++;
2855 if (surface->time.index >= DC_PLANE_UPDATE_TIMES_MAX)
2856 surface->time.index = 0;
2858 surface->triplebuffer_flips = srf_update->flip_addr->triplebuffer_flips;
2861 if (srf_update->scaling_info) {
2862 surface->scaling_quality =
2863 srf_update->scaling_info->scaling_quality;
2865 srf_update->scaling_info->dst_rect;
2867 srf_update->scaling_info->src_rect;
2868 surface->clip_rect =
2869 srf_update->scaling_info->clip_rect;
2872 if (srf_update->plane_info) {
2873 surface->color_space =
2874 srf_update->plane_info->color_space;
2876 srf_update->plane_info->format;
2877 surface->plane_size =
2878 srf_update->plane_info->plane_size;
2880 srf_update->plane_info->rotation;
2881 surface->horizontal_mirror =
2882 srf_update->plane_info->horizontal_mirror;
2883 surface->stereo_format =
2884 srf_update->plane_info->stereo_format;
2885 surface->tiling_info =
2886 srf_update->plane_info->tiling_info;
2888 srf_update->plane_info->visible;
2889 surface->per_pixel_alpha =
2890 srf_update->plane_info->per_pixel_alpha;
2891 surface->global_alpha =
2892 srf_update->plane_info->global_alpha;
2893 surface->global_alpha_value =
2894 srf_update->plane_info->global_alpha_value;
2896 srf_update->plane_info->dcc;
2897 surface->layer_index =
2898 srf_update->plane_info->layer_index;
2901 if (srf_update->gamma) {
2902 memcpy(&surface->gamma_correction.entries,
2903 &srf_update->gamma->entries,
2904 sizeof(struct dc_gamma_entries));
2905 surface->gamma_correction.is_identity =
2906 srf_update->gamma->is_identity;
2907 surface->gamma_correction.num_entries =
2908 srf_update->gamma->num_entries;
2909 surface->gamma_correction.type =
2910 srf_update->gamma->type;
2913 if (srf_update->in_transfer_func) {
2914 surface->in_transfer_func.sdr_ref_white_level =
2915 srf_update->in_transfer_func->sdr_ref_white_level;
2916 surface->in_transfer_func.tf =
2917 srf_update->in_transfer_func->tf;
2918 surface->in_transfer_func.type =
2919 srf_update->in_transfer_func->type;
2920 memcpy(&surface->in_transfer_func.tf_pts,
2921 &srf_update->in_transfer_func->tf_pts,
2922 sizeof(struct dc_transfer_func_distributed_points));
2925 if (srf_update->func_shaper)
2926 memcpy(&surface->in_shaper_func, srf_update->func_shaper,
2927 sizeof(surface->in_shaper_func));
2929 if (srf_update->lut3d_func)
2930 memcpy(&surface->lut3d_func, srf_update->lut3d_func,
2931 sizeof(surface->lut3d_func));
2933 if (srf_update->hdr_mult.value)
2935 srf_update->hdr_mult;
2937 if (srf_update->blend_tf)
2938 memcpy(&surface->blend_tf, srf_update->blend_tf,
2939 sizeof(surface->blend_tf));
2941 if (srf_update->input_csc_color_matrix)
2942 surface->input_csc_color_matrix =
2943 *srf_update->input_csc_color_matrix;
2945 if (srf_update->coeff_reduction_factor)
2946 surface->coeff_reduction_factor =
2947 *srf_update->coeff_reduction_factor;
2949 if (srf_update->gamut_remap_matrix)
2950 surface->gamut_remap_matrix =
2951 *srf_update->gamut_remap_matrix;
2952 if (srf_update->cm2_params) {
2953 surface->mcm_shaper_3dlut_setting = srf_update->cm2_params->component_settings.shaper_3dlut_setting;
2954 surface->mcm_lut1d_enable = srf_update->cm2_params->component_settings.lut1d_enable;
2955 surface->mcm_luts = srf_update->cm2_params->cm2_luts;
2957 if (srf_update->cursor_csc_color_matrix)
2958 surface->cursor_csc_color_matrix =
2959 *srf_update->cursor_csc_color_matrix;
2962 static void copy_stream_update_to_stream(struct dc *dc,
2963 struct dc_state *context,
2964 struct dc_stream_state *stream,
2965 struct dc_stream_update *update)
2967 struct dc_context *dc_ctx = dc->ctx;
2969 if (update == NULL || stream == NULL)
2972 if (update->src.height && update->src.width)
2973 stream->src = update->src;
2975 if (update->dst.height && update->dst.width)
2976 stream->dst = update->dst;
2978 if (update->out_transfer_func) {
2979 stream->out_transfer_func.sdr_ref_white_level =
2980 update->out_transfer_func->sdr_ref_white_level;
2981 stream->out_transfer_func.tf = update->out_transfer_func->tf;
2982 stream->out_transfer_func.type =
2983 update->out_transfer_func->type;
2984 memcpy(&stream->out_transfer_func.tf_pts,
2985 &update->out_transfer_func->tf_pts,
2986 sizeof(struct dc_transfer_func_distributed_points));
2989 if (update->hdr_static_metadata)
2990 stream->hdr_static_metadata = *update->hdr_static_metadata;
2992 if (update->abm_level)
2993 stream->abm_level = *update->abm_level;
2995 if (update->periodic_interrupt)
2996 stream->periodic_interrupt = *update->periodic_interrupt;
2998 if (update->gamut_remap)
2999 stream->gamut_remap_matrix = *update->gamut_remap;
3001 /* Note: this being updated after mode set is currently not a use case
3002 * however if it arises OCSC would need to be reprogrammed at the
3005 if (update->output_color_space)
3006 stream->output_color_space = *update->output_color_space;
3008 if (update->output_csc_transform)
3009 stream->csc_color_matrix = *update->output_csc_transform;
3011 if (update->vrr_infopacket)
3012 stream->vrr_infopacket = *update->vrr_infopacket;
3014 if (update->allow_freesync)
3015 stream->allow_freesync = *update->allow_freesync;
3017 if (update->vrr_active_variable)
3018 stream->vrr_active_variable = *update->vrr_active_variable;
3020 if (update->vrr_active_fixed)
3021 stream->vrr_active_fixed = *update->vrr_active_fixed;
3023 if (update->crtc_timing_adjust)
3024 stream->adjust = *update->crtc_timing_adjust;
3026 if (update->dpms_off)
3027 stream->dpms_off = *update->dpms_off;
3029 if (update->hfvsif_infopacket)
3030 stream->hfvsif_infopacket = *update->hfvsif_infopacket;
3032 if (update->vtem_infopacket)
3033 stream->vtem_infopacket = *update->vtem_infopacket;
3035 if (update->vsc_infopacket)
3036 stream->vsc_infopacket = *update->vsc_infopacket;
3038 if (update->vsp_infopacket)
3039 stream->vsp_infopacket = *update->vsp_infopacket;
3041 if (update->adaptive_sync_infopacket)
3042 stream->adaptive_sync_infopacket = *update->adaptive_sync_infopacket;
3044 if (update->dither_option)
3045 stream->dither_option = *update->dither_option;
3047 if (update->pending_test_pattern)
3048 stream->test_pattern = *update->pending_test_pattern;
3049 /* update current stream with writeback info */
3050 if (update->wb_update) {
3053 stream->num_wb_info = update->wb_update->num_wb_info;
3054 ASSERT(stream->num_wb_info <= MAX_DWB_PIPES);
3055 for (i = 0; i < stream->num_wb_info; i++)
3056 stream->writeback_info[i] =
3057 update->wb_update->writeback_info[i];
3059 if (update->dsc_config) {
3060 struct dc_dsc_config old_dsc_cfg = stream->timing.dsc_cfg;
3061 uint32_t old_dsc_enabled = stream->timing.flags.DSC;
3062 uint32_t enable_dsc = (update->dsc_config->num_slices_h != 0 &&
3063 update->dsc_config->num_slices_v != 0);
3065 /* Use temporarry context for validating new DSC config */
3066 struct dc_state *dsc_validate_context = dc_state_create_copy(dc->current_state);
3068 if (dsc_validate_context) {
3069 stream->timing.dsc_cfg = *update->dsc_config;
3070 stream->timing.flags.DSC = enable_dsc;
3071 if (!dc->res_pool->funcs->validate_bandwidth(dc, dsc_validate_context, true)) {
3072 stream->timing.dsc_cfg = old_dsc_cfg;
3073 stream->timing.flags.DSC = old_dsc_enabled;
3074 update->dsc_config = NULL;
3077 dc_state_release(dsc_validate_context);
3079 DC_ERROR("Failed to allocate new validate context for DSC change\n");
3080 update->dsc_config = NULL;
3085 static void backup_planes_and_stream_state(
3086 struct dc_scratch_space *scratch,
3087 struct dc_stream_state *stream)
3090 struct dc_stream_status *status = dc_stream_get_status(stream);
3095 for (i = 0; i < status->plane_count; i++) {
3096 scratch->plane_states[i] = *status->plane_states[i];
3098 scratch->stream_state = *stream;
3101 static void restore_planes_and_stream_state(
3102 struct dc_scratch_space *scratch,
3103 struct dc_stream_state *stream)
3106 struct dc_stream_status *status = dc_stream_get_status(stream);
3111 for (i = 0; i < status->plane_count; i++) {
3112 *status->plane_states[i] = scratch->plane_states[i];
3114 *stream = scratch->stream_state;
3118 * update_seamless_boot_flags() - Helper function for updating seamless boot flags
3120 * @dc: Current DC state
3121 * @context: New DC state to be programmed
3122 * @surface_count: Number of surfaces that have an updated
3123 * @stream: Corresponding stream to be updated in the current flip
3125 * Updating seamless boot flags do not need to be part of the commit sequence. This
3126 * helper function will update the seamless boot flags on each flip (if required)
3127 * outside of the HW commit sequence (fast or slow).
3131 static void update_seamless_boot_flags(struct dc *dc,
3132 struct dc_state *context,
3134 struct dc_stream_state *stream)
3136 if (get_seamless_boot_stream_count(context) > 0 && surface_count > 0) {
3137 /* Optimize seamless boot flag keeps clocks and watermarks high until
3138 * first flip. After first flip, optimization is required to lower
3139 * bandwidth. Important to note that it is expected UEFI will
3140 * only light up a single display on POST, therefore we only expect
3141 * one stream with seamless boot flag set.
3143 if (stream->apply_seamless_boot_optimization) {
3144 stream->apply_seamless_boot_optimization = false;
3146 if (get_seamless_boot_stream_count(context) == 0)
3147 dc->optimized_required = true;
3153 * update_planes_and_stream_state() - The function takes planes and stream
3154 * updates as inputs and determines the appropriate update type. If update type
3155 * is FULL, the function allocates a new context, populates and validates it.
3156 * Otherwise, it updates current dc context. The function will return both
3157 * new_context and new_update_type back to the caller. The function also backs
3158 * up both current and new contexts into corresponding dc state scratch memory.
3159 * TODO: The function does too many things, and even conditionally allocates dc
3160 * context memory implicitly. We should consider to break it down.
3162 * @dc: Current DC state
3163 * @srf_updates: an array of surface updates
3164 * @surface_count: surface update count
3165 * @stream: Corresponding stream to be updated
3166 * @stream_update: stream update
3167 * @new_update_type: [out] determined update type by the function
3168 * @new_context: [out] new context allocated and validated if update type is
3169 * FULL, reference to current context if update type is less than FULL.
3171 * Return: true if a valid update is populated into new_context, false
3174 static bool update_planes_and_stream_state(struct dc *dc,
3175 struct dc_surface_update *srf_updates, int surface_count,
3176 struct dc_stream_state *stream,
3177 struct dc_stream_update *stream_update,
3178 enum surface_update_type *new_update_type,
3179 struct dc_state **new_context)
3181 struct dc_state *context;
3183 enum surface_update_type update_type;
3184 const struct dc_stream_status *stream_status;
3185 struct dc_context *dc_ctx = dc->ctx;
3187 stream_status = dc_stream_get_status(stream);
3189 if (!stream_status) {
3190 if (surface_count) /* Only an error condition if surf_count non-zero*/
3193 return false; /* Cannot commit surface to stream that is not committed */
3196 context = dc->current_state;
3197 update_type = dc_check_update_surfaces_for_stream(
3198 dc, srf_updates, surface_count, stream_update, stream_status);
3199 if (update_type == UPDATE_TYPE_FULL)
3200 backup_planes_and_stream_state(&dc->scratch.current_state, stream);
3202 /* update current stream with the new updates */
3203 copy_stream_update_to_stream(dc, context, stream, stream_update);
3205 /* do not perform surface update if surface has invalid dimensions
3206 * (all zero) and no scaling_info is provided
3208 if (surface_count > 0) {
3209 for (i = 0; i < surface_count; i++) {
3210 if ((srf_updates[i].surface->src_rect.width == 0 ||
3211 srf_updates[i].surface->src_rect.height == 0 ||
3212 srf_updates[i].surface->dst_rect.width == 0 ||
3213 srf_updates[i].surface->dst_rect.height == 0) &&
3214 (!srf_updates[i].scaling_info ||
3215 srf_updates[i].scaling_info->src_rect.width == 0 ||
3216 srf_updates[i].scaling_info->src_rect.height == 0 ||
3217 srf_updates[i].scaling_info->dst_rect.width == 0 ||
3218 srf_updates[i].scaling_info->dst_rect.height == 0)) {
3219 DC_ERROR("Invalid src/dst rects in surface update!\n");
3225 if (update_type >= update_surface_trace_level)
3226 update_surface_trace(dc, srf_updates, surface_count);
3228 for (i = 0; i < surface_count; i++)
3229 copy_surface_update_to_plane(srf_updates[i].surface, &srf_updates[i]);
3231 if (update_type >= UPDATE_TYPE_FULL) {
3232 struct dc_plane_state *new_planes[MAX_SURFACES] = {0};
3234 for (i = 0; i < surface_count; i++)
3235 new_planes[i] = srf_updates[i].surface;
3237 /* initialize scratch memory for building context */
3238 context = dc_state_create_copy(dc->current_state);
3239 if (context == NULL) {
3240 DC_ERROR("Failed to allocate new validate context!\n");
3244 /* For each full update, remove all existing phantom pipes first.
3245 * Ensures that we have enough pipes for newly added MPO planes
3247 dc_state_remove_phantom_streams_and_planes(dc, context);
3248 dc_state_release_phantom_streams_and_planes(dc, context);
3250 /*remove old surfaces from context */
3251 if (!dc_state_rem_all_planes_for_stream(dc, stream, context)) {
3253 BREAK_TO_DEBUGGER();
3257 /* add surface to context */
3258 if (!dc_state_add_all_planes_for_stream(dc, stream, new_planes, surface_count, context)) {
3260 BREAK_TO_DEBUGGER();
3265 /* save update parameters into surface */
3266 for (i = 0; i < surface_count; i++) {
3267 struct dc_plane_state *surface = srf_updates[i].surface;
3269 if (update_type != UPDATE_TYPE_MED)
3271 if (surface->update_flags.bits.clip_size_change ||
3272 surface->update_flags.bits.position_change) {
3273 for (j = 0; j < dc->res_pool->pipe_count; j++) {
3274 struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[j];
3276 if (pipe_ctx->plane_state != surface)
3279 resource_build_scaling_params(pipe_ctx);
3284 if (update_type == UPDATE_TYPE_FULL) {
3285 if (!dc->res_pool->funcs->validate_bandwidth(dc, context, false)) {
3286 BREAK_TO_DEBUGGER();
3290 update_seamless_boot_flags(dc, context, surface_count, stream);
3292 *new_context = context;
3293 *new_update_type = update_type;
3294 if (update_type == UPDATE_TYPE_FULL)
3295 backup_planes_and_stream_state(&dc->scratch.new_state, stream);
3300 dc_state_release(context);
3306 static void commit_planes_do_stream_update(struct dc *dc,
3307 struct dc_stream_state *stream,
3308 struct dc_stream_update *stream_update,
3309 enum surface_update_type update_type,
3310 struct dc_state *context)
3315 for (j = 0; j < dc->res_pool->pipe_count; j++) {
3316 struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[j];
3318 if (resource_is_pipe_type(pipe_ctx, OTG_MASTER) && pipe_ctx->stream == stream) {
3320 if (stream_update->periodic_interrupt && dc->hwss.setup_periodic_interrupt)
3321 dc->hwss.setup_periodic_interrupt(dc, pipe_ctx);
3323 if ((stream_update->hdr_static_metadata && !stream->use_dynamic_meta) ||
3324 stream_update->vrr_infopacket ||
3325 stream_update->vsc_infopacket ||
3326 stream_update->vsp_infopacket ||
3327 stream_update->hfvsif_infopacket ||
3328 stream_update->adaptive_sync_infopacket ||
3329 stream_update->vtem_infopacket) {
3330 resource_build_info_frame(pipe_ctx);
3331 dc->hwss.update_info_frame(pipe_ctx);
3333 if (dc_is_dp_signal(pipe_ctx->stream->signal))
3334 dc->link_srv->dp_trace_source_sequence(
3335 pipe_ctx->stream->link,
3336 DPCD_SOURCE_SEQ_AFTER_UPDATE_INFO_FRAME);
3339 if (stream_update->hdr_static_metadata &&
3340 stream->use_dynamic_meta &&
3341 dc->hwss.set_dmdata_attributes &&
3342 pipe_ctx->stream->dmdata_address.quad_part != 0)
3343 dc->hwss.set_dmdata_attributes(pipe_ctx);
3345 if (stream_update->gamut_remap)
3346 dc_stream_set_gamut_remap(dc, stream);
3348 if (stream_update->output_csc_transform)
3349 dc_stream_program_csc_matrix(dc, stream);
3351 if (stream_update->dither_option) {
3352 struct pipe_ctx *odm_pipe = pipe_ctx->next_odm_pipe;
3353 resource_build_bit_depth_reduction_params(pipe_ctx->stream,
3354 &pipe_ctx->stream->bit_depth_params);
3355 pipe_ctx->stream_res.opp->funcs->opp_program_fmt(pipe_ctx->stream_res.opp,
3356 &stream->bit_depth_params,
3359 odm_pipe->stream_res.opp->funcs->opp_program_fmt(odm_pipe->stream_res.opp,
3360 &stream->bit_depth_params,
3362 odm_pipe = odm_pipe->next_odm_pipe;
3366 if (stream_update->cursor_attributes)
3367 program_cursor_attributes(dc, stream);
3369 if (stream_update->cursor_position)
3370 program_cursor_position(dc, stream);
3373 if (update_type == UPDATE_TYPE_FAST)
3376 if (stream_update->dsc_config)
3377 dc->link_srv->update_dsc_config(pipe_ctx);
3379 if (stream_update->mst_bw_update) {
3380 if (stream_update->mst_bw_update->is_increase)
3381 dc->link_srv->increase_mst_payload(pipe_ctx,
3382 stream_update->mst_bw_update->mst_stream_bw);
3384 dc->link_srv->reduce_mst_payload(pipe_ctx,
3385 stream_update->mst_bw_update->mst_stream_bw);
3388 if (stream_update->pending_test_pattern) {
3390 * test pattern params depends on ODM topology
3391 * changes that we could be applying to front
3392 * end. Since at the current stage front end
3393 * changes are not yet applied. We can only
3394 * apply test pattern in hw based on current
3395 * state and populate the final test pattern
3396 * params in new state. If current and new test
3397 * pattern params are different as result of
3398 * different ODM topology being used, it will be
3399 * detected and handle during front end
3400 * programming update.
3402 dc->link_srv->dp_set_test_pattern(stream->link,
3403 stream->test_pattern.type,
3404 stream->test_pattern.color_space,
3405 stream->test_pattern.p_link_settings,
3406 stream->test_pattern.p_custom_pattern,
3407 stream->test_pattern.cust_pattern_size);
3408 resource_build_test_pattern_params(&context->res_ctx, pipe_ctx);
3411 if (stream_update->dpms_off) {
3412 if (*stream_update->dpms_off) {
3413 dc->link_srv->set_dpms_off(pipe_ctx);
3414 /* for dpms, keep acquired resources*/
3415 if (pipe_ctx->stream_res.audio && !dc->debug.az_endpoint_mute_only)
3416 pipe_ctx->stream_res.audio->funcs->az_disable(pipe_ctx->stream_res.audio);
3418 dc->optimized_required = true;
3421 if (get_seamless_boot_stream_count(context) == 0)
3422 dc->hwss.prepare_bandwidth(dc, dc->current_state);
3423 dc->link_srv->set_dpms_on(dc->current_state, pipe_ctx);
3425 } else if (pipe_ctx->stream->link->wa_flags.blank_stream_on_ocs_change && stream_update->output_color_space
3426 && !stream->dpms_off && dc_is_dp_signal(pipe_ctx->stream->signal)) {
3428 * Workaround for firmware issue in some receivers where they don't pick up
3429 * correct output color space unless DP link is disabled/re-enabled
3431 dc->link_srv->set_dpms_on(dc->current_state, pipe_ctx);
3434 if (stream_update->abm_level && pipe_ctx->stream_res.abm) {
3435 bool should_program_abm = true;
3437 // if otg funcs defined check if blanked before programming
3438 if (pipe_ctx->stream_res.tg->funcs->is_blanked)
3439 if (pipe_ctx->stream_res.tg->funcs->is_blanked(pipe_ctx->stream_res.tg))
3440 should_program_abm = false;
3442 if (should_program_abm) {
3443 if (*stream_update->abm_level == ABM_LEVEL_IMMEDIATE_DISABLE) {
3444 dc->hwss.set_abm_immediate_disable(pipe_ctx);
3446 pipe_ctx->stream_res.abm->funcs->set_abm_level(
3447 pipe_ctx->stream_res.abm, stream->abm_level);
3455 static bool dc_dmub_should_send_dirty_rect_cmd(struct dc *dc, struct dc_stream_state *stream)
3457 if ((stream->link->psr_settings.psr_version == DC_PSR_VERSION_SU_1
3458 || stream->link->psr_settings.psr_version == DC_PSR_VERSION_1)
3459 && stream->ctx->dce_version >= DCN_VERSION_3_1)
3462 if (stream->link->replay_settings.config.replay_supported)
3465 if (stream->ctx->dce_version >= DCN_VERSION_3_5 && stream->abm_level)
3471 void dc_dmub_update_dirty_rect(struct dc *dc,
3473 struct dc_stream_state *stream,
3474 struct dc_surface_update *srf_updates,
3475 struct dc_state *context)
3477 union dmub_rb_cmd cmd;
3478 struct dmub_cmd_update_dirty_rect_data *update_dirty_rect;
3480 unsigned int panel_inst = 0;
3482 if (!dc_dmub_should_send_dirty_rect_cmd(dc, stream))
3485 if (!dc_get_edp_link_panel_inst(dc, stream->link, &panel_inst))
3488 memset(&cmd, 0x0, sizeof(cmd));
3489 cmd.update_dirty_rect.header.type = DMUB_CMD__UPDATE_DIRTY_RECT;
3490 cmd.update_dirty_rect.header.sub_type = 0;
3491 cmd.update_dirty_rect.header.payload_bytes =
3492 sizeof(cmd.update_dirty_rect) -
3493 sizeof(cmd.update_dirty_rect.header);
3494 update_dirty_rect = &cmd.update_dirty_rect.update_dirty_rect_data;
3495 for (i = 0; i < surface_count; i++) {
3496 struct dc_plane_state *plane_state = srf_updates[i].surface;
3497 const struct dc_flip_addrs *flip_addr = srf_updates[i].flip_addr;
3499 if (!srf_updates[i].surface || !flip_addr)
3501 /* Do not send in immediate flip mode */
3502 if (srf_updates[i].surface->flip_immediate)
3505 update_dirty_rect->cmd_version = DMUB_CMD_PSR_CONTROL_VERSION_1;
3506 update_dirty_rect->dirty_rect_count = flip_addr->dirty_rect_count;
3507 memcpy(update_dirty_rect->src_dirty_rects, flip_addr->dirty_rects,
3508 sizeof(flip_addr->dirty_rects));
3509 for (j = 0; j < dc->res_pool->pipe_count; j++) {
3510 struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[j];
3512 if (pipe_ctx->stream != stream)
3514 if (pipe_ctx->plane_state != plane_state)
3517 update_dirty_rect->panel_inst = panel_inst;
3518 update_dirty_rect->pipe_idx = j;
3519 dc_wake_and_execute_dmub_cmd(dc->ctx, &cmd, DM_DMUB_WAIT_TYPE_NO_WAIT);
3524 static void build_dmub_update_dirty_rect(
3527 struct dc_stream_state *stream,
3528 struct dc_surface_update *srf_updates,
3529 struct dc_state *context,
3530 struct dc_dmub_cmd dc_dmub_cmd[],
3531 unsigned int *dmub_cmd_count)
3533 union dmub_rb_cmd cmd;
3534 struct dmub_cmd_update_dirty_rect_data *update_dirty_rect;
3536 unsigned int panel_inst = 0;
3538 if (!dc_dmub_should_send_dirty_rect_cmd(dc, stream))
3541 if (!dc_get_edp_link_panel_inst(dc, stream->link, &panel_inst))
3544 memset(&cmd, 0x0, sizeof(cmd));
3545 cmd.update_dirty_rect.header.type = DMUB_CMD__UPDATE_DIRTY_RECT;
3546 cmd.update_dirty_rect.header.sub_type = 0;
3547 cmd.update_dirty_rect.header.payload_bytes =
3548 sizeof(cmd.update_dirty_rect) -
3549 sizeof(cmd.update_dirty_rect.header);
3550 update_dirty_rect = &cmd.update_dirty_rect.update_dirty_rect_data;
3551 for (i = 0; i < surface_count; i++) {
3552 struct dc_plane_state *plane_state = srf_updates[i].surface;
3553 const struct dc_flip_addrs *flip_addr = srf_updates[i].flip_addr;
3555 if (!srf_updates[i].surface || !flip_addr)
3557 /* Do not send in immediate flip mode */
3558 if (srf_updates[i].surface->flip_immediate)
3560 update_dirty_rect->cmd_version = DMUB_CMD_PSR_CONTROL_VERSION_1;
3561 update_dirty_rect->dirty_rect_count = flip_addr->dirty_rect_count;
3562 memcpy(update_dirty_rect->src_dirty_rects, flip_addr->dirty_rects,
3563 sizeof(flip_addr->dirty_rects));
3564 for (j = 0; j < dc->res_pool->pipe_count; j++) {
3565 struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[j];
3567 if (pipe_ctx->stream != stream)
3569 if (pipe_ctx->plane_state != plane_state)
3571 update_dirty_rect->panel_inst = panel_inst;
3572 update_dirty_rect->pipe_idx = j;
3573 dc_dmub_cmd[*dmub_cmd_count].dmub_cmd = cmd;
3574 dc_dmub_cmd[*dmub_cmd_count].wait_type = DM_DMUB_WAIT_TYPE_NO_WAIT;
3575 (*dmub_cmd_count)++;
3580 static bool check_address_only_update(union surface_update_flags update_flags)
3582 union surface_update_flags addr_only_update_flags;
3583 addr_only_update_flags.raw = 0;
3584 addr_only_update_flags.bits.addr_update = 1;
3586 return update_flags.bits.addr_update &&
3587 !(update_flags.raw & ~addr_only_update_flags.raw);
3591 * build_dmub_cmd_list() - Build an array of DMCUB commands to be sent to DMCUB
3593 * @dc: Current DC state
3594 * @srf_updates: Array of surface updates
3595 * @surface_count: Number of surfaces that have an updated
3596 * @stream: Corresponding stream to be updated in the current flip
3597 * @context: New DC state to be programmed
3599 * @dc_dmub_cmd: Array of DMCUB commands to be sent to DMCUB
3600 * @dmub_cmd_count: Count indicating the number of DMCUB commands in dc_dmub_cmd array
3602 * This function builds an array of DMCUB commands to be sent to DMCUB. This function is required
3603 * to build an array of commands and have them sent while the OTG lock is acquired.
3607 static void build_dmub_cmd_list(struct dc *dc,
3608 struct dc_surface_update *srf_updates,
3610 struct dc_stream_state *stream,
3611 struct dc_state *context,
3612 struct dc_dmub_cmd dc_dmub_cmd[],
3613 unsigned int *dmub_cmd_count)
3615 // Initialize cmd count to 0
3616 *dmub_cmd_count = 0;
3617 build_dmub_update_dirty_rect(dc, surface_count, stream, srf_updates, context, dc_dmub_cmd, dmub_cmd_count);
3620 static void commit_plane_for_stream_offload_fams2_flip(struct dc *dc,
3621 struct dc_surface_update *srf_updates,
3623 struct dc_stream_state *stream,
3624 struct dc_state *context)
3628 /* update dirty rect for PSR */
3629 dc_dmub_update_dirty_rect(dc, surface_count, stream,
3630 srf_updates, context);
3632 /* Perform requested Updates */
3633 for (i = 0; i < surface_count; i++) {
3634 struct dc_plane_state *plane_state = srf_updates[i].surface;
3636 for (j = 0; j < dc->res_pool->pipe_count; j++) {
3637 struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[j];
3639 if (!should_update_pipe_for_stream(context, pipe_ctx, stream))
3642 if (!should_update_pipe_for_plane(context, pipe_ctx, plane_state))
3645 /* update pipe context for plane */
3646 if (pipe_ctx->plane_state->update_flags.bits.addr_update)
3647 dc->hwss.update_plane_addr(dc, pipe_ctx);
3651 /* Send commands to DMCUB */
3652 dc_dmub_srv_fams2_passthrough_flip(dc,
3659 static void commit_planes_for_stream_fast(struct dc *dc,
3660 struct dc_surface_update *srf_updates,
3662 struct dc_stream_state *stream,
3663 struct dc_stream_update *stream_update,
3664 enum surface_update_type update_type,
3665 struct dc_state *context)
3668 struct pipe_ctx *top_pipe_to_program = NULL;
3669 struct dc_stream_status *stream_status = NULL;
3670 bool should_offload_fams2_flip = false;
3672 if (dc->debug.fams2_config.bits.enable &&
3673 dc->debug.fams2_config.bits.enable_offload_flip &&
3674 dc_state_is_fams2_in_use(dc, context)) {
3675 /* if not offloading to HWFQ, offload to FAMS2 if needed */
3676 should_offload_fams2_flip = true;
3677 for (i = 0; i < surface_count; i++) {
3678 if (srf_updates[i].surface &&
3679 srf_updates[i].surface->update_flags.raw &&
3680 !check_address_only_update(srf_updates[i].surface->update_flags)) {
3681 /* more than address update, need to acquire FAMS2 lock */
3682 should_offload_fams2_flip = false;
3686 if (stream_update) {
3687 /* more than address update, need to acquire FAMS2 lock */
3688 should_offload_fams2_flip = false;
3692 dc_exit_ips_for_hw_access(dc);
3696 top_pipe_to_program = resource_get_otg_master_for_stream(
3700 if (!top_pipe_to_program)
3703 for (i = 0; i < dc->res_pool->pipe_count; i++) {
3704 struct pipe_ctx *pipe = &context->res_ctx.pipe_ctx[i];
3706 if (pipe->stream && pipe->plane_state) {
3707 set_p_state_switch_method(dc, context, pipe);
3709 if (dc->debug.visual_confirm)
3710 dc_update_visual_confirm_color(dc, context, pipe);
3714 for (i = 0; i < surface_count; i++) {
3715 struct dc_plane_state *plane_state = srf_updates[i].surface;
3716 /*set logical flag for lock/unlock use*/
3717 for (j = 0; j < dc->res_pool->pipe_count; j++) {
3718 struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[j];
3720 if (!pipe_ctx->plane_state)
3722 if (should_update_pipe_for_plane(context, pipe_ctx, plane_state))
3724 pipe_ctx->plane_state->triplebuffer_flips = false;
3725 if (update_type == UPDATE_TYPE_FAST &&
3726 dc->hwss.program_triplebuffer != NULL &&
3727 !pipe_ctx->plane_state->flip_immediate && dc->debug.enable_tri_buf) {
3728 /*triple buffer for VUpdate only*/
3729 pipe_ctx->plane_state->triplebuffer_flips = true;
3734 stream_status = dc_state_get_stream_status(context, stream);
3736 if (should_offload_fams2_flip) {
3737 commit_plane_for_stream_offload_fams2_flip(dc,
3743 build_dmub_cmd_list(dc,
3748 context->dc_dmub_cmd,
3749 &(context->dmub_cmd_count));
3750 hwss_build_fast_sequence(dc,
3751 context->dc_dmub_cmd,
3752 context->dmub_cmd_count,
3753 context->block_sequence,
3754 &(context->block_sequence_steps),
3755 top_pipe_to_program,
3758 hwss_execute_sequence(dc,
3759 context->block_sequence,
3760 context->block_sequence_steps);
3763 /* Clear update flags so next flip doesn't have redundant programming
3764 * (if there's no stream update, the update flags are not cleared).
3765 * Surface updates are cleared unconditionally at the beginning of each flip,
3766 * so no need to clear here.
3768 if (top_pipe_to_program->stream)
3769 top_pipe_to_program->stream->update_flags.raw = 0;
3772 static void wait_for_outstanding_hw_updates(struct dc *dc, struct dc_state *dc_context)
3775 * This function calls HWSS to wait for any potentially double buffered
3776 * operations to complete. It should be invoked as a pre-amble prior
3777 * to full update programming before asserting any HW locks.
3781 int opp_count = dc->res_pool->res_cap->num_opp;
3784 const struct pipe_ctx *pipe_ctx;
3786 for (pipe_idx = 0; pipe_idx < dc->res_pool->pipe_count; pipe_idx++) {
3787 pipe_ctx = &dc_context->res_ctx.pipe_ctx[pipe_idx];
3789 if (!pipe_ctx->stream)
3792 if (pipe_ctx->stream_res.tg->funcs->wait_drr_doublebuffer_pending_clear)
3793 pipe_ctx->stream_res.tg->funcs->wait_drr_doublebuffer_pending_clear(pipe_ctx->stream_res.tg);
3795 hubp = pipe_ctx->plane_res.hubp;
3799 mpcc_inst = hubp->inst;
3800 // MPCC inst is equal to pipe index in practice
3801 for (opp_inst = 0; opp_inst < opp_count; opp_inst++) {
3802 if ((dc->res_pool->opps[opp_inst] != NULL) &&
3803 (dc->res_pool->opps[opp_inst]->mpcc_disconnect_pending[mpcc_inst])) {
3804 dc->res_pool->mpc->funcs->wait_for_idle(dc->res_pool->mpc, mpcc_inst);
3805 dc->res_pool->opps[opp_inst]->mpcc_disconnect_pending[mpcc_inst] = false;
3810 wait_for_odm_update_pending_complete(dc, dc_context);
3813 static void commit_planes_for_stream(struct dc *dc,
3814 struct dc_surface_update *srf_updates,
3816 struct dc_stream_state *stream,
3817 struct dc_stream_update *stream_update,
3818 enum surface_update_type update_type,
3819 struct dc_state *context)
3822 struct pipe_ctx *top_pipe_to_program = NULL;
3823 bool should_lock_all_pipes = (update_type != UPDATE_TYPE_FAST);
3824 bool subvp_prev_use = false;
3825 bool subvp_curr_use = false;
3826 uint8_t current_stream_mask = 0;
3828 // Once we apply the new subvp context to hardware it won't be in the
3829 // dc->current_state anymore, so we have to cache it before we apply
3830 // the new SubVP context
3831 subvp_prev_use = false;
3832 dc_exit_ips_for_hw_access(dc);
3835 if (update_type == UPDATE_TYPE_FULL)
3836 wait_for_outstanding_hw_updates(dc, context);
3838 for (i = 0; i < dc->res_pool->pipe_count; i++) {
3839 struct pipe_ctx *pipe = &context->res_ctx.pipe_ctx[i];
3841 if (pipe->stream && pipe->plane_state) {
3842 set_p_state_switch_method(dc, context, pipe);
3844 if (dc->debug.visual_confirm)
3845 dc_update_visual_confirm_color(dc, context, pipe);
3849 if (update_type == UPDATE_TYPE_FULL) {
3850 dc_allow_idle_optimizations(dc, false);
3852 if (get_seamless_boot_stream_count(context) == 0)
3853 dc->hwss.prepare_bandwidth(dc, context);
3855 if (dc->hwss.update_dsc_pg)
3856 dc->hwss.update_dsc_pg(dc, context, false);
3858 context_clock_trace(dc, context);
3861 top_pipe_to_program = resource_get_otg_master_for_stream(
3864 ASSERT(top_pipe_to_program != NULL);
3865 for (i = 0; i < dc->res_pool->pipe_count; i++) {
3866 struct pipe_ctx *old_pipe = &dc->current_state->res_ctx.pipe_ctx[i];
3868 // Check old context for SubVP
3869 subvp_prev_use |= (dc_state_get_pipe_subvp_type(dc->current_state, old_pipe) == SUBVP_PHANTOM);
3874 for (i = 0; i < dc->res_pool->pipe_count; i++) {
3875 struct pipe_ctx *pipe = &context->res_ctx.pipe_ctx[i];
3877 if (dc_state_get_pipe_subvp_type(context, pipe) == SUBVP_PHANTOM) {
3878 subvp_curr_use = true;
3883 if (stream->test_pattern.type != DP_TEST_PATTERN_VIDEO_MODE) {
3884 struct pipe_ctx *mpcc_pipe;
3885 struct pipe_ctx *odm_pipe;
3887 for (mpcc_pipe = top_pipe_to_program; mpcc_pipe; mpcc_pipe = mpcc_pipe->bottom_pipe)
3888 for (odm_pipe = mpcc_pipe; odm_pipe; odm_pipe = odm_pipe->next_odm_pipe)
3889 odm_pipe->ttu_regs.min_ttu_vblank = MAX_TTU;
3892 if (update_type != UPDATE_TYPE_FAST && dc->res_pool->funcs->prepare_mcache_programming)
3893 dc->res_pool->funcs->prepare_mcache_programming(dc, context);
3895 if ((update_type != UPDATE_TYPE_FAST) && stream->update_flags.bits.dsc_changed)
3896 if (top_pipe_to_program &&
3897 top_pipe_to_program->stream_res.tg->funcs->lock_doublebuffer_enable) {
3898 if (should_use_dmub_lock(stream->link)) {
3899 union dmub_hw_lock_flags hw_locks = { 0 };
3900 struct dmub_hw_lock_inst_flags inst_flags = { 0 };
3902 hw_locks.bits.lock_dig = 1;
3903 inst_flags.dig_inst = top_pipe_to_program->stream_res.tg->inst;
3905 dmub_hw_lock_mgr_cmd(dc->ctx->dmub_srv,
3910 top_pipe_to_program->stream_res.tg->funcs->lock_doublebuffer_enable(
3911 top_pipe_to_program->stream_res.tg);
3914 if (dc->hwss.wait_for_dcc_meta_propagation) {
3915 dc->hwss.wait_for_dcc_meta_propagation(dc, top_pipe_to_program);
3918 if (should_lock_all_pipes && dc->hwss.interdependent_update_lock) {
3919 if (dc->hwss.subvp_pipe_control_lock)
3920 dc->hwss.subvp_pipe_control_lock(dc, context, true, should_lock_all_pipes, NULL, subvp_prev_use);
3922 if (dc->hwss.fams2_global_control_lock)
3923 dc->hwss.fams2_global_control_lock(dc, context, true);
3925 dc->hwss.interdependent_update_lock(dc, context, true);
3927 if (dc->hwss.subvp_pipe_control_lock)
3928 dc->hwss.subvp_pipe_control_lock(dc, context, true, should_lock_all_pipes, top_pipe_to_program, subvp_prev_use);
3930 if (dc->hwss.fams2_global_control_lock)
3931 dc->hwss.fams2_global_control_lock(dc, context, true);
3933 /* Lock the top pipe while updating plane addrs, since freesync requires
3934 * plane addr update event triggers to be synchronized.
3935 * top_pipe_to_program is expected to never be NULL
3937 dc->hwss.pipe_control_lock(dc, top_pipe_to_program, true);
3940 dc_dmub_update_dirty_rect(dc, surface_count, stream, srf_updates, context);
3944 commit_planes_do_stream_update(dc, stream, stream_update, update_type, context);
3946 if (surface_count == 0) {
3948 * In case of turning off screen, no need to program front end a second time.
3949 * just return after program blank.
3951 if (dc->hwss.apply_ctx_for_surface)
3952 dc->hwss.apply_ctx_for_surface(dc, stream, 0, context);
3953 if (dc->hwss.program_front_end_for_ctx)
3954 dc->hwss.program_front_end_for_ctx(dc, context);
3956 if (should_lock_all_pipes && dc->hwss.interdependent_update_lock) {
3957 dc->hwss.interdependent_update_lock(dc, context, false);
3959 dc->hwss.pipe_control_lock(dc, top_pipe_to_program, false);
3961 dc->hwss.post_unlock_program_front_end(dc, context);
3963 if (update_type != UPDATE_TYPE_FAST)
3964 if (dc->hwss.commit_subvp_config)
3965 dc->hwss.commit_subvp_config(dc, context);
3967 /* Since phantom pipe programming is moved to post_unlock_program_front_end,
3968 * move the SubVP lock to after the phantom pipes have been setup
3970 if (dc->hwss.subvp_pipe_control_lock)
3971 dc->hwss.subvp_pipe_control_lock(dc, context, false, should_lock_all_pipes,
3972 NULL, subvp_prev_use);
3974 if (dc->hwss.fams2_global_control_lock)
3975 dc->hwss.fams2_global_control_lock(dc, context, false);
3980 if (update_type != UPDATE_TYPE_FAST) {
3981 for (j = 0; j < dc->res_pool->pipe_count; j++) {
3982 struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[j];
3984 if ((dc->debug.visual_confirm == VISUAL_CONFIRM_SUBVP ||
3985 dc->debug.visual_confirm == VISUAL_CONFIRM_MCLK_SWITCH) &&
3986 pipe_ctx->stream && pipe_ctx->plane_state) {
3987 /* Only update visual confirm for SUBVP and Mclk switching here.
3988 * The bar appears on all pipes, so we need to update the bar on all displays,
3989 * so the information doesn't get stale.
3991 dc->hwss.update_visual_confirm_color(dc, pipe_ctx,
3992 pipe_ctx->plane_res.hubp->inst);
3997 for (i = 0; i < surface_count; i++) {
3998 struct dc_plane_state *plane_state = srf_updates[i].surface;
4000 /*set logical flag for lock/unlock use*/
4001 for (j = 0; j < dc->res_pool->pipe_count; j++) {
4002 struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[j];
4003 if (!pipe_ctx->plane_state)
4005 if (should_update_pipe_for_plane(context, pipe_ctx, plane_state))
4007 pipe_ctx->plane_state->triplebuffer_flips = false;
4008 if (update_type == UPDATE_TYPE_FAST &&
4009 dc->hwss.program_triplebuffer != NULL &&
4010 !pipe_ctx->plane_state->flip_immediate && dc->debug.enable_tri_buf) {
4011 /*triple buffer for VUpdate only*/
4012 pipe_ctx->plane_state->triplebuffer_flips = true;
4015 if (update_type == UPDATE_TYPE_FULL) {
4016 /* force vsync flip when reconfiguring pipes to prevent underflow */
4017 plane_state->flip_immediate = false;
4021 // Update Type FULL, Surface updates
4022 for (j = 0; j < dc->res_pool->pipe_count; j++) {
4023 struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[j];
4025 if (!pipe_ctx->top_pipe &&
4026 !pipe_ctx->prev_odm_pipe &&
4027 should_update_pipe_for_stream(context, pipe_ctx, stream)) {
4028 struct dc_stream_status *stream_status = NULL;
4030 if (!pipe_ctx->plane_state)
4034 if (update_type == UPDATE_TYPE_FAST)
4037 ASSERT(!pipe_ctx->plane_state->triplebuffer_flips);
4039 if (dc->hwss.program_triplebuffer != NULL && dc->debug.enable_tri_buf) {
4040 /*turn off triple buffer for full update*/
4041 dc->hwss.program_triplebuffer(
4042 dc, pipe_ctx, pipe_ctx->plane_state->triplebuffer_flips);
4045 stream_get_status(context, pipe_ctx->stream);
4047 if (dc->hwss.apply_ctx_for_surface && stream_status)
4048 dc->hwss.apply_ctx_for_surface(
4049 dc, pipe_ctx->stream, stream_status->plane_count, context);
4052 if (dc->hwss.program_front_end_for_ctx && update_type != UPDATE_TYPE_FAST) {
4053 dc->hwss.program_front_end_for_ctx(dc, context);
4054 if (dc->debug.validate_dml_output) {
4055 for (i = 0; i < dc->res_pool->pipe_count; i++) {
4056 struct pipe_ctx *cur_pipe = &context->res_ctx.pipe_ctx[i];
4057 if (cur_pipe->stream == NULL)
4060 cur_pipe->plane_res.hubp->funcs->validate_dml_output(
4061 cur_pipe->plane_res.hubp, dc->ctx,
4062 &context->res_ctx.pipe_ctx[i].rq_regs,
4063 &context->res_ctx.pipe_ctx[i].dlg_regs,
4064 &context->res_ctx.pipe_ctx[i].ttu_regs);
4069 // Update Type FAST, Surface updates
4070 if (update_type == UPDATE_TYPE_FAST) {
4071 if (dc->hwss.set_flip_control_gsl)
4072 for (i = 0; i < surface_count; i++) {
4073 struct dc_plane_state *plane_state = srf_updates[i].surface;
4075 for (j = 0; j < dc->res_pool->pipe_count; j++) {
4076 struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[j];
4078 if (!should_update_pipe_for_stream(context, pipe_ctx, stream))
4081 if (!should_update_pipe_for_plane(context, pipe_ctx, plane_state))
4084 // GSL has to be used for flip immediate
4085 dc->hwss.set_flip_control_gsl(pipe_ctx,
4086 pipe_ctx->plane_state->flip_immediate);
4090 /* Perform requested Updates */
4091 for (i = 0; i < surface_count; i++) {
4092 struct dc_plane_state *plane_state = srf_updates[i].surface;
4094 for (j = 0; j < dc->res_pool->pipe_count; j++) {
4095 struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[j];
4097 if (!should_update_pipe_for_stream(context, pipe_ctx, stream))
4100 if (!should_update_pipe_for_plane(context, pipe_ctx, plane_state))
4103 if (srf_updates[i].cm2_params &&
4104 srf_updates[i].cm2_params->cm2_luts.lut3d_data.lut3d_src ==
4105 DC_CM2_TRANSFER_FUNC_SOURCE_VIDMEM &&
4106 srf_updates[i].cm2_params->component_settings.shaper_3dlut_setting ==
4107 DC_CM2_SHAPER_3DLUT_SETTING_ENABLE_SHAPER_3DLUT &&
4108 dc->hwss.trigger_3dlut_dma_load)
4109 dc->hwss.trigger_3dlut_dma_load(dc, pipe_ctx);
4111 /*program triple buffer after lock based on flip type*/
4112 if (dc->hwss.program_triplebuffer != NULL && dc->debug.enable_tri_buf) {
4113 /*only enable triplebuffer for fast_update*/
4114 dc->hwss.program_triplebuffer(
4115 dc, pipe_ctx, pipe_ctx->plane_state->triplebuffer_flips);
4117 if (pipe_ctx->plane_state->update_flags.bits.addr_update)
4118 dc->hwss.update_plane_addr(dc, pipe_ctx);
4123 if (should_lock_all_pipes && dc->hwss.interdependent_update_lock) {
4124 dc->hwss.interdependent_update_lock(dc, context, false);
4126 dc->hwss.pipe_control_lock(dc, top_pipe_to_program, false);
4129 if ((update_type != UPDATE_TYPE_FAST) && stream->update_flags.bits.dsc_changed)
4130 if (top_pipe_to_program->stream_res.tg->funcs->lock_doublebuffer_enable) {
4131 top_pipe_to_program->stream_res.tg->funcs->wait_for_state(
4132 top_pipe_to_program->stream_res.tg,
4133 CRTC_STATE_VACTIVE);
4134 top_pipe_to_program->stream_res.tg->funcs->wait_for_state(
4135 top_pipe_to_program->stream_res.tg,
4137 top_pipe_to_program->stream_res.tg->funcs->wait_for_state(
4138 top_pipe_to_program->stream_res.tg,
4139 CRTC_STATE_VACTIVE);
4141 if (should_use_dmub_lock(stream->link)) {
4142 union dmub_hw_lock_flags hw_locks = { 0 };
4143 struct dmub_hw_lock_inst_flags inst_flags = { 0 };
4145 hw_locks.bits.lock_dig = 1;
4146 inst_flags.dig_inst = top_pipe_to_program->stream_res.tg->inst;
4148 dmub_hw_lock_mgr_cmd(dc->ctx->dmub_srv,
4153 top_pipe_to_program->stream_res.tg->funcs->lock_doublebuffer_disable(
4154 top_pipe_to_program->stream_res.tg);
4157 if (subvp_curr_use) {
4158 /* If enabling subvp or transitioning from subvp->subvp, enable the
4159 * phantom streams before we program front end for the phantom pipes.
4161 if (update_type != UPDATE_TYPE_FAST) {
4162 if (dc->hwss.enable_phantom_streams)
4163 dc->hwss.enable_phantom_streams(dc, context);
4167 if (update_type != UPDATE_TYPE_FAST)
4168 dc->hwss.post_unlock_program_front_end(dc, context);
4170 if (subvp_prev_use && !subvp_curr_use) {
4171 /* If disabling subvp, disable phantom streams after front end
4172 * programming has completed (we turn on phantom OTG in order
4173 * to complete the plane disable for phantom pipes).
4176 if (dc->hwss.disable_phantom_streams)
4177 dc->hwss.disable_phantom_streams(dc, context);
4180 if (update_type != UPDATE_TYPE_FAST)
4181 if (dc->hwss.commit_subvp_config)
4182 dc->hwss.commit_subvp_config(dc, context);
4183 /* Since phantom pipe programming is moved to post_unlock_program_front_end,
4184 * move the SubVP lock to after the phantom pipes have been setup
4186 if (should_lock_all_pipes && dc->hwss.interdependent_update_lock) {
4187 if (dc->hwss.subvp_pipe_control_lock)
4188 dc->hwss.subvp_pipe_control_lock(dc, context, false, should_lock_all_pipes, NULL, subvp_prev_use);
4189 if (dc->hwss.fams2_global_control_lock)
4190 dc->hwss.fams2_global_control_lock(dc, context, false);
4192 if (dc->hwss.subvp_pipe_control_lock)
4193 dc->hwss.subvp_pipe_control_lock(dc, context, false, should_lock_all_pipes, top_pipe_to_program, subvp_prev_use);
4194 if (dc->hwss.fams2_global_control_lock)
4195 dc->hwss.fams2_global_control_lock(dc, context, false);
4198 // Fire manual trigger only when bottom plane is flipped
4199 for (j = 0; j < dc->res_pool->pipe_count; j++) {
4200 struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[j];
4202 if (!pipe_ctx->plane_state)
4205 if (pipe_ctx->bottom_pipe || pipe_ctx->next_odm_pipe ||
4206 !pipe_ctx->stream || !should_update_pipe_for_stream(context, pipe_ctx, stream) ||
4207 !pipe_ctx->plane_state->update_flags.bits.addr_update ||
4208 pipe_ctx->plane_state->skip_manual_trigger)
4211 if (pipe_ctx->stream_res.tg->funcs->program_manual_trigger)
4212 pipe_ctx->stream_res.tg->funcs->program_manual_trigger(pipe_ctx->stream_res.tg);
4215 current_stream_mask = get_stream_mask(dc, context);
4216 if (current_stream_mask != context->stream_mask) {
4217 context->stream_mask = current_stream_mask;
4218 dc_dmub_srv_notify_stream_mask(dc->ctx->dmub_srv, current_stream_mask);
4223 * could_mpcc_tree_change_for_active_pipes - Check if an OPP associated with MPCC might change
4225 * @dc: Used to get the current state status
4226 * @stream: Target stream, which we want to remove the attached planes
4227 * @srf_updates: Array of surface updates
4228 * @surface_count: Number of surface update
4229 * @is_plane_addition: [in] Fill out with true if it is a plane addition case
4231 * DCN32x and newer support a feature named Dynamic ODM which can conflict with
4232 * the MPO if used simultaneously in some specific configurations (e.g.,
4233 * 4k@144). This function checks if the incoming context requires applying a
4234 * transition state with unnecessary pipe splitting and ODM disabled to
4235 * circumvent our hardware limitations to prevent this edge case. If the OPP
4236 * associated with an MPCC might change due to plane additions, this function
4240 * Return true if OPP and MPCC might change, otherwise, return false.
4242 static bool could_mpcc_tree_change_for_active_pipes(struct dc *dc,
4243 struct dc_stream_state *stream,
4244 struct dc_surface_update *srf_updates,
4246 bool *is_plane_addition)
4249 struct dc_stream_status *cur_stream_status = stream_get_status(dc->current_state, stream);
4250 bool force_minimal_pipe_splitting = false;
4251 bool subvp_active = false;
4254 *is_plane_addition = false;
4256 if (cur_stream_status &&
4257 dc->current_state->stream_count > 0 &&
4258 dc->debug.pipe_split_policy != MPC_SPLIT_AVOID) {
4259 /* determine if minimal transition is required due to MPC*/
4260 if (surface_count > 0) {
4261 if (cur_stream_status->plane_count > surface_count) {
4262 force_minimal_pipe_splitting = true;
4263 } else if (cur_stream_status->plane_count < surface_count) {
4264 force_minimal_pipe_splitting = true;
4265 *is_plane_addition = true;
4270 if (cur_stream_status &&
4271 dc->current_state->stream_count == 1 &&
4272 dc->debug.enable_single_display_2to1_odm_policy) {
4273 /* determine if minimal transition is required due to dynamic ODM*/
4274 if (surface_count > 0) {
4275 if (cur_stream_status->plane_count > 2 && cur_stream_status->plane_count > surface_count) {
4276 force_minimal_pipe_splitting = true;
4277 } else if (surface_count > 2 && cur_stream_status->plane_count < surface_count) {
4278 force_minimal_pipe_splitting = true;
4279 *is_plane_addition = true;
4284 for (i = 0; i < dc->res_pool->pipe_count; i++) {
4285 struct pipe_ctx *pipe = &dc->current_state->res_ctx.pipe_ctx[i];
4287 if (dc_state_get_pipe_subvp_type(dc->current_state, pipe) != SUBVP_NONE) {
4288 subvp_active = true;
4293 /* For SubVP when adding or removing planes we need to add a minimal transition
4294 * (even when disabling all planes). Whenever disabling a phantom pipe, we
4295 * must use the minimal transition path to disable the pipe correctly.
4297 * We want to use the minimal transition whenever subvp is active, not only if
4298 * a plane is being added / removed from a subvp stream (MPO plane can be added
4299 * to a DRR pipe of SubVP + DRR config, in which case we still want to run through
4300 * a min transition to disable subvp.
4302 if (cur_stream_status && subvp_active) {
4303 /* determine if minimal transition is required due to SubVP*/
4304 if (cur_stream_status->plane_count > surface_count) {
4305 force_minimal_pipe_splitting = true;
4306 } else if (cur_stream_status->plane_count < surface_count) {
4307 force_minimal_pipe_splitting = true;
4308 *is_plane_addition = true;
4312 return force_minimal_pipe_splitting;
4315 struct pipe_split_policy_backup {
4316 bool dynamic_odm_policy;
4318 enum pipe_split_policy mpc_policy;
4319 char force_odm[MAX_PIPES];
4322 static void backup_and_set_minimal_pipe_split_policy(struct dc *dc,
4323 struct dc_state *context,
4324 struct pipe_split_policy_backup *policy)
4328 if (!dc->config.is_vmin_only_asic) {
4329 policy->mpc_policy = dc->debug.pipe_split_policy;
4330 dc->debug.pipe_split_policy = MPC_SPLIT_AVOID;
4332 policy->dynamic_odm_policy = dc->debug.enable_single_display_2to1_odm_policy;
4333 dc->debug.enable_single_display_2to1_odm_policy = false;
4334 policy->subvp_policy = dc->debug.force_disable_subvp;
4335 dc->debug.force_disable_subvp = true;
4336 for (i = 0; i < context->stream_count; i++) {
4337 policy->force_odm[i] = context->streams[i]->debug.force_odm_combine_segments;
4338 context->streams[i]->debug.force_odm_combine_segments = 0;
4342 static void restore_minimal_pipe_split_policy(struct dc *dc,
4343 struct dc_state *context,
4344 struct pipe_split_policy_backup *policy)
4348 if (!dc->config.is_vmin_only_asic)
4349 dc->debug.pipe_split_policy = policy->mpc_policy;
4350 dc->debug.enable_single_display_2to1_odm_policy =
4351 policy->dynamic_odm_policy;
4352 dc->debug.force_disable_subvp = policy->subvp_policy;
4353 for (i = 0; i < context->stream_count; i++)
4354 context->streams[i]->debug.force_odm_combine_segments = policy->force_odm[i];
4357 static void release_minimal_transition_state(struct dc *dc,
4358 struct dc_state *minimal_transition_context,
4359 struct dc_state *base_context,
4360 struct pipe_split_policy_backup *policy)
4362 restore_minimal_pipe_split_policy(dc, base_context, policy);
4363 dc_state_release(minimal_transition_context);
4366 static void force_vsync_flip_in_minimal_transition_context(struct dc_state *context)
4370 struct dc_stream_status *stream_status;
4372 for (i = 0; i < context->stream_count; i++) {
4373 stream_status = &context->stream_status[i];
4375 for (j = 0; j < stream_status->plane_count; j++)
4376 stream_status->plane_states[j]->flip_immediate = false;
4380 static struct dc_state *create_minimal_transition_state(struct dc *dc,
4381 struct dc_state *base_context, struct pipe_split_policy_backup *policy)
4383 struct dc_state *minimal_transition_context = NULL;
4385 minimal_transition_context = dc_state_create_copy(base_context);
4386 if (!minimal_transition_context)
4389 backup_and_set_minimal_pipe_split_policy(dc, base_context, policy);
4390 /* commit minimal state */
4391 if (dc->res_pool->funcs->validate_bandwidth(dc, minimal_transition_context, false)) {
4392 /* prevent underflow and corruption when reconfiguring pipes */
4393 force_vsync_flip_in_minimal_transition_context(minimal_transition_context);
4396 * This should never happen, minimal transition state should
4397 * always be validated first before adding pipe split features.
4399 release_minimal_transition_state(dc, minimal_transition_context, base_context, policy);
4400 BREAK_TO_DEBUGGER();
4401 minimal_transition_context = NULL;
4403 return minimal_transition_context;
4406 static bool is_pipe_topology_transition_seamless_with_intermediate_step(
4408 struct dc_state *initial_state,
4409 struct dc_state *intermediate_state,
4410 struct dc_state *final_state)
4412 return dc->hwss.is_pipe_topology_transition_seamless(dc, initial_state,
4413 intermediate_state) &&
4414 dc->hwss.is_pipe_topology_transition_seamless(dc,
4415 intermediate_state, final_state);
4418 static void swap_and_release_current_context(struct dc *dc,
4419 struct dc_state *new_context, struct dc_stream_state *stream)
4423 struct dc_state *old = dc->current_state;
4424 struct pipe_ctx *pipe_ctx;
4426 /* Since memory free requires elevated IRQ, an interrupt
4427 * request is generated by mem free. If this happens
4428 * between freeing and reassigning the context, our vsync
4429 * interrupt will call into dc and cause a memory
4430 * corruption. Hence, we first reassign the context,
4431 * then free the old context.
4433 dc->current_state = new_context;
4434 dc_state_release(old);
4436 // clear any forced full updates
4437 for (i = 0; i < dc->res_pool->pipe_count; i++) {
4438 pipe_ctx = &new_context->res_ctx.pipe_ctx[i];
4440 if (pipe_ctx->plane_state && pipe_ctx->stream == stream)
4441 pipe_ctx->plane_state->force_full_update = false;
4445 static int initialize_empty_surface_updates(
4446 struct dc_stream_state *stream,
4447 struct dc_surface_update *srf_updates)
4449 struct dc_stream_status *status = dc_stream_get_status(stream);
4455 for (i = 0; i < status->plane_count; i++)
4456 srf_updates[i].surface = status->plane_states[i];
4458 return status->plane_count;
4461 static bool commit_minimal_transition_based_on_new_context(struct dc *dc,
4462 struct dc_state *new_context,
4463 struct dc_stream_state *stream,
4464 struct dc_surface_update *srf_updates,
4467 bool success = false;
4468 struct pipe_split_policy_backup policy;
4469 struct dc_state *intermediate_context =
4470 create_minimal_transition_state(dc, new_context,
4473 if (intermediate_context) {
4474 if (is_pipe_topology_transition_seamless_with_intermediate_step(
4477 intermediate_context,
4479 DC_LOG_DC("commit minimal transition state: base = new state\n");
4480 commit_planes_for_stream(dc, srf_updates,
4481 surface_count, stream, NULL,
4482 UPDATE_TYPE_FULL, intermediate_context);
4483 swap_and_release_current_context(
4484 dc, intermediate_context, stream);
4485 dc_state_retain(dc->current_state);
4488 release_minimal_transition_state(
4489 dc, intermediate_context, new_context, &policy);
4494 static bool commit_minimal_transition_based_on_current_context(struct dc *dc,
4495 struct dc_state *new_context, struct dc_stream_state *stream)
4497 bool success = false;
4498 struct pipe_split_policy_backup policy;
4499 struct dc_state *intermediate_context;
4500 struct dc_state *old_current_state = dc->current_state;
4501 struct dc_surface_update srf_updates[MAX_SURFACE_NUM] = {0};
4505 * Both current and new contexts share the same stream and plane state
4506 * pointers. When new context is validated, stream and planes get
4507 * populated with new updates such as new plane addresses. This makes
4508 * the current context no longer valid because stream and planes are
4509 * modified from the original. We backup current stream and plane states
4510 * into scratch space whenever we are populating new context. So we can
4511 * restore the original values back by calling the restore function now.
4512 * This restores back the original stream and plane states associated
4513 * with the current state.
4515 restore_planes_and_stream_state(&dc->scratch.current_state, stream);
4516 dc_state_retain(old_current_state);
4517 intermediate_context = create_minimal_transition_state(dc,
4518 old_current_state, &policy);
4520 if (intermediate_context) {
4521 if (is_pipe_topology_transition_seamless_with_intermediate_step(
4524 intermediate_context,
4526 DC_LOG_DC("commit minimal transition state: base = current state\n");
4527 surface_count = initialize_empty_surface_updates(
4528 stream, srf_updates);
4529 commit_planes_for_stream(dc, srf_updates,
4530 surface_count, stream, NULL,
4531 UPDATE_TYPE_FULL, intermediate_context);
4532 swap_and_release_current_context(
4533 dc, intermediate_context, stream);
4534 dc_state_retain(dc->current_state);
4537 release_minimal_transition_state(dc, intermediate_context,
4538 old_current_state, &policy);
4540 dc_state_release(old_current_state);
4542 * Restore stream and plane states back to the values associated with
4545 restore_planes_and_stream_state(&dc->scratch.new_state, stream);
4550 * commit_minimal_transition_state_in_dc_update - Commit a minimal state based
4551 * on current or new context
4553 * @dc: DC structure, used to get the current state
4554 * @new_context: New context
4555 * @stream: Stream getting the update for the flip
4556 * @srf_updates: Surface updates
4557 * @surface_count: Number of surfaces
4559 * The function takes in current state and new state and determine a minimal
4560 * transition state as the intermediate step which could make the transition
4561 * between current and new states seamless. If found, it will commit the minimal
4562 * transition state and update current state to this minimal transition state
4563 * and return true, if not, it will return false.
4566 * Return True if the minimal transition succeeded, false otherwise
4568 static bool commit_minimal_transition_state_in_dc_update(struct dc *dc,
4569 struct dc_state *new_context,
4570 struct dc_stream_state *stream,
4571 struct dc_surface_update *srf_updates,
4574 bool success = commit_minimal_transition_based_on_new_context(
4575 dc, new_context, stream, srf_updates,
4578 success = commit_minimal_transition_based_on_current_context(dc,
4579 new_context, stream);
4581 DC_LOG_ERROR("Fail to commit a seamless minimal transition state between current and new states.\nThis pipe topology update is non-seamless!\n");
4586 * commit_minimal_transition_state - Create a transition pipe split state
4588 * @dc: Used to get the current state status
4589 * @transition_base_context: New transition state
4591 * In some specific configurations, such as pipe split on multi-display with
4592 * MPO and/or Dynamic ODM, removing a plane may cause unsupported pipe
4593 * programming when moving to new planes. To mitigate those types of problems,
4594 * this function adds a transition state that minimizes pipe usage before
4595 * programming the new configuration. When adding a new plane, the current
4596 * state requires the least pipes, so it is applied without splitting. When
4597 * removing a plane, the new state requires the least pipes, so it is applied
4598 * without splitting.
4601 * Return false if something is wrong in the transition state.
4603 static bool commit_minimal_transition_state(struct dc *dc,
4604 struct dc_state *transition_base_context)
4606 struct dc_state *transition_context;
4607 struct pipe_split_policy_backup policy;
4608 enum dc_status ret = DC_ERROR_UNEXPECTED;
4610 unsigned int pipe_in_use = 0;
4611 bool subvp_in_use = false;
4612 bool odm_in_use = false;
4614 /* check current pipes in use*/
4615 for (i = 0; i < dc->res_pool->pipe_count; i++) {
4616 struct pipe_ctx *pipe = &transition_base_context->res_ctx.pipe_ctx[i];
4618 if (pipe->plane_state)
4622 /* If SubVP is enabled and we are adding or removing planes from any main subvp
4623 * pipe, we must use the minimal transition.
4625 for (i = 0; i < dc->res_pool->pipe_count; i++) {
4626 struct pipe_ctx *pipe = &dc->current_state->res_ctx.pipe_ctx[i];
4628 if (pipe->stream && dc_state_get_pipe_subvp_type(dc->current_state, pipe) == SUBVP_PHANTOM) {
4629 subvp_in_use = true;
4634 /* If ODM is enabled and we are adding or removing planes from any ODM
4635 * pipe, we must use the minimal transition.
4637 for (i = 0; i < dc->res_pool->pipe_count; i++) {
4638 struct pipe_ctx *pipe = &transition_base_context->res_ctx.pipe_ctx[i];
4640 if (resource_is_pipe_type(pipe, OTG_MASTER)) {
4641 odm_in_use = resource_get_odm_slice_count(pipe) > 1;
4646 /* When the OS add a new surface if we have been used all of pipes with odm combine
4647 * and mpc split feature, it need use commit_minimal_transition_state to transition safely.
4648 * After OS exit MPO, it will back to use odm and mpc split with all of pipes, we need
4649 * call it again. Otherwise return true to skip.
4651 * Reduce the scenarios to use dc_commit_state_no_check in the stage of flip. Especially
4652 * enter/exit MPO when DCN still have enough resources.
4654 if (pipe_in_use != dc->res_pool->pipe_count && !subvp_in_use && !odm_in_use)
4657 DC_LOG_DC("%s base = %s state, reason = %s\n", __func__,
4658 dc->current_state == transition_base_context ? "current" : "new",
4659 subvp_in_use ? "Subvp In Use" :
4660 odm_in_use ? "ODM in Use" :
4661 dc->debug.pipe_split_policy != MPC_SPLIT_AVOID ? "MPC in Use" :
4664 dc_state_retain(transition_base_context);
4665 transition_context = create_minimal_transition_state(dc,
4666 transition_base_context, &policy);
4667 if (transition_context) {
4668 ret = dc_commit_state_no_check(dc, transition_context);
4669 release_minimal_transition_state(dc, transition_context, transition_base_context, &policy);
4671 dc_state_release(transition_base_context);
4674 /* this should never happen */
4675 BREAK_TO_DEBUGGER();
4679 /* force full surface update */
4680 for (i = 0; i < dc->current_state->stream_count; i++) {
4681 for (j = 0; j < dc->current_state->stream_status[i].plane_count; j++) {
4682 dc->current_state->stream_status[i].plane_states[j]->update_flags.raw = 0xFFFFFFFF;
4689 static void populate_fast_updates(struct dc_fast_update *fast_update,
4690 struct dc_surface_update *srf_updates,
4692 struct dc_stream_update *stream_update)
4696 if (stream_update) {
4697 fast_update[0].out_transfer_func = stream_update->out_transfer_func;
4698 fast_update[0].output_csc_transform = stream_update->output_csc_transform;
4701 for (i = 0; i < surface_count; i++) {
4702 fast_update[i].flip_addr = srf_updates[i].flip_addr;
4703 fast_update[i].gamma = srf_updates[i].gamma;
4704 fast_update[i].gamut_remap_matrix = srf_updates[i].gamut_remap_matrix;
4705 fast_update[i].input_csc_color_matrix = srf_updates[i].input_csc_color_matrix;
4706 fast_update[i].coeff_reduction_factor = srf_updates[i].coeff_reduction_factor;
4707 fast_update[i].cursor_csc_color_matrix = srf_updates[i].cursor_csc_color_matrix;
4711 static bool fast_updates_exist(struct dc_fast_update *fast_update, int surface_count)
4715 if (fast_update[0].out_transfer_func ||
4716 fast_update[0].output_csc_transform)
4719 for (i = 0; i < surface_count; i++) {
4720 if (fast_update[i].flip_addr ||
4721 fast_update[i].gamma ||
4722 fast_update[i].gamut_remap_matrix ||
4723 fast_update[i].input_csc_color_matrix ||
4724 fast_update[i].cursor_csc_color_matrix ||
4725 fast_update[i].coeff_reduction_factor)
4732 static bool full_update_required(struct dc *dc,
4733 struct dc_surface_update *srf_updates,
4735 struct dc_stream_update *stream_update,
4736 struct dc_stream_state *stream)
4740 struct dc_stream_status *stream_status;
4741 const struct dc_state *context = dc->current_state;
4743 for (i = 0; i < surface_count; i++) {
4745 (srf_updates[i].plane_info ||
4746 srf_updates[i].scaling_info ||
4747 (srf_updates[i].hdr_mult.value &&
4748 srf_updates[i].hdr_mult.value != srf_updates->surface->hdr_mult.value) ||
4749 srf_updates[i].in_transfer_func ||
4750 srf_updates[i].func_shaper ||
4751 srf_updates[i].lut3d_func ||
4752 srf_updates[i].surface->force_full_update ||
4753 (srf_updates[i].flip_addr &&
4754 srf_updates[i].flip_addr->address.tmz_surface != srf_updates[i].surface->address.tmz_surface) ||
4755 (srf_updates[i].cm2_params &&
4756 (srf_updates[i].cm2_params->component_settings.shaper_3dlut_setting != srf_updates[i].surface->mcm_shaper_3dlut_setting ||
4757 srf_updates[i].cm2_params->component_settings.lut1d_enable != srf_updates[i].surface->mcm_lut1d_enable)) ||
4758 !is_surface_in_context(context, srf_updates[i].surface)))
4762 if (stream_update &&
4763 (((stream_update->src.height != 0 && stream_update->src.width != 0) ||
4764 (stream_update->dst.height != 0 && stream_update->dst.width != 0) ||
4765 stream_update->integer_scaling_update) ||
4766 stream_update->hdr_static_metadata ||
4767 stream_update->abm_level ||
4768 stream_update->periodic_interrupt ||
4769 stream_update->vrr_infopacket ||
4770 stream_update->vsc_infopacket ||
4771 stream_update->vsp_infopacket ||
4772 stream_update->hfvsif_infopacket ||
4773 stream_update->vtem_infopacket ||
4774 stream_update->adaptive_sync_infopacket ||
4775 stream_update->dpms_off ||
4776 stream_update->allow_freesync ||
4777 stream_update->vrr_active_variable ||
4778 stream_update->vrr_active_fixed ||
4779 stream_update->gamut_remap ||
4780 stream_update->output_color_space ||
4781 stream_update->dither_option ||
4782 stream_update->wb_update ||
4783 stream_update->dsc_config ||
4784 stream_update->mst_bw_update ||
4785 stream_update->func_shaper ||
4786 stream_update->lut3d_func ||
4787 stream_update->pending_test_pattern ||
4788 stream_update->crtc_timing_adjust))
4792 stream_status = dc_stream_get_status(stream);
4793 if (stream_status == NULL || stream_status->plane_count != surface_count)
4796 if (dc->idle_optimizations_allowed)
4802 static bool fast_update_only(struct dc *dc,
4803 struct dc_fast_update *fast_update,
4804 struct dc_surface_update *srf_updates,
4806 struct dc_stream_update *stream_update,
4807 struct dc_stream_state *stream)
4809 return fast_updates_exist(fast_update, surface_count)
4810 && !full_update_required(dc, srf_updates, surface_count, stream_update, stream);
4813 static bool update_planes_and_stream_v1(struct dc *dc,
4814 struct dc_surface_update *srf_updates, int surface_count,
4815 struct dc_stream_state *stream,
4816 struct dc_stream_update *stream_update,
4817 struct dc_state *state)
4819 const struct dc_stream_status *stream_status;
4820 enum surface_update_type update_type;
4821 struct dc_state *context;
4822 struct dc_context *dc_ctx = dc->ctx;
4824 struct dc_fast_update fast_update[MAX_SURFACES] = {0};
4826 dc_exit_ips_for_hw_access(dc);
4828 populate_fast_updates(fast_update, srf_updates, surface_count, stream_update);
4829 stream_status = dc_stream_get_status(stream);
4830 context = dc->current_state;
4832 update_type = dc_check_update_surfaces_for_stream(
4833 dc, srf_updates, surface_count, stream_update, stream_status);
4835 if (update_type >= UPDATE_TYPE_FULL) {
4837 /* initialize scratch memory for building context */
4838 context = dc_state_create_copy(state);
4839 if (context == NULL) {
4840 DC_ERROR("Failed to allocate new validate context!\n");
4844 for (i = 0; i < dc->res_pool->pipe_count; i++) {
4845 struct pipe_ctx *new_pipe = &context->res_ctx.pipe_ctx[i];
4846 struct pipe_ctx *old_pipe = &dc->current_state->res_ctx.pipe_ctx[i];
4848 if (new_pipe->plane_state && new_pipe->plane_state != old_pipe->plane_state)
4849 new_pipe->plane_state->force_full_update = true;
4851 } else if (update_type == UPDATE_TYPE_FAST) {
4853 * Previous frame finished and HW is ready for optimization.
4855 dc_post_update_surfaces_to_stream(dc);
4858 for (i = 0; i < surface_count; i++) {
4859 struct dc_plane_state *surface = srf_updates[i].surface;
4861 copy_surface_update_to_plane(surface, &srf_updates[i]);
4863 if (update_type >= UPDATE_TYPE_MED) {
4864 for (j = 0; j < dc->res_pool->pipe_count; j++) {
4865 struct pipe_ctx *pipe_ctx =
4866 &context->res_ctx.pipe_ctx[j];
4868 if (pipe_ctx->plane_state != surface)
4871 resource_build_scaling_params(pipe_ctx);
4876 copy_stream_update_to_stream(dc, context, stream, stream_update);
4878 if (update_type >= UPDATE_TYPE_FULL) {
4879 if (!dc->res_pool->funcs->validate_bandwidth(dc, context, false)) {
4880 DC_ERROR("Mode validation failed for stream update!\n");
4881 dc_state_release(context);
4886 TRACE_DC_PIPE_STATE(pipe_ctx, i, MAX_PIPES);
4888 if (fast_update_only(dc, fast_update, srf_updates, surface_count, stream_update, stream) &&
4889 !dc->debug.enable_legacy_fast_update) {
4890 commit_planes_for_stream_fast(dc,
4898 commit_planes_for_stream(
4907 /*update current_State*/
4908 if (dc->current_state != context) {
4910 struct dc_state *old = dc->current_state;
4912 dc->current_state = context;
4913 dc_state_release(old);
4915 for (i = 0; i < dc->res_pool->pipe_count; i++) {
4916 struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[i];
4918 if (pipe_ctx->plane_state && pipe_ctx->stream == stream)
4919 pipe_ctx->plane_state->force_full_update = false;
4923 /* Legacy optimization path for DCE. */
4924 if (update_type >= UPDATE_TYPE_FULL && dc_ctx->dce_version < DCE_VERSION_MAX) {
4925 dc_post_update_surfaces_to_stream(dc);
4926 TRACE_DCE_CLOCK_STATE(&context->bw_ctx.bw.dce);
4931 static bool update_planes_and_stream_v2(struct dc *dc,
4932 struct dc_surface_update *srf_updates, int surface_count,
4933 struct dc_stream_state *stream,
4934 struct dc_stream_update *stream_update)
4936 struct dc_state *context;
4937 enum surface_update_type update_type;
4938 struct dc_fast_update fast_update[MAX_SURFACES] = {0};
4940 /* In cases where MPO and split or ODM are used transitions can
4941 * cause underflow. Apply stream configuration with minimal pipe
4942 * split first to avoid unsupported transitions for active pipes.
4944 bool force_minimal_pipe_splitting = 0;
4945 bool is_plane_addition = 0;
4946 bool is_fast_update_only;
4948 populate_fast_updates(fast_update, srf_updates, surface_count, stream_update);
4949 is_fast_update_only = fast_update_only(dc, fast_update, srf_updates,
4950 surface_count, stream_update, stream);
4951 force_minimal_pipe_splitting = could_mpcc_tree_change_for_active_pipes(
4956 &is_plane_addition);
4958 /* on plane addition, minimal state is the current one */
4959 if (force_minimal_pipe_splitting && is_plane_addition &&
4960 !commit_minimal_transition_state(dc, dc->current_state))
4963 if (!update_planes_and_stream_state(
4973 /* on plane removal, minimal state is the new one */
4974 if (force_minimal_pipe_splitting && !is_plane_addition) {
4975 if (!commit_minimal_transition_state(dc, context)) {
4976 dc_state_release(context);
4979 update_type = UPDATE_TYPE_FULL;
4982 if (dc->hwss.is_pipe_topology_transition_seamless &&
4983 !dc->hwss.is_pipe_topology_transition_seamless(
4984 dc, dc->current_state, context))
4985 commit_minimal_transition_state_in_dc_update(dc, context, stream,
4986 srf_updates, surface_count);
4988 if (is_fast_update_only && !dc->debug.enable_legacy_fast_update) {
4989 commit_planes_for_stream_fast(dc,
4997 if (!stream_update &&
4998 dc->hwss.is_pipe_topology_transition_seamless &&
4999 !dc->hwss.is_pipe_topology_transition_seamless(
5000 dc, dc->current_state, context)) {
5001 DC_LOG_ERROR("performing non-seamless pipe topology transition with surface only update!\n");
5002 BREAK_TO_DEBUGGER();
5004 commit_planes_for_stream(
5013 if (dc->current_state != context)
5014 swap_and_release_current_context(dc, context, stream);
5018 static void commit_planes_and_stream_update_on_current_context(struct dc *dc,
5019 struct dc_surface_update *srf_updates, int surface_count,
5020 struct dc_stream_state *stream,
5021 struct dc_stream_update *stream_update,
5022 enum surface_update_type update_type)
5024 struct dc_fast_update fast_update[MAX_SURFACES] = {0};
5026 ASSERT(update_type < UPDATE_TYPE_FULL);
5027 populate_fast_updates(fast_update, srf_updates, surface_count,
5029 if (fast_update_only(dc, fast_update, srf_updates, surface_count,
5030 stream_update, stream) &&
5031 !dc->debug.enable_legacy_fast_update)
5032 commit_planes_for_stream_fast(dc,
5040 commit_planes_for_stream(
5050 static void commit_planes_and_stream_update_with_new_context(struct dc *dc,
5051 struct dc_surface_update *srf_updates, int surface_count,
5052 struct dc_stream_state *stream,
5053 struct dc_stream_update *stream_update,
5054 enum surface_update_type update_type,
5055 struct dc_state *new_context)
5057 ASSERT(update_type >= UPDATE_TYPE_FULL);
5058 if (!dc->hwss.is_pipe_topology_transition_seamless(dc,
5059 dc->current_state, new_context))
5061 * It is required by the feature design that all pipe topologies
5062 * using extra free pipes for power saving purposes such as
5063 * dynamic ODM or SubVp shall only be enabled when it can be
5064 * transitioned seamlessly to AND from its minimal transition
5065 * state. A minimal transition state is defined as the same dc
5066 * state but with all power saving features disabled. So it uses
5067 * the minimum pipe topology. When we can't seamlessly
5068 * transition from state A to state B, we will insert the
5069 * minimal transition state A' or B' in between so seamless
5070 * transition between A and B can be made possible.
5072 commit_minimal_transition_state_in_dc_update(dc, new_context,
5073 stream, srf_updates, surface_count);
5075 commit_planes_for_stream(
5085 static bool update_planes_and_stream_v3(struct dc *dc,
5086 struct dc_surface_update *srf_updates, int surface_count,
5087 struct dc_stream_state *stream,
5088 struct dc_stream_update *stream_update)
5090 struct dc_state *new_context;
5091 enum surface_update_type update_type;
5094 * When this function returns true and new_context is not equal to
5095 * current state, the function allocates and validates a new dc state
5096 * and assigns it to new_context. The function expects that the caller
5097 * is responsible to free this memory when new_context is no longer
5098 * used. We swap current with new context and free current instead. So
5099 * new_context's memory will live until the next full update after it is
5100 * replaced by a newer context. Refer to the use of
5101 * swap_and_free_current_context below.
5103 if (!update_planes_and_stream_state(dc, srf_updates, surface_count,
5104 stream, stream_update, &update_type,
5108 if (new_context == dc->current_state) {
5109 commit_planes_and_stream_update_on_current_context(dc,
5110 srf_updates, surface_count, stream,
5111 stream_update, update_type);
5113 commit_planes_and_stream_update_with_new_context(dc,
5114 srf_updates, surface_count, stream,
5115 stream_update, update_type, new_context);
5116 swap_and_release_current_context(dc, new_context, stream);
5122 bool dc_update_planes_and_stream(struct dc *dc,
5123 struct dc_surface_update *srf_updates, int surface_count,
5124 struct dc_stream_state *stream,
5125 struct dc_stream_update *stream_update)
5127 dc_exit_ips_for_hw_access(dc);
5129 * update planes and stream version 3 separates FULL and FAST updates
5130 * to their own sequences. It aims to clean up frequent checks for
5131 * update type resulting unnecessary branching in logic flow. It also
5132 * adds a new commit minimal transition sequence, which detects the need
5133 * for minimal transition based on the actual comparison of current and
5134 * new states instead of "predicting" it based on per feature software
5135 * policy.i.e could_mpcc_tree_change_for_active_pipes. The new commit
5136 * minimal transition sequence is made universal to any power saving
5137 * features that would use extra free pipes such as Dynamic ODM/MPC
5138 * Combine, MPO or SubVp. Therefore there is no longer a need to
5139 * specially handle compatibility problems with transitions among those
5140 * features as they are now transparent to the new sequence.
5142 if (dc->ctx->dce_version >= DCN_VERSION_4_01)
5143 return update_planes_and_stream_v3(dc, srf_updates,
5144 surface_count, stream, stream_update);
5145 return update_planes_and_stream_v2(dc, srf_updates,
5146 surface_count, stream, stream_update);
5149 void dc_commit_updates_for_stream(struct dc *dc,
5150 struct dc_surface_update *srf_updates,
5152 struct dc_stream_state *stream,
5153 struct dc_stream_update *stream_update,
5154 struct dc_state *state)
5156 dc_exit_ips_for_hw_access(dc);
5157 /* TODO: Since change commit sequence can have a huge impact,
5158 * we decided to only enable it for DCN3x. However, as soon as
5159 * we get more confident about this change we'll need to enable
5160 * the new sequence for all ASICs.
5162 if (dc->ctx->dce_version >= DCN_VERSION_4_01) {
5163 update_planes_and_stream_v3(dc, srf_updates, surface_count,
5164 stream, stream_update);
5167 if (dc->ctx->dce_version >= DCN_VERSION_3_2) {
5168 update_planes_and_stream_v2(dc, srf_updates, surface_count,
5169 stream, stream_update);
5172 update_planes_and_stream_v1(dc, srf_updates, surface_count, stream,
5173 stream_update, state);
5176 uint8_t dc_get_current_stream_count(struct dc *dc)
5178 return dc->current_state->stream_count;
5181 struct dc_stream_state *dc_get_stream_at_index(struct dc *dc, uint8_t i)
5183 if (i < dc->current_state->stream_count)
5184 return dc->current_state->streams[i];
5188 enum dc_irq_source dc_interrupt_to_irq_source(
5193 return dal_irq_service_to_irq_source(dc->res_pool->irqs, src_id, ext_id);
5197 * dc_interrupt_set() - Enable/disable an AMD hw interrupt source
5199 bool dc_interrupt_set(struct dc *dc, enum dc_irq_source src, bool enable)
5205 return dal_irq_service_set(dc->res_pool->irqs, src, enable);
5208 void dc_interrupt_ack(struct dc *dc, enum dc_irq_source src)
5210 dal_irq_service_ack(dc->res_pool->irqs, src);
5213 void dc_power_down_on_boot(struct dc *dc)
5215 if (dc->ctx->dce_environment != DCE_ENV_VIRTUAL_HW &&
5216 dc->hwss.power_down_on_boot) {
5217 if (dc->caps.ips_support)
5218 dc_exit_ips_for_hw_access(dc);
5219 dc->hwss.power_down_on_boot(dc);
5223 void dc_set_power_state(struct dc *dc, enum dc_acpi_cm_power_state power_state)
5225 if (!dc->current_state)
5228 switch (power_state) {
5229 case DC_ACPI_CM_POWER_STATE_D0:
5230 dc_state_construct(dc, dc->current_state);
5232 dc_exit_ips_for_hw_access(dc);
5236 dc->hwss.init_hw(dc);
5238 if (dc->hwss.init_sys_ctx != NULL &&
5239 dc->vm_pa_config.valid) {
5240 dc->hwss.init_sys_ctx(dc->hwseq, dc, &dc->vm_pa_config);
5245 ASSERT(dc->current_state->stream_count == 0);
5247 dc_state_destruct(dc->current_state);
5253 void dc_resume(struct dc *dc)
5257 for (i = 0; i < dc->link_count; i++)
5258 dc->link_srv->resume(dc->links[i]);
5261 bool dc_is_dmcu_initialized(struct dc *dc)
5263 struct dmcu *dmcu = dc->res_pool->dmcu;
5266 return dmcu->funcs->is_dmcu_initialized(dmcu);
5270 void get_clock_requirements_for_state(struct dc_state *state, struct AsicStateEx *info)
5272 info->displayClock = (unsigned int)state->bw_ctx.bw.dcn.clk.dispclk_khz;
5273 info->engineClock = (unsigned int)state->bw_ctx.bw.dcn.clk.dcfclk_khz;
5274 info->memoryClock = (unsigned int)state->bw_ctx.bw.dcn.clk.dramclk_khz;
5275 info->maxSupportedDppClock = (unsigned int)state->bw_ctx.bw.dcn.clk.max_supported_dppclk_khz;
5276 info->dppClock = (unsigned int)state->bw_ctx.bw.dcn.clk.dppclk_khz;
5277 info->socClock = (unsigned int)state->bw_ctx.bw.dcn.clk.socclk_khz;
5278 info->dcfClockDeepSleep = (unsigned int)state->bw_ctx.bw.dcn.clk.dcfclk_deep_sleep_khz;
5279 info->fClock = (unsigned int)state->bw_ctx.bw.dcn.clk.fclk_khz;
5280 info->phyClock = (unsigned int)state->bw_ctx.bw.dcn.clk.phyclk_khz;
5282 enum dc_status dc_set_clock(struct dc *dc, enum dc_clock_type clock_type, uint32_t clk_khz, uint32_t stepping)
5284 if (dc->hwss.set_clock)
5285 return dc->hwss.set_clock(dc, clock_type, clk_khz, stepping);
5286 return DC_ERROR_UNEXPECTED;
5288 void dc_get_clock(struct dc *dc, enum dc_clock_type clock_type, struct dc_clock_config *clock_cfg)
5290 if (dc->hwss.get_clock)
5291 dc->hwss.get_clock(dc, clock_type, clock_cfg);
5294 /* enable/disable eDP PSR without specify stream for eDP */
5295 bool dc_set_psr_allow_active(struct dc *dc, bool enable)
5300 for (i = 0; i < dc->current_state->stream_count ; i++) {
5301 struct dc_link *link;
5302 struct dc_stream_state *stream = dc->current_state->streams[i];
5304 link = stream->link;
5308 if (link->psr_settings.psr_feature_enabled) {
5309 if (enable && !link->psr_settings.psr_allow_active) {
5310 allow_active = true;
5311 if (!dc_link_set_psr_allow_active(link, &allow_active, false, false, NULL))
5313 } else if (!enable && link->psr_settings.psr_allow_active) {
5314 allow_active = false;
5315 if (!dc_link_set_psr_allow_active(link, &allow_active, true, false, NULL))
5324 /* enable/disable eDP Replay without specify stream for eDP */
5325 bool dc_set_replay_allow_active(struct dc *dc, bool active)
5330 for (i = 0; i < dc->current_state->stream_count; i++) {
5331 struct dc_link *link;
5332 struct dc_stream_state *stream = dc->current_state->streams[i];
5334 link = stream->link;
5338 if (link->replay_settings.replay_feature_enabled) {
5339 if (active && !link->replay_settings.replay_allow_active) {
5340 allow_active = true;
5341 if (!dc_link_set_replay_allow_active(link, &allow_active,
5342 false, false, NULL))
5344 } else if (!active && link->replay_settings.replay_allow_active) {
5345 allow_active = false;
5346 if (!dc_link_set_replay_allow_active(link, &allow_active,
5356 /* set IPS disable state */
5357 bool dc_set_ips_disable(struct dc *dc, unsigned int disable_ips)
5359 dc_exit_ips_for_hw_access(dc);
5361 dc->config.disable_ips = disable_ips;
5366 void dc_allow_idle_optimizations_internal(struct dc *dc, bool allow, char const *caller_name)
5368 if (dc->debug.disable_idle_power_optimizations)
5371 if (allow != dc->idle_optimizations_allowed)
5372 DC_LOG_IPS("%s: allow_idle old=%d new=%d (caller=%s)\n", __func__,
5373 dc->idle_optimizations_allowed, allow, caller_name);
5375 if (dc->caps.ips_support && (dc->config.disable_ips == DMUB_IPS_DISABLE_ALL))
5378 if (dc->clk_mgr != NULL && dc->clk_mgr->funcs->is_smu_present)
5379 if (!dc->clk_mgr->funcs->is_smu_present(dc->clk_mgr))
5382 if (allow == dc->idle_optimizations_allowed)
5385 if (dc->hwss.apply_idle_power_optimizations && dc->hwss.apply_idle_power_optimizations(dc, allow))
5386 dc->idle_optimizations_allowed = allow;
5389 void dc_exit_ips_for_hw_access_internal(struct dc *dc, const char *caller_name)
5391 if (dc->caps.ips_support)
5392 dc_allow_idle_optimizations_internal(dc, false, caller_name);
5395 bool dc_dmub_is_ips_idle_state(struct dc *dc)
5397 if (dc->debug.disable_idle_power_optimizations)
5400 if (!dc->caps.ips_support || (dc->config.disable_ips == DMUB_IPS_DISABLE_ALL))
5403 if (!dc->ctx->dmub_srv)
5406 return dc->ctx->dmub_srv->idle_allowed;
5409 /* set min and max memory clock to lowest and highest DPM level, respectively */
5410 void dc_unlock_memory_clock_frequency(struct dc *dc)
5412 if (dc->clk_mgr->funcs->set_hard_min_memclk)
5413 dc->clk_mgr->funcs->set_hard_min_memclk(dc->clk_mgr, false);
5415 if (dc->clk_mgr->funcs->set_hard_max_memclk)
5416 dc->clk_mgr->funcs->set_hard_max_memclk(dc->clk_mgr);
5419 /* set min memory clock to the min required for current mode, max to maxDPM */
5420 void dc_lock_memory_clock_frequency(struct dc *dc)
5422 if (dc->clk_mgr->funcs->get_memclk_states_from_smu)
5423 dc->clk_mgr->funcs->get_memclk_states_from_smu(dc->clk_mgr);
5425 if (dc->clk_mgr->funcs->set_hard_min_memclk)
5426 dc->clk_mgr->funcs->set_hard_min_memclk(dc->clk_mgr, true);
5428 if (dc->clk_mgr->funcs->set_hard_max_memclk)
5429 dc->clk_mgr->funcs->set_hard_max_memclk(dc->clk_mgr);
5432 static void blank_and_force_memclk(struct dc *dc, bool apply, unsigned int memclk_mhz)
5434 struct dc_state *context = dc->current_state;
5436 struct pipe_ctx *pipe;
5439 for (i = 0; i < dc->res_pool->pipe_count; i++) {
5440 pipe = &context->res_ctx.pipe_ctx[i];
5442 if (pipe->stream != NULL) {
5443 dc->hwss.disable_pixel_data(dc, pipe, true);
5445 // wait for double buffer
5446 pipe->stream_res.tg->funcs->wait_for_state(pipe->stream_res.tg, CRTC_STATE_VACTIVE);
5447 pipe->stream_res.tg->funcs->wait_for_state(pipe->stream_res.tg, CRTC_STATE_VBLANK);
5448 pipe->stream_res.tg->funcs->wait_for_state(pipe->stream_res.tg, CRTC_STATE_VACTIVE);
5450 hubp = pipe->plane_res.hubp;
5451 hubp->funcs->set_blank_regs(hubp, true);
5455 dc->clk_mgr->funcs->set_max_memclk(dc->clk_mgr, memclk_mhz);
5456 dc->clk_mgr->funcs->set_min_memclk(dc->clk_mgr, memclk_mhz);
5458 for (i = 0; i < dc->res_pool->pipe_count; i++) {
5459 pipe = &context->res_ctx.pipe_ctx[i];
5461 if (pipe->stream != NULL) {
5462 dc->hwss.disable_pixel_data(dc, pipe, false);
5464 hubp = pipe->plane_res.hubp;
5465 hubp->funcs->set_blank_regs(hubp, false);
5472 * dc_enable_dcmode_clk_limit() - lower clocks in dc (battery) mode
5473 * @dc: pointer to dc of the dm calling this
5474 * @enable: True = transition to DC mode, false = transition back to AC mode
5476 * Some SoCs define additional clock limits when in DC mode, DM should
5477 * invoke this function when the platform undergoes a power source transition
5478 * so DC can apply/unapply the limit. This interface may be disruptive to
5479 * the onscreen content.
5481 * Context: Triggered by OS through DM interface, or manually by escape calls.
5482 * Need to hold a dclock when doing so.
5484 * Return: none (void function)
5487 void dc_enable_dcmode_clk_limit(struct dc *dc, bool enable)
5489 unsigned int softMax = 0, maxDPM = 0, funcMin = 0, i;
5490 bool p_state_change_support;
5492 if (!dc->config.dc_mode_clk_limit_support)
5495 softMax = dc->clk_mgr->bw_params->dc_mode_softmax_memclk;
5496 for (i = 0; i < dc->clk_mgr->bw_params->clk_table.num_entries; i++) {
5497 if (dc->clk_mgr->bw_params->clk_table.entries[i].memclk_mhz > maxDPM)
5498 maxDPM = dc->clk_mgr->bw_params->clk_table.entries[i].memclk_mhz;
5500 funcMin = (dc->clk_mgr->clks.dramclk_khz + 999) / 1000;
5501 p_state_change_support = dc->clk_mgr->clks.p_state_change_support;
5503 if (enable && !dc->clk_mgr->dc_mode_softmax_enabled) {
5504 if (p_state_change_support) {
5505 if (funcMin <= softMax)
5506 dc->clk_mgr->funcs->set_max_memclk(dc->clk_mgr, softMax);
5509 if (funcMin <= softMax)
5510 blank_and_force_memclk(dc, true, softMax);
5513 } else if (!enable && dc->clk_mgr->dc_mode_softmax_enabled) {
5514 if (p_state_change_support) {
5515 if (funcMin <= softMax)
5516 dc->clk_mgr->funcs->set_max_memclk(dc->clk_mgr, maxDPM);
5519 if (funcMin <= softMax)
5520 blank_and_force_memclk(dc, true, maxDPM);
5524 dc->clk_mgr->dc_mode_softmax_enabled = enable;
5526 bool dc_is_plane_eligible_for_idle_optimizations(struct dc *dc,
5528 unsigned int height,
5529 enum surface_pixel_format format,
5530 struct dc_cursor_attributes *cursor_attr)
5532 if (dc->hwss.does_plane_fit_in_mall && dc->hwss.does_plane_fit_in_mall(dc, pitch, height, format, cursor_attr))
5537 /* cleanup on driver unload */
5538 void dc_hardware_release(struct dc *dc)
5540 dc_mclk_switch_using_fw_based_vblank_stretch_shut_down(dc);
5542 if (dc->hwss.hardware_release)
5543 dc->hwss.hardware_release(dc);
5546 void dc_mclk_switch_using_fw_based_vblank_stretch_shut_down(struct dc *dc)
5548 if (dc->current_state)
5549 dc->current_state->bw_ctx.bw.dcn.clk.fw_based_mclk_switching_shut_down = true;
5553 * dc_is_dmub_outbox_supported - Check if DMUB firmware support outbox notification
5555 * @dc: [in] dc structure
5557 * Checks whether DMUB FW supports outbox notifications, if supported DM
5558 * should register outbox interrupt prior to actually enabling interrupts
5559 * via dc_enable_dmub_outbox
5562 * True if DMUB FW supports outbox notifications, False otherwise
5564 bool dc_is_dmub_outbox_supported(struct dc *dc)
5566 switch (dc->ctx->asic_id.chip_family) {
5568 case FAMILY_YELLOW_CARP:
5569 /* DCN31 B0 USB4 DPIA needs dmub notifications for interrupts */
5570 if (dc->ctx->asic_id.hw_internal_rev == YELLOW_CARP_B0 &&
5571 !dc->debug.dpia_debug.bits.disable_dpia)
5575 case AMDGPU_FAMILY_GC_11_0_1:
5576 case AMDGPU_FAMILY_GC_11_5_0:
5577 if (!dc->debug.dpia_debug.bits.disable_dpia)
5585 /* dmub aux needs dmub notifications to be enabled */
5586 return dc->debug.enable_dmub_aux_for_legacy_ddc;
5591 * dc_enable_dmub_notifications - Check if dmub fw supports outbox
5593 * @dc: [in] dc structure
5595 * Calls dc_is_dmub_outbox_supported to check if dmub fw supports outbox
5596 * notifications. All DMs shall switch to dc_is_dmub_outbox_supported. This
5597 * API shall be removed after switching.
5600 * True if DMUB FW supports outbox notifications, False otherwise
5602 bool dc_enable_dmub_notifications(struct dc *dc)
5604 return dc_is_dmub_outbox_supported(dc);
5608 * dc_enable_dmub_outbox - Enables DMUB unsolicited notification
5610 * @dc: [in] dc structure
5612 * Enables DMUB unsolicited notifications to x86 via outbox.
5614 void dc_enable_dmub_outbox(struct dc *dc)
5616 struct dc_context *dc_ctx = dc->ctx;
5618 dmub_enable_outbox_notification(dc_ctx->dmub_srv);
5619 DC_LOG_DC("%s: dmub outbox notifications enabled\n", __func__);
5623 * dc_process_dmub_aux_transfer_async - Submits aux command to dmub via inbox message
5624 * Sets port index appropriately for legacy DDC
5626 * @link_index: link index
5627 * @payload: aux payload
5629 * Returns: True if successful, False if failure
5631 bool dc_process_dmub_aux_transfer_async(struct dc *dc,
5632 uint32_t link_index,
5633 struct aux_payload *payload)
5636 union dmub_rb_cmd cmd = {0};
5638 ASSERT(payload->length <= 16);
5640 cmd.dp_aux_access.header.type = DMUB_CMD__DP_AUX_ACCESS;
5641 cmd.dp_aux_access.header.payload_bytes = 0;
5642 /* For dpia, ddc_pin is set to NULL */
5643 if (!dc->links[link_index]->ddc->ddc_pin)
5644 cmd.dp_aux_access.aux_control.type = AUX_CHANNEL_DPIA;
5646 cmd.dp_aux_access.aux_control.type = AUX_CHANNEL_LEGACY_DDC;
5648 cmd.dp_aux_access.aux_control.instance = dc->links[link_index]->ddc_hw_inst;
5649 cmd.dp_aux_access.aux_control.sw_crc_enabled = 0;
5650 cmd.dp_aux_access.aux_control.timeout = 0;
5651 cmd.dp_aux_access.aux_control.dpaux.address = payload->address;
5652 cmd.dp_aux_access.aux_control.dpaux.is_i2c_over_aux = payload->i2c_over_aux;
5653 cmd.dp_aux_access.aux_control.dpaux.length = payload->length;
5655 /* set aux action */
5656 if (payload->i2c_over_aux) {
5657 if (payload->write) {
5659 action = DP_AUX_REQ_ACTION_I2C_WRITE_MOT;
5661 action = DP_AUX_REQ_ACTION_I2C_WRITE;
5664 action = DP_AUX_REQ_ACTION_I2C_READ_MOT;
5666 action = DP_AUX_REQ_ACTION_I2C_READ;
5670 action = DP_AUX_REQ_ACTION_DPCD_WRITE;
5672 action = DP_AUX_REQ_ACTION_DPCD_READ;
5675 cmd.dp_aux_access.aux_control.dpaux.action = action;
5677 if (payload->length && payload->write) {
5678 memcpy(cmd.dp_aux_access.aux_control.dpaux.data,
5684 dc_wake_and_execute_dmub_cmd(dc->ctx, &cmd, DM_DMUB_WAIT_TYPE_WAIT);
5689 uint8_t get_link_index_from_dpia_port_index(const struct dc *dc,
5690 uint8_t dpia_port_index)
5692 uint8_t index, link_index = 0xFF;
5694 for (index = 0; index < dc->link_count; index++) {
5695 /* ddc_hw_inst has dpia port index for dpia links
5696 * and ddc instance for legacy links
5698 if (!dc->links[index]->ddc->ddc_pin) {
5699 if (dc->links[index]->ddc_hw_inst == dpia_port_index) {
5705 ASSERT(link_index != 0xFF);
5710 * dc_process_dmub_set_config_async - Submits set_config command
5712 * @dc: [in] dc structure
5713 * @link_index: [in] link_index: link index
5714 * @payload: [in] aux payload
5715 * @notify: [out] set_config immediate reply
5717 * Submits set_config command to dmub via inbox message.
5720 * True if successful, False if failure
5722 bool dc_process_dmub_set_config_async(struct dc *dc,
5723 uint32_t link_index,
5724 struct set_config_cmd_payload *payload,
5725 struct dmub_notification *notify)
5727 union dmub_rb_cmd cmd = {0};
5728 bool is_cmd_complete = true;
5730 /* prepare SET_CONFIG command */
5731 cmd.set_config_access.header.type = DMUB_CMD__DPIA;
5732 cmd.set_config_access.header.sub_type = DMUB_CMD__DPIA_SET_CONFIG_ACCESS;
5734 cmd.set_config_access.set_config_control.instance = dc->links[link_index]->ddc_hw_inst;
5735 cmd.set_config_access.set_config_control.cmd_pkt.msg_type = payload->msg_type;
5736 cmd.set_config_access.set_config_control.cmd_pkt.msg_data = payload->msg_data;
5738 if (!dc_wake_and_execute_dmub_cmd(dc->ctx, &cmd, DM_DMUB_WAIT_TYPE_WAIT_WITH_REPLY)) {
5739 /* command is not processed by dmub */
5740 notify->sc_status = SET_CONFIG_UNKNOWN_ERROR;
5741 return is_cmd_complete;
5744 /* command processed by dmub, if ret_status is 1, it is completed instantly */
5745 if (cmd.set_config_access.header.ret_status == 1)
5746 notify->sc_status = cmd.set_config_access.set_config_control.immed_status;
5748 /* cmd pending, will receive notification via outbox */
5749 is_cmd_complete = false;
5751 return is_cmd_complete;
5755 * dc_process_dmub_set_mst_slots - Submits MST solt allocation
5757 * @dc: [in] dc structure
5758 * @link_index: [in] link index
5759 * @mst_alloc_slots: [in] mst slots to be allotted
5760 * @mst_slots_in_use: [out] mst slots in use returned in failure case
5762 * Submits mst slot allocation command to dmub via inbox message
5765 * DC_OK if successful, DC_ERROR if failure
5767 enum dc_status dc_process_dmub_set_mst_slots(const struct dc *dc,
5768 uint32_t link_index,
5769 uint8_t mst_alloc_slots,
5770 uint8_t *mst_slots_in_use)
5772 union dmub_rb_cmd cmd = {0};
5774 /* prepare MST_ALLOC_SLOTS command */
5775 cmd.set_mst_alloc_slots.header.type = DMUB_CMD__DPIA;
5776 cmd.set_mst_alloc_slots.header.sub_type = DMUB_CMD__DPIA_MST_ALLOC_SLOTS;
5778 cmd.set_mst_alloc_slots.mst_slots_control.instance = dc->links[link_index]->ddc_hw_inst;
5779 cmd.set_mst_alloc_slots.mst_slots_control.mst_alloc_slots = mst_alloc_slots;
5781 if (!dc_wake_and_execute_dmub_cmd(dc->ctx, &cmd, DM_DMUB_WAIT_TYPE_WAIT_WITH_REPLY))
5782 /* command is not processed by dmub */
5783 return DC_ERROR_UNEXPECTED;
5785 /* command processed by dmub, if ret_status is 1 */
5786 if (cmd.set_config_access.header.ret_status != 1)
5787 /* command processing error */
5788 return DC_ERROR_UNEXPECTED;
5790 /* command processed and we have a status of 2, mst not enabled in dpia */
5791 if (cmd.set_mst_alloc_slots.mst_slots_control.immed_status == 2)
5792 return DC_FAIL_UNSUPPORTED_1;
5794 /* previously configured mst alloc and used slots did not match */
5795 if (cmd.set_mst_alloc_slots.mst_slots_control.immed_status == 3) {
5796 *mst_slots_in_use = cmd.set_mst_alloc_slots.mst_slots_control.mst_slots_in_use;
5797 return DC_NOT_SUPPORTED;
5804 * dc_process_dmub_dpia_hpd_int_enable - Submits DPIA DPD interruption
5806 * @dc: [in] dc structure
5807 * @hpd_int_enable: [in] 1 for hpd int enable, 0 to disable
5809 * Submits dpia hpd int enable command to dmub via inbox message
5811 void dc_process_dmub_dpia_hpd_int_enable(const struct dc *dc,
5812 uint32_t hpd_int_enable)
5814 union dmub_rb_cmd cmd = {0};
5816 cmd.dpia_hpd_int_enable.header.type = DMUB_CMD__DPIA_HPD_INT_ENABLE;
5817 cmd.dpia_hpd_int_enable.enable = hpd_int_enable;
5819 dc_wake_and_execute_dmub_cmd(dc->ctx, &cmd, DM_DMUB_WAIT_TYPE_WAIT);
5821 DC_LOG_DEBUG("%s: hpd_int_enable(%d)\n", __func__, hpd_int_enable);
5825 * dc_print_dmub_diagnostic_data - Print DMUB diagnostic data for debugging
5827 * @dc: [in] dc structure
5831 void dc_print_dmub_diagnostic_data(const struct dc *dc)
5833 dc_dmub_srv_log_diagnostic_data(dc->ctx->dmub_srv);
5837 * dc_disable_accelerated_mode - disable accelerated mode
5840 void dc_disable_accelerated_mode(struct dc *dc)
5842 bios_set_scratch_acc_mode_change(dc->ctx->dc_bios, 0);
5847 * dc_notify_vsync_int_state - notifies vsync enable/disable state
5849 * @stream: stream where vsync int state changed
5850 * @enable: whether vsync is enabled or disabled
5852 * Called when vsync is enabled/disabled Will notify DMUB to start/stop ABM
5853 * interrupts after steady state is reached.
5855 void dc_notify_vsync_int_state(struct dc *dc, struct dc_stream_state *stream, bool enable)
5859 struct pipe_ctx *pipe = NULL;
5860 struct dc_link *link = stream->sink->link;
5861 struct dc_link *edp_links[MAX_NUM_EDP];
5864 if (link->psr_settings.psr_feature_enabled)
5867 if (link->replay_settings.replay_feature_enabled)
5870 /*find primary pipe associated with stream*/
5871 for (i = 0; i < MAX_PIPES; i++) {
5872 pipe = &dc->current_state->res_ctx.pipe_ctx[i];
5874 if (pipe->stream == stream && pipe->stream_res.tg)
5878 if (i == MAX_PIPES) {
5883 dc_get_edp_links(dc, edp_links, &edp_num);
5885 /* Determine panel inst */
5886 for (i = 0; i < edp_num; i++) {
5887 if (edp_links[i] == link)
5895 if (pipe->stream_res.abm && pipe->stream_res.abm->funcs->set_abm_pause)
5896 pipe->stream_res.abm->funcs->set_abm_pause(pipe->stream_res.abm, !enable, i, pipe->stream_res.tg->inst);
5899 /*****************************************************************************
5900 * dc_abm_save_restore() - Interface to DC for save+pause and restore+un-pause
5903 * @stream: stream where vsync int state changed
5904 * @pData: abm hw states
5906 ****************************************************************************/
5907 bool dc_abm_save_restore(
5909 struct dc_stream_state *stream,
5910 struct abm_save_restore *pData)
5914 struct pipe_ctx *pipe = NULL;
5915 struct dc_link *link = stream->sink->link;
5916 struct dc_link *edp_links[MAX_NUM_EDP];
5918 if (link->replay_settings.replay_feature_enabled)
5921 /*find primary pipe associated with stream*/
5922 for (i = 0; i < MAX_PIPES; i++) {
5923 pipe = &dc->current_state->res_ctx.pipe_ctx[i];
5925 if (pipe->stream == stream && pipe->stream_res.tg)
5929 if (i == MAX_PIPES) {
5934 dc_get_edp_links(dc, edp_links, &edp_num);
5936 /* Determine panel inst */
5937 for (i = 0; i < edp_num; i++)
5938 if (edp_links[i] == link)
5944 if (pipe->stream_res.abm &&
5945 pipe->stream_res.abm->funcs->save_restore)
5946 return pipe->stream_res.abm->funcs->save_restore(
5947 pipe->stream_res.abm,
5953 void dc_query_current_properties(struct dc *dc, struct dc_current_properties *properties)
5956 bool subvp_sw_cursor_req = false;
5958 for (i = 0; i < dc->current_state->stream_count; i++) {
5959 if (check_subvp_sw_cursor_fallback_req(dc, dc->current_state->streams[i])) {
5960 subvp_sw_cursor_req = true;
5964 properties->cursor_size_limit = subvp_sw_cursor_req ? 64 : dc->caps.max_cursor_size;
5968 * dc_set_edp_power() - DM controls eDP power to be ON/OFF
5970 * Called when DM wants to power on/off eDP.
5971 * Only work on links with flag skip_implict_edp_power_control is set.
5973 * @dc: Current DC state
5974 * @edp_link: a link with eDP connector signal type
5975 * @powerOn: power on/off eDP
5979 void dc_set_edp_power(const struct dc *dc, struct dc_link *edp_link,
5982 if (edp_link->connector_signal != SIGNAL_TYPE_EDP)
5985 if (edp_link->skip_implict_edp_power_control == false)
5988 edp_link->dc->link_srv->edp_set_panel_power(edp_link, powerOn);
5992 *****************************************************************************
5993 * dc_get_power_profile_for_dc_state() - extracts power profile from dc state
5995 * Called when DM wants to make power policy decisions based on dc_state
5997 *****************************************************************************
5999 struct dc_power_profile dc_get_power_profile_for_dc_state(const struct dc_state *context)
6001 struct dc_power_profile profile = { 0 };
6003 profile.power_level += !context->bw_ctx.bw.dcn.clk.p_state_change_support;