prom_init.c 79 KB

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