[RFC,06/12] libpdbg: Add infrastructure to link backend nodes
diff mbox series

Message ID 20190806013723.4047-7-alistair@popple.id.au
State New
Headers show
Series
  • Split backends from system description
Related show

Checks

Context Check Description
snowpatch_ozlabs/build-multiarch fail Test build-multiarch on branch master
snowpatch_ozlabs/apply_patch success Successfully applied on branch master (3a46123baa267a1bc6e03c50449a42e8d321bf86)

Commit Message

Alistair Popple Aug. 6, 2019, 1:37 a.m. UTC
Signed-off-by: Alistair Popple <alistair@popple.id.au>
---
 Makefile.am       |  3 ++-
 backend.dts.m4    |  4 ++++
 libpdbg/device.c  | 60 +++++++++++++++++++++++++++++++++++++++++++++++
 libpdbg/dtb.c     |  6 +++++
 libpdbg/libpdbg.h |  3 +++
 5 files changed, 75 insertions(+), 1 deletion(-)
 create mode 100644 backend.dts.m4

Patch
diff mbox series

diff --git a/Makefile.am b/Makefile.am
index 011e686..0f2906a 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -35,6 +35,7 @@  AM_CFLAGS = -I$(top_srcdir)/ccan/array_size -Wall -Werror -O2
 
 EXTRA_DIST = \
 	fake.dts.m4 \
+	backend.dts.m4 \
 	p8-fsi.dts.m4 \
 	p8-host.dts.m4 \
 	p8-i2c.dts.m4 \
@@ -63,7 +64,7 @@  if TARGET_PPC
 ARCH_FLAGS="-DTARGET_PPC=1"
 endif
 
-DT = fake.dts p8-cronus.dts p9-cronus.dts \
+DT = fake.dts backend.dts p8-cronus.dts p9-cronus.dts \
      p8-fsi.dts p8-i2c.dts p8-kernel.dts \
      p9w-fsi.dts p9r-fsi.dts p9z-fsi.dts p9-kernel.dts \
      p8-host.dts p9-host.dts
diff --git a/backend.dts.m4 b/backend.dts.m4
new file mode 100644
index 0000000..e160dad
--- /dev/null
+++ b/backend.dts.m4
@@ -0,0 +1,4 @@ 
+/dts-v1/;
+
+/ {
+};
diff --git a/libpdbg/device.c b/libpdbg/device.c
index 2fcb184..7a913b2 100644
--- a/libpdbg/device.c
+++ b/libpdbg/device.c
@@ -39,6 +39,7 @@ 
 static uint32_t last_phandle = 0;
 
 static struct pdbg_target *pdbg_dt_root;
+static struct pdbg_target *pdbg_backend_dt_root;
 
 /*
  * An in-memory representation of a node in the device tree.
@@ -637,6 +638,65 @@  void pdbg_targets_init(void *fdt)
 	dt_expand(pdbg_dt_root, fdt);
 }
 
+static struct pdbg_target *pdbg_get_system_target(struct pdbg_target *backend_target)
+{
+	const char *system_path;
+	struct pdbg_target *system_target = NULL;
+
+	system_path = pdbg_target_property(backend_target, "system-path", NULL);
+
+	/* This is a backend node that needs to be linked to a system target */
+	if (system_path) {
+		system_target = dt_find_by_path(pdbg_dt_root, system_path);
+	}
+
+	return system_target;
+}
+
+static void pdbg_link_backend_targets(struct pdbg_target *backend_target)
+{
+	struct pdbg_target *system_target, *child;
+
+	system_target = pdbg_get_system_target(backend_target);
+	if (system_target) {
+		PR_DEBUG("Linking backend target %s to system target %s\n",
+			 pdbg_target_path(backend_target), pdbg_target_path(system_target));
+
+		/* The backend class must match the system class */
+		assert(!strcmp(pdbg_target_class_name(backend_target),
+			       pdbg_target_class_name(system_target)));
+		system_target->backend = backend_target;
+
+		/* A backend target shoudl always use it's own implementation for access */
+		backend_target->backend = backend_target;
+	} else {
+		PR_INFO("Unable to match backend at %s to system target %s",
+			pdbg_target_path(backend_target), pdbg_target_path(system_target));
+	}
+
+	/* Recursively link all child targets as well */
+	pdbg_for_each_child_target(backend_target, child)
+		pdbg_link_backend_targets(child);
+}
+
+void pdbg_backend_init(void *fdt)
+{
+	pdbg_backend_dt_root = dt_new_node("", NULL, 0);
+
+	if (!fdt)
+		fdt = pdbg_default_backend_dtb();
+
+	if (!fdt) {
+		pdbg_log(PDBG_ERROR, "Could not find a system backend to use\n");
+		return;
+	}
+
+	dt_expand(pdbg_backend_dt_root, fdt);
+
+	/* Link the backend nodes to the system targets */
+	pdbg_link_backend_targets(pdbg_backend_dt_root);
+}
+
 char *pdbg_target_path(const struct pdbg_target *target)
 {
 	return dt_get_path(target);
diff --git a/libpdbg/dtb.c b/libpdbg/dtb.c
index 6c4beed..f6b235f 100644
--- a/libpdbg/dtb.c
+++ b/libpdbg/dtb.c
@@ -41,6 +41,7 @@ 
 #include "p9-host.dt.h"
 #include "p8-cronus.dt.h"
 #include "p9-cronus.dt.h"
+#include "backend.dt.h"
 
 #define AMI_BMC "/proc/ractrends/Helper/FwInfo"
 #define OPENFSI_BMC "/sys/bus/platform/devices/gpio-fsi/fsi0/"
@@ -296,3 +297,8 @@  void *pdbg_default_dtb(void)
 		break;
 	}
 }
+
+void *pdbg_default_backend_dtb(void)
+{
+	return &_binary_backend_dtb_o_start;
+}
diff --git a/libpdbg/libpdbg.h b/libpdbg/libpdbg.h
index 25bfd97..b819c56 100644
--- a/libpdbg/libpdbg.h
+++ b/libpdbg/libpdbg.h
@@ -102,6 +102,7 @@  uint64_t pdbg_target_address(struct pdbg_target *target, uint64_t *size);
 
 /* Misc. */
 void pdbg_targets_init(void *fdt);
+void pdbg_backend_init(void *fdt);
 void pdbg_target_probe_all(struct pdbg_target *parent);
 enum pdbg_target_status pdbg_target_probe(struct pdbg_target *target);
 void pdbg_target_release(struct pdbg_target *target);
@@ -109,6 +110,7 @@  enum pdbg_target_status pdbg_target_status(struct pdbg_target *target);
 void pdbg_target_status_set(struct pdbg_target *target, enum pdbg_target_status status);
 int pdbg_set_backend(enum pdbg_backend backend, const char *backend_option);
 void *pdbg_default_dtb(void);
+void *pdbg_default_backend_dtb(void);
 uint32_t pdbg_target_index(struct pdbg_target *target);
 char *pdbg_target_path(const struct pdbg_target *target);
 struct pdbg_target *pdbg_target_from_path(struct pdbg_target *target, const char *path);
@@ -119,6 +121,7 @@  const char *pdbg_target_dn_name(struct pdbg_target *target);
 void *pdbg_target_priv(struct pdbg_target *target);
 void pdbg_target_priv_set(struct pdbg_target *target, void *priv);
 struct pdbg_target *pdbg_target_root(void);
+struct pdbg_target *pdbg_backend_root(void);
 bool pdbg_target_compatible(struct pdbg_target *target, const char *compatible);
 
 /* Translate an address offset for a target to absolute address in address