From patchwork Sun Aug 25 17:08:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Raphael Tiovalen X-Patchwork-Id: 1976520 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org 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=KktArmbi; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=GekvddDb; dkim-atps=neutral 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=kvm-riscv-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=patchwork.ozlabs.org) 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 (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4WsKyl1nyRz1yNm for ; Mon, 26 Aug 2024 03:08:47 +1000 (AEST) 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=53SHfr7RPiPOpQSRswdTC5urgcTmwL06oXq4D1G8EBk=; b=KktArmbioNeOJQ qMD70K9X19Bs3pdjycRDpzimRUL9DK8UlRJ5FYJnSL8Yv3Acj1KLIMV98HAiXKFsSj3sCR9i+HZV4 ULFZhh6yH6Ge88A3qYHkkkvHLsuC9EIsUubUjrSZ8/EEhbdwuHEK69cz93zRV/8HFi7Ek0hTV4r6J CfPDEQr3PrSLk0IVOAzsJfa6CkOBjEzpNFp9aV4BFYIS6etiGAOm0BJ2PCvyQfs/1X0omscSI2zob fRYMpf9S8MtD51tcZBHFh+YziZPYsW0aqc7lvoHwvMiYTASDxWG/jFCJjC9O52SfLf1AUTJVpxpNo S7vXAKdEtuL21mfZdmew==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1siGjO-00000004hUU-07Km; Sun, 25 Aug 2024 17:08:46 +0000 Received: from mail-pl1-x636.google.com ([2607:f8b0:4864:20::636]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1siGjK-00000004hST-1PnN for kvm-riscv@lists.infradead.org; Sun, 25 Aug 2024 17:08:44 +0000 Received: by mail-pl1-x636.google.com with SMTP id d9443c01a7336-2021c03c13aso25912645ad.1 for ; Sun, 25 Aug 2024 10:08:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1724605721; x=1725210521; darn=lists.infradead.org; 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=gckUWFxhpGbWVlGAGlzsWH3byBepNJj4AE/d1tkaAcc=; b=GekvddDbf5sC7NcQ5Q9TJTBWdP75b2ZEkc2NnHx75VUHWhEMGGg/DlSwU47YHvuiJy b2tavuxAclNfdzB4cDRksj8TYSuM2oua6MHgR3sos7S9eALD/tTMfY78Bg3wNUl9S7N1 SqfoKnFcfdCm+Kr56g4eTZz8uTYfzftndWs0VGtu+TH22GgXFD2lrpkGSUrcaKIodO6z zoWiVXLp3+R6hsrD999A9g7Mcq1KdiU6jy+G/jBZfXo7dRDZ+RZvlnfjV+oFme6CQg7L adH+qlOR0ClNbv3KVNlBxD7otv/7yXTHcfpSgqRTFAHSU9OkCrsQ+okhrmrIg6YzXJXX zueA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724605721; x=1725210521; 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=gckUWFxhpGbWVlGAGlzsWH3byBepNJj4AE/d1tkaAcc=; b=uuuPS0FsmtAtwRylD5YfFMht4gELlTEh3IH8XKixxdj1aAAlSU0SMBrzBVhkfFRbKn xVowMaqIHZKbxoVncdp2emU4xb0F2IGkrBoUo4k6QftTTf581HkH9wip57pFWOv01Xrh jdZhs3wq84RE9lGL2KU2fto2YRwvGgjYO5GGKCE7Q7aZdjqDlJYgHaVvPfMwgD/D8278 FeVfjAY896TqCZ6GUDoB/p+l2FVkqUiOCC5cxGUFJ7gB7Yd2+g8BrOdZlR0rOz7mX442 NZaxpKG+UUmSzPxeAx/1J8VzctAGE2g7VnHVYtHEwnS49tYtcxDqy7VB+ZZsULBXr0Qw MXmg== X-Forwarded-Encrypted: i=1; AJvYcCWXFxqA59f4xlG7OKhqQuuBDY/94fVcIvRSvOUZlvCILynkEr1sg03EkjY5R2DEpEh1R4UV/qcJuMQ=@lists.infradead.org X-Gm-Message-State: AOJu0YymUJXoMa2k06YGXm83dg5OCDu5Ds9Oj67tNBwhKenQNZMZKoov +1NvjxUKg44saz5CdLJAmvAxHQF4VACrqrKJj4s0srNLR+98A6rX X-Google-Smtp-Source: AGHT+IHZzM/qViHLzQpOrmEC/WRNtKeiND6zRKFGZ5NNcOHQwbqPlhRQOWaK/R3e/WS76nMTxpy+Gw== X-Received: by 2002:a17:902:f68c:b0:1f9:d6bf:a67c with SMTP id d9443c01a7336-2039c31cca4mr128706135ad.5.1724605720939; Sun, 25 Aug 2024 10:08:40 -0700 (PDT) Received: from JRT-PC.. ([202.166.44.78]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-203855dd985sm56083165ad.164.2024.08.25.10.08.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 25 Aug 2024 10:08:40 -0700 (PDT) From: James Raphael Tiovalen To: kvm@vger.kernel.org, kvm-riscv@lists.infradead.org Cc: andrew.jones@linux.dev, atishp@rivosinc.com, cade.richard@berkeley.edu, James Raphael Tiovalen Subject: [kvm-unit-tests PATCH v2 3/4] riscv: sbi: Add HSM extension functions Date: Mon, 26 Aug 2024 01:08:23 +0800 Message-ID: <20240825170824.107467-4-jamestiotio@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240825170824.107467-1-jamestiotio@gmail.com> References: <20240825170824.107467-1-jamestiotio@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240825_100842_397256_C4C9F855 X-CRM114-Status: UNSURE ( 9.03 ) X-CRM114-Notice: Please train this message. X-Spam-Score: -2.1 (--) 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 helper functions to perform hart-related operations to prepare for the HSM tests. Also add the HSM state IDs and default suspend type constants. Signed-off-by: James Raphael Tiovalen --- lib/riscv/asm/sbi.h | 17 +++++++++++++++++ lib/riscv/sbi.c | 10 ++++++++++ riscv/sbi.c | 5 +++++ 3 files changed, 32 insertions(+) Content analysis details: (-2.1 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:636 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_EF Message has a valid DKIM or DK signature from envelope-from 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 -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider [jamestiotio(at)gmail.com] -0.0 T_SCC_BODY_TEXT_LINE No description available. X-BeenThere: kvm-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "kvm-riscv" Errors-To: kvm-riscv-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org Add helper functions to perform hart-related operations to prepare for the HSM tests. Also add the HSM state IDs and default suspend type constants. Signed-off-by: James Raphael Tiovalen Reviewed-by: Andrew Jones --- lib/riscv/asm/sbi.h | 17 +++++++++++++++++ lib/riscv/sbi.c | 10 ++++++++++ riscv/sbi.c | 5 +++++ 3 files changed, 32 insertions(+) diff --git a/lib/riscv/asm/sbi.h b/lib/riscv/asm/sbi.h index a864e268..4e48ceaa 100644 --- a/lib/riscv/asm/sbi.h +++ b/lib/riscv/asm/sbi.h @@ -48,6 +48,21 @@ enum sbi_ext_ipi_fid { SBI_EXT_IPI_SEND_IPI = 0, }; +enum sbi_ext_hsm_sid { + SBI_EXT_HSM_STARTED = 0, + SBI_EXT_HSM_STOPPED, + SBI_EXT_HSM_START_PENDING, + SBI_EXT_HSM_STOP_PENDING, + SBI_EXT_HSM_SUSPENDED, + SBI_EXT_HSM_SUSPEND_PENDING, + SBI_EXT_HSM_RESUME_PENDING, +}; + +enum sbi_ext_hsm_hart_suspend_type { + SBI_EXT_HSM_HART_SUSPEND_RETENTIVE = 0, + SBI_EXT_HSM_HART_SUSPEND_NON_RETENTIVE = 0x80000000, +}; + enum sbi_ext_dbcn_fid { SBI_EXT_DBCN_CONSOLE_WRITE = 0, SBI_EXT_DBCN_CONSOLE_READ, @@ -66,6 +81,8 @@ struct sbiret sbi_ecall(int ext, int fid, unsigned long arg0, void sbi_shutdown(void); struct sbiret sbi_hart_start(unsigned long hartid, unsigned long entry, unsigned long sp); +struct sbiret sbi_hart_stop(void); +struct sbiret sbi_hart_get_status(unsigned long hartid); struct sbiret sbi_send_ipi(unsigned long hart_mask, unsigned long hart_mask_base); long sbi_probe(int ext); diff --git a/lib/riscv/sbi.c b/lib/riscv/sbi.c index 19d58ab7..256196b7 100644 --- a/lib/riscv/sbi.c +++ b/lib/riscv/sbi.c @@ -39,6 +39,16 @@ struct sbiret sbi_hart_start(unsigned long hartid, unsigned long entry, unsigned return sbi_ecall(SBI_EXT_HSM, SBI_EXT_HSM_HART_START, hartid, entry, sp, 0, 0, 0); } +struct sbiret sbi_hart_stop(void) +{ + return sbi_ecall(SBI_EXT_HSM, SBI_EXT_HSM_HART_STOP, 0, 0, 0, 0, 0, 0); +} + +struct sbiret sbi_hart_get_status(unsigned long hartid) +{ + return sbi_ecall(SBI_EXT_HSM, SBI_EXT_HSM_HART_STATUS, hartid, 0, 0, 0, 0, 0); +} + struct sbiret sbi_send_ipi(unsigned long hart_mask, unsigned long hart_mask_base) { return sbi_ecall(SBI_EXT_IPI, SBI_EXT_IPI_SEND_IPI, hart_mask, hart_mask_base, 0, 0, 0, 0); diff --git a/riscv/sbi.c b/riscv/sbi.c index 36ddfd48..6469304b 100644 --- a/riscv/sbi.c +++ b/riscv/sbi.c @@ -72,6 +72,11 @@ static phys_addr_t get_highest_addr(void) return highest_end - 1; } +static struct sbiret sbi_hart_suspend(uint32_t suspend_type, unsigned long resume_addr, unsigned long opaque) +{ + return sbi_ecall(SBI_EXT_HSM, SBI_EXT_HSM_HART_SUSPEND, suspend_type, resume_addr, opaque, 0, 0, 0); +} + static bool env_or_skip(const char *env) { if (!getenv(env)) {