prom_init.c 79 KB

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