Skip to content

Commit

Permalink
kboot: Add logic to allow T2 to boot into Linux
Browse files Browse the repository at this point in the history
- Some devices does not have a display internal or external, do not try to
prepare framebuffer on it.

- The SSD cache on T2 can be used as normal memory, so add it to /memory
in addition to the normal memory described by iBoot.

- Only half of the memory channels are used on T2 with 1 GB of memory,
and this fact must be learned at runtime because the amount of memory
depends on the storage configuration of the host Mac.

Signed-off-by: Nick Chan <towinchenmi@gmail.com>
  • Loading branch information
asdfugil committed Dec 1, 2024
1 parent 8eb9f33 commit 927c09f
Showing 1 changed file with 55 additions and 3 deletions.
58 changes: 55 additions & 3 deletions src/kboot.c
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,8 @@ static int dt_set_chosen(void)
printf("FDT: initrd at %p size 0x%lx\n", initrd_start, initrd_size);
}

if (cur_boot_args.video.base) {
if (cur_boot_args.video.base &&
(adt_path_offset(adt, "/arm-io/disp0") > 0 || (chip_id != T8012 && chip_id != T7000))) {
int fb = fdt_path_offset(dt, "/chosen/framebuffer");
if (fb < 0)
bail("FDT: /chosen node not found in devtree\n");
Expand Down Expand Up @@ -335,8 +336,26 @@ static int dt_set_memory(void)
if (node < 0)
bail("FDT: /memory node not found in devtree\n");

if (fdt_setprop(dt, node, "reg", memreg, sizeof(memreg)))
bail("FDT: couldn't set memory.reg property\n");
if (chip_id == T8012) {
u64 cache_min = ALIGN_UP(dram_max, BIT(29));
u64 cache_max = dram_base + dram_size;

/*
* Set the SSD cache as OS memory, supposedly we will deal with the x86 SSD interface with a
* kernel driver that allocates memory anyways
*/
u64 memreg_t2[4] = {memreg[0], memreg[1], cpu_to_fdt64(cache_min),
cpu_to_fdt64(cache_max - cache_min)};

printf("FDT: Usable memory range 2 (SSD cache): 0x%lx..0x%lx (0x%lx)\n", cache_min,
cache_max, cache_max - cache_min);

if (fdt_setprop(dt, node, "reg", memreg_t2, sizeof(memreg_t2)))
bail("FDT: couldn't set memory.reg property\n");
} else {
if (fdt_setprop(dt, node, "reg", memreg, sizeof(memreg)))
bail("FDT: couldn't set memory.reg property\n");
}

return 0;
}
Expand Down Expand Up @@ -2310,6 +2329,37 @@ static int dt_transfer_virtios(void)
return 0;
}

static int dt_set_pmgr(void)
{
if (chip_id != T8012)
return 0;

if (mem_size_actual > 0x40000000)
return 0;

int pmgr_node = fdt_path_offset(dt, "/soc/power-management@20e000000");
if (pmgr_node < 0) {
printf("FDT: Failed to find pmgr node\n");
return 0;
}

int dcs2_node = fdt_path_offset(dt, "/soc/power-management@20e000000/power-controller@80258");
if (dcs2_node < 0)
bail("FDT: failed to find ps_dcs2 node\n");

/* Allow failure */
fdt_delprop(dt, dcs2_node, "apple,always-on");

int dcs3_node = fdt_path_offset(dt, "/soc/power-management@20e000000/power-controller@80260");
if (dcs3_node < 0)
bail("FDT: failed to find ps_dcs3 node\n");

/* Allow failure */
fdt_delprop(dt, dcs3_node, "apple,always-on");

return 0;
}

void kboot_set_initrd(void *start, size_t size)
{
initrd_start = start;
Expand Down Expand Up @@ -2495,6 +2545,8 @@ int kboot_prepare_dt(void *fdt)
return -1;
if (dt_set_isp_fwdata())
return -1;
if (dt_set_pmgr())
return -1;
#ifndef RELEASE
if (dt_transfer_virtios())
return 1;
Expand Down

0 comments on commit 927c09f

Please # to comment.