diff mbox series

[v5,04/19] libpdbg: Register hwunit drivers per backend

Message ID 20200430023440.225504-5-amitay@ozlabs.org
State Accepted
Headers show
Series Add sbefifo backend | expand

Commit Message

Amitay Isaacs April 30, 2020, 2:34 a.m. UTC
This will allow to load backend specific drivers first.  When searching
for drivers, match all compatible strings to backend specific drivers
first and then match all compatible strings to default backend.

All the drivers are registered with the default backend, so this patch
does not change libpdbg behaviour.

Signed-off-by: Amitay Isaacs <amitay@ozlabs.org>
Reviewed-by: Alistair Popple <alistair@popple.id.au>
---
 libpdbg/adu.c             |  4 +--
 libpdbg/bmcfsi.c          |  2 +-
 libpdbg/cfam.c            |  8 +++---
 libpdbg/chip.c            |  2 +-
 libpdbg/cronus.c          |  6 ++---
 libpdbg/device.c          | 15 +++--------
 libpdbg/fake.c            |  8 +++---
 libpdbg/host.c            |  2 +-
 libpdbg/htm.c             |  6 ++---
 libpdbg/hwunit.c          | 51 +++++++++++++++++++++++++++++++-------
 libpdbg/hwunit.h          |  5 ++--
 libpdbg/i2c.c             |  2 +-
 libpdbg/kernel.c          |  4 +--
 libpdbg/p8chip.c          |  4 +--
 libpdbg/p9_fapi_targets.c | 52 +++++++++++++++++++--------------------
 libpdbg/p9chip.c          |  4 +--
 libpdbg/sbefifo.c         |  8 +++---
 17 files changed, 105 insertions(+), 78 deletions(-)
diff mbox series

Patch

diff --git a/libpdbg/adu.c b/libpdbg/adu.c
index df610a7..fe60118 100644
--- a/libpdbg/adu.c
+++ b/libpdbg/adu.c
@@ -597,6 +597,6 @@  DECLARE_HW_UNIT(p9_adu);
 __attribute__((constructor))
 static void register_adu(void)
 {
-	pdbg_hwunit_register(&p8_adu_hw_unit);
-	pdbg_hwunit_register(&p9_adu_hw_unit);
+	pdbg_hwunit_register(PDBG_DEFAULT_BACKEND, &p8_adu_hw_unit);
+	pdbg_hwunit_register(PDBG_DEFAULT_BACKEND, &p9_adu_hw_unit);
 }
diff --git a/libpdbg/bmcfsi.c b/libpdbg/bmcfsi.c
index 1d2e304..2639595 100644
--- a/libpdbg/bmcfsi.c
+++ b/libpdbg/bmcfsi.c
@@ -519,5 +519,5 @@  DECLARE_HW_UNIT(bmcfsi);
 __attribute__((constructor))
 static void register_bmcfsi(void)
 {
-	pdbg_hwunit_register(&bmcfsi_hw_unit);
+	pdbg_hwunit_register(PDBG_DEFAULT_BACKEND, &bmcfsi_hw_unit);
 }
diff --git a/libpdbg/cfam.c b/libpdbg/cfam.c
index da4c5fc..0b0b6f0 100644
--- a/libpdbg/cfam.c
+++ b/libpdbg/cfam.c
@@ -353,8 +353,8 @@  DECLARE_HW_UNIT(cfam_hmfsi);
 __attribute__((constructor))
 static void register_cfam(void)
 {
-	pdbg_hwunit_register(&fsi_pib_hw_unit);
-	pdbg_hwunit_register(&p8_opb_hw_unit);
-	pdbg_hwunit_register(&p8_opb_hmfsi_hw_unit);
-	pdbg_hwunit_register(&cfam_hmfsi_hw_unit);
+	pdbg_hwunit_register(PDBG_DEFAULT_BACKEND, &fsi_pib_hw_unit);
+	pdbg_hwunit_register(PDBG_DEFAULT_BACKEND, &p8_opb_hw_unit);
+	pdbg_hwunit_register(PDBG_DEFAULT_BACKEND, &p8_opb_hmfsi_hw_unit);
+	pdbg_hwunit_register(PDBG_DEFAULT_BACKEND, &cfam_hmfsi_hw_unit);
 }
diff --git a/libpdbg/chip.c b/libpdbg/chip.c
index b45cffa..b961e87 100644
--- a/libpdbg/chip.c
+++ b/libpdbg/chip.c
@@ -679,5 +679,5 @@  DECLARE_HW_UNIT(proc);
 __attribute__((constructor))
 static void register_proc(void)
 {
-	pdbg_hwunit_register(&proc_hw_unit);
+	pdbg_hwunit_register(PDBG_DEFAULT_BACKEND, &proc_hw_unit);
 }
