Skip to content
Draft
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: 0 additions & 1 deletion drivers/gpu/drm/apple/dcp-firmware-test.c
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,6 @@ static void dcp_ext_idle_audio_dma_pin(struct kunit *test)
KUNIT_ASSERT_NOT_NULL(test, dcp);
dcp->dev = &dev;
dcp->hw = apple_dcp_hw_t8142_dcpext;
dcp->hw.s2r_untested = false;
dcp->fw_compat = DCP_FIRMWARE_V_27_0;
dcp->v27_methods = iomfb_v27_methods("27.2.0");
KUNIT_ASSERT_NOT_NULL(test, dcp->v27_methods);
Expand Down
10 changes: 8 additions & 2 deletions drivers/gpu/drm/apple/dcp-internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -445,8 +445,14 @@ struct apple_dcp_hw_data {
bool v27_early_stop;
/* Required with @s2r */
const struct dcp_s2r_layout *s2r_layout;
/* @s2r with derived power words: firmware 27.0 only, off with appledrm.s2r_untested=0 */
bool s2r_untested;
/* @s2r / @s2r_ext static layout requires firmware 27.0 (not 26.x / H17P) */
bool s2r_v27_only;
/*
* If non-NULL, the static @s2r / @s2r_ext layout is enabled only when
* an available sleep-controller node matching this compatible carries
* apple,sleep-tested (matching sleep.c's per-board gate for .untested SoCs).
*/
const char *s2r_sleep_tested_compat;
/*
* @s2r without a secure mailbox: the SoC's ADT has no dcp-exclave-mailbox (T8142, on
* firmware 27.0 and 27.2.1), so there is no secure port to idle before the IOP.
Expand Down
75 changes: 43 additions & 32 deletions drivers/gpu/drm/apple/dcp.c
Original file line number Diff line number Diff line change
Expand Up @@ -413,8 +413,9 @@ static int dcp_secure_port_init(struct apple_dcp *dcp)
* once its secure port has gone idle. A device tree without those keeps the firmware
* running: DPMS is the backlight alone and the display stays up across a sleep. A SoC
* without a secure mailbox says so (hw.s2r_no_secure_port). Power words from the device
* tree stop the firmware by default; a SoC whose static words are only derived (T8142) does
* so with appledrm.s2r_untested (default on).
* tree stop the firmware by default; a SoC whose static layout is tied to a per-board
* sleep gate (hw.s2r_sleep_tested_compat) enables it only when the board's DT marks that
* sleep controller with apple,sleep-tested.
*/
/*
* hw.s2r without a layout in its hw data takes its words from the device tree, the ones its
Expand Down Expand Up @@ -568,7 +569,7 @@ static void dcp_s2r_check_dt(struct apple_dcp *dcp)
/*
* Without a layout from the device tree, an external DCP keeps the fixed DISPEXT0
* sequence it had before (T8140); a firmware-27 one is then not dcp_s2r_ext_capable()
* without the lab parameter and refuses a deep sleep instead.
* and refuses a deep sleep instead.
*/
if (dcp->hw.s2r_ext && !dcp->hw.s2r_layout) {
int ret = dcp_s2r_layout_from_dt(dcp) ?: dcp_s2r_layout_streams(dcp);
Expand All @@ -578,8 +579,8 @@ static void dcp_s2r_check_dt(struct apple_dcp *dcp)
dcp->s2r_dt_layout_ok = false;
}
}
if (dcp->hw.s2r && dcp->hw.s2r_untested)
dev_info(dcp->dev, "firmware stop enabled (appledrm.s2r_untested)\n");
if (dcp->hw.s2r && dcp->hw.s2r_sleep_tested_compat)
dev_info(dcp->dev, "firmware stop enabled (apple,sleep-tested)\n");
}

static void dcp_release_rtkit(void *data)
Expand Down Expand Up @@ -754,16 +755,22 @@ static bool dcp_j714s_ext(struct device *dev)
of_device_is_compatible(dev->of_node, "apple,t6050-dcpext");
}

