Lines Matching +full:non +full:- +full:live
1 // SPDX-License-Identifier: GPL-2.0
5 * Copyright (C) 2012 Pantelis Antoniou <panto@antoniou-consulting.com>
27 * struct target - info about current target node as recursing through overlay
29 * @in_livetree: @np is a node in the live devicetree
33 * in the live devicetree where the overlay subtree is targeted to be grafted
35 * also recurses to the next level of the live devicetree, as long as overlay
36 * subtree node also exists in the live devicetree. When a node in the overlay
37 * subtree does not exist at the same level in the live devicetree, target->np
47 * struct fragment - info about fragment nodes in overlay expanded device tree
65 * @cset: changeset to apply fragments to live device tree
78 /* flags are sticky - once set, do not reset */
98 * of_resolve_phandles() finds the largest phandle in the live tree.
99 * of_overlay_apply() may add a larger phandle to the live tree.
125 * of_overlay_notifier_register() - Register notifier for overlay operations
143 * of_overlay_notifier_register() - Unregister notifier for overlay operations
153 "pre-apply",
154 "post-apply",
155 "pre-remove",
156 "post-remove",
165 for (i = 0; i < ovcs->count; i++) { in overlay_notify()
166 struct fragment *fragment = &ovcs->fragments[i]; in overlay_notify()
168 nd.target = fragment->target; in overlay_notify()
169 nd.overlay = fragment->overlay; in overlay_notify()
186 * the ovcs->overlay_tree. When duplicating the properties, the paths
187 * need to be adjusted to be the correct path for the live device tree.
191 * where symbol_path_tail can be a single node or it may be a multi-node path.
213 if (!prop->value) in dup_and_fixup_symbol_prop()
215 if (strnlen(prop->value, prop->length) >= prop->length) in dup_and_fixup_symbol_prop()
217 path = prop->value; in dup_and_fixup_symbol_prop()
222 fragment_node = __of_find_node_by_path(ovcs->overlay_tree, path + 1); in dup_and_fixup_symbol_prop()
227 for (k = 0; k < ovcs->count; k++) { in dup_and_fixup_symbol_prop()
228 fragment = &ovcs->fragments[k]; in dup_and_fixup_symbol_prop()
229 if (fragment->overlay == overlay_node) in dup_and_fixup_symbol_prop()
232 if (k >= ovcs->count) in dup_and_fixup_symbol_prop()
235 overlay_name_len = snprintf(NULL, 0, "%pOF", fragment->overlay); in dup_and_fixup_symbol_prop()
242 target_path = kasprintf(GFP_KERNEL, "%pOF", fragment->target); in dup_and_fixup_symbol_prop()
251 new_prop->name = kstrdup(prop->name, GFP_KERNEL); in dup_and_fixup_symbol_prop()
252 new_prop->length = target_path_len + path_tail_len + 1; in dup_and_fixup_symbol_prop()
253 new_prop->value = kzalloc(new_prop->length, GFP_KERNEL); in dup_and_fixup_symbol_prop()
254 if (!new_prop->name || !new_prop->value) in dup_and_fixup_symbol_prop()
257 strcpy(new_prop->value, target_path); in dup_and_fixup_symbol_prop()
258 strcpy(new_prop->value + target_path_len, path_tail); in dup_and_fixup_symbol_prop()
267 kfree(new_prop->name); in dup_and_fixup_symbol_prop()
268 kfree(new_prop->value); in dup_and_fixup_symbol_prop()
277 * add_changeset_property() - add @overlay_prop to overlay changeset
283 * If @overlay_prop does not already exist in live devicetree, add changeset
287 * @target may be either in the live devicetree or in a new subtree that
293 * Properties "#address-cells" and "#size-cells" are not updated if they
294 * are already in the live tree, but if present in the live tree, the values
295 * in the overlay must match the values in the live tree.
299 * Return: 0 on success, -ENOMEM if memory allocation failure, or -EINVAL if
309 if (target->in_livetree) in add_changeset_property()
310 if (!of_prop_cmp(overlay_prop->name, "name") || in add_changeset_property()
311 !of_prop_cmp(overlay_prop->name, "phandle") || in add_changeset_property()
312 !of_prop_cmp(overlay_prop->name, "linux,phandle")) in add_changeset_property()
315 if (target->in_livetree) in add_changeset_property()
316 prop = of_find_property(target->np, overlay_prop->name, NULL); in add_changeset_property()
321 if (!of_prop_cmp(prop->name, "#address-cells")) { in add_changeset_property()
323 pr_err("ERROR: changing value of #address-cells is not allowed in %pOF\n", in add_changeset_property()
324 target->np); in add_changeset_property()
325 ret = -EINVAL; in add_changeset_property()
329 } else if (!of_prop_cmp(prop->name, "#size-cells")) { in add_changeset_property()
331 pr_err("ERROR: changing value of #size-cells is not allowed in %pOF\n", in add_changeset_property()
332 target->np); in add_changeset_property()
333 ret = -EINVAL; in add_changeset_property()
341 return -EINVAL; in add_changeset_property()
348 return -ENOMEM; in add_changeset_property()
351 if (!target->in_livetree) { in add_changeset_property()
352 new_prop->next = target->np->deadprops; in add_changeset_property()
353 target->np->deadprops = new_prop; in add_changeset_property()
355 ret = of_changeset_add_property(&ovcs->cset, target->np, in add_changeset_property()
358 ret = of_changeset_update_property(&ovcs->cset, target->np, in add_changeset_property()
362 if (!of_node_check_flag(target->np, OF_OVERLAY)) in add_changeset_property()
364 target->np, new_prop->name); in add_changeset_property()
367 kfree(new_prop->name); in add_changeset_property()
368 kfree(new_prop->value); in add_changeset_property()
375 * add_changeset_node() - add @node (and children) to overlay changeset
377 * @target: where @node will be placed in live tree or changeset
389 * NOTE_1: A live devicetree created from a flattened device tree (FDT) will
390 * not contain the full path in node->full_name. Thus an overlay
392 * node->full_name. However, a live devicetree created from Open
393 * Firmware may have the full path in node->full_name.
396 * the full path in node->full_name. Even though it expects the overlay
399 * to nodes in the live devicetree so that it can apply an overlay to
400 * a live devicetree created from Open Firmware.
404 * Return: 0 on success, -ENOMEM if memory allocation failure, or -EINVAL if
416 node_kbasename = kbasename(node->full_name); in add_changeset_node()
418 for_each_child_of_node(target->np, tchild) in add_changeset_node()
419 if (!of_node_cmp(node_kbasename, kbasename(tchild->full_name))) in add_changeset_node()
425 return -ENOMEM; in add_changeset_node()
427 tchild->parent = target->np; in add_changeset_node()
428 tchild->name = __of_get_property(node, "name", NULL); in add_changeset_node()
430 if (!tchild->name) in add_changeset_node()
431 tchild->name = "<NULL>"; in add_changeset_node()
436 tchild->phandle = be32_to_cpup(phandle); in add_changeset_node()
440 ret = of_changeset_attach_node(&ovcs->cset, tchild); in add_changeset_node()
452 if (node->phandle && tchild->phandle) { in add_changeset_node()
453 ret = -EINVAL; in add_changeset_node()
456 target_child.in_livetree = target->in_livetree; in add_changeset_node()
465 * build_changeset_next_level() - add level of overlay changeset
467 * @target: where to place @overlay_node in live tree
471 * @ovcs->cset changeset. If an added node has child nodes, they will
476 * Return: 0 on success, -ENOMEM if memory allocation failure, or -EINVAL if
490 target->np, prop->name, ret); in build_changeset_next_level()
499 target->np, child, ret); in build_changeset_next_level()
509 * Add the properties from __overlay__ node to the @ovcs->cset changeset.
522 target->np, prop->name, ret); in build_changeset_symbols_node()
537 if (ce_1->action != OF_RECONFIG_ATTACH_NODE && in find_dup_cset_node_entry()
538 ce_1->action != OF_RECONFIG_DETACH_NODE) in find_dup_cset_node_entry()
542 list_for_each_entry_continue(ce_2, &ovcs->cset.entries, node) { in find_dup_cset_node_entry()
543 if ((ce_2->action != OF_RECONFIG_ATTACH_NODE && in find_dup_cset_node_entry()
544 ce_2->action != OF_RECONFIG_DETACH_NODE) || in find_dup_cset_node_entry()
545 of_node_cmp(ce_1->np->full_name, ce_2->np->full_name)) in find_dup_cset_node_entry()
548 fn_1 = kasprintf(GFP_KERNEL, "%pOF", ce_1->np); in find_dup_cset_node_entry()
549 fn_2 = kasprintf(GFP_KERNEL, "%pOF", ce_2->np); in find_dup_cset_node_entry()
555 ce_1->np); in find_dup_cset_node_entry()
556 return -EINVAL; in find_dup_cset_node_entry()
570 if (ce_1->action != OF_RECONFIG_ADD_PROPERTY && in find_dup_cset_prop()
571 ce_1->action != OF_RECONFIG_REMOVE_PROPERTY && in find_dup_cset_prop()
572 ce_1->action != OF_RECONFIG_UPDATE_PROPERTY) in find_dup_cset_prop()
576 list_for_each_entry_continue(ce_2, &ovcs->cset.entries, node) { in find_dup_cset_prop()
577 if ((ce_2->action != OF_RECONFIG_ADD_PROPERTY && in find_dup_cset_prop()
578 ce_2->action != OF_RECONFIG_REMOVE_PROPERTY && in find_dup_cset_prop()
579 ce_2->action != OF_RECONFIG_UPDATE_PROPERTY) || in find_dup_cset_prop()
580 of_node_cmp(ce_1->np->full_name, ce_2->np->full_name)) in find_dup_cset_prop()
583 fn_1 = kasprintf(GFP_KERNEL, "%pOF", ce_1->np); in find_dup_cset_prop()
584 fn_2 = kasprintf(GFP_KERNEL, "%pOF", ce_2->np); in find_dup_cset_prop()
589 !of_prop_cmp(ce_1->prop->name, ce_2->prop->name)) { in find_dup_cset_prop()
591 ce_1->np, ce_1->prop->name); in find_dup_cset_prop()
592 return -EINVAL; in find_dup_cset_prop()
600 * changeset_dup_entry_check() - check for duplicate entries
603 * Check changeset @ovcs->cset for multiple {add or delete} node entries for
607 * Return: 0 on success, or -EINVAL if duplicate changeset entry found.
614 list_for_each_entry(ce_1, &ovcs->cset.entries, node) { in changeset_dup_entry_check()
619 return dup_entry ? -EINVAL : 0; in changeset_dup_entry_check()
623 * build_changeset() - populate overlay changeset in @ovcs from @ovcs->fragments
626 * Create changeset @ovcs->cset to contain the nodes and properties of the
627 * overlay device tree fragments in @ovcs->fragments[]. If an error occurs,
629 * in @ovcs->cset.
631 * Return: 0 on success, -ENOMEM if memory allocation failure, or -EINVAL if
632 * invalid overlay in @ovcs->fragments[].
641 * if there is a symbols fragment in ovcs->fragments[i] it is in build_changeset()
644 if (ovcs->symbols_fragment) in build_changeset()
645 fragments_count = ovcs->count - 1; in build_changeset()
647 fragments_count = ovcs->count; in build_changeset()
650 fragment = &ovcs->fragments[i]; in build_changeset()
652 target.np = fragment->target; in build_changeset()
655 fragment->overlay); in build_changeset()
658 fragment->target); in build_changeset()
663 if (ovcs->symbols_fragment) { in build_changeset()
664 fragment = &ovcs->fragments[ovcs->count - 1]; in build_changeset()
666 target.np = fragment->target; in build_changeset()
669 fragment->overlay); in build_changeset()
672 fragment->target); in build_changeset()
685 * 2) "target-path" property containing the path of the target
703 ret = of_property_read_string(info_node, "target-path", &path); in find_target()
718 * init_overlay_changeset() - initialize overlay changeset from overlay tree
723 * Initialize @ovcs. Populate @ovcs->fragments with node information from
727 * Return: 0 on success, -ENOMEM if memory allocation failure, -EINVAL if error
728 * detected in @tree, or -ENOSPC if idr_alloc() error.
739 * Warn for some issues. Can not return -EINVAL for these until in init_overlay_changeset()
751 ovcs->overlay_tree = tree; in init_overlay_changeset()
752 ovcs->fdt = fdt; in init_overlay_changeset()
754 INIT_LIST_HEAD(&ovcs->ovcs_list); in init_overlay_changeset()
756 of_changeset_init(&ovcs->cset); in init_overlay_changeset()
781 ret = -ENOMEM; in init_overlay_changeset()
792 fragment->overlay = overlay_node; in init_overlay_changeset()
793 fragment->target = find_target(node); in init_overlay_changeset()
794 if (!fragment->target) { in init_overlay_changeset()
795 of_node_put(fragment->overlay); in init_overlay_changeset()
796 ret = -EINVAL; in init_overlay_changeset()
805 * if there is a symbols fragment in ovcs->fragments[i] it is in init_overlay_changeset()
810 ovcs->symbols_fragment = 1; in init_overlay_changeset()
812 fragment->overlay = node; in init_overlay_changeset()
813 fragment->target = of_find_node_by_path("/__symbols__"); in init_overlay_changeset()
815 if (!fragment->target) { in init_overlay_changeset()
816 pr_err("symbols in overlay, but not in live tree\n"); in init_overlay_changeset()
817 ret = -EINVAL; in init_overlay_changeset()
826 ret = -EINVAL; in init_overlay_changeset()
830 ovcs->id = id; in init_overlay_changeset()
831 ovcs->count = cnt; in init_overlay_changeset()
832 ovcs->fragments = fragments; in init_overlay_changeset()
850 if (ovcs->cset.entries.next) in free_overlay_changeset()
851 of_changeset_destroy(&ovcs->cset); in free_overlay_changeset()
853 if (ovcs->id) in free_overlay_changeset()
854 idr_remove(&ovcs_idr, ovcs->id); in free_overlay_changeset()
856 for (i = 0; i < ovcs->count; i++) { in free_overlay_changeset()
857 of_node_put(ovcs->fragments[i].target); in free_overlay_changeset()
858 of_node_put(ovcs->fragments[i].overlay); in free_overlay_changeset()
860 kfree(ovcs->fragments); in free_overlay_changeset()
862 * There should be no live pointers into ovcs->overlay_tree and in free_overlay_changeset()
863 * ovcs->fdt due to the policy that overlay notifiers are not allowed in free_overlay_changeset()
866 kfree(ovcs->overlay_tree); in free_overlay_changeset()
867 kfree(ovcs->fdt); in free_overlay_changeset()
874 * of_overlay_apply() - Create and apply an overlay changeset
881 * If an error occurs in a pre-apply notifier, then no changes are made
885 * A non-zero return value will not have created the changeset if error is from:
886 * - parameter checks
887 * - building the changeset
888 * - overlay changeset pre-apply notifier
890 * If an error is returned by an overlay changeset pre-apply notifier
891 * then no further overlay changeset pre-apply notifier will be called.
893 * A non-zero return value will have created the changeset if error is from:
894 * - overlay changeset entry notifier
895 * - overlay changeset post-apply notifier
897 * If an error is returned by an overlay changeset post-apply notifier
898 * then no further overlay changeset post-apply notifier will be called.
929 ret = -EBUSY; in of_overlay_apply()
937 ret = -ENOMEM; in of_overlay_apply()
953 * after overlay_notify(), ovcs->overlay_tree related pointers may have in of_overlay_apply()
954 * leaked to drivers, so can not kfree() tree, aka ovcs->overlay_tree; in of_overlay_apply()
955 * and can not free fdt, aka ovcs->fdt in of_overlay_apply()
959 pr_err("overlay changeset pre-apply notify error %d\n", ret); in of_overlay_apply()
968 ret = __of_changeset_apply_entries(&ovcs->cset, &ret_revert); in of_overlay_apply()
978 ret = __of_changeset_apply_notify(&ovcs->cset); in of_overlay_apply()
983 list_add_tail(&ovcs->ovcs_list, &ovcs_list); in of_overlay_apply()
984 *ovcs_id = ovcs->id; in of_overlay_apply()
988 pr_err("overlay changeset post-apply notify error %d\n", in of_overlay_apply()
1027 return -EINVAL; in of_overlay_fdt_apply()
1032 return -EINVAL; in of_overlay_fdt_apply()
1040 return -ENOMEM; in of_overlay_fdt_apply()
1045 ret = -EINVAL; in of_overlay_fdt_apply()
1108 list_for_each_entry(ce, &ovcs->cset.entries, node) { in node_overlaps_later_cs()
1109 if (find_node(ce->np, remove_ce_node)) { in node_overlaps_later_cs()
1111 __func__, remove_ovcs->id, ovcs->id, in node_overlaps_later_cs()
1115 if (find_node(remove_ce_node, ce->np)) { in node_overlaps_later_cs()
1117 __func__, remove_ovcs->id, ovcs->id, in node_overlaps_later_cs()
1128 * We can safely remove the overlay only if it's the top-most one.
1141 list_for_each_entry(remove_ce, &remove_ovcs->cset.entries, node) { in overlay_removal_is_ok()
1142 if (node_overlaps_later_cs(remove_ovcs, remove_ce->np)) { in overlay_removal_is_ok()
1143 pr_err("overlay #%d is not topmost\n", remove_ovcs->id); in overlay_removal_is_ok()
1152 * of_overlay_remove() - Revert and free an overlay changeset
1159 * then an attempt is made to re-apply any changeset entry that was
1160 * reverted. If an error occurs on re-apply then the state of the device
1164 * A non-zero return value will not revert the changeset if error is from:
1165 * - parameter checks
1166 * - overlay changeset pre-remove notifier
1167 * - overlay changeset entry revert
1169 * If an error is returned by an overlay changeset pre-remove notifier
1170 * then no further overlay changeset pre-remove notifier will be called.
1175 * A non-zero return value will revert the changeset if error is from:
1176 * - overlay changeset entry notifier
1177 * - overlay changeset post-remove notifier
1179 * If an error is returned by an overlay changeset post-remove notifier
1180 * then no further overlay changeset post-remove notifier will be called.
1194 ret = -EBUSY; in of_overlay_remove()
1202 ret = -ENODEV; in of_overlay_remove()
1208 ret = -EBUSY; in of_overlay_remove()
1214 pr_err("overlay changeset pre-remove notify error %d\n", ret); in of_overlay_remove()
1218 list_del(&ovcs->ovcs_list); in of_overlay_remove()
1221 ret = __of_changeset_revert_entries(&ovcs->cset, &ret_apply); in of_overlay_remove()
1228 ret = __of_changeset_revert_notify(&ovcs->cset); in of_overlay_remove()
1237 pr_err("overlay changeset post-remove notify error %d\n", in of_overlay_remove()
1256 * of_overlay_remove_all() - Reverts and frees all overlay changesets
1269 ret = of_overlay_remove(&ovcs->id); in of_overlay_remove_all()