Skip to contentSkip to conversation

drm/amd/amdgpu: Add 5K Support for iMac20,1 and iMac20,2

PATCH Superseded Atharva Tiwari 3 participants 7 messages Nov 4 – Nov 13

Subsystems (3)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drm/amd/amdgpu: Add 5K Support for iMac20,1 and iMac20,2

This code adds support for 5K in iMac20,1 and iMac20,2 with support of changing resolutions.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c | 32 ++++++++++++++--
 .../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 26 +++++++++++++
 .../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.h |  7 ++++
 .../display/amdgpu_dm/amdgpu_dm_connector.c   | 19 +++++++++-
 .../amd/display/amdgpu_dm/amdgpu_dm_quirks.c  | 29 ++++++++++++++-
 .../gpu/drm/amd/display/dc/core/dc_resource.c |  8 ++++
 drivers/gpu/drm/amd/display/dc/dc.h           |  2 +
 .../amd/display/dc/hwss/dce110/dce110_hwseq.c | 37 +++++++++++++++++--
 .../drm/amd/display/dc/link/link_detection.c  | 14 ++++++-
 .../gpu/drm/amd/display/dc/link/link_dpms.c   |  3 ++
 .../display/dc/link/protocols/link_dp_phy.c   |  5 +++
 .../dc/link/protocols/link_dp_training.c      |  9 ++++-
 12 files changed, 180 insertions(+), 11 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c +29 -3
index 890792a94..fc107e4fa 100644
@@ -21,6 +21,7 @@
  *
  */
 
+#include <linux/dmi.h>
 #include <linux/firmware.h>
 #include <linux/kernfs.h>
 
@@ -3412,6 +3413,22 @@ static int amdgpu_discovery_set_ualink_ip_blocks(struct amdgpu_device *adev)
 	return 0;
 }
 
+static const struct dmi_system_id imac5k_table[] = {
+	{
+		.matches = {
+			DMI_MATCH(DMI_SYS_VENDOR, "Apple Inc."),
+			DMI_MATCH(DMI_PRODUCT_NAME, "iMac20,1"),
+		},
+	},
+	{
+		.matches = {
+			DMI_MATCH(DMI_SYS_VENDOR, "Apple Inc."),
+			DMI_MATCH(DMI_PRODUCT_NAME, "iMac20,2"),
+		},
+	},
+	{}
+};
+
 int amdgpu_discovery_set_ip_blocks(struct amdgpu_device *adev)
 {
 	int r;
@@ -4026,15 +4043,24 @@ int amdgpu_discovery_set_ip_blocks(struct amdgpu_device *adev)
 		}
 	}
 
+	/* TODO: We should enable 5K in EFI and remove this quirk */
+	if (unlikely(dmi_check_system(imac5k_table))) {
+		r = amdgpu_discovery_set_display_ip_blocks(adev);
+		if (r)
+			return r;
+	}
+
 	if (likely(adev->firmware.load_type == AMDGPU_FW_LOAD_PSP)) {
 		r = amdgpu_discovery_set_smu_ip_blocks(adev);
 		if (r)
 			return r;
 	}
 
-	r = amdgpu_discovery_set_display_ip_blocks(adev);
-	if (r)
-		return r;
+	if (likely(!dmi_check_system(imac5k_table))) {
+		r = amdgpu_discovery_set_display_ip_blocks(adev);
+		if (r)
+			return r;
+	}
 
 	r = amdgpu_discovery_set_gc_ip_blocks(adev);
 	if (r)
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +26 -0
index 5b634ae07..a88c86051 100644
@@ -639,6 +639,8 @@ static int amdgpu_dm_init(struct amdgpu_device *adev)
 	retrieve_dmi_info(&adev->dm);
 	if (adev->dm.edp0_on_dp1_quirk)
 		init_data.flags.support_edp0_on_dp1 = true;
+	if (adev->dm.imac5K_support)
+		init_data.flags.imac5K_support = true;
 
 	if (adev->dm.bb_from_dmub)
 		init_data.bb_from_dmub = adev->dm.bb_from_dmub;
@@ -1967,6 +1969,11 @@ static int dm_resume(struct amdgpu_ip_block *ip_block)
 		dc_exit_ips_for_hw_access(dm->dc);
 		WARN_ON(!dc_commit_streams(dm->dc, &commit_params));
 
+		if (dm->dc->config.imac5K_using_5K) {
+			const u8 value = 1;
+
+			core_link_write_dpcd(dm->dc->links[0], 0x4F1, &value, 1);
+		}
 		dm_gpureset_commit_state(dm->cached_dc_state, dm);
 
 		dm_gpureset_toggle_interrupts(adev, dm->cached_dc_state, true);
