blob: f8bac73a319fabee0c669c46dcd354823de911b7 [file] [log] [blame]
Gerald Van Baren7cd5da02007-03-31 11:59:59 -04001/*
2 * libfdt - Flat Device Tree manipulation
3 * Copyright (C) 2006 David Gibson, IBM Corporation.
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public License
7 * as published by the Free Software Foundation; either version 2.1 of
8 * the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 */
19
Gerald Van Baren6679f922007-04-06 14:17:14 -040020#ifndef _LIBFDT_H
21#define _LIBFDT_H
22
Gerald Van Baren7cd5da02007-03-31 11:59:59 -040023#include <fdt.h>
24#include <libfdt_env.h>
25
26#define FDT_FIRST_SUPPORTED_VERSION 0x10
27#define FDT_LAST_SUPPORTED_VERSION 0x11
28
29/* Error codes: informative error codes */
30#define FDT_ERR_NOTFOUND 1
31#define FDT_ERR_EXISTS 2
32#define FDT_ERR_NOSPACE 3
33
34/* Error codes: codes for bad parameters */
35#define FDT_ERR_BADOFFSET 4
36#define FDT_ERR_BADPATH 5
37#define FDT_ERR_BADSTATE 6
38
39/* Error codes: codes for bad device tree blobs */
40#define FDT_ERR_TRUNCATED 7
41#define FDT_ERR_BADMAGIC 8
42#define FDT_ERR_BADVERSION 9
43#define FDT_ERR_BADSTRUCTURE 10
44#define FDT_ERR_BADLAYOUT 11
45
46#define FDT_ERR_MAX 11
47
48#define fdt_get_header(fdt, field) \
49 (fdt32_to_cpu(((struct fdt_header *)(fdt))->field))
Wolfgang Denk94abd7c2007-04-04 01:49:15 +020050#define fdt_magic(fdt) (fdt_get_header(fdt, magic))
Gerald Van Baren7cd5da02007-03-31 11:59:59 -040051#define fdt_totalsize(fdt) (fdt_get_header(fdt, totalsize))
52#define fdt_off_dt_struct(fdt) (fdt_get_header(fdt, off_dt_struct))
53#define fdt_off_dt_strings(fdt) (fdt_get_header(fdt, off_dt_strings))
54#define fdt_off_mem_rsvmap(fdt) (fdt_get_header(fdt, off_mem_rsvmap))
55#define fdt_version(fdt) (fdt_get_header(fdt, version))
Wolfgang Denk94abd7c2007-04-04 01:49:15 +020056#define fdt_last_comp_version(fdt) (fdt_get_header(fdt, last_comp_version))
57#define fdt_boot_cpuid_phys(fdt) (fdt_get_header(fdt, boot_cpuid_phys))
58#define fdt_size_dt_strings(fdt) (fdt_get_header(fdt, size_dt_strings))
Gerald Van Baren7cd5da02007-03-31 11:59:59 -040059#define fdt_size_dt_struct(fdt) (fdt_get_header(fdt, size_dt_struct))
60
61#define fdt_set_header(fdt, field, val) \
62 ((struct fdt_header *)(fdt))->field = cpu_to_fdt32(val)
63
Gerald Van Baren6679f922007-04-06 14:17:14 -040064int fdt_check_header(const void *fdt);
65
Gerald Van Baren7cd5da02007-03-31 11:59:59 -040066void *fdt_offset_ptr(const void *fdt, int offset, int checklen);
67
68#define fdt_offset_ptr_typed(fdt, offset, var) \
69 ((typeof(var))(fdt_offset_ptr((fdt), (offset), sizeof(*(var)))))
70
71int fdt_move(const void *fdt, void *buf, int bufsize);
72
73/* Read-only functions */
74char *fdt_string(const void *fdt, int stroffset);
75
76int fdt_subnode_offset_namelen(const void *fdt, int parentoffset,
77 const char *name, int namelen);
78int fdt_subnode_offset(const void *fdt, int parentoffset, const char *name);
79
80int fdt_path_offset(const void *fdt, const char *path);
81
82struct fdt_property *fdt_get_property(const void *fdt, int nodeoffset,
83 const char *name, int *lenp);
84void *fdt_getprop(const void *fdt, int nodeoffset,
85 const char *name, int *lenp);
86
Gerald Van Baren3af0d582007-03-31 12:13:43 -040087uint32_t fdt_next_tag(const void *fdt, int offset,
Wolfgang Denk94abd7c2007-04-04 01:49:15 +020088 int *nextoffset, char **namep);
Gerald Van Baren3f9f08c2007-04-14 22:46:41 -040089int fdt_num_reservemap(void *fdt, int *used, int *total);
90int fdt_get_reservemap(void *fdt, int n, struct fdt_reserve_entry *re);
Gerald Van Baren3af0d582007-03-31 12:13:43 -040091
Gerald Van Baren7cd5da02007-03-31 11:59:59 -040092/* Write-in-place functions */
93int fdt_setprop_inplace(void *fdt, int nodeoffset, const char *name,
94 const void *val, int len);
95
96#define fdt_setprop_inplace_typed(fdt, nodeoffset, name, val) \
97 ({ \
98 typeof(val) x = val; \
99 fdt_setprop_inplace(fdt, nodeoffset, name, &x, sizeof(x)); \
100 })
101
102int fdt_nop_property(void *fdt, int nodeoffset, const char *name);
103int fdt_nop_node(void *fdt, int nodeoffset);
Gerald Van Baren3f9f08c2007-04-14 22:46:41 -0400104int fdt_insert_reservemap_entry(void *fdt, int n, uint64_t addr, uint64_t size);
105
Gerald Van Baren7cd5da02007-03-31 11:59:59 -0400106
107/* Sequential-write functions */
108int fdt_create(void *buf, int bufsize);
109int fdt_add_reservemap_entry(void *fdt, uint64_t addr, uint64_t size);
110int fdt_finish_reservemap(void *fdt);
111int fdt_begin_node(void *fdt, const char *name);
112int fdt_property(void *fdt, const char *name, const void *val, int len);
113#define fdt_property_typed(fdt, name, val) \
114 ({ \
115 typeof(val) x = (val); \
116 fdt_property((fdt), (name), &x, sizeof(x)); \
117 })
118#define fdt_property_string(fdt, name, str) \
119 fdt_property(fdt, name, str, strlen(str)+1)
120int fdt_end_node(void *fdt);
121int fdt_finish(void *fdt);
Gerald Van Baren3f9f08c2007-04-14 22:46:41 -0400122int fdt_replace_reservemap_entry(void *fdt, int n, uint64_t addr, uint64_t size);
Gerald Van Baren7cd5da02007-03-31 11:59:59 -0400123
124/* Read-write functions */
125int fdt_open_into(void *fdt, void *buf, int bufsize);
126int fdt_pack(void *fdt);
127
128int fdt_setprop(void *fdt, int nodeoffset, const char *name,
129 const void *val, int len);
130#define fdt_setprop_typed(fdt, nodeoffset, name, val) \
131 ({ \
132 typeof(val) x = (val); \
133 fdt_setprop((fdt), (nodeoffset), (name), &x, sizeof(x)); \
134 })
135#define fdt_setprop_string(fdt, nodeoffset, name, str) \
136 fdt_setprop((fdt), (nodeoffset), (name), (str), strlen(str)+1)
137int fdt_delprop(void *fdt, int nodeoffset, const char *name);
138int fdt_add_subnode_namelen(void *fdt, int parentoffset,
139 const char *name, int namelen);
140int fdt_add_subnode(void *fdt, int parentoffset, const char *name);
141int fdt_del_node(void *fdt, int nodeoffset);
142
143/* Extra functions */
144const char *fdt_strerror(int errval);
145
146#endif /* _LIBFDT_H */