Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions drivers/gpu/drm/apple/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ appledrm-y += iomfb_v14_7.o iomfb_v14_7_link.o
appledrm-$(CONFIG_DRM_APPLE_DCP_T8132) += iomfb_m4.o t8132_ext_drm.o
appledrm-y += iomfb_h17p.o
appledrm-$(CONFIG_DRM_APPLE_KUNIT_TEST) += iomfb_h17p_test.o parser_test.o
appledrm-$(CONFIG_DRM_APPLE_KUNIT_TEST) += iomfb_v27_test.o
appledrm-$(CONFIG_DRM_APPLE_KUNIT_TEST) += iomfb_external_hdr_hints_test.o
appledrm-$(CONFIG_DRM_APPLE_KUNIT_TEST) += apple_resume_test.o
appledrm-$(CONFIG_DRM_APPLE_KUNIT_TEST) += apple_boot_display_test.o
Expand Down
106 changes: 80 additions & 26 deletions drivers/gpu/drm/apple/dcp.c
Original file line number Diff line number Diff line change
Expand Up @@ -5293,43 +5293,88 @@ static int dcp_read_fw_version(struct device *dev, const char *name,
return len;
}

/*
* Firmware 27 is selected by the ABI the DCP reports, the same on every SoC:
* a DCP or dcpext whose firmware-compat is 27 or later runs the common
* firmware-27 instance with the method table of that build. The interfaces
* written for older firmware make it panic (T8142 on 27.0 with H17P: "ap_link:
* callback failed with: 0x5"), so a 27 or later build without a complete
* table is not started at all. Pure, so the host test runs the same rule.
*/
enum dcp_v27_admission dcp_v27_admission(const char *compat,
const struct dcp_method_entry **methods,
const char **missing,
unsigned int *num_missing)
{
unsigned int major;

*methods = NULL;
*missing = NULL;
*num_missing = 0;
if (sscanf(compat, "%u.", &major) != 1 || major < 27)
return DCP_V27_NOT_V27;
*methods = iomfb_v27_methods(compat);
if (!*methods)
return DCP_V27_NO_TABLE;
*missing = iomfb_v27_missing_method(*methods, num_missing);
if (*missing)
return DCP_V27_INCOMPLETE;
return DCP_V27_ADMITTED;
}

/*
* Returns true if the DCP reports firmware 27 or later, with @version the
* firmware-27 instance or DCP_FIRMWARE_UNKNOWN if this build cannot be started.
*/
static bool dcp_firmware_27(struct device *dev,
enum dcp_firmware_version *version)
{
char compat[DCP_FW_VERSION_STR_LEN];
const struct dcp_method_entry *methods;
unsigned int num_missing;
const char *missing;

if (dcp_read_fw_version(dev, "apple,firmware-compat", compat) < 0)
return false;

switch (dcp_v27_admission(compat, &methods, &missing, &num_missing)) {
case DCP_V27_NOT_V27:
return false;
case DCP_V27_NO_TABLE:
dev_err(dev, "DCP firmware-compat %s has no 27.x method table\n",
compat);
*version = DCP_FIRMWARE_UNKNOWN;
return true;
case DCP_V27_INCOMPLETE:
dev_err(dev, "DCP firmware-compat %s not started: no ID known for %u methods (first: %s)\n",
compat, num_missing, missing);
*version = DCP_FIRMWARE_UNKNOWN;
return true;
case DCP_V27_ADMITTED:
break;
}
*version = DCP_FIRMWARE_V_27_0;
return true;
}

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;
enum dcp_firmware_version version;
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.
*/
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"))
return DCP_FIRMWARE_V_27_0;
}
if (dcp_firmware_27(dev, &version))
return version;

/* The T6050 was introduced on firmware 27 and has no older interface. */
if (hw->firmware_compat == DCP_FIRMWARE_V_27_0) {
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);
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;
dev_err(dev, "DCP firmware-compat %s is not 27 or later\n",
ret < 0 ? "missing" : compat_str);
return DCP_FIRMWARE_UNKNOWN;
}

