From patchwork Wed Jan 18 14:42:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Jones X-Patchwork-Id: 1728280 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=QyaiQkFB; 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=GlStVwcQ; 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 4NxpTJ4DtQz23gM for ; Thu, 19 Jan 2023 01:45:24 +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=Jf1Kg+da3hWmgNPkU8IsIfkMZeGmeQR+b5PzXhqhDZM=; b=QyaiQkFBsXctWE yEbf5fqiOA57WS5QMSAc0DSZPDpa53fwTSHQtXa7vPbw0KVA4KUCWDkfx/P+IEQpRCFCA4DdvfjyH 0K+KIZ9gPWXSBVk5HmWbW5FRXX9DbwbsgQ/SCn0l7SbiHR1MLyntXyYsJ9aY6FE8f3wizYclPh3T8 QGHqOTnOCQS/+B7xb+shuC1adAf2RR80KfIOsojj2t5tFMlMwcqOz8U6/J/fJwezr7xRKByskWeQT 8ZZednwAYCGG/qWu5txhmG1GX5QFCEbxNIaATYWl5gC1LKKhSPLWz4Qh/VxB2ZlM+jkJ7m4oXchQt W2gep8d7wEvoILYMumSg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pI9gY-001PRL-GI; Wed, 18 Jan 2023 14:45:06 +0000 Received: from mail-wm1-x32c.google.com ([2a00:1450:4864:20::32c]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1pI9eN-001OFS-Rv for opensbi@lists.infradead.org; Wed, 18 Jan 2023 14:42:54 +0000 Received: by mail-wm1-x32c.google.com with SMTP id e19-20020a05600c439300b003db1cac0c1fso73066wmn.5 for ; Wed, 18 Jan 2023 06:42:48 -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=s4cqFtPdqeyHzkujkYkmhOoenrw3r1Ke5f6L12T0uQA=; b=GlStVwcQzaqjJuLtZMdOq5qfykDTMPmXRZPdawC1uxV7T39R2J6HiWQVAzdMbdMqMT F/bXGLJFjDDjrMjA5B0JvkA0kmq+d5spsVPxqgAWMJ1cZVFK9vW6UFjRL+ah+mKU27IA jdFCT4EtYNiKtXjRODuhGeZmOn1rR53pch1z2ujRG21lpLN25TbfY2tgaT9k6x6cGDR1 thns6N5Z3eCejGN8RXosAF58EhJc9/LuCpsh62R8MZWnZAHWSoxav1OT6kj6i2jqhNJM ODscjh2KNUS6uuDCphVNlUFzr1sHtgp8jCzs2JkOrIvQFVCiQrFSmdhWQ69F5uSeirPL aGIQ== 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=s4cqFtPdqeyHzkujkYkmhOoenrw3r1Ke5f6L12T0uQA=; b=gK+cNr6brq9zFbxz5gwAiLByP/lyyYwLyUg//2cCdC4OHKJD42Fk0vAajGQIMk8KG7 IkKSrQF4upUEstRjsKuOnE8wVaACoNs5Jhaem7YL2C7AE8711T/G+mreOb6eISXJMTKC 0VpdPeglR6ScnKop88hB5sstBUVXi2R3py84dun94bym3N9M//SOQPtBCSmVBXmXAlVr UBIw2lo7tZhYr7kpfUic3Pu6ov/CLzxXrO74KUtp+wrt8uN1Ihu0cOeSnP1Llnlg26Bd 7aDw31uUNIhdf+VyKQ1miUO4rZ8Aw8M0j560BgCzdeWN8sU6UIWxKZczgOuq/oJswvyw TltA== X-Gm-Message-State: AFqh2kqbB0cPeB8STHI7dj3RxhaLFNus8bqrEkEO1UDVEzwhY0GEH6mU Mj5GiiBJxJC+2qT+rCh9CHT/2OpYXW1sPQQB X-Google-Smtp-Source: AMrXdXsOsaEemkU3x75HPir4BvIWHK2v1XQGlsuvbXhbF88y2k6zlZosWq667X8O+dqoBzkmsRCnaA== X-Received: by 2002:a05:600c:4e50:b0:3da:4e:8dfe with SMTP id e16-20020a05600c4e5000b003da004e8dfemr6766386wmq.38.1674052967153; Wed, 18 Jan 2023 06:42:47 -0800 (PST) Received: from localhost (2001-1ae9-1c2-4c00-20f-c6b4-1e57-7965.ip6.tmcz.cz. [2001:1ae9:1c2:4c00:20f:c6b4:1e57:7965]) by smtp.gmail.com with ESMTPSA id i18-20020a05600c355200b003d9df9e59c4sm2554692wmq.37.2023.01.18.06.42.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Jan 2023 06:42:46 -0800 (PST) From: Andrew Jones To: opensbi@lists.infradead.org Cc: 'Atish Patra ' , 'Anup Patel ' , 'Ley Foon Tan ' , 'Sia Jee Heng ' , Anup Patel Subject: [PATCH 09/11] lib: sbi: Implement system suspend Date: Wed, 18 Jan 2023 15:42:32 +0100 Message-Id: <20230118144234.79263-10-ajones@ventanamicro.com> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230118144234.79263-1-ajones@ventanamicro.com> References: <20230118144234.79263-1-ajones@ventanamicro.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230118_064251_958222_4234D481 X-CRM114-Status: GOOD ( 13.20 ) 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: Fill the implementation of the system suspend ecall. A platform implementation of the suspend callbacks is still required for this to do anything. Signed-off-by: Andrew Jones Reviewed-by: Anup Patel --- lib/sbi/sbi_system.c | 57 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 56 insert [...] 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:32c 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 Fill the implementation of the system suspend ecall. A platform implementation of the suspend callbacks is still required for this to do anything. Signed-off-by: Andrew Jones Reviewed-by: Anup Patel --- lib/sbi/sbi_system.c | 57 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 56 insertions(+), 1 deletion(-) diff --git a/lib/sbi/sbi_system.c b/lib/sbi/sbi_system.c index 5c123a6c9d8d..c18562cdcfab 100644 --- a/lib/sbi/sbi_system.c +++ b/lib/sbi/sbi_system.c @@ -116,5 +116,60 @@ bool sbi_system_suspend_supported(u32 sleep_type) int sbi_system_suspend(u32 sleep_type, ulong resume_addr, ulong opaque) { - return 0; + int ret = SBI_ENOTSUPP; + const struct sbi_domain *dom = sbi_domain_thishart_ptr(); + struct sbi_scratch *scratch = sbi_scratch_thishart_ptr(); + void (*jump_warmboot)(void) = (void (*)(void))scratch->warmboot_addr; + unsigned int hartid = current_hartid(); + unsigned long prev_mode; + unsigned long i; + + if (!dom || !dom->system_suspend_allowed) + return SBI_EFAIL; + + if (!suspend_dev || !suspend_dev->system_suspend) + return SBI_EFAIL; + + if (!sbi_system_suspend_supported(sleep_type)) + return SBI_ENOTSUPP; + + prev_mode = (csr_read(CSR_MSTATUS) & MSTATUS_MPP) >> MSTATUS_MPP_SHIFT; + if (prev_mode != PRV_S && prev_mode != PRV_U) + return SBI_EFAIL; + + sbi_hartmask_for_each_hart(i, &dom->assigned_harts) { + if (i == hartid) + continue; + if (__sbi_hsm_hart_get_state(i) != SBI_HSM_STATE_STOPPED) + return SBI_EFAIL; + } + + if (!sbi_domain_check_addr(dom, resume_addr, prev_mode, + SBI_DOMAIN_EXECUTE)) + return SBI_EINVALID_ADDR; + + if (!sbi_hsm_hart_change_state(scratch, SBI_HSM_STATE_STARTED, + SBI_HSM_STATE_SUSPENDED)) + return SBI_EFAIL; + + /* Prepare for resume */ + scratch->next_mode = prev_mode; + scratch->next_addr = resume_addr; + scratch->next_arg1 = opaque; + + __sbi_hsm_suspend_non_ret_save(scratch); + + /* Suspend */ + ret = suspend_dev->system_suspend(sleep_type); + if (ret != SBI_OK) { + if (!sbi_hsm_hart_change_state(scratch, SBI_HSM_STATE_SUSPENDED, + SBI_HSM_STATE_STARTED)) + sbi_hart_hang(); + return ret; + } + + /* Resume */ + jump_warmboot(); + + __builtin_unreachable(); }