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 | #ifdef CONFIG_PPC64 |
28897731 | 65 | int __initdata iommu_is_off; |
9b6b563c | 66 | int __initdata iommu_force_on; |
cf00a8d1 | 67 | unsigned long tce_alloc_start, tce_alloc_end; |
9b6b563c PM |
68 | #endif |
69 | ||
70 | typedef u32 cell_t; | |
71 | ||
581b605a | 72 | extern rwlock_t devtree_lock; /* temporary while merging */ |
9b6b563c PM |
73 | |
74 | /* export that to outside world */ | |
75 | struct device_node *of_chosen; | |
76 | ||
2babf5c2 ME |
77 | static int __init early_parse_mem(char *p) |
78 | { | |
79 | if (!p) | |
80 | return 1; | |
81 | ||
82 | memory_limit = PAGE_ALIGN(memparse(p, &p)); | |
49a84965 | 83 | DBG("memory limit = 0x%llx\n", (unsigned long long)memory_limit); |
2babf5c2 ME |
84 | |
85 | return 0; | |
86 | } | |
87 | early_param("mem", early_parse_mem); | |
88 | ||
3c607ce2 LV |
89 | /** |
90 | * move_device_tree - move tree to an unused area, if needed. | |
91 | * | |
92 | * The device tree may be allocated beyond our memory limit, or inside the | |
93 | * crash kernel region for kdump. If so, move it out of the way. | |
2babf5c2 | 94 | */ |
18f032cb | 95 | static void __init move_device_tree(void) |
2babf5c2 ME |
96 | { |
97 | unsigned long start, size; | |
98 | void *p; | |
99 | ||
100 | DBG("-> move_device_tree\n"); | |
101 | ||
102 | start = __pa(initial_boot_params); | |
103 | size = initial_boot_params->totalsize; | |
104 | ||
105 | if ((memory_limit && (start + size) > memory_limit) || | |
106 | overlaps_crashkernel(start, size)) { | |
107 | p = __va(lmb_alloc_base(size, PAGE_SIZE, lmb.rmo_size)); | |
108 | memcpy(p, initial_boot_params, size); | |
109 | initial_boot_params = (struct boot_param_header *)p; | |
110 | DBG("Moved device tree to 0x%p\n", p); | |
111 | } | |
112 | ||
113 | DBG("<- move_device_tree\n"); | |
114 | } | |
9b6b563c | 115 | |
d205819e PM |
116 | /* |
117 | * ibm,pa-features is a per-cpu property that contains a string of | |
118 | * attribute descriptors, each of which has a 2 byte header plus up | |
119 | * to 254 bytes worth of processor attribute bits. First header | |
120 | * byte specifies the number of bytes following the header. | |
121 | * Second header byte is an "attribute-specifier" type, of which | |
122 | * zero is the only currently-defined value. | |
123 | * Implementation: Pass in the byte and bit offset for the feature | |
124 | * that we are interested in. The function will return -1 if the | |
125 | * pa-features property is missing, or a 1/0 to indicate if the feature | |
126 | * is supported/not supported. Note that the bit numbers are | |
127 | * big-endian to match the definition in PAPR. | |
128 | */ | |
129 | static struct ibm_pa_feature { | |
130 | unsigned long cpu_features; /* CPU_FTR_xxx bit */ | |
131 | unsigned int cpu_user_ftrs; /* PPC_FEATURE_xxx bit */ | |
132 | unsigned char pabyte; /* byte number in ibm,pa-features */ | |
133 | unsigned char pabit; /* bit number (big-endian) */ | |
134 | unsigned char invert; /* if 1, pa bit set => clear feature */ | |
135 | } ibm_pa_features[] __initdata = { | |
136 | {0, PPC_FEATURE_HAS_MMU, 0, 0, 0}, | |
137 | {0, PPC_FEATURE_HAS_FPU, 0, 1, 0}, | |
138 | {CPU_FTR_SLB, 0, 0, 2, 0}, | |
139 | {CPU_FTR_CTRL, 0, 0, 3, 0}, | |
140 | {CPU_FTR_NOEXECUTE, 0, 0, 6, 0}, | |
141 | {CPU_FTR_NODSISRALIGN, 0, 1, 1, 1}, | |
142 | {CPU_FTR_CI_LARGE_PAGE, 0, 1, 2, 0}, | |
339d76c5 | 143 | {CPU_FTR_REAL_LE, PPC_FEATURE_TRUE_LE, 5, 0, 0}, |
d205819e PM |
144 | }; |
145 | ||
974a76f5 PM |
146 | static void __init scan_features(unsigned long node, unsigned char *ftrs, |
147 | unsigned long tablelen, | |
148 | struct ibm_pa_feature *fp, | |
149 | unsigned long ft_size) | |
d205819e | 150 | { |
974a76f5 | 151 | unsigned long i, len, bit; |
d205819e PM |
152 | |
153 | /* find descriptor with type == 0 */ | |
154 | for (;;) { | |
155 | if (tablelen < 3) | |
156 | return; | |
974a76f5 | 157 | len = 2 + ftrs[0]; |
d205819e PM |
158 | if (tablelen < len) |
159 | return; /* descriptor 0 not found */ | |
974a76f5 | 160 | if (ftrs[1] == 0) |
d205819e PM |
161 | break; |
162 | tablelen -= len; | |
974a76f5 | 163 | ftrs += len; |
d205819e PM |
164 | } |
165 | ||
166 | /* loop over bits we know about */ | |
974a76f5 PM |
167 | for (i = 0; i < ft_size; ++i, ++fp) { |
168 | if (fp->pabyte >= ftrs[0]) | |
d205819e | 169 | continue; |
974a76f5 | 170 | bit = (ftrs[2 + fp->pabyte] >> (7 - fp->pabit)) & 1; |
d205819e PM |
171 | if (bit ^ fp->invert) { |
172 | cur_cpu_spec->cpu_features |= fp->cpu_features; | |
173 | cur_cpu_spec->cpu_user_features |= fp->cpu_user_ftrs; | |
174 | } else { | |
175 | cur_cpu_spec->cpu_features &= ~fp->cpu_features; | |
176 | cur_cpu_spec->cpu_user_features &= ~fp->cpu_user_ftrs; | |
177 | } | |
178 | } | |
179 | } | |
180 | ||
974a76f5 PM |
181 | static void __init check_cpu_pa_features(unsigned long node) |
182 | { | |
183 | unsigned char *pa_ftrs; | |
184 | unsigned long tablelen; | |
185 | ||
186 | pa_ftrs = of_get_flat_dt_prop(node, "ibm,pa-features", &tablelen); | |
187 | if (pa_ftrs == NULL) | |
188 | return; | |
189 | ||
190 | scan_features(node, pa_ftrs, tablelen, | |
191 | ibm_pa_features, ARRAY_SIZE(ibm_pa_features)); | |
192 | } | |
193 | ||
94491685 | 194 | #ifdef CONFIG_PPC_STD_MMU_64 |
584f8b71 MN |
195 | static void __init check_cpu_slb_size(unsigned long node) |
196 | { | |
197 | u32 *slb_size_ptr; | |
198 | ||
b60c31d8 MN |
199 | slb_size_ptr = of_get_flat_dt_prop(node, "slb-size", NULL); |
200 | if (slb_size_ptr != NULL) { | |
201 | mmu_slb_size = *slb_size_ptr; | |
202 | return; | |
203 | } | |
584f8b71 MN |
204 | slb_size_ptr = of_get_flat_dt_prop(node, "ibm,slb-size", NULL); |
205 | if (slb_size_ptr != NULL) { | |
206 | mmu_slb_size = *slb_size_ptr; | |
207 | } | |
208 | } | |
209 | #else | |
210 | #define check_cpu_slb_size(node) do { } while(0) | |
211 | #endif | |
212 | ||
974a76f5 PM |
213 | static struct feature_property { |
214 | const char *name; | |
215 | u32 min_value; | |
216 | unsigned long cpu_feature; | |
217 | unsigned long cpu_user_ftr; | |
218 | } feature_properties[] __initdata = { | |
219 | #ifdef CONFIG_ALTIVEC | |
220 | {"altivec", 0, CPU_FTR_ALTIVEC, PPC_FEATURE_HAS_ALTIVEC}, | |
221 | {"ibm,vmx", 1, CPU_FTR_ALTIVEC, PPC_FEATURE_HAS_ALTIVEC}, | |
222 | #endif /* CONFIG_ALTIVEC */ | |
b962ce9d MN |
223 | #ifdef CONFIG_VSX |
224 | /* Yes, this _really_ is ibm,vmx == 2 to enable VSX */ | |
225 | {"ibm,vmx", 2, CPU_FTR_VSX, PPC_FEATURE_HAS_VSX}, | |
226 | #endif /* CONFIG_VSX */ | |
974a76f5 PM |
227 | #ifdef CONFIG_PPC64 |
228 | {"ibm,dfp", 1, 0, PPC_FEATURE_HAS_DFP}, | |
229 | {"ibm,purr", 1, CPU_FTR_PURR, 0}, | |
230 | {"ibm,spurr", 1, CPU_FTR_SPURR, 0}, | |
231 | #endif /* CONFIG_PPC64 */ | |
232 | }; | |
233 | ||
14b3d926 VB |
234 | #if defined(CONFIG_44x) && defined(CONFIG_PPC_FPU) |
235 | static inline void identical_pvr_fixup(unsigned long node) | |
236 | { | |
237 | unsigned int pvr; | |
238 | char *model = of_get_flat_dt_prop(node, "model", NULL); | |
239 | ||
240 | /* | |
241 | * Since 440GR(x)/440EP(x) processors have the same pvr, | |
242 | * we check the node path and set bit 28 in the cur_cpu_spec | |
243 | * pvr for EP(x) processor version. This bit is always 0 in | |
244 | * the "real" pvr. Then we call identify_cpu again with | |
245 | * the new logical pvr to enable FPU support. | |
246 | */ | |
247 | if (model && strstr(model, "440EP")) { | |
248 | pvr = cur_cpu_spec->pvr_value | 0x8; | |
249 | identify_cpu(0, pvr); | |
250 | DBG("Using logical pvr %x for %s\n", pvr, model); | |
251 | } | |
252 | } | |
253 | #else | |
254 | #define identical_pvr_fixup(node) do { } while(0) | |
255 | #endif | |
256 | ||
974a76f5 PM |
257 | static void __init check_cpu_feature_properties(unsigned long node) |
258 | { | |
259 | unsigned long i; | |
260 | struct feature_property *fp = feature_properties; | |
261 | const u32 *prop; | |
262 | ||
263 | for (i = 0; i < ARRAY_SIZE(feature_properties); ++i, ++fp) { | |
264 | prop = of_get_flat_dt_prop(node, fp->name, NULL); | |
265 | if (prop && *prop >= fp->min_value) { | |
266 | cur_cpu_spec->cpu_features |= fp->cpu_feature; | |
267 | cur_cpu_spec->cpu_user_features |= fp->cpu_user_ftr; | |
268 | } | |
269 | } | |
270 | } | |
271 | ||
9b6b563c | 272 | static int __init early_init_dt_scan_cpus(unsigned long node, |
4df20460 AB |
273 | const char *uname, int depth, |
274 | void *data) | |
9b6b563c | 275 | { |
4df20460 AB |
276 | static int logical_cpuid = 0; |
277 | char *type = of_get_flat_dt_prop(node, "device_type", NULL); | |
974a76f5 PM |
278 | const u32 *prop; |
279 | const u32 *intserv; | |
4df20460 AB |
280 | int i, nthreads; |
281 | unsigned long len; | |
282 | int found = 0; | |
9b6b563c PM |
283 | |
284 | /* We are scanning "cpu" nodes only */ | |
285 | if (type == NULL || strcmp(type, "cpu") != 0) | |
286 | return 0; | |
287 | ||
4df20460 AB |
288 | /* Get physical cpuid */ |
289 | intserv = of_get_flat_dt_prop(node, "ibm,ppc-interrupt-server#s", &len); | |
290 | if (intserv) { | |
291 | nthreads = len / sizeof(int); | |
9b6b563c | 292 | } else { |
4df20460 AB |
293 | intserv = of_get_flat_dt_prop(node, "reg", NULL); |
294 | nthreads = 1; | |
295 | } | |
296 | ||
297 | /* | |
298 | * Now see if any of these threads match our boot cpu. | |
299 | * NOTE: This must match the parsing done in smp_setup_cpu_maps. | |
300 | */ | |
301 | for (i = 0; i < nthreads; i++) { | |
302 | /* | |
303 | * version 2 of the kexec param format adds the phys cpuid of | |
304 | * booted proc. | |
305 | */ | |
306 | if (initial_boot_params && initial_boot_params->version >= 2) { | |
307 | if (intserv[i] == | |
308 | initial_boot_params->boot_cpuid_phys) { | |
309 | found = 1; | |
310 | break; | |
311 | } | |
312 | } else { | |
313 | /* | |
314 | * Check if it's the boot-cpu, set it's hw index now, | |
315 | * unfortunately this format did not support booting | |
316 | * off secondary threads. | |
317 | */ | |
318 | if (of_get_flat_dt_prop(node, | |
3c726f8d | 319 | "linux,boot-cpu", NULL) != NULL) { |
4df20460 AB |
320 | found = 1; |
321 | break; | |
322 | } | |
9b6b563c | 323 | } |
4df20460 AB |
324 | |
325 | #ifdef CONFIG_SMP | |
326 | /* logical cpu id is always 0 on UP kernels */ | |
327 | logical_cpuid++; | |
328 | #endif | |
329 | } | |
330 | ||
331 | if (found) { | |
332 | DBG("boot cpu: logical %d physical %d\n", logical_cpuid, | |
333 | intserv[i]); | |
334 | boot_cpuid = logical_cpuid; | |
335 | set_hard_smp_processor_id(boot_cpuid, intserv[i]); | |
9b6b563c | 336 | |
974a76f5 PM |
337 | /* |
338 | * PAPR defines "logical" PVR values for cpus that | |
339 | * meet various levels of the architecture: | |
340 | * 0x0f000001 Architecture version 2.04 | |
341 | * 0x0f000002 Architecture version 2.05 | |
342 | * If the cpu-version property in the cpu node contains | |
343 | * such a value, we call identify_cpu again with the | |
344 | * logical PVR value in order to use the cpu feature | |
345 | * bits appropriate for the architecture level. | |
346 | * | |
347 | * A POWER6 partition in "POWER6 architected" mode | |
348 | * uses the 0x0f000002 PVR value; in POWER5+ mode | |
349 | * it uses 0x0f000001. | |
350 | */ | |
351 | prop = of_get_flat_dt_prop(node, "cpu-version", NULL); | |
352 | if (prop && (*prop & 0xff000000) == 0x0f000000) | |
353 | identify_cpu(0, *prop); | |
14b3d926 VB |
354 | |
355 | identical_pvr_fixup(node); | |
9b6b563c | 356 | } |
9b6b563c | 357 | |
974a76f5 | 358 | check_cpu_feature_properties(node); |
d205819e | 359 | check_cpu_pa_features(node); |
584f8b71 | 360 | check_cpu_slb_size(node); |
d205819e | 361 | |
9b6b563c | 362 | #ifdef CONFIG_PPC_PSERIES |
4df20460 | 363 | if (nthreads > 1) |
9b6b563c | 364 | cur_cpu_spec->cpu_features |= CPU_FTR_SMT; |
4df20460 AB |
365 | else |
366 | cur_cpu_spec->cpu_features &= ~CPU_FTR_SMT; | |
9b6b563c PM |
367 | #endif |
368 | ||
369 | return 0; | |
370 | } | |
371 | ||
372 | static int __init early_init_dt_scan_chosen(unsigned long node, | |
373 | const char *uname, int depth, void *data) | |
374 | { | |
9b6b563c | 375 | unsigned long *lprop; |
329dda08 KG |
376 | unsigned long l; |
377 | char *p; | |
9b6b563c PM |
378 | |
379 | DBG("search \"chosen\", depth: %d, uname: %s\n", depth, uname); | |
380 | ||
a575b807 PM |
381 | if (depth != 1 || |
382 | (strcmp(uname, "chosen") != 0 && strcmp(uname, "chosen@0") != 0)) | |
9b6b563c PM |
383 | return 0; |
384 | ||
9b6b563c PM |
385 | #ifdef CONFIG_PPC64 |
386 | /* check if iommu is forced on or off */ | |
3c726f8d | 387 | if (of_get_flat_dt_prop(node, "linux,iommu-off", NULL) != NULL) |
9b6b563c | 388 | iommu_is_off = 1; |
3c726f8d | 389 | if (of_get_flat_dt_prop(node, "linux,iommu-force-on", NULL) != NULL) |
9b6b563c PM |
390 | iommu_force_on = 1; |
391 | #endif | |
392 | ||
2babf5c2 | 393 | /* mem=x on the command line is the preferred mechanism */ |
3c726f8d | 394 | lprop = of_get_flat_dt_prop(node, "linux,memory-limit", NULL); |
9b6b563c PM |
395 | if (lprop) |
396 | memory_limit = *lprop; | |
397 | ||
398 | #ifdef CONFIG_PPC64 | |
3c726f8d | 399 | lprop = of_get_flat_dt_prop(node, "linux,tce-alloc-start", NULL); |
9b6b563c PM |
400 | if (lprop) |
401 | tce_alloc_start = *lprop; | |
3c726f8d | 402 | lprop = of_get_flat_dt_prop(node, "linux,tce-alloc-end", NULL); |
9b6b563c PM |
403 | if (lprop) |
404 | tce_alloc_end = *lprop; | |
405 | #endif | |
406 | ||
dcee3036 | 407 | #ifdef CONFIG_KEXEC |
63277161 | 408 | lprop = of_get_flat_dt_prop(node, "linux,crashkernel-base", NULL); |
70c6cc37 LV |
409 | if (lprop) |
410 | crashk_res.start = *lprop; | |
dcee3036 | 411 | |
63277161 | 412 | lprop = of_get_flat_dt_prop(node, "linux,crashkernel-size", NULL); |
70c6cc37 LV |
413 | if (lprop) |
414 | crashk_res.end = crashk_res.start + *lprop - 1; | |
dcee3036 ME |
415 | #endif |
416 | ||
40472a55 | 417 | early_init_dt_check_for_initrd(node); |
30437b3e | 418 | |
329dda08 KG |
419 | /* Retreive command line */ |
420 | p = of_get_flat_dt_prop(node, "bootargs", &l); | |
421 | if (p != NULL && l > 0) | |
422 | strlcpy(cmd_line, p, min((int)l, COMMAND_LINE_SIZE)); | |
423 | ||
424 | #ifdef CONFIG_CMDLINE | |
c1ce464d | 425 | if (p == NULL || l == 0 || (l == 1 && (*p) == 0)) |
329dda08 KG |
426 | strlcpy(cmd_line, CONFIG_CMDLINE, COMMAND_LINE_SIZE); |
427 | #endif /* CONFIG_CMDLINE */ | |
428 | ||
429 | DBG("Command line is: %s\n", cmd_line); | |
430 | ||
9b6b563c PM |
431 | /* break now */ |
432 | return 1; | |
433 | } | |
434 | ||
abe76885 | 435 | static u64 __init dt_mem_next_cell(int s, cell_t **cellp) |
9b6b563c PM |
436 | { |
437 | cell_t *p = *cellp; | |
9b6b563c | 438 | |
a4dc7ff0 | 439 | *cellp = p + s; |
abe76885 | 440 | return of_read_number(p, s); |
9b6b563c PM |
441 | } |
442 | ||
0204568a PM |
443 | #ifdef CONFIG_PPC_PSERIES |
444 | /* | |
445 | * Interpret the ibm,dynamic-memory property in the | |
446 | * /ibm,dynamic-reconfiguration-memory node. | |
447 | * This contains a list of memory blocks along with NUMA affinity | |
448 | * information. | |
449 | */ | |
450 | static int __init early_init_dt_scan_drconf_memory(unsigned long node) | |
451 | { | |
cf00085d | 452 | cell_t *dm, *ls, *usm; |
abe76885 BB |
453 | unsigned long l, n, flags; |
454 | u64 base, size, lmb_size; | |
cf00085d | 455 | unsigned int is_kexec_kdump = 0, rngs; |
0204568a | 456 | |
63277161 | 457 | ls = of_get_flat_dt_prop(node, "ibm,lmb-size", &l); |
0204568a PM |
458 | if (ls == NULL || l < dt_root_size_cells * sizeof(cell_t)) |
459 | return 0; | |
460 | lmb_size = dt_mem_next_cell(dt_root_size_cells, &ls); | |
461 | ||
63277161 | 462 | dm = of_get_flat_dt_prop(node, "ibm,dynamic-memory", &l); |
0204568a PM |
463 | if (dm == NULL || l < sizeof(cell_t)) |
464 | return 0; | |
465 | ||
466 | n = *dm++; /* number of entries */ | |
467 | if (l < (n * (dt_root_addr_cells + 4) + 1) * sizeof(cell_t)) | |
468 | return 0; | |
469 | ||
cf00085d | 470 | /* check if this is a kexec/kdump kernel. */ |
63277161 | 471 | usm = of_get_flat_dt_prop(node, "linux,drconf-usable-memory", |
cf00085d C |
472 | &l); |
473 | if (usm != NULL) | |
474 | is_kexec_kdump = 1; | |
475 | ||
0204568a PM |
476 | for (; n != 0; --n) { |
477 | base = dt_mem_next_cell(dt_root_addr_cells, &dm); | |
478 | flags = dm[3]; | |
479 | /* skip DRC index, pad, assoc. list index, flags */ | |
480 | dm += 4; | |
481 | /* skip this block if the reserved bit is set in flags (0x80) | |
482 | or if the block is not assigned to this partition (0x8) */ | |
483 | if ((flags & 0x80) || !(flags & 0x8)) | |
484 | continue; | |
485 | size = lmb_size; | |
cf00085d C |
486 | rngs = 1; |
487 | if (is_kexec_kdump) { | |
488 | /* | |
489 | * For each lmb in ibm,dynamic-memory, a corresponding | |
490 | * entry in linux,drconf-usable-memory property contains | |
491 | * a counter 'p' followed by 'p' (base, size) duple. | |
492 | * Now read the counter from | |
493 | * linux,drconf-usable-memory property | |
494 | */ | |
495 | rngs = dt_mem_next_cell(dt_root_size_cells, &usm); | |
496 | if (!rngs) /* there are no (base, size) duple */ | |
0204568a | 497 | continue; |
0204568a | 498 | } |
cf00085d C |
499 | do { |
500 | if (is_kexec_kdump) { | |
501 | base = dt_mem_next_cell(dt_root_addr_cells, | |
502 | &usm); | |
503 | size = dt_mem_next_cell(dt_root_size_cells, | |
504 | &usm); | |
505 | } | |
506 | if (iommu_is_off) { | |
507 | if (base >= 0x80000000ul) | |
508 | continue; | |
509 | if ((base + size) > 0x80000000ul) | |
510 | size = 0x80000000ul - base; | |
511 | } | |
512 | lmb_add(base, size); | |
513 | } while (--rngs); | |
0204568a PM |
514 | } |
515 | lmb_dump_all(); | |
516 | return 0; | |
517 | } | |
518 | #else | |
519 | #define early_init_dt_scan_drconf_memory(node) 0 | |
520 | #endif /* CONFIG_PPC_PSERIES */ | |
9b6b563c PM |
521 | |
522 | static int __init early_init_dt_scan_memory(unsigned long node, | |
523 | const char *uname, int depth, void *data) | |
524 | { | |
3c726f8d | 525 | char *type = of_get_flat_dt_prop(node, "device_type", NULL); |
9b6b563c PM |
526 | cell_t *reg, *endp; |
527 | unsigned long l; | |
528 | ||
0204568a PM |
529 | /* Look for the ibm,dynamic-reconfiguration-memory node */ |
530 | if (depth == 1 && | |
531 | strcmp(uname, "ibm,dynamic-reconfiguration-memory") == 0) | |
532 | return early_init_dt_scan_drconf_memory(node); | |
533 | ||
9b6b563c | 534 | /* We are scanning "memory" nodes only */ |
a23414be PM |
535 | if (type == NULL) { |
536 | /* | |
537 | * The longtrail doesn't have a device_type on the | |
538 | * /memory node, so look for the node called /memory@0. | |
539 | */ | |
540 | if (depth != 1 || strcmp(uname, "memory@0") != 0) | |
541 | return 0; | |
542 | } else if (strcmp(type, "memory") != 0) | |
9b6b563c PM |
543 | return 0; |
544 | ||
63277161 | 545 | reg = of_get_flat_dt_prop(node, "linux,usable-memory", &l); |
ba759485 | 546 | if (reg == NULL) |
63277161 | 547 | reg = of_get_flat_dt_prop(node, "reg", &l); |
9b6b563c PM |
548 | if (reg == NULL) |
549 | return 0; | |
550 | ||
551 | endp = reg + (l / sizeof(cell_t)); | |
552 | ||
358c86fd | 553 | DBG("memory scan node %s, reg size %ld, data: %x %x %x %x,\n", |
9b6b563c PM |
554 | uname, l, reg[0], reg[1], reg[2], reg[3]); |
555 | ||
556 | while ((endp - reg) >= (dt_root_addr_cells + dt_root_size_cells)) { | |
abe76885 | 557 | u64 base, size; |
9b6b563c PM |
558 | |
559 | base = dt_mem_next_cell(dt_root_addr_cells, ®); | |
560 | size = dt_mem_next_cell(dt_root_size_cells, ®); | |
561 | ||
562 | if (size == 0) | |
563 | continue; | |
abe76885 BB |
564 | DBG(" - %llx , %llx\n", (unsigned long long)base, |
565 | (unsigned long long)size); | |
9b6b563c PM |
566 | #ifdef CONFIG_PPC64 |
567 | if (iommu_is_off) { | |
568 | if (base >= 0x80000000ul) | |
569 | continue; | |
570 | if ((base + size) > 0x80000000ul) | |
571 | size = 0x80000000ul - base; | |
572 | } | |
573 | #endif | |
574 | lmb_add(base, size); | |
37dd2bad KG |
575 | |
576 | memstart_addr = min((u64)memstart_addr, base); | |
9b6b563c | 577 | } |
37dd2bad | 578 | |
9b6b563c PM |
579 | return 0; |
580 | } | |
581 | ||
582 | static void __init early_reserve_mem(void) | |
583 | { | |
cbbcf340 KG |
584 | u64 base, size; |
585 | u64 *reserve_map; | |
8a300887 JL |
586 | unsigned long self_base; |
587 | unsigned long self_size; | |
9b6b563c | 588 | |
cbbcf340 | 589 | reserve_map = (u64 *)(((unsigned long)initial_boot_params) + |
9b6b563c | 590 | initial_boot_params->off_mem_rsvmap); |
4d1f3f25 JX |
591 | |
592 | /* before we do anything, lets reserve the dt blob */ | |
8a300887 JL |
593 | self_base = __pa((unsigned long)initial_boot_params); |
594 | self_size = initial_boot_params->totalsize; | |
595 | lmb_reserve(self_base, self_size); | |
4d1f3f25 | 596 | |
30437b3e DG |
597 | #ifdef CONFIG_BLK_DEV_INITRD |
598 | /* then reserve the initrd, if any */ | |
599 | if (initrd_start && (initrd_end > initrd_start)) | |
600 | lmb_reserve(__pa(initrd_start), initrd_end - initrd_start); | |
601 | #endif /* CONFIG_BLK_DEV_INITRD */ | |
602 | ||
cbbcf340 KG |
603 | #ifdef CONFIG_PPC32 |
604 | /* | |
605 | * Handle the case where we might be booting from an old kexec | |
606 | * image that setup the mem_rsvmap as pairs of 32-bit values | |
607 | */ | |
608 | if (*reserve_map > 0xffffffffull) { | |
609 | u32 base_32, size_32; | |
610 | u32 *reserve_map_32 = (u32 *)reserve_map; | |
611 | ||
612 | while (1) { | |
613 | base_32 = *(reserve_map_32++); | |
614 | size_32 = *(reserve_map_32++); | |
615 | if (size_32 == 0) | |
616 | break; | |
8a300887 JL |
617 | /* skip if the reservation is for the blob */ |
618 | if (base_32 == self_base && size_32 == self_size) | |
619 | continue; | |
329dda08 | 620 | DBG("reserving: %x -> %x\n", base_32, size_32); |
cbbcf340 KG |
621 | lmb_reserve(base_32, size_32); |
622 | } | |
623 | return; | |
624 | } | |
625 | #endif | |
9b6b563c PM |
626 | while (1) { |
627 | base = *(reserve_map++); | |
628 | size = *(reserve_map++); | |
629 | if (size == 0) | |
630 | break; | |
cbbcf340 | 631 | DBG("reserving: %llx -> %llx\n", base, size); |
9b6b563c PM |
632 | lmb_reserve(base, size); |
633 | } | |
9b6b563c PM |
634 | } |
635 | ||
6ac26c8a | 636 | #ifdef CONFIG_PHYP_DUMP |
37ddd5d0 MA |
637 | /** |
638 | * phyp_dump_calculate_reserve_size() - reserve variable boot area 5% or arg | |
639 | * | |
640 | * Function to find the largest size we need to reserve | |
641 | * during early boot process. | |
642 | * | |
643 | * It either looks for boot param and returns that OR | |
644 | * returns larger of 256 or 5% rounded down to multiples of 256MB. | |
645 | * | |
646 | */ | |
647 | static inline unsigned long phyp_dump_calculate_reserve_size(void) | |
648 | { | |
649 | unsigned long tmp; | |
650 | ||
651 | if (phyp_dump_info->reserve_bootvar) | |
652 | return phyp_dump_info->reserve_bootvar; | |
653 | ||
654 | /* divide by 20 to get 5% of value */ | |
655 | tmp = lmb_end_of_DRAM(); | |
656 | do_div(tmp, 20); | |
657 | ||
658 | /* round it down in multiples of 256 */ | |
659 | tmp = tmp & ~0x0FFFFFFFUL; | |
660 | ||
661 | return (tmp > PHYP_DUMP_RMR_END ? tmp : PHYP_DUMP_RMR_END); | |
662 | } | |
663 | ||
6ac26c8a MA |
664 | /** |
665 | * phyp_dump_reserve_mem() - reserve all not-yet-dumped mmemory | |
666 | * | |
667 | * This routine may reserve memory regions in the kernel only | |
668 | * if the system is supported and a dump was taken in last | |
669 | * boot instance or if the hardware is supported and the | |
670 | * scratch area needs to be setup. In other instances it returns | |
671 | * without reserving anything. The memory in case of dump being | |
672 | * active is freed when the dump is collected (by userland tools). | |
673 | */ | |
674 | static void __init phyp_dump_reserve_mem(void) | |
675 | { | |
676 | unsigned long base, size; | |
37ddd5d0 MA |
677 | unsigned long variable_reserve_size; |
678 | ||
6ac26c8a MA |
679 | if (!phyp_dump_info->phyp_dump_configured) { |
680 | printk(KERN_ERR "Phyp-dump not supported on this hardware\n"); | |
681 | return; | |
682 | } | |
683 | ||
654f596d MA |
684 | if (!phyp_dump_info->phyp_dump_at_boot) { |
685 | printk(KERN_INFO "Phyp-dump disabled at boot time\n"); | |
686 | return; | |
687 | } | |
688 | ||
37ddd5d0 MA |
689 | variable_reserve_size = phyp_dump_calculate_reserve_size(); |
690 | ||
6ac26c8a MA |
691 | if (phyp_dump_info->phyp_dump_is_active) { |
692 | /* Reserve *everything* above RMR.Area freed by userland tools*/ | |
37ddd5d0 | 693 | base = variable_reserve_size; |
6ac26c8a MA |
694 | size = lmb_end_of_DRAM() - base; |
695 | ||
696 | /* XXX crashed_ram_end is wrong, since it may be beyond | |
697 | * the memory_limit, it will need to be adjusted. */ | |
698 | lmb_reserve(base, size); | |
699 | ||
700 | phyp_dump_info->init_reserve_start = base; | |
701 | phyp_dump_info->init_reserve_size = size; | |
702 | } else { | |
703 | size = phyp_dump_info->cpu_state_size + | |
704 | phyp_dump_info->hpte_region_size + | |
37ddd5d0 | 705 | variable_reserve_size; |
6ac26c8a MA |
706 | base = lmb_end_of_DRAM() - size; |
707 | lmb_reserve(base, size); | |
708 | phyp_dump_info->init_reserve_start = base; | |
709 | phyp_dump_info->init_reserve_size = size; | |
710 | } | |
711 | } | |
712 | #else | |
713 | static inline void __init phyp_dump_reserve_mem(void) {} | |
714 | #endif /* CONFIG_PHYP_DUMP && CONFIG_PPC_RTAS */ | |
715 | ||
716 | ||
9b6b563c PM |
717 | void __init early_init_devtree(void *params) |
718 | { | |
49a84965 | 719 | phys_addr_t limit; |
6ca4f749 | 720 | |
44348105 | 721 | DBG(" -> early_init_devtree(%p)\n", params); |
9b6b563c PM |
722 | |
723 | /* Setup flat device-tree pointer */ | |
724 | initial_boot_params = params; | |
725 | ||
458148c0 ME |
726 | #ifdef CONFIG_PPC_RTAS |
727 | /* Some machines might need RTAS info for debugging, grab it now. */ | |
728 | of_scan_flat_dt(early_init_dt_scan_rtas, NULL); | |
729 | #endif | |
730 | ||
6ac26c8a MA |
731 | #ifdef CONFIG_PHYP_DUMP |
732 | /* scan tree to see if dump occured during last boot */ | |
733 | of_scan_flat_dt(early_init_dt_scan_phyp_dump, NULL); | |
734 | #endif | |
735 | ||
9b6b563c PM |
736 | /* Retrieve various informations from the /chosen node of the |
737 | * device-tree, including the platform type, initrd location and | |
738 | * size, TCE reserve, and more ... | |
739 | */ | |
3c726f8d | 740 | of_scan_flat_dt(early_init_dt_scan_chosen, NULL); |
9b6b563c PM |
741 | |
742 | /* Scan memory nodes and rebuild LMBs */ | |
743 | lmb_init(); | |
3c726f8d BH |
744 | of_scan_flat_dt(early_init_dt_scan_root, NULL); |
745 | of_scan_flat_dt(early_init_dt_scan_memory, NULL); | |
846f77b0 ME |
746 | |
747 | /* Save command line for /proc/cmdline and then parse parameters */ | |
b8757b21 | 748 | strlcpy(boot_command_line, cmd_line, COMMAND_LINE_SIZE); |
846f77b0 ME |
749 | parse_early_param(); |
750 | ||
9b6b563c | 751 | /* Reserve LMB regions used by kernel, initrd, dt, etc... */ |
0cc4746c | 752 | lmb_reserve(PHYSICAL_START, __pa(klimit) - PHYSICAL_START); |
549e8152 PM |
753 | /* If relocatable, reserve first 32k for interrupt vectors etc. */ |
754 | if (PHYSICAL_START > MEMORY_START) | |
755 | lmb_reserve(MEMORY_START, 0x8000); | |
47310413 | 756 | reserve_kdump_trampoline(); |
35dd5432 | 757 | reserve_crashkernel(); |
9b6b563c | 758 | early_reserve_mem(); |
6ac26c8a | 759 | phyp_dump_reserve_mem(); |
9b6b563c | 760 | |
6ca4f749 HB |
761 | limit = memory_limit; |
762 | if (! limit) { | |
49a84965 | 763 | phys_addr_t memsize; |
6ca4f749 HB |
764 | |
765 | /* Ensure that total memory size is page-aligned, because | |
766 | * otherwise mark_bootmem() gets upset. */ | |
767 | lmb_analyze(); | |
768 | memsize = lmb_phys_mem_size(); | |
769 | if ((memsize & PAGE_MASK) != memsize) | |
770 | limit = memsize & PAGE_MASK; | |
771 | } | |
772 | lmb_enforce_memory_limit(limit); | |
773 | ||
2babf5c2 | 774 | lmb_analyze(); |
059f134f | 775 | lmb_dump_all(); |
2babf5c2 | 776 | |
49a84965 | 777 | DBG("Phys. mem: %llx\n", lmb_phys_mem_size()); |
2babf5c2 ME |
778 | |
779 | /* We may need to relocate the flat tree, do it now. | |
780 | * FIXME .. and the initrd too? */ | |
781 | move_device_tree(); | |
782 | ||
9b6b563c PM |
783 | DBG("Scanning CPUs ...\n"); |
784 | ||
3c726f8d BH |
785 | /* Retreive CPU related informations from the flat tree |
786 | * (altivec support, boot CPU ID, ...) | |
9b6b563c | 787 | */ |
3c726f8d | 788 | of_scan_flat_dt(early_init_dt_scan_cpus, NULL); |
9b6b563c | 789 | |
9b6b563c PM |
790 | DBG(" <- early_init_devtree()\n"); |
791 | } | |
792 | ||
9b6b563c | 793 | |
9b6b563c PM |
794 | /** |
795 | * Indicates whether the root node has a given value in its | |
796 | * compatible property. | |
797 | */ | |
798 | int machine_is_compatible(const char *compat) | |
799 | { | |
800 | struct device_node *root; | |
801 | int rc = 0; | |
802 | ||
803 | root = of_find_node_by_path("/"); | |
804 | if (root) { | |
7a92f74f | 805 | rc = of_device_is_compatible(root, compat); |
9b6b563c PM |
806 | of_node_put(root); |
807 | } | |
808 | return rc; | |
809 | } | |
810 | EXPORT_SYMBOL(machine_is_compatible); | |
811 | ||
9b6b563c PM |
812 | /******* |
813 | * | |
814 | * New implementation of the OF "find" APIs, return a refcounted | |
815 | * object, call of_node_put() when done. The device tree and list | |
816 | * are protected by a rw_lock. | |
817 | * | |
818 | * Note that property management will need some locking as well, | |
819 | * this isn't dealt with yet. | |
820 | * | |
821 | *******/ | |
822 | ||
9b6b563c PM |
823 | /** |
824 | * of_find_node_by_phandle - Find a node given a phandle | |
825 | * @handle: phandle of the node to find | |
826 | * | |
827 | * Returns a node pointer with refcount incremented, use | |
828 | * of_node_put() on it when done. | |
829 | */ | |
830 | struct device_node *of_find_node_by_phandle(phandle handle) | |
831 | { | |
832 | struct device_node *np; | |
833 | ||
834 | read_lock(&devtree_lock); | |
835 | for (np = allnodes; np != 0; np = np->allnext) | |
836 | if (np->linux_phandle == handle) | |
837 | break; | |
b1374051 | 838 | of_node_get(np); |
9b6b563c PM |
839 | read_unlock(&devtree_lock); |
840 | return np; | |
841 | } | |
842 | EXPORT_SYMBOL(of_find_node_by_phandle); | |
843 | ||
e523f723 NL |
844 | /** |
845 | * of_find_next_cache_node - Find a node's subsidiary cache | |
846 | * @np: node of type "cpu" or "cache" | |
847 | * | |
848 | * Returns a node pointer with refcount incremented, use | |
849 | * of_node_put() on it when done. Caller should hold a reference | |
850 | * to np. | |
851 | */ | |
852 | struct device_node *of_find_next_cache_node(struct device_node *np) | |
853 | { | |
854 | struct device_node *child; | |
855 | const phandle *handle; | |
856 | ||
857 | handle = of_get_property(np, "l2-cache", NULL); | |
858 | if (!handle) | |
859 | handle = of_get_property(np, "next-level-cache", NULL); | |
860 | ||
861 | if (handle) | |
862 | return of_find_node_by_phandle(*handle); | |
863 | ||
864 | /* OF on pmac has nodes instead of properties named "l2-cache" | |
865 | * beneath CPU nodes. | |
866 | */ | |
867 | if (!strcmp(np->type, "cpu")) | |
868 | for_each_child_of_node(np, child) | |
869 | if (!strcmp(child->type, "cache")) | |
870 | return child; | |
871 | ||
872 | return NULL; | |
873 | } | |
874 | ||
9b6b563c PM |
875 | /** |
876 | * of_node_get - Increment refcount of a node | |
877 | * @node: Node to inc refcount, NULL is supported to | |
878 | * simplify writing of callers | |
879 | * | |
880 | * Returns node. | |
881 | */ | |
882 | struct device_node *of_node_get(struct device_node *node) | |
883 | { | |
884 | if (node) | |
885 | kref_get(&node->kref); | |
886 | return node; | |
887 | } | |
888 | EXPORT_SYMBOL(of_node_get); | |
889 | ||
890 | static inline struct device_node * kref_to_device_node(struct kref *kref) | |
891 | { | |
892 | return container_of(kref, struct device_node, kref); | |
893 | } | |
894 | ||
895 | /** | |
896 | * of_node_release - release a dynamically allocated node | |
897 | * @kref: kref element of the node to be released | |
898 | * | |
899 | * In of_node_put() this function is passed to kref_put() | |
900 | * as the destructor. | |
901 | */ | |
902 | static void of_node_release(struct kref *kref) | |
903 | { | |
904 | struct device_node *node = kref_to_device_node(kref); | |
905 | struct property *prop = node->properties; | |
906 | ||
6a281856 ME |
907 | /* We should never be releasing nodes that haven't been detached. */ |
908 | if (!of_node_check_flag(node, OF_DETACHED)) { | |
909 | printk("WARNING: Bad of_node_put() on %s\n", node->full_name); | |
910 | dump_stack(); | |
911 | kref_init(&node->kref); | |
912 | return; | |
913 | } | |
914 | ||
d3b814bb | 915 | if (!of_node_check_flag(node, OF_DYNAMIC)) |
9b6b563c | 916 | return; |
6a281856 | 917 | |
9b6b563c PM |
918 | while (prop) { |
919 | struct property *next = prop->next; | |
920 | kfree(prop->name); | |
921 | kfree(prop->value); | |
922 | kfree(prop); | |
923 | prop = next; | |
088186de DB |
924 | |
925 | if (!prop) { | |
926 | prop = node->deadprops; | |
927 | node->deadprops = NULL; | |
928 | } | |
9b6b563c | 929 | } |
9b6b563c PM |
930 | kfree(node->full_name); |
931 | kfree(node->data); | |
932 | kfree(node); | |
933 | } | |
934 | ||
935 | /** | |
936 | * of_node_put - Decrement refcount of a node | |
937 | * @node: Node to dec refcount, NULL is supported to | |
938 | * simplify writing of callers | |
939 | * | |
940 | */ | |
941 | void of_node_put(struct device_node *node) | |
942 | { | |
943 | if (node) | |
944 | kref_put(&node->kref, of_node_release); | |
945 | } | |
946 | EXPORT_SYMBOL(of_node_put); | |
947 | ||
948 | /* | |
949 | * Plug a device node into the tree and global list. | |
950 | */ | |
951 | void of_attach_node(struct device_node *np) | |
952 | { | |
f4ac7b5e BH |
953 | unsigned long flags; |
954 | ||
955 | write_lock_irqsave(&devtree_lock, flags); | |
9b6b563c PM |
956 | np->sibling = np->parent->child; |
957 | np->allnext = allnodes; | |
958 | np->parent->child = np; | |
959 | allnodes = np; | |
f4ac7b5e | 960 | write_unlock_irqrestore(&devtree_lock, flags); |
9b6b563c PM |
961 | } |
962 | ||
963 | /* | |
964 | * "Unplug" a node from the device tree. The caller must hold | |
965 | * a reference to the node. The memory associated with the node | |
966 | * is not freed until its refcount goes to zero. | |
967 | */ | |
34f329db | 968 | void of_detach_node(struct device_node *np) |
9b6b563c PM |
969 | { |
970 | struct device_node *parent; | |
f4ac7b5e | 971 | unsigned long flags; |
9b6b563c | 972 | |
f4ac7b5e | 973 | write_lock_irqsave(&devtree_lock, flags); |
9b6b563c PM |
974 | |
975 | parent = np->parent; | |
972d17c9 ME |
976 | if (!parent) |
977 | goto out_unlock; | |
9b6b563c PM |
978 | |
979 | if (allnodes == np) | |
980 | allnodes = np->allnext; | |
981 | else { | |
982 | struct device_node *prev; | |
983 | for (prev = allnodes; | |
984 | prev->allnext != np; | |
985 | prev = prev->allnext) | |
986 | ; | |
987 | prev->allnext = np->allnext; | |
988 | } | |
989 | ||
990 | if (parent->child == np) | |
991 | parent->child = np->sibling; | |
992 | else { | |
993 | struct device_node *prevsib; | |
994 | for (prevsib = np->parent->child; | |
995 | prevsib->sibling != np; | |
996 | prevsib = prevsib->sibling) | |
997 | ; | |
998 | prevsib->sibling = np->sibling; | |
999 | } | |
1000 | ||
6a281856 ME |
1001 | of_node_set_flag(np, OF_DETACHED); |
1002 | ||
972d17c9 | 1003 | out_unlock: |
f4ac7b5e | 1004 | write_unlock_irqrestore(&devtree_lock, flags); |
9b6b563c PM |
1005 | } |
1006 | ||
1007 | #ifdef CONFIG_PPC_PSERIES | |
1008 | /* | |
1009 | * Fix up the uninitialized fields in a new device node: | |
0ebfff14 | 1010 | * name, type and pci-specific fields |
9b6b563c PM |
1011 | */ |
1012 | ||
cc5d0189 | 1013 | static int of_finish_dynamic_node(struct device_node *node) |
9b6b563c PM |
1014 | { |
1015 | struct device_node *parent = of_get_parent(node); | |
1016 | int err = 0; | |
a7f67bdf | 1017 | const phandle *ibm_phandle; |
9b6b563c | 1018 | |
0e56efc7 SR |
1019 | node->name = of_get_property(node, "name", NULL); |
1020 | node->type = of_get_property(node, "device_type", NULL); | |
9b6b563c | 1021 | |
847f5976 BH |
1022 | if (!node->name) |
1023 | node->name = "<NULL>"; | |
1024 | if (!node->type) | |
1025 | node->type = "<NULL>"; | |
1026 | ||
9b6b563c PM |
1027 | if (!parent) { |
1028 | err = -ENODEV; | |
1029 | goto out; | |
1030 | } | |
1031 | ||
1032 | /* We don't support that function on PowerMac, at least | |
1033 | * not yet | |
1034 | */ | |
e8222502 | 1035 | if (machine_is(powermac)) |
9b6b563c PM |
1036 | return -ENODEV; |
1037 | ||
1038 | /* fix up new node's linux_phandle field */ | |
0e56efc7 | 1039 | if ((ibm_phandle = of_get_property(node, "ibm,phandle", NULL))) |
9b6b563c PM |
1040 | node->linux_phandle = *ibm_phandle; |
1041 | ||
1042 | out: | |
1043 | of_node_put(parent); | |
1044 | return err; | |
1045 | } | |
1046 | ||
1047 | static int prom_reconfig_notifier(struct notifier_block *nb, | |
1048 | unsigned long action, void *node) | |
1049 | { | |
1050 | int err; | |
1051 | ||
1052 | switch (action) { | |
1053 | case PSERIES_RECONFIG_ADD: | |
cc5d0189 | 1054 | err = of_finish_dynamic_node(node); |
9b6b563c PM |
1055 | if (err < 0) { |
1056 | printk(KERN_ERR "finish_node returned %d\n", err); | |
1057 | err = NOTIFY_BAD; | |
1058 | } | |
1059 | break; | |
1060 | default: | |
1061 | err = NOTIFY_DONE; | |
1062 | break; | |
1063 | } | |
1064 | return err; | |
1065 | } | |
1066 | ||
1067 | static struct notifier_block prom_reconfig_nb = { | |
1068 | .notifier_call = prom_reconfig_notifier, | |
1069 | .priority = 10, /* This one needs to run first */ | |
1070 | }; | |
1071 | ||
1072 | static int __init prom_reconfig_setup(void) | |
1073 | { | |
1074 | return pSeries_reconfig_notifier_register(&prom_reconfig_nb); | |
1075 | } | |
1076 | __initcall(prom_reconfig_setup); | |
1077 | #endif | |
1078 | ||
acf7d768 BH |
1079 | /* Find the device node for a given logical cpu number, also returns the cpu |
1080 | * local thread number (index in ibm,interrupt-server#s) if relevant and | |
1081 | * asked for (non NULL) | |
1082 | */ | |
1083 | struct device_node *of_get_cpu_node(int cpu, unsigned int *thread) | |
1084 | { | |
1085 | int hardid; | |
1086 | struct device_node *np; | |
1087 | ||
1088 | hardid = get_hard_smp_processor_id(cpu); | |
1089 | ||
1090 | for_each_node_by_type(np, "cpu") { | |
a7f67bdf | 1091 | const u32 *intserv; |
acf7d768 BH |
1092 | unsigned int plen, t; |
1093 | ||
1094 | /* Check for ibm,ppc-interrupt-server#s. If it doesn't exist | |
1095 | * fallback to "reg" property and assume no threads | |
1096 | */ | |
0e56efc7 | 1097 | intserv = of_get_property(np, "ibm,ppc-interrupt-server#s", |
a7f67bdf | 1098 | &plen); |
acf7d768 | 1099 | if (intserv == NULL) { |
0e56efc7 | 1100 | const u32 *reg = of_get_property(np, "reg", NULL); |
acf7d768 BH |
1101 | if (reg == NULL) |
1102 | continue; | |
1103 | if (*reg == hardid) { | |
1104 | if (thread) | |
1105 | *thread = 0; | |
1106 | return np; | |
1107 | } | |
1108 | } else { | |
1109 | plen /= sizeof(u32); | |
1110 | for (t = 0; t < plen; t++) { | |
1111 | if (hardid == intserv[t]) { | |
1112 | if (thread) | |
1113 | *thread = t; | |
1114 | return np; | |
1115 | } | |
1116 | } | |
1117 | } | |
1118 | } | |
1119 | return NULL; | |
1120 | } | |
36ca4ba4 | 1121 | EXPORT_SYMBOL(of_get_cpu_node); |
7a4571ae | 1122 | |
94a3807c | 1123 | #if defined(CONFIG_DEBUG_FS) && defined(DEBUG) |
7a4571ae ME |
1124 | static struct debugfs_blob_wrapper flat_dt_blob; |
1125 | ||
1126 | static int __init export_flat_device_tree(void) | |
1127 | { | |
1128 | struct dentry *d; | |
1129 | ||
7a4571ae ME |
1130 | flat_dt_blob.data = initial_boot_params; |
1131 | flat_dt_blob.size = initial_boot_params->totalsize; | |
1132 | ||
1133 | d = debugfs_create_blob("flat-device-tree", S_IFREG | S_IRUSR, | |
94a3807c | 1134 | powerpc_debugfs_root, &flat_dt_blob); |
7a4571ae ME |
1135 | if (!d) |
1136 | return 1; | |
1137 | ||
1138 | return 0; | |
1139 | } | |
1140 | __initcall(export_flat_device_tree); | |
1141 | #endif |