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"
75 static const char DC_BUILD_ID[] = "production-build";
80 * DC is the OS-agnostic component of the amdgpu DC driver.
82 * DC maintains and validates a set of structs representing the state of the
83 * driver and writes that state to AMD hardware
87 * struct dc - The central struct. One per driver. Created on driver load,
88 * destroyed on driver unload.
90 * struct dc_context - One per driver.
91 * Used as a backpointer by most other structs in dc.
93 * struct dc_link - One per connector (the physical DP, HDMI, miniDP, or eDP
94 * plugpoints). Created on driver load, destroyed on driver unload.
96 * struct dc_sink - One per display. Created on boot or hotplug.
97 * Destroyed on shutdown or hotunplug. A dc_link can have a local sink
98 * (the display directly attached). It may also have one or more remote
99 * sinks (in the Multi-Stream Transport case)
101 * struct resource_pool - One per driver. Represents the hw blocks not in the
102 * main pipeline. Not directly accessible by dm.
104 * Main dc state structs:
106 * These structs can be created and destroyed as needed. There is a full set of
107 * these structs in dc->current_state representing the currently programmed state.
109 * struct dc_state - The global DC state to track global state information,
110 * such as bandwidth values.
112 * struct dc_stream_state - Represents the hw configuration for the pipeline from
113 * a framebuffer to a display. Maps one-to-one with dc_sink.
115 * struct dc_plane_state - Represents a framebuffer. Each stream has at least one,
116 * and may have more in the Multi-Plane Overlay case.
118 * struct resource_context - Represents the programmable state of everything in
119 * the resource_pool. Not directly accessible by dm.
121 * struct pipe_ctx - A member of struct resource_context. Represents the
122 * internal hardware pipeline components. Each dc_plane_state has either
123 * one or two (in the pipe-split case).
126 /*******************************************************************************
128 ******************************************************************************/
130 static inline void elevate_update_type(enum surface_update_type *original, enum surface_update_type new)
136 static void destroy_links(struct dc *dc)
140 for (i = 0; i < dc->link_count; i++) {
141 if (NULL != dc->links[i])
142 link_destroy(&dc->links[i]);
146 static bool create_links(
148 uint32_t num_virtual_links)
152 struct dc_bios *bios = dc->ctx->dc_bios;
156 connectors_num = bios->funcs->get_connectors_number(bios);
158 if (connectors_num > ENUM_ID_COUNT) {
160 "DC: Number of connectors %d exceeds maximum of %d!\n",
166 dm_output_to_console(
167 "DC: %s: connectors_num: physical:%d, virtual:%d\n",
172 for (i = 0; i < connectors_num; i++) {
173 struct link_init_data link_init_params = {0};
174 struct dc_link *link;
176 link_init_params.ctx = dc->ctx;
177 /* next BIOS object table connector */
178 link_init_params.connector_index = i;
179 link_init_params.link_index = dc->link_count;
180 link_init_params.dc = dc;
181 link = link_create(&link_init_params);
184 bool should_destory_link = false;
186 if (link->connector_signal == SIGNAL_TYPE_EDP) {
187 if (dc->config.edp_not_connected)
188 should_destory_link = true;
189 else if (dc->debug.remove_disconnect_edp) {
190 enum dc_connection_type type;
191 dc_link_detect_sink(link, &type);
192 if (type == dc_connection_none)
193 should_destory_link = true;
197 if (dc->config.force_enum_edp || !should_destory_link) {
198 dc->links[dc->link_count] = link;
207 for (i = 0; i < num_virtual_links; i++) {
208 struct dc_link *link = kzalloc(sizeof(*link), GFP_KERNEL);
209 struct encoder_init_data enc_init = {0};
216 link->link_index = dc->link_count;
217 dc->links[dc->link_count] = link;
222 link->connector_signal = SIGNAL_TYPE_VIRTUAL;
223 link->link_id.type = OBJECT_TYPE_CONNECTOR;
224 link->link_id.id = CONNECTOR_ID_VIRTUAL;
225 link->link_id.enum_id = ENUM_ID_1;
226 link->link_enc = kzalloc(sizeof(*link->link_enc), GFP_KERNEL);
228 if (!link->link_enc) {
233 link->link_status.dpcd_caps = &link->dpcd_caps;
235 enc_init.ctx = dc->ctx;
236 enc_init.channel = CHANNEL_ID_UNKNOWN;
237 enc_init.hpd_source = HPD_SOURCEID_UNKNOWN;
238 enc_init.transmitter = TRANSMITTER_UNKNOWN;
239 enc_init.connector = link->link_id;
240 enc_init.encoder.type = OBJECT_TYPE_ENCODER;
241 enc_init.encoder.id = ENCODER_ID_INTERNAL_VIRTUAL;
242 enc_init.encoder.enum_id = ENUM_ID_1;
243 virtual_link_encoder_construct(link->link_enc, &enc_init);
252 static struct dc_perf_trace *dc_perf_trace_create(void)
254 return kzalloc(sizeof(struct dc_perf_trace), GFP_KERNEL);
257 static void dc_perf_trace_destroy(struct dc_perf_trace **perf_trace)
264 *****************************************************************************
265 * Function: dc_stream_adjust_vmin_vmax
268 * Looks up the pipe context of dc_stream_state and updates the
269 * vertical_total_min and vertical_total_max of the DRR, Dynamic Refresh
270 * Rate, which is a power-saving feature that targets reducing panel
271 * refresh rate while the screen is static
273 * @param [in] dc: dc reference
274 * @param [in] stream: Initial dc stream state
275 * @param [in] adjust: Updated parameters for vertical_total_min and
277 *****************************************************************************
279 bool dc_stream_adjust_vmin_vmax(struct dc *dc,
280 struct dc_stream_state *stream,
281 struct dc_crtc_timing_adjust *adjust)
286 stream->adjust = *adjust;
288 for (i = 0; i < MAX_PIPES; i++) {
289 struct pipe_ctx *pipe = &dc->current_state->res_ctx.pipe_ctx[i];
291 if (pipe->stream == stream && pipe->stream_res.tg) {
292 dc->hwss.set_drr(&pipe,
297 adjust->v_total_mid_frame_num);
305 bool dc_stream_get_crtc_position(struct dc *dc,
306 struct dc_stream_state **streams, int num_streams,
307 unsigned int *v_pos, unsigned int *nom_v_pos)
309 /* TODO: Support multiple streams */
310 const struct dc_stream_state *stream = streams[0];
313 struct crtc_position position;
315 for (i = 0; i < MAX_PIPES; i++) {
316 struct pipe_ctx *pipe =
317 &dc->current_state->res_ctx.pipe_ctx[i];
319 if (pipe->stream == stream && pipe->stream_res.stream_enc) {
320 dc->hwss.get_position(&pipe, 1, &position);
322 *v_pos = position.vertical_count;
323 *nom_v_pos = position.nominal_vcount;
331 * dc_stream_configure_crc() - Configure CRC capture for the given stream.
333 * @stream: The stream to configure CRC on.
334 * @enable: Enable CRC if true, disable otherwise.
335 * @continuous: Capture CRC on every frame if true. Otherwise, only capture
338 * By default, only CRC0 is configured, and the entire frame is used to
341 bool dc_stream_configure_crc(struct dc *dc, struct dc_stream_state *stream,
342 bool enable, bool continuous)
345 struct pipe_ctx *pipe;
346 struct crc_params param;
347 struct timing_generator *tg;
349 for (i = 0; i < MAX_PIPES; i++) {
350 pipe = &dc->current_state->res_ctx.pipe_ctx[i];
351 if (pipe->stream == stream)
354 /* Stream not found */
358 /* Always capture the full frame */
359 param.windowa_x_start = 0;
360 param.windowa_y_start = 0;
361 param.windowa_x_end = pipe->stream->timing.h_addressable;
362 param.windowa_y_end = pipe->stream->timing.v_addressable;
363 param.windowb_x_start = 0;
364 param.windowb_y_start = 0;
365 param.windowb_x_end = pipe->stream->timing.h_addressable;
366 param.windowb_y_end = pipe->stream->timing.v_addressable;
368 /* Default to the union of both windows */
369 param.selection = UNION_WINDOW_A_B;
370 param.continuous_mode = continuous;
371 param.enable = enable;
373 tg = pipe->stream_res.tg;
375 /* Only call if supported */
376 if (tg->funcs->configure_crc)
377 return tg->funcs->configure_crc(tg, ¶m);
378 DC_LOG_WARNING("CRC capture not supported.");
383 * dc_stream_get_crc() - Get CRC values for the given stream.
385 * @stream: The DC stream state of the stream to get CRCs from.
386 * @r_cr, g_y, b_cb: CRC values for the three channels are stored here.
388 * dc_stream_configure_crc needs to be called beforehand to enable CRCs.
389 * Return false if stream is not found, or if CRCs are not enabled.
391 bool dc_stream_get_crc(struct dc *dc, struct dc_stream_state *stream,
392 uint32_t *r_cr, uint32_t *g_y, uint32_t *b_cb)
395 struct pipe_ctx *pipe;
396 struct timing_generator *tg;
398 for (i = 0; i < MAX_PIPES; i++) {
399 pipe = &dc->current_state->res_ctx.pipe_ctx[i];
400 if (pipe->stream == stream)
403 /* Stream not found */
407 tg = pipe->stream_res.tg;
409 if (tg->funcs->get_crc)
410 return tg->funcs->get_crc(tg, r_cr, g_y, b_cb);
411 DC_LOG_WARNING("CRC capture not supported.");
415 void dc_stream_set_dyn_expansion(struct dc *dc, struct dc_stream_state *stream,
416 enum dc_dynamic_expansion option)
418 /* OPP FMT dyn expansion updates*/
420 struct pipe_ctx *pipe_ctx;
422 for (i = 0; i < MAX_PIPES; i++) {
423 if (dc->current_state->res_ctx.pipe_ctx[i].stream
425 pipe_ctx = &dc->current_state->res_ctx.pipe_ctx[i];
426 pipe_ctx->stream_res.opp->dyn_expansion = option;
427 pipe_ctx->stream_res.opp->funcs->opp_set_dyn_expansion(
428 pipe_ctx->stream_res.opp,
429 COLOR_SPACE_YCBCR601,
430 stream->timing.display_color_depth,
436 void dc_stream_set_dither_option(struct dc_stream_state *stream,
437 enum dc_dither_option option)
439 struct bit_depth_reduction_params params;
440 struct dc_link *link = stream->link;
441 struct pipe_ctx *pipes = NULL;
444 for (i = 0; i < MAX_PIPES; i++) {
445 if (link->dc->current_state->res_ctx.pipe_ctx[i].stream ==
447 pipes = &link->dc->current_state->res_ctx.pipe_ctx[i];
454 if (option > DITHER_OPTION_MAX)
457 stream->dither_option = option;
459 memset(¶ms, 0, sizeof(params));
460 resource_build_bit_depth_reduction_params(stream, ¶ms);
461 stream->bit_depth_params = params;
463 if (pipes->plane_res.xfm &&
464 pipes->plane_res.xfm->funcs->transform_set_pixel_storage_depth) {
465 pipes->plane_res.xfm->funcs->transform_set_pixel_storage_depth(
466 pipes->plane_res.xfm,
467 pipes->plane_res.scl_data.lb_params.depth,
468 &stream->bit_depth_params);
471 pipes->stream_res.opp->funcs->
472 opp_program_bit_depth_reduction(pipes->stream_res.opp, ¶ms);
475 bool dc_stream_set_gamut_remap(struct dc *dc, const struct dc_stream_state *stream)
479 struct pipe_ctx *pipes;
481 for (i = 0; i < MAX_PIPES; i++) {
482 if (dc->current_state->res_ctx.pipe_ctx[i].stream == stream) {
483 pipes = &dc->current_state->res_ctx.pipe_ctx[i];
484 dc->hwss.program_gamut_remap(pipes);
492 bool dc_stream_program_csc_matrix(struct dc *dc, struct dc_stream_state *stream)
496 struct pipe_ctx *pipes;
498 for (i = 0; i < MAX_PIPES; i++) {
499 if (dc->current_state->res_ctx.pipe_ctx[i].stream
502 pipes = &dc->current_state->res_ctx.pipe_ctx[i];
503 dc->hwss.program_output_csc(dc,
505 stream->output_color_space,
506 stream->csc_color_matrix.matrix,
507 pipes->stream_res.opp->inst);
515 void dc_stream_set_static_screen_params(struct dc *dc,
516 struct dc_stream_state **streams,
518 const struct dc_static_screen_params *params)
522 struct pipe_ctx *pipes_affected[MAX_PIPES];
523 int num_pipes_affected = 0;
525 for (i = 0; i < num_streams; i++) {
526 struct dc_stream_state *stream = streams[i];
528 for (j = 0; j < MAX_PIPES; j++) {
529 if (dc->current_state->res_ctx.pipe_ctx[j].stream
531 pipes_affected[num_pipes_affected++] =
532 &dc->current_state->res_ctx.pipe_ctx[j];
537 dc->hwss.set_static_screen_control(pipes_affected, num_pipes_affected, params);
540 static void dc_destruct(struct dc *dc)
542 if (dc->current_state) {
543 dc_release_state(dc->current_state);
544 dc->current_state = NULL;
550 dc_destroy_clk_mgr(dc->clk_mgr);
554 dc_destroy_resource_pool(dc);
556 if (dc->ctx->gpio_service)
557 dal_gpio_service_destroy(&dc->ctx->gpio_service);
559 if (dc->ctx->created_bios)
560 dal_bios_parser_destroy(&dc->ctx->dc_bios);
562 dc_perf_trace_destroy(&dc->ctx->perf_trace);
573 #ifdef CONFIG_DRM_AMD_DC_DCN
581 kfree(dc->vm_helper);
582 dc->vm_helper = NULL;
586 static bool dc_construct_ctx(struct dc *dc,
587 const struct dc_init_data *init_params)
589 struct dc_context *dc_ctx;
590 enum dce_version dc_version = DCE_VERSION_UNKNOWN;
592 dc_ctx = kzalloc(sizeof(*dc_ctx), GFP_KERNEL);
596 dc_ctx->cgs_device = init_params->cgs_device;
597 dc_ctx->driver_context = init_params->driver;
599 dc_ctx->asic_id = init_params->asic_id;
600 dc_ctx->dc_sink_id_count = 0;
601 dc_ctx->dc_stream_id_count = 0;
602 dc_ctx->dce_environment = init_params->dce_environment;
606 dc_version = resource_parse_asic_id(init_params->asic_id);
607 dc_ctx->dce_version = dc_version;
609 dc_ctx->perf_trace = dc_perf_trace_create();
610 if (!dc_ctx->perf_trace) {
611 ASSERT_CRITICAL(false);
620 static bool dc_construct(struct dc *dc,
621 const struct dc_init_data *init_params)
623 struct dc_context *dc_ctx;
624 struct bw_calcs_dceip *dc_dceip;
625 struct bw_calcs_vbios *dc_vbios;
626 #ifdef CONFIG_DRM_AMD_DC_DCN
627 struct dcn_soc_bounding_box *dcn_soc;
628 struct dcn_ip_params *dcn_ip;
631 dc->config = init_params->flags;
633 // Allocate memory for the vm_helper
634 dc->vm_helper = kzalloc(sizeof(struct vm_helper), GFP_KERNEL);
635 if (!dc->vm_helper) {
636 dm_error("%s: failed to create dc->vm_helper\n", __func__);
640 memcpy(&dc->bb_overrides, &init_params->bb_overrides, sizeof(dc->bb_overrides));
642 dc_dceip = kzalloc(sizeof(*dc_dceip), GFP_KERNEL);
644 dm_error("%s: failed to create dceip\n", __func__);
648 dc->bw_dceip = dc_dceip;
650 dc_vbios = kzalloc(sizeof(*dc_vbios), GFP_KERNEL);
652 dm_error("%s: failed to create vbios\n", __func__);
656 dc->bw_vbios = dc_vbios;
657 #ifdef CONFIG_DRM_AMD_DC_DCN
658 dcn_soc = kzalloc(sizeof(*dcn_soc), GFP_KERNEL);
660 dm_error("%s: failed to create dcn_soc\n", __func__);
664 dc->dcn_soc = dcn_soc;
666 dcn_ip = kzalloc(sizeof(*dcn_ip), GFP_KERNEL);
668 dm_error("%s: failed to create dcn_ip\n", __func__);
673 dc->soc_bounding_box = init_params->soc_bounding_box;
676 if (!dc_construct_ctx(dc, init_params)) {
677 dm_error("%s: failed to create ctx\n", __func__);
683 /* Resource should construct all asic specific resources.
684 * This should be the only place where we need to parse the asic id
686 if (init_params->vbios_override)
687 dc_ctx->dc_bios = init_params->vbios_override;
689 /* Create BIOS parser */
690 struct bp_init_data bp_init_data;
692 bp_init_data.ctx = dc_ctx;
693 bp_init_data.bios = init_params->asic_id.atombios_base_address;
695 dc_ctx->dc_bios = dal_bios_parser_create(
696 &bp_init_data, dc_ctx->dce_version);
698 if (!dc_ctx->dc_bios) {
699 ASSERT_CRITICAL(false);
703 dc_ctx->created_bios = true;
706 dc->vendor_signature = init_params->vendor_signature;
708 /* Create GPIO service */
709 dc_ctx->gpio_service = dal_gpio_service_create(
711 dc_ctx->dce_environment,
714 if (!dc_ctx->gpio_service) {
715 ASSERT_CRITICAL(false);
719 dc->res_pool = dc_create_resource_pool(dc, init_params, dc_ctx->dce_version);
723 dc->clk_mgr = dc_clk_mgr_create(dc->ctx, dc->res_pool->pp_smu, dc->res_pool->dccg);
727 if (dc->res_pool->funcs->update_bw_bounding_box)
728 dc->res_pool->funcs->update_bw_bounding_box(dc, dc->clk_mgr->bw_params);
730 /* Creation of current_state must occur after dc->dml
731 * is initialized in dc_create_resource_pool because
732 * on creation it copies the contents of dc->dml
735 dc->current_state = dc_create_state(dc);
737 if (!dc->current_state) {
738 dm_error("%s: failed to create validate ctx\n", __func__);
742 dc_resource_state_construct(dc, dc->current_state);
744 if (!create_links(dc, init_params->num_virtual_links))
753 static bool disable_all_writeback_pipes_for_stream(
755 struct dc_stream_state *stream,
756 struct dc_state *context)
760 for (i = 0; i < stream->num_wb_info; i++)
761 stream->writeback_info[i].wb_enabled = false;
766 void apply_ctx_interdependent_lock(struct dc *dc, struct dc_state *context, struct dc_stream_state *stream, bool lock)
770 /* Checks if interdependent update function pointer is NULL or not, takes care of DCE110 case */
771 if (dc->hwss.interdependent_update_lock)
772 dc->hwss.interdependent_update_lock(dc, context, lock);
774 for (i = 0; i < dc->res_pool->pipe_count; i++) {
775 struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[i];
776 struct pipe_ctx *old_pipe_ctx = &dc->current_state->res_ctx.pipe_ctx[i];
778 // Copied conditions that were previously in dce110_apply_ctx_for_surface
779 if (stream == pipe_ctx->stream) {
780 if (!pipe_ctx->top_pipe &&
781 (pipe_ctx->plane_state || old_pipe_ctx->plane_state))
782 dc->hwss.pipe_control_lock(dc, pipe_ctx, lock);
788 static void disable_dangling_plane(struct dc *dc, struct dc_state *context)
791 struct dc_state *dangling_context = dc_create_state(dc);
792 struct dc_state *current_ctx;
794 if (dangling_context == NULL)
797 dc_resource_state_copy_construct(dc->current_state, dangling_context);
799 for (i = 0; i < dc->res_pool->pipe_count; i++) {
800 struct dc_stream_state *old_stream =
801 dc->current_state->res_ctx.pipe_ctx[i].stream;
802 bool should_disable = true;
804 for (j = 0; j < context->stream_count; j++) {
805 if (old_stream == context->streams[j]) {
806 should_disable = false;
810 if (should_disable && old_stream) {
811 dc_rem_all_planes_for_stream(dc, old_stream, dangling_context);
812 disable_all_writeback_pipes_for_stream(dc, old_stream, dangling_context);
814 if (dc->hwss.apply_ctx_for_surface) {
815 apply_ctx_interdependent_lock(dc, dc->current_state, old_stream, true);
816 dc->hwss.apply_ctx_for_surface(dc, old_stream, 0, dangling_context);
817 apply_ctx_interdependent_lock(dc, dc->current_state, old_stream, false);
818 dc->hwss.post_unlock_program_front_end(dc, dangling_context);
820 if (dc->hwss.program_front_end_for_ctx) {
821 dc->hwss.interdependent_update_lock(dc, dc->current_state, true);
822 dc->hwss.program_front_end_for_ctx(dc, dangling_context);
823 dc->hwss.interdependent_update_lock(dc, dc->current_state, false);
824 dc->hwss.post_unlock_program_front_end(dc, dangling_context);
829 current_ctx = dc->current_state;
830 dc->current_state = dangling_context;
831 dc_release_state(current_ctx);
834 static void wait_for_no_pipes_pending(struct dc *dc, struct dc_state *context)
838 for (i = 0; i < MAX_PIPES; i++) {
840 struct pipe_ctx *pipe = &context->res_ctx.pipe_ctx[i];
842 if (!pipe->plane_state)
846 while (count < 100000) {
847 /* Must set to false to start with, due to OR in update function */
848 pipe->plane_state->status.is_flip_pending = false;
849 dc->hwss.update_pending_status(pipe);
850 if (!pipe->plane_state->status.is_flip_pending)
855 ASSERT(!pipe->plane_state->status.is_flip_pending);
860 /*******************************************************************************
862 ******************************************************************************/
864 struct dc *dc_create(const struct dc_init_data *init_params)
866 struct dc *dc = kzalloc(sizeof(*dc), GFP_KERNEL);
867 unsigned int full_pipe_count;
872 if (init_params->dce_environment == DCE_ENV_VIRTUAL_HW) {
873 if (false == dc_construct_ctx(dc, init_params)) {
878 if (false == dc_construct(dc, init_params)) {
883 full_pipe_count = dc->res_pool->pipe_count;
884 if (dc->res_pool->underlay_pipe_index != NO_UNDERLAY_PIPE)
886 dc->caps.max_streams = min(
888 dc->res_pool->stream_enc_count);
890 dc->optimize_seamless_boot_streams = 0;
891 dc->caps.max_links = dc->link_count;
892 dc->caps.max_audios = dc->res_pool->audio_count;
893 dc->caps.linear_pitch_alignment = 64;
895 dc->caps.max_dp_protocol_version = DP_VERSION_1_4;
897 if (dc->res_pool->dmcu != NULL)
898 dc->versions.dmcu_version = dc->res_pool->dmcu->dmcu_version;
901 /* Populate versioning information */
902 dc->versions.dc_ver = DC_VER;
904 dc->build_id = DC_BUILD_ID;
906 DC_LOG_DC("Display Core initialized\n");
919 void dc_hardware_init(struct dc *dc)
921 if (dc->ctx->dce_environment != DCE_ENV_VIRTUAL_HW)
922 dc->hwss.init_hw(dc);
925 void dc_init_callbacks(struct dc *dc,
926 const struct dc_callback_init *init_params)
928 #ifdef CONFIG_DRM_AMD_DC_HDCP
929 dc->ctx->cp_psp = init_params->cp_psp;
933 void dc_deinit_callbacks(struct dc *dc)
935 #ifdef CONFIG_DRM_AMD_DC_HDCP
936 memset(&dc->ctx->cp_psp, 0, sizeof(dc->ctx->cp_psp));
940 void dc_destroy(struct dc **dc)
947 static void enable_timing_multisync(
949 struct dc_state *ctx)
951 int i = 0, multisync_count = 0;
952 int pipe_count = dc->res_pool->pipe_count;
953 struct pipe_ctx *multisync_pipes[MAX_PIPES] = { NULL };
955 for (i = 0; i < pipe_count; i++) {
956 if (!ctx->res_ctx.pipe_ctx[i].stream ||
957 !ctx->res_ctx.pipe_ctx[i].stream->triggered_crtc_reset.enabled)
959 if (ctx->res_ctx.pipe_ctx[i].stream == ctx->res_ctx.pipe_ctx[i].stream->triggered_crtc_reset.event_source)
961 multisync_pipes[multisync_count] = &ctx->res_ctx.pipe_ctx[i];
965 if (multisync_count > 0) {
966 dc->hwss.enable_per_frame_crtc_position_reset(
967 dc, multisync_count, multisync_pipes);
971 static void program_timing_sync(
973 struct dc_state *ctx)
978 int pipe_count = dc->res_pool->pipe_count;
979 struct pipe_ctx *unsynced_pipes[MAX_PIPES] = { NULL };
981 for (i = 0; i < pipe_count; i++) {
982 if (!ctx->res_ctx.pipe_ctx[i].stream || ctx->res_ctx.pipe_ctx[i].top_pipe)
985 unsynced_pipes[i] = &ctx->res_ctx.pipe_ctx[i];
988 for (i = 0; i < pipe_count; i++) {
990 struct pipe_ctx *pipe_set[MAX_PIPES];
992 if (!unsynced_pipes[i])
995 pipe_set[0] = unsynced_pipes[i];
996 unsynced_pipes[i] = NULL;
998 /* Add tg to the set, search rest of the tg's for ones with
999 * same timing, add all tgs with same timing to the group
1001 for (j = i + 1; j < pipe_count; j++) {
1002 if (!unsynced_pipes[j])
1005 if (resource_are_streams_timing_synchronizable(
1006 unsynced_pipes[j]->stream,
1007 pipe_set[0]->stream)) {
1008 pipe_set[group_size] = unsynced_pipes[j];
1009 unsynced_pipes[j] = NULL;
1014 /* set first pipe with plane as master */
1015 for (j = 0; j < group_size; j++) {
1016 if (pipe_set[j]->plane_state) {
1020 swap(pipe_set[0], pipe_set[j]);
1026 for (k = 0; k < group_size; k++) {
1027 struct dc_stream_status *status = dc_stream_get_status_from_state(ctx, pipe_set[k]->stream);
1029 status->timing_sync_info.group_id = num_group;
1030 status->timing_sync_info.group_size = group_size;
1032 status->timing_sync_info.master = true;
1034 status->timing_sync_info.master = false;
1037 /* remove any other pipes with plane as they have already been synced */
1038 for (j = j + 1; j < group_size; j++) {
1039 if (pipe_set[j]->plane_state) {
1041 pipe_set[j] = pipe_set[group_size];
1046 if (group_size > 1) {
1047 dc->hwss.enable_timing_synchronization(
1048 dc, group_index, group_size, pipe_set);
1055 static bool context_changed(
1057 struct dc_state *context)
1061 if (context->stream_count != dc->current_state->stream_count)
1064 for (i = 0; i < dc->current_state->stream_count; i++) {
1065 if (dc->current_state->streams[i] != context->streams[i])
1072 bool dc_validate_seamless_boot_timing(const struct dc *dc,
1073 const struct dc_sink *sink,
1074 struct dc_crtc_timing *crtc_timing)
1076 struct timing_generator *tg;
1077 struct stream_encoder *se = NULL;
1079 struct dc_crtc_timing hw_crtc_timing = {0};
1081 struct dc_link *link = sink->link;
1082 unsigned int i, enc_inst, tg_inst = 0;
1084 // Seamless port only support single DP and EDP so far
1085 if (sink->sink_signal != SIGNAL_TYPE_DISPLAY_PORT &&
1086 sink->sink_signal != SIGNAL_TYPE_EDP)
1089 /* Check for enabled DIG to identify enabled display */
1090 if (!link->link_enc->funcs->is_dig_enabled(link->link_enc))
1093 enc_inst = link->link_enc->funcs->get_dig_frontend(link->link_enc);
1095 if (enc_inst == ENGINE_ID_UNKNOWN)
1098 for (i = 0; i < dc->res_pool->stream_enc_count; i++) {
1099 if (dc->res_pool->stream_enc[i]->id == enc_inst) {
1101 se = dc->res_pool->stream_enc[i];
1103 tg_inst = dc->res_pool->stream_enc[i]->funcs->dig_source_otg(
1104 dc->res_pool->stream_enc[i]);
1109 // tg_inst not found
1110 if (i == dc->res_pool->stream_enc_count)
1113 if (tg_inst >= dc->res_pool->timing_generator_count)
1116 tg = dc->res_pool->timing_generators[tg_inst];
1118 if (!tg->funcs->get_hw_timing)
1121 if (!tg->funcs->get_hw_timing(tg, &hw_crtc_timing))
1124 if (crtc_timing->h_total != hw_crtc_timing.h_total)
1127 if (crtc_timing->h_border_left != hw_crtc_timing.h_border_left)
1130 if (crtc_timing->h_addressable != hw_crtc_timing.h_addressable)
1133 if (crtc_timing->h_border_right != hw_crtc_timing.h_border_right)
1136 if (crtc_timing->h_front_porch != hw_crtc_timing.h_front_porch)
1139 if (crtc_timing->h_sync_width != hw_crtc_timing.h_sync_width)
1142 if (crtc_timing->v_total != hw_crtc_timing.v_total)
1145 if (crtc_timing->v_border_top != hw_crtc_timing.v_border_top)
1148 if (crtc_timing->v_addressable != hw_crtc_timing.v_addressable)
1151 if (crtc_timing->v_border_bottom != hw_crtc_timing.v_border_bottom)
1154 if (crtc_timing->v_front_porch != hw_crtc_timing.v_front_porch)
1157 if (crtc_timing->v_sync_width != hw_crtc_timing.v_sync_width)
1160 if (dc_is_dp_signal(link->connector_signal)) {
1161 unsigned int pix_clk_100hz;
1163 dc->res_pool->dp_clock_source->funcs->get_pixel_clk_frequency_100hz(
1164 dc->res_pool->dp_clock_source,
1165 tg_inst, &pix_clk_100hz);
1167 if (crtc_timing->pix_clk_100hz != pix_clk_100hz)
1170 if (!se->funcs->dp_get_pixel_format)
1173 if (!se->funcs->dp_get_pixel_format(
1175 &hw_crtc_timing.pixel_encoding,
1176 &hw_crtc_timing.display_color_depth))
1179 if (hw_crtc_timing.display_color_depth != crtc_timing->display_color_depth)
1182 if (hw_crtc_timing.pixel_encoding != crtc_timing->pixel_encoding)
1189 bool dc_enable_stereo(
1191 struct dc_state *context,
1192 struct dc_stream_state *streams[],
1193 uint8_t stream_count)
1197 struct pipe_ctx *pipe;
1199 for (i = 0; i < MAX_PIPES; i++) {
1200 if (context != NULL)
1201 pipe = &context->res_ctx.pipe_ctx[i];
1203 pipe = &dc->current_state->res_ctx.pipe_ctx[i];
1204 for (j = 0 ; pipe && j < stream_count; j++) {
1205 if (streams[j] && streams[j] == pipe->stream &&
1206 dc->hwss.setup_stereo)
1207 dc->hwss.setup_stereo(pipe, dc);
1215 * Applies given context to HW and copy it into current context.
1216 * It's up to the user to release the src context afterwards.
1218 static enum dc_status dc_commit_state_no_check(struct dc *dc, struct dc_state *context)
1220 struct dc_bios *dcb = dc->ctx->dc_bios;
1221 enum dc_status result = DC_ERROR_UNEXPECTED;
1222 struct pipe_ctx *pipe;
1224 struct dc_stream_state *dc_streams[MAX_STREAMS] = {0};
1226 disable_dangling_plane(dc, context);
1228 for (i = 0; i < context->stream_count; i++)
1229 dc_streams[i] = context->streams[i];
1231 if (!dcb->funcs->is_accelerated_mode(dcb))
1232 dc->hwss.enable_accelerated_mode(dc, context);
1234 for (i = 0; i < context->stream_count; i++) {
1235 if (context->streams[i]->apply_seamless_boot_optimization)
1236 dc->optimize_seamless_boot_streams++;
1239 if (dc->optimize_seamless_boot_streams == 0)
1240 dc->hwss.prepare_bandwidth(dc, context);
1242 /* re-program planes for existing stream, in case we need to
1243 * free up plane resource for later use
1245 if (dc->hwss.apply_ctx_for_surface) {
1246 for (i = 0; i < context->stream_count; i++) {
1247 if (context->streams[i]->mode_changed)
1249 apply_ctx_interdependent_lock(dc, context, context->streams[i], true);
1250 dc->hwss.apply_ctx_for_surface(
1251 dc, context->streams[i],
1252 context->stream_status[i].plane_count,
1253 context); /* use new pipe config in new context */
1254 apply_ctx_interdependent_lock(dc, context, context->streams[i], false);
1255 dc->hwss.post_unlock_program_front_end(dc, context);
1259 /* Program hardware */
1260 for (i = 0; i < dc->res_pool->pipe_count; i++) {
1261 pipe = &context->res_ctx.pipe_ctx[i];
1262 dc->hwss.wait_for_mpcc_disconnect(dc, dc->res_pool, pipe);
1265 result = dc->hwss.apply_ctx_to_hw(dc, context);
1267 if (result != DC_OK)
1270 if (context->stream_count > 1 && !dc->debug.disable_timing_sync) {
1271 enable_timing_multisync(dc, context);
1272 program_timing_sync(dc, context);
1275 /* Program all planes within new context*/
1276 if (dc->hwss.program_front_end_for_ctx) {
1277 dc->hwss.interdependent_update_lock(dc, context, true);
1278 dc->hwss.program_front_end_for_ctx(dc, context);
1279 dc->hwss.interdependent_update_lock(dc, context, false);
1280 dc->hwss.post_unlock_program_front_end(dc, context);
1282 for (i = 0; i < context->stream_count; i++) {
1283 const struct dc_link *link = context->streams[i]->link;
1285 if (!context->streams[i]->mode_changed)
1288 if (dc->hwss.apply_ctx_for_surface) {
1289 apply_ctx_interdependent_lock(dc, context, context->streams[i], true);
1290 dc->hwss.apply_ctx_for_surface(
1291 dc, context->streams[i],
1292 context->stream_status[i].plane_count,
1294 apply_ctx_interdependent_lock(dc, context, context->streams[i], false);
1295 dc->hwss.post_unlock_program_front_end(dc, context);
1300 * TODO rework dc_enable_stereo call to work with validation sets?
1302 for (k = 0; k < MAX_PIPES; k++) {
1303 pipe = &context->res_ctx.pipe_ctx[k];
1305 for (l = 0 ; pipe && l < context->stream_count; l++) {
1306 if (context->streams[l] &&
1307 context->streams[l] == pipe->stream &&
1308 dc->hwss.setup_stereo)
1309 dc->hwss.setup_stereo(pipe, dc);
1313 CONN_MSG_MODE(link, "{%dx%d, %dx%d@%dKhz}",
1314 context->streams[i]->timing.h_addressable,
1315 context->streams[i]->timing.v_addressable,
1316 context->streams[i]->timing.h_total,
1317 context->streams[i]->timing.v_total,
1318 context->streams[i]->timing.pix_clk_100hz / 10);
1321 dc_enable_stereo(dc, context, dc_streams, context->stream_count);
1323 if (dc->optimize_seamless_boot_streams == 0) {
1324 /* Must wait for no flips to be pending before doing optimize bw */
1325 wait_for_no_pipes_pending(dc, context);
1326 /* pplib is notified if disp_num changed */
1327 dc->hwss.optimize_bandwidth(dc, context);
1330 for (i = 0; i < context->stream_count; i++)
1331 context->streams[i]->mode_changed = false;
1333 dc_release_state(dc->current_state);
1335 dc->current_state = context;
1337 dc_retain_state(dc->current_state);
1342 bool dc_commit_state(struct dc *dc, struct dc_state *context)
1344 enum dc_status result = DC_ERROR_UNEXPECTED;
1347 if (false == context_changed(dc, context))
1350 DC_LOG_DC("%s: %d streams\n",
1351 __func__, context->stream_count);
1353 for (i = 0; i < context->stream_count; i++) {
1354 struct dc_stream_state *stream = context->streams[i];
1356 dc_stream_log(dc, stream);
1359 result = dc_commit_state_no_check(dc, context);
1361 return (result == DC_OK);
1364 static bool is_flip_pending_in_pipes(struct dc *dc, struct dc_state *context)
1367 struct pipe_ctx *pipe;
1369 for (i = 0; i < MAX_PIPES; i++) {
1370 pipe = &context->res_ctx.pipe_ctx[i];
1372 if (!pipe->plane_state)
1375 /* Must set to false to start with, due to OR in update function */
1376 pipe->plane_state->status.is_flip_pending = false;
1377 dc->hwss.update_pending_status(pipe);
1378 if (pipe->plane_state->status.is_flip_pending)
1384 bool dc_post_update_surfaces_to_stream(struct dc *dc)
1387 struct dc_state *context = dc->current_state;
1389 if ((!dc->optimized_required) || dc->optimize_seamless_boot_streams > 0)
1392 post_surface_trace(dc);
1394 if (is_flip_pending_in_pipes(dc, context))
1397 for (i = 0; i < dc->res_pool->pipe_count; i++)
1398 if (context->res_ctx.pipe_ctx[i].stream == NULL ||
1399 context->res_ctx.pipe_ctx[i].plane_state == NULL) {
1400 context->res_ctx.pipe_ctx[i].pipe_idx = i;
1401 dc->hwss.disable_plane(dc, &context->res_ctx.pipe_ctx[i]);
1404 dc->hwss.optimize_bandwidth(dc, context);
1406 dc->optimized_required = false;
1407 dc->wm_optimized_required = false;
1412 struct dc_state *dc_create_state(struct dc *dc)
1414 struct dc_state *context = kvzalloc(sizeof(struct dc_state),
1419 /* Each context must have their own instance of VBA and in order to
1420 * initialize and obtain IP and SOC the base DML instance from DC is
1421 * initially copied into every context
1423 #ifdef CONFIG_DRM_AMD_DC_DCN
1424 memcpy(&context->bw_ctx.dml, &dc->dml, sizeof(struct display_mode_lib));
1427 kref_init(&context->refcount);
1432 struct dc_state *dc_copy_state(struct dc_state *src_ctx)
1435 struct dc_state *new_ctx = kvmalloc(sizeof(struct dc_state), GFP_KERNEL);
1439 memcpy(new_ctx, src_ctx, sizeof(struct dc_state));
1441 for (i = 0; i < MAX_PIPES; i++) {
1442 struct pipe_ctx *cur_pipe = &new_ctx->res_ctx.pipe_ctx[i];
1444 if (cur_pipe->top_pipe)
1445 cur_pipe->top_pipe = &new_ctx->res_ctx.pipe_ctx[cur_pipe->top_pipe->pipe_idx];
1447 if (cur_pipe->bottom_pipe)
1448 cur_pipe->bottom_pipe = &new_ctx->res_ctx.pipe_ctx[cur_pipe->bottom_pipe->pipe_idx];
1450 if (cur_pipe->prev_odm_pipe)
1451 cur_pipe->prev_odm_pipe = &new_ctx->res_ctx.pipe_ctx[cur_pipe->prev_odm_pipe->pipe_idx];
1453 if (cur_pipe->next_odm_pipe)
1454 cur_pipe->next_odm_pipe = &new_ctx->res_ctx.pipe_ctx[cur_pipe->next_odm_pipe->pipe_idx];
1458 for (i = 0; i < new_ctx->stream_count; i++) {
1459 dc_stream_retain(new_ctx->streams[i]);
1460 for (j = 0; j < new_ctx->stream_status[i].plane_count; j++)
1461 dc_plane_state_retain(
1462 new_ctx->stream_status[i].plane_states[j]);
1465 kref_init(&new_ctx->refcount);
1470 void dc_retain_state(struct dc_state *context)
1472 kref_get(&context->refcount);
1475 static void dc_state_free(struct kref *kref)
1477 struct dc_state *context = container_of(kref, struct dc_state, refcount);
1478 dc_resource_state_destruct(context);
1482 void dc_release_state(struct dc_state *context)
1484 kref_put(&context->refcount, dc_state_free);
1487 bool dc_set_generic_gpio_for_stereo(bool enable,
1488 struct gpio_service *gpio_service)
1490 enum gpio_result gpio_result = GPIO_RESULT_NON_SPECIFIC_ERROR;
1491 struct gpio_pin_info pin_info;
1492 struct gpio *generic;
1493 struct gpio_generic_mux_config *config = kzalloc(sizeof(struct gpio_generic_mux_config),
1498 pin_info = dal_gpio_get_generic_pin_info(gpio_service, GPIO_ID_GENERIC, 0);
1500 if (pin_info.mask == 0xFFFFFFFF || pin_info.offset == 0xFFFFFFFF) {
1504 generic = dal_gpio_service_create_generic_mux(
1515 gpio_result = dal_gpio_open(generic, GPIO_MODE_OUTPUT);
1517 config->enable_output_from_mux = enable;
1518 config->mux_select = GPIO_SIGNAL_SOURCE_PASS_THROUGH_STEREO_SYNC;
1520 if (gpio_result == GPIO_RESULT_OK)
1521 gpio_result = dal_mux_setup_config(generic, config);
1523 if (gpio_result == GPIO_RESULT_OK) {
1524 dal_gpio_close(generic);
1525 dal_gpio_destroy_generic_mux(&generic);
1529 dal_gpio_close(generic);
1530 dal_gpio_destroy_generic_mux(&generic);
1536 static bool is_surface_in_context(
1537 const struct dc_state *context,
1538 const struct dc_plane_state *plane_state)
1542 for (j = 0; j < MAX_PIPES; j++) {
1543 const struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[j];
1545 if (plane_state == pipe_ctx->plane_state) {
1553 static enum surface_update_type get_plane_info_update_type(const struct dc_surface_update *u)
1555 union surface_update_flags *update_flags = &u->surface->update_flags;
1556 enum surface_update_type update_type = UPDATE_TYPE_FAST;
1559 return UPDATE_TYPE_FAST;
1561 if (u->plane_info->color_space != u->surface->color_space) {
1562 update_flags->bits.color_space_change = 1;
1563 elevate_update_type(&update_type, UPDATE_TYPE_MED);
1566 if (u->plane_info->horizontal_mirror != u->surface->horizontal_mirror) {
1567 update_flags->bits.horizontal_mirror_change = 1;
1568 elevate_update_type(&update_type, UPDATE_TYPE_MED);
1571 if (u->plane_info->rotation != u->surface->rotation) {
1572 update_flags->bits.rotation_change = 1;
1573 elevate_update_type(&update_type, UPDATE_TYPE_FULL);
1576 if (u->plane_info->format != u->surface->format) {
1577 update_flags->bits.pixel_format_change = 1;
1578 elevate_update_type(&update_type, UPDATE_TYPE_FULL);
1581 if (u->plane_info->stereo_format != u->surface->stereo_format) {
1582 update_flags->bits.stereo_format_change = 1;
1583 elevate_update_type(&update_type, UPDATE_TYPE_FULL);
1586 if (u->plane_info->per_pixel_alpha != u->surface->per_pixel_alpha) {
1587 update_flags->bits.per_pixel_alpha_change = 1;
1588 elevate_update_type(&update_type, UPDATE_TYPE_MED);
1591 if (u->plane_info->global_alpha_value != u->surface->global_alpha_value) {
1592 update_flags->bits.global_alpha_change = 1;
1593 elevate_update_type(&update_type, UPDATE_TYPE_MED);
1596 if (u->plane_info->dcc.enable != u->surface->dcc.enable
1597 || u->plane_info->dcc.independent_64b_blks != u->surface->dcc.independent_64b_blks
1598 || u->plane_info->dcc.meta_pitch != u->surface->dcc.meta_pitch) {
1599 update_flags->bits.dcc_change = 1;
1600 elevate_update_type(&update_type, UPDATE_TYPE_MED);
1603 if (resource_pixel_format_to_bpp(u->plane_info->format) !=
1604 resource_pixel_format_to_bpp(u->surface->format)) {
1605 /* different bytes per element will require full bandwidth
1606 * and DML calculation
1608 update_flags->bits.bpp_change = 1;
1609 elevate_update_type(&update_type, UPDATE_TYPE_FULL);
1612 if (u->plane_info->plane_size.surface_pitch != u->surface->plane_size.surface_pitch
1613 || u->plane_info->plane_size.chroma_pitch != u->surface->plane_size.chroma_pitch) {
1614 update_flags->bits.plane_size_change = 1;
1615 elevate_update_type(&update_type, UPDATE_TYPE_MED);
1619 if (memcmp(&u->plane_info->tiling_info, &u->surface->tiling_info,
1620 sizeof(union dc_tiling_info)) != 0) {
1621 update_flags->bits.swizzle_change = 1;
1622 elevate_update_type(&update_type, UPDATE_TYPE_MED);
1624 /* todo: below are HW dependent, we should add a hook to
1625 * DCE/N resource and validated there.
1627 if (u->plane_info->tiling_info.gfx9.swizzle != DC_SW_LINEAR) {
1628 /* swizzled mode requires RQ to be setup properly,
1629 * thus need to run DML to calculate RQ settings
1631 update_flags->bits.bandwidth_change = 1;
1632 elevate_update_type(&update_type, UPDATE_TYPE_FULL);
1636 /* This should be UPDATE_TYPE_FAST if nothing has changed. */
1640 static enum surface_update_type get_scaling_info_update_type(
1641 const struct dc_surface_update *u)
1643 union surface_update_flags *update_flags = &u->surface->update_flags;
1645 if (!u->scaling_info)
1646 return UPDATE_TYPE_FAST;
1648 if (u->scaling_info->clip_rect.width != u->surface->clip_rect.width
1649 || u->scaling_info->clip_rect.height != u->surface->clip_rect.height
1650 || u->scaling_info->dst_rect.width != u->surface->dst_rect.width
1651 || u->scaling_info->dst_rect.height != u->surface->dst_rect.height
1652 || u->scaling_info->scaling_quality.integer_scaling !=
1653 u->surface->scaling_quality.integer_scaling
1655 update_flags->bits.scaling_change = 1;
1657 if ((u->scaling_info->dst_rect.width < u->surface->dst_rect.width
1658 || u->scaling_info->dst_rect.height < u->surface->dst_rect.height)
1659 && (u->scaling_info->dst_rect.width < u->surface->src_rect.width
1660 || u->scaling_info->dst_rect.height < u->surface->src_rect.height))
1661 /* Making dst rect smaller requires a bandwidth change */
1662 update_flags->bits.bandwidth_change = 1;
1665 if (u->scaling_info->src_rect.width != u->surface->src_rect.width
1666 || u->scaling_info->src_rect.height != u->surface->src_rect.height) {
1668 update_flags->bits.scaling_change = 1;
1669 if (u->scaling_info->src_rect.width > u->surface->src_rect.width
1670 || u->scaling_info->src_rect.height > u->surface->src_rect.height)
1671 /* Making src rect bigger requires a bandwidth change */
1672 update_flags->bits.clock_change = 1;
1675 if (u->scaling_info->src_rect.x != u->surface->src_rect.x
1676 || u->scaling_info->src_rect.y != u->surface->src_rect.y
1677 || u->scaling_info->clip_rect.x != u->surface->clip_rect.x
1678 || u->scaling_info->clip_rect.y != u->surface->clip_rect.y
1679 || u->scaling_info->dst_rect.x != u->surface->dst_rect.x
1680 || u->scaling_info->dst_rect.y != u->surface->dst_rect.y)
1681 update_flags->bits.position_change = 1;
1683 if (update_flags->bits.clock_change
1684 || update_flags->bits.bandwidth_change
1685 || update_flags->bits.scaling_change)
1686 return UPDATE_TYPE_FULL;
1688 if (update_flags->bits.position_change)
1689 return UPDATE_TYPE_MED;
1691 return UPDATE_TYPE_FAST;
1694 static enum surface_update_type det_surface_update(const struct dc *dc,
1695 const struct dc_surface_update *u)
1697 const struct dc_state *context = dc->current_state;
1698 enum surface_update_type type;
1699 enum surface_update_type overall_type = UPDATE_TYPE_FAST;
1700 union surface_update_flags *update_flags = &u->surface->update_flags;
1703 update_flags->bits.addr_update = 1;
1705 if (!is_surface_in_context(context, u->surface) || u->surface->force_full_update) {
1706 update_flags->raw = 0xFFFFFFFF;
1707 return UPDATE_TYPE_FULL;
1710 update_flags->raw = 0; // Reset all flags
1712 type = get_plane_info_update_type(u);
1713 elevate_update_type(&overall_type, type);
1715 type = get_scaling_info_update_type(u);
1716 elevate_update_type(&overall_type, type);
1719 update_flags->bits.addr_update = 1;
1721 if (u->in_transfer_func)
1722 update_flags->bits.in_transfer_func_change = 1;
1724 if (u->input_csc_color_matrix)
1725 update_flags->bits.input_csc_change = 1;
1727 if (u->coeff_reduction_factor)
1728 update_flags->bits.coeff_reduction_change = 1;
1730 if (u->gamut_remap_matrix)
1731 update_flags->bits.gamut_remap_change = 1;
1734 enum surface_pixel_format format = SURFACE_PIXEL_FORMAT_GRPH_BEGIN;
1737 format = u->plane_info->format;
1738 else if (u->surface)
1739 format = u->surface->format;
1741 if (dce_use_lut(format))
1742 update_flags->bits.gamma_change = 1;
1745 if (u->hdr_mult.value)
1746 if (u->hdr_mult.value != u->surface->hdr_mult.value) {
1747 update_flags->bits.hdr_mult = 1;
1748 elevate_update_type(&overall_type, UPDATE_TYPE_MED);
1751 if (update_flags->bits.in_transfer_func_change) {
1752 type = UPDATE_TYPE_MED;
1753 elevate_update_type(&overall_type, type);
1756 if (update_flags->bits.input_csc_change
1757 || update_flags->bits.coeff_reduction_change
1758 || update_flags->bits.gamma_change
1759 || update_flags->bits.gamut_remap_change) {
1760 type = UPDATE_TYPE_FULL;
1761 elevate_update_type(&overall_type, type);
1764 return overall_type;
1767 static enum surface_update_type check_update_surfaces_for_stream(
1769 struct dc_surface_update *updates,
1771 struct dc_stream_update *stream_update,
1772 const struct dc_stream_status *stream_status)
1775 enum surface_update_type overall_type = UPDATE_TYPE_FAST;
1777 if (stream_status == NULL || stream_status->plane_count != surface_count)
1778 overall_type = UPDATE_TYPE_FULL;
1780 /* some stream updates require passive update */
1781 if (stream_update) {
1782 union stream_update_flags *su_flags = &stream_update->stream->update_flags;
1784 if ((stream_update->src.height != 0 && stream_update->src.width != 0) ||
1785 (stream_update->dst.height != 0 && stream_update->dst.width != 0) ||
1786 stream_update->integer_scaling_update)
1787 su_flags->bits.scaling = 1;
1789 if (stream_update->out_transfer_func)
1790 su_flags->bits.out_tf = 1;
1792 if (stream_update->abm_level)
1793 su_flags->bits.abm_level = 1;
1795 if (stream_update->dpms_off)
1796 su_flags->bits.dpms_off = 1;
1798 if (stream_update->gamut_remap)
1799 su_flags->bits.gamut_remap = 1;
1801 if (stream_update->wb_update)
1802 su_flags->bits.wb_update = 1;
1804 if (stream_update->dsc_config)
1805 su_flags->bits.dsc_changed = 1;
1807 if (su_flags->raw != 0)
1808 overall_type = UPDATE_TYPE_FULL;
1810 if (stream_update->output_csc_transform || stream_update->output_color_space)
1811 su_flags->bits.out_csc = 1;
1814 for (i = 0 ; i < surface_count; i++) {
1815 enum surface_update_type type =
1816 det_surface_update(dc, &updates[i]);
1818 elevate_update_type(&overall_type, type);
1821 return overall_type;
1825 * dc_check_update_surfaces_for_stream() - Determine update type (fast, med, or full)
1827 * See :c:type:`enum surface_update_type <surface_update_type>` for explanation of update types
1829 enum surface_update_type dc_check_update_surfaces_for_stream(
1831 struct dc_surface_update *updates,
1833 struct dc_stream_update *stream_update,
1834 const struct dc_stream_status *stream_status)
1837 enum surface_update_type type;
1840 stream_update->stream->update_flags.raw = 0;
1841 for (i = 0; i < surface_count; i++)
1842 updates[i].surface->update_flags.raw = 0;
1844 type = check_update_surfaces_for_stream(dc, updates, surface_count, stream_update, stream_status);
1845 if (type == UPDATE_TYPE_FULL) {
1846 if (stream_update) {
1847 uint32_t dsc_changed = stream_update->stream->update_flags.bits.dsc_changed;
1848 stream_update->stream->update_flags.raw = 0xFFFFFFFF;
1849 stream_update->stream->update_flags.bits.dsc_changed = dsc_changed;
1851 for (i = 0; i < surface_count; i++)
1852 updates[i].surface->update_flags.raw = 0xFFFFFFFF;
1855 if (type == UPDATE_TYPE_FAST) {
1856 // If there's an available clock comparator, we use that.
1857 if (dc->clk_mgr->funcs->are_clock_states_equal) {
1858 if (!dc->clk_mgr->funcs->are_clock_states_equal(&dc->clk_mgr->clks, &dc->current_state->bw_ctx.bw.dcn.clk))
1859 dc->optimized_required = true;
1860 // Else we fallback to mem compare.
1861 } 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) {
1862 dc->optimized_required = true;
1865 dc->optimized_required |= dc->wm_optimized_required;
1871 static struct dc_stream_status *stream_get_status(
1872 struct dc_state *ctx,
1873 struct dc_stream_state *stream)
1877 for (i = 0; i < ctx->stream_count; i++) {
1878 if (stream == ctx->streams[i]) {
1879 return &ctx->stream_status[i];
1886 static const enum surface_update_type update_surface_trace_level = UPDATE_TYPE_FULL;
1888 static void copy_surface_update_to_plane(
1889 struct dc_plane_state *surface,
1890 struct dc_surface_update *srf_update)
1892 if (srf_update->flip_addr) {
1893 surface->address = srf_update->flip_addr->address;
1894 surface->flip_immediate =
1895 srf_update->flip_addr->flip_immediate;
1896 surface->time.time_elapsed_in_us[surface->time.index] =
1897 srf_update->flip_addr->flip_timestamp_in_us -
1898 surface->time.prev_update_time_in_us;
1899 surface->time.prev_update_time_in_us =
1900 srf_update->flip_addr->flip_timestamp_in_us;
1901 surface->time.index++;
1902 if (surface->time.index >= DC_PLANE_UPDATE_TIMES_MAX)
1903 surface->time.index = 0;
1905 surface->triplebuffer_flips = srf_update->flip_addr->triplebuffer_flips;
1908 if (srf_update->scaling_info) {
1909 surface->scaling_quality =
1910 srf_update->scaling_info->scaling_quality;
1912 srf_update->scaling_info->dst_rect;
1914 srf_update->scaling_info->src_rect;
1915 surface->clip_rect =
1916 srf_update->scaling_info->clip_rect;
1919 if (srf_update->plane_info) {
1920 surface->color_space =
1921 srf_update->plane_info->color_space;
1923 srf_update->plane_info->format;
1924 surface->plane_size =
1925 srf_update->plane_info->plane_size;
1927 srf_update->plane_info->rotation;
1928 surface->horizontal_mirror =
1929 srf_update->plane_info->horizontal_mirror;
1930 surface->stereo_format =
1931 srf_update->plane_info->stereo_format;
1932 surface->tiling_info =
1933 srf_update->plane_info->tiling_info;
1935 srf_update->plane_info->visible;
1936 surface->per_pixel_alpha =
1937 srf_update->plane_info->per_pixel_alpha;
1938 surface->global_alpha =
1939 srf_update->plane_info->global_alpha;
1940 surface->global_alpha_value =
1941 srf_update->plane_info->global_alpha_value;
1943 srf_update->plane_info->dcc;
1944 surface->layer_index =
1945 srf_update->plane_info->layer_index;
1948 if (srf_update->gamma &&
1949 (surface->gamma_correction !=
1950 srf_update->gamma)) {
1951 memcpy(&surface->gamma_correction->entries,
1952 &srf_update->gamma->entries,
1953 sizeof(struct dc_gamma_entries));
1954 surface->gamma_correction->is_identity =
1955 srf_update->gamma->is_identity;
1956 surface->gamma_correction->num_entries =
1957 srf_update->gamma->num_entries;
1958 surface->gamma_correction->type =
1959 srf_update->gamma->type;
1962 if (srf_update->in_transfer_func &&
1963 (surface->in_transfer_func !=
1964 srf_update->in_transfer_func)) {
1965 surface->in_transfer_func->sdr_ref_white_level =
1966 srf_update->in_transfer_func->sdr_ref_white_level;
1967 surface->in_transfer_func->tf =
1968 srf_update->in_transfer_func->tf;
1969 surface->in_transfer_func->type =
1970 srf_update->in_transfer_func->type;
1971 memcpy(&surface->in_transfer_func->tf_pts,
1972 &srf_update->in_transfer_func->tf_pts,
1973 sizeof(struct dc_transfer_func_distributed_points));
1976 if (srf_update->func_shaper &&
1977 (surface->in_shaper_func !=
1978 srf_update->func_shaper))
1979 memcpy(surface->in_shaper_func, srf_update->func_shaper,
1980 sizeof(*surface->in_shaper_func));
1982 if (srf_update->lut3d_func &&
1983 (surface->lut3d_func !=
1984 srf_update->lut3d_func))
1985 memcpy(surface->lut3d_func, srf_update->lut3d_func,
1986 sizeof(*surface->lut3d_func));
1988 if (srf_update->hdr_mult.value)
1990 srf_update->hdr_mult;
1992 if (srf_update->blend_tf &&
1993 (surface->blend_tf !=
1994 srf_update->blend_tf))
1995 memcpy(surface->blend_tf, srf_update->blend_tf,
1996 sizeof(*surface->blend_tf));
1998 if (srf_update->input_csc_color_matrix)
1999 surface->input_csc_color_matrix =
2000 *srf_update->input_csc_color_matrix;
2002 if (srf_update->coeff_reduction_factor)
2003 surface->coeff_reduction_factor =
2004 *srf_update->coeff_reduction_factor;
2006 if (srf_update->gamut_remap_matrix)
2007 surface->gamut_remap_matrix =
2008 *srf_update->gamut_remap_matrix;
2011 static void copy_stream_update_to_stream(struct dc *dc,
2012 struct dc_state *context,
2013 struct dc_stream_state *stream,
2014 struct dc_stream_update *update)
2016 struct dc_context *dc_ctx = dc->ctx;
2018 if (update == NULL || stream == NULL)
2021 if (update->src.height && update->src.width)
2022 stream->src = update->src;
2024 if (update->dst.height && update->dst.width)
2025 stream->dst = update->dst;
2027 if (update->out_transfer_func &&
2028 stream->out_transfer_func != update->out_transfer_func) {
2029 stream->out_transfer_func->sdr_ref_white_level =
2030 update->out_transfer_func->sdr_ref_white_level;
2031 stream->out_transfer_func->tf = update->out_transfer_func->tf;
2032 stream->out_transfer_func->type =
2033 update->out_transfer_func->type;
2034 memcpy(&stream->out_transfer_func->tf_pts,
2035 &update->out_transfer_func->tf_pts,
2036 sizeof(struct dc_transfer_func_distributed_points));
2039 if (update->hdr_static_metadata)
2040 stream->hdr_static_metadata = *update->hdr_static_metadata;
2042 if (update->abm_level)
2043 stream->abm_level = *update->abm_level;
2045 if (update->periodic_interrupt0)
2046 stream->periodic_interrupt0 = *update->periodic_interrupt0;
2048 if (update->periodic_interrupt1)
2049 stream->periodic_interrupt1 = *update->periodic_interrupt1;
2051 if (update->gamut_remap)
2052 stream->gamut_remap_matrix = *update->gamut_remap;
2054 /* Note: this being updated after mode set is currently not a use case
2055 * however if it arises OCSC would need to be reprogrammed at the
2058 if (update->output_color_space)
2059 stream->output_color_space = *update->output_color_space;
2061 if (update->output_csc_transform)
2062 stream->csc_color_matrix = *update->output_csc_transform;
2064 if (update->vrr_infopacket)
2065 stream->vrr_infopacket = *update->vrr_infopacket;
2067 if (update->dpms_off)
2068 stream->dpms_off = *update->dpms_off;
2070 if (update->vsc_infopacket)
2071 stream->vsc_infopacket = *update->vsc_infopacket;
2073 if (update->vsp_infopacket)
2074 stream->vsp_infopacket = *update->vsp_infopacket;
2076 if (update->dither_option)
2077 stream->dither_option = *update->dither_option;
2078 /* update current stream with writeback info */
2079 if (update->wb_update) {
2082 stream->num_wb_info = update->wb_update->num_wb_info;
2083 ASSERT(stream->num_wb_info <= MAX_DWB_PIPES);
2084 for (i = 0; i < stream->num_wb_info; i++)
2085 stream->writeback_info[i] =
2086 update->wb_update->writeback_info[i];
2088 if (update->dsc_config) {
2089 struct dc_dsc_config old_dsc_cfg = stream->timing.dsc_cfg;
2090 uint32_t old_dsc_enabled = stream->timing.flags.DSC;
2091 uint32_t enable_dsc = (update->dsc_config->num_slices_h != 0 &&
2092 update->dsc_config->num_slices_v != 0);
2094 /* Use temporarry context for validating new DSC config */
2095 struct dc_state *dsc_validate_context = dc_create_state(dc);
2097 if (dsc_validate_context) {
2098 dc_resource_state_copy_construct(dc->current_state, dsc_validate_context);
2100 stream->timing.dsc_cfg = *update->dsc_config;
2101 stream->timing.flags.DSC = enable_dsc;
2102 if (!dc->res_pool->funcs->validate_bandwidth(dc, dsc_validate_context, true)) {
2103 stream->timing.dsc_cfg = old_dsc_cfg;
2104 stream->timing.flags.DSC = old_dsc_enabled;
2105 update->dsc_config = NULL;
2108 dc_release_state(dsc_validate_context);
2110 DC_ERROR("Failed to allocate new validate context for DSC change\n");
2111 update->dsc_config = NULL;
2116 static void commit_planes_do_stream_update(struct dc *dc,
2117 struct dc_stream_state *stream,
2118 struct dc_stream_update *stream_update,
2119 enum surface_update_type update_type,
2120 struct dc_state *context)
2123 bool should_program_abm;
2126 for (j = 0; j < dc->res_pool->pipe_count; j++) {
2127 struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[j];
2129 if (!pipe_ctx->top_pipe && !pipe_ctx->prev_odm_pipe && pipe_ctx->stream == stream) {
2131 if (stream_update->periodic_interrupt0 &&
2132 dc->hwss.setup_periodic_interrupt)
2133 dc->hwss.setup_periodic_interrupt(dc, pipe_ctx, VLINE0);
2135 if (stream_update->periodic_interrupt1 &&
2136 dc->hwss.setup_periodic_interrupt)
2137 dc->hwss.setup_periodic_interrupt(dc, pipe_ctx, VLINE1);
2139 if ((stream_update->hdr_static_metadata && !stream->use_dynamic_meta) ||
2140 stream_update->vrr_infopacket ||
2141 stream_update->vsc_infopacket ||
2142 stream_update->vsp_infopacket) {
2143 resource_build_info_frame(pipe_ctx);
2144 dc->hwss.update_info_frame(pipe_ctx);
2147 if (stream_update->hdr_static_metadata &&
2148 stream->use_dynamic_meta &&
2149 dc->hwss.set_dmdata_attributes &&
2150 pipe_ctx->stream->dmdata_address.quad_part != 0)
2151 dc->hwss.set_dmdata_attributes(pipe_ctx);
2153 if (stream_update->gamut_remap)
2154 dc_stream_set_gamut_remap(dc, stream);
2156 if (stream_update->output_csc_transform)
2157 dc_stream_program_csc_matrix(dc, stream);
2159 if (stream_update->dither_option) {
2160 struct pipe_ctx *odm_pipe = pipe_ctx->next_odm_pipe;
2161 resource_build_bit_depth_reduction_params(pipe_ctx->stream,
2162 &pipe_ctx->stream->bit_depth_params);
2163 pipe_ctx->stream_res.opp->funcs->opp_program_fmt(pipe_ctx->stream_res.opp,
2164 &stream->bit_depth_params,
2167 odm_pipe->stream_res.opp->funcs->opp_program_fmt(odm_pipe->stream_res.opp,
2168 &stream->bit_depth_params,
2170 odm_pipe = odm_pipe->next_odm_pipe;
2175 if (update_type == UPDATE_TYPE_FAST)
2178 if (stream_update->dsc_config)
2179 dp_update_dsc_config(pipe_ctx);
2181 if (stream_update->dpms_off) {
2182 if (*stream_update->dpms_off) {
2183 core_link_disable_stream(pipe_ctx);
2184 /* for dpms, keep acquired resources*/
2185 if (pipe_ctx->stream_res.audio && !dc->debug.az_endpoint_mute_only)
2186 pipe_ctx->stream_res.audio->funcs->az_disable(pipe_ctx->stream_res.audio);
2188 dc->hwss.optimize_bandwidth(dc, dc->current_state);
2190 if (dc->optimize_seamless_boot_streams == 0)
2191 dc->hwss.prepare_bandwidth(dc, dc->current_state);
2193 core_link_enable_stream(dc->current_state, pipe_ctx);
2197 if (stream_update->abm_level && pipe_ctx->stream_res.abm) {
2198 should_program_abm = true;
2200 // if otg funcs defined check if blanked before programming
2201 if (pipe_ctx->stream_res.tg->funcs->is_blanked)
2202 if (pipe_ctx->stream_res.tg->funcs->is_blanked(pipe_ctx->stream_res.tg))
2203 should_program_abm = false;
2205 if (should_program_abm) {
2206 if (*stream_update->abm_level == ABM_LEVEL_IMMEDIATE_DISABLE) {
2207 pipe_ctx->stream_res.abm->funcs->set_abm_immediate_disable(pipe_ctx->stream_res.abm);
2209 pipe_ctx->stream_res.abm->funcs->set_abm_level(
2210 pipe_ctx->stream_res.abm, stream->abm_level);
2218 static void commit_planes_for_stream(struct dc *dc,
2219 struct dc_surface_update *srf_updates,
2221 struct dc_stream_state *stream,
2222 struct dc_stream_update *stream_update,
2223 enum surface_update_type update_type,
2224 struct dc_state *context)
2227 struct pipe_ctx *top_pipe_to_program = NULL;
2229 if (dc->optimize_seamless_boot_streams > 0 && surface_count > 0) {
2230 /* Optimize seamless boot flag keeps clocks and watermarks high until
2231 * first flip. After first flip, optimization is required to lower
2232 * bandwidth. Important to note that it is expected UEFI will
2233 * only light up a single display on POST, therefore we only expect
2234 * one stream with seamless boot flag set.
2236 if (stream->apply_seamless_boot_optimization) {
2237 stream->apply_seamless_boot_optimization = false;
2238 dc->optimize_seamless_boot_streams--;
2240 if (dc->optimize_seamless_boot_streams == 0)
2241 dc->optimized_required = true;
2245 if (update_type == UPDATE_TYPE_FULL && dc->optimize_seamless_boot_streams == 0) {
2246 dc->hwss.prepare_bandwidth(dc, context);
2247 context_clock_trace(dc, context);
2250 for (j = 0; j < dc->res_pool->pipe_count; j++) {
2251 struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[j];
2253 if (!pipe_ctx->top_pipe &&
2254 !pipe_ctx->prev_odm_pipe &&
2256 pipe_ctx->stream == stream) {
2257 top_pipe_to_program = pipe_ctx;
2261 if ((update_type != UPDATE_TYPE_FAST) && stream->update_flags.bits.dsc_changed)
2262 if (top_pipe_to_program->stream_res.tg->funcs->lock_doublebuffer_enable)
2263 top_pipe_to_program->stream_res.tg->funcs->lock_doublebuffer_enable(
2264 top_pipe_to_program->stream_res.tg);
2266 if ((update_type != UPDATE_TYPE_FAST) && dc->hwss.interdependent_update_lock)
2267 dc->hwss.interdependent_update_lock(dc, context, true);
2269 /* Lock the top pipe while updating plane addrs, since freesync requires
2270 * plane addr update event triggers to be synchronized.
2271 * top_pipe_to_program is expected to never be NULL
2273 dc->hwss.pipe_control_lock(dc, top_pipe_to_program, true);
2278 commit_planes_do_stream_update(dc, stream, stream_update, update_type, context);
2280 if (surface_count == 0) {
2282 * In case of turning off screen, no need to program front end a second time.
2283 * just return after program blank.
2285 if (dc->hwss.apply_ctx_for_surface)
2286 dc->hwss.apply_ctx_for_surface(dc, stream, 0, context);
2287 if (dc->hwss.program_front_end_for_ctx)
2288 dc->hwss.program_front_end_for_ctx(dc, context);
2290 if ((update_type != UPDATE_TYPE_FAST) && dc->hwss.interdependent_update_lock)
2291 dc->hwss.interdependent_update_lock(dc, context, false);
2293 dc->hwss.pipe_control_lock(dc, top_pipe_to_program, false);
2295 dc->hwss.post_unlock_program_front_end(dc, context);
2299 if (!IS_DIAG_DC(dc->ctx->dce_environment)) {
2300 for (i = 0; i < surface_count; i++) {
2301 struct dc_plane_state *plane_state = srf_updates[i].surface;
2302 /*set logical flag for lock/unlock use*/
2303 for (j = 0; j < dc->res_pool->pipe_count; j++) {
2304 struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[j];
2305 if (!pipe_ctx->plane_state)
2307 if (pipe_ctx->plane_state != plane_state)
2309 plane_state->triplebuffer_flips = false;
2310 if (update_type == UPDATE_TYPE_FAST &&
2311 dc->hwss.program_triplebuffer != NULL &&
2312 !plane_state->flip_immediate &&
2313 !dc->debug.disable_tri_buf) {
2314 /*triple buffer for VUpdate only*/
2315 plane_state->triplebuffer_flips = true;
2321 // Update Type FULL, Surface updates
2322 for (j = 0; j < dc->res_pool->pipe_count; j++) {
2323 struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[j];
2325 if (!pipe_ctx->top_pipe &&
2326 !pipe_ctx->prev_odm_pipe &&
2328 pipe_ctx->stream == stream) {
2329 struct dc_stream_status *stream_status = NULL;
2331 if (!pipe_ctx->plane_state)
2335 if (update_type == UPDATE_TYPE_FAST)
2338 ASSERT(!pipe_ctx->plane_state->triplebuffer_flips);
2340 if (dc->hwss.program_triplebuffer != NULL &&
2341 !dc->debug.disable_tri_buf) {
2342 /*turn off triple buffer for full update*/
2343 dc->hwss.program_triplebuffer(
2344 dc, pipe_ctx, pipe_ctx->plane_state->triplebuffer_flips);
2347 stream_get_status(context, pipe_ctx->stream);
2349 if (dc->hwss.apply_ctx_for_surface)
2350 dc->hwss.apply_ctx_for_surface(
2351 dc, pipe_ctx->stream, stream_status->plane_count, context);
2354 if (dc->hwss.program_front_end_for_ctx && update_type != UPDATE_TYPE_FAST) {
2355 dc->hwss.program_front_end_for_ctx(dc, context);
2356 #ifdef CONFIG_DRM_AMD_DC_DCN
2357 if (dc->debug.validate_dml_output) {
2358 for (i = 0; i < dc->res_pool->pipe_count; i++) {
2359 struct pipe_ctx cur_pipe = context->res_ctx.pipe_ctx[i];
2360 if (cur_pipe.stream == NULL)
2363 cur_pipe.plane_res.hubp->funcs->validate_dml_output(
2364 cur_pipe.plane_res.hubp, dc->ctx,
2365 &context->res_ctx.pipe_ctx[i].rq_regs,
2366 &context->res_ctx.pipe_ctx[i].dlg_regs,
2367 &context->res_ctx.pipe_ctx[i].ttu_regs);
2373 // Update Type FAST, Surface updates
2374 if (update_type == UPDATE_TYPE_FAST) {
2375 if (dc->hwss.set_flip_control_gsl)
2376 for (i = 0; i < surface_count; i++) {
2377 struct dc_plane_state *plane_state = srf_updates[i].surface;
2379 for (j = 0; j < dc->res_pool->pipe_count; j++) {
2380 struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[j];
2382 if (pipe_ctx->stream != stream)
2385 if (pipe_ctx->plane_state != plane_state)
2388 // GSL has to be used for flip immediate
2389 dc->hwss.set_flip_control_gsl(pipe_ctx,
2390 plane_state->flip_immediate);
2393 /* Perform requested Updates */
2394 for (i = 0; i < surface_count; i++) {
2395 struct dc_plane_state *plane_state = srf_updates[i].surface;
2397 for (j = 0; j < dc->res_pool->pipe_count; j++) {
2398 struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[j];
2400 if (pipe_ctx->stream != stream)
2403 if (pipe_ctx->plane_state != plane_state)
2405 /*program triple buffer after lock based on flip type*/
2406 if (dc->hwss.program_triplebuffer != NULL &&
2407 !dc->debug.disable_tri_buf) {
2408 /*only enable triplebuffer for fast_update*/
2409 dc->hwss.program_triplebuffer(
2410 dc, pipe_ctx, plane_state->triplebuffer_flips);
2412 if (srf_updates[i].flip_addr)
2413 dc->hwss.update_plane_addr(dc, pipe_ctx);
2418 if ((update_type != UPDATE_TYPE_FAST) && dc->hwss.interdependent_update_lock)
2419 dc->hwss.interdependent_update_lock(dc, context, false);
2421 dc->hwss.pipe_control_lock(dc, top_pipe_to_program, false);
2423 if ((update_type != UPDATE_TYPE_FAST) && stream->update_flags.bits.dsc_changed)
2424 if (top_pipe_to_program->stream_res.tg->funcs->lock_doublebuffer_enable) {
2425 top_pipe_to_program->stream_res.tg->funcs->wait_for_state(
2426 top_pipe_to_program->stream_res.tg,
2427 CRTC_STATE_VACTIVE);
2428 top_pipe_to_program->stream_res.tg->funcs->wait_for_state(
2429 top_pipe_to_program->stream_res.tg,
2431 top_pipe_to_program->stream_res.tg->funcs->wait_for_state(
2432 top_pipe_to_program->stream_res.tg,
2433 CRTC_STATE_VACTIVE);
2434 top_pipe_to_program->stream_res.tg->funcs->lock_doublebuffer_disable(
2435 top_pipe_to_program->stream_res.tg);
2438 if (update_type != UPDATE_TYPE_FAST)
2439 dc->hwss.post_unlock_program_front_end(dc, context);
2441 // Fire manual trigger only when bottom plane is flipped
2442 for (j = 0; j < dc->res_pool->pipe_count; j++) {
2443 struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[j];
2445 if (pipe_ctx->bottom_pipe ||
2446 !pipe_ctx->stream ||
2447 pipe_ctx->stream != stream ||
2448 !pipe_ctx->plane_state->update_flags.bits.addr_update)
2451 if (pipe_ctx->stream_res.tg->funcs->program_manual_trigger)
2452 pipe_ctx->stream_res.tg->funcs->program_manual_trigger(pipe_ctx->stream_res.tg);
2456 void dc_commit_updates_for_stream(struct dc *dc,
2457 struct dc_surface_update *srf_updates,
2459 struct dc_stream_state *stream,
2460 struct dc_stream_update *stream_update,
2461 struct dc_state *state)
2463 const struct dc_stream_status *stream_status;
2464 enum surface_update_type update_type;
2465 struct dc_state *context;
2466 struct dc_context *dc_ctx = dc->ctx;
2469 stream_status = dc_stream_get_status(stream);
2470 context = dc->current_state;
2472 update_type = dc_check_update_surfaces_for_stream(
2473 dc, srf_updates, surface_count, stream_update, stream_status);
2475 if (update_type >= update_surface_trace_level)
2476 update_surface_trace(dc, srf_updates, surface_count);
2479 if (update_type >= UPDATE_TYPE_FULL) {
2481 /* initialize scratch memory for building context */
2482 context = dc_create_state(dc);
2483 if (context == NULL) {
2484 DC_ERROR("Failed to allocate new validate context!\n");
2488 dc_resource_state_copy_construct(state, context);
2490 for (i = 0; i < dc->res_pool->pipe_count; i++) {
2491 struct pipe_ctx *new_pipe = &context->res_ctx.pipe_ctx[i];
2492 struct pipe_ctx *old_pipe = &dc->current_state->res_ctx.pipe_ctx[i];
2494 if (new_pipe->plane_state && new_pipe->plane_state != old_pipe->plane_state)
2495 new_pipe->plane_state->force_full_update = true;
2500 for (i = 0; i < surface_count; i++) {
2501 struct dc_plane_state *surface = srf_updates[i].surface;
2503 copy_surface_update_to_plane(surface, &srf_updates[i]);
2505 if (update_type >= UPDATE_TYPE_MED) {
2506 for (j = 0; j < dc->res_pool->pipe_count; j++) {
2507 struct pipe_ctx *pipe_ctx =
2508 &context->res_ctx.pipe_ctx[j];
2510 if (pipe_ctx->plane_state != surface)
2513 resource_build_scaling_params(pipe_ctx);
2518 copy_stream_update_to_stream(dc, context, stream, stream_update);
2520 commit_planes_for_stream(
2528 /*update current_State*/
2529 if (dc->current_state != context) {
2531 struct dc_state *old = dc->current_state;
2533 dc->current_state = context;
2534 dc_release_state(old);
2536 for (i = 0; i < dc->res_pool->pipe_count; i++) {
2537 struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[i];
2539 if (pipe_ctx->plane_state && pipe_ctx->stream == stream)
2540 pipe_ctx->plane_state->force_full_update = false;
2543 /*let's use current_state to update watermark etc*/
2544 if (update_type >= UPDATE_TYPE_FULL)
2545 dc_post_update_surfaces_to_stream(dc);
2551 uint8_t dc_get_current_stream_count(struct dc *dc)
2553 return dc->current_state->stream_count;
2556 struct dc_stream_state *dc_get_stream_at_index(struct dc *dc, uint8_t i)
2558 if (i < dc->current_state->stream_count)
2559 return dc->current_state->streams[i];
2563 enum dc_irq_source dc_interrupt_to_irq_source(
2568 return dal_irq_service_to_irq_source(dc->res_pool->irqs, src_id, ext_id);
2572 * dc_interrupt_set() - Enable/disable an AMD hw interrupt source
2574 bool dc_interrupt_set(struct dc *dc, enum dc_irq_source src, bool enable)
2580 return dal_irq_service_set(dc->res_pool->irqs, src, enable);
2583 void dc_interrupt_ack(struct dc *dc, enum dc_irq_source src)
2585 dal_irq_service_ack(dc->res_pool->irqs, src);
2588 void dc_set_power_state(
2590 enum dc_acpi_cm_power_state power_state)
2592 struct kref refcount;
2593 struct display_mode_lib *dml;
2595 switch (power_state) {
2596 case DC_ACPI_CM_POWER_STATE_D0:
2597 dc_resource_state_construct(dc, dc->current_state);
2599 if (dc->ctx->dmub_srv)
2600 dc_dmub_srv_wait_phy_init(dc->ctx->dmub_srv);
2602 dc->hwss.init_hw(dc);
2604 if (dc->hwss.init_sys_ctx != NULL &&
2605 dc->vm_pa_config.valid) {
2606 dc->hwss.init_sys_ctx(dc->hwseq, dc, &dc->vm_pa_config);
2611 ASSERT(dc->current_state->stream_count == 0);
2612 /* Zero out the current context so that on resume we start with
2613 * clean state, and dc hw programming optimizations will not
2614 * cause any trouble.
2616 dml = kzalloc(sizeof(struct display_mode_lib),
2623 /* Preserve refcount */
2624 refcount = dc->current_state->refcount;
2625 /* Preserve display mode lib */
2626 memcpy(dml, &dc->current_state->bw_ctx.dml, sizeof(struct display_mode_lib));
2628 dc_resource_state_destruct(dc->current_state);
2629 memset(dc->current_state, 0,
2630 sizeof(*dc->current_state));
2632 dc->current_state->refcount = refcount;
2633 dc->current_state->bw_ctx.dml = *dml;
2641 void dc_resume(struct dc *dc)
2646 for (i = 0; i < dc->link_count; i++)
2647 core_link_resume(dc->links[i]);
2650 unsigned int dc_get_current_backlight_pwm(struct dc *dc)
2652 struct abm *abm = dc->res_pool->abm;
2655 return abm->funcs->get_current_backlight(abm);
2660 unsigned int dc_get_target_backlight_pwm(struct dc *dc)
2662 struct abm *abm = dc->res_pool->abm;
2665 return abm->funcs->get_target_backlight(abm);
2670 bool dc_is_dmcu_initialized(struct dc *dc)
2672 struct dmcu *dmcu = dc->res_pool->dmcu;
2675 return dmcu->funcs->is_dmcu_initialized(dmcu);
2681 uint32_t link_index,
2682 struct i2c_command *cmd)
2685 struct dc_link *link = dc->links[link_index];
2686 struct ddc_service *ddc = link->ddc;
2687 return dce_i2c_submit_command(
2693 bool dc_submit_i2c_oem(
2695 struct i2c_command *cmd)
2697 struct ddc_service *ddc = dc->res_pool->oem_device;
2698 return dce_i2c_submit_command(
2704 static bool link_add_remote_sink_helper(struct dc_link *dc_link, struct dc_sink *sink)
2706 if (dc_link->sink_count >= MAX_SINKS_PER_LINK) {
2707 BREAK_TO_DEBUGGER();
2711 dc_sink_retain(sink);
2713 dc_link->remote_sinks[dc_link->sink_count] = sink;
2714 dc_link->sink_count++;
2720 * dc_link_add_remote_sink() - Create a sink and attach it to an existing link
2722 * EDID length is in bytes
2724 struct dc_sink *dc_link_add_remote_sink(
2725 struct dc_link *link,
2726 const uint8_t *edid,
2728 struct dc_sink_init_data *init_data)
2730 struct dc_sink *dc_sink;
2731 enum dc_edid_status edid_status;
2733 if (len > DC_MAX_EDID_BUFFER_SIZE) {
2734 dm_error("Max EDID buffer size breached!\n");
2739 BREAK_TO_DEBUGGER();
2743 if (!init_data->link) {
2744 BREAK_TO_DEBUGGER();
2748 dc_sink = dc_sink_create(init_data);
2753 memmove(dc_sink->dc_edid.raw_edid, edid, len);
2754 dc_sink->dc_edid.length = len;
2756 if (!link_add_remote_sink_helper(
2761 edid_status = dm_helpers_parse_edid_caps(
2764 &dc_sink->edid_caps);
2767 * Treat device as no EDID device if EDID
2770 if (edid_status != EDID_OK) {
2771 dc_sink->dc_edid.length = 0;
2772 dm_error("Bad EDID, status%d!\n", edid_status);
2778 dc_sink_release(dc_sink);
2783 * dc_link_remove_remote_sink() - Remove a remote sink from a dc_link
2785 * Note that this just removes the struct dc_sink - it doesn't
2786 * program hardware or alter other members of dc_link
2788 void dc_link_remove_remote_sink(struct dc_link *link, struct dc_sink *sink)
2792 if (!link->sink_count) {
2793 BREAK_TO_DEBUGGER();
2797 for (i = 0; i < link->sink_count; i++) {
2798 if (link->remote_sinks[i] == sink) {
2799 dc_sink_release(sink);
2800 link->remote_sinks[i] = NULL;
2802 /* shrink array to remove empty place */
2803 while (i < link->sink_count - 1) {
2804 link->remote_sinks[i] = link->remote_sinks[i+1];
2807 link->remote_sinks[i] = NULL;
2814 void get_clock_requirements_for_state(struct dc_state *state, struct AsicStateEx *info)
2816 info->displayClock = (unsigned int)state->bw_ctx.bw.dcn.clk.dispclk_khz;
2817 info->engineClock = (unsigned int)state->bw_ctx.bw.dcn.clk.dcfclk_khz;
2818 info->memoryClock = (unsigned int)state->bw_ctx.bw.dcn.clk.dramclk_khz;
2819 info->maxSupportedDppClock = (unsigned int)state->bw_ctx.bw.dcn.clk.max_supported_dppclk_khz;
2820 info->dppClock = (unsigned int)state->bw_ctx.bw.dcn.clk.dppclk_khz;
2821 info->socClock = (unsigned int)state->bw_ctx.bw.dcn.clk.socclk_khz;
2822 info->dcfClockDeepSleep = (unsigned int)state->bw_ctx.bw.dcn.clk.dcfclk_deep_sleep_khz;
2823 info->fClock = (unsigned int)state->bw_ctx.bw.dcn.clk.fclk_khz;
2824 info->phyClock = (unsigned int)state->bw_ctx.bw.dcn.clk.phyclk_khz;
2826 enum dc_status dc_set_clock(struct dc *dc, enum dc_clock_type clock_type, uint32_t clk_khz, uint32_t stepping)
2828 if (dc->hwss.set_clock)
2829 return dc->hwss.set_clock(dc, clock_type, clk_khz, stepping);
2830 return DC_ERROR_UNEXPECTED;
2832 void dc_get_clock(struct dc *dc, enum dc_clock_type clock_type, struct dc_clock_config *clock_cfg)
2834 if (dc->hwss.get_clock)
2835 dc->hwss.get_clock(dc, clock_type, clock_cfg);