diff mbox series

[07/12] main: Use pdbg_get_proc() for mapping to linux CPUs

Message ID 20210802054112.461728-8-jniethe5@gmail.com
State Superseded
Headers show
Series P10 HTM Support | expand

Commit Message

Jordan Niethe Aug. 2, 2021, 5:41 a.m. UTC
Use pdbg_get_proc() instead of device_node for mapping to linux CPUs.
Now it is not required to use device (-d) when using the -l option.

Signed-off-by: Jordan Niethe <jniethe5@gmail.com>
---
 src/main.c | 67 ++++++++++++++++++++++++++++++++----------------------
 1 file changed, 40 insertions(+), 27 deletions(-)
diff mbox series

Patch

diff --git a/src/main.c b/src/main.c
index b2474d87135a..4c117f68bab5 100644
--- a/src/main.c
+++ b/src/main.c
@@ -59,6 +59,8 @@  static int i2c_addr = 0x50;
 
 static const char *pathsel[MAX_PATH_ARGS];
 static int pathsel_count;
+static int l_list[MAX_LINUX_CPUS];
+static int l_count;
 
 static int probe(void);
 
@@ -131,7 +133,6 @@  static void print_usage(void)
 	printf("\t-t, --thread=<0-%d>|<range>|<list>\n", MAX_THREADS-1);
 #ifdef TARGET_PPC
 	printf("\t-l, --cpu=<0-%d>|<range>|<list>\n", MAX_PROCESSORS-1);
-	printf("\t\tRequires device (-d) to be set to p8|p9\n");
 #endif
 	printf("\t-P, --path=<device tree node spec>\n");
 	printf("\t-a, --all\n");
@@ -205,25 +206,32 @@  out2:
 #define P8_PIR2COREID(pir) (((pir) >> 3) & 0xf)
 #define P8_PIR2THREADID(pir) ((pir) & 0x7)
 
-void pir_map(int pir, int *chip, int *core, int *thread)
+bool pir_map(int pir, int *chip, int *core, int *thread)
 {
 	assert(chip && core && thread);
 
-	if (!strncmp(device_node, "p9", 2)) {
+	switch (pdbg_get_proc()) {
+	case PDBG_PROC_P9:
 		*chip = P9_PIR2GCID(pir);
 		*core = P9_PIR2COREID(pir);
 		*thread = P9_PIR2THREADID(pir);
-	} else if (!strncmp(device_node, "p8", 2)) {
+		break;
+	case PDBG_PROC_P8:
 		*chip = P8_PIR2GCID(pir);
 		*core = P8_PIR2COREID(pir);
 		*thread = P8_PIR2THREADID(pir);
-	} else if (!strncmp(device_node, "p10", 2)) {
+		break;
+	case PDBG_PROC_P10:
 		*chip = P10_PIR2GCID(pir);
 		*core = P10_PIR2COREID(pir);
 		*thread = P10_PIR2THREADID(pir);
-	} else
-		assert(0);
+		break;
+	default:
+		PR_ERROR("Unable to determine processor type for mapping to Linux CPU number\n");
+		return false;
+	}
 
+	return true;
 }
 
 #define PPC_OPTS "l:"
@@ -290,8 +298,7 @@  static bool parse_options(int argc, char *argv[])
 	int p_list[MAX_PROCESSORS];
 	int c_list[MAX_CHIPS];
 	int t_list[MAX_THREADS];
-	int l_list[MAX_LINUX_CPUS];
-	int p_count = 0, c_count = 0, t_count = 0, l_count = 0;
+	int p_count = 0, c_count = 0, t_count = 0;
 	int i;
 	struct option long_opts[] = {
 		{"all",			no_argument,		NULL,	'a'},
@@ -489,33 +496,34 @@  static bool parse_options(int argc, char *argv[])
 			return false;
 	}
 
-	if (l_count) {
-		int pir = -1, i, chip, core, thread;
+	return true;
+}
 
-		if (!device_node)
-			return false;
+bool cpus_parse(int args[], int arg_count)
+{
+	int pir = -1, i, chip, core, thread;
 
-		for (i = 0; i < MAX_LINUX_CPUS; i++) {
-			if (l_list[i] == 1) {
-				pir = get_pir(i);
-				if (pir < 0)
-					return false;
+	for (i = 0; i < MAX_LINUX_CPUS; i++) {
+		if (args[i] == 1) {
+			pir = get_pir(i);
+			if (pir < 0)
+				return false;
 
-				pir_map(pir, &chip, &core, &thread);
+			if (!pir_map(pir, &chip, &core, &thread))
+				return false;
 
-				if (!pathsel_add("pib%d", chip))
-					return false;
-				if (!pathsel_add("pib%d/core%d", chip, core))
-					return false;
-				if (!pathsel_add("pib%d/core%d/thread%d", chip, core, thread))
-					return false;
-			}
+			if (!pathsel_add("pib%d", chip))
+				return false;
+			if (!pathsel_add("pib%d/core%d", chip, core))
+				return false;
+			if (!pathsel_add("pib%d/core%d/thread%d", chip, core, thread))
+				return false;
 		}
 	}
-
 	return true;
 }
 
+
 static void print_target(struct pdbg_target *target, int level)
 {
 	int i;
@@ -587,6 +595,11 @@  int main(int argc, char *argv[])
 	if (!pdbg_targets_init(NULL))
 		return 1;
 
+	if (l_count) {
+		if (!cpus_parse(l_list, l_count))
+			return 1;
+	}
+
 	if (pathsel_count) {
 		if (!path_target_parse(pathsel, pathsel_count))
 			return 1;