/*
* The firmware stop on a SoC whose display power words were derived from its device tree
* instead of measured (T8142), on firmware 27.0. It runs through DPMS off and full deep
* sleeps and wakes on J813 and J815 (MacBook Air 13" and 15" M5), so it is on by default;
* appledrm.s2r_untested=0 keeps such a DCP's firmware running.
*/
static bool s2r_untested = true;
module_param(s2r_untested, bool, 0444);
MODULE_PARM_DESC(s2r_untested,
"Stop the DCP firmware on DPMS off and system sleep using derived T8142 power words (default 1)");
static bool dcp_s2r_sleep_tested(const char *compat)
{
KUNIT_STATIC_STUB_REDIRECT(dcp_s2r_sleep_tested, compat);
return apple_sleep_tested(compat);
}

static bool dcp_s2r_static_layout_allowed(const struct apple_dcp_hw_data *hw,
enum dcp_firmware_version fw_compat)
{
if (hw->s2r_v27_only && fw_compat != DCP_FIRMWARE_V_27_0)
return false;
if (hw->s2r_sleep_tested_compat &&
!dcp_s2r_sleep_tested(hw->s2r_sleep_tested_compat))
return false;
return true;
}

bool dcp_t6041_ext_enabled(void)
{
Expand Down Expand Up @@ -9276,14 +9283,15 @@ static int dcp_platform_probe_pipe(struct platform_device *pdev)
dcp->hw = apple_dcp_hw_t8132_v27;
/*
* A stop needs power words: a static layout, or the device tree's (see
* dcp_s2r_layout_from_dt(), offered by default). A SoC whose static words are only
* derived (hw.s2r_untested, T8142) is offered it only when asked for, and only on
* firmware 27.0, whose calls are the ones that ran with them.
* dcp_s2r_layout_from_dt(), offered by default). A static layout marked
* s2r_v27_only runs only on firmware 27.0, and one marked
* s2r_sleep_tested_compat runs only on boards whose DT marks that sleep
* controller with apple,sleep-tested.
*/
if (dcp->hw.s2r && ((!dcp->hw.s2r_layout &&
!of_property_present(dev->of_node, "apple,display-power")) ||
(dcp->hw.s2r_untested &&
(!s2r_untested || fw_compat != DCP_FIRMWARE_V_27_0))))
(dcp->hw.s2r_layout &&
!dcp_s2r_static_layout_allowed(&dcp->hw, fw_compat))))
dcp->hw.s2r = false;
dcp->v27_sleep_transport = dcp_v27_sleep_transport_supported(dcp);
/* The display such a processor finds at boot is its first sink. */
Expand Down Expand Up @@ -10889,12 +10897,13 @@ static bool dcp_s2r_ext_capable(struct apple_dcp *dcp)
return false;
if (dcp->fw_compat == DCP_FIRMWARE_V_27_0)
/*
* Only with a power layout: the device tree's, or a static one (under the
* lab parameter while it is untested). Without one the fixed DISPEXT0
* sequence below is not this DCP's.
* Only with a power layout: the device tree's, or a static one
* permitted by firmware generation and board sleep-tested state.
* Without one the fixed DISPEXT0 sequence below is not this DCP's.
*/
return (dcp->s2r_dt_layout_ok ||
(dcp->hw.s2r_layout && (!dcp->hw.s2r_untested || s2r_untested))) &&
(dcp->hw.s2r_layout &&
dcp_s2r_static_layout_allowed(&dcp->hw, dcp->fw_compat))) &&
dcp->v27_methods &&
dcp->v27_methods[dcpep_unnamed_500].tag[0];
return dcp->fw_compat == DCP_FIRMWARE_H17P;
Expand Down Expand Up @@ -13397,8 +13406,8 @@ static int dcp_platform_suspend(struct device *dev)

