prom_init.c 64 KB

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