From patchwork Thu Jul 2 03:39:06 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amitay Isaacs X-Patchwork-Id: 1320959 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)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 49y3l23wMgz9sQt for ; Thu, 2 Jul 2020 13:40:14 +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=rv857Zo2; 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 49y3l22dW1zDqn4 for ; Thu, 2 Jul 2020 13:40:14 +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)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 49y3kG5nmrzDqlD for ; Thu, 2 Jul 2020 13:39:34 +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=rv857Zo2; 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 49y3kG46KQz9sRW; Thu, 2 Jul 2020 13:39:34 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ozlabs.org; s=201707; t=1593661174; bh=mvKrV4EBX/WukX8Z0w4WGKg5AOSTp1BmYwe7bMbFmH8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=rv857Zo29xjRmq8DWNtPgsSv0xtDDRCjvjKNZhjE435VD7JpFS52IsgT07HQrVlKU e0znmOYWNoi1ZKmubzG1Y8I2GWMESwgja2MZ6gNi+wfHPyuCnHXcFu5O7pb6VvCHnF v196mljJBL5dctjtZl355ftWAhR74UMYQ+HCMVYF4MDoShGVRvWT2y3EhWX2VtF+ir d069P2uiGdwIe8O5hZhj1u181tk1t5bzHwlW+yreQ72BpEQo3bl05hyektPC1fwTe0 wpJRPAy7iqvweBf2IMpRLhguRyZEgGmDa1JPyNjEm2Wk9YdmQJXAEphzwzL3bn0XaG L2+4iIqH0qfpA== From: Amitay Isaacs To: pdbg@lists.ozlabs.org Date: Thu, 2 Jul 2020 13:39:06 +1000 Message-Id: <20200702033918.708013-8-amitay@ozlabs.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200702033918.708013-1-amitay@ozlabs.org> References: <20200702033918.708013-1-amitay@ozlabs.org> MIME-Version: 1.0 Subject: [Pdbg] [PATCH 07/19] libpdbg: Add processor type and accessor 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 | 43 ++++++++++++++++++++++++++++++++++++++++++- libpdbg/libpdbg.h | 17 +++++++++++++++++ 2 files changed, 59 insertions(+), 1 deletion(-) diff --git a/libpdbg/dtb.c b/libpdbg/dtb.c index c80842f..f47f28f 100644 --- a/libpdbg/dtb.c +++ b/libpdbg/dtb.c @@ -52,6 +52,7 @@ #define AMI_BMC "/proc/ractrends/Helper/FwInfo" #define XSCOM_BASE_PATH "/sys/kernel/debug/powerpc/scom" +static enum pdbg_proc pdbg_proc = PDBG_PROC_UNKNOWN; static enum pdbg_backend pdbg_backend = PDBG_DEFAULT_BACKEND; static const char *pdbg_backend_option; static struct pdbg_dtb pdbg_dtb = { @@ -116,11 +117,13 @@ static void ppc_target(struct pdbg_dtb *dtb) if (pdbg_backend_option) { if (!strcmp(pdbg_backend_option, "p8")) { + pdbg_proc = PDBG_PROC_P8; if (!dtb->backend.fdt) dtb->backend.fdt = &_binary_p8_host_dtb_o_start; if (!dtb->system.fdt) dtb->system.fdt = &_binary_p8_dtb_o_start; } else if (!strcmp(pdbg_backend_option, "p9")) { + pdbg_proc = PDBG_PROC_P9; if (!dtb->backend.fdt) dtb->backend.fdt = &_binary_p9_host_dtb_o_start; if (!dtb->system.fdt) @@ -158,11 +161,13 @@ static void ppc_target(struct pdbg_dtb *dtb) if (strncmp(pos, "POWER8", 6) == 0) { pdbg_log(PDBG_INFO, "Found a POWER8 PPC host system\n"); + pdbg_proc = PDBG_PROC_P8; if (!dtb->backend.fdt) dtb->backend.fdt = &_binary_p8_host_dtb_o_start; if (!dtb->system.fdt) dtb->system.fdt = &_binary_p8_dtb_o_start; } else if (strncmp(pos, "POWER9", 6) == 0) { + pdbg_proc = PDBG_PROC_P9; pdbg_log(PDBG_INFO, "Found a POWER9 PPC host system\n"); if (!dtb->backend.fdt) dtb->backend.fdt = &_binary_p9_host_dtb_o_start; @@ -212,11 +217,13 @@ static void bmc_target(struct pdbg_dtb *dtb) if (pdbg_backend_option) { if (!strcmp(pdbg_backend_option, "p8")) { + pdbg_proc = PDBG_PROC_P8; if (!dtb->backend.fdt) dtb->backend.fdt = &_binary_p8_kernel_dtb_o_start; if (!dtb->system.fdt) dtb->system.fdt = &_binary_p8_dtb_o_start; } else if (!strcmp(pdbg_backend_option, "p9")) { + pdbg_proc = PDBG_PROC_P9; if (!dtb->backend.fdt) dtb->backend.fdt = &_binary_bmc_kernel_dtb_o_start; if (!dtb->system.fdt) @@ -236,6 +243,7 @@ static void bmc_target(struct pdbg_dtb *dtb) case CHIP_ID_P9: case CHIP_ID_P9P: pdbg_log(PDBG_INFO, "Found a POWER9 OpenBMC based system\n"); + pdbg_proc = PDBG_PROC_P9; if (!dtb->backend.fdt) dtb->backend.fdt = &_binary_bmc_kernel_dtb_o_start; if (!dtb->system.fdt) @@ -244,6 +252,7 @@ static void bmc_target(struct pdbg_dtb *dtb) case CHIP_ID_P8: case CHIP_ID_P8P: + pdbg_proc = PDBG_PROC_P8; pdbg_log(PDBG_INFO, "Found a POWER8/8+ OpenBMC based system\n"); if (!dtb->backend.fdt) dtb->backend.fdt = &_binary_p8_kernel_dtb_o_start; @@ -262,6 +271,7 @@ static void sbefifo_target(struct pdbg_dtb *dtb) if (pdbg_backend_option) { if (!strcmp(pdbg_backend_option, "p9")) { + pdbg_proc = PDBG_PROC_P9; if (!dtb->backend.fdt) dtb->backend.fdt = &_binary_bmc_sbefifo_dtb_o_start; if (!dtb->system.fdt) @@ -280,6 +290,7 @@ static void sbefifo_target(struct pdbg_dtb *dtb) switch(chip_id) { case CHIP_ID_P9: case CHIP_ID_P9P: + pdbg_proc = PDBG_PROC_P9; pdbg_log(PDBG_INFO, "Found a POWER9 OpenBMC based system\n"); if (!dtb->backend.fdt) dtb->backend.fdt = &_binary_bmc_sbefifo_dtb_o_start; @@ -289,6 +300,7 @@ static void sbefifo_target(struct pdbg_dtb *dtb) case CHIP_ID_P8: case CHIP_ID_P8P: + pdbg_proc = PDBG_PROC_P8; pdbg_log(PDBG_ERROR, "SBEFIFO backend not supported on POWER8/8+ OpenBMC based system\n"); break; @@ -367,6 +379,26 @@ const char *pdbg_get_backend_option(void) return pdbg_backend_option; } +enum pdbg_proc pdbg_get_proc(void) +{ + return pdbg_proc; +} + +static void set_pdbg_proc(void) +{ + const char *proc; + + /* Allow to set processor, when device trees are overriden */ + proc = getenv("PDBG_PROC"); + if (!proc) + return; + + if (!strcmp(proc, "p8")) + pdbg_proc = PDBG_PROC_P8; + else if (!strcmp(proc, "p9")) + pdbg_proc = PDBG_PROC_P9; +} + /* Determines what platform we are running on and returns a pointer to * the fdt that is most likely to work on the system. */ struct pdbg_dtb *pdbg_default_dtb(void *system_fdt) @@ -388,8 +420,10 @@ struct pdbg_dtb *pdbg_default_dtb(void *system_fdt) if (fdt) mmap_dtb(fdt, false, &dtb->system); - if (dtb->backend.fdt && dtb->system.fdt) + if (dtb->backend.fdt && dtb->system.fdt) { + set_pdbg_proc(); goto done; + } switch(pdbg_backend) { case PDBG_BACKEND_HOST: @@ -398,6 +432,7 @@ struct pdbg_dtb *pdbg_default_dtb(void *system_fdt) case PDBG_BACKEND_I2C: /* I2C is only supported on POWER8 */ + pdbg_proc = PDBG_PROC_P8; if (!dtb->backend.fdt) { pdbg_log(PDBG_INFO, "Found a POWER8 AMI BMC based system\n"); dtb->backend.fdt = &_binary_p8_i2c_dtb_o_start; @@ -418,21 +453,25 @@ struct pdbg_dtb *pdbg_default_dtb(void *system_fdt) } if (!strcmp(pdbg_backend_option, "p8")) { + pdbg_proc = PDBG_PROC_P8; if (!dtb->backend.fdt) dtb->backend.fdt = &_binary_p8_fsi_dtb_o_start; if (!dtb->system.fdt) dtb->system.fdt = &_binary_p8_dtb_o_start; } else if (!strcmp(pdbg_backend_option, "p9w")) { + pdbg_proc = PDBG_PROC_P9; if (!dtb->backend.fdt) dtb->backend.fdt = &_binary_p9w_fsi_dtb_o_start; if (!dtb->system.fdt) dtb->system.fdt = &_binary_p9_dtb_o_start; } else if (!strcmp(pdbg_backend_option, "p9r")) { + pdbg_proc = PDBG_PROC_P9; if (!dtb->backend.fdt) dtb->backend.fdt = &_binary_p9r_fsi_dtb_o_start; if (!dtb->system.fdt) dtb->system.fdt = &_binary_p9_dtb_o_start; } else if (!strcmp(pdbg_backend_option, "p9z")) { + pdbg_proc = PDBG_PROC_P9; if (!dtb->backend.fdt) dtb->backend.fdt = &_binary_p9z_fsi_dtb_o_start; if (!dtb->system.fdt) @@ -451,11 +490,13 @@ struct pdbg_dtb *pdbg_default_dtb(void *system_fdt) } if (!strncmp(pdbg_backend_option, "p8", 2)) { + pdbg_proc = PDBG_PROC_P8; if (!dtb->backend.fdt) dtb->backend.fdt = &_binary_p8_cronus_dtb_o_start; if (!dtb->system.fdt) dtb->system.fdt = &_binary_p8_dtb_o_start; } else if (!strncmp(pdbg_backend_option, "p9", 2)) { + pdbg_proc = PDBG_PROC_P9; if (!dtb->backend.fdt) dtb->backend.fdt = &_binary_cronus_dtb_o_start; if (!dtb->system.fdt) diff --git a/libpdbg/libpdbg.h b/libpdbg/libpdbg.h index 28380cd..a3c90de 100644 --- a/libpdbg/libpdbg.h +++ b/libpdbg/libpdbg.h @@ -46,6 +46,23 @@ struct pdbg_target; */ struct pdbg_target_class; +/** + * @brief Identifies the processor type + */ +enum pdbg_proc { + PDBG_PROC_UNKNOWN, /**< Unknown processor */ + PDBG_PROC_P8, /**< POWER8 processor */ + PDBG_PROC_P9, /**< POWER9 processor */ +}; + +/** + * @brief Get the processor type + * @return the processor type + * + * This function can only be called after pdbg_targets_init() has bee called. + */ +enum pdbg_proc pdbg_get_proc(void); + /** * @brief Find the next compatible target * @param[in] root the head pdbg_target