From patchwork Wed Sep 12 04:15:03 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alistair Popple X-Patchwork-Id: 968839 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [203.11.71.2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4297jS5mxkz9s3x for ; Wed, 12 Sep 2018 14:15:08 +1000 (AEST) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=popple.id.au Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 4297jS464QzF39K for ; Wed, 12 Sep 2018 14:15:08 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=popple.id.au X-Original-To: pdbg@lists.ozlabs.org Delivered-To: pdbg@lists.ozlabs.org Received: from ozlabs.org (bilbo.ozlabs.org [203.11.71.1]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4297jP0q4hzF35T for ; Wed, 12 Sep 2018 14:15:05 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=popple.id.au Received: from authenticated.ozlabs.org (localhost [127.0.0.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPSA id 4297jN5f3wz9s3x; Wed, 12 Sep 2018 14:15:04 +1000 (AEST) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=popple.id.au From: Alistair Popple To: pdbg@lists.ozlabs.org Date: Wed, 12 Sep 2018 14:15:03 +1000 Message-Id: <20180912041503.20066-1-alistair@popple.id.au> X-Mailer: git-send-email 2.11.0 Subject: [Pdbg] [PATCH] src/main.c: Add detection of host type for kernel backend X-BeenThere: pdbg@lists.ozlabs.org X-Mailman-Version: 2.1.27 Precedence: list List-Id: "mailing list for https://github.com/open-power/pdbg development" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: pdbg-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Pdbg" Signed-off-by: Alistair Popple --- src/main.c | 40 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-) diff --git a/src/main.c b/src/main.c index 883e892..79f67a5 100644 --- a/src/main.c +++ b/src/main.c @@ -52,6 +52,8 @@ #include "p9r-fsi.dt.h" #include "p9z-fsi.dt.h" #include "p9-kernel.dt.h" + +#define FSI_CFAM_ID "/sys/devices/platform/gpio-fsi/fsi0/slave@00:00/cfam_id" #endif #ifdef TARGET_PPC @@ -59,6 +61,10 @@ #include "p9-host.dt.h" #endif +#define CHIP_ID_P8 0xea +#define CHIP_ID_P9 0xd1 +#define CHIP_ID_P8P 0xd3 + #define THREADS_PER_CORE 8 static enum backend backend = KERNEL; @@ -629,9 +635,39 @@ static int target_selection(void) case KERNEL: if (device_node == NULL) { - PR_ERROR("kernel backend requires a device type\n"); - return -1; + 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: + device_node = "p9"; + break; + + case CHIP_ID_P8: + case CHIP_ID_P8P: + device_node = "p8"; + break; + + default: + PR_ERROR("Unknown chip-id detected\n"); + PR_ERROR("You will need to specify one with -d \n"); + return -1; + } + } else { + /* The support for POWER8 included the cfam_id + * so if it doesn't exist assume we must be on + * P9 */ + device_node = "p9"; + } } + if (!strcmp(device_node, "p8")) pdbg_targets_init(&_binary_p8_kernel_dtb_o_start); else