Lines Matching +full:a +full:- +full:child +full:- +full:node +full:- +full:property
1 // SPDX-License-Identifier: GPL-2.0
26 * of_node_get() - Increment refcount of a node
27 * @node: Node to inc refcount, NULL is supported to simplify writing of
30 * Returns node.
32 struct device_node *of_node_get(struct device_node *node) in of_node_get() argument
34 if (node) in of_node_get()
35 kobject_get(&node->kobj); in of_node_get()
36 return node; in of_node_get()
41 * of_node_put() - Decrement refcount of a node
42 * @node: Node to dec refcount, NULL is supported to simplify writing of
45 void of_node_put(struct device_node *node) in of_node_put() argument
47 if (node) in of_node_put()
48 kobject_put(&node->kobj); in of_node_put()
85 pr_debug("notify %-15s %pOF\n", action_names[action], in of_reconfig_notify()
86 pr->dn); in of_reconfig_notify()
91 pr_debug("notify %-15s %pOF:%s\n", action_names[action], in of_reconfig_notify()
92 pr->dn, pr->prop->name); in of_reconfig_notify()
102 * of_reconfig_get_state_change() - Returns new state of device
103 * @action - action of the of notifier
104 * @arg - argument of the of notifier
106 * Returns the new state of a device based on the notifier used.
108 * going from disabled to enabled and -1 on no change.
112 struct property *prop, *old_prop = NULL; in of_reconfig_get_state_change()
115 /* figure out if a device should be created or destroyed */ in of_reconfig_get_state_change()
119 prop = of_find_property(pr->dn, "status", NULL); in of_reconfig_get_state_change()
123 prop = pr->prop; in of_reconfig_get_state_change()
126 prop = pr->prop; in of_reconfig_get_state_change()
127 old_prop = pr->old_prop; in of_reconfig_get_state_change()
134 status_state = -1; in of_reconfig_get_state_change()
135 old_status_state = -1; in of_reconfig_get_state_change()
136 prev_state = -1; in of_reconfig_get_state_change()
137 new_state = -1; in of_reconfig_get_state_change()
139 if (prop && !strcmp(prop->name, "status")) { in of_reconfig_get_state_change()
141 status_state = !strcmp(prop->value, "okay") || in of_reconfig_get_state_change()
142 !strcmp(prop->value, "ok"); in of_reconfig_get_state_change()
144 old_status_state = !strcmp(old_prop->value, "okay") || in of_reconfig_get_state_change()
145 !strcmp(old_prop->value, "ok"); in of_reconfig_get_state_change()
151 /* -1 & 0 status either missing or okay */ in of_reconfig_get_state_change()
155 /* -1 & 0 status either missing or okay */ in of_reconfig_get_state_change()
161 /* no status property -> enabled (legacy) */ in of_reconfig_get_state_change()
169 /* no status property -> enabled (legacy) */ in of_reconfig_get_state_change()
189 struct property *prop, struct property *oldprop) in of_property_notify()
193 /* 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()
231 * of_attach_node() - Plug a device node into the tree and global list.
261 parent = np->parent; in __of_detach_node()
265 if (parent->child == np) in __of_detach_node()
266 parent->child = np->sibling; in __of_detach_node()
269 for (prevsib = np->parent->child; in __of_detach_node()
270 prevsib->sibling != np; in __of_detach_node()
271 prevsib = prevsib->sibling) in __of_detach_node()
273 prevsib->sibling = np->sibling; in __of_detach_node()
279 __of_phandle_cache_inv_entry(np->phandle); in __of_detach_node()
283 * of_detach_node() - "Unplug" a node from the device tree.
307 static void property_list_free(struct property *prop_list) in property_list_free()
309 struct property *prop, *next; in property_list_free()
312 next = prop->next; in property_list_free()
313 kfree(prop->name); in property_list_free()
314 kfree(prop->value); in property_list_free()
320 * of_node_release() - release a dynamically allocated node
321 * @kref: kref element of the node to be released
327 struct device_node *node = kobj_to_device_node(kobj); in of_node_release() local
330 if (!of_node_check_flag(node, OF_DETACHED)) { in of_node_release()
331 pr_err("ERROR: Bad of_node_put() on %pOF\n", node); in of_node_release()
335 if (!of_node_check_flag(node, OF_DYNAMIC)) in of_node_release()
338 if (of_node_check_flag(node, OF_OVERLAY)) { in of_node_release()
340 if (!of_node_check_flag(node, OF_OVERLAY_FREE_CSET)) { in of_node_release()
343 node); in of_node_release()
348 * If node->properties non-empty then properties were added in of_node_release()
349 * to this node either by different overlay that has not in of_node_release()
350 * yet been removed, or by a non-overlay mechanism. in of_node_release()
352 if (node->properties) in of_node_release()
354 __func__, node); in of_node_release()
357 property_list_free(node->properties); in of_node_release()
358 property_list_free(node->deadprops); in of_node_release()
360 kfree(node->full_name); in of_node_release()
361 kfree(node->data); in of_node_release()
362 kfree(node); in of_node_release()
366 * __of_prop_dup - Copy a property dynamically.
367 * @prop: Property to copy
370 * Copy a property by dynamically allocating the memory of both the
371 * property structure and the property name & contents. The property's
374 * Returns the newly allocated property or NULL on out of memory error.
376 struct property *__of_prop_dup(const struct property *prop, gfp_t allocflags) in __of_prop_dup()
378 struct property *new; in __of_prop_dup()
386 * In case of a boolean property, this will allocate a value in __of_prop_dup()
390 new->name = kstrdup(prop->name, allocflags); in __of_prop_dup()
391 new->value = kmemdup(prop->value, prop->length, allocflags); in __of_prop_dup()
392 new->length = prop->length; in __of_prop_dup()
393 if (!new->name || !new->value) in __of_prop_dup()
396 /* mark the property as dynamic */ in __of_prop_dup()
402 kfree(new->name); in __of_prop_dup()
403 kfree(new->value); in __of_prop_dup()
409 * __of_node_dup() - Duplicate or create an empty device node dynamically.
410 * @np: if not NULL, contains properties to be duplicated in new node
411 * @full_name: string value to be duplicated into new node's full_name field
413 * Create a device tree node, optionally duplicating the properties of
414 * another node. The node data are dynamically allocated and all the node
417 * Returns the newly allocated node or NULL on out of memory error.
422 struct device_node *node; in __of_node_dup() local
424 node = kzalloc(sizeof(*node), GFP_KERNEL); in __of_node_dup()
425 if (!node) in __of_node_dup()
427 node->full_name = kstrdup(full_name, GFP_KERNEL); in __of_node_dup()
428 if (!node->full_name) { in __of_node_dup()
429 kfree(node); in __of_node_dup()
433 of_node_set_flag(node, OF_DYNAMIC); in __of_node_dup()
434 of_node_set_flag(node, OF_DETACHED); in __of_node_dup()
435 of_node_init(node); in __of_node_dup()
439 struct property *pp, *new_pp; in __of_node_dup()
444 if (__of_add_property(node, new_pp)) { in __of_node_dup()
445 kfree(new_pp->name); in __of_node_dup()
446 kfree(new_pp->value); in __of_node_dup()
452 return node; in __of_node_dup()
455 of_node_put(node); /* Frees the node and properties */ in __of_node_dup()
461 if (ce->action == OF_RECONFIG_ATTACH_NODE && in __of_changeset_entry_destroy()
462 of_node_check_flag(ce->np, OF_OVERLAY)) { in __of_changeset_entry_destroy()
463 if (kref_read(&ce->np->kobj.kref) > 1) { in __of_changeset_entry_destroy()
464 …1 instead of %d, of_node_get()/of_node_put() unbalanced - destroy cset entry: attach overlay node … in __of_changeset_entry_destroy()
465 kref_read(&ce->np->kobj.kref), ce->np); in __of_changeset_entry_destroy()
467 of_node_set_flag(ce->np, OF_OVERLAY_FREE_CSET); in __of_changeset_entry_destroy()
471 of_node_put(ce->np); in __of_changeset_entry_destroy()
472 list_del(&ce->node); in __of_changeset_entry_destroy()
479 switch (ce->action) { in __of_changeset_entry_dump()
483 pr_debug("cset<%p> %-15s %pOF/%s\n", ce, action_names[ce->action], in __of_changeset_entry_dump()
484 ce->np, ce->prop->name); in __of_changeset_entry_dump()
488 pr_debug("cset<%p> %-15s %pOF\n", ce, action_names[ce->action], in __of_changeset_entry_dump()
489 ce->np); in __of_changeset_entry_dump()
505 switch (ce->action) { in __of_changeset_entry_invert()
507 rce->action = OF_RECONFIG_DETACH_NODE; in __of_changeset_entry_invert()
510 rce->action = OF_RECONFIG_ATTACH_NODE; in __of_changeset_entry_invert()
513 rce->action = OF_RECONFIG_REMOVE_PROPERTY; in __of_changeset_entry_invert()
516 rce->action = OF_RECONFIG_ADD_PROPERTY; in __of_changeset_entry_invert()
519 rce->old_prop = ce->prop; in __of_changeset_entry_invert()
520 rce->prop = ce->old_prop; in __of_changeset_entry_invert()
521 /* update was used but original property did not exist */ in __of_changeset_entry_invert()
522 if (!rce->prop) { in __of_changeset_entry_invert()
523 rce->action = OF_RECONFIG_REMOVE_PROPERTY; in __of_changeset_entry_invert()
524 rce->prop = ce->prop; in __of_changeset_entry_invert()
542 switch (ce->action) { in __of_changeset_entry_notify()
546 rd.dn = ce->np; in __of_changeset_entry_notify()
547 ret = of_reconfig_notify(ce->action, &rd); in __of_changeset_entry_notify()
552 ret = of_property_notify(ce->action, ce->np, ce->prop, ce->old_prop); in __of_changeset_entry_notify()
556 (int)ce->action); in __of_changeset_entry_notify()
557 ret = -EINVAL; in __of_changeset_entry_notify()
561 pr_err("changeset notifier error @%pOF\n", ce->np); in __of_changeset_entry_notify()
567 struct property *old_prop, **propp; in __of_changeset_entry_apply()
574 switch (ce->action) { in __of_changeset_entry_apply()
576 __of_attach_node(ce->np); in __of_changeset_entry_apply()
579 __of_detach_node(ce->np); in __of_changeset_entry_apply()
582 /* If the property is in deadprops then it must be removed */ in __of_changeset_entry_apply()
583 for (propp = &ce->np->deadprops; *propp; propp = &(*propp)->next) { in __of_changeset_entry_apply()
584 if (*propp == ce->prop) { in __of_changeset_entry_apply()
585 *propp = ce->prop->next; in __of_changeset_entry_apply()
586 ce->prop->next = NULL; in __of_changeset_entry_apply()
591 ret = __of_add_property(ce->np, ce->prop); in __of_changeset_entry_apply()
594 ce->np, in __of_changeset_entry_apply()
595 ce->prop->name); in __of_changeset_entry_apply()
600 ret = __of_remove_property(ce->np, ce->prop); in __of_changeset_entry_apply()
603 ce->np, in __of_changeset_entry_apply()
604 ce->prop->name); in __of_changeset_entry_apply()
610 /* If the property is in deadprops then it must be removed */ in __of_changeset_entry_apply()
611 for (propp = &ce->np->deadprops; *propp; propp = &(*propp)->next) { in __of_changeset_entry_apply()
612 if (*propp == ce->prop) { in __of_changeset_entry_apply()
613 *propp = ce->prop->next; in __of_changeset_entry_apply()
614 ce->prop->next = NULL; in __of_changeset_entry_apply()
619 ret = __of_update_property(ce->np, ce->prop, &old_prop); in __of_changeset_entry_apply()
622 ce->np, in __of_changeset_entry_apply()
623 ce->prop->name); in __of_changeset_entry_apply()
628 ret = -EINVAL; in __of_changeset_entry_apply()
635 switch (ce->action) { in __of_changeset_entry_apply()
637 __of_attach_node_sysfs(ce->np); in __of_changeset_entry_apply()
640 __of_detach_node_sysfs(ce->np); in __of_changeset_entry_apply()
644 __of_add_property_sysfs(ce->np, ce->prop); in __of_changeset_entry_apply()
647 __of_remove_property_sysfs(ce->np, ce->prop); in __of_changeset_entry_apply()
650 __of_update_property_sysfs(ce->np, ce->prop, ce->old_prop); in __of_changeset_entry_apply()
666 * of_changeset_init - Initialize a changeset for use
670 * Initialize a changeset structure
675 INIT_LIST_HEAD(&ocs->entries); in of_changeset_init()
680 * of_changeset_destroy - Destroy a changeset
684 * Destroys a changeset. Note that if a changeset is applied,
691 list_for_each_entry_safe_reverse(ce, cen, &ocs->entries, node) in of_changeset_destroy()
703 * Returns 0 on success, a negative error value in case of an error.
704 * If a revert error occurs, it is returned in *ret_revert.
712 list_for_each_entry(ce, &ocs->entries, node) { in __of_changeset_apply_entries()
716 list_for_each_entry_continue_reverse(ce, &ocs->entries, in __of_changeset_apply_entries()
717 node) { in __of_changeset_apply_entries()
730 * Returns 0 on success, a negative error value in case of an error.
744 list_for_each_entry(ce, &ocs->entries, node) { in __of_changeset_apply_notify()
756 * Returns 0 on success, a negative error value in case of an error.
758 * If a changeset entry apply fails, an attempt is made to revert any
775 * of_changeset_apply - Applies a changeset
779 * Applies a changeset to the live tree.
780 * Any side-effects of live tree state changes are applied here on
781 * success, like creation/destruction of devices and side-effects
783 * Returns 0 on success, a negative error value in case of an error.
800 * If revert fails, an attempt is made to re-apply the entries that were
803 * If multiple re-apply errors occur then only the final apply error is
806 * Returns 0 on success, a negative error value in case of an error.
815 list_for_each_entry_reverse(ce, &ocs->entries, node) { in __of_changeset_revert_entries()
819 list_for_each_entry_continue(ce, &ocs->entries, node) { in __of_changeset_revert_entries()
844 list_for_each_entry_reverse(ce, &ocs->entries, node) { in __of_changeset_revert_notify()
869 * of_changeset_revert - Reverts an applied changeset
873 * Reverts a changeset returning the state of the tree to what it
875 * Any side-effects like creation/destruction of devices and
877 * Returns 0 on success, a negative error value in case of an error.
892 * of_changeset_action - Add an action to the tail of the changeset list
896 * @np: Pointer to device node
897 * @prop: Pointer to property
905 * Returns 0 on success, a negative error value in case of an error.
908 struct device_node *np, struct property *prop) in of_changeset_action()
914 return -ENOMEM; in of_changeset_action()
916 /* get a reference to the node */ in of_changeset_action()
917 ce->action = action; in of_changeset_action()
918 ce->np = of_node_get(np); in of_changeset_action()
919 ce->prop = prop; in of_changeset_action()
922 ce->old_prop = of_find_property(np, prop->name, NULL); in of_changeset_action()
925 list_add_tail(&ce->node, &ocs->entries); in of_changeset_action()