From be3a61b6d8fdc97560aec0ee8451812e98a71b94 Mon Sep 17 00:00:00 2001 From: Nick Chan Date: Mon, 4 Nov 2024 03:46:22 +0800 Subject: [PATCH] kboot: Add logic to allow T2 to boot into Linux - 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 --- src/kboot.c | 50 +++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-) diff --git a/src/kboot.c b/src/kboot.c index 969d4194e..67b7e5a5c 100644 --- a/src/kboot.c +++ b/src/kboot.c @@ -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"); @@ -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"); @@ -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; @@ -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;