prom_init.c 54 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007
  1. /*
  2. *
  3. *
  4. * Procedures for interfacing to Open Firmware.
  5. *
  6. * Paul Mackerras August 1996.
  7. * Copyright (C) 1996 Paul Mackerras.
  8. *
  9. * Adapted for 64bit PowerPC by Dave Engebretsen and Peter Bergner.
  10. * {engebret|bergner}@us.ibm.com
  11. *
  12. * This program is free software; you can redistribute it and/or
  13. * modify it under the terms of the GNU General Public License
  14. * as published by the Free Software Foundation; either version
  15. * 2 of the License, or (at your option) any later version.
  16. */
  17. #undef DEBUG_PROM
  18. #include <stdarg.h>
  19. #include <linux/config.h>
  20. #include <linux/kernel.h>
  21. #include <linux/string.h>
  22. #include <linux/init.h>
  23. #include <linux/version.h>
  24. #include <linux/threads.h>
  25. #include <linux/spinlock.h>
  26. #include <linux/types.h>
  27. #include <linux/pci.h>
  28. #include <linux/proc_fs.h>
  29. #include <linux/stringify.h>
  30. #include <linux/delay.h>
  31. #include <linux/initrd.h>
  32. #include <linux/bitops.h>
  33. #include <asm/prom.h>
  34. #include <asm/rtas.h>
  35. #include <asm/abs_addr.h>
  36. #include <asm/page.h>
  37. #include <asm/processor.h>
  38. #include <asm/irq.h>
  39. #include <asm/io.h>
  40. #include <asm/smp.h>
  41. #include <asm/system.h>
  42. #include <asm/mmu.h>
  43. #include <asm/pgtable.h>
  44. #include <asm/pci.h>
  45. #include <asm/iommu.h>
  46. #include <asm/bootinfo.h>
  47. #include <asm/ppcdebug.h>
  48. #include <asm/btext.h>
  49. #include <asm/sections.h>
  50. #include <asm/machdep.h>
  51. #ifdef CONFIG_LOGO_LINUX_CLUT224
  52. #include <linux/linux_logo.h>
  53. extern const struct linux_logo logo_linux_clut224;
  54. #endif
  55. /*
  56. * Properties whose value is longer than this get excluded from our
  57. * copy of the device tree. This value does need to be big enough to
  58. * ensure that we don't lose things like the interrupt-map property
  59. * on a PCI-PCI bridge.
  60. */
  61. #define MAX_PROPERTY_LENGTH (1UL * 1024 * 1024)
  62. /*
  63. * Eventually bump that one up
  64. */
  65. #define DEVTREE_CHUNK_SIZE 0x100000
  66. /*
  67. * This is the size of the local memory reserve map that gets copied
  68. * into the boot params passed to the kernel. That size is totally
  69. * flexible as the kernel just reads the list until it encounters an
  70. * entry with size 0, so it can be changed without breaking binary
  71. * compatibility
  72. */
  73. #define MEM_RESERVE_MAP_SIZE 8
  74. /*
  75. * prom_init() is called very early on, before the kernel text
  76. * and data have been mapped to KERNELBASE. At this point the code
  77. * is running at whatever address it has been loaded at, so
  78. * references to extern and static variables must be relocated
  79. * explicitly. The procedure reloc_offset() returns the address
  80. * we're currently running at minus the address we were linked at.
  81. * (Note that strings count as static variables.)
  82. *
  83. * Because OF may have mapped I/O devices into the area starting at
  84. * KERNELBASE, particularly on CHRP machines, we can't safely call
  85. * OF once the kernel has been mapped to KERNELBASE. Therefore all
  86. * OF calls should be done within prom_init(), and prom_init()
  87. * and all routines called within it must be careful to relocate
  88. * references as necessary.
  89. *
  90. * Note that the bss is cleared *after* prom_init runs, so we have
  91. * to make sure that any static or extern variables it accesses
  92. * are put in the data segment.
  93. */
  94. #define PROM_BUG() do { \
  95. prom_printf("kernel BUG at %s line 0x%x!\n", \
  96. RELOC(__FILE__), __LINE__); \
  97. __asm__ __volatile__(".long " BUG_ILLEGAL_INSTR); \
  98. } while (0)
  99. #ifdef DEBUG_PROM
  100. #define prom_debug(x...) prom_printf(x)
  101. #else
  102. #define prom_debug(x...)
  103. #endif
  104. typedef u32 prom_arg_t;
  105. struct prom_args {
  106. u32 service;
  107. u32 nargs;
  108. u32 nret;
  109. prom_arg_t args[10];
  110. prom_arg_t *rets; /* Pointer to return values in args[16]. */
  111. };
  112. struct prom_t {
  113. unsigned long entry;
  114. ihandle root;
  115. ihandle chosen;
  116. int cpu;
  117. ihandle stdout;
  118. ihandle disp_node;
  119. struct prom_args args;
  120. unsigned long version;
  121. unsigned long root_size_cells;
  122. unsigned long root_addr_cells;
  123. };
  124. struct pci_reg_property {
  125. struct pci_address addr;
  126. u32 size_hi;
  127. u32 size_lo;
  128. };
  129. struct mem_map_entry {
  130. u64 base;
  131. u64 size;
  132. };
  133. typedef u32 cell_t;
  134. extern void __start(unsigned long r3, unsigned long r4, unsigned long r5);
  135. extern void enter_prom(struct prom_args *args, unsigned long entry);
  136. extern void copy_and_flush(unsigned long dest, unsigned long src,
  137. unsigned long size, unsigned long offset);
  138. extern unsigned long klimit;
  139. /* prom structure */
  140. static struct prom_t __initdata prom;
  141. #define PROM_SCRATCH_SIZE 256
  142. static char __initdata of_stdout_device[256];
  143. static char __initdata prom_scratch[PROM_SCRATCH_SIZE];
  144. static unsigned long __initdata dt_header_start;
  145. static unsigned long __initdata dt_struct_start, dt_struct_end;
  146. static unsigned long __initdata dt_string_start, dt_string_end;
  147. static unsigned long __initdata prom_initrd_start, prom_initrd_end;
  148. static int __initdata iommu_force_on;
  149. static int __initdata ppc64_iommu_off;
  150. static int __initdata of_platform;
  151. static char __initdata prom_cmd_line[COMMAND_LINE_SIZE];
  152. static unsigned long __initdata prom_memory_limit;
  153. static unsigned long __initdata prom_tce_alloc_start;
  154. static unsigned long __initdata prom_tce_alloc_end;
  155. static unsigned long __initdata alloc_top;
  156. static unsigned long __initdata alloc_top_high;
  157. static unsigned long __initdata alloc_bottom;
  158. static unsigned long __initdata rmo_top;
  159. static unsigned long __initdata ram_top;
  160. static struct mem_map_entry __initdata mem_reserve_map[MEM_RESERVE_MAP_SIZE];
  161. static int __initdata mem_reserve_cnt;
  162. static cell_t __initdata regbuf[1024];
  163. #define MAX_CPU_THREADS 2
  164. /* TO GO */
  165. #ifdef CONFIG_HMT
  166. struct {
  167. unsigned int pir;
  168. unsigned int threadid;
  169. } hmt_thread_data[NR_CPUS];
  170. #endif /* CONFIG_HMT */
  171. /*
  172. * This are used in calls to call_prom. The 4th and following
  173. * arguments to call_prom should be 32-bit values. 64 bit values
  174. * are truncated to 32 bits (and fortunately don't get interpreted
  175. * as two arguments).
  176. */
  177. #define ADDR(x) (u32) ((unsigned long)(x) - offset)
  178. /* This is the one and *ONLY* place where we actually call open
  179. * firmware from, since we need to make sure we're running in 32b
  180. * mode when we do. We switch back to 64b mode upon return.
  181. */
  182. #define PROM_ERROR (-1)
  183. static int __init call_prom(const char *service, int nargs, int nret, ...)
  184. {
  185. int i;
  186. unsigned long offset = reloc_offset();
  187. struct prom_t *_prom = PTRRELOC(&prom);
  188. va_list list;
  189. _prom->args.service = ADDR(service);
  190. _prom->args.nargs = nargs;
  191. _prom->args.nret = nret;
  192. _prom->args.rets = (prom_arg_t *)&(_prom->args.args[nargs]);
  193. va_start(list, nret);
  194. for (i=0; i < nargs; i++)
  195. _prom->args.args[i] = va_arg(list, prom_arg_t);
  196. va_end(list);
  197. for (i=0; i < nret ;i++)
  198. _prom->args.rets[i] = 0;
  199. enter_prom(&_prom->args, _prom->entry);
  200. return (nret > 0) ? _prom->args.rets[0] : 0;
  201. }
  202. static unsigned int __init prom_claim(unsigned long virt, unsigned long size,
  203. unsigned long align)
  204. {
  205. return (unsigned int)call_prom("claim", 3, 1,
  206. (prom_arg_t)virt, (prom_arg_t)size,
  207. (prom_arg_t)align);
  208. }
  209. static void __init prom_print(const char *msg)
  210. {
  211. const char *p, *q;
  212. unsigned long offset = reloc_offset();
  213. struct prom_t *_prom = PTRRELOC(&prom);
  214. if (_prom->stdout == 0)
  215. return;
  216. for (p = msg; *p != 0; p = q) {
  217. for (q = p; *q != 0 && *q != '\n'; ++q)
  218. ;
  219. if (q > p)
  220. call_prom("write", 3, 1, _prom->stdout, p, q - p);
  221. if (*q == 0)
  222. break;
  223. ++q;
  224. call_prom("write", 3, 1, _prom->stdout, ADDR("\r\n"), 2);
  225. }
  226. }
  227. static void __init prom_print_hex(unsigned long val)
  228. {
  229. unsigned long offset = reloc_offset();
  230. int i, nibbles = sizeof(val)*2;
  231. char buf[sizeof(val)*2+1];
  232. struct prom_t *_prom = PTRRELOC(&prom);
  233. for (i = nibbles-1; i >= 0; i--) {
  234. buf[i] = (val & 0xf) + '0';
  235. if (buf[i] > '9')
  236. buf[i] += ('a'-'0'-10);
  237. val >>= 4;
  238. }
  239. buf[nibbles] = '\0';
  240. call_prom("write", 3, 1, _prom->stdout, buf, nibbles);
  241. }
  242. static void __init prom_printf(const char *format, ...)
  243. {
  244. unsigned long offset = reloc_offset();
  245. const char *p, *q, *s;
  246. va_list args;
  247. unsigned long v;
  248. struct prom_t *_prom = PTRRELOC(&prom);
  249. va_start(args, format);
  250. for (p = PTRRELOC(format); *p != 0; p = q) {
  251. for (q = p; *q != 0 && *q != '\n' && *q != '%'; ++q)
  252. ;
  253. if (q > p)
  254. call_prom("write", 3, 1, _prom->stdout, p, q - p);
  255. if (*q == 0)
  256. break;
  257. if (*q == '\n') {
  258. ++q;
  259. call_prom("write", 3, 1, _prom->stdout,
  260. ADDR("\r\n"), 2);
  261. continue;
  262. }
  263. ++q;
  264. if (*q == 0)
  265. break;
  266. switch (*q) {
  267. case 's':
  268. ++q;
  269. s = va_arg(args, const char *);
  270. prom_print(s);
  271. break;
  272. case 'x':
  273. ++q;
  274. v = va_arg(args, unsigned long);
  275. prom_print_hex(v);
  276. break;
  277. }
  278. }
  279. }
  280. static void __init __attribute__((noreturn)) prom_panic(const char *reason)
  281. {
  282. unsigned long offset = reloc_offset();
  283. prom_print(PTRRELOC(reason));
  284. /* ToDo: should put up an SRC here */
  285. call_prom("exit", 0, 0);
  286. for (;;) /* should never get here */
  287. ;
  288. }
  289. static int __init prom_next_node(phandle *nodep)
  290. {
  291. phandle node;
  292. if ((node = *nodep) != 0
  293. && (*nodep = call_prom("child", 1, 1, node)) != 0)
  294. return 1;
  295. if ((*nodep = call_prom("peer", 1, 1, node)) != 0)
  296. return 1;
  297. for (;;) {
  298. if ((node = call_prom("parent", 1, 1, node)) == 0)
  299. return 0;
  300. if ((*nodep = call_prom("peer", 1, 1, node)) != 0)
  301. return 1;
  302. }
  303. }
  304. static int __init prom_getprop(phandle node, const char *pname,
  305. void *value, size_t valuelen)
  306. {
  307. unsigned long offset = reloc_offset();
  308. return call_prom("getprop", 4, 1, node, ADDR(pname),
  309. (u32)(unsigned long) value, (u32) valuelen);
  310. }
  311. static int __init prom_getproplen(phandle node, const char *pname)
  312. {
  313. unsigned long offset = reloc_offset();
  314. return call_prom("getproplen", 2, 1, node, ADDR(pname));
  315. }
  316. static int __init prom_setprop(phandle node, const char *pname,
  317. void *value, size_t valuelen)
  318. {
  319. unsigned long offset = reloc_offset();
  320. return call_prom("setprop", 4, 1, node, ADDR(pname),
  321. (u32)(unsigned long) value, (u32) valuelen);
  322. }
  323. /* We can't use the standard versions because of RELOC headaches. */
  324. #define isxdigit(c) (('0' <= (c) && (c) <= '9') \
  325. || ('a' <= (c) && (c) <= 'f') \
  326. || ('A' <= (c) && (c) <= 'F'))
  327. #define isdigit(c) ('0' <= (c) && (c) <= '9')
  328. #define islower(c) ('a' <= (c) && (c) <= 'z')
  329. #define toupper(c) (islower(c) ? ((c) - 'a' + 'A') : (c))
  330. unsigned long prom_strtoul(const char *cp, const char **endp)
  331. {
  332. unsigned long result = 0, base = 10, value;
  333. if (*cp == '0') {
  334. base = 8;
  335. cp++;
  336. if (toupper(*cp) == 'X') {
  337. cp++;
  338. base = 16;
  339. }
  340. }
  341. while (isxdigit(*cp) &&
  342. (value = isdigit(*cp) ? *cp - '0' : toupper(*cp) - 'A' + 10) < base) {
  343. result = result * base + value;
  344. cp++;
  345. }
  346. if (endp)
  347. *endp = cp;
  348. return result;
  349. }
  350. unsigned long prom_memparse(const char *ptr, const char **retptr)
  351. {
  352. unsigned long ret = prom_strtoul(ptr, retptr);
  353. int shift = 0;
  354. /*
  355. * We can't use a switch here because GCC *may* generate a
  356. * jump table which won't work, because we're not running at
  357. * the address we're linked at.
  358. */
  359. if ('G' == **retptr || 'g' == **retptr)
  360. shift = 30;
  361. if ('M' == **retptr || 'm' == **retptr)
  362. shift = 20;
  363. if ('K' == **retptr || 'k' == **retptr)
  364. shift = 10;
  365. if (shift) {
  366. ret <<= shift;
  367. (*retptr)++;
  368. }
  369. return ret;
  370. }
  371. /*
  372. * Early parsing of the command line passed to the kernel, used for
  373. * "mem=x" and the options that affect the iommu
  374. */
  375. static void __init early_cmdline_parse(void)
  376. {
  377. unsigned long offset = reloc_offset();
  378. struct prom_t *_prom = PTRRELOC(&prom);
  379. char *opt, *p;
  380. int l = 0;
  381. RELOC(prom_cmd_line[0]) = 0;
  382. p = RELOC(prom_cmd_line);
  383. if ((long)_prom->chosen > 0)
  384. l = prom_getprop(_prom->chosen, "bootargs", p, COMMAND_LINE_SIZE-1);
  385. #ifdef CONFIG_CMDLINE
  386. if (l == 0) /* dbl check */
  387. strlcpy(RELOC(prom_cmd_line),
  388. RELOC(CONFIG_CMDLINE), sizeof(prom_cmd_line));
  389. #endif /* CONFIG_CMDLINE */
  390. prom_printf("command line: %s\n", RELOC(prom_cmd_line));
  391. opt = strstr(RELOC(prom_cmd_line), RELOC("iommu="));
  392. if (opt) {
  393. prom_printf("iommu opt is: %s\n", opt);
  394. opt += 6;
  395. while (*opt && *opt == ' ')
  396. opt++;
  397. if (!strncmp(opt, RELOC("off"), 3))
  398. RELOC(ppc64_iommu_off) = 1;
  399. else if (!strncmp(opt, RELOC("force"), 5))
  400. RELOC(iommu_force_on) = 1;
  401. }
  402. opt = strstr(RELOC(prom_cmd_line), RELOC("mem="));
  403. if (opt) {
  404. opt += 4;
  405. RELOC(prom_memory_limit) = prom_memparse(opt, (const char **)&opt);
  406. /* Align to 16 MB == size of large page */
  407. RELOC(prom_memory_limit) = ALIGN(RELOC(prom_memory_limit), 0x1000000);
  408. }
  409. }
  410. /*
  411. * To tell the firmware what our capabilities are, we have to pass
  412. * it a fake 32-bit ELF header containing a couple of PT_NOTE sections
  413. * that contain structures that contain the actual values.
  414. */
  415. static struct fake_elf {
  416. Elf32_Ehdr elfhdr;
  417. Elf32_Phdr phdr[2];
  418. struct chrpnote {
  419. u32 namesz;
  420. u32 descsz;
  421. u32 type;
  422. char name[8]; /* "PowerPC" */
  423. struct chrpdesc {
  424. u32 real_mode;
  425. u32 real_base;
  426. u32 real_size;
  427. u32 virt_base;
  428. u32 virt_size;
  429. u32 load_base;
  430. } chrpdesc;
  431. } chrpnote;
  432. struct rpanote {
  433. u32 namesz;
  434. u32 descsz;
  435. u32 type;
  436. char name[24]; /* "IBM,RPA-Client-Config" */
  437. struct rpadesc {
  438. u32 lpar_affinity;
  439. u32 min_rmo_size;
  440. u32 min_rmo_percent;
  441. u32 max_pft_size;
  442. u32 splpar;
  443. u32 min_load;
  444. u32 new_mem_def;
  445. u32 ignore_me;
  446. } rpadesc;
  447. } rpanote;
  448. } fake_elf = {
  449. .elfhdr = {
  450. .e_ident = { 0x7f, 'E', 'L', 'F',
  451. ELFCLASS32, ELFDATA2MSB, EV_CURRENT },
  452. .e_type = ET_EXEC, /* yeah right */
  453. .e_machine = EM_PPC,
  454. .e_version = EV_CURRENT,
  455. .e_phoff = offsetof(struct fake_elf, phdr),
  456. .e_phentsize = sizeof(Elf32_Phdr),
  457. .e_phnum = 2
  458. },
  459. .phdr = {
  460. [0] = {
  461. .p_type = PT_NOTE,
  462. .p_offset = offsetof(struct fake_elf, chrpnote),
  463. .p_filesz = sizeof(struct chrpnote)
  464. }, [1] = {
  465. .p_type = PT_NOTE,
  466. .p_offset = offsetof(struct fake_elf, rpanote),
  467. .p_filesz = sizeof(struct rpanote)
  468. }
  469. },
  470. .chrpnote = {
  471. .namesz = sizeof("PowerPC"),
  472. .descsz = sizeof(struct chrpdesc),
  473. .type = 0x1275,
  474. .name = "PowerPC",
  475. .chrpdesc = {
  476. .real_mode = ~0U, /* ~0 means "don't care" */
  477. .real_base = ~0U,
  478. .real_size = ~0U,
  479. .virt_base = ~0U,
  480. .virt_size = ~0U,
  481. .load_base = ~0U
  482. },
  483. },
  484. .rpanote = {
  485. .namesz = sizeof("IBM,RPA-Client-Config"),
  486. .descsz = sizeof(struct rpadesc),
  487. .type = 0x12759999,
  488. .name = "IBM,RPA-Client-Config",
  489. .rpadesc = {
  490. .lpar_affinity = 0,
  491. .min_rmo_size = 64, /* in megabytes */
  492. .min_rmo_percent = 0,
  493. .max_pft_size = 48, /* 2^48 bytes max PFT size */
  494. .splpar = 1,
  495. .min_load = ~0U,
  496. .new_mem_def = 0
  497. }
  498. }
  499. };
  500. static void __init prom_send_capabilities(void)
  501. {
  502. unsigned long offset = reloc_offset();
  503. ihandle elfloader;
  504. int ret;
  505. elfloader = call_prom("open", 1, 1, ADDR("/packages/elf-loader"));
  506. if (elfloader == 0) {
  507. prom_printf("couldn't open /packages/elf-loader\n");
  508. return;
  509. }
  510. ret = call_prom("call-method", 3, 1, ADDR("process-elf-header"),
  511. elfloader, ADDR(&fake_elf));
  512. call_prom("close", 1, 0, elfloader);
  513. }
  514. /*
  515. * Memory allocation strategy... our layout is normally:
  516. *
  517. * at 14Mb or more we vmlinux, then a gap and initrd. In some rare cases, initrd
  518. * might end up beeing before the kernel though. We assume this won't override
  519. * the final kernel at 0, we have no provision to handle that in this version,
  520. * but it should hopefully never happen.
  521. *
  522. * alloc_top is set to the top of RMO, eventually shrink down if the TCEs overlap
  523. * alloc_bottom is set to the top of kernel/initrd
  524. *
  525. * from there, allocations are done that way : rtas is allocated topmost, and
  526. * the device-tree is allocated from the bottom. We try to grow the device-tree
  527. * allocation as we progress. If we can't, then we fail, we don't currently have
  528. * a facility to restart elsewhere, but that shouldn't be necessary neither
  529. *
  530. * Note that calls to reserve_mem have to be done explicitely, memory allocated
  531. * with either alloc_up or alloc_down isn't automatically reserved.
  532. */
  533. /*
  534. * Allocates memory in the RMO upward from the kernel/initrd
  535. *
  536. * When align is 0, this is a special case, it means to allocate in place
  537. * at the current location of alloc_bottom or fail (that is basically
  538. * extending the previous allocation). Used for the device-tree flattening
  539. */
  540. static unsigned long __init alloc_up(unsigned long size, unsigned long align)
  541. {
  542. unsigned long offset = reloc_offset();
  543. unsigned long base = _ALIGN_UP(RELOC(alloc_bottom), align);
  544. unsigned long addr = 0;
  545. prom_debug("alloc_up(%x, %x)\n", size, align);
  546. if (RELOC(ram_top) == 0)
  547. prom_panic("alloc_up() called with mem not initialized\n");
  548. if (align)
  549. base = _ALIGN_UP(RELOC(alloc_bottom), align);
  550. else
  551. base = RELOC(alloc_bottom);
  552. for(; (base + size) <= RELOC(alloc_top);
  553. base = _ALIGN_UP(base + 0x100000, align)) {
  554. prom_debug(" trying: 0x%x\n\r", base);
  555. addr = (unsigned long)prom_claim(base, size, 0);
  556. if ((int)addr != PROM_ERROR)
  557. break;
  558. addr = 0;
  559. if (align == 0)
  560. break;
  561. }
  562. if (addr == 0)
  563. return 0;
  564. RELOC(alloc_bottom) = addr;
  565. prom_debug(" -> %x\n", addr);
  566. prom_debug(" alloc_bottom : %x\n", RELOC(alloc_bottom));
  567. prom_debug(" alloc_top : %x\n", RELOC(alloc_top));
  568. prom_debug(" alloc_top_hi : %x\n", RELOC(alloc_top_high));
  569. prom_debug(" rmo_top : %x\n", RELOC(rmo_top));
  570. prom_debug(" ram_top : %x\n", RELOC(ram_top));
  571. return addr;
  572. }
  573. /*
  574. * Allocates memory downard, either from top of RMO, or if highmem
  575. * is set, from the top of RAM. Note that this one doesn't handle
  576. * failures. In does claim memory if highmem is not set.
  577. */
  578. static unsigned long __init alloc_down(unsigned long size, unsigned long align,
  579. int highmem)
  580. {
  581. unsigned long offset = reloc_offset();
  582. unsigned long base, addr = 0;
  583. prom_debug("alloc_down(%x, %x, %s)\n", size, align,
  584. highmem ? RELOC("(high)") : RELOC("(low)"));
  585. if (RELOC(ram_top) == 0)
  586. prom_panic("alloc_down() called with mem not initialized\n");
  587. if (highmem) {
  588. /* Carve out storage for the TCE table. */
  589. addr = _ALIGN_DOWN(RELOC(alloc_top_high) - size, align);
  590. if (addr <= RELOC(alloc_bottom))
  591. return 0;
  592. else {
  593. /* Will we bump into the RMO ? If yes, check out that we
  594. * didn't overlap existing allocations there, if we did,
  595. * we are dead, we must be the first in town !
  596. */
  597. if (addr < RELOC(rmo_top)) {
  598. /* Good, we are first */
  599. if (RELOC(alloc_top) == RELOC(rmo_top))
  600. RELOC(alloc_top) = RELOC(rmo_top) = addr;
  601. else
  602. return 0;
  603. }
  604. RELOC(alloc_top_high) = addr;
  605. }
  606. goto bail;
  607. }
  608. base = _ALIGN_DOWN(RELOC(alloc_top) - size, align);
  609. for(; base > RELOC(alloc_bottom); base = _ALIGN_DOWN(base - 0x100000, align)) {
  610. prom_debug(" trying: 0x%x\n\r", base);
  611. addr = (unsigned long)prom_claim(base, size, 0);
  612. if ((int)addr != PROM_ERROR)
  613. break;
  614. addr = 0;
  615. }
  616. if (addr == 0)
  617. return 0;
  618. RELOC(alloc_top) = addr;
  619. bail:
  620. prom_debug(" -> %x\n", addr);
  621. prom_debug(" alloc_bottom : %x\n", RELOC(alloc_bottom));
  622. prom_debug(" alloc_top : %x\n", RELOC(alloc_top));
  623. prom_debug(" alloc_top_hi : %x\n", RELOC(alloc_top_high));
  624. prom_debug(" rmo_top : %x\n", RELOC(rmo_top));
  625. prom_debug(" ram_top : %x\n", RELOC(ram_top));
  626. return addr;
  627. }
  628. /*
  629. * Parse a "reg" cell
  630. */
  631. static unsigned long __init prom_next_cell(int s, cell_t **cellp)
  632. {
  633. cell_t *p = *cellp;
  634. unsigned long r = 0;
  635. /* Ignore more than 2 cells */
  636. while (s > 2) {
  637. p++;
  638. s--;
  639. }
  640. while (s) {
  641. r <<= 32;
  642. r |= *(p++);
  643. s--;
  644. }
  645. *cellp = p;
  646. return r;
  647. }
  648. /*
  649. * Very dumb function for adding to the memory reserve list, but
  650. * we don't need anything smarter at this point
  651. *
  652. * XXX Eventually check for collisions. They should NEVER happen
  653. * if problems seem to show up, it would be a good start to track
  654. * them down.
  655. */
  656. static void reserve_mem(unsigned long base, unsigned long size)
  657. {
  658. unsigned long offset = reloc_offset();
  659. unsigned long top = base + size;
  660. unsigned long cnt = RELOC(mem_reserve_cnt);
  661. if (size == 0)
  662. return;
  663. /* We need to always keep one empty entry so that we
  664. * have our terminator with "size" set to 0 since we are
  665. * dumb and just copy this entire array to the boot params
  666. */
  667. base = _ALIGN_DOWN(base, PAGE_SIZE);
  668. top = _ALIGN_UP(top, PAGE_SIZE);
  669. size = top - base;
  670. if (cnt >= (MEM_RESERVE_MAP_SIZE - 1))
  671. prom_panic("Memory reserve map exhausted !\n");
  672. RELOC(mem_reserve_map)[cnt].base = base;
  673. RELOC(mem_reserve_map)[cnt].size = size;
  674. RELOC(mem_reserve_cnt) = cnt + 1;
  675. }
  676. /*
  677. * Initialize memory allocation mecanism, parse "memory" nodes and
  678. * obtain that way the top of memory and RMO to setup out local allocator
  679. */
  680. static void __init prom_init_mem(void)
  681. {
  682. phandle node;
  683. char *path, type[64];
  684. unsigned int plen;
  685. cell_t *p, *endp;
  686. unsigned long offset = reloc_offset();
  687. struct prom_t *_prom = PTRRELOC(&prom);
  688. /*
  689. * We iterate the memory nodes to find
  690. * 1) top of RMO (first node)
  691. * 2) top of memory
  692. */
  693. prom_debug("root_addr_cells: %x\n", (long)_prom->root_addr_cells);
  694. prom_debug("root_size_cells: %x\n", (long)_prom->root_size_cells);
  695. prom_debug("scanning memory:\n");
  696. path = RELOC(prom_scratch);
  697. for (node = 0; prom_next_node(&node); ) {
  698. type[0] = 0;
  699. prom_getprop(node, "device_type", type, sizeof(type));
  700. if (strcmp(type, RELOC("memory")))
  701. continue;
  702. plen = prom_getprop(node, "reg", RELOC(regbuf), sizeof(regbuf));
  703. if (plen > sizeof(regbuf)) {
  704. prom_printf("memory node too large for buffer !\n");
  705. plen = sizeof(regbuf);
  706. }
  707. p = RELOC(regbuf);
  708. endp = p + (plen / sizeof(cell_t));
  709. #ifdef DEBUG_PROM
  710. memset(path, 0, PROM_SCRATCH_SIZE);
  711. call_prom("package-to-path", 3, 1, node, path, PROM_SCRATCH_SIZE-1);
  712. prom_debug(" node %s :\n", path);
  713. #endif /* DEBUG_PROM */
  714. while ((endp - p) >= (_prom->root_addr_cells + _prom->root_size_cells)) {
  715. unsigned long base, size;
  716. base = prom_next_cell(_prom->root_addr_cells, &p);
  717. size = prom_next_cell(_prom->root_size_cells, &p);
  718. if (size == 0)
  719. continue;
  720. prom_debug(" %x %x\n", base, size);
  721. if (base == 0)
  722. RELOC(rmo_top) = size;
  723. if ((base + size) > RELOC(ram_top))
  724. RELOC(ram_top) = base + size;
  725. }
  726. }
  727. RELOC(alloc_bottom) = PAGE_ALIGN(RELOC(klimit) - offset + 0x4000);
  728. /* Check if we have an initrd after the kernel, if we do move our bottom
  729. * point to after it
  730. */
  731. if (RELOC(prom_initrd_start)) {
  732. if (RELOC(prom_initrd_end) > RELOC(alloc_bottom))
  733. RELOC(alloc_bottom) = PAGE_ALIGN(RELOC(prom_initrd_end));
  734. }
  735. /*
  736. * If prom_memory_limit is set we reduce the upper limits *except* for
  737. * alloc_top_high. This must be the real top of RAM so we can put
  738. * TCE's up there.
  739. */
  740. RELOC(alloc_top_high) = RELOC(ram_top);
  741. if (RELOC(prom_memory_limit)) {
  742. if (RELOC(prom_memory_limit) <= RELOC(alloc_bottom)) {
  743. prom_printf("Ignoring mem=%x <= alloc_bottom.\n",
  744. RELOC(prom_memory_limit));
  745. RELOC(prom_memory_limit) = 0;
  746. } else if (RELOC(prom_memory_limit) >= RELOC(ram_top)) {
  747. prom_printf("Ignoring mem=%x >= ram_top.\n",
  748. RELOC(prom_memory_limit));
  749. RELOC(prom_memory_limit) = 0;
  750. } else {
  751. RELOC(ram_top) = RELOC(prom_memory_limit);
  752. RELOC(rmo_top) = min(RELOC(rmo_top), RELOC(prom_memory_limit));
  753. }
  754. }
  755. /*
  756. * Setup our top alloc point, that is top of RMO or top of
  757. * segment 0 when running non-LPAR.
  758. */
  759. if ( RELOC(of_platform) == PLATFORM_PSERIES_LPAR )
  760. RELOC(alloc_top) = RELOC(rmo_top);
  761. else
  762. RELOC(alloc_top) = RELOC(rmo_top) = min(0x40000000ul, RELOC(ram_top));
  763. prom_printf("memory layout at init:\n");
  764. prom_printf(" memory_limit : %x (16 MB aligned)\n", RELOC(prom_memory_limit));
  765. prom_printf(" alloc_bottom : %x\n", RELOC(alloc_bottom));
  766. prom_printf(" alloc_top : %x\n", RELOC(alloc_top));
  767. prom_printf(" alloc_top_hi : %x\n", RELOC(alloc_top_high));
  768. prom_printf(" rmo_top : %x\n", RELOC(rmo_top));
  769. prom_printf(" ram_top : %x\n", RELOC(ram_top));
  770. }
  771. /*
  772. * Allocate room for and instanciate RTAS
  773. */
  774. static void __init prom_instantiate_rtas(void)
  775. {
  776. unsigned long offset = reloc_offset();
  777. struct prom_t *_prom = PTRRELOC(&prom);
  778. phandle prom_rtas, rtas_node;
  779. u32 base, entry = 0;
  780. u32 size = 0;
  781. prom_debug("prom_instantiate_rtas: start...\n");
  782. prom_rtas = call_prom("finddevice", 1, 1, ADDR("/rtas"));
  783. prom_debug("prom_rtas: %x\n", prom_rtas);
  784. if (prom_rtas == (phandle) -1)
  785. return;
  786. prom_getprop(prom_rtas, "rtas-size", &size, sizeof(size));
  787. if (size == 0)
  788. return;
  789. base = alloc_down(size, PAGE_SIZE, 0);
  790. if (base == 0) {
  791. prom_printf("RTAS allocation failed !\n");
  792. return;
  793. }
  794. prom_printf("instantiating rtas at 0x%x", base);
  795. rtas_node = call_prom("open", 1, 1, ADDR("/rtas"));
  796. prom_printf("...");
  797. if (call_prom("call-method", 3, 2,
  798. ADDR("instantiate-rtas"),
  799. rtas_node, base) != PROM_ERROR) {
  800. entry = (long)_prom->args.rets[1];
  801. }
  802. if (entry == 0) {
  803. prom_printf(" failed\n");
  804. return;
  805. }
  806. prom_printf(" done\n");
  807. reserve_mem(base, size);
  808. prom_setprop(prom_rtas, "linux,rtas-base", &base, sizeof(base));
  809. prom_setprop(prom_rtas, "linux,rtas-entry", &entry, sizeof(entry));
  810. prom_debug("rtas base = 0x%x\n", base);
  811. prom_debug("rtas entry = 0x%x\n", entry);
  812. prom_debug("rtas size = 0x%x\n", (long)size);
  813. prom_debug("prom_instantiate_rtas: end...\n");
  814. }
  815. /*
  816. * Allocate room for and initialize TCE tables
  817. */
  818. static void __init prom_initialize_tce_table(void)
  819. {
  820. phandle node;
  821. ihandle phb_node;
  822. unsigned long offset = reloc_offset();
  823. char compatible[64], type[64], model[64];
  824. char *path = RELOC(prom_scratch);
  825. u64 base, align;
  826. u32 minalign, minsize;
  827. u64 tce_entry, *tce_entryp;
  828. u64 local_alloc_top, local_alloc_bottom;
  829. u64 i;
  830. if (RELOC(ppc64_iommu_off))
  831. return;
  832. prom_debug("starting prom_initialize_tce_table\n");
  833. /* Cache current top of allocs so we reserve a single block */
  834. local_alloc_top = RELOC(alloc_top_high);
  835. local_alloc_bottom = local_alloc_top;
  836. /* Search all nodes looking for PHBs. */
  837. for (node = 0; prom_next_node(&node); ) {
  838. compatible[0] = 0;
  839. type[0] = 0;
  840. model[0] = 0;
  841. prom_getprop(node, "compatible",
  842. compatible, sizeof(compatible));
  843. prom_getprop(node, "device_type", type, sizeof(type));
  844. prom_getprop(node, "model", model, sizeof(model));
  845. if ((type[0] == 0) || (strstr(type, RELOC("pci")) == NULL))
  846. continue;
  847. /* Keep the old logic in tack to avoid regression. */
  848. if (compatible[0] != 0) {
  849. if ((strstr(compatible, RELOC("python")) == NULL) &&
  850. (strstr(compatible, RELOC("Speedwagon")) == NULL) &&
  851. (strstr(compatible, RELOC("Winnipeg")) == NULL))
  852. continue;
  853. } else if (model[0] != 0) {
  854. if ((strstr(model, RELOC("ython")) == NULL) &&
  855. (strstr(model, RELOC("peedwagon")) == NULL) &&
  856. (strstr(model, RELOC("innipeg")) == NULL))
  857. continue;
  858. }
  859. if (prom_getprop(node, "tce-table-minalign", &minalign,
  860. sizeof(minalign)) == PROM_ERROR)
  861. minalign = 0;
  862. if (prom_getprop(node, "tce-table-minsize", &minsize,
  863. sizeof(minsize)) == PROM_ERROR)
  864. minsize = 4UL << 20;
  865. /*
  866. * Even though we read what OF wants, we just set the table
  867. * size to 4 MB. This is enough to map 2GB of PCI DMA space.
  868. * By doing this, we avoid the pitfalls of trying to DMA to
  869. * MMIO space and the DMA alias hole.
  870. *
  871. * On POWER4, firmware sets the TCE region by assuming
  872. * each TCE table is 8MB. Using this memory for anything
  873. * else will impact performance, so we always allocate 8MB.
  874. * Anton
  875. */
  876. if (__is_processor(PV_POWER4) || __is_processor(PV_POWER4p))
  877. minsize = 8UL << 20;
  878. else
  879. minsize = 4UL << 20;
  880. /* Align to the greater of the align or size */
  881. align = max(minalign, minsize);
  882. base = alloc_down(minsize, align, 1);
  883. if (base == 0)
  884. prom_panic("ERROR, cannot find space for TCE table.\n");
  885. if (base < local_alloc_bottom)
  886. local_alloc_bottom = base;
  887. /* Save away the TCE table attributes for later use. */
  888. prom_setprop(node, "linux,tce-base", &base, sizeof(base));
  889. prom_setprop(node, "linux,tce-size", &minsize, sizeof(minsize));
  890. /* It seems OF doesn't null-terminate the path :-( */
  891. memset(path, 0, sizeof(path));
  892. /* Call OF to setup the TCE hardware */
  893. if (call_prom("package-to-path", 3, 1, node,
  894. path, PROM_SCRATCH_SIZE-1) == PROM_ERROR) {
  895. prom_printf("package-to-path failed\n");
  896. }
  897. prom_debug("TCE table: %s\n", path);
  898. prom_debug("\tnode = 0x%x\n", node);
  899. prom_debug("\tbase = 0x%x\n", base);
  900. prom_debug("\tsize = 0x%x\n", minsize);
  901. /* Initialize the table to have a one-to-one mapping
  902. * over the allocated size.
  903. */
  904. tce_entryp = (unsigned long *)base;
  905. for (i = 0; i < (minsize >> 3) ;tce_entryp++, i++) {
  906. tce_entry = (i << PAGE_SHIFT);
  907. tce_entry |= 0x3;
  908. *tce_entryp = tce_entry;
  909. }
  910. prom_printf("opening PHB %s", path);
  911. phb_node = call_prom("open", 1, 1, path);
  912. if ( (long)phb_node <= 0)
  913. prom_printf("... failed\n");
  914. else
  915. prom_printf("... done\n");
  916. call_prom("call-method", 6, 0, ADDR("set-64-bit-addressing"),
  917. phb_node, -1, minsize,
  918. (u32) base, (u32) (base >> 32));
  919. call_prom("close", 1, 0, phb_node);
  920. }
  921. reserve_mem(local_alloc_bottom, local_alloc_top - local_alloc_bottom);
  922. if (RELOC(prom_memory_limit)) {
  923. /*
  924. * We align the start to a 16MB boundary so we can map the TCE area
  925. * using large pages if possible. The end should be the top of RAM
  926. * so no need to align it.
  927. */
  928. RELOC(prom_tce_alloc_start) = _ALIGN_DOWN(local_alloc_bottom, 0x1000000);
  929. RELOC(prom_tce_alloc_end) = local_alloc_top;
  930. }
  931. /* Flag the first invalid entry */
  932. prom_debug("ending prom_initialize_tce_table\n");
  933. }
  934. /*
  935. * With CHRP SMP we need to use the OF to start the other
  936. * processors so we can't wait until smp_boot_cpus (the OF is
  937. * trashed by then) so we have to put the processors into
  938. * a holding pattern controlled by the kernel (not OF) before
  939. * we destroy the OF.
  940. *
  941. * This uses a chunk of low memory, puts some holding pattern
  942. * code there and sends the other processors off to there until
  943. * smp_boot_cpus tells them to do something. The holding pattern
  944. * checks that address until its cpu # is there, when it is that
  945. * cpu jumps to __secondary_start(). smp_boot_cpus() takes care
  946. * of setting those values.
  947. *
  948. * We also use physical address 0x4 here to tell when a cpu
  949. * is in its holding pattern code.
  950. *
  951. * Fixup comment... DRENG / PPPBBB - Peter
  952. *
  953. * -- Cort
  954. */
  955. static void __init prom_hold_cpus(void)
  956. {
  957. unsigned long i;
  958. unsigned int reg;
  959. phandle node;
  960. unsigned long offset = reloc_offset();
  961. char type[64];
  962. int cpuid = 0;
  963. unsigned int interrupt_server[MAX_CPU_THREADS];
  964. unsigned int cpu_threads, hw_cpu_num;
  965. int propsize;
  966. extern void __secondary_hold(void);
  967. extern unsigned long __secondary_hold_spinloop;
  968. extern unsigned long __secondary_hold_acknowledge;
  969. unsigned long *spinloop
  970. = (void *)virt_to_abs(&__secondary_hold_spinloop);
  971. unsigned long *acknowledge
  972. = (void *)virt_to_abs(&__secondary_hold_acknowledge);
  973. unsigned long secondary_hold
  974. = virt_to_abs(*PTRRELOC((unsigned long *)__secondary_hold));
  975. struct prom_t *_prom = PTRRELOC(&prom);
  976. prom_debug("prom_hold_cpus: start...\n");
  977. prom_debug(" 1) spinloop = 0x%x\n", (unsigned long)spinloop);
  978. prom_debug(" 1) *spinloop = 0x%x\n", *spinloop);
  979. prom_debug(" 1) acknowledge = 0x%x\n",
  980. (unsigned long)acknowledge);
  981. prom_debug(" 1) *acknowledge = 0x%x\n", *acknowledge);
  982. prom_debug(" 1) secondary_hold = 0x%x\n", secondary_hold);
  983. /* Set the common spinloop variable, so all of the secondary cpus
  984. * will block when they are awakened from their OF spinloop.
  985. * This must occur for both SMP and non SMP kernels, since OF will
  986. * be trashed when we move the kernel.
  987. */
  988. *spinloop = 0;
  989. #ifdef CONFIG_HMT
  990. for (i=0; i < NR_CPUS; i++) {
  991. RELOC(hmt_thread_data)[i].pir = 0xdeadbeef;
  992. }
  993. #endif
  994. /* look for cpus */
  995. for (node = 0; prom_next_node(&node); ) {
  996. type[0] = 0;
  997. prom_getprop(node, "device_type", type, sizeof(type));
  998. if (strcmp(type, RELOC("cpu")) != 0)
  999. continue;
  1000. /* Skip non-configured cpus. */
  1001. if (prom_getprop(node, "status", type, sizeof(type)) > 0)
  1002. if (strcmp(type, RELOC("okay")) != 0)
  1003. continue;
  1004. reg = -1;
  1005. prom_getprop(node, "reg", &reg, sizeof(reg));
  1006. prom_debug("\ncpuid = 0x%x\n", cpuid);
  1007. prom_debug("cpu hw idx = 0x%x\n", reg);
  1008. /* Init the acknowledge var which will be reset by
  1009. * the secondary cpu when it awakens from its OF
  1010. * spinloop.
  1011. */
  1012. *acknowledge = (unsigned long)-1;
  1013. propsize = prom_getprop(node, "ibm,ppc-interrupt-server#s",
  1014. &interrupt_server,
  1015. sizeof(interrupt_server));
  1016. if (propsize < 0) {
  1017. /* no property. old hardware has no SMT */
  1018. cpu_threads = 1;
  1019. interrupt_server[0] = reg; /* fake it with phys id */
  1020. } else {
  1021. /* We have a threaded processor */
  1022. cpu_threads = propsize / sizeof(u32);
  1023. if (cpu_threads > MAX_CPU_THREADS) {
  1024. prom_printf("SMT: too many threads!\n"
  1025. "SMT: found %x, max is %x\n",
  1026. cpu_threads, MAX_CPU_THREADS);
  1027. cpu_threads = 1; /* ToDo: panic? */
  1028. }
  1029. }
  1030. hw_cpu_num = interrupt_server[0];
  1031. if (hw_cpu_num != _prom->cpu) {
  1032. /* Primary Thread of non-boot cpu */
  1033. prom_printf("%x : starting cpu hw idx %x... ", cpuid, reg);
  1034. call_prom("start-cpu", 3, 0, node,
  1035. secondary_hold, reg);
  1036. for ( i = 0 ; (i < 100000000) &&
  1037. (*acknowledge == ((unsigned long)-1)); i++ )
  1038. mb();
  1039. if (*acknowledge == reg) {
  1040. prom_printf("done\n");
  1041. /* We have to get every CPU out of OF,
  1042. * even if we never start it. */
  1043. if (cpuid >= NR_CPUS)
  1044. goto next;
  1045. } else {
  1046. prom_printf("failed: %x\n", *acknowledge);
  1047. }
  1048. }
  1049. #ifdef CONFIG_SMP
  1050. else
  1051. prom_printf("%x : boot cpu %x\n", cpuid, reg);
  1052. #endif
  1053. next:
  1054. #ifdef CONFIG_SMP
  1055. /* Init paca for secondary threads. They start later. */
  1056. for (i=1; i < cpu_threads; i++) {
  1057. cpuid++;
  1058. if (cpuid >= NR_CPUS)
  1059. continue;
  1060. }
  1061. #endif /* CONFIG_SMP */
  1062. cpuid++;
  1063. }
  1064. #ifdef CONFIG_HMT
  1065. /* Only enable HMT on processors that provide support. */
  1066. if (__is_processor(PV_PULSAR) ||
  1067. __is_processor(PV_ICESTAR) ||
  1068. __is_processor(PV_SSTAR)) {
  1069. prom_printf(" starting secondary threads\n");
  1070. for (i = 0; i < NR_CPUS; i += 2) {
  1071. if (!cpu_online(i))
  1072. continue;
  1073. if (i == 0) {
  1074. unsigned long pir = mfspr(SPRN_PIR);
  1075. if (__is_processor(PV_PULSAR)) {
  1076. RELOC(hmt_thread_data)[i].pir =
  1077. pir & 0x1f;
  1078. } else {
  1079. RELOC(hmt_thread_data)[i].pir =
  1080. pir & 0x3ff;
  1081. }
  1082. }
  1083. }
  1084. } else {
  1085. prom_printf("Processor is not HMT capable\n");
  1086. }
  1087. #endif
  1088. if (cpuid > NR_CPUS)
  1089. prom_printf("WARNING: maximum CPUs (" __stringify(NR_CPUS)
  1090. ") exceeded: ignoring extras\n");
  1091. prom_debug("prom_hold_cpus: end...\n");
  1092. }
  1093. static void __init prom_init_client_services(unsigned long pp)
  1094. {
  1095. unsigned long offset = reloc_offset();
  1096. struct prom_t *_prom = PTRRELOC(&prom);
  1097. /* Get a handle to the prom entry point before anything else */
  1098. _prom->entry = pp;
  1099. /* Init default value for phys size */
  1100. _prom->root_size_cells = 1;
  1101. _prom->root_addr_cells = 2;
  1102. /* get a handle for the stdout device */
  1103. _prom->chosen = call_prom("finddevice", 1, 1, ADDR("/chosen"));
  1104. if ((long)_prom->chosen <= 0)
  1105. prom_panic("cannot find chosen"); /* msg won't be printed :( */
  1106. /* get device tree root */
  1107. _prom->root = call_prom("finddevice", 1, 1, ADDR("/"));
  1108. if ((long)_prom->root <= 0)
  1109. prom_panic("cannot find device tree root"); /* msg won't be printed :( */
  1110. }
  1111. static void __init prom_init_stdout(void)
  1112. {
  1113. unsigned long offset = reloc_offset();
  1114. struct prom_t *_prom = PTRRELOC(&prom);
  1115. char *path = RELOC(of_stdout_device);
  1116. char type[16];
  1117. u32 val;
  1118. if (prom_getprop(_prom->chosen, "stdout", &val, sizeof(val)) <= 0)
  1119. prom_panic("cannot find stdout");
  1120. _prom->stdout = val;
  1121. /* Get the full OF pathname of the stdout device */
  1122. memset(path, 0, 256);
  1123. call_prom("instance-to-path", 3, 1, _prom->stdout, path, 255);
  1124. val = call_prom("instance-to-package", 1, 1, _prom->stdout);
  1125. prom_setprop(_prom->chosen, "linux,stdout-package", &val, sizeof(val));
  1126. prom_printf("OF stdout device is: %s\n", RELOC(of_stdout_device));
  1127. prom_setprop(_prom->chosen, "linux,stdout-path",
  1128. RELOC(of_stdout_device), strlen(RELOC(of_stdout_device))+1);
  1129. /* If it's a display, note it */
  1130. memset(type, 0, sizeof(type));
  1131. prom_getprop(val, "device_type", type, sizeof(type));
  1132. if (strcmp(type, RELOC("display")) == 0) {
  1133. _prom->disp_node = val;
  1134. prom_setprop(val, "linux,boot-display", NULL, 0);
  1135. }
  1136. }
  1137. static void __init prom_close_stdin(void)
  1138. {
  1139. unsigned long offset = reloc_offset();
  1140. struct prom_t *_prom = PTRRELOC(&prom);
  1141. ihandle val;
  1142. if (prom_getprop(_prom->chosen, "stdin", &val, sizeof(val)) > 0)
  1143. call_prom("close", 1, 0, val);
  1144. }
  1145. static int __init prom_find_machine_type(void)
  1146. {
  1147. unsigned long offset = reloc_offset();
  1148. struct prom_t *_prom = PTRRELOC(&prom);
  1149. char compat[256];
  1150. int len, i = 0;
  1151. phandle rtas;
  1152. len = prom_getprop(_prom->root, "compatible",
  1153. compat, sizeof(compat)-1);
  1154. if (len > 0) {
  1155. compat[len] = 0;
  1156. while (i < len) {
  1157. char *p = &compat[i];
  1158. int sl = strlen(p);
  1159. if (sl == 0)
  1160. break;
  1161. if (strstr(p, RELOC("Power Macintosh")) ||
  1162. strstr(p, RELOC("MacRISC4")))
  1163. return PLATFORM_POWERMAC;
  1164. if (strstr(p, RELOC("Momentum,Maple")))
  1165. return PLATFORM_MAPLE;
  1166. i += sl + 1;
  1167. }
  1168. }
  1169. /* Default to pSeries. We need to know if we are running LPAR */
  1170. rtas = call_prom("finddevice", 1, 1, ADDR("/rtas"));
  1171. if (rtas != (phandle) -1) {
  1172. unsigned long x;
  1173. x = prom_getproplen(rtas, "ibm,hypertas-functions");
  1174. if (x != PROM_ERROR) {
  1175. prom_printf("Hypertas detected, assuming LPAR !\n");
  1176. return PLATFORM_PSERIES_LPAR;
  1177. }
  1178. }
  1179. return PLATFORM_PSERIES;
  1180. }
  1181. static int __init prom_set_color(ihandle ih, int i, int r, int g, int b)
  1182. {
  1183. unsigned long offset = reloc_offset();
  1184. return call_prom("call-method", 6, 1, ADDR("color!"), ih, i, b, g, r);
  1185. }
  1186. /*
  1187. * If we have a display that we don't know how to drive,
  1188. * we will want to try to execute OF's open method for it
  1189. * later. However, OF will probably fall over if we do that
  1190. * we've taken over the MMU.
  1191. * So we check whether we will need to open the display,
  1192. * and if so, open it now.
  1193. */
  1194. static void __init prom_check_displays(void)
  1195. {
  1196. unsigned long offset = reloc_offset();
  1197. struct prom_t *_prom = PTRRELOC(&prom);
  1198. char type[16], *path;
  1199. phandle node;
  1200. ihandle ih;
  1201. int i;
  1202. static unsigned char default_colors[] = {
  1203. 0x00, 0x00, 0x00,
  1204. 0x00, 0x00, 0xaa,
  1205. 0x00, 0xaa, 0x00,
  1206. 0x00, 0xaa, 0xaa,
  1207. 0xaa, 0x00, 0x00,
  1208. 0xaa, 0x00, 0xaa,
  1209. 0xaa, 0xaa, 0x00,
  1210. 0xaa, 0xaa, 0xaa,
  1211. 0x55, 0x55, 0x55,
  1212. 0x55, 0x55, 0xff,
  1213. 0x55, 0xff, 0x55,
  1214. 0x55, 0xff, 0xff,
  1215. 0xff, 0x55, 0x55,
  1216. 0xff, 0x55, 0xff,
  1217. 0xff, 0xff, 0x55,
  1218. 0xff, 0xff, 0xff
  1219. };
  1220. const unsigned char *clut;
  1221. prom_printf("Looking for displays\n");
  1222. for (node = 0; prom_next_node(&node); ) {
  1223. memset(type, 0, sizeof(type));
  1224. prom_getprop(node, "device_type", type, sizeof(type));
  1225. if (strcmp(type, RELOC("display")) != 0)
  1226. continue;
  1227. /* It seems OF doesn't null-terminate the path :-( */
  1228. path = RELOC(prom_scratch);
  1229. memset(path, 0, PROM_SCRATCH_SIZE);
  1230. /*
  1231. * leave some room at the end of the path for appending extra
  1232. * arguments
  1233. */
  1234. if (call_prom("package-to-path", 3, 1, node, path, PROM_SCRATCH_SIZE-10) < 0)
  1235. continue;
  1236. prom_printf("found display : %s, opening ... ", path);
  1237. ih = call_prom("open", 1, 1, path);
  1238. if (ih == (ihandle)0 || ih == (ihandle)-1) {
  1239. prom_printf("failed\n");
  1240. continue;
  1241. }
  1242. /* Success */
  1243. prom_printf("done\n");
  1244. prom_setprop(node, "linux,opened", NULL, 0);
  1245. /*
  1246. * stdout wasn't a display node, pick the first we can find
  1247. * for btext
  1248. */
  1249. if (_prom->disp_node == 0)
  1250. _prom->disp_node = node;
  1251. /* Setup a useable color table when the appropriate
  1252. * method is available. Should update this to set-colors */
  1253. clut = RELOC(default_colors);
  1254. for (i = 0; i < 32; i++, clut += 3)
  1255. if (prom_set_color(ih, i, clut[0], clut[1],
  1256. clut[2]) != 0)
  1257. break;
  1258. #ifdef CONFIG_LOGO_LINUX_CLUT224
  1259. clut = PTRRELOC(RELOC(logo_linux_clut224.clut));
  1260. for (i = 0; i < RELOC(logo_linux_clut224.clutsize); i++, clut += 3)
  1261. if (prom_set_color(ih, i + 32, clut[0], clut[1],
  1262. clut[2]) != 0)
  1263. break;
  1264. #endif /* CONFIG_LOGO_LINUX_CLUT224 */
  1265. }
  1266. }
  1267. /* Return (relocated) pointer to this much memory: moves initrd if reqd. */
  1268. static void __init *make_room(unsigned long *mem_start, unsigned long *mem_end,
  1269. unsigned long needed, unsigned long align)
  1270. {
  1271. unsigned long offset = reloc_offset();
  1272. void *ret;
  1273. *mem_start = _ALIGN(*mem_start, align);
  1274. while ((*mem_start + needed) > *mem_end) {
  1275. unsigned long room, chunk;
  1276. prom_debug("Chunk exhausted, claiming more at %x...\n",
  1277. RELOC(alloc_bottom));
  1278. room = RELOC(alloc_top) - RELOC(alloc_bottom);
  1279. if (room > DEVTREE_CHUNK_SIZE)
  1280. room = DEVTREE_CHUNK_SIZE;
  1281. if (room < PAGE_SIZE)
  1282. prom_panic("No memory for flatten_device_tree (no room)");
  1283. chunk = alloc_up(room, 0);
  1284. if (chunk == 0)
  1285. prom_panic("No memory for flatten_device_tree (claim failed)");
  1286. *mem_end = RELOC(alloc_top);
  1287. }
  1288. ret = (void *)*mem_start;
  1289. *mem_start += needed;
  1290. return ret;
  1291. }
  1292. #define dt_push_token(token, mem_start, mem_end) \
  1293. do { *((u32 *)make_room(mem_start, mem_end, 4, 4)) = token; } while(0)
  1294. static unsigned long __init dt_find_string(char *str)
  1295. {
  1296. unsigned long offset = reloc_offset();
  1297. char *s, *os;
  1298. s = os = (char *)RELOC(dt_string_start);
  1299. s += 4;
  1300. while (s < (char *)RELOC(dt_string_end)) {
  1301. if (strcmp(s, str) == 0)
  1302. return s - os;
  1303. s += strlen(s) + 1;
  1304. }
  1305. return 0;
  1306. }
  1307. static void __init scan_dt_build_strings(phandle node, unsigned long *mem_start,
  1308. unsigned long *mem_end)
  1309. {
  1310. unsigned long offset = reloc_offset();
  1311. char *prev_name, *namep, *sstart;
  1312. unsigned long soff;
  1313. phandle child;
  1314. sstart = (char *)RELOC(dt_string_start);
  1315. /* get and store all property names */
  1316. prev_name = RELOC("");
  1317. for (;;) {
  1318. /* 32 is max len of name including nul. */
  1319. namep = make_room(mem_start, mem_end, 32, 1);
  1320. if (call_prom("nextprop", 3, 1, node, prev_name, namep) <= 0) {
  1321. /* No more nodes: unwind alloc */
  1322. *mem_start = (unsigned long)namep;
  1323. break;
  1324. }
  1325. soff = dt_find_string(namep);
  1326. if (soff != 0) {
  1327. *mem_start = (unsigned long)namep;
  1328. namep = sstart + soff;
  1329. } else {
  1330. /* Trim off some if we can */
  1331. *mem_start = (unsigned long)namep + strlen(namep) + 1;
  1332. RELOC(dt_string_end) = *mem_start;
  1333. }
  1334. prev_name = namep;
  1335. }
  1336. /* do all our children */
  1337. child = call_prom("child", 1, 1, node);
  1338. while (child != (phandle)0) {
  1339. scan_dt_build_strings(child, mem_start, mem_end);
  1340. child = call_prom("peer", 1, 1, child);
  1341. }
  1342. }
  1343. /*
  1344. * The Open Firmware 1275 specification states properties must be 31 bytes or
  1345. * less, however not all firmwares obey this. Make it 64 bytes to be safe.
  1346. */
  1347. #define MAX_PROPERTY_NAME 64
  1348. static void __init scan_dt_build_struct(phandle node, unsigned long *mem_start,
  1349. unsigned long *mem_end)
  1350. {
  1351. int l, align;
  1352. phandle child;
  1353. char *namep, *prev_name, *sstart, *p, *ep;
  1354. unsigned long soff;
  1355. unsigned char *valp;
  1356. unsigned long offset = reloc_offset();
  1357. char pname[MAX_PROPERTY_NAME];
  1358. char *path;
  1359. path = RELOC(prom_scratch);
  1360. dt_push_token(OF_DT_BEGIN_NODE, mem_start, mem_end);
  1361. /* get the node's full name */
  1362. namep = (char *)*mem_start;
  1363. l = call_prom("package-to-path", 3, 1, node,
  1364. namep, *mem_end - *mem_start);
  1365. if (l >= 0) {
  1366. /* Didn't fit? Get more room. */
  1367. if (l+1 > *mem_end - *mem_start) {
  1368. namep = make_room(mem_start, mem_end, l+1, 1);
  1369. call_prom("package-to-path", 3, 1, node, namep, l);
  1370. }
  1371. namep[l] = '\0';
  1372. /* Fixup an Apple bug where they have bogus \0 chars in the
  1373. * middle of the path in some properties
  1374. */
  1375. for (p = namep, ep = namep + l; p < ep; p++)
  1376. if (*p == '\0') {
  1377. memmove(p, p+1, ep - p);
  1378. ep--; l--;
  1379. }
  1380. *mem_start = _ALIGN(((unsigned long) namep) + strlen(namep) + 1, 4);
  1381. }
  1382. /* get it again for debugging */
  1383. memset(path, 0, PROM_SCRATCH_SIZE);
  1384. call_prom("package-to-path", 3, 1, node, path, PROM_SCRATCH_SIZE-1);
  1385. /* get and store all properties */
  1386. prev_name = RELOC("");
  1387. sstart = (char *)RELOC(dt_string_start);
  1388. for (;;) {
  1389. if (call_prom("nextprop", 3, 1, node, prev_name, pname) <= 0)
  1390. break;
  1391. /* find string offset */
  1392. soff = dt_find_string(pname);
  1393. if (soff == 0) {
  1394. prom_printf("WARNING: Can't find string index for <%s>, node %s\n",
  1395. pname, path);
  1396. break;
  1397. }
  1398. prev_name = sstart + soff;
  1399. /* get length */
  1400. l = call_prom("getproplen", 2, 1, node, pname);
  1401. /* sanity checks */
  1402. if (l < 0)
  1403. continue;
  1404. if (l > MAX_PROPERTY_LENGTH) {
  1405. prom_printf("WARNING: ignoring large property ");
  1406. /* It seems OF doesn't null-terminate the path :-( */
  1407. prom_printf("[%s] ", path);
  1408. prom_printf("%s length 0x%x\n", pname, l);
  1409. continue;
  1410. }
  1411. /* push property head */
  1412. dt_push_token(OF_DT_PROP, mem_start, mem_end);
  1413. dt_push_token(l, mem_start, mem_end);
  1414. dt_push_token(soff, mem_start, mem_end);
  1415. /* push property content */
  1416. align = (l >= 8) ? 8 : 4;
  1417. valp = make_room(mem_start, mem_end, l, align);
  1418. call_prom("getprop", 4, 1, node, pname, valp, l);
  1419. *mem_start = _ALIGN(*mem_start, 4);
  1420. }
  1421. /* Add a "linux,phandle" property. */
  1422. soff = dt_find_string(RELOC("linux,phandle"));
  1423. if (soff == 0)
  1424. prom_printf("WARNING: Can't find string index for <linux-phandle>"
  1425. " node %s\n", path);
  1426. else {
  1427. dt_push_token(OF_DT_PROP, mem_start, mem_end);
  1428. dt_push_token(4, mem_start, mem_end);
  1429. dt_push_token(soff, mem_start, mem_end);
  1430. valp = make_room(mem_start, mem_end, 4, 4);
  1431. *(u32 *)valp = node;
  1432. }
  1433. /* do all our children */
  1434. child = call_prom("child", 1, 1, node);
  1435. while (child != (phandle)0) {
  1436. scan_dt_build_struct(child, mem_start, mem_end);
  1437. child = call_prom("peer", 1, 1, child);
  1438. }
  1439. dt_push_token(OF_DT_END_NODE, mem_start, mem_end);
  1440. }
  1441. static void __init flatten_device_tree(void)
  1442. {
  1443. phandle root;
  1444. unsigned long offset = reloc_offset();
  1445. unsigned long mem_start, mem_end, room;
  1446. struct boot_param_header *hdr;
  1447. char *namep;
  1448. u64 *rsvmap;
  1449. /*
  1450. * Check how much room we have between alloc top & bottom (+/- a
  1451. * few pages), crop to 4Mb, as this is our "chuck" size
  1452. */
  1453. room = RELOC(alloc_top) - RELOC(alloc_bottom) - 0x4000;
  1454. if (room > DEVTREE_CHUNK_SIZE)
  1455. room = DEVTREE_CHUNK_SIZE;
  1456. prom_debug("starting device tree allocs at %x\n", RELOC(alloc_bottom));
  1457. /* Now try to claim that */
  1458. mem_start = (unsigned long)alloc_up(room, PAGE_SIZE);
  1459. if (mem_start == 0)
  1460. prom_panic("Can't allocate initial device-tree chunk\n");
  1461. mem_end = RELOC(alloc_top);
  1462. /* Get root of tree */
  1463. root = call_prom("peer", 1, 1, (phandle)0);
  1464. if (root == (phandle)0)
  1465. prom_panic ("couldn't get device tree root\n");
  1466. /* Build header and make room for mem rsv map */
  1467. mem_start = _ALIGN(mem_start, 4);
  1468. hdr = make_room(&mem_start, &mem_end, sizeof(struct boot_param_header), 4);
  1469. RELOC(dt_header_start) = (unsigned long)hdr;
  1470. rsvmap = make_room(&mem_start, &mem_end, sizeof(mem_reserve_map), 8);
  1471. /* Start of strings */
  1472. mem_start = PAGE_ALIGN(mem_start);
  1473. RELOC(dt_string_start) = mem_start;
  1474. mem_start += 4; /* hole */
  1475. /* Add "linux,phandle" in there, we'll need it */
  1476. namep = make_room(&mem_start, &mem_end, 16, 1);
  1477. strcpy(namep, RELOC("linux,phandle"));
  1478. mem_start = (unsigned long)namep + strlen(namep) + 1;
  1479. RELOC(dt_string_end) = mem_start;
  1480. /* Build string array */
  1481. prom_printf("Building dt strings...\n");
  1482. scan_dt_build_strings(root, &mem_start, &mem_end);
  1483. /* Build structure */
  1484. mem_start = PAGE_ALIGN(mem_start);
  1485. RELOC(dt_struct_start) = mem_start;
  1486. prom_printf("Building dt structure...\n");
  1487. scan_dt_build_struct(root, &mem_start, &mem_end);
  1488. dt_push_token(OF_DT_END, &mem_start, &mem_end);
  1489. RELOC(dt_struct_end) = PAGE_ALIGN(mem_start);
  1490. /* Finish header */
  1491. hdr->magic = OF_DT_HEADER;
  1492. hdr->totalsize = RELOC(dt_struct_end) - RELOC(dt_header_start);
  1493. hdr->off_dt_struct = RELOC(dt_struct_start) - RELOC(dt_header_start);
  1494. hdr->off_dt_strings = RELOC(dt_string_start) - RELOC(dt_header_start);
  1495. hdr->off_mem_rsvmap = ((unsigned long)rsvmap) - RELOC(dt_header_start);
  1496. hdr->version = OF_DT_VERSION;
  1497. hdr->last_comp_version = 1;
  1498. /* Reserve the whole thing and copy the reserve map in, we
  1499. * also bump mem_reserve_cnt to cause further reservations to
  1500. * fail since it's too late.
  1501. */
  1502. reserve_mem(RELOC(dt_header_start), hdr->totalsize);
  1503. memcpy(rsvmap, RELOC(mem_reserve_map), sizeof(mem_reserve_map));
  1504. #ifdef DEBUG_PROM
  1505. {
  1506. int i;
  1507. prom_printf("reserved memory map:\n");
  1508. for (i = 0; i < RELOC(mem_reserve_cnt); i++)
  1509. prom_printf(" %x - %x\n", RELOC(mem_reserve_map)[i].base,
  1510. RELOC(mem_reserve_map)[i].size);
  1511. }
  1512. #endif
  1513. RELOC(mem_reserve_cnt) = MEM_RESERVE_MAP_SIZE;
  1514. prom_printf("Device tree strings 0x%x -> 0x%x\n",
  1515. RELOC(dt_string_start), RELOC(dt_string_end));
  1516. prom_printf("Device tree struct 0x%x -> 0x%x\n",
  1517. RELOC(dt_struct_start), RELOC(dt_struct_end));
  1518. }
  1519. static void __init fixup_device_tree(void)
  1520. {
  1521. unsigned long offset = reloc_offset();
  1522. phandle u3, i2c, mpic;
  1523. u32 u3_rev;
  1524. u32 interrupts[2];
  1525. u32 parent;
  1526. /* Some G5s have a missing interrupt definition, fix it up here */
  1527. u3 = call_prom("finddevice", 1, 1, ADDR("/u3@0,f8000000"));
  1528. if ((long)u3 <= 0)
  1529. return;
  1530. i2c = call_prom("finddevice", 1, 1, ADDR("/u3@0,f8000000/i2c@f8001000"));
  1531. if ((long)i2c <= 0)
  1532. return;
  1533. mpic = call_prom("finddevice", 1, 1, ADDR("/u3@0,f8000000/mpic@f8040000"));
  1534. if ((long)mpic <= 0)
  1535. return;
  1536. /* check if proper rev of u3 */
  1537. if (prom_getprop(u3, "device-rev", &u3_rev, sizeof(u3_rev)) <= 0)
  1538. return;
  1539. if (u3_rev != 0x35)
  1540. return;
  1541. /* does it need fixup ? */
  1542. if (prom_getproplen(i2c, "interrupts") > 0)
  1543. return;
  1544. /* interrupt on this revision of u3 is number 0 and level */
  1545. interrupts[0] = 0;
  1546. interrupts[1] = 1;
  1547. prom_setprop(i2c, "interrupts", &interrupts, sizeof(interrupts));
  1548. parent = (u32)mpic;
  1549. prom_setprop(i2c, "interrupt-parent", &parent, sizeof(parent));
  1550. }
  1551. static void __init prom_find_boot_cpu(void)
  1552. {
  1553. unsigned long offset = reloc_offset();
  1554. struct prom_t *_prom = PTRRELOC(&prom);
  1555. u32 getprop_rval;
  1556. ihandle prom_cpu;
  1557. phandle cpu_pkg;
  1558. if (prom_getprop(_prom->chosen, "cpu", &prom_cpu, sizeof(prom_cpu)) <= 0)
  1559. prom_panic("cannot find boot cpu");
  1560. cpu_pkg = call_prom("instance-to-package", 1, 1, prom_cpu);
  1561. prom_setprop(cpu_pkg, "linux,boot-cpu", NULL, 0);
  1562. prom_getprop(cpu_pkg, "reg", &getprop_rval, sizeof(getprop_rval));
  1563. _prom->cpu = getprop_rval;
  1564. prom_debug("Booting CPU hw index = 0x%x\n", _prom->cpu);
  1565. }
  1566. static void __init prom_check_initrd(unsigned long r3, unsigned long r4)
  1567. {
  1568. #ifdef CONFIG_BLK_DEV_INITRD
  1569. unsigned long offset = reloc_offset();
  1570. struct prom_t *_prom = PTRRELOC(&prom);
  1571. if ( r3 && r4 && r4 != 0xdeadbeef) {
  1572. u64 val;
  1573. RELOC(prom_initrd_start) = (r3 >= KERNELBASE) ? __pa(r3) : r3;
  1574. RELOC(prom_initrd_end) = RELOC(prom_initrd_start) + r4;
  1575. val = (u64)RELOC(prom_initrd_start);
  1576. prom_setprop(_prom->chosen, "linux,initrd-start", &val, sizeof(val));
  1577. val = (u64)RELOC(prom_initrd_end);
  1578. prom_setprop(_prom->chosen, "linux,initrd-end", &val, sizeof(val));
  1579. reserve_mem(RELOC(prom_initrd_start),
  1580. RELOC(prom_initrd_end) - RELOC(prom_initrd_start));
  1581. prom_debug("initrd_start=0x%x\n", RELOC(prom_initrd_start));
  1582. prom_debug("initrd_end=0x%x\n", RELOC(prom_initrd_end));
  1583. }
  1584. #endif /* CONFIG_BLK_DEV_INITRD */
  1585. }
  1586. /*
  1587. * We enter here early on, when the Open Firmware prom is still
  1588. * handling exceptions and the MMU hash table for us.
  1589. */
  1590. unsigned long __init prom_init(unsigned long r3, unsigned long r4, unsigned long pp,
  1591. unsigned long r6, unsigned long r7)
  1592. {
  1593. unsigned long offset = reloc_offset();
  1594. struct prom_t *_prom = PTRRELOC(&prom);
  1595. unsigned long phys = KERNELBASE - offset;
  1596. u32 getprop_rval;
  1597. /*
  1598. * First zero the BSS
  1599. */
  1600. memset(PTRRELOC(&__bss_start), 0, __bss_stop - __bss_start);
  1601. /*
  1602. * Init interface to Open Firmware, get some node references,
  1603. * like /chosen
  1604. */
  1605. prom_init_client_services(pp);
  1606. /*
  1607. * Init prom stdout device
  1608. */
  1609. prom_init_stdout();
  1610. prom_debug("klimit=0x%x\n", RELOC(klimit));
  1611. prom_debug("offset=0x%x\n", offset);
  1612. /*
  1613. * Check for an initrd
  1614. */
  1615. prom_check_initrd(r3, r4);
  1616. /*
  1617. * Get default machine type. At this point, we do not differenciate
  1618. * between pSeries SMP and pSeries LPAR
  1619. */
  1620. RELOC(of_platform) = prom_find_machine_type();
  1621. getprop_rval = RELOC(of_platform);
  1622. prom_setprop(_prom->chosen, "linux,platform",
  1623. &getprop_rval, sizeof(getprop_rval));
  1624. /*
  1625. * On pSeries, inform the firmware about our capabilities
  1626. */
  1627. if (RELOC(of_platform) & PLATFORM_PSERIES)
  1628. prom_send_capabilities();
  1629. /*
  1630. * On pSeries, copy the CPU hold code
  1631. */
  1632. if (RELOC(of_platform) & PLATFORM_PSERIES)
  1633. copy_and_flush(0, KERNELBASE - offset, 0x100, 0);
  1634. /*
  1635. * Get memory cells format
  1636. */
  1637. getprop_rval = 1;
  1638. prom_getprop(_prom->root, "#size-cells",
  1639. &getprop_rval, sizeof(getprop_rval));
  1640. _prom->root_size_cells = getprop_rval;
  1641. getprop_rval = 2;
  1642. prom_getprop(_prom->root, "#address-cells",
  1643. &getprop_rval, sizeof(getprop_rval));
  1644. _prom->root_addr_cells = getprop_rval;
  1645. /*
  1646. * Do early parsing of command line
  1647. */
  1648. early_cmdline_parse();
  1649. /*
  1650. * Initialize memory management within prom_init
  1651. */
  1652. prom_init_mem();
  1653. /*
  1654. * Determine which cpu is actually running right _now_
  1655. */
  1656. prom_find_boot_cpu();
  1657. /*
  1658. * Initialize display devices
  1659. */
  1660. prom_check_displays();
  1661. /*
  1662. * Initialize IOMMU (TCE tables) on pSeries. Do that before anything else
  1663. * that uses the allocator, we need to make sure we get the top of memory
  1664. * available for us here...
  1665. */
  1666. if (RELOC(of_platform) == PLATFORM_PSERIES)
  1667. prom_initialize_tce_table();
  1668. /*
  1669. * On non-powermacs, try to instantiate RTAS and puts all CPUs
  1670. * in spin-loops. PowerMacs don't have a working RTAS and use
  1671. * a different way to spin CPUs
  1672. */
  1673. if (RELOC(of_platform) != PLATFORM_POWERMAC) {
  1674. prom_instantiate_rtas();
  1675. prom_hold_cpus();
  1676. }
  1677. /*
  1678. * Fill in some infos for use by the kernel later on
  1679. */
  1680. if (RELOC(ppc64_iommu_off))
  1681. prom_setprop(_prom->chosen, "linux,iommu-off", NULL, 0);
  1682. if (RELOC(iommu_force_on))
  1683. prom_setprop(_prom->chosen, "linux,iommu-force-on", NULL, 0);
  1684. if (RELOC(prom_memory_limit))
  1685. prom_setprop(_prom->chosen, "linux,memory-limit",
  1686. PTRRELOC(&prom_memory_limit), sizeof(RELOC(prom_memory_limit)));
  1687. if (RELOC(prom_tce_alloc_start)) {
  1688. prom_setprop(_prom->chosen, "linux,tce-alloc-start",
  1689. PTRRELOC(&prom_tce_alloc_start), sizeof(RELOC(prom_tce_alloc_start)));
  1690. prom_setprop(_prom->chosen, "linux,tce-alloc-end",
  1691. PTRRELOC(&prom_tce_alloc_end), sizeof(RELOC(prom_tce_alloc_end)));
  1692. }
  1693. /*
  1694. * Fixup any known bugs in the device-tree
  1695. */
  1696. fixup_device_tree();
  1697. /*
  1698. * Now finally create the flattened device-tree
  1699. */
  1700. prom_printf("copying OF device tree ...\n");
  1701. flatten_device_tree();
  1702. /* in case stdin is USB and still active on IBM machines... */
  1703. prom_close_stdin();
  1704. /*
  1705. * Call OF "quiesce" method to shut down pending DMA's from
  1706. * devices etc...
  1707. */
  1708. prom_printf("Calling quiesce ...\n");
  1709. call_prom("quiesce", 0, 0);
  1710. /*
  1711. * And finally, call the kernel passing it the flattened device
  1712. * tree and NULL as r5, thus triggering the new entry point which
  1713. * is common to us and kexec
  1714. */
  1715. prom_printf("returning from prom_init\n");
  1716. prom_debug("->dt_header_start=0x%x\n", RELOC(dt_header_start));
  1717. prom_debug("->phys=0x%x\n", phys);
  1718. __start(RELOC(dt_header_start), phys, 0);
  1719. return 0;
  1720. }