blob: 67bd5f02c74486a86948960f9861baa41d5d22e0 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001/* SPDX-License-Identifier: GPL-2.0+ */
Simon Glass8b50d522017-05-18 20:08:55 -06002/*
3 * Copyright (c) 2017 Google, Inc
4 * Written by Simon Glass <sjg@chromium.org>
5 *
Simon Glass8b50d522017-05-18 20:08:55 -06006 * Support for a 'live' (as opposed to flat) device tree
7 */
8
9#ifndef _OF_LIVE_H
10#define _OF_LIVE_H
11
Simon Glass62b1db32023-09-26 08:14:43 -060012struct abuf;
Simon Glass8b50d522017-05-18 20:08:55 -060013struct device_node;
14
15/**
16 * of_live_build() - build a live (hierarchical) tree from a flat DT
17 *
18 * @fdt_blob: Input tree to convert
19 * @rootp: Returns live tree that was created
Heinrich Schuchardt185f8122022-01-19 18:05:50 +010020 * Return: 0 if OK, -ve on error
Simon Glass8b50d522017-05-18 20:08:55 -060021 */
22int of_live_build(const void *fdt_blob, struct device_node **rootp);
23
Simon Glass33104842022-07-30 15:52:08 -060024/**
25 * unflatten_device_tree() - create tree of device_nodes from flat blob
26 *
27 * Note that this allocates a single block of memory, pointed to by *mynodes.
28 * To free the tree, use free(*mynodes)
29 *
30 * unflattens a device-tree, creating the
31 * tree of struct device_node. It also fills the "name" and "type"
32 * pointers of the nodes so the normal device-tree walking functions
33 * can be used.
34 * @blob: The blob to expand
35 * @mynodes: The device_node tree created by the call
36 * Return: 0 if OK, -ve on error
37 */
38int unflatten_device_tree(const void *blob, struct device_node **mynodes);
39
Simon Glassa8f2ac22023-06-01 10:22:42 -060040/**
41 * of_live_free() - Dispose of a livetree
42 *
43 * This frees memory used by the tree, after which @root becomes invalid and
44 * cannot be used
45 *
46 * @root: Tree to dispose
47 */
48void of_live_free(struct device_node *root);
49
Simon Glasse0c3c212023-09-26 08:14:40 -060050/**
51 * of_live_create_empty() - Create a new, empty tree
52 *
53 * @rootp: Returns the root node of the created tree
54 * Return: 0 if OK, -ENOMEM if out of memory
55 */
56int of_live_create_empty(struct device_node **rootp);
57
Simon Glass62b1db32023-09-26 08:14:43 -060058/**
59 * of_live_flatten() - Create an FDT from a hierarchical tree
60 *
61 * @root: Root node of tree to convert
62 * @buf: Buffer to return the tree (inited by this function)
63 * Return: 0 if OK, -ENOMEM if out of memory
64 */
65int of_live_flatten(const struct device_node *root, struct abuf *buf);
66
Simon Glass8b50d522017-05-18 20:08:55 -060067#endif