From 233264cda2da36fc20e5354f63afcbeb75ba233c Mon Sep 17 00:00:00 2001 From: Janne Grunau Date: Wed, 6 Apr 2022 22:29:35 +0200 Subject: [PATCH] dart: add dart_init_fdt() Used to intialize by FDT phandle. Signed-off-by: Janne Grunau --- src/dart.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ src/dart.h | 1 + 2 files changed, 49 insertions(+) diff --git a/src/dart.c b/src/dart.c index 2a5f2e69..f8d32478 100644 --- a/src/dart.c +++ b/src/dart.c @@ -8,6 +8,8 @@ #include "string.h" #include "utils.h" +#include "libfdt/libfdt.h" + #define DART_T8020_CONFIG 0x60 #define DART_T8020_CONFIG_LOCK BIT(15) @@ -318,6 +320,52 @@ dart_dev_t *dart_init_adt(const char *path, int instance, int device, bool keep_ return dart; } +dart_dev_t *dart_init_fdt(void *dt, u32 phandle, int device, bool keep_pts) +{ + int node = fdt_node_offset_by_phandle(dt, phandle); + if (node < 0) { + printf("FDT: node for phandle %u not found\n", phandle); + return NULL; + } + + int len; + const void *prop = fdt_getprop(dt, node, "reg", &len); + if (!prop || len < 8) { + return NULL; + } + uintptr_t base = fdt64_ld((const fdt64_t *)prop); + if (!base) + return NULL; + + enum dart_type_t type; + const char *type_s; + const char *name = fdt_get_name(dt, node, NULL); + + if (fdt_node_check_compatible(dt, node, "apple,t8103-dart") == 0) { + type = DART_T8020; + type_s = "t8020"; + } else if (fdt_node_check_compatible(dt, node, "apple,t6000-dart") == 0) { + type = DART_T6000; + type_s = "t6000"; + } else if (fdt_node_check_compatible(dt, node, "apple,t8110-dart") == 0) { + type = DART_T8110; + type_s = "t8110"; + } else { + printf("dart: dart %s at 0x%lx is of an unknown type\n", name, base); + return NULL; + } + + dart_dev_t *dart = dart_init(base, device, keep_pts, type); + + if (!dart) + return NULL; + + printf("dart: dart %s at 0x%lx is a %s%s\n", name, base, type_s, + dart->locked ? " (locked)" : ""); + + return dart; +} + int dart_setup_pt_region(dart_dev_t *dart, const char *path, int device) { /* only device 0 of dart-dcp and dart-disp0 are of interest */ diff --git a/src/dart.h b/src/dart.h index 254506bc..42f9f7c6 100644 --- a/src/dart.h +++ b/src/dart.h @@ -18,6 +18,7 @@ enum dart_type_t { dart_dev_t *dart_init(uintptr_t base, u8 device, bool keep_pts, enum dart_type_t type); dart_dev_t *dart_init_adt(const char *path, int instance, int device, bool keep_pts); +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); int dart_map(dart_dev_t *dart, uintptr_t iova, void *bfr, size_t len); void dart_unmap(dart_dev_t *dart, uintptr_t iova, size_t len);