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
7 changes: 6 additions & 1 deletion src/kboot.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,12 @@ void kboot_delete_chosen(const char *name);
void kboot_set_config_lost(void);
int kboot_set_uboot(const char *name, const char *value);
int dt_gpu_t8122_26_calibrate(void *dt);
int dt_gpu_t8122_27_machine_values(void *dt);
#define T8122_27_VALUES 2
int dt_gpu_t8122_27_machine_values_read(u32 val[T8122_27_VALUES]);
struct t8122_27_value {
const char *path, *adt, *dt;
};
extern const struct t8122_27_value t8122_27_values[T8122_27_VALUES];
void t8122_read_powered_identity(void *dt, int gpu);
int dt_set_gpu_t8122_26(void *dt);

Expand Down
50 changes: 18 additions & 32 deletions src/kboot_gpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -2213,43 +2213,29 @@ int dt_gpu_t8122_26_calibrate(void *dt)
}

/*
* 27.2 start values the kernel takes from the GPU node rather than its own literals, each copied
* as it is and only when this Mac's ADT has it (one cell when present; a malformed one fails):
* 27.2 start values the kernel takes from the GPU node rather than its own literals. Both are
* required: without either one in this Mac's ADT the 27.2 GPU is not handed over.
* - apple,fast-die0-target: /arm-io/sgx gpu-fast-die0-target (degrees C);
* - apple,coredump-copy-buffer: /arm-io/gfx-asc/iop-gfx-nub coredump-copy-buffer (bytes, the
* host's firmware crash-copy buffer).
* dt_gpu_t8122_27_machine_values_read() reads the ADT only, so the start can refuse before
* anything is powered; t8122_gpu_enable_27() copies them to the GPU node as they are.
*/
int dt_gpu_t8122_27_machine_values(void *dt)
const struct t8122_27_value t8122_27_values[T8122_27_VALUES] = {
{"/arm-io/sgx", "gpu-fast-die0-target", "apple,fast-die0-target"},
{"/arm-io/gfx-asc/iop-gfx-nub", "coredump-copy-buffer", "apple,coredump-copy-buffer"},
};

int dt_gpu_t8122_27_machine_values_read(u32 val[T8122_27_VALUES])
{
static const struct {
const char *path, *adt, *dt, *what;
} values[] = {
{"/arm-io/sgx", "gpu-fast-die0-target", "apple,fast-die0-target", "fast-die0 target"},
{"/arm-io/gfx-asc/iop-gfx-nub", "coredump-copy-buffer", "apple,coredump-copy-buffer",
"coredump copy buffer"},
};
bool have[ARRAY_SIZE(values)];
u32 val[ARRAY_SIZE(values)];
for (size_t i = 0; i < ARRAY_SIZE(values); i++) {
int node = adt_path_offset(adt, values[i].path);
for (size_t i = 0; i < T8122_27_VALUES; i++) {
int node = adt_path_offset(adt, t8122_27_values[i].path);
u32 len = 0;
have[i] = node >= 0 && adt_getprop(adt, node, values[i].adt, &len) != NULL;
if (have[i] && g15_adt_u32(node, values[i].adt, &val[i]))
bail("ADT: GPU: T8122 malformed %s (len %u)\n", values[i].adt, len);
int gpu = fdt_path_offset(dt, "gpu");
if (gpu < 0 || (have[i] && fdt_setprop_u32(dt, gpu, values[i].dt, val[i])))
bail("FDT: GPU: T8122 cannot set %s\n", values[i].dt);
}
printf("FDT: GPU: T8122 27.2 machine values: %s ", values[0].what);
if (have[0])
printf("%u C", val[0]);
else
printf("absent");
printf(", %s ", values[1].what);
if (have[1])
printf("0x%x bytes\n", val[1]);
else
printf("absent\n");
if (node < 0 || !adt_getprop(adt, node, t8122_27_values[i].adt, &len))
bail("ADT: GPU: T8122 27.2: %s absent, GPU left disabled\n", t8122_27_values[i].adt);
if (g15_adt_u32(node, t8122_27_values[i].adt, &val[i]) || !val[i])
bail("ADT: GPU: T8122 malformed %s (len %u)\n", t8122_27_values[i].adt, len);
}
return 0;
}