@@ -4739,6 +4746,25 @@ static void amdgpu_dm_commit_streams(struct drm_atomic_commit *state,
 	dc_exit_ips_for_hw_access(dm->dc);
 	WARN_ON(!dc_commit_streams(dm->dc, &params));
 
+	if (dm->imac5K_support) {
+		for_each_new_crtc_in_state(state, crtc, new_crtc_state, i) {
+			dm_new_crtc_state = to_dm_crtc_state(new_crtc_state);
+
+			if (!dm_new_crtc_state->stream)
+				continue;
+
+			if (dm_new_crtc_state->stream->signal != SIGNAL_TYPE_EDP)
+				continue;
+
+			if (new_crtc_state->mode.vdisplay == 2880 && new_crtc_state->mode.hdisplay == 2560) {
+				u8 value = 1;
+
+				core_link_write_dpcd(dm->dc->links[0], 0x4F1, &value, 1);
+				dm->dc->config.imac5K_using_5K = true;
+			} else
+				dm->dc->config.imac5K_using_5K = false;
+		}
+	}
 	bool frl_stream_found = false;
 
 	for (i = 0; i < params.stream_count; i++) {
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.h +7 -0
index 1b91fe4c3..65a2330c6 100644
@@ -698,6 +698,13 @@ struct amdgpu_display_manager {
 	 */
 	bool edp0_on_dp1_quirk;
 
+	/**
+	 * @imac5K_support:
+	 *
+	 * quirk for iMac that support 5K
+	 */
+	bool imac5K_support;
+
 	/**
 	 * @dpia_aux_lock:
 	 *
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_connector.c +18 -1
index 2b81396bd..2269b91c3 100644
@@ -123,6 +123,13 @@ STATIC_IFN_KUNIT int dm_encoder_helper_atomic_check(struct drm_encoder *encoder,
 				       drm_mode_vrefresh(adjusted_mode));
 			dm_new_connector_state->scaling = RMX_ASPECT;
 		}
+
+		if (aconnector->dc_link && aconnector->dc_link->dc->config.imac5K_support) {
+			if (crtc_state->mode.vdisplay != 2880)
+				dm_new_connector_state->scaling = RMX_FULL;
+			else
+				dm_new_connector_state->scaling = RMX_OFF;
+		}
 		return 0;
 	}
 
@@ -3130,9 +3137,19 @@ STATIC_IFN_KUNIT int amdgpu_dm_connector_get_modes(struct drm_connector *connect
 	const struct drm_edid *drm_edid = amdgpu_dm_connector->drm_edid;
 	struct dc_link_settings *verified_link_cap = &dc_link->verified_link_cap;
 	const struct dc *dc = dc_link->dc;
+	struct dc_sink *sink = amdgpu_dm_connector->dc_sink;
 
 	encoder = amdgpu_dm_connector_to_encoder(connector);
 
+	if (dc->config.imac5K_support && sink &&
+	    sink->link->link_index == 1 && !connector->edid_blob_ptr) {
+		const struct drm_edid *kept = drm_edid_alloc(sink->dc_edid.raw_edid,
+							     sink->dc_edid.length);
+
+		drm_edid_connector_update(connector, kept);
+		drm_edid_free(kept);
+	}
+
 	if (!drm_edid) {
 		amdgpu_dm_connector->num_modes =
 				drm_add_modes_noedid(connector, 640, 480);
@@ -3312,7 +3329,7 @@ void amdgpu_dm_connector_init_helper(struct amdgpu_display_manager *dm,
 				adev->mode_info.underscan_vborder_property,
 				0);
 
-	if (!aconnector->mst_root)
+	if (!aconnector->mst_root && !(dm->imac5K_support && link_index <= 1))
 		drm_connector_attach_max_bpc_property(&aconnector->base, 8, 16);
 
 	aconnector->base.state->max_bpc = 16;
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_quirks.c +28 -1
index 259966703..8657dd972 100644
@@ -33,11 +33,13 @@
 struct amdgpu_dm_quirks {
 	bool aux_hpd_discon;
 	bool support_edp0_on_dp1;
+	bool imac5K_support;
 };
 
 static struct amdgpu_dm_quirks quirk_entries = {
 	.aux_hpd_discon = false,
-	.support_edp0_on_dp1 = false
+	.support_edp0_on_dp1 = false,
+	.imac5K_support = false,
 };
 
 static int edp0_on_dp1_callback(const struct dmi_system_id *id)
@@ -52,6 +54,12 @@ static int aux_hpd_discon_callback(const struct dmi_system_id *id)
 	return 0;
 }
 
+static int imac5K_support_callback(const struct dmi_system_id *id)
+{
+	quirk_entries.imac5K_support = true;
+	return 0;
+}
+
 static const struct dmi_system_id dmi_quirk_table[] = {
 	{
 		.callback = aux_hpd_discon_callback,
@@ -151,6 +159,20 @@ static const struct dmi_system_id dmi_quirk_table[] = {
 			DMI_MATCH(DMI_PRODUCT_NAME, "HP ProBook 465 16 inch G11 Notebook PC"),
 		},
 	},
+	{
+		.callback = imac5K_support_callback,
+		.matches = {
+			DMI_MATCH(DMI_SYS_VENDOR, "Apple Inc."),
+			DMI_MATCH(DMI_PRODUCT_NAME, "iMac20,1"),
+		},
+	},
+	{
+		.callback = imac5K_support_callback,
+		.matches = {
+			DMI_MATCH(DMI_SYS_VENDOR, "Apple Inc."),
+			DMI_MATCH(DMI_PRODUCT_NAME, "iMac20,2"),
+		},
+	},
 	{}
 	/* TODO: refactor this from a fixed table to a dynamic option */
 };
@@ -162,6 +184,7 @@ void retrieve_dmi_info(struct amdgpu_display_manager *dm)
 
 	dm->aux_hpd_discon_quirk = false;
 	dm->edp0_on_dp1_quirk = false;
+	dm->imac5K_support = false;
 
 	dmi_id = dmi_check_system(dmi_quirk_table);
 
@@ -176,6 +199,10 @@ void retrieve_dmi_info(struct amdgpu_display_manager *dm)
 		dm->edp0_on_dp1_quirk = true;
 		drm_info(dev, "support_edp0_on_dp1 attached\n");
 	}
+	if (quirk_entries.imac5K_support) {
+		dm->imac5K_support = true;
+		drm_info(dev, "imac5K_support attached\n");
+	}
 }
 EXPORT_IF_KUNIT(retrieve_dmi_info);
 
