setup.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725
  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/hv_lp_event.h>
  51. #include <asm/iseries/lpar_map.h>
  52. #include <asm/udbg.h>
  53. #include <asm/irq.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. extern int rd_size; /* Defined in drivers/block/rd.c */
  77. extern unsigned long iSeries_recal_tb;
  78. extern unsigned long iSeries_recal_titan;
  79. struct MemoryBlock {
  80. unsigned long absStart;
  81. unsigned long absEnd;
  82. unsigned long logicalStart;
  83. unsigned long logicalEnd;
  84. };
  85. /*
  86. * Process the main store vpd to determine where the holes in memory are
  87. * and return the number of physical blocks and fill in the array of
  88. * block data.
  89. */
  90. static unsigned long iSeries_process_Condor_mainstore_vpd(
  91. struct MemoryBlock *mb_array, unsigned long max_entries)
  92. {
  93. unsigned long holeFirstChunk, holeSizeChunks;
  94. unsigned long numMemoryBlocks = 1;
  95. struct IoHriMainStoreSegment4 *msVpd =
  96. (struct IoHriMainStoreSegment4 *)xMsVpd;
  97. unsigned long holeStart = msVpd->nonInterleavedBlocksStartAdr;
  98. unsigned long holeEnd = msVpd->nonInterleavedBlocksEndAdr;
  99. unsigned long holeSize = holeEnd - holeStart;
  100. printk("Mainstore_VPD: Condor\n");
  101. /*
  102. * Determine if absolute memory has any
  103. * holes so that we can interpret the
  104. * access map we get back from the hypervisor
  105. * correctly.
  106. */
  107. mb_array[0].logicalStart = 0;
  108. mb_array[0].logicalEnd = 0x100000000;
  109. mb_array[0].absStart = 0;
  110. mb_array[0].absEnd = 0x100000000;
  111. if (holeSize) {
  112. numMemoryBlocks = 2;
  113. holeStart = holeStart & 0x000fffffffffffff;
  114. holeStart = addr_to_chunk(holeStart);
  115. holeFirstChunk = holeStart;
  116. holeSize = addr_to_chunk(holeSize);
  117. holeSizeChunks = holeSize;
  118. printk( "Main store hole: start chunk = %0lx, size = %0lx chunks\n",
  119. holeFirstChunk, holeSizeChunks );
  120. mb_array[0].logicalEnd = holeFirstChunk;
  121. mb_array[0].absEnd = holeFirstChunk;
  122. mb_array[1].logicalStart = holeFirstChunk;
  123. mb_array[1].logicalEnd = 0x100000000 - holeSizeChunks;
  124. mb_array[1].absStart = holeFirstChunk + holeSizeChunks;
  125. mb_array[1].absEnd = 0x100000000;
  126. }
  127. return numMemoryBlocks;
  128. }
  129. #define MaxSegmentAreas 32
  130. #define MaxSegmentAdrRangeBlocks 128
  131. #define MaxAreaRangeBlocks 4
  132. static unsigned long iSeries_process_Regatta_mainstore_vpd(
  133. struct MemoryBlock *mb_array, unsigned long max_entries)
  134. {
  135. struct IoHriMainStoreSegment5 *msVpdP =
  136. (struct IoHriMainStoreSegment5 *)xMsVpd;
  137. unsigned long numSegmentBlocks = 0;
  138. u32 existsBits = msVpdP->msAreaExists;
  139. unsigned long area_num;
  140. printk("Mainstore_VPD: Regatta\n");
  141. for (area_num = 0; area_num < MaxSegmentAreas; ++area_num ) {
  142. unsigned long numAreaBlocks;
  143. struct IoHriMainStoreArea4 *currentArea;
  144. if (existsBits & 0x80000000) {
  145. unsigned long block_num;
  146. currentArea = &msVpdP->msAreaArray[area_num];
  147. numAreaBlocks = currentArea->numAdrRangeBlocks;
  148. printk("ms_vpd: processing area %2ld blocks=%ld",
  149. area_num, numAreaBlocks);
  150. for (block_num = 0; block_num < numAreaBlocks;
  151. ++block_num ) {
  152. /* Process an address range block */
  153. struct MemoryBlock tempBlock;
  154. unsigned long i;
  155. tempBlock.absStart =
  156. (unsigned long)currentArea->xAdrRangeBlock[block_num].blockStart;
  157. tempBlock.absEnd =
  158. (unsigned long)currentArea->xAdrRangeBlock[block_num].blockEnd;
  159. tempBlock.logicalStart = 0;
  160. tempBlock.logicalEnd = 0;
  161. printk("\n block %ld absStart=%016lx absEnd=%016lx",
  162. block_num, tempBlock.absStart,
  163. tempBlock.absEnd);
  164. for (i = 0; i < numSegmentBlocks; ++i) {
  165. if (mb_array[i].absStart ==
  166. tempBlock.absStart)
  167. break;
  168. }
  169. if (i == numSegmentBlocks) {
  170. if (numSegmentBlocks == max_entries)
  171. panic("iSeries_process_mainstore_vpd: too many memory blocks");
  172. mb_array[numSegmentBlocks] = tempBlock;
  173. ++numSegmentBlocks;
  174. } else
  175. printk(" (duplicate)");
  176. }
  177. printk("\n");
  178. }
  179. existsBits <<= 1;
  180. }
  181. /* Now sort the blocks found into ascending sequence */
  182. if (numSegmentBlocks > 1) {
  183. unsigned long m, n;
  184. for (m = 0; m < numSegmentBlocks - 1; ++m) {
  185. for (n = numSegmentBlocks - 1; m < n; --n) {
  186. if (mb_array[n].absStart <
  187. mb_array[n-1].absStart) {
  188. struct MemoryBlock tempBlock;
  189. tempBlock = mb_array[n];
  190. mb_array[n] = mb_array[n-1];
  191. mb_array[n-1] = tempBlock;
  192. }
  193. }
  194. }
  195. }
  196. /*
  197. * Assign "logical" addresses to each block. These
  198. * addresses correspond to the hypervisor "bitmap" space.
  199. * Convert all addresses into units of 256K chunks.
  200. */
  201. {
  202. unsigned long i, nextBitmapAddress;
  203. printk("ms_vpd: %ld sorted memory blocks\n", numSegmentBlocks);
  204. nextBitmapAddress = 0;
  205. for (i = 0; i < numSegmentBlocks; ++i) {
  206. unsigned long length = mb_array[i].absEnd -
  207. mb_array[i].absStart;
  208. mb_array[i].logicalStart = nextBitmapAddress;
  209. mb_array[i].logicalEnd = nextBitmapAddress + length;
  210. nextBitmapAddress += length;
  211. printk(" Bitmap range: %016lx - %016lx\n"
  212. " Absolute range: %016lx - %016lx\n",
  213. mb_array[i].logicalStart,
  214. mb_array[i].logicalEnd,
  215. mb_array[i].absStart, mb_array[i].absEnd);
  216. mb_array[i].absStart = addr_to_chunk(mb_array[i].absStart &
  217. 0x000fffffffffffff);
  218. mb_array[i].absEnd = addr_to_chunk(mb_array[i].absEnd &
  219. 0x000fffffffffffff);
  220. mb_array[i].logicalStart =
  221. addr_to_chunk(mb_array[i].logicalStart);
  222. mb_array[i].logicalEnd = addr_to_chunk(mb_array[i].logicalEnd);
  223. }
  224. }
  225. return numSegmentBlocks;
  226. }
  227. static unsigned long iSeries_process_mainstore_vpd(struct MemoryBlock *mb_array,
  228. unsigned long max_entries)
  229. {
  230. unsigned long i;
  231. unsigned long mem_blocks = 0;
  232. if (cpu_has_feature(CPU_FTR_SLB))
  233. mem_blocks = iSeries_process_Regatta_mainstore_vpd(mb_array,
  234. max_entries);
  235. else
  236. mem_blocks = iSeries_process_Condor_mainstore_vpd(mb_array,
  237. max_entries);
  238. printk("Mainstore_VPD: numMemoryBlocks = %ld \n", mem_blocks);
  239. for (i = 0; i < mem_blocks; ++i) {
  240. printk("Mainstore_VPD: block %3ld logical chunks %016lx - %016lx\n"
  241. " abs chunks %016lx - %016lx\n",
  242. i, mb_array[i].logicalStart, mb_array[i].logicalEnd,
  243. mb_array[i].absStart, mb_array[i].absEnd);
  244. }
  245. return mem_blocks;
  246. }
  247. static void __init iSeries_get_cmdline(void)
  248. {
  249. char *p, *q;
  250. /* copy the command line parameter from the primary VSP */
  251. HvCallEvent_dmaToSp(cmd_line, 2 * 64* 1024, 256,
  252. HvLpDma_Direction_RemoteToLocal);
  253. p = cmd_line;
  254. q = cmd_line + 255;
  255. while(p < q) {
  256. if (!*p || *p == '\n')
  257. break;
  258. ++p;
  259. }
  260. *p = 0;
  261. }
  262. static void __init iSeries_init_early(void)
  263. {
  264. DBG(" -> iSeries_init_early()\n");
  265. ppc64_interrupt_controller = IC_ISERIES;
  266. #if defined(CONFIG_BLK_DEV_INITRD)
  267. /*
  268. * If the init RAM disk has been configured and there is
  269. * a non-zero starting address for it, set it up
  270. */
  271. if (naca.xRamDisk) {
  272. initrd_start = (unsigned long)__va(naca.xRamDisk);
  273. initrd_end = initrd_start + naca.xRamDiskSize * HW_PAGE_SIZE;
  274. initrd_below_start_ok = 1; // ramdisk in kernel space
  275. ROOT_DEV = Root_RAM0;
  276. if (((rd_size * 1024) / HW_PAGE_SIZE) < naca.xRamDiskSize)
  277. rd_size = (naca.xRamDiskSize * HW_PAGE_SIZE) / 1024;
  278. } else
  279. #endif /* CONFIG_BLK_DEV_INITRD */
  280. {
  281. /* ROOT_DEV = MKDEV(VIODASD_MAJOR, 1); */
  282. }
  283. iSeries_recal_tb = get_tb();
  284. iSeries_recal_titan = HvCallXm_loadTod();
  285. /*
  286. * Initialize the hash table management pointers
  287. */
  288. hpte_init_iSeries();
  289. /*
  290. * Initialize the DMA/TCE management
  291. */
  292. iommu_init_early_iSeries();
  293. /* Initialize machine-dependency vectors */
  294. #ifdef CONFIG_SMP
  295. smp_init_iSeries();
  296. #endif
  297. /* Associate Lp Event Queue 0 with processor 0 */
  298. HvCallEvent_setLpEventQueueInterruptProc(0, 0);
  299. mf_init();
  300. /* If we were passed an initrd, set the ROOT_DEV properly if the values
  301. * look sensible. If not, clear initrd reference.
  302. */
  303. #ifdef CONFIG_BLK_DEV_INITRD
  304. if (initrd_start >= KERNELBASE && initrd_end >= KERNELBASE &&
  305. initrd_end > initrd_start)
  306. ROOT_DEV = Root_RAM0;
  307. else
  308. initrd_start = initrd_end = 0;
  309. #endif /* CONFIG_BLK_DEV_INITRD */
  310. DBG(" <- iSeries_init_early()\n");
  311. }
  312. struct mschunks_map mschunks_map = {
  313. /* XXX We don't use these, but Piranha might need them. */
  314. .chunk_size = MSCHUNKS_CHUNK_SIZE,
  315. .chunk_shift = MSCHUNKS_CHUNK_SHIFT,
  316. .chunk_mask = MSCHUNKS_OFFSET_MASK,
  317. };
  318. EXPORT_SYMBOL(mschunks_map);
  319. void mschunks_alloc(unsigned long num_chunks)
  320. {
  321. klimit = _ALIGN(klimit, sizeof(u32));
  322. mschunks_map.mapping = (u32 *)klimit;
  323. klimit += num_chunks * sizeof(u32);
  324. mschunks_map.num_chunks = num_chunks;
  325. }
  326. /*
  327. * The iSeries may have very large memories ( > 128 GB ) and a partition
  328. * may get memory in "chunks" that may be anywhere in the 2**52 real
  329. * address space. The chunks are 256K in size. To map this to the
  330. * memory model Linux expects, the AS/400 specific code builds a
  331. * translation table to translate what Linux thinks are "physical"
  332. * addresses to the actual real addresses. This allows us to make
  333. * it appear to Linux that we have contiguous memory starting at
  334. * physical address zero while in fact this could be far from the truth.
  335. * To avoid confusion, I'll let the words physical and/or real address
  336. * apply to the Linux addresses while I'll use "absolute address" to
  337. * refer to the actual hardware real address.
  338. *
  339. * build_iSeries_Memory_Map gets information from the Hypervisor and
  340. * looks at the Main Store VPD to determine the absolute addresses
  341. * of the memory that has been assigned to our partition and builds
  342. * a table used to translate Linux's physical addresses to these
  343. * absolute addresses. Absolute addresses are needed when
  344. * communicating with the hypervisor (e.g. to build HPT entries)
  345. *
  346. * Returns the physical memory size
  347. */
  348. static unsigned long __init build_iSeries_Memory_Map(void)
  349. {
  350. u32 loadAreaFirstChunk, loadAreaLastChunk, loadAreaSize;
  351. u32 nextPhysChunk;
  352. u32 hptFirstChunk, hptLastChunk, hptSizeChunks, hptSizePages;
  353. u32 totalChunks,moreChunks;
  354. u32 currChunk, thisChunk, absChunk;
  355. u32 currDword;
  356. u32 chunkBit;
  357. u64 map;
  358. struct MemoryBlock mb[32];
  359. unsigned long numMemoryBlocks, curBlock;
  360. /* Chunk size on iSeries is 256K bytes */
  361. totalChunks = (u32)HvLpConfig_getMsChunks();
  362. mschunks_alloc(totalChunks);
  363. /*
  364. * Get absolute address of our load area
  365. * and map it to physical address 0
  366. * This guarantees that the loadarea ends up at physical 0
  367. * otherwise, it might not be returned by PLIC as the first
  368. * chunks
  369. */
  370. loadAreaFirstChunk = (u32)addr_to_chunk(itLpNaca.xLoadAreaAddr);
  371. loadAreaSize = itLpNaca.xLoadAreaChunks;
  372. /*
  373. * Only add the pages already mapped here.
  374. * Otherwise we might add the hpt pages
  375. * The rest of the pages of the load area
  376. * aren't in the HPT yet and can still
  377. * be assigned an arbitrary physical address
  378. */
  379. if ((loadAreaSize * 64) > HvPagesToMap)
  380. loadAreaSize = HvPagesToMap / 64;
  381. loadAreaLastChunk = loadAreaFirstChunk + loadAreaSize - 1;
  382. /*
  383. * TODO Do we need to do something if the HPT is in the 64MB load area?
  384. * This would be required if the itLpNaca.xLoadAreaChunks includes
  385. * the HPT size
  386. */
  387. printk("Mapping load area - physical addr = 0000000000000000\n"
  388. " absolute addr = %016lx\n",
  389. chunk_to_addr(loadAreaFirstChunk));
  390. printk("Load area size %dK\n", loadAreaSize * 256);
  391. for (nextPhysChunk = 0; nextPhysChunk < loadAreaSize; ++nextPhysChunk)
  392. mschunks_map.mapping[nextPhysChunk] =
  393. loadAreaFirstChunk + nextPhysChunk;
  394. /*
  395. * Get absolute address of our HPT and remember it so
  396. * we won't map it to any physical address
  397. */
  398. hptFirstChunk = (u32)addr_to_chunk(HvCallHpt_getHptAddress());
  399. hptSizePages = (u32)HvCallHpt_getHptPages();
  400. hptSizeChunks = hptSizePages >>
  401. (MSCHUNKS_CHUNK_SHIFT - HW_PAGE_SHIFT);
  402. hptLastChunk = hptFirstChunk + hptSizeChunks - 1;
  403. printk("HPT absolute addr = %016lx, size = %dK\n",
  404. chunk_to_addr(hptFirstChunk), hptSizeChunks * 256);
  405. /*
  406. * Determine if absolute memory has any
  407. * holes so that we can interpret the
  408. * access map we get back from the hypervisor
  409. * correctly.
  410. */
  411. numMemoryBlocks = iSeries_process_mainstore_vpd(mb, 32);
  412. /*
  413. * Process the main store access map from the hypervisor
  414. * to build up our physical -> absolute translation table
  415. */
  416. curBlock = 0;
  417. currChunk = 0;
  418. currDword = 0;
  419. moreChunks = totalChunks;
  420. while (moreChunks) {
  421. map = HvCallSm_get64BitsOfAccessMap(itLpNaca.xLpIndex,
  422. currDword);
  423. thisChunk = currChunk;
  424. while (map) {
  425. chunkBit = map >> 63;
  426. map <<= 1;
  427. if (chunkBit) {
  428. --moreChunks;
  429. while (thisChunk >= mb[curBlock].logicalEnd) {
  430. ++curBlock;
  431. if (curBlock >= numMemoryBlocks)
  432. panic("out of memory blocks");
  433. }
  434. if (thisChunk < mb[curBlock].logicalStart)
  435. panic("memory block error");
  436. absChunk = mb[curBlock].absStart +
  437. (thisChunk - mb[curBlock].logicalStart);
  438. if (((absChunk < hptFirstChunk) ||
  439. (absChunk > hptLastChunk)) &&
  440. ((absChunk < loadAreaFirstChunk) ||
  441. (absChunk > loadAreaLastChunk))) {
  442. mschunks_map.mapping[nextPhysChunk] =
  443. absChunk;
  444. ++nextPhysChunk;
  445. }
  446. }
  447. ++thisChunk;
  448. }
  449. ++currDword;
  450. currChunk += 64;
  451. }
  452. /*
  453. * main store size (in chunks) is
  454. * totalChunks - hptSizeChunks
  455. * which should be equal to
  456. * nextPhysChunk
  457. */
  458. return chunk_to_addr(nextPhysChunk);
  459. }
  460. /*
  461. * Document me.
  462. */
  463. static void __init iSeries_setup_arch(void)
  464. {
  465. if (get_lppaca()->shared_proc) {
  466. ppc_md.idle_loop = iseries_shared_idle;
  467. printk(KERN_DEBUG "Using shared processor idle loop\n");
  468. } else {
  469. ppc_md.idle_loop = iseries_dedicated_idle;
  470. printk(KERN_DEBUG "Using dedicated idle loop\n");
  471. }
  472. /* Setup the Lp Event Queue */
  473. setup_hvlpevent_queue();
  474. printk("Max logical processors = %d\n",
  475. itVpdAreas.xSlicMaxLogicalProcs);
  476. printk("Max physical processors = %d\n",
  477. itVpdAreas.xSlicMaxPhysicalProcs);
  478. }
  479. static void iSeries_show_cpuinfo(struct seq_file *m)
  480. {
  481. seq_printf(m, "machine\t\t: 64-bit iSeries Logical Partition\n");
  482. }
  483. static void __init iSeries_progress(char * st, unsigned short code)
  484. {
  485. printk("Progress: [%04x] - %s\n", (unsigned)code, st);
  486. mf_display_progress(code);
  487. }
  488. static void __init iSeries_fixup_klimit(void)
  489. {
  490. /*
  491. * Change klimit to take into account any ram disk
  492. * that may be included
  493. */
  494. if (naca.xRamDisk)
  495. klimit = KERNELBASE + (u64)naca.xRamDisk +
  496. (naca.xRamDiskSize * HW_PAGE_SIZE);
  497. }
  498. static int __init iSeries_src_init(void)
  499. {
  500. /* clear the progress line */
  501. ppc_md.progress(" ", 0xffff);
  502. return 0;
  503. }
  504. late_initcall(iSeries_src_init);
  505. static inline void process_iSeries_events(void)
  506. {
  507. asm volatile ("li 0,0x5555; sc" : : : "r0", "r3");
  508. }
  509. static void yield_shared_processor(void)
  510. {
  511. unsigned long tb;
  512. HvCall_setEnabledInterrupts(HvCall_MaskIPI |
  513. HvCall_MaskLpEvent |
  514. HvCall_MaskLpProd |
  515. HvCall_MaskTimeout);
  516. tb = get_tb();
  517. /* Compute future tb value when yield should expire */
  518. HvCall_yieldProcessor(HvCall_YieldTimed, tb+tb_ticks_per_jiffy);
  519. /*
  520. * The decrementer stops during the yield. Force a fake decrementer
  521. * here and let the timer_interrupt code sort out the actual time.
  522. */
  523. get_lppaca()->int_dword.fields.decr_int = 1;
  524. ppc64_runlatch_on();
  525. process_iSeries_events();
  526. }
  527. static void iseries_shared_idle(void)
  528. {
  529. while (1) {
  530. while (!need_resched() && !hvlpevent_is_pending()) {
  531. local_irq_disable();
  532. ppc64_runlatch_off();
  533. /* Recheck with irqs off */
  534. if (!need_resched() && !hvlpevent_is_pending())
  535. yield_shared_processor();
  536. HMT_medium();
  537. local_irq_enable();
  538. }
  539. ppc64_runlatch_on();
  540. if (hvlpevent_is_pending())
  541. process_iSeries_events();
  542. preempt_enable_no_resched();
  543. schedule();
  544. preempt_disable();
  545. }
  546. }
  547. static void iseries_dedicated_idle(void)
  548. {
  549. set_thread_flag(TIF_POLLING_NRFLAG);
  550. while (1) {
  551. if (!need_resched()) {
  552. while (!need_resched()) {
  553. ppc64_runlatch_off();
  554. HMT_low();
  555. if (hvlpevent_is_pending()) {
  556. HMT_medium();
  557. ppc64_runlatch_on();
  558. process_iSeries_events();
  559. }
  560. }
  561. HMT_medium();
  562. }
  563. ppc64_runlatch_on();
  564. preempt_enable_no_resched();
  565. schedule();
  566. preempt_disable();
  567. }
  568. }
  569. #ifndef CONFIG_PCI
  570. void __init iSeries_init_IRQ(void) { }
  571. #endif
  572. static int __init iseries_probe(void)
  573. {
  574. unsigned long root = of_get_flat_dt_root();
  575. if (!of_flat_dt_is_compatible(root, "IBM,iSeries"))
  576. return 0;
  577. powerpc_firmware_features |= FW_FEATURE_ISERIES;
  578. powerpc_firmware_features |= FW_FEATURE_LPAR;
  579. /*
  580. * The Hypervisor only allows us up to 256 interrupt
  581. * sources (the irq number is passed in a u8).
  582. */
  583. virt_irq_max = 255;
  584. return 1;
  585. }
  586. define_machine(iseries) {
  587. .name = "iSeries",
  588. .setup_arch = iSeries_setup_arch,
  589. .show_cpuinfo = iSeries_show_cpuinfo,
  590. .init_IRQ = iSeries_init_IRQ,
  591. .get_irq = iSeries_get_irq,
  592. .init_early = iSeries_init_early,
  593. .pcibios_fixup = iSeries_pci_final_fixup,
  594. .restart = mf_reboot,
  595. .power_off = mf_power_off,
  596. .halt = mf_power_off,
  597. .get_boot_time = iSeries_get_boot_time,
  598. .set_rtc_time = iSeries_set_rtc_time,
  599. .get_rtc_time = iSeries_get_rtc_time,
  600. .calibrate_decr = generic_calibrate_decr,
  601. .progress = iSeries_progress,
  602. .probe = iseries_probe,
  603. /* XXX Implement enable_pmcs for iSeries */
  604. };
  605. void * __init iSeries_early_setup(void)
  606. {
  607. unsigned long phys_mem_size;
  608. iSeries_fixup_klimit();
  609. /*
  610. * Initialize the table which translate Linux physical addresses to
  611. * AS/400 absolute addresses
  612. */
  613. phys_mem_size = build_iSeries_Memory_Map();
  614. iSeries_get_cmdline();
  615. return (void *) __pa(build_flat_dt(phys_mem_size));
  616. }
  617. static void hvputc(char c)
  618. {
  619. if (c == '\n')
  620. hvputc('\r');
  621. HvCall_writeLogBuffer(&c, 1);
  622. }
  623. void __init udbg_init_iseries(void)
  624. {
  625. udbg_putc = hvputc;
  626. }