Skip to contentSkip to conversation

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

PATCH New Atharva Tiwari 2 participants 2 messages Nov 23

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH v3 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.

0x4F1 is an Apple-specific DPCD register on the iMac 5K TCON that selects tile mode: with 0x4F1 = 0 the panel comes up as a single 3840x2160 display, and with 0x4F1 = 1 it is driven as 5120x2880 over two tiles.

On these iMacs, 0x4F1 = 1 is also required for the SMU to boot properly. With it unset at SMU init, we see crashes in 5/10 boots even with the 5K support applied (UCLK still works). With it set, or with the display IP block initialized before SMU, crashes drop to 0/10.

To avoid depending on the bootloader, init the display IP block before SMU on DMI-matched iMac20,1/20,2, so 0x4F1 is set before SMU init.

(Tested on iMac20,1 and iMacPro1,1)

---
Changes in v3:
- Restricted the display to 10bpc
Changes in v2:
- Added check to remove thunderbolt devices from 5K list
- defined 0x4f1 as DP_APPLE_5K_TILE_MODE
- Added iMacPro1,1 to 5K list

 drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c | 43 +++++++++++++++++--
 .../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 28 ++++++++++++
 .../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.h |  7 +++
 .../display/amdgpu_dm/amdgpu_dm_connector.c   | 35 +++++++++++++--
 .../amd/display/amdgpu_dm/amdgpu_dm_quirks.c  | 38 +++++++++++++++-
 .../gpu/drm/amd/display/dc/core/dc_resource.c |  9 ++++
 drivers/gpu/drm/amd/display/dc/dc.h           |  2 +
 drivers/gpu/drm/amd/display/dc/dc_dp_types.h  |  2 +
 .../amd/display/dc/hwss/dce110/dce110_hwseq.c | 37 ++++++++++++++--
 .../drm/amd/display/dc/link/link_detection.c  | 13 ++++++
 .../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      | 10 ++++-
 13 files changed, 219 insertions(+), 13 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c +40 -3
index 890792a94..a907d5629 100644
@@ -21,6 +21,7 @@
  *
  */
 
+#include <linux/dmi.h>
 #include <linux/firmware.h>
 #include <linux/kernfs.h>
 
@@ -3412,8 +3413,34 @@ 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"),
+		},
+	},
+	{}
+};
+
+static bool amdgpu_discovery_is_imac5k(struct amdgpu_device *adev)
+{
+	if (pci_is_thunderbolt_attached(adev->pdev) ||
+	    dev_is_removable(&adev->pdev->dev))
+		return false;
+
+	return dmi_check_system(imac5k_table);
+}
+
 int amdgpu_discovery_set_ip_blocks(struct amdgpu_device *adev)
 {
+	bool imac5k;
 	int r;
 
 	switch (adev->asic_type) {
@@ -4026,15 +4053,25 @@ int amdgpu_discovery_set_ip_blocks(struct amdgpu_device *adev)
 		}
 	}
 
+	/* TODO: We should enable 5K in EFI and remove this quirk */
+	imac5k = amdgpu_discovery_is_imac5k(adev);
+	if (unlikely(imac5k)) {
+		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(!imac5k)) {
+		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 +28 -0
index 5b634ae07..ea0af1fdd 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], DP_APPLE_5K_TILE_MODE, &value, 1);
+		}
 		dm_gpureset_commit_state(dm->cached_dc_state, dm);
 
 		dm_gpureset_toggle_interrupts(adev, dm->cached_dc_state, true);
@@ -4739,6 +4746,27 @@ 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],
+						     DP_APPLE_5K_TILE_MODE, &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 +31 -4
index 2b81396bd..e51ca7c95 100644
@@ -123,6 +123,14 @@ 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;
 		}
+
+		/* The 5K panel reports no scaling info, scale every non 5K mode to full */
+		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 +3138,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,11 +3330,20 @@ void amdgpu_dm_connector_init_helper(struct amdgpu_display_manager *dm,
 				adev->mode_info.underscan_vborder_property,
 				0);
 
-	if (!aconnector->mst_root)
-		drm_connector_attach_max_bpc_property(&aconnector->base, 8, 16);
+	if (!aconnector->mst_root) {
+		if (dm->imac5K_support && link_index <= 1)
+			drm_connector_attach_max_bpc_property(&aconnector->base, 10, 10);
+		else
+			drm_connector_attach_max_bpc_property(&aconnector->base, 8, 16);
+	}
 
