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.
26 /* The caprices of the preprocessor require that this be declared right here */
27 #define CREATE_TRACE_POINTS
29 #include "dm_services_types.h"
31 #include "link_enc_cfg.h"
32 #include "dc/inc/core_types.h"
33 #include "dal_asic_id.h"
34 #include "dmub/dmub_srv.h"
35 #include "dc/inc/hw/dmcu.h"
36 #include "dc/inc/hw/abm.h"
37 #include "dc/dc_dmub_srv.h"
38 #include "dc/dc_edid_parser.h"
39 #include "dc/dc_stat.h"
40 #include "dc/dc_state.h"
41 #include "amdgpu_dm_trace.h"
42 #include "dpcd_defs.h"
43 #include "link/protocols/link_dpcd.h"
44 #include "link_service_types.h"
45 #include "link/protocols/link_dp_capability.h"
46 #include "link/protocols/link_ddc.h"
50 #include "amdgpu_display.h"
51 #include "amdgpu_ucode.h"
53 #include "amdgpu_dm.h"
54 #include "amdgpu_dm_plane.h"
55 #include "amdgpu_dm_crtc.h"
56 #include "amdgpu_dm_hdcp.h"
57 #include <drm/display/drm_hdcp_helper.h>
58 #include "amdgpu_dm_wb.h"
59 #include "amdgpu_pm.h"
60 #include "amdgpu_atombios.h"
62 #include "amd_shared.h"
63 #include "amdgpu_dm_irq.h"
64 #include "dm_helpers.h"
65 #include "amdgpu_dm_mst_types.h"
66 #if defined(CONFIG_DEBUG_FS)
67 #include "amdgpu_dm_debugfs.h"
69 #include "amdgpu_dm_psr.h"
70 #include "amdgpu_dm_replay.h"
72 #include "ivsrcid/ivsrcid_vislands30.h"
74 #include <linux/backlight.h>
75 #include <linux/module.h>
76 #include <linux/moduleparam.h>
77 #include <linux/types.h>
78 #include <linux/pm_runtime.h>
79 #include <linux/pci.h>
80 #include <linux/firmware.h>
81 #include <linux/component.h>
82 #include <linux/dmi.h>
84 #include <drm/display/drm_dp_mst_helper.h>
85 #include <drm/display/drm_hdmi_helper.h>
86 #include <drm/drm_atomic.h>
87 #include <drm/drm_atomic_uapi.h>
88 #include <drm/drm_atomic_helper.h>
89 #include <drm/drm_blend.h>
90 #include <drm/drm_fixed.h>
91 #include <drm/drm_fourcc.h>
92 #include <drm/drm_edid.h>
93 #include <drm/drm_eld.h>
94 #include <drm/drm_vblank.h>
95 #include <drm/drm_audio_component.h>
96 #include <drm/drm_gem_atomic_helper.h>
98 #include <acpi/video.h>
100 #include "ivsrcid/dcn/irqsrcs_dcn_1_0.h"
102 #include "dcn/dcn_1_0_offset.h"
103 #include "dcn/dcn_1_0_sh_mask.h"
104 #include "soc15_hw_ip.h"
105 #include "soc15_common.h"
106 #include "vega10_ip_offset.h"
108 #include "gc/gc_11_0_0_offset.h"
109 #include "gc/gc_11_0_0_sh_mask.h"
111 #include "modules/inc/mod_freesync.h"
112 #include "modules/power/power_helpers.h"
114 #define FIRMWARE_RENOIR_DMUB "amdgpu/renoir_dmcub.bin"
115 MODULE_FIRMWARE(FIRMWARE_RENOIR_DMUB);
116 #define FIRMWARE_SIENNA_CICHLID_DMUB "amdgpu/sienna_cichlid_dmcub.bin"
117 MODULE_FIRMWARE(FIRMWARE_SIENNA_CICHLID_DMUB);
118 #define FIRMWARE_NAVY_FLOUNDER_DMUB "amdgpu/navy_flounder_dmcub.bin"
119 MODULE_FIRMWARE(FIRMWARE_NAVY_FLOUNDER_DMUB);
120 #define FIRMWARE_GREEN_SARDINE_DMUB "amdgpu/green_sardine_dmcub.bin"
121 MODULE_FIRMWARE(FIRMWARE_GREEN_SARDINE_DMUB);
122 #define FIRMWARE_VANGOGH_DMUB "amdgpu/vangogh_dmcub.bin"
123 MODULE_FIRMWARE(FIRMWARE_VANGOGH_DMUB);
124 #define FIRMWARE_DIMGREY_CAVEFISH_DMUB "amdgpu/dimgrey_cavefish_dmcub.bin"
125 MODULE_FIRMWARE(FIRMWARE_DIMGREY_CAVEFISH_DMUB);
126 #define FIRMWARE_BEIGE_GOBY_DMUB "amdgpu/beige_goby_dmcub.bin"
127 MODULE_FIRMWARE(FIRMWARE_BEIGE_GOBY_DMUB);
128 #define FIRMWARE_YELLOW_CARP_DMUB "amdgpu/yellow_carp_dmcub.bin"
129 MODULE_FIRMWARE(FIRMWARE_YELLOW_CARP_DMUB);
130 #define FIRMWARE_DCN_314_DMUB "amdgpu/dcn_3_1_4_dmcub.bin"
131 MODULE_FIRMWARE(FIRMWARE_DCN_314_DMUB);
132 #define FIRMWARE_DCN_315_DMUB "amdgpu/dcn_3_1_5_dmcub.bin"
133 MODULE_FIRMWARE(FIRMWARE_DCN_315_DMUB);
134 #define FIRMWARE_DCN316_DMUB "amdgpu/dcn_3_1_6_dmcub.bin"
135 MODULE_FIRMWARE(FIRMWARE_DCN316_DMUB);
137 #define FIRMWARE_DCN_V3_2_0_DMCUB "amdgpu/dcn_3_2_0_dmcub.bin"
138 MODULE_FIRMWARE(FIRMWARE_DCN_V3_2_0_DMCUB);
139 #define FIRMWARE_DCN_V3_2_1_DMCUB "amdgpu/dcn_3_2_1_dmcub.bin"
140 MODULE_FIRMWARE(FIRMWARE_DCN_V3_2_1_DMCUB);
142 #define FIRMWARE_RAVEN_DMCU "amdgpu/raven_dmcu.bin"
143 MODULE_FIRMWARE(FIRMWARE_RAVEN_DMCU);
145 #define FIRMWARE_NAVI12_DMCU "amdgpu/navi12_dmcu.bin"
146 MODULE_FIRMWARE(FIRMWARE_NAVI12_DMCU);
148 #define FIRMWARE_DCN_35_DMUB "amdgpu/dcn_3_5_dmcub.bin"
149 MODULE_FIRMWARE(FIRMWARE_DCN_35_DMUB);
151 #define FIRMWARE_DCN_351_DMUB "amdgpu/dcn_3_5_1_dmcub.bin"
152 MODULE_FIRMWARE(FIRMWARE_DCN_351_DMUB);
154 /* Number of bytes in PSP header for firmware. */
155 #define PSP_HEADER_BYTES 0x100
157 /* Number of bytes in PSP footer for firmware. */
158 #define PSP_FOOTER_BYTES 0x100
163 * The AMDgpu display manager, **amdgpu_dm** (or even simpler,
164 * **dm**) sits between DRM and DC. It acts as a liaison, converting DRM
165 * requests into DC requests, and DC responses into DRM responses.
167 * The root control structure is &struct amdgpu_display_manager.
170 /* basic init/fini API */
171 static int amdgpu_dm_init(struct amdgpu_device *adev);
172 static void amdgpu_dm_fini(struct amdgpu_device *adev);
173 static bool is_freesync_video_mode(const struct drm_display_mode *mode, struct amdgpu_dm_connector *aconnector);
175 static enum drm_mode_subconnector get_subconnector_type(struct dc_link *link)
177 switch (link->dpcd_caps.dongle_type) {
178 case DISPLAY_DONGLE_NONE:
179 return DRM_MODE_SUBCONNECTOR_Native;
180 case DISPLAY_DONGLE_DP_VGA_CONVERTER:
181 return DRM_MODE_SUBCONNECTOR_VGA;
182 case DISPLAY_DONGLE_DP_DVI_CONVERTER:
183 case DISPLAY_DONGLE_DP_DVI_DONGLE:
184 return DRM_MODE_SUBCONNECTOR_DVID;
185 case DISPLAY_DONGLE_DP_HDMI_CONVERTER:
186 case DISPLAY_DONGLE_DP_HDMI_DONGLE:
187 return DRM_MODE_SUBCONNECTOR_HDMIA;
188 case DISPLAY_DONGLE_DP_HDMI_MISMATCHED_DONGLE:
190 return DRM_MODE_SUBCONNECTOR_Unknown;
194 static void update_subconnector_property(struct amdgpu_dm_connector *aconnector)
196 struct dc_link *link = aconnector->dc_link;
197 struct drm_connector *connector = &aconnector->base;
198 enum drm_mode_subconnector subconnector = DRM_MODE_SUBCONNECTOR_Unknown;
200 if (connector->connector_type != DRM_MODE_CONNECTOR_DisplayPort)
203 if (aconnector->dc_sink)
204 subconnector = get_subconnector_type(link);
206 drm_object_property_set_value(&connector->base,
207 connector->dev->mode_config.dp_subconnector_property,
212 * initializes drm_device display related structures, based on the information
213 * provided by DAL. The drm strcutures are: drm_crtc, drm_connector,
214 * drm_encoder, drm_mode_config
216 * Returns 0 on success
218 static int amdgpu_dm_initialize_drm_device(struct amdgpu_device *adev);
219 /* removes and deallocates the drm structures, created by the above function */
220 static void amdgpu_dm_destroy_drm_device(struct amdgpu_display_manager *dm);
222 static int amdgpu_dm_connector_init(struct amdgpu_display_manager *dm,
223 struct amdgpu_dm_connector *amdgpu_dm_connector,
225 struct amdgpu_encoder *amdgpu_encoder);
226 static int amdgpu_dm_encoder_init(struct drm_device *dev,
227 struct amdgpu_encoder *aencoder,
228 uint32_t link_index);
230 static int amdgpu_dm_connector_get_modes(struct drm_connector *connector);
232 static void amdgpu_dm_atomic_commit_tail(struct drm_atomic_state *state);
234 static int amdgpu_dm_atomic_check(struct drm_device *dev,
235 struct drm_atomic_state *state);
237 static void handle_hpd_irq_helper(struct amdgpu_dm_connector *aconnector);
238 static void handle_hpd_rx_irq(void *param);
241 is_timing_unchanged_for_freesync(struct drm_crtc_state *old_crtc_state,
242 struct drm_crtc_state *new_crtc_state);
244 * dm_vblank_get_counter
247 * Get counter for number of vertical blanks
250 * struct amdgpu_device *adev - [in] desired amdgpu device
251 * int disp_idx - [in] which CRTC to get the counter from
254 * Counter for vertical blanks
256 static u32 dm_vblank_get_counter(struct amdgpu_device *adev, int crtc)
258 struct amdgpu_crtc *acrtc = NULL;
260 if (crtc >= adev->mode_info.num_crtc)
263 acrtc = adev->mode_info.crtcs[crtc];
265 if (!acrtc->dm_irq_params.stream) {
266 DRM_ERROR("dc_stream_state is NULL for crtc '%d'!\n",
271 return dc_stream_get_vblank_counter(acrtc->dm_irq_params.stream);
274 static int dm_crtc_get_scanoutpos(struct amdgpu_device *adev, int crtc,
275 u32 *vbl, u32 *position)
277 u32 v_blank_start = 0, v_blank_end = 0, h_position = 0, v_position = 0;
278 struct amdgpu_crtc *acrtc = NULL;
279 struct dc *dc = adev->dm.dc;
281 if ((crtc < 0) || (crtc >= adev->mode_info.num_crtc))
284 acrtc = adev->mode_info.crtcs[crtc];
286 if (!acrtc->dm_irq_params.stream) {
287 DRM_ERROR("dc_stream_state is NULL for crtc '%d'!\n",
292 if (dc && dc->caps.ips_support && dc->idle_optimizations_allowed)
293 dc_allow_idle_optimizations(dc, false);
296 * TODO rework base driver to use values directly.
297 * for now parse it back into reg-format
299 dc_stream_get_scanoutpos(acrtc->dm_irq_params.stream,
305 *position = v_position | (h_position << 16);
306 *vbl = v_blank_start | (v_blank_end << 16);
311 static bool dm_is_idle(void *handle)
317 static int dm_wait_for_idle(void *handle)
323 static bool dm_check_soft_reset(void *handle)
328 static int dm_soft_reset(void *handle)
334 static struct amdgpu_crtc *
335 get_crtc_by_otg_inst(struct amdgpu_device *adev,
338 struct drm_device *dev = adev_to_drm(adev);
339 struct drm_crtc *crtc;
340 struct amdgpu_crtc *amdgpu_crtc;
342 if (WARN_ON(otg_inst == -1))
343 return adev->mode_info.crtcs[0];
345 list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
346 amdgpu_crtc = to_amdgpu_crtc(crtc);
348 if (amdgpu_crtc->otg_inst == otg_inst)
355 static inline bool is_dc_timing_adjust_needed(struct dm_crtc_state *old_state,
356 struct dm_crtc_state *new_state)
358 if (new_state->freesync_config.state == VRR_STATE_ACTIVE_FIXED)
360 else if (amdgpu_dm_crtc_vrr_active(old_state) != amdgpu_dm_crtc_vrr_active(new_state))
366 static inline void reverse_planes_order(struct dc_surface_update *array_of_surface_update,
371 for (i = 0, j = planes_count - 1; i < j; i++, j--)
372 swap(array_of_surface_update[i], array_of_surface_update[j]);
376 * update_planes_and_stream_adapter() - Send planes to be updated in DC
378 * DC has a generic way to update planes and stream via
379 * dc_update_planes_and_stream function; however, DM might need some
380 * adjustments and preparation before calling it. This function is a wrapper
381 * for the dc_update_planes_and_stream that does any required configuration
382 * before passing control to DC.
384 * @dc: Display Core control structure
385 * @update_type: specify whether it is FULL/MEDIUM/FAST update
386 * @planes_count: planes count to update
387 * @stream: stream state
388 * @stream_update: stream update
389 * @array_of_surface_update: dc surface update pointer
392 static inline bool update_planes_and_stream_adapter(struct dc *dc,
395 struct dc_stream_state *stream,
396 struct dc_stream_update *stream_update,
397 struct dc_surface_update *array_of_surface_update)
399 reverse_planes_order(array_of_surface_update, planes_count);
402 * Previous frame finished and HW is ready for optimization.
404 if (update_type == UPDATE_TYPE_FAST)
405 dc_post_update_surfaces_to_stream(dc);
407 return dc_update_planes_and_stream(dc,
408 array_of_surface_update,
415 * dm_pflip_high_irq() - Handle pageflip interrupt
416 * @interrupt_params: ignored
418 * Handles the pageflip interrupt by notifying all interested parties
419 * that the pageflip has been completed.
421 static void dm_pflip_high_irq(void *interrupt_params)
423 struct amdgpu_crtc *amdgpu_crtc;
424 struct common_irq_params *irq_params = interrupt_params;
425 struct amdgpu_device *adev = irq_params->adev;
426 struct drm_device *dev = adev_to_drm(adev);
428 struct drm_pending_vblank_event *e;
429 u32 vpos, hpos, v_blank_start, v_blank_end;
432 amdgpu_crtc = get_crtc_by_otg_inst(adev, irq_params->irq_src - IRQ_TYPE_PFLIP);
434 /* IRQ could occur when in initial stage */
435 /* TODO work and BO cleanup */
436 if (amdgpu_crtc == NULL) {
437 drm_dbg_state(dev, "CRTC is null, returning.\n");
441 spin_lock_irqsave(&adev_to_drm(adev)->event_lock, flags);
443 if (amdgpu_crtc->pflip_status != AMDGPU_FLIP_SUBMITTED) {
445 "amdgpu_crtc->pflip_status = %d != AMDGPU_FLIP_SUBMITTED(%d) on crtc:%d[%p]\n",
446 amdgpu_crtc->pflip_status, AMDGPU_FLIP_SUBMITTED,
447 amdgpu_crtc->crtc_id, amdgpu_crtc);
448 spin_unlock_irqrestore(&adev_to_drm(adev)->event_lock, flags);
452 /* page flip completed. */
453 e = amdgpu_crtc->event;
454 amdgpu_crtc->event = NULL;
458 vrr_active = amdgpu_dm_crtc_vrr_active_irq(amdgpu_crtc);
460 /* Fixed refresh rate, or VRR scanout position outside front-porch? */
462 !dc_stream_get_scanoutpos(amdgpu_crtc->dm_irq_params.stream, &v_blank_start,
463 &v_blank_end, &hpos, &vpos) ||
464 (vpos < v_blank_start)) {
465 /* Update to correct count and vblank timestamp if racing with
466 * vblank irq. This also updates to the correct vblank timestamp
467 * even in VRR mode, as scanout is past the front-porch atm.
469 drm_crtc_accurate_vblank_count(&amdgpu_crtc->base);
471 /* Wake up userspace by sending the pageflip event with proper
472 * count and timestamp of vblank of flip completion.
475 drm_crtc_send_vblank_event(&amdgpu_crtc->base, e);
477 /* Event sent, so done with vblank for this flip */
478 drm_crtc_vblank_put(&amdgpu_crtc->base);
481 /* VRR active and inside front-porch: vblank count and
482 * timestamp for pageflip event will only be up to date after
483 * drm_crtc_handle_vblank() has been executed from late vblank
484 * irq handler after start of back-porch (vline 0). We queue the
485 * pageflip event for send-out by drm_crtc_handle_vblank() with
486 * updated timestamp and count, once it runs after us.
488 * We need to open-code this instead of using the helper
489 * drm_crtc_arm_vblank_event(), as that helper would
490 * call drm_crtc_accurate_vblank_count(), which we must
491 * not call in VRR mode while we are in front-porch!
494 /* sequence will be replaced by real count during send-out. */
495 e->sequence = drm_crtc_vblank_count(&amdgpu_crtc->base);
496 e->pipe = amdgpu_crtc->crtc_id;
498 list_add_tail(&e->base.link, &adev_to_drm(adev)->vblank_event_list);
502 /* Keep track of vblank of this flip for flip throttling. We use the
503 * cooked hw counter, as that one incremented at start of this vblank
504 * of pageflip completion, so last_flip_vblank is the forbidden count
505 * for queueing new pageflips if vsync + VRR is enabled.
507 amdgpu_crtc->dm_irq_params.last_flip_vblank =
508 amdgpu_get_vblank_counter_kms(&amdgpu_crtc->base);
510 amdgpu_crtc->pflip_status = AMDGPU_FLIP_NONE;
511 spin_unlock_irqrestore(&adev_to_drm(adev)->event_lock, flags);
514 "crtc:%d[%p], pflip_stat:AMDGPU_FLIP_NONE, vrr[%d]-fp %d\n",
515 amdgpu_crtc->crtc_id, amdgpu_crtc, vrr_active, (int)!e);
518 static void dm_vupdate_high_irq(void *interrupt_params)
520 struct common_irq_params *irq_params = interrupt_params;
521 struct amdgpu_device *adev = irq_params->adev;
522 struct amdgpu_crtc *acrtc;
523 struct drm_device *drm_dev;
524 struct drm_vblank_crtc *vblank;
525 ktime_t frame_duration_ns, previous_timestamp;
529 acrtc = get_crtc_by_otg_inst(adev, irq_params->irq_src - IRQ_TYPE_VUPDATE);
532 vrr_active = amdgpu_dm_crtc_vrr_active_irq(acrtc);
533 drm_dev = acrtc->base.dev;
534 vblank = &drm_dev->vblank[acrtc->base.index];
535 previous_timestamp = atomic64_read(&irq_params->previous_timestamp);
536 frame_duration_ns = vblank->time - previous_timestamp;
538 if (frame_duration_ns > 0) {
539 trace_amdgpu_refresh_rate_track(acrtc->base.index,
541 ktime_divns(NSEC_PER_SEC, frame_duration_ns));
542 atomic64_set(&irq_params->previous_timestamp, vblank->time);
546 "crtc:%d, vupdate-vrr:%d\n", acrtc->crtc_id,
549 /* Core vblank handling is done here after end of front-porch in
550 * vrr mode, as vblank timestamping will give valid results
551 * while now done after front-porch. This will also deliver
552 * page-flip completion events that have been queued to us
553 * if a pageflip happened inside front-porch.
556 amdgpu_dm_crtc_handle_vblank(acrtc);
558 /* BTR processing for pre-DCE12 ASICs */
559 if (acrtc->dm_irq_params.stream &&
560 adev->family < AMDGPU_FAMILY_AI) {
561 spin_lock_irqsave(&adev_to_drm(adev)->event_lock, flags);
562 mod_freesync_handle_v_update(
563 adev->dm.freesync_module,
564 acrtc->dm_irq_params.stream,
565 &acrtc->dm_irq_params.vrr_params);
567 dc_stream_adjust_vmin_vmax(
569 acrtc->dm_irq_params.stream,
570 &acrtc->dm_irq_params.vrr_params.adjust);
571 spin_unlock_irqrestore(&adev_to_drm(adev)->event_lock, flags);
578 * dm_crtc_high_irq() - Handles CRTC interrupt
579 * @interrupt_params: used for determining the CRTC instance
581 * Handles the CRTC/VSYNC interrupt by notfying DRM's VBLANK
584 static void dm_crtc_high_irq(void *interrupt_params)
586 struct common_irq_params *irq_params = interrupt_params;
587 struct amdgpu_device *adev = irq_params->adev;
588 struct drm_writeback_job *job;
589 struct amdgpu_crtc *acrtc;
593 acrtc = get_crtc_by_otg_inst(adev, irq_params->irq_src - IRQ_TYPE_VBLANK);
597 if (acrtc->wb_pending) {
598 if (acrtc->wb_conn) {
599 spin_lock_irqsave(&acrtc->wb_conn->job_lock, flags);
600 job = list_first_entry_or_null(&acrtc->wb_conn->job_queue,
601 struct drm_writeback_job,
603 spin_unlock_irqrestore(&acrtc->wb_conn->job_lock, flags);
606 unsigned int v_total, refresh_hz;
607 struct dc_stream_state *stream = acrtc->dm_irq_params.stream;
609 v_total = stream->adjust.v_total_max ?
610 stream->adjust.v_total_max : stream->timing.v_total;
611 refresh_hz = div_u64((uint64_t) stream->timing.pix_clk_100hz *
612 100LL, (v_total * stream->timing.h_total));
613 mdelay(1000 / refresh_hz);
615 drm_writeback_signal_completion(acrtc->wb_conn, 0);
616 dc_stream_fc_disable_writeback(adev->dm.dc,
617 acrtc->dm_irq_params.stream, 0);
620 DRM_ERROR("%s: no amdgpu_crtc wb_conn\n", __func__);
621 acrtc->wb_pending = false;
624 vrr_active = amdgpu_dm_crtc_vrr_active_irq(acrtc);
626 drm_dbg_vbl(adev_to_drm(adev),
627 "crtc:%d, vupdate-vrr:%d, planes:%d\n", acrtc->crtc_id,
628 vrr_active, acrtc->dm_irq_params.active_planes);
631 * Core vblank handling at start of front-porch is only possible
632 * in non-vrr mode, as only there vblank timestamping will give
633 * valid results while done in front-porch. Otherwise defer it
634 * to dm_vupdate_high_irq after end of front-porch.
637 amdgpu_dm_crtc_handle_vblank(acrtc);
640 * Following stuff must happen at start of vblank, for crc
641 * computation and below-the-range btr support in vrr mode.
643 amdgpu_dm_crtc_handle_crc_irq(&acrtc->base);
645 /* BTR updates need to happen before VUPDATE on Vega and above. */
646 if (adev->family < AMDGPU_FAMILY_AI)
649 spin_lock_irqsave(&adev_to_drm(adev)->event_lock, flags);
651 if (acrtc->dm_irq_params.stream &&
652 acrtc->dm_irq_params.vrr_params.supported &&
653 acrtc->dm_irq_params.freesync_config.state ==
654 VRR_STATE_ACTIVE_VARIABLE) {
655 mod_freesync_handle_v_update(adev->dm.freesync_module,
656 acrtc->dm_irq_params.stream,
657 &acrtc->dm_irq_params.vrr_params);
659 dc_stream_adjust_vmin_vmax(adev->dm.dc, acrtc->dm_irq_params.stream,
660 &acrtc->dm_irq_params.vrr_params.adjust);
664 * If there aren't any active_planes then DCH HUBP may be clock-gated.
665 * In that case, pageflip completion interrupts won't fire and pageflip
666 * completion events won't get delivered. Prevent this by sending
667 * pending pageflip events from here if a flip is still pending.
669 * If any planes are enabled, use dm_pflip_high_irq() instead, to
670 * avoid race conditions between flip programming and completion,
671 * which could cause too early flip completion events.
673 if (adev->family >= AMDGPU_FAMILY_RV &&
674 acrtc->pflip_status == AMDGPU_FLIP_SUBMITTED &&
675 acrtc->dm_irq_params.active_planes == 0) {
677 drm_crtc_send_vblank_event(&acrtc->base, acrtc->event);
679 drm_crtc_vblank_put(&acrtc->base);
681 acrtc->pflip_status = AMDGPU_FLIP_NONE;
684 spin_unlock_irqrestore(&adev_to_drm(adev)->event_lock, flags);
687 #if defined(CONFIG_DRM_AMD_SECURE_DISPLAY)
689 * dm_dcn_vertical_interrupt0_high_irq() - Handles OTG Vertical interrupt0 for
690 * DCN generation ASICs
691 * @interrupt_params: interrupt parameters
693 * Used to set crc window/read out crc value at vertical line 0 position
695 static void dm_dcn_vertical_interrupt0_high_irq(void *interrupt_params)
697 struct common_irq_params *irq_params = interrupt_params;
698 struct amdgpu_device *adev = irq_params->adev;
699 struct amdgpu_crtc *acrtc;
701 acrtc = get_crtc_by_otg_inst(adev, irq_params->irq_src - IRQ_TYPE_VLINE0);
706 amdgpu_dm_crtc_handle_crc_window_irq(&acrtc->base);
708 #endif /* CONFIG_DRM_AMD_SECURE_DISPLAY */
711 * dmub_aux_setconfig_callback - Callback for AUX or SET_CONFIG command.
712 * @adev: amdgpu_device pointer
713 * @notify: dmub notification structure
715 * Dmub AUX or SET_CONFIG command completion processing callback
716 * Copies dmub notification to DM which is to be read by AUX command.
717 * issuing thread and also signals the event to wake up the thread.
719 static void dmub_aux_setconfig_callback(struct amdgpu_device *adev,
720 struct dmub_notification *notify)
722 if (adev->dm.dmub_notify)
723 memcpy(adev->dm.dmub_notify, notify, sizeof(struct dmub_notification));
724 if (notify->type == DMUB_NOTIFICATION_AUX_REPLY)
725 complete(&adev->dm.dmub_aux_transfer_done);
729 * dmub_hpd_callback - DMUB HPD interrupt processing callback.
730 * @adev: amdgpu_device pointer
731 * @notify: dmub notification structure
733 * Dmub Hpd interrupt processing callback. Gets displayindex through the
734 * ink index and calls helper to do the processing.
736 static void dmub_hpd_callback(struct amdgpu_device *adev,
737 struct dmub_notification *notify)
739 struct amdgpu_dm_connector *aconnector;
740 struct amdgpu_dm_connector *hpd_aconnector = NULL;
741 struct drm_connector *connector;
742 struct drm_connector_list_iter iter;
743 struct dc_link *link;
745 struct drm_device *dev;
750 if (notify == NULL) {
751 DRM_ERROR("DMUB HPD callback notification was NULL");
755 if (notify->link_index > adev->dm.dc->link_count) {
756 DRM_ERROR("DMUB HPD index (%u)is abnormal", notify->link_index);
760 link_index = notify->link_index;
761 link = adev->dm.dc->links[link_index];
764 drm_connector_list_iter_begin(dev, &iter);
765 drm_for_each_connector_iter(connector, &iter) {
767 if (connector->connector_type == DRM_MODE_CONNECTOR_WRITEBACK)
770 aconnector = to_amdgpu_dm_connector(connector);
771 if (link && aconnector->dc_link == link) {
772 if (notify->type == DMUB_NOTIFICATION_HPD)
773 DRM_INFO("DMUB HPD callback: link_index=%u\n", link_index);
774 else if (notify->type == DMUB_NOTIFICATION_HPD_IRQ)
775 DRM_INFO("DMUB HPD IRQ callback: link_index=%u\n", link_index);
777 DRM_WARN("DMUB Unknown HPD callback type %d, link_index=%u\n",
778 notify->type, link_index);
780 hpd_aconnector = aconnector;
784 drm_connector_list_iter_end(&iter);
786 if (hpd_aconnector) {
787 if (notify->type == DMUB_NOTIFICATION_HPD)
788 handle_hpd_irq_helper(hpd_aconnector);
789 else if (notify->type == DMUB_NOTIFICATION_HPD_IRQ)
790 handle_hpd_rx_irq(hpd_aconnector);
795 * register_dmub_notify_callback - Sets callback for DMUB notify
796 * @adev: amdgpu_device pointer
797 * @type: Type of dmub notification
798 * @callback: Dmub interrupt callback function
799 * @dmub_int_thread_offload: offload indicator
801 * API to register a dmub callback handler for a dmub notification
802 * Also sets indicator whether callback processing to be offloaded.
803 * to dmub interrupt handling thread
804 * Return: true if successfully registered, false if there is existing registration
806 static bool register_dmub_notify_callback(struct amdgpu_device *adev,
807 enum dmub_notification_type type,
808 dmub_notify_interrupt_callback_t callback,
809 bool dmub_int_thread_offload)
811 if (callback != NULL && type < ARRAY_SIZE(adev->dm.dmub_thread_offload)) {
812 adev->dm.dmub_callback[type] = callback;
813 adev->dm.dmub_thread_offload[type] = dmub_int_thread_offload;
820 static void dm_handle_hpd_work(struct work_struct *work)
822 struct dmub_hpd_work *dmub_hpd_wrk;
824 dmub_hpd_wrk = container_of(work, struct dmub_hpd_work, handle_hpd_work);
826 if (!dmub_hpd_wrk->dmub_notify) {
827 DRM_ERROR("dmub_hpd_wrk dmub_notify is NULL");
831 if (dmub_hpd_wrk->dmub_notify->type < ARRAY_SIZE(dmub_hpd_wrk->adev->dm.dmub_callback)) {
832 dmub_hpd_wrk->adev->dm.dmub_callback[dmub_hpd_wrk->dmub_notify->type](dmub_hpd_wrk->adev,
833 dmub_hpd_wrk->dmub_notify);
836 kfree(dmub_hpd_wrk->dmub_notify);
841 #define DMUB_TRACE_MAX_READ 64
843 * dm_dmub_outbox1_low_irq() - Handles Outbox interrupt
844 * @interrupt_params: used for determining the Outbox instance
846 * Handles the Outbox Interrupt
849 static void dm_dmub_outbox1_low_irq(void *interrupt_params)
851 struct dmub_notification notify = {0};
852 struct common_irq_params *irq_params = interrupt_params;
853 struct amdgpu_device *adev = irq_params->adev;
854 struct amdgpu_display_manager *dm = &adev->dm;
855 struct dmcub_trace_buf_entry entry = { 0 };
857 struct dmub_hpd_work *dmub_hpd_wrk;
858 struct dc_link *plink = NULL;
860 if (dc_enable_dmub_notifications(adev->dm.dc) &&
861 irq_params->irq_src == DC_IRQ_SOURCE_DMCUB_OUTBOX) {
864 dc_stat_get_dmub_notification(adev->dm.dc, ¬ify);
865 if (notify.type >= ARRAY_SIZE(dm->dmub_thread_offload)) {
866 DRM_ERROR("DM: notify type %d invalid!", notify.type);
869 if (!dm->dmub_callback[notify.type]) {
870 DRM_DEBUG_DRIVER("DMUB notification skipped, no handler: type=%d\n", notify.type);
873 if (dm->dmub_thread_offload[notify.type] == true) {
874 dmub_hpd_wrk = kzalloc(sizeof(*dmub_hpd_wrk), GFP_ATOMIC);
876 DRM_ERROR("Failed to allocate dmub_hpd_wrk");
879 dmub_hpd_wrk->dmub_notify = kmemdup(¬ify, sizeof(struct dmub_notification),
881 if (!dmub_hpd_wrk->dmub_notify) {
883 DRM_ERROR("Failed to allocate dmub_hpd_wrk->dmub_notify");
886 INIT_WORK(&dmub_hpd_wrk->handle_hpd_work, dm_handle_hpd_work);
887 dmub_hpd_wrk->adev = adev;
888 if (notify.type == DMUB_NOTIFICATION_HPD) {
889 plink = adev->dm.dc->links[notify.link_index];
892 notify.hpd_status == DP_HPD_PLUG;
895 queue_work(adev->dm.delayed_hpd_wq, &dmub_hpd_wrk->handle_hpd_work);
897 dm->dmub_callback[notify.type](adev, ¬ify);
899 } while (notify.pending_notification);
904 if (dc_dmub_srv_get_dmub_outbox0_msg(dm->dc, &entry)) {
905 trace_amdgpu_dmub_trace_high_irq(entry.trace_code, entry.tick_count,
906 entry.param0, entry.param1);
908 DRM_DEBUG_DRIVER("trace_code:%u, tick_count:%u, param0:%u, param1:%u\n",
909 entry.trace_code, entry.tick_count, entry.param0, entry.param1);
915 } while (count <= DMUB_TRACE_MAX_READ);
917 if (count > DMUB_TRACE_MAX_READ)
918 DRM_DEBUG_DRIVER("Warning : count > DMUB_TRACE_MAX_READ");
921 static int dm_set_clockgating_state(void *handle,
922 enum amd_clockgating_state state)
927 static int dm_set_powergating_state(void *handle,
928 enum amd_powergating_state state)
933 /* Prototypes of private functions */
934 static int dm_early_init(void *handle);
936 /* Allocate memory for FBC compressed data */
937 static void amdgpu_dm_fbc_init(struct drm_connector *connector)
939 struct amdgpu_device *adev = drm_to_adev(connector->dev);
940 struct dm_compressor_info *compressor = &adev->dm.compressor;
941 struct amdgpu_dm_connector *aconn = to_amdgpu_dm_connector(connector);
942 struct drm_display_mode *mode;
943 unsigned long max_size = 0;
945 if (adev->dm.dc->fbc_compressor == NULL)
948 if (aconn->dc_link->connector_signal != SIGNAL_TYPE_EDP)
951 if (compressor->bo_ptr)
955 list_for_each_entry(mode, &connector->modes, head) {
956 if (max_size < mode->htotal * mode->vtotal)
957 max_size = mode->htotal * mode->vtotal;
961 int r = amdgpu_bo_create_kernel(adev, max_size * 4, PAGE_SIZE,
962 AMDGPU_GEM_DOMAIN_GTT, &compressor->bo_ptr,
963 &compressor->gpu_addr, &compressor->cpu_addr);
966 DRM_ERROR("DM: Failed to initialize FBC\n");
968 adev->dm.dc->ctx->fbc_gpu_addr = compressor->gpu_addr;
969 DRM_INFO("DM: FBC alloc %lu\n", max_size*4);
976 static int amdgpu_dm_audio_component_get_eld(struct device *kdev, int port,
977 int pipe, bool *enabled,
978 unsigned char *buf, int max_bytes)
980 struct drm_device *dev = dev_get_drvdata(kdev);
981 struct amdgpu_device *adev = drm_to_adev(dev);
982 struct drm_connector *connector;
983 struct drm_connector_list_iter conn_iter;
984 struct amdgpu_dm_connector *aconnector;
989 mutex_lock(&adev->dm.audio_lock);
991 drm_connector_list_iter_begin(dev, &conn_iter);
992 drm_for_each_connector_iter(connector, &conn_iter) {
994 if (connector->connector_type == DRM_MODE_CONNECTOR_WRITEBACK)
997 aconnector = to_amdgpu_dm_connector(connector);
998 if (aconnector->audio_inst != port)
1002 ret = drm_eld_size(connector->eld);
1003 memcpy(buf, connector->eld, min(max_bytes, ret));
1007 drm_connector_list_iter_end(&conn_iter);
1009 mutex_unlock(&adev->dm.audio_lock);
1011 DRM_DEBUG_KMS("Get ELD : idx=%d ret=%d en=%d\n", port, ret, *enabled);
1016 static const struct drm_audio_component_ops amdgpu_dm_audio_component_ops = {
1017 .get_eld = amdgpu_dm_audio_component_get_eld,
1020 static int amdgpu_dm_audio_component_bind(struct device *kdev,
1021 struct device *hda_kdev, void *data)
1023 struct drm_device *dev = dev_get_drvdata(kdev);
1024 struct amdgpu_device *adev = drm_to_adev(dev);
1025 struct drm_audio_component *acomp = data;
1027 acomp->ops = &amdgpu_dm_audio_component_ops;
1029 adev->dm.audio_component = acomp;
1034 static void amdgpu_dm_audio_component_unbind(struct device *kdev,
1035 struct device *hda_kdev, void *data)
1037 struct amdgpu_device *adev = drm_to_adev(dev_get_drvdata(kdev));
1038 struct drm_audio_component *acomp = data;
1042 adev->dm.audio_component = NULL;
1045 static const struct component_ops amdgpu_dm_audio_component_bind_ops = {
1046 .bind = amdgpu_dm_audio_component_bind,
1047 .unbind = amdgpu_dm_audio_component_unbind,
1050 static int amdgpu_dm_audio_init(struct amdgpu_device *adev)
1057 adev->mode_info.audio.enabled = true;
1059 adev->mode_info.audio.num_pins = adev->dm.dc->res_pool->audio_count;
1061 for (i = 0; i < adev->mode_info.audio.num_pins; i++) {
1062 adev->mode_info.audio.pin[i].channels = -1;
1063 adev->mode_info.audio.pin[i].rate = -1;
1064 adev->mode_info.audio.pin[i].bits_per_sample = -1;
1065 adev->mode_info.audio.pin[i].status_bits = 0;
1066 adev->mode_info.audio.pin[i].category_code = 0;
1067 adev->mode_info.audio.pin[i].connected = false;
1068 adev->mode_info.audio.pin[i].id =
1069 adev->dm.dc->res_pool->audios[i]->inst;
1070 adev->mode_info.audio.pin[i].offset = 0;
1073 ret = component_add(adev->dev, &amdgpu_dm_audio_component_bind_ops);
1077 adev->dm.audio_registered = true;
1082 static void amdgpu_dm_audio_fini(struct amdgpu_device *adev)
1087 if (!adev->mode_info.audio.enabled)
1090 if (adev->dm.audio_registered) {
1091 component_del(adev->dev, &amdgpu_dm_audio_component_bind_ops);
1092 adev->dm.audio_registered = false;
1095 /* TODO: Disable audio? */
1097 adev->mode_info.audio.enabled = false;
1100 static void amdgpu_dm_audio_eld_notify(struct amdgpu_device *adev, int pin)
1102 struct drm_audio_component *acomp = adev->dm.audio_component;
1104 if (acomp && acomp->audio_ops && acomp->audio_ops->pin_eld_notify) {
1105 DRM_DEBUG_KMS("Notify ELD: %d\n", pin);
1107 acomp->audio_ops->pin_eld_notify(acomp->audio_ops->audio_ptr,
1112 static int dm_dmub_hw_init(struct amdgpu_device *adev)
1114 const struct dmcub_firmware_header_v1_0 *hdr;
1115 struct dmub_srv *dmub_srv = adev->dm.dmub_srv;
1116 struct dmub_srv_fb_info *fb_info = adev->dm.dmub_fb_info;
1117 const struct firmware *dmub_fw = adev->dm.dmub_fw;
1118 struct dmcu *dmcu = adev->dm.dc->res_pool->dmcu;
1119 struct abm *abm = adev->dm.dc->res_pool->abm;
1120 struct dc_context *ctx = adev->dm.dc->ctx;
1121 struct dmub_srv_hw_params hw_params;
1122 enum dmub_status status;
1123 const unsigned char *fw_inst_const, *fw_bss_data;
1124 u32 i, fw_inst_const_size, fw_bss_data_size;
1125 bool has_hw_support;
1128 /* DMUB isn't supported on the ASIC. */
1132 DRM_ERROR("No framebuffer info for DMUB service.\n");
1137 /* Firmware required for DMUB support. */
1138 DRM_ERROR("No firmware provided for DMUB.\n");
1142 /* initialize register offsets for ASICs with runtime initialization available */
1143 if (dmub_srv->hw_funcs.init_reg_offsets)
1144 dmub_srv->hw_funcs.init_reg_offsets(dmub_srv, ctx);
1146 status = dmub_srv_has_hw_support(dmub_srv, &has_hw_support);
1147 if (status != DMUB_STATUS_OK) {
1148 DRM_ERROR("Error checking HW support for DMUB: %d\n", status);
1152 if (!has_hw_support) {
1153 DRM_INFO("DMUB unsupported on ASIC\n");
1157 /* Reset DMCUB if it was previously running - before we overwrite its memory. */
1158 status = dmub_srv_hw_reset(dmub_srv);
1159 if (status != DMUB_STATUS_OK)
1160 DRM_WARN("Error resetting DMUB HW: %d\n", status);
1162 hdr = (const struct dmcub_firmware_header_v1_0 *)dmub_fw->data;
1164 fw_inst_const = dmub_fw->data +
1165 le32_to_cpu(hdr->header.ucode_array_offset_bytes) +
1168 fw_bss_data = dmub_fw->data +
1169 le32_to_cpu(hdr->header.ucode_array_offset_bytes) +
1170 le32_to_cpu(hdr->inst_const_bytes);
1172 /* Copy firmware and bios info into FB memory. */
1173 fw_inst_const_size = le32_to_cpu(hdr->inst_const_bytes) -
1174 PSP_HEADER_BYTES - PSP_FOOTER_BYTES;
1176 fw_bss_data_size = le32_to_cpu(hdr->bss_data_bytes);
1178 /* if adev->firmware.load_type == AMDGPU_FW_LOAD_PSP,
1179 * amdgpu_ucode_init_single_fw will load dmub firmware
1180 * fw_inst_const part to cw0; otherwise, the firmware back door load
1181 * will be done by dm_dmub_hw_init
1183 if (adev->firmware.load_type != AMDGPU_FW_LOAD_PSP) {
1184 memcpy(fb_info->fb[DMUB_WINDOW_0_INST_CONST].cpu_addr, fw_inst_const,
1185 fw_inst_const_size);
1188 if (fw_bss_data_size)
1189 memcpy(fb_info->fb[DMUB_WINDOW_2_BSS_DATA].cpu_addr,
1190 fw_bss_data, fw_bss_data_size);
1192 /* Copy firmware bios info into FB memory. */
1193 memcpy(fb_info->fb[DMUB_WINDOW_3_VBIOS].cpu_addr, adev->bios,
1196 /* Reset regions that need to be reset. */
1197 memset(fb_info->fb[DMUB_WINDOW_4_MAILBOX].cpu_addr, 0,
1198 fb_info->fb[DMUB_WINDOW_4_MAILBOX].size);
1200 memset(fb_info->fb[DMUB_WINDOW_5_TRACEBUFF].cpu_addr, 0,
1201 fb_info->fb[DMUB_WINDOW_5_TRACEBUFF].size);
1203 memset(fb_info->fb[DMUB_WINDOW_6_FW_STATE].cpu_addr, 0,
1204 fb_info->fb[DMUB_WINDOW_6_FW_STATE].size);
1206 /* Initialize hardware. */
1207 memset(&hw_params, 0, sizeof(hw_params));
1208 hw_params.fb_base = adev->gmc.fb_start;
1209 hw_params.fb_offset = adev->vm_manager.vram_base_offset;
1211 /* backdoor load firmware and trigger dmub running */
1212 if (adev->firmware.load_type != AMDGPU_FW_LOAD_PSP)
1213 hw_params.load_inst_const = true;
1216 hw_params.psp_version = dmcu->psp_version;
1218 for (i = 0; i < fb_info->num_fb; ++i)
1219 hw_params.fb[i] = &fb_info->fb[i];
1221 switch (amdgpu_ip_version(adev, DCE_HWIP, 0)) {
1222 case IP_VERSION(3, 1, 3):
1223 case IP_VERSION(3, 1, 4):
1224 case IP_VERSION(3, 5, 0):
1225 case IP_VERSION(3, 5, 1):
1226 hw_params.dpia_supported = true;
1227 hw_params.disable_dpia = adev->dm.dc->debug.dpia_debug.bits.disable_dpia;
1233 switch (amdgpu_ip_version(adev, DCE_HWIP, 0)) {
1234 case IP_VERSION(3, 5, 0):
1235 case IP_VERSION(3, 5, 1):
1236 hw_params.ips_sequential_ono = adev->external_rev_id > 0x10;
1242 status = dmub_srv_hw_init(dmub_srv, &hw_params);
1243 if (status != DMUB_STATUS_OK) {
1244 DRM_ERROR("Error initializing DMUB HW: %d\n", status);
1248 /* Wait for firmware load to finish. */
1249 status = dmub_srv_wait_for_auto_load(dmub_srv, 100000);
1250 if (status != DMUB_STATUS_OK)
1251 DRM_WARN("Wait for DMUB auto-load failed: %d\n", status);
1253 /* Init DMCU and ABM if available. */
1255 dmcu->funcs->dmcu_init(dmcu);
1256 abm->dmcu_is_running = dmcu->funcs->is_dmcu_initialized(dmcu);
1259 if (!adev->dm.dc->ctx->dmub_srv)
1260 adev->dm.dc->ctx->dmub_srv = dc_dmub_srv_create(adev->dm.dc, dmub_srv);
1261 if (!adev->dm.dc->ctx->dmub_srv) {
1262 DRM_ERROR("Couldn't allocate DC DMUB server!\n");
1266 DRM_INFO("DMUB hardware initialized: version=0x%08X\n",
1267 adev->dm.dmcub_fw_version);
1272 static void dm_dmub_hw_resume(struct amdgpu_device *adev)
1274 struct dmub_srv *dmub_srv = adev->dm.dmub_srv;
1275 enum dmub_status status;
1279 /* DMUB isn't supported on the ASIC. */
1283 status = dmub_srv_is_hw_init(dmub_srv, &init);
1284 if (status != DMUB_STATUS_OK)
1285 DRM_WARN("DMUB hardware init check failed: %d\n", status);
1287 if (status == DMUB_STATUS_OK && init) {
1288 /* Wait for firmware load to finish. */
1289 status = dmub_srv_wait_for_auto_load(dmub_srv, 100000);
1290 if (status != DMUB_STATUS_OK)
1291 DRM_WARN("Wait for DMUB auto-load failed: %d\n", status);
1293 /* Perform the full hardware initialization. */
1294 dm_dmub_hw_init(adev);
1298 static void mmhub_read_system_context(struct amdgpu_device *adev, struct dc_phy_addr_space_config *pa_config)
1301 u32 logical_addr_low;
1302 u32 logical_addr_high;
1303 u32 agp_base, agp_bot, agp_top;
1304 PHYSICAL_ADDRESS_LOC page_table_start, page_table_end, page_table_base;
1306 memset(pa_config, 0, sizeof(*pa_config));
1309 agp_bot = adev->gmc.agp_start >> 24;
1310 agp_top = adev->gmc.agp_end >> 24;
1312 /* AGP aperture is disabled */
1313 if (agp_bot > agp_top) {
1314 logical_addr_low = adev->gmc.fb_start >> 18;
1315 if (adev->apu_flags & (AMD_APU_IS_RAVEN2 |
1317 AMD_APU_IS_GREEN_SARDINE))
1319 * Raven2 has a HW issue that it is unable to use the vram which
1320 * is out of MC_VM_SYSTEM_APERTURE_HIGH_ADDR. So here is the
1321 * workaround that increase system aperture high address (add 1)
1322 * to get rid of the VM fault and hardware hang.
1324 logical_addr_high = (adev->gmc.fb_end >> 18) + 0x1;
1326 logical_addr_high = adev->gmc.fb_end >> 18;
1328 logical_addr_low = min(adev->gmc.fb_start, adev->gmc.agp_start) >> 18;
1329 if (adev->apu_flags & (AMD_APU_IS_RAVEN2 |
1331 AMD_APU_IS_GREEN_SARDINE))
1333 * Raven2 has a HW issue that it is unable to use the vram which
1334 * is out of MC_VM_SYSTEM_APERTURE_HIGH_ADDR. So here is the
1335 * workaround that increase system aperture high address (add 1)
1336 * to get rid of the VM fault and hardware hang.
1338 logical_addr_high = max((adev->gmc.fb_end >> 18) + 0x1, adev->gmc.agp_end >> 18);
1340 logical_addr_high = max(adev->gmc.fb_end, adev->gmc.agp_end) >> 18;
1343 pt_base = amdgpu_gmc_pd_addr(adev->gart.bo);
1345 page_table_start.high_part = upper_32_bits(adev->gmc.gart_start >>
1346 AMDGPU_GPU_PAGE_SHIFT);
1347 page_table_start.low_part = lower_32_bits(adev->gmc.gart_start >>
1348 AMDGPU_GPU_PAGE_SHIFT);
1349 page_table_end.high_part = upper_32_bits(adev->gmc.gart_end >>
1350 AMDGPU_GPU_PAGE_SHIFT);
1351 page_table_end.low_part = lower_32_bits(adev->gmc.gart_end >>
1352 AMDGPU_GPU_PAGE_SHIFT);
1353 page_table_base.high_part = upper_32_bits(pt_base);
1354 page_table_base.low_part = lower_32_bits(pt_base);
1356 pa_config->system_aperture.start_addr = (uint64_t)logical_addr_low << 18;
1357 pa_config->system_aperture.end_addr = (uint64_t)logical_addr_high << 18;
1359 pa_config->system_aperture.agp_base = (uint64_t)agp_base << 24;
1360 pa_config->system_aperture.agp_bot = (uint64_t)agp_bot << 24;
1361 pa_config->system_aperture.agp_top = (uint64_t)agp_top << 24;
1363 pa_config->system_aperture.fb_base = adev->gmc.fb_start;
1364 pa_config->system_aperture.fb_offset = adev->vm_manager.vram_base_offset;
1365 pa_config->system_aperture.fb_top = adev->gmc.fb_end;
1367 pa_config->gart_config.page_table_start_addr = page_table_start.quad_part << 12;
1368 pa_config->gart_config.page_table_end_addr = page_table_end.quad_part << 12;
1369 pa_config->gart_config.page_table_base_addr = page_table_base.quad_part;
1371 pa_config->is_hvm_enabled = adev->mode_info.gpu_vm_support;
1375 static void force_connector_state(
1376 struct amdgpu_dm_connector *aconnector,
1377 enum drm_connector_force force_state)
1379 struct drm_connector *connector = &aconnector->base;
1381 mutex_lock(&connector->dev->mode_config.mutex);
1382 aconnector->base.force = force_state;
1383 mutex_unlock(&connector->dev->mode_config.mutex);
1385 mutex_lock(&aconnector->hpd_lock);
1386 drm_kms_helper_connector_hotplug_event(connector);
1387 mutex_unlock(&aconnector->hpd_lock);
1390 static void dm_handle_hpd_rx_offload_work(struct work_struct *work)
1392 struct hpd_rx_irq_offload_work *offload_work;
1393 struct amdgpu_dm_connector *aconnector;
1394 struct dc_link *dc_link;
1395 struct amdgpu_device *adev;
1396 enum dc_connection_type new_connection_type = dc_connection_none;
1397 unsigned long flags;
1398 union test_response test_response;
1400 memset(&test_response, 0, sizeof(test_response));
1402 offload_work = container_of(work, struct hpd_rx_irq_offload_work, work);
1403 aconnector = offload_work->offload_wq->aconnector;
1406 DRM_ERROR("Can't retrieve aconnector in hpd_rx_irq_offload_work");
1410 adev = drm_to_adev(aconnector->base.dev);
1411 dc_link = aconnector->dc_link;
1413 mutex_lock(&aconnector->hpd_lock);
1414 if (!dc_link_detect_connection_type(dc_link, &new_connection_type))
1415 DRM_ERROR("KMS: Failed to detect connector\n");
1416 mutex_unlock(&aconnector->hpd_lock);
1418 if (new_connection_type == dc_connection_none)
1421 if (amdgpu_in_reset(adev))
1424 if (offload_work->data.bytes.device_service_irq.bits.UP_REQ_MSG_RDY ||
1425 offload_work->data.bytes.device_service_irq.bits.DOWN_REP_MSG_RDY) {
1426 dm_handle_mst_sideband_msg_ready_event(&aconnector->mst_mgr, DOWN_OR_UP_MSG_RDY_EVENT);
1427 spin_lock_irqsave(&offload_work->offload_wq->offload_lock, flags);
1428 offload_work->offload_wq->is_handling_mst_msg_rdy_event = false;
1429 spin_unlock_irqrestore(&offload_work->offload_wq->offload_lock, flags);
1433 mutex_lock(&adev->dm.dc_lock);
1434 if (offload_work->data.bytes.device_service_irq.bits.AUTOMATED_TEST) {
1435 dc_link_dp_handle_automated_test(dc_link);
1437 if (aconnector->timing_changed) {
1438 /* force connector disconnect and reconnect */
1439 force_connector_state(aconnector, DRM_FORCE_OFF);
1441 force_connector_state(aconnector, DRM_FORCE_UNSPECIFIED);
1444 test_response.bits.ACK = 1;
1446 core_link_write_dpcd(
1450 sizeof(test_response));
1451 } else if ((dc_link->connector_signal != SIGNAL_TYPE_EDP) &&
1452 dc_link_check_link_loss_status(dc_link, &offload_work->data) &&
1453 dc_link_dp_allow_hpd_rx_irq(dc_link)) {
1454 /* offload_work->data is from handle_hpd_rx_irq->
1455 * schedule_hpd_rx_offload_work.this is defer handle
1456 * for hpd short pulse. upon here, link status may be
1457 * changed, need get latest link status from dpcd
1458 * registers. if link status is good, skip run link
1461 union hpd_irq_data irq_data;
1463 memset(&irq_data, 0, sizeof(irq_data));
1465 /* before dc_link_dp_handle_link_loss, allow new link lost handle
1466 * request be added to work queue if link lost at end of dc_link_
1467 * dp_handle_link_loss
1469 spin_lock_irqsave(&offload_work->offload_wq->offload_lock, flags);
1470 offload_work->offload_wq->is_handling_link_loss = false;
1471 spin_unlock_irqrestore(&offload_work->offload_wq->offload_lock, flags);
1473 if ((dc_link_dp_read_hpd_rx_irq_data(dc_link, &irq_data) == DC_OK) &&
1474 dc_link_check_link_loss_status(dc_link, &irq_data))
1475 dc_link_dp_handle_link_loss(dc_link);
1477 mutex_unlock(&adev->dm.dc_lock);
1480 kfree(offload_work);
1484 static struct hpd_rx_irq_offload_work_queue *hpd_rx_irq_create_workqueue(struct dc *dc)
1486 int max_caps = dc->caps.max_links;
1488 struct hpd_rx_irq_offload_work_queue *hpd_rx_offload_wq = NULL;
1490 hpd_rx_offload_wq = kcalloc(max_caps, sizeof(*hpd_rx_offload_wq), GFP_KERNEL);
1492 if (!hpd_rx_offload_wq)
1496 for (i = 0; i < max_caps; i++) {
1497 hpd_rx_offload_wq[i].wq =
1498 create_singlethread_workqueue("amdgpu_dm_hpd_rx_offload_wq");
1500 if (hpd_rx_offload_wq[i].wq == NULL) {
1501 DRM_ERROR("create amdgpu_dm_hpd_rx_offload_wq fail!");
1505 spin_lock_init(&hpd_rx_offload_wq[i].offload_lock);
1508 return hpd_rx_offload_wq;
1511 for (i = 0; i < max_caps; i++) {
1512 if (hpd_rx_offload_wq[i].wq)
1513 destroy_workqueue(hpd_rx_offload_wq[i].wq);
1515 kfree(hpd_rx_offload_wq);
1519 struct amdgpu_stutter_quirk {
1527 static const struct amdgpu_stutter_quirk amdgpu_stutter_quirk_list[] = {
1528 /* https://bugzilla.kernel.org/show_bug.cgi?id=214417 */
1529 { 0x1002, 0x15dd, 0x1002, 0x15dd, 0xc8 },
1533 static bool dm_should_disable_stutter(struct pci_dev *pdev)
1535 const struct amdgpu_stutter_quirk *p = amdgpu_stutter_quirk_list;
1537 while (p && p->chip_device != 0) {
1538 if (pdev->vendor == p->chip_vendor &&
1539 pdev->device == p->chip_device &&
1540 pdev->subsystem_vendor == p->subsys_vendor &&
1541 pdev->subsystem_device == p->subsys_device &&
1542 pdev->revision == p->revision) {
1550 static const struct dmi_system_id hpd_disconnect_quirk_table[] = {
1553 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
1554 DMI_MATCH(DMI_PRODUCT_NAME, "Precision 3660"),
1559 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
1560 DMI_MATCH(DMI_PRODUCT_NAME, "Precision 3260"),
1565 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
1566 DMI_MATCH(DMI_PRODUCT_NAME, "Precision 3460"),
1571 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
1572 DMI_MATCH(DMI_PRODUCT_NAME, "OptiPlex Tower Plus 7010"),
1577 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
1578 DMI_MATCH(DMI_PRODUCT_NAME, "OptiPlex Tower 7010"),
1583 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
1584 DMI_MATCH(DMI_PRODUCT_NAME, "OptiPlex SFF Plus 7010"),
1589 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
1590 DMI_MATCH(DMI_PRODUCT_NAME, "OptiPlex SFF 7010"),
1595 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
1596 DMI_MATCH(DMI_PRODUCT_NAME, "OptiPlex Micro Plus 7010"),
1601 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
1602 DMI_MATCH(DMI_PRODUCT_NAME, "OptiPlex Micro 7010"),
1606 /* TODO: refactor this from a fixed table to a dynamic option */
1609 static void retrieve_dmi_info(struct amdgpu_display_manager *dm)
1611 const struct dmi_system_id *dmi_id;
1613 dm->aux_hpd_discon_quirk = false;
1615 dmi_id = dmi_first_match(hpd_disconnect_quirk_table);
1617 dm->aux_hpd_discon_quirk = true;
1618 DRM_INFO("aux_hpd_discon_quirk attached\n");
1622 static int amdgpu_dm_init(struct amdgpu_device *adev)
1624 struct dc_init_data init_data;
1625 struct dc_callback_init init_params;
1628 adev->dm.ddev = adev_to_drm(adev);
1629 adev->dm.adev = adev;
1631 /* Zero all the fields */
1632 memset(&init_data, 0, sizeof(init_data));
1633 memset(&init_params, 0, sizeof(init_params));
1635 mutex_init(&adev->dm.dpia_aux_lock);
1636 mutex_init(&adev->dm.dc_lock);
1637 mutex_init(&adev->dm.audio_lock);
1639 if (amdgpu_dm_irq_init(adev)) {
1640 DRM_ERROR("amdgpu: failed to initialize DM IRQ support.\n");
1644 init_data.asic_id.chip_family = adev->family;
1646 init_data.asic_id.pci_revision_id = adev->pdev->revision;
1647 init_data.asic_id.hw_internal_rev = adev->external_rev_id;
1648 init_data.asic_id.chip_id = adev->pdev->device;
1650 init_data.asic_id.vram_width = adev->gmc.vram_width;
1651 /* TODO: initialize init_data.asic_id.vram_type here!!!! */
1652 init_data.asic_id.atombios_base_address =
1653 adev->mode_info.atom_context->bios;
1655 init_data.driver = adev;
1657 adev->dm.cgs_device = amdgpu_cgs_create_device(adev);
1659 if (!adev->dm.cgs_device) {
1660 DRM_ERROR("amdgpu: failed to create cgs device.\n");
1664 init_data.cgs_device = adev->dm.cgs_device;
1666 init_data.dce_environment = DCE_ENV_PRODUCTION_DRV;
1668 switch (amdgpu_ip_version(adev, DCE_HWIP, 0)) {
1669 case IP_VERSION(2, 1, 0):
1670 switch (adev->dm.dmcub_fw_version) {
1671 case 0: /* development */
1672 case 0x1: /* linux-firmware.git hash 6d9f399 */
1673 case 0x01000000: /* linux-firmware.git hash 9a0b0f4 */
1674 init_data.flags.disable_dmcu = false;
1677 init_data.flags.disable_dmcu = true;
1680 case IP_VERSION(2, 0, 3):
1681 init_data.flags.disable_dmcu = true;
1687 /* APU support S/G display by default except:
1688 * ASICs before Carrizo,
1689 * RAVEN1 (Users reported stability issue)
1692 if (adev->asic_type < CHIP_CARRIZO) {
1693 init_data.flags.gpu_vm_support = false;
1694 } else if (adev->asic_type == CHIP_RAVEN) {
1695 if (adev->apu_flags & AMD_APU_IS_RAVEN)
1696 init_data.flags.gpu_vm_support = false;
1698 init_data.flags.gpu_vm_support = (amdgpu_sg_display != 0);
1700 init_data.flags.gpu_vm_support = (amdgpu_sg_display != 0) && (adev->flags & AMD_IS_APU);
1703 adev->mode_info.gpu_vm_support = init_data.flags.gpu_vm_support;
1705 if (amdgpu_dc_feature_mask & DC_FBC_MASK)
1706 init_data.flags.fbc_support = true;
1708 if (amdgpu_dc_feature_mask & DC_MULTI_MON_PP_MCLK_SWITCH_MASK)
1709 init_data.flags.multi_mon_pp_mclk_switch = true;
1711 if (amdgpu_dc_feature_mask & DC_DISABLE_FRACTIONAL_PWM_MASK)
1712 init_data.flags.disable_fractional_pwm = true;
1714 if (amdgpu_dc_feature_mask & DC_EDP_NO_POWER_SEQUENCING)
1715 init_data.flags.edp_no_power_sequencing = true;
1717 if (amdgpu_dc_feature_mask & DC_DISABLE_LTTPR_DP1_4A)
1718 init_data.flags.allow_lttpr_non_transparent_mode.bits.DP1_4A = true;
1719 if (amdgpu_dc_feature_mask & DC_DISABLE_LTTPR_DP2_0)
1720 init_data.flags.allow_lttpr_non_transparent_mode.bits.DP2_0 = true;
1722 init_data.flags.seamless_boot_edp_requested = false;
1724 if (amdgpu_device_seamless_boot_supported(adev)) {
1725 init_data.flags.seamless_boot_edp_requested = true;
1726 init_data.flags.allow_seamless_boot_optimization = true;
1727 DRM_INFO("Seamless boot condition check passed\n");
1730 init_data.flags.enable_mipi_converter_optimization = true;
1732 init_data.dcn_reg_offsets = adev->reg_offset[DCE_HWIP][0];
1733 init_data.nbio_reg_offsets = adev->reg_offset[NBIO_HWIP][0];
1734 init_data.clk_reg_offsets = adev->reg_offset[CLK_HWIP][0];
1736 if (amdgpu_dc_debug_mask & DC_DISABLE_IPS)
1737 init_data.flags.disable_ips = DMUB_IPS_DISABLE_ALL;
1739 init_data.flags.disable_ips = DMUB_IPS_RCG_IN_ACTIVE_IPS2_IN_OFF;
1741 init_data.flags.disable_ips_in_vpb = 0;
1743 /* Enable DWB for tested platforms only */
1744 if (amdgpu_ip_version(adev, DCE_HWIP, 0) >= IP_VERSION(3, 0, 0))
1745 init_data.num_virtual_links = 1;
1747 INIT_LIST_HEAD(&adev->dm.da_list);
1749 retrieve_dmi_info(&adev->dm);
1751 /* Display Core create. */
1752 adev->dm.dc = dc_create(&init_data);
1755 DRM_INFO("Display Core v%s initialized on %s\n", DC_VER,
1756 dce_version_to_string(adev->dm.dc->ctx->dce_version));
1758 DRM_INFO("Display Core failed to initialize with v%s!\n", DC_VER);
1762 if (amdgpu_dc_debug_mask & DC_DISABLE_PIPE_SPLIT) {
1763 adev->dm.dc->debug.force_single_disp_pipe_split = false;
1764 adev->dm.dc->debug.pipe_split_policy = MPC_SPLIT_AVOID;
1767 if (adev->asic_type != CHIP_CARRIZO && adev->asic_type != CHIP_STONEY)
1768 adev->dm.dc->debug.disable_stutter = amdgpu_pp_feature_mask & PP_STUTTER_MODE ? false : true;
1769 if (dm_should_disable_stutter(adev->pdev))
1770 adev->dm.dc->debug.disable_stutter = true;
1772 if (amdgpu_dc_debug_mask & DC_DISABLE_STUTTER)
1773 adev->dm.dc->debug.disable_stutter = true;
1775 if (amdgpu_dc_debug_mask & DC_DISABLE_DSC)
1776 adev->dm.dc->debug.disable_dsc = true;
1778 if (amdgpu_dc_debug_mask & DC_DISABLE_CLOCK_GATING)
1779 adev->dm.dc->debug.disable_clock_gate = true;
1781 if (amdgpu_dc_debug_mask & DC_FORCE_SUBVP_MCLK_SWITCH)
1782 adev->dm.dc->debug.force_subvp_mclk_switch = true;
1784 if (amdgpu_dc_debug_mask & DC_ENABLE_DML2)
1785 adev->dm.dc->debug.using_dml2 = true;
1787 adev->dm.dc->debug.visual_confirm = amdgpu_dc_visual_confirm;
1789 /* TODO: Remove after DP2 receiver gets proper support of Cable ID feature */
1790 adev->dm.dc->debug.ignore_cable_id = true;
1792 if (adev->dm.dc->caps.dp_hdmi21_pcon_support)
1793 DRM_INFO("DP-HDMI FRL PCON supported\n");
1795 r = dm_dmub_hw_init(adev);
1797 DRM_ERROR("DMUB interface failed to initialize: status=%d\n", r);
1801 dc_hardware_init(adev->dm.dc);
1803 adev->dm.hpd_rx_offload_wq = hpd_rx_irq_create_workqueue(adev->dm.dc);
1804 if (!adev->dm.hpd_rx_offload_wq) {
1805 DRM_ERROR("amdgpu: failed to create hpd rx offload workqueue.\n");
1809 if ((adev->flags & AMD_IS_APU) && (adev->asic_type >= CHIP_CARRIZO)) {
1810 struct dc_phy_addr_space_config pa_config;
1812 mmhub_read_system_context(adev, &pa_config);
1814 // Call the DC init_memory func
1815 dc_setup_system_context(adev->dm.dc, &pa_config);
1818 adev->dm.freesync_module = mod_freesync_create(adev->dm.dc);
1819 if (!adev->dm.freesync_module) {
1821 "amdgpu: failed to initialize freesync_module.\n");
1823 DRM_DEBUG_DRIVER("amdgpu: freesync_module init done %p.\n",
1824 adev->dm.freesync_module);
1826 amdgpu_dm_init_color_mod();
1828 if (adev->dm.dc->caps.max_links > 0) {
1829 adev->dm.vblank_control_workqueue =
1830 create_singlethread_workqueue("dm_vblank_control_workqueue");
1831 if (!adev->dm.vblank_control_workqueue)
1832 DRM_ERROR("amdgpu: failed to initialize vblank_workqueue.\n");
1835 if (adev->dm.dc->caps.max_links > 0 && adev->family >= AMDGPU_FAMILY_RV) {
1836 adev->dm.hdcp_workqueue = hdcp_create_workqueue(adev, &init_params.cp_psp, adev->dm.dc);
1838 if (!adev->dm.hdcp_workqueue)
1839 DRM_ERROR("amdgpu: failed to initialize hdcp_workqueue.\n");
1841 DRM_DEBUG_DRIVER("amdgpu: hdcp_workqueue init done %p.\n", adev->dm.hdcp_workqueue);
1843 dc_init_callbacks(adev->dm.dc, &init_params);
1845 if (dc_is_dmub_outbox_supported(adev->dm.dc)) {
1846 init_completion(&adev->dm.dmub_aux_transfer_done);
1847 adev->dm.dmub_notify = kzalloc(sizeof(struct dmub_notification), GFP_KERNEL);
1848 if (!adev->dm.dmub_notify) {
1849 DRM_INFO("amdgpu: fail to allocate adev->dm.dmub_notify");
1853 adev->dm.delayed_hpd_wq = create_singlethread_workqueue("amdgpu_dm_hpd_wq");
1854 if (!adev->dm.delayed_hpd_wq) {
1855 DRM_ERROR("amdgpu: failed to create hpd offload workqueue.\n");
1859 amdgpu_dm_outbox_init(adev);
1860 if (!register_dmub_notify_callback(adev, DMUB_NOTIFICATION_AUX_REPLY,
1861 dmub_aux_setconfig_callback, false)) {
1862 DRM_ERROR("amdgpu: fail to register dmub aux callback");
1865 /* Enable outbox notification only after IRQ handlers are registered and DMUB is alive.
1866 * It is expected that DMUB will resend any pending notifications at this point. Note
1867 * that hpd and hpd_irq handler registration are deferred to register_hpd_handlers() to
1868 * align legacy interface initialization sequence. Connection status will be proactivly
1869 * detected once in the amdgpu_dm_initialize_drm_device.
1871 dc_enable_dmub_outbox(adev->dm.dc);
1873 /* DPIA trace goes to dmesg logs only if outbox is enabled */
1874 if (amdgpu_dc_debug_mask & DC_ENABLE_DPIA_TRACE)
1875 dc_dmub_srv_enable_dpia_trace(adev->dm.dc);
1878 if (amdgpu_dm_initialize_drm_device(adev)) {
1880 "amdgpu: failed to initialize sw for display support.\n");
1884 /* create fake encoders for MST */
1885 dm_dp_create_fake_mst_encoders(adev);
1887 /* TODO: Add_display_info? */
1889 /* TODO use dynamic cursor width */
1890 adev_to_drm(adev)->mode_config.cursor_width = adev->dm.dc->caps.max_cursor_size;
1891 adev_to_drm(adev)->mode_config.cursor_height = adev->dm.dc->caps.max_cursor_size;
1893 if (drm_vblank_init(adev_to_drm(adev), adev->dm.display_indexes_num)) {
1895 "amdgpu: failed to initialize sw for display support.\n");
1899 #if defined(CONFIG_DRM_AMD_SECURE_DISPLAY)
1900 adev->dm.secure_display_ctxs = amdgpu_dm_crtc_secure_display_create_contexts(adev);
1901 if (!adev->dm.secure_display_ctxs)
1902 DRM_ERROR("amdgpu: failed to initialize secure display contexts.\n");
1905 DRM_DEBUG_DRIVER("KMS initialized.\n");
1909 amdgpu_dm_fini(adev);
1914 static int amdgpu_dm_early_fini(void *handle)
1916 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
1918 amdgpu_dm_audio_fini(adev);
1923 static void amdgpu_dm_fini(struct amdgpu_device *adev)
1927 if (adev->dm.vblank_control_workqueue) {
1928 destroy_workqueue(adev->dm.vblank_control_workqueue);
1929 adev->dm.vblank_control_workqueue = NULL;
1932 amdgpu_dm_destroy_drm_device(&adev->dm);
1934 #if defined(CONFIG_DRM_AMD_SECURE_DISPLAY)
1935 if (adev->dm.secure_display_ctxs) {
1936 for (i = 0; i < adev->mode_info.num_crtc; i++) {
1937 if (adev->dm.secure_display_ctxs[i].crtc) {
1938 flush_work(&adev->dm.secure_display_ctxs[i].notify_ta_work);
1939 flush_work(&adev->dm.secure_display_ctxs[i].forward_roi_work);
1942 kfree(adev->dm.secure_display_ctxs);
1943 adev->dm.secure_display_ctxs = NULL;
1946 if (adev->dm.hdcp_workqueue) {
1947 hdcp_destroy(&adev->dev->kobj, adev->dm.hdcp_workqueue);
1948 adev->dm.hdcp_workqueue = NULL;
1952 dc_deinit_callbacks(adev->dm.dc);
1953 dc_dmub_srv_destroy(&adev->dm.dc->ctx->dmub_srv);
1954 if (dc_enable_dmub_notifications(adev->dm.dc)) {
1955 kfree(adev->dm.dmub_notify);
1956 adev->dm.dmub_notify = NULL;
1957 destroy_workqueue(adev->dm.delayed_hpd_wq);
1958 adev->dm.delayed_hpd_wq = NULL;
1962 if (adev->dm.dmub_bo)
1963 amdgpu_bo_free_kernel(&adev->dm.dmub_bo,
1964 &adev->dm.dmub_bo_gpu_addr,
1965 &adev->dm.dmub_bo_cpu_addr);
1967 if (adev->dm.hpd_rx_offload_wq && adev->dm.dc) {
1968 for (i = 0; i < adev->dm.dc->caps.max_links; i++) {
1969 if (adev->dm.hpd_rx_offload_wq[i].wq) {
1970 destroy_workqueue(adev->dm.hpd_rx_offload_wq[i].wq);
1971 adev->dm.hpd_rx_offload_wq[i].wq = NULL;
1975 kfree(adev->dm.hpd_rx_offload_wq);
1976 adev->dm.hpd_rx_offload_wq = NULL;
1979 /* DC Destroy TODO: Replace destroy DAL */
1981 dc_destroy(&adev->dm.dc);
1983 * TODO: pageflip, vlank interrupt
1985 * amdgpu_dm_irq_fini(adev);
1988 if (adev->dm.cgs_device) {
1989 amdgpu_cgs_destroy_device(adev->dm.cgs_device);
1990 adev->dm.cgs_device = NULL;
1992 if (adev->dm.freesync_module) {
1993 mod_freesync_destroy(adev->dm.freesync_module);
1994 adev->dm.freesync_module = NULL;
1997 mutex_destroy(&adev->dm.audio_lock);
1998 mutex_destroy(&adev->dm.dc_lock);
1999 mutex_destroy(&adev->dm.dpia_aux_lock);
2002 static int load_dmcu_fw(struct amdgpu_device *adev)
2004 const char *fw_name_dmcu = NULL;
2006 const struct dmcu_firmware_header_v1_0 *hdr;
2008 switch (adev->asic_type) {
2009 #if defined(CONFIG_DRM_AMD_DC_SI)
2024 case CHIP_POLARIS11:
2025 case CHIP_POLARIS10:
2026 case CHIP_POLARIS12:
2033 fw_name_dmcu = FIRMWARE_NAVI12_DMCU;
2036 if (ASICREV_IS_PICASSO(adev->external_rev_id))
2037 fw_name_dmcu = FIRMWARE_RAVEN_DMCU;
2038 else if (ASICREV_IS_RAVEN2(adev->external_rev_id))
2039 fw_name_dmcu = FIRMWARE_RAVEN_DMCU;
2044 switch (amdgpu_ip_version(adev, DCE_HWIP, 0)) {
2045 case IP_VERSION(2, 0, 2):
2046 case IP_VERSION(2, 0, 3):
2047 case IP_VERSION(2, 0, 0):
2048 case IP_VERSION(2, 1, 0):
2049 case IP_VERSION(3, 0, 0):
2050 case IP_VERSION(3, 0, 2):
2051 case IP_VERSION(3, 0, 3):
2052 case IP_VERSION(3, 0, 1):
2053 case IP_VERSION(3, 1, 2):
2054 case IP_VERSION(3, 1, 3):
2055 case IP_VERSION(3, 1, 4):
2056 case IP_VERSION(3, 1, 5):
2057 case IP_VERSION(3, 1, 6):
2058 case IP_VERSION(3, 2, 0):
2059 case IP_VERSION(3, 2, 1):
2060 case IP_VERSION(3, 5, 0):
2061 case IP_VERSION(3, 5, 1):
2066 DRM_ERROR("Unsupported ASIC type: 0x%X\n", adev->asic_type);
2070 if (adev->firmware.load_type != AMDGPU_FW_LOAD_PSP) {
2071 DRM_DEBUG_KMS("dm: DMCU firmware not supported on direct or SMU loading\n");
2075 r = amdgpu_ucode_request(adev, &adev->dm.fw_dmcu, fw_name_dmcu);
2077 /* DMCU firmware is not necessary, so don't raise a fuss if it's missing */
2078 DRM_DEBUG_KMS("dm: DMCU firmware not found\n");
2079 adev->dm.fw_dmcu = NULL;
2083 dev_err(adev->dev, "amdgpu_dm: Can't validate firmware \"%s\"\n",
2085 amdgpu_ucode_release(&adev->dm.fw_dmcu);
2089 hdr = (const struct dmcu_firmware_header_v1_0 *)adev->dm.fw_dmcu->data;
2090 adev->firmware.ucode[AMDGPU_UCODE_ID_DMCU_ERAM].ucode_id = AMDGPU_UCODE_ID_DMCU_ERAM;
2091 adev->firmware.ucode[AMDGPU_UCODE_ID_DMCU_ERAM].fw = adev->dm.fw_dmcu;
2092 adev->firmware.fw_size +=
2093 ALIGN(le32_to_cpu(hdr->header.ucode_size_bytes) - le32_to_cpu(hdr->intv_size_bytes), PAGE_SIZE);
2095 adev->firmware.ucode[AMDGPU_UCODE_ID_DMCU_INTV].ucode_id = AMDGPU_UCODE_ID_DMCU_INTV;
2096 adev->firmware.ucode[AMDGPU_UCODE_ID_DMCU_INTV].fw = adev->dm.fw_dmcu;
2097 adev->firmware.fw_size +=
2098 ALIGN(le32_to_cpu(hdr->intv_size_bytes), PAGE_SIZE);
2100 adev->dm.dmcu_fw_version = le32_to_cpu(hdr->header.ucode_version);
2102 DRM_DEBUG_KMS("PSP loading DMCU firmware\n");
2107 static uint32_t amdgpu_dm_dmub_reg_read(void *ctx, uint32_t address)
2109 struct amdgpu_device *adev = ctx;
2111 return dm_read_reg(adev->dm.dc->ctx, address);
2114 static void amdgpu_dm_dmub_reg_write(void *ctx, uint32_t address,
2117 struct amdgpu_device *adev = ctx;
2119 return dm_write_reg(adev->dm.dc->ctx, address, value);
2122 static int dm_dmub_sw_init(struct amdgpu_device *adev)
2124 struct dmub_srv_create_params create_params;
2125 struct dmub_srv_region_params region_params;
2126 struct dmub_srv_region_info region_info;
2127 struct dmub_srv_memory_params memory_params;
2128 struct dmub_srv_fb_info *fb_info;
2129 struct dmub_srv *dmub_srv;
2130 const struct dmcub_firmware_header_v1_0 *hdr;
2131 enum dmub_asic dmub_asic;
2132 enum dmub_status status;
2133 static enum dmub_window_memory_type window_memory_type[DMUB_WINDOW_TOTAL] = {
2134 DMUB_WINDOW_MEMORY_TYPE_FB, //DMUB_WINDOW_0_INST_CONST
2135 DMUB_WINDOW_MEMORY_TYPE_FB, //DMUB_WINDOW_1_STACK
2136 DMUB_WINDOW_MEMORY_TYPE_FB, //DMUB_WINDOW_2_BSS_DATA
2137 DMUB_WINDOW_MEMORY_TYPE_FB, //DMUB_WINDOW_3_VBIOS
2138 DMUB_WINDOW_MEMORY_TYPE_FB, //DMUB_WINDOW_4_MAILBOX
2139 DMUB_WINDOW_MEMORY_TYPE_FB, //DMUB_WINDOW_5_TRACEBUFF
2140 DMUB_WINDOW_MEMORY_TYPE_FB, //DMUB_WINDOW_6_FW_STATE
2141 DMUB_WINDOW_MEMORY_TYPE_FB, //DMUB_WINDOW_7_SCRATCH_MEM
2142 DMUB_WINDOW_MEMORY_TYPE_FB, //DMUB_WINDOW_SHARED_STATE
2146 switch (amdgpu_ip_version(adev, DCE_HWIP, 0)) {
2147 case IP_VERSION(2, 1, 0):
2148 dmub_asic = DMUB_ASIC_DCN21;
2150 case IP_VERSION(3, 0, 0):
2151 dmub_asic = DMUB_ASIC_DCN30;
2153 case IP_VERSION(3, 0, 1):
2154 dmub_asic = DMUB_ASIC_DCN301;
2156 case IP_VERSION(3, 0, 2):
2157 dmub_asic = DMUB_ASIC_DCN302;
2159 case IP_VERSION(3, 0, 3):
2160 dmub_asic = DMUB_ASIC_DCN303;
2162 case IP_VERSION(3, 1, 2):
2163 case IP_VERSION(3, 1, 3):
2164 dmub_asic = (adev->external_rev_id == YELLOW_CARP_B0) ? DMUB_ASIC_DCN31B : DMUB_ASIC_DCN31;
2166 case IP_VERSION(3, 1, 4):
2167 dmub_asic = DMUB_ASIC_DCN314;
2169 case IP_VERSION(3, 1, 5):
2170 dmub_asic = DMUB_ASIC_DCN315;
2172 case IP_VERSION(3, 1, 6):
2173 dmub_asic = DMUB_ASIC_DCN316;
2175 case IP_VERSION(3, 2, 0):
2176 dmub_asic = DMUB_ASIC_DCN32;
2178 case IP_VERSION(3, 2, 1):
2179 dmub_asic = DMUB_ASIC_DCN321;
2181 case IP_VERSION(3, 5, 0):
2182 case IP_VERSION(3, 5, 1):
2183 dmub_asic = DMUB_ASIC_DCN35;
2186 /* ASIC doesn't support DMUB. */
2190 hdr = (const struct dmcub_firmware_header_v1_0 *)adev->dm.dmub_fw->data;
2191 adev->dm.dmcub_fw_version = le32_to_cpu(hdr->header.ucode_version);
2193 if (adev->firmware.load_type == AMDGPU_FW_LOAD_PSP) {
2194 adev->firmware.ucode[AMDGPU_UCODE_ID_DMCUB].ucode_id =
2195 AMDGPU_UCODE_ID_DMCUB;
2196 adev->firmware.ucode[AMDGPU_UCODE_ID_DMCUB].fw =
2198 adev->firmware.fw_size +=
2199 ALIGN(le32_to_cpu(hdr->inst_const_bytes), PAGE_SIZE);
2201 DRM_INFO("Loading DMUB firmware via PSP: version=0x%08X\n",
2202 adev->dm.dmcub_fw_version);
2206 adev->dm.dmub_srv = kzalloc(sizeof(*adev->dm.dmub_srv), GFP_KERNEL);
2207 dmub_srv = adev->dm.dmub_srv;
2210 DRM_ERROR("Failed to allocate DMUB service!\n");
2214 memset(&create_params, 0, sizeof(create_params));
2215 create_params.user_ctx = adev;
2216 create_params.funcs.reg_read = amdgpu_dm_dmub_reg_read;
2217 create_params.funcs.reg_write = amdgpu_dm_dmub_reg_write;
2218 create_params.asic = dmub_asic;
2220 /* Create the DMUB service. */
2221 status = dmub_srv_create(dmub_srv, &create_params);
2222 if (status != DMUB_STATUS_OK) {
2223 DRM_ERROR("Error creating DMUB service: %d\n", status);
2227 /* Calculate the size of all the regions for the DMUB service. */
2228 memset(®ion_params, 0, sizeof(region_params));
2230 region_params.inst_const_size = le32_to_cpu(hdr->inst_const_bytes) -
2231 PSP_HEADER_BYTES - PSP_FOOTER_BYTES;
2232 region_params.bss_data_size = le32_to_cpu(hdr->bss_data_bytes);
2233 region_params.vbios_size = adev->bios_size;
2234 region_params.fw_bss_data = region_params.bss_data_size ?
2235 adev->dm.dmub_fw->data +
2236 le32_to_cpu(hdr->header.ucode_array_offset_bytes) +
2237 le32_to_cpu(hdr->inst_const_bytes) : NULL;
2238 region_params.fw_inst_const =
2239 adev->dm.dmub_fw->data +
2240 le32_to_cpu(hdr->header.ucode_array_offset_bytes) +
2242 region_params.window_memory_type = window_memory_type;
2244 status = dmub_srv_calc_region_info(dmub_srv, ®ion_params,
2247 if (status != DMUB_STATUS_OK) {
2248 DRM_ERROR("Error calculating DMUB region info: %d\n", status);
2253 * Allocate a framebuffer based on the total size of all the regions.
2254 * TODO: Move this into GART.
2256 r = amdgpu_bo_create_kernel(adev, region_info.fb_size, PAGE_SIZE,
2257 AMDGPU_GEM_DOMAIN_VRAM |
2258 AMDGPU_GEM_DOMAIN_GTT,
2260 &adev->dm.dmub_bo_gpu_addr,
2261 &adev->dm.dmub_bo_cpu_addr);
2265 /* Rebase the regions on the framebuffer address. */
2266 memset(&memory_params, 0, sizeof(memory_params));
2267 memory_params.cpu_fb_addr = adev->dm.dmub_bo_cpu_addr;
2268 memory_params.gpu_fb_addr = adev->dm.dmub_bo_gpu_addr;
2269 memory_params.region_info = ®ion_info;
2270 memory_params.window_memory_type = window_memory_type;
2272 adev->dm.dmub_fb_info =
2273 kzalloc(sizeof(*adev->dm.dmub_fb_info), GFP_KERNEL);
2274 fb_info = adev->dm.dmub_fb_info;
2278 "Failed to allocate framebuffer info for DMUB service!\n");
2282 status = dmub_srv_calc_mem_info(dmub_srv, &memory_params, fb_info);
2283 if (status != DMUB_STATUS_OK) {
2284 DRM_ERROR("Error calculating DMUB FB info: %d\n", status);
2291 static int dm_sw_init(void *handle)
2293 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
2296 r = dm_dmub_sw_init(adev);
2300 return load_dmcu_fw(adev);
2303 static int dm_sw_fini(void *handle)
2305 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
2307 kfree(adev->dm.dmub_fb_info);
2308 adev->dm.dmub_fb_info = NULL;
2310 if (adev->dm.dmub_srv) {
2311 dmub_srv_destroy(adev->dm.dmub_srv);
2312 kfree(adev->dm.dmub_srv);
2313 adev->dm.dmub_srv = NULL;
2316 amdgpu_ucode_release(&adev->dm.dmub_fw);
2317 amdgpu_ucode_release(&adev->dm.fw_dmcu);
2322 static int detect_mst_link_for_all_connectors(struct drm_device *dev)
2324 struct amdgpu_dm_connector *aconnector;
2325 struct drm_connector *connector;
2326 struct drm_connector_list_iter iter;
2329 drm_connector_list_iter_begin(dev, &iter);
2330 drm_for_each_connector_iter(connector, &iter) {
2332 if (connector->connector_type == DRM_MODE_CONNECTOR_WRITEBACK)
2335 aconnector = to_amdgpu_dm_connector(connector);
2336 if (aconnector->dc_link->type == dc_connection_mst_branch &&
2337 aconnector->mst_mgr.aux) {
2338 DRM_DEBUG_DRIVER("DM_MST: starting TM on aconnector: %p [id: %d]\n",
2340 aconnector->base.base.id);
2342 ret = drm_dp_mst_topology_mgr_set_mst(&aconnector->mst_mgr, true);
2344 DRM_ERROR("DM_MST: Failed to start MST\n");
2345 aconnector->dc_link->type =
2346 dc_connection_single;
2347 ret = dm_helpers_dp_mst_stop_top_mgr(aconnector->dc_link->ctx,
2348 aconnector->dc_link);
2353 drm_connector_list_iter_end(&iter);
2358 static int dm_late_init(void *handle)
2360 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
2362 struct dmcu_iram_parameters params;
2363 unsigned int linear_lut[16];
2365 struct dmcu *dmcu = NULL;
2367 dmcu = adev->dm.dc->res_pool->dmcu;
2369 for (i = 0; i < 16; i++)
2370 linear_lut[i] = 0xFFFF * i / 15;
2373 params.backlight_ramping_override = false;
2374 params.backlight_ramping_start = 0xCCCC;
2375 params.backlight_ramping_reduction = 0xCCCCCCCC;
2376 params.backlight_lut_array_size = 16;
2377 params.backlight_lut_array = linear_lut;
2379 /* Min backlight level after ABM reduction, Don't allow below 1%
2380 * 0xFFFF x 0.01 = 0x28F
2382 params.min_abm_backlight = 0x28F;
2383 /* In the case where abm is implemented on dmcub,
2384 * dmcu object will be null.
2385 * ABM 2.4 and up are implemented on dmcub.
2388 if (!dmcu_load_iram(dmcu, params))
2390 } else if (adev->dm.dc->ctx->dmub_srv) {
2391 struct dc_link *edp_links[MAX_NUM_EDP];
2394 dc_get_edp_links(adev->dm.dc, edp_links, &edp_num);
2395 for (i = 0; i < edp_num; i++) {
2396 if (!dmub_init_abm_config(adev->dm.dc->res_pool, params, i))
2401 return detect_mst_link_for_all_connectors(adev_to_drm(adev));
2404 static void resume_mst_branch_status(struct drm_dp_mst_topology_mgr *mgr)
2410 mutex_lock(&mgr->lock);
2411 if (!mgr->mst_primary)
2414 if (drm_dp_read_dpcd_caps(mgr->aux, mgr->dpcd) < 0) {
2415 drm_dbg_kms(mgr->dev, "dpcd read failed - undocked during suspend?\n");
2419 ret = drm_dp_dpcd_writeb(mgr->aux, DP_MSTM_CTRL,
2422 DP_UPSTREAM_IS_SRC);
2424 drm_dbg_kms(mgr->dev, "mst write failed - undocked during suspend?\n");
2428 /* Some hubs forget their guids after they resume */
2429 ret = drm_dp_dpcd_read(mgr->aux, DP_GUID, guid, 16);
2431 drm_dbg_kms(mgr->dev, "dpcd read failed - undocked during suspend?\n");
2435 if (memchr_inv(guid, 0, 16) == NULL) {
2436 tmp64 = get_jiffies_64();
2437 memcpy(&guid[0], &tmp64, sizeof(u64));
2438 memcpy(&guid[8], &tmp64, sizeof(u64));
2440 ret = drm_dp_dpcd_write(mgr->aux, DP_GUID, guid, 16);
2443 drm_dbg_kms(mgr->dev, "check mstb guid failed - undocked during suspend?\n");
2448 memcpy(mgr->mst_primary->guid, guid, 16);
2451 mutex_unlock(&mgr->lock);
2454 static void s3_handle_mst(struct drm_device *dev, bool suspend)
2456 struct amdgpu_dm_connector *aconnector;
2457 struct drm_connector *connector;
2458 struct drm_connector_list_iter iter;
2459 struct drm_dp_mst_topology_mgr *mgr;
2461 drm_connector_list_iter_begin(dev, &iter);
2462 drm_for_each_connector_iter(connector, &iter) {
2464 if (connector->connector_type == DRM_MODE_CONNECTOR_WRITEBACK)
2467 aconnector = to_amdgpu_dm_connector(connector);
2468 if (aconnector->dc_link->type != dc_connection_mst_branch ||
2469 aconnector->mst_root)
2472 mgr = &aconnector->mst_mgr;
2475 drm_dp_mst_topology_mgr_suspend(mgr);
2477 /* if extended timeout is supported in hardware,
2478 * default to LTTPR timeout (3.2ms) first as a W/A for DP link layer
2479 * CTS 4.2.1.1 regression introduced by CTS specs requirement update.
2481 try_to_configure_aux_timeout(aconnector->dc_link->ddc, LINK_AUX_DEFAULT_LTTPR_TIMEOUT_PERIOD);
2482 if (!dp_is_lttpr_present(aconnector->dc_link))
2483 try_to_configure_aux_timeout(aconnector->dc_link->ddc, LINK_AUX_DEFAULT_TIMEOUT_PERIOD);
2485 /* TODO: move resume_mst_branch_status() into drm mst resume again
2486 * once topology probing work is pulled out from mst resume into mst
2487 * resume 2nd step. mst resume 2nd step should be called after old
2488 * state getting restored (i.e. drm_atomic_helper_resume()).
2490 resume_mst_branch_status(mgr);
2493 drm_connector_list_iter_end(&iter);
2496 static int amdgpu_dm_smu_write_watermarks_table(struct amdgpu_device *adev)
2500 /* This interface is for dGPU Navi1x.Linux dc-pplib interface depends
2501 * on window driver dc implementation.
2502 * For Navi1x, clock settings of dcn watermarks are fixed. the settings
2503 * should be passed to smu during boot up and resume from s3.
2504 * boot up: dc calculate dcn watermark clock settings within dc_create,
2505 * dcn20_resource_construct
2506 * then call pplib functions below to pass the settings to smu:
2507 * smu_set_watermarks_for_clock_ranges
2508 * smu_set_watermarks_table
2509 * navi10_set_watermarks_table
2510 * smu_write_watermarks_table
2512 * For Renoir, clock settings of dcn watermark are also fixed values.
2513 * dc has implemented different flow for window driver:
2514 * dc_hardware_init / dc_set_power_state
2519 * smu_set_watermarks_for_clock_ranges
2520 * renoir_set_watermarks_table
2521 * smu_write_watermarks_table
2524 * dc_hardware_init -> amdgpu_dm_init
2525 * dc_set_power_state --> dm_resume
2527 * therefore, this function apply to navi10/12/14 but not Renoir
2530 switch (amdgpu_ip_version(adev, DCE_HWIP, 0)) {
2531 case IP_VERSION(2, 0, 2):
2532 case IP_VERSION(2, 0, 0):
2538 ret = amdgpu_dpm_write_watermarks_table(adev);
2540 DRM_ERROR("Failed to update WMTABLE!\n");
2548 * dm_hw_init() - Initialize DC device
2549 * @handle: The base driver device containing the amdgpu_dm device.
2551 * Initialize the &struct amdgpu_display_manager device. This involves calling
2552 * the initializers of each DM component, then populating the struct with them.
2554 * Although the function implies hardware initialization, both hardware and
2555 * software are initialized here. Splitting them out to their relevant init
2556 * hooks is a future TODO item.
2558 * Some notable things that are initialized here:
2560 * - Display Core, both software and hardware
2561 * - DC modules that we need (freesync and color management)
2562 * - DRM software states
2563 * - Interrupt sources and handlers
2565 * - Debug FS entries, if enabled
2567 static int dm_hw_init(void *handle)
2569 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
2570 /* Create DAL display manager */
2571 amdgpu_dm_init(adev);
2572 amdgpu_dm_hpd_init(adev);
2578 * dm_hw_fini() - Teardown DC device
2579 * @handle: The base driver device containing the amdgpu_dm device.
2581 * Teardown components within &struct amdgpu_display_manager that require
2582 * cleanup. This involves cleaning up the DRM device, DC, and any modules that
2583 * were loaded. Also flush IRQ workqueues and disable them.
2585 static int dm_hw_fini(void *handle)
2587 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
2589 amdgpu_dm_hpd_fini(adev);
2591 amdgpu_dm_irq_fini(adev);
2592 amdgpu_dm_fini(adev);
2597 static void dm_gpureset_toggle_interrupts(struct amdgpu_device *adev,
2598 struct dc_state *state, bool enable)
2600 enum dc_irq_source irq_source;
2601 struct amdgpu_crtc *acrtc;
2605 for (i = 0; i < state->stream_count; i++) {
2606 acrtc = get_crtc_by_otg_inst(
2607 adev, state->stream_status[i].primary_otg_inst);
2609 if (acrtc && state->stream_status[i].plane_count != 0) {
2610 irq_source = IRQ_TYPE_PFLIP + acrtc->otg_inst;
2611 rc = dc_interrupt_set(adev->dm.dc, irq_source, enable) ? 0 : -EBUSY;
2613 DRM_WARN("Failed to %s pflip interrupts\n",
2614 enable ? "enable" : "disable");
2617 if (amdgpu_dm_crtc_vrr_active(to_dm_crtc_state(acrtc->base.state)))
2618 rc = amdgpu_dm_crtc_set_vupdate_irq(&acrtc->base, true);
2620 rc = amdgpu_dm_crtc_set_vupdate_irq(&acrtc->base, false);
2623 DRM_WARN("Failed to %sable vupdate interrupt\n", enable ? "en" : "dis");
2625 irq_source = IRQ_TYPE_VBLANK + acrtc->otg_inst;
2626 /* During gpu-reset we disable and then enable vblank irq, so
2627 * don't use amdgpu_irq_get/put() to avoid refcount change.
2629 if (!dc_interrupt_set(adev->dm.dc, irq_source, enable))
2630 DRM_WARN("Failed to %sable vblank interrupt\n", enable ? "en" : "dis");
2636 static enum dc_status amdgpu_dm_commit_zero_streams(struct dc *dc)
2638 struct dc_state *context = NULL;
2639 enum dc_status res = DC_ERROR_UNEXPECTED;
2641 struct dc_stream_state *del_streams[MAX_PIPES];
2642 int del_streams_count = 0;
2643 struct dc_commit_streams_params params = {};
2645 memset(del_streams, 0, sizeof(del_streams));
2647 context = dc_state_create_current_copy(dc);
2648 if (context == NULL)
2649 goto context_alloc_fail;
2651 /* First remove from context all streams */
2652 for (i = 0; i < context->stream_count; i++) {
2653 struct dc_stream_state *stream = context->streams[i];
2655 del_streams[del_streams_count++] = stream;
2658 /* Remove all planes for removed streams and then remove the streams */
2659 for (i = 0; i < del_streams_count; i++) {
2660 if (!dc_state_rem_all_planes_for_stream(dc, del_streams[i], context)) {
2661 res = DC_FAIL_DETACH_SURFACES;
2665 res = dc_state_remove_stream(dc, context, del_streams[i]);
2670 params.streams = context->streams;
2671 params.stream_count = context->stream_count;
2672 res = dc_commit_streams(dc, ¶ms);
2675 dc_state_release(context);
2681 static void hpd_rx_irq_work_suspend(struct amdgpu_display_manager *dm)
2685 if (dm->hpd_rx_offload_wq) {
2686 for (i = 0; i < dm->dc->caps.max_links; i++)
2687 flush_workqueue(dm->hpd_rx_offload_wq[i].wq);
2691 static int dm_suspend(void *handle)
2693 struct amdgpu_device *adev = handle;
2694 struct amdgpu_display_manager *dm = &adev->dm;
2697 if (amdgpu_in_reset(adev)) {
2698 mutex_lock(&dm->dc_lock);
2700 dc_allow_idle_optimizations(adev->dm.dc, false);
2702 dm->cached_dc_state = dc_state_create_copy(dm->dc->current_state);
2704 dm_gpureset_toggle_interrupts(adev, dm->cached_dc_state, false);
2706 amdgpu_dm_commit_zero_streams(dm->dc);
2708 amdgpu_dm_irq_suspend(adev);
2710 hpd_rx_irq_work_suspend(dm);
2715 WARN_ON(adev->dm.cached_state);
2716 adev->dm.cached_state = drm_atomic_helper_suspend(adev_to_drm(adev));
2717 if (IS_ERR(adev->dm.cached_state))
2718 return PTR_ERR(adev->dm.cached_state);
2720 s3_handle_mst(adev_to_drm(adev), true);
2722 amdgpu_dm_irq_suspend(adev);
2724 hpd_rx_irq_work_suspend(dm);
2726 dc_set_power_state(dm->dc, DC_ACPI_CM_POWER_STATE_D3);
2727 dc_dmub_srv_set_power_state(dm->dc->ctx->dmub_srv, DC_ACPI_CM_POWER_STATE_D3);
2732 struct drm_connector *
2733 amdgpu_dm_find_first_crtc_matching_connector(struct drm_atomic_state *state,
2734 struct drm_crtc *crtc)
2737 struct drm_connector_state *new_con_state;
2738 struct drm_connector *connector;
2739 struct drm_crtc *crtc_from_state;
2741 for_each_new_connector_in_state(state, connector, new_con_state, i) {
2742 crtc_from_state = new_con_state->crtc;
2744 if (crtc_from_state == crtc)
2751 static void emulated_link_detect(struct dc_link *link)
2753 struct dc_sink_init_data sink_init_data = { 0 };
2754 struct display_sink_capability sink_caps = { 0 };
2755 enum dc_edid_status edid_status;
2756 struct dc_context *dc_ctx = link->ctx;
2757 struct drm_device *dev = adev_to_drm(dc_ctx->driver_context);
2758 struct dc_sink *sink = NULL;
2759 struct dc_sink *prev_sink = NULL;
2761 link->type = dc_connection_none;
2762 prev_sink = link->local_sink;
2765 dc_sink_release(prev_sink);
2767 switch (link->connector_signal) {
2768 case SIGNAL_TYPE_HDMI_TYPE_A: {
2769 sink_caps.transaction_type = DDC_TRANSACTION_TYPE_I2C;
2770 sink_caps.signal = SIGNAL_TYPE_HDMI_TYPE_A;
2774 case SIGNAL_TYPE_DVI_SINGLE_LINK: {
2775 sink_caps.transaction_type = DDC_TRANSACTION_TYPE_I2C;
2776 sink_caps.signal = SIGNAL_TYPE_DVI_SINGLE_LINK;
2780 case SIGNAL_TYPE_DVI_DUAL_LINK: {
2781 sink_caps.transaction_type = DDC_TRANSACTION_TYPE_I2C;
2782 sink_caps.signal = SIGNAL_TYPE_DVI_DUAL_LINK;
2786 case SIGNAL_TYPE_LVDS: {
2787 sink_caps.transaction_type = DDC_TRANSACTION_TYPE_I2C;
2788 sink_caps.signal = SIGNAL_TYPE_LVDS;
2792 case SIGNAL_TYPE_EDP: {
2793 sink_caps.transaction_type =
2794 DDC_TRANSACTION_TYPE_I2C_OVER_AUX;
2795 sink_caps.signal = SIGNAL_TYPE_EDP;
2799 case SIGNAL_TYPE_DISPLAY_PORT: {
2800 sink_caps.transaction_type =
2801 DDC_TRANSACTION_TYPE_I2C_OVER_AUX;
2802 sink_caps.signal = SIGNAL_TYPE_VIRTUAL;
2807 drm_err(dev, "Invalid connector type! signal:%d\n",
2808 link->connector_signal);
2812 sink_init_data.link = link;
2813 sink_init_data.sink_signal = sink_caps.signal;
2815 sink = dc_sink_create(&sink_init_data);
2817 drm_err(dev, "Failed to create sink!\n");
2821 /* dc_sink_create returns a new reference */
2822 link->local_sink = sink;
2824 edid_status = dm_helpers_read_local_edid(
2829 if (edid_status != EDID_OK)
2830 drm_err(dev, "Failed to read EDID\n");
2834 static void dm_gpureset_commit_state(struct dc_state *dc_state,
2835 struct amdgpu_display_manager *dm)
2838 struct dc_surface_update surface_updates[MAX_SURFACES];
2839 struct dc_plane_info plane_infos[MAX_SURFACES];
2840 struct dc_scaling_info scaling_infos[MAX_SURFACES];
2841 struct dc_flip_addrs flip_addrs[MAX_SURFACES];
2842 struct dc_stream_update stream_update;
2846 bundle = kzalloc(sizeof(*bundle), GFP_KERNEL);
2849 drm_err(dm->ddev, "Failed to allocate update bundle\n");
2853 for (k = 0; k < dc_state->stream_count; k++) {
2854 bundle->stream_update.stream = dc_state->streams[k];
2856 for (m = 0; m < dc_state->stream_status->plane_count; m++) {
2857 bundle->surface_updates[m].surface =
2858 dc_state->stream_status->plane_states[m];
2859 bundle->surface_updates[m].surface->force_full_update =
2863 update_planes_and_stream_adapter(dm->dc,
2865 dc_state->stream_status->plane_count,
2866 dc_state->streams[k],
2867 &bundle->stream_update,
2868 bundle->surface_updates);
2875 static int dm_resume(void *handle)
2877 struct amdgpu_device *adev = handle;
2878 struct drm_device *ddev = adev_to_drm(adev);
2879 struct amdgpu_display_manager *dm = &adev->dm;
2880 struct amdgpu_dm_connector *aconnector;
2881 struct drm_connector *connector;
2882 struct drm_connector_list_iter iter;
2883 struct drm_crtc *crtc;
2884 struct drm_crtc_state *new_crtc_state;
2885 struct dm_crtc_state *dm_new_crtc_state;
2886 struct drm_plane *plane;
2887 struct drm_plane_state *new_plane_state;
2888 struct dm_plane_state *dm_new_plane_state;
2889 struct dm_atomic_state *dm_state = to_dm_atomic_state(dm->atomic_obj.state);
2890 enum dc_connection_type new_connection_type = dc_connection_none;
2891 struct dc_state *dc_state;
2893 bool need_hotplug = false;
2894 struct dc_commit_streams_params commit_params = {};
2896 if (dm->dc->caps.ips_support) {
2897 dc_dmub_srv_apply_idle_power_optimizations(dm->dc, false);
2900 if (amdgpu_in_reset(adev)) {
2901 dc_state = dm->cached_dc_state;
2904 * The dc->current_state is backed up into dm->cached_dc_state
2905 * before we commit 0 streams.
2907 * DC will clear link encoder assignments on the real state
2908 * but the changes won't propagate over to the copy we made
2909 * before the 0 streams commit.
2911 * DC expects that link encoder assignments are *not* valid
2912 * when committing a state, so as a workaround we can copy
2913 * off of the current state.
2915 * We lose the previous assignments, but we had already
2916 * commit 0 streams anyway.
2918 link_enc_cfg_copy(adev->dm.dc->current_state, dc_state);
2920 r = dm_dmub_hw_init(adev);
2922 DRM_ERROR("DMUB interface failed to initialize: status=%d\n", r);
2924 dc_dmub_srv_set_power_state(dm->dc->ctx->dmub_srv, DC_ACPI_CM_POWER_STATE_D0);
2925 dc_set_power_state(dm->dc, DC_ACPI_CM_POWER_STATE_D0);
2929 amdgpu_dm_irq_resume_early(adev);
2931 for (i = 0; i < dc_state->stream_count; i++) {
2932 dc_state->streams[i]->mode_changed = true;
2933 for (j = 0; j < dc_state->stream_status[i].plane_count; j++) {
2934 dc_state->stream_status[i].plane_states[j]->update_flags.raw
2939 if (dc_is_dmub_outbox_supported(adev->dm.dc)) {
2940 amdgpu_dm_outbox_init(adev);
2941 dc_enable_dmub_outbox(adev->dm.dc);
2944 commit_params.streams = dc_state->streams;
2945 commit_params.stream_count = dc_state->stream_count;
2946 WARN_ON(!dc_commit_streams(dm->dc, &commit_params));
2948 dm_gpureset_commit_state(dm->cached_dc_state, dm);
2950 dm_gpureset_toggle_interrupts(adev, dm->cached_dc_state, true);
2952 dc_state_release(dm->cached_dc_state);
2953 dm->cached_dc_state = NULL;
2955 amdgpu_dm_irq_resume_late(adev);
2957 mutex_unlock(&dm->dc_lock);
2961 /* Recreate dc_state - DC invalidates it when setting power state to S3. */
2962 dc_state_release(dm_state->context);
2963 dm_state->context = dc_state_create(dm->dc, NULL);
2964 /* TODO: Remove dc_state->dccg, use dc->dccg directly. */
2966 /* Before powering on DC we need to re-initialize DMUB. */
2967 dm_dmub_hw_resume(adev);
2969 /* Re-enable outbox interrupts for DPIA. */
2970 if (dc_is_dmub_outbox_supported(adev->dm.dc)) {
2971 amdgpu_dm_outbox_init(adev);
2972 dc_enable_dmub_outbox(adev->dm.dc);
2975 /* power on hardware */
2976 dc_dmub_srv_set_power_state(dm->dc->ctx->dmub_srv, DC_ACPI_CM_POWER_STATE_D0);
2977 dc_set_power_state(dm->dc, DC_ACPI_CM_POWER_STATE_D0);
2979 /* program HPD filter */
2983 * early enable HPD Rx IRQ, should be done before set mode as short
2984 * pulse interrupts are used for MST
2986 amdgpu_dm_irq_resume_early(adev);
2988 /* On resume we need to rewrite the MSTM control bits to enable MST*/
2989 s3_handle_mst(ddev, false);
2992 drm_connector_list_iter_begin(ddev, &iter);
2993 drm_for_each_connector_iter(connector, &iter) {
2995 if (connector->connector_type == DRM_MODE_CONNECTOR_WRITEBACK)
2998 aconnector = to_amdgpu_dm_connector(connector);
3000 if (!aconnector->dc_link)
3004 * this is the case when traversing through already created end sink
3005 * MST connectors, should be skipped
3007 if (aconnector && aconnector->mst_root)
3010 mutex_lock(&aconnector->hpd_lock);
3011 if (!dc_link_detect_connection_type(aconnector->dc_link, &new_connection_type))
3012 DRM_ERROR("KMS: Failed to detect connector\n");
3014 if (aconnector->base.force && new_connection_type == dc_connection_none) {
3015 emulated_link_detect(aconnector->dc_link);
3017 mutex_lock(&dm->dc_lock);
3018 dc_link_detect(aconnector->dc_link, DETECT_REASON_HPD);
3019 mutex_unlock(&dm->dc_lock);
3022 if (aconnector->fake_enable && aconnector->dc_link->local_sink)
3023 aconnector->fake_enable = false;
3025 if (aconnector->dc_sink)
3026 dc_sink_release(aconnector->dc_sink);
3027 aconnector->dc_sink = NULL;
3028 amdgpu_dm_update_connector_after_detect(aconnector);
3029 mutex_unlock(&aconnector->hpd_lock);
3031 drm_connector_list_iter_end(&iter);
3033 /* Force mode set in atomic commit */
3034 for_each_new_crtc_in_state(dm->cached_state, crtc, new_crtc_state, i)
3035 new_crtc_state->active_changed = true;
3038 * atomic_check is expected to create the dc states. We need to release
3039 * them here, since they were duplicated as part of the suspend
3042 for_each_new_crtc_in_state(dm->cached_state, crtc, new_crtc_state, i) {
3043 dm_new_crtc_state = to_dm_crtc_state(new_crtc_state);
3044 if (dm_new_crtc_state->stream) {
3045 WARN_ON(kref_read(&dm_new_crtc_state->stream->refcount) > 1);
3046 dc_stream_release(dm_new_crtc_state->stream);
3047 dm_new_crtc_state->stream = NULL;
3049 dm_new_crtc_state->base.color_mgmt_changed = true;
3052 for_each_new_plane_in_state(dm->cached_state, plane, new_plane_state, i) {
3053 dm_new_plane_state = to_dm_plane_state(new_plane_state);
3054 if (dm_new_plane_state->dc_state) {
3055 WARN_ON(kref_read(&dm_new_plane_state->dc_state->refcount) > 1);
3056 dc_plane_state_release(dm_new_plane_state->dc_state);
3057 dm_new_plane_state->dc_state = NULL;
3061 drm_atomic_helper_resume(ddev, dm->cached_state);
3063 dm->cached_state = NULL;
3065 /* Do mst topology probing after resuming cached state*/
3066 drm_connector_list_iter_begin(ddev, &iter);
3067 drm_for_each_connector_iter(connector, &iter) {
3069 if (connector->connector_type == DRM_MODE_CONNECTOR_WRITEBACK)
3072 aconnector = to_amdgpu_dm_connector(connector);
3073 if (aconnector->dc_link->type != dc_connection_mst_branch ||
3074 aconnector->mst_root)
3077 ret = drm_dp_mst_topology_mgr_resume(&aconnector->mst_mgr, true);
3080 dm_helpers_dp_mst_stop_top_mgr(aconnector->dc_link->ctx,
3081 aconnector->dc_link);
3082 need_hotplug = true;
3085 drm_connector_list_iter_end(&iter);
3088 drm_kms_helper_hotplug_event(ddev);
3090 amdgpu_dm_irq_resume_late(adev);
3092 amdgpu_dm_smu_write_watermarks_table(adev);
3100 * DM (and consequently DC) is registered in the amdgpu base driver as a IP
3101 * block. When CONFIG_DRM_AMD_DC is enabled, the DM device IP block is added to
3102 * the base driver's device list to be initialized and torn down accordingly.
3104 * The functions to do so are provided as hooks in &struct amd_ip_funcs.
3107 static const struct amd_ip_funcs amdgpu_dm_funcs = {
3109 .early_init = dm_early_init,
3110 .late_init = dm_late_init,
3111 .sw_init = dm_sw_init,
3112 .sw_fini = dm_sw_fini,
3113 .early_fini = amdgpu_dm_early_fini,
3114 .hw_init = dm_hw_init,
3115 .hw_fini = dm_hw_fini,
3116 .suspend = dm_suspend,
3117 .resume = dm_resume,
3118 .is_idle = dm_is_idle,
3119 .wait_for_idle = dm_wait_for_idle,
3120 .check_soft_reset = dm_check_soft_reset,
3121 .soft_reset = dm_soft_reset,
3122 .set_clockgating_state = dm_set_clockgating_state,
3123 .set_powergating_state = dm_set_powergating_state,
3124 .dump_ip_state = NULL,
3125 .print_ip_state = NULL,
3128 const struct amdgpu_ip_block_version dm_ip_block = {
3129 .type = AMD_IP_BLOCK_TYPE_DCE,
3133 .funcs = &amdgpu_dm_funcs,
3143 static const struct drm_mode_config_funcs amdgpu_dm_mode_funcs = {
3144 .fb_create = amdgpu_display_user_framebuffer_create,
3145 .get_format_info = amdgpu_dm_plane_get_format_info,
3146 .atomic_check = amdgpu_dm_atomic_check,
3147 .atomic_commit = drm_atomic_helper_commit,
3150 static struct drm_mode_config_helper_funcs amdgpu_dm_mode_config_helperfuncs = {
3151 .atomic_commit_tail = amdgpu_dm_atomic_commit_tail,
3152 .atomic_commit_setup = drm_dp_mst_atomic_setup_commit,
3155 static void update_connector_ext_caps(struct amdgpu_dm_connector *aconnector)
3157 struct amdgpu_dm_backlight_caps *caps;
3158 struct drm_connector *conn_base;
3159 struct amdgpu_device *adev;
3160 struct drm_luminance_range_info *luminance_range;
3162 if (aconnector->bl_idx == -1 ||
3163 aconnector->dc_link->connector_signal != SIGNAL_TYPE_EDP)
3166 conn_base = &aconnector->base;
3167 adev = drm_to_adev(conn_base->dev);
3169 caps = &adev->dm.backlight_caps[aconnector->bl_idx];
3170 caps->ext_caps = &aconnector->dc_link->dpcd_sink_ext_caps;
3171 caps->aux_support = false;
3173 if (caps->ext_caps->bits.oled == 1
3176 * caps->ext_caps->bits.sdr_aux_backlight_control == 1 ||
3177 * caps->ext_caps->bits.hdr_aux_backlight_control == 1
3179 caps->aux_support = true;
3181 if (amdgpu_backlight == 0)
3182 caps->aux_support = false;
3183 else if (amdgpu_backlight == 1)
3184 caps->aux_support = true;
3186 luminance_range = &conn_base->display_info.luminance_range;
3188 if (luminance_range->max_luminance) {
3189 caps->aux_min_input_signal = luminance_range->min_luminance;
3190 caps->aux_max_input_signal = luminance_range->max_luminance;
3192 caps->aux_min_input_signal = 0;
3193 caps->aux_max_input_signal = 512;
3197 void amdgpu_dm_update_connector_after_detect(
3198 struct amdgpu_dm_connector *aconnector)
3200 struct drm_connector *connector = &aconnector->base;
3201 struct drm_device *dev = connector->dev;
3202 struct dc_sink *sink;
3204 /* MST handled by drm_mst framework */
3205 if (aconnector->mst_mgr.mst_state == true)
3208 sink = aconnector->dc_link->local_sink;
3210 dc_sink_retain(sink);
3213 * Edid mgmt connector gets first update only in mode_valid hook and then
3214 * the connector sink is set to either fake or physical sink depends on link status.
3215 * Skip if already done during boot.
3217 if (aconnector->base.force != DRM_FORCE_UNSPECIFIED
3218 && aconnector->dc_em_sink) {
3221 * For S3 resume with headless use eml_sink to fake stream
3222 * because on resume connector->sink is set to NULL
3224 mutex_lock(&dev->mode_config.mutex);
3227 if (aconnector->dc_sink) {
3228 amdgpu_dm_update_freesync_caps(connector, NULL);
3230 * retain and release below are used to
3231 * bump up refcount for sink because the link doesn't point
3232 * to it anymore after disconnect, so on next crtc to connector
3233 * reshuffle by UMD we will get into unwanted dc_sink release
3235 dc_sink_release(aconnector->dc_sink);
3237 aconnector->dc_sink = sink;
3238 dc_sink_retain(aconnector->dc_sink);
3239 amdgpu_dm_update_freesync_caps(connector,
3242 amdgpu_dm_update_freesync_caps(connector, NULL);
3243 if (!aconnector->dc_sink) {
3244 aconnector->dc_sink = aconnector->dc_em_sink;
3245 dc_sink_retain(aconnector->dc_sink);
3249 mutex_unlock(&dev->mode_config.mutex);
3252 dc_sink_release(sink);
3257 * TODO: temporary guard to look for proper fix
3258 * if this sink is MST sink, we should not do anything
3260 if (sink && sink->sink_signal == SIGNAL_TYPE_DISPLAY_PORT_MST) {
3261 dc_sink_release(sink);
3265 if (aconnector->dc_sink == sink) {
3267 * We got a DP short pulse (Link Loss, DP CTS, etc...).
3270 DRM_DEBUG_DRIVER("DCHPD: connector_id=%d: dc_sink didn't change.\n",
3271 aconnector->connector_id);
3273 dc_sink_release(sink);
3277 DRM_DEBUG_DRIVER("DCHPD: connector_id=%d: Old sink=%p New sink=%p\n",
3278 aconnector->connector_id, aconnector->dc_sink, sink);
3280 mutex_lock(&dev->mode_config.mutex);
3283 * 1. Update status of the drm connector
3284 * 2. Send an event and let userspace tell us what to do
3288 * TODO: check if we still need the S3 mode update workaround.
3289 * If yes, put it here.
3291 if (aconnector->dc_sink) {
3292 amdgpu_dm_update_freesync_caps(connector, NULL);
3293 dc_sink_release(aconnector->dc_sink);
3296 aconnector->dc_sink = sink;
3297 dc_sink_retain(aconnector->dc_sink);
3298 if (sink->dc_edid.length == 0) {
3299 aconnector->edid = NULL;
3300 if (aconnector->dc_link->aux_mode) {
3301 drm_dp_cec_unset_edid(
3302 &aconnector->dm_dp_aux.aux);
3306 (struct edid *)sink->dc_edid.raw_edid;
3308 if (aconnector->dc_link->aux_mode)
3309 drm_dp_cec_set_edid(&aconnector->dm_dp_aux.aux,
3313 if (!aconnector->timing_requested) {
3314 aconnector->timing_requested =
3315 kzalloc(sizeof(struct dc_crtc_timing), GFP_KERNEL);
3316 if (!aconnector->timing_requested)
3318 "failed to create aconnector->requested_timing\n");
3321 drm_connector_update_edid_property(connector, aconnector->edid);
3322 amdgpu_dm_update_freesync_caps(connector, aconnector->edid);
3323 update_connector_ext_caps(aconnector);
3325 drm_dp_cec_unset_edid(&aconnector->dm_dp_aux.aux);
3326 amdgpu_dm_update_freesync_caps(connector, NULL);
3327 drm_connector_update_edid_property(connector, NULL);
3328 aconnector->num_modes = 0;
3329 dc_sink_release(aconnector->dc_sink);
3330 aconnector->dc_sink = NULL;
3331 aconnector->edid = NULL;
3332 kfree(aconnector->timing_requested);
3333 aconnector->timing_requested = NULL;
3334 /* Set CP to DESIRED if it was ENABLED, so we can re-enable it again on hotplug */
3335 if (connector->state->content_protection == DRM_MODE_CONTENT_PROTECTION_ENABLED)
3336 connector->state->content_protection = DRM_MODE_CONTENT_PROTECTION_DESIRED;
3339 mutex_unlock(&dev->mode_config.mutex);
3341 update_subconnector_property(aconnector);
3344 dc_sink_release(sink);
3347 static void handle_hpd_irq_helper(struct amdgpu_dm_connector *aconnector)
3349 struct drm_connector *connector = &aconnector->base;
3350 struct drm_device *dev = connector->dev;
3351 enum dc_connection_type new_connection_type = dc_connection_none;
3352 struct amdgpu_device *adev = drm_to_adev(dev);
3353 struct dm_connector_state *dm_con_state = to_dm_connector_state(connector->state);
3356 if (adev->dm.disable_hpd_irq)
3360 * In case of failure or MST no need to update connector status or notify the OS
3361 * since (for MST case) MST does this in its own context.
3363 mutex_lock(&aconnector->hpd_lock);
3365 if (adev->dm.hdcp_workqueue) {
3366 hdcp_reset_display(adev->dm.hdcp_workqueue, aconnector->dc_link->link_index);
3367 dm_con_state->update_hdcp = true;
3369 if (aconnector->fake_enable)
3370 aconnector->fake_enable = false;
3372 aconnector->timing_changed = false;
3374 if (!dc_link_detect_connection_type(aconnector->dc_link, &new_connection_type))
3375 DRM_ERROR("KMS: Failed to detect connector\n");
3377 if (aconnector->base.force && new_connection_type == dc_connection_none) {
3378 emulated_link_detect(aconnector->dc_link);
3380 drm_modeset_lock_all(dev);
3381 dm_restore_drm_connector_state(dev, connector);
3382 drm_modeset_unlock_all(dev);
3384 if (aconnector->base.force == DRM_FORCE_UNSPECIFIED)
3385 drm_kms_helper_connector_hotplug_event(connector);
3387 mutex_lock(&adev->dm.dc_lock);
3388 ret = dc_link_detect(aconnector->dc_link, DETECT_REASON_HPD);
3389 mutex_unlock(&adev->dm.dc_lock);
3391 amdgpu_dm_update_connector_after_detect(aconnector);
3393 drm_modeset_lock_all(dev);
3394 dm_restore_drm_connector_state(dev, connector);
3395 drm_modeset_unlock_all(dev);
3397 if (aconnector->base.force == DRM_FORCE_UNSPECIFIED)
3398 drm_kms_helper_connector_hotplug_event(connector);
3401 mutex_unlock(&aconnector->hpd_lock);
3405 static void handle_hpd_irq(void *param)
3407 struct amdgpu_dm_connector *aconnector = (struct amdgpu_dm_connector *)param;
3409 handle_hpd_irq_helper(aconnector);
3413 static void schedule_hpd_rx_offload_work(struct hpd_rx_irq_offload_work_queue *offload_wq,
3414 union hpd_irq_data hpd_irq_data)
3416 struct hpd_rx_irq_offload_work *offload_work =
3417 kzalloc(sizeof(*offload_work), GFP_KERNEL);
3419 if (!offload_work) {
3420 DRM_ERROR("Failed to allocate hpd_rx_irq_offload_work.\n");
3424 INIT_WORK(&offload_work->work, dm_handle_hpd_rx_offload_work);
3425 offload_work->data = hpd_irq_data;
3426 offload_work->offload_wq = offload_wq;
3428 queue_work(offload_wq->wq, &offload_work->work);
3429 DRM_DEBUG_KMS("queue work to handle hpd_rx offload work");
3432 static void handle_hpd_rx_irq(void *param)
3434 struct amdgpu_dm_connector *aconnector = (struct amdgpu_dm_connector *)param;
3435 struct drm_connector *connector = &aconnector->base;
3436 struct drm_device *dev = connector->dev;
3437 struct dc_link *dc_link = aconnector->dc_link;
3438 bool is_mst_root_connector = aconnector->mst_mgr.mst_state;
3439 bool result = false;
3440 enum dc_connection_type new_connection_type = dc_connection_none;
3441 struct amdgpu_device *adev = drm_to_adev(dev);
3442 union hpd_irq_data hpd_irq_data;
3443 bool link_loss = false;
3444 bool has_left_work = false;
3445 int idx = dc_link->link_index;
3446 struct hpd_rx_irq_offload_work_queue *offload_wq = &adev->dm.hpd_rx_offload_wq[idx];
3448 memset(&hpd_irq_data, 0, sizeof(hpd_irq_data));
3450 if (adev->dm.disable_hpd_irq)
3454 * TODO:Temporary add mutex to protect hpd interrupt not have a gpio
3455 * conflict, after implement i2c helper, this mutex should be
3458 mutex_lock(&aconnector->hpd_lock);
3460 result = dc_link_handle_hpd_rx_irq(dc_link, &hpd_irq_data,
3461 &link_loss, true, &has_left_work);
3466 if (hpd_irq_data.bytes.device_service_irq.bits.AUTOMATED_TEST) {
3467 schedule_hpd_rx_offload_work(offload_wq, hpd_irq_data);
3471 if (dc_link_dp_allow_hpd_rx_irq(dc_link)) {
3472 if (hpd_irq_data.bytes.device_service_irq.bits.UP_REQ_MSG_RDY ||
3473 hpd_irq_data.bytes.device_service_irq.bits.DOWN_REP_MSG_RDY) {
3477 * DOWN_REP_MSG_RDY is also handled by polling method
3478 * mgr->cbs->poll_hpd_irq()
3480 spin_lock(&offload_wq->offload_lock);
3481 skip = offload_wq->is_handling_mst_msg_rdy_event;
3484 offload_wq->is_handling_mst_msg_rdy_event = true;
3486 spin_unlock(&offload_wq->offload_lock);
3489 schedule_hpd_rx_offload_work(offload_wq, hpd_irq_data);
3497 spin_lock(&offload_wq->offload_lock);
3498 skip = offload_wq->is_handling_link_loss;
3501 offload_wq->is_handling_link_loss = true;
3503 spin_unlock(&offload_wq->offload_lock);
3506 schedule_hpd_rx_offload_work(offload_wq, hpd_irq_data);
3513 if (result && !is_mst_root_connector) {
3514 /* Downstream Port status changed. */
3515 if (!dc_link_detect_connection_type(dc_link, &new_connection_type))
3516 DRM_ERROR("KMS: Failed to detect connector\n");
3518 if (aconnector->base.force && new_connection_type == dc_connection_none) {
3519 emulated_link_detect(dc_link);
3521 if (aconnector->fake_enable)
3522 aconnector->fake_enable = false;
3524 amdgpu_dm_update_connector_after_detect(aconnector);
3527 drm_modeset_lock_all(dev);
3528 dm_restore_drm_connector_state(dev, connector);
3529 drm_modeset_unlock_all(dev);
3531 drm_kms_helper_connector_hotplug_event(connector);
3535 mutex_lock(&adev->dm.dc_lock);
3536 ret = dc_link_detect(dc_link, DETECT_REASON_HPDRX);
3537 mutex_unlock(&adev->dm.dc_lock);
3540 if (aconnector->fake_enable)
3541 aconnector->fake_enable = false;
3543 amdgpu_dm_update_connector_after_detect(aconnector);
3545 drm_modeset_lock_all(dev);
3546 dm_restore_drm_connector_state(dev, connector);
3547 drm_modeset_unlock_all(dev);
3549 drm_kms_helper_connector_hotplug_event(connector);
3553 if (hpd_irq_data.bytes.device_service_irq.bits.CP_IRQ) {
3554 if (adev->dm.hdcp_workqueue)
3555 hdcp_handle_cpirq(adev->dm.hdcp_workqueue, aconnector->base.index);
3558 if (dc_link->type != dc_connection_mst_branch)
3559 drm_dp_cec_irq(&aconnector->dm_dp_aux.aux);
3561 mutex_unlock(&aconnector->hpd_lock);
3564 static void register_hpd_handlers(struct amdgpu_device *adev)
3566 struct drm_device *dev = adev_to_drm(adev);
3567 struct drm_connector *connector;
3568 struct amdgpu_dm_connector *aconnector;
3569 const struct dc_link *dc_link;
3570 struct dc_interrupt_params int_params = {0};
3572 int_params.requested_polarity = INTERRUPT_POLARITY_DEFAULT;
3573 int_params.current_polarity = INTERRUPT_POLARITY_DEFAULT;
3575 if (dc_is_dmub_outbox_supported(adev->dm.dc)) {
3576 if (!register_dmub_notify_callback(adev, DMUB_NOTIFICATION_HPD, dmub_hpd_callback, true))
3577 DRM_ERROR("amdgpu: fail to register dmub hpd callback");
3579 if (!register_dmub_notify_callback(adev, DMUB_NOTIFICATION_HPD_IRQ, dmub_hpd_callback, true))
3580 DRM_ERROR("amdgpu: fail to register dmub hpd callback");
3583 list_for_each_entry(connector,
3584 &dev->mode_config.connector_list, head) {
3586 if (connector->connector_type == DRM_MODE_CONNECTOR_WRITEBACK)
3589 aconnector = to_amdgpu_dm_connector(connector);
3590 dc_link = aconnector->dc_link;
3592 if (dc_link->irq_source_hpd != DC_IRQ_SOURCE_INVALID) {
3593 int_params.int_context = INTERRUPT_LOW_IRQ_CONTEXT;
3594 int_params.irq_source = dc_link->irq_source_hpd;
3596 amdgpu_dm_irq_register_interrupt(adev, &int_params,
3598 (void *) aconnector);
3601 if (dc_link->irq_source_hpd_rx != DC_IRQ_SOURCE_INVALID) {
3603 /* Also register for DP short pulse (hpd_rx). */
3604 int_params.int_context = INTERRUPT_LOW_IRQ_CONTEXT;
3605 int_params.irq_source = dc_link->irq_source_hpd_rx;
3607 amdgpu_dm_irq_register_interrupt(adev, &int_params,
3609 (void *) aconnector);
3614 #if defined(CONFIG_DRM_AMD_DC_SI)
3615 /* Register IRQ sources and initialize IRQ callbacks */
3616 static int dce60_register_irq_handlers(struct amdgpu_device *adev)
3618 struct dc *dc = adev->dm.dc;
3619 struct common_irq_params *c_irq_params;
3620 struct dc_interrupt_params int_params = {0};
3623 unsigned int client_id = AMDGPU_IRQ_CLIENTID_LEGACY;
3625 int_params.requested_polarity = INTERRUPT_POLARITY_DEFAULT;
3626 int_params.current_polarity = INTERRUPT_POLARITY_DEFAULT;
3629 * Actions of amdgpu_irq_add_id():
3630 * 1. Register a set() function with base driver.
3631 * Base driver will call set() function to enable/disable an
3632 * interrupt in DC hardware.
3633 * 2. Register amdgpu_dm_irq_handler().
3634 * Base driver will call amdgpu_dm_irq_handler() for ALL interrupts
3635 * coming from DC hardware.
3636 * amdgpu_dm_irq_handler() will re-direct the interrupt to DC
3637 * for acknowledging and handling.
3640 /* Use VBLANK interrupt */
3641 for (i = 0; i < adev->mode_info.num_crtc; i++) {
3642 r = amdgpu_irq_add_id(adev, client_id, i + 1, &adev->crtc_irq);
3644 DRM_ERROR("Failed to add crtc irq id!\n");
3648 int_params.int_context = INTERRUPT_HIGH_IRQ_CONTEXT;
3649 int_params.irq_source =
3650 dc_interrupt_to_irq_source(dc, i + 1, 0);
3652 c_irq_params = &adev->dm.vblank_params[int_params.irq_source - DC_IRQ_SOURCE_VBLANK1];
3654 c_irq_params->adev = adev;
3655 c_irq_params->irq_src = int_params.irq_source;
3657 amdgpu_dm_irq_register_interrupt(adev, &int_params,
3658 dm_crtc_high_irq, c_irq_params);
3661 /* Use GRPH_PFLIP interrupt */
3662 for (i = VISLANDS30_IV_SRCID_D1_GRPH_PFLIP;
3663 i <= VISLANDS30_IV_SRCID_D6_GRPH_PFLIP; i += 2) {
3664 r = amdgpu_irq_add_id(adev, client_id, i, &adev->pageflip_irq);
3666 DRM_ERROR("Failed to add page flip irq id!\n");
3670 int_params.int_context = INTERRUPT_HIGH_IRQ_CONTEXT;
3671 int_params.irq_source =
3672 dc_interrupt_to_irq_source(dc, i, 0);
3674 c_irq_params = &adev->dm.pflip_params[int_params.irq_source - DC_IRQ_SOURCE_PFLIP_FIRST];
3676 c_irq_params->adev = adev;
3677 c_irq_params->irq_src = int_params.irq_source;
3679 amdgpu_dm_irq_register_interrupt(adev, &int_params,
3680 dm_pflip_high_irq, c_irq_params);
3685 r = amdgpu_irq_add_id(adev, client_id,
3686 VISLANDS30_IV_SRCID_HOTPLUG_DETECT_A, &adev->hpd_irq);
3688 DRM_ERROR("Failed to add hpd irq id!\n");
3692 register_hpd_handlers(adev);
3698 /* Register IRQ sources and initialize IRQ callbacks */
3699 static int dce110_register_irq_handlers(struct amdgpu_device *adev)
3701 struct dc *dc = adev->dm.dc;
3702 struct common_irq_params *c_irq_params;
3703 struct dc_interrupt_params int_params = {0};
3706 unsigned int client_id = AMDGPU_IRQ_CLIENTID_LEGACY;
3708 if (adev->family >= AMDGPU_FAMILY_AI)
3709 client_id = SOC15_IH_CLIENTID_DCE;
3711 int_params.requested_polarity = INTERRUPT_POLARITY_DEFAULT;
3712 int_params.current_polarity = INTERRUPT_POLARITY_DEFAULT;
3715 * Actions of amdgpu_irq_add_id():
3716 * 1. Register a set() function with base driver.
3717 * Base driver will call set() function to enable/disable an
3718 * interrupt in DC hardware.
3719 * 2. Register amdgpu_dm_irq_handler().
3720 * Base driver will call amdgpu_dm_irq_handler() for ALL interrupts
3721 * coming from DC hardware.
3722 * amdgpu_dm_irq_handler() will re-direct the interrupt to DC
3723 * for acknowledging and handling.
3726 /* Use VBLANK interrupt */
3727 for (i = VISLANDS30_IV_SRCID_D1_VERTICAL_INTERRUPT0; i <= VISLANDS30_IV_SRCID_D6_VERTICAL_INTERRUPT0; i++) {
3728 r = amdgpu_irq_add_id(adev, client_id, i, &adev->crtc_irq);
3730 DRM_ERROR("Failed to add crtc irq id!\n");
3734 int_params.int_context = INTERRUPT_HIGH_IRQ_CONTEXT;
3735 int_params.irq_source =
3736 dc_interrupt_to_irq_source(dc, i, 0);
3738 c_irq_params = &adev->dm.vblank_params[int_params.irq_source - DC_IRQ_SOURCE_VBLANK1];
3740 c_irq_params->adev = adev;
3741 c_irq_params->irq_src = int_params.irq_source;
3743 amdgpu_dm_irq_register_interrupt(adev, &int_params,
3744 dm_crtc_high_irq, c_irq_params);
3747 /* Use VUPDATE interrupt */
3748 for (i = VISLANDS30_IV_SRCID_D1_V_UPDATE_INT; i <= VISLANDS30_IV_SRCID_D6_V_UPDATE_INT; i += 2) {
3749 r = amdgpu_irq_add_id(adev, client_id, i, &adev->vupdate_irq);
3751 DRM_ERROR("Failed to add vupdate irq id!\n");
3755 int_params.int_context = INTERRUPT_HIGH_IRQ_CONTEXT;
3756 int_params.irq_source =
3757 dc_interrupt_to_irq_source(dc, i, 0);
3759 c_irq_params = &adev->dm.vupdate_params[int_params.irq_source - DC_IRQ_SOURCE_VUPDATE1];
3761 c_irq_params->adev = adev;
3762 c_irq_params->irq_src = int_params.irq_source;
3764 amdgpu_dm_irq_register_interrupt(adev, &int_params,
3765 dm_vupdate_high_irq, c_irq_params);
3768 /* Use GRPH_PFLIP interrupt */
3769 for (i = VISLANDS30_IV_SRCID_D1_GRPH_PFLIP;
3770 i <= VISLANDS30_IV_SRCID_D6_GRPH_PFLIP; i += 2) {
3771 r = amdgpu_irq_add_id(adev, client_id, i, &adev->pageflip_irq);
3773 DRM_ERROR("Failed to add page flip irq id!\n");
3777 int_params.int_context = INTERRUPT_HIGH_IRQ_CONTEXT;
3778 int_params.irq_source =
3779 dc_interrupt_to_irq_source(dc, i, 0);
3781 c_irq_params = &adev->dm.pflip_params[int_params.irq_source - DC_IRQ_SOURCE_PFLIP_FIRST];
3783 c_irq_params->adev = adev;
3784 c_irq_params->irq_src = int_params.irq_source;
3786 amdgpu_dm_irq_register_interrupt(adev, &int_params,
3787 dm_pflip_high_irq, c_irq_params);
3792 r = amdgpu_irq_add_id(adev, client_id,
3793 VISLANDS30_IV_SRCID_HOTPLUG_DETECT_A, &adev->hpd_irq);
3795 DRM_ERROR("Failed to add hpd irq id!\n");
3799 register_hpd_handlers(adev);
3804 /* Register IRQ sources and initialize IRQ callbacks */
3805 static int dcn10_register_irq_handlers(struct amdgpu_device *adev)
3807 struct dc *dc = adev->dm.dc;
3808 struct common_irq_params *c_irq_params;
3809 struct dc_interrupt_params int_params = {0};
3812 #if defined(CONFIG_DRM_AMD_SECURE_DISPLAY)
3813 static const unsigned int vrtl_int_srcid[] = {
3814 DCN_1_0__SRCID__OTG1_VERTICAL_INTERRUPT0_CONTROL,
3815 DCN_1_0__SRCID__OTG2_VERTICAL_INTERRUPT0_CONTROL,
3816 DCN_1_0__SRCID__OTG3_VERTICAL_INTERRUPT0_CONTROL,
3817 DCN_1_0__SRCID__OTG4_VERTICAL_INTERRUPT0_CONTROL,
3818 DCN_1_0__SRCID__OTG5_VERTICAL_INTERRUPT0_CONTROL,
3819 DCN_1_0__SRCID__OTG6_VERTICAL_INTERRUPT0_CONTROL
3823 int_params.requested_polarity = INTERRUPT_POLARITY_DEFAULT;
3824 int_params.current_polarity = INTERRUPT_POLARITY_DEFAULT;
3827 * Actions of amdgpu_irq_add_id():
3828 * 1. Register a set() function with base driver.
3829 * Base driver will call set() function to enable/disable an
3830 * interrupt in DC hardware.
3831 * 2. Register amdgpu_dm_irq_handler().
3832 * Base driver will call amdgpu_dm_irq_handler() for ALL interrupts
3833 * coming from DC hardware.
3834 * amdgpu_dm_irq_handler() will re-direct the interrupt to DC
3835 * for acknowledging and handling.
3838 /* Use VSTARTUP interrupt */
3839 for (i = DCN_1_0__SRCID__DC_D1_OTG_VSTARTUP;
3840 i <= DCN_1_0__SRCID__DC_D1_OTG_VSTARTUP + adev->mode_info.num_crtc - 1;
3842 r = amdgpu_irq_add_id(adev, SOC15_IH_CLIENTID_DCE, i, &adev->crtc_irq);
3845 DRM_ERROR("Failed to add crtc irq id!\n");
3849 int_params.int_context = INTERRUPT_HIGH_IRQ_CONTEXT;
3850 int_params.irq_source =
3851 dc_interrupt_to_irq_source(dc, i, 0);
3853 c_irq_params = &adev->dm.vblank_params[int_params.irq_source - DC_IRQ_SOURCE_VBLANK1];
3855 c_irq_params->adev = adev;
3856 c_irq_params->irq_src = int_params.irq_source;
3858 amdgpu_dm_irq_register_interrupt(
3859 adev, &int_params, dm_crtc_high_irq, c_irq_params);
3862 /* Use otg vertical line interrupt */
3863 #if defined(CONFIG_DRM_AMD_SECURE_DISPLAY)
3864 for (i = 0; i <= adev->mode_info.num_crtc - 1; i++) {
3865 r = amdgpu_irq_add_id(adev, SOC15_IH_CLIENTID_DCE,
3866 vrtl_int_srcid[i], &adev->vline0_irq);
3869 DRM_ERROR("Failed to add vline0 irq id!\n");
3873 int_params.int_context = INTERRUPT_HIGH_IRQ_CONTEXT;
3874 int_params.irq_source =
3875 dc_interrupt_to_irq_source(dc, vrtl_int_srcid[i], 0);
3877 if (int_params.irq_source == DC_IRQ_SOURCE_INVALID) {
3878 DRM_ERROR("Failed to register vline0 irq %d!\n", vrtl_int_srcid[i]);
3882 c_irq_params = &adev->dm.vline0_params[int_params.irq_source
3883 - DC_IRQ_SOURCE_DC1_VLINE0];
3885 c_irq_params->adev = adev;
3886 c_irq_params->irq_src = int_params.irq_source;
3888 amdgpu_dm_irq_register_interrupt(adev, &int_params,
3889 dm_dcn_vertical_interrupt0_high_irq, c_irq_params);
3893 /* Use VUPDATE_NO_LOCK interrupt on DCN, which seems to correspond to
3894 * the regular VUPDATE interrupt on DCE. We want DC_IRQ_SOURCE_VUPDATEx
3895 * to trigger at end of each vblank, regardless of state of the lock,
3896 * matching DCE behaviour.
3898 for (i = DCN_1_0__SRCID__OTG0_IHC_V_UPDATE_NO_LOCK_INTERRUPT;
3899 i <= DCN_1_0__SRCID__OTG0_IHC_V_UPDATE_NO_LOCK_INTERRUPT + adev->mode_info.num_crtc - 1;
3901 r = amdgpu_irq_add_id(adev, SOC15_IH_CLIENTID_DCE, i, &adev->vupdate_irq);
3904 DRM_ERROR("Failed to add vupdate irq id!\n");
3908 int_params.int_context = INTERRUPT_HIGH_IRQ_CONTEXT;
3909 int_params.irq_source =
3910 dc_interrupt_to_irq_source(dc, i, 0);
3912 c_irq_params = &adev->dm.vupdate_params[int_params.irq_source - DC_IRQ_SOURCE_VUPDATE1];
3914 c_irq_params->adev = adev;
3915 c_irq_params->irq_src = int_params.irq_source;
3917 amdgpu_dm_irq_register_interrupt(adev, &int_params,
3918 dm_vupdate_high_irq, c_irq_params);
3921 /* Use GRPH_PFLIP interrupt */
3922 for (i = DCN_1_0__SRCID__HUBP0_FLIP_INTERRUPT;
3923 i <= DCN_1_0__SRCID__HUBP0_FLIP_INTERRUPT + dc->caps.max_otg_num - 1;
3925 r = amdgpu_irq_add_id(adev, SOC15_IH_CLIENTID_DCE, i, &adev->pageflip_irq);
3927 DRM_ERROR("Failed to add page flip irq id!\n");
3931 int_params.int_context = INTERRUPT_HIGH_IRQ_CONTEXT;
3932 int_params.irq_source =
3933 dc_interrupt_to_irq_source(dc, i, 0);
3935 c_irq_params = &adev->dm.pflip_params[int_params.irq_source - DC_IRQ_SOURCE_PFLIP_FIRST];
3937 c_irq_params->adev = adev;
3938 c_irq_params->irq_src = int_params.irq_source;
3940 amdgpu_dm_irq_register_interrupt(adev, &int_params,
3941 dm_pflip_high_irq, c_irq_params);
3946 r = amdgpu_irq_add_id(adev, SOC15_IH_CLIENTID_DCE, DCN_1_0__SRCID__DC_HPD1_INT,
3949 DRM_ERROR("Failed to add hpd irq id!\n");
3953 register_hpd_handlers(adev);
3957 /* Register Outbox IRQ sources and initialize IRQ callbacks */
3958 static int register_outbox_irq_handlers(struct amdgpu_device *adev)
3960 struct dc *dc = adev->dm.dc;
3961 struct common_irq_params *c_irq_params;
3962 struct dc_interrupt_params int_params = {0};
3965 int_params.requested_polarity = INTERRUPT_POLARITY_DEFAULT;
3966 int_params.current_polarity = INTERRUPT_POLARITY_DEFAULT;
3968 r = amdgpu_irq_add_id(adev, SOC15_IH_CLIENTID_DCE, DCN_1_0__SRCID__DMCUB_OUTBOX_LOW_PRIORITY_READY_INT,
3969 &adev->dmub_outbox_irq);
3971 DRM_ERROR("Failed to add outbox irq id!\n");
3975 if (dc->ctx->dmub_srv) {
3976 i = DCN_1_0__SRCID__DMCUB_OUTBOX_LOW_PRIORITY_READY_INT;
3977 int_params.int_context = INTERRUPT_LOW_IRQ_CONTEXT;
3978 int_params.irq_source =
3979 dc_interrupt_to_irq_source(dc, i, 0);
3981 c_irq_params = &adev->dm.dmub_outbox_params[0];
3983 c_irq_params->adev = adev;
3984 c_irq_params->irq_src = int_params.irq_source;
3986 amdgpu_dm_irq_register_interrupt(adev, &int_params,
3987 dm_dmub_outbox1_low_irq, c_irq_params);
3994 * Acquires the lock for the atomic state object and returns
3995 * the new atomic state.
3997 * This should only be called during atomic check.
3999 int dm_atomic_get_state(struct drm_atomic_state *state,
4000 struct dm_atomic_state **dm_state)
4002 struct drm_device *dev = state->dev;
4003 struct amdgpu_device *adev = drm_to_adev(dev);
4004 struct amdgpu_display_manager *dm = &adev->dm;
4005 struct drm_private_state *priv_state;
4010 priv_state = drm_atomic_get_private_obj_state(state, &dm->atomic_obj);
4011 if (IS_ERR(priv_state))
4012 return PTR_ERR(priv_state);
4014 *dm_state = to_dm_atomic_state(priv_state);
4019 static struct dm_atomic_state *
4020 dm_atomic_get_new_state(struct drm_atomic_state *state)
4022 struct drm_device *dev = state->dev;
4023 struct amdgpu_device *adev = drm_to_adev(dev);
4024 struct amdgpu_display_manager *dm = &adev->dm;
4025 struct drm_private_obj *obj;
4026 struct drm_private_state *new_obj_state;
4029 for_each_new_private_obj_in_state(state, obj, new_obj_state, i) {
4030 if (obj->funcs == dm->atomic_obj.funcs)
4031 return to_dm_atomic_state(new_obj_state);
4037 static struct drm_private_state *
4038 dm_atomic_duplicate_state(struct drm_private_obj *obj)
4040 struct dm_atomic_state *old_state, *new_state;
4042 new_state = kzalloc(sizeof(*new_state), GFP_KERNEL);
4046 __drm_atomic_helper_private_obj_duplicate_state(obj, &new_state->base);
4048 old_state = to_dm_atomic_state(obj->state);
4050 if (old_state && old_state->context)
4051 new_state->context = dc_state_create_copy(old_state->context);
4053 if (!new_state->context) {
4058 return &new_state->base;
4061 static void dm_atomic_destroy_state(struct drm_private_obj *obj,
4062 struct drm_private_state *state)
4064 struct dm_atomic_state *dm_state = to_dm_atomic_state(state);
4066 if (dm_state && dm_state->context)
4067 dc_state_release(dm_state->context);
4072 static struct drm_private_state_funcs dm_atomic_state_funcs = {
4073 .atomic_duplicate_state = dm_atomic_duplicate_state,
4074 .atomic_destroy_state = dm_atomic_destroy_state,
4077 static int amdgpu_dm_mode_config_init(struct amdgpu_device *adev)
4079 struct dm_atomic_state *state;
4082 adev->mode_info.mode_config_initialized = true;
4084 adev_to_drm(adev)->mode_config.funcs = (void *)&amdgpu_dm_mode_funcs;
4085 adev_to_drm(adev)->mode_config.helper_private = &amdgpu_dm_mode_config_helperfuncs;
4087 adev_to_drm(adev)->mode_config.max_width = 16384;
4088 adev_to_drm(adev)->mode_config.max_height = 16384;
4090 adev_to_drm(adev)->mode_config.preferred_depth = 24;
4091 if (adev->asic_type == CHIP_HAWAII)
4092 /* disable prefer shadow for now due to hibernation issues */
4093 adev_to_drm(adev)->mode_config.prefer_shadow = 0;
4095 adev_to_drm(adev)->mode_config.prefer_shadow = 1;
4096 /* indicates support for immediate flip */
4097 adev_to_drm(adev)->mode_config.async_page_flip = true;
4099 state = kzalloc(sizeof(*state), GFP_KERNEL);
4103 state->context = dc_state_create_current_copy(adev->dm.dc);
4104 if (!state->context) {
4109 drm_atomic_private_obj_init(adev_to_drm(adev),
4110 &adev->dm.atomic_obj,
4112 &dm_atomic_state_funcs);
4114 r = amdgpu_display_modeset_create_props(adev);
4116 dc_state_release(state->context);
4121 #ifdef AMD_PRIVATE_COLOR
4122 if (amdgpu_dm_create_color_properties(adev))
4126 r = amdgpu_dm_audio_init(adev);
4128 dc_state_release(state->context);
4136 #define AMDGPU_DM_DEFAULT_MIN_BACKLIGHT 12
4137 #define AMDGPU_DM_DEFAULT_MAX_BACKLIGHT 255
4138 #define AUX_BL_DEFAULT_TRANSITION_TIME_MS 50
4140 static void amdgpu_dm_update_backlight_caps(struct amdgpu_display_manager *dm,
4143 #if defined(CONFIG_ACPI)
4144 struct amdgpu_dm_backlight_caps caps;
4146 memset(&caps, 0, sizeof(caps));
4148 if (dm->backlight_caps[bl_idx].caps_valid)
4151 amdgpu_acpi_get_backlight_caps(&caps);
4152 if (caps.caps_valid) {
4153 dm->backlight_caps[bl_idx].caps_valid = true;
4154 if (caps.aux_support)
4156 dm->backlight_caps[bl_idx].min_input_signal = caps.min_input_signal;
4157 dm->backlight_caps[bl_idx].max_input_signal = caps.max_input_signal;
4159 dm->backlight_caps[bl_idx].min_input_signal =
4160 AMDGPU_DM_DEFAULT_MIN_BACKLIGHT;
4161 dm->backlight_caps[bl_idx].max_input_signal =
4162 AMDGPU_DM_DEFAULT_MAX_BACKLIGHT;
4165 if (dm->backlight_caps[bl_idx].aux_support)
4168 dm->backlight_caps[bl_idx].min_input_signal = AMDGPU_DM_DEFAULT_MIN_BACKLIGHT;
4169 dm->backlight_caps[bl_idx].max_input_signal = AMDGPU_DM_DEFAULT_MAX_BACKLIGHT;
4173 static int get_brightness_range(const struct amdgpu_dm_backlight_caps *caps,
4174 unsigned int *min, unsigned int *max)
4179 if (caps->aux_support) {
4180 // Firmware limits are in nits, DC API wants millinits.
4181 *max = 1000 * caps->aux_max_input_signal;
4182 *min = 1000 * caps->aux_min_input_signal;
4184 // Firmware limits are 8-bit, PWM control is 16-bit.
4185 *max = 0x101 * caps->max_input_signal;
4186 *min = 0x101 * caps->min_input_signal;
4191 static u32 convert_brightness_from_user(const struct amdgpu_dm_backlight_caps *caps,
4192 uint32_t brightness)
4194 unsigned int min, max;
4196 if (!get_brightness_range(caps, &min, &max))
4199 // Rescale 0..255 to min..max
4200 return min + DIV_ROUND_CLOSEST((max - min) * brightness,
4201 AMDGPU_MAX_BL_LEVEL);
4204 static u32 convert_brightness_to_user(const struct amdgpu_dm_backlight_caps *caps,
4205 uint32_t brightness)
4207 unsigned int min, max;
4209 if (!get_brightness_range(caps, &min, &max))
4212 if (brightness < min)
4214 // Rescale min..max to 0..255
4215 return DIV_ROUND_CLOSEST(AMDGPU_MAX_BL_LEVEL * (brightness - min),
4219 static void amdgpu_dm_backlight_set_level(struct amdgpu_display_manager *dm,
4221 u32 user_brightness)
4223 struct amdgpu_dm_backlight_caps caps;
4224 struct dc_link *link;
4228 amdgpu_dm_update_backlight_caps(dm, bl_idx);
4229 caps = dm->backlight_caps[bl_idx];
4231 dm->brightness[bl_idx] = user_brightness;
4232 /* update scratch register */
4234 amdgpu_atombios_scratch_regs_set_backlight_level(dm->adev, dm->brightness[bl_idx]);
4235 brightness = convert_brightness_from_user(&caps, dm->brightness[bl_idx]);
4236 link = (struct dc_link *)dm->backlight_link[bl_idx];
4238 /* Change brightness based on AUX property */
4239 if (caps.aux_support) {
4240 rc = dc_link_set_backlight_level_nits(link, true, brightness,
4241 AUX_BL_DEFAULT_TRANSITION_TIME_MS);
4243 DRM_DEBUG("DM: Failed to update backlight via AUX on eDP[%d]\n", bl_idx);
4245 rc = dc_link_set_backlight_level(link, brightness, 0);
4247 DRM_DEBUG("DM: Failed to update backlight on eDP[%d]\n", bl_idx);
4251 dm->actual_brightness[bl_idx] = user_brightness;
4254 static int amdgpu_dm_backlight_update_status(struct backlight_device *bd)
4256 struct amdgpu_display_manager *dm = bl_get_data(bd);
4259 for (i = 0; i < dm->num_of_edps; i++) {
4260 if (bd == dm->backlight_dev[i])
4263 if (i >= AMDGPU_DM_MAX_NUM_EDP)
4265 amdgpu_dm_backlight_set_level(dm, i, bd->props.brightness);
4270 static u32 amdgpu_dm_backlight_get_level(struct amdgpu_display_manager *dm,
4274 struct amdgpu_dm_backlight_caps caps;
4275 struct dc_link *link = (struct dc_link *)dm->backlight_link[bl_idx];
4277 amdgpu_dm_update_backlight_caps(dm, bl_idx);
4278 caps = dm->backlight_caps[bl_idx];
4280 if (caps.aux_support) {
4284 rc = dc_link_get_backlight_level_nits(link, &avg, &peak);
4286 return dm->brightness[bl_idx];
4287 return convert_brightness_to_user(&caps, avg);
4290 ret = dc_link_get_backlight_level(link);
4292 if (ret == DC_ERROR_UNEXPECTED)
4293 return dm->brightness[bl_idx];
4295 return convert_brightness_to_user(&caps, ret);
4298 static int amdgpu_dm_backlight_get_brightness(struct backlight_device *bd)
4300 struct amdgpu_display_manager *dm = bl_get_data(bd);
4303 for (i = 0; i < dm->num_of_edps; i++) {
4304 if (bd == dm->backlight_dev[i])
4307 if (i >= AMDGPU_DM_MAX_NUM_EDP)
4309 return amdgpu_dm_backlight_get_level(dm, i);
4312 static const struct backlight_ops amdgpu_dm_backlight_ops = {
4313 .options = BL_CORE_SUSPENDRESUME,
4314 .get_brightness = amdgpu_dm_backlight_get_brightness,
4315 .update_status = amdgpu_dm_backlight_update_status,
4319 amdgpu_dm_register_backlight_device(struct amdgpu_dm_connector *aconnector)
4321 struct drm_device *drm = aconnector->base.dev;
4322 struct amdgpu_display_manager *dm = &drm_to_adev(drm)->dm;
4323 struct backlight_properties props = { 0 };
4326 if (aconnector->bl_idx == -1)
4329 if (!acpi_video_backlight_use_native()) {
4330 drm_info(drm, "Skipping amdgpu DM backlight registration\n");
4331 /* Try registering an ACPI video backlight device instead. */
4332 acpi_video_register_backlight();
4336 props.max_brightness = AMDGPU_MAX_BL_LEVEL;
4337 props.brightness = AMDGPU_MAX_BL_LEVEL;
4338 props.type = BACKLIGHT_RAW;
4340 snprintf(bl_name, sizeof(bl_name), "amdgpu_bl%d",
4341 drm->primary->index + aconnector->bl_idx);
4343 dm->backlight_dev[aconnector->bl_idx] =
4344 backlight_device_register(bl_name, aconnector->base.kdev, dm,
4345 &amdgpu_dm_backlight_ops, &props);
4347 if (IS_ERR(dm->backlight_dev[aconnector->bl_idx])) {
4348 DRM_ERROR("DM: Backlight registration failed!\n");
4349 dm->backlight_dev[aconnector->bl_idx] = NULL;
4351 DRM_DEBUG_DRIVER("DM: Registered Backlight device: %s\n", bl_name);
4354 static int initialize_plane(struct amdgpu_display_manager *dm,
4355 struct amdgpu_mode_info *mode_info, int plane_id,
4356 enum drm_plane_type plane_type,
4357 const struct dc_plane_cap *plane_cap)
4359 struct drm_plane *plane;
4360 unsigned long possible_crtcs;
4363 plane = kzalloc(sizeof(struct drm_plane), GFP_KERNEL);
4365 DRM_ERROR("KMS: Failed to allocate plane\n");
4368 plane->type = plane_type;
4371 * HACK: IGT tests expect that the primary plane for a CRTC
4372 * can only have one possible CRTC. Only expose support for
4373 * any CRTC if they're not going to be used as a primary plane
4374 * for a CRTC - like overlay or underlay planes.
4376 possible_crtcs = 1 << plane_id;
4377 if (plane_id >= dm->dc->caps.max_streams)
4378 possible_crtcs = 0xff;
4380 ret = amdgpu_dm_plane_init(dm, plane, possible_crtcs, plane_cap);
4383 DRM_ERROR("KMS: Failed to initialize plane\n");
4389 mode_info->planes[plane_id] = plane;
4395 static void setup_backlight_device(struct amdgpu_display_manager *dm,
4396 struct amdgpu_dm_connector *aconnector)
4398 struct dc_link *link = aconnector->dc_link;
4399 int bl_idx = dm->num_of_edps;
4401 if (!(link->connector_signal & (SIGNAL_TYPE_EDP | SIGNAL_TYPE_LVDS)) ||
4402 link->type == dc_connection_none)
4405 if (dm->num_of_edps >= AMDGPU_DM_MAX_NUM_EDP) {
4406 drm_warn(adev_to_drm(dm->adev), "Too much eDP connections, skipping backlight setup for additional eDPs\n");
4410 aconnector->bl_idx = bl_idx;
4412 amdgpu_dm_update_backlight_caps(dm, bl_idx);
4413 dm->brightness[bl_idx] = AMDGPU_MAX_BL_LEVEL;
4414 dm->backlight_link[bl_idx] = link;
4417 update_connector_ext_caps(aconnector);
4420 static void amdgpu_set_panel_orientation(struct drm_connector *connector);
4423 * In this architecture, the association
4424 * connector -> encoder -> crtc
4425 * id not really requried. The crtc and connector will hold the
4426 * display_index as an abstraction to use with DAL component
4428 * Returns 0 on success
4430 static int amdgpu_dm_initialize_drm_device(struct amdgpu_device *adev)
4432 struct amdgpu_display_manager *dm = &adev->dm;
4434 struct amdgpu_dm_connector *aconnector = NULL;
4435 struct amdgpu_encoder *aencoder = NULL;
4436 struct amdgpu_mode_info *mode_info = &adev->mode_info;
4439 enum dc_connection_type new_connection_type = dc_connection_none;
4440 const struct dc_plane_cap *plane;
4441 bool psr_feature_enabled = false;
4442 bool replay_feature_enabled = false;
4443 int max_overlay = dm->dc->caps.max_slave_planes;
4445 dm->display_indexes_num = dm->dc->caps.max_streams;
4446 /* Update the actual used number of crtc */
4447 adev->mode_info.num_crtc = adev->dm.display_indexes_num;
4449 amdgpu_dm_set_irq_funcs(adev);
4451 link_cnt = dm->dc->caps.max_links;
4452 if (amdgpu_dm_mode_config_init(dm->adev)) {
4453 DRM_ERROR("DM: Failed to initialize mode config\n");
4457 /* There is one primary plane per CRTC */
4458 primary_planes = dm->dc->caps.max_streams;
4459 ASSERT(primary_planes <= AMDGPU_MAX_PLANES);
4462 * Initialize primary planes, implicit planes for legacy IOCTLS.
4463 * Order is reversed to match iteration order in atomic check.
4465 for (i = (primary_planes - 1); i >= 0; i--) {
4466 plane = &dm->dc->caps.planes[i];
4468 if (initialize_plane(dm, mode_info, i,
4469 DRM_PLANE_TYPE_PRIMARY, plane)) {
4470 DRM_ERROR("KMS: Failed to initialize primary plane\n");
4476 * Initialize overlay planes, index starting after primary planes.
4477 * These planes have a higher DRM index than the primary planes since
4478 * they should be considered as having a higher z-order.
4479 * Order is reversed to match iteration order in atomic check.
4481 * Only support DCN for now, and only expose one so we don't encourage
4482 * userspace to use up all the pipes.
4484 for (i = 0; i < dm->dc->caps.max_planes; ++i) {
4485 struct dc_plane_cap *plane = &dm->dc->caps.planes[i];
4487 /* Do not create overlay if MPO disabled */
4488 if (amdgpu_dc_debug_mask & DC_DISABLE_MPO)
4491 if (plane->type != DC_PLANE_TYPE_DCN_UNIVERSAL)
4494 if (!plane->pixel_format_support.argb8888)
4497 if (max_overlay-- == 0)
4500 if (initialize_plane(dm, NULL, primary_planes + i,
4501 DRM_PLANE_TYPE_OVERLAY, plane)) {
4502 DRM_ERROR("KMS: Failed to initialize overlay plane\n");
4507 for (i = 0; i < dm->dc->caps.max_streams; i++)
4508 if (amdgpu_dm_crtc_init(dm, mode_info->planes[i], i)) {
4509 DRM_ERROR("KMS: Failed to initialize crtc\n");
4513 /* Use Outbox interrupt */
4514 switch (amdgpu_ip_version(adev, DCE_HWIP, 0)) {
4515 case IP_VERSION(3, 0, 0):
4516 case IP_VERSION(3, 1, 2):
4517 case IP_VERSION(3, 1, 3):
4518 case IP_VERSION(3, 1, 4):
4519 case IP_VERSION(3, 1, 5):
4520 case IP_VERSION(3, 1, 6):
4521 case IP_VERSION(3, 2, 0):
4522 case IP_VERSION(3, 2, 1):
4523 case IP_VERSION(2, 1, 0):
4524 case IP_VERSION(3, 5, 0):
4525 case IP_VERSION(3, 5, 1):
4526 if (register_outbox_irq_handlers(dm->adev)) {
4527 DRM_ERROR("DM: Failed to initialize IRQ\n");
4532 DRM_DEBUG_KMS("Unsupported DCN IP version for outbox: 0x%X\n",
4533 amdgpu_ip_version(adev, DCE_HWIP, 0));
4536 /* Determine whether to enable PSR support by default. */
4537 if (!(amdgpu_dc_debug_mask & DC_DISABLE_PSR)) {
4538 switch (amdgpu_ip_version(adev, DCE_HWIP, 0)) {
4539 case IP_VERSION(3, 1, 2):
4540 case IP_VERSION(3, 1, 3):
4541 case IP_VERSION(3, 1, 4):
4542 case IP_VERSION(3, 1, 5):
4543 case IP_VERSION(3, 1, 6):
4544 case IP_VERSION(3, 2, 0):
4545 case IP_VERSION(3, 2, 1):
4546 case IP_VERSION(3, 5, 0):
4547 case IP_VERSION(3, 5, 1):
4548 psr_feature_enabled = true;
4551 psr_feature_enabled = amdgpu_dc_feature_mask & DC_PSR_MASK;
4556 /* Determine whether to enable Replay support by default. */
4557 if (!(amdgpu_dc_debug_mask & DC_DISABLE_REPLAY)) {
4558 switch (amdgpu_ip_version(adev, DCE_HWIP, 0)) {
4560 * Disabled by default due to https://gitlab.freedesktop.org/drm/amd/-/issues/3344
4561 * case IP_VERSION(3, 1, 4):
4562 * case IP_VERSION(3, 1, 5):
4563 * case IP_VERSION(3, 1, 6):
4564 * case IP_VERSION(3, 2, 0):
4565 * case IP_VERSION(3, 2, 1):
4566 * case IP_VERSION(3, 5, 0):
4567 * case IP_VERSION(3, 5, 1):
4568 * replay_feature_enabled = true;
4572 replay_feature_enabled = amdgpu_dc_feature_mask & DC_REPLAY_MASK;
4577 /* loops over all connectors on the board */
4578 for (i = 0; i < link_cnt; i++) {
4579 struct dc_link *link = NULL;
4581 if (i > AMDGPU_DM_MAX_DISPLAY_INDEX) {
4583 "KMS: Cannot support more than %d display indexes\n",
4584 AMDGPU_DM_MAX_DISPLAY_INDEX);
4588 link = dc_get_link_at_index(dm->dc, i);
4590 if (link->connector_signal == SIGNAL_TYPE_VIRTUAL) {
4591 struct amdgpu_dm_wb_connector *wbcon = kzalloc(sizeof(*wbcon), GFP_KERNEL);
4594 DRM_ERROR("KMS: Failed to allocate writeback connector\n");
4598 if (amdgpu_dm_wb_connector_init(dm, wbcon, i)) {
4599 DRM_ERROR("KMS: Failed to initialize writeback connector\n");
4604 link->psr_settings.psr_feature_enabled = false;
4605 link->psr_settings.psr_version = DC_PSR_VERSION_UNSUPPORTED;
4610 aconnector = kzalloc(sizeof(*aconnector), GFP_KERNEL);
4614 aencoder = kzalloc(sizeof(*aencoder), GFP_KERNEL);
4618 if (amdgpu_dm_encoder_init(dm->ddev, aencoder, i)) {
4619 DRM_ERROR("KMS: Failed to initialize encoder\n");
4623 if (amdgpu_dm_connector_init(dm, aconnector, i, aencoder)) {
4624 DRM_ERROR("KMS: Failed to initialize connector\n");
4628 if (dm->hpd_rx_offload_wq)
4629 dm->hpd_rx_offload_wq[aconnector->base.index].aconnector =
4632 if (!dc_link_detect_connection_type(link, &new_connection_type))
4633 DRM_ERROR("KMS: Failed to detect connector\n");
4635 if (aconnector->base.force && new_connection_type == dc_connection_none) {
4636 emulated_link_detect(link);
4637 amdgpu_dm_update_connector_after_detect(aconnector);
4641 mutex_lock(&dm->dc_lock);
4642 ret = dc_link_detect(link, DETECT_REASON_BOOT);
4643 mutex_unlock(&dm->dc_lock);
4646 amdgpu_dm_update_connector_after_detect(aconnector);
4647 setup_backlight_device(dm, aconnector);
4649 /* Disable PSR if Replay can be enabled */
4650 if (replay_feature_enabled)
4651 if (amdgpu_dm_set_replay_caps(link, aconnector))
4652 psr_feature_enabled = false;
4654 if (psr_feature_enabled)
4655 amdgpu_dm_set_psr_caps(link);
4657 /* TODO: Fix vblank control helpers to delay PSR entry to allow this when
4658 * PSR is also supported.
4660 if (link->psr_settings.psr_feature_enabled)
4661 adev_to_drm(adev)->vblank_disable_immediate = false;
4664 amdgpu_set_panel_orientation(&aconnector->base);
4667 /* Software is initialized. Now we can register interrupt handlers. */
4668 switch (adev->asic_type) {
4669 #if defined(CONFIG_DRM_AMD_DC_SI)
4674 if (dce60_register_irq_handlers(dm->adev)) {
4675 DRM_ERROR("DM: Failed to initialize IRQ\n");
4689 case CHIP_POLARIS11:
4690 case CHIP_POLARIS10:
4691 case CHIP_POLARIS12:
4696 if (dce110_register_irq_handlers(dm->adev)) {
4697 DRM_ERROR("DM: Failed to initialize IRQ\n");
4702 switch (amdgpu_ip_version(adev, DCE_HWIP, 0)) {
4703 case IP_VERSION(1, 0, 0):
4704 case IP_VERSION(1, 0, 1):
4705 case IP_VERSION(2, 0, 2):
4706 case IP_VERSION(2, 0, 3):
4707 case IP_VERSION(2, 0, 0):
4708 case IP_VERSION(2, 1, 0):
4709 case IP_VERSION(3, 0, 0):
4710 case IP_VERSION(3, 0, 2):
4711 case IP_VERSION(3, 0, 3):
4712 case IP_VERSION(3, 0, 1):
4713 case IP_VERSION(3, 1, 2):
4714 case IP_VERSION(3, 1, 3):
4715 case IP_VERSION(3, 1, 4):
4716 case IP_VERSION(3, 1, 5):
4717 case IP_VERSION(3, 1, 6):
4718 case IP_VERSION(3, 2, 0):
4719 case IP_VERSION(3, 2, 1):
4720 case IP_VERSION(3, 5, 0):
4721 case IP_VERSION(3, 5, 1):
4722 if (dcn10_register_irq_handlers(dm->adev)) {
4723 DRM_ERROR("DM: Failed to initialize IRQ\n");
4728 DRM_ERROR("Unsupported DCE IP versions: 0x%X\n",
4729 amdgpu_ip_version(adev, DCE_HWIP, 0));
4743 static void amdgpu_dm_destroy_drm_device(struct amdgpu_display_manager *dm)
4745 drm_atomic_private_obj_fini(&dm->atomic_obj);
4748 /******************************************************************************
4749 * amdgpu_display_funcs functions
4750 *****************************************************************************/
4753 * dm_bandwidth_update - program display watermarks
4755 * @adev: amdgpu_device pointer
4757 * Calculate and program the display watermarks and line buffer allocation.
4759 static void dm_bandwidth_update(struct amdgpu_device *adev)
4761 /* TODO: implement later */
4764 static const struct amdgpu_display_funcs dm_display_funcs = {
4765 .bandwidth_update = dm_bandwidth_update, /* called unconditionally */
4766 .vblank_get_counter = dm_vblank_get_counter,/* called unconditionally */
4767 .backlight_set_level = NULL, /* never called for DC */
4768 .backlight_get_level = NULL, /* never called for DC */
4769 .hpd_sense = NULL,/* called unconditionally */
4770 .hpd_set_polarity = NULL, /* called unconditionally */
4771 .hpd_get_gpio_reg = NULL, /* VBIOS parsing. DAL does it. */
4772 .page_flip_get_scanoutpos =
4773 dm_crtc_get_scanoutpos,/* called unconditionally */
4774 .add_encoder = NULL, /* VBIOS parsing. DAL does it. */
4775 .add_connector = NULL, /* VBIOS parsing. DAL does it. */
4778 #if defined(CONFIG_DEBUG_KERNEL_DC)
4780 static ssize_t s3_debug_store(struct device *device,
4781 struct device_attribute *attr,
4787 struct drm_device *drm_dev = dev_get_drvdata(device);
4788 struct amdgpu_device *adev = drm_to_adev(drm_dev);
4790 ret = kstrtoint(buf, 0, &s3_state);
4795 drm_kms_helper_hotplug_event(adev_to_drm(adev));
4800 return ret == 0 ? count : 0;
4803 DEVICE_ATTR_WO(s3_debug);
4807 static int dm_init_microcode(struct amdgpu_device *adev)
4812 switch (amdgpu_ip_version(adev, DCE_HWIP, 0)) {
4813 case IP_VERSION(2, 1, 0):
4814 fw_name_dmub = FIRMWARE_RENOIR_DMUB;
4815 if (ASICREV_IS_GREEN_SARDINE(adev->external_rev_id))
4816 fw_name_dmub = FIRMWARE_GREEN_SARDINE_DMUB;
4818 case IP_VERSION(3, 0, 0):
4819 if (amdgpu_ip_version(adev, GC_HWIP, 0) == IP_VERSION(10, 3, 0))
4820 fw_name_dmub = FIRMWARE_SIENNA_CICHLID_DMUB;
4822 fw_name_dmub = FIRMWARE_NAVY_FLOUNDER_DMUB;
4824 case IP_VERSION(3, 0, 1):
4825 fw_name_dmub = FIRMWARE_VANGOGH_DMUB;
4827 case IP_VERSION(3, 0, 2):
4828 fw_name_dmub = FIRMWARE_DIMGREY_CAVEFISH_DMUB;
4830 case IP_VERSION(3, 0, 3):
4831 fw_name_dmub = FIRMWARE_BEIGE_GOBY_DMUB;
4833 case IP_VERSION(3, 1, 2):
4834 case IP_VERSION(3, 1, 3):
4835 fw_name_dmub = FIRMWARE_YELLOW_CARP_DMUB;
4837 case IP_VERSION(3, 1, 4):
4838 fw_name_dmub = FIRMWARE_DCN_314_DMUB;
4840 case IP_VERSION(3, 1, 5):
4841 fw_name_dmub = FIRMWARE_DCN_315_DMUB;
4843 case IP_VERSION(3, 1, 6):
4844 fw_name_dmub = FIRMWARE_DCN316_DMUB;
4846 case IP_VERSION(3, 2, 0):
4847 fw_name_dmub = FIRMWARE_DCN_V3_2_0_DMCUB;
4849 case IP_VERSION(3, 2, 1):
4850 fw_name_dmub = FIRMWARE_DCN_V3_2_1_DMCUB;
4852 case IP_VERSION(3, 5, 0):
4853 fw_name_dmub = FIRMWARE_DCN_35_DMUB;
4855 case IP_VERSION(3, 5, 1):
4856 fw_name_dmub = FIRMWARE_DCN_351_DMUB;
4859 /* ASIC doesn't support DMUB. */
4862 r = amdgpu_ucode_request(adev, &adev->dm.dmub_fw, fw_name_dmub);
4866 static int dm_early_init(void *handle)
4868 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
4869 struct amdgpu_mode_info *mode_info = &adev->mode_info;
4870 struct atom_context *ctx = mode_info->atom_context;
4871 int index = GetIndexIntoMasterTable(DATA, Object_Header);
4874 /* if there is no object header, skip DM */
4875 if (!amdgpu_atom_parse_data_header(ctx, index, NULL, NULL, NULL, &data_offset)) {
4876 adev->harvest_ip_mask |= AMD_HARVEST_IP_DMU_MASK;
4877 dev_info(adev->dev, "No object header, skipping DM\n");
4881 switch (adev->asic_type) {
4882 #if defined(CONFIG_DRM_AMD_DC_SI)
4886 adev->mode_info.num_crtc = 6;
4887 adev->mode_info.num_hpd = 6;
4888 adev->mode_info.num_dig = 6;
4891 adev->mode_info.num_crtc = 2;
4892 adev->mode_info.num_hpd = 2;
4893 adev->mode_info.num_dig = 2;
4898 adev->mode_info.num_crtc = 6;
4899 adev->mode_info.num_hpd = 6;
4900 adev->mode_info.num_dig = 6;
4903 adev->mode_info.num_crtc = 4;
4904 adev->mode_info.num_hpd = 6;
4905 adev->mode_info.num_dig = 7;
4909 adev->mode_info.num_crtc = 2;
4910 adev->mode_info.num_hpd = 6;
4911 adev->mode_info.num_dig = 6;
4915 adev->mode_info.num_crtc = 6;
4916 adev->mode_info.num_hpd = 6;
4917 adev->mode_info.num_dig = 7;
4920 adev->mode_info.num_crtc = 3;
4921 adev->mode_info.num_hpd = 6;
4922 adev->mode_info.num_dig = 9;
4925 adev->mode_info.num_crtc = 2;
4926 adev->mode_info.num_hpd = 6;
4927 adev->mode_info.num_dig = 9;
4929 case CHIP_POLARIS11:
4930 case CHIP_POLARIS12:
4931 adev->mode_info.num_crtc = 5;
4932 adev->mode_info.num_hpd = 5;
4933 adev->mode_info.num_dig = 5;
4935 case CHIP_POLARIS10:
4937 adev->mode_info.num_crtc = 6;
4938 adev->mode_info.num_hpd = 6;
4939 adev->mode_info.num_dig = 6;
4944 adev->mode_info.num_crtc = 6;
4945 adev->mode_info.num_hpd = 6;
4946 adev->mode_info.num_dig = 6;
4950 switch (amdgpu_ip_version(adev, DCE_HWIP, 0)) {
4951 case IP_VERSION(2, 0, 2):
4952 case IP_VERSION(3, 0, 0):
4953 adev->mode_info.num_crtc = 6;
4954 adev->mode_info.num_hpd = 6;
4955 adev->mode_info.num_dig = 6;
4957 case IP_VERSION(2, 0, 0):
4958 case IP_VERSION(3, 0, 2):
4959 adev->mode_info.num_crtc = 5;
4960 adev->mode_info.num_hpd = 5;
4961 adev->mode_info.num_dig = 5;
4963 case IP_VERSION(2, 0, 3):
4964 case IP_VERSION(3, 0, 3):
4965 adev->mode_info.num_crtc = 2;
4966 adev->mode_info.num_hpd = 2;
4967 adev->mode_info.num_dig = 2;
4969 case IP_VERSION(1, 0, 0):
4970 case IP_VERSION(1, 0, 1):
4971 case IP_VERSION(3, 0, 1):
4972 case IP_VERSION(2, 1, 0):
4973 case IP_VERSION(3, 1, 2):
4974 case IP_VERSION(3, 1, 3):
4975 case IP_VERSION(3, 1, 4):
4976 case IP_VERSION(3, 1, 5):
4977 case IP_VERSION(3, 1, 6):
4978 case IP_VERSION(3, 2, 0):
4979 case IP_VERSION(3, 2, 1):
4980 case IP_VERSION(3, 5, 0):
4981 case IP_VERSION(3, 5, 1):
4982 adev->mode_info.num_crtc = 4;
4983 adev->mode_info.num_hpd = 4;
4984 adev->mode_info.num_dig = 4;
4987 DRM_ERROR("Unsupported DCE IP versions: 0x%x\n",
4988 amdgpu_ip_version(adev, DCE_HWIP, 0));
4994 if (adev->mode_info.funcs == NULL)
4995 adev->mode_info.funcs = &dm_display_funcs;
4998 * Note: Do NOT change adev->audio_endpt_rreg and
4999 * adev->audio_endpt_wreg because they are initialised in
5000 * amdgpu_device_init()
5002 #if defined(CONFIG_DEBUG_KERNEL_DC)
5004 adev_to_drm(adev)->dev,
5005 &dev_attr_s3_debug);
5007 adev->dc_enabled = true;
5009 return dm_init_microcode(adev);
5012 static bool modereset_required(struct drm_crtc_state *crtc_state)
5014 return !crtc_state->active && drm_atomic_crtc_needs_modeset(crtc_state);
5017 static void amdgpu_dm_encoder_destroy(struct drm_encoder *encoder)
5019 drm_encoder_cleanup(encoder);
5023 static const struct drm_encoder_funcs amdgpu_dm_encoder_funcs = {
5024 .destroy = amdgpu_dm_encoder_destroy,
5028 fill_plane_color_attributes(const struct drm_plane_state *plane_state,
5029 const enum surface_pixel_format format,
5030 enum dc_color_space *color_space)
5034 *color_space = COLOR_SPACE_SRGB;
5036 /* DRM color properties only affect non-RGB formats. */
5037 if (format < SURFACE_PIXEL_FORMAT_VIDEO_BEGIN)
5040 full_range = (plane_state->color_range == DRM_COLOR_YCBCR_FULL_RANGE);
5042 switch (plane_state->color_encoding) {
5043 case DRM_COLOR_YCBCR_BT601:
5045 *color_space = COLOR_SPACE_YCBCR601;
5047 *color_space = COLOR_SPACE_YCBCR601_LIMITED;
5050 case DRM_COLOR_YCBCR_BT709:
5052 *color_space = COLOR_SPACE_YCBCR709;
5054 *color_space = COLOR_SPACE_YCBCR709_LIMITED;
5057 case DRM_COLOR_YCBCR_BT2020:
5059 *color_space = COLOR_SPACE_2020_YCBCR;
5072 fill_dc_plane_info_and_addr(struct amdgpu_device *adev,
5073 const struct drm_plane_state *plane_state,
5074 const u64 tiling_flags,
5075 struct dc_plane_info *plane_info,
5076 struct dc_plane_address *address,
5078 bool force_disable_dcc)
5080 const struct drm_framebuffer *fb = plane_state->fb;
5081 const struct amdgpu_framebuffer *afb =
5082 to_amdgpu_framebuffer(plane_state->fb);
5085 memset(plane_info, 0, sizeof(*plane_info));
5087 switch (fb->format->format) {
5089 plane_info->format =
5090 SURFACE_PIXEL_FORMAT_GRPH_PALETA_256_COLORS;
5092 case DRM_FORMAT_RGB565:
5093 plane_info->format = SURFACE_PIXEL_FORMAT_GRPH_RGB565;
5095 case DRM_FORMAT_XRGB8888:
5096 case DRM_FORMAT_ARGB8888:
5097 plane_info->format = SURFACE_PIXEL_FORMAT_GRPH_ARGB8888;
5099 case DRM_FORMAT_XRGB2101010:
5100 case DRM_FORMAT_ARGB2101010:
5101 plane_info->format = SURFACE_PIXEL_FORMAT_GRPH_ARGB2101010;
5103 case DRM_FORMAT_XBGR2101010:
5104 case DRM_FORMAT_ABGR2101010:
5105 plane_info->format = SURFACE_PIXEL_FORMAT_GRPH_ABGR2101010;
5107 case DRM_FORMAT_XBGR8888:
5108 case DRM_FORMAT_ABGR8888:
5109 plane_info->format = SURFACE_PIXEL_FORMAT_GRPH_ABGR8888;
5111 case DRM_FORMAT_NV21:
5112 plane_info->format = SURFACE_PIXEL_FORMAT_VIDEO_420_YCbCr;
5114 case DRM_FORMAT_NV12:
5115 plane_info->format = SURFACE_PIXEL_FORMAT_VIDEO_420_YCrCb;
5117 case DRM_FORMAT_P010:
5118 plane_info->format = SURFACE_PIXEL_FORMAT_VIDEO_420_10bpc_YCrCb;
5120 case DRM_FORMAT_XRGB16161616F:
5121 case DRM_FORMAT_ARGB16161616F:
5122 plane_info->format = SURFACE_PIXEL_FORMAT_GRPH_ARGB16161616F;
5124 case DRM_FORMAT_XBGR16161616F:
5125 case DRM_FORMAT_ABGR16161616F:
5126 plane_info->format = SURFACE_PIXEL_FORMAT_GRPH_ABGR16161616F;
5128 case DRM_FORMAT_XRGB16161616:
5129 case DRM_FORMAT_ARGB16161616:
5130 plane_info->format = SURFACE_PIXEL_FORMAT_GRPH_ARGB16161616;
5132 case DRM_FORMAT_XBGR16161616:
5133 case DRM_FORMAT_ABGR16161616:
5134 plane_info->format = SURFACE_PIXEL_FORMAT_GRPH_ABGR16161616;
5138 "Unsupported screen format %p4cc\n",
5139 &fb->format->format);
5143 switch (plane_state->rotation & DRM_MODE_ROTATE_MASK) {
5144 case DRM_MODE_ROTATE_0:
5145 plane_info->rotation = ROTATION_ANGLE_0;
5147 case DRM_MODE_ROTATE_90:
5148 plane_info->rotation = ROTATION_ANGLE_90;
5150 case DRM_MODE_ROTATE_180:
5151 plane_info->rotation = ROTATION_ANGLE_180;
5153 case DRM_MODE_ROTATE_270:
5154 plane_info->rotation = ROTATION_ANGLE_270;
5157 plane_info->rotation = ROTATION_ANGLE_0;
5162 plane_info->visible = true;
5163 plane_info->stereo_format = PLANE_STEREO_FORMAT_NONE;
5165 plane_info->layer_index = plane_state->normalized_zpos;
5167 ret = fill_plane_color_attributes(plane_state, plane_info->format,
5168 &plane_info->color_space);
5172 ret = amdgpu_dm_plane_fill_plane_buffer_attributes(adev, afb, plane_info->format,
5173 plane_info->rotation, tiling_flags,
5174 &plane_info->tiling_info,
5175 &plane_info->plane_size,
5176 &plane_info->dcc, address,
5177 tmz_surface, force_disable_dcc);
5181 amdgpu_dm_plane_fill_blending_from_plane_state(
5182 plane_state, &plane_info->per_pixel_alpha, &plane_info->pre_multiplied_alpha,
5183 &plane_info->global_alpha, &plane_info->global_alpha_value);
5188 static int fill_dc_plane_attributes(struct amdgpu_device *adev,
5189 struct dc_plane_state *dc_plane_state,
5190 struct drm_plane_state *plane_state,
5191 struct drm_crtc_state *crtc_state)
5193 struct dm_crtc_state *dm_crtc_state = to_dm_crtc_state(crtc_state);
5194 struct amdgpu_framebuffer *afb = (struct amdgpu_framebuffer *)plane_state->fb;
5195 struct dc_scaling_info scaling_info;
5196 struct dc_plane_info plane_info;
5198 bool force_disable_dcc = false;
5200 ret = amdgpu_dm_plane_fill_dc_scaling_info(adev, plane_state, &scaling_info);
5204 dc_plane_state->src_rect = scaling_info.src_rect;
5205 dc_plane_state->dst_rect = scaling_info.dst_rect;
5206 dc_plane_state->clip_rect = scaling_info.clip_rect;
5207 dc_plane_state->scaling_quality = scaling_info.scaling_quality;
5209 force_disable_dcc = adev->asic_type == CHIP_RAVEN && adev->in_suspend;
5210 ret = fill_dc_plane_info_and_addr(adev, plane_state,
5213 &dc_plane_state->address,
5219 dc_plane_state->format = plane_info.format;
5220 dc_plane_state->color_space = plane_info.color_space;
5221 dc_plane_state->format = plane_info.format;
5222 dc_plane_state->plane_size = plane_info.plane_size;
5223 dc_plane_state->rotation = plane_info.rotation;
5224 dc_plane_state->horizontal_mirror = plane_info.horizontal_mirror;
5225 dc_plane_state->stereo_format = plane_info.stereo_format;
5226 dc_plane_state->tiling_info = plane_info.tiling_info;
5227 dc_plane_state->visible = plane_info.visible;
5228 dc_plane_state->per_pixel_alpha = plane_info.per_pixel_alpha;
5229 dc_plane_state->pre_multiplied_alpha = plane_info.pre_multiplied_alpha;
5230 dc_plane_state->global_alpha = plane_info.global_alpha;
5231 dc_plane_state->global_alpha_value = plane_info.global_alpha_value;
5232 dc_plane_state->dcc = plane_info.dcc;
5233 dc_plane_state->layer_index = plane_info.layer_index;
5234 dc_plane_state->flip_int_enabled = true;
5237 * Always set input transfer function, since plane state is refreshed
5240 ret = amdgpu_dm_update_plane_color_mgmt(dm_crtc_state,
5249 static inline void fill_dc_dirty_rect(struct drm_plane *plane,
5250 struct rect *dirty_rect, int32_t x,
5251 s32 y, s32 width, s32 height,
5254 WARN_ON(*i >= DC_MAX_DIRTY_RECTS);
5258 dirty_rect->width = width;
5259 dirty_rect->height = height;
5263 "[PLANE:%d] PSR FFU dirty rect size (%d, %d)\n",
5264 plane->base.id, width, height);
5267 "[PLANE:%d] PSR SU dirty rect at (%d, %d) size (%d, %d)",
5268 plane->base.id, x, y, width, height);
5274 * fill_dc_dirty_rects() - Fill DC dirty regions for PSR selective updates
5276 * @plane: DRM plane containing dirty regions that need to be flushed to the eDP
5278 * @old_plane_state: Old state of @plane
5279 * @new_plane_state: New state of @plane
5280 * @crtc_state: New state of CRTC connected to the @plane
5281 * @flip_addrs: DC flip tracking struct, which also tracts dirty rects
5282 * @is_psr_su: Flag indicating whether Panel Self Refresh Selective Update (PSR SU) is enabled.
5283 * If PSR SU is enabled and damage clips are available, only the regions of the screen
5284 * that have changed will be updated. If PSR SU is not enabled,
5285 * or if damage clips are not available, the entire screen will be updated.
5286 * @dirty_regions_changed: dirty regions changed
5288 * For PSR SU, DC informs the DMUB uController of dirty rectangle regions
5289 * (referred to as "damage clips" in DRM nomenclature) that require updating on
5290 * the eDP remote buffer. The responsibility of specifying the dirty regions is
5293 * A damage-aware DRM client should fill the FB_DAMAGE_CLIPS property on the
5294 * plane with regions that require flushing to the eDP remote buffer. In
5295 * addition, certain use cases - such as cursor and multi-plane overlay (MPO) -
5296 * implicitly provide damage clips without any client support via the plane
5299 static void fill_dc_dirty_rects(struct drm_plane *plane,
5300 struct drm_plane_state *old_plane_state,
5301 struct drm_plane_state *new_plane_state,
5302 struct drm_crtc_state *crtc_state,
5303 struct dc_flip_addrs *flip_addrs,
5305 bool *dirty_regions_changed)
5307 struct dm_crtc_state *dm_crtc_state = to_dm_crtc_state(crtc_state);
5308 struct rect *dirty_rects = flip_addrs->dirty_rects;
5310 struct drm_mode_rect *clips;
5314 *dirty_regions_changed = false;
5317 * Cursor plane has it's own dirty rect update interface. See
5318 * dcn10_dmub_update_cursor_data and dmub_cmd_update_cursor_info_data
5320 if (plane->type == DRM_PLANE_TYPE_CURSOR)
5323 if (new_plane_state->rotation != DRM_MODE_ROTATE_0)
5326 num_clips = drm_plane_get_damage_clips_count(new_plane_state);
5327 clips = drm_plane_get_damage_clips(new_plane_state);
5329 if (num_clips && (!amdgpu_damage_clips || (amdgpu_damage_clips < 0 &&
5333 if (!dm_crtc_state->mpo_requested) {
5334 if (!num_clips || num_clips > DC_MAX_DIRTY_RECTS)
5337 for (; flip_addrs->dirty_rect_count < num_clips; clips++)
5338 fill_dc_dirty_rect(new_plane_state->plane,
5339 &dirty_rects[flip_addrs->dirty_rect_count],
5340 clips->x1, clips->y1,
5341 clips->x2 - clips->x1, clips->y2 - clips->y1,
5342 &flip_addrs->dirty_rect_count,
5348 * MPO is requested. Add entire plane bounding box to dirty rects if
5349 * flipped to or damaged.
5351 * If plane is moved or resized, also add old bounding box to dirty
5354 fb_changed = old_plane_state->fb->base.id !=
5355 new_plane_state->fb->base.id;
5356 bb_changed = (old_plane_state->crtc_x != new_plane_state->crtc_x ||
5357 old_plane_state->crtc_y != new_plane_state->crtc_y ||
5358 old_plane_state->crtc_w != new_plane_state->crtc_w ||
5359 old_plane_state->crtc_h != new_plane_state->crtc_h);
5362 "[PLANE:%d] PSR bb_changed:%d fb_changed:%d num_clips:%d\n",
5363 new_plane_state->plane->base.id,
5364 bb_changed, fb_changed, num_clips);
5366 *dirty_regions_changed = bb_changed;
5368 if ((num_clips + (bb_changed ? 2 : 0)) > DC_MAX_DIRTY_RECTS)
5372 fill_dc_dirty_rect(new_plane_state->plane, &dirty_rects[i],
5373 new_plane_state->crtc_x,
5374 new_plane_state->crtc_y,
5375 new_plane_state->crtc_w,
5376 new_plane_state->crtc_h, &i, false);
5378 /* Add old plane bounding-box if plane is moved or resized */
5379 fill_dc_dirty_rect(new_plane_state->plane, &dirty_rects[i],
5380 old_plane_state->crtc_x,
5381 old_plane_state->crtc_y,
5382 old_plane_state->crtc_w,
5383 old_plane_state->crtc_h, &i, false);
5387 for (; i < num_clips; clips++)
5388 fill_dc_dirty_rect(new_plane_state->plane,
5389 &dirty_rects[i], clips->x1,
5390 clips->y1, clips->x2 - clips->x1,
5391 clips->y2 - clips->y1, &i, false);
5392 } else if (fb_changed && !bb_changed) {
5393 fill_dc_dirty_rect(new_plane_state->plane, &dirty_rects[i],
5394 new_plane_state->crtc_x,
5395 new_plane_state->crtc_y,
5396 new_plane_state->crtc_w,
5397 new_plane_state->crtc_h, &i, false);
5400 flip_addrs->dirty_rect_count = i;
5404 fill_dc_dirty_rect(new_plane_state->plane, &dirty_rects[0], 0, 0,
5405 dm_crtc_state->base.mode.crtc_hdisplay,
5406 dm_crtc_state->base.mode.crtc_vdisplay,
5407 &flip_addrs->dirty_rect_count, true);
5410 static void update_stream_scaling_settings(const struct drm_display_mode *mode,
5411 const struct dm_connector_state *dm_state,
5412 struct dc_stream_state *stream)
5414 enum amdgpu_rmx_type rmx_type;
5416 struct rect src = { 0 }; /* viewport in composition space*/
5417 struct rect dst = { 0 }; /* stream addressable area */
5419 /* no mode. nothing to be done */
5423 /* Full screen scaling by default */
5424 src.width = mode->hdisplay;
5425 src.height = mode->vdisplay;
5426 dst.width = stream->timing.h_addressable;
5427 dst.height = stream->timing.v_addressable;
5430 rmx_type = dm_state->scaling;
5431 if (rmx_type == RMX_ASPECT || rmx_type == RMX_OFF) {
5432 if (src.width * dst.height <
5433 src.height * dst.width) {
5434 /* height needs less upscaling/more downscaling */
5435 dst.width = src.width *
5436 dst.height / src.height;
5438 /* width needs less upscaling/more downscaling */
5439 dst.height = src.height *
5440 dst.width / src.width;
5442 } else if (rmx_type == RMX_CENTER) {
5446 dst.x = (stream->timing.h_addressable - dst.width) / 2;
5447 dst.y = (stream->timing.v_addressable - dst.height) / 2;
5449 if (dm_state->underscan_enable) {
5450 dst.x += dm_state->underscan_hborder / 2;
5451 dst.y += dm_state->underscan_vborder / 2;
5452 dst.width -= dm_state->underscan_hborder;
5453 dst.height -= dm_state->underscan_vborder;
5460 DRM_DEBUG_KMS("Destination Rectangle x:%d y:%d width:%d height:%d\n",
5461 dst.x, dst.y, dst.width, dst.height);
5465 static enum dc_color_depth
5466 convert_color_depth_from_display_info(const struct drm_connector *connector,
5467 bool is_y420, int requested_bpc)
5474 /* Cap display bpc based on HDMI 2.0 HF-VSDB */
5475 if (connector->display_info.hdmi.y420_dc_modes & DRM_EDID_YCBCR420_DC_48)
5477 else if (connector->display_info.hdmi.y420_dc_modes & DRM_EDID_YCBCR420_DC_36)
5479 else if (connector->display_info.hdmi.y420_dc_modes & DRM_EDID_YCBCR420_DC_30)
5482 bpc = (uint8_t)connector->display_info.bpc;
5483 /* Assume 8 bpc by default if no bpc is specified. */
5484 bpc = bpc ? bpc : 8;
5487 if (requested_bpc > 0) {
5489 * Cap display bpc based on the user requested value.
5491 * The value for state->max_bpc may not correctly updated
5492 * depending on when the connector gets added to the state
5493 * or if this was called outside of atomic check, so it
5494 * can't be used directly.
5496 bpc = min_t(u8, bpc, requested_bpc);
5498 /* Round down to the nearest even number. */
5499 bpc = bpc - (bpc & 1);
5505 * Temporary Work around, DRM doesn't parse color depth for
5506 * EDID revision before 1.4
5507 * TODO: Fix edid parsing
5509 return COLOR_DEPTH_888;
5511 return COLOR_DEPTH_666;
5513 return COLOR_DEPTH_888;
5515 return COLOR_DEPTH_101010;
5517 return COLOR_DEPTH_121212;
5519 return COLOR_DEPTH_141414;
5521 return COLOR_DEPTH_161616;
5523 return COLOR_DEPTH_UNDEFINED;
5527 static enum dc_aspect_ratio
5528 get_aspect_ratio(const struct drm_display_mode *mode_in)
5530 /* 1-1 mapping, since both enums follow the HDMI spec. */
5531 return (enum dc_aspect_ratio) mode_in->picture_aspect_ratio;
5534 static enum dc_color_space
5535 get_output_color_space(const struct dc_crtc_timing *dc_crtc_timing,
5536 const struct drm_connector_state *connector_state)
5538 enum dc_color_space color_space = COLOR_SPACE_SRGB;
5540 switch (connector_state->colorspace) {
5541 case DRM_MODE_COLORIMETRY_BT601_YCC:
5542 if (dc_crtc_timing->flags.Y_ONLY)
5543 color_space = COLOR_SPACE_YCBCR601_LIMITED;
5545 color_space = COLOR_SPACE_YCBCR601;
5547 case DRM_MODE_COLORIMETRY_BT709_YCC:
5548 if (dc_crtc_timing->flags.Y_ONLY)
5549 color_space = COLOR_SPACE_YCBCR709_LIMITED;
5551 color_space = COLOR_SPACE_YCBCR709;
5553 case DRM_MODE_COLORIMETRY_OPRGB:
5554 color_space = COLOR_SPACE_ADOBERGB;
5556 case DRM_MODE_COLORIMETRY_BT2020_RGB:
5557 case DRM_MODE_COLORIMETRY_BT2020_YCC:
5558 if (dc_crtc_timing->pixel_encoding == PIXEL_ENCODING_RGB)
5559 color_space = COLOR_SPACE_2020_RGB_FULLRANGE;
5561 color_space = COLOR_SPACE_2020_YCBCR;
5563 case DRM_MODE_COLORIMETRY_DEFAULT: // ITU601
5565 if (dc_crtc_timing->pixel_encoding == PIXEL_ENCODING_RGB) {
5566 color_space = COLOR_SPACE_SRGB;
5568 * 27030khz is the separation point between HDTV and SDTV
5569 * according to HDMI spec, we use YCbCr709 and YCbCr601
5572 } else if (dc_crtc_timing->pix_clk_100hz > 270300) {
5573 if (dc_crtc_timing->flags.Y_ONLY)
5575 COLOR_SPACE_YCBCR709_LIMITED;
5577 color_space = COLOR_SPACE_YCBCR709;
5579 if (dc_crtc_timing->flags.Y_ONLY)
5581 COLOR_SPACE_YCBCR601_LIMITED;
5583 color_space = COLOR_SPACE_YCBCR601;
5591 static enum display_content_type
5592 get_output_content_type(const struct drm_connector_state *connector_state)
5594 switch (connector_state->content_type) {
5596 case DRM_MODE_CONTENT_TYPE_NO_DATA:
5597 return DISPLAY_CONTENT_TYPE_NO_DATA;
5598 case DRM_MODE_CONTENT_TYPE_GRAPHICS:
5599 return DISPLAY_CONTENT_TYPE_GRAPHICS;
5600 case DRM_MODE_CONTENT_TYPE_PHOTO:
5601 return DISPLAY_CONTENT_TYPE_PHOTO;
5602 case DRM_MODE_CONTENT_TYPE_CINEMA:
5603 return DISPLAY_CONTENT_TYPE_CINEMA;
5604 case DRM_MODE_CONTENT_TYPE_GAME:
5605 return DISPLAY_CONTENT_TYPE_GAME;
5609 static bool adjust_colour_depth_from_display_info(
5610 struct dc_crtc_timing *timing_out,
5611 const struct drm_display_info *info)
5613 enum dc_color_depth depth = timing_out->display_color_depth;
5617 normalized_clk = timing_out->pix_clk_100hz / 10;
5618 /* YCbCr 4:2:0 requires additional adjustment of 1/2 */
5619 if (timing_out->pixel_encoding == PIXEL_ENCODING_YCBCR420)
5620 normalized_clk /= 2;
5621 /* Adjusting pix clock following on HDMI spec based on colour depth */
5623 case COLOR_DEPTH_888:
5625 case COLOR_DEPTH_101010:
5626 normalized_clk = (normalized_clk * 30) / 24;
5628 case COLOR_DEPTH_121212:
5629 normalized_clk = (normalized_clk * 36) / 24;
5631 case COLOR_DEPTH_161616:
5632 normalized_clk = (normalized_clk * 48) / 24;
5635 /* The above depths are the only ones valid for HDMI. */
5638 if (normalized_clk <= info->max_tmds_clock) {
5639 timing_out->display_color_depth = depth;
5642 } while (--depth > COLOR_DEPTH_666);
5646 static void fill_stream_properties_from_drm_display_mode(
5647 struct dc_stream_state *stream,
5648 const struct drm_display_mode *mode_in,
5649 const struct drm_connector *connector,
5650 const struct drm_connector_state *connector_state,
5651 const struct dc_stream_state *old_stream,
5654 struct dc_crtc_timing *timing_out = &stream->timing;
5655 const struct drm_display_info *info = &connector->display_info;
5656 struct amdgpu_dm_connector *aconnector = NULL;
5657 struct hdmi_vendor_infoframe hv_frame;
5658 struct hdmi_avi_infoframe avi_frame;
5660 if (connector->connector_type != DRM_MODE_CONNECTOR_WRITEBACK)
5661 aconnector = to_amdgpu_dm_connector(connector);
5663 memset(&hv_frame, 0, sizeof(hv_frame));
5664 memset(&avi_frame, 0, sizeof(avi_frame));
5666 timing_out->h_border_left = 0;
5667 timing_out->h_border_right = 0;
5668 timing_out->v_border_top = 0;
5669 timing_out->v_border_bottom = 0;
5670 /* TODO: un-hardcode */
5671 if (drm_mode_is_420_only(info, mode_in)
5672 && stream->signal == SIGNAL_TYPE_HDMI_TYPE_A)
5673 timing_out->pixel_encoding = PIXEL_ENCODING_YCBCR420;
5674 else if (drm_mode_is_420_also(info, mode_in)
5676 && aconnector->force_yuv420_output)
5677 timing_out->pixel_encoding = PIXEL_ENCODING_YCBCR420;
5678 else if ((connector->display_info.color_formats & DRM_COLOR_FORMAT_YCBCR444)
5679 && stream->signal == SIGNAL_TYPE_HDMI_TYPE_A)
5680 timing_out->pixel_encoding = PIXEL_ENCODING_YCBCR444;
5682 timing_out->pixel_encoding = PIXEL_ENCODING_RGB;
5684 timing_out->timing_3d_format = TIMING_3D_FORMAT_NONE;
5685 timing_out->display_color_depth = convert_color_depth_from_display_info(
5687 (timing_out->pixel_encoding == PIXEL_ENCODING_YCBCR420),
5689 timing_out->scan_type = SCANNING_TYPE_NODATA;
5690 timing_out->hdmi_vic = 0;
5693 timing_out->vic = old_stream->timing.vic;
5694 timing_out->flags.HSYNC_POSITIVE_POLARITY = old_stream->timing.flags.HSYNC_POSITIVE_POLARITY;
5695 timing_out->flags.VSYNC_POSITIVE_POLARITY = old_stream->timing.flags.VSYNC_POSITIVE_POLARITY;
5697 timing_out->vic = drm_match_cea_mode(mode_in);
5698 if (mode_in->flags & DRM_MODE_FLAG_PHSYNC)
5699 timing_out->flags.HSYNC_POSITIVE_POLARITY = 1;
5700 if (mode_in->flags & DRM_MODE_FLAG_PVSYNC)
5701 timing_out->flags.VSYNC_POSITIVE_POLARITY = 1;
5704 if (stream->signal == SIGNAL_TYPE_HDMI_TYPE_A) {
5705 drm_hdmi_avi_infoframe_from_display_mode(&avi_frame, (struct drm_connector *)connector, mode_in);
5706 timing_out->vic = avi_frame.video_code;
5707 drm_hdmi_vendor_infoframe_from_display_mode(&hv_frame, (struct drm_connector *)connector, mode_in);
5708 timing_out->hdmi_vic = hv_frame.vic;
5711 if (aconnector && is_freesync_video_mode(mode_in, aconnector)) {
5712 timing_out->h_addressable = mode_in->hdisplay;
5713 timing_out->h_total = mode_in->htotal;
5714 timing_out->h_sync_width = mode_in->hsync_end - mode_in->hsync_start;
5715 timing_out->h_front_porch = mode_in->hsync_start - mode_in->hdisplay;
5716 timing_out->v_total = mode_in->vtotal;
5717 timing_out->v_addressable = mode_in->vdisplay;
5718 timing_out->v_front_porch = mode_in->vsync_start - mode_in->vdisplay;
5719 timing_out->v_sync_width = mode_in->vsync_end - mode_in->vsync_start;
5720 timing_out->pix_clk_100hz = mode_in->clock * 10;
5722 timing_out->h_addressable = mode_in->crtc_hdisplay;
5723 timing_out->h_total = mode_in->crtc_htotal;
5724 timing_out->h_sync_width = mode_in->crtc_hsync_end - mode_in->crtc_hsync_start;
5725 timing_out->h_front_porch = mode_in->crtc_hsync_start - mode_in->crtc_hdisplay;
5726 timing_out->v_total = mode_in->crtc_vtotal;
5727 timing_out->v_addressable = mode_in->crtc_vdisplay;
5728 timing_out->v_front_porch = mode_in->crtc_vsync_start - mode_in->crtc_vdisplay;
5729 timing_out->v_sync_width = mode_in->crtc_vsync_end - mode_in->crtc_vsync_start;
5730 timing_out->pix_clk_100hz = mode_in->crtc_clock * 10;
5733 timing_out->aspect_ratio = get_aspect_ratio(mode_in);
5735 stream->out_transfer_func.type = TF_TYPE_PREDEFINED;
5736 stream->out_transfer_func.tf = TRANSFER_FUNCTION_SRGB;
5737 if (stream->signal == SIGNAL_TYPE_HDMI_TYPE_A) {
5738 if (!adjust_colour_depth_from_display_info(timing_out, info) &&
5739 drm_mode_is_420_also(info, mode_in) &&
5740 timing_out->pixel_encoding != PIXEL_ENCODING_YCBCR420) {
5741 timing_out->pixel_encoding = PIXEL_ENCODING_YCBCR420;
5742 adjust_colour_depth_from_display_info(timing_out, info);
5746 stream->output_color_space = get_output_color_space(timing_out, connector_state);
5747 stream->content_type = get_output_content_type(connector_state);
5750 static void fill_audio_info(struct audio_info *audio_info,
5751 const struct drm_connector *drm_connector,
5752 const struct dc_sink *dc_sink)
5755 int cea_revision = 0;
5756 const struct dc_edid_caps *edid_caps = &dc_sink->edid_caps;
5758 audio_info->manufacture_id = edid_caps->manufacturer_id;
5759 audio_info->product_id = edid_caps->product_id;
5761 cea_revision = drm_connector->display_info.cea_rev;
5763 strscpy(audio_info->display_name,
5764 edid_caps->display_name,
5765 AUDIO_INFO_DISPLAY_NAME_SIZE_IN_CHARS);
5767 if (cea_revision >= 3) {
5768 audio_info->mode_count = edid_caps->audio_mode_count;
5770 for (i = 0; i < audio_info->mode_count; ++i) {
5771 audio_info->modes[i].format_code =
5772 (enum audio_format_code)
5773 (edid_caps->audio_modes[i].format_code);
5774 audio_info->modes[i].channel_count =
5775 edid_caps->audio_modes[i].channel_count;
5776 audio_info->modes[i].sample_rates.all =
5777 edid_caps->audio_modes[i].sample_rate;
5778 audio_info->modes[i].sample_size =
5779 edid_caps->audio_modes[i].sample_size;
5783 audio_info->flags.all = edid_caps->speaker_flags;
5785 /* TODO: We only check for the progressive mode, check for interlace mode too */
5786 if (drm_connector->latency_present[0]) {
5787 audio_info->video_latency = drm_connector->video_latency[0];
5788 audio_info->audio_latency = drm_connector->audio_latency[0];
5791 /* TODO: For DP, video and audio latency should be calculated from DPCD caps */
5796 copy_crtc_timing_for_drm_display_mode(const struct drm_display_mode *src_mode,
5797 struct drm_display_mode *dst_mode)
5799 dst_mode->crtc_hdisplay = src_mode->crtc_hdisplay;
5800 dst_mode->crtc_vdisplay = src_mode->crtc_vdisplay;
5801 dst_mode->crtc_clock = src_mode->crtc_clock;
5802 dst_mode->crtc_hblank_start = src_mode->crtc_hblank_start;
5803 dst_mode->crtc_hblank_end = src_mode->crtc_hblank_end;
5804 dst_mode->crtc_hsync_start = src_mode->crtc_hsync_start;
5805 dst_mode->crtc_hsync_end = src_mode->crtc_hsync_end;
5806 dst_mode->crtc_htotal = src_mode->crtc_htotal;
5807 dst_mode->crtc_hskew = src_mode->crtc_hskew;
5808 dst_mode->crtc_vblank_start = src_mode->crtc_vblank_start;
5809 dst_mode->crtc_vblank_end = src_mode->crtc_vblank_end;
5810 dst_mode->crtc_vsync_start = src_mode->crtc_vsync_start;
5811 dst_mode->crtc_vsync_end = src_mode->crtc_vsync_end;
5812 dst_mode->crtc_vtotal = src_mode->crtc_vtotal;
5816 decide_crtc_timing_for_drm_display_mode(struct drm_display_mode *drm_mode,
5817 const struct drm_display_mode *native_mode,
5820 if (scale_enabled) {
5821 copy_crtc_timing_for_drm_display_mode(native_mode, drm_mode);
5822 } else if (native_mode->clock == drm_mode->clock &&
5823 native_mode->htotal == drm_mode->htotal &&
5824 native_mode->vtotal == drm_mode->vtotal) {
5825 copy_crtc_timing_for_drm_display_mode(native_mode, drm_mode);
5827 /* no scaling nor amdgpu inserted, no need to patch */
5831 static struct dc_sink *
5832 create_fake_sink(struct dc_link *link)
5834 struct dc_sink_init_data sink_init_data = { 0 };
5835 struct dc_sink *sink = NULL;
5837 sink_init_data.link = link;
5838 sink_init_data.sink_signal = link->connector_signal;
5840 sink = dc_sink_create(&sink_init_data);
5842 DRM_ERROR("Failed to create sink!\n");
5845 sink->sink_signal = SIGNAL_TYPE_VIRTUAL;
5850 static void set_multisync_trigger_params(
5851 struct dc_stream_state *stream)
5853 struct dc_stream_state *master = NULL;
5855 if (stream->triggered_crtc_reset.enabled) {
5856 master = stream->triggered_crtc_reset.event_source;
5857 stream->triggered_crtc_reset.event =
5858 master->timing.flags.VSYNC_POSITIVE_POLARITY ?
5859 CRTC_EVENT_VSYNC_RISING : CRTC_EVENT_VSYNC_FALLING;
5860 stream->triggered_crtc_reset.delay = TRIGGER_DELAY_NEXT_PIXEL;
5864 static void set_master_stream(struct dc_stream_state *stream_set[],
5867 int j, highest_rfr = 0, master_stream = 0;
5869 for (j = 0; j < stream_count; j++) {
5870 if (stream_set[j] && stream_set[j]->triggered_crtc_reset.enabled) {
5871 int refresh_rate = 0;
5873 refresh_rate = (stream_set[j]->timing.pix_clk_100hz*100)/
5874 (stream_set[j]->timing.h_total*stream_set[j]->timing.v_total);
5875 if (refresh_rate > highest_rfr) {
5876 highest_rfr = refresh_rate;
5881 for (j = 0; j < stream_count; j++) {
5883 stream_set[j]->triggered_crtc_reset.event_source = stream_set[master_stream];
5887 static void dm_enable_per_frame_crtc_master_sync(struct dc_state *context)
5890 struct dc_stream_state *stream;
5892 if (context->stream_count < 2)
5894 for (i = 0; i < context->stream_count ; i++) {
5895 if (!context->streams[i])
5898 * TODO: add a function to read AMD VSDB bits and set
5899 * crtc_sync_master.multi_sync_enabled flag
5900 * For now it's set to false
5904 set_master_stream(context->streams, context->stream_count);
5906 for (i = 0; i < context->stream_count ; i++) {
5907 stream = context->streams[i];
5912 set_multisync_trigger_params(stream);
5917 * DOC: FreeSync Video
5919 * When a userspace application wants to play a video, the content follows a
5920 * standard format definition that usually specifies the FPS for that format.
5921 * The below list illustrates some video format and the expected FPS,
5924 * - TV/NTSC (23.976 FPS)
5927 * - TV/NTSC (29.97 FPS)
5928 * - TV/NTSC (30 FPS)
5929 * - Cinema HFR (48 FPS)
5931 * - Commonly used (60 FPS)
5932 * - Multiples of 24 (48,72,96 FPS)
5934 * The list of standards video format is not huge and can be added to the
5935 * connector modeset list beforehand. With that, userspace can leverage
5936 * FreeSync to extends the front porch in order to attain the target refresh
5937 * rate. Such a switch will happen seamlessly, without screen blanking or
5938 * reprogramming of the output in any other way. If the userspace requests a
5939 * modesetting change compatible with FreeSync modes that only differ in the
5940 * refresh rate, DC will skip the full update and avoid blink during the
5941 * transition. For example, the video player can change the modesetting from
5942 * 60Hz to 30Hz for playing TV/NTSC content when it goes full screen without
5943 * causing any display blink. This same concept can be applied to a mode
5946 static struct drm_display_mode *
5947 get_highest_refresh_rate_mode(struct amdgpu_dm_connector *aconnector,
5948 bool use_probed_modes)
5950 struct drm_display_mode *m, *m_pref = NULL;
5951 u16 current_refresh, highest_refresh;
5952 struct list_head *list_head = use_probed_modes ?
5953 &aconnector->base.probed_modes :
5954 &aconnector->base.modes;
5956 if (aconnector->base.connector_type == DRM_MODE_CONNECTOR_WRITEBACK)
5959 if (aconnector->freesync_vid_base.clock != 0)
5960 return &aconnector->freesync_vid_base;
5962 /* Find the preferred mode */
5963 list_for_each_entry(m, list_head, head) {
5964 if (m->type & DRM_MODE_TYPE_PREFERRED) {
5971 /* Probably an EDID with no preferred mode. Fallback to first entry */
5972 m_pref = list_first_entry_or_null(
5973 &aconnector->base.modes, struct drm_display_mode, head);
5975 DRM_DEBUG_DRIVER("No preferred mode found in EDID\n");
5980 highest_refresh = drm_mode_vrefresh(m_pref);
5983 * Find the mode with highest refresh rate with same resolution.
5984 * For some monitors, preferred mode is not the mode with highest
5985 * supported refresh rate.
5987 list_for_each_entry(m, list_head, head) {
5988 current_refresh = drm_mode_vrefresh(m);
5990 if (m->hdisplay == m_pref->hdisplay &&
5991 m->vdisplay == m_pref->vdisplay &&
5992 highest_refresh < current_refresh) {
5993 highest_refresh = current_refresh;
5998 drm_mode_copy(&aconnector->freesync_vid_base, m_pref);
6002 static bool is_freesync_video_mode(const struct drm_display_mode *mode,
6003 struct amdgpu_dm_connector *aconnector)
6005 struct drm_display_mode *high_mode;
6008 high_mode = get_highest_refresh_rate_mode(aconnector, false);
6009 if (!high_mode || !mode)
6012 timing_diff = high_mode->vtotal - mode->vtotal;
6014 if (high_mode->clock == 0 || high_mode->clock != mode->clock ||
6015 high_mode->hdisplay != mode->hdisplay ||
6016 high_mode->vdisplay != mode->vdisplay ||
6017 high_mode->hsync_start != mode->hsync_start ||
6018 high_mode->hsync_end != mode->hsync_end ||
6019 high_mode->htotal != mode->htotal ||
6020 high_mode->hskew != mode->hskew ||
6021 high_mode->vscan != mode->vscan ||
6022 high_mode->vsync_start - mode->vsync_start != timing_diff ||
6023 high_mode->vsync_end - mode->vsync_end != timing_diff)
6029 static void update_dsc_caps(struct amdgpu_dm_connector *aconnector,
6030 struct dc_sink *sink, struct dc_stream_state *stream,
6031 struct dsc_dec_dpcd_caps *dsc_caps)
6033 stream->timing.flags.DSC = 0;
6034 dsc_caps->is_dsc_supported = false;
6036 if (aconnector->dc_link && (sink->sink_signal == SIGNAL_TYPE_DISPLAY_PORT ||
6037 sink->sink_signal == SIGNAL_TYPE_EDP)) {
6038 if (sink->link->dpcd_caps.dongle_type == DISPLAY_DONGLE_NONE ||
6039 sink->link->dpcd_caps.dongle_type == DISPLAY_DONGLE_DP_HDMI_CONVERTER)
6040 dc_dsc_parse_dsc_dpcd(aconnector->dc_link->ctx->dc,
6041 aconnector->dc_link->dpcd_caps.dsc_caps.dsc_basic_caps.raw,
6042 aconnector->dc_link->dpcd_caps.dsc_caps.dsc_branch_decoder_caps.raw,
6048 static void apply_dsc_policy_for_edp(struct amdgpu_dm_connector *aconnector,
6049 struct dc_sink *sink, struct dc_stream_state *stream,
6050 struct dsc_dec_dpcd_caps *dsc_caps,
6051 uint32_t max_dsc_target_bpp_limit_override)
6053 const struct dc_link_settings *verified_link_cap = NULL;
6054 u32 link_bw_in_kbps;
6055 u32 edp_min_bpp_x16, edp_max_bpp_x16;
6056 struct dc *dc = sink->ctx->dc;
6057 struct dc_dsc_bw_range bw_range = {0};
6058 struct dc_dsc_config dsc_cfg = {0};
6059 struct dc_dsc_config_options dsc_options = {0};
6061 dc_dsc_get_default_config_option(dc, &dsc_options);
6062 dsc_options.max_target_bpp_limit_override_x16 = max_dsc_target_bpp_limit_override * 16;
6064 verified_link_cap = dc_link_get_link_cap(stream->link);
6065 link_bw_in_kbps = dc_link_bandwidth_kbps(stream->link, verified_link_cap);
6066 edp_min_bpp_x16 = 8 * 16;
6067 edp_max_bpp_x16 = 8 * 16;
6069 if (edp_max_bpp_x16 > dsc_caps->edp_max_bits_per_pixel)
6070 edp_max_bpp_x16 = dsc_caps->edp_max_bits_per_pixel;
6072 if (edp_max_bpp_x16 < edp_min_bpp_x16)
6073 edp_min_bpp_x16 = edp_max_bpp_x16;
6075 if (dc_dsc_compute_bandwidth_range(dc->res_pool->dscs[0],
6076 dc->debug.dsc_min_slice_height_override,
6077 edp_min_bpp_x16, edp_max_bpp_x16,
6080 dc_link_get_highest_encoding_format(aconnector->dc_link),
6083 if (bw_range.max_kbps < link_bw_in_kbps) {
6084 if (dc_dsc_compute_config(dc->res_pool->dscs[0],
6089 dc_link_get_highest_encoding_format(aconnector->dc_link),
6091 stream->timing.dsc_cfg = dsc_cfg;
6092 stream->timing.flags.DSC = 1;
6093 stream->timing.dsc_cfg.bits_per_pixel = edp_max_bpp_x16;
6099 if (dc_dsc_compute_config(dc->res_pool->dscs[0],
6104 dc_link_get_highest_encoding_format(aconnector->dc_link),
6106 stream->timing.dsc_cfg = dsc_cfg;
6107 stream->timing.flags.DSC = 1;
6112 static void apply_dsc_policy_for_stream(struct amdgpu_dm_connector *aconnector,
6113 struct dc_sink *sink, struct dc_stream_state *stream,
6114 struct dsc_dec_dpcd_caps *dsc_caps)
6116 struct drm_connector *drm_connector = &aconnector->base;
6117 u32 link_bandwidth_kbps;
6118 struct dc *dc = sink->ctx->dc;
6119 u32 max_supported_bw_in_kbps, timing_bw_in_kbps;
6120 u32 dsc_max_supported_bw_in_kbps;
6121 u32 max_dsc_target_bpp_limit_override =
6122 drm_connector->display_info.max_dsc_bpp;
6123 struct dc_dsc_config_options dsc_options = {0};
6125 dc_dsc_get_default_config_option(dc, &dsc_options);
6126 dsc_options.max_target_bpp_limit_override_x16 = max_dsc_target_bpp_limit_override * 16;
6128 link_bandwidth_kbps = dc_link_bandwidth_kbps(aconnector->dc_link,
6129 dc_link_get_link_cap(aconnector->dc_link));
6131 /* Set DSC policy according to dsc_clock_en */
6132 dc_dsc_policy_set_enable_dsc_when_not_needed(
6133 aconnector->dsc_settings.dsc_force_enable == DSC_CLK_FORCE_ENABLE);
6135 if (aconnector->dc_link && sink->sink_signal == SIGNAL_TYPE_EDP &&
6136 !aconnector->dc_link->panel_config.dsc.disable_dsc_edp &&
6137 dc->caps.edp_dsc_support && aconnector->dsc_settings.dsc_force_enable != DSC_CLK_FORCE_DISABLE) {
6139 apply_dsc_policy_for_edp(aconnector, sink, stream, dsc_caps, max_dsc_target_bpp_limit_override);
6141 } else if (aconnector->dc_link && sink->sink_signal == SIGNAL_TYPE_DISPLAY_PORT) {
6142 if (sink->link->dpcd_caps.dongle_type == DISPLAY_DONGLE_NONE) {
6143 if (dc_dsc_compute_config(aconnector->dc_link->ctx->dc->res_pool->dscs[0],
6146 link_bandwidth_kbps,
6148 dc_link_get_highest_encoding_format(aconnector->dc_link),
6149 &stream->timing.dsc_cfg)) {
6150 stream->timing.flags.DSC = 1;
6151 DRM_DEBUG_DRIVER("%s: [%s] DSC is selected from SST RX\n", __func__, drm_connector->name);
6153 } else if (sink->link->dpcd_caps.dongle_type == DISPLAY_DONGLE_DP_HDMI_CONVERTER) {
6154 timing_bw_in_kbps = dc_bandwidth_in_kbps_from_timing(&stream->timing,
6155 dc_link_get_highest_encoding_format(aconnector->dc_link));
6156 max_supported_bw_in_kbps = link_bandwidth_kbps;
6157 dsc_max_supported_bw_in_kbps = link_bandwidth_kbps;
6159 if (timing_bw_in_kbps > max_supported_bw_in_kbps &&
6160 max_supported_bw_in_kbps > 0 &&
6161 dsc_max_supported_bw_in_kbps > 0)
6162 if (dc_dsc_compute_config(aconnector->dc_link->ctx->dc->res_pool->dscs[0],
6165 dsc_max_supported_bw_in_kbps,
6167 dc_link_get_highest_encoding_format(aconnector->dc_link),
6168 &stream->timing.dsc_cfg)) {
6169 stream->timing.flags.DSC = 1;
6170 DRM_DEBUG_DRIVER("%s: [%s] DSC is selected from DP-HDMI PCON\n",
6171 __func__, drm_connector->name);
6176 /* Overwrite the stream flag if DSC is enabled through debugfs */
6177 if (aconnector->dsc_settings.dsc_force_enable == DSC_CLK_FORCE_ENABLE)
6178 stream->timing.flags.DSC = 1;
6180 if (stream->timing.flags.DSC && aconnector->dsc_settings.dsc_num_slices_h)
6181 stream->timing.dsc_cfg.num_slices_h = aconnector->dsc_settings.dsc_num_slices_h;
6183 if (stream->timing.flags.DSC && aconnector->dsc_settings.dsc_num_slices_v)
6184 stream->timing.dsc_cfg.num_slices_v = aconnector->dsc_settings.dsc_num_slices_v;
6186 if (stream->timing.flags.DSC && aconnector->dsc_settings.dsc_bits_per_pixel)
6187 stream->timing.dsc_cfg.bits_per_pixel = aconnector->dsc_settings.dsc_bits_per_pixel;
6190 static struct dc_stream_state *
6191 create_stream_for_sink(struct drm_connector *connector,
6192 const struct drm_display_mode *drm_mode,
6193 const struct dm_connector_state *dm_state,
6194 const struct dc_stream_state *old_stream,
6197 struct amdgpu_dm_connector *aconnector = NULL;
6198 struct drm_display_mode *preferred_mode = NULL;
6199 const struct drm_connector_state *con_state = &dm_state->base;
6200 struct dc_stream_state *stream = NULL;
6201 struct drm_display_mode mode;
6202 struct drm_display_mode saved_mode;
6203 struct drm_display_mode *freesync_mode = NULL;
6204 bool native_mode_found = false;
6205 bool recalculate_timing = false;
6206 bool scale = dm_state->scaling != RMX_OFF;
6208 int preferred_refresh = 0;
6209 enum color_transfer_func tf = TRANSFER_FUNC_UNKNOWN;
6210 struct dsc_dec_dpcd_caps dsc_caps;
6212 struct dc_link *link = NULL;
6213 struct dc_sink *sink = NULL;
6215 drm_mode_init(&mode, drm_mode);
6216 memset(&saved_mode, 0, sizeof(saved_mode));
6218 if (connector == NULL) {
6219 DRM_ERROR("connector is NULL!\n");
6223 if (connector->connector_type != DRM_MODE_CONNECTOR_WRITEBACK) {
6225 aconnector = to_amdgpu_dm_connector(connector);
6226 link = aconnector->dc_link;
6228 struct drm_writeback_connector *wbcon = NULL;
6229 struct amdgpu_dm_wb_connector *dm_wbcon = NULL;
6231 wbcon = drm_connector_to_writeback(connector);
6232 dm_wbcon = to_amdgpu_dm_wb_connector(wbcon);
6233 link = dm_wbcon->link;
6236 if (!aconnector || !aconnector->dc_sink) {
6237 sink = create_fake_sink(link);
6242 sink = aconnector->dc_sink;
6243 dc_sink_retain(sink);
6246 stream = dc_create_stream_for_sink(sink);
6248 if (stream == NULL) {
6249 DRM_ERROR("Failed to create stream for sink!\n");
6253 /* We leave this NULL for writeback connectors */
6254 stream->dm_stream_context = aconnector;
6256 stream->timing.flags.LTE_340MCSC_SCRAMBLE =
6257 connector->display_info.hdmi.scdc.scrambling.low_rates;
6259 list_for_each_entry(preferred_mode, &connector->modes, head) {
6260 /* Search for preferred mode */
6261 if (preferred_mode->type & DRM_MODE_TYPE_PREFERRED) {
6262 native_mode_found = true;
6266 if (!native_mode_found)
6267 preferred_mode = list_first_entry_or_null(
6269 struct drm_display_mode,
6272 mode_refresh = drm_mode_vrefresh(&mode);
6274 if (preferred_mode == NULL) {
6276 * This may not be an error, the use case is when we have no
6277 * usermode calls to reset and set mode upon hotplug. In this
6278 * case, we call set mode ourselves to restore the previous mode
6279 * and the modelist may not be filled in time.
6281 DRM_DEBUG_DRIVER("No preferred mode found\n");
6282 } else if (aconnector) {
6283 recalculate_timing = amdgpu_freesync_vid_mode &&
6284 is_freesync_video_mode(&mode, aconnector);
6285 if (recalculate_timing) {
6286 freesync_mode = get_highest_refresh_rate_mode(aconnector, false);
6287 drm_mode_copy(&saved_mode, &mode);
6288 saved_mode.picture_aspect_ratio = mode.picture_aspect_ratio;
6289 drm_mode_copy(&mode, freesync_mode);
6290 mode.picture_aspect_ratio = saved_mode.picture_aspect_ratio;
6292 decide_crtc_timing_for_drm_display_mode(
6293 &mode, preferred_mode, scale);
6295 preferred_refresh = drm_mode_vrefresh(preferred_mode);
6299 if (recalculate_timing)
6300 drm_mode_set_crtcinfo(&saved_mode, 0);
6303 * If scaling is enabled and refresh rate didn't change
6304 * we copy the vic and polarities of the old timings
6306 if (!scale || mode_refresh != preferred_refresh)
6307 fill_stream_properties_from_drm_display_mode(
6308 stream, &mode, connector, con_state, NULL,
6311 fill_stream_properties_from_drm_display_mode(
6312 stream, &mode, connector, con_state, old_stream,
6315 /* The rest isn't needed for writeback connectors */
6319 if (aconnector->timing_changed) {
6320 drm_dbg(aconnector->base.dev,
6321 "overriding timing for automated test, bpc %d, changing to %d\n",
6322 stream->timing.display_color_depth,
6323 aconnector->timing_requested->display_color_depth);
6324 stream->timing = *aconnector->timing_requested;
6327 /* SST DSC determination policy */
6328 update_dsc_caps(aconnector, sink, stream, &dsc_caps);
6329 if (aconnector->dsc_settings.dsc_force_enable != DSC_CLK_FORCE_DISABLE && dsc_caps.is_dsc_supported)
6330 apply_dsc_policy_for_stream(aconnector, sink, stream, &dsc_caps);
6332 update_stream_scaling_settings(&mode, dm_state, stream);
6335 &stream->audio_info,
6339 update_stream_signal(stream, sink);
6341 if (stream->signal == SIGNAL_TYPE_HDMI_TYPE_A)
6342 mod_build_hf_vsif_infopacket(stream, &stream->vsp_infopacket);
6344 if (stream->signal == SIGNAL_TYPE_DISPLAY_PORT ||
6345 stream->signal == SIGNAL_TYPE_DISPLAY_PORT_MST ||
6346 stream->signal == SIGNAL_TYPE_EDP) {
6348 // should decide stream support vsc sdp colorimetry capability
6349 // before building vsc info packet
6351 stream->use_vsc_sdp_for_colorimetry = stream->link->dpcd_caps.dpcd_rev.raw >= 0x14 &&
6352 stream->link->dpcd_caps.dprx_feature.bits.VSC_SDP_COLORIMETRY_SUPPORTED;
6354 if (stream->out_transfer_func.tf == TRANSFER_FUNCTION_GAMMA22)
6355 tf = TRANSFER_FUNC_GAMMA_22;
6356 mod_build_vsc_infopacket(stream, &stream->vsc_infopacket, stream->output_color_space, tf);
6357 aconnector->psr_skip_count = AMDGPU_DM_PSR_ENTRY_DELAY;
6361 dc_sink_release(sink);
6366 static enum drm_connector_status
6367 amdgpu_dm_connector_detect(struct drm_connector *connector, bool force)
6370 struct amdgpu_dm_connector *aconnector = to_amdgpu_dm_connector(connector);
6374 * 1. This interface is NOT called in context of HPD irq.
6375 * 2. This interface *is called* in context of user-mode ioctl. Which
6376 * makes it a bad place for *any* MST-related activity.
6379 if (aconnector->base.force == DRM_FORCE_UNSPECIFIED &&
6380 !aconnector->fake_enable)
6381 connected = (aconnector->dc_sink != NULL);
6383 connected = (aconnector->base.force == DRM_FORCE_ON ||
6384 aconnector->base.force == DRM_FORCE_ON_DIGITAL);
6386 update_subconnector_property(aconnector);
6388 return (connected ? connector_status_connected :
6389 connector_status_disconnected);
6392 int amdgpu_dm_connector_atomic_set_property(struct drm_connector *connector,
6393 struct drm_connector_state *connector_state,
6394 struct drm_property *property,
6397 struct drm_device *dev = connector->dev;
6398 struct amdgpu_device *adev = drm_to_adev(dev);
6399 struct dm_connector_state *dm_old_state =
6400 to_dm_connector_state(connector->state);
6401 struct dm_connector_state *dm_new_state =
6402 to_dm_connector_state(connector_state);
6406 if (property == dev->mode_config.scaling_mode_property) {
6407 enum amdgpu_rmx_type rmx_type;
6410 case DRM_MODE_SCALE_CENTER:
6411 rmx_type = RMX_CENTER;
6413 case DRM_MODE_SCALE_ASPECT:
6414 rmx_type = RMX_ASPECT;
6416 case DRM_MODE_SCALE_FULLSCREEN:
6417 rmx_type = RMX_FULL;
6419 case DRM_MODE_SCALE_NONE:
6425 if (dm_old_state->scaling == rmx_type)
6428 dm_new_state->scaling = rmx_type;
6430 } else if (property == adev->mode_info.underscan_hborder_property) {
6431 dm_new_state->underscan_hborder = val;
6433 } else if (property == adev->mode_info.underscan_vborder_property) {
6434 dm_new_state->underscan_vborder = val;
6436 } else if (property == adev->mode_info.underscan_property) {
6437 dm_new_state->underscan_enable = val;
6444 int amdgpu_dm_connector_atomic_get_property(struct drm_connector *connector,
6445 const struct drm_connector_state *state,
6446 struct drm_property *property,
6449 struct drm_device *dev = connector->dev;
6450 struct amdgpu_device *adev = drm_to_adev(dev);
6451 struct dm_connector_state *dm_state =
6452 to_dm_connector_state(state);
6455 if (property == dev->mode_config.scaling_mode_property) {
6456 switch (dm_state->scaling) {
6458 *val = DRM_MODE_SCALE_CENTER;
6461 *val = DRM_MODE_SCALE_ASPECT;
6464 *val = DRM_MODE_SCALE_FULLSCREEN;
6468 *val = DRM_MODE_SCALE_NONE;
6472 } else if (property == adev->mode_info.underscan_hborder_property) {
6473 *val = dm_state->underscan_hborder;
6475 } else if (property == adev->mode_info.underscan_vborder_property) {
6476 *val = dm_state->underscan_vborder;
6478 } else if (property == adev->mode_info.underscan_property) {
6479 *val = dm_state->underscan_enable;
6487 * DOC: panel power savings
6489 * The display manager allows you to set your desired **panel power savings**
6490 * level (between 0-4, with 0 representing off), e.g. using the following::
6492 * # echo 3 > /sys/class/drm/card0-eDP-1/amdgpu/panel_power_savings
6494 * Modifying this value can have implications on color accuracy, so tread
6498 static ssize_t panel_power_savings_show(struct device *device,
6499 struct device_attribute *attr,
6502 struct drm_connector *connector = dev_get_drvdata(device);
6503 struct drm_device *dev = connector->dev;
6506 drm_modeset_lock(&dev->mode_config.connection_mutex, NULL);
6507 val = to_dm_connector_state(connector->state)->abm_level ==
6508 ABM_LEVEL_IMMEDIATE_DISABLE ? 0 :
6509 to_dm_connector_state(connector->state)->abm_level;
6510 drm_modeset_unlock(&dev->mode_config.connection_mutex);
6512 return sysfs_emit(buf, "%u\n", val);
6515 static ssize_t panel_power_savings_store(struct device *device,
6516 struct device_attribute *attr,
6517 const char *buf, size_t count)
6519 struct drm_connector *connector = dev_get_drvdata(device);
6520 struct drm_device *dev = connector->dev;
6524 ret = kstrtol(buf, 0, &val);
6529 if (val < 0 || val > 4)
6532 drm_modeset_lock(&dev->mode_config.connection_mutex, NULL);
6533 to_dm_connector_state(connector->state)->abm_level = val ?:
6534 ABM_LEVEL_IMMEDIATE_DISABLE;
6535 drm_modeset_unlock(&dev->mode_config.connection_mutex);
6537 drm_kms_helper_hotplug_event(dev);
6542 static DEVICE_ATTR_RW(panel_power_savings);
6544 static struct attribute *amdgpu_attrs[] = {
6545 &dev_attr_panel_power_savings.attr,
6549 static const struct attribute_group amdgpu_group = {
6551 .attrs = amdgpu_attrs
6554 static void amdgpu_dm_connector_unregister(struct drm_connector *connector)
6556 struct amdgpu_dm_connector *amdgpu_dm_connector = to_amdgpu_dm_connector(connector);
6558 if (connector->connector_type == DRM_MODE_CONNECTOR_eDP &&
6559 amdgpu_dm_abm_level < 0)
6560 sysfs_remove_group(&connector->kdev->kobj, &amdgpu_group);
6562 drm_dp_aux_unregister(&amdgpu_dm_connector->dm_dp_aux.aux);
6565 static void amdgpu_dm_connector_destroy(struct drm_connector *connector)
6567 struct amdgpu_dm_connector *aconnector = to_amdgpu_dm_connector(connector);
6568 struct amdgpu_device *adev = drm_to_adev(connector->dev);
6569 struct amdgpu_display_manager *dm = &adev->dm;
6572 * Call only if mst_mgr was initialized before since it's not done
6573 * for all connector types.
6575 if (aconnector->mst_mgr.dev)
6576 drm_dp_mst_topology_mgr_destroy(&aconnector->mst_mgr);
6578 if (aconnector->bl_idx != -1) {
6579 backlight_device_unregister(dm->backlight_dev[aconnector->bl_idx]);
6580 dm->backlight_dev[aconnector->bl_idx] = NULL;
6583 if (aconnector->dc_em_sink)
6584 dc_sink_release(aconnector->dc_em_sink);
6585 aconnector->dc_em_sink = NULL;
6586 if (aconnector->dc_sink)
6587 dc_sink_release(aconnector->dc_sink);
6588 aconnector->dc_sink = NULL;
6590 drm_dp_cec_unregister_connector(&aconnector->dm_dp_aux.aux);
6591 drm_connector_unregister(connector);
6592 drm_connector_cleanup(connector);
6593 if (aconnector->i2c) {
6594 i2c_del_adapter(&aconnector->i2c->base);
6595 kfree(aconnector->i2c);
6597 kfree(aconnector->dm_dp_aux.aux.name);
6602 void amdgpu_dm_connector_funcs_reset(struct drm_connector *connector)
6604 struct dm_connector_state *state =
6605 to_dm_connector_state(connector->state);
6607 if (connector->state)
6608 __drm_atomic_helper_connector_destroy_state(connector->state);
6612 state = kzalloc(sizeof(*state), GFP_KERNEL);
6615 state->scaling = RMX_OFF;
6616 state->underscan_enable = false;
6617 state->underscan_hborder = 0;
6618 state->underscan_vborder = 0;
6619 state->base.max_requested_bpc = 8;
6620 state->vcpi_slots = 0;
6623 if (connector->connector_type == DRM_MODE_CONNECTOR_eDP) {
6624 if (amdgpu_dm_abm_level <= 0)
6625 state->abm_level = ABM_LEVEL_IMMEDIATE_DISABLE;
6627 state->abm_level = amdgpu_dm_abm_level;
6630 __drm_atomic_helper_connector_reset(connector, &state->base);
6634 struct drm_connector_state *
6635 amdgpu_dm_connector_atomic_duplicate_state(struct drm_connector *connector)
6637 struct dm_connector_state *state =
6638 to_dm_connector_state(connector->state);
6640 struct dm_connector_state *new_state =
6641 kmemdup(state, sizeof(*state), GFP_KERNEL);
6646 __drm_atomic_helper_connector_duplicate_state(connector, &new_state->base);
6648 new_state->freesync_capable = state->freesync_capable;
6649 new_state->abm_level = state->abm_level;
6650 new_state->scaling = state->scaling;
6651 new_state->underscan_enable = state->underscan_enable;
6652 new_state->underscan_hborder = state->underscan_hborder;
6653 new_state->underscan_vborder = state->underscan_vborder;
6654 new_state->vcpi_slots = state->vcpi_slots;
6655 new_state->pbn = state->pbn;
6656 return &new_state->base;
6660 amdgpu_dm_connector_late_register(struct drm_connector *connector)
6662 struct amdgpu_dm_connector *amdgpu_dm_connector =
6663 to_amdgpu_dm_connector(connector);
6666 if (connector->connector_type == DRM_MODE_CONNECTOR_eDP &&
6667 amdgpu_dm_abm_level < 0) {
6668 r = sysfs_create_group(&connector->kdev->kobj,
6674 amdgpu_dm_register_backlight_device(amdgpu_dm_connector);
6676 if ((connector->connector_type == DRM_MODE_CONNECTOR_DisplayPort) ||
6677 (connector->connector_type == DRM_MODE_CONNECTOR_eDP)) {
6678 amdgpu_dm_connector->dm_dp_aux.aux.dev = connector->kdev;
6679 r = drm_dp_aux_register(&amdgpu_dm_connector->dm_dp_aux.aux);
6684 #if defined(CONFIG_DEBUG_FS)
6685 connector_debugfs_init(amdgpu_dm_connector);
6691 static void amdgpu_dm_connector_funcs_force(struct drm_connector *connector)
6693 struct amdgpu_dm_connector *aconnector = to_amdgpu_dm_connector(connector);
6694 struct dc_link *dc_link = aconnector->dc_link;
6695 struct dc_sink *dc_em_sink = aconnector->dc_em_sink;
6697 struct i2c_adapter *ddc;
6699 if (dc_link && dc_link->aux_mode)
6700 ddc = &aconnector->dm_dp_aux.aux.ddc;
6702 ddc = &aconnector->i2c->base;
6705 * Note: drm_get_edid gets edid in the following order:
6706 * 1) override EDID if set via edid_override debugfs,
6707 * 2) firmware EDID if set via edid_firmware module parameter
6708 * 3) regular DDC read.
6710 edid = drm_get_edid(connector, ddc);
6712 DRM_ERROR("No EDID found on connector: %s.\n", connector->name);
6716 aconnector->edid = edid;
6718 /* Update emulated (virtual) sink's EDID */
6719 if (dc_em_sink && dc_link) {
6720 memset(&dc_em_sink->edid_caps, 0, sizeof(struct dc_edid_caps));
6721 memmove(dc_em_sink->dc_edid.raw_edid, edid, (edid->extensions + 1) * EDID_LENGTH);
6722 dm_helpers_parse_edid_caps(
6724 &dc_em_sink->dc_edid,
6725 &dc_em_sink->edid_caps);
6729 static const struct drm_connector_funcs amdgpu_dm_connector_funcs = {
6730 .reset = amdgpu_dm_connector_funcs_reset,
6731 .detect = amdgpu_dm_connector_detect,
6732 .fill_modes = drm_helper_probe_single_connector_modes,
6733 .destroy = amdgpu_dm_connector_destroy,
6734 .atomic_duplicate_state = amdgpu_dm_connector_atomic_duplicate_state,
6735 .atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
6736 .atomic_set_property = amdgpu_dm_connector_atomic_set_property,
6737 .atomic_get_property = amdgpu_dm_connector_atomic_get_property,
6738 .late_register = amdgpu_dm_connector_late_register,
6739 .early_unregister = amdgpu_dm_connector_unregister,
6740 .force = amdgpu_dm_connector_funcs_force
6743 static int get_modes(struct drm_connector *connector)
6745 return amdgpu_dm_connector_get_modes(connector);
6748 static void create_eml_sink(struct amdgpu_dm_connector *aconnector)
6750 struct drm_connector *connector = &aconnector->base;
6751 struct dc_link *dc_link = aconnector->dc_link;
6752 struct dc_sink_init_data init_params = {
6753 .link = aconnector->dc_link,
6754 .sink_signal = SIGNAL_TYPE_VIRTUAL
6757 struct i2c_adapter *ddc;
6759 if (dc_link->aux_mode)
6760 ddc = &aconnector->dm_dp_aux.aux.ddc;
6762 ddc = &aconnector->i2c->base;
6765 * Note: drm_get_edid gets edid in the following order:
6766 * 1) override EDID if set via edid_override debugfs,
6767 * 2) firmware EDID if set via edid_firmware module parameter
6768 * 3) regular DDC read.
6770 edid = drm_get_edid(connector, ddc);
6772 DRM_ERROR("No EDID found on connector: %s.\n", connector->name);
6776 if (drm_detect_hdmi_monitor(edid))
6777 init_params.sink_signal = SIGNAL_TYPE_HDMI_TYPE_A;
6779 aconnector->edid = edid;
6781 aconnector->dc_em_sink = dc_link_add_remote_sink(
6782 aconnector->dc_link,
6784 (edid->extensions + 1) * EDID_LENGTH,
6787 if (aconnector->base.force == DRM_FORCE_ON) {
6788 aconnector->dc_sink = aconnector->dc_link->local_sink ?
6789 aconnector->dc_link->local_sink :
6790 aconnector->dc_em_sink;
6791 dc_sink_retain(aconnector->dc_sink);
6795 static void handle_edid_mgmt(struct amdgpu_dm_connector *aconnector)
6797 struct dc_link *link = (struct dc_link *)aconnector->dc_link;
6800 * In case of headless boot with force on for DP managed connector
6801 * Those settings have to be != 0 to get initial modeset
6803 if (link->connector_signal == SIGNAL_TYPE_DISPLAY_PORT) {
6804 link->verified_link_cap.lane_count = LANE_COUNT_FOUR;
6805 link->verified_link_cap.link_rate = LINK_RATE_HIGH2;
6808 create_eml_sink(aconnector);
6811 static enum dc_status dm_validate_stream_and_context(struct dc *dc,
6812 struct dc_stream_state *stream)
6814 enum dc_status dc_result = DC_ERROR_UNEXPECTED;
6815 struct dc_plane_state *dc_plane_state = NULL;
6816 struct dc_state *dc_state = NULL;
6821 dc_plane_state = dc_create_plane_state(dc);
6822 if (!dc_plane_state)
6825 dc_state = dc_state_create(dc, NULL);
6829 /* populate stream to plane */
6830 dc_plane_state->src_rect.height = stream->src.height;
6831 dc_plane_state->src_rect.width = stream->src.width;
6832 dc_plane_state->dst_rect.height = stream->src.height;
6833 dc_plane_state->dst_rect.width = stream->src.width;
6834 dc_plane_state->clip_rect.height = stream->src.height;
6835 dc_plane_state->clip_rect.width = stream->src.width;
6836 dc_plane_state->plane_size.surface_pitch = ((stream->src.width + 255) / 256) * 256;
6837 dc_plane_state->plane_size.surface_size.height = stream->src.height;
6838 dc_plane_state->plane_size.surface_size.width = stream->src.width;
6839 dc_plane_state->plane_size.chroma_size.height = stream->src.height;
6840 dc_plane_state->plane_size.chroma_size.width = stream->src.width;
6841 dc_plane_state->format = SURFACE_PIXEL_FORMAT_GRPH_ARGB8888;
6842 dc_plane_state->tiling_info.gfx9.swizzle = DC_SW_UNKNOWN;
6843 dc_plane_state->rotation = ROTATION_ANGLE_0;
6844 dc_plane_state->is_tiling_rotated = false;
6845 dc_plane_state->tiling_info.gfx8.array_mode = DC_ARRAY_LINEAR_GENERAL;
6847 dc_result = dc_validate_stream(dc, stream);
6848 if (dc_result == DC_OK)
6849 dc_result = dc_validate_plane(dc, dc_plane_state);
6851 if (dc_result == DC_OK)
6852 dc_result = dc_state_add_stream(dc, dc_state, stream);
6854 if (dc_result == DC_OK && !dc_state_add_plane(
6859 dc_result = DC_FAIL_ATTACH_SURFACES;
6861 if (dc_result == DC_OK)
6862 dc_result = dc_validate_global_state(dc, dc_state, true);
6866 dc_state_release(dc_state);
6869 dc_plane_state_release(dc_plane_state);
6874 struct dc_stream_state *
6875 create_validate_stream_for_sink(struct amdgpu_dm_connector *aconnector,
6876 const struct drm_display_mode *drm_mode,
6877 const struct dm_connector_state *dm_state,
6878 const struct dc_stream_state *old_stream)
6880 struct drm_connector *connector = &aconnector->base;
6881 struct amdgpu_device *adev = drm_to_adev(connector->dev);
6882 struct dc_stream_state *stream;
6883 const struct drm_connector_state *drm_state = dm_state ? &dm_state->base : NULL;
6884 int requested_bpc = drm_state ? drm_state->max_requested_bpc : 8;
6885 enum dc_status dc_result = DC_OK;
6888 stream = create_stream_for_sink(connector, drm_mode,
6889 dm_state, old_stream,
6891 if (stream == NULL) {
6892 DRM_ERROR("Failed to create stream for sink!\n");
6896 if (aconnector->base.connector_type == DRM_MODE_CONNECTOR_WRITEBACK)
6899 dc_result = dc_validate_stream(adev->dm.dc, stream);
6900 if (dc_result == DC_OK && stream->signal == SIGNAL_TYPE_DISPLAY_PORT_MST)
6901 dc_result = dm_dp_mst_is_port_support_mode(aconnector, stream);
6903 if (dc_result == DC_OK)
6904 dc_result = dm_validate_stream_and_context(adev->dm.dc, stream);
6906 if (dc_result != DC_OK) {
6907 DRM_DEBUG_KMS("Mode %dx%d (clk %d) failed DC validation with error %d (%s)\n",
6912 dc_status_to_str(dc_result));
6914 dc_stream_release(stream);
6916 requested_bpc -= 2; /* lower bpc to retry validation */
6919 } while (stream == NULL && requested_bpc >= 6);
6921 if (dc_result == DC_FAIL_ENC_VALIDATE && !aconnector->force_yuv420_output) {
6922 DRM_DEBUG_KMS("Retry forcing YCbCr420 encoding\n");
6924 aconnector->force_yuv420_output = true;
6925 stream = create_validate_stream_for_sink(aconnector, drm_mode,
6926 dm_state, old_stream);
6927 aconnector->force_yuv420_output = false;
6933 enum drm_mode_status amdgpu_dm_connector_mode_valid(struct drm_connector *connector,
6934 struct drm_display_mode *mode)
6936 int result = MODE_ERROR;
6937 struct dc_sink *dc_sink;
6938 /* TODO: Unhardcode stream count */
6939 struct dc_stream_state *stream;
6940 struct amdgpu_dm_connector *aconnector = to_amdgpu_dm_connector(connector);
6942 if ((mode->flags & DRM_MODE_FLAG_INTERLACE) ||
6943 (mode->flags & DRM_MODE_FLAG_DBLSCAN))
6947 * Only run this the first time mode_valid is called to initilialize
6950 if (aconnector->base.force != DRM_FORCE_UNSPECIFIED &&
6951 !aconnector->dc_em_sink)
6952 handle_edid_mgmt(aconnector);
6954 dc_sink = to_amdgpu_dm_connector(connector)->dc_sink;
6956 if (dc_sink == NULL && aconnector->base.force != DRM_FORCE_ON_DIGITAL &&
6957 aconnector->base.force != DRM_FORCE_ON) {
6958 DRM_ERROR("dc_sink is NULL!\n");
6962 drm_mode_set_crtcinfo(mode, 0);
6964 stream = create_validate_stream_for_sink(aconnector, mode,
6965 to_dm_connector_state(connector->state),
6968 dc_stream_release(stream);
6973 /* TODO: error handling*/
6977 static int fill_hdr_info_packet(const struct drm_connector_state *state,
6978 struct dc_info_packet *out)
6980 struct hdmi_drm_infoframe frame;
6981 unsigned char buf[30]; /* 26 + 4 */
6985 memset(out, 0, sizeof(*out));
6987 if (!state->hdr_output_metadata)
6990 ret = drm_hdmi_infoframe_set_hdr_metadata(&frame, state);
6994 len = hdmi_drm_infoframe_pack_only(&frame, buf, sizeof(buf));
6998 /* Static metadata is a fixed 26 bytes + 4 byte header. */
7002 /* Prepare the infopacket for DC. */
7003 switch (state->connector->connector_type) {
7004 case DRM_MODE_CONNECTOR_HDMIA:
7005 out->hb0 = 0x87; /* type */
7006 out->hb1 = 0x01; /* version */
7007 out->hb2 = 0x1A; /* length */
7008 out->sb[0] = buf[3]; /* checksum */
7012 case DRM_MODE_CONNECTOR_DisplayPort:
7013 case DRM_MODE_CONNECTOR_eDP:
7014 out->hb0 = 0x00; /* sdp id, zero */
7015 out->hb1 = 0x87; /* type */
7016 out->hb2 = 0x1D; /* payload len - 1 */
7017 out->hb3 = (0x13 << 2); /* sdp version */
7018 out->sb[0] = 0x01; /* version */
7019 out->sb[1] = 0x1A; /* length */
7027 memcpy(&out->sb[i], &buf[4], 26);
7030 print_hex_dump(KERN_DEBUG, "HDR SB:", DUMP_PREFIX_NONE, 16, 1, out->sb,
7031 sizeof(out->sb), false);
7037 amdgpu_dm_connector_atomic_check(struct drm_connector *conn,
7038 struct drm_atomic_state *state)
7040 struct drm_connector_state *new_con_state =
7041 drm_atomic_get_new_connector_state(state, conn);
7042 struct drm_connector_state *old_con_state =
7043 drm_atomic_get_old_connector_state(state, conn);
7044 struct drm_crtc *crtc = new_con_state->crtc;
7045 struct drm_crtc_state *new_crtc_state;
7046 struct amdgpu_dm_connector *aconn = to_amdgpu_dm_connector(conn);
7049 trace_amdgpu_dm_connector_atomic_check(new_con_state);
7051 if (conn->connector_type == DRM_MODE_CONNECTOR_DisplayPort) {
7052 ret = drm_dp_mst_root_conn_atomic_check(new_con_state, &aconn->mst_mgr);
7060 if (new_con_state->colorspace != old_con_state->colorspace) {
7061 new_crtc_state = drm_atomic_get_crtc_state(state, crtc);
7062 if (IS_ERR(new_crtc_state))
7063 return PTR_ERR(new_crtc_state);
7065 new_crtc_state->mode_changed = true;
7068 if (new_con_state->content_type != old_con_state->content_type) {
7069 new_crtc_state = drm_atomic_get_crtc_state(state, crtc);
7070 if (IS_ERR(new_crtc_state))
7071 return PTR_ERR(new_crtc_state);
7073 new_crtc_state->mode_changed = true;
7076 if (!drm_connector_atomic_hdr_metadata_equal(old_con_state, new_con_state)) {
7077 struct dc_info_packet hdr_infopacket;
7079 ret = fill_hdr_info_packet(new_con_state, &hdr_infopacket);
7083 new_crtc_state = drm_atomic_get_crtc_state(state, crtc);
7084 if (IS_ERR(new_crtc_state))
7085 return PTR_ERR(new_crtc_state);
7088 * DC considers the stream backends changed if the
7089 * static metadata changes. Forcing the modeset also
7090 * gives a simple way for userspace to switch from
7091 * 8bpc to 10bpc when setting the metadata to enter
7094 * Changing the static metadata after it's been
7095 * set is permissible, however. So only force a
7096 * modeset if we're entering or exiting HDR.
7098 new_crtc_state->mode_changed = new_crtc_state->mode_changed ||
7099 !old_con_state->hdr_output_metadata ||
7100 !new_con_state->hdr_output_metadata;
7106 static const struct drm_connector_helper_funcs
7107 amdgpu_dm_connector_helper_funcs = {
7109 * If hotplugging a second bigger display in FB Con mode, bigger resolution
7110 * modes will be filtered by drm_mode_validate_size(), and those modes
7111 * are missing after user start lightdm. So we need to renew modes list.
7112 * in get_modes call back, not just return the modes count
7114 .get_modes = get_modes,
7115 .mode_valid = amdgpu_dm_connector_mode_valid,
7116 .atomic_check = amdgpu_dm_connector_atomic_check,
7119 static void dm_encoder_helper_disable(struct drm_encoder *encoder)
7124 int convert_dc_color_depth_into_bpc(enum dc_color_depth display_color_depth)
7126 switch (display_color_depth) {
7127 case COLOR_DEPTH_666:
7129 case COLOR_DEPTH_888:
7131 case COLOR_DEPTH_101010:
7133 case COLOR_DEPTH_121212:
7135 case COLOR_DEPTH_141414:
7137 case COLOR_DEPTH_161616:
7145 static int dm_encoder_helper_atomic_check(struct drm_encoder *encoder,
7146 struct drm_crtc_state *crtc_state,
7147 struct drm_connector_state *conn_state)
7149 struct drm_atomic_state *state = crtc_state->state;
7150 struct drm_connector *connector = conn_state->connector;
7151 struct amdgpu_dm_connector *aconnector = to_amdgpu_dm_connector(connector);
7152 struct dm_connector_state *dm_new_connector_state = to_dm_connector_state(conn_state);
7153 const struct drm_display_mode *adjusted_mode = &crtc_state->adjusted_mode;
7154 struct drm_dp_mst_topology_mgr *mst_mgr;
7155 struct drm_dp_mst_port *mst_port;
7156 struct drm_dp_mst_topology_state *mst_state;
7157 enum dc_color_depth color_depth;
7159 bool is_y420 = false;
7161 if (!aconnector->mst_output_port)
7164 mst_port = aconnector->mst_output_port;
7165 mst_mgr = &aconnector->mst_root->mst_mgr;
7167 if (!crtc_state->connectors_changed && !crtc_state->mode_changed)
7170 mst_state = drm_atomic_get_mst_topology_state(state, mst_mgr);
7171 if (IS_ERR(mst_state))
7172 return PTR_ERR(mst_state);
7174 mst_state->pbn_div.full = dfixed_const(dm_mst_get_pbn_divider(aconnector->mst_root->dc_link));
7176 if (!state->duplicated) {
7177 int max_bpc = conn_state->max_requested_bpc;
7179 is_y420 = drm_mode_is_420_also(&connector->display_info, adjusted_mode) &&
7180 aconnector->force_yuv420_output;
7181 color_depth = convert_color_depth_from_display_info(connector,
7184 bpp = convert_dc_color_depth_into_bpc(color_depth) * 3;
7185 clock = adjusted_mode->clock;
7186 dm_new_connector_state->pbn = drm_dp_calc_pbn_mode(clock, bpp << 4);
7189 dm_new_connector_state->vcpi_slots =
7190 drm_dp_atomic_find_time_slots(state, mst_mgr, mst_port,
7191 dm_new_connector_state->pbn);
7192 if (dm_new_connector_state->vcpi_slots < 0) {
7193 DRM_DEBUG_ATOMIC("failed finding vcpi slots: %d\n", (int)dm_new_connector_state->vcpi_slots);
7194 return dm_new_connector_state->vcpi_slots;
7199 const struct drm_encoder_helper_funcs amdgpu_dm_encoder_helper_funcs = {
7200 .disable = dm_encoder_helper_disable,
7201 .atomic_check = dm_encoder_helper_atomic_check
7204 static int dm_update_mst_vcpi_slots_for_dsc(struct drm_atomic_state *state,
7205 struct dc_state *dc_state,
7206 struct dsc_mst_fairness_vars *vars)
7208 struct dc_stream_state *stream = NULL;
7209 struct drm_connector *connector;
7210 struct drm_connector_state *new_con_state;
7211 struct amdgpu_dm_connector *aconnector;
7212 struct dm_connector_state *dm_conn_state;
7214 int vcpi, pbn_div, pbn = 0, slot_num = 0;
7216 for_each_new_connector_in_state(state, connector, new_con_state, i) {
7218 if (connector->connector_type == DRM_MODE_CONNECTOR_WRITEBACK)
7221 aconnector = to_amdgpu_dm_connector(connector);
7223 if (!aconnector->mst_output_port)
7226 if (!new_con_state || !new_con_state->crtc)
7229 dm_conn_state = to_dm_connector_state(new_con_state);
7231 for (j = 0; j < dc_state->stream_count; j++) {
7232 stream = dc_state->streams[j];
7236 if ((struct amdgpu_dm_connector *)stream->dm_stream_context == aconnector)
7245 pbn_div = dm_mst_get_pbn_divider(stream->link);
7246 /* pbn is calculated by compute_mst_dsc_configs_for_state*/
7247 for (j = 0; j < dc_state->stream_count; j++) {
7248 if (vars[j].aconnector == aconnector) {
7254 if (j == dc_state->stream_count)
7257 slot_num = DIV_ROUND_UP(pbn, pbn_div);
7259 if (stream->timing.flags.DSC != 1) {
7260 dm_conn_state->pbn = pbn;
7261 dm_conn_state->vcpi_slots = slot_num;
7263 ret = drm_dp_mst_atomic_enable_dsc(state, aconnector->mst_output_port,
7264 dm_conn_state->pbn, false);
7271 vcpi = drm_dp_mst_atomic_enable_dsc(state, aconnector->mst_output_port, pbn, true);
7275 dm_conn_state->pbn = pbn;
7276 dm_conn_state->vcpi_slots = vcpi;
7281 static int to_drm_connector_type(enum signal_type st)
7284 case SIGNAL_TYPE_HDMI_TYPE_A:
7285 return DRM_MODE_CONNECTOR_HDMIA;
7286 case SIGNAL_TYPE_EDP:
7287 return DRM_MODE_CONNECTOR_eDP;
7288 case SIGNAL_TYPE_LVDS:
7289 return DRM_MODE_CONNECTOR_LVDS;
7290 case SIGNAL_TYPE_RGB:
7291 return DRM_MODE_CONNECTOR_VGA;
7292 case SIGNAL_TYPE_DISPLAY_PORT:
7293 case SIGNAL_TYPE_DISPLAY_PORT_MST:
7294 return DRM_MODE_CONNECTOR_DisplayPort;
7295 case SIGNAL_TYPE_DVI_DUAL_LINK:
7296 case SIGNAL_TYPE_DVI_SINGLE_LINK:
7297 return DRM_MODE_CONNECTOR_DVID;
7298 case SIGNAL_TYPE_VIRTUAL:
7299 return DRM_MODE_CONNECTOR_VIRTUAL;
7302 return DRM_MODE_CONNECTOR_Unknown;
7306 static struct drm_encoder *amdgpu_dm_connector_to_encoder(struct drm_connector *connector)
7308 struct drm_encoder *encoder;
7310 /* There is only one encoder per connector */
7311 drm_connector_for_each_possible_encoder(connector, encoder)
7317 static void amdgpu_dm_get_native_mode(struct drm_connector *connector)
7319 struct drm_encoder *encoder;
7320 struct amdgpu_encoder *amdgpu_encoder;
7322 encoder = amdgpu_dm_connector_to_encoder(connector);
7324 if (encoder == NULL)
7327 amdgpu_encoder = to_amdgpu_encoder(encoder);
7329 amdgpu_encoder->native_mode.clock = 0;
7331 if (!list_empty(&connector->probed_modes)) {
7332 struct drm_display_mode *preferred_mode = NULL;
7334 list_for_each_entry(preferred_mode,
7335 &connector->probed_modes,
7337 if (preferred_mode->type & DRM_MODE_TYPE_PREFERRED)
7338 amdgpu_encoder->native_mode = *preferred_mode;
7346 static struct drm_display_mode *
7347 amdgpu_dm_create_common_mode(struct drm_encoder *encoder,
7349 int hdisplay, int vdisplay)
7351 struct drm_device *dev = encoder->dev;
7352 struct amdgpu_encoder *amdgpu_encoder = to_amdgpu_encoder(encoder);
7353 struct drm_display_mode *mode = NULL;
7354 struct drm_display_mode *native_mode = &amdgpu_encoder->native_mode;
7356 mode = drm_mode_duplicate(dev, native_mode);
7361 mode->hdisplay = hdisplay;
7362 mode->vdisplay = vdisplay;
7363 mode->type &= ~DRM_MODE_TYPE_PREFERRED;
7364 strscpy(mode->name, name, DRM_DISPLAY_MODE_LEN);
7370 static void amdgpu_dm_connector_add_common_modes(struct drm_encoder *encoder,
7371 struct drm_connector *connector)
7373 struct amdgpu_encoder *amdgpu_encoder = to_amdgpu_encoder(encoder);
7374 struct drm_display_mode *mode = NULL;
7375 struct drm_display_mode *native_mode = &amdgpu_encoder->native_mode;
7376 struct amdgpu_dm_connector *amdgpu_dm_connector =
7377 to_amdgpu_dm_connector(connector);
7381 char name[DRM_DISPLAY_MODE_LEN];
7384 } common_modes[] = {
7385 { "640x480", 640, 480},
7386 { "800x600", 800, 600},
7387 { "1024x768", 1024, 768},
7388 { "1280x720", 1280, 720},
7389 { "1280x800", 1280, 800},
7390 {"1280x1024", 1280, 1024},
7391 { "1440x900", 1440, 900},
7392 {"1680x1050", 1680, 1050},
7393 {"1600x1200", 1600, 1200},
7394 {"1920x1080", 1920, 1080},
7395 {"1920x1200", 1920, 1200}
7398 n = ARRAY_SIZE(common_modes);
7400 for (i = 0; i < n; i++) {
7401 struct drm_display_mode *curmode = NULL;
7402 bool mode_existed = false;
7404 if (common_modes[i].w > native_mode->hdisplay ||
7405 common_modes[i].h > native_mode->vdisplay ||
7406 (common_modes[i].w == native_mode->hdisplay &&
7407 common_modes[i].h == native_mode->vdisplay))
7410 list_for_each_entry(curmode, &connector->probed_modes, head) {
7411 if (common_modes[i].w == curmode->hdisplay &&
7412 common_modes[i].h == curmode->vdisplay) {
7413 mode_existed = true;
7421 mode = amdgpu_dm_create_common_mode(encoder,
7422 common_modes[i].name, common_modes[i].w,
7427 drm_mode_probed_add(connector, mode);
7428 amdgpu_dm_connector->num_modes++;
7432 static void amdgpu_set_panel_orientation(struct drm_connector *connector)
7434 struct drm_encoder *encoder;
7435 struct amdgpu_encoder *amdgpu_encoder;
7436 const struct drm_display_mode *native_mode;
7438 if (connector->connector_type != DRM_MODE_CONNECTOR_eDP &&
7439 connector->connector_type != DRM_MODE_CONNECTOR_LVDS)
7442 mutex_lock(&connector->dev->mode_config.mutex);
7443 amdgpu_dm_connector_get_modes(connector);
7444 mutex_unlock(&connector->dev->mode_config.mutex);
7446 encoder = amdgpu_dm_connector_to_encoder(connector);
7450 amdgpu_encoder = to_amdgpu_encoder(encoder);
7452 native_mode = &amdgpu_encoder->native_mode;
7453 if (native_mode->hdisplay == 0 || native_mode->vdisplay == 0)
7456 drm_connector_set_panel_orientation_with_quirk(connector,
7457 DRM_MODE_PANEL_ORIENTATION_UNKNOWN,
7458 native_mode->hdisplay,
7459 native_mode->vdisplay);
7462 static void amdgpu_dm_connector_ddc_get_modes(struct drm_connector *connector,
7465 struct amdgpu_dm_connector *amdgpu_dm_connector =
7466 to_amdgpu_dm_connector(connector);
7469 /* empty probed_modes */
7470 INIT_LIST_HEAD(&connector->probed_modes);
7471 amdgpu_dm_connector->num_modes =
7472 drm_add_edid_modes(connector, edid);
7474 /* sorting the probed modes before calling function
7475 * amdgpu_dm_get_native_mode() since EDID can have
7476 * more than one preferred mode. The modes that are
7477 * later in the probed mode list could be of higher
7478 * and preferred resolution. For example, 3840x2160
7479 * resolution in base EDID preferred timing and 4096x2160
7480 * preferred resolution in DID extension block later.
7482 drm_mode_sort(&connector->probed_modes);
7483 amdgpu_dm_get_native_mode(connector);
7485 /* Freesync capabilities are reset by calling
7486 * drm_add_edid_modes() and need to be
7489 amdgpu_dm_update_freesync_caps(connector, edid);
7491 amdgpu_dm_connector->num_modes = 0;
7495 static bool is_duplicate_mode(struct amdgpu_dm_connector *aconnector,
7496 struct drm_display_mode *mode)
7498 struct drm_display_mode *m;
7500 list_for_each_entry(m, &aconnector->base.probed_modes, head) {
7501 if (drm_mode_equal(m, mode))
7508 static uint add_fs_modes(struct amdgpu_dm_connector *aconnector)
7510 const struct drm_display_mode *m;
7511 struct drm_display_mode *new_mode;
7513 u32 new_modes_count = 0;
7515 /* Standard FPS values
7524 * 60 - Commonly used
7525 * 48,72,96,120 - Multiples of 24
7527 static const u32 common_rates[] = {
7528 23976, 24000, 25000, 29970, 30000,
7529 48000, 50000, 60000, 72000, 96000, 120000
7533 * Find mode with highest refresh rate with the same resolution
7534 * as the preferred mode. Some monitors report a preferred mode
7535 * with lower resolution than the highest refresh rate supported.
7538 m = get_highest_refresh_rate_mode(aconnector, true);
7542 for (i = 0; i < ARRAY_SIZE(common_rates); i++) {
7543 u64 target_vtotal, target_vtotal_diff;
7546 if (drm_mode_vrefresh(m) * 1000 < common_rates[i])
7549 if (common_rates[i] < aconnector->min_vfreq * 1000 ||
7550 common_rates[i] > aconnector->max_vfreq * 1000)
7553 num = (unsigned long long)m->clock * 1000 * 1000;
7554 den = common_rates[i] * (unsigned long long)m->htotal;
7555 target_vtotal = div_u64(num, den);
7556 target_vtotal_diff = target_vtotal - m->vtotal;
7558 /* Check for illegal modes */
7559 if (m->vsync_start + target_vtotal_diff < m->vdisplay ||
7560 m->vsync_end + target_vtotal_diff < m->vsync_start ||
7561 m->vtotal + target_vtotal_diff < m->vsync_end)
7564 new_mode = drm_mode_duplicate(aconnector->base.dev, m);
7568 new_mode->vtotal += (u16)target_vtotal_diff;
7569 new_mode->vsync_start += (u16)target_vtotal_diff;
7570 new_mode->vsync_end += (u16)target_vtotal_diff;
7571 new_mode->type &= ~DRM_MODE_TYPE_PREFERRED;
7572 new_mode->type |= DRM_MODE_TYPE_DRIVER;
7574 if (!is_duplicate_mode(aconnector, new_mode)) {
7575 drm_mode_probed_add(&aconnector->base, new_mode);
7576 new_modes_count += 1;
7578 drm_mode_destroy(aconnector->base.dev, new_mode);
7581 return new_modes_count;
7584 static void amdgpu_dm_connector_add_freesync_modes(struct drm_connector *connector,
7587 struct amdgpu_dm_connector *amdgpu_dm_connector =
7588 to_amdgpu_dm_connector(connector);
7590 if (!(amdgpu_freesync_vid_mode && edid))
7593 if (amdgpu_dm_connector->max_vfreq - amdgpu_dm_connector->min_vfreq > 10)
7594 amdgpu_dm_connector->num_modes +=
7595 add_fs_modes(amdgpu_dm_connector);
7598 static int amdgpu_dm_connector_get_modes(struct drm_connector *connector)
7600 struct amdgpu_dm_connector *amdgpu_dm_connector =
7601 to_amdgpu_dm_connector(connector);
7602 struct drm_encoder *encoder;
7603 struct edid *edid = amdgpu_dm_connector->edid;
7604 struct dc_link_settings *verified_link_cap =
7605 &amdgpu_dm_connector->dc_link->verified_link_cap;
7606 const struct dc *dc = amdgpu_dm_connector->dc_link->dc;
7608 encoder = amdgpu_dm_connector_to_encoder(connector);
7610 if (!drm_edid_is_valid(edid)) {
7611 amdgpu_dm_connector->num_modes =
7612 drm_add_modes_noedid(connector, 640, 480);
7613 if (dc->link_srv->dp_get_encoding_format(verified_link_cap) == DP_128b_132b_ENCODING)
7614 amdgpu_dm_connector->num_modes +=
7615 drm_add_modes_noedid(connector, 1920, 1080);
7617 amdgpu_dm_connector_ddc_get_modes(connector, edid);
7618 amdgpu_dm_connector_add_common_modes(encoder, connector);
7619 amdgpu_dm_connector_add_freesync_modes(connector, edid);
7621 amdgpu_dm_fbc_init(connector);
7623 return amdgpu_dm_connector->num_modes;
7626 static const u32 supported_colorspaces =
7627 BIT(DRM_MODE_COLORIMETRY_BT709_YCC) |
7628 BIT(DRM_MODE_COLORIMETRY_OPRGB) |
7629 BIT(DRM_MODE_COLORIMETRY_BT2020_RGB) |
7630 BIT(DRM_MODE_COLORIMETRY_BT2020_YCC);
7632 void amdgpu_dm_connector_init_helper(struct amdgpu_display_manager *dm,
7633 struct amdgpu_dm_connector *aconnector,
7635 struct dc_link *link,
7638 struct amdgpu_device *adev = drm_to_adev(dm->ddev);
7641 * Some of the properties below require access to state, like bpc.
7642 * Allocate some default initial connector state with our reset helper.
7644 if (aconnector->base.funcs->reset)
7645 aconnector->base.funcs->reset(&aconnector->base);
7647 aconnector->connector_id = link_index;
7648 aconnector->bl_idx = -1;
7649 aconnector->dc_link = link;
7650 aconnector->base.interlace_allowed = false;
7651 aconnector->base.doublescan_allowed = false;
7652 aconnector->base.stereo_allowed = false;
7653 aconnector->base.dpms = DRM_MODE_DPMS_OFF;
7654 aconnector->hpd.hpd = AMDGPU_HPD_NONE; /* not used */
7655 aconnector->audio_inst = -1;
7656 aconnector->pack_sdp_v1_3 = false;
7657 aconnector->as_type = ADAPTIVE_SYNC_TYPE_NONE;
7658 memset(&aconnector->vsdb_info, 0, sizeof(aconnector->vsdb_info));
7659 mutex_init(&aconnector->hpd_lock);
7660 mutex_init(&aconnector->handle_mst_msg_ready);
7663 * configure support HPD hot plug connector_>polled default value is 0
7664 * which means HPD hot plug not supported
7666 switch (connector_type) {
7667 case DRM_MODE_CONNECTOR_HDMIA:
7668 aconnector->base.polled = DRM_CONNECTOR_POLL_HPD;
7669 aconnector->base.ycbcr_420_allowed =
7670 link->link_enc->features.hdmi_ycbcr420_supported ? true : false;
7672 case DRM_MODE_CONNECTOR_DisplayPort:
7673 aconnector->base.polled = DRM_CONNECTOR_POLL_HPD;
7674 link->link_enc = link_enc_cfg_get_link_enc(link);
7675 ASSERT(link->link_enc);
7677 aconnector->base.ycbcr_420_allowed =
7678 link->link_enc->features.dp_ycbcr420_supported ? true : false;
7680 case DRM_MODE_CONNECTOR_DVID:
7681 aconnector->base.polled = DRM_CONNECTOR_POLL_HPD;
7687 drm_object_attach_property(&aconnector->base.base,
7688 dm->ddev->mode_config.scaling_mode_property,
7689 DRM_MODE_SCALE_NONE);
7691 drm_object_attach_property(&aconnector->base.base,
7692 adev->mode_info.underscan_property,
7694 drm_object_attach_property(&aconnector->base.base,
7695 adev->mode_info.underscan_hborder_property,
7697 drm_object_attach_property(&aconnector->base.base,
7698 adev->mode_info.underscan_vborder_property,
7701 if (!aconnector->mst_root)
7702 drm_connector_attach_max_bpc_property(&aconnector->base, 8, 16);
7704 aconnector->base.state->max_bpc = 16;
7705 aconnector->base.state->max_requested_bpc = aconnector->base.state->max_bpc;
7707 if (connector_type == DRM_MODE_CONNECTOR_HDMIA) {
7708 /* Content Type is currently only implemented for HDMI. */
7709 drm_connector_attach_content_type_property(&aconnector->base);
7712 if (connector_type == DRM_MODE_CONNECTOR_HDMIA) {
7713 if (!drm_mode_create_hdmi_colorspace_property(&aconnector->base, supported_colorspaces))
7714 drm_connector_attach_colorspace_property(&aconnector->base);
7715 } else if ((connector_type == DRM_MODE_CONNECTOR_DisplayPort && !aconnector->mst_root) ||
7716 connector_type == DRM_MODE_CONNECTOR_eDP) {
7717 if (!drm_mode_create_dp_colorspace_property(&aconnector->base, supported_colorspaces))
7718 drm_connector_attach_colorspace_property(&aconnector->base);
7721 if (connector_type == DRM_MODE_CONNECTOR_HDMIA ||
7722 connector_type == DRM_MODE_CONNECTOR_DisplayPort ||
7723 connector_type == DRM_MODE_CONNECTOR_eDP) {
7724 drm_connector_attach_hdr_output_metadata_property(&aconnector->base);
7726 if (!aconnector->mst_root)
7727 drm_connector_attach_vrr_capable_property(&aconnector->base);
7729 if (adev->dm.hdcp_workqueue)
7730 drm_connector_attach_content_protection_property(&aconnector->base, true);
7734 static int amdgpu_dm_i2c_xfer(struct i2c_adapter *i2c_adap,
7735 struct i2c_msg *msgs, int num)
7737 struct amdgpu_i2c_adapter *i2c = i2c_get_adapdata(i2c_adap);
7738 struct ddc_service *ddc_service = i2c->ddc_service;
7739 struct i2c_command cmd;
7743 if (!ddc_service->ddc_pin || !ddc_service->ddc_pin->hw_info.hw_supported)
7746 cmd.payloads = kcalloc(num, sizeof(struct i2c_payload), GFP_KERNEL);
7751 cmd.number_of_payloads = num;
7752 cmd.engine = I2C_COMMAND_ENGINE_DEFAULT;
7755 for (i = 0; i < num; i++) {
7756 cmd.payloads[i].write = !(msgs[i].flags & I2C_M_RD);
7757 cmd.payloads[i].address = msgs[i].addr;
7758 cmd.payloads[i].length = msgs[i].len;
7759 cmd.payloads[i].data = msgs[i].buf;
7763 ddc_service->ctx->dc,
7764 ddc_service->link->link_index,
7768 kfree(cmd.payloads);
7772 static u32 amdgpu_dm_i2c_func(struct i2c_adapter *adap)
7774 return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL;
7777 static const struct i2c_algorithm amdgpu_dm_i2c_algo = {
7778 .master_xfer = amdgpu_dm_i2c_xfer,
7779 .functionality = amdgpu_dm_i2c_func,
7782 static struct amdgpu_i2c_adapter *
7783 create_i2c(struct ddc_service *ddc_service,
7787 struct amdgpu_device *adev = ddc_service->ctx->driver_context;
7788 struct amdgpu_i2c_adapter *i2c;
7790 i2c = kzalloc(sizeof(struct amdgpu_i2c_adapter), GFP_KERNEL);
7793 i2c->base.owner = THIS_MODULE;
7794 i2c->base.dev.parent = &adev->pdev->dev;
7795 i2c->base.algo = &amdgpu_dm_i2c_algo;
7796 snprintf(i2c->base.name, sizeof(i2c->base.name), "AMDGPU DM i2c hw bus %d", link_index);
7797 i2c_set_adapdata(&i2c->base, i2c);
7798 i2c->ddc_service = ddc_service;
7805 * Note: this function assumes that dc_link_detect() was called for the
7806 * dc_link which will be represented by this aconnector.
7808 static int amdgpu_dm_connector_init(struct amdgpu_display_manager *dm,
7809 struct amdgpu_dm_connector *aconnector,
7811 struct amdgpu_encoder *aencoder)
7815 struct dc *dc = dm->dc;
7816 struct dc_link *link = dc_get_link_at_index(dc, link_index);
7817 struct amdgpu_i2c_adapter *i2c;
7819 /* Not needed for writeback connector */
7820 link->priv = aconnector;
7823 i2c = create_i2c(link->ddc, link->link_index, &res);
7825 DRM_ERROR("Failed to create i2c adapter data\n");
7829 aconnector->i2c = i2c;
7830 res = i2c_add_adapter(&i2c->base);
7833 DRM_ERROR("Failed to register hw i2c %d\n", link->link_index);
7837 connector_type = to_drm_connector_type(link->connector_signal);
7839 res = drm_connector_init_with_ddc(
7842 &amdgpu_dm_connector_funcs,
7847 DRM_ERROR("connector_init failed\n");
7848 aconnector->connector_id = -1;
7852 drm_connector_helper_add(
7854 &amdgpu_dm_connector_helper_funcs);
7856 amdgpu_dm_connector_init_helper(
7863 drm_connector_attach_encoder(
7864 &aconnector->base, &aencoder->base);
7866 if (connector_type == DRM_MODE_CONNECTOR_DisplayPort
7867 || connector_type == DRM_MODE_CONNECTOR_eDP)
7868 amdgpu_dm_initialize_dp_connector(dm, aconnector, link->link_index);
7873 aconnector->i2c = NULL;
7878 int amdgpu_dm_get_encoder_crtc_mask(struct amdgpu_device *adev)
7880 switch (adev->mode_info.num_crtc) {
7897 static int amdgpu_dm_encoder_init(struct drm_device *dev,
7898 struct amdgpu_encoder *aencoder,
7899 uint32_t link_index)
7901 struct amdgpu_device *adev = drm_to_adev(dev);
7903 int res = drm_encoder_init(dev,
7905 &amdgpu_dm_encoder_funcs,
7906 DRM_MODE_ENCODER_TMDS,
7909 aencoder->base.possible_crtcs = amdgpu_dm_get_encoder_crtc_mask(adev);
7912 aencoder->encoder_id = link_index;
7914 aencoder->encoder_id = -1;
7916 drm_encoder_helper_add(&aencoder->base, &amdgpu_dm_encoder_helper_funcs);
7921 static void manage_dm_interrupts(struct amdgpu_device *adev,
7922 struct amdgpu_crtc *acrtc,
7926 * We have no guarantee that the frontend index maps to the same
7927 * backend index - some even map to more than one.
7929 * TODO: Use a different interrupt or check DC itself for the mapping.
7932 amdgpu_display_crtc_idx_to_irq_type(
7937 drm_crtc_vblank_on(&acrtc->base);
7940 &adev->pageflip_irq,
7942 #if defined(CONFIG_DRM_AMD_SECURE_DISPLAY)
7949 #if defined(CONFIG_DRM_AMD_SECURE_DISPLAY)
7957 &adev->pageflip_irq,
7959 drm_crtc_vblank_off(&acrtc->base);
7963 static void dm_update_pflip_irq_state(struct amdgpu_device *adev,
7964 struct amdgpu_crtc *acrtc)
7967 amdgpu_display_crtc_idx_to_irq_type(adev, acrtc->crtc_id);
7970 * This reads the current state for the IRQ and force reapplies
7971 * the setting to hardware.
7973 amdgpu_irq_update(adev, &adev->pageflip_irq, irq_type);
7977 is_scaling_state_different(const struct dm_connector_state *dm_state,
7978 const struct dm_connector_state *old_dm_state)
7980 if (dm_state->scaling != old_dm_state->scaling)
7982 if (!dm_state->underscan_enable && old_dm_state->underscan_enable) {
7983 if (old_dm_state->underscan_hborder != 0 && old_dm_state->underscan_vborder != 0)
7985 } else if (dm_state->underscan_enable && !old_dm_state->underscan_enable) {
7986 if (dm_state->underscan_hborder != 0 && dm_state->underscan_vborder != 0)
7988 } else if (dm_state->underscan_hborder != old_dm_state->underscan_hborder ||
7989 dm_state->underscan_vborder != old_dm_state->underscan_vborder)
7994 static bool is_content_protection_different(struct drm_crtc_state *new_crtc_state,
7995 struct drm_crtc_state *old_crtc_state,
7996 struct drm_connector_state *new_conn_state,
7997 struct drm_connector_state *old_conn_state,
7998 const struct drm_connector *connector,
7999 struct hdcp_workqueue *hdcp_w)
8001 struct amdgpu_dm_connector *aconnector = to_amdgpu_dm_connector(connector);
8002 struct dm_connector_state *dm_con_state = to_dm_connector_state(connector->state);
8004 pr_debug("[HDCP_DM] connector->index: %x connect_status: %x dpms: %x\n",
8005 connector->index, connector->status, connector->dpms);
8006 pr_debug("[HDCP_DM] state protection old: %x new: %x\n",
8007 old_conn_state->content_protection, new_conn_state->content_protection);
8010 pr_debug("[HDCP_DM] old crtc en: %x a: %x m: %x a-chg: %x c-chg: %x\n",
8011 old_crtc_state->enable,
8012 old_crtc_state->active,
8013 old_crtc_state->mode_changed,
8014 old_crtc_state->active_changed,
8015 old_crtc_state->connectors_changed);
8018 pr_debug("[HDCP_DM] NEW crtc en: %x a: %x m: %x a-chg: %x c-chg: %x\n",
8019 new_crtc_state->enable,
8020 new_crtc_state->active,
8021 new_crtc_state->mode_changed,
8022 new_crtc_state->active_changed,
8023 new_crtc_state->connectors_changed);
8025 /* hdcp content type change */
8026 if (old_conn_state->hdcp_content_type != new_conn_state->hdcp_content_type &&
8027 new_conn_state->content_protection != DRM_MODE_CONTENT_PROTECTION_UNDESIRED) {
8028 new_conn_state->content_protection = DRM_MODE_CONTENT_PROTECTION_DESIRED;
8029 pr_debug("[HDCP_DM] Type0/1 change %s :true\n", __func__);
8033 /* CP is being re enabled, ignore this */
8034 if (old_conn_state->content_protection == DRM_MODE_CONTENT_PROTECTION_ENABLED &&
8035 new_conn_state->content_protection == DRM_MODE_CONTENT_PROTECTION_DESIRED) {
8036 if (new_crtc_state && new_crtc_state->mode_changed) {
8037 new_conn_state->content_protection = DRM_MODE_CONTENT_PROTECTION_DESIRED;
8038 pr_debug("[HDCP_DM] ENABLED->DESIRED & mode_changed %s :true\n", __func__);
8041 new_conn_state->content_protection = DRM_MODE_CONTENT_PROTECTION_ENABLED;
8042 pr_debug("[HDCP_DM] ENABLED -> DESIRED %s :false\n", __func__);
8046 /* S3 resume case, since old state will always be 0 (UNDESIRED) and the restored state will be ENABLED
8048 * Handles: UNDESIRED -> ENABLED
8050 if (old_conn_state->content_protection == DRM_MODE_CONTENT_PROTECTION_UNDESIRED &&
8051 new_conn_state->content_protection == DRM_MODE_CONTENT_PROTECTION_ENABLED)
8052 new_conn_state->content_protection = DRM_MODE_CONTENT_PROTECTION_DESIRED;
8054 /* Stream removed and re-enabled
8056 * Can sometimes overlap with the HPD case,
8057 * thus set update_hdcp to false to avoid
8058 * setting HDCP multiple times.
8060 * Handles: DESIRED -> DESIRED (Special case)
8062 if (!(old_conn_state->crtc && old_conn_state->crtc->enabled) &&
8063 new_conn_state->crtc && new_conn_state->crtc->enabled &&
8064 connector->state->content_protection == DRM_MODE_CONTENT_PROTECTION_DESIRED) {
8065 dm_con_state->update_hdcp = false;
8066 pr_debug("[HDCP_DM] DESIRED->DESIRED (Stream removed and re-enabled) %s :true\n",
8071 /* Hot-plug, headless s3, dpms
8073 * Only start HDCP if the display is connected/enabled.
8074 * update_hdcp flag will be set to false until the next
8077 * Handles: DESIRED -> DESIRED (Special case)
8079 if (dm_con_state->update_hdcp &&
8080 new_conn_state->content_protection == DRM_MODE_CONTENT_PROTECTION_DESIRED &&
8081 connector->dpms == DRM_MODE_DPMS_ON && aconnector->dc_sink != NULL) {
8082 dm_con_state->update_hdcp = false;
8083 pr_debug("[HDCP_DM] DESIRED->DESIRED (Hot-plug, headless s3, dpms) %s :true\n",
8088 if (old_conn_state->content_protection == new_conn_state->content_protection) {
8089 if (new_conn_state->content_protection >= DRM_MODE_CONTENT_PROTECTION_DESIRED) {
8090 if (new_crtc_state && new_crtc_state->mode_changed) {
8091 pr_debug("[HDCP_DM] DESIRED->DESIRED or ENABLE->ENABLE mode_change %s :true\n",
8095 pr_debug("[HDCP_DM] DESIRED->DESIRED & ENABLE->ENABLE %s :false\n",
8100 pr_debug("[HDCP_DM] UNDESIRED->UNDESIRED %s :false\n", __func__);
8104 if (new_conn_state->content_protection != DRM_MODE_CONTENT_PROTECTION_ENABLED) {
8105 pr_debug("[HDCP_DM] UNDESIRED->DESIRED or DESIRED->UNDESIRED or ENABLED->UNDESIRED %s :true\n",
8110 pr_debug("[HDCP_DM] DESIRED->ENABLED %s :false\n", __func__);
8114 static void remove_stream(struct amdgpu_device *adev,
8115 struct amdgpu_crtc *acrtc,
8116 struct dc_stream_state *stream)
8118 /* this is the update mode case */
8120 acrtc->otg_inst = -1;
8121 acrtc->enabled = false;
8124 static void prepare_flip_isr(struct amdgpu_crtc *acrtc)
8127 assert_spin_locked(&acrtc->base.dev->event_lock);
8128 WARN_ON(acrtc->event);
8130 acrtc->event = acrtc->base.state->event;
8132 /* Set the flip status */
8133 acrtc->pflip_status = AMDGPU_FLIP_SUBMITTED;
8135 /* Mark this event as consumed */
8136 acrtc->base.state->event = NULL;
8138 drm_dbg_state(acrtc->base.dev,
8139 "crtc:%d, pflip_stat:AMDGPU_FLIP_SUBMITTED\n",
8143 static void update_freesync_state_on_stream(
8144 struct amdgpu_display_manager *dm,
8145 struct dm_crtc_state *new_crtc_state,
8146 struct dc_stream_state *new_stream,
8147 struct dc_plane_state *surface,
8148 u32 flip_timestamp_in_us)
8150 struct mod_vrr_params vrr_params;
8151 struct dc_info_packet vrr_infopacket = {0};
8152 struct amdgpu_device *adev = dm->adev;
8153 struct amdgpu_crtc *acrtc = to_amdgpu_crtc(new_crtc_state->base.crtc);
8154 unsigned long flags;
8155 bool pack_sdp_v1_3 = false;
8156 struct amdgpu_dm_connector *aconn;
8157 enum vrr_packet_type packet_type = PACKET_TYPE_VRR;
8163 * TODO: Determine why min/max totals and vrefresh can be 0 here.
8164 * For now it's sufficient to just guard against these conditions.
8167 if (!new_stream->timing.h_total || !new_stream->timing.v_total)
8170 spin_lock_irqsave(&adev_to_drm(adev)->event_lock, flags);
8171 vrr_params = acrtc->dm_irq_params.vrr_params;
8174 mod_freesync_handle_preflip(
8175 dm->freesync_module,
8178 flip_timestamp_in_us,
8181 if (adev->family < AMDGPU_FAMILY_AI &&
8182 amdgpu_dm_crtc_vrr_active(new_crtc_state)) {
8183 mod_freesync_handle_v_update(dm->freesync_module,
8184 new_stream, &vrr_params);
8186 /* Need to call this before the frame ends. */
8187 dc_stream_adjust_vmin_vmax(dm->dc,
8188 new_crtc_state->stream,
8189 &vrr_params.adjust);
8193 aconn = (struct amdgpu_dm_connector *)new_stream->dm_stream_context;
8195 if (aconn && (aconn->as_type == FREESYNC_TYPE_PCON_IN_WHITELIST || aconn->vsdb_info.replay_mode)) {
8196 pack_sdp_v1_3 = aconn->pack_sdp_v1_3;
8198 if (aconn->vsdb_info.amd_vsdb_version == 1)
8199 packet_type = PACKET_TYPE_FS_V1;
8200 else if (aconn->vsdb_info.amd_vsdb_version == 2)
8201 packet_type = PACKET_TYPE_FS_V2;
8202 else if (aconn->vsdb_info.amd_vsdb_version == 3)
8203 packet_type = PACKET_TYPE_FS_V3;
8205 mod_build_adaptive_sync_infopacket(new_stream, aconn->as_type, NULL,
8206 &new_stream->adaptive_sync_infopacket);
8209 mod_freesync_build_vrr_infopacket(
8210 dm->freesync_module,
8214 TRANSFER_FUNC_UNKNOWN,
8218 new_crtc_state->freesync_vrr_info_changed |=
8219 (memcmp(&new_crtc_state->vrr_infopacket,
8221 sizeof(vrr_infopacket)) != 0);
8223 acrtc->dm_irq_params.vrr_params = vrr_params;
8224 new_crtc_state->vrr_infopacket = vrr_infopacket;
8226 new_stream->vrr_infopacket = vrr_infopacket;
8227 new_stream->allow_freesync = mod_freesync_get_freesync_enabled(&vrr_params);
8229 if (new_crtc_state->freesync_vrr_info_changed)
8230 DRM_DEBUG_KMS("VRR packet update: crtc=%u enabled=%d state=%d",
8231 new_crtc_state->base.crtc->base.id,
8232 (int)new_crtc_state->base.vrr_enabled,
8233 (int)vrr_params.state);
8235 spin_unlock_irqrestore(&adev_to_drm(adev)->event_lock, flags);
8238 static void update_stream_irq_parameters(
8239 struct amdgpu_display_manager *dm,
8240 struct dm_crtc_state *new_crtc_state)
8242 struct dc_stream_state *new_stream = new_crtc_state->stream;
8243 struct mod_vrr_params vrr_params;
8244 struct mod_freesync_config config = new_crtc_state->freesync_config;
8245 struct amdgpu_device *adev = dm->adev;
8246 struct amdgpu_crtc *acrtc = to_amdgpu_crtc(new_crtc_state->base.crtc);
8247 unsigned long flags;
8253 * TODO: Determine why min/max totals and vrefresh can be 0 here.
8254 * For now it's sufficient to just guard against these conditions.
8256 if (!new_stream->timing.h_total || !new_stream->timing.v_total)
8259 spin_lock_irqsave(&adev_to_drm(adev)->event_lock, flags);
8260 vrr_params = acrtc->dm_irq_params.vrr_params;
8262 if (new_crtc_state->vrr_supported &&
8263 config.min_refresh_in_uhz &&
8264 config.max_refresh_in_uhz) {
8266 * if freesync compatible mode was set, config.state will be set
8269 if (config.state == VRR_STATE_ACTIVE_FIXED && config.fixed_refresh_in_uhz &&
8270 (!drm_atomic_crtc_needs_modeset(&new_crtc_state->base) ||
8271 new_crtc_state->freesync_config.state == VRR_STATE_ACTIVE_FIXED)) {
8272 vrr_params.max_refresh_in_uhz = config.max_refresh_in_uhz;
8273 vrr_params.min_refresh_in_uhz = config.min_refresh_in_uhz;
8274 vrr_params.fixed_refresh_in_uhz = config.fixed_refresh_in_uhz;
8275 vrr_params.state = VRR_STATE_ACTIVE_FIXED;
8277 config.state = new_crtc_state->base.vrr_enabled ?
8278 VRR_STATE_ACTIVE_VARIABLE :
8282 config.state = VRR_STATE_UNSUPPORTED;
8285 mod_freesync_build_vrr_params(dm->freesync_module,
8287 &config, &vrr_params);
8289 new_crtc_state->freesync_config = config;
8290 /* Copy state for access from DM IRQ handler */
8291 acrtc->dm_irq_params.freesync_config = config;
8292 acrtc->dm_irq_params.active_planes = new_crtc_state->active_planes;
8293 acrtc->dm_irq_params.vrr_params = vrr_params;
8294 spin_unlock_irqrestore(&adev_to_drm(adev)->event_lock, flags);
8297 static void amdgpu_dm_handle_vrr_transition(struct dm_crtc_state *old_state,
8298 struct dm_crtc_state *new_state)
8300 bool old_vrr_active = amdgpu_dm_crtc_vrr_active(old_state);
8301 bool new_vrr_active = amdgpu_dm_crtc_vrr_active(new_state);
8303 if (!old_vrr_active && new_vrr_active) {
8304 /* Transition VRR inactive -> active:
8305 * While VRR is active, we must not disable vblank irq, as a
8306 * reenable after disable would compute bogus vblank/pflip
8307 * timestamps if it likely happened inside display front-porch.
8309 * We also need vupdate irq for the actual core vblank handling
8312 WARN_ON(amdgpu_dm_crtc_set_vupdate_irq(new_state->base.crtc, true) != 0);
8313 WARN_ON(drm_crtc_vblank_get(new_state->base.crtc) != 0);
8314 DRM_DEBUG_DRIVER("%s: crtc=%u VRR off->on: Get vblank ref\n",
8315 __func__, new_state->base.crtc->base.id);
8316 } else if (old_vrr_active && !new_vrr_active) {
8317 /* Transition VRR active -> inactive:
8318 * Allow vblank irq disable again for fixed refresh rate.
8320 WARN_ON(amdgpu_dm_crtc_set_vupdate_irq(new_state->base.crtc, false) != 0);
8321 drm_crtc_vblank_put(new_state->base.crtc);
8322 DRM_DEBUG_DRIVER("%s: crtc=%u VRR on->off: Drop vblank ref\n",
8323 __func__, new_state->base.crtc->base.id);
8327 static void amdgpu_dm_commit_cursors(struct drm_atomic_state *state)
8329 struct drm_plane *plane;
8330 struct drm_plane_state *old_plane_state;
8334 * TODO: Make this per-stream so we don't issue redundant updates for
8335 * commits with multiple streams.
8337 for_each_old_plane_in_state(state, plane, old_plane_state, i)
8338 if (plane->type == DRM_PLANE_TYPE_CURSOR)
8339 amdgpu_dm_plane_handle_cursor_update(plane, old_plane_state);
8342 static inline uint32_t get_mem_type(struct drm_framebuffer *fb)
8344 struct amdgpu_bo *abo = gem_to_amdgpu_bo(fb->obj[0]);
8346 return abo->tbo.resource ? abo->tbo.resource->mem_type : 0;
8349 static void amdgpu_dm_commit_planes(struct drm_atomic_state *state,
8350 struct drm_device *dev,
8351 struct amdgpu_display_manager *dm,
8352 struct drm_crtc *pcrtc,
8353 bool wait_for_vblank)
8356 u64 timestamp_ns = ktime_get_ns();
8357 struct drm_plane *plane;
8358 struct drm_plane_state *old_plane_state, *new_plane_state;
8359 struct amdgpu_crtc *acrtc_attach = to_amdgpu_crtc(pcrtc);
8360 struct drm_crtc_state *new_pcrtc_state =
8361 drm_atomic_get_new_crtc_state(state, pcrtc);
8362 struct dm_crtc_state *acrtc_state = to_dm_crtc_state(new_pcrtc_state);
8363 struct dm_crtc_state *dm_old_crtc_state =
8364 to_dm_crtc_state(drm_atomic_get_old_crtc_state(state, pcrtc));
8365 int planes_count = 0, vpos, hpos;
8366 unsigned long flags;
8367 u32 target_vblank, last_flip_vblank;
8368 bool vrr_active = amdgpu_dm_crtc_vrr_active(acrtc_state);
8369 bool cursor_update = false;
8370 bool pflip_present = false;
8371 bool dirty_rects_changed = false;
8373 struct dc_surface_update surface_updates[MAX_SURFACES];
8374 struct dc_plane_info plane_infos[MAX_SURFACES];
8375 struct dc_scaling_info scaling_infos[MAX_SURFACES];
8376 struct dc_flip_addrs flip_addrs[MAX_SURFACES];
8377 struct dc_stream_update stream_update;
8380 bundle = kzalloc(sizeof(*bundle), GFP_KERNEL);
8383 drm_err(dev, "Failed to allocate update bundle\n");
8388 * Disable the cursor first if we're disabling all the planes.
8389 * It'll remain on the screen after the planes are re-enabled
8392 if (acrtc_state->active_planes == 0)
8393 amdgpu_dm_commit_cursors(state);
8395 /* update planes when needed */
8396 for_each_oldnew_plane_in_state(state, plane, old_plane_state, new_plane_state, i) {
8397 struct drm_crtc *crtc = new_plane_state->crtc;
8398 struct drm_crtc_state *new_crtc_state;
8399 struct drm_framebuffer *fb = new_plane_state->fb;
8400 struct amdgpu_framebuffer *afb = (struct amdgpu_framebuffer *)fb;
8401 bool plane_needs_flip;
8402 struct dc_plane_state *dc_plane;
8403 struct dm_plane_state *dm_new_plane_state = to_dm_plane_state(new_plane_state);
8405 /* Cursor plane is handled after stream updates */
8406 if (plane->type == DRM_PLANE_TYPE_CURSOR) {
8407 if ((fb && crtc == pcrtc) ||
8408 (old_plane_state->fb && old_plane_state->crtc == pcrtc))
8409 cursor_update = true;
8414 if (!fb || !crtc || pcrtc != crtc)
8417 new_crtc_state = drm_atomic_get_new_crtc_state(state, crtc);
8418 if (!new_crtc_state->active)
8421 dc_plane = dm_new_plane_state->dc_state;
8425 bundle->surface_updates[planes_count].surface = dc_plane;
8426 if (new_pcrtc_state->color_mgmt_changed) {
8427 bundle->surface_updates[planes_count].gamma = &dc_plane->gamma_correction;
8428 bundle->surface_updates[planes_count].in_transfer_func = &dc_plane->in_transfer_func;
8429 bundle->surface_updates[planes_count].gamut_remap_matrix = &dc_plane->gamut_remap_matrix;
8430 bundle->surface_updates[planes_count].hdr_mult = dc_plane->hdr_mult;
8431 bundle->surface_updates[planes_count].func_shaper = &dc_plane->in_shaper_func;
8432 bundle->surface_updates[planes_count].lut3d_func = &dc_plane->lut3d_func;
8433 bundle->surface_updates[planes_count].blend_tf = &dc_plane->blend_tf;
8436 amdgpu_dm_plane_fill_dc_scaling_info(dm->adev, new_plane_state,
8437 &bundle->scaling_infos[planes_count]);
8439 bundle->surface_updates[planes_count].scaling_info =
8440 &bundle->scaling_infos[planes_count];
8442 plane_needs_flip = old_plane_state->fb && new_plane_state->fb;
8444 pflip_present = pflip_present || plane_needs_flip;
8446 if (!plane_needs_flip) {
8451 fill_dc_plane_info_and_addr(
8452 dm->adev, new_plane_state,
8454 &bundle->plane_infos[planes_count],
8455 &bundle->flip_addrs[planes_count].address,
8456 afb->tmz_surface, false);
8458 drm_dbg_state(state->dev, "plane: id=%d dcc_en=%d\n",
8459 new_plane_state->plane->index,
8460 bundle->plane_infos[planes_count].dcc.enable);
8462 bundle->surface_updates[planes_count].plane_info =
8463 &bundle->plane_infos[planes_count];
8465 if (acrtc_state->stream->link->psr_settings.psr_feature_enabled ||
8466 acrtc_state->stream->link->replay_settings.replay_feature_enabled) {
8467 fill_dc_dirty_rects(plane, old_plane_state,
8468 new_plane_state, new_crtc_state,
8469 &bundle->flip_addrs[planes_count],
8470 acrtc_state->stream->link->psr_settings.psr_version ==
8471 DC_PSR_VERSION_SU_1,
8472 &dirty_rects_changed);
8475 * If the dirty regions changed, PSR-SU need to be disabled temporarily
8476 * and enabled it again after dirty regions are stable to avoid video glitch.
8477 * PSR-SU will be enabled in vblank_control_worker() if user pause the video
8478 * during the PSR-SU was disabled.
8480 if (acrtc_state->stream->link->psr_settings.psr_version >= DC_PSR_VERSION_SU_1 &&
8481 acrtc_attach->dm_irq_params.allow_psr_entry &&
8482 #ifdef CONFIG_DRM_AMD_SECURE_DISPLAY
8483 !amdgpu_dm_crc_window_is_activated(acrtc_state->base.crtc) &&
8485 dirty_rects_changed) {
8486 mutex_lock(&dm->dc_lock);
8487 acrtc_state->stream->link->psr_settings.psr_dirty_rects_change_timestamp_ns =
8489 if (acrtc_state->stream->link->psr_settings.psr_allow_active)
8490 amdgpu_dm_psr_disable(acrtc_state->stream);
8491 mutex_unlock(&dm->dc_lock);
8496 * Only allow immediate flips for fast updates that don't
8497 * change memory domain, FB pitch, DCC state, rotation or
8500 * dm_crtc_helper_atomic_check() only accepts async flips with
8503 if (crtc->state->async_flip &&
8504 (acrtc_state->update_type != UPDATE_TYPE_FAST ||
8505 get_mem_type(old_plane_state->fb) != get_mem_type(fb)))
8506 drm_warn_once(state->dev,
8507 "[PLANE:%d:%s] async flip with non-fast update\n",
8508 plane->base.id, plane->name);
8510 bundle->flip_addrs[planes_count].flip_immediate =
8511 crtc->state->async_flip &&
8512 acrtc_state->update_type == UPDATE_TYPE_FAST &&
8513 get_mem_type(old_plane_state->fb) == get_mem_type(fb);
8515 timestamp_ns = ktime_get_ns();
8516 bundle->flip_addrs[planes_count].flip_timestamp_in_us = div_u64(timestamp_ns, 1000);
8517 bundle->surface_updates[planes_count].flip_addr = &bundle->flip_addrs[planes_count];
8518 bundle->surface_updates[planes_count].surface = dc_plane;
8520 if (!bundle->surface_updates[planes_count].surface) {
8521 DRM_ERROR("No surface for CRTC: id=%d\n",
8522 acrtc_attach->crtc_id);
8526 if (plane == pcrtc->primary)
8527 update_freesync_state_on_stream(
8530 acrtc_state->stream,
8532 bundle->flip_addrs[planes_count].flip_timestamp_in_us);
8534 drm_dbg_state(state->dev, "%s Flipping to hi: 0x%x, low: 0x%x\n",
8536 bundle->flip_addrs[planes_count].address.grph.addr.high_part,
8537 bundle->flip_addrs[planes_count].address.grph.addr.low_part);
8543 if (pflip_present) {
8545 /* Use old throttling in non-vrr fixed refresh rate mode
8546 * to keep flip scheduling based on target vblank counts
8547 * working in a backwards compatible way, e.g., for
8548 * clients using the GLX_OML_sync_control extension or
8549 * DRI3/Present extension with defined target_msc.
8551 last_flip_vblank = amdgpu_get_vblank_counter_kms(pcrtc);
8553 /* For variable refresh rate mode only:
8554 * Get vblank of last completed flip to avoid > 1 vrr
8555 * flips per video frame by use of throttling, but allow
8556 * flip programming anywhere in the possibly large
8557 * variable vrr vblank interval for fine-grained flip
8558 * timing control and more opportunity to avoid stutter
8559 * on late submission of flips.
8561 spin_lock_irqsave(&pcrtc->dev->event_lock, flags);
8562 last_flip_vblank = acrtc_attach->dm_irq_params.last_flip_vblank;
8563 spin_unlock_irqrestore(&pcrtc->dev->event_lock, flags);
8566 target_vblank = last_flip_vblank + wait_for_vblank;
8569 * Wait until we're out of the vertical blank period before the one
8570 * targeted by the flip
8572 while ((acrtc_attach->enabled &&
8573 (amdgpu_display_get_crtc_scanoutpos(dm->ddev, acrtc_attach->crtc_id,
8574 0, &vpos, &hpos, NULL,
8575 NULL, &pcrtc->hwmode)
8576 & (DRM_SCANOUTPOS_VALID | DRM_SCANOUTPOS_IN_VBLANK)) ==
8577 (DRM_SCANOUTPOS_VALID | DRM_SCANOUTPOS_IN_VBLANK) &&
8578 (int)(target_vblank -
8579 amdgpu_get_vblank_counter_kms(pcrtc)) > 0)) {
8580 usleep_range(1000, 1100);
8584 * Prepare the flip event for the pageflip interrupt to handle.
8586 * This only works in the case where we've already turned on the
8587 * appropriate hardware blocks (eg. HUBP) so in the transition case
8588 * from 0 -> n planes we have to skip a hardware generated event
8589 * and rely on sending it from software.
8591 if (acrtc_attach->base.state->event &&
8592 acrtc_state->active_planes > 0) {
8593 drm_crtc_vblank_get(pcrtc);
8595 spin_lock_irqsave(&pcrtc->dev->event_lock, flags);
8597 WARN_ON(acrtc_attach->pflip_status != AMDGPU_FLIP_NONE);
8598 prepare_flip_isr(acrtc_attach);
8600 spin_unlock_irqrestore(&pcrtc->dev->event_lock, flags);
8603 if (acrtc_state->stream) {
8604 if (acrtc_state->freesync_vrr_info_changed)
8605 bundle->stream_update.vrr_infopacket =
8606 &acrtc_state->stream->vrr_infopacket;
8608 } else if (cursor_update && acrtc_state->active_planes > 0 &&
8609 acrtc_attach->base.state->event) {
8610 drm_crtc_vblank_get(pcrtc);
8612 spin_lock_irqsave(&pcrtc->dev->event_lock, flags);
8614 acrtc_attach->event = acrtc_attach->base.state->event;
8615 acrtc_attach->base.state->event = NULL;
8617 spin_unlock_irqrestore(&pcrtc->dev->event_lock, flags);
8620 /* Update the planes if changed or disable if we don't have any. */
8621 if ((planes_count || acrtc_state->active_planes == 0) &&
8622 acrtc_state->stream) {
8624 * If PSR or idle optimizations are enabled then flush out
8625 * any pending work before hardware programming.
8627 if (dm->vblank_control_workqueue)
8628 flush_workqueue(dm->vblank_control_workqueue);
8630 bundle->stream_update.stream = acrtc_state->stream;
8631 if (new_pcrtc_state->mode_changed) {
8632 bundle->stream_update.src = acrtc_state->stream->src;
8633 bundle->stream_update.dst = acrtc_state->stream->dst;
8636 if (new_pcrtc_state->color_mgmt_changed) {
8638 * TODO: This isn't fully correct since we've actually
8639 * already modified the stream in place.
8641 bundle->stream_update.gamut_remap =
8642 &acrtc_state->stream->gamut_remap_matrix;
8643 bundle->stream_update.output_csc_transform =
8644 &acrtc_state->stream->csc_color_matrix;
8645 bundle->stream_update.out_transfer_func =
8646 &acrtc_state->stream->out_transfer_func;
8647 bundle->stream_update.lut3d_func =
8648 (struct dc_3dlut *) acrtc_state->stream->lut3d_func;
8649 bundle->stream_update.func_shaper =
8650 (struct dc_transfer_func *) acrtc_state->stream->func_shaper;
8653 acrtc_state->stream->abm_level = acrtc_state->abm_level;
8654 if (acrtc_state->abm_level != dm_old_crtc_state->abm_level)
8655 bundle->stream_update.abm_level = &acrtc_state->abm_level;
8657 mutex_lock(&dm->dc_lock);
8658 if ((acrtc_state->update_type > UPDATE_TYPE_FAST) &&
8659 acrtc_state->stream->link->psr_settings.psr_allow_active)
8660 amdgpu_dm_psr_disable(acrtc_state->stream);
8661 mutex_unlock(&dm->dc_lock);
8664 * If FreeSync state on the stream has changed then we need to
8665 * re-adjust the min/max bounds now that DC doesn't handle this
8666 * as part of commit.
8668 if (is_dc_timing_adjust_needed(dm_old_crtc_state, acrtc_state)) {
8669 spin_lock_irqsave(&pcrtc->dev->event_lock, flags);
8670 dc_stream_adjust_vmin_vmax(
8671 dm->dc, acrtc_state->stream,
8672 &acrtc_attach->dm_irq_params.vrr_params.adjust);
8673 spin_unlock_irqrestore(&pcrtc->dev->event_lock, flags);
8675 mutex_lock(&dm->dc_lock);
8676 update_planes_and_stream_adapter(dm->dc,
8677 acrtc_state->update_type,
8679 acrtc_state->stream,
8680 &bundle->stream_update,
8681 bundle->surface_updates);
8684 * Enable or disable the interrupts on the backend.
8686 * Most pipes are put into power gating when unused.
8688 * When power gating is enabled on a pipe we lose the
8689 * interrupt enablement state when power gating is disabled.
8691 * So we need to update the IRQ control state in hardware
8692 * whenever the pipe turns on (since it could be previously
8693 * power gated) or off (since some pipes can't be power gated
8696 if (dm_old_crtc_state->active_planes != acrtc_state->active_planes)
8697 dm_update_pflip_irq_state(drm_to_adev(dev),
8700 if (acrtc_state->update_type > UPDATE_TYPE_FAST) {
8701 if (acrtc_state->stream->link->replay_settings.config.replay_supported &&
8702 !acrtc_state->stream->link->replay_settings.replay_feature_enabled) {
8703 struct amdgpu_dm_connector *aconn =
8704 (struct amdgpu_dm_connector *)acrtc_state->stream->dm_stream_context;
8705 amdgpu_dm_link_setup_replay(acrtc_state->stream->link, aconn);
8706 } else if (acrtc_state->stream->link->psr_settings.psr_version != DC_PSR_VERSION_UNSUPPORTED &&
8707 !acrtc_state->stream->link->psr_settings.psr_feature_enabled) {
8709 struct amdgpu_dm_connector *aconn = (struct amdgpu_dm_connector *)
8710 acrtc_state->stream->dm_stream_context;
8712 if (!aconn->disallow_edp_enter_psr)
8713 amdgpu_dm_link_setup_psr(acrtc_state->stream);
8717 /* Decrement skip count when PSR is enabled and we're doing fast updates. */
8718 if (acrtc_state->update_type == UPDATE_TYPE_FAST &&
8719 acrtc_state->stream->link->psr_settings.psr_feature_enabled) {
8720 struct amdgpu_dm_connector *aconn =
8721 (struct amdgpu_dm_connector *)acrtc_state->stream->dm_stream_context;
8723 if (aconn->psr_skip_count > 0)
8724 aconn->psr_skip_count--;
8726 /* Allow PSR when skip count is 0. */
8727 acrtc_attach->dm_irq_params.allow_psr_entry = !aconn->psr_skip_count;
8730 * If sink supports PSR SU, there is no need to rely on
8731 * a vblank event disable request to enable PSR. PSR SU
8732 * can be enabled immediately once OS demonstrates an
8733 * adequate number of fast atomic commits to notify KMD
8734 * of update events. See `vblank_control_worker()`.
8736 if (acrtc_state->stream->link->psr_settings.psr_version >= DC_PSR_VERSION_SU_1 &&
8737 acrtc_attach->dm_irq_params.allow_psr_entry &&
8738 #ifdef CONFIG_DRM_AMD_SECURE_DISPLAY
8739 !amdgpu_dm_crc_window_is_activated(acrtc_state->base.crtc) &&
8741 !acrtc_state->stream->link->psr_settings.psr_allow_active &&
8742 !aconn->disallow_edp_enter_psr &&
8744 acrtc_state->stream->link->psr_settings.psr_dirty_rects_change_timestamp_ns) >
8746 amdgpu_dm_psr_enable(acrtc_state->stream);
8748 acrtc_attach->dm_irq_params.allow_psr_entry = false;
8751 mutex_unlock(&dm->dc_lock);
8755 * Update cursor state *after* programming all the planes.
8756 * This avoids redundant programming in the case where we're going
8757 * to be disabling a single plane - those pipes are being disabled.
8759 if (acrtc_state->active_planes)
8760 amdgpu_dm_commit_cursors(state);
8766 static void amdgpu_dm_commit_audio(struct drm_device *dev,
8767 struct drm_atomic_state *state)
8769 struct amdgpu_device *adev = drm_to_adev(dev);
8770 struct amdgpu_dm_connector *aconnector;
8771 struct drm_connector *connector;
8772 struct drm_connector_state *old_con_state, *new_con_state;
8773 struct drm_crtc_state *new_crtc_state;
8774 struct dm_crtc_state *new_dm_crtc_state;
8775 const struct dc_stream_status *status;
8778 /* Notify device removals. */
8779 for_each_oldnew_connector_in_state(state, connector, old_con_state, new_con_state, i) {
8780 if (old_con_state->crtc != new_con_state->crtc) {
8781 /* CRTC changes require notification. */
8785 if (!new_con_state->crtc)
8788 new_crtc_state = drm_atomic_get_new_crtc_state(
8789 state, new_con_state->crtc);
8791 if (!new_crtc_state)
8794 if (!drm_atomic_crtc_needs_modeset(new_crtc_state))
8798 if (connector->connector_type == DRM_MODE_CONNECTOR_WRITEBACK)
8801 aconnector = to_amdgpu_dm_connector(connector);
8803 mutex_lock(&adev->dm.audio_lock);
8804 inst = aconnector->audio_inst;
8805 aconnector->audio_inst = -1;
8806 mutex_unlock(&adev->dm.audio_lock);
8808 amdgpu_dm_audio_eld_notify(adev, inst);
8811 /* Notify audio device additions. */
8812 for_each_new_connector_in_state(state, connector, new_con_state, i) {
8813 if (!new_con_state->crtc)
8816 new_crtc_state = drm_atomic_get_new_crtc_state(
8817 state, new_con_state->crtc);
8819 if (!new_crtc_state)
8822 if (!drm_atomic_crtc_needs_modeset(new_crtc_state))
8825 new_dm_crtc_state = to_dm_crtc_state(new_crtc_state);
8826 if (!new_dm_crtc_state->stream)
8829 status = dc_stream_get_status(new_dm_crtc_state->stream);
8833 if (connector->connector_type == DRM_MODE_CONNECTOR_WRITEBACK)
8836 aconnector = to_amdgpu_dm_connector(connector);
8838 mutex_lock(&adev->dm.audio_lock);
8839 inst = status->audio_inst;
8840 aconnector->audio_inst = inst;
8841 mutex_unlock(&adev->dm.audio_lock);
8843 amdgpu_dm_audio_eld_notify(adev, inst);
8848 * amdgpu_dm_crtc_copy_transient_flags - copy mirrored flags from DRM to DC
8849 * @crtc_state: the DRM CRTC state
8850 * @stream_state: the DC stream state.
8852 * Copy the mirrored transient state flags from DRM, to DC. It is used to bring
8853 * a dc_stream_state's flags in sync with a drm_crtc_state's flags.
8855 static void amdgpu_dm_crtc_copy_transient_flags(struct drm_crtc_state *crtc_state,
8856 struct dc_stream_state *stream_state)
8858 stream_state->mode_changed = drm_atomic_crtc_needs_modeset(crtc_state);
8861 static void dm_clear_writeback(struct amdgpu_display_manager *dm,
8862 struct dm_crtc_state *crtc_state)
8864 dc_stream_remove_writeback(dm->dc, crtc_state->stream, 0);
8867 static void amdgpu_dm_commit_streams(struct drm_atomic_state *state,
8868 struct dc_state *dc_state)
8870 struct drm_device *dev = state->dev;
8871 struct amdgpu_device *adev = drm_to_adev(dev);
8872 struct amdgpu_display_manager *dm = &adev->dm;
8873 struct drm_crtc *crtc;
8874 struct drm_crtc_state *old_crtc_state, *new_crtc_state;
8875 struct dm_crtc_state *dm_old_crtc_state, *dm_new_crtc_state;
8876 struct drm_connector_state *old_con_state;
8877 struct drm_connector *connector;
8878 bool mode_set_reset_required = false;
8880 struct dc_commit_streams_params params = {dc_state->streams, dc_state->stream_count};
8882 /* Disable writeback */
8883 for_each_old_connector_in_state(state, connector, old_con_state, i) {
8884 struct dm_connector_state *dm_old_con_state;
8885 struct amdgpu_crtc *acrtc;
8887 if (connector->connector_type != DRM_MODE_CONNECTOR_WRITEBACK)
8890 old_crtc_state = NULL;
8892 dm_old_con_state = to_dm_connector_state(old_con_state);
8893 if (!dm_old_con_state->base.crtc)
8896 acrtc = to_amdgpu_crtc(dm_old_con_state->base.crtc);
8898 old_crtc_state = drm_atomic_get_old_crtc_state(state, &acrtc->base);
8900 if (!acrtc->wb_enabled)
8903 dm_old_crtc_state = to_dm_crtc_state(old_crtc_state);
8905 dm_clear_writeback(dm, dm_old_crtc_state);
8906 acrtc->wb_enabled = false;
8909 for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state,
8910 new_crtc_state, i) {
8911 struct amdgpu_crtc *acrtc = to_amdgpu_crtc(crtc);
8913 dm_old_crtc_state = to_dm_crtc_state(old_crtc_state);
8915 if (old_crtc_state->active &&
8916 (!new_crtc_state->active ||
8917 drm_atomic_crtc_needs_modeset(new_crtc_state))) {
8918 manage_dm_interrupts(adev, acrtc, false);
8919 dc_stream_release(dm_old_crtc_state->stream);
8923 drm_atomic_helper_calc_timestamping_constants(state);
8925 /* update changed items */
8926 for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) {
8927 struct amdgpu_crtc *acrtc = to_amdgpu_crtc(crtc);
8929 dm_new_crtc_state = to_dm_crtc_state(new_crtc_state);
8930 dm_old_crtc_state = to_dm_crtc_state(old_crtc_state);
8932 drm_dbg_state(state->dev,
8933 "amdgpu_crtc id:%d crtc_state_flags: enable:%d, active:%d, planes_changed:%d, mode_changed:%d,active_changed:%d,connectors_changed:%d\n",
8935 new_crtc_state->enable,
8936 new_crtc_state->active,
8937 new_crtc_state->planes_changed,
8938 new_crtc_state->mode_changed,
8939 new_crtc_state->active_changed,
8940 new_crtc_state->connectors_changed);
8942 /* Disable cursor if disabling crtc */
8943 if (old_crtc_state->active && !new_crtc_state->active) {
8944 struct dc_cursor_position position;
8946 memset(&position, 0, sizeof(position));
8947 mutex_lock(&dm->dc_lock);
8948 dc_stream_set_cursor_position(dm_old_crtc_state->stream, &position);
8949 mutex_unlock(&dm->dc_lock);
8952 /* Copy all transient state flags into dc state */
8953 if (dm_new_crtc_state->stream) {
8954 amdgpu_dm_crtc_copy_transient_flags(&dm_new_crtc_state->base,
8955 dm_new_crtc_state->stream);
8958 /* handles headless hotplug case, updating new_state and
8959 * aconnector as needed
8962 if (amdgpu_dm_crtc_modeset_required(new_crtc_state, dm_new_crtc_state->stream, dm_old_crtc_state->stream)) {
8964 DRM_DEBUG_ATOMIC("Atomic commit: SET crtc id %d: [%p]\n", acrtc->crtc_id, acrtc);
8966 if (!dm_new_crtc_state->stream) {
8968 * this could happen because of issues with
8969 * userspace notifications delivery.
8970 * In this case userspace tries to set mode on
8971 * display which is disconnected in fact.
8972 * dc_sink is NULL in this case on aconnector.
8973 * We expect reset mode will come soon.
8975 * This can also happen when unplug is done
8976 * during resume sequence ended
8978 * In this case, we want to pretend we still
8979 * have a sink to keep the pipe running so that
8980 * hw state is consistent with the sw state
8982 DRM_DEBUG_DRIVER("%s: Failed to create new stream for crtc %d\n",
8983 __func__, acrtc->base.base.id);
8987 if (dm_old_crtc_state->stream)
8988 remove_stream(adev, acrtc, dm_old_crtc_state->stream);
8990 pm_runtime_get_noresume(dev->dev);
8992 acrtc->enabled = true;
8993 acrtc->hw_mode = new_crtc_state->mode;
8994 crtc->hwmode = new_crtc_state->mode;
8995 mode_set_reset_required = true;
8996 } else if (modereset_required(new_crtc_state)) {
8997 DRM_DEBUG_ATOMIC("Atomic commit: RESET. crtc id %d:[%p]\n", acrtc->crtc_id, acrtc);
8998 /* i.e. reset mode */
8999 if (dm_old_crtc_state->stream)
9000 remove_stream(adev, acrtc, dm_old_crtc_state->stream);
9002 mode_set_reset_required = true;
9004 } /* for_each_crtc_in_state() */
9006 /* if there mode set or reset, disable eDP PSR, Replay */
9007 if (mode_set_reset_required) {
9008 if (dm->vblank_control_workqueue)
9009 flush_workqueue(dm->vblank_control_workqueue);
9011 amdgpu_dm_replay_disable_all(dm);
9012 amdgpu_dm_psr_disable_all(dm);
9015 dm_enable_per_frame_crtc_master_sync(dc_state);
9016 mutex_lock(&dm->dc_lock);
9017 WARN_ON(!dc_commit_streams(dm->dc, ¶ms));
9019 /* Allow idle optimization when vblank count is 0 for display off */
9020 if (dm->active_vblank_irq_count == 0)
9021 dc_allow_idle_optimizations(dm->dc, true);
9022 mutex_unlock(&dm->dc_lock);
9024 for_each_new_crtc_in_state(state, crtc, new_crtc_state, i) {
9025 struct amdgpu_crtc *acrtc = to_amdgpu_crtc(crtc);
9027 dm_new_crtc_state = to_dm_crtc_state(new_crtc_state);
9029 if (dm_new_crtc_state->stream != NULL) {
9030 const struct dc_stream_status *status =
9031 dc_stream_get_status(dm_new_crtc_state->stream);
9034 status = dc_state_get_stream_status(dc_state,
9035 dm_new_crtc_state->stream);
9038 "got no status for stream %p on acrtc%p\n",
9039 dm_new_crtc_state->stream, acrtc);
9041 acrtc->otg_inst = status->primary_otg_inst;
9046 static void dm_set_writeback(struct amdgpu_display_manager *dm,
9047 struct dm_crtc_state *crtc_state,
9048 struct drm_connector *connector,
9049 struct drm_connector_state *new_con_state)
9051 struct drm_writeback_connector *wb_conn = drm_connector_to_writeback(connector);
9052 struct amdgpu_device *adev = dm->adev;
9053 struct amdgpu_crtc *acrtc;
9054 struct dc_writeback_info *wb_info;
9055 struct pipe_ctx *pipe = NULL;
9056 struct amdgpu_framebuffer *afb;
9059 wb_info = kzalloc(sizeof(*wb_info), GFP_KERNEL);
9061 DRM_ERROR("Failed to allocate wb_info\n");
9065 acrtc = to_amdgpu_crtc(wb_conn->encoder.crtc);
9067 DRM_ERROR("no amdgpu_crtc found\n");
9072 afb = to_amdgpu_framebuffer(new_con_state->writeback_job->fb);
9074 DRM_ERROR("No amdgpu_framebuffer found\n");
9079 for (i = 0; i < MAX_PIPES; i++) {
9080 if (dm->dc->current_state->res_ctx.pipe_ctx[i].stream == crtc_state->stream) {
9081 pipe = &dm->dc->current_state->res_ctx.pipe_ctx[i];
9086 /* fill in wb_info */
9087 wb_info->wb_enabled = true;
9089 wb_info->dwb_pipe_inst = 0;
9090 wb_info->dwb_params.dwbscl_black_color = 0;
9091 wb_info->dwb_params.hdr_mult = 0x1F000;
9092 wb_info->dwb_params.csc_params.gamut_adjust_type = CM_GAMUT_ADJUST_TYPE_BYPASS;
9093 wb_info->dwb_params.csc_params.gamut_coef_format = CM_GAMUT_REMAP_COEF_FORMAT_S2_13;
9094 wb_info->dwb_params.output_depth = DWB_OUTPUT_PIXEL_DEPTH_10BPC;
9095 wb_info->dwb_params.cnv_params.cnv_out_bpc = DWB_CNV_OUT_BPC_10BPC;
9097 /* width & height from crtc */
9098 wb_info->dwb_params.cnv_params.src_width = acrtc->base.mode.crtc_hdisplay;
9099 wb_info->dwb_params.cnv_params.src_height = acrtc->base.mode.crtc_vdisplay;
9100 wb_info->dwb_params.dest_width = acrtc->base.mode.crtc_hdisplay;
9101 wb_info->dwb_params.dest_height = acrtc->base.mode.crtc_vdisplay;
9103 wb_info->dwb_params.cnv_params.crop_en = false;
9104 wb_info->dwb_params.stereo_params.stereo_enabled = false;
9106 wb_info->dwb_params.cnv_params.out_max_pix_val = 0x3ff; // 10 bits
9107 wb_info->dwb_params.cnv_params.out_min_pix_val = 0;
9108 wb_info->dwb_params.cnv_params.fc_out_format = DWB_OUT_FORMAT_32BPP_ARGB;
9109 wb_info->dwb_params.cnv_params.out_denorm_mode = DWB_OUT_DENORM_BYPASS;
9111 wb_info->dwb_params.out_format = dwb_scaler_mode_bypass444;
9113 wb_info->dwb_params.capture_rate = dwb_capture_rate_0;
9115 wb_info->dwb_params.scaler_taps.h_taps = 4;
9116 wb_info->dwb_params.scaler_taps.v_taps = 4;
9117 wb_info->dwb_params.scaler_taps.h_taps_c = 2;
9118 wb_info->dwb_params.scaler_taps.v_taps_c = 2;
9119 wb_info->dwb_params.subsample_position = DWB_INTERSTITIAL_SUBSAMPLING;
9121 wb_info->mcif_buf_params.luma_pitch = afb->base.pitches[0];
9122 wb_info->mcif_buf_params.chroma_pitch = afb->base.pitches[1];
9124 for (i = 0; i < DWB_MCIF_BUF_COUNT; i++) {
9125 wb_info->mcif_buf_params.luma_address[i] = afb->address;
9126 wb_info->mcif_buf_params.chroma_address[i] = 0;
9129 wb_info->mcif_buf_params.p_vmid = 1;
9130 if (amdgpu_ip_version(adev, DCE_HWIP, 0) >= IP_VERSION(3, 0, 0)) {
9131 wb_info->mcif_warmup_params.start_address.quad_part = afb->address;
9132 wb_info->mcif_warmup_params.region_size =
9133 wb_info->mcif_buf_params.luma_pitch * wb_info->dwb_params.dest_height;
9135 wb_info->mcif_warmup_params.p_vmid = 1;
9136 wb_info->writeback_source_plane = pipe->plane_state;
9138 dc_stream_add_writeback(dm->dc, crtc_state->stream, wb_info);
9140 acrtc->wb_pending = true;
9141 acrtc->wb_conn = wb_conn;
9142 drm_writeback_queue_job(wb_conn, new_con_state);
9146 * amdgpu_dm_atomic_commit_tail() - AMDgpu DM's commit tail implementation.
9147 * @state: The atomic state to commit
9149 * This will tell DC to commit the constructed DC state from atomic_check,
9150 * programming the hardware. Any failures here implies a hardware failure, since
9151 * atomic check should have filtered anything non-kosher.
9153 static void amdgpu_dm_atomic_commit_tail(struct drm_atomic_state *state)
9155 struct drm_device *dev = state->dev;
9156 struct amdgpu_device *adev = drm_to_adev(dev);
9157 struct amdgpu_display_manager *dm = &adev->dm;
9158 struct dm_atomic_state *dm_state;
9159 struct dc_state *dc_state = NULL;
9161 struct drm_crtc *crtc;
9162 struct drm_crtc_state *old_crtc_state, *new_crtc_state;
9163 unsigned long flags;
9164 bool wait_for_vblank = true;
9165 struct drm_connector *connector;
9166 struct drm_connector_state *old_con_state, *new_con_state;
9167 struct dm_crtc_state *dm_old_crtc_state, *dm_new_crtc_state;
9168 int crtc_disable_count = 0;
9170 trace_amdgpu_dm_atomic_commit_tail_begin(state);
9172 if (dm->dc->caps.ips_support && dm->dc->idle_optimizations_allowed)
9173 dc_allow_idle_optimizations(dm->dc, false);
9175 drm_atomic_helper_update_legacy_modeset_state(dev, state);
9176 drm_dp_mst_atomic_wait_for_dependencies(state);
9178 dm_state = dm_atomic_get_new_state(state);
9179 if (dm_state && dm_state->context) {
9180 dc_state = dm_state->context;
9181 amdgpu_dm_commit_streams(state, dc_state);
9184 for_each_oldnew_connector_in_state(state, connector, old_con_state, new_con_state, i) {
9185 struct dm_connector_state *dm_new_con_state = to_dm_connector_state(new_con_state);
9186 struct amdgpu_crtc *acrtc = to_amdgpu_crtc(dm_new_con_state->base.crtc);
9187 struct amdgpu_dm_connector *aconnector;
9189 if (connector->connector_type == DRM_MODE_CONNECTOR_WRITEBACK)
9192 aconnector = to_amdgpu_dm_connector(connector);
9194 if (!adev->dm.hdcp_workqueue)
9197 pr_debug("[HDCP_DM] -------------- i : %x ----------\n", i);
9202 pr_debug("[HDCP_DM] connector->index: %x connect_status: %x dpms: %x\n",
9203 connector->index, connector->status, connector->dpms);
9204 pr_debug("[HDCP_DM] state protection old: %x new: %x\n",
9205 old_con_state->content_protection, new_con_state->content_protection);
9207 if (aconnector->dc_sink) {
9208 if (aconnector->dc_sink->sink_signal != SIGNAL_TYPE_VIRTUAL &&
9209 aconnector->dc_sink->sink_signal != SIGNAL_TYPE_NONE) {
9210 pr_debug("[HDCP_DM] pipe_ctx dispname=%s\n",
9211 aconnector->dc_sink->edid_caps.display_name);
9215 new_crtc_state = NULL;
9216 old_crtc_state = NULL;
9219 new_crtc_state = drm_atomic_get_new_crtc_state(state, &acrtc->base);
9220 old_crtc_state = drm_atomic_get_old_crtc_state(state, &acrtc->base);
9224 pr_debug("old crtc en: %x a: %x m: %x a-chg: %x c-chg: %x\n",
9225 old_crtc_state->enable,
9226 old_crtc_state->active,
9227 old_crtc_state->mode_changed,
9228 old_crtc_state->active_changed,
9229 old_crtc_state->connectors_changed);
9232 pr_debug("NEW crtc en: %x a: %x m: %x a-chg: %x c-chg: %x\n",
9233 new_crtc_state->enable,
9234 new_crtc_state->active,
9235 new_crtc_state->mode_changed,
9236 new_crtc_state->active_changed,
9237 new_crtc_state->connectors_changed);
9240 for_each_oldnew_connector_in_state(state, connector, old_con_state, new_con_state, i) {
9241 struct dm_connector_state *dm_new_con_state = to_dm_connector_state(new_con_state);
9242 struct amdgpu_crtc *acrtc = to_amdgpu_crtc(dm_new_con_state->base.crtc);
9243 struct amdgpu_dm_connector *aconnector = to_amdgpu_dm_connector(connector);
9245 if (!adev->dm.hdcp_workqueue)
9248 new_crtc_state = NULL;
9249 old_crtc_state = NULL;
9252 new_crtc_state = drm_atomic_get_new_crtc_state(state, &acrtc->base);
9253 old_crtc_state = drm_atomic_get_old_crtc_state(state, &acrtc->base);
9256 dm_new_crtc_state = to_dm_crtc_state(new_crtc_state);
9258 if (dm_new_crtc_state && dm_new_crtc_state->stream == NULL &&
9259 connector->state->content_protection == DRM_MODE_CONTENT_PROTECTION_ENABLED) {
9260 hdcp_reset_display(adev->dm.hdcp_workqueue, aconnector->dc_link->link_index);
9261 new_con_state->content_protection = DRM_MODE_CONTENT_PROTECTION_DESIRED;
9262 dm_new_con_state->update_hdcp = true;
9266 if (is_content_protection_different(new_crtc_state, old_crtc_state, new_con_state,
9267 old_con_state, connector, adev->dm.hdcp_workqueue)) {
9268 /* when display is unplugged from mst hub, connctor will
9269 * be destroyed within dm_dp_mst_connector_destroy. connector
9270 * hdcp perperties, like type, undesired, desired, enabled,
9271 * will be lost. So, save hdcp properties into hdcp_work within
9272 * amdgpu_dm_atomic_commit_tail. if the same display is
9273 * plugged back with same display index, its hdcp properties
9274 * will be retrieved from hdcp_work within dm_dp_mst_get_modes
9277 bool enable_encryption = false;
9279 if (new_con_state->content_protection == DRM_MODE_CONTENT_PROTECTION_DESIRED)
9280 enable_encryption = true;
9282 if (aconnector->dc_link && aconnector->dc_sink &&
9283 aconnector->dc_link->type == dc_connection_mst_branch) {
9284 struct hdcp_workqueue *hdcp_work = adev->dm.hdcp_workqueue;
9285 struct hdcp_workqueue *hdcp_w =
9286 &hdcp_work[aconnector->dc_link->link_index];
9288 hdcp_w->hdcp_content_type[connector->index] =
9289 new_con_state->hdcp_content_type;
9290 hdcp_w->content_protection[connector->index] =
9291 new_con_state->content_protection;
9294 if (new_crtc_state && new_crtc_state->mode_changed &&
9295 new_con_state->content_protection >= DRM_MODE_CONTENT_PROTECTION_DESIRED)
9296 enable_encryption = true;
9298 DRM_INFO("[HDCP_DM] hdcp_update_display enable_encryption = %x\n", enable_encryption);
9300 hdcp_update_display(
9301 adev->dm.hdcp_workqueue, aconnector->dc_link->link_index, aconnector,
9302 new_con_state->hdcp_content_type, enable_encryption);
9306 /* Handle connector state changes */
9307 for_each_oldnew_connector_in_state(state, connector, old_con_state, new_con_state, i) {
9308 struct dm_connector_state *dm_new_con_state = to_dm_connector_state(new_con_state);
9309 struct dm_connector_state *dm_old_con_state = to_dm_connector_state(old_con_state);
9310 struct amdgpu_crtc *acrtc = to_amdgpu_crtc(dm_new_con_state->base.crtc);
9311 struct dc_surface_update *dummy_updates;
9312 struct dc_stream_update stream_update;
9313 struct dc_info_packet hdr_packet;
9314 struct dc_stream_status *status = NULL;
9315 bool abm_changed, hdr_changed, scaling_changed;
9317 memset(&stream_update, 0, sizeof(stream_update));
9320 new_crtc_state = drm_atomic_get_new_crtc_state(state, &acrtc->base);
9321 old_crtc_state = drm_atomic_get_old_crtc_state(state, &acrtc->base);
9324 /* Skip any modesets/resets */
9325 if (!acrtc || drm_atomic_crtc_needs_modeset(new_crtc_state))
9328 dm_new_crtc_state = to_dm_crtc_state(new_crtc_state);
9329 dm_old_crtc_state = to_dm_crtc_state(old_crtc_state);
9331 scaling_changed = is_scaling_state_different(dm_new_con_state,
9334 abm_changed = dm_new_crtc_state->abm_level !=
9335 dm_old_crtc_state->abm_level;
9338 !drm_connector_atomic_hdr_metadata_equal(old_con_state, new_con_state);
9340 if (!scaling_changed && !abm_changed && !hdr_changed)
9343 stream_update.stream = dm_new_crtc_state->stream;
9344 if (scaling_changed) {
9345 update_stream_scaling_settings(&dm_new_con_state->base.crtc->mode,
9346 dm_new_con_state, dm_new_crtc_state->stream);
9348 stream_update.src = dm_new_crtc_state->stream->src;
9349 stream_update.dst = dm_new_crtc_state->stream->dst;
9353 dm_new_crtc_state->stream->abm_level = dm_new_crtc_state->abm_level;
9355 stream_update.abm_level = &dm_new_crtc_state->abm_level;
9359 fill_hdr_info_packet(new_con_state, &hdr_packet);
9360 stream_update.hdr_static_metadata = &hdr_packet;
9363 status = dc_stream_get_status(dm_new_crtc_state->stream);
9365 if (WARN_ON(!status))
9368 WARN_ON(!status->plane_count);
9371 * TODO: DC refuses to perform stream updates without a dc_surface_update.
9372 * Here we create an empty update on each plane.
9373 * To fix this, DC should permit updating only stream properties.
9375 dummy_updates = kzalloc(sizeof(struct dc_surface_update) * MAX_SURFACES, GFP_ATOMIC);
9376 if (!dummy_updates) {
9377 DRM_ERROR("Failed to allocate memory for dummy_updates.\n");
9380 for (j = 0; j < status->plane_count; j++)
9381 dummy_updates[j].surface = status->plane_states[0];
9384 mutex_lock(&dm->dc_lock);
9385 dc_update_planes_and_stream(dm->dc,
9387 status->plane_count,
9388 dm_new_crtc_state->stream,
9390 mutex_unlock(&dm->dc_lock);
9391 kfree(dummy_updates);
9395 * Enable interrupts for CRTCs that are newly enabled or went through
9396 * a modeset. It was intentionally deferred until after the front end
9397 * state was modified to wait until the OTG was on and so the IRQ
9398 * handlers didn't access stale or invalid state.
9400 for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) {
9401 struct amdgpu_crtc *acrtc = to_amdgpu_crtc(crtc);
9402 #ifdef CONFIG_DEBUG_FS
9403 enum amdgpu_dm_pipe_crc_source cur_crc_src;
9405 /* Count number of newly disabled CRTCs for dropping PM refs later. */
9406 if (old_crtc_state->active && !new_crtc_state->active)
9407 crtc_disable_count++;
9409 dm_new_crtc_state = to_dm_crtc_state(new_crtc_state);
9410 dm_old_crtc_state = to_dm_crtc_state(old_crtc_state);
9412 /* For freesync config update on crtc state and params for irq */
9413 update_stream_irq_parameters(dm, dm_new_crtc_state);
9415 #ifdef CONFIG_DEBUG_FS
9416 spin_lock_irqsave(&adev_to_drm(adev)->event_lock, flags);
9417 cur_crc_src = acrtc->dm_irq_params.crc_src;
9418 spin_unlock_irqrestore(&adev_to_drm(adev)->event_lock, flags);
9421 if (new_crtc_state->active &&
9422 (!old_crtc_state->active ||
9423 drm_atomic_crtc_needs_modeset(new_crtc_state))) {
9424 dc_stream_retain(dm_new_crtc_state->stream);
9425 acrtc->dm_irq_params.stream = dm_new_crtc_state->stream;
9426 manage_dm_interrupts(adev, acrtc, true);
9428 /* Handle vrr on->off / off->on transitions */
9429 amdgpu_dm_handle_vrr_transition(dm_old_crtc_state, dm_new_crtc_state);
9431 #ifdef CONFIG_DEBUG_FS
9432 if (new_crtc_state->active &&
9433 (!old_crtc_state->active ||
9434 drm_atomic_crtc_needs_modeset(new_crtc_state))) {
9436 * Frontend may have changed so reapply the CRC capture
9437 * settings for the stream.
9439 if (amdgpu_dm_is_valid_crc_source(cur_crc_src)) {
9440 #if defined(CONFIG_DRM_AMD_SECURE_DISPLAY)
9441 if (amdgpu_dm_crc_window_is_activated(crtc)) {
9442 spin_lock_irqsave(&adev_to_drm(adev)->event_lock, flags);
9443 acrtc->dm_irq_params.window_param.update_win = true;
9446 * It takes 2 frames for HW to stably generate CRC when
9447 * resuming from suspend, so we set skip_frame_cnt 2.
9449 acrtc->dm_irq_params.window_param.skip_frame_cnt = 2;
9450 spin_unlock_irqrestore(&adev_to_drm(adev)->event_lock, flags);
9453 if (amdgpu_dm_crtc_configure_crc_source(
9454 crtc, dm_new_crtc_state, cur_crc_src))
9455 DRM_DEBUG_DRIVER("Failed to configure crc source");
9461 for_each_new_crtc_in_state(state, crtc, new_crtc_state, j)
9462 if (new_crtc_state->async_flip)
9463 wait_for_vblank = false;
9465 /* update planes when needed per crtc*/
9466 for_each_new_crtc_in_state(state, crtc, new_crtc_state, j) {
9467 dm_new_crtc_state = to_dm_crtc_state(new_crtc_state);
9469 if (dm_new_crtc_state->stream)
9470 amdgpu_dm_commit_planes(state, dev, dm, crtc, wait_for_vblank);
9473 /* Enable writeback */
9474 for_each_new_connector_in_state(state, connector, new_con_state, i) {
9475 struct dm_connector_state *dm_new_con_state = to_dm_connector_state(new_con_state);
9476 struct amdgpu_crtc *acrtc = to_amdgpu_crtc(dm_new_con_state->base.crtc);
9478 if (connector->connector_type != DRM_MODE_CONNECTOR_WRITEBACK)
9481 if (!new_con_state->writeback_job)
9484 new_crtc_state = drm_atomic_get_new_crtc_state(state, &acrtc->base);
9486 if (!new_crtc_state)
9489 if (acrtc->wb_enabled)
9492 dm_new_crtc_state = to_dm_crtc_state(new_crtc_state);
9494 dm_set_writeback(dm, dm_new_crtc_state, connector, new_con_state);
9495 acrtc->wb_enabled = true;
9498 /* Update audio instances for each connector. */
9499 amdgpu_dm_commit_audio(dev, state);
9501 /* restore the backlight level */
9502 for (i = 0; i < dm->num_of_edps; i++) {
9503 if (dm->backlight_dev[i] &&
9504 (dm->actual_brightness[i] != dm->brightness[i]))
9505 amdgpu_dm_backlight_set_level(dm, i, dm->brightness[i]);
9509 * send vblank event on all events not handled in flip and
9510 * mark consumed event for drm_atomic_helper_commit_hw_done
9512 spin_lock_irqsave(&adev_to_drm(adev)->event_lock, flags);
9513 for_each_new_crtc_in_state(state, crtc, new_crtc_state, i) {
9515 if (new_crtc_state->event)
9516 drm_send_event_locked(dev, &new_crtc_state->event->base);
9518 new_crtc_state->event = NULL;
9520 spin_unlock_irqrestore(&adev_to_drm(adev)->event_lock, flags);
9522 /* Signal HW programming completion */
9523 drm_atomic_helper_commit_hw_done(state);
9525 if (wait_for_vblank)
9526 drm_atomic_helper_wait_for_flip_done(dev, state);
9528 drm_atomic_helper_cleanup_planes(dev, state);
9530 /* Don't free the memory if we are hitting this as part of suspend.
9531 * This way we don't free any memory during suspend; see
9532 * amdgpu_bo_free_kernel(). The memory will be freed in the first
9533 * non-suspend modeset or when the driver is torn down.
9535 if (!adev->in_suspend) {
9536 /* return the stolen vga memory back to VRAM */
9537 if (!adev->mman.keep_stolen_vga_memory)
9538 amdgpu_bo_free_kernel(&adev->mman.stolen_vga_memory, NULL, NULL);
9539 amdgpu_bo_free_kernel(&adev->mman.stolen_extended_memory, NULL, NULL);
9543 * Finally, drop a runtime PM reference for each newly disabled CRTC,
9544 * so we can put the GPU into runtime suspend if we're not driving any
9547 for (i = 0; i < crtc_disable_count; i++)
9548 pm_runtime_put_autosuspend(dev->dev);
9549 pm_runtime_mark_last_busy(dev->dev);
9552 static int dm_force_atomic_commit(struct drm_connector *connector)
9555 struct drm_device *ddev = connector->dev;
9556 struct drm_atomic_state *state = drm_atomic_state_alloc(ddev);
9557 struct amdgpu_crtc *disconnected_acrtc = to_amdgpu_crtc(connector->encoder->crtc);
9558 struct drm_plane *plane = disconnected_acrtc->base.primary;
9559 struct drm_connector_state *conn_state;
9560 struct drm_crtc_state *crtc_state;
9561 struct drm_plane_state *plane_state;
9566 state->acquire_ctx = ddev->mode_config.acquire_ctx;
9568 /* Construct an atomic state to restore previous display setting */
9571 * Attach connectors to drm_atomic_state
9573 conn_state = drm_atomic_get_connector_state(state, connector);
9575 ret = PTR_ERR_OR_ZERO(conn_state);
9579 /* Attach crtc to drm_atomic_state*/
9580 crtc_state = drm_atomic_get_crtc_state(state, &disconnected_acrtc->base);
9582 ret = PTR_ERR_OR_ZERO(crtc_state);
9586 /* force a restore */
9587 crtc_state->mode_changed = true;
9589 /* Attach plane to drm_atomic_state */
9590 plane_state = drm_atomic_get_plane_state(state, plane);
9592 ret = PTR_ERR_OR_ZERO(plane_state);
9596 /* Call commit internally with the state we just constructed */
9597 ret = drm_atomic_commit(state);
9600 drm_atomic_state_put(state);
9602 DRM_ERROR("Restoring old state failed with %i\n", ret);
9608 * This function handles all cases when set mode does not come upon hotplug.
9609 * This includes when a display is unplugged then plugged back into the
9610 * same port and when running without usermode desktop manager supprot
9612 void dm_restore_drm_connector_state(struct drm_device *dev,
9613 struct drm_connector *connector)
9615 struct amdgpu_dm_connector *aconnector;
9616 struct amdgpu_crtc *disconnected_acrtc;
9617 struct dm_crtc_state *acrtc_state;
9619 if (connector->connector_type == DRM_MODE_CONNECTOR_WRITEBACK)
9622 aconnector = to_amdgpu_dm_connector(connector);
9624 if (!aconnector->dc_sink || !connector->state || !connector->encoder)
9627 disconnected_acrtc = to_amdgpu_crtc(connector->encoder->crtc);
9628 if (!disconnected_acrtc)
9631 acrtc_state = to_dm_crtc_state(disconnected_acrtc->base.state);
9632 if (!acrtc_state->stream)
9636 * If the previous sink is not released and different from the current,
9637 * we deduce we are in a state where we can not rely on usermode call
9638 * to turn on the display, so we do it here
9640 if (acrtc_state->stream->sink != aconnector->dc_sink)
9641 dm_force_atomic_commit(&aconnector->base);
9645 * Grabs all modesetting locks to serialize against any blocking commits,
9646 * Waits for completion of all non blocking commits.
9648 static int do_aquire_global_lock(struct drm_device *dev,
9649 struct drm_atomic_state *state)
9651 struct drm_crtc *crtc;
9652 struct drm_crtc_commit *commit;
9656 * Adding all modeset locks to aquire_ctx will
9657 * ensure that when the framework release it the
9658 * extra locks we are locking here will get released to
9660 ret = drm_modeset_lock_all_ctx(dev, state->acquire_ctx);
9664 list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
9665 spin_lock(&crtc->commit_lock);
9666 commit = list_first_entry_or_null(&crtc->commit_list,
9667 struct drm_crtc_commit, commit_entry);
9669 drm_crtc_commit_get(commit);
9670 spin_unlock(&crtc->commit_lock);
9676 * Make sure all pending HW programming completed and
9679 ret = wait_for_completion_interruptible_timeout(&commit->hw_done, 10*HZ);
9682 ret = wait_for_completion_interruptible_timeout(
9683 &commit->flip_done, 10*HZ);
9686 DRM_ERROR("[CRTC:%d:%s] hw_done or flip_done timed out\n",
9687 crtc->base.id, crtc->name);
9689 drm_crtc_commit_put(commit);
9692 return ret < 0 ? ret : 0;
9695 static void get_freesync_config_for_crtc(
9696 struct dm_crtc_state *new_crtc_state,
9697 struct dm_connector_state *new_con_state)
9699 struct mod_freesync_config config = {0};
9700 struct amdgpu_dm_connector *aconnector;
9701 struct drm_display_mode *mode = &new_crtc_state->base.mode;
9702 int vrefresh = drm_mode_vrefresh(mode);
9703 bool fs_vid_mode = false;
9705 if (new_con_state->base.connector->connector_type == DRM_MODE_CONNECTOR_WRITEBACK)
9708 aconnector = to_amdgpu_dm_connector(new_con_state->base.connector);
9710 new_crtc_state->vrr_supported = new_con_state->freesync_capable &&
9711 vrefresh >= aconnector->min_vfreq &&
9712 vrefresh <= aconnector->max_vfreq;
9714 if (new_crtc_state->vrr_supported) {
9715 new_crtc_state->stream->ignore_msa_timing_param = true;
9716 fs_vid_mode = new_crtc_state->freesync_config.state == VRR_STATE_ACTIVE_FIXED;
9718 config.min_refresh_in_uhz = aconnector->min_vfreq * 1000000;
9719 config.max_refresh_in_uhz = aconnector->max_vfreq * 1000000;
9720 config.vsif_supported = true;
9724 config.state = VRR_STATE_ACTIVE_FIXED;
9725 config.fixed_refresh_in_uhz = new_crtc_state->freesync_config.fixed_refresh_in_uhz;
9727 } else if (new_crtc_state->base.vrr_enabled) {
9728 config.state = VRR_STATE_ACTIVE_VARIABLE;
9730 config.state = VRR_STATE_INACTIVE;
9734 new_crtc_state->freesync_config = config;
9737 static void reset_freesync_config_for_crtc(
9738 struct dm_crtc_state *new_crtc_state)
9740 new_crtc_state->vrr_supported = false;
9742 memset(&new_crtc_state->vrr_infopacket, 0,
9743 sizeof(new_crtc_state->vrr_infopacket));
9747 is_timing_unchanged_for_freesync(struct drm_crtc_state *old_crtc_state,
9748 struct drm_crtc_state *new_crtc_state)
9750 const struct drm_display_mode *old_mode, *new_mode;
9752 if (!old_crtc_state || !new_crtc_state)
9755 old_mode = &old_crtc_state->mode;
9756 new_mode = &new_crtc_state->mode;
9758 if (old_mode->clock == new_mode->clock &&
9759 old_mode->hdisplay == new_mode->hdisplay &&
9760 old_mode->vdisplay == new_mode->vdisplay &&
9761 old_mode->htotal == new_mode->htotal &&
9762 old_mode->vtotal != new_mode->vtotal &&
9763 old_mode->hsync_start == new_mode->hsync_start &&
9764 old_mode->vsync_start != new_mode->vsync_start &&
9765 old_mode->hsync_end == new_mode->hsync_end &&
9766 old_mode->vsync_end != new_mode->vsync_end &&
9767 old_mode->hskew == new_mode->hskew &&
9768 old_mode->vscan == new_mode->vscan &&
9769 (old_mode->vsync_end - old_mode->vsync_start) ==
9770 (new_mode->vsync_end - new_mode->vsync_start))
9776 static void set_freesync_fixed_config(struct dm_crtc_state *dm_new_crtc_state)
9779 struct drm_crtc_state *new_crtc_state = &dm_new_crtc_state->base;
9781 dm_new_crtc_state->freesync_config.state = VRR_STATE_ACTIVE_FIXED;
9783 num = (unsigned long long)new_crtc_state->mode.clock * 1000 * 1000000;
9784 den = (unsigned long long)new_crtc_state->mode.htotal *
9785 (unsigned long long)new_crtc_state->mode.vtotal;
9787 res = div_u64(num, den);
9788 dm_new_crtc_state->freesync_config.fixed_refresh_in_uhz = res;
9791 static int dm_update_crtc_state(struct amdgpu_display_manager *dm,
9792 struct drm_atomic_state *state,
9793 struct drm_crtc *crtc,
9794 struct drm_crtc_state *old_crtc_state,
9795 struct drm_crtc_state *new_crtc_state,
9797 bool *lock_and_validation_needed)
9799 struct dm_atomic_state *dm_state = NULL;
9800 struct dm_crtc_state *dm_old_crtc_state, *dm_new_crtc_state;
9801 struct dc_stream_state *new_stream;
9805 * TODO Move this code into dm_crtc_atomic_check once we get rid of dc_validation_set
9806 * update changed items
9808 struct amdgpu_crtc *acrtc = NULL;
9809 struct drm_connector *connector = NULL;
9810 struct amdgpu_dm_connector *aconnector = NULL;
9811 struct drm_connector_state *drm_new_conn_state = NULL, *drm_old_conn_state = NULL;
9812 struct dm_connector_state *dm_new_conn_state = NULL, *dm_old_conn_state = NULL;
9816 dm_old_crtc_state = to_dm_crtc_state(old_crtc_state);
9817 dm_new_crtc_state = to_dm_crtc_state(new_crtc_state);
9818 acrtc = to_amdgpu_crtc(crtc);
9819 connector = amdgpu_dm_find_first_crtc_matching_connector(state, crtc);
9821 aconnector = to_amdgpu_dm_connector(connector);
9823 /* TODO This hack should go away */
9824 if (connector && enable) {
9825 /* Make sure fake sink is created in plug-in scenario */
9826 drm_new_conn_state = drm_atomic_get_new_connector_state(state,
9828 drm_old_conn_state = drm_atomic_get_old_connector_state(state,
9831 if (IS_ERR(drm_new_conn_state)) {
9832 ret = PTR_ERR_OR_ZERO(drm_new_conn_state);
9836 dm_new_conn_state = to_dm_connector_state(drm_new_conn_state);
9837 dm_old_conn_state = to_dm_connector_state(drm_old_conn_state);
9839 if (!drm_atomic_crtc_needs_modeset(new_crtc_state))
9842 new_stream = create_validate_stream_for_sink(aconnector,
9843 &new_crtc_state->mode,
9845 dm_old_crtc_state->stream);
9848 * we can have no stream on ACTION_SET if a display
9849 * was disconnected during S3, in this case it is not an
9850 * error, the OS will be updated after detection, and
9851 * will do the right thing on next atomic commit
9855 DRM_DEBUG_DRIVER("%s: Failed to create new stream for crtc %d\n",
9856 __func__, acrtc->base.base.id);
9862 * TODO: Check VSDB bits to decide whether this should
9863 * be enabled or not.
9865 new_stream->triggered_crtc_reset.enabled =
9866 dm->force_timing_sync;
9868 dm_new_crtc_state->abm_level = dm_new_conn_state->abm_level;
9870 ret = fill_hdr_info_packet(drm_new_conn_state,
9871 &new_stream->hdr_static_metadata);
9876 * If we already removed the old stream from the context
9877 * (and set the new stream to NULL) then we can't reuse
9878 * the old stream even if the stream and scaling are unchanged.
9879 * We'll hit the BUG_ON and black screen.
9881 * TODO: Refactor this function to allow this check to work
9882 * in all conditions.
9884 if (amdgpu_freesync_vid_mode &&
9885 dm_new_crtc_state->stream &&
9886 is_timing_unchanged_for_freesync(new_crtc_state, old_crtc_state))
9889 if (dm_new_crtc_state->stream &&
9890 dc_is_stream_unchanged(new_stream, dm_old_crtc_state->stream) &&
9891 dc_is_stream_scaling_unchanged(new_stream, dm_old_crtc_state->stream)) {
9892 new_crtc_state->mode_changed = false;
9893 DRM_DEBUG_DRIVER("Mode change not required, setting mode_changed to %d",
9894 new_crtc_state->mode_changed);
9898 /* mode_changed flag may get updated above, need to check again */
9899 if (!drm_atomic_crtc_needs_modeset(new_crtc_state))
9902 drm_dbg_state(state->dev,
9903 "amdgpu_crtc id:%d crtc_state_flags: enable:%d, active:%d, planes_changed:%d, mode_changed:%d,active_changed:%d,connectors_changed:%d\n",
9905 new_crtc_state->enable,
9906 new_crtc_state->active,
9907 new_crtc_state->planes_changed,
9908 new_crtc_state->mode_changed,
9909 new_crtc_state->active_changed,
9910 new_crtc_state->connectors_changed);
9912 /* Remove stream for any changed/disabled CRTC */
9915 if (!dm_old_crtc_state->stream)
9918 /* Unset freesync video if it was active before */
9919 if (dm_old_crtc_state->freesync_config.state == VRR_STATE_ACTIVE_FIXED) {
9920 dm_new_crtc_state->freesync_config.state = VRR_STATE_INACTIVE;
9921 dm_new_crtc_state->freesync_config.fixed_refresh_in_uhz = 0;
9924 /* Now check if we should set freesync video mode */
9925 if (amdgpu_freesync_vid_mode && dm_new_crtc_state->stream &&
9926 dc_is_stream_unchanged(new_stream, dm_old_crtc_state->stream) &&
9927 dc_is_stream_scaling_unchanged(new_stream, dm_old_crtc_state->stream) &&
9928 is_timing_unchanged_for_freesync(new_crtc_state,
9930 new_crtc_state->mode_changed = false;
9932 "Mode change not required for front porch change, setting mode_changed to %d",
9933 new_crtc_state->mode_changed);
9935 set_freesync_fixed_config(dm_new_crtc_state);
9938 } else if (amdgpu_freesync_vid_mode && aconnector &&
9939 is_freesync_video_mode(&new_crtc_state->mode,
9941 struct drm_display_mode *high_mode;
9943 high_mode = get_highest_refresh_rate_mode(aconnector, false);
9944 if (!drm_mode_equal(&new_crtc_state->mode, high_mode))
9945 set_freesync_fixed_config(dm_new_crtc_state);
9948 ret = dm_atomic_get_state(state, &dm_state);
9952 DRM_DEBUG_DRIVER("Disabling DRM crtc: %d\n",
9955 /* i.e. reset mode */
9956 if (dc_state_remove_stream(
9959 dm_old_crtc_state->stream) != DC_OK) {
9964 dc_stream_release(dm_old_crtc_state->stream);
9965 dm_new_crtc_state->stream = NULL;
9967 reset_freesync_config_for_crtc(dm_new_crtc_state);
9969 *lock_and_validation_needed = true;
9971 } else {/* Add stream for any updated/enabled CRTC */
9973 * Quick fix to prevent NULL pointer on new_stream when
9974 * added MST connectors not found in existing crtc_state in the chained mode
9975 * TODO: need to dig out the root cause of that
9980 if (modereset_required(new_crtc_state))
9983 if (amdgpu_dm_crtc_modeset_required(new_crtc_state, new_stream,
9984 dm_old_crtc_state->stream)) {
9986 WARN_ON(dm_new_crtc_state->stream);
9988 ret = dm_atomic_get_state(state, &dm_state);
9992 dm_new_crtc_state->stream = new_stream;
9994 dc_stream_retain(new_stream);
9996 DRM_DEBUG_ATOMIC("Enabling DRM crtc: %d\n",
9999 if (dc_state_add_stream(
10002 dm_new_crtc_state->stream) != DC_OK) {
10007 *lock_and_validation_needed = true;
10012 /* Release extra reference */
10014 dc_stream_release(new_stream);
10017 * We want to do dc stream updates that do not require a
10018 * full modeset below.
10020 if (!(enable && connector && new_crtc_state->active))
10023 * Given above conditions, the dc state cannot be NULL because:
10024 * 1. We're in the process of enabling CRTCs (just been added
10025 * to the dc context, or already is on the context)
10026 * 2. Has a valid connector attached, and
10027 * 3. Is currently active and enabled.
10028 * => The dc stream state currently exists.
10030 BUG_ON(dm_new_crtc_state->stream == NULL);
10032 /* Scaling or underscan settings */
10033 if (is_scaling_state_different(dm_old_conn_state, dm_new_conn_state) ||
10034 drm_atomic_crtc_needs_modeset(new_crtc_state))
10035 update_stream_scaling_settings(
10036 &new_crtc_state->mode, dm_new_conn_state, dm_new_crtc_state->stream);
10039 dm_new_crtc_state->abm_level = dm_new_conn_state->abm_level;
10042 * Color management settings. We also update color properties
10043 * when a modeset is needed, to ensure it gets reprogrammed.
10045 if (dm_new_crtc_state->base.color_mgmt_changed ||
10046 dm_old_crtc_state->regamma_tf != dm_new_crtc_state->regamma_tf ||
10047 drm_atomic_crtc_needs_modeset(new_crtc_state)) {
10048 ret = amdgpu_dm_update_crtc_color_mgmt(dm_new_crtc_state);
10053 /* Update Freesync settings. */
10054 get_freesync_config_for_crtc(dm_new_crtc_state,
10055 dm_new_conn_state);
10061 dc_stream_release(new_stream);
10065 static bool should_reset_plane(struct drm_atomic_state *state,
10066 struct drm_plane *plane,
10067 struct drm_plane_state *old_plane_state,
10068 struct drm_plane_state *new_plane_state)
10070 struct drm_plane *other;
10071 struct drm_plane_state *old_other_state, *new_other_state;
10072 struct drm_crtc_state *new_crtc_state;
10073 struct amdgpu_device *adev = drm_to_adev(plane->dev);
10077 * TODO: Remove this hack for all asics once it proves that the
10078 * fast updates works fine on DCN3.2+.
10080 if (amdgpu_ip_version(adev, DCE_HWIP, 0) < IP_VERSION(3, 2, 0) &&
10081 state->allow_modeset)
10084 /* Exit early if we know that we're adding or removing the plane. */
10085 if (old_plane_state->crtc != new_plane_state->crtc)
10088 /* old crtc == new_crtc == NULL, plane not in context. */
10089 if (!new_plane_state->crtc)
10093 drm_atomic_get_new_crtc_state(state, new_plane_state->crtc);
10095 if (!new_crtc_state)
10098 /* CRTC Degamma changes currently require us to recreate planes. */
10099 if (new_crtc_state->color_mgmt_changed)
10102 if (drm_atomic_crtc_needs_modeset(new_crtc_state))
10106 * If there are any new primary or overlay planes being added or
10107 * removed then the z-order can potentially change. To ensure
10108 * correct z-order and pipe acquisition the current DC architecture
10109 * requires us to remove and recreate all existing planes.
10111 * TODO: Come up with a more elegant solution for this.
10113 for_each_oldnew_plane_in_state(state, other, old_other_state, new_other_state, i) {
10114 struct amdgpu_framebuffer *old_afb, *new_afb;
10115 struct dm_plane_state *dm_new_other_state, *dm_old_other_state;
10117 dm_new_other_state = to_dm_plane_state(new_other_state);
10118 dm_old_other_state = to_dm_plane_state(old_other_state);
10120 if (other->type == DRM_PLANE_TYPE_CURSOR)
10123 if (old_other_state->crtc != new_plane_state->crtc &&
10124 new_other_state->crtc != new_plane_state->crtc)
10127 if (old_other_state->crtc != new_other_state->crtc)
10130 /* Src/dst size and scaling updates. */
10131 if (old_other_state->src_w != new_other_state->src_w ||
10132 old_other_state->src_h != new_other_state->src_h ||
10133 old_other_state->crtc_w != new_other_state->crtc_w ||
10134 old_other_state->crtc_h != new_other_state->crtc_h)
10137 /* Rotation / mirroring updates. */
10138 if (old_other_state->rotation != new_other_state->rotation)
10141 /* Blending updates. */
10142 if (old_other_state->pixel_blend_mode !=
10143 new_other_state->pixel_blend_mode)
10146 /* Alpha updates. */
10147 if (old_other_state->alpha != new_other_state->alpha)
10150 /* Colorspace changes. */
10151 if (old_other_state->color_range != new_other_state->color_range ||
10152 old_other_state->color_encoding != new_other_state->color_encoding)
10155 /* HDR/Transfer Function changes. */
10156 if (dm_old_other_state->degamma_tf != dm_new_other_state->degamma_tf ||
10157 dm_old_other_state->degamma_lut != dm_new_other_state->degamma_lut ||
10158 dm_old_other_state->hdr_mult != dm_new_other_state->hdr_mult ||
10159 dm_old_other_state->ctm != dm_new_other_state->ctm ||
10160 dm_old_other_state->shaper_lut != dm_new_other_state->shaper_lut ||
10161 dm_old_other_state->shaper_tf != dm_new_other_state->shaper_tf ||
10162 dm_old_other_state->lut3d != dm_new_other_state->lut3d ||
10163 dm_old_other_state->blend_lut != dm_new_other_state->blend_lut ||
10164 dm_old_other_state->blend_tf != dm_new_other_state->blend_tf)
10167 /* Framebuffer checks fall at the end. */
10168 if (!old_other_state->fb || !new_other_state->fb)
10171 /* Pixel format changes can require bandwidth updates. */
10172 if (old_other_state->fb->format != new_other_state->fb->format)
10175 old_afb = (struct amdgpu_framebuffer *)old_other_state->fb;
10176 new_afb = (struct amdgpu_framebuffer *)new_other_state->fb;
10178 /* Tiling and DCC changes also require bandwidth updates. */
10179 if (old_afb->tiling_flags != new_afb->tiling_flags ||
10180 old_afb->base.modifier != new_afb->base.modifier)
10187 static int dm_check_cursor_fb(struct amdgpu_crtc *new_acrtc,
10188 struct drm_plane_state *new_plane_state,
10189 struct drm_framebuffer *fb)
10191 struct amdgpu_device *adev = drm_to_adev(new_acrtc->base.dev);
10192 struct amdgpu_framebuffer *afb = to_amdgpu_framebuffer(fb);
10193 unsigned int pitch;
10196 if (fb->width > new_acrtc->max_cursor_width ||
10197 fb->height > new_acrtc->max_cursor_height) {
10198 DRM_DEBUG_ATOMIC("Bad cursor FB size %dx%d\n",
10199 new_plane_state->fb->width,
10200 new_plane_state->fb->height);
10203 if (new_plane_state->src_w != fb->width << 16 ||
10204 new_plane_state->src_h != fb->height << 16) {
10205 DRM_DEBUG_ATOMIC("Cropping not supported for cursor plane\n");
10209 /* Pitch in pixels */
10210 pitch = fb->pitches[0] / fb->format->cpp[0];
10212 if (fb->width != pitch) {
10213 DRM_DEBUG_ATOMIC("Cursor FB width %d doesn't match pitch %d",
10222 /* FB pitch is supported by cursor plane */
10225 DRM_DEBUG_ATOMIC("Bad cursor FB pitch %d px\n", pitch);
10229 /* Core DRM takes care of checking FB modifiers, so we only need to
10230 * check tiling flags when the FB doesn't have a modifier.
10232 if (!(fb->flags & DRM_MODE_FB_MODIFIERS)) {
10233 if (adev->family < AMDGPU_FAMILY_AI) {
10234 linear = AMDGPU_TILING_GET(afb->tiling_flags, ARRAY_MODE) != DC_ARRAY_2D_TILED_THIN1 &&
10235 AMDGPU_TILING_GET(afb->tiling_flags, ARRAY_MODE) != DC_ARRAY_1D_TILED_THIN1 &&
10236 AMDGPU_TILING_GET(afb->tiling_flags, MICRO_TILE_MODE) == 0;
10238 linear = AMDGPU_TILING_GET(afb->tiling_flags, SWIZZLE_MODE) == 0;
10241 DRM_DEBUG_ATOMIC("Cursor FB not linear");
10249 static int dm_update_plane_state(struct dc *dc,
10250 struct drm_atomic_state *state,
10251 struct drm_plane *plane,
10252 struct drm_plane_state *old_plane_state,
10253 struct drm_plane_state *new_plane_state,
10255 bool *lock_and_validation_needed,
10256 bool *is_top_most_overlay)
10259 struct dm_atomic_state *dm_state = NULL;
10260 struct drm_crtc *new_plane_crtc, *old_plane_crtc;
10261 struct drm_crtc_state *old_crtc_state, *new_crtc_state;
10262 struct dm_crtc_state *dm_new_crtc_state, *dm_old_crtc_state;
10263 struct dm_plane_state *dm_new_plane_state, *dm_old_plane_state;
10264 struct amdgpu_crtc *new_acrtc;
10269 new_plane_crtc = new_plane_state->crtc;
10270 old_plane_crtc = old_plane_state->crtc;
10271 dm_new_plane_state = to_dm_plane_state(new_plane_state);
10272 dm_old_plane_state = to_dm_plane_state(old_plane_state);
10274 if (plane->type == DRM_PLANE_TYPE_CURSOR) {
10275 if (!enable || !new_plane_crtc ||
10276 drm_atomic_plane_disabling(plane->state, new_plane_state))
10279 new_acrtc = to_amdgpu_crtc(new_plane_crtc);
10281 if (new_plane_state->src_x != 0 || new_plane_state->src_y != 0) {
10282 DRM_DEBUG_ATOMIC("Cropping not supported for cursor plane\n");
10286 if (new_plane_state->fb) {
10287 ret = dm_check_cursor_fb(new_acrtc, new_plane_state,
10288 new_plane_state->fb);
10296 needs_reset = should_reset_plane(state, plane, old_plane_state,
10299 /* Remove any changed/removed planes */
10304 if (!old_plane_crtc)
10307 old_crtc_state = drm_atomic_get_old_crtc_state(
10308 state, old_plane_crtc);
10309 dm_old_crtc_state = to_dm_crtc_state(old_crtc_state);
10311 if (!dm_old_crtc_state->stream)
10314 DRM_DEBUG_ATOMIC("Disabling DRM plane: %d on DRM crtc %d\n",
10315 plane->base.id, old_plane_crtc->base.id);
10317 ret = dm_atomic_get_state(state, &dm_state);
10321 if (!dc_state_remove_plane(
10323 dm_old_crtc_state->stream,
10324 dm_old_plane_state->dc_state,
10325 dm_state->context)) {
10330 if (dm_old_plane_state->dc_state)
10331 dc_plane_state_release(dm_old_plane_state->dc_state);
10333 dm_new_plane_state->dc_state = NULL;
10335 *lock_and_validation_needed = true;
10337 } else { /* Add new planes */
10338 struct dc_plane_state *dc_new_plane_state;
10340 if (drm_atomic_plane_disabling(plane->state, new_plane_state))
10343 if (!new_plane_crtc)
10346 new_crtc_state = drm_atomic_get_new_crtc_state(state, new_plane_crtc);
10347 dm_new_crtc_state = to_dm_crtc_state(new_crtc_state);
10349 if (!dm_new_crtc_state->stream)
10355 ret = amdgpu_dm_plane_helper_check_state(new_plane_state, new_crtc_state);
10359 WARN_ON(dm_new_plane_state->dc_state);
10361 dc_new_plane_state = dc_create_plane_state(dc);
10362 if (!dc_new_plane_state)
10365 /* Block top most plane from being a video plane */
10366 if (plane->type == DRM_PLANE_TYPE_OVERLAY) {
10367 if (amdgpu_dm_plane_is_video_format(new_plane_state->fb->format->format) && *is_top_most_overlay)
10370 *is_top_most_overlay = false;
10373 DRM_DEBUG_ATOMIC("Enabling DRM plane: %d on DRM crtc %d\n",
10374 plane->base.id, new_plane_crtc->base.id);
10376 ret = fill_dc_plane_attributes(
10377 drm_to_adev(new_plane_crtc->dev),
10378 dc_new_plane_state,
10382 dc_plane_state_release(dc_new_plane_state);
10386 ret = dm_atomic_get_state(state, &dm_state);
10388 dc_plane_state_release(dc_new_plane_state);
10393 * Any atomic check errors that occur after this will
10394 * not need a release. The plane state will be attached
10395 * to the stream, and therefore part of the atomic
10396 * state. It'll be released when the atomic state is
10399 if (!dc_state_add_plane(
10401 dm_new_crtc_state->stream,
10402 dc_new_plane_state,
10403 dm_state->context)) {
10405 dc_plane_state_release(dc_new_plane_state);
10409 dm_new_plane_state->dc_state = dc_new_plane_state;
10411 dm_new_crtc_state->mpo_requested |= (plane->type == DRM_PLANE_TYPE_OVERLAY);
10413 /* Tell DC to do a full surface update every time there
10414 * is a plane change. Inefficient, but works for now.
10416 dm_new_plane_state->dc_state->update_flags.bits.full_update = 1;
10418 *lock_and_validation_needed = true;
10425 static void dm_get_oriented_plane_size(struct drm_plane_state *plane_state,
10426 int *src_w, int *src_h)
10428 switch (plane_state->rotation & DRM_MODE_ROTATE_MASK) {
10429 case DRM_MODE_ROTATE_90:
10430 case DRM_MODE_ROTATE_270:
10431 *src_w = plane_state->src_h >> 16;
10432 *src_h = plane_state->src_w >> 16;
10434 case DRM_MODE_ROTATE_0:
10435 case DRM_MODE_ROTATE_180:
10437 *src_w = plane_state->src_w >> 16;
10438 *src_h = plane_state->src_h >> 16;
10444 dm_get_plane_scale(struct drm_plane_state *plane_state,
10445 int *out_plane_scale_w, int *out_plane_scale_h)
10447 int plane_src_w, plane_src_h;
10449 dm_get_oriented_plane_size(plane_state, &plane_src_w, &plane_src_h);
10450 *out_plane_scale_w = plane_state->crtc_w * 1000 / plane_src_w;
10451 *out_plane_scale_h = plane_state->crtc_h * 1000 / plane_src_h;
10454 static int dm_check_crtc_cursor(struct drm_atomic_state *state,
10455 struct drm_crtc *crtc,
10456 struct drm_crtc_state *new_crtc_state)
10458 struct drm_plane *cursor = crtc->cursor, *plane, *underlying;
10459 struct drm_plane_state *old_plane_state, *new_plane_state;
10460 struct drm_plane_state *new_cursor_state, *new_underlying_state;
10462 int cursor_scale_w, cursor_scale_h, underlying_scale_w, underlying_scale_h;
10463 bool any_relevant_change = false;
10465 /* On DCE and DCN there is no dedicated hardware cursor plane. We get a
10466 * cursor per pipe but it's going to inherit the scaling and
10467 * positioning from the underlying pipe. Check the cursor plane's
10468 * blending properties match the underlying planes'.
10471 /* If no plane was enabled or changed scaling, no need to check again */
10472 for_each_oldnew_plane_in_state(state, plane, old_plane_state, new_plane_state, i) {
10473 int new_scale_w, new_scale_h, old_scale_w, old_scale_h;
10475 if (!new_plane_state || !new_plane_state->fb || new_plane_state->crtc != crtc)
10478 if (!old_plane_state || !old_plane_state->fb || old_plane_state->crtc != crtc) {
10479 any_relevant_change = true;
10483 if (new_plane_state->fb == old_plane_state->fb &&
10484 new_plane_state->crtc_w == old_plane_state->crtc_w &&
10485 new_plane_state->crtc_h == old_plane_state->crtc_h)
10488 dm_get_plane_scale(new_plane_state, &new_scale_w, &new_scale_h);
10489 dm_get_plane_scale(old_plane_state, &old_scale_w, &old_scale_h);
10491 if (new_scale_w != old_scale_w || new_scale_h != old_scale_h) {
10492 any_relevant_change = true;
10497 if (!any_relevant_change)
10500 new_cursor_state = drm_atomic_get_plane_state(state, cursor);
10501 if (IS_ERR(new_cursor_state))
10502 return PTR_ERR(new_cursor_state);
10504 if (!new_cursor_state->fb)
10507 dm_get_plane_scale(new_cursor_state, &cursor_scale_w, &cursor_scale_h);
10509 /* Need to check all enabled planes, even if this commit doesn't change
10512 i = drm_atomic_add_affected_planes(state, crtc);
10516 for_each_new_plane_in_state_reverse(state, underlying, new_underlying_state, i) {
10517 /* Narrow down to non-cursor planes on the same CRTC as the cursor */
10518 if (new_underlying_state->crtc != crtc || underlying == crtc->cursor)
10521 /* Ignore disabled planes */
10522 if (!new_underlying_state->fb)
10525 dm_get_plane_scale(new_underlying_state,
10526 &underlying_scale_w, &underlying_scale_h);
10528 if (cursor_scale_w != underlying_scale_w ||
10529 cursor_scale_h != underlying_scale_h) {
10530 drm_dbg_atomic(crtc->dev,
10531 "Cursor [PLANE:%d:%s] scaling doesn't match underlying [PLANE:%d:%s]\n",
10532 cursor->base.id, cursor->name, underlying->base.id, underlying->name);
10536 /* If this plane covers the whole CRTC, no need to check planes underneath */
10537 if (new_underlying_state->crtc_x <= 0 &&
10538 new_underlying_state->crtc_y <= 0 &&
10539 new_underlying_state->crtc_x + new_underlying_state->crtc_w >= new_crtc_state->mode.hdisplay &&
10540 new_underlying_state->crtc_y + new_underlying_state->crtc_h >= new_crtc_state->mode.vdisplay)
10547 static int add_affected_mst_dsc_crtcs(struct drm_atomic_state *state, struct drm_crtc *crtc)
10549 struct drm_connector *connector;
10550 struct drm_connector_state *conn_state, *old_conn_state;
10551 struct amdgpu_dm_connector *aconnector = NULL;
10554 for_each_oldnew_connector_in_state(state, connector, old_conn_state, conn_state, i) {
10555 if (!conn_state->crtc)
10556 conn_state = old_conn_state;
10558 if (conn_state->crtc != crtc)
10561 if (connector->connector_type == DRM_MODE_CONNECTOR_WRITEBACK)
10564 aconnector = to_amdgpu_dm_connector(connector);
10565 if (!aconnector->mst_output_port || !aconnector->mst_root)
10574 return drm_dp_mst_add_affected_dsc_crtcs(state, &aconnector->mst_root->mst_mgr);
10578 * amdgpu_dm_atomic_check() - Atomic check implementation for AMDgpu DM.
10580 * @dev: The DRM device
10581 * @state: The atomic state to commit
10583 * Validate that the given atomic state is programmable by DC into hardware.
10584 * This involves constructing a &struct dc_state reflecting the new hardware
10585 * state we wish to commit, then querying DC to see if it is programmable. It's
10586 * important not to modify the existing DC state. Otherwise, atomic_check
10587 * may unexpectedly commit hardware changes.
10589 * When validating the DC state, it's important that the right locks are
10590 * acquired. For full updates case which removes/adds/updates streams on one
10591 * CRTC while flipping on another CRTC, acquiring global lock will guarantee
10592 * that any such full update commit will wait for completion of any outstanding
10593 * flip using DRMs synchronization events.
10595 * Note that DM adds the affected connectors for all CRTCs in state, when that
10596 * might not seem necessary. This is because DC stream creation requires the
10597 * DC sink, which is tied to the DRM connector state. Cleaning this up should
10598 * be possible but non-trivial - a possible TODO item.
10600 * Return: -Error code if validation failed.
10602 static int amdgpu_dm_atomic_check(struct drm_device *dev,
10603 struct drm_atomic_state *state)
10605 struct amdgpu_device *adev = drm_to_adev(dev);
10606 struct dm_atomic_state *dm_state = NULL;
10607 struct dc *dc = adev->dm.dc;
10608 struct drm_connector *connector;
10609 struct drm_connector_state *old_con_state, *new_con_state;
10610 struct drm_crtc *crtc;
10611 struct drm_crtc_state *old_crtc_state, *new_crtc_state;
10612 struct drm_plane *plane;
10613 struct drm_plane_state *old_plane_state, *new_plane_state;
10614 enum dc_status status;
10616 bool lock_and_validation_needed = false;
10617 bool is_top_most_overlay = true;
10618 struct dm_crtc_state *dm_old_crtc_state, *dm_new_crtc_state;
10619 struct drm_dp_mst_topology_mgr *mgr;
10620 struct drm_dp_mst_topology_state *mst_state;
10621 struct dsc_mst_fairness_vars vars[MAX_PIPES] = {0};
10623 trace_amdgpu_dm_atomic_check_begin(state);
10625 ret = drm_atomic_helper_check_modeset(dev, state);
10627 DRM_DEBUG_DRIVER("drm_atomic_helper_check_modeset() failed\n");
10631 /* Check connector changes */
10632 for_each_oldnew_connector_in_state(state, connector, old_con_state, new_con_state, i) {
10633 struct dm_connector_state *dm_old_con_state = to_dm_connector_state(old_con_state);
10634 struct dm_connector_state *dm_new_con_state = to_dm_connector_state(new_con_state);
10636 /* Skip connectors that are disabled or part of modeset already. */
10637 if (!new_con_state->crtc)
10640 new_crtc_state = drm_atomic_get_crtc_state(state, new_con_state->crtc);
10641 if (IS_ERR(new_crtc_state)) {
10642 DRM_DEBUG_DRIVER("drm_atomic_get_crtc_state() failed\n");
10643 ret = PTR_ERR(new_crtc_state);
10647 if (dm_old_con_state->abm_level != dm_new_con_state->abm_level ||
10648 dm_old_con_state->scaling != dm_new_con_state->scaling)
10649 new_crtc_state->connectors_changed = true;
10652 if (dc_resource_is_dsc_encoding_supported(dc)) {
10653 for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) {
10654 if (drm_atomic_crtc_needs_modeset(new_crtc_state)) {
10655 ret = add_affected_mst_dsc_crtcs(state, crtc);
10657 DRM_DEBUG_DRIVER("add_affected_mst_dsc_crtcs() failed\n");
10663 for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) {
10664 dm_old_crtc_state = to_dm_crtc_state(old_crtc_state);
10666 if (!drm_atomic_crtc_needs_modeset(new_crtc_state) &&
10667 !new_crtc_state->color_mgmt_changed &&
10668 old_crtc_state->vrr_enabled == new_crtc_state->vrr_enabled &&
10669 dm_old_crtc_state->dsc_force_changed == false)
10672 ret = amdgpu_dm_verify_lut_sizes(new_crtc_state);
10674 DRM_DEBUG_DRIVER("amdgpu_dm_verify_lut_sizes() failed\n");
10678 if (!new_crtc_state->enable)
10681 ret = drm_atomic_add_affected_connectors(state, crtc);
10683 DRM_DEBUG_DRIVER("drm_atomic_add_affected_connectors() failed\n");
10687 ret = drm_atomic_add_affected_planes(state, crtc);
10689 DRM_DEBUG_DRIVER("drm_atomic_add_affected_planes() failed\n");
10693 if (dm_old_crtc_state->dsc_force_changed)
10694 new_crtc_state->mode_changed = true;
10698 * Add all primary and overlay planes on the CRTC to the state
10699 * whenever a plane is enabled to maintain correct z-ordering
10700 * and to enable fast surface updates.
10702 drm_for_each_crtc(crtc, dev) {
10703 bool modified = false;
10705 for_each_oldnew_plane_in_state(state, plane, old_plane_state, new_plane_state, i) {
10706 if (plane->type == DRM_PLANE_TYPE_CURSOR)
10709 if (new_plane_state->crtc == crtc ||
10710 old_plane_state->crtc == crtc) {
10719 drm_for_each_plane_mask(plane, state->dev, crtc->state->plane_mask) {
10720 if (plane->type == DRM_PLANE_TYPE_CURSOR)
10724 drm_atomic_get_plane_state(state, plane);
10726 if (IS_ERR(new_plane_state)) {
10727 ret = PTR_ERR(new_plane_state);
10728 DRM_DEBUG_DRIVER("new_plane_state is BAD\n");
10735 * DC consults the zpos (layer_index in DC terminology) to determine the
10736 * hw plane on which to enable the hw cursor (see
10737 * `dcn10_can_pipe_disable_cursor`). By now, all modified planes are in
10738 * atomic state, so call drm helper to normalize zpos.
10740 ret = drm_atomic_normalize_zpos(dev, state);
10742 drm_dbg(dev, "drm_atomic_normalize_zpos() failed\n");
10746 /* Remove exiting planes if they are modified */
10747 for_each_oldnew_plane_in_state_reverse(state, plane, old_plane_state, new_plane_state, i) {
10748 if (old_plane_state->fb && new_plane_state->fb &&
10749 get_mem_type(old_plane_state->fb) !=
10750 get_mem_type(new_plane_state->fb))
10751 lock_and_validation_needed = true;
10753 ret = dm_update_plane_state(dc, state, plane,
10757 &lock_and_validation_needed,
10758 &is_top_most_overlay);
10760 DRM_DEBUG_DRIVER("dm_update_plane_state() failed\n");
10765 /* Disable all crtcs which require disable */
10766 for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) {
10767 ret = dm_update_crtc_state(&adev->dm, state, crtc,
10771 &lock_and_validation_needed);
10773 DRM_DEBUG_DRIVER("DISABLE: dm_update_crtc_state() failed\n");
10778 /* Enable all crtcs which require enable */
10779 for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) {
10780 ret = dm_update_crtc_state(&adev->dm, state, crtc,
10784 &lock_and_validation_needed);
10786 DRM_DEBUG_DRIVER("ENABLE: dm_update_crtc_state() failed\n");
10791 /* Add new/modified planes */
10792 for_each_oldnew_plane_in_state_reverse(state, plane, old_plane_state, new_plane_state, i) {
10793 ret = dm_update_plane_state(dc, state, plane,
10797 &lock_and_validation_needed,
10798 &is_top_most_overlay);
10800 DRM_DEBUG_DRIVER("dm_update_plane_state() failed\n");
10805 if (dc_resource_is_dsc_encoding_supported(dc)) {
10806 ret = pre_validate_dsc(state, &dm_state, vars);
10811 /* Run this here since we want to validate the streams we created */
10812 ret = drm_atomic_helper_check_planes(dev, state);
10814 DRM_DEBUG_DRIVER("drm_atomic_helper_check_planes() failed\n");
10818 for_each_new_crtc_in_state(state, crtc, new_crtc_state, i) {
10819 dm_new_crtc_state = to_dm_crtc_state(new_crtc_state);
10820 if (dm_new_crtc_state->mpo_requested)
10821 DRM_DEBUG_DRIVER("MPO enablement requested on crtc:[%p]\n", crtc);
10824 /* Check cursor planes scaling */
10825 for_each_new_crtc_in_state(state, crtc, new_crtc_state, i) {
10826 ret = dm_check_crtc_cursor(state, crtc, new_crtc_state);
10828 DRM_DEBUG_DRIVER("dm_check_crtc_cursor() failed\n");
10833 if (state->legacy_cursor_update) {
10835 * This is a fast cursor update coming from the plane update
10836 * helper, check if it can be done asynchronously for better
10839 state->async_update =
10840 !drm_atomic_helper_async_check(dev, state);
10843 * Skip the remaining global validation if this is an async
10844 * update. Cursor updates can be done without affecting
10845 * state or bandwidth calcs and this avoids the performance
10846 * penalty of locking the private state object and
10847 * allocating a new dc_state.
10849 if (state->async_update)
10853 /* Check scaling and underscan changes*/
10854 /* TODO Removed scaling changes validation due to inability to commit
10855 * new stream into context w\o causing full reset. Need to
10856 * decide how to handle.
10858 for_each_oldnew_connector_in_state(state, connector, old_con_state, new_con_state, i) {
10859 struct dm_connector_state *dm_old_con_state = to_dm_connector_state(old_con_state);
10860 struct dm_connector_state *dm_new_con_state = to_dm_connector_state(new_con_state);
10861 struct amdgpu_crtc *acrtc = to_amdgpu_crtc(dm_new_con_state->base.crtc);
10863 /* Skip any modesets/resets */
10864 if (!acrtc || drm_atomic_crtc_needs_modeset(
10865 drm_atomic_get_new_crtc_state(state, &acrtc->base)))
10868 /* Skip any thing not scale or underscan changes */
10869 if (!is_scaling_state_different(dm_new_con_state, dm_old_con_state))
10872 lock_and_validation_needed = true;
10875 /* set the slot info for each mst_state based on the link encoding format */
10876 for_each_new_mst_mgr_in_state(state, mgr, mst_state, i) {
10877 struct amdgpu_dm_connector *aconnector;
10878 struct drm_connector *connector;
10879 struct drm_connector_list_iter iter;
10880 u8 link_coding_cap;
10882 drm_connector_list_iter_begin(dev, &iter);
10883 drm_for_each_connector_iter(connector, &iter) {
10884 if (connector->index == mst_state->mgr->conn_base_id) {
10885 aconnector = to_amdgpu_dm_connector(connector);
10886 link_coding_cap = dc_link_dp_mst_decide_link_encoding_format(aconnector->dc_link);
10887 drm_dp_mst_update_slots(mst_state, link_coding_cap);
10892 drm_connector_list_iter_end(&iter);
10896 * Streams and planes are reset when there are changes that affect
10897 * bandwidth. Anything that affects bandwidth needs to go through
10898 * DC global validation to ensure that the configuration can be applied
10901 * We have to currently stall out here in atomic_check for outstanding
10902 * commits to finish in this case because our IRQ handlers reference
10903 * DRM state directly - we can end up disabling interrupts too early
10906 * TODO: Remove this stall and drop DM state private objects.
10908 if (lock_and_validation_needed) {
10909 ret = dm_atomic_get_state(state, &dm_state);
10911 DRM_DEBUG_DRIVER("dm_atomic_get_state() failed\n");
10915 ret = do_aquire_global_lock(dev, state);
10917 DRM_DEBUG_DRIVER("do_aquire_global_lock() failed\n");
10921 if (dc_resource_is_dsc_encoding_supported(dc)) {
10922 ret = compute_mst_dsc_configs_for_state(state, dm_state->context, vars);
10924 DRM_DEBUG_DRIVER("compute_mst_dsc_configs_for_state() failed\n");
10930 ret = dm_update_mst_vcpi_slots_for_dsc(state, dm_state->context, vars);
10932 DRM_DEBUG_DRIVER("dm_update_mst_vcpi_slots_for_dsc() failed\n");
10937 * Perform validation of MST topology in the state:
10938 * We need to perform MST atomic check before calling
10939 * dc_validate_global_state(), or there is a chance
10940 * to get stuck in an infinite loop and hang eventually.
10942 ret = drm_dp_mst_atomic_check(state);
10944 DRM_DEBUG_DRIVER("drm_dp_mst_atomic_check() failed\n");
10947 status = dc_validate_global_state(dc, dm_state->context, true);
10948 if (status != DC_OK) {
10949 DRM_DEBUG_DRIVER("DC global validation failure: %s (%d)",
10950 dc_status_to_str(status), status);
10956 * The commit is a fast update. Fast updates shouldn't change
10957 * the DC context, affect global validation, and can have their
10958 * commit work done in parallel with other commits not touching
10959 * the same resource. If we have a new DC context as part of
10960 * the DM atomic state from validation we need to free it and
10961 * retain the existing one instead.
10963 * Furthermore, since the DM atomic state only contains the DC
10964 * context and can safely be annulled, we can free the state
10965 * and clear the associated private object now to free
10966 * some memory and avoid a possible use-after-free later.
10969 for (i = 0; i < state->num_private_objs; i++) {
10970 struct drm_private_obj *obj = state->private_objs[i].ptr;
10972 if (obj->funcs == adev->dm.atomic_obj.funcs) {
10973 int j = state->num_private_objs-1;
10975 dm_atomic_destroy_state(obj,
10976 state->private_objs[i].state);
10978 /* If i is not at the end of the array then the
10979 * last element needs to be moved to where i was
10980 * before the array can safely be truncated.
10983 state->private_objs[i] =
10984 state->private_objs[j];
10986 state->private_objs[j].ptr = NULL;
10987 state->private_objs[j].state = NULL;
10988 state->private_objs[j].old_state = NULL;
10989 state->private_objs[j].new_state = NULL;
10991 state->num_private_objs = j;
10997 /* Store the overall update type for use later in atomic check. */
10998 for_each_new_crtc_in_state(state, crtc, new_crtc_state, i) {
10999 struct dm_crtc_state *dm_new_crtc_state =
11000 to_dm_crtc_state(new_crtc_state);
11003 * Only allow async flips for fast updates that don't change
11004 * the FB pitch, the DCC state, rotation, etc.
11006 if (new_crtc_state->async_flip && lock_and_validation_needed) {
11007 drm_dbg_atomic(crtc->dev,
11008 "[CRTC:%d:%s] async flips are only supported for fast updates\n",
11009 crtc->base.id, crtc->name);
11014 dm_new_crtc_state->update_type = lock_and_validation_needed ?
11015 UPDATE_TYPE_FULL : UPDATE_TYPE_FAST;
11018 /* Must be success */
11021 trace_amdgpu_dm_atomic_check_finish(state, ret);
11026 if (ret == -EDEADLK)
11027 DRM_DEBUG_DRIVER("Atomic check stopped to avoid deadlock.\n");
11028 else if (ret == -EINTR || ret == -EAGAIN || ret == -ERESTARTSYS)
11029 DRM_DEBUG_DRIVER("Atomic check stopped due to signal.\n");
11031 DRM_DEBUG_DRIVER("Atomic check failed with err: %d\n", ret);
11033 trace_amdgpu_dm_atomic_check_finish(state, ret);
11038 static bool is_dp_capable_without_timing_msa(struct dc *dc,
11039 struct amdgpu_dm_connector *amdgpu_dm_connector)
11042 bool capable = false;
11044 if (amdgpu_dm_connector->dc_link &&
11045 dm_helpers_dp_read_dpcd(
11047 amdgpu_dm_connector->dc_link,
11048 DP_DOWN_STREAM_PORT_COUNT,
11050 sizeof(dpcd_data))) {
11051 capable = (dpcd_data & DP_MSA_TIMING_PAR_IGNORED) ? true:false;
11057 static bool dm_edid_parser_send_cea(struct amdgpu_display_manager *dm,
11058 unsigned int offset,
11059 unsigned int total_length,
11061 unsigned int length,
11062 struct amdgpu_hdmi_vsdb_info *vsdb)
11065 union dmub_rb_cmd cmd;
11066 struct dmub_cmd_send_edid_cea *input;
11067 struct dmub_cmd_edid_cea_output *output;
11069 if (length > DMUB_EDID_CEA_DATA_CHUNK_BYTES)
11072 memset(&cmd, 0, sizeof(cmd));
11074 input = &cmd.edid_cea.data.input;
11076 cmd.edid_cea.header.type = DMUB_CMD__EDID_CEA;
11077 cmd.edid_cea.header.sub_type = 0;
11078 cmd.edid_cea.header.payload_bytes =
11079 sizeof(cmd.edid_cea) - sizeof(cmd.edid_cea.header);
11080 input->offset = offset;
11081 input->length = length;
11082 input->cea_total_length = total_length;
11083 memcpy(input->payload, data, length);
11085 res = dc_wake_and_execute_dmub_cmd(dm->dc->ctx, &cmd, DM_DMUB_WAIT_TYPE_WAIT_WITH_REPLY);
11087 DRM_ERROR("EDID CEA parser failed\n");
11091 output = &cmd.edid_cea.data.output;
11093 if (output->type == DMUB_CMD__EDID_CEA_ACK) {
11094 if (!output->ack.success) {
11095 DRM_ERROR("EDID CEA ack failed at offset %d\n",
11096 output->ack.offset);
11098 } else if (output->type == DMUB_CMD__EDID_CEA_AMD_VSDB) {
11099 if (!output->amd_vsdb.vsdb_found)
11102 vsdb->freesync_supported = output->amd_vsdb.freesync_supported;
11103 vsdb->amd_vsdb_version = output->amd_vsdb.amd_vsdb_version;
11104 vsdb->min_refresh_rate_hz = output->amd_vsdb.min_frame_rate;
11105 vsdb->max_refresh_rate_hz = output->amd_vsdb.max_frame_rate;
11107 DRM_WARN("Unknown EDID CEA parser results\n");
11114 static bool parse_edid_cea_dmcu(struct amdgpu_display_manager *dm,
11115 u8 *edid_ext, int len,
11116 struct amdgpu_hdmi_vsdb_info *vsdb_info)
11120 /* send extension block to DMCU for parsing */
11121 for (i = 0; i < len; i += 8) {
11125 /* send 8 bytes a time */
11126 if (!dc_edid_parser_send_cea(dm->dc, i, len, &edid_ext[i], 8))
11130 /* EDID block sent completed, expect result */
11131 int version, min_rate, max_rate;
11133 res = dc_edid_parser_recv_amd_vsdb(dm->dc, &version, &min_rate, &max_rate);
11135 /* amd vsdb found */
11136 vsdb_info->freesync_supported = 1;
11137 vsdb_info->amd_vsdb_version = version;
11138 vsdb_info->min_refresh_rate_hz = min_rate;
11139 vsdb_info->max_refresh_rate_hz = max_rate;
11147 res = dc_edid_parser_recv_cea_ack(dm->dc, &offset);
11155 static bool parse_edid_cea_dmub(struct amdgpu_display_manager *dm,
11156 u8 *edid_ext, int len,
11157 struct amdgpu_hdmi_vsdb_info *vsdb_info)
11161 /* send extension block to DMCU for parsing */
11162 for (i = 0; i < len; i += 8) {
11163 /* send 8 bytes a time */
11164 if (!dm_edid_parser_send_cea(dm, i, len, &edid_ext[i], 8, vsdb_info))
11168 return vsdb_info->freesync_supported;
11171 static bool parse_edid_cea(struct amdgpu_dm_connector *aconnector,
11172 u8 *edid_ext, int len,
11173 struct amdgpu_hdmi_vsdb_info *vsdb_info)
11175 struct amdgpu_device *adev = drm_to_adev(aconnector->base.dev);
11178 mutex_lock(&adev->dm.dc_lock);
11179 if (adev->dm.dmub_srv)
11180 ret = parse_edid_cea_dmub(&adev->dm, edid_ext, len, vsdb_info);
11182 ret = parse_edid_cea_dmcu(&adev->dm, edid_ext, len, vsdb_info);
11183 mutex_unlock(&adev->dm.dc_lock);
11187 static int parse_amd_vsdb(struct amdgpu_dm_connector *aconnector,
11188 struct edid *edid, struct amdgpu_hdmi_vsdb_info *vsdb_info)
11190 u8 *edid_ext = NULL;
11194 if (edid == NULL || edid->extensions == 0)
11197 /* Find DisplayID extension */
11198 for (i = 0; i < edid->extensions; i++) {
11199 edid_ext = (void *)(edid + (i + 1));
11200 if (edid_ext[0] == DISPLAYID_EXT)
11204 while (j < EDID_LENGTH) {
11205 struct amd_vsdb_block *amd_vsdb = (struct amd_vsdb_block *)&edid_ext[j];
11206 unsigned int ieeeId = (amd_vsdb->ieee_id[2] << 16) | (amd_vsdb->ieee_id[1] << 8) | (amd_vsdb->ieee_id[0]);
11208 if (ieeeId == HDMI_AMD_VENDOR_SPECIFIC_DATA_BLOCK_IEEE_REGISTRATION_ID &&
11209 amd_vsdb->version == HDMI_AMD_VENDOR_SPECIFIC_DATA_BLOCK_VERSION_3) {
11210 vsdb_info->replay_mode = (amd_vsdb->feature_caps & AMD_VSDB_VERSION_3_FEATURECAP_REPLAYMODE) ? true : false;
11211 vsdb_info->amd_vsdb_version = HDMI_AMD_VENDOR_SPECIFIC_DATA_BLOCK_VERSION_3;
11212 DRM_DEBUG_KMS("Panel supports Replay Mode: %d\n", vsdb_info->replay_mode);
11222 static int parse_hdmi_amd_vsdb(struct amdgpu_dm_connector *aconnector,
11223 struct edid *edid, struct amdgpu_hdmi_vsdb_info *vsdb_info)
11225 u8 *edid_ext = NULL;
11227 bool valid_vsdb_found = false;
11229 /*----- drm_find_cea_extension() -----*/
11230 /* No EDID or EDID extensions */
11231 if (edid == NULL || edid->extensions == 0)
11234 /* Find CEA extension */
11235 for (i = 0; i < edid->extensions; i++) {
11236 edid_ext = (uint8_t *)edid + EDID_LENGTH * (i + 1);
11237 if (edid_ext[0] == CEA_EXT)
11241 if (i == edid->extensions)
11244 /*----- cea_db_offsets() -----*/
11245 if (edid_ext[0] != CEA_EXT)
11248 valid_vsdb_found = parse_edid_cea(aconnector, edid_ext, EDID_LENGTH, vsdb_info);
11250 return valid_vsdb_found ? i : -ENODEV;
11254 * amdgpu_dm_update_freesync_caps - Update Freesync capabilities
11256 * @connector: Connector to query.
11257 * @edid: EDID from monitor
11259 * Amdgpu supports Freesync in DP and HDMI displays, and it is required to keep
11260 * track of some of the display information in the internal data struct used by
11261 * amdgpu_dm. This function checks which type of connector we need to set the
11262 * FreeSync parameters.
11264 void amdgpu_dm_update_freesync_caps(struct drm_connector *connector,
11268 struct detailed_timing *timing;
11269 struct detailed_non_pixel *data;
11270 struct detailed_data_monitor_range *range;
11271 struct amdgpu_dm_connector *amdgpu_dm_connector =
11272 to_amdgpu_dm_connector(connector);
11273 struct dm_connector_state *dm_con_state = NULL;
11274 struct dc_sink *sink;
11276 struct amdgpu_device *adev = drm_to_adev(connector->dev);
11277 struct amdgpu_hdmi_vsdb_info vsdb_info = {0};
11278 bool freesync_capable = false;
11279 enum adaptive_sync_type as_type = ADAPTIVE_SYNC_TYPE_NONE;
11281 if (!connector->state) {
11282 DRM_ERROR("%s - Connector has no state", __func__);
11286 sink = amdgpu_dm_connector->dc_sink ?
11287 amdgpu_dm_connector->dc_sink :
11288 amdgpu_dm_connector->dc_em_sink;
11290 if (!edid || !sink) {
11291 dm_con_state = to_dm_connector_state(connector->state);
11293 amdgpu_dm_connector->min_vfreq = 0;
11294 amdgpu_dm_connector->max_vfreq = 0;
11295 amdgpu_dm_connector->pixel_clock_mhz = 0;
11296 connector->display_info.monitor_range.min_vfreq = 0;
11297 connector->display_info.monitor_range.max_vfreq = 0;
11298 freesync_capable = false;
11303 dm_con_state = to_dm_connector_state(connector->state);
11305 if (!adev->dm.freesync_module)
11308 if (edid && (sink->sink_signal == SIGNAL_TYPE_DISPLAY_PORT ||
11309 sink->sink_signal == SIGNAL_TYPE_EDP)) {
11310 bool edid_check_required = false;
11312 if (is_dp_capable_without_timing_msa(adev->dm.dc,
11313 amdgpu_dm_connector)) {
11314 if (edid->features & DRM_EDID_FEATURE_CONTINUOUS_FREQ) {
11315 freesync_capable = true;
11316 amdgpu_dm_connector->min_vfreq = connector->display_info.monitor_range.min_vfreq;
11317 amdgpu_dm_connector->max_vfreq = connector->display_info.monitor_range.max_vfreq;
11319 edid_check_required = edid->version > 1 ||
11320 (edid->version == 1 &&
11321 edid->revision > 1);
11325 if (edid_check_required) {
11326 for (i = 0; i < 4; i++) {
11328 timing = &edid->detailed_timings[i];
11329 data = &timing->data.other_data;
11330 range = &data->data.range;
11332 * Check if monitor has continuous frequency mode
11334 if (data->type != EDID_DETAIL_MONITOR_RANGE)
11337 * Check for flag range limits only. If flag == 1 then
11338 * no additional timing information provided.
11339 * Default GTF, GTF Secondary curve and CVT are not
11342 if (range->flags != 1)
11345 connector->display_info.monitor_range.min_vfreq = range->min_vfreq;
11346 connector->display_info.monitor_range.max_vfreq = range->max_vfreq;
11348 if (edid->revision >= 4) {
11349 if (data->pad2 & DRM_EDID_RANGE_OFFSET_MIN_VFREQ)
11350 connector->display_info.monitor_range.min_vfreq += 255;
11351 if (data->pad2 & DRM_EDID_RANGE_OFFSET_MAX_VFREQ)
11352 connector->display_info.monitor_range.max_vfreq += 255;
11355 amdgpu_dm_connector->min_vfreq =
11356 connector->display_info.monitor_range.min_vfreq;
11357 amdgpu_dm_connector->max_vfreq =
11358 connector->display_info.monitor_range.max_vfreq;
11359 amdgpu_dm_connector->pixel_clock_mhz =
11360 range->pixel_clock_mhz * 10;
11365 if (amdgpu_dm_connector->max_vfreq -
11366 amdgpu_dm_connector->min_vfreq > 10) {
11368 freesync_capable = true;
11371 parse_amd_vsdb(amdgpu_dm_connector, edid, &vsdb_info);
11373 if (vsdb_info.replay_mode) {
11374 amdgpu_dm_connector->vsdb_info.replay_mode = vsdb_info.replay_mode;
11375 amdgpu_dm_connector->vsdb_info.amd_vsdb_version = vsdb_info.amd_vsdb_version;
11376 amdgpu_dm_connector->as_type = ADAPTIVE_SYNC_TYPE_EDP;
11379 } else if (edid && sink->sink_signal == SIGNAL_TYPE_HDMI_TYPE_A) {
11380 i = parse_hdmi_amd_vsdb(amdgpu_dm_connector, edid, &vsdb_info);
11381 if (i >= 0 && vsdb_info.freesync_supported) {
11382 timing = &edid->detailed_timings[i];
11383 data = &timing->data.other_data;
11385 amdgpu_dm_connector->min_vfreq = vsdb_info.min_refresh_rate_hz;
11386 amdgpu_dm_connector->max_vfreq = vsdb_info.max_refresh_rate_hz;
11387 if (amdgpu_dm_connector->max_vfreq - amdgpu_dm_connector->min_vfreq > 10)
11388 freesync_capable = true;
11390 connector->display_info.monitor_range.min_vfreq = vsdb_info.min_refresh_rate_hz;
11391 connector->display_info.monitor_range.max_vfreq = vsdb_info.max_refresh_rate_hz;
11395 as_type = dm_get_adaptive_sync_support_type(amdgpu_dm_connector->dc_link);
11397 if (as_type == FREESYNC_TYPE_PCON_IN_WHITELIST) {
11398 i = parse_hdmi_amd_vsdb(amdgpu_dm_connector, edid, &vsdb_info);
11399 if (i >= 0 && vsdb_info.freesync_supported && vsdb_info.amd_vsdb_version > 0) {
11401 amdgpu_dm_connector->pack_sdp_v1_3 = true;
11402 amdgpu_dm_connector->as_type = as_type;
11403 amdgpu_dm_connector->vsdb_info = vsdb_info;
11405 amdgpu_dm_connector->min_vfreq = vsdb_info.min_refresh_rate_hz;
11406 amdgpu_dm_connector->max_vfreq = vsdb_info.max_refresh_rate_hz;
11407 if (amdgpu_dm_connector->max_vfreq - amdgpu_dm_connector->min_vfreq > 10)
11408 freesync_capable = true;
11410 connector->display_info.monitor_range.min_vfreq = vsdb_info.min_refresh_rate_hz;
11411 connector->display_info.monitor_range.max_vfreq = vsdb_info.max_refresh_rate_hz;
11417 dm_con_state->freesync_capable = freesync_capable;
11419 if (connector->vrr_capable_property)
11420 drm_connector_set_vrr_capable_property(connector,
11424 void amdgpu_dm_trigger_timing_sync(struct drm_device *dev)
11426 struct amdgpu_device *adev = drm_to_adev(dev);
11427 struct dc *dc = adev->dm.dc;
11430 mutex_lock(&adev->dm.dc_lock);
11431 if (dc->current_state) {
11432 for (i = 0; i < dc->current_state->stream_count; ++i)
11433 dc->current_state->streams[i]
11434 ->triggered_crtc_reset.enabled =
11435 adev->dm.force_timing_sync;
11437 dm_enable_per_frame_crtc_master_sync(dc->current_state);
11438 dc_trigger_sync(dc, dc->current_state);
11440 mutex_unlock(&adev->dm.dc_lock);
11443 void dm_write_reg_func(const struct dc_context *ctx, uint32_t address,
11444 u32 value, const char *func_name)
11446 #ifdef DM_CHECK_ADDR_0
11447 if (address == 0) {
11448 drm_err(adev_to_drm(ctx->driver_context),
11449 "invalid register write. address = 0");
11453 cgs_write_register(ctx->cgs_device, address, value);
11454 trace_amdgpu_dc_wreg(&ctx->perf_trace->write_count, address, value);
11457 uint32_t dm_read_reg_func(const struct dc_context *ctx, uint32_t address,
11458 const char *func_name)
11461 #ifdef DM_CHECK_ADDR_0
11462 if (address == 0) {
11463 drm_err(adev_to_drm(ctx->driver_context),
11464 "invalid register read; address = 0\n");
11469 if (ctx->dmub_srv &&
11470 ctx->dmub_srv->reg_helper_offload.gather_in_progress &&
11471 !ctx->dmub_srv->reg_helper_offload.should_burst_write) {
11476 value = cgs_read_register(ctx->cgs_device, address);
11478 trace_amdgpu_dc_rreg(&ctx->perf_trace->read_count, address, value);
11483 int amdgpu_dm_process_dmub_aux_transfer_sync(
11484 struct dc_context *ctx,
11485 unsigned int link_index,
11486 struct aux_payload *payload,
11487 enum aux_return_code_type *operation_result)
11489 struct amdgpu_device *adev = ctx->driver_context;
11490 struct dmub_notification *p_notify = adev->dm.dmub_notify;
11493 mutex_lock(&adev->dm.dpia_aux_lock);
11494 if (!dc_process_dmub_aux_transfer_async(ctx->dc, link_index, payload)) {
11495 *operation_result = AUX_RET_ERROR_ENGINE_ACQUIRE;
11499 if (!wait_for_completion_timeout(&adev->dm.dmub_aux_transfer_done, 10 * HZ)) {
11500 DRM_ERROR("wait_for_completion_timeout timeout!");
11501 *operation_result = AUX_RET_ERROR_TIMEOUT;
11505 if (p_notify->result != AUX_RET_SUCCESS) {
11507 * Transient states before tunneling is enabled could
11508 * lead to this error. We can ignore this for now.
11510 if (p_notify->result != AUX_RET_ERROR_PROTOCOL_ERROR) {
11511 DRM_WARN("DPIA AUX failed on 0x%x(%d), error %d\n",
11512 payload->address, payload->length,
11515 *operation_result = AUX_RET_ERROR_INVALID_REPLY;
11520 payload->reply[0] = adev->dm.dmub_notify->aux_reply.command;
11521 if (!payload->write && p_notify->aux_reply.length &&
11522 (payload->reply[0] == AUX_TRANSACTION_REPLY_AUX_ACK)) {
11524 if (payload->length != p_notify->aux_reply.length) {
11525 DRM_WARN("invalid read length %d from DPIA AUX 0x%x(%d)!\n",
11526 p_notify->aux_reply.length,
11527 payload->address, payload->length);
11528 *operation_result = AUX_RET_ERROR_INVALID_REPLY;
11532 memcpy(payload->data, p_notify->aux_reply.data,
11533 p_notify->aux_reply.length);
11537 ret = p_notify->aux_reply.length;
11538 *operation_result = p_notify->result;
11540 reinit_completion(&adev->dm.dmub_aux_transfer_done);
11541 mutex_unlock(&adev->dm.dpia_aux_lock);
11545 int amdgpu_dm_process_dmub_set_config_sync(
11546 struct dc_context *ctx,
11547 unsigned int link_index,
11548 struct set_config_cmd_payload *payload,
11549 enum set_config_status *operation_result)
11551 struct amdgpu_device *adev = ctx->driver_context;
11552 bool is_cmd_complete;
11555 mutex_lock(&adev->dm.dpia_aux_lock);
11556 is_cmd_complete = dc_process_dmub_set_config_async(ctx->dc,
11557 link_index, payload, adev->dm.dmub_notify);
11559 if (is_cmd_complete || wait_for_completion_timeout(&adev->dm.dmub_aux_transfer_done, 10 * HZ)) {
11561 *operation_result = adev->dm.dmub_notify->sc_status;
11563 DRM_ERROR("wait_for_completion_timeout timeout!");
11565 *operation_result = SET_CONFIG_UNKNOWN_ERROR;
11568 if (!is_cmd_complete)
11569 reinit_completion(&adev->dm.dmub_aux_transfer_done);
11570 mutex_unlock(&adev->dm.dpia_aux_lock);
11574 bool dm_execute_dmub_cmd(const struct dc_context *ctx, union dmub_rb_cmd *cmd, enum dm_dmub_wait_type wait_type)
11576 return dc_dmub_srv_cmd_run(ctx->dmub_srv, cmd, wait_type);
11579 bool dm_execute_dmub_cmd_list(const struct dc_context *ctx, unsigned int count, union dmub_rb_cmd *cmd, enum dm_dmub_wait_type wait_type)
11581 return dc_dmub_srv_cmd_run_list(ctx->dmub_srv, count, cmd, wait_type);