Merge tag 'soc-late-6.9' of git://git.kernel.org/pub/scm/linux/kernel/git/soc/soc
[sfrench/cifs-2.6.git] / include / linux / of.h
index 85bcc05b278d589e053e9ced9df3a463c2588285..a0bedd038a059b1d8a32644b09b6a73f04eea2d2 100644 (file)
@@ -13,6 +13,7 @@
  */
 #include <linux/types.h>
 #include <linux/bitops.h>
+#include <linux/cleanup.h>
 #include <linux/errno.h>
 #include <linux/kobject.h>
 #include <linux/mod_devicetable.h>
@@ -134,6 +135,7 @@ static inline struct device_node *of_node_get(struct device_node *node)
 }
 static inline void of_node_put(struct device_node *node) { }
 #endif /* !CONFIG_OF_DYNAMIC */
+DEFINE_FREE(device_node, struct device_node *, if (_T) of_node_put(_T))
 
 /* Pointer for first entry in chain of all nodes. */
 extern struct device_node *of_root;
@@ -180,11 +182,6 @@ static inline bool is_of_node(const struct fwnode_handle *fwnode)
                        &__of_fwnode_handle_node->fwnode : NULL;        \
        })
 
-static inline bool of_have_populated_dt(void)
-{
-       return of_root != NULL;
-}
-
 static inline bool of_node_is_root(const struct device_node *node)
 {
        return node && (node->parent == NULL);
@@ -294,6 +291,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);
@@ -362,9 +361,6 @@ extern struct device_node *of_get_cpu_state_node(struct device_node *cpu_node,
                                                 int index);
 extern u64 of_get_cpu_hwid(struct device_node *cpun, unsigned int thread);
 
-#define for_each_property_of_node(dn, pp) \
-       for (pp = dn->properties; pp != NULL; pp = pp->next)
-
 extern int of_n_addr_cells(struct device_node *np);
 extern int of_n_size_cells(struct device_node *np);
 extern const struct of_device_id *of_match_node(
@@ -402,7 +398,20 @@ 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_machine_is_compatible(const char *compat);
+bool of_machine_compatible_match(const char *const *compats);
+
+/**
+ * of_machine_is_compatible - Test root of device tree for a given compatible value
+ * @compat: compatible string to look for in root node's compatible property.
+ *
+ * Return: true if the root node has the given value in its compatible property.
+ */
+static inline bool of_machine_is_compatible(const char *compat)
+{
+       const char *compats[] = { compat, NULL };
+
+       return of_machine_compatible_match(compats);
+}
 
 extern int of_add_property(struct device_node *np, struct property *prop);
 extern int of_remove_property(struct device_node *np, struct property *prop);
@@ -541,6 +550,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)
 {
@@ -549,11 +564,6 @@ static inline struct device_node *of_find_node_with_property(
 
 #define of_fwnode_handle(node) NULL
 
-static inline bool of_have_populated_dt(void)
-{
-       return false;
-}
-
 static inline struct device_node *of_get_compatible_child(const struct device_node *parent,
                                        const char *compatible)
 {
@@ -808,6 +818,11 @@ static inline int of_remove_property(struct device_node *np, struct property *pr
        return 0;
 }
 
+static inline bool of_machine_compatible_match(const char *const *compats)
+{
+       return false;
+}
+
 static inline bool of_console_check(const struct device_node *dn, const char *name, int index)
 {
        return false;
@@ -892,6 +907,9 @@ static inline int of_prop_val_eq(struct property *p1, struct property *p2)
               !memcmp(p1->value, p2->value, (size_t)p1->length);
 }
 
+#define for_each_property_of_node(dn, pp) \
+       for (pp = dn->properties; pp != NULL; pp = pp->next)
+
 #if defined(CONFIG_OF) && defined(CONFIG_NUMA)
 extern int of_node_to_nid(struct device_node *np);
 #else
@@ -1444,9 +1462,25 @@ static inline int of_property_read_s32(const struct device_node *np,
 #define for_each_child_of_node(parent, child) \
        for (child = of_get_next_child(parent, NULL); child != NULL; \
             child = of_get_next_child(parent, child))
+
+#define for_each_child_of_node_scoped(parent, child) \
+       for (struct device_node *child __free(device_node) =            \
+            of_get_next_child(parent, NULL);                           \
+            child != NULL;                                             \
+            child = of_get_next_child(parent, child))
+
 #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_available_child_of_node_scoped(parent, child) \
+       for (struct device_node *child __free(device_node) =            \
+            of_get_next_available_child(parent, NULL);                 \
+            child != NULL;                                             \
+            child = of_get_next_available_child(parent, child))
 
 #define for_each_of_cpu_node(cpu) \
        for (cpu = of_get_next_cpu_node(NULL); cpu != NULL; \
@@ -1650,6 +1684,21 @@ static inline bool of_device_is_system_power_controller(const struct device_node
        return of_property_read_bool(np, "system-power-controller");
 }
 
+/**
+ * of_have_populated_dt() - Has DT been populated by bootloader
+ *
+ * Return: True if a DTB has been populated by the bootloader and it isn't the
+ * empty builtin one. False otherwise.
+ */
+static inline bool of_have_populated_dt(void)
+{
+#ifdef CONFIG_OF
+       return of_property_present(of_root, "compatible");
+#else
+       return false;
+#endif
+}
+
 /*
  * Overlay support
  */