diff --git a/libpdbg/cronus.c b/libpdbg/cronus.c
index ff8af4c..23d555b 100644
--- a/libpdbg/cronus.c
+++ b/libpdbg/cronus.c
@@ -219,7 +219,7 @@  DECLARE_HW_UNIT(cronus_sbefifo);
 __attribute__((constructor))
 static void register_cronus(void)
 {
-	pdbg_hwunit_register(&cronus_pib_hw_unit);
-	pdbg_hwunit_register(&cronus_fsi_hw_unit);
-	pdbg_hwunit_register(&cronus_sbefifo_hw_unit);
+	pdbg_hwunit_register(PDBG_DEFAULT_BACKEND, &cronus_pib_hw_unit);
+	pdbg_hwunit_register(PDBG_DEFAULT_BACKEND, &cronus_fsi_hw_unit);
+	pdbg_hwunit_register(PDBG_DEFAULT_BACKEND, &cronus_sbefifo_hw_unit);
 }
diff --git a/libpdbg/device.c b/libpdbg/device.c
index 219569e..8db6572 100644
--- a/libpdbg/device.c
+++ b/libpdbg/device.c
@@ -60,23 +60,16 @@  static struct pdbg_target *dt_pdbg_target_new(const void *fdt, int node_offset)
 
 	prop = fdt_get_property(fdt, node_offset, "compatible", NULL);
 	if (prop) {
-		int i, prop_len = fdt32_to_cpu(prop->len);
+		uint32_t prop_len = fdt32_to_cpu(prop->len);
 
 		/*
 		 * If I understand correctly, the property we have
 		 * here can be a stringlist with a few compatible
 		 * strings
 		 */
-		i = 0;
-		while (i < prop_len) {
-			hw_info = pdbg_hwunit_find_compatible(&prop->data[i]);
-			if (hw_info) {
-				size = hw_info->size;
-				break;
-			}
-
-			i += strlen(&prop->data[i]) + 1;
-		}
+		hw_info = pdbg_hwunit_find_compatible(prop->data, prop_len);
+		if (hw_info)
+			size = hw_info->size;
 	}
 
 	if (!hw_info)
diff --git a/libpdbg/fake.c b/libpdbg/fake.c
index 82415db..ae02463 100644
--- a/libpdbg/fake.c
+++ b/libpdbg/fake.c
@@ -90,8 +90,8 @@  DECLARE_HW_UNIT(fake_thread);
 __attribute__((constructor))
 static void register_fake(void)
 {
-	pdbg_hwunit_register(&fake_fsi_hw_unit);
-	pdbg_hwunit_register(&fake_pib_hw_unit);
-	pdbg_hwunit_register(&fake_core_hw_unit);
-	pdbg_hwunit_register(&fake_thread_hw_unit);
+	pdbg_hwunit_register(PDBG_DEFAULT_BACKEND, &fake_fsi_hw_unit);
+	pdbg_hwunit_register(PDBG_DEFAULT_BACKEND, &fake_pib_hw_unit);
+	pdbg_hwunit_register(PDBG_DEFAULT_BACKEND, &fake_core_hw_unit);
+	pdbg_hwunit_register(PDBG_DEFAULT_BACKEND, &fake_thread_hw_unit);
 }
diff --git a/libpdbg/host.c b/libpdbg/host.c
index 428c18b..d02b53d 100644
--- a/libpdbg/host.c
+++ b/libpdbg/host.c
@@ -127,5 +127,5 @@  DECLARE_HW_UNIT(host_pib);
 __attribute__((constructor))
 static void register_host(void)
 {
-	pdbg_hwunit_register(&host_pib_hw_unit);
+	pdbg_hwunit_register(PDBG_DEFAULT_BACKEND, &host_pib_hw_unit);
 }
diff --git a/libpdbg/htm.c b/libpdbg/htm.c
index 4d23e82..a259478 100644
--- a/libpdbg/htm.c
+++ b/libpdbg/htm.c
@@ -1158,7 +1158,7 @@  DECLARE_HW_UNIT(p8_chtm);
 __attribute__((constructor))
 static void register_htm(void)
 {
-	pdbg_hwunit_register(&p8_nhtm_hw_unit);
-	pdbg_hwunit_register(&p9_nhtm_hw_unit);
-	pdbg_hwunit_register(&p8_chtm_hw_unit);
+	pdbg_hwunit_register(PDBG_DEFAULT_BACKEND, &p8_nhtm_hw_unit);
+	pdbg_hwunit_register(PDBG_DEFAULT_BACKEND, &p9_nhtm_hw_unit);
+	pdbg_hwunit_register(PDBG_DEFAULT_BACKEND, &p8_chtm_hw_unit);
 }
