diff mbox series

[10/10] main: Convert getscom/putscom

Message ID 20181023021602.449244-1-amitay@ozlabs.org
State Superseded
Headers show
Series None | expand

Commit Message

Amitay Isaacs Oct. 23, 2018, 2:16 a.m. UTC
Signed-off-by: Amitay Isaacs <amitay@ozlabs.org>
---
 src/scom.c | 82 ++++++++++++++++++++++++++++++++++++++++++------------
 1 file changed, 64 insertions(+), 18 deletions(-)
diff mbox series

Patch

diff --git a/src/scom.c b/src/scom.c
index 2372e91..3fc3e6e 100644
--- a/src/scom.c
+++ b/src/scom.c
@@ -23,36 +23,82 @@ 
 
 #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;
+	bool failed = false;
+
+	for_each_path_target(target, true) {
+		path = path_target_path(target);
+
+		if (!scommable(target)) {
+			printf("%s: invalid target\n", path);
+			free(path);
+			continue;
+		}
+
+		if (pib_read(target, addr, &value)) {
+			failed = true;
+			printf("%s: failed\n", path);
+			free(path);
+			continue;
+		}
+
+		printf("%s: 0x%" PRIx64 " = 0x%016" PRIx64 "\n", path, addr, value);
+		free(path);
+	}
+
+	if (failed)
+		return 1;
+
+	return 0;
 }
 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;
+	bool failed = false;
 
-	return 1;
-}
+	for_each_path_target(target, true) {
+		path = path_target_path(target);
 
- int putscom(uint64_t addr, uint64_t data, uint64_t mask)
-{
-	/* TODO: Restore the <mask> functionality */
-	return for_each_target("pib", _putscom, &addr, &data);
+		if (!scommable(target)) {
+			printf("%s: invalid target\n", path);
+			free(path);
+			continue;
+		}
+
+		/* TODO: Restore the <mask> functionality */
+		if (pib_write(target, addr, data)) {
+			failed = true;
+			printf("%s: failed\n", path);
+			free(path);
+		}
+	}
+
+	if (failed)
+		return 1;
+
+	return 0;
 }
 OPTCMD_DEFINE_CMD_WITH_ARGS(putscom, putscom, (ADDRESS, DATA, DEFAULT_DATA("0xffffffffffffffff")));