From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 36C09288C02 for ; Tue, 29 Jul 2025 09:58:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753783082; cv=none; b=u4JjMjJq3fxmTovRdHyeYCZF3m2LaK97TTn0BMKWDY4wffJ8pmqjDCqwJdER7EYUjT1V3bjkq+eugZxZZgp1tvSaeO7qRHRPIMAbnmBQ/hb8lrNhSZhV6uC/TWu+RI85Bt3YtsYZfFNjf69W3iFf8j+XV/2gSQlsIBDhcFa68Ds= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753783082; c=relaxed/simple; bh=qO7Oxu4MghnFe89SQZSfyy3L7Fji0ufbNWOYNTXTM5c=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Mt7bWdLjOmxiA+VEek8cL0NCCkFGbij95aPs2mylWwZJmuPC/aTHBrP0ocae4K0uegiTYrqhDVdHuZSLCbLsTUDJQUEXzGvru27vIQnLbPVuLaB8BSFce04m150VMi9hKfs6vzo7l3tYKrpOyu7zDJTOECOLtI1acqwT501R1sw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id D6B011516; Tue, 29 Jul 2025 02:57:52 -0700 (PDT) Received: from donnerap.arm.com (donnerap.manchester.arm.com [10.32.101.27]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 9D85C3F673; Tue, 29 Jul 2025 02:57:59 -0700 (PDT) From: Andre Przywara To: Will Deacon , Julien Thierry , Marc Zyngier Cc: kvm@vger.kernel.org, kvmarm@lists.linux.dev, Alexandru Elisei Subject: [PATCH kvmtool v3 6/6] arm64: Generate HYP timer interrupt specifiers Date: Tue, 29 Jul 2025 10:57:45 +0100 Message-Id: <20250729095745.3148294-7-andre.przywara@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20250729095745.3148294-1-andre.przywara@arm.com> References: <20250729095745.3148294-1-andre.przywara@arm.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Marc Zyngier FEAT_VHE introduced a non-secure EL2 virtual timer, along with its interrupt line. Consequently the arch timer DT binding introduced a fifth interrupt to communicate this interrupt number. Refactor the interrupts property generation code to deal with a variable number of interrupts, and forward five interrupts instead of four in case nested virt is enabled. Signed-off-by: Marc Zyngier Signed-off-by: Andre Przywara --- arm64/arm-cpu.c | 4 +--- arm64/include/kvm/timer.h | 2 +- arm64/timer.c | 29 ++++++++++++----------------- 3 files changed, 14 insertions(+), 21 deletions(-) diff --git a/arm64/arm-cpu.c b/arm64/arm-cpu.c index 1e456f2c6..abdd6324f 100644 --- a/arm64/arm-cpu.c +++ b/arm64/arm-cpu.c @@ -12,11 +12,9 @@ static void generate_fdt_nodes(void *fdt, struct kvm *kvm) { - int timer_interrupts[4] = {13, 14, 11, 10}; - gic__generate_fdt_nodes(fdt, kvm->cfg.arch.irqchip, kvm->cfg.arch.nested_virt); - timer__generate_fdt_nodes(fdt, kvm, timer_interrupts); + timer__generate_fdt_nodes(fdt, kvm); pmu__generate_fdt_nodes(fdt, kvm); } diff --git a/arm64/include/kvm/timer.h b/arm64/include/kvm/timer.h index 928e9ea7a..81e093e46 100644 --- a/arm64/include/kvm/timer.h +++ b/arm64/include/kvm/timer.h @@ -1,6 +1,6 @@ #ifndef ARM_COMMON__TIMER_H #define ARM_COMMON__TIMER_H -void timer__generate_fdt_nodes(void *fdt, struct kvm *kvm, int *irqs); +void timer__generate_fdt_nodes(void *fdt, struct kvm *kvm); #endif /* ARM_COMMON__TIMER_H */ diff --git a/arm64/timer.c b/arm64/timer.c index 861f2d994..2ac6144f9 100644 --- a/arm64/timer.c +++ b/arm64/timer.c @@ -5,31 +5,26 @@ #include "kvm/timer.h" #include "kvm/util.h" -void timer__generate_fdt_nodes(void *fdt, struct kvm *kvm, int *irqs) +void timer__generate_fdt_nodes(void *fdt, struct kvm *kvm) { const char compatible[] = "arm,armv8-timer\0arm,armv7-timer"; u32 cpu_mask = gic__get_fdt_irq_cpumask(kvm); - u32 irq_prop[] = { - cpu_to_fdt32(GIC_FDT_IRQ_TYPE_PPI), - cpu_to_fdt32(irqs[0]), - cpu_to_fdt32(cpu_mask | IRQ_TYPE_LEVEL_LOW), + int irqs[5] = {13, 14, 11, 10, 12}; + int nr = ARRAY_SIZE(irqs); + u32 irq_prop[nr * 3]; - cpu_to_fdt32(GIC_FDT_IRQ_TYPE_PPI), - cpu_to_fdt32(irqs[1]), - cpu_to_fdt32(cpu_mask | IRQ_TYPE_LEVEL_LOW), + if (!kvm->cfg.arch.nested_virt) + nr--; - cpu_to_fdt32(GIC_FDT_IRQ_TYPE_PPI), - cpu_to_fdt32(irqs[2]), - cpu_to_fdt32(cpu_mask | IRQ_TYPE_LEVEL_LOW), - - cpu_to_fdt32(GIC_FDT_IRQ_TYPE_PPI), - cpu_to_fdt32(irqs[3]), - cpu_to_fdt32(cpu_mask | IRQ_TYPE_LEVEL_LOW), - }; + for (int i = 0; i < nr; i++) { + irq_prop[i * 3 + 0] = cpu_to_fdt32(GIC_FDT_IRQ_TYPE_PPI); + irq_prop[i * 3 + 1] = cpu_to_fdt32(irqs[i]); + irq_prop[i * 3 + 2] = cpu_to_fdt32(cpu_mask | IRQ_TYPE_LEVEL_LOW); + } _FDT(fdt_begin_node(fdt, "timer")); _FDT(fdt_property(fdt, "compatible", compatible, sizeof(compatible))); - _FDT(fdt_property(fdt, "interrupts", irq_prop, sizeof(irq_prop))); + _FDT(fdt_property(fdt, "interrupts", irq_prop, nr * 3 * sizeof(irq_prop[0]))); _FDT(fdt_property(fdt, "always-on", NULL, 0)); if (kvm->cfg.arch.force_cntfrq > 0) _FDT(fdt_property_cell(fdt, "clock-frequency", kvm->cfg.arch.force_cntfrq)); -- 2.25.1