2 * Copyright 2015 Advanced Micro Devices, Inc.
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 * OTHER DEALINGS IN THE SOFTWARE.
25 #include <linux/slab.h>
28 #include "dm_services.h"
32 #include "core_status.h"
33 #include "core_types.h"
34 #include "hw_sequencer.h"
35 #include "dce/dce_hwseq.h"
40 #include "clock_source.h"
41 #include "dc_bios_types.h"
43 #include "bios_parser_interface.h"
44 #include "include/irq_service_interface.h"
45 #include "transform.h"
48 #include "timing_generator.h"
50 #include "virtual/virtual_link_encoder.h"
52 #include "link_hwss.h"
53 #include "link_encoder.h"
55 #include "dc_link_ddc.h"
56 #include "dm_helpers.h"
57 #include "mem_input.h"
60 #include "dc_link_dp.h"
61 #include "dc_dmub_srv.h"
65 #include "vm_helper.h"
67 #include "dce/dce_i2c.h"
69 #include "dmub/dmub_srv.h"
71 #include "dce/dmub_hw_lock_mgr.h"
81 static const char DC_BUILD_ID[] = "production-build";
86 * DC is the OS-agnostic component of the amdgpu DC driver.
88 * DC maintains and validates a set of structs representing the state of the
89 * driver and writes that state to AMD hardware
93 * struct dc - The central struct. One per driver. Created on driver load,
94 * destroyed on driver unload.
96 * struct dc_context - One per driver.
97 * Used as a backpointer by most other structs in dc.
99 * struct dc_link - One per connector (the physical DP, HDMI, miniDP, or eDP
100 * plugpoints). Created on driver load, destroyed on driver unload.
102 * struct dc_sink - One per display. Created on boot or hotplug.
103 * Destroyed on shutdown or hotunplug. A dc_link can have a local sink
104 * (the display directly attached). It may also have one or more remote
105 * sinks (in the Multi-Stream Transport case)
107 * struct resource_pool - One per driver. Represents the hw blocks not in the
108 * main pipeline. Not directly accessible by dm.
110 * Main dc state structs:
112 * These structs can be created and destroyed as needed. There is a full set of
113 * these structs in dc->current_state representing the currently programmed state.
115 * struct dc_state - The global DC state to track global state information,
116 * such as bandwidth values.
118 * struct dc_stream_state - Represents the hw configuration for the pipeline from
119 * a framebuffer to a display. Maps one-to-one with dc_sink.
121 * struct dc_plane_state - Represents a framebuffer. Each stream has at least one,
122 * and may have more in the Multi-Plane Overlay case.
124 * struct resource_context - Represents the programmable state of everything in
125 * the resource_pool. Not directly accessible by dm.
127 * struct pipe_ctx - A member of struct resource_context. Represents the
128 * internal hardware pipeline components. Each dc_plane_state has either
129 * one or two (in the pipe-split case).
132 /*******************************************************************************
134 ******************************************************************************/
136 static inline void elevate_update_type(enum surface_update_type *original, enum surface_update_type new)
142 static void destroy_links(struct dc *dc)
146 for (i = 0; i < dc->link_count; i++) {
147 if (NULL != dc->links[i])
148 link_destroy(&dc->links[i]);
152 static bool create_links(
154 uint32_t num_virtual_links)
158 struct dc_bios *bios = dc->ctx->dc_bios;
162 connectors_num = bios->funcs->get_connectors_number(bios);
164 if (connectors_num > ENUM_ID_COUNT) {
166 "DC: Number of connectors %d exceeds maximum of %d!\n",
172 dm_output_to_console(
173 "DC: %s: connectors_num: physical:%d, virtual:%d\n",
178 for (i = 0; i < connectors_num; i++) {
179 struct link_init_data link_init_params = {0};
180 struct dc_link *link;
182 link_init_params.ctx = dc->ctx;
183 /* next BIOS object table connector */
184 link_init_params.connector_index = i;
185 link_init_params.link_index = dc->link_count;
186 link_init_params.dc = dc;
187 link = link_create(&link_init_params);
190 bool should_destory_link = false;
192 if (link->connector_signal == SIGNAL_TYPE_EDP) {
193 if (dc->config.edp_not_connected) {
194 if (!IS_DIAG_DC(dc->ctx->dce_environment))
195 should_destory_link = true;
197 enum dc_connection_type type;
198 dc_link_detect_sink(link, &type);
199 if (type == dc_connection_none)
200 should_destory_link = true;
204 if (dc->config.force_enum_edp || !should_destory_link) {
205 dc->links[dc->link_count] = link;
214 for (i = 0; i < num_virtual_links; i++) {
215 struct dc_link *link = kzalloc(sizeof(*link), GFP_KERNEL);
216 struct encoder_init_data enc_init = {0};
223 link->link_index = dc->link_count;
224 dc->links[dc->link_count] = link;
229 link->connector_signal = SIGNAL_TYPE_VIRTUAL;
230 link->link_id.type = OBJECT_TYPE_CONNECTOR;
231 link->link_id.id = CONNECTOR_ID_VIRTUAL;
232 link->link_id.enum_id = ENUM_ID_1;
233 link->link_enc = kzalloc(sizeof(*link->link_enc), GFP_KERNEL);
235 if (!link->link_enc) {
240 link->link_status.dpcd_caps = &link->dpcd_caps;
242 enc_init.ctx = dc->ctx;
243 enc_init.channel = CHANNEL_ID_UNKNOWN;
244 enc_init.hpd_source = HPD_SOURCEID_UNKNOWN;
245 enc_init.transmitter = TRANSMITTER_UNKNOWN;
246 enc_init.connector = link->link_id;
247 enc_init.encoder.type = OBJECT_TYPE_ENCODER;
248 enc_init.encoder.id = ENCODER_ID_INTERNAL_VIRTUAL;
249 enc_init.encoder.enum_id = ENUM_ID_1;
250 virtual_link_encoder_construct(link->link_enc, &enc_init);
259 static struct dc_perf_trace *dc_perf_trace_create(void)
261 return kzalloc(sizeof(struct dc_perf_trace), GFP_KERNEL);
264 static void dc_perf_trace_destroy(struct dc_perf_trace **perf_trace)
271 *****************************************************************************
272 * Function: dc_stream_adjust_vmin_vmax
275 * Looks up the pipe context of dc_stream_state and updates the
276 * vertical_total_min and vertical_total_max of the DRR, Dynamic Refresh
277 * Rate, which is a power-saving feature that targets reducing panel
278 * refresh rate while the screen is static
280 * @param [in] dc: dc reference
281 * @param [in] stream: Initial dc stream state
282 * @param [in] adjust: Updated parameters for vertical_total_min and
284 *****************************************************************************
286 bool dc_stream_adjust_vmin_vmax(struct dc *dc,
287 struct dc_stream_state *stream,
288 struct dc_crtc_timing_adjust *adjust)
293 stream->adjust = *adjust;
295 for (i = 0; i < MAX_PIPES; i++) {
296 struct pipe_ctx *pipe = &dc->current_state->res_ctx.pipe_ctx[i];
298 if (pipe->stream == stream && pipe->stream_res.tg) {
299 dc->hwss.set_drr(&pipe,
304 adjust->v_total_mid_frame_num);
312 bool dc_stream_get_crtc_position(struct dc *dc,
313 struct dc_stream_state **streams, int num_streams,
314 unsigned int *v_pos, unsigned int *nom_v_pos)
316 /* TODO: Support multiple streams */
317 const struct dc_stream_state *stream = streams[0];
320 struct crtc_position position;
322 for (i = 0; i < MAX_PIPES; i++) {
323 struct pipe_ctx *pipe =
324 &dc->current_state->res_ctx.pipe_ctx[i];
326 if (pipe->stream == stream && pipe->stream_res.stream_enc) {
327 dc->hwss.get_position(&pipe, 1, &position);
329 *v_pos = position.vertical_count;
330 *nom_v_pos = position.nominal_vcount;
338 * dc_stream_configure_crc() - Configure CRC capture for the given stream.
340 * @stream: The stream to configure CRC on.
341 * @enable: Enable CRC if true, disable otherwise.
342 * @continuous: Capture CRC on every frame if true. Otherwise, only capture
345 * By default, only CRC0 is configured, and the entire frame is used to
348 bool dc_stream_configure_crc(struct dc *dc, struct dc_stream_state *stream,
349 bool enable, bool continuous)
352 struct pipe_ctx *pipe;
353 struct crc_params param;
354 struct timing_generator *tg;
356 for (i = 0; i < MAX_PIPES; i++) {
357 pipe = &dc->current_state->res_ctx.pipe_ctx[i];
358 if (pipe->stream == stream && !pipe->top_pipe && !pipe->prev_odm_pipe)
361 /* Stream not found */
365 /* Always capture the full frame */
366 param.windowa_x_start = 0;
367 param.windowa_y_start = 0;
368 param.windowa_x_end = pipe->stream->timing.h_addressable;
369 param.windowa_y_end = pipe->stream->timing.v_addressable;
370 param.windowb_x_start = 0;
371 param.windowb_y_start = 0;
372 param.windowb_x_end = pipe->stream->timing.h_addressable;
373 param.windowb_y_end = pipe->stream->timing.v_addressable;
375 param.dsc_mode = pipe->stream->timing.flags.DSC ? 1:0;
376 param.odm_mode = pipe->next_odm_pipe ? 1:0;
378 /* Default to the union of both windows */
379 param.selection = UNION_WINDOW_A_B;
380 param.continuous_mode = continuous;
381 param.enable = enable;
383 tg = pipe->stream_res.tg;
385 /* Only call if supported */
386 if (tg->funcs->configure_crc)
387 return tg->funcs->configure_crc(tg, ¶m);
388 DC_LOG_WARNING("CRC capture not supported.");
393 * dc_stream_get_crc() - Get CRC values for the given stream.
395 * @stream: The DC stream state of the stream to get CRCs from.
396 * @r_cr, g_y, b_cb: CRC values for the three channels are stored here.
398 * dc_stream_configure_crc needs to be called beforehand to enable CRCs.
399 * Return false if stream is not found, or if CRCs are not enabled.
401 bool dc_stream_get_crc(struct dc *dc, struct dc_stream_state *stream,
402 uint32_t *r_cr, uint32_t *g_y, uint32_t *b_cb)
405 struct pipe_ctx *pipe;
406 struct timing_generator *tg;
408 for (i = 0; i < MAX_PIPES; i++) {
409 pipe = &dc->current_state->res_ctx.pipe_ctx[i];
410 if (pipe->stream == stream)
413 /* Stream not found */
417 tg = pipe->stream_res.tg;
419 if (tg->funcs->get_crc)
420 return tg->funcs->get_crc(tg, r_cr, g_y, b_cb);
421 DC_LOG_WARNING("CRC capture not supported.");
425 void dc_stream_set_dyn_expansion(struct dc *dc, struct dc_stream_state *stream,
426 enum dc_dynamic_expansion option)
428 /* OPP FMT dyn expansion updates*/
430 struct pipe_ctx *pipe_ctx;
432 for (i = 0; i < MAX_PIPES; i++) {
433 if (dc->current_state->res_ctx.pipe_ctx[i].stream
435 pipe_ctx = &dc->current_state->res_ctx.pipe_ctx[i];
436 pipe_ctx->stream_res.opp->dyn_expansion = option;
437 pipe_ctx->stream_res.opp->funcs->opp_set_dyn_expansion(
438 pipe_ctx->stream_res.opp,
439 COLOR_SPACE_YCBCR601,
440 stream->timing.display_color_depth,
446 void dc_stream_set_dither_option(struct dc_stream_state *stream,
447 enum dc_dither_option option)
449 struct bit_depth_reduction_params params;
450 struct dc_link *link = stream->link;
451 struct pipe_ctx *pipes = NULL;
454 for (i = 0; i < MAX_PIPES; i++) {
455 if (link->dc->current_state->res_ctx.pipe_ctx[i].stream ==
457 pipes = &link->dc->current_state->res_ctx.pipe_ctx[i];
464 if (option > DITHER_OPTION_MAX)
467 stream->dither_option = option;
469 memset(¶ms, 0, sizeof(params));
470 resource_build_bit_depth_reduction_params(stream, ¶ms);
471 stream->bit_depth_params = params;
473 if (pipes->plane_res.xfm &&
474 pipes->plane_res.xfm->funcs->transform_set_pixel_storage_depth) {
475 pipes->plane_res.xfm->funcs->transform_set_pixel_storage_depth(
476 pipes->plane_res.xfm,
477 pipes->plane_res.scl_data.lb_params.depth,
478 &stream->bit_depth_params);
481 pipes->stream_res.opp->funcs->
482 opp_program_bit_depth_reduction(pipes->stream_res.opp, ¶ms);
485 bool dc_stream_set_gamut_remap(struct dc *dc, const struct dc_stream_state *stream)
489 struct pipe_ctx *pipes;
491 for (i = 0; i < MAX_PIPES; i++) {
492 if (dc->current_state->res_ctx.pipe_ctx[i].stream == stream) {
493 pipes = &dc->current_state->res_ctx.pipe_ctx[i];
494 dc->hwss.program_gamut_remap(pipes);
502 bool dc_stream_program_csc_matrix(struct dc *dc, struct dc_stream_state *stream)
506 struct pipe_ctx *pipes;
508 for (i = 0; i < MAX_PIPES; i++) {
509 if (dc->current_state->res_ctx.pipe_ctx[i].stream
512 pipes = &dc->current_state->res_ctx.pipe_ctx[i];
513 dc->hwss.program_output_csc(dc,
515 stream->output_color_space,
516 stream->csc_color_matrix.matrix,
517 pipes->stream_res.opp->inst);
525 void dc_stream_set_static_screen_params(struct dc *dc,
526 struct dc_stream_state **streams,
528 const struct dc_static_screen_params *params)
532 struct pipe_ctx *pipes_affected[MAX_PIPES];
533 int num_pipes_affected = 0;
535 for (i = 0; i < num_streams; i++) {
536 struct dc_stream_state *stream = streams[i];
538 for (j = 0; j < MAX_PIPES; j++) {
539 if (dc->current_state->res_ctx.pipe_ctx[j].stream
541 pipes_affected[num_pipes_affected++] =
542 &dc->current_state->res_ctx.pipe_ctx[j];
547 dc->hwss.set_static_screen_control(pipes_affected, num_pipes_affected, params);
550 static void dc_destruct(struct dc *dc)
552 if (dc->current_state) {
553 dc_release_state(dc->current_state);
554 dc->current_state = NULL;
560 dc_destroy_clk_mgr(dc->clk_mgr);
564 dc_destroy_resource_pool(dc);
566 if (dc->ctx->gpio_service)
567 dal_gpio_service_destroy(&dc->ctx->gpio_service);
569 if (dc->ctx->created_bios)
570 dal_bios_parser_destroy(&dc->ctx->dc_bios);
572 dc_perf_trace_destroy(&dc->ctx->perf_trace);
583 #ifdef CONFIG_DRM_AMD_DC_DCN
591 kfree(dc->vm_helper);
592 dc->vm_helper = NULL;
596 static bool dc_construct_ctx(struct dc *dc,
597 const struct dc_init_data *init_params)
599 struct dc_context *dc_ctx;
600 enum dce_version dc_version = DCE_VERSION_UNKNOWN;
602 dc_ctx = kzalloc(sizeof(*dc_ctx), GFP_KERNEL);
606 dc_ctx->cgs_device = init_params->cgs_device;
607 dc_ctx->driver_context = init_params->driver;
609 dc_ctx->asic_id = init_params->asic_id;
610 dc_ctx->dc_sink_id_count = 0;
611 dc_ctx->dc_stream_id_count = 0;
612 dc_ctx->dce_environment = init_params->dce_environment;
616 dc_version = resource_parse_asic_id(init_params->asic_id);
617 dc_ctx->dce_version = dc_version;
619 dc_ctx->perf_trace = dc_perf_trace_create();
620 if (!dc_ctx->perf_trace) {
621 ASSERT_CRITICAL(false);
630 static bool dc_construct(struct dc *dc,
631 const struct dc_init_data *init_params)
633 struct dc_context *dc_ctx;
634 struct bw_calcs_dceip *dc_dceip;
635 struct bw_calcs_vbios *dc_vbios;
636 #ifdef CONFIG_DRM_AMD_DC_DCN
637 struct dcn_soc_bounding_box *dcn_soc;
638 struct dcn_ip_params *dcn_ip;
641 dc->config = init_params->flags;
643 // Allocate memory for the vm_helper
644 dc->vm_helper = kzalloc(sizeof(struct vm_helper), GFP_KERNEL);
645 if (!dc->vm_helper) {
646 dm_error("%s: failed to create dc->vm_helper\n", __func__);
650 memcpy(&dc->bb_overrides, &init_params->bb_overrides, sizeof(dc->bb_overrides));
652 dc_dceip = kzalloc(sizeof(*dc_dceip), GFP_KERNEL);
654 dm_error("%s: failed to create dceip\n", __func__);
658 dc->bw_dceip = dc_dceip;
660 dc_vbios = kzalloc(sizeof(*dc_vbios), GFP_KERNEL);
662 dm_error("%s: failed to create vbios\n", __func__);
666 dc->bw_vbios = dc_vbios;
667 #ifdef CONFIG_DRM_AMD_DC_DCN
668 dcn_soc = kzalloc(sizeof(*dcn_soc), GFP_KERNEL);
670 dm_error("%s: failed to create dcn_soc\n", __func__);
674 dc->dcn_soc = dcn_soc;
676 dcn_ip = kzalloc(sizeof(*dcn_ip), GFP_KERNEL);
678 dm_error("%s: failed to create dcn_ip\n", __func__);
683 dc->soc_bounding_box = init_params->soc_bounding_box;
686 if (!dc_construct_ctx(dc, init_params)) {
687 dm_error("%s: failed to create ctx\n", __func__);
693 /* Resource should construct all asic specific resources.
694 * This should be the only place where we need to parse the asic id
696 if (init_params->vbios_override)
697 dc_ctx->dc_bios = init_params->vbios_override;
699 /* Create BIOS parser */
700 struct bp_init_data bp_init_data;
702 bp_init_data.ctx = dc_ctx;
703 bp_init_data.bios = init_params->asic_id.atombios_base_address;
705 dc_ctx->dc_bios = dal_bios_parser_create(
706 &bp_init_data, dc_ctx->dce_version);
708 if (!dc_ctx->dc_bios) {
709 ASSERT_CRITICAL(false);
713 dc_ctx->created_bios = true;
716 dc->vendor_signature = init_params->vendor_signature;
718 /* Create GPIO service */
719 dc_ctx->gpio_service = dal_gpio_service_create(
721 dc_ctx->dce_environment,
724 if (!dc_ctx->gpio_service) {
725 ASSERT_CRITICAL(false);
729 dc->res_pool = dc_create_resource_pool(dc, init_params, dc_ctx->dce_version);
733 dc->clk_mgr = dc_clk_mgr_create(dc->ctx, dc->res_pool->pp_smu, dc->res_pool->dccg);
736 #ifdef CONFIG_DRM_AMD_DC_DCN3_0
737 dc->clk_mgr->force_smu_not_present = init_params->force_smu_not_present;
740 dc->debug.force_ignore_link_settings = init_params->force_ignore_link_settings;
742 if (dc->res_pool->funcs->update_bw_bounding_box)
743 dc->res_pool->funcs->update_bw_bounding_box(dc, dc->clk_mgr->bw_params);
745 /* Creation of current_state must occur after dc->dml
746 * is initialized in dc_create_resource_pool because
747 * on creation it copies the contents of dc->dml
750 dc->current_state = dc_create_state(dc);
752 if (!dc->current_state) {
753 dm_error("%s: failed to create validate ctx\n", __func__);
757 dc_resource_state_construct(dc, dc->current_state);
759 if (!create_links(dc, init_params->num_virtual_links))
768 static void disable_all_writeback_pipes_for_stream(
770 struct dc_stream_state *stream,
771 struct dc_state *context)
775 for (i = 0; i < stream->num_wb_info; i++)
776 stream->writeback_info[i].wb_enabled = false;
779 void apply_ctx_interdependent_lock(struct dc *dc, struct dc_state *context, struct dc_stream_state *stream, bool lock)
783 /* Checks if interdependent update function pointer is NULL or not, takes care of DCE110 case */
784 if (dc->hwss.interdependent_update_lock)
785 dc->hwss.interdependent_update_lock(dc, context, lock);
787 for (i = 0; i < dc->res_pool->pipe_count; i++) {
788 struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[i];
789 struct pipe_ctx *old_pipe_ctx = &dc->current_state->res_ctx.pipe_ctx[i];
791 // Copied conditions that were previously in dce110_apply_ctx_for_surface
792 if (stream == pipe_ctx->stream) {
793 if (!pipe_ctx->top_pipe &&
794 (pipe_ctx->plane_state || old_pipe_ctx->plane_state))
795 dc->hwss.pipe_control_lock(dc, pipe_ctx, lock);
801 static void disable_dangling_plane(struct dc *dc, struct dc_state *context)
804 struct dc_state *dangling_context = dc_create_state(dc);
805 struct dc_state *current_ctx;
807 if (dangling_context == NULL)
810 dc_resource_state_copy_construct(dc->current_state, dangling_context);
812 for (i = 0; i < dc->res_pool->pipe_count; i++) {
813 struct dc_stream_state *old_stream =
814 dc->current_state->res_ctx.pipe_ctx[i].stream;
815 bool should_disable = true;
817 for (j = 0; j < context->stream_count; j++) {
818 if (old_stream == context->streams[j]) {
819 should_disable = false;
823 if (should_disable && old_stream) {
824 dc_rem_all_planes_for_stream(dc, old_stream, dangling_context);
825 disable_all_writeback_pipes_for_stream(dc, old_stream, dangling_context);
827 if (dc->hwss.apply_ctx_for_surface) {
828 apply_ctx_interdependent_lock(dc, dc->current_state, old_stream, true);
829 dc->hwss.apply_ctx_for_surface(dc, old_stream, 0, dangling_context);
830 apply_ctx_interdependent_lock(dc, dc->current_state, old_stream, false);
831 dc->hwss.post_unlock_program_front_end(dc, dangling_context);
833 if (dc->hwss.program_front_end_for_ctx) {
834 dc->hwss.interdependent_update_lock(dc, dc->current_state, true);
835 dc->hwss.program_front_end_for_ctx(dc, dangling_context);
836 dc->hwss.interdependent_update_lock(dc, dc->current_state, false);
837 dc->hwss.post_unlock_program_front_end(dc, dangling_context);
842 current_ctx = dc->current_state;
843 dc->current_state = dangling_context;
844 dc_release_state(current_ctx);
847 static void disable_vbios_mode_if_required(
849 struct dc_state *context)
853 /* check if timing_changed, disable stream*/
854 for (i = 0; i < dc->res_pool->pipe_count; i++) {
855 struct dc_stream_state *stream = NULL;
856 struct dc_link *link = NULL;
857 struct pipe_ctx *pipe = NULL;
859 pipe = &context->res_ctx.pipe_ctx[i];
860 stream = pipe->stream;
864 // only looking for first odm pipe
865 if (pipe->prev_odm_pipe)
868 if (stream->link->local_sink &&
869 stream->link->local_sink->sink_signal == SIGNAL_TYPE_EDP) {
873 if (link != NULL && link->link_enc->funcs->is_dig_enabled(link->link_enc)) {
874 unsigned int enc_inst, tg_inst = 0;
875 unsigned int pix_clk_100hz;
877 enc_inst = link->link_enc->funcs->get_dig_frontend(link->link_enc);
878 if (enc_inst != ENGINE_ID_UNKNOWN) {
879 for (j = 0; j < dc->res_pool->stream_enc_count; j++) {
880 if (dc->res_pool->stream_enc[j]->id == enc_inst) {
881 tg_inst = dc->res_pool->stream_enc[j]->funcs->dig_source_otg(
882 dc->res_pool->stream_enc[j]);
887 dc->res_pool->dp_clock_source->funcs->get_pixel_clk_frequency_100hz(
888 dc->res_pool->dp_clock_source,
889 tg_inst, &pix_clk_100hz);
891 if (link->link_status.link_active) {
892 uint32_t requested_pix_clk_100hz =
893 pipe->stream_res.pix_clk_params.requested_pix_clk_100hz;
895 if (pix_clk_100hz != requested_pix_clk_100hz) {
896 core_link_disable_stream(pipe);
897 pipe->stream->dpms_off = false;
905 static void wait_for_no_pipes_pending(struct dc *dc, struct dc_state *context)
909 for (i = 0; i < MAX_PIPES; i++) {
911 struct pipe_ctx *pipe = &context->res_ctx.pipe_ctx[i];
913 if (!pipe->plane_state)
917 while (count < 100000) {
918 /* Must set to false to start with, due to OR in update function */
919 pipe->plane_state->status.is_flip_pending = false;
920 dc->hwss.update_pending_status(pipe);
921 if (!pipe->plane_state->status.is_flip_pending)
926 ASSERT(!pipe->plane_state->status.is_flip_pending);
931 /*******************************************************************************
933 ******************************************************************************/
935 struct dc *dc_create(const struct dc_init_data *init_params)
937 struct dc *dc = kzalloc(sizeof(*dc), GFP_KERNEL);
938 unsigned int full_pipe_count;
943 if (init_params->dce_environment == DCE_ENV_VIRTUAL_HW) {
944 if (false == dc_construct_ctx(dc, init_params)) {
949 if (false == dc_construct(dc, init_params)) {
954 full_pipe_count = dc->res_pool->pipe_count;
955 if (dc->res_pool->underlay_pipe_index != NO_UNDERLAY_PIPE)
957 dc->caps.max_streams = min(
959 dc->res_pool->stream_enc_count);
961 dc->optimize_seamless_boot_streams = 0;
962 dc->caps.max_links = dc->link_count;
963 dc->caps.max_audios = dc->res_pool->audio_count;
964 dc->caps.linear_pitch_alignment = 64;
966 dc->caps.max_dp_protocol_version = DP_VERSION_1_4;
968 if (dc->res_pool->dmcu != NULL)
969 dc->versions.dmcu_version = dc->res_pool->dmcu->dmcu_version;
972 /* Populate versioning information */
973 dc->versions.dc_ver = DC_VER;
975 dc->build_id = DC_BUILD_ID;
977 DC_LOG_DC("Display Core initialized\n");
990 void dc_hardware_init(struct dc *dc)
992 if (dc->ctx->dce_environment != DCE_ENV_VIRTUAL_HW)
993 dc->hwss.init_hw(dc);
996 void dc_init_callbacks(struct dc *dc,
997 const struct dc_callback_init *init_params)
999 #ifdef CONFIG_DRM_AMD_DC_HDCP
1000 dc->ctx->cp_psp = init_params->cp_psp;
1004 void dc_deinit_callbacks(struct dc *dc)
1006 #ifdef CONFIG_DRM_AMD_DC_HDCP
1007 memset(&dc->ctx->cp_psp, 0, sizeof(dc->ctx->cp_psp));
1011 void dc_destroy(struct dc **dc)
1018 static void enable_timing_multisync(
1020 struct dc_state *ctx)
1022 int i = 0, multisync_count = 0;
1023 int pipe_count = dc->res_pool->pipe_count;
1024 struct pipe_ctx *multisync_pipes[MAX_PIPES] = { NULL };
1026 for (i = 0; i < pipe_count; i++) {
1027 if (!ctx->res_ctx.pipe_ctx[i].stream ||
1028 !ctx->res_ctx.pipe_ctx[i].stream->triggered_crtc_reset.enabled)
1030 if (ctx->res_ctx.pipe_ctx[i].stream == ctx->res_ctx.pipe_ctx[i].stream->triggered_crtc_reset.event_source)
1032 multisync_pipes[multisync_count] = &ctx->res_ctx.pipe_ctx[i];
1036 if (multisync_count > 0) {
1037 dc->hwss.enable_per_frame_crtc_position_reset(
1038 dc, multisync_count, multisync_pipes);
1042 static void program_timing_sync(
1044 struct dc_state *ctx)
1047 int group_index = 0;
1049 int pipe_count = dc->res_pool->pipe_count;
1050 struct pipe_ctx *unsynced_pipes[MAX_PIPES] = { NULL };
1052 for (i = 0; i < pipe_count; i++) {
1053 if (!ctx->res_ctx.pipe_ctx[i].stream || ctx->res_ctx.pipe_ctx[i].top_pipe)
1056 unsynced_pipes[i] = &ctx->res_ctx.pipe_ctx[i];
1059 for (i = 0; i < pipe_count; i++) {
1061 struct pipe_ctx *pipe_set[MAX_PIPES];
1063 if (!unsynced_pipes[i])
1066 pipe_set[0] = unsynced_pipes[i];
1067 unsynced_pipes[i] = NULL;
1069 /* Add tg to the set, search rest of the tg's for ones with
1070 * same timing, add all tgs with same timing to the group
1072 for (j = i + 1; j < pipe_count; j++) {
1073 if (!unsynced_pipes[j])
1076 if (resource_are_streams_timing_synchronizable(
1077 unsynced_pipes[j]->stream,
1078 pipe_set[0]->stream)) {
1079 pipe_set[group_size] = unsynced_pipes[j];
1080 unsynced_pipes[j] = NULL;
1085 /* set first unblanked pipe as master */
1086 for (j = 0; j < group_size; j++) {
1089 if (pipe_set[j]->stream_res.opp->funcs->dpg_is_blanked)
1091 pipe_set[j]->stream_res.opp->funcs->dpg_is_blanked(pipe_set[j]->stream_res.opp);
1094 pipe_set[j]->stream_res.tg->funcs->is_blanked(pipe_set[j]->stream_res.tg);
1099 swap(pipe_set[0], pipe_set[j]);
1105 for (k = 0; k < group_size; k++) {
1106 struct dc_stream_status *status = dc_stream_get_status_from_state(ctx, pipe_set[k]->stream);
1108 status->timing_sync_info.group_id = num_group;
1109 status->timing_sync_info.group_size = group_size;
1111 status->timing_sync_info.master = true;
1113 status->timing_sync_info.master = false;
1116 /* remove any other unblanked pipes as they have already been synced */
1117 for (j = j + 1; j < group_size; j++) {
1120 if (pipe_set[j]->stream_res.opp->funcs->dpg_is_blanked)
1122 pipe_set[j]->stream_res.opp->funcs->dpg_is_blanked(pipe_set[j]->stream_res.opp);
1125 pipe_set[j]->stream_res.tg->funcs->is_blanked(pipe_set[j]->stream_res.tg);
1128 pipe_set[j] = pipe_set[group_size];
1133 if (group_size > 1) {
1134 dc->hwss.enable_timing_synchronization(
1135 dc, group_index, group_size, pipe_set);
1142 static bool context_changed(
1144 struct dc_state *context)
1148 if (context->stream_count != dc->current_state->stream_count)
1151 for (i = 0; i < dc->current_state->stream_count; i++) {
1152 if (dc->current_state->streams[i] != context->streams[i])
1159 bool dc_validate_seamless_boot_timing(const struct dc *dc,
1160 const struct dc_sink *sink,
1161 struct dc_crtc_timing *crtc_timing)
1163 struct timing_generator *tg;
1164 struct stream_encoder *se = NULL;
1166 struct dc_crtc_timing hw_crtc_timing = {0};
1168 struct dc_link *link = sink->link;
1169 unsigned int i, enc_inst, tg_inst = 0;
1171 // Seamless port only support single DP and EDP so far
1172 if (sink->sink_signal != SIGNAL_TYPE_DISPLAY_PORT &&
1173 sink->sink_signal != SIGNAL_TYPE_EDP)
1176 /* Check for enabled DIG to identify enabled display */
1177 if (!link->link_enc->funcs->is_dig_enabled(link->link_enc))
1180 enc_inst = link->link_enc->funcs->get_dig_frontend(link->link_enc);
1182 if (enc_inst == ENGINE_ID_UNKNOWN)
1185 for (i = 0; i < dc->res_pool->stream_enc_count; i++) {
1186 if (dc->res_pool->stream_enc[i]->id == enc_inst) {
1188 se = dc->res_pool->stream_enc[i];
1190 tg_inst = dc->res_pool->stream_enc[i]->funcs->dig_source_otg(
1191 dc->res_pool->stream_enc[i]);
1196 // tg_inst not found
1197 if (i == dc->res_pool->stream_enc_count)
1200 if (tg_inst >= dc->res_pool->timing_generator_count)
1203 tg = dc->res_pool->timing_generators[tg_inst];
1205 if (!tg->funcs->get_hw_timing)
1208 if (!tg->funcs->get_hw_timing(tg, &hw_crtc_timing))
1211 if (crtc_timing->h_total != hw_crtc_timing.h_total)
1214 if (crtc_timing->h_border_left != hw_crtc_timing.h_border_left)
1217 if (crtc_timing->h_addressable != hw_crtc_timing.h_addressable)
1220 if (crtc_timing->h_border_right != hw_crtc_timing.h_border_right)
1223 if (crtc_timing->h_front_porch != hw_crtc_timing.h_front_porch)
1226 if (crtc_timing->h_sync_width != hw_crtc_timing.h_sync_width)
1229 if (crtc_timing->v_total != hw_crtc_timing.v_total)
1232 if (crtc_timing->v_border_top != hw_crtc_timing.v_border_top)
1235 if (crtc_timing->v_addressable != hw_crtc_timing.v_addressable)
1238 if (crtc_timing->v_border_bottom != hw_crtc_timing.v_border_bottom)
1241 if (crtc_timing->v_front_porch != hw_crtc_timing.v_front_porch)
1244 if (crtc_timing->v_sync_width != hw_crtc_timing.v_sync_width)
1247 if (dc_is_dp_signal(link->connector_signal)) {
1248 unsigned int pix_clk_100hz;
1250 dc->res_pool->dp_clock_source->funcs->get_pixel_clk_frequency_100hz(
1251 dc->res_pool->dp_clock_source,
1252 tg_inst, &pix_clk_100hz);
1254 if (crtc_timing->pix_clk_100hz != pix_clk_100hz)
1257 if (!se->funcs->dp_get_pixel_format)
1260 if (!se->funcs->dp_get_pixel_format(
1262 &hw_crtc_timing.pixel_encoding,
1263 &hw_crtc_timing.display_color_depth))
1266 if (hw_crtc_timing.display_color_depth != crtc_timing->display_color_depth)
1269 if (hw_crtc_timing.pixel_encoding != crtc_timing->pixel_encoding)
1273 if (link->dpcd_caps.dprx_feature.bits.VSC_SDP_COLORIMETRY_SUPPORTED) {
1280 void dc_enable_stereo(
1282 struct dc_state *context,
1283 struct dc_stream_state *streams[],
1284 uint8_t stream_count)
1287 struct pipe_ctx *pipe;
1289 for (i = 0; i < MAX_PIPES; i++) {
1290 if (context != NULL)
1291 pipe = &context->res_ctx.pipe_ctx[i];
1293 pipe = &dc->current_state->res_ctx.pipe_ctx[i];
1294 for (j = 0 ; pipe && j < stream_count; j++) {
1295 if (streams[j] && streams[j] == pipe->stream &&
1296 dc->hwss.setup_stereo)
1297 dc->hwss.setup_stereo(pipe, dc);
1302 void dc_trigger_sync(struct dc *dc, struct dc_state *context)
1304 if (context->stream_count > 1 && !dc->debug.disable_timing_sync) {
1305 enable_timing_multisync(dc, context);
1306 program_timing_sync(dc, context);
1310 static uint8_t get_stream_mask(struct dc *dc, struct dc_state *context)
1313 unsigned int stream_mask = 0;
1315 for (i = 0; i < dc->res_pool->pipe_count; i++) {
1316 if (context->res_ctx.pipe_ctx[i].stream)
1317 stream_mask |= 1 << i;
1324 * Applies given context to HW and copy it into current context.
1325 * It's up to the user to release the src context afterwards.
1327 static enum dc_status dc_commit_state_no_check(struct dc *dc, struct dc_state *context)
1329 struct dc_bios *dcb = dc->ctx->dc_bios;
1330 enum dc_status result = DC_ERROR_UNEXPECTED;
1331 struct pipe_ctx *pipe;
1333 struct dc_stream_state *dc_streams[MAX_STREAMS] = {0};
1335 #if defined(CONFIG_DRM_AMD_DC_DCN3_0)
1336 dc_allow_idle_optimizations(dc, false);
1339 for (i = 0; i < context->stream_count; i++)
1340 dc_streams[i] = context->streams[i];
1342 if (!dcb->funcs->is_accelerated_mode(dcb)) {
1343 disable_vbios_mode_if_required(dc, context);
1344 dc->hwss.enable_accelerated_mode(dc, context);
1347 for (i = 0; i < context->stream_count; i++)
1348 if (context->streams[i]->apply_seamless_boot_optimization)
1349 dc->optimize_seamless_boot_streams++;
1351 if (context->stream_count > dc->optimize_seamless_boot_streams ||
1352 context->stream_count == 0)
1353 dc->hwss.prepare_bandwidth(dc, context);
1355 disable_dangling_plane(dc, context);
1356 /* re-program planes for existing stream, in case we need to
1357 * free up plane resource for later use
1359 if (dc->hwss.apply_ctx_for_surface) {
1360 for (i = 0; i < context->stream_count; i++) {
1361 if (context->streams[i]->mode_changed)
1363 apply_ctx_interdependent_lock(dc, context, context->streams[i], true);
1364 dc->hwss.apply_ctx_for_surface(
1365 dc, context->streams[i],
1366 context->stream_status[i].plane_count,
1367 context); /* use new pipe config in new context */
1368 apply_ctx_interdependent_lock(dc, context, context->streams[i], false);
1369 dc->hwss.post_unlock_program_front_end(dc, context);
1373 /* Program hardware */
1374 for (i = 0; i < dc->res_pool->pipe_count; i++) {
1375 pipe = &context->res_ctx.pipe_ctx[i];
1376 dc->hwss.wait_for_mpcc_disconnect(dc, dc->res_pool, pipe);
1379 result = dc->hwss.apply_ctx_to_hw(dc, context);
1381 if (result != DC_OK)
1384 dc_trigger_sync(dc, context);
1386 /* Program all planes within new context*/
1387 if (dc->hwss.program_front_end_for_ctx) {
1388 dc->hwss.interdependent_update_lock(dc, context, true);
1389 dc->hwss.program_front_end_for_ctx(dc, context);
1390 dc->hwss.interdependent_update_lock(dc, context, false);
1391 dc->hwss.post_unlock_program_front_end(dc, context);
1393 for (i = 0; i < context->stream_count; i++) {
1394 const struct dc_link *link = context->streams[i]->link;
1396 if (!context->streams[i]->mode_changed)
1399 if (dc->hwss.apply_ctx_for_surface) {
1400 apply_ctx_interdependent_lock(dc, context, context->streams[i], true);
1401 dc->hwss.apply_ctx_for_surface(
1402 dc, context->streams[i],
1403 context->stream_status[i].plane_count,
1405 apply_ctx_interdependent_lock(dc, context, context->streams[i], false);
1406 dc->hwss.post_unlock_program_front_end(dc, context);
1411 * TODO rework dc_enable_stereo call to work with validation sets?
1413 for (k = 0; k < MAX_PIPES; k++) {
1414 pipe = &context->res_ctx.pipe_ctx[k];
1416 for (l = 0 ; pipe && l < context->stream_count; l++) {
1417 if (context->streams[l] &&
1418 context->streams[l] == pipe->stream &&
1419 dc->hwss.setup_stereo)
1420 dc->hwss.setup_stereo(pipe, dc);
1424 CONN_MSG_MODE(link, "{%dx%d, %dx%d@%dKhz}",
1425 context->streams[i]->timing.h_addressable,
1426 context->streams[i]->timing.v_addressable,
1427 context->streams[i]->timing.h_total,
1428 context->streams[i]->timing.v_total,
1429 context->streams[i]->timing.pix_clk_100hz / 10);
1432 dc_enable_stereo(dc, context, dc_streams, context->stream_count);
1434 if (context->stream_count > dc->optimize_seamless_boot_streams ||
1435 context->stream_count == 0) {
1436 /* Must wait for no flips to be pending before doing optimize bw */
1437 wait_for_no_pipes_pending(dc, context);
1438 /* pplib is notified if disp_num changed */
1439 dc->hwss.optimize_bandwidth(dc, context);
1442 if (dc->ctx->dce_version >= DCE_VERSION_MAX)
1443 TRACE_DCN_CLOCK_STATE(&context->bw_ctx.bw.dcn.clk);
1445 TRACE_DCE_CLOCK_STATE(&context->bw_ctx.bw.dce);
1447 context->stream_mask = get_stream_mask(dc, context);
1449 if (context->stream_mask != dc->current_state->stream_mask)
1450 dc_dmub_srv_notify_stream_mask(dc->ctx->dmub_srv, context->stream_mask);
1452 for (i = 0; i < context->stream_count; i++)
1453 context->streams[i]->mode_changed = false;
1455 dc_release_state(dc->current_state);
1457 dc->current_state = context;
1459 dc_retain_state(dc->current_state);
1464 bool dc_commit_state(struct dc *dc, struct dc_state *context)
1466 enum dc_status result = DC_ERROR_UNEXPECTED;
1469 if (false == context_changed(dc, context))
1472 DC_LOG_DC("%s: %d streams\n",
1473 __func__, context->stream_count);
1475 for (i = 0; i < context->stream_count; i++) {
1476 struct dc_stream_state *stream = context->streams[i];
1478 dc_stream_log(dc, stream);
1481 result = dc_commit_state_no_check(dc, context);
1483 return (result == DC_OK);
1486 #if defined(CONFIG_DRM_AMD_DC_DCN3_0)
1487 bool dc_acquire_release_mpc_3dlut(
1488 struct dc *dc, bool acquire,
1489 struct dc_stream_state *stream,
1490 struct dc_3dlut **lut,
1491 struct dc_transfer_func **shaper)
1495 bool found_pipe_idx = false;
1496 const struct resource_pool *pool = dc->res_pool;
1497 struct resource_context *res_ctx = &dc->current_state->res_ctx;
1500 if (pool && res_ctx) {
1502 /*find pipe idx for the given stream*/
1503 for (pipe_idx = 0; pipe_idx < pool->pipe_count; pipe_idx++) {
1504 if (res_ctx->pipe_ctx[pipe_idx].stream == stream) {
1505 found_pipe_idx = true;
1506 mpcc_id = res_ctx->pipe_ctx[pipe_idx].plane_res.hubp->inst;
1511 found_pipe_idx = true;/*for release pipe_idx is not required*/
1513 if (found_pipe_idx) {
1514 if (acquire && pool->funcs->acquire_post_bldn_3dlut)
1515 ret = pool->funcs->acquire_post_bldn_3dlut(res_ctx, pool, mpcc_id, lut, shaper);
1516 else if (acquire == false && pool->funcs->release_post_bldn_3dlut)
1517 ret = pool->funcs->release_post_bldn_3dlut(res_ctx, pool, lut, shaper);
1523 static bool is_flip_pending_in_pipes(struct dc *dc, struct dc_state *context)
1526 struct pipe_ctx *pipe;
1528 for (i = 0; i < MAX_PIPES; i++) {
1529 pipe = &context->res_ctx.pipe_ctx[i];
1531 if (!pipe->plane_state)
1534 /* Must set to false to start with, due to OR in update function */
1535 pipe->plane_state->status.is_flip_pending = false;
1536 dc->hwss.update_pending_status(pipe);
1537 if (pipe->plane_state->status.is_flip_pending)
1543 void dc_post_update_surfaces_to_stream(struct dc *dc)
1546 struct dc_state *context = dc->current_state;
1548 if ((!dc->optimized_required) || dc->optimize_seamless_boot_streams > 0)
1551 post_surface_trace(dc);
1553 if (is_flip_pending_in_pipes(dc, context))
1556 for (i = 0; i < dc->res_pool->pipe_count; i++)
1557 if (context->res_ctx.pipe_ctx[i].stream == NULL ||
1558 context->res_ctx.pipe_ctx[i].plane_state == NULL) {
1559 context->res_ctx.pipe_ctx[i].pipe_idx = i;
1560 dc->hwss.disable_plane(dc, &context->res_ctx.pipe_ctx[i]);
1563 dc->hwss.optimize_bandwidth(dc, context);
1565 dc->optimized_required = false;
1566 dc->wm_optimized_required = false;
1569 static void init_state(struct dc *dc, struct dc_state *context)
1571 /* Each context must have their own instance of VBA and in order to
1572 * initialize and obtain IP and SOC the base DML instance from DC is
1573 * initially copied into every context
1575 #ifdef CONFIG_DRM_AMD_DC_DCN
1576 memcpy(&context->bw_ctx.dml, &dc->dml, sizeof(struct display_mode_lib));
1580 struct dc_state *dc_create_state(struct dc *dc)
1582 struct dc_state *context = kvzalloc(sizeof(struct dc_state),
1588 init_state(dc, context);
1590 kref_init(&context->refcount);
1595 struct dc_state *dc_copy_state(struct dc_state *src_ctx)
1598 struct dc_state *new_ctx = kvmalloc(sizeof(struct dc_state), GFP_KERNEL);
1602 memcpy(new_ctx, src_ctx, sizeof(struct dc_state));
1604 for (i = 0; i < MAX_PIPES; i++) {
1605 struct pipe_ctx *cur_pipe = &new_ctx->res_ctx.pipe_ctx[i];
1607 if (cur_pipe->top_pipe)
1608 cur_pipe->top_pipe = &new_ctx->res_ctx.pipe_ctx[cur_pipe->top_pipe->pipe_idx];
1610 if (cur_pipe->bottom_pipe)
1611 cur_pipe->bottom_pipe = &new_ctx->res_ctx.pipe_ctx[cur_pipe->bottom_pipe->pipe_idx];
1613 if (cur_pipe->prev_odm_pipe)
1614 cur_pipe->prev_odm_pipe = &new_ctx->res_ctx.pipe_ctx[cur_pipe->prev_odm_pipe->pipe_idx];
1616 if (cur_pipe->next_odm_pipe)
1617 cur_pipe->next_odm_pipe = &new_ctx->res_ctx.pipe_ctx[cur_pipe->next_odm_pipe->pipe_idx];
1621 for (i = 0; i < new_ctx->stream_count; i++) {
1622 dc_stream_retain(new_ctx->streams[i]);
1623 for (j = 0; j < new_ctx->stream_status[i].plane_count; j++)
1624 dc_plane_state_retain(
1625 new_ctx->stream_status[i].plane_states[j]);
1628 kref_init(&new_ctx->refcount);
1633 void dc_retain_state(struct dc_state *context)
1635 kref_get(&context->refcount);
1638 static void dc_state_free(struct kref *kref)
1640 struct dc_state *context = container_of(kref, struct dc_state, refcount);
1641 dc_resource_state_destruct(context);
1645 void dc_release_state(struct dc_state *context)
1647 kref_put(&context->refcount, dc_state_free);
1650 bool dc_set_generic_gpio_for_stereo(bool enable,
1651 struct gpio_service *gpio_service)
1653 enum gpio_result gpio_result = GPIO_RESULT_NON_SPECIFIC_ERROR;
1654 struct gpio_pin_info pin_info;
1655 struct gpio *generic;
1656 struct gpio_generic_mux_config *config = kzalloc(sizeof(struct gpio_generic_mux_config),
1661 pin_info = dal_gpio_get_generic_pin_info(gpio_service, GPIO_ID_GENERIC, 0);
1663 if (pin_info.mask == 0xFFFFFFFF || pin_info.offset == 0xFFFFFFFF) {
1667 generic = dal_gpio_service_create_generic_mux(
1678 gpio_result = dal_gpio_open(generic, GPIO_MODE_OUTPUT);
1680 config->enable_output_from_mux = enable;
1681 config->mux_select = GPIO_SIGNAL_SOURCE_PASS_THROUGH_STEREO_SYNC;
1683 if (gpio_result == GPIO_RESULT_OK)
1684 gpio_result = dal_mux_setup_config(generic, config);
1686 if (gpio_result == GPIO_RESULT_OK) {
1687 dal_gpio_close(generic);
1688 dal_gpio_destroy_generic_mux(&generic);
1692 dal_gpio_close(generic);
1693 dal_gpio_destroy_generic_mux(&generic);
1699 static bool is_surface_in_context(
1700 const struct dc_state *context,
1701 const struct dc_plane_state *plane_state)
1705 for (j = 0; j < MAX_PIPES; j++) {
1706 const struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[j];
1708 if (plane_state == pipe_ctx->plane_state) {
1716 static enum surface_update_type get_plane_info_update_type(const struct dc_surface_update *u)
1718 union surface_update_flags *update_flags = &u->surface->update_flags;
1719 enum surface_update_type update_type = UPDATE_TYPE_FAST;
1722 return UPDATE_TYPE_FAST;
1724 if (u->plane_info->color_space != u->surface->color_space) {
1725 update_flags->bits.color_space_change = 1;
1726 elevate_update_type(&update_type, UPDATE_TYPE_MED);
1729 if (u->plane_info->horizontal_mirror != u->surface->horizontal_mirror) {
1730 update_flags->bits.horizontal_mirror_change = 1;
1731 elevate_update_type(&update_type, UPDATE_TYPE_MED);
1734 if (u->plane_info->rotation != u->surface->rotation) {
1735 update_flags->bits.rotation_change = 1;
1736 elevate_update_type(&update_type, UPDATE_TYPE_FULL);
1739 if (u->plane_info->format != u->surface->format) {
1740 update_flags->bits.pixel_format_change = 1;
1741 elevate_update_type(&update_type, UPDATE_TYPE_FULL);
1744 if (u->plane_info->stereo_format != u->surface->stereo_format) {
1745 update_flags->bits.stereo_format_change = 1;
1746 elevate_update_type(&update_type, UPDATE_TYPE_FULL);
1749 if (u->plane_info->per_pixel_alpha != u->surface->per_pixel_alpha) {
1750 update_flags->bits.per_pixel_alpha_change = 1;
1751 elevate_update_type(&update_type, UPDATE_TYPE_MED);
1754 if (u->plane_info->global_alpha_value != u->surface->global_alpha_value) {
1755 update_flags->bits.global_alpha_change = 1;
1756 elevate_update_type(&update_type, UPDATE_TYPE_MED);
1759 if (u->plane_info->dcc.enable != u->surface->dcc.enable
1760 || u->plane_info->dcc.independent_64b_blks != u->surface->dcc.independent_64b_blks
1761 || u->plane_info->dcc.meta_pitch != u->surface->dcc.meta_pitch) {
1762 update_flags->bits.dcc_change = 1;
1763 elevate_update_type(&update_type, UPDATE_TYPE_MED);
1766 if (resource_pixel_format_to_bpp(u->plane_info->format) !=
1767 resource_pixel_format_to_bpp(u->surface->format)) {
1768 /* different bytes per element will require full bandwidth
1769 * and DML calculation
1771 update_flags->bits.bpp_change = 1;
1772 elevate_update_type(&update_type, UPDATE_TYPE_FULL);
1775 if (u->plane_info->plane_size.surface_pitch != u->surface->plane_size.surface_pitch
1776 || u->plane_info->plane_size.chroma_pitch != u->surface->plane_size.chroma_pitch) {
1777 update_flags->bits.plane_size_change = 1;
1778 elevate_update_type(&update_type, UPDATE_TYPE_MED);
1782 if (memcmp(&u->plane_info->tiling_info, &u->surface->tiling_info,
1783 sizeof(union dc_tiling_info)) != 0) {
1784 update_flags->bits.swizzle_change = 1;
1785 elevate_update_type(&update_type, UPDATE_TYPE_MED);
1787 /* todo: below are HW dependent, we should add a hook to
1788 * DCE/N resource and validated there.
1790 if (u->plane_info->tiling_info.gfx9.swizzle != DC_SW_LINEAR) {
1791 /* swizzled mode requires RQ to be setup properly,
1792 * thus need to run DML to calculate RQ settings
1794 update_flags->bits.bandwidth_change = 1;
1795 elevate_update_type(&update_type, UPDATE_TYPE_FULL);
1799 /* This should be UPDATE_TYPE_FAST if nothing has changed. */
1803 static enum surface_update_type get_scaling_info_update_type(
1804 const struct dc_surface_update *u)
1806 union surface_update_flags *update_flags = &u->surface->update_flags;
1808 if (!u->scaling_info)
1809 return UPDATE_TYPE_FAST;
1811 if (u->scaling_info->clip_rect.width != u->surface->clip_rect.width
1812 || u->scaling_info->clip_rect.height != u->surface->clip_rect.height
1813 || u->scaling_info->dst_rect.width != u->surface->dst_rect.width
1814 || u->scaling_info->dst_rect.height != u->surface->dst_rect.height
1815 || u->scaling_info->scaling_quality.integer_scaling !=
1816 u->surface->scaling_quality.integer_scaling
1818 update_flags->bits.scaling_change = 1;
1820 if ((u->scaling_info->dst_rect.width < u->surface->dst_rect.width
1821 || u->scaling_info->dst_rect.height < u->surface->dst_rect.height)
1822 && (u->scaling_info->dst_rect.width < u->surface->src_rect.width
1823 || u->scaling_info->dst_rect.height < u->surface->src_rect.height))
1824 /* Making dst rect smaller requires a bandwidth change */
1825 update_flags->bits.bandwidth_change = 1;
1828 if (u->scaling_info->src_rect.width != u->surface->src_rect.width
1829 || u->scaling_info->src_rect.height != u->surface->src_rect.height) {
1831 update_flags->bits.scaling_change = 1;
1832 if (u->scaling_info->src_rect.width > u->surface->src_rect.width
1833 || u->scaling_info->src_rect.height > u->surface->src_rect.height)
1834 /* Making src rect bigger requires a bandwidth change */
1835 update_flags->bits.clock_change = 1;
1838 if (u->scaling_info->src_rect.x != u->surface->src_rect.x
1839 || u->scaling_info->src_rect.y != u->surface->src_rect.y
1840 || u->scaling_info->clip_rect.x != u->surface->clip_rect.x
1841 || u->scaling_info->clip_rect.y != u->surface->clip_rect.y
1842 || u->scaling_info->dst_rect.x != u->surface->dst_rect.x
1843 || u->scaling_info->dst_rect.y != u->surface->dst_rect.y)
1844 update_flags->bits.position_change = 1;
1846 if (update_flags->bits.clock_change
1847 || update_flags->bits.bandwidth_change
1848 || update_flags->bits.scaling_change)
1849 return UPDATE_TYPE_FULL;
1851 if (update_flags->bits.position_change)
1852 return UPDATE_TYPE_MED;
1854 return UPDATE_TYPE_FAST;
1857 static enum surface_update_type det_surface_update(const struct dc *dc,
1858 const struct dc_surface_update *u)
1860 const struct dc_state *context = dc->current_state;
1861 enum surface_update_type type;
1862 enum surface_update_type overall_type = UPDATE_TYPE_FAST;
1863 union surface_update_flags *update_flags = &u->surface->update_flags;
1866 update_flags->bits.addr_update = 1;
1868 if (!is_surface_in_context(context, u->surface) || u->surface->force_full_update) {
1869 update_flags->raw = 0xFFFFFFFF;
1870 return UPDATE_TYPE_FULL;
1873 update_flags->raw = 0; // Reset all flags
1875 type = get_plane_info_update_type(u);
1876 elevate_update_type(&overall_type, type);
1878 type = get_scaling_info_update_type(u);
1879 elevate_update_type(&overall_type, type);
1882 update_flags->bits.addr_update = 1;
1884 if (u->in_transfer_func)
1885 update_flags->bits.in_transfer_func_change = 1;
1887 if (u->input_csc_color_matrix)
1888 update_flags->bits.input_csc_change = 1;
1890 if (u->coeff_reduction_factor)
1891 update_flags->bits.coeff_reduction_change = 1;
1893 if (u->gamut_remap_matrix)
1894 update_flags->bits.gamut_remap_change = 1;
1897 enum surface_pixel_format format = SURFACE_PIXEL_FORMAT_GRPH_BEGIN;
1900 format = u->plane_info->format;
1901 else if (u->surface)
1902 format = u->surface->format;
1904 if (dce_use_lut(format))
1905 update_flags->bits.gamma_change = 1;
1908 if (u->hdr_mult.value)
1909 if (u->hdr_mult.value != u->surface->hdr_mult.value) {
1910 update_flags->bits.hdr_mult = 1;
1911 elevate_update_type(&overall_type, UPDATE_TYPE_MED);
1914 if (update_flags->bits.in_transfer_func_change) {
1915 type = UPDATE_TYPE_MED;
1916 elevate_update_type(&overall_type, type);
1919 if (update_flags->bits.input_csc_change
1920 || update_flags->bits.coeff_reduction_change
1921 || update_flags->bits.gamma_change
1922 || update_flags->bits.gamut_remap_change) {
1923 type = UPDATE_TYPE_FULL;
1924 elevate_update_type(&overall_type, type);
1927 return overall_type;
1930 static enum surface_update_type check_update_surfaces_for_stream(
1932 struct dc_surface_update *updates,
1934 struct dc_stream_update *stream_update,
1935 const struct dc_stream_status *stream_status)
1938 enum surface_update_type overall_type = UPDATE_TYPE_FAST;
1940 #if defined(CONFIG_DRM_AMD_DC_DCN3_0)
1941 if (dc->idle_optimizations_allowed)
1942 overall_type = UPDATE_TYPE_FULL;
1945 if (stream_status == NULL || stream_status->plane_count != surface_count)
1946 overall_type = UPDATE_TYPE_FULL;
1948 /* some stream updates require passive update */
1949 if (stream_update) {
1950 union stream_update_flags *su_flags = &stream_update->stream->update_flags;
1952 if ((stream_update->src.height != 0 && stream_update->src.width != 0) ||
1953 (stream_update->dst.height != 0 && stream_update->dst.width != 0) ||
1954 stream_update->integer_scaling_update)
1955 su_flags->bits.scaling = 1;
1957 if (stream_update->out_transfer_func)
1958 su_flags->bits.out_tf = 1;
1960 if (stream_update->abm_level)
1961 su_flags->bits.abm_level = 1;
1963 if (stream_update->dpms_off)
1964 su_flags->bits.dpms_off = 1;
1966 if (stream_update->gamut_remap)
1967 su_flags->bits.gamut_remap = 1;
1969 if (stream_update->wb_update)
1970 su_flags->bits.wb_update = 1;
1972 if (stream_update->dsc_config)
1973 su_flags->bits.dsc_changed = 1;
1975 if (su_flags->raw != 0)
1976 overall_type = UPDATE_TYPE_FULL;
1978 if (stream_update->output_csc_transform || stream_update->output_color_space)
1979 su_flags->bits.out_csc = 1;
1982 for (i = 0 ; i < surface_count; i++) {
1983 enum surface_update_type type =
1984 det_surface_update(dc, &updates[i]);
1986 elevate_update_type(&overall_type, type);
1989 return overall_type;
1993 * dc_check_update_surfaces_for_stream() - Determine update type (fast, med, or full)
1995 * See :c:type:`enum surface_update_type <surface_update_type>` for explanation of update types
1997 enum surface_update_type dc_check_update_surfaces_for_stream(
1999 struct dc_surface_update *updates,
2001 struct dc_stream_update *stream_update,
2002 const struct dc_stream_status *stream_status)
2005 enum surface_update_type type;
2008 stream_update->stream->update_flags.raw = 0;
2009 for (i = 0; i < surface_count; i++)
2010 updates[i].surface->update_flags.raw = 0;
2012 type = check_update_surfaces_for_stream(dc, updates, surface_count, stream_update, stream_status);
2013 if (type == UPDATE_TYPE_FULL) {
2014 if (stream_update) {
2015 uint32_t dsc_changed = stream_update->stream->update_flags.bits.dsc_changed;
2016 stream_update->stream->update_flags.raw = 0xFFFFFFFF;
2017 stream_update->stream->update_flags.bits.dsc_changed = dsc_changed;
2019 for (i = 0; i < surface_count; i++)
2020 updates[i].surface->update_flags.raw = 0xFFFFFFFF;
2023 if (type == UPDATE_TYPE_FAST) {
2024 // If there's an available clock comparator, we use that.
2025 if (dc->clk_mgr->funcs->are_clock_states_equal) {
2026 if (!dc->clk_mgr->funcs->are_clock_states_equal(&dc->clk_mgr->clks, &dc->current_state->bw_ctx.bw.dcn.clk))
2027 dc->optimized_required = true;
2028 // Else we fallback to mem compare.
2029 } 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) {
2030 dc->optimized_required = true;
2033 dc->optimized_required |= dc->wm_optimized_required;
2039 static struct dc_stream_status *stream_get_status(
2040 struct dc_state *ctx,
2041 struct dc_stream_state *stream)
2045 for (i = 0; i < ctx->stream_count; i++) {
2046 if (stream == ctx->streams[i]) {
2047 return &ctx->stream_status[i];
2054 static const enum surface_update_type update_surface_trace_level = UPDATE_TYPE_FULL;
2056 static void copy_surface_update_to_plane(
2057 struct dc_plane_state *surface,
2058 struct dc_surface_update *srf_update)
2060 if (srf_update->flip_addr) {
2061 surface->address = srf_update->flip_addr->address;
2062 surface->flip_immediate =
2063 srf_update->flip_addr->flip_immediate;
2064 surface->time.time_elapsed_in_us[surface->time.index] =
2065 srf_update->flip_addr->flip_timestamp_in_us -
2066 surface->time.prev_update_time_in_us;
2067 surface->time.prev_update_time_in_us =
2068 srf_update->flip_addr->flip_timestamp_in_us;
2069 surface->time.index++;
2070 if (surface->time.index >= DC_PLANE_UPDATE_TIMES_MAX)
2071 surface->time.index = 0;
2073 surface->triplebuffer_flips = srf_update->flip_addr->triplebuffer_flips;
2076 if (srf_update->scaling_info) {
2077 surface->scaling_quality =
2078 srf_update->scaling_info->scaling_quality;
2080 srf_update->scaling_info->dst_rect;
2082 srf_update->scaling_info->src_rect;
2083 surface->clip_rect =
2084 srf_update->scaling_info->clip_rect;
2087 if (srf_update->plane_info) {
2088 surface->color_space =
2089 srf_update->plane_info->color_space;
2091 srf_update->plane_info->format;
2092 surface->plane_size =
2093 srf_update->plane_info->plane_size;
2095 srf_update->plane_info->rotation;
2096 surface->horizontal_mirror =
2097 srf_update->plane_info->horizontal_mirror;
2098 surface->stereo_format =
2099 srf_update->plane_info->stereo_format;
2100 surface->tiling_info =
2101 srf_update->plane_info->tiling_info;
2103 srf_update->plane_info->visible;
2104 surface->per_pixel_alpha =
2105 srf_update->plane_info->per_pixel_alpha;
2106 surface->global_alpha =
2107 srf_update->plane_info->global_alpha;
2108 surface->global_alpha_value =
2109 srf_update->plane_info->global_alpha_value;
2111 srf_update->plane_info->dcc;
2112 surface->layer_index =
2113 srf_update->plane_info->layer_index;
2116 if (srf_update->gamma &&
2117 (surface->gamma_correction !=
2118 srf_update->gamma)) {
2119 memcpy(&surface->gamma_correction->entries,
2120 &srf_update->gamma->entries,
2121 sizeof(struct dc_gamma_entries));
2122 surface->gamma_correction->is_identity =
2123 srf_update->gamma->is_identity;
2124 surface->gamma_correction->num_entries =
2125 srf_update->gamma->num_entries;
2126 surface->gamma_correction->type =
2127 srf_update->gamma->type;
2130 if (srf_update->in_transfer_func &&
2131 (surface->in_transfer_func !=
2132 srf_update->in_transfer_func)) {
2133 surface->in_transfer_func->sdr_ref_white_level =
2134 srf_update->in_transfer_func->sdr_ref_white_level;
2135 surface->in_transfer_func->tf =
2136 srf_update->in_transfer_func->tf;
2137 surface->in_transfer_func->type =
2138 srf_update->in_transfer_func->type;
2139 memcpy(&surface->in_transfer_func->tf_pts,
2140 &srf_update->in_transfer_func->tf_pts,
2141 sizeof(struct dc_transfer_func_distributed_points));
2144 if (srf_update->func_shaper &&
2145 (surface->in_shaper_func !=
2146 srf_update->func_shaper))
2147 memcpy(surface->in_shaper_func, srf_update->func_shaper,
2148 sizeof(*surface->in_shaper_func));
2150 if (srf_update->lut3d_func &&
2151 (surface->lut3d_func !=
2152 srf_update->lut3d_func))
2153 memcpy(surface->lut3d_func, srf_update->lut3d_func,
2154 sizeof(*surface->lut3d_func));
2156 if (srf_update->hdr_mult.value)
2158 srf_update->hdr_mult;
2160 if (srf_update->blend_tf &&
2161 (surface->blend_tf !=
2162 srf_update->blend_tf))
2163 memcpy(surface->blend_tf, srf_update->blend_tf,
2164 sizeof(*surface->blend_tf));
2166 if (srf_update->input_csc_color_matrix)
2167 surface->input_csc_color_matrix =
2168 *srf_update->input_csc_color_matrix;
2170 if (srf_update->coeff_reduction_factor)
2171 surface->coeff_reduction_factor =
2172 *srf_update->coeff_reduction_factor;
2174 if (srf_update->gamut_remap_matrix)
2175 surface->gamut_remap_matrix =
2176 *srf_update->gamut_remap_matrix;
2179 static void copy_stream_update_to_stream(struct dc *dc,
2180 struct dc_state *context,
2181 struct dc_stream_state *stream,
2182 struct dc_stream_update *update)
2184 struct dc_context *dc_ctx = dc->ctx;
2186 if (update == NULL || stream == NULL)
2189 if (update->src.height && update->src.width)
2190 stream->src = update->src;
2192 if (update->dst.height && update->dst.width)
2193 stream->dst = update->dst;
2195 if (update->out_transfer_func &&
2196 stream->out_transfer_func != update->out_transfer_func) {
2197 stream->out_transfer_func->sdr_ref_white_level =
2198 update->out_transfer_func->sdr_ref_white_level;
2199 stream->out_transfer_func->tf = update->out_transfer_func->tf;
2200 stream->out_transfer_func->type =
2201 update->out_transfer_func->type;
2202 memcpy(&stream->out_transfer_func->tf_pts,
2203 &update->out_transfer_func->tf_pts,
2204 sizeof(struct dc_transfer_func_distributed_points));
2207 if (update->hdr_static_metadata)
2208 stream->hdr_static_metadata = *update->hdr_static_metadata;
2210 if (update->abm_level)
2211 stream->abm_level = *update->abm_level;
2213 if (update->periodic_interrupt0)
2214 stream->periodic_interrupt0 = *update->periodic_interrupt0;
2216 if (update->periodic_interrupt1)
2217 stream->periodic_interrupt1 = *update->periodic_interrupt1;
2219 if (update->gamut_remap)
2220 stream->gamut_remap_matrix = *update->gamut_remap;
2222 /* Note: this being updated after mode set is currently not a use case
2223 * however if it arises OCSC would need to be reprogrammed at the
2226 if (update->output_color_space)
2227 stream->output_color_space = *update->output_color_space;
2229 if (update->output_csc_transform)
2230 stream->csc_color_matrix = *update->output_csc_transform;
2232 if (update->vrr_infopacket)
2233 stream->vrr_infopacket = *update->vrr_infopacket;
2235 if (update->dpms_off)
2236 stream->dpms_off = *update->dpms_off;
2238 if (update->vsc_infopacket)
2239 stream->vsc_infopacket = *update->vsc_infopacket;
2241 if (update->vsp_infopacket)
2242 stream->vsp_infopacket = *update->vsp_infopacket;
2244 if (update->dither_option)
2245 stream->dither_option = *update->dither_option;
2246 /* update current stream with writeback info */
2247 if (update->wb_update) {
2250 stream->num_wb_info = update->wb_update->num_wb_info;
2251 ASSERT(stream->num_wb_info <= MAX_DWB_PIPES);
2252 for (i = 0; i < stream->num_wb_info; i++)
2253 stream->writeback_info[i] =
2254 update->wb_update->writeback_info[i];
2256 if (update->dsc_config) {
2257 struct dc_dsc_config old_dsc_cfg = stream->timing.dsc_cfg;
2258 uint32_t old_dsc_enabled = stream->timing.flags.DSC;
2259 uint32_t enable_dsc = (update->dsc_config->num_slices_h != 0 &&
2260 update->dsc_config->num_slices_v != 0);
2262 /* Use temporarry context for validating new DSC config */
2263 struct dc_state *dsc_validate_context = dc_create_state(dc);
2265 if (dsc_validate_context) {
2266 dc_resource_state_copy_construct(dc->current_state, dsc_validate_context);
2268 stream->timing.dsc_cfg = *update->dsc_config;
2269 stream->timing.flags.DSC = enable_dsc;
2270 if (!dc->res_pool->funcs->validate_bandwidth(dc, dsc_validate_context, true)) {
2271 stream->timing.dsc_cfg = old_dsc_cfg;
2272 stream->timing.flags.DSC = old_dsc_enabled;
2273 update->dsc_config = NULL;
2276 dc_release_state(dsc_validate_context);
2278 DC_ERROR("Failed to allocate new validate context for DSC change\n");
2279 update->dsc_config = NULL;
2284 static void commit_planes_do_stream_update(struct dc *dc,
2285 struct dc_stream_state *stream,
2286 struct dc_stream_update *stream_update,
2287 enum surface_update_type update_type,
2288 struct dc_state *context)
2291 bool should_program_abm;
2294 for (j = 0; j < dc->res_pool->pipe_count; j++) {
2295 struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[j];
2297 if (!pipe_ctx->top_pipe && !pipe_ctx->prev_odm_pipe && pipe_ctx->stream == stream) {
2299 if (stream_update->periodic_interrupt0 &&
2300 dc->hwss.setup_periodic_interrupt)
2301 dc->hwss.setup_periodic_interrupt(dc, pipe_ctx, VLINE0);
2303 if (stream_update->periodic_interrupt1 &&
2304 dc->hwss.setup_periodic_interrupt)
2305 dc->hwss.setup_periodic_interrupt(dc, pipe_ctx, VLINE1);
2307 if ((stream_update->hdr_static_metadata && !stream->use_dynamic_meta) ||
2308 stream_update->vrr_infopacket ||
2309 stream_update->vsc_infopacket ||
2310 stream_update->vsp_infopacket) {
2311 resource_build_info_frame(pipe_ctx);
2312 dc->hwss.update_info_frame(pipe_ctx);
2315 if (stream_update->hdr_static_metadata &&
2316 stream->use_dynamic_meta &&
2317 dc->hwss.set_dmdata_attributes &&
2318 pipe_ctx->stream->dmdata_address.quad_part != 0)
2319 dc->hwss.set_dmdata_attributes(pipe_ctx);
2321 if (stream_update->gamut_remap)
2322 dc_stream_set_gamut_remap(dc, stream);
2324 if (stream_update->output_csc_transform)
2325 dc_stream_program_csc_matrix(dc, stream);
2327 if (stream_update->dither_option) {
2328 struct pipe_ctx *odm_pipe = pipe_ctx->next_odm_pipe;
2329 resource_build_bit_depth_reduction_params(pipe_ctx->stream,
2330 &pipe_ctx->stream->bit_depth_params);
2331 pipe_ctx->stream_res.opp->funcs->opp_program_fmt(pipe_ctx->stream_res.opp,
2332 &stream->bit_depth_params,
2335 odm_pipe->stream_res.opp->funcs->opp_program_fmt(odm_pipe->stream_res.opp,
2336 &stream->bit_depth_params,
2338 odm_pipe = odm_pipe->next_odm_pipe;
2343 if (update_type == UPDATE_TYPE_FAST)
2346 if (stream_update->dsc_config)
2347 dp_update_dsc_config(pipe_ctx);
2349 if (stream_update->dpms_off) {
2350 if (*stream_update->dpms_off) {
2351 core_link_disable_stream(pipe_ctx);
2352 /* for dpms, keep acquired resources*/
2353 if (pipe_ctx->stream_res.audio && !dc->debug.az_endpoint_mute_only)
2354 pipe_ctx->stream_res.audio->funcs->az_disable(pipe_ctx->stream_res.audio);
2356 dc->hwss.optimize_bandwidth(dc, dc->current_state);
2358 if (dc->optimize_seamless_boot_streams == 0)
2359 dc->hwss.prepare_bandwidth(dc, dc->current_state);
2361 core_link_enable_stream(dc->current_state, pipe_ctx);
2365 if (stream_update->abm_level && pipe_ctx->stream_res.abm) {
2366 should_program_abm = true;
2368 // if otg funcs defined check if blanked before programming
2369 if (pipe_ctx->stream_res.tg->funcs->is_blanked)
2370 if (pipe_ctx->stream_res.tg->funcs->is_blanked(pipe_ctx->stream_res.tg))
2371 should_program_abm = false;
2373 if (should_program_abm) {
2374 if (*stream_update->abm_level == ABM_LEVEL_IMMEDIATE_DISABLE) {
2375 dc->hwss.set_abm_immediate_disable(pipe_ctx);
2377 pipe_ctx->stream_res.abm->funcs->set_abm_level(
2378 pipe_ctx->stream_res.abm, stream->abm_level);
2386 static void commit_planes_for_stream(struct dc *dc,
2387 struct dc_surface_update *srf_updates,
2389 struct dc_stream_state *stream,
2390 struct dc_stream_update *stream_update,
2391 enum surface_update_type update_type,
2392 struct dc_state *context)
2395 struct pipe_ctx *top_pipe_to_program = NULL;
2397 if (dc->optimize_seamless_boot_streams > 0 && surface_count > 0) {
2398 /* Optimize seamless boot flag keeps clocks and watermarks high until
2399 * first flip. After first flip, optimization is required to lower
2400 * bandwidth. Important to note that it is expected UEFI will
2401 * only light up a single display on POST, therefore we only expect
2402 * one stream with seamless boot flag set.
2404 if (stream->apply_seamless_boot_optimization) {
2405 stream->apply_seamless_boot_optimization = false;
2406 dc->optimize_seamless_boot_streams--;
2408 if (dc->optimize_seamless_boot_streams == 0)
2409 dc->optimized_required = true;
2413 if (update_type == UPDATE_TYPE_FULL) {
2414 #if defined(CONFIG_DRM_AMD_DC_DCN3_0)
2415 dc_allow_idle_optimizations(dc, false);
2418 if (dc->optimize_seamless_boot_streams == 0)
2419 dc->hwss.prepare_bandwidth(dc, context);
2421 context_clock_trace(dc, context);
2424 for (j = 0; j < dc->res_pool->pipe_count; j++) {
2425 struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[j];
2427 if (!pipe_ctx->top_pipe &&
2428 !pipe_ctx->prev_odm_pipe &&
2430 pipe_ctx->stream == stream) {
2431 top_pipe_to_program = pipe_ctx;
2435 if ((update_type != UPDATE_TYPE_FAST) && stream->update_flags.bits.dsc_changed)
2436 if (top_pipe_to_program->stream_res.tg->funcs->lock_doublebuffer_enable) {
2437 if (should_use_dmub_lock(stream->link)) {
2438 union dmub_hw_lock_flags hw_locks = { 0 };
2439 struct dmub_hw_lock_inst_flags inst_flags = { 0 };
2441 hw_locks.bits.lock_dig = 1;
2442 inst_flags.dig_inst = top_pipe_to_program->stream_res.tg->inst;
2444 dmub_hw_lock_mgr_cmd(dc->ctx->dmub_srv,
2449 top_pipe_to_program->stream_res.tg->funcs->lock_doublebuffer_enable(
2450 top_pipe_to_program->stream_res.tg);
2453 if ((update_type != UPDATE_TYPE_FAST) && dc->hwss.interdependent_update_lock)
2454 dc->hwss.interdependent_update_lock(dc, context, true);
2456 /* Lock the top pipe while updating plane addrs, since freesync requires
2457 * plane addr update event triggers to be synchronized.
2458 * top_pipe_to_program is expected to never be NULL
2460 dc->hwss.pipe_control_lock(dc, top_pipe_to_program, true);
2464 commit_planes_do_stream_update(dc, stream, stream_update, update_type, context);
2466 if (surface_count == 0) {
2468 * In case of turning off screen, no need to program front end a second time.
2469 * just return after program blank.
2471 if (dc->hwss.apply_ctx_for_surface)
2472 dc->hwss.apply_ctx_for_surface(dc, stream, 0, context);
2473 if (dc->hwss.program_front_end_for_ctx)
2474 dc->hwss.program_front_end_for_ctx(dc, context);
2476 if ((update_type != UPDATE_TYPE_FAST) && dc->hwss.interdependent_update_lock)
2477 dc->hwss.interdependent_update_lock(dc, context, false);
2479 dc->hwss.pipe_control_lock(dc, top_pipe_to_program, false);
2481 dc->hwss.post_unlock_program_front_end(dc, context);
2485 if (!IS_DIAG_DC(dc->ctx->dce_environment)) {
2486 for (i = 0; i < surface_count; i++) {
2487 struct dc_plane_state *plane_state = srf_updates[i].surface;
2488 /*set logical flag for lock/unlock use*/
2489 for (j = 0; j < dc->res_pool->pipe_count; j++) {
2490 struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[j];
2491 if (!pipe_ctx->plane_state)
2493 if (pipe_ctx->plane_state != plane_state)
2495 plane_state->triplebuffer_flips = false;
2496 if (update_type == UPDATE_TYPE_FAST &&
2497 dc->hwss.program_triplebuffer != NULL &&
2498 !plane_state->flip_immediate && dc->debug.enable_tri_buf) {
2499 /*triple buffer for VUpdate only*/
2500 plane_state->triplebuffer_flips = true;
2506 // Update Type FULL, Surface updates
2507 for (j = 0; j < dc->res_pool->pipe_count; j++) {
2508 struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[j];
2510 if (!pipe_ctx->top_pipe &&
2511 !pipe_ctx->prev_odm_pipe &&
2513 pipe_ctx->stream == stream) {
2514 struct dc_stream_status *stream_status = NULL;
2516 if (!pipe_ctx->plane_state)
2520 if (update_type == UPDATE_TYPE_FAST)
2523 ASSERT(!pipe_ctx->plane_state->triplebuffer_flips);
2525 if (dc->hwss.program_triplebuffer != NULL && dc->debug.enable_tri_buf) {
2526 /*turn off triple buffer for full update*/
2527 dc->hwss.program_triplebuffer(
2528 dc, pipe_ctx, pipe_ctx->plane_state->triplebuffer_flips);
2531 stream_get_status(context, pipe_ctx->stream);
2533 if (dc->hwss.apply_ctx_for_surface)
2534 dc->hwss.apply_ctx_for_surface(
2535 dc, pipe_ctx->stream, stream_status->plane_count, context);
2538 if (dc->hwss.program_front_end_for_ctx && update_type != UPDATE_TYPE_FAST) {
2539 dc->hwss.program_front_end_for_ctx(dc, context);
2540 #ifdef CONFIG_DRM_AMD_DC_DCN
2541 if (dc->debug.validate_dml_output) {
2542 for (i = 0; i < dc->res_pool->pipe_count; i++) {
2543 struct pipe_ctx cur_pipe = context->res_ctx.pipe_ctx[i];
2544 if (cur_pipe.stream == NULL)
2547 cur_pipe.plane_res.hubp->funcs->validate_dml_output(
2548 cur_pipe.plane_res.hubp, dc->ctx,
2549 &context->res_ctx.pipe_ctx[i].rq_regs,
2550 &context->res_ctx.pipe_ctx[i].dlg_regs,
2551 &context->res_ctx.pipe_ctx[i].ttu_regs);
2557 // Update Type FAST, Surface updates
2558 if (update_type == UPDATE_TYPE_FAST) {
2559 if (dc->hwss.set_flip_control_gsl)
2560 for (i = 0; i < surface_count; i++) {
2561 struct dc_plane_state *plane_state = srf_updates[i].surface;
2563 for (j = 0; j < dc->res_pool->pipe_count; j++) {
2564 struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[j];
2566 if (pipe_ctx->stream != stream)
2569 if (pipe_ctx->plane_state != plane_state)
2572 // GSL has to be used for flip immediate
2573 dc->hwss.set_flip_control_gsl(pipe_ctx,
2574 plane_state->flip_immediate);
2577 /* Perform requested Updates */
2578 for (i = 0; i < surface_count; i++) {
2579 struct dc_plane_state *plane_state = srf_updates[i].surface;
2581 for (j = 0; j < dc->res_pool->pipe_count; j++) {
2582 struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[j];
2584 if (pipe_ctx->stream != stream)
2587 if (pipe_ctx->plane_state != plane_state)
2589 /*program triple buffer after lock based on flip type*/
2590 if (dc->hwss.program_triplebuffer != NULL && dc->debug.enable_tri_buf) {
2591 /*only enable triplebuffer for fast_update*/
2592 dc->hwss.program_triplebuffer(
2593 dc, pipe_ctx, plane_state->triplebuffer_flips);
2595 if (srf_updates[i].flip_addr)
2596 dc->hwss.update_plane_addr(dc, pipe_ctx);
2601 if ((update_type != UPDATE_TYPE_FAST) && dc->hwss.interdependent_update_lock)
2602 dc->hwss.interdependent_update_lock(dc, context, false);
2604 dc->hwss.pipe_control_lock(dc, top_pipe_to_program, false);
2606 if ((update_type != UPDATE_TYPE_FAST) && stream->update_flags.bits.dsc_changed)
2607 if (top_pipe_to_program->stream_res.tg->funcs->lock_doublebuffer_enable) {
2608 top_pipe_to_program->stream_res.tg->funcs->wait_for_state(
2609 top_pipe_to_program->stream_res.tg,
2610 CRTC_STATE_VACTIVE);
2611 top_pipe_to_program->stream_res.tg->funcs->wait_for_state(
2612 top_pipe_to_program->stream_res.tg,
2614 top_pipe_to_program->stream_res.tg->funcs->wait_for_state(
2615 top_pipe_to_program->stream_res.tg,
2616 CRTC_STATE_VACTIVE);
2618 if (stream && should_use_dmub_lock(stream->link)) {
2619 union dmub_hw_lock_flags hw_locks = { 0 };
2620 struct dmub_hw_lock_inst_flags inst_flags = { 0 };
2622 hw_locks.bits.lock_dig = 1;
2623 inst_flags.dig_inst = top_pipe_to_program->stream_res.tg->inst;
2625 dmub_hw_lock_mgr_cmd(dc->ctx->dmub_srv,
2630 top_pipe_to_program->stream_res.tg->funcs->lock_doublebuffer_disable(
2631 top_pipe_to_program->stream_res.tg);
2634 if (update_type != UPDATE_TYPE_FAST)
2635 dc->hwss.post_unlock_program_front_end(dc, context);
2637 // Fire manual trigger only when bottom plane is flipped
2638 for (j = 0; j < dc->res_pool->pipe_count; j++) {
2639 struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[j];
2641 if (pipe_ctx->bottom_pipe || pipe_ctx->next_odm_pipe ||
2642 !pipe_ctx->stream || pipe_ctx->stream != stream ||
2643 !pipe_ctx->plane_state->update_flags.bits.addr_update)
2646 if (pipe_ctx->stream_res.tg->funcs->program_manual_trigger)
2647 pipe_ctx->stream_res.tg->funcs->program_manual_trigger(pipe_ctx->stream_res.tg);
2651 void dc_commit_updates_for_stream(struct dc *dc,
2652 struct dc_surface_update *srf_updates,
2654 struct dc_stream_state *stream,
2655 struct dc_stream_update *stream_update,
2656 struct dc_state *state)
2658 const struct dc_stream_status *stream_status;
2659 enum surface_update_type update_type;
2660 struct dc_state *context;
2661 struct dc_context *dc_ctx = dc->ctx;
2664 stream_status = dc_stream_get_status(stream);
2665 context = dc->current_state;
2667 update_type = dc_check_update_surfaces_for_stream(
2668 dc, srf_updates, surface_count, stream_update, stream_status);
2670 if (update_type >= update_surface_trace_level)
2671 update_surface_trace(dc, srf_updates, surface_count);
2674 if (update_type >= UPDATE_TYPE_FULL) {
2676 /* initialize scratch memory for building context */
2677 context = dc_create_state(dc);
2678 if (context == NULL) {
2679 DC_ERROR("Failed to allocate new validate context!\n");
2683 dc_resource_state_copy_construct(state, context);
2685 for (i = 0; i < dc->res_pool->pipe_count; i++) {
2686 struct pipe_ctx *new_pipe = &context->res_ctx.pipe_ctx[i];
2687 struct pipe_ctx *old_pipe = &dc->current_state->res_ctx.pipe_ctx[i];
2689 if (new_pipe->plane_state && new_pipe->plane_state != old_pipe->plane_state)
2690 new_pipe->plane_state->force_full_update = true;
2695 for (i = 0; i < surface_count; i++) {
2696 struct dc_plane_state *surface = srf_updates[i].surface;
2698 copy_surface_update_to_plane(surface, &srf_updates[i]);
2700 if (update_type >= UPDATE_TYPE_MED) {
2701 for (j = 0; j < dc->res_pool->pipe_count; j++) {
2702 struct pipe_ctx *pipe_ctx =
2703 &context->res_ctx.pipe_ctx[j];
2705 if (pipe_ctx->plane_state != surface)
2708 resource_build_scaling_params(pipe_ctx);
2713 copy_stream_update_to_stream(dc, context, stream, stream_update);
2715 if (update_type >= UPDATE_TYPE_FULL) {
2716 if (!dc->res_pool->funcs->validate_bandwidth(dc, context, false)) {
2717 DC_ERROR("Mode validation failed for stream update!\n");
2718 dc_release_state(context);
2723 TRACE_DC_PIPE_STATE(pipe_ctx, i, MAX_PIPES);
2725 commit_planes_for_stream(
2733 /*update current_State*/
2734 if (dc->current_state != context) {
2736 struct dc_state *old = dc->current_state;
2738 dc->current_state = context;
2739 dc_release_state(old);
2741 for (i = 0; i < dc->res_pool->pipe_count; i++) {
2742 struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[i];
2744 if (pipe_ctx->plane_state && pipe_ctx->stream == stream)
2745 pipe_ctx->plane_state->force_full_update = false;
2748 /*let's use current_state to update watermark etc*/
2749 if (update_type >= UPDATE_TYPE_FULL) {
2750 dc_post_update_surfaces_to_stream(dc);
2752 if (dc_ctx->dce_version >= DCE_VERSION_MAX)
2753 TRACE_DCN_CLOCK_STATE(&context->bw_ctx.bw.dcn.clk);
2755 TRACE_DCE_CLOCK_STATE(&context->bw_ctx.bw.dce);
2762 uint8_t dc_get_current_stream_count(struct dc *dc)
2764 return dc->current_state->stream_count;
2767 struct dc_stream_state *dc_get_stream_at_index(struct dc *dc, uint8_t i)
2769 if (i < dc->current_state->stream_count)
2770 return dc->current_state->streams[i];
2774 enum dc_irq_source dc_interrupt_to_irq_source(
2779 return dal_irq_service_to_irq_source(dc->res_pool->irqs, src_id, ext_id);
2783 * dc_interrupt_set() - Enable/disable an AMD hw interrupt source
2785 bool dc_interrupt_set(struct dc *dc, enum dc_irq_source src, bool enable)
2791 return dal_irq_service_set(dc->res_pool->irqs, src, enable);
2794 void dc_interrupt_ack(struct dc *dc, enum dc_irq_source src)
2796 dal_irq_service_ack(dc->res_pool->irqs, src);
2799 void dc_power_down_on_boot(struct dc *dc)
2801 if (dc->ctx->dce_environment != DCE_ENV_VIRTUAL_HW &&
2802 dc->hwss.power_down_on_boot)
2803 dc->hwss.power_down_on_boot(dc);
2806 void dc_set_power_state(
2808 enum dc_acpi_cm_power_state power_state)
2810 struct kref refcount;
2811 struct display_mode_lib *dml;
2813 switch (power_state) {
2814 case DC_ACPI_CM_POWER_STATE_D0:
2815 dc_resource_state_construct(dc, dc->current_state);
2817 if (dc->ctx->dmub_srv)
2818 dc_dmub_srv_wait_phy_init(dc->ctx->dmub_srv);
2820 dc->hwss.init_hw(dc);
2822 if (dc->hwss.init_sys_ctx != NULL &&
2823 dc->vm_pa_config.valid) {
2824 dc->hwss.init_sys_ctx(dc->hwseq, dc, &dc->vm_pa_config);
2829 ASSERT(dc->current_state->stream_count == 0);
2830 /* Zero out the current context so that on resume we start with
2831 * clean state, and dc hw programming optimizations will not
2832 * cause any trouble.
2834 dml = kzalloc(sizeof(struct display_mode_lib),
2841 /* Preserve refcount */
2842 refcount = dc->current_state->refcount;
2843 /* Preserve display mode lib */
2844 memcpy(dml, &dc->current_state->bw_ctx.dml, sizeof(struct display_mode_lib));
2846 dc_resource_state_destruct(dc->current_state);
2847 memset(dc->current_state, 0,
2848 sizeof(*dc->current_state));
2850 dc->current_state->refcount = refcount;
2851 dc->current_state->bw_ctx.dml = *dml;
2859 void dc_resume(struct dc *dc)
2863 for (i = 0; i < dc->link_count; i++)
2864 core_link_resume(dc->links[i]);
2867 bool dc_is_dmcu_initialized(struct dc *dc)
2869 struct dmcu *dmcu = dc->res_pool->dmcu;
2872 return dmcu->funcs->is_dmcu_initialized(dmcu);
2878 uint32_t link_index,
2879 struct i2c_command *cmd)
2882 struct dc_link *link = dc->links[link_index];
2883 struct ddc_service *ddc = link->ddc;
2884 return dce_i2c_submit_command(
2890 bool dc_submit_i2c_oem(
2892 struct i2c_command *cmd)
2894 struct ddc_service *ddc = dc->res_pool->oem_device;
2895 return dce_i2c_submit_command(
2901 static bool link_add_remote_sink_helper(struct dc_link *dc_link, struct dc_sink *sink)
2903 if (dc_link->sink_count >= MAX_SINKS_PER_LINK) {
2904 BREAK_TO_DEBUGGER();
2908 dc_sink_retain(sink);
2910 dc_link->remote_sinks[dc_link->sink_count] = sink;
2911 dc_link->sink_count++;
2917 * dc_link_add_remote_sink() - Create a sink and attach it to an existing link
2919 * EDID length is in bytes
2921 struct dc_sink *dc_link_add_remote_sink(
2922 struct dc_link *link,
2923 const uint8_t *edid,
2925 struct dc_sink_init_data *init_data)
2927 struct dc_sink *dc_sink;
2928 enum dc_edid_status edid_status;
2930 if (len > DC_MAX_EDID_BUFFER_SIZE) {
2931 dm_error("Max EDID buffer size breached!\n");
2936 BREAK_TO_DEBUGGER();
2940 if (!init_data->link) {
2941 BREAK_TO_DEBUGGER();
2945 dc_sink = dc_sink_create(init_data);
2950 memmove(dc_sink->dc_edid.raw_edid, edid, len);
2951 dc_sink->dc_edid.length = len;
2953 if (!link_add_remote_sink_helper(
2958 edid_status = dm_helpers_parse_edid_caps(
2961 &dc_sink->edid_caps);
2964 * Treat device as no EDID device if EDID
2967 if (edid_status != EDID_OK) {
2968 dc_sink->dc_edid.length = 0;
2969 dm_error("Bad EDID, status%d!\n", edid_status);
2975 dc_sink_release(dc_sink);
2980 * dc_link_remove_remote_sink() - Remove a remote sink from a dc_link
2982 * Note that this just removes the struct dc_sink - it doesn't
2983 * program hardware or alter other members of dc_link
2985 void dc_link_remove_remote_sink(struct dc_link *link, struct dc_sink *sink)
2989 if (!link->sink_count) {
2990 BREAK_TO_DEBUGGER();
2994 for (i = 0; i < link->sink_count; i++) {
2995 if (link->remote_sinks[i] == sink) {
2996 dc_sink_release(sink);
2997 link->remote_sinks[i] = NULL;
2999 /* shrink array to remove empty place */
3000 while (i < link->sink_count - 1) {
3001 link->remote_sinks[i] = link->remote_sinks[i+1];
3004 link->remote_sinks[i] = NULL;
3011 void get_clock_requirements_for_state(struct dc_state *state, struct AsicStateEx *info)
3013 info->displayClock = (unsigned int)state->bw_ctx.bw.dcn.clk.dispclk_khz;
3014 info->engineClock = (unsigned int)state->bw_ctx.bw.dcn.clk.dcfclk_khz;
3015 info->memoryClock = (unsigned int)state->bw_ctx.bw.dcn.clk.dramclk_khz;
3016 info->maxSupportedDppClock = (unsigned int)state->bw_ctx.bw.dcn.clk.max_supported_dppclk_khz;
3017 info->dppClock = (unsigned int)state->bw_ctx.bw.dcn.clk.dppclk_khz;
3018 info->socClock = (unsigned int)state->bw_ctx.bw.dcn.clk.socclk_khz;
3019 info->dcfClockDeepSleep = (unsigned int)state->bw_ctx.bw.dcn.clk.dcfclk_deep_sleep_khz;
3020 info->fClock = (unsigned int)state->bw_ctx.bw.dcn.clk.fclk_khz;
3021 info->phyClock = (unsigned int)state->bw_ctx.bw.dcn.clk.phyclk_khz;
3023 enum dc_status dc_set_clock(struct dc *dc, enum dc_clock_type clock_type, uint32_t clk_khz, uint32_t stepping)
3025 if (dc->hwss.set_clock)
3026 return dc->hwss.set_clock(dc, clock_type, clk_khz, stepping);
3027 return DC_ERROR_UNEXPECTED;
3029 void dc_get_clock(struct dc *dc, enum dc_clock_type clock_type, struct dc_clock_config *clock_cfg)
3031 if (dc->hwss.get_clock)
3032 dc->hwss.get_clock(dc, clock_type, clock_cfg);
3035 /* enable/disable eDP PSR without specify stream for eDP */
3036 bool dc_set_psr_allow_active(struct dc *dc, bool enable)
3040 for (i = 0; i < dc->current_state->stream_count ; i++) {
3041 struct dc_link *link;
3042 struct dc_stream_state *stream = dc->current_state->streams[i];
3044 link = stream->link;
3048 if (link->psr_settings.psr_feature_enabled) {
3049 if (enable && !link->psr_settings.psr_allow_active)
3050 return dc_link_set_psr_allow_active(link, true, false);
3051 else if (!enable && link->psr_settings.psr_allow_active)
3052 return dc_link_set_psr_allow_active(link, false, true);
3059 #if defined(CONFIG_DRM_AMD_DC_DCN3_0)
3061 void dc_allow_idle_optimizations(struct dc *dc, bool allow)
3063 if (dc->debug.disable_idle_power_optimizations)
3066 if (allow == dc->idle_optimizations_allowed)
3069 if (dc->hwss.apply_idle_power_optimizations && dc->hwss.apply_idle_power_optimizations(dc, allow))
3070 dc->idle_optimizations_allowed = allow;
3074 * blank all streams, and set min and max memory clock to
3075 * lowest and highest DPM level, respectively
3077 void dc_unlock_memory_clock_frequency(struct dc *dc)
3081 for (i = 0; i < MAX_PIPES; i++)
3082 if (dc->current_state->res_ctx.pipe_ctx[i].plane_state)
3083 core_link_disable_stream(&dc->current_state->res_ctx.pipe_ctx[i]);
3085 dc->clk_mgr->funcs->set_hard_min_memclk(dc->clk_mgr, false);
3086 dc->clk_mgr->funcs->set_hard_max_memclk(dc->clk_mgr);
3090 * set min memory clock to the min required for current mode,
3091 * max to maxDPM, and unblank streams
3093 void dc_lock_memory_clock_frequency(struct dc *dc)
3097 dc->clk_mgr->funcs->get_memclk_states_from_smu(dc->clk_mgr);
3098 dc->clk_mgr->funcs->set_hard_min_memclk(dc->clk_mgr, true);
3099 dc->clk_mgr->funcs->set_hard_max_memclk(dc->clk_mgr);
3101 for (i = 0; i < MAX_PIPES; i++)
3102 if (dc->current_state->res_ctx.pipe_ctx[i].plane_state)
3103 core_link_enable_stream(dc->current_state, &dc->current_state->res_ctx.pipe_ctx[i]);
3106 bool dc_is_plane_eligible_for_idle_optimizaitons(struct dc *dc,
3107 struct dc_plane_state *plane)
3112 /* cleanup on driver unload */
3113 void dc_hardware_release(struct dc *dc)
3115 if (dc->hwss.hardware_release)
3116 dc->hwss.hardware_release(dc);