-	aconnector->base.state->max_bpc = 16;
-	aconnector->base.state->max_requested_bpc = aconnector->base.state->max_bpc;
+	if (dm->imac5K_support && link_index <= 1) {
+		aconnector->base.state->max_bpc = 10;
+		aconnector->base.state->max_requested_bpc = 10;
+	} else {
+		aconnector->base.state->max_bpc = 16;
+		aconnector->base.state->max_requested_bpc = aconnector->base.state->max_bpc;
+	}
 
 	if (connector_type == DRM_MODE_CONNECTOR_HDMIA) {
 		/* Content Type is currently only implemented for HDMI. */
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_quirks.c +37 -1
index 259966703..a84ff90ef 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,27 @@ 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"),
+		},
+	},
+	{
+		.callback = imac5K_support_callback,
+		.matches = {
+			DMI_MATCH(DMI_SYS_VENDOR, "Apple Inc."),
+			DMI_MATCH(DMI_PRODUCT_NAME, "iMacPro1,1"),
+		},
+	},
 	{}
 	/* TODO: refactor this from a fixed table to a dynamic option */
 };
@@ -162,6 +191,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 +206,12 @@ 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 &&
+	    !pci_is_thunderbolt_attached(dm->adev->pdev) &&
+	    !dev_is_removable(&dm->adev->pdev->dev)) {
+		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 +9 -0
index 187486d97..e62f14f04 100644
@@ -711,6 +711,15 @@ bool resource_are_streams_timing_synchronizable(
 				!= stream2->timing.pix_clk_100hz)
 		return false;
 
+	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->clamping.c_depth != stream2->clamping.c_depth)
 		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/dc_dp_types.h +2 -0
index b0e91b321..09bcb1600 100644
@@ -1510,6 +1510,8 @@ struct dp_trace {
 /* TODO - This is a temporary location for any new DPCD definitions.
  * We should move these to drm_dp header.
  */
+/* Apple 5K iMac TCON, 1 drives the panel as two tiles */
+#define DP_APPLE_5K_TILE_MODE				0x4F1
 #ifndef DP_LINK_SQUARE_PATTERN
 #define DP_LINK_SQUARE_PATTERN				0x10F
 #endif
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 -0
index b4546f93a..9b69a8013 100644
@@ -1205,7 +1205,11 @@ 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, DP_APPLE_5K_TILE_MODE, &val, 1);
+			}
 			sink_caps.transaction_type = DDC_TRANSACTION_TYPE_I2C_OVER_AUX;
 			sink_caps.signal = SIGNAL_TYPE_EDP;
 			break;
@@ -1634,6 +1638,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..e7ce8e903 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, DP_APPLE_5K_TILE_MODE, &state, sizeof(state));
+	}
 }
 
 void dp_enable_link_phy(
drivers/gpu/drm/amd/display/dc/link/protocols/link_dp_training.c +9 -1
index 3be36d106..0618333bb 100644
@@ -1540,8 +1540,16 @@ 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) {
+				/* The 5K tile link only has to answer AUX */
+				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
Thank you for your contribution! Sashiko AI review found 7 potential issues 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 issues 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: companion pipe left blanked in dce110_apply_ctx_to_hw()
- [Low] drm/amd/display: undocumented iMacPro1,1 DMI quirk in dmi_quirk_table
- [Low] drm/amd/display: NULL dm->adev dereference in retrieve_dmi_info() KUnit tests
- [Low] drm/amd/display: direct edid_blob_ptr use and redundant alloc in get_modes()
- [Low] drm/amd/display: redundant DPCD write in amdgpu_dm_commit_streams()
--

commit f1d3c9c046bd569268b41732fc66898568a48d2e
Author: Atharva Tiwari <[email protected]>

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

This commit adds 5K tiled display support for Apple iMac 5K systems by programming the Apple-specific DPCD 0x4F1 tile-mode register, synchronizing the dual-link pipes, and initializing the display IP block ahead of the SMU on iMac20,1 and iMac20,2.

Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c +0 -0
index 164e85b66e2d4..479c71ec32109 100644

[ ... ]

Quoted 16 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c +8 -0
@@ -3677,15 +3704,25 @@ int amdgpu_discovery_set_ip_blocks(struct amdgpu_device *adev)
 		}
 	}
 
+	/* TODO: We should enable 5K in EFI and remove this quirk */
+	imac5k = amdgpu_discovery_is_imac5k(adev);
+	if (unlikely(imac5k)) {
+		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 3725

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(!imac5k)) {
+		r = amdgpu_discovery_set_display_ip_blocks(adev);
+		if (r)
+			return r;
+	}

[Severity: High]
Does registering dm_ip_block ahead of smu_v11_0_ip_block break DCN2.0 SMU initialization and teardown ordering?

During amdgpu_device_ip_hw_init_phase2(), dm_hw_init() -> amdgpu_dm_init() -> dc_create() -> dcn20_resource_construct() now runs before smu_hw_init() sets adev->pm.dpm_enabled = true. In that state, smu_get_uclk_dpm_states(), smu_get_max_sustainable_clocks_by_dc(), and smu_set_watermarks_for_clock_ranges() all reject DC's calls with -EOPNOTSUPP:

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c:smu_set_watermarks_for_clock_ranges() {
	...
	if (!smu->pm_enabled || !smu->adev->pm.dpm_enabled)
		return -EOPNOTSUPP;
	...
}

Because dcn20_resource_construct() only uploads watermarks once at init, WATERMARKS_EXIST is never set in smu->watermarks_bitmap, leaving DCN watermark tables unprogrammed at boot and across S3/S4 resume and causing navi10_display_config_changed() to skip SMU_MSG_NumOfDisplays. In addition, amdgpu_device_ip_fini_early() and amdgpu_device_ip_fini() walk adev->ip_blocks[] in reverse registration order, so smu_hw_fini() and smu_sw_fini() tear down SMU DPM before dm_hw_fini() shuts down the display engine.

Quoted 4 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +0 -0
index 284aac4d96bce..8c85878951287 100644

[ ... ]

Quoted 15 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +11 -0
@@ -4591,6 +4598,27 @@ 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 &&

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c static void amdgpu_dm_commit_streams(struct drm_atomic_commit *state, · line 4621

Quoted 10 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +10 -0
+			    new_crtc_state->mode.hdisplay == 2560) {
+				u8 value = 1;
+
+				core_link_write_dpcd(dm->dc->links[0],
+						     DP_APPLE_5K_TILE_MODE, &value, 1);
+				dm->dc->config.imac5K_using_5K = true;
+			} else
+				dm->dc->config.imac5K_using_5K = false;
+		}
+	}

[Severity: Low]
Does this write DP_APPLE_5K_TILE_MODE over AUX on every full atomic commit that includes the eDP CRTC, even when no modeset occurred?

amdgpu_dm_atomic_commit_tail() calls amdgpu_dm_commit_streams() whenever lock_and_validation_needed is true (such as plane scaling, format, overlay, or color-management updates), even if dc_commit_streams() returns early because streams did not change. Gating this on mode_set_reset_required or amdgpu_dm_crtc_modeset_required() would avoid redundant AUX writes under dm->dc_lock.

Quoted 8 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_connector.c +0 -0
index c8a1ab8c3b169..e7663adcb501f 100644
@@ -125,6 +125,14 @@ 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 137

Quoted 10 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_connector.c +8 -0
+
+		/* The 5K panel reports no scaling info, scale every non 5K mode to full */
+		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]
Why does dm_encoder_helper_atomic_check() unconditionally overwrite dm_new_connector_state->scaling with RMX_FULL when vdisplay != 2880?

The check right above already defaults non-native eDP modes to RMX_ASPECT when dm_new_connector_state->scaling == RMX_OFF, preserving the aspect ratio as expected when userspace has not requested a scaling mode. Overwriting dm_new_connector_state->scaling unconditionally here stretches non-16:9 modes across the panel, ignores any explicit scaling_mode property set by userspace (such as DRM_MODE_SCALE_ASPECT or DRM_MODE_SCALE_CENTER), and forces scaling even on the panel's native single-cable 3840x2160 mode.

In addition, persisting RMX_FULL in connector->state causes subsequent amdgpu_dm_connector_mode_valid() calls to validate the 2560x2880 tile mode with scaling enabled, where decide_crtc_timing_for_drm_display_mode() replaces its CRTC timings with the 3840x2160 preferred mode's timings.

Quoted 8 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_connector.c +1 -0
@@ -3091,9 +3099,19 @@ static int amdgpu_dm_connector_get_modes(struct drm_connector *connector)
 	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);
 

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_connector.c static int amdgpu_dm_connector_get_modes(struct drm_connector *connector) · line 3115

