From nobody Sat Oct 11 10:24:55 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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 ARC-Seal: i=1; a=rsa-sha256; t=1592511876; cv=none; d=zohomail.com; s=zohoarc; b=bg5rJ7BHBZoRhyzuQVkbokQ1hgdbRPG0Gbx3otkqiaBMHsIPBVsh2GTrk4VHHvvslpR7a4VFtevHXj2Mduh4iAXYwKI0R5YzyROIi/8/h59ZBUbakPyciBkxAPWqzc+NGjz6znkVJt0E0ScpTpHBWiKIrW+BgvrmE+TPybpYbh4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1592511876; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=JRRajxzTamdBT9+1rzxFUuGVADWvlG2jM5oN0hXK2r4=; b=m1oVvxcmOcLUDLJInSARE84AA0c8DkEtSOLOqLOyRcpKC76SlofHl2aPDXjOQoLW8JOe1tVAALBdNVO7Goi0e2aRpGbnC/tFO6gV1vR7cSiHYQgRK9Z1RRO3hdBxWYDTKsC9JujeZnq+jZOYV/oeBTlesH0ClXA+fw/JZ7y66xA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1592511876072785.3670465577709; Thu, 18 Jun 2020 13:24:36 -0700 (PDT) Received: from localhost ([::1]:45444 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jm15L-0005MF-5G for importer@patchew.org; Thu, 18 Jun 2020 16:24:31 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56336) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jm14i-0004lf-18 for qemu-devel@nongnu.org; Thu, 18 Jun 2020 16:23:52 -0400 Received: from mail-wr1-x443.google.com ([2a00:1450:4864:20::443]:39336) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jm14g-0003X1-E0 for qemu-devel@nongnu.org; Thu, 18 Jun 2020 16:23:51 -0400 Received: by mail-wr1-x443.google.com with SMTP id t18so7465226wru.6 for ; Thu, 18 Jun 2020 13:23:49 -0700 (PDT) Received: from Jessicas-MacBook.local (trinity-students-nat.trin.cam.ac.uk. [131.111.193.104]) by smtp.gmail.com with ESMTPSA id c143sm11065586wmd.1.2020.06.18.13.23.47 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 18 Jun 2020 13:23:47 -0700 (PDT) Received: by Jessicas-MacBook.local (Postfix, from userid 501) id 2AFFA207586B45; Thu, 18 Jun 2020 21:23:47 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=jrtc27.com; s=gmail.jrtc27.user; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=JRRajxzTamdBT9+1rzxFUuGVADWvlG2jM5oN0hXK2r4=; b=EWUzfWfA9ZciY/8Pf4des8G5tzExTyBmRXQtb2F4rOd2LSvHY3VtYk8LKEZe7XQwyo gyKqzsoR6klunD75+5Ud5OgYQl27ysLRn6j8vjedUll6Q+v7Qz1hnZ/60+thv5pqJPx/ jvg7F+vZfZaCsfp3ZFuhwhYve7GGSAjVthCQqzh9Tv2cdFiZ5AHIBoSX5PzQUAAKUPQw ug5cPh277bTifYPmZE3vnuk7ZNDZW38qr4/Jd/PhH+u+KLczPpykywBnlenoW71avT88 R+2DJozDeCMKSEhtt8RdWh8JUiOHgXMjRVVNz6S9R4Bd3bYfLiMCZKDF2/Mw8s8o/PfH 54CQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=JRRajxzTamdBT9+1rzxFUuGVADWvlG2jM5oN0hXK2r4=; b=okvd8KaWE3GAWZDigb9yRnMyNwtHa/Lv1KQQFmM8XJ8TxyYP2+BFuLNEkvgOkvVAx+ RCOroKYsQcIjQho/dkswpOd9Ke9FJgkXQIIZNYXcMwAfaGnW53iJD12MXyRtFnpxhKEG vXatrB2Woxf7wV6Ao6kF/0x3kLPobH6kpsr8i9n6YyeXa3KJSJhXoqDh3DMNQPkdkC6P Uva02aNsJ4rIvr97pCnWXtPLxFoGvqLTRB3TSSiGB7ZDXDNAu2Rn6muwcVG27HfjgyTP fExI9O5g0ld4eJF2inzSBBKV+/qM3LWTiOXm5Zn5E6hNlasYFSztOZ8SpeFKUgX8o039 VH5w== X-Gm-Message-State: AOAM533XdTwAD0av0wEyhnnoyo+vGb8mw14NTH/LIVcu/+RTBY54A5Yc g70VIGNwAU0719fnaCKVlhpb3g== X-Google-Smtp-Source: ABdhPJwgow/wNWpaDS6YrSp2jR6h4Nnw63nZnjeULv79PiQjwaqEKEXBVnlgBVEFCEC6IgcCqYKQcQ== X-Received: by 2002:adf:ec4e:: with SMTP id w14mr269869wrn.280.1592511828637; Thu, 18 Jun 2020 13:23:48 -0700 (PDT) From: Jessica Clarke To: qemu-riscv@nongnu.org Subject: [PATCH v2] riscv: plic: Honour source priorities Date: Thu, 18 Jun 2020 21:23:43 +0100 Message-Id: <20200618202343.20455-1-jrtc27@jrtc27.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200618193556.19459-1-jrtc27@jrtc27.com> References: <20200618193556.19459-1-jrtc27@jrtc27.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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=2a00:1450:4864:20::443; envelope-from=jrtc27@jrtc27.com; helo=mail-wr1-x443.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. 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, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Sagar Karandikar , Bastian Koppelmann , qemu-devel@nongnu.org, Palmer Dabbelt , Alistair Francis , Jessica Clarke Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" The source priorities can be used to order sources with respect to other sources, not just as a way to enable/disable them based off a threshold. We must therefore always claim the highest-priority source, rather than the first source we find. Signed-off-by: Jessica Clarke Reviewed-by: Alistair Francis --- Changes since v1: * Initialise max_prio to plic->target_priority[addrid] rather than 0, allowing the target priority comparison to be dropped and covered by the max_prio comparison. hw/riscv/sifive_plic.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/hw/riscv/sifive_plic.c b/hw/riscv/sifive_plic.c index 4f216c5585..d91e82b8ab 100644 --- a/hw/riscv/sifive_plic.c +++ b/hw/riscv/sifive_plic.c @@ -166,6 +166,9 @@ static void sifive_plic_update(SiFivePLICState *plic) static uint32_t sifive_plic_claim(SiFivePLICState *plic, uint32_t addrid) { int i, j; + uint32_t max_irq =3D 0; + uint32_t max_prio =3D plic->target_priority[addrid]; + for (i =3D 0; i < plic->bitfield_words; i++) { uint32_t pending_enabled_not_claimed =3D (plic->pending[i] & ~plic->claimed[i]) & @@ -177,14 +180,18 @@ static uint32_t sifive_plic_claim(SiFivePLICState *pl= ic, uint32_t addrid) int irq =3D (i << 5) + j; uint32_t prio =3D plic->source_priority[irq]; int enabled =3D pending_enabled_not_claimed & (1 << j); - if (enabled && prio > plic->target_priority[addrid]) { - sifive_plic_set_pending(plic, irq, false); - sifive_plic_set_claimed(plic, irq, true); - return irq; + if (enabled && prio > max_prio) { + max_irq =3D irq; + max_prio =3D prio; } } } - return 0; + + if (max_irq) { + sifive_plic_set_pending(plic, max_irq, false); + sifive_plic_set_claimed(plic, max_irq, true); + } + return max_irq; } static uint64_t sifive_plic_read(void *opaque, hwaddr addr, unsigned size) -- 2.20.1