Expand Down Expand Up @@ -4572,7 +4558,7 @@ int dt_set_gpu(void *dt)
int dcp = fdt_path_offset(dt, "dcp"), len;
const fdt32_t *profile =
dcp < 0 ? NULL : fdt_getprop(dt, dcp, "apple,j613-25g83-profile", &len);
/* 27.2 (26B123) firmware: the handoff publication only; it leaves the GPU disabled. */
/* 27.2 (26B123) firmware: the handoff publication, and the GPU start when described. */
if ((profile && len == 4 && fdt32_ld(profile) == 1) || os_firmware.version == V27_2) {
t8122_leak_fuse_export(dt);
return dt_set_gpu_t8122_26(dt);
Expand Down
22 changes: 17 additions & 5 deletions src/kboot_gpu26.c
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,8 @@ static int t8122_gpu_phandle_node(void *dt, const char *prop)

/*
* Hand the GPU to Linux on 27.2, on the copy t8122_gpu_publish_27() passes: everything is
* checked in the DT first, then the 26.6.2 path's calibration runs (OPPs and SRAM voltages from
* checked in the DT and both start values are read from the ADT first (nothing is powered for a
* refusal), then the 26.6.2 path's calibration runs (OPPs and SRAM voltages from
* this Mac's ADT, the bounded powered identity, every power vote released), and only then are
* the mailbox and the GPU node enabled. Any failure discards the copy.
*/
Expand All @@ -439,10 +440,21 @@ static int t8122_gpu_enable_27(void *dt, void *arg)
if (t8122_gpu_phandle_node(dt, "power-domains") < 0)
bail("FDT: GPU: T8122 27.2: GPU node has no single power domain\n");

/* Both start values from this Mac's ADT, read before anything is powered. */
u32 values[T8122_27_VALUES];
if (dt_gpu_t8122_27_machine_values_read(values))
return -1;

if (dt_gpu_t8122_26_calibrate(dt))
bail("FDT: GPU: T8122 27.2: calibration from this Mac's ADT failed\n");
if (dt_gpu_t8122_27_machine_values(dt))
return -1;
for (size_t i = 0; i < T8122_27_VALUES; i++) {
int gpu = t8122_gpu_node(dt);
if (gpu < 0 || fdt_setprop_u32(dt, gpu, t8122_27_values[i].dt, values[i]))
bail("FDT: GPU: T8122 27.2: cannot set %s\n", t8122_27_values[i].dt);
}
printf("FDT: GPU: T8122 27.2 machine values: fast-die0 target %u C, coredump copy buffer "
"0x%x bytes\n",
values[0], values[1]);

mailbox = t8122_gpu_phandle_node(dt, "mboxes");
if (mailbox < 0 || fdt_setprop_string(dt, mailbox, "status", "okay"))
Expand All @@ -468,8 +480,8 @@ static int t8122_gpu_enable_27(void *dt, void *arg)
* has a single power domain, and the 26.6.2 path's calibration (OPPs and SRAM
* voltages from this Mac's ADT, the bounded powered identity the kernel's admission checks, every
* power vote released before Linux starts) succeeds under the M3 Air's chosen.asahi,t8122-gpu
* switch. Then the GPU node gets the 27.2 start values this Mac's ADT has
* (dt_gpu_t8122_27_machine_values()), the mailbox is enabled, the GPU's power domain gets
* switch, and this Mac's ADT has both 27.2 start values. Then the GPU node gets them
* (dt_gpu_t8122_27_machine_values_read()), the mailbox is enabled, the GPU's power domain gets
* apple,no-auto-pm (the 27.2 start takes no PMP link), and the GPU node is enabled; the kernel
* admits and starts the loaded firmware. Any failure leaves the GPU node and the mailbox disabled,
* as before; then only with chosen.asahi,t8122-gpu-power-diag=1 the bounded powered identity probe
Expand Down
41 changes: 33 additions & 8 deletions tests/kboot_gpu_g15_host.c
Original file line number Diff line number Diff line change
Expand Up @@ -2211,15 +2211,29 @@ static void t8122_27_start_t8122_mailbox(void)
}
static void t8122_27_start_values_absent(void)
{
/* Both machine values are optional: absent in the ADT, absent on the GPU node. */
/* Both machine values are required: without them the GPU stays off and is never powered. */
prepare_27_start();
hdel("/arm-io/sgx", "gpu-fast-die0-target");
hdel("/arm-io/gfx-asc/iop-gfx-nub", "coredump-copy-buffer");
run();
assert(!strcmp(status_of(dtbuf, "/soc/gpu@292400000"), "okay"));
assert(prop_len(dtbuf, "/soc/gpu@292400000", "apple,fast-die0-target") < 0);
assert(prop_len(dtbuf, "/soc/gpu@292400000", "apple,coredump-copy-buffer") < 0);
assert(log_has("27.2 machine values: fast-die0 target absent, coredump copy buffer absent"));
t27_start_refused();
assert(log_has("gpu-fast-die0-target absent, GPU left disabled"));
assert(!pmgr_enables && !pmgr_disables);
}
static void t8122_27_start_fast_die_absent(void)
{
prepare_27_start();
hdel("/arm-io/sgx", "gpu-fast-die0-target");
t27_start_refused();
assert(log_has("gpu-fast-die0-target absent, GPU left disabled"));
assert(!pmgr_enables && !pmgr_disables);
}
static void t8122_27_start_coredump_absent(void)
{
prepare_27_start();
hdel("/arm-io/gfx-asc/iop-gfx-nub", "coredump-copy-buffer");
t27_start_refused();
assert(log_has("coredump-copy-buffer absent, GPU left disabled"));
assert(!pmgr_enables && !pmgr_disables);
}
static void t8122_27_start_value_malformed(void)
{
Expand All @@ -2228,8 +2242,16 @@ static void t8122_27_start_value_malformed(void)
hset("/arm-io/gfx-asc/iop-gfx-nub", "coredump-copy-buffer", &wide, sizeof(wide));
t27_start_refused();
assert(log_has("malformed coredump-copy-buffer"));
/* Refused after the calibration: its power vote was still released. */
assert(pmgr_enables == 1 && pmgr_disables == 1 && pmgr_off == 1);
/* Refused from the ADT alone: nothing was powered. */
assert(!pmgr_enables && !pmgr_disables);
}
static void t8122_27_start_value_zero(void)
{
prepare_27_start();
hset_u32("/arm-io/sgx", "gpu-fast-die0-target", 0);
t27_start_refused();
assert(log_has("malformed gpu-fast-die0-target"));
assert(!pmgr_enables && !pmgr_disables);
}
static void t8122_27_start_no_pmp(void)
{
Expand Down Expand Up @@ -2766,7 +2788,10 @@ static const struct {
{"t8122-27-start", t8122_27_start},
{"t8122-27-start-t8122-mailbox", t8122_27_start_t8122_mailbox},
{"t8122-27-start-values-absent", t8122_27_start_values_absent},
{"t8122-27-start-fast-die-absent", t8122_27_start_fast_die_absent},
{"t8122-27-start-coredump-absent", t8122_27_start_coredump_absent},
{"t8122-27-start-value-malformed", t8122_27_start_value_malformed},
{"t8122-27-start-value-zero", t8122_27_start_value_zero},
{"t8122-27-start-no-pmp", t8122_27_start_no_pmp},
{"t8122-27-start-no-power-domain", t8122_27_start_no_power_domain},
{"t8122-27-start-other-mailbox", t8122_27_start_other_mailbox},
Expand Down
Loading