From nobody Sun Apr 12 02:49:29 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=1771511839; cv=none; d=zohomail.com; s=zohoarc; b=eSz8z4V3co9fWuaGVBj9Fe06LzhyriAMGRc15iCP71Mk32ZHgTkJXxMtNbRLTbzP+yMCur0xNyON+WzNY1pfyybR0dW6raryc8JSH5vwC5AyuuAKY0TOqT98tjXrEbn9dleYC0pVhItsiNxjF02RTCEE8fOZReqsIxES1njukEk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1771511839; 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=8p7OUmEJMiBfURYJ4JeOsw/eoH+9F0GGVOCzGcWPVSw=; b=k4mdy8KkrooWFN8o6/clNvo3sXO+K9WKdRvIymDPKEr4ESfrWgtq0IaKTtjTRoxHloGEjDqXQUEC+c1UaB8GthfGjXBc2gUXIar1xqWQXa2wAtdA4vff3VdwGP0AkOKofytzwNjJ8+TSvrDlrUL2CjZ0ZbHFogtuEdXseeZKMYo= 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 1771511839394187.62317988338611; Thu, 19 Feb 2026 06:37:19 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vt57I-0000Bn-U0; Thu, 19 Feb 2026 09:34:56 -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 1vt57G-0000AP-Sj for qemu-devel@nongnu.org; Thu, 19 Feb 2026 09:34:54 -0500 Received: from mail-wr1-x433.google.com ([2a00:1450:4864:20::433]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1vt57F-0002zH-2C for qemu-devel@nongnu.org; Thu, 19 Feb 2026 09:34:54 -0500 Received: by mail-wr1-x433.google.com with SMTP id ffacd0b85a97d-4359a316d89so962732f8f.0 for ; Thu, 19 Feb 2026 06:34:52 -0800 (PST) Received: from thinkpad-t470s.. (93-143-129-182.adsl.net.t-com.hr. [93.143.129.182]) by smtp.googlemail.com with ESMTPSA id ffacd0b85a97d-43796abd259sm52022770f8f.24.2026.02.19.06.34.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Feb 2026 06:34:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1771511691; x=1772116491; 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=8p7OUmEJMiBfURYJ4JeOsw/eoH+9F0GGVOCzGcWPVSw=; b=IByYDXE4AntdZsLnlphGtcsQ/AdULndKjN53Qt+OnExaoA20+nBZlLVhOIF97EZL7r 5BrTKlCy3WICV+VnQUwPgr4b8dJ+jO1o2gHCZqIa1ah/FxiCaE5VuuZKr5jLX8+wUHHA /6nfHemXfpVlHfnqeXVbWjX04w7XJKghBC01A9aJmiXnwEPhVDiJ/VrvYW3CVv73SDtn wXIVV+qGwoLSuy5fZJX4B34wNxAfibYyzz33tI+OAISnbA7HccMF5pMEgFH+S3nZVO72 2efDrIhazmWeRlYdXWmVKpnNbvXl5jc2iJ95TL9oploTxknVCXLPdfpzDqrNwD5TpkHx 2VoA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1771511691; x=1772116491; 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=8p7OUmEJMiBfURYJ4JeOsw/eoH+9F0GGVOCzGcWPVSw=; b=Cp84c2tDUT+Ib2W2nM2Qxh3dJ59COsxPJX9SMUXrvkjvGVwS4hAfAcLBNZFDobzA57 DtJekQAoHmsov1283Psvar++Uv45eN7byaGp5/uZs7puEPwFuNdHXkQ29pWNdAWVwrk2 FbeAyulZRkYmDsigqH6jI8f9YchSKWSBEw4Iu0wD12aky7HFWT/ll04XX+ZIiGr2JX5Z izYr0zfKPZUe+PD/bSOUQ/eX7qD51QzrKQMspGJnIP4oPvtsYvyuc2bjqMYMaX8vq8NN +03XcxO0QSieExrDB0joDU3dC9o7BgIoiO14uATg1lIX6NZuUO+ALuUj2tIt9OjfaWyd HGfg== X-Gm-Message-State: AOJu0YwOUjS6iBr/3G3sHzcGDUeuDbOCuoxxa85WQiAdi+m7f9lrg3MF 49/UbxisBVCpnRs6DPaD+fkeW9A2zB/durgFnOwwD7Pi3/t60m9o24NxfEA42QPi X-Gm-Gg: AZuq6aK0IEz7nBWWgY6nxkA0jGuvZlESWN39j+tGBxqpXVp2z65UTGy7n6ITybHD/Y5 n4gyifh6nI/Wvd5ln+2UWFmQzX3qbGgEjtAECJXhZIIinfzqd/tQUlrsADbbulN1Rh4KgyFYlRT hW8qJV/l/LW9VNZ2lgI+Li6R9ivbyJ8qg4MiUIdfrs1Lh48qg6kZVUKWY6A3Uq1rpJsjlV4Ff7M mHw5MtPMWEeN7J9/KwBt4jenHXoleAoe66eZ9vHX4LdjorYmr7y3W1YgMXsLE2Z/lpIRGzGg+su v0AJMdGy0olcOQM+3zLdOWEBQc1INfj/4kOikT+IEBeeLzZANhrPcQ+7Ko+EIPH4vwAt8p+Suzb L6eq5fH/D24tkSsJxQ8ak5rPRt79Aijrrpc6zeflPAz4ZdTu/Bpz0boYEh0x6VJ+CMo4hK7w32U 37moPLRxJAuPjN/+fBHrPxAuv07J1G3qna4Y+BiKbgFhWH4Dy8syTcFOOLLaELGGMiRXLY X-Received: by 2002:a05:6000:40dc:b0:437:6839:d5e with SMTP id ffacd0b85a97d-43958df370bmr9925523f8f.13.1771511690774; Thu, 19 Feb 2026 06:34:50 -0800 (PST) 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 v2 10/33] hw/core/fdt_generic_util: initilize qdev properties from fdt Date: Thu, 19 Feb 2026 15:33:09 +0100 Message-ID: <20260219143332.3316679-11-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: 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::433; envelope-from=ruslichenko.r@gmail.com; helo=mail-wr1-x433.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: 1771511841592158500 Content-Type: text/plain; charset="utf-8" From: Ruslan Ruslichenko The patch adds possibility to read and parse device tree node properties and set them to newly created object. Signed-off-by: Ruslan Ruslichenko --- hw/core/fdt_generic_util.c | 222 +++++++++++++++++++++++++++++++++++++ 1 file changed, 222 insertions(+) diff --git a/hw/core/fdt_generic_util.c b/hw/core/fdt_generic_util.c index 8131511e70..2a3862b9ac 100644 --- a/hw/core/fdt_generic_util.c +++ b/hw/core/fdt_generic_util.c @@ -40,7 +40,9 @@ #include "qemu/config-file.h" #include "hw/core/boards.h" #include "qemu/option.h" +#include "hw/core/qdev-properties.h" #include "hw/cpu/cluster.h" +#include "qobject/qlist.h" =20 #ifndef FDT_GENERIC_UTIL_ERR_DEBUG #define FDT_GENERIC_UTIL_ERR_DEBUG 3 @@ -342,6 +344,25 @@ static Object *fdt_create_from_compat(const char *comp= at, char **dev_type) return ret; } =20 +/*FIXME: roll into device tree functionality */ + +static inline uint64_t get_int_be(const void *p, int len) +{ + switch (len) { + case 1: + return *((uint8_t *)p); + case 2: + return be16_to_cpu(*((uint16_t *)p)); + case 4: + return be32_to_cpu(*((uint32_t *)p)); + case 8: + return be32_to_cpu(*((uint64_t *)p)); + default: + fprintf(stderr, "unsupported integer length\n"); + abort(); + } +} + /* * Error handler for device creation failure. * @@ -369,10 +390,185 @@ static void fdt_dev_error(FDTMachineInfo *fdti, char= *node_path, char *compat) } } =20 +static void fdt_init_qdev_link_prop(Object *obj, ObjectProperty *p, + FDTMachineInfo *fdti, + const char *node_path, + const QEMUDevtreeProp *prop) +{ + int len =3D prop->len; + const void *val =3D prop->value; + const char *propname =3D prop->name; + + Object *linked_dev, *proxy; + char target_node_path[DT_PATH_LENGTH]; + g_autofree char *propname_target =3D g_strconcat(propname, "-target", = NULL); + Error *errp =3D NULL; + + if (qemu_devtree_get_node_by_phandle(fdti->fdt, target_node_path, + get_int_be(val, len))) { + abort(); + } + + while (!fdt_init_has_opaque(fdti, target_node_path)) { + fdt_init_yield(fdti); + } + linked_dev =3D fdt_init_get_opaque(fdti, target_node_path); + + proxy =3D linked_dev ? object_property_get_link(linked_dev, + propname_target, + &errp) : NULL; + if (!errp && proxy) { + DB_PRINT_NP(0, "detected proxy object for %s connection\n", propna= me); + linked_dev =3D proxy; + } + + if (!linked_dev) { + linked_dev =3D object_resolve_link(obj, propname, + target_node_path, &errp); + if (!linked_dev) { + return; + } + } + + errp =3D NULL; + object_property_set_link(obj, propname, linked_dev, &errp); + if (errp) { + /* Unable to set the property, maybe it is a memory alias? */ + MemoryRegion *alias_mr; + int offset =3D len / 2; + int region =3D 0; + + if (len > 4) { + region =3D get_int_be(val + offset, len - offset); + } + + alias_mr =3D sysbus_mmio_get_region(SYS_BUS_DEVICE(linked_dev), re= gion); + + object_property_set_link(obj, propname, OBJECT(alias_mr), &error_a= bort); + + } + + DB_PRINT_NP(0, "set link %s\n", propname); +} + +static void fdt_init_qdev_scalar_prop(Object *obj, ObjectProperty *p, + FDTMachineInfo *fdti, + const char *node_path, + const QEMUDevtreeProp *prop) +{ + const char *propname =3D trim_vendor(prop->name); + const void *val =3D prop->value; + int len =3D prop->len; + + /* FIXME: handle generically using accessors and stuff */ + if (!strncmp(p->type, "link", 4)) { + fdt_init_qdev_link_prop(obj, p, fdti, node_path, prop); + return; + } + + if (!strcmp(p->type, "uint8") || !strcmp(p->type, "uint16") || + !strcmp(p->type, "uint32") || !strcmp(p->type, "uint64") || + !strcmp(p->type, "int8") || !strcmp(p->type, "int16") || + !strcmp(p->type, "int32") || !strcmp(p->type, "int64")) { + object_property_set_int(obj, propname, + get_int_be(val, len), &error_abort); + DB_PRINT_NP(0, "set property %s to 0x%llx\n", propname, + (unsigned long long)get_int_be(val, len)); + return; + } + + if (!strcmp(p->type, "boolean") || !strcmp(p->type, "bool")) { + object_property_set_bool(obj, propname, + !!get_int_be(val, len), &error_abort); + DB_PRINT_NP(0, "set property %s to %s\n", propname, + get_int_be(val, len) ? "true" : "false"); + return; + } + + if (!strcmp(p->type, "string") || !strcmp(p->type, "str")) { + object_property_set_str(obj, propname, + (const char *)val, &error_abort); + DB_PRINT_NP(0, "set property %s to %s\n", propname, (const char *)= val); + return; + } + + DB_PRINT_NP(0, "WARNING: property is of unknown type\n"); +} + +static size_t fdt_array_elem_len(FDTMachineInfo *fdti, + const char *node_path, + const char *propname) +{ + g_autofree char *elem_cells_propname =3D NULL; + Error *err =3D NULL; + uint32_t elem_cells; + + /* + * Default element size to 1 uint32_t cell, unless it is explicitly + * given in the same FDT node (not inherited). + */ + elem_cells_propname =3D g_strconcat("#", propname, "-cells", NULL); + elem_cells =3D qemu_fdt_getprop_cell(fdti->fdt, node_path, + elem_cells_propname, 0, &err); + + return (err ? 1 : elem_cells) * 4; +} + +static void fdt_init_qdev_array_prop(Object *obj, + FDTMachineInfo *fdti, + const char *node_path, + QEMUDevtreeProp *prop) +{ + const char *propname =3D trim_vendor(prop->name); + int nr =3D prop->len; + uint32_t elem_len; + QList *qlist =3D qlist_new(); + const char *prop_type; + const void *prop_value =3D prop->value; + + if (!prop->value || !nr) { + return; + } + + elem_len =3D fdt_array_elem_len(fdti, node_path, propname); + if (nr % elem_len) { + return; + } + + nr /=3D elem_len; + + prop_type =3D qdev_prop_get_array_elem_type(DEVICE(obj), propname); + if (!prop_type) { + DB_PRINT_NP(0, "fail to get property array elem type\n"); + return; + } + + while (nr--) { + if (!strcmp(prop_type, "uint8") || !strcmp(prop_type, "uint16") || + !strcmp(prop_type, "uint32") || !strcmp(prop_type, "uint64") || + !strcmp(prop_type, "int8") || !strcmp(prop_type, "int16") || + !strcmp(prop_type, "int32") || !strcmp(prop_type, "int64")) { + qlist_append_int(qlist, get_int_be(prop_value, elem_len)); + } else if (!strcmp(prop_type, "boolean") || !strcmp(prop_type, "bo= ol")) { + qlist_append_bool(qlist, !!get_int_be(prop_value, elem_len)); + } else if (!strcmp(prop_type, "string") || !strcmp(prop_type, "str= ")) { + qlist_append_str(qlist, (const char *)prop_value); + } + + prop_value +=3D elem_len; + + /* TBD: add link type support */ + } + + qdev_prop_set_array(DEVICE(obj), propname, qlist); + DB_PRINT_NP(0, "set property %s propname to \n", propname); +} + static int fdt_init_qdev(char *node_path, FDTMachineInfo *fdti, char *comp= at) { Object *dev, *parent; char *dev_type =3D NULL; + QEMUDevtreeProp *prop, *props; char parent_node_path[DT_PATH_LENGTH]; =20 if (!compat) { @@ -460,7 +656,33 @@ static int fdt_init_qdev(char *node_path, FDTMachineIn= fo *fdti, char *compat) } fdt_init_set_opaque(fdti, node_path, dev); =20 + props =3D qemu_devtree_get_props(fdti->fdt, node_path); + for (prop =3D props; prop->name; prop++) { + const char *propname =3D trim_vendor(prop->name); + ObjectProperty *p =3D NULL; + + p =3D object_property_find(OBJECT(dev), propname); + if (p) { + DB_PRINT_NP(1, "matched property: %s of type %s, len %d\n", + propname, p->type, prop->len); + } + if (!p) { + continue; + } + + if (!strcmp(p->type, "list")) { + fdt_init_qdev_array_prop(dev, fdti, node_path, prop); + } + + if (!strcmp(propname, "type")) { + continue; + } + + fdt_init_qdev_scalar_prop(OBJECT(dev), p, fdti, node_path, prop); + } + g_free(dev_type); + g_free(props); =20 return 0; } --=20 2.43.0