From nobody Mon Feb 9 11:28:48 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=1661525449; cv=none; d=zohomail.com; s=zohoarc; b=FbNKCUfIeUdzaHb6VGipLFd6NvvXoz4fMSw+XZlmu6PYkWLat5HfJ+/Vx1vdugx+DomTigF9VZHOvt6tywpEujgFnQiAfSH5um+P2x1yT1U8fZXDj0q7K4HAFXYRulAFV0y42oBGE3bg3o7BgLPEbv52qtRbwKNt7sKaAkUTQgQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1661525449; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=ANVbfUNhn0caCyzAkihc79NuPXOAYDT2141wO72Bs/o=; b=fGkM9S46SDpII16r31/QzmqIMpZcZZ6p18CA/ObP+KOZ2FloWI+6ZphwJPT/ayGFXCnftEQB1bVRHvh0aQKZTWVap4RnpWvaHYpULPbekC66z/E3VL+ed7RUSPsKZj0v343wy2ZCiF1XzJRvQ89/l7iSYms24TlN1k9yuA2OlQU= 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 1661525449073592.891588505007; Fri, 26 Aug 2022 07:50:49 -0700 (PDT) Received: from localhost ([::1]:60634 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oRafW-0007Qr-LJ for importer@patchew.org; Fri, 26 Aug 2022 10:50:46 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34080) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oRa4x-0000M2-0l; Fri, 26 Aug 2022 10:12:59 -0400 Received: from mail-oi1-x236.google.com ([2607:f8b0:4864:20::236]:39635) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oRa4t-00047M-My; Fri, 26 Aug 2022 10:12:58 -0400 Received: by mail-oi1-x236.google.com with SMTP id j5so2122142oih.6; Fri, 26 Aug 2022 07:12:55 -0700 (PDT) Received: from balboa.COMFAST ([177.189.45.98]) by smtp.gmail.com with ESMTPSA id z12-20020a056808064c00b00344aa3f17d9sm1087736oih.10.2022.08.26.07.12.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Aug 2022 07:12:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=ANVbfUNhn0caCyzAkihc79NuPXOAYDT2141wO72Bs/o=; b=IFVsTE2iZ47g5KwtTJjhpgnYUJcBXU5bWxUWfgjWIYUBfuYs6nv9X6HXBUwc2sBC5d rJ6wNz2a5fLGkoVWaLYu+Xi+PyiecwaekpFI8t2YVlWYa8CL+Iausx8st90CTfQId+V0 JxceqD+F9vP1X8mb3Mi5L+hE4rXTe/GkWzLBnrHLX9fA3LhaComjP2l6Tc0JPj9ohw/9 jQRvRFJ5gW/RQAEnWEYzyuHOT33t//hjlPMmoRIVue4zhf0fkn68nnmEf2KQjlVR4I2V 6irz7fAP4R2uDkC+ispLm3pBDYeJgZDeJjzVHMa09KPzfYkY3n28O6dc/j9FV+PP08f4 8oBA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=ANVbfUNhn0caCyzAkihc79NuPXOAYDT2141wO72Bs/o=; b=0JUV8QQXiUP1m+AVhO9kDp54ePPyy2fQqJYBIvefFyI0CfjUvEgqqhElv7bG1MB9Ze TYV9xeYByc5msN7/IT2Ben1IYVeuLBTbWE9Cogk0DGhnm4VKN7DGLVoLZ2TtU8xj6p65 9SLvsfr+UA2jqDUC0KxNcfxTBqcpOzXrOd7wPC/LO4ox325g9y3i/S7HxfbLOtQYaJnq KV6NxZO/ZThCILz2yuV21M1nOiUAa693v7xsb7+vRmyfJzJZdyPAYBjIkT2zGLQ0UqDU S03FzlEyb//JB4qZn6wYh4n5HJvtA6w2Z7QWR10YqrCb0LDvKm6kAWze8j85lQu0vadS in3A== X-Gm-Message-State: ACgBeo0XOJeU82FnE0aBXxT5SiYKKArqB2VAQrSI4jNpeM4EgBVPvP5b Gt4rlOAYj11wqoqB4UyAlABM4xWbrkg= X-Google-Smtp-Source: AA6agR4CCGoQWNPZPo2tZI6DopRhNaiDWfNvdL9R2HF3ItNNfnYSSLWQ5eGUK8pHXsent04uAh6Zmg== X-Received: by 2002:a05:6808:ec3:b0:2ec:8fcb:1d4a with SMTP id q3-20020a0568080ec300b002ec8fcb1d4amr1741675oiv.162.1661523173961; Fri, 26 Aug 2022 07:12:53 -0700 (PDT) From: Daniel Henrique Barboza To: qemu-devel@nongnu.org Cc: qemu-ppc@nongnu.org, clg@kaod.org, david@gibson.dropbear.id.au, alistair.francis@wdc.com, Daniel Henrique Barboza , "Dr . David Alan Gilbert" Subject: [PATCH for-7.2 v4 20/21] hmp, device_tree.c: add 'info fdt ' support Date: Fri, 26 Aug 2022 11:11:49 -0300 Message-Id: <20220826141150.7201-21-danielhb413@gmail.com> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220826141150.7201-1-danielhb413@gmail.com> References: <20220826141150.7201-1-danielhb413@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=2607:f8b0:4864:20::236; envelope-from=danielhb413@gmail.com; helo=mail-oi1-x236.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 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_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1661525450076100001 Content-Type: text/plain; charset="utf-8" 'info fdt' is only able to print full nodes so far. It would be good to be able to also print single properties, since ometimes we just want to verify a single value from the FDT. libfdt does not have support to find a property given its full path, but it does have a way to return a fdt_property given a prop name and its subnode. Add a new optional 'propname' parameter to x-query-fdt to specify the property of a given node. If it's present, we'll proceed to find the node as usual but, instead of printing the node, we'll attempt to find the property and print it standalone. After this change, if an user wants to print just the value of 'cpu' inside /cpu/cpu-map(...) from an ARM FDT, we can do it: (qemu) info fdt /cpus/cpu-map/socket0/cluster0/core0 cpu /cpus/cpu-map/socket0/cluster0/core0/cpu =3D <0x8001>; Or the 'ibm,my-dma-window' from the v-scsi device inside the pSeries FDT: (qemu) info fdt /vdevice/v-scsi@71000003 ibm,my-dma-window /vdevice/v-scsi@71000003/ibm,my-dma-window =3D <0x71000003 0x0 0x0 0x0 0x10= 000000>; Cc: Dr. David Alan Gilbert Acked-by: Dr. David Alan Gilbert Signed-off-by: Daniel Henrique Barboza --- hmp-commands-info.hx | 9 +++++---- include/sysemu/device_tree.h | 2 ++ monitor/hmp-cmds.c | 5 ++++- monitor/qmp-cmds.c | 8 +++++--- qapi/machine.json | 4 +++- softmmu/device_tree.c | 29 ++++++++++++++++++++++++----- 6 files changed, 43 insertions(+), 14 deletions(-) diff --git a/hmp-commands-info.hx b/hmp-commands-info.hx index 743b48865d..17d6ee4d30 100644 --- a/hmp-commands-info.hx +++ b/hmp-commands-info.hx @@ -924,13 +924,14 @@ ERST =20 { .name =3D "fdt", - .args_type =3D "nodepath:s", - .params =3D "nodepath", - .help =3D "show firmware device tree node given its path", + .args_type =3D "nodepath:s,propname:s?", + .params =3D "nodepath [propname]", + .help =3D "show firmware device tree node or property given = its path", .cmd =3D hmp_info_fdt, }, =20 SRST ``info fdt`` - Show a firmware device tree node given its path. Requires libfdt. + Show a firmware device tree node or property given its path. + Requires libfdt. ERST diff --git a/include/sysemu/device_tree.h b/include/sysemu/device_tree.h index 057d13e397..551a02dee2 100644 --- a/include/sysemu/device_tree.h +++ b/include/sysemu/device_tree.h @@ -140,6 +140,8 @@ int qemu_fdt_add_path(void *fdt, const char *path); void qemu_fdt_dumpdtb(void *fdt, int size); void qemu_fdt_qmp_dumpdtb(const char *filename, Error **errp); HumanReadableText *qemu_fdt_qmp_query_fdt(const char *nodepath, + bool has_propname, + const char *propname, Error **errp); =20 /** diff --git a/monitor/hmp-cmds.c b/monitor/hmp-cmds.c index 93a4103afa..320204e982 100644 --- a/monitor/hmp-cmds.c +++ b/monitor/hmp-cmds.c @@ -2488,8 +2488,11 @@ void hmp_dumpdtb(Monitor *mon, const QDict *qdict) void hmp_info_fdt(Monitor *mon, const QDict *qdict) { const char *nodepath =3D qdict_get_str(qdict, "nodepath"); + const char *propname =3D qdict_get_try_str(qdict, "propname"); Error *err =3D NULL; - g_autoptr(HumanReadableText) info =3D qmp_x_query_fdt(nodepath, &err); + g_autoptr(HumanReadableText) info =3D NULL; + + info =3D qmp_x_query_fdt(nodepath, propname !=3D NULL, propname, &err); =20 if (hmp_handle_error(mon, err)) { return; diff --git a/monitor/qmp-cmds.c b/monitor/qmp-cmds.c index db2c6aa7da..ca2a96cdf7 100644 --- a/monitor/qmp-cmds.c +++ b/monitor/qmp-cmds.c @@ -604,9 +604,10 @@ void qmp_dumpdtb(const char *filename, Error **errp) return qemu_fdt_qmp_dumpdtb(filename, errp); } =20 -HumanReadableText *qmp_x_query_fdt(const char *nodepath, Error **errp) +HumanReadableText *qmp_x_query_fdt(const char *nodepath, bool has_propname, + const char *propname, Error **errp) { - return qemu_fdt_qmp_query_fdt(nodepath, errp); + return qemu_fdt_qmp_query_fdt(nodepath, has_propname, propname, errp); } #else void qmp_dumpdtb(const char *filename, Error **errp) @@ -614,7 +615,8 @@ void qmp_dumpdtb(const char *filename, Error **errp) error_setg(errp, "dumpdtb requires libfdt"); } =20 -HumanReadableText *qmp_x_query_fdt(const char *nodepath, Error **errp) +HumanReadableText *qmp_x_query_fdt(const char *nodepath, bool has_propname, + const char *propname, Error **errp) { error_setg(errp, "this command requires libfdt"); =20 diff --git a/qapi/machine.json b/qapi/machine.json index 96cff541ca..c15ce60f46 100644 --- a/qapi/machine.json +++ b/qapi/machine.json @@ -1688,6 +1688,7 @@ # Query for FDT element (node or property). Requires 'libfdt'. # # @nodepath: the path of the FDT node to be retrieved +# @propname: name of the property inside the node # # Features: # @unstable: This command is meant for debugging. @@ -1697,6 +1698,7 @@ # Since: 7.2 ## { 'command': 'x-query-fdt', - 'data': { 'nodepath': 'str' }, + 'data': { 'nodepath': 'str', + '*propname': 'str' }, 'returns': 'HumanReadableText', 'features': [ 'unstable' ] } diff --git a/softmmu/device_tree.c b/softmmu/device_tree.c index 70a011495d..ad2386295b 100644 --- a/softmmu/device_tree.c +++ b/softmmu/device_tree.c @@ -823,23 +823,42 @@ static void fdt_format_node(GString *buf, int node, i= nt depth, g_string_append_printf(buf, "%*s};\n", padding, ""); } =20 -HumanReadableText *qemu_fdt_qmp_query_fdt(const char *nodepath, Error **er= rp) +HumanReadableText *qemu_fdt_qmp_query_fdt(const char *nodepath, + bool has_propname, + const char *propname, + Error **errp) { g_autoptr(GString) buf =3D g_string_new(""); - int node; + const struct fdt_property *prop =3D NULL; + void *fdt =3D current_machine->fdt; + int node, prop_size; =20 - if (!current_machine->fdt) { + if (!fdt) { error_setg(errp, "Unable to find the machine FDT"); return NULL; } =20 - node =3D fdt_path_offset(current_machine->fdt, nodepath); + node =3D fdt_path_offset(fdt, nodepath); if (node < 0) { error_setg(errp, "node '%s' not found in FDT", nodepath); return NULL; } =20 - fdt_format_node(buf, node, 0, nodepath); + if (!has_propname) { + fdt_format_node(buf, node, 0, nodepath); + } else { + g_autofree char *proppath =3D g_strdup_printf("%s/%s", nodepath, + propname); + + prop =3D fdt_get_property(fdt, node, propname, &prop_size); + if (!prop) { + error_setg(errp, "property '%s' not found in node '%s' in FDT", + propname, nodepath); + return NULL; + } + + fdt_format_property(buf, proppath, prop->data, prop_size, 0); + } =20 return human_readable_text_from_str(buf); } --=20 2.37.2