1 /*
2  * Definitions for working with the Flattened Device Tree data format
3  *
4  * Copyright 2009 Benjamin Herrenschmidt, IBM Corp
5  * benh@kernel.crashing.org
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * version 2 as published by the Free Software Foundation.
10  */
11 
12 #ifndef _LINUX_OF_FDT_H
13 #define _LINUX_OF_FDT_H
14 
15 #include <linux/types.h>
16 #include <linux/init.h>
17 
18 /* Definitions used by the flattened device tree */
19 #define OF_DT_HEADER		0xd00dfeed	/* marker */
20 #define OF_DT_BEGIN_NODE	0x1		/* Start of node, full name */
21 #define OF_DT_END_NODE		0x2		/* End node */
22 #define OF_DT_PROP		0x3		/* Property: name off, size,
23 						 * content */
24 #define OF_DT_NOP		0x4		/* nop */
25 #define OF_DT_END		0x9
26 
27 #define OF_DT_VERSION		0x10
28 
29 #ifndef __ASSEMBLY__
30 /*
31  * This is what gets passed to the kernel by prom_init or kexec
32  *
33  * The dt struct contains the device tree structure, full pathes and
34  * property contents. The dt strings contain a separate block with just
35  * the strings for the property names, and is fully page aligned and
36  * self contained in a page, so that it can be kept around by the kernel,
37  * each property name appears only once in this page (cheap compression)
38  *
39  * the mem_rsvmap contains a map of reserved ranges of physical memory,
40  * passing it here instead of in the device-tree itself greatly simplifies
41  * the job of everybody. It's just a list of u64 pairs (base/size) that
42  * ends when size is 0
43  */
44 struct boot_param_header {
45 	__be32	magic;			/* magic word OF_DT_HEADER */
46 	__be32	totalsize;		/* total size of DT block */
47 	__be32	off_dt_struct;		/* offset to structure */
48 	__be32	off_dt_strings;		/* offset to strings */
49 	__be32	off_mem_rsvmap;		/* offset to memory reserve map */
50 	__be32	version;		/* format version */
51 	__be32	last_comp_version;	/* last compatible version */
52 	/* version 2 fields below */
53 	__be32	boot_cpuid_phys;	/* Physical CPU id we're booting on */
54 	/* version 3 fields below */
55 	__be32	dt_strings_size;	/* size of the DT strings block */
56 	/* version 17 fields below */
57 	__be32	dt_struct_size;		/* size of the DT structure block */
58 };
59 
60 #if defined(CONFIG_OF_FLATTREE)
61 
62 struct device_node;
63 
64 /* For scanning an arbitrary device-tree at any time */
65 extern char *of_fdt_get_string(struct boot_param_header *blob, u32 offset);
66 extern void *of_fdt_get_property(struct boot_param_header *blob,
67 				 unsigned long node,
68 				 const char *name,
69 				 unsigned long *size);
70 extern int of_fdt_is_compatible(struct boot_param_header *blob,
71 				unsigned long node,
72 				const char *compat);
73 extern int of_fdt_match(struct boot_param_header *blob, unsigned long node,
74 			const char **compat);
75 extern void of_fdt_unflatten_tree(unsigned long *blob,
76 			       struct device_node **mynodes);
77 
78 /* TBD: Temporary export of fdt globals - remove when code fully merged */
79 extern int __initdata dt_root_addr_cells;
80 extern int __initdata dt_root_size_cells;
81 extern struct boot_param_header *initial_boot_params;
82 
83 /* For scanning the flat device-tree at boot time */
84 extern char *find_flat_dt_string(u32 offset);
85 extern int of_scan_flat_dt(int (*it)(unsigned long node, const char *uname,
86 				     int depth, void *data),
87 			   void *data);
88 extern void *of_get_flat_dt_prop(unsigned long node, const char *name,
89 				 unsigned long *size);
90 extern int of_flat_dt_is_compatible(unsigned long node, const char *name);
91 extern int of_flat_dt_match(unsigned long node, const char **matches);
92 extern unsigned long of_get_flat_dt_root(void);
93 
94 extern int early_init_dt_scan_chosen(unsigned long node, const char *uname,
95 				     int depth, void *data);
96 extern void early_init_dt_check_for_initrd(unsigned long node);
97 extern int early_init_dt_scan_memory(unsigned long node, const char *uname,
98 				     int depth, void *data);
99 extern void early_init_dt_add_memory_arch(u64 base, u64 size);
100 extern void * early_init_dt_alloc_memory_arch(u64 size, u64 align);
101 extern u64 dt_mem_next_cell(int s, __be32 **cellp);
102 
103 /*
104  * If BLK_DEV_INITRD, the fdt early init code will call this function,
105  * to be provided by the arch code. start and end are specified as
106  * physical addresses.
107  */
108 #ifdef CONFIG_BLK_DEV_INITRD
109 extern void early_init_dt_setup_initrd_arch(unsigned long start,
110 					    unsigned long end);
111 #endif
112 
113 /* Early flat tree scan hooks */
114 extern int early_init_dt_scan_root(unsigned long node, const char *uname,
115 				   int depth, void *data);
116 
117 /* Other Prototypes */
118 extern void unflatten_device_tree(void);
119 extern void early_init_devtree(void *);
120 #else /* CONFIG_OF_FLATTREE */
unflatten_device_tree(void)121 static inline void unflatten_device_tree(void) {}
122 #endif /* CONFIG_OF_FLATTREE */
123 
124 #endif /* __ASSEMBLY__ */
125 #endif /* _LINUX_OF_FDT_H */
126