Skip to content
Merged
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
5 changes: 5 additions & 0 deletions src/dcp_iboot.c
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,11 @@ int dcp_ib_shutdown(dcp_iboot_if_t *iboot)
return 0;
}

bool dcp_ib_is_afkv2(const dcp_iboot_if_t *iboot)
{
return iboot && afk_epic_is_v2(iboot->epic);
}

static int dcp_ib_cmd(dcp_iboot_if_t *iboot, int op, size_t in_size)
{
size_t rxsize = RXBUF_LEN;
Expand Down
1 change: 1 addition & 0 deletions src/dcp_iboot.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ typedef struct {

dcp_iboot_if_t *dcp_ib_init(dcp_dev_t *dcp);
int dcp_ib_shutdown(dcp_iboot_if_t *iboot);
bool dcp_ib_is_afkv2(const dcp_iboot_if_t *iboot);

int dcp_ib_set_surface(dcp_iboot_if_t *iboot, dcp_layer_t *layer);
int dcp_ib_set_power(dcp_iboot_if_t *iboot, bool power);
Expand Down
37 changes: 26 additions & 11 deletions src/display.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ bool has_dcp;
bool display_is_external;
bool display_is_dptx;
bool display_needs_power_cycle;
static bool display_external_lit;

static const display_config_t display_config_m1 = {
.dcp = "/arm-io/dcp",
Expand Down Expand Up @@ -456,6 +457,7 @@ int display_start_dcp(void)
}

display_is_dptx = !!disp_cfg->dptx_phy[0];
display_external_lit = false;

display_afk_restart(disp_cfg->dcp);
dcp = dcp_init(disp_cfg);
Expand Down Expand Up @@ -669,6 +671,8 @@ int display_configure(const char *config)
printf("display: failed to set power\n");
return ret;
}
if (display_is_external)
display_external_lit = true;

// Sonoma bug workaround
mdelay(100);
Expand Down Expand Up @@ -1250,27 +1254,35 @@ static int display_handoff_t8152(void)
}

/*
* Once a dptx-port that speaks AFKv2 has been connected, its DCP acknowledges no power request:
* on the M2 Mac mini with the 27.2 firmware neither AP QUIESCED or IDLE nor IOP SLEEP is answered,
* even after the display is released and powered off. It cannot be slept or quiesced, so it is
* handed on running, as the T8152 and T8132 displays are, with the display left lit: the next
* stage keeps showing the framebuffer.
* Once a dptx-port that speaks AFKv2 has been connected (M2 Mac mini on 27.2 firmware), or an
* external display on an AFKv2 iBoot interface has been powered on (M1 Mac mini J274 HDMI on 27.2
* firmware), its DCP acknowledges no power request: neither AP QUIESCED or IDLE nor IOP SLEEP is
* answered. It cannot be slept or quiesced, so it is handed on running, as the T8152 and T8132
* displays are, with the display left lit: the next stage keeps showing the framebuffer and Linux
* adopts the live RTKit session via apple,rtkit-handoff ("dcp-live-v1").
*
* Without an attached display (headless), a direct external AFKv2 DCP never powers on or modesets
* and still sleeps cleanly, so it keeps the sleep path.
*/
static bool display_dptx_hands_on(void)
static bool display_dcp_hands_on(void)
{
return display_is_dptx && dcp && dcp_dptx_is_afkv2(dcp->dptx_ep);
if (!dcp)
return false;
if (display_is_dptx && dcp_dptx_is_afkv2(dcp->dptx_ep))
return true;
return display_is_external && display_external_lit && dcp_ib_is_afkv2(iboot);
}

bool display_needs_live_receiver(void)
{
return dcp_handed_on_live() || display_inherited_live_heap(NULL) ||
(iboot && display_dptx_hands_on() && !display_hands_on_live());
(iboot && display_dcp_hands_on() && !display_hands_on_live());
}

