From patchwork Thu Jun 25 06:40:49 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amitay Isaacs X-Patchwork-Id: 1316745 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.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 49sr585VZgz9sSJ for ; Thu, 25 Jun 2020 16:41:16 +1000 (AEST) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=ozlabs.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; secure) header.d=ozlabs.org header.i=@ozlabs.org header.a=rsa-sha256 header.s=201707 header.b=GCeOkFNo; dkim-atps=neutral Received: from bilbo.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 49sr5769PRzDqht for ; Thu, 25 Jun 2020 16:41:15 +1000 (AEST) 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.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 49sr4x64ZmzDqcc for ; Thu, 25 Jun 2020 16:41:05 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=ozlabs.org Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=ozlabs.org header.i=@ozlabs.org header.a=rsa-sha256 header.s=201707 header.b=GCeOkFNo; dkim-atps=neutral Received: from authenticated.ozlabs.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mail.ozlabs.org (Postfix) with ESMTPSA id 49sr4x0w5qz9s1x; Thu, 25 Jun 2020 16:41:04 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ozlabs.org; s=201707; t=1593067265; bh=Bgmlndm8uXfabIwSzuKUjt+v0GwEpL77FAMH7E0PjJk=; h=From:To:Cc:Subject:Date:From; b=GCeOkFNoMwAeBA/7hGj2Kjw8zI9jFR3ICpP8VfIOtXDBO9oImAXlfYZZyaLiV/hQi YVGI9DCMC2tn9SYhATJyJzx5ZwWsLi4k2tkrsPcl0vUW+G6w+iodA5qTd55BotwHwY 0h2cmvk11u5gcc/iJNO9yHz7hYP1zIUw+Gxr7nZzV0koHVftF5LnjhOEES58Mm9Nz/ UMeBj09snmAGFdCH82/b85iOsRtHhXUNj9B3oXAqsdJl89d/7JJQZ7gXGguspZgQax rPSP8qu/bMaQx8OMPiRTAlALnAap9paCwHvIMKXSIDLzx4aunz+0oPW3pEbirvpuAy F/p3n7Js4aRvw== From: Amitay Isaacs To: pdbg@lists.ozlabs.org Date: Thu, 25 Jun 2020 16:40:49 +1000 Message-Id: <20200625064050.308393-1-amitay@ozlabs.org> X-Mailer: git-send-email 2.26.2 MIME-Version: 1.0 Subject: [Pdbg] [PATCH v3 1/2] libpdbg: Refactor code to get chip id X-BeenThere: pdbg@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "mailing list for https://github.com/open-power/pdbg development" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Amitay Isaacs Errors-To: pdbg-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Pdbg" Signed-off-by: Amitay Isaacs --- libpdbg/dtb.c | 55 ++++++++++++++++++++++++++++++--------------------- 1 file changed, 32 insertions(+), 23 deletions(-) diff --git a/libpdbg/dtb.c b/libpdbg/dtb.c index 6d9b182..2ec89e0 100644 --- a/libpdbg/dtb.c +++ b/libpdbg/dtb.c @@ -173,14 +173,43 @@ static void ppc_target(struct pdbg_dtb *dtb) } } -static void bmc_target(struct pdbg_dtb *dtb) +static bool get_chipid(uint32_t *chip_id) { FILE *cfam_id_file; char *path; uint32_t cfam_id = 0; - uint32_t chip_id = 0; int rc; + /* Try and determine the correct device type */ + rc = asprintf(&path, "%s/fsi0/slave@00:00/cfam_id", kernel_get_fsi_path()); + if (rc < 0) { + pdbg_log(PDBG_ERROR, "Unable create fsi path"); + return false; + } + + cfam_id_file = fopen(path, "r"); + free(path); + if (!cfam_id_file) { + pdbg_log(PDBG_ERROR, "Unabled to open CFAM ID file\n"); + return false; + } + + rc = fscanf(cfam_id_file, "0x%" PRIx32, &cfam_id); + if (rc != 1) { + pdbg_log(PDBG_ERROR, "Unable to read CFAM ID: %s", strerror(errno)); + fclose(cfam_id_file); + return false; + } + fclose(cfam_id_file); + + *chip_id = (cfam_id >> 4) & 0xff; + return true; +} + +static void bmc_target(struct pdbg_dtb *dtb) +{ + uint32_t chip_id = 0; + if (pdbg_backend_option) { if (!strcmp(pdbg_backend_option, "p8")) { if (!dtb->backend.fdt) @@ -200,28 +229,8 @@ static void bmc_target(struct pdbg_dtb *dtb) return; } - /* Try and determine the correct device type */ - rc = asprintf(&path, "%s/fsi0/slave@00:00/cfam_id", kernel_get_fsi_path()); - if (rc < 0) { - pdbg_log(PDBG_ERROR, "Unable create fsi path"); + if (!get_chipid(&chip_id)) return; - } - - cfam_id_file = fopen(path, "r"); - free(path); - if (!cfam_id_file) { - pdbg_log(PDBG_ERROR, "Unabled to open CFAM ID file\n"); - return; - } - - rc = fscanf(cfam_id_file, "0x%" PRIx32, &cfam_id); - if (rc != 1) { - pdbg_log(PDBG_ERROR, "Unable to read CFAM ID: %s", strerror(errno)); - fclose(cfam_id_file); - return; - } - fclose(cfam_id_file); - chip_id = (cfam_id >> 4) & 0xff; switch(chip_id) { case CHIP_ID_P9: From patchwork Thu Jun 25 06:40:50 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amitay Isaacs X-Patchwork-Id: 1316746 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 49sr5F37NCz9sSJ for ; Thu, 25 Jun 2020 16:41:21 +1000 (AEST) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=ozlabs.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; secure) header.d=ozlabs.org header.i=@ozlabs.org header.a=rsa-sha256 header.s=201707 header.b=x39gc04O; dkim-atps=neutral Received: from bilbo.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 49sr5F1nqbzDqht for ; Thu, 25 Jun 2020 16:41:21 +1000 (AEST) X-Original-To: pdbg@lists.ozlabs.org Delivered-To: pdbg@lists.ozlabs.org Received: from ozlabs.org (bilbo.ozlabs.org [IPv6:2401:3900:2:1::2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 49sr4y5xJczDqcq for ; Thu, 25 Jun 2020 16:41:06 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=ozlabs.org Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=ozlabs.org header.i=@ozlabs.org header.a=rsa-sha256 header.s=201707 header.b=x39gc04O; dkim-atps=neutral Received: from authenticated.ozlabs.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mail.ozlabs.org (Postfix) with ESMTPSA id 49sr4x6Xpyz9sSJ; Thu, 25 Jun 2020 16:41:05 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ozlabs.org; s=201707; t=1593067266; bh=R3TGTVlz4wyf+LbZerFxJrREutPF2Tg2yMoQ/V5gZ9Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=x39gc04OJbIMWMZazxcylGIhpERaFinmb+m0wwxMLkvYTi9vJyuQ2MwiY5919H2gW RoOZzvBwEZ4i8VY4VahDWkN39NxA8HX/VBNxQo72bbRn1LdbQx2AJW+FaLEYjSJgVR JqIcJRhUFTWIu3THqOk0+OiAJLjtBZlHKNLrkGivg8DWLA34NX+0xe5o+iZ0ntPJur FEE9QaC02V4zQu0XWnxpCPWL5ICsG4UFYfAS7AvlHesPO/zTVWAieBFvCtuPVPjoNn c3+0uqQSVU5rFKODBQyrjPhtQWZLovwznB6S2fwf733DtzAqBnrdsdtNIt/M3DBBj0 8DFdw3xNL6FxA== From: Amitay Isaacs To: pdbg@lists.ozlabs.org Date: Thu, 25 Jun 2020 16:40:50 +1000 Message-Id: <20200625064050.308393-2-amitay@ozlabs.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200625064050.308393-1-amitay@ozlabs.org> References: <20200625064050.308393-1-amitay@ozlabs.org> MIME-Version: 1.0 Subject: [Pdbg] [PATCH v3 2/2] libpdbg: Auto-detect using bmc_target() for SBEFIFO backend X-BeenThere: pdbg@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "mailing list for https://github.com/open-power/pdbg development" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Amitay Isaacs Errors-To: pdbg-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Pdbg" Signed-off-by: Amitay Isaacs --- libpdbg/dtb.c | 57 +++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 42 insertions(+), 15 deletions(-) diff --git a/libpdbg/dtb.c b/libpdbg/dtb.c index 2ec89e0..c80842f 100644 --- a/libpdbg/dtb.c +++ b/libpdbg/dtb.c @@ -256,6 +256,47 @@ static void bmc_target(struct pdbg_dtb *dtb) } } +static void sbefifo_target(struct pdbg_dtb *dtb) +{ + uint32_t chip_id = 0; + + if (pdbg_backend_option) { + if (!strcmp(pdbg_backend_option, "p9")) { + if (!dtb->backend.fdt) + dtb->backend.fdt = &_binary_bmc_sbefifo_dtb_o_start; + if (!dtb->system.fdt) + dtb->system.fdt = &_binary_p9_dtb_o_start; + } else { + pdbg_log(PDBG_ERROR, "Invalid system type %s\n", pdbg_backend_option); + pdbg_log(PDBG_ERROR, "Use 'p9'\n"); + } + + return; + } + + if (!get_chipid(&chip_id)) + return; + + switch(chip_id) { + case CHIP_ID_P9: + case CHIP_ID_P9P: + pdbg_log(PDBG_INFO, "Found a POWER9 OpenBMC based system\n"); + if (!dtb->backend.fdt) + dtb->backend.fdt = &_binary_bmc_sbefifo_dtb_o_start; + if (!dtb->system.fdt) + dtb->system.fdt = &_binary_p9_dtb_o_start; + break; + + case CHIP_ID_P8: + case CHIP_ID_P8P: + pdbg_log(PDBG_ERROR, "SBEFIFO backend not supported on POWER8/8+ OpenBMC based system\n"); + break; + + default: + pdbg_log(PDBG_ERROR, "Unrecognised Chip ID register 0x%08" PRIx32 "\n", chip_id); + } +} + /* Opens a dtb at the given path */ static void mmap_dtb(const char *file, bool readonly, struct pdbg_mfile *mfile) { @@ -426,21 +467,7 @@ struct pdbg_dtb *pdbg_default_dtb(void *system_fdt) break; case PDBG_BACKEND_SBEFIFO: - if (!pdbg_backend_option) { - pdbg_log(PDBG_ERROR, "No system type specified\n"); - pdbg_log(PDBG_ERROR, "Use p9\n"); - return NULL; - } - - if (!strcmp(pdbg_backend_option, "p9")) { - if (!dtb->backend.fdt) - dtb->backend.fdt = &_binary_bmc_sbefifo_dtb_o_start; - if (!dtb->system.fdt) - dtb->system.fdt = &_binary_p9_dtb_o_start; - } else { - pdbg_log(PDBG_ERROR, "Invalid system type %s\n", pdbg_backend_option); - pdbg_log(PDBG_ERROR, "Use p9\n"); - } + sbefifo_target(dtb); break; default: