Skip to content
Closed
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
23 changes: 20 additions & 3 deletions src/cpufreq.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ static u32 pstate_reg_to_pstate(u64 val)
case T8122:
case T8142:
case T8140:
case T6050:
return FIELD_GET(CLUSTER_PSTATE_DESIRED1, val);
default:
printf("cpufreq: Chip 0x%x is unsupported\n", chip_id);
Expand All @@ -80,8 +81,9 @@ static u32 pstate_reg_to_pstate(u64 val)

static int set_pstate(const struct cluster_t *cluster, uint32_t pstate)
{
if (chip_id == T8142 && poll64(cluster->base + CLUSTER_PSTATE, CLUSTER_PSTATE_BUSY, 0,
CLUSTER_SWITCH_TIMEOUT) < 0) {
if ((chip_id == T8142 || chip_id == T6050) &&
poll64(cluster->base + CLUSTER_PSTATE, CLUSTER_PSTATE_BUSY, 0, CLUSTER_SWITCH_TIMEOUT) <
0) {
printf("cpufreq: Cluster %s is busy before P-State request\n", cluster->name);
return -1;
}
Expand Down Expand Up @@ -118,6 +120,7 @@ static int set_pstate(const struct cluster_t *cluster, uint32_t pstate)
case T8122:
case T8142:
case T8140:
case T6050:
val &= ~CLUSTER_PSTATE_DESIRED1;
val |= CLUSTER_PSTATE_SET | FIELD_PREP(CLUSTER_PSTATE_DESIRED1, pstate);
break;
Expand All @@ -133,7 +136,7 @@ static int set_pstate(const struct cluster_t *cluster, uint32_t pstate)
}
}

