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
39 changes: 35 additions & 4 deletions src/firmware.c
Original file line number Diff line number Diff line change
Expand Up @@ -340,8 +340,14 @@ bool firmware_sfw_in_range(enum fw_version lower_bound, enum fw_version upper_bo
*
* Only an exact match of the whole identifying part of the header (branch, magic, version, UUID,
* patchbay offset/size, text size) against the table below counts as a positive identification.
* Anything else (no header, unknown image, read fault, odd ADT) makes firmware_gfx_version() return
* NULL, and the caller must then leave the GPU disabled.
*
* Images without that header (G14G on 27.2) are identified by the ADT instead: the uuid string
* iBoot publishes in /arm-io/gfx-asc/iop-gfx-nub for the image it loaded, together with the size
* of the image's __TEXT segment. Such rows have nub_uuid set and are matched only when no
* segment carries a header.
*
* Anything else (no header and no matching nub uuid, unknown image, read fault, odd ADT) makes
* firmware_gfx_version() return NULL, and the caller must then leave the GPU disabled.
*/
// clang-format on
struct gfx_fw_image {
Expand All @@ -352,7 +358,8 @@ struct gfx_fw_image {
u32 patchbay_off;
u32 patchbay_size;
u32 text_size;
bool experimental; /* identified only by firmware_gfx_version_ex(chip, true) */
bool experimental; /* identified only by firmware_gfx_version_ex(chip, true) */
const char *nub_uuid; /* headerless image: the iop-gfx-nub uuid; text_size is __TEXT's size */
};

// clang-format off
Expand All @@ -373,6 +380,11 @@ static const struct gfx_fw_image gfx_fw_images[] = {
{T8122, V14_8_3, "g15g build c0", {0xdf, 0x69, 0x7f, 0x05, 0xf6, 0xb5, 0x33, 0xef,
0xa1, 0x37, 0x61, 0xc4, 0xa7, 0x3d, 0x66, 0x6a},
0x5d54a, 0x1e8, 0x64000, true},
/*
* T8112 (M2, G14G): the headerless image iBoot loads on macOS 27.2 (26B123), seen on the
* MacBook Air (J413). Linux's g14_v27_2 backend starts it.
*/
{T8112, V27_2, "g14g 27.2", {0}, 0, 0, 0x60000, false, "EEFD8A47-3273-3387-868A-F1E0585A978E"},
};
// clang-format on

Expand Down Expand Up @@ -546,7 +558,7 @@ const struct fw_version_info *firmware_gfx_version_ex(u32 chip, bool experimenta
for (size_t j = 0; j < ARRAY_SIZE(gfx_fw_images); j++) {
const struct gfx_fw_image *img = &gfx_fw_images[j];

if (img->chip != chip || (img->experimental && !experimental))
if (img->chip != chip || img->nub_uuid || (img->experimental && !experimental))
continue;
if (memcmp(uuid, img->uuid, sizeof(img->uuid)) || hdr[11] != img->patchbay_off ||
hdr[12] != img->patchbay_size || hdr[13] != img->text_size)
Expand All @@ -564,6 +576,25 @@ const struct fw_version_info *firmware_gfx_version_ex(u32 chip, bool experimenta
return NULL;
}

/* No header in any segment: a headerless image, named by the uuid in the ADT. */
int nub = adt_path_offset(adt, "/arm-io/gfx-asc/iop-gfx-nub");
u32 uuid_len = 0;
const char *uuid = nub < 0 ? NULL : adt_getprop(adt, nub, "uuid", &uuid_len);
for (size_t j = 0; uuid && j < ARRAY_SIZE(gfx_fw_images); j++) {
const struct gfx_fw_image *img = &gfx_fw_images[j];

if (img->chip != chip || !img->nub_uuid || (img->experimental && !experimental))
continue;
if (uuid_len != strlen(img->nub_uuid) + 1 || memcmp(uuid, img->nub_uuid, uuid_len) ||
seg[0].size != img->text_size)
continue;

const struct fw_version_info *ver = &fw_versions[img->version];
printf("FW: GFX: identified image %s (iop-gfx-nub uuid %s), firmware %s\n", img->image,
img->nub_uuid, ver->string);
return ver;
}

printf("FW: GFX: no image-info header found, GPU firmware not identified\n");
return NULL;
}
Expand Down
2 changes: 2 additions & 0 deletions src/kboot.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ struct gpu_fw_layout {
u64 ro_size; /* __DATA_SHARED_RO right after __DATA, or 0 */
};
int gpu_fw_layout(int sgx, struct gpu_fw_layout *fw);
struct fw_version_info;
int dt_set_gpu_g14g_handoff(void *dt, const struct fw_version_info *image);
int kboot_prepare_dt(void *fdt);
int kboot_boot(void *kernel);
/* Reserve the DMA a USB controller that could not be stopped keeps (main.c, after USB shutdown). */
Expand Down
102 changes: 71 additions & 31 deletions src/kboot_gpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -4484,6 +4484,24 @@ static const struct fw_version_info *gpu_initdata_compat(void)
}
}

/*
* Keep iBoot's UAT carveouts reserved and leave the GPU disabled, without touching its power state
* or publishing an ABI.
*/
static int gpu_leave_disabled(void *dt, int sgx)
{
if (dt_set_region(dt, sgx, "gfx-handoff", "/reserved-memory/uat-handoff") ||
dt_set_region(dt, sgx, "gfx-shared-region", "/reserved-memory/uat-pagetables") ||
dt_set_region(dt, sgx, "gpu-region", "/reserved-memory/uat-ttbs"))
return -1;
int gpu = fdt_path_offset(dt, "gpu");
if (gpu < 0)
return 0;
printf("FDT: GPU: no initdata layout for firmware %s; GPU disabled, boot continues\n",
os_firmware.string);
return fdt_setprop_string(dt, gpu, "status", "disabled");
}

int dt_set_gpu(void *dt)
{
if (chip_id == T8152) {
Expand Down Expand Up @@ -4594,38 +4612,47 @@ int dt_set_gpu(void *dt)
size_t data_a_size, data_b_size, globals_size;

/*
* Without an initdata layout for this firmware (T8112's G14G on 27.2), the GPU cannot be
* started. Keep iBoot's carveouts reserved and leave the GPU disabled, without touching its
* power state or publishing an ABI, instead of refusing the whole boot.
* Without an initdata layout for this firmware (T8112's G14G on 27.2), aura cannot set the
* GPU up, so it is left disabled instead of refusing the whole boot. The exception is a loaded
* image that firmware_gfx_version() identifies, which the kernel starts itself from the
* handoff (dt_set_gpu_g14g_handoff()): the operating points are published below as usual,
* then the handoff. A kernel without a backend for that firmware refuses the GPU node at
* probe. Any other image, any operating-point or ADT problem on the handoff path, or a
* handoff the ADT does not describe leaves the GPU disabled; the boot continues.
*/
const struct fw_version_info *handoff = NULL;
if (rust_gpu_initdata_size(compat->num[0], compat->num[1], &data_a_size, &data_b_size,
&globals_size) == -1) {
if (dt_set_region(dt, sgx, "gfx-handoff", "/reserved-memory/uat-handoff") ||
dt_set_region(dt, sgx, "gfx-shared-region", "/reserved-memory/uat-pagetables") ||
dt_set_region(dt, sgx, "gpu-region", "/reserved-memory/uat-ttbs"))
return -1;
gpu = fdt_path_offset(dt, "gpu");
if (gpu < 0)
return 0;
printf("FDT: GPU: no initdata layout for firmware %s; GPU disabled, boot continues\n",
os_firmware.string);
return fdt_setprop_string(dt, gpu, "status", "disabled");
handoff = downstream_dtb ? firmware_gfx_version(chip_id) : NULL;
if (!handoff)
return gpu_leave_disabled(dt, sgx);
}

/* On the handoff path a failure below leaves the GPU disabled instead of failing the boot. */
#define gpu_fail(...) \
do { \
printf(__VA_ARGS__); \
if (handoff) { \
printf("FDT: GPU: firmware %s handoff refused\n", handoff->string); \
return gpu_leave_disabled(dt, sgx); \
} \
return -1; \
} while (0)

u32 perf_state_count;
if (ADT_GETPROP(adt, sgx, "perf-state-count", &perf_state_count) < 0 || !perf_state_count)
bail("ADT: GPU: missing perf-state-count\n");
gpu_fail("ADT: GPU: missing perf-state-count\n");

u32 perf_state_table_count;
if (ADT_GETPROP(adt, sgx, "perf-state-table-count", &perf_state_table_count) < 0 ||
!perf_state_table_count)
bail("ADT: GPU: missing perf-state-table-count\n");
gpu_fail("ADT: GPU: missing perf-state-table-count\n");

if (perf_state_count > MAX_PSTATES)
bail("ADT: GPU: perf-state-count too large\n");
gpu_fail("ADT: GPU: perf-state-count too large\n");

if (perf_state_table_count > MAX_CLUSTERS)
bail("ADT: GPU: perf-state-table-count too large\n");
gpu_fail("ADT: GPU: perf-state-table-count too large\n");

u32 perf_states_len;
const struct perf_state *perf_states, *perf_states_sram;
Expand All @@ -4634,21 +4661,24 @@ int dt_set_gpu(void *dt)
perf_states = adt_getprop(adt, sgx, "perf-states", &perf_states_len);
if (!perf_states ||
perf_states_len != sizeof(*perf_states) * perf_state_count * perf_state_table_count)
bail("ADT: GPU: invalid perf-states length\n");
gpu_fail("ADT: GPU: invalid perf-states length\n");

perf_states_sram = adt_getprop(adt, sgx, "perf-states-sram", &perf_states_len);
/* The 27.2 backend takes each operating point's SRAM voltage from the handoff. */
if (handoff && !perf_states_sram)
gpu_fail("ADT: GPU: perf-states-sram missing\n");
if (perf_states_sram &&
perf_states_len != sizeof(*perf_states) * perf_state_count * perf_state_table_count)
bail("ADT: GPU: invalid perf-states-sram length\n");
gpu_fail("ADT: GPU: invalid perf-states-sram length\n");

perf_states_afr = adt_getprop(adt, sgx, "afr-perf-states", NULL);
perf_states_cs = adt_getprop(adt, sgx, "cs-perf-states", NULL);

if (has_cs_afr && !perf_states_cs)
bail("ADT: GPU: cs-perf-states not found\n");
gpu_fail("ADT: GPU: cs-perf-states not found\n");

if (has_cs_afr && !perf_states_afr)
bail("ADT: GPU: afr-perf-states not found\n");
gpu_fail("ADT: GPU: afr-perf-states not found\n");

u32 max_pwr[MAX_PSTATES];
float core_leak[MAX_CLUSTERS];
Expand All @@ -4658,7 +4688,7 @@ int dt_set_gpu(void *dt)

if (calc_power(perf_state_count, perf_state_table_count, perf_states, perf_states_sram,
perf_states_cs, max_pwr, core_leak, sram_leak, cs_leak, afr_leak))
return -1;
gpu_fail("FDT: GPU: power table calculation failed\n");

printf("FDT: GPU: Max power table: ");
for (u32 i = 0; i < perf_state_count; i++) {
Expand Down Expand Up @@ -4690,19 +4720,19 @@ int dt_set_gpu(void *dt)

if (downstream_dtb) {
if (fdt_set_float_array(dt, gpu, "apple,core-leak-coef", core_leak, perf_state_table_count))
return -1;
gpu_fail("FDT: GPU: cannot set leakage coefficients\n");

if (fdt_set_float_array(dt, gpu, "apple,sram-leak-coef", sram_leak, perf_state_table_count))
return -1;
gpu_fail("FDT: GPU: cannot set leakage coefficients\n");

int len;
const fdt32_t *opps_ph = fdt_getprop(dt, gpu, "operating-points-v2", &len);
if (!opps_ph || len != 4)
bail("FDT: GPU: operating-points-v2 not found\n");
gpu_fail("FDT: GPU: operating-points-v2 not found\n");

int opps = fdt_node_offset_by_phandle(dt, fdt32_ld(opps_ph));
if (opps < 0)
bail("FDT: GPU: node for phandle %u not found\n", fdt32_ld(opps_ph));
gpu_fail("FDT: GPU: node for phandle %u not found\n", fdt32_ld(opps_ph));

u32 i = 0;
int opp;
Expand All @@ -4715,23 +4745,24 @@ int dt_set_gpu(void *dt)
}

if (i >= perf_state_count)
bail("FDT: GPU: Expected %d operating points, but found more\n", perf_state_count);
gpu_fail("FDT: GPU: Expected %d operating points, but found more\n",
perf_state_count);

if (fdt_setprop_inplace(dt, opp, "opp-microvolt", &volts,
sizeof(u32) * perf_state_table_count))
bail("FDT: GPU: Failed to set opp-microvolt for PS %d\n", i);
gpu_fail("FDT: GPU: Failed to set opp-microvolt for PS %d\n", i);

if (fdt_setprop_inplace_u64(dt, opp, "opp-hz", perf_states[i].freq))
bail("FDT: GPU: Failed to set opp-hz for PS %d\n", i);
gpu_fail("FDT: GPU: Failed to set opp-hz for PS %d\n", i);

if (fdt_setprop_inplace_u32(dt, opp, "opp-microwatt", max_pwr[i]))
bail("FDT: GPU: Failed to set opp-microwatt for PS %d\n", i);
gpu_fail("FDT: GPU: Failed to set opp-microwatt for PS %d\n", i);

i++;
}

if (i != perf_state_count)
bail("FDT: GPU: Expected %d operating points, but found %d\n", perf_state_count, i);
gpu_fail("FDT: GPU: Expected %d operating points, but found %d\n", perf_state_count, i);

if (has_cs_afr) {
int ret = fdt_set_aux_opp(dt, gpu, "apple,cs-opp", perf_states_cs, dies);
Expand All @@ -4751,6 +4782,15 @@ int dt_set_gpu(void *dt)
}
}

#undef gpu_fail

if (handoff) {
if (!dt_set_gpu_g14g_handoff(dt, handoff))
return 0;
printf("FDT: GPU: firmware %s handoff not published\n", handoff->string);
return gpu_leave_disabled(dt, sgx);
}

if (dt_set_region(dt, sgx, "gfx-handoff", "/reserved-memory/uat-handoff"))
return -1;
if (dt_set_region(dt, sgx, "gfx-shared-region", "/reserved-memory/uat-pagetables"))
Expand Down
Loading
Loading