/*
* The same stop as DPMS off; without this system-suspend path an active
* panel leaves the DCP running. Probe already gates a derived power
* layout (T8142) on appledrm.s2r_untested.
* panel leaves the DCP running. Probe already gates static layouts on
* firmware generation and the board's apple,sleep-tested state.
*/
if (pm_suspend_via_firmware() && dcp_s2r_capable(dcp)) {
int ret = dcp_s2r_suspend(dcp);
Expand Down Expand Up @@ -13681,7 +13690,8 @@ static const struct apple_dcp_hw_data apple_dcp_hw_t6020 = {
.num_dptx_ports = 1,
.t6020_tunnel_flow = true,
.s2r = true,
.s2r_untested = true,
.s2r_v27_only = true,
.s2r_sleep_tested_compat = "apple,t6020-sleep",
.s2r_no_secure_port = true,
.map_reg_dart = true,
.s2r_disp_dart_with_dcp = true,
Expand All @@ -13693,7 +13703,8 @@ static const struct apple_dcp_hw_data apple_dcp_hw_t6020_dcpext = {
.num_dptx_ports = 2,
.t6020_tunnel_flow = true,
.s2r_ext = true,
.s2r_untested = true,
.s2r_v27_only = true,
.s2r_sleep_tested_compat = "apple,t6020-sleep",
.s2r_no_secure_port = true,
.map_reg_dart = true,
.s2r_disp_dart_with_dcp = true,
Expand Down Expand Up @@ -13758,9 +13769,9 @@ static const struct apple_dcp_hw_data apple_dcp_hw_t8142 = {
.iomfb_method_profile = DCP_IOMFB_METHODS_H17G,
.adopt_live_session = true,
.firmware_compat = DCP_FIRMWARE_H17P,
/* Firmware 27.0's sleep calls (iomfb_v27.c), unless appledrm.s2r_untested=0 */
/* Firmware 27.0's sleep calls (iomfb_v27.c); tested on J813/J815. */
.s2r = true,
.s2r_untested = true,
.s2r_v27_only = true,
.s2r_no_secure_port = true,
.s2r_layout = &dcp_s2r_t8142,
};
Expand Down Expand Up @@ -13918,9 +13929,9 @@ static const struct apple_dcp_hw_data apple_dcp_hw_t8142_dcpext = {
.sink_metadata_edid = true,
.dptx_endpoint = DPTX_ENDPOINT,
.dptx_controller = true,
/* TEST: firmware 27.2 link release, gated by appledrm.s2r_untested. */
/* Firmware 27.2 link release on J813/J815. */
.s2r_ext = true,
.s2r_untested = true,
.s2r_v27_only = true,
.s2r_no_secure_port = true,
.s2r_layout = &dcp_s2r_t8142_ext[0],
};
Expand Down
84 changes: 84 additions & 0 deletions drivers/gpu/drm/apple/dcp_s2r_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -309,12 +309,96 @@ static void dcp_s2r_t8140_retained_ext_stop_unchanged(struct kunit *test)
KUNIT_EXPECT_TRUE(test, dcp->typec_crtc_off);
}

static bool dcp_s2r_test_sleep_tested_false(const char *compat)
{
struct kunit *test = kunit_get_current_test();

KUNIT_EXPECT_STREQ(test, compat, "apple,t6020-sleep");
return false;
}

static bool dcp_s2r_test_sleep_tested_true(const char *compat)
{
struct kunit *test = kunit_get_current_test();

KUNIT_EXPECT_STREQ(test, compat, "apple,t6020-sleep");
return true;
}

/*
* T6020 internal and external DCP S2R layouts stay off on boards whose
* apple,t6020-sleep node lacks apple,sleep-tested (e.g. J416s, J474s, T6021,
* T6022) and on non-v27 firmware; they enable automatically on firmware 27.x
* once the board marks apple,t6020-sleep with apple,sleep-tested (J414s).
*/
static void dcp_s2r_t6020_gated_by_sleep_tested(struct kunit *test)
{
static const char compat[] = "apple,t6020-dcpext";
struct property props[] = {
{ .name = "apple,display-power", .next = &props[1] },
{ .name = "compatible", .length = sizeof(compat),
.value = (void *)compat },
};
struct device_node node = {
.name = "dcpext",
.full_name = "dcpext",
.properties = props,
};
struct device dev = {
.init_name = "dcp-s2r-t6020-gate-test",
.of_node = &node,
};
struct apple_dcp *dcp = kunit_kzalloc(test, sizeof(*dcp), GFP_KERNEL);

KUNIT_ASSERT_NOT_NULL(test, dcp);
dcp->dev = &dev;
dcp->hw = apple_dcp_hw_t6020_dcpext;
dcp->fw_compat = DCP_FIRMWARE_V_27_0;
dcp->v27_methods = iomfb_v27_methods("27.2.0");
KUNIT_ASSERT_NOT_NULL(test, dcp->v27_methods);
dcp->fixed_connector_type = DRM_MODE_CONNECTOR_USB;

/* Untested T6020 board on fw 27.2: internal, external S2R and ext-idle stay off. */
kunit_activate_static_stub(test, dcp_s2r_sleep_tested, dcp_s2r_test_sleep_tested_false);
KUNIT_EXPECT_FALSE(test, dcp_s2r_static_layout_allowed(&apple_dcp_hw_t6020,
DCP_FIRMWARE_V_27_0));
KUNIT_EXPECT_FALSE(test, dcp_s2r_static_layout_allowed(&apple_dcp_hw_t6020_dcpext,
DCP_FIRMWARE_V_27_0));
KUNIT_EXPECT_FALSE(test, dcp_s2r_ext_capable(dcp));
KUNIT_EXPECT_FALSE(test, dcp_ext_idle_capable(dcp));

/* Board with apple,sleep-tested on apple,t6020-sleep (J414s): enabled on fw 27.x. */
kunit_activate_static_stub(test, dcp_s2r_sleep_tested, dcp_s2r_test_sleep_tested_true);
KUNIT_EXPECT_TRUE(test, dcp_s2r_static_layout_allowed(&apple_dcp_hw_t6020,
DCP_FIRMWARE_V_27_0));
KUNIT_EXPECT_TRUE(test, dcp_s2r_static_layout_allowed(&apple_dcp_hw_t6020_dcpext,
DCP_FIRMWARE_V_27_0));
KUNIT_EXPECT_TRUE(test, dcp_s2r_ext_capable(dcp));
KUNIT_EXPECT_TRUE(test, dcp_ext_idle_capable(dcp));

/* Even on a sleep-tested board, v27-only layouts stay off on 26.x / 13.5 firmware. */
KUNIT_EXPECT_FALSE(test, dcp_s2r_static_layout_allowed(&apple_dcp_hw_t6020,
DCP_FIRMWARE_H17P));
KUNIT_EXPECT_FALSE(test, dcp_s2r_static_layout_allowed(&apple_dcp_hw_t6020,
DCP_FIRMWARE_V_13_5));

/* T8142 (already sleep-tested on J813/J815) stays v27-only without the T6020 DT gate. */
kunit_activate_static_stub(test, dcp_s2r_sleep_tested, dcp_s2r_test_sleep_tested_false);
KUNIT_EXPECT_TRUE(test, dcp_s2r_static_layout_allowed(&apple_dcp_hw_t8142,
DCP_FIRMWARE_V_27_0));
KUNIT_EXPECT_TRUE(test, dcp_s2r_static_layout_allowed(&apple_dcp_hw_t8142_dcpext,
DCP_FIRMWARE_V_27_0));
KUNIT_EXPECT_FALSE(test, dcp_s2r_static_layout_allowed(&apple_dcp_hw_t8142,
DCP_FIRMWARE_H17P));
}

static struct kunit_case dcp_s2r_cases[] = {
KUNIT_CASE(dcp_s2r_t8103_dcpext_wake_order),
KUNIT_CASE(dcp_s2r_t8140_dcpext_wake_order),
KUNIT_CASE(dcp_s2r_t8103_warm_restart_wake_order),
KUNIT_CASE(dcp_s2r_t8142_dcpext_stop_rearms_hpd_ready),
KUNIT_CASE(dcp_s2r_t8140_retained_ext_stop_unchanged),
KUNIT_CASE(dcp_s2r_t6020_gated_by_sleep_tested),
{}
};

Expand Down
17 changes: 17 additions & 0 deletions include/linux/soc/apple/sleep.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,23 @@ static inline bool apple_t6050_sleep_described(void)
return apple_t6050_sleep_property(NULL);
}

/*
* Whether the device tree marks an available @compat sleep controller as
* tested (apple,sleep-tested), matching sleep.c's per-board gate for SoCs
* with apple_sleep_soc.untested = true.
*/
static inline bool apple_sleep_tested(const char *compat)
{
struct device_node *np;
bool ret;

np = of_find_compatible_node(NULL, NULL, compat);
ret = np && of_device_is_available(np) &&
of_property_read_bool(np, "apple,sleep-tested");
of_node_put(np);
return ret;
}

/*
* A sleep controller in the device tree that takes the SMC through its saved-context policy
* (apple,smc-sleep-policy): the SMC's last notices go out with interrupts off, on the
Expand Down
Loading
Loading