blob: b777d8f46bd59696e366f957c27211411b32ef76 [file] [log] [blame]
Grant Likelye169cfb2009-11-23 14:53:09 -07001/*
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
Grant Likely41f88002009-11-23 20:07:01 -070012#include <linux/kernel.h>
Grant Likelyf7b3a832009-11-24 03:26:58 -070013#include <linux/initrd.h>
Grant Likelya1727da2013-08-28 21:18:32 +010014#include <linux/memblock.h>
Grant Likelye169cfb2009-11-23 14:53:09 -070015#include <linux/of.h>
16#include <linux/of_fdt.h>
Marek Szyprowski3f0c8202014-02-28 14:42:48 +010017#include <linux/of_reserved_mem.h>
Marek Szyprowskie8d9d1f2014-02-28 14:42:47 +010018#include <linux/sizes.h>
Jeremy Kerr4ef7b372010-02-14 07:13:47 -070019#include <linux/string.h>
20#include <linux/errno.h>
Stephen Neuendorfferfe140422010-11-18 15:55:02 -080021#include <linux/slab.h>
Rob Herringe6a69282014-04-02 15:10:14 -050022#include <linux/libfdt.h>
Rob Herringb0a6fb32014-04-02 16:56:48 -050023#include <linux/debugfs.h>
Rob Herringfb11ffe2014-03-27 08:07:01 -050024#include <linux/serial_core.h>
Grant Likely51975db2010-02-01 21:34:14 -070025
Fabio Estevamc89810a2012-01-02 14:19:03 -020026#include <asm/setup.h> /* for COMMAND_LINE_SIZE */
Jeremy Kerr4ef7b372010-02-14 07:13:47 -070027#include <asm/page.h>
28
Stephen Neuendorffer9706a362010-11-18 15:54:59 -080029/**
30 * of_fdt_is_compatible - Return true if given node from the given blob has
31 * compat in its compatible list
32 * @blob: A device tree blob
33 * @node: node to test
34 * @compat: compatible string to compare with compatible list.
Grant Likelya4f740c2010-10-30 11:49:09 -040035 *
36 * On match, returns a non-zero value with smaller values returned for more
37 * specific compatible values.
Stephen Neuendorffer9706a362010-11-18 15:54:59 -080038 */
Rob Herringc972de12014-04-01 22:48:01 -050039int of_fdt_is_compatible(const void *blob,
Stephen Neuendorffer9706a362010-11-18 15:54:59 -080040 unsigned long node, const char *compat)
41{
42 const char *cp;
Rob Herring9d0c4df2014-04-01 23:49:03 -050043 int cplen;
44 unsigned long l, score = 0;
Stephen Neuendorffer9706a362010-11-18 15:54:59 -080045
Rob Herringe6a69282014-04-02 15:10:14 -050046 cp = fdt_getprop(blob, node, "compatible", &cplen);
Stephen Neuendorffer9706a362010-11-18 15:54:59 -080047 if (cp == NULL)
48 return 0;
49 while (cplen > 0) {
Grant Likelya4f740c2010-10-30 11:49:09 -040050 score++;
Stephen Neuendorffer9706a362010-11-18 15:54:59 -080051 if (of_compat_cmp(cp, compat, strlen(compat)) == 0)
Grant Likelya4f740c2010-10-30 11:49:09 -040052 return score;
Stephen Neuendorffer9706a362010-11-18 15:54:59 -080053 l = strlen(cp) + 1;
54 cp += l;
55 cplen -= l;
56 }
57
58 return 0;
59}
60
Grant Likelya4f740c2010-10-30 11:49:09 -040061/**
62 * of_fdt_match - Return true if node matches a list of compatible values
63 */
Rob Herringc972de12014-04-01 22:48:01 -050064int of_fdt_match(const void *blob, unsigned long node,
Uwe Kleine-König7b482c82011-12-20 22:56:45 +010065 const char *const *compat)
Grant Likelya4f740c2010-10-30 11:49:09 -040066{
67 unsigned int tmp, score = 0;
68
69 if (!compat)
70 return 0;
71
72 while (*compat) {
73 tmp = of_fdt_is_compatible(blob, node, *compat);
74 if (tmp && (score == 0 || (tmp < score)))
75 score = tmp;
76 compat++;
77 }
78
79 return score;
80}
81
Grant Likely44856812013-08-29 13:30:35 +010082static void *unflatten_dt_alloc(void **mem, unsigned long size,
Grant Likelybbd33932009-11-23 20:07:00 -070083 unsigned long align)
84{
85 void *res;
86
Grant Likely44856812013-08-29 13:30:35 +010087 *mem = PTR_ALIGN(*mem, align);
88 res = *mem;
Grant Likelybbd33932009-11-23 20:07:00 -070089 *mem += size;
90
91 return res;
92}
93
94/**
95 * unflatten_dt_node - Alloc and populate a device_node from the flat tree
Stephen Neuendorffera40d6c42010-11-18 15:55:00 -080096 * @blob: The parent device tree blob
Andres Salomona7006c92011-03-17 17:32:35 -070097 * @mem: Memory chunk to use for allocating device nodes and properties
Grant Likelybbd33932009-11-23 20:07:00 -070098 * @p: pointer to node in flat tree
99 * @dad: Parent struct device_node
100 * @allnextpp: pointer to ->allnext from last allocated device_node
101 * @fpsize: Size of the node path up at the current depth.
102 */
Rob Herringc972de12014-04-01 22:48:01 -0500103static void * unflatten_dt_node(void *blob,
Grant Likely44856812013-08-29 13:30:35 +0100104 void *mem,
Rob Herringe6a69282014-04-02 15:10:14 -0500105 int *poffset,
Stephen Neuendorffera40d6c42010-11-18 15:55:00 -0800106 struct device_node *dad,
107 struct device_node ***allnextpp,
108 unsigned long fpsize)
Grant Likelybbd33932009-11-23 20:07:00 -0700109{
Rob Herringe6a69282014-04-02 15:10:14 -0500110 const __be32 *p;
Grant Likelybbd33932009-11-23 20:07:00 -0700111 struct device_node *np;
112 struct property *pp, **prev_pp = NULL;
Rob Herringe6a69282014-04-02 15:10:14 -0500113 const char *pathp;
Grant Likelybbd33932009-11-23 20:07:00 -0700114 unsigned int l, allocl;
Rob Herringe6a69282014-04-02 15:10:14 -0500115 static int depth = 0;
116 int old_depth;
117 int offset;
Grant Likelybbd33932009-11-23 20:07:00 -0700118 int has_name = 0;
119 int new_format = 0;
120
Rob Herringe6a69282014-04-02 15:10:14 -0500121 pathp = fdt_get_name(blob, *poffset, &l);
122 if (!pathp)
Grant Likelybbd33932009-11-23 20:07:00 -0700123 return mem;
Rob Herringe6a69282014-04-02 15:10:14 -0500124
125 allocl = l++;
Grant Likelybbd33932009-11-23 20:07:00 -0700126
127 /* version 0x10 has a more compact unit name here instead of the full
128 * path. we accumulate the full path size using "fpsize", we'll rebuild
129 * it later. We detect this because the first character of the name is
130 * not '/'.
131 */
132 if ((*pathp) != '/') {
133 new_format = 1;
134 if (fpsize == 0) {
135 /* root node: special case. fpsize accounts for path
136 * plus terminating zero. root node only has '/', so
137 * fpsize should be 2, but we want to avoid the first
138 * level nodes to have two '/' so we use fpsize 1 here
139 */
140 fpsize = 1;
141 allocl = 2;
Catalin Marinas0fca5de2012-11-16 15:14:38 +0000142 l = 1;
Rob Herringe6a69282014-04-02 15:10:14 -0500143 pathp = "";
Grant Likelybbd33932009-11-23 20:07:00 -0700144 } else {
145 /* account for '/' and path size minus terminal 0
146 * already in 'l'
147 */
148 fpsize += l;
149 allocl = fpsize;
150 }
151 }
152
153 np = unflatten_dt_alloc(&mem, sizeof(struct device_node) + allocl,
154 __alignof__(struct device_node));
155 if (allnextpp) {
Grant Likelyc22618a2012-11-14 22:37:12 +0000156 char *fn;
Pantelis Antoniou0829f6d2013-12-13 20:08:59 +0200157 of_node_init(np);
Grant Likelyc22618a2012-11-14 22:37:12 +0000158 np->full_name = fn = ((char *)np) + sizeof(*np);
Grant Likelybbd33932009-11-23 20:07:00 -0700159 if (new_format) {
Grant Likelybbd33932009-11-23 20:07:00 -0700160 /* rebuild full path for new format */
161 if (dad && dad->parent) {
162 strcpy(fn, dad->full_name);
163#ifdef DEBUG
164 if ((strlen(fn) + l + 1) != allocl) {
165 pr_debug("%s: p: %d, l: %d, a: %d\n",
166 pathp, (int)strlen(fn),
167 l, allocl);
168 }
169#endif
170 fn += strlen(fn);
171 }
172 *(fn++) = '/';
Grant Likelyc22618a2012-11-14 22:37:12 +0000173 }
174 memcpy(fn, pathp, l);
175
Grant Likelybbd33932009-11-23 20:07:00 -0700176 prev_pp = &np->properties;
177 **allnextpp = np;
178 *allnextpp = &np->allnext;
179 if (dad != NULL) {
180 np->parent = dad;
181 /* we temporarily use the next field as `last_child'*/
182 if (dad->next == NULL)
183 dad->child = np;
184 else
185 dad->next->sibling = np;
186 dad->next = np;
187 }
Grant Likelybbd33932009-11-23 20:07:00 -0700188 }
Andres Salomona7006c92011-03-17 17:32:35 -0700189 /* process properties */
Rob Herringe6a69282014-04-02 15:10:14 -0500190 for (offset = fdt_first_property_offset(blob, *poffset);
191 (offset >= 0);
192 (offset = fdt_next_property_offset(blob, offset))) {
193 const char *pname;
194 u32 sz;
Grant Likelybbd33932009-11-23 20:07:00 -0700195
Rob Herringe6a69282014-04-02 15:10:14 -0500196 if (!(p = fdt_getprop_by_offset(blob, offset, &pname, &sz))) {
197 offset = -FDT_ERR_INTERNAL;
Grant Likelybbd33932009-11-23 20:07:00 -0700198 break;
Rob Herringe6a69282014-04-02 15:10:14 -0500199 }
Grant Likelybbd33932009-11-23 20:07:00 -0700200
Grant Likelybbd33932009-11-23 20:07:00 -0700201 if (pname == NULL) {
202 pr_info("Can't find property name in list !\n");
203 break;
204 }
205 if (strcmp(pname, "name") == 0)
206 has_name = 1;
Grant Likelybbd33932009-11-23 20:07:00 -0700207 pp = unflatten_dt_alloc(&mem, sizeof(struct property),
208 __alignof__(struct property));
209 if (allnextpp) {
David Gibson04b954a2010-02-01 21:34:15 -0700210 /* We accept flattened tree phandles either in
211 * ePAPR-style "phandle" properties, or the
212 * legacy "linux,phandle" properties. If both
213 * appear and have different values, things
214 * will get weird. Don't do that. */
215 if ((strcmp(pname, "phandle") == 0) ||
216 (strcmp(pname, "linux,phandle") == 0)) {
Grant Likely6016a362010-01-28 14:06:53 -0700217 if (np->phandle == 0)
Rob Herringe6a69282014-04-02 15:10:14 -0500218 np->phandle = be32_to_cpup(p);
Grant Likelybbd33932009-11-23 20:07:00 -0700219 }
David Gibson04b954a2010-02-01 21:34:15 -0700220 /* And we process the "ibm,phandle" property
221 * used in pSeries dynamic device tree
222 * stuff */
Grant Likelybbd33932009-11-23 20:07:00 -0700223 if (strcmp(pname, "ibm,phandle") == 0)
Rob Herringe6a69282014-04-02 15:10:14 -0500224 np->phandle = be32_to_cpup(p);
225 pp->name = (char *)pname;
Grant Likelybbd33932009-11-23 20:07:00 -0700226 pp->length = sz;
Rob Herringe6a69282014-04-02 15:10:14 -0500227 pp->value = (__be32 *)p;
Grant Likelybbd33932009-11-23 20:07:00 -0700228 *prev_pp = pp;
229 prev_pp = &pp->next;
230 }
Grant Likelybbd33932009-11-23 20:07:00 -0700231 }
232 /* with version 0x10 we may not have the name property, recreate
233 * it here from the unit name if absent
234 */
235 if (!has_name) {
Rob Herringe6a69282014-04-02 15:10:14 -0500236 const char *p1 = pathp, *ps = pathp, *pa = NULL;
Grant Likelybbd33932009-11-23 20:07:00 -0700237 int sz;
238
239 while (*p1) {
240 if ((*p1) == '@')
241 pa = p1;
242 if ((*p1) == '/')
243 ps = p1 + 1;
244 p1++;
245 }
246 if (pa < ps)
247 pa = p1;
248 sz = (pa - ps) + 1;
249 pp = unflatten_dt_alloc(&mem, sizeof(struct property) + sz,
250 __alignof__(struct property));
251 if (allnextpp) {
252 pp->name = "name";
253 pp->length = sz;
254 pp->value = pp + 1;
255 *prev_pp = pp;
256 prev_pp = &pp->next;
257 memcpy(pp->value, ps, sz - 1);
258 ((char *)pp->value)[sz - 1] = 0;
259 pr_debug("fixed up name for %s -> %s\n", pathp,
260 (char *)pp->value);
261 }
262 }
263 if (allnextpp) {
264 *prev_pp = NULL;
265 np->name = of_get_property(np, "name", NULL);
266 np->type = of_get_property(np, "device_type", NULL);
267
268 if (!np->name)
269 np->name = "<NULL>";
270 if (!np->type)
271 np->type = "<NULL>";
272 }
Rob Herringe6a69282014-04-02 15:10:14 -0500273
274 old_depth = depth;
275 *poffset = fdt_next_node(blob, *poffset, &depth);
276 if (depth < 0)
277 depth = 0;
278 while (*poffset > 0 && depth > old_depth)
279 mem = unflatten_dt_node(blob, mem, poffset, np, allnextpp,
280 fpsize);
281
282 if (*poffset < 0 && *poffset != -FDT_ERR_NOTFOUND)
283 pr_err("unflatten: error %d processing FDT\n", *poffset);
284
Grant Likelybbd33932009-11-23 20:07:00 -0700285 return mem;
286}
Grant Likely41f88002009-11-23 20:07:01 -0700287
Stephen Neuendorfferfe140422010-11-18 15:55:02 -0800288/**
289 * __unflatten_device_tree - create tree of device_nodes from flat blob
290 *
291 * unflattens a device-tree, creating the
292 * tree of struct device_node. It also fills the "name" and "type"
293 * pointers of the nodes so the normal device-tree walking functions
294 * can be used.
295 * @blob: The blob to expand
296 * @mynodes: The device_node tree created by the call
297 * @dt_alloc: An allocator that provides a virtual address to memory
298 * for the resulting tree
299 */
Rob Herringc972de12014-04-01 22:48:01 -0500300static void __unflatten_device_tree(void *blob,
Stephen Neuendorfferfe140422010-11-18 15:55:02 -0800301 struct device_node **mynodes,
302 void * (*dt_alloc)(u64 size, u64 align))
303{
Grant Likely44856812013-08-29 13:30:35 +0100304 unsigned long size;
Rob Herringe6a69282014-04-02 15:10:14 -0500305 int start;
306 void *mem;
Stephen Neuendorfferfe140422010-11-18 15:55:02 -0800307 struct device_node **allnextp = mynodes;
308
309 pr_debug(" -> unflatten_device_tree()\n");
310
311 if (!blob) {
312 pr_debug("No device tree pointer\n");
313 return;
314 }
315
316 pr_debug("Unflattening device tree:\n");
Rob Herringc972de12014-04-01 22:48:01 -0500317 pr_debug("magic: %08x\n", fdt_magic(blob));
318 pr_debug("size: %08x\n", fdt_totalsize(blob));
319 pr_debug("version: %08x\n", fdt_version(blob));
Stephen Neuendorfferfe140422010-11-18 15:55:02 -0800320
Rob Herringc972de12014-04-01 22:48:01 -0500321 if (fdt_check_header(blob)) {
Stephen Neuendorfferfe140422010-11-18 15:55:02 -0800322 pr_err("Invalid device tree blob header\n");
323 return;
324 }
325
326 /* First pass, scan for size */
Rob Herringe6a69282014-04-02 15:10:14 -0500327 start = 0;
Thierry Redingd2d3d7c2014-04-02 09:47:01 +0200328 size = (unsigned long)unflatten_dt_node(blob, NULL, &start, NULL, NULL, 0);
Grant Likely44856812013-08-29 13:30:35 +0100329 size = ALIGN(size, 4);
Stephen Neuendorfferfe140422010-11-18 15:55:02 -0800330
331 pr_debug(" size is %lx, allocating...\n", size);
332
333 /* Allocate memory for the expanded device tree */
Grant Likely44856812013-08-29 13:30:35 +0100334 mem = dt_alloc(size + 4, __alignof__(struct device_node));
335 memset(mem, 0, size);
Stephen Neuendorfferfe140422010-11-18 15:55:02 -0800336
Grant Likely44856812013-08-29 13:30:35 +0100337 *(__be32 *)(mem + size) = cpu_to_be32(0xdeadbeef);
Wladislav Wiebe9e401272013-08-12 13:06:53 +0200338
Grant Likely44856812013-08-29 13:30:35 +0100339 pr_debug(" unflattening %p...\n", mem);
Stephen Neuendorfferfe140422010-11-18 15:55:02 -0800340
341 /* Second pass, do actual unflattening */
Rob Herringe6a69282014-04-02 15:10:14 -0500342 start = 0;
Stephen Neuendorfferfe140422010-11-18 15:55:02 -0800343 unflatten_dt_node(blob, mem, &start, NULL, &allnextp, 0);
Grant Likely44856812013-08-29 13:30:35 +0100344 if (be32_to_cpup(mem + size) != 0xdeadbeef)
Stephen Neuendorfferfe140422010-11-18 15:55:02 -0800345 pr_warning("End of tree marker overwritten: %08x\n",
Grant Likely44856812013-08-29 13:30:35 +0100346 be32_to_cpup(mem + size));
Stephen Neuendorfferfe140422010-11-18 15:55:02 -0800347 *allnextp = NULL;
348
349 pr_debug(" <- unflatten_device_tree()\n");
350}
351
352static void *kernel_tree_alloc(u64 size, u64 align)
353{
354 return kzalloc(size, GFP_KERNEL);
355}
356
357/**
358 * of_fdt_unflatten_tree - create tree of device_nodes from flat blob
359 *
360 * unflattens the device-tree passed by the firmware, creating the
361 * tree of struct device_node. It also fills the "name" and "type"
362 * pointers of the nodes so the normal device-tree walking functions
363 * can be used.
364 */
365void of_fdt_unflatten_tree(unsigned long *blob,
366 struct device_node **mynodes)
367{
Rob Herringc972de12014-04-01 22:48:01 -0500368 __unflatten_device_tree(blob, mynodes, &kernel_tree_alloc);
Stephen Neuendorfferfe140422010-11-18 15:55:02 -0800369}
370EXPORT_SYMBOL_GPL(of_fdt_unflatten_tree);
371
Stephen Neuendorffer57d00ec2010-11-18 15:55:01 -0800372/* Everything below here references initial_boot_params directly. */
373int __initdata dt_root_addr_cells;
374int __initdata dt_root_size_cells;
375
Rob Herring1daa0c42014-03-31 15:25:04 -0500376void *initial_boot_params;
Stephen Neuendorffer57d00ec2010-11-18 15:55:01 -0800377
378#ifdef CONFIG_OF_EARLY_FLATTREE
379
380/**
Marek Szyprowskie8d9d1f2014-02-28 14:42:47 +0100381 * res_mem_reserve_reg() - reserve all memory described in 'reg' property
382 */
383static int __init __reserved_mem_reserve_reg(unsigned long node,
384 const char *uname)
385{
386 int t_len = (dt_root_addr_cells + dt_root_size_cells) * sizeof(__be32);
387 phys_addr_t base, size;
Rob Herring9d0c4df2014-04-01 23:49:03 -0500388 int len;
389 const __be32 *prop;
Marek Szyprowski3f0c8202014-02-28 14:42:48 +0100390 int nomap, first = 1;
Marek Szyprowskie8d9d1f2014-02-28 14:42:47 +0100391
392 prop = of_get_flat_dt_prop(node, "reg", &len);
393 if (!prop)
394 return -ENOENT;
395
396 if (len && len % t_len != 0) {
397 pr_err("Reserved memory: invalid reg property in '%s', skipping node.\n",
398 uname);
399 return -EINVAL;
400 }
401
402 nomap = of_get_flat_dt_prop(node, "no-map", NULL) != NULL;
403
404 while (len >= t_len) {
405 base = dt_mem_next_cell(dt_root_addr_cells, &prop);
406 size = dt_mem_next_cell(dt_root_size_cells, &prop);
407
408 if (base && size &&
409 early_init_dt_reserve_memory_arch(base, size, nomap) == 0)
410 pr_debug("Reserved memory: reserved region for node '%s': base %pa, size %ld MiB\n",
411 uname, &base, (unsigned long)size / SZ_1M);
412 else
413 pr_info("Reserved memory: failed to reserve memory for node '%s': base %pa, size %ld MiB\n",
414 uname, &base, (unsigned long)size / SZ_1M);
415
416 len -= t_len;
Marek Szyprowski3f0c8202014-02-28 14:42:48 +0100417 if (first) {
418 fdt_reserved_mem_save_node(node, uname, base, size);
419 first = 0;
420 }
Marek Szyprowskie8d9d1f2014-02-28 14:42:47 +0100421 }
422 return 0;
423}
424
425/**
426 * __reserved_mem_check_root() - check if #size-cells, #address-cells provided
427 * in /reserved-memory matches the values supported by the current implementation,
428 * also check if ranges property has been provided
429 */
Xiubo Li5b624112014-04-08 13:48:07 +0800430static int __init __reserved_mem_check_root(unsigned long node)
Marek Szyprowskie8d9d1f2014-02-28 14:42:47 +0100431{
Rob Herring9d0c4df2014-04-01 23:49:03 -0500432 const __be32 *prop;
Marek Szyprowskie8d9d1f2014-02-28 14:42:47 +0100433
434 prop = of_get_flat_dt_prop(node, "#size-cells", NULL);
435 if (!prop || be32_to_cpup(prop) != dt_root_size_cells)
436 return -EINVAL;
437
438 prop = of_get_flat_dt_prop(node, "#address-cells", NULL);
439 if (!prop || be32_to_cpup(prop) != dt_root_addr_cells)
440 return -EINVAL;
441
442 prop = of_get_flat_dt_prop(node, "ranges", NULL);
443 if (!prop)
444 return -EINVAL;
445 return 0;
446}
447
448/**
449 * fdt_scan_reserved_mem() - scan a single FDT node for reserved memory
450 */
451static int __init __fdt_scan_reserved_mem(unsigned long node, const char *uname,
452 int depth, void *data)
453{
454 static int found;
455 const char *status;
Marek Szyprowski3f0c8202014-02-28 14:42:48 +0100456 int err;
Marek Szyprowskie8d9d1f2014-02-28 14:42:47 +0100457
458 if (!found && depth == 1 && strcmp(uname, "reserved-memory") == 0) {
459 if (__reserved_mem_check_root(node) != 0) {
460 pr_err("Reserved memory: unsupported node format, ignoring\n");
461 /* break scan */
462 return 1;
463 }
464 found = 1;
465 /* scan next node */
466 return 0;
467 } else if (!found) {
468 /* scan next node */
469 return 0;
470 } else if (found && depth < 2) {
471 /* scanning of /reserved-memory has been finished */
472 return 1;
473 }
474
475 status = of_get_flat_dt_prop(node, "status", NULL);
476 if (status && strcmp(status, "okay") != 0 && strcmp(status, "ok") != 0)
477 return 0;
478
Marek Szyprowski3f0c8202014-02-28 14:42:48 +0100479 err = __reserved_mem_reserve_reg(node, uname);
480 if (err == -ENOENT && of_get_flat_dt_prop(node, "size", NULL))
481 fdt_reserved_mem_save_node(node, uname, 0, 0);
Marek Szyprowskie8d9d1f2014-02-28 14:42:47 +0100482
483 /* scan next node */
484 return 0;
485}
486
487/**
488 * early_init_fdt_scan_reserved_mem() - create reserved memory regions
489 *
490 * This function grabs memory from early allocator for device exclusive use
491 * defined in device tree structures. It should be called by arch specific code
492 * once the early allocator (i.e. memblock) has been fully activated.
493 */
494void __init early_init_fdt_scan_reserved_mem(void)
495{
Rob Herringd1552ce2014-04-01 22:46:48 -0500496 int n;
497 u64 base, size;
498
Josh Cartwright2040b522014-03-13 16:36:36 -0500499 if (!initial_boot_params)
500 return;
501
Rob Herringd1552ce2014-04-01 22:46:48 -0500502 /* Reserve the dtb region */
503 early_init_dt_reserve_memory_arch(__pa(initial_boot_params),
504 fdt_totalsize(initial_boot_params),
505 0);
506
507 /* Process header /memreserve/ fields */
508 for (n = 0; ; n++) {
509 fdt_get_mem_rsv(initial_boot_params, n, &base, &size);
510 if (!size)
511 break;
512 early_init_dt_reserve_memory_arch(base, size, 0);
513 }
514
Marek Szyprowskie8d9d1f2014-02-28 14:42:47 +0100515 of_scan_flat_dt(__fdt_scan_reserved_mem, NULL);
Marek Szyprowski3f0c8202014-02-28 14:42:48 +0100516 fdt_init_reserved_mem();
Marek Szyprowskie8d9d1f2014-02-28 14:42:47 +0100517}
518
519/**
Stephen Neuendorffer57d00ec2010-11-18 15:55:01 -0800520 * of_scan_flat_dt - scan flattened tree blob and call callback on each.
521 * @it: callback function
522 * @data: context data pointer
523 *
524 * This function is used to scan the flattened device-tree, it is
525 * used to extract the memory information at boot before we can
526 * unflatten the tree
527 */
528int __init of_scan_flat_dt(int (*it)(unsigned long node,
529 const char *uname, int depth,
530 void *data),
531 void *data)
532{
Rob Herringe6a69282014-04-02 15:10:14 -0500533 const void *blob = initial_boot_params;
534 const char *pathp;
535 int offset, rc = 0, depth = -1;
Stephen Neuendorffer57d00ec2010-11-18 15:55:01 -0800536
Rob Herringe6a69282014-04-02 15:10:14 -0500537 for (offset = fdt_next_node(blob, -1, &depth);
538 offset >= 0 && depth >= 0 && !rc;
539 offset = fdt_next_node(blob, offset, &depth)) {
Stephen Neuendorffer57d00ec2010-11-18 15:55:01 -0800540
Rob Herringe6a69282014-04-02 15:10:14 -0500541 pathp = fdt_get_name(blob, offset, NULL);
Andy Shevchenko375da3a2012-12-17 16:01:28 -0800542 if (*pathp == '/')
543 pathp = kbasename(pathp);
Rob Herringe6a69282014-04-02 15:10:14 -0500544 rc = it(offset, pathp, depth, data);
545 }
Stephen Neuendorffer57d00ec2010-11-18 15:55:01 -0800546 return rc;
547}
548
549/**
550 * of_get_flat_dt_root - find the root node in the flat blob
551 */
552unsigned long __init of_get_flat_dt_root(void)
553{
Rob Herringe6a69282014-04-02 15:10:14 -0500554 return 0;
Stephen Neuendorffer57d00ec2010-11-18 15:55:01 -0800555}
556
557/**
Rob Herringc0556d32014-04-22 12:55:10 -0500558 * of_get_flat_dt_size - Return the total size of the FDT
559 */
560int __init of_get_flat_dt_size(void)
561{
562 return fdt_totalsize(initial_boot_params);
563}
564
565/**
Stephen Neuendorffer57d00ec2010-11-18 15:55:01 -0800566 * of_get_flat_dt_prop - Given a node in the flat blob, return the property ptr
567 *
568 * This function can be used within scan_flattened_dt callback to get
569 * access to properties
570 */
Rob Herring9d0c4df2014-04-01 23:49:03 -0500571const void *__init of_get_flat_dt_prop(unsigned long node, const char *name,
572 int *size)
Stephen Neuendorffer57d00ec2010-11-18 15:55:01 -0800573{
Rob Herringe6a69282014-04-02 15:10:14 -0500574 return fdt_getprop(initial_boot_params, node, name, size);
Stephen Neuendorffer57d00ec2010-11-18 15:55:01 -0800575}
576
577/**
578 * of_flat_dt_is_compatible - Return true if given node has compat in compatible list
579 * @node: node to test
580 * @compat: compatible string to compare with compatible list.
581 */
582int __init of_flat_dt_is_compatible(unsigned long node, const char *compat)
583{
584 return of_fdt_is_compatible(initial_boot_params, node, compat);
585}
586
Grant Likelya4f740c2010-10-30 11:49:09 -0400587/**
588 * of_flat_dt_match - Return true if node matches a list of compatible values
589 */
Uwe Kleine-König7b482c82011-12-20 22:56:45 +0100590int __init of_flat_dt_match(unsigned long node, const char *const *compat)
Grant Likelya4f740c2010-10-30 11:49:09 -0400591{
592 return of_fdt_match(initial_boot_params, node, compat);
593}
594
Marek Szyprowski57d74bc2013-08-26 14:41:56 +0200595struct fdt_scan_status {
596 const char *name;
597 int namelen;
598 int depth;
599 int found;
600 int (*iterator)(unsigned long node, const char *uname, int depth, void *data);
601 void *data;
602};
603
Rob Herring6a903a22013-08-27 21:41:56 -0500604const char * __init of_flat_dt_get_machine_name(void)
605{
606 const char *name;
607 unsigned long dt_root = of_get_flat_dt_root();
608
609 name = of_get_flat_dt_prop(dt_root, "model", NULL);
610 if (!name)
611 name = of_get_flat_dt_prop(dt_root, "compatible", NULL);
612 return name;
613}
614
615/**
616 * of_flat_dt_match_machine - Iterate match tables to find matching machine.
617 *
618 * @default_match: A machine specific ptr to return in case of no match.
619 * @get_next_compat: callback function to return next compatible match table.
620 *
621 * Iterate through machine match tables to find the best match for the machine
622 * compatible string in the FDT.
623 */
624const void * __init of_flat_dt_match_machine(const void *default_match,
625 const void * (*get_next_compat)(const char * const**))
626{
627 const void *data = NULL;
628 const void *best_data = default_match;
629 const char *const *compat;
630 unsigned long dt_root;
631 unsigned int best_score = ~1, score = 0;
632
633 dt_root = of_get_flat_dt_root();
634 while ((data = get_next_compat(&compat))) {
635 score = of_flat_dt_match(dt_root, compat);
636 if (score > 0 && score < best_score) {
637 best_data = data;
638 best_score = score;
639 }
640 }
641 if (!best_data) {
642 const char *prop;
Rob Herring9d0c4df2014-04-01 23:49:03 -0500643 int size;
Rob Herring6a903a22013-08-27 21:41:56 -0500644
645 pr_err("\n unrecognized device tree list:\n[ ");
646
647 prop = of_get_flat_dt_prop(dt_root, "compatible", &size);
648 if (prop) {
649 while (size > 0) {
650 printk("'%s' ", prop);
651 size -= strlen(prop) + 1;
652 prop += strlen(prop) + 1;
653 }
654 }
655 printk("]\n\n");
656 return NULL;
657 }
658
659 pr_info("Machine model: %s\n", of_flat_dt_get_machine_name());
660
661 return best_data;
662}
663
Grant Likelyf7b3a832009-11-24 03:26:58 -0700664#ifdef CONFIG_BLK_DEV_INITRD
665/**
666 * early_init_dt_check_for_initrd - Decode initrd location from flat tree
667 * @node: reference to node containing initrd location ('chosen')
668 */
Rob Herring29eb45a2013-08-30 17:06:53 -0500669static void __init early_init_dt_check_for_initrd(unsigned long node)
Grant Likelyf7b3a832009-11-24 03:26:58 -0700670{
Santosh Shilimkar374d5c92013-07-01 14:20:35 -0400671 u64 start, end;
Rob Herring9d0c4df2014-04-01 23:49:03 -0500672 int len;
673 const __be32 *prop;
Grant Likelyf7b3a832009-11-24 03:26:58 -0700674
675 pr_debug("Looking for initrd properties... ");
676
677 prop = of_get_flat_dt_prop(node, "linux,initrd-start", &len);
Jeremy Kerr1406bc22010-01-30 01:31:21 -0700678 if (!prop)
679 return;
Santosh Shilimkar374d5c92013-07-01 14:20:35 -0400680 start = of_read_number(prop, len/4);
Grant Likelyf7b3a832009-11-24 03:26:58 -0700681
Jeremy Kerr1406bc22010-01-30 01:31:21 -0700682 prop = of_get_flat_dt_prop(node, "linux,initrd-end", &len);
683 if (!prop)
684 return;
Santosh Shilimkar374d5c92013-07-01 14:20:35 -0400685 end = of_read_number(prop, len/4);
Grant Likelyf7b3a832009-11-24 03:26:58 -0700686
Rob Herring29eb45a2013-08-30 17:06:53 -0500687 initrd_start = (unsigned long)__va(start);
688 initrd_end = (unsigned long)__va(end);
689 initrd_below_start_ok = 1;
690
Santosh Shilimkar374d5c92013-07-01 14:20:35 -0400691 pr_debug("initrd_start=0x%llx initrd_end=0x%llx\n",
692 (unsigned long long)start, (unsigned long long)end);
Grant Likelyf7b3a832009-11-24 03:26:58 -0700693}
694#else
Rob Herring29eb45a2013-08-30 17:06:53 -0500695static inline void early_init_dt_check_for_initrd(unsigned long node)
Grant Likelyf7b3a832009-11-24 03:26:58 -0700696{
697}
698#endif /* CONFIG_BLK_DEV_INITRD */
699
Rob Herringfb11ffe2014-03-27 08:07:01 -0500700#ifdef CONFIG_SERIAL_EARLYCON
701extern struct of_device_id __earlycon_of_table[];
702
703int __init early_init_dt_scan_chosen_serial(void)
704{
705 int offset;
706 const char *p;
707 int l;
708 const struct of_device_id *match = __earlycon_of_table;
709 const void *fdt = initial_boot_params;
710
711 offset = fdt_path_offset(fdt, "/chosen");
712 if (offset < 0)
713 offset = fdt_path_offset(fdt, "/chosen@0");
714 if (offset < 0)
715 return -ENOENT;
716
717 p = fdt_getprop(fdt, offset, "stdout-path", &l);
718 if (!p)
719 p = fdt_getprop(fdt, offset, "linux,stdout-path", &l);
720 if (!p || !l)
721 return -ENOENT;
722
723 /* Get the node specified by stdout-path */
724 offset = fdt_path_offset(fdt, p);
725 if (offset < 0)
726 return -ENODEV;
727
728 while (match->compatible) {
729 unsigned long addr;
730 if (fdt_node_check_compatible(fdt, offset, match->compatible)) {
731 match++;
732 continue;
733 }
734
735 addr = fdt_translate_address(fdt, offset);
736 if (!addr)
737 return -ENXIO;
738
739 of_setup_earlycon(addr, match->data);
740 return 0;
741 }
742 return -ENODEV;
743}
744
745static int __init setup_of_earlycon(char *buf)
746{
747 if (buf)
748 return 0;
749
750 return early_init_dt_scan_chosen_serial();
751}
752early_param("earlycon", setup_of_earlycon);
753#endif
754
Grant Likely41f88002009-11-23 20:07:01 -0700755/**
Grant Likelyf00abd92009-11-24 03:27:10 -0700756 * early_init_dt_scan_root - fetch the top level address and size cells
757 */
758int __init early_init_dt_scan_root(unsigned long node, const char *uname,
759 int depth, void *data)
760{
Rob Herring9d0c4df2014-04-01 23:49:03 -0500761 const __be32 *prop;
Grant Likelyf00abd92009-11-24 03:27:10 -0700762
763 if (depth != 0)
764 return 0;
765
Jeremy Kerr33714882010-01-30 01:45:26 -0700766 dt_root_size_cells = OF_ROOT_NODE_SIZE_CELLS_DEFAULT;
767 dt_root_addr_cells = OF_ROOT_NODE_ADDR_CELLS_DEFAULT;
768
Grant Likelyf00abd92009-11-24 03:27:10 -0700769 prop = of_get_flat_dt_prop(node, "#size-cells", NULL);
Jeremy Kerr33714882010-01-30 01:45:26 -0700770 if (prop)
771 dt_root_size_cells = be32_to_cpup(prop);
Grant Likelyf00abd92009-11-24 03:27:10 -0700772 pr_debug("dt_root_size_cells = %x\n", dt_root_size_cells);
773
774 prop = of_get_flat_dt_prop(node, "#address-cells", NULL);
Jeremy Kerr33714882010-01-30 01:45:26 -0700775 if (prop)
776 dt_root_addr_cells = be32_to_cpup(prop);
Grant Likelyf00abd92009-11-24 03:27:10 -0700777 pr_debug("dt_root_addr_cells = %x\n", dt_root_addr_cells);
778
779 /* break now */
780 return 1;
781}
782
Rob Herring9d0c4df2014-04-01 23:49:03 -0500783u64 __init dt_mem_next_cell(int s, const __be32 **cellp)
Grant Likely83f7a062009-11-24 03:37:56 -0700784{
Rob Herring9d0c4df2014-04-01 23:49:03 -0500785 const __be32 *p = *cellp;
Grant Likely83f7a062009-11-24 03:37:56 -0700786
787 *cellp = p + s;
788 return of_read_number(p, s);
789}
790
Grant Likely51975db2010-02-01 21:34:14 -0700791/**
792 * early_init_dt_scan_memory - Look for an parse memory nodes
793 */
794int __init early_init_dt_scan_memory(unsigned long node, const char *uname,
795 int depth, void *data)
796{
Rob Herring9d0c4df2014-04-01 23:49:03 -0500797 const char *type = of_get_flat_dt_prop(node, "device_type", NULL);
798 const __be32 *reg, *endp;
799 int l;
Grant Likely51975db2010-02-01 21:34:14 -0700800
801 /* We are scanning "memory" nodes only */
802 if (type == NULL) {
803 /*
804 * The longtrail doesn't have a device_type on the
805 * /memory node, so look for the node called /memory@0.
806 */
Leif Lindholmb44aa252014-04-17 18:42:01 +0100807 if (!IS_ENABLED(CONFIG_PPC32) || depth != 1 || strcmp(uname, "memory@0") != 0)
Grant Likely51975db2010-02-01 21:34:14 -0700808 return 0;
809 } else if (strcmp(type, "memory") != 0)
810 return 0;
811
812 reg = of_get_flat_dt_prop(node, "linux,usable-memory", &l);
813 if (reg == NULL)
814 reg = of_get_flat_dt_prop(node, "reg", &l);
815 if (reg == NULL)
816 return 0;
817
818 endp = reg + (l / sizeof(__be32));
819
Rob Herring9d0c4df2014-04-01 23:49:03 -0500820 pr_debug("memory scan node %s, reg size %d, data: %x %x %x %x,\n",
Grant Likely51975db2010-02-01 21:34:14 -0700821 uname, l, reg[0], reg[1], reg[2], reg[3]);
822
823 while ((endp - reg) >= (dt_root_addr_cells + dt_root_size_cells)) {
824 u64 base, size;
825
826 base = dt_mem_next_cell(dt_root_addr_cells, &reg);
827 size = dt_mem_next_cell(dt_root_size_cells, &reg);
828
829 if (size == 0)
830 continue;
831 pr_debug(" - %llx , %llx\n", (unsigned long long)base,
832 (unsigned long long)size);
833
834 early_init_dt_add_memory_arch(base, size);
835 }
836
837 return 0;
838}
839
Grant Likely86e03222009-12-10 23:42:21 -0700840int __init early_init_dt_scan_chosen(unsigned long node, const char *uname,
841 int depth, void *data)
842{
Rob Herring9d0c4df2014-04-01 23:49:03 -0500843 int l;
844 const char *p;
Grant Likely86e03222009-12-10 23:42:21 -0700845
846 pr_debug("search \"chosen\", depth: %d, uname: %s\n", depth, uname);
847
Grant Likely85f60ae2011-04-29 00:18:16 -0600848 if (depth != 1 || !data ||
Grant Likely86e03222009-12-10 23:42:21 -0700849 (strcmp(uname, "chosen") != 0 && strcmp(uname, "chosen@0") != 0))
850 return 0;
851
852 early_init_dt_check_for_initrd(node);
853
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300854 /* Retrieve command line */
Grant Likely86e03222009-12-10 23:42:21 -0700855 p = of_get_flat_dt_prop(node, "bootargs", &l);
856 if (p != NULL && l > 0)
Grant Likely85f60ae2011-04-29 00:18:16 -0600857 strlcpy(data, p, min((int)l, COMMAND_LINE_SIZE));
Grant Likely86e03222009-12-10 23:42:21 -0700858
Benjamin Herrenschmidt78b782c2011-09-19 18:50:15 +0000859 /*
860 * CONFIG_CMDLINE is meant to be a default in case nothing else
861 * managed to set the command line, unless CONFIG_CMDLINE_FORCE
862 * is set in which case we override whatever was found earlier.
863 */
Grant Likely86e03222009-12-10 23:42:21 -0700864#ifdef CONFIG_CMDLINE
865#ifndef CONFIG_CMDLINE_FORCE
Benjamin Herrenschmidt78b782c2011-09-19 18:50:15 +0000866 if (!((char *)data)[0])
Grant Likely86e03222009-12-10 23:42:21 -0700867#endif
Grant Likely85f60ae2011-04-29 00:18:16 -0600868 strlcpy(data, CONFIG_CMDLINE, COMMAND_LINE_SIZE);
Grant Likely86e03222009-12-10 23:42:21 -0700869#endif /* CONFIG_CMDLINE */
870
Grant Likely85f60ae2011-04-29 00:18:16 -0600871 pr_debug("Command line is: %s\n", (char*)data);
Grant Likely86e03222009-12-10 23:42:21 -0700872
873 /* break now */
874 return 1;
875}
876
Grant Likelya1727da2013-08-28 21:18:32 +0100877#ifdef CONFIG_HAVE_MEMBLOCK
Rob Herring068f6312013-09-24 22:20:01 -0500878void __init __weak early_init_dt_add_memory_arch(u64 base, u64 size)
879{
880 const u64 phys_offset = __pa(PAGE_OFFSET);
881 base &= PAGE_MASK;
882 size &= PAGE_MASK;
Laura Abbotta67a6ed2014-06-19 20:13:38 -0700883
884 if (sizeof(phys_addr_t) < sizeof(u64)) {
885 if (base > ULONG_MAX) {
886 pr_warning("Ignoring memory block 0x%llx - 0x%llx\n",
887 base, base + size);
888 return;
889 }
890
891 if (base + size > ULONG_MAX) {
892 pr_warning("Ignoring memory range 0x%lx - 0x%llx\n",
893 ULONG_MAX, base + size);
894 size = ULONG_MAX - base;
895 }
896 }
897
Rob Herring068f6312013-09-24 22:20:01 -0500898 if (base + size < phys_offset) {
899 pr_warning("Ignoring memory block 0x%llx - 0x%llx\n",
900 base, base + size);
901 return;
902 }
903 if (base < phys_offset) {
904 pr_warning("Ignoring memory range 0x%llx - 0x%llx\n",
905 base, phys_offset);
906 size -= phys_offset - base;
907 base = phys_offset;
908 }
909 memblock_add(base, size);
910}
911
Marek Szyprowskie8d9d1f2014-02-28 14:42:47 +0100912int __init __weak early_init_dt_reserve_memory_arch(phys_addr_t base,
913 phys_addr_t size, bool nomap)
914{
915 if (memblock_is_region_reserved(base, size))
916 return -EBUSY;
917 if (nomap)
918 return memblock_remove(base, size);
919 return memblock_reserve(base, size);
920}
921
Grant Likelya1727da2013-08-28 21:18:32 +0100922/*
923 * called from unflatten_device_tree() to bootstrap devicetree itself
924 * Architectures can override this definition if memblock isn't used
925 */
926void * __init __weak early_init_dt_alloc_memory_arch(u64 size, u64 align)
927{
928 return __va(memblock_alloc(size, align));
929}
Marek Szyprowskie8d9d1f2014-02-28 14:42:47 +0100930#else
931int __init __weak early_init_dt_reserve_memory_arch(phys_addr_t base,
932 phys_addr_t size, bool nomap)
933{
Rob Herring1d1a6612014-04-22 12:50:24 -0500934 pr_err("Reserved memory not supported, ignoring range 0x%pa - 0x%pa%s\n",
935 &base, &size, nomap ? " (nomap)" : "");
Marek Szyprowskie8d9d1f2014-02-28 14:42:47 +0100936 return -ENOSYS;
937}
Grant Likelya1727da2013-08-28 21:18:32 +0100938#endif
939
Rob Herring0288ffcb2013-08-26 09:47:40 -0500940bool __init early_init_dt_scan(void *params)
941{
942 if (!params)
943 return false;
944
945 /* Setup flat device-tree pointer */
946 initial_boot_params = params;
947
948 /* check device tree validity */
Rob Herringc972de12014-04-01 22:48:01 -0500949 if (fdt_check_header(params)) {
Rob Herring0288ffcb2013-08-26 09:47:40 -0500950 initial_boot_params = NULL;
951 return false;
952 }
953
954 /* Retrieve various information from the /chosen node */
955 of_scan_flat_dt(early_init_dt_scan_chosen, boot_command_line);
956
957 /* Initialize {size,address}-cells info */
958 of_scan_flat_dt(early_init_dt_scan_root, NULL);
959
960 /* Setup memory, calling early_init_dt_add_memory_arch */
961 of_scan_flat_dt(early_init_dt_scan_memory, NULL);
962
963 return true;
964}
965
Grant Likelyf00abd92009-11-24 03:27:10 -0700966/**
Grant Likely41f88002009-11-23 20:07:01 -0700967 * unflatten_device_tree - create tree of device_nodes from flat blob
968 *
969 * unflattens the device-tree passed by the firmware, creating the
970 * tree of struct device_node. It also fills the "name" and "type"
971 * pointers of the nodes so the normal device-tree walking functions
972 * can be used.
973 */
974void __init unflatten_device_tree(void)
975{
Randy Dunlap465aac62012-11-30 10:01:51 +0000976 __unflatten_device_tree(initial_boot_params, &of_allnodes,
Grant Likely672c5442011-01-13 15:36:09 -0700977 early_init_dt_alloc_memory_arch);
Grant Likely41f88002009-11-23 20:07:01 -0700978
Robert P. J. Day4c7d6362013-05-30 05:38:08 -0400979 /* Get pointer to "/chosen" and "/aliases" nodes for use everywhere */
Shawn Guo611cad72011-08-15 15:28:14 +0800980 of_alias_scan(early_init_dt_alloc_memory_arch);
Grant Likely41f88002009-11-23 20:07:01 -0700981}
Stephen Neuendorffere6ce1322010-11-18 15:54:56 -0800982
Rob Herringa8bf7522013-08-26 11:22:45 -0500983/**
984 * unflatten_and_copy_device_tree - copy and create tree of device_nodes from flat blob
985 *
986 * Copies and unflattens the device-tree passed by the firmware, creating the
987 * tree of struct device_node. It also fills the "name" and "type"
988 * pointers of the nodes so the normal device-tree walking functions
989 * can be used. This should only be used when the FDT memory has not been
990 * reserved such is the case when the FDT is built-in to the kernel init
991 * section. If the FDT memory is reserved already then unflatten_device_tree
992 * should be used instead.
993 */
994void __init unflatten_and_copy_device_tree(void)
995{
James Hogan6f041e92013-11-21 13:44:14 +0000996 int size;
997 void *dt;
998
999 if (!initial_boot_params) {
1000 pr_warn("No valid device tree found, continuing without\n");
1001 return;
1002 }
1003
Rob Herringc972de12014-04-01 22:48:01 -05001004 size = fdt_totalsize(initial_boot_params);
James Hogan6f041e92013-11-21 13:44:14 +00001005 dt = early_init_dt_alloc_memory_arch(size,
Rob Herringc972de12014-04-01 22:48:01 -05001006 roundup_pow_of_two(FDT_V17_SIZE));
Rob Herringa8bf7522013-08-26 11:22:45 -05001007
1008 if (dt) {
1009 memcpy(dt, initial_boot_params, size);
1010 initial_boot_params = dt;
1011 }
1012 unflatten_device_tree();
1013}
1014
Rob Herringb0a6fb32014-04-02 16:56:48 -05001015#if defined(CONFIG_DEBUG_FS) && defined(DEBUG)
1016static struct debugfs_blob_wrapper flat_dt_blob;
1017
1018static int __init of_flat_dt_debugfs_export_fdt(void)
1019{
1020 struct dentry *d = debugfs_create_dir("device-tree", NULL);
1021
1022 if (!d)
1023 return -ENOENT;
1024
1025 flat_dt_blob.data = initial_boot_params;
1026 flat_dt_blob.size = fdt_totalsize(initial_boot_params);
1027
1028 d = debugfs_create_blob("flat-device-tree", S_IFREG | S_IRUSR,
1029 d, &flat_dt_blob);
1030 if (!d)
1031 return -ENOENT;
1032
1033 return 0;
1034}
1035module_init(of_flat_dt_debugfs_export_fdt);
1036#endif
1037
Stephen Neuendorffere6ce1322010-11-18 15:54:56 -08001038#endif /* CONFIG_OF_EARLY_FLATTREE */