From nobody Sat Apr 11 19:54:30 2026 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=1775167077; cv=none; d=zohomail.com; s=zohoarc; b=bekYDbISXTXdKPYlQ4dECkyRG0T1w2lHQs7oUMNKSxRteNY4kcJel08ja+0dPaa0VibMxp9Sb3PYo/RCcA+F532h21IMIlnvJMok+R9stBUnSxNAkKoa0XiQjzMaDFj7UEBMz5YBjssAuydvLlMKeL/WBJMpcfli0OjhDgoBUxo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1775167077; 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=SZPYiFfpkqs7OEfAorj2jjdtW/THFK7eOizNd6vUIEE=; b=nxlZgjdOqJWbSCA9np9sO90CBOCHH2Cg5CrFNx7GkxnVO6GLUu2uJEuundALWGBj5P5eEbEmc+6O8QiSAUZU3MX+PVivr+gGUqbRSnv4Ixtp9PlEOcSvzyDCZQbS6u8z4rHTT/nQoVRvK+GmA+EHaP7crgPlQshGzxqwqSHadX4= 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 1775167077124994.8729267245374; Thu, 2 Apr 2026 14:57:57 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1w8Q2p-0000Lo-6x; Thu, 02 Apr 2026 17:57:43 -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 1w8Q2b-00009i-N3 for qemu-devel@nongnu.org; Thu, 02 Apr 2026 17:57:29 -0400 Received: from mail-ej1-x630.google.com ([2a00:1450:4864:20::630]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1w8Q2Y-0007E6-BN for qemu-devel@nongnu.org; Thu, 02 Apr 2026 17:57:28 -0400 Received: by mail-ej1-x630.google.com with SMTP id a640c23a62f3a-b982518b73fso207753066b.1 for ; Thu, 02 Apr 2026 14:57:25 -0700 (PDT) Received: from thinkpad-t470s.. (93-143-182-244.adsl.net.t-com.hr. [93.143.182.244]) by smtp.googlemail.com with ESMTPSA id a640c23a62f3a-b9c3cac0e1asm134009166b.27.2026.04.02.14.57.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Apr 2026 14:57:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1775167044; x=1775771844; 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=SZPYiFfpkqs7OEfAorj2jjdtW/THFK7eOizNd6vUIEE=; b=eAXaA+y1x1p4cfrxlmaz6i95e6k3MJo048D5jJ+roayy68J/NXH7PA2CDk+L8OoGR/ olcgeDL9uGlP+rkRaj5DTQOmWuZPZ1QF++Qr+TSg0sy8pMkJgj8mpi/2Gq/6GAYvFGJL Dqe4lhXuaWGHpfWyQYW6GN7dmk2qKY0Wh+iHA/0Ac1EVP8UQ8TSadoiyhulzVRY/jNf8 gXtLUBHLjPo0EGLW7l8KLle6umH6BQCnPR82ve6ApanGH6NqndKIzLSZpjuSxgmXrp5T BtoEUw093wmarlc4mVdPcuIepcWGnJH6WK0MscxFANnJ25LljoqWQEtvLDGOhn5a8ul5 Si0g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1775167044; x=1775771844; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=SZPYiFfpkqs7OEfAorj2jjdtW/THFK7eOizNd6vUIEE=; b=so+x3v6rlSpW22rzQt+cNUm6fZRWGMdwjOVeiYVSycJ232qSoC/y/QnPdpx20bQDE5 nku1Yo/zTMLGDsUA9Q41iyAKkrYAyfHiIF0+5fohsJt2H1a6AGICYold+btU11Y2S7lW U3ZMSIy0W+NLYbkTFhJR+5czY/wFuwbpoXfh27ePHIBr3W0G4sZzf+4MYiZFgnFgTAYa UEYhB+M8irPAXex+Kuzni8Y/9DsV+Gy+44CFHLJSVJa1sb0RVyU2H1lmEaWgKR1kGuuM +/pvNJq7Kt09KsZhvX011t/Ty2DmrFPyJLbVAFj5K6q8RfnRqBfopqagGkYoBWRoCWvt Fx/Q== X-Gm-Message-State: AOJu0YxTOpdmAZ+YziDThmUZiw0NdOuJK9hu1RXjKQe36i/6xDs8U4KX QOOi+XR968WcVzJmUGUV0JggyhU8CyihvbR62aBBStNr1aFLwzdofwE7gVsa1r9b X-Gm-Gg: ATEYQzx1ipQZURQwn5FyqKJWvJwj2eLGsZ9NoTnHYgVIKq2XkuW+C/myynhpI4ndQNF 5/YWr0AM1jpat/Eb1lfyCEzYXGFlMW0yRYUYyD6Lz8yMcTEVHARrSEPEx5L3TyaZbvYKLfXuNSW gKkLXNt8TuREPvux4KB2AWd3P14vHxDI+600pkq+TbtrnEbT8W6NDnrc+IoQ4ZcCrE5+K9yLmpf 69X+kN/Ps63QtVI1dUeKPmzi97HwB9UjJ4i2MNMmKzdktFaPg7P6alK7cEMvtt3HmQ91BBkwYmQ LGUy4OKnHsh8rLbJoy5NcJHFUxhVXNcb5pUQYAY5iBTp12ZpdO/xmhxpONura2T9yBwhBsPB2hA aee5/dh+rwDUjHK9H5dlQxo5q8ANozUtPnuveOHu9YTxnybXsPtIHJ4W+HwAI/CB5apUEnvUmCi W56GQPNjviWofkXjRVxiqWxn0ISJqvWGdfWpXvFC97M5VFTAbjXg0b3Gwgngj9fisHjkQB8Q== X-Received: by 2002:a17:907:5c9:b0:b98:3bb8:c10f with SMTP id a640c23a62f3a-b9c67423283mr24107866b.5.1775167044460; Thu, 02 Apr 2026 14:57:24 -0700 (PDT) From: Ruslan Ruslichenko To: qemu-devel@nongnu.org Cc: qemu-arm@nongnu.org, alex.bennee@linaro.org, peter.maydell@linaro.org, artem_mygaiev@epam.com, volodymyr_babchuk@epam.com, takahiro.nakata.wr@renesas.com, "Edgar E . Iglesias" , Ruslan_Ruslichenko@epam.com, balaton@eik.bme.hu Subject: [PATCH v3 24/33] target/arm/cpu: add fdt support for armv8-timer Date: Thu, 2 Apr 2026 23:56:09 +0200 Message-ID: <20260402215629.745866-25-ruslichenko.r@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260402215629.745866-1-ruslichenko.r@gmail.com> References: <20260402215629.745866-1-ruslichenko.r@gmail.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::630; envelope-from=ruslichenko.r@gmail.com; helo=mail-ej1-x630.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, 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: qemu development 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: 1775167079099158500 Content-Type: text/plain; charset="utf-8" From: Ruslan Ruslichenko Implement FDT compatibility, so that timer can initilize and wire irqs based on device tree information. Signed-off-by: Ruslan Ruslichenko --- target/arm/cpu.c | 112 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 112 insertions(+) diff --git a/target/arm/cpu.c b/target/arm/cpu.c index ccc47c8a9a..35e38f9970 100644 --- a/target/arm/cpu.c +++ b/target/arm/cpu.c @@ -54,6 +54,8 @@ #include "target/arm/gtimer.h" =20 #include "trace.h" +#include "hw/core/fdt_generic_util.h" + =20 static void arm_cpu_set_pc(CPUState *cs, vaddr value) { @@ -2447,3 +2449,113 @@ static void arm_cpu_register_types(void) } =20 type_init(arm_cpu_register_types) + +#ifndef CONFIG_USER_ONLY + +static Object *fdt_armv8_timer_get_intc(FDTMachineInfo *fdti, char *node_p= ath) +{ + char intc_node_path[DT_PATH_LENGTH]; + uint32_t intc_phandle; + Error *errp =3D NULL; + DeviceState *intc; + + intc_phandle =3D qemu_fdt_getprop_cell_inherited(fdti->fdt, node_path, + "interrupt-parent", + 0, &errp); + + /* There must be an interrupt-parent */ + if (errp || + qemu_devtree_get_node_by_phandle(fdti->fdt, + intc_node_path, intc_phandle)) { + g_assert_not_reached(); + } + + while (!fdt_init_has_opaque(fdti, intc_node_path)) { + fdt_init_yield(fdti); + } + + intc =3D DEVICE(fdt_init_get_opaque(fdti, intc_node_path)); + + while (!intc->realized) { + fdt_init_yield(fdti); + } + + return OBJECT(intc); +} + +static int armv8_timer_fdt_init(char *node_path, FDTMachineInfo *fdti, + void *priv) +{ + Object *intc =3D fdt_armv8_timer_get_intc(fdti, node_path); + CPUState *cpu; + qemu_irq *sec_irqs =3D NULL; + qemu_irq *ns_irqs; + qemu_irq *v_irqs; + qemu_irq *h_irqs; + uint32_t first_cpu_idx; + uint32_t num_cpu; + bool has_sec_ext; + Error *err =3D NULL; + + first_cpu_idx =3D object_property_get_uint(intc, "first-cpu-idx", &err= ); + if (!err) { + num_cpu =3D object_property_get_uint(intc, "num-cpu", &err); + assert(!err); + has_sec_ext =3D object_property_get_bool(intc, "has-security-exten= sions", + &err); + assert(!err); + } else { + /* + * Connect all CPUs with the ARM_FEATURE_GENERIC_TIMER set for + * backwards compatibility when the 'first-cpu-idx' property does = not + * exist. + */ + num_cpu =3D 0; + has_sec_ext =3D true; + } + + if (has_sec_ext) { + sec_irqs =3D fdt_get_irq(fdti, node_path, 0); + ns_irqs =3D fdt_get_irq(fdti, node_path, 1); + v_irqs =3D fdt_get_irq(fdti, node_path, 2); + h_irqs =3D fdt_get_irq(fdti, node_path, 3); + } else { + ns_irqs =3D fdt_get_irq(fdti, node_path, 0); + v_irqs =3D fdt_get_irq(fdti, node_path, 1); + h_irqs =3D fdt_get_irq(fdti, node_path, 2); + } + + for (cpu =3D first_cpu; cpu; cpu =3D CPU_NEXT(cpu)) { + ARMCPU *acpu =3D ARM_CPU(cpu); + bool is_gic_cpu; + + if (!arm_feature(&acpu->env, ARM_FEATURE_GENERIC_TIMER)) { + continue; + } + + is_gic_cpu =3D cpu->cpu_index >=3D first_cpu_idx && + cpu->cpu_index < (first_cpu_idx + num_cpu); + + if (!num_cpu || is_gic_cpu) { + + assert(*ns_irqs); + assert(*v_irqs); + assert(*h_irqs); + qdev_connect_gpio_out(DEVICE(acpu), 0, *ns_irqs++); + qdev_connect_gpio_out(DEVICE(acpu), 1, *v_irqs++); + qdev_connect_gpio_out(DEVICE(acpu), 2, *h_irqs++); + + if (has_sec_ext) { + assert(*sec_irqs); + qdev_connect_gpio_out(DEVICE(acpu), 3, *sec_irqs++); + } + } + } + + return 0; +} + +fdt_register_compatibility(armv8_timer_fdt_init, + "compatible:arm,armv8-timer"); + +#endif --=20 2.43.0