/* Stop the endpoints before callers lay out the next image or measure its reservations. */
int display_prepare_live_handoff(void)
{
if (!iboot || !display_dptx_hands_on())
if (!iboot || !display_dcp_hands_on())
return 0;

return display_shutdown(DCP_SLEEP_IF_EXTERNAL);
Expand Down Expand Up @@ -1382,11 +1394,14 @@ int display_shutdown(dcp_shutdown_mode mode)
return 0;

if (iboot) {
bool hands_on = display_dcp_hands_on();
/* An endpoint that does not stop stays registered, so dcp_shutdown()
* retries it with the rest and reports the DCP as still running. */
dcp_ib_shutdown(iboot);
if (display_dptx_hands_on()) {
printf("display: handing the DCP on running (its dptx-port speaks AFKv2)\n");
display_external_lit = false;
if (hands_on) {
printf("display: handing the DCP on running (%s)\n",
display_is_dptx ? "its dptx-port speaks AFKv2" : "external AFKv2 display");
iboot = NULL;
return dcp_hand_on(dcp) < 0 ? -1 : 0;
}
Expand Down
51 changes: 35 additions & 16 deletions tests/python/test_display_dptx_hand_on.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ def function(text, signature):
typedef enum { DCP_QUIESCED, DCP_SLEEP_IF_EXTERNAL, DCP_SLEEP, DCP_HANDOFF } dcp_shutdown_mode;
typedef struct { bool afkv2; } dcp_dptx_if_t;
typedef struct { dcp_dptx_if_t *dptx_ep; bool endpoint_fails; } dcp_dev_t;
typedef struct { int unused; } dcp_iboot_if_t;
typedef struct { bool afkv2; } dcp_iboot_if_t;
static unsigned chip_id = T8112;
static bool has_dcp = true, display_is_external = true, display_is_dptx;
static bool has_dcp = true, display_is_external = true, display_is_dptx, display_external_lit;
static dcp_dev_t *dcp;
static dcp_iboot_if_t *iboot;
static bool running, handed_on;
Expand All @@ -49,6 +49,7 @@ def function(text, signature):
static bool display_hands_on_live(void) { return chip_id == T8140 || chip_id == T8132 || chip_id == T8152; }
static int display_handoff_t8152(void) { call("t8152"); return 0; }
static bool dcp_dptx_is_afkv2(const dcp_dptx_if_t *ep) { return ep && ep->afkv2; }
static bool dcp_ib_is_afkv2(const dcp_iboot_if_t *ib) { return ib && ib->afkv2; }
static int dcp_ib_shutdown(dcp_iboot_if_t *ib) { (void)ib; call("ib"); return 0; }
static int dcp_shutdown(dcp_dev_t *d, bool sleep) { (void)d; call(sleep ? "sleep" : "quiesce"); return 0; }
static int dcp_hand_on(dcp_dev_t *d)
Expand All @@ -64,47 +65,65 @@ def function(text, signature):
"""

MAIN = r"""
static void reset(dcp_dev_t *d, dcp_iboot_if_t *ib, bool dptx, bool external)
static void reset(dcp_dev_t *d, dcp_iboot_if_t *ib, bool dptx, bool external, bool lit)
{
dcp = d;
iboot = ib;
display_is_dptx = dptx;
display_is_external = external;
display_external_lit = lit;
running = handed_on = false;
calls[0] = 0;
}
int main(void)
{
dcp_dptx_if_t v2 = {true}, v1 = {false};
dcp_dev_t d2 = {&v2, false}, d1 = {&v1, false}, internal = {NULL, false}, stuck = {&v2, true};
dcp_iboot_if_t ib;
dcp_dev_t d2 = {&v2, false}, d1 = {&v1, false}, direct = {NULL, false}, stuck = {&v2, true};
dcp_iboot_if_t ib_v1 = {false}, ib_v2 = {true};

/* AFKv2 dptx-port: iBoot interface stopped, then handed on running; no sleep. */
reset(&d2, &ib, true, true);
reset(&d2, &ib_v2, true, true, true);
assert(display_shutdown(DCP_SLEEP_IF_EXTERNAL) == 0);
assert(!strcmp(calls, "ib hand-on ") && !iboot);
assert(!strcmp(calls, "ib hand-on ") && !iboot && !display_external_lit);
/* The Linux boundary asks again: nothing more to do, and still no failure. */
calls[0] = 0;
assert(display_shutdown(DCP_SLEEP_IF_EXTERNAL) == 0 && !calls[0]);

/* The pre-AFKv2 format (13.5 firmware) keeps the sleep. */
reset(&d1, &ib, true, true);
/* Direct external HDMI on AFKv2 (J274 27.2) after power-on: handed on running. */
reset(&direct, &ib_v2, false, true, true);
assert(display_shutdown(DCP_SLEEP_IF_EXTERNAL) == 0);
assert(!strcmp(calls, "ib hand-on ") && !iboot && !display_external_lit);

/* Direct external HDMI on AFKv2 headless (no display lit): still sleeps cleanly. */
reset(&direct, &ib_v2, false, true, false);
assert(display_shutdown(DCP_SLEEP_IF_EXTERNAL) == 0 && !strcmp(calls, "ib sleep "));

/* An internal panel without a dptx-port keeps the quiesce. */
reset(&internal, &ib, false, false);
/* Direct external HDMI on AFKv1 (J274 13.5): keeps the sleep. */
reset(&direct, &ib_v1, false, true, true);
assert(display_shutdown(DCP_SLEEP_IF_EXTERNAL) == 0 && !strcmp(calls, "ib sleep "));

/* The pre-AFKv2 dptx-port format (13.5 firmware) keeps the sleep. */
reset(&d1, &ib_v1, true, true, true);
assert(display_shutdown(DCP_SLEEP_IF_EXTERNAL) == 0 && !strcmp(calls, "ib sleep "));

/* An internal panel without a dptx-port keeps the quiesce, even on AFKv2. */
reset(&direct, &ib_v2, false, false, false);
assert(display_shutdown(DCP_SLEEP_IF_EXTERNAL) == 0 && !strcmp(calls, "ib quiesce "));

/* A modeset after main's initial shutdown still hands off before kboot measures the heap. */
reset(&d2, &ib, true, true);
reset(&d2, &ib_v2, true, true, true);
assert(!handed_on);
assert(display_prepare_live_handoff() == 0);
assert(handed_on && !iboot && !strcmp(calls, "ib hand-on "));
reset(&direct, &ib_v2, false, true, true);
assert(!handed_on);
assert(display_prepare_live_handoff() == 0);
assert(handed_on && !iboot && !strcmp(calls, "ib hand-on "));
reset(&d1, &ib, true, true);
reset(&d1, &ib_v1, true, true, true);
assert(display_prepare_live_handoff() == 0 && !handed_on && !calls[0]);

/* An endpoint that does not stop fails the hand-on, then and at the next boundary. */
reset(&stuck, &ib, true, true);
reset(&stuck, &ib_v2, true, true, true);
assert(display_shutdown(DCP_SLEEP_IF_EXTERNAL) == -1 && !strcmp(calls, "ib hand-on "));
assert(display_shutdown(DCP_SLEEP_IF_EXTERNAL) == -1);
puts("ok");
Expand All @@ -116,13 +135,13 @@ def function(text, signature):
def test_afkv2_dptx_dcp_is_handed_on_running(tmp_path):
disp = (SOURCE / "src/display.c").read_text()
source = HARNESS + "".join(function(disp, signature) for signature in (
"static bool display_dptx_hands_on(",
"static bool display_dcp_hands_on(",
"int display_prepare_live_handoff(void)",
"int display_shutdown(dcp_shutdown_mode mode)\n",
)) + MAIN
exe = tmp_path / "hand-on"
subprocess.run(["cc", "-std=gnu11", "-Wall", "-Wextra", "-Werror", "-Wno-unused-function", "-Wno-switch",
"-x", "c", "-", "-o", str(exe)], input=source, text=True, check=True)
out = subprocess.run([str(exe)], capture_output=True, text=True, check=True).stdout
assert out.count("handing the DCP on running") == 3
assert out.count("handing the DCP on running") == 5
assert out.endswith("ok\n")
2 changes: 1 addition & 1 deletion tests/python/test_t8103_iboot_power_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ def unit():
static dcp_dev_t dcp_storage, *dcp = &dcp_storage;
static struct dcp_iboot_if iboot_storage, *iboot = &iboot_storage;
static u64 fb_dva, fb_size;
static bool display_is_external, display_is_dptx, display_needs_power_cycle;
static bool display_is_external, display_is_dptx, display_needs_power_cycle, display_external_lit;
static bool display_mode_max, fb_dva_allocated;
static struct { struct { u64 base, stride, width, height, depth; } video; } cur_boot_args;
static u64 boot_args_addr;
Expand Down
Loading