From patchwork Tue Jul 30 06:18:16 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: 1966318 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=MB1nmfTk; 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=Hu6IVDaQ; 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 4WY4mZ5XD6z20Fx for ; Tue, 30 Jul 2024 16:18:36 +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=fWoDH6BiZYLffOMrM5kuhHA6iThHdAA6o8jmrnMRy7E=; b=MB1nmfTkBfrYLE hTZKRDW9ZHDU4vdrDlMsCVzn54ElT575Wf/2Q0WKPl8iLxNjKNrW0utpuCRL29Of0aezxtZHd2DGJ ScsTIi46I2ALpTwcR0K50J01mILqA/23lMkbN5bTvFjxm5vVJA2HrZk/JsSvniMWaZnEo2W3w4YdO Ce4tI0GWdcT9TGDwboU6Z2HsDzUkCg90ohPldXCYgWjRpjqUvPYOIlScOSSaFbnATcyNkrWs2Ycmn NbCurA52UWabOeoaBsECmhnGYNnXNfbqOrXEplrU9wkNjqpJ+GTNI6j6a13O5Dd3q5SjeBRfEfYM+ MImYjrvtihmtFm7jO0ew==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sYgBt-0000000DoTy-3Nrp; Tue, 30 Jul 2024 06:18:33 +0000 Received: from mail-oa1-x34.google.com ([2001:4860:4864:20::34]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sYgBq-0000000DoSv-3Zbo for kvm-riscv@lists.infradead.org; Tue, 30 Jul 2024 06:18:32 +0000 Received: by mail-oa1-x34.google.com with SMTP id 586e51a60fabf-267b7ef154aso2912364fac.0 for ; Mon, 29 Jul 2024 23:18:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1722320309; x=1722925109; 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=joTVeUit/9PHPnwE5WAgfkXToAh6iydIyxEEP0jrhcY=; b=Hu6IVDaQIL42vVbNpbqpsrY3z/Qnmgop3Bqv9hxBeAUmyc9SfbEovsgkL2xCaKfBfb NGN3qugIKeiki7RHoKFKBam9LvY5wSbeoZvQb5cKiQc1hdY21m314ZrIw4PsWGyGjTIe EHMhf6l4Shxd0YNLF5dM6XUXFo5JoAgqRBNhJimd7ZgtNHPEgY2Do6roPYGjywIyx3K0 i5pusLVMdiI2v9d07YQDfDYdleQg1lTE+cIKibsC3hU8z9VJRNj0nDGtdVAsVU/Afsq9 WOvgznqumImEhZBNLH7ikuHXGsHQyUZ3w0tITH2iCS06k4HMnbSw+++fNofy4Use/3DE 0emg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722320309; x=1722925109; 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=joTVeUit/9PHPnwE5WAgfkXToAh6iydIyxEEP0jrhcY=; b=K5m6bzwnAr6UwbyP+GBqYs9pH6qNDps9a9+iGPxVfl1ep5rvr6IoUNYzMAzaX7/DFD zxUFvkt5lswbPezqlLBmH7UM6VKaKoP5Z+kshgjq07Ku7NUn76VXbZE1Zv7azoZ6fu7L oFuDhQbkgkGDJr1bJCa/QuHULd3dN8fsbPVk1qotP2fTCK3W43ZAquVNnQRd1pzBMAMB z09cciXUdTEzOP5MUjNmVAiEYP2ouEPuPGQquXQyj+RSkHRvyzWmHkj3BnFIWSCeO3+K FI6x6PgTMfRM5sMTogthjjbF5aEEgtTqeWkC5H5YczwTenm5Kmt8th33KRFZbEXD1Fa5 UDFQ== X-Forwarded-Encrypted: i=1; AJvYcCWmczqR/930etTz0vdbdmiB5x7J2D1NQVGuAkasZ+tO3moCwtPoT+fIaquz/5GPEEyh9W0xpPThjt7yQaFZ+uNYuiGdOeZMpqhggXOVfQ== X-Gm-Message-State: AOJu0YxVc/zouOcL+63KUGp5Zm9+fI0Jye4fvjg+1mepoURAyiCwj4nk qdvrP4atUXWnltiEWV/75B8I6fRQi7sL76Dxg3vu4tVxEO/pvByP X-Google-Smtp-Source: AGHT+IFZ3x92GfozCY0gffggNOeUFWskApsLodKhUoHGWGIw8sMwo0kCANfV3FpZC5rDkPZNY+qAPg== X-Received: by 2002:a05:6870:7192:b0:254:7211:424b with SMTP id 586e51a60fabf-267d4ccc224mr12102963fac.6.1722320309253; Mon, 29 Jul 2024 23:18:29 -0700 (PDT) Received: from JRT-PC.. ([202.166.44.78]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-70ead6e161dsm7732781b3a.42.2024.07.29.23.18.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Jul 2024 23:18:28 -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 v6 1/5] riscv: Extend exception handling support for interrupts Date: Tue, 30 Jul 2024 14:18:16 +0800 Message-ID: <20240730061821.43811-2-jamestiotio@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240730061821.43811-1-jamestiotio@gmail.com> References: <20240730061821.43811-1-jamestiotio@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240729_231830_898690_645F38D6 X-CRM114-Status: GOOD ( 13.37 ) 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: From: Andrew Jones Add install_irq_handler() to enable tests to install interrupt handlers. Also add local_irq_enable() and local_irq_disable() to respectively enable and disable IRQs via the sstatus.SIE bit. 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 [2001:4860:4864:20:0:0:0:34 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_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_VALID_AU Message has a valid DKIM or DK signature from author's 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] 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 From: Andrew Jones Add install_irq_handler() to enable tests to install interrupt handlers. Also add local_irq_enable() and local_irq_disable() to respectively enable and disable IRQs via the sstatus.SIE bit. Signed-off-by: Andrew Jones Signed-off-by: James Raphael Tiovalen --- lib/riscv/asm/csr.h | 2 ++ lib/riscv/asm/processor.h | 13 +++++++++++++ lib/riscv/processor.c | 27 +++++++++++++++++++++++---- 3 files changed, 38 insertions(+), 4 deletions(-) diff --git a/lib/riscv/asm/csr.h b/lib/riscv/asm/csr.h index 52608512..d6909d93 100644 --- a/lib/riscv/asm/csr.h +++ b/lib/riscv/asm/csr.h @@ -11,6 +11,8 @@ #define CSR_STVAL 0x143 #define CSR_SATP 0x180 +#define SR_SIE _AC(0x00000002, UL) + /* Exception cause high bit - is an interrupt if set */ #define CAUSE_IRQ_FLAG (_AC(1, UL) << (__riscv_xlen - 1)) diff --git a/lib/riscv/asm/processor.h b/lib/riscv/asm/processor.h index 32c499d0..6451adb5 100644 --- a/lib/riscv/asm/processor.h +++ b/lib/riscv/asm/processor.h @@ -5,6 +5,7 @@ #include #define EXCEPTION_CAUSE_MAX 16 +#define INTERRUPT_CAUSE_MAX 16 typedef void (*exception_fn)(struct pt_regs *); @@ -13,6 +14,7 @@ struct thread_info { unsigned long hartid; unsigned long isa[1]; exception_fn exception_handlers[EXCEPTION_CAUSE_MAX]; + exception_fn interrupt_handlers[INTERRUPT_CAUSE_MAX]; }; static inline struct thread_info *current_thread_info(void) @@ -20,7 +22,18 @@ static inline struct thread_info *current_thread_info(void) return (struct thread_info *)csr_read(CSR_SSCRATCH); } +static inline void local_irq_enable(void) +{ + csr_set(CSR_SSTATUS, SR_SIE); +} + +static inline void local_irq_disable(void) +{ + csr_clear(CSR_SSTATUS, SR_SIE); +} + void install_exception_handler(unsigned long cause, void (*handler)(struct pt_regs *)); +void install_irq_handler(unsigned long cause, void (*handler)(struct pt_regs *)); void do_handle_exception(struct pt_regs *regs); void thread_info_init(void); diff --git a/lib/riscv/processor.c b/lib/riscv/processor.c index ece7cbff..0dffadc7 100644 --- a/lib/riscv/processor.c +++ b/lib/riscv/processor.c @@ -36,10 +36,21 @@ void do_handle_exception(struct pt_regs *regs) { struct thread_info *info = current_thread_info(); - assert(regs->cause < EXCEPTION_CAUSE_MAX); - if (info->exception_handlers[regs->cause]) { - info->exception_handlers[regs->cause](regs); - return; + if (regs->cause & CAUSE_IRQ_FLAG) { + unsigned long irq_cause = regs->cause & ~CAUSE_IRQ_FLAG; + + assert(irq_cause < INTERRUPT_CAUSE_MAX); + if (info->interrupt_handlers[irq_cause]) { + info->interrupt_handlers[irq_cause](regs); + return; + } + } else { + assert(regs->cause < EXCEPTION_CAUSE_MAX); + + if (info->exception_handlers[regs->cause]) { + info->exception_handlers[regs->cause](regs); + return; + } } show_regs(regs); @@ -47,6 +58,14 @@ void do_handle_exception(struct pt_regs *regs) abort(); } +void install_irq_handler(unsigned long cause, void (*handler)(struct pt_regs *)) +{ + struct thread_info *info = current_thread_info(); + + assert(cause < INTERRUPT_CAUSE_MAX); + info->interrupt_handlers[cause] = handler; +} + void install_exception_handler(unsigned long cause, void (*handler)(struct pt_regs *)) { struct thread_info *info = current_thread_info(); From patchwork Tue Jul 30 06:18:17 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: 1966320 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=vG8DdUk0; 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=QG4L/Yco; 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 4WY4mZ4vNWz1ybY for ; Tue, 30 Jul 2024 16:18:37 +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=zddro/WZHx/BaI62je1E6TZ0lg4vQwzOiSW9lsLVnr4=; b=vG8DdUk0IFgCMn ziG5IwSLgWTY3Ku58SaHXISSTlNc9xmy6SJWhKyD1Xm1E44DVvRXOAlaAPwScmGFYEr/TOXOp5UY/ aPAf7Goo3CL9S/IEKkh/UK9KbF6M3JFk4VSFwtrXaf1xlZeDS3T4NvNH83/9ggEKLOS37hGUFOcjH iqIiu54yAGKyBPPQTW/pQRuTd3TDhLTpmQfUmYz8NnHdo8DefOYjBM+ZXuK/kWNEGSDOTs2c1Z6bo Sxe2riWT3GuZZ/3QpsvbrL0KkUf7+SpLXHsYvPPwAC4KlMDY0RasntI8BoTd2TLw+Zz8sYk0TYUS5 0hohNcPtuqVRni/rCqoA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sYgBw-0000000DoUY-0kjL; Tue, 30 Jul 2024 06:18:36 +0000 Received: from mail-pf1-x42f.google.com ([2607:f8b0:4864:20::42f]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sYgBs-0000000DoTV-3jsH for kvm-riscv@lists.infradead.org; Tue, 30 Jul 2024 06:18:34 +0000 Received: by mail-pf1-x42f.google.com with SMTP id d2e1a72fcca58-70d1d818c42so2521739b3a.1 for ; Mon, 29 Jul 2024 23:18:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1722320312; x=1722925112; 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=YOqEXJYpkIexGhOwSJXzU52SvIkIRl2QtZdZCBi6Nm8=; b=QG4L/YcorGO3JP7wbD9rLmftXT2k2QpT7atU48mFtaxl7T3QKoMkvbQRas6ghFuJ+0 jzvNkB+EI1Nhe1Lq1hDErwRW8Y8Uul0v0RnNz6lKKwSIcLxr6hYGItqtvQDsKLTnfUm1 wCXjLE+35HalrAcqQFUbpfN8mr5eewvBRB63SzWJUyxo6PYgf/z7SDw40Rd5/afDYjmM 51NYtSCy0ItgdJvcsPILEwpa9+IUnVAV4/LFdjfptOxsY/nUlHC/ZSRoYU8bfQjB8VpV mKSBRdCHXeaTNbbKHSH9Edfl5EFePIfSGCX5r07pnYcki87+grcy+tHGk7AOdUru3nue x53g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722320312; x=1722925112; 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=YOqEXJYpkIexGhOwSJXzU52SvIkIRl2QtZdZCBi6Nm8=; b=GeEK4xFo7Zq7Dq7f9bYROjJUn2dAiLzGpGvoSDM4YDXAR9tRYAGwzyQE6I1jPfbBul WENjjXHve/vm5/tKBfv+/VC56GxQjR22S4G1qBn3lTbmLsShfMF2S+8VnfCqOncpeGKx GA7EgUb0lcsxDFHXOJQpMmauZrAsJEOr8+/p4OaEtjuElxdVDusfrBUMLwxEwOcKOuLl hsvNx8yHiCsckMC3GsBQuZeBNiNcaXJLJoImQc9Nk/9SRRfh/Gd8Fxa+xGti+l840Jo2 xARmXy7RiLfV2LuMwIZU45qlbvkf8GoFNEKbZXjue/L1cUaJ6cOMgOUykhoLY89Yl0mN xZqg== X-Forwarded-Encrypted: i=1; AJvYcCURdE1oLaX4WmVdX63u8r+Qvd1sV4DYZhvEFOXjklVUdJszdf38LzIGcPNNtvWHbH5UWLi6HliLKN23akkTzV7jLrQ0LzdZxsJXTJXe2g== X-Gm-Message-State: AOJu0YzvzzeGsMKmZVc/zJejtKz/JaPAUEmPZGO2p3te31Bz+XZB/Q0x WrevI2ahkPaTskLnbg+ABraaM3wZ1ETF9M0THiWbqObCa7vRqrAr X-Google-Smtp-Source: AGHT+IGueUZNpYqBiwQ62P95Q5NRqthBhu516As+jDWGSNvqn1Hw5DPqrLuTQBmoOvfL7J5BmHJ/oA== X-Received: by 2002:aa7:88c5:0:b0:70d:262e:7279 with SMTP id d2e1a72fcca58-70ecea01412mr10223964b3a.3.1722320311581; Mon, 29 Jul 2024 23:18:31 -0700 (PDT) Received: from JRT-PC.. ([202.166.44.78]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-70ead6e161dsm7732781b3a.42.2024.07.29.23.18.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Jul 2024 23:18:31 -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 v6 2/5] riscv: Update exception cause list Date: Tue, 30 Jul 2024 14:18:17 +0800 Message-ID: <20240730061821.43811-3-jamestiotio@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240730061821.43811-1-jamestiotio@gmail.com> References: <20240730061821.43811-1-jamestiotio@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240729_231832_936642_C894705A X-CRM114-Status: GOOD ( 10.13 ) 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: Update the list of exception and interrupt causes to follow the latest RISC-V privileged ISA specification (version 20240411 section 18.6.1). Reviewed-by: Andrew Jones Signed-off-by: James Raphael Tiovalen --- lib/riscv/asm/csr.h | 10 ++++++++++ lib/riscv/asm/processor.h | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) 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: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_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_VALID_AU Message has a valid DKIM or DK signature from author's 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] 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 Update the list of exception and interrupt causes to follow the latest RISC-V privileged ISA specification (version 20240411 section 18.6.1). Reviewed-by: Andrew Jones Signed-off-by: James Raphael Tiovalen --- lib/riscv/asm/csr.h | 10 ++++++++++ lib/riscv/asm/processor.h | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/riscv/asm/csr.h b/lib/riscv/asm/csr.h index d6909d93..ba810c9f 100644 --- a/lib/riscv/asm/csr.h +++ b/lib/riscv/asm/csr.h @@ -36,6 +36,16 @@ #define EXC_VIRTUAL_INST_FAULT 22 #define EXC_STORE_GUEST_PAGE_FAULT 23 +/* Interrupt causes */ +#define IRQ_S_SOFT 1 +#define IRQ_VS_SOFT 2 +#define IRQ_S_TIMER 5 +#define IRQ_VS_TIMER 6 +#define IRQ_S_EXT 9 +#define IRQ_VS_EXT 10 +#define IRQ_S_GEXT 12 +#define IRQ_PMU_OVF 13 + #ifndef __ASSEMBLY__ #define csr_swap(csr, val) \ diff --git a/lib/riscv/asm/processor.h b/lib/riscv/asm/processor.h index 6451adb5..4c9ad968 100644 --- a/lib/riscv/asm/processor.h +++ b/lib/riscv/asm/processor.h @@ -4,7 +4,7 @@ #include #include -#define EXCEPTION_CAUSE_MAX 16 +#define EXCEPTION_CAUSE_MAX 24 #define INTERRUPT_CAUSE_MAX 16 typedef void (*exception_fn)(struct pt_regs *); From patchwork Tue Jul 30 06:18:18 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: 1966319 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=qtskxwzj; 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=TtpHzveU; 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 4WY4mb084Bz20G6 for ; Tue, 30 Jul 2024 16:18:38 +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=qtskxwzj0y+SN8 msT4yy9y2jGMTrAZPpLAag12hmTyLylf0JFYH87oxwAxgfDU8DMffLxwPiSoPhyRg1Tnb4sA9IKWd HFNnwe638hWXnbMELZfjDPNP1ZKNcGKN4ukZkpa2xbQS9ljmUpDqTGWuHtLeJE/9+sOSuV6zATk4o NEpeJJ1vksxFGwtIqWmcly0yxZkRKaIptOkG4V7zK8/Q6+v3FpmEyXobj5AD/Hqzw5iDw1LcVn8cT FTNu+nUFR27BBfPJ1+T+Oq2lYgZmo1jAo9BjpqA4+UxGEZA1Ie7J4J+NptC9c3z1FlGl251QzRfFM cdaljdeqbKCXWZyX6Tcw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sYgBx-0000000DoVe-2MbV; Tue, 30 Jul 2024 06:18:37 +0000 Received: from mail-pf1-x436.google.com ([2607:f8b0:4864:20::436]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sYgBv-0000000DoUF-0p4v for kvm-riscv@lists.infradead.org; Tue, 30 Jul 2024 06:18:36 +0000 Received: by mail-pf1-x436.google.com with SMTP id d2e1a72fcca58-70d18d4b94cso2908294b3a.2 for ; Mon, 29 Jul 2024 23:18:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1722320314; x=1722925114; 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=TtpHzveUit4PQiRqSVaEc+E3vZ8azePIyIdMQMZyvXHvBNdS8DdiN0P1Gtg6jhvmFY PwQv8eYANs7O6NXLFSbXTrlWUy50CRBefj03vet7p/2WUzMrDsf8KQ0IRZ63hUkCDQEH NEqgbdFlsg5Wb4brWJswUyOCj4f6insZKR0tGZzEvMXfjrfnLRO3/1SXmijz0ON7d6H5 NZOHXVBnqHGre/LTjmLKTtUrRVRGPfhRX9rUUaKLr83C33WGTjWDaAytgu1W9r38uKuA +U8cFyA6MwbH7gDgxor8S6chVkSzhVgm33UUKf0g5jDdEoI1UyYunJxZn1SBKbvlKEU5 AcXg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722320314; x=1722925114; 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=rgg5mEqY/XVogsm03X9EP2FxTKc3JAM9+R1Zdz2w50WL7zfQ+2HwnF4ENwvD+/k9lv pUT/5xUh3kvQyXqmQtxX0a8qtrX6AG9aPfHjROZVjCkvWZwc8UYsQ9xfEDFTwayoLgxO ObRO76rjpLTQnOTXNFqQ+wsLJAJq+lYcOEQBqlXvUUBxyGA4OQg41fFAY0Tu3anLlEKu 0FmDYbrScYfurD7SzYHeAR0e91ZGmiCEGgWMv6wKc9ISBPr4JRzC13A/CJqIJ5vYvdW0 +1egquHFQA0OOwkWt6Nf6E9VnFsMOqbFJOkeDAu/CbV/65GVTfu8AY634Pc9DiC/IbEo l5RA== X-Forwarded-Encrypted: i=1; AJvYcCVgd2eTmaesi7hX4TbXYutvwTyL2TfmgZJbL4XZZqJ2hZF4Di6swhfQdnPurfOhW2IvG9UeOhHTkVT5v00k9tffQuTiHLTSVRV995+9CQ== X-Gm-Message-State: AOJu0YyewIbEvi0EtnxGpDDMVDcKksKvNOD0ZjxtO+VTuJ4PhE3R2w2w ZKlf4PVPM5TH5pIy+zXIQd4haoNrquIijqICZh3BF7jS5YC8Q0aP X-Google-Smtp-Source: AGHT+IHEOGQoMzw6uwNYgIfG5QWUNtOH7qO1sK3jwBwHoTREqCpBgVGPtSWJwiAOfdutPlMvqnSdKw== X-Received: by 2002:a05:6a20:9e4b:b0:1be:c2f7:275 with SMTP id adf61e73a8af0-1c4a153355fmr8735392637.50.1722320313931; Mon, 29 Jul 2024 23:18:33 -0700 (PDT) Received: from JRT-PC.. ([202.166.44.78]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-70ead6e161dsm7732781b3a.42.2024.07.29.23.18.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Jul 2024 23:18:33 -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 v6 3/5] riscv: Add method to probe for SBI extensions Date: Tue, 30 Jul 2024 14:18:18 +0800 Message-ID: <20240730061821.43811-4-jamestiotio@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240730061821.43811-1-jamestiotio@gmail.com> References: <20240730061821.43811-1-jamestiotio@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240729_231835_240802_FBE2D4D1 X-CRM114-Status: GOOD ( 10.08 ) 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 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2607:f8b0:4864:20:0:0:0:436 listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.1 DKIM_VALID_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_VALID_AU Message has a valid DKIM or DK signature from author's 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] 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; +} From patchwork Tue Jul 30 06:18:19 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: 1966322 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=4diSP4sj; 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=b+8UEUp0; 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 4WY4mf3bWcz1yYq for ; Tue, 30 Jul 2024 16:18:42 +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=sHnZKN/bbX1lFUtyjP5kt03qAM++oTRJyTNZdrQ1Xp0=; b=4diSP4sjV6RJnN QJDsaZYKA0FZ8rSiFCEqS7mIY5zUg+ooLmzeDfBp9OmRgf1jBNqeKdSx/zwO2pT/XDcDUJqjfIwQm e9iNjkwSJcKfafdWQ4FyDhkpJgBQGlcEPBxpnTesX+D+iWDKvOuEaIwfqgc+y6SCzkO7bZLtiF/LR ugEVI7OoY0qFWDF7xXWq6ZO6yJQlsHvsAIuNN8T9325+UgSmlxEkRm9X7lHjhwAVjIKakKyR2actn pH+WfptFz4MG+CURHenAWIBJUdUxmkFg+gQiple91cxgOT0Gn8SG2k5QVBeJWDN57CzNiSoctdwTY HbqB8KXYAuI/6vVvmK5Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sYgC1-0000000DoYL-13Pt; Tue, 30 Jul 2024 06:18:41 +0000 Received: from mail-pf1-x42f.google.com ([2607:f8b0:4864:20::42f]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sYgBx-0000000DoV3-0oHJ for kvm-riscv@lists.infradead.org; Tue, 30 Jul 2024 06:18:39 +0000 Received: by mail-pf1-x42f.google.com with SMTP id d2e1a72fcca58-70d1a74a43bso2765369b3a.1 for ; Mon, 29 Jul 2024 23:18:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1722320316; x=1722925116; 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=wwRnLnxZnIX7jpw6TVepgUUISRg5HGFY1cuRHhUH+u4=; b=b+8UEUp0UTbfYsSFgxTKxV23Kg8VkY/c2JfhwhizUlziGoHoUzYy/OXZ+yWYvU1QPf D1Ap/AsouRDr7ACOvsNSjFBV2ug1d1nGMSMwysJIkmHojc9/XrRvkDon+jFHkmFoaKJo qMe13U69rTL6DsY4cuhWKL7/96yizM6JSCk2IzjAQaIbonSXTCVaHfBQTEpI22khUpOZ jTDlovY8HAIYAS0FUwPyGcl6L6wnwJxKVEhUxeb3k7ulCBzHezhSYMUQwNKUH0K1acpK drEbXKt+5K/TmDVnPgqodVSAJwSoaPlA1gCNmcNzesl0zzo3U/7AtrcE+58o/2XN6rCE ODjA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722320316; x=1722925116; 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=wwRnLnxZnIX7jpw6TVepgUUISRg5HGFY1cuRHhUH+u4=; b=OHg8fuiEZ324wr/XHagdtZkJRmwQXZZWdeiSEZdHISD+iKhCP5gOmKyt+SNWYslEaY z7Z3CpbUeIfYQZv5jgK2B4XFDGPcPmve0wgV4mici38tS8MIufqP0+T6rFtjyg3XTw3k YnGwnxbhwsQdbYgt7fKV29EzKhqsbM9uIxDPyaowx2fD8O418kCx3uEfwcNRTSGRTCfl sQ0r3qL3abJ36z8udaXil7E3qdBqf0bg3ZjN6ge/5/b916SsEwZcjwg4U5v1YkZSsmkD fCKNT1QHbAD1kQhmFeu5fNqNUuIRKPzixmypAAppfzmiPj4AMW0UcAUcx3CsvhScjZp8 TZ5A== X-Forwarded-Encrypted: i=1; AJvYcCULGeeegXLfJavvp8zdZj1yz0lCgOtAuC/f1iG2q8yMqNnVftOR0nxu7Zk6IHtOlJXCm3q5EL+VbdEG8PJsmEaXn53GrJ+STH4fTF6hdw== X-Gm-Message-State: AOJu0Yz+3xz1fLiIVI1v1wNQyOXCcItR8STn0osczAx89ATrP0x0YZ/t /xFsLlXo/lM96waYt0OP7lsfMp35f3/qAmIkXNRmuDfBT6GxNCs2 X-Google-Smtp-Source: AGHT+IEOe21GzPpIFL9RJlKO9WKXPkc5wU/dA9Yimqtc6/HmISTe4cOgbk2Kf7vwcHA2NB7i87ed8A== X-Received: by 2002:a05:6a21:789f:b0:1bd:7559:1710 with SMTP id adf61e73a8af0-1c4a12a2e50mr9193595637.14.1722320316245; Mon, 29 Jul 2024 23:18:36 -0700 (PDT) Received: from JRT-PC.. ([202.166.44.78]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-70ead6e161dsm7732781b3a.42.2024.07.29.23.18.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Jul 2024 23:18:35 -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 v6 4/5] riscv: Add some delay and timer routines Date: Tue, 30 Jul 2024 14:18:19 +0800 Message-ID: <20240730061821.43811-5-jamestiotio@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240730061821.43811-1-jamestiotio@gmail.com> References: <20240730061821.43811-1-jamestiotio@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240729_231837_252937_E45D81A1 X-CRM114-Status: GOOD ( 17.76 ) 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 delay method that would allow tests to wait for some specified number of cycles. Also add a conversion helper method between microseconds and cycles. This conversion is done by using the timebas [...] 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: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_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_VALID_AU Message has a valid DKIM or DK signature from author's 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] 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 delay method that would allow tests to wait for some specified number of cycles. Also add a conversion helper method between microseconds and cycles. This conversion is done by using the timebase frequency, which is obtained during setup via the device tree. Reviewed-by: Andrew Jones Signed-off-by: James Raphael Tiovalen --- riscv/Makefile | 2 ++ lib/riscv/asm/csr.h | 1 + lib/riscv/asm/delay.h | 16 ++++++++++++++++ lib/riscv/asm/setup.h | 1 + lib/riscv/asm/timer.h | 14 ++++++++++++++ lib/riscv/delay.c | 21 +++++++++++++++++++++ lib/riscv/setup.c | 4 ++++ lib/riscv/timer.c | 28 ++++++++++++++++++++++++++++ 8 files changed, 87 insertions(+) create mode 100644 lib/riscv/asm/delay.h create mode 100644 lib/riscv/asm/timer.h create mode 100644 lib/riscv/delay.c create mode 100644 lib/riscv/timer.c diff --git a/riscv/Makefile b/riscv/Makefile index 919a3ebb..b0cd613f 100644 --- a/riscv/Makefile +++ b/riscv/Makefile @@ -30,6 +30,7 @@ cflatobjs += lib/memregions.o cflatobjs += lib/on-cpus.o cflatobjs += lib/vmalloc.o cflatobjs += lib/riscv/bitops.o +cflatobjs += lib/riscv/delay.o cflatobjs += lib/riscv/io.o cflatobjs += lib/riscv/isa.o cflatobjs += lib/riscv/mmu.o @@ -38,6 +39,7 @@ cflatobjs += lib/riscv/sbi.o cflatobjs += lib/riscv/setup.o cflatobjs += lib/riscv/smp.o cflatobjs += lib/riscv/stack.o +cflatobjs += lib/riscv/timer.o ifeq ($(ARCH),riscv32) cflatobjs += lib/ldiv32.o endif diff --git a/lib/riscv/asm/csr.h b/lib/riscv/asm/csr.h index ba810c9f..a9b1bd42 100644 --- a/lib/riscv/asm/csr.h +++ b/lib/riscv/asm/csr.h @@ -10,6 +10,7 @@ #define CSR_SCAUSE 0x142 #define CSR_STVAL 0x143 #define CSR_SATP 0x180 +#define CSR_TIME 0xc01 #define SR_SIE _AC(0x00000002, UL) diff --git a/lib/riscv/asm/delay.h b/lib/riscv/asm/delay.h new file mode 100644 index 00000000..31379eac --- /dev/null +++ b/lib/riscv/asm/delay.h @@ -0,0 +1,16 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +#ifndef _ASMRISCV_DELAY_H_ +#define _ASMRISCV_DELAY_H_ + +#include +#include + +extern void delay(uint64_t cycles); +extern void udelay(unsigned long usecs); + +static inline uint64_t usec_to_cycles(uint64_t usec) +{ + return (timebase_frequency * usec) / 1000000; +} + +#endif /* _ASMRISCV_DELAY_H_ */ diff --git a/lib/riscv/asm/setup.h b/lib/riscv/asm/setup.h index 7f81a705..a13159bf 100644 --- a/lib/riscv/asm/setup.h +++ b/lib/riscv/asm/setup.h @@ -7,6 +7,7 @@ #define NR_CPUS 16 extern struct thread_info cpus[NR_CPUS]; extern int nr_cpus; +extern uint64_t timebase_frequency; int hartid_to_cpu(unsigned long hartid); void io_init(void); diff --git a/lib/riscv/asm/timer.h b/lib/riscv/asm/timer.h new file mode 100644 index 00000000..f7504f84 --- /dev/null +++ b/lib/riscv/asm/timer.h @@ -0,0 +1,14 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +#ifndef _ASMRISCV_TIMER_H_ +#define _ASMRISCV_TIMER_H_ + +#include + +extern void timer_get_frequency(void); + +static inline uint64_t timer_get_cycles(void) +{ + return csr_read(CSR_TIME); +} + +#endif /* _ASMRISCV_TIMER_H_ */ diff --git a/lib/riscv/delay.c b/lib/riscv/delay.c new file mode 100644 index 00000000..d4f76c29 --- /dev/null +++ b/lib/riscv/delay.c @@ -0,0 +1,21 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Copyright (C) 2024, James Raphael Tiovalen + */ +#include +#include +#include +#include + +void delay(uint64_t cycles) +{ + uint64_t start = timer_get_cycles(); + + while ((timer_get_cycles() - start) < cycles) + cpu_relax(); +} + +void udelay(unsigned long usecs) +{ + delay(usec_to_cycles((uint64_t)usecs)); +} diff --git a/lib/riscv/setup.c b/lib/riscv/setup.c index 50ffb0d0..e0b5f6f7 100644 --- a/lib/riscv/setup.c +++ b/lib/riscv/setup.c @@ -20,6 +20,7 @@ #include #include #include +#include #define VA_BASE ((phys_addr_t)3 * SZ_1G) #if __riscv_xlen == 64 @@ -38,6 +39,7 @@ u32 initrd_size; struct thread_info cpus[NR_CPUS]; int nr_cpus; +uint64_t timebase_frequency; static struct mem_region riscv_mem_regions[NR_MEM_REGIONS + 1]; @@ -199,6 +201,7 @@ void setup(const void *fdt, phys_addr_t freemem_start) mem_init(PAGE_ALIGN(__pa(freemem))); cpu_init(); + timer_get_frequency(); thread_info_init(); io_init(); @@ -264,6 +267,7 @@ efi_status_t setup_efi(efi_bootinfo_t *efi_bootinfo) } cpu_init(); + timer_get_frequency(); thread_info_init(); io_init(); initrd_setup(); diff --git a/lib/riscv/timer.c b/lib/riscv/timer.c new file mode 100644 index 00000000..d78d254c --- /dev/null +++ b/lib/riscv/timer.c @@ -0,0 +1,28 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Copyright (C) 2024, James Raphael Tiovalen + */ +#include +#include +#include +#include + +void timer_get_frequency(void) +{ + const struct fdt_property *prop; + u32 *data; + int cpus, len; + + assert_msg(dt_available(), "ACPI not yet supported"); + + const void *fdt = dt_fdt(); + + cpus = fdt_path_offset(fdt, "/cpus"); + assert(cpus >= 0); + + prop = fdt_get_property(fdt, cpus, "timebase-frequency", &len); + assert(prop != NULL && len == 4); + + data = (u32 *)prop->data; + timebase_frequency = fdt32_to_cpu(*data); +} From patchwork Tue Jul 30 06:18:20 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: 1966323 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=Pxn6DjZC; 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=Ll4cxMSu; 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 4WY4mg6Qhrz1yYq for ; Tue, 30 Jul 2024 16:18:43 +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=hG6qf7PaPjtP2YnLFM2EaNQzvwnGb8a6A755Udvqvzo=; b=Pxn6DjZCnLwyhq 5I9OE+8hmaQf+I38MY75fmhD+FCx2yew0OsxoP0lgGFtJVbn/eOmXuCciUBoqDoSLjpgp93iaDXyI 6q3i49P/TbQwv7Zkhmp1kRa8PpNrcb6OPxZEZWjvIg5WrK5L3nYKVzx7JBmH0hIU3wRN8pqeu/Twc ZrFcm5XvIMo/okeIvH2paV3dRLdNW1q1pJ/q6megFaYDABrezck3oTWhe5f7lteClNgQKd+s4Off/ ytRS5HGjaXI0JTaE2mEziAqgiFxTSvOPEs0jevWRBfgPI989yBC7QMOBxZntHw9wo6epq3gIHuheO UL7T2rk4IUbNshayIxsw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sYgC2-0000000DoZe-2rWl; Tue, 30 Jul 2024 06:18:42 +0000 Received: from mail-pf1-x432.google.com ([2607:f8b0:4864:20::432]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sYgBz-0000000DoWw-3hpZ for kvm-riscv@lists.infradead.org; Tue, 30 Jul 2024 06:18:41 +0000 Received: by mail-pf1-x432.google.com with SMTP id d2e1a72fcca58-70d18112b60so2943797b3a.1 for ; Mon, 29 Jul 2024 23:18:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1722320319; x=1722925119; 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=b9aR+63uT7v78VjbRv6DJCJHpLF+0X46I4y0U041o2c=; b=Ll4cxMSuoPnTQLYaIRLS7Ylre7U9VGUuJ84BPNd4LU3C9ZD8JOv9nypSPl31ZhqwWA eycgbBzYIr5AIMkXLqJ0AOpMOibziZOu65/MxLkYJCpEbmBqHxtZfE8lGhMjkXYXk5UO 08W6WuqLLb3BnLLPJsnpvrN1quZ/ITxV0a5ODFTosDl2lYHBgEU3G1osLyX5tvz+odfY gE5YEvXfbyjh1vWudSXdBx9JJXcQnKFwIEmHPB58aqQ0qxu8sEDCHNh3LxDJvft7Rtug 7RYm/svYzrrpKsM5QhQ2Xe/A5perTs7fonmcC4+q3JstaF4VyD4ItCDspNqeGK7cPY0V 75ig== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722320319; x=1722925119; 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=b9aR+63uT7v78VjbRv6DJCJHpLF+0X46I4y0U041o2c=; b=JbUteGf1xUimEiYWwHBNLQ1xCoKEgmgSUg7wKiZ/PfE8m476wqNrpp4oTKvnX56gnL 38tzp/jWSKryxH18P71nm+hpLVQq0PKw7obFEdB8PrcXHNpb0OozSItrwVlNRo0WrBrR C8+eo+Pvlv9vTuVLxwaTZaQ6TCF/eyE3otwsIXkJiQ1xQjcYmbIwYMiqSHER9v59I2WX r7CbmsQSL30II2DsBT5OtmDMmFJIkbZewW0e0vWNZ3S7BQ8RC+t8RMNClvD8RljbvpQM IEFJITgqkx2Lb7lLzhFmX5C+QqDBgc716jyHvHRtUWDcHPjHm7eRH4pGjx/JmNjvkHD+ kLzQ== X-Forwarded-Encrypted: i=1; AJvYcCXBmLbn9r7Y/v25/7ocOQjbipv/k9btxeW3301VZgfUXsuDw+OXpDM+PIdv1l3fM5k1gFEKM8Ku/M0LaV3UlRH/altlvgb+RlTw30cu9g== X-Gm-Message-State: AOJu0YyUEUDb/4HjqT8eGaEQCgg9tv4cumttsk5OuLsgl18AXbYdc8jo CsZOVXKPWJD2MXB7shKevQefKd62bKRG7TirEgDj4BW1PO221FQ0 X-Google-Smtp-Source: AGHT+IEAIFl8b07iaWFTucQrr8o5u8AfL9aHdpepBAosSPFLueK4FRXeZIiIZifwd3D2tPdwPtlgDA== X-Received: by 2002:aa7:8257:0:b0:70e:ce95:b87 with SMTP id d2e1a72fcca58-70efe2a2430mr1637242b3a.0.1722320318624; Mon, 29 Jul 2024 23:18:38 -0700 (PDT) Received: from JRT-PC.. ([202.166.44.78]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-70ead6e161dsm7732781b3a.42.2024.07.29.23.18.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Jul 2024 23:18:38 -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 v6 5/5] riscv: sbi: Add test for timer extension Date: Tue, 30 Jul 2024 14:18:20 +0800 Message-ID: <20240730061821.43811-6-jamestiotio@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240730061821.43811-1-jamestiotio@gmail.com> References: <20240730061821.43811-1-jamestiotio@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240729_231839_948908_A8334B32 X-CRM114-Status: GOOD ( 19.51 ) 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 test for the set_timer function of the time extension. The test checks that: - The time extension is available - The installed timer interrupt handler is called - The timer interrupt is received [...] 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: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_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_VALID_AU Message has a valid DKIM or DK signature from author's 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] 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 test for the set_timer function of the time extension. The test checks that: - The time extension is available - The installed timer interrupt handler is called - The timer interrupt is received within a reasonable time interval - The timer interrupt pending bit is cleared after the set_timer SBI call is made - The timer interrupt can be cleared either by requesting a timer interrupt infinitely far into the future or by masking the timer interrupt The timer interrupt delay can be set using the TIMER_DELAY environment variable in microseconds. The default delay value is 200 milliseconds. Since the interrupt can arrive a little later than the specified delay, allow some margin of error. This margin of error can be specified via the TIMER_MARGIN environment variable in microseconds. The default margin of error is 200 milliseconds. Reviewed-by: Andrew Jones Signed-off-by: James Raphael Tiovalen --- lib/riscv/asm/csr.h | 8 +++ lib/riscv/asm/sbi.h | 5 ++ lib/riscv/asm/timer.h | 10 ++++ riscv/sbi.c | 127 ++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 150 insertions(+) diff --git a/lib/riscv/asm/csr.h b/lib/riscv/asm/csr.h index a9b1bd42..24b333e0 100644 --- a/lib/riscv/asm/csr.h +++ b/lib/riscv/asm/csr.h @@ -4,11 +4,15 @@ #include #define CSR_SSTATUS 0x100 +#define CSR_SIE 0x104 #define CSR_STVEC 0x105 #define CSR_SSCRATCH 0x140 #define CSR_SEPC 0x141 #define CSR_SCAUSE 0x142 #define CSR_STVAL 0x143 +#define CSR_SIP 0x144 +#define CSR_STIMECMP 0x14d +#define CSR_STIMECMPH 0x15d #define CSR_SATP 0x180 #define CSR_TIME 0xc01 @@ -47,6 +51,10 @@ #define IRQ_S_GEXT 12 #define IRQ_PMU_OVF 13 +#define IE_TIE (_AC(0x1, UL) << IRQ_S_TIMER) + +#define IP_TIP IE_TIE + #ifndef __ASSEMBLY__ #define csr_swap(csr, val) \ diff --git a/lib/riscv/asm/sbi.h b/lib/riscv/asm/sbi.h index 5e1a674a..73ab5438 100644 --- a/lib/riscv/asm/sbi.h +++ b/lib/riscv/asm/sbi.h @@ -16,6 +16,7 @@ enum sbi_ext_id { SBI_EXT_BASE = 0x10, + SBI_EXT_TIME = 0x54494d45, SBI_EXT_HSM = 0x48534d, SBI_EXT_SRST = 0x53525354, }; @@ -37,6 +38,10 @@ enum sbi_ext_hsm_fid { SBI_EXT_HSM_HART_SUSPEND, }; +enum sbi_ext_time_fid { + SBI_EXT_TIME_SET_TIMER = 0, +}; + struct sbiret { long error; long value; diff --git a/lib/riscv/asm/timer.h b/lib/riscv/asm/timer.h index f7504f84..b3514d3f 100644 --- a/lib/riscv/asm/timer.h +++ b/lib/riscv/asm/timer.h @@ -11,4 +11,14 @@ static inline uint64_t timer_get_cycles(void) return csr_read(CSR_TIME); } +static inline void timer_irq_enable(void) +{ + csr_set(CSR_SIE, IE_TIE); +} + +static inline void timer_irq_disable(void) +{ + csr_clear(CSR_SIE, IE_TIE); +} + #endif /* _ASMRISCV_TIMER_H_ */ diff --git a/riscv/sbi.c b/riscv/sbi.c index 762e9711..9fc099df 100644 --- a/riscv/sbi.c +++ b/riscv/sbi.c @@ -6,7 +6,25 @@ */ #include #include +#include +#include +#include +#include +#include +#include #include +#include +#include + +struct timer_info { + bool timer_works; + bool mask_timer_irq; + bool timer_irq_set; + bool timer_irq_cleared; + unsigned long timer_irq_count; +}; + +static struct timer_info timer_info; static void help(void) { @@ -19,6 +37,78 @@ static struct sbiret __base_sbi_ecall(int fid, unsigned long arg0) return sbi_ecall(SBI_EXT_BASE, fid, arg0, 0, 0, 0, 0, 0); } +static struct sbiret __time_sbi_ecall(unsigned long stime_value) +{ + return sbi_ecall(SBI_EXT_TIME, SBI_EXT_TIME_SET_TIMER, stime_value, 0, 0, 0, 0, 0); +} + +static bool timer_irq_pending(void) +{ + return csr_read(CSR_SIP) & IP_TIP; +} + +static void timer_irq_handler(struct pt_regs *regs) +{ + if (timer_info.timer_irq_count < ULONG_MAX) + ++timer_info.timer_irq_count; + + timer_info.timer_works = true; + if (timer_irq_pending()) + timer_info.timer_irq_set = true; + + if (timer_info.mask_timer_irq) { + timer_irq_disable(); + __time_sbi_ecall(0); + } else { + __time_sbi_ecall(ULONG_MAX); + } + + if (!timer_irq_pending()) + timer_info.timer_irq_cleared = true; +} + +static void execute_set_timer_test(bool mask_timer_irq) +{ + struct sbiret ret; + unsigned long begin, end, duration; + const char *mask_test_str = mask_timer_irq ? " for mask irq test" : ""; + const char *clear_irq_bit_str = mask_timer_irq ? "masking timer irq" + : "setting timer to -1"; + unsigned long d = getenv("TIMER_DELAY") ? strtol(getenv("TIMER_DELAY"), NULL, 0) + : 200000; + unsigned long margin = getenv("TIMER_MARGIN") ? strtol(getenv("TIMER_MARGIN"), NULL, 0) + : 200000; + + d = usec_to_cycles(d); + margin = usec_to_cycles(margin); + + timer_info = (struct timer_info){ .mask_timer_irq = mask_timer_irq }; + begin = timer_get_cycles(); + ret = __time_sbi_ecall(begin + d); + + report(!ret.error, "set timer%s", mask_test_str); + if (ret.error) + report_info("set timer%s failed with %ld\n", mask_test_str, ret.error); + + while ((end = timer_get_cycles()) <= (begin + d + margin) && !timer_info.timer_works) + cpu_relax(); + + report(timer_info.timer_works, "timer interrupt received%s", mask_test_str); + report(timer_info.timer_irq_set, "pending timer interrupt bit set in irq handler%s", + mask_test_str); + report(timer_info.timer_irq_set && timer_info.timer_irq_cleared, + "pending timer interrupt bit cleared by %s", clear_irq_bit_str); + + if (timer_info.timer_works) { + duration = end - begin; + report(duration >= d && duration <= (d + margin), "timer delay honored%s", + mask_test_str); + } + + if (timer_info.timer_irq_count > 1) + report_fail("timer interrupt received multiple times%s", mask_test_str); +} + static bool env_or_skip(const char *env) { if (!getenv(env)) { @@ -112,6 +202,42 @@ static void check_base(void) report_prefix_pop(); } +static void check_time(void) +{ + report_prefix_push("time"); + + if (!sbi_probe(SBI_EXT_TIME)) { + report_skip("time extension not available"); + report_prefix_pop(); + return; + } + + report_prefix_push("set_timer"); + + install_irq_handler(IRQ_S_TIMER, timer_irq_handler); + local_irq_enable(); + if (cpu_has_extension(smp_processor_id(), ISA_SSTC)) { + csr_write(CSR_STIMECMP, ULONG_MAX); +#if __riscv_xlen == 32 + csr_write(CSR_STIMECMPH, ULONG_MAX); +#endif + } + timer_irq_enable(); + + execute_set_timer_test(false); + + if (csr_read(CSR_SIE) & IE_TIE) + execute_set_timer_test(true); + else + report_skip("timer irq enable bit is not writable, skipping mask irq test"); + + local_irq_disable(); + install_irq_handler(IRQ_S_TIMER, NULL); + + report_prefix_pop(); + report_prefix_pop(); +} + int main(int argc, char **argv) { @@ -122,6 +248,7 @@ int main(int argc, char **argv) report_prefix_push("sbi"); check_base(); + check_time(); return report_summary(); }