From: Sakari Ailus <sakari.ailus@linux.intel.com> To: Petr Mladek <pmladek@suse.com>, linux-kernel@vger.kernel.org, rafael@kernel.org Cc: Andy Shevchenko <andriy.shevchenko@linux.intel.com>, linux-acpi@vger.kernel.org, devicetree@vger.kernel.org, Rob Herring <robh@kernel.org>, Heikki Krogerus <heikki.krogerus@linux.intel.com> Subject: [PATCH v4 06/11] device property: Add a function to obtain a node's prefix Date: Mon, 2 Sep 2019 11:32:35 +0300 Message-ID: <20190902083240.20367-7-sakari.ailus@linux.intel.com> (raw) In-Reply-To: <20190902083240.20367-1-sakari.ailus@linux.intel.com> The prefix is used for printing purpose before a node, and it also works as a separator between two nodes. Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com> Acked-by: Rob Herring <robh@kernel.org> (for OF) --- drivers/acpi/property.c | 22 ++++++++++++++++++++++ drivers/base/property.c | 12 ++++++++++++ drivers/base/swnode.c | 26 ++++++++++++++++++++++++++ drivers/of/property.c | 10 ++++++++++ include/linux/fwnode.h | 2 ++ include/linux/property.h | 1 + 6 files changed, 73 insertions(+) diff --git a/drivers/acpi/property.c b/drivers/acpi/property.c index 5a9397a390f41..466239d3bb345 100644 --- a/drivers/acpi/property.c +++ b/drivers/acpi/property.c @@ -1336,6 +1336,27 @@ static const char *acpi_fwnode_get_name(const struct fwnode_handle *fwnode) return acpi_device_bid(adev); } +static const char * +acpi_fwnode_get_name_prefix(const struct fwnode_handle *fwnode) +{ + struct fwnode_handle *parent; + + /* Is this the root node? */ + parent = fwnode_get_parent(fwnode); + if (!parent) + return ""; + + /* Is this 2nd node from the root? */ + parent = fwnode_get_next_parent(parent); + if (!parent) + return ""; + + fwnode_handle_put(parent); + + /* ACPI device or data node. */ + return "."; +} + static struct fwnode_handle * acpi_fwnode_get_parent(struct fwnode_handle *fwnode) { @@ -1377,6 +1398,7 @@ acpi_fwnode_device_get_match_data(const struct fwnode_handle *fwnode, .get_next_child_node = acpi_get_next_subnode, \ .get_named_child_node = acpi_fwnode_get_named_child_node, \ .get_name = acpi_fwnode_get_name, \ + .get_name_prefix = acpi_fwnode_get_name_prefix, \ .get_reference_args = acpi_fwnode_get_reference_args, \ .graph_get_next_endpoint = \ acpi_graph_get_next_endpoint, \ diff --git a/drivers/base/property.c b/drivers/base/property.c index 0ce5052a7f9b7..9563db780e039 100644 --- a/drivers/base/property.c +++ b/drivers/base/property.c @@ -567,6 +567,18 @@ const char *fwnode_get_name(const struct fwnode_handle *fwnode) return fwnode_call_ptr_op(fwnode, get_name); } +/** + * fwnode_get_name_prefix - Return the prefix of node for printing purposes + * @fwnode: The firmware node + * + * Returns the prefix of a node, intended to be printed right before the node. + * The prefix works also as a separator between the nodes. + */ +const char *fwnode_get_name_prefix(const struct fwnode_handle *fwnode) +{ + return fwnode_call_ptr_op(fwnode, get_name_prefix); +} + /** * fwnode_get_parent - Return parent firwmare node * @fwnode: Firmware whose parent is retrieved diff --git a/drivers/base/swnode.c b/drivers/base/swnode.c index a4a0f5b80bad3..9cc17baa193fc 100644 --- a/drivers/base/swnode.c +++ b/drivers/base/swnode.c @@ -534,6 +534,31 @@ software_node_get_name(const struct fwnode_handle *fwnode) return kobject_name(&swnode->kobj); } +static const char * +software_node_get_name_prefix(const struct fwnode_handle *fwnode) +{ + struct fwnode_handle *parent; + const char *prefix; + + parent = fwnode_get_parent(fwnode); + if (!parent) + return ""; + + parent = fwnode_get_next_parent(parent); + if (!parent) + return "/"; + + /* Figure out the prefix from the parents. */ + while (is_software_node(parent)) + parent = fwnode_get_next_parent(parent); + + prefix = fwnode_get_name_prefix(parent); + fwnode_handle_put(parent); + + /* Guess something if prefix was NULL. */ + return prefix ?: "/"; +} + static struct fwnode_handle * software_node_get_parent(const struct fwnode_handle *fwnode) { @@ -635,6 +660,7 @@ static const struct fwnode_operations software_node_ops = { .property_read_int_array = software_node_read_int_array, .property_read_string_array = software_node_read_string_array, .get_name = software_node_get_name, + .get_name_prefix = software_node_get_name_prefix, .get_parent = software_node_get_parent, .get_next_child_node = software_node_get_next_child, .get_named_child_node = software_node_get_named_child_node, diff --git a/drivers/of/property.c b/drivers/of/property.c index 5bed634551ea6..e8202f61a5d93 100644 --- a/drivers/of/property.c +++ b/drivers/of/property.c @@ -877,6 +877,15 @@ static const char *of_fwnode_get_name(const struct fwnode_handle *fwnode) return kbasename(to_of_node(fwnode)->full_name); } +static const char *of_fwnode_get_name_prefix(const struct fwnode_handle *fwnode) +{ + /* Root needs no prefix here (its name is "/"). */ + if (!to_of_node(fwnode)->parent) + return ""; + + return "/"; +} + static struct fwnode_handle * of_fwnode_get_parent(const struct fwnode_handle *fwnode) { @@ -999,6 +1008,7 @@ const struct fwnode_operations of_fwnode_ops = { .property_read_int_array = of_fwnode_property_read_int_array, .property_read_string_array = of_fwnode_property_read_string_array, .get_name = of_fwnode_get_name, + .get_name_prefix = of_fwnode_get_name_prefix, .get_parent = of_fwnode_get_parent, .get_next_child_node = of_fwnode_get_next_child_node, .get_named_child_node = of_fwnode_get_named_child_node, diff --git a/include/linux/fwnode.h b/include/linux/fwnode.h index c331e0ef31e80..755709703fe6f 100644 --- a/include/linux/fwnode.h +++ b/include/linux/fwnode.h @@ -57,6 +57,7 @@ struct fwnode_reference_args { * @property_read_string_array: Read an array of string properties. Return zero * on success, a negative error code otherwise. * @get_name: Return the name of an fwnode. + * @get_name_prefix: Get a prefix for a node (for printing purposes). * @get_parent: Return the parent of an fwnode. * @get_next_child_node: Return the next child node in an iteration. * @get_named_child_node: Return a child node with a given name. @@ -84,6 +85,7 @@ struct fwnode_operations { const char *propname, const char **val, size_t nval); const char *(*get_name)(const struct fwnode_handle *fwnode); + const char *(*get_name_prefix)(const struct fwnode_handle *fwnode); struct fwnode_handle *(*get_parent)(const struct fwnode_handle *fwnode); struct fwnode_handle * (*get_next_child_node)(const struct fwnode_handle *fwnode, diff --git a/include/linux/property.h b/include/linux/property.h index ebc5e2016bb66..c40fcfc5774a7 100644 --- a/include/linux/property.h +++ b/include/linux/property.h @@ -81,6 +81,7 @@ struct fwnode_handle *fwnode_find_reference(const struct fwnode_handle *fwnode, unsigned int index); const char *fwnode_get_name(const struct fwnode_handle *fwnode); +const char *fwnode_get_name_prefix(const struct fwnode_handle *fwnode); struct fwnode_handle *fwnode_get_parent(const struct fwnode_handle *fwnode); struct fwnode_handle *fwnode_get_next_parent( struct fwnode_handle *fwnode); -- 2.20.1
next prev parent reply index Thread overview: 36+ messages / expand[flat|nested] mbox.gz Atom feed top 2019-09-02 8:32 [PATCH v4 00/11] Device property improvements, add %pfw format specifier Sakari Ailus 2019-09-02 8:32 ` [PATCH v4 01/11] software node: Get reference to parent swnode in get_parent op Sakari Ailus 2019-09-02 10:10 ` Andy Shevchenko 2019-09-02 8:32 ` [PATCH v4 02/11] software node: Make argument to to_software_node const Sakari Ailus 2019-09-02 8:32 ` [PATCH v4 03/11] device property: Move fwnode_get_parent() up Sakari Ailus 2019-09-02 10:11 ` Andy Shevchenko 2019-09-02 8:32 ` [PATCH v4 04/11] device property: Add functions for accessing node's parents Sakari Ailus 2019-09-02 10:14 ` Andy Shevchenko 2019-09-02 12:34 ` Sakari Ailus 2019-09-02 12:46 ` Andy Shevchenko 2019-09-02 8:32 ` [PATCH v4 05/11] device property: Add fwnode_get_name for returning the name of a node Sakari Ailus 2019-09-02 8:32 ` Sakari Ailus [this message] 2019-09-02 10:16 ` [PATCH v4 06/11] device property: Add a function to obtain a node's prefix Andy Shevchenko 2019-09-02 8:32 ` [PATCH v4 07/11] lib/vsprintf: Remove support for %pF and %pf in favour of %pS and %ps Sakari Ailus 2019-09-02 14:39 ` Petr Mladek 2019-09-02 16:01 ` Andy Shevchenko 2019-09-03 14:04 ` Petr Mladek 2019-09-06 6:59 ` Sakari Ailus 2019-09-02 8:32 ` [PATCH v4 08/11] lib/vsprintf: Make use of fwnode API to obtain node names and separators Sakari Ailus 2019-09-02 15:18 ` Petr Mladek 2019-09-02 15:41 ` Sakari Ailus 2019-09-02 8:32 ` [PATCH v4 09/11] lib/vsprintf: OF nodes are first and foremost, struct device_nodes Sakari Ailus 2019-09-02 10:21 ` Andy Shevchenko 2019-09-02 8:32 ` [PATCH v4 10/11] lib/vsprintf: Add %pfw conversion specifier for printing fwnode names Sakari Ailus 2019-09-03 13:06 ` Petr Mladek 2019-09-04 15:04 ` Sakari Ailus 2019-09-04 15:17 ` Andy Shevchenko 2019-09-04 15:39 ` Joe Perches 2019-09-04 15:54 ` Andy Shevchenko 2019-09-04 15:37 ` Joe Perches 2019-09-04 16:09 ` Sakari Ailus 2019-09-02 8:32 ` [PATCH v4 11/11] lib/test_printf: Add tests for %pfw printk modifier Sakari Ailus 2019-09-02 12:26 ` Andy Shevchenko 2019-09-02 13:09 ` Sakari Ailus 2019-09-03 13:38 ` Petr Mladek 2019-09-04 14:03 ` Sakari Ailus
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=20190902083240.20367-7-sakari.ailus@linux.intel.com \ --to=sakari.ailus@linux.intel.com \ --cc=andriy.shevchenko@linux.intel.com \ --cc=devicetree@vger.kernel.org \ --cc=heikki.krogerus@linux.intel.com \ --cc=linux-acpi@vger.kernel.org \ --cc=linux-kernel@vger.kernel.org \ --cc=pmladek@suse.com \ --cc=rafael@kernel.org \ --cc=robh@kernel.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
Linux-ACPI Archive on lore.kernel.org Archives are clonable: git clone --mirror https://lore.kernel.org/linux-acpi/0 linux-acpi/git/0.git # If you have public-inbox 1.1+ installed, you may # initialize and index your mirror using the following commands: public-inbox-init -V2 linux-acpi linux-acpi/ https://lore.kernel.org/linux-acpi \ linux-acpi@vger.kernel.org public-inbox-index linux-acpi Example config snippet for mirrors Newsgroup available over NNTP: nntp://nntp.lore.kernel.org/org.kernel.vger.linux-acpi AGPL code for this site: git clone https://public-inbox.org/public-inbox.git