if (chip_id == T8142 &&
if ((chip_id == T8142 || chip_id == T6050) &&
pstate_reg_to_pstate(read64(cluster->base + CLUSTER_PSTATE)) != pstate) {
printf("cpufreq: Cluster %s did not accept P-State %u\n", cluster->name, pstate);
return -1;
Expand Down Expand Up @@ -179,6 +182,7 @@ int cpufreq_init_cluster(const struct cluster_t *cluster, const struct feat_t *f
case S8000 ... S8003:
case T8010 ... T8015: /* This covers a gap but T8013 and T8014 will not randomly appear. */
case T8142: /* Keep firmware voltage, PLL and throttling configuration. */
case T6050:
/* Do nothing */
break;
case T8103:
Expand Down Expand Up @@ -378,6 +382,16 @@ static const struct cluster_t t8142_clusters[] = {
{},
};

/*
* T6050 (M5 Pro/Max): two M clusters (ADT voltage-states22/23, 15 P-states,
* 1.344 to 4.38 GHz) and one P cluster (voltage-states5, 20 P-states). Only
* cluster 0 runs cores today (CPU-START.md); the others stay untouched.
*/
static const struct cluster_t t6050_clusters[] = {
{"MCPU0", 0x210e00000, false, 1, 4},
{},
};

const struct cluster_t *cpufreq_get_clusters(void)
{
switch (chip_id) {
Expand Down Expand Up @@ -417,6 +431,8 @@ const struct cluster_t *cpufreq_get_clusters(void)
return t6030_clusters;
case T8142:
return t8142_clusters;
case T6050:
return t6050_clusters;
case T6031:
case T6034:
return t6031_clusters;
Expand Down Expand Up @@ -535,6 +551,7 @@ const struct feat_t *cpufreq_get_features(void)
case T8122:
return t8122_features;
case T8142:
case T6050:
return t8142_features;
case T6020:
case T6021:
Expand Down
10 changes: 8 additions & 2 deletions src/dapf.c
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,14 @@ struct entry {

struct entry dapf_entries[] = {
/* Keep dart-ane out: its Linux driver owns that DAPF on T8140. */
{"/arm-io/dart-aop", 1, "aop"}, {"/arm-io/dart-mtp", 1, "mtp"}, {"/arm-io/dart-pmp", 1, "pmp"},
{"/arm-io/dart-isp", 5, "isp"}, {"/arm-io/dart-isp0", 5, "isp"}, {NULL, -1, NULL},
{"/arm-io/dart-aop", 1, "aop"},
{"/arm-io/dart-mtp", 1, "mtp"},
{"/arm-io/dart-pmp", 1, "pmp"},
/* T6050: the PMP's DART is dart-pmp0 (dart,t8110; DAPF aperture reg[1], live-verified). */
{"/arm-io/dart-pmp0", 1, "pmp0"},
{"/arm-io/dart-isp", 5, "isp"},
{"/arm-io/dart-isp0", 5, "isp"},
{NULL, -1, NULL},
};

int dapf_init_fdt(const void *fdt)
Expand Down
45 changes: 42 additions & 3 deletions src/kboot.c
Original file line number Diff line number Diff line change
Expand Up @@ -6223,6 +6223,34 @@ void kboot_set_initrd(void *start, size_t size)
initrd_size = size;
}

/* Writes a u32 array straight into the prepared tree's /chosen (after kboot_prepare_dt). */
int kboot_set_chosen_u32s(const char *name, const u32 *vals, int n)
{
if (!dt)
return -1;
/*
* The prepared tree is packed; reopen it over its whole buffer from a
* copy (reopening in place needs twice the packed size).
*/
void *packed = malloc(fdt_totalsize(dt));
if (!packed)
return -1;
memcpy(packed, dt, fdt_totalsize(dt));
int ret = fdt_open_into(packed, dt, dt_bufsize);
free(packed);
if (ret < 0)
return -1;
int node = fdt_path_offset(dt, "/chosen");
if (node < 0)
return -1;
if (fdt_setprop(dt, node, name, NULL, 0) < 0)
return -1;
for (int i = 0; i < n; i++)
if (fdt_appendprop_u32(dt, node, name, vals[i]) < 0)
return -1;
return fdt_pack(dt);
}

int kboot_set_chosen(const char *name, const char *value)
{
int i = 0;
Expand Down Expand Up @@ -6466,7 +6494,9 @@ int kboot_prepare_dt(void *fdt)
image_end < (u64)_base || image_end > ram_end)
bail("FDT: invalid T8103 inherited memory extent\n");
}
if (chip_id == T8140) {
/* T6050 hands its live NVMe session to Linux the same way: retain the heap it allocated from.
*/
if (chip_id == T8140 || chip_id == T6050) {
u64 ram_end, inherited = cur_boot_args.top_of_kernel_data;
u64 high_water = heapblock_high_water();

Expand Down Expand Up @@ -6585,7 +6615,7 @@ int kboot_prepare_dt(void *fdt)
return -1;
if (dt_disable_missing_devs("acio", "cio@", 8, 2))
return -1;
if (dt_disable_missing_devs("i2c", "i2c@", 8, 0))
if (dt_disable_missing_devs("i2c", "i2c@", 16, 0)) /* T6050 (J714c) has nine i2c nodes */
return -1;
if (dt_disable_missing_j700_touch_id())
return -1;
Expand Down Expand Up @@ -6699,7 +6729,16 @@ int kboot_boot(void *kernel)
if (dt_remain < SZ_16K)
printf("FDT: free dt buffer space low, %u bytes left\n", dt_remain);
}
ret = chip_id == T8142 ? dapf_init_fdt(dt) : dapf_init_all();
if (chip_id == T8142) {
ret = dapf_init_fdt(dt);
} else if (chip_id == T6050) {
/* Only the MTP filter, reg 1 of dart-mtp; the AOP entry of the table points at the block
* shared by every DART and faults. */
ret = dapf_init("/arm-io/dart-mtp", 1);
printf("kboot: MTP DAPF %s on T6050\n", ret < 0 ? "failed" : "programmed");
} else {
ret = dapf_init_all();
}
if (ret < 0 && chip_id == T8140) {
printf("kboot: refusing T8140 handoff after DAPF failure\n");
pcie_shutdown();
Expand Down
1 change: 1 addition & 0 deletions src/kboot.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ struct kernel_header {

void kboot_set_initrd(void *start, size_t size);
int kboot_set_chosen(const char *name, const char *value);
int kboot_set_chosen_u32s(const char *name, const u32 *vals, int n);
void kboot_delete_chosen(const char *name);
void kboot_set_config_lost(void);
int kboot_set_uboot(const char *name, const char *value);
Expand Down
43 changes: 30 additions & 13 deletions src/kboot_gpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -2984,28 +2984,41 @@ static int dt_set_gpu_t8122(void *dt)
return 0;
}

static int dt_set_gpu_t8140(void *dt)
/* G17 GPUs: the ADT perf-state shape and the compatibles the loader accepts. */
struct g17_gpu {
const char *name;
const char *compatible;
const char *adt_compatible;
u32 count; /* perf-state-count, and the DT OPP entries */
u32 num_states; /* gpu-num-perf-states */
u32 tables; /* perf-state-table-count; the OPPs come from the first table */
};

static const struct g17_gpu g17_t8140 = {"T8140", "apple,agx-t8140", "gpu,t8140", 16, 15, 1};
static const struct g17_gpu g17_t6050 = {"T6050", "apple,agx-t6050", "gpu,t6050", 14, 13, 4};

static int dt_set_gpu_g17(void *dt, const struct g17_gpu *g)
{
int gpu = fdt_path_offset(dt, "gpu");
if (gpu < 0)
return 0;
if (fdt_node_check_compatible(dt, gpu, "apple,agx-t8140") &&
fdt_node_check_compatible(dt, gpu, "gpu,t8140"))
if (fdt_node_check_compatible(dt, gpu, g->compatible) &&
fdt_node_check_compatible(dt, gpu, g->adt_compatible))
return 0;

int sgx = adt_path_offset(adt, "/arm-io/sgx");
u32 count, num_states, tables, len;
const struct perf_state *states, *sram;
if (sgx < 0 || ADT_GETPROP(adt, sgx, "perf-state-count", &count) != sizeof(count) ||
ADT_GETPROP(adt, sgx, "gpu-num-perf-states", &num_states) != sizeof(num_states) ||
ADT_GETPROP(adt, sgx, "perf-state-table-count", &tables) != sizeof(tables) || count != 16 ||
num_states != 15 || tables != 1)
ADT_GETPROP(adt, sgx, "perf-state-table-count", &tables) != sizeof(tables) ||
count != g->count || num_states != g->num_states || tables != g->tables)
goto disable;
states = adt_getprop(adt, sgx, "perf-states", &len);
if (!states || len != count * sizeof(*states))
if (!states || len != tables * count * sizeof(*states))
goto disable;
sram = adt_getprop(adt, sgx, "perf-states-sram", &len);
if (!sram || len != count * sizeof(*sram))
if (!sram || len != tables * count * sizeof(*sram))
goto disable;
for (u32 i = 0; i < count; i++)
if (states[i].volt > UINT32_MAX / 1000)
Expand All @@ -3018,14 +3031,16 @@ static int dt_set_gpu_t8140(void *dt)
int table = fdt_node_offset_by_phandle(dt, fdt32_ld(opp_ph));
if (table < 0)
goto disable;
int opp, opp_count = 0;
int opp;
u32 opp_count = 0;
fdt_for_each_subnode(opp, dt, table)
{
if (++opp_count > 16 || !fdt_getprop(dt, opp, "opp-hz", &ph_len) || ph_len != sizeof(u64) ||
!fdt_getprop(dt, opp, "opp-microvolt", &ph_len) || ph_len != sizeof(u32))
if (++opp_count > g->count || !fdt_getprop(dt, opp, "opp-hz", &ph_len) ||
ph_len != sizeof(u64) || !fdt_getprop(dt, opp, "opp-microvolt", &ph_len) ||
ph_len != sizeof(u32))
goto disable;
}
if (opp_count != 16)
if (opp_count != g->count)
goto disable;

static const struct {
Expand Down Expand Up @@ -3070,14 +3085,16 @@ static int dt_set_gpu_t8140(void *dt)
gpu = fdt_path_offset(dt, "gpu");
if (gpu >= 0 && fdt_setprop_string(dt, gpu, "status", "disabled"))
return -1;
printf("FDT: GPU: invalid T8140 ADT or DT data, disabling GPU\n");
printf("FDT: GPU: invalid %s ADT or DT data, disabling GPU\n", g->name);
return 0;
}

int dt_set_gpu(void *dt)
{
if (chip_id == T8140)
return dt_set_gpu_t8140(dt);
return dt_set_gpu_g17(dt, &g17_t8140);
if (chip_id == T6050)
return dt_set_gpu_g17(dt, &g17_t6050);

bool has_cs_afr = false;
int (*calc_power)(u32 count, u32 table_count, const struct perf_state *core,
Expand Down
7 changes: 7 additions & 0 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -335,12 +335,19 @@ void m1n1_main(void)
#ifndef BRINGUP
if (chip_id != T8152) {
usb_iodev_shutdown();
#ifdef T6050_NO_HOST_PREP
/* Test build: the kernel's apple,t6050-usb2-phy does the port setup alone. */
printf("T6050 host prep skipped\n");
#else
usb_t6050_host_prep();
#endif
/* Its firmware may still use memory the next stage will reuse. */
if (display_shutdown(DCP_SLEEP_IF_EXTERNAL) < 0) {
printf("Display handoff failed; returning to proxy\n");
uartproxy_run(NULL);
panic("Display handoff failed\n");
}
usb_t6050_host_record();
}
#ifdef USE_FB
fb_shutdown(next_stage.restore_logo);
Expand Down
24 changes: 24 additions & 0 deletions src/nvme.c
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,8 @@ static bool nvme_initialized = false;
static bool nvme_reboot_required;
bool nvme_adopt_live_session = false;
bool nvme_keep_running_for_linux = false;
bool nvme_t6050_stop_coproc =
false; /* T6050: stop the coprocessor at shutdown (it does not restart) */
Comment on lines +136 to +137

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Stop path cannot run

The new nvme_t6050_stop_coproc flag starts as false, and nothing sets it. Normal boots therefore cannot reach the added T6050 stop path. This leaves shutdown code to maintain without a supported way to use or test it. Remove the unused path or connect it to an explicit opt-in.

static u8 nvme_die;

static asc_dev_t *nvme_asc = NULL;
Expand Down Expand Up @@ -412,6 +414,10 @@ bool nvme_init(void)
if (chip_id == T8140 && nvmmu_base == 0x38dcc0000 &&
nvme_base == 0x3cdcc0000 && nvme_size == 0x10000)
nvme_size = 0x30000;
/* The J714c (T6050) ADT has the same 64 KiB alias; same registers above it. */
if (chip_id == T6050 && nvmmu_base == 0x41dcc0000 && nvme_base == 0x45dcc0000 &&
nvme_size == 0x10000)
nvme_size = 0x30000;
if (nvmmu_size < NVMMU_TCB_STAT + sizeof(u32) ||
nvme_size < NVME_DB_LINEAR_IOSQ + sizeof(u32) || nvmmu_base > UINT64_MAX - nvmmu_size ||
nvme_base > UINT64_MAX - nvme_size ||
Expand Down Expand Up @@ -713,6 +719,24 @@ bool nvme_shutdown(void)
goto out_preserve;
}

if (nvme_type == NVME_T8132 && chip_id == T6050 && nvme_t6050_stop_coproc) {
/*
* T6050: stop the coprocessor cleanly and leave its firmware resident.
* Linux sets RUN again and runs a fresh RTKit boot. No PMGR reset here.
*/
write64_lo_hi(nvme_base + NVME_IOQ_CMDS, 0);
write64_lo_hi(nvme_base + NVME_IOQ_CQES, 0);
rtkit_sleep(nvme_rtkit);
rtkit_free(nvme_rtkit);
sart_free(nvme_sart);
asc_free(nvme_asc);
free_queue(&ioq);
free_queue(&adminq);
nvme_initialized = false;
printf("nvme: shutdown done, coprocessor stopped\n");
return true;
}

if (nvme_type == NVME_T8132) {
write64_lo_hi(nvme_base + NVME_IOQ_CMDS, 0);
write64_lo_hi(nvme_base + NVME_IOQ_CQES, 0);
Expand Down
14 changes: 13 additions & 1 deletion src/payload.c
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,11 @@ int payload_run(void)

#ifndef ESP_STAGE2
if (!stage1_config_applied) {
const char *target = stage1_config_target();
/*
* With boot= or an appended kernel (U-Boot) the embedded config only sets the proxy
* window: no chainload target.
*/
const char *target = (boot_spec || kernel) ? NULL : stage1_config_target();
if (target) {
if (chainload_spec && strcmp(chainload_spec, target)) {
printf("Payload: embedded and appended chainload targets differ\n");
Expand Down Expand Up @@ -508,6 +512,14 @@ int payload_run(void)

if (config_lost)
kboot_set_config_lost();

#ifdef ESP_STAGE2
/* T6050: stage 1 left the ANS session live; the next stage (U-Boot) adopts it. */
if (chip_id == T6050 && nvme_adopt_live_session && !boot_spec &&
kboot_set_chosen("asahi,nvme-adopt", "live-rtkit-v1") < 0)
printf("Failed to kboot set asahi,nvme-adopt\n");
#endif

if (kboot_prepare_dt(fdt)) {
printf("Failed to prepare FDT!\n");
goto boot_failed;
Expand Down
8 changes: 7 additions & 1 deletion src/proxy.c
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,13 @@ int proxy_process(ProxyRequest *request, ProxyReply *reply)
break;
case P_VECTOR:
// forcefully restore tps6598x IRQs
usb_hpm_restore_irqs(1);
/*
* T6050: keep the PD controllers masked across the handoff; with
* their interrupts back they renegotiate the ports and the USB 2.0
* host set up for the next stage loses its device (J714c).
*/
if (chip_id != T6050)
usb_hpm_restore_irqs(1);
iodev_console_flush();
next_stage.entry = (generic_func *)request->args[0];
memcpy(next_stage.args, &request->args[1], 5 * sizeof(u64));
Expand Down
5 changes: 3 additions & 2 deletions src/smp.c
Original file line number Diff line number Diff line change
Expand Up @@ -274,8 +274,9 @@ void smp_secondary_prep_el3(void)

static u32 cpu_start_bit(int index, const struct cpu_info *cpu)
{
/* T8142 has six E cores followed by four P cores, not four-core banks. */
if (chip_id == T8142)
/* T8142 has six E cores followed by four P cores, not four-core banks.
* T6050 (J714c) measures the same: one bit per CPU index, write-1-to-clear. */
if (chip_id == T8142 || chip_id == T6050)
return BIT(index);

return BIT(4 * cpu->cluster + cpu->core);
Expand Down
Loading