[Skiboot] [PATCH] external/xscom-utils: Add --list-bits

Oliver O'Halloran oohall at gmail.com
Thu Aug 17 16:44:41 AEST 2017


When using getscom/putscom it's helpful to know what bits are set in the
register. This patch adds an option to print out which bits are set
along with the value that was read/written to the register. Note that
this output indicates which bits are set using the IBM bit ordering
since that's what the XSCOM documentation uses.

Signed-off-by: Oliver O'Halloran <oohall at gmail.com>
---
 external/xscom-utils/getscom.c | 27 ++++++++++++++++++++++++---
 external/xscom-utils/putscom.c | 25 ++++++++++++++++++++++---
 external/xscom-utils/sram.c    |  3 ---
 external/xscom-utils/xscom.h   |  4 ++++
 4 files changed, 50 insertions(+), 9 deletions(-)

diff --git a/external/xscom-utils/getscom.c b/external/xscom-utils/getscom.c
index a46c82b1f8fa..8c9663460d88 100644
--- a/external/xscom-utils/getscom.c
+++ b/external/xscom-utils/getscom.c
@@ -25,9 +25,11 @@
 
 static void print_usage(int code)
 {
-	printf("usage: getscom [-c|--chip chip-id] addr\n");
+	printf("usage: getscom [-c|--chip chip-id] [-b|--list-bits] addr\n");
 	printf("       getscom -l|--list-chips\n");
 	printf("       getscom -v|--version\n");
+	printf("\n");
+	printf("       NB: --list-bits shows which PPC bits are set\n");
 	exit(code);
 }
 
@@ -88,6 +90,7 @@ int main(int argc, char *argv[])
 	uint32_t def_chip, chip_id = 0xffffffff;
 	bool list_chips = false;
 	bool no_work = false;
+	bool list_bits = false;
 	int rc;
 
 	while(1) {
@@ -96,10 +99,11 @@ int main(int argc, char *argv[])
 			{"list-chips",	no_argument,		NULL,	'l'},
 			{"help",	no_argument,		NULL,	'h'},
 			{"version",	no_argument,		NULL,	'v'},
+			{"list-bits",	no_argument,		NULL,	'b'},
 		};
 		int c, oidx = 0;
 
-		c = getopt_long(argc, argv, "-c:hlv", long_opts, &oidx);
+		c = getopt_long(argc, argv, "-c:bhlv", long_opts, &oidx);
 		if (c == EOF)
 			break;
 		switch(c) {
@@ -115,6 +119,9 @@ int main(int argc, char *argv[])
 		case 'l':
 			list_chips = true;
 			break;
+		case 'b':
+			list_bits = true;
+			break;
 		case 'v':
 			printf("xscom utils version %s\n", version);
 			exit(0);
@@ -150,7 +157,21 @@ int main(int argc, char *argv[])
 		fprintf(stderr,"Error %d reading XSCOM\n", rc);
 		exit(1);
 	}
-	printf("%016" PRIx64 "\n", val);
+
+	printf("%016" PRIx64, val);
+
+	if (list_bits) {
+		int i;
+
+		printf(" - set: ");
+
+		for (i = 0; i < 64; i++)
+			if (val & PPC_BIT(i))
+				printf("%d ", i);
+	}
+
+	putchar('\n');
+
 	return 0;
 }
 
diff --git a/external/xscom-utils/putscom.c b/external/xscom-utils/putscom.c
index ca8c0da30537..84b6f897f3e5 100644
--- a/external/xscom-utils/putscom.c
+++ b/external/xscom-utils/putscom.c
@@ -25,8 +25,11 @@
 
 static void print_usage(int code)
 {
-	printf("usage: putscom [-c|--chip chip-id] addr value\n");
+	printf("usage: putscom [-c|--chip chip-id] [-b|--list-bits] addr value\n");
 	printf("       putscom -v|--version\n");
+	printf("\n");
+	printf("       NB: --list-bits shows which PPC bits are set\n");
+	exit(code);
 	exit(code);
 }
 
@@ -37,6 +40,7 @@ int main(int argc, char *argv[])
 	uint64_t val = -1ull, addr = -1ull;
 	uint32_t def_chip, chip_id = 0xffffffff;
 	bool got_addr = false, got_val = false;
+	bool list_bits = false;
 	int rc;
 
 	while(1) {
@@ -47,7 +51,7 @@ int main(int argc, char *argv[])
 		};
 		int c, oidx = 0;
 
-		c = getopt_long(argc, argv, "-c:hv", long_opts, &oidx);
+		c = getopt_long(argc, argv, "-c:bhv", long_opts, &oidx);
 		if (c == EOF)
 			break;
 		switch(c) {
@@ -63,6 +67,9 @@ int main(int argc, char *argv[])
 		case 'c':
 			chip_id = strtoul(optarg, NULL, 16);
 			break;
+		case 'b':
+			list_bits = true;
+			break;
 		case 'v':
 			printf("xscom utils version %s\n", version);
 			exit(0);
@@ -99,7 +106,19 @@ int main(int argc, char *argv[])
 			exit(1);
 		}
 	}
-	printf("%016" PRIx64 "\n", val);
+
+	printf("%016" PRIx64, val);
+	if (list_bits) {
+		int i;
+
+		printf(" - set: ");
+
+		for (i = 0; i < 64; i++)
+			if (val & PPC_BIT(i))
+				printf("%d ", i);
+	}
+
+	putchar('\n');
 	return 0;
 }
 
diff --git a/external/xscom-utils/sram.c b/external/xscom-utils/sram.c
index 74ad9967c969..721adee6569d 100644
--- a/external/xscom-utils/sram.c
+++ b/external/xscom-utils/sram.c
@@ -24,9 +24,6 @@
 #define DBG(fmt...)	do { if (verbose) printf(fmt); } while(0)
 #define ERR(fmt...)	do { fprintf(stderr, fmt); } while(0)
 
-#define PPC_BIT(bit)		(0x8000000000000000UL >> (bit))
-
-
 #define OCB_PIB_OCBCSR0_0x0006B011	0x0006B011
 #define OCB_PIB_OCBCSR0_ANDx0006B012	0x0006B012
 #define OCB_PIB_OCBCSR0_ORx0006B013	0x0006B013
diff --git a/external/xscom-utils/xscom.h b/external/xscom-utils/xscom.h
index 5f9edbc9b347..49323158bfbe 100644
--- a/external/xscom-utils/xscom.h
+++ b/external/xscom-utils/xscom.h
@@ -31,4 +31,8 @@ extern bool xscom_readable(uint64_t addr);
 
 extern uint32_t xscom_init(void);
 
+#ifndef PPC_BIT
+#define PPC_BIT(bit)		(0x8000000000000000UL >> (bit))
+#endif
+
 #endif /* __XSCOM_H */
-- 
2.9.4



More information about the Skiboot mailing list