Quoted 10 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_connector.c +9 -0
+	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) {

[Severity: Low]
Can this use amdgpu_dm_connector->drm_edid instead of testing connector->edid_blob_ptr and allocating a temporary drm_edid?

include/drm/drm_connector.h documents that edid_blob_ptr is internal to DRM and must not be used by drivers directly. Also, when drm_edid is NULL here, freeing kept without storing it in amdgpu_dm_connector->drm_edid (and updating local drm_edid) causes the !drm_edid branch right below to fall back to drm_add_modes_noedid(connector, 640, 480) instead of probing modes from the EDID.

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

[ ... ]

Quoted 16 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_quirks.c +12 -0
@@ -151,6 +159,27 @@ 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"),

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_quirks.c static const struct dmi_system_id dmi_quirk_table[] = { · line 183

Quoted 10 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_quirks.c +9 -0
+		},
+	},
+	{
+		.callback = imac5K_support_callback,
+		.matches = {
+			DMI_MATCH(DMI_SYS_VENDOR, "Apple Inc."),
+			DMI_MATCH(DMI_PRODUCT_NAME, "iMacPro1,1"),
+		},
+	},
 	{}

[Severity: Low]
This isn't a bug, but dmi_quirk_table enables imac5K_support on iMacPro1,1 while the commit subject, changelog, and imac5k_table in amdgpu_discovery.c only describe adding support for iMac20,1 and iMac20,2. Could the commit message document that iMacPro1,1 is also enabled here and why it is omitted from imac5k_table?

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

Quoted 11 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_quirks.c +6 -0
@@ -176,6 +206,12 @@ 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 &&
+	    !pci_is_thunderbolt_attached(dm->adev->pdev) &&
+	    !dev_is_removable(&dm->adev->pdev->dev)) {
+		dm->imac5K_support = true;
+		drm_info(dev, "imac5K_support attached\n");
+	}
 }

[Severity: Low]
Can dm->adev be NULL when retrieve_dmi_info() is called from the KUnit tests in drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_quirks_test.c?

Those tests pass a zero-allocated struct amdgpu_display_manager where dm->adev is NULL, so running the KUnit suite on a DMI-matched iMac will hit a NULL pointer dereference on dm->adev->pdev.

Quoted 5 lines
drivers/gpu/drm/amd/display/dc/hwss/dce110/dce110_hwseq.c +0 -0
index 328321961fba2..edffaca05756c 100644
@@ -2657,7 +2657,8 @@ enum dc_status dce110_apply_ctx_to_hw(

[ ... ]

drivers/gpu/drm/amd/display/dc/hwss/dce110/dce110_hwseq.c enum dc_status dce110_apply_ctx_to_hw( · line 2696

Quoted 12 lines
drivers/gpu/drm/amd/display/dc/hwss/dce110/dce110_hwseq.c +9 -0
+	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);

[Severity: Medium]
On DCE12 (such as Vega10/Vega12 in iMacPro1,1), does clearing right->link_state_valid here without marking the companion stream mode_changed leave the right tile blanked?

When right->link_state_valid is set to false, pipe_need_reprogram() becomes true for the companion pipe inside dce110_reset_hw_ctx_wrap(), which blanks its timing generator, frees its memory input, and calls dc->hwss.disable_plane(). dce110_apply_single_controller_ctx_to_hw() then re-enables the companion timing generator in a blanked state, and on DCE12 (where program_front_end_for_ctx is NULL and apply_ctx_for_surface is used) dc_commit_state_no_check() skips apply_ctx_for_surface() after apply_ctx_to_hw() whenever the companion stream's mode_changed flag is false:

drivers/gpu/drm/amd/display/dc/core/dc.c:dc_commit_state_no_check() {
	...
	for (i = 0; i < context->stream_count; i++) {
		const struct dc_link *link = context->streams[i]->link;

		if (!context->streams[i]->mode_changed)
			continue;

		if (dc->hwss.apply_ctx_for_surface) {
	...
}

This leaves the companion tile's front-end plane disabled and its timing generator blanked whenever the primary pipe is reprogrammed without a mode change on the companion stream. Note also that reset_syncd_pipes_from_disabled_pipes() at the top of dce110_apply_ctx_to_hw() runs before right->link_state_valid is cleared.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1