{"id":2198196,"url":"http://patchwork.ozlabs.org/api/1.0/patches/2198196/?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":"<20260219143332.3316679-8-ruslichenko.r@gmail.com>","date":"2026-02-19T14:33:06","name":"[v2,07/33] hw/core/fdt_generic_util: implement main fdt parse routine","commit_ref":null,"pull_url":null,"state":"new","archived":false,"hash":"70bab9fab7ecc5a6ed06f29e3573ec410c5f99f6","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/20260219143332.3316679-8-ruslichenko.r@gmail.com/mbox/","series":[{"id":492690,"url":"http://patchwork.ozlabs.org/api/1.0/series/492690/?format=json","date":"2026-02-19T14:33:04","name":"hw/arm: Introduce generic FDT-driven machine","version":2,"mbox":"http://patchwork.ozlabs.org/series/492690/mbox/"}],"check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/2198196/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=20230601 header.b=nSuNBxUR;\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 4fGwt33jHSz1xpl\n\tfor <incoming@patchwork.ozlabs.org>; Fri, 20 Feb 2026 01:36:11 +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 1vt57F-00009X-1p; Thu, 19 Feb 2026 09:34:53 -0500","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 1vt57C-00006r-SH\n for qemu-devel@nongnu.org; Thu, 19 Feb 2026 09:34:50 -0500","from mail-wr1-x42a.google.com ([2a00:1450:4864:20::42a])\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 1vt57A-0002xq-Lu\n for qemu-devel@nongnu.org; Thu, 19 Feb 2026 09:34:50 -0500","by mail-wr1-x42a.google.com with SMTP id\n ffacd0b85a97d-43638a3330dso869697f8f.0\n for <qemu-devel@nongnu.org>; Thu, 19 Feb 2026 06:34:48 -0800 (PST)","from thinkpad-t470s.. (93-143-129-182.adsl.net.t-com.hr.\n [93.143.129.182]) by smtp.googlemail.com with ESMTPSA id\n ffacd0b85a97d-43796abd259sm52022770f8f.24.2026.02.19.06.34.45\n (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n Thu, 19 Feb 2026 06:34:45 -0800 (PST)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=gmail.com; s=20230601; t=1771511686; x=1772116486; 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=01ZMGYFRrfWfHnGaFGvUO9i4Bz2/krK23Z8+MfNVIME=;\n b=nSuNBxURymz82328BZ6kISQ6iEs2MNjLOilXfKTkm0WHBZtnlEkdZlV0cpwic9u9Ji\n fbGX26coPQ2Qj24sLkN3MRXaAW6TgsCWAxBE6S9UJqe7M0TuKXcrs6B+83FTbdr36Rb2\n i/bepqg/C8aC5LkEPWjk8L90wEtJ1EHsrDgncFycf6UpRDb2d3zVdfsGR6gWBGIPsPv/\n jcfYCNcasDULFyVoFxWdppXxGW2svoxBE3XLt5zsXQSsx9w1Xxcrs0yK1UuFbmxqmZUz\n mSwxO9vK5P+C3pf01IyK7iswq7wCxD4oMqjsvof7NvQBQB+2Sgu9cmtqFX+gSSw7ioGJ\n alOw==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=1e100.net; s=20230601; t=1771511687; x=1772116487;\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=01ZMGYFRrfWfHnGaFGvUO9i4Bz2/krK23Z8+MfNVIME=;\n b=JZmQEP6kGovwvouwjFBz+2bGra7SzAWqmWVmmaD25MrsufeNl3bD6naSJX/URYUyA2\n cQlKIts3cEk/3P2l6vLU84ZjgGbovW+hDE2oxt60HFo4aCQ6qUBaG9m3EtAPGBmif1wn\n hsxxle6+k0qG+1tt9iAy80KiGG57qxh1Hyfj0w7Ut4+rYZkqboEbkkzKb8R71Y4OZV8L\n MgP75JwXhy8p0NCvw1Ow/kCfYc71Pp/+VFDz0y6E+Tef6omUZuO2vw2Gt2sWaArZWZZj\n Z6XzHx5LnZfsYg0Rh4HCfUybhYS55X8x/5GFXVE4+8bD2DIngekDWjUN7Hmn5mdcqNM6\n 4G5Q==","X-Gm-Message-State":"AOJu0YyxUz/Vi4nmJKY1Yw3pTWAvaztbIPdl2cO6bsyv1mqYNKKFWSc9\n jjjhXsZK41Npn5EOXxPnUpRuRjE60ST7wJeurNKVUZwg1oKHF+F7zDmkQ1Q27klz","X-Gm-Gg":"AZuq6aJU1dx9/3jwoFsZL+F3zfRiWKAvP+qvLVWiLQSe83j1QTnW35WdyJUMBSKc8Bv\n VJ7EK6+8mHW0torj13ro1Um4ulE/jktXfqfUUPuzyLBxJSzXlFWHgQMTjCN1zXYQz0v/2MdezfC\n b/t+ZG4U3muV8CvpPxWCL2BeOrMYnw82D93N2rwb+Hn0uFo94Vnayr7INpuDn+LT08gqw2LkCt0\n v4PSqQucxYBskTOjZ4Tb9HWKMTbjn9ayTfOsWMmURrm9+esuv4yQ1ssoT9g9kajnBz+nxss5sub\n kNx0+4wckhKKiZ+FOo5DY5tic6dvnrwpkxYael/EfuwxENYd2mcXOebRA6fWMeWC4RHVeW7p947\n Hj9wQA2+FMRMcvLAizTxX+1d3VNERk/4Bmml33X6kiiTRAHoEAjYI1poyAN8z3JG8DlO3dCyOvL\n duvFTbpaRxfZw3ejwTCBkixCMFRN3GjkqRwYRPEUVMa8W9X6CRNKU4hux+JYUqpJyQp1px","X-Received":"by 2002:a05:6000:2203:b0:436:173c:b8e3 with SMTP id\n ffacd0b85a97d-4379db93b3amr33744794f8f.29.1771511686405;\n Thu, 19 Feb 2026 06:34:46 -0800 (PST)","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 v2 07/33] hw/core/fdt_generic_util: implement main fdt parse\n routine","Date":"Thu, 19 Feb 2026 15:33:06 +0100","Message-ID":"<20260219143332.3316679-8-ruslichenko.r@gmail.com>","X-Mailer":"git-send-email 2.43.0","In-Reply-To":"<20260219143332.3316679-1-ruslichenko.r@gmail.com>","References":"<20260219143332.3316679-1-ruslichenko.r@gmail.com>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","Received-SPF":"pass client-ip=2a00:1450:4864:20::42a;\n envelope-from=ruslichenko.r@gmail.com; helo=mail-wr1-x42a.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\nImplement main fdt_generic_create_machine() routine.\n\nAs of now do the following:\n\n- parse each node and subnode in device tree\n- check node has correct compatible or device types\n- call fdt_init_qdev() which will eventually create\n  device object.\n\nThe MIT license of fdt_generic_util.c preserved as in original\nfile from https://github.com/Xilinx/qemu.git repo.\n\nThe license for fdt_generic_util.h derived from matching\nfdt_generic_util.c file.\n\nSigned-off-by: Ruslan Ruslichenko <Ruslan_Ruslichenko@epam.com>\n---\n hw/core/fdt_generic_util.c         | 245 +++++++++++++++++++++++++++++\n include/hw/core/fdt_generic_util.h |  19 +++\n 2 files changed, 264 insertions(+)\n create mode 100644 hw/core/fdt_generic_util.c\n create mode 100644 include/hw/core/fdt_generic_util.h","diff":"diff --git a/hw/core/fdt_generic_util.c b/hw/core/fdt_generic_util.c\nnew file mode 100644\nindex 0000000000..3606c11349\n--- /dev/null\n+++ b/hw/core/fdt_generic_util.c\n@@ -0,0 +1,245 @@\n+// SPDX-License-Identifier: MIT\n+/*\n+ * Utility functions for fdt generic framework\n+ *\n+ * Copyright (c) 2009 Edgar E. Iglesias.\n+ * Copyright (c) 2009 Michal Simek.\n+ * Copyright (c) 2011 PetaLogix Qld Pty Ltd.\n+ * Copyright (c) 2011 Peter A. G. Crosthwaite <peter.crosthwaite@petalogix.com>.\n+ *\n+ * Permission is hereby granted, free of charge, to any person obtaining a copy\n+ * of this software and associated documentation files (the \"Software\"), to deal\n+ * in the Software without restriction, including without limitation the rights\n+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n+ * copies of the Software, and to permit persons to whom the Software is\n+ * furnished to do so, subject to the following conditions:\n+ *\n+ * The above copyright notice and this permission notice shall be included in\n+ * all copies or substantial portions of the Software.\n+ *\n+ * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL\n+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n+ * THE SOFTWARE.\n+ */\n+\n+#include \"qemu/osdep.h\"\n+#include \"hw/core/fdt_generic_util.h\"\n+#include \"system/memory.h\"\n+#include \"system/address-spaces.h\"\n+#include \"hw/core/sysbus.h\"\n+#include \"qapi/error.h\"\n+#include \"qemu/error-report.h\"\n+#include \"system/system.h\"\n+#include \"system/reset.h\"\n+#include \"qemu/cutils.h\"\n+#include \"qemu/log.h\"\n+#include \"qemu/config-file.h\"\n+#include \"hw/core/boards.h\"\n+#include \"qemu/option.h\"\n+\n+#ifndef FDT_GENERIC_UTIL_ERR_DEBUG\n+#define FDT_GENERIC_UTIL_ERR_DEBUG 3\n+#endif\n+#define DB_PRINT(lvl, ...) do { \\\n+    if (FDT_GENERIC_UTIL_ERR_DEBUG > (lvl)) { \\\n+        qemu_log_mask(LOG_FDT, \": %s: \", __func__); \\\n+        qemu_log_mask(LOG_FDT, ## __VA_ARGS__); \\\n+    } \\\n+} while (0)\n+\n+#define DB_PRINT_NP(lvl, ...) do { \\\n+    if (FDT_GENERIC_UTIL_ERR_DEBUG > (lvl)) { \\\n+        qemu_log_mask(LOG_FDT, \"%s\", node_path); \\\n+        DB_PRINT((lvl), ## __VA_ARGS__); \\\n+    } \\\n+} while (0)\n+\n+/* FIXME: wrap direct calls into libfdt */\n+\n+#include <libfdt.h>\n+#include <stdlib.h>\n+\n+static int fdt_generic_num_cpus;\n+\n+static int simple_bus_fdt_init(char *bus_node_path, FDTMachineInfo *fdti);\n+\n+FDTMachineInfo *fdt_generic_create_machine(void *fdt, qemu_irq *cpu_irq)\n+{\n+    char node_path[DT_PATH_LENGTH];\n+    FDTMachineInfo *fdti = fdt_init_new_fdti(fdt);\n+\n+    fdti->irq_base = cpu_irq;\n+\n+    /* parse the device tree */\n+    if (!fdt_get_path(fdt, 0, node_path, DT_PATH_LENGTH)) {\n+        memory_region_transaction_begin();\n+        fdt_init_set_opaque(fdti, node_path, NULL);\n+        simple_bus_fdt_init(node_path, fdti);\n+        while (qemu_co_enter_next(fdti->cq, NULL)) {\n+            ;\n+        }\n+        memory_region_transaction_commit();\n+    } else {\n+        fprintf(stderr, \"FDT: ERROR: cannot get root node from device tree %s\\n\"\n+            , node_path);\n+    }\n+\n+    /* FIXME: Populate these from DTS and create CPU clusters.  */\n+    current_machine->smp.cores = fdt_generic_num_cpus;\n+    current_machine->smp.cpus = fdt_generic_num_cpus;\n+    current_machine->smp.max_cpus = fdt_generic_num_cpus;\n+\n+    DB_PRINT(0, \"FDT: Device tree scan complete\\n\");\n+    return fdti;\n+}\n+\n+struct FDTInitNodeArgs {\n+    char *node_path;\n+    char *parent_path;\n+    FDTMachineInfo *fdti;\n+};\n+\n+static int fdt_init_qdev(char *node_path, FDTMachineInfo *fdti, char *compat);\n+\n+static int check_compat(const char *prefix, const char *compat,\n+                        char *node_path, FDTMachineInfo *fdti)\n+{\n+    char *compat_prefixed = g_strconcat(prefix, compat, NULL);\n+    const int done = !fdt_init_compat(node_path, fdti, compat_prefixed);\n+    g_free(compat_prefixed);\n+    return done;\n+}\n+\n+static void fdt_init_node(void *args)\n+{\n+    struct FDTInitNodeArgs *a = args;\n+    char *node_path = a->node_path;\n+    FDTMachineInfo *fdti = a->fdti;\n+    g_free(a);\n+\n+    simple_bus_fdt_init(node_path, fdti);\n+\n+    const char *prop;\n+    char *all_compats = NULL, *node_name;\n+    char *device_type = NULL;\n+    int prop_len;\n+\n+    DB_PRINT_NP(1, \"enter\\n\");\n+\n+    /* try instance binding first */\n+    node_name = strrchr(node_path, '/') + 1;\n+    DB_PRINT_NP(1, \"node with name: %s\\n\", node_name ? node_name : \"(none)\");\n+    if (!node_name) {\n+        printf(\"FDT: ERROR: nameless node: %s\\n\", node_path);\n+    }\n+    if (!fdt_init_inst_bind(node_path, fdti, node_name)) {\n+        DB_PRINT_NP(0, \"instance bind successful\\n\");\n+        goto exit;\n+    }\n+\n+    /* fallback to compatibility binding */\n+    prop = qemu_fdt_getprop(fdti->fdt, node_path, \"compatible\",\n+                                       &prop_len, NULL);\n+    all_compats = g_memdup2(prop, prop_len);\n+    if (all_compats) {\n+        char *compat = all_compats;\n+        char * const end = &all_compats[prop_len - 1]; /* points to nul */\n+\n+        while (compat < end) {\n+            if (check_compat(\"compatible:\", compat, node_path, fdti)) {\n+                goto exit;\n+            }\n+\n+            if (!fdt_init_qdev(node_path, fdti, compat)) {\n+                check_compat(\"postinit:\", compat, node_path, fdti);\n+                goto exit;\n+            }\n+\n+            /* Scan forward to the end of the current compat. */\n+            while (compat < end && *compat) {\n+                ++compat;\n+            }\n+\n+            /* Replace nul with space for the debug printf below. */\n+            if (compat < end) {\n+                *compat++ = ' ';\n+            }\n+        };\n+    } else {\n+        DB_PRINT_NP(0, \"no compatibility found\\n\");\n+    }\n+\n+    /*\n+     * Try to create the device using device_type property\n+     * Not every device tree node has compatible  property, so\n+     * try with device_type.\n+     */\n+    prop = qemu_fdt_getprop(fdti->fdt, node_path,\n+                            \"device_type\", &prop_len, NULL);\n+    device_type = g_memdup2(prop, prop_len);\n+    if (device_type) {\n+        if (check_compat(\"device_type:\", device_type, node_path, fdti)) {\n+            goto exit;\n+        }\n+\n+        if (!fdt_init_qdev(node_path, fdti, device_type)) {\n+            goto exit;\n+        }\n+    }\n+\n+    if (all_compats) {\n+        DB_PRINT_NP(0, \"FDT: Unsupported peripheral invalidated - \"\n+                    \"compatibilities %s\\n\", all_compats);\n+        qemu_fdt_setprop_string(fdti->fdt, node_path, \"compatible\",\n+                                \"invalidated\");\n+    }\n+exit:\n+\n+    DB_PRINT_NP(1, \"exit\\n\");\n+\n+    if (!fdt_init_has_opaque(fdti, node_path)) {\n+        fdt_init_set_opaque(fdti, node_path, NULL);\n+    }\n+    g_free(node_path);\n+    g_free(all_compats);\n+    g_free(device_type);\n+    return;\n+}\n+\n+static int simple_bus_fdt_init(char *node_path, FDTMachineInfo *fdti)\n+{\n+    int i;\n+    char **children;\n+    int num_children = qemu_devtree_get_num_children(fdti->fdt, node_path);\n+\n+    if (num_children <= 0) {\n+        return 0;\n+    }\n+\n+    children = g_malloc0(sizeof(*children) * num_children);\n+\n+    num_children = qemu_devtree_get_children(fdti->fdt, node_path, num_children,\n+                                             children);\n+\n+    DB_PRINT_NP(num_children ? 0 : 1, \"num child devices: %d\\n\", num_children);\n+\n+    for (i = 0; i < num_children; i++) {\n+        struct FDTInitNodeArgs *init_args = g_malloc0(sizeof(*init_args));\n+        init_args->node_path = children[i];\n+        init_args->fdti = fdti;\n+        qemu_coroutine_enter(qemu_coroutine_create(fdt_init_node, init_args));\n+    }\n+\n+    g_free(children);\n+    return 0;\n+}\n+\n+static int fdt_init_qdev(char *node_path, FDTMachineInfo *fdti, char *compat)\n+{\n+    return 0;\n+}\n+\ndiff --git a/include/hw/core/fdt_generic_util.h b/include/hw/core/fdt_generic_util.h\nnew file mode 100644\nindex 0000000000..e18c4f9c8b\n--- /dev/null\n+++ b/include/hw/core/fdt_generic_util.h\n@@ -0,0 +1,19 @@\n+// SPDX-License-Identifier: MIT\n+\n+#ifndef FDT_GENERIC_UTIL_H\n+#define FDT_GENERIC_UTIL_H\n+\n+#include \"qemu/help-texts.h\"\n+#include \"fdt_generic.h\"\n+#include \"system/memory.h\"\n+#include \"qom/object.h\"\n+\n+/*\n+ * create a fdt_generic machine. the top level cpu irqs are required for\n+ * systems instantiating interrupt devices. The client is responsible for\n+ * destroying the returned FDTMachineInfo (using fdt_init_destroy_fdti)\n+ */\n+\n+FDTMachineInfo *fdt_generic_create_machine(void *fdt, qemu_irq *cpu_irq);\n+\n+#endif /* FDT_GENERIC_UTIL_H */\n","prefixes":["v2","07/33"]}