prom_init.c 65 KB

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