From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id D09D6A034F; Fri, 8 Oct 2021 10:17:24 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id BB8C840DDD; Fri, 8 Oct 2021 10:17:24 +0200 (CEST) Received: from mail-il1-f181.google.com (mail-il1-f181.google.com [209.85.166.181]) by mails.dpdk.org (Postfix) with ESMTP id 4DD79407FF for ; Fri, 8 Oct 2021 10:17:24 +0200 (CEST) Received: by mail-il1-f181.google.com with SMTP id k13so9117205ilo.7 for ; Fri, 08 Oct 2021 01:17:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=R/dklaPvRyRjcDPWmUiHIASQU/rBgtjoR3HMxe9ig0c=; b=K1L2dhaULR162dwsVI8LHCpCDEzZsiFTI/uqGAXqCZfERcJin9QWaib4zskGJg6rnO 4ktsuKaVBvnSR2Y7shjceM5QFBwA9xc4arbeLU/Nd8oKF5zSa8x0kiFFbh05R1UheLSR 38PQsf/yLAFBvGNK02excmI2Kx1xLahyi3ISi+sYB4J1WLnrp7rsjzE+hJ/SQIDaMhgn 5eFzHnFa/KuXdw1BikD22F653lAmG9+95eyApV2hmPgPhNYriWcsQTtYqMOByaJ7HlmT 9QeC0P3ZReCheTyj3S8OKN+QXX923C12gTYQFvRmGc8Y+sDRHHPEs70G6qSLxlxE07a+ zhvA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=R/dklaPvRyRjcDPWmUiHIASQU/rBgtjoR3HMxe9ig0c=; b=uAxktiKuOUNerqPoiZV/Ozeu3K8xWlT1+kBLa34iQazuzYP9g1xs925An2XdT0G2LB j0se4O0q7Zj7azEJvZdkwAsrNmxfTuI0xH8fw1IFCD5ydzYus+iR6Zk28TlIEH+GSSVH o1fpctj1Dp/gSAruT1Oe+2rbmII+PJGeW5xieHoehdwCIy4Fc2EZZakTr9PhNdyez0ru 14VpzSifLEQ/VxEWVrJZl5pSmGGA01szc82N1y+8s4oUF0ksvljnS35hIsMt32vmYq1I 86UhygTite6/BvGTh/M2v6G3nrSBjYrGKV8uoU6qN17ID4HFa9r00PH9p1/N/Fm0hHRf V8AA== X-Gm-Message-State: AOAM531vbuEDM6SR99GKJtBGSIZ1upzk7O9bpKc93yIWSICH3Zkv8K6M dsyr4p94hE7jlcecRBZ1gcudJI8gsz30kAchYlE= X-Google-Smtp-Source: ABdhPJxBloaAiz0HAaHf9LctQ9ERoE+LLRTisCSRn616oXt9jG6VoFaIQnrOE+c1ULxuCDdwUb6iWASm9tPnzxDZLBk= X-Received: by 2002:a05:6e02:1bef:: with SMTP id y15mr7232483ilv.295.1633681043667; Fri, 08 Oct 2021 01:17:23 -0700 (PDT) MIME-Version: 1.0 References: <20211001202456.2073532-1-tduszynski@marvell.com> In-Reply-To: <20211001202456.2073532-1-tduszynski@marvell.com> From: Jerin Jacob Date: Fri, 8 Oct 2021 13:46:57 +0530 Message-ID: To: Tomasz Duszynski , Ferruh Yigit Cc: dpdk-dev , Jerin Jacob , Nithin Dabilpuram , Kiran Kumar K , Sunil Kumar Kori , Satha Rao Content-Type: text/plain; charset="UTF-8" Subject: Re: [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" On Sat, Oct 2, 2021 at 1:55 AM Tomasz Duszynski wrote: > > 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 Applied to dpdk-next-net-mrvl/for-next-net. Thanks > --- > 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 > -- > 2.25.1 >