]>
Commit | Line | Data |
---|---|---|
9b6b563c PM |
1 | /* |
2 | * Procedures for interfacing to Open Firmware. | |
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_PROM | |
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/proc_fs.h> | |
27 | #include <linux/stringify.h> | |
28 | #include <linux/delay.h> | |
29 | #include <linux/initrd.h> | |
30 | #include <linux/bitops.h> | |
31 | #include <asm/prom.h> | |
32 | #include <asm/rtas.h> | |
33 | #include <asm/page.h> | |
34 | #include <asm/processor.h> | |
35 | #include <asm/irq.h> | |
36 | #include <asm/io.h> | |
37 | #include <asm/smp.h> | |
38 | #include <asm/system.h> | |
39 | #include <asm/mmu.h> | |
40 | #include <asm/pgtable.h> | |
41 | #include <asm/pci.h> | |
42 | #include <asm/iommu.h> | |
9b6b563c PM |
43 | #include <asm/btext.h> |
44 | #include <asm/sections.h> | |
45 | #include <asm/machdep.h> | |
46 | ||
9b6b563c | 47 | #include <linux/linux_logo.h> |
9b6b563c PM |
48 | |
49 | /* | |
50 | * Properties whose value is longer than this get excluded from our | |
51 | * copy of the device tree. This value does need to be big enough to | |
52 | * ensure that we don't lose things like the interrupt-map property | |
53 | * on a PCI-PCI bridge. | |
54 | */ | |
55 | #define MAX_PROPERTY_LENGTH (1UL * 1024 * 1024) | |
56 | ||
57 | /* | |
58 | * Eventually bump that one up | |
59 | */ | |
60 | #define DEVTREE_CHUNK_SIZE 0x100000 | |
61 | ||
62 | /* | |
63 | * This is the size of the local memory reserve map that gets copied | |
64 | * into the boot params passed to the kernel. That size is totally | |
65 | * flexible as the kernel just reads the list until it encounters an | |
66 | * entry with size 0, so it can be changed without breaking binary | |
67 | * compatibility | |
68 | */ | |
69 | #define MEM_RESERVE_MAP_SIZE 8 | |
70 | ||
71 | /* | |
72 | * prom_init() is called very early on, before the kernel text | |
73 | * and data have been mapped to KERNELBASE. At this point the code | |
74 | * is running at whatever address it has been loaded at. | |
75 | * On ppc32 we compile with -mrelocatable, which means that references | |
76 | * to extern and static variables get relocated automatically. | |
77 | * On ppc64 we have to relocate the references explicitly with | |
78 | * RELOC. (Note that strings count as static variables.) | |
79 | * | |
80 | * Because OF may have mapped I/O devices into the area starting at | |
81 | * KERNELBASE, particularly on CHRP machines, we can't safely call | |
82 | * OF once the kernel has been mapped to KERNELBASE. Therefore all | |
83 | * OF calls must be done within prom_init(). | |
84 | * | |
85 | * ADDR is used in calls to call_prom. The 4th and following | |
86 | * arguments to call_prom should be 32-bit values. | |
87 | * On ppc64, 64 bit values are truncated to 32 bits (and | |
88 | * fortunately don't get interpreted as two arguments). | |
89 | */ | |
90 | #ifdef CONFIG_PPC64 | |
91 | #define RELOC(x) (*PTRRELOC(&(x))) | |
92 | #define ADDR(x) (u32) add_reloc_offset((unsigned long)(x)) | |
a23414be | 93 | #define OF_WORKAROUNDS 0 |
9b6b563c PM |
94 | #else |
95 | #define RELOC(x) (x) | |
96 | #define ADDR(x) (u32) (x) | |
a23414be PM |
97 | #define OF_WORKAROUNDS of_workarounds |
98 | int of_workarounds; | |
9b6b563c PM |
99 | #endif |
100 | ||
a23414be PM |
101 | #define OF_WA_CLAIM 1 /* do phys/virt claim separately, then map */ |
102 | #define OF_WA_LONGTRAIL 2 /* work around longtrail bugs */ | |
103 | ||
9b6b563c PM |
104 | #define PROM_BUG() do { \ |
105 | prom_printf("kernel BUG at %s line 0x%x!\n", \ | |
106 | RELOC(__FILE__), __LINE__); \ | |
107 | __asm__ __volatile__(".long " BUG_ILLEGAL_INSTR); \ | |
108 | } while (0) | |
109 | ||
110 | #ifdef DEBUG_PROM | |
111 | #define prom_debug(x...) prom_printf(x) | |
112 | #else | |
113 | #define prom_debug(x...) | |
114 | #endif | |
115 | ||
9b6b563c PM |
116 | |
117 | typedef u32 prom_arg_t; | |
118 | ||
119 | struct prom_args { | |
120 | u32 service; | |
121 | u32 nargs; | |
122 | u32 nret; | |
123 | prom_arg_t args[10]; | |
124 | }; | |
125 | ||
126 | struct prom_t { | |
127 | ihandle root; | |
a23414be | 128 | phandle chosen; |
9b6b563c PM |
129 | int cpu; |
130 | ihandle stdout; | |
a575b807 | 131 | ihandle mmumap; |
a23414be | 132 | ihandle memory; |
9b6b563c PM |
133 | }; |
134 | ||
135 | struct mem_map_entry { | |
cbbcf340 KG |
136 | u64 base; |
137 | u64 size; | |
9b6b563c PM |
138 | }; |
139 | ||
140 | typedef u32 cell_t; | |
141 | ||
142 | extern void __start(unsigned long r3, unsigned long r4, unsigned long r5); | |
143 | ||
144 | #ifdef CONFIG_PPC64 | |
c4988820 | 145 | extern int enter_prom(struct prom_args *args, unsigned long entry); |
9b6b563c | 146 | #else |
c4988820 | 147 | static inline int enter_prom(struct prom_args *args, unsigned long entry) |
9b6b563c | 148 | { |
c4988820 | 149 | return ((int (*)(struct prom_args *))entry)(args); |
9b6b563c PM |
150 | } |
151 | #endif | |
152 | ||
153 | extern void copy_and_flush(unsigned long dest, unsigned long src, | |
154 | unsigned long size, unsigned long offset); | |
155 | ||
156 | /* prom structure */ | |
157 | static struct prom_t __initdata prom; | |
158 | ||
159 | static unsigned long prom_entry __initdata; | |
160 | ||
161 | #define PROM_SCRATCH_SIZE 256 | |
162 | ||
163 | static char __initdata of_stdout_device[256]; | |
164 | static char __initdata prom_scratch[PROM_SCRATCH_SIZE]; | |
165 | ||
166 | static unsigned long __initdata dt_header_start; | |
167 | static unsigned long __initdata dt_struct_start, dt_struct_end; | |
168 | static unsigned long __initdata dt_string_start, dt_string_end; | |
169 | ||
170 | static unsigned long __initdata prom_initrd_start, prom_initrd_end; | |
171 | ||
172 | #ifdef CONFIG_PPC64 | |
165785e5 JK |
173 | static int __initdata prom_iommu_force_on; |
174 | static int __initdata prom_iommu_off; | |
9b6b563c PM |
175 | static unsigned long __initdata prom_tce_alloc_start; |
176 | static unsigned long __initdata prom_tce_alloc_end; | |
177 | #endif | |
178 | ||
e8222502 BH |
179 | /* Platforms codes are now obsolete in the kernel. Now only used within this |
180 | * file and ultimately gone too. Feel free to change them if you need, they | |
181 | * are not shared with anything outside of this file anymore | |
182 | */ | |
183 | #define PLATFORM_PSERIES 0x0100 | |
184 | #define PLATFORM_PSERIES_LPAR 0x0101 | |
185 | #define PLATFORM_LPAR 0x0001 | |
186 | #define PLATFORM_POWERMAC 0x0400 | |
187 | #define PLATFORM_GENERIC 0x0500 | |
188 | ||
9b6b563c PM |
189 | static int __initdata of_platform; |
190 | ||
191 | static char __initdata prom_cmd_line[COMMAND_LINE_SIZE]; | |
192 | ||
9b6b563c PM |
193 | static unsigned long __initdata alloc_top; |
194 | static unsigned long __initdata alloc_top_high; | |
195 | static unsigned long __initdata alloc_bottom; | |
196 | static unsigned long __initdata rmo_top; | |
197 | static unsigned long __initdata ram_top; | |
198 | ||
199 | static struct mem_map_entry __initdata mem_reserve_map[MEM_RESERVE_MAP_SIZE]; | |
200 | static int __initdata mem_reserve_cnt; | |
201 | ||
202 | static cell_t __initdata regbuf[1024]; | |
203 | ||
204 | ||
9b6b563c PM |
205 | /* |
206 | * Error results ... some OF calls will return "-1" on error, some | |
207 | * will return 0, some will return either. To simplify, here are | |
208 | * macros to use with any ihandle or phandle return value to check if | |
209 | * it is valid | |
210 | */ | |
211 | ||
212 | #define PROM_ERROR (-1u) | |
213 | #define PHANDLE_VALID(p) ((p) != 0 && (p) != PROM_ERROR) | |
214 | #define IHANDLE_VALID(i) ((i) != 0 && (i) != PROM_ERROR) | |
215 | ||
216 | ||
217 | /* This is the one and *ONLY* place where we actually call open | |
218 | * firmware. | |
219 | */ | |
220 | ||
221 | static int __init call_prom(const char *service, int nargs, int nret, ...) | |
222 | { | |
223 | int i; | |
224 | struct prom_args args; | |
225 | va_list list; | |
226 | ||
227 | args.service = ADDR(service); | |
228 | args.nargs = nargs; | |
229 | args.nret = nret; | |
230 | ||
231 | va_start(list, nret); | |
232 | for (i = 0; i < nargs; i++) | |
233 | args.args[i] = va_arg(list, prom_arg_t); | |
234 | va_end(list); | |
235 | ||
236 | for (i = 0; i < nret; i++) | |
237 | args.args[nargs+i] = 0; | |
238 | ||
c4988820 PM |
239 | if (enter_prom(&args, RELOC(prom_entry)) < 0) |
240 | return PROM_ERROR; | |
9b6b563c PM |
241 | |
242 | return (nret > 0) ? args.args[nargs] : 0; | |
243 | } | |
244 | ||
245 | static int __init call_prom_ret(const char *service, int nargs, int nret, | |
246 | prom_arg_t *rets, ...) | |
247 | { | |
248 | int i; | |
249 | struct prom_args args; | |
250 | va_list list; | |
251 | ||
252 | args.service = ADDR(service); | |
253 | args.nargs = nargs; | |
254 | args.nret = nret; | |
255 | ||
256 | va_start(list, rets); | |
257 | for (i = 0; i < nargs; i++) | |
258 | args.args[i] = va_arg(list, prom_arg_t); | |
259 | va_end(list); | |
260 | ||
261 | for (i = 0; i < nret; i++) | |
ed1189b7 | 262 | args.args[nargs+i] = 0; |
9b6b563c | 263 | |
c4988820 PM |
264 | if (enter_prom(&args, RELOC(prom_entry)) < 0) |
265 | return PROM_ERROR; | |
9b6b563c PM |
266 | |
267 | if (rets != NULL) | |
268 | for (i = 1; i < nret; ++i) | |
c5200c90 | 269 | rets[i-1] = args.args[nargs+i]; |
9b6b563c PM |
270 | |
271 | return (nret > 0) ? args.args[nargs] : 0; | |
272 | } | |
273 | ||
274 | ||
9b6b563c PM |
275 | static void __init prom_print(const char *msg) |
276 | { | |
277 | const char *p, *q; | |
278 | struct prom_t *_prom = &RELOC(prom); | |
279 | ||
280 | if (_prom->stdout == 0) | |
281 | return; | |
282 | ||
283 | for (p = msg; *p != 0; p = q) { | |
284 | for (q = p; *q != 0 && *q != '\n'; ++q) | |
285 | ; | |
286 | if (q > p) | |
287 | call_prom("write", 3, 1, _prom->stdout, p, q - p); | |
288 | if (*q == 0) | |
289 | break; | |
290 | ++q; | |
291 | call_prom("write", 3, 1, _prom->stdout, ADDR("\r\n"), 2); | |
292 | } | |
293 | } | |
294 | ||
295 | ||
296 | static void __init prom_print_hex(unsigned long val) | |
297 | { | |
298 | int i, nibbles = sizeof(val)*2; | |
299 | char buf[sizeof(val)*2+1]; | |
300 | struct prom_t *_prom = &RELOC(prom); | |
301 | ||
302 | for (i = nibbles-1; i >= 0; i--) { | |
303 | buf[i] = (val & 0xf) + '0'; | |
304 | if (buf[i] > '9') | |
305 | buf[i] += ('a'-'0'-10); | |
306 | val >>= 4; | |
307 | } | |
308 | buf[nibbles] = '\0'; | |
309 | call_prom("write", 3, 1, _prom->stdout, buf, nibbles); | |
310 | } | |
311 | ||
312 | ||
313 | static void __init prom_printf(const char *format, ...) | |
314 | { | |
315 | const char *p, *q, *s; | |
316 | va_list args; | |
317 | unsigned long v; | |
318 | struct prom_t *_prom = &RELOC(prom); | |
319 | ||
320 | va_start(args, format); | |
321 | #ifdef CONFIG_PPC64 | |
322 | format = PTRRELOC(format); | |
323 | #endif | |
324 | for (p = format; *p != 0; p = q) { | |
325 | for (q = p; *q != 0 && *q != '\n' && *q != '%'; ++q) | |
326 | ; | |
327 | if (q > p) | |
328 | call_prom("write", 3, 1, _prom->stdout, p, q - p); | |
329 | if (*q == 0) | |
330 | break; | |
331 | if (*q == '\n') { | |
332 | ++q; | |
333 | call_prom("write", 3, 1, _prom->stdout, | |
334 | ADDR("\r\n"), 2); | |
335 | continue; | |
336 | } | |
337 | ++q; | |
338 | if (*q == 0) | |
339 | break; | |
340 | switch (*q) { | |
341 | case 's': | |
342 | ++q; | |
343 | s = va_arg(args, const char *); | |
344 | prom_print(s); | |
345 | break; | |
346 | case 'x': | |
347 | ++q; | |
348 | v = va_arg(args, unsigned long); | |
349 | prom_print_hex(v); | |
350 | break; | |
351 | } | |
352 | } | |
353 | } | |
354 | ||
355 | ||
a575b807 PM |
356 | static unsigned int __init prom_claim(unsigned long virt, unsigned long size, |
357 | unsigned long align) | |
358 | { | |
a575b807 PM |
359 | struct prom_t *_prom = &RELOC(prom); |
360 | ||
a23414be PM |
361 | if (align == 0 && (OF_WORKAROUNDS & OF_WA_CLAIM)) { |
362 | /* | |
363 | * Old OF requires we claim physical and virtual separately | |
364 | * and then map explicitly (assuming virtual mode) | |
365 | */ | |
366 | int ret; | |
367 | prom_arg_t result; | |
368 | ||
369 | ret = call_prom_ret("call-method", 5, 2, &result, | |
370 | ADDR("claim"), _prom->memory, | |
371 | align, size, virt); | |
372 | if (ret != 0 || result == -1) | |
373 | return -1; | |
374 | ret = call_prom_ret("call-method", 5, 2, &result, | |
375 | ADDR("claim"), _prom->mmumap, | |
376 | align, size, virt); | |
377 | if (ret != 0) { | |
378 | call_prom("call-method", 4, 1, ADDR("release"), | |
379 | _prom->memory, size, virt); | |
380 | return -1; | |
381 | } | |
382 | /* the 0x12 is M (coherence) + PP == read/write */ | |
a575b807 | 383 | call_prom("call-method", 6, 1, |
a23414be PM |
384 | ADDR("map"), _prom->mmumap, 0x12, size, virt, virt); |
385 | return virt; | |
386 | } | |
387 | return call_prom("claim", 3, 1, (prom_arg_t)virt, (prom_arg_t)size, | |
388 | (prom_arg_t)align); | |
a575b807 PM |
389 | } |
390 | ||
9b6b563c PM |
391 | static void __init __attribute__((noreturn)) prom_panic(const char *reason) |
392 | { | |
393 | #ifdef CONFIG_PPC64 | |
394 | reason = PTRRELOC(reason); | |
395 | #endif | |
396 | prom_print(reason); | |
add60ef3 OH |
397 | /* Do not call exit because it clears the screen on pmac |
398 | * it also causes some sort of double-fault on early pmacs */ | |
399 | if (RELOC(of_platform) == PLATFORM_POWERMAC) | |
400 | asm("trap\n"); | |
401 | ||
9b6b563c PM |
402 | /* ToDo: should put up an SRC here on p/iSeries */ |
403 | call_prom("exit", 0, 0); | |
404 | ||
405 | for (;;) /* should never get here */ | |
406 | ; | |
407 | } | |
408 | ||
409 | ||
410 | static int __init prom_next_node(phandle *nodep) | |
411 | { | |
412 | phandle node; | |
413 | ||
414 | if ((node = *nodep) != 0 | |
415 | && (*nodep = call_prom("child", 1, 1, node)) != 0) | |
416 | return 1; | |
417 | if ((*nodep = call_prom("peer", 1, 1, node)) != 0) | |
418 | return 1; | |
419 | for (;;) { | |
420 | if ((node = call_prom("parent", 1, 1, node)) == 0) | |
421 | return 0; | |
422 | if ((*nodep = call_prom("peer", 1, 1, node)) != 0) | |
423 | return 1; | |
424 | } | |
425 | } | |
426 | ||
21fe3301 | 427 | static int inline prom_getprop(phandle node, const char *pname, |
9b6b563c PM |
428 | void *value, size_t valuelen) |
429 | { | |
430 | return call_prom("getprop", 4, 1, node, ADDR(pname), | |
431 | (u32)(unsigned long) value, (u32) valuelen); | |
432 | } | |
433 | ||
21fe3301 | 434 | static int inline prom_getproplen(phandle node, const char *pname) |
9b6b563c PM |
435 | { |
436 | return call_prom("getproplen", 2, 1, node, ADDR(pname)); | |
437 | } | |
438 | ||
a23414be | 439 | static void add_string(char **str, const char *q) |
9b6b563c | 440 | { |
a23414be PM |
441 | char *p = *str; |
442 | ||
443 | while (*q) | |
444 | *p++ = *q++; | |
445 | *p++ = ' '; | |
446 | *str = p; | |
447 | } | |
448 | ||
449 | static char *tohex(unsigned int x) | |
450 | { | |
451 | static char digits[] = "0123456789abcdef"; | |
452 | static char result[9]; | |
453 | int i; | |
454 | ||
455 | result[8] = 0; | |
456 | i = 8; | |
457 | do { | |
458 | --i; | |
459 | result[i] = digits[x & 0xf]; | |
460 | x >>= 4; | |
461 | } while (x != 0 && i > 0); | |
462 | return &result[i]; | |
463 | } | |
464 | ||
465 | static int __init prom_setprop(phandle node, const char *nodename, | |
466 | const char *pname, void *value, size_t valuelen) | |
467 | { | |
468 | char cmd[256], *p; | |
469 | ||
470 | if (!(OF_WORKAROUNDS & OF_WA_LONGTRAIL)) | |
471 | return call_prom("setprop", 4, 1, node, ADDR(pname), | |
472 | (u32)(unsigned long) value, (u32) valuelen); | |
473 | ||
474 | /* gah... setprop doesn't work on longtrail, have to use interpret */ | |
475 | p = cmd; | |
476 | add_string(&p, "dev"); | |
477 | add_string(&p, nodename); | |
478 | add_string(&p, tohex((u32)(unsigned long) value)); | |
479 | add_string(&p, tohex(valuelen)); | |
480 | add_string(&p, tohex(ADDR(pname))); | |
481 | add_string(&p, tohex(strlen(RELOC(pname)))); | |
482 | add_string(&p, "property"); | |
483 | *p = 0; | |
484 | return call_prom("interpret", 1, 1, (u32)(unsigned long) cmd); | |
9b6b563c PM |
485 | } |
486 | ||
9b6b563c PM |
487 | /* |
488 | * Early parsing of the command line passed to the kernel, used for | |
489 | * "mem=x" and the options that affect the iommu | |
490 | */ | |
491 | static void __init early_cmdline_parse(void) | |
492 | { | |
493 | struct prom_t *_prom = &RELOC(prom); | |
470407a8 | 494 | #ifdef CONFIG_PPC64 |
cc5d0189 | 495 | const char *opt; |
470407a8 | 496 | #endif |
cc5d0189 | 497 | char *p; |
9b6b563c PM |
498 | int l = 0; |
499 | ||
500 | RELOC(prom_cmd_line[0]) = 0; | |
501 | p = RELOC(prom_cmd_line); | |
502 | if ((long)_prom->chosen > 0) | |
503 | l = prom_getprop(_prom->chosen, "bootargs", p, COMMAND_LINE_SIZE-1); | |
504 | #ifdef CONFIG_CMDLINE | |
0e4aa9c2 | 505 | if (l <= 0 || p[0] == '\0') /* dbl check */ |
9b6b563c PM |
506 | strlcpy(RELOC(prom_cmd_line), |
507 | RELOC(CONFIG_CMDLINE), sizeof(prom_cmd_line)); | |
508 | #endif /* CONFIG_CMDLINE */ | |
509 | prom_printf("command line: %s\n", RELOC(prom_cmd_line)); | |
510 | ||
511 | #ifdef CONFIG_PPC64 | |
512 | opt = strstr(RELOC(prom_cmd_line), RELOC("iommu=")); | |
513 | if (opt) { | |
514 | prom_printf("iommu opt is: %s\n", opt); | |
515 | opt += 6; | |
516 | while (*opt && *opt == ' ') | |
517 | opt++; | |
518 | if (!strncmp(opt, RELOC("off"), 3)) | |
165785e5 | 519 | RELOC(prom_iommu_off) = 1; |
9b6b563c | 520 | else if (!strncmp(opt, RELOC("force"), 5)) |
165785e5 | 521 | RELOC(prom_iommu_force_on) = 1; |
9b6b563c PM |
522 | } |
523 | #endif | |
9b6b563c PM |
524 | } |
525 | ||
526 | #ifdef CONFIG_PPC_PSERIES | |
527 | /* | |
f709bfac PM |
528 | * There are two methods for telling firmware what our capabilities are. |
529 | * Newer machines have an "ibm,client-architecture-support" method on the | |
530 | * root node. For older machines, we have to call the "process-elf-header" | |
531 | * method in the /packages/elf-loader node, passing it a fake 32-bit | |
532 | * ELF header containing a couple of PT_NOTE sections that contain | |
533 | * structures that contain various information. | |
9b6b563c | 534 | */ |
f709bfac PM |
535 | |
536 | /* | |
537 | * New method - extensible architecture description vector. | |
538 | * | |
539 | * Because the description vector contains a mix of byte and word | |
540 | * values, we declare it as an unsigned char array, and use this | |
541 | * macro to put word values in. | |
542 | */ | |
543 | #define W(x) ((x) >> 24) & 0xff, ((x) >> 16) & 0xff, \ | |
544 | ((x) >> 8) & 0xff, (x) & 0xff | |
545 | ||
546 | /* Option vector bits - generic bits in byte 1 */ | |
547 | #define OV_IGNORE 0x80 /* ignore this vector */ | |
548 | #define OV_CESSATION_POLICY 0x40 /* halt if unsupported option present*/ | |
549 | ||
550 | /* Option vector 1: processor architectures supported */ | |
551 | #define OV1_PPC_2_00 0x80 /* set if we support PowerPC 2.00 */ | |
552 | #define OV1_PPC_2_01 0x40 /* set if we support PowerPC 2.01 */ | |
553 | #define OV1_PPC_2_02 0x20 /* set if we support PowerPC 2.02 */ | |
554 | #define OV1_PPC_2_03 0x10 /* set if we support PowerPC 2.03 */ | |
555 | #define OV1_PPC_2_04 0x08 /* set if we support PowerPC 2.04 */ | |
556 | #define OV1_PPC_2_05 0x04 /* set if we support PowerPC 2.05 */ | |
0cb99013 | 557 | #define OV1_PPC_2_06 0x02 /* set if we support PowerPC 2.06 */ |
f709bfac PM |
558 | |
559 | /* Option vector 2: Open Firmware options supported */ | |
560 | #define OV2_REAL_MODE 0x20 /* set if we want OF in real mode */ | |
561 | ||
562 | /* Option vector 3: processor options supported */ | |
563 | #define OV3_FP 0x80 /* floating point */ | |
564 | #define OV3_VMX 0x40 /* VMX/Altivec */ | |
974a76f5 | 565 | #define OV3_DFP 0x20 /* decimal FP */ |
f709bfac PM |
566 | |
567 | /* Option vector 5: PAPR/OF options supported */ | |
568 | #define OV5_LPAR 0x80 /* logical partitioning supported */ | |
569 | #define OV5_SPLPAR 0x40 /* shared-processor LPAR supported */ | |
570 | /* ibm,dynamic-reconfiguration-memory property supported */ | |
571 | #define OV5_DRCONF_MEMORY 0x20 | |
572 | #define OV5_LARGE_PAGES 0x10 /* large pages supported */ | |
d8c391a5 | 573 | #define OV5_DONATE_DEDICATE_CPU 0x02 /* donate dedicated CPU support */ |
014dad90 ME |
574 | /* PCIe/MSI support. Without MSI full PCIe is not supported */ |
575 | #ifdef CONFIG_PCI_MSI | |
576 | #define OV5_MSI 0x01 /* PCIe/MSI support */ | |
577 | #else | |
578 | #define OV5_MSI 0x00 | |
579 | #endif /* CONFIG_PCI_MSI */ | |
8391e42a NF |
580 | #ifdef CONFIG_PPC_SMLPAR |
581 | #define OV5_CMO 0x80 /* Cooperative Memory Overcommitment */ | |
582 | #else | |
583 | #define OV5_CMO 0x00 | |
584 | #endif | |
f709bfac PM |
585 | |
586 | /* | |
587 | * The architecture vector has an array of PVR mask/value pairs, | |
588 | * followed by # option vectors - 1, followed by the option vectors. | |
589 | */ | |
590 | static unsigned char ibm_architecture_vec[] = { | |
591 | W(0xfffe0000), W(0x003a0000), /* POWER5/POWER5+ */ | |
03054d51 | 592 | W(0xffff0000), W(0x003e0000), /* POWER6 */ |
e952e6c4 | 593 | W(0xffff0000), W(0x003f0000), /* POWER7 */ |
0cb99013 | 594 | W(0xffffffff), W(0x0f000003), /* all 2.06-compliant */ |
0efbc18a | 595 | W(0xffffffff), W(0x0f000002), /* all 2.05-compliant */ |
f709bfac PM |
596 | W(0xfffffffe), W(0x0f000001), /* all 2.04-compliant and earlier */ |
597 | 5 - 1, /* 5 option vectors */ | |
598 | ||
599 | /* option vector 1: processor architectures supported */ | |
11e9ed43 | 600 | 3 - 2, /* length */ |
f709bfac PM |
601 | 0, /* don't ignore, don't halt */ |
602 | OV1_PPC_2_00 | OV1_PPC_2_01 | OV1_PPC_2_02 | OV1_PPC_2_03 | | |
0cb99013 | 603 | OV1_PPC_2_04 | OV1_PPC_2_05 | OV1_PPC_2_06, |
f709bfac PM |
604 | |
605 | /* option vector 2: Open Firmware options supported */ | |
11e9ed43 | 606 | 34 - 2, /* length */ |
f709bfac PM |
607 | OV2_REAL_MODE, |
608 | 0, 0, | |
609 | W(0xffffffff), /* real_base */ | |
610 | W(0xffffffff), /* real_size */ | |
611 | W(0xffffffff), /* virt_base */ | |
612 | W(0xffffffff), /* virt_size */ | |
613 | W(0xffffffff), /* load_base */ | |
856cc2f0 | 614 | W(64), /* 64MB min RMA */ |
f709bfac PM |
615 | W(0xffffffff), /* full client load */ |
616 | 0, /* min RMA percentage of total RAM */ | |
617 | 48, /* max log_2(hash table size) */ | |
618 | ||
619 | /* option vector 3: processor options supported */ | |
11e9ed43 | 620 | 3 - 2, /* length */ |
f709bfac | 621 | 0, /* don't ignore, don't halt */ |
974a76f5 | 622 | OV3_FP | OV3_VMX | OV3_DFP, |
f709bfac PM |
623 | |
624 | /* option vector 4: IBM PAPR implementation */ | |
11e9ed43 | 625 | 2 - 2, /* length */ |
f709bfac PM |
626 | 0, /* don't halt */ |
627 | ||
628 | /* option vector 5: PAPR/OF options */ | |
8391e42a | 629 | 5 - 2, /* length */ |
f709bfac | 630 | 0, /* don't ignore, don't halt */ |
d8c391a5 JM |
631 | OV5_LPAR | OV5_SPLPAR | OV5_LARGE_PAGES | OV5_DRCONF_MEMORY | |
632 | OV5_DONATE_DEDICATE_CPU | OV5_MSI, | |
8391e42a NF |
633 | 0, |
634 | OV5_CMO, | |
f709bfac PM |
635 | }; |
636 | ||
637 | /* Old method - ELF header with PT_NOTE sections */ | |
9b6b563c PM |
638 | static struct fake_elf { |
639 | Elf32_Ehdr elfhdr; | |
640 | Elf32_Phdr phdr[2]; | |
641 | struct chrpnote { | |
642 | u32 namesz; | |
643 | u32 descsz; | |
644 | u32 type; | |
645 | char name[8]; /* "PowerPC" */ | |
646 | struct chrpdesc { | |
647 | u32 real_mode; | |
648 | u32 real_base; | |
649 | u32 real_size; | |
650 | u32 virt_base; | |
651 | u32 virt_size; | |
652 | u32 load_base; | |
653 | } chrpdesc; | |
654 | } chrpnote; | |
655 | struct rpanote { | |
656 | u32 namesz; | |
657 | u32 descsz; | |
658 | u32 type; | |
659 | char name[24]; /* "IBM,RPA-Client-Config" */ | |
660 | struct rpadesc { | |
661 | u32 lpar_affinity; | |
662 | u32 min_rmo_size; | |
663 | u32 min_rmo_percent; | |
664 | u32 max_pft_size; | |
665 | u32 splpar; | |
666 | u32 min_load; | |
667 | u32 new_mem_def; | |
668 | u32 ignore_me; | |
669 | } rpadesc; | |
670 | } rpanote; | |
5663a123 | 671 | } fake_elf = { |
9b6b563c PM |
672 | .elfhdr = { |
673 | .e_ident = { 0x7f, 'E', 'L', 'F', | |
674 | ELFCLASS32, ELFDATA2MSB, EV_CURRENT }, | |
675 | .e_type = ET_EXEC, /* yeah right */ | |
676 | .e_machine = EM_PPC, | |
677 | .e_version = EV_CURRENT, | |
678 | .e_phoff = offsetof(struct fake_elf, phdr), | |
679 | .e_phentsize = sizeof(Elf32_Phdr), | |
680 | .e_phnum = 2 | |
681 | }, | |
682 | .phdr = { | |
683 | [0] = { | |
684 | .p_type = PT_NOTE, | |
685 | .p_offset = offsetof(struct fake_elf, chrpnote), | |
686 | .p_filesz = sizeof(struct chrpnote) | |
687 | }, [1] = { | |
688 | .p_type = PT_NOTE, | |
689 | .p_offset = offsetof(struct fake_elf, rpanote), | |
690 | .p_filesz = sizeof(struct rpanote) | |
691 | } | |
692 | }, | |
693 | .chrpnote = { | |
694 | .namesz = sizeof("PowerPC"), | |
695 | .descsz = sizeof(struct chrpdesc), | |
696 | .type = 0x1275, | |
697 | .name = "PowerPC", | |
698 | .chrpdesc = { | |
699 | .real_mode = ~0U, /* ~0 means "don't care" */ | |
700 | .real_base = ~0U, | |
701 | .real_size = ~0U, | |
702 | .virt_base = ~0U, | |
703 | .virt_size = ~0U, | |
704 | .load_base = ~0U | |
705 | }, | |
706 | }, | |
707 | .rpanote = { | |
708 | .namesz = sizeof("IBM,RPA-Client-Config"), | |
709 | .descsz = sizeof(struct rpadesc), | |
710 | .type = 0x12759999, | |
711 | .name = "IBM,RPA-Client-Config", | |
712 | .rpadesc = { | |
5663a123 PM |
713 | .lpar_affinity = 0, |
714 | .min_rmo_size = 64, /* in megabytes */ | |
9b6b563c | 715 | .min_rmo_percent = 0, |
5663a123 | 716 | .max_pft_size = 48, /* 2^48 bytes max PFT size */ |
9b6b563c PM |
717 | .splpar = 1, |
718 | .min_load = ~0U, | |
5663a123 | 719 | .new_mem_def = 0 |
9b6b563c PM |
720 | } |
721 | } | |
722 | }; | |
723 | ||
724 | static void __init prom_send_capabilities(void) | |
725 | { | |
f709bfac PM |
726 | ihandle elfloader, root; |
727 | prom_arg_t ret; | |
728 | ||
729 | root = call_prom("open", 1, 1, ADDR("/")); | |
730 | if (root != 0) { | |
731 | /* try calling the ibm,client-architecture-support method */ | |
4da727ae | 732 | prom_printf("Calling ibm,client-architecture..."); |
f709bfac PM |
733 | if (call_prom_ret("call-method", 3, 2, &ret, |
734 | ADDR("ibm,client-architecture-support"), | |
33b74977 | 735 | root, |
f709bfac PM |
736 | ADDR(ibm_architecture_vec)) == 0) { |
737 | /* the call exists... */ | |
738 | if (ret) | |
4da727ae | 739 | prom_printf("\nWARNING: ibm,client-architecture" |
f709bfac PM |
740 | "-support call FAILED!\n"); |
741 | call_prom("close", 1, 0, root); | |
4da727ae | 742 | prom_printf(" done\n"); |
f709bfac PM |
743 | return; |
744 | } | |
745 | call_prom("close", 1, 0, root); | |
746 | } | |
9b6b563c | 747 | |
f709bfac | 748 | /* no ibm,client-architecture-support call, try the old way */ |
9b6b563c PM |
749 | elfloader = call_prom("open", 1, 1, ADDR("/packages/elf-loader")); |
750 | if (elfloader == 0) { | |
751 | prom_printf("couldn't open /packages/elf-loader\n"); | |
752 | return; | |
753 | } | |
754 | call_prom("call-method", 3, 1, ADDR("process-elf-header"), | |
755 | elfloader, ADDR(&fake_elf)); | |
756 | call_prom("close", 1, 0, elfloader); | |
757 | } | |
758 | #endif | |
759 | ||
760 | /* | |
761 | * Memory allocation strategy... our layout is normally: | |
762 | * | |
763 | * at 14Mb or more we have vmlinux, then a gap and initrd. In some | |
764 | * rare cases, initrd might end up being before the kernel though. | |
765 | * We assume this won't override the final kernel at 0, we have no | |
766 | * provision to handle that in this version, but it should hopefully | |
767 | * never happen. | |
768 | * | |
769 | * alloc_top is set to the top of RMO, eventually shrink down if the | |
770 | * TCEs overlap | |
771 | * | |
772 | * alloc_bottom is set to the top of kernel/initrd | |
773 | * | |
774 | * from there, allocations are done this way : rtas is allocated | |
775 | * topmost, and the device-tree is allocated from the bottom. We try | |
776 | * to grow the device-tree allocation as we progress. If we can't, | |
777 | * then we fail, we don't currently have a facility to restart | |
778 | * elsewhere, but that shouldn't be necessary. | |
779 | * | |
780 | * Note that calls to reserve_mem have to be done explicitly, memory | |
781 | * allocated with either alloc_up or alloc_down isn't automatically | |
782 | * reserved. | |
783 | */ | |
784 | ||
785 | ||
786 | /* | |
787 | * Allocates memory in the RMO upward from the kernel/initrd | |
788 | * | |
789 | * When align is 0, this is a special case, it means to allocate in place | |
790 | * at the current location of alloc_bottom or fail (that is basically | |
791 | * extending the previous allocation). Used for the device-tree flattening | |
792 | */ | |
793 | static unsigned long __init alloc_up(unsigned long size, unsigned long align) | |
794 | { | |
c4988820 | 795 | unsigned long base = RELOC(alloc_bottom); |
9b6b563c PM |
796 | unsigned long addr = 0; |
797 | ||
c4988820 PM |
798 | if (align) |
799 | base = _ALIGN_UP(base, align); | |
9b6b563c PM |
800 | prom_debug("alloc_up(%x, %x)\n", size, align); |
801 | if (RELOC(ram_top) == 0) | |
802 | prom_panic("alloc_up() called with mem not initialized\n"); | |
803 | ||
804 | if (align) | |
805 | base = _ALIGN_UP(RELOC(alloc_bottom), align); | |
806 | else | |
807 | base = RELOC(alloc_bottom); | |
808 | ||
809 | for(; (base + size) <= RELOC(alloc_top); | |
810 | base = _ALIGN_UP(base + 0x100000, align)) { | |
811 | prom_debug(" trying: 0x%x\n\r", base); | |
812 | addr = (unsigned long)prom_claim(base, size, 0); | |
c4988820 | 813 | if (addr != PROM_ERROR && addr != 0) |
9b6b563c PM |
814 | break; |
815 | addr = 0; | |
816 | if (align == 0) | |
817 | break; | |
818 | } | |
819 | if (addr == 0) | |
820 | return 0; | |
821 | RELOC(alloc_bottom) = addr; | |
822 | ||
823 | prom_debug(" -> %x\n", addr); | |
824 | prom_debug(" alloc_bottom : %x\n", RELOC(alloc_bottom)); | |
825 | prom_debug(" alloc_top : %x\n", RELOC(alloc_top)); | |
826 | prom_debug(" alloc_top_hi : %x\n", RELOC(alloc_top_high)); | |
827 | prom_debug(" rmo_top : %x\n", RELOC(rmo_top)); | |
828 | prom_debug(" ram_top : %x\n", RELOC(ram_top)); | |
829 | ||
830 | return addr; | |
831 | } | |
832 | ||
833 | /* | |
834 | * Allocates memory downward, either from top of RMO, or if highmem | |
835 | * is set, from the top of RAM. Note that this one doesn't handle | |
836 | * failures. It does claim memory if highmem is not set. | |
837 | */ | |
838 | static unsigned long __init alloc_down(unsigned long size, unsigned long align, | |
839 | int highmem) | |
840 | { | |
841 | unsigned long base, addr = 0; | |
842 | ||
843 | prom_debug("alloc_down(%x, %x, %s)\n", size, align, | |
844 | highmem ? RELOC("(high)") : RELOC("(low)")); | |
845 | if (RELOC(ram_top) == 0) | |
846 | prom_panic("alloc_down() called with mem not initialized\n"); | |
847 | ||
848 | if (highmem) { | |
849 | /* Carve out storage for the TCE table. */ | |
850 | addr = _ALIGN_DOWN(RELOC(alloc_top_high) - size, align); | |
851 | if (addr <= RELOC(alloc_bottom)) | |
852 | return 0; | |
853 | /* Will we bump into the RMO ? If yes, check out that we | |
854 | * didn't overlap existing allocations there, if we did, | |
855 | * we are dead, we must be the first in town ! | |
856 | */ | |
857 | if (addr < RELOC(rmo_top)) { | |
858 | /* Good, we are first */ | |
859 | if (RELOC(alloc_top) == RELOC(rmo_top)) | |
860 | RELOC(alloc_top) = RELOC(rmo_top) = addr; | |
861 | else | |
862 | return 0; | |
863 | } | |
864 | RELOC(alloc_top_high) = addr; | |
865 | goto bail; | |
866 | } | |
867 | ||
868 | base = _ALIGN_DOWN(RELOC(alloc_top) - size, align); | |
869 | for (; base > RELOC(alloc_bottom); | |
870 | base = _ALIGN_DOWN(base - 0x100000, align)) { | |
871 | prom_debug(" trying: 0x%x\n\r", base); | |
872 | addr = (unsigned long)prom_claim(base, size, 0); | |
c4988820 | 873 | if (addr != PROM_ERROR && addr != 0) |
9b6b563c PM |
874 | break; |
875 | addr = 0; | |
876 | } | |
877 | if (addr == 0) | |
878 | return 0; | |
879 | RELOC(alloc_top) = addr; | |
880 | ||
881 | bail: | |
882 | prom_debug(" -> %x\n", addr); | |
883 | prom_debug(" alloc_bottom : %x\n", RELOC(alloc_bottom)); | |
884 | prom_debug(" alloc_top : %x\n", RELOC(alloc_top)); | |
885 | prom_debug(" alloc_top_hi : %x\n", RELOC(alloc_top_high)); | |
886 | prom_debug(" rmo_top : %x\n", RELOC(rmo_top)); | |
887 | prom_debug(" ram_top : %x\n", RELOC(ram_top)); | |
888 | ||
889 | return addr; | |
890 | } | |
891 | ||
892 | /* | |
893 | * Parse a "reg" cell | |
894 | */ | |
895 | static unsigned long __init prom_next_cell(int s, cell_t **cellp) | |
896 | { | |
897 | cell_t *p = *cellp; | |
898 | unsigned long r = 0; | |
899 | ||
900 | /* Ignore more than 2 cells */ | |
901 | while (s > sizeof(unsigned long) / 4) { | |
902 | p++; | |
903 | s--; | |
904 | } | |
905 | r = *p++; | |
906 | #ifdef CONFIG_PPC64 | |
35499c01 | 907 | if (s > 1) { |
9b6b563c PM |
908 | r <<= 32; |
909 | r |= *(p++); | |
910 | } | |
911 | #endif | |
912 | *cellp = p; | |
913 | return r; | |
914 | } | |
915 | ||
916 | /* | |
917 | * Very dumb function for adding to the memory reserve list, but | |
918 | * we don't need anything smarter at this point | |
919 | * | |
920 | * XXX Eventually check for collisions. They should NEVER happen. | |
921 | * If problems seem to show up, it would be a good start to track | |
922 | * them down. | |
923 | */ | |
0108d3fe | 924 | static void __init reserve_mem(u64 base, u64 size) |
9b6b563c | 925 | { |
cbbcf340 | 926 | u64 top = base + size; |
9b6b563c PM |
927 | unsigned long cnt = RELOC(mem_reserve_cnt); |
928 | ||
929 | if (size == 0) | |
930 | return; | |
931 | ||
932 | /* We need to always keep one empty entry so that we | |
933 | * have our terminator with "size" set to 0 since we are | |
934 | * dumb and just copy this entire array to the boot params | |
935 | */ | |
936 | base = _ALIGN_DOWN(base, PAGE_SIZE); | |
937 | top = _ALIGN_UP(top, PAGE_SIZE); | |
938 | size = top - base; | |
939 | ||
940 | if (cnt >= (MEM_RESERVE_MAP_SIZE - 1)) | |
941 | prom_panic("Memory reserve map exhausted !\n"); | |
942 | RELOC(mem_reserve_map)[cnt].base = base; | |
943 | RELOC(mem_reserve_map)[cnt].size = size; | |
944 | RELOC(mem_reserve_cnt) = cnt + 1; | |
945 | } | |
946 | ||
947 | /* | |
b3c2ffd5 | 948 | * Initialize memory allocation mechanism, parse "memory" nodes and |
9b6b563c PM |
949 | * obtain that way the top of memory and RMO to setup out local allocator |
950 | */ | |
951 | static void __init prom_init_mem(void) | |
952 | { | |
953 | phandle node; | |
954 | char *path, type[64]; | |
955 | unsigned int plen; | |
956 | cell_t *p, *endp; | |
957 | struct prom_t *_prom = &RELOC(prom); | |
958 | u32 rac, rsc; | |
959 | ||
960 | /* | |
961 | * We iterate the memory nodes to find | |
962 | * 1) top of RMO (first node) | |
963 | * 2) top of memory | |
964 | */ | |
965 | rac = 2; | |
966 | prom_getprop(_prom->root, "#address-cells", &rac, sizeof(rac)); | |
967 | rsc = 1; | |
968 | prom_getprop(_prom->root, "#size-cells", &rsc, sizeof(rsc)); | |
969 | prom_debug("root_addr_cells: %x\n", (unsigned long) rac); | |
970 | prom_debug("root_size_cells: %x\n", (unsigned long) rsc); | |
971 | ||
972 | prom_debug("scanning memory:\n"); | |
973 | path = RELOC(prom_scratch); | |
974 | ||
975 | for (node = 0; prom_next_node(&node); ) { | |
976 | type[0] = 0; | |
977 | prom_getprop(node, "device_type", type, sizeof(type)); | |
978 | ||
c4988820 PM |
979 | if (type[0] == 0) { |
980 | /* | |
981 | * CHRP Longtrail machines have no device_type | |
982 | * on the memory node, so check the name instead... | |
983 | */ | |
984 | prom_getprop(node, "name", type, sizeof(type)); | |
985 | } | |
9b6b563c PM |
986 | if (strcmp(type, RELOC("memory"))) |
987 | continue; | |
c4988820 | 988 | |
9b6b563c PM |
989 | plen = prom_getprop(node, "reg", RELOC(regbuf), sizeof(regbuf)); |
990 | if (plen > sizeof(regbuf)) { | |
991 | prom_printf("memory node too large for buffer !\n"); | |
992 | plen = sizeof(regbuf); | |
993 | } | |
994 | p = RELOC(regbuf); | |
995 | endp = p + (plen / sizeof(cell_t)); | |
996 | ||
997 | #ifdef DEBUG_PROM | |
998 | memset(path, 0, PROM_SCRATCH_SIZE); | |
999 | call_prom("package-to-path", 3, 1, node, path, PROM_SCRATCH_SIZE-1); | |
1000 | prom_debug(" node %s :\n", path); | |
1001 | #endif /* DEBUG_PROM */ | |
1002 | ||
1003 | while ((endp - p) >= (rac + rsc)) { | |
1004 | unsigned long base, size; | |
1005 | ||
1006 | base = prom_next_cell(rac, &p); | |
1007 | size = prom_next_cell(rsc, &p); | |
1008 | ||
1009 | if (size == 0) | |
1010 | continue; | |
1011 | prom_debug(" %x %x\n", base, size); | |
ab1b55e2 | 1012 | if (base == 0 && (RELOC(of_platform) & PLATFORM_LPAR)) |
9b6b563c PM |
1013 | RELOC(rmo_top) = size; |
1014 | if ((base + size) > RELOC(ram_top)) | |
1015 | RELOC(ram_top) = base + size; | |
1016 | } | |
1017 | } | |
1018 | ||
1019 | RELOC(alloc_bottom) = PAGE_ALIGN((unsigned long)&RELOC(_end) + 0x4000); | |
1020 | ||
1021 | /* Check if we have an initrd after the kernel, if we do move our bottom | |
1022 | * point to after it | |
1023 | */ | |
1024 | if (RELOC(prom_initrd_start)) { | |
1025 | if (RELOC(prom_initrd_end) > RELOC(alloc_bottom)) | |
1026 | RELOC(alloc_bottom) = PAGE_ALIGN(RELOC(prom_initrd_end)); | |
1027 | } | |
1028 | ||
9b6b563c PM |
1029 | /* |
1030 | * Setup our top alloc point, that is top of RMO or top of | |
1031 | * segment 0 when running non-LPAR. | |
1032 | * Some RS64 machines have buggy firmware where claims up at | |
1033 | * 1GB fail. Cap at 768MB as a workaround. | |
1034 | * Since 768MB is plenty of room, and we need to cap to something | |
1035 | * reasonable on 32-bit, cap at 768MB on all machines. | |
1036 | */ | |
1037 | if (!RELOC(rmo_top)) | |
1038 | RELOC(rmo_top) = RELOC(ram_top); | |
1039 | RELOC(rmo_top) = min(0x30000000ul, RELOC(rmo_top)); | |
1040 | RELOC(alloc_top) = RELOC(rmo_top); | |
2babf5c2 | 1041 | RELOC(alloc_top_high) = RELOC(ram_top); |
9b6b563c PM |
1042 | |
1043 | prom_printf("memory layout at init:\n"); | |
9b6b563c PM |
1044 | prom_printf(" alloc_bottom : %x\n", RELOC(alloc_bottom)); |
1045 | prom_printf(" alloc_top : %x\n", RELOC(alloc_top)); | |
1046 | prom_printf(" alloc_top_hi : %x\n", RELOC(alloc_top_high)); | |
1047 | prom_printf(" rmo_top : %x\n", RELOC(rmo_top)); | |
1048 | prom_printf(" ram_top : %x\n", RELOC(ram_top)); | |
1049 | } | |
1050 | ||
1051 | ||
1052 | /* | |
1053 | * Allocate room for and instantiate RTAS | |
1054 | */ | |
1055 | static void __init prom_instantiate_rtas(void) | |
1056 | { | |
1057 | phandle rtas_node; | |
1058 | ihandle rtas_inst; | |
1059 | u32 base, entry = 0; | |
1060 | u32 size = 0; | |
1061 | ||
1062 | prom_debug("prom_instantiate_rtas: start...\n"); | |
1063 | ||
1064 | rtas_node = call_prom("finddevice", 1, 1, ADDR("/rtas")); | |
1065 | prom_debug("rtas_node: %x\n", rtas_node); | |
1066 | if (!PHANDLE_VALID(rtas_node)) | |
1067 | return; | |
1068 | ||
1069 | prom_getprop(rtas_node, "rtas-size", &size, sizeof(size)); | |
1070 | if (size == 0) | |
1071 | return; | |
1072 | ||
1073 | base = alloc_down(size, PAGE_SIZE, 0); | |
1074 | if (base == 0) { | |
1075 | prom_printf("RTAS allocation failed !\n"); | |
1076 | return; | |
1077 | } | |
1078 | ||
1079 | rtas_inst = call_prom("open", 1, 1, ADDR("/rtas")); | |
1080 | if (!IHANDLE_VALID(rtas_inst)) { | |
a23414be | 1081 | prom_printf("opening rtas package failed (%x)\n", rtas_inst); |
9b6b563c PM |
1082 | return; |
1083 | } | |
1084 | ||
1f8737aa | 1085 | prom_printf("instantiating rtas at 0x%x...", base); |
9b6b563c PM |
1086 | |
1087 | if (call_prom_ret("call-method", 3, 2, &entry, | |
1088 | ADDR("instantiate-rtas"), | |
a23414be | 1089 | rtas_inst, base) != 0 |
9b6b563c PM |
1090 | || entry == 0) { |
1091 | prom_printf(" failed\n"); | |
1092 | return; | |
1093 | } | |
1094 | prom_printf(" done\n"); | |
1095 | ||
1096 | reserve_mem(base, size); | |
1097 | ||
a23414be PM |
1098 | prom_setprop(rtas_node, "/rtas", "linux,rtas-base", |
1099 | &base, sizeof(base)); | |
1100 | prom_setprop(rtas_node, "/rtas", "linux,rtas-entry", | |
1101 | &entry, sizeof(entry)); | |
9b6b563c PM |
1102 | |
1103 | prom_debug("rtas base = 0x%x\n", base); | |
1104 | prom_debug("rtas entry = 0x%x\n", entry); | |
1105 | prom_debug("rtas size = 0x%x\n", (long)size); | |
1106 | ||
1107 | prom_debug("prom_instantiate_rtas: end...\n"); | |
1108 | } | |
1109 | ||
1110 | #ifdef CONFIG_PPC64 | |
1111 | /* | |
1112 | * Allocate room for and initialize TCE tables | |
1113 | */ | |
1114 | static void __init prom_initialize_tce_table(void) | |
1115 | { | |
1116 | phandle node; | |
1117 | ihandle phb_node; | |
1118 | char compatible[64], type[64], model[64]; | |
1119 | char *path = RELOC(prom_scratch); | |
1120 | u64 base, align; | |
1121 | u32 minalign, minsize; | |
1122 | u64 tce_entry, *tce_entryp; | |
1123 | u64 local_alloc_top, local_alloc_bottom; | |
1124 | u64 i; | |
1125 | ||
165785e5 | 1126 | if (RELOC(prom_iommu_off)) |
9b6b563c PM |
1127 | return; |
1128 | ||
1129 | prom_debug("starting prom_initialize_tce_table\n"); | |
1130 | ||
1131 | /* Cache current top of allocs so we reserve a single block */ | |
1132 | local_alloc_top = RELOC(alloc_top_high); | |
1133 | local_alloc_bottom = local_alloc_top; | |
1134 | ||
1135 | /* Search all nodes looking for PHBs. */ | |
1136 | for (node = 0; prom_next_node(&node); ) { | |
1137 | compatible[0] = 0; | |
1138 | type[0] = 0; | |
1139 | model[0] = 0; | |
1140 | prom_getprop(node, "compatible", | |
1141 | compatible, sizeof(compatible)); | |
1142 | prom_getprop(node, "device_type", type, sizeof(type)); | |
1143 | prom_getprop(node, "model", model, sizeof(model)); | |
1144 | ||
1145 | if ((type[0] == 0) || (strstr(type, RELOC("pci")) == NULL)) | |
1146 | continue; | |
1147 | ||
e788ff13 | 1148 | /* Keep the old logic intact to avoid regression. */ |
9b6b563c PM |
1149 | if (compatible[0] != 0) { |
1150 | if ((strstr(compatible, RELOC("python")) == NULL) && | |
1151 | (strstr(compatible, RELOC("Speedwagon")) == NULL) && | |
1152 | (strstr(compatible, RELOC("Winnipeg")) == NULL)) | |
1153 | continue; | |
1154 | } else if (model[0] != 0) { | |
1155 | if ((strstr(model, RELOC("ython")) == NULL) && | |
1156 | (strstr(model, RELOC("peedwagon")) == NULL) && | |
1157 | (strstr(model, RELOC("innipeg")) == NULL)) | |
1158 | continue; | |
1159 | } | |
1160 | ||
1161 | if (prom_getprop(node, "tce-table-minalign", &minalign, | |
1162 | sizeof(minalign)) == PROM_ERROR) | |
1163 | minalign = 0; | |
1164 | if (prom_getprop(node, "tce-table-minsize", &minsize, | |
1165 | sizeof(minsize)) == PROM_ERROR) | |
1166 | minsize = 4UL << 20; | |
1167 | ||
1168 | /* | |
1169 | * Even though we read what OF wants, we just set the table | |
1170 | * size to 4 MB. This is enough to map 2GB of PCI DMA space. | |
1171 | * By doing this, we avoid the pitfalls of trying to DMA to | |
1172 | * MMIO space and the DMA alias hole. | |
1173 | * | |
1174 | * On POWER4, firmware sets the TCE region by assuming | |
1175 | * each TCE table is 8MB. Using this memory for anything | |
1176 | * else will impact performance, so we always allocate 8MB. | |
1177 | * Anton | |
1178 | */ | |
1179 | if (__is_processor(PV_POWER4) || __is_processor(PV_POWER4p)) | |
1180 | minsize = 8UL << 20; | |
1181 | else | |
1182 | minsize = 4UL << 20; | |
1183 | ||
1184 | /* Align to the greater of the align or size */ | |
1185 | align = max(minalign, minsize); | |
1186 | base = alloc_down(minsize, align, 1); | |
1187 | if (base == 0) | |
1188 | prom_panic("ERROR, cannot find space for TCE table.\n"); | |
1189 | if (base < local_alloc_bottom) | |
1190 | local_alloc_bottom = base; | |
1191 | ||
9b6b563c | 1192 | /* It seems OF doesn't null-terminate the path :-( */ |
aca71ef8 | 1193 | memset(path, 0, PROM_SCRATCH_SIZE); |
9b6b563c PM |
1194 | /* Call OF to setup the TCE hardware */ |
1195 | if (call_prom("package-to-path", 3, 1, node, | |
1196 | path, PROM_SCRATCH_SIZE-1) == PROM_ERROR) { | |
1197 | prom_printf("package-to-path failed\n"); | |
1198 | } | |
1199 | ||
a23414be PM |
1200 | /* Save away the TCE table attributes for later use. */ |
1201 | prom_setprop(node, path, "linux,tce-base", &base, sizeof(base)); | |
1202 | prom_setprop(node, path, "linux,tce-size", &minsize, sizeof(minsize)); | |
1203 | ||
9b6b563c PM |
1204 | prom_debug("TCE table: %s\n", path); |
1205 | prom_debug("\tnode = 0x%x\n", node); | |
1206 | prom_debug("\tbase = 0x%x\n", base); | |
1207 | prom_debug("\tsize = 0x%x\n", minsize); | |
1208 | ||
1209 | /* Initialize the table to have a one-to-one mapping | |
1210 | * over the allocated size. | |
1211 | */ | |
2b931fb6 | 1212 | tce_entryp = (u64 *)base; |
9b6b563c PM |
1213 | for (i = 0; i < (minsize >> 3) ;tce_entryp++, i++) { |
1214 | tce_entry = (i << PAGE_SHIFT); | |
1215 | tce_entry |= 0x3; | |
1216 | *tce_entryp = tce_entry; | |
1217 | } | |
1218 | ||
1219 | prom_printf("opening PHB %s", path); | |
1220 | phb_node = call_prom("open", 1, 1, path); | |
1221 | if (phb_node == 0) | |
1222 | prom_printf("... failed\n"); | |
1223 | else | |
1224 | prom_printf("... done\n"); | |
1225 | ||
1226 | call_prom("call-method", 6, 0, ADDR("set-64-bit-addressing"), | |
1227 | phb_node, -1, minsize, | |
1228 | (u32) base, (u32) (base >> 32)); | |
1229 | call_prom("close", 1, 0, phb_node); | |
1230 | } | |
1231 | ||
1232 | reserve_mem(local_alloc_bottom, local_alloc_top - local_alloc_bottom); | |
1233 | ||
2babf5c2 ME |
1234 | /* These are only really needed if there is a memory limit in |
1235 | * effect, but we don't know so export them always. */ | |
1236 | RELOC(prom_tce_alloc_start) = local_alloc_bottom; | |
1237 | RELOC(prom_tce_alloc_end) = local_alloc_top; | |
9b6b563c PM |
1238 | |
1239 | /* Flag the first invalid entry */ | |
1240 | prom_debug("ending prom_initialize_tce_table\n"); | |
1241 | } | |
1242 | #endif | |
1243 | ||
1244 | /* | |
1245 | * With CHRP SMP we need to use the OF to start the other processors. | |
1246 | * We can't wait until smp_boot_cpus (the OF is trashed by then) | |
1247 | * so we have to put the processors into a holding pattern controlled | |
1248 | * by the kernel (not OF) before we destroy the OF. | |
1249 | * | |
1250 | * This uses a chunk of low memory, puts some holding pattern | |
1251 | * code there and sends the other processors off to there until | |
1252 | * smp_boot_cpus tells them to do something. The holding pattern | |
1253 | * checks that address until its cpu # is there, when it is that | |
1254 | * cpu jumps to __secondary_start(). smp_boot_cpus() takes care | |
1255 | * of setting those values. | |
1256 | * | |
1257 | * We also use physical address 0x4 here to tell when a cpu | |
1258 | * is in its holding pattern code. | |
1259 | * | |
1260 | * -- Cort | |
1261 | */ | |
bbd0abda PM |
1262 | /* |
1263 | * We want to reference the copy of __secondary_hold_* in the | |
1264 | * 0 - 0x100 address range | |
1265 | */ | |
1266 | #define LOW_ADDR(x) (((unsigned long) &(x)) & 0xff) | |
1267 | ||
9b6b563c PM |
1268 | static void __init prom_hold_cpus(void) |
1269 | { | |
9b6b563c PM |
1270 | unsigned long i; |
1271 | unsigned int reg; | |
1272 | phandle node; | |
1273 | char type[64]; | |
bbd0abda | 1274 | struct prom_t *_prom = &RELOC(prom); |
9b6b563c | 1275 | unsigned long *spinloop |
bbd0abda | 1276 | = (void *) LOW_ADDR(__secondary_hold_spinloop); |
9b6b563c | 1277 | unsigned long *acknowledge |
bbd0abda | 1278 | = (void *) LOW_ADDR(__secondary_hold_acknowledge); |
bbd0abda | 1279 | unsigned long secondary_hold = LOW_ADDR(__secondary_hold); |
9b6b563c PM |
1280 | |
1281 | prom_debug("prom_hold_cpus: start...\n"); | |
1282 | prom_debug(" 1) spinloop = 0x%x\n", (unsigned long)spinloop); | |
1283 | prom_debug(" 1) *spinloop = 0x%x\n", *spinloop); | |
1284 | prom_debug(" 1) acknowledge = 0x%x\n", | |
1285 | (unsigned long)acknowledge); | |
1286 | prom_debug(" 1) *acknowledge = 0x%x\n", *acknowledge); | |
1287 | prom_debug(" 1) secondary_hold = 0x%x\n", secondary_hold); | |
1288 | ||
1289 | /* Set the common spinloop variable, so all of the secondary cpus | |
1290 | * will block when they are awakened from their OF spinloop. | |
1291 | * This must occur for both SMP and non SMP kernels, since OF will | |
1292 | * be trashed when we move the kernel. | |
1293 | */ | |
1294 | *spinloop = 0; | |
1295 | ||
9b6b563c PM |
1296 | /* look for cpus */ |
1297 | for (node = 0; prom_next_node(&node); ) { | |
1298 | type[0] = 0; | |
1299 | prom_getprop(node, "device_type", type, sizeof(type)); | |
1300 | if (strcmp(type, RELOC("cpu")) != 0) | |
1301 | continue; | |
1302 | ||
1303 | /* Skip non-configured cpus. */ | |
1304 | if (prom_getprop(node, "status", type, sizeof(type)) > 0) | |
1305 | if (strcmp(type, RELOC("okay")) != 0) | |
1306 | continue; | |
1307 | ||
1308 | reg = -1; | |
1309 | prom_getprop(node, "reg", ®, sizeof(reg)); | |
1310 | ||
9b6b563c PM |
1311 | prom_debug("cpu hw idx = 0x%x\n", reg); |
1312 | ||
1313 | /* Init the acknowledge var which will be reset by | |
1314 | * the secondary cpu when it awakens from its OF | |
1315 | * spinloop. | |
1316 | */ | |
1317 | *acknowledge = (unsigned long)-1; | |
1318 | ||
7d2f6075 | 1319 | if (reg != _prom->cpu) { |
9b6b563c | 1320 | /* Primary Thread of non-boot cpu */ |
7d2f6075 | 1321 | prom_printf("starting cpu hw idx %x... ", reg); |
9b6b563c PM |
1322 | call_prom("start-cpu", 3, 0, node, |
1323 | secondary_hold, reg); | |
1324 | ||
bbd0abda PM |
1325 | for (i = 0; (i < 100000000) && |
1326 | (*acknowledge == ((unsigned long)-1)); i++ ) | |
9b6b563c PM |
1327 | mb(); |
1328 | ||
bbd0abda | 1329 | if (*acknowledge == reg) |
9b6b563c | 1330 | prom_printf("done\n"); |
bbd0abda | 1331 | else |
9b6b563c | 1332 | prom_printf("failed: %x\n", *acknowledge); |
9b6b563c PM |
1333 | } |
1334 | #ifdef CONFIG_SMP | |
1335 | else | |
7d2f6075 | 1336 | prom_printf("boot cpu hw idx %x\n", reg); |
9b6b563c | 1337 | #endif /* CONFIG_SMP */ |
9b6b563c | 1338 | } |
9b6b563c | 1339 | |
9b6b563c | 1340 | prom_debug("prom_hold_cpus: end...\n"); |
9b6b563c PM |
1341 | } |
1342 | ||
1343 | ||
1344 | static void __init prom_init_client_services(unsigned long pp) | |
1345 | { | |
1346 | struct prom_t *_prom = &RELOC(prom); | |
1347 | ||
1348 | /* Get a handle to the prom entry point before anything else */ | |
1349 | RELOC(prom_entry) = pp; | |
1350 | ||
1351 | /* get a handle for the stdout device */ | |
1352 | _prom->chosen = call_prom("finddevice", 1, 1, ADDR("/chosen")); | |
1353 | if (!PHANDLE_VALID(_prom->chosen)) | |
1354 | prom_panic("cannot find chosen"); /* msg won't be printed :( */ | |
1355 | ||
1356 | /* get device tree root */ | |
1357 | _prom->root = call_prom("finddevice", 1, 1, ADDR("/")); | |
1358 | if (!PHANDLE_VALID(_prom->root)) | |
1359 | prom_panic("cannot find device tree root"); /* msg won't be printed :( */ | |
a575b807 PM |
1360 | |
1361 | _prom->mmumap = 0; | |
1362 | } | |
1363 | ||
1364 | #ifdef CONFIG_PPC32 | |
1365 | /* | |
1366 | * For really old powermacs, we need to map things we claim. | |
1367 | * For that, we need the ihandle of the mmu. | |
a23414be | 1368 | * Also, on the longtrail, we need to work around other bugs. |
a575b807 PM |
1369 | */ |
1370 | static void __init prom_find_mmu(void) | |
1371 | { | |
1372 | struct prom_t *_prom = &RELOC(prom); | |
1373 | phandle oprom; | |
1374 | char version[64]; | |
1375 | ||
1376 | oprom = call_prom("finddevice", 1, 1, ADDR("/openprom")); | |
1377 | if (!PHANDLE_VALID(oprom)) | |
1378 | return; | |
1379 | if (prom_getprop(oprom, "model", version, sizeof(version)) <= 0) | |
1380 | return; | |
1381 | version[sizeof(version) - 1] = 0; | |
a575b807 | 1382 | /* XXX might need to add other versions here */ |
a23414be PM |
1383 | if (strcmp(version, "Open Firmware, 1.0.5") == 0) |
1384 | of_workarounds = OF_WA_CLAIM; | |
1385 | else if (strncmp(version, "FirmWorks,3.", 12) == 0) { | |
1386 | of_workarounds = OF_WA_CLAIM | OF_WA_LONGTRAIL; | |
1387 | call_prom("interpret", 1, 1, "dev /memory 0 to allow-reclaim"); | |
1388 | } else | |
a575b807 | 1389 | return; |
a23414be | 1390 | _prom->memory = call_prom("open", 1, 1, ADDR("/memory")); |
a575b807 PM |
1391 | prom_getprop(_prom->chosen, "mmu", &_prom->mmumap, |
1392 | sizeof(_prom->mmumap)); | |
a23414be PM |
1393 | if (!IHANDLE_VALID(_prom->memory) || !IHANDLE_VALID(_prom->mmumap)) |
1394 | of_workarounds &= ~OF_WA_CLAIM; /* hmmm */ | |
9b6b563c | 1395 | } |
a575b807 PM |
1396 | #else |
1397 | #define prom_find_mmu() | |
1398 | #endif | |
9b6b563c PM |
1399 | |
1400 | static void __init prom_init_stdout(void) | |
1401 | { | |
1402 | struct prom_t *_prom = &RELOC(prom); | |
1403 | char *path = RELOC(of_stdout_device); | |
1404 | char type[16]; | |
1405 | u32 val; | |
1406 | ||
1407 | if (prom_getprop(_prom->chosen, "stdout", &val, sizeof(val)) <= 0) | |
1408 | prom_panic("cannot find stdout"); | |
1409 | ||
1410 | _prom->stdout = val; | |
1411 | ||
1412 | /* Get the full OF pathname of the stdout device */ | |
1413 | memset(path, 0, 256); | |
1414 | call_prom("instance-to-path", 3, 1, _prom->stdout, path, 255); | |
1415 | val = call_prom("instance-to-package", 1, 1, _prom->stdout); | |
a23414be PM |
1416 | prom_setprop(_prom->chosen, "/chosen", "linux,stdout-package", |
1417 | &val, sizeof(val)); | |
9b6b563c | 1418 | prom_printf("OF stdout device is: %s\n", RELOC(of_stdout_device)); |
a23414be PM |
1419 | prom_setprop(_prom->chosen, "/chosen", "linux,stdout-path", |
1420 | path, strlen(path) + 1); | |
9b6b563c PM |
1421 | |
1422 | /* If it's a display, note it */ | |
1423 | memset(type, 0, sizeof(type)); | |
1424 | prom_getprop(val, "device_type", type, sizeof(type)); | |
1425 | if (strcmp(type, RELOC("display")) == 0) | |
a23414be | 1426 | prom_setprop(val, path, "linux,boot-display", NULL, 0); |
9b6b563c PM |
1427 | } |
1428 | ||
1429 | static void __init prom_close_stdin(void) | |
1430 | { | |
1431 | struct prom_t *_prom = &RELOC(prom); | |
1432 | ihandle val; | |
1433 | ||
1434 | if (prom_getprop(_prom->chosen, "stdin", &val, sizeof(val)) > 0) | |
1435 | call_prom("close", 1, 0, val); | |
1436 | } | |
1437 | ||
1438 | static int __init prom_find_machine_type(void) | |
1439 | { | |
1440 | struct prom_t *_prom = &RELOC(prom); | |
1441 | char compat[256]; | |
1442 | int len, i = 0; | |
21fe3301 | 1443 | #ifdef CONFIG_PPC64 |
9b6b563c | 1444 | phandle rtas; |
e8222502 | 1445 | int x; |
21fe3301 | 1446 | #endif |
e8222502 BH |
1447 | |
1448 | /* Look for a PowerMac */ | |
9b6b563c PM |
1449 | len = prom_getprop(_prom->root, "compatible", |
1450 | compat, sizeof(compat)-1); | |
1451 | if (len > 0) { | |
1452 | compat[len] = 0; | |
1453 | while (i < len) { | |
1454 | char *p = &compat[i]; | |
1455 | int sl = strlen(p); | |
1456 | if (sl == 0) | |
1457 | break; | |
1458 | if (strstr(p, RELOC("Power Macintosh")) || | |
a575b807 | 1459 | strstr(p, RELOC("MacRISC"))) |
9b6b563c | 1460 | return PLATFORM_POWERMAC; |
133dda1e AB |
1461 | #ifdef CONFIG_PPC64 |
1462 | /* We must make sure we don't detect the IBM Cell | |
1463 | * blades as pSeries due to some firmware issues, | |
1464 | * so we do it here. | |
1465 | */ | |
1466 | if (strstr(p, RELOC("IBM,CBEA")) || | |
1467 | strstr(p, RELOC("IBM,CPBW-1.0"))) | |
1468 | return PLATFORM_GENERIC; | |
1469 | #endif /* CONFIG_PPC64 */ | |
9b6b563c PM |
1470 | i += sl + 1; |
1471 | } | |
1472 | } | |
1473 | #ifdef CONFIG_PPC64 | |
e8222502 BH |
1474 | /* If not a mac, try to figure out if it's an IBM pSeries or any other |
1475 | * PAPR compliant platform. We assume it is if : | |
1476 | * - /device_type is "chrp" (please, do NOT use that for future | |
1477 | * non-IBM designs ! | |
1478 | * - it has /rtas | |
1479 | */ | |
6f806cee | 1480 | len = prom_getprop(_prom->root, "device_type", |
e8222502 BH |
1481 | compat, sizeof(compat)-1); |
1482 | if (len <= 0) | |
1483 | return PLATFORM_GENERIC; | |
cb6b2eb9 | 1484 | if (strcmp(compat, RELOC("chrp"))) |
e8222502 BH |
1485 | return PLATFORM_GENERIC; |
1486 | ||
9b6b563c PM |
1487 | /* Default to pSeries. We need to know if we are running LPAR */ |
1488 | rtas = call_prom("finddevice", 1, 1, ADDR("/rtas")); | |
e8222502 BH |
1489 | if (!PHANDLE_VALID(rtas)) |
1490 | return PLATFORM_GENERIC; | |
1491 | x = prom_getproplen(rtas, "ibm,hypertas-functions"); | |
1492 | if (x != PROM_ERROR) { | |
4da727ae | 1493 | prom_debug("Hypertas detected, assuming LPAR !\n"); |
e8222502 | 1494 | return PLATFORM_PSERIES_LPAR; |
9b6b563c PM |
1495 | } |
1496 | return PLATFORM_PSERIES; | |
1497 | #else | |
e8222502 | 1498 | return PLATFORM_GENERIC; |
9b6b563c PM |
1499 | #endif |
1500 | } | |
1501 | ||
9b6b563c PM |
1502 | static int __init prom_set_color(ihandle ih, int i, int r, int g, int b) |
1503 | { | |
1504 | return call_prom("call-method", 6, 1, ADDR("color!"), ih, i, b, g, r); | |
1505 | } | |
1506 | ||
1507 | /* | |
1508 | * If we have a display that we don't know how to drive, | |
1509 | * we will want to try to execute OF's open method for it | |
1510 | * later. However, OF will probably fall over if we do that | |
1511 | * we've taken over the MMU. | |
1512 | * So we check whether we will need to open the display, | |
1513 | * and if so, open it now. | |
1514 | */ | |
1515 | static void __init prom_check_displays(void) | |
1516 | { | |
1517 | char type[16], *path; | |
1518 | phandle node; | |
1519 | ihandle ih; | |
1520 | int i; | |
9b6b563c PM |
1521 | |
1522 | static unsigned char default_colors[] = { | |
1523 | 0x00, 0x00, 0x00, | |
1524 | 0x00, 0x00, 0xaa, | |
1525 | 0x00, 0xaa, 0x00, | |
1526 | 0x00, 0xaa, 0xaa, | |
1527 | 0xaa, 0x00, 0x00, | |
1528 | 0xaa, 0x00, 0xaa, | |
1529 | 0xaa, 0xaa, 0x00, | |
1530 | 0xaa, 0xaa, 0xaa, | |
1531 | 0x55, 0x55, 0x55, | |
1532 | 0x55, 0x55, 0xff, | |
1533 | 0x55, 0xff, 0x55, | |
1534 | 0x55, 0xff, 0xff, | |
1535 | 0xff, 0x55, 0x55, | |
1536 | 0xff, 0x55, 0xff, | |
1537 | 0xff, 0xff, 0x55, | |
1538 | 0xff, 0xff, 0xff | |
1539 | }; | |
1540 | const unsigned char *clut; | |
1541 | ||
4da727ae | 1542 | prom_debug("Looking for displays\n"); |
9b6b563c PM |
1543 | for (node = 0; prom_next_node(&node); ) { |
1544 | memset(type, 0, sizeof(type)); | |
1545 | prom_getprop(node, "device_type", type, sizeof(type)); | |
1546 | if (strcmp(type, RELOC("display")) != 0) | |
1547 | continue; | |
1548 | ||
1549 | /* It seems OF doesn't null-terminate the path :-( */ | |
1550 | path = RELOC(prom_scratch); | |
1551 | memset(path, 0, PROM_SCRATCH_SIZE); | |
1552 | ||
1553 | /* | |
1554 | * leave some room at the end of the path for appending extra | |
1555 | * arguments | |
1556 | */ | |
1557 | if (call_prom("package-to-path", 3, 1, node, path, | |
1558 | PROM_SCRATCH_SIZE-10) == PROM_ERROR) | |
1559 | continue; | |
1f8737aa | 1560 | prom_printf("found display : %s, opening... ", path); |
9b6b563c PM |
1561 | |
1562 | ih = call_prom("open", 1, 1, path); | |
1563 | if (ih == 0) { | |
1564 | prom_printf("failed\n"); | |
1565 | continue; | |
1566 | } | |
1567 | ||
1568 | /* Success */ | |
1569 | prom_printf("done\n"); | |
a23414be | 1570 | prom_setprop(node, path, "linux,opened", NULL, 0); |
9b6b563c PM |
1571 | |
1572 | /* Setup a usable color table when the appropriate | |
1573 | * method is available. Should update this to set-colors */ | |
1574 | clut = RELOC(default_colors); | |
1575 | for (i = 0; i < 32; i++, clut += 3) | |
1576 | if (prom_set_color(ih, i, clut[0], clut[1], | |
1577 | clut[2]) != 0) | |
1578 | break; | |
1579 | ||
1580 | #ifdef CONFIG_LOGO_LINUX_CLUT224 | |
1581 | clut = PTRRELOC(RELOC(logo_linux_clut224.clut)); | |
1582 | for (i = 0; i < RELOC(logo_linux_clut224.clutsize); i++, clut += 3) | |
1583 | if (prom_set_color(ih, i + 32, clut[0], clut[1], | |
1584 | clut[2]) != 0) | |
1585 | break; | |
1586 | #endif /* CONFIG_LOGO_LINUX_CLUT224 */ | |
9b6b563c PM |
1587 | } |
1588 | } | |
1589 | ||
1590 | ||
1591 | /* Return (relocated) pointer to this much memory: moves initrd if reqd. */ | |
1592 | static void __init *make_room(unsigned long *mem_start, unsigned long *mem_end, | |
1593 | unsigned long needed, unsigned long align) | |
1594 | { | |
1595 | void *ret; | |
1596 | ||
1597 | *mem_start = _ALIGN(*mem_start, align); | |
1598 | while ((*mem_start + needed) > *mem_end) { | |
1599 | unsigned long room, chunk; | |
1600 | ||
1601 | prom_debug("Chunk exhausted, claiming more at %x...\n", | |
1602 | RELOC(alloc_bottom)); | |
1603 | room = RELOC(alloc_top) - RELOC(alloc_bottom); | |
1604 | if (room > DEVTREE_CHUNK_SIZE) | |
1605 | room = DEVTREE_CHUNK_SIZE; | |
1606 | if (room < PAGE_SIZE) | |
1607 | prom_panic("No memory for flatten_device_tree (no room)"); | |
1608 | chunk = alloc_up(room, 0); | |
1609 | if (chunk == 0) | |
1610 | prom_panic("No memory for flatten_device_tree (claim failed)"); | |
1611 | *mem_end = RELOC(alloc_top); | |
1612 | } | |
1613 | ||
1614 | ret = (void *)*mem_start; | |
1615 | *mem_start += needed; | |
1616 | ||
1617 | return ret; | |
1618 | } | |
1619 | ||
1620 | #define dt_push_token(token, mem_start, mem_end) \ | |
1621 | do { *((u32 *)make_room(mem_start, mem_end, 4, 4)) = token; } while(0) | |
1622 | ||
1623 | static unsigned long __init dt_find_string(char *str) | |
1624 | { | |
1625 | char *s, *os; | |
1626 | ||
1627 | s = os = (char *)RELOC(dt_string_start); | |
1628 | s += 4; | |
1629 | while (s < (char *)RELOC(dt_string_end)) { | |
1630 | if (strcmp(s, str) == 0) | |
1631 | return s - os; | |
1632 | s += strlen(s) + 1; | |
1633 | } | |
1634 | return 0; | |
1635 | } | |
1636 | ||
1637 | /* | |
1638 | * The Open Firmware 1275 specification states properties must be 31 bytes or | |
1639 | * less, however not all firmwares obey this. Make it 64 bytes to be safe. | |
1640 | */ | |
1641 | #define MAX_PROPERTY_NAME 64 | |
1642 | ||
1643 | static void __init scan_dt_build_strings(phandle node, | |
1644 | unsigned long *mem_start, | |
1645 | unsigned long *mem_end) | |
1646 | { | |
1647 | char *prev_name, *namep, *sstart; | |
1648 | unsigned long soff; | |
1649 | phandle child; | |
1650 | ||
1651 | sstart = (char *)RELOC(dt_string_start); | |
1652 | ||
1653 | /* get and store all property names */ | |
1654 | prev_name = RELOC(""); | |
1655 | for (;;) { | |
1656 | /* 64 is max len of name including nul. */ | |
1657 | namep = make_room(mem_start, mem_end, MAX_PROPERTY_NAME, 1); | |
1658 | if (call_prom("nextprop", 3, 1, node, prev_name, namep) != 1) { | |
1659 | /* No more nodes: unwind alloc */ | |
1660 | *mem_start = (unsigned long)namep; | |
1661 | break; | |
1662 | } | |
1663 | ||
1664 | /* skip "name" */ | |
1665 | if (strcmp(namep, RELOC("name")) == 0) { | |
1666 | *mem_start = (unsigned long)namep; | |
1667 | prev_name = RELOC("name"); | |
1668 | continue; | |
1669 | } | |
1670 | /* get/create string entry */ | |
1671 | soff = dt_find_string(namep); | |
1672 | if (soff != 0) { | |
1673 | *mem_start = (unsigned long)namep; | |
1674 | namep = sstart + soff; | |
1675 | } else { | |
1676 | /* Trim off some if we can */ | |
1677 | *mem_start = (unsigned long)namep + strlen(namep) + 1; | |
1678 | RELOC(dt_string_end) = *mem_start; | |
1679 | } | |
1680 | prev_name = namep; | |
1681 | } | |
1682 | ||
1683 | /* do all our children */ | |
1684 | child = call_prom("child", 1, 1, node); | |
1685 | while (child != 0) { | |
1686 | scan_dt_build_strings(child, mem_start, mem_end); | |
1687 | child = call_prom("peer", 1, 1, child); | |
1688 | } | |
1689 | } | |
1690 | ||
1691 | static void __init scan_dt_build_struct(phandle node, unsigned long *mem_start, | |
1692 | unsigned long *mem_end) | |
1693 | { | |
1694 | phandle child; | |
1695 | char *namep, *prev_name, *sstart, *p, *ep, *lp, *path; | |
1696 | unsigned long soff; | |
1697 | unsigned char *valp; | |
1698 | static char pname[MAX_PROPERTY_NAME]; | |
c4988820 | 1699 | int l, room; |
9b6b563c PM |
1700 | |
1701 | dt_push_token(OF_DT_BEGIN_NODE, mem_start, mem_end); | |
1702 | ||
1703 | /* get the node's full name */ | |
1704 | namep = (char *)*mem_start; | |
c4988820 PM |
1705 | room = *mem_end - *mem_start; |
1706 | if (room > 255) | |
1707 | room = 255; | |
1708 | l = call_prom("package-to-path", 3, 1, node, namep, room); | |
9b6b563c PM |
1709 | if (l >= 0) { |
1710 | /* Didn't fit? Get more room. */ | |
c4988820 PM |
1711 | if (l >= room) { |
1712 | if (l >= *mem_end - *mem_start) | |
1713 | namep = make_room(mem_start, mem_end, l+1, 1); | |
9b6b563c PM |
1714 | call_prom("package-to-path", 3, 1, node, namep, l); |
1715 | } | |
1716 | namep[l] = '\0'; | |
1717 | ||
1718 | /* Fixup an Apple bug where they have bogus \0 chars in the | |
a575b807 PM |
1719 | * middle of the path in some properties, and extract |
1720 | * the unit name (everything after the last '/'). | |
9b6b563c | 1721 | */ |
a575b807 | 1722 | for (lp = p = namep, ep = namep + l; p < ep; p++) { |
9b6b563c | 1723 | if (*p == '/') |
a575b807 PM |
1724 | lp = namep; |
1725 | else if (*p != 0) | |
1726 | *lp++ = *p; | |
1727 | } | |
1728 | *lp = 0; | |
1729 | *mem_start = _ALIGN((unsigned long)lp + 1, 4); | |
9b6b563c PM |
1730 | } |
1731 | ||
1732 | /* get it again for debugging */ | |
1733 | path = RELOC(prom_scratch); | |
1734 | memset(path, 0, PROM_SCRATCH_SIZE); | |
1735 | call_prom("package-to-path", 3, 1, node, path, PROM_SCRATCH_SIZE-1); | |
1736 | ||
1737 | /* get and store all properties */ | |
1738 | prev_name = RELOC(""); | |
1739 | sstart = (char *)RELOC(dt_string_start); | |
1740 | for (;;) { | |
1741 | if (call_prom("nextprop", 3, 1, node, prev_name, | |
1742 | RELOC(pname)) != 1) | |
1743 | break; | |
1744 | ||
1745 | /* skip "name" */ | |
1746 | if (strcmp(RELOC(pname), RELOC("name")) == 0) { | |
1747 | prev_name = RELOC("name"); | |
1748 | continue; | |
1749 | } | |
1750 | ||
1751 | /* find string offset */ | |
1752 | soff = dt_find_string(RELOC(pname)); | |
1753 | if (soff == 0) { | |
1754 | prom_printf("WARNING: Can't find string index for" | |
1755 | " <%s>, node %s\n", RELOC(pname), path); | |
1756 | break; | |
1757 | } | |
1758 | prev_name = sstart + soff; | |
1759 | ||
1760 | /* get length */ | |
1761 | l = call_prom("getproplen", 2, 1, node, RELOC(pname)); | |
1762 | ||
1763 | /* sanity checks */ | |
1764 | if (l == PROM_ERROR) | |
1765 | continue; | |
1766 | if (l > MAX_PROPERTY_LENGTH) { | |
1767 | prom_printf("WARNING: ignoring large property "); | |
1768 | /* It seems OF doesn't null-terminate the path :-( */ | |
1769 | prom_printf("[%s] ", path); | |
1770 | prom_printf("%s length 0x%x\n", RELOC(pname), l); | |
1771 | continue; | |
1772 | } | |
1773 | ||
1774 | /* push property head */ | |
1775 | dt_push_token(OF_DT_PROP, mem_start, mem_end); | |
1776 | dt_push_token(l, mem_start, mem_end); | |
1777 | dt_push_token(soff, mem_start, mem_end); | |
1778 | ||
1779 | /* push property content */ | |
1780 | valp = make_room(mem_start, mem_end, l, 4); | |
1781 | call_prom("getprop", 4, 1, node, RELOC(pname), valp, l); | |
1782 | *mem_start = _ALIGN(*mem_start, 4); | |
1783 | } | |
1784 | ||
1785 | /* Add a "linux,phandle" property. */ | |
1786 | soff = dt_find_string(RELOC("linux,phandle")); | |
1787 | if (soff == 0) | |
1788 | prom_printf("WARNING: Can't find string index for" | |
1789 | " <linux-phandle> node %s\n", path); | |
1790 | else { | |
1791 | dt_push_token(OF_DT_PROP, mem_start, mem_end); | |
1792 | dt_push_token(4, mem_start, mem_end); | |
1793 | dt_push_token(soff, mem_start, mem_end); | |
1794 | valp = make_room(mem_start, mem_end, 4, 4); | |
1795 | *(u32 *)valp = node; | |
1796 | } | |
1797 | ||
1798 | /* do all our children */ | |
1799 | child = call_prom("child", 1, 1, node); | |
1800 | while (child != 0) { | |
1801 | scan_dt_build_struct(child, mem_start, mem_end); | |
1802 | child = call_prom("peer", 1, 1, child); | |
1803 | } | |
1804 | ||
1805 | dt_push_token(OF_DT_END_NODE, mem_start, mem_end); | |
1806 | } | |
1807 | ||
1808 | static void __init flatten_device_tree(void) | |
1809 | { | |
1810 | phandle root; | |
1811 | unsigned long mem_start, mem_end, room; | |
1812 | struct boot_param_header *hdr; | |
1813 | struct prom_t *_prom = &RELOC(prom); | |
1814 | char *namep; | |
1815 | u64 *rsvmap; | |
1816 | ||
1817 | /* | |
1818 | * Check how much room we have between alloc top & bottom (+/- a | |
1819 | * few pages), crop to 4Mb, as this is our "chuck" size | |
1820 | */ | |
1821 | room = RELOC(alloc_top) - RELOC(alloc_bottom) - 0x4000; | |
1822 | if (room > DEVTREE_CHUNK_SIZE) | |
1823 | room = DEVTREE_CHUNK_SIZE; | |
1824 | prom_debug("starting device tree allocs at %x\n", RELOC(alloc_bottom)); | |
1825 | ||
1826 | /* Now try to claim that */ | |
1827 | mem_start = (unsigned long)alloc_up(room, PAGE_SIZE); | |
1828 | if (mem_start == 0) | |
1829 | prom_panic("Can't allocate initial device-tree chunk\n"); | |
1830 | mem_end = RELOC(alloc_top); | |
1831 | ||
1832 | /* Get root of tree */ | |
1833 | root = call_prom("peer", 1, 1, (phandle)0); | |
1834 | if (root == (phandle)0) | |
1835 | prom_panic ("couldn't get device tree root\n"); | |
1836 | ||
1837 | /* Build header and make room for mem rsv map */ | |
1838 | mem_start = _ALIGN(mem_start, 4); | |
1839 | hdr = make_room(&mem_start, &mem_end, | |
1840 | sizeof(struct boot_param_header), 4); | |
1841 | RELOC(dt_header_start) = (unsigned long)hdr; | |
1842 | rsvmap = make_room(&mem_start, &mem_end, sizeof(mem_reserve_map), 8); | |
1843 | ||
1844 | /* Start of strings */ | |
1845 | mem_start = PAGE_ALIGN(mem_start); | |
1846 | RELOC(dt_string_start) = mem_start; | |
1847 | mem_start += 4; /* hole */ | |
1848 | ||
1849 | /* Add "linux,phandle" in there, we'll need it */ | |
1850 | namep = make_room(&mem_start, &mem_end, 16, 1); | |
1851 | strcpy(namep, RELOC("linux,phandle")); | |
1852 | mem_start = (unsigned long)namep + strlen(namep) + 1; | |
1853 | ||
1854 | /* Build string array */ | |
1855 | prom_printf("Building dt strings...\n"); | |
1856 | scan_dt_build_strings(root, &mem_start, &mem_end); | |
1857 | RELOC(dt_string_end) = mem_start; | |
1858 | ||
1859 | /* Build structure */ | |
1860 | mem_start = PAGE_ALIGN(mem_start); | |
1861 | RELOC(dt_struct_start) = mem_start; | |
1862 | prom_printf("Building dt structure...\n"); | |
1863 | scan_dt_build_struct(root, &mem_start, &mem_end); | |
1864 | dt_push_token(OF_DT_END, &mem_start, &mem_end); | |
1865 | RELOC(dt_struct_end) = PAGE_ALIGN(mem_start); | |
1866 | ||
1867 | /* Finish header */ | |
1868 | hdr->boot_cpuid_phys = _prom->cpu; | |
1869 | hdr->magic = OF_DT_HEADER; | |
1870 | hdr->totalsize = RELOC(dt_struct_end) - RELOC(dt_header_start); | |
1871 | hdr->off_dt_struct = RELOC(dt_struct_start) - RELOC(dt_header_start); | |
1872 | hdr->off_dt_strings = RELOC(dt_string_start) - RELOC(dt_header_start); | |
1873 | hdr->dt_strings_size = RELOC(dt_string_end) - RELOC(dt_string_start); | |
1874 | hdr->off_mem_rsvmap = ((unsigned long)rsvmap) - RELOC(dt_header_start); | |
1875 | hdr->version = OF_DT_VERSION; | |
1876 | /* Version 16 is not backward compatible */ | |
1877 | hdr->last_comp_version = 0x10; | |
1878 | ||
4d1f3f25 | 1879 | /* Copy the reserve map in */ |
9b6b563c PM |
1880 | memcpy(rsvmap, RELOC(mem_reserve_map), sizeof(mem_reserve_map)); |
1881 | ||
1882 | #ifdef DEBUG_PROM | |
1883 | { | |
1884 | int i; | |
1885 | prom_printf("reserved memory map:\n"); | |
1886 | for (i = 0; i < RELOC(mem_reserve_cnt); i++) | |
1887 | prom_printf(" %x - %x\n", | |
1888 | RELOC(mem_reserve_map)[i].base, | |
1889 | RELOC(mem_reserve_map)[i].size); | |
1890 | } | |
1891 | #endif | |
4d1f3f25 JX |
1892 | /* Bump mem_reserve_cnt to cause further reservations to fail |
1893 | * since it's too late. | |
1894 | */ | |
9b6b563c PM |
1895 | RELOC(mem_reserve_cnt) = MEM_RESERVE_MAP_SIZE; |
1896 | ||
1897 | prom_printf("Device tree strings 0x%x -> 0x%x\n", | |
1898 | RELOC(dt_string_start), RELOC(dt_string_end)); | |
1899 | prom_printf("Device tree struct 0x%x -> 0x%x\n", | |
1900 | RELOC(dt_struct_start), RELOC(dt_struct_end)); | |
1901 | ||
1902 | } | |
1903 | ||
54f4ee18 HB |
1904 | #ifdef CONFIG_PPC_MAPLE |
1905 | /* PIBS Version 1.05.0000 04/26/2005 has an incorrect /ht/isa/ranges property. | |
1906 | * The values are bad, and it doesn't even have the right number of cells. */ | |
1907 | static void __init fixup_device_tree_maple(void) | |
9b6b563c | 1908 | { |
54f4ee18 | 1909 | phandle isa; |
980a6513 | 1910 | u32 rloc = 0x01002000; /* IO space; PCI device = 4 */ |
54f4ee18 | 1911 | u32 isa_ranges[6]; |
980a6513 BH |
1912 | char *name; |
1913 | ||
1914 | name = "/ht@0/isa@4"; | |
1915 | isa = call_prom("finddevice", 1, 1, ADDR(name)); | |
1916 | if (!PHANDLE_VALID(isa)) { | |
1917 | name = "/ht@0/isa@6"; | |
1918 | isa = call_prom("finddevice", 1, 1, ADDR(name)); | |
1919 | rloc = 0x01003000; /* IO space; PCI device = 6 */ | |
1920 | } | |
54f4ee18 HB |
1921 | if (!PHANDLE_VALID(isa)) |
1922 | return; | |
1923 | ||
980a6513 BH |
1924 | if (prom_getproplen(isa, "ranges") != 12) |
1925 | return; | |
54f4ee18 HB |
1926 | if (prom_getprop(isa, "ranges", isa_ranges, sizeof(isa_ranges)) |
1927 | == PROM_ERROR) | |
1928 | return; | |
1929 | ||
1930 | if (isa_ranges[0] != 0x1 || | |
1931 | isa_ranges[1] != 0xf4000000 || | |
1932 | isa_ranges[2] != 0x00010000) | |
1933 | return; | |
1934 | ||
980a6513 | 1935 | prom_printf("Fixing up bogus ISA range on Maple/Apache...\n"); |
54f4ee18 HB |
1936 | |
1937 | isa_ranges[0] = 0x1; | |
1938 | isa_ranges[1] = 0x0; | |
980a6513 | 1939 | isa_ranges[2] = rloc; |
54f4ee18 HB |
1940 | isa_ranges[3] = 0x0; |
1941 | isa_ranges[4] = 0x0; | |
1942 | isa_ranges[5] = 0x00010000; | |
980a6513 | 1943 | prom_setprop(isa, name, "ranges", |
54f4ee18 HB |
1944 | isa_ranges, sizeof(isa_ranges)); |
1945 | } | |
8f101a05 HC |
1946 | |
1947 | #define CPC925_MC_START 0xf8000000 | |
1948 | #define CPC925_MC_LENGTH 0x1000000 | |
1949 | /* The values for memory-controller don't have right number of cells */ | |
1950 | static void __init fixup_device_tree_maple_memory_controller(void) | |
1951 | { | |
1952 | phandle mc; | |
1953 | u32 mc_reg[4]; | |
1954 | char *name = "/hostbridge@f8000000"; | |
1955 | struct prom_t *_prom = &RELOC(prom); | |
1956 | u32 ac, sc; | |
1957 | ||
1958 | mc = call_prom("finddevice", 1, 1, ADDR(name)); | |
1959 | if (!PHANDLE_VALID(mc)) | |
1960 | return; | |
1961 | ||
1962 | if (prom_getproplen(mc, "reg") != 8) | |
1963 | return; | |
1964 | ||
1965 | prom_getprop(_prom->root, "#address-cells", &ac, sizeof(ac)); | |
1966 | prom_getprop(_prom->root, "#size-cells", &sc, sizeof(sc)); | |
1967 | if ((ac != 2) || (sc != 2)) | |
1968 | return; | |
1969 | ||
1970 | if (prom_getprop(mc, "reg", mc_reg, sizeof(mc_reg)) == PROM_ERROR) | |
1971 | return; | |
1972 | ||
1973 | if (mc_reg[0] != CPC925_MC_START || mc_reg[1] != CPC925_MC_LENGTH) | |
1974 | return; | |
1975 | ||
1976 | prom_printf("Fixing up bogus hostbridge on Maple...\n"); | |
1977 | ||
1978 | mc_reg[0] = 0x0; | |
1979 | mc_reg[1] = CPC925_MC_START; | |
1980 | mc_reg[2] = 0x0; | |
1981 | mc_reg[3] = CPC925_MC_LENGTH; | |
1982 | prom_setprop(mc, name, "reg", mc_reg, sizeof(mc_reg)); | |
1983 | } | |
54f4ee18 HB |
1984 | #else |
1985 | #define fixup_device_tree_maple() | |
8f101a05 | 1986 | #define fixup_device_tree_maple_memory_controller() |
54f4ee18 HB |
1987 | #endif |
1988 | ||
e8c0acf9 | 1989 | #ifdef CONFIG_PPC_CHRP |
e4805922 OH |
1990 | /* |
1991 | * Pegasos and BriQ lacks the "ranges" property in the isa node | |
1992 | * Pegasos needs decimal IRQ 14/15, not hexadecimal | |
556ecf9b | 1993 | * Pegasos has the IDE configured in legacy mode, but advertised as native |
e4805922 | 1994 | */ |
e8c0acf9 BH |
1995 | static void __init fixup_device_tree_chrp(void) |
1996 | { | |
e4805922 OH |
1997 | phandle ph; |
1998 | u32 prop[6]; | |
26c5032e | 1999 | u32 rloc = 0x01006000; /* IO space; PCI device = 12 */ |
e8c0acf9 BH |
2000 | char *name; |
2001 | int rc; | |
2002 | ||
2003 | name = "/pci@80000000/isa@c"; | |
e4805922 OH |
2004 | ph = call_prom("finddevice", 1, 1, ADDR(name)); |
2005 | if (!PHANDLE_VALID(ph)) { | |
26c5032e | 2006 | name = "/pci@ff500000/isa@6"; |
e4805922 | 2007 | ph = call_prom("finddevice", 1, 1, ADDR(name)); |
26c5032e BH |
2008 | rloc = 0x01003000; /* IO space; PCI device = 6 */ |
2009 | } | |
e4805922 OH |
2010 | if (PHANDLE_VALID(ph)) { |
2011 | rc = prom_getproplen(ph, "ranges"); | |
2012 | if (rc == 0 || rc == PROM_ERROR) { | |
2013 | prom_printf("Fixing up missing ISA range on Pegasos...\n"); | |
2014 | ||
2015 | prop[0] = 0x1; | |
2016 | prop[1] = 0x0; | |
2017 | prop[2] = rloc; | |
2018 | prop[3] = 0x0; | |
2019 | prop[4] = 0x0; | |
2020 | prop[5] = 0x00010000; | |
2021 | prom_setprop(ph, name, "ranges", prop, sizeof(prop)); | |
2022 | } | |
2023 | } | |
e8c0acf9 | 2024 | |
e4805922 OH |
2025 | name = "/pci@80000000/ide@C,1"; |
2026 | ph = call_prom("finddevice", 1, 1, ADDR(name)); | |
2027 | if (PHANDLE_VALID(ph)) { | |
2028 | prom_printf("Fixing up IDE interrupt on Pegasos...\n"); | |
2029 | prop[0] = 14; | |
2030 | prop[1] = 0x0; | |
556ecf9b OH |
2031 | prom_setprop(ph, name, "interrupts", prop, 2*sizeof(u32)); |
2032 | prom_printf("Fixing up IDE class-code on Pegasos...\n"); | |
2033 | rc = prom_getprop(ph, "class-code", prop, sizeof(u32)); | |
2034 | if (rc == sizeof(u32)) { | |
2035 | prop[0] &= ~0x5; | |
2036 | prom_setprop(ph, name, "class-code", prop, sizeof(u32)); | |
2037 | } | |
e4805922 | 2038 | } |
e8c0acf9 BH |
2039 | } |
2040 | #else | |
2041 | #define fixup_device_tree_chrp() | |
2042 | #endif | |
2043 | ||
9b6b563c | 2044 | #if defined(CONFIG_PPC64) && defined(CONFIG_PPC_PMAC) |
54f4ee18 HB |
2045 | static void __init fixup_device_tree_pmac(void) |
2046 | { | |
9b6b563c PM |
2047 | phandle u3, i2c, mpic; |
2048 | u32 u3_rev; | |
2049 | u32 interrupts[2]; | |
2050 | u32 parent; | |
2051 | ||
2052 | /* Some G5s have a missing interrupt definition, fix it up here */ | |
2053 | u3 = call_prom("finddevice", 1, 1, ADDR("/u3@0,f8000000")); | |
2054 | if (!PHANDLE_VALID(u3)) | |
2055 | return; | |
2056 | i2c = call_prom("finddevice", 1, 1, ADDR("/u3@0,f8000000/i2c@f8001000")); | |
2057 | if (!PHANDLE_VALID(i2c)) | |
2058 | return; | |
2059 | mpic = call_prom("finddevice", 1, 1, ADDR("/u3@0,f8000000/mpic@f8040000")); | |
2060 | if (!PHANDLE_VALID(mpic)) | |
2061 | return; | |
2062 | ||
2063 | /* check if proper rev of u3 */ | |
2064 | if (prom_getprop(u3, "device-rev", &u3_rev, sizeof(u3_rev)) | |
2065 | == PROM_ERROR) | |
2066 | return; | |
7d49697e | 2067 | if (u3_rev < 0x35 || u3_rev > 0x39) |
9b6b563c PM |
2068 | return; |
2069 | /* does it need fixup ? */ | |
2070 | if (prom_getproplen(i2c, "interrupts") > 0) | |
2071 | return; | |
2072 | ||
2073 | prom_printf("fixing up bogus interrupts for u3 i2c...\n"); | |
2074 | ||
2075 | /* interrupt on this revision of u3 is number 0 and level */ | |
2076 | interrupts[0] = 0; | |
2077 | interrupts[1] = 1; | |
a23414be PM |
2078 | prom_setprop(i2c, "/u3@0,f8000000/i2c@f8001000", "interrupts", |
2079 | &interrupts, sizeof(interrupts)); | |
9b6b563c | 2080 | parent = (u32)mpic; |
a23414be PM |
2081 | prom_setprop(i2c, "/u3@0,f8000000/i2c@f8001000", "interrupt-parent", |
2082 | &parent, sizeof(parent)); | |
9b6b563c | 2083 | } |
54f4ee18 HB |
2084 | #else |
2085 | #define fixup_device_tree_pmac() | |
2086 | #endif | |
9b6b563c | 2087 | |
88fd2a9d | 2088 | #ifdef CONFIG_PPC_EFIKA |
94d2dde7 GL |
2089 | /* |
2090 | * The MPC5200 FEC driver requires an phy-handle property to tell it how | |
2091 | * to talk to the phy. If the phy-handle property is missing, then this | |
2092 | * function is called to add the appropriate nodes and link it to the | |
2093 | * ethernet node. | |
2094 | */ | |
2095 | static void __init fixup_device_tree_efika_add_phy(void) | |
88fd2a9d | 2096 | { |
88fd2a9d SM |
2097 | u32 node; |
2098 | char prop[64]; | |
94d2dde7 | 2099 | int rv; |
88fd2a9d | 2100 | |
94d2dde7 GL |
2101 | /* Check if /builtin/ethernet exists - bail if it doesn't */ |
2102 | node = call_prom("finddevice", 1, 1, ADDR("/builtin/ethernet")); | |
88fd2a9d SM |
2103 | if (!PHANDLE_VALID(node)) |
2104 | return; | |
2105 | ||
94d2dde7 GL |
2106 | /* Check if the phy-handle property exists - bail if it does */ |
2107 | rv = prom_getprop(node, "phy-handle", prop, sizeof(prop)); | |
2108 | if (!rv) | |
88fd2a9d SM |
2109 | return; |
2110 | ||
94d2dde7 GL |
2111 | /* |
2112 | * At this point the ethernet device doesn't have a phy described. | |
2113 | * Now we need to add the missing phy node and linkage | |
2114 | */ | |
6f4347c9 | 2115 | |
94d2dde7 | 2116 | /* Check for an MDIO bus node - if missing then create one */ |
6f4347c9 OH |
2117 | node = call_prom("finddevice", 1, 1, ADDR("/builtin/mdio")); |
2118 | if (!PHANDLE_VALID(node)) { | |
2119 | prom_printf("Adding Ethernet MDIO node\n"); | |
2120 | call_prom("interpret", 1, 1, | |
2121 | " s\" /builtin\" find-device" | |
2122 | " new-device" | |
2123 | " 1 encode-int s\" #address-cells\" property" | |
2124 | " 0 encode-int s\" #size-cells\" property" | |
94d2dde7 GL |
2125 | " s\" mdio\" device-name" |
2126 | " s\" fsl,mpc5200b-mdio\" encode-string" | |
6f4347c9 OH |
2127 | " s\" compatible\" property" |
2128 | " 0xf0003000 0x400 reg" | |
2129 | " 0x2 encode-int" | |
2130 | " 0x5 encode-int encode+" | |
2131 | " 0x3 encode-int encode+" | |
2132 | " s\" interrupts\" property" | |
2133 | " finish-device"); | |
2134 | }; | |
2135 | ||
94d2dde7 GL |
2136 | /* Check for a PHY device node - if missing then create one and |
2137 | * give it's phandle to the ethernet node */ | |
2138 | node = call_prom("finddevice", 1, 1, | |
2139 | ADDR("/builtin/mdio/ethernet-phy")); | |
6f4347c9 OH |
2140 | if (!PHANDLE_VALID(node)) { |
2141 | prom_printf("Adding Ethernet PHY node\n"); | |
2142 | call_prom("interpret", 1, 1, | |
2143 | " s\" /builtin/mdio\" find-device" | |
2144 | " new-device" | |
2145 | " s\" ethernet-phy\" device-name" | |
2146 | " 0x10 encode-int s\" reg\" property" | |
2147 | " my-self" | |
2148 | " ihandle>phandle" | |
2149 | " finish-device" | |
2150 | " s\" /builtin/ethernet\" find-device" | |
2151 | " encode-int" | |
2152 | " s\" phy-handle\" property" | |
2153 | " device-end"); | |
2154 | } | |
94d2dde7 GL |
2155 | } |
2156 | ||
2157 | static void __init fixup_device_tree_efika(void) | |
2158 | { | |
2159 | int sound_irq[3] = { 2, 2, 0 }; | |
2160 | int bcomm_irq[3*16] = { 3,0,0, 3,1,0, 3,2,0, 3,3,0, | |
2161 | 3,4,0, 3,5,0, 3,6,0, 3,7,0, | |
2162 | 3,8,0, 3,9,0, 3,10,0, 3,11,0, | |
2163 | 3,12,0, 3,13,0, 3,14,0, 3,15,0 }; | |
2164 | u32 node; | |
2165 | char prop[64]; | |
2166 | int rv, len; | |
2167 | ||
2168 | /* Check if we're really running on a EFIKA */ | |
2169 | node = call_prom("finddevice", 1, 1, ADDR("/")); | |
2170 | if (!PHANDLE_VALID(node)) | |
2171 | return; | |
2172 | ||
2173 | rv = prom_getprop(node, "model", prop, sizeof(prop)); | |
2174 | if (rv == PROM_ERROR) | |
2175 | return; | |
2176 | if (strcmp(prop, "EFIKA5K2")) | |
2177 | return; | |
2178 | ||
2179 | prom_printf("Applying EFIKA device tree fixups\n"); | |
2180 | ||
2181 | /* Claiming to be 'chrp' is death */ | |
2182 | node = call_prom("finddevice", 1, 1, ADDR("/")); | |
2183 | rv = prom_getprop(node, "device_type", prop, sizeof(prop)); | |
2184 | if (rv != PROM_ERROR && (strcmp(prop, "chrp") == 0)) | |
2185 | prom_setprop(node, "/", "device_type", "efika", sizeof("efika")); | |
2186 | ||
7f4392cd DW |
2187 | /* CODEGEN,description is exposed in /proc/cpuinfo so |
2188 | fix that too */ | |
2189 | rv = prom_getprop(node, "CODEGEN,description", prop, sizeof(prop)); | |
2190 | if (rv != PROM_ERROR && (strstr(prop, "CHRP"))) | |
2191 | prom_setprop(node, "/", "CODEGEN,description", | |
2192 | "Efika 5200B PowerPC System", | |
2193 | sizeof("Efika 5200B PowerPC System")); | |
2194 | ||
94d2dde7 GL |
2195 | /* Fixup bestcomm interrupts property */ |
2196 | node = call_prom("finddevice", 1, 1, ADDR("/builtin/bestcomm")); | |
2197 | if (PHANDLE_VALID(node)) { | |
2198 | len = prom_getproplen(node, "interrupts"); | |
2199 | if (len == 12) { | |
2200 | prom_printf("Fixing bestcomm interrupts property\n"); | |
2201 | prom_setprop(node, "/builtin/bestcom", "interrupts", | |
2202 | bcomm_irq, sizeof(bcomm_irq)); | |
2203 | } | |
2204 | } | |
2205 | ||
2206 | /* Fixup sound interrupts property */ | |
2207 | node = call_prom("finddevice", 1, 1, ADDR("/builtin/sound")); | |
2208 | if (PHANDLE_VALID(node)) { | |
2209 | rv = prom_getprop(node, "interrupts", prop, sizeof(prop)); | |
2210 | if (rv == PROM_ERROR) { | |
2211 | prom_printf("Adding sound interrupts property\n"); | |
2212 | prom_setprop(node, "/builtin/sound", "interrupts", | |
2213 | sound_irq, sizeof(sound_irq)); | |
2214 | } | |
2215 | } | |
6f4347c9 | 2216 | |
94d2dde7 GL |
2217 | /* Make sure ethernet phy-handle property exists */ |
2218 | fixup_device_tree_efika_add_phy(); | |
88fd2a9d SM |
2219 | } |
2220 | #else | |
2221 | #define fixup_device_tree_efika() | |
2222 | #endif | |
2223 | ||
54f4ee18 HB |
2224 | static void __init fixup_device_tree(void) |
2225 | { | |
2226 | fixup_device_tree_maple(); | |
8f101a05 | 2227 | fixup_device_tree_maple_memory_controller(); |
e8c0acf9 | 2228 | fixup_device_tree_chrp(); |
54f4ee18 | 2229 | fixup_device_tree_pmac(); |
88fd2a9d | 2230 | fixup_device_tree_efika(); |
54f4ee18 | 2231 | } |
9b6b563c PM |
2232 | |
2233 | static void __init prom_find_boot_cpu(void) | |
2234 | { | |
e788ff13 | 2235 | struct prom_t *_prom = &RELOC(prom); |
9b6b563c PM |
2236 | u32 getprop_rval; |
2237 | ihandle prom_cpu; | |
2238 | phandle cpu_pkg; | |
2239 | ||
a575b807 | 2240 | _prom->cpu = 0; |
9b6b563c | 2241 | if (prom_getprop(_prom->chosen, "cpu", &prom_cpu, sizeof(prom_cpu)) <= 0) |
a575b807 | 2242 | return; |
9b6b563c PM |
2243 | |
2244 | cpu_pkg = call_prom("instance-to-package", 1, 1, prom_cpu); | |
2245 | ||
2246 | prom_getprop(cpu_pkg, "reg", &getprop_rval, sizeof(getprop_rval)); | |
2247 | _prom->cpu = getprop_rval; | |
2248 | ||
2249 | prom_debug("Booting CPU hw index = 0x%x\n", _prom->cpu); | |
2250 | } | |
2251 | ||
2252 | static void __init prom_check_initrd(unsigned long r3, unsigned long r4) | |
2253 | { | |
2254 | #ifdef CONFIG_BLK_DEV_INITRD | |
e788ff13 | 2255 | struct prom_t *_prom = &RELOC(prom); |
9b6b563c PM |
2256 | |
2257 | if (r3 && r4 && r4 != 0xdeadbeef) { | |
2258 | unsigned long val; | |
2259 | ||
51fae6de | 2260 | RELOC(prom_initrd_start) = is_kernel_addr(r3) ? __pa(r3) : r3; |
9b6b563c PM |
2261 | RELOC(prom_initrd_end) = RELOC(prom_initrd_start) + r4; |
2262 | ||
2263 | val = RELOC(prom_initrd_start); | |
a23414be PM |
2264 | prom_setprop(_prom->chosen, "/chosen", "linux,initrd-start", |
2265 | &val, sizeof(val)); | |
9b6b563c | 2266 | val = RELOC(prom_initrd_end); |
a23414be PM |
2267 | prom_setprop(_prom->chosen, "/chosen", "linux,initrd-end", |
2268 | &val, sizeof(val)); | |
9b6b563c PM |
2269 | |
2270 | reserve_mem(RELOC(prom_initrd_start), | |
2271 | RELOC(prom_initrd_end) - RELOC(prom_initrd_start)); | |
2272 | ||
2273 | prom_debug("initrd_start=0x%x\n", RELOC(prom_initrd_start)); | |
2274 | prom_debug("initrd_end=0x%x\n", RELOC(prom_initrd_end)); | |
2275 | } | |
2276 | #endif /* CONFIG_BLK_DEV_INITRD */ | |
2277 | } | |
2278 | ||
2279 | /* | |
2280 | * We enter here early on, when the Open Firmware prom is still | |
2281 | * handling exceptions and the MMU hash table for us. | |
2282 | */ | |
2283 | ||
2284 | unsigned long __init prom_init(unsigned long r3, unsigned long r4, | |
2285 | unsigned long pp, | |
549e8152 PM |
2286 | unsigned long r6, unsigned long r7, |
2287 | unsigned long kbase) | |
9b6b563c | 2288 | { |
e788ff13 | 2289 | struct prom_t *_prom; |
9b6b563c | 2290 | unsigned long hdr; |
9b6b563c PM |
2291 | |
2292 | #ifdef CONFIG_PPC32 | |
549e8152 | 2293 | unsigned long offset = reloc_offset(); |
9b6b563c PM |
2294 | reloc_got2(offset); |
2295 | #endif | |
2296 | ||
2297 | _prom = &RELOC(prom); | |
2298 | ||
2299 | /* | |
2300 | * First zero the BSS | |
2301 | */ | |
2302 | memset(&RELOC(__bss_start), 0, __bss_stop - __bss_start); | |
2303 | ||
2304 | /* | |
2305 | * Init interface to Open Firmware, get some node references, | |
2306 | * like /chosen | |
2307 | */ | |
2308 | prom_init_client_services(pp); | |
2309 | ||
2310 | /* | |
a23414be PM |
2311 | * See if this OF is old enough that we need to do explicit maps |
2312 | * and other workarounds | |
9b6b563c | 2313 | */ |
a23414be | 2314 | prom_find_mmu(); |
9b6b563c | 2315 | |
a575b807 | 2316 | /* |
a23414be | 2317 | * Init prom stdout device |
a575b807 | 2318 | */ |
a23414be | 2319 | prom_init_stdout(); |
a575b807 | 2320 | |
151a9f4a | 2321 | prom_printf("Preparing to boot %s", RELOC(linux_banner)); |
e7943fbb | 2322 | |
9b6b563c PM |
2323 | /* |
2324 | * Get default machine type. At this point, we do not differentiate | |
2325 | * between pSeries SMP and pSeries LPAR | |
2326 | */ | |
2327 | RELOC(of_platform) = prom_find_machine_type(); | |
9b6b563c | 2328 | |
549e8152 | 2329 | #ifndef CONFIG_RELOCATABLE |
add60ef3 OH |
2330 | /* Bail if this is a kdump kernel. */ |
2331 | if (PHYSICAL_START > 0) | |
2332 | prom_panic("Error: You can't boot a kdump kernel from OF!\n"); | |
549e8152 | 2333 | #endif |
add60ef3 OH |
2334 | |
2335 | /* | |
2336 | * Check for an initrd | |
2337 | */ | |
2338 | prom_check_initrd(r3, r4); | |
2339 | ||
9b6b563c PM |
2340 | #ifdef CONFIG_PPC_PSERIES |
2341 | /* | |
2342 | * On pSeries, inform the firmware about our capabilities | |
2343 | */ | |
799d6046 PM |
2344 | if (RELOC(of_platform) == PLATFORM_PSERIES || |
2345 | RELOC(of_platform) == PLATFORM_PSERIES_LPAR) | |
9b6b563c PM |
2346 | prom_send_capabilities(); |
2347 | #endif | |
2348 | ||
9b6b563c | 2349 | /* |
f3f66f59 | 2350 | * Copy the CPU hold code |
9b6b563c | 2351 | */ |
e788ff13 | 2352 | if (RELOC(of_platform) != PLATFORM_POWERMAC) |
549e8152 | 2353 | copy_and_flush(0, kbase, 0x100, 0); |
9b6b563c PM |
2354 | |
2355 | /* | |
2356 | * Do early parsing of command line | |
2357 | */ | |
2358 | early_cmdline_parse(); | |
2359 | ||
2360 | /* | |
2361 | * Initialize memory management within prom_init | |
2362 | */ | |
2363 | prom_init_mem(); | |
2364 | ||
2365 | /* | |
2366 | * Determine which cpu is actually running right _now_ | |
2367 | */ | |
2368 | prom_find_boot_cpu(); | |
2369 | ||
2370 | /* | |
2371 | * Initialize display devices | |
2372 | */ | |
2373 | prom_check_displays(); | |
2374 | ||
2375 | #ifdef CONFIG_PPC64 | |
2376 | /* | |
2377 | * Initialize IOMMU (TCE tables) on pSeries. Do that before anything else | |
2378 | * that uses the allocator, we need to make sure we get the top of memory | |
2379 | * available for us here... | |
2380 | */ | |
2381 | if (RELOC(of_platform) == PLATFORM_PSERIES) | |
2382 | prom_initialize_tce_table(); | |
2383 | #endif | |
2384 | ||
2385 | /* | |
2386 | * On non-powermacs, try to instantiate RTAS and puts all CPUs | |
2387 | * in spin-loops. PowerMacs don't have a working RTAS and use | |
2388 | * a different way to spin CPUs | |
2389 | */ | |
2390 | if (RELOC(of_platform) != PLATFORM_POWERMAC) { | |
2391 | prom_instantiate_rtas(); | |
2392 | prom_hold_cpus(); | |
2393 | } | |
2394 | ||
2395 | /* | |
2396 | * Fill in some infos for use by the kernel later on | |
2397 | */ | |
9b6b563c | 2398 | #ifdef CONFIG_PPC64 |
165785e5 | 2399 | if (RELOC(prom_iommu_off)) |
a23414be PM |
2400 | prom_setprop(_prom->chosen, "/chosen", "linux,iommu-off", |
2401 | NULL, 0); | |
9b6b563c | 2402 | |
165785e5 | 2403 | if (RELOC(prom_iommu_force_on)) |
a23414be PM |
2404 | prom_setprop(_prom->chosen, "/chosen", "linux,iommu-force-on", |
2405 | NULL, 0); | |
9b6b563c PM |
2406 | |
2407 | if (RELOC(prom_tce_alloc_start)) { | |
a23414be | 2408 | prom_setprop(_prom->chosen, "/chosen", "linux,tce-alloc-start", |
9b6b563c PM |
2409 | &RELOC(prom_tce_alloc_start), |
2410 | sizeof(prom_tce_alloc_start)); | |
a23414be | 2411 | prom_setprop(_prom->chosen, "/chosen", "linux,tce-alloc-end", |
9b6b563c PM |
2412 | &RELOC(prom_tce_alloc_end), |
2413 | sizeof(prom_tce_alloc_end)); | |
2414 | } | |
2415 | #endif | |
2416 | ||
2417 | /* | |
2418 | * Fixup any known bugs in the device-tree | |
2419 | */ | |
2420 | fixup_device_tree(); | |
2421 | ||
2422 | /* | |
2423 | * Now finally create the flattened device-tree | |
2424 | */ | |
1f8737aa | 2425 | prom_printf("copying OF device tree...\n"); |
9b6b563c PM |
2426 | flatten_device_tree(); |
2427 | ||
3825ac0e PM |
2428 | /* |
2429 | * in case stdin is USB and still active on IBM machines... | |
2430 | * Unfortunately quiesce crashes on some powermacs if we have | |
2431 | * closed stdin already (in particular the powerbook 101). | |
2432 | */ | |
2433 | if (RELOC(of_platform) != PLATFORM_POWERMAC) | |
2434 | prom_close_stdin(); | |
9b6b563c PM |
2435 | |
2436 | /* | |
2437 | * Call OF "quiesce" method to shut down pending DMA's from | |
2438 | * devices etc... | |
2439 | */ | |
1f8737aa | 2440 | prom_printf("Calling quiesce...\n"); |
9b6b563c PM |
2441 | call_prom("quiesce", 0, 0); |
2442 | ||
2443 | /* | |
2444 | * And finally, call the kernel passing it the flattened device | |
2445 | * tree and NULL as r5, thus triggering the new entry point which | |
2446 | * is common to us and kexec | |
2447 | */ | |
2448 | hdr = RELOC(dt_header_start); | |
2449 | prom_printf("returning from prom_init\n"); | |
2450 | prom_debug("->dt_header_start=0x%x\n", hdr); | |
2451 | ||
2452 | #ifdef CONFIG_PPC32 | |
2453 | reloc_got2(-offset); | |
2454 | #endif | |
2455 | ||
549e8152 | 2456 | __start(hdr, kbase, 0); |
9b6b563c PM |
2457 | |
2458 | return 0; | |
2459 | } |