Lines Matching +full:a +full:- +full:child +full:- +full:node +full:- +full:property
1 // SPDX-License-Identifier: GPL-2.0
28 * of_node_get() - Increment refcount of a node
29 * @node: Node to inc refcount, NULL is supported to simplify writing of
32 * Return: The node with refcount incremented.
34 struct device_node *of_node_get(struct device_node *node) in of_node_get() argument
36 if (node) in of_node_get()
37 kobject_get(&node->kobj); in of_node_get()
38 return node; in of_node_get()
43 * of_node_put() - Decrement refcount of a node
44 * @node: Node to dec refcount, NULL is supported to simplify writing of
47 void of_node_put(struct device_node *node) in of_node_put() argument
49 if (node) in of_node_put()
50 kobject_put(&node->kobj); in of_node_put()
77 #define _do_print(func, prefix, action, node, prop, ...) ({ \ argument
78 func("changeset: " prefix "%-15s %pOF%s%s\n", \
79 ##__VA_ARGS__, action_names[action], node, \
80 prop ? ":" : "", prop ? prop->name : ""); \
90 of_changeset_action_debug("notify: ", action, pr->dn, pr->prop); in of_reconfig_notify()
97 * of_reconfig_get_state_change() - Returns new state of device
98 * @action - action of the of notifier
99 * @arg - argument of the of notifier
101 * Returns the new state of a device based on the notifier used.
109 struct property *prop, *old_prop = NULL; in of_reconfig_get_state_change()
112 /* figure out if a device should be created or destroyed */ in of_reconfig_get_state_change()
116 prop = of_find_property(pr->dn, "status", NULL); in of_reconfig_get_state_change()
120 prop = pr->prop; in of_reconfig_get_state_change()
123 prop = pr->prop; in of_reconfig_get_state_change()
124 old_prop = pr->old_prop; in of_reconfig_get_state_change()
131 status_state = -1; in of_reconfig_get_state_change()
132 old_status_state = -1; in of_reconfig_get_state_change()
133 prev_state = -1; in of_reconfig_get_state_change()
134 new_state = -1; in of_reconfig_get_state_change()
136 if (prop && !strcmp(prop->name, "status")) { in of_reconfig_get_state_change()
138 status_state = !strcmp(prop->value, "okay") || in of_reconfig_get_state_change()
139 !strcmp(prop->value, "ok"); in of_reconfig_get_state_change()
141 old_status_state = !strcmp(old_prop->value, "okay") || in of_reconfig_get_state_change()
142 !strcmp(old_prop->value, "ok"); in of_reconfig_get_state_change()
148 /* -1 & 0 status either missing or okay */ in of_reconfig_get_state_change()
152 /* -1 & 0 status either missing or okay */ in of_reconfig_get_state_change()
158 /* no status property -> enabled (legacy) */ in of_reconfig_get_state_change()
166 /* no status property -> enabled (legacy) */ in of_reconfig_get_state_change()
186 struct property *prop, struct property *oldprop) in of_property_notify()
190 /* only call notifiers if the node is attached */ in of_property_notify()
209 np->name = __of_get_property(np, "name", NULL); in __of_attach_node()
210 if (!np->name) in __of_attach_node()
211 np->name = "<NULL>"; in __of_attach_node()
219 np->phandle = be32_to_cpup(phandle); in __of_attach_node()
221 np->phandle = 0; in __of_attach_node()
224 np->child = NULL; in __of_attach_node()
225 np->sibling = np->parent->child; in __of_attach_node()
226 np->parent->child = np; in __of_attach_node()
228 np->fwnode.flags |= FWNODE_FLAG_NOT_DEVICE; in __of_attach_node()
236 * of_attach_node() - Plug a device node into the tree and global list.
237 * @np: Pointer to the caller's Device Node
262 parent = np->parent; in __of_detach_node()
268 if (parent->child == np) in __of_detach_node()
269 parent->child = np->sibling; in __of_detach_node()
272 for (prevsib = np->parent->child; in __of_detach_node()
273 prevsib->sibling != np; in __of_detach_node()
274 prevsib = prevsib->sibling) in __of_detach_node()
276 prevsib->sibling = np->sibling; in __of_detach_node()
282 __of_phandle_cache_inv_entry(np->phandle); in __of_detach_node()
290 * of_detach_node() - "Unplug" a node from the device tree.
291 * @np: Pointer to the caller's Device Node
310 void __of_prop_free(struct property *prop) in __of_prop_free()
312 kfree(prop->name); in __of_prop_free()
313 kfree(prop->value); in __of_prop_free()
317 static void property_list_free(struct property *prop_list) in property_list_free()
319 struct property *prop, *next; in property_list_free()
322 next = prop->next; in property_list_free()
328 * of_node_release() - release a dynamically allocated node
329 * @kobj: kernel object of the node to be released
335 struct device_node *node = kobj_to_device_node(kobj); in of_node_release() local
338 * can not use '"%pOF", node' in pr_err() calls from this function in of_node_release()
339 * because an of_node_get(node) when refcount is already zero in of_node_release()
340 * will result in an error and a stack dump in of_node_release()
344 if (!of_node_check_flag(node, OF_DETACHED)) { in of_node_release()
347 __func__, node->parent, node->full_name); in of_node_release()
352 * not display what a normal developer might reasonably in of_node_release()
353 * consider a real bug. in of_node_release()
356 strcmp(node->parent->full_name, "testcase-data")) { in of_node_release()
358 …_err("ERROR: next of_node_put() on this node will result in a kobject warning 'refcount_t: underfl… in of_node_release()
363 if (!of_node_check_flag(node, OF_DYNAMIC)) in of_node_release()
366 if (of_node_check_flag(node, OF_OVERLAY)) { in of_node_release()
368 if (!of_node_check_flag(node, OF_OVERLAY_FREE_CSET)) { in of_node_release()
371 node); in of_node_release()
376 * If node->properties non-empty then properties were added in of_node_release()
377 * to this node either by different overlay that has not in of_node_release()
378 * yet been removed, or by a non-overlay mechanism. in of_node_release()
380 if (node->properties) in of_node_release()
382 __func__, node); in of_node_release()
385 if (node->child) in of_node_release()
387 __func__, node->parent, node->full_name); in of_node_release()
389 property_list_free(node->properties); in of_node_release()
390 property_list_free(node->deadprops); in of_node_release()
391 fwnode_links_purge(of_fwnode_handle(node)); in of_node_release()
393 kfree(node->full_name); in of_node_release()
394 kfree(node->data); in of_node_release()
395 kfree(node); in of_node_release()
399 * __of_prop_dup - Copy a property dynamically.
400 * @prop: Property to copy
403 * Copy a property by dynamically allocating the memory of both the
404 * property structure and the property name & contents. The property's
408 * Return: The newly allocated property or NULL on out of memory error.
410 struct property *__of_prop_dup(const struct property *prop, gfp_t allocflags) in __of_prop_dup()
412 struct property *new; in __of_prop_dup()
420 * In case of a boolean property, this will allocate a value in __of_prop_dup()
424 new->name = kstrdup(prop->name, allocflags); in __of_prop_dup()
425 new->value = kmemdup(prop->value, prop->length, allocflags); in __of_prop_dup()
426 new->length = prop->length; in __of_prop_dup()
427 if (!new->name || !new->value) in __of_prop_dup()
430 /* mark the property as dynamic */ in __of_prop_dup()
441 * __of_node_dup() - Duplicate or create an empty device node dynamically.
442 * @np: if not NULL, contains properties to be duplicated in new node
443 * @full_name: string value to be duplicated into new node's full_name field
445 * Create a device tree node, optionally duplicating the properties of
446 * another node. The node data are dynamically allocated and all the node
449 * Return: The newly allocated node or NULL on out of memory error. Use
455 struct device_node *node; in __of_node_dup() local
457 node = kzalloc(sizeof(*node), GFP_KERNEL); in __of_node_dup()
458 if (!node) in __of_node_dup()
460 node->full_name = kstrdup(full_name, GFP_KERNEL); in __of_node_dup()
461 if (!node->full_name) { in __of_node_dup()
462 kfree(node); in __of_node_dup()
466 of_node_set_flag(node, OF_DYNAMIC); in __of_node_dup()
467 of_node_set_flag(node, OF_DETACHED); in __of_node_dup()
468 of_node_init(node); in __of_node_dup()
472 struct property *pp, *new_pp; in __of_node_dup()
477 if (__of_add_property(node, new_pp)) { in __of_node_dup()
483 return node; in __of_node_dup()
486 of_node_put(node); /* Frees the node and properties */ in __of_node_dup()
491 * of_changeset_create_node - Dynamically create a device node and attach to
492 * a given changeset.
495 * @parent: Pointer to parent device node
496 * @full_name: Node full name
498 * Return: Pointer to the created device node or NULL in case of an error.
510 np->parent = parent; in of_changeset_create_node()
524 if (ce->action == OF_RECONFIG_ATTACH_NODE && in __of_changeset_entry_destroy()
525 of_node_check_flag(ce->np, OF_OVERLAY)) { in __of_changeset_entry_destroy()
526 if (kref_read(&ce->np->kobj.kref) > 1) { in __of_changeset_entry_destroy()
527 …1 instead of %d, of_node_get()/of_node_put() unbalanced - destroy cset entry: attach overlay node … in __of_changeset_entry_destroy()
528 kref_read(&ce->np->kobj.kref), ce->np); in __of_changeset_entry_destroy()
530 of_node_set_flag(ce->np, OF_OVERLAY_FREE_CSET); in __of_changeset_entry_destroy()
534 of_node_put(ce->np); in __of_changeset_entry_destroy()
535 list_del(&ce->node); in __of_changeset_entry_destroy()
544 switch (ce->action) { in __of_changeset_entry_invert()
546 rce->action = OF_RECONFIG_DETACH_NODE; in __of_changeset_entry_invert()
549 rce->action = OF_RECONFIG_ATTACH_NODE; in __of_changeset_entry_invert()
552 rce->action = OF_RECONFIG_REMOVE_PROPERTY; in __of_changeset_entry_invert()
555 rce->action = OF_RECONFIG_ADD_PROPERTY; in __of_changeset_entry_invert()
558 rce->old_prop = ce->prop; in __of_changeset_entry_invert()
559 rce->prop = ce->old_prop; in __of_changeset_entry_invert()
560 /* update was used but original property did not exist */ in __of_changeset_entry_invert()
561 if (!rce->prop) { in __of_changeset_entry_invert()
562 rce->action = OF_RECONFIG_REMOVE_PROPERTY; in __of_changeset_entry_invert()
563 rce->prop = ce->prop; in __of_changeset_entry_invert()
581 switch (ce->action) { in __of_changeset_entry_notify()
585 rd.dn = ce->np; in __of_changeset_entry_notify()
586 ret = of_reconfig_notify(ce->action, &rd); in __of_changeset_entry_notify()
591 ret = of_property_notify(ce->action, ce->np, ce->prop, ce->old_prop); in __of_changeset_entry_notify()
595 (int)ce->action); in __of_changeset_entry_notify()
596 ret = -EINVAL; in __of_changeset_entry_notify()
600 pr_err("changeset notifier error @%pOF\n", ce->np); in __of_changeset_entry_notify()
608 of_changeset_action_debug("apply: ", ce->action, ce->np, ce->prop); in __of_changeset_entry_apply()
610 switch (ce->action) { in __of_changeset_entry_apply()
612 __of_attach_node(ce->np); in __of_changeset_entry_apply()
615 __of_detach_node(ce->np); in __of_changeset_entry_apply()
618 ret = __of_add_property(ce->np, ce->prop); in __of_changeset_entry_apply()
621 ret = __of_remove_property(ce->np, ce->prop); in __of_changeset_entry_apply()
625 ret = __of_update_property(ce->np, ce->prop, &ce->old_prop); in __of_changeset_entry_apply()
628 ret = -EINVAL; in __of_changeset_entry_apply()
632 of_changeset_action_err("apply failed: ", ce->action, ce->np, ce->prop); in __of_changeset_entry_apply()
648 * of_changeset_init - Initialize a changeset for use
652 * Initialize a changeset structure
657 INIT_LIST_HEAD(&ocs->entries); in of_changeset_init()
662 * of_changeset_destroy - Destroy a changeset
666 * Destroys a changeset. Note that if a changeset is applied,
674 * When a device is deleted, the device links to/from it are also queued in of_changeset_destroy()
677 * overlay change, this device might be holding a reference to a device in of_changeset_destroy()
678 * node that will be freed. So, wait until all already pending device in of_changeset_destroy()
679 * links are deleted before freeing a device node. This ensures we don't in of_changeset_destroy()
680 * free any device node that has a non-zero reference count. in of_changeset_destroy()
684 list_for_each_entry_safe_reverse(ce, cen, &ocs->entries, node) in of_changeset_destroy()
696 * Returns 0 on success, a negative error value in case of an error.
697 * If a revert error occurs, it is returned in *ret_revert.
705 list_for_each_entry(ce, &ocs->entries, node) { in __of_changeset_apply_entries()
709 list_for_each_entry_continue_reverse(ce, &ocs->entries, in __of_changeset_apply_entries()
710 node) { in __of_changeset_apply_entries()
723 * Returns 0 on success, a negative error value in case of an error.
737 list_for_each_entry(ce, &ocs->entries, node) { in __of_changeset_apply_notify()
749 * Returns 0 on success, a negative error value in case of an error.
751 * If a changeset entry apply fails, an attempt is made to revert any
768 * of_changeset_apply - Applies a changeset
772 * Applies a changeset to the live tree.
773 * Any side-effects of live tree state changes are applied here on
774 * success, like creation/destruction of devices and side-effects
777 * Return: 0 on success, a negative error value in case of an error.
794 * If revert fails, an attempt is made to re-apply the entries that were
797 * If multiple re-apply errors occur then only the final apply error is
800 * Returns 0 on success, a negative error value in case of an error.
809 list_for_each_entry_reverse(ce, &ocs->entries, node) { in __of_changeset_revert_entries()
813 list_for_each_entry_continue(ce, &ocs->entries, node) { in __of_changeset_revert_entries()
838 list_for_each_entry_reverse(ce, &ocs->entries, node) { in __of_changeset_revert_notify()
863 * of_changeset_revert - Reverts an applied changeset
867 * Reverts a changeset returning the state of the tree to what it
869 * Any side-effects like creation/destruction of devices and
872 * Return: 0 on success, a negative error value in case of an error.
887 * of_changeset_action - Add an action to the tail of the changeset list
891 * @np: Pointer to device node
892 * @prop: Pointer to property
901 * Return: 0 on success, a negative error value in case of an error.
904 struct device_node *np, struct property *prop) in of_changeset_action()
909 return -EINVAL; in of_changeset_action()
913 return -ENOMEM; in of_changeset_action()
915 /* get a reference to the node */ in of_changeset_action()
916 ce->action = action; in of_changeset_action()
917 ce->np = of_node_get(np); in of_changeset_action()
918 ce->prop = prop; in of_changeset_action()
921 list_add_tail(&ce->node, &ocs->entries); in of_changeset_action()
928 const struct property *pp) in of_changeset_add_prop_helper()
930 struct property *new_pp; in of_changeset_add_prop_helper()
935 return -ENOMEM; in of_changeset_add_prop_helper()
945 * of_changeset_add_prop_string - Add a string property to a changeset
948 * @np: device node pointer
949 * @prop_name: name of the property to be added
952 * Create a string property and add it to a changeset.
954 * Return: 0 on success, a negative error value in case of an error.
960 struct property prop; in of_changeset_add_prop_string()
971 * of_changeset_add_prop_string_array - Add a string list property to
972 * a changeset
975 * @np: device node pointer
976 * @prop_name: name of the property to be added
980 * Create a string list property and add it to a changeset.
982 * Return: 0 on success, a negative error value in case of an error.
989 struct property prop; in of_changeset_add_prop_string_array()
1001 return -ENOMEM; in of_changeset_add_prop_string_array()
1005 vp += snprintf(vp, (char *)prop.value + prop.length - vp, "%s", in of_changeset_add_prop_string_array()
1016 * of_changeset_add_prop_u32_array - Add a property of 32 bit integers
1017 * property to a changeset
1020 * @np: device node pointer
1021 * @prop_name: name of the property to be added
1025 * Create a property of 32 bit integers and add it to a changeset.
1027 * Return: 0 on success, a negative error value in case of an error.
1034 struct property prop; in of_changeset_add_prop_u32_array()
1039 return -ENOMEM; in of_changeset_add_prop_u32_array()
1052 * of_changeset_add_prop_bool - Add a boolean property (i.e. a property without
1053 * any values) to a changeset.
1056 * @np: device node pointer
1057 * @prop_name: name of the property to be added
1059 * Create a boolean property and add it to a changeset.
1061 * Return: 0 on success, a negative error value in case of an error.
1066 struct property prop; in of_changeset_add_prop_bool()
1078 const struct property *pp) in of_changeset_update_prop_helper()
1080 struct property *new_pp; in of_changeset_update_prop_helper()
1085 return -ENOMEM; in of_changeset_update_prop_helper()
1095 * of_changeset_update_prop_string - Add a string property update to a changeset
1098 * @np: device node pointer
1099 * @prop_name: name of the property to be updated
1102 * Create a string property to be updated and add it to a changeset.
1104 * Return: 0 on success, a negative error value in case of an error.
1110 struct property prop = { in of_changeset_update_prop_string()