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 <linux/slab.h>
28 #include "dm_services.h"
32 #include "core_status.h"
33 #include "core_types.h"
34 #include "hw_sequencer.h"
35 #include "dce/dce_hwseq.h"
40 #include "clock_source.h"
41 #include "dc_bios_types.h"
43 #include "bios_parser_interface.h"
44 #include "include/irq_service_interface.h"
45 #include "transform.h"
48 #include "timing_generator.h"
50 #include "virtual/virtual_link_encoder.h"
52 #include "link_hwss.h"
53 #include "link_encoder.h"
55 #include "dc_link_ddc.h"
56 #include "dm_helpers.h"
57 #include "mem_input.h"
60 #include "dc_link_dp.h"
61 #include "dc_dmub_srv.h"
65 #include "vm_helper.h"
67 #include "dce/dce_i2c.h"
69 #include "dmub/dmub_srv.h"
71 #include "dce/dmub_hw_lock_mgr.h"
79 static const char DC_BUILD_ID[] = "production-build";
84 * DC is the OS-agnostic component of the amdgpu DC driver.
86 * DC maintains and validates a set of structs representing the state of the
87 * driver and writes that state to AMD hardware
91 * struct dc - The central struct. One per driver. Created on driver load,
92 * destroyed on driver unload.
94 * struct dc_context - One per driver.
95 * Used as a backpointer by most other structs in dc.
97 * struct dc_link - One per connector (the physical DP, HDMI, miniDP, or eDP
98 * plugpoints). Created on driver load, destroyed on driver unload.
100 * struct dc_sink - One per display. Created on boot or hotplug.
101 * Destroyed on shutdown or hotunplug. A dc_link can have a local sink
102 * (the display directly attached). It may also have one or more remote
103 * sinks (in the Multi-Stream Transport case)
105 * struct resource_pool - One per driver. Represents the hw blocks not in the
106 * main pipeline. Not directly accessible by dm.
108 * Main dc state structs:
110 * These structs can be created and destroyed as needed. There is a full set of
111 * these structs in dc->current_state representing the currently programmed state.
113 * struct dc_state - The global DC state to track global state information,
114 * such as bandwidth values.
116 * struct dc_stream_state - Represents the hw configuration for the pipeline from
117 * a framebuffer to a display. Maps one-to-one with dc_sink.
119 * struct dc_plane_state - Represents a framebuffer. Each stream has at least one,
120 * and may have more in the Multi-Plane Overlay case.
122 * struct resource_context - Represents the programmable state of everything in
123 * the resource_pool. Not directly accessible by dm.
125 * struct pipe_ctx - A member of struct resource_context. Represents the
126 * internal hardware pipeline components. Each dc_plane_state has either
127 * one or two (in the pipe-split case).
130 /*******************************************************************************
132 ******************************************************************************/
134 static inline void elevate_update_type(enum surface_update_type *original, enum surface_update_type new)
140 static void destroy_links(struct dc *dc)
144 for (i = 0; i < dc->link_count; i++) {
145 if (NULL != dc->links[i])
146 link_destroy(&dc->links[i]);
150 static bool create_links(
152 uint32_t num_virtual_links)
156 struct dc_bios *bios = dc->ctx->dc_bios;
160 connectors_num = bios->funcs->get_connectors_number(bios);
162 if (connectors_num > ENUM_ID_COUNT) {
164 "DC: Number of connectors %d exceeds maximum of %d!\n",
170 dm_output_to_console(
171 "DC: %s: connectors_num: physical:%d, virtual:%d\n",
176 for (i = 0; i < connectors_num; i++) {
177 struct link_init_data link_init_params = {0};
178 struct dc_link *link;
180 link_init_params.ctx = dc->ctx;
181 /* next BIOS object table connector */
182 link_init_params.connector_index = i;
183 link_init_params.link_index = dc->link_count;
184 link_init_params.dc = dc;
185 link = link_create(&link_init_params);
188 bool should_destory_link = false;
190 if (link->connector_signal == SIGNAL_TYPE_EDP) {
191 if (dc->config.edp_not_connected) {
192 if (!IS_DIAG_DC(dc->ctx->dce_environment))
193 should_destory_link = true;
195 enum dc_connection_type type;
196 dc_link_detect_sink(link, &type);
197 if (type == dc_connection_none)
198 should_destory_link = true;
202 if (dc->config.force_enum_edp || !should_destory_link) {
203 dc->links[dc->link_count] = link;
212 for (i = 0; i < num_virtual_links; i++) {
213 struct dc_link *link = kzalloc(sizeof(*link), GFP_KERNEL);
214 struct encoder_init_data enc_init = {0};
221 link->link_index = dc->link_count;
222 dc->links[dc->link_count] = link;
227 link->connector_signal = SIGNAL_TYPE_VIRTUAL;
228 link->link_id.type = OBJECT_TYPE_CONNECTOR;
229 link->link_id.id = CONNECTOR_ID_VIRTUAL;
230 link->link_id.enum_id = ENUM_ID_1;
231 link->link_enc = kzalloc(sizeof(*link->link_enc), GFP_KERNEL);
233 if (!link->link_enc) {
238 link->link_status.dpcd_caps = &link->dpcd_caps;
240 enc_init.ctx = dc->ctx;
241 enc_init.channel = CHANNEL_ID_UNKNOWN;
242 enc_init.hpd_source = HPD_SOURCEID_UNKNOWN;
243 enc_init.transmitter = TRANSMITTER_UNKNOWN;
244 enc_init.connector = link->link_id;
245 enc_init.encoder.type = OBJECT_TYPE_ENCODER;
246 enc_init.encoder.id = ENCODER_ID_INTERNAL_VIRTUAL;
247 enc_init.encoder.enum_id = ENUM_ID_1;
248 virtual_link_encoder_construct(link->link_enc, &enc_init);
257 static struct dc_perf_trace *dc_perf_trace_create(void)
259 return kzalloc(sizeof(struct dc_perf_trace), GFP_KERNEL);
262 static void dc_perf_trace_destroy(struct dc_perf_trace **perf_trace)
269 *****************************************************************************
270 * Function: dc_stream_adjust_vmin_vmax
273 * Looks up the pipe context of dc_stream_state and updates the
274 * vertical_total_min and vertical_total_max of the DRR, Dynamic Refresh
275 * Rate, which is a power-saving feature that targets reducing panel
276 * refresh rate while the screen is static
278 * @param [in] dc: dc reference
279 * @param [in] stream: Initial dc stream state
280 * @param [in] adjust: Updated parameters for vertical_total_min and
282 *****************************************************************************
284 bool dc_stream_adjust_vmin_vmax(struct dc *dc,
285 struct dc_stream_state *stream,
286 struct dc_crtc_timing_adjust *adjust)
291 stream->adjust = *adjust;
293 for (i = 0; i < MAX_PIPES; i++) {
294 struct pipe_ctx *pipe = &dc->current_state->res_ctx.pipe_ctx[i];
296 if (pipe->stream == stream && pipe->stream_res.tg) {
297 dc->hwss.set_drr(&pipe,
302 adjust->v_total_mid_frame_num);
310 bool dc_stream_get_crtc_position(struct dc *dc,
311 struct dc_stream_state **streams, int num_streams,
312 unsigned int *v_pos, unsigned int *nom_v_pos)
314 /* TODO: Support multiple streams */
315 const struct dc_stream_state *stream = streams[0];
318 struct crtc_position position;
320 for (i = 0; i < MAX_PIPES; i++) {
321 struct pipe_ctx *pipe =
322 &dc->current_state->res_ctx.pipe_ctx[i];
324 if (pipe->stream == stream && pipe->stream_res.stream_enc) {
325 dc->hwss.get_position(&pipe, 1, &position);
327 *v_pos = position.vertical_count;
328 *nom_v_pos = position.nominal_vcount;
336 * dc_stream_configure_crc() - Configure CRC capture for the given stream.
338 * @stream: The stream to configure CRC on.
339 * @enable: Enable CRC if true, disable otherwise.
340 * @continuous: Capture CRC on every frame if true. Otherwise, only capture
343 * By default, only CRC0 is configured, and the entire frame is used to
346 bool dc_stream_configure_crc(struct dc *dc, struct dc_stream_state *stream,
347 bool enable, bool continuous)
350 struct pipe_ctx *pipe;
351 struct crc_params param;
352 struct timing_generator *tg;
354 for (i = 0; i < MAX_PIPES; i++) {
355 pipe = &dc->current_state->res_ctx.pipe_ctx[i];
356 if (pipe->stream == stream && !pipe->top_pipe && !pipe->prev_odm_pipe)
359 /* Stream not found */
363 /* Always capture the full frame */
364 param.windowa_x_start = 0;
365 param.windowa_y_start = 0;
366 param.windowa_x_end = pipe->stream->timing.h_addressable;
367 param.windowa_y_end = pipe->stream->timing.v_addressable;
368 param.windowb_x_start = 0;
369 param.windowb_y_start = 0;
370 param.windowb_x_end = pipe->stream->timing.h_addressable;
371 param.windowb_y_end = pipe->stream->timing.v_addressable;
373 param.dsc_mode = pipe->stream->timing.flags.DSC ? 1:0;
374 param.odm_mode = pipe->next_odm_pipe ? 1:0;
376 /* Default to the union of both windows */
377 param.selection = UNION_WINDOW_A_B;
378 param.continuous_mode = continuous;
379 param.enable = enable;
381 tg = pipe->stream_res.tg;
383 /* Only call if supported */
384 if (tg->funcs->configure_crc)
385 return tg->funcs->configure_crc(tg, ¶m);
386 DC_LOG_WARNING("CRC capture not supported.");
391 * dc_stream_get_crc() - Get CRC values for the given stream.
393 * @stream: The DC stream state of the stream to get CRCs from.
394 * @r_cr, g_y, b_cb: CRC values for the three channels are stored here.
396 * dc_stream_configure_crc needs to be called beforehand to enable CRCs.
397 * Return false if stream is not found, or if CRCs are not enabled.
399 bool dc_stream_get_crc(struct dc *dc, struct dc_stream_state *stream,
400 uint32_t *r_cr, uint32_t *g_y, uint32_t *b_cb)
403 struct pipe_ctx *pipe;
404 struct timing_generator *tg;
406 for (i = 0; i < MAX_PIPES; i++) {
407 pipe = &dc->current_state->res_ctx.pipe_ctx[i];
408 if (pipe->stream == stream)
411 /* Stream not found */
415 tg = pipe->stream_res.tg;
417 if (tg->funcs->get_crc)
418 return tg->funcs->get_crc(tg, r_cr, g_y, b_cb);
419 DC_LOG_WARNING("CRC capture not supported.");
423 void dc_stream_set_dyn_expansion(struct dc *dc, struct dc_stream_state *stream,
424 enum dc_dynamic_expansion option)
426 /* OPP FMT dyn expansion updates*/
428 struct pipe_ctx *pipe_ctx;
430 for (i = 0; i < MAX_PIPES; i++) {
431 if (dc->current_state->res_ctx.pipe_ctx[i].stream
433 pipe_ctx = &dc->current_state->res_ctx.pipe_ctx[i];
434 pipe_ctx->stream_res.opp->dyn_expansion = option;
435 pipe_ctx->stream_res.opp->funcs->opp_set_dyn_expansion(
436 pipe_ctx->stream_res.opp,
437 COLOR_SPACE_YCBCR601,
438 stream->timing.display_color_depth,
444 void dc_stream_set_dither_option(struct dc_stream_state *stream,
445 enum dc_dither_option option)
447 struct bit_depth_reduction_params params;
448 struct dc_link *link = stream->link;
449 struct pipe_ctx *pipes = NULL;
452 for (i = 0; i < MAX_PIPES; i++) {
453 if (link->dc->current_state->res_ctx.pipe_ctx[i].stream ==
455 pipes = &link->dc->current_state->res_ctx.pipe_ctx[i];
462 if (option > DITHER_OPTION_MAX)
465 stream->dither_option = option;
467 memset(¶ms, 0, sizeof(params));
468 resource_build_bit_depth_reduction_params(stream, ¶ms);
469 stream->bit_depth_params = params;
471 if (pipes->plane_res.xfm &&
472 pipes->plane_res.xfm->funcs->transform_set_pixel_storage_depth) {
473 pipes->plane_res.xfm->funcs->transform_set_pixel_storage_depth(
474 pipes->plane_res.xfm,
475 pipes->plane_res.scl_data.lb_params.depth,
476 &stream->bit_depth_params);
479 pipes->stream_res.opp->funcs->
480 opp_program_bit_depth_reduction(pipes->stream_res.opp, ¶ms);
483 bool dc_stream_set_gamut_remap(struct dc *dc, const struct dc_stream_state *stream)
487 struct pipe_ctx *pipes;
489 for (i = 0; i < MAX_PIPES; i++) {
490 if (dc->current_state->res_ctx.pipe_ctx[i].stream == stream) {
491 pipes = &dc->current_state->res_ctx.pipe_ctx[i];
492 dc->hwss.program_gamut_remap(pipes);
500 bool dc_stream_program_csc_matrix(struct dc *dc, struct dc_stream_state *stream)
504 struct pipe_ctx *pipes;
506 for (i = 0; i < MAX_PIPES; i++) {
507 if (dc->current_state->res_ctx.pipe_ctx[i].stream
510 pipes = &dc->current_state->res_ctx.pipe_ctx[i];
511 dc->hwss.program_output_csc(dc,
513 stream->output_color_space,
514 stream->csc_color_matrix.matrix,
515 pipes->stream_res.opp->inst);
523 void dc_stream_set_static_screen_params(struct dc *dc,
524 struct dc_stream_state **streams,
526 const struct dc_static_screen_params *params)
530 struct pipe_ctx *pipes_affected[MAX_PIPES];
531 int num_pipes_affected = 0;
533 for (i = 0; i < num_streams; i++) {
534 struct dc_stream_state *stream = streams[i];
536 for (j = 0; j < MAX_PIPES; j++) {
537 if (dc->current_state->res_ctx.pipe_ctx[j].stream
539 pipes_affected[num_pipes_affected++] =
540 &dc->current_state->res_ctx.pipe_ctx[j];
545 dc->hwss.set_static_screen_control(pipes_affected, num_pipes_affected, params);
548 static void dc_destruct(struct dc *dc)
550 if (dc->current_state) {
551 dc_release_state(dc->current_state);
552 dc->current_state = NULL;
558 dc_destroy_clk_mgr(dc->clk_mgr);
562 dc_destroy_resource_pool(dc);
564 if (dc->ctx->gpio_service)
565 dal_gpio_service_destroy(&dc->ctx->gpio_service);
567 if (dc->ctx->created_bios)
568 dal_bios_parser_destroy(&dc->ctx->dc_bios);
570 dc_perf_trace_destroy(&dc->ctx->perf_trace);
581 #ifdef CONFIG_DRM_AMD_DC_DCN
589 kfree(dc->vm_helper);
590 dc->vm_helper = NULL;
594 static bool dc_construct_ctx(struct dc *dc,
595 const struct dc_init_data *init_params)
597 struct dc_context *dc_ctx;
598 enum dce_version dc_version = DCE_VERSION_UNKNOWN;
600 dc_ctx = kzalloc(sizeof(*dc_ctx), GFP_KERNEL);
604 dc_ctx->cgs_device = init_params->cgs_device;
605 dc_ctx->driver_context = init_params->driver;
607 dc_ctx->asic_id = init_params->asic_id;
608 dc_ctx->dc_sink_id_count = 0;
609 dc_ctx->dc_stream_id_count = 0;
610 dc_ctx->dce_environment = init_params->dce_environment;
614 dc_version = resource_parse_asic_id(init_params->asic_id);
615 dc_ctx->dce_version = dc_version;
617 dc_ctx->perf_trace = dc_perf_trace_create();
618 if (!dc_ctx->perf_trace) {
619 ASSERT_CRITICAL(false);
628 static bool dc_construct(struct dc *dc,
629 const struct dc_init_data *init_params)
631 struct dc_context *dc_ctx;
632 struct bw_calcs_dceip *dc_dceip;
633 struct bw_calcs_vbios *dc_vbios;
634 #ifdef CONFIG_DRM_AMD_DC_DCN
635 struct dcn_soc_bounding_box *dcn_soc;
636 struct dcn_ip_params *dcn_ip;
639 dc->config = init_params->flags;
641 // Allocate memory for the vm_helper
642 dc->vm_helper = kzalloc(sizeof(struct vm_helper), GFP_KERNEL);
643 if (!dc->vm_helper) {
644 dm_error("%s: failed to create dc->vm_helper\n", __func__);
648 memcpy(&dc->bb_overrides, &init_params->bb_overrides, sizeof(dc->bb_overrides));
650 dc_dceip = kzalloc(sizeof(*dc_dceip), GFP_KERNEL);
652 dm_error("%s: failed to create dceip\n", __func__);
656 dc->bw_dceip = dc_dceip;
658 dc_vbios = kzalloc(sizeof(*dc_vbios), GFP_KERNEL);
660 dm_error("%s: failed to create vbios\n", __func__);
664 dc->bw_vbios = dc_vbios;
665 #ifdef CONFIG_DRM_AMD_DC_DCN
666 dcn_soc = kzalloc(sizeof(*dcn_soc), GFP_KERNEL);
668 dm_error("%s: failed to create dcn_soc\n", __func__);
672 dc->dcn_soc = dcn_soc;
674 dcn_ip = kzalloc(sizeof(*dcn_ip), GFP_KERNEL);
676 dm_error("%s: failed to create dcn_ip\n", __func__);
681 dc->soc_bounding_box = init_params->soc_bounding_box;
684 if (!dc_construct_ctx(dc, init_params)) {
685 dm_error("%s: failed to create ctx\n", __func__);
691 /* Resource should construct all asic specific resources.
692 * This should be the only place where we need to parse the asic id
694 if (init_params->vbios_override)
695 dc_ctx->dc_bios = init_params->vbios_override;
697 /* Create BIOS parser */
698 struct bp_init_data bp_init_data;
700 bp_init_data.ctx = dc_ctx;
701 bp_init_data.bios = init_params->asic_id.atombios_base_address;
703 dc_ctx->dc_bios = dal_bios_parser_create(
704 &bp_init_data, dc_ctx->dce_version);
706 if (!dc_ctx->dc_bios) {
707 ASSERT_CRITICAL(false);
711 dc_ctx->created_bios = true;
714 dc->vendor_signature = init_params->vendor_signature;
716 /* Create GPIO service */
717 dc_ctx->gpio_service = dal_gpio_service_create(
719 dc_ctx->dce_environment,
722 if (!dc_ctx->gpio_service) {
723 ASSERT_CRITICAL(false);
727 dc->res_pool = dc_create_resource_pool(dc, init_params, dc_ctx->dce_version);
731 dc->clk_mgr = dc_clk_mgr_create(dc->ctx, dc->res_pool->pp_smu, dc->res_pool->dccg);
734 #ifdef CONFIG_DRM_AMD_DC_DCN3_0
735 dc->clk_mgr->force_smu_not_present = init_params->force_smu_not_present;
738 if (dc->res_pool->funcs->update_bw_bounding_box)
739 dc->res_pool->funcs->update_bw_bounding_box(dc, dc->clk_mgr->bw_params);
741 /* Creation of current_state must occur after dc->dml
742 * is initialized in dc_create_resource_pool because
743 * on creation it copies the contents of dc->dml
746 dc->current_state = dc_create_state(dc);
748 if (!dc->current_state) {
749 dm_error("%s: failed to create validate ctx\n", __func__);
753 dc_resource_state_construct(dc, dc->current_state);
755 if (!create_links(dc, init_params->num_virtual_links))
764 static bool disable_all_writeback_pipes_for_stream(
766 struct dc_stream_state *stream,
767 struct dc_state *context)
771 for (i = 0; i < stream->num_wb_info; i++)
772 stream->writeback_info[i].wb_enabled = false;
777 void apply_ctx_interdependent_lock(struct dc *dc, struct dc_state *context, struct dc_stream_state *stream, bool lock)
781 /* Checks if interdependent update function pointer is NULL or not, takes care of DCE110 case */
782 if (dc->hwss.interdependent_update_lock)
783 dc->hwss.interdependent_update_lock(dc, context, lock);
785 for (i = 0; i < dc->res_pool->pipe_count; i++) {
786 struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[i];
787 struct pipe_ctx *old_pipe_ctx = &dc->current_state->res_ctx.pipe_ctx[i];
789 // Copied conditions that were previously in dce110_apply_ctx_for_surface
790 if (stream == pipe_ctx->stream) {
791 if (!pipe_ctx->top_pipe &&
792 (pipe_ctx->plane_state || old_pipe_ctx->plane_state))
793 dc->hwss.pipe_control_lock(dc, pipe_ctx, lock);
799 static void disable_dangling_plane(struct dc *dc, struct dc_state *context)
802 struct dc_state *dangling_context = dc_create_state(dc);
803 struct dc_state *current_ctx;
805 if (dangling_context == NULL)
808 dc_resource_state_copy_construct(dc->current_state, dangling_context);
810 for (i = 0; i < dc->res_pool->pipe_count; i++) {
811 struct dc_stream_state *old_stream =
812 dc->current_state->res_ctx.pipe_ctx[i].stream;
813 bool should_disable = true;
815 for (j = 0; j < context->stream_count; j++) {
816 if (old_stream == context->streams[j]) {
817 should_disable = false;
821 if (should_disable && old_stream) {
822 dc_rem_all_planes_for_stream(dc, old_stream, dangling_context);
823 disable_all_writeback_pipes_for_stream(dc, old_stream, dangling_context);
825 if (dc->hwss.apply_ctx_for_surface) {
826 apply_ctx_interdependent_lock(dc, dc->current_state, old_stream, true);
827 dc->hwss.apply_ctx_for_surface(dc, old_stream, 0, dangling_context);
828 apply_ctx_interdependent_lock(dc, dc->current_state, old_stream, false);
829 dc->hwss.post_unlock_program_front_end(dc, dangling_context);
831 if (dc->hwss.program_front_end_for_ctx) {
832 dc->hwss.interdependent_update_lock(dc, dc->current_state, true);
833 dc->hwss.program_front_end_for_ctx(dc, dangling_context);
834 dc->hwss.interdependent_update_lock(dc, dc->current_state, false);
835 dc->hwss.post_unlock_program_front_end(dc, dangling_context);
840 current_ctx = dc->current_state;
841 dc->current_state = dangling_context;
842 dc_release_state(current_ctx);
845 static void wait_for_no_pipes_pending(struct dc *dc, struct dc_state *context)
849 for (i = 0; i < MAX_PIPES; i++) {
851 struct pipe_ctx *pipe = &context->res_ctx.pipe_ctx[i];
853 if (!pipe->plane_state)
857 while (count < 100000) {
858 /* Must set to false to start with, due to OR in update function */
859 pipe->plane_state->status.is_flip_pending = false;
860 dc->hwss.update_pending_status(pipe);
861 if (!pipe->plane_state->status.is_flip_pending)
866 ASSERT(!pipe->plane_state->status.is_flip_pending);
871 /*******************************************************************************
873 ******************************************************************************/
875 struct dc *dc_create(const struct dc_init_data *init_params)
877 struct dc *dc = kzalloc(sizeof(*dc), GFP_KERNEL);
878 unsigned int full_pipe_count;
883 if (init_params->dce_environment == DCE_ENV_VIRTUAL_HW) {
884 if (false == dc_construct_ctx(dc, init_params)) {
889 if (false == dc_construct(dc, init_params)) {
894 full_pipe_count = dc->res_pool->pipe_count;
895 if (dc->res_pool->underlay_pipe_index != NO_UNDERLAY_PIPE)
897 dc->caps.max_streams = min(
899 dc->res_pool->stream_enc_count);
901 dc->optimize_seamless_boot_streams = 0;
902 dc->caps.max_links = dc->link_count;
903 dc->caps.max_audios = dc->res_pool->audio_count;
904 dc->caps.linear_pitch_alignment = 64;
906 dc->caps.max_dp_protocol_version = DP_VERSION_1_4;
908 if (dc->res_pool->dmcu != NULL)
909 dc->versions.dmcu_version = dc->res_pool->dmcu->dmcu_version;
912 /* Populate versioning information */
913 dc->versions.dc_ver = DC_VER;
915 dc->build_id = DC_BUILD_ID;
917 DC_LOG_DC("Display Core initialized\n");
930 void dc_hardware_init(struct dc *dc)
932 if (dc->ctx->dce_environment != DCE_ENV_VIRTUAL_HW)
933 dc->hwss.init_hw(dc);
936 void dc_init_callbacks(struct dc *dc,
937 const struct dc_callback_init *init_params)
939 #ifdef CONFIG_DRM_AMD_DC_HDCP
940 dc->ctx->cp_psp = init_params->cp_psp;
944 void dc_deinit_callbacks(struct dc *dc)
946 #ifdef CONFIG_DRM_AMD_DC_HDCP
947 memset(&dc->ctx->cp_psp, 0, sizeof(dc->ctx->cp_psp));
951 void dc_destroy(struct dc **dc)
958 static void enable_timing_multisync(
960 struct dc_state *ctx)
962 int i = 0, multisync_count = 0;
963 int pipe_count = dc->res_pool->pipe_count;
964 struct pipe_ctx *multisync_pipes[MAX_PIPES] = { NULL };
966 for (i = 0; i < pipe_count; i++) {
967 if (!ctx->res_ctx.pipe_ctx[i].stream ||
968 !ctx->res_ctx.pipe_ctx[i].stream->triggered_crtc_reset.enabled)
970 if (ctx->res_ctx.pipe_ctx[i].stream == ctx->res_ctx.pipe_ctx[i].stream->triggered_crtc_reset.event_source)
972 multisync_pipes[multisync_count] = &ctx->res_ctx.pipe_ctx[i];
976 if (multisync_count > 0) {
977 dc->hwss.enable_per_frame_crtc_position_reset(
978 dc, multisync_count, multisync_pipes);
982 static void program_timing_sync(
984 struct dc_state *ctx)
989 int pipe_count = dc->res_pool->pipe_count;
990 struct pipe_ctx *unsynced_pipes[MAX_PIPES] = { NULL };
992 for (i = 0; i < pipe_count; i++) {
993 if (!ctx->res_ctx.pipe_ctx[i].stream || ctx->res_ctx.pipe_ctx[i].top_pipe)
996 unsynced_pipes[i] = &ctx->res_ctx.pipe_ctx[i];
999 for (i = 0; i < pipe_count; i++) {
1001 struct pipe_ctx *pipe_set[MAX_PIPES];
1003 if (!unsynced_pipes[i])
1006 pipe_set[0] = unsynced_pipes[i];
1007 unsynced_pipes[i] = NULL;
1009 /* Add tg to the set, search rest of the tg's for ones with
1010 * same timing, add all tgs with same timing to the group
1012 for (j = i + 1; j < pipe_count; j++) {
1013 if (!unsynced_pipes[j])
1016 if (resource_are_streams_timing_synchronizable(
1017 unsynced_pipes[j]->stream,
1018 pipe_set[0]->stream)) {
1019 pipe_set[group_size] = unsynced_pipes[j];
1020 unsynced_pipes[j] = NULL;
1025 /* set first unblanked pipe as master */
1026 for (j = 0; j < group_size; j++) {
1029 if (pipe_set[j]->stream_res.opp->funcs->dpg_is_blanked)
1031 pipe_set[j]->stream_res.opp->funcs->dpg_is_blanked(pipe_set[j]->stream_res.opp);
1034 pipe_set[j]->stream_res.tg->funcs->is_blanked(pipe_set[j]->stream_res.tg);
1039 swap(pipe_set[0], pipe_set[j]);
1045 for (k = 0; k < group_size; k++) {
1046 struct dc_stream_status *status = dc_stream_get_status_from_state(ctx, pipe_set[k]->stream);
1048 status->timing_sync_info.group_id = num_group;
1049 status->timing_sync_info.group_size = group_size;
1051 status->timing_sync_info.master = true;
1053 status->timing_sync_info.master = false;
1056 /* remove any other unblanked pipes as they have already been synced */
1057 for (j = j + 1; j < group_size; j++) {
1060 if (pipe_set[j]->stream_res.opp->funcs->dpg_is_blanked)
1062 pipe_set[j]->stream_res.opp->funcs->dpg_is_blanked(pipe_set[j]->stream_res.opp);
1065 pipe_set[j]->stream_res.tg->funcs->is_blanked(pipe_set[j]->stream_res.tg);
1068 pipe_set[j] = pipe_set[group_size];
1073 if (group_size > 1) {
1074 dc->hwss.enable_timing_synchronization(
1075 dc, group_index, group_size, pipe_set);
1082 static bool context_changed(
1084 struct dc_state *context)
1088 if (context->stream_count != dc->current_state->stream_count)
1091 for (i = 0; i < dc->current_state->stream_count; i++) {
1092 if (dc->current_state->streams[i] != context->streams[i])
1099 bool dc_validate_seamless_boot_timing(const struct dc *dc,
1100 const struct dc_sink *sink,
1101 struct dc_crtc_timing *crtc_timing)
1103 struct timing_generator *tg;
1104 struct stream_encoder *se = NULL;
1106 struct dc_crtc_timing hw_crtc_timing = {0};
1108 struct dc_link *link = sink->link;
1109 unsigned int i, enc_inst, tg_inst = 0;
1111 // Seamless port only support single DP and EDP so far
1112 if (sink->sink_signal != SIGNAL_TYPE_DISPLAY_PORT &&
1113 sink->sink_signal != SIGNAL_TYPE_EDP)
1116 /* Check for enabled DIG to identify enabled display */
1117 if (!link->link_enc->funcs->is_dig_enabled(link->link_enc))
1120 enc_inst = link->link_enc->funcs->get_dig_frontend(link->link_enc);
1122 if (enc_inst == ENGINE_ID_UNKNOWN)
1125 for (i = 0; i < dc->res_pool->stream_enc_count; i++) {
1126 if (dc->res_pool->stream_enc[i]->id == enc_inst) {
1128 se = dc->res_pool->stream_enc[i];
1130 tg_inst = dc->res_pool->stream_enc[i]->funcs->dig_source_otg(
1131 dc->res_pool->stream_enc[i]);
1136 // tg_inst not found
1137 if (i == dc->res_pool->stream_enc_count)
1140 if (tg_inst >= dc->res_pool->timing_generator_count)
1143 tg = dc->res_pool->timing_generators[tg_inst];
1145 if (!tg->funcs->get_hw_timing)
1148 if (!tg->funcs->get_hw_timing(tg, &hw_crtc_timing))
1151 if (crtc_timing->h_total != hw_crtc_timing.h_total)
1154 if (crtc_timing->h_border_left != hw_crtc_timing.h_border_left)
1157 if (crtc_timing->h_addressable != hw_crtc_timing.h_addressable)
1160 if (crtc_timing->h_border_right != hw_crtc_timing.h_border_right)
1163 if (crtc_timing->h_front_porch != hw_crtc_timing.h_front_porch)
1166 if (crtc_timing->h_sync_width != hw_crtc_timing.h_sync_width)
1169 if (crtc_timing->v_total != hw_crtc_timing.v_total)
1172 if (crtc_timing->v_border_top != hw_crtc_timing.v_border_top)
1175 if (crtc_timing->v_addressable != hw_crtc_timing.v_addressable)
1178 if (crtc_timing->v_border_bottom != hw_crtc_timing.v_border_bottom)
1181 if (crtc_timing->v_front_porch != hw_crtc_timing.v_front_porch)
1184 if (crtc_timing->v_sync_width != hw_crtc_timing.v_sync_width)
1187 if (dc_is_dp_signal(link->connector_signal)) {
1188 unsigned int pix_clk_100hz;
1190 dc->res_pool->dp_clock_source->funcs->get_pixel_clk_frequency_100hz(
1191 dc->res_pool->dp_clock_source,
1192 tg_inst, &pix_clk_100hz);
1194 if (crtc_timing->pix_clk_100hz != pix_clk_100hz)
1197 if (!se->funcs->dp_get_pixel_format)
1200 if (!se->funcs->dp_get_pixel_format(
1202 &hw_crtc_timing.pixel_encoding,
1203 &hw_crtc_timing.display_color_depth))
1206 if (hw_crtc_timing.display_color_depth != crtc_timing->display_color_depth)
1209 if (hw_crtc_timing.pixel_encoding != crtc_timing->pixel_encoding)
1216 bool dc_enable_stereo(
1218 struct dc_state *context,
1219 struct dc_stream_state *streams[],
1220 uint8_t stream_count)
1224 struct pipe_ctx *pipe;
1226 for (i = 0; i < MAX_PIPES; i++) {
1227 if (context != NULL)
1228 pipe = &context->res_ctx.pipe_ctx[i];
1230 pipe = &dc->current_state->res_ctx.pipe_ctx[i];
1231 for (j = 0 ; pipe && j < stream_count; j++) {
1232 if (streams[j] && streams[j] == pipe->stream &&
1233 dc->hwss.setup_stereo)
1234 dc->hwss.setup_stereo(pipe, dc);
1241 void dc_trigger_sync(struct dc *dc, struct dc_state *context)
1243 if (context->stream_count > 1 && !dc->debug.disable_timing_sync) {
1244 enable_timing_multisync(dc, context);
1245 program_timing_sync(dc, context);
1249 static uint8_t get_stream_mask(struct dc *dc, struct dc_state *context)
1252 unsigned int stream_mask = 0;
1254 for (i = 0; i < dc->res_pool->pipe_count; i++) {
1255 if (context->res_ctx.pipe_ctx[i].stream)
1256 stream_mask |= 1 << i;
1263 * Applies given context to HW and copy it into current context.
1264 * It's up to the user to release the src context afterwards.
1266 static enum dc_status dc_commit_state_no_check(struct dc *dc, struct dc_state *context)
1268 struct dc_bios *dcb = dc->ctx->dc_bios;
1269 enum dc_status result = DC_ERROR_UNEXPECTED;
1270 struct pipe_ctx *pipe;
1272 struct dc_stream_state *dc_streams[MAX_STREAMS] = {0};
1274 #if defined(CONFIG_DRM_AMD_DC_DCN3_0)
1275 dc_allow_idle_optimizations(dc, false);
1278 for (i = 0; i < context->stream_count; i++)
1279 dc_streams[i] = context->streams[i];
1281 if (!dcb->funcs->is_accelerated_mode(dcb))
1282 dc->hwss.enable_accelerated_mode(dc, context);
1284 for (i = 0; i < context->stream_count; i++) {
1285 if (context->streams[i]->apply_seamless_boot_optimization)
1286 dc->optimize_seamless_boot_streams++;
1289 if (context->stream_count > dc->optimize_seamless_boot_streams)
1290 dc->hwss.prepare_bandwidth(dc, context);
1292 disable_dangling_plane(dc, context);
1293 /* re-program planes for existing stream, in case we need to
1294 * free up plane resource for later use
1296 if (dc->hwss.apply_ctx_for_surface) {
1297 for (i = 0; i < context->stream_count; i++) {
1298 if (context->streams[i]->mode_changed)
1300 apply_ctx_interdependent_lock(dc, context, context->streams[i], true);
1301 dc->hwss.apply_ctx_for_surface(
1302 dc, context->streams[i],
1303 context->stream_status[i].plane_count,
1304 context); /* use new pipe config in new context */
1305 apply_ctx_interdependent_lock(dc, context, context->streams[i], false);
1306 dc->hwss.post_unlock_program_front_end(dc, context);
1310 /* Program hardware */
1311 for (i = 0; i < dc->res_pool->pipe_count; i++) {
1312 pipe = &context->res_ctx.pipe_ctx[i];
1313 dc->hwss.wait_for_mpcc_disconnect(dc, dc->res_pool, pipe);
1316 result = dc->hwss.apply_ctx_to_hw(dc, context);
1318 if (result != DC_OK)
1321 dc_trigger_sync(dc, context);
1323 /* Program all planes within new context*/
1324 if (dc->hwss.program_front_end_for_ctx) {
1325 dc->hwss.interdependent_update_lock(dc, context, true);
1326 dc->hwss.program_front_end_for_ctx(dc, context);
1327 dc->hwss.interdependent_update_lock(dc, context, false);
1328 dc->hwss.post_unlock_program_front_end(dc, context);
1330 for (i = 0; i < context->stream_count; i++) {
1331 const struct dc_link *link = context->streams[i]->link;
1333 if (!context->streams[i]->mode_changed)
1336 if (dc->hwss.apply_ctx_for_surface) {
1337 apply_ctx_interdependent_lock(dc, context, context->streams[i], true);
1338 dc->hwss.apply_ctx_for_surface(
1339 dc, context->streams[i],
1340 context->stream_status[i].plane_count,
1342 apply_ctx_interdependent_lock(dc, context, context->streams[i], false);
1343 dc->hwss.post_unlock_program_front_end(dc, context);
1348 * TODO rework dc_enable_stereo call to work with validation sets?
1350 for (k = 0; k < MAX_PIPES; k++) {
1351 pipe = &context->res_ctx.pipe_ctx[k];
1353 for (l = 0 ; pipe && l < context->stream_count; l++) {
1354 if (context->streams[l] &&
1355 context->streams[l] == pipe->stream &&
1356 dc->hwss.setup_stereo)
1357 dc->hwss.setup_stereo(pipe, dc);
1361 CONN_MSG_MODE(link, "{%dx%d, %dx%d@%dKhz}",
1362 context->streams[i]->timing.h_addressable,
1363 context->streams[i]->timing.v_addressable,
1364 context->streams[i]->timing.h_total,
1365 context->streams[i]->timing.v_total,
1366 context->streams[i]->timing.pix_clk_100hz / 10);
1369 dc_enable_stereo(dc, context, dc_streams, context->stream_count);
1371 if (context->stream_count > dc->optimize_seamless_boot_streams) {
1372 /* Must wait for no flips to be pending before doing optimize bw */
1373 wait_for_no_pipes_pending(dc, context);
1374 /* pplib is notified if disp_num changed */
1375 dc->hwss.optimize_bandwidth(dc, context);
1378 context->stream_mask = get_stream_mask(dc, context);
1380 if (context->stream_mask != dc->current_state->stream_mask)
1381 dc_dmub_srv_notify_stream_mask(dc->ctx->dmub_srv, context->stream_mask);
1383 for (i = 0; i < context->stream_count; i++)
1384 context->streams[i]->mode_changed = false;
1386 dc_release_state(dc->current_state);
1388 dc->current_state = context;
1390 dc_retain_state(dc->current_state);
1395 bool dc_commit_state(struct dc *dc, struct dc_state *context)
1397 enum dc_status result = DC_ERROR_UNEXPECTED;
1400 if (false == context_changed(dc, context))
1403 DC_LOG_DC("%s: %d streams\n",
1404 __func__, context->stream_count);
1406 for (i = 0; i < context->stream_count; i++) {
1407 struct dc_stream_state *stream = context->streams[i];
1409 dc_stream_log(dc, stream);
1412 result = dc_commit_state_no_check(dc, context);
1414 return (result == DC_OK);
1417 #if defined(CONFIG_DRM_AMD_DC_DCN3_0)
1418 bool dc_acquire_release_mpc_3dlut(
1419 struct dc *dc, bool acquire,
1420 struct dc_stream_state *stream,
1421 struct dc_3dlut **lut,
1422 struct dc_transfer_func **shaper)
1426 bool found_pipe_idx = false;
1427 const struct resource_pool *pool = dc->res_pool;
1428 struct resource_context *res_ctx = &dc->current_state->res_ctx;
1431 if (pool && res_ctx) {
1433 /*find pipe idx for the given stream*/
1434 for (pipe_idx = 0; pipe_idx < pool->pipe_count; pipe_idx++) {
1435 if (res_ctx->pipe_ctx[pipe_idx].stream == stream) {
1436 found_pipe_idx = true;
1437 mpcc_id = res_ctx->pipe_ctx[pipe_idx].plane_res.hubp->inst;
1442 found_pipe_idx = true;/*for release pipe_idx is not required*/
1444 if (found_pipe_idx) {
1445 if (acquire && pool->funcs->acquire_post_bldn_3dlut)
1446 ret = pool->funcs->acquire_post_bldn_3dlut(res_ctx, pool, mpcc_id, lut, shaper);
1447 else if (acquire == false && pool->funcs->release_post_bldn_3dlut)
1448 ret = pool->funcs->release_post_bldn_3dlut(res_ctx, pool, lut, shaper);
1454 static bool is_flip_pending_in_pipes(struct dc *dc, struct dc_state *context)
1457 struct pipe_ctx *pipe;
1459 for (i = 0; i < MAX_PIPES; i++) {
1460 pipe = &context->res_ctx.pipe_ctx[i];
1462 if (!pipe->plane_state)
1465 /* Must set to false to start with, due to OR in update function */
1466 pipe->plane_state->status.is_flip_pending = false;
1467 dc->hwss.update_pending_status(pipe);
1468 if (pipe->plane_state->status.is_flip_pending)
1474 bool dc_post_update_surfaces_to_stream(struct dc *dc)
1477 struct dc_state *context = dc->current_state;
1479 if ((!dc->optimized_required) || dc->optimize_seamless_boot_streams > 0)
1482 post_surface_trace(dc);
1484 if (is_flip_pending_in_pipes(dc, context))
1487 for (i = 0; i < dc->res_pool->pipe_count; i++)
1488 if (context->res_ctx.pipe_ctx[i].stream == NULL ||
1489 context->res_ctx.pipe_ctx[i].plane_state == NULL) {
1490 context->res_ctx.pipe_ctx[i].pipe_idx = i;
1491 dc->hwss.disable_plane(dc, &context->res_ctx.pipe_ctx[i]);
1494 dc->hwss.optimize_bandwidth(dc, context);
1496 dc->optimized_required = false;
1497 dc->wm_optimized_required = false;
1502 static void init_state(struct dc *dc, struct dc_state *context)
1504 /* Each context must have their own instance of VBA and in order to
1505 * initialize and obtain IP and SOC the base DML instance from DC is
1506 * initially copied into every context
1508 #ifdef CONFIG_DRM_AMD_DC_DCN
1509 memcpy(&context->bw_ctx.dml, &dc->dml, sizeof(struct display_mode_lib));
1513 struct dc_state *dc_create_state(struct dc *dc)
1515 struct dc_state *context = kzalloc(sizeof(struct dc_state),
1521 init_state(dc, context);
1523 kref_init(&context->refcount);
1528 struct dc_state *dc_copy_state(struct dc_state *src_ctx)
1531 struct dc_state *new_ctx = kvmalloc(sizeof(struct dc_state), GFP_KERNEL);
1535 memcpy(new_ctx, src_ctx, sizeof(struct dc_state));
1537 for (i = 0; i < MAX_PIPES; i++) {
1538 struct pipe_ctx *cur_pipe = &new_ctx->res_ctx.pipe_ctx[i];
1540 if (cur_pipe->top_pipe)
1541 cur_pipe->top_pipe = &new_ctx->res_ctx.pipe_ctx[cur_pipe->top_pipe->pipe_idx];
1543 if (cur_pipe->bottom_pipe)
1544 cur_pipe->bottom_pipe = &new_ctx->res_ctx.pipe_ctx[cur_pipe->bottom_pipe->pipe_idx];
1546 if (cur_pipe->prev_odm_pipe)
1547 cur_pipe->prev_odm_pipe = &new_ctx->res_ctx.pipe_ctx[cur_pipe->prev_odm_pipe->pipe_idx];
1549 if (cur_pipe->next_odm_pipe)
1550 cur_pipe->next_odm_pipe = &new_ctx->res_ctx.pipe_ctx[cur_pipe->next_odm_pipe->pipe_idx];
1554 for (i = 0; i < new_ctx->stream_count; i++) {
1555 dc_stream_retain(new_ctx->streams[i]);
1556 for (j = 0; j < new_ctx->stream_status[i].plane_count; j++)
1557 dc_plane_state_retain(
1558 new_ctx->stream_status[i].plane_states[j]);
1561 kref_init(&new_ctx->refcount);
1566 void dc_retain_state(struct dc_state *context)
1568 kref_get(&context->refcount);
1571 static void dc_state_free(struct kref *kref)
1573 struct dc_state *context = container_of(kref, struct dc_state, refcount);
1574 dc_resource_state_destruct(context);
1578 void dc_release_state(struct dc_state *context)
1580 kref_put(&context->refcount, dc_state_free);
1583 bool dc_set_generic_gpio_for_stereo(bool enable,
1584 struct gpio_service *gpio_service)
1586 enum gpio_result gpio_result = GPIO_RESULT_NON_SPECIFIC_ERROR;
1587 struct gpio_pin_info pin_info;
1588 struct gpio *generic;
1589 struct gpio_generic_mux_config *config = kzalloc(sizeof(struct gpio_generic_mux_config),
1594 pin_info = dal_gpio_get_generic_pin_info(gpio_service, GPIO_ID_GENERIC, 0);
1596 if (pin_info.mask == 0xFFFFFFFF || pin_info.offset == 0xFFFFFFFF) {
1600 generic = dal_gpio_service_create_generic_mux(
1611 gpio_result = dal_gpio_open(generic, GPIO_MODE_OUTPUT);
1613 config->enable_output_from_mux = enable;
1614 config->mux_select = GPIO_SIGNAL_SOURCE_PASS_THROUGH_STEREO_SYNC;
1616 if (gpio_result == GPIO_RESULT_OK)
1617 gpio_result = dal_mux_setup_config(generic, config);
1619 if (gpio_result == GPIO_RESULT_OK) {
1620 dal_gpio_close(generic);
1621 dal_gpio_destroy_generic_mux(&generic);
1625 dal_gpio_close(generic);
1626 dal_gpio_destroy_generic_mux(&generic);
1632 static bool is_surface_in_context(
1633 const struct dc_state *context,
1634 const struct dc_plane_state *plane_state)
1638 for (j = 0; j < MAX_PIPES; j++) {
1639 const struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[j];
1641 if (plane_state == pipe_ctx->plane_state) {
1649 static enum surface_update_type get_plane_info_update_type(const struct dc_surface_update *u)
1651 union surface_update_flags *update_flags = &u->surface->update_flags;
1652 enum surface_update_type update_type = UPDATE_TYPE_FAST;
1655 return UPDATE_TYPE_FAST;
1657 if (u->plane_info->color_space != u->surface->color_space) {
1658 update_flags->bits.color_space_change = 1;
1659 elevate_update_type(&update_type, UPDATE_TYPE_MED);
1662 if (u->plane_info->horizontal_mirror != u->surface->horizontal_mirror) {
1663 update_flags->bits.horizontal_mirror_change = 1;
1664 elevate_update_type(&update_type, UPDATE_TYPE_MED);
1667 if (u->plane_info->rotation != u->surface->rotation) {
1668 update_flags->bits.rotation_change = 1;
1669 elevate_update_type(&update_type, UPDATE_TYPE_FULL);
1672 if (u->plane_info->format != u->surface->format) {
1673 update_flags->bits.pixel_format_change = 1;
1674 elevate_update_type(&update_type, UPDATE_TYPE_FULL);
1677 if (u->plane_info->stereo_format != u->surface->stereo_format) {
1678 update_flags->bits.stereo_format_change = 1;
1679 elevate_update_type(&update_type, UPDATE_TYPE_FULL);
1682 if (u->plane_info->per_pixel_alpha != u->surface->per_pixel_alpha) {
1683 update_flags->bits.per_pixel_alpha_change = 1;
1684 elevate_update_type(&update_type, UPDATE_TYPE_MED);
1687 if (u->plane_info->global_alpha_value != u->surface->global_alpha_value) {
1688 update_flags->bits.global_alpha_change = 1;
1689 elevate_update_type(&update_type, UPDATE_TYPE_MED);
1692 if (u->plane_info->dcc.enable != u->surface->dcc.enable
1693 || u->plane_info->dcc.independent_64b_blks != u->surface->dcc.independent_64b_blks
1694 || u->plane_info->dcc.meta_pitch != u->surface->dcc.meta_pitch) {
1695 update_flags->bits.dcc_change = 1;
1696 elevate_update_type(&update_type, UPDATE_TYPE_MED);
1699 if (resource_pixel_format_to_bpp(u->plane_info->format) !=
1700 resource_pixel_format_to_bpp(u->surface->format)) {
1701 /* different bytes per element will require full bandwidth
1702 * and DML calculation
1704 update_flags->bits.bpp_change = 1;
1705 elevate_update_type(&update_type, UPDATE_TYPE_FULL);
1708 if (u->plane_info->plane_size.surface_pitch != u->surface->plane_size.surface_pitch
1709 || u->plane_info->plane_size.chroma_pitch != u->surface->plane_size.chroma_pitch) {
1710 update_flags->bits.plane_size_change = 1;
1711 elevate_update_type(&update_type, UPDATE_TYPE_MED);
1715 if (memcmp(&u->plane_info->tiling_info, &u->surface->tiling_info,
1716 sizeof(union dc_tiling_info)) != 0) {
1717 update_flags->bits.swizzle_change = 1;
1718 elevate_update_type(&update_type, UPDATE_TYPE_MED);
1720 /* todo: below are HW dependent, we should add a hook to
1721 * DCE/N resource and validated there.
1723 if (u->plane_info->tiling_info.gfx9.swizzle != DC_SW_LINEAR) {
1724 /* swizzled mode requires RQ to be setup properly,
1725 * thus need to run DML to calculate RQ settings
1727 update_flags->bits.bandwidth_change = 1;
1728 elevate_update_type(&update_type, UPDATE_TYPE_FULL);
1732 /* This should be UPDATE_TYPE_FAST if nothing has changed. */
1736 static enum surface_update_type get_scaling_info_update_type(
1737 const struct dc_surface_update *u)
1739 union surface_update_flags *update_flags = &u->surface->update_flags;
1741 if (!u->scaling_info)
1742 return UPDATE_TYPE_FAST;
1744 if (u->scaling_info->clip_rect.width != u->surface->clip_rect.width
1745 || u->scaling_info->clip_rect.height != u->surface->clip_rect.height
1746 || u->scaling_info->dst_rect.width != u->surface->dst_rect.width
1747 || u->scaling_info->dst_rect.height != u->surface->dst_rect.height
1748 || u->scaling_info->scaling_quality.integer_scaling !=
1749 u->surface->scaling_quality.integer_scaling
1751 update_flags->bits.scaling_change = 1;
1753 if ((u->scaling_info->dst_rect.width < u->surface->dst_rect.width
1754 || u->scaling_info->dst_rect.height < u->surface->dst_rect.height)
1755 && (u->scaling_info->dst_rect.width < u->surface->src_rect.width
1756 || u->scaling_info->dst_rect.height < u->surface->src_rect.height))
1757 /* Making dst rect smaller requires a bandwidth change */
1758 update_flags->bits.bandwidth_change = 1;
1761 if (u->scaling_info->src_rect.width != u->surface->src_rect.width
1762 || u->scaling_info->src_rect.height != u->surface->src_rect.height) {
1764 update_flags->bits.scaling_change = 1;
1765 if (u->scaling_info->src_rect.width > u->surface->src_rect.width
1766 || u->scaling_info->src_rect.height > u->surface->src_rect.height)
1767 /* Making src rect bigger requires a bandwidth change */
1768 update_flags->bits.clock_change = 1;
1771 if (u->scaling_info->src_rect.x != u->surface->src_rect.x
1772 || u->scaling_info->src_rect.y != u->surface->src_rect.y
1773 || u->scaling_info->clip_rect.x != u->surface->clip_rect.x
1774 || u->scaling_info->clip_rect.y != u->surface->clip_rect.y
1775 || u->scaling_info->dst_rect.x != u->surface->dst_rect.x
1776 || u->scaling_info->dst_rect.y != u->surface->dst_rect.y)
1777 update_flags->bits.position_change = 1;
1779 if (update_flags->bits.clock_change
1780 || update_flags->bits.bandwidth_change
1781 || update_flags->bits.scaling_change)
1782 return UPDATE_TYPE_FULL;
1784 if (update_flags->bits.position_change)
1785 return UPDATE_TYPE_MED;
1787 return UPDATE_TYPE_FAST;
1790 static enum surface_update_type det_surface_update(const struct dc *dc,
1791 const struct dc_surface_update *u)
1793 const struct dc_state *context = dc->current_state;
1794 enum surface_update_type type;
1795 enum surface_update_type overall_type = UPDATE_TYPE_FAST;
1796 union surface_update_flags *update_flags = &u->surface->update_flags;
1799 update_flags->bits.addr_update = 1;
1801 if (!is_surface_in_context(context, u->surface) || u->surface->force_full_update) {
1802 update_flags->raw = 0xFFFFFFFF;
1803 return UPDATE_TYPE_FULL;
1806 update_flags->raw = 0; // Reset all flags
1808 type = get_plane_info_update_type(u);
1809 elevate_update_type(&overall_type, type);
1811 type = get_scaling_info_update_type(u);
1812 elevate_update_type(&overall_type, type);
1815 update_flags->bits.addr_update = 1;
1817 if (u->in_transfer_func)
1818 update_flags->bits.in_transfer_func_change = 1;
1820 if (u->input_csc_color_matrix)
1821 update_flags->bits.input_csc_change = 1;
1823 if (u->coeff_reduction_factor)
1824 update_flags->bits.coeff_reduction_change = 1;
1826 if (u->gamut_remap_matrix)
1827 update_flags->bits.gamut_remap_change = 1;
1830 enum surface_pixel_format format = SURFACE_PIXEL_FORMAT_GRPH_BEGIN;
1833 format = u->plane_info->format;
1834 else if (u->surface)
1835 format = u->surface->format;
1837 if (dce_use_lut(format))
1838 update_flags->bits.gamma_change = 1;
1841 if (u->hdr_mult.value)
1842 if (u->hdr_mult.value != u->surface->hdr_mult.value) {
1843 update_flags->bits.hdr_mult = 1;
1844 elevate_update_type(&overall_type, UPDATE_TYPE_MED);
1847 if (update_flags->bits.in_transfer_func_change) {
1848 type = UPDATE_TYPE_MED;
1849 elevate_update_type(&overall_type, type);
1852 if (update_flags->bits.input_csc_change
1853 || update_flags->bits.coeff_reduction_change
1854 || update_flags->bits.gamma_change
1855 || update_flags->bits.gamut_remap_change) {
1856 type = UPDATE_TYPE_FULL;
1857 elevate_update_type(&overall_type, type);
1860 return overall_type;
1863 static enum surface_update_type check_update_surfaces_for_stream(
1865 struct dc_surface_update *updates,
1867 struct dc_stream_update *stream_update,
1868 const struct dc_stream_status *stream_status)
1871 enum surface_update_type overall_type = UPDATE_TYPE_FAST;
1873 #if defined(CONFIG_DRM_AMD_DC_DCN3_0)
1874 if (dc->idle_optimizations_allowed)
1875 overall_type = UPDATE_TYPE_FULL;
1878 if (stream_status == NULL || stream_status->plane_count != surface_count)
1879 overall_type = UPDATE_TYPE_FULL;
1881 /* some stream updates require passive update */
1882 if (stream_update) {
1883 union stream_update_flags *su_flags = &stream_update->stream->update_flags;
1885 if ((stream_update->src.height != 0 && stream_update->src.width != 0) ||
1886 (stream_update->dst.height != 0 && stream_update->dst.width != 0) ||
1887 stream_update->integer_scaling_update)
1888 su_flags->bits.scaling = 1;
1890 if (stream_update->out_transfer_func)
1891 su_flags->bits.out_tf = 1;
1893 if (stream_update->abm_level)
1894 su_flags->bits.abm_level = 1;
1896 if (stream_update->dpms_off)
1897 su_flags->bits.dpms_off = 1;
1899 if (stream_update->gamut_remap)
1900 su_flags->bits.gamut_remap = 1;
1902 if (stream_update->wb_update)
1903 su_flags->bits.wb_update = 1;
1905 if (stream_update->dsc_config)
1906 su_flags->bits.dsc_changed = 1;
1908 if (su_flags->raw != 0)
1909 overall_type = UPDATE_TYPE_FULL;
1911 if (stream_update->output_csc_transform || stream_update->output_color_space)
1912 su_flags->bits.out_csc = 1;
1915 for (i = 0 ; i < surface_count; i++) {
1916 enum surface_update_type type =
1917 det_surface_update(dc, &updates[i]);
1919 elevate_update_type(&overall_type, type);
1922 return overall_type;
1926 * dc_check_update_surfaces_for_stream() - Determine update type (fast, med, or full)
1928 * See :c:type:`enum surface_update_type <surface_update_type>` for explanation of update types
1930 enum surface_update_type dc_check_update_surfaces_for_stream(
1932 struct dc_surface_update *updates,
1934 struct dc_stream_update *stream_update,
1935 const struct dc_stream_status *stream_status)
1938 enum surface_update_type type;
1941 stream_update->stream->update_flags.raw = 0;
1942 for (i = 0; i < surface_count; i++)
1943 updates[i].surface->update_flags.raw = 0;
1945 type = check_update_surfaces_for_stream(dc, updates, surface_count, stream_update, stream_status);
1946 if (type == UPDATE_TYPE_FULL) {
1947 if (stream_update) {
1948 uint32_t dsc_changed = stream_update->stream->update_flags.bits.dsc_changed;
1949 stream_update->stream->update_flags.raw = 0xFFFFFFFF;
1950 stream_update->stream->update_flags.bits.dsc_changed = dsc_changed;
1952 for (i = 0; i < surface_count; i++)
1953 updates[i].surface->update_flags.raw = 0xFFFFFFFF;
1956 if (type == UPDATE_TYPE_FAST) {
1957 // If there's an available clock comparator, we use that.
1958 if (dc->clk_mgr->funcs->are_clock_states_equal) {
1959 if (!dc->clk_mgr->funcs->are_clock_states_equal(&dc->clk_mgr->clks, &dc->current_state->bw_ctx.bw.dcn.clk))
1960 dc->optimized_required = true;
1961 // Else we fallback to mem compare.
1962 } 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) {
1963 dc->optimized_required = true;
1966 dc->optimized_required |= dc->wm_optimized_required;
1972 static struct dc_stream_status *stream_get_status(
1973 struct dc_state *ctx,
1974 struct dc_stream_state *stream)
1978 for (i = 0; i < ctx->stream_count; i++) {
1979 if (stream == ctx->streams[i]) {
1980 return &ctx->stream_status[i];
1987 static const enum surface_update_type update_surface_trace_level = UPDATE_TYPE_FULL;
1989 static void copy_surface_update_to_plane(
1990 struct dc_plane_state *surface,
1991 struct dc_surface_update *srf_update)
1993 if (srf_update->flip_addr) {
1994 surface->address = srf_update->flip_addr->address;
1995 surface->flip_immediate =
1996 srf_update->flip_addr->flip_immediate;
1997 surface->time.time_elapsed_in_us[surface->time.index] =
1998 srf_update->flip_addr->flip_timestamp_in_us -
1999 surface->time.prev_update_time_in_us;
2000 surface->time.prev_update_time_in_us =
2001 srf_update->flip_addr->flip_timestamp_in_us;
2002 surface->time.index++;
2003 if (surface->time.index >= DC_PLANE_UPDATE_TIMES_MAX)
2004 surface->time.index = 0;
2006 surface->triplebuffer_flips = srf_update->flip_addr->triplebuffer_flips;
2009 if (srf_update->scaling_info) {
2010 surface->scaling_quality =
2011 srf_update->scaling_info->scaling_quality;
2013 srf_update->scaling_info->dst_rect;
2015 srf_update->scaling_info->src_rect;
2016 surface->clip_rect =
2017 srf_update->scaling_info->clip_rect;
2020 if (srf_update->plane_info) {
2021 surface->color_space =
2022 srf_update->plane_info->color_space;
2024 srf_update->plane_info->format;
2025 surface->plane_size =
2026 srf_update->plane_info->plane_size;
2028 srf_update->plane_info->rotation;
2029 surface->horizontal_mirror =
2030 srf_update->plane_info->horizontal_mirror;
2031 surface->stereo_format =
2032 srf_update->plane_info->stereo_format;
2033 surface->tiling_info =
2034 srf_update->plane_info->tiling_info;
2036 srf_update->plane_info->visible;
2037 surface->per_pixel_alpha =
2038 srf_update->plane_info->per_pixel_alpha;
2039 surface->global_alpha =
2040 srf_update->plane_info->global_alpha;
2041 surface->global_alpha_value =
2042 srf_update->plane_info->global_alpha_value;
2044 srf_update->plane_info->dcc;
2045 surface->layer_index =
2046 srf_update->plane_info->layer_index;
2049 if (srf_update->gamma &&
2050 (surface->gamma_correction !=
2051 srf_update->gamma)) {
2052 memcpy(&surface->gamma_correction->entries,
2053 &srf_update->gamma->entries,
2054 sizeof(struct dc_gamma_entries));
2055 surface->gamma_correction->is_identity =
2056 srf_update->gamma->is_identity;
2057 surface->gamma_correction->num_entries =
2058 srf_update->gamma->num_entries;
2059 surface->gamma_correction->type =
2060 srf_update->gamma->type;
2063 if (srf_update->in_transfer_func &&
2064 (surface->in_transfer_func !=
2065 srf_update->in_transfer_func)) {
2066 surface->in_transfer_func->sdr_ref_white_level =
2067 srf_update->in_transfer_func->sdr_ref_white_level;
2068 surface->in_transfer_func->tf =
2069 srf_update->in_transfer_func->tf;
2070 surface->in_transfer_func->type =
2071 srf_update->in_transfer_func->type;
2072 memcpy(&surface->in_transfer_func->tf_pts,
2073 &srf_update->in_transfer_func->tf_pts,
2074 sizeof(struct dc_transfer_func_distributed_points));
2077 if (srf_update->func_shaper &&
2078 (surface->in_shaper_func !=
2079 srf_update->func_shaper))
2080 memcpy(surface->in_shaper_func, srf_update->func_shaper,
2081 sizeof(*surface->in_shaper_func));
2083 if (srf_update->lut3d_func &&
2084 (surface->lut3d_func !=
2085 srf_update->lut3d_func))
2086 memcpy(surface->lut3d_func, srf_update->lut3d_func,
2087 sizeof(*surface->lut3d_func));
2089 if (srf_update->hdr_mult.value)
2091 srf_update->hdr_mult;
2093 if (srf_update->blend_tf &&
2094 (surface->blend_tf !=
2095 srf_update->blend_tf))
2096 memcpy(surface->blend_tf, srf_update->blend_tf,
2097 sizeof(*surface->blend_tf));
2099 if (srf_update->input_csc_color_matrix)
2100 surface->input_csc_color_matrix =
2101 *srf_update->input_csc_color_matrix;
2103 if (srf_update->coeff_reduction_factor)
2104 surface->coeff_reduction_factor =
2105 *srf_update->coeff_reduction_factor;
2107 if (srf_update->gamut_remap_matrix)
2108 surface->gamut_remap_matrix =
2109 *srf_update->gamut_remap_matrix;
2112 static void copy_stream_update_to_stream(struct dc *dc,
2113 struct dc_state *context,
2114 struct dc_stream_state *stream,
2115 struct dc_stream_update *update)
2117 struct dc_context *dc_ctx = dc->ctx;
2119 if (update == NULL || stream == NULL)
2122 if (update->src.height && update->src.width)
2123 stream->src = update->src;
2125 if (update->dst.height && update->dst.width)
2126 stream->dst = update->dst;
2128 if (update->out_transfer_func &&
2129 stream->out_transfer_func != update->out_transfer_func) {
2130 stream->out_transfer_func->sdr_ref_white_level =
2131 update->out_transfer_func->sdr_ref_white_level;
2132 stream->out_transfer_func->tf = update->out_transfer_func->tf;
2133 stream->out_transfer_func->type =
2134 update->out_transfer_func->type;
2135 memcpy(&stream->out_transfer_func->tf_pts,
2136 &update->out_transfer_func->tf_pts,
2137 sizeof(struct dc_transfer_func_distributed_points));
2140 if (update->hdr_static_metadata)
2141 stream->hdr_static_metadata = *update->hdr_static_metadata;
2143 if (update->abm_level)
2144 stream->abm_level = *update->abm_level;
2146 if (update->periodic_interrupt0)
2147 stream->periodic_interrupt0 = *update->periodic_interrupt0;
2149 if (update->periodic_interrupt1)
2150 stream->periodic_interrupt1 = *update->periodic_interrupt1;
2152 if (update->gamut_remap)
2153 stream->gamut_remap_matrix = *update->gamut_remap;
2155 /* Note: this being updated after mode set is currently not a use case
2156 * however if it arises OCSC would need to be reprogrammed at the
2159 if (update->output_color_space)
2160 stream->output_color_space = *update->output_color_space;
2162 if (update->output_csc_transform)
2163 stream->csc_color_matrix = *update->output_csc_transform;
2165 if (update->vrr_infopacket)
2166 stream->vrr_infopacket = *update->vrr_infopacket;
2168 if (update->dpms_off)
2169 stream->dpms_off = *update->dpms_off;
2171 if (update->vsc_infopacket)
2172 stream->vsc_infopacket = *update->vsc_infopacket;
2174 if (update->vsp_infopacket)
2175 stream->vsp_infopacket = *update->vsp_infopacket;
2177 if (update->dither_option)
2178 stream->dither_option = *update->dither_option;
2179 /* update current stream with writeback info */
2180 if (update->wb_update) {
2183 stream->num_wb_info = update->wb_update->num_wb_info;
2184 ASSERT(stream->num_wb_info <= MAX_DWB_PIPES);
2185 for (i = 0; i < stream->num_wb_info; i++)
2186 stream->writeback_info[i] =
2187 update->wb_update->writeback_info[i];
2189 if (update->dsc_config) {
2190 struct dc_dsc_config old_dsc_cfg = stream->timing.dsc_cfg;
2191 uint32_t old_dsc_enabled = stream->timing.flags.DSC;
2192 uint32_t enable_dsc = (update->dsc_config->num_slices_h != 0 &&
2193 update->dsc_config->num_slices_v != 0);
2195 /* Use temporarry context for validating new DSC config */
2196 struct dc_state *dsc_validate_context = dc_create_state(dc);
2198 if (dsc_validate_context) {
2199 dc_resource_state_copy_construct(dc->current_state, dsc_validate_context);
2201 stream->timing.dsc_cfg = *update->dsc_config;
2202 stream->timing.flags.DSC = enable_dsc;
2203 if (!dc->res_pool->funcs->validate_bandwidth(dc, dsc_validate_context, true)) {
2204 stream->timing.dsc_cfg = old_dsc_cfg;
2205 stream->timing.flags.DSC = old_dsc_enabled;
2206 update->dsc_config = NULL;
2209 dc_release_state(dsc_validate_context);
2211 DC_ERROR("Failed to allocate new validate context for DSC change\n");
2212 update->dsc_config = NULL;
2217 static void commit_planes_do_stream_update(struct dc *dc,
2218 struct dc_stream_state *stream,
2219 struct dc_stream_update *stream_update,
2220 enum surface_update_type update_type,
2221 struct dc_state *context)
2224 bool should_program_abm;
2227 for (j = 0; j < dc->res_pool->pipe_count; j++) {
2228 struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[j];
2230 if (!pipe_ctx->top_pipe && !pipe_ctx->prev_odm_pipe && pipe_ctx->stream == stream) {
2232 if (stream_update->periodic_interrupt0 &&
2233 dc->hwss.setup_periodic_interrupt)
2234 dc->hwss.setup_periodic_interrupt(dc, pipe_ctx, VLINE0);
2236 if (stream_update->periodic_interrupt1 &&
2237 dc->hwss.setup_periodic_interrupt)
2238 dc->hwss.setup_periodic_interrupt(dc, pipe_ctx, VLINE1);
2240 if ((stream_update->hdr_static_metadata && !stream->use_dynamic_meta) ||
2241 stream_update->vrr_infopacket ||
2242 stream_update->vsc_infopacket ||
2243 stream_update->vsp_infopacket) {
2244 resource_build_info_frame(pipe_ctx);
2245 dc->hwss.update_info_frame(pipe_ctx);
2248 if (stream_update->hdr_static_metadata &&
2249 stream->use_dynamic_meta &&
2250 dc->hwss.set_dmdata_attributes &&
2251 pipe_ctx->stream->dmdata_address.quad_part != 0)
2252 dc->hwss.set_dmdata_attributes(pipe_ctx);
2254 if (stream_update->gamut_remap)
2255 dc_stream_set_gamut_remap(dc, stream);
2257 if (stream_update->output_csc_transform)
2258 dc_stream_program_csc_matrix(dc, stream);
2260 if (stream_update->dither_option) {
2261 struct pipe_ctx *odm_pipe = pipe_ctx->next_odm_pipe;
2262 resource_build_bit_depth_reduction_params(pipe_ctx->stream,
2263 &pipe_ctx->stream->bit_depth_params);
2264 pipe_ctx->stream_res.opp->funcs->opp_program_fmt(pipe_ctx->stream_res.opp,
2265 &stream->bit_depth_params,
2268 odm_pipe->stream_res.opp->funcs->opp_program_fmt(odm_pipe->stream_res.opp,
2269 &stream->bit_depth_params,
2271 odm_pipe = odm_pipe->next_odm_pipe;
2276 if (update_type == UPDATE_TYPE_FAST)
2279 if (stream_update->dsc_config)
2280 dp_update_dsc_config(pipe_ctx);
2282 if (stream_update->dpms_off) {
2283 if (*stream_update->dpms_off) {
2284 core_link_disable_stream(pipe_ctx);
2285 /* for dpms, keep acquired resources*/
2286 if (pipe_ctx->stream_res.audio && !dc->debug.az_endpoint_mute_only)
2287 pipe_ctx->stream_res.audio->funcs->az_disable(pipe_ctx->stream_res.audio);
2289 dc->hwss.optimize_bandwidth(dc, dc->current_state);
2291 if (dc->optimize_seamless_boot_streams == 0)
2292 dc->hwss.prepare_bandwidth(dc, dc->current_state);
2294 core_link_enable_stream(dc->current_state, pipe_ctx);
2298 if (stream_update->abm_level && pipe_ctx->stream_res.abm) {
2299 should_program_abm = true;
2301 // if otg funcs defined check if blanked before programming
2302 if (pipe_ctx->stream_res.tg->funcs->is_blanked)
2303 if (pipe_ctx->stream_res.tg->funcs->is_blanked(pipe_ctx->stream_res.tg))
2304 should_program_abm = false;
2306 if (should_program_abm) {
2307 if (*stream_update->abm_level == ABM_LEVEL_IMMEDIATE_DISABLE) {
2308 dc->hwss.set_abm_immediate_disable(pipe_ctx);
2310 pipe_ctx->stream_res.abm->funcs->set_abm_level(
2311 pipe_ctx->stream_res.abm, stream->abm_level);
2319 static void commit_planes_for_stream(struct dc *dc,
2320 struct dc_surface_update *srf_updates,
2322 struct dc_stream_state *stream,
2323 struct dc_stream_update *stream_update,
2324 enum surface_update_type update_type,
2325 struct dc_state *context)
2327 bool mpcc_disconnected = false;
2329 struct pipe_ctx *top_pipe_to_program = NULL;
2331 if (dc->optimize_seamless_boot_streams > 0 && surface_count > 0) {
2332 /* Optimize seamless boot flag keeps clocks and watermarks high until
2333 * first flip. After first flip, optimization is required to lower
2334 * bandwidth. Important to note that it is expected UEFI will
2335 * only light up a single display on POST, therefore we only expect
2336 * one stream with seamless boot flag set.
2338 if (stream->apply_seamless_boot_optimization) {
2339 stream->apply_seamless_boot_optimization = false;
2340 dc->optimize_seamless_boot_streams--;
2342 if (dc->optimize_seamless_boot_streams == 0)
2343 dc->optimized_required = true;
2347 if (update_type == UPDATE_TYPE_FULL) {
2348 #if defined(CONFIG_DRM_AMD_DC_DCN3_0)
2349 dc_allow_idle_optimizations(dc, false);
2352 if (dc->optimize_seamless_boot_streams == 0)
2353 dc->hwss.prepare_bandwidth(dc, context);
2355 context_clock_trace(dc, context);
2358 if (update_type != UPDATE_TYPE_FAST && dc->hwss.interdependent_update_lock &&
2359 dc->hwss.disconnect_pipes && dc->hwss.wait_for_pending_cleared){
2360 dc->hwss.interdependent_update_lock(dc, context, true);
2361 mpcc_disconnected = dc->hwss.disconnect_pipes(dc, context);
2362 dc->hwss.interdependent_update_lock(dc, context, false);
2363 if (mpcc_disconnected)
2364 dc->hwss.wait_for_pending_cleared(dc, context);
2367 for (j = 0; j < dc->res_pool->pipe_count; j++) {
2368 struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[j];
2370 if (!pipe_ctx->top_pipe &&
2371 !pipe_ctx->prev_odm_pipe &&
2373 pipe_ctx->stream == stream) {
2374 top_pipe_to_program = pipe_ctx;
2378 if ((update_type != UPDATE_TYPE_FAST) && stream->update_flags.bits.dsc_changed)
2379 if (top_pipe_to_program->stream_res.tg->funcs->lock_doublebuffer_enable) {
2380 if (should_use_dmub_lock(stream->link)) {
2381 union dmub_hw_lock_flags hw_locks = { 0 };
2382 struct dmub_hw_lock_inst_flags inst_flags = { 0 };
2384 hw_locks.bits.lock_dig = 1;
2385 inst_flags.dig_inst = top_pipe_to_program->stream_res.tg->inst;
2387 dmub_hw_lock_mgr_cmd(dc->ctx->dmub_srv,
2392 top_pipe_to_program->stream_res.tg->funcs->lock_doublebuffer_enable(
2393 top_pipe_to_program->stream_res.tg);
2396 if ((update_type != UPDATE_TYPE_FAST) && dc->hwss.interdependent_update_lock)
2397 dc->hwss.interdependent_update_lock(dc, context, true);
2399 /* Lock the top pipe while updating plane addrs, since freesync requires
2400 * plane addr update event triggers to be synchronized.
2401 * top_pipe_to_program is expected to never be NULL
2403 dc->hwss.pipe_control_lock(dc, top_pipe_to_program, true);
2408 commit_planes_do_stream_update(dc, stream, stream_update, update_type, context);
2410 if (surface_count == 0) {
2412 * In case of turning off screen, no need to program front end a second time.
2413 * just return after program blank.
2415 if (dc->hwss.apply_ctx_for_surface)
2416 dc->hwss.apply_ctx_for_surface(dc, stream, 0, context);
2417 if (dc->hwss.program_front_end_for_ctx)
2418 dc->hwss.program_front_end_for_ctx(dc, context);
2420 if ((update_type != UPDATE_TYPE_FAST) && dc->hwss.interdependent_update_lock)
2421 dc->hwss.interdependent_update_lock(dc, context, false);
2423 dc->hwss.pipe_control_lock(dc, top_pipe_to_program, false);
2425 dc->hwss.post_unlock_program_front_end(dc, context);
2429 if (!IS_DIAG_DC(dc->ctx->dce_environment)) {
2430 for (i = 0; i < surface_count; i++) {
2431 struct dc_plane_state *plane_state = srf_updates[i].surface;
2432 /*set logical flag for lock/unlock use*/
2433 for (j = 0; j < dc->res_pool->pipe_count; j++) {
2434 struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[j];
2435 if (!pipe_ctx->plane_state)
2437 if (pipe_ctx->plane_state != plane_state)
2439 plane_state->triplebuffer_flips = false;
2440 if (update_type == UPDATE_TYPE_FAST &&
2441 dc->hwss.program_triplebuffer != NULL &&
2442 !plane_state->flip_immediate && dc->debug.enable_tri_buf) {
2443 /*triple buffer for VUpdate only*/
2444 plane_state->triplebuffer_flips = true;
2450 // Update Type FULL, Surface updates
2451 for (j = 0; j < dc->res_pool->pipe_count; j++) {
2452 struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[j];
2454 if (!pipe_ctx->top_pipe &&
2455 !pipe_ctx->prev_odm_pipe &&
2457 pipe_ctx->stream == stream) {
2458 struct dc_stream_status *stream_status = NULL;
2460 if (!pipe_ctx->plane_state)
2464 if (update_type == UPDATE_TYPE_FAST)
2467 ASSERT(!pipe_ctx->plane_state->triplebuffer_flips);
2469 if (dc->hwss.program_triplebuffer != NULL && dc->debug.enable_tri_buf) {
2470 /*turn off triple buffer for full update*/
2471 dc->hwss.program_triplebuffer(
2472 dc, pipe_ctx, pipe_ctx->plane_state->triplebuffer_flips);
2475 stream_get_status(context, pipe_ctx->stream);
2477 if (dc->hwss.apply_ctx_for_surface)
2478 dc->hwss.apply_ctx_for_surface(
2479 dc, pipe_ctx->stream, stream_status->plane_count, context);
2482 if (dc->hwss.program_front_end_for_ctx && update_type != UPDATE_TYPE_FAST) {
2483 dc->hwss.program_front_end_for_ctx(dc, context);
2484 #ifdef CONFIG_DRM_AMD_DC_DCN
2485 if (dc->debug.validate_dml_output) {
2486 for (i = 0; i < dc->res_pool->pipe_count; i++) {
2487 struct pipe_ctx cur_pipe = context->res_ctx.pipe_ctx[i];
2488 if (cur_pipe.stream == NULL)
2491 cur_pipe.plane_res.hubp->funcs->validate_dml_output(
2492 cur_pipe.plane_res.hubp, dc->ctx,
2493 &context->res_ctx.pipe_ctx[i].rq_regs,
2494 &context->res_ctx.pipe_ctx[i].dlg_regs,
2495 &context->res_ctx.pipe_ctx[i].ttu_regs);
2501 // Update Type FAST, Surface updates
2502 if (update_type == UPDATE_TYPE_FAST) {
2503 if (dc->hwss.set_flip_control_gsl)
2504 for (i = 0; i < surface_count; i++) {
2505 struct dc_plane_state *plane_state = srf_updates[i].surface;
2507 for (j = 0; j < dc->res_pool->pipe_count; j++) {
2508 struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[j];
2510 if (pipe_ctx->stream != stream)
2513 if (pipe_ctx->plane_state != plane_state)
2516 // GSL has to be used for flip immediate
2517 dc->hwss.set_flip_control_gsl(pipe_ctx,
2518 plane_state->flip_immediate);
2521 /* Perform requested Updates */
2522 for (i = 0; i < surface_count; i++) {
2523 struct dc_plane_state *plane_state = srf_updates[i].surface;
2525 for (j = 0; j < dc->res_pool->pipe_count; j++) {
2526 struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[j];
2528 if (pipe_ctx->stream != stream)
2531 if (pipe_ctx->plane_state != plane_state)
2533 /*program triple buffer after lock based on flip type*/
2534 if (dc->hwss.program_triplebuffer != NULL && dc->debug.enable_tri_buf) {
2535 /*only enable triplebuffer for fast_update*/
2536 dc->hwss.program_triplebuffer(
2537 dc, pipe_ctx, plane_state->triplebuffer_flips);
2539 if (srf_updates[i].flip_addr)
2540 dc->hwss.update_plane_addr(dc, pipe_ctx);
2545 if ((update_type != UPDATE_TYPE_FAST) && dc->hwss.interdependent_update_lock)
2546 dc->hwss.interdependent_update_lock(dc, context, false);
2548 dc->hwss.pipe_control_lock(dc, top_pipe_to_program, false);
2550 if ((update_type != UPDATE_TYPE_FAST) && stream->update_flags.bits.dsc_changed)
2551 if (top_pipe_to_program->stream_res.tg->funcs->lock_doublebuffer_enable) {
2552 top_pipe_to_program->stream_res.tg->funcs->wait_for_state(
2553 top_pipe_to_program->stream_res.tg,
2554 CRTC_STATE_VACTIVE);
2555 top_pipe_to_program->stream_res.tg->funcs->wait_for_state(
2556 top_pipe_to_program->stream_res.tg,
2558 top_pipe_to_program->stream_res.tg->funcs->wait_for_state(
2559 top_pipe_to_program->stream_res.tg,
2560 CRTC_STATE_VACTIVE);
2562 if (stream && should_use_dmub_lock(stream->link)) {
2563 union dmub_hw_lock_flags hw_locks = { 0 };
2564 struct dmub_hw_lock_inst_flags inst_flags = { 0 };
2566 hw_locks.bits.lock_dig = 1;
2567 inst_flags.dig_inst = top_pipe_to_program->stream_res.tg->inst;
2569 dmub_hw_lock_mgr_cmd(dc->ctx->dmub_srv,
2574 top_pipe_to_program->stream_res.tg->funcs->lock_doublebuffer_disable(
2575 top_pipe_to_program->stream_res.tg);
2578 if (update_type != UPDATE_TYPE_FAST)
2579 dc->hwss.post_unlock_program_front_end(dc, context);
2581 // Fire manual trigger only when bottom plane is flipped
2582 for (j = 0; j < dc->res_pool->pipe_count; j++) {
2583 struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[j];
2585 if (pipe_ctx->bottom_pipe ||
2586 !pipe_ctx->stream ||
2587 pipe_ctx->stream != stream ||
2588 !pipe_ctx->plane_state->update_flags.bits.addr_update)
2591 if (pipe_ctx->stream_res.tg->funcs->program_manual_trigger)
2592 pipe_ctx->stream_res.tg->funcs->program_manual_trigger(pipe_ctx->stream_res.tg);
2596 void dc_commit_updates_for_stream(struct dc *dc,
2597 struct dc_surface_update *srf_updates,
2599 struct dc_stream_state *stream,
2600 struct dc_stream_update *stream_update,
2601 struct dc_state *state)
2603 const struct dc_stream_status *stream_status;
2604 enum surface_update_type update_type;
2605 struct dc_state *context;
2606 struct dc_context *dc_ctx = dc->ctx;
2609 stream_status = dc_stream_get_status(stream);
2610 context = dc->current_state;
2612 update_type = dc_check_update_surfaces_for_stream(
2613 dc, srf_updates, surface_count, stream_update, stream_status);
2615 if (update_type >= update_surface_trace_level)
2616 update_surface_trace(dc, srf_updates, surface_count);
2619 if (update_type >= UPDATE_TYPE_FULL) {
2621 /* initialize scratch memory for building context */
2622 context = dc_create_state(dc);
2623 if (context == NULL) {
2624 DC_ERROR("Failed to allocate new validate context!\n");
2628 dc_resource_state_copy_construct(state, context);
2630 for (i = 0; i < dc->res_pool->pipe_count; i++) {
2631 struct pipe_ctx *new_pipe = &context->res_ctx.pipe_ctx[i];
2632 struct pipe_ctx *old_pipe = &dc->current_state->res_ctx.pipe_ctx[i];
2634 if (new_pipe->plane_state && new_pipe->plane_state != old_pipe->plane_state)
2635 new_pipe->plane_state->force_full_update = true;
2640 for (i = 0; i < surface_count; i++) {
2641 struct dc_plane_state *surface = srf_updates[i].surface;
2643 copy_surface_update_to_plane(surface, &srf_updates[i]);
2645 if (update_type >= UPDATE_TYPE_MED) {
2646 for (j = 0; j < dc->res_pool->pipe_count; j++) {
2647 struct pipe_ctx *pipe_ctx =
2648 &context->res_ctx.pipe_ctx[j];
2650 if (pipe_ctx->plane_state != surface)
2653 resource_build_scaling_params(pipe_ctx);
2658 copy_stream_update_to_stream(dc, context, stream, stream_update);
2660 if (update_type >= UPDATE_TYPE_FULL) {
2661 if (!dc->res_pool->funcs->validate_bandwidth(dc, context, false)) {
2662 DC_ERROR("Mode validation failed for stream update!\n");
2663 dc_release_state(context);
2668 commit_planes_for_stream(
2676 /*update current_State*/
2677 if (dc->current_state != context) {
2679 struct dc_state *old = dc->current_state;
2681 dc->current_state = context;
2682 dc_release_state(old);
2684 for (i = 0; i < dc->res_pool->pipe_count; i++) {
2685 struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[i];
2687 if (pipe_ctx->plane_state && pipe_ctx->stream == stream)
2688 pipe_ctx->plane_state->force_full_update = false;
2691 /*let's use current_state to update watermark etc*/
2692 if (update_type >= UPDATE_TYPE_FULL)
2693 dc_post_update_surfaces_to_stream(dc);
2699 uint8_t dc_get_current_stream_count(struct dc *dc)
2701 return dc->current_state->stream_count;
2704 struct dc_stream_state *dc_get_stream_at_index(struct dc *dc, uint8_t i)
2706 if (i < dc->current_state->stream_count)
2707 return dc->current_state->streams[i];
2711 enum dc_irq_source dc_interrupt_to_irq_source(
2716 return dal_irq_service_to_irq_source(dc->res_pool->irqs, src_id, ext_id);
2720 * dc_interrupt_set() - Enable/disable an AMD hw interrupt source
2722 bool dc_interrupt_set(struct dc *dc, enum dc_irq_source src, bool enable)
2728 return dal_irq_service_set(dc->res_pool->irqs, src, enable);
2731 void dc_interrupt_ack(struct dc *dc, enum dc_irq_source src)
2733 dal_irq_service_ack(dc->res_pool->irqs, src);
2736 void dc_power_down_on_boot(struct dc *dc)
2738 if (dc->ctx->dce_environment != DCE_ENV_VIRTUAL_HW &&
2739 dc->hwss.power_down_on_boot)
2740 dc->hwss.power_down_on_boot(dc);
2743 void dc_set_power_state(
2745 enum dc_acpi_cm_power_state power_state)
2747 struct kref refcount;
2748 struct display_mode_lib *dml;
2750 switch (power_state) {
2751 case DC_ACPI_CM_POWER_STATE_D0:
2752 dc_resource_state_construct(dc, dc->current_state);
2754 if (dc->ctx->dmub_srv)
2755 dc_dmub_srv_wait_phy_init(dc->ctx->dmub_srv);
2757 dc->hwss.init_hw(dc);
2759 if (dc->hwss.init_sys_ctx != NULL &&
2760 dc->vm_pa_config.valid) {
2761 dc->hwss.init_sys_ctx(dc->hwseq, dc, &dc->vm_pa_config);
2766 ASSERT(dc->current_state->stream_count == 0);
2767 /* Zero out the current context so that on resume we start with
2768 * clean state, and dc hw programming optimizations will not
2769 * cause any trouble.
2771 dml = kzalloc(sizeof(struct display_mode_lib),
2778 /* Preserve refcount */
2779 refcount = dc->current_state->refcount;
2780 /* Preserve display mode lib */
2781 memcpy(dml, &dc->current_state->bw_ctx.dml, sizeof(struct display_mode_lib));
2783 dc_resource_state_destruct(dc->current_state);
2784 memset(dc->current_state, 0,
2785 sizeof(*dc->current_state));
2787 dc->current_state->refcount = refcount;
2788 dc->current_state->bw_ctx.dml = *dml;
2796 void dc_resume(struct dc *dc)
2800 for (i = 0; i < dc->link_count; i++)
2801 core_link_resume(dc->links[i]);
2804 bool dc_is_dmcu_initialized(struct dc *dc)
2806 struct dmcu *dmcu = dc->res_pool->dmcu;
2809 return dmcu->funcs->is_dmcu_initialized(dmcu);
2815 uint32_t link_index,
2816 struct i2c_command *cmd)
2819 struct dc_link *link = dc->links[link_index];
2820 struct ddc_service *ddc = link->ddc;
2821 return dce_i2c_submit_command(
2827 bool dc_submit_i2c_oem(
2829 struct i2c_command *cmd)
2831 struct ddc_service *ddc = dc->res_pool->oem_device;
2832 return dce_i2c_submit_command(
2838 static bool link_add_remote_sink_helper(struct dc_link *dc_link, struct dc_sink *sink)
2840 if (dc_link->sink_count >= MAX_SINKS_PER_LINK) {
2841 BREAK_TO_DEBUGGER();
2845 dc_sink_retain(sink);
2847 dc_link->remote_sinks[dc_link->sink_count] = sink;
2848 dc_link->sink_count++;
2854 * dc_link_add_remote_sink() - Create a sink and attach it to an existing link
2856 * EDID length is in bytes
2858 struct dc_sink *dc_link_add_remote_sink(
2859 struct dc_link *link,
2860 const uint8_t *edid,
2862 struct dc_sink_init_data *init_data)
2864 struct dc_sink *dc_sink;
2865 enum dc_edid_status edid_status;
2867 if (len > DC_MAX_EDID_BUFFER_SIZE) {
2868 dm_error("Max EDID buffer size breached!\n");
2873 BREAK_TO_DEBUGGER();
2877 if (!init_data->link) {
2878 BREAK_TO_DEBUGGER();
2882 dc_sink = dc_sink_create(init_data);
2887 memmove(dc_sink->dc_edid.raw_edid, edid, len);
2888 dc_sink->dc_edid.length = len;
2890 if (!link_add_remote_sink_helper(
2895 edid_status = dm_helpers_parse_edid_caps(
2898 &dc_sink->edid_caps);
2901 * Treat device as no EDID device if EDID
2904 if (edid_status != EDID_OK) {
2905 dc_sink->dc_edid.length = 0;
2906 dm_error("Bad EDID, status%d!\n", edid_status);
2912 dc_sink_release(dc_sink);
2917 * dc_link_remove_remote_sink() - Remove a remote sink from a dc_link
2919 * Note that this just removes the struct dc_sink - it doesn't
2920 * program hardware or alter other members of dc_link
2922 void dc_link_remove_remote_sink(struct dc_link *link, struct dc_sink *sink)
2926 if (!link->sink_count) {
2927 BREAK_TO_DEBUGGER();
2931 for (i = 0; i < link->sink_count; i++) {
2932 if (link->remote_sinks[i] == sink) {
2933 dc_sink_release(sink);
2934 link->remote_sinks[i] = NULL;
2936 /* shrink array to remove empty place */
2937 while (i < link->sink_count - 1) {
2938 link->remote_sinks[i] = link->remote_sinks[i+1];
2941 link->remote_sinks[i] = NULL;
2948 void get_clock_requirements_for_state(struct dc_state *state, struct AsicStateEx *info)
2950 info->displayClock = (unsigned int)state->bw_ctx.bw.dcn.clk.dispclk_khz;
2951 info->engineClock = (unsigned int)state->bw_ctx.bw.dcn.clk.dcfclk_khz;
2952 info->memoryClock = (unsigned int)state->bw_ctx.bw.dcn.clk.dramclk_khz;
2953 info->maxSupportedDppClock = (unsigned int)state->bw_ctx.bw.dcn.clk.max_supported_dppclk_khz;
2954 info->dppClock = (unsigned int)state->bw_ctx.bw.dcn.clk.dppclk_khz;
2955 info->socClock = (unsigned int)state->bw_ctx.bw.dcn.clk.socclk_khz;
2956 info->dcfClockDeepSleep = (unsigned int)state->bw_ctx.bw.dcn.clk.dcfclk_deep_sleep_khz;
2957 info->fClock = (unsigned int)state->bw_ctx.bw.dcn.clk.fclk_khz;
2958 info->phyClock = (unsigned int)state->bw_ctx.bw.dcn.clk.phyclk_khz;
2960 enum dc_status dc_set_clock(struct dc *dc, enum dc_clock_type clock_type, uint32_t clk_khz, uint32_t stepping)
2962 if (dc->hwss.set_clock)
2963 return dc->hwss.set_clock(dc, clock_type, clk_khz, stepping);
2964 return DC_ERROR_UNEXPECTED;
2966 void dc_get_clock(struct dc *dc, enum dc_clock_type clock_type, struct dc_clock_config *clock_cfg)
2968 if (dc->hwss.get_clock)
2969 dc->hwss.get_clock(dc, clock_type, clock_cfg);
2972 /* enable/disable eDP PSR without specify stream for eDP */
2973 bool dc_set_psr_allow_active(struct dc *dc, bool enable)
2977 for (i = 0; i < dc->current_state->stream_count ; i++) {
2978 struct dc_link *link;
2979 struct dc_stream_state *stream = dc->current_state->streams[i];
2981 link = stream->link;
2985 if (link->psr_settings.psr_feature_enabled) {
2986 if (enable && !link->psr_settings.psr_allow_active)
2987 return dc_link_set_psr_allow_active(link, true, false);
2988 else if (!enable && link->psr_settings.psr_allow_active)
2989 return dc_link_set_psr_allow_active(link, false, true);
2996 #if defined(CONFIG_DRM_AMD_DC_DCN3_0)
2998 void dc_allow_idle_optimizations(struct dc *dc, bool allow)
3000 if (dc->debug.disable_idle_power_optimizations)
3003 if (allow == dc->idle_optimizations_allowed)
3006 if (dc->hwss.apply_idle_power_optimizations && dc->hwss.apply_idle_power_optimizations(dc, allow))
3007 dc->idle_optimizations_allowed = allow;
3011 * blank all streams, and set min and max memory clock to
3012 * lowest and highest DPM level, respectively
3014 void dc_unlock_memory_clock_frequency(struct dc *dc)
3018 for (i = 0; i < MAX_PIPES; i++)
3019 if (dc->current_state->res_ctx.pipe_ctx[i].plane_state)
3020 core_link_disable_stream(&dc->current_state->res_ctx.pipe_ctx[i]);
3022 dc->clk_mgr->funcs->set_hard_min_memclk(dc->clk_mgr, false);
3023 dc->clk_mgr->funcs->set_hard_max_memclk(dc->clk_mgr);
3027 * set min memory clock to the min required for current mode,
3028 * max to maxDPM, and unblank streams
3030 void dc_lock_memory_clock_frequency(struct dc *dc)
3034 dc->clk_mgr->funcs->get_memclk_states_from_smu(dc->clk_mgr);
3035 dc->clk_mgr->funcs->set_hard_min_memclk(dc->clk_mgr, true);
3036 dc->clk_mgr->funcs->set_hard_max_memclk(dc->clk_mgr);
3038 for (i = 0; i < MAX_PIPES; i++)
3039 if (dc->current_state->res_ctx.pipe_ctx[i].plane_state)
3040 core_link_enable_stream(dc->current_state, &dc->current_state->res_ctx.pipe_ctx[i]);
3043 bool dc_is_plane_eligible_for_idle_optimizaitons(struct dc *dc,
3044 struct dc_plane_state *plane)