From nobody Sun Nov 16 02:26:31 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=reject dis=none) header.from=sifive.com ARC-Seal: i=1; a=rsa-sha256; t=1744167186; cv=none; d=zohomail.com; s=zohoarc; b=Mx9qHWPRzuZPS7rizplNA2ww+60UcNIzynozHKPl7tmnhdhHPgEZxd/OYdJtTcU62AuEvZbfbYREXNxfut6GUr1p7mcdtIJKY/sZGybSrTBytjgd4w1+wF1PNYPeN3n7fFG8fmYMXIZQA5qHa94LN/HcmoAtYiTJskc6c3NTXVw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1744167186; h=Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=34lLEwB0Gg3cwH10oPYf9tvhYdTQGgJnGI9qEibZYP8=; b=TpRLa77s9LSQ6Kb6Icaw46v3eA0471IrCslK7DEuHgFGZ9YZUoyIadJbjTHt5aBa/PQBUwhd0QJ0YPJWyb98IbwZTBRi8kBDMX8Yx+2Nnp1n6IbLjnOTvfrapfTHmbvfMxJjmheEA06AEICYpFKFzX8jlVwmE/bDVdyKaGy1d5c= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1744167186670447.4720642943971; Tue, 8 Apr 2025 19:53:06 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1u2LXi-0000tO-Fj; Tue, 08 Apr 2025 22:51:58 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1u2LXg-0000sD-P1 for qemu-devel@nongnu.org; Tue, 08 Apr 2025 22:51:56 -0400 Received: from mail-pl1-x632.google.com ([2607:f8b0:4864:20::632]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1u2LXf-00019a-1F for qemu-devel@nongnu.org; Tue, 08 Apr 2025 22:51:56 -0400 Received: by mail-pl1-x632.google.com with SMTP id d9443c01a7336-22401f4d35aso71642155ad.2 for ; Tue, 08 Apr 2025 19:51:54 -0700 (PDT) Received: from hsinchu26.internal.sifive.com ([210.176.154.34]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-22ac7cb5463sm665725ad.195.2025.04.08.19.51.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Apr 2025 19:51:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1744167113; x=1744771913; darn=nongnu.org; h=references:in-reply-to:message-id:date:subject:cc:to:from:from:to :cc:subject:date:message-id:reply-to; bh=34lLEwB0Gg3cwH10oPYf9tvhYdTQGgJnGI9qEibZYP8=; b=h5dXJeE8JN+k1C4AU4i2Wc9u+Ke2t5BWUKvsXgXXCSIfhjvpKnihS7sZx6F2YzFQcy KwM9Nd/I/RUwSTFSElU9lYeI4bm82yPkLX9vqmFdmWHcCN/jMVS/K0pO403/c4wC1ZaH FWZFpLVNLlDGFgGe2vQCrWwD6J16GbmUaUK39si3uADdtRVJgOBTR+6QNvPieYJbeeFh L/NvA9gLQ1jBW1IsxhhWEys8hNOyyMrVnENZk8UEGUk3y7es5ha1V0bXOhBJG/Ze5iQN De67tfcMocv3mFz389sh/zbMV2KV3eTnJCKFCg9jOxritceqlRMo0aBUARKeE01+GlWU 0yOg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1744167113; x=1744771913; h=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=34lLEwB0Gg3cwH10oPYf9tvhYdTQGgJnGI9qEibZYP8=; b=EimITTMvW0we+Q9Zf9UkmWaX2QAFf3AhQ2I+Ufo5skQgHY0LZEa9bZ/suvS6HfjfCi 50uygJUQqim+jd0QKoHybam5CJNOf6un9oT0iMZs91a1ajNOOYkA2jWbYA8ssEoOj3Ng P8HN5F71Lse4It9ZtIXYvBpZbqzqgkB6LakFZ2UBeKjXh8o3ijpQ9OG3QFHYWcnMgmu+ 3yIfolro7kupgJqNC8dVgGQM54mOBrnLMWV+TCM90Olaoa18yCYuHvJMqd6uw7sJ/SYq B53MX2K8yxPwG1rX5LvXQFbyoBuNA91TSvCz7ySj1u3J7GW9EF8eu5WQUf/7u6c7N4Hb nB7A== X-Gm-Message-State: AOJu0YxtP7DA9l/4XHQTKGOJDa5Y3QTb4GRNuOhbJLVRH0HabPwZzslH rX57ydg3PY9AOQxXEocb3RQdi4v8F1/vGEC/f6bU3YqBHsgYbZ58kq2n5G6vVrCNPiPgyt06tZg WR8ddYUcsfryG4A248GsOsNqhYRXXM4vMqNN+3C6li2zn6BD5VThJQWW79fOqP3fFZq7kgCr/Cl ktnSKlIU34a1uPr5+KP008Kf7jTmtXiG9p/g== X-Gm-Gg: ASbGncu45G6If3HMYzemqoFpQrjLz0ziAUy1lY50t4M6fG14/3AupaAOXiTC/fwFUjA sdxZGynPuwfOxvzvpVSDr2WvAL8fdG56Rsu86IN3bQNwFSkEqRFS6w77VWPDUMrfwRvVRyPqJtO e/fQJllmjCXjXUHCyqBRqbhLSy99sdcC01vbo4+dyA+MiUG4m7UQalHuYmyrDpXMNiuq4gBKPH7 vST17WQwQ2CBpfxL9NEGSuvJeNypqhLJecY8sMfGsYqVIO8sLKcjAO85/KSfH6oKMxE6Wyhyeje hhXszNGILVEjB4U4NyqiT4zxCu2iMOMxkFuCO3Ssd0WZpxkfB04VkltmIL7XwWMgDsXRZw+mSxH ppA== X-Google-Smtp-Source: AGHT+IHuZxg1XkNr9HdgCzep2yi5FoOs4gQYQjdn86csPg0WTyyAoPp3Pa3tlKPVjO2/r354THkDLQ== X-Received: by 2002:a17:902:f9c3:b0:224:78e:4ebe with SMTP id d9443c01a7336-22ac2a1df74mr12899575ad.33.1744167113040; Tue, 08 Apr 2025 19:51:53 -0700 (PDT) From: Jim Shu To: qemu-devel@nongnu.org, qemu-riscv@nongnu.org Cc: Palmer Dabbelt , Alistair Francis , Weiwei Li , Daniel Henrique Barboza , Liu Zhiwei , Jim Shu Subject: [PATCH v2 2/4] hw/intc: riscv_aclint: Fix mtime write for sstc extension Date: Wed, 9 Apr 2025 10:51:29 +0800 Message-Id: <20250409025131.3670-3-jim.shu@sifive.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20250409025131.3670-1-jim.shu@sifive.com> References: <20250409025131.3670-1-jim.shu@sifive.com> Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::632; envelope-from=jim.shu@sifive.com; helo=mail-pl1-x632.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @sifive.com) X-ZM-MESSAGEID: 1744167189638019100 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" When changing the mtime value, the period of [s|vs]timecmp timers should also be updated, similar to the period of mtimecmp timer. The period of the stimecmp timer is the time until the next S-mode timer IRQ. The value is calculated as "stimecmp - time". [1] It is equal to "stimecmp - mtime" since the time CSR is a read-only shadow of the memory-mapped mtime register. Thus, changing mtime value will update the period of stimecmp timer. Similarly, the period of vstimecmp timer is calculated as "vstimecmp - (mtime + htimedelta)" [2], so changing mtime value will update the period of vstimecmp timer. [1] RISC-V Priv spec ch 9.1.1. Supervisor Timer (stimecmp) Register A supervisor timer interrupt becomes pending, as reflected in the STIP bit in the mip and sip registers whenever time contains a value greater than or equal to stimecmp. [2] RISC-V Priv spec ch19.2.1. Virtual Supervisor Timer (vstimecmp) Register A virtual supervisor timer interrupt becomes pending, as reflected in the VSTIP bit in the hip register, whenever (time + htimedelta), truncated to 64 bits, contains a value greater than or equal to vstimecmp Signed-off-by: Jim Shu Acked-by: Alistair Francis --- hw/intc/riscv_aclint.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/hw/intc/riscv_aclint.c b/hw/intc/riscv_aclint.c index db374a7c2d..5f4a17e177 100644 --- a/hw/intc/riscv_aclint.c +++ b/hw/intc/riscv_aclint.c @@ -28,6 +28,7 @@ #include "qemu/module.h" #include "hw/sysbus.h" #include "target/riscv/cpu.h" +#include "target/riscv/time_helper.h" #include "hw/qdev-properties.h" #include "hw/intc/riscv_aclint.h" #include "qemu/timer.h" @@ -240,6 +241,10 @@ static void riscv_aclint_mtimer_write(void *opaque, hw= addr addr, riscv_aclint_mtimer_write_timecmp(mtimer, RISCV_CPU(cpu), mtimer->hartid_base + i, mtimer->timecmp[i]); + riscv_timer_write_timecmp(env, env->stimer, env->stimecmp, 0, = MIP_STIP); + riscv_timer_write_timecmp(env, env->vstimer, env->vstimecmp, + env->htimedelta, MIP_VSTIP); + } return; } --=20 2.17.1