From patchwork Fri Feb 10 08:52:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nylon Chen X-Patchwork-Id: 1740387 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=ZPLXI1eT; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=sifive.com header.i=@sifive.com header.a=rsa-sha256 header.s=google header.b=bnClQeQk; 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 4PCnZ86NFMz23hX for ; Fri, 10 Feb 2023 19:53:04 +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: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:In-Reply-To:References: List-Owner; bh=NSJMianXDrmr3A6618mqdzt16IiL7Ae4rCwujXNnfwE=; b=ZPLXI1eTJ528R2 JHu7vG/JuJSuvczQ1xG7M0nomGhX5V9U9MRB5ovZtGt1+VCw0Mwh+JkSWJqowAKuGQaoPdg9shCS9 tgnyqr9w0SY+UC08WYnWURA9C9GSx/AtkM0jPyViMs2d7lHiJ+jrsutWPF5O8uP0I1cyObT1Oi6NV zAmLoZk3o65y/88t+0G5JMZ7FgCqJBNf8Cw+jGJwHbleKtUUwxy9rFtNM/CZgwmAeEkNHZDYJR5fr bE/gvK1sePQegBBTbarTjLblC6FvwEqRCPSiMmsANgblSGYFD3lSp8oUjSNbKzJV0ooDOKz99T3EH PCb1Go1QEYUm5RyEB3/w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pQP9F-004qs6-GR; Fri, 10 Feb 2023 08:52:49 +0000 Received: from mail-pj1-x102c.google.com ([2607:f8b0:4864:20::102c]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1pQP9C-004qpK-7k for opensbi@lists.infradead.org; Fri, 10 Feb 2023 08:52:47 +0000 Received: by mail-pj1-x102c.google.com with SMTP id y11so871446pjc.0 for ; Fri, 10 Feb 2023 00:52:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=h4D1tCH0SgS17Z/y0OPoJ5WHqPPeTJ+lY8yLtfe4E28=; b=bnClQeQk0bVkNnrbqjgriIi98pBxggg69ldIhnRcyKwY9VOr+ay3DMkInJ33JEo1aI ukunVkmiaiLKQUEmuHsK6ova7lxY0VGCsxh8GsjALz+D3zWut2zZkVl/En8NFEEBHSIl Ci9N8D+0VlT/egVeG2HHsYysuxBshKtY0ngNj9i4Xpp5lWX4Q0uJFq9cQGr6F8QcKisR Gi8QbdMyBYHV1lrY2DDMrDddCFBiwzfHS4QUUi95KTv1Zu2bEqHokxb7xM1iheMHc4kA sS1r234Z0dfDsc5/JPA4D7yit0vCRJumq0StCkx9qrqjTzwbCE1f9f5UIDP/OE1q8wdD H0pQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=h4D1tCH0SgS17Z/y0OPoJ5WHqPPeTJ+lY8yLtfe4E28=; b=wGTf8otqJLdwilqBI6ObQwY41eu1h1MMcnOGMAcOaOkPJq3ASolfJrbfJxczl4wFbM TEs6t2ah+4PmTsdJupMXacWgTHpa4un7BqcA2KoYJRpwE0yOTsDwrsLHeYagrer8qNK5 BTtjEWzNv6jJHTCA64iSuGa1Usv8OxHleMlreSoThV6nEVLy0+i6oaplo+pijfFPyxV2 evAqkKs1XTJ1QlbEajZlrzidvtVMv1cgVCPsAalKaS389KZ2+0nPcBOvC4vQ1tfcsmFb nvAL/BWKBgNotCoRzBTup9aGAJ2cfDKZQP/LDALSsPZ2ZYkGbczGleDWW1K7/44h0NXi EI3g== X-Gm-Message-State: AO0yUKVn9buzVxXx80qx5EIyC06undjzC6PIM5tSLFhQfOT9KWLhPOHp rdavTOCLNgle+1Uoa3wSns3eQqlki/xgNt4uDi7ikGautgC+eztJ38O8yFixHD+nGNmgPeDlQgK gFkyVm6DTFt96q4Y/miLDIQW38WEFo+o1PPiLZ8fUwvuL3MYUBF7ocsr81TK1J+Ni0IugkwLWca hhSF4fuQ== X-Google-Smtp-Source: AK7set8qRtL4Bqh5+iAZjWd1PX/w4mU7iJs/LzLXHfE6YJsB7gQNDsqmb9iRhnx31ZjhjcaNtiTwZg== X-Received: by 2002:a17:90b:1c10:b0:232:db7b:5698 with SMTP id oc16-20020a17090b1c1000b00232db7b5698mr5010591pjb.15.1676019162348; Fri, 10 Feb 2023 00:52:42 -0800 (PST) Received: from hsinchu15.internal.sifive.com (59-124-168-89.hinet-ip.hinet.net. [59.124.168.89]) by smtp.gmail.com with ESMTPSA id k6-20020a17090a4c8600b002339195a47bsm1146729pjh.53.2023.02.10.00.52.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 Feb 2023 00:52:41 -0800 (PST) From: Nylon Chen To: opensbi@lists.infradead.org Cc: zong.li@sifive.com, nylon7717@gmail.com, Nylon Chen Subject: [PATCH] lib: sbi_hart: Enable hcontext and scontext Date: Fri, 10 Feb 2023 16:52:38 +0800 Message-Id: <20230210085238.19723-1-nylon.chen@sifive.com> X-Mailer: git-send-email 2.36.1 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230210_005246_368477_BFF76B3B X-CRM114-Status: UNSURE ( 7.54 ) X-CRM114-Notice: Please train this message. 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: According to the description in "riscv-state-enable[0]", to access h/scontext in S-Mode, we need to enable the 57th bit. If it is not enabled, an "illegal instruction" error will occur. Link: https://github.com/riscv/riscv-state-enable/blob/a28bfae443f350d5b4c42874f428367d5b322ffe/content.adoc [0] 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 [2607:f8b0:4864:20:0:0:0:102c 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 According to the description in "riscv-state-enable[0]", to access h/scontext in S-Mode, we need to enable the 57th bit. If it is not enabled, an "illegal instruction" error will occur. Link: https://github.com/riscv/riscv-state-enable/blob/a28bfae443f350d5b4c42874f428367d5b322ffe/content.adoc [0] Signed-off-by: Nylon Chen Reviewed-by: Zong Li Reviewed-by: Anup Patel --- include/sbi/riscv_encoding.h | 2 ++ lib/sbi/sbi_hart.c | 1 + 2 files changed, 3 insertions(+) diff --git a/include/sbi/riscv_encoding.h b/include/sbi/riscv_encoding.h index b0f08c8..4ebed97 100644 --- a/include/sbi/riscv_encoding.h +++ b/include/sbi/riscv_encoding.h @@ -736,6 +736,8 @@ #define SMSTATEEN0_CS (_ULL(1) << SMSTATEEN0_CS_SHIFT) #define SMSTATEEN0_FCSR_SHIFT 1 #define SMSTATEEN0_FCSR (_ULL(1) << SMSTATEEN0_FCSR_SHIFT) +#define SMSTATEEN0_CONTEXT_SHIFT 57 +#define SMSTATEEN0_CONTEXT (_ULL(1) << SMSTATEEN0_CONTEXT_SHIFT) #define SMSTATEEN0_IMSIC_SHIFT 58 #define SMSTATEEN0_IMSIC (_ULL(1) << SMSTATEEN0_IMSIC_SHIFT) #define SMSTATEEN0_AIA_SHIFT 59 diff --git a/lib/sbi/sbi_hart.c b/lib/sbi/sbi_hart.c index 02ce991..5e06918 100644 --- a/lib/sbi/sbi_hart.c +++ b/lib/sbi/sbi_hart.c @@ -90,6 +90,7 @@ static void mstatus_init(struct sbi_scratch *scratch) mstateen_val |= ((uint64_t)csr_read(CSR_MSTATEEN0H)) << 32; #endif mstateen_val |= SMSTATEEN_STATEN; + mstateen_val |= SMSTATEEN0_CONTEXT; mstateen_val |= SMSTATEEN0_HSENVCFG; if (sbi_hart_has_extension(scratch, SBI_HART_EXT_SMAIA))