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
76 changes: 45 additions & 31 deletions drivers/gpu/drm/apple/dcp.c
Original file line number Diff line number Diff line change
Expand Up @@ -5753,6 +5753,31 @@ 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 bool dcp_ext26_admitted(struct device_node *np)
{
struct device_node *chosen = of_find_node_by_path("/chosen");
Expand Down Expand Up @@ -5808,40 +5833,27 @@ static enum dcp_firmware_version dcp_check_firmware_version(struct device *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;

/*
* 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;
}

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;
if (of_device_is_compatible(dev->of_node, "apple,t8142-dcp") ||
of_device_is_compatible(dev->of_node, "apple,t8140-dcp")) {
u32 major;

if (!of_property_read_u32_index(dev->of_node, "apple,firmware-compat",
0, &major) && major >= 27)
return dcp_check_firmware_27(dev);
}

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.
Expand Down Expand Up @@ -7080,11 +7092,13 @@ static int dcp_platform_probe_pipe(struct platform_device *pdev)
if (!dcp_j714s_ext(dev))
dcp->hw.link_report = false;
/*
* 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;
/*
* A SoC with derived power words is offered the stop only when asked for, and only on
Expand Down
109 changes: 109 additions & 0 deletions tools/testing/selftests/drivers/gpu/apple-dcp/boot.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,3 +187,112 @@ 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 <assert.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <string.h>
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 dcp_ext26_admitted(struct device_node *n) { (void)n; 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_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);
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 && !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 T6050 selection unchanged");
return 0;
}
'''
1 change: 1 addition & 0 deletions tools/testing/selftests/drivers/gpu/apple-dcp/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -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, ((),), ()),
Expand Down
Loading