of: Add for_each_reserved_child_of_node()
authorKuninori Morimoto <kuninori.morimoto.gx@renesas.com>
Wed, 10 Jan 2024 01:14:50 +0000 (01:14 +0000)
committerGeert Uytterhoeven <geert+renesas@glider.be>
Tue, 23 Jan 2024 08:38:30 +0000 (09:38 +0100)
We would like to use for_each loop for status = "reserved" nodes.
Add for_each_reserved_child_of_node() for it.

Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
Tested-by: Yusuke Goda <yusuke.goda.sx@renesas.com>
Reviewed-by: Geert Uytterhoeven <geert+renesas@glider.be>
Reviewed-by: Rob Herring <robh@kernel.org>
Link: https://lore.kernel.org/r/87a5pegfau.wl-kuninori.morimoto.gx@renesas.com
Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
drivers/of/base.c
include/linux/of.h

index ae26a15390f74f5ccf2212c6a54142cc065ca8e4..49a9ad8134db44287353c45291efb26ed9f5a064 100644 (file)
@@ -465,6 +465,20 @@ static bool __of_device_is_available(const struct device_node *device)
                __of_device_is_status(device, ok);
 }
 
+/**
+ *  __of_device_is_reserved - check if a device is reserved
+ *
+ *  @device: Node to check for availability, with locks already held
+ *
+ *  Return: True if the status property is set to "reserved", false otherwise
+ */
+static bool __of_device_is_reserved(const struct device_node *device)
+{
+       static const char * const reserved[] = {"reserved", NULL};
+
+       return __of_device_is_status(device, reserved);
+}
+
 /**
  *  of_device_is_available - check if a device is available for use
  *
@@ -650,6 +664,21 @@ struct device_node *of_get_next_available_child(const struct device_node *node,
 }
 EXPORT_SYMBOL(of_get_next_available_child);
 
+/**
+ * of_get_next_reserved_child - Find the next reserved child node
+ * @node:      parent node
+ * @prev:      previous child of the parent node, or NULL to get first
+ *
+ * This function is like of_get_next_child(), except that it
+ * automatically skips any disabled nodes (i.e. status = "disabled").
+ */
+struct device_node *of_get_next_reserved_child(const struct device_node *node,
+                                               struct device_node *prev)
+{
+       return of_get_next_status_child(node, prev, __of_device_is_reserved);
+}
+EXPORT_SYMBOL(of_get_next_reserved_child);
+
 /**
  * of_get_next_cpu_node - Iterate on cpu nodes
  * @prev:      previous child of the /cpus node, or NULL to get first
index 6a9ddf20e79abdf0341f0cf6210e5991231eeab8..331e05918f11f9edfa436c810e7c46037b179c45 100644 (file)
@@ -294,6 +294,8 @@ extern struct device_node *of_get_next_child(const struct device_node *node,
                                             struct device_node *prev);
 extern struct device_node *of_get_next_available_child(
        const struct device_node *node, struct device_node *prev);
+extern struct device_node *of_get_next_reserved_child(
+       const struct device_node *node, struct device_node *prev);
 
 extern struct device_node *of_get_compatible_child(const struct device_node *parent,
                                        const char *compatible);
@@ -541,6 +543,12 @@ static inline struct device_node *of_get_next_available_child(
        return NULL;
 }
 
+static inline struct device_node *of_get_next_reserved_child(
+       const struct device_node *node, struct device_node *prev)
+{
+       return NULL;
+}
+
 static inline struct device_node *of_find_node_with_property(
        struct device_node *from, const char *prop_name)
 {
@@ -1431,6 +1439,9 @@ static inline int of_property_read_s32(const struct device_node *np,
 #define for_each_available_child_of_node(parent, child) \
        for (child = of_get_next_available_child(parent, NULL); child != NULL; \
             child = of_get_next_available_child(parent, child))
+#define for_each_reserved_child_of_node(parent, child)                 \
+       for (child = of_get_next_reserved_child(parent, NULL); child != NULL; \
+            child = of_get_next_reserved_child(parent, child))
 
 #define for_each_of_cpu_node(cpu) \
        for (cpu = of_get_next_cpu_node(NULL); cpu != NULL; \