Lines Matching +full:child +full:- +full:nodes
1 // SPDX-License-Identifier: GPL-2.0
25 /* embedded_bootconfig_data is defined in bootconfig-data.S */
31 *size = embedded_bootconfig_data_end - embedded_bootconfig_data; in xbc_get_embedded_bootconfig()
38 * Extra Boot Config (XBC) is given as tree-structured ascii text of
39 * key-value pairs on memory.
42 * a child node (both key and value). A value node may have a next value
83 * xbc_get_info() - Get the information of loaded boot config
84 * @node_size: A pointer to store the number of nodes.
87 * Get the number of used nodes in @node_size if it is not NULL,
89 * Return 0 if the boot config is initialized, or return -ENODEV.
94 return -ENODEV; in xbc_get_info()
106 xbc_err_pos = (int)(p - xbc_data); in xbc_parse_error()
108 return -EINVAL; in xbc_parse_error()
112 * xbc_root_node() - Get the root node of extended boot config
126 * xbc_node_index() - Get the index of XBC node
133 return node - &xbc_nodes[0]; in xbc_node_index()
137 * xbc_node_get_parent() - Get the parent XBC node
145 return node->parent == XBC_NODE_MAX ? NULL : &xbc_nodes[node->parent]; in xbc_node_get_parent()
149 * xbc_node_get_child() - Get the child XBC node
152 * Return the first child node of @node. If the node has no child, return
157 return node->child ? &xbc_nodes[node->child] : NULL; in xbc_node_get_child()
161 * xbc_node_get_next() - Get the next sibling XBC node
166 * has no siblings. (You also has to check whether the parent's child node
171 return node->next ? &xbc_nodes[node->next] : NULL; in xbc_node_get_next()
175 * xbc_node_get_data() - Get the data of XBC node
183 int offset = node->data & ~XBC_VALUE; in xbc_node_get_data()
211 * xbc_node_find_subkey() - Find a subkey node which matches given key
242 * xbc_node_find_value() - Find a value node which matches given key
252 * Note that this returns 0-length string and stores NULL in *@vnode if the
276 * xbc_node_compose_key_after() - Compose partial key string of the XBC node
285 * Returns the total length of the key stored in @buf. Returns -EINVAL
287 * or returns -ERANGE if the key depth is deeper than max depth.
288 * This is expected to be used with xbc_find_node() to list up all (child)
299 return -EINVAL; in xbc_node_compose_key_after()
307 return -ERANGE; in xbc_node_compose_key_after()
311 return -EINVAL; in xbc_node_compose_key_after()
313 while (--depth >= 0) { in xbc_node_compose_key_after()
322 size -= ret; in xbc_node_compose_key_after()
332 * xbc_node_find_next_leaf() - Find the next leaf node under given node
360 if (node == root) /* @root was a leaf, no child node. */ in xbc_node_find_next_leaf()
363 while (!node->next) { in xbc_node_find_next_leaf()
382 * xbc_node_find_next_key_value() - Find the next key-value pair nodes
389 * Note that this returns 0-length string if the key has no value, or
402 if ((*leaf)->child) in xbc_node_find_next_key_value()
412 unsigned long offset = data - xbc_data; in xbc_init_node()
415 return -EINVAL; in xbc_init_node()
417 node->data = (uint16_t)offset | flag; in xbc_init_node()
418 node->child = 0; in xbc_init_node()
419 node->next = 0; in xbc_init_node()
440 while (node->next) in xbc_last_sibling()
448 while (node->child) in xbc_last_child()
461 node->parent = XBC_NODE_MAX; in __xbc_add_sibling()
463 sib->next = xbc_node_index(node); in __xbc_add_sibling()
465 node->parent = xbc_node_index(last_parent); in __xbc_add_sibling()
466 if (!last_parent->child || head) { in __xbc_add_sibling()
467 node->next = last_parent->child; in __xbc_add_sibling()
468 last_parent->child = xbc_node_index(node); in __xbc_add_sibling()
472 sib->next = xbc_node_index(node); in __xbc_add_sibling()
476 xbc_parse_error("Too many nodes", data); in __xbc_add_sibling()
506 while (isalnum(*key) || *key == '-' || *key == '_') in xbc_valid_keyword()
544 brace_index--; in __xbc_close_brace()
552 last_parent = &xbc_nodes[open_brace[brace_index - 1]]; in __xbc_close_brace()
575 p = v - 1; in __xbc_parse_value()
616 if (last_parent->child) in xbc_parse_array()
626 return -ENOMEM; in xbc_parse_array()
629 node->child = 0; in xbc_parse_array()
647 struct xbc_node *node, *child; in __xbc_add_key() local
658 child = xbc_node_get_child(last_parent); in __xbc_add_key()
659 /* Since the value node is the first child, skip it. */ in __xbc_add_key()
660 if (child && xbc_node_is_value(child)) in __xbc_add_key()
661 child = xbc_node_get_next(child); in __xbc_add_key()
662 node = find_match_node(child, k); in __xbc_add_key()
671 return -ENOMEM; in __xbc_add_key()
696 struct xbc_node *child; in xbc_parse_kv() local
708 child = xbc_node_get_child(last_parent); in xbc_parse_kv()
709 if (child && xbc_node_is_value(child)) { in xbc_parse_kv()
713 unsigned short nidx = child->next; in xbc_parse_kv()
715 xbc_init_node(child, v, XBC_VALUE); in xbc_parse_kv()
716 child->next = nidx; /* keep subkeys */ in xbc_parse_kv()
720 last_parent = xbc_last_child(child); in xbc_parse_kv()
722 /* The value node should always be the first child */ in xbc_parse_kv()
724 return -ENOMEM; in xbc_parse_kv()
736 ret = __xbc_close_brace(next - 1); in xbc_parse_kv()
772 return __xbc_open_brace(n - 1); in xbc_open_brace()
784 return __xbc_close_brace(n - 1); in xbc_close_brace()
802 return -ENOENT; in xbc_verify_tree()
833 len -= wlen; in xbc_verify_tree()
839 len -= strlen(xbc_node_get_data(n)) + 1; in xbc_verify_tree()
840 depth--; in xbc_verify_tree()
875 q - 2); in xbc_parse_tree()
902 * _xbc_exit() - Clean up all parsed bootconfig
921 * xbc_init() - Parse given XBC file and build XBC internal tree
929 * Return the number of stored nodes (>0) if succeeded, or -errno
933 * of @buf. If the error is not a parser error, @epos will be -1.
940 *epos = -1; in xbc_init()
945 return -EBUSY; in xbc_init()
951 return -ERANGE; in xbc_init()
958 return -ENOMEM; in xbc_init()
967 *emsg = "Failed to allocate bootconfig nodes"; in xbc_init()
969 return -ENOMEM; in xbc_init()