Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 37 additions & 8 deletions src/dapf.c
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ struct dapf_t8110_config {
u8 r0_lo;
u8 unk4;
} PACKED;
static_assert(sizeof(struct dapf_t8110_config) == 52, "Invalid T8110 DAPF entry size");

struct dapf_t8110b_config {
u64 start;
Expand Down Expand Up @@ -223,24 +224,26 @@ static void dapf_t8132_put(u64 base, const struct dapf_slice *slice)
write32(base + 0x20, slice->r20);
}

static const struct dapf_t8110_config *dapf_t8132_config(const char *path, int node, u32 instance,
static const struct dapf_t8110_config *dapf_t8110_slices(const char *path, int node, u32 instance,
u32 *count)
{
char prop[32];
u32 length;
u32 length = 0;

snprintf(prop, sizeof(prop), "dapf-instance-%u", instance);
const struct dapf_t8110_config *config = adt_getprop(adt, node, prop, &length);
if (!config || !length || length % sizeof(*config) ||
length / sizeof(*config) > T8132_DAPF_SLICES) {
printf("dapf: Invalid T8132 %s for %s\n", prop, path);
printf("dapf: Invalid %s for %s (len %u)\n", prop, path, length);
return NULL;
}

*count = length / sizeof(*config);
for (u32 i = 0; i < *count; i++) {
if (config[i].end < config[i].start) {
printf("dapf: Invalid T8132 %s slice %u for %s\n", prop, i, path);
struct dapf_t8110_config entry;
memcpy(&entry, &config[i], sizeof(entry));
if (entry.end < entry.start) {
printf("dapf: Invalid %s slice %u for %s\n", prop, i, path);
return NULL;
}
}
Expand All @@ -257,7 +260,7 @@ static int dapf_program_t8132(const char *path, u64 base, int node, u32 instance
{
struct dapf_slice want[T8132_DAPF_SLICES], had[T8132_DAPF_SLICES];
u32 count;
const struct dapf_t8110_config *config = dapf_t8132_config(path, node, instance, &count);
const struct dapf_t8110_config *config = dapf_t8110_slices(path, node, instance, &count);

if (!config)
return -1;
Expand Down Expand Up @@ -410,7 +413,7 @@ int dapf_t8132_windows(const char *path, int index, struct dapf_window *out, int
dapf_select_t8132(path, index, node, dart_path, &instance) != 1)
return -1;

const struct dapf_t8110_config *config = dapf_t8132_config(path, node, instance, &count);
const struct dapf_t8110_config *config = dapf_t8110_slices(path, node, instance, &count);
if (!config)
return -1;

Expand Down Expand Up @@ -492,7 +495,7 @@ int dapf_t8132_ranges(const char *path, u32 r0, u32 r4, u32 r20, u64 *ranges, in
if (index < 0 || dapf_select_t8132(path, index, node, dart_path, &instance) != 1)
return -1;

const struct dapf_t8110_config *config = dapf_t8132_config(path, node, instance, &count);
const struct dapf_t8110_config *config = dapf_t8110_slices(path, node, instance, &count);
if (!config || !count || count > (u32)max)
return -1;

Expand All @@ -509,6 +512,32 @@ int dapf_t8132_ranges(const char *path, u32 r0, u32 r4, u32 r20, u64 *ranges, in
return count;
}

/*
* Return the raw inclusive [start, end] slices of a T8110 DART's dapf-instance
* property (up to max entries), or -1 on missing or malformed ADT metadata.
*/
int dapf_t8110_ranges(const char *path, u32 instance, struct dapf_window *out, int max)
{
int node = adt_path_offset(adt, path);
u32 count = 0;

if (node < 0 || max <= 0) {
printf("dapf: Missing ADT node %s for dapf-instance-%u\n", path, instance);
return -1;
}

const struct dapf_t8110_config *config = dapf_t8110_slices(path, node, instance, &count);
if (!config || (int)count > max)
return -1;

for (u32 i = 0; i < count; i++) {
struct dapf_t8110_config entry;
memcpy(&entry, &config[i], sizeof(entry));
out[i] = (struct dapf_window){.start = entry.start, .end = entry.end};
}
return (int)count;
}

static bool dapf_is_j614s(void)
{
return chip_id == T6040 && board_id == 4 && adt_is_compatible(adt, 0, "J614sAP");
Expand Down
3 changes: 3 additions & 0 deletions src/dapf.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,11 @@ struct dapf_window {
u64 end;
};

#define DAPF_T8110_MAX_SLICES 16

int dapf_init_t8132_halted(const char *path, int index);
int dapf_t8132_windows(const char *path, int index, struct dapf_window *out, int max);
int dapf_t8132_ranges(const char *path, u32 r0, u32 r4, u32 r20, u64 *ranges, int max);
int dapf_t8110_ranges(const char *path, u32 instance, struct dapf_window *out, int max);

#endif
41 changes: 38 additions & 3 deletions src/isp.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,38 @@
#include "utils.h"
#include "xnuboot.h"

#include "libfdt/libfdt.h"

/*
* Loader ISP power-up and heap carveout apply only when the kernel tree enables an
* `isp` node that has neither firmware segment placeholders nor a kernel-managed ISP
* compatible (apple,t8132-isp, apple,t6041-isp on T6040/T6041, apple,t6050-isp).
*/
bool isp_fdt_needs_init(const void *fdt)
{
static const char *const kernel_owned[] = {
"apple,t8132-isp",
"apple,t6041-isp",
"apple,t6050-isp",
};
if (!fdt || fdt_check_header(fdt) != 0)
return false;
int isp = fdt_path_offset(fdt, "isp");
if (isp < 0)
return false;
const char *status = fdt_getprop(fdt, isp, "status", NULL);
if (status && strcmp(status, "okay") && strcmp(status, "ok"))
return false;
int resv = fdt_path_offset(fdt, "/reserved-memory");
if (resv >= 0 && fdt_subnode_offset(fdt, resv, "isp-firmware-text") >= 0 &&
fdt_subnode_offset(fdt, resv, "isp-firmware-data") >= 0)
return false;
for (size_t i = 0; i < ARRAY_SIZE(kernel_owned); i++)
if (!fdt_node_check_compatible(fdt, isp, kernel_owned[i]))
return false;
return true;
}

#define ISP_ASC_VERSION 0x1800000

#define ISP_VER_T8103 0xb0090
Expand Down Expand Up @@ -56,6 +88,11 @@ static const struct {
static bool isp_initialized = false;
static u64 heap_phys, heap_iova, heap_size;

void isp_reset(void)
{
isp_initialized = false;
}

int isp_get_heap(u64 *phys, u64 *iova, u64 *size)
{
if (!isp_initialized)
Expand Down Expand Up @@ -95,9 +132,7 @@ static int isp_firmware_end(const struct adt_segment_ranges *segments, u32 lengt

int isp_init(void)
{
/* The T6050 kernel owns power-up. Its handoff only reserves memory. */
if (chip_id == T6050)
return 0;
isp_initialized = false;

int err = -1;
/* T8142 takes the T8140 (ISP17a) path throughout. */
Expand Down
2 changes: 2 additions & 0 deletions src/isp.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

#include "types.h"

void isp_reset(void);
bool isp_fdt_needs_init(const void *fdt);
int isp_init(void);
int isp_get_heap(u64 *phys, u64 *iova, u64 *size);
u64 isp_iova_base(void);
Expand Down
Loading
Loading