From nobody Tue Dec 24 13:25:55 2024 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=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1734660120; cv=none; d=zohomail.com; s=zohoarc; b=k8LuNU3sywK53YziBhvhJj8iQIc0gqCSV9V2hWJ3PlrrYz26ts20bdhagNCY9/rkK8T5fn/QFtmKIq1kqG/AwnCXIwA+lOsmdLvKuL2AYrH2gKVvLBxiHRwUjV3BiMyKQj6qJohhrGehBHO1Vzbc2Mlxd3sprlhA+6lGHAjBick= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1734660120; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=PXDNoX4qOLwESPjPkWgs/x/mjCxJy7bzXdJnmiQehW0=; b=hxspxf33JoeccREJ5ehPN/9CT8K9BUrnSdKMEEX4lJ6jxgT9We3d7Wz3cMzMO7PB3l+Ej+ciuMjgLkeivORKKcKguocC/AmMRjQfLEDUsPPAa7fao8LHfZNuQgXC6+58oS1dvc/oAv6CZAKjQnp7J16bV1xSY/JMmLZVwKhfHA8= 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=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1734660119981479.56513139700235; Thu, 19 Dec 2024 18:01:59 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tOSF3-0006TO-1V; Thu, 19 Dec 2024 20:55:49 -0500 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 1tOSEv-0006FM-BX for qemu-devel@nongnu.org; Thu, 19 Dec 2024 20:55:42 -0500 Received: from mail-pf1-x42e.google.com ([2607:f8b0:4864:20::42e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tOSEt-0004UX-Np for qemu-devel@nongnu.org; Thu, 19 Dec 2024 20:55:41 -0500 Received: by mail-pf1-x42e.google.com with SMTP id d2e1a72fcca58-728eedfca37so1546886b3a.2 for ; Thu, 19 Dec 2024 17:55:39 -0800 (PST) Received: from toolbox.alistair23.me (2403-580b-97e8-0-82ce-f179-8a79-69f4.ip6.aussiebb.net. [2403:580b:97e8:0:82ce:f179:8a79:69f4]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-72aad8164d3sm2002539b3a.15.2024.12.19.17.55.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Dec 2024 17:55:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1734659738; x=1735264538; darn=nongnu.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=PXDNoX4qOLwESPjPkWgs/x/mjCxJy7bzXdJnmiQehW0=; b=HURvmOUH5VdK6S22CZTPAhoYwlKy1q2DCO6hOyDJwwvcp0i3khaswWoyKmLSA9exIf 6MVKDmd0xBVUkTrWTPNWIrrCFpVFZas8K31TPFEF5tgOFe8cAtMabYxvRkyLhM4lPm0Y vLTzEwTtdkwYjHX7pUYBAh4y+YPi0raicu9hR9ow5ixdRsqTjkPp0p7gVTRwQBfqozrL LSTnPYM9Y+FsHZpmmefzqn1grvM0em6h7GblZzyb2f9Eom4aJAmmPePNpuUXA460NTFH nSVJx2k/zmM6LXFTDrxJ+JiVlhiD4qTiiQWrgyLrzrivqaginwEfnvI1lu2HMcfzN9ex trsQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734659738; x=1735264538; 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=PXDNoX4qOLwESPjPkWgs/x/mjCxJy7bzXdJnmiQehW0=; b=VFqqiTCh/CYom1AlcLOGs91Yb/UaqACKc+5eLJZjbsJ5Vip2PZchdmIA2h87DDoJh+ qDgHLMEIK//pCd7k/g3SLSKL7ImnFABudt7Ig3NegoskB8GsvNiDbFt5QoYvCk3kWdQe jsKXB2JUme3wojdQ0wpx9+Q1hbQtP8sGinpRgmc2xpLFUmLHCIIHw8hKIlu7eJuikoH9 S6QaXAYoJX2jZHRNEoc8eewQYCaMXnqGm8VxjPvBFUBz0TPlZY9cpFNUdeIOP5y6Qf4k yEv7w+3p1obX/iBDlYyjR0Lu+vjD09GKM9BqCpks0YTuu4tCdNV2Hg6lEJaSvYeQ9ARG 38ow== X-Gm-Message-State: AOJu0Yy1v2MuWFIE1nuVNNHLqRQTipL9P/mJD7sfSAErHWEDpWdIrGZp eW9250KJ9sMvCmFyFLPCvUX6//trstTKJwxmHH6baK7lvbbWHl0hFw6jDt81 X-Gm-Gg: ASbGncuITJppkxAMOT7LqNnomoMpfFu/jKhStVG4/CXS5lWfvvCLHRxKbDfmMQH9mug MTd31BJr9XWT90QVWcVY1aC3iAnwrun/4jSH52pzuKR04ed3I0IHgbFaqhb4sQzY5lgJkDZPyL3 wa6PNQvu8jjTr2NS5+b7AZch98aGetuqLoMwbK7yldS8jj20ZDg9tp3skabkeEpuZV6ls/T30B1 4FlH5tSPdIwQKDRbVLqGApo+45hKt/tem1p3MPK8oyDOuQuW9SCmhdNmEksaJkR15rPsSARbhES bAfeewqTiF9NJRsyE5/xOddR/WdFQ0Y+oCv4lYXn4cgOiF6sX/yNI9Dw86pLRFk= X-Google-Smtp-Source: AGHT+IFxxDBYobqliCl9DXvxZVwyvpmVyk5hNENodJ/q+pukVGzikfu7vUmWkkG1eJM2FAUjea5OoA== X-Received: by 2002:a05:6a21:998b:b0:1e0:b5ae:8fc1 with SMTP id adf61e73a8af0-1e5e0484570mr1999345637.13.1734659738269; Thu, 19 Dec 2024 17:55:38 -0800 (PST) From: Alistair Francis X-Google-Original-From: Alistair Francis To: qemu-devel@nongnu.org Cc: alistair23@gmail.com, Daniel Henrique Barboza , Alistair Francis Subject: [PULL v2 15/39] hw/riscv/virt.c, riscv_aplic.c: add 'emulated_aplic' helpers Date: Fri, 20 Dec 2024 11:54:15 +1000 Message-ID: <20241220015441.317236-16-alistair.francis@wdc.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241220015441.317236-1-alistair.francis@wdc.com> References: <20241220015441.317236-1-alistair.francis@wdc.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=2607:f8b0:4864:20::42e; envelope-from=alistair23@gmail.com; helo=mail-pf1-x42e.google.com X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 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, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham 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 @gmail.com) X-ZM-MESSAGEID: 1734660121718116600 Content-Type: text/plain; charset="utf-8" From: Daniel Henrique Barboza The current logic to determine if we don't need an emulated APLIC controller, i.e. KVM will provide for us, is to determine if we're running KVM, with in-kernel irqchip support, and running aia=3Daplic-imsic. This is modelled by riscv_is_kvm_aia_aplic_imsic() and virt_use_kvm_aia_aplic_imsic(). This won't suffice to support irqchip_split() mode: it will match exactly the same conditions as the one above, but setting the irqchip to 'split' mode will now require us to emulate an APLIC s-mode controller, like we're doing with 'aia=3Daplic'. Create a new riscv_use_emulated_aplic() helper that will encapsulate this logic. Replace the uses of "riscv_is_kvm_aia_aplic_imsic()" with this helper every time we're taking a decision on emulate an APLIC controller or not. Do the same in virt.c with virt_use_emulated_aplic(). Signed-off-by: Daniel Henrique Barboza Reviewed-by: Alistair Francis Message-ID: <20241119191706.718860-6-dbarboza@ventanamicro.com> Signed-off-by: Alistair Francis --- include/hw/intc/riscv_aplic.h | 1 + hw/intc/riscv_aplic.c | 24 +++++++++++++++++++++--- hw/riscv/virt.c | 14 ++++++++++++-- 3 files changed, 34 insertions(+), 5 deletions(-) diff --git a/include/hw/intc/riscv_aplic.h b/include/hw/intc/riscv_aplic.h index fd0e6427d9..74ae5d87b5 100644 --- a/include/hw/intc/riscv_aplic.h +++ b/include/hw/intc/riscv_aplic.h @@ -72,6 +72,7 @@ struct RISCVAPLICState { =20 void riscv_aplic_add_child(DeviceState *parent, DeviceState *child); bool riscv_is_kvm_aia_aplic_imsic(bool msimode); +bool riscv_use_emulated_aplic(bool msimode); =20 DeviceState *riscv_aplic_create(hwaddr addr, hwaddr size, uint32_t hartid_base, uint32_t num_harts, uint32_t num_sources, diff --git a/hw/intc/riscv_aplic.c b/hw/intc/riscv_aplic.c index 9f9814a40b..ba4e802888 100644 --- a/hw/intc/riscv_aplic.c +++ b/hw/intc/riscv_aplic.c @@ -32,6 +32,7 @@ #include "target/riscv/cpu.h" #include "sysemu/sysemu.h" #include "sysemu/kvm.h" +#include "sysemu/tcg.h" #include "kvm/kvm_riscv.h" #include "migration/vmstate.h" =20 @@ -159,6 +160,23 @@ bool riscv_is_kvm_aia_aplic_imsic(bool msimode) return kvm_irqchip_in_kernel() && msimode; } =20 +bool riscv_use_emulated_aplic(bool msimode) +{ +#ifdef CONFIG_KVM + if (tcg_enabled()) { + return true; + } + + if (!riscv_is_kvm_aia_aplic_imsic(msimode)) { + return true; + } + + return kvm_kernel_irqchip_split(); +#else + return true; +#endif +} + static bool riscv_aplic_irq_rectified_val(RISCVAPLICState *aplic, uint32_t irq) { @@ -857,7 +875,7 @@ static void riscv_aplic_realize(DeviceState *dev, Error= **errp) uint32_t i; RISCVAPLICState *aplic =3D RISCV_APLIC(dev); =20 - if (!riscv_is_kvm_aia_aplic_imsic(aplic->msimode)) { + if (riscv_use_emulated_aplic(aplic->msimode)) { aplic->bitfield_words =3D (aplic->num_irqs + 31) >> 5; aplic->sourcecfg =3D g_new0(uint32_t, aplic->num_irqs); aplic->state =3D g_new0(uint32_t, aplic->num_irqs); @@ -881,7 +899,7 @@ static void riscv_aplic_realize(DeviceState *dev, Error= **errp) * have IRQ lines delegated by their parent APLIC. */ if (!aplic->parent) { - if (kvm_enabled() && riscv_is_kvm_aia_aplic_imsic(aplic->msimode))= { + if (kvm_enabled() && !riscv_use_emulated_aplic(aplic->msimode)) { qdev_init_gpio_in(dev, riscv_kvm_aplic_request, aplic->num_irq= s); } else { qdev_init_gpio_in(dev, riscv_aplic_request, aplic->num_irqs); @@ -1025,7 +1043,7 @@ DeviceState *riscv_aplic_create(hwaddr addr, hwaddr s= ize, =20 sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal); =20 - if (!riscv_is_kvm_aia_aplic_imsic(msimode)) { + if (riscv_use_emulated_aplic(msimode)) { sysbus_mmio_map(SYS_BUS_DEVICE(dev), 0, addr); } =20 diff --git a/hw/riscv/virt.c b/hw/riscv/virt.c index a67ab80b16..937dfd1ef2 100644 --- a/hw/riscv/virt.c +++ b/hw/riscv/virt.c @@ -66,6 +66,13 @@ static bool virt_use_kvm_aia_aplic_imsic(RISCVVirtAIATyp= e aia_type) return riscv_is_kvm_aia_aplic_imsic(msimode); } =20 +static bool virt_use_emulated_aplic(RISCVVirtAIAType aia_type) +{ + bool msimode =3D aia_type =3D=3D VIRT_AIA_TYPE_APLIC_IMSIC; + + return riscv_use_emulated_aplic(msimode); +} + static bool virt_aclint_allowed(void) { return tcg_enabled() || qtest_enabled(); @@ -779,8 +786,11 @@ static void create_fdt_sockets(RISCVVirtState *s, cons= t MemMapEntry *memmap, *msi_pcie_phandle =3D msi_s_phandle; } =20 - /* KVM AIA aplic-imsic only has one APLIC instance */ - if (kvm_enabled() && virt_use_kvm_aia_aplic_imsic(s->aia_type)) { + /* + * With KVM AIA aplic-imsic, using an irqchip without split + * mode, we'll use only one APLIC instance. + */ + if (!virt_use_emulated_aplic(s->aia_type)) { create_fdt_socket_aplic(s, memmap, 0, msi_m_phandle, msi_s_phandle, phandle, &intc_phandles[0], xplic_phandles, --=20 2.47.1