diff --git a/rust/src/adt.rs b/rust/src/adt.rs index e1b9c516f..54170a86a 100644 --- a/rust/src/adt.rs +++ b/rust/src/adt.rs @@ -718,7 +718,7 @@ unsafe extern "C" { } #[no_mangle] -pub unsafe extern "C" fn adt_check_header(_dt: *const c_void) -> c_int { +pub unsafe extern "C" fn adt_check_header() -> c_int { unsafe { match ADTNode::from_ptr(adt as *const ADTNode) { Ok(_) => 0, @@ -728,7 +728,7 @@ pub unsafe extern "C" fn adt_check_header(_dt: *const c_void) -> c_int { } #[no_mangle] -pub unsafe extern "C" fn adt_first_property_offset(_dt: *const c_void, offset: c_int) -> c_int { +pub unsafe extern "C" fn adt_first_property_offset(offset: c_int) -> c_int { let ptr: *const ADTNode = unsafe { adt.add(offset as usize) as *const ADTNode }; let p: *const u8 = ADTNode::from_ptr(ptr) @@ -743,7 +743,7 @@ pub unsafe extern "C" fn adt_first_property_offset(_dt: *const c_void, offset: c // This function has load-bearing UB on the C side... The sound Rust equivalent // breaks this. Recreate the UB here rather than call the new Rust function. #[no_mangle] -pub unsafe extern "C" fn adt_next_property_offset(_dt: *const c_void, offset: c_int) -> c_int { +pub unsafe extern "C" fn adt_next_property_offset(offset: c_int) -> c_int { let ptr: usize = unsafe { adt.add(offset as usize) as usize }; let p = ADTProperty::from_ptr(ptr).unwrap(); unsafe { @@ -756,34 +756,33 @@ pub unsafe extern "C" fn adt_next_property_offset(_dt: *const c_void, offset: c_ } #[no_mangle] -pub unsafe extern "C" fn adt_first_child_offset(_dt: *const c_void, offset: c_int) -> c_int { +pub unsafe extern "C" fn adt_first_child_offset(offset: c_int) -> c_int { let ptr: *const ADTNode = unsafe { adt.add(offset as usize) as *const ADTNode }; let n = ADTNode::from_ptr(ptr).unwrap(); unsafe { n.first_child().unwrap().as_ptr().sub(adt as usize) as c_int } } #[no_mangle] -pub unsafe extern "C" fn adt_next_sibling_offset(_dt: *const c_void, offset: c_int) -> c_int { +pub unsafe extern "C" fn adt_next_sibling_offset(offset: c_int) -> c_int { let ptr: *const ADTNode = unsafe { adt.add(offset as usize) as *const ADTNode }; let n = ADTNode::from_ptr(ptr).unwrap(); unsafe { n.next_sibling().unwrap().as_ptr().sub(adt as usize) as c_int } } #[no_mangle] -pub unsafe extern "C" fn adt_get_child_count(_dt: *const c_void, offset: c_int) -> c_int { +pub unsafe extern "C" fn adt_get_child_count(offset: c_int) -> c_int { let ptr: *const ADTNode = unsafe { adt.add(offset as usize) as *const ADTNode }; ADTNode::from_ptr(ptr).unwrap().child_count as c_int } #[no_mangle] -pub unsafe extern "C" fn adt_get_property_count(_dt: *const c_void, offset: c_int) -> c_int { +pub unsafe extern "C" fn adt_get_property_count(offset: c_int) -> c_int { let ptr: *const ADTNode = unsafe { adt.add(offset as usize) as *const ADTNode }; ADTNode::from_ptr(ptr).unwrap().property_count as c_int } #[no_mangle] pub unsafe extern "C" fn adt_get_property_by_offset( - _dt: *const c_void, offset: c_int, ) -> *const c_void { let ptr: usize = unsafe { adt.add(offset as usize) as usize }; @@ -795,7 +794,6 @@ pub unsafe extern "C" fn adt_get_property_by_offset( #[no_mangle] pub unsafe extern "C" fn adt_get_property( - _dt: *const c_void, offset: c_int, name: *const c_char, ) -> *const c_void { @@ -811,7 +809,6 @@ pub unsafe extern "C" fn adt_get_property( #[no_mangle] pub unsafe extern "C" fn adt_getprop( - _dt: *const c_void, offset: c_int, name: *const c_char, lenp: *mut c_uint, @@ -833,7 +830,6 @@ pub unsafe extern "C" fn adt_getprop( #[no_mangle] pub unsafe extern "C" fn adt_getprop_by_offset( - _dt: *const c_void, offset: c_int, namep: *mut *const c_char, lenp: *mut c_uint, @@ -857,7 +853,6 @@ pub unsafe extern "C" fn adt_getprop_by_offset( #[no_mangle] pub unsafe extern "C" fn adt_setprop( - _dt: *const c_void, offset: c_int, name: *const c_char, val: *const c_void, @@ -890,7 +885,6 @@ pub unsafe extern "C" fn adt_setprop( #[no_mangle] pub unsafe extern "C" fn adt_subnode_offset( - _dt: *const c_void, offset: c_int, name: *const c_char, ) -> c_int { @@ -910,7 +904,6 @@ pub unsafe extern "C" fn adt_subnode_offset( #[no_mangle] pub unsafe extern "C" fn adt_is_compatible( - _dt: *const c_void, offset: c_int, compat: *const c_char, ) -> bool { @@ -924,7 +917,6 @@ pub unsafe extern "C" fn adt_is_compatible( #[no_mangle] pub unsafe extern "C" fn adt_is_compatible_at( - _dt: *const c_void, offset: c_int, compat: *const c_char, index: usize, @@ -935,14 +927,13 @@ pub unsafe extern "C" fn adt_is_compatible_at( } #[no_mangle] -pub unsafe extern "C" fn adt_get_name(_dt: *const c_void, offset: c_int) -> *const c_char { +pub unsafe extern "C" fn adt_get_name(offset: c_int) -> *const c_char { let ptr: *const ADTNode = unsafe { adt.add(offset as usize) as *const ADTNode }; ADTNode::from_ptr(ptr).unwrap().name().unwrap().as_ptr() as *const c_char } #[no_mangle] pub unsafe extern "C" fn adt_getprop_copy( - _dt: *const c_void, offset: c_int, name: *const c_char, out: *mut c_void, @@ -975,7 +966,6 @@ pub unsafe extern "C" fn adt_getprop_copy( #[no_mangle] pub unsafe extern "C" fn adt_path_offset_trace( - _dt: *const c_void, path: *const c_char, offsets: *mut i32, ) -> c_int { @@ -1007,7 +997,7 @@ pub unsafe extern "C" fn adt_path_offset_trace( } #[no_mangle] -pub unsafe extern "C" fn adt_path_offset(_dt: *const c_void, path: *const c_char) -> c_int { +pub unsafe extern "C" fn adt_path_offset(path: *const c_char) -> c_int { let strpath: &str = unsafe { CStr::from_ptr(path).to_str().unwrap() }; match ADTNode::from_path(strpath) { @@ -1018,7 +1008,6 @@ pub unsafe extern "C" fn adt_path_offset(_dt: *const c_void, path: *const c_char #[no_mangle] pub unsafe extern "C" fn adt_get_reg( - _dt: *const c_void, offsets: *mut i32, prop: *const c_char, i: c_int, diff --git a/src/adt.h b/src/adt.h index 6bea107d0..920b372fd 100644 --- a/src/adt.h +++ b/src/adt.h @@ -18,7 +18,7 @@ struct adt_node_hdr { u32 child_count; }; -#define ADT_PROP(adt, offset) ((const struct adt_property *)(((u8 *)(adt)) + (offset))) +#define ADT_PROP(offset) ((const struct adt_property *)(((u8 *)(adt)) + (offset))) /* This API is designed to match libfdt's read-only API */ @@ -26,53 +26,53 @@ struct adt_node_hdr { u32 adt_get_size(void); /* Basic sanity check */ -int adt_check_header(const void *adt); +int adt_check_header(void); -int adt_get_property_count(const void *adt, int offset); +int adt_get_property_count(int offset); -int adt_first_property_offset(const void *adt, int offset); +int adt_first_property_offset(int offset); -int adt_next_property_offset(const void *adt, int offset); +int adt_next_property_offset(int offset); -const struct adt_property *adt_get_property_by_offset(const void *adt, int offset); +const struct adt_property *adt_get_property_by_offset(int offset); -int adt_get_child_count(const void *adt, int offset); +int adt_get_child_count(int offset); -int adt_first_child_offset(const void *adt, int offset); -int adt_next_sibling_offset(const void *adt, int offset); +int adt_first_child_offset(int offset); +int adt_next_sibling_offset(int offset); -int adt_subnode_offset(const void *adt, int parentoffset, const char *name); -int adt_path_offset(const void *adt, const char *path); -int adt_path_offset_trace(const void *adt, const char *path, int *offsets); +int adt_subnode_offset(int parentoffset, const char *name); +int adt_path_offset(const char *path); +int adt_path_offset_trace(const char *path, int *offsets); -const char *adt_get_name(const void *adt, int nodeoffset); -const struct adt_property *adt_get_property(const void *adt, int nodeoffset, const char *name); -const void *adt_getprop_by_offset(const void *adt, int offset, const char **namep, u32 *lenp); -const void *adt_getprop(const void *adt, int nodeoffset, const char *name, u32 *lenp); -int adt_setprop(void *adt, int nodeoffset, const char *name, void *value, size_t len); -int adt_getprop_copy(const void *adt, int nodeoffset, const char *name, void *out, size_t len); +const char *adt_get_name(int nodeoffset); +const struct adt_property *adt_get_property(int nodeoffset, const char *name); +const void *adt_getprop_by_offset(int offset, const char **namep, u32 *lenp); +const void *adt_getprop(int nodeoffset, const char *name, u32 *lenp); +int adt_setprop(int nodeoffset, const char *name, void *value, size_t len); +int adt_getprop_copy(int nodeoffset, const char *name, void *out, size_t len); -#define ADT_GETPROP(adt, nodeoffset, name, val) \ - adt_getprop_copy(adt, nodeoffset, name, (val), sizeof(*(val))) +#define ADT_GETPROP(nodeoffset, name, val) \ + adt_getprop_copy(nodeoffset, name, (val), sizeof(*(val))) -#define ADT_GETPROP_ARRAY(adt, nodeoffset, name, arr) \ - adt_getprop_copy(adt, nodeoffset, name, (arr), sizeof(arr)) +#define ADT_GETPROP_ARRAY(nodeoffset, name, arr) \ + adt_getprop_copy(nodeoffset, name, (arr), sizeof(arr)) -int adt_get_reg(const void *adt, int *path, const char *prop, int idx, u64 *addr, u64 *size); -bool adt_is_compatible(const void *adt, int nodeoffset, const char *compat); -bool adt_is_compatible_at(const void *adt, int nodeoffset, const char *compat, size_t index); +int adt_get_reg(int *path, const char *prop, int idx, u64 *addr, u64 *size); +bool adt_is_compatible(int nodeoffset, const char *compat); +bool adt_is_compatible_at(int nodeoffset, const char *compat, size_t index); -#define ADT_FOREACH_CHILD(adt, node) \ - for (int _child_count = adt_get_child_count(adt, node); _child_count; _child_count = 0) \ - for (node = adt_first_child_offset(adt, node); _child_count--; \ - node = adt_next_sibling_offset(adt, node)) +#define ADT_FOREACH_CHILD(node) \ + for (int _child_count = adt_get_child_count(node); _child_count; _child_count = 0) \ + for (node = adt_first_child_offset(node); _child_count--; \ + node = adt_next_sibling_offset(node)) -#define ADT_FOREACH_PROPERTY(adt, node, prop) \ - for (int _prop_count = adt_get_property_count(adt, node), \ - _poff = adt_first_property_offset(adt, node); \ +#define ADT_FOREACH_PROPERTY(node, prop) \ + for (int _prop_count = adt_get_property_count(node), \ + _poff = adt_first_property_offset(node); \ _prop_count; _prop_count = 0) \ - for (const struct adt_property *prop = ADT_PROP(adt, _poff); _prop_count--; \ - prop = ADT_PROP(adt, _poff = adt_next_property_offset(adt, _poff))) + for (const struct adt_property *prop = ADT_PROP(_poff); _prop_count--; \ + prop = ADT_PROP(_poff = adt_next_property_offset(_poff))) /* Common ADT properties */ struct adt_segment_ranges { diff --git a/src/afk.c b/src/afk.c index d8e239f48..b60fd1e97 100644 --- a/src/afk.c +++ b/src/afk.c @@ -5,6 +5,7 @@ #include "malloc.h" #include "string.h" #include "utils.h" +#include "adt.h" #include "dcp/parser.h" @@ -510,7 +511,10 @@ int afk_epic_command(afk_epic_ep_t *epic, int channel, u16 sub_type, void *txbuf msg.hdr.version = 2; msg.hdr.seq = epic->seq++; msg.sub.length = sizeof(msg.cmd); - msg.sub.version = 4; + if (adt_is_compatible(0, "J517AP")) + msg.sub.version = 3; + else + msg.sub.version = 4; msg.sub.category = CAT_COMMAND; msg.sub.type = sub_type; msg.sub.seq = 0; diff --git a/src/aic.c b/src/aic.c index e7f02d49d..44a2c56ec 100644 --- a/src/aic.c +++ b/src/aic.c @@ -46,7 +46,7 @@ struct aic *aic; static int aic23_init(int version, int node) { - int ret = ADT_GETPROP(adt, node, "aic-iack-offset", &aic->regs.event); + int ret = ADT_GETPROP(node, "aic-iack-offset", &aic->regs.event); if (ret < 0) { printf("AIC: failed to get property aic-iack-offset\n"); return ret; @@ -54,7 +54,7 @@ static int aic23_init(int version, int node) int32_t cap0_offset = aic->cap0_offset; if (cap0_offset == -1) { - ret = ADT_GETPROP(adt, node, "cap0-offset", &cap0_offset); + ret = ADT_GETPROP(node, "cap0-offset", &cap0_offset); if (ret < 0) { printf("AIC: failed to get property cap0-offset\n"); } @@ -65,7 +65,7 @@ static int aic23_init(int version, int node) int32_t maxnumirq_offset = aic->maxnumirq_offset; if (maxnumirq_offset == -1) { - ret = ADT_GETPROP(adt, node, "maxnumirq-offset", &maxnumirq_offset); + ret = ADT_GETPROP(node, "maxnumirq-offset", &maxnumirq_offset); if (ret < 0) { printf("AIC: failed to get property maxnumirq-offset\n"); } @@ -90,7 +90,7 @@ static int aic23_init(int version, int node) * AIC2, but fatal on AIC3. */ u32 config_base; - if (ADT_GETPROP(adt, node, "extint-baseaddress", &config_base) > 0) { + if (ADT_GETPROP(node, "extint-baseaddress", &config_base) > 0) { aic->regs.config = config_base; } @@ -112,11 +112,11 @@ static int aic23_init(int version, int node) off += sizeof(u32) * (aic->max_irq >> 5); /* HW_STATE */ /* Fill in the strides dynamically if we can */ - if (ADT_GETPROP(adt, node, "extintrcfg-stride", &aic->extintrcfg_stride) < 0) + if (ADT_GETPROP(node, "extintrcfg-stride", &aic->extintrcfg_stride) < 0) aic->extintrcfg_stride = off - start_off; - if (ADT_GETPROP(adt, node, "intmaskset-stride", &aic->intmaskset_stride) < 0) + if (ADT_GETPROP(node, "intmaskset-stride", &aic->intmaskset_stride) < 0) aic->intmaskset_stride = off - start_off; - if (ADT_GETPROP(adt, node, "intmaskclear-stride", &aic->intmaskclear_stride) < 0) + if (ADT_GETPROP(node, "intmaskclear-stride", &aic->intmaskclear_stride) < 0) aic->intmaskclear_stride = off - start_off; aic->regs.reg_size = aic->regs.event + 4; @@ -128,7 +128,7 @@ static int aic23_init(int version, int node) aic->intmaskclear_stride); u32 ext_intr_config_len; - const u8 *ext_intr_config = adt_getprop(adt, node, "aic-ext-intr-cfg", &ext_intr_config_len); + const u8 *ext_intr_config = adt_getprop(node, "aic-ext-intr-cfg", &ext_intr_config_len); if (ext_intr_config) { printf("AIC: Configuring %d external interrupts\n", ext_intr_config_len / 3); @@ -149,25 +149,25 @@ static int aic23_init(int version, int node) void aic_init(void) { int path[8]; - int node = adt_path_offset_trace(adt, "/arm-io/aic", path); + int node = adt_path_offset_trace("/arm-io/aic", path); if (node < 0) { printf("AIC node not found!\n"); return; } - if (adt_is_compatible(adt, node, "aic,1")) { + if (adt_is_compatible(node, "aic,1")) { aic = &aic1; - } else if (adt_is_compatible(adt, node, "aic,2")) { + } else if (adt_is_compatible(node, "aic,2")) { aic = &aic2; - } else if (adt_is_compatible(adt, node, "aic,3")) { + } else if (adt_is_compatible(node, "aic,3")) { aic = &aic3; } else { printf("AIC: Error: Unsupported version\n"); return; } - if (adt_get_reg(adt, path, "reg", 0, &aic->base, NULL)) { + if (adt_get_reg(path, "reg", 0, &aic->base, NULL)) { printf("Failed to get AIC reg property!\n"); return; } diff --git a/src/akf.c b/src/akf.c index a279aac49..a6b624400 100644 --- a/src/akf.c +++ b/src/akf.c @@ -50,14 +50,14 @@ struct akf_dev { akf_dev_t *akf_init(const char *path) { int akf_path[8]; - int node = adt_path_offset_trace(adt, path, akf_path); + int node = adt_path_offset_trace(path, akf_path); if (node < 0) { printf("akf: Error getting akf node %s\n", path); return NULL; } u64 base; - if (adt_get_reg(adt, akf_path, "reg", 0, &base, NULL) < 0) { + if (adt_get_reg(akf_path, "reg", 0, &base, NULL) < 0) { printf("akf: Error getting akf %s base address.\n", path); return NULL; } @@ -67,9 +67,9 @@ akf_dev_t *akf_init(const char *path) return NULL; akf->cpu_base = base; - if (adt_is_compatible(adt, node, "iop,s5l8960x")) { + if (adt_is_compatible(node, "iop,s5l8960x")) { akf->base = base + AKF_V1_OFF; - } else if (adt_is_compatible(adt, node, "iop,s8000")) { + } else if (adt_is_compatible(node, "iop,s8000")) { akf->base = base + AKF_V2_OFF; } else { printf("akf: Unsupported compatible\n"); @@ -91,7 +91,7 @@ static bool akf_get_fw_region_new(int fw_node, u64 *phys, u64 *iova, u64 *size) const struct adt_segment_ranges *seg; u32 segments_len; - seg = adt_getprop(adt, fw_node, "segment-ranges", &segments_len); + seg = adt_getprop(fw_node, "segment-ranges", &segments_len); if (!seg) { printf("akf: No segment-ranges property\n"); return false; @@ -128,12 +128,12 @@ static bool akf_get_fw_region_new(int fw_node, u64 *phys, u64 *iova, u64 *size) /* Old style with region-base and region-size; iOS 10 */ static bool akf_get_fw_region_old(int fw_node, u64 *phys, u64 *iova, u64 *size) { - if (ADT_GETPROP(adt, fw_node, "region-base", phys) < 0) { + if (ADT_GETPROP(fw_node, "region-base", phys) < 0) { printf("akf: Could not get region-base property\n"); return false; } - if (ADT_GETPROP(adt, fw_node, "region-size", size) < 0) { + if (ADT_GETPROP(fw_node, "region-size", size) < 0) { printf("akf: Could not get region-size property\n"); return false; } @@ -148,14 +148,14 @@ static bool akf_get_fw_region_old(int fw_node, u64 *phys, u64 *iova, u64 *size) bool akf_map_preloaded_fw(akf_dev_t *akf) { - int fw_node = adt_first_child_offset(adt, akf->iop_node); + int fw_node = adt_first_child_offset(akf->iop_node); if (!fw_node) { printf("akf: IOP Firmware node not found\n"); return false; } int pre_loaded; - if (ADT_GETPROP(adt, fw_node, "pre-loaded", &pre_loaded) < 0) { + if (ADT_GETPROP(fw_node, "pre-loaded", &pre_loaded) < 0) { printf("akf: Could not get pre-loaded property\n"); return false; } diff --git a/src/asc.c b/src/asc.c index d9e25b445..95f8f3a63 100644 --- a/src/asc.c +++ b/src/asc.c @@ -173,14 +173,14 @@ const struct asc_ops t8015_ops = { asc_dev_t *asc_init(const char *path) { int asc_path[8]; - int node = adt_path_offset_trace(adt, path, asc_path); + int node = adt_path_offset_trace(path, asc_path); if (node < 0) { printf("asc: Error getting ASC node %s\n", path); return NULL; } u64 base; - if (adt_get_reg(adt, asc_path, "reg", 0, &base, NULL) < 0) { + if (adt_get_reg(asc_path, "reg", 0, &base, NULL) < 0) { printf("asc: Error getting ASC %s base address.\n", path); return NULL; } @@ -189,25 +189,25 @@ asc_dev_t *asc_init(const char *path) if (!asc) return NULL; - if (adt_is_compatible(adt, node, "iop-pmp,t8015") || - adt_is_compatible(adt, node, "iop,t8015")) { + if (adt_is_compatible(node, "iop-pmp,t8015") || + adt_is_compatible(node, "iop,t8015")) { // there is also a iop-gfx,t8015 but how that works is unknown asc->base = base + 0x8000; asc->ops = &t8015_ops; - if (adt_get_reg(adt, asc_path, "reg", 2, (u64 *)&asc->cpu_base, NULL) < 0) + if (adt_get_reg(asc_path, "reg", 2, (u64 *)&asc->cpu_base, NULL) < 0) asc->cpu_base = 0; - } else if (adt_is_compatible(adt, node, "iop-ans2,t8015")) { + } else if (adt_is_compatible(node, "iop-ans2,t8015")) { asc->base = base + 0x8000; asc->ops = &t8015_ans2_ops; - if (adt_get_reg(adt, asc_path, "reg", 1, (u64 *)&asc->cpu_base, NULL) < 0) { + if (adt_get_reg(asc_path, "reg", 1, (u64 *)&asc->cpu_base, NULL) < 0) { printf("asc: Error getting T8015 ANS2 %s CPU base address.\n", path); return NULL; } - } else if (adt_is_compatible(adt, node, "iop,ascwrap-v4") || - adt_is_compatible(adt, node, "iop-sep,ascwrap-v4")) { + } else if (adt_is_compatible(node, "iop,ascwrap-v4") || + adt_is_compatible(node, "iop-sep,ascwrap-v4")) { asc->cpu_base = base; asc->base = base + 0x8000; asc->ops = &ascwrap_v4_ops; @@ -216,7 +216,7 @@ asc_dev_t *asc_init(const char *path) goto out_free; } - asc->iop_node = adt_first_child_offset(adt, node); + asc->iop_node = adt_first_child_offset(node); return asc; @@ -257,7 +257,11 @@ bool asc_can_recv(asc_dev_t *asc) bool asc_recv(asc_dev_t *asc, struct asc_message *msg) { - return asc->ops->recv(asc, msg); + bool ret = asc->ops->recv(asc, msg); + + dprintf("received msg: %lx %x\n", msg->msg0, msg->msg1); + + return ret; } bool asc_recv_timeout(asc_dev_t *asc, struct asc_message *msg, u32 delay_usec) @@ -277,5 +281,7 @@ bool asc_can_send(asc_dev_t *asc) bool asc_send(asc_dev_t *asc, const struct asc_message *msg) { + dprintf("sent msg: %lx %x\n", msg->msg0, msg->msg1); + return asc->ops->send(asc, msg); } diff --git a/src/chainload.c b/src/chainload.c index 1dd7c689b..3428d8c11 100644 --- a/src/chainload.c +++ b/src/chainload.c @@ -37,13 +37,13 @@ int chainload_image(void *image, size_t size, char **vars, size_t var_cnt) // SEPFW size_t sepfw_off = image_size; - int anode = adt_path_offset(adt, "/chosen/memory-map"); + int anode = adt_path_offset("/chosen/memory-map"); if (anode < 0) { printf("chainload: /chosen/memory-map not found\n"); return -1; } u64 sepfw[2]; - if (ADT_GETPROP_ARRAY(adt, anode, "SEPFW", sepfw) < 0) { + if (ADT_GETPROP_ARRAY(anode, "SEPFW", sepfw) < 0) { printf("chainload: Failed to find SEPFW\n"); return -1; } @@ -83,7 +83,7 @@ int chainload_image(void *image, size_t size, char **vars, size_t var_cnt) // Adjust ADT SEPFW address sepfw[0] = new_base + sepfw_off; - if (adt_setprop(adt, anode, "SEPFW", &sepfw, sizeof(sepfw)) < 0) { + if (adt_setprop(anode, "SEPFW", &sepfw, sizeof(sepfw)) < 0) { printf("chainload: Failed to set SEPFW prop\n"); free(new_image); return -1; diff --git a/src/clk.c b/src/clk.c index 41b2d3039..6e0a38927 100644 --- a/src/clk.c +++ b/src/clk.c @@ -14,7 +14,7 @@ void clk_set_mca_muxes(void) { int path[8]; - int node = adt_path_offset_trace(adt, "/arm-io/mca-switch", path); + int node = adt_path_offset_trace("/arm-io/mca-switch", path); if (node < 0) { printf("mca-switch node not found!\n"); @@ -22,7 +22,7 @@ void clk_set_mca_muxes(void) } u64 mca_clk_base, mca_clk_size; - if (adt_get_reg(adt, path, "reg", 2, &mca_clk_base, &mca_clk_size)) { + if (adt_get_reg(path, "reg", 2, &mca_clk_base, &mca_clk_size)) { printf("Failed to get mca-switch reg property!\n"); return; } diff --git a/src/cpufreq.c b/src/cpufreq.c index dc93efc59..a3bbaa3c0 100644 --- a/src/cpufreq.c +++ b/src/cpufreq.c @@ -220,12 +220,12 @@ int cpufreq_init_cluster(const struct cluster_t *cluster, const struct feat_t *f int pmgr_path[8]; u64 pmgr_reg; - if (adt_path_offset_trace(adt, "/arm-io/pmgr", pmgr_path) < 0) { + if (adt_path_offset_trace("/arm-io/pmgr", pmgr_path) < 0) { printf("Error getting /arm-io/pmgr node\n"); return -1; } - if (adt_get_reg(adt, pmgr_path, "reg", 0, &pmgr_reg, NULL) < 0) { + if (adt_get_reg(pmgr_path, "reg", 0, &pmgr_reg, NULL) < 0) { printf("Error getting /arm-io/pmgr regs\n"); return -1; } diff --git a/src/dapf.c b/src/dapf.c index 3b4b773dc..18037c796 100644 --- a/src/dapf.c +++ b/src/dapf.c @@ -23,7 +23,7 @@ static int dapf_init_t8020(const char *path, u64 base, int node) { u32 length; const char *prop = "filter-data-instance-0"; - const struct dapf_t8020_config *config = adt_getprop(adt, node, prop, &length); + const struct dapf_t8020_config *config = adt_getprop(node, prop, &length); if (!config || !length || (length % sizeof(*config)) != 0) { printf("dapf: Error getting ADT node %s property %s.\n", path, prop); @@ -103,7 +103,7 @@ static int dapf_init_t8110(const char *path, u64 base, int node) { u32 length; const char *prop = "dapf-instance-0"; - const void *config = adt_getprop(adt, node, prop, &length); + const void *config = adt_getprop(node, prop, &length); if (!config || !length) { printf("dapf: Error getting ADT node %s property %s.\n", path, prop); @@ -127,29 +127,29 @@ int dapf_init(const char *path, int index) { int ret; int dart_path[8]; - int node = adt_path_offset_trace(adt, path, dart_path); + int node = adt_path_offset_trace(path, dart_path); if (node < 0) { printf("dapf: Error getting DAPF %s node.\n", path); return -1; } u32 pwr; - if (!adt_getprop(adt, node, "clock-gates", &pwr)) + if (!adt_getprop(node, "clock-gates", &pwr)) pwr = 0; if (pwr && (pmgr_adt_power_enable(path) < 0)) return -1; u64 base; - if (adt_get_reg(adt, dart_path, "reg", index, &base, NULL) < 0) { + if (adt_get_reg(dart_path, "reg", index, &base, NULL) < 0) { printf("dapf: Error getting DAPF %s base address.\n", path); return -1; } - if (adt_is_compatible(adt, node, "dart,t8020")) { + if (adt_is_compatible(node, "dart,t8020")) { ret = dapf_init_t8020(path, base, node); - } else if (adt_is_compatible(adt, node, "dart,t6000")) { + } else if (adt_is_compatible(node, "dart,t6000")) { ret = dapf_init_t8020(path, base, node); - } else if (adt_is_compatible(adt, node, "dart,t8110")) { + } else if (adt_is_compatible(node, "dart,t8110")) { ret = dapf_init_t8110(path, base, node); } else { printf("dapf: DAPF %s at 0x%lx is of an unknown type\n", path, base); @@ -182,7 +182,7 @@ int dapf_init_all(void) struct entry *entry = dapf_entries; while (entry->path != NULL) { - if (adt_path_offset(adt, entry->path) < 0) { + if (adt_path_offset(entry->path) < 0) { entry++; continue; } diff --git a/src/dart.c b/src/dart.c index abb020110..5e695253e 100644 --- a/src/dart.c +++ b/src/dart.c @@ -277,14 +277,14 @@ dart_dev_t *dart_init(uintptr_t base, u8 device, bool keep_pts, enum dart_type_t dart_dev_t *dart_init_adt(const char *path, int instance, int device, bool keep_pts) { int dart_path[8]; - int node = adt_path_offset_trace(adt, path, dart_path); + int node = adt_path_offset_trace(path, dart_path); if (node < 0) { printf("dart: Error getting DART node %s\n", path); return NULL; } u64 base; - if (adt_get_reg(adt, dart_path, "reg", instance, &base, NULL) < 0) { + if (adt_get_reg(dart_path, "reg", instance, &base, NULL) < 0) { printf("dart: Error getting DART %s base address.\n", path); return NULL; } @@ -292,13 +292,13 @@ dart_dev_t *dart_init_adt(const char *path, int instance, int device, bool keep_ enum dart_type_t type; const char *type_s; - if (adt_is_compatible(adt, node, "dart,t8020")) { + if (adt_is_compatible(node, "dart,t8020")) { type = DART_T8020; type_s = "t8020"; - } else if (adt_is_compatible(adt, node, "dart,t6000")) { + } else if (adt_is_compatible(node, "dart,t6000")) { type = DART_T6000; type_s = "t6000"; - } else if (adt_is_compatible(adt, node, "dart,t8110")) { + } else if (adt_is_compatible(node, "dart,t8110")) { type = DART_T8110; type_s = "t8110"; } else { @@ -314,14 +314,14 @@ dart_dev_t *dart_init_adt(const char *path, int instance, int device, bool keep_ printf("dart: dart %s at 0x%lx is a %s%s\n", path, base, type_s, dart->locked ? " (locked)" : ""); - if (adt_getprop(adt, node, "real-time", NULL)) { + if (adt_getprop(node, "real-time", NULL)) { for (int i = 0; i < dart->params->ttbr_count; i++) { printf("dart: dart %s.%d.%d L1 %d is real-time at %p\n", path, instance, device, i, dart->l1[i]); } } u32 len; - const void *prop = adt_getprop(adt, node, "vm-base", &len); + const void *prop = adt_getprop(node, "vm-base", &len); if (prop) { if (len == sizeof(u32)) { u32 tmp; @@ -344,22 +344,22 @@ dart_dev_t *dart_init_adt(const char *path, int instance, int device, bool keep_ void dart_lock_adt(const char *path, int instance) { int dart_path[8]; - int node = adt_path_offset_trace(adt, path, dart_path); + int node = adt_path_offset_trace(path, dart_path); if (node < 0) { printf("dart: Error getting DART node %s\n", path); return; } u64 base; - if (adt_get_reg(adt, dart_path, "reg", instance, &base, NULL) < 0) { + if (adt_get_reg(dart_path, "reg", instance, &base, NULL) < 0) { printf("dart: Error getting DART %s base address.\n", path); return; } - if (adt_is_compatible(adt, node, "dart,t8020") || adt_is_compatible(adt, node, "dart,t6000")) { + if (adt_is_compatible(node, "dart,t8020") || adt_is_compatible(node, "dart,t6000")) { if (!(read32(base + DART_T8020_CONFIG) & DART_T8020_CONFIG_LOCK)) set32(base + DART_T8020_CONFIG, DART_T8020_CONFIG_LOCK); - } else if (adt_is_compatible(adt, node, "dart,t8110")) { + } else if (adt_is_compatible(node, "dart,t8110")) { if (!(read32(base + DART_T8110_PROTECT) & DART_T8110_PROTECT_TTBR_TCR)) set32(base + DART_T8110_PROTECT, DART_T8110_PROTECT_TTBR_TCR); } else { @@ -410,7 +410,7 @@ dart_dev_t *dart_init_fdt(void *dt, u32 phandle, int device, bool keep_pts) int dart_setup_pt_region(dart_dev_t *dart, const char *path, int device, u64 vm_base) { - int node = adt_path_offset(adt, path); + int node = adt_path_offset(path); if (node < 0) { printf("dart: Error getting DART node %s\n", path); return -1; @@ -420,7 +420,7 @@ int dart_setup_pt_region(dart_dev_t *dart, const char *path, int device, u64 vm_ char l2_tt_str[24]; snprintf(l2_tt_str, sizeof(l2_tt_str), "l2-tt-%d", device); - const struct adt_property *pt_region = adt_get_property(adt, node, pt_region_str); + const struct adt_property *pt_region = adt_get_property(node, pt_region_str); if (pt_region && pt_region->size == 16) { u64 region[2]; memcpy(region, pt_region->value, sizeof(region)); @@ -481,7 +481,7 @@ int dart_setup_pt_region(dart_dev_t *dart, const char *path, int device, u64 vm_ } u64 l2_tt[2] = {region[0], 2}; - int ret = adt_setprop(adt, node, l2_tt_str, &l2_tt, sizeof(l2_tt)); + int ret = adt_setprop(node, l2_tt_str, &l2_tt, sizeof(l2_tt)); if (ret < 0) { printf("dart: failed to update '%s/%s'\n", path, l2_tt_str); } diff --git a/src/dcp.c b/src/dcp.c index 16b0225cf..f5e8a9940 100644 --- a/src/dcp.c +++ b/src/dcp.c @@ -27,7 +27,7 @@ static u32 dcp_die; static int dcp_hdmi_dptx_init(dcp_dev_t *dcp, const display_config_t *cfg) { - int node = adt_path_offset(adt, cfg->dp2hdmi_gpio); + int node = adt_path_offset(cfg->dp2hdmi_gpio); if (node < 0) { printf("dcp: failed to find dp2hdmi-gpio node '%s'\n", cfg->dp2hdmi_gpio); return -1; @@ -35,12 +35,12 @@ static int dcp_hdmi_dptx_init(dcp_dev_t *dcp, const display_config_t *cfg) struct adt_function_smc_gpio dp2hdmi_pwr, hdmi_pwr; int err = - adt_getprop_copy(adt, node, "function-dp2hdmi_pwr_en", &dp2hdmi_pwr, sizeof(dp2hdmi_pwr)); + adt_getprop_copy(node, "function-dp2hdmi_pwr_en", &dp2hdmi_pwr, sizeof(dp2hdmi_pwr)); if (err < 0) printf("dcp: failed to get dp2hdmi_pwr_en gpio\n"); else dcp->dp2hdmi_pwr_gpio = dp2hdmi_pwr.gpio; - err = adt_getprop_copy(adt, node, "function-hdmi_pwr_en", &hdmi_pwr, sizeof(hdmi_pwr)); + err = adt_getprop_copy(node, "function-hdmi_pwr_en", &hdmi_pwr, sizeof(hdmi_pwr)); if (err < 0) printf("dcp: failed to get hdmi_pwr_en gpio\n"); else @@ -109,21 +109,21 @@ int dcp_work(dcp_dev_t *dcp) static int dcp_create_firmware_mappings(const display_config_t *cfg, dcp_dev_t *dcp) { int created = 0; - int dcp_node = adt_path_offset(adt, cfg->dcp); - int node = adt_first_child_offset(adt, dcp_node); + int dcp_node = adt_path_offset(cfg->dcp); + int node = adt_first_child_offset(dcp_node); if (node < 0) { printf("dcp: iop-dcp*-nub not found!\n"); return -1; } u64 asc_dram_mask; - if (ADT_GETPROP(adt, node, "asc-dram-mask", &asc_dram_mask) < 0) + if (ADT_GETPROP(node, "asc-dram-mask", &asc_dram_mask) < 0) asc_dram_mask = 0; const struct adt_segment_ranges *seg; u32 segments_len; - seg = adt_getprop(adt, node, "segment-ranges", &segments_len); + seg = adt_getprop(node, "segment-ranges", &segments_len); unsigned int count = segments_len / sizeof(*seg); for (unsigned int i = 0; i < count; i++) { @@ -161,13 +161,13 @@ dcp_dev_t *dcp_init(const display_config_t *cfg) mdelay(25); } - int dart_node = adt_path_offset(adt, cfg->dcp_dart); - int node = adt_first_child_offset(adt, dart_node); + int dart_node = adt_path_offset(cfg->dcp_dart); + int node = adt_first_child_offset(dart_node); if (node < 0) { printf("dcp: mapper-dcp* not found!\n"); return NULL; } - if (ADT_GETPROP(adt, node, "reg", &sid) < 0) { + if (ADT_GETPROP(node, "reg", &sid) < 0) { printf("dcp: failed to read dart stream ID!\n"); return NULL; } diff --git a/src/dcp/dptx_phy.c b/src/dcp/dptx_phy.c index 71ce82ec8..fa0fb8806 100644 --- a/src/dcp/dptx_phy.c +++ b/src/dcp/dptx_phy.c @@ -464,15 +464,15 @@ dptx_phy_t *dptx_phy_init(const char *phy_node, u32 dcp_index) enum dptx_type type; int adt_phy_path[8]; - int node = adt_path_offset_trace(adt, phy_node, adt_phy_path); + int node = adt_path_offset_trace(phy_node, adt_phy_path); if (node < 0) { printf("DPtx-phy: Error getting phy node %s\n", phy_node); return NULL; } - if (adt_is_compatible(adt, node, "dptx-phy,t8112")) + if (adt_is_compatible(node, "dptx-phy,t8112")) type = DPTX_PHY_T8112; - else if (adt_is_compatible(adt, node, "dptx-phy,t602x")) + else if (adt_is_compatible(node, "dptx-phy,t602x")) type = DPTX_PHY_T602X; else { printf("DPtx-phy: dptx-phy node %s is not compatible\n", phy_node); @@ -486,12 +486,12 @@ dptx_phy_t *dptx_phy_init(const char *phy_node, u32 dcp_index) phy->type = type; phy->dcp_index = dcp_index; - if (adt_get_reg(adt, adt_phy_path, "reg", 0, &phy->regs[0], NULL) < 0) { + if (adt_get_reg(adt_phy_path, "reg", 0, &phy->regs[0], NULL) < 0) { printf("DPtx-phy: failed to get %s.reg[0]\n", phy_node); goto out_err; } - if (adt_get_reg(adt, adt_phy_path, "reg", 1, &phy->regs[1], NULL) < 0) { + if (adt_get_reg(adt_phy_path, "reg", 1, &phy->regs[1], NULL) < 0) { printf("DPtx-phy: failed to get %s.reg[1]\n", phy_node); goto out_err; } diff --git a/src/dcp_iboot.c b/src/dcp_iboot.c index f5ec4e122..1c2b63531 100644 --- a/src/dcp_iboot.c +++ b/src/dcp_iboot.c @@ -55,6 +55,7 @@ enum IBootCmd { IBOOT_SWAP_BEGIN = 15, IBOOT_SWAP_SET_LAYER = 16, IBOOT_SWAP_END = 18, + IBOOT_SET_BACKLIGHT_NITS = 20, }; struct get_hpd_resp { @@ -293,3 +294,12 @@ int dcp_ib_swap_end(dcp_iboot_if_t *iboot) memset(iboot->txcmd.payload, 0, 12); return dcp_ib_cmd(iboot, IBOOT_SWAP_END, 12); } + +int dcp_ib_set_bightness(dcp_iboot_if_t *iboot, u32 nits) +{ + dcp_backlight_nits_t *bl = (void *)iboot->txcmd.payload; + bl->unk = 1; + bl->nits = nits & 0x7fffffff; + + return dcp_ib_cmd(iboot, IBOOT_SET_BACKLIGHT_NITS, sizeof(*bl)); +} diff --git a/src/dcp_iboot.h b/src/dcp_iboot.h index c0fc5225d..00612e048 100644 --- a/src/dcp_iboot.h +++ b/src/dcp_iboot.h @@ -95,6 +95,11 @@ typedef struct { u32 w, h, x, y; } PACKED dcp_rect_t; +typedef struct { + u32 unk; + u32 nits; +} PACKED dcp_backlight_nits_t; + dcp_iboot_if_t *dcp_ib_init(dcp_dev_t *dcp); int dcp_ib_shutdown(dcp_iboot_if_t *iboot); @@ -108,5 +113,6 @@ int dcp_ib_swap_begin(dcp_iboot_if_t *iboot); int dcp_ib_swap_set_layer(dcp_iboot_if_t *iboot, int layer_id, dcp_layer_t *layer, dcp_rect_t *src_rect, dcp_rect_t *dst_rect); int dcp_ib_swap_end(dcp_iboot_if_t *iboot); +int dcp_ib_set_bightness(dcp_iboot_if_t *iboot, u32 nits); #endif diff --git a/src/display.c b/src/display.c index e1a66c7e7..d3a5a5871 100644 --- a/src/display.c +++ b/src/display.c @@ -161,7 +161,7 @@ int display_get_vram(u64 *paddr, u64 *size) { int ret = 0; int adt_path[4]; - int node = adt_path_offset_trace(adt, "/vram", adt_path); + int node = adt_path_offset_trace("/vram", adt_path); if (node < 0) { printf("display: '/vram' not found\n"); @@ -173,7 +173,7 @@ int display_get_vram(u64 *paddr, u64 *size) pp++; adt_path[pp + 1] = 0; - ret = adt_get_reg(adt, adt_path, "reg", 0, paddr, size); + ret = adt_get_reg(adt_path, "reg", 0, paddr, size); if (ret < 0) { printf("display: failed to read /vram/reg\n"); return -1; @@ -247,16 +247,16 @@ const display_config_t *display_get_config(void) { const display_config_t *conf = NULL; - if (adt_is_compatible(adt, 0, "J473AP")) + if (adt_is_compatible(0, "J473AP")) conf = &display_config_m2; - else if (adt_is_compatible(adt, 0, "J474sAP") || adt_is_compatible(adt, 0, "J475cAP")) + else if (adt_is_compatible(0, "J474sAP") || adt_is_compatible(0, "J475cAP")) conf = &display_config_m2_pro_max; - else if (adt_is_compatible(adt, 0, "J180dAP") || adt_is_compatible(adt, 0, "J475dAP")) + else if (adt_is_compatible(0, "J180dAP") || adt_is_compatible(0, "J475dAP")) conf = &display_config_m2_ultra; else conf = &display_config_m1; - has_dcp = adt_path_offset(adt, conf->dcp) > 0; + has_dcp = adt_path_offset(conf->dcp) > 0; if (!has_dcp) { return NULL; } @@ -490,8 +490,9 @@ int display_configure(const char *config) if ((ret = dcp_ib_set_mode(iboot, &tbest, &cbest)) < 0) { printf("display: failed to set mode twice.\n"); return ret; - } - } + } + } + u64 fb_pa = cur_boot_args.video.base; u64 tmp_dva = 0; @@ -520,7 +521,7 @@ int display_configure(const char *config) } // Swap! - u32 stride = tbest.width * 4; + u32 stride = ((tbest.width * 4) + 63) & 0xffffffc0; ret = display_swap(tmp_dva, stride, tbest.width, tbest.height); if (ret < 0) return ret; @@ -543,24 +544,24 @@ int display_configure(const char *config) /* update ADT with the physical address of the new framebuffer */ u64 fb_reg[2] = {fb_pa, size}; - int node = adt_path_offset(adt, "vram"); + int node = adt_path_offset("vram"); if (node >= 0) { - // TODO: adt_set_reg(adt, node, "vram", fb_pa, size);? - ret = adt_setprop(adt, node, "reg", &fb_reg, sizeof(fb_reg)); + // TODO: adt_set_reg(node, "vram", fb_pa, size);? + ret = adt_setprop(node, "reg", &fb_reg, sizeof(fb_reg)); if (ret < 0) printf("display: failed to update '/vram'\n"); } - node = adt_path_offset(adt, "/chosen/carveout-memory-map"); + node = adt_path_offset("/chosen/carveout-memory-map"); if (node >= 0) { - // TODO: adt_set_reg(adt, node, "vram", fb_pa, size);? - ret = adt_setprop(adt, node, "region-id-14", &fb_reg, sizeof(fb_reg)); + // TODO: adt_set_reg(node, "vram", fb_pa, size);? + ret = adt_setprop(node, "region-id-14", &fb_reg, sizeof(fb_reg)); if (ret < 0) printf("display: failed to update '/chosen/carveout-memory-map/region-id-14'\n"); } } // Swap! - u32 stride = tbest.width * 4; + u32 stride = ((tbest.width * 4) + 63) & 0xffffffc0; ret = display_swap(fb_dva, stride, tbest.width, tbest.height); if (ret < 0) return ret; @@ -610,7 +611,7 @@ int display_configure(const char *config) int display_init(void) { const char *disp_path; - if (adt_is_compatible(adt, 0, "J180dAP") || adt_is_compatible(adt, 0, "J475dAP")) + if (adt_is_compatible(0, "J180dAP") || adt_is_compatible(0, "J475dAP")) disp_path = "/arm-io/dispext4"; else disp_path = "/arm-io/disp0"; @@ -618,22 +619,22 @@ int display_init(void) bool has_notch = false; UNUSED(has_notch); - int product = adt_path_offset(adt, "/product"); + int product = adt_path_offset("/product"); if (product < 0) { printf("/product node not found!\n"); } else { u32 val = 0; - ADT_GETPROP(adt, product, "partially-occluded-display", &val); + ADT_GETPROP(product, "partially-occluded-display", &val); has_notch = !!val; } - int node = adt_path_offset(adt, disp_path); + int node = adt_path_offset(disp_path); if (node < 0) { printf("%s node not found!\n", disp_path); return -1; } - display_is_external = adt_getprop(adt, node, "external", NULL); + display_is_external = adt_getprop(node, "external", NULL); if (display_is_external) printf("display: Display is external\n"); else @@ -658,11 +659,16 @@ int display_init(void) display_needs_power_cycle = true; return display_configure(NULL); #endif - } else { - printf("display: Display is already initialized (%ldx%ld)\n", cur_boot_args.video.width, - cur_boot_args.video.height); - return 0; + } if (adt_is_compatible(0, "J517AP")) { + int ret = display_configure(NULL); + if (ret < 0) + return ret; + return dcp_ib_set_bightness(iboot, 0x7fffffff); } + + printf("display: Display is already initialized (%ldx%ld)\n", cur_boot_args.video.width, + cur_boot_args.video.height); + return 0; } void display_shutdown(dcp_shutdown_mode mode) diff --git a/src/dockchannel_uart.c b/src/dockchannel_uart.c index 8de89efc3..a9179191f 100644 --- a/src/dockchannel_uart.c +++ b/src/dockchannel_uart.c @@ -19,10 +19,10 @@ int dockchannel_uart_init(void) { int path[8]; - if (adt_path_offset_trace(adt, "/arm-io/dockchannel-uart", path) < 0) + if (adt_path_offset_trace("/arm-io/dockchannel-uart", path) < 0) return -1; - if (adt_get_reg(adt, path, "reg", 0, &uart_base, NULL)) { + if (adt_get_reg(path, "reg", 0, &uart_base, NULL)) { printf("!!! Failed to get dockchannel UART reg property!\n"); return -1; } diff --git a/src/exception.c b/src/exception.c index ded20c438..d26885f1b 100644 --- a/src/exception.c +++ b/src/exception.c @@ -213,7 +213,7 @@ void print_regs(u64 *regs, int el12) u64 far = in_gl ? mrs(SYS_IMP_APL_FAR_GL1) : (el12 ? mrs(FAR_EL12) : (el3 ? mrs(FAR_EL3) : mrs(FAR_EL1))); - printf("PC: 0x%lx (rel: 0x%lx)\n", elr, elr - (u64)_base); + printf("PC: 0x%lx (rel: 0x%lx)\n", elr, elr - (u64)_text_start); printf("SP: 0x%lx\n", sp); printf("SPSR: 0x%lx\n", spsr); if (in_gl12()) { diff --git a/src/firmware.c b/src/firmware.c index e844317ef..b426f4830 100644 --- a/src/firmware.c +++ b/src/firmware.c @@ -283,7 +283,7 @@ bool firmware_sfw_in_range(enum fw_version lower_bound, enum fw_version upper_bo int firmware_init(void) { - int node = adt_path_offset(adt, "/chosen"); + int node = adt_path_offset("/chosen"); if (node < 0) { printf("ADT: no /chosen found\n"); @@ -291,7 +291,7 @@ int firmware_init(void) } u32 len; - const char *p = adt_getprop(adt, node, "firmware-version", &len); + const char *p = adt_getprop(node, "firmware-version", &len); if (p && len && p[len - 1] == 0) { detect_firmware(&os_firmware, p); printf("OS FW version: %s (%s)\n", os_firmware.string, os_firmware.iboot); @@ -300,7 +300,7 @@ int firmware_init(void) return -1; } - p = adt_getprop(adt, node, "system-firmware-version", &len); + p = adt_getprop(node, "system-firmware-version", &len); if (p && len && p[len - 1] == 0) { detect_firmware(&system_firmware, p); printf("System FW version: %s (%s)\n", system_firmware.string, system_firmware.iboot); diff --git a/src/hv_wdt.c b/src/hv_wdt.c index d78c38584..a0533bfcc 100644 --- a/src/hv_wdt.c +++ b/src/hv_wdt.c @@ -132,14 +132,14 @@ void hv_wdt_init(void) char boot_cpu_name[32]; snprintf(boot_cpu_name, sizeof(boot_cpu_name), "/cpus/cpu%d", boot_cpu_idx); - int node = adt_path_offset(adt, boot_cpu_name); + int node = adt_path_offset(boot_cpu_name); if (node < 0) { printf("Error getting %s node\n", boot_cpu_name); return; } u64 reg[2]; - if (ADT_GETPROP_ARRAY(adt, node, "cpu-uttdbg-reg", reg) < 0) { + if (ADT_GETPROP_ARRAY(node, "cpu-uttdbg-reg", reg) < 0) { printf("Error getting cpu-uttdbg-reg property\n"); return; } diff --git a/src/i2c.c b/src/i2c.c index 1fcd6933f..33516742f 100644 --- a/src/i2c.c +++ b/src/i2c.c @@ -31,14 +31,14 @@ i2c_dev_t *i2c_init(const char *adt_node) { int adt_path[8]; int adt_offset; - adt_offset = adt_path_offset_trace(adt, adt_node, adt_path); + adt_offset = adt_path_offset_trace(adt_node, adt_path); if (adt_offset < 0) { printf("i2c: Error getting %s node\n", adt_node); return NULL; } u64 base; - if (adt_get_reg(adt, adt_path, "reg", 0, &base, NULL) < 0) { + if (adt_get_reg(adt_path, "reg", 0, &base, NULL) < 0) { printf("i2c: Error getting %s regs\n", adt_node); return NULL; } diff --git a/src/isp.c b/src/isp.c index 96a982ea7..4f5809872 100644 --- a/src/isp.c +++ b/src/isp.c @@ -54,13 +54,13 @@ int isp_init(void) const char *dart_path = "/arm-io/dart-isp"; int adt_path[8], adt_isp_path[8]; - int isp_node = adt_path_offset_trace(adt, isp_path, adt_isp_path); - int node = adt_path_offset_trace(adt, dart_path, adt_path); + int isp_node = adt_path_offset_trace(isp_path, adt_isp_path); + int node = adt_path_offset_trace(dart_path, adt_path); if (node < 0 || isp_node < 0) { isp_path = "/arm-io/isp0"; dart_path = "/arm-io/dart-isp0"; - isp_node = adt_path_offset_trace(adt, isp_path, adt_isp_path); - node = adt_path_offset_trace(adt, dart_path, adt_path); + isp_node = adt_path_offset_trace(isp_path, adt_isp_path); + node = adt_path_offset_trace(dart_path, adt_path); } if (node < 0) return 0; @@ -70,11 +70,11 @@ int isp_init(void) u64 isp_base; u64 pmgr_base; - err = adt_get_reg(adt, adt_isp_path, "reg", 0, &isp_base, NULL); + err = adt_get_reg(adt_isp_path, "reg", 0, &isp_base, NULL); if (err) return err; - err = adt_get_reg(adt, adt_isp_path, "reg", 1, &pmgr_base, NULL); + err = adt_get_reg(adt_isp_path, "reg", 1, &pmgr_base, NULL); if (err) return err; @@ -168,7 +168,7 @@ int isp_init(void) const struct adt_segment_ranges *seg; u32 segments_len; - seg = adt_getprop(adt, isp_node, "segment-ranges", &segments_len); + seg = adt_getprop(isp_node, "segment-ranges", &segments_len); unsigned int count = segments_len / sizeof(*seg); heap_iova = seg[count - 1].iova + seg[count - 1].size; diff --git a/src/kboot.c b/src/kboot.c index d4b240c76..104a87ce1 100644 --- a/src/kboot.c +++ b/src/kboot.c @@ -72,7 +72,7 @@ void get_notchless_fb(u64 *fb_base, u64 *fb_height) *fb_base = cur_boot_args.video.base; *fb_height = cur_boot_args.video.height; - int node = adt_path_offset(adt, "/product"); + int node = adt_path_offset("/product"); if (node < 0) { printf("FDT: /product node not found\n"); @@ -81,7 +81,7 @@ void get_notchless_fb(u64 *fb_base, u64 *fb_height) u32 val; - if ((ADT_GETPROP(adt, node, "partially-occluded-display", &val) < 0 || !val) && + if ((ADT_GETPROP(node, "partially-occluded-display", &val) < 0 || !val) && (chip_id != T8015 || (board_id != 0x6 && board_id != 0xe))) { printf("FDT: No notch detected\n"); return; @@ -132,7 +132,7 @@ static int dt_set_rng_seed_sep(int node) static int dt_set_rng_seed_adt(int node) { - int anode = adt_path_offset(adt, "/chosen"); + int anode = adt_path_offset("/chosen"); if (anode < 0) bail("ADT: /chosen not found\n"); @@ -140,7 +140,7 @@ static int dt_set_rng_seed_adt(int node) const uint8_t *random_seed; u32 seed_length; - random_seed = adt_getprop(adt, anode, "random-seed", &seed_length); + random_seed = adt_getprop(anode, "random-seed", &seed_length); if (random_seed) { printf("ADT: %d bytes of random seed available\n", seed_length); @@ -353,7 +353,7 @@ static int dt_set_uboot_config(void) static int dt_set_memory(void) { - int anode = adt_path_offset(adt, "/chosen"); + int anode = adt_path_offset("/chosen"); if (anode < 0) bail("ADT: /chosen not found\n"); @@ -361,12 +361,12 @@ static int dt_set_memory(void) u64 dram_base = 0, dram_size = 0; // iOS 12 and below seems to be missing a bunch of stuff... - if (ADT_GETPROP(adt, anode, "dram-base", &dram_base) < 0) { + if (ADT_GETPROP(anode, "dram-base", &dram_base) < 0) { printf("ADT: Failed to get dram-base\n"); dram_base = 0x800000000; } - if (ADT_GETPROP(adt, anode, "dram-size", &dram_size) < 0) { + if (ADT_GETPROP(anode, "dram-size", &dram_size) < 0) { printf("ADT: Failed to get dram-size\n"); dram_size = mem_size_actual; } @@ -459,7 +459,7 @@ static int dt_set_serial_number(void) { int fdt_root = fdt_path_offset(dt, "/"); - int adt_root = adt_path_offset(adt, "/"); + int adt_root = adt_path_offset("/"); if (fdt_root < 0) bail("FDT: could not open a handle to FDT root.\n"); @@ -467,7 +467,7 @@ static int dt_set_serial_number(void) bail("ADT: could not open a handle to ADT root.\n"); u32 sn_len; - const char *serial_number = adt_getprop(adt, adt_root, "serial-number", &sn_len); + const char *serial_number = adt_getprop(adt_root, "serial-number", &sn_len); if (fdt_setprop_string(dt, fdt_root, "serial-number", serial_number)) bail("FDT: unable to set device serial number!\n"); printf("FDT: reporting device serial number: %s\n", serial_number); @@ -478,7 +478,7 @@ static int dt_set_serial_number(void) static int dt_set_smbios(void) { int fdt_root = fdt_path_offset(dt, "/"); - int adt_root = adt_path_offset(adt, "/"); + int adt_root = adt_path_offset("/"); int len, node, smbios_node; if (fdt_root < 0) @@ -499,15 +499,15 @@ static int dt_set_smbios(void) if (node < 0) bail("FDT: failed to add node 'system' to '/smbios'\n"); - const char *manuf = adt_getprop(adt, adt_root, "manufacturer", NULL); + const char *manuf = adt_getprop(adt_root, "manufacturer", NULL); if (!manuf) bail("ADT: failed to get manufacturer property\n"); fdt_setprop_string(dt, node, "manufacturer", manuf); - const char *model = adt_getprop(adt, adt_root, "model", NULL); + const char *model = adt_getprop(adt_root, "model", NULL); if (!model) bail("ADT: failed to get model property\n"); fdt_setprop_string(dt, node, "product", model); - const char *serial = adt_getprop(adt, adt_root, "serial-number", NULL); + const char *serial = adt_getprop(adt_root, "serial-number", NULL); if (!serial) bail("ADT: failed to get serial-number property\n"); fdt_setprop_string(dt, node, "serial", serial); @@ -516,7 +516,7 @@ static int dt_set_smbios(void) if (node < 0) bail("FDT: failed to add node 'baseboard' to '/smbios'\n"); fdt_setprop_string(dt, node, "manufacturer", manuf); - const char *target_type = adt_getprop(adt, 0, "target-type", NULL); + const char *target_type = adt_getprop(0, "target-type", NULL); if (!target_type) bail("ADT: failed to get target-type property\n"); fdt_setprop_string(dt, node, "product", target_type); @@ -781,7 +781,7 @@ static struct { static int dt_set_mac_addresses(void) { - int anode = adt_path_offset(adt, "/chosen"); + int anode = adt_path_offset("/chosen"); if (anode < 0) bail("ADT: /chosen not found\n"); @@ -791,7 +791,7 @@ static int dt_set_mac_addresses(void) snprintf(propname, sizeof(propname), "mac-address-%s", mac_address_devices[i].alias); uint8_t addr[6]; - if (ADT_GETPROP_ARRAY(adt, anode, propname, addr) < 0) + if (ADT_GETPROP_ARRAY(anode, propname, addr) < 0) continue; if (mac_address_devices[i].swap) { @@ -819,7 +819,7 @@ static int dt_set_mac_addresses(void) static int dt_set_bluetooth_cal(int anode, int node, const char *adt_name, const char *fdt_name) { u32 len; - const u8 *cal_blob = adt_getprop(adt, anode, adt_name, &len); + const u8 *cal_blob = adt_getprop(anode, adt_name, &len); if (!cal_blob || !len) { printf("ADT: Failed to get %s. Replaced module?\n", adt_name); @@ -833,7 +833,7 @@ static int dt_set_bluetooth_cal(int anode, int node, const char *adt_name, const static int dt_set_bluetooth(void) { int ret; - int anode = adt_path_offset(adt, "/arm-io/bluetooth"); + int anode = adt_path_offset("/arm-io/bluetooth"); if (anode < 0) { /* @@ -882,12 +882,12 @@ static int dt_set_multitouch(void) else return 0; - int anode = adt_path_offset(adt, adt_touchbar); + int anode = adt_path_offset(adt_touchbar); if (anode < 0) bail("ADT: touchbar node %s not found\n", adt_touchbar); u32 len; - const u8 *cal_blob = adt_getprop(adt, anode, "multi-touch-calibration", &len); + const u8 *cal_blob = adt_getprop(anode, "multi-touch-calibration", &len); if (!cal_blob || !len) { printf("ADT: Failed to get multi-touch-calibration from %s\n", adt_touchbar); return 0; @@ -905,9 +905,9 @@ static int dt_set_ipd(void) if (chosen < 0) bail("FDT: /chosen node not found in devtree\n"); - int ipd = adt_path_offset(adt, "/arm-io/spi3/ipd"); + int ipd = adt_path_offset("/arm-io/spi3/ipd"); if (ipd < 0) - ipd = adt_path_offset(adt, "/arm-io/dockchannel-mtp/mtp-transport/keyboard"); + ipd = adt_path_offset("/arm-io/dockchannel-mtp/mtp-transport/keyboard"); if (ipd < 0) { printf("ADT: no keyboard found\n"); @@ -915,7 +915,7 @@ static int dt_set_ipd(void) } u32 len; - const u8 *kblang = adt_getprop(adt, ipd, "kblang-calibration", &len); + const u8 *kblang = adt_getprop(ipd, "kblang-calibration", &len); if (!kblang || len < 2) { printf("ADT: kblang-calibration not found, no keyboard layout\n"); return 0; @@ -952,7 +952,7 @@ static int dt_set_nvram(void) int adt_path[8]; u64 start, size; - int anode = adt_path_offset_trace(adt, "/arm-io/spi1/spinor/anvram", adt_path); + int anode = adt_path_offset_trace("/arm-io/spi1/spinor/anvram", adt_path); if (anode < 0) { printf("ADT: nvram partition not found\n"); return 0; @@ -963,7 +963,7 @@ static int dt_set_nvram(void) pp++; adt_path[pp + 1] = 0; - int ret = adt_get_reg(adt, adt_path, "reg", 0, &start, &size); + int ret = adt_get_reg(adt_path, "reg", 0, &start, &size); if (ret < 0) { printf("ADT: could not read nvram partition start/size\n"); return 0; @@ -997,7 +997,7 @@ static int dt_set_nvram(void) static int dt_set_wifi(void) { - int anode = adt_path_offset(adt, "/arm-io/wlan"); + int anode = adt_path_offset("/arm-io/wlan"); if (anode < 0) { /* @@ -1009,7 +1009,7 @@ static int dt_set_wifi(void) } uint8_t info[16]; - if (ADT_GETPROP_ARRAY(adt, anode, "wifi-antenna-sku-info", info) < 0) + if (ADT_GETPROP_ARRAY(anode, "wifi-antenna-sku-info", info) < 0) bail("ADT: Failed to get wifi-antenna-sku-info\n"); const char *path = fdt_get_alias(dt, "wifi0"); @@ -1025,7 +1025,7 @@ static int dt_set_wifi(void) fdt_setprop_string(dt, node, "apple,antenna-sku", antenna); u32 len; - const u8 *cal_blob = adt_getprop(adt, anode, "wifi-calibration-msf", &len); + const u8 *cal_blob = adt_getprop(anode, "wifi-calibration-msf", &len); if (!cal_blob || !len) { printf("ADT: Failed to get wifi-calibration-msf. Replaced module?\n"); @@ -1142,7 +1142,7 @@ static int dt_append_acio_tunable(int adt_node, int fdt_node, { u32 tunables_len; const struct acio_tunable *tunable_adt = - adt_getprop(adt, adt_node, tunable_info->adt_name, &tunables_len); + adt_getprop(adt_node, tunable_info->adt_name, &tunables_len); if (!tunable_adt) { printf("ADT: tunable %s not found\n", tunable_info->adt_name); @@ -1191,7 +1191,7 @@ static int dt_append_acio_tunable(int adt_node, int fdt_node, static int dt_copy_usb4_drom(const char *adt_path, const char *dt_alias) { - int adt_node = adt_path_offset(adt, adt_path); + int adt_node = adt_path_offset(adt_path); if (adt_node < 0) return -1; @@ -1204,7 +1204,7 @@ static int dt_copy_usb4_drom(const char *adt_path, const char *dt_alias) bail("FDT: Unable to find path %s for alias %s\n", fdt_path, dt_alias); u32 drom_len; - const u8 *drom_blob = adt_getprop(adt, adt_node, "thunderbolt-drom", &drom_len); + const u8 *drom_blob = adt_getprop(adt_node, "thunderbolt-drom", &drom_len); if (!drom_blob || !drom_len) bail("ADT: Failed to get thunderbolt-drom\n"); @@ -1215,7 +1215,7 @@ static int dt_copy_acio_tunables(const char *adt_path, const char *dt_alias, const struct adt_tunable_info *tunables, size_t n_tunables) { int ret; - int adt_node = adt_path_offset(adt, adt_path); + int adt_node = adt_path_offset(adt_path); if (adt_node < 0) return -1; @@ -1279,7 +1279,7 @@ static int dt_copy_ausb_tunable(int adt_node, int fdt_node, char *name) snprintf(fdt_name, 32, "apple,%s", name); - if (adt_getprop_copy(adt, adt_node, name, &cfg, sizeof(u32)) < 0) + if (adt_getprop_copy(adt_node, name, &cfg, sizeof(u32)) < 0) bail("ADT: Could not get cfg0-device property\n"); if (fdt_setprop_u32(dt, fdt_node, fdt_name, cfg)) @@ -1298,7 +1298,7 @@ static int dt_set_ausb_tunables(void) if (fdt_node < 0) bail("FDT: Unable to find node for path %s from alias ausbphy0", fdt_path); - int adt_node = adt_path_offset(adt, "/arm-io/otgphyctrl"); + int adt_node = adt_path_offset("/arm-io/otgphyctrl"); if (adt_node < 0) bail("ADT: Could not get /arm-io/otgphyctrl path\n"); @@ -1333,7 +1333,7 @@ static const struct adt_tunable_info pciec_port_tunable = { static int dt_copy_pciec_tunables(const char *adt_path, const char *dt_alias) { int ret; - int adt_node = adt_path_offset(adt, adt_path); + int adt_node = adt_path_offset(adt_path); if (adt_node < 0) return -1; @@ -1737,7 +1737,7 @@ static int dt_carveout_reserved_regions(const char *dcp_alias, const char *disp_ if (ret) return ret; - int node = adt_path_offset(adt, "/chosen/carveout-memory-map"); + int node = adt_path_offset("/chosen/carveout-memory-map"); if (node < 0) bail("ADT: '/chosen/carveout-memory-map' not found\n"); @@ -1750,7 +1750,7 @@ static int dt_carveout_reserved_regions(const char *dcp_alias, const char *disp_ struct disp_mapping *map = &maps[i]; const char *name = map->region_adt; - ret = ADT_GETPROP_ARRAY(adt, node, name, phys_map); + ret = ADT_GETPROP_ARRAY(node, name, phys_map); if (ret != sizeof(phys_map)) bail("ADT: could not get carveout memory '%s'\n", name); if (!phys_map[0] || !phys_map[1]) @@ -1779,7 +1779,7 @@ static int dt_vram_reserved_region(const char *dcp_alias, const char *disp_alias if (!fdt_get_alias(dt, dcp_alias)) return 0; - int node = adt_path_offset_trace(adt, "/vram", adt_path); + int node = adt_path_offset_trace("/vram", adt_path); if (node < 0) bail("ADT: '/vram' not found\n"); @@ -1789,7 +1789,7 @@ static int dt_vram_reserved_region(const char *dcp_alias, const char *disp_alias pp++; adt_path[pp + 1] = 0; - ret = adt_get_reg(adt, adt_path, "reg", 0, ®ion.paddr, ®ion.size); + ret = adt_get_reg(adt_path, "reg", 0, ®ion.paddr, ®ion.size); if (ret < 0) bail("ADT: failed to read /vram/reg\n"); @@ -1808,9 +1808,9 @@ static int dt_reserve_asc_firmware(const char *adt_path, const char *adt_path_al return 0; } - int node = adt_path_offset(adt, adt_path); + int node = adt_path_offset(adt_path); if (node < 0 && adt_path_alt) - node = adt_path_offset(adt, adt_path_alt); + node = adt_path_offset(adt_path_alt); if (node < 0) bail("ADT: '%s' not found\n", adt_path); @@ -1826,7 +1826,7 @@ static int dt_reserve_asc_firmware(const char *adt_path, const char *adt_path_al const struct adt_segment_ranges *seg; u32 segments_len; - seg = adt_getprop(adt, node, "segment-ranges", &segments_len); + seg = adt_getprop(node, "segment-ranges", &segments_len); unsigned int num_maps = segments_len / sizeof(*seg); for (unsigned i = 0; i < num_maps; i++) { @@ -1877,7 +1877,7 @@ static int dt_reserve_dcpext_firmware(void) dcpext_alias); adt_path[sizeof(adt_path) - 1] = '\0'; - if (adt_path_offset(adt, adt_path) < 0) + if (adt_path_offset(adt_path) < 0) continue; int dcpext_node = fdt_path_offset(dt, dcpext_alias); @@ -2084,19 +2084,19 @@ static int dt_set_pmp(void) printf("FDT: pmp not found in devtree\n"); return 0; } - int chosen_anode = adt_path_offset(adt, "/chosen"); + int chosen_anode = adt_path_offset("/chosen"); if (chosen_anode < 0) bail("ADT: /chosen not found \n"); - int pmp_iop_anode = adt_path_offset(adt, "/arm-io/pmp/iop-pmp-nub"); + int pmp_iop_anode = adt_path_offset("/arm-io/pmp/iop-pmp-nub"); if (pmp_iop_anode < 0) bail("ADT: /arm-io/pmp/iop-pmp-nub not found \n"); u32 board_id, dram_vendor_id, dram_capacity = 0xFFFFFFFF; - if (ADT_GETPROP(adt, chosen_anode, "board-id", &board_id) < 0) + if (ADT_GETPROP(chosen_anode, "board-id", &board_id) < 0) bail("ADT: failed to get board id\n"); - if (ADT_GETPROP(adt, chosen_anode, "dram-vendor-id", &dram_vendor_id) < 0) + if (ADT_GETPROP(chosen_anode, "dram-vendor-id", &dram_vendor_id) < 0) bail("ADT: failed to get dram vendor id\n"); - ADT_GETPROP(adt, pmp_iop_anode, "dram-capacity", &dram_capacity); + ADT_GETPROP(pmp_iop_anode, "dram-capacity", &dram_capacity); if (fdt_setprop_u32(dt, pmp_node, "apple,board-id", board_id)) bail("FDT: failed to set board id\n"); @@ -2106,7 +2106,7 @@ static int dt_set_pmp(void) fdt_setprop_u32(dt, pmp_node, "apple,dram-capacity", dram_capacity)) bail("FDT: failed to set dram capacity\n"); - ADT_FOREACH_PROPERTY(adt, pmp_iop_anode, prop) + ADT_FOREACH_PROPERTY(pmp_iop_anode, prop) { if (skip_pmp_prop(prop->name)) continue; @@ -2128,12 +2128,12 @@ static int dt_set_sep(void) return 0; } - int anode_mmap = adt_path_offset(adt, "/chosen/memory-map"); + int anode_mmap = adt_path_offset("/chosen/memory-map"); if (anode_mmap < 0) bail("ADT: /chosen/memory-map not found \n"); u64 phys_map[2]; - size_t ret = ADT_GETPROP_ARRAY(adt, anode_mmap, "SEPFW", phys_map); + size_t ret = ADT_GETPROP_ARRAY(anode_mmap, "SEPFW", phys_map); if (ret != sizeof(phys_map)) bail("ADT: could not get sepfw memory\n"); @@ -2152,16 +2152,16 @@ static int dt_set_sep(void) if (node < 0) bail("FDT: sep not not found in devtree\n"); - int anode_manifest = adt_path_offset(adt, "/chosen/boot-object-manifests"); + int anode_manifest = adt_path_offset("/chosen/boot-object-manifests"); if (anode_manifest < 0) bail("ADT: /chosen/boot-object-manifests not found \n"); - ret = ADT_GETPROP_ARRAY(adt, anode_manifest, "lpol", phys_map); + ret = ADT_GETPROP_ARRAY(anode_manifest, "lpol", phys_map); if (ret != sizeof(phys_map)) bail("ADT: could not get local policy\n"); fdt_setprop(dt, node, "local-policy-manifest", (void *)phys_map[0], phys_map[1]); - ret = ADT_GETPROP_ARRAY(adt, anode_manifest, "ibot", phys_map); + ret = ADT_GETPROP_ARRAY(anode_manifest, "ibot", phys_map); if (ret != sizeof(phys_map)) bail("ADT: could not get iboot manifest\n"); fdt_setprop(dt, node, "iboot-manifest", (void *)phys_map[0], phys_map[1]); @@ -2188,7 +2188,7 @@ static int dt_set_smc(void) if (fdt_node_check_compatible(dt, reboot_node, "apple,t8015-smc-reboot")) return 0; - if (!(region = adt_getprop(adt, 0, "region-info", NULL))) { + if (!(region = adt_getprop(0, "region-info", NULL))) { printf("ADT: could not get region-info\n"); return 0; } @@ -2345,9 +2345,9 @@ static int dt_set_isp_fwdata(void) return 0; } - int adt_node = adt_path_offset(adt, "/arm-io/isp"); + int adt_node = adt_path_offset("/arm-io/isp"); if (adt_node < 0) - adt_node = adt_path_offset(adt, "/arm-io/isp0"); + adt_node = adt_path_offset("/arm-io/isp0"); if (adt_node < 0) return 0; @@ -2384,7 +2384,7 @@ static int dt_disable_missing_devs(const char *adt_prefix, const char *dt_prefix bail_cleanup("FDT: out of memory\n"); int path[8]; - int node = adt_path_offset_trace(adt, "/arm-io", path); + int node = adt_path_offset_trace("/arm-io", path); if (node < 0) bail_cleanup("ADT: /arm-io not found\n"); @@ -2394,7 +2394,7 @@ static int dt_disable_missing_devs(const char *adt_prefix, const char *dt_prefix path[pp + 1] = 0; u32 die_count; - if (ADT_GETPROP(adt, node, "die-count", &die_count) < 0) { + if (ADT_GETPROP(node, "die-count", &die_count) < 0) { die_count = 1; } if (die_count > 8) { @@ -2403,14 +2403,14 @@ static int dt_disable_missing_devs(const char *adt_prefix, const char *dt_prefix } /* Find ADT registers */ - ADT_FOREACH_CHILD(adt, node) + ADT_FOREACH_CHILD(node) { - const char *name = adt_get_name(adt, node); + const char *name = adt_get_name(node); if (strncmp(name, adt_prefix, adt_prefix_len)) continue; path[pp] = node; - if (adt_get_reg(adt, path, "reg", 0, &addrs[acnt++], NULL) < 0) + if (adt_get_reg(path, "reg", 0, &addrs[acnt++], NULL) < 0) bail_cleanup("Error getting /arm-io/%s regs\n", name); } @@ -2577,7 +2577,7 @@ static int dt_disable_missing_devs(const char *adt_prefix, const char *dt_prefix __attribute__((unused)) static int dt_transfer_virtios(void) { int path[3]; - path[0] = adt_path_offset(adt, "/arm-io/"); + path[0] = adt_path_offset("/arm-io/"); if (path[0] < 0) bail("ADT: /arm-io not found\n"); @@ -2601,17 +2601,17 @@ __attribute__((unused)) static int dt_transfer_virtios(void) char name[16], fullname[32]; snprintf(name, sizeof(name) - 1, "virtio%d", i); - path[1] = adt_subnode_offset(adt, path[0], name); + path[1] = adt_subnode_offset(path[0], name); if (path[1] < 0) break; path[2] = 0; u64 addr, size; - if (adt_get_reg(adt, path, "reg", 0, &addr, &size) < 0) + if (adt_get_reg(path, "reg", 0, &addr, &size) < 0) bail("ADT: error getting /arm-io/%s regs\n", name); u32 irq; - ADT_GETPROP(adt, path[1], "interrupts", &irq); + ADT_GETPROP(path[1], "interrupts", &irq); snprintf(fullname, sizeof(fullname) - 1, "virtio@%lx", addr); printf("FDT: Adding %s found in ADT\n", name); diff --git a/src/kboot_atc.c b/src/kboot_atc.c index 85d8d3a5f..38f11d022 100644 --- a/src/kboot_atc.c +++ b/src/kboot_atc.c @@ -339,7 +339,7 @@ static int dt_append_atc_fuses_helper(void *dt, int fdt_node, const struct atc_f static int dt_append_fuses(void *dt, int adt_node, int fdt_node, int port) { for (size_t i = 0; i < ARRAY_SIZE(atc_fuses); ++i) { - if (!adt_is_compatible_at(adt, adt_node, atc_fuses[i].compatible, 0)) + if (!adt_is_compatible_at(adt_node, atc_fuses[i].compatible, 0)) continue; if (atc_fuses[i].port >= 0 && port != atc_fuses[i].port) continue; @@ -367,7 +367,7 @@ static int dt_append_atc_tunable(void *dt, int adt_node, int fdt_node, { u32 tunables_len; const struct atc_tunable *tunable_adt = - adt_getprop(adt, adt_node, tunable_info->adt_name, &tunables_len); + adt_getprop(adt_node, tunable_info->adt_name, &tunables_len); if (!tunable_adt) { printf("ADT: tunable %s not found\n", tunable_info->adt_name); @@ -420,7 +420,7 @@ static void dt_copy_atc_tunables(void *dt, const char *adt_path, const char *dt_ const struct adt_tunable_info *tunables; size_t tunable_count; - int adt_node = adt_path_offset(adt, adt_path); + int adt_node = adt_path_offset(adt_path); if (adt_node < 0) return; @@ -443,7 +443,7 @@ static void dt_copy_atc_tunables(void *dt, const char *adt_path, const char *dt_ goto cleanup; } - if (adt_is_compatible_at(adt, adt_node, "atc-phy,t8122", 0)) { + if (adt_is_compatible_at(adt_node, "atc-phy,t8122", 0)) { tunables = &atc_tunables_t8122[0]; tunable_count = sizeof(atc_tunables_t8122) / sizeof(*atc_tunables_t8122); } else { diff --git a/src/kboot_gpu.c b/src/kboot_gpu.c index 8161534cb..e6badbbe1 100644 --- a/src/kboot_gpu.c +++ b/src/kboot_gpu.c @@ -67,10 +67,10 @@ static int get_core_counts(u32 *count, u32 nclusters, u32 ncores) pmgr_adt_power_enable("/arm-io/sgx"); int adt_sgx_path[8]; - if (adt_path_offset_trace(adt, "/arm-io/sgx", adt_sgx_path) < 0) + if (adt_path_offset_trace("/arm-io/sgx", adt_sgx_path) < 0) bail("ADT: GPU: Failed to get sgx\n"); - if (adt_get_reg(adt, adt_sgx_path, "reg", 0, &base, NULL) < 0) + if (adt_get_reg(adt_sgx_path, "reg", 0, &base, NULL) < 0) bail("ADT: GPU: Failed to get sgx reg 0\n"); u32 cores[3] = {0, 0, 0}; @@ -423,11 +423,11 @@ static int dt_set_region(void *dt, int sgx, const char *name, const char *path) char prop[64]; snprintf(prop, sizeof(prop), "%s-base", name); - if (ADT_GETPROP(adt, sgx, prop, &base) < 0 || !base) + if (ADT_GETPROP(sgx, prop, &base) < 0 || !base) bail("ADT: GPU: failed to find %s property\n", prop); snprintf(prop, sizeof(prop), "%s-size", name); - if (ADT_GETPROP(adt, sgx, prop, &size) < 0 || !base) + if (ADT_GETPROP(sgx, prop, &size) < 0 || !base) bail("ADT: GPU: failed to find %s property\n", prop); return dt_set_resvmem(dt, path, base, size); @@ -543,16 +543,16 @@ int dt_set_gpu(void *dt) downstream_dtb |= fdt_node_check_compatible(dt, gpu, "apple,agx-t6021") == 0; downstream_dtb |= fdt_node_check_compatible(dt, gpu, "apple,agx-t6022") == 0; - int sgx = adt_path_offset(adt, "/arm-io/sgx"); + int sgx = adt_path_offset("/arm-io/sgx"); if (sgx < 0) bail("ADT: GPU: /arm-io/sgx node not found\n"); u32 perf_state_count; - if (ADT_GETPROP(adt, sgx, "perf-state-count", &perf_state_count) < 0 || !perf_state_count) + if (ADT_GETPROP(sgx, "perf-state-count", &perf_state_count) < 0 || !perf_state_count) bail("ADT: GPU: missing perf-state-count\n"); u32 perf_state_table_count; - if (ADT_GETPROP(adt, sgx, "perf-state-table-count", &perf_state_table_count) < 0 || + if (ADT_GETPROP(sgx, "perf-state-table-count", &perf_state_table_count) < 0 || !perf_state_table_count) bail("ADT: GPU: missing perf-state-table-count\n"); @@ -566,18 +566,18 @@ int dt_set_gpu(void *dt) const struct perf_state *perf_states, *perf_states_sram; const struct aux_perf_states *perf_states_afr, *perf_states_cs; - perf_states = adt_getprop(adt, sgx, "perf-states", &perf_states_len); + perf_states = adt_getprop(sgx, "perf-states", &perf_states_len); if (!perf_states || perf_states_len != sizeof(*perf_states) * perf_state_count * perf_state_table_count) bail("ADT: GPU: invalid perf-states length\n"); - perf_states_sram = adt_getprop(adt, sgx, "perf-states-sram", &perf_states_len); + perf_states_sram = adt_getprop(sgx, "perf-states-sram", &perf_states_len); if (perf_states_sram && perf_states_len != sizeof(*perf_states) * perf_state_count * perf_state_table_count) bail("ADT: GPU: invalid perf-states-sram length\n"); - perf_states_afr = adt_getprop(adt, sgx, "afr-perf-states", NULL); - perf_states_cs = adt_getprop(adt, sgx, "cs-perf-states", NULL); + perf_states_afr = adt_getprop(sgx, "afr-perf-states", NULL); + perf_states_cs = adt_getprop(sgx, "cs-perf-states", NULL); if (has_cs_afr && !perf_states_cs) bail("ADT: GPU: cs-perf-states not found\n"); diff --git a/src/main.c b/src/main.c index d4e828c54..c8341c27f 100644 --- a/src/main.c +++ b/src/main.c @@ -40,8 +40,8 @@ u32 board_id = ~0, chip_id = ~0; void get_device_info(void) { - const char *model = (const char *)adt_getprop(adt, 0, "model", NULL); - const char *target = (const char *)adt_getprop(adt, 0, "target-type", NULL); + const char *model = (const char *)adt_getprop(0, "model", NULL); + const char *target = (const char *)adt_getprop(0, "target-type", NULL); printf("Device info:\n"); @@ -53,11 +53,11 @@ void get_device_info(void) is_mac = !!strstr(model, "Mac"); - int chosen = adt_path_offset(adt, "/chosen"); + int chosen = adt_path_offset("/chosen"); if (chosen > 0) { - if (ADT_GETPROP(adt, chosen, "board-id", &board_id) < 0) + if (ADT_GETPROP(chosen, "board-id", &board_id) < 0) printf("Failed to find board-id\n"); - if (ADT_GETPROP(adt, chosen, "chip-id", &chip_id) < 0) + if (ADT_GETPROP(chosen, "chip-id", &chip_id) < 0) printf("Failed to find chip-id\n"); printf(" Board-ID: 0x%x\n", board_id); @@ -75,11 +75,11 @@ void run_actions(void) #ifndef BRINGUP #ifdef EARLY_PROXY_TIMEOUT - int node = adt_path_offset(adt, "/chosen/asmb"); + int node = adt_path_offset("/chosen/asmb"); u64 lp_sip0 = 0; if (node >= 0) { - ADT_GETPROP(adt, node, "lp-sip0", &lp_sip0); + ADT_GETPROP(node, "lp-sip0", &lp_sip0); printf("Boot policy: sip0 = %ld\n", lp_sip0); } diff --git a/src/mcc.c b/src/mcc.c index 375388399..216f7f606 100644 --- a/src/mcc.c +++ b/src/mcc.c @@ -229,23 +229,23 @@ int mcc_init_t8103(int node, int *path, bool t8112) mcc_regs[0].plane_count = T8103_PLANES; mcc_regs[0].dcs_stride = T8103_DCS_STRIDE; - if (adt_get_reg(adt, path, "reg", 0, &mcc_regs[0].global_base, NULL)) { + if (adt_get_reg(path, "reg", 0, &mcc_regs[0].global_base, NULL)) { printf("MCC: Failed to get reg property 0!\n"); return -1; } - if (adt_get_reg(adt, path, "reg", 1, &mcc_regs[0].plane_base, NULL)) { + if (adt_get_reg(path, "reg", 1, &mcc_regs[0].plane_base, NULL)) { printf("MCC: Failed to get reg property 1!\n"); return -1; } - if (adt_get_reg(adt, path, "reg", 2, &mcc_regs[0].dcs_base, NULL)) { + if (adt_get_reg(path, "reg", 2, &mcc_regs[0].dcs_base, NULL)) { printf("MCC: Failed to get reg property 2!\n"); return -1; } u32 val; - if (ADT_GETPROP(adt, node, "dcs_num_channels", &val) < 0) { + if (ADT_GETPROP(node, "dcs_num_channels", &val) < 0) { printf("MCC: Failed to get dcs_num_channels property!\n"); return -1; } @@ -270,7 +270,7 @@ int mcc_init_t6000(int node, int *path, bool t602x) u32 reg_len; u32 reg_offset = t602x ? 2 : 0; - if (!adt_getprop(adt, node, "reg", ®_len)) { + if (!adt_getprop(node, "reg", ®_len)) { printf("MCC: Failed to get reg property!\n"); return -1; } @@ -286,7 +286,7 @@ int mcc_init_t6000(int node, int *path, bool t602x) for (int i = 0; i < mcc_count; i++) { u64 base; - if (adt_get_reg(adt, path, "reg", i + reg_offset, &base, NULL)) { + if (adt_get_reg(path, "reg", i + reg_offset, &base, NULL)) { printf("MCC: Failed to get reg index %d!\n", i + reg_offset); return -1; } @@ -323,7 +323,7 @@ int mcc_init_t6031(int node, int *path) u32 reg_len; u32 reg_offset = 3; - if (!adt_getprop(adt, node, "reg", ®_len)) { + if (!adt_getprop(node, "reg", ®_len)) { printf("MCC: Failed to get reg property!\n"); return -1; } @@ -340,19 +340,19 @@ int mcc_init_t6031(int node, int *path) u32 plane_count = 0; u32 dcs_count = 0; - if (!ADT_GETPROP(adt, node, "dcs-count-per-amcc", &dcs_count)) { + if (!ADT_GETPROP(node, "dcs-count-per-amcc", &dcs_count)) { printf("MCC: Failed to get dcs count!\n"); return -1; } - if (!ADT_GETPROP(adt, node, "plane-count-per-amcc", &plane_count)) { + if (!ADT_GETPROP(node, "plane-count-per-amcc", &plane_count)) { printf("MCC: Failed to get plane count!\n"); return -1; } for (int i = 0; i < mcc_count; i++) { u64 base; - if (adt_get_reg(adt, path, "reg", i + reg_offset, &base, NULL)) { + if (adt_get_reg(path, "reg", i + reg_offset, &base, NULL)) { printf("MCC: Failed to get reg index %d!\n", i + reg_offset); return -1; } @@ -387,25 +387,25 @@ int mcc_init_t6031(int node, int *path) int mcc_init(void) { int path[8]; - int node = adt_path_offset_trace(adt, "/arm-io/mcc", path); + int node = adt_path_offset_trace("/arm-io/mcc", path); if (node < 0) { printf("MCC: MCC node not found!\n"); return -1; } - if (adt_is_compatible(adt, node, "mcc,t8103")) { + if (adt_is_compatible(node, "mcc,t8103")) { return mcc_init_t8103(node, path, false); - } else if (adt_is_compatible(adt, node, "mcc,t8112")) { + } else if (adt_is_compatible(node, "mcc,t8112")) { return mcc_init_t8103(node, path, true); - } else if (adt_is_compatible(adt, node, "mcc,t6000")) { + } else if (adt_is_compatible(node, "mcc,t6000")) { return mcc_init_t6000(node, path, false); - } else if (adt_is_compatible(adt, node, "mcc,t6020")) { + } else if (adt_is_compatible(node, "mcc,t6020")) { return mcc_init_t6000(node, path, true); - } else if (adt_is_compatible(adt, node, "mcc,t6031")) { + } else if (adt_is_compatible(node, "mcc,t6031")) { return mcc_init_t6031(node, path); } else { - printf("MCC: Unsupported version:%s\n", adt_get_property(adt, node, "compatible")->value); + printf("MCC: Unsupported version:%s\n", adt_get_property(node, "compatible")->value); return -1; } } diff --git a/src/memory.c b/src/memory.c index 107672553..d2fedf4fb 100644 --- a/src/memory.c +++ b/src/memory.c @@ -390,13 +390,13 @@ void mmu_rm_mapping(u64 from, size_t size) static void mmu_map_mmio(void) { - int node = adt_path_offset(adt, "/arm-io"); + int node = adt_path_offset("/arm-io"); if (node < 0) { printf("MMU: ARM-IO node not found!\n"); return; } u32 ranges_len; - const u32 *ranges = adt_getprop(adt, node, "ranges", &ranges_len); + const u32 *ranges = adt_getprop(node, "ranges", &ranges_len); if (!ranges) { printf("MMU: Failed to get ranges property!\n"); return; @@ -419,13 +419,13 @@ static void mmu_map_mmio(void) static void mmu_remap_ranges(void) { - int node = adt_path_offset(adt, "/defaults"); + int node = adt_path_offset("/defaults"); if (node < 0) { printf("MMU: defaults node not found!\n"); return; } u32 ranges_len; - const u32 *ranges = adt_getprop(adt, node, "pmap-io-ranges", &ranges_len); + const u32 *ranges = adt_getprop(node, "pmap-io-ranges", &ranges_len); if (!ranges) { printf("MMU: Failed to get pmap-io-ranges property!\n"); return; diff --git a/src/nvme.c b/src/nvme.c index 71d547212..5bfa4a2c8 100644 --- a/src/nvme.c +++ b/src/nvme.c @@ -371,18 +371,18 @@ bool nvme_init(void) } int adt_path[8]; - int node = adt_path_offset_trace(adt, "/arm-io/ans", adt_path); + int node = adt_path_offset_trace("/arm-io/ans", adt_path); if (node < 0) { printf("nvme: Error getting NVMe node /arm-io/ans\n"); return NULL; } - if (adt_get_reg(adt, adt_path, "reg", 3, &nvme_base, NULL) < 0) { + if (adt_get_reg(adt_path, "reg", 3, &nvme_base, NULL) < 0) { printf("nvme: Error getting NVMe base address.\n"); return NULL; } - if (adt_is_compatible(adt, node, "iop-ans2,t8015")) { + if (adt_is_compatible(node, "iop-ans2,t8015")) { nvme_type = NVME_TYPE_T8015; nvme_queue_size = NVME_QUEUE_SIZE_T8015; } else { @@ -391,7 +391,7 @@ bool nvme_init(void) } u32 cg; - if (ADT_GETPROP(adt, node, "clock-gates", &cg) < 0) { + if (ADT_GETPROP(node, "clock-gates", &cg) < 0) { printf("nvme: clock-gates not set\n"); nvme_die = (nvme_base >> 37) & 3; } else { diff --git a/src/payload.c b/src/payload.c index 5b1547fde..b07ba6665 100644 --- a/src/payload.c +++ b/src/payload.c @@ -290,7 +290,7 @@ bool payload_logo(void **custom_128, void **custom_256) int payload_run(void) { - const char *target = adt_getprop(adt, 0, "target-type", NULL); + const char *target = adt_getprop(0, "target-type", NULL); if (target) { strcpy(expect_compatible, "apple,"); char *p = expect_compatible + strlen(expect_compatible); diff --git a/src/pcie.c b/src/pcie.c index 04fb18ca5..f3433621e 100644 --- a/src/pcie.c +++ b/src/pcie.c @@ -249,47 +249,47 @@ static int pcie_init_controller(int controller, const char *path) state->initialized = false; state->num_phys = 1; - adt_offset = adt_path_offset_trace(adt, path, adt_path); + adt_offset = adt_path_offset_trace(path, adt_path); if (adt_offset < 0) { printf("pcie: Error getting node %s\n", path); return -1; } - if (adt_is_compatible(adt, adt_offset, "apcie,t8103")) { + if (adt_is_compatible(adt_offset, "apcie,t8103")) { fuse_bits = pcie_fuse_bits_t8103; state->pcie_regs = ®s_t8xxx_t600x; printf("pcie: Initializing t8103 PCIe controller\n"); - } else if (adt_is_compatible(adt, adt_offset, "apcie,t6000")) { + } else if (adt_is_compatible(adt_offset, "apcie,t6000")) { fuse_bits = pcie_fuse_bits_t6000; state->pcie_regs = ®s_t8xxx_t600x; printf("pcie: Initializing t6000 PCIe controller\n"); - } else if (adt_is_compatible(adt, adt_offset, "apcie,t8112")) { + } else if (adt_is_compatible(adt_offset, "apcie,t8112")) { fuse_bits = pcie_fuse_bits_t8112; state->pcie_regs = ®s_t8xxx_t600x; printf("pcie: Initializing t8112 PCIe controller\n"); - } else if (adt_is_compatible(adt, adt_offset, "apcie,t8122")) { + } else if (adt_is_compatible(adt_offset, "apcie,t8122")) { fuse_bits = NULL; state->pcie_regs = ®s_t8122; printf("pcie: Initializing t8122 PCIe controller\n"); - } else if (adt_is_compatible(adt, adt_offset, "apcie,t6030")) { + } else if (adt_is_compatible(adt_offset, "apcie,t6030")) { fuse_bits = NULL; state->pcie_regs = ®s_t8122; printf("pcie: Initializing t6030 PCIe controller\n"); - } else if (adt_is_compatible(adt, adt_offset, "apcie,t6020")) { + } else if (adt_is_compatible(adt_offset, "apcie,t6020")) { fuse_bits = NULL; state->pcie_regs = ®s_t602x; printf("pcie: Initializing t6020 PCIe controller\n"); - } else if (adt_is_compatible(adt, adt_offset, "apcie,t6031")) { + } else if (adt_is_compatible(adt_offset, "apcie,t6031")) { fuse_bits = NULL; state->pcie_regs = ®s_t6031; printf("pcie: Initializing t6031 PCIe controller\n"); - } else if (adt_is_compatible(adt, adt_offset, "apcie-ge,t6020")) { + } else if (adt_is_compatible(adt_offset, "apcie-ge,t6020")) { u32 lane_cfg; fuse_bits = NULL; state->pcie_regs = ®s_t602x; printf("pcie: Initializing t6020 PCIe GE controller\n"); - if (ADT_GETPROP(adt, adt_offset, "lane-cfg", &lane_cfg) < 0) { + if (ADT_GETPROP(adt_offset, "lane-cfg", &lane_cfg) < 0) { printf("pcie: Error getting lane_cfg for %s\n", path); return -1; } @@ -313,30 +313,30 @@ static int pcie_init_controller(int controller, const char *path) return -1; } - if (ADT_GETPROP(adt, adt_offset, "#ports", &state->port_count) < 0) { + if (ADT_GETPROP(adt_offset, "#ports", &state->port_count) < 0) { printf("pcie: Error getting port count for %s\n", path); return -1; } u64 config_base; - if (adt_get_reg(adt, adt_path, "reg", state->pcie_regs->config_idx, &config_base, NULL)) { + if (adt_get_reg(adt_path, "reg", state->pcie_regs->config_idx, &config_base, NULL)) { printf("pcie: Error getting reg with index %d for %s\n", state->pcie_regs->config_idx, path); return -1; } - if (adt_get_reg(adt, adt_path, "reg", state->pcie_regs->rc_idx, &state->rc_base, NULL)) { + if (adt_get_reg(adt_path, "reg", state->pcie_regs->rc_idx, &state->rc_base, NULL)) { printf("pcie: Error getting reg with index %d for %s\n", state->pcie_regs->rc_idx, path); return -1; } - if (adt_get_reg(adt, adt_path, "reg", state->pcie_regs->axi_idx, &state->axi_base, NULL)) { + if (adt_get_reg(adt_path, "reg", state->pcie_regs->axi_idx, &state->axi_base, NULL)) { printf("pcie: Error getting reg with index %d for %s\n", state->pcie_regs->axi_idx, path); return -1; } if (state->pcie_regs->phy_common_idx != -1) { - if (adt_get_reg(adt, adt_path, "reg", state->pcie_regs->phy_common_idx, + if (adt_get_reg(adt_path, "reg", state->pcie_regs->phy_common_idx, &state->phy_common_base, NULL)) { printf("pcie: Error getting reg with index %d for %s\n", state->pcie_regs->phy_common_idx, path); @@ -346,12 +346,12 @@ static int pcie_init_controller(int controller, const char *path) state->phy_common_base = 0; } - if (adt_get_reg(adt, adt_path, "reg", state->pcie_regs->phy_idx, &state->phy_base[0], NULL)) { + if (adt_get_reg(adt_path, "reg", state->pcie_regs->phy_idx, &state->phy_base[0], NULL)) { printf("pcie: Error getting reg with index %d for %s\n", state->pcie_regs->phy_idx, path); return -1; } - if (adt_get_reg(adt, adt_path, "reg", state->pcie_regs->phy_ip_idx, &state->phy_ip_base[0], + if (adt_get_reg(adt_path, "reg", state->pcie_regs->phy_ip_idx, &state->phy_ip_base[0], NULL)) { printf("pcie: Error getting reg with index %d for %s\n", state->pcie_regs->phy_ip_idx, path); @@ -370,13 +370,13 @@ static int pcie_init_controller(int controller, const char *path) state->phy_ip_base[phy] = state->phy_ip_base[0] + PHYIP_STRIDE * phy; } - if (adt_get_reg(adt, adt_path, "reg", state->pcie_regs->fuse_idx, &state->fuse_base, NULL)) { + if (adt_get_reg(adt_path, "reg", state->pcie_regs->fuse_idx, &state->fuse_base, NULL)) { printf("pcie: Error getting reg with index %d for %s\n", state->pcie_regs->fuse_idx, path); return -1; } u32 reg_len; - if (!adt_getprop(adt, adt_offset, "reg", ®_len)) { + if (!adt_getprop(adt_offset, "reg", ®_len)) { printf("pcie: Error getting reg length for %s\n", path); return -1; } @@ -397,7 +397,7 @@ static int pcie_init_controller(int controller, const char *path) return -1; } - if (!adt_getprop(adt, adt_offset, "apcie-axi2af-tunables", NULL)) { + if (!adt_getprop(adt_offset, "apcie-axi2af-tunables", NULL)) { printf("pcie: No axi2af tunables\n"); } else if (tunables_apply_local(path, "apcie-axi2af-tunables", state->pcie_regs->axi_idx)) { printf("pcie: Error applying %s for %s\n", "apcie-axi2af-tunables", path); @@ -408,7 +408,7 @@ static int pcie_init_controller(int controller, const char *path) if (controller == APCIE) write32(state->rc_base + 0x4, 0); - if (!adt_getprop(adt, adt_offset, "apcie-common-tunables", NULL)) { + if (!adt_getprop(adt_offset, "apcie-common-tunables", NULL)) { printf("pcie: No common tunables\n"); } else if (tunables_apply_local(path, "apcie-common-tunables", state->pcie_regs->rc_idx)) { printf("pcie: Error applying %s for %s\n", "apcie-common-tunables", path); @@ -419,7 +419,7 @@ static int pcie_init_controller(int controller, const char *path) * Initialize PHY. */ - if (!adt_getprop(adt, adt_offset, "apcie-phy-tunables", NULL)) { + if (!adt_getprop(adt_offset, "apcie-phy-tunables", NULL)) { printf("pcie: No PHY tunables\n"); } else if (tunables_apply_local(path, "apcie-phy-tunables", state->pcie_regs->phy_idx)) { printf("pcie: Error applying %s for %s\n", "apcie-phy-tunables", path); @@ -546,12 +546,12 @@ static int pcie_init_controller(int controller, const char *path) break; } - if ((bridge_offset = adt_path_offset(adt, bridge)) < 0) + if ((bridge_offset = adt_path_offset(bridge)) < 0) continue; printf("pcie: Initializing port %d\n", port); - if (adt_get_reg(adt, adt_path, "reg", + if (adt_get_reg(adt_path, "reg", port * port_reg_cnt + state->pcie_regs->shared_reg_count, &state->port_base[port], NULL)) { printf("pcie: Error getting reg with index %d for %s\n", @@ -559,7 +559,7 @@ static int pcie_init_controller(int controller, const char *path) return -1; } - if (adt_get_reg(adt, adt_path, "reg", + if (adt_get_reg(adt_path, "reg", port * port_reg_cnt + state->pcie_regs->shared_reg_count + 1, &state->port_ltssm_base[port], NULL)) { printf("pcie: Error getting reg with index %d for %s\n", @@ -567,7 +567,7 @@ static int pcie_init_controller(int controller, const char *path) return -1; } - if (adt_get_reg(adt, adt_path, "reg", + if (adt_get_reg(adt_path, "reg", port * port_reg_cnt + state->pcie_regs->shared_reg_count + 2, &state->port_phy_base[port], NULL)) { printf("pcie: Error getting reg with index %d for %s\n", @@ -576,7 +576,7 @@ static int pcie_init_controller(int controller, const char *path) } if (port_reg_cnt >= 5) { - if (adt_get_reg(adt, adt_path, "reg", + if (adt_get_reg(adt_path, "reg", port * port_reg_cnt + state->pcie_regs->shared_reg_count + 4, &state->port_intr2axi_base[port], NULL)) { printf("pcie: Error getting reg with index %d for %s\n", @@ -737,7 +737,7 @@ static int pcie_init_controller(int controller, const char *path) } u32 max_speed; - if (ADT_GETPROP(adt, bridge_offset, "maximum-link-speed", &max_speed) >= 0) { + if (ADT_GETPROP(bridge_offset, "maximum-link-speed", &max_speed) >= 0) { /* Some devices override "maximum-link-speed" in the device child nodes. * The property used for the link speed seems to be ad-hoc made up. * The 10 GB ethernet adapter uses "target-link-speed" and the SD card @@ -745,13 +745,13 @@ static int pcie_init_controller(int controller, const char *path) * resides in the first (only?) child node. */ if (max_speed == 1) { - int np = adt_first_child_offset(adt, bridge_offset); + int np = adt_first_child_offset(bridge_offset); if (np >= 0) { int target_speed; - if (ADT_GETPROP(adt, np, "target-link-speed", &target_speed) >= 0 && + if (ADT_GETPROP(np, "target-link-speed", &target_speed) >= 0 && target_speed > 0) { max_speed = target_speed; - } else if (ADT_GETPROP(adt, np, "expected-link-speed", &target_speed) >= 0 && + } else if (ADT_GETPROP(np, "expected-link-speed", &target_speed) >= 0 && target_speed > 0) { max_speed = target_speed; } diff --git a/src/pmgr.c b/src/pmgr.c index 4119f8fea..0567ba98b 100644 --- a/src/pmgr.c +++ b/src/pmgr.c @@ -73,7 +73,7 @@ static uintptr_t pmgr_get_psreg(u8 idx) u32 reg_offset = pmgr_ps_regs[3 * idx + 1]; u64 pmgr_reg; - if (adt_get_reg(adt, pmgr_path, "reg", reg_idx, &pmgr_reg, NULL) < 0) { + if (adt_get_reg(pmgr_path, "reg", reg_idx, &pmgr_reg, NULL) < 0) { printf("pmgr: Error getting /arm-io/pmgr regs\n"); return 0; } @@ -209,13 +209,13 @@ int pmgr_power_disable(u32 id) static int pmgr_adt_find_devices(const char *path, const u32 **devices, u32 *n_devices) { - int node_offset = adt_path_offset(adt, path); + int node_offset = adt_path_offset(path); if (node_offset < 0) { printf("pmgr: Error getting node %s\n", path); return -1; } - *devices = adt_getprop(adt, node_offset, "clock-gates", n_devices); + *devices = adt_getprop(node_offset, "clock-gates", n_devices); if (*devices == NULL || *n_devices == 0) { printf("pmgr: Error getting %s clock-gates.\n", path); return -1; @@ -380,31 +380,31 @@ int pmgr_power_on(int die, const char *name) int pmgr_init(void) { - int node = adt_path_offset(adt, "/arm-io"); + int node = adt_path_offset("/arm-io"); if (node < 0) { printf("pmgr: Error getting /arm-io node\n"); return -1; } - if (ADT_GETPROP(adt, node, "die-count", &pmgr_dies) < 0) + if (ADT_GETPROP(node, "die-count", &pmgr_dies) < 0) pmgr_dies = 1; - pmgr_offset = adt_path_offset_trace(adt, "/arm-io/pmgr", pmgr_path); + pmgr_offset = adt_path_offset_trace("/arm-io/pmgr", pmgr_path); if (pmgr_offset < 0) { printf("pmgr: Error getting /arm-io/pmgr node\n"); return -1; } - pmgr_ps_regs = adt_getprop(adt, pmgr_offset, "ps-regs", &pmgr_ps_regs_len); + pmgr_ps_regs = adt_getprop(pmgr_offset, "ps-regs", &pmgr_ps_regs_len); if (pmgr_ps_regs == NULL || pmgr_ps_regs_len == 0) { pmgr_use_group_and_offset = true; - pmgr_ps_regs = adt_getprop(adt, pmgr_offset, "ps-groups", &pmgr_ps_regs_len); + pmgr_ps_regs = adt_getprop(pmgr_offset, "ps-groups", &pmgr_ps_regs_len); if (pmgr_ps_regs == NULL || pmgr_ps_regs_len == 0) { printf("pmgr: Error getting /arm-io/pmgr ps-regs\n."); return -1; } } - pmgr_devices = adt_getprop(adt, pmgr_offset, "devices", &pmgr_devices_len); + pmgr_devices = adt_getprop(pmgr_offset, "devices", &pmgr_devices_len); if (pmgr_devices == NULL || pmgr_devices_len == 0) { printf("pmgr: Error getting /arm-io/pmgr devices.\n"); return -1; @@ -475,11 +475,11 @@ u32 pmgr_get_feature(const char *name) { u32 val = 0; - int node = adt_path_offset(adt, "/arm-io/pmgr"); + int node = adt_path_offset("/arm-io/pmgr"); if (node < 0) return 0; - if (ADT_GETPROP(adt, node, name, &val) < 0) + if (ADT_GETPROP(node, name, &val) < 0) return 0; return val; diff --git a/src/rtkit.c b/src/rtkit.c index d971716b7..7b5551a5d 100644 --- a/src/rtkit.c +++ b/src/rtkit.c @@ -213,7 +213,7 @@ static bool rtkit_asc_recv_timeout(struct rtkit_dev *rtk, struct rtkit_message * static void rtkit_asc_init_fini(struct rtkit_dev *rtk) { int iop_node = asc_get_iop_node((asc_dev_t *)rtk->mbox); - ADT_GETPROP(adt, iop_node, "asc-dram-mask", &rtk->dva_base); + ADT_GETPROP(iop_node, "asc-dram-mask", &rtk->dva_base); } static const struct rtkit_iop_ops __rtkit_asc_iop_ops = { @@ -755,25 +755,9 @@ bool rtkit_boot(rtkit_dev_t *rtk) if (ep_idx >= rtk->app_ep_start) continue; - switch (ep_idx) { - case RTKIT_EP_CRASHLOG: - has_crashlog = true; - break; - case RTKIT_EP_DEBUG: - has_debug = true; - break; - case RTKIT_EP_IOREPORT: - has_ioreport = true; - break; - case RTKIT_EP_SYSLOG: - has_syslog = true; - break; - case RTKIT_EP_OSLOG: - has_oslog = true; - case RTKIT_EP_MGMT: - break; - default: - rtkit_printf("unknown system endpoint 0x%02x\n", ep_idx); + if (!rtkit_start_ep(rtk, ep_idx)) { + rtkit_printf("failed to start ep: %d\n", ep_idx); + return false; } } } @@ -784,10 +768,9 @@ bool rtkit_boot(rtkit_dev_t *rtk) msg.msg = FIELD_PREP(MGMT_TYPE, MGMT_MSG_EPMAP_REPLY); msg.msg |= FIELD_PREP(MGMT_MSG_EPMAP_BASE, base); if (want_ver > 10) { + msg.msg |= FIELD_PREP(MGMT_MSG_EPMAP_BITMAP, bitmap); if (got_epmap) msg.msg |= MGMT_MSG_EPMAP_REPLY_DONE; - else - msg.msg |= MGMT_MSG_EPMAP_REPLY_MORE; } msg.ep = RTKIT_EP_MGMT; @@ -802,18 +785,6 @@ bool rtkit_boot(rtkit_dev_t *rtk) return false; } - /* start all required system endpoints */ - if (has_debug && !rtkit_start_ep(rtk, RTKIT_EP_DEBUG)) - return false; - if (has_crashlog && !rtkit_start_ep(rtk, RTKIT_EP_CRASHLOG)) - return false; - if (has_syslog && !rtkit_start_ep(rtk, RTKIT_EP_SYSLOG)) - return false; - if (has_ioreport && !rtkit_start_ep(rtk, RTKIT_EP_IOREPORT)) - return false; - if (has_oslog && !rtkit_start_ep(rtk, RTKIT_EP_OSLOG)) - return false; - while (rtk->iop_power != RTKIT_POWER_ON) { struct rtkit_message rtk_msg; bool handled = false; diff --git a/src/sart.c b/src/sart.c index 29919ee98..9a3a20cf7 100644 --- a/src/sart.c +++ b/src/sart.c @@ -154,22 +154,22 @@ static bool sart3_set_entry(sart_dev_t *sart, int index, u8 flags, void *paddr_, sart_dev_t *sart_init(const char *adt_path) { int sart_path[8]; - int node = adt_path_offset_trace(adt, adt_path, sart_path); + int node = adt_path_offset_trace(adt_path, sart_path); if (node < 0) { printf("sart: Error getting SART node %s\n", adt_path); return NULL; } u64 base; - if (adt_get_reg(adt, sart_path, "reg", 0, &base, NULL) < 0) { + if (adt_get_reg(sart_path, "reg", 0, &base, NULL) < 0) { printf("sart: Error getting SART %s base address.\n", adt_path); return NULL; } - const u32 *sart_version = adt_getprop(adt, node, "sart-version", NULL); + const u32 *sart_version = adt_getprop(node, "sart-version", NULL); const u32 sart_version_zero = 0; if (!sart_version) { - if (adt_is_compatible(adt, node, "sart,t8015")) { + if (adt_is_compatible(node, "sart,t8015")) { sart_version = &sart_version_zero; } else { printf("sart: SART %s has no sart-version property\n", adt_path); diff --git a/src/sep.c b/src/sep.c index c3ab62980..fa1088d8f 100644 --- a/src/sep.c +++ b/src/sep.c @@ -41,21 +41,21 @@ int sep_init(void) const char *path = "/arm-io/sep"; int sep_path[8]; - int node = adt_path_offset_trace(adt, path, sep_path); + int node = adt_path_offset_trace(path, sep_path); if (node < 0) { printf("sep: Error getting sep node %s\n", path); return -1; } u64 base; - if (adt_get_reg(adt, sep_path, "reg", 0, &base, NULL) < 0) { + if (adt_get_reg(sep_path, "reg", 0, &base, NULL) < 0) { printf("sep: Error getting akf %s base address.\n", path); return -1; } sep_dev = calloc(0, sizeof(*sep_dev)); - if (adt_is_compatible(adt, node, "iop,s5l8960x") || adt_is_compatible(adt, node, "iop,s8000")) { + if (adt_is_compatible(node, "iop,s5l8960x") || adt_is_compatible(node, "iop,s8000")) { sep_dev->type = SEP_MBOX_TYPE_AKF; } else { sep_dev->type = SEP_MBOX_TYPE_ASC; diff --git a/src/sio.c b/src/sio.c index e4ee7e8da..15f6d6fbf 100644 --- a/src/sio.c +++ b/src/sio.c @@ -154,7 +154,7 @@ struct sio_data *sio_setup_fwdata(const char *adt_path) siodata->iova_base = 0x30000; - int node = adt_path_offset(adt, adt_path); + int node = adt_path_offset(adt_path); if (node < 0) { printf("%s: missing node %s\n", __func__, adt_path); goto err; @@ -171,7 +171,7 @@ struct sio_data *sio_setup_fwdata(const char *adt_path) continue; } - const u8 *adt_blob = adt_getprop(adt, node, rule->prop, &len); + const u8 *adt_blob = adt_getprop(node, rule->prop, &len); if (!adt_blob) { printf("%s: missing ADT property '%s'\n", __func__, rule->prop); goto err; diff --git a/src/smp.c b/src/smp.c index 184984f54..9f9139076 100644 --- a/src/smp.c +++ b/src/smp.c @@ -231,20 +231,20 @@ static u64 smp_get_iorvbar(int node, int cpu) { u64 cpu_impl_reg[2]; - if (ADT_GETPROP_ARRAY(adt, node, "cpu-impl-reg", cpu_impl_reg) >= 0) + if (ADT_GETPROP_ARRAY(node, "cpu-impl-reg", cpu_impl_reg) >= 0) return cpu_impl_reg[0]; - if (ADT_GETPROP(adt, node, "reg-private", &cpu_impl_reg[0]) >= 0) + if (ADT_GETPROP(node, "reg-private", &cpu_impl_reg[0]) >= 0) return (cpu_impl_reg[0] + 0x40000); int arm_io_node; - if ((arm_io_node = adt_path_offset(adt, "/arm-io")) < 0) { + if ((arm_io_node = adt_path_offset("/arm-io")) < 0) { printf("smp: Error getting /arm-io node\n"); return 0; } u32 reg_len; - const u64 *regs = adt_getprop(adt, arm_io_node, "reg", ®_len); + const u64 *regs = adt_getprop(arm_io_node, "reg", ®_len); if (!regs) return 0; u32 index = 2 * cpu + 2; @@ -260,16 +260,16 @@ void smp_start_secondaries(void) int pmgr_path[8]; - if (adt_path_offset_trace(adt, "/arm-io/pmgr", pmgr_path) < 0) { + if (adt_path_offset_trace("/arm-io/pmgr", pmgr_path) < 0) { printf("Error getting /arm-io/pmgr node\n"); return; } - if (adt_get_reg(adt, pmgr_path, "reg", 0, &pmgr_reg, NULL) < 0) { + if (adt_get_reg(pmgr_path, "reg", 0, &pmgr_reg, NULL) < 0) { printf("Error getting /arm-io/pmgr regs\n"); return; } - int node = adt_path_offset(adt, "/cpus"); + int node = adt_path_offset("/cpus"); if (node < 0) { printf("Error getting /cpus node\n"); return; @@ -324,12 +324,12 @@ void smp_start_secondaries(void) return; } - ADT_FOREACH_CHILD(adt, node) + ADT_FOREACH_CHILD(node) { u32 cpu_id; - if (ADT_GETPROP(adt, node, "cpu-id", &cpu_id) < 0) - if (ADT_GETPROP(adt, node, "reg", &cpu_id) < 0) + if (ADT_GETPROP(node, "cpu-id", &cpu_id) < 0) + if (ADT_GETPROP(node, "reg", &cpu_id) < 0) continue; if (cpu_id >= MAX_CPUS) { @@ -349,7 +349,7 @@ void smp_start_secondaries(void) int cpu_node = cpu_nodes[i]; if (!cpu_node) continue; - const char *state = adt_getprop(adt, cpu_node, "state", NULL); + const char *state = adt_getprop(cpu_node, "state", NULL); if (!state) continue; if (strcmp(state, "running") == 0) { @@ -384,7 +384,7 @@ void smp_start_secondaries(void) if (!iorvbar) continue; - if (ADT_GETPROP(adt, cpu_node, "reg", ®) < 0) + if (ADT_GETPROP(cpu_node, "reg", ®) < 0) continue; if (i == boot_cpu_idx) { @@ -422,7 +422,7 @@ void smp_stop_secondaries(bool deep_sleep) u32 reg; u64 iorvbar = smp_get_iorvbar(node, i); - if (ADT_GETPROP(adt, node, "reg", ®) < 0) + if (ADT_GETPROP(node, "reg", ®) < 0) continue; u8 core = FIELD_GET(CPU_REG_CORE, reg); diff --git a/src/spmi.c b/src/spmi.c index e4de96f98..d1ed55611 100644 --- a/src/spmi.c +++ b/src/spmi.c @@ -46,14 +46,14 @@ spmi_dev_t *spmi_init(const char *adt_node) { int adt_path[8]; int adt_offset; - adt_offset = adt_path_offset_trace(adt, adt_node, adt_path); + adt_offset = adt_path_offset_trace(adt_node, adt_path); if (adt_offset < 0) { printf("spmi: Error getting %s node\n", adt_node); return NULL; } u64 base; - if (adt_get_reg(adt, adt_path, "reg", 0, &base, NULL) < 0) { + if (adt_get_reg(adt_path, "reg", 0, &base, NULL) < 0) { printf("spmi: Error getting %s regs\n", adt_node); return NULL; } diff --git a/src/startup.c b/src/startup.c index 61afe169c..74ebee117 100644 --- a/src/startup.c +++ b/src/startup.c @@ -77,8 +77,8 @@ void dump_boot_args(struct boot_args *ba) printf(" top_of_kdata: 0x%lx\n", ba->top_of_kernel_data); printf(" video:\n"); printf(" base: 0x%lx\n", ba->video.base); - printf(" display: 0x%lx\n", ba->video.display); - printf(" stride: 0x%lx\n", ba->video.stride); + printf(" display: %lu\n", ba->video.display); + printf(" stride: %lu\n", ba->video.stride); printf(" width: %lu\n", ba->video.width); printf(" height: %lu\n", ba->video.height); printf(" depth: %lubpp\n", ba->video.depth & 0xff); @@ -86,7 +86,7 @@ void dump_boot_args(struct boot_args *ba) printf(" machine_type: %d\n", ba->machine_type); printf(" devtree: %p\n", ba->devtree); printf(" devtree_size: 0x%x\n", ba->devtree_size); - int node = adt_path_offset(adt, "/chosen"); + int node = adt_path_offset("/chosen"); if (node < 0) { printf("ADT: no /chosen found\n"); @@ -95,7 +95,7 @@ void dump_boot_args(struct boot_args *ba) /* This is called very early - before firmware information is initialized */ u32 len; - const char *p = adt_getprop(adt, node, "firmware-version", &len); + const char *p = adt_getprop(node, "firmware-version", &len); if (!p) { printf("ADT: failed to find firmware-version\n"); return; @@ -136,7 +136,7 @@ void dump_boot_args(struct boot_args *ba) } if (!mem_size_actual) { if (chip_id == T8012) { - int anode = adt_path_offset(adt, "/arm-io/mcc"); + int anode = adt_path_offset("/arm-io/mcc"); /* * For T8012, compute mem_size_actual from the amount of memory channels @@ -147,7 +147,7 @@ void dump_boot_args(struct boot_args *ba) */ u32 dcs_num_channels = 0; - if (anode > 0 && ADT_GETPROP(adt, anode, "dcs_num_channels", &dcs_num_channels) > 0) + if (anode > 0 && ADT_GETPROP(anode, "dcs_num_channels", &dcs_num_channels) > 0) mem_size_actual = dcs_num_channels * 0x20000000; else mem_size_actual = 0x40000000; @@ -172,15 +172,15 @@ void _start_c(void *boot_args, void *base) (void *)(((u64)cur_boot_args.devtree) - cur_boot_args.virt_base + cur_boot_args.phys_base); #ifndef BRINGUP - int node = adt_path_offset(adt, "/cpus"); + int node = adt_path_offset("/cpus"); if (node >= 0) { - ADT_FOREACH_CHILD(adt, node) + ADT_FOREACH_CHILD(node) { - const char *state = adt_getprop(adt, node, "state", NULL); + const char *state = adt_getprop(node, "state", NULL); if (!state) continue; if (strcmp(state, "running") == 0) - if (ADT_GETPROP(adt, node, "cpu-id", &cpu_id) == sizeof(cpu_id)) + if (ADT_GETPROP(node, "cpu-id", &cpu_id) == sizeof(cpu_id)) break; } } diff --git a/src/tps6598x.c b/src/tps6598x.c index 56735c173..a812dcdf0 100644 --- a/src/tps6598x.c +++ b/src/tps6598x.c @@ -27,13 +27,13 @@ struct tps6598x_dev { tps6598x_dev_t *tps6598x_init(const char *adt_node, i2c_dev_t *i2c) { int adt_offset; - adt_offset = adt_path_offset(adt, adt_node); + adt_offset = adt_path_offset(adt_node); if (adt_offset < 0) { printf("tps6598x: Error getting %s node\n", adt_node); return NULL; } - const u8 *iic_addr = adt_getprop(adt, adt_offset, "hpm-iic-addr", NULL); + const u8 *iic_addr = adt_getprop(adt_offset, "hpm-iic-addr", NULL); if (iic_addr == NULL) { printf("tps6598x: Error getting %s hpm-iic-addr\n.", adt_node); return NULL; @@ -197,7 +197,7 @@ int tps6598x_powerup(tps6598x_dev_t *dev) int tps6598x_enter_kis(tps6598x_dev_t *dev) { u32 target_len = 0; - const u8 *target = adt_getprop(adt, 0, "target-type", &target_len); + const u8 *target = adt_getprop(0, "target-type", &target_len); u8 key[4] = {0}; const u8 key_null[4] = {0, 0, 0, 0}; const u8 vdm[] = {0x06, 0x46, 0x82, 0x01}; @@ -259,36 +259,36 @@ int tps6598x_enable_debugusb(void) int node; int ret; - node = adt_path_offset(adt, "/arm-io"); + node = adt_path_offset("/arm-io"); if (node < 0) return -1; - ADT_FOREACH_CHILD(adt, node) + ADT_FOREACH_CHILD(node) { int mngr_node; - if (!adt_is_compatible(adt, node, "i2c,s5l8940x")) + if (!adt_is_compatible(node, "i2c,s5l8940x")) continue; - mngr_node = adt_first_child_offset(adt, node); - if (mngr_node < 0 || !adt_is_compatible(adt, mngr_node, "usbc,manager")) + mngr_node = adt_first_child_offset(node); + if (mngr_node < 0 || !adt_is_compatible(mngr_node, "usbc,manager")) continue; int it = mngr_node; - ADT_FOREACH_CHILD(adt, it) + ADT_FOREACH_CHILD(it) { - if (!adt_is_compatible(adt, it, "usbc,cd3217")) + if (!adt_is_compatible(it, "usbc,cd3217")) continue; - const char *name = adt_get_name(adt, it); + const char *name = adt_get_name(it); if (strcmp(name, "hpm0")) continue; - ret = snprintf(i2c_path, sizeof(i2c_path), "/arm-io/%s", adt_get_name(adt, node)); + ret = snprintf(i2c_path, sizeof(i2c_path), "/arm-io/%s", adt_get_name(node)); if (ret < 0 || (size_t)ret >= sizeof(i2c_path)) continue; - ret = snprintf(hpm_path, sizeof(hpm_path), "/arm-io/%s/%s/%s", adt_get_name(adt, node), - adt_get_name(adt, mngr_node), name); + ret = snprintf(hpm_path, sizeof(hpm_path), "/arm-io/%s/%s/%s", adt_get_name(node), + adt_get_name(mngr_node), name); if (ret < 0 || (size_t)ret >= sizeof(hpm_path)) continue; diff --git a/src/tunables.c b/src/tunables.c index ced789ece..342bc25a7 100644 --- a/src/tunables.c +++ b/src/tunables.c @@ -15,13 +15,13 @@ struct tunable_info { static int tunables_adt_find(const char *path, const char *prop, struct tunable_info *info, u32 item_size) { - info->node_offset = adt_path_offset_trace(adt, path, info->node_path); + info->node_offset = adt_path_offset_trace(path, info->node_path); if (info->node_offset < 0) { printf("tunable: unable to find ADT node %s.\n", path); return -1; } - info->tunable_raw = adt_getprop(adt, info->node_offset, prop, &info->tunable_len); + info->tunable_raw = adt_getprop(info->node_offset, prop, &info->tunable_len); if (info->tunable_raw == NULL || info->tunable_len == 0) { printf("tunable: Error getting ADT node %s property %s .\n", path, prop); return -1; @@ -57,7 +57,7 @@ int tunables_apply_global(const char *path, const char *prop) const struct tunable_global *tunable = &tunables[i]; u64 addr; - if (adt_get_reg(adt, info.node_path, "reg", tunable->reg_idx, &addr, NULL) < 0) { + if (adt_get_reg(info.node_path, "reg", tunable->reg_idx, &addr, NULL) < 0) { printf("tunable: Error getting regs with index %d\n", tunable->reg_idx); return -1; } @@ -115,7 +115,7 @@ int tunables_apply_local(const char *path, const char *prop, u32 reg_offset) return -1; u64 base; - if (adt_get_reg(adt, info.node_path, "reg", reg_offset, &base, NULL) < 0) { + if (adt_get_reg(info.node_path, "reg", reg_offset, &base, NULL) < 0) { printf("tunable: Error getting regs\n"); return -1; } diff --git a/src/uart.c b/src/uart.c index 6bd2dab61..fdf1ca57e 100644 --- a/src/uart.c +++ b/src/uart.c @@ -19,19 +19,19 @@ int uart_init(void) int path[8]; const char *uart_path; - if (adt_path_offset_trace(adt, "/arm-io/uart6/debug-console", NULL) > 0) { + if (adt_path_offset_trace("/arm-io/uart6/debug-console", NULL) > 0) { uart_path = "/arm-io/uart6"; /* T2 ADT does not have /arm-io/uart0/debug-console, but it is the correct UART */ - } else if (adt_path_offset_trace(adt, "/arm-io/uart0", NULL) > 0) { + } else if (adt_path_offset_trace("/arm-io/uart0", NULL) > 0) { uart_path = "/arm-io/uart0"; } else { printf("!!!Debug UART node not found!\n"); return -1; } - adt_path_offset_trace(adt, uart_path, path); + adt_path_offset_trace(uart_path, path); - if (adt_get_reg(adt, path, "reg", 0, &uart_base, NULL)) { + if (adt_get_reg(path, "reg", 0, &uart_base, NULL)) { printf("!!! Failed to get UART reg property!\n"); return -1; } diff --git a/src/usb.c b/src/usb.c index fce0d5d0a..661770fc3 100644 --- a/src/usb.c +++ b/src/usb.c @@ -73,14 +73,14 @@ static dart_dev_t *usb_dart_init(u32 idx) char path[sizeof(FMT_DART_MAPPER_PATH)]; snprintf(path, sizeof(path), FMT_DART_MAPPER_PATH, idx, idx); - mapper_offset = adt_path_offset(adt, path); + mapper_offset = adt_path_offset(path); if (mapper_offset < 0) { // Device not present return NULL; } u32 dart_idx; - if (ADT_GETPROP(adt, mapper_offset, "reg", &dart_idx) < 0) { + if (ADT_GETPROP(mapper_offset, "reg", &dart_idx) < 0) { printf("usb: Error getting DART %s device index/\n", path); return NULL; } @@ -99,28 +99,28 @@ static int usb_drd_get_regs(u32 idx, struct usb_drd_regs *regs) char drd_path[sizeof(FMT_DRD_PATH)]; snprintf(drd_path, sizeof(drd_path), FMT_DRD_PATH, idx); - adt_drd_offset = adt_path_offset_trace(adt, drd_path, adt_drd_path); + adt_drd_offset = adt_path_offset_trace(drd_path, adt_drd_path); if (adt_drd_offset < 0) { // Nonexistent device return -1; } snprintf(phy_path, sizeof(phy_path), FMT_ATC_PATH, idx); - adt_phy_offset = adt_path_offset_trace(adt, phy_path, adt_phy_path); + adt_phy_offset = adt_path_offset_trace(phy_path, adt_phy_path); if (adt_phy_offset < 0) { printf("usb: Error getting phy node %s\n", phy_path); return -1; } - if (adt_get_reg(adt, adt_phy_path, "reg", 0, ®s->atc, NULL) < 0) { + if (adt_get_reg(adt_phy_path, "reg", 0, ®s->atc, NULL) < 0) { printf("usb: Error getting reg with index 0 for %s.\n", phy_path); return -1; } - if (adt_get_reg(adt, adt_drd_path, "reg", 0, ®s->drd_regs, NULL) < 0) { + if (adt_get_reg(adt_drd_path, "reg", 0, ®s->drd_regs, NULL) < 0) { printf("usb: Error getting reg with index 0 for %s.\n", drd_path); return -1; } - if (adt_get_reg(adt, adt_drd_path, "reg", 3, ®s->drd_regs_unk3, NULL) < 0) { + if (adt_get_reg(adt_drd_path, "reg", 3, ®s->drd_regs_unk3, NULL) < 0) { printf("usb: Error getting reg with index 3 for %s.\n", drd_path); return -1; } @@ -270,18 +270,18 @@ static int usb_init_i2c(const char *i2c_path) { char hpm_path[MAX_HPM_PATH_LEN]; - int node = adt_path_offset(adt, i2c_path); + int node = adt_path_offset(i2c_path); if (node < 0) return 0; - node = adt_first_child_offset(adt, node); + node = adt_first_child_offset(node); if (node < 0) return 0; - if (!adt_is_compatible(adt, node, "usbc,manager")) + if (!adt_is_compatible(node, "usbc,manager")) return 0; - const char *hpm_mngr_name = adt_get_name(adt, node); + const char *hpm_mngr_name = adt_get_name(node); if (!hpm_mngr_name || strnlen(hpm_mngr_name, 16) >= 16) return 0; @@ -291,9 +291,9 @@ static int usb_init_i2c(const char *i2c_path) return -1; } - ADT_FOREACH_CHILD(adt, node) + ADT_FOREACH_CHILD(node) { - const char *name = adt_get_name(adt, node); + const char *name = adt_get_name(node); if (!name || memcmp(name, "hpm", 3) || name[4] != '\0') continue; // unexpected hpm node name u32 idx = name[3] - '0'; @@ -404,12 +404,12 @@ int usb_complex_init_adt(void) enum usb_complex_type type; u64 USBComplexBase, USB2Phy_Base = 0, DWC2Base; - usbComplex_offset = adt_path_offset_trace(adt, "/arm-io/usb-complex", usbComplex_path); + usbComplex_offset = adt_path_offset_trace("/arm-io/usb-complex", usbComplex_path); if (usbComplex_offset < 0) return -1; - otgctl_offset = adt_path_offset_trace(adt, "/arm-io/otgphyctrl", otgphyctrl_path); + otgctl_offset = adt_path_offset_trace("/arm-io/otgphyctrl", otgphyctrl_path); if (otgctl_offset < 0) { printf("usb: No /arm-io/otgphyctrl node \n"); return -1; @@ -417,7 +417,7 @@ int usb_complex_init_adt(void) for (uint32_t i = 0, max = 2; i < max; ++i) { u64 ctlsize, ctlbase; - if (adt_get_reg(adt, otgphyctrl_path, "reg", i, &ctlbase, &ctlsize) < 0) { + if (adt_get_reg(otgphyctrl_path, "reg", i, &ctlbase, &ctlsize) < 0) { printf("usb: failed to get /arm-io/otgphyctrl reg\n"); return -1; } @@ -432,17 +432,17 @@ int usb_complex_init_adt(void) return -1; } - if (adt_get_reg(adt, usbComplex_path, "reg", 0, &USBComplexBase, NULL) < 0) { + if (adt_get_reg(usbComplex_path, "reg", 0, &USBComplexBase, NULL) < 0) { printf("usb: Error getting USBComplexBase Reg\n"); return -1; } u32 cfg0, cfg1; - if (ADT_GETPROP(adt, otgctl_offset, "cfg0-device", &cfg0) < 0) { + if (ADT_GETPROP(otgctl_offset, "cfg0-device", &cfg0) < 0) { printf("usb: Error getting CFG0 from otgctl \n"); return -1; } - if (ADT_GETPROP(adt, otgctl_offset, "cfg1-device", &cfg1) < 0) { + if (ADT_GETPROP(otgctl_offset, "cfg1-device", &cfg1) < 0) { printf("usb: Error getting CFG1 from otgctl \n"); return -1; } @@ -450,13 +450,13 @@ int usb_complex_init_adt(void) // the usb-device on iPad Pro 2 is some USB3 device so derive dwc2 base from phy base instead DWC2Base = (USB2Phy_Base & ~0xfffULL) + 0x100000; - if (adt_is_compatible(adt, usbComplex_offset, "usb-complex,s5l8960x")) { + if (adt_is_compatible(usbComplex_offset, "usb-complex,s5l8960x")) { type = USBCOMPLEX_S5L8960X; - } else if (adt_is_compatible(adt, usbComplex_offset, "usb-complex,t8015")) { + } else if (adt_is_compatible(usbComplex_offset, "usb-complex,t8015")) { type = USBCOMPLEX_T8015; } // This must be last because of the fallback compatible to usb-complex,t8011 on t8015 - else if (adt_is_compatible(adt, usbComplex_offset, "usb-complex,t8011")) { + else if (adt_is_compatible(usbComplex_offset, "usb-complex,t8011")) { type = USBCOMPLEX_T8011; } else { printf("usb: unsupported USB complex type!\n"); @@ -494,7 +494,7 @@ void usb_init(void) * M3/M4 models do not use i2c, but instead SPMI with a new controller. * We can get USB going for now by just bringing up the phys. */ - if (adt_path_offset(adt, "/arm-io/nub-spmi-a0/hpm0") > 0) { + if (adt_path_offset("/arm-io/nub-spmi-a0/hpm0") > 0) { usb_spmi_init(); return; } @@ -503,13 +503,13 @@ void usb_init(void) * A7-A11 uses a custom internal otg phy with the peripheral part * being dwc2, role switch seems custom. */ - if (adt_path_offset(adt, "/arm-io/otgphyctrl") > 0 && - adt_path_offset(adt, "/arm-io/usb-complex") > 0) { + if (adt_path_offset("/arm-io/otgphyctrl") > 0 && + adt_path_offset("/arm-io/usb-complex") > 0) { usb_complex_init_adt(); return; } - if (adt_is_compatible(adt, 0, "J180dAP") && usb_init_i2c("/arm-io/i2c3") < 0) + if (adt_is_compatible(0, "J180dAP") && usb_init_i2c("/arm-io/i2c3") < 0) return; if (usb_init_i2c("/arm-io/i2c0") < 0) return; @@ -524,18 +524,18 @@ void usb_i2c_restore_irqs(const char *i2c_path, bool force) { char hpm_path[MAX_HPM_PATH_LEN]; - int node = adt_path_offset(adt, i2c_path); + int node = adt_path_offset(i2c_path); if (node < 0) return; - node = adt_first_child_offset(adt, node); + node = adt_first_child_offset(node); if (node < 0) return; - if (!adt_is_compatible(adt, node, "usbc,manager")) + if (!adt_is_compatible(node, "usbc,manager")) return; - const char *hpm_mngr_name = adt_get_name(adt, node); + const char *hpm_mngr_name = adt_get_name(node); if (!hpm_mngr_name || strnlen(hpm_mngr_name, 16) >= 16) return; @@ -545,9 +545,9 @@ void usb_i2c_restore_irqs(const char *i2c_path, bool force) return; } - ADT_FOREACH_CHILD(adt, node) + ADT_FOREACH_CHILD(node) { - const char *name = adt_get_name(adt, node); + const char *name = adt_get_name(node); if (!name || memcmp(name, "hpm", 3) || name[4] != '\0') continue; // unexpected hpm node name u32 idx = name[3] - '0'; @@ -578,25 +578,25 @@ void usb_hpm_restore_irqs(bool force) /* * Do not try to restore irqs on M3/M4 which don't use i2c */ - if (adt_path_offset(adt, "/arm-io/nub-spmi-a0/hpm0") > 0) + if (adt_path_offset("/arm-io/nub-spmi-a0/hpm0") > 0) return; /* * Do not try to restore irqs on A7-A11 which don't use i2c */ - if (adt_path_offset(adt, "/arm-io/otgphyctrl") > 0 && - adt_path_offset(adt, "/arm-io/usb-complex") > 0) + if (adt_path_offset("/arm-io/otgphyctrl") > 0 && + adt_path_offset("/arm-io/usb-complex") > 0) return; - if (adt_is_compatible(adt, 0, "J180dAP")) + if (adt_is_compatible(0, "J180dAP")) usb_i2c_restore_irqs("/arm-io/i2c3", force); usb_i2c_restore_irqs("/arm-io/i2c0", force); } void usb_iodev_init(void) { - if (adt_path_offset(adt, "/arm-io/otgphyctrl") > 0 && - adt_path_offset(adt, "/arm-io/usb-complex") > 0) { + if (adt_path_offset("/arm-io/otgphyctrl") > 0 && + adt_path_offset("/arm-io/usb-complex") > 0) { return; // already init in usb_init() since we do have only 1 usb port } for (int i = FIRST_USB_IODEV; i < USB_IODEV_COUNT; i++) { diff --git a/src/usb_dwc2.c b/src/usb_dwc2.c index 9220d62c0..8ef13b5fc 100644 --- a/src/usb_dwc2.c +++ b/src/usb_dwc2.c @@ -555,7 +555,7 @@ static void usb_build_serial(void) if (str_serial) return; - const char *serial = adt_getprop(adt, 0, "serial-number", NULL); + const char *serial = adt_getprop(0, "serial-number", NULL); if (!serial || !serial[0]) { str_serial = &str_serial_dummy; return; diff --git a/src/usb_dwc3.c b/src/usb_dwc3.c index 14db08f2c..f0c8b8e1b 100644 --- a/src/usb_dwc3.c +++ b/src/usb_dwc3.c @@ -535,7 +535,7 @@ static void usb_build_serial(void) if (str_serial) return; - const char *serial = adt_getprop(adt, 0, "serial-number", NULL); + const char *serial = adt_getprop(0, "serial-number", NULL); if (!serial || !serial[0]) { str_serial = &str_serial_dummy; return; diff --git a/src/utils.c b/src/utils.c index feeca6925..41018a72d 100644 --- a/src/utils.c +++ b/src/utils.c @@ -302,7 +302,7 @@ void cpu_sleep(bool deep) bool main_storage_init(void) { - int ans_node = adt_path_offset(adt, "/arm-io/ans"); + int ans_node = adt_path_offset("/arm-io/ans"); if (ans_node < 0) { /* A9/A9X/A10/A10X */ @@ -310,7 +310,7 @@ bool main_storage_init(void) return false; } - if (adt_is_compatible(adt, ans_node, "iop,s5l8960x")) { + if (adt_is_compatible(ans_node, "iop,s5l8960x")) { storage_type = STORAGE_TYPE_ANS1; return ans1_init(); } else { diff --git a/src/utils.h b/src/utils.h index 429db16eb..687e95b20 100644 --- a/src/utils.h +++ b/src/utils.h @@ -384,6 +384,7 @@ static inline size_t get_page_size(void) } extern char _base[]; +extern char _text_start[]; extern char _rodata_end[]; extern char _end[]; extern char _payload_start[]; diff --git a/src/wdt.c b/src/wdt.c index b69d76d13..20c8e5aba 100644 --- a/src/wdt.c +++ b/src/wdt.c @@ -14,14 +14,14 @@ static u64 wdt_base = 0; void wdt_disable(void) { int path[8]; - int node = adt_path_offset_trace(adt, "/arm-io/wdt", path); + int node = adt_path_offset_trace("/arm-io/wdt", path); if (node < 0) { printf("WDT node not found!\n"); return; } - if (adt_get_reg(adt, path, "reg", 0, &wdt_base, NULL)) { + if (adt_get_reg(path, "reg", 0, &wdt_base, NULL)) { printf("Failed to get WDT reg property!\n"); return; } @@ -32,12 +32,12 @@ void wdt_disable(void) // disable secondary watchdog if wdt-version is 2 or 3 u32 wdt_version; - if (ADT_GETPROP(adt, node, "wdt-version", &wdt_version) < 0) + if (ADT_GETPROP(node, "wdt-version", &wdt_version) < 0) return; if (wdt_version == 2 || wdt_version == 3) { u64 wdt_2nd = 0; - if (adt_get_reg(adt, path, "reg", 2, &wdt_2nd, NULL)) { + if (adt_get_reg(path, "reg", 2, &wdt_2nd, NULL)) { printf("Failed to get WDT reg[2] property!\n"); return; }