{"id":2219345,"url":"http://patchwork.ozlabs.org/api/1.0/patches/2219345/?format=json","project":{"id":14,"url":"http://patchwork.ozlabs.org/api/1.0/projects/14/?format=json","name":"QEMU Development","link_name":"qemu-devel","list_id":"qemu-devel.nongnu.org","list_email":"qemu-devel@nongnu.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20260402215629.745866-16-ruslichenko.r@gmail.com>","date":"2026-04-02T21:56:00","name":"[v3,15/33] hw/core/fdt_generic_util: implement fdt_get_irq/_info API","commit_ref":null,"pull_url":null,"state":"new","archived":false,"hash":"d34015e2bf59e6c47507b0ce4cb574fae7c03fcf","submitter":{"id":92275,"url":"http://patchwork.ozlabs.org/api/1.0/people/92275/?format=json","name":"Ruslan Ruslichenko","email":"ruslichenko.r@gmail.com"},"delegate":null,"mbox":"http://patchwork.ozlabs.org/project/qemu-devel/patch/20260402215629.745866-16-ruslichenko.r@gmail.com/mbox/","series":[{"id":498555,"url":"http://patchwork.ozlabs.org/api/1.0/series/498555/?format=json","date":"2026-04-02T21:55:47","name":"hw/arm: Introduce generic FDT-driven machine","version":3,"mbox":"http://patchwork.ozlabs.org/series/498555/mbox/"}],"check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/2219345/checks/","tags":{},"headers":{"Return-Path":"<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>","X-Original-To":"incoming@patchwork.ozlabs.org","Delivered-To":"patchwork-incoming@legolas.ozlabs.org","Authentication-Results":["legolas.ozlabs.org;\n\tdkim=pass (2048-bit key;\n unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256\n header.s=20251104 header.b=Fr4iMmC7;\n\tdkim-atps=neutral","legolas.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org\n (client-ip=209.51.188.17; helo=lists.gnu.org;\n envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org;\n receiver=patchwork.ozlabs.org)"],"Received":["from lists.gnu.org (lists.gnu.org [209.51.188.17])\n\t(using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits))\n\t(No client certificate requested)\n\tby legolas.ozlabs.org (Postfix) with ESMTPS id 4fmwj826Fcz1yDH\n\tfor <incoming@patchwork.ozlabs.org>; Fri, 03 Apr 2026 08:58:36 +1100 (AEDT)","from localhost ([::1] helo=lists1p.gnu.org)\n\tby lists.gnu.org with esmtp (Exim 4.90_1)\n\t(envelope-from <qemu-devel-bounces@nongnu.org>)\n\tid 1w8Q2W-0008WJ-GO; Thu, 02 Apr 2026 17:57:24 -0400","from eggs.gnu.org ([2001:470:142:3::10])\n by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)\n (Exim 4.90_1) (envelope-from <ruslichenko.r@gmail.com>)\n id 1w8Q2L-0008Lm-UJ\n for qemu-devel@nongnu.org; Thu, 02 Apr 2026 17:57:14 -0400","from mail-ej1-x632.google.com ([2a00:1450:4864:20::632])\n by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128)\n (Exim 4.90_1) (envelope-from <ruslichenko.r@gmail.com>)\n id 1w8Q2J-00079F-02\n for qemu-devel@nongnu.org; Thu, 02 Apr 2026 17:57:13 -0400","by mail-ej1-x632.google.com with SMTP id\n a640c23a62f3a-b9b1df1a6b3so163801166b.0\n for <qemu-devel@nongnu.org>; Thu, 02 Apr 2026 14:57:10 -0700 (PDT)","from thinkpad-t470s.. (93-143-182-244.adsl.net.t-com.hr.\n [93.143.182.244]) by smtp.googlemail.com with ESMTPSA id\n a640c23a62f3a-b9c3cac0e1asm134009166b.27.2026.04.02.14.57.07\n (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n Thu, 02 Apr 2026 14:57:08 -0700 (PDT)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=gmail.com; s=20251104; t=1775167029; x=1775771829; darn=nongnu.org;\n h=content-transfer-encoding:mime-version:references:in-reply-to\n :message-id:date:subject:cc:to:from:from:to:cc:subject:date\n :message-id:reply-to;\n bh=Ti9TrcfoeyeQNd3Zl+7f/uTE9kKOziltFUJwrjRDreg=;\n b=Fr4iMmC7WwQK5xcFXq3KoWVvYw1sLpScUkAyX2dEBxAnaQ/c+DrWt/EvM7iaH95pVE\n w8eX89SdjLinq2SNiHTXiuEceo0VdjORF52Ozsj182KKD/fHrQrYCzA/2Mcj8b8LNYUF\n zks7OwlSXhlbGl3YJ9IsAs41xoPRn6lkIHaEr/+4gxWMhSR2AgXODZNABCqBOWQk7EPv\n nWmMQECFVAzn0DTo9VonLhxoj4BlYTbR40Nucit3sjvCxWET1RY0nXf7X+RvqF0aF7Y8\n yLUXYePTAXB8/NxXQYZO9W2HmRtkEb3mPzGSLXTgVmEMp89TOfiNAcZKNgy4VvtUNHGV\n EaAA==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=1e100.net; s=20251104; t=1775167029; x=1775771829;\n h=content-transfer-encoding:mime-version:references:in-reply-to\n :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from\n :to:cc:subject:date:message-id:reply-to;\n bh=Ti9TrcfoeyeQNd3Zl+7f/uTE9kKOziltFUJwrjRDreg=;\n b=EASKxNG1Lp3+5S2zgloYtQkqFhBGkR4hcVTsXRCR+WEnT08R8xtSftxetpKRCsg2kr\n GWQv/jM1Kx+hzunkqFsEJScaQRzMfG9MUiSPUjS7cyuJIuKd/7MgzKkAmBvE/S+faqAa\n K5PD/KNjYUUCY3jghdMnpAoFRk230KFLSObKZLrvLuJlpP6jgf0/RjNTq6ACt2E4ZUcT\n eTfjepE2hzAV8Xs3CB5fhYiG7hMQdEPcDs0BnjuMGb/sgMb1CuST6MS/8FT0fmMkJsWJ\n QetcaL0XeNxC3HCDt7MxAvE/efBEgaX9Z+tWwuvZPxOqV1RarL9iwRmp9+ihXHS08T9x\n PHfA==","X-Gm-Message-State":"AOJu0Yx34/sR6sNNPMAija6qmXb0y/ZdAMNTkJOycvTIaif54KLUCKZz\n u231NWfhFuXpWVIBylNnmguk768pioPbuyXL7PJJ8cOxpMAy8zspbXySp/cb5Nb5","X-Gm-Gg":"ATEYQzyJI+R/F1lmriuM69uJnEYemxTr1eucVoBElJr4bItS08AWiOrAAOjFsp2LChj\n 29txTV6PWCaX5zd6Th+d3bbAf2yPJUM79pjXMt3TrpbQ/z3DcTqOhaH3mgpDN7F6l8JCDRgfb0h\n y+pV50SLLQ35o4yzMkdf0SHKC1IidzXeOfC5Ix0DxZsQuu84d7yDxdz7ZkI8Zhgq2sRxgEt25rm\n RiYnMdu+HA7FXljq5P1vGQKtEJcsbuz+Ktt2lt+FAse4OGrqu/3xNQU6wKNK6dy1rtXdGZCgzx9\n c94znzMNtUAyDkNPAFdAtq2wdzfhNCITY/1OLNBB7hLsKMTo80KQkPCJ3ye1zYcQBkzG+fW7Gph\n 6yJYXukpCI08xz9CtO9GT5oIV0aCSvTTEg5H4VGzwLteoBwuSa7tG0ja13McHkDn9zNciSg+9wp\n +krVBTCYHQ+6EHKsx2wORvEN18Gklxn+rPDLPXNaUHGsBGn5tSHFkbsKEaWiTgmFLrir9JuA==","X-Received":"by 2002:a17:907:3f90:b0:b98:cb6:e896 with SMTP id\n a640c23a62f3a-b9c67b77b14mr24507466b.38.1775167028943;\n Thu, 02 Apr 2026 14:57:08 -0700 (PDT)","From":"Ruslan Ruslichenko <ruslichenko.r@gmail.com>","To":"qemu-devel@nongnu.org","Cc":"qemu-arm@nongnu.org, alex.bennee@linaro.org, peter.maydell@linaro.org,\n artem_mygaiev@epam.com, volodymyr_babchuk@epam.com,\n takahiro.nakata.wr@renesas.com,\n \"Edgar E . Iglesias\" <edgar.iglesias@gmail.com>,\n Ruslan_Ruslichenko@epam.com, balaton@eik.bme.hu","Subject":"[PATCH v3 15/33] hw/core/fdt_generic_util: implement\n 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":"8bit","Received-SPF":"pass client-ip=2a00:1450:4864:20::632;\n 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,\n DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001,\n RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001,\n 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 <qemu-devel.nongnu.org>","List-Unsubscribe":"<https://lists.nongnu.org/mailman/options/qemu-devel>,\n <mailto:qemu-devel-request@nongnu.org?subject=unsubscribe>","List-Archive":"<https://lists.nongnu.org/archive/html/qemu-devel>","List-Post":"<mailto:qemu-devel@nongnu.org>","List-Help":"<mailto:qemu-devel-request@nongnu.org?subject=help>","List-Subscribe":"<https://lists.nongnu.org/mailman/listinfo/qemu-devel>,\n <mailto:qemu-devel-request@nongnu.org?subject=subscribe>","Errors-To":"qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org","Sender":"qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org"},"content":"From: Ruslan Ruslichenko <Ruslan_Ruslichenko@epam.com>\n\nBoth interfaces may be used by devices to get IRQ information\nbased device tree entry.\nBoth methods will identify interrupt parent for a device and\nretrieve irq entry.\n\nSigned-off-by: Ruslan Ruslichenko <Ruslan_Ruslichenko@epam.com>\n---\n hw/core/fdt_generic_util.c         | 132 +++++++++++++++++++++++++++++\n include/hw/core/fdt_generic_util.h |  17 ++++\n 2 files changed, 149 insertions(+)","diff":"diff --git a/hw/core/fdt_generic_util.c b/hw/core/fdt_generic_util.c\nindex d816e395fd..51b808d9d0 100644\n--- a/hw/core/fdt_generic_util.c\n+++ b/hw/core/fdt_generic_util.c\n@@ -64,6 +64,11 @@ static int fdt_generic_num_cpus;\n \n static int simple_bus_fdt_init(const char *bus_node_path, FDTMachineInfo *fdti);\n \n+static void fdt_get_irq_info_from_intc(FDTMachineInfo *fdti, qemu_irq *ret,\n+                                       char *intc_node_path,\n+                                       uint32_t *cells, uint32_t num_cells,\n+                                       uint32_t max, Error **errp);\n+\n FDTMachineInfo *fdt_generic_create_machine(void *fdt, qemu_irq *cpu_irq)\n {\n     FDTMachineInfo *fdti = fdt_init_new_fdti(fdt);\n@@ -229,6 +234,133 @@ static int simple_bus_fdt_init(const char *node_path, FDTMachineInfo *fdti)\n     return 0;\n }\n \n+static void fdt_get_irq_info_from_intc(FDTMachineInfo *fdti, qemu_irq *ret,\n+                                       char *intc_node_path,\n+                                       uint32_t *cells, uint32_t num_cells,\n+                                       uint32_t max, Error **errp)\n+{\n+    FDTGenericIntcClass *intc_fdt_class;\n+    DeviceState *intc;\n+\n+    while (!fdt_init_has_opaque(fdti, intc_node_path) &&\n+           qemu_in_coroutine()) {\n+        fdt_init_yield(fdti);\n+    }\n+    intc = DEVICE(fdt_init_get_opaque(fdti, intc_node_path));\n+\n+    if (!intc) {\n+        goto fail;\n+    }\n+\n+    while (!intc->realized && qemu_in_coroutine()) {\n+        fdt_init_yield(fdti);\n+    }\n+\n+    if (!intc->realized) {\n+        goto fail;\n+    }\n+\n+    intc_fdt_class = FDT_GENERIC_INTC_GET_CLASS(intc);\n+    if (!intc_fdt_class) {\n+        goto fail;\n+    }\n+\n+    intc_fdt_class->get_irq(FDT_GENERIC_INTC(intc), ret, cells, num_cells,\n+                            max, errp);\n+\n+    return;\n+fail:\n+    error_setg(errp, \"%s\", __func__);\n+}\n+\n+qemu_irq *fdt_get_irq_info(FDTMachineInfo *fdti, char *node_path, int irq_idx,\n+                          char *info) {\n+    void *fdt = fdti->fdt;\n+    uint32_t intc_phandle, intc_cells, cells[32];\n+    char intc_node_path[DT_PATH_LENGTH];\n+    qemu_irq *ret = NULL;\n+    int i;\n+    Error *errp = NULL;\n+\n+    intc_phandle = qemu_fdt_getprop_cell_inherited(fdt, node_path,\n+                                                   \"interrupt-parent\",\n+                                                   0, &errp);\n+    if (errp) {\n+        goto fail;\n+    } else {\n+        if (qemu_devtree_get_node_by_phandle(fdt, intc_node_path,\n+                                             intc_phandle)) {\n+            goto fail;\n+        }\n+\n+        /* Check if the device is using interrupt-maps */\n+        qemu_fdt_getprop_cell(fdt, node_path, \"interrupt-map-mask\", 0,\n+                              &errp);\n+        if (!errp) {\n+            error_report(\n+                 \"'interrupt-map' routing is not yet supported for node %s\",\n+                     node_path);\n+            goto fail;\n+        } else {\n+            error_free(errp);\n+            errp = NULL;\n+            intc_cells = qemu_fdt_getprop_cell_inherited(fdt, intc_node_path,\n+                                               \"#interrupt-cells\", 0,\n+                                               &errp);\n+        }\n+    }\n+\n+    if (errp) {\n+        goto fail;\n+    }\n+\n+    fdt_debug_np(\"%s intc_phandle: %d\\n\", node_path, intc_phandle);\n+\n+    for (i = 0; i < intc_cells; ++i) {\n+        cells[i] = qemu_fdt_getprop_cell(fdt, node_path, \"interrupts\",\n+                                        intc_cells * irq_idx + i, &errp);\n+        if (errp) {\n+            goto fail;\n+        }\n+    }\n+\n+    fdt_debug_np(\"Getting IRQ information: %s -> %s\\n\",\n+                node_path, intc_node_path);\n+\n+    ret = g_new0(qemu_irq, fdt_generic_num_cpus + 2);\n+    fdt_get_irq_info_from_intc(fdti, ret, intc_node_path, cells, intc_cells,\n+                               fdt_generic_num_cpus, &errp);\n+\n+    if (errp) {\n+        goto fail;\n+    }\n+\n+    /* FIXME: Phase out this info bussiness */\n+    if (info) {\n+        snprintf(info, DT_PATH_LENGTH, \"%s\", intc_node_path);\n+    }\n+\n+    return ret;\n+\n+fail:\n+    if (info) {\n+        snprintf(info, DT_PATH_LENGTH, \"%s\",\n+                 errp ? error_get_pretty(errp) : \"(none)\");\n+\n+    }\n+\n+    if (errp) {\n+        error_free(errp);\n+    }\n+\n+    return NULL;\n+}\n+\n+qemu_irq *fdt_get_irq(FDTMachineInfo *fdti, char *node_path, int irq_idx)\n+{\n+    return fdt_get_irq_info(fdti, node_path, irq_idx, NULL);\n+}\n+\n static inline const char *trim_vendor(const char *s)\n {\n     /* FIXME: be more intelligent */\ndiff --git a/include/hw/core/fdt_generic_util.h b/include/hw/core/fdt_generic_util.h\nindex c92c79dd12..6fb0708d7a 100644\n--- a/include/hw/core/fdt_generic_util.h\n+++ b/include/hw/core/fdt_generic_util.h\n@@ -16,6 +16,23 @@\n \n FDTMachineInfo *fdt_generic_create_machine(void *fdt, qemu_irq *cpu_irq);\n \n+/*\n+ * get an irq for a device. The interrupt parent of a device is idenitified\n+ * and the specified irq (by the interrupts device-tree property) is retrieved\n+ */\n+\n+qemu_irq *fdt_get_irq(FDTMachineInfo *fdti, char *node_path, int irq_idx);\n+\n+/*\n+ * same as above, but poulates err with non-zero if something goes wrong, and\n+ * populates info with a human readable string giving some basic information\n+ * about the interrupt connection found (or not found). Both arguments are\n+ * optional (i.e. can be NULL)\n+ */\n+\n+qemu_irq *fdt_get_irq_info(FDTMachineInfo *fdti, char *node_path, int irq_idx,\n+                           char *info);\n+\n #define TYPE_FDT_GENERIC_INTC \"fdt-generic-intc\"\n \n #define FDT_GENERIC_INTC_CLASS(klass) \\\n","prefixes":["v3","15/33"]}