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
9 changes: 5 additions & 4 deletions docs/m1-m3-handoff-sources.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,18 +48,19 @@ Repository links for these source revisions are
The panel and each external-controller transaction are atomic. The optional
native path is not exercised by a J516S boot using the legacy handoff.
* T6031 GPU probing requires the exact chosen string `asahi,t6031-gpu=1`.
On a J516C, `dt_set_m3_defaults()` sets it unless a config line set it.
On J514C and J516C, `dt_set_m3_defaults()` sets it unless a config line set it.
`chosen.asahi,t6031-gpu=0` keeps the handoff off. `chosen.asahi,m3-defaults=0`
prevents the default and keeps the owner's explicit lines as written, an
owner's `asahi,t6031-gpu=1` included. After a lost config line no T6031 line
is passed on, the owner's `=1` included. A J514C still needs the line. This
is passed on, the owner's `=1` included. No manual enable line is needed on
either supported board. This
does not qualify stand-in power data or widen the kernel's board gate.
* The T6031 display handoff requires the exact chosen string
`asahi,t6031-dcp=1`. On a J516C, `dt_set_m3_defaults()` sets it unless a
`asahi,t6031-dcp=1`. On J514C and J516C, `dt_set_m3_defaults()` sets it unless a
config line set it, beside the GPU default, with the same `=0`,
`m3-defaults=0` and lost-line rules. Each switch stands alone: `t6031-gpu=0`
keeps the GPU off and still gets the display default, and `t6031-dcp=0` the
other way round. A J514C still needs the line. Whether the kernel takes the
other way round. No manual enable line is needed. Whether the kernel takes the
display over is the kernel's decision; one that does not leaves the boot
framebuffer. Its `__OS_LOG` reservations are made on every J514C or J516C
boot without it.
Expand Down
26 changes: 18 additions & 8 deletions docs/t8122-gpu-diagnostics.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,17 @@ UUIDs and other machine-derived values outside git.

This switch runs the same fail-soft G15 GPU setup that `chosen.asahi,t6030-gpu=1`
runs on the M3 Pro (`dt_set_gpu_g15()` in `src/kboot_gpu.c`), with the T8122
entry of its SoC table. It is off by default: without it a T8122 boot does not
run the setup at all (there is no dry run), and only the diagnostic switches
above apply. With it, `asahi,t8122-gpu-handoff-diag` is ignored.
entry of its SoC table. On the M3 MacBook Airs (J613, J615) and the 14" M3
MacBook Pro (J504), a normal build sets it by default, together with
`asahi,t8122-dcp`, the stand-in power model (`asahi,t8122-gpu-power-standin`)
and the leakage fuse (`asahi,t8122-gpu-fuse-leakage`), unless a config line set
it (`dt_set_m3_defaults()` in `src/kboot.c`). `chosen.asahi,t8122-gpu=0` keeps
the GPU off; `chosen.asahi,t8122-dcp=0` or `chosen.asahi,m3-defaults=0` keeps
the default GPU switches off too, while an owner's own GPU line still counts.
Other T8122 boards (the J433/J434 iMacs) get no default. Without the switch a
T8122 boot does not run the setup at all (there is no dry run), and only the
diagnostic switches above apply. With it, `asahi,t8122-gpu-handoff-diag` is
ignored.