/*
Expand Down Expand Up @@ -6507,6 +6552,15 @@ static int dcp_platform_probe_pipe(struct platform_device *pdev)
if (fw_compat == DCP_FIRMWARE_V_27_0 &&
of_device_is_compatible(dev->of_node, "apple,t8142-dcp"))
dcp->hw.iomfb_method_profile = DCP_IOMFB_METHODS_DEFAULT;
/*
* Every processor on firmware 27 inherits the live session the boot
* loader handed over. Its match data keeps the per-SoC port count,
* tunnel-flow flag and DART resources; only the session adoption follows
* the firmware. (The T8140 dcpext, the one processor whose match data
* does not adopt, is refused above on anything but 26.6.2.)
*/
if (fw_compat == DCP_FIRMWARE_V_27_0)
dcp->hw.adopt_live_session = true;
/* The display such a processor finds at boot is its first sink. */
if (dcp_sink_metadata(dcp))
dcp_desktop_metadata_new_sink(dcp);
Expand Down
13 changes: 13 additions & 0 deletions drivers/gpu/drm/apple/dcp.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,19 @@ bool dcp_fw_compat_is_14_7(struct platform_device *pdev);
bool dcp_fw_compat_is_desktop(struct platform_device *pdev);
bool dcp_fw_compat_panel_edr(struct platform_device *pdev);
unsigned int dcp_gamma_lut_size(struct platform_device *pdev);
/* Whether a DCP reporting firmware-compat @compat runs the firmware-27 instance. */
enum dcp_v27_admission {
DCP_V27_NOT_V27, /* older than 27: the older interfaces decide */
DCP_V27_NO_TABLE, /* 27 or later, no method table for the build */
DCP_V27_INCOMPLETE, /* 27 or later, a method has no known ID */
DCP_V27_ADMITTED,
};

struct dcp_method_entry;
enum dcp_v27_admission dcp_v27_admission(const char *compat,
const struct dcp_method_entry **methods,
const char **missing,
unsigned int *num_missing);
/* T6041 external display processors may join the DRM device. */
bool dcp_t6041_ext_enabled(void);
void dcp_backlight_takeover_registered(struct platform_device *pdev);
Expand Down
85 changes: 85 additions & 0 deletions drivers/gpu/drm/apple/iomfb_v27_test.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
// SPDX-License-Identifier: GPL-2.0-only OR MIT
/* Copyright 2026 Aurora Silicon */

/*
* Firmware 27 is selected by the firmware-compat a DCP reports, on every SoC:
* 27 or later runs the firmware-27 instance when the build has a complete
* method table and is not started otherwise; older firmware is left to the
* older interfaces. These tests cover that rule and the in-tree tables.
*/

#include <kunit/test.h>
#include <linux/module.h>
#include <linux/string.h>

#include "dcp.h"
#include "iomfb.h"
#include "iomfb_v27.h"

static enum dcp_v27_admission admission(const char *compat)
{
const struct dcp_method_entry *methods;
unsigned int num_missing;
const char *missing;

return dcp_v27_admission(compat, &methods, &missing, &num_missing);
}

/* Builds with a complete table start, whatever SoC reports them. */
static void v27_complete_table_admits_test(struct kunit *test)
{
const struct dcp_method_entry *methods;
unsigned int num_missing;
const char *missing;

KUNIT_EXPECT_EQ(test, dcp_v27_admission("27.2.0", &methods, &missing,
&num_missing),
DCP_V27_ADMITTED);
KUNIT_EXPECT_PTR_EQ(test, methods, iomfb_v27_methods("27.2.0"));
KUNIT_EXPECT_PTR_EQ(test, missing, NULL);
KUNIT_EXPECT_EQ(test, num_missing, 0U);
KUNIT_EXPECT_EQ(test, admission("27.0.0"), DCP_V27_ADMITTED);
}

/* 27 or later without a usable table is refused, never handed down. */
static void v27_unusable_table_refuses_test(struct kunit *test)
{
const struct dcp_method_entry *methods;
unsigned int num_missing;
const char *missing;

KUNIT_EXPECT_EQ(test, admission("27.1.0"), DCP_V27_NO_TABLE);
KUNIT_EXPECT_EQ(test, admission("28.0.0"), DCP_V27_NO_TABLE);
KUNIT_EXPECT_EQ(test, dcp_v27_admission("27.3.0", &methods, &missing,
&num_missing),
DCP_V27_INCOMPLETE);
KUNIT_EXPECT_NOT_NULL(test, missing);
KUNIT_EXPECT_GT(test, num_missing, 0U);
}

/* Older firmware keeps the 26.x, 14.x and 13.x selection. */
static void v27_older_firmware_not_v27_test(struct kunit *test)
{
KUNIT_EXPECT_EQ(test, admission("26.6.2"), DCP_V27_NOT_V27);
KUNIT_EXPECT_EQ(test, admission("26.5.2"), DCP_V27_NOT_V27);
KUNIT_EXPECT_EQ(test, admission("14.7.0"), DCP_V27_NOT_V27);
KUNIT_EXPECT_EQ(test, admission("13.5.0"), DCP_V27_NOT_V27);
KUNIT_EXPECT_EQ(test, admission("12.3.0"), DCP_V27_NOT_V27);
KUNIT_EXPECT_EQ(test, admission("UNKNOWN"), DCP_V27_NOT_V27);
}

static struct kunit_case v27_cases[] = {
KUNIT_CASE(v27_complete_table_admits_test),
KUNIT_CASE(v27_unusable_table_refuses_test),
KUNIT_CASE(v27_older_firmware_not_v27_test),
{}
};

static struct kunit_suite v27_suite = {
.name = "apple-dcp-v27",
.test_cases = v27_cases,
};

kunit_test_suite(v27_suite);

MODULE_LICENSE("Dual MIT/GPL");