setup.c 20 KB

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