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
16 changes: 14 additions & 2 deletions src/exception.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "gxf.h"
#include "iodev.h"
#include "memory.h"
#include "smp.h"
#include "sptm_virt.h"
#include "sptm_virt_priv.h"
#include "uart.h"
Expand Down Expand Up @@ -138,8 +139,14 @@ static const char *get_exception_level(void)

void exception_initialize(void)
{
/*
* At EL2, name VBAR_EL2 itself: VBAR_EL1 reaches it only through the E2H alias, which a core
* reset (a wake from a system sleep) need not have set up by this point.
*/
if (in_el3())
msr(VBAR_EL3, _vectors_start);
else if (in_el2())
msr(VBAR_EL2, _vectors_start);
else
msr(VBAR_EL1, _vectors_start);

Expand Down Expand Up @@ -168,9 +175,14 @@ void exception_initialize(void)
}

/* Initial T8152 bring-up polls KIS without configuring the AIC. A core reset while the
* virtualized SPTM's guest is live must not take the guest's interrupts at EL2. */
if (is_boot_cpu() && chip_id != T8152 && !sptm_virt_guest_live)
* virtualized SPTM's guest is live must not take the guest's interrupts at EL2. A core back
* from a system sleep returns to the OS that slept, which owns every interrupt source by
* then: nothing may be taken here on the way back. */
bool s2r = smp_s2r_published();
if (is_boot_cpu() && chip_id != T8152 && !sptm_virt_guest_live && !s2r)
msr(DAIF, 0 << 6); // Enable SError, IRQ and FIQ
else if (s2r)
msr(DAIF, 0xf << 6); // Mask debug, SError, IRQ and FIQ
else
msr(DAIF, 3 << 6); // Disable IRQ and FIQ

Expand Down
5 changes: 5 additions & 0 deletions src/firmware.c
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,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},
/*
* T8103 (M1, G13G): the headerless image iBoot loads on macOS 27.2 (26B131), seen on the
* MacBook Air (J313). Linux's g14_v27_2 backend starts it.
*/
{T8103, V27_2, "g13g 27.2", {0}, 0, 0, 0x50000, false, "2FF15E57-6B75-3421-922F-EE7EE927AC22"},
/*
* 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.
Expand Down
17 changes: 16 additions & 1 deletion src/kboot.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
#include "usb_dwc3.h"
#include "utils.h"
#include "vsprintf.h"
#include "wdt.h"
#include "xnuboot.h"

#include "libfdt/libfdt.h"
Expand Down Expand Up @@ -742,6 +743,18 @@ static int dt_set_s2r_mailbox(int node)
return 0;
}

/*
* A wake may have to set PCIe up again before the OS runs (smp_s2r_pcie_reinit()), which it
* does only under a watchdog that can still reset the SoC. kboot sets PCIe up after this, so
* decide from the ADT alone whether that step can come up at all.
*/
if (pcie_sleep_reinit_possible() && !wdt_s2r_guard_supported()) {
printf("FDT: no S2R mailbox: no watchdog for the wake's PCIe bring-up\n");
fdt_setprop_string(dt, node, "aurora,s2r-unavailable",
"no watchdog for the wake's PCIe bring-up");
return 0;
}

