From nobody Sat Apr 11 19:54:31 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=1775167115; cv=none; d=zohomail.com; s=zohoarc; b=YFPWU9puYm5pPsOvYdwdiPY5lR9LeLyuqNOdSMF7MWfJ4eEoy9nj1kamuOBdhp9odbMKNwAggUBw+AqLJ3DIj7F7lh/VOXF1Ep5EflKzgmrak7a5N851nvd734g6U3tS1ADYyFVE/Nr64TiD3Doukz3Oo2Z1Lq/XxV/vCWYsq+Q= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1775167115; 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=Ti9TrcfoeyeQNd3Zl+7f/uTE9kKOziltFUJwrjRDreg=; b=f9f1UNLjA3y3rCgaaQhuRvVKnzXoHePTlKLU6FWeNLUnfT7kdx+m2C0Kr+rFRnNSliTNnwoKmU2UzNzT8dmwq/9LgwXjjW3op3fDBxo/17kAMDckYmoRiGu94F7TcqEsnrEEWUMB/Mk08ZDh8whucstkJpsdw5jfuAxHW1AMEaE= 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 1775167115088248.40621200743533; Thu, 2 Apr 2026 14:58:35 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1w8Q2W-0008WJ-GO; Thu, 02 Apr 2026 17:57:24 -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 1w8Q2L-0008Lm-UJ for qemu-devel@nongnu.org; Thu, 02 Apr 2026 17:57:14 -0400 Received: from mail-ej1-x632.google.com ([2a00:1450:4864:20::632]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1w8Q2J-00079F-02 for qemu-devel@nongnu.org; Thu, 02 Apr 2026 17:57:13 -0400 Received: by mail-ej1-x632.google.com with SMTP id a640c23a62f3a-b9b1df1a6b3so163801166b.0 for ; Thu, 02 Apr 2026 14:57:10 -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.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Apr 2026 14:57:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1775167029; x=1775771829; 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=Ti9TrcfoeyeQNd3Zl+7f/uTE9kKOziltFUJwrjRDreg=; b=Fr4iMmC7WwQK5xcFXq3KoWVvYw1sLpScUkAyX2dEBxAnaQ/c+DrWt/EvM7iaH95pVE w8eX89SdjLinq2SNiHTXiuEceo0VdjORF52Ozsj182KKD/fHrQrYCzA/2Mcj8b8LNYUF zks7OwlSXhlbGl3YJ9IsAs41xoPRn6lkIHaEr/+4gxWMhSR2AgXODZNABCqBOWQk7EPv nWmMQECFVAzn0DTo9VonLhxoj4BlYTbR40Nucit3sjvCxWET1RY0nXf7X+RvqF0aF7Y8 yLUXYePTAXB8/NxXQYZO9W2HmRtkEb3mPzGSLXTgVmEMp89TOfiNAcZKNgy4VvtUNHGV EaAA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1775167029; x=1775771829; 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=Ti9TrcfoeyeQNd3Zl+7f/uTE9kKOziltFUJwrjRDreg=; b=EASKxNG1Lp3+5S2zgloYtQkqFhBGkR4hcVTsXRCR+WEnT08R8xtSftxetpKRCsg2kr GWQv/jM1Kx+hzunkqFsEJScaQRzMfG9MUiSPUjS7cyuJIuKd/7MgzKkAmBvE/S+faqAa K5PD/KNjYUUCY3jghdMnpAoFRk230KFLSObKZLrvLuJlpP6jgf0/RjNTq6ACt2E4ZUcT eTfjepE2hzAV8Xs3CB5fhYiG7hMQdEPcDs0BnjuMGb/sgMb1CuST6MS/8FT0fmMkJsWJ QetcaL0XeNxC3HCDt7MxAvE/efBEgaX9Z+tWwuvZPxOqV1RarL9iwRmp9+ihXHS08T9x PHfA== X-Gm-Message-State: AOJu0Yx34/sR6sNNPMAija6qmXb0y/ZdAMNTkJOycvTIaif54KLUCKZz u231NWfhFuXpWVIBylNnmguk768pioPbuyXL7PJJ8cOxpMAy8zspbXySp/cb5Nb5 X-Gm-Gg: ATEYQzyJI+R/F1lmriuM69uJnEYemxTr1eucVoBElJr4bItS08AWiOrAAOjFsp2LChj 29txTV6PWCaX5zd6Th+d3bbAf2yPJUM79pjXMt3TrpbQ/z3DcTqOhaH3mgpDN7F6l8JCDRgfb0h y+pV50SLLQ35o4yzMkdf0SHKC1IidzXeOfC5Ix0DxZsQuu84d7yDxdz7ZkI8Zhgq2sRxgEt25rm RiYnMdu+HA7FXljq5P1vGQKtEJcsbuz+Ktt2lt+FAse4OGrqu/3xNQU6wKNK6dy1rtXdGZCgzx9 c94znzMNtUAyDkNPAFdAtq2wdzfhNCITY/1OLNBB7hLsKMTo80KQkPCJ3ye1zYcQBkzG+fW7Gph 6yJYXukpCI08xz9CtO9GT5oIV0aCSvTTEg5H4VGzwLteoBwuSa7tG0ja13McHkDn9zNciSg+9wp +krVBTCYHQ+6EHKsx2wORvEN18Gklxn+rPDLPXNaUHGsBGn5tSHFkbsKEaWiTgmFLrir9JuA== X-Received: by 2002:a17:907:3f90:b0:b98:cb6:e896 with SMTP id a640c23a62f3a-b9c67b77b14mr24507466b.38.1775167028943; Thu, 02 Apr 2026 14:57:08 -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 15/33] hw/core/fdt_generic_util: implement fdt_get_irq/_info API Date: Thu, 2 Apr 2026 23:56:00 +0200 Message-ID: <20260402215629.745866-16-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::632; envelope-from=ruslichenko.r@gmail.com; helo=mail-ej1-x632.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=unavailable 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: 1775167117234158500 Content-Type: text/plain; charset="utf-8" From: Ruslan Ruslichenko Both interfaces may be used by devices to get IRQ information based device tree entry. Both methods will identify interrupt parent for a device and retrieve irq entry. Signed-off-by: Ruslan Ruslichenko --- hw/core/fdt_generic_util.c | 132 +++++++++++++++++++++++++++++ include/hw/core/fdt_generic_util.h | 17 ++++ 2 files changed, 149 insertions(+) diff --git a/hw/core/fdt_generic_util.c b/hw/core/fdt_generic_util.c index d816e395fd..51b808d9d0 100644 --- a/hw/core/fdt_generic_util.c +++ b/hw/core/fdt_generic_util.c @@ -64,6 +64,11 @@ static int fdt_generic_num_cpus; =20 static int simple_bus_fdt_init(const char *bus_node_path, FDTMachineInfo *= fdti); =20 +static void fdt_get_irq_info_from_intc(FDTMachineInfo *fdti, qemu_irq *ret, + char *intc_node_path, + uint32_t *cells, uint32_t num_cells, + uint32_t max, Error **errp); + FDTMachineInfo *fdt_generic_create_machine(void *fdt, qemu_irq *cpu_irq) { FDTMachineInfo *fdti =3D fdt_init_new_fdti(fdt); @@ -229,6 +234,133 @@ static int simple_bus_fdt_init(const char *node_path,= FDTMachineInfo *fdti) return 0; } =20 +static void fdt_get_irq_info_from_intc(FDTMachineInfo *fdti, qemu_irq *ret, + char *intc_node_path, + uint32_t *cells, uint32_t num_cells, + uint32_t max, Error **errp) +{ + FDTGenericIntcClass *intc_fdt_class; + DeviceState *intc; + + while (!fdt_init_has_opaque(fdti, intc_node_path) && + qemu_in_coroutine()) { + fdt_init_yield(fdti); + } + intc =3D DEVICE(fdt_init_get_opaque(fdti, intc_node_path)); + + if (!intc) { + goto fail; + } + + while (!intc->realized && qemu_in_coroutine()) { + fdt_init_yield(fdti); + } + + if (!intc->realized) { + goto fail; + } + + intc_fdt_class =3D FDT_GENERIC_INTC_GET_CLASS(intc); + if (!intc_fdt_class) { + goto fail; + } + + intc_fdt_class->get_irq(FDT_GENERIC_INTC(intc), ret, cells, num_cells, + max, errp); + + return; +fail: + error_setg(errp, "%s", __func__); +} + +qemu_irq *fdt_get_irq_info(FDTMachineInfo *fdti, char *node_path, int irq_= idx, + char *info) { + void *fdt =3D fdti->fdt; + uint32_t intc_phandle, intc_cells, cells[32]; + char intc_node_path[DT_PATH_LENGTH]; + qemu_irq *ret =3D NULL; + int i; + Error *errp =3D NULL; + + intc_phandle =3D qemu_fdt_getprop_cell_inherited(fdt, node_path, + "interrupt-parent", + 0, &errp); + if (errp) { + goto fail; + } else { + if (qemu_devtree_get_node_by_phandle(fdt, intc_node_path, + intc_phandle)) { + goto fail; + } + + /* Check if the device is using interrupt-maps */ + qemu_fdt_getprop_cell(fdt, node_path, "interrupt-map-mask", 0, + &errp); + if (!errp) { + error_report( + "'interrupt-map' routing is not yet supported for node %s= ", + node_path); + goto fail; + } else { + error_free(errp); + errp =3D NULL; + intc_cells =3D qemu_fdt_getprop_cell_inherited(fdt, intc_node_= path, + "#interrupt-cells", 0, + &errp); + } + } + + if (errp) { + goto fail; + } + + fdt_debug_np("%s intc_phandle: %d\n", node_path, intc_phandle); + + for (i =3D 0; i < intc_cells; ++i) { + cells[i] =3D qemu_fdt_getprop_cell(fdt, node_path, "interrupts", + intc_cells * irq_idx + i, &errp); + if (errp) { + goto fail; + } + } + + fdt_debug_np("Getting IRQ information: %s -> %s\n", + node_path, intc_node_path); + + ret =3D g_new0(qemu_irq, fdt_generic_num_cpus + 2); + fdt_get_irq_info_from_intc(fdti, ret, intc_node_path, cells, intc_cell= s, + fdt_generic_num_cpus, &errp); + + if (errp) { + goto fail; + } + + /* FIXME: Phase out this info bussiness */ + if (info) { + snprintf(info, DT_PATH_LENGTH, "%s", intc_node_path); + } + + return ret; + +fail: + if (info) { + snprintf(info, DT_PATH_LENGTH, "%s", + errp ? error_get_pretty(errp) : "(none)"); + + } + + if (errp) { + error_free(errp); + } + + return NULL; +} + +qemu_irq *fdt_get_irq(FDTMachineInfo *fdti, char *node_path, int irq_idx) +{ + return fdt_get_irq_info(fdti, node_path, irq_idx, NULL); +} + static inline const char *trim_vendor(const char *s) { /* FIXME: be more intelligent */ diff --git a/include/hw/core/fdt_generic_util.h b/include/hw/core/fdt_gener= ic_util.h index c92c79dd12..6fb0708d7a 100644 --- a/include/hw/core/fdt_generic_util.h +++ b/include/hw/core/fdt_generic_util.h @@ -16,6 +16,23 @@ =20 FDTMachineInfo *fdt_generic_create_machine(void *fdt, qemu_irq *cpu_irq); =20 +/* + * get an irq for a device. The interrupt parent of a device is idenitified + * and the specified irq (by the interrupts device-tree property) is retri= eved + */ + +qemu_irq *fdt_get_irq(FDTMachineInfo *fdti, char *node_path, int irq_idx); + +/* + * same as above, but poulates err with non-zero if something goes wrong, = and + * populates info with a human readable string giving some basic informati= on + * about the interrupt connection found (or not found). Both arguments are + * optional (i.e. can be NULL) + */ + +qemu_irq *fdt_get_irq_info(FDTMachineInfo *fdti, char *node_path, int irq_= idx, + char *info); + #define TYPE_FDT_GENERIC_INTC "fdt-generic-intc" =20 #define FDT_GENERIC_INTC_CLASS(klass) \ --=20 2.43.0