Skip to content

Commit 1124c22

Browse files
WhatAmISupposedToPutHerejannau
authored andcommitted
kboot: pmp initialization
Copy all the things that PMP needs in order to boot. Signed-off-by: Sasha Finkelstein <[email protected]>
1 parent c7aff8f commit 1124c22

1 file changed

Lines changed: 59 additions & 0 deletions

File tree

src/kboot.c

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2014,6 +2014,63 @@ static int dt_set_display(void)
20142014
return dt_vram_reserved_region("dcp", "disp0");
20152015
}
20162016

2017+
static const char *excluded_pmp_props[] = {
2018+
"compatible", "AAPL,phandle", "region-base", "region-size",
2019+
"segment-names", "segment-ranges", "pre-loaded", "firmware-name",
2020+
"dram-capacity", "coredump-enable", "name", NULL,
2021+
};
2022+
2023+
static bool skip_pmp_prop(const char *prop_name)
2024+
{
2025+
for (int i = 0; excluded_pmp_props[i]; i++)
2026+
if (!strcmp(prop_name, excluded_pmp_props[i]))
2027+
return true;
2028+
return false;
2029+
}
2030+
2031+
static int dt_set_pmp(void)
2032+
{
2033+
int pmp_node = fdt_path_offset(dt, "pmp");
2034+
if (pmp_node < 0) {
2035+
printf("FDT: pmp not found in devtree\n");
2036+
return 0;
2037+
}
2038+
int chosen_anode = adt_path_offset(adt, "/chosen");
2039+
if (chosen_anode < 0)
2040+
bail("ADT: /chosen not found \n");
2041+
int pmp_iop_anode = adt_path_offset(adt, "/arm-io/pmp/iop-pmp-nub");
2042+
if (pmp_iop_anode < 0)
2043+
bail("ADT: /arm-io/pmp/iop-pmp-nub not found \n");
2044+
2045+
u32 board_id, dram_vendor_id, dram_capacity = 0xFFFFFFFF;
2046+
if (ADT_GETPROP(adt, chosen_anode, "board-id", &board_id) < 0)
2047+
bail("ADT: failed to get board id\n");
2048+
if (ADT_GETPROP(adt, chosen_anode, "dram-vendor-id", &dram_vendor_id) < 0)
2049+
bail("ADT: failed to get dram vendor id\n");
2050+
ADT_GETPROP(adt, pmp_iop_anode, "dram-capacity", &dram_capacity);
2051+
2052+
if (fdt_setprop_u32(dt, pmp_node, "apple,board-id", board_id))
2053+
bail("FDT: failed to set board id\n");
2054+
if (fdt_setprop_u32(dt, pmp_node, "apple,dram-vendor-id", dram_vendor_id))
2055+
bail("FDT: failed to set dram vendor id\n");
2056+
if (dram_capacity != 0xFFFFFFFF &&
2057+
fdt_setprop_u32(dt, pmp_node, "apple,dram-capacity", dram_capacity))
2058+
bail("FDT: failed to set dram capacity\n");
2059+
2060+
ADT_FOREACH_PROPERTY(adt, pmp_iop_anode, prop)
2061+
{
2062+
if (skip_pmp_prop(prop->name))
2063+
continue;
2064+
char prop_name[128];
2065+
snprintf(prop_name, sizeof(prop_name), "apple,tunable-%s", prop->name);
2066+
if (fdt_setprop(dt, pmp_node, prop_name, prop->value, prop->size))
2067+
bail("FDT: failed to transfer pmp tunable");
2068+
}
2069+
pmp_node = fdt_path_offset(dt, "pmp");
2070+
fdt_setprop_string(dt, pmp_node, "status", "okay");
2071+
return 0;
2072+
}
2073+
20172074
static int dt_set_sep(void)
20182075
{
20192076
const char *path = fdt_get_alias(dt, "sep");
@@ -2749,6 +2806,8 @@ int kboot_prepare_dt(void *fdt)
27492806
return -1;
27502807
if (dt_set_sep())
27512808
return -1;
2809+
if (dt_set_pmp())
2810+
return -1;
27522811
if (dt_set_nvram())
27532812
return -1;
27542813
if (dt_set_ipd())

0 commit comments

Comments
 (0)