xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
From: Rahul Singh <rahul.singh@arm.com>
To: xen-devel@lists.xenproject.org
Cc: bertrand.marquis@arm.com, rahul.singh@arm.com,
	Stefano Stabellini <sstabellini@kernel.org>,
	Julien Grall <julien@xen.org>
Subject: [PATCH v5 06/10] xen/device-tree: Add dt_property_match_string helper
Date: Wed, 20 Jan 2021 14:52:40 +0000	[thread overview]
Message-ID: <720eb04dcd2a2c8b9d7d8c96b0064af4465ca207.1611153615.git.rahul.singh@arm.com> (raw)
In-Reply-To: <cover.1611153615.git.rahul.singh@arm.com>
In-Reply-To: <cover.1611153615.git.rahul.singh@arm.com>

Import the Linux helper of_property_match_string. This function searches
a string list property and returns the index of a specific string value.

Signed-off-by: Rahul Singh <rahul.singh@arm.com>
Reviewed-by: Bertrand Marquis <bertrand.marquis@arm.com>
Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
---
Changes since v2:
 - This patch is introduce in this verison.
Changes since v3: No changes
Changes since v4: No changes
---
---
 xen/common/device_tree.c      | 27 +++++++++++++++++++++++++++
 xen/include/xen/device_tree.h | 12 ++++++++++++
 2 files changed, 39 insertions(+)

diff --git a/xen/common/device_tree.c b/xen/common/device_tree.c
index e107c6f89f..18825e333e 100644
--- a/xen/common/device_tree.c
+++ b/xen/common/device_tree.c
@@ -208,6 +208,33 @@ int dt_property_read_string(const struct dt_device_node *np,
     return 0;
 }
 
+int dt_property_match_string(const struct dt_device_node *np,
+                             const char *propname, const char *string)
+{
+    const struct dt_property *dtprop = dt_find_property(np, propname, NULL);
+    size_t l;
+    int i;
+    const char *p, *end;
+
+    if ( !dtprop )
+        return -EINVAL;
+    if ( !dtprop->value )
+        return -ENODATA;
+
+    p = dtprop->value;
+    end = p + dtprop->length;
+
+    for ( i = 0; p < end; i++, p += l )
+    {
+        l = strnlen(p, end - p) + 1;
+        if ( p + l > end )
+            return -EILSEQ;
+        if ( strcmp(string, p) == 0 )
+            return i; /* Found it; return index */
+    }
+    return -ENODATA;
+}
+
 bool_t dt_device_is_compatible(const struct dt_device_node *device,
                                const char *compat)
 {
diff --git a/xen/include/xen/device_tree.h b/xen/include/xen/device_tree.h
index f2ad22b79c..b02696be94 100644
--- a/xen/include/xen/device_tree.h
+++ b/xen/include/xen/device_tree.h
@@ -400,6 +400,18 @@ static inline bool_t dt_property_read_bool(const struct dt_device_node *np,
 int dt_property_read_string(const struct dt_device_node *np,
                             const char *propname, const char **out_string);
 
+/**
+ * dt_property_match_string() - Find string in a list and return index
+ * @np: pointer to node containing string list property
+ * @propname: string list property name
+ * @string: pointer to string to search for in string list
+ *
+ * This function searches a string list property and returns the index
+ * of a specific string value.
+ */
+int dt_property_match_string(const struct dt_device_node *np,
+                             const char *propname, const char *string);
+
 /**
  * Checks if the given "compat" string matches one of the strings in
  * the device's "compatible" property
-- 
2.17.1



  parent reply	other threads:[~2021-01-20 14:57 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-20 14:52 [PATCH v5 00/10] xen/arm: Add support for SMMUv3 driver Rahul Singh
2021-01-20 14:52 ` [PATCH v5 01/10] xen/arm: smmuv3: Import the SMMUv3 driver from Linux Rahul Singh
2021-01-20 14:52 ` [PATCH v5 02/10] xen/arm: Revert atomic operation related command-queue insertion patch Rahul Singh
2021-01-20 14:52 ` [PATCH v5 03/10] xen/arm: smmuv3: Revert patch related to XArray Rahul Singh
2021-01-20 14:52 ` [PATCH v5 04/10] xen/arm: smmuv3: Remove support for Stage-1 translation on SMMUv3 Rahul Singh
2021-01-20 14:52 ` [PATCH v5 05/10] xen/arm: smmuv3: Remove Linux specific code that is not usable in XEN Rahul Singh
2021-01-20 14:52 ` Rahul Singh [this message]
2021-01-20 14:52 ` [PATCH v5 07/10] xen/compiler: import 'fallthrough' keyword from linux Rahul Singh
2021-01-20 14:52 ` [PATCH v5 08/10] xen/arm: smmuv3: Use fallthrough pseudo-keyword Rahul Singh
2021-01-20 15:36   ` Bertrand Marquis
2021-01-20 19:56   ` Stefano Stabellini
2021-01-20 14:52 ` [PATCH v5 09/10] xen/arm: smmuv3: Replace linux functions with xen functions Rahul Singh
2021-01-20 14:52 ` [PATCH v5 10/10] xen/arm: smmuv3: Add support for SMMUv3 driver Rahul Singh
2021-01-20 15:35   ` Bertrand Marquis
2021-01-20 20:31   ` Stefano Stabellini
2021-01-21 17:10     ` Rahul Singh
2021-01-21 18:43       ` Julien Grall
2021-01-21 20:28         ` Rahul Singh
2021-01-21 21:20           ` Stefano Stabellini
2021-01-20 21:33   ` Oleksandr
2021-01-21 17:18     ` Rahul Singh
2021-01-21 18:31       ` Julien Grall
2021-01-21 18:50         ` Rahul Singh
2021-01-21 20:19           ` Julien Grall

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=720eb04dcd2a2c8b9d7d8c96b0064af4465ca207.1611153615.git.rahul.singh@arm.com \
    --to=rahul.singh@arm.com \
    --cc=bertrand.marquis@arm.com \
    --cc=julien@xen.org \
    --cc=sstabellini@kernel.org \
    --cc=xen-devel@lists.xenproject.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).