Skip to content

Commit

Permalink
kboot: dcpext: t8112/t602x: Use dt_reserve_asc_firmware() for dcpext*
Browse files Browse the repository at this point in the history
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?".
  • Loading branch information
jannau committed Nov 6, 2023
1 parent 3af4e92 commit 012c89a
Showing 1 changed file with 58 additions and 14 deletions.
72 changes: 58 additions & 14 deletions src/kboot.c
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand All @@ -1649,20 +1689,14 @@ 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
{"region-id-94", "region94", true, true, false},
{"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},
Expand Down Expand Up @@ -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
Expand All @@ -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 */
Expand All @@ -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",
Expand All @@ -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")) {
Expand All @@ -1779,14 +1809,28 @@ 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;
}
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)
Expand Down

0 comments on commit 012c89a

Please sign in to comment.