diff --git a/libpdbg/hwunit.c b/libpdbg/hwunit.c
index c7ec63d..074ddef 100644
--- a/libpdbg/hwunit.c
+++ b/libpdbg/hwunit.c
@@ -20,26 +20,28 @@ 
 #include "hwunit.h"
 
 #define MAX_HW_UNITS	1024
+#define MAX_BACKENDS	16
 
-static const struct hw_unit_info *g_hw_unit[MAX_HW_UNITS];
-static int g_hw_unit_count;
+static const struct hw_unit_info *g_hw_unit[MAX_BACKENDS][MAX_HW_UNITS];
+static int g_hw_unit_count[MAX_BACKENDS];
 
-void pdbg_hwunit_register(const struct hw_unit_info *hw_unit)
+void pdbg_hwunit_register(enum pdbg_backend backend, const struct hw_unit_info *hw_unit)
 {
-	assert(g_hw_unit_count < MAX_HW_UNITS);
+	assert(g_hw_unit_count[backend] < MAX_HW_UNITS);
 
-	g_hw_unit[g_hw_unit_count] = hw_unit;
-	g_hw_unit_count++;
+	g_hw_unit[backend][g_hw_unit_count[backend]] = hw_unit;
+	g_hw_unit_count[backend]++;
 }
 