The setup needs a `gpu` alias to an `apple,agx-t8122` node with the same inputs
as the T6030 node (`reg`/`reg-names` for asc and sgx, `operating-points-v2`,
Expand All @@ -152,11 +160,13 @@ Any failure leaves the gpu node, the UAT regions and the mailbox disabled,
zeroes `apple,firmware-compat`, releases the GPU power closure recursively
and checks that it is off, and lets the boot continue.

The T8122 table does not have a known G15G firmware image, a leakage fuse or a
power model yet, so today step 2 stops the setup before any GPU register or
power access. It logs the loaded image (`FW: GFX: image uuid ...`) and that
the leakage fuse and power model are missing. The kernel also has no T8122 GPU
node or driver path yet.
The T8122 table knows the 14.8.3 G15G image the Airs and the J504 load. Its
power model is a stand-in worked out on the J613, not measured: it sets power
targets, not clocks. The leakage fuse decode was also worked out on the J613.
A boot with an unknown image still stops at step 2, before any GPU register or
power access, and logs the loaded image (`FW: GFX: image uuid ...`). The kernel
starts the GPU only on the boards in its own T8122 list (J613, J615, J504), at
a conservative cap.

Host tests (synthetic ADT, simulated bus, real libfdt):

Expand Down
11 changes: 5 additions & 6 deletions src/kboot.c
Original file line number Diff line number Diff line change
Expand Up @@ -390,9 +390,8 @@ static int dt_set_t8140_wfx_args(int node)
* The J516C switches are its display handoff and GPU, each on its own as on the Pro: an owner's
* chosen.asahi,t6031-gpu=0 keeps the GPU off and the display default still goes in, and
* chosen.asahi,t6031-dcp=0 the other way round. The kernel decides whether it takes the display
* over; one that does not leaves it on the boot framebuffer. The J514C (a T6031 board the
* kernel's GPU driver refuses) and the T6034 Maxes (J514M, J516M) are not touched, nor is any
* other board.
* over; one that does not leaves it on the boot framebuffer. J514C gets the same two defaults
* on a normal build. T6034 Maxes (J514M, J516M) and other boards are untouched.
*/
struct m3_default_board {
const char *soc;
Expand All @@ -411,7 +410,7 @@ static const char *const m3_air_switches[] = {
"asahi,t8122-gpu-fuse-leakage", NULL};
static const char *const m3_pro_boards[] = {"apple,j514s", "apple,j516s", NULL};
static const char *const m3_pro_switches[] = {"asahi,t6030-dcp", "asahi,t6030-gpu", NULL};
static const char *const m3_max_boards[] = {"apple,j516c", NULL};
static const char *const m3_max_boards[] = {"apple,j514c", "apple,j516c", NULL};
static const char *const m3_max_switches[] = {"asahi,t6031-dcp", "asahi,t6031-gpu", NULL};
static const char *const m3_air_graphics[] = {"asahi,t8122-", "asahi,j613-", "asahi,j615-", NULL};
static const char *const m3_pro_graphics[] = {"asahi,t6030-", NULL};
Expand Down Expand Up @@ -5326,8 +5325,8 @@ static int dt_set_display(void)
* On T8122 it does nothing unless chosen.asahi,t8122-dcp=1; the external DCP firmware is
* reserved only with chosen.asahi,t8122-dcpext=1 and that handoff. On T6031 it does nothing
* unless the board is a J514C or J516C, and reserves only __OS_LOG unless
* chosen.asahi,t6031-dcp=1 (on a J516C, dt_set_m3_defaults() sets it unless a config line
* set it).
* chosen.asahi,t6031-dcp=1. dt_set_m3_defaults() supplies it on J514C and J516C;
* an owner's explicit value always wins.
*/
ret = dt_set_display_handoff(dt);
if (!fdt_node_check_compatible(dt, 0, "apple,t8122"))
Expand Down
4 changes: 2 additions & 2 deletions src/kboot_display_handoff.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@
*
* T6031 (M3 Max, J514C/J516C only; nothing at all on another board or chip, so not on a T6034):
* the T8122 handoff with T6031 values, armed by chosen.asahi,t6031-dcp=1, as on T6030 and T8122.
* On a J516C dt_set_m3_defaults() (kboot.c) sets it unless a config line set it; a J514C still
* needs the boot.bin config line. The kernel decides whether to take the display over (a kernel
* dt_set_m3_defaults() (kboot.c) sets it on J514C and J516C unless a config line set it.
* The kernel decides whether to take the display over (a kernel
* may leave that to its command line), so the handoff must be harmless when ignored: the nodes
* stay disabled and only the marker and the memory description are added. On every boot, armed or
* not, the __OS_LOG buffers of dcp and dcpext0..3, taken from the ADT, are reserved. Armed, the
Expand Down
10 changes: 5 additions & 5 deletions src/kboot_gpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -2025,9 +2025,9 @@ static const struct g15_soc g15_soc_t8122_standin = {
};

/*
* T6031 (M3 Max, G15C), J514C/J516C only, requires chosen.asahi,t6031-gpu=1 (on a J516C,
* dt_set_m3_defaults() sets it unless a config line set it): the J613 14.x setup with T6031
* values, with these differences.
* T6031 (M3 Max, G15C), J514C/J516C only, requires chosen.asahi,t6031-gpu=1. Defaults supply
* it on J514C and J516C; an explicit config line always wins.
* This is the J613 14.x setup with T6031 values, with these differences.
* - The identity, topology and core masks come from the bounded powered identity read that runs
* first (t6031_gpu_probe()), which puts the GPU power closure back exactly as iBoot left it. The
* setup itself touches no GPU hardware and leaves the GPU unpowered: the kernel's power domain
Expand Down Expand Up @@ -2691,8 +2691,8 @@ static void t6031_gpu_probe(void *dt)
* T6031 (J514C/J516C): the firmware image facts, the bounded powered identity read, then the GPU
* setup (which itself touches no GPU hardware). Each part is fail-soft; all three
* require chosen.asahi,t6031-gpu=1 because this profile uses unmeasured power stand-ins. On a
* J516C dt_set_m3_defaults() sets it unless a config line set it (=0 keeps all three off); a
* J514C still needs the line.
* J514C or J516C dt_set_m3_defaults() sets it unless a config line set it
* (=0 keeps all three off).
*/
static int dt_set_gpu_t6031(void *dt)
{
Expand Down
27 changes: 13 additions & 14 deletions tests/python/test_m3_defaults_optout.py
Original file line number Diff line number Diff line change
Expand Up @@ -464,12 +464,13 @@ def t6031_lines(r):
return {k: v for k, v in r.chosen.items() if k.startswith("asahi,t6031-")}


@pytest.mark.parametrize("board", ["j514c", "j516c"])
@pytest.mark.parametrize("build", STAGE2)
def test_the_j516c_gets_its_display_and_gpu_defaults_and_nothing_else(tools, build):
def test_the_t6031_boards_get_display_and_gpu_without_config(tools, build, board):
"""A boot.bin with no config: both switches are armed, and the real T6031 GPU entry sees its
switch and runs its image read, identity probe and setup, all on the first boot that loads
this stage 2"""
b = boot(tools, build, b"", board="j516c")
b = boot(tools, build, b"", board=board)
booted(b)
assert t6031_lines(b) == MAX and {MAX_DCP, MAX_GPU} <= b.armed
assert not any(n.startswith(("asahi,t8122-", "asahi,t6030-")) for n in b.chosen)
Expand All @@ -490,32 +491,33 @@ def test_the_j516c_gets_its_display_and_gpu_defaults_and_nothing_else(tools, bui
"t6031-disabled"),
], ids=["gpu-off", "gpu-on-then-off", "gpu-on", "master-off", "master-off-gpu-on",
"master-off-dcp-on", "dcp-on", "dcp-off", "both-off"])
@pytest.mark.parametrize("board", ["j514c", "j516c"])
@pytest.mark.parametrize("build", STAGE2)
def test_j516c_owner_lines_are_kept(tools, build, config, lines, select):
b = boot(tools, build, config, board="j516c")
def test_t6031_owner_lines_are_kept(tools, build, board, config, lines, select):
b = boot(tools, build, config, board=board)
booted(b)
assert t6031_lines(b) == lines and b.select == select
assert bool(b.probes) == (select == "t6031-g15")
assert b.armed & {MAX_DCP, MAX_GPU} == {k for k, v in lines.items() if v == "1"}


@pytest.mark.parametrize("board", ["j514c", "j514m", "j516m", "j293", "j433"])
@pytest.mark.parametrize("board", ["j514m", "j516m", "j293", "j433"])
@pytest.mark.parametrize("build", STAGE2)
def test_other_maxes_and_macs_get_no_default(tools, build, board):
b = boot(tools, build, b"", board=board)
booted(b)
assert not any(n.startswith(M3_LINES) for n in b.chosen), b.stdout
assert not b.probes
# the J514C reaches the T6031 entry, which needs its line as before; T6034 has no GPU path
assert b.select == {"j514c": "t6031-disabled", "j433": "reservation-only"}.get(board, "none")
# T6034 has no GPU path; the J433 (M3 iMac) reaches only the T8122 reservations
assert b.select == {"j433": "reservation-only"}.get(board, "none")


@pytest.mark.parametrize("config,lines", [
(b"chosen.asahi,t6031-gpu=1\n", {MAX_GPU: "1"}),
(b"chosen.asahi,t6031-gpu=1\n", MAX),
(b"chosen.asahi,t6031-gpu=1\nchosen.asahi,t6031-dcp=1\n", MAX),
], ids=["gpu", "gpu-dcp"])
@pytest.mark.parametrize("build", STAGE2)
def test_the_j514c_manual_line_works_as_before(tools, build, config, lines):
def test_explicit_j514c_enable_lines_match_normal_defaults(tools, build, config, lines):
b = boot(tools, build, config, board="j514c")
booted(b)
assert t6031_lines(b) == lines and b.select == "t6031-g15"
Expand Down Expand Up @@ -568,7 +570,7 @@ def test_literal_display_zero_is_the_framebuffer_setting(tools, build):
assert set(AIR) <= b.armed


# ---- a lost line: no graphics on the four boards, and the Mac still boots ----
# ---- a lost line: no graphics on the supported boards, and the Mac still boots ----

LOSSES = {
"gpu-on-fillers-lost-gpu-off": lambda build: GPU_ON + fill(build, keep=1) + GPU_OFF,
Expand Down Expand Up @@ -628,16 +630,13 @@ def test_a_kboot_table_too_small_for_the_config(tools, build):
graphics_off(boot(tools, build, b"tso=1\n" + GPU_ON + lines))


@pytest.mark.parametrize("board,line", [("j514c", b"chosen.asahi,t6031-gpu="),
("j516m", b"chosen.asahi,t6031-gpu="),
@pytest.mark.parametrize("board,line", [("j516m", b"chosen.asahi,t6031-gpu="),
("j293", b"chosen.test,switch=")])
@pytest.mark.parametrize("build", STAGE2)
def test_other_boards_keep_their_lines_after_a_loss(tools, build, board, line):
b = boot(tools, build, line + b"1\n" + fill(build, keep=1) + line + b"0\n", board=board)
booted(b)
assert b.chosen[line[7:-1].decode()] == "1" # as before the M3 defaults: no rule there
if board == "j514c":
assert b.select == "t6031-g15"


# ---- the chainload route ----
Expand Down
45 changes: 39 additions & 6 deletions tests/python/test_m3_graphics_defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,9 +163,9 @@ def harness():
assert(entries() == 2 && defaults() == 2 && chosen_is_default[0] && chosen_is_default[1]);
assert(slot("asahi,t6031-dcp") == 0 && slot("asahi,t6031-gpu") == 1);

/* the J514C, the T6034 Maxes, a Max board name on another SoC or none, unknown M3 boards, a
/* J514C gets normal defaults; T6034 Maxes, a Max board name on another SoC or none, unknown M3 boards, a
board without its SoC, M1/M2: untouched */
UNTOUCHED(J514C);
RESET(J514C); assert(!run()); expect_only(max, 2);
UNTOUCHED(J514M);
UNTOUCHED(J433);
UNTOUCHED("apple,j504\0apple,arm-platform");
Expand Down Expand Up @@ -365,7 +365,7 @@ def harness():
TREE(J516C); assert(!run());
expect_only(max, 2); assert(entries() == 2);
TREE(J514C); assert(!run());
expect_none(); assert(entries() == 0);
expect_only(max, 2); assert(entries() == 2);

/* an owner's later value for a defaulted switch is theirs and survives */
RESET("apple,j613\0apple,t8122\0apple,arm-platform");
Expand Down Expand Up @@ -395,7 +395,7 @@ def harness():
TREE(J613); assert(!run());
expect_only(air, 4); assert(entries() == 6 && defaults() == 4);
TREE(J514C); assert(!run());
expect_none(); assert(entries() == 2 && defaults() == 0);
expect_only(max, 2); assert(entries() == 4 && defaults() == 2);
TREE(J516M); assert(!run());
expect_none(); assert(entries() == 2 && defaults() == 0);
TREE(J516C); assert(!run());
Expand Down Expand Up @@ -580,7 +580,7 @@ def harness():
assert(kboot_set_chosen("asahi,t6031-dcp", "1") >= 0);
chosen_lost = true;
assert(!run());
assert(armed("asahi,t6031-gpu") && armed("asahi,t6031-dcp") && entries() == 2);
assert(!present("asahi,t6031-gpu") && !present("asahi,t6031-dcp") && entries() == 0);
RESET(J516M);
assert(kboot_set_chosen("asahi,t6031-gpu", "1") >= 0);
chosen_lost = true;
Expand Down Expand Up @@ -617,7 +617,11 @@ def test_the_j516c_defaults_are_the_switches_the_t6031_entries_read():
kboot = (ROOT / "src/kboot.c").read_text()
gpu = (ROOT / "src/kboot_gpu.c").read_text()
handoff = (ROOT / "src/kboot_display_handoff.c").read_text()
assert 'm3_max_boards[] = {"apple,j516c", NULL};' in kboot
boards = between(kboot, "static const char *const m3_max_boards[]", "NULL};")
assert '"apple,j516c"' in boards
assert '"apple,j514c"' in boards
assert "#ifdef" not in boards
assert "J514C_BRINGUP" not in (ROOT / "Makefile").read_text()
assert 'm3_max_switches[] = {"asahi,t6031-dcp", "asahi,t6031-gpu", NULL};' in kboot
display = between(handoff, "static const struct dcp_soc dcp_soc_t6031 = {", "};")
assert '.optin = "asahi,t6031-dcp",' in display and ".board_gate = true," in display
Expand Down Expand Up @@ -648,3 +652,32 @@ def test_the_defaults_path_only_edits_the_chosen_table():
calls = set(re.findall(r"\b([A-Za-z_]\w*)\s*\(", body))
assert "kboot_delete_chosen" in calls or "dt_drop_m3_defaults" in calls, name
assert calls <= allowed, (name, calls - allowed)


def test_j514c_normal_build_keeps_exact_board_soc_and_owner_optout(tmp_path):
source = harness().split('int main(void)', 1)[0]
main = r'''
int main(void) {
RESET(J514C); assert(!run()); expect_only(max, N(max));
RESET(J516C); assert(!run()); expect_only(max, N(max));
RESET(J514M); assert(!run()); expect_none();
RESET(J516M); assert(!run()); expect_none();
RESET("apple,j514c\0apple,t6034\0apple,arm-platform");
assert(!run()); expect_none();
RESET(J514C); assert(!kboot_set_chosen("asahi,t6031-gpu", "0"));
assert(!run()); assert(armed("asahi,t6031-dcp"));
assert(!armed("asahi,t6031-gpu"));
RESET(J514C); assert(!kboot_set_chosen("asahi,t6031-dcp", "0"));
assert(!run()); assert(present("asahi,t6031-dcp"));
assert(!armed("asahi,t6031-dcp")); assert(armed("asahi,t6031-gpu"));
assert(entries() == 2 && defaults() == 1);
RESET(J514C); assert(!kboot_set_chosen("asahi,m3-defaults", "0"));
assert(!run()); assert(!present("asahi,t6031-gpu"));
assert(!present("asahi,t6031-dcp"));
RESET(J514C); chosen_lost = true; assert(!run()); expect_none();
return 0;
}
'''
run_c(tmp_path, 'j514c-default',
'#pragma GCC diagnostic ignored "-Wunused-function"\n'
'#pragma GCC diagnostic ignored "-Wunused-variable"\n' + source + main)
Loading