From 012c89aae0095363d5b74e771e3ce3bef8bcbe28 Mon Sep 17 00:00:00 2001 From: Janne Grunau Date: Wed, 1 Nov 2023 13:48:04 +0100 Subject: [PATCH] kboot: dcpext: t8112/t602x: Use dt_reserve_asc_firmware() for dcpext* Avoids manually matching pre-mapped memory against "carveout-memory-map" and maintaining a list of hopefully static carveoout regions. Leave t8103 and t600x alone for now. Porting dcp over to this a littles harder since that needs additional handling for regions mapped to "dart-disp0?". --- src/kboot.c | 72 ++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 58 insertions(+), 14 deletions(-) diff --git a/src/kboot.c b/src/kboot.c index 15787a9d1..bcbdeb83e 100644 --- a/src/kboot.c +++ b/src/kboot.c @@ -1635,6 +1635,46 @@ static int dt_reserve_asc_firmware(const char *adt_path, const char *adt_path_al return 0; } +static const char dcpext_aliases[][8] = { + "dcpext", "dcpext0", "dcpext1", "dcpext2", "dcpext3", + "dcpext4", "dcpext5", "dcpext6", "dcpext7", +}; + +static int dt_reserve_dcpext_firmware(void) +{ + /* reserve asc for all */ + for (size_t n = 0; n < ARRAY_SIZE(dcpext_aliases); n++) { + const char *dcpext_alias = dcpext_aliases[n]; + char adt_path[48]; + + snprintf(adt_path, sizeof(adt_path) - 1, "/arm-io/%s/iop-%s-nub", dcpext_alias, + dcpext_alias); + adt_path[sizeof(adt_path) - 1] = '\0'; + + if (adt_path_offset(adt, adt_path) < 0) + continue; + + int dcpext_node = fdt_path_offset(dt, dcpext_alias); + if (dcpext_node < 0) + continue; + + int ret = dt_reserve_asc_firmware(adt_path, NULL, dcpext_alias, true, 0); + if (ret < 0) + bail("FDT: reserving ASC firmware for %s failed!\n", dcpext_alias); + + ret = dt_set_dcp_firmware(dcpext_alias); + if (ret) + continue; + + // refresh dcpext_node + dcpext_node = fdt_path_offset(dt, dcpext_alias); + if ((dcpext_node < 0) || (fdt_setprop_string(dt, dcpext_node, "status", "okay") < 0)) + printf("FDT: failed to enable '%s'\n", dcpext_alias); + } + + return 0; +} + static struct disp_mapping disp_reserved_regions_t8103[] = { {"region-id-50", "dcp_data", true, false, false}, {"region-id-57", "region57", true, false, false}, @@ -1649,7 +1689,7 @@ static struct disp_mapping dcpext_reserved_regions_t8103[] = { }; static struct disp_mapping disp_reserved_regions_t8112[] = { - {"region-id-49", "dcp_txt", true, false, false}, + {"region-id-49", "asc-firmware", true, false, false}, {"region-id-50", "dcp_data", true, false, false}, {"region-id-57", "region57", true, false, false}, // The 2 following regions are mapped in dart-dcp sid 5 and dart-disp0 sid 0 and 4 @@ -1657,12 +1697,6 @@ static struct disp_mapping disp_reserved_regions_t8112[] = { {"region-id-95", "region95", true, false, true}, }; -static struct disp_mapping dcpext_reserved_regions_t8112[] = { - {"region-id-49", "dcp_txt", true, false, false}, - {"region-id-73", "dcpext_data", true, false, false}, - {"region-id-74", "region74", true, false, false}, -}; - static struct disp_mapping disp_reserved_regions_t600x[] = { {"region-id-50", "dcp_data", true, false, false}, {"region-id-57", "region57", true, false, false}, @@ -1711,7 +1745,7 @@ static struct disp_mapping dcpext_reserved_regions_t600x[MAX_DCPEXT][2] = { }; static struct disp_mapping disp_reserved_regions_t602x[] = { - {"region-id-49", "dcp_txt", true, false, false}, + {"region-id-49", "asc-firmware", true, false, false}, {"region-id-50", "dcp_data", true, false, false}, {"region-id-57", "region57", true, false, false}, // The 2 following regions are mapped in dart-dcp sid 0 and dart-disp0 sid 0 and 4 @@ -1721,8 +1755,6 @@ static struct disp_mapping disp_reserved_regions_t602x[] = { {"region-id-157", "region157", true, true, false}, }; -#define ARRAY_SIZE(s) (sizeof(s) / sizeof((s)[0])) - static int dt_set_display(void) { /* lock dart-disp0 to prevent old software from resetting it */ @@ -1736,6 +1768,7 @@ static int dt_set_display(void) * they are missing. */ int ret = 0; + char dcp_alias[8] = "dcp"; if (!fdt_node_check_compatible(dt, 0, "apple,t8103")) { ret = dt_carveout_reserved_regions("dcp", "disp0", "disp0_piodma", @@ -1752,9 +1785,6 @@ static int dt_set_display(void) ARRAY_SIZE(disp_reserved_regions_t8112)); if (ret) return ret; - - ret = dt_carveout_reserved_regions("dcpext", NULL, NULL, dcpext_reserved_regions_t8112, - ARRAY_SIZE(dcpext_reserved_regions_t8112)); } else if (!fdt_node_check_compatible(dt, 0, "apple,t6000") || !fdt_node_check_compatible(dt, 0, "apple,t6001") || !fdt_node_check_compatible(dt, 0, "apple,t6002")) { @@ -1779,6 +1809,10 @@ static int dt_set_display(void) ARRAY_SIZE(disp_reserved_regions_t602x)); if (ret) return ret; + } else if (!fdt_node_check_compatible(dt, 0, "apple,t6022")) { + // Set dcp_alias to "dcpext4" on M2 Ultra, cmp. display.c + strncpy(dcp_alias, "dcpext4", sizeof(dcp_alias)); + dcp_alias[sizeof(dcp_alias) - 1] = '\0'; } else { printf("FDT: unknown compatible, skip display reserved-memory setup\n"); return 0; @@ -1786,7 +1820,17 @@ static int dt_set_display(void) if (ret) return ret; - return dt_vram_reserved_region("dcp", "disp0"); + /* + * Ignore errors for dcpext firmware reservation, nodes should be disabled + * if the reservation fails allowing basic operation with just dcp. + */ + if (!fdt_node_check_compatible(dt, 0, "apple,t8112") || + !fdt_node_check_compatible(dt, 0, "apple,t6020") || + !fdt_node_check_compatible(dt, 0, "apple,t6021") || + !fdt_node_check_compatible(dt, 0, "apple,t6022")) + dt_reserve_dcpext_firmware(); + + return dt_vram_reserved_region(dcp_alias, "disp0"); } static int dt_set_sio_fwdata(void)