From nobody Sat Feb 7 07:11:52 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=1769449897; cv=none; d=zohomail.com; s=zohoarc; b=JfzQp7ZIBS83hKYSb9V7OacXnIXS+G6amTMbrTsmeAPRecZh8ZhoQmMPayXwi3k3ZF5KKfXtRS3F0e3FIxv5zv8E2ExYzQ/8+q/AYvkYSmjU6/62lgdIEaaC7AnDJnNFHhV1WbX038jC7icwtc8THbrgsFjw0ogUfUHYARbBwuc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1769449897; 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=+JVcXy0dwK/92fGA+np6cVxIVwdiBdpVuuBvIqmsfVg=; b=Ie2egp9ity8XAjI3omy31Gz1n7HDZlgIaRQcsdmaIfatjAwBTkHu3k119B8xu0zZ/HiWLATpFf7CWvIn1ZDdpzVfxp8WY0UDns0rz2by2niYUH/xJM0V8CcrCygUmbseA2WaQsp+Vh+dTv96TmJRjp0WA6F1FHw3bg4L3JXeltM= 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 1769449897350117.89205937443262; Mon, 26 Jan 2026 09:51:37 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vkQd7-0001cI-2J; Mon, 26 Jan 2026 12:44:01 -0500 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 1vkQch-0001K4-TH for qemu-devel@nongnu.org; Mon, 26 Jan 2026 12:43:36 -0500 Received: from mail-wm1-x32b.google.com ([2a00:1450:4864:20::32b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1vkQcf-0008V9-71 for qemu-devel@nongnu.org; Mon, 26 Jan 2026 12:43:35 -0500 Received: by mail-wm1-x32b.google.com with SMTP id 5b1f17b1804b1-480142406b3so32372085e9.1 for ; Mon, 26 Jan 2026 09:43:32 -0800 (PST) Received: from thinkpad-t470s.. (93-143-71-105.adsl.net.t-com.hr. [93.143.71.105]) by smtp.googlemail.com with ESMTPSA id ffacd0b85a97d-435b1e71730sm34199603f8f.26.2026.01.26.09.43.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Jan 2026 09:43:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1769449411; x=1770054211; 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=+JVcXy0dwK/92fGA+np6cVxIVwdiBdpVuuBvIqmsfVg=; b=LGwrmPOP57ZB4GCtoSDiDT5dfLyiLDq8rHNofyKZCZ1yxWCbP2XKOYfHPs5hzXmB9c tidxZ1F+EQn1FU4p/teVW95USRpxZN9h9NPKErP81UdXqX/vyQ1wV8PoKgisNXkStBH0 Tzm35+MaU6I9cccN8VO3XL5YQliII4FeaiEVR4cGCCGV+67CR75FfAbUVLK9f3QLm/ws DC+Vu+tXzEqA2ItZ57YYh7YAtj0NyYfVY/1pJSZu88l5aGmwkjzRh+/7xnqKKtrwZ6XI g0XzWG8DcHbtL2J6EstYnTq2vrdWU0p3bkWEqBq/IfA7neOTQyU1OvB81ZaD2kBoMWZf 9DUw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1769449411; x=1770054211; 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=+JVcXy0dwK/92fGA+np6cVxIVwdiBdpVuuBvIqmsfVg=; b=J5MLfWAGrvDUGFaCkt4JkNomD3vfEzhbYIugfQq4D6RiaLMyzF3ddt5li0ZbK2m63h uMH9qsdsh18vNy123k8h+mSGfG9NvdZ4rMa6m5fpeP5sNB+GJgtzHgtl5FH46ICRy/3O bmE5ZxDbF1rdEAbGb3sGAuvQBw27cmD5y71PYBmoBKcsrQj+U5qYOIzOFkS09igU//XY xifH24KiZXCJVq30NKS7r33Eo+/y6uY8DJNcqS6+KdocY96CTt1BxLjaefAFEXWC3MWv dB//u/plaYsv6mRTc4U5xsW7eeDQcLFNiNJLqL4huusGoXE0LBeIg779WO3OLq8HTZgU z5vw== X-Gm-Message-State: AOJu0YwWl0vkQfyQStodMCNLARxd2he6d2WJHtVBTqOSKtoDV1nFjmNc U/HalzWenAZaIqufhc/9LlzTImFqecrEE2/1Q+jfY1L8jgT6hqqRF/P+e1DpzLv4 X-Gm-Gg: AZuq6aKgLNP+bkjjrdoB4qAZId8b+UgTG2Oo/0paNUqr/Y/AYeQqgmCbMwF9PIIBLB2 ZYGfZFFAgkuH/aDmlx1Dw+Se6JGXPYxgjQJmaI8kiiEZTyVd1WsqqvfP2NwhJCsMwkz4TamtL/j XkfrodIxWuTdz1NzM3s05kPvMFuh180zHH5RxpHSwKsl/Uhh+ceXg5bjz3NwsCufcOKPbWAZV68 5TVbwBer/yikenZZ8yBCpUaFQSU62+lmVZKQtqwkO/6GcMha7Am/MLZwuUunJzUNKHvU8qs6bty 8RujrLEqdda289YfoijKhF29QG59/HAxL6ZooyMdreq1zgCmnxWIphGX47JahO2/TL7053U6Jq8 pTWVE+naVVCg1zezvkOZ2RfYGM8PUMUD5kUpF0TxYmzYTV4eLSvxlWh7w/pLsb0uJFpA7LMBwWc yKQCniM59KB6KHswJf96zCH9mR9bozAU/ePuLYA7GCs90zS5Yypk6iRg== X-Received: by 2002:a05:600c:a00f:b0:480:2521:4d92 with SMTP id 5b1f17b1804b1-4805cf6365bmr83782395e9.24.1769449411109; Mon, 26 Jan 2026 09:43:31 -0800 (PST) From: Ruslan Ruslichenko To: qemu-devel@nongnu.org Cc: qemu-arm@nongnu.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 Subject: [PATCH 07/27] hw/core/fdt_generic_util: implement main fdt parse routine Date: Mon, 26 Jan 2026 18:42:53 +0100 Message-ID: <20260126174313.1418150-8-ruslichenko.r@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260126174313.1418150-1-ruslichenko.r@gmail.com> References: <20260126174313.1418150-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::32b; envelope-from=ruslichenko.r@gmail.com; helo=mail-wm1-x32b.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: 1769449899701154100 Content-Type: text/plain; charset="utf-8" From: Ruslan Ruslichenko Implement main fdt_generic_create_machine() routine. As of now do the following: - parse each node and subnode in device tree - check node has correct compatible or device types - call fdt_init_qdev() which will eventually create device object. The MIT license of fdt_generic_util.c preserved as in original file from https://github.com/Xilinx/qemu.git repo. The license for fdt_generic_util.h derived from matching fdt_generic_util.c file. Signed-off-by: Ruslan Ruslichenko --- hw/core/fdt_generic_util.c | 242 +++++++++++++++++++++++++++++ include/hw/core/fdt_generic_util.h | 19 +++ 2 files changed, 261 insertions(+) create mode 100644 hw/core/fdt_generic_util.c create mode 100644 include/hw/core/fdt_generic_util.h diff --git a/hw/core/fdt_generic_util.c b/hw/core/fdt_generic_util.c new file mode 100644 index 0000000000..4338dc956b --- /dev/null +++ b/hw/core/fdt_generic_util.c @@ -0,0 +1,242 @@ +// SPDX-License-Identifier: MIT +/* + * Utility functions for fdt generic framework + * + * Copyright (c) 2009 Edgar E. Iglesias. + * Copyright (c) 2009 Michal Simek. + * Copyright (c) 2011 PetaLogix Qld Pty Ltd. + * Copyright (c) 2011 Peter A. G. Crosthwaite . + * + * Permission is hereby granted, free of charge, to any person obtaining a= copy + * of this software and associated documentation files (the "Software"), t= o deal + * in the Software without restriction, including without limitation the r= ights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or se= ll + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included= in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS= OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OT= HER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING= FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS = IN + * THE SOFTWARE. + */ + +#include "qemu/osdep.h" +#include "hw/core/fdt_generic_util.h" +#include "system/memory.h" +#include "system/address-spaces.h" +#include "hw/core/sysbus.h" +#include "qapi/error.h" +#include "qemu/error-report.h" +#include "system/system.h" +#include "system/reset.h" +#include "qemu/cutils.h" +#include "qemu/log.h" +#include "qemu/config-file.h" +#include "hw/core/boards.h" +#include "qemu/option.h" + +#ifndef FDT_GENERIC_UTIL_ERR_DEBUG +#define FDT_GENERIC_UTIL_ERR_DEBUG 3 +#endif +#define DB_PRINT(lvl, ...) do { \ + if (FDT_GENERIC_UTIL_ERR_DEBUG > (lvl)) { \ + qemu_log_mask(LOG_FDT, ": %s: ", __func__); \ + qemu_log_mask(LOG_FDT, ## __VA_ARGS__); \ + } \ +} while (0) + +#define DB_PRINT_NP(lvl, ...) do { \ + if (FDT_GENERIC_UTIL_ERR_DEBUG > (lvl)) { \ + qemu_log_mask(LOG_FDT, "%s", node_path); \ + DB_PRINT((lvl), ## __VA_ARGS__); \ + } \ +} while (0) + +/* FIXME: wrap direct calls into libfdt */ + +#include +#include + +static int fdt_generic_num_cpus; + +static int simple_bus_fdt_init(char *bus_node_path, FDTMachineInfo *fdti); + +FDTMachineInfo *fdt_generic_create_machine(void *fdt, qemu_irq *cpu_irq) +{ + char node_path[DT_PATH_LENGTH]; + FDTMachineInfo *fdti =3D fdt_init_new_fdti(fdt); + + fdti->irq_base =3D cpu_irq; + + /* parse the device tree */ + if (!qemu_devtree_get_root_node(fdt, node_path)) { + memory_region_transaction_begin(); + fdt_init_set_opaque(fdti, node_path, NULL); + simple_bus_fdt_init(node_path, fdti); + while (qemu_co_enter_next(fdti->cq, NULL)) { + ; + } + memory_region_transaction_commit(); + } else { + fprintf(stderr, "FDT: ERROR: cannot get root node from device tree= %s\n" + , node_path); + } + + /* FIXME: Populate these from DTS and create CPU clusters. */ + current_machine->smp.cores =3D fdt_generic_num_cpus; + current_machine->smp.cpus =3D fdt_generic_num_cpus; + current_machine->smp.max_cpus =3D fdt_generic_num_cpus; + + DB_PRINT(0, "FDT: Device tree scan complete\n"); + return fdti; +} + +struct FDTInitNodeArgs { + char *node_path; + char *parent_path; + FDTMachineInfo *fdti; +}; + +static int fdt_init_qdev(char *node_path, FDTMachineInfo *fdti, char *comp= at); + +static int check_compat(const char *prefix, const char *compat, + char *node_path, FDTMachineInfo *fdti) +{ + char *compat_prefixed =3D g_strconcat(prefix, compat, NULL); + const int done =3D !fdt_init_compat(node_path, fdti, compat_prefixed); + g_free(compat_prefixed); + return done; +} + +static void fdt_init_node(void *args) +{ + struct FDTInitNodeArgs *a =3D args; + char *node_path =3D a->node_path; + FDTMachineInfo *fdti =3D a->fdti; + g_free(a); + + simple_bus_fdt_init(node_path, fdti); + + const char *prop; + char *all_compats =3D NULL, *node_name; + char *device_type =3D NULL; + int prop_len; + + DB_PRINT_NP(1, "enter\n"); + + /* try instance binding first */ + node_name =3D qemu_devtree_get_node_name(fdti->fdt, node_path); + DB_PRINT_NP(1, "node with name: %s\n", node_name ? node_name : "(none)= "); + if (!node_name) { + printf("FDT: ERROR: nameless node: %s\n", node_path); + } + if (!fdt_init_inst_bind(node_path, fdti, node_name)) { + DB_PRINT_NP(0, "instance bind successful\n"); + goto exit; + } + + /* fallback to compatibility binding */ + prop =3D qemu_fdt_getprop(fdti->fdt, node_path, "compatible", + &prop_len, false, NULL); + all_compats =3D g_memdup2(prop, prop_len); + if (all_compats) { + char *compat =3D all_compats; + char * const end =3D &all_compats[prop_len - 1]; /* points to nul = */ + + while (compat < end) { + if (check_compat("compatible:", compat, node_path, fdti)) { + goto exit; + } + + if (!fdt_init_qdev(node_path, fdti, compat)) { + check_compat("postinit:", compat, node_path, fdti); + goto exit; + } + + /* Scan forward to the end of the current compat. */ + while (compat < end && *compat) { + ++compat; + } + + /* Replace nul with space for the debug printf below. */ + if (compat < end) { + *compat++ =3D ' '; + } + }; + } else { + DB_PRINT_NP(0, "no compatibility found\n"); + } + + /* + * Try to create the device using device_type property + * Not every device tree node has compatible property, so + * try with device_type. + */ + prop =3D qemu_fdt_getprop(fdti->fdt, node_path, + "device_type", &prop_len, false, NULL); + device_type =3D g_memdup2(prop, prop_len); + if (device_type) { + if (check_compat("device_type:", device_type, node_path, fdti)) { + goto exit; + } + + if (!fdt_init_qdev(node_path, fdti, device_type)) { + goto exit; + } + } + + if (all_compats) { + DB_PRINT_NP(0, "FDT: Unsupported peripheral invalidated - " + "compatibilities %s\n", all_compats); + qemu_fdt_setprop_string(fdti->fdt, node_path, "compatible", + "invalidated"); + } +exit: + + DB_PRINT_NP(1, "exit\n"); + + if (!fdt_init_has_opaque(fdti, node_path)) { + fdt_init_set_opaque(fdti, node_path, NULL); + } + g_free(node_path); + g_free(all_compats); + g_free(device_type); + return; +} + +static int simple_bus_fdt_init(char *node_path, FDTMachineInfo *fdti) +{ + int i; + int num_children =3D qemu_devtree_get_num_children(fdti->fdt, node_pat= h, + 1); + char **children; + + if (num_children =3D=3D 0) { + return 0; + } + children =3D qemu_devtree_get_children(fdti->fdt, node_path, 1); + + DB_PRINT_NP(num_children ? 0 : 1, "num child devices: %d\n", num_child= ren); + + for (i =3D 0; i < num_children; i++) { + struct FDTInitNodeArgs *init_args =3D g_malloc0(sizeof(*init_args)= ); + init_args->node_path =3D children[i]; + init_args->fdti =3D fdti; + qemu_coroutine_enter(qemu_coroutine_create(fdt_init_node, init_arg= s)); + } + + g_free(children); + return 0; +} + +static int fdt_init_qdev(char *node_path, FDTMachineInfo *fdti, char *comp= at) +{ + return 0; +} + diff --git a/include/hw/core/fdt_generic_util.h b/include/hw/core/fdt_gener= ic_util.h new file mode 100644 index 0000000000..e18c4f9c8b --- /dev/null +++ b/include/hw/core/fdt_generic_util.h @@ -0,0 +1,19 @@ +// SPDX-License-Identifier: MIT + +#ifndef FDT_GENERIC_UTIL_H +#define FDT_GENERIC_UTIL_H + +#include "qemu/help-texts.h" +#include "fdt_generic.h" +#include "system/memory.h" +#include "qom/object.h" + +/* + * create a fdt_generic machine. the top level cpu irqs are required for + * systems instantiating interrupt devices. The client is responsible for + * destroying the returned FDTMachineInfo (using fdt_init_destroy_fdti) + */ + +FDTMachineInfo *fdt_generic_create_machine(void *fdt, qemu_irq *cpu_irq); + +#endif /* FDT_GENERIC_UTIL_H */ --=20 2.43.0