setup.c 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994
  1. /*
  2. * Copyright (c) 2000 Mike Corrigan <mikejc@us.ibm.com>
  3. * Copyright (c) 1999-2000 Grant Erickson <grant@lcse.umn.edu>
  4. *
  5. * Description:
  6. * Architecture- / platform-specific boot-time initialization code for
  7. * the IBM iSeries LPAR. Adapted from original code by Grant Erickson and
  8. * code by Gary Thomas, Cort Dougan <cort@fsmlabs.com>, and Dan Malek
  9. * <dan@net4x.com>.
  10. *
  11. * This program is free software; you can redistribute it and/or
  12. * modify it under the terms of the GNU General Public License
  13. * as published by the Free Software Foundation; either version
  14. * 2 of the License, or (at your option) any later version.
  15. */
  16. #undef DEBUG
  17. #include <linux/config.h>
  18. #include <linux/init.h>
  19. #include <linux/threads.h>
  20. #include <linux/smp.h>
  21. #include <linux/param.h>
  22. #include <linux/string.h>
  23. #include <linux/initrd.h>
  24. #include <linux/seq_file.h>
  25. #include <linux/kdev_t.h>
  26. #include <linux/major.h>
  27. #include <linux/root_dev.h>
  28. #include <linux/kernel.h>
  29. #include <asm/processor.h>
  30. #include <asm/machdep.h>
  31. #include <asm/page.h>
  32. #include <asm/mmu.h>
  33. #include <asm/pgtable.h>
  34. #include <asm/mmu_context.h>
  35. #include <asm/cputable.h>
  36. #include <asm/sections.h>
  37. #include <asm/iommu.h>
  38. #include <asm/firmware.h>
  39. #include <asm/system.h>
  40. #include <asm/time.h>
  41. #include <asm/paca.h>
  42. #include <asm/cache.h>
  43. #include <asm/sections.h>
  44. #include <asm/abs_addr.h>
  45. #include <asm/iseries/hv_lp_config.h>
  46. #include <asm/iseries/hv_call_event.h>
  47. #include <asm/iseries/hv_call_xm.h>
  48. #include <asm/iseries/it_lp_queue.h>
  49. #include <asm/iseries/mf.h>
  50. #include <asm/iseries/it_exp_vpd_panel.h>
  51. #include <asm/iseries/hv_lp_event.h>
  52. #include <asm/iseries/lpar_map.h>
  53. #include <asm/udbg.h>
  54. #include "naca.h"
  55. #include "setup.h"
  56. #include "irq.h"
  57. #include "vpd_areas.h"
  58. #include "processor_vpd.h"
  59. #include "main_store.h"
  60. #include "call_sm.h"
  61. #include "call_hpt.h"
  62. #ifdef DEBUG
  63. #define DBG(fmt...) udbg_printf(fmt)
  64. #else
  65. #define DBG(fmt...)
  66. #endif
  67. /* Function Prototypes */
  68. static unsigned long build_iSeries_Memory_Map(void);
  69. static void iseries_shared_idle(void);
  70. static void iseries_dedicated_idle(void);
  71. #ifdef CONFIG_PCI
  72. extern void iSeries_pci_final_fixup(void);
  73. #else
  74. static void iSeries_pci_final_fixup(void) { }
  75. #endif
  76. /* Global Variables */
  77. int piranha_simulator;
  78. extern int rd_size; /* Defined in drivers/block/rd.c */
  79. extern unsigned long embedded_sysmap_start;
  80. extern unsigned long embedded_sysmap_end;
  81. extern unsigned long iSeries_recal_tb;
  82. extern unsigned long iSeries_recal_titan;
  83. static unsigned long cmd_mem_limit;
  84. struct MemoryBlock {
  85. unsigned long absStart;
  86. unsigned long absEnd;
  87. unsigned long logicalStart;
  88. unsigned long logicalEnd;
  89. };
  90. /*
  91. * Process the main store vpd to determine where the holes in memory are
  92. * and return the number of physical blocks and fill in the array of
  93. * block data.
  94. */
  95. static unsigned long iSeries_process_Condor_mainstore_vpd(
  96. struct MemoryBlock *mb_array, unsigned long max_entries)
  97. {
  98. unsigned long holeFirstChunk, holeSizeChunks;
  99. unsigned long numMemoryBlocks = 1;
  100. struct IoHriMainStoreSegment4 *msVpd =
  101. (struct IoHriMainStoreSegment4 *)xMsVpd;
  102. unsigned long holeStart = msVpd->nonInterleavedBlocksStartAdr;
  103. unsigned long holeEnd = msVpd->nonInterleavedBlocksEndAdr;
  104. unsigned long holeSize = holeEnd - holeStart;
  105. printk("Mainstore_VPD: Condor\n");
  106. /*
  107. * Determine if absolute memory has any
  108. * holes so that we can interpret the
  109. * access map we get back from the hypervisor
  110. * correctly.
  111. */
  112. mb_array[0].logicalStart = 0;
  113. mb_array[0].logicalEnd = 0x100000000;
  114. mb_array[0].absStart = 0;
  115. mb_array[0].absEnd = 0x100000000;
  116. if (holeSize) {
  117. numMemoryBlocks = 2;
  118. holeStart = holeStart & 0x000fffffffffffff;
  119. holeStart = addr_to_chunk(holeStart);
  120. holeFirstChunk = holeStart;
  121. holeSize = addr_to_chunk(holeSize);
  122. holeSizeChunks = holeSize;
  123. printk( "Main store hole: start chunk = %0lx, size = %0lx chunks\n",
  124. holeFirstChunk, holeSizeChunks );
  125. mb_array[0].logicalEnd = holeFirstChunk;
  126. mb_array[0].absEnd = holeFirstChunk;
  127. mb_array[1].logicalStart = holeFirstChunk;
  128. mb_array[1].logicalEnd = 0x100000000 - holeSizeChunks;
  129. mb_array[1].absStart = holeFirstChunk + holeSizeChunks;
  130. mb_array[1].absEnd = 0x100000000;
  131. }
  132. return numMemoryBlocks;
  133. }
  134. #define MaxSegmentAreas 32
  135. #define MaxSegmentAdrRangeBlocks 128
  136. #define MaxAreaRangeBlocks 4
  137. static unsigned long iSeries_process_Regatta_mainstore_vpd(
  138. struct MemoryBlock *mb_array, unsigned long max_entries)
  139. {
  140. struct IoHriMainStoreSegment5 *msVpdP =
  141. (struct IoHriMainStoreSegment5 *)xMsVpd;
  142. unsigned long numSegmentBlocks = 0;
  143. u32 existsBits = msVpdP->msAreaExists;
  144. unsigned long area_num;
  145. printk("Mainstore_VPD: Regatta\n");
  146. for (area_num = 0; area_num < MaxSegmentAreas; ++area_num ) {
  147. unsigned long numAreaBlocks;
  148. struct IoHriMainStoreArea4 *currentArea;
  149. if (existsBits & 0x80000000) {
  150. unsigned long block_num;
  151. currentArea = &msVpdP->msAreaArray[area_num];
  152. numAreaBlocks = currentArea->numAdrRangeBlocks;
  153. printk("ms_vpd: processing area %2ld blocks=%ld",
  154. area_num, numAreaBlocks);
  155. for (block_num = 0; block_num < numAreaBlocks;
  156. ++block_num ) {
  157. /* Process an address range block */
  158. struct MemoryBlock tempBlock;
  159. unsigned long i;
  160. tempBlock.absStart =
  161. (unsigned long)currentArea->xAdrRangeBlock[block_num].blockStart;
  162. tempBlock.absEnd =
  163. (unsigned long)currentArea->xAdrRangeBlock[block_num].blockEnd;
  164. tempBlock.logicalStart = 0;
  165. tempBlock.logicalEnd = 0;
  166. printk("\n block %ld absStart=%016lx absEnd=%016lx",
  167. block_num, tempBlock.absStart,
  168. tempBlock.absEnd);
  169. for (i = 0; i < numSegmentBlocks; ++i) {
  170. if (mb_array[i].absStart ==
  171. tempBlock.absStart)
  172. break;
  173. }
  174. if (i == numSegmentBlocks) {
  175. if (numSegmentBlocks == max_entries)
  176. panic("iSeries_process_mainstore_vpd: too many memory blocks");
  177. mb_array[numSegmentBlocks] = tempBlock;
  178. ++numSegmentBlocks;
  179. } else
  180. printk(" (duplicate)");
  181. }
  182. printk("\n");
  183. }
  184. existsBits <<= 1;
  185. }
  186. /* Now sort the blocks found into ascending sequence */
  187. if (numSegmentBlocks > 1) {
  188. unsigned long m, n;
  189. for (m = 0; m < numSegmentBlocks - 1; ++m) {
  190. for (n = numSegmentBlocks - 1; m < n; --n) {
  191. if (mb_array[n].absStart <
  192. mb_array[n-1].absStart) {
  193. struct MemoryBlock tempBlock;
  194. tempBlock = mb_array[n];
  195. mb_array[n] = mb_array[n-1];
  196. mb_array[n-1] = tempBlock;
  197. }
  198. }
  199. }
  200. }
  201. /*
  202. * Assign "logical" addresses to each block. These
  203. * addresses correspond to the hypervisor "bitmap" space.
  204. * Convert all addresses into units of 256K chunks.
  205. */
  206. {
  207. unsigned long i, nextBitmapAddress;
  208. printk("ms_vpd: %ld sorted memory blocks\n", numSegmentBlocks);
  209. nextBitmapAddress = 0;
  210. for (i = 0; i < numSegmentBlocks; ++i) {
  211. unsigned long length = mb_array[i].absEnd -
  212. mb_array[i].absStart;
  213. mb_array[i].logicalStart = nextBitmapAddress;
  214. mb_array[i].logicalEnd = nextBitmapAddress + length;
  215. nextBitmapAddress += length;
  216. printk(" Bitmap range: %016lx - %016lx\n"
  217. " Absolute range: %016lx - %016lx\n",
  218. mb_array[i].logicalStart,
  219. mb_array[i].logicalEnd,
  220. mb_array[i].absStart, mb_array[i].absEnd);
  221. mb_array[i].absStart = addr_to_chunk(mb_array[i].absStart &
  222. 0x000fffffffffffff);
  223. mb_array[i].absEnd = addr_to_chunk(mb_array[i].absEnd &
  224. 0x000fffffffffffff);
  225. mb_array[i].logicalStart =
  226. addr_to_chunk(mb_array[i].logicalStart);
  227. mb_array[i].logicalEnd = addr_to_chunk(mb_array[i].logicalEnd);
  228. }
  229. }
  230. return numSegmentBlocks;
  231. }
  232. static unsigned long iSeries_process_mainstore_vpd(struct MemoryBlock *mb_array,
  233. unsigned long max_entries)
  234. {
  235. unsigned long i;
  236. unsigned long mem_blocks = 0;
  237. if (cpu_has_feature(CPU_FTR_SLB))
  238. mem_blocks = iSeries_process_Regatta_mainstore_vpd(mb_array,
  239. max_entries);
  240. else
  241. mem_blocks = iSeries_process_Condor_mainstore_vpd(mb_array,
  242. max_entries);
  243. printk("Mainstore_VPD: numMemoryBlocks = %ld \n", mem_blocks);
  244. for (i = 0; i < mem_blocks; ++i) {
  245. printk("Mainstore_VPD: block %3ld logical chunks %016lx - %016lx\n"
  246. " abs chunks %016lx - %016lx\n",
  247. i, mb_array[i].logicalStart, mb_array[i].logicalEnd,
  248. mb_array[i].absStart, mb_array[i].absEnd);
  249. }
  250. return mem_blocks;
  251. }
  252. static void __init iSeries_get_cmdline(void)
  253. {
  254. char *p, *q;
  255. /* copy the command line parameter from the primary VSP */
  256. HvCallEvent_dmaToSp(cmd_line, 2 * 64* 1024, 256,
  257. HvLpDma_Direction_RemoteToLocal);
  258. p = cmd_line;
  259. q = cmd_line + 255;
  260. while(p < q) {
  261. if (!*p || *p == '\n')
  262. break;
  263. ++p;
  264. }
  265. *p = 0;
  266. }
  267. static void __init iSeries_init_early(void)
  268. {
  269. DBG(" -> iSeries_init_early()\n");
  270. ppc64_interrupt_controller = IC_ISERIES;
  271. #if defined(CONFIG_BLK_DEV_INITRD)
  272. /*
  273. * If the init RAM disk has been configured and there is
  274. * a non-zero starting address for it, set it up
  275. */
  276. if (naca.xRamDisk) {
  277. initrd_start = (unsigned long)__va(naca.xRamDisk);
  278. initrd_end = initrd_start + naca.xRamDiskSize * HW_PAGE_SIZE;
  279. initrd_below_start_ok = 1; // ramdisk in kernel space
  280. ROOT_DEV = Root_RAM0;
  281. if (((rd_size * 1024) / HW_PAGE_SIZE) < naca.xRamDiskSize)
  282. rd_size = (naca.xRamDiskSize * HW_PAGE_SIZE) / 1024;
  283. } else
  284. #endif /* CONFIG_BLK_DEV_INITRD */
  285. {
  286. /* ROOT_DEV = MKDEV(VIODASD_MAJOR, 1); */
  287. }
  288. iSeries_recal_tb = get_tb();
  289. iSeries_recal_titan = HvCallXm_loadTod();
  290. /*
  291. * Initialize the hash table management pointers
  292. */
  293. hpte_init_iSeries();
  294. /*
  295. * Initialize the DMA/TCE management
  296. */
  297. iommu_init_early_iSeries();
  298. /* Initialize machine-dependency vectors */
  299. #ifdef CONFIG_SMP
  300. smp_init_iSeries();
  301. #endif
  302. if (itLpNaca.xPirEnvironMode == 0)
  303. piranha_simulator = 1;
  304. /* Associate Lp Event Queue 0 with processor 0 */
  305. HvCallEvent_setLpEventQueueInterruptProc(0, 0);
  306. mf_init();
  307. /* If we were passed an initrd, set the ROOT_DEV properly if the values
  308. * look sensible. If not, clear initrd reference.
  309. */
  310. #ifdef CONFIG_BLK_DEV_INITRD
  311. if (initrd_start >= KERNELBASE && initrd_end >= KERNELBASE &&
  312. initrd_end > initrd_start)
  313. ROOT_DEV = Root_RAM0;
  314. else
  315. initrd_start = initrd_end = 0;
  316. #endif /* CONFIG_BLK_DEV_INITRD */
  317. DBG(" <- iSeries_init_early()\n");
  318. }
  319. struct mschunks_map mschunks_map = {
  320. /* XXX We don't use these, but Piranha might need them. */
  321. .chunk_size = MSCHUNKS_CHUNK_SIZE,
  322. .chunk_shift = MSCHUNKS_CHUNK_SHIFT,
  323. .chunk_mask = MSCHUNKS_OFFSET_MASK,
  324. };
  325. EXPORT_SYMBOL(mschunks_map);
  326. void mschunks_alloc(unsigned long num_chunks)
  327. {
  328. klimit = _ALIGN(klimit, sizeof(u32));
  329. mschunks_map.mapping = (u32 *)klimit;
  330. klimit += num_chunks * sizeof(u32);
  331. mschunks_map.num_chunks = num_chunks;
  332. }
  333. /*
  334. * The iSeries may have very large memories ( > 128 GB ) and a partition
  335. * may get memory in "chunks" that may be anywhere in the 2**52 real
  336. * address space. The chunks are 256K in size. To map this to the
  337. * memory model Linux expects, the AS/400 specific code builds a
  338. * translation table to translate what Linux thinks are "physical"
  339. * addresses to the actual real addresses. This allows us to make
  340. * it appear to Linux that we have contiguous memory starting at
  341. * physical address zero while in fact this could be far from the truth.
  342. * To avoid confusion, I'll let the words physical and/or real address
  343. * apply to the Linux addresses while I'll use "absolute address" to
  344. * refer to the actual hardware real address.
  345. *
  346. * build_iSeries_Memory_Map gets information from the Hypervisor and
  347. * looks at the Main Store VPD to determine the absolute addresses
  348. * of the memory that has been assigned to our partition and builds
  349. * a table used to translate Linux's physical addresses to these
  350. * absolute addresses. Absolute addresses are needed when
  351. * communicating with the hypervisor (e.g. to build HPT entries)
  352. *
  353. * Returns the physical memory size
  354. */
  355. static unsigned long __init build_iSeries_Memory_Map(void)
  356. {
  357. u32 loadAreaFirstChunk, loadAreaLastChunk, loadAreaSize;
  358. u32 nextPhysChunk;
  359. u32 hptFirstChunk, hptLastChunk, hptSizeChunks, hptSizePages;
  360. u32 totalChunks,moreChunks;
  361. u32 currChunk, thisChunk, absChunk;
  362. u32 currDword;
  363. u32 chunkBit;
  364. u64 map;
  365. struct MemoryBlock mb[32];
  366. unsigned long numMemoryBlocks, curBlock;
  367. /* Chunk size on iSeries is 256K bytes */
  368. totalChunks = (u32)HvLpConfig_getMsChunks();
  369. mschunks_alloc(totalChunks);
  370. /*
  371. * Get absolute address of our load area
  372. * and map it to physical address 0
  373. * This guarantees that the loadarea ends up at physical 0
  374. * otherwise, it might not be returned by PLIC as the first
  375. * chunks
  376. */
  377. loadAreaFirstChunk = (u32)addr_to_chunk(itLpNaca.xLoadAreaAddr);
  378. loadAreaSize = itLpNaca.xLoadAreaChunks;
  379. /*
  380. * Only add the pages already mapped here.
  381. * Otherwise we might add the hpt pages
  382. * The rest of the pages of the load area
  383. * aren't in the HPT yet and can still
  384. * be assigned an arbitrary physical address
  385. */
  386. if ((loadAreaSize * 64) > HvPagesToMap)
  387. loadAreaSize = HvPagesToMap / 64;
  388. loadAreaLastChunk = loadAreaFirstChunk + loadAreaSize - 1;
  389. /*
  390. * TODO Do we need to do something if the HPT is in the 64MB load area?
  391. * This would be required if the itLpNaca.xLoadAreaChunks includes
  392. * the HPT size
  393. */
  394. printk("Mapping load area - physical addr = 0000000000000000\n"
  395. " absolute addr = %016lx\n",
  396. chunk_to_addr(loadAreaFirstChunk));
  397. printk("Load area size %dK\n", loadAreaSize * 256);
  398. for (nextPhysChunk = 0; nextPhysChunk < loadAreaSize; ++nextPhysChunk)
  399. mschunks_map.mapping[nextPhysChunk] =
  400. loadAreaFirstChunk + nextPhysChunk;
  401. /*
  402. * Get absolute address of our HPT and remember it so
  403. * we won't map it to any physical address
  404. */
  405. hptFirstChunk = (u32)addr_to_chunk(HvCallHpt_getHptAddress());
  406. hptSizePages = (u32)HvCallHpt_getHptPages();
  407. hptSizeChunks = hptSizePages >>
  408. (MSCHUNKS_CHUNK_SHIFT - HW_PAGE_SHIFT);
  409. hptLastChunk = hptFirstChunk + hptSizeChunks - 1;
  410. printk("HPT absolute addr = %016lx, size = %dK\n",
  411. chunk_to_addr(hptFirstChunk), hptSizeChunks * 256);
  412. /*
  413. * Determine if absolute memory has any
  414. * holes so that we can interpret the
  415. * access map we get back from the hypervisor
  416. * correctly.
  417. */
  418. numMemoryBlocks = iSeries_process_mainstore_vpd(mb, 32);
  419. /*
  420. * Process the main store access map from the hypervisor
  421. * to build up our physical -> absolute translation table
  422. */
  423. curBlock = 0;
  424. currChunk = 0;
  425. currDword = 0;
  426. moreChunks = totalChunks;
  427. while (moreChunks) {
  428. map = HvCallSm_get64BitsOfAccessMap(itLpNaca.xLpIndex,
  429. currDword);
  430. thisChunk = currChunk;
  431. while (map) {
  432. chunkBit = map >> 63;
  433. map <<= 1;
  434. if (chunkBit) {
  435. --moreChunks;
  436. while (thisChunk >= mb[curBlock].logicalEnd) {
  437. ++curBlock;
  438. if (curBlock >= numMemoryBlocks)
  439. panic("out of memory blocks");
  440. }
  441. if (thisChunk < mb[curBlock].logicalStart)
  442. panic("memory block error");
  443. absChunk = mb[curBlock].absStart +
  444. (thisChunk - mb[curBlock].logicalStart);
  445. if (((absChunk < hptFirstChunk) ||
  446. (absChunk > hptLastChunk)) &&
  447. ((absChunk < loadAreaFirstChunk) ||
  448. (absChunk > loadAreaLastChunk))) {
  449. mschunks_map.mapping[nextPhysChunk] =
  450. absChunk;
  451. ++nextPhysChunk;
  452. }
  453. }
  454. ++thisChunk;
  455. }
  456. ++currDword;
  457. currChunk += 64;
  458. }
  459. /*
  460. * main store size (in chunks) is
  461. * totalChunks - hptSizeChunks
  462. * which should be equal to
  463. * nextPhysChunk
  464. */
  465. return chunk_to_addr(nextPhysChunk);
  466. }
  467. /*
  468. * Document me.
  469. */
  470. static void __init iSeries_setup_arch(void)
  471. {
  472. if (get_lppaca()->shared_proc) {
  473. ppc_md.idle_loop = iseries_shared_idle;
  474. printk(KERN_INFO "Using shared processor idle loop\n");
  475. } else {
  476. ppc_md.idle_loop = iseries_dedicated_idle;
  477. printk(KERN_INFO "Using dedicated idle loop\n");
  478. }
  479. /* Setup the Lp Event Queue */
  480. setup_hvlpevent_queue();
  481. printk("Max logical processors = %d\n",
  482. itVpdAreas.xSlicMaxLogicalProcs);
  483. printk("Max physical processors = %d\n",
  484. itVpdAreas.xSlicMaxPhysicalProcs);
  485. }
  486. static void iSeries_show_cpuinfo(struct seq_file *m)
  487. {
  488. seq_printf(m, "machine\t\t: 64-bit iSeries Logical Partition\n");
  489. }
  490. static void __init iSeries_progress(char * st, unsigned short code)
  491. {
  492. printk("Progress: [%04x] - %s\n", (unsigned)code, st);
  493. mf_display_progress(code);
  494. }
  495. static void __init iSeries_fixup_klimit(void)
  496. {
  497. /*
  498. * Change klimit to take into account any ram disk
  499. * that may be included
  500. */
  501. if (naca.xRamDisk)
  502. klimit = KERNELBASE + (u64)naca.xRamDisk +
  503. (naca.xRamDiskSize * HW_PAGE_SIZE);
  504. else {
  505. /*
  506. * No ram disk was included - check and see if there
  507. * was an embedded system map. Change klimit to take
  508. * into account any embedded system map
  509. */
  510. if (embedded_sysmap_end)
  511. klimit = KERNELBASE + ((embedded_sysmap_end + 4095) &
  512. 0xfffffffffffff000);
  513. }
  514. }
  515. static int __init iSeries_src_init(void)
  516. {
  517. /* clear the progress line */
  518. ppc_md.progress(" ", 0xffff);
  519. return 0;
  520. }
  521. late_initcall(iSeries_src_init);
  522. static inline void process_iSeries_events(void)
  523. {
  524. asm volatile ("li 0,0x5555; sc" : : : "r0", "r3");
  525. }
  526. static void yield_shared_processor(void)
  527. {
  528. unsigned long tb;
  529. HvCall_setEnabledInterrupts(HvCall_MaskIPI |
  530. HvCall_MaskLpEvent |
  531. HvCall_MaskLpProd |
  532. HvCall_MaskTimeout);
  533. tb = get_tb();
  534. /* Compute future tb value when yield should expire */
  535. HvCall_yieldProcessor(HvCall_YieldTimed, tb+tb_ticks_per_jiffy);
  536. /*
  537. * The decrementer stops during the yield. Force a fake decrementer
  538. * here and let the timer_interrupt code sort out the actual time.
  539. */
  540. get_lppaca()->int_dword.fields.decr_int = 1;
  541. ppc64_runlatch_on();
  542. process_iSeries_events();
  543. }
  544. static void iseries_shared_idle(void)
  545. {
  546. while (1) {
  547. while (!need_resched() && !hvlpevent_is_pending()) {
  548. local_irq_disable();
  549. ppc64_runlatch_off();
  550. /* Recheck with irqs off */
  551. if (!need_resched() && !hvlpevent_is_pending())
  552. yield_shared_processor();
  553. HMT_medium();
  554. local_irq_enable();
  555. }
  556. ppc64_runlatch_on();
  557. if (hvlpevent_is_pending())
  558. process_iSeries_events();
  559. preempt_enable_no_resched();
  560. schedule();
  561. preempt_disable();
  562. }
  563. }
  564. static void iseries_dedicated_idle(void)
  565. {
  566. set_thread_flag(TIF_POLLING_NRFLAG);
  567. while (1) {
  568. if (!need_resched()) {
  569. while (!need_resched()) {
  570. ppc64_runlatch_off();
  571. HMT_low();
  572. if (hvlpevent_is_pending()) {
  573. HMT_medium();
  574. ppc64_runlatch_on();
  575. process_iSeries_events();
  576. }
  577. }
  578. HMT_medium();
  579. }
  580. ppc64_runlatch_on();
  581. preempt_enable_no_resched();
  582. schedule();
  583. preempt_disable();
  584. }
  585. }
  586. #ifndef CONFIG_PCI
  587. void __init iSeries_init_IRQ(void) { }
  588. #endif
  589. static int __init iseries_probe(int platform)
  590. {
  591. if (PLATFORM_ISERIES_LPAR != platform)
  592. return 0;
  593. ppc64_firmware_features |= FW_FEATURE_ISERIES;
  594. ppc64_firmware_features |= FW_FEATURE_LPAR;
  595. return 1;
  596. }
  597. struct machdep_calls __initdata iseries_md = {
  598. .setup_arch = iSeries_setup_arch,
  599. .show_cpuinfo = iSeries_show_cpuinfo,
  600. .init_IRQ = iSeries_init_IRQ,
  601. .get_irq = iSeries_get_irq,
  602. .init_early = iSeries_init_early,
  603. .pcibios_fixup = iSeries_pci_final_fixup,
  604. .restart = mf_reboot,
  605. .power_off = mf_power_off,
  606. .halt = mf_power_off,
  607. .get_boot_time = iSeries_get_boot_time,
  608. .set_rtc_time = iSeries_set_rtc_time,
  609. .get_rtc_time = iSeries_get_rtc_time,
  610. .calibrate_decr = generic_calibrate_decr,
  611. .progress = iSeries_progress,
  612. .probe = iseries_probe,
  613. /* XXX Implement enable_pmcs for iSeries */
  614. };
  615. struct blob {
  616. unsigned char data[PAGE_SIZE];
  617. unsigned long next;
  618. };
  619. struct iseries_flat_dt {
  620. struct boot_param_header header;
  621. u64 reserve_map[2];
  622. struct blob dt;
  623. struct blob strings;
  624. };
  625. struct iseries_flat_dt iseries_dt;
  626. void dt_init(struct iseries_flat_dt *dt)
  627. {
  628. dt->header.off_mem_rsvmap =
  629. offsetof(struct iseries_flat_dt, reserve_map);
  630. dt->header.off_dt_struct = offsetof(struct iseries_flat_dt, dt);
  631. dt->header.off_dt_strings = offsetof(struct iseries_flat_dt, strings);
  632. dt->header.totalsize = sizeof(struct iseries_flat_dt);
  633. dt->header.dt_strings_size = sizeof(struct blob);
  634. /* There is no notion of hardware cpu id on iSeries */
  635. dt->header.boot_cpuid_phys = smp_processor_id();
  636. dt->dt.next = (unsigned long)&dt->dt.data;
  637. dt->strings.next = (unsigned long)&dt->strings.data;
  638. dt->header.magic = OF_DT_HEADER;
  639. dt->header.version = 0x10;
  640. dt->header.last_comp_version = 0x10;
  641. dt->reserve_map[0] = 0;
  642. dt->reserve_map[1] = 0;
  643. }
  644. void dt_check_blob(struct blob *b)
  645. {
  646. if (b->next >= (unsigned long)&b->next) {
  647. DBG("Ran out of space in flat device tree blob!\n");
  648. BUG();
  649. }
  650. }
  651. void dt_push_u32(struct iseries_flat_dt *dt, u32 value)
  652. {
  653. *((u32*)dt->dt.next) = value;
  654. dt->dt.next += sizeof(u32);
  655. dt_check_blob(&dt->dt);
  656. }
  657. void dt_push_u64(struct iseries_flat_dt *dt, u64 value)
  658. {
  659. *((u64*)dt->dt.next) = value;
  660. dt->dt.next += sizeof(u64);
  661. dt_check_blob(&dt->dt);
  662. }
  663. unsigned long dt_push_bytes(struct blob *blob, char *data, int len)
  664. {
  665. unsigned long start = blob->next - (unsigned long)blob->data;
  666. memcpy((char *)blob->next, data, len);
  667. blob->next = _ALIGN(blob->next + len, 4);
  668. dt_check_blob(blob);
  669. return start;
  670. }
  671. void dt_start_node(struct iseries_flat_dt *dt, char *name)
  672. {
  673. dt_push_u32(dt, OF_DT_BEGIN_NODE);
  674. dt_push_bytes(&dt->dt, name, strlen(name) + 1);
  675. }
  676. #define dt_end_node(dt) dt_push_u32(dt, OF_DT_END_NODE)
  677. void dt_prop(struct iseries_flat_dt *dt, char *name, char *data, int len)
  678. {
  679. unsigned long offset;
  680. dt_push_u32(dt, OF_DT_PROP);
  681. /* Length of the data */
  682. dt_push_u32(dt, len);
  683. /* Put the property name in the string blob. */
  684. offset = dt_push_bytes(&dt->strings, name, strlen(name) + 1);
  685. /* The offset of the properties name in the string blob. */
  686. dt_push_u32(dt, (u32)offset);
  687. /* The actual data. */
  688. dt_push_bytes(&dt->dt, data, len);
  689. }
  690. void dt_prop_str(struct iseries_flat_dt *dt, char *name, char *data)
  691. {
  692. dt_prop(dt, name, data, strlen(data) + 1); /* + 1 for NULL */
  693. }
  694. void dt_prop_u32(struct iseries_flat_dt *dt, char *name, u32 data)
  695. {
  696. dt_prop(dt, name, (char *)&data, sizeof(u32));
  697. }
  698. void dt_prop_u64(struct iseries_flat_dt *dt, char *name, u64 data)
  699. {
  700. dt_prop(dt, name, (char *)&data, sizeof(u64));
  701. }
  702. void dt_prop_u64_list(struct iseries_flat_dt *dt, char *name, u64 *data, int n)
  703. {
  704. dt_prop(dt, name, (char *)data, sizeof(u64) * n);
  705. }
  706. void dt_prop_u32_list(struct iseries_flat_dt *dt, char *name, u32 *data, int n)
  707. {
  708. dt_prop(dt, name, (char *)data, sizeof(u32) * n);
  709. }
  710. void dt_prop_empty(struct iseries_flat_dt *dt, char *name)
  711. {
  712. dt_prop(dt, name, NULL, 0);
  713. }
  714. void dt_cpus(struct iseries_flat_dt *dt)
  715. {
  716. unsigned char buf[32];
  717. unsigned char *p;
  718. unsigned int i, index;
  719. struct IoHriProcessorVpd *d;
  720. u32 pft_size[2];
  721. /* yuck */
  722. snprintf(buf, 32, "PowerPC,%s", cur_cpu_spec->cpu_name);
  723. p = strchr(buf, ' ');
  724. if (!p) p = buf + strlen(buf);
  725. dt_start_node(dt, "cpus");
  726. dt_prop_u32(dt, "#address-cells", 1);
  727. dt_prop_u32(dt, "#size-cells", 0);
  728. pft_size[0] = 0; /* NUMA CEC cookie, 0 for non NUMA */
  729. pft_size[1] = __ilog2(HvCallHpt_getHptPages() * HW_PAGE_SIZE);
  730. for (i = 0; i < NR_CPUS; i++) {
  731. if (lppaca[i].dyn_proc_status >= 2)
  732. continue;
  733. snprintf(p, 32 - (p - buf), "@%d", i);
  734. dt_start_node(dt, buf);
  735. dt_prop_str(dt, "device_type", "cpu");
  736. index = lppaca[i].dyn_hv_phys_proc_index;
  737. d = &xIoHriProcessorVpd[index];
  738. dt_prop_u32(dt, "i-cache-size", d->xInstCacheSize * 1024);
  739. dt_prop_u32(dt, "i-cache-line-size", d->xInstCacheOperandSize);
  740. dt_prop_u32(dt, "d-cache-size", d->xDataL1CacheSizeKB * 1024);
  741. dt_prop_u32(dt, "d-cache-line-size", d->xDataCacheOperandSize);
  742. /* magic conversions to Hz copied from old code */
  743. dt_prop_u32(dt, "clock-frequency",
  744. ((1UL << 34) * 1000000) / d->xProcFreq);
  745. dt_prop_u32(dt, "timebase-frequency",
  746. ((1UL << 32) * 1000000) / d->xTimeBaseFreq);
  747. dt_prop_u32(dt, "reg", i);
  748. dt_prop_u32_list(dt, "ibm,pft-size", pft_size, 2);
  749. dt_end_node(dt);
  750. }
  751. dt_end_node(dt);
  752. }
  753. void dt_model(struct iseries_flat_dt *dt)
  754. {
  755. char buf[16] = "IBM,";
  756. /* "IBM," + mfgId[2:3] + systemSerial[1:5] */
  757. strne2a(buf + 4, xItExtVpdPanel.mfgID + 2, 2);
  758. strne2a(buf + 6, xItExtVpdPanel.systemSerial + 1, 5);
  759. buf[11] = '\0';
  760. dt_prop_str(dt, "system-id", buf);
  761. /* "IBM," + machineType[0:4] */
  762. strne2a(buf + 4, xItExtVpdPanel.machineType, 4);
  763. buf[8] = '\0';
  764. dt_prop_str(dt, "model", buf);
  765. dt_prop_str(dt, "compatible", "IBM,iSeries");
  766. }
  767. void build_flat_dt(struct iseries_flat_dt *dt, unsigned long phys_mem_size)
  768. {
  769. u64 tmp[2];
  770. dt_init(dt);
  771. dt_start_node(dt, "");
  772. dt_prop_u32(dt, "#address-cells", 2);
  773. dt_prop_u32(dt, "#size-cells", 2);
  774. dt_model(dt);
  775. /* /memory */
  776. dt_start_node(dt, "memory@0");
  777. dt_prop_str(dt, "name", "memory");
  778. dt_prop_str(dt, "device_type", "memory");
  779. tmp[0] = 0;
  780. tmp[1] = phys_mem_size;
  781. dt_prop_u64_list(dt, "reg", tmp, 2);
  782. dt_end_node(dt);
  783. /* /chosen */
  784. dt_start_node(dt, "chosen");
  785. dt_prop_u32(dt, "linux,platform", PLATFORM_ISERIES_LPAR);
  786. dt_prop_str(dt, "bootargs", cmd_line);
  787. if (cmd_mem_limit)
  788. dt_prop_u64(dt, "linux,memory-limit", cmd_mem_limit);
  789. dt_end_node(dt);
  790. dt_cpus(dt);
  791. dt_end_node(dt);
  792. dt_push_u32(dt, OF_DT_END);
  793. }
  794. void * __init iSeries_early_setup(void)
  795. {
  796. unsigned long phys_mem_size;
  797. iSeries_fixup_klimit();
  798. /*
  799. * Initialize the table which translate Linux physical addresses to
  800. * AS/400 absolute addresses
  801. */
  802. phys_mem_size = build_iSeries_Memory_Map();
  803. iSeries_get_cmdline();
  804. /* Save unparsed command line copy for /proc/cmdline */
  805. strlcpy(saved_command_line, cmd_line, COMMAND_LINE_SIZE);
  806. /* Parse early parameters, in particular mem=x */
  807. parse_early_param();
  808. build_flat_dt(&iseries_dt, phys_mem_size);
  809. return (void *) __pa(&iseries_dt);
  810. }
  811. /*
  812. * On iSeries we just parse the mem=X option from the command line.
  813. * On pSeries it's a bit more complicated, see prom_init_mem()
  814. */
  815. static int __init early_parsemem(char *p)
  816. {
  817. if (p)
  818. cmd_mem_limit = ALIGN(memparse(p, &p), PAGE_SIZE);
  819. return 0;
  820. }
  821. early_param("mem", early_parsemem);
  822. static void hvputc(char c)
  823. {
  824. if (c == '\n')
  825. hvputc('\r');
  826. HvCall_writeLogBuffer(&c, 1);
  827. }
  828. void __init udbg_init_iseries(void)
  829. {
  830. udbg_putc = hvputc;
  831. }