prom_init.c 66 KB

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