From patchwork Sun Jul 21 07:05:58 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: 1962859 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=Nkhutjky; 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=Y+bnHg1o; 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 4WRZGL63W4z1xrQ for ; Sun, 21 Jul 2024 17:06:50 +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=fo6ZcxIZxFG6fUUX6YlgaAet0el/BDOYSdljK2JbZ/U=; b=Nkhutjky5yVOy6 b+f+r84IqSltYRasXgGUzNeFts/9ZWr0XxIaHB2zomdmuvB6rgxPUbhQqId6zmDz2ci6OsRwK32dr tbohsyRIKVhAuhnKvvhS0x8WjnGceXltUqjPKb+1ZVrzdDgNM93fpsv/zIXIZHehA68H1aRYoZWA8 8HliH3hYYbPpSKmcBnhmEG+Hd5HBmdCMrZ9LbBV8zwnrJLDQwBH8ngC9QRdqVoT7ivssaLB/OEXzR vgWV9sK+Fc4YZh0o9D6EZFNBNk8RYFj1BhRkOGl2er52KvjoYizyhnJoz53er/6yE3oqWFcM62Nal +V2J13JmVFKxMMN7Hglw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sVQef-00000006Lzp-2Dtn; Sun, 21 Jul 2024 07:06:49 +0000 Received: from mail-pj1-x1030.google.com ([2607:f8b0:4864:20::1030]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sVQec-00000006Lyd-2bkp for kvm-riscv@lists.infradead.org; Sun, 21 Jul 2024 07:06:48 +0000 Received: by mail-pj1-x1030.google.com with SMTP id 98e67ed59e1d1-2cb57e25387so2024105a91.3 for ; Sun, 21 Jul 2024 00:06:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1721545606; x=1722150406; 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=BEiXZ1Hftnd13V7cSXtmzxOOQFtbwN2az/SPk33hWyc=; b=Y+bnHg1o4BvFDNZTjfHxdy7moFxH8odvMVM5EzLjqZX9ZMhvbu+7P3OlS47s/rMLc/ xmCXxbW/v+4Yq5peul5+e1ur0Uze7BvdGgVhr+nBJ39w/eg/wfZH2ocOsZ4Xo5IpO+43 lACF2zEGHlCnrpC5PuAzMpqMNSkon9jgmYn689nbjIRJWRhuWpr7kDTRo83EgOLjkHDO B3insZ5i1zPsbjiQcaUQ9dUI1I1Vtkf//9kNOwZ7WAXGUz1OtRiLzf+FhqgCARwNZZkr pjdpfED76ZXnKfC9RGKa4h8VDZ5pjyLls2wCOLCF/w6zInkafXq3tR06v497n8s+4TSa C3iA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721545606; x=1722150406; 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=BEiXZ1Hftnd13V7cSXtmzxOOQFtbwN2az/SPk33hWyc=; b=N9GZCa1tg3lA60qbWuTpo/oH5pPqNglIB1h6wvkHmXIfRtfbG1SOV2gWGRwt6mtFlM +JuTdodsdZwBIJgY+WOQTIwhW07HYkggkS3qONJgevjMmHOJRHUhISuncGUlWV6to4ix 6dciin375YY/DXvxRx4iCKuOqdTs2WMqzOpg4h4Ptq1UYn5DOvdduI0X917T1bHggDSV x9vhytbPSBSvI4gc2tIS8Ji08fGgzQCdAJkmdWWAGsLPVT6tT9YSnr6/OmCKcApG03Qr xOCfyVpyDvaohSQOGQarH5rdeLUIwrU3b6DSbEyxZS5R1pZzuxD4TN2HIBlJvpaZ59+w G3gw== X-Forwarded-Encrypted: i=1; AJvYcCXtIDxM7O3yCdvGJPB0Dk8pUJeCVy9n02eq/+AJI+HReIWqYvAxUoqV7UOjYmQQ0u68QOV/a6NxQseOWHTP5xebXOa3NfVwLFAPyK+WaQ== X-Gm-Message-State: AOJu0YxtzdkF/IH/P0owEWya3p4BwOBrrIDLFW2z6HYso7UBreb3Sp3X YZQ6QB2KBVWXfNQr8jXxxqwUDMbAcjsylB8OSuoWud/gG+la287zYgL2phPi X-Google-Smtp-Source: AGHT+IGqLG6cChuadUwSJR6nMD/h/GchDo5AotWk4zMR+oxtwoOnJrNXEf93syvi6klE5/FW8cHLAA== X-Received: by 2002:a17:90b:1e44:b0:2c9:9fcd:aa51 with SMTP id 98e67ed59e1d1-2cd273d7d38mr2374397a91.5.1721545575837; Sun, 21 Jul 2024 00:06:15 -0700 (PDT) Received: from JRT-PC.. ([180.255.73.78]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2cb77492bc6sm4891461a91.1.2024.07.21.00.06.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 21 Jul 2024 00:06:15 -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 v4 3/5] riscv: Add method to probe for SBI extensions Date: Sun, 21 Jul 2024 15:05:58 +0800 Message-ID: <20240721070601.88639-4-jamestiotio@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240721070601.88639-1-jamestiotio@gmail.com> References: <20240721070601.88639-1-jamestiotio@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240721_000646_682698_ACC4B66E X-CRM114-Status: UNSURE ( 9.84 ) 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 a `sbi_probe` helper method that can be used by SBI extension tests to check if a given extension is available. Suggested-by: Andrew Jones Reviewed-by: Andrew Jones Signed-off-by: James Raphael Tiovalen --- lib/riscv/asm/sbi.h | 1 + lib/riscv/sbi.c | 13 +++++++++++++ 2 files changed, 14 insertions(+) Content analysis details: (-2.1 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -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_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain 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 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2607:f8b0:4864:20:0:0:0:1030 listed in] [list.dnswl.org] 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 a `sbi_probe` helper method that can be used by SBI extension tests to check if a given extension is available. Suggested-by: Andrew Jones Reviewed-by: Andrew Jones Signed-off-by: James Raphael Tiovalen --- lib/riscv/asm/sbi.h | 1 + lib/riscv/sbi.c | 13 +++++++++++++ 2 files changed, 14 insertions(+) diff --git a/lib/riscv/asm/sbi.h b/lib/riscv/asm/sbi.h index d82a384d..5e1a674a 100644 --- a/lib/riscv/asm/sbi.h +++ b/lib/riscv/asm/sbi.h @@ -49,6 +49,7 @@ 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); +long sbi_probe(int ext); #endif /* !__ASSEMBLY__ */ #endif /* _ASMRISCV_SBI_H_ */ diff --git a/lib/riscv/sbi.c b/lib/riscv/sbi.c index f39134c4..3d4236e5 100644 --- a/lib/riscv/sbi.c +++ b/lib/riscv/sbi.c @@ -38,3 +38,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); } + +long sbi_probe(int ext) +{ + struct sbiret ret; + + ret = sbi_ecall(SBI_EXT_BASE, SBI_EXT_BASE_GET_SPEC_VERSION, 0, 0, 0, 0, 0, 0); + assert(!ret.error && ret.value >= 2); + + ret = sbi_ecall(SBI_EXT_BASE, SBI_EXT_BASE_PROBE_EXT, ext, 0, 0, 0, 0, 0); + assert(!ret.error); + + return ret.value; +}