]> rtime.felk.cvut.cz Git - zynq/linux.git/commitdiff
of: base: Introduce of_alias_get_alias_list() to check alias IDs
authorMichal Simek <michal.simek@xilinx.com>
Thu, 20 Sep 2018 11:41:52 +0000 (13:41 +0200)
committerMichal Simek <michal.simek@xilinx.com>
Thu, 20 Sep 2018 13:24:03 +0000 (15:24 +0200)
The function travels the lookup table to record alias ids for the given
device match structures and alias stem.
This function will be used by serial drivers to check if requested alias
is allocated or free to use.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Reviewed-by: Rob Herring <robh@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/of/base.c
include/linux/of.h

index 63897531cd75e66b2a62a2e872e74232e6b0b1ac..11fe50341e95f96f504e9fce97336c07ea024ccb 100644 (file)
@@ -20,6 +20,7 @@
 
 #define pr_fmt(fmt)    "OF: " fmt
 
+#include <linux/bitmap.h>
 #include <linux/console.h>
 #include <linux/ctype.h>
 #include <linux/cpu.h>
@@ -1741,6 +1742,57 @@ int of_alias_get_id(struct device_node *np, const char *stem)
 }
 EXPORT_SYMBOL_GPL(of_alias_get_id);
 
+/**
+ * of_alias_get_alias_list - Get alias list for the given device driver
+ * @matches:   Array of OF device match structures to search in
+ * @stem:      Alias stem of the given device_node
+ * @bitmap:    Bitmap field pointer
+ * @nbits:     Maximum number of alias ID which can be recorded it bitmap
+ *
+ * The function travels the lookup table to record alias ids for the given
+ * device match structures and alias stem.
+ *
+ * Return:     0 or -ENOSYS when !CONFIG_OF
+ */
+int of_alias_get_alias_list(const struct of_device_id *matches,
+                            const char *stem, unsigned long *bitmap,
+                            unsigned int nbits)
+{
+       struct alias_prop *app;
+
+       /* Zero bitmap field to make sure that all the time it is clean */
+       bitmap_zero(bitmap, nbits);
+
+       mutex_lock(&of_mutex);
+       pr_debug("%s: Looking for stem: %s\n", __func__, stem);
+       list_for_each_entry(app, &aliases_lookup, link) {
+               pr_debug("%s: stem: %s, id: %d\n",
+                        __func__, app->stem, app->id);
+
+               if (strcmp(app->stem, stem) != 0) {
+                       pr_debug("%s: stem comparison doesn't passed %s\n",
+                                __func__, app->stem);
+                       continue;
+               }
+
+               if (app->id >= nbits) {
+                       pr_debug("%s: ID %d greater then bitmap field %d\n",
+                               __func__, app->id, nbits);
+                       continue;
+               }
+
+               if (of_match_node(matches, app->np)) {
+                       pr_debug("%s: Allocated ID %d\n", __func__, app->id);
+                       set_bit(app->id, bitmap);
+               }
+               /* Alias exist but it not compatible with matches */
+       }
+       mutex_unlock(&of_mutex);
+
+       return 0;
+}
+EXPORT_SYMBOL_GPL(of_alias_get_alias_list);
+
 /**
  * of_alias_get_highest_id - Get highest alias id for the given stem
  * @stem:      Alias stem to be examined
index 842cbcc3d03c0ebacf40161f4149156b6b02b2a0..02635f6df2143494ff5b51e5b7f55f8dd9a773c2 100644 (file)
@@ -382,6 +382,9 @@ extern int of_phandle_iterator_args(struct of_phandle_iterator *it,
 extern void of_alias_scan(void * (*dt_alloc)(u64 size, u64 align));
 extern int of_alias_get_id(struct device_node *np, const char *stem);
 extern int of_alias_get_highest_id(const char *stem);
+extern int of_alias_get_alias_list(const struct of_device_id *matches,
+                                  const char *stem, unsigned long *bitmap,
+                                  unsigned int nbits);
 
 extern int of_machine_is_compatible(const char *compat);
 
@@ -818,6 +821,13 @@ static inline int of_alias_get_highest_id(const char *stem)
        return -ENOSYS;
 }
 
+static inline int of_alias_get_alias_list(const struct of_device_id *matches,
+                                         const char *stem, unsigned long *bitmap,
+                                         unsigned int nbits)
+{
+       return -ENOSYS;
+}
+
 static inline int of_machine_is_compatible(const char *compat)
 {
        return 0;