Commit | Line | Data |
---|---|---|
9b6b563c PM |
1 | /* |
2 | * Procedures for creating, accessing and interpreting the device tree. | |
3 | * | |
4 | * Paul Mackerras August 1996. | |
5 | * Copyright (C) 1996-2005 Paul Mackerras. | |
6 | * | |
7 | * Adapted for 64bit PowerPC by Dave Engebretsen and Peter Bergner. | |
8 | * {engebret|bergner}@us.ibm.com | |
9 | * | |
10 | * This program is free software; you can redistribute it and/or | |
11 | * modify it under the terms of the GNU General Public License | |
12 | * as published by the Free Software Foundation; either version | |
13 | * 2 of the License, or (at your option) any later version. | |
14 | */ | |
15 | ||
16 | #undef DEBUG | |
17 | ||
18 | #include <stdarg.h> | |
9b6b563c PM |
19 | #include <linux/kernel.h> |
20 | #include <linux/string.h> | |
21 | #include <linux/init.h> | |
22 | #include <linux/threads.h> | |
23 | #include <linux/spinlock.h> | |
24 | #include <linux/types.h> | |
25 | #include <linux/pci.h> | |
26 | #include <linux/stringify.h> | |
27 | #include <linux/delay.h> | |
28 | #include <linux/initrd.h> | |
29 | #include <linux/bitops.h> | |
30 | #include <linux/module.h> | |
dcee3036 | 31 | #include <linux/kexec.h> |
7a4571ae | 32 | #include <linux/debugfs.h> |
0ebfff14 | 33 | #include <linux/irq.h> |
d9b2b2a2 | 34 | #include <linux/lmb.h> |
9b6b563c PM |
35 | |
36 | #include <asm/prom.h> | |
37 | #include <asm/rtas.h> | |
9b6b563c PM |
38 | #include <asm/page.h> |
39 | #include <asm/processor.h> | |
40 | #include <asm/irq.h> | |
41 | #include <asm/io.h> | |
0cc4746c | 42 | #include <asm/kdump.h> |
9b6b563c PM |
43 | #include <asm/smp.h> |
44 | #include <asm/system.h> | |
45 | #include <asm/mmu.h> | |
46 | #include <asm/pgtable.h> | |
47 | #include <asm/pci.h> | |
48 | #include <asm/iommu.h> | |
49 | #include <asm/btext.h> | |
50 | #include <asm/sections.h> | |
51 | #include <asm/machdep.h> | |
52 | #include <asm/pSeries_reconfig.h> | |
40ef8cbc | 53 | #include <asm/pci-bridge.h> |
6ac26c8a | 54 | #include <asm/phyp_dump.h> |
2babf5c2 | 55 | #include <asm/kexec.h> |
37dd2bad | 56 | #include <mm/mmu_decl.h> |
9b6b563c PM |
57 | |
58 | #ifdef DEBUG | |
59 | #define DBG(fmt...) printk(KERN_ERR fmt) | |
60 | #else | |
61 | #define DBG(fmt...) | |
62 | #endif | |
63 | ||
9b6b563c | 64 | |
9b6b563c PM |
65 | static int __initdata dt_root_addr_cells; |
66 | static int __initdata dt_root_size_cells; | |
67 | ||
68 | #ifdef CONFIG_PPC64 | |
28897731 | 69 | int __initdata iommu_is_off; |
9b6b563c | 70 | int __initdata iommu_force_on; |
cf00a8d1 | 71 | unsigned long tce_alloc_start, tce_alloc_end; |
9b6b563c PM |
72 | #endif |
73 | ||
74 | typedef u32 cell_t; | |
75 | ||
76 | #if 0 | |
77 | static struct boot_param_header *initial_boot_params __initdata; | |
78 | #else | |
79 | struct boot_param_header *initial_boot_params; | |
80 | #endif | |
81 | ||
1ef4d424 | 82 | extern struct device_node *allnodes; /* temporary while merging */ |
9b6b563c | 83 | |
581b605a | 84 | extern rwlock_t devtree_lock; /* temporary while merging */ |
9b6b563c PM |
85 | |
86 | /* export that to outside world */ | |
87 | struct device_node *of_chosen; | |
88 | ||
9b6b563c PM |
89 | static inline char *find_flat_dt_string(u32 offset) |
90 | { | |
91 | return ((char *)initial_boot_params) + | |
92 | initial_boot_params->off_dt_strings + offset; | |
93 | } | |
94 | ||
95 | /** | |
96 | * This function is used to scan the flattened device-tree, it is | |
97 | * used to extract the memory informations at boot before we can | |
98 | * unflatten the tree | |
99 | */ | |
3c726f8d BH |
100 | int __init of_scan_flat_dt(int (*it)(unsigned long node, |
101 | const char *uname, int depth, | |
102 | void *data), | |
103 | void *data) | |
9b6b563c PM |
104 | { |
105 | unsigned long p = ((unsigned long)initial_boot_params) + | |
106 | initial_boot_params->off_dt_struct; | |
107 | int rc = 0; | |
108 | int depth = -1; | |
109 | ||
110 | do { | |
111 | u32 tag = *((u32 *)p); | |
112 | char *pathp; | |
113 | ||
114 | p += 4; | |
115 | if (tag == OF_DT_END_NODE) { | |
116 | depth --; | |
117 | continue; | |
118 | } | |
119 | if (tag == OF_DT_NOP) | |
120 | continue; | |
121 | if (tag == OF_DT_END) | |
122 | break; | |
123 | if (tag == OF_DT_PROP) { | |
124 | u32 sz = *((u32 *)p); | |
125 | p += 8; | |
126 | if (initial_boot_params->version < 0x10) | |
127 | p = _ALIGN(p, sz >= 8 ? 8 : 4); | |
128 | p += sz; | |
129 | p = _ALIGN(p, 4); | |
130 | continue; | |
131 | } | |
132 | if (tag != OF_DT_BEGIN_NODE) { | |
133 | printk(KERN_WARNING "Invalid tag %x scanning flattened" | |
134 | " device tree !\n", tag); | |
135 | return -EINVAL; | |
136 | } | |
137 | depth++; | |
138 | pathp = (char *)p; | |
139 | p = _ALIGN(p + strlen(pathp) + 1, 4); | |
140 | if ((*pathp) == '/') { | |
141 | char *lp, *np; | |
142 | for (lp = NULL, np = pathp; *np; np++) | |
143 | if ((*np) == '/') | |
144 | lp = np+1; | |
145 | if (lp != NULL) | |
146 | pathp = lp; | |
147 | } | |
148 | rc = it(p, pathp, depth, data); | |
149 | if (rc != 0) | |
150 | break; | |
151 | } while(1); | |
152 | ||
153 | return rc; | |
154 | } | |
155 | ||
e8222502 BH |
156 | unsigned long __init of_get_flat_dt_root(void) |
157 | { | |
158 | unsigned long p = ((unsigned long)initial_boot_params) + | |
159 | initial_boot_params->off_dt_struct; | |
160 | ||
161 | while(*((u32 *)p) == OF_DT_NOP) | |
162 | p += 4; | |
163 | BUG_ON (*((u32 *)p) != OF_DT_BEGIN_NODE); | |
164 | p += 4; | |
165 | return _ALIGN(p + strlen((char *)p) + 1, 4); | |
166 | } | |
167 | ||
9b6b563c PM |
168 | /** |
169 | * This function can be used within scan_flattened_dt callback to get | |
170 | * access to properties | |
171 | */ | |
3c726f8d BH |
172 | void* __init of_get_flat_dt_prop(unsigned long node, const char *name, |
173 | unsigned long *size) | |
9b6b563c PM |
174 | { |
175 | unsigned long p = node; | |
176 | ||
177 | do { | |
178 | u32 tag = *((u32 *)p); | |
179 | u32 sz, noff; | |
180 | const char *nstr; | |
181 | ||
182 | p += 4; | |
183 | if (tag == OF_DT_NOP) | |
184 | continue; | |
185 | if (tag != OF_DT_PROP) | |
186 | return NULL; | |
187 | ||
188 | sz = *((u32 *)p); | |
189 | noff = *((u32 *)(p + 4)); | |
190 | p += 8; | |
191 | if (initial_boot_params->version < 0x10) | |
192 | p = _ALIGN(p, sz >= 8 ? 8 : 4); | |
193 | ||
194 | nstr = find_flat_dt_string(noff); | |
195 | if (nstr == NULL) { | |
196 | printk(KERN_WARNING "Can't find property index" | |
197 | " name !\n"); | |
198 | return NULL; | |
199 | } | |
200 | if (strcmp(name, nstr) == 0) { | |
201 | if (size) | |
202 | *size = sz; | |
203 | return (void *)p; | |
204 | } | |
205 | p += sz; | |
206 | p = _ALIGN(p, 4); | |
207 | } while(1); | |
208 | } | |
209 | ||
e8222502 BH |
210 | int __init of_flat_dt_is_compatible(unsigned long node, const char *compat) |
211 | { | |
212 | const char* cp; | |
213 | unsigned long cplen, l; | |
214 | ||
215 | cp = of_get_flat_dt_prop(node, "compatible", &cplen); | |
216 | if (cp == NULL) | |
217 | return 0; | |
218 | while (cplen > 0) { | |
219 | if (strncasecmp(cp, compat, strlen(compat)) == 0) | |
220 | return 1; | |
221 | l = strlen(cp) + 1; | |
222 | cp += l; | |
223 | cplen -= l; | |
224 | } | |
225 | ||
226 | return 0; | |
227 | } | |
228 | ||
9b6b563c PM |
229 | static void *__init unflatten_dt_alloc(unsigned long *mem, unsigned long size, |
230 | unsigned long align) | |
231 | { | |
232 | void *res; | |
233 | ||
234 | *mem = _ALIGN(*mem, align); | |
235 | res = (void *)*mem; | |
236 | *mem += size; | |
237 | ||
238 | return res; | |
239 | } | |
240 | ||
241 | static unsigned long __init unflatten_dt_node(unsigned long mem, | |
242 | unsigned long *p, | |
243 | struct device_node *dad, | |
244 | struct device_node ***allnextpp, | |
245 | unsigned long fpsize) | |
246 | { | |
247 | struct device_node *np; | |
248 | struct property *pp, **prev_pp = NULL; | |
249 | char *pathp; | |
250 | u32 tag; | |
251 | unsigned int l, allocl; | |
252 | int has_name = 0; | |
253 | int new_format = 0; | |
254 | ||
255 | tag = *((u32 *)(*p)); | |
256 | if (tag != OF_DT_BEGIN_NODE) { | |
257 | printk("Weird tag at start of node: %x\n", tag); | |
258 | return mem; | |
259 | } | |
260 | *p += 4; | |
261 | pathp = (char *)*p; | |
262 | l = allocl = strlen(pathp) + 1; | |
263 | *p = _ALIGN(*p + l, 4); | |
264 | ||
265 | /* version 0x10 has a more compact unit name here instead of the full | |
266 | * path. we accumulate the full path size using "fpsize", we'll rebuild | |
267 | * it later. We detect this because the first character of the name is | |
268 | * not '/'. | |
269 | */ | |
270 | if ((*pathp) != '/') { | |
271 | new_format = 1; | |
272 | if (fpsize == 0) { | |
273 | /* root node: special case. fpsize accounts for path | |
274 | * plus terminating zero. root node only has '/', so | |
275 | * fpsize should be 2, but we want to avoid the first | |
276 | * level nodes to have two '/' so we use fpsize 1 here | |
277 | */ | |
278 | fpsize = 1; | |
279 | allocl = 2; | |
280 | } else { | |
281 | /* account for '/' and path size minus terminal 0 | |
282 | * already in 'l' | |
283 | */ | |
284 | fpsize += l; | |
285 | allocl = fpsize; | |
286 | } | |
287 | } | |
288 | ||
289 | ||
290 | np = unflatten_dt_alloc(&mem, sizeof(struct device_node) + allocl, | |
291 | __alignof__(struct device_node)); | |
292 | if (allnextpp) { | |
293 | memset(np, 0, sizeof(*np)); | |
294 | np->full_name = ((char*)np) + sizeof(struct device_node); | |
295 | if (new_format) { | |
296 | char *p = np->full_name; | |
297 | /* rebuild full path for new format */ | |
298 | if (dad && dad->parent) { | |
299 | strcpy(p, dad->full_name); | |
300 | #ifdef DEBUG | |
301 | if ((strlen(p) + l + 1) != allocl) { | |
302 | DBG("%s: p: %d, l: %d, a: %d\n", | |
e8222502 | 303 | pathp, (int)strlen(p), l, allocl); |
9b6b563c PM |
304 | } |
305 | #endif | |
306 | p += strlen(p); | |
307 | } | |
308 | *(p++) = '/'; | |
309 | memcpy(p, pathp, l); | |
310 | } else | |
311 | memcpy(np->full_name, pathp, l); | |
312 | prev_pp = &np->properties; | |
313 | **allnextpp = np; | |
314 | *allnextpp = &np->allnext; | |
315 | if (dad != NULL) { | |
316 | np->parent = dad; | |
317 | /* we temporarily use the next field as `last_child'*/ | |
318 | if (dad->next == 0) | |
319 | dad->child = np; | |
320 | else | |
321 | dad->next->sibling = np; | |
322 | dad->next = np; | |
323 | } | |
324 | kref_init(&np->kref); | |
325 | } | |
326 | while(1) { | |
327 | u32 sz, noff; | |
328 | char *pname; | |
329 | ||
330 | tag = *((u32 *)(*p)); | |
331 | if (tag == OF_DT_NOP) { | |
332 | *p += 4; | |
333 | continue; | |
334 | } | |
335 | if (tag != OF_DT_PROP) | |
336 | break; | |
337 | *p += 4; | |
338 | sz = *((u32 *)(*p)); | |
339 | noff = *((u32 *)((*p) + 4)); | |
340 | *p += 8; | |
341 | if (initial_boot_params->version < 0x10) | |
342 | *p = _ALIGN(*p, sz >= 8 ? 8 : 4); | |
343 | ||
344 | pname = find_flat_dt_string(noff); | |
345 | if (pname == NULL) { | |
346 | printk("Can't find property name in list !\n"); | |
347 | break; | |
348 | } | |
349 | if (strcmp(pname, "name") == 0) | |
350 | has_name = 1; | |
351 | l = strlen(pname) + 1; | |
352 | pp = unflatten_dt_alloc(&mem, sizeof(struct property), | |
353 | __alignof__(struct property)); | |
354 | if (allnextpp) { | |
355 | if (strcmp(pname, "linux,phandle") == 0) { | |
356 | np->node = *((u32 *)*p); | |
357 | if (np->linux_phandle == 0) | |
358 | np->linux_phandle = np->node; | |
359 | } | |
360 | if (strcmp(pname, "ibm,phandle") == 0) | |
361 | np->linux_phandle = *((u32 *)*p); | |
362 | pp->name = pname; | |
363 | pp->length = sz; | |
364 | pp->value = (void *)*p; | |
365 | *prev_pp = pp; | |
366 | prev_pp = &pp->next; | |
367 | } | |
368 | *p = _ALIGN((*p) + sz, 4); | |
369 | } | |
370 | /* with version 0x10 we may not have the name property, recreate | |
371 | * it here from the unit name if absent | |
372 | */ | |
373 | if (!has_name) { | |
374 | char *p = pathp, *ps = pathp, *pa = NULL; | |
375 | int sz; | |
376 | ||
377 | while (*p) { | |
378 | if ((*p) == '@') | |
379 | pa = p; | |
380 | if ((*p) == '/') | |
381 | ps = p + 1; | |
382 | p++; | |
383 | } | |
384 | if (pa < ps) | |
385 | pa = p; | |
386 | sz = (pa - ps) + 1; | |
387 | pp = unflatten_dt_alloc(&mem, sizeof(struct property) + sz, | |
388 | __alignof__(struct property)); | |
389 | if (allnextpp) { | |
390 | pp->name = "name"; | |
391 | pp->length = sz; | |
1a38147e | 392 | pp->value = pp + 1; |
9b6b563c PM |
393 | *prev_pp = pp; |
394 | prev_pp = &pp->next; | |
395 | memcpy(pp->value, ps, sz - 1); | |
396 | ((char *)pp->value)[sz - 1] = 0; | |
1a38147e SR |
397 | DBG("fixed up name for %s -> %s\n", pathp, |
398 | (char *)pp->value); | |
9b6b563c PM |
399 | } |
400 | } | |
401 | if (allnextpp) { | |
402 | *prev_pp = NULL; | |
0e56efc7 SR |
403 | np->name = of_get_property(np, "name", NULL); |
404 | np->type = of_get_property(np, "device_type", NULL); | |
9b6b563c PM |
405 | |
406 | if (!np->name) | |
407 | np->name = "<NULL>"; | |
408 | if (!np->type) | |
409 | np->type = "<NULL>"; | |
410 | } | |
411 | while (tag == OF_DT_BEGIN_NODE) { | |
412 | mem = unflatten_dt_node(mem, p, np, allnextpp, fpsize); | |
413 | tag = *((u32 *)(*p)); | |
414 | } | |
415 | if (tag != OF_DT_END_NODE) { | |
416 | printk("Weird tag at end of node: %x\n", tag); | |
417 | return mem; | |
418 | } | |
419 | *p += 4; | |
420 | return mem; | |
421 | } | |
422 | ||
2babf5c2 ME |
423 | static int __init early_parse_mem(char *p) |
424 | { | |
425 | if (!p) | |
426 | return 1; | |
427 | ||
428 | memory_limit = PAGE_ALIGN(memparse(p, &p)); | |
429 | DBG("memory limit = 0x%lx\n", memory_limit); | |
430 | ||
431 | return 0; | |
432 | } | |
433 | early_param("mem", early_parse_mem); | |
434 | ||
3c607ce2 LV |
435 | /** |
436 | * move_device_tree - move tree to an unused area, if needed. | |
437 | * | |
438 | * The device tree may be allocated beyond our memory limit, or inside the | |
439 | * crash kernel region for kdump. If so, move it out of the way. | |
2babf5c2 | 440 | */ |
18f032cb | 441 | static void __init move_device_tree(void) |
2babf5c2 ME |
442 | { |
443 | unsigned long start, size; | |
444 | void *p; | |
445 | ||
446 | DBG("-> move_device_tree\n"); | |
447 | ||
448 | start = __pa(initial_boot_params); | |
449 | size = initial_boot_params->totalsize; | |
450 | ||
451 | if ((memory_limit && (start + size) > memory_limit) || | |
452 | overlaps_crashkernel(start, size)) { | |
453 | p = __va(lmb_alloc_base(size, PAGE_SIZE, lmb.rmo_size)); | |
454 | memcpy(p, initial_boot_params, size); | |
455 | initial_boot_params = (struct boot_param_header *)p; | |
456 | DBG("Moved device tree to 0x%p\n", p); | |
457 | } | |
458 | ||
459 | DBG("<- move_device_tree\n"); | |
460 | } | |
9b6b563c PM |
461 | |
462 | /** | |
463 | * unflattens the device-tree passed by the firmware, creating the | |
464 | * tree of struct device_node. It also fills the "name" and "type" | |
465 | * pointers of the nodes so the normal device-tree walking functions | |
466 | * can be used (this used to be done by finish_device_tree) | |
467 | */ | |
468 | void __init unflatten_device_tree(void) | |
469 | { | |
470 | unsigned long start, mem, size; | |
471 | struct device_node **allnextp = &allnodes; | |
9b6b563c PM |
472 | |
473 | DBG(" -> unflatten_device_tree()\n"); | |
474 | ||
475 | /* First pass, scan for size */ | |
476 | start = ((unsigned long)initial_boot_params) + | |
477 | initial_boot_params->off_dt_struct; | |
478 | size = unflatten_dt_node(0, &start, NULL, NULL, 0); | |
479 | size = (size | 3) + 1; | |
480 | ||
481 | DBG(" size is %lx, allocating...\n", size); | |
482 | ||
483 | /* Allocate memory for the expanded device tree */ | |
484 | mem = lmb_alloc(size + 4, __alignof__(struct device_node)); | |
9b6b563c PM |
485 | mem = (unsigned long) __va(mem); |
486 | ||
487 | ((u32 *)mem)[size / 4] = 0xdeadbeef; | |
488 | ||
489 | DBG(" unflattening %lx...\n", mem); | |
490 | ||
491 | /* Second pass, do actual unflattening */ | |
492 | start = ((unsigned long)initial_boot_params) + | |
493 | initial_boot_params->off_dt_struct; | |
494 | unflatten_dt_node(mem, &start, NULL, &allnextp, 0); | |
495 | if (*((u32 *)start) != OF_DT_END) | |
496 | printk(KERN_WARNING "Weird tag at end of tree: %08x\n", *((u32 *)start)); | |
497 | if (((u32 *)mem)[size / 4] != 0xdeadbeef) | |
498 | printk(KERN_WARNING "End of tree marker overwritten: %08x\n", | |
499 | ((u32 *)mem)[size / 4] ); | |
500 | *allnextp = NULL; | |
501 | ||
502 | /* Get pointer to OF "/chosen" node for use everywhere */ | |
503 | of_chosen = of_find_node_by_path("/chosen"); | |
a575b807 PM |
504 | if (of_chosen == NULL) |
505 | of_chosen = of_find_node_by_path("/chosen@0"); | |
9b6b563c | 506 | |
9b6b563c PM |
507 | DBG(" <- unflatten_device_tree()\n"); |
508 | } | |
509 | ||
d205819e PM |
510 | /* |
511 | * ibm,pa-features is a per-cpu property that contains a string of | |
512 | * attribute descriptors, each of which has a 2 byte header plus up | |
513 | * to 254 bytes worth of processor attribute bits. First header | |
514 | * byte specifies the number of bytes following the header. | |
515 | * Second header byte is an "attribute-specifier" type, of which | |
516 | * zero is the only currently-defined value. | |
517 | * Implementation: Pass in the byte and bit offset for the feature | |
518 | * that we are interested in. The function will return -1 if the | |
519 | * pa-features property is missing, or a 1/0 to indicate if the feature | |
520 | * is supported/not supported. Note that the bit numbers are | |
521 | * big-endian to match the definition in PAPR. | |
522 | */ | |
523 | static struct ibm_pa_feature { | |
524 | unsigned long cpu_features; /* CPU_FTR_xxx bit */ | |
525 | unsigned int cpu_user_ftrs; /* PPC_FEATURE_xxx bit */ | |
526 | unsigned char pabyte; /* byte number in ibm,pa-features */ | |
527 | unsigned char pabit; /* bit number (big-endian) */ | |
528 | unsigned char invert; /* if 1, pa bit set => clear feature */ | |
529 | } ibm_pa_features[] __initdata = { | |
530 | {0, PPC_FEATURE_HAS_MMU, 0, 0, 0}, | |
531 | {0, PPC_FEATURE_HAS_FPU, 0, 1, 0}, | |
532 | {CPU_FTR_SLB, 0, 0, 2, 0}, | |
533 | {CPU_FTR_CTRL, 0, 0, 3, 0}, | |
534 | {CPU_FTR_NOEXECUTE, 0, 0, 6, 0}, | |
535 | {CPU_FTR_NODSISRALIGN, 0, 1, 1, 1}, | |
536 | {CPU_FTR_CI_LARGE_PAGE, 0, 1, 2, 0}, | |
339d76c5 | 537 | {CPU_FTR_REAL_LE, PPC_FEATURE_TRUE_LE, 5, 0, 0}, |
d205819e PM |
538 | }; |
539 | ||
974a76f5 PM |
540 | static void __init scan_features(unsigned long node, unsigned char *ftrs, |
541 | unsigned long tablelen, | |
542 | struct ibm_pa_feature *fp, | |
543 | unsigned long ft_size) | |
d205819e | 544 | { |
974a76f5 | 545 | unsigned long i, len, bit; |
d205819e PM |
546 | |
547 | /* find descriptor with type == 0 */ | |
548 | for (;;) { | |
549 | if (tablelen < 3) | |
550 | return; | |
974a76f5 | 551 | len = 2 + ftrs[0]; |
d205819e PM |
552 | if (tablelen < len) |
553 | return; /* descriptor 0 not found */ | |
974a76f5 | 554 | if (ftrs[1] == 0) |
d205819e PM |
555 | break; |
556 | tablelen -= len; | |
974a76f5 | 557 | ftrs += len; |
d205819e PM |
558 | } |
559 | ||
560 | /* loop over bits we know about */ | |
974a76f5 PM |
561 | for (i = 0; i < ft_size; ++i, ++fp) { |
562 | if (fp->pabyte >= ftrs[0]) | |
d205819e | 563 | continue; |
974a76f5 | 564 | bit = (ftrs[2 + fp->pabyte] >> (7 - fp->pabit)) & 1; |
d205819e PM |
565 | if (bit ^ fp->invert) { |
566 | cur_cpu_spec->cpu_features |= fp->cpu_features; | |
567 | cur_cpu_spec->cpu_user_features |= fp->cpu_user_ftrs; | |
568 | } else { | |
569 | cur_cpu_spec->cpu_features &= ~fp->cpu_features; | |
570 | cur_cpu_spec->cpu_user_features &= ~fp->cpu_user_ftrs; | |
571 | } | |
572 | } | |
573 | } | |
574 | ||
974a76f5 PM |
575 | static void __init check_cpu_pa_features(unsigned long node) |
576 | { | |
577 | unsigned char *pa_ftrs; | |
578 | unsigned long tablelen; | |
579 | ||
580 | pa_ftrs = of_get_flat_dt_prop(node, "ibm,pa-features", &tablelen); | |
581 | if (pa_ftrs == NULL) | |
582 | return; | |
583 | ||
584 | scan_features(node, pa_ftrs, tablelen, | |
585 | ibm_pa_features, ARRAY_SIZE(ibm_pa_features)); | |
586 | } | |
587 | ||
584f8b71 MN |
588 | #ifdef CONFIG_PPC64 |
589 | static void __init check_cpu_slb_size(unsigned long node) | |
590 | { | |
591 | u32 *slb_size_ptr; | |
592 | ||
593 | slb_size_ptr = of_get_flat_dt_prop(node, "ibm,slb-size", NULL); | |
594 | if (slb_size_ptr != NULL) { | |
595 | mmu_slb_size = *slb_size_ptr; | |
596 | } | |
597 | } | |
598 | #else | |
599 | #define check_cpu_slb_size(node) do { } while(0) | |
600 | #endif | |
601 | ||
974a76f5 PM |
602 | static struct feature_property { |
603 | const char *name; | |
604 | u32 min_value; | |
605 | unsigned long cpu_feature; | |
606 | unsigned long cpu_user_ftr; | |
607 | } feature_properties[] __initdata = { | |
608 | #ifdef CONFIG_ALTIVEC | |
609 | {"altivec", 0, CPU_FTR_ALTIVEC, PPC_FEATURE_HAS_ALTIVEC}, | |
610 | {"ibm,vmx", 1, CPU_FTR_ALTIVEC, PPC_FEATURE_HAS_ALTIVEC}, | |
611 | #endif /* CONFIG_ALTIVEC */ | |
b962ce9d MN |
612 | #ifdef CONFIG_VSX |
613 | /* Yes, this _really_ is ibm,vmx == 2 to enable VSX */ | |
614 | {"ibm,vmx", 2, CPU_FTR_VSX, PPC_FEATURE_HAS_VSX}, | |
615 | #endif /* CONFIG_VSX */ | |
974a76f5 PM |
616 | #ifdef CONFIG_PPC64 |
617 | {"ibm,dfp", 1, 0, PPC_FEATURE_HAS_DFP}, | |
618 | {"ibm,purr", 1, CPU_FTR_PURR, 0}, | |
619 | {"ibm,spurr", 1, CPU_FTR_SPURR, 0}, | |
620 | #endif /* CONFIG_PPC64 */ | |
621 | }; | |
622 | ||
14b3d926 VB |
623 | #if defined(CONFIG_44x) && defined(CONFIG_PPC_FPU) |
624 | static inline void identical_pvr_fixup(unsigned long node) | |
625 | { | |
626 | unsigned int pvr; | |
627 | char *model = of_get_flat_dt_prop(node, "model", NULL); | |
628 | ||
629 | /* | |
630 | * Since 440GR(x)/440EP(x) processors have the same pvr, | |
631 | * we check the node path and set bit 28 in the cur_cpu_spec | |
632 | * pvr for EP(x) processor version. This bit is always 0 in | |
633 | * the "real" pvr. Then we call identify_cpu again with | |
634 | * the new logical pvr to enable FPU support. | |
635 | */ | |
636 | if (model && strstr(model, "440EP")) { | |
637 | pvr = cur_cpu_spec->pvr_value | 0x8; | |
638 | identify_cpu(0, pvr); | |
639 | DBG("Using logical pvr %x for %s\n", pvr, model); | |
640 | } | |
641 | } | |
642 | #else | |
643 | #define identical_pvr_fixup(node) do { } while(0) | |
644 | #endif | |
645 | ||
974a76f5 PM |
646 | static void __init check_cpu_feature_properties(unsigned long node) |
647 | { | |
648 | unsigned long i; | |
649 | struct feature_property *fp = feature_properties; | |
650 | const u32 *prop; | |
651 | ||
652 | for (i = 0; i < ARRAY_SIZE(feature_properties); ++i, ++fp) { | |
653 | prop = of_get_flat_dt_prop(node, fp->name, NULL); | |
654 | if (prop && *prop >= fp->min_value) { | |
655 | cur_cpu_spec->cpu_features |= fp->cpu_feature; | |
656 | cur_cpu_spec->cpu_user_features |= fp->cpu_user_ftr; | |
657 | } | |
658 | } | |
659 | } | |
660 | ||
9b6b563c | 661 | static int __init early_init_dt_scan_cpus(unsigned long node, |
4df20460 AB |
662 | const char *uname, int depth, |
663 | void *data) | |
9b6b563c | 664 | { |
4df20460 AB |
665 | static int logical_cpuid = 0; |
666 | char *type = of_get_flat_dt_prop(node, "device_type", NULL); | |
974a76f5 PM |
667 | const u32 *prop; |
668 | const u32 *intserv; | |
4df20460 AB |
669 | int i, nthreads; |
670 | unsigned long len; | |
671 | int found = 0; | |
9b6b563c PM |
672 | |
673 | /* We are scanning "cpu" nodes only */ | |
674 | if (type == NULL || strcmp(type, "cpu") != 0) | |
675 | return 0; | |
676 | ||
4df20460 AB |
677 | /* Get physical cpuid */ |
678 | intserv = of_get_flat_dt_prop(node, "ibm,ppc-interrupt-server#s", &len); | |
679 | if (intserv) { | |
680 | nthreads = len / sizeof(int); | |
9b6b563c | 681 | } else { |
4df20460 AB |
682 | intserv = of_get_flat_dt_prop(node, "reg", NULL); |
683 | nthreads = 1; | |
684 | } | |
685 | ||
686 | /* | |
687 | * Now see if any of these threads match our boot cpu. | |
688 | * NOTE: This must match the parsing done in smp_setup_cpu_maps. | |
689 | */ | |
690 | for (i = 0; i < nthreads; i++) { | |
691 | /* | |
692 | * version 2 of the kexec param format adds the phys cpuid of | |
693 | * booted proc. | |
694 | */ | |
695 | if (initial_boot_params && initial_boot_params->version >= 2) { | |
696 | if (intserv[i] == | |
697 | initial_boot_params->boot_cpuid_phys) { | |
698 | found = 1; | |
699 | break; | |
700 | } | |
701 | } else { | |
702 | /* | |
703 | * Check if it's the boot-cpu, set it's hw index now, | |
704 | * unfortunately this format did not support booting | |
705 | * off secondary threads. | |
706 | */ | |
707 | if (of_get_flat_dt_prop(node, | |
3c726f8d | 708 | "linux,boot-cpu", NULL) != NULL) { |
4df20460 AB |
709 | found = 1; |
710 | break; | |
711 | } | |
9b6b563c | 712 | } |
4df20460 AB |
713 | |
714 | #ifdef CONFIG_SMP | |
715 | /* logical cpu id is always 0 on UP kernels */ | |
716 | logical_cpuid++; | |
717 | #endif | |
718 | } | |
719 | ||
720 | if (found) { | |
721 | DBG("boot cpu: logical %d physical %d\n", logical_cpuid, | |
722 | intserv[i]); | |
723 | boot_cpuid = logical_cpuid; | |
724 | set_hard_smp_processor_id(boot_cpuid, intserv[i]); | |
9b6b563c | 725 | |
974a76f5 PM |
726 | /* |
727 | * PAPR defines "logical" PVR values for cpus that | |
728 | * meet various levels of the architecture: | |
729 | * 0x0f000001 Architecture version 2.04 | |
730 | * 0x0f000002 Architecture version 2.05 | |
731 | * If the cpu-version property in the cpu node contains | |
732 | * such a value, we call identify_cpu again with the | |
733 | * logical PVR value in order to use the cpu feature | |
734 | * bits appropriate for the architecture level. | |
735 | * | |
736 | * A POWER6 partition in "POWER6 architected" mode | |
737 | * uses the 0x0f000002 PVR value; in POWER5+ mode | |
738 | * it uses 0x0f000001. | |
739 | */ | |
740 | prop = of_get_flat_dt_prop(node, "cpu-version", NULL); | |
741 | if (prop && (*prop & 0xff000000) == 0x0f000000) | |
742 | identify_cpu(0, *prop); | |
14b3d926 VB |
743 | |
744 | identical_pvr_fixup(node); | |
9b6b563c | 745 | } |
9b6b563c | 746 | |
974a76f5 | 747 | check_cpu_feature_properties(node); |
d205819e | 748 | check_cpu_pa_features(node); |
584f8b71 | 749 | check_cpu_slb_size(node); |
d205819e | 750 | |
9b6b563c | 751 | #ifdef CONFIG_PPC_PSERIES |
4df20460 | 752 | if (nthreads > 1) |
9b6b563c | 753 | cur_cpu_spec->cpu_features |= CPU_FTR_SMT; |
4df20460 AB |
754 | else |
755 | cur_cpu_spec->cpu_features &= ~CPU_FTR_SMT; | |
9b6b563c PM |
756 | #endif |
757 | ||
758 | return 0; | |
759 | } | |
760 | ||
40472a55 ME |
761 | #ifdef CONFIG_BLK_DEV_INITRD |
762 | static void __init early_init_dt_check_for_initrd(unsigned long node) | |
763 | { | |
764 | unsigned long l; | |
765 | u32 *prop; | |
766 | ||
767 | DBG("Looking for initrd properties... "); | |
768 | ||
769 | prop = of_get_flat_dt_prop(node, "linux,initrd-start", &l); | |
770 | if (prop) { | |
771 | initrd_start = (unsigned long)__va(of_read_ulong(prop, l/4)); | |
772 | ||
773 | prop = of_get_flat_dt_prop(node, "linux,initrd-end", &l); | |
774 | if (prop) { | |
775 | initrd_end = (unsigned long) | |
776 | __va(of_read_ulong(prop, l/4)); | |
777 | initrd_below_start_ok = 1; | |
778 | } else { | |
779 | initrd_start = 0; | |
780 | } | |
781 | } | |
782 | ||
783 | DBG("initrd_start=0x%lx initrd_end=0x%lx\n", initrd_start, initrd_end); | |
784 | } | |
785 | #else | |
786 | static inline void early_init_dt_check_for_initrd(unsigned long node) | |
787 | { | |
788 | } | |
789 | #endif /* CONFIG_BLK_DEV_INITRD */ | |
790 | ||
9b6b563c PM |
791 | static int __init early_init_dt_scan_chosen(unsigned long node, |
792 | const char *uname, int depth, void *data) | |
793 | { | |
9b6b563c | 794 | unsigned long *lprop; |
329dda08 KG |
795 | unsigned long l; |
796 | char *p; | |
9b6b563c PM |
797 | |
798 | DBG("search \"chosen\", depth: %d, uname: %s\n", depth, uname); | |
799 | ||
a575b807 PM |
800 | if (depth != 1 || |
801 | (strcmp(uname, "chosen") != 0 && strcmp(uname, "chosen@0") != 0)) | |
9b6b563c PM |
802 | return 0; |
803 | ||
9b6b563c PM |
804 | #ifdef CONFIG_PPC64 |
805 | /* check if iommu is forced on or off */ | |
3c726f8d | 806 | if (of_get_flat_dt_prop(node, "linux,iommu-off", NULL) != NULL) |
9b6b563c | 807 | iommu_is_off = 1; |
3c726f8d | 808 | if (of_get_flat_dt_prop(node, "linux,iommu-force-on", NULL) != NULL) |
9b6b563c PM |
809 | iommu_force_on = 1; |
810 | #endif | |
811 | ||
2babf5c2 | 812 | /* mem=x on the command line is the preferred mechanism */ |
3c726f8d | 813 | lprop = of_get_flat_dt_prop(node, "linux,memory-limit", NULL); |
9b6b563c PM |
814 | if (lprop) |
815 | memory_limit = *lprop; | |
816 | ||
817 | #ifdef CONFIG_PPC64 | |
3c726f8d | 818 | lprop = of_get_flat_dt_prop(node, "linux,tce-alloc-start", NULL); |
9b6b563c PM |
819 | if (lprop) |
820 | tce_alloc_start = *lprop; | |
3c726f8d | 821 | lprop = of_get_flat_dt_prop(node, "linux,tce-alloc-end", NULL); |
9b6b563c PM |
822 | if (lprop) |
823 | tce_alloc_end = *lprop; | |
824 | #endif | |
825 | ||
dcee3036 | 826 | #ifdef CONFIG_KEXEC |
70c6cc37 LV |
827 | lprop = (u64*)of_get_flat_dt_prop(node, "linux,crashkernel-base", NULL); |
828 | if (lprop) | |
829 | crashk_res.start = *lprop; | |
dcee3036 | 830 | |
70c6cc37 LV |
831 | lprop = (u64*)of_get_flat_dt_prop(node, "linux,crashkernel-size", NULL); |
832 | if (lprop) | |
833 | crashk_res.end = crashk_res.start + *lprop - 1; | |
dcee3036 ME |
834 | #endif |
835 | ||
40472a55 | 836 | early_init_dt_check_for_initrd(node); |
30437b3e | 837 | |
329dda08 KG |
838 | /* Retreive command line */ |
839 | p = of_get_flat_dt_prop(node, "bootargs", &l); | |
840 | if (p != NULL && l > 0) | |
841 | strlcpy(cmd_line, p, min((int)l, COMMAND_LINE_SIZE)); | |
842 | ||
843 | #ifdef CONFIG_CMDLINE | |
c1ce464d | 844 | if (p == NULL || l == 0 || (l == 1 && (*p) == 0)) |
329dda08 KG |
845 | strlcpy(cmd_line, CONFIG_CMDLINE, COMMAND_LINE_SIZE); |
846 | #endif /* CONFIG_CMDLINE */ | |
847 | ||
848 | DBG("Command line is: %s\n", cmd_line); | |
849 | ||
9b6b563c PM |
850 | /* break now */ |
851 | return 1; | |
852 | } | |
853 | ||
854 | static int __init early_init_dt_scan_root(unsigned long node, | |
855 | const char *uname, int depth, void *data) | |
856 | { | |
857 | u32 *prop; | |
858 | ||
859 | if (depth != 0) | |
860 | return 0; | |
861 | ||
3c726f8d | 862 | prop = of_get_flat_dt_prop(node, "#size-cells", NULL); |
9b6b563c PM |
863 | dt_root_size_cells = (prop == NULL) ? 1 : *prop; |
864 | DBG("dt_root_size_cells = %x\n", dt_root_size_cells); | |
865 | ||
3c726f8d | 866 | prop = of_get_flat_dt_prop(node, "#address-cells", NULL); |
9b6b563c PM |
867 | dt_root_addr_cells = (prop == NULL) ? 2 : *prop; |
868 | DBG("dt_root_addr_cells = %x\n", dt_root_addr_cells); | |
869 | ||
870 | /* break now */ | |
871 | return 1; | |
872 | } | |
873 | ||
abe76885 | 874 | static u64 __init dt_mem_next_cell(int s, cell_t **cellp) |
9b6b563c PM |
875 | { |
876 | cell_t *p = *cellp; | |
9b6b563c | 877 | |
a4dc7ff0 | 878 | *cellp = p + s; |
abe76885 | 879 | return of_read_number(p, s); |
9b6b563c PM |
880 | } |
881 | ||
0204568a PM |
882 | #ifdef CONFIG_PPC_PSERIES |
883 | /* | |
884 | * Interpret the ibm,dynamic-memory property in the | |
885 | * /ibm,dynamic-reconfiguration-memory node. | |
886 | * This contains a list of memory blocks along with NUMA affinity | |
887 | * information. | |
888 | */ | |
889 | static int __init early_init_dt_scan_drconf_memory(unsigned long node) | |
890 | { | |
cf00085d | 891 | cell_t *dm, *ls, *usm; |
abe76885 BB |
892 | unsigned long l, n, flags; |
893 | u64 base, size, lmb_size; | |
cf00085d | 894 | unsigned int is_kexec_kdump = 0, rngs; |
0204568a PM |
895 | |
896 | ls = (cell_t *)of_get_flat_dt_prop(node, "ibm,lmb-size", &l); | |
897 | if (ls == NULL || l < dt_root_size_cells * sizeof(cell_t)) | |
898 | return 0; | |
899 | lmb_size = dt_mem_next_cell(dt_root_size_cells, &ls); | |
900 | ||
901 | dm = (cell_t *)of_get_flat_dt_prop(node, "ibm,dynamic-memory", &l); | |
902 | if (dm == NULL || l < sizeof(cell_t)) | |
903 | return 0; | |
904 | ||
905 | n = *dm++; /* number of entries */ | |
906 | if (l < (n * (dt_root_addr_cells + 4) + 1) * sizeof(cell_t)) | |
907 | return 0; | |
908 | ||
cf00085d C |
909 | /* check if this is a kexec/kdump kernel. */ |
910 | usm = (cell_t *)of_get_flat_dt_prop(node, "linux,drconf-usable-memory", | |
911 | &l); | |
912 | if (usm != NULL) | |
913 | is_kexec_kdump = 1; | |
914 | ||
0204568a PM |
915 | for (; n != 0; --n) { |
916 | base = dt_mem_next_cell(dt_root_addr_cells, &dm); | |
917 | flags = dm[3]; | |
918 | /* skip DRC index, pad, assoc. list index, flags */ | |
919 | dm += 4; | |
920 | /* skip this block if the reserved bit is set in flags (0x80) | |
921 | or if the block is not assigned to this partition (0x8) */ | |
922 | if ((flags & 0x80) || !(flags & 0x8)) | |
923 | continue; | |
924 | size = lmb_size; | |
cf00085d C |
925 | rngs = 1; |
926 | if (is_kexec_kdump) { | |
927 | /* | |
928 | * For each lmb in ibm,dynamic-memory, a corresponding | |
929 | * entry in linux,drconf-usable-memory property contains | |
930 | * a counter 'p' followed by 'p' (base, size) duple. | |
931 | * Now read the counter from | |
932 | * linux,drconf-usable-memory property | |
933 | */ | |
934 | rngs = dt_mem_next_cell(dt_root_size_cells, &usm); | |
935 | if (!rngs) /* there are no (base, size) duple */ | |
0204568a | 936 | continue; |
0204568a | 937 | } |
cf00085d C |
938 | do { |
939 | if (is_kexec_kdump) { | |
940 | base = dt_mem_next_cell(dt_root_addr_cells, | |
941 | &usm); | |
942 | size = dt_mem_next_cell(dt_root_size_cells, | |
943 | &usm); | |
944 | } | |
945 | if (iommu_is_off) { | |
946 | if (base >= 0x80000000ul) | |
947 | continue; | |
948 | if ((base + size) > 0x80000000ul) | |
949 | size = 0x80000000ul - base; | |
950 | } | |
951 | lmb_add(base, size); | |
952 | } while (--rngs); | |
0204568a PM |
953 | } |
954 | lmb_dump_all(); | |
955 | return 0; | |
956 | } | |
957 | #else | |
958 | #define early_init_dt_scan_drconf_memory(node) 0 | |
959 | #endif /* CONFIG_PPC_PSERIES */ | |
9b6b563c PM |
960 | |
961 | static int __init early_init_dt_scan_memory(unsigned long node, | |
962 | const char *uname, int depth, void *data) | |
963 | { | |
3c726f8d | 964 | char *type = of_get_flat_dt_prop(node, "device_type", NULL); |
9b6b563c PM |
965 | cell_t *reg, *endp; |
966 | unsigned long l; | |
967 | ||
0204568a PM |
968 | /* Look for the ibm,dynamic-reconfiguration-memory node */ |
969 | if (depth == 1 && | |
970 | strcmp(uname, "ibm,dynamic-reconfiguration-memory") == 0) | |
971 | return early_init_dt_scan_drconf_memory(node); | |
972 | ||
9b6b563c | 973 | /* We are scanning "memory" nodes only */ |
a23414be PM |
974 | if (type == NULL) { |
975 | /* | |
976 | * The longtrail doesn't have a device_type on the | |
977 | * /memory node, so look for the node called /memory@0. | |
978 | */ | |
979 | if (depth != 1 || strcmp(uname, "memory@0") != 0) | |
980 | return 0; | |
981 | } else if (strcmp(type, "memory") != 0) | |
9b6b563c PM |
982 | return 0; |
983 | ||
ba759485 ME |
984 | reg = (cell_t *)of_get_flat_dt_prop(node, "linux,usable-memory", &l); |
985 | if (reg == NULL) | |
986 | reg = (cell_t *)of_get_flat_dt_prop(node, "reg", &l); | |
9b6b563c PM |
987 | if (reg == NULL) |
988 | return 0; | |
989 | ||
990 | endp = reg + (l / sizeof(cell_t)); | |
991 | ||
358c86fd | 992 | DBG("memory scan node %s, reg size %ld, data: %x %x %x %x,\n", |
9b6b563c PM |
993 | uname, l, reg[0], reg[1], reg[2], reg[3]); |
994 | ||
995 | while ((endp - reg) >= (dt_root_addr_cells + dt_root_size_cells)) { | |
abe76885 | 996 | u64 base, size; |
9b6b563c PM |
997 | |
998 | base = dt_mem_next_cell(dt_root_addr_cells, ®); | |
999 | size = dt_mem_next_cell(dt_root_size_cells, ®); | |
1000 | ||
1001 | if (size == 0) | |
1002 | continue; | |
abe76885 BB |
1003 | DBG(" - %llx , %llx\n", (unsigned long long)base, |
1004 | (unsigned long long)size); | |
9b6b563c PM |
1005 | #ifdef CONFIG_PPC64 |
1006 | if (iommu_is_off) { | |
1007 | if (base >= 0x80000000ul) | |
1008 | continue; | |
1009 | if ((base + size) > 0x80000000ul) | |
1010 | size = 0x80000000ul - base; | |
1011 | } | |
1012 | #endif | |
1013 | lmb_add(base, size); | |
37dd2bad KG |
1014 | |
1015 | memstart_addr = min((u64)memstart_addr, base); | |
9b6b563c | 1016 | } |
37dd2bad | 1017 | |
9b6b563c PM |
1018 | return 0; |
1019 | } | |
1020 | ||
1021 | static void __init early_reserve_mem(void) | |
1022 | { | |
cbbcf340 KG |
1023 | u64 base, size; |
1024 | u64 *reserve_map; | |
8a300887 JL |
1025 | unsigned long self_base; |
1026 | unsigned long self_size; | |
9b6b563c | 1027 | |
cbbcf340 | 1028 | reserve_map = (u64 *)(((unsigned long)initial_boot_params) + |
9b6b563c | 1029 | initial_boot_params->off_mem_rsvmap); |
4d1f3f25 JX |
1030 | |
1031 | /* before we do anything, lets reserve the dt blob */ | |
8a300887 JL |
1032 | self_base = __pa((unsigned long)initial_boot_params); |
1033 | self_size = initial_boot_params->totalsize; | |
1034 | lmb_reserve(self_base, self_size); | |
4d1f3f25 | 1035 | |
30437b3e DG |
1036 | #ifdef CONFIG_BLK_DEV_INITRD |
1037 | /* then reserve the initrd, if any */ | |
1038 | if (initrd_start && (initrd_end > initrd_start)) | |
1039 | lmb_reserve(__pa(initrd_start), initrd_end - initrd_start); | |
1040 | #endif /* CONFIG_BLK_DEV_INITRD */ | |
1041 | ||
cbbcf340 KG |
1042 | #ifdef CONFIG_PPC32 |
1043 | /* | |
1044 | * Handle the case where we might be booting from an old kexec | |
1045 | * image that setup the mem_rsvmap as pairs of 32-bit values | |
1046 | */ | |
1047 | if (*reserve_map > 0xffffffffull) { | |
1048 | u32 base_32, size_32; | |
1049 | u32 *reserve_map_32 = (u32 *)reserve_map; | |
1050 | ||
1051 | while (1) { | |
1052 | base_32 = *(reserve_map_32++); | |
1053 | size_32 = *(reserve_map_32++); | |
1054 | if (size_32 == 0) | |
1055 | break; | |
8a300887 JL |
1056 | /* skip if the reservation is for the blob */ |
1057 | if (base_32 == self_base && size_32 == self_size) | |
1058 | continue; | |
329dda08 | 1059 | DBG("reserving: %x -> %x\n", base_32, size_32); |
cbbcf340 KG |
1060 | lmb_reserve(base_32, size_32); |
1061 | } | |
1062 | return; | |
1063 | } | |
1064 | #endif | |
9b6b563c PM |
1065 | while (1) { |
1066 | base = *(reserve_map++); | |
1067 | size = *(reserve_map++); | |
1068 | if (size == 0) | |
1069 | break; | |
cbbcf340 | 1070 | DBG("reserving: %llx -> %llx\n", base, size); |
9b6b563c PM |
1071 | lmb_reserve(base, size); |
1072 | } | |
1073 | ||
1074 | #if 0 | |
1075 | DBG("memory reserved, lmbs :\n"); | |
1076 | lmb_dump_all(); | |
1077 | #endif | |
1078 | } | |
1079 | ||
6ac26c8a | 1080 | #ifdef CONFIG_PHYP_DUMP |
37ddd5d0 MA |
1081 | /** |
1082 | * phyp_dump_calculate_reserve_size() - reserve variable boot area 5% or arg | |
1083 | * | |
1084 | * Function to find the largest size we need to reserve | |
1085 | * during early boot process. | |
1086 | * | |
1087 | * It either looks for boot param and returns that OR | |
1088 | * returns larger of 256 or 5% rounded down to multiples of 256MB. | |
1089 | * | |
1090 | */ | |
1091 | static inline unsigned long phyp_dump_calculate_reserve_size(void) | |
1092 | { | |
1093 | unsigned long tmp; | |
1094 | ||
1095 | if (phyp_dump_info->reserve_bootvar) | |
1096 | return phyp_dump_info->reserve_bootvar; | |
1097 | ||
1098 | /* divide by 20 to get 5% of value */ | |
1099 | tmp = lmb_end_of_DRAM(); | |
1100 | do_div(tmp, 20); | |
1101 | ||
1102 | /* round it down in multiples of 256 */ | |
1103 | tmp = tmp & ~0x0FFFFFFFUL; | |
1104 | ||
1105 | return (tmp > PHYP_DUMP_RMR_END ? tmp : PHYP_DUMP_RMR_END); | |
1106 | } | |
1107 | ||
6ac26c8a MA |
1108 | /** |
1109 | * phyp_dump_reserve_mem() - reserve all not-yet-dumped mmemory | |
1110 | * | |
1111 | * This routine may reserve memory regions in the kernel only | |
1112 | * if the system is supported and a dump was taken in last | |
1113 | * boot instance or if the hardware is supported and the | |
1114 | * scratch area needs to be setup. In other instances it returns | |
1115 | * without reserving anything. The memory in case of dump being | |
1116 | * active is freed when the dump is collected (by userland tools). | |
1117 | */ | |
1118 | static void __init phyp_dump_reserve_mem(void) | |
1119 | { | |
1120 | unsigned long base, size; | |
37ddd5d0 MA |
1121 | unsigned long variable_reserve_size; |
1122 | ||
6ac26c8a MA |
1123 | if (!phyp_dump_info->phyp_dump_configured) { |
1124 | printk(KERN_ERR "Phyp-dump not supported on this hardware\n"); | |
1125 | return; | |
1126 | } | |
1127 | ||
654f596d MA |
1128 | if (!phyp_dump_info->phyp_dump_at_boot) { |
1129 | printk(KERN_INFO "Phyp-dump disabled at boot time\n"); | |
1130 | return; | |
1131 | } | |
1132 | ||
37ddd5d0 MA |
1133 | variable_reserve_size = phyp_dump_calculate_reserve_size(); |
1134 | ||
6ac26c8a MA |
1135 | if (phyp_dump_info->phyp_dump_is_active) { |
1136 | /* Reserve *everything* above RMR.Area freed by userland tools*/ | |
37ddd5d0 | 1137 | base = variable_reserve_size; |
6ac26c8a MA |
1138 | size = lmb_end_of_DRAM() - base; |
1139 | ||
1140 | /* XXX crashed_ram_end is wrong, since it may be beyond | |
1141 | * the memory_limit, it will need to be adjusted. */ | |
1142 | lmb_reserve(base, size); | |
1143 | ||
1144 | phyp_dump_info->init_reserve_start = base; | |
1145 | phyp_dump_info->init_reserve_size = size; | |
1146 | } else { | |
1147 | size = phyp_dump_info->cpu_state_size + | |
1148 | phyp_dump_info->hpte_region_size + | |
37ddd5d0 | 1149 | variable_reserve_size; |
6ac26c8a MA |
1150 | base = lmb_end_of_DRAM() - size; |
1151 | lmb_reserve(base, size); | |
1152 | phyp_dump_info->init_reserve_start = base; | |
1153 | phyp_dump_info->init_reserve_size = size; | |
1154 | } | |
1155 | } | |
1156 | #else | |
1157 | static inline void __init phyp_dump_reserve_mem(void) {} | |
1158 | #endif /* CONFIG_PHYP_DUMP && CONFIG_PPC_RTAS */ | |
1159 | ||
1160 | ||
9b6b563c PM |
1161 | void __init early_init_devtree(void *params) |
1162 | { | |
44348105 | 1163 | DBG(" -> early_init_devtree(%p)\n", params); |
9b6b563c PM |
1164 | |
1165 | /* Setup flat device-tree pointer */ | |
1166 | initial_boot_params = params; | |
1167 | ||
458148c0 ME |
1168 | #ifdef CONFIG_PPC_RTAS |
1169 | /* Some machines might need RTAS info for debugging, grab it now. */ | |
1170 | of_scan_flat_dt(early_init_dt_scan_rtas, NULL); | |
1171 | #endif | |
1172 | ||
6ac26c8a MA |
1173 | #ifdef CONFIG_PHYP_DUMP |
1174 | /* scan tree to see if dump occured during last boot */ | |
1175 | of_scan_flat_dt(early_init_dt_scan_phyp_dump, NULL); | |
1176 | #endif | |
1177 | ||
9b6b563c PM |
1178 | /* Retrieve various informations from the /chosen node of the |
1179 | * device-tree, including the platform type, initrd location and | |
1180 | * size, TCE reserve, and more ... | |
1181 | */ | |
3c726f8d | 1182 | of_scan_flat_dt(early_init_dt_scan_chosen, NULL); |
9b6b563c PM |
1183 | |
1184 | /* Scan memory nodes and rebuild LMBs */ | |
1185 | lmb_init(); | |
3c726f8d BH |
1186 | of_scan_flat_dt(early_init_dt_scan_root, NULL); |
1187 | of_scan_flat_dt(early_init_dt_scan_memory, NULL); | |
846f77b0 ME |
1188 | |
1189 | /* Save command line for /proc/cmdline and then parse parameters */ | |
b8757b21 | 1190 | strlcpy(boot_command_line, cmd_line, COMMAND_LINE_SIZE); |
846f77b0 ME |
1191 | parse_early_param(); |
1192 | ||
9b6b563c | 1193 | /* Reserve LMB regions used by kernel, initrd, dt, etc... */ |
0cc4746c | 1194 | lmb_reserve(PHYSICAL_START, __pa(klimit) - PHYSICAL_START); |
47310413 | 1195 | reserve_kdump_trampoline(); |
35dd5432 | 1196 | reserve_crashkernel(); |
9b6b563c | 1197 | early_reserve_mem(); |
6ac26c8a | 1198 | phyp_dump_reserve_mem(); |
9b6b563c | 1199 | |
2babf5c2 ME |
1200 | lmb_enforce_memory_limit(memory_limit); |
1201 | lmb_analyze(); | |
1202 | ||
1203 | DBG("Phys. mem: %lx\n", lmb_phys_mem_size()); | |
1204 | ||
1205 | /* We may need to relocate the flat tree, do it now. | |
1206 | * FIXME .. and the initrd too? */ | |
1207 | move_device_tree(); | |
1208 | ||
9b6b563c PM |
1209 | DBG("Scanning CPUs ...\n"); |
1210 | ||
3c726f8d BH |
1211 | /* Retreive CPU related informations from the flat tree |
1212 | * (altivec support, boot CPU ID, ...) | |
9b6b563c | 1213 | */ |
3c726f8d | 1214 | of_scan_flat_dt(early_init_dt_scan_cpus, NULL); |
9b6b563c | 1215 | |
9b6b563c PM |
1216 | DBG(" <- early_init_devtree()\n"); |
1217 | } | |
1218 | ||
9b6b563c | 1219 | |
9b6b563c PM |
1220 | /** |
1221 | * Indicates whether the root node has a given value in its | |
1222 | * compatible property. | |
1223 | */ | |
1224 | int machine_is_compatible(const char *compat) | |
1225 | { | |
1226 | struct device_node *root; | |
1227 | int rc = 0; | |
1228 | ||
1229 | root = of_find_node_by_path("/"); | |
1230 | if (root) { | |
7a92f74f | 1231 | rc = of_device_is_compatible(root, compat); |
9b6b563c PM |
1232 | of_node_put(root); |
1233 | } | |
1234 | return rc; | |
1235 | } | |
1236 | EXPORT_SYMBOL(machine_is_compatible); | |
1237 | ||
9b6b563c PM |
1238 | /******* |
1239 | * | |
1240 | * New implementation of the OF "find" APIs, return a refcounted | |
1241 | * object, call of_node_put() when done. The device tree and list | |
1242 | * are protected by a rw_lock. | |
1243 | * | |
1244 | * Note that property management will need some locking as well, | |
1245 | * this isn't dealt with yet. | |
1246 | * | |
1247 | *******/ | |
1248 | ||
9b6b563c PM |
1249 | /** |
1250 | * of_find_node_by_phandle - Find a node given a phandle | |
1251 | * @handle: phandle of the node to find | |
1252 | * | |
1253 | * Returns a node pointer with refcount incremented, use | |
1254 | * of_node_put() on it when done. | |
1255 | */ | |
1256 | struct device_node *of_find_node_by_phandle(phandle handle) | |
1257 | { | |
1258 | struct device_node *np; | |
1259 | ||
1260 | read_lock(&devtree_lock); | |
1261 | for (np = allnodes; np != 0; np = np->allnext) | |
1262 | if (np->linux_phandle == handle) | |
1263 | break; | |
b1374051 | 1264 | of_node_get(np); |
9b6b563c PM |
1265 | read_unlock(&devtree_lock); |
1266 | return np; | |
1267 | } | |
1268 | EXPORT_SYMBOL(of_find_node_by_phandle); | |
1269 | ||
1270 | /** | |
1271 | * of_find_all_nodes - Get next node in global list | |
1272 | * @prev: Previous node or NULL to start iteration | |
1273 | * of_node_put() will be called on it | |
1274 | * | |
1275 | * Returns a node pointer with refcount incremented, use | |
1276 | * of_node_put() on it when done. | |
1277 | */ | |
1278 | struct device_node *of_find_all_nodes(struct device_node *prev) | |
1279 | { | |
1280 | struct device_node *np; | |
1281 | ||
1282 | read_lock(&devtree_lock); | |
1283 | np = prev ? prev->allnext : allnodes; | |
1284 | for (; np != 0; np = np->allnext) | |
1285 | if (of_node_get(np)) | |
1286 | break; | |
b1374051 | 1287 | of_node_put(prev); |
9b6b563c PM |
1288 | read_unlock(&devtree_lock); |
1289 | return np; | |
1290 | } | |
1291 | EXPORT_SYMBOL(of_find_all_nodes); | |
1292 | ||
9b6b563c PM |
1293 | /** |
1294 | * of_node_get - Increment refcount of a node | |
1295 | * @node: Node to inc refcount, NULL is supported to | |
1296 | * simplify writing of callers | |
1297 | * | |
1298 | * Returns node. | |
1299 | */ | |
1300 | struct device_node *of_node_get(struct device_node *node) | |
1301 | { | |
1302 | if (node) | |
1303 | kref_get(&node->kref); | |
1304 | return node; | |
1305 | } | |
1306 | EXPORT_SYMBOL(of_node_get); | |
1307 | ||
1308 | static inline struct device_node * kref_to_device_node(struct kref *kref) | |
1309 | { | |
1310 | return container_of(kref, struct device_node, kref); | |
1311 | } | |
1312 | ||
1313 | /** | |
1314 | * of_node_release - release a dynamically allocated node | |
1315 | * @kref: kref element of the node to be released | |
1316 | * | |
1317 | * In of_node_put() this function is passed to kref_put() | |
1318 | * as the destructor. | |
1319 | */ | |
1320 | static void of_node_release(struct kref *kref) | |
1321 | { | |
1322 | struct device_node *node = kref_to_device_node(kref); | |
1323 | struct property *prop = node->properties; | |
1324 | ||
6a281856 ME |
1325 | /* We should never be releasing nodes that haven't been detached. */ |
1326 | if (!of_node_check_flag(node, OF_DETACHED)) { | |
1327 | printk("WARNING: Bad of_node_put() on %s\n", node->full_name); | |
1328 | dump_stack(); | |
1329 | kref_init(&node->kref); | |
1330 | return; | |
1331 | } | |
1332 | ||
d3b814bb | 1333 | if (!of_node_check_flag(node, OF_DYNAMIC)) |
9b6b563c | 1334 | return; |
6a281856 | 1335 | |
9b6b563c PM |
1336 | while (prop) { |
1337 | struct property *next = prop->next; | |
1338 | kfree(prop->name); | |
1339 | kfree(prop->value); | |
1340 | kfree(prop); | |
1341 | prop = next; | |
088186de DB |
1342 | |
1343 | if (!prop) { | |
1344 | prop = node->deadprops; | |
1345 | node->deadprops = NULL; | |
1346 | } | |
9b6b563c | 1347 | } |
9b6b563c PM |
1348 | kfree(node->full_name); |
1349 | kfree(node->data); | |
1350 | kfree(node); | |
1351 | } | |
1352 | ||
1353 | /** | |
1354 | * of_node_put - Decrement refcount of a node | |
1355 | * @node: Node to dec refcount, NULL is supported to | |
1356 | * simplify writing of callers | |
1357 | * | |
1358 | */ | |
1359 | void of_node_put(struct device_node *node) | |
1360 | { | |
1361 | if (node) | |
1362 | kref_put(&node->kref, of_node_release); | |
1363 | } | |
1364 | EXPORT_SYMBOL(of_node_put); | |
1365 | ||
1366 | /* | |
1367 | * Plug a device node into the tree and global list. | |
1368 | */ | |
1369 | void of_attach_node(struct device_node *np) | |
1370 | { | |
f4ac7b5e BH |
1371 | unsigned long flags; |
1372 | ||
1373 | write_lock_irqsave(&devtree_lock, flags); | |
9b6b563c PM |
1374 | np->sibling = np->parent->child; |
1375 | np->allnext = allnodes; | |
1376 | np->parent->child = np; | |
1377 | allnodes = np; | |
f4ac7b5e | 1378 | write_unlock_irqrestore(&devtree_lock, flags); |
9b6b563c PM |
1379 | } |
1380 | ||
1381 | /* | |
1382 | * "Unplug" a node from the device tree. The caller must hold | |
1383 | * a reference to the node. The memory associated with the node | |
1384 | * is not freed until its refcount goes to zero. | |
1385 | */ | |
34f329db | 1386 | void of_detach_node(struct device_node *np) |
9b6b563c PM |
1387 | { |
1388 | struct device_node *parent; | |
f4ac7b5e | 1389 | unsigned long flags; |
9b6b563c | 1390 | |
f4ac7b5e | 1391 | write_lock_irqsave(&devtree_lock, flags); |
9b6b563c PM |
1392 | |
1393 | parent = np->parent; | |
972d17c9 ME |
1394 | if (!parent) |
1395 | goto out_unlock; | |
9b6b563c PM |
1396 | |
1397 | if (allnodes == np) | |
1398 | allnodes = np->allnext; | |
1399 | else { | |
1400 | struct device_node *prev; | |
1401 | for (prev = allnodes; | |
1402 | prev->allnext != np; | |
1403 | prev = prev->allnext) | |
1404 | ; | |
1405 | prev->allnext = np->allnext; | |
1406 | } | |
1407 | ||
1408 | if (parent->child == np) | |
1409 | parent->child = np->sibling; | |
1410 | else { | |
1411 | struct device_node *prevsib; | |
1412 | for (prevsib = np->parent->child; | |
1413 | prevsib->sibling != np; | |
1414 | prevsib = prevsib->sibling) | |
1415 | ; | |
1416 | prevsib->sibling = np->sibling; | |
1417 | } | |
1418 | ||
6a281856 ME |
1419 | of_node_set_flag(np, OF_DETACHED); |
1420 | ||
972d17c9 | 1421 | out_unlock: |
f4ac7b5e | 1422 | write_unlock_irqrestore(&devtree_lock, flags); |
9b6b563c PM |
1423 | } |
1424 | ||
1425 | #ifdef CONFIG_PPC_PSERIES | |
1426 | /* | |
1427 | * Fix up the uninitialized fields in a new device node: | |
0ebfff14 | 1428 | * name, type and pci-specific fields |
9b6b563c PM |
1429 | */ |
1430 | ||
cc5d0189 | 1431 | static int of_finish_dynamic_node(struct device_node *node) |
9b6b563c PM |
1432 | { |
1433 | struct device_node *parent = of_get_parent(node); | |
1434 | int err = 0; | |
a7f67bdf | 1435 | const phandle *ibm_phandle; |
9b6b563c | 1436 | |
0e56efc7 SR |
1437 | node->name = of_get_property(node, "name", NULL); |
1438 | node->type = of_get_property(node, "device_type", NULL); | |
9b6b563c | 1439 | |
847f5976 BH |
1440 | if (!node->name) |
1441 | node->name = "<NULL>"; | |
1442 | if (!node->type) | |
1443 | node->type = "<NULL>"; | |
1444 | ||
9b6b563c PM |
1445 | if (!parent) { |
1446 | err = -ENODEV; | |
1447 | goto out; | |
1448 | } | |
1449 | ||
1450 | /* We don't support that function on PowerMac, at least | |
1451 | * not yet | |
1452 | */ | |
e8222502 | 1453 | if (machine_is(powermac)) |
9b6b563c PM |
1454 | return -ENODEV; |
1455 | ||
1456 | /* fix up new node's linux_phandle field */ | |
0e56efc7 | 1457 | if ((ibm_phandle = of_get_property(node, "ibm,phandle", NULL))) |
9b6b563c PM |
1458 | node->linux_phandle = *ibm_phandle; |
1459 | ||
1460 | out: | |
1461 | of_node_put(parent); | |
1462 | return err; | |
1463 | } | |
1464 | ||
1465 | static int prom_reconfig_notifier(struct notifier_block *nb, | |
1466 | unsigned long action, void *node) | |
1467 | { | |
1468 | int err; | |
1469 | ||
1470 | switch (action) { | |
1471 | case PSERIES_RECONFIG_ADD: | |
cc5d0189 | 1472 | err = of_finish_dynamic_node(node); |
9b6b563c PM |
1473 | if (err < 0) { |
1474 | printk(KERN_ERR "finish_node returned %d\n", err); | |
1475 | err = NOTIFY_BAD; | |
1476 | } | |
1477 | break; | |
1478 | default: | |
1479 | err = NOTIFY_DONE; | |
1480 | break; | |
1481 | } | |
1482 | return err; | |
1483 | } | |
1484 | ||
1485 | static struct notifier_block prom_reconfig_nb = { | |
1486 | .notifier_call = prom_reconfig_notifier, | |
1487 | .priority = 10, /* This one needs to run first */ | |
1488 | }; | |
1489 | ||
1490 | static int __init prom_reconfig_setup(void) | |
1491 | { | |
1492 | return pSeries_reconfig_notifier_register(&prom_reconfig_nb); | |
1493 | } | |
1494 | __initcall(prom_reconfig_setup); | |
1495 | #endif | |
1496 | ||
9b6b563c PM |
1497 | /* |
1498 | * Add a property to a node | |
1499 | */ | |
183d0202 | 1500 | int prom_add_property(struct device_node* np, struct property* prop) |
9b6b563c | 1501 | { |
183d0202 | 1502 | struct property **next; |
f4ac7b5e | 1503 | unsigned long flags; |
9b6b563c PM |
1504 | |
1505 | prop->next = NULL; | |
f4ac7b5e | 1506 | write_lock_irqsave(&devtree_lock, flags); |
183d0202 BH |
1507 | next = &np->properties; |
1508 | while (*next) { | |
1509 | if (strcmp(prop->name, (*next)->name) == 0) { | |
1510 | /* duplicate ! don't insert it */ | |
f4ac7b5e | 1511 | write_unlock_irqrestore(&devtree_lock, flags); |
183d0202 BH |
1512 | return -1; |
1513 | } | |
9b6b563c | 1514 | next = &(*next)->next; |
183d0202 | 1515 | } |
9b6b563c | 1516 | *next = prop; |
f4ac7b5e | 1517 | write_unlock_irqrestore(&devtree_lock, flags); |
183d0202 | 1518 | |
799d6046 | 1519 | #ifdef CONFIG_PROC_DEVICETREE |
183d0202 BH |
1520 | /* try to add to proc as well if it was initialized */ |
1521 | if (np->pde) | |
1522 | proc_device_tree_add_prop(np->pde, prop); | |
799d6046 | 1523 | #endif /* CONFIG_PROC_DEVICETREE */ |
183d0202 BH |
1524 | |
1525 | return 0; | |
9b6b563c PM |
1526 | } |
1527 | ||
088186de DB |
1528 | /* |
1529 | * Remove a property from a node. Note that we don't actually | |
1530 | * remove it, since we have given out who-knows-how-many pointers | |
1531 | * to the data using get-property. Instead we just move the property | |
1532 | * to the "dead properties" list, so it won't be found any more. | |
1533 | */ | |
1534 | int prom_remove_property(struct device_node *np, struct property *prop) | |
1535 | { | |
1536 | struct property **next; | |
f4ac7b5e | 1537 | unsigned long flags; |
088186de DB |
1538 | int found = 0; |
1539 | ||
f4ac7b5e | 1540 | write_lock_irqsave(&devtree_lock, flags); |
088186de DB |
1541 | next = &np->properties; |
1542 | while (*next) { | |
1543 | if (*next == prop) { | |
1544 | /* found the node */ | |
1545 | *next = prop->next; | |
1546 | prop->next = np->deadprops; | |
1547 | np->deadprops = prop; | |
1548 | found = 1; | |
1549 | break; | |
1550 | } | |
1551 | next = &(*next)->next; | |
1552 | } | |
f4ac7b5e | 1553 | write_unlock_irqrestore(&devtree_lock, flags); |
088186de DB |
1554 | |
1555 | if (!found) | |
1556 | return -ENODEV; | |
1557 | ||
1558 | #ifdef CONFIG_PROC_DEVICETREE | |
1559 | /* try to remove the proc node as well */ | |
1560 | if (np->pde) | |
1561 | proc_device_tree_remove_prop(np->pde, prop); | |
1562 | #endif /* CONFIG_PROC_DEVICETREE */ | |
1563 | ||
1564 | return 0; | |
1565 | } | |
1566 | ||
1567 | /* | |
1568 | * Update a property in a node. Note that we don't actually | |
1569 | * remove it, since we have given out who-knows-how-many pointers | |
1570 | * to the data using get-property. Instead we just move the property | |
1571 | * to the "dead properties" list, and add the new property to the | |
1572 | * property list | |
1573 | */ | |
1574 | int prom_update_property(struct device_node *np, | |
1575 | struct property *newprop, | |
1576 | struct property *oldprop) | |
1577 | { | |
1578 | struct property **next; | |
f4ac7b5e | 1579 | unsigned long flags; |
088186de DB |
1580 | int found = 0; |
1581 | ||
f4ac7b5e | 1582 | write_lock_irqsave(&devtree_lock, flags); |
088186de DB |
1583 | next = &np->properties; |
1584 | while (*next) { | |
1585 | if (*next == oldprop) { | |
1586 | /* found the node */ | |
1587 | newprop->next = oldprop->next; | |
1588 | *next = newprop; | |
1589 | oldprop->next = np->deadprops; | |
1590 | np->deadprops = oldprop; | |
1591 | found = 1; | |
1592 | break; | |
1593 | } | |
1594 | next = &(*next)->next; | |
1595 | } | |
f4ac7b5e | 1596 | write_unlock_irqrestore(&devtree_lock, flags); |
088186de DB |
1597 | |
1598 | if (!found) | |
1599 | return -ENODEV; | |
9b6b563c | 1600 | |
088186de DB |
1601 | #ifdef CONFIG_PROC_DEVICETREE |
1602 | /* try to add to proc as well if it was initialized */ | |
1603 | if (np->pde) | |
1604 | proc_device_tree_update_prop(np->pde, newprop, oldprop); | |
1605 | #endif /* CONFIG_PROC_DEVICETREE */ | |
1606 | ||
1607 | return 0; | |
1608 | } | |
b68239ee | 1609 | |
acf7d768 BH |
1610 | |
1611 | /* Find the device node for a given logical cpu number, also returns the cpu | |
1612 | * local thread number (index in ibm,interrupt-server#s) if relevant and | |
1613 | * asked for (non NULL) | |
1614 | */ | |
1615 | struct device_node *of_get_cpu_node(int cpu, unsigned int *thread) | |
1616 | { | |
1617 | int hardid; | |
1618 | struct device_node *np; | |
1619 | ||
1620 | hardid = get_hard_smp_processor_id(cpu); | |
1621 | ||
1622 | for_each_node_by_type(np, "cpu") { | |
a7f67bdf | 1623 | const u32 *intserv; |
acf7d768 BH |
1624 | unsigned int plen, t; |
1625 | ||
1626 | /* Check for ibm,ppc-interrupt-server#s. If it doesn't exist | |
1627 | * fallback to "reg" property and assume no threads | |
1628 | */ | |
0e56efc7 | 1629 | intserv = of_get_property(np, "ibm,ppc-interrupt-server#s", |
a7f67bdf | 1630 | &plen); |
acf7d768 | 1631 | if (intserv == NULL) { |
0e56efc7 | 1632 | const u32 *reg = of_get_property(np, "reg", NULL); |
acf7d768 BH |
1633 | if (reg == NULL) |
1634 | continue; | |
1635 | if (*reg == hardid) { | |
1636 | if (thread) | |
1637 | *thread = 0; | |
1638 | return np; | |
1639 | } | |
1640 | } else { | |
1641 | plen /= sizeof(u32); | |
1642 | for (t = 0; t < plen; t++) { | |
1643 | if (hardid == intserv[t]) { | |
1644 | if (thread) | |
1645 | *thread = t; | |
1646 | return np; | |
1647 | } | |
1648 | } | |
1649 | } | |
1650 | } | |
1651 | return NULL; | |
1652 | } | |
36ca4ba4 | 1653 | EXPORT_SYMBOL(of_get_cpu_node); |
7a4571ae | 1654 | |
94a3807c | 1655 | #if defined(CONFIG_DEBUG_FS) && defined(DEBUG) |
7a4571ae ME |
1656 | static struct debugfs_blob_wrapper flat_dt_blob; |
1657 | ||
1658 | static int __init export_flat_device_tree(void) | |
1659 | { | |
1660 | struct dentry *d; | |
1661 | ||
7a4571ae ME |
1662 | flat_dt_blob.data = initial_boot_params; |
1663 | flat_dt_blob.size = initial_boot_params->totalsize; | |
1664 | ||
1665 | d = debugfs_create_blob("flat-device-tree", S_IFREG | S_IRUSR, | |
94a3807c | 1666 | powerpc_debugfs_root, &flat_dt_blob); |
7a4571ae ME |
1667 | if (!d) |
1668 | return 1; | |
1669 | ||
1670 | return 0; | |
1671 | } | |
1672 | __initcall(export_flat_device_tree); | |
1673 | #endif |