From patchwork Mon Feb 27 10:31:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Jones X-Patchwork-Id: 1748601 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org 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=) 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=sQZ0qMj5; 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=cmSJez6N; dkim-atps=neutral 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 (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4PQGyc5XYLz1yWw for ; Mon, 27 Feb 2023 21:32:08 +1100 (AEDT) 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=t0a/KdQ21aPSstue3wUnmH6WP/UX7gTZ3FDkhFCCaYc=; b=sQZ0qMj5HlEshg raqdU3FCf59gssQM5sdTDQYhx6o+jfB2p4a29XP84Om/Cx3XzRep+TEspCsMLSMAgXvNAaWLEtJ0y vuS+MHJQes346IWDDLHSmDTwL5k0+DAqKQ7/Yg8FpAfv7sdrQ5LW+QJXeAxFhnUWjDAqJS2E+MO2k UI3EZVf8A6pHfpz02/NU/TRdAYSHLIQYlDHVr+9079pXm6+DjQL2VP6yIdiBgaLbt35VAbBuaARHZ Ij5Agve+dRfEegTaKRHkxju1OpP4S9HQDyQThpFZsLMt0eP40T6E8HzVUnWrPKlOInifZG0W9BuNn 8jprGiH3PDexP+wttNaw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pWanR-009EpG-1R; Mon, 27 Feb 2023 10:31:53 +0000 Received: from mail-wr1-x436.google.com ([2a00:1450:4864:20::436]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1pWan9-009Ebc-6o for opensbi@lists.infradead.org; Mon, 27 Feb 2023 10:31:43 +0000 Received: by mail-wr1-x436.google.com with SMTP id r18so5666792wrx.1 for ; Mon, 27 Feb 2023 02:31:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; 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=+Hv0rey1612hXp57/odW6VLM4iqRyBAdRQVS3Z7Eeuc=; b=cmSJez6NtjkvVH91C4mK+PsXW3CM4KfbpSsl1lJdjOnuDIfBH85Ua+H69yn1QGG8ln /0ohR+qTZDmc/W9DNfEolXpETFhBzPNvMq4AnrZ3vtsRga+n9F3/pnV/D0kKP6ORZMDL P5aadQyxp08kEkaHRTr9IFgVSfU4LgrwrxQyuV05lbRdhhMr9KK5XANhUHOxRBHIamen mPDQXOZxQSxDuZctb+d7jzIr5wFDVxiWl9/ys+AdgHifeHBmI2vjs7GVjxkh4LmvAkUu C/yceltMETi2jCake0ga6444fKsJPOyvmXW8ggWjyuuKoGESYVD8Ns3cLcWVIUV/LBp8 ITKw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=+Hv0rey1612hXp57/odW6VLM4iqRyBAdRQVS3Z7Eeuc=; b=ZyWZqcGXulReUvuAbE75t5Y8axeK2Xiy8TDyNFQCXVHZGJohl8CzRFfLTmedubxsA2 qtJZQtTyYrdK7iOTk8uayfZXCD1OyoAWAbnNxxCBApgzHoEBFP8+ByLF4VQ5eETaMZWR B49VQG5aR+PJ5z5hs8H/GqqJUcuq0vDt2Uv/8CwtIBTnijKffexvV0a9NCZNZ14obHgf j113bN++0ZcGIJSQrrtjshqk47tWGGSdYjrDrziJ+7EtQEOe5Wbo28Z+45khWIP2dn6o XAUzvCL3Hm1eNwapGl4vveBOX/FqZXDa75gcNGROrGIC/b0WjE0FzDO3MMjk/nU3Rq7x D6ow== X-Gm-Message-State: AO0yUKW+KoBIR5rTlh3Kyb+Xb0LCtGrtzkzkLQSYEgms1ShBuDTSLEnv 9McAg2niA4ylcUF16ZTYxRD6rblj/jYSW8yX X-Google-Smtp-Source: AK7set8JDWLNs1nSVL3JVwAxNvDxAAMN4egSSTNqT+USWbglSds2D4oXIsuPRNKy10lgWg5HmaG+Cg== X-Received: by 2002:a5d:438e:0:b0:2c8:37a:59c2 with SMTP id i14-20020a5d438e000000b002c8037a59c2mr7733798wrq.63.1677493893473; Mon, 27 Feb 2023 02:31:33 -0800 (PST) Received: from localhost (cst2-173-16.cust.vodafone.cz. [31.30.173.16]) by smtp.gmail.com with ESMTPSA id u4-20020adff884000000b002c70851bfcasm6693521wrp.28.2023.02.27.02.31.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Feb 2023 02:31:33 -0800 (PST) From: Andrew Jones To: opensbi@lists.infradead.org Cc: 'Ley Foon Tan ' , 'Atish Patra ' , 'Anup Patel ' , 'Sia Jee Heng ' , Anup Patel Subject: [PATCH v2 11/11] platform: generic: Add system suspend test Date: Mon, 27 Feb 2023 11:31:06 +0100 Message-Id: <20230227103106.137995-12-ajones@ventanamicro.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230227103106.137995-1-ajones@ventanamicro.com> References: <20230227103106.137995-1-ajones@ventanamicro.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230227_023135_433419_1A3851CA X-CRM114-Status: GOOD ( 18.78 ) X-Spam-Score: -0.2 (/) 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: When the system-suspend-test property is present in the domain config node as shown below, implement system suspend with a simple 5 second delay followed by a WFI. This allows testing system suspend w [...] Content analysis details: (-0.2 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2a00:1450:4864:20:0:0:0:436 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_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain 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 When the system-suspend-test property is present in the domain config node as shown below, implement system suspend with a simple 5 second delay followed by a WFI. This allows testing system suspend when the low-level firmware doesn't support it. / { chosen { opensbi-domains { compatible = "opensbi,domain,config"; system-suspend-test; }; Signed-off-by: Andrew Jones Reviewed-by: Anup Patel --- docs/domain_support.md | 4 ++++ include/sbi/sbi_system.h | 1 + lib/sbi/sbi_system.c | 31 +++++++++++++++++++++++++++++++ platform/generic/platform.c | 20 +++++++++++++++++++- 4 files changed, 55 insertions(+), 1 deletion(-) diff --git a/docs/domain_support.md b/docs/domain_support.md index 265d8d85786e..c13014a5f7cf 100644 --- a/docs/domain_support.md +++ b/docs/domain_support.md @@ -126,6 +126,9 @@ The DT properties of a domain configuration DT node are as follows: * **compatible** (Mandatory) - The compatible string of the domain configuration. This DT property should have value *"opensbi,domain,config"* +* **system-suspend-test** (Optional) - When present, enable a system + suspend test implementation which simply waits five seconds and issues a WFI. + ### Domain Memory Region Node The domain memory region DT node describes details of a memory region and @@ -234,6 +237,7 @@ be done: chosen { opensbi-domains { compatible = "opensbi,domain,config"; + system-suspend-test; tmem: tmem { compatible = "opensbi,domain,memregion"; diff --git a/include/sbi/sbi_system.h b/include/sbi/sbi_system.h index d70ef8bb8874..b4e86aef8949 100644 --- a/include/sbi/sbi_system.h +++ b/include/sbi/sbi_system.h @@ -66,6 +66,7 @@ struct sbi_system_suspend_device { const struct sbi_system_suspend_device *sbi_system_suspend_get_device(void); void sbi_system_suspend_set_device(struct sbi_system_suspend_device *dev); +void sbi_system_suspend_test_enable(void); bool sbi_system_suspend_supported(u32 sleep_type); int sbi_system_suspend(u32 sleep_type, ulong resume_addr, ulong opaque); diff --git a/lib/sbi/sbi_system.c b/lib/sbi/sbi_system.c index 7fa5ea82b7a6..6eaf6c9508e0 100644 --- a/lib/sbi/sbi_system.c +++ b/lib/sbi/sbi_system.c @@ -17,6 +17,7 @@ #include #include #include +#include static SBI_LIST_HEAD(reset_devices_list); @@ -108,6 +109,36 @@ void sbi_system_suspend_set_device(struct sbi_system_suspend_device *dev) suspend_dev = dev; } +static int sbi_system_suspend_test_check(u32 sleep_type) +{ + return sleep_type == SBI_SUSP_SLEEP_TYPE_SUSPEND; +} + +static int sbi_system_suspend_test_suspend(u32 sleep_type, + unsigned long warmboot_addr) +{ + if (sleep_type != SBI_SUSP_SLEEP_TYPE_SUSPEND) + return SBI_EINVAL; + + sbi_timer_mdelay(5000); + + /* Wait for interrupt */ + wfi(); + + return SBI_OK; +} + +static struct sbi_system_suspend_device sbi_system_suspend_test = { + .name = "system-suspend-test", + .system_suspend_check = sbi_system_suspend_test_check, + .system_suspend = sbi_system_suspend_test_suspend, +}; + +void sbi_system_suspend_test_enable(void) +{ + sbi_system_suspend_set_device(&sbi_system_suspend_test); +} + bool sbi_system_suspend_supported(u32 sleep_type) { return suspend_dev && suspend_dev->system_suspend_check && diff --git a/platform/generic/platform.c b/platform/generic/platform.c index 0b90fd7c1446..eeefef4c9533 100644 --- a/platform/generic/platform.c +++ b/platform/generic/platform.c @@ -13,6 +13,7 @@ #include #include #include +#include #include #include #include @@ -219,7 +220,24 @@ static int generic_extensions_init(struct sbi_hart_features *hfeatures) static int generic_domains_init(void) { - return fdt_domains_populate(fdt_get_address()); + void *fdt = fdt_get_address(); + int offset, ret; + + ret = fdt_domains_populate(fdt); + if (ret < 0) + return ret; + + offset = fdt_path_offset(fdt, "/chosen"); + + if (offset >= 0) { + offset = fdt_node_offset_by_compatible(fdt, offset, + "opensbi,domain,config"); + if (offset >= 0 && + fdt_get_property(fdt, offset, "system-suspend-test", NULL)) + sbi_system_suspend_test_enable(); + } + + return 0; } static u64 generic_tlbr_flush_limit(void)