From patchwork Mon Feb 27 10:30:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Jones X-Patchwork-Id: 1748591 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=vdD0M0hU; 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=b/3nUBzV; 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 4PQGy04Rykz1yWw for ; Mon, 27 Feb 2023 21:31:36 +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=ssmBupjrldbDrRit7iAQp1vIUGxEf8DYxKLe+PI6hyc=; b=vdD0M0hUBUkRgr a/+pMYGH2BgypvUI+hswY38Idw6NiqPzP4hlHIu6ngxIZO+2bfOy3hJu4FFppc0Kh4CtA734bUaw2 lGJwtPGMXTqsOriaZdFuvtLf7x5etIqnQv+alMWcd43KrUsMxfeLQlSbjbn7SdLKNmUVVRUU5mHS5 mzElrS2U9FOCmr3BepGNVeI1Cae4dT08fvZPuk84pciAbK1HslFy87ojbX3XuQY+EPsw3ZiPlJFPX xojPYxlg71S6KqVIEbxE+rb1KLdqeJy/p+kTLGBSq2pxSXv9FXmr7DaDq+bOXRiWi7hUxHu2KVq9H /xV7gXou7KczggKLyxyA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pWamu-009ETi-AI; Mon, 27 Feb 2023 10:31:20 +0000 Received: from mail-wm1-x331.google.com ([2a00:1450:4864:20::331]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1pWamq-009ESd-6e for opensbi@lists.infradead.org; Mon, 27 Feb 2023 10:31:18 +0000 Received: by mail-wm1-x331.google.com with SMTP id t25-20020a1c7719000000b003eb052cc5ccso6315109wmi.4 for ; Mon, 27 Feb 2023 02:31:15 -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=s1pT3SQbl6RirQPJiNT2WtpGzM9IQRHAmEMA62Ee3JQ=; b=b/3nUBzV7ZYIpRhCmDwMObjCIwdBjARFeTF/KR1xgnKlgLMlu4c+lf9lxf6I6Izib7 s5r9FZXOEZQfZrTAKuvGG9iyj0rGh6Iqp7RKl4Zr0fOwa2Gy5/gpXyY5rAnu+acn/nbU TqWr4CD0q3pP67Zhnm+dJak0UGA0hqWeg+qA7zR9wZ5xLQKepZxB72ypvalaSTzlx+Rg dkthhCDSULmOINPdwhdbCwb1X0WND9tPsuCZxjg8tKyW7HAe0rPFY6Ao/k6h4m9WIfQ5 TkrMuY8EDUZ4VXXwJ9G0ZAHlga09RZdM4jG7kCYhWtoavHX+MDRV85jVWcUI08Z/pd7F ufSQ== 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=s1pT3SQbl6RirQPJiNT2WtpGzM9IQRHAmEMA62Ee3JQ=; b=UyWGj4ReiZU4R6C8lDkQEvOsmtSOdh4V7UswHvdaGgp5ew2GyXubpgYyiFKBVwSPAr nQTdaWTY6OuFN4Q/kNH69tBj+i1zblt0pJerLswjSCL21iJkiK0ZtSm3gS3QqtrwdZpB u0xN4m6adMuZzEaK0U+i9VZeeyFMbIAohMrZ6UwabVg0FjVjt077fLZc/deXXAzyJ/pP 8MJ3e2jQNP+SSIfCYJSjWjSuZ+14C765kRrYESpZoVuYwm1s6GUIoP1/7VlDA3PjGzGu 2zDN+jxUwUlb9oYrJZpRnImeREh+hfvoaLc4qSaLPid2Wo8jcLcLrAkax+wdzVtKWELf DNnA== X-Gm-Message-State: AO0yUKUYPXn5lwzBeLon7QTj0+8JEgDwKwLIxYqTGTrYZ8ae7jk+KhZq hQ4JwqD++UsDTEJ17bpL4iVi1ezT7vZJqMjN X-Google-Smtp-Source: AK7set9oTpeAGzxSThkbgEQTJCT7KopQXaz68X4ZHgnMfgVWxKQdC/DyX9dvLGngwd7XeRAd9r5STw== X-Received: by 2002:a05:600c:1d8c:b0:3ea:ed4d:38f4 with SMTP id p12-20020a05600c1d8c00b003eaed4d38f4mr8699505wms.41.1677493874407; Mon, 27 Feb 2023 02:31:14 -0800 (PST) Received: from localhost (cst2-173-16.cust.vodafone.cz. [31.30.173.16]) by smtp.gmail.com with ESMTPSA id z22-20020a1c4c16000000b003e206cc7237sm11791400wmf.24.2023.02.27.02.31.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Feb 2023 02:31:13 -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 01/11] lib: sbi_hsm: Factor out invalid state detection Date: Mon, 27 Feb 2023 11:30:56 +0100 Message-Id: <20230227103106.137995-2-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_023116_267978_5EB713A3 X-CRM114-Status: GOOD ( 11.94 ) 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: Remove some redundant code by creating an invalid state detection macro. No functional change intended. Signed-off-by: Andrew Jones Reviewed-by: Anup Patel --- lib/sbi/sbi_hsm.c | 65 +++++++++++++++++ 1 file changed, 24 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:331 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 Remove some redundant code by creating an invalid state detection macro. No functional change intended. Signed-off-by: Andrew Jones Reviewed-by: Anup Patel --- lib/sbi/sbi_hsm.c | 65 +++++++++++++++++------------------------------ 1 file changed, 24 insertions(+), 41 deletions(-) diff --git a/lib/sbi/sbi_hsm.c b/lib/sbi/sbi_hsm.c index 8499bb1ddeae..b71ee6ba4e80 100644 --- a/lib/sbi/sbi_hsm.c +++ b/lib/sbi/sbi_hsm.c @@ -26,6 +26,15 @@ #include #include +#define __sbi_hsm_hart_change_state(hdata, oldstate, newstate) \ +({ \ + long state = atomic_cmpxchg(&(hdata)->state, oldstate, newstate); \ + if (state != (oldstate)) \ + sbi_printf("%s: ERR: The hart is in invalid state [%lu]\n", \ + __func__, state); \ + state == (oldstate); \ +}) + static const struct sbi_hsm_device *hsm_dev = NULL; static unsigned long hart_data_offset; @@ -95,13 +104,11 @@ int sbi_hsm_hart_interruptible_mask(const struct sbi_domain *dom, void sbi_hsm_prepare_next_jump(struct sbi_scratch *scratch, u32 hartid) { - u32 oldstate; struct sbi_hsm_data *hdata = sbi_scratch_offset_ptr(scratch, hart_data_offset); - oldstate = atomic_cmpxchg(&hdata->state, SBI_HSM_STATE_START_PENDING, - SBI_HSM_STATE_STARTED); - if (oldstate != SBI_HSM_STATE_START_PENDING) + if (!__sbi_hsm_hart_change_state(hdata, SBI_HSM_STATE_START_PENDING, + SBI_HSM_STATE_STARTED)) sbi_hart_hang(); } @@ -217,14 +224,12 @@ int sbi_hsm_init(struct sbi_scratch *scratch, u32 hartid, bool cold_boot) void __noreturn sbi_hsm_exit(struct sbi_scratch *scratch) { - u32 hstate; struct sbi_hsm_data *hdata = sbi_scratch_offset_ptr(scratch, hart_data_offset); void (*jump_warmboot)(void) = (void (*)(void))scratch->warmboot_addr; - hstate = atomic_cmpxchg(&hdata->state, SBI_HSM_STATE_STOP_PENDING, - SBI_HSM_STATE_STOPPED); - if (hstate != SBI_HSM_STATE_STOP_PENDING) + if (!__sbi_hsm_hart_change_state(hdata, SBI_HSM_STATE_STOP_PENDING, + SBI_HSM_STATE_STOPPED)) goto fail_exit; if (hsm_device_has_hart_hotplug()) { @@ -298,7 +303,6 @@ int sbi_hsm_hart_start(struct sbi_scratch *scratch, int sbi_hsm_hart_stop(struct sbi_scratch *scratch, bool exitnow) { - int oldstate; const struct sbi_domain *dom = sbi_domain_thishart_ptr(); struct sbi_hsm_data *hdata = sbi_scratch_offset_ptr(scratch, hart_data_offset); @@ -306,13 +310,9 @@ int sbi_hsm_hart_stop(struct sbi_scratch *scratch, bool exitnow) if (!dom) return SBI_EFAIL; - oldstate = atomic_cmpxchg(&hdata->state, SBI_HSM_STATE_STARTED, - SBI_HSM_STATE_STOP_PENDING); - if (oldstate != SBI_HSM_STATE_STARTED) { - sbi_printf("%s: ERR: The hart is in invalid state [%u]\n", - __func__, oldstate); + if (!__sbi_hsm_hart_change_state(hdata, SBI_HSM_STATE_STARTED, + SBI_HSM_STATE_STOP_PENDING)) return SBI_EFAIL; - } if (exitnow) sbi_exit(scratch); @@ -362,36 +362,26 @@ static void __sbi_hsm_suspend_non_ret_restore(struct sbi_scratch *scratch) void sbi_hsm_hart_resume_start(struct sbi_scratch *scratch) { - int oldstate; struct sbi_hsm_data *hdata = sbi_scratch_offset_ptr(scratch, hart_data_offset); /* If current HART was SUSPENDED then set RESUME_PENDING state */ - oldstate = atomic_cmpxchg(&hdata->state, SBI_HSM_STATE_SUSPENDED, - SBI_HSM_STATE_RESUME_PENDING); - if (oldstate != SBI_HSM_STATE_SUSPENDED) { - sbi_printf("%s: ERR: The hart is in invalid state [%u]\n", - __func__, oldstate); + if (!__sbi_hsm_hart_change_state(hdata, SBI_HSM_STATE_SUSPENDED, + SBI_HSM_STATE_RESUME_PENDING)) sbi_hart_hang(); - } hsm_device_hart_resume(); } void sbi_hsm_hart_resume_finish(struct sbi_scratch *scratch) { - u32 oldstate; struct sbi_hsm_data *hdata = sbi_scratch_offset_ptr(scratch, hart_data_offset); /* If current HART was RESUME_PENDING then set STARTED state */ - oldstate = atomic_cmpxchg(&hdata->state, SBI_HSM_STATE_RESUME_PENDING, - SBI_HSM_STATE_STARTED); - if (oldstate != SBI_HSM_STATE_RESUME_PENDING) { - sbi_printf("%s: ERR: The hart is in invalid state [%u]\n", - __func__, oldstate); + if (!__sbi_hsm_hart_change_state(hdata, SBI_HSM_STATE_RESUME_PENDING, + SBI_HSM_STATE_STARTED)) sbi_hart_hang(); - } /* * Restore some of the M-mode CSRs which we are re-configured by @@ -403,7 +393,7 @@ void sbi_hsm_hart_resume_finish(struct sbi_scratch *scratch) int sbi_hsm_hart_suspend(struct sbi_scratch *scratch, u32 suspend_type, ulong raddr, ulong rmode, ulong arg1) { - int oldstate, ret; + int ret; const struct sbi_domain *dom = sbi_domain_thishart_ptr(); struct sbi_hsm_data *hdata = sbi_scratch_offset_ptr(scratch, hart_data_offset); @@ -437,11 +427,8 @@ int sbi_hsm_hart_suspend(struct sbi_scratch *scratch, u32 suspend_type, scratch->next_mode = rmode; /* Directly move from STARTED to SUSPENDED state */ - oldstate = atomic_cmpxchg(&hdata->state, SBI_HSM_STATE_STARTED, - SBI_HSM_STATE_SUSPENDED); - if (oldstate != SBI_HSM_STATE_STARTED) { - sbi_printf("%s: ERR: The hart is in invalid state [%u]\n", - __func__, oldstate); + if (!__sbi_hsm_hart_change_state(hdata, SBI_HSM_STATE_STARTED, + SBI_HSM_STATE_SUSPENDED)) { ret = SBI_EDENIED; goto fail_restore_state; } @@ -484,13 +471,9 @@ fail_restore_state: * We might have successfully resumed from retentive suspend * or suspend failed. In both cases, we restore state of hart. */ - oldstate = atomic_cmpxchg(&hdata->state, SBI_HSM_STATE_SUSPENDED, - SBI_HSM_STATE_STARTED); - if (oldstate != SBI_HSM_STATE_SUSPENDED) { - sbi_printf("%s: ERR: The hart is in invalid state [%u]\n", - __func__, oldstate); + if (!__sbi_hsm_hart_change_state(hdata, SBI_HSM_STATE_SUSPENDED, + SBI_HSM_STATE_STARTED)) sbi_hart_hang(); - } return ret; } From patchwork Mon Feb 27 10:30:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Jones X-Patchwork-Id: 1748593 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=e66kX5VD; 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=PbjHvxOw; 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 4PQGy34Q7sz1yWw for ; Mon, 27 Feb 2023 21:31:39 +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=x2CCDprU5hIj1l9JjAET4bDzFEya8BpHpS/nWT5xqGE=; b=e66kX5VDVYC4fm 89TpmS5xblW6s/kNIntg1lz9/voiblo6UqYKZ6e8P5oyg0q5iVeon8uxaORgeqblJI7vBzq3Ud+EO IAzduHoflmjarGIO4NBisRDgC2W9S//SnuvRr912rbT5ZFv36c+ZO8IdLARAJU4Kxud8zCZrlbXua 4fdx5gtqqXhpU2xIFFNcXOQB15MobFpDkLOYkszWUM7eM+eVaUsAoIfamCmQi6dpz3HcUbDVDyBiL 9eiYR6+vF1yv5j3GpfKbJePyVWJT91+II2WTQcghLHE4mT09zyRfPaKAmn2b2qblw4+FgJSAJEi7t AAMxLOD8NRquQjG8uSQw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pWamz-009EVL-18; Mon, 27 Feb 2023 10:31:25 +0000 Received: from mail-wr1-x42d.google.com ([2a00:1450:4864:20::42d]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1pWamu-009ETE-Oj for opensbi@lists.infradead.org; Mon, 27 Feb 2023 10:31:22 +0000 Received: by mail-wr1-x42d.google.com with SMTP id bw19so5608965wrb.13 for ; Mon, 27 Feb 2023 02:31:18 -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=l5PNA7eCDnerEK00iHsatrtclCndJFVzJ3CruUMd+Wk=; b=PbjHvxOw5f93FI5n90BtaZU50WT+uvbe8N92GLQPxAOB6gzcWindD4n4Hya8UlUiBK 4QC7UbjTe+hAsvX3qfPFgP2FsRtulcae93+7z+ZjRIa0U9YMHADFASSJtNZNLPRngQyQ lN4OlYcgMA/LVmokCjv4IaYeBSotaLROWUux/7Br4Eo3EuDAI87ydL50a1Dxx4LBoJOV LDhFw16zszfeaFt/+4r48eNZtbJNSn2gH+XPVHLsmcvB7mB4zttKhUMiXCWQFqmdzGUX BmC8dKIuoW9kUZoLV/CZVvDkQO3Ul0tBO5/y7FcfyYS+ovHl2dnVLfaQv5oiAiKTQVsX Km9w== 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=l5PNA7eCDnerEK00iHsatrtclCndJFVzJ3CruUMd+Wk=; b=79oBqC1+TiYe7k0y//7x1vwFIbLoAxpX3LaWnYZ/POKW2vt9VmtfWPW7o4vnygppWJ C0VD6uwtQWMD2VzniMe4mWNdzoVYcIe0oTpzryF20yDZcqj6rrVbK1QPbypFYL7Tgi59 S0DEF/HVUd+vL4VUbT5hH/6zLukyR+KnYd2QZ/bJT3vjw1wkkHdU7QgaDwjyRRpUct/W gWq2vQnv49Vm0SQoWD55SSYCD2iHYA2Wwz7ZXiJD2ds8cqkjm3mmctLSa4CcFk50AId1 1Hs0vUOmTU1FNej9Tn5AFQ8iHjBN8gLr3XXKoK3gtGbB++DXOSN/YLAtx2eURjPHEZpj vEhA== X-Gm-Message-State: AO0yUKVBuulql+3i+/qhpoR/B2TQ5Zg+js00+sReekB1wTtQWI6rcSU5 6pJpBeOznVqUBQA7qg6whLj/gTjzaaKhYSnm X-Google-Smtp-Source: AK7set8B/qY5UcdUllm7IOt6u1Y8ql+WDJeje4c8gMPJVjWEQjuGJDxUrBLLSIzbFvSnGMMirX9Lhg== X-Received: by 2002:a5d:6acf:0:b0:2c7:17db:bf5a with SMTP id u15-20020a5d6acf000000b002c717dbbf5amr8609467wrw.5.1677493876734; Mon, 27 Feb 2023 02:31:16 -0800 (PST) Received: from localhost (cst2-173-16.cust.vodafone.cz. [31.30.173.16]) by smtp.gmail.com with ESMTPSA id u3-20020adfed43000000b002c55ec7f661sm7006449wro.5.2023.02.27.02.31.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Feb 2023 02:31:16 -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 02/11] lib: sbi_hsm: Don't try to restore state on failed change Date: Mon, 27 Feb 2023 11:30:57 +0100 Message-Id: <20230227103106.137995-3-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_023120_980586_5954D051 X-CRM114-Status: GOOD ( 10.11 ) 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 a state change fails there's no need to restore the original state as it remains the same. Signed-off-by: Andrew Jones Reviewed-by: Anup Patel --- lib/sbi/sbi_hsm.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) 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:42d 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 a state change fails there's no need to restore the original state as it remains the same. Signed-off-by: Andrew Jones Reviewed-by: Anup Patel --- lib/sbi/sbi_hsm.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/lib/sbi/sbi_hsm.c b/lib/sbi/sbi_hsm.c index b71ee6ba4e80..7ee4159256be 100644 --- a/lib/sbi/sbi_hsm.c +++ b/lib/sbi/sbi_hsm.c @@ -428,10 +428,8 @@ int sbi_hsm_hart_suspend(struct sbi_scratch *scratch, u32 suspend_type, /* Directly move from STARTED to SUSPENDED state */ if (!__sbi_hsm_hart_change_state(hdata, SBI_HSM_STATE_STARTED, - SBI_HSM_STATE_SUSPENDED)) { - ret = SBI_EDENIED; - goto fail_restore_state; - } + SBI_HSM_STATE_SUSPENDED)) + return SBI_EDENIED; /* Save the suspend type */ hdata->suspend_type = suspend_type; @@ -466,7 +464,6 @@ int sbi_hsm_hart_suspend(struct sbi_scratch *scratch, u32 suspend_type, jump_warmboot(); } -fail_restore_state: /* * We might have successfully resumed from retentive suspend * or suspend failed. In both cases, we restore state of hart. From patchwork Mon Feb 27 10:30:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Jones X-Patchwork-Id: 1748596 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=KmDzEkMA; 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=AuBMU01y; 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 4PQGyC6SrVz1yWw for ; Mon, 27 Feb 2023 21:31:47 +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=2CQDYvGWCBqqSMC4rtVgXJ51/cfTzxM94w5iFQcLwSs=; b=KmDzEkMAopnHFE 8PEfftCBjy3JcHVDI5KhT6PL2/DBpALZFs8UuAcaIgZOFB0PhoTqFlTASx+7G/X0uP2sgKNBWjoru U6TEYO8G6jeQ8OIpcG14yvnOg2Wz+A4IQT6lYpId2pWSj5kdAvhVc9Oc03hzzwOTSz39kJOpsdnw6 KkklzChUjsTGML4zqLqnla4SCbbxPrUbTTozrHHfTQKMhPylqsJCuR7oUGGwurQoTJaW3DwDKt6JG BrRlK1W6LBPexsrkBoZNqXfUT45pXXsJUCKS+f/F2KcRJIgGVpjBeyJ2B+4y1gZi1iZhK47b9E270 cDXBHLE7/uBhDzI+mKvw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pWan6-009EZz-8n; Mon, 27 Feb 2023 10:31:33 +0000 Received: from mail-wr1-x42b.google.com ([2a00:1450:4864:20::42b]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1pWamy-009ETe-8V for opensbi@lists.infradead.org; Mon, 27 Feb 2023 10:31:28 +0000 Received: by mail-wr1-x42b.google.com with SMTP id v16so2842013wrn.0 for ; Mon, 27 Feb 2023 02:31:20 -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=OX2TPXCHfeJ+nwhVtY/+me8cjItUMBpf05HV24+LlI8=; b=AuBMU01yeP+VGTom/EMInpnz4E0RRFB8azJRQd53Ew+0XG5f5MXRVPZGQSnFhxl9LM DsVHufTbjydv361nnNjO2MjpD2UeLnrnZDmZVaL9h468cPUNWnUkdprHCypcwsyEEZuw kmvyW3P3auaUBQ+2bkcsGHM96XYoxr7G9FY7Q4sU26nYXK70p7hGYAIVQVGPfzjQxZ/T ZNYGoHHky/NMCTx3Q3nr+5umhajHpHxI4ObNcoLJj4MPWoPqyIfGYh48pCla2/h/f2PD jGasxw0M6kOaTVC8uyFsXEGHfr+0wqSU+tar9KGtvN+Hmp7VwMiZLt/TZMjDhTLFjDeO RZKg== 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=OX2TPXCHfeJ+nwhVtY/+me8cjItUMBpf05HV24+LlI8=; b=0FQpT9gOBM7GDr4GqxRnewQ9rZ8qC8BReYeFmzGQcRfaR5GD6xir2yW2KFchuHe3MY z3MyiwGrFSL21F5oEmcPaey9SZII/rTsun36ZZAkiG3KVmrb8s7lPrO+fuI4Xz1JAQu8 TmKVPMB54ZQFO4u7povlviMejQo01AQfxb2SZwLh9HVcB7NFLl0lpAsmkhvrrnnXCSil cJQ9S+jLLHVfqF+pqkoOzmOHzWv1/gvFwFFrxOK5/mK8gOBVwVWeHOP48utX15MRjY4i kjJJDrm5hFiNCx9HQb/hygevf8fv/llW3mBclwE+wIU2cxTg0hQRJHC57hPQ6Mzd6lh9 q9gw== X-Gm-Message-State: AO0yUKW5AwdnxuVFYwGShjmhSyRA7uTaxhnohttYR2MV+71rmb8P5Hca MA/Yd/HMZ7b5mAsKFBozWEJaHhZYtbWvSzng X-Google-Smtp-Source: AK7set+Ze1HlTy0yS5ogm07w9jWVmbQ1ut0FfRkyI0MXQFBiNEv15vaD35e4jnWH8RfBsktVQdsOlQ== X-Received: by 2002:a05:6000:146:b0:2c9:a800:7d08 with SMTP id r6-20020a056000014600b002c9a8007d08mr6977935wrx.43.1677493878589; Mon, 27 Feb 2023 02:31:18 -0800 (PST) Received: from localhost (cst2-173-16.cust.vodafone.cz. [31.30.173.16]) by smtp.gmail.com with ESMTPSA id b15-20020a5d45cf000000b002c703d59fa7sm6654030wrs.12.2023.02.27.02.31.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Feb 2023 02:31:18 -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 03/11] lib: sbi_hsm: Ensure errors are consistent with spec Date: Mon, 27 Feb 2023 11:30:58 +0100 Message-Id: <20230227103106.137995-4-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_023124_317730_754838FF X-CRM114-Status: GOOD ( 11.92 ) 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: HSM functions define when SBI_ERR_INVALID_PARAM should be returned. Ensure it's not used for reasons that don't meet the definitions by using the catch-all code, SBI_ERR_FAILED, for those reasons inst [...] 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:42b 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 HSM functions define when SBI_ERR_INVALID_PARAM should be returned. Ensure it's not used for reasons that don't meet the definitions by using the catch-all code, SBI_ERR_FAILED, for those reasons instead. Also, in one case sbi_hart_suspend() may have returned SBI_ERR_DENIED, which isn't defined for that function at all. Use SBI_ERR_FAILED for that case too. Signed-off-by: Andrew Jones Reviewed-by: Anup Patel --- lib/sbi/sbi_hsm.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/sbi/sbi_hsm.c b/lib/sbi/sbi_hsm.c index 7ee4159256be..3455520b8a94 100644 --- a/lib/sbi/sbi_hsm.c +++ b/lib/sbi/sbi_hsm.c @@ -402,7 +402,7 @@ int sbi_hsm_hart_suspend(struct sbi_scratch *scratch, u32 suspend_type, /* Sanity check on domain assigned to current HART */ if (!dom) - return SBI_EINVAL; + return SBI_EFAIL; /* Sanity check on suspend type */ if (SBI_HSM_SUSPEND_RET_DEFAULT < suspend_type && @@ -415,7 +415,7 @@ int sbi_hsm_hart_suspend(struct sbi_scratch *scratch, u32 suspend_type, /* Additional sanity check for non-retentive suspend */ if (suspend_type & SBI_HSM_SUSP_NON_RET_BIT) { if (rmode != PRV_S && rmode != PRV_U) - return SBI_EINVAL; + return SBI_EFAIL; if (dom && !sbi_domain_check_addr(dom, raddr, rmode, SBI_DOMAIN_EXECUTE)) return SBI_EINVALID_ADDR; @@ -429,7 +429,7 @@ int sbi_hsm_hart_suspend(struct sbi_scratch *scratch, u32 suspend_type, /* Directly move from STARTED to SUSPENDED state */ if (!__sbi_hsm_hart_change_state(hdata, SBI_HSM_STATE_STARTED, SBI_HSM_STATE_SUSPENDED)) - return SBI_EDENIED; + return SBI_EFAIL; /* Save the suspend type */ hdata->suspend_type = suspend_type; From patchwork Mon Feb 27 10:30:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Jones X-Patchwork-Id: 1748594 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=KBkteTYi; 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=gvTyvDBm; 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 4PQGy46zvKz1yWw for ; Mon, 27 Feb 2023 21:31:40 +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=ViyO5Me9v9tpc33LZDGvxaaxBBHfMJmHw6lungxAXPM=; b=KBkteTYiJMRvLP EHBEOoRpuXJruZ9x0UB7fGN3ttDpJ5ONcdJpBvyQfmwj2DbypnfqtXWZJLP3/ksu2gpzQ+Es5mQWz qRSR8koaLug+ixMDePUVU40JcM9RRYND5hfT9JHni6lNa51mYb9ae7/Alhrej+jZK3HFgpz509nhX hWA9qVoyO+8JRggspBUh3WYKnHM+xFDtzmmBKAbCAYOWnNMIvrWJdZTsXMZhPwuaH2CI3upIWdTXV pJDmGyfeRGCKgMCqv/yamLysWt9Tu/JPXQHK9NPdDHcCSn0hCeE0YjTWMCXrSc0DR4WuIaPVN5hyS WWZN4dMQw/Vaduc2kyog==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pWan0-009EVp-Bh; Mon, 27 Feb 2023 10:31:26 +0000 Received: from mail-wm1-x331.google.com ([2a00:1450:4864:20::331]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1pWamv-009ESd-0G for opensbi@lists.infradead.org; Mon, 27 Feb 2023 10:31:22 +0000 Received: by mail-wm1-x331.google.com with SMTP id t25-20020a1c7719000000b003eb052cc5ccso6315349wmi.4 for ; Mon, 27 Feb 2023 02:31:20 -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=xzHODErJ2E0zNFIVq46+IZjfgCC/LkfKFtws9NyQeCM=; b=gvTyvDBmUCrSWYJelD09mbGLelE8846bXOk4kgRS0gR5tmns773DzqE0Bx4/ycB+jU jjWVeS4Ekos1BShewO+2lgEHY9TFBVa1pkyAe3hPpW6ijVEP9m6V/wehfRiPEwB9okfb HyiJ+tTZlrLgxzL/UQXEYdyZGO9ZQJ27/5C2h3i41j+GGs1KtxOKbcGEEF4ln1vGb7td BmaG+KEc8ANNoExgfWDt/JfxDwQVz4nnmIyZjE+ZHJ/S7df+y+oqaGuBZLqvkerY6Ud6 24mnMHcVxnxLHGzVuAR8MkPMemWyWQp34KnyfWmjg8NYzBc4WV6ntVmN2Bem2slP+GIM kYjQ== 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=xzHODErJ2E0zNFIVq46+IZjfgCC/LkfKFtws9NyQeCM=; b=Lqf6p4MbaeqsBiCQJ745UowcAQedFXpX8GwmlSbIjPan1eYohP3yD0O2gYLAr5OKAo ZEDzjf8VVxmkU2f6ij2MvSmkfRYKmYvPl6JTLg4ghwpEAAPJ0QJ4vtba+LnJMC1g4jf8 ju5ImtlXU86ELCR09x7uDrmPUGPhg6PiDE4vGA8Rd50ZzzVtg5Njvr/ZefHFYhpcbFg+ D2F25JHflna0u7Qm2gQ3bziUjMhAUJjz400T+lqqvBiLTFj1jS4oN70RvoJEw5qJFUyX usZtRMvpsUBoDKUXOTX1b8vApKiKJqbqq6siIotxeU0+H9luexdeYzXkMzUMknkE9OzC hvLw== X-Gm-Message-State: AO0yUKXqKWfFKDeZiFflArL+OMhigycOBGL454y6PauzR3ZvLTyBIkWF abJ10ptvf3K0Cq6OWiLckve9jA76a4gFCG4+ X-Google-Smtp-Source: AK7set/SIwdnRf6vZTilRqt6yRy1mBZzcUAD5VbJBqq2T9k5iv1fCaLA1TVCF9+DU6cDaT6fynYF7g== X-Received: by 2002:a1c:ed1a:0:b0:3ea:f6c4:305e with SMTP id l26-20020a1ced1a000000b003eaf6c4305emr9448094wmh.38.1677493880447; Mon, 27 Feb 2023 02:31:20 -0800 (PST) Received: from localhost (cst2-173-16.cust.vodafone.cz. [31.30.173.16]) by smtp.gmail.com with ESMTPSA id f5-20020a1c6a05000000b003d9aa76dc6asm12153121wmc.0.2023.02.27.02.31.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Feb 2023 02:31:20 -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 04/11] lib: sbi_hsm: Move misplaced comment Date: Mon, 27 Feb 2023 11:30:59 +0100 Message-Id: <20230227103106.137995-5-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_023121_097828_6505EB9F X-CRM114-Status: GOOD ( 10.76 ) 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: While non-retentive suspend is not allowed for M-mode, the comment at the top of sbi_hsm_hart_suspend() implied suspend wasn't allowed for M-mode at all. Move the comment above the mode check which is [...] 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:331 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 While non-retentive suspend is not allowed for M-mode, the comment at the top of sbi_hsm_hart_suspend() implied suspend wasn't allowed for M-mode at all. Move the comment above the mode check which is inside a suspend type is non-retentive check. Signed-off-by: Andrew Jones Reviewed-by: Anup Patel --- lib/sbi/sbi_hsm.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/sbi/sbi_hsm.c b/lib/sbi/sbi_hsm.c index 3455520b8a94..294156a9a7bd 100644 --- a/lib/sbi/sbi_hsm.c +++ b/lib/sbi/sbi_hsm.c @@ -398,8 +398,6 @@ int sbi_hsm_hart_suspend(struct sbi_scratch *scratch, u32 suspend_type, struct sbi_hsm_data *hdata = sbi_scratch_offset_ptr(scratch, hart_data_offset); - /* For now, we only allow suspend from S-mode or U-mode. */ - /* Sanity check on domain assigned to current HART */ if (!dom) return SBI_EFAIL; @@ -414,6 +412,10 @@ int sbi_hsm_hart_suspend(struct sbi_scratch *scratch, u32 suspend_type, /* Additional sanity check for non-retentive suspend */ if (suspend_type & SBI_HSM_SUSP_NON_RET_BIT) { + /* + * For now, we only allow non-retentive suspend from + * S-mode or U-mode. + */ if (rmode != PRV_S && rmode != PRV_U) return SBI_EFAIL; if (dom && !sbi_domain_check_addr(dom, raddr, rmode, From patchwork Mon Feb 27 10:31:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Jones X-Patchwork-Id: 1748595 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=3Qj5xQWj; 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=hyMkx+jO; 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 4PQGy94G6Dz1yWw for ; Mon, 27 Feb 2023 21:31:45 +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=b+AhxScygGJPn+0CtW+KT8ieXAsZVjEwaA+F8/v6iA0=; b=3Qj5xQWjLrybX2 O1rCWJbd6g/qE4lImzyv/1FhdZDp5ZeR8Rh/YmcfKU0t4EDgwj27XekCshdPzGz69dY9CAcjT5JQn 1odZ5uCL0mWExvC2MTiiVvtMMdwTgbOKp1DLVA2OP/cn2LdHRYg8zZ/tqYcdY0Fwp2+0IfjFfWFV1 lX49VImsPjgThCMGGDrpaD9Nw419TqhHhfD6rScbSUzyr6oH5UMwuw7QG/p2aN/Z8jTlzMo5f9pTN mQZQCt//rO92lLt7Nv7BPc9Px9AlamElkJpey1W5CyNn+RYwe2UefrSj4ZmE71d7oJLwZki3Mg7am R+9hW6MmNWd/gz4rW5ZQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pWan4-009EYq-Rz; Mon, 27 Feb 2023 10:31:30 +0000 Received: from mail-wr1-x433.google.com ([2a00:1450:4864:20::433]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1pWan0-009EUg-D0 for opensbi@lists.infradead.org; Mon, 27 Feb 2023 10:31:28 +0000 Received: by mail-wr1-x433.google.com with SMTP id v16so2842232wrn.0 for ; Mon, 27 Feb 2023 02:31:23 -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=/Ze+4S8+McZ3JvR/TH/XBHJO99QHFmkQO3DWS7xDsJ4=; b=hyMkx+jO3WY3J7OSuraSrh9AWNiNJ6wQXHZOvRuAMMMJjuUuY4KckARmtfGCWWSxth qOFDL3kPAP7aiNHoIGMsg9BAYOSN3XZ3VOEFrSefUeibCCIKM8x0BUK5jqJPfC3c/xRh k5QuO9I8huUQXaqN2naf+RLcBfaNoiZoCt/pirZk3qwcz5ZPtuuulcOhGyUUuyj2tuu7 IvSR28RxvsDZ9tiXqpE0mGJk//CWuxSna0cNjWMGX9FD8OuTHu55yHg65WWXIB69vOFZ myMpgp9QgMYoGaXtCR1bIPNdj+jp0Afw9YL+p415cLBrb/oNBdnUAvDzpK/+ckWNKMl6 Fp0A== 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=/Ze+4S8+McZ3JvR/TH/XBHJO99QHFmkQO3DWS7xDsJ4=; b=F55Ge8ouoAqtmkKiCjhNBeuHEDrqqCQjpy9xXtpx0rREgISEHWJf3GrrismFO4r632 cwsbL6VfLgSvIkr1kTzdFQwE6B2r6qV32xgKM60xxCvbhzzS2KolpQkJ5yLyAUeT8t7W XknRrk/MpvnUsVyNx3slvh8wEtyjl3mWlf8slIj1qyxdFaU8mPPLl6PL3X4Ykxx55hri JS8pK5CZFFABrr+vqnb8Qtf40ZkIdcX7UdIaV9GCXw9bhoM7I7rapAhJuleKO6fn4KSH RyqwtHOC37AQy+KMhH+CGZLh+PrqjbxXzysfu3N9JjyilzqupxzNLnvLMBM8WMOxl6Tv /Hfw== X-Gm-Message-State: AO0yUKUxz+PaoEFWrCXLWtOY3Uj4nKLaAYP20dAloT6G3lcbTqAOulDf O1LlZIjgO8yQSJ9eSX//bMFuzIxOvJOMPnym X-Google-Smtp-Source: AK7set8m/ltkibfpw/AYB2hQ/A8TUKwaiyFco00LY/qSwCYOa2u5I+FzQVyvXeSWdqUDWhzvnF6DnQ== X-Received: by 2002:a5d:69cd:0:b0:2c5:9ef9:9bab with SMTP id s13-20020a5d69cd000000b002c59ef99babmr18610872wrw.43.1677493882420; Mon, 27 Feb 2023 02:31:22 -0800 (PST) Received: from localhost (cst2-173-16.cust.vodafone.cz. [31.30.173.16]) by smtp.gmail.com with ESMTPSA id u6-20020a05600c00c600b003e21dcccf9fsm11933128wmm.16.2023.02.27.02.31.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Feb 2023 02:31:22 -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 05/11] lib: sbi_hsm: Remove unnecessary include Date: Mon, 27 Feb 2023 11:31:00 +0100 Message-Id: <20230227103106.137995-6-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_023126_502741_C929C554 X-CRM114-Status: GOOD ( 11.05 ) 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: Also remove a superfluous semicolon and add a blank line. Signed-off-by: Andrew Jones Reviewed-by: Anup Patel --- lib/sbi/sbi_ecall_hsm.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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: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_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 Also remove a superfluous semicolon and add a blank line. Signed-off-by: Andrew Jones Reviewed-by: Anup Patel --- lib/sbi/sbi_ecall_hsm.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/sbi/sbi_ecall_hsm.c b/lib/sbi/sbi_ecall_hsm.c index 703a824493b4..f1b41d073b22 100644 --- a/lib/sbi/sbi_ecall_hsm.c +++ b/lib/sbi/sbi_ecall_hsm.c @@ -12,7 +12,6 @@ #include #include #include -#include #include #include #include @@ -45,7 +44,8 @@ static int sbi_ecall_hsm_handler(unsigned long extid, unsigned long funcid, break; default: ret = SBI_ENOTSUPP; - }; + } + if (ret >= 0) { *out_val = ret; ret = 0; From patchwork Mon Feb 27 10:31:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Jones X-Patchwork-Id: 1748597 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=SneLxfrA; 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=Ay8WylRm; 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 4PQGyG4xZkz1yWw for ; Mon, 27 Feb 2023 21:31:50 +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=TRAF5E5h9g2kdqijoJr4J30LXuXxddLK3BR5LjCjbnE=; b=SneLxfrAj91Lav wSI/nMCIGij1WNDLHVSiDZ16PoYG3UjoFSMn7+rc6tLWQZwnYijSlM1Lh4WrWcZnO8mmEtLJitaEB PjtCp/OmO9OpCVyHv3gpts1BJaZmkn3NwHpG6efoWX2sKwdzbb0tn8OLljLvzkC+Ejztu9AbcXqyx dw4cEd/cRF9OixpI4PcmTGCne0aOrPwL2HRVm6n5ikPJP4BSuXFrmZlv72NKHJIGoTEc3OPdaNLzs 2roWALgBUnfJPAXh3yiDLxi0laB81xDTWUZKw6neQGBSqrv1SNNuYArx7VNk6nPmuQOtn5xbWawTy UVRar3WjQn+NmHiRdx4Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pWan9-009Ec8-5g; Mon, 27 Feb 2023 10:31:35 +0000 Received: from mail-wr1-x435.google.com ([2a00:1450:4864:20::435]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1pWan2-009EVI-ED for opensbi@lists.infradead.org; Mon, 27 Feb 2023 10:31:31 +0000 Received: by mail-wr1-x435.google.com with SMTP id bt28so5638393wrb.8 for ; Mon, 27 Feb 2023 02:31:25 -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=nlMS+i6dlWZNklC8Ztba3ByzNdnkQang/Dkeotu66UA=; b=Ay8WylRmQn/1JEH8ozsioTc4H5sS1+pzBeCAUpwAg/Gjzr8/8xb25JvhqwBjZ4BWrb +6o9GS9F1X4IZNWuzyPBaJrg76GTBS+GxLoD9pOdqAbyZRR7H1STKWv+Q+2qfZeAqL6z 0y7w9Tb2IwuVazl5g/pOlbeNML7LTdMyY48XH9sW3KPXoXa5IhwEIgT25sCqkazGtVBG LT+sHQi8A+0TuAI+p8f7Kd9w/pf6V5tkE6ohVGgKbpSqH9vduBCrkGyRPAwr3mRmSFeA 85pUUVtdMCnCp/O9ixkxJ10YckFMi0o1RpMsoo4MoLkvUAo5Upk9+8mvxCh7vGzye7bN e+NA== 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=nlMS+i6dlWZNklC8Ztba3ByzNdnkQang/Dkeotu66UA=; b=spvR6tIeEdmd7nvGNQha54U4ofXsTyewTnHfhRRN6NMlHw5nx57Tj8r3RoaqcJlMrb e+oQO7v0bR/rD6xKNEhPygmuubufPfJJ6fjX3U1MTpeMPB+534NTgHeqwgBLhwMZ+LPv q+O6XhF1Uvgdzpf7rb9p93Qkux6Gvps6siXuPAZGNsGUKtFHBXE59tOg9vl0AwKJsthK R30A0iQgMkxXlrnGTAKdNIzgNvHip0b1fWSyr2H9Pk3sHzDRE/aptDrtIt1w7CsDIaYC 97yrABsmH9s9GOEIx2+GzO7cAbcaYYHWNqYL931iOD7t7V3aXcEZHwzQ1KEZCdnvVSXv tcAg== X-Gm-Message-State: AO0yUKUWdtxxe4w5LVgpBk50gnCEo7iHAfvIYVHlsvvcy/7/IIo/koNx N59wUXJlWrMn7StLsdlnLaDDSFGeYRxWFD/M X-Google-Smtp-Source: AK7set/WvUHnEr31gCTczinQeEr6Xj3cNUmB+Irff3IXfApB0mJBjx1EPLOF48YfkKSAjLVA98puow== X-Received: by 2002:adf:cd82:0:b0:2c7:cc8:84a6 with SMTP id q2-20020adfcd82000000b002c70cc884a6mr14469748wrj.31.1677493884257; Mon, 27 Feb 2023 02:31:24 -0800 (PST) Received: from localhost (cst2-173-16.cust.vodafone.cz. [31.30.173.16]) by smtp.gmail.com with ESMTPSA id l3-20020a05600012c300b002c5694aef92sm6667451wrx.21.2023.02.27.02.31.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Feb 2023 02:31:23 -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 06/11] lib: sbi_hsm: Export some functions Date: Mon, 27 Feb 2023 11:31:01 +0100 Message-Id: <20230227103106.137995-7-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_023128_521478_6BEDD318 X-CRM114-Status: GOOD ( 10.32 ) 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: A coming patch can make use of a few internal hsm functions if we export them. Signed-off-by: Andrew Jones Reviewed-by: Anup Patel --- include/sbi/sbi_hsm.h | 4 ++++ lib/sbi/sbi_hsm.c | 12 ++++++++++-- 2 files changed, 14 insertion [...] 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: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_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 A coming patch can make use of a few internal hsm functions if we export them. Signed-off-by: Andrew Jones Reviewed-by: Anup Patel --- include/sbi/sbi_hsm.h | 4 ++++ lib/sbi/sbi_hsm.c | 12 ++++++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/include/sbi/sbi_hsm.h b/include/sbi/sbi_hsm.h index 1170127baa87..c0b483030de8 100644 --- a/include/sbi/sbi_hsm.h +++ b/include/sbi/sbi_hsm.h @@ -69,9 +69,13 @@ void sbi_hsm_hart_resume_start(struct sbi_scratch *scratch); void sbi_hsm_hart_resume_finish(struct sbi_scratch *scratch); int sbi_hsm_hart_suspend(struct sbi_scratch *scratch, u32 suspend_type, ulong raddr, ulong rmode, ulong arg1); +bool sbi_hsm_hart_change_state(struct sbi_scratch *scratch, long oldstate, + long newstate); +int __sbi_hsm_hart_get_state(u32 hartid); int sbi_hsm_hart_get_state(const struct sbi_domain *dom, u32 hartid); int sbi_hsm_hart_interruptible_mask(const struct sbi_domain *dom, ulong hbase, ulong *out_hmask); +void __sbi_hsm_suspend_non_ret_save(struct sbi_scratch *scratch); void sbi_hsm_prepare_next_jump(struct sbi_scratch *scratch, u32 hartid); #endif diff --git a/lib/sbi/sbi_hsm.c b/lib/sbi/sbi_hsm.c index 294156a9a7bd..3eeeb586cbb8 100644 --- a/lib/sbi/sbi_hsm.c +++ b/lib/sbi/sbi_hsm.c @@ -46,7 +46,15 @@ struct sbi_hsm_data { unsigned long saved_mip; }; -static inline int __sbi_hsm_hart_get_state(u32 hartid) +bool sbi_hsm_hart_change_state(struct sbi_scratch *scratch, long oldstate, + long newstate) +{ + struct sbi_hsm_data *hdata = sbi_scratch_offset_ptr(scratch, + hart_data_offset); + return __sbi_hsm_hart_change_state(hdata, oldstate, newstate); +} + +int __sbi_hsm_hart_get_state(u32 hartid) { struct sbi_hsm_data *hdata; struct sbi_scratch *scratch; @@ -328,7 +336,7 @@ static int __sbi_hsm_suspend_default(struct sbi_scratch *scratch) return 0; } -static void __sbi_hsm_suspend_non_ret_save(struct sbi_scratch *scratch) +void __sbi_hsm_suspend_non_ret_save(struct sbi_scratch *scratch) { struct sbi_hsm_data *hdata = sbi_scratch_offset_ptr(scratch, hart_data_offset); From patchwork Mon Feb 27 10:31:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Jones X-Patchwork-Id: 1748599 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=sTJ7GsOa; 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=l3/Ys1rX; 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 4PQGyS2mPTz1yWw for ; Mon, 27 Feb 2023 21:32:00 +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=G+vVrCVjIH2RaYIEpDKL+zQwwjtDjjuu3xuJ8wpIYVY=; b=sTJ7GsOa1AdtOq 2V9reVC9CHh9pZ3pCeve0zwbdIOVumXFCns3bdpGQKgur8JAKoa3QN1VoFU+1QihATRrKc7DOrQ2M lUeYYOuaLsLpXCPe33SZMFbMYWHAXYu7D/VNr3UXny5E7B7Hj71v3Hn8b9Nufjn2towRaf4wpmjJf 4Qz+A+v0RjfiVjc/iIhLJ908syVZmT8tOQWdTXPtHznvzkv7zfgiiDEc4O4JETtav2vKtn9lV26XJ UgUjzyR8jgraocX0tzAB0g44YHpzv00sQXYYwMxHnLY4/3CmiAhNZRnP0w0GoYjLb1pBWo9neqyXi gG0aCPO9Grh6bK7CSccQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pWanJ-009EjX-RR; Mon, 27 Feb 2023 10:31:46 +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 1pWan5-009EWH-0Z for opensbi@lists.infradead.org; Mon, 27 Feb 2023 10:31:41 +0000 Received: by mail-wm1-x32c.google.com with SMTP id j19-20020a05600c1c1300b003e9b564fae9so6764021wms.2 for ; Mon, 27 Feb 2023 02:31:27 -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=zgC2xcZGkSa+pwhzVvYAHnB3br85wjboYdpDKBMpvyw=; b=l3/Ys1rXm5IfkrxyvWoBet5r6rqHvS32UEP4Yvml1a7u6ScWM57HkGknKvBhSx8w5O PJYiIQoAl5J4PktLo1mU7xvDNX+LqfKSWPJw5dPiC6wFqS7pnII6I53vMvnFMEfdktti QIsjVikDK5L5YC+6N4ljGNqgXrcxWN47n7YXzNdXh3BejiRLP6r2iJyUAtKIm/Pnp/aF vy/jVlIarYxcU160/+OXCu4gAoDe8KbOKEBC2dw9eVdz5iltxNOvIXVeE+EECOQJfkmz zKgyYUdU5HUTX7KRorZFxQmha3dYokwn88P9mxTT+IdXVZEnvTfyw2fAWVNKAuFU6Lb6 3G4A== 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=zgC2xcZGkSa+pwhzVvYAHnB3br85wjboYdpDKBMpvyw=; b=4upIXKhbBCmR92NwjheZPW0SP+SHISpXASZhRcFaKAIXUkc1NrYN8cQ65Gcyque+rH a1VGa1vBCyRqPaqbF74i2HgH6MwwtHI3Ooxn6FA2O6SDz5NaAJfDvAVW/T9Y4wlf93+d wPIg/95QSiGSlvYRRREMRhYKTiLhI7Q9a9NR7JoSCXfFdICXnxJcpHA7vNwbK6V8lwU0 rbAj7m5CUnihky0ZOGcj90ZLc2f32SBPqrSzOcHBI9LrPb2eR/1DNsJdUKrkZiPmPzaS TB0f4k2u8XGkBd4qpCHkz8hDk8lzRqZZFZdcl7k+LmTrBXXcwhEF9Uo6mZGJLmzk0CRf y38g== X-Gm-Message-State: AO0yUKVVxI/uFMS9xDMlnd8HD5mpgg3GbxnYczUmBkpsY7gz0+n1Z1nW DpAamt+7l/DiT7b/UBf0bBk50tobCyeTHefi X-Google-Smtp-Source: AK7set+qvZ0sACwJA5xeJncd+PKIdNZXLr8H6ELmQ09+1fGPlRCbNzGRBMzYiXpuAFATdJxbxPpkJQ== X-Received: by 2002:a05:600c:713:b0:3dc:4b87:a570 with SMTP id i19-20020a05600c071300b003dc4b87a570mr13049258wmn.35.1677493886009; Mon, 27 Feb 2023 02:31:26 -0800 (PST) Received: from localhost (cst2-173-16.cust.vodafone.cz. [31.30.173.16]) by smtp.gmail.com with ESMTPSA id p4-20020a05600c358400b003dc5b59ed7asm9164517wmq.11.2023.02.27.02.31.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Feb 2023 02:31:25 -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 07/11] lib: sbi: Add system suspend skeleton Date: Mon, 27 Feb 2023 11:31:02 +0100 Message-Id: <20230227103106.137995-8-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_023131_400498_D4577607 X-CRM114-Status: GOOD ( 23.27 ) 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: Add the SUSP extension probe and ecall support, but for now the system suspend function is just a stub. Signed-off-by: Andrew Jones Reviewed-by: Anup Patel --- include/sbi/sbi_ecall_interface.h | 8 ++++++ include/sbi/sbi_system.h | 26 +++++++++++++++++ lib [...] 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 Add the SUSP extension probe and ecall support, but for now the system suspend function is just a stub. Signed-off-by: Andrew Jones Reviewed-by: Anup Patel --- include/sbi/sbi_ecall_interface.h | 8 ++++++ include/sbi/sbi_system.h | 26 +++++++++++++++++ lib/sbi/Kconfig | 4 +++ lib/sbi/objects.mk | 3 ++ lib/sbi/sbi_ecall_susp.c | 48 +++++++++++++++++++++++++++++++ lib/sbi/sbi_init.c | 4 +++ lib/sbi/sbi_system.c | 26 +++++++++++++++++ 7 files changed, 119 insertions(+) create mode 100644 lib/sbi/sbi_ecall_susp.c diff --git a/include/sbi/sbi_ecall_interface.h b/include/sbi/sbi_ecall_interface.h index 9d6f4743651d..4c378c3e7c30 100644 --- a/include/sbi/sbi_ecall_interface.h +++ b/include/sbi/sbi_ecall_interface.h @@ -30,6 +30,7 @@ #define SBI_EXT_SRST 0x53525354 #define SBI_EXT_PMU 0x504D55 #define SBI_EXT_DBCN 0x4442434E +#define SBI_EXT_SUSP 0x53555350 /* SBI function IDs for BASE extension*/ #define SBI_EXT_BASE_GET_SPEC_VERSION 0x0 @@ -236,6 +237,13 @@ enum sbi_pmu_ctr_type { #define SBI_EXT_DBCN_CONSOLE_READ 0x1 #define SBI_EXT_DBCN_CONSOLE_WRITE_BYTE 0x2 +/* SBI function IDs for SUSP extension */ +#define SBI_EXT_SUSP_SUSPEND 0x0 + +#define SBI_SUSP_SLEEP_TYPE_SUSPEND 0x0 +#define SBI_SUSP_SLEEP_TYPE_LAST SBI_SUSP_SLEEP_TYPE_SUSPEND +#define SBI_SUSP_PLATFORM_SLEEP_START 0x80000000 + /* SBI base specification related macros */ #define SBI_SPEC_VERSION_MAJOR_OFFSET 24 #define SBI_SPEC_VERSION_MAJOR_MASK 0x7f diff --git a/include/sbi/sbi_system.h b/include/sbi/sbi_system.h index 84c281383d8c..d70ef8bb8874 100644 --- a/include/sbi/sbi_system.h +++ b/include/sbi/sbi_system.h @@ -43,4 +43,30 @@ bool sbi_system_reset_supported(u32 reset_type, u32 reset_reason); void __noreturn sbi_system_reset(u32 reset_type, u32 reset_reason); +/** System suspend device */ +struct sbi_system_suspend_device { + /** Name of the system suspend device */ + char name[32]; + + /* Check whether sleep type is supported by the device */ + int (*system_suspend_check)(u32 sleep_type); + + /** + * Suspend the system + * + * @sleep_type: The sleep type identifier passed to the SBI call. + * @warmboot_addr: + * This is the same as sbi_scratch.warmboot_addr. Some platforms + * may not be able to return from system_suspend(), so they will + * jump directly to this address instead. Platforms which can + * return from system_suspend() may ignore this parameter. + */ + int (*system_suspend)(u32 sleep_type, unsigned long warmboot_addr); +}; + +const struct sbi_system_suspend_device *sbi_system_suspend_get_device(void); +void sbi_system_suspend_set_device(struct sbi_system_suspend_device *dev); +bool sbi_system_suspend_supported(u32 sleep_type); +int sbi_system_suspend(u32 sleep_type, ulong resume_addr, ulong opaque); + #endif diff --git a/lib/sbi/Kconfig b/lib/sbi/Kconfig index ef6728bab3ea..7eb3273d546e 100644 --- a/lib/sbi/Kconfig +++ b/lib/sbi/Kconfig @@ -22,6 +22,10 @@ config SBI_ECALL_SRST bool "System Reset extension" default y +config SBI_ECALL_SUSP + bool "System Suspend extension" + default y + config SBI_ECALL_PMU bool "Performance Monitoring Unit extension" default y diff --git a/lib/sbi/objects.mk b/lib/sbi/objects.mk index 319f38dce702..770238b25fa6 100644 --- a/lib/sbi/objects.mk +++ b/lib/sbi/objects.mk @@ -34,6 +34,9 @@ libsbi-objs-$(CONFIG_SBI_ECALL_HSM) += sbi_ecall_hsm.o carray-sbi_ecall_exts-$(CONFIG_SBI_ECALL_SRST) += ecall_srst libsbi-objs-$(CONFIG_SBI_ECALL_SRST) += sbi_ecall_srst.o +carray-sbi_ecall_exts-$(CONFIG_SBI_ECALL_SUSP) += ecall_susp +libsbi-objs-$(CONFIG_SBI_ECALL_SUSP) += sbi_ecall_susp.o + carray-sbi_ecall_exts-$(CONFIG_SBI_ECALL_PMU) += ecall_pmu libsbi-objs-$(CONFIG_SBI_ECALL_PMU) += sbi_ecall_pmu.o diff --git a/lib/sbi/sbi_ecall_susp.c b/lib/sbi/sbi_ecall_susp.c new file mode 100644 index 000000000000..f20126c49a60 --- /dev/null +++ b/lib/sbi/sbi_ecall_susp.c @@ -0,0 +1,48 @@ +// SPDX-License-Identifier: BSD-2-Clause +#include +#include +#include +#include +#include + +static int sbi_ecall_susp_handler(unsigned long extid, unsigned long funcid, + const struct sbi_trap_regs *regs, + unsigned long *out_val, + struct sbi_trap_info *out_trap) +{ + int ret = SBI_ENOTSUPP; + + if (funcid == SBI_EXT_SUSP_SUSPEND) + ret = sbi_system_suspend(regs->a0, regs->a1, regs->a2); + + if (ret >= 0) { + *out_val = ret; + ret = 0; + } + + return ret; +} + +static int sbi_ecall_susp_probe(unsigned long extid, unsigned long *out_val) +{ + u32 type, count = 0; + + /* + * At least one suspend type should be supported by the + * platform for the SBI SUSP extension to be usable. + */ + for (type = 0; type <= SBI_SUSP_SLEEP_TYPE_LAST; type++) { + if (sbi_system_suspend_supported(type)) + count++; + } + + *out_val = count ? 1 : 0; + return 0; +} + +struct sbi_ecall_extension ecall_susp = { + .extid_start = SBI_EXT_SUSP, + .extid_end = SBI_EXT_SUSP, + .handle = sbi_ecall_susp_handler, + .probe = sbi_ecall_susp_probe, +}; diff --git a/lib/sbi/sbi_init.c b/lib/sbi/sbi_init.c index e353c3348303..bc60a4279354 100644 --- a/lib/sbi/sbi_init.c +++ b/lib/sbi/sbi_init.c @@ -69,6 +69,7 @@ static void sbi_boot_print_general(struct sbi_scratch *scratch) const struct sbi_timer_device *tdev; const struct sbi_console_device *cdev; const struct sbi_system_reset_device *srdev; + const struct sbi_system_suspend_device *susp_dev; const struct sbi_platform *plat = sbi_platform_ptr(scratch); if (scratch->options & SBI_SCRATCH_NO_BOOT_PRINTS) @@ -103,6 +104,9 @@ static void sbi_boot_print_general(struct sbi_scratch *scratch) srdev = sbi_system_reset_get_device(SBI_SRST_RESET_TYPE_SHUTDOWN, 0); sbi_printf("Platform Shutdown Device : %s\n", (srdev) ? srdev->name : "---"); + susp_dev = sbi_system_suspend_get_device(); + sbi_printf("Platform Suspend Device : %s\n", + (susp_dev) ? susp_dev->name : "---"); /* Firmware details */ sbi_printf("Firmware Base : 0x%lx\n", scratch->fw_start); diff --git a/lib/sbi/sbi_system.c b/lib/sbi/sbi_system.c index f37c811d0bf3..5c123a6c9d8d 100644 --- a/lib/sbi/sbi_system.c +++ b/lib/sbi/sbi_system.c @@ -92,3 +92,29 @@ void __noreturn sbi_system_reset(u32 reset_type, u32 reset_reason) /* If platform specific reset did not work then do sbi_exit() */ sbi_exit(scratch); } + +static const struct sbi_system_suspend_device *suspend_dev = NULL; + +const struct sbi_system_suspend_device *sbi_system_suspend_get_device(void) +{ + return suspend_dev; +} + +void sbi_system_suspend_set_device(struct sbi_system_suspend_device *dev) +{ + if (!dev || suspend_dev) + return; + + suspend_dev = dev; +} + +bool sbi_system_suspend_supported(u32 sleep_type) +{ + return suspend_dev && suspend_dev->system_suspend_check && + suspend_dev->system_suspend_check(sleep_type); +} + +int sbi_system_suspend(u32 sleep_type, ulong resume_addr, ulong opaque) +{ + return 0; +} From patchwork Mon Feb 27 10:31:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Jones X-Patchwork-Id: 1748602 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=ucwoXhaX; 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=gm7u2du+; 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 4PQGyf2TT1z1yWw for ; Mon, 27 Feb 2023 21:32:10 +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=JHt8D4u167c2tvl1GpQPwekwhN9Jjyq3XkO80BRtkhU=; b=ucwoXhaXOX2YxS TxqJmNMpb6a21K5Gxxne5ESuoozetLTjMo+kyKO/0Hg6OIFOBdzcG3ueeiIFj4AKdWpqSVNTcSJBW 2CdNVm/ur4bP1d3T96h8UZf21KsSW4kL/Mw4bQTpaxvLsCrHzGNa2/pDYUx7mPB3wZhF3S+tVq9Xp ZOeA0hjKrUXIloAUeXLZhVRcJpzd8zKtadsYkavvlDXJwguynAo/3Pie9BgwAQjVtRqTNaDxO5h4h g3OLjFc6A23koH/wtiQUKUQT4ibHKZWkbQtRq2eTRrFo1Q8yE6Lu+uQY23Pn0qZatiYF7iA9RGuSm 9VQbgPPhb1EpPl34Sjpg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pWanP-009Eo4-7w; Mon, 27 Feb 2023 10:31:51 +0000 Received: from mail-wm1-x32e.google.com ([2a00:1450:4864:20::32e]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1pWan7-009EXS-F3 for opensbi@lists.infradead.org; Mon, 27 Feb 2023 10:31:43 +0000 Received: by mail-wm1-x32e.google.com with SMTP id k37so3937701wms.0 for ; Mon, 27 Feb 2023 02:31:29 -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=ELV1RcFmgJ2+B/oEHXRIRGor8RDVutps/1fcF5TP5tE=; b=gm7u2du+Y9c3PeO+4AKW1r8z6UI+kaDLBH/e2ykvCBM5AoBif5KHdFN2U1Ww48tlw7 QPVoaJcl5FndHFGim5F2M3ydcxgeQPhaPMZftOKstKDUpTBhifAmHlP5v+tmOTTQjnwA TJ17elAt5hjWXJWoiHFYgPknh1U+1DJe3u1Dg9ma8x5ZNGjH44HIalBeB6b8J112imGE BbdpfZXnjSpV/L0xgct7bSS7jjY5MmgbfJP87Lu0NXZMKn7yCOjoZYb2iwG/5reXHM0H yWifJhPrEH/tR49t/kudl/dLA1pSklJ+rk076U8Bx5FYXSP/5PZtkh8WxJ0GERsPCKsJ i+Uw== 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=ELV1RcFmgJ2+B/oEHXRIRGor8RDVutps/1fcF5TP5tE=; b=Nn7L0m/P81WysIiiidvNYne/LMcWPXbztXCl0a7UWti/Mq4BrNYeY3um78xjbzXO3R MkR8K9gqkTyF1niJ+XzHvmmIlFTWtazocDY3mFcnQ2hpI9oqJ/FFI8OPcL1kae+7JHBQ tRXLIXWGl3diWBeDpGyVNEBddhSPv8uRoNTmuHzPSR9jO5yRl7Fi1I0DdB/NogNEhMWq NHIdZJ+CoCjawor6ZbYQGkVbTXOdikCY1MZ+voTLRMDqwPPSb4fUJGgEUMBhOwS8QGc2 lYGzKaVfBs3XhkyOKv/AyzGVu7ma4JMZEm+cc+ruequ2+vJYlITmRZZBYKJJ5PjMozF6 NR9g== X-Gm-Message-State: AO0yUKX0/IrN8z+NhqcJYP433xRaZtvP5zCxWYxQM8+8/jCEBXmJ5GBW mmOeS0ReApKO1ehQJu5acwI0e5Vxala/b9qx X-Google-Smtp-Source: AK7set92twoAaAZ8ozyHhdJSWueMl8l2qInVpTFF52MUhjRdEjD0a4OmUauZix7RmY6BJF5U9ui8qw== X-Received: by 2002:a05:600c:746:b0:3eb:38e6:f652 with SMTP id j6-20020a05600c074600b003eb38e6f652mr6046165wmn.13.1677493887857; Mon, 27 Feb 2023 02:31:27 -0800 (PST) Received: from localhost (cst2-173-16.cust.vodafone.cz. [31.30.173.16]) by smtp.gmail.com with ESMTPSA id az11-20020a05600c600b00b003e1202744f2sm12106367wmb.31.2023.02.27.02.31.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Feb 2023 02:31:27 -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 08/11] lib: sbi: Add system_suspend_allowed domain property Date: Mon, 27 Feb 2023 11:31:03 +0100 Message-Id: <20230227103106.137995-9-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_023134_018061_90653CD2 X-CRM114-Status: GOOD ( 15.32 ) 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: Only privileged domains should be allowed to suspend the entire system. Give the root domain this property by default and allow other domains to be given the property by specifying it in the DT. Signed-off-by: Andrew Jones Reviewed-by: Anup Patel --- docs/domain_support.md | 5 +++++ include/sbi/sbi_domain.h | 2 ++ lib/sbi/sbi_domain.c | 4 ++++ l [...] 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:32e 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 Only privileged domains should be allowed to suspend the entire system. Give the root domain this property by default and allow other domains to be given the property by specifying it in the DT. Signed-off-by: Andrew Jones Reviewed-by: Anup Patel --- docs/domain_support.md | 5 +++++ include/sbi/sbi_domain.h | 2 ++ lib/sbi/sbi_domain.c | 4 ++++ lib/utils/fdt/fdt_domain.c | 7 +++++++ 4 files changed, 18 insertions(+) diff --git a/docs/domain_support.md b/docs/domain_support.md index 4ccbcff87195..e2ff896bd550 100644 --- a/docs/domain_support.md +++ b/docs/domain_support.md @@ -52,6 +52,7 @@ has following details: * **next_mode** - Privilege mode of the next booting stage for this domain. This can be either S-mode or U-mode. * **system_reset_allowed** - Is domain allowed to reset the system? +* **system_suspend_allowed** - Is domain allowed to suspend the system? The memory regions represented by **regions** in **struct sbi_domain** have following additional constraints to align with RISC-V PMP requirements: @@ -91,6 +92,7 @@ following manner: * **next_mode** - Next booting stage mode in coldboot HART scratch space is the next mode for the ROOT domain * **system_reset_allowed** - The ROOT domain is allowed to reset the system +* **system_suspend_allowed** - The ROOT domain is allowed to suspend the system Domain Effects -------------- @@ -195,6 +197,8 @@ The DT properties of a domain instance DT node are as follows: stage mode of coldboot HART** is used as default value. * **system-reset-allowed** (Optional) - A boolean flag representing whether the domain instance is allowed to do system reset. +* **system-suspend-allowed** (Optional) - A boolean flag representing + whether the domain instance is allowed to do system suspend. ### Assigning HART To Domain Instance @@ -260,6 +264,7 @@ be done: next-addr = <0x0 0x80100000>; next-mode = <0x0>; system-reset-allowed; + system-suspend-allowed; }; udomain: untrusted-domain { diff --git a/include/sbi/sbi_domain.h b/include/sbi/sbi_domain.h index ab1a944b474b..eaca7f093271 100644 --- a/include/sbi/sbi_domain.h +++ b/include/sbi/sbi_domain.h @@ -120,6 +120,8 @@ struct sbi_domain { unsigned long next_mode; /** Is domain allowed to reset the system */ bool system_reset_allowed; + /** Is domain allowed to suspend the system */ + bool system_suspend_allowed; }; /** The root domain instance */ diff --git a/lib/sbi/sbi_domain.c b/lib/sbi/sbi_domain.c index dc825b0d95f6..b1cd837e4b70 100644 --- a/lib/sbi/sbi_domain.c +++ b/lib/sbi/sbi_domain.c @@ -38,6 +38,7 @@ struct sbi_domain root = { .possible_harts = &root_hmask, .regions = root_memregs, .system_reset_allowed = true, + .system_suspend_allowed = true, }; bool sbi_domain_is_assigned_hart(const struct sbi_domain *dom, u32 hartid) @@ -467,6 +468,9 @@ void sbi_domain_dump(const struct sbi_domain *dom, const char *suffix) sbi_printf("Domain%d SysReset %s: %s\n", dom->index, suffix, (dom->system_reset_allowed) ? "yes" : "no"); + + sbi_printf("Domain%d SysSuspend %s: %s\n", + dom->index, suffix, (dom->system_suspend_allowed) ? "yes" : "no"); } void sbi_domain_dump_all(const char *suffix) diff --git a/lib/utils/fdt/fdt_domain.c b/lib/utils/fdt/fdt_domain.c index 2b51a8ebe132..33653e2f555f 100644 --- a/lib/utils/fdt/fdt_domain.c +++ b/lib/utils/fdt/fdt_domain.c @@ -419,6 +419,13 @@ static int __fdt_parse_domain(void *fdt, int domain_offset, void *opaque) else dom->system_reset_allowed = false; + /* Read "system-suspend-allowed" DT property */ + if (fdt_get_property(fdt, domain_offset, + "system-suspend-allowed", NULL)) + dom->system_suspend_allowed = true; + else + dom->system_suspend_allowed = false; + /* Find /cpus DT node */ cpus_offset = fdt_path_offset(fdt, "/cpus"); if (cpus_offset < 0) From patchwork Mon Feb 27 10:31:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Jones X-Patchwork-Id: 1748600 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=j1OOlUAs; 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=O8LEb2FF; 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 4PQGyZ6kYBz1yWw for ; Mon, 27 Feb 2023 21:32:06 +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=tyLChlrPOiWEKuooQANhT9OrpWmV2cEfs7dVH4vKp4Y=; b=j1OOlUAsq4pEL6 mD7LaJ61R0vglVvx6jwr1fdrIM7IFrlWmFb+D03Bsem2KiynXDMB6FbvSYDVoaXTSKODqUyxkAmmp 7qzDbGKvdBGNmbhen+MQJ4C2MSTO2FLUfRdDFI2U3uvOJcp7lF6WtidxwaSybQChdOZRUKU8y2Cb4 KdA7UAIpab/U19G/49tMpjUSgRaki8KK8zcx5bidfjfQjG2gemRFL/6D/6E+5+o8qGsFFWyFmqD2x jFGMig15tO3YY+udxzBkLH8R5UJ1IFvJxqVWHLvvPRVKZC7GA5gC+ksdBnNKvMtO68avmdR3+n1aR 7LZ77i2mQxYyujYzMTIw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pWanN-009Emh-Kp; Mon, 27 Feb 2023 10:31:49 +0000 Received: from mail-wm1-x332.google.com ([2a00:1450:4864:20::332]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1pWan5-009EYg-9y for opensbi@lists.infradead.org; Mon, 27 Feb 2023 10:31:43 +0000 Received: by mail-wm1-x332.google.com with SMTP id j19-20020a05600c1c1300b003e9b564fae9so6764133wms.2 for ; Mon, 27 Feb 2023 02:31:30 -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=s7rK9fK3uFY3qyNOBWkas74Wbdl0/XsslwOrJTwgFzg=; b=O8LEb2FFgepoDZK+IaG/j/IGO5qmqU9/hEXaGalbeWKUfmik3XkKIdzpGy4AivXhUW 9lGZ+6ZLxFZSKQblkkKm/UN2YpRF3KEwJmjKwXDY2U2PJsAE2as8LfbrAU1O97hCg1Rs VSMD+kMtN/Bsl4m0PbMN950DYFspltPPEyEWjliW0umUB0HTzp+ESvpfIUh6CbMiTqok TKO7m5iP2PfjS7Rv+wyxwKCXJhTU4hRee1UuljNAeF8fn04pRZWYzwuNTsTiJApDZdG8 Cms2q7/DQAQn3iOfjzfMCm52k4gVp1Ee21j7zUqL9+POloC1bnceQkcSnsxOY3XQrK2L uTPw== 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=s7rK9fK3uFY3qyNOBWkas74Wbdl0/XsslwOrJTwgFzg=; b=pJ6CYNs2k6jly9SWMsh4kkBOBDBM7ogFN1T02kaMBpZV8pVObnmiX9zgxdTXfygJlZ P2FiqVwFQpGB9Ssd5BQVrGtAirF/y302SQ5kliGYDS14wWDFx12iQYRvOgwpbotP0w1K NUVV9D646Y+Fx0JAioG9JPe4SARNBFnSICit8kJ16FZduBQY/N/d1Isdpoy9x95o1PS0 tF5rwtNSRqCINGP6P7KadXaa0lsz/0z/+eG5UHocmT1uuxXebV8hJr6+A0TGNQm2G+DN dBFqiS8V/h/3OQZ0mWucQDTk81XYwpdTwA/sERZ1ty4vg/TdUIwJnpMCB3ae4eJVySvs 2ijg== X-Gm-Message-State: AO0yUKVw597gDyaLUOTJfNuWQnTiFI10vwNqoMYA8GeHn5TFN1rOSyUn TQrkbDzMTEyeQQavk+f6b5zn1rHWx6npDp6X X-Google-Smtp-Source: AK7set+MKZS+Np2b3nHnR4HN06TxqLeC7alC5bYNPXtUwrp7DpnRM64w1egguXPnpsRpeAueMM9wCg== X-Received: by 2002:a05:600c:511b:b0:3ea:f6c4:5f3f with SMTP id o27-20020a05600c511b00b003eaf6c45f3fmr8899156wms.13.1677493889624; Mon, 27 Feb 2023 02:31:29 -0800 (PST) Received: from localhost (cst2-173-16.cust.vodafone.cz. [31.30.173.16]) by smtp.gmail.com with ESMTPSA id m33-20020a05600c3b2100b003eaee9e0d22sm9183632wms.33.2023.02.27.02.31.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Feb 2023 02:31:29 -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 09/11] lib: sbi: Implement system suspend Date: Mon, 27 Feb 2023 11:31:04 +0100 Message-Id: <20230227103106.137995-10-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_023131_647264_F5742446 X-CRM114-Status: GOOD ( 13.70 ) 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:332 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..7fa5ea82b7a6 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, scratch->warmboot_addr); + 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(); } From patchwork Mon Feb 27 10:31:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Jones X-Patchwork-Id: 1748598 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=Y2lnQ7eM; 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=UkxfF5Pr; 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 4PQGyQ4q35z1yWw for ; Mon, 27 Feb 2023 21:31:58 +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=/OZYpmkOiebhAKv7eRNBTxv8Tv6SDKOiLx/zTVlU0q0=; b=Y2lnQ7eM4r0Pbd /nLWCpFHQkCQdUjy0RwOFrRzaF8hjGwesRA2449dbMxr4YK6xKwd8/FzAWo3MEbyxMCmBcuu0t+ma TyZtvBbAAI90Pxw8gdVsAth0bH527nmnyZWmPd9l6K7GIBKmN7PrpUHsDwpDJStMRgXmzi+oXTFrp NJwZqbeK3qro4XmrVTdapES5O3HDRqf2MSrjF+yQLZgz9YMdtnZm30ArCwQ7M8lpnYyXTvLYAnU9T 2arzMmoGgw5ve6pg3uifCjCyeQDEtTnlvyiQweZ9oxc3e9HC++CykHt64PBVD8Vq+VbxEuE8lF9Wy urPaDrIQ+A7MwIAO+D/w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pWanH-009Ehz-B3; Mon, 27 Feb 2023 10:31:43 +0000 Received: from mail-wr1-x42a.google.com ([2a00:1450:4864:20::42a]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1pWan9-009EZs-EA for opensbi@lists.infradead.org; Mon, 27 Feb 2023 10:31:41 +0000 Received: by mail-wr1-x42a.google.com with SMTP id bt28so5638771wrb.8 for ; Mon, 27 Feb 2023 02:31:32 -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=ZhtuDLRtqIVx4XVH6flozD3uUJOKIX5ySDp+uCTvUEs=; b=UkxfF5PrgaLAYneeIiBwZEcs4rCCDbVYpTQqFPv9RccaNpU0As9LUto70F6b8/Bsc6 QvdAUHuDW7cGAGuGEoHUjvF3xrB5msHyPgiRmnIAbKhzuId6+P2UuIllPahOCvghFgZO ziF3cI7ER02NbW7Gc7UnicrLFzKFxJ/LmxIoztwBKMK8uoIPEGYaC+c3EXRdRzsJy6Y1 JyMUxzvASbsKpftErm5ejiSqQ0C9RWlHBLXyInoEzRNZ+b5Oex904poaVeZh/EpeZviu CgavBfUsqON2v0yam3xE0hJS3H56yUnTF+DdUqnZKp2GhE7Z63K5fy8G+OBEXvhGGMJZ sC4w== 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=ZhtuDLRtqIVx4XVH6flozD3uUJOKIX5ySDp+uCTvUEs=; b=ACWRa5M14jmaBXGfyBU96yVkN6Y6jjyemcc9GzPcz/lOub1nRG0D5ET+AS+E2AyeJ3 BEGG5cTjV0tOXXRstzh5eQQDn+7AOy2gJsZc8UV46k59eJRE9RWXHh97SensgUf6xr4/ DUgBWFhAxJrXA1lFJPwNotGrDXQr+vtmV/dfF6QZtgQY05yioNCVfdsSvTvGDCzWfCgA ne6jPvJuC8sdZiMrV6tId1cuv23i0sK+UUZgen0rxdbv2AWQI3KqcY39jgUjzXVO5f23 UZwMsm/J7cy0vChEejnRO7s8wHiiySnY8cb3TypjxAfW7Qfi9JIo9g5vVJ+PA0RHJC75 Et8A== X-Gm-Message-State: AO0yUKWxnUBzGYaqv0KzJXnuiqbbvpiAluktNbRZSwwMXXh4CvQ5SUVr 5ufedzNu/OZZN5EMBl3FlwjLq852LXvKeG+Y X-Google-Smtp-Source: AK7set8CDBLzeb1pqMz4kfz9k1hNu9Jpub3XpNVwYa6Zg1fA/qhv1t1QNlOULpZL4XxHFHzUR1wukw== X-Received: by 2002:adf:fc10:0:b0:2c7:832:8ccf with SMTP id i16-20020adffc10000000b002c708328ccfmr17724435wrr.53.1677493891480; Mon, 27 Feb 2023 02:31:31 -0800 (PST) Received: from localhost (cst2-173-16.cust.vodafone.cz. [31.30.173.16]) by smtp.gmail.com with ESMTPSA id l17-20020a5d6691000000b002c54e26bca5sm6732409wru.49.2023.02.27.02.31.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Feb 2023 02:31:31 -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 10/11] docs: Correct opensbi-domain property name Date: Mon, 27 Feb 2023 11:31:05 +0100 Message-Id: <20230227103106.137995-11-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_572835_E63DA34B X-CRM114-Status: GOOD ( 10.48 ) 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: Replace the commas with dashes to correct the name. Signed-off-by: Andrew Jones Reviewed-by: Anup Patel --- docs/domain_support.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) 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:42a 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 Replace the commas with dashes to correct the name. Signed-off-by: Andrew Jones Reviewed-by: Anup Patel --- docs/domain_support.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/domain_support.md b/docs/domain_support.md index e2ff896bd550..265d8d85786e 100644 --- a/docs/domain_support.md +++ b/docs/domain_support.md @@ -207,9 +207,9 @@ platform support can provide the HART to domain instance assignment using platform specific callback. The HART to domain instance assignment can be parsed from the device tree -using optional DT property **opensbi,domain** in each CPU DT node. The -value of DT property **opensbi,domain** is the DT phandle of the domain -instance DT node. If **opensbi,domain** DT property is not specified then +using optional DT property **opensbi-domain** in each CPU DT node. The +value of DT property **opensbi-domain** is the DT phandle of the domain +instance DT node. If **opensbi-domain** DT property is not specified then corresponding HART is assigned to **the ROOT domain**. ### Domain Configuration Only Accessible to OpenSBI 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)