prom_init.c 80 KB

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