From 075a7bc56ef6325088230065157d66d2d040d5ca Mon Sep 17 00:00:00 2001 From: Ryan <81541646+RyanTheTide@users.noreply.github.com> Date: Fri, 13 Nov 2026 21:21:42 +1100 Subject: [PATCH 1/2] drm/apple: T8140: run the macOS 27.2 DCP firmware as firmware 27 T8140's DCP is pinned to the H17P interface by its match data, so a J700 booted from a 27.x stub would have its DCP firmware driven with the 26.x interface. On T8142 that makes the 27.0 firmware panic after the first hotplug, and T8142 was moved to the T6050's firmware-27 instance (121d6e978265, "drm/apple: T8142: run the macOS 27.0 DCP firmware as firmware 27"). Do the same for T8140 on 27.2, the one 27.x build it is going to run: - firmware-compat 27.2.0 selects DCP_FIRMWARE_V_27_0 with the existing 27.2 method table, checked for completeness as on T6050; - the internal DCP takes the default method profile, as T8142 does; - any other 27.x or later build on T8140 is refused instead of being driven through H17P. 26.x selection is unchanged. The table check moves into dcp_check_firmware_27() so both callers share it. The T8140 external DCP still admits only 26.6.2 firmware, so on 27.2 it stays off and the internal panel is unaffected. A host selftest covers the selection for T8140, T8142 and T6050. Assisted-by: LLM Signed-off-by: Ryan Murray --- drivers/gpu/drm/apple/dcp.c | 65 ++++++++--- .../selftests/drivers/gpu/apple-dcp/boot.py | 101 ++++++++++++++++++ .../selftests/drivers/gpu/apple-dcp/run.py | 1 + 3 files changed, 150 insertions(+), 17 deletions(-) diff --git a/drivers/gpu/drm/apple/dcp.c b/drivers/gpu/drm/apple/dcp.c index e819a3565b5f3..c878d829bc113 100644 --- a/drivers/gpu/drm/apple/dcp.c +++ b/drivers/gpu/drm/apple/dcp.c @@ -5269,14 +5269,37 @@ static int dcp_read_fw_version(struct device *dev, const char *name, return len; } +/* Firmware 27: start it only with a complete method table for its build. */ +static enum dcp_firmware_version dcp_check_firmware_27(struct device *dev) +{ + char compat_str[DCP_FW_VERSION_STR_LEN]; + const struct dcp_method_entry *methods; + unsigned int num_missing; + const char *missing; + int ret; + + ret = dcp_read_fw_version(dev, "apple,firmware-compat", compat_str); + methods = ret < 0 ? NULL : iomfb_v27_methods(compat_str); + if (!methods) { + dev_err(dev, "DCP firmware-compat %s has no 27.x method table\n", + ret < 0 ? "missing" : compat_str); + return DCP_FIRMWARE_UNKNOWN; + } + missing = iomfb_v27_missing_method(methods, &num_missing); + if (missing) { + dev_err(dev, "DCP firmware-compat %s not started: no ID known for %u methods (first: %s)\n", + compat_str, num_missing, missing); + return DCP_FIRMWARE_UNKNOWN; + } + return DCP_FIRMWARE_V_27_0; +} + static enum dcp_firmware_version dcp_check_firmware_version(struct device *dev) { const struct apple_dcp_hw_data *hw = of_device_get_match_data(dev); const struct dcp_v14_board *v14_board; char compat_str[DCP_FW_VERSION_STR_LEN]; char fw_str[DCP_FW_VERSION_STR_LEN]; - unsigned int num_missing; - const char *missing; int ret; /* @@ -5291,23 +5314,29 @@ static enum dcp_firmware_version dcp_check_firmware_version(struct device *dev) return DCP_FIRMWARE_V_27_0; } - if (hw->firmware_compat == DCP_FIRMWARE_V_27_0) { + /* + * T8140 (J700) runs H17P firmware up to 26.6.2. Its 27.2 DCP firmware + * is driven as firmware 27, like T8142 on 27.0. Any other 27.x build + * is not started: the H17P interface is not used on firmware 27. + */ + if (of_device_is_compatible(dev->of_node, "apple,t8140-dcp")) { + u32 major; + ret = dcp_read_fw_version(dev, "apple,firmware-compat", compat_str); - if (ret < 0 || !iomfb_v27_methods(compat_str)) { - dev_err(dev, "DCP firmware-compat %s has no 27.x method table\n", - ret < 0 ? "missing" : compat_str); + if (ret >= 0 && !strcmp(compat_str, "27.2.0")) + return dcp_check_firmware_27(dev); + if (ret >= 0 && + !of_property_read_u32_index(dev->of_node, "apple,firmware-compat", + 0, &major) && major >= 27) { + dev_err(dev, "T8140 display not started: DCP firmware-compat %s is not 27.2.0\n", + compat_str); return DCP_FIRMWARE_UNKNOWN; } - missing = iomfb_v27_missing_method(iomfb_v27_methods(compat_str), - &num_missing); - if (missing) { - dev_err(dev, "DCP firmware-compat %s not started: no ID known for %u methods (first: %s)\n", - compat_str, num_missing, missing); - return DCP_FIRMWARE_UNKNOWN; - } - return DCP_FIRMWARE_V_27_0; } + if (hw->firmware_compat == DCP_FIRMWARE_V_27_0) + return dcp_check_firmware_27(dev); + /* * SoCs introduced with H17-generation firmware pin its interface; the * loader may not recognise their boot firmware version. @@ -6477,11 +6506,13 @@ static int dcp_platform_probe_pipe(struct platform_device *pdev) return ret; dcp->hw = *(struct apple_dcp_hw_data *)of_device_get_match_data(dev); /* - * T8142 on firmware 27 runs as the T6050's firmware-27 instance, with - * the default method profile: with H17G every swap fails with status 4. + * T8142 and T8140 on firmware 27 run as the T6050's firmware-27 + * instance, with the default method profile: with H17G every swap + * fails with status 4 (T8142). */ if (fw_compat == DCP_FIRMWARE_V_27_0 && - of_device_is_compatible(dev->of_node, "apple,t8142-dcp")) + (of_device_is_compatible(dev->of_node, "apple,t8142-dcp") || + of_device_is_compatible(dev->of_node, "apple,t8140-dcp"))) dcp->hw.iomfb_method_profile = DCP_IOMFB_METHODS_DEFAULT; /* The display such a processor finds at boot is its first sink. */ if (dcp_sink_metadata(dcp)) diff --git a/tools/testing/selftests/drivers/gpu/apple-dcp/boot.py b/tools/testing/selftests/drivers/gpu/apple-dcp/boot.py index 95c02e87ddc02..e3461a454e335 100644 --- a/tools/testing/selftests/drivers/gpu/apple-dcp/boot.py +++ b/tools/testing/selftests/drivers/gpu/apple-dcp/boot.py @@ -181,3 +181,104 @@ def syslog(root): return 0; } ''' + + +def firmware_selection(root): + """DCP firmware interface selection by SoC and firmware-compat build.""" + source = (root / 'drivers/gpu/drm/apple/dcp.c').read_text() + versions = (root / 'drivers/gpu/drm/apple/version_utils.h').read_text() + enum = block(versions, 'enum dcp_firmware_version {') + ';\n' + return r''' +#include +#include +#include +#include +#include +typedef uint32_t u32; +#define DCP_FW_VERSION_STR_LEN 20 +#define EINVAL 22 +#define IS_ERR(p) ((uintptr_t)(p) >= (uintptr_t)-4095) +''' + enum + r''' +struct device_node { const char *compatible; u32 compat[3]; int compat_cells; }; +struct device { struct device_node *of_node; const void *data; }; +struct apple_dcp_hw_data { enum dcp_firmware_version firmware_compat; }; +struct dcp_method_entry { const char *tag; }; +struct dcp_v14_board { int unused; }; +static const struct dcp_method_entry complete[1] = { { "A000" } }, partial[1] = { { "" } }; +static bool table_27_2_complete = true; +static unsigned errors; +static const void *of_device_get_match_data(struct device *dev) { return dev->data; } +static bool of_device_is_compatible(struct device_node *n, const char *s) { return !strcmp(n->compatible, s); } +static int dcp_read_fw_version(struct device *dev, const char *name, char *out) +{ + struct device_node *n = dev->of_node; + assert(!strcmp(name, "apple,firmware-compat") || !strcmp(name, "apple,firmware-version")); + if (n->compat_cells != 3) + return -EINVAL; + return snprintf(out, DCP_FW_VERSION_STR_LEN, "%u.%u.%u", n->compat[0], n->compat[1], n->compat[2]); +} +static int of_property_read_u32_index(struct device_node *n, const char *name, u32 index, u32 *out) +{ + assert(!strcmp(name, "apple,firmware-compat") && index == 0); + if (n->compat_cells != 3) + return -EINVAL; + *out = n->compat[0]; + return 0; +} +static const struct dcp_method_entry *iomfb_v27_methods(const char *compat) +{ + if (!strcmp(compat, "27.0.0") || !strcmp(compat, "27.3.0")) + return complete; + if (!strcmp(compat, "27.2.0")) + return table_27_2_complete ? complete : partial; + return NULL; +} +static const char *iomfb_v27_missing_method(const struct dcp_method_entry *m, unsigned int *count) +{ + *count = m[0].tag[0] ? 0 : 1; + return m[0].tag[0] ? NULL : "some_method"; +} +static bool of_property_present(struct device_node *n, const char *s) { (void)n; (void)s; return false; } +static bool apple_t8122_25g83_board(void) { return false; } +static int of_property_read_u32(struct device_node *n, const char *s, u32 *v) { (void)n; (void)s; (void)v; return -EINVAL; } +static int of_property_read_string(struct device_node *n, const char *s, const char **v) { (void)n; (void)s; (void)v; return -EINVAL; } +static const struct dcp_v14_board *iomfb_v14_7_board(struct device *dev) { (void)dev; return NULL; } +static __attribute__((unused)) const char *iomfb_v14_7_board_name(const struct dcp_v14_board *b) { (void)b; return "none"; } +#define dev_err(dev, ...) do { (void)(dev); errors++; } while (0) +#define dev_warn(dev, ...) do { (void)(dev); } while (0) +''' + block(source, 'static enum dcp_firmware_version dcp_check_firmware_27(') + '\n' \ + + block(source, 'static enum dcp_firmware_version dcp_check_firmware_version(') + r''' +static enum dcp_firmware_version pick(const char *compatible, enum dcp_firmware_version pinned, + u32 a, u32 b, u32 c) +{ + struct device_node n = { compatible, { a, b, c }, 3 }; + struct apple_dcp_hw_data hw = { pinned }; + struct device dev = { &n, &hw }; + errors = 0; + return dcp_check_firmware_version(&dev); +} +int main(void) +{ + assert(pick("apple,t8140-dcp", DCP_FIRMWARE_H17P, 26, 6, 2) == DCP_FIRMWARE_H17P && !errors); + assert(pick("apple,t8140-dcp", DCP_FIRMWARE_H17P, 26, 5, 0) == DCP_FIRMWARE_H17P && !errors); + puts("PASS T8140 keeps the H17P interface on 26.x firmware"); + assert(pick("apple,t8140-dcp", DCP_FIRMWARE_H17P, 27, 2, 0) == DCP_FIRMWARE_V_27_0 && !errors); + puts("PASS T8140 drives 27.2 firmware as firmware 27"); + table_27_2_complete = false; + assert(pick("apple,t8140-dcp", DCP_FIRMWARE_H17P, 27, 2, 0) == DCP_FIRMWARE_UNKNOWN && errors == 1); + table_27_2_complete = true; + puts("PASS T8140 27.2 is not started with an incomplete method table"); + assert(pick("apple,t8140-dcp", DCP_FIRMWARE_H17P, 27, 0, 0) == DCP_FIRMWARE_UNKNOWN && errors == 1); + assert(pick("apple,t8140-dcp", DCP_FIRMWARE_H17P, 27, 3, 0) == DCP_FIRMWARE_UNKNOWN && errors == 1); + assert(pick("apple,t8140-dcp", DCP_FIRMWARE_H17P, 28, 0, 0) == DCP_FIRMWARE_UNKNOWN && errors == 1); + puts("PASS T8140 never drives other 27+ builds through H17P"); + assert(pick("apple,t8140-dcpext", DCP_FIRMWARE_H17P, 27, 2, 0) == DCP_FIRMWARE_H17P); + puts("PASS T8140 dcpext selection is unchanged (its probe admits 26.6.2 only)"); + assert(pick("apple,t8142-dcp", DCP_FIRMWARE_H17P, 27, 0, 0) == DCP_FIRMWARE_V_27_0); + assert(pick("apple,t8142-dcp", DCP_FIRMWARE_H17P, 26, 6, 2) == DCP_FIRMWARE_H17P); + assert(pick("apple,t6050-dcp", DCP_FIRMWARE_V_27_0, 27, 2, 0) == DCP_FIRMWARE_V_27_0 && !errors); + assert(pick("apple,t6050-dcp", DCP_FIRMWARE_V_27_0, 26, 6, 2) == DCP_FIRMWARE_UNKNOWN && errors == 1); + puts("PASS T8142 and T6050 selection unchanged"); + return 0; +} +''' diff --git a/tools/testing/selftests/drivers/gpu/apple-dcp/run.py b/tools/testing/selftests/drivers/gpu/apple-dcp/run.py index 05a825197e978..0c6f21c7d3592 100644 --- a/tools/testing/selftests/drivers/gpu/apple-dcp/run.py +++ b/tools/testing/selftests/drivers/gpu/apple-dcp/run.py @@ -88,6 +88,7 @@ def main(): ('m4', 'm4-panel-timing', m4.timing, ((),), ('-Wno-unused-function', '-Wno-unused-const-variable')), ('boot', 'oslog-events', boot.oslog, ((),), ()), ('boot', 'syslog-policy', boot.syslog, ((),), ()), + ('boot', 'firmware-selection', boot.firmware_selection, ((),), ()), ('edid', 'dpavserv-start', edid.startup, ((),), ()), ('edid', 'service-rebind', edid.rebind, ((),), ()), ('edid', 'provider-admission', edid.admission, ((),), ()), From adb99697c2c9ec00efb1563db902cd36fa54e153 Mon Sep 17 00:00:00 2001 From: Ryan Murray Date: Fri, 20 Nov 2026 00:38:08 +1100 Subject: [PATCH 2/2] drm/apple: one firmware-27 rule for T8142 and T8140 T8142 and T8140 each had their own firmware-27 block: T8142 took 27.0.0 and 27.2.0 without checking the method table and sent any other 27+ build through H17P; T8140 took only 27.2.0 and refused the rest. Both SoCs ship on H17-generation DCP firmware and run the T6050 firmware-27 generation on macOS 27, so they share one rule: a firmware-compat of 27 or later runs as firmware 27 through dcp_check_firmware_27() (a known, complete method table for the build) or is not started. No 27+ build reaches the H17P interface on either SoC. Changes: T8142 now checks the 27.0/27.2 table for completeness (both are complete, as on T6050), drives 27.3 with its table instead of H17P, and refuses 28+. T8140 also takes 27.0 and 27.3. The selftest covers each case. Signed-off-by: Ryan Murray --- drivers/gpu/drm/apple/dcp.c | 35 +++++-------------- .../selftests/drivers/gpu/apple-dcp/boot.py | 19 ++++++---- 2 files changed, 22 insertions(+), 32 deletions(-) diff --git a/drivers/gpu/drm/apple/dcp.c b/drivers/gpu/drm/apple/dcp.c index 657dee40b8d80..c2d85990bb184 100644 --- a/drivers/gpu/drm/apple/dcp.c +++ b/drivers/gpu/drm/apple/dcp.c @@ -5836,36 +5836,19 @@ static enum dcp_firmware_version dcp_check_firmware_version(struct device *dev) int ret; /* - * T8142 (J813) on macOS 27.0: the H17P interface written for its 26.x - * firmware makes the 27.0 DCP firmware panic right after the first - * hotplug ("ap_link: callback failed with: 0x5"). It runs the T6050's - * firmware-27 generation, and so does 27.2, with the 27.2 method table. + * T8142 (J813) and T8140 (J700) ship on H17-generation DCP firmware. + * On macOS 27 they run the T6050's firmware-27 generation; the H17P + * interface makes it panic right after the first hotplug (T8142 on + * 27.0: "ap_link: callback failed with: 0x5"). A 27 or later build + * runs as firmware 27 with its build's method table, or is not started. */ - if (of_device_is_compatible(dev->of_node, "apple,t8142-dcp")) { - ret = dcp_read_fw_version(dev, "apple,firmware-compat", compat_str); - if (ret >= 0 && (!strcmp(compat_str, "27.0.0") || - !strcmp(compat_str, "27.2.0"))) - return DCP_FIRMWARE_V_27_0; - } - - /* - * T8140 (J700) runs H17P firmware up to 26.6.2. Its 27.2 DCP firmware - * is driven as firmware 27, like T8142 on 27.0. Any other 27.x build - * is not started: the H17P interface is not used on firmware 27. - */ - if (of_device_is_compatible(dev->of_node, "apple,t8140-dcp")) { + if (of_device_is_compatible(dev->of_node, "apple,t8142-dcp") || + of_device_is_compatible(dev->of_node, "apple,t8140-dcp")) { u32 major; - ret = dcp_read_fw_version(dev, "apple,firmware-compat", compat_str); - if (ret >= 0 && !strcmp(compat_str, "27.2.0")) + if (!of_property_read_u32_index(dev->of_node, "apple,firmware-compat", + 0, &major) && major >= 27) return dcp_check_firmware_27(dev); - if (ret >= 0 && - !of_property_read_u32_index(dev->of_node, "apple,firmware-compat", - 0, &major) && major >= 27) { - dev_err(dev, "T8140 display not started: DCP firmware-compat %s is not 27.2.0\n", - compat_str); - return DCP_FIRMWARE_UNKNOWN; - } } if (hw->firmware_compat == DCP_FIRMWARE_V_27_0) diff --git a/tools/testing/selftests/drivers/gpu/apple-dcp/boot.py b/tools/testing/selftests/drivers/gpu/apple-dcp/boot.py index d2820ea62e5b2..9c41279df3938 100644 --- a/tools/testing/selftests/drivers/gpu/apple-dcp/boot.py +++ b/tools/testing/selftests/drivers/gpu/apple-dcp/boot.py @@ -275,17 +275,24 @@ def firmware_selection(root): assert(pick("apple,t8140-dcp", DCP_FIRMWARE_H17P, 27, 2, 0) == DCP_FIRMWARE_UNKNOWN && errors == 1); table_27_2_complete = true; puts("PASS T8140 27.2 is not started with an incomplete method table"); - assert(pick("apple,t8140-dcp", DCP_FIRMWARE_H17P, 27, 0, 0) == DCP_FIRMWARE_UNKNOWN && errors == 1); - assert(pick("apple,t8140-dcp", DCP_FIRMWARE_H17P, 27, 3, 0) == DCP_FIRMWARE_UNKNOWN && errors == 1); + assert(pick("apple,t8140-dcp", DCP_FIRMWARE_H17P, 27, 0, 0) == DCP_FIRMWARE_V_27_0 && !errors); + assert(pick("apple,t8140-dcp", DCP_FIRMWARE_H17P, 27, 3, 0) == DCP_FIRMWARE_V_27_0 && !errors); + puts("PASS T8140 drives every 27.x build with a method table as firmware 27"); assert(pick("apple,t8140-dcp", DCP_FIRMWARE_H17P, 28, 0, 0) == DCP_FIRMWARE_UNKNOWN && errors == 1); - puts("PASS T8140 never drives other 27+ builds through H17P"); + assert(pick("apple,t8140-dcp", DCP_FIRMWARE_H17P, 27, 1, 0) == DCP_FIRMWARE_UNKNOWN && errors == 1); + puts("PASS T8140 never drives a 27+ build without a method table through H17P"); assert(pick("apple,t8140-dcpext", DCP_FIRMWARE_H17P, 27, 2, 0) == DCP_FIRMWARE_H17P); puts("PASS T8140 dcpext selection is unchanged (its probe admits 26.6.2 only)"); - assert(pick("apple,t8142-dcp", DCP_FIRMWARE_H17P, 27, 0, 0) == DCP_FIRMWARE_V_27_0); - assert(pick("apple,t8142-dcp", DCP_FIRMWARE_H17P, 26, 6, 2) == DCP_FIRMWARE_H17P); + assert(pick("apple,t8142-dcp", DCP_FIRMWARE_H17P, 27, 0, 0) == DCP_FIRMWARE_V_27_0 && !errors); + assert(pick("apple,t8142-dcp", DCP_FIRMWARE_H17P, 27, 2, 0) == DCP_FIRMWARE_V_27_0 && !errors); + assert(pick("apple,t8142-dcp", DCP_FIRMWARE_H17P, 26, 6, 2) == DCP_FIRMWARE_H17P && !errors); + puts("PASS T8142 27.0/27.2 and 26.x selection unchanged"); + assert(pick("apple,t8142-dcp", DCP_FIRMWARE_H17P, 27, 3, 0) == DCP_FIRMWARE_V_27_0 && !errors); + assert(pick("apple,t8142-dcp", DCP_FIRMWARE_H17P, 28, 0, 0) == DCP_FIRMWARE_UNKNOWN && errors == 1); + puts("PASS T8142 shares the T8140 rule: 27+ runs as firmware 27 or not at all"); assert(pick("apple,t6050-dcp", DCP_FIRMWARE_V_27_0, 27, 2, 0) == DCP_FIRMWARE_V_27_0 && !errors); assert(pick("apple,t6050-dcp", DCP_FIRMWARE_V_27_0, 26, 6, 2) == DCP_FIRMWARE_UNKNOWN && errors == 1); - puts("PASS T8142 and T6050 selection unchanged"); + puts("PASS T6050 selection unchanged"); return 0; } '''