xref: /openbsd/sys/dev/ofw/fdt.h (revision 274d7c50)
1 /*	$OpenBSD: fdt.h,v 1.5 2016/07/26 22:10:10 patrick Exp $	*/
2 
3 /*
4  * Copyright (c) 2009 Dariusz Swiderski <sfires@sfires.net>
5  *
6  * Permission to use, copy, modify, and distribute this software for any
7  * purpose with or without fee is hereby granted, provided that the above
8  * copyright notice and this permission notice appear in all copies.
9  *
10  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17  */
18 
19 struct fdt_head {
20 	u_int32_t fh_magic;
21 	u_int32_t fh_size;
22 	u_int32_t fh_struct_off;
23 	u_int32_t fh_strings_off;
24 	u_int32_t fh_reserve_off;
25 	u_int32_t fh_version;
26 	u_int32_t fh_comp_ver;     /* last compatible version */
27 	u_int32_t fh_boot_cpu_id;  /* fh_version >=2 */
28 	u_int32_t fh_strings_size; /* fh_version >=3 */
29 	u_int32_t fh_struct_size;  /* fh_version >=17 */
30 };
31 
32 struct fdt {
33 	struct fdt_head *header;
34 	void *		tree;
35 	void *		strings;
36 	void *		memory;
37 	int		version;
38 	int		strings_size;
39 };
40 
41 struct fdt_reg {
42 	uint64_t	addr;
43 	uint64_t	size;
44 };
45 
46 #define FDT_MAGIC	0xd00dfeed
47 #define FDT_NODE_BEGIN	0x01
48 #define FDT_NODE_END	0x02
49 #define FDT_PROPERTY	0x03
50 #define FDT_NOP		0x04
51 #define FDT_END		0x09
52 
53 #define FDT_CODE_VERSION 0x11
54 
55 int	 fdt_init(void *);
56 size_t	 fdt_get_size(void *);
57 void	*fdt_next_node(void *);
58 void	*fdt_child_node(void *);
59 char	*fdt_node_name(void *);
60 void	*fdt_find_node(char *);
61 int	 fdt_node_property(void *, char *, char **);
62 void	*fdt_parent_node(void *);
63 void	*fdt_find_phandle(uint32_t);
64 int	 fdt_get_reg(void *, int, struct fdt_reg *);
65 int	 fdt_is_compatible(void *, const char *);
66 #ifdef DEBUG
67 void	*fdt_print_property(void *, int);
68 void 	 fdt_print_node(void *, int);
69 void	 fdt_print_tree(void);
70 #endif
71