Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 135C4CD98E6 for ; Fri, 19 Jun 2026 04:52:18 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1waRAa-0008QC-ER; Fri, 19 Jun 2026 00:49:32 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1waRAT-0008NL-Q2 for qemu-riscv@nongnu.org; Fri, 19 Jun 2026 00:49:26 -0400 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 1waRAQ-0005MP-62 for qemu-riscv@nongnu.org; Fri, 19 Jun 2026 00:49:25 -0400 Received: by mail-pf1-x42e.google.com with SMTP id d2e1a72fcca58-8422f395a4aso1146899b3a.0 for ; Thu, 18 Jun 2026 21:49:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1781844561; x=1782449361; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:from:to:cc:subject:date :message-id:reply-to; bh=kqTO7zQpJ1EAJJdfDeD5+U8h9Uv+pcG9eZ/nvTZxrn0=; b=NNlywXvkZepBjDYARCGrBiN+wi+nuaMkTbWQh6Hr7tWFhExouYO/R0tlm5PcqMPvwN TTR5kIwYLoX2plo8FNCeFLLLcrpbTGHmoG8k4PKzozmfyYuZm5nr0aKqKlLF9RME75xx ucud8rLQ3FG8zynGpmU0pTb69zAl017TJsfkdOjgnOuyNdo4alG0h1jqNbxPRZZrb9C6 FuHLiPGRHfLCPlhdPaMbBcA67V4es4zxQG8KEPPHmF2qQnLnOFHtLug3EkYIrdPfB1SE 9m+Zu4m/w0wMP6G8YLhsTy/mHn0fZKxx4/Q/lO/O2xZFwK4Rq+Iqn/GQPWYxei2sCTw1 Uhyg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1781844561; x=1782449361; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=kqTO7zQpJ1EAJJdfDeD5+U8h9Uv+pcG9eZ/nvTZxrn0=; b=FoAxsOCvX729E8OlJnIbKcSLl0AE/q87a5ENv9xtZc9GKTXF40R1NQymqb5k1SLwFX E+7xjw3gXyT0Tndi/9+brpYRTmaOkeh1odjsTOIgxPwoyCocYgcmMvdl8y+iNY1NaWSH c6Q6gCNY3xWFms9ThKS4JIZtcAsVk3zBmK4zgClU/yWYu96RAeK4Z7aHTyNalm8EXEVD ECqtlqhiI+iVu6XMrmgjW+bduOG4Gu2vA+2UKpbJOsQSD/3aZ1GqXwg3FxKwYKj9ncVy P9beZvnABlip8DbGLSC55wYTn81TNFrj21K5xxSRrOgQMrn7eagrM0mIsZnpo8IyKvFW +Utw== X-Forwarded-Encrypted: i=1; AFNElJ/vdnLDQnrtJgMd8Ua+jEO8Wt9lQogsS1y7NprEfsasgesUcjsgNZIr/9xVq0qX3nVrtjZ6Obic63KP@nongnu.org X-Gm-Message-State: AOJu0YwCPvgQ6o4QoQiVFwP6eN56fuoZJ+cBThSFTW847oPVbzBzZQvJ xuFq2Omx8U4TlWc3EKG3l6k9knZkEzyc7LKxmZq3Skj92Z4CpcQDbiiB X-Gm-Gg: AfdE7cm6eX7ajpkg85mtYK7cje9Sl2W9Cjk5X50PSo92qhdrNHGxBJ1AWoQFGAnzcsg 4EjghDmzpL+RgEmaBFDoC0gNfTIvrRqG0UHvg4Lg2okZSB9cVhsX1PQzVtndXcGCtiYTrtYtDAX S+ggj9liGW6OoZl4CH96xoVXE8nFJEUuHQH8C1genLhM1W/Iel5ReFCaJZvrGBL13AdwlaFPu2t 0yxVGLzEjhWXOS6LubWHQTE+c5TO/rd0/tbfXS1L952/YYY93rJVQc7+SIRSCsTAye1TalCT8yL EGUzH+WVzRMzu3VA2u4CLNTm5Bcf+UzhA0dnc51IuhkuBPJJnyIrkRrucd+5yMXxMwCIdzw/0DR wV5IZ3XNJV1E0gTrZluFO6k7dQN5yYWJ5CuHPlnubVkO/sJeDUFL5RTxTa7DtsIejQz/pfP8qTy T6pUfmOTV0XaCFpCkVQfLBV67kZHqcgIZVwz/1mvzOgI2/2Uuli2ujQ652HyGe53/ps7hjTaAaY ef2lfrrpJ8XZQaWJPucJ/SYqUS3ymfDwaCFP0i6bw== X-Received: by 2002:a05:6a00:853:b0:82c:7420:82bf with SMTP id d2e1a72fcca58-845502f140emr2091342b3a.19.1781844560861; Thu, 18 Jun 2026 21:49:20 -0700 (PDT) Received: from donnager-debian.. ([144.6.172.18]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-8455363da44sm870141b3a.8.2026.06.18.21.49.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Jun 2026 21:49:20 -0700 (PDT) From: Joel Stanley To: Alistair Francis , qemu-devel@nongnu.org Cc: Daniel Henrique Barboza , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Chris Rauer , Alano Song , Michael Ellerman , Joel Stanley , Nick Piggin , Anirudh Srinivasan , Portia Stephens , qemu-riscv@nongnu.org, Nutty Liu , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [PATCH v9 04/12] hw/riscv/aia: Provide number of irq sources Date: Fri, 19 Jun 2026 14:18:28 +0930 Message-ID: <20260619044838.1054677-5-joel@jms.id.au> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260619044838.1054677-1-joel@jms.id.au> References: <20260619044838.1054677-1-joel@jms.id.au> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Received-SPF: pass client-ip=2607:f8b0:4864:20::42e; envelope-from=joel.stan@gmail.com; helo=mail-pf1-x42e.google.com X-Spam_score_int: -16 X-Spam_score: -1.7 X-Spam_bar: - X-Spam_report: (-1.7 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.001, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-riscv@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-riscv-bounces+qemu-riscv=archiver.kernel.org@nongnu.org Sender: qemu-riscv-bounces+qemu-riscv=archiver.kernel.org@nongnu.org Instead of hard coding the number of IRQ sources used by the APLIC pass it in as a parameter. This allows other machines to configure this as required. The maximum number of sources is 1023. Reviewed-by: Nutty Liu Reviewed-by: Daniel Henrique Barboza Reviewed-by: Philippe Mathieu-Daudé Reviewed-by: Alistair Francis Signed-off-by: Nicholas Piggin Signed-off-by: Joel Stanley --- hw/riscv/aia.h | 3 +-- include/hw/riscv/virt.h | 1 + hw/riscv/aia.c | 8 ++++++-- hw/riscv/virt-acpi-build.c | 25 ++++++++++++++++--------- hw/riscv/virt.c | 2 ++ 5 files changed, 26 insertions(+), 13 deletions(-) diff --git a/hw/riscv/aia.h b/hw/riscv/aia.h index dbb833340276..5ad0a902be0d 100644 --- a/hw/riscv/aia.h +++ b/hw/riscv/aia.h @@ -11,11 +11,10 @@ #include "exec/hwaddr.h" -#define VIRT_IRQCHIP_NUM_SOURCES 96 - uint32_t imsic_num_bits(uint32_t count); DeviceState *riscv_create_aia(bool msimode, int aia_guests, + uint16_t num_sources, const MemMapEntry *aplic_m, const MemMapEntry *aplic_s, const MemMapEntry *imsic_m, diff --git a/include/hw/riscv/virt.h b/include/hw/riscv/virt.h index ad858deb76ad..36a2def41096 100644 --- a/include/hw/riscv/virt.h +++ b/include/hw/riscv/virt.h @@ -64,6 +64,7 @@ struct RISCVVirtState { struct GPEXHost *gpex_host; OnOffAuto iommu_sys; uint16_t pci_iommu_bdf; + uint16_t num_sources; }; enum { diff --git a/hw/riscv/aia.c b/hw/riscv/aia.c index c724612a50a5..82ea9d48ea75 100644 --- a/hw/riscv/aia.c +++ b/hw/riscv/aia.c @@ -25,6 +25,7 @@ uint32_t imsic_num_bits(uint32_t count) } DeviceState *riscv_create_aia(bool msimode, int aia_guests, + uint16_t num_sources, const MemMapEntry *aplic_m, const MemMapEntry *aplic_s, const MemMapEntry *imsic_m, @@ -38,6 +39,9 @@ DeviceState *riscv_create_aia(bool msimode, int aia_guests, DeviceState *aplic_s_dev = NULL; DeviceState *aplic_m_dev = NULL; + /* The RISC-V Advanced Interrupt Architecture, Chapter 1.2. Limits */ + g_assert(num_sources <= 1023); + if (msimode) { if (!kvm_enabled()) { /* Per-socket M-level IMSICs */ @@ -66,7 +70,7 @@ DeviceState *riscv_create_aia(bool msimode, int aia_guests, aplic_m->size, (msimode) ? 0 : base_hartid, (msimode) ? 0 : hart_count, - VIRT_IRQCHIP_NUM_SOURCES, + num_sources, num_prio_bits, msimode, true, NULL); } @@ -77,7 +81,7 @@ DeviceState *riscv_create_aia(bool msimode, int aia_guests, aplic_s->size, (msimode) ? 0 : base_hartid, (msimode) ? 0 : hart_count, - VIRT_IRQCHIP_NUM_SOURCES, + num_sources, num_prio_bits, msimode, false, aplic_m_dev); diff --git a/hw/riscv/virt-acpi-build.c b/hw/riscv/virt-acpi-build.c index e3da87492408..db3ea4f03ac3 100644 --- a/hw/riscv/virt-acpi-build.c +++ b/hw/riscv/virt-acpi-build.c @@ -146,6 +146,7 @@ static void acpi_dsdt_add_cpus(Aml *scope, RISCVVirtState *s) } static void acpi_dsdt_add_plic_aplic(Aml *scope, uint8_t socket_count, + uint16_t num_sources, uint64_t mmio_base, uint64_t mmio_size, const char *hid) { @@ -153,9 +154,12 @@ static void acpi_dsdt_add_plic_aplic(Aml *scope, uint8_t socket_count, uint32_t gsi_base; uint8_t socket; + /* The RISC-V Advanced Interrupt Architecture, Chapter 1.2. Limits */ + g_assert(num_sources <= 1023); + for (socket = 0; socket < socket_count; socket++) { plic_aplic_addr = mmio_base + mmio_size * socket; - gsi_base = VIRT_IRQCHIP_NUM_SOURCES * socket; + gsi_base = num_sources * socket; Aml *dev = aml_device("IC%.02X", socket); aml_append(dev, aml_name_decl("_HID", aml_string("%s", hid))); aml_append(dev, aml_name_decl("_UID", aml_int(socket))); @@ -474,10 +478,13 @@ static void build_dsdt(GArray *table_data, socket_count = riscv_socket_count(ms); if (s->aia_type == VIRT_AIA_TYPE_NONE) { - acpi_dsdt_add_plic_aplic(scope, socket_count, memmap[VIRT_PLIC].base, - memmap[VIRT_PLIC].size, "RSCV0001"); + acpi_dsdt_add_plic_aplic(scope, socket_count, s->num_sources, + memmap[VIRT_PLIC].base, + memmap[VIRT_PLIC].size, + "RSCV0001"); } else { - acpi_dsdt_add_plic_aplic(scope, socket_count, memmap[VIRT_APLIC_S].base, + acpi_dsdt_add_plic_aplic(scope, socket_count, s->num_sources, + memmap[VIRT_APLIC_S].base, memmap[VIRT_APLIC_S].size, "RSCV0002"); } @@ -494,15 +501,15 @@ static void build_dsdt(GArray *table_data, } else if (socket_count == 2) { virtio_acpi_dsdt_add(scope, memmap[VIRT_VIRTIO].base, memmap[VIRT_VIRTIO].size, - VIRTIO_IRQ + VIRT_IRQCHIP_NUM_SOURCES, 0, + VIRTIO_IRQ + s->num_sources, 0, VIRTIO_COUNT); - acpi_dsdt_add_gpex_host(scope, PCIE_IRQ + VIRT_IRQCHIP_NUM_SOURCES); + acpi_dsdt_add_gpex_host(scope, PCIE_IRQ + s->num_sources); } else { virtio_acpi_dsdt_add(scope, memmap[VIRT_VIRTIO].base, memmap[VIRT_VIRTIO].size, - VIRTIO_IRQ + VIRT_IRQCHIP_NUM_SOURCES, 0, + VIRTIO_IRQ + s->num_sources, 0, VIRTIO_COUNT); - acpi_dsdt_add_gpex_host(scope, PCIE_IRQ + VIRT_IRQCHIP_NUM_SOURCES * 2); + acpi_dsdt_add_gpex_host(scope, PCIE_IRQ + s->num_sources * 2); } aml_append(dsdt, scope); @@ -581,7 +588,7 @@ static void build_madt(GArray *table_data, for (socket = 0; socket < riscv_socket_count(ms); socket++) { aplic_addr = s->memmap[VIRT_APLIC_S].base + s->memmap[VIRT_APLIC_S].size * socket; - gsi_base = VIRT_IRQCHIP_NUM_SOURCES * socket; + gsi_base = s->num_sources * socket; build_append_int_noprefix(table_data, 0x1A, 1); /* Type */ build_append_int_noprefix(table_data, 36, 1); /* Length */ build_append_int_noprefix(table_data, 1, 1); /* Version */ diff --git a/hw/riscv/virt.c b/hw/riscv/virt.c index 84480da2953b..b62864559f57 100644 --- a/hw/riscv/virt.c +++ b/hw/riscv/virt.c @@ -1418,6 +1418,7 @@ static void virt_machine_init(MachineState *machine) } else { s->irqchip[i] = riscv_create_aia(s->aia_type == VIRT_AIA_TYPE_APLIC_IMSIC, s->aia_guests, + s->num_sources, &s->memmap[VIRT_APLIC_M], &s->memmap[VIRT_APLIC_S], &s->memmap[VIRT_IMSIC_M], @@ -1574,6 +1575,7 @@ static void virt_machine_instance_init(Object *obj) s->oem_table_id = g_strndup(ACPI_BUILD_APPNAME8, 8); s->acpi = ON_OFF_AUTO_AUTO; s->iommu_sys = ON_OFF_AUTO_AUTO; + s->num_sources = VIRT_IRQCHIP_NUM_SOURCES; } static char *virt_get_aia_guests(Object *obj, Error **errp) -- 2.47.3