Skip to content

Commit 5cf3eb3

Browse files
kboot: pmp initialization
Copy all the things that PMP needs in order to boot. Signed-off-by: Sasha Finkelstein <fnkl.kernel@gmail.com>
1 parent aad70d5 commit 5cf3eb3

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed

src/kboot.c

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

1987+
static const char *excluded_pmp_props[] = {
1988+
"compatible", "AAPL,phandle", "region-base", "region-size",
1989+
"segment-names", "segment-ranges", "pre-loaded", "firmware-name",
1990+
"dram-capacity", "coredump-enable", NULL,
1991+
};
1992+
1993+
static bool skip_pmp_prop(const char *prop_name)
1994+
{
1995+
for (int i = 0; excluded_pmp_props[i]; i++)
1996+
if (!strcmp(prop_name, excluded_pmp_props[i]))
1997+
return true;
1998+
return false;
1999+
}
2000+
2001+
static int dt_set_pmp(void)
2002+
{
2003+
int chosen_anode = adt_path_offset(adt, "/chosen");
2004+
if (chosen_anode < 0)
2005+
bail("ADT: /chosen not found \n");
2006+
int pmp_iop_anode = adt_path_offset(adt, "/arm-io/pmp/iop-pmp-nub");
2007+
if (pmp_iop_anode < 0)
2008+
bail("ADT: /arm-io/pmp/iop-pmp-nub not found \n");
2009+
2010+
u32 board_id, dram_vendor_id, dram_capacity;
2011+
if (ADT_GETPROP(adt, chosen_anode, "board-id", &board_id) < 0)
2012+
bail("ADT: failed to get board id\n");
2013+
if (ADT_GETPROP(adt, chosen_anode, "dram-vendor-id", &dram_vendor_id) < 0)
2014+
bail("ADT: failed to get dram vendor id\n");
2015+
if (ADT_GETPROP(adt, pmp_iop_anode, "dram-capacity", &dram_capacity) < 0)
2016+
bail("ADT: failed to get dram capacity\n");
2017+
2018+
int pmp_node = fdt_path_offset(dt, "pmp");
2019+
if (pmp_node < 0)
2020+
bail("FDT: pmp not not found in devtree\n");
2021+
if (fdt_setprop_u32(dt, pmp_node, "apple,board-id", board_id))
2022+
bail("FDT: failed to set board id\n");
2023+
if (fdt_setprop_u32(dt, pmp_node, "apple,dram-vendor-id", dram_vendor_id))
2024+
bail("FDT: failed to set dram vendor id\n");
2025+
if (fdt_setprop_u32(dt, pmp_node, "apple,dram-capacity", dram_capacity))
2026+
bail("FDT: failed to set dram capacity\n");
2027+
2028+
int tunables_node = fdt_subnode_offset(dt, pmp_node, "tunables");
2029+
if (tunables_node < 0)
2030+
bail("FDT: pmp tunables not not found in devtree\n");
2031+
2032+
ADT_FOREACH_PROPERTY(adt, pmp_iop_anode, prop)
2033+
{
2034+
if (skip_pmp_prop(prop->name))
2035+
continue;
2036+
if (fdt_setprop(dt, tunables_node, prop->name, prop->value, prop->size))
2037+
bail("FDT: failed to transfer pmp tunable");
2038+
}
2039+
pmp_node = fdt_path_offset(dt, "pmp");
2040+
fdt_setprop_string(dt, pmp_node, "status", "okay");
2041+
return 0;
2042+
}
2043+
19872044
static int dt_set_sep(void)
19882045
{
19892046
const char *path = fdt_get_alias(dt, "sep");
@@ -2685,6 +2742,8 @@ int kboot_prepare_dt(void *fdt)
26852742
return -1;
26862743
if (dt_set_sep())
26872744
return -1;
2745+
if (dt_set_pmp())
2746+
return -1;
26882747
if (dt_set_nvram())
26892748
return -1;
26902749
if (dt_set_ipd())

0 commit comments

Comments
 (0)