From: "Dr. David Alan Gilbert" <dgilbert@redhat.com>
To: Daniel Henrique Barboza <danielhb413@gmail.com>
Cc: qemu-devel@nongnu.org, alistair.francis@wdc.com,
david@gibson.dropbear.id.au
Subject: Re: [PATCH for-7.2 v2 20/20] hmp, device_tree.c: add 'info fdt <property>' support
Date: Mon, 15 Aug 2022 19:38:28 +0100 [thread overview]
Message-ID: <YvqSpGchfWoQgqZd@work-vm> (raw)
In-Reply-To: <20220805093948.82561-21-danielhb413@gmail.com>
* Daniel Henrique Barboza (danielhb413@gmail.com) wrote:
> '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 = <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 = <0x71000003 0x0 0x0 0x0 0x10000000>
>
> Cc: Dr. David Alan Gilbert <dgilbert@redhat.com>
> Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
> ---
> 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
>
> {
> .name = "fdt",
> - .args_type = "nodepath:s",
> - .params = "nodepath",
> - .help = "show firmware device tree node given its path",
> + .args_type = "nodepath:s,propname:s?",
> + .params = "nodepath [propname]",
> + .help = "show firmware device tree node or property given its path",
> .cmd = hmp_info_fdt,
> },
Yeh that seems easier to me; from HMP:
Acked-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
> 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);
>
> /**
> diff --git a/monitor/hmp-cmds.c b/monitor/hmp-cmds.c
> index accde90380..df8493adc5 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 = qdict_get_str(qdict, "nodepath");
> + const char *propname = qdict_get_try_str(qdict, "propname");
> Error *err = NULL;
> - g_autoptr(HumanReadableText) info = qmp_x_query_fdt(nodepath, &err);
> + g_autoptr(HumanReadableText) info = NULL;
> +
> + info = qmp_x_query_fdt(nodepath, propname != NULL, propname, &err);
>
> 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);
> }
>
> -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");
> }
>
> -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");
>
> 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 902a7f680b..be7b7e297e 100644
> --- a/softmmu/device_tree.c
> +++ b/softmmu/device_tree.c
> @@ -785,23 +785,42 @@ static void fdt_format_node(GString *buf, int node, int depth,
> g_string_append_printf(buf, "%*s}\n", padding, "");
> }
>
> -HumanReadableText *qemu_fdt_qmp_query_fdt(const char *nodepath, Error **errp)
> +HumanReadableText *qemu_fdt_qmp_query_fdt(const char *nodepath,
> + bool has_propname,
> + const char *propname,
> + Error **errp)
> {
> g_autoptr(GString) buf = g_string_new("");
> - int node;
> + const struct fdt_property *prop = NULL;
> + void *fdt = current_machine->fdt;
> + int node, prop_size;
>
> - if (!current_machine->fdt) {
> + if (!fdt) {
> error_setg(errp, "Unable to find the machine FDT");
> return NULL;
> }
>
> - node = fdt_path_offset(current_machine->fdt, nodepath);
> + node = fdt_path_offset(fdt, nodepath);
> if (node < 0) {
> error_setg(errp, "node '%s' not found in FDT", nodepath);
> return NULL;
> }
>
> - fdt_format_node(buf, node, 0, nodepath);
> + if (!has_propname) {
> + fdt_format_node(buf, node, 0, nodepath);
> + } else {
> + g_autofree char *proppath = g_strdup_printf("%s/%s", nodepath,
> + propname);
> +
> + prop = 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);
> + }
>
> return human_readable_text_from_str(buf);
> }
> --
> 2.36.1
>
--
Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK
prev parent reply other threads:[~2022-08-15 18:41 UTC|newest]
Thread overview: 58+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-08-05 9:39 [PATCH for-7.2 v2 00/20] QMP/HMP: add 'dumpdtb' and 'info fdt' commands Daniel Henrique Barboza
2022-08-05 9:39 ` [PATCH for-7.2 v2 01/20] hw/arm: do not free machine->fdt in arm_load_dtb() Daniel Henrique Barboza
2022-08-08 3:23 ` David Gibson
2022-08-08 23:00 ` Daniel Henrique Barboza
2022-08-12 22:03 ` Daniel Henrique Barboza
2022-08-15 2:36 ` David Gibson
2022-08-05 9:39 ` [PATCH for-7.2 v2 02/20] hw/microblaze: set machine->fdt in microblaze_load_dtb() Daniel Henrique Barboza
2022-08-05 9:39 ` [PATCH for-7.2 v2 03/20] hw/nios2: set machine->fdt in nios2_load_dtb() Daniel Henrique Barboza
2022-08-05 9:39 ` [PATCH for-7.2 v2 04/20] hw/ppc: set machine->fdt in ppce500_load_device_tree() Daniel Henrique Barboza
2022-08-05 9:39 ` [PATCH for-7.2 v2 05/20] hw/ppc: set machine->fdt in bamboo_load_device_tree() Daniel Henrique Barboza
2022-08-05 9:39 ` [PATCH for-7.2 v2 06/20] hw/ppc: set machine->fdt in sam460ex_load_device_tree() Daniel Henrique Barboza
2022-08-05 9:39 ` [PATCH for-7.2 v2 07/20] hw/ppc: set machine->fdt in xilinx_load_device_tree() Daniel Henrique Barboza
2022-08-05 9:39 ` [PATCH for-7.2 v2 08/20] hw/ppc: set machine->fdt in pegasos2_machine_reset() Daniel Henrique Barboza
2022-08-05 9:39 ` [PATCH for-7.2 v2 09/20] hw/ppc: set machine->fdt in pnv_reset() Daniel Henrique Barboza
2022-08-05 11:03 ` Frederic Barrat
2022-08-05 12:31 ` Daniel Henrique Barboza
2022-08-08 3:25 ` David Gibson
2022-08-08 6:47 ` Cédric Le Goater
2022-08-08 7:13 ` Cédric Le Goater
2022-08-10 19:30 ` Daniel Henrique Barboza
2022-08-05 9:39 ` [PATCH for-7.2 v2 10/20] hw/ppc: set machine->fdt in spapr machine Daniel Henrique Barboza
2022-08-08 3:26 ` David Gibson
2022-08-12 22:23 ` Daniel Henrique Barboza
2022-08-15 2:37 ` David Gibson
2022-08-19 2:11 ` Alexey Kardashevskiy
2022-08-19 2:33 ` David Gibson
2022-08-19 9:42 ` Daniel Henrique Barboza
2022-08-22 3:05 ` David Gibson
2022-08-22 3:29 ` Alexey Kardashevskiy
2022-08-22 10:30 ` Daniel Henrique Barboza
2022-08-23 8:58 ` Alexey Kardashevskiy
2022-08-23 18:09 ` Daniel Henrique Barboza
2022-09-01 1:57 ` David Gibson
2022-08-05 9:39 ` [PATCH for-7.2 v2 11/20] hw/riscv: set machine->fdt in sifive_u_machine_init() Daniel Henrique Barboza
2022-08-07 22:46 ` Alistair Francis
2022-08-05 9:39 ` [PATCH for-7.2 v2 12/20] hw/riscv: set machine->fdt in spike_board_init() Daniel Henrique Barboza
2022-08-07 22:46 ` Alistair Francis
2022-08-05 9:39 ` [PATCH for-7.2 v2 13/20] hw/xtensa: set machine->fdt in xtfpga_init() Daniel Henrique Barboza
2022-08-05 9:39 ` [PATCH for-7.2 v2 14/20] qmp/hmp, device_tree.c: introduce dumpdtb Daniel Henrique Barboza
2022-08-07 23:02 ` Alistair Francis
2022-08-08 3:30 ` David Gibson
2022-08-15 17:36 ` Daniel Henrique Barboza
2022-08-15 18:31 ` Dr. David Alan Gilbert
2022-08-15 19:20 ` Daniel Henrique Barboza
2022-08-05 9:39 ` [PATCH for-7.2 v2 15/20] qmp/hmp, device_tree.c: introduce 'info fdt' command Daniel Henrique Barboza
2022-08-08 4:21 ` David Gibson
2022-08-15 22:48 ` Daniel Henrique Barboza
2022-08-18 2:46 ` David Gibson
2022-08-05 9:39 ` [PATCH for-7.2 v2 16/20] device_tree.c: support string props in fdt_format_node() Daniel Henrique Barboza
2022-08-08 4:36 ` David Gibson
2022-08-10 19:40 ` Daniel Henrique Barboza
2022-08-11 4:09 ` David Gibson
2022-08-05 9:39 ` [PATCH for-7.2 v2 17/20] device_tree.c: support remaining FDT prop types Daniel Henrique Barboza
2022-08-08 4:40 ` David Gibson
2022-08-05 9:39 ` [PATCH for-7.2 v2 18/20] device_node.c: enable 'info fdt' to print subnodes Daniel Henrique Barboza
2022-08-05 9:39 ` [PATCH for-7.2 v2 19/20] device_tree.c: add fdt_format_property() helper Daniel Henrique Barboza
2022-08-05 9:39 ` [PATCH for-7.2 v2 20/20] hmp, device_tree.c: add 'info fdt <property>' support Daniel Henrique Barboza
2022-08-15 18:38 ` Dr. David Alan Gilbert [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=YvqSpGchfWoQgqZd@work-vm \
--to=dgilbert@redhat.com \
--cc=alistair.francis@wdc.com \
--cc=danielhb413@gmail.com \
--cc=david@gibson.dropbear.id.au \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.