diff mbox series

[2/2] src/options_arm.c: Add detection of host type for kernel backend

Message ID 20180912070118.29951-2-alistair@popple.id.au
State Accepted
Headers show
Series [1/2] pdbg: Rework backend detection | expand

Checks

Context Check Description
snowpatch_ozlabs/apply_patch success master/apply_patch Successfully applied
snowpatch_ozlabs/build-multiarch fail Test build-multiarch on branch master

Commit Message

Alistair Popple Sept. 12, 2018, 7:01 a.m. UTC
Signed-off-by: Alistair Popple <alistair@popple.id.au>
---
 src/options_arm.c | 45 ++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 44 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/src/options_arm.c b/src/options_arm.c
index d43e5ee..88cf9c9 100644
--- a/src/options_arm.c
+++ b/src/options_arm.c
@@ -21,6 +21,11 @@ 
 
 #define AMI_BMC "/proc/ractrends/Helper/FwInfo"
 #define OPENFSI_BMC "/sys/bus/platform/devices/gpio-fsi/fsi0/"
+#define FSI_CFAM_ID "/sys/devices/platform/gpio-fsi/fsi0/slave@00:00/cfam_id"
+
+#define CHIP_ID_P8  0xea
+#define CHIP_ID_P9  0xd1
+#define CHIP_ID_P8P 0xd3
 
 enum backend default_backend(void)
 {
@@ -48,6 +53,44 @@  void print_targets(FILE *stream)
 	fprintf(stream, "fsi: p8 p9w p9r p9z\n");
 }
 
+static const char *default_kernel_target(void)
+{
+	FILE *cfam_id_file;
+
+	/* Try and determine the correct device type */
+	cfam_id_file = fopen(FSI_CFAM_ID, "r");
+	if (cfam_id_file) {
+		uint32_t cfam_id = 0;
+
+		fscanf(cfam_id_file, "0x%" PRIx32, &cfam_id);
+		fclose(cfam_id_file);
+
+		switch((cfam_id >> 4) & 0xff) {
+		case CHIP_ID_P9:
+			return "p9";
+			break;
+
+		case CHIP_ID_P8:
+		case CHIP_ID_P8P:
+			return "p8";
+			break;
+
+		default:
+			pdbg_log(PDBG_ERROR, "Unknown chip-id detected\n");
+			pdbg_log(PDBG_ERROR, "You will need to specify a host type with -d <host type>\n");
+			return NULL;
+		}
+	} else {
+		/* The support for POWER8 included the cfam_id
+		 * so if it doesn't exist assume we must be on
+		 * P9 */
+		pdbg_log(PDBG_WARNING, "Unable to determine host type, defaulting to p9\n");
+		return "p9";
+	}
+
+	return NULL;
+}
+
 static const char *default_fsi_target(void)
 {
 	FILE *dt_compatible;
@@ -86,7 +129,7 @@  const char *default_target(enum backend backend)
 		break;
 
 	case KERNEL:
-		return NULL;
+		return default_kernel_target();
 		break;
 
 	case FSI: