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.

- Describe the x86 SSD cache on T2, since any potential driver will also
need that memory range to be described. For now though, it can be used
as normal memory.

- 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 Feb 3, 2025
1 parent 0bc4955 commit be3a61b
Showing 1 changed file with 49 additions and 1 deletion.
50 changes: 49 additions & 1 deletion src/kboot.c
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,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 @@ -396,6 +397,20 @@ static int dt_set_memory(void)
}
}

if (chip_id == T8012) {
u64 cache_min = ALIGN_UP(dram_max, BIT(29));
u64 cache_max = dram_base + dram_size;

/* Set x86 SSD Cache as OS memory, any potential driver would need the memory described
* anyways */

memreg[num_regions].start = cpu_to_fdt64(cache_min);
memreg[num_regions++].size = 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);
}

int node = fdt_path_offset(dt, "/memory");
if (node < 0)
bail("FDT: /memory node not found in devtree\n");
Expand Down Expand Up @@ -2383,6 +2398,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 @@ -2570,6 +2616,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 be3a61b

Please # to comment.