Skip to content

Commit

Permalink
kboot: Reserve ISP firmware
Browse files Browse the repository at this point in the history
Signed-off-by: Eileen Yoon <[email protected]>
  • Loading branch information
eiln committed Aug 22, 2023
1 parent 9ef073a commit 336dfb0
Showing 1 changed file with 66 additions and 0 deletions.
66 changes: 66 additions & 0 deletions src/kboot.c
Original file line number Diff line number Diff line change
Expand Up @@ -1791,6 +1791,68 @@ static int dt_set_sio_fwdata(void)
return 0;
}

struct isp_segment_ranges {
u64 phys;
u64 iova;
u64 remap;
u32 size;
u32 unk;
} PACKED;

static int dt_set_isp_fwdata(void)
{
const char *path = "isp";
const char *adt_path = "/arm-io/isp";

int adt_node = adt_path_offset(adt, adt_path);
if (adt_node < 0) {
printf("ADT: '%s' node not found\n", adt_path);
return 0;
}

u32 segments_len;
struct isp_segment_ranges *segments;
segments =
(struct isp_segment_ranges *)adt_getprop(adt, adt_node, "segment-ranges", &segments_len);
if (!segments || !segments_len)
bail("ADT: invalid ISP segment-ranges\n");

int count = segments_len / sizeof(*segments);
for (int i = 0; i < count; i++)
segments[i].remap = segments[i].iova; // match sio segment-ranges

u64 ctrr_size;
switch (os_firmware.version) {
case V12_1: // haven't checked, probably right
case V12_2: // "
case V12_3:
case V12_3_1:
case V12_4:
case V12_5:
ctrr_size = 0x1800000;
break;
case V13_5:
ctrr_size = 0x1000000;
break;
default:
bail("FDT: couldn't get ISP CTRR size (%d)\n", os_firmware.version);
}

u64 heap_base = segments[count - 1].iova + segments[count - 1].size;
u64 heap_size = ctrr_size - heap_base;

int fdt_node = fdt_path_offset(dt, path);
if (fdt_node < 0)
bail("FDT: '%s' node not found\n", path);

if (fdt_appendprop_u64(dt, fdt_node, "apple,isp-heap-base", heap_base))
bail("FDT: couldn't set apple,isp-heap-base\n");
if (fdt_appendprop_u64(dt, fdt_node, "apple,isp-heap-size", heap_size))
bail("FDT: couldn't set apple,isp-heap-size\n");

return 0;
}

static int dt_disable_missing_devs(const char *adt_prefix, const char *dt_prefix, int max_devs)
{
int ret = -1;
Expand Down Expand Up @@ -2101,6 +2163,10 @@ int kboot_prepare_dt(void *fdt)
return -1;
if (dt_set_sio_fwdata())
return -1;
if (dt_set_isp_fwdata())
return -1;
if (dt_reserve_asc_firmware("/arm-io/isp", "isp"))
return -1;
#ifndef RELEASE
if (dt_transfer_virtios())
return 1;
Expand Down

0 comments on commit 336dfb0

Please sign in to comment.