prom_init.c 54 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993
  1. /*
  2. *
  3. *
  4. * Procedures for interfacing to Open Firmware.
  5. *
  6. * Paul Mackerras August 1996.
  7. * Copyright (C) 1996 Paul Mackerras.
  8. *
  9. * Adapted for 64bit PowerPC by Dave Engebretsen and Peter Bergner.
  10. * {engebret|bergner}@us.ibm.com
  11. *
  12. * This program is free software; you can redistribute it and/or
  13. * modify it under the terms of the GNU General Public License
  14. * as published by the Free Software Foundation; either version
  15. * 2 of the License, or (at your option) any later version.
  16. */
  17. #undef DEBUG_PROM
  18. #include <stdarg.h>
  19. #include <linux/config.h>
  20. #include <linux/kernel.h>
  21. #include <linux/string.h>
  22. #include <linux/init.h>
  23. #include <linux/version.h>
  24. #include <linux/threads.h>
  25. #include <linux/spinlock.h>
  26. #include <linux/types.h>
  27. #include <linux/pci.h>
  28. #include <linux/proc_fs.h>
  29. #include <linux/stringify.h>
  30. #include <linux/delay.h>
  31. #include <linux/initrd.h>
  32. #include <linux/bitops.h>
  33. #include <asm/prom.h>
  34. #include <asm/rtas.h>
  35. #include <asm/abs_addr.h>
  36. #include <asm/page.h>
  37. #include <asm/processor.h>
  38. #include <asm/irq.h>
  39. #include <asm/io.h>
  40. #include <asm/smp.h>
  41. #include <asm/system.h>
  42. #include <asm/mmu.h>
  43. #include <asm/pgtable.h>
  44. #include <asm/pci.h>
  45. #include <asm/iommu.h>
  46. #include <asm/bootinfo.h>
  47. #include <asm/ppcdebug.h>
  48. #include <asm/btext.h>
  49. #include <asm/sections.h>
  50. #include <asm/machdep.h>
  51. #ifdef CONFIG_LOGO_LINUX_CLUT224
  52. #include <linux/linux_logo.h>
  53. extern const struct linux_logo logo_linux_clut224;
  54. #endif
  55. /*
  56. * Properties whose value is longer than this get excluded from our
  57. * copy of the device tree. This value does need to be big enough to
  58. * ensure that we don't lose things like the interrupt-map property
  59. * on a PCI-PCI bridge.
  60. */
  61. #define MAX_PROPERTY_LENGTH (1UL * 1024 * 1024)
  62. /*
  63. * Eventually bump that one up
  64. */
  65. #define DEVTREE_CHUNK_SIZE 0x100000
  66. /*
  67. * This is the size of the local memory reserve map that gets copied
  68. * into the boot params passed to the kernel. That size is totally
  69. * flexible as the kernel just reads the list until it encounters an
  70. * entry with size 0, so it can be changed without breaking binary
  71. * compatibility
  72. */
  73. #define MEM_RESERVE_MAP_SIZE 8
  74. /*
  75. * prom_init() is called very early on, before the kernel text
  76. * and data have been mapped to KERNELBASE. At this point the code
  77. * is running at whatever address it has been loaded at, so
  78. * references to extern and static variables must be relocated
  79. * explicitly. The procedure reloc_offset() returns the address
  80. * we're currently running at minus the address we were linked at.
  81. * (Note that strings count as static variables.)
  82. *
  83. * Because OF may have mapped I/O devices into the area starting at
  84. * KERNELBASE, particularly on CHRP machines, we can't safely call
  85. * OF once the kernel has been mapped to KERNELBASE. Therefore all
  86. * OF calls should be done within prom_init(), and prom_init()
  87. * and all routines called within it must be careful to relocate
  88. * references as necessary.
  89. *
  90. * Note that the bss is cleared *after* prom_init runs, so we have
  91. * to make sure that any static or extern variables it accesses
  92. * are put in the data segment.
  93. */
  94. #define PROM_BUG() do { \
  95. prom_printf("kernel BUG at %s line 0x%x!\n", \
  96. RELOC(__FILE__), __LINE__); \
  97. __asm__ __volatile__(".long " BUG_ILLEGAL_INSTR); \
  98. } while (0)
  99. #ifdef DEBUG_PROM
  100. #define prom_debug(x...) prom_printf(x)
  101. #else
  102. #define prom_debug(x...)
  103. #endif
  104. typedef u32 prom_arg_t;
  105. struct prom_args {
  106. u32 service;
  107. u32 nargs;
  108. u32 nret;
  109. prom_arg_t args[10];
  110. prom_arg_t *rets; /* Pointer to return values in args[16]. */
  111. };
  112. struct prom_t {
  113. unsigned long entry;
  114. ihandle root;
  115. ihandle chosen;
  116. int cpu;
  117. ihandle stdout;
  118. ihandle disp_node;
  119. struct prom_args args;
  120. unsigned long version;
  121. unsigned long root_size_cells;
  122. unsigned long root_addr_cells;
  123. };
  124. struct pci_reg_property {
  125. struct pci_address addr;
  126. u32 size_hi;
  127. u32 size_lo;
  128. };
  129. struct mem_map_entry {
  130. u64 base;
  131. u64 size;
  132. };
  133. typedef u32 cell_t;
  134. extern void __start(unsigned long r3, unsigned long r4, unsigned long r5);
  135. extern void enter_prom(struct prom_args *args, unsigned long entry);
  136. extern void copy_and_flush(unsigned long dest, unsigned long src,
  137. unsigned long size, unsigned long offset);
  138. extern unsigned long klimit;
  139. /* prom structure */
  140. static struct prom_t __initdata prom;
  141. #define PROM_SCRATCH_SIZE 256
  142. static char __initdata of_stdout_device[256];
  143. static char __initdata prom_scratch[PROM_SCRATCH_SIZE];
  144. static unsigned long __initdata dt_header_start;
  145. static unsigned long __initdata dt_struct_start, dt_struct_end;
  146. static unsigned long __initdata dt_string_start, dt_string_end;
  147. static unsigned long __initdata prom_initrd_start, prom_initrd_end;
  148. static int __initdata iommu_force_on;
  149. static int __initdata ppc64_iommu_off;
  150. static int __initdata of_platform;
  151. static char __initdata prom_cmd_line[COMMAND_LINE_SIZE];
  152. static unsigned long __initdata prom_memory_limit;
  153. static unsigned long __initdata prom_tce_alloc_start;
  154. static unsigned long __initdata prom_tce_alloc_end;
  155. static unsigned long __initdata alloc_top;
  156. static unsigned long __initdata alloc_top_high;
  157. static unsigned long __initdata alloc_bottom;
  158. static unsigned long __initdata rmo_top;
  159. static unsigned long __initdata ram_top;
  160. static struct mem_map_entry __initdata mem_reserve_map[MEM_RESERVE_MAP_SIZE];
  161. static int __initdata mem_reserve_cnt;
  162. static cell_t __initdata regbuf[1024];
  163. #define MAX_CPU_THREADS 2
  164. /* TO GO */
  165. #ifdef CONFIG_HMT
  166. struct {
  167. unsigned int pir;
  168. unsigned int threadid;
  169. } hmt_thread_data[NR_CPUS];
  170. #endif /* CONFIG_HMT */
  171. /*
  172. * This are used in calls to call_prom. The 4th and following
  173. * arguments to call_prom should be 32-bit values. 64 bit values
  174. * are truncated to 32 bits (and fortunately don't get interpreted
  175. * as two arguments).
  176. */
  177. #define ADDR(x) (u32) ((unsigned long)(x) - offset)
  178. /* This is the one and *ONLY* place where we actually call open
  179. * firmware from, since we need to make sure we're running in 32b
  180. * mode when we do. We switch back to 64b mode upon return.
  181. */
  182. #define PROM_ERROR (-1)
  183. static int __init call_prom(const char *service, int nargs, int nret, ...)
  184. {
  185. int i;
  186. unsigned long offset = reloc_offset();
  187. struct prom_t *_prom = PTRRELOC(&prom);
  188. va_list list;
  189. _prom->args.service = ADDR(service);
  190. _prom->args.nargs = nargs;
  191. _prom->args.nret = nret;
  192. _prom->args.rets = (prom_arg_t *)&(_prom->args.args[nargs]);
  193. va_start(list, nret);
  194. for (i=0; i < nargs; i++)
  195. _prom->args.args[i] = va_arg(list, prom_arg_t);
  196. va_end(list);
  197. for (i=0; i < nret ;i++)
  198. _prom->args.rets[i] = 0;
  199. enter_prom(&_prom->args, _prom->entry);
  200. return (nret > 0) ? _prom->args.rets[0] : 0;
  201. }
  202. static unsigned int __init prom_claim(unsigned long virt, unsigned long size,
  203. unsigned long align)
  204. {
  205. return (unsigned int)call_prom("claim", 3, 1,
  206. (prom_arg_t)virt, (prom_arg_t)size,
  207. (prom_arg_t)align);
  208. }
  209. static void __init prom_print(const char *msg)
  210. {
  211. const char *p, *q;
  212. unsigned long offset = reloc_offset();
  213. struct prom_t *_prom = PTRRELOC(&prom);
  214. if (_prom->stdout == 0)
  215. return;
  216. for (p = msg; *p != 0; p = q) {
  217. for (q = p; *q != 0 && *q != '\n'; ++q)
  218. ;
  219. if (q > p)
  220. call_prom("write", 3, 1, _prom->stdout, p, q - p);
  221. if (*q == 0)
  222. break;
  223. ++q;
  224. call_prom("write", 3, 1, _prom->stdout, ADDR("\r\n"), 2);
  225. }
  226. }
  227. static void __init prom_print_hex(unsigned long val)
  228. {
  229. unsigned long offset = reloc_offset();
  230. int i, nibbles = sizeof(val)*2;
  231. char buf[sizeof(val)*2+1];
  232. struct prom_t *_prom = PTRRELOC(&prom);
  233. for (i = nibbles-1; i >= 0; i--) {
  234. buf[i] = (val & 0xf) + '0';
  235. if (buf[i] > '9')
  236. buf[i] += ('a'-'0'-10);
  237. val >>= 4;
  238. }
  239. buf[nibbles] = '\0';
  240. call_prom("write", 3, 1, _prom->stdout, buf, nibbles);
  241. }
  242. static void __init prom_printf(const char *format, ...)
  243. {
  244. unsigned long offset = reloc_offset();
  245. const char *p, *q, *s;
  246. va_list args;
  247. unsigned long v;
  248. struct prom_t *_prom = PTRRELOC(&prom);
  249. va_start(args, format);
  250. for (p = PTRRELOC(format); *p != 0; p = q) {
  251. for (q = p; *q != 0 && *q != '\n' && *q != '%'; ++q)
  252. ;
  253. if (q > p)
  254. call_prom("write", 3, 1, _prom->stdout, p, q - p);
  255. if (*q == 0)
  256. break;
  257. if (*q == '\n') {
  258. ++q;
  259. call_prom("write", 3, 1, _prom->stdout,
  260. ADDR("\r\n"), 2);
  261. continue;
  262. }
  263. ++q;
  264. if (*q == 0)
  265. break;
  266. switch (*q) {
  267. case 's':
  268. ++q;
  269. s = va_arg(args, const char *);
  270. prom_print(s);
  271. break;
  272. case 'x':
  273. ++q;
  274. v = va_arg(args, unsigned long);
  275. prom_print_hex(v);
  276. break;
  277. }
  278. }
  279. }
  280. static void __init __attribute__((noreturn)) prom_panic(const char *reason)
  281. {
  282. unsigned long offset = reloc_offset();
  283. prom_print(PTRRELOC(reason));
  284. /* ToDo: should put up an SRC here */
  285. call_prom("exit", 0, 0);
  286. for (;;) /* should never get here */
  287. ;
  288. }
  289. static int __init prom_next_node(phandle *nodep)
  290. {
  291. phandle node;
  292. if ((node = *nodep) != 0
  293. && (*nodep = call_prom("child", 1, 1, node)) != 0)
  294. return 1;
  295. if ((*nodep = call_prom("peer", 1, 1, node)) != 0)
  296. return 1;
  297. for (;;) {
  298. if ((node = call_prom("parent", 1, 1, node)) == 0)
  299. return 0;
  300. if ((*nodep = call_prom("peer", 1, 1, node)) != 0)
  301. return 1;
  302. }
  303. }
  304. static int __init prom_getprop(phandle node, const char *pname,
  305. void *value, size_t valuelen)
  306. {
  307. unsigned long offset = reloc_offset();
  308. return call_prom("getprop", 4, 1, node, ADDR(pname),
  309. (u32)(unsigned long) value, (u32) valuelen);
  310. }
  311. static int __init prom_getproplen(phandle node, const char *pname)
  312. {
  313. unsigned long offset = reloc_offset();
  314. return call_prom("getproplen", 2, 1, node, ADDR(pname));
  315. }
  316. static int __init prom_setprop(phandle node, const char *pname,
  317. void *value, size_t valuelen)
  318. {
  319. unsigned long offset = reloc_offset();
  320. return call_prom("setprop", 4, 1, node, ADDR(pname),
  321. (u32)(unsigned long) value, (u32) valuelen);
  322. }
  323. /* We can't use the standard versions because of RELOC headaches. */
  324. #define isxdigit(c) (('0' <= (c) && (c) <= '9') \
  325. || ('a' <= (c) && (c) <= 'f') \
  326. || ('A' <= (c) && (c) <= 'F'))
  327. #define isdigit(c) ('0' <= (c) && (c) <= '9')
  328. #define islower(c) ('a' <= (c) && (c) <= 'z')
  329. #define toupper(c) (islower(c) ? ((c) - 'a' + 'A') : (c))
  330. unsigned long prom_strtoul(const char *cp, const char **endp)
  331. {
  332. unsigned long result = 0, base = 10, value;
  333. if (*cp == '0') {
  334. base = 8;
  335. cp++;
  336. if (toupper(*cp) == 'X') {
  337. cp++;
  338. base = 16;
  339. }
  340. }
  341. while (isxdigit(*cp) &&
  342. (value = isdigit(*cp) ? *cp - '0' : toupper(*cp) - 'A' + 10) < base) {
  343. result = result * base + value;
  344. cp++;
  345. }
  346. if (endp)
  347. *endp = cp;
  348. return result;
  349. }
  350. unsigned long prom_memparse(const char *ptr, const char **retptr)
  351. {
  352. unsigned long ret = prom_strtoul(ptr, retptr);
  353. int shift = 0;
  354. /*
  355. * We can't use a switch here because GCC *may* generate a
  356. * jump table which won't work, because we're not running at
  357. * the address we're linked at.
  358. */
  359. if ('G' == **retptr || 'g' == **retptr)
  360. shift = 30;
  361. if ('M' == **retptr || 'm' == **retptr)
  362. shift = 20;
  363. if ('K' == **retptr || 'k' == **retptr)
  364. shift = 10;
  365. if (shift) {
  366. ret <<= shift;
  367. (*retptr)++;
  368. }
  369. return ret;
  370. }
  371. /*
  372. * Early parsing of the command line passed to the kernel, used for
  373. * "mem=x" and the options that affect the iommu
  374. */
  375. static void __init early_cmdline_parse(void)
  376. {
  377. unsigned long offset = reloc_offset();
  378. struct prom_t *_prom = PTRRELOC(&prom);
  379. char *opt, *p;
  380. int l = 0;
  381. RELOC(prom_cmd_line[0]) = 0;
  382. p = RELOC(prom_cmd_line);
  383. if ((long)_prom->chosen > 0)
  384. l = prom_getprop(_prom->chosen, "bootargs", p, COMMAND_LINE_SIZE-1);
  385. #ifdef CONFIG_CMDLINE
  386. if (l == 0) /* dbl check */
  387. strlcpy(RELOC(prom_cmd_line),
  388. RELOC(CONFIG_CMDLINE), sizeof(prom_cmd_line));
  389. #endif /* CONFIG_CMDLINE */
  390. prom_printf("command line: %s\n", RELOC(prom_cmd_line));
  391. opt = strstr(RELOC(prom_cmd_line), RELOC("iommu="));
  392. if (opt) {
  393. prom_printf("iommu opt is: %s\n", opt);
  394. opt += 6;
  395. while (*opt && *opt == ' ')
  396. opt++;
  397. if (!strncmp(opt, RELOC("off"), 3))
  398. RELOC(ppc64_iommu_off) = 1;
  399. else if (!strncmp(opt, RELOC("force"), 5))
  400. RELOC(iommu_force_on) = 1;
  401. }
  402. opt = strstr(RELOC(prom_cmd_line), RELOC("mem="));
  403. if (opt) {
  404. opt += 4;
  405. RELOC(prom_memory_limit) = prom_memparse(opt, (const char **)&opt);
  406. /* Align to 16 MB == size of large page */
  407. RELOC(prom_memory_limit) = ALIGN(RELOC(prom_memory_limit), 0x1000000);
  408. }
  409. }
  410. /*
  411. * To tell the firmware what our capabilities are, we have to pass
  412. * it a fake 32-bit ELF header containing a couple of PT_NOTE sections
  413. * that contain structures that contain the actual values.
  414. */
  415. static struct fake_elf {
  416. Elf32_Ehdr elfhdr;
  417. Elf32_Phdr phdr[2];
  418. struct chrpnote {
  419. u32 namesz;
  420. u32 descsz;
  421. u32 type;
  422. char name[8]; /* "PowerPC" */
  423. struct chrpdesc {
  424. u32 real_mode;
  425. u32 real_base;
  426. u32 real_size;
  427. u32 virt_base;
  428. u32 virt_size;
  429. u32 load_base;
  430. } chrpdesc;
  431. } chrpnote;
  432. struct rpanote {
  433. u32 namesz;
  434. u32 descsz;
  435. u32 type;
  436. char name[24]; /* "IBM,RPA-Client-Config" */
  437. struct rpadesc {
  438. u32 lpar_affinity;
  439. u32 min_rmo_size;
  440. u32 min_rmo_percent;
  441. u32 max_pft_size;
  442. u32 splpar;
  443. u32 min_load;
  444. u32 new_mem_def;
  445. u32 ignore_me;
  446. } rpadesc;
  447. } rpanote;
  448. } fake_elf = {
  449. .elfhdr = {
  450. .e_ident = { 0x7f, 'E', 'L', 'F',
  451. ELFCLASS32, ELFDATA2MSB, EV_CURRENT },
  452. .e_type = ET_EXEC, /* yeah right */
  453. .e_machine = EM_PPC,
  454. .e_version = EV_CURRENT,
  455. .e_phoff = offsetof(struct fake_elf, phdr),
  456. .e_phentsize = sizeof(Elf32_Phdr),
  457. .e_phnum = 2
  458. },
  459. .phdr = {
  460. [0] = {
  461. .p_type = PT_NOTE,
  462. .p_offset = offsetof(struct fake_elf, chrpnote),
  463. .p_filesz = sizeof(struct chrpnote)
  464. }, [1] = {
  465. .p_type = PT_NOTE,
  466. .p_offset = offsetof(struct fake_elf, rpanote),
  467. .p_filesz = sizeof(struct rpanote)
  468. }
  469. },
  470. .chrpnote = {
  471. .namesz = sizeof("PowerPC"),
  472. .descsz = sizeof(struct chrpdesc),
  473. .type = 0x1275,
  474. .name = "PowerPC",
  475. .chrpdesc = {
  476. .real_mode = ~0U, /* ~0 means "don't care" */
  477. .real_base = ~0U,
  478. .real_size = ~0U,
  479. .virt_base = ~0U,
  480. .virt_size = ~0U,
  481. .load_base = ~0U
  482. },
  483. },
  484. .rpanote = {
  485. .namesz = sizeof("IBM,RPA-Client-Config"),
  486. .descsz = sizeof(struct rpadesc),
  487. .type = 0x12759999,
  488. .name = "IBM,RPA-Client-Config",
  489. .rpadesc = {
  490. .lpar_affinity = 0,
  491. .min_rmo_size = 64, /* in megabytes */
  492. .min_rmo_percent = 0,
  493. .max_pft_size = 48, /* 2^48 bytes max PFT size */
  494. .splpar = 1,
  495. .min_load = ~0U,
  496. .new_mem_def = 0
  497. }
  498. }
  499. };
  500. static void __init prom_send_capabilities(void)
  501. {
  502. unsigned long offset = reloc_offset();
  503. ihandle elfloader;
  504. int ret;
  505. elfloader = call_prom("open", 1, 1, ADDR("/packages/elf-loader"));
  506. if (elfloader == 0) {
  507. prom_printf("couldn't open /packages/elf-loader\n");
  508. return;
  509. }
  510. ret = call_prom("call-method", 3, 1, ADDR("process-elf-header"),
  511. elfloader, ADDR(&fake_elf));
  512. call_prom("close", 1, 0, elfloader);
  513. }
  514. /*
  515. * Memory allocation strategy... our layout is normally:
  516. *
  517. * at 14Mb or more we vmlinux, then a gap and initrd. In some rare cases, initrd
  518. * might end up beeing before the kernel though. We assume this won't override
  519. * the final kernel at 0, we have no provision to handle that in this version,
  520. * but it should hopefully never happen.
  521. *
  522. * alloc_top is set to the top of RMO, eventually shrink down if the TCEs overlap
  523. * alloc_bottom is set to the top of kernel/initrd
  524. *
  525. * from there, allocations are done that way : rtas is allocated topmost, and
  526. * the device-tree is allocated from the bottom. We try to grow the device-tree
  527. * allocation as we progress. If we can't, then we fail, we don't currently have
  528. * a facility to restart elsewhere, but that shouldn't be necessary neither
  529. *
  530. * Note that calls to reserve_mem have to be done explicitely, memory allocated
  531. * with either alloc_up or alloc_down isn't automatically reserved.
  532. */
  533. /*
  534. * Allocates memory in the RMO upward from the kernel/initrd
  535. *
  536. * When align is 0, this is a special case, it means to allocate in place
  537. * at the current location of alloc_bottom or fail (that is basically
  538. * extending the previous allocation). Used for the device-tree flattening
  539. */
  540. static unsigned long __init alloc_up(unsigned long size, unsigned long align)
  541. {
  542. unsigned long offset = reloc_offset();
  543. unsigned long base = _ALIGN_UP(RELOC(alloc_bottom), align);
  544. unsigned long addr = 0;
  545. prom_debug("alloc_up(%x, %x)\n", size, align);
  546. if (RELOC(ram_top) == 0)
  547. prom_panic("alloc_up() called with mem not initialized\n");
  548. if (align)
  549. base = _ALIGN_UP(RELOC(alloc_bottom), align);
  550. else
  551. base = RELOC(alloc_bottom);
  552. for(; (base + size) <= RELOC(alloc_top);
  553. base = _ALIGN_UP(base + 0x100000, align)) {
  554. prom_debug(" trying: 0x%x\n\r", base);
  555. addr = (unsigned long)prom_claim(base, size, 0);
  556. if ((int)addr != PROM_ERROR)
  557. break;
  558. addr = 0;
  559. if (align == 0)
  560. break;
  561. }
  562. if (addr == 0)
  563. return 0;
  564. RELOC(alloc_bottom) = addr;
  565. prom_debug(" -> %x\n", addr);
  566. prom_debug(" alloc_bottom : %x\n", RELOC(alloc_bottom));
  567. prom_debug(" alloc_top : %x\n", RELOC(alloc_top));
  568. prom_debug(" alloc_top_hi : %x\n", RELOC(alloc_top_high));
  569. prom_debug(" rmo_top : %x\n", RELOC(rmo_top));
  570. prom_debug(" ram_top : %x\n", RELOC(ram_top));
  571. return addr;
  572. }
  573. /*
  574. * Allocates memory downard, either from top of RMO, or if highmem
  575. * is set, from the top of RAM. Note that this one doesn't handle
  576. * failures. In does claim memory if highmem is not set.
  577. */
  578. static unsigned long __init alloc_down(unsigned long size, unsigned long align,
  579. int highmem)
  580. {
  581. unsigned long offset = reloc_offset();
  582. unsigned long base, addr = 0;
  583. prom_debug("alloc_down(%x, %x, %s)\n", size, align,
  584. highmem ? RELOC("(high)") : RELOC("(low)"));
  585. if (RELOC(ram_top) == 0)
  586. prom_panic("alloc_down() called with mem not initialized\n");
  587. if (highmem) {
  588. /* Carve out storage for the TCE table. */
  589. addr = _ALIGN_DOWN(RELOC(alloc_top_high) - size, align);
  590. if (addr <= RELOC(alloc_bottom))
  591. return 0;
  592. else {
  593. /* Will we bump into the RMO ? If yes, check out that we
  594. * didn't overlap existing allocations there, if we did,
  595. * we are dead, we must be the first in town !
  596. */
  597. if (addr < RELOC(rmo_top)) {
  598. /* Good, we are first */
  599. if (RELOC(alloc_top) == RELOC(rmo_top))
  600. RELOC(alloc_top) = RELOC(rmo_top) = addr;
  601. else
  602. return 0;
  603. }
  604. RELOC(alloc_top_high) = addr;
  605. }
  606. goto bail;
  607. }
  608. base = _ALIGN_DOWN(RELOC(alloc_top) - size, align);
  609. for(; base > RELOC(alloc_bottom); base = _ALIGN_DOWN(base - 0x100000, align)) {
  610. prom_debug(" trying: 0x%x\n\r", base);
  611. addr = (unsigned long)prom_claim(base, size, 0);
  612. if ((int)addr != PROM_ERROR)
  613. break;
  614. addr = 0;
  615. }
  616. if (addr == 0)
  617. return 0;
  618. RELOC(alloc_top) = addr;
  619. bail:
  620. prom_debug(" -> %x\n", addr);
  621. prom_debug(" alloc_bottom : %x\n", RELOC(alloc_bottom));
  622. prom_debug(" alloc_top : %x\n", RELOC(alloc_top));
  623. prom_debug(" alloc_top_hi : %x\n", RELOC(alloc_top_high));
  624. prom_debug(" rmo_top : %x\n", RELOC(rmo_top));
  625. prom_debug(" ram_top : %x\n", RELOC(ram_top));
  626. return addr;
  627. }
  628. /*
  629. * Parse a "reg" cell
  630. */
  631. static unsigned long __init prom_next_cell(int s, cell_t **cellp)
  632. {
  633. cell_t *p = *cellp;
  634. unsigned long r = 0;
  635. /* Ignore more than 2 cells */
  636. while (s > 2) {
  637. p++;
  638. s--;
  639. }
  640. while (s) {
  641. r <<= 32;
  642. r |= *(p++);
  643. s--;
  644. }
  645. *cellp = p;
  646. return r;
  647. }
  648. /*
  649. * Very dumb function for adding to the memory reserve list, but
  650. * we don't need anything smarter at this point
  651. *
  652. * XXX Eventually check for collisions. They should NEVER happen
  653. * if problems seem to show up, it would be a good start to track
  654. * them down.
  655. */
  656. static void reserve_mem(unsigned long base, unsigned long size)
  657. {
  658. unsigned long offset = reloc_offset();
  659. unsigned long top = base + size;
  660. unsigned long cnt = RELOC(mem_reserve_cnt);
  661. if (size == 0)
  662. return;
  663. /* We need to always keep one empty entry so that we
  664. * have our terminator with "size" set to 0 since we are
  665. * dumb and just copy this entire array to the boot params
  666. */
  667. base = _ALIGN_DOWN(base, PAGE_SIZE);
  668. top = _ALIGN_UP(top, PAGE_SIZE);
  669. size = top - base;
  670. if (cnt >= (MEM_RESERVE_MAP_SIZE - 1))
  671. prom_panic("Memory reserve map exhausted !\n");
  672. RELOC(mem_reserve_map)[cnt].base = base;
  673. RELOC(mem_reserve_map)[cnt].size = size;
  674. RELOC(mem_reserve_cnt) = cnt + 1;
  675. }
  676. /*
  677. * Initialize memory allocation mecanism, parse "memory" nodes and
  678. * obtain that way the top of memory and RMO to setup out local allocator
  679. */
  680. static void __init prom_init_mem(void)
  681. {
  682. phandle node;
  683. char *path, type[64];
  684. unsigned int plen;
  685. cell_t *p, *endp;
  686. unsigned long offset = reloc_offset();
  687. struct prom_t *_prom = PTRRELOC(&prom);
  688. /*
  689. * We iterate the memory nodes to find
  690. * 1) top of RMO (first node)
  691. * 2) top of memory
  692. */
  693. prom_debug("root_addr_cells: %x\n", (long)_prom->root_addr_cells);
  694. prom_debug("root_size_cells: %x\n", (long)_prom->root_size_cells);
  695. prom_debug("scanning memory:\n");
  696. path = RELOC(prom_scratch);
  697. for (node = 0; prom_next_node(&node); ) {
  698. type[0] = 0;
  699. prom_getprop(node, "device_type", type, sizeof(type));
  700. if (strcmp(type, RELOC("memory")))
  701. continue;
  702. plen = prom_getprop(node, "reg", RELOC(regbuf), sizeof(regbuf));
  703. if (plen > sizeof(regbuf)) {
  704. prom_printf("memory node too large for buffer !\n");
  705. plen = sizeof(regbuf);
  706. }
  707. p = RELOC(regbuf);
  708. endp = p + (plen / sizeof(cell_t));
  709. #ifdef DEBUG_PROM
  710. memset(path, 0, PROM_SCRATCH_SIZE);
  711. call_prom("package-to-path", 3, 1, node, path, PROM_SCRATCH_SIZE-1);
  712. prom_debug(" node %s :\n", path);
  713. #endif /* DEBUG_PROM */
  714. while ((endp - p) >= (_prom->root_addr_cells + _prom->root_size_cells)) {
  715. unsigned long base, size;
  716. base = prom_next_cell(_prom->root_addr_cells, &p);
  717. size = prom_next_cell(_prom->root_size_cells, &p);
  718. if (size == 0)
  719. continue;
  720. prom_debug(" %x %x\n", base, size);
  721. if (base == 0)
  722. RELOC(rmo_top) = size;
  723. if ((base + size) > RELOC(ram_top))
  724. RELOC(ram_top) = base + size;
  725. }
  726. }
  727. RELOC(alloc_bottom) = PAGE_ALIGN(RELOC(klimit) - offset + 0x4000);
  728. /* Check if we have an initrd after the kernel, if we do move our bottom
  729. * point to after it
  730. */
  731. if (RELOC(prom_initrd_start)) {
  732. if (RELOC(prom_initrd_end) > RELOC(alloc_bottom))
  733. RELOC(alloc_bottom) = PAGE_ALIGN(RELOC(prom_initrd_end));
  734. }
  735. /*
  736. * If prom_memory_limit is set we reduce the upper limits *except* for
  737. * alloc_top_high. This must be the real top of RAM so we can put
  738. * TCE's up there.
  739. */
  740. RELOC(alloc_top_high) = RELOC(ram_top);
  741. if (RELOC(prom_memory_limit)) {
  742. if (RELOC(prom_memory_limit) <= RELOC(alloc_bottom)) {
  743. prom_printf("Ignoring mem=%x <= alloc_bottom.\n",
  744. RELOC(prom_memory_limit));
  745. RELOC(prom_memory_limit) = 0;
  746. } else if (RELOC(prom_memory_limit) >= RELOC(ram_top)) {
  747. prom_printf("Ignoring mem=%x >= ram_top.\n",
  748. RELOC(prom_memory_limit));
  749. RELOC(prom_memory_limit) = 0;
  750. } else {
  751. RELOC(ram_top) = RELOC(prom_memory_limit);
  752. RELOC(rmo_top) = min(RELOC(rmo_top), RELOC(prom_memory_limit));
  753. }
  754. }
  755. /*
  756. * Setup our top alloc point, that is top of RMO or top of
  757. * segment 0 when running non-LPAR.
  758. */
  759. if ( RELOC(of_platform) == PLATFORM_PSERIES_LPAR )
  760. RELOC(alloc_top) = RELOC(rmo_top);
  761. else
  762. RELOC(alloc_top) = RELOC(rmo_top) = min(0x40000000ul, RELOC(ram_top));
  763. prom_printf("memory layout at init:\n");
  764. prom_printf(" memory_limit : %x (16 MB aligned)\n", RELOC(prom_memory_limit));
  765. prom_printf(" alloc_bottom : %x\n", RELOC(alloc_bottom));
  766. prom_printf(" alloc_top : %x\n", RELOC(alloc_top));
  767. prom_printf(" alloc_top_hi : %x\n", RELOC(alloc_top_high));
  768. prom_printf(" rmo_top : %x\n", RELOC(rmo_top));
  769. prom_printf(" ram_top : %x\n", RELOC(ram_top));
  770. }
  771. /*
  772. * Allocate room for and instanciate RTAS
  773. */
  774. static void __init prom_instantiate_rtas(void)
  775. {
  776. unsigned long offset = reloc_offset();
  777. struct prom_t *_prom = PTRRELOC(&prom);
  778. phandle prom_rtas, rtas_node;
  779. u32 base, entry = 0;
  780. u32 size = 0;
  781. prom_debug("prom_instantiate_rtas: start...\n");
  782. prom_rtas = call_prom("finddevice", 1, 1, ADDR("/rtas"));
  783. prom_debug("prom_rtas: %x\n", prom_rtas);
  784. if (prom_rtas == (phandle) -1)
  785. return;
  786. prom_getprop(prom_rtas, "rtas-size", &size, sizeof(size));
  787. if (size == 0)
  788. return;
  789. base = alloc_down(size, PAGE_SIZE, 0);
  790. if (base == 0) {
  791. prom_printf("RTAS allocation failed !\n");
  792. return;
  793. }
  794. prom_printf("instantiating rtas at 0x%x", base);
  795. rtas_node = call_prom("open", 1, 1, ADDR("/rtas"));
  796. prom_printf("...");
  797. if (call_prom("call-method", 3, 2,
  798. ADDR("instantiate-rtas"),
  799. rtas_node, base) != PROM_ERROR) {
  800. entry = (long)_prom->args.rets[1];
  801. }
  802. if (entry == 0) {
  803. prom_printf(" failed\n");
  804. return;
  805. }
  806. prom_printf(" done\n");
  807. reserve_mem(base, size);
  808. prom_setprop(prom_rtas, "linux,rtas-base", &base, sizeof(base));
  809. prom_setprop(prom_rtas, "linux,rtas-entry", &entry, sizeof(entry));
  810. prom_debug("rtas base = 0x%x\n", base);
  811. prom_debug("rtas entry = 0x%x\n", entry);
  812. prom_debug("rtas size = 0x%x\n", (long)size);
  813. prom_debug("prom_instantiate_rtas: end...\n");
  814. }
  815. /*
  816. * Allocate room for and initialize TCE tables
  817. */
  818. static void __init prom_initialize_tce_table(void)
  819. {
  820. phandle node;
  821. ihandle phb_node;
  822. unsigned long offset = reloc_offset();
  823. char compatible[64], type[64], model[64];
  824. char *path = RELOC(prom_scratch);
  825. u64 base, align;
  826. u32 minalign, minsize;
  827. u64 tce_entry, *tce_entryp;
  828. u64 local_alloc_top, local_alloc_bottom;
  829. u64 i;
  830. if (RELOC(ppc64_iommu_off))
  831. return;
  832. prom_debug("starting prom_initialize_tce_table\n");
  833. /* Cache current top of allocs so we reserve a single block */
  834. local_alloc_top = RELOC(alloc_top_high);
  835. local_alloc_bottom = local_alloc_top;
  836. /* Search all nodes looking for PHBs. */
  837. for (node = 0; prom_next_node(&node); ) {
  838. compatible[0] = 0;
  839. type[0] = 0;
  840. model[0] = 0;
  841. prom_getprop(node, "compatible",
  842. compatible, sizeof(compatible));
  843. prom_getprop(node, "device_type", type, sizeof(type));
  844. prom_getprop(node, "model", model, sizeof(model));
  845. if ((type[0] == 0) || (strstr(type, RELOC("pci")) == NULL))
  846. continue;
  847. /* Keep the old logic in tack to avoid regression. */
  848. if (compatible[0] != 0) {
  849. if ((strstr(compatible, RELOC("python")) == NULL) &&
  850. (strstr(compatible, RELOC("Speedwagon")) == NULL) &&
  851. (strstr(compatible, RELOC("Winnipeg")) == NULL))
  852. continue;
  853. } else if (model[0] != 0) {
  854. if ((strstr(model, RELOC("ython")) == NULL) &&
  855. (strstr(model, RELOC("peedwagon")) == NULL) &&
  856. (strstr(model, RELOC("innipeg")) == NULL))
  857. continue;
  858. }
  859. if (prom_getprop(node, "tce-table-minalign", &minalign,
  860. sizeof(minalign)) == PROM_ERROR)
  861. minalign = 0;
  862. if (prom_getprop(node, "tce-table-minsize", &minsize,
  863. sizeof(minsize)) == PROM_ERROR)
  864. minsize = 4UL << 20;
  865. /*
  866. * Even though we read what OF wants, we just set the table
  867. * size to 4 MB. This is enough to map 2GB of PCI DMA space.
  868. * By doing this, we avoid the pitfalls of trying to DMA to
  869. * MMIO space and the DMA alias hole.
  870. *
  871. * On POWER4, firmware sets the TCE region by assuming
  872. * each TCE table is 8MB. Using this memory for anything
  873. * else will impact performance, so we always allocate 8MB.
  874. * Anton
  875. */
  876. if (__is_processor(PV_POWER4) || __is_processor(PV_POWER4p))
  877. minsize = 8UL << 20;
  878. else
  879. minsize = 4UL << 20;
  880. /* Align to the greater of the align or size */
  881. align = max(minalign, minsize);
  882. base = alloc_down(minsize, align, 1);
  883. if (base == 0)
  884. prom_panic("ERROR, cannot find space for TCE table.\n");
  885. if (base < local_alloc_bottom)
  886. local_alloc_bottom = base;
  887. /* Save away the TCE table attributes for later use. */
  888. prom_setprop(node, "linux,tce-base", &base, sizeof(base));
  889. prom_setprop(node, "linux,tce-size", &minsize, sizeof(minsize));
  890. /* It seems OF doesn't null-terminate the path :-( */
  891. memset(path, 0, sizeof(path));
  892. /* Call OF to setup the TCE hardware */
  893. if (call_prom("package-to-path", 3, 1, node,
  894. path, PROM_SCRATCH_SIZE-1) == PROM_ERROR) {
  895. prom_printf("package-to-path failed\n");
  896. }
  897. prom_debug("TCE table: %s\n", path);
  898. prom_debug("\tnode = 0x%x\n", node);
  899. prom_debug("\tbase = 0x%x\n", base);
  900. prom_debug("\tsize = 0x%x\n", minsize);
  901. /* Initialize the table to have a one-to-one mapping
  902. * over the allocated size.
  903. */
  904. tce_entryp = (unsigned long *)base;
  905. for (i = 0; i < (minsize >> 3) ;tce_entryp++, i++) {
  906. tce_entry = (i << PAGE_SHIFT);
  907. tce_entry |= 0x3;
  908. *tce_entryp = tce_entry;
  909. }
  910. prom_printf("opening PHB %s", path);
  911. phb_node = call_prom("open", 1, 1, path);
  912. if ( (long)phb_node <= 0)
  913. prom_printf("... failed\n");
  914. else
  915. prom_printf("... done\n");
  916. call_prom("call-method", 6, 0, ADDR("set-64-bit-addressing"),
  917. phb_node, -1, minsize,
  918. (u32) base, (u32) (base >> 32));
  919. call_prom("close", 1, 0, phb_node);
  920. }
  921. reserve_mem(local_alloc_bottom, local_alloc_top - local_alloc_bottom);
  922. if (RELOC(prom_memory_limit)) {
  923. /*
  924. * We align the start to a 16MB boundary so we can map the TCE area
  925. * using large pages if possible. The end should be the top of RAM
  926. * so no need to align it.
  927. */
  928. RELOC(prom_tce_alloc_start) = _ALIGN_DOWN(local_alloc_bottom, 0x1000000);
  929. RELOC(prom_tce_alloc_end) = local_alloc_top;
  930. }
  931. /* Flag the first invalid entry */
  932. prom_debug("ending prom_initialize_tce_table\n");
  933. }
  934. /*
  935. * With CHRP SMP we need to use the OF to start the other
  936. * processors so we can't wait until smp_boot_cpus (the OF is
  937. * trashed by then) so we have to put the processors into
  938. * a holding pattern controlled by the kernel (not OF) before
  939. * we destroy the OF.
  940. *
  941. * This uses a chunk of low memory, puts some holding pattern
  942. * code there and sends the other processors off to there until
  943. * smp_boot_cpus tells them to do something. The holding pattern
  944. * checks that address until its cpu # is there, when it is that
  945. * cpu jumps to __secondary_start(). smp_boot_cpus() takes care
  946. * of setting those values.
  947. *
  948. * We also use physical address 0x4 here to tell when a cpu
  949. * is in its holding pattern code.
  950. *
  951. * Fixup comment... DRENG / PPPBBB - Peter
  952. *
  953. * -- Cort
  954. */
  955. static void __init prom_hold_cpus(void)
  956. {
  957. unsigned long i;
  958. unsigned int reg;
  959. phandle node;
  960. unsigned long offset = reloc_offset();
  961. char type[64];
  962. int cpuid = 0;
  963. unsigned int interrupt_server[MAX_CPU_THREADS];
  964. unsigned int cpu_threads, hw_cpu_num;
  965. int propsize;
  966. extern void __secondary_hold(void);
  967. extern unsigned long __secondary_hold_spinloop;
  968. extern unsigned long __secondary_hold_acknowledge;
  969. unsigned long *spinloop
  970. = (void *)virt_to_abs(&__secondary_hold_spinloop);
  971. unsigned long *acknowledge
  972. = (void *)virt_to_abs(&__secondary_hold_acknowledge);
  973. unsigned long secondary_hold
  974. = virt_to_abs(*PTRRELOC((unsigned long *)__secondary_hold));
  975. struct prom_t *_prom = PTRRELOC(&prom);
  976. prom_debug("prom_hold_cpus: start...\n");
  977. prom_debug(" 1) spinloop = 0x%x\n", (unsigned long)spinloop);
  978. prom_debug(" 1) *spinloop = 0x%x\n", *spinloop);
  979. prom_debug(" 1) acknowledge = 0x%x\n",
  980. (unsigned long)acknowledge);
  981. prom_debug(" 1) *acknowledge = 0x%x\n", *acknowledge);
  982. prom_debug(" 1) secondary_hold = 0x%x\n", secondary_hold);
  983. /* Set the common spinloop variable, so all of the secondary cpus
  984. * will block when they are awakened from their OF spinloop.
  985. * This must occur for both SMP and non SMP kernels, since OF will
  986. * be trashed when we move the kernel.
  987. */
  988. *spinloop = 0;
  989. #ifdef CONFIG_HMT
  990. for (i=0; i < NR_CPUS; i++) {
  991. RELOC(hmt_thread_data)[i].pir = 0xdeadbeef;
  992. }
  993. #endif
  994. /* look for cpus */
  995. for (node = 0; prom_next_node(&node); ) {
  996. type[0] = 0;
  997. prom_getprop(node, "device_type", type, sizeof(type));
  998. if (strcmp(type, RELOC("cpu")) != 0)
  999. continue;
  1000. /* Skip non-configured cpus. */
  1001. if (prom_getprop(node, "status", type, sizeof(type)) > 0)
  1002. if (strcmp(type, RELOC("okay")) != 0)
  1003. continue;
  1004. reg = -1;
  1005. prom_getprop(node, "reg", &reg, sizeof(reg));
  1006. prom_debug("\ncpuid = 0x%x\n", cpuid);
  1007. prom_debug("cpu hw idx = 0x%x\n", reg);
  1008. /* Init the acknowledge var which will be reset by
  1009. * the secondary cpu when it awakens from its OF
  1010. * spinloop.
  1011. */
  1012. *acknowledge = (unsigned long)-1;
  1013. propsize = prom_getprop(node, "ibm,ppc-interrupt-server#s",
  1014. &interrupt_server,
  1015. sizeof(interrupt_server));
  1016. if (propsize < 0) {
  1017. /* no property. old hardware has no SMT */
  1018. cpu_threads = 1;
  1019. interrupt_server[0] = reg; /* fake it with phys id */
  1020. } else {
  1021. /* We have a threaded processor */
  1022. cpu_threads = propsize / sizeof(u32);
  1023. if (cpu_threads > MAX_CPU_THREADS) {
  1024. prom_printf("SMT: too many threads!\n"
  1025. "SMT: found %x, max is %x\n",
  1026. cpu_threads, MAX_CPU_THREADS);
  1027. cpu_threads = 1; /* ToDo: panic? */
  1028. }
  1029. }
  1030. hw_cpu_num = interrupt_server[0];
  1031. if (hw_cpu_num != _prom->cpu) {
  1032. /* Primary Thread of non-boot cpu */
  1033. prom_printf("%x : starting cpu hw idx %x... ", cpuid, reg);
  1034. call_prom("start-cpu", 3, 0, node,
  1035. secondary_hold, reg);
  1036. for ( i = 0 ; (i < 100000000) &&
  1037. (*acknowledge == ((unsigned long)-1)); i++ )
  1038. mb();
  1039. if (*acknowledge == reg) {
  1040. prom_printf("done\n");
  1041. /* We have to get every CPU out of OF,
  1042. * even if we never start it. */
  1043. if (cpuid >= NR_CPUS)
  1044. goto next;
  1045. } else {
  1046. prom_printf("failed: %x\n", *acknowledge);
  1047. }
  1048. }
  1049. #ifdef CONFIG_SMP
  1050. else
  1051. prom_printf("%x : boot cpu %x\n", cpuid, reg);
  1052. #endif
  1053. next:
  1054. #ifdef CONFIG_SMP
  1055. /* Init paca for secondary threads. They start later. */
  1056. for (i=1; i < cpu_threads; i++) {
  1057. cpuid++;
  1058. if (cpuid >= NR_CPUS)
  1059. continue;
  1060. }
  1061. #endif /* CONFIG_SMP */
  1062. cpuid++;
  1063. }
  1064. #ifdef CONFIG_HMT
  1065. /* Only enable HMT on processors that provide support. */
  1066. if (__is_processor(PV_PULSAR) ||
  1067. __is_processor(PV_ICESTAR) ||
  1068. __is_processor(PV_SSTAR)) {
  1069. prom_printf(" starting secondary threads\n");
  1070. for (i = 0; i < NR_CPUS; i += 2) {
  1071. if (!cpu_online(i))
  1072. continue;
  1073. if (i == 0) {
  1074. unsigned long pir = mfspr(SPRN_PIR);
  1075. if (__is_processor(PV_PULSAR)) {
  1076. RELOC(hmt_thread_data)[i].pir =
  1077. pir & 0x1f;
  1078. } else {
  1079. RELOC(hmt_thread_data)[i].pir =
  1080. pir & 0x3ff;
  1081. }
  1082. }
  1083. }
  1084. } else {
  1085. prom_printf("Processor is not HMT capable\n");
  1086. }
  1087. #endif
  1088. if (cpuid > NR_CPUS)
  1089. prom_printf("WARNING: maximum CPUs (" __stringify(NR_CPUS)
  1090. ") exceeded: ignoring extras\n");
  1091. prom_debug("prom_hold_cpus: end...\n");
  1092. }
  1093. static void __init prom_init_client_services(unsigned long pp)
  1094. {
  1095. unsigned long offset = reloc_offset();
  1096. struct prom_t *_prom = PTRRELOC(&prom);
  1097. /* Get a handle to the prom entry point before anything else */
  1098. _prom->entry = pp;
  1099. /* Init default value for phys size */
  1100. _prom->root_size_cells = 1;
  1101. _prom->root_addr_cells = 2;
  1102. /* get a handle for the stdout device */
  1103. _prom->chosen = call_prom("finddevice", 1, 1, ADDR("/chosen"));
  1104. if ((long)_prom->chosen <= 0)
  1105. prom_panic("cannot find chosen"); /* msg won't be printed :( */
  1106. /* get device tree root */
  1107. _prom->root = call_prom("finddevice", 1, 1, ADDR("/"));
  1108. if ((long)_prom->root <= 0)
  1109. prom_panic("cannot find device tree root"); /* msg won't be printed :( */
  1110. }
  1111. static void __init prom_init_stdout(void)
  1112. {
  1113. unsigned long offset = reloc_offset();
  1114. struct prom_t *_prom = PTRRELOC(&prom);
  1115. char *path = RELOC(of_stdout_device);
  1116. char type[16];
  1117. u32 val;
  1118. if (prom_getprop(_prom->chosen, "stdout", &val, sizeof(val)) <= 0)
  1119. prom_panic("cannot find stdout");
  1120. _prom->stdout = val;
  1121. /* Get the full OF pathname of the stdout device */
  1122. memset(path, 0, 256);
  1123. call_prom("instance-to-path", 3, 1, _prom->stdout, path, 255);
  1124. val = call_prom("instance-to-package", 1, 1, _prom->stdout);
  1125. prom_setprop(_prom->chosen, "linux,stdout-package", &val, sizeof(val));
  1126. prom_printf("OF stdout device is: %s\n", RELOC(of_stdout_device));
  1127. prom_setprop(_prom->chosen, "linux,stdout-path",
  1128. RELOC(of_stdout_device), strlen(RELOC(of_stdout_device))+1);
  1129. /* If it's a display, note it */
  1130. memset(type, 0, sizeof(type));
  1131. prom_getprop(val, "device_type", type, sizeof(type));
  1132. if (strcmp(type, RELOC("display")) == 0) {
  1133. _prom->disp_node = val;
  1134. prom_setprop(val, "linux,boot-display", NULL, 0);
  1135. }
  1136. }
  1137. static void __init prom_close_stdin(void)
  1138. {
  1139. unsigned long offset = reloc_offset();
  1140. struct prom_t *_prom = PTRRELOC(&prom);
  1141. ihandle val;
  1142. if (prom_getprop(_prom->chosen, "stdin", &val, sizeof(val)) > 0)
  1143. call_prom("close", 1, 0, val);
  1144. }
  1145. static int __init prom_find_machine_type(void)
  1146. {
  1147. unsigned long offset = reloc_offset();
  1148. struct prom_t *_prom = PTRRELOC(&prom);
  1149. char compat[256];
  1150. int len, i = 0;
  1151. phandle rtas;
  1152. len = prom_getprop(_prom->root, "compatible",
  1153. compat, sizeof(compat)-1);
  1154. if (len > 0) {
  1155. compat[len] = 0;
  1156. while (i < len) {
  1157. char *p = &compat[i];
  1158. int sl = strlen(p);
  1159. if (sl == 0)
  1160. break;
  1161. if (strstr(p, RELOC("Power Macintosh")) ||
  1162. strstr(p, RELOC("MacRISC4")))
  1163. return PLATFORM_POWERMAC;
  1164. if (strstr(p, RELOC("Momentum,Maple")))
  1165. return PLATFORM_MAPLE;
  1166. i += sl + 1;
  1167. }
  1168. }
  1169. /* Default to pSeries. We need to know if we are running LPAR */
  1170. rtas = call_prom("finddevice", 1, 1, ADDR("/rtas"));
  1171. if (rtas != (phandle) -1) {
  1172. unsigned long x;
  1173. x = prom_getproplen(rtas, "ibm,hypertas-functions");
  1174. if (x != PROM_ERROR) {
  1175. prom_printf("Hypertas detected, assuming LPAR !\n");
  1176. return PLATFORM_PSERIES_LPAR;
  1177. }
  1178. }
  1179. return PLATFORM_PSERIES;
  1180. }
  1181. static int __init prom_set_color(ihandle ih, int i, int r, int g, int b)
  1182. {
  1183. unsigned long offset = reloc_offset();
  1184. return call_prom("call-method", 6, 1, ADDR("color!"), ih, i, b, g, r);
  1185. }
  1186. /*
  1187. * If we have a display that we don't know how to drive,
  1188. * we will want to try to execute OF's open method for it
  1189. * later. However, OF will probably fall over if we do that
  1190. * we've taken over the MMU.
  1191. * So we check whether we will need to open the display,
  1192. * and if so, open it now.
  1193. */
  1194. static void __init prom_check_displays(void)
  1195. {
  1196. unsigned long offset = reloc_offset();
  1197. struct prom_t *_prom = PTRRELOC(&prom);
  1198. char type[16], *path;
  1199. phandle node;
  1200. ihandle ih;
  1201. int i;
  1202. static unsigned char default_colors[] = {
  1203. 0x00, 0x00, 0x00,
  1204. 0x00, 0x00, 0xaa,
  1205. 0x00, 0xaa, 0x00,
  1206. 0x00, 0xaa, 0xaa,
  1207. 0xaa, 0x00, 0x00,
  1208. 0xaa, 0x00, 0xaa,
  1209. 0xaa, 0xaa, 0x00,
  1210. 0xaa, 0xaa, 0xaa,
  1211. 0x55, 0x55, 0x55,
  1212. 0x55, 0x55, 0xff,
  1213. 0x55, 0xff, 0x55,
  1214. 0x55, 0xff, 0xff,
  1215. 0xff, 0x55, 0x55,
  1216. 0xff, 0x55, 0xff,
  1217. 0xff, 0xff, 0x55,
  1218. 0xff, 0xff, 0xff
  1219. };
  1220. const unsigned char *clut;
  1221. prom_printf("Looking for displays\n");
  1222. for (node = 0; prom_next_node(&node); ) {
  1223. memset(type, 0, sizeof(type));
  1224. prom_getprop(node, "device_type", type, sizeof(type));
  1225. if (strcmp(type, RELOC("display")) != 0)
  1226. continue;
  1227. /* It seems OF doesn't null-terminate the path :-( */
  1228. path = RELOC(prom_scratch);
  1229. memset(path, 0, PROM_SCRATCH_SIZE);
  1230. /*
  1231. * leave some room at the end of the path for appending extra
  1232. * arguments
  1233. */
  1234. if (call_prom("package-to-path", 3, 1, node, path, PROM_SCRATCH_SIZE-10) < 0)
  1235. continue;
  1236. prom_printf("found display : %s, opening ... ", path);
  1237. ih = call_prom("open", 1, 1, path);
  1238. if (ih == (ihandle)0 || ih == (ihandle)-1) {
  1239. prom_printf("failed\n");
  1240. continue;
  1241. }
  1242. /* Success */
  1243. prom_printf("done\n");
  1244. prom_setprop(node, "linux,opened", NULL, 0);
  1245. /*
  1246. * stdout wasn't a display node, pick the first we can find
  1247. * for btext
  1248. */
  1249. if (_prom->disp_node == 0)
  1250. _prom->disp_node = node;
  1251. /* Setup a useable color table when the appropriate
  1252. * method is available. Should update this to set-colors */
  1253. clut = RELOC(default_colors);
  1254. for (i = 0; i < 32; i++, clut += 3)
  1255. if (prom_set_color(ih, i, clut[0], clut[1],
  1256. clut[2]) != 0)
  1257. break;
  1258. #ifdef CONFIG_LOGO_LINUX_CLUT224
  1259. clut = PTRRELOC(RELOC(logo_linux_clut224.clut));
  1260. for (i = 0; i < RELOC(logo_linux_clut224.clutsize); i++, clut += 3)
  1261. if (prom_set_color(ih, i + 32, clut[0], clut[1],
  1262. clut[2]) != 0)
  1263. break;
  1264. #endif /* CONFIG_LOGO_LINUX_CLUT224 */
  1265. }
  1266. }
  1267. /* Return (relocated) pointer to this much memory: moves initrd if reqd. */
  1268. static void __init *make_room(unsigned long *mem_start, unsigned long *mem_end,
  1269. unsigned long needed, unsigned long align)
  1270. {
  1271. unsigned long offset = reloc_offset();
  1272. void *ret;
  1273. *mem_start = _ALIGN(*mem_start, align);
  1274. while ((*mem_start + needed) > *mem_end) {
  1275. unsigned long room, chunk;
  1276. prom_debug("Chunk exhausted, claiming more at %x...\n",
  1277. RELOC(alloc_bottom));
  1278. room = RELOC(alloc_top) - RELOC(alloc_bottom);
  1279. if (room > DEVTREE_CHUNK_SIZE)
  1280. room = DEVTREE_CHUNK_SIZE;
  1281. if (room < PAGE_SIZE)
  1282. prom_panic("No memory for flatten_device_tree (no room)");
  1283. chunk = alloc_up(room, 0);
  1284. if (chunk == 0)
  1285. prom_panic("No memory for flatten_device_tree (claim failed)");
  1286. *mem_end = RELOC(alloc_top);
  1287. }
  1288. ret = (void *)*mem_start;
  1289. *mem_start += needed;
  1290. return ret;
  1291. }
  1292. #define dt_push_token(token, mem_start, mem_end) \
  1293. do { *((u32 *)make_room(mem_start, mem_end, 4, 4)) = token; } while(0)
  1294. static unsigned long __init dt_find_string(char *str)
  1295. {
  1296. unsigned long offset = reloc_offset();
  1297. char *s, *os;
  1298. s = os = (char *)RELOC(dt_string_start);
  1299. s += 4;
  1300. while (s < (char *)RELOC(dt_string_end)) {
  1301. if (strcmp(s, str) == 0)
  1302. return s - os;
  1303. s += strlen(s) + 1;
  1304. }
  1305. return 0;
  1306. }
  1307. static void __init scan_dt_build_strings(phandle node, unsigned long *mem_start,
  1308. unsigned long *mem_end)
  1309. {
  1310. unsigned long offset = reloc_offset();
  1311. char *prev_name, *namep, *sstart;
  1312. unsigned long soff;
  1313. phandle child;
  1314. sstart = (char *)RELOC(dt_string_start);
  1315. /* get and store all property names */
  1316. prev_name = RELOC("");
  1317. for (;;) {
  1318. /* 32 is max len of name including nul. */
  1319. namep = make_room(mem_start, mem_end, 32, 1);
  1320. if (call_prom("nextprop", 3, 1, node, prev_name, namep) <= 0) {
  1321. /* No more nodes: unwind alloc */
  1322. *mem_start = (unsigned long)namep;
  1323. break;
  1324. }
  1325. soff = dt_find_string(namep);
  1326. if (soff != 0) {
  1327. *mem_start = (unsigned long)namep;
  1328. namep = sstart + soff;
  1329. } else {
  1330. /* Trim off some if we can */
  1331. *mem_start = (unsigned long)namep + strlen(namep) + 1;
  1332. RELOC(dt_string_end) = *mem_start;
  1333. }
  1334. prev_name = namep;
  1335. }
  1336. /* do all our children */
  1337. child = call_prom("child", 1, 1, node);
  1338. while (child != (phandle)0) {
  1339. scan_dt_build_strings(child, mem_start, mem_end);
  1340. child = call_prom("peer", 1, 1, child);
  1341. }
  1342. }
  1343. /*
  1344. * The Open Firmware 1275 specification states properties must be 31 bytes or
  1345. * less, however not all firmwares obey this. Make it 64 bytes to be safe.
  1346. */
  1347. #define MAX_PROPERTY_NAME 64
  1348. static void __init scan_dt_build_struct(phandle node, unsigned long *mem_start,
  1349. unsigned long *mem_end)
  1350. {
  1351. int l, align;
  1352. phandle child;
  1353. char *namep, *prev_name, *sstart;
  1354. unsigned long soff;
  1355. unsigned char *valp;
  1356. unsigned long offset = reloc_offset();
  1357. char pname[MAX_PROPERTY_NAME];
  1358. char *path;
  1359. path = RELOC(prom_scratch);
  1360. dt_push_token(OF_DT_BEGIN_NODE, mem_start, mem_end);
  1361. /* get the node's full name */
  1362. namep = (char *)*mem_start;
  1363. l = call_prom("package-to-path", 3, 1, node,
  1364. namep, *mem_end - *mem_start);
  1365. if (l >= 0) {
  1366. /* Didn't fit? Get more room. */
  1367. if (l+1 > *mem_end - *mem_start) {
  1368. namep = make_room(mem_start, mem_end, l+1, 1);
  1369. call_prom("package-to-path", 3, 1, node, namep, l);
  1370. }
  1371. namep[l] = '\0';
  1372. *mem_start = _ALIGN(((unsigned long) namep) + strlen(namep) + 1, 4);
  1373. }
  1374. /* get it again for debugging */
  1375. memset(path, 0, PROM_SCRATCH_SIZE);
  1376. call_prom("package-to-path", 3, 1, node, path, PROM_SCRATCH_SIZE-1);
  1377. /* get and store all properties */
  1378. prev_name = RELOC("");
  1379. sstart = (char *)RELOC(dt_string_start);
  1380. for (;;) {
  1381. if (call_prom("nextprop", 3, 1, node, prev_name, pname) <= 0)
  1382. break;
  1383. /* find string offset */
  1384. soff = dt_find_string(pname);
  1385. if (soff == 0) {
  1386. prom_printf("WARNING: Can't find string index for <%s>, node %s\n",
  1387. pname, path);
  1388. break;
  1389. }
  1390. prev_name = sstart + soff;
  1391. /* get length */
  1392. l = call_prom("getproplen", 2, 1, node, pname);
  1393. /* sanity checks */
  1394. if (l < 0)
  1395. continue;
  1396. if (l > MAX_PROPERTY_LENGTH) {
  1397. prom_printf("WARNING: ignoring large property ");
  1398. /* It seems OF doesn't null-terminate the path :-( */
  1399. prom_printf("[%s] ", path);
  1400. prom_printf("%s length 0x%x\n", pname, l);
  1401. continue;
  1402. }
  1403. /* push property head */
  1404. dt_push_token(OF_DT_PROP, mem_start, mem_end);
  1405. dt_push_token(l, mem_start, mem_end);
  1406. dt_push_token(soff, mem_start, mem_end);
  1407. /* push property content */
  1408. align = (l >= 8) ? 8 : 4;
  1409. valp = make_room(mem_start, mem_end, l, align);
  1410. call_prom("getprop", 4, 1, node, pname, valp, l);
  1411. *mem_start = _ALIGN(*mem_start, 4);
  1412. }
  1413. /* Add a "linux,phandle" property. */
  1414. soff = dt_find_string(RELOC("linux,phandle"));
  1415. if (soff == 0)
  1416. prom_printf("WARNING: Can't find string index for <linux-phandle>"
  1417. " node %s\n", path);
  1418. else {
  1419. dt_push_token(OF_DT_PROP, mem_start, mem_end);
  1420. dt_push_token(4, mem_start, mem_end);
  1421. dt_push_token(soff, mem_start, mem_end);
  1422. valp = make_room(mem_start, mem_end, 4, 4);
  1423. *(u32 *)valp = node;
  1424. }
  1425. /* do all our children */
  1426. child = call_prom("child", 1, 1, node);
  1427. while (child != (phandle)0) {
  1428. scan_dt_build_struct(child, mem_start, mem_end);
  1429. child = call_prom("peer", 1, 1, child);
  1430. }
  1431. dt_push_token(OF_DT_END_NODE, mem_start, mem_end);
  1432. }
  1433. static void __init flatten_device_tree(void)
  1434. {
  1435. phandle root;
  1436. unsigned long offset = reloc_offset();
  1437. unsigned long mem_start, mem_end, room;
  1438. struct boot_param_header *hdr;
  1439. char *namep;
  1440. u64 *rsvmap;
  1441. /*
  1442. * Check how much room we have between alloc top & bottom (+/- a
  1443. * few pages), crop to 4Mb, as this is our "chuck" size
  1444. */
  1445. room = RELOC(alloc_top) - RELOC(alloc_bottom) - 0x4000;
  1446. if (room > DEVTREE_CHUNK_SIZE)
  1447. room = DEVTREE_CHUNK_SIZE;
  1448. prom_debug("starting device tree allocs at %x\n", RELOC(alloc_bottom));
  1449. /* Now try to claim that */
  1450. mem_start = (unsigned long)alloc_up(room, PAGE_SIZE);
  1451. if (mem_start == 0)
  1452. prom_panic("Can't allocate initial device-tree chunk\n");
  1453. mem_end = RELOC(alloc_top);
  1454. /* Get root of tree */
  1455. root = call_prom("peer", 1, 1, (phandle)0);
  1456. if (root == (phandle)0)
  1457. prom_panic ("couldn't get device tree root\n");
  1458. /* Build header and make room for mem rsv map */
  1459. mem_start = _ALIGN(mem_start, 4);
  1460. hdr = make_room(&mem_start, &mem_end, sizeof(struct boot_param_header), 4);
  1461. RELOC(dt_header_start) = (unsigned long)hdr;
  1462. rsvmap = make_room(&mem_start, &mem_end, sizeof(mem_reserve_map), 8);
  1463. /* Start of strings */
  1464. mem_start = PAGE_ALIGN(mem_start);
  1465. RELOC(dt_string_start) = mem_start;
  1466. mem_start += 4; /* hole */
  1467. /* Add "linux,phandle" in there, we'll need it */
  1468. namep = make_room(&mem_start, &mem_end, 16, 1);
  1469. strcpy(namep, RELOC("linux,phandle"));
  1470. mem_start = (unsigned long)namep + strlen(namep) + 1;
  1471. RELOC(dt_string_end) = mem_start;
  1472. /* Build string array */
  1473. prom_printf("Building dt strings...\n");
  1474. scan_dt_build_strings(root, &mem_start, &mem_end);
  1475. /* Build structure */
  1476. mem_start = PAGE_ALIGN(mem_start);
  1477. RELOC(dt_struct_start) = mem_start;
  1478. prom_printf("Building dt structure...\n");
  1479. scan_dt_build_struct(root, &mem_start, &mem_end);
  1480. dt_push_token(OF_DT_END, &mem_start, &mem_end);
  1481. RELOC(dt_struct_end) = PAGE_ALIGN(mem_start);
  1482. /* Finish header */
  1483. hdr->magic = OF_DT_HEADER;
  1484. hdr->totalsize = RELOC(dt_struct_end) - RELOC(dt_header_start);
  1485. hdr->off_dt_struct = RELOC(dt_struct_start) - RELOC(dt_header_start);
  1486. hdr->off_dt_strings = RELOC(dt_string_start) - RELOC(dt_header_start);
  1487. hdr->off_mem_rsvmap = ((unsigned long)rsvmap) - RELOC(dt_header_start);
  1488. hdr->version = OF_DT_VERSION;
  1489. hdr->last_comp_version = 1;
  1490. /* Reserve the whole thing and copy the reserve map in, we
  1491. * also bump mem_reserve_cnt to cause further reservations to
  1492. * fail since it's too late.
  1493. */
  1494. reserve_mem(RELOC(dt_header_start), hdr->totalsize);
  1495. memcpy(rsvmap, RELOC(mem_reserve_map), sizeof(mem_reserve_map));
  1496. #ifdef DEBUG_PROM
  1497. {
  1498. int i;
  1499. prom_printf("reserved memory map:\n");
  1500. for (i = 0; i < RELOC(mem_reserve_cnt); i++)
  1501. prom_printf(" %x - %x\n", RELOC(mem_reserve_map)[i].base,
  1502. RELOC(mem_reserve_map)[i].size);
  1503. }
  1504. #endif
  1505. RELOC(mem_reserve_cnt) = MEM_RESERVE_MAP_SIZE;
  1506. prom_printf("Device tree strings 0x%x -> 0x%x\n",
  1507. RELOC(dt_string_start), RELOC(dt_string_end));
  1508. prom_printf("Device tree struct 0x%x -> 0x%x\n",
  1509. RELOC(dt_struct_start), RELOC(dt_struct_end));
  1510. }
  1511. static void __init fixup_device_tree(void)
  1512. {
  1513. unsigned long offset = reloc_offset();
  1514. phandle u3, i2c, mpic;
  1515. u32 u3_rev;
  1516. u32 interrupts[2];
  1517. u32 parent;
  1518. /* Some G5s have a missing interrupt definition, fix it up here */
  1519. u3 = call_prom("finddevice", 1, 1, ADDR("/u3@0,f8000000"));
  1520. if ((long)u3 <= 0)
  1521. return;
  1522. i2c = call_prom("finddevice", 1, 1, ADDR("/u3@0,f8000000/i2c@f8001000"));
  1523. if ((long)i2c <= 0)
  1524. return;
  1525. mpic = call_prom("finddevice", 1, 1, ADDR("/u3@0,f8000000/mpic@f8040000"));
  1526. if ((long)mpic <= 0)
  1527. return;
  1528. /* check if proper rev of u3 */
  1529. if (prom_getprop(u3, "device-rev", &u3_rev, sizeof(u3_rev)) <= 0)
  1530. return;
  1531. if (u3_rev != 0x35)
  1532. return;
  1533. /* does it need fixup ? */
  1534. if (prom_getproplen(i2c, "interrupts") > 0)
  1535. return;
  1536. /* interrupt on this revision of u3 is number 0 and level */
  1537. interrupts[0] = 0;
  1538. interrupts[1] = 1;
  1539. prom_setprop(i2c, "interrupts", &interrupts, sizeof(interrupts));
  1540. parent = (u32)mpic;
  1541. prom_setprop(i2c, "interrupt-parent", &parent, sizeof(parent));
  1542. }
  1543. static void __init prom_find_boot_cpu(void)
  1544. {
  1545. unsigned long offset = reloc_offset();
  1546. struct prom_t *_prom = PTRRELOC(&prom);
  1547. u32 getprop_rval;
  1548. ihandle prom_cpu;
  1549. phandle cpu_pkg;
  1550. if (prom_getprop(_prom->chosen, "cpu", &prom_cpu, sizeof(prom_cpu)) <= 0)
  1551. prom_panic("cannot find boot cpu");
  1552. cpu_pkg = call_prom("instance-to-package", 1, 1, prom_cpu);
  1553. prom_setprop(cpu_pkg, "linux,boot-cpu", NULL, 0);
  1554. prom_getprop(cpu_pkg, "reg", &getprop_rval, sizeof(getprop_rval));
  1555. _prom->cpu = getprop_rval;
  1556. prom_debug("Booting CPU hw index = 0x%x\n", _prom->cpu);
  1557. }
  1558. static void __init prom_check_initrd(unsigned long r3, unsigned long r4)
  1559. {
  1560. #ifdef CONFIG_BLK_DEV_INITRD
  1561. unsigned long offset = reloc_offset();
  1562. struct prom_t *_prom = PTRRELOC(&prom);
  1563. if ( r3 && r4 && r4 != 0xdeadbeef) {
  1564. u64 val;
  1565. RELOC(prom_initrd_start) = (r3 >= KERNELBASE) ? __pa(r3) : r3;
  1566. RELOC(prom_initrd_end) = RELOC(prom_initrd_start) + r4;
  1567. val = (u64)RELOC(prom_initrd_start);
  1568. prom_setprop(_prom->chosen, "linux,initrd-start", &val, sizeof(val));
  1569. val = (u64)RELOC(prom_initrd_end);
  1570. prom_setprop(_prom->chosen, "linux,initrd-end", &val, sizeof(val));
  1571. reserve_mem(RELOC(prom_initrd_start),
  1572. RELOC(prom_initrd_end) - RELOC(prom_initrd_start));
  1573. prom_debug("initrd_start=0x%x\n", RELOC(prom_initrd_start));
  1574. prom_debug("initrd_end=0x%x\n", RELOC(prom_initrd_end));
  1575. }
  1576. #endif /* CONFIG_BLK_DEV_INITRD */
  1577. }
  1578. /*
  1579. * We enter here early on, when the Open Firmware prom is still
  1580. * handling exceptions and the MMU hash table for us.
  1581. */
  1582. unsigned long __init prom_init(unsigned long r3, unsigned long r4, unsigned long pp,
  1583. unsigned long r6, unsigned long r7)
  1584. {
  1585. unsigned long offset = reloc_offset();
  1586. struct prom_t *_prom = PTRRELOC(&prom);
  1587. unsigned long phys = KERNELBASE - offset;
  1588. u32 getprop_rval;
  1589. /*
  1590. * First zero the BSS
  1591. */
  1592. memset(PTRRELOC(&__bss_start), 0, __bss_stop - __bss_start);
  1593. /*
  1594. * Init interface to Open Firmware, get some node references,
  1595. * like /chosen
  1596. */
  1597. prom_init_client_services(pp);
  1598. /*
  1599. * Init prom stdout device
  1600. */
  1601. prom_init_stdout();
  1602. prom_debug("klimit=0x%x\n", RELOC(klimit));
  1603. prom_debug("offset=0x%x\n", offset);
  1604. /*
  1605. * Check for an initrd
  1606. */
  1607. prom_check_initrd(r3, r4);
  1608. /*
  1609. * Get default machine type. At this point, we do not differenciate
  1610. * between pSeries SMP and pSeries LPAR
  1611. */
  1612. RELOC(of_platform) = prom_find_machine_type();
  1613. getprop_rval = RELOC(of_platform);
  1614. prom_setprop(_prom->chosen, "linux,platform",
  1615. &getprop_rval, sizeof(getprop_rval));
  1616. /*
  1617. * On pSeries, copy the CPU hold code
  1618. */
  1619. if (RELOC(of_platform) & PLATFORM_PSERIES)
  1620. copy_and_flush(0, KERNELBASE - offset, 0x100, 0);
  1621. /*
  1622. * Get memory cells format
  1623. */
  1624. getprop_rval = 1;
  1625. prom_getprop(_prom->root, "#size-cells",
  1626. &getprop_rval, sizeof(getprop_rval));
  1627. _prom->root_size_cells = getprop_rval;
  1628. getprop_rval = 2;
  1629. prom_getprop(_prom->root, "#address-cells",
  1630. &getprop_rval, sizeof(getprop_rval));
  1631. _prom->root_addr_cells = getprop_rval;
  1632. /*
  1633. * Do early parsing of command line
  1634. */
  1635. early_cmdline_parse();
  1636. /*
  1637. * Initialize memory management within prom_init
  1638. */
  1639. prom_init_mem();
  1640. /*
  1641. * Determine which cpu is actually running right _now_
  1642. */
  1643. prom_find_boot_cpu();
  1644. /*
  1645. * Initialize display devices
  1646. */
  1647. prom_check_displays();
  1648. /*
  1649. * Initialize IOMMU (TCE tables) on pSeries. Do that before anything else
  1650. * that uses the allocator, we need to make sure we get the top of memory
  1651. * available for us here...
  1652. */
  1653. if (RELOC(of_platform) == PLATFORM_PSERIES)
  1654. prom_initialize_tce_table();
  1655. /*
  1656. * On non-powermacs, try to instantiate RTAS and puts all CPUs
  1657. * in spin-loops. PowerMacs don't have a working RTAS and use
  1658. * a different way to spin CPUs
  1659. */
  1660. if (RELOC(of_platform) != PLATFORM_POWERMAC) {
  1661. prom_instantiate_rtas();
  1662. prom_hold_cpus();
  1663. }
  1664. /*
  1665. * Fill in some infos for use by the kernel later on
  1666. */
  1667. if (RELOC(ppc64_iommu_off))
  1668. prom_setprop(_prom->chosen, "linux,iommu-off", NULL, 0);
  1669. if (RELOC(iommu_force_on))
  1670. prom_setprop(_prom->chosen, "linux,iommu-force-on", NULL, 0);
  1671. if (RELOC(prom_memory_limit))
  1672. prom_setprop(_prom->chosen, "linux,memory-limit",
  1673. PTRRELOC(&prom_memory_limit), sizeof(RELOC(prom_memory_limit)));
  1674. if (RELOC(prom_tce_alloc_start)) {
  1675. prom_setprop(_prom->chosen, "linux,tce-alloc-start",
  1676. PTRRELOC(&prom_tce_alloc_start), sizeof(RELOC(prom_tce_alloc_start)));
  1677. prom_setprop(_prom->chosen, "linux,tce-alloc-end",
  1678. PTRRELOC(&prom_tce_alloc_end), sizeof(RELOC(prom_tce_alloc_end)));
  1679. }
  1680. /*
  1681. * Fixup any known bugs in the device-tree
  1682. */
  1683. fixup_device_tree();
  1684. /*
  1685. * Now finally create the flattened device-tree
  1686. */
  1687. prom_printf("copying OF device tree ...\n");
  1688. flatten_device_tree();
  1689. /* in case stdin is USB and still active on IBM machines... */
  1690. prom_close_stdin();
  1691. /*
  1692. * Call OF "quiesce" method to shut down pending DMA's from
  1693. * devices etc...
  1694. */
  1695. prom_printf("Calling quiesce ...\n");
  1696. call_prom("quiesce", 0, 0);
  1697. /*
  1698. * And finally, call the kernel passing it the flattened device
  1699. * tree and NULL as r5, thus triggering the new entry point which
  1700. * is common to us and kexec
  1701. */
  1702. prom_printf("returning from prom_init\n");
  1703. prom_debug("->dt_header_start=0x%x\n", RELOC(dt_header_start));
  1704. prom_debug("->phys=0x%x\n", phys);
  1705. __start(RELOC(dt_header_start), phys, 0);
  1706. return 0;
  1707. }