[Pdbg] [PATCH v2 14/15] main: Convert getscom/putscom to use path based targeting

Amitay Isaacs amitay at ozlabs.org
Fri Nov 9 18:10:10 AEDT 2018


Signed-off-by: Amitay Isaacs <amitay at ozlabs.org>
---
 src/scom.c           | 87 +++++++++++++++++++++++++++++++++++---------
 tests/test_hw_bmc.sh |  2 +-
 2 files changed, 70 insertions(+), 19 deletions(-)

diff --git a/src/scom.c b/src/scom.c
index 2372e91..ad70523 100644
--- a/src/scom.c
+++ b/src/scom.c
@@ -18,41 +18,92 @@
 #include <stdlib.h>
 #include <string.h>
 #include <inttypes.h>
+#include <assert.h>
 
 #include <libpdbg.h>
 
 #include "main.h"
 #include "optcmd.h"
+#include "path.h"
 
-static int _getscom(struct pdbg_target *target, uint32_t index, uint64_t *addr, uint64_t *unused)
+/* Check if a target has scom region */
+static bool scommable(struct pdbg_target *target)
 {
-	uint64_t value;
-
-	if (pib_read(target, *addr, &value))
-		return 0;
+	char *classname;
 
-	printf("p%d:0x%" PRIx64 " = 0x%016" PRIx64 "\n", index, *addr, value);
+	classname = pdbg_target_class_name(target);
+	if (!strcmp(classname, "pib") ||
+	    !strcmp(classname, "core") ||
+	    !strcmp(classname, "thread"))
+		return true;
 
-	return 1;
+	return false;
 }
 
- int getscom(uint64_t addr)
+int getscom(uint64_t addr)
 {
-	return for_each_target("pib", _getscom, &addr, NULL);
+	struct pdbg_target *target;
+	char *path;
+	uint64_t value;
+	int count = 0;
+
+	for_each_path_target(target) {
+		if (pdbg_target_status(target) != PDBG_TARGET_ENABLED)
+			continue;
+
+		path = pdbg_target_path(target);
+		assert(path);
+
+		if (!scommable(target)) {
+			printf("%s: invalid target\n", path);
+			free(path);
+			continue;
+		}
+
+		if (pib_read(target, addr, &value)) {
+			printf("%s: failed\n", path);
+			free(path);
+			continue;
+		}
+
+		printf("%s: 0x%" PRIx64 " = 0x%016" PRIx64 "\n", path, addr, value);
+		free(path);
+		count++;
+	}
+
+	return count;
 }
 OPTCMD_DEFINE_CMD_WITH_ARGS(getscom, getscom, (ADDRESS));
 
-static int _putscom(struct pdbg_target *target, uint32_t index, uint64_t *addr, uint64_t *data)
+int putscom(uint64_t addr, uint64_t data, uint64_t mask)
 {
-	if (pib_write(target, *addr, *data))
-		return 0;
+	struct pdbg_target *target;
+	char *path;
+	int count = 0;
 
-	return 1;
-}
+	for_each_path_target(target) {
+		if (pdbg_target_status(target) != PDBG_TARGET_ENABLED)
+			continue;
 
- int putscom(uint64_t addr, uint64_t data, uint64_t mask)
-{
-	/* TODO: Restore the <mask> functionality */
-	return for_each_target("pib", _putscom, &addr, &data);
+		path = pdbg_target_path(target);
+		assert(path);
+
+		if (!scommable(target)) {
+			printf("%s: invalid target\n", path);
+			free(path);
+			continue;
+		}
+
+		/* TODO: Restore the <mask> functionality */
+		if (pib_write(target, addr, data)) {
+			printf("%s: failed\n", path);
+			free(path);
+			continue;
+		}
+
+		count++;
+	}
+
+	return count;
 }
 OPTCMD_DEFINE_CMD_WITH_ARGS(putscom, putscom, (ADDRESS, DATA, DEFAULT_DATA("0xffffffffffffffff")));
diff --git a/tests/test_hw_bmc.sh b/tests/test_hw_bmc.sh
index 9bc1deb..d656a3f 100755
--- a/tests/test_hw_bmc.sh
+++ b/tests/test_hw_bmc.sh
@@ -91,7 +91,7 @@ do_skip
 test_run $PDBG -P fsi getcfam 0xc09
 
 test_result 0 <<EOF
-p0:0xf000f = HEX16
+/kernelfsi at 0/pib at 1000: 0xf000f = HEX16
 EOF
 
 do_skip
-- 
2.19.1



More information about the Pdbg mailing list