drivers/gpu/drm/amd/display/dc/core/dc_resource.c +8 -0
index 187486d97..98f74ffc2 100644
@@ -689,6 +689,14 @@ bool resource_are_streams_timing_synchronizable(
 	struct dc_stream_state *stream1,
 	struct dc_stream_state *stream2)
 {
+
+	if (stream1->ctx->dc->config.imac5K_support &&
+		((stream1->signal == SIGNAL_TYPE_EDP && stream2->signal == SIGNAL_TYPE_DISPLAY_PORT &&
+		stream2->link->link_index == 1) ||
+		(stream2->signal == SIGNAL_TYPE_EDP && stream1->signal == SIGNAL_TYPE_DISPLAY_PORT &&
+		stream1->link->link_index == 1)))
+		return true;
+
 	if (stream1->timing.h_total != stream2->timing.h_total)
 		return false;
 
drivers/gpu/drm/amd/display/dc/dc.h +2 -0
index d3c484f45..a0b746250 100644
@@ -635,6 +635,8 @@ struct dc_config {
 	struct spl_sharpness_range dcn_sharpness_range;
 	struct spl_sharpness_range dcn_override_sharpness_range;
 	bool no_native422_support;
+	bool imac5K_support;
+	bool imac5K_using_5K;
 };
 
 enum visual_confirm {
drivers/gpu/drm/amd/display/dc/hwss/dce110/dce110_hwseq.c +33 -4
index 7b3aa02dd..aba1dc9b4 100644
@@ -2656,7 +2656,8 @@ enum dc_status dce110_apply_ctx_to_hw(
 	struct dce_hwseq *hws = dc->hwseq;
 	struct dc_bios *dcb = dc->ctx->dc_bios;
 	enum dc_status status;
-	unsigned int i;
+	unsigned int i, n, enable_order[MAX_PIPES];
+	int primary = -1, companion = -1;
 	bool was_hpo_acquired = resource_is_hpo_acquired(dc->current_state);
 	bool is_hpo_acquired = resource_is_hpo_acquired(context);
 
@@ -2664,6 +2665,32 @@ enum dc_status dce110_apply_ctx_to_hw(
 	if (dc->config.use_pipe_ctx_sync_logic)
 		reset_syncd_pipes_from_disabled_pipes(dc, context);
 
+	for (i = 0; i < dc->res_pool->pipe_count; i++) {
+		struct pipe_ctx *pipe = &context->res_ctx.pipe_ctx[i];
+
+		enable_order[i] = i;
+		if (!dc->config.imac5K_support || !pipe->stream ||
+		    pipe->top_pipe || pipe->prev_odm_pipe)
+			continue;
+		if (pipe->stream->link->link_index == 0)
+			primary = i;
+		else if (pipe->stream->link->link_index == 1)
+			companion = i;
+	}
+	if (companion >= 0 && primary > companion) {
+		enable_order[companion] = primary;
+		enable_order[primary] = companion;
+	}
+
+	if (primary >= 0 && companion >= 0) {
+		struct pipe_ctx *old = &dc->current_state->res_ctx.pipe_ctx[primary];
+		struct dc_link *right = context->res_ctx.pipe_ctx[companion].stream->link;
+
+		if (!old->stream ||
+		    pipe_need_reprogram(old, &context->res_ctx.pipe_ctx[primary]))
+			right->link_state_valid = false;
+	}
+
 	/* Reset old context */
 	/* look up the targets that have been removed since last commit */
 	hws->funcs.reset_hw_ctx_wrap(dc, context);
@@ -2705,10 +2732,12 @@ enum dc_status dce110_apply_ctx_to_hw(
 		dc->hwseq->funcs.setup_hpo_hw_control(dc->hwseq, is_hpo_acquired);
 	}
 
-	for (i = 0; i < dc->res_pool->pipe_count; i++) {
+	for (n = 0; n < dc->res_pool->pipe_count; n++) {
 		struct pipe_ctx *pipe_ctx_old =
-					&dc->current_state->res_ctx.pipe_ctx[i];
-		struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[i];
+			&dc->current_state->res_ctx.pipe_ctx[enable_order[n]];
+		struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[enable_order[n]];
+
+		i = enable_order[n];
 
 		if (pipe_ctx->stream == NULL)
 			continue;
drivers/gpu/drm/amd/display/dc/link/link_detection.c +13 -1
index b4546f93a..a92399753 100644
@@ -1205,7 +1205,10 @@ static bool detect_link_and_local_sink(struct dc_link *link,
 				if (!link->dpcd_caps.set_power_state_capable_edp)
 					link->wa_flags.dp_keep_receiver_powered = true;
 			}
-
+			if (dc->config.imac5K_support) {
+				const uint8_t val = 1;
+				core_link_write_dpcd(link, 0x4F1, &val, 1);
+			}
 			sink_caps.transaction_type = DDC_TRANSACTION_TYPE_I2C_OVER_AUX;
 			sink_caps.signal = SIGNAL_TYPE_EDP;
 			break;
@@ -1634,6 +1637,15 @@ bool link_detect(struct dc_link *link, enum dc_detect_reason reason)
 	bool is_delegated_to_mst_top_mgr = false;
 	enum dc_connection_type pre_link_type = link->type;
 
+	if (link->local_sink &&
+			link->dc->config.imac5K_support &&
+			link->local_sink->link->link_index == 1)
+		return false;
+
+	if (reason == DETECT_REASON_BOOT && link->dc->config.imac5K_support &&
+	    link->link_index == 1)
+		msleep(100);
+
 	is_local_sink_detect_success = detect_link_and_local_sink(link, reason);
 
 	if (is_local_sink_detect_success && link->local_sink) {
drivers/gpu/drm/amd/display/dc/link/link_dpms.c +3 -0
index 2aeb9a0e6..3d7d1ddc4 100644
@@ -2084,6 +2084,9 @@ static enum dc_status enable_link_dp(struct dc_state *state,
 			!link->dc->config.enable_dpia_pre_training)
 		do_fallback = true;
 
+	if (link->dc->config.imac5K_support && link->link_index == 1)
+		msleep(100);
+
 	/*
 	 * Temporary w/a to get DP2.0 link rates to work with SST.
 	 * TODO DP2.0 - Workaround: Remove w/a if and when the issue is resolved.
drivers/gpu/drm/amd/display/dc/link/protocols/link_dp_phy.c +5 -0
index 49521ac4b..e90164a58 100644
@@ -53,6 +53,11 @@ void dpcd_write_rx_power_ctrl(struct dc_link *link, bool on)
 	core_link_write_dpcd(link, DP_SET_POWER, &state,
 						 sizeof(state));
 
+	if (on && link->dc->config.imac5K_support &&
+	    link->connector_signal == SIGNAL_TYPE_EDP) {
+		state = 1;
+		core_link_write_dpcd(link, 0x4F1, &state, sizeof(state));
+	}
 }
 
 void dp_enable_link_phy(
drivers/gpu/drm/amd/display/dc/link/protocols/link_dp_training.c +8 -1
index 3be36d106..4eca11169 100644
@@ -1540,8 +1540,15 @@ static enum link_training_result dp_transition_to_video_idle(
 		 */
 		if (link->connector_signal != SIGNAL_TYPE_EDP && status == LINK_TRAINING_SUCCESS) {
 			msleep(5);
-			if (!link->skip_fallback_on_link_loss)
+			if (link->dc->config.imac5K_support && link->link_index == 1) {
+				uint8_t lanes;
+
+				if (core_link_read_dpcd(link, DP_LANE0_1_STATUS,
+							&lanes, 1) != DC_OK)
+					status = LINK_TRAINING_LINK_LOSS;
+			} else if (!link->skip_fallback_on_link_loss) {
 				status = dp_check_link_loss_status(link, lt_settings);
+			}
 		}
 		return status;
 	}
Signature · 1 line
2.55.0
#1 lore raw
Quoted 4 lines · Atharva Tiwari

This code adds support for 5K in iMac20,1 and iMac20,2 with support of changing resolutions.

Please give a better description of what has changed here.

Quoted 55 lines
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c | 32 ++++++++++++++--
 .../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 26 +++++++++++++
 .../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.h |  7 ++++
 .../display/amdgpu_dm/amdgpu_dm_connector.c   | 19 +++++++++-
 .../amd/display/amdgpu_dm/amdgpu_dm_quirks.c  | 29 ++++++++++++++-
 .../gpu/drm/amd/display/dc/core/dc_resource.c |  8 ++++
 drivers/gpu/drm/amd/display/dc/dc.h           |  2 +
 .../amd/display/dc/hwss/dce110/dce110_hwseq.c | 37 +++++++++++++++++--
 .../drm/amd/display/dc/link/link_detection.c  | 14 ++++++-
 .../gpu/drm/amd/display/dc/link/link_dpms.c   |  3 ++
 .../display/dc/link/protocols/link_dp_phy.c   |  5 +++
 .../dc/link/protocols/link_dp_training.c      |  9 ++++-
 12 files changed, 180 insertions(+), 11 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c +17 -0
index 890792a94..fc107e4fa 100644
@@ -21,6 +21,7 @@
  *
  */
 
+#include <linux/dmi.h>
 #include <linux/firmware.h>
 #include <linux/kernfs.h>
 
@@ -3412,6 +3413,22 @@ static int amdgpu_discovery_set_ualink_ip_blocks(struct amdgpu_device *adev)
        return 0;
 }
 
+static const struct dmi_system_id imac5k_table[] = {
+       {
+               .matches = {
+                       DMI_MATCH(DMI_SYS_VENDOR, "Apple Inc."),
+                       DMI_MATCH(DMI_PRODUCT_NAME, "iMac20,1"),
+               },
+       },
+       {
+               .matches = {
+                       DMI_MATCH(DMI_SYS_VENDOR, "Apple Inc."),
+                       DMI_MATCH(DMI_PRODUCT_NAME, "iMac20,2"),
+               },
+       },
+       {}
+};
+
 int amdgpu_discovery_set_ip_blocks(struct amdgpu_device *adev)
 {
        int r;

drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c int amdgpu_discovery_set_ip_blocks(struct amdgpu_device *adev) · line 4051

Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c +6 -0
@@ -4026,15 +4043,24 @@ int amdgpu_discovery_set_ip_blocks(struct amdgpu_device *adev)
                }
        }
 
+       /* TODO: We should enable 5K in EFI and remove this quirk */
+       if (unlikely(dmi_check_system(imac5k_table))) {
+               r = amdgpu_discovery_set_display_ip_blocks(adev);
+               if (r)
+                       return r;
+       }

What's the reason for this change?

Quoted 374 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c +6 -3
+
        if (likely(adev->firmware.load_type == AMDGPU_FW_LOAD_PSP)) {
                r = amdgpu_discovery_set_smu_ip_blocks(adev);
                if (r)
                        return r;
        }
 
-       r = amdgpu_discovery_set_display_ip_blocks(adev);
-       if (r)
-               return r;
+       if (likely(!dmi_check_system(imac5k_table))) {
+               r = amdgpu_discovery_set_display_ip_blocks(adev);
+               if (r)
+                       return r;
+       }
 
        r = amdgpu_discovery_set_gc_ip_blocks(adev);
        if (r)
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +26 -0
index 5b634ae07..a88c86051 100644
@@ -639,6 +639,8 @@ static int amdgpu_dm_init(struct amdgpu_device *adev)
        retrieve_dmi_info(&adev->dm);
        if (adev->dm.edp0_on_dp1_quirk)
                init_data.flags.support_edp0_on_dp1 = true;
+       if (adev->dm.imac5K_support)
+               init_data.flags.imac5K_support = true;
 
        if (adev->dm.bb_from_dmub)
                init_data.bb_from_dmub = adev->dm.bb_from_dmub;
@@ -1967,6 +1969,11 @@ static int dm_resume(struct amdgpu_ip_block *ip_block)
                dc_exit_ips_for_hw_access(dm->dc);
                WARN_ON(!dc_commit_streams(dm->dc, &commit_params));
 
+               if (dm->dc->config.imac5K_using_5K) {
+                       const u8 value = 1;
+
+                       core_link_write_dpcd(dm->dc->links[0], 0x4F1, &value, 1);
+               }
                dm_gpureset_commit_state(dm->cached_dc_state, dm);
 
                dm_gpureset_toggle_interrupts(adev, dm->cached_dc_state, true);
@@ -4739,6 +4746,25 @@ static void amdgpu_dm_commit_streams(struct drm_atomic_commit *state,
        dc_exit_ips_for_hw_access(dm->dc);
        WARN_ON(!dc_commit_streams(dm->dc, &params));
 
+       if (dm->imac5K_support) {
+               for_each_new_crtc_in_state(state, crtc, new_crtc_state, i) {
+                       dm_new_crtc_state = to_dm_crtc_state(new_crtc_state);
+
+                       if (!dm_new_crtc_state->stream)
+                               continue;
+
+                       if (dm_new_crtc_state->stream->signal != SIGNAL_TYPE_EDP)
+                               continue;
+
+                       if (new_crtc_state->mode.vdisplay == 2880 && new_crtc_state->mode.hdisplay == 2560) {
+                               u8 value = 1;
+
+                               core_link_write_dpcd(dm->dc->links[0], 0x4F1, &value, 1);
+                               dm->dc->config.imac5K_using_5K = true;
+                       } else
+                               dm->dc->config.imac5K_using_5K = false;
+               }
+       }
        bool frl_stream_found = false;
 
        for (i = 0; i < params.stream_count; i++) {
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.h +7 -0
index 1b91fe4c3..65a2330c6 100644
@@ -698,6 +698,13 @@ struct amdgpu_display_manager {
         */
        bool edp0_on_dp1_quirk;
 
+       /**
+        * @imac5K_support:
+        *
+        * quirk for iMac that support 5K
+        */
+       bool imac5K_support;
+
        /**
         * @dpia_aux_lock:
         *
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_connector.c +18 -1
index 2b81396bd..2269b91c3 100644
@@ -123,6 +123,13 @@ STATIC_IFN_KUNIT int dm_encoder_helper_atomic_check(struct drm_encoder *encoder,
                                       drm_mode_vrefresh(adjusted_mode));
                        dm_new_connector_state->scaling = RMX_ASPECT;
                }
+
+               if (aconnector->dc_link && aconnector->dc_link->dc->config.imac5K_support) {
+                       if (crtc_state->mode.vdisplay != 2880)
+                               dm_new_connector_state->scaling = RMX_FULL;
+                       else
+                               dm_new_connector_state->scaling = RMX_OFF;
+               }
                return 0;
        }
 
@@ -3130,9 +3137,19 @@ STATIC_IFN_KUNIT int amdgpu_dm_connector_get_modes(struct drm_connector *connect
        const struct drm_edid *drm_edid = amdgpu_dm_connector->drm_edid;
        struct dc_link_settings *verified_link_cap = &dc_link->verified_link_cap;
        const struct dc *dc = dc_link->dc;
+       struct dc_sink *sink = amdgpu_dm_connector->dc_sink;
 
        encoder = amdgpu_dm_connector_to_encoder(connector);
 
+       if (dc->config.imac5K_support && sink &&
+           sink->link->link_index == 1 && !connector->edid_blob_ptr) {
+               const struct drm_edid *kept = drm_edid_alloc(sink->dc_edid.raw_edid,
+                                                            sink->dc_edid.length);
+
+               drm_edid_connector_update(connector, kept);
+               drm_edid_free(kept);
+       }
+
        if (!drm_edid) {
                amdgpu_dm_connector->num_modes =
                                drm_add_modes_noedid(connector, 640, 480);
@@ -3312,7 +3329,7 @@ void amdgpu_dm_connector_init_helper(struct amdgpu_display_manager *dm,
                                adev->mode_info.underscan_vborder_property,
                                0);
 
-       if (!aconnector->mst_root)
+       if (!aconnector->mst_root && !(dm->imac5K_support && link_index <= 1))
                drm_connector_attach_max_bpc_property(&aconnector->base, 8, 16);
 
        aconnector->base.state->max_bpc = 16;
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_quirks.c +28 -1
index 259966703..8657dd972 100644
@@ -33,11 +33,13 @@
 struct amdgpu_dm_quirks {
        bool aux_hpd_discon;
        bool support_edp0_on_dp1;
+       bool imac5K_support;
 };
 
 static struct amdgpu_dm_quirks quirk_entries = {
        .aux_hpd_discon = false,
-       .support_edp0_on_dp1 = false
+       .support_edp0_on_dp1 = false,
+       .imac5K_support = false,
 };
 
 static int edp0_on_dp1_callback(const struct dmi_system_id *id)
@@ -52,6 +54,12 @@ static int aux_hpd_discon_callback(const struct dmi_system_id *id)
        return 0;
 }
 
+static int imac5K_support_callback(const struct dmi_system_id *id)
+{
+       quirk_entries.imac5K_support = true;
+       return 0;
+}
+
 static const struct dmi_system_id dmi_quirk_table[] = {
        {
                .callback = aux_hpd_discon_callback,
@@ -151,6 +159,20 @@ static const struct dmi_system_id dmi_quirk_table[] = {
                        DMI_MATCH(DMI_PRODUCT_NAME, "HP ProBook 465 16 inch G11 Notebook PC"),
                },
        },
+       {
+               .callback = imac5K_support_callback,
+               .matches = {
+                       DMI_MATCH(DMI_SYS_VENDOR, "Apple Inc."),
+                       DMI_MATCH(DMI_PRODUCT_NAME, "iMac20,1"),
+               },
+       },
+       {
+               .callback = imac5K_support_callback,
+               .matches = {
+                       DMI_MATCH(DMI_SYS_VENDOR, "Apple Inc."),
+                       DMI_MATCH(DMI_PRODUCT_NAME, "iMac20,2"),
+               },
+       },
        {}
        /* TODO: refactor this from a fixed table to a dynamic option */
 };
@@ -162,6 +184,7 @@ void retrieve_dmi_info(struct amdgpu_display_manager *dm)
 
        dm->aux_hpd_discon_quirk = false;
        dm->edp0_on_dp1_quirk = false;
+       dm->imac5K_support = false;
 
        dmi_id = dmi_check_system(dmi_quirk_table);
 
@@ -176,6 +199,10 @@ void retrieve_dmi_info(struct amdgpu_display_manager *dm)
                dm->edp0_on_dp1_quirk = true;
                drm_info(dev, "support_edp0_on_dp1 attached\n");
        }
+       if (quirk_entries.imac5K_support) {
+               dm->imac5K_support = true;
+               drm_info(dev, "imac5K_support attached\n");
+       }
 }
 EXPORT_IF_KUNIT(retrieve_dmi_info);
 
drivers/gpu/drm/amd/display/dc/core/dc_resource.c +8 -0
index 187486d97..98f74ffc2 100644
@@ -689,6 +689,14 @@ bool resource_are_streams_timing_synchronizable(
        struct dc_stream_state *stream1,
        struct dc_stream_state *stream2)
 {
+
+       if (stream1->ctx->dc->config.imac5K_support &&
+               ((stream1->signal == SIGNAL_TYPE_EDP && stream2->signal == SIGNAL_TYPE_DISPLAY_PORT &&
+               stream2->link->link_index == 1) ||
+               (stream2->signal == SIGNAL_TYPE_EDP && stream1->signal == SIGNAL_TYPE_DISPLAY_PORT &&
+               stream1->link->link_index == 1)))
+               return true;
+
        if (stream1->timing.h_total != stream2->timing.h_total)
                return false;
 
drivers/gpu/drm/amd/display/dc/dc.h +2 -0
index d3c484f45..a0b746250 100644
@@ -635,6 +635,8 @@ struct dc_config {
        struct spl_sharpness_range dcn_sharpness_range;
        struct spl_sharpness_range dcn_override_sharpness_range;
        bool no_native422_support;
+       bool imac5K_support;
+       bool imac5K_using_5K;
 };
 
 enum visual_confirm {
drivers/gpu/drm/amd/display/dc/hwss/dce110/dce110_hwseq.c +33 -4
index 7b3aa02dd..aba1dc9b4 100644
@@ -2656,7 +2656,8 @@ enum dc_status dce110_apply_ctx_to_hw(
        struct dce_hwseq *hws = dc->hwseq;
        struct dc_bios *dcb = dc->ctx->dc_bios;
        enum dc_status status;
-       unsigned int i;
+       unsigned int i, n, enable_order[MAX_PIPES];
+       int primary = -1, companion = -1;
        bool was_hpo_acquired = resource_is_hpo_acquired(dc->current_state);
        bool is_hpo_acquired = resource_is_hpo_acquired(context);
 
@@ -2664,6 +2665,32 @@ enum dc_status dce110_apply_ctx_to_hw(
        if (dc->config.use_pipe_ctx_sync_logic)
                reset_syncd_pipes_from_disabled_pipes(dc, context);
 
+       for (i = 0; i < dc->res_pool->pipe_count; i++) {
+               struct pipe_ctx *pipe = &context->res_ctx.pipe_ctx[i];
+
+               enable_order[i] = i;
+               if (!dc->config.imac5K_support || !pipe->stream ||
+                   pipe->top_pipe || pipe->prev_odm_pipe)
+                       continue;
+               if (pipe->stream->link->link_index == 0)
+                       primary = i;
+               else if (pipe->stream->link->link_index == 1)
+                       companion = i;
+       }
+       if (companion >= 0 && primary > companion) {
+               enable_order[companion] = primary;
+               enable_order[primary] = companion;
+       }
+
+       if (primary >= 0 && companion >= 0) {
+               struct pipe_ctx *old = &dc->current_state->res_ctx.pipe_ctx[primary];
+               struct dc_link *right = context->res_ctx.pipe_ctx[companion].stream->link;
+
+               if (!old->stream ||
+                   pipe_need_reprogram(old, &context->res_ctx.pipe_ctx[primary]))
+                       right->link_state_valid = false;
+       }
+
        /* Reset old context */
        /* look up the targets that have been removed since last commit */
        hws->funcs.reset_hw_ctx_wrap(dc, context);
@@ -2705,10 +2732,12 @@ enum dc_status dce110_apply_ctx_to_hw(
                dc->hwseq->funcs.setup_hpo_hw_control(dc->hwseq, is_hpo_acquired);
        }
 
-       for (i = 0; i < dc->res_pool->pipe_count; i++) {
+       for (n = 0; n < dc->res_pool->pipe_count; n++) {
                struct pipe_ctx *pipe_ctx_old =
-                                       &dc->current_state->res_ctx.pipe_ctx[i];
-               struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[i];
+                       &dc->current_state->res_ctx.pipe_ctx[enable_order[n]];
+               struct pipe_ctx *pipe_ctx = &context->res_ctx.pipe_ctx[enable_order[n]];
+
+               i = enable_order[n];
 
                if (pipe_ctx->stream == NULL)
                        continue;
drivers/gpu/drm/amd/display/dc/link/link_detection.c +13 -1
index b4546f93a..a92399753 100644
@@ -1205,7 +1205,10 @@ static bool detect_link_and_local_sink(struct dc_link *link,
                                if (!link->dpcd_caps.set_power_state_capable_edp)
                                        link->wa_flags.dp_keep_receiver_powered = true;
                        }
-
+                       if (dc->config.imac5K_support) {
+                               const uint8_t val = 1;
+                               core_link_write_dpcd(link, 0x4F1, &val, 1);
+                       }
                        sink_caps.transaction_type = DDC_TRANSACTION_TYPE_I2C_OVER_AUX;
                        sink_caps.signal = SIGNAL_TYPE_EDP;
                        break;
@@ -1634,6 +1637,15 @@ bool link_detect(struct dc_link *link, enum dc_detect_reason reason)
        bool is_delegated_to_mst_top_mgr = false;
        enum dc_connection_type pre_link_type = link->type;
 
+       if (link->local_sink &&
+                       link->dc->config.imac5K_support &&
+                       link->local_sink->link->link_index == 1)
+               return false;
+
+       if (reason == DETECT_REASON_BOOT && link->dc->config.imac5K_support &&
+           link->link_index == 1)
+               msleep(100);
+
        is_local_sink_detect_success = detect_link_and_local_sink(link, reason);
 
        if (is_local_sink_detect_success && link->local_sink) {
drivers/gpu/drm/amd/display/dc/link/link_dpms.c +3 -0
index 2aeb9a0e6..3d7d1ddc4 100644
@@ -2084,6 +2084,9 @@ static enum dc_status enable_link_dp(struct dc_state *state,
                        !link->dc->config.enable_dpia_pre_training)
                do_fallback = true;
 
+       if (link->dc->config.imac5K_support && link->link_index == 1)
+               msleep(100);
+
        /*
         * Temporary w/a to get DP2.0 link rates to work with SST.
         * TODO DP2.0 - Workaround: Remove w/a if and when the issue is resolved.
drivers/gpu/drm/amd/display/dc/link/protocols/link_dp_phy.c +5 -0
index 49521ac4b..e90164a58 100644
@@ -53,6 +53,11 @@ void dpcd_write_rx_power_ctrl(struct dc_link *link, bool on)
        core_link_write_dpcd(link, DP_SET_POWER, &state,
                                                 sizeof(state));
 
+       if (on && link->dc->config.imac5K_support &&
+           link->connector_signal == SIGNAL_TYPE_EDP) {
+               state = 1;
+               core_link_write_dpcd(link, 0x4F1, &state, sizeof(state));
+       }
 }
 
 void dp_enable_link_phy(
drivers/gpu/drm/amd/display/dc/link/protocols/link_dp_training.c +2 -1
index 3be36d106..4eca11169 100644
@@ -1540,8 +1540,15 @@ static enum link_training_result dp_transition_to_video_idle(
                 */
                if (link->connector_signal != SIGNAL_TYPE_EDP && status == LINK_TRAINING_SUCCESS) {
                        msleep(5);
-                       if (!link->skip_fallback_on_link_loss)
+                       if (link->dc->config.imac5K_support && link->link_index == 1) {
+                               uint8_t lanes;

drivers/gpu/drm/amd/display/dc/link/protocols/link_dp_training.c static enum link_training_result dp_transition_to_video_idle( · line 1554

Quoted 10 lines
drivers/gpu/drm/amd/display/dc/link/protocols/link_dp_training.c +6 -0
+
+                               if (core_link_read_dpcd(link, DP_LANE0_1_STATUS,
+                                                       &lanes, 1) != DC_OK)
+                                       status = LINK_TRAINING_LINK_LOSS;
+                       } else if (!link->skip_fallback_on_link_loss) {
                                status = dp_check_link_loss_status(link, lt_settings);
+                       }
                }
                return status;
        }

I think the rest of this can be simplified quite a bit. I'd suggest rebasing this on the other 5K support patches and see how much of that code you can share.
https://lists.freedesktop.org/archives/dri-devel/2026-November/610011.html

Alex

Quoted 3 lines

--
2.55.0

#2 lore raw
Quoted 1 line

What's the reason for this change?

This is the code that fixes the SMU boot issue, that we discussed eariler:

https://lore.kernel.org/all/[email protected]/

Its confirmed to be 0x4F1 as OCLP enables it, and with OCLP and no patches it booted fine.

I plan to add 5K support to efi libstub or something in the future, hence the TODO, so we get 5K in simpledrm and get rid of this not good looking quirk.

#5 lore raw
In reply to Alex Deucher
Quoted 4 lines

I think the rest of this can be simplified quite a bit. I'd suggest rebasing this on the other 5K support patches and see how much of that code you can share.
https://lists.freedesktop.org/archives/dri-devel/2026-November/610011.html

The code that i saw, dosent have the ability to change resolutions, and the code it self, is basically completely different, for example writing 0 to 0x4F1 completely kills 5K forever, you cant alive it again on iMac20,1 and the code does that.

#6 lore raw
In reply to Atharva Tiwari
Thank you for your contribution! Sashiko AI review found 7 potential issue(s) to consider: - [High] drm/amdgpu: registering DM before SMU in amdgpu_discovery_set_ip_blocks() - [Medium]…

Thank you for your contribution! Sashiko AI review found 7 potential issue(s) to consider:
- [High] drm/amdgpu: registering DM before SMU in amdgpu_discovery_set_ip_blocks()
- [Medium] drm/amd/display: dm_encoder_helper_atomic_check() forces RMX_FULL scaling
- [Medium] drm/amd/display: max_requested_bpc still set to 16 when skipping max_bpc prop
- [Medium] drm/amd/display: resource_are_streams_timing_synchronizable() skips timing check
- [Medium] drm/amd/display: unchecked DP_LANE0_1_STATUS value in dp_transition_to_video_idle()
- [Medium] drm/amd/display: unscoped imac5K_support quirk breaks external GPUs on iMac20,1/2
- [Medium] drm/amd/display: unchecked DP_LANE0_1_STATUS value in dp_transition_to_video_idle() --

commit 6453a4798539c35712ed27f125a2228a469fabe9
Author: Atharva Tiwari <[email protected]>

drm/amd/amdgpu: Add 5K Support for iMac20,1 and iMac20,2

This commit adds 5K display and resolution switching support for Apple iMac20,1 and iMac20,2 systems via DMI quirks and dual-link eDP/DP handling in amdgpu_dm and DC.

Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c +0 -0
index 890792a94e09f..fc107e4fab4fd 100644

[ ... ]

Quoted 15 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c +7 -0
@@ -4026,15 +4043,24 @@ int amdgpu_discovery_set_ip_blocks(struct amdgpu_device *adev)
 		}
 	}
 
+	/* TODO: We should enable 5K in EFI and remove this quirk */
+	if (unlikely(dmi_check_system(imac5k_table))) {
+		r = amdgpu_discovery_set_display_ip_blocks(adev);
+		if (r)
+			return r;
+	}
+
 	if (likely(adev->firmware.load_type == AMDGPU_FW_LOAD_PSP)) {
 		r = amdgpu_discovery_set_smu_ip_blocks(adev);
 		if (r)
 			return r;

drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c int amdgpu_discovery_set_ip_blocks(struct amdgpu_device *adev) · line 4063

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c +5 -3
 	}
 
-	r = amdgpu_discovery_set_display_ip_blocks(adev);
-	if (r)
-		return r;
+	if (likely(!dmi_check_system(imac5k_table))) {
+		r = amdgpu_discovery_set_display_ip_blocks(adev);
+		if (r)
+			return r;
+	}

[Severity: High]
Does registering the display IP block before the SMU IP block in amdgpu_discovery_set_ip_blocks() break DC/SMU initialization and teardown ordering?

During amdgpu_device_ip_init() -> amdgpu_device_ip_hw_init_phase2(), IP blocks are initialized in forward registration order, so dm_hw_init() -> amdgpu_dm_init() -> dc_create() -> dcn20_resource_construct() runs before smu_hw_init():

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c:smu_hw_init() {
	...
	ret = smu_init_max_sustainable_clocks(smu);
	if (ret) {
		dev_err(adev->dev, "Failed to init max sustainable clocks!\n");
		return ret;
	}

	adev->pm.dpm_enabled = true;
	...
}

Because smu_hw_init() has not run yet when dcn20_resource_construct() and init_soc_bounding_box() execute, adev->pm.dpm_enabled is still false. As a result, smu_get_uclk_dpm_states(), smu_get_max_sustainable_clocks_by_dc(), and smu_set_watermarks_for_clock_ranges() all check (!smu->pm_enabled || !smu->adev->pm.dpm_enabled) and return -EOPNOTSUPP. This skips dcn20_update_bounding_box() and dcn20_cap_soc_clocks(), leaves the DCN watermark table unprogrammed in the SMU, fails clock requests during dc_hardware_init(), and then resets the active display count to 0 when smu_hw_init() -> smu_smc_hw_setup() -> smu_init_display_count(smu, 0) runs afterwards.

In addition, amdgpu_device_ip_fini_early() tears down IP blocks in reverse registration order, so smu_hw_fini() will disable SMU DPM before dm_hw_fini() shuts down the display hardware.

Quoted 7 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_connector.c +0 -0
index b498fc5fbb140..d18c7828a2855 100644
@@ -123,6 +123,13 @@ STATIC_IFN_KUNIT int dm_encoder_helper_atomic_check(struct drm_encoder *encoder,
 				       drm_mode_vrefresh(adjusted_mode));
 			dm_new_connector_state->scaling = RMX_ASPECT;

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_connector.c STATIC_IFN_KUNIT int dm_encoder_helper_atomic_check(struct drm_encoder *encoder, · line 134

Quoted 10 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_connector.c +7 -0
 		}
+
+		if (aconnector->dc_link && aconnector->dc_link->dc->config.imac5K_support) {
+			if (crtc_state->mode.vdisplay != 2880)
+				dm_new_connector_state->scaling = RMX_FULL;
+			else
+				dm_new_connector_state->scaling = RMX_OFF;
+		}
 		return 0;
 	}

[Severity: Medium]
Should dm_encoder_helper_atomic_check() avoid forcing RMX_FULL when crtc_state->mode.vdisplay != 2880?

Unconditionally setting dm_new_connector_state->scaling to RMX_FULL stretches non-16:9 modes across the screen instead of keeping the aspect ratio with RMX_ASPECT, overwrites any explicit scaling_mode property requested by userspace (such as RMX_ASPECT or RMX_CENTER), and forces scaling even when crtc_state->mode is the panel's single-cable native 3840x2160 mode (where drm_crtc_helper_mode_valid_fixed() returns MODE_OK).

[ ... ]

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_connector.c void amdgpu_dm_connector_init_helper(struct amdgpu_display_manager *dm, · line 3335

Quoted 9 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_connector.c +1 -1
@@ -3312,7 +3329,7 @@ void amdgpu_dm_connector_init_helper(struct amdgpu_display_manager *dm,
 				adev->mode_info.underscan_vborder_property,
 				0);
 
-	if (!aconnector->mst_root)
+	if (!aconnector->mst_root && !(dm->imac5K_support && link_index <= 1))
 		drm_connector_attach_max_bpc_property(&aconnector->base, 8, 16);
 
 	aconnector->base.state->max_bpc = 16;

[Severity: Medium]
Does skipping drm_connector_attach_max_bpc_property() in amdgpu_dm_connector_init_helper() actually cap the bpc on links 0 and 1?

Right after this check, amdgpu_dm_connector_init_helper() still executes:

	aconnector->base.state->max_bpc = 16;
	aconnector->base.state->max_requested_bpc = aconnector->base.state->max_bpc;

Because amdgpu_dm_create_validate_stream_for_sink() reads requested_bpc from drm_state->max_requested_bpc and drm_atomic_connector_check() only clamps state->max_bpc when connector->max_bpc_property is attached, max_requested_bpc remains 16 while userspace loses the max bpc KMS property on both connectors.

Quoted 4 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_quirks.c +0 -0
index 259966703cef5..8657dd972ee96 100644

[ ... ]

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_quirks.c void retrieve_dmi_info(struct amdgpu_display_manager *dm) · line 206

Quoted 9 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_quirks.c +4 -0
@@ -176,6 +199,10 @@ void retrieve_dmi_info(struct amdgpu_display_manager *dm)
 		dm->edp0_on_dp1_quirk = true;
 		drm_info(dev, "support_edp0_on_dp1 attached\n");
 	}
+	if (quirk_entries.imac5K_support) {
+		dm->imac5K_support = true;
+		drm_info(dev, "imac5K_support attached\n");
+	}
 }

[Severity: Medium]
What happens if an external AMD GPU (eGPU) is connected to an iMac20,1 or iMac20,2?

In retrieve_dmi_info(), dm->imac5K_support (and consequently dc->config.imac5K_support) is enabled solely from the host DMI match without checking whether the GPU actually drives the internal eDP panel. On an external AMD GPU attached to one of these hosts:

- link_detect() will return false on link_index == 1 once link->local_sink is populated, preventing subsequent unplug, hotplug, or resume detection on that connector.
- amdgpu_dm_connector_init_helper() will omit the max bpc property on link_index 0 and 1.
- dce110_apply_ctx_to_hw() and dp_transition_to_video_idle() will treat link_index 0 and 1 on the external GPU as the internal primary and companion 5K links.

Should imac5K_support be scoped to the internal GPU or verified against link 0 being an eDP connector?

Quoted 8 lines
drivers/gpu/drm/amd/display/dc/core/dc_resource.c +0 -0
index 187486d978da6..98f74ffc2c27f 100644
@@ -689,6 +689,14 @@ bool resource_are_streams_timing_synchronizable(
 	struct dc_stream_state *stream1,
 	struct dc_stream_state *stream2)
 {

drivers/gpu/drm/amd/display/dc/core/dc_resource.c bool resource_are_streams_timing_synchronizable( · line 701

Quoted 10 lines
drivers/gpu/drm/amd/display/dc/core/dc_resource.c +8 -0
+
+	if (stream1->ctx->dc->config.imac5K_support &&
+		((stream1->signal == SIGNAL_TYPE_EDP && stream2->signal == SIGNAL_TYPE_DISPLAY_PORT &&
+		stream2->link->link_index == 1) ||
+		(stream2->signal == SIGNAL_TYPE_EDP && stream1->signal == SIGNAL_TYPE_DISPLAY_PORT &&
+		stream1->link->link_index == 1)))
+		return true;
+
 	if (stream1->timing.h_total != stream2->timing.h_total)
 		return false;

[Severity: Medium]
In resource_are_streams_timing_synchronizable(), does returning true at the very beginning of the function bypass the timing equality checks when the two streams have different timings?

Placing this return before the comparisons of h_total, v_total, h_addressable, v_addressable, v_front_porch, and pix_clk_100hz means any active streams on eDP and DP link 1 are reported as timing-synchronizable even if their timings do not match (for example, during a per-CRTC legacy modeset where one CRTC switches to a non-5K mode while the second CRTC is still active at 2560x2880). Callers such as program_timing_sync() will then attempt to hardware-synchronize OTGs running with incompatible timings.

Should this check be placed after the timing comparisons so that it only bypasses the clamping.c_depth or ignore_msa_timing_param checks?

Quoted 11 lines
drivers/gpu/drm/amd/display/dc/link/protocols/link_dp_training.c +2 -1
index 3be36d1063ded..4eca11169f803 100644
@@ -1540,8 +1540,15 @@ static enum link_training_result dp_transition_to_video_idle(
 		 */
 		if (link->connector_signal != SIGNAL_TYPE_EDP && status == LINK_TRAINING_SUCCESS) {
 			msleep(5);
-			if (!link->skip_fallback_on_link_loss)
+			if (link->dc->config.imac5K_support && link->link_index == 1) {
+				uint8_t lanes;

drivers/gpu/drm/amd/display/dc/link/protocols/link_dp_training.c static enum link_training_result dp_transition_to_video_idle( · line 1554

Quoted 10 lines
drivers/gpu/drm/amd/display/dc/link/protocols/link_dp_training.c +6 -0
+
+				if (core_link_read_dpcd(link, DP_LANE0_1_STATUS,
+							&lanes, 1) != DC_OK)
+					status = LINK_TRAINING_LINK_LOSS;
+			} else if (!link->skip_fallback_on_link_loss) {
 				status = dp_check_link_loss_status(link, lt_settings);
+			}
 		}
 		return status;
 	}

[Severity: Medium]
In dp_transition_to_video_idle(), DP_LANE0_1_STATUS is read into lanes on link_index == 1, but the value of lanes is never inspected (and DP_LANE2_3_STATUS is not read).

If the AUX read returns DC_OK while the lane status bits report that clock recovery, channel equalization, or symbol lock failed, status remains LINK_TRAINING_SUCCESS. Was lanes meant to be checked for lane status bits, or is this intentionally only testing whether the AUX transaction succeeds on the TCON?

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
#3 lore raw
In reply to Atharva Tiwari
Quoted 11 lines · Atharva Tiwari
Quoted 2 lines

What's the reason for this change?

This is the code that fixes the SMU boot issue, that we discussed eariler:

https://lore.kernel.org/all/[email protected]/

Its confirmed to be 0x4F1 as OCLP enables it, and with OCLP and no patches it booted fine.

I plan to add 5K support to efi libstub or something in the future, hence the TODO, so we get 5K in simpledrm and get rid of this not good looking quirk.

That sounds like a separate logical change from the rest of the patch. If changing the order of the init sequence fixes the SMU UCLK issue, that should be a separate patch from the changes to enable the 5K display. That said, I'm not really keen on this change. Can you dig further and figure out what the actual issue is? There are now 3 separate slightly different fixes for this for people with various Macs:
1. Enabling UCLK DPM in late init
2. Using the UCLK states from the UMC DPM table
3. Changing the init order for specific Mac models

Alex

#4 lore raw
Quoted 10 lines

That sounds like a separate logical change from the rest of the patch. If changing the order of the init sequence fixes the SMU UCLK issue, that should be a separate patch from the changes to enable the 5K display. That said, I'm not really keen on this change. Can you dig further and figure out what the actual issue is? There are now 3 separate slightly different fixes for this for people with various Macs:
1. Enabling UCLK DPM in late init
2. Using the UCLK states from the UMC DPM table
3. Changing the init order for specific Mac models

I can understand your confusion, so i have tested some scenario's to make you understand the situation. And for the moment you can assume that OCLP is a efi loader that sets 0x4f1 to 1.

1. Stock Amdgpu, Without OCLP (0x4f1 = 0): Crashes 6/10 times, 3840x2160, UCLK works
2. Stock Amdgpu, With OCLP (0x4f1 = 1): Crashes 0/10 times, 2560x2880 (1 tile streched), UCLK works
3. Late UCLK patch, Without OCLP (0x4f1 = 0): Crashes 0/10 times, 3840x2160, UCLK works
4. Late UCLK patch, With OCLP (0x4f1 = 1): Crashes 0/10 times, 2560x2880, UCLK does not work (Command are sent BUT no change in hardware).
5. This patch, Without OCLP, Without revised boot order

	 (0x4f1 = 0, at boot, after amdgpu init 0x4f1 = 1): Crashes 5/10 times, 5120x2880, UCLK works
6. This patch, With OCLP, Without revised boot order (0x4f1 = 1): Crashes 0/10 times, 5120x2880, UCLK works
7. This patch, without OCLP, With revised boot order
	(0x4f1 = 0, at boot, after amdgpu init 0x4f1 = 1): Crashes 0/10 times, 5120x2880, UCLK works
8. This patch, with OCLP, With revised boot order
	(0x4f1 = 1): Crashes 0/10 times, 5120x2880, UCLK works

So from these scenario's you can probably conclude that 0x4F1 = 1 is needed for SMU to boot properly and thats the reason for the init order change, to set 0x4F1 before SMU init, if we can for example set 0x4F1 in EFI (x86-libstub) (like OCLP), we dont need the init order change, but to do that we need to RE the DXE modules in apple EFI and check how apple's firmware sets 0x4f1 = 1.
And even OCLP does not enable 0x4F1 on its own, its fakes being macOS, and then the
DXE modules turn 0x4F1 on, for the "faking" macOS, we need EFI changes across iMacs which is not fesiable.

And the UMC DPM tables patch does not interfere with anything, its not needed for iMacs.