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 for (i = 0; i < MAX_PIPES; i++) {
287 struct pipe_ctx *pipe = &dc->current_state->res_ctx.pipe_ctx[i];
289 if (pipe->stream == stream && pipe->stream_res.tg) {
290 dc->hwss.set_drr(&pipe,
295 adjust->v_total_mid_frame_num);
303 bool dc_stream_get_crtc_position(struct dc *dc,
304 struct dc_stream_state **streams, int num_streams,
305 unsigned int *v_pos, unsigned int *nom_v_pos)
307 /* TODO: Support multiple streams */
308 const struct dc_stream_state *stream = streams[0];
311 struct crtc_position position;
313 for (i = 0; i < MAX_PIPES; i++) {
314 struct pipe_ctx *pipe =
315 &dc->current_state->res_ctx.pipe_ctx[i];
317 if (pipe->stream == stream && pipe->stream_res.stream_enc) {
318 dc->hwss.get_position(&pipe, 1, &position);
320 *v_pos = position.vertical_count;
321 *nom_v_pos = position.nominal_vcount;
329 * dc_stream_configure_crc() - Configure CRC capture for the given stream.
331 * @stream: The stream to configure CRC on.
332 * @enable: Enable CRC if true, disable otherwise.
333 * @continuous: Capture CRC on every frame if true. Otherwise, only capture
336 * By default, only CRC0 is configured, and the entire frame is used to
339 bool dc_stream_configure_crc(struct dc *dc, struct dc_stream_state *stream,
340 bool enable, bool continuous)
343 struct pipe_ctx *pipe;
344 struct crc_params param;
345 struct timing_generator *tg;
347 for (i = 0; i < MAX_PIPES; i++) {
348 pipe = &dc->current_state->res_ctx.pipe_ctx[i];
349 if (pipe->stream == stream)
352 /* Stream not found */
356 /* Always capture the full frame */
357 param.windowa_x_start = 0;
358 param.windowa_y_start = 0;
359 param.windowa_x_end = pipe->stream->timing.h_addressable;
360 param.windowa_y_end = pipe->stream->timing.v_addressable;
361 param.windowb_x_start = 0;
362 param.windowb_y_start = 0;
363 param.windowb_x_end = pipe->stream->timing.h_addressable;
364 param.windowb_y_end = pipe->stream->timing.v_addressable;
366 /* Default to the union of both windows */
367 param.selection = UNION_WINDOW_A_B;
368 param.continuous_mode = continuous;
369 param.enable = enable;
371 tg = pipe->stream_res.tg;
373 /* Only call if supported */
374 if (tg->funcs->configure_crc)
375 return tg->funcs->configure_crc(tg, ¶m);
376 DC_LOG_WARNING("CRC capture not supported.");
381 * dc_stream_get_crc() - Get CRC values for the given stream.
383 * @stream: The DC stream state of the stream to get CRCs from.
384 * @r_cr, g_y, b_cb: CRC values for the three channels are stored here.
386 * dc_stream_configure_crc needs to be called beforehand to enable CRCs.
387 * Return false if stream is not found, or if CRCs are not enabled.
389 bool dc_stream_get_crc(struct dc *dc, struct dc_stream_state *stream,
390 uint32_t *r_cr, uint32_t *g_y, uint32_t *b_cb)
393 struct pipe_ctx *pipe;
394 struct timing_generator *tg;
396 for (i = 0; i < MAX_PIPES; i++) {
397 pipe = &dc->current_state->res_ctx.pipe_ctx[i];
398 if (pipe->stream == stream)
401 /* Stream not found */
405 tg = pipe->stream_res.tg;
407 if (tg->funcs->get_crc)
408 return tg->funcs->get_crc(tg, r_cr, g_y, b_cb);
409 DC_LOG_WARNING("CRC capture not supported.");
413 void dc_stream_set_dyn_expansion(struct dc *dc, struct dc_stream_state *stream,
414 enum dc_dynamic_expansion option)
416 /* OPP FMT dyn expansion updates*/
418 struct pipe_ctx *pipe_ctx;
420 for (i = 0; i < MAX_PIPES; i++) {
421 if (dc->current_state->res_ctx.pipe_ctx[i].stream
423 pipe_ctx = &dc->current_state->res_ctx.pipe_ctx[i];
424 pipe_ctx->stream_res.opp->dyn_expansion = option;
425 pipe_ctx->stream_res.opp->funcs->opp_set_dyn_expansion(
426 pipe_ctx->stream_res.opp,
427 COLOR_SPACE_YCBCR601,
428 stream->timing.display_color_depth,
434 void dc_stream_set_dither_option(struct dc_stream_state *stream,
435 enum dc_dither_option option)
437 struct bit_depth_reduction_params params;
438 struct dc_link *link = stream->link;
439 struct pipe_ctx *pipes = NULL;
442 for (i = 0; i < MAX_PIPES; i++) {
443 if (link->dc->current_state->res_ctx.pipe_ctx[i].stream ==
445 pipes = &link->dc->current_state->res_ctx.pipe_ctx[i];
452 if (option > DITHER_OPTION_MAX)
455 stream->dither_option = option;
457 memset(¶ms, 0, sizeof(params));
458 resource_build_bit_depth_reduction_params(stream, ¶ms);
459 stream->bit_depth_params = params;
461 if (pipes->plane_res.xfm &&
462 pipes->plane_res.xfm->funcs->transform_set_pixel_storage_depth) {
463 pipes->plane_res.xfm->funcs->transform_set_pixel_storage_depth(
464 pipes->plane_res.xfm,
465 pipes->plane_res.scl_data.lb_params.depth,
466 &stream->bit_depth_params);
469 pipes->stream_res.opp->funcs->
470 opp_program_bit_depth_reduction(pipes->stream_res.opp, ¶ms);
473 bool dc_stream_set_gamut_remap(struct dc *dc, const struct dc_stream_state *stream)
477 struct pipe_ctx *pipes;
479 for (i = 0; i < MAX_PIPES; i++) {
480 if (dc->current_state->res_ctx.pipe_ctx[i].stream == stream) {
481 pipes = &dc->current_state->res_ctx.pipe_ctx[i];
482 dc->hwss.program_gamut_remap(pipes);
490 bool dc_stream_program_csc_matrix(struct dc *dc, struct dc_stream_state *stream)
494 struct pipe_ctx *pipes;
496 for (i = 0; i < MAX_PIPES; i++) {
497 if (dc->current_state->res_ctx.pipe_ctx[i].stream
500 pipes = &dc->current_state->res_ctx.pipe_ctx[i];
501 dc->hwss.program_output_csc(dc,
503 stream->output_color_space,
504 stream->csc_color_matrix.matrix,
505 pipes->stream_res.opp->inst);
513 void dc_stream_set_static_screen_params(struct dc *dc,
514 struct dc_stream_state **streams,
516 const struct dc_static_screen_params *params)
520 struct pipe_ctx *pipes_affected[MAX_PIPES];
521 int num_pipes_affected = 0;
523 for (i = 0; i < num_streams; i++) {
524 struct dc_stream_state *stream = streams[i];
526 for (j = 0; j < MAX_PIPES; j++) {
527 if (dc->current_state->res_ctx.pipe_ctx[j].stream
529 pipes_affected[num_pipes_affected++] =
530 &dc->current_state->res_ctx.pipe_ctx[j];
535 dc->hwss.set_static_screen_control(pipes_affected, num_pipes_affected, params);
538 static void dc_destruct(struct dc *dc)
540 if (dc->current_state) {
541 dc_release_state(dc->current_state);
542 dc->current_state = NULL;
548 dc_destroy_clk_mgr(dc->clk_mgr);
552 dc_destroy_resource_pool(dc);
554 if (dc->ctx->gpio_service)
555 dal_gpio_service_destroy(&dc->ctx->gpio_service);
557 if (dc->ctx->created_bios)
558 dal_bios_parser_destroy(&dc->ctx->dc_bios);
560 dc_perf_trace_destroy(&dc->ctx->perf_trace);
571 #ifdef CONFIG_DRM_AMD_DC_DCN
579 kfree(dc->vm_helper);
580 dc->vm_helper = NULL;
584 static bool dc_construct_ctx(struct dc *dc,
585 const struct dc_init_data *init_params)
587 struct dc_context *dc_ctx;
588 enum dce_version dc_version = DCE_VERSION_UNKNOWN;
590 dc_ctx = kzalloc(sizeof(*dc_ctx), GFP_KERNEL);
594 dc_ctx->cgs_device = init_params->cgs_device;
595 dc_ctx->driver_context = init_params->driver;
597 dc_ctx->asic_id = init_params->asic_id;
598 dc_ctx->dc_sink_id_count = 0;
599 dc_ctx->dc_stream_id_count = 0;
600 dc_ctx->dce_environment = init_params->dce_environment;
604 dc_version = resource_parse_asic_id(init_params->asic_id);
605 dc_ctx->dce_version = dc_version;
607 dc_ctx->perf_trace = dc_perf_trace_create();
608 if (!dc_ctx->perf_trace) {
609 ASSERT_CRITICAL(false);
618 static bool dc_construct(struct dc *dc,
619 const struct dc_init_data *init_params)
621 struct dc_context *dc_ctx;
622 struct bw_calcs_dceip *dc_dceip;
623 struct bw_calcs_vbios *dc_vbios;
624 #ifdef CONFIG_DRM_AMD_DC_DCN
625 struct dcn_soc_bounding_box *dcn_soc;
626 struct dcn_ip_params *dcn_ip;
629 dc->config = init_params->flags;
631 // Allocate memory for the vm_helper
632 dc->vm_helper = kzalloc(sizeof(struct vm_helper), GFP_KERNEL);
633 if (!dc->vm_helper) {
634 dm_error("%s: failed to create dc->vm_helper\n", __func__);
638 memcpy(&dc->bb_overrides, &init_params->bb_overrides, sizeof(dc->bb_overrides));
640 dc_dceip = kzalloc(sizeof(*dc_dceip), GFP_KERNEL);
642 dm_error("%s: failed to create dceip\n", __func__);
646 dc->bw_dceip = dc_dceip;
648 dc_vbios = kzalloc(sizeof(*dc_vbios), GFP_KERNEL);
650 dm_error("%s: failed to create vbios\n", __func__);
654 dc->bw_vbios = dc_vbios;
655 #ifdef CONFIG_DRM_AMD_DC_DCN
656 dcn_soc = kzalloc(sizeof(*dcn_soc), GFP_KERNEL);
658 dm_error("%s: failed to create dcn_soc\n", __func__);
662 dc->dcn_soc = dcn_soc;
664 dcn_ip = kzalloc(sizeof(*dcn_ip), GFP_KERNEL);
666 dm_error("%s: failed to create dcn_ip\n", __func__);
671 dc->soc_bounding_box = init_params->soc_bounding_box;
674 if (!dc_construct_ctx(dc, init_params)) {
675 dm_error("%s: failed to create ctx\n", __func__);
681 /* Resource should construct all asic specific resources.
682 * This should be the only place where we need to parse the asic id
684 if (init_params->vbios_override)
685 dc_ctx->dc_bios = init_params->vbios_override;
687 /* Create BIOS parser */
688 struct bp_init_data bp_init_data;
690 bp_init_data.ctx = dc_ctx;
691 bp_init_data.bios = init_params->asic_id.atombios_base_address;
693 dc_ctx->dc_bios = dal_bios_parser_create(
694 &bp_init_data, dc_ctx->dce_version);
696 if (!dc_ctx->dc_bios) {
697 ASSERT_CRITICAL(false);
701 dc_ctx->created_bios = true;
704 dc->vendor_signature = init_params->vendor_signature;
706 /* Create GPIO service */
707 dc_ctx->gpio_service = dal_gpio_service_create(
709 dc_ctx->dce_environment,
712 if (!dc_ctx->gpio_service) {
713 ASSERT_CRITICAL(false);
717 dc->res_pool = dc_create_resource_pool(dc, init_params, dc_ctx->dce_version);
721 dc->clk_mgr = dc_clk_mgr_create(dc->ctx, dc->res_pool->pp_smu, dc->res_pool->dccg);
725 if (dc->res_pool->funcs->update_bw_bounding_box)
726 dc->res_pool->funcs->update_bw_bounding_box(dc, dc->clk_mgr->bw_params);
728 /* Creation of current_state must occur after dc->dml
729 * is initialized in dc_create_resource_pool because
730 * on creation it copies the contents of dc->dml
733 dc->current_state = dc_create_state(dc);
735 if (!dc->current_state) {
736 dm_error("%s: failed to create validate ctx\n", __func__);
740 dc_resource_state_construct(dc, dc->current_state);
742 if (!create_links(dc, init_params->num_virtual_links))
751 static bool disable_all_writeback_pipes_for_stream(
753 struct dc_stream_state *stream,
754 struct dc_state *context)
758 for (i = 0; i < stream->num_wb_info; i++)
759 stream->writeback_info[i].wb_enabled = false;
764 void apply_ctx_interdependent_lock(struct dc *dc, struct dc_state *context, struct dc_stream_state *stream, bool lock)
768 /* Checks if interdependent update function pointer is NULL or not, takes care of DCE110 case */
769 if (dc->hwss.interdependent_update_lock)
770 dc->hwss.interdependent_update_lock(dc, context, lock);
772 for (i = 0; i < dc->res_pool->pipe_count; i++) {
773 struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[i];
774 struct pipe_ctx *old_pipe_ctx = &dc->current_state->res_ctx.pipe_ctx[i];
776 // Copied conditions that were previously in dce110_apply_ctx_for_surface
777 if (stream == pipe_ctx->stream) {
778 if (!pipe_ctx->top_pipe &&
779 (pipe_ctx->plane_state || old_pipe_ctx->plane_state))
780 dc->hwss.pipe_control_lock(dc, pipe_ctx, lock);
786 static void disable_dangling_plane(struct dc *dc, struct dc_state *context)
789 struct dc_state *dangling_context = dc_create_state(dc);
790 struct dc_state *current_ctx;
792 if (dangling_context == NULL)
795 dc_resource_state_copy_construct(dc->current_state, dangling_context);
797 for (i = 0; i < dc->res_pool->pipe_count; i++) {
798 struct dc_stream_state *old_stream =
799 dc->current_state->res_ctx.pipe_ctx[i].stream;
800 bool should_disable = true;
802 for (j = 0; j < context->stream_count; j++) {
803 if (old_stream == context->streams[j]) {
804 should_disable = false;
808 if (should_disable && old_stream) {
809 dc_rem_all_planes_for_stream(dc, old_stream, dangling_context);
810 disable_all_writeback_pipes_for_stream(dc, old_stream, dangling_context);
812 if (dc->hwss.apply_ctx_for_surface) {
813 apply_ctx_interdependent_lock(dc, dc->current_state, old_stream, true);
814 dc->hwss.apply_ctx_for_surface(dc, old_stream, 0, dangling_context);
815 apply_ctx_interdependent_lock(dc, dc->current_state, old_stream, false);
816 dc->hwss.post_unlock_program_front_end(dc, dangling_context);
818 if (dc->hwss.program_front_end_for_ctx) {
819 dc->hwss.interdependent_update_lock(dc, dc->current_state, true);
820 dc->hwss.program_front_end_for_ctx(dc, dangling_context);
821 dc->hwss.interdependent_update_lock(dc, dc->current_state, false);
822 dc->hwss.post_unlock_program_front_end(dc, dangling_context);
827 current_ctx = dc->current_state;
828 dc->current_state = dangling_context;
829 dc_release_state(current_ctx);
832 static void wait_for_no_pipes_pending(struct dc *dc, struct dc_state *context)
836 struct pipe_ctx *pipe;
838 for (i = 0; i < MAX_PIPES; i++) {
839 pipe = &context->res_ctx.pipe_ctx[i];
841 if (!pipe->plane_state)
845 while (count < 100000) {
846 /* Must set to false to start with, due to OR in update function */
847 pipe->plane_state->status.is_flip_pending = false;
848 dc->hwss.update_pending_status(pipe);
849 if (!pipe->plane_state->status.is_flip_pending)
854 ASSERT(!pipe->plane_state->status.is_flip_pending);
859 /*******************************************************************************
861 ******************************************************************************/
863 struct dc *dc_create(const struct dc_init_data *init_params)
865 struct dc *dc = kzalloc(sizeof(*dc), GFP_KERNEL);
866 unsigned int full_pipe_count;
871 if (init_params->dce_environment == DCE_ENV_VIRTUAL_HW) {
872 if (false == dc_construct_ctx(dc, init_params)) {
877 if (false == dc_construct(dc, init_params)) {
882 full_pipe_count = dc->res_pool->pipe_count;
883 if (dc->res_pool->underlay_pipe_index != NO_UNDERLAY_PIPE)
885 dc->caps.max_streams = min(
887 dc->res_pool->stream_enc_count);
889 dc->optimize_seamless_boot_streams = 0;
890 dc->caps.max_links = dc->link_count;
891 dc->caps.max_audios = dc->res_pool->audio_count;
892 dc->caps.linear_pitch_alignment = 64;
894 dc->caps.max_dp_protocol_version = DP_VERSION_1_4;
896 if (dc->res_pool->dmcu != NULL)
897 dc->versions.dmcu_version = dc->res_pool->dmcu->dmcu_version;
900 /* Populate versioning information */
901 dc->versions.dc_ver = DC_VER;
903 dc->build_id = DC_BUILD_ID;
905 DC_LOG_DC("Display Core initialized\n");
918 void dc_hardware_init(struct dc *dc)
920 if (dc->ctx->dce_environment != DCE_ENV_VIRTUAL_HW)
921 dc->hwss.init_hw(dc);
924 void dc_init_callbacks(struct dc *dc,
925 const struct dc_callback_init *init_params)
927 #ifdef CONFIG_DRM_AMD_DC_HDCP
928 dc->ctx->cp_psp = init_params->cp_psp;
932 void dc_deinit_callbacks(struct dc *dc)
934 #ifdef CONFIG_DRM_AMD_DC_HDCP
935 memset(&dc->ctx->cp_psp, 0, sizeof(dc->ctx->cp_psp));
939 void dc_destroy(struct dc **dc)
946 static void enable_timing_multisync(
948 struct dc_state *ctx)
950 int i = 0, multisync_count = 0;
951 int pipe_count = dc->res_pool->pipe_count;
952 struct pipe_ctx *multisync_pipes[MAX_PIPES] = { NULL };
954 for (i = 0; i < pipe_count; i++) {
955 if (!ctx->res_ctx.pipe_ctx[i].stream ||
956 !ctx->res_ctx.pipe_ctx[i].stream->triggered_crtc_reset.enabled)
958 if (ctx->res_ctx.pipe_ctx[i].stream == ctx->res_ctx.pipe_ctx[i].stream->triggered_crtc_reset.event_source)
960 multisync_pipes[multisync_count] = &ctx->res_ctx.pipe_ctx[i];
964 if (multisync_count > 0) {
965 dc->hwss.enable_per_frame_crtc_position_reset(
966 dc, multisync_count, multisync_pipes);
970 static void program_timing_sync(
972 struct dc_state *ctx)
977 int pipe_count = dc->res_pool->pipe_count;
978 struct pipe_ctx *unsynced_pipes[MAX_PIPES] = { NULL };
980 for (i = 0; i < pipe_count; i++) {
981 if (!ctx->res_ctx.pipe_ctx[i].stream || ctx->res_ctx.pipe_ctx[i].top_pipe)
984 unsynced_pipes[i] = &ctx->res_ctx.pipe_ctx[i];
987 for (i = 0; i < pipe_count; i++) {
989 struct pipe_ctx *pipe_set[MAX_PIPES];
991 if (!unsynced_pipes[i])
994 pipe_set[0] = unsynced_pipes[i];
995 unsynced_pipes[i] = NULL;
997 /* Add tg to the set, search rest of the tg's for ones with
998 * same timing, add all tgs with same timing to the group
1000 for (j = i + 1; j < pipe_count; j++) {
1001 if (!unsynced_pipes[j])
1004 if (resource_are_streams_timing_synchronizable(
1005 unsynced_pipes[j]->stream,
1006 pipe_set[0]->stream)) {
1007 pipe_set[group_size] = unsynced_pipes[j];
1008 unsynced_pipes[j] = NULL;
1013 /* set first pipe with plane as master */
1014 for (j = 0; j < group_size; j++) {
1015 if (pipe_set[j]->plane_state) {
1019 swap(pipe_set[0], pipe_set[j]);
1025 for (k = 0; k < group_size; k++) {
1026 struct dc_stream_status *status = dc_stream_get_status_from_state(ctx, pipe_set[k]->stream);
1028 status->timing_sync_info.group_id = num_group;
1029 status->timing_sync_info.group_size = group_size;
1031 status->timing_sync_info.master = true;
1033 status->timing_sync_info.master = false;
1036 /* remove any other pipes with plane as they have already been synced */
1037 for (j = j + 1; j < group_size; j++) {
1038 if (pipe_set[j]->plane_state) {
1040 pipe_set[j] = pipe_set[group_size];
1045 if (group_size > 1) {
1046 dc->hwss.enable_timing_synchronization(
1047 dc, group_index, group_size, pipe_set);
1054 static bool context_changed(
1056 struct dc_state *context)
1060 if (context->stream_count != dc->current_state->stream_count)
1063 for (i = 0; i < dc->current_state->stream_count; i++) {
1064 if (dc->current_state->streams[i] != context->streams[i])
1071 bool dc_validate_seamless_boot_timing(const struct dc *dc,
1072 const struct dc_sink *sink,
1073 struct dc_crtc_timing *crtc_timing)
1075 struct timing_generator *tg;
1076 struct stream_encoder *se = NULL;
1078 struct dc_crtc_timing hw_crtc_timing = {0};
1080 struct dc_link *link = sink->link;
1081 unsigned int i, enc_inst, tg_inst = 0;
1083 // Seamless port only support single DP and EDP so far
1084 if (sink->sink_signal != SIGNAL_TYPE_DISPLAY_PORT &&
1085 sink->sink_signal != SIGNAL_TYPE_EDP)
1088 /* Check for enabled DIG to identify enabled display */
1089 if (!link->link_enc->funcs->is_dig_enabled(link->link_enc))
1092 enc_inst = link->link_enc->funcs->get_dig_frontend(link->link_enc);
1094 if (enc_inst == ENGINE_ID_UNKNOWN)
1097 for (i = 0; i < dc->res_pool->stream_enc_count; i++) {
1098 if (dc->res_pool->stream_enc[i]->id == enc_inst) {
1100 se = dc->res_pool->stream_enc[i];
1102 tg_inst = dc->res_pool->stream_enc[i]->funcs->dig_source_otg(
1103 dc->res_pool->stream_enc[i]);
1108 // tg_inst not found
1109 if (i == dc->res_pool->stream_enc_count)
1112 if (tg_inst >= dc->res_pool->timing_generator_count)
1115 tg = dc->res_pool->timing_generators[tg_inst];
1117 if (!tg->funcs->get_hw_timing)
1120 if (!tg->funcs->get_hw_timing(tg, &hw_crtc_timing))
1123 if (crtc_timing->h_total != hw_crtc_timing.h_total)
1126 if (crtc_timing->h_border_left != hw_crtc_timing.h_border_left)
1129 if (crtc_timing->h_addressable != hw_crtc_timing.h_addressable)
1132 if (crtc_timing->h_border_right != hw_crtc_timing.h_border_right)
1135 if (crtc_timing->h_front_porch != hw_crtc_timing.h_front_porch)
1138 if (crtc_timing->h_sync_width != hw_crtc_timing.h_sync_width)
1141 if (crtc_timing->v_total != hw_crtc_timing.v_total)
1144 if (crtc_timing->v_border_top != hw_crtc_timing.v_border_top)
1147 if (crtc_timing->v_addressable != hw_crtc_timing.v_addressable)
1150 if (crtc_timing->v_border_bottom != hw_crtc_timing.v_border_bottom)
1153 if (crtc_timing->v_front_porch != hw_crtc_timing.v_front_porch)
1156 if (crtc_timing->v_sync_width != hw_crtc_timing.v_sync_width)
1159 if (dc_is_dp_signal(link->connector_signal)) {
1160 unsigned int pix_clk_100hz;
1162 dc->res_pool->dp_clock_source->funcs->get_pixel_clk_frequency_100hz(
1163 dc->res_pool->dp_clock_source,
1164 tg_inst, &pix_clk_100hz);
1166 if (crtc_timing->pix_clk_100hz != pix_clk_100hz)
1169 if (!se->funcs->dp_get_pixel_format)
1172 if (!se->funcs->dp_get_pixel_format(
1174 &hw_crtc_timing.pixel_encoding,
1175 &hw_crtc_timing.display_color_depth))
1178 if (hw_crtc_timing.display_color_depth != crtc_timing->display_color_depth)
1181 if (hw_crtc_timing.pixel_encoding != crtc_timing->pixel_encoding)
1188 bool dc_enable_stereo(
1190 struct dc_state *context,
1191 struct dc_stream_state *streams[],
1192 uint8_t stream_count)
1196 struct pipe_ctx *pipe;
1198 for (i = 0; i < MAX_PIPES; i++) {
1199 if (context != NULL)
1200 pipe = &context->res_ctx.pipe_ctx[i];
1202 pipe = &dc->current_state->res_ctx.pipe_ctx[i];
1203 for (j = 0 ; pipe && j < stream_count; j++) {
1204 if (streams[j] && streams[j] == pipe->stream &&
1205 dc->hwss.setup_stereo)
1206 dc->hwss.setup_stereo(pipe, dc);
1214 * Applies given context to HW and copy it into current context.
1215 * It's up to the user to release the src context afterwards.
1217 static enum dc_status dc_commit_state_no_check(struct dc *dc, struct dc_state *context)
1219 struct dc_bios *dcb = dc->ctx->dc_bios;
1220 enum dc_status result = DC_ERROR_UNEXPECTED;
1221 struct pipe_ctx *pipe;
1223 struct dc_stream_state *dc_streams[MAX_STREAMS] = {0};
1225 disable_dangling_plane(dc, context);
1227 for (i = 0; i < context->stream_count; i++)
1228 dc_streams[i] = context->streams[i];
1230 if (!dcb->funcs->is_accelerated_mode(dcb))
1231 dc->hwss.enable_accelerated_mode(dc, context);
1233 for (i = 0; i < context->stream_count; i++) {
1234 if (context->streams[i]->apply_seamless_boot_optimization)
1235 dc->optimize_seamless_boot_streams++;
1238 if (dc->optimize_seamless_boot_streams == 0)
1239 dc->hwss.prepare_bandwidth(dc, context);
1241 /* re-program planes for existing stream, in case we need to
1242 * free up plane resource for later use
1244 if (dc->hwss.apply_ctx_for_surface) {
1245 for (i = 0; i < context->stream_count; i++) {
1246 if (context->streams[i]->mode_changed)
1248 apply_ctx_interdependent_lock(dc, context, context->streams[i], true);
1249 dc->hwss.apply_ctx_for_surface(
1250 dc, context->streams[i],
1251 context->stream_status[i].plane_count,
1252 context); /* use new pipe config in new context */
1253 apply_ctx_interdependent_lock(dc, context, context->streams[i], false);
1254 dc->hwss.post_unlock_program_front_end(dc, context);
1258 /* Program hardware */
1259 for (i = 0; i < dc->res_pool->pipe_count; i++) {
1260 pipe = &context->res_ctx.pipe_ctx[i];
1261 dc->hwss.wait_for_mpcc_disconnect(dc, dc->res_pool, pipe);
1264 result = dc->hwss.apply_ctx_to_hw(dc, context);
1266 if (result != DC_OK)
1269 if (context->stream_count > 1 && !dc->debug.disable_timing_sync) {
1270 enable_timing_multisync(dc, context);
1271 program_timing_sync(dc, context);
1274 /* Program all planes within new context*/
1275 if (dc->hwss.program_front_end_for_ctx) {
1276 dc->hwss.interdependent_update_lock(dc, context, true);
1277 dc->hwss.program_front_end_for_ctx(dc, context);
1278 dc->hwss.interdependent_update_lock(dc, context, false);
1279 dc->hwss.post_unlock_program_front_end(dc, context);
1281 for (i = 0; i < context->stream_count; i++) {
1282 const struct dc_link *link = context->streams[i]->link;
1284 if (!context->streams[i]->mode_changed)
1287 if (dc->hwss.apply_ctx_for_surface) {
1288 apply_ctx_interdependent_lock(dc, context, context->streams[i], true);
1289 dc->hwss.apply_ctx_for_surface(
1290 dc, context->streams[i],
1291 context->stream_status[i].plane_count,
1293 apply_ctx_interdependent_lock(dc, context, context->streams[i], false);
1294 dc->hwss.post_unlock_program_front_end(dc, context);
1299 * TODO rework dc_enable_stereo call to work with validation sets?
1301 for (k = 0; k < MAX_PIPES; k++) {
1302 pipe = &context->res_ctx.pipe_ctx[k];
1304 for (l = 0 ; pipe && l < context->stream_count; l++) {
1305 if (context->streams[l] &&
1306 context->streams[l] == pipe->stream &&
1307 dc->hwss.setup_stereo)
1308 dc->hwss.setup_stereo(pipe, dc);
1312 CONN_MSG_MODE(link, "{%dx%d, %dx%d@%dKhz}",
1313 context->streams[i]->timing.h_addressable,
1314 context->streams[i]->timing.v_addressable,
1315 context->streams[i]->timing.h_total,
1316 context->streams[i]->timing.v_total,
1317 context->streams[i]->timing.pix_clk_100hz / 10);
1320 dc_enable_stereo(dc, context, dc_streams, context->stream_count);
1322 if (dc->optimize_seamless_boot_streams == 0) {
1323 /* Must wait for no flips to be pending before doing optimize bw */
1324 wait_for_no_pipes_pending(dc, context);
1325 /* pplib is notified if disp_num changed */
1326 dc->hwss.optimize_bandwidth(dc, context);
1329 for (i = 0; i < context->stream_count; i++)
1330 context->streams[i]->mode_changed = false;
1332 dc_release_state(dc->current_state);
1334 dc->current_state = context;
1336 dc_retain_state(dc->current_state);
1341 bool dc_commit_state(struct dc *dc, struct dc_state *context)
1343 enum dc_status result = DC_ERROR_UNEXPECTED;
1346 if (false == context_changed(dc, context))
1349 DC_LOG_DC("%s: %d streams\n",
1350 __func__, context->stream_count);
1352 for (i = 0; i < context->stream_count; i++) {
1353 struct dc_stream_state *stream = context->streams[i];
1355 dc_stream_log(dc, stream);
1358 result = dc_commit_state_no_check(dc, context);
1360 return (result == DC_OK);
1363 static bool is_flip_pending_in_pipes(struct dc *dc, struct dc_state *context)
1366 struct pipe_ctx *pipe;
1368 for (i = 0; i < MAX_PIPES; i++) {
1369 pipe = &context->res_ctx.pipe_ctx[i];
1371 if (!pipe->plane_state)
1374 /* Must set to false to start with, due to OR in update function */
1375 pipe->plane_state->status.is_flip_pending = false;
1376 dc->hwss.update_pending_status(pipe);
1377 if (pipe->plane_state->status.is_flip_pending)
1383 bool dc_post_update_surfaces_to_stream(struct dc *dc)
1386 struct dc_state *context = dc->current_state;
1388 if ((!dc->optimized_required) || dc->optimize_seamless_boot_streams > 0)
1391 post_surface_trace(dc);
1393 if (is_flip_pending_in_pipes(dc, context))
1396 for (i = 0; i < dc->res_pool->pipe_count; i++)
1397 if (context->res_ctx.pipe_ctx[i].stream == NULL ||
1398 context->res_ctx.pipe_ctx[i].plane_state == NULL) {
1399 context->res_ctx.pipe_ctx[i].pipe_idx = i;
1400 dc->hwss.disable_plane(dc, &context->res_ctx.pipe_ctx[i]);
1403 dc->hwss.optimize_bandwidth(dc, context);
1405 dc->optimized_required = false;
1406 dc->wm_optimized_required = false;
1411 struct dc_state *dc_create_state(struct dc *dc)
1413 struct dc_state *context = kvzalloc(sizeof(struct dc_state),
1418 /* Each context must have their own instance of VBA and in order to
1419 * initialize and obtain IP and SOC the base DML instance from DC is
1420 * initially copied into every context
1422 #ifdef CONFIG_DRM_AMD_DC_DCN
1423 memcpy(&context->bw_ctx.dml, &dc->dml, sizeof(struct display_mode_lib));
1426 kref_init(&context->refcount);
1431 struct dc_state *dc_copy_state(struct dc_state *src_ctx)
1434 struct dc_state *new_ctx = kvmalloc(sizeof(struct dc_state), GFP_KERNEL);
1438 memcpy(new_ctx, src_ctx, sizeof(struct dc_state));
1440 for (i = 0; i < MAX_PIPES; i++) {
1441 struct pipe_ctx *cur_pipe = &new_ctx->res_ctx.pipe_ctx[i];
1443 if (cur_pipe->top_pipe)
1444 cur_pipe->top_pipe = &new_ctx->res_ctx.pipe_ctx[cur_pipe->top_pipe->pipe_idx];
1446 if (cur_pipe->bottom_pipe)
1447 cur_pipe->bottom_pipe = &new_ctx->res_ctx.pipe_ctx[cur_pipe->bottom_pipe->pipe_idx];
1449 if (cur_pipe->prev_odm_pipe)
1450 cur_pipe->prev_odm_pipe = &new_ctx->res_ctx.pipe_ctx[cur_pipe->prev_odm_pipe->pipe_idx];
1452 if (cur_pipe->next_odm_pipe)
1453 cur_pipe->next_odm_pipe = &new_ctx->res_ctx.pipe_ctx[cur_pipe->next_odm_pipe->pipe_idx];
1457 for (i = 0; i < new_ctx->stream_count; i++) {
1458 dc_stream_retain(new_ctx->streams[i]);
1459 for (j = 0; j < new_ctx->stream_status[i].plane_count; j++)
1460 dc_plane_state_retain(
1461 new_ctx->stream_status[i].plane_states[j]);
1464 kref_init(&new_ctx->refcount);
1469 void dc_retain_state(struct dc_state *context)
1471 kref_get(&context->refcount);
1474 static void dc_state_free(struct kref *kref)
1476 struct dc_state *context = container_of(kref, struct dc_state, refcount);
1477 dc_resource_state_destruct(context);
1481 void dc_release_state(struct dc_state *context)
1483 kref_put(&context->refcount, dc_state_free);
1486 bool dc_set_generic_gpio_for_stereo(bool enable,
1487 struct gpio_service *gpio_service)
1489 enum gpio_result gpio_result = GPIO_RESULT_NON_SPECIFIC_ERROR;
1490 struct gpio_pin_info pin_info;
1491 struct gpio *generic;
1492 struct gpio_generic_mux_config *config = kzalloc(sizeof(struct gpio_generic_mux_config),
1497 pin_info = dal_gpio_get_generic_pin_info(gpio_service, GPIO_ID_GENERIC, 0);
1499 if (pin_info.mask == 0xFFFFFFFF || pin_info.offset == 0xFFFFFFFF) {
1503 generic = dal_gpio_service_create_generic_mux(
1514 gpio_result = dal_gpio_open(generic, GPIO_MODE_OUTPUT);
1516 config->enable_output_from_mux = enable;
1517 config->mux_select = GPIO_SIGNAL_SOURCE_PASS_THROUGH_STEREO_SYNC;
1519 if (gpio_result == GPIO_RESULT_OK)
1520 gpio_result = dal_mux_setup_config(generic, config);
1522 if (gpio_result == GPIO_RESULT_OK) {
1523 dal_gpio_close(generic);
1524 dal_gpio_destroy_generic_mux(&generic);
1528 dal_gpio_close(generic);
1529 dal_gpio_destroy_generic_mux(&generic);
1535 static bool is_surface_in_context(
1536 const struct dc_state *context,
1537 const struct dc_plane_state *plane_state)
1541 for (j = 0; j < MAX_PIPES; j++) {
1542 const struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[j];
1544 if (plane_state == pipe_ctx->plane_state) {
1552 static enum surface_update_type get_plane_info_update_type(const struct dc_surface_update *u)
1554 union surface_update_flags *update_flags = &u->surface->update_flags;
1555 enum surface_update_type update_type = UPDATE_TYPE_FAST;
1558 return UPDATE_TYPE_FAST;
1560 if (u->plane_info->color_space != u->surface->color_space) {
1561 update_flags->bits.color_space_change = 1;
1562 elevate_update_type(&update_type, UPDATE_TYPE_MED);
1565 if (u->plane_info->horizontal_mirror != u->surface->horizontal_mirror) {
1566 update_flags->bits.horizontal_mirror_change = 1;
1567 elevate_update_type(&update_type, UPDATE_TYPE_MED);
1570 if (u->plane_info->rotation != u->surface->rotation) {
1571 update_flags->bits.rotation_change = 1;
1572 elevate_update_type(&update_type, UPDATE_TYPE_FULL);
1575 if (u->plane_info->format != u->surface->format) {
1576 update_flags->bits.pixel_format_change = 1;
1577 elevate_update_type(&update_type, UPDATE_TYPE_FULL);
1580 if (u->plane_info->stereo_format != u->surface->stereo_format) {
1581 update_flags->bits.stereo_format_change = 1;
1582 elevate_update_type(&update_type, UPDATE_TYPE_FULL);
1585 if (u->plane_info->per_pixel_alpha != u->surface->per_pixel_alpha) {
1586 update_flags->bits.per_pixel_alpha_change = 1;
1587 elevate_update_type(&update_type, UPDATE_TYPE_MED);
1590 if (u->plane_info->global_alpha_value != u->surface->global_alpha_value) {
1591 update_flags->bits.global_alpha_change = 1;
1592 elevate_update_type(&update_type, UPDATE_TYPE_MED);
1595 if (u->plane_info->dcc.enable != u->surface->dcc.enable
1596 || u->plane_info->dcc.independent_64b_blks != u->surface->dcc.independent_64b_blks
1597 || u->plane_info->dcc.meta_pitch != u->surface->dcc.meta_pitch) {
1598 update_flags->bits.dcc_change = 1;
1599 elevate_update_type(&update_type, UPDATE_TYPE_MED);
1602 if (resource_pixel_format_to_bpp(u->plane_info->format) !=
1603 resource_pixel_format_to_bpp(u->surface->format)) {
1604 /* different bytes per element will require full bandwidth
1605 * and DML calculation
1607 update_flags->bits.bpp_change = 1;
1608 elevate_update_type(&update_type, UPDATE_TYPE_FULL);
1611 if (u->plane_info->plane_size.surface_pitch != u->surface->plane_size.surface_pitch
1612 || u->plane_info->plane_size.chroma_pitch != u->surface->plane_size.chroma_pitch) {
1613 update_flags->bits.plane_size_change = 1;
1614 elevate_update_type(&update_type, UPDATE_TYPE_MED);
1618 if (memcmp(&u->plane_info->tiling_info, &u->surface->tiling_info,
1619 sizeof(union dc_tiling_info)) != 0) {
1620 update_flags->bits.swizzle_change = 1;
1621 elevate_update_type(&update_type, UPDATE_TYPE_MED);
1623 /* todo: below are HW dependent, we should add a hook to
1624 * DCE/N resource and validated there.
1626 if (u->plane_info->tiling_info.gfx9.swizzle != DC_SW_LINEAR) {
1627 /* swizzled mode requires RQ to be setup properly,
1628 * thus need to run DML to calculate RQ settings
1630 update_flags->bits.bandwidth_change = 1;
1631 elevate_update_type(&update_type, UPDATE_TYPE_FULL);
1635 /* This should be UPDATE_TYPE_FAST if nothing has changed. */
1639 static enum surface_update_type get_scaling_info_update_type(
1640 const struct dc_surface_update *u)
1642 union surface_update_flags *update_flags = &u->surface->update_flags;
1644 if (!u->scaling_info)
1645 return UPDATE_TYPE_FAST;
1647 if (u->scaling_info->clip_rect.width != u->surface->clip_rect.width
1648 || u->scaling_info->clip_rect.height != u->surface->clip_rect.height
1649 || u->scaling_info->dst_rect.width != u->surface->dst_rect.width
1650 || u->scaling_info->dst_rect.height != u->surface->dst_rect.height
1651 || u->scaling_info->scaling_quality.integer_scaling !=
1652 u->surface->scaling_quality.integer_scaling
1654 update_flags->bits.scaling_change = 1;
1656 if ((u->scaling_info->dst_rect.width < u->surface->dst_rect.width
1657 || u->scaling_info->dst_rect.height < u->surface->dst_rect.height)
1658 && (u->scaling_info->dst_rect.width < u->surface->src_rect.width
1659 || u->scaling_info->dst_rect.height < u->surface->src_rect.height))
1660 /* Making dst rect smaller requires a bandwidth change */
1661 update_flags->bits.bandwidth_change = 1;
1664 if (u->scaling_info->src_rect.width != u->surface->src_rect.width
1665 || u->scaling_info->src_rect.height != u->surface->src_rect.height) {
1667 update_flags->bits.scaling_change = 1;
1668 if (u->scaling_info->src_rect.width > u->surface->src_rect.width
1669 || u->scaling_info->src_rect.height > u->surface->src_rect.height)
1670 /* Making src rect bigger requires a bandwidth change */
1671 update_flags->bits.clock_change = 1;
1674 if (u->scaling_info->src_rect.x != u->surface->src_rect.x
1675 || u->scaling_info->src_rect.y != u->surface->src_rect.y
1676 || u->scaling_info->clip_rect.x != u->surface->clip_rect.x
1677 || u->scaling_info->clip_rect.y != u->surface->clip_rect.y
1678 || u->scaling_info->dst_rect.x != u->surface->dst_rect.x
1679 || u->scaling_info->dst_rect.y != u->surface->dst_rect.y)
1680 update_flags->bits.position_change = 1;
1682 if (update_flags->bits.clock_change
1683 || update_flags->bits.bandwidth_change
1684 || update_flags->bits.scaling_change)
1685 return UPDATE_TYPE_FULL;
1687 if (update_flags->bits.position_change)
1688 return UPDATE_TYPE_MED;
1690 return UPDATE_TYPE_FAST;
1693 static enum surface_update_type det_surface_update(const struct dc *dc,
1694 const struct dc_surface_update *u)
1696 const struct dc_state *context = dc->current_state;
1697 enum surface_update_type type;
1698 enum surface_update_type overall_type = UPDATE_TYPE_FAST;
1699 union surface_update_flags *update_flags = &u->surface->update_flags;
1702 update_flags->bits.addr_update = 1;
1704 if (!is_surface_in_context(context, u->surface) || u->surface->force_full_update) {
1705 update_flags->raw = 0xFFFFFFFF;
1706 return UPDATE_TYPE_FULL;
1709 update_flags->raw = 0; // Reset all flags
1711 type = get_plane_info_update_type(u);
1712 elevate_update_type(&overall_type, type);
1714 type = get_scaling_info_update_type(u);
1715 elevate_update_type(&overall_type, type);
1718 update_flags->bits.addr_update = 1;
1720 if (u->in_transfer_func)
1721 update_flags->bits.in_transfer_func_change = 1;
1723 if (u->input_csc_color_matrix)
1724 update_flags->bits.input_csc_change = 1;
1726 if (u->coeff_reduction_factor)
1727 update_flags->bits.coeff_reduction_change = 1;
1729 if (u->gamut_remap_matrix)
1730 update_flags->bits.gamut_remap_change = 1;
1733 enum surface_pixel_format format = SURFACE_PIXEL_FORMAT_GRPH_BEGIN;
1736 format = u->plane_info->format;
1737 else if (u->surface)
1738 format = u->surface->format;
1740 if (dce_use_lut(format))
1741 update_flags->bits.gamma_change = 1;
1744 if (u->hdr_mult.value)
1745 if (u->hdr_mult.value != u->surface->hdr_mult.value) {
1746 update_flags->bits.hdr_mult = 1;
1747 elevate_update_type(&overall_type, UPDATE_TYPE_MED);
1750 if (update_flags->bits.in_transfer_func_change) {
1751 type = UPDATE_TYPE_MED;
1752 elevate_update_type(&overall_type, type);
1755 if (update_flags->bits.input_csc_change
1756 || update_flags->bits.coeff_reduction_change
1757 || update_flags->bits.gamma_change
1758 || update_flags->bits.gamut_remap_change) {
1759 type = UPDATE_TYPE_FULL;
1760 elevate_update_type(&overall_type, type);
1763 return overall_type;
1766 static enum surface_update_type check_update_surfaces_for_stream(
1768 struct dc_surface_update *updates,
1770 struct dc_stream_update *stream_update,
1771 const struct dc_stream_status *stream_status)
1774 enum surface_update_type overall_type = UPDATE_TYPE_FAST;
1776 if (stream_status == NULL || stream_status->plane_count != surface_count)
1777 overall_type = UPDATE_TYPE_FULL;
1779 /* some stream updates require passive update */
1780 if (stream_update) {
1781 union stream_update_flags *su_flags = &stream_update->stream->update_flags;
1783 if ((stream_update->src.height != 0 && stream_update->src.width != 0) ||
1784 (stream_update->dst.height != 0 && stream_update->dst.width != 0) ||
1785 stream_update->integer_scaling_update)
1786 su_flags->bits.scaling = 1;
1788 if (stream_update->out_transfer_func)
1789 su_flags->bits.out_tf = 1;
1791 if (stream_update->abm_level)
1792 su_flags->bits.abm_level = 1;
1794 if (stream_update->dpms_off)
1795 su_flags->bits.dpms_off = 1;
1797 if (stream_update->gamut_remap)
1798 su_flags->bits.gamut_remap = 1;
1800 if (stream_update->wb_update)
1801 su_flags->bits.wb_update = 1;
1803 if (stream_update->dsc_config)
1804 su_flags->bits.dsc_changed = 1;
1806 if (su_flags->raw != 0)
1807 overall_type = UPDATE_TYPE_FULL;
1809 if (stream_update->output_csc_transform || stream_update->output_color_space)
1810 su_flags->bits.out_csc = 1;
1813 for (i = 0 ; i < surface_count; i++) {
1814 enum surface_update_type type =
1815 det_surface_update(dc, &updates[i]);
1817 elevate_update_type(&overall_type, type);
1820 return overall_type;
1824 * dc_check_update_surfaces_for_stream() - Determine update type (fast, med, or full)
1826 * See :c:type:`enum surface_update_type <surface_update_type>` for explanation of update types
1828 enum surface_update_type dc_check_update_surfaces_for_stream(
1830 struct dc_surface_update *updates,
1832 struct dc_stream_update *stream_update,
1833 const struct dc_stream_status *stream_status)
1836 enum surface_update_type type;
1839 stream_update->stream->update_flags.raw = 0;
1840 for (i = 0; i < surface_count; i++)
1841 updates[i].surface->update_flags.raw = 0;
1843 type = check_update_surfaces_for_stream(dc, updates, surface_count, stream_update, stream_status);
1844 if (type == UPDATE_TYPE_FULL) {
1845 if (stream_update) {
1846 uint32_t dsc_changed = stream_update->stream->update_flags.bits.dsc_changed;
1847 stream_update->stream->update_flags.raw = 0xFFFFFFFF;
1848 stream_update->stream->update_flags.bits.dsc_changed = dsc_changed;
1850 for (i = 0; i < surface_count; i++)
1851 updates[i].surface->update_flags.raw = 0xFFFFFFFF;
1854 if (type == UPDATE_TYPE_FAST) {
1855 // If there's an available clock comparator, we use that.
1856 if (dc->clk_mgr->funcs->are_clock_states_equal) {
1857 if (!dc->clk_mgr->funcs->are_clock_states_equal(&dc->clk_mgr->clks, &dc->current_state->bw_ctx.bw.dcn.clk))
1858 dc->optimized_required = true;
1859 // Else we fallback to mem compare.
1860 } 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) {
1861 dc->optimized_required = true;
1862 } else if (dc->wm_optimized_required)
1863 dc->optimized_required = true;
1869 static struct dc_stream_status *stream_get_status(
1870 struct dc_state *ctx,
1871 struct dc_stream_state *stream)
1875 for (i = 0; i < ctx->stream_count; i++) {
1876 if (stream == ctx->streams[i]) {
1877 return &ctx->stream_status[i];
1884 static const enum surface_update_type update_surface_trace_level = UPDATE_TYPE_FULL;
1886 static void copy_surface_update_to_plane(
1887 struct dc_plane_state *surface,
1888 struct dc_surface_update *srf_update)
1890 if (srf_update->flip_addr) {
1891 surface->address = srf_update->flip_addr->address;
1892 surface->flip_immediate =
1893 srf_update->flip_addr->flip_immediate;
1894 surface->time.time_elapsed_in_us[surface->time.index] =
1895 srf_update->flip_addr->flip_timestamp_in_us -
1896 surface->time.prev_update_time_in_us;
1897 surface->time.prev_update_time_in_us =
1898 srf_update->flip_addr->flip_timestamp_in_us;
1899 surface->time.index++;
1900 if (surface->time.index >= DC_PLANE_UPDATE_TIMES_MAX)
1901 surface->time.index = 0;
1903 surface->triplebuffer_flips = srf_update->flip_addr->triplebuffer_flips;
1906 if (srf_update->scaling_info) {
1907 surface->scaling_quality =
1908 srf_update->scaling_info->scaling_quality;
1910 srf_update->scaling_info->dst_rect;
1912 srf_update->scaling_info->src_rect;
1913 surface->clip_rect =
1914 srf_update->scaling_info->clip_rect;
1917 if (srf_update->plane_info) {
1918 surface->color_space =
1919 srf_update->plane_info->color_space;
1921 srf_update->plane_info->format;
1922 surface->plane_size =
1923 srf_update->plane_info->plane_size;
1925 srf_update->plane_info->rotation;
1926 surface->horizontal_mirror =
1927 srf_update->plane_info->horizontal_mirror;
1928 surface->stereo_format =
1929 srf_update->plane_info->stereo_format;
1930 surface->tiling_info =
1931 srf_update->plane_info->tiling_info;
1933 srf_update->plane_info->visible;
1934 surface->per_pixel_alpha =
1935 srf_update->plane_info->per_pixel_alpha;
1936 surface->global_alpha =
1937 srf_update->plane_info->global_alpha;
1938 surface->global_alpha_value =
1939 srf_update->plane_info->global_alpha_value;
1941 srf_update->plane_info->dcc;
1942 surface->layer_index =
1943 srf_update->plane_info->layer_index;
1946 if (srf_update->gamma &&
1947 (surface->gamma_correction !=
1948 srf_update->gamma)) {
1949 memcpy(&surface->gamma_correction->entries,
1950 &srf_update->gamma->entries,
1951 sizeof(struct dc_gamma_entries));
1952 surface->gamma_correction->is_identity =
1953 srf_update->gamma->is_identity;
1954 surface->gamma_correction->num_entries =
1955 srf_update->gamma->num_entries;
1956 surface->gamma_correction->type =
1957 srf_update->gamma->type;
1960 if (srf_update->in_transfer_func &&
1961 (surface->in_transfer_func !=
1962 srf_update->in_transfer_func)) {
1963 surface->in_transfer_func->sdr_ref_white_level =
1964 srf_update->in_transfer_func->sdr_ref_white_level;
1965 surface->in_transfer_func->tf =
1966 srf_update->in_transfer_func->tf;
1967 surface->in_transfer_func->type =
1968 srf_update->in_transfer_func->type;
1969 memcpy(&surface->in_transfer_func->tf_pts,
1970 &srf_update->in_transfer_func->tf_pts,
1971 sizeof(struct dc_transfer_func_distributed_points));
1974 if (srf_update->func_shaper &&
1975 (surface->in_shaper_func !=
1976 srf_update->func_shaper))
1977 memcpy(surface->in_shaper_func, srf_update->func_shaper,
1978 sizeof(*surface->in_shaper_func));
1980 if (srf_update->lut3d_func &&
1981 (surface->lut3d_func !=
1982 srf_update->lut3d_func))
1983 memcpy(surface->lut3d_func, srf_update->lut3d_func,
1984 sizeof(*surface->lut3d_func));
1986 if (srf_update->hdr_mult.value)
1988 srf_update->hdr_mult;
1990 if (srf_update->blend_tf &&
1991 (surface->blend_tf !=
1992 srf_update->blend_tf))
1993 memcpy(surface->blend_tf, srf_update->blend_tf,
1994 sizeof(*surface->blend_tf));
1996 if (srf_update->input_csc_color_matrix)
1997 surface->input_csc_color_matrix =
1998 *srf_update->input_csc_color_matrix;
2000 if (srf_update->coeff_reduction_factor)
2001 surface->coeff_reduction_factor =
2002 *srf_update->coeff_reduction_factor;
2004 if (srf_update->gamut_remap_matrix)
2005 surface->gamut_remap_matrix =
2006 *srf_update->gamut_remap_matrix;
2009 static void copy_stream_update_to_stream(struct dc *dc,
2010 struct dc_state *context,
2011 struct dc_stream_state *stream,
2012 struct dc_stream_update *update)
2014 struct dc_context *dc_ctx = dc->ctx;
2016 if (update == NULL || stream == NULL)
2019 if (update->src.height && update->src.width)
2020 stream->src = update->src;
2022 if (update->dst.height && update->dst.width)
2023 stream->dst = update->dst;
2025 if (update->out_transfer_func &&
2026 stream->out_transfer_func != update->out_transfer_func) {
2027 stream->out_transfer_func->sdr_ref_white_level =
2028 update->out_transfer_func->sdr_ref_white_level;
2029 stream->out_transfer_func->tf = update->out_transfer_func->tf;
2030 stream->out_transfer_func->type =
2031 update->out_transfer_func->type;
2032 memcpy(&stream->out_transfer_func->tf_pts,
2033 &update->out_transfer_func->tf_pts,
2034 sizeof(struct dc_transfer_func_distributed_points));
2037 if (update->hdr_static_metadata)
2038 stream->hdr_static_metadata = *update->hdr_static_metadata;
2040 if (update->abm_level)
2041 stream->abm_level = *update->abm_level;
2043 if (update->periodic_interrupt0)
2044 stream->periodic_interrupt0 = *update->periodic_interrupt0;
2046 if (update->periodic_interrupt1)
2047 stream->periodic_interrupt1 = *update->periodic_interrupt1;
2049 if (update->gamut_remap)
2050 stream->gamut_remap_matrix = *update->gamut_remap;
2052 /* Note: this being updated after mode set is currently not a use case
2053 * however if it arises OCSC would need to be reprogrammed at the
2056 if (update->output_color_space)
2057 stream->output_color_space = *update->output_color_space;
2059 if (update->output_csc_transform)
2060 stream->csc_color_matrix = *update->output_csc_transform;
2062 if (update->vrr_infopacket)
2063 stream->vrr_infopacket = *update->vrr_infopacket;
2065 if (update->dpms_off)
2066 stream->dpms_off = *update->dpms_off;
2068 if (update->vsc_infopacket)
2069 stream->vsc_infopacket = *update->vsc_infopacket;
2071 if (update->vsp_infopacket)
2072 stream->vsp_infopacket = *update->vsp_infopacket;
2074 if (update->dither_option)
2075 stream->dither_option = *update->dither_option;
2076 /* update current stream with writeback info */
2077 if (update->wb_update) {
2080 stream->num_wb_info = update->wb_update->num_wb_info;
2081 ASSERT(stream->num_wb_info <= MAX_DWB_PIPES);
2082 for (i = 0; i < stream->num_wb_info; i++)
2083 stream->writeback_info[i] =
2084 update->wb_update->writeback_info[i];
2086 if (update->dsc_config) {
2087 struct dc_dsc_config old_dsc_cfg = stream->timing.dsc_cfg;
2088 uint32_t old_dsc_enabled = stream->timing.flags.DSC;
2089 uint32_t enable_dsc = (update->dsc_config->num_slices_h != 0 &&
2090 update->dsc_config->num_slices_v != 0);
2092 /* Use temporarry context for validating new DSC config */
2093 struct dc_state *dsc_validate_context = dc_create_state(dc);
2095 if (dsc_validate_context) {
2096 dc_resource_state_copy_construct(dc->current_state, dsc_validate_context);
2098 stream->timing.dsc_cfg = *update->dsc_config;
2099 stream->timing.flags.DSC = enable_dsc;
2100 if (!dc->res_pool->funcs->validate_bandwidth(dc, dsc_validate_context, true)) {
2101 stream->timing.dsc_cfg = old_dsc_cfg;
2102 stream->timing.flags.DSC = old_dsc_enabled;
2103 update->dsc_config = NULL;
2106 dc_release_state(dsc_validate_context);
2108 DC_ERROR("Failed to allocate new validate context for DSC change\n");
2109 update->dsc_config = NULL;
2114 static void commit_planes_do_stream_update(struct dc *dc,
2115 struct dc_stream_state *stream,
2116 struct dc_stream_update *stream_update,
2117 enum surface_update_type update_type,
2118 struct dc_state *context)
2121 bool should_program_abm;
2124 for (j = 0; j < dc->res_pool->pipe_count; j++) {
2125 struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[j];
2127 if (!pipe_ctx->top_pipe && !pipe_ctx->prev_odm_pipe && pipe_ctx->stream == stream) {
2129 if (stream_update->periodic_interrupt0 &&
2130 dc->hwss.setup_periodic_interrupt)
2131 dc->hwss.setup_periodic_interrupt(dc, pipe_ctx, VLINE0);
2133 if (stream_update->periodic_interrupt1 &&
2134 dc->hwss.setup_periodic_interrupt)
2135 dc->hwss.setup_periodic_interrupt(dc, pipe_ctx, VLINE1);
2137 if ((stream_update->hdr_static_metadata && !stream->use_dynamic_meta) ||
2138 stream_update->vrr_infopacket ||
2139 stream_update->vsc_infopacket ||
2140 stream_update->vsp_infopacket) {
2141 resource_build_info_frame(pipe_ctx);
2142 dc->hwss.update_info_frame(pipe_ctx);
2145 if (stream_update->hdr_static_metadata &&
2146 stream->use_dynamic_meta &&
2147 dc->hwss.set_dmdata_attributes &&
2148 pipe_ctx->stream->dmdata_address.quad_part != 0)
2149 dc->hwss.set_dmdata_attributes(pipe_ctx);
2151 if (stream_update->gamut_remap)
2152 dc_stream_set_gamut_remap(dc, stream);
2154 if (stream_update->output_csc_transform)
2155 dc_stream_program_csc_matrix(dc, stream);
2157 if (stream_update->dither_option) {
2158 struct pipe_ctx *odm_pipe = pipe_ctx->next_odm_pipe;
2159 resource_build_bit_depth_reduction_params(pipe_ctx->stream,
2160 &pipe_ctx->stream->bit_depth_params);
2161 pipe_ctx->stream_res.opp->funcs->opp_program_fmt(pipe_ctx->stream_res.opp,
2162 &stream->bit_depth_params,
2165 odm_pipe->stream_res.opp->funcs->opp_program_fmt(odm_pipe->stream_res.opp,
2166 &stream->bit_depth_params,
2168 odm_pipe = odm_pipe->next_odm_pipe;
2173 if (update_type == UPDATE_TYPE_FAST)
2176 if (stream_update->dsc_config)
2177 dp_update_dsc_config(pipe_ctx);
2179 if (stream_update->dpms_off) {
2180 if (*stream_update->dpms_off) {
2181 core_link_disable_stream(pipe_ctx);
2182 /* for dpms, keep acquired resources*/
2183 if (pipe_ctx->stream_res.audio && !dc->debug.az_endpoint_mute_only)
2184 pipe_ctx->stream_res.audio->funcs->az_disable(pipe_ctx->stream_res.audio);
2186 dc->hwss.optimize_bandwidth(dc, dc->current_state);
2188 if (dc->optimize_seamless_boot_streams == 0)
2189 dc->hwss.prepare_bandwidth(dc, dc->current_state);
2191 core_link_enable_stream(dc->current_state, pipe_ctx);
2195 if (stream_update->abm_level && pipe_ctx->stream_res.abm) {
2196 should_program_abm = true;
2198 // if otg funcs defined check if blanked before programming
2199 if (pipe_ctx->stream_res.tg->funcs->is_blanked)
2200 if (pipe_ctx->stream_res.tg->funcs->is_blanked(pipe_ctx->stream_res.tg))
2201 should_program_abm = false;
2203 if (should_program_abm) {
2204 if (*stream_update->abm_level == ABM_LEVEL_IMMEDIATE_DISABLE) {
2205 pipe_ctx->stream_res.abm->funcs->set_abm_immediate_disable(pipe_ctx->stream_res.abm);
2207 pipe_ctx->stream_res.abm->funcs->set_abm_level(
2208 pipe_ctx->stream_res.abm, stream->abm_level);
2216 static void commit_planes_for_stream(struct dc *dc,
2217 struct dc_surface_update *srf_updates,
2219 struct dc_stream_state *stream,
2220 struct dc_stream_update *stream_update,
2221 enum surface_update_type update_type,
2222 struct dc_state *context)
2225 struct pipe_ctx *top_pipe_to_program = NULL;
2227 if (dc->optimize_seamless_boot_streams > 0 && surface_count > 0) {
2228 /* Optimize seamless boot flag keeps clocks and watermarks high until
2229 * first flip. After first flip, optimization is required to lower
2230 * bandwidth. Important to note that it is expected UEFI will
2231 * only light up a single display on POST, therefore we only expect
2232 * one stream with seamless boot flag set.
2234 if (stream->apply_seamless_boot_optimization) {
2235 stream->apply_seamless_boot_optimization = false;
2236 dc->optimize_seamless_boot_streams--;
2238 if (dc->optimize_seamless_boot_streams == 0)
2239 dc->optimized_required = true;
2243 if (update_type == UPDATE_TYPE_FULL && dc->optimize_seamless_boot_streams == 0) {
2244 dc->hwss.prepare_bandwidth(dc, context);
2245 context_clock_trace(dc, context);
2248 for (j = 0; j < dc->res_pool->pipe_count; j++) {
2249 struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[j];
2251 if (!pipe_ctx->top_pipe &&
2252 !pipe_ctx->prev_odm_pipe &&
2254 pipe_ctx->stream == stream) {
2255 top_pipe_to_program = pipe_ctx;
2259 if ((update_type != UPDATE_TYPE_FAST) && stream->update_flags.bits.dsc_changed)
2260 if (top_pipe_to_program->stream_res.tg->funcs->lock_doublebuffer_enable)
2261 top_pipe_to_program->stream_res.tg->funcs->lock_doublebuffer_enable(
2262 top_pipe_to_program->stream_res.tg);
2264 if ((update_type != UPDATE_TYPE_FAST) && dc->hwss.interdependent_update_lock)
2265 dc->hwss.interdependent_update_lock(dc, context, true);
2267 /* Lock the top pipe while updating plane addrs, since freesync requires
2268 * plane addr update event triggers to be synchronized.
2269 * top_pipe_to_program is expected to never be NULL
2271 dc->hwss.pipe_control_lock(dc, top_pipe_to_program, true);
2276 commit_planes_do_stream_update(dc, stream, stream_update, update_type, context);
2278 if (surface_count == 0) {
2280 * In case of turning off screen, no need to program front end a second time.
2281 * just return after program blank.
2283 if (dc->hwss.apply_ctx_for_surface)
2284 dc->hwss.apply_ctx_for_surface(dc, stream, 0, context);
2285 if (dc->hwss.program_front_end_for_ctx)
2286 dc->hwss.program_front_end_for_ctx(dc, context);
2288 if ((update_type != UPDATE_TYPE_FAST) && dc->hwss.interdependent_update_lock)
2289 dc->hwss.interdependent_update_lock(dc, context, false);
2291 dc->hwss.pipe_control_lock(dc, top_pipe_to_program, false);
2293 dc->hwss.post_unlock_program_front_end(dc, context);
2297 if (!IS_DIAG_DC(dc->ctx->dce_environment)) {
2298 for (i = 0; i < surface_count; i++) {
2299 struct dc_plane_state *plane_state = srf_updates[i].surface;
2300 /*set logical flag for lock/unlock use*/
2301 for (j = 0; j < dc->res_pool->pipe_count; j++) {
2302 struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[j];
2303 if (!pipe_ctx->plane_state)
2305 if (pipe_ctx->plane_state != plane_state)
2307 plane_state->triplebuffer_flips = false;
2308 if (update_type == UPDATE_TYPE_FAST &&
2309 dc->hwss.program_triplebuffer != NULL &&
2310 !plane_state->flip_immediate &&
2311 !dc->debug.disable_tri_buf) {
2312 /*triple buffer for VUpdate only*/
2313 plane_state->triplebuffer_flips = true;
2319 // Update Type FULL, Surface updates
2320 for (j = 0; j < dc->res_pool->pipe_count; j++) {
2321 struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[j];
2323 if (!pipe_ctx->top_pipe &&
2324 !pipe_ctx->prev_odm_pipe &&
2326 pipe_ctx->stream == stream) {
2327 struct dc_stream_status *stream_status = NULL;
2329 if (!pipe_ctx->plane_state)
2333 if (update_type == UPDATE_TYPE_FAST)
2336 ASSERT(!pipe_ctx->plane_state->triplebuffer_flips);
2338 if (dc->hwss.program_triplebuffer != NULL &&
2339 !dc->debug.disable_tri_buf) {
2340 /*turn off triple buffer for full update*/
2341 dc->hwss.program_triplebuffer(
2342 dc, pipe_ctx, pipe_ctx->plane_state->triplebuffer_flips);
2345 stream_get_status(context, pipe_ctx->stream);
2347 if (dc->hwss.apply_ctx_for_surface)
2348 dc->hwss.apply_ctx_for_surface(
2349 dc, pipe_ctx->stream, stream_status->plane_count, context);
2352 if (dc->hwss.program_front_end_for_ctx && update_type != UPDATE_TYPE_FAST) {
2353 dc->hwss.program_front_end_for_ctx(dc, context);
2354 #ifdef CONFIG_DRM_AMD_DC_DCN
2355 if (dc->debug.validate_dml_output) {
2356 for (i = 0; i < dc->res_pool->pipe_count; i++) {
2357 struct pipe_ctx cur_pipe = context->res_ctx.pipe_ctx[i];
2358 if (cur_pipe.stream == NULL)
2361 cur_pipe.plane_res.hubp->funcs->validate_dml_output(
2362 cur_pipe.plane_res.hubp, dc->ctx,
2363 &context->res_ctx.pipe_ctx[i].rq_regs,
2364 &context->res_ctx.pipe_ctx[i].dlg_regs,
2365 &context->res_ctx.pipe_ctx[i].ttu_regs);
2371 // Update Type FAST, Surface updates
2372 if (update_type == UPDATE_TYPE_FAST) {
2373 if (dc->hwss.set_flip_control_gsl)
2374 for (i = 0; i < surface_count; i++) {
2375 struct dc_plane_state *plane_state = srf_updates[i].surface;
2377 for (j = 0; j < dc->res_pool->pipe_count; j++) {
2378 struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[j];
2380 if (pipe_ctx->stream != stream)
2383 if (pipe_ctx->plane_state != plane_state)
2386 // GSL has to be used for flip immediate
2387 dc->hwss.set_flip_control_gsl(pipe_ctx,
2388 plane_state->flip_immediate);
2391 /* Perform requested Updates */
2392 for (i = 0; i < surface_count; i++) {
2393 struct dc_plane_state *plane_state = srf_updates[i].surface;
2395 for (j = 0; j < dc->res_pool->pipe_count; j++) {
2396 struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[j];
2398 if (pipe_ctx->stream != stream)
2401 if (pipe_ctx->plane_state != plane_state)
2403 /*program triple buffer after lock based on flip type*/
2404 if (dc->hwss.program_triplebuffer != NULL &&
2405 !dc->debug.disable_tri_buf) {
2406 /*only enable triplebuffer for fast_update*/
2407 dc->hwss.program_triplebuffer(
2408 dc, pipe_ctx, plane_state->triplebuffer_flips);
2410 if (srf_updates[i].flip_addr)
2411 dc->hwss.update_plane_addr(dc, pipe_ctx);
2416 if ((update_type != UPDATE_TYPE_FAST) && dc->hwss.interdependent_update_lock)
2417 dc->hwss.interdependent_update_lock(dc, context, false);
2419 dc->hwss.pipe_control_lock(dc, top_pipe_to_program, false);
2421 if ((update_type != UPDATE_TYPE_FAST) && stream->update_flags.bits.dsc_changed)
2422 if (top_pipe_to_program->stream_res.tg->funcs->lock_doublebuffer_enable) {
2423 top_pipe_to_program->stream_res.tg->funcs->wait_for_state(
2424 top_pipe_to_program->stream_res.tg,
2425 CRTC_STATE_VACTIVE);
2426 top_pipe_to_program->stream_res.tg->funcs->wait_for_state(
2427 top_pipe_to_program->stream_res.tg,
2429 top_pipe_to_program->stream_res.tg->funcs->wait_for_state(
2430 top_pipe_to_program->stream_res.tg,
2431 CRTC_STATE_VACTIVE);
2432 top_pipe_to_program->stream_res.tg->funcs->lock_doublebuffer_disable(
2433 top_pipe_to_program->stream_res.tg);
2436 if (update_type != UPDATE_TYPE_FAST)
2437 dc->hwss.post_unlock_program_front_end(dc, context);
2439 // Fire manual trigger only when bottom plane is flipped
2440 for (j = 0; j < dc->res_pool->pipe_count; j++) {
2441 struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[j];
2443 if (pipe_ctx->bottom_pipe ||
2444 !pipe_ctx->stream ||
2445 pipe_ctx->stream != stream ||
2446 !pipe_ctx->plane_state->update_flags.bits.addr_update)
2449 if (pipe_ctx->stream_res.tg->funcs->program_manual_trigger)
2450 pipe_ctx->stream_res.tg->funcs->program_manual_trigger(pipe_ctx->stream_res.tg);
2454 void dc_commit_updates_for_stream(struct dc *dc,
2455 struct dc_surface_update *srf_updates,
2457 struct dc_stream_state *stream,
2458 struct dc_stream_update *stream_update,
2459 struct dc_state *state)
2461 const struct dc_stream_status *stream_status;
2462 enum surface_update_type update_type;
2463 struct dc_state *context;
2464 struct dc_context *dc_ctx = dc->ctx;
2467 stream_status = dc_stream_get_status(stream);
2468 context = dc->current_state;
2470 update_type = dc_check_update_surfaces_for_stream(
2471 dc, srf_updates, surface_count, stream_update, stream_status);
2473 if (update_type >= update_surface_trace_level)
2474 update_surface_trace(dc, srf_updates, surface_count);
2477 if (update_type >= UPDATE_TYPE_FULL) {
2479 /* initialize scratch memory for building context */
2480 context = dc_create_state(dc);
2481 if (context == NULL) {
2482 DC_ERROR("Failed to allocate new validate context!\n");
2486 dc_resource_state_copy_construct(state, context);
2488 for (i = 0; i < dc->res_pool->pipe_count; i++) {
2489 struct pipe_ctx *new_pipe = &context->res_ctx.pipe_ctx[i];
2490 struct pipe_ctx *old_pipe = &dc->current_state->res_ctx.pipe_ctx[i];
2492 if (new_pipe->plane_state && new_pipe->plane_state != old_pipe->plane_state)
2493 new_pipe->plane_state->force_full_update = true;
2498 for (i = 0; i < surface_count; i++) {
2499 struct dc_plane_state *surface = srf_updates[i].surface;
2501 copy_surface_update_to_plane(surface, &srf_updates[i]);
2505 copy_stream_update_to_stream(dc, context, stream, stream_update);
2507 commit_planes_for_stream(
2515 /*update current_State*/
2516 if (dc->current_state != context) {
2518 struct dc_state *old = dc->current_state;
2520 dc->current_state = context;
2521 dc_release_state(old);
2523 for (i = 0; i < dc->res_pool->pipe_count; i++) {
2524 struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[i];
2526 if (pipe_ctx->plane_state && pipe_ctx->stream == stream)
2527 pipe_ctx->plane_state->force_full_update = false;
2530 /*let's use current_state to update watermark etc*/
2531 if (update_type >= UPDATE_TYPE_FULL)
2532 dc_post_update_surfaces_to_stream(dc);
2538 uint8_t dc_get_current_stream_count(struct dc *dc)
2540 return dc->current_state->stream_count;
2543 struct dc_stream_state *dc_get_stream_at_index(struct dc *dc, uint8_t i)
2545 if (i < dc->current_state->stream_count)
2546 return dc->current_state->streams[i];
2550 enum dc_irq_source dc_interrupt_to_irq_source(
2555 return dal_irq_service_to_irq_source(dc->res_pool->irqs, src_id, ext_id);
2559 * dc_interrupt_set() - Enable/disable an AMD hw interrupt source
2561 bool dc_interrupt_set(struct dc *dc, enum dc_irq_source src, bool enable)
2567 return dal_irq_service_set(dc->res_pool->irqs, src, enable);
2570 void dc_interrupt_ack(struct dc *dc, enum dc_irq_source src)
2572 dal_irq_service_ack(dc->res_pool->irqs, src);
2575 void dc_set_power_state(
2577 enum dc_acpi_cm_power_state power_state)
2579 struct kref refcount;
2580 struct display_mode_lib *dml;
2582 switch (power_state) {
2583 case DC_ACPI_CM_POWER_STATE_D0:
2584 dc_resource_state_construct(dc, dc->current_state);
2586 if (dc->ctx->dmub_srv)
2587 dc_dmub_srv_wait_phy_init(dc->ctx->dmub_srv);
2589 dc->hwss.init_hw(dc);
2591 if (dc->hwss.init_sys_ctx != NULL &&
2592 dc->vm_pa_config.valid) {
2593 dc->hwss.init_sys_ctx(dc->hwseq, dc, &dc->vm_pa_config);
2598 ASSERT(dc->current_state->stream_count == 0);
2599 /* Zero out the current context so that on resume we start with
2600 * clean state, and dc hw programming optimizations will not
2601 * cause any trouble.
2603 dml = kzalloc(sizeof(struct display_mode_lib),
2610 /* Preserve refcount */
2611 refcount = dc->current_state->refcount;
2612 /* Preserve display mode lib */
2613 memcpy(dml, &dc->current_state->bw_ctx.dml, sizeof(struct display_mode_lib));
2615 dc_resource_state_destruct(dc->current_state);
2616 memset(dc->current_state, 0,
2617 sizeof(*dc->current_state));
2619 dc->current_state->refcount = refcount;
2620 dc->current_state->bw_ctx.dml = *dml;
2628 void dc_resume(struct dc *dc)
2633 for (i = 0; i < dc->link_count; i++)
2634 core_link_resume(dc->links[i]);
2637 unsigned int dc_get_current_backlight_pwm(struct dc *dc)
2639 struct abm *abm = dc->res_pool->abm;
2642 return abm->funcs->get_current_backlight(abm);
2647 unsigned int dc_get_target_backlight_pwm(struct dc *dc)
2649 struct abm *abm = dc->res_pool->abm;
2652 return abm->funcs->get_target_backlight(abm);
2657 bool dc_is_dmcu_initialized(struct dc *dc)
2659 struct dmcu *dmcu = dc->res_pool->dmcu;
2662 return dmcu->funcs->is_dmcu_initialized(dmcu);
2668 uint32_t link_index,
2669 struct i2c_command *cmd)
2672 struct dc_link *link = dc->links[link_index];
2673 struct ddc_service *ddc = link->ddc;
2674 return dce_i2c_submit_command(
2680 bool dc_submit_i2c_oem(
2682 struct i2c_command *cmd)
2684 struct ddc_service *ddc = dc->res_pool->oem_device;
2685 return dce_i2c_submit_command(
2691 static bool link_add_remote_sink_helper(struct dc_link *dc_link, struct dc_sink *sink)
2693 if (dc_link->sink_count >= MAX_SINKS_PER_LINK) {
2694 BREAK_TO_DEBUGGER();
2698 dc_sink_retain(sink);
2700 dc_link->remote_sinks[dc_link->sink_count] = sink;
2701 dc_link->sink_count++;
2707 * dc_link_add_remote_sink() - Create a sink and attach it to an existing link
2709 * EDID length is in bytes
2711 struct dc_sink *dc_link_add_remote_sink(
2712 struct dc_link *link,
2713 const uint8_t *edid,
2715 struct dc_sink_init_data *init_data)
2717 struct dc_sink *dc_sink;
2718 enum dc_edid_status edid_status;
2720 if (len > DC_MAX_EDID_BUFFER_SIZE) {
2721 dm_error("Max EDID buffer size breached!\n");
2726 BREAK_TO_DEBUGGER();
2730 if (!init_data->link) {
2731 BREAK_TO_DEBUGGER();
2735 dc_sink = dc_sink_create(init_data);
2740 memmove(dc_sink->dc_edid.raw_edid, edid, len);
2741 dc_sink->dc_edid.length = len;
2743 if (!link_add_remote_sink_helper(
2748 edid_status = dm_helpers_parse_edid_caps(
2751 &dc_sink->edid_caps);
2754 * Treat device as no EDID device if EDID
2757 if (edid_status != EDID_OK) {
2758 dc_sink->dc_edid.length = 0;
2759 dm_error("Bad EDID, status%d!\n", edid_status);
2765 dc_sink_release(dc_sink);
2770 * dc_link_remove_remote_sink() - Remove a remote sink from a dc_link
2772 * Note that this just removes the struct dc_sink - it doesn't
2773 * program hardware or alter other members of dc_link
2775 void dc_link_remove_remote_sink(struct dc_link *link, struct dc_sink *sink)
2779 if (!link->sink_count) {
2780 BREAK_TO_DEBUGGER();
2784 for (i = 0; i < link->sink_count; i++) {
2785 if (link->remote_sinks[i] == sink) {
2786 dc_sink_release(sink);
2787 link->remote_sinks[i] = NULL;
2789 /* shrink array to remove empty place */
2790 while (i < link->sink_count - 1) {
2791 link->remote_sinks[i] = link->remote_sinks[i+1];
2794 link->remote_sinks[i] = NULL;
2801 void get_clock_requirements_for_state(struct dc_state *state, struct AsicStateEx *info)
2803 info->displayClock = (unsigned int)state->bw_ctx.bw.dcn.clk.dispclk_khz;
2804 info->engineClock = (unsigned int)state->bw_ctx.bw.dcn.clk.dcfclk_khz;
2805 info->memoryClock = (unsigned int)state->bw_ctx.bw.dcn.clk.dramclk_khz;
2806 info->maxSupportedDppClock = (unsigned int)state->bw_ctx.bw.dcn.clk.max_supported_dppclk_khz;
2807 info->dppClock = (unsigned int)state->bw_ctx.bw.dcn.clk.dppclk_khz;
2808 info->socClock = (unsigned int)state->bw_ctx.bw.dcn.clk.socclk_khz;
2809 info->dcfClockDeepSleep = (unsigned int)state->bw_ctx.bw.dcn.clk.dcfclk_deep_sleep_khz;
2810 info->fClock = (unsigned int)state->bw_ctx.bw.dcn.clk.fclk_khz;
2811 info->phyClock = (unsigned int)state->bw_ctx.bw.dcn.clk.phyclk_khz;
2813 enum dc_status dc_set_clock(struct dc *dc, enum dc_clock_type clock_type, uint32_t clk_khz, uint32_t stepping)
2815 if (dc->hwss.set_clock)
2816 return dc->hwss.set_clock(dc, clock_type, clk_khz, stepping);
2817 return DC_ERROR_UNEXPECTED;
2819 void dc_get_clock(struct dc *dc, enum dc_clock_type clock_type, struct dc_clock_config *clock_cfg)
2821 if (dc->hwss.get_clock)
2822 dc->hwss.get_clock(dc, clock_type, clock_cfg);