From ab7b87192d779427a80b4ffee20d812345ca1c68 Mon Sep 17 00:00:00 2001 From: Eduardo Date: Wed, 25 Nov 2026 11:55:03 +0000 Subject: [PATCH] drm/apple: m4: keep the sink's primaries in the external EDID The EDID an M4 external output publishes goes through dcp_edid_sdr(), written for the native26 outputs and their sRGB output contract. Besides the colour capabilities it zeroes the ten chromaticity bytes, so the connector describes a sink whose red, green, blue and white are all 0,0: no gamut at all. A compositor that maps into the EDID's gamut builds its matrix from these bytes, and a zero set is singular. The M4 path has no such contract. Its link uses a colour element of the sink's own timing, which on an Apple Studio Display is Default RGB, the sink's native gamut: its primaries are the ones frames are shown with. Keep them, through dcp_edid_sdr_native(). Everything else dcp_edid_sdr() removes still goes, and the native26 outputs keep the bytes zeroed. Signed-off-by: Eduardo --- drivers/gpu/drm/apple/dcp-sdr-edid.h | 20 +++++++++++++++++++ drivers/gpu/drm/apple/iomfb_m4.c | 10 +++++----- tools/asahi/dcpext26-edid-tests.py | 9 ++++++++- .../selftests/drivers/gpu/apple-dcp/rate.py | 4 +++- 4 files changed, 36 insertions(+), 7 deletions(-) diff --git a/drivers/gpu/drm/apple/dcp-sdr-edid.h b/drivers/gpu/drm/apple/dcp-sdr-edid.h index 5b8c710de8d7e..f5f7aba51e3d0 100644 --- a/drivers/gpu/drm/apple/dcp-sdr-edid.h +++ b/drivers/gpu/drm/apple/dcp-sdr-edid.h @@ -83,4 +83,24 @@ static inline size_t dcp_edid_sdr(u8 *edid, size_t size) return output; } +/* + * dcp_edid_sdr() for an output without an sRGB contract, whose link carries + * SDR RGB in the sink's own gamut: the sink's primaries are what its frames + * are shown with, so they stay. + */ +static inline size_t dcp_edid_sdr_native(u8 *edid, size_t size) +{ + u8 primaries[DCP_EDID_CHROMATICITY_SIZE]; + + if (size < DCP_EDID_BLOCK_SIZE) + return 0; + memcpy(primaries, edid + DCP_EDID_CHROMATICITY, sizeof(primaries)); + size = dcp_edid_sdr(edid, size); + if (size) { + memcpy(edid + DCP_EDID_CHROMATICITY, primaries, sizeof(primaries)); + dcp_edid_checksum(edid); + } + return size; +} + #endif diff --git a/drivers/gpu/drm/apple/iomfb_m4.c b/drivers/gpu/drm/apple/iomfb_m4.c index dd3e573e89044..0813a78439b2c 100644 --- a/drivers/gpu/drm/apple/iomfb_m4.c +++ b/drivers/gpu/drm/apple/iomfb_m4.c @@ -3334,10 +3334,10 @@ int iomfb_m4_ext_get_modes(struct apple_dcp *owner, struct drm_connector *connec } /* - * The EDID the connector publishes, as native26's (dcp_edid_sdr()): this - * scanout is 8-bpc RGB SDR, so the sink's colour capabilities, deep colour - * and 4:2:0 timings go. The last would otherwise make the probe helper prune - * the catalog's mode of a timing the sink lists as 4:2:0 only. + * The EDID the connector publishes (dcp_edid_sdr_native()): this scanout is + * 8-bpc RGB SDR, so the sink's colour capabilities, deep colour and 4:2:0 + * timings go. The last would otherwise make the probe helper prune the + * catalog's mode of a timing the sink lists as 4:2:0 only. Its primaries stay. */ static const struct drm_edid *iomfb_m4_ext_edid_sdr(const struct drm_edid *edid) { @@ -3352,7 +3352,7 @@ static const struct drm_edid *iomfb_m4_ext_edid_sdr(const struct drm_edid *edid) copy = kmemdup(raw, size, GFP_KERNEL); if (!copy) return ERR_PTR(-ENOMEM); - size = dcp_edid_sdr(copy, size); + size = dcp_edid_sdr_native(copy, size); sdr = size ? drm_edid_alloc(copy, size) : ERR_PTR(-EPROTO); kfree(copy); return sdr ?: ERR_PTR(-ENOMEM); diff --git a/tools/asahi/dcpext26-edid-tests.py b/tools/asahi/dcpext26-edid-tests.py index 0171c1ece0fde..23e040def503a 100644 --- a/tools/asahi/dcpext26-edid-tests.py +++ b/tools/asahi/dcpext26-edid-tests.py @@ -77,12 +77,19 @@ def function(name): memcpy(original,sdr,256);assert(dcp_edid_sdr(sdr,256)==256);assert(!memcmp(sdr,original,256)); for(unsigned n=0;n<128;n++)assert(!dcp_edid_sdr(sdr,n)); assert(!dcp_edid_sdr(sdr,128)); + /* The sink's own primaries kept, the rest as above and the checksum right. */ + u8 native[384];memset(sdr+25,0x55,10);checksum(sdr);memcpy(native,sdr,sizeof(native)); + assert(dcp_edid_sdr(sdr,256)==256);assert(dcp_edid_sdr_native(native,256)==256); + for(unsigned i=0;i<256;i++)assert(native[i]==(i>=25&&i<35?0x55:i==127?native[127]:sdr[i])); + {u8 sum=0;for(unsigned j=0;j<128;j++)sum+=native[j];assert(!sum);} + for(unsigned n=0;n<128;n++)assert(!dcp_edid_sdr_native(native,n)); + assert(!dcp_edid_sdr_native(native,128)); /* A CTA with no data collection can still advertise basic stereo audio. */ memset(sdr,0,sizeof(sdr));memcpy(sdr,header,8);sdr[126]=1; cta=sdr+128;cta[0]=2;cta[1]=3;cta[3]=0x40;checksum(sdr);checksum(cta); assert(dcp_edid_sdr(sdr,256)==256);assert(sdr[126]==1 && cta[3]==0x40); - puts("PASS SDR EDID identity, audio, timing, colour removal, checksums, bounds and idempotence"); + puts("PASS SDR EDID identity, audio, timing, colour removal, native primaries, checksums, bounds and idempotence"); puts("PASS native26 AV identity, stale attachment/owner, bounded EDID length, extension count and checksum failures"); } ''' diff --git a/tools/testing/selftests/drivers/gpu/apple-dcp/rate.py b/tools/testing/selftests/drivers/gpu/apple-dcp/rate.py index 8c4267a2dc8f7..616b443e3a189 100644 --- a/tools/testing/selftests/drivers/gpu/apple-dcp/rate.py +++ b/tools/testing/selftests/drivers/gpu/apple-dcp/rate.py @@ -1072,8 +1072,10 @@ def publication(root): if 'dcp_edid_sdr(' in publication: # Keep extracting the real publication path, including its SDR helper. # Model only kernel allocation/DRM ownership at the host boundary. + # dcp_edid_sdr_native() is the M4 outputs', not this path's. sdr = '\n'.join(line for line in (base / 'dcp-sdr-edid.h').read_text().splitlines() - if not line.startswith('#include')) + if not line.startswith('#include')).replace( + 'static inline ', 'static inline __attribute__((unused)) ') publication = sdr + r""" static void *kmemdup(const void *data,size_t size,int gfp) { (void)gfp;void *copy=malloc(size);if(copy)memcpy(copy,data,size);return copy;