prom_init.c 66 KB

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