-const struct hw_unit_info *pdbg_hwunit_find_compatible(const char *compat)
+static const struct hw_unit_info *find_driver(enum pdbg_backend backend,
+					      const char *compat)
 {
 	const struct hw_unit_info *p;
 	struct pdbg_target *target;
 	int i;
 
-	for (i = 0; i < g_hw_unit_count; i++) {
-		p = g_hw_unit[i];
+	for (i = 0; i < g_hw_unit_count[backend]; i++) {
+		p = g_hw_unit[backend][i];
 		target = p->hw_unit;
 
 		if (!strcmp(target->compatible, compat))
@@ -48,3 +50,34 @@  const struct hw_unit_info *pdbg_hwunit_find_compatible(const char *compat)
 
 	return NULL;
 }
+
+static const struct hw_unit_info *find_compatible(enum pdbg_backend backend,
+						  const char *compat_list,
+						  uint32_t len)
+{
+	const struct hw_unit_info *p;
+	uint32_t i;
+
+	i = 0;
+	while (i < len) {
+		p = find_driver(backend, &compat_list[i]);
+		if (p)
+			return p;
+
+		i += strlen(&compat_list[i]) + 1;
+	}
+
+	return NULL;
+}
+
+const struct hw_unit_info *pdbg_hwunit_find_compatible(const char *compat_list,
+						       uint32_t len)
+{
+	const struct hw_unit_info *p;
+
+	p = find_compatible(pdbg_get_backend(), compat_list, len);
+	if (!p)
+		p = find_compatible(PDBG_DEFAULT_BACKEND, compat_list, len);
+
+	return p;
+}
diff --git a/libpdbg/hwunit.h b/libpdbg/hwunit.h
index 7165a3c..dd41da7 100644
--- a/libpdbg/hwunit.h
+++ b/libpdbg/hwunit.h
@@ -31,8 +31,9 @@  struct hw_unit_info {
 	size_t size;
 };
 
-void pdbg_hwunit_register(const struct hw_unit_info *hw_unit);
-const struct hw_unit_info *pdbg_hwunit_find_compatible(const char *compat);
+void pdbg_hwunit_register(enum pdbg_backend backend, const struct hw_unit_info *hw_unit);
+const struct hw_unit_info *pdbg_hwunit_find_compatible(const char *compat_list,
+						       uint32_t len);
 
 /*
  * If this macro fails to compile for you, you've probably not
diff --git a/libpdbg/i2c.c b/libpdbg/i2c.c
index 1a5d089..3d0b80a 100644
--- a/libpdbg/i2c.c
+++ b/libpdbg/i2c.c
@@ -177,5 +177,5 @@  DECLARE_HW_UNIT(p8_i2c_pib);
 __attribute__((constructor))
 static void register_i2c(void)
 {
-	pdbg_hwunit_register(&p8_i2c_pib_hw_unit);
+	pdbg_hwunit_register(PDBG_DEFAULT_BACKEND, &p8_i2c_pib_hw_unit);
 }
diff --git a/libpdbg/kernel.c b/libpdbg/kernel.c
index dbd3586..c4637a7 100644
--- a/libpdbg/kernel.c
+++ b/libpdbg/kernel.c
@@ -264,6 +264,6 @@  DECLARE_HW_UNIT(kernel_pib);
 __attribute__((constructor))
 static void register_kernel(void)
 {
-	pdbg_hwunit_register(&kernel_fsi_hw_unit);
-	pdbg_hwunit_register(&kernel_pib_hw_unit);
+	pdbg_hwunit_register(PDBG_DEFAULT_BACKEND, &kernel_fsi_hw_unit);
+	pdbg_hwunit_register(PDBG_DEFAULT_BACKEND, &kernel_pib_hw_unit);
 }
diff --git a/libpdbg/p8chip.c b/libpdbg/p8chip.c
index 1bf71e8..484d77c 100644
--- a/libpdbg/p8chip.c
+++ b/libpdbg/p8chip.c
@@ -738,6 +738,6 @@  DECLARE_HW_UNIT(p8_core);
 __attribute__((constructor))
 static void register_p8chip(void)
 {
-	pdbg_hwunit_register(&p8_thread_hw_unit);
-	pdbg_hwunit_register(&p8_core_hw_unit);
+	pdbg_hwunit_register(PDBG_DEFAULT_BACKEND, &p8_thread_hw_unit);
+	pdbg_hwunit_register(PDBG_DEFAULT_BACKEND, &p8_core_hw_unit);
 }
diff --git a/libpdbg/p9_fapi_targets.c b/libpdbg/p9_fapi_targets.c
index 1dc7af8..97680d5 100644
--- a/libpdbg/p9_fapi_targets.c
+++ b/libpdbg/p9_fapi_targets.c
@@ -720,30 +720,30 @@  DECLARE_HW_UNIT(p9_capp);
 __attribute__((constructor))
 static void register_p9_fapi_targets(void)
 {
-	pdbg_hwunit_register(&p9_ex_hw_unit);
-	pdbg_hwunit_register(&p9_mba_hw_unit);
-	pdbg_hwunit_register(&p9_mcs_hw_unit);
-	pdbg_hwunit_register(&p9_xbus_hw_unit);
-	pdbg_hwunit_register(&p9_abus_hw_unit);
-	pdbg_hwunit_register(&p9_l4_hw_unit);
-	pdbg_hwunit_register(&p9_eq_hw_unit);
-	pdbg_hwunit_register(&p9_mca_hw_unit);
-	pdbg_hwunit_register(&p9_mcbist_hw_unit);
-	pdbg_hwunit_register(&p9_mi_hw_unit);
-	pdbg_hwunit_register(&p9_dmi_hw_unit);
-	pdbg_hwunit_register(&p9_obus_hw_unit);
-	pdbg_hwunit_register(&p9_obus_brick_hw_unit);
-	pdbg_hwunit_register(&p9_sbe_hw_unit);
-	pdbg_hwunit_register(&p9_ppe_hw_unit);
-	pdbg_hwunit_register(&p9_pec_hw_unit);
-	pdbg_hwunit_register(&p9_phb_hw_unit);
-	pdbg_hwunit_register(&p9_mc_hw_unit);
-	pdbg_hwunit_register(&p9_mem_port_hw_unit);
-	pdbg_hwunit_register(&p9_nmmu_hw_unit);
-	pdbg_hwunit_register(&p9_pau_hw_unit);
-	pdbg_hwunit_register(&p9_iohs_hw_unit);
-	pdbg_hwunit_register(&p9_fc_hw_unit);
-	pdbg_hwunit_register(&p9_pauc_hw_unit);
-	pdbg_hwunit_register(&p9_chiplet_hw_unit);
-	pdbg_hwunit_register(&p9_capp_hw_unit);
+	pdbg_hwunit_register(PDBG_DEFAULT_BACKEND, &p9_ex_hw_unit);
+	pdbg_hwunit_register(PDBG_DEFAULT_BACKEND, &p9_mba_hw_unit);
+	pdbg_hwunit_register(PDBG_DEFAULT_BACKEND, &p9_mcs_hw_unit);
+	pdbg_hwunit_register(PDBG_DEFAULT_BACKEND, &p9_xbus_hw_unit);
+	pdbg_hwunit_register(PDBG_DEFAULT_BACKEND, &p9_abus_hw_unit);
+	pdbg_hwunit_register(PDBG_DEFAULT_BACKEND, &p9_l4_hw_unit);
+	pdbg_hwunit_register(PDBG_DEFAULT_BACKEND, &p9_eq_hw_unit);
+	pdbg_hwunit_register(PDBG_DEFAULT_BACKEND, &p9_mca_hw_unit);
+	pdbg_hwunit_register(PDBG_DEFAULT_BACKEND, &p9_mcbist_hw_unit);
+	pdbg_hwunit_register(PDBG_DEFAULT_BACKEND, &p9_mi_hw_unit);
+	pdbg_hwunit_register(PDBG_DEFAULT_BACKEND, &p9_dmi_hw_unit);
+	pdbg_hwunit_register(PDBG_DEFAULT_BACKEND, &p9_obus_hw_unit);
+	pdbg_hwunit_register(PDBG_DEFAULT_BACKEND, &p9_obus_brick_hw_unit);
+	pdbg_hwunit_register(PDBG_DEFAULT_BACKEND, &p9_sbe_hw_unit);
+	pdbg_hwunit_register(PDBG_DEFAULT_BACKEND, &p9_ppe_hw_unit);
+	pdbg_hwunit_register(PDBG_DEFAULT_BACKEND, &p9_pec_hw_unit);
+	pdbg_hwunit_register(PDBG_DEFAULT_BACKEND, &p9_phb_hw_unit);
+	pdbg_hwunit_register(PDBG_DEFAULT_BACKEND, &p9_mc_hw_unit);
+	pdbg_hwunit_register(PDBG_DEFAULT_BACKEND, &p9_mem_port_hw_unit);
+	pdbg_hwunit_register(PDBG_DEFAULT_BACKEND, &p9_nmmu_hw_unit);
+	pdbg_hwunit_register(PDBG_DEFAULT_BACKEND, &p9_pau_hw_unit);
+	pdbg_hwunit_register(PDBG_DEFAULT_BACKEND, &p9_iohs_hw_unit);
+	pdbg_hwunit_register(PDBG_DEFAULT_BACKEND, &p9_fc_hw_unit);
+	pdbg_hwunit_register(PDBG_DEFAULT_BACKEND, &p9_pauc_hw_unit);
+	pdbg_hwunit_register(PDBG_DEFAULT_BACKEND, &p9_chiplet_hw_unit);
+	pdbg_hwunit_register(PDBG_DEFAULT_BACKEND, &p9_capp_hw_unit);
 }
diff --git a/libpdbg/p9chip.c b/libpdbg/p9chip.c
index 63434ee..6222dc3 100644
--- a/libpdbg/p9chip.c
+++ b/libpdbg/p9chip.c
@@ -510,6 +510,6 @@  DECLARE_HW_UNIT(p9_core);
 __attribute__((constructor))
 static void register_p9chip(void)
 {
-	pdbg_hwunit_register(&p9_thread_hw_unit);
-	pdbg_hwunit_register(&p9_core_hw_unit);
+	pdbg_hwunit_register(PDBG_DEFAULT_BACKEND, &p9_thread_hw_unit);
+	pdbg_hwunit_register(PDBG_DEFAULT_BACKEND, &p9_core_hw_unit);
 }
diff --git a/libpdbg/sbefifo.c b/libpdbg/sbefifo.c
index 41e68e9..22f11f1 100644
--- a/libpdbg/sbefifo.c
+++ b/libpdbg/sbefifo.c
@@ -321,8 +321,8 @@  DECLARE_HW_UNIT(kernel_sbefifo);
 __attribute__((constructor))
 static void register_sbefifo(void)
 {
-	pdbg_hwunit_register(&kernel_sbefifo_hw_unit);
-	pdbg_hwunit_register(&sbefifo_chipop_hw_unit);
-	pdbg_hwunit_register(&sbefifo_mem_hw_unit);
-	pdbg_hwunit_register(&sbefifo_pba_hw_unit);
+	pdbg_hwunit_register(PDBG_DEFAULT_BACKEND, &kernel_sbefifo_hw_unit);
+	pdbg_hwunit_register(PDBG_DEFAULT_BACKEND, &sbefifo_chipop_hw_unit);
+	pdbg_hwunit_register(PDBG_DEFAULT_BACKEND, &sbefifo_mem_hw_unit);
+	pdbg_hwunit_register(PDBG_DEFAULT_BACKEND, &sbefifo_pba_hw_unit);
 }