From patchwork Fri Jan 6 11:21: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: 1722372 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=kqdwCyhM; 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=JE4kpOeR; 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 4NpLXq47fZz23fc for ; Fri, 6 Jan 2023 22:22:35 +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=36V3GizzPJcWZWojUeTKRAJl2EB9BCZ/ayLeT7nK4sQ=; b=kqdwCyhMn20lRw vn5q4ZXCqZsRm8uIoEuTsfrfK+lw9DtWyE00AIrz4cKAlsYhgycZWbcxOlGrlEFWiiaz6WQ6BK5o+ BwekYW20wWc/RV0SlR3lkTRCfINQRaYwDsJrrSs7pzAblXjIY0BQIB5dxDZnGDCfmWcc0fA1iJNvw frD8DJkzBADs12MGTS6LjtzJpUR3z4u+J8d2kvoCRk3Q16UxhHUn6TtLdRwFWoHMw1jgkYU5GW6E7 NWFVZmx583C7/eZl1cMzf7/TYLuEljePhZ75lhVw7m2PJZZx1MnFgoDY60TZLhGhndG/QGPeOCV6u Dj3mvTS1w4WOutgvxlMA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pDknh-007i3r-F1; Fri, 06 Jan 2023 11:22:17 +0000 Received: from mail-wm1-x32b.google.com ([2a00:1450:4864:20::32b]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1pDkne-007i27-0z for opensbi@lists.infradead.org; Fri, 06 Jan 2023 11:22:15 +0000 Received: by mail-wm1-x32b.google.com with SMTP id i17-20020a05600c355100b003d99434b1cfso865724wmq.1 for ; Fri, 06 Jan 2023 03:22:13 -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=0rnBZ4k58u0ungUlPT+fSJXsZO9tAx669FZvmh/uKkg=; b=JE4kpOeRon6d6P4MWQYs47rgvE90z5uG+MVbSvKw+7lltp9+FYT1PNTV51/aKZOo+Z 7Yt8252PlVhTYR0XfwK9irudQgZUnbOyUwwuzqSgYb+HN98kiiec9K8+Cl9NAwfb5Zvl ZTkCpM+82HPlmDJPOgQ5MCH9FnfIhCW/uF0Wn2KvswXwyU+dru6lkfucZWKpZgl0TtHP tQSKhG5Jv/h4C6/uSGc7L84Fo/CU2ecmKlCA43ZrcgsXc/K/JKOcgGDSG786Do6Rmtm+ pTSdqLLqe3oaLczuhYajGcvHTU8NiKuiJWghJpiSZZINLkYgTt5IZArdN0nnqstJJy+O 4+9w== 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=0rnBZ4k58u0ungUlPT+fSJXsZO9tAx669FZvmh/uKkg=; b=peRUXjtaUsX0CiAFj7pL2p5YSIs0gFdKMhVlIANEv6fh1NDO1iUDesaMbLjr5nZ9Jt vx7pkIkuCmLVSlSWlDKPOXLn7FIw1zy79gaHC5BbvluZTtuTwh02SoE8MZSTdHLfFvdh NgQlRdAgH4mN2yi5gNOhrLUXcBhWGvx8G8v4n/X+bDQF/BHHTqd4djo1VzSs7uN2UrAL uO89X/MnO0pWvnl8n4w7gftaT2nDAK81PaGwDy3PSjSGHhCUc3Q5+0nF1hriIt0zQdvS JxJD/80eXPrIiJzso6bKl7vmlD1zCCUcwHKrLzaqBGeELdCgdQAtKfkrUv/9oy9nEYjT k2HQ== X-Gm-Message-State: AFqh2ko5KMF4IzziK81qFrjYoRPetX1cDrx9pO4Kzs/fxdkC7wjzlo1H EgVJbVFTooIKf7HJqTK2na8fY39CIrwp75wt X-Google-Smtp-Source: AMrXdXvKK6Nk1dFizJQFIw0UQoqFZCcnrqGvGKvLIPi7o2a9ac9+KXbLYQqYHR88pgCWyMkesb9E5g== X-Received: by 2002:a05:600c:4f48:b0:3d6:8570:1239 with SMTP id m8-20020a05600c4f4800b003d685701239mr48274885wmq.16.1673004132337; Fri, 06 Jan 2023 03:22:12 -0800 (PST) Received: from localhost (cst2-173-16.cust.vodafone.cz. [31.30.173.16]) by smtp.gmail.com with ESMTPSA id r10-20020a05600c458a00b003d35acb0fd7sm6335649wmo.34.2023.01.06.03.22.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 Jan 2023 03:22:12 -0800 (PST) From: Andrew Jones To: opensbi@lists.infradead.org Cc: 'Sia Jee Heng ' , 'Anup Patel ' , 'Ley Foon Tan ' , 'Atish Patra ' Subject: [RFC PATCH 01/11] lib: sbi_hsm: Factor out invalid state detection Date: Fri, 6 Jan 2023 12:21:59 +0100 Message-Id: <20230106112209.441825-2-ajones@ventanamicro.com> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230106112209.441825-1-ajones@ventanamicro.com> References: <20230106112209.441825-1-ajones@ventanamicro.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230106_032214_096162_85D331D2 X-CRM114-Status: GOOD ( 12.35 ) 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 --- lib/sbi/sbi_hsm.c | 65 +++++++++++++++++ 1 file changed, 24 insertions(+), 41 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:32b 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 836008fc92d7..1896f52c2ab2 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()) { @@ -299,7 +304,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); @@ -307,13 +311,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); @@ -363,36 +363,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 @@ -404,7 +394,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 priv) { - 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); @@ -438,11 +428,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; } @@ -485,13 +472,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 Fri Jan 6 11:22: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: 1722371 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=Sab/VeMi; 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=GTXNi9RH; 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 4NpLXq5rhXz23fn for ; Fri, 6 Jan 2023 22:22:35 +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=b8/k3bE7FHL/Tk5XYXwBT1R/CH5ljmNiZdZvXJjligY=; b=Sab/VeMibZTUt7 6OuInk0+T0DppfdX8ElTvo7ufTys3NQqbb6UXjHfzPjj7gHqxSsRhHAqJPmPlgu36yfDlNZ9KWUXz amPrkLwlXJjeoTDcqyb8YuGk+vY0XTMs/emhCY39hivpt1UHGjas5rgn9LYwkczp8DsYl2w/lme9Z U/E3qoDsvJx/ibve1gS2VIui0eO5ksBWYgJAPEwbaAT7CkHdSsIH8ONP0DtTukWPz+BYD7fe1mB4k wt82BSDN95mf0H4xKZ1OqrznL6D9M/dJeCR1j2XRcZCXkOXGgIF6gjVLkiKa0TdGwqlJzDLlB7LUr Bv3XkAXCkMfCtrlo00/g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pDknk-007i5k-Be; Fri, 06 Jan 2023 11:22:20 +0000 Received: from mail-wm1-x334.google.com ([2a00:1450:4864:20::334]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1pDknh-007i2l-Px for opensbi@lists.infradead.org; Fri, 06 Jan 2023 11:22:19 +0000 Received: by mail-wm1-x334.google.com with SMTP id b24-20020a05600c4a9800b003d21efdd61dso853925wmp.3 for ; Fri, 06 Jan 2023 03:22: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=IZSyslErJWgC+xyqHOu7hImqAOny20e5nC5UtJDaWrA=; b=GTXNi9RHUoFVIxfWQGF2AJC+22Ehr7njGCrKesp2zfPF0kl4m0qaNHJYF2CLhTZCDn L8s7FAy7Mg3wuSH13UL5UUkY0rdRDIbG82i+VaQ3WEh2X7V8VEUtxSX5iLhxQEgXLWPG rACuPwSaA2KN4Son1BtvjTyAZenwspQei1amed6b41RMoM6/AudPmvBbX1pWKiFXbOYV qlBw1U88u70o57jMBNmyP/v8y8aejj0O/3aSh2ZjPoELWXeH1PJVZXjoMSfvcNTLUbsa kfr5hAse0+BYqjQLE25EgFJxDHR646p/nt9CgEHxESEusoEZ3fxsSbaXOw58kmK+qJ7+ 5s6w== 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=IZSyslErJWgC+xyqHOu7hImqAOny20e5nC5UtJDaWrA=; b=FXYCx+Z93rHsJjxrn12a1AgR7z6H779cdBRT5qv1fL5d+hUgFzKBez7XEeLLK3FXKR f3T8oN8uOFda3wdHR5pCCmR4pBkGChE5VHoSU43dG6LWdbqxxN7ytmq1480KSGSkEhJZ wrc7/gbqjEMoA8y85iuIY07ugsDNS8aJghfKluq7LGbHdEby1se+zzE8rB8O/fGs/SKs bD19Ue1zGt2qPuuOi2ylGSMP6G3KLtYq2vn4SwR/H5LJDMpd5K6ojf0DJPV2xlxzypTV WCnrULj1tg5rIzKX1lnBQvkp9EvgyGVAzSaPOb6rn8vBoZmbxocvaxUeWQ25qR1IuXeC hPfQ== X-Gm-Message-State: AFqh2kqA+p658giDjrp7pN2pRJcCAxrjFEYibxQmXHsLQSssfIequGV7 ot0oHSW/LnZZzqEdRT9rjNh+I5iVNIsE/QR8 X-Google-Smtp-Source: AMrXdXuQTTMeCQl4Qao3ZjgUDdzqReeUsRomnC1VdkXd8YcxAONr5ueCsT6836irt1NxZ97Dh0SVSQ== X-Received: by 2002:a05:600c:1d0e:b0:3cf:8957:a441 with SMTP id l14-20020a05600c1d0e00b003cf8957a441mr5289561wms.12.1673004133910; Fri, 06 Jan 2023 03:22:13 -0800 (PST) Received: from localhost (cst2-173-16.cust.vodafone.cz. [31.30.173.16]) by smtp.gmail.com with ESMTPSA id bg24-20020a05600c3c9800b003cfa3a12660sm14247163wmb.1.2023.01.06.03.22.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 Jan 2023 03:22:13 -0800 (PST) From: Andrew Jones To: opensbi@lists.infradead.org Cc: 'Sia Jee Heng ' , 'Anup Patel ' , 'Ley Foon Tan ' , 'Atish Patra ' Subject: [RFC PATCH 02/11] lib: sbi_hsm: Don't try to restore state on failed change Date: Fri, 6 Jan 2023 12:22:00 +0100 Message-Id: <20230106112209.441825-3-ajones@ventanamicro.com> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230106112209.441825-1-ajones@ventanamicro.com> References: <20230106112209.441825-1-ajones@ventanamicro.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230106_032217_874072_40F495D3 X-CRM114-Status: GOOD ( 10.21 ) 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 --- 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:334 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 1896f52c2ab2..6ef6c5bdd4a7 100644 --- a/lib/sbi/sbi_hsm.c +++ b/lib/sbi/sbi_hsm.c @@ -429,10 +429,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; @@ -467,7 +465,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 Fri Jan 6 11:22: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: 1722373 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=umtN2jJy; 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=CCqffFIV; 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 4NpLXr3JkWz23fq for ; Fri, 6 Jan 2023 22:22: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=kOIbzQ85h5uy9A33OFB0pwz0Xm3UKNZrTV+3HZ1PRMY=; b=umtN2jJytGaG87 Ch7z89PqhUtZGlYCCBMpver9+nvaTkunU6akIZkqi+NBJFPAc6wIYUa9BqIlQWsJfov1FBaiF3SjF 4zhmjR1Xe+6SmdVGK6vvzOabI2OEo5bt+c+GEaSlw+VhLgE14sw/NGl6pp7KJFQA81vCLrckqc34/ 5EgKTHNbPNUI2TZ6rWnPV/vAHCh3pPlTwYA0QHoK9rdtJa1oxZ0LR3XsNjIwVEnr/WWBqITc68oLS 2/fxBD73gRX6DqtkJNRv0zykvJQWgyRahKCIScZozAdebWXFIiPgqIQFWTIY2PYLumrZlJJC99sql nMamCSxb4gXtw1fBZ4Hg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pDknl-007i6K-4x; Fri, 06 Jan 2023 11:22:21 +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 1pDknh-007i3B-QB for opensbi@lists.infradead.org; Fri, 06 Jan 2023 11:22:19 +0000 Received: by mail-wr1-x42a.google.com with SMTP id s9so973447wru.13 for ; Fri, 06 Jan 2023 03:22:16 -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=6zIWMy8OVGBLIFyH/EZ3AqXENiyhsmS66/S6uwBRvH8=; b=CCqffFIVw6pMGhGhPf4CtBNRpGT+yR7/Mkk8F+NEI9iN2n/yWygsW1X05jLABwhxbv BhtROihR33s8fp9nKFnwGQwfP3nKUgA4518+ZSHkypEANHEUiyXDfhGJf7ctV1ZGrYud +m7rtAcnMrrXeuF8iX+uAGXSpJHW073J/cN/1+4/ynwukCvr9seWY/vpN7Z65o4oFy7M 0Vxnkbtg71FJVWF7trDbewbiQZ2W4onpYHxMgZG/vN7UeoR5vUmJGt66l0nglP9Z31jM WTivp45dPdCeQDf3xVSQST7lFDmCrV+dq9tMWTuseaS/QlNbKRoCMzF028Nzn3GIvBE5 h2xA== 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=6zIWMy8OVGBLIFyH/EZ3AqXENiyhsmS66/S6uwBRvH8=; b=phxDbp3wshY+K1jQ/9Dj2SzixmH0WatnRTruEO9IgKfIsQhAxrkZO76d1NO24rSTam 9ZPwQCV7qlrf8j7y8hL7dn9+Jt2TEI3px4XjkeJuWnYc4bTCozURp1mHyIb2yi5iBZi8 7jh7LDW19eJhJy9Se/WF+iStE32XRjQc9WUdg1XlWdd/BMLyyDHBMO53R01te5V148yP x454kRecGpKzpiFAU6OgP9jiWvfPqd18mFYiMSDt928fSo+B3ql3Dr98gBvSTUz5bSWh dT1K3u6ETkwnjT5hBGjKIWX2oCo1m2myWuQML+F4oCdrLP9+lnZ7NKMauinVtFnXW/1p VryA== X-Gm-Message-State: AFqh2krYsVdWlOK8NJQ9ZIkmgcSdO3fx8WvM1NSp6ZQ/NwFlF360zimk BXvGF1lWEwFczq4UiADR5cfDIcu97yMKparI X-Google-Smtp-Source: AMrXdXtmNQjp/yl327zzY+jfRrVvhZ/xsC7mYLfzWoJtsp/3vIN+IENtjA06+fTWj4xqlSQgOBbFXg== X-Received: by 2002:a05:6000:170f:b0:24a:9a21:c9e with SMTP id n15-20020a056000170f00b0024a9a210c9emr32917498wrc.59.1673004135174; Fri, 06 Jan 2023 03:22:15 -0800 (PST) Received: from localhost (cst2-173-16.cust.vodafone.cz. [31.30.173.16]) by smtp.gmail.com with ESMTPSA id j11-20020adfd20b000000b0024207478de3sm874362wrh.93.2023.01.06.03.22.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 Jan 2023 03:22:14 -0800 (PST) From: Andrew Jones To: opensbi@lists.infradead.org Cc: 'Sia Jee Heng ' , 'Anup Patel ' , 'Ley Foon Tan ' , 'Atish Patra ' Subject: [RFC PATCH 03/11] lib: sbi_hsm: Ensure errors are consistent with spec Date: Fri, 6 Jan 2023 12:22:01 +0100 Message-Id: <20230106112209.441825-4-ajones@ventanamicro.com> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230106112209.441825-1-ajones@ventanamicro.com> References: <20230106112209.441825-1-ajones@ventanamicro.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230106_032217_882133_5E857D77 X-CRM114-Status: GOOD ( 12.10 ) 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: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 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 6ef6c5bdd4a7..3635f968e020 100644 --- a/lib/sbi/sbi_hsm.c +++ b/lib/sbi/sbi_hsm.c @@ -403,7 +403,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 && @@ -416,7 +416,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; @@ -430,7 +430,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 Fri Jan 6 11:22: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: 1722376 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=Xc63Q8vY; 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=eLcGDBrq; 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 4NpLXt4wL1z23fc for ; Fri, 6 Jan 2023 22:22:38 +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=AxR28+e4zZE43zekR4NuDcMDdBEZvRo/6g1mr454vN4=; b=Xc63Q8vY66oyTQ vLDxn74CnzPdCDUlrRl4WhwNJTgo4KOTFq0Y1wYXLjkx7zY/RLXZgQ8tJG8eKMt0unUHJ73Yk6eeL kZRULRBwe9SdcooaAXmM+1h+3TU9eY0SCY0stZPw8U+JoOPU0aR2Npse1vc7QcGJkw3QF2/aCIU1A PkgK3cElQWLppLOAVtRNO+UTYF40od0q6sloWcJwXg9o4BIY7FMKUsUPLa1kPeT6QcqA3I79RrVZy FyoX1DW8Jy3fSa7NJygs4qk3gkwH63iHcCSpASgA91gqXEpEfONvbhA+CRACs5RjbZy1zzomO4os8 o21NhPDTlD05G/u9Ol7Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pDknn-007i7g-6P; Fri, 06 Jan 2023 11:22:23 +0000 Received: from mail-wm1-x333.google.com ([2a00:1450:4864:20::333]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1pDknk-007i3u-GK for opensbi@lists.infradead.org; Fri, 06 Jan 2023 11:22:21 +0000 Received: by mail-wm1-x333.google.com with SMTP id fm16-20020a05600c0c1000b003d96fb976efso3305872wmb.3 for ; Fri, 06 Jan 2023 03:22:17 -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=9dbo7ETAv4ATw7Pn77wS2ZtCYQvg8blzHA/zEkRIJtc=; b=eLcGDBrq1Ewb81jd6ZJGf76HsktXbB5wDT7Gr1tEbhxcFhTUVCdUIyZLIh/BmhFVzI 7xdFKLKFBnpU4BpQjqT4XVyL0hR84D3AH2DDQQyWqMXkf+5xvddwwcUAlZiR8l/X1YKw V8aWy5l4SvdB5ICzwUHa8MLB91CYO51ug+yWLpiVIIHZESLDqjjblq0L/maq4xY3y8Nb yJxnTxQOX0A8eZd2oM0MNnXM94kA7rS/B0RHY0Fm4vvG1EAd/wtOppvAjcQqKHabGE/e XNuC24afXdKzD0ezt6MFGnye6pY/ekrg6PMVW+AUZZVuLNR+zalO6RjAh22Qu8Mmil5S Vnlw== 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=9dbo7ETAv4ATw7Pn77wS2ZtCYQvg8blzHA/zEkRIJtc=; b=nJfccenca/F+lxcx8mUGFE6B7UtCIPeYB4EhZc+q74F2TaGPWKmtmSFXek8xdW1Xza U35ZY1YibOm5e/fI9NVtZeRxe9AomvTiQZ8h2Vg4lXGhPmE0zT0ZpQX6lsBVAcnv6ZQi ilVdU/VQ5Y6pu7uIOvAA7SotBG1wDpkCpWeH4jX8ti0Ro21mMi779/26e3ZjwrHu+3mf q/eO33kCzGoU/Ok3V5EfPwzwqnfQy3qBPsdnTxSFhjY/RSpqfXvnpWLj1PULyHtVVs+U tnVSU3ChxJftFL2SL5gCgRTtuWkArix1B/HIMi3VOaJeBUKfklwiMP3kz2KwBu4Zh2d2 WO8g== X-Gm-Message-State: AFqh2kqPcXgJxxHFPELaaiHxPOSKeXuGvIqHS/VazmMy/uieKC0A33St 6psKMFHZFpoUZyC/mOOtDXJihCNRNiIv4nyp X-Google-Smtp-Source: AMrXdXuWBknxhgOgfVnSAmc9PeWmKX4ggcBGAa4R+zpSlOsIw71YekFZFtiZ6KA+Qhhm8Bnq97VU5Q== X-Received: by 2002:a05:600c:1911:b0:3d9:8635:a916 with SMTP id j17-20020a05600c191100b003d98635a916mr34058086wmq.9.1673004136538; Fri, 06 Jan 2023 03:22:16 -0800 (PST) Received: from localhost (cst2-173-16.cust.vodafone.cz. [31.30.173.16]) by smtp.gmail.com with ESMTPSA id c13-20020adffb0d000000b00241fde8fe04sm914543wrr.7.2023.01.06.03.22.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 Jan 2023 03:22:16 -0800 (PST) From: Andrew Jones To: opensbi@lists.infradead.org Cc: 'Sia Jee Heng ' , 'Anup Patel ' , 'Ley Foon Tan ' , 'Atish Patra ' Subject: [RFC PATCH 04/11] lib: sbi_hsm: Move misplaced comment Date: Fri, 6 Jan 2023 12:22:02 +0100 Message-Id: <20230106112209.441825-5-ajones@ventanamicro.com> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230106112209.441825-1-ajones@ventanamicro.com> References: <20230106112209.441825-1-ajones@ventanamicro.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230106_032220_622462_5D0CE453 X-CRM114-Status: GOOD ( 10.86 ) 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:333 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 3635f968e020..cce4b07bbb36 100644 --- a/lib/sbi/sbi_hsm.c +++ b/lib/sbi/sbi_hsm.c @@ -399,8 +399,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; @@ -415,6 +413,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 Fri Jan 6 11:22: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: 1722375 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=AjRc7Ka/; 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=H07c7kw3; 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 4NpLXs70b8z23fc for ; Fri, 6 Jan 2023 22:22:37 +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=289YPDQpQgxUeFzVQcDqwcg1MxKWedhSjKEsfidfpPY=; b=AjRc7Ka/TNAxf8 LBUmtaSfwMzOyT5i2zINvt1ZAf8hg9AWB/DnzAsZrGK3ot/l4LngIHCP82zvWWJWp5RXk2S8LO8eI O8DLw3/RQvyJ6K93wOWdC9478VaD38rYutJ9HMJwAp0WdtE+Iu5bz50+regS0/t2aMwl3XnQ+F+B4 fEg1tJsy7avwmlf6zLvupcuEveIoOjB7qZRL5Y0W71T3S6gsU5LGL1aDpD10pbFPZNpu1aAB8/kp4 Li/ehBkqP22USV09d5my4PJvjwkEoeuMVI3JfVMJubUmroWDxxUVwsBNKIjTQ4WEapD40Rg4eFjly YBCejG0cqaOZ5jTNcC/Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pDknm-007i6p-2I; Fri, 06 Jan 2023 11:22:22 +0000 Received: from mail-wm1-x32b.google.com ([2a00:1450:4864:20::32b]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1pDkni-007i27-GO for opensbi@lists.infradead.org; Fri, 06 Jan 2023 11:22:20 +0000 Received: by mail-wm1-x32b.google.com with SMTP id i17-20020a05600c355100b003d99434b1cfso865867wmq.1 for ; Fri, 06 Jan 2023 03:22: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=+adATilsLJ3uPG5W8jLJqsn0e4oqBHvIAfP8zJGosVc=; b=H07c7kw35UO1aqLx9LdaA011wlo7Tyc1RRIGosT8JMZwJtTW0BuQ7v+GQ73MGCXSUs LBHbp8/deCZHr6E6xHZpJHxb4YoXf1OchnBcqUVtea8BP0nI82CPtkHac9RQTpch90Tu R8eSHf7NRne4grptAScyEvWUgZLKHqaNkMR2usuSgBVboycTQrsPVMXiRN3FIKdBQeVD txbCHbzP+jUooFhYnzUlIy9WzEiFguenMi7ajGUDH1By9j9NLRlL/9IIx3ymMXpC8G+V WkLakMyel3wiHA3J4gAX6AnOzv7YvB5zXcKR9Ej9EyahjfOI7vbvd5OHe1V5o8yG9TfT FCdw== 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=+adATilsLJ3uPG5W8jLJqsn0e4oqBHvIAfP8zJGosVc=; b=4h/50B/gEC2qygfvsR9k5YkI7I2splEAbB4y1XljSWPBHPHAKtX8BJ2ZAlYSv30Zz4 QYSxx2aZcjNdo/51eQffxFST74KNXbiIoGpUHTbuBDkFXf/hPcWSfENWZ42E3zrSxgjD 0avU2BYCL/Eaka5KCPe55ruIcGJAv69WSKlxDkxrVnqnILvs8bERrmQGLhrKkwVLqNnZ InU1wILft3JAJwj5iVPFdVN+QYXW866wsf47bdsGtvjXsB5vIwfb5Tv8Kp6P389AM3n8 Ok172nGpf8dOifuSk7GKVKS8DDvCjEhQ93KFfadinGnmhXKNOq6Mkj1LW669o59Qv/IH reLA== X-Gm-Message-State: AFqh2kr/2SaDE7DZ3urqd4e2InAmSWXEWCwQa3HUYUxGNJ8OjbPRCGEq 6Gsnyoq4y1GQcXHvB91KtMRSOp90/GhZRfN6 X-Google-Smtp-Source: AMrXdXtbT7gZeptcui6rzhg5OTBjU7o1yOU2Z2ug785BrAR5vmx7l0UOlp+k6QJXufORpLNStylhzg== X-Received: by 2002:a05:600c:3789:b0:3d1:f234:12cc with SMTP id o9-20020a05600c378900b003d1f23412ccmr40469505wmr.33.1673004137967; Fri, 06 Jan 2023 03:22:17 -0800 (PST) Received: from localhost (cst2-173-16.cust.vodafone.cz. [31.30.173.16]) by smtp.gmail.com with ESMTPSA id p1-20020a05600c204100b003d99a39b846sm1581209wmg.5.2023.01.06.03.22.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 Jan 2023 03:22:17 -0800 (PST) From: Andrew Jones To: opensbi@lists.infradead.org Cc: 'Sia Jee Heng ' , 'Anup Patel ' , 'Ley Foon Tan ' , 'Atish Patra ' Subject: [RFC PATCH 05/11] lib: sbi_hsm: Remove unnecessary include Date: Fri, 6 Jan 2023 12:22:03 +0100 Message-Id: <20230106112209.441825-6-ajones@ventanamicro.com> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230106112209.441825-1-ajones@ventanamicro.com> References: <20230106112209.441825-1-ajones@ventanamicro.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230106_032218_583598_80F0EB76 X-CRM114-Status: GOOD ( 11.15 ) 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 --- 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 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 Fri Jan 6 11:22: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: 1722377 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=2E3iP0xx; 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=F9k46fCJ; 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 4NpLXx41Rtz23fc for ; Fri, 6 Jan 2023 22:22:41 +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=BORDFMEOC9Zfu6DzgnlWt4ylBfm3jnzAFUtLuYFRaMQ=; b=2E3iP0xx8hLxL8 /bhjodkHROiH2OMeLRnMZH9DnT3pK+MzpsZ/J69gavGHb5qbFniPHFzvz8JbLdHt2Y/fdAjWwGPBs i4BFFBvrh6RMvB3tbJ7VypexskVQnQX7TYHPpWAYeN2vJ9/9PWKWxEeozAe9qK9fHyqfkyih10Gln l/co8MycD6ur1yUx8G2scABir5gzZyZEX/qE9a19nTPtBWvRDkz321KGZ7QkxxFbPTR1fTC7PbX1J GZ3WGvHICoRdGVUzpIgcmCi2m5Ix9JStSCc31IBFqE43z2zsrYr5omjiOUmLvG0IDw6Gj2a1TqWxJ cSbUetDAytlFu24Wjwww==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pDknp-007i9C-6M; Fri, 06 Jan 2023 11:22:25 +0000 Received: from mail-wm1-x32f.google.com ([2a00:1450:4864:20::32f]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1pDknm-007i5c-9x for opensbi@lists.infradead.org; Fri, 06 Jan 2023 11:22:23 +0000 Received: by mail-wm1-x32f.google.com with SMTP id bi26-20020a05600c3d9a00b003d3404a89faso3545324wmb.1 for ; Fri, 06 Jan 2023 03:22: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=J2rdJ7g+0nwnhWNenv4sr17y5+qkeWl6LQugu98/DfI=; b=F9k46fCJqX4nKRSggaj6LLnpwuqHXLk8rLzPZP5975tO2x7P7fykhBTyUwkEavcD9i Ucsc8yPwa3YGuRbAejSFT0DfgJHqNXXS1znGbVrPbPSavAlM+8kHgFomZXTqrbxmrmhh UuWi6eNotr+3oLxC6PeVmOt9JQHjgAG6PWTkP/7dvpw3FgwqbYrzCVhaF6NHhXZdHm6J zo+09f4YA66x7KbSLw/NlY4T3Ubsu3fFDTpN19pXD3WxztSz2tTQRsgVCEl+mQEQPsmN 0qfSulx0AukeUHWcjQn4Jg2KN1QEwKti20JlfGTF21ToQK3vEvogVpFZq7EH7gvva9xv qkbw== 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=J2rdJ7g+0nwnhWNenv4sr17y5+qkeWl6LQugu98/DfI=; b=dW5OWrYdjWvxEd+hGkkGCGbnF/L529gZv2XaahMqKkIzyOZF/aZiIt8xdE6x4IVc5X 4zUaAPqYXBL7xq4LN0arrdQZ0iusIW6+Lm7/RD5ZstTK7n6wzTROr0+trnrS3sKgR9XR Ggit69aKkLsY41egjzYyMCyp5ZeipenFAZNGlNej7loP4t+kXqNirPaywJ5U32CCKtDL xks8WNSNsMmz+3D8+lJLVOa6fSEGYf9/BhS3xN1MAhkyP0HE2uuHpFfnB5Ql36TwX1fF xC6NaGfwlg6yh6+JkCH3fjaoke/eytwu/tud1MukV4z2BsGNuMF2ZTpsla/CJjHetvIW 8Wcg== X-Gm-Message-State: AFqh2kpVfP/5N+geZBHlrALBqniwb19e4p23Pd6B+j0mU7p3/zEfT73H 7ODtb2ziNvWl64H+w6lThW+a2oJZceUj+Gal X-Google-Smtp-Source: AMrXdXvIM+/W5auSwoZh8f36Untgj5wIZVxNS43Ecpb/eFv1GiEph+rrUjRLqVJCO+X22tWA2L76nw== X-Received: by 2002:a7b:c7d6:0:b0:3d1:ee3a:62ae with SMTP id z22-20020a7bc7d6000000b003d1ee3a62aemr42077539wmk.8.1673004139412; Fri, 06 Jan 2023 03:22:19 -0800 (PST) Received: from localhost (cst2-173-16.cust.vodafone.cz. [31.30.173.16]) by smtp.gmail.com with ESMTPSA id n23-20020a05600c3b9700b003cf71b1f66csm1592155wms.0.2023.01.06.03.22.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 Jan 2023 03:22:19 -0800 (PST) From: Andrew Jones To: opensbi@lists.infradead.org Cc: 'Sia Jee Heng ' , 'Anup Patel ' , 'Ley Foon Tan ' , 'Atish Patra ' Subject: [RFC PATCH 06/11] lib: sbi_hsm: Export some functions Date: Fri, 6 Jan 2023 12:22:04 +0100 Message-Id: <20230106112209.441825-7-ajones@ventanamicro.com> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230106112209.441825-1-ajones@ventanamicro.com> References: <20230106112209.441825-1-ajones@ventanamicro.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230106_032222_363615_0CC7B30B X-CRM114-Status: GOOD ( 10.43 ) 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 --- include/sbi/sbi_hsm.h | 4 ++++ lib/sbi/sbi_hsm.c | 12 ++++++++++-- 2 files changed, 14 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:32f 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 d6cc468d0528..00adfe1a4ef1 100644 --- a/include/sbi/sbi_hsm.h +++ b/include/sbi/sbi_hsm.h @@ -65,9 +65,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 priv); +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 cce4b07bbb36..8eb9643e6e72 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; @@ -329,7 +337,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 Fri Jan 6 11:22: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: 1722378 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=lQo9qAg0; 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=d18Z/mVA; 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 4NpLY16hDdz23fc for ; Fri, 6 Jan 2023 22:22: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=2z4fyDAcCvd9wtlieX14kJhIig1aMo6bZd09IbmlxNU=; b=lQo9qAg0piXKeG KaKVvmzkepUIC8tyJYJowPq9qbCuBTskledKeDaEIj8JeskIwdvrtk4LpCAZ4HPoryR+V0jLX02yB cqKxsJ9E2065BhsOO2QW1XkPJzXZRrqRES6scEZghEid4u/qaL/aCQI5u7ERk9iLimXHZZTG6nQI+ 5P6epZoH42vrhiMADOQulMgdI4myCvXw1PvKjV66kMaVCVlsPW7M5uHjfOL4ta3MOKSuw21IBc0VR WHo6lI4eQLPvThNuEcQSacy+pSRlxfPK1r50b/IsBo4miBh4GmgAXrvfEoYzc+Sv4TO6ofgIbaLva /fN0RXmzNmWrqPiG6uuA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pDknt-007iD9-Vl; Fri, 06 Jan 2023 11:22:30 +0000 Received: from mail-wm1-x336.google.com ([2a00:1450:4864:20::336]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1pDkno-007i6l-Pi for opensbi@lists.infradead.org; Fri, 06 Jan 2023 11:22:26 +0000 Received: by mail-wm1-x336.google.com with SMTP id k22-20020a05600c1c9600b003d1ee3a6289so862189wms.2 for ; Fri, 06 Jan 2023 03:22:22 -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=QiiLEpxWRX5nQIPwOQFZ7/pC7hshd5wgP5cJA4lG8xc=; b=d18Z/mVA7smhO1GkFnUrmI2TNzJBd6PbCRsMg9hHkOpVBeUJq5C+2KrgWB+glh3xLq T2l94uQuEL1zlqQ2oToEIoXekRZJWzusz62/Il5aRi3ELb3F8q0tJJR/pJEaMZY7br5B Ez5jWui0ATUbFy1KBOu7/f411INdw1VO9pRkcx+EzFZ2W4mDPQyfQ+tsyRmcasQfMzvt pFHH7+iYkMhF6Pu5FJTCi6naxA7UyPHbqg7KNty+bsNwmTwxO4PXWv+5W9HnIxxAGKJW yCf+w2dBZx0yjApJTT/Wbg7gFsTosFdky0qr2nKHPLA11kXmUgaof8w202a4hXZcsRq7 qqnA== 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=QiiLEpxWRX5nQIPwOQFZ7/pC7hshd5wgP5cJA4lG8xc=; b=s72U9/1wop/iiiRVPPsx3ViBm+7ALYgLlRZ6S1sgwkz9CSLrV2cG7iENJi6FOntrWD EHAhoh66hHpePoROk6b9yMwymw2ksq6Mpx8lQREKPd4vvgp7IWCEsB2XknmNdtIUzlNs VmDMjE5M9PcioV6s1BSHCL37m73xgtp2je+5UxpcmR9HKrnaDfX+gs2X83LF6ku6ontM n0QpIRUjlWQ4IfpJWInRKUJvsWzE1C88anjHGQKtTCYgyHe+QRfLvR8zusSZmRoLo6Yk vTozp2DYslDmtpkC2a0Rw89yQMhVCP3kFvWWL96QD4NktAcn3GdZOzaOU1eY6ClV6awr 7NZw== X-Gm-Message-State: AFqh2krSTULrxm2Qx8Hu2taImu3nyRVccQEMuJ3aAyChaE9QKNyROc/O SWvhdg4iCqBrpqAnGIFfNgTZ1ySsTWEnDBFG X-Google-Smtp-Source: AMrXdXvZxno/I86HUmq92k16ocmBMeXR02frD8d26Mb8Jvs9v0TKgVQfPDoDfg/b/leEGZ8YWvC04Q== X-Received: by 2002:a05:600c:2207:b0:3d2:24d2:d02b with SMTP id z7-20020a05600c220700b003d224d2d02bmr39772816wml.29.1673004140907; Fri, 06 Jan 2023 03:22:20 -0800 (PST) Received: from localhost (cst2-173-16.cust.vodafone.cz. [31.30.173.16]) by smtp.gmail.com with ESMTPSA id i10-20020adff30a000000b0024228b0b932sm1082056wro.27.2023.01.06.03.22.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 Jan 2023 03:22:20 -0800 (PST) From: Andrew Jones To: opensbi@lists.infradead.org Cc: 'Sia Jee Heng ' , 'Anup Patel ' , 'Ley Foon Tan ' , 'Atish Patra ' Subject: [RFC PATCH 07/11] lib: sbi: Add system suspend skeleton Date: Fri, 6 Jan 2023 12:22:05 +0100 Message-Id: <20230106112209.441825-8-ajones@ventanamicro.com> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230106112209.441825-1-ajones@ventanamicro.com> References: <20230106112209.441825-1-ajones@ventanamicro.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230106_032224_859690_BAB58C08 X-CRM114-Status: GOOD ( 20.56 ) 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 --- include/sbi/sbi_ecall_interface.h | 8 ++++++ include/sbi/sbi_system.h | 17 +++++++++++ lib/sbi/Kconfig | 4 +++ lib/sbi/objects.mk | 3 ++ lib/s [...] 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:336 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 | 17 +++++++++++ lib/sbi/Kconfig | 4 +++ lib/sbi/objects.mk | 3 ++ lib/sbi/sbi_ecall_susp.c | 48 +++++++++++++++++++++++++++++++ lib/sbi/sbi_system.c | 26 +++++++++++++++++ 6 files changed, 106 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 a3f2bf4bdf69..98a426a74ec4 100644 --- a/include/sbi/sbi_ecall_interface.h +++ b/include/sbi/sbi_ecall_interface.h @@ -29,6 +29,7 @@ #define SBI_EXT_HSM 0x48534D #define SBI_EXT_SRST 0x53525354 #define SBI_EXT_PMU 0x504D55 +#define SBI_EXT_SUSP 0x53555350 /* SBI function IDs for BASE extension*/ #define SBI_EXT_BASE_GET_SPEC_VERSION 0x0 @@ -230,6 +231,13 @@ enum sbi_pmu_ctr_type { /* Flags defined for counter stop function */ #define SBI_PMU_STOP_FLAG_RESET (1 << 0) +/* 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..65ea3d36d6cf 100644 --- a/include/sbi/sbi_system.h +++ b/include/sbi/sbi_system.h @@ -43,4 +43,21 @@ 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 */ + int (*system_suspend)(u32 sleep_type); +}; + +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 df74bba38540..7e139017fec7 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 c774ebbcd142..c4f3d0991aa2 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_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 Fri Jan 6 11:22: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: 1722380 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=dXz/C22Q; 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=goxlAf4n; 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 4NpLY45djrz23fc for ; Fri, 6 Jan 2023 22:22:48 +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=xpaU4X3dBETK54mYOliVo02qn0ul/DWEoOznHgR+NpA=; b=dXz/C22QsEtYus a2hErVyvnRBdEDTuLHmnFLSp/5qAWLjDST8MHoOEViO23GPqe4XHLDpslR5DXqeoyDMTOxj6NuYRB HnzVguyRMDiKfUhF6lOMwx/SScXP2noG8FPNBqGDCyNa21rvWu3/9blpuc027uUsSBmj6hg+PRONN BwEsg2Pw7x8HA9t2LLWMH+CO3yFJjTY2Y42Fst2PFv3Or4+DcqAPm6lQyVOIO7YicwpRpYNM6089D 1HYZ6xhWHrMw1xArnwKFUT0EYKxrNOqURet0aiCviLQHvFAMueUn3FTTlxw8kVAnHcLmfHRg8yLqs 0CUfYZp/wb2Ohq/20e6A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pDknv-007iE7-17; Fri, 06 Jan 2023 11:22:31 +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 1pDknp-007i7f-Mu for opensbi@lists.infradead.org; Fri, 06 Jan 2023 11:22:27 +0000 Received: by mail-wm1-x332.google.com with SMTP id ja17so846071wmb.3 for ; Fri, 06 Jan 2023 03:22: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=HoDoFXTUEnBamlOJFiQJa3oZghwJVA1Yq8HD9bgAK/Y=; b=goxlAf4ns+uq6EymF2dzoTvUGbR3+KoTV2owXs2nLDOJCI/5H4xeMzsRGU8F6aDjN9 IeRkO1er6ZVDiQfkuZSygyVmxcn/KS18GB7i9hohfHpWtJDiJpDfKGt4Ht2iFGc3Q8yk Y0zPnjObArl56yceITxr+lEnu5BCo/b5iaWjxRfW8RUflk/k03qgKIED8sgmQko3F8s7 jUUIPt4p3XJxHNTVWMHhyme2NPZTunhvx4/CEffUEXme7Ih+Y4XOCtnAPPDd9/IuhIo3 BZaNbxFuEA+36r6gRyk0m224TRWn2CrizwY3klG3pRC/nkGbUSCzwfc5sRJwGuwff9cV WSlg== 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=HoDoFXTUEnBamlOJFiQJa3oZghwJVA1Yq8HD9bgAK/Y=; b=DMW4oKO35KQk1s1ENamGErkMY0+x+4B7Y7RITrSD7pcKUBo9ZOrljMexWdM66cGvaQ fdtEG7Eb19XSyiJ35u1tiUydz2BZeiUE6J5+g6c0KtamSYc1jUE1FzHIy70y0qj9OqpO u85N/91ZyPHKuhbyTIhxz1P6itrRnZ5JSk2byNPvyfV2+OR0OMsbA47Aob/KYpaCa3MU n/Apqk7KF2iW45GKshj/t4IVL6LRmhorOHLfkInOHh9OKHL6w+NXz0NW1eUCj8TwK6fn JlSC6ch+Hp/2FkUr8TLOzdh/fFEEDcL45tPYSEBH1zgfudwOW4Lsn1Y6Ko1iX4Lu5hkS 3W5g== X-Gm-Message-State: AFqh2kqxL90q38HOveHpk+dSSy2TQU/Kfnya5s6QliSHm7oKFDHCpmjE vaWy7psQfBBmi1ADi+VV1z5Urdz/QMTg9+fl X-Google-Smtp-Source: AMrXdXtlJyD2h0iXoJvTnY/G9EdGFG4zJZMAJmZBxOgGi2japQwX0gX19KoYIYdnbKE/EKS5liMJ/w== X-Received: by 2002:a05:600c:3ac8:b0:3d3:4ae6:a71b with SMTP id d8-20020a05600c3ac800b003d34ae6a71bmr39911618wms.2.1673004142294; Fri, 06 Jan 2023 03:22:22 -0800 (PST) Received: from localhost (cst2-173-16.cust.vodafone.cz. [31.30.173.16]) by smtp.gmail.com with ESMTPSA id p16-20020a05600c469000b003d9b87296a9sm6452432wmo.25.2023.01.06.03.22.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 Jan 2023 03:22:21 -0800 (PST) From: Andrew Jones To: opensbi@lists.infradead.org Cc: 'Sia Jee Heng ' , 'Anup Patel ' , 'Ley Foon Tan ' , 'Atish Patra ' Subject: [RFC PATCH 08/11] lib: sbi: Add system_suspend_allowed domain property Date: Fri, 6 Jan 2023 12:22:06 +0100 Message-Id: <20230106112209.441825-9-ajones@ventanamicro.com> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230106112209.441825-1-ajones@ventanamicro.com> References: <20230106112209.441825-1-ajones@ventanamicro.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230106_032225_780264_01E015EE X-CRM114-Status: GOOD ( 15.54 ) 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 --- 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 [...] 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 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 8963b57e3787..ac8c73d40b3e 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 -------------- @@ -187,6 +189,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 @@ -252,6 +256,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 f0d9289ec7cc..6f51b3f6324c 100644 --- a/include/sbi/sbi_domain.h +++ b/include/sbi/sbi_domain.h @@ -78,6 +78,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 19e2029e6c4c..38684cdc6527 100644 --- a/lib/sbi/sbi_domain.c +++ b/lib/sbi/sbi_domain.c @@ -34,6 +34,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) @@ -374,6 +375,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 35462a2008aa..32be6a5ab7e4 100644 --- a/lib/utils/fdt/fdt_domain.c +++ b/lib/utils/fdt/fdt_domain.c @@ -405,6 +405,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 Fri Jan 6 11:22:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Jones X-Patchwork-Id: 1722379 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=KDOWXaap; 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=J4ubkanw; 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 4NpLY32hFGz23fc for ; Fri, 6 Jan 2023 22:22: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=+cGwEqTMolccyivb7PRU/BaNoCWhB3L0ttOyS3tQZes=; b=KDOWXaapXF65yC 9IoCKqou8bYkuuD3ddO23cBhJc0r/Mr4avDQxUa2w6Zuzu2VMwZbuBIAw2oNozd3WKvQQyxATz6J/ FzvMq6Wc3r9qH2bpbTAcFVxtVAGr5OPZJV9SllsJTsF8LDBlaF/6G3w6FxfQaU9RVFxLg8hIEZQI7 4uGH2sYptm5LDUU8NxAJ1/omO9gSu0BU5qLsYstS2vvuZWMKIk3pT1u5fDN0VZndL2LtPEKgJlmzq DBbJroBeBIRseK2OzPJp49jVvEpJax89SpfFTN+V9Ry1CY9Zqh7EcdIL6SM3wB6C3S+7+RPvQtev2 dWiG3FOaCTz4LG2/Aeyg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pDknx-007iGg-6x; Fri, 06 Jan 2023 11:22:33 +0000 Received: from mail-wm1-x329.google.com ([2a00:1450:4864:20::329]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1pDknr-007i8R-Pb for opensbi@lists.infradead.org; Fri, 06 Jan 2023 11:22:29 +0000 Received: by mail-wm1-x329.google.com with SMTP id ay2-20020a05600c1e0200b003d22e3e796dso882291wmb.0 for ; Fri, 06 Jan 2023 03:22: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=O5UvRZYyqBn/PqBWiPPBLVLk9JchSCj6uQLmIkA8Vv4=; b=J4ubkanwzBNLOWAq5AjBAFEz3bWt89pFcdtF5Ock2icSa4T73z2nw8nxCbA110nVej 7j7qMpNrJr5AoOUBl5qvvt0Egqt0jTT0KtEKynylG/yxkA26OBwA5SPUYhjnWynY8FD1 IB5t7B/6EDsi/omElEDxLnxxEfQZdtJO4o/XcRyWObdlghfC0cE4B9Bf2GmhaCff/XBQ fICrvdcGufcq8nhztYTIVsIPawK8LqKBcG0H3iA/7Kz4wJJAJiCys1vm5F87yz9jSaW+ kas9SdE8wQsNoSBDpHhcl1PbMI6+Xe6Z2MFTWyAwEtHFaGwH9i8Lv/g/9mrY6Uvhqm4m Viqw== 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=O5UvRZYyqBn/PqBWiPPBLVLk9JchSCj6uQLmIkA8Vv4=; b=JIGKDVj+MimQbVmf+/qHSOGimOjVNhmtYRnqtPKFpX9AMzacGwEugSEvjPTbfPMsIJ Y4wSA7vGxu5g6yp8dtb39ylapQ0Pk5D8KDMq2sX1O1yrmR+JwazDkKAm2md/QVixUW97 Fn9gHelWtdbniJPS5ZRzscWK6kqKJmaV8gPAaCM7wlMFgsqGIBDwcmcpZsYL5M+EKOYc pKQbvfeQhnvLfIgpzGXx+SnVNItpW0KRD/FpQqxok2Gb1OsLT5bjcfwK7QNbXgt4QC5i PItsLbZkbARm/yuMOuAL0VnZwFCWQ/A0FIP1Z7u+sHHUP9q2phRC8pT9AQ0qvnH4HB+9 +z8Q== X-Gm-Message-State: AFqh2krYKWb03AxPn5mVsULGl0mXLsW12am7wX48g6Qxljv96LBWGJu1 wyqdUIUU3ORgvHnp/WNrv9YpxFlbbu8d2xHA X-Google-Smtp-Source: AMrXdXtJraYH1xPx7q7Nfu+9EyuM0fSSJmdwEUWV6iDEMwDY5B8a26ZjSJ9F3PcTiAyGyImoDb/OAw== X-Received: by 2002:a05:600c:1d92:b0:3d2:254d:62a7 with SMTP id p18-20020a05600c1d9200b003d2254d62a7mr38894148wms.10.1673004143879; Fri, 06 Jan 2023 03:22:23 -0800 (PST) Received: from localhost (cst2-173-16.cust.vodafone.cz. [31.30.173.16]) by smtp.gmail.com with ESMTPSA id q6-20020a05600c46c600b003d1f3e9df3csm6398067wmo.7.2023.01.06.03.22.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 Jan 2023 03:22:23 -0800 (PST) From: Andrew Jones To: opensbi@lists.infradead.org Cc: 'Sia Jee Heng ' , 'Anup Patel ' , 'Ley Foon Tan ' , 'Atish Patra ' Subject: [RFC PATCH 09/11] lib: sbi: Implement system suspend Date: Fri, 6 Jan 2023 12:22:07 +0100 Message-Id: <20230106112209.441825-10-ajones@ventanamicro.com> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230106112209.441825-1-ajones@ventanamicro.com> References: <20230106112209.441825-1-ajones@ventanamicro.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230106_032228_257687_14826296 X-CRM114-Status: GOOD ( 13.77 ) 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 --- lib/sbi/sbi_system.c | 57 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 56 insertions(+), 1 deletion(-) 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:329 listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain X-BeenThere: opensbi@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "opensbi" Errors-To: opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org Fill the implementation of the system suspend ecall. A platform implementation of the suspend callbacks is still required for this to do anything. Signed-off-by: Andrew Jones Reviewed-by: Anup Patel --- lib/sbi/sbi_system.c | 57 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 56 insertions(+), 1 deletion(-) diff --git a/lib/sbi/sbi_system.c b/lib/sbi/sbi_system.c index 5c123a6c9d8d..c18562cdcfab 100644 --- a/lib/sbi/sbi_system.c +++ b/lib/sbi/sbi_system.c @@ -116,5 +116,60 @@ bool sbi_system_suspend_supported(u32 sleep_type) int sbi_system_suspend(u32 sleep_type, ulong resume_addr, ulong opaque) { - return 0; + int ret = SBI_ENOTSUPP; + const struct sbi_domain *dom = sbi_domain_thishart_ptr(); + struct sbi_scratch *scratch = sbi_scratch_thishart_ptr(); + void (*jump_warmboot)(void) = (void (*)(void))scratch->warmboot_addr; + unsigned int hartid = current_hartid(); + unsigned long prev_mode; + unsigned long i; + + if (!dom || !dom->system_suspend_allowed) + return SBI_EFAIL; + + if (!suspend_dev || !suspend_dev->system_suspend) + return SBI_EFAIL; + + if (!sbi_system_suspend_supported(sleep_type)) + return SBI_ENOTSUPP; + + prev_mode = (csr_read(CSR_MSTATUS) & MSTATUS_MPP) >> MSTATUS_MPP_SHIFT; + if (prev_mode != PRV_S && prev_mode != PRV_U) + return SBI_EFAIL; + + sbi_hartmask_for_each_hart(i, &dom->assigned_harts) { + if (i == hartid) + continue; + if (__sbi_hsm_hart_get_state(i) != SBI_HSM_STATE_STOPPED) + return SBI_EFAIL; + } + + if (!sbi_domain_check_addr(dom, resume_addr, prev_mode, + SBI_DOMAIN_EXECUTE)) + return SBI_EINVALID_ADDR; + + if (!sbi_hsm_hart_change_state(scratch, SBI_HSM_STATE_STARTED, + SBI_HSM_STATE_SUSPENDED)) + return SBI_EFAIL; + + /* Prepare for resume */ + scratch->next_mode = prev_mode; + scratch->next_addr = resume_addr; + scratch->next_arg1 = opaque; + + __sbi_hsm_suspend_non_ret_save(scratch); + + /* Suspend */ + ret = suspend_dev->system_suspend(sleep_type); + if (ret != SBI_OK) { + if (!sbi_hsm_hart_change_state(scratch, SBI_HSM_STATE_SUSPENDED, + SBI_HSM_STATE_STARTED)) + sbi_hart_hang(); + return ret; + } + + /* Resume */ + jump_warmboot(); + + __builtin_unreachable(); } From patchwork Fri Jan 6 11:22:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Jones X-Patchwork-Id: 1722381 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=q1AoHHFP; 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=JQ1QiZVJ; 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 4NpLY516M7z23fn for ; Fri, 6 Jan 2023 22:22:49 +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=xfujscn1T9j7+Nw/3kDhligus70VPTFCrue4l5suqrY=; b=q1AoHHFPYmLcnY r+3K59MP7FnsY6WzeGGMM5mJ3FC510MPQ4uz11EqPoULhxQRlXY64kpE1DMm3JFS5/nZr5+9gwSkc Zq3KIK1Co6mO4hCEctJWMZKolK2zbuWbnMsRWSdiepdvfJR9LIH1xDa/vXk6mHYcYe/VroeVWO9Lv ZWZI74XSszEQ0pU2Vx7CwZYzFlLwZbkyZo3OcOZu2JXhg0avb4AurV8E/1c5VgiONIPhEeAqdtQ4U D1Nra5sY59qVkfjyn5+tSz02DPBUsjPAZb+sg8YGRR+vfZb9e8S4jemYhXkmhgiSvPl1KsTlmA//y zqsmaVG/SO+GqXU1mBsw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pDkny-007iI2-Dm; Fri, 06 Jan 2023 11:22:34 +0000 Received: from mail-wr1-x42f.google.com ([2a00:1450:4864:20::42f]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1pDknt-007iA8-8w for opensbi@lists.infradead.org; Fri, 06 Jan 2023 11:22:30 +0000 Received: by mail-wr1-x42f.google.com with SMTP id t15so985503wro.9 for ; Fri, 06 Jan 2023 03:22:26 -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=WFHvJiD6ouIP3B3nVG1IQywJwyG86eA6rECK3IfEMPI=; b=JQ1QiZVJPTFjR95bhRDsBdjbxNLbAb9N9t5t2b73L8+RVKMlhLVtphkZy/HsWTrmYG A+Oix9RKguDyAoqvNSPm+fCwcoej0DsOG3+UVVvmmANRYftTwkjUZ7HoNEvtU9nFxVmA YFKLeNV1mtgwZpFPgTpx7ylJA74VGB7U6nl8jasf3cAB3lKS09fpODV7HpSJ8p3f0mN8 YnEVURBRC1oiFJwij6d/m0BJEiEtrVgIQu36yqpnqSbqBLcqX4Fs3nnIzXgkJY+FOAKb HVsASYLlYprCjNVx/ZlG8FUXY9fOjSGUKO4YiEuqKdO9Gcx5a8xri3KTVWGF4LYL+JGV L+vA== 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=WFHvJiD6ouIP3B3nVG1IQywJwyG86eA6rECK3IfEMPI=; b=WoPnddsodJ4hULX6CdauiEx9K4f1Qoz9UVePfikuZOB1apJaAqUHLyg7y3Y4TO13Z0 HSQXaSN00s06mEh4hAjjrdENe99dirhlbE6dWPHPo/aFJH8T2L4DFsAOOrMgaJrdPPia sw3ctJHejfQ3Ju1n3D95+vdKXZ93+sOjdRCpPOhbvkrNj/7L7vw5dvlznP7aC86grhuA dOl3MBM2pFhL8ZUFjrN6OqLtsZ3MV5yQSTltHJn0SXDev7lQQiAb+jBN18sIByGUejBv Dby4RaVx6mZXocC/Rpzq/iFH+pT/+T6uw7T2m87roUDF9vK3o8rbIzkkaQAwO0V/LoyA g0/A== X-Gm-Message-State: AFqh2koQ90MI5s37xS4DyKzk7ulbL/cMibs4CuRyYUFIiIsg6ov86NSH Ymz1yFK6G0p7nWHqDD2I8EgUCM+VGGJMmxNJ X-Google-Smtp-Source: AMrXdXuOqXcCP2mxkLeobLLteT8C9VFT/tDhLoCE4RkKHM6mkYdC2lcDH7P/q1fzwstN+or0Em0s4A== X-Received: by 2002:adf:f0ca:0:b0:275:e426:4134 with SMTP id x10-20020adff0ca000000b00275e4264134mr30601990wro.51.1673004145337; Fri, 06 Jan 2023 03:22:25 -0800 (PST) Received: from localhost (cst2-173-16.cust.vodafone.cz. [31.30.173.16]) by smtp.gmail.com with ESMTPSA id i13-20020adffdcd000000b002a91572638csm853180wrs.75.2023.01.06.03.22.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 Jan 2023 03:22:25 -0800 (PST) From: Andrew Jones To: opensbi@lists.infradead.org Cc: 'Sia Jee Heng ' , 'Anup Patel ' , 'Ley Foon Tan ' , 'Atish Patra ' Subject: [RFC PATCH 10/11] docs: Correct opensbi-domain property name Date: Fri, 6 Jan 2023 12:22:08 +0100 Message-Id: <20230106112209.441825-11-ajones@ventanamicro.com> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230106112209.441825-1-ajones@ventanamicro.com> References: <20230106112209.441825-1-ajones@ventanamicro.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230106_032229_420433_1EE14D63 X-CRM114-Status: GOOD ( 10.55 ) 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 --- 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 ac8c73d40b3e..b2c1023008cc 100644 --- a/docs/domain_support.md +++ b/docs/domain_support.md @@ -199,9 +199,9 @@ platform support can [...] 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:42f 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 ac8c73d40b3e..b2c1023008cc 100644 --- a/docs/domain_support.md +++ b/docs/domain_support.md @@ -199,9 +199,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 Fri Jan 6 11:22:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Jones X-Patchwork-Id: 1722382 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=a/eOMO6C; 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=GTjbKqaM; 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 4NpLY66TZrz23fc for ; Fri, 6 Jan 2023 22:22: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=5/GOctuYjz7GIW4a/op/IRvsbjnz5W/8YBHRqU41DIg=; b=a/eOMO6Cx01XDW i6MUGh2Q6FNVe0LD8N/GJuZQoyBgYWYOK4ngSkm4uTUUyrjNoFEyEc0wg6rO9L4rCdqObtbS9XbPU TVZ6oNI6O2tUgCnA3IxIcRqOHu+wEkex9P5cnGGKWyLNmX2EQlOau/LOIyU/7aE39Xw1i/tQQmcXM w4upIRjfCHv5vSF/t/yMKdtK6hHWlfVroUYpbjzeBCLdWwjYf5FiMy3orm+4KOIZlDNwd9TSi2vgV N5A63ZuR9+AD27xnktQu5S1xFAiykUxB/0Ahs9/igZ8cAP0/m97n4B8J4Zq8dGIo2sbhb3AYihBSe muR+2+530KULLZP8GQzg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pDko0-007iKc-HT; Fri, 06 Jan 2023 11:22:36 +0000 Received: from mail-wr1-x432.google.com ([2a00:1450:4864:20::432]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1pDknu-007iAj-S4 for opensbi@lists.infradead.org; Fri, 06 Jan 2023 11:22:32 +0000 Received: by mail-wr1-x432.google.com with SMTP id d4so990914wrw.6 for ; Fri, 06 Jan 2023 03:22:28 -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=mnPu66PUXdT8LJ0TfR3IKFAwRCc/nlW7HMjgcwmBnkE=; b=GTjbKqaMYxcDSOeGYKm+7drJAzBeCf9eG06TntCgN5xaHFKzYRkRIF4nQZtl/IAU0l 9LYC53xOVz1s60lOLRQhEfWAVGzqgEDFmSRN+9p7a80r5LO3fbf2Ct2OhAozKkK9wUZz hiSGIOmtqDbNVY80mKNX0ikzef2u+7R6Z6472hZx00q8qlS5t1CsGBc11gPDV1Ds8eaH NCjDFaL842hz4dfsXfcp6gzFolrYtJ+kHtfXtM0ACsqeXoB3TW7fM+wiBJySHpq6+yfd G83Wvm2FrFQ4hEs9QtPoBJyeBqv2aTJ65+9xWu5JVtQn3Tb4XLwzc/iUVb/D1mElA03Q StDQ== 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=mnPu66PUXdT8LJ0TfR3IKFAwRCc/nlW7HMjgcwmBnkE=; b=CDPVwqTfqEiBPg8gAMcYVFNTLq+m+Y0za+W5mkIwvrCc1H3Yk0r6uap4P5cRfKsaZ5 /82O0U06Bicj0Eabx68BHMEsg91ZWNIcCiB+0A4ORSOfvlr7yfRmRR5iHYu4Lu0qzn1A wFC5sg5loRlWWVN6mm8WcwYwt0hOkqJR7Dv1Q1xLTZN8wl5uzKIsKpn6IrevOoujGwMX xViY6yaYeTDPLUoKMgfIb4VdpM4RGIgnTHMdhHiSyvYFfohocKVUoDP4OXDH9e6TI14C jtcRFlqjGsRxXQtyyKROaObf35klG4nO2HxL62sv5ayRy2Hgf8xWUo5zCsCKCbPMdjS+ mw5A== X-Gm-Message-State: AFqh2kpPlLrJ9NdfYRUL232KaTuH5NQL+EyTbmqVvaq0Y5zGC9Q+k6eX Vzb0HzeSdcf5vk3zloIjwq6orXvpMjoTk+ov X-Google-Smtp-Source: AMrXdXuk24mCm3inH6p1KF0Epu5/+uFAjngPUyNBfyNc9dtlHztcLp9SpNWlVVswgnpoDVeMZIN3lQ== X-Received: by 2002:a5d:58fa:0:b0:28e:46bc:3256 with SMTP id f26-20020a5d58fa000000b0028e46bc3256mr16142372wrd.8.1673004146969; Fri, 06 Jan 2023 03:22:26 -0800 (PST) Received: from localhost (cst2-173-16.cust.vodafone.cz. [31.30.173.16]) by smtp.gmail.com with ESMTPSA id j15-20020a5d452f000000b0028f9132e9ddsm896957wra.39.2023.01.06.03.22.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 Jan 2023 03:22:26 -0800 (PST) From: Andrew Jones To: opensbi@lists.infradead.org Cc: 'Sia Jee Heng ' , 'Anup Patel ' , 'Ley Foon Tan ' , 'Atish Patra ' Subject: [RFC PATCH 11/11] platform: generic: Add system suspend test Date: Fri, 6 Jan 2023 12:22:09 +0100 Message-Id: <20230106112209.441825-12-ajones@ventanamicro.com> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230106112209.441825-1-ajones@ventanamicro.com> References: <20230106112209.441825-1-ajones@ventanamicro.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230106_032231_155923_0D319D2E X-CRM114-Status: GOOD ( 18.59 ) 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:432 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 | 30 ++++++++++++++++++++++++++++++ platform/generic/platform.c | 20 +++++++++++++++++++- 4 files changed, 54 insertions(+), 1 deletion(-) diff --git a/docs/domain_support.md b/docs/domain_support.md index b2c1023008cc..d86628049b62 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 @@ -226,6 +229,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 65ea3d36d6cf..7d0867f276aa 100644 --- a/include/sbi/sbi_system.h +++ b/include/sbi/sbi_system.h @@ -57,6 +57,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 c18562cdcfab..3242b21699cb 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,35 @@ 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) +{ + 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 bfe15f0d6b87..b3a3351c0439 100644 --- a/platform/generic/platform.c +++ b/platform/generic/platform.c @@ -13,6 +13,7 @@ #include #include #include +#include #include #include #include @@ -215,7 +216,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)