From patchwork Mon Sep 23 11:56:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 1988570 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=jcfdv8id; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=ventanamicro.com header.i=@ventanamicro.com header.a=rsa-sha256 header.s=google header.b=Tsel/4SS; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:3::133; helo=bombadil.infradead.org; envelope-from=opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=patchwork.ozlabs.org) Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4XC1hR2P7zz1xsg for ; Mon, 23 Sep 2024 21:57:43 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=ZSNmDOUc4XHg+TpShBwHquz6O1V5fn7232w3xraaAKA=; b=jcfdv8id6+PdLN OwF3Vhi6kPP86c4scTr0P96wP6DTez7IdhzKWbmh8QdCfIVxTC4RxS5JvKaITGXsTZgEfBcNIPEnp DWLbCOFiu3PupCi0dA4vTtNrwfIphs49npEP/atnR0x0GlUIdDlcckmuziR64NLja2+dWWF8Km7y8 krgS2P6troAU52dv/oFozfymz5ZbfHF5Lx4LNG77O+6ExjWhwJiH2C4cWATdhpFkzXU+iMadzvoWZ xTo/iEjB7E44UdRcljzDcDWfLd4Swwh7wkVi7auxBLqQg+hCjiRj0ZmR72rIPpZ45gFYxLaxg4jlF nF2TuKmC1mkmFWSZ/tyw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1sshhB-0000000H7QN-27ut; Mon, 23 Sep 2024 11:57:37 +0000 Received: from mail-pj1-x1031.google.com ([2607:f8b0:4864:20::1031]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1sshh8-0000000H7Na-0vcn for opensbi@lists.infradead.org; Mon, 23 Sep 2024 11:57:35 +0000 Received: by mail-pj1-x1031.google.com with SMTP id 98e67ed59e1d1-2da4ea973bdso3376752a91.1 for ; Mon, 23 Sep 2024 04:57:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1727092653; x=1727697453; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=41+bb0AJAa5m2e2zH4ksehlYKDsNVaILIDfHcWL8OCU=; b=Tsel/4SS7VGfgqlIRRJlqgtlMKhCyHETW/kvvuesnnuLFNsR3O2YbzCQbYK63ismzN peB0q/T9+hw4Ohke1uYwvtavHYUFSonAe9j0DQmxnGkKSqL0B6OB0H7q3+StjA7RBm3z ZGU4Suplfebl0UgRCGiBc3jzPJyxvpqcSex5iPhwDmOPnys67nqI8eXpK4zV3k+l/AhU AAPrEtTpcHYvF/ckszyFZoBP0rd9qvrorpbfbElulMBj+AMBJePWZFlQtvV8UiYeVqe3 vD1WcVVWdY4itye9UzaDI3GxE+KImuG4M4xM3GqOkcRuj28qRILxSlfrCLe8+qe8exp6 UrVA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727092653; x=1727697453; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=41+bb0AJAa5m2e2zH4ksehlYKDsNVaILIDfHcWL8OCU=; b=r37BcnMkS6vmPlGrI/DnMavblLdZirWkiuRBGxymcvzfaNz7Sh1/H7ephM3zVQ40nW KevtSWpEjo02BhyTAN2nGYDc8Vd92t59did2GAdZF0NwfWH2svAPXmx/KoJsydm1qcQb qKCLySn49qkfB/XACPDUn3zW5K4J7y1nOjf89ZJudxM2n9RC6QnTTKHPECgvw24+z+iO y/7nZ+atUpXQmF1cxBxeCVFAfEUnRw1DXmcxUsPNCTjatYk+NjAk9rGyqX68R6UCxo9S +3YfOme29lhfPGBfGFClWJaLaBVToVDyS0ssVgERmthOfbm5LsLY5fvI17iMjOFv8R1r vv0w== X-Forwarded-Encrypted: i=1; AJvYcCUlPIBN05tTaBkUHCTmeKm6X3fyOa0Ed2Uj94gJK7+CQU6uLZUr/7SbB21WmR1uQFxHU/O15Pg4@lists.infradead.org X-Gm-Message-State: AOJu0Yw4ZScPkW4VdI77CF1MPoRpSPEIVpr6Kwg02FHyZFHOgFb29E4V vL4pmsVBqzH6f+x+jixy4U8cC5ssoelgtlebRXeXFfUZc8X4yCrQkZeMRu2v5g0= X-Google-Smtp-Source: AGHT+IHv7M9i2CozqUcCQrGFy9uM/l7AEJfk/NVkZdMp8oRd6kmjPOHDTFICGq8E2lZEOMePcmRxCA== X-Received: by 2002:a17:90a:5143:b0:2db:ec3c:8a0e with SMTP id 98e67ed59e1d1-2dd7f758735mr13522515a91.35.1727092652971; Mon, 23 Sep 2024 04:57:32 -0700 (PDT) Received: from anup-ubuntu-vm.localdomain ([103.97.165.210]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2dd6ef361b0sm9252106a91.44.2024.09.23.04.57.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Sep 2024 04:57:32 -0700 (PDT) From: Anup Patel To: Atish Patra Cc: Andrew Jones , Anup Patel , opensbi@lists.infradead.org, Anup Patel Subject: [PATCH 7/9] lib: sbi: Introduce domain data Date: Mon, 23 Sep 2024 17:26:58 +0530 Message-ID: <20240923115700.381916-8-apatel@ventanamicro.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240923115700.381916-1-apatel@ventanamicro.com> References: <20240923115700.381916-1-apatel@ventanamicro.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240923_045734_309000_808051EC X-CRM114-Status: GOOD ( 22.26 ) X-Spam-Score: -2.1 (--) X-Spam-Report: Spam detection software, running on the system "bombadil.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: Different parts of OpenSBI require their own per-domain data so introduce domain data (or sbi_domain_data) which can be registered by any part of OpenSBI. Using the domain data, the domain framework w [...] Content analysis details: (-2.1 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2607:f8b0:4864:20:0:0:0:1031 listed in] [list.dnswl.org] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches SPF record -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] X-BeenThere: opensbi@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "opensbi" Errors-To: opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org Different parts of OpenSBI require their own per-domain data so introduce domain data (or sbi_domain_data) which can be registered by any part of OpenSBI. Using the domain data, the domain framework will create a data pointer for every domain which can be used to maintain some per-domain state. Signed-off-by: Anup Patel Reviewed-by: Yu Chien Peter Lin --- include/sbi/sbi_domain.h | 3 + include/sbi/sbi_domain_data.h | 93 +++++++++++++++++++++++ lib/sbi/objects.mk | 1 + lib/sbi/sbi_domain.c | 11 +++ lib/sbi/sbi_domain_data.c | 138 ++++++++++++++++++++++++++++++++++ 5 files changed, 246 insertions(+) create mode 100755 include/sbi/sbi_domain_data.h create mode 100755 lib/sbi/sbi_domain_data.c diff --git a/include/sbi/sbi_domain.h b/include/sbi/sbi_domain.h index 22aa8e50..60d7a776 100644 --- a/include/sbi/sbi_domain.h +++ b/include/sbi/sbi_domain.h @@ -15,6 +15,7 @@ #include #include #include +#include struct sbi_scratch; @@ -163,6 +164,8 @@ struct sbi_domain_memregion { struct sbi_domain { /** Node in linked list of domains */ struct sbi_dlist node; + /** Internal state of per-domain data */ + struct sbi_domain_data_priv data_priv; /** Logical index of this domain */ u32 index; /** HARTs assigned to this domain */ diff --git a/include/sbi/sbi_domain_data.h b/include/sbi/sbi_domain_data.h new file mode 100755 index 00000000..7eeafdce --- /dev/null +++ b/include/sbi/sbi_domain_data.h @@ -0,0 +1,93 @@ +/* + * SPDX-License-Identifier: BSD-2-Clause + * + * Copyright (c) 2024 Ventana Micro Systems Inc. + */ + +#ifndef __SBI_DOMAIN_DATA_H__ +#define __SBI_DOMAIN_DATA_H__ + +#include +#include + +struct sbi_domain; + +/** Maximum domain data per-domain */ +#define SBI_DOMAIN_MAX_DATA_PTRS 32 + +/** Representation of per-domain data */ +struct sbi_domain_data_priv { + /** Array of domain data pointers indexed by domain data identifier */ + void *idx_to_data_ptr[SBI_DOMAIN_MAX_DATA_PTRS]; +}; + +/** Representation of a domain data */ +struct sbi_domain_data { + /** + * Head is used for maintaining data list + * + * Note: initialized by domain framework + */ + struct sbi_dlist head; + /** + * Identifier which used to locate per-domain data + * + * Note: initialized by domain framework + */ + unsigned long data_idx; + /** Size of per-domain data */ + unsigned long data_size; + /** Optional callback to setup domain data */ + int (*data_setup)(struct sbi_domain *dom, + struct sbi_domain_data *data, void *data_ptr); + /** Optional callback to cleanup domain data */ + void (*data_cleanup)(struct sbi_domain *dom, + struct sbi_domain_data *data, void *data_ptr); +}; + +/** + * Get per-domain data pointer for a given domain + * @param dom pointer to domain + * @param data pointer to domain data + * + * @return per-domain data pointer + */ +void *sbi_domain_data_ptr(struct sbi_domain *dom, struct sbi_domain_data *data); + +/** + * Setup all domain data for a domain + * @param dom pointer to domain + * + * @return 0 on success and negative error code on failure + * + * Note: This function is used internally within domain framework. + */ +int sbi_domain_setup_data(struct sbi_domain *dom); + +/** + * Cleanup all domain data for a domain + * @param dom pointer to domain + * + * Note: This function is used internally within domain framework. + */ +void sbi_domain_cleanup_data(struct sbi_domain *dom); + +/** + * Register a domain data + * @param hndl pointer to domain data + * + * @return 0 on success and negative error code on failure + * + * Note: This function must be used only in cold boot path. + */ +int sbi_domain_register_data(struct sbi_domain_data *data); + +/** + * Unregister a domain data + * @param hndl pointer to domain data + * + * Note: This function must be used only in cold boot path. + */ +void sbi_domain_unregister_data(struct sbi_domain_data *data); + +#endif diff --git a/lib/sbi/objects.mk b/lib/sbi/objects.mk index 535aa709..0b114bbd 100644 --- a/lib/sbi/objects.mk +++ b/lib/sbi/objects.mk @@ -65,6 +65,7 @@ libsbi-objs-y += sbi_bitmap.o libsbi-objs-y += sbi_bitops.o libsbi-objs-y += sbi_console.o libsbi-objs-y += sbi_domain_context.o +libsbi-objs-y += sbi_domain_data.o libsbi-objs-y += sbi_domain.o libsbi-objs-y += sbi_emulate_csr.o libsbi-objs-y += sbi_fifo.o diff --git a/lib/sbi/sbi_domain.c b/lib/sbi/sbi_domain.c index 04e70d3b..22c5c752 100644 --- a/lib/sbi/sbi_domain.c +++ b/lib/sbi/sbi_domain.c @@ -587,6 +587,15 @@ int sbi_domain_register(struct sbi_domain *dom, } } + /* Setup data for the discovered domain */ + rc = sbi_domain_setup_data(dom); + if (rc) { + sbi_printf("%s: domain data setup failed for %s (error %d)\n", + __func__, dom->name, rc); + sbi_list_del(&dom->node); + return rc; + } + return 0; } @@ -753,6 +762,8 @@ int sbi_domain_init(struct sbi_scratch *scratch, u32 cold_hartid) struct sbi_domain_memregion *root_memregs; const struct sbi_platform *plat = sbi_platform_ptr(scratch); + SBI_INIT_LIST_HEAD(&domain_list); + if (scratch->fw_rw_offset == 0 || (scratch->fw_rw_offset & (scratch->fw_rw_offset - 1)) != 0) { sbi_printf("%s: fw_rw_offset is not a power of 2 (0x%lx)\n", diff --git a/lib/sbi/sbi_domain_data.c b/lib/sbi/sbi_domain_data.c new file mode 100755 index 00000000..04f0edf9 --- /dev/null +++ b/lib/sbi/sbi_domain_data.c @@ -0,0 +1,138 @@ +/* + * SPDX-License-Identifier: BSD-2-Clause + * + * Copyright (c) 2024 Ventana Micro Systems Inc. + */ + +#include +#include +#include +#include + +static SBI_LIST_HEAD(data_list); +static DECLARE_BITMAP(data_idx_bmap, SBI_DOMAIN_MAX_DATA_PTRS); + +void *sbi_domain_data_ptr(struct sbi_domain *dom, struct sbi_domain_data *data) +{ + if (dom && data && data->data_idx < SBI_DOMAIN_MAX_DATA_PTRS) + return dom->data_priv.idx_to_data_ptr[data->data_idx]; + + return NULL; +} + +static int domain_setup_data_one(struct sbi_domain *dom, + struct sbi_domain_data *data) +{ + struct sbi_domain_data_priv *priv = &dom->data_priv; + void *data_ptr; + int rc; + + if (priv->idx_to_data_ptr[data->data_idx]) + return SBI_EALREADY; + + data_ptr = sbi_zalloc(data->data_size); + if (!data_ptr) { + sbi_domain_cleanup_data(dom); + return SBI_ENOMEM; + } + + if (data->data_setup) { + rc = data->data_setup(dom, data, data_ptr); + if (rc) { + sbi_free(data_ptr); + return rc; + } + } + + priv->idx_to_data_ptr[data->data_idx] = data_ptr; + return 0; +} + +static void domain_cleanup_data_one(struct sbi_domain *dom, + struct sbi_domain_data *data) +{ + struct sbi_domain_data_priv *priv = &dom->data_priv; + void *data_ptr; + + data_ptr = priv->idx_to_data_ptr[data->data_idx]; + if (!data_ptr) + return; + + if (data->data_cleanup) + data->data_cleanup(dom, data, data_ptr); + + sbi_free(data_ptr); + priv->idx_to_data_ptr[data->data_idx] = NULL; +} + +int sbi_domain_setup_data(struct sbi_domain *dom) +{ + struct sbi_domain_data *data; + int rc; + + if (!dom) + return SBI_EINVAL; + + sbi_list_for_each_entry(data, &data_list, head) { + rc = domain_setup_data_one(dom, data); + if (rc) { + sbi_domain_cleanup_data(dom); + return rc; + } + } + + return 0; +} + +void sbi_domain_cleanup_data(struct sbi_domain *dom) +{ + struct sbi_domain_data *data; + + if (!dom) + return; + + sbi_list_for_each_entry(data, &data_list, head) + domain_cleanup_data_one(dom, data); +} + +int sbi_domain_register_data(struct sbi_domain_data *data) +{ + struct sbi_domain *dom; + u32 data_idx; + int rc; + + if (!data || !data->data_size) + return SBI_EINVAL; + + for (data_idx = 0; data_idx < SBI_DOMAIN_MAX_DATA_PTRS; data_idx++) { + if (!bitmap_test(data_idx_bmap, data_idx)) + break; + } + if (SBI_DOMAIN_MAX_DATA_PTRS <= data_idx) + return SBI_ENOSPC; + bitmap_set(data_idx_bmap, data_idx, 1); + + data->data_idx = data_idx; + sbi_list_add_tail(&data->head, &data_list); + + sbi_domain_for_each(dom) { + rc = domain_setup_data_one(dom, data); + if (rc) { + sbi_domain_unregister_data(data); + return rc; + } + } + + return 0; +} + +void sbi_domain_unregister_data(struct sbi_domain_data *data) +{ + struct sbi_domain *dom; + + sbi_domain_for_each(dom) + domain_cleanup_data_one(dom, data); + + sbi_list_del(&data->head); + bitmap_clear(data_idx_bmap, data->data_idx, 1); +}