From patchwork Tue Aug 6 07:33:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 1969353 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=g+3D4kak; 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=isoH7Xe6; 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 4WdQ6G6LBMz1yYD for ; Tue, 6 Aug 2024 17:33:58 +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=rrwP9/rfPz694HzYgL3+m2NoYcGUweeI1mQ+fRyXEOQ=; b=g+3D4kakYE4UsZ ize6yRs9+5srdsd6uRleV9JsvaDgxCMIwYyxmW4gKZ1fQEN117mpCRl7YmY65s3Hz5tmsJk3qHP0u x3AGQBuVqNYECe+R4NB6CXqnm9dBwY6/4R4tuUPhliWB0fW86RuWvcLL3OguEKm3EQSD6UubYjz5f Z1q1xDtHQRQewceNMM8qebasNYcWHQEgJtFKZTp3cDKQO99NW3oJYVWx1oZvXbGK5g2ahKRmN7Yok vj0+fM25kpcovly/AM0aXqBbc5ISGhDBFJX9YfRpke8degzSx/JfzY9Lkd1NFRU02n1+YAkSgPw48 ZxBygmFV1sM0GJ9WG5xg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sbEha-00000000nix-3wIv; Tue, 06 Aug 2024 07:33:50 +0000 Received: from mail-pf1-x435.google.com ([2607:f8b0:4864:20::435]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sbEhY-00000000ni8-3MyS for opensbi@lists.infradead.org; Tue, 06 Aug 2024 07:33:50 +0000 Received: by mail-pf1-x435.google.com with SMTP id d2e1a72fcca58-70ea2f25bfaso203265b3a.1 for ; Tue, 06 Aug 2024 00:33:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1722929628; x=1723534428; 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=5OqsrHvigNFg2ygUR+D353nFmGeoJerXW+yukN3qgHg=; b=isoH7Xe6pvxlCUQ4AU8zGE7x5AiA6ABSNPhrdOco4lrVElrrqCNC3TF3cyqvHs7xto 6FqIfaFEc1wz6vRep4DBIZ4LqoLpXVCoNu0UdiaqSxZRTaGRVbb9YOS0Kn1gt4F4b3RR hwTwXyzoe+Y84C/wUjNrR5UWJsmFHH2ue1G/W3U883WRA3d96rXYvStmX8USMg/hqGUh thEz/kPUP0y37rdYOKPofMw9vvPImnA9OzTq1LVhTCNof2VIzgimWUTDFzEunKxbAg4A tlFEFN1TievqFx65uRebBa2cB4SqvQuHnOYEHIF8HE4CoN7cawcyjfuokdw9W+ChBuD4 YJbA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722929628; x=1723534428; 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=5OqsrHvigNFg2ygUR+D353nFmGeoJerXW+yukN3qgHg=; b=o0/7QXuAPgHMRLcjxmqLdiS9raWxH8JhnnN+jBc5gZYWcAfQn5IQsn94h4W3x5wBXB 5ei6btYfijUryxztRB4peZVrx+UzyVkly5d/Ee5N6oJZnm36UcelPuSosWYdOcs6nXg1 julRlIgYCqSbgkWnA3f0QedGCOSgcgM7p+jswqg5kYm9ITS6H2N1y9USdbSTscSZ5TgR GUDqpyPAF70J9NpEb/fQ1gnZgzkrCgGaBQOhqzYJkE+uXjEqkA9c5VkOqyvUMVVH1Hsf pJ3PDXHjxgj0wnuTuvbp3b20x95XVU0gQnwbKEthdwjzZswWQ+q3EejDDozCrrgwhqJw Q94w== X-Forwarded-Encrypted: i=1; AJvYcCV8UDWKsy5iCh9lXZ0x57vviQj2fIeywppxhS3dkTWKo9lLQCMWvbEXM+Jr+8UtzY9w6Gap2CMzSp2Nj2FFor/lcgeV/VrDAnvx29Y= X-Gm-Message-State: AOJu0YxG5TirxwNofYMyVFQ354w3M38Z1oiGGS1QII3fI4oEK+o3Dqlf KqiDf5kgQR8HXckBitBzQyvkHDecM0qrCTC+Ofl6jTyIjJPWTXke8CyuQ2MFBKKPvQ3QRmK7OnU z X-Google-Smtp-Source: AGHT+IHQSQyxfj9q1qw5kD+x22I0BO1ZiWYrCfEppT8N0LjZ7BGxoCQ8/+IZ5d/MDiH4WNyy/QmYMA== X-Received: by 2002:a05:6a00:b53:b0:710:5848:8ae1 with SMTP id d2e1a72fcca58-7106cf8fd33mr14656804b3a.4.1722929627633; Tue, 06 Aug 2024 00:33:47 -0700 (PDT) Received: from anup-ubuntu-vm.localdomain ([223.185.134.124]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7106ed2de28sm6455011b3a.191.2024.08.06.00.33.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Aug 2024 00:33:47 -0700 (PDT) From: Anup Patel To: Atish Patra Cc: Andrew Jones , Anup Patel , opensbi@lists.infradead.org, Rahul Pathak , Anup Patel Subject: [PATCH 01/16] lib: Increase ROOT_REGION_MAX to accomodate more memregions Date: Tue, 6 Aug 2024 13:03:23 +0530 Message-Id: <20240806073338.1856901-2-apatel@ventanamicro.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240806073338.1856901-1-apatel@ventanamicro.com> References: <20240806073338.1856901-1-apatel@ventanamicro.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240806_003348_863623_0AAFB7DA X-CRM114-Status: GOOD ( 10.30 ) 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: From: Rahul Pathak As more drivers adding memregions into root domain, the current static limit of ROOT_REGION_MAX is not sufficient. Increase the limit to accomodate more memregions. 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:435 listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -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 From: Rahul Pathak As more drivers adding memregions into root domain, the current static limit of ROOT_REGION_MAX is not sufficient. Increase the limit to accomodate more memregions. Signed-off-by: Rahul Pathak Signed-off-by: Anup Patel --- lib/sbi/sbi_domain.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/sbi/sbi_domain.c b/lib/sbi/sbi_domain.c index 374ac36b..65649169 100644 --- a/lib/sbi/sbi_domain.c +++ b/lib/sbi/sbi_domain.c @@ -26,7 +26,7 @@ struct sbi_domain *domidx_to_domain_table[SBI_DOMAIN_MAX_INDEX + 1] = { 0 }; static u32 domain_count = 0; static bool domain_finalized = false; -#define ROOT_REGION_MAX 16 +#define ROOT_REGION_MAX 32 static u32 root_memregs_count = 0; struct sbi_domain root = { From patchwork Tue Aug 6 07:33:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 1969355 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=3a7MiPq+; 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=GOircqZV; 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 4WdQ6K6Zmqz1yYD for ; Tue, 6 Aug 2024 17:34:01 +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=2JmA0t8heW55McVi9AQEOlsCkwJEuBCZ/Gn4y4y9RXM=; b=3a7MiPq+fq8zBg YZmjW6Fq4gStsvpgs6CkPsR5AWVoRh/sgi/wUkZ8lpQiw/gDQAezT2E1oUVzG/cP0g94o3a9TlkW4 lzdITKG2WZbnHR/zOdCL08c3788RVYALJDFmlF+lwWcBXm/sR17O6zQE8p2AU/v5FBwVqnntGFUME fR2ESM8gztYiOIDQYdBivMEUk9TW0pzYwxd7jg5Of9zIS76O6ZBxJtVD1WjZiqsvcTGTaOrxyQI0s iUt165lCSqdDFYsffxpvrSAjIw9T8COpiRkbH404lgfuqrXDhTXNHf0pfovUdPSpSVcaB69L8KHAR mSJy5TGmDbJ5m+pcbvAQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sbEhe-00000000nkU-2eYX; Tue, 06 Aug 2024 07:33:54 +0000 Received: from mail-pf1-x430.google.com ([2607:f8b0:4864:20::430]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sbEhb-00000000nj5-2eUj for opensbi@lists.infradead.org; Tue, 06 Aug 2024 07:33:52 +0000 Received: by mail-pf1-x430.google.com with SMTP id d2e1a72fcca58-7107b16be12so231877b3a.3 for ; Tue, 06 Aug 2024 00:33:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1722929631; x=1723534431; 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=wXWUNXUCshdcJXebGuFo5x+khY5BAvsLrbmq4KLi7L0=; b=GOircqZVV48LE0gWPF0UV5jH04LOhnfX3m4M/pOfMQWMLHXzTrH2Umkk3fV63PARQl 76ovOG0rtQqKXq9GMQdv4x2cW0Stnhj4bq9rWPZuc6V1foCr2kstehc3ZgzpVCiNTfOo m8Ik6KJ/4o7sP0zeXcBuS790bmwJNDeTX+Bw4nQwaokSdv+LH4Q3FQydGSzwyGQhRbyg bsGNKpIFEUI8pGBon+GbK7CC56er6C1FA92Vh5dQ0mmkgBdtcVcFh+X3loVrorzr5ELc ZXnS2IrIutQ57NrDn+gfFK1NKZubv+SrSE4X7Z7RuBZAq4lwN7G/aczAoZjeZU/AGbwI t3yw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722929631; x=1723534431; 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=wXWUNXUCshdcJXebGuFo5x+khY5BAvsLrbmq4KLi7L0=; b=sy97PSJLAOJJkjn0qSfVPszl1c300u2fnaxOKGmkhDHvmAKw+ESePG5UXJlGEvfaiy 5sWl+Umur5wljr8NZk1UgYAUNe/fr/i7I/60JyAEVj4IvI5T2SLrb5hwFIPDC8mXaCYh g+8m8U5iX+9Gg65exs/7YlR6t22Ia3oxkdaz2k+iQttljqoSmjIbh7Ob1wJJ/LWPV0I2 t2eW948eOt43YCLZjEZhQM6jN1T5TMn1UP7ga2anU9mHJxV2Jsw8sDVoPDxe8cnS4kmj cK8nIE9UWkHx31HWEM3Uy1PKrV4Dml60dveW3V6hk67KVcwoqSg6gIsi81hYM6JuOVDc l6AA== X-Forwarded-Encrypted: i=1; AJvYcCWAFUwEjAXLgDFmiHf0fk+eeShvKtTxYjwuWb6MDBNrd/wcWrr1h9wXXLG/FRcZCyOmJOAUQOd28BouxcO8EY/VWrR2MW45vNM/MPU= X-Gm-Message-State: AOJu0YyLw+HvRbKy28uzL4AXqtrNhwwQNjw3LaWg4N+3o1upkRHDrhSi alDh5bnyLATeHyePLvqKr1hFVzr8+/CekRGBnbCXNb41UUUr76prcTha3sxV6TA= X-Google-Smtp-Source: AGHT+IFbJzwwvtolJ2zOtn2ENi8i2NVR69O/qeujDYjv7sxfCZtR4tCwvfbRsOFhlyGhLt8uNszKww== X-Received: by 2002:a05:6a00:2287:b0:70d:2c8d:bed0 with SMTP id d2e1a72fcca58-7106d046be9mr13623065b3a.24.1722929630415; Tue, 06 Aug 2024 00:33:50 -0700 (PDT) Received: from anup-ubuntu-vm.localdomain ([223.185.134.124]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7106ed2de28sm6455011b3a.191.2024.08.06.00.33.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Aug 2024 00:33:49 -0700 (PDT) From: Anup Patel To: Atish Patra Cc: Andrew Jones , Anup Patel , opensbi@lists.infradead.org, Anup Patel Subject: [PATCH 02/16] lib: utils/mailbox: Add generic mailbox library Date: Tue, 6 Aug 2024 13:03:24 +0530 Message-Id: <20240806073338.1856901-3-apatel@ventanamicro.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240806073338.1856901-1-apatel@ventanamicro.com> References: <20240806073338.1856901-1-apatel@ventanamicro.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240806_003351_700671_D7C912C0 X-CRM114-Status: GOOD ( 22.78 ) 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: Add generic mailbox library which is independent of hardware description format. The OpenSBI platform support or mailbox drivers can register mailbox controller instances which can be discovered and u [...] 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:430 listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -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 Add generic mailbox library which is independent of hardware description format. The OpenSBI platform support or mailbox drivers can register mailbox controller instances which can be discovered and used by different mailbox client drivers. Each mailbox controller instance has a unique ID which can be used by mailbox client drivers for find the mailbox controller instance. The mailbox client drivers will typically request a mailbox channel from the mailbox controller and use it to do data transfer with the remote end of mailbox channel. Signed-off-by: Anup Patel --- include/sbi_utils/mailbox/mailbox.h | 170 ++++++++++++++++++++++++++++ lib/utils/Kconfig | 2 + lib/utils/mailbox/Kconfig | 9 ++ lib/utils/mailbox/mailbox.c | 116 +++++++++++++++++++ lib/utils/mailbox/objects.mk | 10 ++ 5 files changed, 307 insertions(+) create mode 100644 include/sbi_utils/mailbox/mailbox.h create mode 100644 lib/utils/mailbox/Kconfig create mode 100644 lib/utils/mailbox/mailbox.c create mode 100644 lib/utils/mailbox/objects.mk diff --git a/include/sbi_utils/mailbox/mailbox.h b/include/sbi_utils/mailbox/mailbox.h new file mode 100644 index 00000000..7206ce81 --- /dev/null +++ b/include/sbi_utils/mailbox/mailbox.h @@ -0,0 +1,170 @@ +/* + * SPDX-License-Identifier: BSD-2-Clause + * + * Copyright (c) 2024 Ventana Micro Systems Inc. + * + * Authors: + * Anup Patel + */ + +#ifndef __MAILBOX_H__ +#define __MAILBOX_H__ + +#include +#include +#include + +/** Representation of a mailbox channel */ +struct mbox_chan { + /** List head */ + struct sbi_dlist node; + /** Pointer to the mailbox controller */ + struct mbox_controller *mbox; + /** + * Arguments (or parameters) to identify a mailbox channel + * within a mailbox controller. + */ +#define MBOX_CHAN_MAX_ARGS 2 + u32 chan_args[MBOX_CHAN_MAX_ARGS]; +}; + +#define to_mbox_chan(__node) \ + container_of((__node), struct mbox_chan, node) + +/** + * Representation of a mailbox data transfer + * + * NOTE: If both "tx" and "rx" are non-NULL then Tx is done before Rx. + */ +struct mbox_xfer { +#define MBOX_XFER_SEQ (1UL << 0) + /** Transfer flags */ + unsigned long flags; + /** Transfer arguments (or parameters) */ + void *args; + /** + * Sequence number + * + * If MBOX_XFER_SEQ is not set in flags then mbox_chan_xfer() + * will generate a unique sequence number and update this field + * else mbox_chan_xfer() will blindly use the sequence number + * specified by this field. + */ + long seq; + /** Send data pointer */ + void *tx; + /** Send data length (valid only if tx != NULL) */ + unsigned long tx_len; + /** + * Send timeout milliseconds (valid only if tx != NULL) + * + * If this field is non-zero along with tx != NULL then the + * mailbox controller driver will wait specified milliseconds + * for send data transfer to complete else the mailbox controller + * driver will not wait. + */ + unsigned long tx_timeout; + /** Receive data pointer */ + void *rx; + /** Receive data length (valid only if rx != NULL) */ + unsigned long rx_len; + /** + * Receive timeout milliseconds (valid only if rx != NULL) + * + * If this field is non-zero along with rx != NULL then the + * mailbox controller driver will wait specified milliseconds + * for receive data transfer to complete else the mailbox + * controller driver will not wait. + */ + unsigned long rx_timeout; +}; + +#define mbox_xfer_init_tx(__p, __a, __t, __t_len, __t_tim) \ +do { \ + (__p)->flags = 0; \ + (__p)->args = (__a); \ + (__p)->tx = (__t); \ + (__p)->tx_len = (__t_len); \ + (__p)->tx_timeout = (__t_tim); \ + (__p)->rx = NULL; \ + (__p)->rx_len = 0; \ + (__p)->rx_timeout = 0; \ +} while (0) + +#define mbox_xfer_init_rx(__p, __a, __r, __r_len, __r_tim) \ +do { \ + (__p)->flags = 0; \ + (__p)->args = (__a); \ + (__p)->tx = NULL; \ + (__p)->tx_len = 0; \ + (__p)->tx_timeout = 0; \ + (__p)->rx = (__r); \ + (__p)->rx_len = (__r_len); \ + (__p)->rx_timeout = (__r_tim); \ +} while (0) + +#define mbox_xfer_init_txrx(__p, __a, __t, __t_len, __t_tim, __r, __r_len, __r_tim)\ +do { \ + (__p)->flags = 0; \ + (__p)->args = (__a); \ + (__p)->tx = (__t); \ + (__p)->tx_len = (__t_len); \ + (__p)->tx_timeout = (__t_tim); \ + (__p)->rx = (__r); \ + (__p)->rx_len = (__r_len); \ + (__p)->rx_timeout = (__r_tim); \ +} while (0) + +#define mbox_xfer_set_sequence(__p, __seq) \ +do { \ + (__p)->flags |= MBOX_XFER_SEQ; \ + (__p)->seq = (__seq); \ +} while (0) + +/** Representation of a mailbox controller */ +struct mbox_controller { + /** List head */ + struct sbi_dlist node; + /** Next sequence atomic counter */ + atomic_t xfer_next_seq; + /* List of mailbox channels */ + struct sbi_dlist chan_list; + /** Unique ID of the mailbox controller assigned by the driver */ + unsigned int id; + /** Maximum length of transfer supported by the mailbox controller */ + unsigned int max_xfer_len; + /** Pointer to mailbox driver owning this mailbox controller */ + void *driver; + /** Request a mailbox channel from the mailbox controller */ + struct mbox_chan *(*request_chan)(struct mbox_controller *mbox, + u32 *chan_args); + /** Free a mailbox channel from the mailbox controller */ + void *(*free_chan)(struct mbox_controller *mbox, + struct mbox_chan *chan); + /** Transfer data over mailbox channel */ + int (*xfer)(struct mbox_chan *chan, struct mbox_xfer *xfer); +}; + +#define to_mbox_controller(__node) \ + container_of((__node), struct mbox_controller, node) + +/** Find a registered mailbox controller */ +struct mbox_controller *mbox_controller_find(unsigned int id); + +/** Register mailbox controller */ +int mbox_controller_add(struct mbox_controller *mbox); + +/** Un-register mailbox controller */ +void mbox_controller_remove(struct mbox_controller *mbox); + +/** Request a mailbox channel */ +struct mbox_chan *mbox_controller_request_chan(struct mbox_controller *mbox, + u32 *chan_args); + +/** Free a mailbox channel */ +void mbox_controller_free_chan(struct mbox_chan *chan); + +/** Data transfer over mailbox channel */ +int mbox_chan_xfer(struct mbox_chan *chan, struct mbox_xfer *xfer); + +#endif diff --git a/lib/utils/Kconfig b/lib/utils/Kconfig index de8b4eb9..6aa7843c 100644 --- a/lib/utils/Kconfig +++ b/lib/utils/Kconfig @@ -14,6 +14,8 @@ source "$(OPENSBI_SRC_DIR)/lib/utils/irqchip/Kconfig" source "$(OPENSBI_SRC_DIR)/lib/utils/libfdt/Kconfig" +source "$(OPENSBI_SRC_DIR)/lib/utils/mailbox/Kconfig" + source "$(OPENSBI_SRC_DIR)/lib/utils/regmap/Kconfig" source "$(OPENSBI_SRC_DIR)/lib/utils/reset/Kconfig" diff --git a/lib/utils/mailbox/Kconfig b/lib/utils/mailbox/Kconfig new file mode 100644 index 00000000..f91a9bb9 --- /dev/null +++ b/lib/utils/mailbox/Kconfig @@ -0,0 +1,9 @@ +# SPDX-License-Identifier: BSD-2-Clause + +menu "Mailbox Support" + +config MAILBOX + bool "Mailbox support" + default n + +endmenu diff --git a/lib/utils/mailbox/mailbox.c b/lib/utils/mailbox/mailbox.c new file mode 100644 index 00000000..86f2feac --- /dev/null +++ b/lib/utils/mailbox/mailbox.c @@ -0,0 +1,116 @@ +/* + * SPDX-License-Identifier: BSD-2-Clause + * + * Copyright (c) 2024 Ventana Micro Systems Inc. + * + * Authors: + * Anup Patel + */ + +#include +#include +#include + +static SBI_LIST_HEAD(mbox_list); + +struct mbox_controller *mbox_controller_find(unsigned int id) +{ + struct sbi_dlist *pos; + + sbi_list_for_each(pos, &mbox_list) { + struct mbox_controller *mbox = to_mbox_controller(pos); + + if (mbox->id == id) + return mbox; + } + + return NULL; +} + +int mbox_controller_add(struct mbox_controller *mbox) +{ + if (!mbox || !mbox->max_xfer_len) + return SBI_EINVAL; + if (mbox_controller_find(mbox->id)) + return SBI_EALREADY; + + SBI_INIT_LIST_HEAD(&mbox->node); + ATOMIC_INIT(&mbox->xfer_next_seq, 0); + SBI_INIT_LIST_HEAD(&mbox->chan_list); + sbi_list_add(&mbox->node, &mbox_list); + + return 0; +} + +void mbox_controller_remove(struct mbox_controller *mbox) +{ + struct mbox_chan *chan; + + if (!mbox) + return; + + while (!sbi_list_empty(&mbox->chan_list)) { + chan = sbi_list_first_entry(&mbox->chan_list, + struct mbox_chan, node); + if (mbox->free_chan) + mbox->free_chan(mbox, chan); + sbi_list_del(&chan->node); + } + + sbi_list_del(&mbox->node); +} + +struct mbox_chan *mbox_controller_request_chan(struct mbox_controller *mbox, + u32 *chan_args) +{ + struct mbox_chan *ret; + struct sbi_dlist *pos; + + if (!chan_args || !mbox || !mbox->request_chan) + return NULL; + + sbi_list_for_each(pos, &mbox->chan_list) { + ret = to_mbox_chan(pos); + if (!sbi_memcmp(ret->chan_args, chan_args, + sizeof(ret->chan_args))) + return ret; + } + + ret = mbox->request_chan(mbox, chan_args); + if (!ret) + return NULL; + + SBI_INIT_LIST_HEAD(&ret->node); + ret->mbox = mbox; + sbi_memcpy(ret->chan_args, chan_args, sizeof(ret->chan_args)); + sbi_list_add(&ret->node, &mbox->chan_list); + return ret; +} + +void mbox_controller_free_chan(struct mbox_chan *chan) +{ + if (!chan || !chan->mbox) + return; + + if (chan->mbox->free_chan) + chan->mbox->free_chan(chan->mbox, chan); + sbi_list_del(&chan->node); +} + +int mbox_chan_xfer(struct mbox_chan *chan, struct mbox_xfer *xfer) +{ + if (!xfer || !chan || !chan->mbox || !chan->mbox->xfer) + return SBI_EINVAL; + + if (xfer->tx && (xfer->tx_len > chan->mbox->max_xfer_len)) + return SBI_EINVAL; + + if (xfer->rx && (xfer->rx_len > chan->mbox->max_xfer_len)) + return SBI_EINVAL; + + if (!(xfer->flags & MBOX_XFER_SEQ)) + mbox_xfer_set_sequence(xfer, + atomic_add_return(&chan->mbox->xfer_next_seq, 1)); + + return chan->mbox->xfer(chan, xfer); +} diff --git a/lib/utils/mailbox/objects.mk b/lib/utils/mailbox/objects.mk new file mode 100644 index 00000000..79b27e4c --- /dev/null +++ b/lib/utils/mailbox/objects.mk @@ -0,0 +1,10 @@ +# +# SPDX-License-Identifier: BSD-2-Clause +# +# Copyright (c) 2024 Ventana Micro Systems Inc. +# +# Authors: +# Anup Patel +# + +libsbiutils-objs-$(CONFIG_MAILBOX) += mailbox/mailbox.o From patchwork Tue Aug 6 07:33:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 1969356 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=Ba1e353s; 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=iKD/+rGB; 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 4WdQ6N35ypz1yYD for ; Tue, 6 Aug 2024 17:34:04 +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=snaIF4x6sTVyl/PZfM6mHm2KD9bIFbloLFq3RejbuU8=; b=Ba1e353svpO018 GZ7QrJOHGRqsercvAy4rBXRo39etuAvDWPoxqE/kevn+XJihejM4jwXyIf/Dx1zXYaEUjNhNqxHN8 mJoxIOzCjkUaPSM9QPKz3HM+QIuGt4s8fmNmwKSO62edQ/6FhSrIwdKlCHvpV3Y5LJTOXysQo9qUV f6vrCE/K0mbc0RIxFFq6KfmH753d8vwgONlsL5u6hG+Xs+QfVUHjl8J7m6C5cN3UdXjaQGSBgL+uW E0uhduzX9ZrZntjJk4NwpefO/rZ6P5JqFYVBej8BjSy73kAfiMHrKHN6v3Z6Bz4WYaZ1XGzX9COmZ pPVsh6tQvDBXIcms3RDQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sbEhg-00000000nlP-3Rhj; Tue, 06 Aug 2024 07:33:56 +0000 Received: from mail-pg1-x52d.google.com ([2607:f8b0:4864:20::52d]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sbEhe-00000000nkB-0yew for opensbi@lists.infradead.org; Tue, 06 Aug 2024 07:33:55 +0000 Received: by mail-pg1-x52d.google.com with SMTP id 41be03b00d2f7-75a6c290528so157665a12.1 for ; Tue, 06 Aug 2024 00:33:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1722929633; x=1723534433; 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=wo86vHqf7x8901wkK2oBwU0h8Tw7mYFg2056bBEVWlM=; b=iKD/+rGBuyVNKdxdWu7QYzzkqarStGNa1DckyY0smjflSNtsylUxD4KQUyBHVaJLBL IHFKGQ9qLL9zv8jnxQoWwKHu4swvnWZqMH8MFDa2INboWB3UIztyd0Q0USBXFprAAzpM y3L/gOONREmqeMYwQ+Ib26zZ/uT+XwOK36ilr8qFadepegS3EcwdWYLCND6TTtdQ+PCw Yo/HsmZTuj0vW0NRfKbla23rvQRKx1aVM3IncdT9kS3BV4HMgosGKXxghSq9qZZ/9GDb ltRJxf4ufFGbFh41+BhCH2xN2zzDqpFHnhZCO4IUbzAR1qbC4ys9criNS6PGE130yOlo 4TZg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722929633; x=1723534433; 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=wo86vHqf7x8901wkK2oBwU0h8Tw7mYFg2056bBEVWlM=; b=hNkXCKqZzDGaaK7nl5vqGIJF/wDn72W+GSK4zCOtuSBTWk6LLcRFzW2VEPPBYDNRdS 2xqv3vZxbb+3lUOrtl/7q2a6Lq9P1p28OuxpxCQuKBtZ6uA7SPiA7XU3w5Bi64XsnP7X iZAON3QcRN9vMt5yeeIDEoTBlcEmm/+49CfuEs+lPkdelQBHcHk4i3RmLuPhTjBCMICD K4eY3aBnmTNeAlY3vismNrRSzpE88rey0VNa9dzS2hbrjYKRK1suNqhErLiMJJCAdRu5 Hhvmmkmonre90lTD3pRo15jBauAHWc50z0+d6ohyhG1eMc1UKsl96qaHmGF8Hz0wru0C j9MA== X-Forwarded-Encrypted: i=1; AJvYcCVX3zeviwN1+SNQ/2jxRrz+MvIT6TS5UKcV+J5LO7+vSwC1hRDOj+hIsJxlpW1lrmEMSD6gCW9u+KXGWmDRjs5VDUgQm7PdhtMyOE4= X-Gm-Message-State: AOJu0YxK9rDB/09cXKkm6SFjM7SR/CxaGbkL2Ou/cWJmG5CxarJZtLfC 4vKGGeLrGwMDiHgRz3QJbcCmJsZ4mgqMX5MU95ZAnj0NyIhez8lrvWN3gxOeqqI= X-Google-Smtp-Source: AGHT+IFqgw8kVe0HXrz3WZA+Vu+HJ4JNR3NvFrRKsqEn6Q5MwYMds10ZnKDdmfbhhVnjma3mN25Ceg== X-Received: by 2002:a05:6a20:c90c:b0:1c4:c1cd:a29d with SMTP id adf61e73a8af0-1c6995ab267mr14243639637.28.1722929633031; Tue, 06 Aug 2024 00:33:53 -0700 (PDT) Received: from anup-ubuntu-vm.localdomain ([223.185.134.124]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7106ed2de28sm6455011b3a.191.2024.08.06.00.33.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Aug 2024 00:33:52 -0700 (PDT) From: Anup Patel To: Atish Patra Cc: Andrew Jones , Anup Patel , opensbi@lists.infradead.org, Anup Patel Subject: [PATCH 03/16] lib: utils/mailbox: Add simple FDT based mailbox framework Date: Tue, 6 Aug 2024 13:03:25 +0530 Message-Id: <20240806073338.1856901-4-apatel@ventanamicro.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240806073338.1856901-1-apatel@ventanamicro.com> References: <20240806073338.1856901-1-apatel@ventanamicro.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240806_003354_296887_D2F54ACB X-CRM114-Status: GOOD ( 20.25 ) 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: Add a simple FDT based mailbox framework which is built on top of the generic mailbox library. The phandle of FDT mailbox DT node is treated as the unique mailbox controller ID which is required by th [...] 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:52d listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -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 Add a simple FDT based mailbox framework which is built on top of the generic mailbox library. The phandle of FDT mailbox DT node is treated as the unique mailbox controller ID which is required by the generic mailbox library. The FDT based mailbox drivers will be probed on-demand from fdt_mailbox_request_chan() called by the mailbox client drivers. Signed-off-by: Anup Patel --- include/sbi_utils/mailbox/fdt_mailbox.h | 36 +++++ lib/utils/mailbox/Kconfig | 6 + lib/utils/mailbox/fdt_mailbox.c | 142 +++++++++++++++++++ lib/utils/mailbox/fdt_mailbox_drivers.carray | 3 + lib/utils/mailbox/objects.mk | 3 + 5 files changed, 190 insertions(+) create mode 100644 include/sbi_utils/mailbox/fdt_mailbox.h create mode 100644 lib/utils/mailbox/fdt_mailbox.c create mode 100644 lib/utils/mailbox/fdt_mailbox_drivers.carray diff --git a/include/sbi_utils/mailbox/fdt_mailbox.h b/include/sbi_utils/mailbox/fdt_mailbox.h new file mode 100644 index 00000000..27f425db --- /dev/null +++ b/include/sbi_utils/mailbox/fdt_mailbox.h @@ -0,0 +1,36 @@ +/* + * SPDX-License-Identifier: BSD-2-Clause + * + * Copyright (c) 2024 Ventana Micro Systems Inc. + * + * Authors: + * Anup Patel + */ + +#ifndef __FDT_MAILBOX_H__ +#define __FDT_MAILBOX_H__ + +#include + +struct fdt_phandle_args; + +/** FDT based mailbox driver */ +struct fdt_mailbox { + const struct fdt_match *match_table; + int (*xlate)(struct mbox_controller *mbox, + const struct fdt_phandle_args *pargs, + u32 *out_chan_args); + int (*init)(void *fdt, int nodeoff, u32 phandle, + const struct fdt_match *match); +}; + +/** Request a mailbox channel using "mboxes" DT property of client DT node */ +int fdt_mailbox_request_chan(void *fdt, int nodeoff, int index, + struct mbox_chan **out_chan); + +/** Simple xlate function to convert one mailbox FDT cell into channel args */ +int fdt_mailbox_simple_xlate(struct mbox_controller *mbox, + const struct fdt_phandle_args *pargs, + u32 *out_chan_args); + +#endif diff --git a/lib/utils/mailbox/Kconfig b/lib/utils/mailbox/Kconfig index f91a9bb9..3957bfba 100644 --- a/lib/utils/mailbox/Kconfig +++ b/lib/utils/mailbox/Kconfig @@ -2,6 +2,12 @@ menu "Mailbox Support" +config FDT_MAILBOX + bool "FDT based mailbox drivers" + depends on FDT + select MAILBOX + default n + config MAILBOX bool "Mailbox support" default n diff --git a/lib/utils/mailbox/fdt_mailbox.c b/lib/utils/mailbox/fdt_mailbox.c new file mode 100644 index 00000000..85a71429 --- /dev/null +++ b/lib/utils/mailbox/fdt_mailbox.c @@ -0,0 +1,142 @@ +/* + * SPDX-License-Identifier: BSD-2-Clause + * + * Copyright (c) 2024 Ventana Micro Systems Inc. + * + * Authors: + * Anup Patel + */ + +#include +#include +#include +#include + +/* List of FDT mailbox drivers generated at compile time */ +extern struct fdt_mailbox *fdt_mailbox_drivers[]; +extern unsigned long fdt_mailbox_drivers_size; + +static struct fdt_mailbox *fdt_mailbox_driver(struct mbox_controller *mbox) +{ + int pos; + + if (!mbox) + return NULL; + + for (pos = 0; pos < fdt_mailbox_drivers_size; pos++) { + if (mbox->driver == fdt_mailbox_drivers[pos]) + return fdt_mailbox_drivers[pos]; + } + + return NULL; +} + +static int fdt_mailbox_init(void *fdt, u32 phandle) +{ + int pos, nodeoff, rc; + struct fdt_mailbox *drv; + const struct fdt_match *match; + + /* Find node offset */ + nodeoff = fdt_node_offset_by_phandle(fdt, phandle); + if (nodeoff < 0) + return nodeoff; + + /* Try all mailbox drivers one-by-one */ + for (pos = 0; pos < fdt_mailbox_drivers_size; pos++) { + drv = fdt_mailbox_drivers[pos]; + + match = fdt_match_node(fdt, nodeoff, drv->match_table); + if (match && drv->init) { + rc = drv->init(fdt, nodeoff, phandle, match); + if (rc == SBI_ENODEV) + continue; + if (rc) + return rc; + return 0; + } + } + + return SBI_ENOSYS; +} + +static int fdt_mbox_controller_find(void *fdt, u32 phandle, + struct mbox_controller **out_mbox) +{ + int rc; + struct mbox_controller *mbox = mbox_controller_find(phandle); + + if (!mbox) { + /* mailbox not found so initialize matching driver */ + rc = fdt_mailbox_init(fdt, phandle); + if (rc) + return rc; + + /* Try to find mailbox controller again */ + mbox = mbox_controller_find(phandle); + if (!mbox) + return SBI_ENOSYS; + } + + if (out_mbox) + *out_mbox = mbox; + + return 0; +} + +int fdt_mailbox_request_chan(void *fdt, int nodeoff, int index, + struct mbox_chan **out_chan) +{ + int rc; + struct mbox_chan *chan; + struct fdt_mailbox *drv; + struct fdt_phandle_args pargs; + struct mbox_controller *mbox = NULL; + u32 phandle, chan_args[MBOX_CHAN_MAX_ARGS]; + + if (!fdt || (nodeoff < 0) || (index < 0) || !out_chan) + return SBI_EINVAL; + + pargs.node_offset = pargs.args_count = 0; + rc = fdt_parse_phandle_with_args(fdt, nodeoff, + "mboxes", "#mbox-cells", + index, &pargs); + if (rc) + return rc; + + phandle = fdt_get_phandle(fdt, pargs.node_offset); + rc = fdt_mbox_controller_find(fdt, phandle, &mbox); + if (rc) + return rc; + + drv = fdt_mailbox_driver(mbox); + if (!drv || !drv->xlate) + return SBI_ENOSYS; + + rc = drv->xlate(mbox, &pargs, chan_args); + if (rc) + return rc; + + chan = mbox_controller_request_chan(mbox, chan_args); + if (!chan) + return SBI_ENOENT; + + *out_chan = chan; + return 0; +} + +int fdt_mailbox_simple_xlate(struct mbox_controller *mbox, + const struct fdt_phandle_args *pargs, + u32 *out_chan_args) +{ + int i; + + if (pargs->args_count < 1) + return SBI_EINVAL; + + out_chan_args[0] = pargs->args[0]; + for (i = 1; i < MBOX_CHAN_MAX_ARGS; i++) + out_chan_args[i] = 0; + + return 0; +} diff --git a/lib/utils/mailbox/fdt_mailbox_drivers.carray b/lib/utils/mailbox/fdt_mailbox_drivers.carray new file mode 100644 index 00000000..fd4246df --- /dev/null +++ b/lib/utils/mailbox/fdt_mailbox_drivers.carray @@ -0,0 +1,3 @@ +HEADER: sbi_utils/mailbox/fdt_mailbox.h +TYPE: struct fdt_mailbox +NAME: fdt_mailbox_drivers diff --git a/lib/utils/mailbox/objects.mk b/lib/utils/mailbox/objects.mk index 79b27e4c..2135898c 100644 --- a/lib/utils/mailbox/objects.mk +++ b/lib/utils/mailbox/objects.mk @@ -7,4 +7,7 @@ # Anup Patel # +libsbiutils-objs-$(CONFIG_FDT_MAILBOX) += mailbox/fdt_mailbox.o +libsbiutils-objs-$(CONFIG_FDT_MAILBOX) += mailbox/fdt_mailbox_drivers.carray.o + libsbiutils-objs-$(CONFIG_MAILBOX) += mailbox/mailbox.o From patchwork Tue Aug 6 07:33:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 1969358 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=h9WHFKar; 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=SmyDbIva; 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 4WdQ6W210kz1ydt for ; Tue, 6 Aug 2024 17:34:11 +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=U0KRCVmBEOa+mGduprYyPPA42xsLIDKgMTP5M3J9OF0=; b=h9WHFKarmYHfUH mUdx2ln8S7I4AJatKMTcAiI8XpkCIBd0w7j/eGbi8tzh7YSkMUwaaNiyWp40KEeJdtJ6BEjKRf9Np 04U0bCDcykYODFAUb9IwxL4kf2JFv8kMR09BVL7et7MAk021/wDSJEyNvjqe0x7IU7UqBUcIxYXMV uuztdiYotJ4eF6LAYLW5t6cWueJaZKN9vzmAmOOQK6vOdciQWri6qQyEgG1pGs/MRbgF4iBCRHaZF le1Xq3H2uMI/rMA7CMknjOtec8+yKh5n0CE7zKX3QHWYXCruGgjoUIc1JLLMW3tNuCkgHePJjDCEj sfR58Cbvj8kbQzTYWx2A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sbEhm-00000000noH-2CgS; Tue, 06 Aug 2024 07:34:02 +0000 Received: from mail-pg1-x529.google.com ([2607:f8b0:4864:20::529]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sbEhh-00000000nlm-2SHB for opensbi@lists.infradead.org; Tue, 06 Aug 2024 07:34:00 +0000 Received: by mail-pg1-x529.google.com with SMTP id 41be03b00d2f7-7b396521ff6so165851a12.1 for ; Tue, 06 Aug 2024 00:33:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1722929637; x=1723534437; 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=PtaeJ9Ay8YQ3LeMfrwvaANYYFEUfC3/mn4XbVy61s4I=; b=SmyDbIvauRFwnNo/P+opuu9ZbBpP14B1eiRtQ4dPqVFCGW4urbVGXGBE/LEYjbbS3S OWZCn6NePdal8QTsvFlYAYXi6m/zvqc9hEjoVvYS3dbEUL1QobN99Gut2mNpoKe8p8Gw xaRM1S/XGm3zVM56WRB86QepphvW0ykO1uS6PsBddajikuzLKdH3AJVZzx4uatC/Srse wyHQ6FtvtS0kUk0wLRJd2LtEPhdvcrUb8RWP805rRh+aAnP4Tuovz46hNMZ0ip3y/qsL ak2YKgNT8KB8EFQquBLb3oqOTPUS21vqNxDbw1OL2eXnechR+I35tMJBhuQiDJfHpl51 TL+g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722929637; x=1723534437; 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=PtaeJ9Ay8YQ3LeMfrwvaANYYFEUfC3/mn4XbVy61s4I=; b=Vk+xeBgtL6fAFvnf/oeByLRis55lnIoF896WkHprzUm70pASCqgLD9Iy24ugAXg/R8 iAWNHD9cDN0ljQfMmTO+oyeK0lKf/gGPXtnd7C3GTjwSlMGJf8HH8U5vDtQj067TxQbx zO9EpFI4tcl0pl6pXoxhecNepEw5w2e1YwNcT3MW+LszbRTHHScRGPe3we1+luHtDhjV gLJLHvgwSvSDlp3/ThxAtTEMXK1yed8YkxWqixNAALQ/RE0KPlEcNOx52Jy3yqFQZYVU HKD93b/JnE5z5byxaXPwXF2EL5q0OG/MEccyeIexQlHYyztJlF1I6B3PE1XmBTkdxaOU nhQA== X-Forwarded-Encrypted: i=1; AJvYcCUCTDlbnBUTh1+L04WtS08K91Ja0S2AmbXwXaXbFvFDuLPTw2/8q2kSyqMa5wWm0hsorwQ7zT5lTgwVMwr+XqkEIIA3rsWQXIU0eoE= X-Gm-Message-State: AOJu0YyGiH2N5N1O9IxeGLaP1wn0+Vpr+NFUf72LmvAznrf5e35Ix5vh qdPKP+Aw2WoPOk5mQG6S41LeD3q3TeC5K4CgI191DN0LUX0Nz5XSMXnhri6qD5w2i8/14XpzXh3 E X-Google-Smtp-Source: AGHT+IF+AoT0FpeoihqrW7YsqiAwjIapij9kliawllLCRW8B/qcuXai0c/ZOKDrt2k3Lm0cY6g9MaQ== X-Received: by 2002:a05:6a21:3392:b0:1c2:8bf8:e7ab with SMTP id adf61e73a8af0-1c6995720bfmr22638177637.9.1722929636388; Tue, 06 Aug 2024 00:33:56 -0700 (PDT) Received: from anup-ubuntu-vm.localdomain ([223.185.134.124]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7106ed2de28sm6455011b3a.191.2024.08.06.00.33.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Aug 2024 00:33:55 -0700 (PDT) From: Anup Patel To: Atish Patra Cc: Andrew Jones , Anup Patel , opensbi@lists.infradead.org, Rahul Pathak , Subrahmanya Lingappa , Anup Patel Subject: [PATCH 04/16] lib/utils: Add RPMI messaging protocol and shared memory transport support Date: Tue, 6 Aug 2024 13:03:26 +0530 Message-Id: <20240806073338.1856901-5-apatel@ventanamicro.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240806073338.1856901-1-apatel@ventanamicro.com> References: <20240806073338.1856901-1-apatel@ventanamicro.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240806_003357_692610_F9D0ED8A X-CRM114-Status: GOOD ( 18.66 ) 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: From: Rahul Pathak The RISC-V Platform Management Interface (RPMI) defines a messaging protocol and shared memory based transport for bi-directional communication with an on-chip or external microcontroller. 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:529 listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -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 From: Rahul Pathak The RISC-V Platform Management Interface (RPMI) defines a messaging protocol and shared memory based transport for bi-directional communication with an on-chip or external microcontroller. To support RPMI in OpenSBI, add: 1) The RPMI messaging protocol defines and helper macros 2) A FDT mailbox driver for the RPMI shared memory transport Signed-off-by: Rahul Pathak Co-developed-by: Subrahmanya Lingappa Signed-off-by: Subrahmanya Lingappa Co-developed-by: Anup Patel Signed-off-by: Anup Patel --- include/sbi_utils/mailbox/rpmi_mailbox.h | 32 + include/sbi_utils/mailbox/rpmi_msgprot.h | 186 ++++++ lib/utils/mailbox/Kconfig | 14 + lib/utils/mailbox/fdt_mailbox_rpmi_shmem.c | 671 +++++++++++++++++++++ lib/utils/mailbox/objects.mk | 5 + lib/utils/mailbox/rpmi_mailbox.c | 79 +++ platform/generic/configs/defconfig | 3 + 7 files changed, 990 insertions(+) create mode 100644 include/sbi_utils/mailbox/rpmi_mailbox.h create mode 100644 include/sbi_utils/mailbox/rpmi_msgprot.h create mode 100644 lib/utils/mailbox/fdt_mailbox_rpmi_shmem.c create mode 100644 lib/utils/mailbox/rpmi_mailbox.c diff --git a/include/sbi_utils/mailbox/rpmi_mailbox.h b/include/sbi_utils/mailbox/rpmi_mailbox.h new file mode 100644 index 00000000..61af51a8 --- /dev/null +++ b/include/sbi_utils/mailbox/rpmi_mailbox.h @@ -0,0 +1,32 @@ +/* + * SPDX-License-Identifier: BSD-2-Clause + * + * Copyright (c) 2023 Ventana Micro Systems Inc. + * + * Authors: + * Anup Patel + */ + +#ifndef __RPMI_MAILBOX_H__ +#define __RPMI_MAILBOX_H__ + +#include +#include + +#define rpmi_u32_count(__var) (sizeof(__var) / sizeof(u32)) + +/** Convert RPMI error to SBI error */ +int rpmi_xlate_error(enum rpmi_error error); + +/** Typical RPMI normal request with at least status code in response */ +int rpmi_normal_request_with_status( + struct mbox_chan *chan, u32 service_id, + void *req, u32 req_words, u32 req_endian_words, + void *resp, u32 resp_words, u32 resp_endian_words); + +/* RPMI posted request which is without any response*/ +int rpmi_posted_request( + struct mbox_chan *chan, u32 service_id, + void *req, u32 req_words, u32 req_endian_words); + +#endif /* !__RPMI_MAILBOX_H__ */ diff --git a/include/sbi_utils/mailbox/rpmi_msgprot.h b/include/sbi_utils/mailbox/rpmi_msgprot.h new file mode 100644 index 00000000..e0c7cba0 --- /dev/null +++ b/include/sbi_utils/mailbox/rpmi_msgprot.h @@ -0,0 +1,186 @@ +/* + * SPDX-License-Identifier: BSD-2-Clause + * + * Copyright (c) 2023 Ventana Micro Systems Inc. + * + * Authors: + * Rahul Pathak + */ + +#ifndef __RPMI_MSGPROT_H__ +#define __RPMI_MSGPROT_H__ + +#include +#include + +/* + * 31 0 + * +---------------------+-----------------------+ + * | FLAGS | SERVICE_ID | SERVICEGROUP_ID | + * +---------------------+-----------------------+ + * | TOKEN | DATA LENGTH | + * +---------------------+-----------------------+ + * | DATA/PAYLOAD | + * +---------------------------------------------+ + */ + +/** Message Header byte offset */ +#define RPMI_MSG_HDR_OFFSET (0x0) +/** Message Header Size in bytes */ +#define RPMI_MSG_HDR_SIZE (8) + +/** ServiceGroup ID field byte offset */ +#define RPMI_MSG_SERVICEGROUP_ID_OFFSET (0x0) +/** ServiceGroup ID field size in bytes */ +#define RPMI_MSG_SERVICEGROUP_ID_SIZE (2) + +/** Service ID field byte offset */ +#define RPMI_MSG_SERVICE_ID_OFFSET (0x2) +/** Service ID field size in bytes */ +#define RPMI_MSG_SERVICE_ID_SIZE (1) + +/** Flags field byte offset */ +#define RPMI_MSG_FLAGS_OFFSET (0x3) +/** Flags field size in bytes */ +#define RPMI_MSG_FLAGS_SIZE (1) + +#define RPMI_MSG_FLAGS_TYPE_POS (0U) +#define RPMI_MSG_FLAGS_TYPE_MASK 0x7 +#define RPMI_MSG_FLAGS_TYPE \ + ((0x7) << RPMI_MSG_FLAGS_TYPE_POS) + +#define RPMI_MSG_FLAGS_DOORBELL_POS (3U) +#define RPMI_MSG_FLAGS_DOORBELL_MASK 0x1 +#define RPMI_MSG_FLAGS_DOORBELL \ + ((0x1) << RPMI_MSG_FLAGS_DOORBELL_POS) + +/** Data length field byte offset */ +#define RPMI_MSG_DATALEN_OFFSET (0x4) +/** Data length field size in bytes */ +#define RPMI_MSG_DATALEN_SIZE (2) + +/** Token field byte offset */ +#define RPMI_MSG_TOKEN_OFFSET (0x6) +/** Token field size in bytes */ +#define RPMI_MSG_TOKEN_SIZE (2) +/** Token field mask */ +#define RPMI_MSG_TOKEN_MASK (0xffffU) + +/** Data field byte offset */ +#define RPMI_MSG_DATA_OFFSET (RPMI_MSG_HDR_SIZE) +/** Data field size in bytes */ +#define RPMI_MSG_DATA_SIZE(__slot_size) ((__slot_size) - RPMI_MSG_HDR_SIZE) + +/** Minimum slot size in bytes */ +#define RPMI_SLOT_SIZE_MIN (64) + +/** Name length of 16 characters */ +#define RPMI_NAME_CHARS_MAX (16) + +/** Queue layout */ +#define RPMI_QUEUE_HEAD_SLOT 0 +#define RPMI_QUEUE_TAIL_SLOT 1 +#define RPMI_QUEUE_HEADER_SLOTS 2 + +/** Default timeout values */ +#define RPMI_DEF_TX_TIMEOUT 20 +#define RPMI_DEF_RX_TIMEOUT 20 + +/** RPMI Message Header */ +struct rpmi_message_header { + le16_t servicegroup_id; + uint8_t service_id; + uint8_t flags; + le16_t datalen; + le16_t token; +} __packed; + +/** RPMI Message */ +struct rpmi_message { + struct rpmi_message_header header; + u8 data[0]; +} __packed; + +/** RPMI Messages Types */ +enum rpmi_message_type { + /* Normal request backed with ack */ + RPMI_MSG_NORMAL_REQUEST = 0x0, + /* Request without any ack */ + RPMI_MSG_POSTED_REQUEST = 0x1, + /* Acknowledgment for normal request message */ + RPMI_MSG_ACKNOWLDGEMENT = 0x2, + /* Notification message */ + RPMI_MSG_NOTIFICATION = 0x3, +}; + +/** RPMI Error Types */ +enum rpmi_error { + RPMI_SUCCESS = 0, + RPMI_ERR_FAILED = -1, + RPMI_ERR_NOTSUPP = -2, + RPMI_ERR_INVAL = -3, + RPMI_ERR_DENIED = -4, + RPMI_ERR_NOTFOUND = -5, + RPMI_ERR_OUTOFRANGE = -6, + RPMI_ERR_OUTOFRES = -7, + RPMI_ERR_HWFAULT = -8, +}; + +/** RPMI Message Arguments */ +struct rpmi_message_args { + u32 flags; +#define RPMI_MSG_FLAGS_NO_TX (1U << 0) +#define RPMI_MSG_FLAGS_NO_RX (1U << 1) +#define RPMI_MSG_FLAGS_NO_RX_TOKEN (1U << 2) + enum rpmi_message_type type; + u8 service_id; + u32 tx_endian_words; + u32 rx_endian_words; + u16 rx_token; + u32 rx_data_len; +}; + +/* + * RPMI SERVICEGROUPS AND SERVICES + */ + +/** RPMI ServiceGroups IDs */ +enum rpmi_servicegroup_id { + RPMI_SRVGRP_ID_MIN = 0, + RPMI_SRVGRP_BASE = 0x00001, + RPMI_SRVGRP_ID_MAX_COUNT, +}; + +/** RPMI enable notification request */ +struct rpmi_enable_notification_req { + u32 eventid; +}; + +/** RPMI enable notification response */ +struct rpmi_enable_notification_resp { + s32 status; +}; + +/** RPMI Base ServiceGroup Service IDs */ +enum rpmi_base_service_id { + RPMI_BASE_SRV_ENABLE_NOTIFICATION = 0x01, + RPMI_BASE_SRV_GET_IMPLEMENTATION_VERSION = 0x02, + RPMI_BASE_SRV_GET_IMPLEMENTATION_IDN = 0x03, + RPMI_BASE_SRV_GET_SPEC_VERSION = 0x04, + RPMI_BASE_SRV_GET_HW_INFO = 0x05, + RPMI_BASE_SRV_PROBE_SERVICE_GROUP = 0x06, + RPMI_BASE_SRV_GET_ATTRIBUTES = 0x07, + RPMI_BASE_SRV_SET_MSI = 0x08, +}; + +struct rpmi_base_get_attributes_resp { + s32 status_code; +#define RPMI_BASE_FLAGS_F0_EV_NOTIFY (1U << 31) +#define RPMI_BASE_FLAGS_F0_MSI_EN (1U << 30) + u32 f0; + u32 f1; + u32 f2; + u32 f3; +}; + +#endif /* !__RPMI_MSGPROT_H__ */ diff --git a/lib/utils/mailbox/Kconfig b/lib/utils/mailbox/Kconfig index 3957bfba..6e7f2cdd 100644 --- a/lib/utils/mailbox/Kconfig +++ b/lib/utils/mailbox/Kconfig @@ -8,8 +8,22 @@ config FDT_MAILBOX select MAILBOX default n +config RPMI_MAILBOX + bool "RPMI based mailbox drivers" + select MAILBOX + default n + config MAILBOX bool "Mailbox support" default n +if FDT_MAILBOX + +config FDT_MAILBOX_RPMI_SHMEM + bool "RPMI Shared Memory Mailbox Controller" + depends on RPMI_MAILBOX + default n + +endif + endmenu diff --git a/lib/utils/mailbox/fdt_mailbox_rpmi_shmem.c b/lib/utils/mailbox/fdt_mailbox_rpmi_shmem.c new file mode 100644 index 00000000..9705507c --- /dev/null +++ b/lib/utils/mailbox/fdt_mailbox_rpmi_shmem.c @@ -0,0 +1,671 @@ +/* + * SPDX-License-Identifier: BSD-2-Clause + * + * Copyright (c) 2024 Ventana Micro Systems Inc. + * + * Authors: + * Rahul Pathak + * Subrahmanya Lingappa + * Anup Patel + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/**************** RPMI Transport Structures and Macros ***********/ + +#define RPMI_MAILBOX_CHANNELS_MAX (16) + +#define GET_SERVICEGROUP_ID(msg) \ +({ \ + struct rpmi_message *mbuf = msg; \ + le16_to_cpu(mbuf->header.servicegroup_id);\ +}) + +#define GET_SERVICE_ID(msg) \ +({ \ + struct rpmi_message *mbuf = msg; \ + mbuf->header.service_id; \ +}) + +#define GET_FLAGS(msg) \ +({ \ + struct rpmi_message *mbuf = msg; \ + mbuf->header.flags; \ +}) + +#define GET_MESSAGE_ID(msg) \ +({ \ + struct rpmi_message *mbuf = msg; \ + ((u32)mbuf->header.flags << (RPMI_MSG_FLAGS_OFFSET * 8)) | \ + ((u32)mbuf->header.service_id << (RPMI_MSG_SERVICE_ID_OFFSET * 8)) | \ + ((u32)le16_to_cpu(mbuf->header.servicegroup_id)); \ +}) + +#define MAKE_MESSAGE_ID(__group_id, __service_id, __flags) \ +({ \ + u32 __ret = 0; \ + __ret |= (u32)(__group_id) << (RPMI_MSG_SERVICEGROUP_ID_OFFSET * 8); \ + __ret |= (u32)(__service_id) << (RPMI_MSG_SERVICE_ID_OFFSET * 8); \ + __ret |= (u32)(__flags) << (RPMI_MSG_FLAGS_OFFSET * 8); \ + __ret; \ +}) + +#define GET_DLEN(msg) \ +({ \ + struct rpmi_message *mbuf = msg; \ + le16_to_cpu(mbuf->header.datalen); \ +}) + +#define GET_TOKEN(msg) \ +({ \ + struct rpmi_message *mbuf = msg; \ + le16_to_cpu(mbuf->header.token); \ +}) + +#define GET_MESSAGE_TYPE(msg) \ +({ \ + uint8_t flags = *((uint8_t *)msg + RPMI_MSG_FLAGS_OFFSET); \ + ((flags & RPMI_MSG_FLAGS_TYPE) >> RPMI_MSG_FLAGS_TYPE_POS)); \ +}) + +enum rpmi_queue_type { + RPMI_QUEUE_TYPE_REQ = 0, + RPMI_QUEUE_TYPE_ACK = 1, +}; + +enum rpmi_queue_idx { + RPMI_QUEUE_IDX_A2P_REQ = 0, + RPMI_QUEUE_IDX_P2A_ACK = 1, + RPMI_QUEUE_IDX_P2A_REQ = 2, + RPMI_QUEUE_IDX_A2P_ACK = 3, + RPMI_QUEUE_IDX_MAX_COUNT, +}; + +enum rpmi_reg_idx { + RPMI_REG_IDX_DB_REG = 0, /* Doorbell register */ + RPMI_REG_IDX_MAX_COUNT, +}; + +/** Mailbox registers */ +struct rpmi_mb_regs { + /* doorbell from AP -> PuC*/ + volatile le32_t db_reg; +} __packed; + +/** Single Queue Context Structure */ +struct smq_queue_ctx { + u32 queue_id; + u32 num_slots; + spinlock_t queue_lock; + /* Type of queue - REQ or ACK */ + enum rpmi_queue_type queue_type; + /* Pointers to the queue shared memory */ + volatile le32_t *headptr; + volatile le32_t *tailptr; + volatile uint8_t *buffer; + /* Name of the queue */ + char name[RPMI_NAME_CHARS_MAX]; +}; + +struct rpmi_shmem_mbox_controller { + /* Driver specific members */ + u32 slot_size; + u32 queue_count; + struct rpmi_mb_regs *mb_regs; + struct smq_queue_ctx queue_ctx_tbl[RPMI_QUEUE_IDX_MAX_COUNT]; + /* Mailbox framework related members */ + struct mbox_controller controller; + struct mbox_chan channels[RPMI_MAILBOX_CHANNELS_MAX]; + struct mbox_chan *base_chan; + u32 impl_version; + u32 impl_id; + u32 spec_version; + struct { + bool f0_ev_notif_en; + bool f0_msi_en; + } base_flags; +}; + +/**************** Shared Memory Queues Helpers **************/ + +static bool __smq_queue_full(struct smq_queue_ctx *qctx) +{ + return ((le32_to_cpu(*qctx->tailptr) + 1) % qctx->num_slots == + le32_to_cpu(*qctx->headptr)) ? true : false; +} + +static bool __smq_queue_empty(struct smq_queue_ctx *qctx) +{ + return (le32_to_cpu(*qctx->headptr) == + le32_to_cpu(*qctx->tailptr)) ? true : false; +} + +static int __smq_rx(struct smq_queue_ctx *qctx, u32 slot_size, + u32 service_group_id, struct mbox_xfer *xfer) +{ + void *dst, *src; + struct rpmi_message *msg; + u32 i, tmp, pos, dlen, msgidn, headidx, tailidx; + struct rpmi_message_args *args = xfer->args; + bool no_rx_token = (args->flags & RPMI_MSG_FLAGS_NO_RX_TOKEN) ? + true : false; + + /* Rx sanity checks */ + if ((sizeof(u32) * args->rx_endian_words) > + (slot_size - sizeof(struct rpmi_message_header))) + return SBI_EINVAL; + if ((sizeof(u32) * args->rx_endian_words) > xfer->rx_len) + return SBI_EINVAL; + + /* There should be some message in the queue */ + if (__smq_queue_empty(qctx)) + return SBI_ENOENT; + + /* Get the head/read index and tail/write index */ + headidx = le32_to_cpu(*qctx->headptr); + tailidx = le32_to_cpu(*qctx->tailptr); + + /* + * Compute msgidn expected in the incoming message + * NOTE: DOORBELL bit is not expected to be set. + */ + msgidn = MAKE_MESSAGE_ID(service_group_id, args->service_id, args->type); + + /* Find the Rx message with matching token */ + pos = headidx; + while (pos != tailidx) { + src = (void *)qctx->buffer + (pos * slot_size); + if ((no_rx_token && GET_MESSAGE_ID(src) == msgidn) || + (GET_TOKEN(src) == (xfer->seq & RPMI_MSG_TOKEN_MASK))) + break; + pos = (pos + 1) % qctx->num_slots; + } + if (pos == tailidx) + return SBI_ENOENT; + + /* If Rx message is not first message then make it first message */ + if (pos != headidx) { + src = (void *)qctx->buffer + (pos * slot_size); + dst = (void *)qctx->buffer + (headidx * slot_size); + for (i = 0; i < slot_size / sizeof(u32); i++) { + tmp = ((u32 *)dst)[i]; + ((u32 *)dst)[i] = ((u32 *)src)[i]; + ((u32 *)src)[i] = tmp; + } + } + + /* Update rx_token if not available */ + msg = (void *)qctx->buffer + (headidx * slot_size); + if (no_rx_token) + args->rx_token = GET_TOKEN(msg); + + /* Extract data from the first message */ + if (xfer->rx) { + args->rx_data_len = dlen = GET_DLEN(msg); + if (dlen > xfer->rx_len) + dlen = xfer->rx_len; + src = (void *)msg + sizeof(struct rpmi_message_header); + dst = xfer->rx; + for (i = 0; i < args->rx_endian_words; i++) + ((u32 *)dst)[i] = le32_to_cpu(((u32 *)src)[i]); + dst += sizeof(u32) * args->rx_endian_words; + src += sizeof(u32) * args->rx_endian_words; + sbi_memcpy(dst, src, + xfer->rx_len - (sizeof(u32) * args->rx_endian_words)); + } + + /* Update the head/read index */ + *qctx->headptr = cpu_to_le32(headidx + 1) % qctx->num_slots; + smp_wmb(); + + return SBI_OK; +} + +static int __smq_tx(struct smq_queue_ctx *qctx, struct rpmi_mb_regs *mb_regs, + u32 slot_size, u32 service_group_id, struct mbox_xfer *xfer) +{ + u32 i, tailidx; + void *dst, *src; + struct rpmi_message_header header = { 0 }; + struct rpmi_message_args *args = xfer->args; + + /* Tx sanity checks */ + if ((sizeof(u32) * args->tx_endian_words) > + (slot_size - sizeof(struct rpmi_message_header))) + return SBI_EINVAL; + if ((sizeof(u32) * args->tx_endian_words) > xfer->tx_len) + return SBI_EINVAL; + + /* There should be some room in the queue */ + if (__smq_queue_full(qctx)) + return SBI_ENOMEM; + + /* Get the tail/write index */ + tailidx = le32_to_cpu(*qctx->tailptr); + + /* Prepare the header to be written into the slot */ + header.servicegroup_id = cpu_to_le16(service_group_id); + header.service_id = args->service_id; + header.flags = args->type; + header.datalen = cpu_to_le16((u16)xfer->tx_len); + header.token = cpu_to_le16((u16)xfer->seq); + + /* Write header into the slot */ + dst = (char *)qctx->buffer + (tailidx * slot_size); + sbi_memcpy(dst, &header, sizeof(header)); + dst += sizeof(header); + + /* Write data into the slot */ + if (xfer->tx) { + src = xfer->tx; + for (i = 0; i < args->tx_endian_words; i++) + ((u32 *)dst)[i] = cpu_to_le32(((u32 *)src)[i]); + dst += sizeof(u32) * args->tx_endian_words; + src += sizeof(u32) * args->tx_endian_words; + sbi_memcpy(dst, src, + xfer->tx_len - (sizeof(u32) * args->tx_endian_words)); + } + + /* Update the tail/write index */ + *qctx->tailptr = cpu_to_le32(tailidx + 1) % qctx->num_slots; + smp_wmb(); + + /* Ring the RPMI doorbell if present */ + if (mb_regs) + writel(cpu_to_le32(1), &mb_regs->db_reg); + + return SBI_OK; +} + +static int smq_rx(struct rpmi_shmem_mbox_controller *mctl, + u32 queue_id, u32 service_group_id, struct mbox_xfer *xfer) +{ + int ret, rxretry = 0; + struct smq_queue_ctx *qctx; + + if (mctl->queue_count < queue_id || + RPMI_MAILBOX_CHANNELS_MAX <= service_group_id) { + sbi_printf("%s: invalid queue_id or service_group_id\n", + __func__); + return SBI_EINVAL; + } + qctx = &mctl->queue_ctx_tbl[queue_id]; + + /* + * Once the timeout happens and call this function is returned + * to the client then there is no way to deliver the response + * message after that if it comes later. + * + * REVISIT: In complete timeout duration how much duration + * it should wait(delay) before recv retry. udelay or mdelay + */ + do { + spin_lock(&qctx->queue_lock); + ret = __smq_rx(qctx, mctl->slot_size, service_group_id, xfer); + spin_unlock(&qctx->queue_lock); + if (!ret) + return 0; + + sbi_timer_mdelay(1); + rxretry += 1; + } while (rxretry < xfer->rx_timeout); + + return SBI_ETIMEDOUT; +} + +static int smq_tx(struct rpmi_shmem_mbox_controller *mctl, + u32 queue_id, u32 service_group_id, struct mbox_xfer *xfer) +{ + int ret, txretry = 0; + struct smq_queue_ctx *qctx; + + if (mctl->queue_count < queue_id || + RPMI_MAILBOX_CHANNELS_MAX <= service_group_id) { + sbi_printf("%s: invalid queue_id or service_group_id\n", + __func__); + return SBI_EINVAL; + } + qctx = &mctl->queue_ctx_tbl[queue_id]; + + /* + * Ignoring the tx timeout since in RPMI has no mechanism + * with which other side can let know about the reception of + * message which marks as tx complete. For RPMI tx complete is + * marked as done when message in successfully copied in queue. + * + * REVISIT: In complete timeout duration how much duration + * it should wait(delay) before send retry. udelay or mdelay + */ + do { + spin_lock(&qctx->queue_lock); + ret = __smq_tx(qctx, mctl->mb_regs, mctl->slot_size, + service_group_id, xfer); + spin_unlock(&qctx->queue_lock); + if (!ret) + return 0; + + sbi_timer_mdelay(1); + txretry += 1; + } while (txretry < xfer->tx_timeout); + + return SBI_ETIMEDOUT; +} + +static int smq_base_get_two_u32(struct rpmi_shmem_mbox_controller *mctl, + u32 service_id, u32 *inarg, u32 *outvals) +{ + return rpmi_normal_request_with_status( + mctl->base_chan, service_id, + inarg, (inarg) ? 1 : 0, (inarg) ? 1 : 0, + outvals, 2, 2); +} + +/**************** Mailbox Controller Functions **************/ + +static int rpmi_shmem_mbox_xfer(struct mbox_chan *chan, struct mbox_xfer *xfer) +{ + int ret; + u32 tx_qid = 0, rx_qid = 0; + struct rpmi_shmem_mbox_controller *mctl = + container_of(chan->mbox, + struct rpmi_shmem_mbox_controller, + controller); + struct rpmi_message_args *args = xfer->args; + bool do_tx = (args->flags & RPMI_MSG_FLAGS_NO_TX) ? false : true; + bool do_rx = (args->flags & RPMI_MSG_FLAGS_NO_RX) ? false : true; + + if (!do_tx && !do_rx) + return SBI_EINVAL; + + switch (args->type) { + case RPMI_MSG_NORMAL_REQUEST: + if (do_tx && do_rx) { + tx_qid = RPMI_QUEUE_IDX_A2P_REQ; + rx_qid = RPMI_QUEUE_IDX_P2A_ACK; + } else if (do_tx) { + tx_qid = RPMI_QUEUE_IDX_A2P_REQ; + } else if (do_rx) { + rx_qid = RPMI_QUEUE_IDX_P2A_REQ; + } + break; + case RPMI_MSG_POSTED_REQUEST: + if (do_tx && do_rx) + return SBI_EINVAL; + if (do_tx) { + tx_qid = RPMI_QUEUE_IDX_A2P_REQ; + } else { + rx_qid = RPMI_QUEUE_IDX_P2A_REQ; + } + break; + case RPMI_MSG_ACKNOWLDGEMENT: + if (do_tx && do_rx) + return SBI_EINVAL; + if (do_tx) { + tx_qid = RPMI_QUEUE_IDX_A2P_ACK; + } else { + rx_qid = RPMI_QUEUE_IDX_P2A_ACK; + } + break; + default: + return SBI_ENOTSUPP; + } + + if (do_tx) { + ret = smq_tx(mctl, tx_qid, chan - mctl->channels, xfer); + if (ret) + return ret; + } + + if (do_rx) { + ret = smq_rx(mctl, rx_qid, chan - mctl->channels, xfer); + if (ret) + return ret; + } + + return 0; +} + +static struct mbox_chan *rpmi_shmem_mbox_request_chan( + struct mbox_controller *mbox, + u32 *chan_args) +{ + int ret; + u32 tval[2] = { 0 }; + struct rpmi_shmem_mbox_controller *mctl = + container_of(mbox, + struct rpmi_shmem_mbox_controller, + controller); + + if (chan_args[0] >= RPMI_MAILBOX_CHANNELS_MAX) + return NULL; + + /* Base serivce group is always present so probe other groups */ + if (chan_args[0] != RPMI_SRVGRP_BASE) { + /* Probe service group */ + ret = smq_base_get_two_u32(mctl, + RPMI_BASE_SRV_PROBE_SERVICE_GROUP, + chan_args, tval); + if (ret || !tval[1]) + return NULL; + } + + return &mctl->channels[chan_args[0]]; +} + +static void *rpmi_shmem_mbox_free_chan(struct mbox_controller *mbox, + struct mbox_chan *chan) +{ + /* Nothing to do here */ + return NULL; +} + +extern struct fdt_mailbox fdt_mailbox_rpmi_shmem; + +static int rpmi_shmem_transport_init(struct rpmi_shmem_mbox_controller *mctl, + void *fdt, int nodeoff) +{ + const char *name; + int count, len, ret, qid; + uint64_t reg_addr, reg_size; + const fdt32_t *prop_slotsz; + struct smq_queue_ctx *qctx; + + ret = fdt_node_check_compatible(fdt, nodeoff, + "riscv,rpmi-shmem-mbox"); + if (ret) + return ret; + + /* get queue slot size in bytes */ + prop_slotsz = fdt_getprop(fdt, nodeoff, "riscv,slot-size", &len); + if (!prop_slotsz) + return SBI_ENOENT; + + mctl->slot_size = fdt32_to_cpu(*prop_slotsz); + if (mctl->slot_size < RPMI_SLOT_SIZE_MIN) { + sbi_printf("%s: slot_size < mimnum required message size\n", + __func__); + mctl->slot_size = RPMI_SLOT_SIZE_MIN; + } + + /* + * queue names count is taken as the number of queues + * supported which make it mandatory to provide the + * name of the queue. + */ + count = fdt_stringlist_count(fdt, nodeoff, "reg-names"); + if (count < 0 || + count > (RPMI_QUEUE_IDX_MAX_COUNT + RPMI_REG_IDX_MAX_COUNT)) + return SBI_EINVAL; + + mctl->queue_count = count - RPMI_REG_IDX_MAX_COUNT; + + /* parse all queues and populate queues context structure */ + for (qid = 0; qid < mctl->queue_count; qid++) { + qctx = &mctl->queue_ctx_tbl[qid]; + + /* get each queue share-memory base address and size*/ + ret = fdt_get_node_addr_size(fdt, nodeoff, qid, + ®_addr, ®_size); + if (ret < 0 || !reg_addr || !reg_size) + return SBI_ENOENT; + + ret = sbi_domain_root_add_memrange(reg_addr, reg_size, reg_size, + (SBI_DOMAIN_MEMREGION_MMIO | + SBI_DOMAIN_MEMREGION_M_READABLE | + SBI_DOMAIN_MEMREGION_M_WRITABLE)); + if (ret) + return ret; + + /* calculate number of slots in each queue */ + qctx->num_slots = + (reg_size - (mctl->slot_size * RPMI_QUEUE_HEADER_SLOTS)) / mctl->slot_size; + + /* setup queue pointers */ + qctx->headptr = ((void *)(unsigned long)reg_addr) + + RPMI_QUEUE_HEAD_SLOT * mctl->slot_size; + qctx->tailptr = ((void *)(unsigned long)reg_addr) + + RPMI_QUEUE_TAIL_SLOT * mctl->slot_size; + qctx->buffer = ((void *)(unsigned long)reg_addr) + + RPMI_QUEUE_HEADER_SLOTS * mctl->slot_size; + + /* get the queue name */ + name = fdt_stringlist_get(fdt, nodeoff, "reg-names", + qid, &len); + if (!name || (name && len < 0)) + return len; + + sbi_memcpy(qctx->name, name, len); + + /* store the index as queue_id */ + qctx->queue_id = qid; + + SPIN_LOCK_INIT(qctx->queue_lock); + } + + /* get the db-reg property name */ + name = fdt_stringlist_get(fdt, nodeoff, "reg-names", qid, &len); + if (!name || (name && len < 0)) + return len; + + /* fetch doorbell register address*/ + ret = fdt_get_node_addr_size(fdt, nodeoff, qid, ®_addr, + ®_size); + if (!ret && !(strncmp(name, "db-reg", strlen("db-reg")))) { + mctl->mb_regs = (void *)(unsigned long)reg_addr; + ret = sbi_domain_root_add_memrange(reg_addr, reg_size, reg_size, + (SBI_DOMAIN_MEMREGION_MMIO | + SBI_DOMAIN_MEMREGION_M_READABLE | + SBI_DOMAIN_MEMREGION_M_WRITABLE)); + if (ret) + return ret; + } + + return SBI_SUCCESS; +} + +static int rpmi_shmem_mbox_init(void *fdt, int nodeoff, u32 phandle, + const struct fdt_match *match) +{ + int ret = 0; + u32 tval[2]; + struct rpmi_base_get_attributes_resp resp; + struct rpmi_shmem_mbox_controller *mctl; + + mctl = sbi_zalloc(sizeof(*mctl)); + if (!mctl) + return SBI_ENOMEM; + + /* Initialization transport from device tree */ + ret = rpmi_shmem_transport_init(mctl, fdt, nodeoff); + if (ret) + goto fail_free_controller; + + /* Register mailbox controller */ + mctl->controller.id = phandle; + mctl->controller.max_xfer_len = + mctl->slot_size - sizeof(struct rpmi_message_header); + mctl->controller.driver = &fdt_mailbox_rpmi_shmem; + mctl->controller.request_chan = rpmi_shmem_mbox_request_chan; + mctl->controller.free_chan = rpmi_shmem_mbox_free_chan; + mctl->controller.xfer = rpmi_shmem_mbox_xfer; + ret = mbox_controller_add(&mctl->controller); + if (ret) + goto fail_free_controller; + + /* Request base service group channel */ + tval[0] = RPMI_SRVGRP_BASE; + mctl->base_chan = mbox_controller_request_chan(&mctl->controller, + tval); + if (!mctl->base_chan) { + ret = SBI_ENOENT; + goto fail_remove_controller; + } + + /* Get implementation id */ + ret = smq_base_get_two_u32(mctl, + RPMI_BASE_SRV_GET_IMPLEMENTATION_VERSION, + NULL, tval); + if (ret) + goto fail_free_chan; + mctl->impl_version = tval[1]; + + /* Get implementation version */ + ret = smq_base_get_two_u32(mctl, RPMI_BASE_SRV_GET_IMPLEMENTATION_IDN, + NULL, tval); + if (ret) + goto fail_free_chan; + mctl->impl_id = tval[1]; + + /* Get specification version */ + ret = smq_base_get_two_u32(mctl, RPMI_BASE_SRV_GET_SPEC_VERSION, + NULL, tval); + if (ret) + goto fail_free_chan; + mctl->spec_version = tval[1]; + + /* Get optional features implementation flags */ + ret = rpmi_normal_request_with_status( + mctl->base_chan, RPMI_BASE_SRV_GET_ATTRIBUTES, + NULL, 0, 0, + &resp, rpmi_u32_count(resp), rpmi_u32_count(resp)); + if (ret) + goto fail_free_chan; + + mctl->base_flags.f0_ev_notif_en = + resp.f0 & RPMI_BASE_FLAGS_F0_EV_NOTIFY ? 1 : 0; + mctl->base_flags.f0_msi_en = + resp.f0 & RPMI_BASE_FLAGS_F0_MSI_EN ? 1 : 0; + + return 0; + +fail_free_chan: + mbox_controller_free_chan(mctl->base_chan); +fail_remove_controller: + mbox_controller_remove(&mctl->controller); +fail_free_controller: + sbi_free(mctl); + return ret; +} + +static const struct fdt_match rpmi_shmem_mbox_match[] = { + { .compatible = "riscv,rpmi-shmem-mbox" }, + { }, +}; + +struct fdt_mailbox fdt_mailbox_rpmi_shmem = { + .match_table = rpmi_shmem_mbox_match, + .init = rpmi_shmem_mbox_init, + .xlate = fdt_mailbox_simple_xlate, +}; diff --git a/lib/utils/mailbox/objects.mk b/lib/utils/mailbox/objects.mk index 2135898c..746b0313 100644 --- a/lib/utils/mailbox/objects.mk +++ b/lib/utils/mailbox/objects.mk @@ -11,3 +11,8 @@ libsbiutils-objs-$(CONFIG_FDT_MAILBOX) += mailbox/fdt_mailbox.o libsbiutils-objs-$(CONFIG_FDT_MAILBOX) += mailbox/fdt_mailbox_drivers.carray.o libsbiutils-objs-$(CONFIG_MAILBOX) += mailbox/mailbox.o + +libsbiutils-objs-$(CONFIG_RPMI_MAILBOX) += mailbox/rpmi_mailbox.o + +carray-fdt_mailbox_drivers-$(CONFIG_FDT_MAILBOX_RPMI_SHMEM) += fdt_mailbox_rpmi_shmem +libsbiutils-objs-$(CONFIG_FDT_MAILBOX_RPMI_SHMEM) += mailbox/fdt_mailbox_rpmi_shmem.o diff --git a/lib/utils/mailbox/rpmi_mailbox.c b/lib/utils/mailbox/rpmi_mailbox.c new file mode 100644 index 00000000..58c64e56 --- /dev/null +++ b/lib/utils/mailbox/rpmi_mailbox.c @@ -0,0 +1,79 @@ +/* + * SPDX-License-Identifier: BSD-2-Clause + * + * Copyright (c) 2023 Ventana Micro Systems Inc. + * + * Authors: + * Anup Patel + */ + +#include +#include +#include + +int rpmi_xlate_error(enum rpmi_error error) +{ + switch (error) { + case RPMI_SUCCESS: + return SBI_OK; + case RPMI_ERR_FAILED: + return SBI_EFAIL; + case RPMI_ERR_NOTSUPP: + return SBI_ENOTSUPP; + case RPMI_ERR_INVAL: + return SBI_EINVAL; + case RPMI_ERR_DENIED: + return SBI_EDENIED; + case RPMI_ERR_NOTFOUND: + return SBI_ENOENT; + case RPMI_ERR_OUTOFRANGE: + return SBI_EINVAL; + case RPMI_ERR_OUTOFRES: + return SBI_ENOSPC; + case RPMI_ERR_HWFAULT: + return SBI_EIO; + default: + return SBI_EUNKNOWN; + } +} + +int rpmi_normal_request_with_status( + struct mbox_chan *chan, u32 service_id, + void *req, u32 req_words, u32 req_endian_words, + void *resp, u32 resp_words, u32 resp_endian_words) +{ + int ret; + struct mbox_xfer xfer; + struct rpmi_message_args args = { 0 }; + + args.type = RPMI_MSG_NORMAL_REQUEST; + args.service_id = service_id; + args.tx_endian_words = req_endian_words; + args.rx_endian_words = resp_endian_words; + mbox_xfer_init_txrx(&xfer, &args, + req, sizeof(u32) * req_words, RPMI_DEF_TX_TIMEOUT, + resp, sizeof(u32) * resp_words, RPMI_DEF_RX_TIMEOUT); + + ret = mbox_chan_xfer(chan, &xfer); + if (ret) + return ret; + + return rpmi_xlate_error(((u32 *)resp)[0]); +} + +int rpmi_posted_request( + struct mbox_chan *chan, u32 service_id, + void *req, u32 req_words, u32 req_endian_words) +{ + struct mbox_xfer xfer; + struct rpmi_message_args args = { 0 }; + + args.type = RPMI_MSG_POSTED_REQUEST; + args.flags = RPMI_MSG_FLAGS_NO_RX; + args.service_id = service_id; + args.tx_endian_words = req_endian_words; + mbox_xfer_init_tx(&xfer, &args, + req, sizeof(u32) * req_words, RPMI_DEF_TX_TIMEOUT); + + return mbox_chan_xfer(chan, &xfer); +} diff --git a/platform/generic/configs/defconfig b/platform/generic/configs/defconfig index 079bc4fe..233a9a89 100644 --- a/platform/generic/configs/defconfig +++ b/platform/generic/configs/defconfig @@ -20,6 +20,9 @@ CONFIG_FDT_IRQCHIP=y CONFIG_FDT_IRQCHIP_APLIC=y CONFIG_FDT_IRQCHIP_IMSIC=y CONFIG_FDT_IRQCHIP_PLIC=y +CONFIG_FDT_MAILBOX=y +CONFIG_RPMI_MAILBOX=y +CONFIG_FDT_MAILBOX_RPMI_SHMEM=y CONFIG_FDT_REGMAP=y CONFIG_FDT_REGMAP_SYSCON=y CONFIG_FDT_RESET=y From patchwork Tue Aug 6 07:33:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 1969357 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=aEOoQ4z4; 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=FGJe9w5b; 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 4WdQ6W1D32z1yYD for ; Tue, 6 Aug 2024 17:34:11 +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=nEMOzM/BukE0HQxkgzt/Qhm7cFpe1oEU+sYhG8HWwQY=; b=aEOoQ4z4++TOZG VlOGVbLYhcIiwRnqZxL9cPnjwCjCEqNWoiI3gZLZ4NoWimspBdJFniXfKcCxOwBuPOooqOZCtNUEh hIWIQV98Z/FfDG1maO92Hlkef+mGXXzYg7NhRqAvDOvoHyaBdW73KIrZqMT/o9GypHSvHVlUgkGfJ 7/dfjqBcKNRe1HntU7cB/00d88uC92fhBUgpwRkRuvrQC/RbugbrbofxlSKGjkDXPCG3tOWT4VuRm orvfHDWFj3bF/j03O/PyoD5ZKGMudgANXRtC+g2x96mfh2EvB6gTa7PwjwJbQrapuLbU7e/QPF8lN JVBLLS6beTywzQki1iVQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sbEhn-00000000npB-1vAs; Tue, 06 Aug 2024 07:34:03 +0000 Received: from mail-oo1-xc2d.google.com ([2607:f8b0:4864:20::c2d]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sbEhk-00000000nn1-1YTI for opensbi@lists.infradead.org; Tue, 06 Aug 2024 07:34:01 +0000 Received: by mail-oo1-xc2d.google.com with SMTP id 006d021491bc7-5c661e75ff6so214324eaf.2 for ; Tue, 06 Aug 2024 00:34:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1722929639; x=1723534439; 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=mAOZNB634wJvAhtRH+jI/bXq8x6WhMchMOBaUttFjVM=; b=FGJe9w5b8dZ5elp4ZH0WwWYUrFyjXaEMZsY+PFFWzTh0M9Hdo7o0a6OsiWvHv2Kpx0 daKf0i0GSJ+Zx2aPF1H5bircwGKEKima9gLfXBbwrknKx4JhHVcH+uW73oUgT/ZmA6/t gbBY1ELw8LPBpZi5GTz38lJsR3dX3m/znDlXzqC4RhbX4P1tekXxOQ2IR0G0Mod17alw MBlDJHZzfgX94gf/oxUtueqcNoG/DgItD7bCr30muHeCcL0NzjbWd0/SxUFwSIZBbwk7 nbvIjTLyQbeRhg59oP9JAxhlyyq+5zRgDcep9zic77sqURe8fM83zoDqiO3D19iJdTFy 7Ljw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722929639; x=1723534439; 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=mAOZNB634wJvAhtRH+jI/bXq8x6WhMchMOBaUttFjVM=; b=PGb1oOg2oala9hJGbXW9nyxdzzoC1+hx7VE/GwpK41RH6Bv3ZsHemg8wwTTTcPLqxZ Z6cXiBrYLbYKmfuBuy5AqZOlM1ABVLEqEtoYkbseIfVs44foH2mNfAmjKFGxGVVoZxOS rk68tf3k5JJ9ttjXS4uasfYGSKBgp4zlB9lurTujOWndLowcbfL7c4YIovJBSrhlpvcP kbEUKhqCEO7EL1dywYntxLZKFabQSGZ64FGbctknLiC6KKHOLFlgMe/IyJ0W1ktM1KdQ Uql/RX/8p6sjSF+UFdFe1OEppg216XcLQWziJhwHXaGnlHRsX0E11HUQVYksRHP53dgN r0uw== X-Forwarded-Encrypted: i=1; AJvYcCX+68UpOWoFzP0K6mMMouERGqO8m/WxpttQc91MK5WP7km39FLH9wE0o91gF4Qb/HT9MqPX36QoJp3Li6JHMv3fWRCfuv/LvV/zt9E= X-Gm-Message-State: AOJu0Yx9+D+7YpIKPVa8Zk5nccP2WMN/jBcu8yYXATJ1WhM1c63sgj9Z WzHFx6W69EA1A6XH28hm+s4mkYsjuOEsl+GpxpWNPT8Wd1dfhbtzBJ3dDMk+1aI= X-Google-Smtp-Source: AGHT+IGKSiVYCPCEYGL49S7BehMx0SU7RFm7rw/4jxjE0BGwtEnC+MpMoAilqBzCZhD4w4UfmRwr2A== X-Received: by 2002:a05:6871:4d09:b0:268:9d81:24b7 with SMTP id 586e51a60fabf-2689d8161ddmr11219432fac.29.1722929639300; Tue, 06 Aug 2024 00:33:59 -0700 (PDT) Received: from anup-ubuntu-vm.localdomain ([223.185.134.124]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7106ed2de28sm6455011b3a.191.2024.08.06.00.33.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Aug 2024 00:33:58 -0700 (PDT) From: Anup Patel To: Atish Patra Cc: Andrew Jones , Anup Patel , opensbi@lists.infradead.org, Rahul Pathak , Anup Patel Subject: [PATCH 05/16] lib/utils: reset: Add RPMI System Reset driver Date: Tue, 6 Aug 2024 13:03:27 +0530 Message-Id: <20240806073338.1856901-6-apatel@ventanamicro.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240806073338.1856901-1-apatel@ventanamicro.com> References: <20240806073338.1856901-1-apatel@ventanamicro.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240806_003400_550355_CEF215A7 X-CRM114-Status: GOOD ( 19.36 ) 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: From: Rahul Pathak Add RPMI based driver for system reset and enable it in the generic platform defconfig Signed-off-by: Rahul Pathak Signed-off-by: Anup Patel --- include/sbi_utils/mailbox/rpmi_msgprot.h | 26 +++++ lib/utils/reset/Kconfig | 5 + lib/uti [...] 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:c2d listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -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 From: Rahul Pathak Add RPMI based driver for system reset and enable it in the generic platform defconfig Signed-off-by: Rahul Pathak Signed-off-by: Anup Patel --- include/sbi_utils/mailbox/rpmi_msgprot.h | 26 +++++ lib/utils/reset/Kconfig | 5 + lib/utils/reset/fdt_reset_rpmi.c | 141 +++++++++++++++++++++++ lib/utils/reset/objects.mk | 3 + platform/generic/configs/defconfig | 1 + 5 files changed, 176 insertions(+) create mode 100644 lib/utils/reset/fdt_reset_rpmi.c diff --git a/include/sbi_utils/mailbox/rpmi_msgprot.h b/include/sbi_utils/mailbox/rpmi_msgprot.h index e0c7cba0..4ede28dd 100644 --- a/include/sbi_utils/mailbox/rpmi_msgprot.h +++ b/include/sbi_utils/mailbox/rpmi_msgprot.h @@ -148,6 +148,7 @@ struct rpmi_message_args { enum rpmi_servicegroup_id { RPMI_SRVGRP_ID_MIN = 0, RPMI_SRVGRP_BASE = 0x00001, + RPMI_SRVGRP_SYSTEM_RESET = 0x00002, RPMI_SRVGRP_ID_MAX_COUNT, }; @@ -183,4 +184,29 @@ struct rpmi_base_get_attributes_resp { u32 f3; }; +/** RPMI System Reset ServiceGroup Service IDs */ +enum rpmi_system_reset_service_id { + RPMI_SYSRST_SRV_ENABLE_NOTIFICATION = 0x01, + RPMI_SYSRST_SRV_GET_SYSTEM_RESET_ATTRIBUTES = 0x02, + RPMI_SYSRST_SRV_SYSTEM_RESET = 0x03, + RPMI_SYSRST_SRV_ID_MAX_COUNT, +}; + +/** RPMI System Reset types */ +enum rpmi_sysrst_reset_type { + RPMI_SYSRST_SHUTDOWN = 0, + RPMI_SYSRST_COLD_RESET = 1, + RPMI_SYSRST_WARM_RESET = 2, + RPMI_SYSRST_MAX_IDN_COUNT, +}; + +/** Response for system reset attributes */ +struct rpmi_sysrst_get_reset_attributes_resp { + s32 status; +#define RPMI_SYSRST_FLAGS_SUPPORTED_POS (31) +#define RPMI_SYSRST_FLAGS_SUPPORTED_MASK \ + (1U << RPMI_SYSRST_FLAGS_SUPPORTED_POS) + u32 flags; +}; + #endif /* !__RPMI_MSGPROT_H__ */ diff --git a/lib/utils/reset/Kconfig b/lib/utils/reset/Kconfig index 6c077fe7..68e66716 100644 --- a/lib/utils/reset/Kconfig +++ b/lib/utils/reset/Kconfig @@ -24,6 +24,11 @@ config FDT_RESET_HTIF select SYS_HTIF default n +config FDT_RESET_RPMI + bool "RPMI FDT reset driver" + depends on FDT_MAILBOX && RPMI_MAILBOX + default n + config FDT_RESET_SG2042_HWMON_MCU bool "Sophgo SG2042 hwmon MCU FDT reset driver" default n diff --git a/lib/utils/reset/fdt_reset_rpmi.c b/lib/utils/reset/fdt_reset_rpmi.c new file mode 100644 index 00000000..3664a3c6 --- /dev/null +++ b/lib/utils/reset/fdt_reset_rpmi.c @@ -0,0 +1,141 @@ +/* + * SPDX-License-Identifier: BSD-2-Clause + * + * Copyright (c) 2024 Ventana Micro Systems Inc. + * + * Authors: + * Rahul Pathak + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +/* struct rpmi_sysreset: RPMI System Reset Context */ +struct rpmi_sysreset { + int warm_reset_support; + struct mbox_chan *chan; +}; + +static struct rpmi_sysreset sysreset_ctx; + +static int rpmi_system_reset_type_check(u32 reset_type) +{ + int ret; + struct rpmi_sysrst_get_reset_attributes_resp resp; + + ret = rpmi_normal_request_with_status(sysreset_ctx.chan, + RPMI_SYSRST_SRV_GET_SYSTEM_RESET_ATTRIBUTES, &reset_type, + rpmi_u32_count(reset_type), rpmi_u32_count(reset_type), + &resp, rpmi_u32_count(resp), rpmi_u32_count(resp)); + if (ret) { + return 0; + } + + return (resp.flags & RPMI_SYSRST_FLAGS_SUPPORTED_MASK) ? 1 : 0; +} + +/** + * rpmi_do_system_reset: Do system reset + * + * @reset_type: RPMI System Reset Type + */ +static void rpmi_do_system_reset(u32 reset_type) +{ + int ret; + + ret = rpmi_posted_request(sysreset_ctx.chan, + RPMI_SYSRST_SRV_SYSTEM_RESET, + &reset_type, rpmi_u32_count(reset_type), + rpmi_u32_count(reset_type)); + if (ret) + sbi_printf("system reset failed [type: %d]: ret: %d\n", + reset_type, ret); +} + +/** + * rpmi_system_reset_check: Check the support for + * various reset types + * + * @type: SBI System Reset Type + * @reason: Reason for system reset + */ +static int rpmi_system_reset_check(u32 type, u32 reason) +{ + switch (type) { + case SBI_SRST_RESET_TYPE_SHUTDOWN: + case SBI_SRST_RESET_TYPE_COLD_REBOOT: + return 1; + case SBI_SRST_RESET_TYPE_WARM_REBOOT: + return sysreset_ctx.warm_reset_support; + default: + return 0; + } +} + +static void rpmi_system_reset(u32 type, u32 reason) +{ + u32 reset_type; + + switch (type) { + case SBI_SRST_RESET_TYPE_SHUTDOWN: + reset_type = RPMI_SYSRST_SHUTDOWN; + break; + case SBI_SRST_RESET_TYPE_COLD_REBOOT: + reset_type = RPMI_SYSRST_COLD_RESET; + break; + case SBI_SRST_RESET_TYPE_WARM_REBOOT: + reset_type = RPMI_SYSRST_WARM_RESET; + break; + default: + return; + } + + rpmi_do_system_reset(reset_type); +} + +static struct sbi_system_reset_device rpmi_reset_dev = { + .name = "rpmi-system-reset", + .system_reset_check = rpmi_system_reset_check, + .system_reset = rpmi_system_reset, +}; + +static int rpmi_reset_init(void *fdt, int nodeoff, + const struct fdt_match *match) +{ + int ret; + + /* If channel already available then do nothing. */ + if (sysreset_ctx.chan) + return 0; + + /* + * If channel request failed then other end does not support + * system reset group so do nothing. + */ + ret = fdt_mailbox_request_chan(fdt, nodeoff, 0, &sysreset_ctx.chan); + if (ret) + return ret; + + sysreset_ctx.warm_reset_support = + rpmi_system_reset_type_check(RPMI_SYSRST_WARM_RESET); + + sbi_system_reset_add_device(&rpmi_reset_dev); + + return SBI_OK; +} + +static const struct fdt_match rpmi_reset_match[] = { + { .compatible = "riscv,rpmi-system-reset" }, + {}, +}; + +struct fdt_reset fdt_reset_rpmi = { + .match_table = rpmi_reset_match, + .init = rpmi_reset_init, +}; diff --git a/lib/utils/reset/objects.mk b/lib/utils/reset/objects.mk index a84336cf..8f3774c5 100644 --- a/lib/utils/reset/objects.mk +++ b/lib/utils/reset/objects.mk @@ -29,3 +29,6 @@ libsbiutils-objs-$(CONFIG_FDT_RESET_SUNXI_WDT) += reset/fdt_reset_sunxi_wdt.o carray-fdt_reset_drivers-$(CONFIG_FDT_RESET_SYSCON) += fdt_syscon_poweroff carray-fdt_reset_drivers-$(CONFIG_FDT_RESET_SYSCON) += fdt_syscon_reboot libsbiutils-objs-$(CONFIG_FDT_RESET_SYSCON) += reset/fdt_reset_syscon.o + +carray-fdt_reset_drivers-$(CONFIG_FDT_RESET_RPMI) += fdt_reset_rpmi +libsbiutils-objs-$(CONFIG_FDT_RESET_RPMI) += reset/fdt_reset_rpmi.o diff --git a/platform/generic/configs/defconfig b/platform/generic/configs/defconfig index 233a9a89..48f8df4c 100644 --- a/platform/generic/configs/defconfig +++ b/platform/generic/configs/defconfig @@ -29,6 +29,7 @@ CONFIG_FDT_RESET=y CONFIG_FDT_RESET_ATCWDT200=y CONFIG_FDT_RESET_GPIO=y CONFIG_FDT_RESET_HTIF=y +CONFIG_FDT_RESET_RPMI=y CONFIG_FDT_RESET_SUNXI_WDT=y CONFIG_FDT_RESET_SG2042_HWMON_MCU=y CONFIG_FDT_RESET_SYSCON=y From patchwork Tue Aug 6 07:33:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 1969359 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=PbVVpSX3; 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=gSZYznbz; 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 4WdQ6X6Xv4z1yYD for ; Tue, 6 Aug 2024 17:34:12 +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=SILTPtZ4A+rx0PnsLaxL5E05flAvL8exKcpNieDZKoA=; b=PbVVpSX3Lrsp2g wxTCD/hjLgW5NfePhLRqxerR0ay5aYdpW+Sp7Bgg/X10E9pMZW7hkGHoPIs4jgrt9fZZ3ItYyYnLs 1D4fK1y0UjmsGvEx9QbR7Gf6L0cfXrD0qEByzl7cS2U9B7pxlxs0vUE32uLbn6RAVqXbf6VpGliSX NsStZrJSXNTze9zAb27j9PjFnVnvuqNIvIuGZHT8594kkGIYjkHlYC/G3CgCDBnez/PVQn1U13HNc yoQ4KaIsewuRHD/v7iXQpXGoWOLMY2wAt5QnoJlOyRoEw0m3zHN7o16iMawmNpXVC/N/QlzMisggF ln1eEv2Vwp9uLBvc3IoA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sbEhq-00000000nr0-104h; Tue, 06 Aug 2024 07:34:06 +0000 Received: from mail-pf1-x429.google.com ([2607:f8b0:4864:20::429]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sbEhn-00000000noP-0Gtl for opensbi@lists.infradead.org; Tue, 06 Aug 2024 07:34:04 +0000 Received: by mail-pf1-x429.google.com with SMTP id d2e1a72fcca58-70d23caf8ddso286103b3a.0 for ; Tue, 06 Aug 2024 00:34:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1722929642; x=1723534442; 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=Y3wVTSfdXdZyvs1TV9WfK2ZsbQutQPeJTwgVEH0FCGY=; b=gSZYznbzIx1/IwIITSy+QBfaVd0g0VzBvf+en9+aFHy17yCX3UpydkwQAVcK+XlJ5W Fu/tageak7TH3cwPdMjc+8FlIdtUS8cp6ZKtZszbfewlC+9mVV/BatYNgxDxFQhwDvUK vmW9cz7H8VLiJYPWkgcgvFikG5VfVbaQDF2ugTErCgaw/7Gjc7vY06RbKp1iqUqs/asS 7l70eUOT3cX3SfzDO+eRa4v3ZITrACw/rzY9N7SzCVkOsZRDrJ2qLtLX3cWbmkhD6+ld 43ghwG4X13hkK/bzOQkiDNvYHOxu2NHr78C7gJaVXU5wQPG4cPomKUC1NeIWGiRGn22o EuDg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722929642; x=1723534442; 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=Y3wVTSfdXdZyvs1TV9WfK2ZsbQutQPeJTwgVEH0FCGY=; b=Hs2ix75BObDoEEeL8bqEijX4G906TKxX2gb5ey07YBkpSw6+h8x9AQwe8BshFlOfsA /NdGdDN/+OJWH+R6L6CWi7FmkQ52mtENpOuYnPoJYKkwercQ6mbXnAOH+LCSXkbnaPXo KtwRnP/dVZszLcTpsRmjhnp3B5CGVhHxWlPHpDxcK78rk/02FFbxfg3crbQ5TzOCgbIx MR62rznq0ZFSz8uijtX251B1TrklEQHHVvD2/+KXhOKMJjDqRXeJWnDlRdHuZxyXulxi HWdvyvgftMootKFFRIOFQjSE2KLf+RwaXkl9Wkf2zAuOA+IBX6ATlO6y1Y+glzlnYqPA ZrVw== X-Forwarded-Encrypted: i=1; AJvYcCU/7ywo76JIr5sLfcG+bgaNHrwzLT2rUVtnldiMh3JW0FFwsvphJC3RYWQkLMHK9g6kJJt8xDNKBfpwUy5Kif72Gi2kg/iQxwOlky4= X-Gm-Message-State: AOJu0Ywvux3vMa26jZirrGU3Lip4KzDObo+PKgK191LUgEzgqKJRrFXO wZCsCuVh3T2CvLMD+aJiMRBjGXwyW/vFYJ9Z9P+Rw/UDPpCsAEI7IzQFJnqyEhk= X-Google-Smtp-Source: AGHT+IFt0mvnEy7FYl0YzhWlRdLKeNnYbN5dqUzTx7j/vYajazqYJNqBiPZ01r3SYgPJImZK8+r0hA== X-Received: by 2002:a05:6a00:1790:b0:70d:21d9:e2ae with SMTP id d2e1a72fcca58-7106cf8ff18mr18029441b3a.6.1722929641855; Tue, 06 Aug 2024 00:34:01 -0700 (PDT) Received: from anup-ubuntu-vm.localdomain ([223.185.134.124]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7106ed2de28sm6455011b3a.191.2024.08.06.00.33.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Aug 2024 00:34:01 -0700 (PDT) From: Anup Patel To: Atish Patra Cc: Andrew Jones , Anup Patel , opensbi@lists.infradead.org, Anup Patel Subject: [PATCH 06/16] lib: utils: Add simple FDT based system suspend driver framework Date: Tue, 6 Aug 2024 13:03:28 +0530 Message-Id: <20240806073338.1856901-7-apatel@ventanamicro.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240806073338.1856901-1-apatel@ventanamicro.com> References: <20240806073338.1856901-1-apatel@ventanamicro.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240806_003403_149631_2A27FBB2 X-CRM114-Status: GOOD ( 19.41 ) 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: The generic platform can have multiple system suspend drivers so add a simple FDT based system suspend driver framework. Signed-off-by: Anup Patel --- include/sbi_utils/suspend/fdt_suspend.h | 45 +++++++++++++++++++ lib/utils/Kconfig | 2 + lib/utils/suspend/Kconfig | 10 +++++ lib/utils/suspend/ [...] 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:429 listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -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 The generic platform can have multiple system suspend drivers so add a simple FDT based system suspend driver framework. Signed-off-by: Anup Patel --- include/sbi_utils/suspend/fdt_suspend.h | 45 +++++++++++++++++++ lib/utils/Kconfig | 2 + lib/utils/suspend/Kconfig | 10 +++++ lib/utils/suspend/fdt_suspend.c | 46 ++++++++++++++++++++ lib/utils/suspend/fdt_suspend_drivers.carray | 3 ++ lib/utils/suspend/objects.mk | 11 +++++ platform/generic/configs/defconfig | 1 + platform/generic/platform.c | 2 + 8 files changed, 120 insertions(+) create mode 100644 include/sbi_utils/suspend/fdt_suspend.h create mode 100644 lib/utils/suspend/Kconfig create mode 100644 lib/utils/suspend/fdt_suspend.c create mode 100644 lib/utils/suspend/fdt_suspend_drivers.carray create mode 100644 lib/utils/suspend/objects.mk diff --git a/include/sbi_utils/suspend/fdt_suspend.h b/include/sbi_utils/suspend/fdt_suspend.h new file mode 100644 index 00000000..cb6fb719 --- /dev/null +++ b/include/sbi_utils/suspend/fdt_suspend.h @@ -0,0 +1,45 @@ +/* + * SPDX-License-Identifier: BSD-2-Clause + * + * Copyright (c) 2024 Ventana Micro Systems Inc. + * + * Authors: + * Anup Patel + */ + +#ifndef __FDT_SUSPEND_H__ +#define __FDT_SUSPEND_H__ + +#include + +struct fdt_suspend { + const struct fdt_match *match_table; + int (*init)(void *fdt, int nodeoff, const struct fdt_match *match); +}; + +#ifdef CONFIG_FDT_SUSPEND + +/** + * fdt_suspend_driver_init() - initialize suspend driver based on the device-tree + */ +int fdt_suspend_driver_init(void *fdt, struct fdt_suspend *drv); + +/** + * fdt_suspend_init() - initialize reset drivers based on the device-tree + * + * This function shall be invoked in final init. + */ +void fdt_suspend_init(void); + +#else + +static inline int fdt_suspend_driver_init(void *fdt, struct fdt_suspend *drv) +{ + return 0; +} + +static inline void fdt_suspend_init(void) { } + +#endif + +#endif diff --git a/lib/utils/Kconfig b/lib/utils/Kconfig index 6aa7843c..3f32c1ca 100644 --- a/lib/utils/Kconfig +++ b/lib/utils/Kconfig @@ -22,6 +22,8 @@ source "$(OPENSBI_SRC_DIR)/lib/utils/reset/Kconfig" source "$(OPENSBI_SRC_DIR)/lib/utils/serial/Kconfig" +source "$(OPENSBI_SRC_DIR)/lib/utils/suspend/Kconfig" + source "$(OPENSBI_SRC_DIR)/lib/utils/sys/Kconfig" source "$(OPENSBI_SRC_DIR)/lib/utils/timer/Kconfig" diff --git a/lib/utils/suspend/Kconfig b/lib/utils/suspend/Kconfig new file mode 100644 index 00000000..416ae795 --- /dev/null +++ b/lib/utils/suspend/Kconfig @@ -0,0 +1,10 @@ +# SPDX-License-Identifier: BSD-2-Clause + +menu "System Suspend Support" + +config FDT_SUSPEND + bool "FDT based suspend drivers" + depends on FDT + default n + +endmenu diff --git a/lib/utils/suspend/fdt_suspend.c b/lib/utils/suspend/fdt_suspend.c new file mode 100644 index 00000000..029d6476 --- /dev/null +++ b/lib/utils/suspend/fdt_suspend.c @@ -0,0 +1,46 @@ +/* + * SPDX-License-Identifier: BSD-2-Clause + * + * Copyright (c) 2024 Ventana Micro Systems Inc. + * + * Authors: + * Anup Patel + */ + +#include +#include +#include +#include + +/* List of FDT suspend drivers generated at compile time */ +extern struct fdt_suspend *fdt_suspend_drivers[]; +extern unsigned long fdt_suspend_drivers_size; + +int fdt_suspend_driver_init(void *fdt, struct fdt_suspend *drv) +{ + int noff, rc = SBI_ENODEV; + const struct fdt_match *match; + + noff = fdt_find_match(fdt, -1, drv->match_table, &match); + if (noff < 0) + return SBI_ENODEV; + + if (drv->init) { + rc = drv->init(fdt, noff, match); + if (rc && rc != SBI_ENODEV) { + sbi_printf("%s: %s init failed, %d\n", + __func__, match->compatible, rc); + } + } + + return rc; +} + +void fdt_suspend_init(void) +{ + int pos; + void *fdt = fdt_get_address(); + + for (pos = 0; pos < fdt_suspend_drivers_size; pos++) + fdt_suspend_driver_init(fdt, fdt_suspend_drivers[pos]); +} diff --git a/lib/utils/suspend/fdt_suspend_drivers.carray b/lib/utils/suspend/fdt_suspend_drivers.carray new file mode 100644 index 00000000..8793e4cf --- /dev/null +++ b/lib/utils/suspend/fdt_suspend_drivers.carray @@ -0,0 +1,3 @@ +HEADER: sbi_utils/suspend/fdt_suspend.h +TYPE: struct fdt_suspend +NAME: fdt_suspend_drivers diff --git a/lib/utils/suspend/objects.mk b/lib/utils/suspend/objects.mk new file mode 100644 index 00000000..30d897d1 --- /dev/null +++ b/lib/utils/suspend/objects.mk @@ -0,0 +1,11 @@ +# +# SPDX-License-Identifier: BSD-2-Clause +# +# Copyright (c) 2024 Ventana Micro Systems Inc. +# +# Authors: +# Anup Patel +# + +libsbiutils-objs-$(CONFIG_FDT_SUSPEND) += suspend/fdt_suspend.o +libsbiutils-objs-$(CONFIG_FDT_SUSPEND) += suspend/fdt_suspend_drivers.carray.o diff --git a/platform/generic/configs/defconfig b/platform/generic/configs/defconfig index 48f8df4c..ec439d74 100644 --- a/platform/generic/configs/defconfig +++ b/platform/generic/configs/defconfig @@ -44,6 +44,7 @@ CONFIG_FDT_SERIAL_LITEX=y CONFIG_FDT_SERIAL_UART8250=y CONFIG_FDT_SERIAL_XILINX_UARTLITE=y CONFIG_SERIAL_SEMIHOSTING=y +CONFIG_FDT_SUSPEND=y CONFIG_FDT_TIMER=y CONFIG_FDT_TIMER_MTIMER=y CONFIG_FDT_TIMER_PLMT=y diff --git a/platform/generic/platform.c b/platform/generic/platform.c index 3470474a..138a54c2 100644 --- a/platform/generic/platform.c +++ b/platform/generic/platform.c @@ -24,6 +24,7 @@ #include #include #include +#include #include #include #include @@ -225,6 +226,7 @@ static int generic_early_init(bool cold_boot) if (cold_boot) { fdt_reset_init(); + fdt_suspend_init(); if (semihosting_enabled()) rc = semihosting_init(); From patchwork Tue Aug 6 07:33:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 1969360 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=fh4Ymn0W; 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=jvOcz/5o; 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 4WdQ6b6BRPz1yYD for ; Tue, 6 Aug 2024 17:34:15 +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=kXpApPyLDZp3kSbIPFlA/daGZzmY/wkpZtjAiX/1pWI=; b=fh4Ymn0WA9aTEf eRe6yVZ6+GfFbEGo9BQPwBMBOpcJ7F6T8BUAXLeYINWV615ePiYSRwhkzRPs5Pv7xVkz16Q0JOdCJ 3Vg1LA5K628trKgKhCEuc9MYvlOnC10sTW73fECagpVpfSIka82SfwKZ5LYXd2LeztXamq7v1eJrL CXSSZeiSEWgT0+OYGD+UvoMSFgEeKb4WUQjrfkG2cfkx8sVA2FT/sBIO5HQ2nXNoKmjcNGIVCv2Ff vBA/nooe/McnKVKSeUisZky06FOwHPD4p3QzU09CKTJIoZZIwEpBLqy0KfTGMqwOzq0qXVuha+uFH 11xP4E/FrBR60C92SOgQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sbEht-00000000ntg-172i; Tue, 06 Aug 2024 07:34:09 +0000 Received: from mail-oi1-x236.google.com ([2607:f8b0:4864:20::236]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sbEhq-00000000nqV-1ehn for opensbi@lists.infradead.org; Tue, 06 Aug 2024 07:34:08 +0000 Received: by mail-oi1-x236.google.com with SMTP id 5614622812f47-3db50abf929so211464b6e.2 for ; Tue, 06 Aug 2024 00:34:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1722929645; x=1723534445; 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=F/fpWWtIO2vCJqymUn40LfuZlWWhkECO7uabcVsoxdY=; b=jvOcz/5oO2YpuN/hS6y4xwpZDtQct7bKxSmPO803Ce1NGRYyX99JVeXJiVrM7I5fmd nYhKfeQxyOSvpDYLt7/df131Q4Q1sKhti/BFkNO2oYc8sZA4Ne799cqNXxg/pyp29zEM 9RtMkiPehx1ZOdrDlsc1R0hcBvVljZ6Y8+p/stsNdZ33ah1ix2rjNZSq0LL5j6H0yMKs JSu99/7poMyVSYKIx9QWCfLYGKIvWfMXyTDPJBV59gT/nlgmPbhpn9oNcybWZhKBIKEl QqYCEYAag29ma6GB4s2AKbD8e5TCxhjBl4/OIZKkyZJhM1x0uRbMiqZZqsTV6b6MFM8P X2aQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722929645; x=1723534445; 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=F/fpWWtIO2vCJqymUn40LfuZlWWhkECO7uabcVsoxdY=; b=Lb/3nz7Ulj+QkasjotwDbEq2E6gN70gODpRA6/6pOeBI/j+ZPApzkghRdLF3QcwwaH HgJAwhWB3r9dEuq0FqeshIe+X8OO/7LoekhbfEeftEoa2UB9qbSj8OXWIAo3raYCejGY K6esRCVBMcoJZYSUHDwS6GzW7pzaGhrOl5OCvtLmAnU3Axj1aiAXpaISO0/Q3QzKiHiT BKzJHhYPqKFMWGB/4SfDJRd8qgd9o6lnP24tQoRO7fiFps18cnEgv6J9nPZBZ//Uk07T wOVf7SWmWLwT2TLXncvob++bNQiZ+NlDlVn/JIx2Ic4/HtIhwEN1Ede3lp+9jr4VVF3z 457A== X-Forwarded-Encrypted: i=1; AJvYcCUGcvQuTPtBgEAfJ6l7PVz71XJUrVMYQeqISkpnT8MiVNq0Adio6KHle/YTdy/44rUr8yxkHgaoO3sEPJqpBB1E/VqUhA5F+KA9CN4= X-Gm-Message-State: AOJu0YyFrRohu055TH4hXqWVySMHsM8ElGRhN+L5Sp+6dcbuCarY+nd4 7Wmn58bmKPM4HAH/IwVlwUGzhhTBlOdqplGhOyCTXOuZz0rIODD32W/L7Gaoo7U= X-Google-Smtp-Source: AGHT+IHawp0DW1JjSF5+ql4dMRdI86NyB0kUzhexZRvPUBJ3xTeingOzWTPyVJEHI9khwjOLFu67ug== X-Received: by 2002:a05:6808:1710:b0:3d9:1f05:845 with SMTP id 5614622812f47-3db5580a5c5mr18850156b6e.19.1722929644813; Tue, 06 Aug 2024 00:34:04 -0700 (PDT) Received: from anup-ubuntu-vm.localdomain ([223.185.134.124]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7106ed2de28sm6455011b3a.191.2024.08.06.00.34.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Aug 2024 00:34:04 -0700 (PDT) From: Anup Patel To: Atish Patra Cc: Andrew Jones , Anup Patel , opensbi@lists.infradead.org, Subrahmanya Lingappa , Anup Patel Subject: [PATCH 07/16] lib: utils/suspend: Add RPMI system suspend driver Date: Tue, 6 Aug 2024 13:03:29 +0530 Message-Id: <20240806073338.1856901-8-apatel@ventanamicro.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240806073338.1856901-1-apatel@ventanamicro.com> References: <20240806073338.1856901-1-apatel@ventanamicro.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240806_003406_644760_C8581186 X-CRM114-Status: GOOD ( 17.86 ) 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: From: Subrahmanya Lingappa Add RPMI based system suspend driver. To test this, execute the follwoing in Linux: $ echo mem > /sys/power/state 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:236 listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -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 From: Subrahmanya Lingappa Add RPMI based system suspend driver. To test this, execute the follwoing in Linux: $ echo mem > /sys/power/state To wake up, execute the following command on qemu monitor terminal: (qemu) system_wakeup Signed-off-by: Subrahmanya Lingappa Signed-off-by: Anup Patel --- include/sbi_utils/mailbox/rpmi_msgprot.h | 34 ++++++ lib/utils/suspend/Kconfig | 9 ++ lib/utils/suspend/fdt_suspend_rpmi.c | 137 +++++++++++++++++++++++ lib/utils/suspend/objects.mk | 3 + platform/generic/configs/defconfig | 1 + 5 files changed, 184 insertions(+) create mode 100644 lib/utils/suspend/fdt_suspend_rpmi.c diff --git a/include/sbi_utils/mailbox/rpmi_msgprot.h b/include/sbi_utils/mailbox/rpmi_msgprot.h index 4ede28dd..a2403c90 100644 --- a/include/sbi_utils/mailbox/rpmi_msgprot.h +++ b/include/sbi_utils/mailbox/rpmi_msgprot.h @@ -5,6 +5,7 @@ * * Authors: * Rahul Pathak + * Subrahmanya Lingappa */ #ifndef __RPMI_MSGPROT_H__ @@ -149,6 +150,7 @@ enum rpmi_servicegroup_id { RPMI_SRVGRP_ID_MIN = 0, RPMI_SRVGRP_BASE = 0x00001, RPMI_SRVGRP_SYSTEM_RESET = 0x00002, + RPMI_SRVGRP_SYSTEM_SUSPEND = 0x00003, RPMI_SRVGRP_ID_MAX_COUNT, }; @@ -209,4 +211,36 @@ struct rpmi_sysrst_get_reset_attributes_resp { u32 flags; }; +/** RPMI System Suspend ServiceGroup Service IDs */ +enum rpmi_system_suspend_service_id { + RPMI_SYSSUSP_SRV_ENABLE_NOTIFICATION = 0x01, + RPMI_SYSSUSP_SRV_GET_SYSTEM_SUSPEND_ATTRIBUTES = 0x02, + RPMI_SYSSUSP_SRV_SYSTEM_SUSPEND = 0x03, + RPMI_SYSSUSP_SRV_ID_MAX_COUNT, +}; + +/** Request for system suspend attributes */ +struct rpmi_syssusp_get_attr_req { + u32 susp_type; +}; + +/** Response for system suspend attributes */ +struct rpmi_syssusp_get_attr_resp { + s32 status; +#define RPMI_SYSSUSP_FLAGS_CUSTOM_RESUME_ADDR_SUPPORTED (1U << 31) +#define RPMI_SYSSUSP_FLAGS_SUPPORTED (1U << 30) + u32 flags; +}; + +struct rpmi_syssusp_suspend_req { + u32 hartid; + u32 suspend_type; + u32 resume_addr_lo; + u32 resume_addr_hi; +}; + +struct rpmi_syssusp_suspend_resp { + s32 status; +}; + #endif /* !__RPMI_MSGPROT_H__ */ diff --git a/lib/utils/suspend/Kconfig b/lib/utils/suspend/Kconfig index 416ae795..2cbea75c 100644 --- a/lib/utils/suspend/Kconfig +++ b/lib/utils/suspend/Kconfig @@ -7,4 +7,13 @@ config FDT_SUSPEND depends on FDT default n +if FDT_SUSPEND + +config FDT_SUSPEND_RPMI + bool "FDT RPMI suspend driver" + depends on FDT_MAILBOX && RPMI_MAILBOX + default n + +endif + endmenu diff --git a/lib/utils/suspend/fdt_suspend_rpmi.c b/lib/utils/suspend/fdt_suspend_rpmi.c new file mode 100644 index 00000000..aa5db128 --- /dev/null +++ b/lib/utils/suspend/fdt_suspend_rpmi.c @@ -0,0 +1,137 @@ +/* + * SPDX-License-Identifier: BSD-2-Clause + * + * Copyright (c) 2024 Ventana Micro Systems Inc. + * + * Authors: + * Subrahmanya Lingappa + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +struct rpmi_syssusp { + struct mbox_chan *chan; + bool cust_res_addr_supported; + bool suspend_supported; +}; + +static struct rpmi_syssusp syssusp_ctx; + +static int rpmi_syssusp_attrs(uint32_t *attrs) +{ + int rc; + struct rpmi_syssusp_get_attr_resp resp; + struct rpmi_syssusp_get_attr_req req; + + req.susp_type = SBI_SUSP_SLEEP_TYPE_SUSPEND; + + rc = rpmi_normal_request_with_status( + syssusp_ctx.chan, RPMI_SYSSUSP_SRV_GET_SYSTEM_SUSPEND_ATTRIBUTES, + &req, rpmi_u32_count(req), rpmi_u32_count(req), + &resp, rpmi_u32_count(resp), rpmi_u32_count(resp)); + if (rc) + return rc; + + *attrs = resp.flags; + + return 0; +} + +static int rpmi_syssusp(uint32_t suspend_type, ulong resume_addr) +{ + int rc; + struct rpmi_syssusp_suspend_req req; + struct rpmi_syssusp_suspend_resp resp; + + req.hartid = current_hartid(); + req.suspend_type = suspend_type; + req.resume_addr_lo = resume_addr; + req.resume_addr_hi = (u64)resume_addr >> 32; + + rc = rpmi_normal_request_with_status( + syssusp_ctx.chan, RPMI_SYSSUSP_SRV_SYSTEM_SUSPEND, + &req, rpmi_u32_count(req), rpmi_u32_count(req), + &resp, rpmi_u32_count(resp), rpmi_u32_count(resp)); + if (rc) + return rc; + + /* Wait for interrupt */ + wfi(); + + return 0; +} + +static int rpmi_system_suspend_check(u32 sleep_type) +{ + return ((sleep_type == SBI_SUSP_SLEEP_TYPE_SUSPEND) && + syssusp_ctx.suspend_supported) ? 0 : SBI_EINVAL; +} + +static int rpmi_system_suspend(u32 sleep_type, ulong resume_addr) +{ + int rc; + + if (sleep_type != SBI_SUSP_SLEEP_TYPE_SUSPEND) + return SBI_ENOTSUPP; + + rc = rpmi_syssusp(sleep_type, resume_addr); + if (rc) + return rc; + + return 0; +} + +static struct sbi_system_suspend_device rpmi_suspend_dev = { + .name = "rpmi-system-suspend", + .system_suspend_check = rpmi_system_suspend_check, + .system_suspend = rpmi_system_suspend, +}; + +static int rpmi_suspend_init(void *fdt, int nodeoff, + const struct fdt_match *match) +{ + int rc; + uint32_t attrs = 0; + + /* If channel already available then do nothing. */ + if (syssusp_ctx.chan) + return 0; + + /* + * If channel request failed then other end does not support + * suspend service group so do nothing. + */ + rc = fdt_mailbox_request_chan(fdt, nodeoff, 0, &syssusp_ctx.chan); + if (rc) + return 0; + + /* Get suspend attributes */ + rc = rpmi_syssusp_attrs(&attrs); + if (rc) + return rc; + + syssusp_ctx.suspend_supported = attrs & RPMI_SYSSUSP_FLAGS_SUPPORTED; + syssusp_ctx.cust_res_addr_supported = + attrs & RPMI_SYSSUSP_FLAGS_CUSTOM_RESUME_ADDR_SUPPORTED; + + sbi_system_suspend_set_device(&rpmi_suspend_dev); + + return 0; +} + +static const struct fdt_match rpmi_suspend_match[] = { + { .compatible = "riscv,rpmi-system-suspend" }, + {}, +}; + +struct fdt_suspend fdt_suspend_rpmi = { + .match_table = rpmi_suspend_match, + .init = rpmi_suspend_init, +}; diff --git a/lib/utils/suspend/objects.mk b/lib/utils/suspend/objects.mk index 30d897d1..657670a8 100644 --- a/lib/utils/suspend/objects.mk +++ b/lib/utils/suspend/objects.mk @@ -9,3 +9,6 @@ libsbiutils-objs-$(CONFIG_FDT_SUSPEND) += suspend/fdt_suspend.o libsbiutils-objs-$(CONFIG_FDT_SUSPEND) += suspend/fdt_suspend_drivers.carray.o + +carray-fdt_suspend_drivers-$(CONFIG_FDT_SUSPEND_RPMI) += fdt_suspend_rpmi +libsbiutils-objs-$(CONFIG_FDT_SUSPEND_RPMI) += suspend/fdt_suspend_rpmi.o diff --git a/platform/generic/configs/defconfig b/platform/generic/configs/defconfig index ec439d74..54300fb5 100644 --- a/platform/generic/configs/defconfig +++ b/platform/generic/configs/defconfig @@ -45,6 +45,7 @@ CONFIG_FDT_SERIAL_UART8250=y CONFIG_FDT_SERIAL_XILINX_UARTLITE=y CONFIG_SERIAL_SEMIHOSTING=y CONFIG_FDT_SUSPEND=y +CONFIG_FDT_SUSPEND_RPMI=y CONFIG_FDT_TIMER=y CONFIG_FDT_TIMER_MTIMER=y CONFIG_FDT_TIMER_PLMT=y From patchwork Tue Aug 6 07:33:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 1969361 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=zA6JIfoL; 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=AJivsP9Y; 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 4WdQ6f3dBxz1yYD for ; Tue, 6 Aug 2024 17:34:18 +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=VcY3kQp/pbcRegmT98gqD9e9l8M4gpaUNviyhJz0fIg=; b=zA6JIfoLCUXF8C VbWLHpVWHrJBKIGouE6vzOGVBDYpEyAvuhVQx+/pHLfXJtCPORc9qd9RllVma6ey06fDiveoNAZxG QRBUmZ4puxguifVZbdUbELex5mQC0xLxtMoz7y5C0cqoo7Xo6qRU4nhi3lU6U519KAGt6vhMgiTU3 p3CL3IQ5vxSSBmuds+LjPHHHzS1v6I7yiW8XQA830MdI7VEUtE2gruVfQ+vyDxT5evKKt42yj62o0 L2ZilxqjyW0FHPaIIKKlbiYNRLiEUGJtR+HnsUBn2KnoDYRz89h33gAPHUyXlwzHVHCQQj4DdIAtN 09Z0kE0Pd6+BGzG9wWQw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sbEhv-00000000nv5-1MCG; Tue, 06 Aug 2024 07:34:11 +0000 Received: from mail-pf1-x429.google.com ([2607:f8b0:4864:20::429]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sbEhs-00000000nsx-1ii0 for opensbi@lists.infradead.org; Tue, 06 Aug 2024 07:34:09 +0000 Received: by mail-pf1-x429.google.com with SMTP id d2e1a72fcca58-70d316f0060so4238633b3a.1 for ; Tue, 06 Aug 2024 00:34:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1722929648; x=1723534448; 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=9gsver5Q1fQKX5swvbK9rHFRA0LyT84jvHfArdMVnNM=; b=AJivsP9YS5veB4tDk1qAsy+OwL56XzXGqUsWcCFB5rGAmObKxyyMbNPj45cBmWvBRh 86xOEYn81Qi9cjMpGPoj7nZNFiu77KI6Jq3TfzFWQK/S0Gq3i83dcOpoXdV2At9EkV19 VDs9bp8l4SJWcFRolr4MkY5Az+xpVoxIOcVrMf3tY0CHwBgqMoiR144DSOcx9iKgxbyU fHEjgf+o44w31JbDNeHMsB+YvapIbNOFyeTZh5Zwtlk9fetyCsO+NTjIcjW9Rya6eFGG Sv9opRgRB6LmZZPjy9MSB+dIEp903hRBTXRvlZ/lpcbMhu2+/W0hgKzel/+5iKUOvXoq uvJA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722929648; x=1723534448; 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=9gsver5Q1fQKX5swvbK9rHFRA0LyT84jvHfArdMVnNM=; b=af9IAT0SLgVLYXTC0SV8awVNwE5yvVjPR/JQnYtu8KFf1sBPttqS6otCCBJQcWVTrE PmwPMNVsehZPXBytnea0uV9PlDDD12wtiIXZ1u2BW6fU56//CcLWB5K3hKVmFe3j4KoU QL9IeAEE9jGzJSZ2jBSxL7CK1gF/T1It9+sogY6ywEyp6d120Vpr58cIljxFTAqq9KZV mw+aT0XAxkOjj/c+cV9YvRQVHSQ7dEYLKnwUJS9cprzqqaTiNzwJN6eAZAAqIAGUrZ/v 6LcF0Q8YdKr2mcCRyg3dUG7FRRkjN/mJ+pm1HPsSDp0HWNPTnQNixOg/HKJkNkgbpPdg WpjA== X-Forwarded-Encrypted: i=1; AJvYcCWEy/TMsoP9hsRlTd3y81T7ShbpT3MWzlQoXlhYmkN8uFUZNuuhd6fj9ajfWY5qmy4zF0QksmeOz6Jjp/ylKGbJQXT2VB7wqZtcl3I= X-Gm-Message-State: AOJu0Yy4si1GjuKHN2jofmEQh9XiFY2clF0iJL+kqX9dXAp6/VUPpKcV Jfk0E8yu99nnU4tt1/lrLcr4gttP2q8e3Vp1OW7R06ah46fHWrY0aJ2nTIF/+v0= X-Google-Smtp-Source: AGHT+IHhRBeEC1YH1LJpti8ZI+bkbUZTY+xDQhPxR1tSxbcssPP0elCuPmf51emznwaFkaDyZR9KEA== X-Received: by 2002:a05:6a20:a10c:b0:1c4:779b:fb02 with SMTP id adf61e73a8af0-1c69a69879amr23710540637.21.1722929647493; Tue, 06 Aug 2024 00:34:07 -0700 (PDT) Received: from anup-ubuntu-vm.localdomain ([223.185.134.124]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7106ed2de28sm6455011b3a.191.2024.08.06.00.34.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Aug 2024 00:34:07 -0700 (PDT) From: Anup Patel To: Atish Patra Cc: Andrew Jones , Anup Patel , opensbi@lists.infradead.org, Anup Patel Subject: [PATCH 08/16] lib: utils: Add simple FDT based HSM driver framework Date: Tue, 6 Aug 2024 13:03:30 +0530 Message-Id: <20240806073338.1856901-9-apatel@ventanamicro.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240806073338.1856901-1-apatel@ventanamicro.com> References: <20240806073338.1856901-1-apatel@ventanamicro.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240806_003408_506322_4B7DD0D2 X-CRM114-Status: GOOD ( 21.24 ) 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: The generic platform can have multiple HSM drivers so add a simple FDT based HSM driver framework. Signed-off-by: Anup Patel --- include/sbi_utils/hsm/fdt_hsm.h | 39 ++++++++++++ lib/utils/Kconfig | 2 + lib/utils/hsm/Kconfig | 10 ++++ lib/utils/hsm/fdt_hsm.c | 89 +++++++++ [...] 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:429 listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -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 The generic platform can have multiple HSM drivers so add a simple FDT based HSM driver framework. Signed-off-by: Anup Patel --- include/sbi_utils/hsm/fdt_hsm.h | 39 ++++++++++++ lib/utils/Kconfig | 2 + lib/utils/hsm/Kconfig | 10 ++++ lib/utils/hsm/fdt_hsm.c | 89 ++++++++++++++++++++++++++++ lib/utils/hsm/fdt_hsm_drivers.carray | 3 + lib/utils/hsm/objects.mk | 11 ++++ platform/generic/configs/defconfig | 1 + platform/generic/platform.c | 6 ++ 8 files changed, 161 insertions(+) create mode 100644 include/sbi_utils/hsm/fdt_hsm.h create mode 100644 lib/utils/hsm/Kconfig create mode 100644 lib/utils/hsm/fdt_hsm.c create mode 100644 lib/utils/hsm/fdt_hsm_drivers.carray create mode 100644 lib/utils/hsm/objects.mk diff --git a/include/sbi_utils/hsm/fdt_hsm.h b/include/sbi_utils/hsm/fdt_hsm.h new file mode 100644 index 00000000..7076873c --- /dev/null +++ b/include/sbi_utils/hsm/fdt_hsm.h @@ -0,0 +1,39 @@ +/* + * SPDX-License-Identifier: BSD-2-Clause + * + * Copyright (c) 2024 Ventana Micro Systems Inc. + * + * Authors: + * Anup Patel + */ + +#ifndef __FDT_HSM_H__ +#define __FDT_HSM_H__ + +#include + +#ifdef CONFIG_FDT_HSM + +struct fdt_hsm { + const struct fdt_match *match_table; + int (*fdt_fixup)(void *fdt); + int (*cold_init)(void *fdt, int nodeoff, const struct fdt_match *match); + int (*warm_init)(void); + void (*exit)(void); +}; + +int fdt_hsm_fixup(void *fdt); + +void fdt_hsm_exit(void); + +int fdt_hsm_init(bool cold_boot); + +#else + +static inline int fdt_hsm_fixup(void *fdt) { return 0; } +static inline void fdt_hsm_exit(void) { } +static inline int fdt_hsm_init(bool cold_boot) { return 0; } + +#endif + +#endif diff --git a/lib/utils/Kconfig b/lib/utils/Kconfig index 3f32c1ca..c860a185 100644 --- a/lib/utils/Kconfig +++ b/lib/utils/Kconfig @@ -6,6 +6,8 @@ source "$(OPENSBI_SRC_DIR)/lib/utils/fdt/Kconfig" source "$(OPENSBI_SRC_DIR)/lib/utils/gpio/Kconfig" +source "$(OPENSBI_SRC_DIR)/lib/utils/hsm/Kconfig" + source "$(OPENSBI_SRC_DIR)/lib/utils/i2c/Kconfig" source "$(OPENSBI_SRC_DIR)/lib/utils/ipi/Kconfig" diff --git a/lib/utils/hsm/Kconfig b/lib/utils/hsm/Kconfig new file mode 100644 index 00000000..31506116 --- /dev/null +++ b/lib/utils/hsm/Kconfig @@ -0,0 +1,10 @@ +# SPDX-License-Identifier: BSD-2-Clause + +menu "HSM Device Support" + +config FDT_HSM + bool "FDT based HSM drivers" + depends on FDT + default n + +endmenu diff --git a/lib/utils/hsm/fdt_hsm.c b/lib/utils/hsm/fdt_hsm.c new file mode 100644 index 00000000..7166dce8 --- /dev/null +++ b/lib/utils/hsm/fdt_hsm.c @@ -0,0 +1,89 @@ +/* + * SPDX-License-Identifier: BSD-2-Clause + * + * Copyright (c) 2024 Ventana Micro Systems Inc. + * + * Authors: + * Anup Patel + */ + +#include +#include +#include + +/* List of FDT HSM drivers generated at compile time */ +extern struct fdt_hsm *fdt_hsm_drivers[]; +extern unsigned long fdt_hsm_drivers_size; + +static struct fdt_hsm *current_driver = NULL; + +int fdt_hsm_fixup(void *fdt) +{ + if (current_driver && current_driver->fdt_fixup) + return current_driver->fdt_fixup(fdt); + return 0; +} + +void fdt_hsm_exit(void) +{ + if (current_driver && current_driver->exit) + current_driver->exit(); +} + +static int fdt_hsm_warm_init(void) +{ + if (current_driver && current_driver->warm_init) + return current_driver->warm_init(); + return 0; +} + +static int fdt_hsm_cold_init(void) +{ + int pos, noff, rc; + struct fdt_hsm *drv; + const struct fdt_match *match; + void *fdt = fdt_get_address(); + + for (pos = 0; pos < fdt_hsm_drivers_size; pos++) { + drv = fdt_hsm_drivers[pos]; + + noff = -1; + while ((noff = fdt_find_match(fdt, noff, + drv->match_table, &match)) >= 0) { + /* drv->cold_init must not be NULL */ + if (drv->cold_init == NULL) + return SBI_EFAIL; + + rc = drv->cold_init(fdt, noff, match); + if (rc == SBI_ENODEV) + continue; + if (rc) + return rc; + current_driver = drv; + + /* + * We can have multiple HSM devices on multi-die or + * multi-socket systems so we cannot break here. + */ + } + } + + /* + * On some single-hart system there is no need for HSM, + * so we cannot return a failure here + */ + return 0; +} + +int fdt_hsm_init(bool cold_boot) +{ + int rc; + + if (cold_boot) { + rc = fdt_hsm_cold_init(); + if (rc) + return rc; + } + + return fdt_hsm_warm_init(); +} diff --git a/lib/utils/hsm/fdt_hsm_drivers.carray b/lib/utils/hsm/fdt_hsm_drivers.carray new file mode 100644 index 00000000..21396db2 --- /dev/null +++ b/lib/utils/hsm/fdt_hsm_drivers.carray @@ -0,0 +1,3 @@ +HEADER: sbi_utils/hsm/fdt_hsm.h +TYPE: struct fdt_hsm +NAME: fdt_hsm_drivers diff --git a/lib/utils/hsm/objects.mk b/lib/utils/hsm/objects.mk new file mode 100644 index 00000000..49337bf5 --- /dev/null +++ b/lib/utils/hsm/objects.mk @@ -0,0 +1,11 @@ +# +# SPDX-License-Identifier: BSD-2-Clause +# +# Copyright (c) 2024 Ventana Micro Systems Inc. +# +# Authors: +# Anup Patel +# + +libsbiutils-objs-$(CONFIG_FDT_HSM) += hsm/fdt_hsm.o +libsbiutils-objs-$(CONFIG_FDT_HSM) += hsm/fdt_hsm_drivers.carray.o diff --git a/platform/generic/configs/defconfig b/platform/generic/configs/defconfig index 54300fb5..2efc7136 100644 --- a/platform/generic/configs/defconfig +++ b/platform/generic/configs/defconfig @@ -10,6 +10,7 @@ CONFIG_FDT_GPIO=y CONFIG_FDT_GPIO_DESIGNWARE=y CONFIG_FDT_GPIO_SIFIVE=y CONFIG_FDT_GPIO_STARFIVE=y +CONFIG_FDT_HSM=y CONFIG_FDT_I2C=y CONFIG_FDT_I2C_SIFIVE=y CONFIG_FDT_I2C_DW=y diff --git a/platform/generic/platform.c b/platform/generic/platform.c index 138a54c2..bcd7133b 100644 --- a/platform/generic/platform.c +++ b/platform/generic/platform.c @@ -21,6 +21,7 @@ #include #include #include +#include #include #include #include @@ -236,6 +237,8 @@ static int generic_early_init(bool cold_boot) return rc; } + fdt_hsm_init(cold_boot); + if (!generic_plat || !generic_plat->early_init) return 0; @@ -261,6 +264,7 @@ static int generic_final_init(bool cold_boot) fdt_cpu_fixup(fdt); fdt_fixups(fdt); fdt_domain_fixup(fdt); + fdt_hsm_fixup(fdt); if (generic_plat && generic_plat->fdt_fixup) { rc = generic_plat->fdt_fixup(fdt, generic_plat_match); @@ -287,6 +291,8 @@ static int generic_vendor_ext_provider(long funcid, static void generic_early_exit(void) { + fdt_hsm_exit(); + if (generic_plat && generic_plat->early_exit) generic_plat->early_exit(generic_plat_match); } From patchwork Tue Aug 6 07:33:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 1969362 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=TCK418KN; 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=JvJ/dC+R; 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 4WdQ6k1MZ6z1yYD for ; Tue, 6 Aug 2024 17:34:22 +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=lmW4bGcP3piOfC1iBbJ2paZiwuTVx7rcELw4Wm7wsPQ=; b=TCK418KNZy8FeD vudZ4P940HtdgWrcRzhH8xCfIavUgKVvoCR/H9fp6TiqvBo8f8CHvDc5jtKrM6nGoeI/kqjA1za1B K9fMOpngFhd3K2CqXvXSNWS1gzJ4a2vL81aFQjWyZf1x++aw7iyHELRU5JR1Z0pb2jwwXrPtC27RI lOA+/OAQ7EzeZExEZ9qzcgFOJfw4l9jlp+cYkR+yDUwHc4xwC0WgCFi9N/ST1qNnduvd3O6VLcDak B6JHVEg4qDRldSszv/eocim/dwFFIDHz1NHIuaBF/ZbDETlOMHcUGi1DALpTSmuSLplJC6wUhoInQ 5V/u6Z15l3OzgSC3M78A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sbEhy-00000000nxN-1pZP; Tue, 06 Aug 2024 07:34:14 +0000 Received: from mail-pf1-x42e.google.com ([2607:f8b0:4864:20::42e]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sbEhv-00000000nuy-2fl8 for opensbi@lists.infradead.org; Tue, 06 Aug 2024 07:34:13 +0000 Received: by mail-pf1-x42e.google.com with SMTP id d2e1a72fcca58-70d1c655141so203982b3a.1 for ; Tue, 06 Aug 2024 00:34:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1722929651; x=1723534451; 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=s/ZKIgQwhn8FRNR3SSuhI2F5k74pyUvGdi5+UfohX5I=; b=JvJ/dC+RZE5/3xZR/7Khe9BAdEh6uxKyl+Ky2UZvLet5ioKlvDkrOSUqEs/qn1KVQ7 WnfR1vAmHNgDqblLV7SXj3ojyjpRh7VwBeZ7dsPQEVnDh5w1qI10yhvFWkBFJcwXFdPj YbNkX6w+KtVnz4wfcIBgHDF9uhWeoLXITWXQNuRDhc4JBEjfYthcJl0/gfzllReCBKSb V+OGVyMxmrOgcFooMJDWZFLczNYdOXjDpGbcXN/SvwQb04xHZ/dgSJvHVRtA6NgXljMJ trwy4To57TPTkzYe+fICbRdLji5EmFwQFxrUIfrBHTodMyocNBM1uMO6yv7XG6hG+U1I 2P4w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722929651; x=1723534451; 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=s/ZKIgQwhn8FRNR3SSuhI2F5k74pyUvGdi5+UfohX5I=; b=Xze3YUcdrG0iEF5Zg1PEP5wGEN4mUJ6o1ArIew52HN/YEhyTZwEQwZngcsSjbDlpy4 UTkj7boG6g9lqThMNJT462RE7gfCuOwiPUGi5aPDaFlqJLzOJuFMH9mI8phV39pBo0eh ra0WVbqKPGFmowrbQqxKyIvqFngvHqbQI9wh2YIHRnMZ8L3T167uDmhJTKhoA9isF/+F 1kelZZcdHiUrSVdMHkpKdcCggHilwxBbpR/VjxIzBNsdnuy6uiVUZtgKIE1h99SnD15F Nu3SVgQ2/Fy7B0T3KDtBZ2BZEYndQ1QcXI6w0JKbTPPAgQqLvOam/9iXq+ItaDGDVd/Y Bd/Q== X-Forwarded-Encrypted: i=1; AJvYcCX2w1uXrZRGFH13m/bpkwwxA4yOJfS0oqNJbXnheypLFGuH85LlycKwg0dAqZX+gktrzbw03pWevM9tKMksz4G2DWhFPi2aOlaB7hw= X-Gm-Message-State: AOJu0Yy2ZPyE7ciXXd2LHc3zj/ys6Kv+sQ+ZXwANyUfdZ9oiv6n+7fNv K/q72r6B9CgFKTq9MTIr8ZtgGJ/A1jvAoCYvmTX+HRJu6J1iPgb7UWbWk0AlfaDvQjtNzN+8U/v c X-Google-Smtp-Source: AGHT+IGSZ+n/1FGZM1U2VqQUl4pVgZWZkPV2CClzy2ao30iDxPJdMrDuoEZ7REdPUQmLEuAUPfcRAw== X-Received: by 2002:a05:6a20:7288:b0:1c3:fc60:84f1 with SMTP id adf61e73a8af0-1c6995511c4mr16694737637.7.1722929650353; Tue, 06 Aug 2024 00:34:10 -0700 (PDT) Received: from anup-ubuntu-vm.localdomain ([223.185.134.124]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7106ed2de28sm6455011b3a.191.2024.08.06.00.34.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Aug 2024 00:34:09 -0700 (PDT) From: Anup Patel To: Atish Patra Cc: Andrew Jones , Anup Patel , opensbi@lists.infradead.org, Subrahmanya Lingappa , Anup Patel Subject: [PATCH 09/16] lib: sbi: Add optional resume address to hart suspend Date: Tue, 6 Aug 2024 13:03:31 +0530 Message-Id: <20240806073338.1856901-10-apatel@ventanamicro.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240806073338.1856901-1-apatel@ventanamicro.com> References: <20240806073338.1856901-1-apatel@ventanamicro.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240806_003411_904924_127E43D5 X-CRM114-Status: GOOD ( 13.28 ) 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: From: Subrahmanya Lingappa Add an optional resume address to the platform specific hart suspend call. Signed-off-by: Subrahmanya Lingappa Signed-off-by: Anup Patel --- include/sbi/sbi_hsm.h | 6 +++++- lib/sbi/sbi_hsm.c | 6 +++--- platform/generic/ [...] 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:42e listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -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 From: Subrahmanya Lingappa Add an optional resume address to the platform specific hart suspend call. Signed-off-by: Subrahmanya Lingappa Signed-off-by: Anup Patel --- include/sbi/sbi_hsm.h | 6 +++++- lib/sbi/sbi_hsm.c | 6 +++--- platform/generic/allwinner/sun20i-d1.c | 2 +- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/include/sbi/sbi_hsm.h b/include/sbi/sbi_hsm.h index 4b5601ba..aa692dfe 100644 --- a/include/sbi/sbi_hsm.h +++ b/include/sbi/sbi_hsm.h @@ -39,8 +39,12 @@ struct sbi_hsm_device { * * For successful non-retentive suspend, the hart will resume from * the warm boot entry point. + * + * NOTE: mmode_resume_addr(resume address) is optional hence it + * may or may not be honored by the platform. If its not honored + * then platform must ensure to resume from the warmboot address. */ - int (*hart_suspend)(u32 suspend_type); + int (*hart_suspend)(u32 suspend_type, ulong mmode_resume_addr); /** * Perform platform-specific actions to resume from a suspended state. diff --git a/lib/sbi/sbi_hsm.c b/lib/sbi/sbi_hsm.c index 3706acfb..2f518d44 100644 --- a/lib/sbi/sbi_hsm.c +++ b/lib/sbi/sbi_hsm.c @@ -228,10 +228,10 @@ static int hsm_device_hart_stop(void) return SBI_ENOTSUPP; } -static int hsm_device_hart_suspend(u32 suspend_type) +static int hsm_device_hart_suspend(u32 suspend_type, ulong mmode_resume_addr) { if (hsm_dev && hsm_dev->hart_suspend) - return hsm_dev->hart_suspend(suspend_type); + return hsm_dev->hart_suspend(suspend_type, mmode_resume_addr); return SBI_ENOTSUPP; } @@ -536,7 +536,7 @@ int sbi_hsm_hart_suspend(struct sbi_scratch *scratch, u32 suspend_type, __sbi_hsm_suspend_non_ret_save(scratch); /* Try platform specific suspend */ - ret = hsm_device_hart_suspend(suspend_type); + ret = hsm_device_hart_suspend(suspend_type, scratch->warmboot_addr); if (ret == SBI_ENOTSUPP) { /* Try generic implementation of default suspend types */ if (suspend_type == SBI_HSM_SUSPEND_RET_DEFAULT || diff --git a/platform/generic/allwinner/sun20i-d1.c b/platform/generic/allwinner/sun20i-d1.c index ab2eee55..33312e0b 100644 --- a/platform/generic/allwinner/sun20i-d1.c +++ b/platform/generic/allwinner/sun20i-d1.c @@ -152,7 +152,7 @@ static void sun20i_d1_riscv_cfg_init(void) writel_relaxed(entry >> 32, SUN20I_D1_RISCV_CFG_BASE + RESET_ENTRY_HI_REG); } -static int sun20i_d1_hart_suspend(u32 suspend_type) +static int sun20i_d1_hart_suspend(u32 suspend_type, ulong mmode_resume_addr) { /* Use the generic code for retentive suspend. */ if (!(suspend_type & SBI_HSM_SUSP_NON_RET_BIT)) From patchwork Tue Aug 6 07:33:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 1969363 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=Uq4m8s5v; 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=CW6pVbKz; 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 4WdQ6r3Fnmz1yYD for ; Tue, 6 Aug 2024 17:34:28 +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=Lh+/CyfsH46jtO7wThWp9b84eRFm/9E1g9hSqXH2DFA=; b=Uq4m8s5vCKrsXl gYJ8Yp8IKqqLFAYzHYiXwzAjil3pNt6i3ljzUVuKz12JVvRfz4GvvpPGXNn5SZZJpBqFbqCqDEB/z 1zFr8zqR1kk7Sya5aIzL+rtd6ptHIFtDJOiCTG5o/xA3KSMkZLk9LZNIGW0ktE25/yMA1/U+KtPCB 1pzTCtNDNtp0WxIbJdrgFmBMvFulDhRTaziz3YRTA9SNJLWpTsQgBL8Yn0iAnhgRwPosdHc0pPack fyH8t2XZ7OcgHkAuqIw0QXanKiO9kBZzj2Pl+mztozGUewDAtwKcVg03TFTxJqrmnSSowNorAJt15 oCBG1sTVLvyGvzb0R75w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sbEi5-00000000o1x-0E4x; Tue, 06 Aug 2024 07:34:21 +0000 Received: from mail-pf1-x42e.google.com ([2607:f8b0:4864:20::42e]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sbEhy-00000000nxZ-3q7y for opensbi@lists.infradead.org; Tue, 06 Aug 2024 07:34:18 +0000 Received: by mail-pf1-x42e.google.com with SMTP id d2e1a72fcca58-70d23caf8ddso286213b3a.0 for ; Tue, 06 Aug 2024 00:34:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1722929654; x=1723534454; 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=Y7TPRnaFrAtCNWpiTJtHiv13r5RgdBoonWPDPgXEYpU=; b=CW6pVbKz3Dq4Hd/A+7rJAHs/6hpcA7GDf5UMeylcp+YS3zfjKuViYFjrW3eJRbSp9C hA7jKChMjXIcSazAXRkULFPMJN0Q0ylk6lqX7jr3WWE7pphcZp/tkYBshkhxnBoc0sXy m35UIYJJSexbUF0EJVXxBcz5rZrdhi8kv5otSDWYRWV4W8/OUro7prPNS9rB7w5+XXTK mMJsa/t9KJQQ4e23iX0v5D/zkoQvRNtqhjqO8v6SA8NQc4zk7fxrgWLQgzFYf0tYMVfs a6uXhQfr1Bx7QlOqs98Ztyp8PwPwwK7wN39TZcdc82BOUO8g7KsrHLxMhuAuv7isYpyl 9hhA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722929654; x=1723534454; 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=Y7TPRnaFrAtCNWpiTJtHiv13r5RgdBoonWPDPgXEYpU=; b=gP5THyxLpNTLGniGD/hronR8QMmbwZYeCgjpM7C4mxdzILtKobKn+a7dWIaSX6ae6C nnmJ/H8bbEuIBu2ZPfFDA6bJXuoYzOM9Q/E/5FL3Iy2s/b1cbb0RLkKdBzJZXF4p6o3T GrsuSc6FGU/mcUro9+aAFipHcDifhoVVDtDe6U8phlWKIVGBKIxe5gtBiHyGUDZlRFaY yK3i541quWMhd7MGKbjJsz+1ldihNiKG8NGonGB0vuxubGiwlaktL1KmZtwaI/b9k0+6 qbkfgNbAYXm02vrC5/Wq7/+PJOGzmkpfdbHNHQKkseBmEWarjr8IlsRjFOhnzKOH18w+ BpNw== X-Forwarded-Encrypted: i=1; AJvYcCXhsGGP70BJeajW/JuIhILWYPtMGnHf2uhcgbLUZ9hCZna9vv+PCDaDOo6rD9MqCymWesd2tcZfdq/HsWJEkZs4MS5nHJHUrDb3JCM= X-Gm-Message-State: AOJu0YweaG4xf3lU2WQDVfghCMtPHPs77ZlK2ELrHgpAokLx939w8vpI jTt5mIB+C+O2SW0b3YrXUUQ485VNUwO1XwYx1ScOC25Kch3vn7wPeR02SeLf3v8= X-Google-Smtp-Source: AGHT+IFpx6P438yryYcjQSQ7maQjngJJqU1ql1ykiOxF+ZM0O4g83oEKmLeB18fu+3K4yGne0RIG3g== X-Received: by 2002:a05:6a00:1912:b0:707:ffa4:de3f with SMTP id d2e1a72fcca58-7106cfcfd8dmr19561944b3a.17.1722929653554; Tue, 06 Aug 2024 00:34:13 -0700 (PDT) Received: from anup-ubuntu-vm.localdomain ([223.185.134.124]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7106ed2de28sm6455011b3a.191.2024.08.06.00.34.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Aug 2024 00:34:13 -0700 (PDT) From: Anup Patel To: Atish Patra Cc: Andrew Jones , Anup Patel , opensbi@lists.infradead.org, Subrahmanya Lingappa , Anup Patel Subject: [PATCH 10/16] lib: utils/hsm: Add RPMI HSM driver Date: Tue, 6 Aug 2024 13:03:32 +0530 Message-Id: <20240806073338.1856901-11-apatel@ventanamicro.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240806073338.1856901-1-apatel@ventanamicro.com> References: <20240806073338.1856901-1-apatel@ventanamicro.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240806_003415_559930_1D0661DB X-CRM114-Status: GOOD ( 22.15 ) 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: From: Subrahmanya Lingappa The RPMI HSM service group provides set of routine to query and control power states of a Hart. Add RPMI based Hart State Management (HSM) driver. 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:42e listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -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 From: Subrahmanya Lingappa The RPMI HSM service group provides set of routine to query and control power states of a Hart. Add RPMI based Hart State Management (HSM) driver. Signed-off-by: Subrahmanya Lingappa Signed-off-by: Anup Patel --- include/sbi_utils/mailbox/rpmi_msgprot.h | 91 ++++++ lib/utils/hsm/Kconfig | 9 + lib/utils/hsm/fdt_hsm_rpmi.c | 351 +++++++++++++++++++++++ lib/utils/hsm/objects.mk | 3 + platform/generic/configs/defconfig | 1 + 5 files changed, 455 insertions(+) create mode 100644 lib/utils/hsm/fdt_hsm_rpmi.c diff --git a/include/sbi_utils/mailbox/rpmi_msgprot.h b/include/sbi_utils/mailbox/rpmi_msgprot.h index a2403c90..efe35aee 100644 --- a/include/sbi_utils/mailbox/rpmi_msgprot.h +++ b/include/sbi_utils/mailbox/rpmi_msgprot.h @@ -151,6 +151,7 @@ enum rpmi_servicegroup_id { RPMI_SRVGRP_BASE = 0x00001, RPMI_SRVGRP_SYSTEM_RESET = 0x00002, RPMI_SRVGRP_SYSTEM_SUSPEND = 0x00003, + RPMI_SRVGRP_HSM = 0x00004, RPMI_SRVGRP_ID_MAX_COUNT, }; @@ -243,4 +244,94 @@ struct rpmi_syssusp_suspend_resp { s32 status; }; +/** RPMI HSM State Management ServiceGroup Service IDs */ +enum rpmi_cpu_hsm_service_id { + RPMI_HSM_SRV_ENABLE_NOTIFICATION = 0x01, + RPMI_HSM_SRV_HART_START = 0x02, + RPMI_HSM_SRV_HART_STOP = 0x03, + RPMI_HSM_SRV_HART_SUSPEND = 0x04, + RPMI_HSM_SRV_GET_HART_STATUS = 0x05, + RPMI_HSM_SRV_GET_HART_LIST = 0x06, + RPMI_HSM_SRV_GET_SUSPEND_TYPES = 0x07, + RPMI_HSM_SRV_GET_SUSPEND_INFO = 0x08, + RPMI_HSM_SRV_ID_MAX_COUNT, +}; + +/* HSM service group request and response structs */ +struct rpmi_hsm_hart_start_req { + u32 hartid; + u32 start_addr_lo; + u32 start_addr_hi; +}; + +struct rpmi_hsm_hart_start_resp { + s32 status; +}; + +struct rpmi_hsm_hart_stop_req { + u32 hartid; +}; + +struct rpmi_hsm_hart_stop_resp { + s32 status; +}; + +struct rpmi_hsm_hart_susp_req { + u32 hartid; + u32 suspend_type; + u32 resume_addr_lo; + u32 resume_addr_hi; +}; + +struct rpmi_hsm_hart_susp_resp { + s32 status; +}; + +struct rpmi_hsm_get_hart_status_req { + u32 hartid; +}; + +struct rpmi_hsm_get_hart_status_resp { + s32 status; + u32 hart_status; +}; + +struct rpmi_hsm_get_hart_list_req { + u32 start_index; +}; + +struct rpmi_hsm_get_hart_list_resp { + s32 status; + u32 remaining; + u32 returned; + /* remaining space need to be adjusted for the above 3 u32's */ + u32 hartid[(RPMI_MSG_DATA_SIZE(RPMI_SLOT_SIZE_MIN) - (sizeof(u32) * 3)) / sizeof(u32)]; +}; + +struct rpmi_hsm_get_susp_types_req { + u32 start_index; +}; + +struct rpmi_hsm_get_susp_types_resp { + s32 status; + u32 remaining; + u32 returned; + /* remaining space need to be adjusted for the above 3 u32's */ + u32 types[(RPMI_MSG_DATA_SIZE(RPMI_SLOT_SIZE_MIN) - (sizeof(u32) * 3)) / sizeof(u32)]; +}; + +struct rpmi_hsm_get_susp_info_req { + u32 suspend_type; +}; + +struct rpmi_hsm_get_susp_info_resp { + s32 status; + u32 flags; +#define RPMI_HSM_FLAGS_LOCAL_TIME_STOP (1U << 31) + u32 entry_latency_us; + u32 exit_latency_us; + u32 wakeup_latency_us; + u32 min_residency_us; +}; + #endif /* !__RPMI_MSGPROT_H__ */ diff --git a/lib/utils/hsm/Kconfig b/lib/utils/hsm/Kconfig index 31506116..1ad7958f 100644 --- a/lib/utils/hsm/Kconfig +++ b/lib/utils/hsm/Kconfig @@ -7,4 +7,13 @@ config FDT_HSM depends on FDT default n +if FDT_HSM + +config FDT_HSM_RPMI + bool "FDT RPMI HSM driver" + depends on FDT_MAILBOX && RPMI_MAILBOX + default n + +endif + endmenu diff --git a/lib/utils/hsm/fdt_hsm_rpmi.c b/lib/utils/hsm/fdt_hsm_rpmi.c new file mode 100644 index 00000000..e598901d --- /dev/null +++ b/lib/utils/hsm/fdt_hsm_rpmi.c @@ -0,0 +1,351 @@ +/* + * SPDX-License-Identifier: BSD-2-Clause + * + * Copyright (c) 2024 Ventana Micro Systems Inc. + * + * Authors: + * Subrahmanya Lingappa + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define MAX_HSM_SUPSEND_STATE_NAMELEN 16 + +struct rpmi_hsm_suspend { + u32 num_states; + struct sbi_cpu_idle_state *states; +}; + +struct rpmi_hsm { + struct mbox_chan *chan; + struct rpmi_hsm_suspend *susp; +}; + +static unsigned long rpmi_hsm_offset; + +static struct rpmi_hsm *rpmi_hsm_get_pointer(u32 hartid) +{ + struct sbi_scratch *scratch; + + scratch = sbi_hartid_to_scratch(hartid); + if (!scratch || !rpmi_hsm_offset) + return NULL; + + return sbi_scratch_offset_ptr(scratch, rpmi_hsm_offset); +} + +static int rpmi_hsm_start(u32 hartid, ulong resume_addr) +{ + struct rpmi_hsm_hart_start_req req; + struct rpmi_hsm_hart_start_resp resp; + struct rpmi_hsm *rpmi = rpmi_hsm_get_pointer(hartid); + + if (!rpmi) + return SBI_ENOSYS; + + req.hartid = hartid; + req.start_addr_lo = resume_addr; + req.start_addr_hi = (u64)resume_addr >> 32; + + return rpmi_normal_request_with_status( + rpmi->chan, RPMI_HSM_SRV_HART_START, + &req, rpmi_u32_count(req), rpmi_u32_count(req), + &resp, rpmi_u32_count(resp), rpmi_u32_count(resp)); +} + +static int rpmi_hsm_stop(void) +{ + int rc; + struct rpmi_hsm_hart_stop_req req; + struct rpmi_hsm_hart_stop_resp resp; + void (*jump_warmboot)(void) = + (void (*)(void))sbi_scratch_thishart_ptr()->warmboot_addr; + struct rpmi_hsm *rpmi = rpmi_hsm_get_pointer(current_hartid()); + + if (!rpmi) + return SBI_ENOSYS; + + req.hartid = current_hartid(); + + rc = rpmi_normal_request_with_status( + rpmi->chan, RPMI_HSM_SRV_HART_STOP, + &req, rpmi_u32_count(req), rpmi_u32_count(req), + &resp, rpmi_u32_count(resp), rpmi_u32_count(resp)); + if (rc) + return rc; + + /* Wait for interrupt */ + wfi(); + + jump_warmboot(); + + return 0; +} + +static bool is_rpmi_hsm_susp_supported(struct rpmi_hsm_suspend *susp, u32 type) +{ + int i; + + for (i = 0; i < susp->num_states; i++) + if (type == susp->states[i].suspend_param) + return true; + + return false; +} + +static int rpmi_hsm_suspend(u32 type, ulong resume_addr) +{ + int rc; + struct rpmi_hsm_hart_susp_req req; + struct rpmi_hsm_hart_susp_resp resp; + struct rpmi_hsm *rpmi = rpmi_hsm_get_pointer(current_hartid()); + + if (!rpmi) + return SBI_ENOSYS; + + /* check if harts support this suspend type */ + if (!is_rpmi_hsm_susp_supported(rpmi->susp, type)) + return SBI_EINVAL; + + req.hartid = current_hartid(); + req.suspend_type = type; + req.resume_addr_lo = resume_addr; + req.resume_addr_hi = (u64)resume_addr >> 32; + + rc = rpmi_normal_request_with_status( + rpmi->chan, RPMI_HSM_SRV_HART_SUSPEND, + &req, rpmi_u32_count(req), rpmi_u32_count(req), + &resp, rpmi_u32_count(resp), rpmi_u32_count(resp)); + if (rc) + return rc; + + /* Wait for interrupt */ + wfi(); + + return 0; +} + +static struct sbi_hsm_device sbi_hsm_rpmi = { + .name = "rpmi-hsm", + .hart_start = rpmi_hsm_start, + .hart_stop = rpmi_hsm_stop, + .hart_suspend = rpmi_hsm_suspend, +}; + +static int rpmi_hsm_fixup(void *fdt) +{ + struct rpmi_hsm *rpmi = rpmi_hsm_get_pointer(current_hartid()); + + if (!rpmi || !rpmi->susp || !rpmi->susp->num_states) + return 0; + + return fdt_add_cpu_idle_states(fdt, rpmi->susp->states); +} + +static int rpmi_hsm_get_num_suspend_states(struct mbox_chan *chan, + struct rpmi_hsm_suspend *susp) +{ + int rc; + struct rpmi_hsm_get_susp_types_req req; + struct rpmi_hsm_get_susp_types_resp resp; + + req.start_index = 0; + rc = rpmi_normal_request_with_status( + chan, RPMI_HSM_SRV_GET_SUSPEND_TYPES, + &req, rpmi_u32_count(req), rpmi_u32_count(req), + &resp, rpmi_u32_count(resp), rpmi_u32_count(resp)); + if (rc) + return rc; + + susp->num_states = resp.returned + resp.remaining; + return 0; +} + +static int rpmi_hsm_get_suspend_states(struct mbox_chan *chan, + struct rpmi_hsm_suspend *susp) +{ + int rc, i, cnt = 0; + struct rpmi_hsm_get_susp_types_req req; + struct rpmi_hsm_get_susp_types_resp resp; + struct rpmi_hsm_get_susp_info_req dreq; + struct rpmi_hsm_get_susp_info_resp dresp; + struct sbi_cpu_idle_state *state; + + if (!susp->num_states) + return 0; + + req.start_index = 0; + do { + rc = rpmi_normal_request_with_status( + chan, RPMI_HSM_SRV_GET_SUSPEND_TYPES, + &req, rpmi_u32_count(req), rpmi_u32_count(req), + &resp, rpmi_u32_count(resp), rpmi_u32_count(resp)); + if (rc) + return rc; + + for (i = 0; i < resp.returned && cnt < susp->num_states; i++) + susp->states[cnt++].suspend_param = resp.types[i]; + req.start_index = i; + } while (resp.remaining); + + for (i = 0; i < susp->num_states; i++) { + state = &susp->states[i]; + + dreq.suspend_type = state->suspend_param; + rc = rpmi_normal_request_with_status( + chan, RPMI_HSM_SRV_GET_SUSPEND_INFO, + &dreq, rpmi_u32_count(dreq), rpmi_u32_count(dreq), + &dresp, rpmi_u32_count(dresp), rpmi_u32_count(dresp)); + if (rc) + return rc; + + state->entry_latency_us = dresp.entry_latency_us; + state->exit_latency_us = dresp.exit_latency_us; + state->wakeup_latency_us = dresp.wakeup_latency_us; + state->min_residency_us = dresp.min_residency_us; + } + + return 0; +} + +static int rpmi_hsm_update_hart_scratch(struct mbox_chan *chan, + struct rpmi_hsm_suspend *susp) +{ + int rc, i; + struct rpmi_hsm_get_hart_list_req req; + struct rpmi_hsm_get_hart_list_resp resp; + struct rpmi_hsm *rpmi = rpmi_hsm_get_pointer(current_hartid()); + + req.start_index = 0; + do { + rc = rpmi_normal_request_with_status( + chan, RPMI_HSM_SRV_GET_HART_LIST, + &req, rpmi_u32_count(req), rpmi_u32_count(req), + &resp, rpmi_u32_count(resp), rpmi_u32_count(resp)); + if (rc) + return rc; + + for (i = 0; i < resp.returned; i++) { + rpmi = rpmi_hsm_get_pointer(resp.hartid[i]); + if (!rpmi) + return SBI_ENOSYS; + + rpmi->chan = chan; + rpmi->susp = susp; + } + + req.start_index += resp.returned; + } while (resp.remaining); + + return 0; +} + +static int rpmi_hsm_cold_init(void *fdt, int nodeoff, + const struct fdt_match *match) +{ + int rc, i; + struct mbox_chan *chan; + struct rpmi_hsm_suspend *susp; + + if (!rpmi_hsm_offset) { + rpmi_hsm_offset = + sbi_scratch_alloc_type_offset(struct rpmi_hsm); + if (!rpmi_hsm_offset) + return SBI_ENOMEM; + } + + /* + * If channel request failed then other end does not support + * HSM service group so do nothing. + */ + rc = fdt_mailbox_request_chan(fdt, nodeoff, 0, &chan); + if (rc) + return 0; + + /* Allocate context for HART suspend states */ + susp = sbi_zalloc(sizeof(*susp)); + if (!susp) + return SBI_ENOMEM; + + /* Get number of HART suspend states */ + rc = rpmi_hsm_get_num_suspend_states(chan, susp); + if (rc) + goto fail_free_susp; + + /* Skip HART suspend state discovery for zero HART suspend states */ + if (!susp->num_states) + goto skip_suspend_states; + + /* Allocate array of HART suspend states */ + susp->states = sbi_calloc(susp->num_states + 1, sizeof(*susp->states)); + if (!susp->states) { + rc = SBI_ENOMEM; + goto fail_free_susp; + } + + /* Allocate name of each HART suspend state */ + for (i = 0; i < susp->num_states; i++) { + susp->states[i].name = + sbi_zalloc(MAX_HSM_SUPSEND_STATE_NAMELEN); + if (!susp->states[i].name) { + do { + i--; + sbi_free((void *)susp->states[i].name); + } while (i > 0); + + rc = SBI_ENOMEM; + goto fail_free_susp_states; + } + sbi_snprintf((char *)susp->states[i].name, + MAX_HSM_SUPSEND_STATE_NAMELEN, "cpu-susp%d", i); + } + + /* Get details about each HART suspend state */ + rc = rpmi_hsm_get_suspend_states(chan, susp); + if (rc) + goto fail_free_susp_state_names; + +skip_suspend_states: + /* Update per-HART scratch space */ + rc = rpmi_hsm_update_hart_scratch(chan, susp); + if (rc) + goto fail_free_susp_state_names; + + /* Register HSM device */ + if (!susp->num_states) + sbi_hsm_rpmi.hart_suspend = NULL; + sbi_hsm_set_device(&sbi_hsm_rpmi); + + return 0; + +fail_free_susp_state_names: + for (i = 0; i < susp->num_states; i++) + sbi_free((void *)susp->states[i].name); +fail_free_susp_states: + if (susp->num_states) + sbi_free(susp->states); +fail_free_susp: + sbi_free(susp); + return rc; +} + +static const struct fdt_match rpmi_hsm_match[] = { + { .compatible = "riscv,rpmi-hsm" }, + {}, +}; + +struct fdt_hsm fdt_hsm_rpmi = { + .match_table = rpmi_hsm_match, + .fdt_fixup = rpmi_hsm_fixup, + .cold_init = rpmi_hsm_cold_init, +}; diff --git a/lib/utils/hsm/objects.mk b/lib/utils/hsm/objects.mk index 49337bf5..b54b6f6c 100644 --- a/lib/utils/hsm/objects.mk +++ b/lib/utils/hsm/objects.mk @@ -9,3 +9,6 @@ libsbiutils-objs-$(CONFIG_FDT_HSM) += hsm/fdt_hsm.o libsbiutils-objs-$(CONFIG_FDT_HSM) += hsm/fdt_hsm_drivers.carray.o + +carray-fdt_hsm_drivers-$(CONFIG_FDT_HSM_RPMI) += fdt_hsm_rpmi +libsbiutils-objs-$(CONFIG_FDT_HSM_RPMI) += hsm/fdt_hsm_rpmi.o diff --git a/platform/generic/configs/defconfig b/platform/generic/configs/defconfig index 2efc7136..78fc96b6 100644 --- a/platform/generic/configs/defconfig +++ b/platform/generic/configs/defconfig @@ -11,6 +11,7 @@ CONFIG_FDT_GPIO_DESIGNWARE=y CONFIG_FDT_GPIO_SIFIVE=y CONFIG_FDT_GPIO_STARFIVE=y CONFIG_FDT_HSM=y +CONFIG_FDT_HSM_RPMI=y CONFIG_FDT_I2C=y CONFIG_FDT_I2C_SIFIVE=y CONFIG_FDT_I2C_DW=y From patchwork Tue Aug 6 07:33:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 1969364 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=IdIubnEz; 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=iBTckI1Y; 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 4WdQ6s2V8kz1ydt for ; Tue, 6 Aug 2024 17:34:29 +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=V5QNWWXPG7+hRJOCQS8lsvmEppDmwwL6i+EVdfdXinA=; b=IdIubnEzFxy+kk DWEBKdCKqQyRRf0tDRF0bjJofcsdWjeUmFAq9B7dOLDn+hFNJXDOg2PsL/m+ZeAJCIaKiPryGMeiD EF3FGeJ5bvrV9JjWSEwECrp+rFjBQA+WD7khcTLIbYIYYYo97N5Jum0koDtD55wJkb1M6t8A389EV Ve8E7NT7PGOGGJL30lOONT51k/PNlqdgaewUk15n3qzZeRaK91q1NpQt+eUxM2/E6ClgxeWtHKHwd cq9AdR4GZ7H1dg8lEOy7e0nJK2C0kxOtx2husXyM5I0YNZe57UnqHtGGn42ZpYZ8YtJW1jWQFXkmO 8W42JUz4iIR24DH1K5pw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sbEi6-00000000o3j-25Ti; Tue, 06 Aug 2024 07:34:22 +0000 Received: from mail-pg1-x52b.google.com ([2607:f8b0:4864:20::52b]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sbEi1-00000000nzN-2BuI for opensbi@lists.infradead.org; Tue, 06 Aug 2024 07:34:19 +0000 Received: by mail-pg1-x52b.google.com with SMTP id 41be03b00d2f7-7a263f6439eso143894a12.3 for ; Tue, 06 Aug 2024 00:34:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1722929656; x=1723534456; 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=ZqgHPdXvyyiYF+mqE1Hfy5rLM6qVSm+QKCx6uIgLne0=; b=iBTckI1YGrWzVXuGtXt6XAs++1mNYWjrXtxeX2S8VTcNQpbZAwayIzEauxdOMnJnjO wBSFG866TF0YpBjZdyWN+0gdX92O9MtDDVHrd/73sGY/qUWVJT8Kb+x3xkekPSear02c zNMVfjbCXCFKFcN8nK/E9e1ROlUp48Beg5LP6M01o7Iv2DHhd9mHJYGEQYW2CBdDjuzY 1BzxAayWhZZgEcyepojOA+eZdoOiVHQ7/4x7uWaCcW4nUo/eODxFDPuWOba5XhS8zuC+ /bw+4mkBQjuWfoVXQOW00h5rGbfYqfrboibkUNVA5bwBY75X/DlmAYLMxoNUr7juYmCK ai+Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722929656; x=1723534456; 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=ZqgHPdXvyyiYF+mqE1Hfy5rLM6qVSm+QKCx6uIgLne0=; b=jn/2emf0YWek+LWFozz587W4fYvoqLLnUAPV61xlhZzsLbpUeMSfRkxtq+VfIroaE2 TAaZMv7NmOM0KAeNYp8AAOhu376q7k/oQAbB9EjE/+aE6We7ncTNOqzln8+ooDyiW/eC mll8VDN50mpIY1TeU8iDNps4eKis/HR1EuNt56m9zGnhzVI6PkHvfJXdYlW5igwGZAMf u256U+oYHUd/SFnmiD1B/bp+vBSjY/u3tPzs8vDf4K10yYePuIkdDKBS2nmt1uAVZfDm B17AsgxN9H5DB8VdH5vIniAnQLjbG3yi32JNcLWemlNO17N1PngWaUCBrEshC8EnDED0 KdaQ== X-Forwarded-Encrypted: i=1; AJvYcCWp3K1JYP2yLSTvP6TW2wX6Pnt30MEJQLjw7KzqeDTdtBN87lgRIvlO896HWLO+Oub7aOlfvlQBCX/4LlUvvzLtHcdPQpZvuqaZsXc= X-Gm-Message-State: AOJu0YxT1YGK0qDhmQBa6KMZz/3phRJwpLAq+l8zMfJAL4x5q+8w2hSK /SQMvPT4mP/RpsA3wwv/XX/+iVo03Fg1E9aJsRk4bKH7fWk4z+6OuWGiPZkz9tGWcW1jwKwYxx8 d X-Google-Smtp-Source: AGHT+IGQiGw5WgMjIh2IBdqCT9IHUystflnfT6awYSybu71p+gn81ZSCpuSC629vP7Z4Q5B0oNvokQ== X-Received: by 2002:a05:6a20:6a0a:b0:1c4:d4b2:ffe6 with SMTP id adf61e73a8af0-1c69953e89emr15285869637.19.1722929656198; Tue, 06 Aug 2024 00:34:16 -0700 (PDT) Received: from anup-ubuntu-vm.localdomain ([223.185.134.124]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7106ed2de28sm6455011b3a.191.2024.08.06.00.34.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Aug 2024 00:34:15 -0700 (PDT) From: Anup Patel To: Atish Patra Cc: Andrew Jones , Anup Patel , opensbi@lists.infradead.org, Anup Patel Subject: [PATCH 11/16] lib: utils: Add simple FDT based CPPC driver framework Date: Tue, 6 Aug 2024 13:03:33 +0530 Message-Id: <20240806073338.1856901-12-apatel@ventanamicro.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240806073338.1856901-1-apatel@ventanamicro.com> References: <20240806073338.1856901-1-apatel@ventanamicro.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240806_003417_725996_6ABE5AE7 X-CRM114-Status: GOOD ( 21.43 ) 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: The generic platform can have multiple CPPC drivers so add a simple FDT based CPPC driver framework. Signed-off-by: Anup Patel --- include/sbi_utils/cppc/fdt_cppc.h | 35 +++++++++++ lib/utils/Kconfig | 2 + lib/utils/cppc/Kconfig | 10 ++++ lib/utils/cppc/fdt_cppc.c | 82 +++++ [...] 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:52b listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -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 The generic platform can have multiple CPPC drivers so add a simple FDT based CPPC driver framework. Signed-off-by: Anup Patel --- include/sbi_utils/cppc/fdt_cppc.h | 35 +++++++++++ lib/utils/Kconfig | 2 + lib/utils/cppc/Kconfig | 10 ++++ lib/utils/cppc/fdt_cppc.c | 82 ++++++++++++++++++++++++++ lib/utils/cppc/fdt_cppc_drivers.carray | 3 + lib/utils/cppc/objects.mk | 11 ++++ platform/generic/configs/defconfig | 1 + platform/generic/platform.c | 3 + 8 files changed, 147 insertions(+) create mode 100644 include/sbi_utils/cppc/fdt_cppc.h create mode 100644 lib/utils/cppc/Kconfig create mode 100644 lib/utils/cppc/fdt_cppc.c create mode 100644 lib/utils/cppc/fdt_cppc_drivers.carray create mode 100644 lib/utils/cppc/objects.mk diff --git a/include/sbi_utils/cppc/fdt_cppc.h b/include/sbi_utils/cppc/fdt_cppc.h new file mode 100644 index 00000000..af0cdc41 --- /dev/null +++ b/include/sbi_utils/cppc/fdt_cppc.h @@ -0,0 +1,35 @@ +/* + * SPDX-License-Identifier: BSD-2-Clause + * + * Copyright (c) 2024 Ventana Micro Systems Inc. + * + * Authors: + * Anup Patel + */ + +#ifndef __FDT_CPPC_H__ +#define __FDT_CPPC_H__ + +#include + +#ifdef CONFIG_FDT_CPPC + +struct fdt_cppc { + const struct fdt_match *match_table; + int (*cold_init)(void *fdt, int nodeoff, const struct fdt_match *match); + int (*warm_init)(void); + void (*exit)(void); +}; + +void fdt_cppc_exit(void); + +int fdt_cppc_init(bool cold_boot); + +#else + +static inline void fdt_cppc_exit(void) { } +static inline int fdt_cppc_init(bool cold_boot) { return 0; } + +#endif + +#endif diff --git a/lib/utils/Kconfig b/lib/utils/Kconfig index c860a185..002d6f8f 100644 --- a/lib/utils/Kconfig +++ b/lib/utils/Kconfig @@ -2,6 +2,8 @@ menu "Utils and Drivers Support" +source "$(OPENSBI_SRC_DIR)/lib/utils/cppc/Kconfig" + source "$(OPENSBI_SRC_DIR)/lib/utils/fdt/Kconfig" source "$(OPENSBI_SRC_DIR)/lib/utils/gpio/Kconfig" diff --git a/lib/utils/cppc/Kconfig b/lib/utils/cppc/Kconfig new file mode 100644 index 00000000..08d1c97f --- /dev/null +++ b/lib/utils/cppc/Kconfig @@ -0,0 +1,10 @@ +# SPDX-License-Identifier: BSD-2-Clause + +menu "CPPC Device Support" + +config FDT_CPPC + bool "FDT based CPPC drivers" + depends on FDT + default n + +endmenu diff --git a/lib/utils/cppc/fdt_cppc.c b/lib/utils/cppc/fdt_cppc.c new file mode 100644 index 00000000..de11f0e1 --- /dev/null +++ b/lib/utils/cppc/fdt_cppc.c @@ -0,0 +1,82 @@ +/* + * SPDX-License-Identifier: BSD-2-Clause + * + * Copyright (c) 2024 Ventana Micro Systems Inc. + * + * Authors: + * Anup Patel + */ + +#include +#include +#include + +/* List of FDT CPPC drivers generated at compile time */ +extern struct fdt_cppc *fdt_cppc_drivers[]; +extern unsigned long fdt_cppc_drivers_size; + +static struct fdt_cppc *current_driver = NULL; + +void fdt_cppc_exit(void) +{ + if (current_driver && current_driver->exit) + current_driver->exit(); +} + +static int fdt_cppc_warm_init(void) +{ + if (current_driver && current_driver->warm_init) + return current_driver->warm_init(); + return 0; +} + +static int fdt_cppc_cold_init(void) +{ + int pos, noff, rc; + struct fdt_cppc *drv; + const struct fdt_match *match; + void *fdt = fdt_get_address(); + + for (pos = 0; pos < fdt_cppc_drivers_size; pos++) { + drv = fdt_cppc_drivers[pos]; + + noff = -1; + while ((noff = fdt_find_match(fdt, noff, + drv->match_table, &match)) >= 0) { + /* drv->cold_init must not be NULL */ + if (drv->cold_init == NULL) + return SBI_EFAIL; + + rc = drv->cold_init(fdt, noff, match); + if (rc == SBI_ENODEV) + continue; + if (rc) + return rc; + current_driver = drv; + + /* + * We can have multiple CPPC devices on multi-die or + * multi-socket systems so we cannot break here. + */ + } + } + + /* + * On some single-hart system there is no need for CPPC, + * so we cannot return a failure here + */ + return 0; +} + +int fdt_cppc_init(bool cold_boot) +{ + int rc; + + if (cold_boot) { + rc = fdt_cppc_cold_init(); + if (rc) + return rc; + } + + return fdt_cppc_warm_init(); +} diff --git a/lib/utils/cppc/fdt_cppc_drivers.carray b/lib/utils/cppc/fdt_cppc_drivers.carray new file mode 100644 index 00000000..c2a9af2c --- /dev/null +++ b/lib/utils/cppc/fdt_cppc_drivers.carray @@ -0,0 +1,3 @@ +HEADER: sbi_utils/cppc/fdt_cppc.h +TYPE: struct fdt_cppc +NAME: fdt_cppc_drivers diff --git a/lib/utils/cppc/objects.mk b/lib/utils/cppc/objects.mk new file mode 100644 index 00000000..fb37478a --- /dev/null +++ b/lib/utils/cppc/objects.mk @@ -0,0 +1,11 @@ +# +# SPDX-License-Identifier: BSD-2-Clause +# +# Copyright (c) 2024 Ventana Micro Systems Inc. +# +# Authors: +# Anup Patel +# + +libsbiutils-objs-$(CONFIG_FDT_CPPC) += cppc/fdt_cppc.o +libsbiutils-objs-$(CONFIG_FDT_CPPC) += cppc/fdt_cppc_drivers.carray.o diff --git a/platform/generic/configs/defconfig b/platform/generic/configs/defconfig index 78fc96b6..bd18c3c1 100644 --- a/platform/generic/configs/defconfig +++ b/platform/generic/configs/defconfig @@ -6,6 +6,7 @@ CONFIG_PLATFORM_SIFIVE_FU740=y CONFIG_PLATFORM_SOPHGO_SG2042=y CONFIG_PLATFORM_STARFIVE_JH7110=y CONFIG_PLATFORM_THEAD=y +CONFIG_FDT_CPPC=y CONFIG_FDT_GPIO=y CONFIG_FDT_GPIO_DESIGNWARE=y CONFIG_FDT_GPIO_SIFIVE=y diff --git a/platform/generic/platform.c b/platform/generic/platform.c index bcd7133b..d085647d 100644 --- a/platform/generic/platform.c +++ b/platform/generic/platform.c @@ -17,6 +17,7 @@ #include #include #include +#include #include #include #include @@ -238,6 +239,7 @@ static int generic_early_init(bool cold_boot) } fdt_hsm_init(cold_boot); + fdt_cppc_init(cold_boot); if (!generic_plat || !generic_plat->early_init) return 0; @@ -291,6 +293,7 @@ static int generic_vendor_ext_provider(long funcid, static void generic_early_exit(void) { + fdt_cppc_exit(); fdt_hsm_exit(); if (generic_plat && generic_plat->early_exit) From patchwork Tue Aug 6 07:33:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 1969365 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=u3GzfEoL; 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=EIe5MWll; 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 4WdQ6z3kQGz1ydt for ; Tue, 6 Aug 2024 17:34:35 +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=1OQ/Gp4vaNuWyvnewUI6u8wOYdGn2elvyV+qgJ0ahMA=; b=u3GzfEoLZ8kgom nmPFqfBiNYNGTb/21UEk8iiIlIZNjDFEYhtsn9vOikBeJk2SbToVBEkP1e8c0s2pgF8OfRKDFQWxi wd9iYWkzZ1vmxbnsg85b+6YxqzQPXZhhIfzRF0xmGyW1ZXf4z+DJgussgbQWV6rsqo2rFG62vTtOB RG/76YPc0Wol+ApSf56nkqO+lRNXgZuXvsTOaoGNq6qOF/PeTVN3s1Uq/MCpgSzTSQwAUvyUqo90K utgxIkNdU4jFApWcp3NhxUbplcFobsv+BSbBmTs0dqbQgCS5n0WFk5HhX6hdRaJeKsFsa/PGFqtcm YeHzDPGU27wxt1GhI8CQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sbEiC-00000000o90-0Ymf; Tue, 06 Aug 2024 07:34:28 +0000 Received: from mail-pf1-x434.google.com ([2607:f8b0:4864:20::434]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sbEi4-00000000o1Y-26N9 for opensbi@lists.infradead.org; Tue, 06 Aug 2024 07:34:25 +0000 Received: by mail-pf1-x434.google.com with SMTP id d2e1a72fcca58-7104f939aaaso260649b3a.1 for ; Tue, 06 Aug 2024 00:34:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1722929659; x=1723534459; 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=RfiIrj24wpoH9q3QQVcyN3yO1yesFh9YsUO44Oai1KE=; b=EIe5MWllGdBsvk5qGvuDBBGiuXoBWmC/z5OTOdMu93IjJWWSO+hqt6+1cZuDsX7pvq AKEpgwCyJY5+NPiZD0vrWNnOpPpJxGSS7oMnze4BG+C5blV4VZR70XctSUkdJRxEMPLD SbhRoO1NrNXfGLTOm6MmFpWAahqJ3KYbW+L31XXhHiINKk0jPk5Gsk+hRoP/tRvDw+ET JY/pfOiAwqIvsU8Q6oxLMIassVZC+n5XThV8SktG2QXzsEtdwvsnsfksccJJFns1LubC t+yvFJVUm9Po+f8TfBbKJUypmTcy4+IeCi+eTWBlWWGCs+m/37/kxIlsgApqDh/hU9ZW 1h3w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722929659; x=1723534459; 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=RfiIrj24wpoH9q3QQVcyN3yO1yesFh9YsUO44Oai1KE=; b=IJDONtApYEk+YvcGcYR75jG8QRLK1P125PH/P0On/OvR/gzmRCoVyDqydgdggp1N6p bQT+wE9ieMBysqeIre6y2uauHLrnwzhSzXfo7lG+YwTm5TSKnEIfkzkQ1gmsUGI3kF4F s0raiiHlL5niWwY8kH1Aodh8FCXhwDWfeylCPAs138wvBxiBoWlYuhRP8i7eMaV+V3/f 6lGotLDGq0krA/7IrojJNHyqEJhGizpNw2Hf9wgnQq+v8CIzu+23hQLV02IRlDB5qmar TtBHgo7L5BeDzgo4dgjcoz9aflZrwx1sNPu7HoFn+tWdIsNfSkrD8tanGLIxoXHuZFst w1sA== X-Forwarded-Encrypted: i=1; AJvYcCXzlzIv5W6d7Zn5XcuSsAmWEeYOjHMDpyKhFPWWLm7mLBqEoj4OCOuwLrOHCFDdGYwgt0EAd2kH@lists.infradead.org X-Gm-Message-State: AOJu0YysHCGGO/CpA3u12FqWMyf4MwqwcYATUtybNn8P5Pp12XplNrzR 50agAaSPWmFeBtHR1Gq0n0KwwDEkIDXb2NCFzhMUl4PdQHHNgjPuIX/81hjEI+M= X-Google-Smtp-Source: AGHT+IF6HImvE4ryuRcEgipAGgBeTFSRCxkk4TCUFGy8w5aUrLpNvydCC6fPTXWXjxvoxeBT1gdzoQ== X-Received: by 2002:a05:6a00:88e:b0:70d:306c:3e57 with SMTP id d2e1a72fcca58-7106cfab267mr13956356b3a.10.1722929659164; Tue, 06 Aug 2024 00:34:19 -0700 (PDT) Received: from anup-ubuntu-vm.localdomain ([223.185.134.124]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7106ed2de28sm6455011b3a.191.2024.08.06.00.34.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Aug 2024 00:34:18 -0700 (PDT) From: Anup Patel To: Atish Patra Cc: Andrew Jones , Anup Patel , opensbi@lists.infradead.org, Subrahmanya Lingappa , Sunil V L , Anup Patel Subject: [PATCH 12/16] lib: utils/cppc: Add RPMI CPPC driver Date: Tue, 6 Aug 2024 13:03:34 +0530 Message-Id: <20240806073338.1856901-13-apatel@ventanamicro.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240806073338.1856901-1-apatel@ventanamicro.com> References: <20240806073338.1856901-1-apatel@ventanamicro.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240806_003420_928046_D223F4B9 X-CRM114-Status: GOOD ( 21.95 ) 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: From: Subrahmanya Lingappa Add RPMI based driver for CPPC register read, write and probe. Signed-off-by: Subrahmanya Lingappa Co-developed-by: Sunil V L Signed-off-by: Sunil V L Signed-off-by: Anup Patel List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "opensbi" Errors-To: opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org From: Subrahmanya Lingappa Add RPMI based driver for CPPC register read, write and probe. Signed-off-by: Subrahmanya Lingappa Co-developed-by: Sunil V L Signed-off-by: Sunil V L Signed-off-by: Anup Patel --- include/sbi_utils/mailbox/rpmi_msgprot.h | 83 +++++++ lib/utils/cppc/Kconfig | 9 + lib/utils/cppc/fdt_cppc_rpmi.c | 287 +++++++++++++++++++++++ lib/utils/cppc/objects.mk | 3 + platform/generic/configs/defconfig | 1 + 5 files changed, 383 insertions(+) create mode 100644 lib/utils/cppc/fdt_cppc_rpmi.c diff --git a/include/sbi_utils/mailbox/rpmi_msgprot.h b/include/sbi_utils/mailbox/rpmi_msgprot.h index efe35aee..f7913ab1 100644 --- a/include/sbi_utils/mailbox/rpmi_msgprot.h +++ b/include/sbi_utils/mailbox/rpmi_msgprot.h @@ -152,6 +152,7 @@ enum rpmi_servicegroup_id { RPMI_SRVGRP_SYSTEM_RESET = 0x00002, RPMI_SRVGRP_SYSTEM_SUSPEND = 0x00003, RPMI_SRVGRP_HSM = 0x00004, + RPMI_SRVGRP_CPPC = 0x00005, RPMI_SRVGRP_ID_MAX_COUNT, }; @@ -334,4 +335,86 @@ struct rpmi_hsm_get_susp_info_resp { u32 min_residency_us; }; +/** RPMI CPPC ServiceGroup Service IDs */ +enum rpmi_cppc_service_id { + RPMI_CPPC_SRV_ENABLE_NOTIFICATION = 0x01, + RPMI_CPPC_SRV_PROBE_REG = 0x02, + RPMI_CPPC_SRV_READ_REG = 0x03, + RPMI_CPPC_SRV_WRITE_REG = 0x04, + RPMI_CPPC_SRV_GET_FAST_CHANNEL_ADDR = 0x05, + RPMI_CPPC_SRV_POKE_FAST_CHANNEL = 0x06, + RPMI_CPPC_SRV_GET_HART_LIST = 0x07, + RPMI_CPPC_SRV_MAX_COUNT, +}; + +struct rpmi_cppc_probe_req { + u32 hart_id; + u32 reg_id; +}; + +struct rpmi_cppc_probe_resp { + s32 status; + u32 reg_len; +}; + +struct rpmi_cppc_read_reg_req { + u32 hart_id; + u32 reg_id; +}; + +struct rpmi_cppc_read_reg_resp { + s32 status; + u32 data_lo; + u32 data_hi; +}; + +struct rpmi_cppc_write_reg_req { + u32 hart_id; + u32 reg_id; + u32 data_lo; + u32 data_hi; +}; + +struct rpmi_cppc_write_reg_resp { + s32 status; +}; + +struct rpmi_cppc_get_fast_channel_addr_req { + u32 hart_id; +}; + +struct rpmi_cppc_get_fast_channel_addr_resp { + s32 status; +#define RPMI_CPPC_FAST_CHANNEL_FLAGS_DB_WIDTH_POS 1 +#define RPMI_CPPC_FAST_CHANNEL_FLAGS_DB_WIDTH_MASK \ + (3U << RPMI_CPPC_FAST_CHANNEL_FLAGS_DB_WIDTH_POS) +#define RPMI_CPPC_FAST_CHANNEL_FLAGS_DB_SUPPORTED (1U << 0) + u32 flags; + u32 addr_lo; + u32 addr_hi; + u32 db_addr_lo; + u32 db_addr_hi; + u32 db_id_lo; + u32 db_id_hi; +}; + +enum rpmi_cppc_fast_channel_db_width { + RPMI_CPPC_FAST_CHANNEL_DB_WIDTH_8 = 0x0, + RPMI_CPPC_FAST_CHANNEL_DB_WIDTH_16 = 0x1, + RPMI_CPPC_FAST_CHANNEL_DB_WIDTH_32 = 0x2, + RPMI_CPPC_FAST_CHANNEL_DB_WIDTH_64 = 0x3, +}; + +struct rpmi_cppc_hart_list_req { + u32 start_index; +}; + +struct rpmi_cppc_hart_list_resp { + s32 status; + u32 remaining; + u32 returned; + /* remaining space need to be adjusted for the above 3 u32's */ + u32 hartid[(RPMI_MSG_DATA_SIZE(RPMI_SLOT_SIZE_MIN) - (sizeof(u32) * 3)) / sizeof(u32)]; +}; + #endif /* !__RPMI_MSGPROT_H__ */ diff --git a/lib/utils/cppc/Kconfig b/lib/utils/cppc/Kconfig index 08d1c97f..494f6894 100644 --- a/lib/utils/cppc/Kconfig +++ b/lib/utils/cppc/Kconfig @@ -7,4 +7,13 @@ config FDT_CPPC depends on FDT default n +if FDT_CPPC + +config FDT_CPPC_RPMI + bool "FDT RPMI CPPC driver" + depends on FDT_MAILBOX && RPMI_MAILBOX + default n + +endif + endmenu diff --git a/lib/utils/cppc/fdt_cppc_rpmi.c b/lib/utils/cppc/fdt_cppc_rpmi.c new file mode 100644 index 00000000..e9669ce4 --- /dev/null +++ b/lib/utils/cppc/fdt_cppc_rpmi.c @@ -0,0 +1,287 @@ +/* + * SPDX-License-Identifier: BSD-2-Clause + * + * Copyright (c) 2024 Ventana Micro Systems Inc. + * + * Authors: + * Subrahmanya Lingappa + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +struct rpmi_cppc { + struct mbox_chan *chan; + bool fast_chan_supported; + ulong fast_chan_addr; + bool fast_chan_db_supported; + enum rpmi_cppc_fast_channel_db_width fast_chan_db_width; + ulong fast_chan_db_addr; + u64 fast_chan_db_id; +}; + +static unsigned long rpmi_cppc_offset; + +static struct rpmi_cppc *rpmi_cppc_get_pointer(u32 hartid) +{ + struct sbi_scratch *scratch; + + scratch = sbi_hartid_to_scratch(hartid); + if (!scratch || !rpmi_cppc_offset) + return NULL; + + return sbi_scratch_offset_ptr(scratch, rpmi_cppc_offset); +} + +static int rpmi_cppc_read(unsigned long reg, u64 *val) +{ + int rc = SBI_SUCCESS; + struct rpmi_cppc_read_reg_req req; + struct rpmi_cppc_read_reg_resp resp; + struct rpmi_cppc *cppc; + + req.hart_id = current_hartid(); + req.reg_id = reg; + cppc = rpmi_cppc_get_pointer(req.hart_id); + + rc = rpmi_normal_request_with_status( + cppc->chan, RPMI_CPPC_SRV_READ_REG, + &req, rpmi_u32_count(req), rpmi_u32_count(req), + &resp, rpmi_u32_count(resp), rpmi_u32_count(resp)); + if (rc) + return rc; + +#if __riscv_xlen == 32 + *val = resp.data_lo; +#else + *val = (u64)resp.data_hi << 32 | resp.data_lo; +#endif + return rc; +} + +static int rpmi_cppc_write(unsigned long reg, u64 val) +{ + int rc = SBI_SUCCESS; + u32 hart_id = current_hartid(); + struct rpmi_cppc_write_reg_req req; + struct rpmi_cppc_write_reg_resp resp; + struct rpmi_cppc *cppc = rpmi_cppc_get_pointer(hart_id); + + if (reg != SBI_CPPC_DESIRED_PERF || !cppc->fast_chan_supported) { + req.hart_id = hart_id; + req.reg_id = reg; + req.data_lo = val & 0xFFFFFFFF; + req.data_hi = val >> 32; + + rc = rpmi_normal_request_with_status( + cppc->chan, RPMI_CPPC_SRV_WRITE_REG, + &req, rpmi_u32_count(req), rpmi_u32_count(req), + &resp, rpmi_u32_count(resp), rpmi_u32_count(resp)); + } else { + /* use fast path writes */ +#if __riscv_xlen != 32 + writeq(val, (void *)cppc->fast_chan_addr); +#else + writel((u32)val, (void *)cppc->fast_chan_addr); + writel((u32)(val >> 32), (void *)(cppc->fast_chan_addr + 4)); +#endif + if (cppc->fast_chan_db_supported) { + switch (cppc->fast_chan_db_width) { + case RPMI_CPPC_FAST_CHANNEL_DB_WIDTH_8: + writeb((u8)cppc->fast_chan_db_id, + (void *)cppc->fast_chan_db_addr); + break; + case RPMI_CPPC_FAST_CHANNEL_DB_WIDTH_16: + writew((u16)cppc->fast_chan_db_id, + (void *)cppc->fast_chan_db_addr); + break; + case RPMI_CPPC_FAST_CHANNEL_DB_WIDTH_32: + writel((u32)cppc->fast_chan_db_id, + (void *)cppc->fast_chan_db_addr); + break; + case RPMI_CPPC_FAST_CHANNEL_DB_WIDTH_64: +#if __riscv_xlen != 32 + writeq(cppc->fast_chan_db_id, + (void *)cppc->fast_chan_db_addr); +#else + writel((u32)cppc->fast_chan_db_id, + (void *)cppc->fast_chan_db_addr); + writel((u32)(cppc->fast_chan_db_id >> 32), + (void *)(cppc->fast_chan_db_addr + 4)); +#endif + break; + default: + break; + } + } + } + + return rc; +} + +static int rpmi_cppc_probe(unsigned long reg) +{ + int rc; + struct rpmi_cppc *cppc; + struct rpmi_cppc_probe_resp resp; + struct rpmi_cppc_probe_req req; + + req.hart_id = current_hartid(); + req.reg_id = reg; + + cppc = rpmi_cppc_get_pointer(req.hart_id); + if (!cppc) + return SBI_ENOSYS; + + rc = rpmi_normal_request_with_status( + cppc->chan, RPMI_CPPC_SRV_PROBE_REG, + &req, rpmi_u32_count(req), rpmi_u32_count(req), + &resp, rpmi_u32_count(resp), rpmi_u32_count(resp)); + if (rc) + return rc; + + return resp.reg_len; +} + +static struct sbi_cppc_device sbi_rpmi_cppc = { + .name = "rpmi-cppc", + .cppc_read = rpmi_cppc_read, + .cppc_write = rpmi_cppc_write, + .cppc_probe = rpmi_cppc_probe, +}; + +#define TOTAL_FAST_CHAN_SIZE 0x1000 +#define FAST_CHANNEL_REGION_ALIGN 0x1000 + +static int rpmi_cppc_update_hart_scratch(struct mbox_chan *chan) +{ + int rc, i; + struct rpmi_cppc_hart_list_req req; + struct rpmi_cppc_hart_list_resp resp; + struct rpmi_cppc_get_fast_channel_addr_req freq; + struct rpmi_cppc_get_fast_channel_addr_resp fresp; + struct rpmi_cppc *cppc; + unsigned long fast_chan_base_addr; + + /* Workaround for Smepmp issue */ + freq.hart_id = 0; + rc = rpmi_normal_request_with_status( + chan, RPMI_CPPC_SRV_GET_FAST_CHANNEL_ADDR, + &freq, rpmi_u32_count(freq), rpmi_u32_count(freq), + &fresp, rpmi_u32_count(fresp), rpmi_u32_count(fresp)); + if (rc) + return rc; + +#if __riscv_xlen == 32 + fast_chan_base_addr = fresp.addr_lo; +#else + fast_chan_base_addr = (ulong)fresp.addr_hi << 32 | + fresp.addr_lo; +#endif + rc = sbi_domain_root_add_memrange(fast_chan_base_addr, + TOTAL_FAST_CHAN_SIZE, + FAST_CHANNEL_REGION_ALIGN, + (SBI_DOMAIN_MEMREGION_MMIO | + SBI_DOMAIN_MEMREGION_M_READABLE | + SBI_DOMAIN_MEMREGION_M_WRITABLE)); + if (rc) + return rc; + + req.start_index = 0; + do { + rc = rpmi_normal_request_with_status( + chan, RPMI_CPPC_SRV_GET_HART_LIST, + &req, rpmi_u32_count(req), rpmi_u32_count(req), + &resp, rpmi_u32_count(resp), rpmi_u32_count(resp)); + if (rc) + return rc; + + for (i = 0; i < resp.returned; i++) { + cppc = rpmi_cppc_get_pointer(resp.hartid[i]); + if (!cppc) + return SBI_ENOSYS; + cppc->chan = chan; + + freq.hart_id = resp.hartid[i]; + rc = rpmi_normal_request_with_status( + chan, RPMI_CPPC_SRV_GET_FAST_CHANNEL_ADDR, + &freq, rpmi_u32_count(freq), rpmi_u32_count(freq), + &fresp, rpmi_u32_count(fresp), rpmi_u32_count(fresp)); + if (rc) + continue; + + cppc->fast_chan_supported = true; +#if __riscv_xlen == 32 + cppc->fast_chan_addr = fresp.addr_lo; +#else + cppc->fast_chan_addr = (ulong)fresp.addr_hi << 32 | + fresp.addr_lo; +#endif + cppc->fast_chan_db_supported = fresp.flags & + RPMI_CPPC_FAST_CHANNEL_FLAGS_DB_SUPPORTED; + cppc->fast_chan_db_width = (fresp.flags & + RPMI_CPPC_FAST_CHANNEL_FLAGS_DB_WIDTH_MASK) >> + RPMI_CPPC_FAST_CHANNEL_FLAGS_DB_WIDTH_POS; +#if __riscv_xlen == 32 + cppc->fast_chan_db_addr = fresp.db_addr_lo; +#else + cppc->fast_chan_db_addr = (ulong)fresp.db_addr_hi << 32 | + fresp.db_addr_lo; +#endif + cppc->fast_chan_db_id = (u64)fresp.db_id_hi << 32 | + fresp.db_id_lo; + } + + req.start_index += resp.returned; + } while (resp.remaining); + + return 0; +} + +static int rpmi_cppc_cold_init(void *fdt, int nodeoff, + const struct fdt_match *match) +{ + int rc; + struct mbox_chan *chan; + + if (!rpmi_cppc_offset) { + rpmi_cppc_offset = + sbi_scratch_alloc_type_offset(struct rpmi_cppc); + if (!rpmi_cppc_offset) + return SBI_ENOMEM; + } + + /* + * If channel request failed then other end does not support + * CPPC service group so do nothing. + */ + rc = fdt_mailbox_request_chan(fdt, nodeoff, 0, &chan); + if (rc) + return 0; + + /* Update per-HART scratch space */ + rc = rpmi_cppc_update_hart_scratch(chan); + if (rc) + return rc; + + sbi_cppc_set_device(&sbi_rpmi_cppc); + + return 0; +} + +static const struct fdt_match rpmi_cppc_match[] = { + { .compatible = "riscv,rpmi-cppc" }, + {}, +}; + +struct fdt_cppc fdt_cppc_rpmi = { + .match_table = rpmi_cppc_match, + .cold_init = rpmi_cppc_cold_init, +}; diff --git a/lib/utils/cppc/objects.mk b/lib/utils/cppc/objects.mk index fb37478a..07dc7d89 100644 --- a/lib/utils/cppc/objects.mk +++ b/lib/utils/cppc/objects.mk @@ -9,3 +9,6 @@ libsbiutils-objs-$(CONFIG_FDT_CPPC) += cppc/fdt_cppc.o libsbiutils-objs-$(CONFIG_FDT_CPPC) += cppc/fdt_cppc_drivers.carray.o + +carray-fdt_cppc_drivers-$(CONFIG_FDT_CPPC_RPMI) += fdt_cppc_rpmi +libsbiutils-objs-$(CONFIG_FDT_CPPC_RPMI) += cppc/fdt_cppc_rpmi.o diff --git a/platform/generic/configs/defconfig b/platform/generic/configs/defconfig index bd18c3c1..384918f9 100644 --- a/platform/generic/configs/defconfig +++ b/platform/generic/configs/defconfig @@ -7,6 +7,7 @@ CONFIG_PLATFORM_SOPHGO_SG2042=y CONFIG_PLATFORM_STARFIVE_JH7110=y CONFIG_PLATFORM_THEAD=y CONFIG_FDT_CPPC=y +CONFIG_FDT_CPPC_RPMI=y CONFIG_FDT_GPIO=y CONFIG_FDT_GPIO_DESIGNWARE=y CONFIG_FDT_GPIO_SIFIVE=y From patchwork Tue Aug 6 07:33:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 1969367 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=agxU2Edj; 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=iAvew3q1; 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 4WdQ7H23lqz1yYD for ; Tue, 6 Aug 2024 17:34:51 +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=GBGYgf0Nb55tB4wwv4gX/Vja0aVgc1C8TYqaEziORIw=; b=agxU2EdjKzYBYz ctCzvDekYdLv1pRcDs7dr0AP1MpC6ZA79RYHvHpKqRuxCCQrcspKYk+nTDe1Ew40EAUBa4YKzSsqa 1JLn8e3eUZS7KGT2UntuALdzS+z6Fjx1bniZXzMUY/OiSSFrzb2J9lOdxvZTizjLXjozwnyyYYG22 xqTGIn9k8FwtwJpB8n/vj3SxDlIT68FjSa9tZSwMUj2DNht1F7x3+xogZGes6lYPTo1pUef/Qumyi QKEmaaC083dmhikpnR8TvIz7ouIwih4FH7/cVCATt/3dut1NkrtMW8Ako8iXG3PuWjuYeUOx6/9hA rh+Rw0cC+E3lAdmWkg8A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sbEiQ-00000000oJR-27yl; Tue, 06 Aug 2024 07:34:42 +0000 Received: from mail-pf1-x433.google.com ([2607:f8b0:4864:20::433]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sbEi7-00000000o4I-2fET for opensbi@lists.infradead.org; Tue, 06 Aug 2024 07:34:35 +0000 Received: by mail-pf1-x433.google.com with SMTP id d2e1a72fcca58-7104f93a20eso243778b3a.1 for ; Tue, 06 Aug 2024 00:34:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1722929663; x=1723534463; 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=IIXH2m0sChT4WiDoizsiVStglXOcp2RrseAizC7R2GA=; b=iAvew3q1dNcJjHLjd6s9TCYh6WGKITMaU09ahXtGnpb73BKcY9kDK0pNBDGC4opgPh 09vgwrGqP382y+WiB2+j+RSBlMkoxm/AT52G5V0gBTyFkYluPoamfj5cb798V6SzNWkT aj2k11P269jTpVkCuYk1+KIrbDh3mjfHmfAbwMRyAs2LpR8eM8ILz1mUJlIfmRurGEGQ vCb8uvW9vnnDulB9Ni5uGLaPuZpz1dAXaZrInsIoMC97BgO8hIWVbKTkxusasrWx58Jz lwSofkNIr2PK6CnwUAY+YourZZ/q8ZXFpO+nt0X/AEOZO5D/o8joskoRSXpozF6BNbb3 lU/Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722929663; x=1723534463; 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=IIXH2m0sChT4WiDoizsiVStglXOcp2RrseAizC7R2GA=; b=dia6ykiImJrd94p/lNKRXH/6OrPe8W1BOmmrmJIGAhtlbb5kmgZDJxSEERBAem5Uem t3Myz0ZTShJaS7R6dwJqt/HPZ9Unxv+1FuyISAQ2Yp0ptimGbmobrPY1gaKFyrTh8E7d CDhhRYhEDMJX7ungSJZfKE9a7FoHyyy04b9r5Bu51KH+YpQZBG8FrKlk8OSh9oXJvECs Po+N6onEC0pnaSUfh2tI+n5PMlvcgq8xEOo00bqsSruNxnycObsfAiU+JMi8/wEFqS/4 ppDvVzHyNF1mVsi6zOI2ppg5/7jE/q/Cz24OqViL66PbpGAV0UwjQWc9njiS5NNYkXmL ieVw== X-Forwarded-Encrypted: i=1; AJvYcCXq+2rHz7vtPYg5yvDPQXZMKTZWt9PnI+jID964ZxoF2RLnSOAkzSp3F9jyL4HUqFExDaKdeXj41oiNJkYh957GqIndy0Kc1wn2CkQ= X-Gm-Message-State: AOJu0Yz6IhPNQcOEwzGeiAtq5gFeOg1QLc7e4XCdvCMYPP97I9q1QNXA cd512Uyg9fjevwoxmyGvZainQ3n7SlSekh3sNxsr+uiah7WG6HQUp0GpwGw73gU= X-Google-Smtp-Source: AGHT+IFkEwGkKx9+73RNmW51qCEsfEWtOnCXwQkjjQSJhJM1mkeMJgUXtFTV7L7H9d6fB4ZSdB8GQA== X-Received: by 2002:a05:6a00:22d4:b0:70d:ca45:a004 with SMTP id d2e1a72fcca58-7106cfcf88bmr14103619b3a.13.1722929662250; Tue, 06 Aug 2024 00:34:22 -0700 (PDT) Received: from anup-ubuntu-vm.localdomain ([223.185.134.124]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7106ed2de28sm6455011b3a.191.2024.08.06.00.34.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Aug 2024 00:34:21 -0700 (PDT) From: Anup Patel To: Atish Patra Cc: Andrew Jones , Anup Patel , opensbi@lists.infradead.org, Rahul Pathak , Himanshu Chauhan , Anup Patel Subject: [PATCH 13/16] lib: sbi: Add SBI Message Proxy (MPXY) framework Date: Tue, 6 Aug 2024 13:03:35 +0530 Message-Id: <20240806073338.1856901-14-apatel@ventanamicro.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240806073338.1856901-1-apatel@ventanamicro.com> References: <20240806073338.1856901-1-apatel@ventanamicro.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240806_003423_860480_F6D7AA59 X-CRM114-Status: GOOD ( 23.11 ) 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: From: Rahul Pathak Introduce SBI Message Proxy (MPXY) framework which allows platform specific code or drivers to register message protocol specific channels. This framework enables the supervisor software to send messages belonging to different message protocols via OpenSBI firmware. 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:433 listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -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 From: Rahul Pathak Introduce SBI Message Proxy (MPXY) framework which allows platform specific code or drivers to register message protocol specific channels. This framework enables the supervisor software to send messages belonging to different message protocols via OpenSBI firmware. Signed-off-by: Rahul Pathak Co-developed-by: Himanshu Chauhan Signed-off-by: Himanshu Chauhan Co-developed-by: Anup Patel Signed-off-by: Anup Patel --- include/sbi/sbi_ecall_interface.h | 3 + include/sbi/sbi_error.h | 14 +- include/sbi/sbi_mpxy.h | 181 +++++++++ include/sbi/sbi_platform.h | 17 + lib/sbi/objects.mk | 1 + lib/sbi/sbi_init.c | 6 + lib/sbi/sbi_mpxy.c | 644 ++++++++++++++++++++++++++++++ 7 files changed, 860 insertions(+), 6 deletions(-) create mode 100644 include/sbi/sbi_mpxy.h create mode 100644 lib/sbi/sbi_mpxy.c diff --git a/include/sbi/sbi_ecall_interface.h b/include/sbi/sbi_ecall_interface.h index e9a81677..6b993b18 100644 --- a/include/sbi/sbi_ecall_interface.h +++ b/include/sbi/sbi_ecall_interface.h @@ -428,6 +428,9 @@ enum sbi_sse_state { #define SBI_ERR_NO_SHMEM -9 #define SBI_ERR_INVALID_STATE -10 #define SBI_ERR_BAD_RANGE -11 +#define SBI_ERR_NOT_IMPLEMENTED -12 +#define SBI_ERR_TIMEOUT -13 +#define SBI_ERR_IO -14 #define SBI_LAST_ERR SBI_ERR_BAD_RANGE diff --git a/include/sbi/sbi_error.h b/include/sbi/sbi_error.h index fb78bf62..173923fb 100644 --- a/include/sbi/sbi_error.h +++ b/include/sbi/sbi_error.h @@ -26,16 +26,18 @@ #define SBI_ENO_SHMEM SBI_ERR_NO_SHMEM #define SBI_EINVALID_STATE SBI_ERR_INVALID_STATE #define SBI_EBAD_RANGE SBI_ERR_BAD_RANGE +#define SBI_ENOTIMPL SBI_ERR_NOT_IMPLEMENTED +#define SBI_ETIMEOUT SBI_ERR_TIMEOUT +#define SBI_EIO SBI_ERR_IO #define SBI_ENODEV -1000 #define SBI_ENOSYS -1001 #define SBI_ETIMEDOUT -1002 -#define SBI_EIO -1003 -#define SBI_EILL -1004 -#define SBI_ENOSPC -1005 -#define SBI_ENOMEM -1006 -#define SBI_EUNKNOWN -1007 -#define SBI_ENOENT -1008 +#define SBI_EILL -1003 +#define SBI_ENOSPC -1004 +#define SBI_ENOMEM -1005 +#define SBI_EUNKNOWN -1006 +#define SBI_ENOENT -1007 /* clang-format on */ diff --git a/include/sbi/sbi_mpxy.h b/include/sbi/sbi_mpxy.h new file mode 100644 index 00000000..5e7935e3 --- /dev/null +++ b/include/sbi/sbi_mpxy.h @@ -0,0 +1,181 @@ +/* + * SPDX-License-Identifier: BSD-2-Clause + * + * Copyright (c) 2024 Ventana Micro Systems Inc. + * + * Authors: + * Rahul Pathak + */ + +#ifndef __SBI_MPXY_H__ +#define __SBI_MPXY_H__ + +#include + +struct sbi_scratch; + +#define SBI_MPXY_MSGPROTO_VERSION(Major, Minor) ((Major << 16) | Minor) + +/** Channel Capability - Events State */ +#define CAP_EVENTSSTATE_POS 2 +#define CAP_EVENTSSTATE_MASK (1U << CAP_EVENTSSTATE_POS) + +/** Helpers to enable/disable channel capability bits + * _c: capability variable + * _m: capability mask + */ +#define CAP_ENABLE(_c, _m) INSERT_FIELD(_c, _m, 1) +#define CAP_DISABLE(_c, _m) INSERT_FIELD(_c, _m, 0) +#define CAP_GET(_c, _m) EXTRACT_FIELD(_c, _m) + +enum sbi_mpxy_attr_id { + /* Standard channel attributes managed by MPXY framework */ + SBI_MPXY_ATTR_MSG_PROT_ID = 0x00000000, + SBI_MPXY_ATTR_MSG_PROT_VER = 0x00000001, + SBI_MPXY_ATTR_MSG_MAX_LEN = 0x00000002, + SBI_MPXY_ATTR_MSG_SEND_TIMEOUT = 0x00000003, + SBI_MPXY_ATTR_CHANNEL_CAPABILITY = 0x00000004, + SBI_MPXY_ATTR_MSI_CONTROL = 0x00000005, + SBI_MPXY_ATTR_MSI_ADDR_LO = 0x00000006, + SBI_MPXY_ATTR_MSI_ADDR_HI = 0x00000007, + SBI_MPXY_ATTR_MSI_DATA = 0x00000008, + SBI_MPXY_ATTR_SSE_EVENT_ID = 0x00000009, + SBI_MPXY_ATTR_EVENTS_STATE_CONTROL = 0x0000000A, + SBI_MPXY_ATTR_STD_ATTR_MAX_IDX, + /* Message protocol specific attributes, managed by + * message protocol driver */ + SBI_MPXY_ATTR_MSGPROTO_ATTR_START = 0x80000000, + SBI_MPXY_ATTR_MSGPROTO_ATTR_END = 0xffffffff +}; + +/** + * SBI MPXY Message Protocol IDs + */ +enum sbi_mpxy_msgproto_id { + SBI_MPXY_MSGPROTO_RPMI_ID = 0x0, +}; + +enum SBI_EXT_MPXY_SHMEM_FLAGS { + SBI_EXT_MPXY_SHMEM_FLAG_OVERWRITE = 0b00, + SBI_EXT_MPXY_SHMEM_FLAG_OVERWRITE_RETURN = 0b01, + SBI_EXT_MPXY_SHMEM_FLAG_MAX_IDX +}; + +struct sbi_mpxy_msi_info { + /* MSI target address low 32-bit */ + u32 msi_addr_lo; + /* MSI target address high 32-bit */ + u32 msi_addr_hi; + /* MSI data */ + u32 msi_data; +}; + +/** + * Channel attributes. + * NOTE: The sequence of attribute fields are as per the + * defined sequence in the attribute table in spec(or as + * per the enum sbi_mpxy_attr_id). + */ +struct sbi_mpxy_channel_attrs { + /* Message protocol ID */ + u32 msg_proto_id; + /* Message protocol Version */ + u32 msg_proto_version; + /* Message protocol maximum message data length(bytes) */ + u32 msg_data_maxlen; + /* Message protocol message send timeout + * in microseconds */ + u32 msg_send_timeout; + /* Bit array for channel capabilities */ + u32 capability; + u32 msi_control; + struct sbi_mpxy_msi_info msi_info; + u32 sse_event_id; + /* Events State Control */ + u32 eventsstate_ctrl; +}; + +/** A Message proxy channel accessible through SBI interface */ +struct sbi_mpxy_channel { + /** List head to a set of channels */ + struct sbi_dlist head; + u32 channel_id; + struct sbi_mpxy_channel_attrs attrs; + + /** + * Read message protocol attributes + * NOTE: inmem requires little-endian byte-ordering + */ + int (*read_attributes)(struct sbi_mpxy_channel *channel, + u32 *outmem, + u32 base_attr_id, + u32 attr_count); + + /** + * Write message protocol attributes + * NOTE: outmem requires little-endian byte-ordering + */ + int (*write_attributes)(struct sbi_mpxy_channel *channel, + u32 *inmem, + u32 base_attr_id, + u32 attr_count); + /** + * Send a message over a channel + * NOTE: For message without response, resp_len == NULL + * msgbuf requires little-endian byte-ordering + */ + int (*send_message)(struct sbi_mpxy_channel *channel, + u32 msg_id, void *msgbuf, u32 msg_len, + void *respbuf, u32 resp_max_len, + unsigned long *resp_len); + + /** + * Get notifications events if supported on a channel + * NOTE: eventsbuf requires little-endian byte-ordering + */ + int (*get_notification_events)(struct sbi_mpxy_channel *channel, + void *eventsbuf, u32 bufsize, + unsigned long *events_len); + + void (*switch_eventsstate)(u32 enable); +}; + +/** Register a Message proxy channel */ +int sbi_mpxy_register_channel(struct sbi_mpxy_channel *channel); + +/** Initialize Message proxy subsystem */ +int sbi_mpxy_init(struct sbi_scratch *scratch); + +/** Check if some Message proxy channel is available */ +bool sbi_mpxy_channel_available(void); + +/** Set Message proxy shared memory on the calling HART */ +int sbi_mpxy_set_shmem(unsigned long shmem_size, + unsigned long shmem_phys_lo, + unsigned long shmem_phys_hi, + unsigned long flags); + +/** Get channel IDs list */ +int sbi_mpxy_get_channel_ids(u32 start_index); + +/** Read MPXY channel attributes */ +int sbi_mpxy_read_attrs(u32 channel_id, u32 base_attr_id, u32 attr_count); + +/** Write MPXY channel attributes */ +int sbi_mpxy_write_attrs(u32 channel_id, u32 base_attr_id, u32 attr_count); + +/** + * Send a message over a MPXY channel. + * For message with response the resp_data_len must point + * to valid buffer. + * For message without response the resp_data_len must be NULL + **/ +int sbi_mpxy_send_message(u32 channel_id, u8 msg_id, + unsigned long msg_data_len, + unsigned long *resp_data_len); + +/** Get Message proxy notification events */ +int sbi_mpxy_get_notification_events(u32 channel_id, + unsigned long *events_len); + +#endif diff --git a/include/sbi/sbi_platform.h b/include/sbi/sbi_platform.h index 7b3ac4bf..91996888 100644 --- a/include/sbi/sbi_platform.h +++ b/include/sbi/sbi_platform.h @@ -132,6 +132,9 @@ struct sbi_platform_operations { /** Exit platform timer for current HART */ void (*timer_exit)(void); + /** Initialize the platform Message Proxy(MPXY) driver */ + int (*mpxy_init)(void); + /** Check if SBI vendor extension is implemented or not */ bool (*vendor_ext_check)(void); /** platform specific SBI extension implementation provider */ @@ -627,6 +630,20 @@ static inline void sbi_platform_timer_exit(const struct sbi_platform *plat) sbi_platform_ops(plat)->timer_exit(); } +/** + * Initialize the platform Message Proxy drivers + * + * @param plat pointer to struct sbi_platform + * + * @return 0 on success and negative error code on failure + */ +static inline int sbi_platform_mpxy_init(const struct sbi_platform *plat) +{ + if (plat && sbi_platform_ops(plat)->mpxy_init) + return sbi_platform_ops(plat)->mpxy_init(); + return 0; +} + /** * Check if SBI vendor extension is implemented or not. * diff --git a/lib/sbi/objects.mk b/lib/sbi/objects.mk index 535aa709..2cea93b9 100644 --- a/lib/sbi/objects.mk +++ b/lib/sbi/objects.mk @@ -81,6 +81,7 @@ libsbi-objs-y += sbi_irqchip.o libsbi-objs-y += sbi_platform.o libsbi-objs-y += sbi_pmu.o libsbi-objs-y += sbi_dbtr.o +libsbi-objs-y += sbi_mpxy.o libsbi-objs-y += sbi_scratch.o libsbi-objs-y += sbi_sse.o libsbi-objs-y += sbi_string.o diff --git a/lib/sbi/sbi_init.c b/lib/sbi/sbi_init.c index d80efe97..bac55e79 100644 --- a/lib/sbi/sbi_init.c +++ b/lib/sbi/sbi_init.c @@ -24,6 +24,7 @@ #include #include #include +#include #include #include #include @@ -311,6 +312,11 @@ static void __noreturn init_coldboot(struct sbi_scratch *scratch, u32 hartid) sbi_hart_hang(); } + rc = sbi_mpxy_init(scratch); + if (rc) { + sbi_printf("%s: mpxy init failed (error %d)\n", __func__, rc); + sbi_hart_hang(); + } /* * Note: Finalize domains after HSM initialization so that we * can startup non-root domains. diff --git a/lib/sbi/sbi_mpxy.c b/lib/sbi/sbi_mpxy.c new file mode 100644 index 00000000..53adf510 --- /dev/null +++ b/lib/sbi/sbi_mpxy.c @@ -0,0 +1,644 @@ +/* + * SPDX-License-Identifier: BSD-2-Clause + * + * Copyright (c) 2024 Ventana Micro Systems Inc. + * + * Authors: + * Rahul Pathak + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/** Offset of pointer to MPXY state in scratch space */ +static unsigned long mpxy_state_offset; + +/** List of MPXY proxy channels */ +static SBI_LIST_HEAD(mpxy_channel_list); + +/** Invalid Physical Address(all bits 1) */ +#define INVALID_ADDR (-1U) + +/** MPXY Attribute size in bytes */ +#define ATTR_SIZE (4) + +/** Channel Capability - MSI */ +#define CAP_MSI_POS 0 +#define CAP_MSI_MASK (1U << CAP_MSI_POS) +/** Channel Capability - SSE */ +#define CAP_SSE_POS 1 +#define CAP_SSE_MASK (1U << CAP_SSE_POS) + +#if __riscv_xlen == 64 +#define SHMEM_PHYS_ADDR(_hi, _lo) (_lo) +#elif __riscv_xlen == 32 +#define SHMEM_PHYS_ADDR(_hi, _lo) (((u64)(_hi) << 32) | (_lo)) +#else +#error "Undefined XLEN" +#endif + +/** Per hart shared memory */ +struct mpxy_shmem { + unsigned long shmem_size; + unsigned long shmem_addr_lo; + unsigned long shmem_addr_hi; +}; + +struct mpxy_state { + /* MSI support in MPXY */ + bool msi_avail; + /* SSE support in MPXY */ + bool sse_avail; + /* MPXY Shared memory details */ + struct mpxy_shmem shmem; +}; + +/** Disable hart shared memory */ +static inline void sbi_mpxy_shmem_disable(struct mpxy_state *rs) +{ + rs->shmem.shmem_size = 0; + rs->shmem.shmem_addr_lo = INVALID_ADDR; + rs->shmem.shmem_addr_hi = INVALID_ADDR; +} + +/** Check if shared memory is already setup on hart */ +static inline bool mpxy_shmem_enabled(struct mpxy_state *rs) +{ + return (rs->shmem.shmem_addr_lo == INVALID_ADDR + && rs->shmem.shmem_addr_hi == INVALID_ADDR) ? + false : true; +} + +/** Get hart shared memory base address */ +static inline void *hart_shmem_base(struct mpxy_state *rs) +{ + return (void *)(unsigned long)SHMEM_PHYS_ADDR(rs->shmem.shmem_addr_hi, + rs->shmem.shmem_addr_lo); +} + + +/** Make sure all attributes are packed for direct memcpy in ATTR_READ */ +#define assert_field_offset(field, attr_offset) \ + _Static_assert( \ + ((offsetof(struct sbi_mpxy_channel_attrs, field)) / \ + sizeof(u32)) == attr_offset, \ + "field " #field \ + " from struct sbi_mpxy_channel_attrs invalid offset, expected " #attr_offset) + +assert_field_offset(msg_proto_id, SBI_MPXY_ATTR_MSG_PROT_ID); +assert_field_offset(msg_proto_version, SBI_MPXY_ATTR_MSG_PROT_VER); +assert_field_offset(msg_data_maxlen, SBI_MPXY_ATTR_MSG_MAX_LEN); +assert_field_offset(msg_send_timeout, SBI_MPXY_ATTR_MSG_SEND_TIMEOUT); +assert_field_offset(capability, SBI_MPXY_ATTR_CHANNEL_CAPABILITY); +assert_field_offset(msi_control, SBI_MPXY_ATTR_MSI_CONTROL); +assert_field_offset(msi_info.msi_addr_lo, SBI_MPXY_ATTR_MSI_ADDR_LO); +assert_field_offset(msi_info.msi_addr_hi, SBI_MPXY_ATTR_MSI_ADDR_HI); +assert_field_offset(msi_info.msi_data, SBI_MPXY_ATTR_MSI_DATA); +assert_field_offset(sse_event_id, SBI_MPXY_ATTR_SSE_EVENT_ID); +assert_field_offset(eventsstate_ctrl, SBI_MPXY_ATTR_EVENTS_STATE_CONTROL); + +/** + * Check if the attribute is a standard attribute or + * a message protocol specific attribute + * attr_id[31] = 0 for standard + * attr_id[31] = 1 for message protocol specific + */ +static inline bool mpxy_is_std_attr(u32 attr_id) +{ + return (attr_id >> 31) ? false : true; +} + +/** Find channel_id in registered channels list */ +static struct sbi_mpxy_channel *mpxy_find_channel(u32 channel_id) +{ + struct sbi_mpxy_channel *channel; + + sbi_list_for_each_entry(channel, &mpxy_channel_list, head) + if (channel->channel_id == channel_id) + return channel; + + return NULL; +} + +/** Copy attributes word size */ +static void mpxy_copy_std_attrs(u32 *outmem, u32 *inmem, u32 count) +{ + int idx; + for (idx = 0; idx < count; idx++) + outmem[idx] = cpu_to_le32(inmem[idx]); +} + +/** Check if any channel is registered with mpxy framework */ +bool sbi_mpxy_channel_available(void) +{ + return sbi_list_empty(&mpxy_channel_list) ? false : true; +} + +static void mpxy_std_attrs_init(struct sbi_mpxy_channel *channel) +{ + struct mpxy_state *rs = + sbi_scratch_thishart_offset_ptr(mpxy_state_offset); + + /* Reset values */ + channel->attrs.msi_control = 0; + channel->attrs.msi_info.msi_data = 0; + channel->attrs.msi_info.msi_addr_lo = INVALID_ADDR; + channel->attrs.msi_info.msi_addr_hi = INVALID_ADDR; + channel->attrs.capability = 0; + channel->attrs.eventsstate_ctrl = 0; + + /** + * Check if MSI or SSE available for notification interrrupt. + * Priority given to MSI if both MSI and SSE are avaialble. + */ + if (rs->msi_avail) + channel->attrs.capability = + CAP_ENABLE(channel->attrs.capability, CAP_MSI_MASK); + else if (rs->sse_avail) { + channel->attrs.capability = + CAP_ENABLE(channel->attrs.capability, CAP_SSE_MASK); + /* TODO: Assign SSE EVENT_ID for the channel */ + } + + /** + * Enable Events State in channel capability if message protocol + * provides callback to switch + */ + if (channel->switch_eventsstate) + channel->attrs.capability = + CAP_ENABLE(channel->attrs.capability, + CAP_EVENTSSTATE_MASK); +} + +/** + * Register a channel with MPXY framework. + * Called by message protocol drivers + */ +int sbi_mpxy_register_channel(struct sbi_mpxy_channel *channel) +{ + if (!channel) + return SBI_EINVAL; + + if (mpxy_find_channel(channel->channel_id)) + return SBI_EALREADY; + + /* Initialize channel specific attributes */ + mpxy_std_attrs_init(channel); + + SBI_INIT_LIST_HEAD(&channel->head); + sbi_list_add_tail(&channel->head, &mpxy_channel_list); + + return SBI_OK; +} + +int sbi_mpxy_init(struct sbi_scratch *scratch) +{ + mpxy_state_offset = sbi_scratch_alloc_type_offset(struct mpxy_state); + if (!mpxy_state_offset) + return SBI_ENOMEM; + + /** TODO: Proper support for checking msi support from platform. + * Currently disable msi and sse and use polling + **/ + struct mpxy_state *rs = + sbi_scratch_thishart_offset_ptr(mpxy_state_offset); + rs->msi_avail = false; + rs->sse_avail = false; + + sbi_mpxy_shmem_disable(rs); + + return sbi_platform_mpxy_init(sbi_platform_ptr(scratch)); +} + +int sbi_mpxy_set_shmem(unsigned long shmem_size, unsigned long shmem_phys_lo, + unsigned long shmem_phys_hi, unsigned long flags) +{ + struct mpxy_state *rs = + sbi_scratch_thishart_offset_ptr(mpxy_state_offset); + unsigned long *ret_buf; + + shmem_size = lle_to_cpu(shmem_size); + shmem_phys_hi = lle_to_cpu(shmem_phys_hi); + shmem_phys_lo = lle_to_cpu(shmem_phys_lo); + + /** Disable shared memory if both hi and lo have all bit 1s */ + if (shmem_phys_lo == INVALID_ADDR && + shmem_phys_hi == INVALID_ADDR) { + sbi_mpxy_shmem_disable(rs); + return SBI_SUCCESS; + } + + if (flags >= SBI_EXT_MPXY_SHMEM_FLAG_MAX_IDX) + return SBI_ERR_INVALID_PARAM; + + /** Check shared memory size and address aligned to 4K Page */ + if (!shmem_size || (shmem_size & ~PAGE_MASK) || + (shmem_phys_lo & ~PAGE_MASK)) + return SBI_ERR_INVALID_PARAM; + + if (!sbi_domain_check_addr_range(sbi_domain_thishart_ptr(), + SHMEM_PHYS_ADDR(shmem_phys_hi, shmem_phys_lo), + shmem_size, PRV_S, + SBI_DOMAIN_READ | SBI_DOMAIN_WRITE)) + return SBI_ERR_INVALID_ADDRESS; + + /** Save the current shmem details in new shmem region */ + if (flags == SBI_EXT_MPXY_SHMEM_FLAG_OVERWRITE_RETURN) { + ret_buf = (unsigned long *)(ulong)SHMEM_PHYS_ADDR(shmem_phys_hi, shmem_phys_lo); + ret_buf[0] = cpu_to_lle(rs->shmem.shmem_size); + ret_buf[1] = cpu_to_lle(rs->shmem.shmem_addr_lo); + ret_buf[2] = cpu_to_lle(rs->shmem.shmem_addr_hi); + } + + /** Setup the new shared memory */ + rs->shmem.shmem_size = shmem_size; + rs->shmem.shmem_addr_lo = shmem_phys_lo; + rs->shmem.shmem_addr_hi = shmem_phys_hi; + + return SBI_SUCCESS; +} + +int sbi_mpxy_get_channel_ids(u32 start_index) +{ + u32 node_index = 0, node_ret = 0; + u32 remaining, returned, max_channelids; + u32 channels_count = 0; + u32 *shmem_base; + struct sbi_mpxy_channel *channel; + + /* Check if the shared memory is being setup or not. */ + struct mpxy_state *rs = + sbi_scratch_thishart_offset_ptr(mpxy_state_offset); + + if (!mpxy_shmem_enabled(rs)) + return SBI_ERR_NO_SHMEM; + + sbi_list_for_each_entry(channel, &mpxy_channel_list, head) + channels_count += 1; + + if (start_index > channels_count) + return SBI_ERR_INVALID_PARAM; + + shmem_base = hart_shmem_base(rs); + sbi_hart_map_saddr((unsigned long)hart_shmem_base(rs), + rs->shmem.shmem_size); + + /** number of channel ids which can be stored in shmem adjusting + * for remaining and returned fields */ + max_channelids = (rs->shmem.shmem_size / sizeof(u32)) - 2; + /* total remaining from the start index */ + remaining = channels_count - start_index; + /* how many can be returned */ + returned = (remaining > max_channelids)? max_channelids : remaining; + + // Iterate over the list of channels to get the channel ids. + sbi_list_for_each_entry(channel, &mpxy_channel_list, head) { + if (node_index >= start_index && + node_index < (start_index + returned)) { + shmem_base[2 + node_ret] = cpu_to_le32(channel->channel_id); + node_ret += 1; + } + + node_index += 1; + } + + /* final remaininig channel ids */ + remaining = channels_count - (start_index + returned); + + shmem_base[0] = cpu_to_le32(remaining); + shmem_base[1] = cpu_to_le32(returned); + + sbi_hart_unmap_saddr(); + + return SBI_SUCCESS; +} + +int sbi_mpxy_read_attrs(u32 channel_id, u32 base_attr_id, u32 attr_count) +{ + int ret = SBI_SUCCESS; + u32 *attr_ptr, end_id; + void *shmem_base; + + struct mpxy_state *rs = + sbi_scratch_thishart_offset_ptr(mpxy_state_offset); + + if (!mpxy_shmem_enabled(rs)) + return SBI_ERR_NO_SHMEM; + + struct sbi_mpxy_channel *channel = mpxy_find_channel(channel_id); + if (!channel) + return SBI_ERR_NOT_SUPPORTED; + + /* base attribute id is not a defined std attribute or reserved */ + if (base_attr_id >= SBI_MPXY_ATTR_STD_ATTR_MAX_IDX && + base_attr_id < SBI_MPXY_ATTR_MSGPROTO_ATTR_START) + return SBI_ERR_INVALID_PARAM; + + /* Sanity check for base_attr_id and attr_count */ + if (!attr_count || (attr_count > (rs->shmem.shmem_size / ATTR_SIZE))) + return SBI_ERR_INVALID_PARAM; + + shmem_base = hart_shmem_base(rs); + end_id = base_attr_id + attr_count - 1; + + sbi_hart_map_saddr((unsigned long)hart_shmem_base(rs), + rs->shmem.shmem_size); + + /* Standard attributes range check */ + if (mpxy_is_std_attr(base_attr_id)) { + if (end_id >= SBI_MPXY_ATTR_STD_ATTR_MAX_IDX) { + ret = SBI_EBAD_RANGE; + goto out; + } + + attr_ptr = (u32 *)&channel->attrs; + mpxy_copy_std_attrs((u32 *)shmem_base, &attr_ptr[base_attr_id], + attr_count); + } else { + /** + * Even if the message protocol driver does not provide + * read attribute callback, return bad range error instead + * of not supported to let client distinguish it from channel + * id not supported. + * Check the complate range supported for message protocol + * attributes. Actual supported attributes will be checked + * by the message protocol driver. + */ + if (!channel->read_attributes || + end_id > SBI_MPXY_ATTR_MSGPROTO_ATTR_END) { + ret = SBI_ERR_BAD_RANGE; + goto out; + } + + /** + * Function expected to return the SBI supported errors + * At this point both base attribute id and only the mpxy + * supported range been verified. Platform callback must + * check if the range requested is supported by message + * protocol driver */ + ret = channel->read_attributes(channel, + (u32 *)shmem_base, + base_attr_id, attr_count); + } +out: + sbi_hart_unmap_saddr(); + return ret; +} + +/** + * Verify the channel standard attribute wrt to write permission + * and the value to be set if valid or not. + * Only attributes needs to be checked which are defined Read/Write + * permission. Other with Readonly permission will result in error. + * + * Attributes values to be written must also be checked because + * before writing a range of attributes, we need to make sure that + * either complete range of attributes is written successfully or not + * at all. + */ +static int mpxy_check_write_std_attr(struct sbi_mpxy_channel *channel, + u32 attr_id, u32 attr_val) +{ + int ret = SBI_SUCCESS; + struct sbi_mpxy_channel_attrs *attrs = &channel->attrs; + + switch(attr_id) { + case SBI_MPXY_ATTR_MSI_CONTROL: + if (attr_val > 1) + ret = SBI_ERR_INVALID_PARAM; + if (attr_val == 1 && + (attrs->msi_info.msi_addr_lo == INVALID_ADDR) && + (attrs->msi_info.msi_addr_hi == INVALID_ADDR)) + ret = SBI_ERR_DENIED; + break; + case SBI_MPXY_ATTR_MSI_ADDR_LO: + case SBI_MPXY_ATTR_MSI_ADDR_HI: + case SBI_MPXY_ATTR_MSI_DATA: + ret = SBI_SUCCESS; + break; + case SBI_MPXY_ATTR_EVENTS_STATE_CONTROL: + if (attr_val > 1) + ret = SBI_ERR_INVALID_PARAM; + break; + default: + /** All RO access attributes falls under default */ + ret = SBI_ERR_BAD_RANGE; + }; + + return ret; +} + +/** + * Write the attribute value + */ +static void mpxy_write_std_attr(struct sbi_mpxy_channel *channel, u32 attr_id, + u32 attr_val) +{ + struct mpxy_state *rs = + sbi_scratch_thishart_offset_ptr(mpxy_state_offset); + + struct sbi_mpxy_channel_attrs *attrs = &channel->attrs; + + switch(attr_id) { + case SBI_MPXY_ATTR_MSI_CONTROL: + if (rs->msi_avail && attr_val <= 1) + attrs->msi_control = attr_val; + break; + case SBI_MPXY_ATTR_MSI_ADDR_LO: + if (rs->msi_avail) + attrs->msi_info.msi_addr_lo = attr_val; + break; + case SBI_MPXY_ATTR_MSI_ADDR_HI: + if (rs->msi_avail) + attrs->msi_info.msi_addr_hi = attr_val; + break; + case SBI_MPXY_ATTR_MSI_DATA: + if (rs->msi_avail) + attrs->msi_info.msi_data = attr_val; + break; + case SBI_MPXY_ATTR_EVENTS_STATE_CONTROL: + if (CAP_GET(attrs->capability, CAP_EVENTSSTATE_MASK)) { + attrs->eventsstate_ctrl = attr_val; + /* call message protocol callback */ + channel->switch_eventsstate(attr_val); + } + + break; + }; +} + +int sbi_mpxy_write_attrs(u32 channel_id, u32 base_attr_id, u32 attr_count) +{ + int ret, mem_idx; + void *shmem_base; + u32 *mem_ptr, attr_id, end_id, attr_val; + + struct mpxy_state *rs = + sbi_scratch_thishart_offset_ptr(mpxy_state_offset); + + if (!mpxy_shmem_enabled(rs)) + return SBI_ERR_NO_SHMEM; + + struct sbi_mpxy_channel *channel = mpxy_find_channel(channel_id); + if (!channel) + return SBI_ERR_NOT_SUPPORTED; + + /* base attribute id is not a defined std attribute or reserved */ + if (base_attr_id >= SBI_MPXY_ATTR_STD_ATTR_MAX_IDX && + base_attr_id < SBI_MPXY_ATTR_MSGPROTO_ATTR_START) + return SBI_ERR_INVALID_PARAM; + + /* Sanity check for base_attr_id and attr_count */ + if (!attr_count || (attr_count > (rs->shmem.shmem_size / ATTR_SIZE))) + return SBI_ERR_INVALID_PARAM; + + shmem_base = hart_shmem_base(rs); + end_id = base_attr_id + attr_count - 1; + + sbi_hart_map_saddr((unsigned long)shmem_base, rs->shmem.shmem_size); + + mem_ptr = (u32 *)shmem_base; + + if (mpxy_is_std_attr(base_attr_id)) { + if (end_id >= SBI_MPXY_ATTR_STD_ATTR_MAX_IDX) { + ret = SBI_ERR_BAD_RANGE; + goto out; + } + + /** Verify the attribute ids range and values */ + mem_idx = 0; + for (attr_id = base_attr_id; attr_id <= end_id; attr_id++) { + attr_val = le32_to_cpu(mem_ptr[mem_idx++]); + ret = mpxy_check_write_std_attr(channel, + attr_id, attr_val); + if (ret) + goto out; + } + + /* Write the attribute ids values */ + mem_idx = 0; + for (attr_id = base_attr_id; attr_id <= end_id; attr_id++) { + attr_val = le32_to_cpu(mem_ptr[mem_idx++]); + mpxy_write_std_attr(channel, attr_id, attr_val); + } + } else {/** + * Message protocol specific attributes: + * If attributes belong to message protocol, they + * are simply passed to the message protocol driver + * callback after checking the valid range. + * Attributes contiguous range & permission & other checks + * are done by the mpxy and message protocol glue layer. + */ + /** + * Even if the message protocol driver does not provide + * write attribute callback, return bad range error instead + * of not supported to let client distinguish it from channel + * id not supported. + */ + if (!channel->write_attributes || + end_id > SBI_MPXY_ATTR_MSGPROTO_ATTR_END) { + ret = SBI_ERR_BAD_RANGE; + goto out; + } + + /** + * Function expected to return the SBI supported errors + * At this point both base attribute id and only the mpxy + * supported range been verified. Platform callback must + * check if the range requested is supported by message + * protocol driver */ + ret = channel->write_attributes(channel, + (u32 *)shmem_base, + base_attr_id, attr_count); + } +out: + sbi_hart_unmap_saddr(); + return ret; +} + +int sbi_mpxy_send_message(u32 channel_id, u8 msg_id, unsigned long msg_data_len, + unsigned long *resp_data_len) +{ + int ret; + void *msgbuf, *shmem_base; + + struct mpxy_state *rs = + sbi_scratch_thishart_offset_ptr(mpxy_state_offset); + + if (!mpxy_shmem_enabled(rs)) + return SBI_ERR_NO_SHMEM; + + struct sbi_mpxy_channel *channel = mpxy_find_channel(channel_id); + if (!channel) + return SBI_ERR_NOT_SUPPORTED; + + if (!channel->send_message) + return SBI_ERR_NOT_IMPLEMENTED; + + if (msg_data_len > rs->shmem.shmem_size || + msg_data_len > channel->attrs.msg_data_maxlen) + return SBI_ERR_INVALID_PARAM; + + shmem_base = hart_shmem_base(rs); + sbi_hart_map_saddr((unsigned long)shmem_base, rs->shmem.shmem_size); + msgbuf = shmem_base; + + ret = channel->send_message(channel, msg_id, msgbuf, msg_data_len, + resp_data_len ? shmem_base : NULL, + resp_data_len ? rs->shmem.shmem_size : 0, + resp_data_len); + sbi_hart_unmap_saddr(); + if (ret) + return ret; + + if (resp_data_len && + (*resp_data_len > rs->shmem.shmem_size || + *resp_data_len > channel->attrs.msg_data_maxlen)) + return SBI_ERR_FAILED; + + return SBI_SUCCESS; +} + +int sbi_mpxy_get_notification_events(u32 channel_id, unsigned long *events_len) +{ + int ret; + void *eventsbuf, *shmem_base; + + struct mpxy_state *rs = + sbi_scratch_thishart_offset_ptr(mpxy_state_offset); + + if (!mpxy_shmem_enabled(rs)) + return SBI_ERR_NO_SHMEM; + + struct sbi_mpxy_channel *channel = mpxy_find_channel(channel_id); + if (!channel) + return SBI_ERR_NOT_SUPPORTED; + + if (!channel->get_notification_events) + return SBI_ERR_NOT_IMPLEMENTED; + + shmem_base = hart_shmem_base(rs); + sbi_hart_map_saddr((unsigned long)shmem_base, rs->shmem.shmem_size); + eventsbuf = shmem_base; + ret = channel->get_notification_events(channel, eventsbuf, + rs->shmem.shmem_size, + events_len); + sbi_hart_unmap_saddr(); + + if (ret) + return ret; + + if (*events_len > rs->shmem.shmem_size) + return SBI_ERR_FAILED; + + return SBI_SUCCESS; +} From patchwork Tue Aug 6 07:33:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 1969366 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=vQ7MfCIB; 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=aSa9OOpJ; 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 4WdQ7C1DVJz1yYD for ; Tue, 6 Aug 2024 17:34:47 +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=NKEFtRxOQABolHV621/SxqhcI0g7LA/vnVkv5botvmM=; b=vQ7MfCIBwJEXb9 vrz3zi1VaQfF9DwpiLrp1TVpfYVH2Fld43NKPRMbIT7lC9Mmjr9K/qPmv6AWTyO0Y/eFFZ2T8tWWJ NIRggvb5RXrHT6awhb+wbqM9fFHUG52MhcRKAW288M4+6ELBglDN54CIaZb9sPvz6yGtF9xrM2SuI QFcp6lSFYhMDt93MAJp5Lzt43ZydN+RK2rw70kWyrcV3jQ66Z0sLHjrwpDOnvivmdfMvGLsjNIKK5 4egP61Dk6/M1vpBdjEqjkWSHCkrokJdd7Spp1Wz7FUYPdSTAM8kUb/fOIs1jQaw7J8LkoqSOWEXRz 80ueakwvolzKYIPBH7Mg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sbEiM-00000000oFu-2KfV; Tue, 06 Aug 2024 07:34:38 +0000 Received: from mail-pf1-x42e.google.com ([2607:f8b0:4864:20::42e]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sbEiA-00000000o6z-0Af2 for opensbi@lists.infradead.org; Tue, 06 Aug 2024 07:34:34 +0000 Received: by mail-pf1-x42e.google.com with SMTP id d2e1a72fcca58-70d399da0b5so267489b3a.3 for ; Tue, 06 Aug 2024 00:34:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1722929665; x=1723534465; 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=DTMgQSIF0PsA1GYIwrb/EZG4t4iBAxlXpBWeON010ig=; b=aSa9OOpJAYzB0S9/8MyaUlJegIeBjTvqo/5yldvwBHGWequzf0uxChk4kK6RMmI033 L0hhAVSXOvnRSnkKgIWks475Dng9SrOlLizbLcFh8uYVN8cConiurVO59Wd2WpqlyuRT JSVGi1LJGYy3vq7k8NVlwSkZtEZ6+614OSHJ/G3zHgdwvMF6Ktpt5m3g/H0UbwEeijdN Go9IuX1V4Sn4DyqSAfyMMt3CaoPknYAAyNCa5fCGJn4QClB/ihIVGy41oA6qQvg/WGGA e26gMwB7n9n2nsJbybVD46Q31ddV5rfei+C2dlOcj+nKDFmC2QrduMxLhLL7r/pCEh6D QzFw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722929665; x=1723534465; 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=DTMgQSIF0PsA1GYIwrb/EZG4t4iBAxlXpBWeON010ig=; b=BhZm0sBxoI36cRZAQB7QFaL8/DE1ZUS3hylL1jZXoS7xDlh61XcmaNhJY471RZF9Ev KGjyhjMg0H9yhhCi/AXWEPeyiHabZM9bfBU8HxYhK4+hNccsBksDz4GJvJx0UrjbNMzE glTQHIWYhYstH3TJP87p2kQ3HPftQqLK2LkLJQx0g32DvqlMaXEfsVW8qAgavVJPrzTR IWQZ1H6EvEP5dvfiaq5vriTFodE2a5pMftyl/FpFxw8KJn12RyPcgxXjQgbqU1Jynk4W EL4I1qiSh/yK34/IFZgV9BADjb0JFr6kQIw3fOwD2TVymxYFAYBpTEDphop29ddRdokX Us5Q== X-Forwarded-Encrypted: i=1; AJvYcCWTN/I6+wqHKFiA6CtXPr//9+mnQ6xro4swhILFiUN3bsFI8eqxOUslhxX+8l0lTEgMfpm6D50HuRkJtsgJEiAwTidFBn3GqSyLfyc= X-Gm-Message-State: AOJu0YwED1O77KSxyNA6Y0xgrzfZppaQynqiHCWLUxpp9wP8ohCue4fp J9CvGPzoSrhHrznAUbv2eRRo6SMrh9z/dadEi9+T6Ni2Lf6ZXQQ7mO5OAB56M3M= X-Google-Smtp-Source: AGHT+IGjETU3HoV18fIZENbotBTcXlIvuxQ2KwQPhlwzfyi9A/AqYZ/I2VJ4XrQoOqB5GP2ysl5kLw== X-Received: by 2002:a05:6a20:6a1e:b0:1c4:7dbc:d21a with SMTP id adf61e73a8af0-1c6995d5686mr22111545637.32.1722929665083; Tue, 06 Aug 2024 00:34:25 -0700 (PDT) Received: from anup-ubuntu-vm.localdomain ([223.185.134.124]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7106ed2de28sm6455011b3a.191.2024.08.06.00.34.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Aug 2024 00:34:24 -0700 (PDT) From: Anup Patel To: Atish Patra Cc: Andrew Jones , Anup Patel , opensbi@lists.infradead.org, Anup Patel , Rahul Pathak Subject: [PATCH 14/16] lib: sbi: Implement SBI MPXY extension Date: Tue, 6 Aug 2024 13:03:36 +0530 Message-Id: <20240806073338.1856901-15-apatel@ventanamicro.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240806073338.1856901-1-apatel@ventanamicro.com> References: <20240806073338.1856901-1-apatel@ventanamicro.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240806_003426_378910_EE651D69 X-CRM114-Status: GOOD ( 15.11 ) 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: Implement the SBI MPXY extension which provides an SBI interface to the supervisor software for send messages via MPXY framework. Signed-off-by: Rahul Pathak Co-developed-by: Anup Patel Signed-off-by: Anup Patel --- include/sbi/sbi_ecall_interface.h | [...] 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:42e listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -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 Implement the SBI MPXY extension which provides an SBI interface to the supervisor software for send messages via MPXY framework. Signed-off-by: Rahul Pathak Co-developed-by: Anup Patel Signed-off-by: Anup Patel --- include/sbi/sbi_ecall_interface.h | 10 +++++ lib/sbi/Kconfig | 3 ++ lib/sbi/objects.mk | 3 ++ lib/sbi/sbi_ecall_mpxy.c | 68 +++++++++++++++++++++++++++++++ 4 files changed, 84 insertions(+) create mode 100644 lib/sbi/sbi_ecall_mpxy.c diff --git a/include/sbi/sbi_ecall_interface.h b/include/sbi/sbi_ecall_interface.h index 6b993b18..085b33e7 100644 --- a/include/sbi/sbi_ecall_interface.h +++ b/include/sbi/sbi_ecall_interface.h @@ -35,6 +35,7 @@ #define SBI_EXT_DBTR 0x44425452 #define SBI_EXT_SSE 0x535345 #define SBI_EXT_FWFT 0x46574654 +#define SBI_EXT_MPXY 0x4D505859 /* SBI function IDs for BASE extension*/ #define SBI_EXT_BASE_GET_SPEC_VERSION 0x0 @@ -406,6 +407,15 @@ enum sbi_sse_state { #define SBI_SSE_EVENT_GLOBAL_BIT (1 << 15) #define SBI_SSE_EVENT_PLATFORM_BIT (1 << 14) +/* SBI function IDs for MPXY extension */ +#define SBI_EXT_MPXY_SET_SHMEM 0x0 +#define SBI_EXT_MPXY_GET_CHANNEL_IDS 0x1 +#define SBI_EXT_MPXY_READ_ATTRS 0x2 +#define SBI_EXT_MPXY_WRITE_ATTRS 0x3 +#define SBI_EXT_MPXY_SEND_MSG_WITH_RESP 0x4 +#define SBI_EXT_MPXY_SEND_MSG_NO_RESP 0x5 +#define SBI_EXT_MPXY_GET_NOTIFICATION_EVENTS 0x6 + /* SBI base specification related macros */ #define SBI_SPEC_VERSION_MAJOR_OFFSET 24 #define SBI_SPEC_VERSION_MAJOR_MASK 0x7f diff --git a/lib/sbi/Kconfig b/lib/sbi/Kconfig index bd8ba2b6..c6cc04bc 100644 --- a/lib/sbi/Kconfig +++ b/lib/sbi/Kconfig @@ -66,4 +66,7 @@ config SBI_ECALL_SSE bool "SSE extension" default y +config SBI_ECALL_MPXY + bool "MPXY extension" + default y endmenu diff --git a/lib/sbi/objects.mk b/lib/sbi/objects.mk index 2cea93b9..c199b834 100644 --- a/lib/sbi/objects.mk +++ b/lib/sbi/objects.mk @@ -61,6 +61,9 @@ libsbi-objs-$(CONFIG_SBI_ECALL_DBTR) += sbi_ecall_dbtr.o carray-sbi_ecall_exts-$(CONFIG_SBI_ECALL_SSE) += ecall_sse libsbi-objs-$(CONFIG_SBI_ECALL_SSE) += sbi_ecall_sse.o +carray-sbi_ecall_exts-$(CONFIG_SBI_ECALL_MPXY) += ecall_mpxy +libsbi-objs-$(CONFIG_SBI_ECALL_MPXY) += sbi_ecall_mpxy.o + libsbi-objs-y += sbi_bitmap.o libsbi-objs-y += sbi_bitops.o libsbi-objs-y += sbi_console.o diff --git a/lib/sbi/sbi_ecall_mpxy.c b/lib/sbi/sbi_ecall_mpxy.c new file mode 100644 index 00000000..5f717b76 --- /dev/null +++ b/lib/sbi/sbi_ecall_mpxy.c @@ -0,0 +1,68 @@ +/* + * SPDX-License-Identifier: BSD-2-Clause + * + * Copyright (c) 2024 Ventana Micro Systems Inc. + * + * Authors: + * Anup Patel + */ + +#include +#include +#include +#include +#include + +static int sbi_ecall_mpxy_handler(unsigned long extid, unsigned long funcid, + struct sbi_trap_regs *regs, + struct sbi_ecall_return *out) +{ + int ret = 0; + + switch (funcid) { + case SBI_EXT_MPXY_SET_SHMEM: + ret = sbi_mpxy_set_shmem(regs->a0, regs->a1, regs->a2, regs->a3); + break; + case SBI_EXT_MPXY_GET_CHANNEL_IDS: + ret = sbi_mpxy_get_channel_ids(regs->a0); + break; + case SBI_EXT_MPXY_READ_ATTRS: + ret = sbi_mpxy_read_attrs(regs->a0, regs->a1, regs->a2); + break; + case SBI_EXT_MPXY_WRITE_ATTRS: + ret = sbi_mpxy_write_attrs(regs->a0, regs->a1, regs->a2); + break; + case SBI_EXT_MPXY_SEND_MSG_WITH_RESP: + ret = sbi_mpxy_send_message(regs->a0, regs->a1, + regs->a2, &out->value); + break; + case SBI_EXT_MPXY_SEND_MSG_NO_RESP: + ret = sbi_mpxy_send_message(regs->a0, regs->a1, regs->a2, + NULL); + break; + case SBI_EXT_MPXY_GET_NOTIFICATION_EVENTS: + ret = sbi_mpxy_get_notification_events(regs->a0, &out->value); + break; + default: + ret = SBI_ENOTSUPP; + } + + return ret; +} + +struct sbi_ecall_extension ecall_mpxy; + +static int sbi_ecall_mpxy_register_extensions(void) +{ + if (!sbi_mpxy_channel_available()) + return 0; + + return sbi_ecall_register_extension(&ecall_mpxy); +} + +struct sbi_ecall_extension ecall_mpxy = { + .extid_start = SBI_EXT_MPXY, + .extid_end = SBI_EXT_MPXY, + .register_extensions = sbi_ecall_mpxy_register_extensions, + .handle = sbi_ecall_mpxy_handler, +}; From patchwork Tue Aug 6 07:33:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 1969368 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=EUIo07Bx; 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=IlDNC/Uz; 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 4WdQ7K0djSz1yYD for ; Tue, 6 Aug 2024 17:34:53 +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=wwxiHOgQx4dpvP7Oq95ihbimZXnFr3TXamXIux+US/Q=; b=EUIo07BxbzdPW+ Tqr6SOmo6r+d7EZmbaKxQdWGfng7KU84cE6bTO/ZDFR/Odi809oFour3D6a6d6O1M0crKJbkgrzSo m2DYDoH9TfFoQkhb+x86fUJf45Aoj7uxwsqqKLk2+msOvOW/z49pS+1ekm8u6e8RVDgmhBFajtagJ EfrJ1+Qnmt7FFtXMnDMwOiifhrr7IyYLsOQxhghqf0WLZiqOhhB3ofgAvcCfZJnzA98g8MKSQqFca kePaJe78r51AMbItbdn0JEQ2P/ULUzWNBXKp2AImpeiTe+HFhO4wk1hFi7yPR1CCjAhlwr1TTlKG0 8eI6buesaqnavBoL4LWw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sbEiS-00000000oKg-2Rwx; Tue, 06 Aug 2024 07:34:44 +0000 Received: from mail-pg1-x533.google.com ([2607:f8b0:4864:20::533]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sbEiD-00000000o9b-04gF for opensbi@lists.infradead.org; Tue, 06 Aug 2024 07:34:38 +0000 Received: by mail-pg1-x533.google.com with SMTP id 41be03b00d2f7-7a1843b4cdbso327043a12.2 for ; Tue, 06 Aug 2024 00:34:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1722929668; x=1723534468; 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=Ay8ImBJARtaHmCOWagBjToOniPmKX3S+lmUJZyUxH4Y=; b=IlDNC/UzldOKCtZ+yO5qmiYH7hEWGjXBgZPUaJd3rNPguh5YOe8oFJ36dhSHAKRKqQ Xl86QyXSIJHLMz0uGl6ZMlszjgHKD8ZdAW0HAt03ObkaMnZ/zmoSar9rMBSjAC4/Hot3 5N/hRW2sPfD8zcO9kXRhtIIy/oMNF/p3ckz14Vd88zk4LNWGsb9qfUHIerDbAmiXC878 nMbcf40HOKL/u6Ke63fsD2Mi4fLEYuzTlkcCwH8bDJQLYYc+b+wey86AD07Qwy4kyk4x pSU2OLnO80VpA4p0YLQurWRp6fkcHDZ3r+O4JJWXSLKBULKiu7WzMUT1hTstJxXFIgDf KKpw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722929668; x=1723534468; 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=Ay8ImBJARtaHmCOWagBjToOniPmKX3S+lmUJZyUxH4Y=; b=xB17VeT3mV325x69Ym3Nnc/Xz06Q3KXpLS6KBIvDYcIZMiYY7hjVeAwrS1Ywv0OcPY qaZ7CNOtlAuBYGh8ZVV4NFdBVDe0Nz9kmBe9NycMLeUMYskHi++U/GENQ//LKp1R7Wzx fb02BN+BMQJv6Nn0hwCqxVDDgqhBB9EIAKsQarn++g+6Sp5hr2awmVicqi2xEjUqmgk3 2o6szBGIioZG2CSuU15LXSR06iXdoK85xoiORyCv8aQ6nSAGYPKerUoc9bLHKt1xsFRK h2+KaoW7c6ApRAOu2EZlL2ryX7gZBwvgNXnVcJCTp2OkRru9FB+07aY5UnVsbYDLhN2D LVFQ== X-Forwarded-Encrypted: i=1; AJvYcCV9D/7b/BhtUJnrMz4oGfB6O8kmFNYChjSo2X+j7O4LpBRegqxBMzsIAA2J8FoZoIPWjQvWrpRu@lists.infradead.org X-Gm-Message-State: AOJu0Yy9bCSpIEo2y51OrGfvjbOHrkc9NGbXYdfmMw9RXjOP+F7tHzwD c2DTUjHX862yKOkh/ATzJoUQ9H4BC9CGhlMnGwkubk4xj5zyI4JKtsASdwYiCFA= X-Google-Smtp-Source: AGHT+IGfBG5zHDUfK4ZBZDx5bW84TFWUhvk2fFYMBhwzV7gIjEvQGmv5HZi/YUzV8L9f60HBXWbqAA== X-Received: by 2002:a05:6a20:7f94:b0:1be:c2f7:275 with SMTP id adf61e73a8af0-1c69969b5c0mr14446885637.50.1722929667658; Tue, 06 Aug 2024 00:34:27 -0700 (PDT) Received: from anup-ubuntu-vm.localdomain ([223.185.134.124]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7106ed2de28sm6455011b3a.191.2024.08.06.00.34.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Aug 2024 00:34:27 -0700 (PDT) From: Anup Patel To: Atish Patra Cc: Andrew Jones , Anup Patel , opensbi@lists.infradead.org, Anup Patel Subject: [PATCH 15/16] lib: utils: Add simple FDT based MPXY driver framework Date: Tue, 6 Aug 2024 13:03:37 +0530 Message-Id: <20240806073338.1856901-16-apatel@ventanamicro.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240806073338.1856901-1-apatel@ventanamicro.com> References: <20240806073338.1856901-1-apatel@ventanamicro.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240806_003429_165032_F7333C3D X-CRM114-Status: GOOD ( 18.74 ) 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: The generic platform can have multiple MPXY drivers so add a simple FDT based MPXY driver framework. Signed-off-by: Anup Patel --- include/sbi_utils/mpxy/fdt_mpxy.h | 31 ++++++++++++++++ lib/utils/Kconfig | 2 ++ lib/utils/mpxy/Kconfig | 10 ++++++ lib/utils/mpxy/fdt_mpxy.c | [...] 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:533 listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -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 The generic platform can have multiple MPXY drivers so add a simple FDT based MPXY driver framework. Signed-off-by: Anup Patel --- include/sbi_utils/mpxy/fdt_mpxy.h | 31 ++++++++++++++++ lib/utils/Kconfig | 2 ++ lib/utils/mpxy/Kconfig | 10 ++++++ lib/utils/mpxy/fdt_mpxy.c | 50 ++++++++++++++++++++++++++ lib/utils/mpxy/fdt_mpxy_drivers.carray | 3 ++ lib/utils/mpxy/objects.mk | 11 ++++++ platform/generic/configs/defconfig | 1 + platform/generic/platform.c | 2 ++ 8 files changed, 110 insertions(+) create mode 100644 include/sbi_utils/mpxy/fdt_mpxy.h create mode 100644 lib/utils/mpxy/Kconfig create mode 100644 lib/utils/mpxy/fdt_mpxy.c create mode 100644 lib/utils/mpxy/fdt_mpxy_drivers.carray create mode 100644 lib/utils/mpxy/objects.mk diff --git a/include/sbi_utils/mpxy/fdt_mpxy.h b/include/sbi_utils/mpxy/fdt_mpxy.h new file mode 100644 index 00000000..7ea26055 --- /dev/null +++ b/include/sbi_utils/mpxy/fdt_mpxy.h @@ -0,0 +1,31 @@ +/* + * SPDX-License-Identifier: BSD-2-Clause + * + * Copyright (c) 2024 Ventana Micro Systems Inc. + * + * Authors: + * Anup Patel + */ + +#ifndef __FDT_MPXY_H__ +#define __FDT_MPXY_H__ + +#include + +#ifdef CONFIG_FDT_MPXY + +struct fdt_mpxy { + const struct fdt_match *match_table; + int (*init)(void *fdt, int nodeoff, const struct fdt_match *match); + void (*exit)(void); +}; + +int fdt_mpxy_init(void); + +#else + +static inline int fdt_mpxy_init(void) { return 0; } + +#endif + +#endif diff --git a/lib/utils/Kconfig b/lib/utils/Kconfig index 002d6f8f..901ba564 100644 --- a/lib/utils/Kconfig +++ b/lib/utils/Kconfig @@ -32,4 +32,6 @@ source "$(OPENSBI_SRC_DIR)/lib/utils/sys/Kconfig" source "$(OPENSBI_SRC_DIR)/lib/utils/timer/Kconfig" +source "$(OPENSBI_SRC_DIR)/lib/utils/mpxy/Kconfig" + endmenu diff --git a/lib/utils/mpxy/Kconfig b/lib/utils/mpxy/Kconfig new file mode 100644 index 00000000..d084b09a --- /dev/null +++ b/lib/utils/mpxy/Kconfig @@ -0,0 +1,10 @@ +# SPDX-License-Identifier: BSD-2-Clause + +menu "MPXY Device Support" + +config FDT_MPXY + bool "FDT based MPXY drivers" + depends on FDT + default n + +endmenu diff --git a/lib/utils/mpxy/fdt_mpxy.c b/lib/utils/mpxy/fdt_mpxy.c new file mode 100644 index 00000000..41753fab --- /dev/null +++ b/lib/utils/mpxy/fdt_mpxy.c @@ -0,0 +1,50 @@ +/* + * SPDX-License-Identifier: BSD-2-Clause + * + * Copyright (c) 2024 Ventana Micro Systems Inc. + * + * Authors: + * Anup Patel + */ + +#include +#include +#include + +/* List of FDT MPXY drivers generated at compile time */ +extern struct fdt_mpxy *fdt_mpxy_drivers[]; +extern unsigned long fdt_mpxy_drivers_size; + +int fdt_mpxy_init(void) +{ + int pos, noff, rc; + struct fdt_mpxy *drv; + const struct fdt_match *match; + void *fdt = fdt_get_address(); + + for (pos = 0; pos < fdt_mpxy_drivers_size; pos++) { + drv = fdt_mpxy_drivers[pos]; + + noff = -1; + while ((noff = fdt_find_match(fdt, noff, + drv->match_table, &match)) >= 0) { + /* drv->init must not be NULL */ + if (drv->init == NULL) + return SBI_EFAIL; + + rc = drv->init(fdt, noff, match); + if (rc == SBI_ENODEV) + continue; + if (rc) + return rc; + + /* + * We will have multiple MPXY devices so we + * cannot break here. + */ + } + } + + /* Platforms might not have any MPXY devices so don't fail */ + return 0; +} diff --git a/lib/utils/mpxy/fdt_mpxy_drivers.carray b/lib/utils/mpxy/fdt_mpxy_drivers.carray new file mode 100644 index 00000000..d930753a --- /dev/null +++ b/lib/utils/mpxy/fdt_mpxy_drivers.carray @@ -0,0 +1,3 @@ +HEADER: sbi_utils/mpxy/fdt_mpxy.h +TYPE: struct fdt_mpxy +NAME: fdt_mpxy_drivers diff --git a/lib/utils/mpxy/objects.mk b/lib/utils/mpxy/objects.mk new file mode 100644 index 00000000..43e73c94 --- /dev/null +++ b/lib/utils/mpxy/objects.mk @@ -0,0 +1,11 @@ +# +# SPDX-License-Identifier: BSD-2-Clause +# +# Copyright (c) 2024 Ventana Micro Systems Inc. +# +# Authors: +# Anup Patel +# + +libsbiutils-objs-$(CONFIG_FDT_MPXY) += mpxy/fdt_mpxy.o +libsbiutils-objs-$(CONFIG_FDT_MPXY) += mpxy/fdt_mpxy_drivers.carray.o diff --git a/platform/generic/configs/defconfig b/platform/generic/configs/defconfig index 384918f9..1f0880ee 100644 --- a/platform/generic/configs/defconfig +++ b/platform/generic/configs/defconfig @@ -53,3 +53,4 @@ CONFIG_FDT_SUSPEND_RPMI=y CONFIG_FDT_TIMER=y CONFIG_FDT_TIMER_MTIMER=y CONFIG_FDT_TIMER_PLMT=y +CONFIG_FDT_MPXY=y diff --git a/platform/generic/platform.c b/platform/generic/platform.c index d085647d..89bd3af9 100644 --- a/platform/generic/platform.c +++ b/platform/generic/platform.c @@ -17,6 +17,7 @@ #include #include #include +#include #include #include #include @@ -418,6 +419,7 @@ const struct sbi_platform_operations platform_ops = { .get_tlb_num_entries = generic_tlb_num_entries, .timer_init = fdt_timer_init, .timer_exit = fdt_timer_exit, + .mpxy_init = fdt_mpxy_init, .vendor_ext_check = generic_vendor_ext_check, .vendor_ext_provider = generic_vendor_ext_provider, }; From patchwork Tue Aug 6 07:33:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 1969369 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=bUD8p8vS; 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=msmGFVcv; 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 4WdQ7L6pLWz1ydt for ; Tue, 6 Aug 2024 17:34:54 +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=k+gNcr7RdkMdxUeqETe6mlbyR4nooSsmykFhBJd7VnE=; b=bUD8p8vSg3H+hg rSv18gHOFXsDnUrGDs+8EOs+fu0984doQM4xoH4ciCD+EG2k8ip1d/lTHM0BE7BvH8j/qbtviYgMG hIMuuD7n9TcZA/JEvbWhF2prTrbEmM/1nno/ysBDbkEI9uVhuFnTrfeVbN119RuQDL5FD+XIrVM0p eceGCNzRT4We79kVH7WcGde/6z6+pumdxg0T2EKZUhCoLMDIzW8d1EdA35XpfLfZU5PsM8Vwx4873 0kk+wr3rtBB3uPSoQna0l7JcDu5z/lh55GP7RrDARXPY3c3ctsjn0pJqvbz9cEjIfNHNxuR9/Bfb9 W69EB5pszt2xhDDzYsZg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sbEiU-00000000oMn-3cfR; Tue, 06 Aug 2024 07:34:46 +0000 Received: from mail-pf1-x433.google.com ([2607:f8b0:4864:20::433]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sbEiF-00000000oBW-19TW for opensbi@lists.infradead.org; Tue, 06 Aug 2024 07:34:43 +0000 Received: by mail-pf1-x433.google.com with SMTP id d2e1a72fcca58-70d1fb6c108so240529b3a.3 for ; Tue, 06 Aug 2024 00:34:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1722929670; x=1723534470; 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=RJNKFhRxj4PnzzkSybD+gZma5CnsstVm0I38wOvgyYs=; b=msmGFVcvgp71m0GQQsQtvMFYeqAIQXYekV0DJ6iOYH3oWjfomrTkq4k4fqTZrn/2yi Uj190y2Xl3uq/0sPKXmIGDolH2ZMxQeabamcT9HPb1PIDMf7BybEiRfkNqRIgMke7Qac roY1UKwpgurXKFi+y1V7pr+eLO4zu4NM+FOvuDrkRFDwF0JxLON1DzUV21VHIz00zlDA H31J5hpKUYGw1lh4VoUHc+58yOr5NkHMZGpicQ/5LRmiPeMRZVJ4abyfCjkyg7XUs5HM Zd53uisODu04hoiax5pIj6V3am0IgpVayYu3DxvlmiCROZ06JWTaa4SPKjsVTKu2zMCb W46A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722929671; x=1723534471; 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=RJNKFhRxj4PnzzkSybD+gZma5CnsstVm0I38wOvgyYs=; b=XTXUgH05iu/3WKAwJvoatEcre6QfvmOlMQLSbUnYC9uMwCGKNiVd33BR+W2J1n9xHs /Vg/Z4GC4XIq29ugMvUWGgYfEjkNNvfmokSPd82e3o1IoqLwDWd4oCzJ1e3A68Hf2Soq oLuFDiiGBBAwZWUNZneiZoI7YXADuhUA6f5UrYJ43LLazBZUVdp2G0X5+UTNKk2CTO+J 7hUt2Cfkf+JwhEN3wB03+p2+t1ruL2JALB1dqKKxacfXZS7l+lpKqGPT6tAK/hM+QVgS NIwF8qkquzrDRjL4cEBSJMG96PpZ8+QZHpUQ339jHVQ36VgLRYV4yx3hvz7OflNiURnB XCrA== X-Forwarded-Encrypted: i=1; AJvYcCVmRiZDgzCarzgfqKCmMj2pqDDrVVrnsHxDF9GgLUGu/1MqwPRWUalOaSw6fQJcZH+olOAnCViYQc0zUgFJFXdByC8pucfyy/lmQos= X-Gm-Message-State: AOJu0YwCxeiyA6d66wM5i5r1XsyaYm1vxqw/2YK5wClFf69547Okca1f Z2lNfnVJUxi/7eM0sbOJBXaQjYd9shpgZVg228Aat1OHxd2OozwUh53n8CrAmip0rh3F2ObeSvH L X-Google-Smtp-Source: AGHT+IFGfGu94/5miRdQh8pdtqS3nrAguwDN7kr+qj6lDyrvcbnK0IHtwRR2Jvpz+yORiuVI4UbhQg== X-Received: by 2002:a05:6a00:6f0f:b0:706:67c9:16d0 with SMTP id d2e1a72fcca58-7106d0812eemr12417549b3a.26.1722929670363; Tue, 06 Aug 2024 00:34:30 -0700 (PDT) Received: from anup-ubuntu-vm.localdomain ([223.185.134.124]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7106ed2de28sm6455011b3a.191.2024.08.06.00.34.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Aug 2024 00:34:29 -0700 (PDT) From: Anup Patel To: Atish Patra Cc: Andrew Jones , Anup Patel , opensbi@lists.infradead.org, Rahul Pathak , Anup Patel Subject: [PATCH 16/16] lib: utils/mpxy: Add RPMI client driver for MPXY Date: Tue, 6 Aug 2024 13:03:38 +0530 Message-Id: <20240806073338.1856901-17-apatel@ventanamicro.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240806073338.1856901-1-apatel@ventanamicro.com> References: <20240806073338.1856901-1-apatel@ventanamicro.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240806_003431_753305_A245EBFB X-CRM114-Status: GOOD ( 25.63 ) 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: From: Rahul Pathak Add a generic RPMI mailbox client driver which provides a MPXY channel. Initially, this driver only supports RPMI clock service group but can be extended to support multiple RPMI service groups. 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:433 listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -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 From: Rahul Pathak Add a generic RPMI mailbox client driver which provides a MPXY channel. Initially, this driver only supports RPMI clock service group but can be extended to support multiple RPMI service groups. Signed-off-by: Rahul Pathak Co-developed-by: Anup Patel Signed-off-by: Anup Patel --- include/sbi_utils/mailbox/rpmi_msgprot.h | 93 ++++++ lib/utils/mpxy/Kconfig | 9 + lib/utils/mpxy/fdt_mpxy_rpmi_mbox.c | 408 +++++++++++++++++++++++ lib/utils/mpxy/objects.mk | 3 + platform/generic/configs/defconfig | 1 + 5 files changed, 514 insertions(+) create mode 100644 lib/utils/mpxy/fdt_mpxy_rpmi_mbox.c diff --git a/include/sbi_utils/mailbox/rpmi_msgprot.h b/include/sbi_utils/mailbox/rpmi_msgprot.h index f7913ab1..50d34017 100644 --- a/include/sbi_utils/mailbox/rpmi_msgprot.h +++ b/include/sbi_utils/mailbox/rpmi_msgprot.h @@ -153,6 +153,7 @@ enum rpmi_servicegroup_id { RPMI_SRVGRP_SYSTEM_SUSPEND = 0x00003, RPMI_SRVGRP_HSM = 0x00004, RPMI_SRVGRP_CPPC = 0x00005, + RPMI_SRVGRP_CLOCK = 0x00007, RPMI_SRVGRP_ID_MAX_COUNT, }; @@ -417,4 +418,96 @@ struct rpmi_cppc_hart_list_resp { u32 hartid[(RPMI_MSG_DATA_SIZE(RPMI_SLOT_SIZE_MIN) - (sizeof(u32) * 3)) / sizeof(u32)]; }; +/** RPMI Clock ServiceGroup Service IDs */ +enum rpmi_clock_service_id { + RPMI_CLOCK_SRV_ENABLE_NOTIFICATION = 0x01, + RPMI_CLOCK_SRV_GET_NUM_CLOCKS = 0x02, + RPMI_CLOCK_SRV_GET_ATTRIBUTES = 0x03, + RPMI_CLOCK_SRV_GET_SUPPORTED_RATES = 0x04, + RPMI_CLOCK_SRV_SET_CONFIG = 0x05, + RPMI_CLOCK_SRV_GET_CONFIG = 0x06, + RPMI_CLOCK_SRV_SET_RATE = 0x07, + RPMI_CLOCK_SRV_GET_RATE = 0x08, + RPMI_CLOCK_SRV_MAX_COUNT, +}; + +struct rpmi_clock_get_num_clocks_resp { + s32 status; + u32 num_clocks; +}; + +struct rpmi_clock_get_attributes_req { + u32 clock_id; +}; + +struct rpmi_clock_get_attributes_resp { + s32 status; +#define RPMI_CLOCK_FLAGS_FORMAT_POS 30 +#define RPMI_CLOCK_FLAGS_FORMAT_MASK \ + (3U << RPMI_CLOCK_FLAGS_CLOCK_FORMAT_POS) +#define RPMI_CLOCK_FLAGS_FORMAT_DISCRETE 0 +#define RPMI_CLOCK_FLAGS_FORMAT_LINEAR 1 + u32 flags; + u32 num_rates; + u32 transition_latency; + u8 name[16]; +}; + +struct rpmi_clock_get_supported_rates_req { + u32 clock_id; + u32 clock_rate_index; +}; + +struct rpmi_clock_get_supported_rates_resp { + s32 status; + u32 flags; + u32 remaining; + u32 returned; + u32 clock_rate[0]; +}; + +struct rpmi_clock_set_config_req { + u32 clock_id; +#define RPMI_CLOCK_CONFIG_ENABLE (1U << 0) + u32 config; +}; + +struct rpmi_clock_set_config_resp { + s32 status; +}; + +struct rpmi_clock_get_config_req { + u32 clock_id; +}; + +struct rpmi_clock_get_config_resp { + s32 status; + u32 config; +}; + +struct rpmi_clock_set_rate_req { + u32 clock_id; +#define RPMI_CLOCK_SET_RATE_FLAGS_MASK (3U << 0) +#define RPMI_CLOCK_SET_RATE_FLAGS_ROUND_DOWN 0 +#define RPMI_CLOCK_SET_RATE_FLAGS_ROUND_UP 1 +#define RPMI_CLOCK_SET_RATE_FLAGS_ROUND_PLAT 2 + u32 flags; + u32 clock_rate_low; + u32 clock_rate_high; +}; + +struct rpmi_clock_set_rate_resp { + s32 status; +}; + +struct rpmi_clock_get_rate_req { + u32 clock_id; +}; + +struct rpmi_clock_get_rate_resp { + s32 status; + u32 clock_rate_low; + u32 clock_rate_high; +}; + #endif /* !__RPMI_MSGPROT_H__ */ diff --git a/lib/utils/mpxy/Kconfig b/lib/utils/mpxy/Kconfig index d084b09a..131fb91a 100644 --- a/lib/utils/mpxy/Kconfig +++ b/lib/utils/mpxy/Kconfig @@ -7,4 +7,13 @@ config FDT_MPXY depends on FDT default n +if FDT_MPXY + +config FDT_MPXY_RPMI_MBOX + bool "FDT MPXY mailbox client driver" + depends on FDT_MAILBOX + default n + +endif + endmenu diff --git a/lib/utils/mpxy/fdt_mpxy_rpmi_mbox.c b/lib/utils/mpxy/fdt_mpxy_rpmi_mbox.c new file mode 100644 index 00000000..d396aa7f --- /dev/null +++ b/lib/utils/mpxy/fdt_mpxy_rpmi_mbox.c @@ -0,0 +1,408 @@ +/* + * SPDX-License-Identifier: BSD-2-Clause + * + * Copyright (c) 2024 Ventana Micro Systems Inc. + * + * Authors: + * Rahul Pathak + * Anup Patel + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define RPMI_MAJOR_VER (0x0000) +#define RPMI_MINOR_VER (0x0001) +#define RPMI_MSG_SEND_TIMEOUT (10) /* microseconds */ + +/** Convert the mpxy attribute ID to attribute array index */ +#define attr_id2index(attr_id) (attr_id - SBI_MPXY_ATTR_MSGPROTO_ATTR_START) + +enum mpxy_msgprot_rpmi_attr_id { + MPXY_MSGPROT_RPMI_ATTR_SERVICEGROUP_ID = SBI_MPXY_ATTR_MSGPROTO_ATTR_START, + MPXY_MSGPROT_RPMI_ATTR_MAX_ID, +}; + +/** + * MPXY message protocol attributes for RPMI + * Order of attribute fields must follow the + * attribute IDs in `enum mpxy_msgprot_rpmi_attr_id` + */ +struct mpxy_rpmi_channel_attrs { + u32 servicegrp_id; +}; + +/* RPMI mbox data per service group */ +struct mpxy_mbox_data { + u32 servicegrp_id; + u32 num_services; + u32 notifications_support; + void *priv_data; +}; + +/* RPMI service data per service group */ +struct rpmi_service_data { + u8 id; + u32 min_tx_len; + u32 max_tx_len; + u32 min_rx_len; + u32 max_rx_len; +}; + +/** + * MPXY mbox instance per MPXY channel. This ties + * an MPXY channel with an RPMI Service group. + */ +struct mpxy_mbox { + struct mbox_chan *chan; + struct mpxy_mbox_data *mbox_data; + struct mpxy_rpmi_channel_attrs msgprot_attrs; + struct sbi_mpxy_channel channel; +}; + +/** Make sure all attributes are packed for direct memcpy */ +#define assert_field_offset(field, attr_offset) \ + _Static_assert( \ + ((offsetof(struct mpxy_rpmi_channel_attrs, field)) / \ + sizeof(u32)) == (attr_offset - SBI_MPXY_ATTR_MSGPROTO_ATTR_START),\ + "field " #field \ + " from struct mpxy_rpmi_channel_attrs invalid offset, expected " #attr_offset) + +assert_field_offset(servicegrp_id, MPXY_MSGPROT_RPMI_ATTR_SERVICEGROUP_ID); + +/** + * Discover the RPMI service data using message_id + * MPXY message_id == RPMI service_id + */ +static struct rpmi_service_data *mpxy_find_rpmi_srvid(u32 message_id, + struct mpxy_mbox_data *mbox_data) +{ + int mid = 0; + struct rpmi_service_data *srv = mbox_data->priv_data; + for (mid = 0; srv[mid].id < mbox_data->num_services; mid++) { + if (srv[mid].id == (u8)message_id) + return &srv[mid]; + } + + return NULL; +} + +/** Copy attributes word size */ +static void mpxy_copy_attrs(u32 *outmem, u32 *inmem, u32 count) +{ + u32 idx; + for (idx = 0; idx < count; idx++) + outmem[idx] = cpu_to_le32(inmem[idx]); +} + +static int mpxy_mbox_read_attributes(struct sbi_mpxy_channel *channel, + u32 *outmem, u32 base_attr_id, + u32 attr_count) +{ + u32 end_id; + struct mpxy_mbox *rmb = + container_of(channel, struct mpxy_mbox, channel); + + u32 *attr_array = (u32 *)&rmb->msgprot_attrs; + + end_id = base_attr_id + attr_count - 1; + + if (end_id >= MPXY_MSGPROT_RPMI_ATTR_MAX_ID) + return SBI_ERR_BAD_RANGE; + + mpxy_copy_attrs(outmem, &attr_array[attr_id2index(base_attr_id)], + attr_count); + + return SBI_SUCCESS; +} + +/** + * Verify the channel standard attribute wrt to write permission + * and the value to be set if valid or not. + * Only attributes needs to be checked which are defined Read/Write + * permission. Other with Readonly permission will result in error. + * + * Attributes values to be written must also be checked because + * before writing a range of attributes, we need to make sure that + * either complete range of attributes is written successfully or not + * at all. + */ +static int mpxy_check_write_attr(u32 attr_id, u32 attr_val) +{ + int ret = SBI_SUCCESS; + + switch(attr_id) { + /** All RO access attributes falls under default */ + default: + ret = SBI_ERR_BAD_RANGE; + }; + + return ret; +} + +static void mpxy_write_attr(struct mpxy_rpmi_channel_attrs *attrs, + u32 attr_id, + u32 attr_val) +{ + /* No writable attributes in RPMI */ +} + +static int mpxy_mbox_write_attributes(struct sbi_mpxy_channel *channel, + u32 *outmem, u32 base_attr_id, + u32 attr_count) +{ + int ret, mem_idx; + u32 end_id, attr_val, idx; + struct mpxy_mbox *rmb = + container_of(channel, struct mpxy_mbox, channel); + + end_id = base_attr_id + attr_count - 1; + + if (end_id >= MPXY_MSGPROT_RPMI_ATTR_MAX_ID) + return SBI_ERR_BAD_RANGE; + + mem_idx = 0; + for (idx = base_attr_id; idx <= end_id; idx++) { + attr_val = le32_to_cpu(outmem[mem_idx++]); + ret = mpxy_check_write_attr(idx, attr_val); + if (ret) + return ret; + } + + mem_idx = 0; + for (idx = base_attr_id; idx <= end_id; idx++) { + attr_val = le32_to_cpu(outmem[mem_idx++]); + mpxy_write_attr(&rmb->msgprot_attrs, idx, attr_val); + } + + return SBI_SUCCESS; +} + +static int mpxy_mbox_send_message(struct sbi_mpxy_channel *channel, + u32 message_id, void *tx, u32 tx_len, + void *rx, u32 rx_max_len, + unsigned long *ack_len) +{ + int ret; + u32 rx_len = 0; + struct mbox_xfer xfer; + struct rpmi_message_args args = {0}; + struct mpxy_mbox *rmb = + container_of(channel, struct mpxy_mbox, channel); + struct rpmi_service_data *srv = + mpxy_find_rpmi_srvid(message_id, rmb->mbox_data); + if (!srv) + return SBI_EFAIL; + + if (tx_len < srv->min_tx_len || tx_len > srv->max_tx_len) + return SBI_EFAIL; + + if (ack_len) { + if (srv->min_rx_len == srv->max_rx_len) + rx_len = srv->min_rx_len; + else if (srv->max_rx_len < channel->attrs.msg_data_maxlen) + rx_len = srv->max_rx_len; + else + rx_len = channel->attrs.msg_data_maxlen; + + args.type = RPMI_MSG_NORMAL_REQUEST; + args.flags = (rx) ? 0 : RPMI_MSG_FLAGS_NO_RX; + args.service_id = srv->id; + mbox_xfer_init_txrx(&xfer, &args, + tx, tx_len, RPMI_DEF_TX_TIMEOUT, + rx, rx_len, RPMI_DEF_TX_TIMEOUT); + } + else { + args.type = RPMI_MSG_POSTED_REQUEST; + args.flags = RPMI_MSG_FLAGS_NO_RX; + args.service_id = srv->id; + mbox_xfer_init_tx(&xfer, &args, + tx, tx_len, RPMI_DEF_TX_TIMEOUT); + } + + ret = mbox_chan_xfer(rmb->chan, &xfer); + if (ret) + return (ret == SBI_ETIMEDOUT) ? SBI_ETIMEDOUT : SBI_EFAIL; + + if (ack_len) + *ack_len = args.rx_data_len; + + return SBI_OK; +} + +static int mpxy_mbox_get_notifications(struct sbi_mpxy_channel *channel, + void *eventsbuf, u32 bufsize, + unsigned long *events_len) +{ + return SBI_ENOTSUPP; +} + +static int mpxy_mbox_init(void *fdt, int nodeoff, + const struct fdt_match *match) +{ + int rc, len; + const fdt32_t *val; + u32 channel_id; + struct mpxy_mbox *rmb; + struct mbox_chan *chan; + const struct mpxy_mbox_data *data = match->data; + + /* Allocate context for RPXY mbox client */ + rmb = sbi_zalloc(sizeof(*rmb)); + if (!rmb) + return SBI_ENOMEM; + + /* + * If channel request failed then other end does not support + * service group so do nothing. + */ + rc = fdt_mailbox_request_chan(fdt, nodeoff, 0, &chan); + if (rc) { + sbi_free(rmb); + return 0; + } + + /* Match channel service group id */ + if (data->servicegrp_id != chan->chan_args[0]) { + mbox_controller_free_chan(chan); + sbi_free(rmb); + return SBI_EINVAL; + } + + val = fdt_getprop(fdt, nodeoff, "riscv,sbi-mpxy-channel-id", &len); + if (len > 0 && val) + channel_id = fdt32_to_cpu(*val); + else { + mbox_controller_free_chan(chan); + sbi_free(rmb); + return SBI_ENODEV; + } + + /* Setup MPXY mbox client */ + /* Channel ID*/ + rmb->channel.channel_id = channel_id; + /* Callback for read RPMI attributes */ + rmb->channel.read_attributes = mpxy_mbox_read_attributes; + /* Callback for write RPMI attributes */ + rmb->channel.write_attributes = mpxy_mbox_write_attributes; + /* Callback for sending RPMI message */ + rmb->channel.send_message = mpxy_mbox_send_message; + /* Callback to get RPMI notifications */ + rmb->channel.get_notification_events = mpxy_mbox_get_notifications; + + /* No callback to switch events state data */ + rmb->channel.switch_eventsstate = NULL; + + /* RPMI Message Protocol ID */ + rmb->channel.attrs.msg_proto_id = SBI_MPXY_MSGPROTO_RPMI_ID; + /* RPMI Message Protocol Version */ + rmb->channel.attrs.msg_proto_version = + SBI_MPXY_MSGPROTO_VERSION(RPMI_MAJOR_VER, RPMI_MINOR_VER); + + /* RPMI supported max message data length(bytes), same for + * all service groups */ + rmb->channel.attrs.msg_data_maxlen = + RPMI_MSG_DATA_SIZE(RPMI_SLOT_SIZE_MIN); + /* RPMI message send timeout(milliseconds) + * same for all service groups */ + rmb->channel.attrs.msg_send_timeout = RPMI_MSG_SEND_TIMEOUT; + + /* RPMI message protocol attribute: service group id */ + rmb->msgprot_attrs.servicegrp_id = data->servicegrp_id; + + rmb->mbox_data = (struct mpxy_mbox_data *)data; + rmb->chan = chan; + + /* Register RPXY service group */ + rc = sbi_mpxy_register_channel(&rmb->channel); + if (rc) { + mbox_controller_free_chan(chan); + sbi_free(rmb); + return rc; + } + + return SBI_OK; +} + +static struct rpmi_service_data clock_services[] = { +{ + .id = RPMI_CLOCK_SRV_ENABLE_NOTIFICATION, + .min_tx_len = sizeof(struct rpmi_enable_notification_req), + .max_tx_len = sizeof(struct rpmi_enable_notification_req), + .min_rx_len = sizeof(struct rpmi_enable_notification_resp), + .max_rx_len = sizeof(struct rpmi_enable_notification_resp), +}, +{ + .id = RPMI_CLOCK_SRV_GET_NUM_CLOCKS, + .min_tx_len = 0, + .max_tx_len = 0, + .min_rx_len = sizeof(struct rpmi_clock_get_num_clocks_resp), + .max_rx_len = sizeof(struct rpmi_clock_get_num_clocks_resp), +}, +{ + .id = RPMI_CLOCK_SRV_GET_ATTRIBUTES, + .min_tx_len = sizeof(struct rpmi_clock_get_attributes_req), + .max_tx_len = sizeof(struct rpmi_clock_get_attributes_req), + .min_rx_len = sizeof(struct rpmi_clock_get_attributes_resp), + .max_rx_len = sizeof(struct rpmi_clock_get_attributes_resp), +}, +{ + .id = RPMI_CLOCK_SRV_GET_SUPPORTED_RATES, + .min_tx_len = sizeof(struct rpmi_clock_get_supported_rates_req), + .max_tx_len = sizeof(struct rpmi_clock_get_supported_rates_req), + .min_rx_len = sizeof(struct rpmi_clock_get_supported_rates_resp), + .max_rx_len = -1U, +}, +{ + .id = RPMI_CLOCK_SRV_SET_CONFIG, + .min_tx_len = sizeof(struct rpmi_clock_set_config_req), + .max_tx_len = sizeof(struct rpmi_clock_set_config_req), + .min_rx_len = sizeof(struct rpmi_clock_set_config_resp), + .max_rx_len = sizeof(struct rpmi_clock_set_config_resp), +}, +{ + .id = RPMI_CLOCK_SRV_GET_CONFIG, + .min_tx_len = sizeof(struct rpmi_clock_get_config_req), + .max_tx_len = sizeof(struct rpmi_clock_get_config_req), + .min_rx_len = sizeof(struct rpmi_clock_get_config_resp), + .max_rx_len = sizeof(struct rpmi_clock_get_config_resp), +}, +{ + .id = RPMI_CLOCK_SRV_SET_RATE, + .min_tx_len = sizeof(struct rpmi_clock_set_rate_req), + .max_tx_len = sizeof(struct rpmi_clock_set_rate_req), + .min_rx_len = sizeof(struct rpmi_clock_set_rate_resp), + .max_rx_len = sizeof(struct rpmi_clock_set_rate_resp), +}, +{ + .id = RPMI_CLOCK_SRV_GET_RATE, + .min_tx_len = sizeof(struct rpmi_clock_get_rate_req), + .max_tx_len = sizeof(struct rpmi_clock_get_rate_req), + .min_rx_len = sizeof(struct rpmi_clock_get_rate_resp), + .max_rx_len = sizeof(struct rpmi_clock_get_rate_resp), +}, +}; + +static struct mpxy_mbox_data clock_data = { + .servicegrp_id = RPMI_SRVGRP_CLOCK, + .num_services = RPMI_CLOCK_SRV_MAX_COUNT, + .notifications_support = 1, + .priv_data = clock_services, +}; + +static const struct fdt_match mpxy_mbox_match[] = { + { .compatible = "riscv,rpmi-mpxy-clk", .data = &clock_data }, + { }, +}; + +struct fdt_mpxy fdt_mpxy_rpmi_mbox = { + .match_table = mpxy_mbox_match, + .init = mpxy_mbox_init, +}; diff --git a/lib/utils/mpxy/objects.mk b/lib/utils/mpxy/objects.mk index 43e73c94..ccb28b55 100644 --- a/lib/utils/mpxy/objects.mk +++ b/lib/utils/mpxy/objects.mk @@ -9,3 +9,6 @@ libsbiutils-objs-$(CONFIG_FDT_MPXY) += mpxy/fdt_mpxy.o libsbiutils-objs-$(CONFIG_FDT_MPXY) += mpxy/fdt_mpxy_drivers.carray.o + +carray-fdt_mpxy_drivers-$(CONFIG_FDT_MPXY_RPMI_MBOX) += fdt_mpxy_rpmi_mbox +libsbiutils-objs-$(CONFIG_FDT_MPXY_RPMI_MBOX) += mpxy/fdt_mpxy_rpmi_mbox.o diff --git a/platform/generic/configs/defconfig b/platform/generic/configs/defconfig index 1f0880ee..e23b38b2 100644 --- a/platform/generic/configs/defconfig +++ b/platform/generic/configs/defconfig @@ -54,3 +54,4 @@ CONFIG_FDT_TIMER=y CONFIG_FDT_TIMER_MTIMER=y CONFIG_FDT_TIMER_PLMT=y CONFIG_FDT_MPXY=y +CONFIG_FDT_MPXY_RPMI_MBOX=y