From 9f617d0f3c870e8fa0c96d9be0d32738dfb68a87 Mon Sep 17 00:00:00 2001 From: Eduardo Date: Wed, 25 Nov 2026 11:52:41 +0000 Subject: [PATCH] drm/apple: m4: offer only external modes the host can scan out An external output scans out from its surfaces or direct-scanout windows, which hold one XRGB8888 frame of at most 5120x2880. The mode list does not know: a larger native mode, such as a 6K display's, is offered and preferred, the firmware sets it, and then the enable fails allocating its surfaces (-EINVAL) and every frame is refused. The display stays black, again at every hotplug. Make the limit part of whether a mode fits: a larger mode is not offered, not preferred, and refused by the atomic check with -ENOSPC, as one over the link is. Seen on a J713 (M4 MacBook Air) with a 5120x2880 display over Thunderbolt while the limit was 3840x2160, and reported on a J715 with a 3840x2400 display then. Signed-off-by: Eduardo --- drivers/gpu/drm/apple/dcp-m4-frame.h | 10 ++++++++++ drivers/gpu/drm/apple/iomfb_m4.c | 29 ++++++++++++++++------------ 2 files changed, 27 insertions(+), 12 deletions(-) diff --git a/drivers/gpu/drm/apple/dcp-m4-frame.h b/drivers/gpu/drm/apple/dcp-m4-frame.h index 35a72fe59e882..aa3e6847ae568 100644 --- a/drivers/gpu/drm/apple/dcp-m4-frame.h +++ b/drivers/gpu/drm/apple/dcp-m4-frame.h @@ -156,6 +156,16 @@ static inline u64 dcp_m4_nits_binary64(u32 nits) #define DCP_M4_EXT_MAX_WIDTH 5120U #define DCP_M4_EXT_MAX_HEIGHT 2880U +/* + * Whether the host can scan out an external output of this size: no larger + * than its surfaces and windows hold (above). Modes over it are not offered. + */ +static inline bool dcp_m4_ext_size_ok(u32 width, u32 height) +{ + return width && height && width <= DCP_M4_EXT_MAX_WIDTH && + height <= DCP_M4_EXT_MAX_HEIGHT; +} + /* * External outputs: any qualified size up to 5120x2880, same surface layout. * The frame must already be described at its wire DVA in an owned mapping. diff --git a/drivers/gpu/drm/apple/iomfb_m4.c b/drivers/gpu/drm/apple/iomfb_m4.c index dd3e573e89044..87727c1fc4db7 100644 --- a/drivers/gpu/drm/apple/iomfb_m4.c +++ b/drivers/gpu/drm/apple/iomfb_m4.c @@ -3107,12 +3107,13 @@ int iomfb_m4_ext_detect(struct apple_dcp *owner) /* * The sink's modes for its DRM connector: the cached 8-bpc RGB SDR timings that - * fit the DPTX link at 24 bits per pixel, when the link rate and lane count - * are known (8b/10b coding); the firmware's own judgement is in the colour - * elements it marks unsafe or DSC-only, which are never used. The preferred - * one is the highest refresh rate at the sink's native size that fits, else - * the largest sink-preferred timing that fits, both at 50 Hz or more (see - * dcp_m4_ext_pick_preferred()), else 1920x1080 at 60 Hz (else the first). + * the host can scan out and that fit the DPTX link at 24 bits per pixel, when + * the link rate and lane count are known (8b/10b coding); the firmware's own + * judgement is in the colour elements it marks unsafe or DSC-only, which are + * never used. The preferred one is the highest refresh rate at the sink's + * native size that fits, else the largest sink-preferred timing that fits, + * both at 50 Hz or more (see dcp_m4_ext_pick_preferred()), else 1920x1080 at + * 60 Hz (else the first). * Takes ext_modes_lock only, never the session. */ /* The DPTX link's capacity in kbit/s at 8b/10b, 0 while not known. */ @@ -3129,18 +3130,22 @@ static u64 dcp_m4_ext_capacity(struct apple_dcp *owner) } /* - * Whether a cached mode fits the link: at 24 bpp uncompressed, at 8 bpp (the - * lowest DSC target) with a colour that needs DSC, whose rate the firmware - * picks itself. + * Whether a cached mode can be shown: no larger than the host can scan out + * (DCP_M4_EXT_MAX_WIDTH x DCP_M4_EXT_MAX_HEIGHT), and within the link: at + * 24 bpp uncompressed, at 8 bpp (the lowest DSC target) with a colour that + * needs DSC, whose rate the firmware picks itself. */ static bool dcp_m4_ext_fits(const struct iomfb_m4_ext_mode *e, u64 capacity) { + if (!dcp_m4_ext_size_ok(e->mode.hdisplay, e->mode.vdisplay)) + return false; return !capacity || (u64)e->mode.clock * (e->dsc ? 8 : 24) <= capacity; } /* * The firmware's IDs of a mode iomfb_m4_ext_get_modes() - * offered: -ENOENT for any other mode, -ENOSPC for one over the link. + * offered: -ENOENT for any other mode, -ENOSPC for one over the link or + * larger than the host can scan out. */ int iomfb_m4_ext_mode_ids(struct apple_dcp *owner, const struct drm_display_mode *mode, struct iomfb_m4_ext_ids *ids) @@ -3270,7 +3275,7 @@ static int dcp_m4_ext_pick_preferred(struct iomfb_m4 *dcp, u64 capacity, const c best = i; } if (best >= 0) - *why = "the native size is over the link: the largest preferred timing within it"; + *why = "the native size does not fit: the largest preferred timing that does"; return best; } @@ -3323,7 +3328,7 @@ int iomfb_m4_ext_get_modes(struct apple_dcp *owner, struct drm_connector *connec dcp->ext_logged_modes = added << 16 | skipped; dcp->ext_logged_link = lanes << 16 | rate; dcp->ext_logged_pick = pick; - dev_dbg(dcp->dev, "modes: %u of %u (%u over link %u x %u Mbit/s)%s; preferred %ux%u@%d Hz, %d kHz (%s)\n", + dev_dbg(dcp->dev, "modes: %u of %u (%u over the scanout or link %u x %u Mbit/s)%s; preferred %ux%u@%d Hz, %d kHz (%s)\n", added, total, skipped, lanes, rate * 270, capacity ? "" : ", link not known: not checked", p ? p->hdisplay : 0, p ? p->vdisplay : 0, p ? drm_mode_vrefresh(p) : 0,