u64 mailbox = smp_s2r_publish();
if (fdt_setprop_u64(dt, node, "aurora,s2r-mailbox", mailbox))
bail("FDT: couldn't set aurora,s2r-mailbox\n");
Expand Down Expand Up @@ -14030,8 +14043,10 @@ int kboot_boot(void *kernel)
return -1;
}
/* Linux's deep sleep needs them to bring ANS's APCIe block back. */
if (!ret && pcie_apcie_tables_fdt(dt, dt_bufsize) < 0)
int apcie_tables = ret ? 0 : pcie_apcie_tables_fdt(dt, dt_bufsize);
if (apcie_tables < 0)
printf("kboot: APCIe tables not published; deep sleep stays refused\n");
pcie_set_os_restores_apcie(apcie_tables > 0);
if (chip_id == T8140) {
if (ret < 0) {
printf("kboot: refusing T8140 handoff after partial PCIe setup\n");
Expand Down
10 changes: 8 additions & 2 deletions src/kboot_gpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -4542,6 +4542,7 @@ int dt_set_gpu(void *dt)
return dt_set_gpu_t6041(dt);

bool has_cs_afr = false;
bool has_sram_pstates = true;
int (*calc_power)(u32 count, u32 table_count, const struct perf_state *core,
const struct perf_state *sram, const struct aux_perf_states *cs, u32 *max_pwr,
float *core_leak, float *sram_leak, float *cs_leak, float *afr_leak);
Expand All @@ -4552,6 +4553,7 @@ int dt_set_gpu(void *dt)

switch (chip_id) {
case T8103:
has_sram_pstates = false;
calc_power = calc_power_t8103;
break;
case T6022:
Expand Down Expand Up @@ -4676,8 +4678,12 @@ int dt_set_gpu(void *dt)
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)
/*
* The 27.2 backend takes each operating point's SRAM voltage from the handoff on SoCs whose
* ADT publishes perf-states-sram (T8112); T8103 has no such table and derives SRAM voltage
* from apple,min-sram-microvolt in the device tree.
*/
if (handoff && has_sram_pstates && !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)
Expand Down
88 changes: 63 additions & 25 deletions src/kboot_gpu26.c
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ struct gpu26_target {
int (*calibrate)(void *dt);
bool fast_die;
bool exact_regions;
bool zero_data_flag_3seg; /* __DATA flags in the 3-segment layout (0 on G13, 0x10 on G14/G15) */
bool sram_optional;
};

static const struct gpu26_target t8122_target = {
Expand Down Expand Up @@ -216,8 +218,11 @@ static int gpu26_read_adt(const struct gpu26_target *t, struct t8122_gpu_fw *fw)
/* Without a fixed base, the segments only have to run on from the first one. */
if (!i && !next_va && s.iova && !(s.iova & (SZ_16K - 1)))
next_va = s.iova;
u32 expected_flag = (segments == 3 && i == 1 && t->zero_data_flag_3seg)
? 0
: t8122_gpu_layouts[segments].flags[i];
if (s.phys != s.remap || !s.size || s.size & (SZ_16K - 1) || s.size > T8122_GPU_MAX_SEG ||
s.unk != t8122_gpu_layouts[segments].flags[i])
s.unk != expected_flag)
bail("ADT: GPU: %s gfx-asc segment %d is not a plain preloaded segment\n", t->tag, i);
if (s.iova != next_va)
bail("ADT: GPU: %s firmware segment %d at unexpected VA 0x%lx (expected 0x%lx)\n",
Expand Down Expand Up @@ -878,13 +883,23 @@ int dt_set_gpu_t6030_27(void *dt, const struct fw_version_info *image)
}

/*
* G14G (T8112) on firmware whose GPU interface the kernel starts itself (on 27.2, Linux's
* g14_v27_2 backend). The caller has identified the image iBoot loaded (firmware_gfx_version())
* and has no initdata layout for it, and has already published the operating points. The ADT
* must describe the same handoff as on T8122: four UAT regions in /arm-io/sgx and the preloaded
* gfx-asc segments, the __DATA_SHARED_RO tail matching the sgx gfx-data-shared-ro pair. Their
* firmware VAs are not fixed here: they must follow on from the first segment's.
* G13G (T8103) and G14G (T8112) on firmware whose GPU interface the kernel starts itself (on 27.2,
* Linux's g14_v27_2 backend). The caller has identified the image iBoot loaded
* (firmware_gfx_version()) and has no initdata layout for it, and has already published the
* operating points. The ADT must describe the same handoff as on T8122: four UAT regions in
* /arm-io/sgx and the preloaded gfx-asc segments, the __DATA_SHARED_RO tail matching the sgx
* gfx-data-shared-ro pair. Their firmware VAs are not fixed here: they must follow on from the
* first segment's.
*/
static const struct gpu26_target g13g_target = {
.tag = "G13G",
.sgx_compat = "gpu,t8103",
.gpu_compat = "apple,agx-g13g",
.mbox_compat = "apple,asc-mailbox-v4",
.zero_data_flag_3seg = true,
.sram_optional = true,
};

static const struct gpu26_target g14g_target = {
.tag = "G14G",
.sgx_compat = "gpu,t8112",
Expand All @@ -902,43 +917,66 @@ struct g14g_handoff {
static int g14g_gpu_publish(void *dt, void *arg)
{
const struct g14g_handoff *h = arg;
const char *tag = h->fw.t->tag;

if (gpu26_publish_regions(dt, &h->fw))
return -1;

/*
* The kernel's 27.2 backend reads the SRAM voltage of each operating point from
* /chosen/aurora-gpu-resources/sgx adt-perf-states-sram, the ADT property as it is.
* On SoCs whose ADT carries perf-states-sram (T8112), the kernel's 27.2 backend reads each
* operating point's SRAM voltage from /chosen/aurora-gpu-resources/sgx adt-perf-states-sram.
* T8103 has no perf-states-sram in its ADT and uses apple,min-sram-microvolt instead.
*/
int chosen = fdt_path_offset(dt, "/chosen");
int res = chosen < 0 ? chosen : fdt_subnode_offset(dt, chosen, "aurora-gpu-resources");
if (chosen >= 0 && res == -FDT_ERR_NOTFOUND)
res = fdt_add_subnode(dt, chosen, "aurora-gpu-resources");
int sgx = res < 0 ? res : fdt_subnode_offset(dt, res, "sgx");
if (res >= 0 && sgx == -FDT_ERR_NOTFOUND)
sgx = fdt_add_subnode(dt, res, "sgx");
if (sgx < 0 || fdt_setprop(dt, sgx, "adt-perf-states-sram", h->sram, h->sram_len))
bail("FDT: GPU: G14G cannot publish /chosen/aurora-gpu-resources/sgx\n");
if (h->sram && h->sram_len) {
int chosen = fdt_path_offset(dt, "/chosen");
int res = chosen < 0 ? chosen : fdt_subnode_offset(dt, chosen, "aurora-gpu-resources");
if (chosen >= 0 && res == -FDT_ERR_NOTFOUND)
res = fdt_add_subnode(dt, chosen, "aurora-gpu-resources");
int sgx = res < 0 ? res : fdt_subnode_offset(dt, res, "sgx");
if (res >= 0 && sgx == -FDT_ERR_NOTFOUND)
sgx = fdt_add_subnode(dt, res, "sgx");
if (sgx < 0 || fdt_setprop(dt, sgx, "adt-perf-states-sram", h->sram, h->sram_len))
bail("FDT: GPU: %s cannot publish /chosen/aurora-gpu-resources/sgx\n", tag);
}

if (gpu26_publish_version(dt, h->fw.t, h->image) || gpu26_enable(dt, (void *)h->fw.t))
return -1;

/*
* The firmware keeps running through suspend-to-idle, so pmgr must retain the GPU domain
* across system sleep instead of gating it under the live ASC.
*/
int domain = gpu26_phandle_node(dt, h->fw.t, "power-domains");
if (domain < 0 || fdt_setprop_empty(dt, domain, "apple,sleep-retained"))
bail("FDT: GPU: %s cannot mark the GPU power domain apple,sleep-retained\n", tag);

for (int i = 0; i < T8122_GPU_REGIONS; i++)
printf("FDT: GPU: G14G %s: 0x%lx+0x%lx (no-map)\n", t8122_gpu_names[i], h->fw.base[i],
printf("FDT: GPU: %s %s: 0x%lx+0x%lx (no-map)\n", tag, t8122_gpu_names[i], h->fw.base[i],
h->fw.size[i]);
printf("FDT: GPU: G14G firmware %s handoff published, GPU enabled\n", h->image->string);
printf("FDT: GPU: %s firmware %s handoff published, GPU enabled\n", tag, h->image->string);
return 0;
}

int dt_set_gpu_g14g_handoff(void *dt, const struct fw_version_info *image)
{
int sgx = adt_path_offset(adt, "/arm-io/sgx");
if (sgx < 0)
return -1;

const struct gpu26_target *target;
if (adt_is_compatible(adt, sgx, g13g_target.sgx_compat))
target = &g13g_target;
else if (adt_is_compatible(adt, sgx, g14g_target.sgx_compat))
target = &g14g_target;
else
return -1;

struct g14g_handoff h = {.image = image};

if (gpu26_read_adt(&g14g_target, &h.fw))
if (gpu26_read_adt(target, &h.fw))
return -1;
int sgx = adt_path_offset(adt, "/arm-io/sgx");
h.sram = sgx < 0 ? NULL : adt_getprop(adt, sgx, "perf-states-sram", &h.sram_len);
if (!h.sram || !h.sram_len)
bail("ADT: GPU: G14G perf-states-sram missing; handoff refused\n");
h.sram = adt_getprop(adt, sgx, "perf-states-sram", &h.sram_len);
if (!target->sram_optional && (!h.sram || !h.sram_len))
bail("ADT: GPU: %s perf-states-sram missing; handoff refused\n", target->tag);
return t8122_fdt_transaction(dt, g14g_gpu_publish, &h);
}
Loading
Loading