From cf76b173389bca5d1bc794a43513b25f012dd10c Mon Sep 17 00:00:00 2001 From: DjDeveloperr Date: Sun, 15 Nov 2026 18:52:24 -0500 Subject: [PATCH 1/2] drm/apple: give an external sink a firmware-derived EDID with what it reports An external display on a T6050 or T6041 external DCP, or on T8140's, gets its EDID from the firmware's DisplayAttributes: the driver builds a base block from the sink's identity, size, colour description and preferred timing. Every one of those had to be present and in range, or the sink got no EDID at all. A sink that reports no image size, a name longer than a descriptor holds, an alphanumeric serial number that is empty, too long or not printable, a model year (week 255), no colour description, or a preferred timing faster than a detailed timing descriptor can hold (655.35 MHz) was left without one, so compositors listed it with an empty description and could not tell it apart from another. Require only the identity, the manufacturer and product code, as a sink's own EDID does, and leave the rest undefined when the firmware does not report it: - no image size: both size bytes 0; - no or an invalid colour description: the sRGB primaries, D65 and gamma 2.2, the panel path's fallback; - a name longer than 13 characters is cut to 13, as for the panel; no name gives a text descriptor instead of a name; - an alphanumeric serial number the parser cannot take is left out; the numeric serial number stays; - no ManufacturerID: it is taken from LegacyManufacturerID, as for the panel; - a missing or invalid manufacture date: week 0 and year byte 0 (1990), as EDID has no unknown year; week 255 stays a model year; - no preferred timing that fits a detailed timing descriptor: a dummy descriptor, without the preferred timing feature bit. The descriptor names a timing only: a polarity the firmware leaves out is given as positive, as the mode list stays authoritative. The preferred timing is now picked among the timings a descriptor holds, so a sink whose preferred timing is above 655.35 MHz gets the best-scored timing that fits instead of no EDID. The EDID is published once the identity is current; a timing is no longer required for it. The log line names what the parser found missing or out of range. On a J714s, a 1920x1280 display behind a Thunderbolt dock reports an alphanumeric serial number the parser refuses. It had no EDID and was listed without a name; it now gets a 128-byte EDID and is listed as "JTG S123". A 3840x2160 display that reports everything keeps the EDID it had. Signed-off-by: Diljit Singh --- drivers/gpu/drm/apple/dcp-display-metadata.c | 83 ++++++++++++++---- drivers/gpu/drm/apple/dcp-display-metadata.h | 11 +++ drivers/gpu/drm/apple/dcp-internal.h | 3 +- drivers/gpu/drm/apple/dcp.c | 31 ++++--- drivers/gpu/drm/apple/iomfb.c | 13 ++- drivers/gpu/drm/apple/parser.c | 88 ++++++++++++++++++-- 6 files changed, 190 insertions(+), 39 deletions(-) diff --git a/drivers/gpu/drm/apple/dcp-display-metadata.c b/drivers/gpu/drm/apple/dcp-display-metadata.c index a84a2bd9abdda..bcc3f70d8db7a 100644 --- a/drivers/gpu/drm/apple/dcp-display-metadata.c +++ b/drivers/gpu/drm/apple/dcp-display-metadata.c @@ -215,49 +215,96 @@ static void dcp_panel_color(struct edid *edid, const struct dcp_display_metadata dcp_metadata_color(edid, &named); } -/* Build only a base block: the authoritative firmware mode list stays separate. */ +/* EDID 1.4 dummy descriptor: a placeholder for an unused 18-byte slot. */ +#define DCP_EDID_DETAIL_DUMMY 0x10 + +/* + * The descriptor only names the sink's preferred timing: a sync polarity the + * firmware does not report is given as positive, and the authoritative mode + * list stays separate. + */ +static void dcp_metadata_timing_polarity(struct drm_display_mode *mode) +{ + if (!(mode->flags & (DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NHSYNC))) + mode->flags |= DRM_MODE_FLAG_PHSYNC; + if (!(mode->flags & (DRM_MODE_FLAG_PVSYNC | DRM_MODE_FLAG_NVSYNC))) + mode->flags |= DRM_MODE_FLAG_PVSYNC; +} + +/* Whether @mode fits an EDID detailed timing. */ +bool dcp_metadata_timing_fits(const struct drm_display_mode *mode) +{ + const struct dcp_display_metadata none = {}; + struct detailed_timing timing; + struct drm_display_mode m = *mode; + + dcp_metadata_timing_polarity(&m); + return !dcp_metadata_timing(&timing, &m, &none); +} + +/* + * Build only a base block: the authoritative firmware mode list stays + * separate. What the sink leaves out stays undefined, as in its own EDID: no + * image size, the sRGB primaries, no manufacture week. Without a timing that + * fits a detailed timing descriptor, the first descriptor is a dummy one. + */ static int dcp_metadata_block(struct edid *edid, const struct dcp_display_metadata *metadata, const struct drm_display_mode *mode) { + bool sized = metadata->width_cm && metadata->width_cm <= 255 && + metadata->height_cm && metadata->height_cm <= 255; + bool dated = metadata->year >= 1990 && metadata->year <= 2245 && + (metadata->week <= 53 || metadata->week == 255); + struct dcp_display_metadata image = *metadata; u32 manufacturer = 0; u8 checksum = 0; int ret; - if (!metadata->width_cm || metadata->width_cm > 255 || - !metadata->height_cm || metadata->height_cm > 255 || - metadata->product > U16_MAX || metadata->week > 53 || - metadata->year < 1990 || metadata->year > 2245 || - metadata->gamma < 65536 || metadata->gamma > (354U << 16) / 100 || - strnlen(metadata->manufacturer, 4) != 3) + if (metadata->product > U16_MAX || strnlen(metadata->manufacturer, 4) != 3) return -EINVAL; for (unsigned int i = 0; i < 3; i++) { if (metadata->manufacturer[i] < 'A' || metadata->manufacturer[i] > 'Z') return -EINVAL; manufacturer = manufacturer << 5 | (metadata->manufacturer[i] - '@'); } + if (!sized) { + image.width_cm = 0; + image.height_cm = 0; + } memset(edid, 0, sizeof(*edid)); memcpy(edid->header, "\x00\xff\xff\xff\xff\xff\xff\x00", 8); edid->product_id.manufacturer_name = cpu_to_be16(manufacturer); edid->product_id.product_code = cpu_to_le16(metadata->product); edid->product_id.serial_number = cpu_to_le32(metadata->serial); - edid->product_id.week_of_manufacture = metadata->week; - edid->product_id.year_of_manufacture = metadata->year - 1990; + edid->product_id.week_of_manufacture = dated ? metadata->week : 0; + edid->product_id.year_of_manufacture = dated ? metadata->year - 1990 : 0; edid->version = 1; edid->revision = 4; /* No claim about connector interface, bit depth, HDR, audio or VRR. */ edid->input = DRM_EDID_INPUT_DIGITAL; - edid->width_cm = metadata->width_cm; - edid->height_cm = metadata->height_cm; - ret = dcp_metadata_color(edid, metadata); - if (ret) - return ret; + edid->width_cm = image.width_cm; + edid->height_cm = image.height_cm; + dcp_panel_color(edid, metadata, dcp_color_space_lookup("srgb")); edid->features = DRM_EDID_FEATURE_PREFERRED_TIMING | DRM_EDID_FEATURE_RGB; memset(edid->standard_timings, 1, sizeof(edid->standard_timings)); - ret = dcp_metadata_timing(&edid->detailed_timings[0], mode, metadata); - if (!ret) - ret = dcp_metadata_text(&edid->detailed_timings[1], EDID_DETAIL_MONITOR_NAME, - metadata->name); + ret = -EINVAL; + if (mode) { + struct drm_display_mode m = *mode; + + dcp_metadata_timing_polarity(&m); + ret = dcp_metadata_timing(&edid->detailed_timings[0], &m, &image); + } + if (ret) { + memset(&edid->detailed_timings[0], 0, sizeof(edid->detailed_timings[0])); + edid->detailed_timings[0].data.other_data.type = DCP_EDID_DETAIL_DUMMY; + edid->features &= ~DRM_EDID_FEATURE_PREFERRED_TIMING; + } + ret = metadata->name[0] ? + dcp_metadata_text(&edid->detailed_timings[1], EDID_DETAIL_MONITOR_NAME, + metadata->name) : + dcp_metadata_text(&edid->detailed_timings[1], EDID_DETAIL_MONITOR_STRING, + "DCP display"); if (!ret) ret = dcp_metadata_text(&edid->detailed_timings[2], EDID_DETAIL_MONITOR_STRING, "DCP metadata"); diff --git a/drivers/gpu/drm/apple/dcp-display-metadata.h b/drivers/gpu/drm/apple/dcp-display-metadata.h index 66c28c1bc7004..20ba07d691fe7 100644 --- a/drivers/gpu/drm/apple/dcp-display-metadata.h +++ b/drivers/gpu/drm/apple/dcp-display-metadata.h @@ -2,6 +2,7 @@ #ifndef APPLE_DCP_DISPLAY_METADATA_H #define APPLE_DCP_DISPLAY_METADATA_H +#include #include /* Values reported by DisplayAttributes, not a copy of the sink's EDID. */ @@ -17,8 +18,17 @@ struct dcp_display_metadata { /* Optional HDR capability: false and zero when not reported */ bool pq, static_metadata_type1, bt2020_rgb; u32 max_luminance, max_fall, min_luminance; /* 16.16 cd/m2 */ + /* DCP_METADATA_DEFAULT_*: what the sink left out, so the EDID leaves undefined */ + u32 defaults; }; +#define DCP_METADATA_DEFAULT_SIZE BIT(0) +#define DCP_METADATA_DEFAULT_COLOR BIT(1) +#define DCP_METADATA_DEFAULT_NAME BIT(2) +#define DCP_METADATA_DEFAULT_DATE BIT(3) +#define DCP_METADATA_DEFAULT_SERIAL BIT(4) +#define DCP_METADATA_DEFAULT_TIMING BIT(5) + /* Calibrated target named by the boot-populated raw ADT. */ enum dcp_panel_gamut { DCP_PANEL_GAMUT_UNSPECIFIED, @@ -46,6 +56,7 @@ struct drm_display_mode; struct dcp_display_mode; const struct drm_edid *dcp_metadata_edid(const struct dcp_display_metadata *metadata, const struct drm_display_mode *mode); +bool dcp_metadata_timing_fits(const struct drm_display_mode *mode); const struct drm_edid *dcp_panel_edid(const struct dcp_display_metadata *metadata, const struct dcp_color_space *target, diff --git a/drivers/gpu/drm/apple/dcp-internal.h b/drivers/gpu/drm/apple/dcp-internal.h index 2eb5eb53fb8c6..97b0db066bb93 100644 --- a/drivers/gpu/drm/apple/dcp-internal.h +++ b/drivers/gpu/drm/apple/dcp-internal.h @@ -1106,7 +1106,8 @@ void dcp_firmware_metadata_attributes(struct apple_dcp *dcp, const struct dcp_display_metadata *attributes); void dcp_firmware_metadata_timing(struct apple_dcp *dcp); bool dcp_firmware_metadata_current(struct apple_dcp *dcp, u64 generation); -const struct drm_edid *dcp_firmware_edid(struct apple_dcp *dcp, u64 *generation); +const struct drm_edid *dcp_firmware_edid(struct apple_dcp *dcp, u64 *generation, + u32 *defaults); void iomfb_scanout_complete_h17p(struct apple_dcp *dcp); void iomfb_present_backlight_h17p(struct apple_dcp *dcp); diff --git a/drivers/gpu/drm/apple/dcp.c b/drivers/gpu/drm/apple/dcp.c index b4d1cba2dffc6..57ebc6df61eea 100644 --- a/drivers/gpu/drm/apple/dcp.c +++ b/drivers/gpu/drm/apple/dcp.c @@ -1039,10 +1039,10 @@ static void dcp_firmware_metadata_notify(struct apple_dcp *dcp) unsigned long flags; bool ready; + /* The sink's identity is enough: a timing that fits a descriptor is optional. */ spin_lock_irqsave(&dcp->metadata.lock, flags); - ready = dcp->metadata.attributes_valid && dcp->metadata.timing_valid && - dcp_metadata_matches(&dcp->metadata.epoch, dcp->metadata.attributes_ticket) && - dcp_metadata_matches(&dcp->metadata.epoch, dcp->metadata.timing_ticket); + ready = dcp->metadata.attributes_valid && + dcp_metadata_matches(&dcp->metadata.epoch, dcp->metadata.attributes_ticket); spin_unlock_irqrestore(&dcp->metadata.lock, flags); if (ready && dcp->connector && READ_ONCE(dcp->connector->connected)) schedule_work(&dcp->connector->hotplug_wq); @@ -1094,9 +1094,14 @@ void dcp_firmware_metadata_timing(struct apple_dcp *dcp) */ for (i = 0; i < dcp->nr_modes; i++) { const struct dcp_display_mode *m = &dcp->modes[i]; + struct drm_display_mode timing = m->mode; if (!m->metadata_timing_valid) continue; + /* A descriptor holds at most 655.35 MHz: faster modes are left to the list. */ + timing.flags |= m->metadata_sync_flags; + if (!dcp_metadata_timing_fits(&timing)) + continue; if (best == UINT_MAX || (m->mode.type & DRM_MODE_TYPE_PREFERRED) || (!(dcp->modes[best].mode.type & DRM_MODE_TYPE_PREFERRED) && m->score > dcp->modes[best].score)) @@ -1128,29 +1133,35 @@ bool dcp_firmware_metadata_current(struct apple_dcp *dcp, u64 generation) return valid; } -const struct drm_edid *dcp_firmware_edid(struct apple_dcp *dcp, u64 *generation) +const struct drm_edid *dcp_firmware_edid(struct apple_dcp *dcp, u64 *generation, + u32 *defaults) { struct dcp_display_metadata attributes; struct drm_display_mode preferred; const struct drm_edid *edid; unsigned long flags; - bool valid; + bool valid, timing = false; if (!dcp_firmware_metadata_enabled(dcp)) return ERR_PTR(-ENODEV); spin_lock_irqsave(&dcp->metadata.lock, flags); - valid = dcp->metadata.attributes_valid && dcp->metadata.timing_valid && - dcp_metadata_matches(&dcp->metadata.epoch, dcp->metadata.attributes_ticket) && - dcp_metadata_matches(&dcp->metadata.epoch, dcp->metadata.timing_ticket); + valid = dcp->metadata.attributes_valid && + dcp_metadata_matches(&dcp->metadata.epoch, dcp->metadata.attributes_ticket); if (valid) { attributes = dcp->metadata.attributes; - preferred = dcp->metadata.preferred; + timing = dcp->metadata.timing_valid && + dcp_metadata_matches(&dcp->metadata.epoch, dcp->metadata.timing_ticket); + if (timing) + preferred = dcp->metadata.preferred; *generation = dcp->metadata.epoch.generation; } spin_unlock_irqrestore(&dcp->metadata.lock, flags); if (!valid) return ERR_PTR(-ENODATA); - edid = dcp_metadata_edid(&attributes, &preferred); + if (!timing) + attributes.defaults |= DCP_METADATA_DEFAULT_TIMING; + *defaults = attributes.defaults; + edid = dcp_metadata_edid(&attributes, timing ? &preferred : NULL); spin_lock_irqsave(&dcp->metadata.lock, flags); valid = !dcp->metadata.epoch.invalidated && dcp->metadata.epoch.connected && *generation == dcp->metadata.epoch.generation; diff --git a/drivers/gpu/drm/apple/iomfb.c b/drivers/gpu/drm/apple/iomfb.c index 8714adf0b7e1f..3b41359bba82e 100644 --- a/drivers/gpu/drm/apple/iomfb.c +++ b/drivers/gpu/drm/apple/iomfb.c @@ -2787,10 +2787,11 @@ int dcp_get_modes(struct drm_connector *connector) } } else { u64 generation = 0; + u32 defaults = 0; bool panel = dcp->panel_identity && dcp_has_panel(dcp); const struct drm_edid *derived = nr_modes ? (panel ? dcp_panel_edid_snapshot(dcp, modes, nr_modes, &generation) : - dcp_firmware_edid(dcp, &generation)) : ERR_PTR(-ENODATA); + dcp_firmware_edid(dcp, &generation, &defaults)) : ERR_PTR(-ENODATA); if (!IS_ERR(derived)) { bool log = !apple_connector->drm_edid_firmware_derived || @@ -2808,8 +2809,14 @@ int dcp_get_modes(struct drm_connector *connector) drm_edid_connector_update(connector, NULL); apple_connector->drm_edid_firmware_derived = false; } else if (log) { - dev_info(dcp->dev, "using firmware-derived EDID metadata for connection %llu\n", - generation); + dev_info(dcp->dev, "using firmware-derived EDID metadata for connection %llu%s%s%s%s%s%s%s\n", + generation, defaults ? "; not reported:" : "", + defaults & DCP_METADATA_DEFAULT_SIZE ? " size" : "", + defaults & DCP_METADATA_DEFAULT_COLOR ? " colour" : "", + defaults & DCP_METADATA_DEFAULT_NAME ? " name" : "", + defaults & DCP_METADATA_DEFAULT_SERIAL ? " serial" : "", + defaults & DCP_METADATA_DEFAULT_DATE ? " date" : "", + defaults & DCP_METADATA_DEFAULT_TIMING ? " timing" : ""); } } else { if (panel && nr_modes) diff --git a/drivers/gpu/drm/apple/parser.c b/drivers/gpu/drm/apple/parser.c index 905789f495cd5..8538b0cb5aa0e 100644 --- a/drivers/gpu/drm/apple/parser.c +++ b/drivers/gpu/drm/apple/parser.c @@ -1569,6 +1569,21 @@ static int parse_panel_label(struct dcp_parse_ctx *handle, char out[14]) return 0; } +/* + * An optional value an EDID can do without: on any error the value is skipped, + * the caller's default stays, and the field is noted in @defaults. + */ +static int parse_metadata_optional(struct dcp_parse_ctx *handle, + const struct dcp_parse_ctx *at, int ret, + u32 *defaults, u32 field) +{ + if (!ret) + return 0; + *handle = *at; + *defaults |= field; + return skip(handle); +} + static int parse_metadata_product(struct dcp_parse_ctx *handle, struct dcp_display_metadata *out, bool panel) { @@ -1580,11 +1595,13 @@ static int parse_metadata_product(struct dcp_parse_ctx *handle, if (ret) return ret; for (; it.idx < it.len; it.idx++) { + struct dcp_parse_ctx at; char key[64]; ret = parse_metadata_string(handle, key, sizeof(key)); if (ret) return ret; + at = *handle; if (!strcmp(key, "ManufacturerID")) { if (seen & 1) return -EINVAL; @@ -1595,8 +1612,11 @@ static int parse_metadata_product(struct dcp_parse_ctx *handle, if (seen & 2) return -EINVAL; seen |= 2; - ret = panel ? parse_panel_label(handle, out->name) : - parse_metadata_string(handle, out->name, sizeof(out->name)); + /* Longer than a descriptor holds: keep its first 13 characters. */ + ret = parse_panel_label(handle, out->name); + if (!panel) + ret = parse_metadata_optional(handle, &at, ret, &out->defaults, + DCP_METADATA_DEFAULT_NAME); } else if (!strcmp(key, "ProductID")) { if (seen & 4) return -EINVAL; @@ -1606,14 +1626,23 @@ static int parse_metadata_product(struct dcp_parse_ctx *handle, if (seen & 8) return -EINVAL; seen |= 8; + /* 255: the year is a model year (EDID 1.4). */ ret = panel ? skip(handle) : - parse_metadata_number(handle, &out->week, 0, 53); + parse_metadata_number(handle, &out->week, 0, 255); + if (!panel && !ret && out->week > 53 && out->week != 255) + ret = -EINVAL; + if (!panel) + ret = parse_metadata_optional(handle, &at, ret, &out->defaults, + DCP_METADATA_DEFAULT_DATE); } else if (!strcmp(key, "YearOfManufacture")) { if (seen & 16) return -EINVAL; seen |= 16; ret = panel ? skip(handle) : parse_metadata_number(handle, &out->year, 1990, 2245); + if (!panel) + ret = parse_metadata_optional(handle, &at, ret, &out->defaults, + DCP_METADATA_DEFAULT_DATE); } else if (!strcmp(key, "SerialNumber")) { if (seen & 64) return -EINVAL; @@ -1626,6 +1655,9 @@ static int parse_metadata_product(struct dcp_parse_ctx *handle, ret = panel ? parse_panel_label(handle, out->serial_text) : parse_metadata_string(handle, out->serial_text, sizeof(out->serial_text)); + if (!panel) + ret = parse_metadata_optional(handle, &at, ret, &out->defaults, + DCP_METADATA_DEFAULT_SERIAL); } else if (!strcmp(key, "LegacyManufacturerID")) { if (seen & 32) return -EINVAL; @@ -1637,14 +1669,26 @@ static int parse_metadata_product(struct dcp_parse_ctx *handle, if (ret) return ret; } - if (panel && !(seen & 1) && (seen & 32)) { + if (!(seen & 1) && (seen & 32)) { for (unsigned int i = 0; i < 3; i++) out->manufacturer[i] = '@' + ((legacy >> (10 - 5 * i)) & 31); seen |= 1; } - if ((seen & (panel ? 5 : 31)) != (panel ? 5 : 31) || - strlen(out->manufacturer) != 3) + /* + * The identity is the manufacturer and product code. A sink's name, + * serial and date are optional, as in its own EDID. + */ + if ((seen & 5) != 5 || strlen(out->manufacturer) != 3) return -EINVAL; + if (!panel) { + if (!(seen & 2) || !out->name[0]) + out->defaults |= DCP_METADATA_DEFAULT_NAME; + if ((seen & 24) != 24 || (out->defaults & DCP_METADATA_DEFAULT_DATE)) { + out->week = 0; + out->year = 0; + out->defaults |= DCP_METADATA_DEFAULT_DATE; + } + } for (unsigned int i = 0; i < 3; i++) if (out->manufacturer[i] < 'A' || out->manufacturer[i] > 'Z') return -EINVAL; @@ -1714,6 +1758,12 @@ static int parse_metadata_capability(struct dcp_parse_ctx *handle, bool *out) return skip(handle); } +/* + * A sink's DisplayAttributes. Only its identity (ProductAttributes) is + * required: a missing or out-of-range size or colour description is noted in + * defaults and left to the EDID's own defaults, as a sink's EDID may leave + * them undefined too. + */ int parse_display_metadata(struct dcp_parse_ctx *handle, struct dcp_display_metadata *out) { struct dcp_display_metadata parsed = {}; @@ -1724,31 +1774,41 @@ int parse_display_metadata(struct dcp_parse_ctx *handle, struct dcp_display_meta if (ret) return ret; for (; it.idx < it.len; it.idx++) { + struct dcp_parse_ctx at; char key[64]; ret = parse_metadata_string(handle, key, sizeof(key)); if (ret) return ret; + at = *handle; if (!strcmp(key, "MaxHorizontalImageSize")) { if (seen & 1) return -EINVAL; seen |= 1; ret = parse_metadata_number(handle, &parsed.width_cm, 1, 255); + ret = parse_metadata_optional(handle, &at, ret, &parsed.defaults, + DCP_METADATA_DEFAULT_SIZE); } else if (!strcmp(key, "MaxVerticalImageSize")) { if (seen & 2) return -EINVAL; seen |= 2; ret = parse_metadata_number(handle, &parsed.height_cm, 1, 255); + ret = parse_metadata_optional(handle, &at, ret, &parsed.defaults, + DCP_METADATA_DEFAULT_SIZE); } else if (!strcmp(key, "Chromaticity")) { if (seen & 4) return -EINVAL; seen |= 4; ret = parse_metadata_chromaticity(handle, &parsed); + ret = parse_metadata_optional(handle, &at, ret, &parsed.defaults, + DCP_METADATA_DEFAULT_COLOR); } else if (!strcmp(key, "DefaultWhitePoint")) { if (seen & 8) return -EINVAL; seen |= 8; ret = parse_metadata_point(handle, parsed.white, &parsed.gamma, false); + ret = parse_metadata_optional(handle, &at, ret, &parsed.defaults, + DCP_METADATA_DEFAULT_COLOR); } else if (!strcmp(key, "ProductAttributes")) { if (seen & 16) return -EINVAL; @@ -1768,8 +1828,22 @@ int parse_display_metadata(struct dcp_parse_ctx *handle, struct dcp_display_meta if (ret) return ret; } - if (seen != 31) + if (!(seen & 16)) return -EINVAL; + /* An image size is both dimensions or none. */ + if ((seen & 3) != 3 || !parsed.width_cm || !parsed.height_cm || + (parsed.defaults & DCP_METADATA_DEFAULT_SIZE)) { + parsed.width_cm = 0; + parsed.height_cm = 0; + parsed.defaults |= DCP_METADATA_DEFAULT_SIZE; + } + /* Primaries and white point are one description: both or neither. */ + if ((seen & 12) != 12 || (parsed.defaults & DCP_METADATA_DEFAULT_COLOR)) { + memset(parsed.chromaticity, 0, sizeof(parsed.chromaticity)); + memset(parsed.white, 0, sizeof(parsed.white)); + parsed.gamma = 0; + parsed.defaults |= DCP_METADATA_DEFAULT_COLOR; + } *out = parsed; return 0; } From 1c0c9dd640a3aaa5d8ec9baaee16cc7ef1cecded Mon Sep 17 00:00:00 2001 From: DjDeveloperr Date: Sun, 15 Nov 2026 20:59:49 -0500 Subject: [PATCH 2/2] tools: apple-dcp: follow the external EDID's optional sink values The previous commit makes an external sink's DisplayAttributes need only its identity. A size, colour description, date, name or serial number the firmware leaves out or reports out of range is noted in the metadata's defaults (DCP_METADATA_DEFAULT_*) and left undefined, and the EDID builder writes a dummy first descriptor when no detailed timing holds the preferred mode. The host units that compile parser.c and the EDID builder still modelled the old rules, so they no longer built or held: - The parser fixture takes the DCP_METADATA_DEFAULT_* values from dcp-display-metadata.h with the metadata struct. - The publication fixture's dcp_firmware_edid() stub takes the defaults argument, and dcp_metadata_timing_fits() is stubbed with the detailed timing's clock limit (655.35 MHz in 10 kHz steps). - metadata-decoder: a missing sync polarity now gives a positive one, and a mode no descriptor holds gives a dummy descriptor and no preferred timing, instead of no EDID. Its malformed inputs are split: a bad identity or a duplicated key is still refused with the output untouched; a bad or missing size, colour description or date parses with that default noted, its fields zero, and still builds an EDID; a name over 13 characters is cut to 13. No production code changes. Signed-off-by: Diljit Singh --- .../selftests/drivers/gpu/apple-dcp/rate.py | 106 ++++++++++++++---- 1 file changed, 85 insertions(+), 21 deletions(-) diff --git a/tools/testing/selftests/drivers/gpu/apple-dcp/rate.py b/tools/testing/selftests/drivers/gpu/apple-dcp/rate.py index 4985476ad19e6..5d4f8c6abab76 100644 --- a/tools/testing/selftests/drivers/gpu/apple-dcp/rate.py +++ b/tools/testing/selftests/drivers/gpu/apple-dcp/rate.py @@ -45,9 +45,13 @@ def wire(value, out): source = (base / 'parser.c').read_text() parser = source[source.index('#define DCP_PARSE_HEADER'):source.index('int parse_epic_service_init(')] metadata = (base / 'dcp-display-metadata.h').read_text() + # What a sink left out (DCP_METADATA_DEFAULT_*), as the parser notes it. + defaults = ''.join(re.sub(r'\bBIT\((\d+)\)', r'(1U << \1)', d) + '\n' + for d in source_defines(metadata) if d.startswith('#define DCP_METADATA_DEFAULT_')) metadata = (block(metadata, 'struct dcp_display_metadata {') + ';\n' + block(metadata, 'enum dcp_panel_gamut {') + ';\n' + - block(metadata, 'struct dcp_color_space {') + ';\n') + block(metadata, 'struct dcp_color_space {') + ';\n' + + defaults) header = (base / 'parser.h').read_text() header = header[header.index('struct apple_dcp;'):header.index('int parse(')] refresh = (base / 'dcp-refresh.h').read_text().replace('#include ', '') @@ -363,6 +367,23 @@ def timing(i, w, h, hz, pref, score, unsafe=False): memset(&metadata, 0xa5, sizeof(metadata)); unchanged = metadata; assert(!parse(data, length, &ctx)); int ret = parse_display_metadata(&ctx, &metadata); + if (argv[2][0] == 'd' || argv[2][0] == 't') { + /* Left out or out of range: noted and left undefined; the EDID is still built. */ + unsigned long want = argv[2][0] == 'd' ? strtoul(argv[2] + 1, NULL, 0) : 0; + assert(!ret && (metadata.defaults & want) == want && (want || !metadata.defaults)); + if (want & DCP_METADATA_DEFAULT_SIZE) + assert(!metadata.width_cm && !metadata.height_cm); + if (want & DCP_METADATA_DEFAULT_COLOR) + assert(!metadata.gamma && !metadata.white[0] && !metadata.chromaticity[0][0]); + if (want & DCP_METADATA_DEFAULT_DATE) + assert(!metadata.week && !metadata.year); + if (argv[2][0] == 't') + assert(strlen(metadata.name) == 13); + const struct drm_edid *e = dcp_metadata_edid(&metadata, NULL); + assert(!IS_ERR(e)); + drm_edid_free(e); + free(data); return 0; + } if (atoi(argv[2])) { assert(ret == -EINVAL && !memcmp(&metadata, &unchanged, sizeof(metadata))); free(data); return 0; @@ -424,11 +445,27 @@ def timing(i, w, h, hz, pref, score, unsafe=False): assert(!memcmp(edid->cta, "\x02\x03\x08\x00\xe3\x06\x05\x01", 8)); drm_edid_free(edid); } + /* A sync polarity the firmware leaves out is given as positive. */ mode.flags = 0; - assert(IS_ERR(dcp_metadata_edid(&metadata, &mode))); + edid = dcp_metadata_edid(&metadata, &mode); + assert(!IS_ERR(edid)); + { + const u8 *r = (const u8 *)&edid->raw; + assert((r[24] & DRM_EDID_FEATURE_PREFERRED_TIMING) && (r[54] | r[55])); + assert((r[71] & (DRM_EDID_PT_HSYNC_POSITIVE | DRM_EDID_PT_VSYNC_POSITIVE)) == + (DRM_EDID_PT_HSYNC_POSITIVE | DRM_EDID_PT_VSYNC_POSITIVE)); + } + drm_edid_free(edid); + /* No detailed timing holds the mode: a dummy descriptor, no preferred timing. */ mode.flags = DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC; mode.clock++; - assert(IS_ERR(dcp_metadata_edid(&metadata, &mode))); + edid = dcp_metadata_edid(&metadata, &mode); + assert(!IS_ERR(edid)); + { + const u8 *r = (const u8 *)&edid->raw; + assert(!(r[24] & DRM_EDID_FEATURE_PREFERRED_TIMING) && !r[54] && !r[55] && r[57] == 0x10); + } + drm_edid_free(edid); free(data); if (argc == 5) { f=fopen(argv[4],"rb"); assert(f && !fseek(f,0,SEEK_END)); @@ -744,6 +781,16 @@ def publication(root): start = state.index('static bool dcpavserv_edid_current(') state = state[:start] + dcp_c = (base/'dcp.c').read_text() + # The firmware-derived EDID reports what the sink left out, once the tree has it. + defaults_arg = re.search(r'dcp_firmware_edid\(\s*dcp,\s*&generation,\s*&defaults\s*\)', dcp_c + iomfb) + firmware_edid = ('static const struct drm_edid *dcp_firmware_edid(struct apple_dcp *d,u64 *generation' + + (',u32 *defaults) { (void)defaults; ' if defaults_arg else ') { ') + + '(void)d; (void)generation; return ERR_PTR(-ENODATA); }\n') + if 'dcp_metadata_timing_fits(' in dcp_c: + # A detailed timing descriptor holds a pixel clock of at most 655.35 MHz. + firmware_edid += ('static bool dcp_metadata_timing_fits(const struct drm_display_mode *m) ' + '{ return m->clock > 0 && m->clock <= 655350 && !(m->clock % 10); }\n') stubs = r''' /* The rate/HPD fixture is an external H17P sink; it never selects M4. */ #define iomfb_is_v26_6(dcp) false @@ -805,7 +852,7 @@ def publication(root): static int drm_edid_connector_update(struct drm_connector *c,const struct drm_edid *e) { assert(c->dev->mode_config.mutex); (void)e; return fail_update?-EIO:0; } -static const struct drm_edid *dcp_firmware_edid(struct apple_dcp *d,u64 *generation) { (void)d; (void)generation; return ERR_PTR(-ENODATA); } +DCP_FIRMWARE_EDID_STUB static bool dcp_firmware_metadata_current(struct apple_dcp *d,u64 generation) { (void)d; (void)generation; return false; } static const struct drm_edid *dcp_panel_edid_snapshot(struct apple_dcp *d,const struct dcp_display_mode *m,unsigned n,u64 *generation) { (void)d;(void)m;(void)n;(void)generation;assert(!"panel identity in external fixture");return ERR_PTR(-ENODATA); } static bool dcp_panel_metadata_current(struct apple_dcp *d,u64 generation) { (void)d;(void)generation;assert(!"panel identity in external fixture");return false; } @@ -1013,6 +1060,7 @@ def publication(root): puts("PASS: 24 callback/timing/AV arrival permutations and real get_modes/lookup publication; early configuration needs no second callback; CLOSE, physical reconnect, receipt epochs and publication races deny stale proof"); } ''' + stubs=stubs.replace('DCP_FIRMWARE_EDID_STUB\n',firmware_edid) unit=n['prefix']+n['metadata']+n['epoch']+n['header']+n['edid_header']+n['parser']+n['blobs']+n['policy']+n['proof']+state+stubs+transport+n['source']+n['callback_types']+n['callback_stubs']+n['callback']+n['connection']+publication+receipt+helpers+fixture+'int main(int argc,char **argv) {'+main_prefix+main # Conflicts are scanned across the full binary receipt, including filtered # siblings. Exercise both orders, replacement receipts and equivalent aliases. @@ -1325,39 +1373,55 @@ def hotplug(root): def metadata(root, output): - """Keep malformed/duplicate metadata cases with synthetic bounded wire input.""" + """Keep malformed/duplicate metadata cases with synthetic bounded wire input. + + Only a sink's identity (manufacturer and product code, once each) is + required. A size, colour description or date out of range or missing is + noted in the metadata's defaults (DCP_METADATA_DEFAULT_*), left undefined, + and the sink still gets an EDID; a name longer than a descriptor is cut. + """ n = parser_fixture(root) fixture = n['fixture'] - cases = [(fixture, False)] - for path, value in [ - (('MaxHorizontalImageSize',), 256), (('MaxVerticalImageSize',), '33'), - (('Chromaticity', 'Red', 'X'), True), (('Chromaticity', 'Blue', 'Y'), 65536), - (('DefaultWhitePoint', 'Y'), 64000), (('DefaultWhitePoint', 'Gamma'), 65535), - (('DefaultWhitePoint', 'Gamma'), 240000), (('ProductAttributes', 'ManufacturerID'), 'AC'), - (('ProductAttributes', 'ManufacturerID'), 'A\0R'), (('ProductAttributes', 'LegacyManufacturerID'), 1), - (('ProductAttributes', 'ProductName'), 'x' * 14), (('ProductAttributes', 'ProductID'), 65536), - (('ProductAttributes', 'YearOfManufacture'), 1989), (('ProductAttributes', 'WeekOfManufacture'), 54), + header = (root / 'drivers/gpu/drm/apple/dcp-display-metadata.h').read_text() + bits = {m.group(1): 1 << int(m.group(2)) for m in + re.finditer(r'^#define DCP_METADATA_DEFAULT_(\w+)\s+BIT\((\d+)\)', header, re.M)} + # Expectations: '1' refused and the output untouched, 'd' parsed with + # those defaults noted, 't' parsed with the name cut to 13 characters. + reject = '1' + size, color, date = (f"d{bits[k]}" for k in ('SIZE', 'COLOR', 'DATE')) + cases = [(fixture, '0')] + for path, value, expect in [ + (('MaxHorizontalImageSize',), 256, size), (('MaxVerticalImageSize',), '33', size), + (('Chromaticity', 'Red', 'X'), True, color), (('Chromaticity', 'Blue', 'Y'), 65536, color), + (('DefaultWhitePoint', 'Y'), 64000, color), (('DefaultWhitePoint', 'Gamma'), 65535, color), + (('DefaultWhitePoint', 'Gamma'), 240000, color), (('ProductAttributes', 'ManufacturerID'), 'AC', reject), + (('ProductAttributes', 'ManufacturerID'), 'A\0R', reject), + (('ProductAttributes', 'LegacyManufacturerID'), 1, reject), + (('ProductAttributes', 'ProductName'), 'x' * 14, 't'), (('ProductAttributes', 'ProductID'), 65536, reject), + (('ProductAttributes', 'YearOfManufacture'), 1989, date), + (('ProductAttributes', 'WeekOfManufacture'), 54, date), ]: bad = copy.deepcopy(fixture) target = bad for key in path[:-1]: target = target[key] target[path[-1]] = value - cases.append((bad, True)) - for key in ('Chromaticity', 'DefaultWhitePoint', 'ProductAttributes'): + cases.append((bad, expect)) + # Missing: a colour description may be, the identity may not. Twice: never. + for key, missing in (('Chromaticity', color), ('DefaultWhitePoint', color), ('ProductAttributes', reject)): bad = copy.deepcopy(fixture) del bad[key] - cases.append((bad, True)) + cases.append((bad, missing)) second = copy.deepcopy(fixture[key]) - cases.append((n['ObjectPairs'](list(fixture.items()) + [(key, second)]), True)) - for path, field in [(('Chromaticity', 'Red'), 'X'), (('ProductAttributes',), 'ProductName')]: + cases.append((n['ObjectPairs'](list(fixture.items()) + [(key, second)]), reject)) + for path, field, expect in [(('Chromaticity', 'Red'), 'X', color), (('ProductAttributes',), 'ProductName', reject)]: bad = copy.deepcopy(fixture) target = bad for key in path[:-1]: target = target[key] value = target[path[-1]] target[path[-1]] = n['ObjectPairs'](list(value.items()) + [(field, value[field])]) - cases.append((bad, True)) + cases.append((bad, expect)) inputs = output / 'metadata-inputs' inputs.mkdir(parents=True, exist_ok=True) arguments = [] @@ -1366,7 +1430,7 @@ def metadata(root, output): n['wire'](value, data) path = inputs / str(index) path.write_bytes(data) - arguments.append((str(path), str(int(bad)), str(inputs / 'edid'))) + arguments.append((str(path), bad, str(inputs / 'edid'))) unit = ''.join(n[k] for k in ('prefix', 'metadata', 'epoch', 'header', 'edid_header', 'stubs', 'parser', 'builder', 'timing_source', 'proof_test', 'suffix')) return unit, tuple(arguments)