From patchwork Fri Oct 1 20:24:56 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomasz Duszynski X-Patchwork-Id: 100365 X-Patchwork-Delegate: jerinj@marvell.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 38786A0032; Fri, 1 Oct 2021 22:25:51 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id C9B9C41183; Fri, 1 Oct 2021 22:25:50 +0200 (CEST) Received: from mx0b-0016f401.pphosted.com (mx0b-0016f401.pphosted.com [67.231.156.173]) by mails.dpdk.org (Postfix) with ESMTP id 6C8094115D for ; Fri, 1 Oct 2021 22:25:49 +0200 (CEST) Received: from pps.filterd (m0045851.ppops.net [127.0.0.1]) by mx0b-0016f401.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 1919hdVQ021712 for ; Fri, 1 Oct 2021 13:25:48 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=marvell.com; h=from : to : cc : subject : date : message-id : mime-version : content-transfer-encoding : content-type; s=pfpt0220; bh=rNils5+W0oj1Wi09tLNbM60dzJkPzHuYQtrtBlAflrs=; b=YReKCAR5RoElPPtL10BUtzfDSrEVxEtKqzxZtZB1xD+UV82YYzX/qlEhOHD8Tb+wAP2c yvRcB/vFSrm8Hv7QU52iNs0WvGdDTSmRW6zo6I7XdH8b72//+NFm66wvJ5VBh4K/wqw4 VSn7vyTHRPc5S/5xNGbxVbQJQVA37B1xsi8IF3axJ/a5xEA3s6p/nq82S9fypRR35gJI MXLcI3xwqXwivTFMCsg9dB+c2vQ4+k0T5m/xoQh6hVXFpd8yPzD48sG8EXcV7wsJ65S/ g2fAqW6LVYkXeBHTvE711tH0dnznf+eXtQtK67bQwKKvgzoXRopQVLLT52jGL/8hdU51 1w== Received: from dc5-exch02.marvell.com ([199.233.59.182]) by mx0b-0016f401.pphosted.com with ESMTP id 3bdrxmk88s-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT) for ; Fri, 01 Oct 2021 13:25:48 -0700 Received: from DC5-EXCH01.marvell.com (10.69.176.38) by DC5-EXCH02.marvell.com (10.69.176.39) with Microsoft SMTP Server (TLS) id 15.0.1497.18; Fri, 1 Oct 2021 13:25:46 -0700 Received: from maili.marvell.com (10.69.176.80) by DC5-EXCH01.marvell.com (10.69.176.38) with Microsoft SMTP Server id 15.0.1497.18 via Frontend Transport; Fri, 1 Oct 2021 13:25:46 -0700 Received: from localhost.localdomain (unknown [10.28.34.39]) by maili.marvell.com (Postfix) with ESMTP id 932DE3F7058; Fri, 1 Oct 2021 13:25:44 -0700 (PDT) From: Tomasz Duszynski To: CC: , Tomasz Duszynski , "Nithin Dabilpuram" , Kiran Kumar K , Sunil Kumar Kori , Satha Rao Date: Fri, 1 Oct 2021 22:24:56 +0200 Message-ID: <20211001202456.2073532-1-tduszynski@marvell.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-Proofpoint-GUID: khodRqRLxstyUozJ_IDpEVI4XRXqr-4m X-Proofpoint-ORIG-GUID: khodRqRLxstyUozJ_IDpEVI4XRXqr-4m X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.182.1,Aquarius:18.0.790,Hydra:6.0.391,FMLib:17.0.607.475 definitions=2021-10-01_05,2021-10-01_02,2020-04-07_01 Subject: [dpdk-dev] [PATCH] common/cnxk: add helpers for reading runplatform X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Add helper functions that allow one to check platform ROC is running on. Platform type is retrieved from device tree attribute runplatform which is updated by EBF accordingly. Signed-off-by: Tomasz Duszynski Reviewed-by: Jerin Jacob Kollanukkaran --- drivers/common/cnxk/roc_model.c | 53 ++++++++++++++++++++++++++++++++- drivers/common/cnxk/roc_model.h | 29 ++++++++++++++++++ 2 files changed, 81 insertions(+), 1 deletion(-) diff --git a/drivers/common/cnxk/roc_model.c b/drivers/common/cnxk/roc_model.c index e5aeabe2e2..447dc6e8bc 100644 --- a/drivers/common/cnxk/roc_model.c +++ b/drivers/common/cnxk/roc_model.c @@ -178,6 +178,55 @@ detect_invalid_config(void) #endif } +static uint64_t +env_lookup_flag(const char *name) +{ + unsigned int i; + struct { + const char *name; + uint64_t flag; + } envs[] = { + {"HW_PLATFORM", ROC_ENV_HW}, + {"EMUL_PLATFORM", ROC_ENV_EMUL}, + {"ASIM_PLATFORM", ROC_ENV_ASIM}, + }; + + for (i = 0; i < PLT_DIM(envs); i++) + if (!strncmp(envs[i].name, name, strlen(envs[i].name))) + return envs[i].flag; + + return 0; +} + +static void +of_env_get(struct roc_model *model) +{ + const char *const path = "/proc/device-tree/soc@0/runplatform"; + uint64_t flag; + FILE *fp; + + fp = fopen(path, "r"); + if (!fp) { + plt_err("Failed to open %s", path); + return; + } + + if (!fgets(model->env, sizeof(model->env), fp)) { + plt_err("Failed to read %s", path); + goto err; + } + + flag = env_lookup_flag(model->env); + if (flag == 0) { + plt_err("Unknown platform: %s", model->env); + goto err; + } + + model->flag |= flag; +err: + fclose(fp); +} + int roc_model_init(struct roc_model *model) { @@ -197,8 +246,10 @@ roc_model_init(struct roc_model *model) if (!populate_model(model, midr)) goto err; + of_env_get(model); + rc = 0; - plt_info("RoC Model: %s", model->name); + plt_info("RoC Model: %s (%s)", model->name, model->env); roc_model = model; err: return rc; diff --git a/drivers/common/cnxk/roc_model.h b/drivers/common/cnxk/roc_model.h index a54f435b46..3779a88bca 100644 --- a/drivers/common/cnxk/roc_model.h +++ b/drivers/common/cnxk/roc_model.h @@ -23,10 +23,15 @@ struct roc_model { #define ROC_MODEL_CN106xx_A0 BIT_ULL(20) #define ROC_MODEL_CNF105xx_A0 BIT_ULL(21) #define ROC_MODEL_CNF105xxN_A0 BIT_ULL(22) +/* Following flags describe platform code is running on */ +#define ROC_ENV_HW BIT_ULL(61) +#define ROC_ENV_EMUL BIT_ULL(62) +#define ROC_ENV_ASIM BIT_ULL(63) uint64_t flag; #define ROC_MODEL_STR_LEN_MAX 128 char name[ROC_MODEL_STR_LEN_MAX]; + char env[ROC_MODEL_STR_LEN_MAX]; } __plt_cache_aligned; #define ROC_MODEL_CN96xx_Ax (ROC_MODEL_CN96xx_A0 | ROC_MODEL_CN96xx_B0) @@ -158,6 +163,30 @@ roc_model_is_cnf10kb_a0(void) return roc_model->flag & ROC_MODEL_CNF105xxN_A0; } +static inline bool +roc_env_is_hw(void) +{ + return roc_model->flag & ROC_ENV_HW; +} + +static inline bool +roc_env_is_emulator(void) +{ + return roc_model->flag & ROC_ENV_EMUL; +} + +static inline bool +roc_env_is_asim(void) +{ + return roc_model->flag & ROC_ENV_ASIM; +} + +static inline const char * +roc_env_get(void) +{ + return roc_model->env; +} + int roc_model_init(struct roc_model *model); #endif