19 #include <linux/kernel.h>
20 #include <linux/string.h>
24 #include <linux/types.h>
25 #include <linux/pci.h>
30 #include <linux/bitops.h>
34 #include <asm/processor.h>
39 #include <asm/pgtable.h>
41 #include <asm/iommu.h>
42 #include <asm/btext.h>
43 #include <asm/sections.h>
44 #include <asm/machdep.h>
52 #define DEVTREE_CHUNK_SIZE 0x100000
61 #define MEM_RESERVE_MAP_SIZE 8
83 #define RELOC(x) (*PTRRELOC(&(x)))
84 #define ADDR(x) (u32) add_reloc_offset((unsigned long)(x))
85 #define OF_WORKAROUNDS 0
88 #define ADDR(x) (u32) (x)
89 #define OF_WORKAROUNDS of_workarounds
94 #define OF_WA_LONGTRAIL 2
96 #define PROM_BUG() do { \
97 prom_printf("kernel BUG at %s line 0x%x!\n", \
98 RELOC(__FILE__), __LINE__); \
99 __asm__ __volatile__(".long " BUG_ILLEGAL_INSTR); \
103 #define prom_debug(x...) prom_printf(x)
105 #define prom_debug(x...)
134 extern void __start(
unsigned long r3,
unsigned long r4,
unsigned long r5,
135 unsigned long r6,
unsigned long r7,
unsigned long r8,
139 extern int enter_prom(
struct prom_args *args,
unsigned long entry);
141 static inline int enter_prom(
struct prom_args *args,
unsigned long entry)
143 return ((
int (*)(
struct prom_args *))entry)(args);
155 #define PROM_SCRATCH_SIZE 256
157 static char __initdata of_stdout_device[256];
160 static unsigned long __initdata dt_header_start;
161 static unsigned long __initdata dt_struct_start, dt_struct_end;
162 static unsigned long __initdata dt_string_start, dt_string_end;
164 static unsigned long __initdata prom_initrd_start, prom_initrd_end;
167 static int __initdata prom_iommu_force_on;
168 static int __initdata prom_iommu_off;
169 static unsigned long __initdata prom_tce_alloc_start;
170 static unsigned long __initdata prom_tce_alloc_end;
177 #define PLATFORM_PSERIES 0x0100
178 #define PLATFORM_PSERIES_LPAR 0x0101
179 #define PLATFORM_LPAR 0x0001
180 #define PLATFORM_POWERMAC 0x0400
181 #define PLATFORM_GENERIC 0x0500
182 #define PLATFORM_OPAL 0x0600
184 static int __initdata of_platform;
188 static unsigned long __initdata prom_memory_limit;
190 static unsigned long __initdata alloc_top;
191 static unsigned long __initdata alloc_top_high;
192 static unsigned long __initdata alloc_bottom;
193 static unsigned long __initdata rmo_top;
194 static unsigned long __initdata ram_top;
197 static int __initdata mem_reserve_cnt;
199 static cell_t __initdata regbuf[1024];
209 #define PROM_ERROR (-1u)
210 #define PHANDLE_VALID(p) ((p) != 0 && (p) != PROM_ERROR)
211 #define IHANDLE_VALID(i) ((i) != 0 && (i) != PROM_ERROR)
218 static int __init call_prom(
const char *
service,
int nargs,
int nret, ...)
229 for (i = 0; i <
nargs; i++)
233 for (i = 0; i <
nret; i++)
234 args.
args[nargs+i] = 0;
236 if (enter_prom(&args,
RELOC(prom_entry)) < 0)
239 return (nret > 0) ? args.
args[
nargs] : 0;
254 for (i = 0; i <
nargs; i++)
258 for (i = 0; i <
nret; i++)
259 args.
args[nargs+i] = 0;
261 if (enter_prom(&args,
RELOC(prom_entry)) < 0)
265 for (i = 1; i <
nret; ++
i)
266 rets[i-1] = args.
args[nargs+i];
272 static void __init prom_print(
const char *
msg)
280 for (p = msg; *p != 0; p =
q) {
281 for (q = p; *q != 0 && *q !=
'\n'; ++
q)
284 call_prom(
"write", 3, 1, _prom->
stdout, p, q - p);
288 call_prom(
"write", 3, 1, _prom->
stdout,
ADDR(
"\r\n"), 2);
293 static void __init prom_print_hex(
unsigned long val)
295 int i, nibbles =
sizeof(
val)*2;
296 char buf[
sizeof(
val)*2+1];
299 for (i = nibbles-1; i >= 0; i--) {
300 buf[
i] = (val & 0xf) +
'0';
302 buf[
i] += (
'a'-
'0'-10);
306 call_prom(
"write", 3, 1, _prom->
stdout,
buf, nibbles);
311 static void __init prom_print_dec(
unsigned long val)
318 buf[
i] = (val % 10) +
'0';
325 call_prom(
"write", 3, 1, _prom->
stdout, buf+i, size);
330 const char *
p, *
q, *
s;
340 for (p = format; *p != 0; p =
q) {
341 for (q = p; *q != 0 && *q !=
'\n' && *q !=
'%'; ++
q)
344 call_prom(
"write", 3, 1, _prom->
stdout, p, q - p);
349 call_prom(
"write", 3, 1, _prom->
stdout,
359 s =
va_arg(args,
const char *);
364 v =
va_arg(args,
unsigned long);
371 prom_print(
RELOC(
"-"));
380 else if (*q ==
'x') {
382 v =
va_arg(args,
unsigned long);
384 }
else if (*q ==
'u') {
386 v =
va_arg(args,
unsigned long);
388 }
else if (*q ==
'd') {
392 prom_print(
RELOC(
"-"));
403 static unsigned int __init prom_claim(
unsigned long virt,
unsigned long size,
416 ret = call_prom_ret(
"call-method", 5, 2, &result,
419 if (ret != 0 || result == -1)
421 ret = call_prom_ret(
"call-method", 5, 2, &result,
425 call_prom(
"call-method", 4, 1,
ADDR(
"release"),
426 _prom->
memory, size, virt);
430 call_prom(
"call-method", 6, 1,
431 ADDR(
"map"), _prom->
mmumap, 0x12, size, virt, virt);
450 call_prom(
"exit", 0, 0);
461 if ((node = *nodep) != 0
462 && (*nodep = call_prom(
"child", 1, 1, node)) != 0)
464 if ((*nodep = call_prom(
"peer", 1, 1, node)) != 0)
467 if ((node = call_prom(
"parent", 1, 1, node)) == 0)
469 if ((*nodep = call_prom(
"peer", 1, 1, node)) != 0)
474 static int inline prom_getprop(
phandle node,
const char *pname,
475 void *
value,
size_t valuelen)
477 return call_prom(
"getprop", 4, 1, node,
ADDR(pname),
478 (
u32)(
unsigned long) value, (
u32) valuelen);
483 return call_prom(
"getproplen", 2, 1, node,
ADDR(pname));
486 static void add_string(
char **
str,
const char *q)
496 static char *tohex(
unsigned int x)
498 static char digits[] =
"0123456789abcdef";
499 static char result[9];
506 result[
i] = digits[x & 0xf];
508 }
while (x != 0 && i > 0);
513 const char *pname,
void *value,
size_t valuelen)
518 return call_prom(
"setprop", 4, 1, node,
ADDR(pname),
519 (
u32)(
unsigned long) value, (
u32) valuelen);
523 add_string(&p,
"dev");
524 add_string(&p, nodename);
525 add_string(&p, tohex((
u32)(
unsigned long) value));
526 add_string(&p, tohex(valuelen));
527 add_string(&p, tohex(
ADDR(pname)));
529 add_string(&p,
"property");
531 return call_prom(
"interpret", 1, 1, (
u32)(
unsigned long) cmd);
535 #define isxdigit(c) (('0' <= (c) && (c) <= '9') \
536 || ('a' <= (c) && (c) <= 'f') \
537 || ('A' <= (c) && (c) <= 'F'))
539 #define isdigit(c) ('0' <= (c) && (c) <= '9')
540 #define islower(c) ('a' <= (c) && (c) <= 'z')
541 #define toupper(c) (islower(c) ? ((c) - 'a' + 'A') : (c))
545 unsigned long result = 0,
base = 10,
value;
578 if (
'G' == **retptr ||
'g' == **retptr)
581 if (
'M' == **retptr ||
'm' == **retptr)
584 if (
'K' == **retptr ||
'k' == **retptr)
599 static void __init early_cmdline_parse(
void)
607 RELOC(prom_cmd_line[0]) = 0;
608 p =
RELOC(prom_cmd_line);
609 if ((
long)_prom->
chosen > 0)
611 #ifdef CONFIG_CMDLINE
612 if (l <= 0 || p[0] ==
'\0')
614 RELOC(CONFIG_CMDLINE),
sizeof(prom_cmd_line));
623 while (*opt && *opt ==
' ')
626 RELOC(prom_iommu_off) = 1;
628 RELOC(prom_iommu_force_on) = 1;
642 #if defined(CONFIG_PPC_PSERIES) || defined(CONFIG_PPC_POWERNV)
659 #define W(x) ((x) >> 24) & 0xff, ((x) >> 16) & 0xff, \
660 ((x) >> 8) & 0xff, (x) & 0xff
663 #define OV_IGNORE 0x80
664 #define OV_CESSATION_POLICY 0x40
667 #define OV1_PPC_2_00 0x80
668 #define OV1_PPC_2_01 0x40
669 #define OV1_PPC_2_02 0x20
670 #define OV1_PPC_2_03 0x10
671 #define OV1_PPC_2_04 0x08
672 #define OV1_PPC_2_05 0x04
673 #define OV1_PPC_2_06 0x02
676 #define OV2_REAL_MODE 0x20
684 #define OV4_MIN_ENT_CAP 0x01
687 #define OV5_LPAR 0x80
688 #define OV5_SPLPAR 0x40
690 #define OV5_DRCONF_MEMORY 0x20
691 #define OV5_LARGE_PAGES 0x10
692 #define OV5_DONATE_DEDICATE_CPU 0x02
694 #ifdef CONFIG_PCI_MSI
699 #ifdef CONFIG_PPC_SMLPAR
701 #define OV5_XCMO 0x40
704 #define OV5_XCMO 0x00
706 #define OV5_TYPE1_AFFINITY 0x80
707 #define OV5_PFO_HW_RNG 0x80
708 #define OV5_PFO_HW_842 0x40
709 #define OV5_PFO_HW_ENCR 0x20
712 #define OV6_LINUX 0x02
718 static unsigned char ibm_architecture_vec[] = {
719 W(0xfffe0000),
W(0x003a0000),
720 W(0xffff0000),
W(0x003e0000),
721 W(0xffff0000),
W(0x003f0000),
722 W(0xffffffff),
W(0x0f000003),
723 W(0xffffffff),
W(0x0f000002),
724 W(0xfffffffe),
W(0x0f000001),
730 OV1_PPC_2_00 | OV1_PPC_2_01 | OV1_PPC_2_02 | OV1_PPC_2_03 |
731 OV1_PPC_2_04 | OV1_PPC_2_05 | OV1_PPC_2_06,
750 OV3_FP | OV3_VMX | OV3_DFP,
760 OV5_LPAR | OV5_SPLPAR | OV5_LARGE_PAGES | OV5_DRCONF_MEMORY |
761 OV5_DONATE_DEDICATE_CPU | OV5_MSI,
772 #define IBM_ARCH_VEC_NRCORES_OFFSET 101
778 OV5_PFO_HW_RNG | OV5_PFO_HW_ENCR | OV5_PFO_HW_842,
788 static struct fake_elf {
823 .e_ident = { 0x7f,
'E',
'L',
'F',
828 .e_phoff =
offsetof(
struct fake_elf, phdr),
835 .p_offset =
offsetof(
struct fake_elf, chrpnote),
836 .p_filesz =
sizeof(
struct chrpnote)
840 .p_filesz =
sizeof(
struct rpanote)
844 .namesz =
sizeof(
"PowerPC"),
845 .descsz =
sizeof(
struct chrpdesc),
858 .namesz =
sizeof(
"IBM,RPA-Client-Config"),
859 .descsz =
sizeof(
struct rpadesc),
861 .name =
"IBM,RPA-Client-Config",
865 .min_rmo_percent = 0,
874 static int __init prom_count_smt_threads(
void)
881 for (node = 0; prom_next_node(&node); ) {
883 prom_getprop(node,
"device_type", type,
sizeof(type));
896 prom_debug(
"Found %lu smt threads per core\n", (
unsigned long)plen);
899 if (plen < 1 || plen > 64) {
900 prom_printf(
"Threads per core %lu out of bounds, assuming 1\n",
901 (
unsigned long)plen);
906 prom_debug(
"No threads found, assuming 1 per core\n");
913 static void __init prom_send_capabilities(
void)
919 root = call_prom(
"open", 1, 1,
ADDR(
"/"));
927 cores = (
u32 *)
PTRRELOC(&ibm_architecture_vec[IBM_ARCH_VEC_NRCORES_OFFSET]);
930 "ibm_architecture_vec structure inconsistent: %lu!\n",
934 prom_printf(
"Max number of cores passed to firmware: %lu (NR_CPUS = %lu)\n",
939 prom_printf(
"Calling ibm,client-architecture-support...");
940 if (call_prom_ret(
"call-method", 3, 2, &ret,
941 ADDR(
"ibm,client-architecture-support"),
943 ADDR(ibm_architecture_vec)) == 0) {
947 "-support call FAILED!\n");
948 call_prom(
"close", 1, 0, root);
952 call_prom(
"close", 1, 0, root);
957 elfloader = call_prom(
"open", 1, 1,
ADDR(
"/packages/elf-loader"));
958 if (elfloader == 0) {
959 prom_printf(
"couldn't open /packages/elf-loader\n");
962 call_prom(
"call-method", 3, 1,
ADDR(
"process-elf-header"),
963 elfloader,
ADDR(&fake_elf));
964 call_prom(
"close", 1, 0, elfloader);
1001 static unsigned long __init alloc_up(
unsigned long size,
unsigned long align)
1003 unsigned long base =
RELOC(alloc_bottom);
1004 unsigned long addr = 0;
1008 prom_debug(
"alloc_up(%x, %x)\n", size, align);
1009 if (
RELOC(ram_top) == 0)
1010 prom_panic(
"alloc_up() called with mem not initialized\n");
1015 base =
RELOC(alloc_bottom);
1017 for(; (base +
size) <=
RELOC(alloc_top);
1018 base =
_ALIGN_UP(base + 0x100000, align)) {
1020 addr = (
unsigned long)prom_claim(base, size, 0);
1046 static unsigned long __init alloc_down(
unsigned long size,
unsigned long align,
1049 unsigned long base, addr = 0;
1051 prom_debug(
"alloc_down(%x, %x, %s)\n", size, align,
1053 if (
RELOC(ram_top) == 0)
1054 prom_panic(
"alloc_down() called with mem not initialized\n");
1059 if (addr <=
RELOC(alloc_bottom))
1065 if (addr <
RELOC(rmo_top)) {
1077 for (; base >
RELOC(alloc_bottom);
1080 addr = (
unsigned long)prom_claim(base, size, 0);
1103 static unsigned long __init prom_next_cell(
int s,
cell_t **cellp)
1106 unsigned long r = 0;
1109 while (s >
sizeof(
unsigned long) / 4) {
1135 unsigned long cnt =
RELOC(mem_reserve_cnt);
1149 prom_panic(
"Memory reserve map exhausted !\n");
1150 RELOC(mem_reserve_map)[
cnt].base = base;
1152 RELOC(mem_reserve_cnt) = cnt + 1;
1159 static void __init prom_init_mem(
void)
1162 char *
path, type[64];
1174 prom_getprop(_prom->
root,
"#address-cells", &rac,
sizeof(rac));
1176 prom_getprop(_prom->
root,
"#size-cells", &rsc,
sizeof(rsc));
1177 prom_debug(
"root_addr_cells: %x\n", (
unsigned long) rac);
1178 prom_debug(
"root_size_cells: %x\n", (
unsigned long) rsc);
1181 path =
RELOC(prom_scratch);
1183 for (node = 0; prom_next_node(&node); ) {
1185 prom_getprop(node,
"device_type", type,
sizeof(type));
1192 prom_getprop(node,
"name", type,
sizeof(type));
1197 plen = prom_getprop(node,
"reg",
RELOC(regbuf),
sizeof(regbuf));
1198 if (plen >
sizeof(regbuf)) {
1199 prom_printf(
"memory node too large for buffer !\n");
1200 plen =
sizeof(regbuf);
1203 endp = p + (plen /
sizeof(
cell_t));
1211 while ((endp - p) >= (rac + rsc)) {
1212 unsigned long base,
size;
1214 base = prom_next_cell(rac, &p);
1215 size = prom_next_cell(rsc, &p);
1222 if ((base + size) >
RELOC(ram_top))
1237 if (
RELOC(prom_memory_limit)) {
1238 if (
RELOC(prom_memory_limit) <=
RELOC(alloc_bottom)) {
1240 RELOC(prom_memory_limit));
1241 RELOC(prom_memory_limit) = 0;
1242 }
else if (
RELOC(prom_memory_limit) >=
RELOC(ram_top)) {
1244 RELOC(prom_memory_limit));
1245 RELOC(prom_memory_limit) = 0;
1260 if (!
RELOC(rmo_top))
1270 if (
RELOC(prom_initrd_start) &&
1272 RELOC(prom_initrd_end) >
RELOC(alloc_bottom))
1276 prom_printf(
" memory_limit : %x (16 MB aligned)\n",
RELOC(prom_memory_limit));
1284 static void __init prom_close_stdin(
void)
1289 if (prom_getprop(_prom->
chosen,
"stdin", &val,
sizeof(val)) > 0)
1290 call_prom(
"close", 1, 0, val);
1293 #ifdef CONFIG_PPC_POWERNV
1295 static u64 __initdata prom_opal_size;
1296 static u64 __initdata prom_opal_align;
1297 static int __initdata prom_rtas_start_cpu;
1298 static u64 __initdata prom_rtas_data;
1299 static u64 __initdata prom_rtas_entry;
1301 #ifdef CONFIG_PPC_EARLY_DEBUG_OPAL
1302 static u64 __initdata prom_opal_base;
1303 static u64 __initdata prom_opal_entry;
1307 static struct opal_secondary_data {
1311 } opal_secondary_data;
1313 extern char opal_secondary_entry;
1315 static void __init prom_query_opal(
void)
1324 ADDR(
"/tnk-memory-map")))) {
1325 prom_printf(
"TNK takeover detected, skipping OPAL check\n");
1331 &
RELOC(prom_opal_align));
1341 if (
RELOC(prom_opal_align) < 0x10000)
1342 RELOC(prom_opal_align) = 0x10000;
1345 static int prom_rtas_call(
int token,
int nargs,
int nret,
int *outputs, ...)
1347 struct rtas_args rtas_args;
1351 rtas_args.token =
token;
1352 rtas_args.nargs = nargs;
1353 rtas_args.nret = nret;
1354 rtas_args.rets = (rtas_arg_t *)&(rtas_args.args[nargs]);
1356 for (i = 0; i < nargs; ++
i)
1357 rtas_args.args[i] =
va_arg(list, rtas_arg_t);
1360 for (i = 0; i < nret; ++
i)
1361 rtas_args.rets[i] = 0;
1364 RELOC(prom_rtas_entry));
1366 if (nret > 1 && outputs !=
NULL)
1367 for (i = 0; i < nret-1; ++
i)
1368 outputs[i] = rtas_args.rets[i+1];
1369 return (nret > 0)? rtas_args.rets[0]: 0;
1372 static void __init prom_opal_hold_cpus(
void)
1380 void *entry = (
unsigned long *)&
RELOC(opal_secondary_entry);
1381 struct opal_secondary_data *
data = &
RELOC(opal_secondary_data);
1383 prom_debug(
"prom_opal_hold_cpus: start...\n");
1391 for (node = 0; prom_next_node(&node); ) {
1393 prom_getprop(node,
"device_type", type,
sizeof(type));
1398 if (prom_getprop(node,
"status", type,
sizeof(type)) > 0)
1402 cnt = prom_getprop(node,
"ibm,ppc-interrupt-server#s", servers,
1407 for (i = 0; i <
cnt; i++) {
1410 if (cpu == _prom->
cpu) {
1421 rc = prom_rtas_call(
RELOC(prom_rtas_start_cpu), 3, 1,
1422 NULL, cpu, entry, data);
1425 for (j = 0; j < 100000000 && data->ack == -1; j++) {
1430 if (data->ack != -1)
1439 static void __init prom_opal_takeover(
void)
1441 struct opal_secondary_data *data = &
RELOC(opal_secondary_data);
1443 u64 align =
RELOC(prom_opal_align);
1453 if (
RELOC(prom_initrd_start) != 0) {
1468 if (opal_addr < top_addr)
1484 prom_printf(
"Performing OPAL takeover,this can take a few minutes..\n");
1495 static void __init prom_instantiate_opal(
void)
1500 u64 size = 0, align = 0x10000;
1503 prom_debug(
"prom_instantiate_opal: start...\n");
1505 opal_node = call_prom(
"finddevice", 1, 1,
ADDR(
"/ibm,opal"));
1510 prom_getprop(opal_node,
"opal-runtime-size", &size,
sizeof(size));
1513 prom_getprop(opal_node,
"opal-runtime-alignment", &align,
1516 base = alloc_down(size, align, 0);
1522 opal_inst = call_prom(
"open", 1, 1,
ADDR(
"/ibm,opal"));
1524 prom_printf(
"opening opal package failed (%x)\n", opal_inst);
1528 prom_printf(
"instantiating opal at 0x%x...", base);
1530 if (call_prom_ret(
"call-method", 4, 3, rets,
1531 ADDR(
"load-opal-runtime"),
1533 base >> 32, base & 0xffffffff) != 0
1534 || (rets[0] == 0 && rets[1] == 0)) {
1538 entry = (((
u64)rets[0]) << 32) | rets[1];
1542 reserve_mem(base, size);
1547 prom_debug(
"opal size = 0x%x\n", (
long)size);
1549 prom_setprop(opal_node,
"/ibm,opal",
"opal-base-address",
1550 &base,
sizeof(base));
1551 prom_setprop(opal_node,
"/ibm,opal",
"opal-entry-address",
1552 &entry,
sizeof(entry));
1554 #ifdef CONFIG_PPC_EARLY_DEBUG_OPAL
1555 RELOC(prom_opal_base) = base;
1558 prom_debug(
"prom_instantiate_opal: end...\n");
1566 static void __init prom_instantiate_rtas(
void)
1570 u32 base, entry = 0;
1573 prom_debug(
"prom_instantiate_rtas: start...\n");
1575 rtas_node = call_prom(
"finddevice", 1, 1,
ADDR(
"/rtas"));
1580 prom_getprop(rtas_node,
"rtas-size", &size,
sizeof(size));
1586 prom_panic(
"Could not allocate memory for RTAS\n");
1588 rtas_inst = call_prom(
"open", 1, 1,
ADDR(
"/rtas"));
1590 prom_printf(
"opening rtas package failed (%x)\n", rtas_inst);
1594 prom_printf(
"instantiating rtas at 0x%x...", base);
1596 if (call_prom_ret(
"call-method", 3, 2, &entry,
1597 ADDR(
"instantiate-rtas"),
1598 rtas_inst, base) != 0
1605 reserve_mem(base, size);
1608 &base,
sizeof(base));
1610 &entry,
sizeof(entry));
1612 #ifdef CONFIG_PPC_POWERNV
1614 RELOC(prom_rtas_data) = base;
1616 prom_getprop(rtas_node,
"start-cpu", &
RELOC(prom_rtas_start_cpu), 4);
1620 prom_debug(
"rtas size = 0x%x\n", (
long)size);
1622 prom_debug(
"prom_instantiate_rtas: end...\n");
1629 static void __init prom_instantiate_sml(
void)
1633 u32 entry = 0, size = 0;
1636 prom_debug(
"prom_instantiate_sml: start...\n");
1638 ibmvtpm_node = call_prom(
"finddevice", 1, 1,
ADDR(
"/ibm,vtpm"));
1639 prom_debug(
"ibmvtpm_node: %x\n", ibmvtpm_node);
1643 ibmvtpm_inst = call_prom(
"open", 1, 1,
ADDR(
"/ibm,vtpm"));
1645 prom_printf(
"opening vtpm package failed (%x)\n", ibmvtpm_inst);
1649 if (call_prom_ret(
"call-method", 2, 2, &size,
1650 ADDR(
"sml-get-handover-size"),
1651 ibmvtpm_inst) != 0 || size == 0) {
1658 prom_panic(
"Could not allocate memory for sml\n");
1660 prom_printf(
"instantiating sml at 0x%x...", base);
1662 if (call_prom_ret(
"call-method", 4, 2, &entry,
1663 ADDR(
"sml-handover"),
1664 ibmvtpm_inst, size, base) != 0 || entry == 0) {
1670 reserve_mem(base, size);
1672 prom_setprop(ibmvtpm_node,
"/ibm,vtpm",
"linux,sml-base",
1673 &base,
sizeof(base));
1674 prom_setprop(ibmvtpm_node,
"/ibm,vtpm",
"linux,sml-size",
1675 &size,
sizeof(size));
1680 prom_debug(
"prom_instantiate_sml: end...\n");
1686 static void __init prom_initialize_tce_table(
void)
1691 char *path =
RELOC(prom_scratch);
1694 u64 tce_entry, *tce_entryp;
1695 u64 local_alloc_top, local_alloc_bottom;
1698 if (
RELOC(prom_iommu_off))
1701 prom_debug(
"starting prom_initialize_tce_table\n");
1704 local_alloc_top =
RELOC(alloc_top_high);
1705 local_alloc_bottom = local_alloc_top;
1708 for (node = 0; prom_next_node(&node); ) {
1712 prom_getprop(node,
"compatible",
1713 compatible,
sizeof(compatible));
1714 prom_getprop(node,
"device_type", type,
sizeof(type));
1715 prom_getprop(node,
"model", model,
sizeof(model));
1721 if (compatible[0] != 0) {
1726 }
else if (model[0] != 0) {
1733 if (prom_getprop(node,
"tce-table-minalign", &minalign,
1736 if (prom_getprop(node,
"tce-table-minsize", &minsize,
1738 minsize = 4
UL << 20;
1751 if (pvr_version_is(PVR_POWER4) || pvr_version_is(PVR_POWER4p))
1752 minsize = 8
UL << 20;
1754 minsize = 4
UL << 20;
1757 align =
max(minalign, minsize);
1758 base = alloc_down(minsize, align, 1);
1760 prom_panic(
"ERROR, cannot find space for TCE table.\n");
1761 if (base < local_alloc_bottom)
1762 local_alloc_bottom = base;
1767 if (call_prom(
"package-to-path", 3, 1, node,
1773 prom_setprop(node, path,
"linux,tce-base", &base,
sizeof(base));
1774 prom_setprop(node, path,
"linux,tce-size", &minsize,
sizeof(minsize));
1784 tce_entryp = (
u64 *)base;
1785 for (i = 0; i < (minsize >> 3) ;tce_entryp++, i++) {
1788 *tce_entryp = tce_entry;
1792 phb_node = call_prom(
"open", 1, 1, path);
1798 call_prom(
"call-method", 6, 0,
ADDR(
"set-64-bit-addressing"),
1799 phb_node, -1, minsize,
1800 (
u32) base, (
u32) (base >> 32));
1801 call_prom(
"close", 1, 0, phb_node);
1804 reserve_mem(local_alloc_bottom, local_alloc_top - local_alloc_bottom);
1808 RELOC(prom_tce_alloc_start) = local_alloc_bottom;
1809 RELOC(prom_tce_alloc_end) = local_alloc_top;
1812 prom_debug(
"ending prom_initialize_tce_table\n");
1838 #define LOW_ADDR(x) (((unsigned long) &(x)) & 0xff)
1840 static void __init prom_hold_cpus(
void)
1847 unsigned long *spinloop
1848 = (
void *)
LOW_ADDR(__secondary_hold_spinloop);
1849 unsigned long *acknowledge
1850 = (
void *)
LOW_ADDR(__secondary_hold_acknowledge);
1851 unsigned long secondary_hold =
LOW_ADDR(__secondary_hold);
1854 prom_debug(
" 1) spinloop = 0x%x\n", (
unsigned long)spinloop);
1855 prom_debug(
" 1) *spinloop = 0x%x\n", *spinloop);
1857 (
unsigned long)acknowledge);
1858 prom_debug(
" 1) *acknowledge = 0x%x\n", *acknowledge);
1859 prom_debug(
" 1) secondary_hold = 0x%x\n", secondary_hold);
1869 for (node = 0; prom_next_node(&node); ) {
1871 prom_getprop(node,
"device_type", type,
sizeof(type));
1876 if (prom_getprop(node,
"status", type,
sizeof(type)) > 0)
1881 prom_getprop(node,
"reg", ®,
sizeof(reg));
1889 *acknowledge = (
unsigned long)-1;
1891 if (reg != _prom->
cpu) {
1894 call_prom(
"start-cpu", 3, 0, node,
1895 secondary_hold, reg);
1897 for (i = 0; (i < 100000000) &&
1898 (*acknowledge == ((
unsigned long)-1)); i++ )
1901 if (*acknowledge == reg)
1916 static void __init prom_init_client_services(
unsigned long pp)
1924 _prom->
chosen = call_prom(
"finddevice", 1, 1,
ADDR(
"/chosen"));
1926 prom_panic(
"cannot find chosen");
1929 _prom->
root = call_prom(
"finddevice", 1, 1,
ADDR(
"/"));
1931 prom_panic(
"cannot find device tree root");
1948 oprom = call_prom(
"finddevice", 1, 1,
ADDR(
"/openprom"));
1951 if (prom_getprop(oprom,
"model", version,
sizeof(version)) <= 0)
1953 version[
sizeof(
version) - 1] = 0;
1955 if (
strcmp(version,
"Open Firmware, 1.0.5") == 0)
1957 else if (
strncmp(version,
"FirmWorks,3.", 12) == 0) {
1959 call_prom(
"interpret", 1, 1,
"dev /memory 0 to allow-reclaim");
1962 _prom->
memory = call_prom(
"open", 1, 1,
ADDR(
"/memory"));
1969 #define prom_find_mmu()
1972 static void __init prom_init_stdout(
void)
1975 char *path =
RELOC(of_stdout_device);
1979 if (prom_getprop(_prom->
chosen,
"stdout", &val,
sizeof(val)) <= 0)
1980 prom_panic(
"cannot find stdout");
1986 call_prom(
"instance-to-path", 3, 1, _prom->
stdout, path, 255);
1987 val = call_prom(
"instance-to-package", 1, 1, _prom->
stdout);
1995 memset(type, 0,
sizeof(type));
1996 prom_getprop(val,
"device_type", type,
sizeof(type));
2001 static int __init prom_find_machine_type(
void)
2012 len = prom_getprop(_prom->
root,
"compatible",
2013 compat,
sizeof(compat)-1);
2017 char *p = &compat[
i];
2047 len = prom_getprop(_prom->
root,
"device_type",
2048 compat,
sizeof(compat)-1);
2055 rtas = call_prom(
"finddevice", 1, 1,
ADDR(
"/rtas"));
2060 prom_debug(
"Hypertas detected, assuming LPAR !\n");
2069 static int __init prom_set_color(
ihandle ih,
int i,
int r,
int g,
int b)
2071 return call_prom(
"call-method", 6, 1,
ADDR(
"color!"), ih, i, b, g, r);
2082 static void __init prom_check_displays(
void)
2084 char type[16], *
path;
2089 static unsigned char default_colors[] = {
2107 const unsigned char *clut;
2110 for (node = 0; prom_next_node(&node); ) {
2111 memset(type, 0,
sizeof(type));
2112 prom_getprop(node,
"device_type", type,
sizeof(type));
2117 path =
RELOC(prom_scratch);
2124 if (call_prom(
"package-to-path", 3, 1, node, path,
2127 prom_printf(
"found display : %s, opening... ", path);
2129 ih = call_prom(
"open", 1, 1, path);
2141 clut =
RELOC(default_colors);
2142 for (i = 0; i < 16; i++, clut += 3)
2143 if (prom_set_color(ih, i, clut[0], clut[1],
2147 #ifdef CONFIG_LOGO_LINUX_CLUT224
2150 if (prom_set_color(ih, i + 32, clut[0], clut[1],
2160 unsigned long needed,
unsigned long align)
2164 *mem_start =
_ALIGN(*mem_start, align);
2165 while ((*mem_start + needed) > *mem_end) {
2166 unsigned long room,
chunk;
2168 prom_debug(
"Chunk exhausted, claiming more at %x...\n",
2169 RELOC(alloc_bottom));
2170 room =
RELOC(alloc_top) -
RELOC(alloc_bottom);
2174 prom_panic(
"No memory for flatten_device_tree "
2176 chunk = alloc_up(room, 0);
2178 prom_panic(
"No memory for flatten_device_tree "
2179 "(claim failed)\n");
2180 *mem_end = chunk + room;
2183 ret = (
void *)*mem_start;
2184 *mem_start += needed;
2189 #define dt_push_token(token, mem_start, mem_end) \
2190 do { *((u32 *)make_room(mem_start, mem_end, 4, 4)) = token; } while(0)
2192 static unsigned long __init dt_find_string(
char *str)
2196 s = os = (
char *)
RELOC(dt_string_start);
2198 while (s < (
char *)
RELOC(dt_string_end)) {
2210 #define MAX_PROPERTY_NAME 64
2213 unsigned long *mem_start,
2214 unsigned long *mem_end)
2216 char *prev_name, *namep, *sstart;
2220 sstart = (
char *)
RELOC(dt_string_start);
2223 prev_name =
RELOC(
"");
2227 if (call_prom(
"nextprop", 3, 1, node, prev_name, namep) != 1) {
2229 *mem_start = (
unsigned long)namep;
2235 *mem_start = (
unsigned long)namep;
2236 prev_name =
RELOC(
"name");
2240 soff = dt_find_string(namep);
2242 *mem_start = (
unsigned long)namep;
2243 namep = sstart + soff;
2246 *mem_start = (
unsigned long)namep +
strlen(namep) + 1;
2253 child = call_prom(
"child", 1, 1, node);
2254 while (child != 0) {
2255 scan_dt_build_strings(child, mem_start, mem_end);
2256 child = call_prom(
"peer", 1, 1, child);
2260 static void __init scan_dt_build_struct(
phandle node,
unsigned long *mem_start,
2261 unsigned long *mem_end)
2264 char *namep, *prev_name, *sstart, *
p, *ep, *
lp, *
path;
2266 unsigned char *valp;
2268 int l, room, has_phandle = 0;
2273 namep = (
char *)*mem_start;
2277 l = call_prom(
"package-to-path", 3, 1, node, namep, room);
2281 if (l >= *mem_end - *mem_start)
2282 namep = make_room(mem_start, mem_end, l+1, 1);
2283 call_prom(
"package-to-path", 3, 1, node, namep, l);
2291 for (lp = p = namep, ep = namep + l; p < ep; p++) {
2298 *mem_start =
_ALIGN((
unsigned long)lp + 1, 4);
2302 path =
RELOC(prom_scratch);
2307 prev_name =
RELOC(
"");
2308 sstart = (
char *)
RELOC(dt_string_start);
2310 if (call_prom(
"nextprop", 3, 1, node, prev_name,
2316 prev_name =
RELOC(
"name");
2321 soff = dt_find_string(
RELOC(pname));
2323 prom_printf(
"WARNING: Can't find string index for"
2324 " <%s>, node %s\n",
RELOC(pname), path);
2327 prev_name = sstart + soff;
2330 l = call_prom(
"getproplen", 2, 1, node,
RELOC(pname));
2342 valp = make_room(mem_start, mem_end, l, 4);
2343 call_prom(
"getprop", 4, 1, node,
RELOC(pname), valp, l);
2344 *mem_start =
_ALIGN(*mem_start, 4);
2354 soff = dt_find_string(
RELOC(
"linux,phandle"));
2356 prom_printf(
"WARNING: Can't find string index for"
2357 " <linux-phandle> node %s\n", path);
2362 valp = make_room(mem_start, mem_end, 4, 4);
2363 *(
u32 *)valp = node;
2368 child = call_prom(
"child", 1, 1, node);
2369 while (child != 0) {
2370 scan_dt_build_struct(child, mem_start, mem_end);
2371 child = call_prom(
"peer", 1, 1, child);
2377 static void __init flatten_device_tree(
void)
2390 room =
RELOC(alloc_top) -
RELOC(alloc_bottom) - 0x4000;
2393 prom_debug(
"starting device tree allocs at %x\n",
RELOC(alloc_bottom));
2398 prom_panic(
"Can't allocate initial device-tree chunk\n");
2399 mem_end = mem_start + room;
2402 root = call_prom(
"peer", 1, 1, (
phandle)0);
2404 prom_panic (
"couldn't get device tree root\n");
2407 mem_start =
_ALIGN(mem_start, 4);
2408 hdr = make_room(&mem_start, &mem_end,
2410 RELOC(dt_header_start) = (
unsigned long)hdr;
2411 rsvmap = make_room(&mem_start, &mem_end,
sizeof(mem_reserve_map), 8);
2419 namep = make_room(&mem_start, &mem_end, 16, 1);
2421 mem_start = (
unsigned long)namep +
strlen(namep) + 1;
2425 scan_dt_build_strings(root, &mem_start, &mem_end);
2432 scan_dt_build_struct(root, &mem_start, &mem_end);
2449 memcpy(rsvmap,
RELOC(mem_reserve_map),
sizeof(mem_reserve_map));
2455 for (i = 0; i <
RELOC(mem_reserve_cnt); i++)
2457 RELOC(mem_reserve_map)[
i].base,
2458 RELOC(mem_reserve_map)[
i].size);
2467 RELOC(dt_string_start),
RELOC(dt_string_end));
2469 RELOC(dt_struct_start),
RELOC(dt_struct_end));
2473 #ifdef CONFIG_PPC_MAPLE
2479 u32 rloc = 0x01002000;
2483 name =
"/ht@0/isa@4";
2484 isa = call_prom(
"finddevice", 1, 1,
ADDR(name));
2486 name =
"/ht@0/isa@6";
2487 isa = call_prom(
"finddevice", 1, 1,
ADDR(name));
2495 if (prom_getprop(isa,
"ranges", isa_ranges,
sizeof(isa_ranges))
2499 if (isa_ranges[0] != 0x1 ||
2500 isa_ranges[1] != 0xf4000000 ||
2501 isa_ranges[2] != 0x00010000)
2504 prom_printf(
"Fixing up bogus ISA range on Maple/Apache...\n");
2506 isa_ranges[0] = 0x1;
2507 isa_ranges[1] = 0x0;
2508 isa_ranges[2] = rloc;
2509 isa_ranges[3] = 0x0;
2510 isa_ranges[4] = 0x0;
2511 isa_ranges[5] = 0x00010000;
2513 isa_ranges,
sizeof(isa_ranges));
2516 #define CPC925_MC_START 0xf8000000
2517 #define CPC925_MC_LENGTH 0x1000000
2523 char *name =
"/hostbridge@f8000000";
2527 mc = call_prom(
"finddevice", 1, 1,
ADDR(name));
2534 prom_getprop(_prom->
root,
"#address-cells", &ac,
sizeof(ac));
2535 prom_getprop(_prom->
root,
"#size-cells", &sc,
sizeof(sc));
2536 if ((ac != 2) || (sc != 2))
2539 if (prom_getprop(mc,
"reg", mc_reg,
sizeof(mc_reg)) ==
PROM_ERROR)
2542 if (mc_reg[0] != CPC925_MC_START || mc_reg[1] != CPC925_MC_LENGTH)
2545 prom_printf(
"Fixing up bogus hostbridge on Maple...\n");
2548 mc_reg[1] = CPC925_MC_START;
2550 mc_reg[3] = CPC925_MC_LENGTH;
2554 #define fixup_device_tree_maple()
2555 #define fixup_device_tree_maple_memory_controller()
2558 #ifdef CONFIG_PPC_CHRP
2568 u32 rloc = 0x01006000;
2572 name =
"/pci@80000000/isa@c";
2573 ph = call_prom(
"finddevice", 1, 1,
ADDR(name));
2575 name =
"/pci@ff500000/isa@6";
2576 ph = call_prom(
"finddevice", 1, 1,
ADDR(name));
2582 prom_printf(
"Fixing up missing ISA range on Pegasos...\n");
2589 prop[5] = 0x00010000;
2594 name =
"/pci@80000000/ide@C,1";
2595 ph = call_prom(
"finddevice", 1, 1,
ADDR(name));
2597 prom_printf(
"Fixing up IDE interrupt on Pegasos...\n");
2601 prom_printf(
"Fixing up IDE class-code on Pegasos...\n");
2602 rc = prom_getprop(ph,
"class-code", prop,
sizeof(
u32));
2603 if (rc ==
sizeof(
u32)) {
2610 #define fixup_device_tree_chrp()
2613 #if defined(CONFIG_PPC64) && defined(CONFIG_PPC_PMAC)
2622 u3 = call_prom(
"finddevice", 1, 1,
ADDR(
"/u3@0,f8000000"));
2625 i2c = call_prom(
"finddevice", 1, 1,
ADDR(
"/u3@0,f8000000/i2c@f8001000"));
2628 mpic = call_prom(
"finddevice", 1, 1,
ADDR(
"/u3@0,f8000000/mpic@f8040000"));
2633 if (prom_getprop(u3,
"device-rev", &u3_rev,
sizeof(u3_rev))
2636 if (u3_rev < 0x35 || u3_rev > 0x39)
2642 prom_printf(
"fixing up bogus interrupts for u3 i2c...\n");
2647 prom_setprop(i2c,
"/u3@0,f8000000/i2c@f8001000",
"interrupts",
2648 &interrupts,
sizeof(interrupts));
2650 prom_setprop(i2c,
"/u3@0,f8000000/i2c@f8001000",
"interrupt-parent",
2651 &parent,
sizeof(parent));
2654 #define fixup_device_tree_pmac()
2657 #ifdef CONFIG_PPC_EFIKA
2664 static void __init fixup_device_tree_efika_add_phy(
void)
2671 node = call_prom(
"finddevice", 1, 1,
ADDR(
"/builtin/ethernet"));
2676 rv = prom_getprop(node,
"phy-handle", prop,
sizeof(prop));
2686 node = call_prom(
"finddevice", 1, 1,
ADDR(
"/builtin/mdio"));
2689 call_prom(
"interpret", 1, 1,
2690 " s\" /builtin\" find-device"
2692 " 1 encode-int s\" #address-cells\" property"
2693 " 0 encode-int s\" #size-cells\" property"
2694 " s\" mdio\" device-name"
2695 " s\" fsl,mpc5200b-mdio\" encode-string"
2696 " s\" compatible\" property"
2697 " 0xf0003000 0x400 reg"
2699 " 0x5 encode-int encode+"
2700 " 0x3 encode-int encode+"
2701 " s\" interrupts\" property"
2707 node = call_prom(
"finddevice", 1, 1,
2708 ADDR(
"/builtin/mdio/ethernet-phy"));
2711 call_prom(
"interpret", 1, 1,
2712 " s\" /builtin/mdio\" find-device"
2714 " s\" ethernet-phy\" device-name"
2715 " 0x10 encode-int s\" reg\" property"
2719 " s\" /builtin/ethernet\" find-device"
2721 " s\" phy-handle\" property"
2728 int sound_irq[3] = { 2, 2, 0 };
2729 int bcomm_irq[3*16] = { 3,0,0, 3,1,0, 3,2,0, 3,3,0,
2730 3,4,0, 3,5,0, 3,6,0, 3,7,0,
2731 3,8,0, 3,9,0, 3,10,0, 3,11,0,
2732 3,12,0, 3,13,0, 3,14,0, 3,15,0 };
2738 node = call_prom(
"finddevice", 1, 1,
ADDR(
"/"));
2742 rv = prom_getprop(node,
"model", prop,
sizeof(prop));
2745 if (
strcmp(prop,
"EFIKA5K2"))
2748 prom_printf(
"Applying EFIKA device tree fixups\n");
2751 node = call_prom(
"finddevice", 1, 1,
ADDR(
"/"));
2752 rv = prom_getprop(node,
"device_type", prop,
sizeof(prop));
2754 prom_setprop(node,
"/",
"device_type",
"efika",
sizeof(
"efika"));
2758 rv = prom_getprop(node,
"CODEGEN,description", prop,
sizeof(prop));
2761 "Efika 5200B PowerPC System",
2762 sizeof(
"Efika 5200B PowerPC System"));
2765 node = call_prom(
"finddevice", 1, 1,
ADDR(
"/builtin/bestcomm"));
2769 prom_printf(
"Fixing bestcomm interrupts property\n");
2771 bcomm_irq,
sizeof(bcomm_irq));
2776 node = call_prom(
"finddevice", 1, 1,
ADDR(
"/builtin/sound"));
2778 rv = prom_getprop(node,
"interrupts", prop,
sizeof(prop));
2780 prom_printf(
"Adding sound interrupts property\n");
2782 sound_irq,
sizeof(sound_irq));
2787 fixup_device_tree_efika_add_phy();
2790 #define fixup_device_tree_efika()
2793 static void __init fixup_device_tree(
void)
2802 static void __init prom_find_boot_cpu(
void)
2810 if (prom_getprop(_prom->
chosen,
"cpu", &prom_cpu,
sizeof(prom_cpu)) <= 0)
2813 cpu_pkg = call_prom(
"instance-to-package", 1, 1, prom_cpu);
2815 prom_getprop(cpu_pkg,
"reg", &getprop_rval,
sizeof(getprop_rval));
2816 _prom->
cpu = getprop_rval;
2821 static void __init prom_check_initrd(
unsigned long r3,
unsigned long r4)
2823 #ifdef CONFIG_BLK_DEV_INITRD
2826 if (r3 && r4 && r4 != 0xdeadbeef) {
2830 RELOC(prom_initrd_end) =
RELOC(prom_initrd_start) +
r4;
2832 val =
RELOC(prom_initrd_start);
2835 val =
RELOC(prom_initrd_end);
2839 reserve_mem(
RELOC(prom_initrd_start),
2840 RELOC(prom_initrd_end) -
RELOC(prom_initrd_start));
2856 unsigned long r6,
unsigned long r7,
2857 unsigned long kbase)
2867 _prom = &
RELOC(prom);
2878 prom_init_client_services(pp);
2897 RELOC(of_platform) = prom_find_machine_type();
2900 #ifndef CONFIG_NONSTATIC_KERNEL
2903 prom_panic(
"Error: You can't boot a kdump kernel from OF!\n");
2909 prom_check_initrd(r3, r4);
2911 #if defined(CONFIG_PPC_PSERIES) || defined(CONFIG_PPC_POWERNV)
2917 prom_send_capabilities();
2929 early_cmdline_parse();
2939 prom_find_boot_cpu();
2944 prom_check_displays();
2953 prom_initialize_tce_table();
2962 prom_instantiate_rtas();
2964 #ifdef CONFIG_PPC_POWERNV
2969 prom_opal_hold_cpus();
2970 prom_opal_takeover();
2973 prom_instantiate_opal();
2978 prom_instantiate_sml();
2993 if (
RELOC(prom_memory_limit))
2995 &
RELOC(prom_memory_limit),
2996 sizeof(prom_memory_limit));
2998 if (
RELOC(prom_iommu_off))
3002 if (
RELOC(prom_iommu_force_on))
3006 if (
RELOC(prom_tce_alloc_start)) {
3008 &
RELOC(prom_tce_alloc_start),
3009 sizeof(prom_tce_alloc_start));
3011 &
RELOC(prom_tce_alloc_end),
3012 sizeof(prom_tce_alloc_end));
3019 fixup_device_tree();
3025 flatten_device_tree();
3042 call_prom(
"quiesce", 0, 0);
3049 hdr =
RELOC(dt_header_start);
3061 #ifdef CONFIG_PPC_EARLY_DEBUG_OPAL
3064 RELOC(prom_opal_base),
RELOC(prom_opal_entry));
3066 __start(hdr, kbase, 0, 0, 0, 0, 0);