All of lore.kernel.org
 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 v4 06/11] xen/device-tree: Add dt_property_match_string helper
Date: Fri,  8 Jan 2021 14:46:26 +0000	[thread overview]
Message-ID: <0df414d5496574269c58415f7bff8f069efce94d.1610115608.git.rahul.singh@arm.com> (raw)
In-Reply-To: <cover.1610115608.git.rahul.singh@arm.com>
In-Reply-To: <cover.1610115608.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>
---
Changes in V3:
 - This patch is introduce in this verison.
Changes in V4: Rebase
---
 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-08 14:50 UTC|newest]

Thread overview: 55+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-08 14:46 [PATCH v4 00/11] xen/arm: Add support for SMMUv3 driver Rahul Singh
2021-01-08 14:46 ` [PATCH v4 01/11] xen/arm: smmuv3: Import the SMMUv3 driver from Linux Rahul Singh
2021-01-08 23:42   ` Stefano Stabellini
2021-01-15 11:55   ` Julien Grall
2021-01-08 14:46 ` [PATCH v4 02/11] xen/arm: Revert atomic operation related command-queue insertion patch Rahul Singh
2021-01-08 23:43   ` Stefano Stabellini
2021-01-08 14:46 ` [PATCH v4 03/11] xen/arm: smmuv3: Revert patch related to XArray Rahul Singh
2021-01-08 23:43   ` Stefano Stabellini
2021-01-08 14:46 ` [PATCH v4 04/11] xen/arm: smmuv3: Remove support for Stage-1 translation on SMMUv3 Rahul Singh
2021-01-08 23:52   ` Stefano Stabellini
2021-01-08 14:46 ` [PATCH v4 05/11] xen/arm: smmuv3: Remove Linux specific code that is not usable in XEN Rahul Singh
2021-01-08 23:56   ` Stefano Stabellini
2021-01-12 11:38   ` Bertrand Marquis
2021-01-08 14:46 ` Rahul Singh [this message]
2021-01-08 23:57   ` [PATCH v4 06/11] xen/device-tree: Add dt_property_match_string helper Stefano Stabellini
2021-01-12 11:38   ` Bertrand Marquis
2021-01-08 14:46 ` [PATCH v4 07/11] xen/arm: bitops: Implement a ffsll function Rahul Singh
2021-01-09  1:44   ` Stefano Stabellini
2021-01-12 11:35   ` Bertrand Marquis
2021-01-15 12:16   ` Julien Grall
2021-01-18 15:32     ` Rahul Singh
2021-01-08 14:46 ` [PATCH v4 08/11] xen/compiler: import 'fallthrough' keyword from linux Rahul Singh
2021-01-09  1:44   ` Stefano Stabellini
2021-01-12 11:36   ` Bertrand Marquis
2021-01-12 11:41   ` Jan Beulich
2021-01-12 23:30     ` Stefano Stabellini
2021-01-12 23:40       ` Stefano Stabellini
2021-01-14  9:04       ` Jan Beulich
2021-01-14 23:47         ` Stefano Stabellini
2021-01-15 12:14           ` Rahul Singh
2021-01-15 13:09             ` Jan Beulich
2021-01-15 17:56               ` Stefano Stabellini
2021-01-08 14:46 ` [PATCH v4 09/11] xen/arm: smmuv3: Use fallthrough pseudo-keyword Rahul Singh
2021-01-09  1:44   ` Stefano Stabellini
2021-01-09 18:57     ` Rahul Singh
2021-01-12 11:34   ` Bertrand Marquis
2021-01-15 12:18   ` Julien Grall
2021-01-18 15:33     ` Rahul Singh
2021-01-08 14:46 ` [PATCH v4 10/11] xen/arm: smmuv3: Replace linux functions with xen functions Rahul Singh
2021-01-09  1:44   ` Stefano Stabellini
2021-01-12 11:35   ` Bertrand Marquis
2021-01-08 14:46 ` [PATCH v4 11/11] xen/arm: smmuv3: Add support for SMMUv3 driver Rahul Singh
2021-01-09  1:45   ` Stefano Stabellini
2021-01-11 16:09   ` Oleksandr
2021-01-11 16:39     ` Oleksandr
2021-01-18 15:33       ` Rahul Singh
2021-01-18 16:20         ` Oleksandr
2021-01-18 16:57           ` Rahul Singh
2021-01-19 14:43             ` Oleksandr
2021-01-19 14:53               ` Rahul Singh
2021-01-12  9:41     ` Rahul Singh
2021-01-12 20:59       ` Oleksandr
2021-01-15 12:38         ` Rahul Singh
2021-01-15 12:40           ` Julien Grall
2021-01-15 12:37   ` 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=0df414d5496574269c58415f7bff8f069efce94d.1610115608.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 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.