aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/of
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/of')
-rw-r--r--drivers/of/Kconfig4
-rw-r--r--drivers/of/Makefile1
-rw-r--r--drivers/of/base.c212
-rw-r--r--drivers/of/fdt.c528
4 files changed, 745 insertions, 0 deletions
diff --git a/drivers/of/Kconfig b/drivers/of/Kconfig
index d2fa27c5c1b2..462825e03123 100644
--- a/drivers/of/Kconfig
+++ b/drivers/of/Kconfig
@@ -1,3 +1,7 @@
1config OF_FLATTREE
2 bool
3 depends on OF
4
1config OF_DEVICE 5config OF_DEVICE
2 def_bool y 6 def_bool y
3 depends on OF && (SPARC || PPC_OF || MICROBLAZE) 7 depends on OF && (SPARC || PPC_OF || MICROBLAZE)
diff --git a/drivers/of/Makefile b/drivers/of/Makefile
index bdfb5f5d4b06..f232cc98ce00 100644
--- a/drivers/of/Makefile
+++ b/drivers/of/Makefile
@@ -1,4 +1,5 @@
1obj-y = base.o 1obj-y = base.o
2obj-$(CONFIG_OF_FLATTREE) += fdt.o
2obj-$(CONFIG_OF_DEVICE) += device.o platform.o 3obj-$(CONFIG_OF_DEVICE) += device.o platform.o
3obj-$(CONFIG_OF_GPIO) += gpio.o 4obj-$(CONFIG_OF_GPIO) += gpio.o
4obj-$(CONFIG_OF_I2C) += of_i2c.o 5obj-$(CONFIG_OF_I2C) += of_i2c.o
diff --git a/drivers/of/base.c b/drivers/of/base.c
index e6627b2320f1..cf89ee6253f3 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -60,6 +60,81 @@ int of_n_size_cells(struct device_node *np)
60} 60}
61EXPORT_SYMBOL(of_n_size_cells); 61EXPORT_SYMBOL(of_n_size_cells);
62 62
63#if !defined(CONFIG_SPARC) /* SPARC doesn't do ref counting (yet) */
64/**
65 * of_node_get - Increment refcount of a node
66 * @node: Node to inc refcount, NULL is supported to
67 * simplify writing of callers
68 *
69 * Returns node.
70 */
71struct device_node *of_node_get(struct device_node *node)
72{
73 if (node)
74 kref_get(&node->kref);
75 return node;
76}
77EXPORT_SYMBOL(of_node_get);
78
79static inline struct device_node *kref_to_device_node(struct kref *kref)
80{
81 return container_of(kref, struct device_node, kref);
82}
83
84/**
85 * of_node_release - release a dynamically allocated node
86 * @kref: kref element of the node to be released
87 *
88 * In of_node_put() this function is passed to kref_put()
89 * as the destructor.
90 */
91static void of_node_release(struct kref *kref)
92{
93 struct device_node *node = kref_to_device_node(kref);
94 struct property *prop = node->properties;
95
96 /* We should never be releasing nodes that haven't been detached. */
97 if (!of_node_check_flag(node, OF_DETACHED)) {
98 pr_err("ERROR: Bad of_node_put() on %s\n", node->full_name);
99 dump_stack();
100 kref_init(&node->kref);
101 return;
102 }
103
104 if (!of_node_check_flag(node, OF_DYNAMIC))
105 return;
106
107 while (prop) {
108 struct property *next = prop->next;
109 kfree(prop->name);
110 kfree(prop->value);
111 kfree(prop);
112 prop = next;
113
114 if (!prop) {
115 prop = node->deadprops;
116 node->deadprops = NULL;
117 }
118 }
119 kfree(node->full_name);
120 kfree(node->data);
121 kfree(node);
122}
123
124/**
125 * of_node_put - Decrement refcount of a node
126 * @node: Node to dec refcount, NULL is supported to
127 * simplify writing of callers
128 *
129 */
130void of_node_put(struct device_node *node)
131{
132 if (node)
133 kref_put(&node->kref, of_node_release);
134}
135EXPORT_SYMBOL(of_node_put);
136#endif /* !CONFIG_SPARC */
137
63struct property *of_find_property(const struct device_node *np, 138struct property *of_find_property(const struct device_node *np,
64 const char *name, 139 const char *name,
65 int *lenp) 140 int *lenp)
@@ -144,6 +219,27 @@ int of_device_is_compatible(const struct device_node *device,
144EXPORT_SYMBOL(of_device_is_compatible); 219EXPORT_SYMBOL(of_device_is_compatible);
145 220
146/** 221/**
222 * machine_is_compatible - Test root of device tree for a given compatible value
223 * @compat: compatible string to look for in root node's compatible property.
224 *
225 * Returns true if the root node has the given value in its
226 * compatible property.
227 */
228int machine_is_compatible(const char *compat)
229{
230 struct device_node *root;
231 int rc = 0;
232
233 root = of_find_node_by_path("/");
234 if (root) {
235 rc = of_device_is_compatible(root, compat);
236 of_node_put(root);
237 }
238 return rc;
239}
240EXPORT_SYMBOL(machine_is_compatible);
241
242/**
147 * of_device_is_available - check if a device is available for use 243 * of_device_is_available - check if a device is available for use
148 * 244 *
149 * @device: Node to check for availability 245 * @device: Node to check for availability
@@ -658,3 +754,119 @@ err0:
658 return ret; 754 return ret;
659} 755}
660EXPORT_SYMBOL(of_parse_phandles_with_args); 756EXPORT_SYMBOL(of_parse_phandles_with_args);
757
758/**
759 * prom_add_property - Add a property to a node
760 */
761int prom_add_property(struct device_node *np, struct property *prop)
762{
763 struct property **next;
764 unsigned long flags;
765
766 prop->next = NULL;
767 write_lock_irqsave(&devtree_lock, flags);
768 next = &np->properties;
769 while (*next) {
770 if (strcmp(prop->name, (*next)->name) == 0) {
771 /* duplicate ! don't insert it */
772 write_unlock_irqrestore(&devtree_lock, flags);
773 return -1;
774 }
775 next = &(*next)->next;
776 }
777 *next = prop;
778 write_unlock_irqrestore(&devtree_lock, flags);
779
780#ifdef CONFIG_PROC_DEVICETREE
781 /* try to add to proc as well if it was initialized */
782 if (np->pde)
783 proc_device_tree_add_prop(np->pde, prop);
784#endif /* CONFIG_PROC_DEVICETREE */
785
786 return 0;
787}
788
789/**
790 * prom_remove_property - Remove a property from a node.
791 *
792 * Note that we don't actually remove it, since we have given out
793 * who-knows-how-many pointers to the data using get-property.
794 * Instead we just move the property to the "dead properties"
795 * list, so it won't be found any more.
796 */
797int prom_remove_property(struct device_node *np, struct property *prop)
798{
799 struct property **next;
800 unsigned long flags;
801 int found = 0;
802
803 write_lock_irqsave(&devtree_lock, flags);
804 next = &np->properties;
805 while (*next) {
806 if (*next == prop) {
807 /* found the node */
808 *next = prop->next;
809 prop->next = np->deadprops;
810 np->deadprops = prop;
811 found = 1;
812 break;
813 }
814 next = &(*next)->next;
815 }
816 write_unlock_irqrestore(&devtree_lock, flags);
817
818 if (!found)
819 return -ENODEV;
820
821#ifdef CONFIG_PROC_DEVICETREE
822 /* try to remove the proc node as well */
823 if (np->pde)
824 proc_device_tree_remove_prop(np->pde, prop);
825#endif /* CONFIG_PROC_DEVICETREE */
826
827 return 0;
828}
829
830/*
831 * prom_update_property - Update a property in a node.
832 *
833 * Note that we don't actually remove it, since we have given out
834 * who-knows-how-many pointers to the data using get-property.
835 * Instead we just move the property to the "dead properties" list,
836 * and add the new property to the property list
837 */
838int prom_update_property(struct device_node *np,
839 struct property *newprop,
840 struct property *oldprop)
841{
842 struct property **next;
843 unsigned long flags;
844 int found = 0;
845
846 write_lock_irqsave(&devtree_lock, flags);
847 next = &np->properties;
848 while (*next) {
849 if (*next == oldprop) {
850 /* found the node */
851 newprop->next = oldprop->next;
852 *next = newprop;
853 oldprop->next = np->deadprops;
854 np->deadprops = oldprop;
855 found = 1;
856 break;
857 }
858 next = &(*next)->next;
859 }
860 write_unlock_irqrestore(&devtree_lock, flags);
861
862 if (!found)
863 return -ENODEV;
864
865#ifdef CONFIG_PROC_DEVICETREE
866 /* try to add to proc as well if it was initialized */
867 if (np->pde)
868 proc_device_tree_update_prop(np->pde, newprop, oldprop);
869#endif /* CONFIG_PROC_DEVICETREE */
870
871 return 0;
872}
diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c
new file mode 100644
index 000000000000..7f8861121a31
--- /dev/null
+++ b/drivers/of/fdt.c
@@ -0,0 +1,528 @@
1/*
2 * Functions 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#include <linux/kernel.h>
13#include <linux/lmb.h>
14#include <linux/initrd.h>
15#include <linux/of.h>
16#include <linux/of_fdt.h>
17
18#ifdef CONFIG_PPC
19#include <asm/machdep.h>
20#endif /* CONFIG_PPC */
21
22int __initdata dt_root_addr_cells;
23int __initdata dt_root_size_cells;
24
25struct boot_param_header *initial_boot_params;
26
27char *find_flat_dt_string(u32 offset)
28{
29 return ((char *)initial_boot_params) +
30 initial_boot_params->off_dt_strings + offset;
31}
32
33/**
34 * of_scan_flat_dt - scan flattened tree blob and call callback on each.
35 * @it: callback function
36 * @data: context data pointer
37 *
38 * This function is used to scan the flattened device-tree, it is
39 * used to extract the memory information at boot before we can
40 * unflatten the tree
41 */
42int __init of_scan_flat_dt(int (*it)(unsigned long node,
43 const char *uname, int depth,
44 void *data),
45 void *data)
46{
47 unsigned long p = ((unsigned long)initial_boot_params) +
48 initial_boot_params->off_dt_struct;
49 int rc = 0;
50 int depth = -1;
51
52 do {
53 u32 tag = *((u32 *)p);
54 char *pathp;
55
56 p += 4;
57 if (tag == OF_DT_END_NODE) {
58 depth--;
59 continue;
60 }
61 if (tag == OF_DT_NOP)
62 continue;
63 if (tag == OF_DT_END)
64 break;
65 if (tag == OF_DT_PROP) {
66 u32 sz = *((u32 *)p);
67 p += 8;
68 if (initial_boot_params->version < 0x10)
69 p = _ALIGN(p, sz >= 8 ? 8 : 4);
70 p += sz;
71 p = _ALIGN(p, 4);
72 continue;
73 }
74 if (tag != OF_DT_BEGIN_NODE) {
75 pr_err("Invalid tag %x in flat device tree!\n", tag);
76 return -EINVAL;
77 }
78 depth++;
79 pathp = (char *)p;
80 p = _ALIGN(p + strlen(pathp) + 1, 4);
81 if ((*pathp) == '/') {
82 char *lp, *np;
83 for (lp = NULL, np = pathp; *np; np++)
84 if ((*np) == '/')
85 lp = np+1;
86 if (lp != NULL)
87 pathp = lp;
88 }
89 rc = it(p, pathp, depth, data);
90 if (rc != 0)
91 break;
92 } while (1);
93
94 return rc;
95}
96
97/**
98 * of_get_flat_dt_root - find the root node in the flat blob
99 */
100unsigned long __init of_get_flat_dt_root(void)
101{
102 unsigned long p = ((unsigned long)initial_boot_params) +
103 initial_boot_params->off_dt_struct;
104
105 while (*((u32 *)p) == OF_DT_NOP)
106 p += 4;
107 BUG_ON(*((u32 *)p) != OF_DT_BEGIN_NODE);
108 p += 4;
109 return _ALIGN(p + strlen((char *)p) + 1, 4);
110}
111
112/**
113 * of_get_flat_dt_prop - Given a node in the flat blob, return the property ptr
114 *
115 * This function can be used within scan_flattened_dt callback to get
116 * access to properties
117 */
118void *__init of_get_flat_dt_prop(unsigned long node, const char *name,
119 unsigned long *size)
120{
121 unsigned long p = node;
122
123 do {
124 u32 tag = *((u32 *)p);
125 u32 sz, noff;
126 const char *nstr;
127
128 p += 4;
129 if (tag == OF_DT_NOP)
130 continue;
131 if (tag != OF_DT_PROP)
132 return NULL;
133
134 sz = *((u32 *)p);
135 noff = *((u32 *)(p + 4));
136 p += 8;
137 if (initial_boot_params->version < 0x10)
138 p = _ALIGN(p, sz >= 8 ? 8 : 4);
139
140 nstr = find_flat_dt_string(noff);
141 if (nstr == NULL) {
142 pr_warning("Can't find property index name !\n");
143 return NULL;
144 }
145 if (strcmp(name, nstr) == 0) {
146 if (size)
147 *size = sz;
148 return (void *)p;
149 }
150 p += sz;
151 p = _ALIGN(p, 4);
152 } while (1);
153}
154
155/**
156 * of_flat_dt_is_compatible - Return true if given node has compat in compatible list
157 * @node: node to test
158 * @compat: compatible string to compare with compatible list.
159 */
160int __init of_flat_dt_is_compatible(unsigned long node, const char *compat)
161{
162 const char *cp;
163 unsigned long cplen, l;
164
165 cp = of_get_flat_dt_prop(node, "compatible", &cplen);
166 if (cp == NULL)
167 return 0;
168 while (cplen > 0) {
169 if (strncasecmp(cp, compat, strlen(compat)) == 0)
170 return 1;
171 l = strlen(cp) + 1;
172 cp += l;
173 cplen -= l;
174 }
175
176 return 0;
177}
178
179static void *__init unflatten_dt_alloc(unsigned long *mem, unsigned long size,
180 unsigned long align)
181{
182 void *res;
183
184 *mem = _ALIGN(*mem, align);
185 res = (void *)*mem;
186 *mem += size;
187
188 return res;
189}
190
191/**
192 * unflatten_dt_node - Alloc and populate a device_node from the flat tree
193 * @p: pointer to node in flat tree
194 * @dad: Parent struct device_node
195 * @allnextpp: pointer to ->allnext from last allocated device_node
196 * @fpsize: Size of the node path up at the current depth.
197 */
198unsigned long __init unflatten_dt_node(unsigned long mem,
199 unsigned long *p,
200 struct device_node *dad,
201 struct device_node ***allnextpp,
202 unsigned long fpsize)
203{
204 struct device_node *np;
205 struct property *pp, **prev_pp = NULL;
206 char *pathp;
207 u32 tag;
208 unsigned int l, allocl;
209 int has_name = 0;
210 int new_format = 0;
211
212 tag = *((u32 *)(*p));
213 if (tag != OF_DT_BEGIN_NODE) {
214 pr_err("Weird tag at start of node: %x\n", tag);
215 return mem;
216 }
217 *p += 4;
218 pathp = (char *)*p;
219 l = allocl = strlen(pathp) + 1;
220 *p = _ALIGN(*p + l, 4);
221
222 /* version 0x10 has a more compact unit name here instead of the full
223 * path. we accumulate the full path size using "fpsize", we'll rebuild
224 * it later. We detect this because the first character of the name is
225 * not '/'.
226 */
227 if ((*pathp) != '/') {
228 new_format = 1;
229 if (fpsize == 0) {
230 /* root node: special case. fpsize accounts for path
231 * plus terminating zero. root node only has '/', so
232 * fpsize should be 2, but we want to avoid the first
233 * level nodes to have two '/' so we use fpsize 1 here
234 */
235 fpsize = 1;
236 allocl = 2;
237 } else {
238 /* account for '/' and path size minus terminal 0
239 * already in 'l'
240 */
241 fpsize += l;
242 allocl = fpsize;
243 }
244 }
245
246 np = unflatten_dt_alloc(&mem, sizeof(struct device_node) + allocl,
247 __alignof__(struct device_node));
248 if (allnextpp) {
249 memset(np, 0, sizeof(*np));
250 np->full_name = ((char *)np) + sizeof(struct device_node);
251 if (new_format) {
252 char *fn = np->full_name;
253 /* rebuild full path for new format */
254 if (dad && dad->parent) {
255 strcpy(fn, dad->full_name);
256#ifdef DEBUG
257 if ((strlen(fn) + l + 1) != allocl) {
258 pr_debug("%s: p: %d, l: %d, a: %d\n",
259 pathp, (int)strlen(fn),
260 l, allocl);
261 }
262#endif
263 fn += strlen(fn);
264 }
265 *(fn++) = '/';
266 memcpy(fn, pathp, l);
267 } else
268 memcpy(np->full_name, pathp, l);
269 prev_pp = &np->properties;
270 **allnextpp = np;
271 *allnextpp = &np->allnext;
272 if (dad != NULL) {
273 np->parent = dad;
274 /* we temporarily use the next field as `last_child'*/
275 if (dad->next == NULL)
276 dad->child = np;
277 else
278 dad->next->sibling = np;
279 dad->next = np;
280 }
281 kref_init(&np->kref);
282 }
283 while (1) {
284 u32 sz, noff;
285 char *pname;
286
287 tag = *((u32 *)(*p));
288 if (tag == OF_DT_NOP) {
289 *p += 4;
290 continue;
291 }
292 if (tag != OF_DT_PROP)
293 break;
294 *p += 4;
295 sz = *((u32 *)(*p));
296 noff = *((u32 *)((*p) + 4));
297 *p += 8;
298 if (initial_boot_params->version < 0x10)
299 *p = _ALIGN(*p, sz >= 8 ? 8 : 4);
300
301 pname = find_flat_dt_string(noff);
302 if (pname == NULL) {
303 pr_info("Can't find property name in list !\n");
304 break;
305 }
306 if (strcmp(pname, "name") == 0)
307 has_name = 1;
308 l = strlen(pname) + 1;
309 pp = unflatten_dt_alloc(&mem, sizeof(struct property),
310 __alignof__(struct property));
311 if (allnextpp) {
312 if (strcmp(pname, "linux,phandle") == 0) {
313 if (np->phandle == 0)
314 np->phandle = *((u32 *)*p);
315 }
316 if (strcmp(pname, "ibm,phandle") == 0)
317 np->phandle = *((u32 *)*p);
318 pp->name = pname;
319 pp->length = sz;
320 pp->value = (void *)*p;
321 *prev_pp = pp;
322 prev_pp = &pp->next;
323 }
324 *p = _ALIGN((*p) + sz, 4);
325 }
326 /* with version 0x10 we may not have the name property, recreate
327 * it here from the unit name if absent
328 */
329 if (!has_name) {
330 char *p1 = pathp, *ps = pathp, *pa = NULL;
331 int sz;
332
333 while (*p1) {
334 if ((*p1) == '@')
335 pa = p1;
336 if ((*p1) == '/')
337 ps = p1 + 1;
338 p1++;
339 }
340 if (pa < ps)
341 pa = p1;
342 sz = (pa - ps) + 1;
343 pp = unflatten_dt_alloc(&mem, sizeof(struct property) + sz,
344 __alignof__(struct property));
345 if (allnextpp) {
346 pp->name = "name";
347 pp->length = sz;
348 pp->value = pp + 1;
349 *prev_pp = pp;
350 prev_pp = &pp->next;
351 memcpy(pp->value, ps, sz - 1);
352 ((char *)pp->value)[sz - 1] = 0;
353 pr_debug("fixed up name for %s -> %s\n", pathp,
354 (char *)pp->value);
355 }
356 }
357 if (allnextpp) {
358 *prev_pp = NULL;
359 np->name = of_get_property(np, "name", NULL);
360 np->type = of_get_property(np, "device_type", NULL);
361
362 if (!np->name)
363 np->name = "<NULL>";
364 if (!np->type)
365 np->type = "<NULL>";
366 }
367 while (tag == OF_DT_BEGIN_NODE) {
368 mem = unflatten_dt_node(mem, p, np, allnextpp, fpsize);
369 tag = *((u32 *)(*p));
370 }
371 if (tag != OF_DT_END_NODE) {
372 pr_err("Weird tag at end of node: %x\n", tag);
373 return mem;
374 }
375 *p += 4;
376 return mem;
377}
378
379#ifdef CONFIG_BLK_DEV_INITRD
380/**
381 * early_init_dt_check_for_initrd - Decode initrd location from flat tree
382 * @node: reference to node containing initrd location ('chosen')
383 */
384void __init early_init_dt_check_for_initrd(unsigned long node)
385{
386 unsigned long len;
387 u32 *prop;
388
389 pr_debug("Looking for initrd properties... ");
390
391 prop = of_get_flat_dt_prop(node, "linux,initrd-start", &len);
392 if (prop) {
393 initrd_start = (unsigned long)
394 __va(of_read_ulong(prop, len/4));
395
396 prop = of_get_flat_dt_prop(node, "linux,initrd-end", &len);
397 if (prop) {
398 initrd_end = (unsigned long)
399 __va(of_read_ulong(prop, len/4));
400 initrd_below_start_ok = 1;
401 } else {
402 initrd_start = 0;
403 }
404 }
405
406 pr_debug("initrd_start=0x%lx initrd_end=0x%lx\n",
407 initrd_start, initrd_end);
408}
409#else
410inline void early_init_dt_check_for_initrd(unsigned long node)
411{
412}
413#endif /* CONFIG_BLK_DEV_INITRD */
414
415/**
416 * early_init_dt_scan_root - fetch the top level address and size cells
417 */
418int __init early_init_dt_scan_root(unsigned long node, const char *uname,
419 int depth, void *data)
420{
421 u32 *prop;
422
423 if (depth != 0)
424 return 0;
425
426 prop = of_get_flat_dt_prop(node, "#size-cells", NULL);
427 dt_root_size_cells = (prop == NULL) ? 1 : *prop;
428 pr_debug("dt_root_size_cells = %x\n", dt_root_size_cells);
429
430 prop = of_get_flat_dt_prop(node, "#address-cells", NULL);
431 dt_root_addr_cells = (prop == NULL) ? 2 : *prop;
432 pr_debug("dt_root_addr_cells = %x\n", dt_root_addr_cells);
433
434 /* break now */
435 return 1;
436}
437
438u64 __init dt_mem_next_cell(int s, u32 **cellp)
439{
440 u32 *p = *cellp;
441
442 *cellp = p + s;
443 return of_read_number(p, s);
444}
445
446int __init early_init_dt_scan_chosen(unsigned long node, const char *uname,
447 int depth, void *data)
448{
449 unsigned long l;
450 char *p;
451
452 pr_debug("search \"chosen\", depth: %d, uname: %s\n", depth, uname);
453
454 if (depth != 1 ||
455 (strcmp(uname, "chosen") != 0 && strcmp(uname, "chosen@0") != 0))
456 return 0;
457
458 early_init_dt_check_for_initrd(node);
459
460 /* Retreive command line */
461 p = of_get_flat_dt_prop(node, "bootargs", &l);
462 if (p != NULL && l > 0)
463 strlcpy(cmd_line, p, min((int)l, COMMAND_LINE_SIZE));
464
465#ifdef CONFIG_CMDLINE
466#ifndef CONFIG_CMDLINE_FORCE
467 if (p == NULL || l == 0 || (l == 1 && (*p) == 0))
468#endif
469 strlcpy(cmd_line, CONFIG_CMDLINE, COMMAND_LINE_SIZE);
470#endif /* CONFIG_CMDLINE */
471
472 early_init_dt_scan_chosen_arch(node);
473
474 pr_debug("Command line is: %s\n", cmd_line);
475
476 /* break now */
477 return 1;
478}
479
480/**
481 * unflatten_device_tree - create tree of device_nodes from flat blob
482 *
483 * unflattens the device-tree passed by the firmware, creating the
484 * tree of struct device_node. It also fills the "name" and "type"
485 * pointers of the nodes so the normal device-tree walking functions
486 * can be used.
487 */
488void __init unflatten_device_tree(void)
489{
490 unsigned long start, mem, size;
491 struct device_node **allnextp = &allnodes;
492
493 pr_debug(" -> unflatten_device_tree()\n");
494
495 /* First pass, scan for size */
496 start = ((unsigned long)initial_boot_params) +
497 initial_boot_params->off_dt_struct;
498 size = unflatten_dt_node(0, &start, NULL, NULL, 0);
499 size = (size | 3) + 1;
500
501 pr_debug(" size is %lx, allocating...\n", size);
502
503 /* Allocate memory for the expanded device tree */
504 mem = lmb_alloc(size + 4, __alignof__(struct device_node));
505 mem = (unsigned long) __va(mem);
506
507 ((u32 *)mem)[size / 4] = 0xdeadbeef;
508
509 pr_debug(" unflattening %lx...\n", mem);
510
511 /* Second pass, do actual unflattening */
512 start = ((unsigned long)initial_boot_params) +
513 initial_boot_params->off_dt_struct;
514 unflatten_dt_node(mem, &start, NULL, &allnextp, 0);
515 if (*((u32 *)start) != OF_DT_END)
516 pr_warning("Weird tag at end of tree: %08x\n", *((u32 *)start));
517 if (((u32 *)mem)[size / 4] != 0xdeadbeef)
518 pr_warning("End of tree marker overwritten: %08x\n",
519 ((u32 *)mem)[size / 4]);
520 *allnextp = NULL;
521
522 /* Get pointer to OF "/chosen" node for use everywhere */
523 of_chosen = of_find_node_by_path("/chosen");
524 if (of_chosen == NULL)
525 of_chosen = of_find_node_by_path("/chosen@0");
526
527 pr_debug(" <- unflatten_device_tree()\n");
528}