setup.c 26 KB

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