setup.c 25 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006
  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 "naca.h"
  54. #include "setup.h"
  55. #include "irq.h"
  56. #include "vpd_areas.h"
  57. #include "processor_vpd.h"
  58. #include "main_store.h"
  59. #include "call_sm.h"
  60. #include "call_hpt.h"
  61. #ifdef DEBUG
  62. #define DBG(fmt...) udbg_printf(fmt)
  63. #else
  64. #define DBG(fmt...)
  65. #endif
  66. /* Function Prototypes */
  67. static unsigned long build_iSeries_Memory_Map(void);
  68. static void iseries_shared_idle(void);
  69. static void iseries_dedicated_idle(void);
  70. #ifdef CONFIG_PCI
  71. extern void iSeries_pci_final_fixup(void);
  72. #else
  73. static void iSeries_pci_final_fixup(void) { }
  74. #endif
  75. /* Global Variables */
  76. int piranha_simulator;
  77. extern int rd_size; /* Defined in drivers/block/rd.c */
  78. extern unsigned long embedded_sysmap_start;
  79. extern unsigned long embedded_sysmap_end;
  80. extern unsigned long iSeries_recal_tb;
  81. extern unsigned long iSeries_recal_titan;
  82. static int mf_initialized;
  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. mf_initialized = 1;
  308. mb();
  309. /* If we were passed an initrd, set the ROOT_DEV properly if the values
  310. * look sensible. If not, clear initrd reference.
  311. */
  312. #ifdef CONFIG_BLK_DEV_INITRD
  313. if (initrd_start >= KERNELBASE && initrd_end >= KERNELBASE &&
  314. initrd_end > initrd_start)
  315. ROOT_DEV = Root_RAM0;
  316. else
  317. initrd_start = initrd_end = 0;
  318. #endif /* CONFIG_BLK_DEV_INITRD */
  319. DBG(" <- iSeries_init_early()\n");
  320. }
  321. struct mschunks_map mschunks_map = {
  322. /* XXX We don't use these, but Piranha might need them. */
  323. .chunk_size = MSCHUNKS_CHUNK_SIZE,
  324. .chunk_shift = MSCHUNKS_CHUNK_SHIFT,
  325. .chunk_mask = MSCHUNKS_OFFSET_MASK,
  326. };
  327. EXPORT_SYMBOL(mschunks_map);
  328. void mschunks_alloc(unsigned long num_chunks)
  329. {
  330. klimit = _ALIGN(klimit, sizeof(u32));
  331. mschunks_map.mapping = (u32 *)klimit;
  332. klimit += num_chunks * sizeof(u32);
  333. mschunks_map.num_chunks = num_chunks;
  334. }
  335. /*
  336. * The iSeries may have very large memories ( > 128 GB ) and a partition
  337. * may get memory in "chunks" that may be anywhere in the 2**52 real
  338. * address space. The chunks are 256K in size. To map this to the
  339. * memory model Linux expects, the AS/400 specific code builds a
  340. * translation table to translate what Linux thinks are "physical"
  341. * addresses to the actual real addresses. This allows us to make
  342. * it appear to Linux that we have contiguous memory starting at
  343. * physical address zero while in fact this could be far from the truth.
  344. * To avoid confusion, I'll let the words physical and/or real address
  345. * apply to the Linux addresses while I'll use "absolute address" to
  346. * refer to the actual hardware real address.
  347. *
  348. * build_iSeries_Memory_Map gets information from the Hypervisor and
  349. * looks at the Main Store VPD to determine the absolute addresses
  350. * of the memory that has been assigned to our partition and builds
  351. * a table used to translate Linux's physical addresses to these
  352. * absolute addresses. Absolute addresses are needed when
  353. * communicating with the hypervisor (e.g. to build HPT entries)
  354. *
  355. * Returns the physical memory size
  356. */
  357. static unsigned long __init build_iSeries_Memory_Map(void)
  358. {
  359. u32 loadAreaFirstChunk, loadAreaLastChunk, loadAreaSize;
  360. u32 nextPhysChunk;
  361. u32 hptFirstChunk, hptLastChunk, hptSizeChunks, hptSizePages;
  362. u32 totalChunks,moreChunks;
  363. u32 currChunk, thisChunk, absChunk;
  364. u32 currDword;
  365. u32 chunkBit;
  366. u64 map;
  367. struct MemoryBlock mb[32];
  368. unsigned long numMemoryBlocks, curBlock;
  369. /* Chunk size on iSeries is 256K bytes */
  370. totalChunks = (u32)HvLpConfig_getMsChunks();
  371. mschunks_alloc(totalChunks);
  372. /*
  373. * Get absolute address of our load area
  374. * and map it to physical address 0
  375. * This guarantees that the loadarea ends up at physical 0
  376. * otherwise, it might not be returned by PLIC as the first
  377. * chunks
  378. */
  379. loadAreaFirstChunk = (u32)addr_to_chunk(itLpNaca.xLoadAreaAddr);
  380. loadAreaSize = itLpNaca.xLoadAreaChunks;
  381. /*
  382. * Only add the pages already mapped here.
  383. * Otherwise we might add the hpt pages
  384. * The rest of the pages of the load area
  385. * aren't in the HPT yet and can still
  386. * be assigned an arbitrary physical address
  387. */
  388. if ((loadAreaSize * 64) > HvPagesToMap)
  389. loadAreaSize = HvPagesToMap / 64;
  390. loadAreaLastChunk = loadAreaFirstChunk + loadAreaSize - 1;
  391. /*
  392. * TODO Do we need to do something if the HPT is in the 64MB load area?
  393. * This would be required if the itLpNaca.xLoadAreaChunks includes
  394. * the HPT size
  395. */
  396. printk("Mapping load area - physical addr = 0000000000000000\n"
  397. " absolute addr = %016lx\n",
  398. chunk_to_addr(loadAreaFirstChunk));
  399. printk("Load area size %dK\n", loadAreaSize * 256);
  400. for (nextPhysChunk = 0; nextPhysChunk < loadAreaSize; ++nextPhysChunk)
  401. mschunks_map.mapping[nextPhysChunk] =
  402. loadAreaFirstChunk + nextPhysChunk;
  403. /*
  404. * Get absolute address of our HPT and remember it so
  405. * we won't map it to any physical address
  406. */
  407. hptFirstChunk = (u32)addr_to_chunk(HvCallHpt_getHptAddress());
  408. hptSizePages = (u32)HvCallHpt_getHptPages();
  409. hptSizeChunks = hptSizePages >>
  410. (MSCHUNKS_CHUNK_SHIFT - HW_PAGE_SHIFT);
  411. hptLastChunk = hptFirstChunk + hptSizeChunks - 1;
  412. printk("HPT absolute addr = %016lx, size = %dK\n",
  413. chunk_to_addr(hptFirstChunk), hptSizeChunks * 256);
  414. /*
  415. * Determine if absolute memory has any
  416. * holes so that we can interpret the
  417. * access map we get back from the hypervisor
  418. * correctly.
  419. */
  420. numMemoryBlocks = iSeries_process_mainstore_vpd(mb, 32);
  421. /*
  422. * Process the main store access map from the hypervisor
  423. * to build up our physical -> absolute translation table
  424. */
  425. curBlock = 0;
  426. currChunk = 0;
  427. currDword = 0;
  428. moreChunks = totalChunks;
  429. while (moreChunks) {
  430. map = HvCallSm_get64BitsOfAccessMap(itLpNaca.xLpIndex,
  431. currDword);
  432. thisChunk = currChunk;
  433. while (map) {
  434. chunkBit = map >> 63;
  435. map <<= 1;
  436. if (chunkBit) {
  437. --moreChunks;
  438. while (thisChunk >= mb[curBlock].logicalEnd) {
  439. ++curBlock;
  440. if (curBlock >= numMemoryBlocks)
  441. panic("out of memory blocks");
  442. }
  443. if (thisChunk < mb[curBlock].logicalStart)
  444. panic("memory block error");
  445. absChunk = mb[curBlock].absStart +
  446. (thisChunk - mb[curBlock].logicalStart);
  447. if (((absChunk < hptFirstChunk) ||
  448. (absChunk > hptLastChunk)) &&
  449. ((absChunk < loadAreaFirstChunk) ||
  450. (absChunk > loadAreaLastChunk))) {
  451. mschunks_map.mapping[nextPhysChunk] =
  452. absChunk;
  453. ++nextPhysChunk;
  454. }
  455. }
  456. ++thisChunk;
  457. }
  458. ++currDword;
  459. currChunk += 64;
  460. }
  461. /*
  462. * main store size (in chunks) is
  463. * totalChunks - hptSizeChunks
  464. * which should be equal to
  465. * nextPhysChunk
  466. */
  467. return chunk_to_addr(nextPhysChunk);
  468. }
  469. /*
  470. * Document me.
  471. */
  472. static void __init iSeries_setup_arch(void)
  473. {
  474. if (get_lppaca()->shared_proc) {
  475. ppc_md.idle_loop = iseries_shared_idle;
  476. printk(KERN_INFO "Using shared processor idle loop\n");
  477. } else {
  478. ppc_md.idle_loop = iseries_dedicated_idle;
  479. printk(KERN_INFO "Using dedicated idle loop\n");
  480. }
  481. /* Setup the Lp Event Queue */
  482. setup_hvlpevent_queue();
  483. printk("Max logical processors = %d\n",
  484. itVpdAreas.xSlicMaxLogicalProcs);
  485. printk("Max physical processors = %d\n",
  486. itVpdAreas.xSlicMaxPhysicalProcs);
  487. }
  488. static void iSeries_show_cpuinfo(struct seq_file *m)
  489. {
  490. seq_printf(m, "machine\t\t: 64-bit iSeries Logical Partition\n");
  491. }
  492. /*
  493. * Document me.
  494. */
  495. static void iSeries_restart(char *cmd)
  496. {
  497. mf_reboot();
  498. }
  499. /*
  500. * Document me.
  501. */
  502. static void iSeries_power_off(void)
  503. {
  504. mf_power_off();
  505. }
  506. /*
  507. * Document me.
  508. */
  509. static void iSeries_halt(void)
  510. {
  511. mf_power_off();
  512. }
  513. static void __init iSeries_progress(char * st, unsigned short code)
  514. {
  515. printk("Progress: [%04x] - %s\n", (unsigned)code, st);
  516. if (!piranha_simulator && mf_initialized) {
  517. if (code != 0xffff)
  518. mf_display_progress(code);
  519. else
  520. mf_clear_src();
  521. }
  522. }
  523. static void __init iSeries_fixup_klimit(void)
  524. {
  525. /*
  526. * Change klimit to take into account any ram disk
  527. * that may be included
  528. */
  529. if (naca.xRamDisk)
  530. klimit = KERNELBASE + (u64)naca.xRamDisk +
  531. (naca.xRamDiskSize * HW_PAGE_SIZE);
  532. else {
  533. /*
  534. * No ram disk was included - check and see if there
  535. * was an embedded system map. Change klimit to take
  536. * into account any embedded system map
  537. */
  538. if (embedded_sysmap_end)
  539. klimit = KERNELBASE + ((embedded_sysmap_end + 4095) &
  540. 0xfffffffffffff000);
  541. }
  542. }
  543. static int __init iSeries_src_init(void)
  544. {
  545. /* clear the progress line */
  546. ppc_md.progress(" ", 0xffff);
  547. return 0;
  548. }
  549. late_initcall(iSeries_src_init);
  550. static inline void process_iSeries_events(void)
  551. {
  552. asm volatile ("li 0,0x5555; sc" : : : "r0", "r3");
  553. }
  554. static void yield_shared_processor(void)
  555. {
  556. unsigned long tb;
  557. HvCall_setEnabledInterrupts(HvCall_MaskIPI |
  558. HvCall_MaskLpEvent |
  559. HvCall_MaskLpProd |
  560. HvCall_MaskTimeout);
  561. tb = get_tb();
  562. /* Compute future tb value when yield should expire */
  563. HvCall_yieldProcessor(HvCall_YieldTimed, tb+tb_ticks_per_jiffy);
  564. /*
  565. * The decrementer stops during the yield. Force a fake decrementer
  566. * here and let the timer_interrupt code sort out the actual time.
  567. */
  568. get_lppaca()->int_dword.fields.decr_int = 1;
  569. ppc64_runlatch_on();
  570. process_iSeries_events();
  571. }
  572. static void iseries_shared_idle(void)
  573. {
  574. while (1) {
  575. while (!need_resched() && !hvlpevent_is_pending()) {
  576. local_irq_disable();
  577. ppc64_runlatch_off();
  578. /* Recheck with irqs off */
  579. if (!need_resched() && !hvlpevent_is_pending())
  580. yield_shared_processor();
  581. HMT_medium();
  582. local_irq_enable();
  583. }
  584. ppc64_runlatch_on();
  585. if (hvlpevent_is_pending())
  586. process_iSeries_events();
  587. preempt_enable_no_resched();
  588. schedule();
  589. preempt_disable();
  590. }
  591. }
  592. static void iseries_dedicated_idle(void)
  593. {
  594. set_thread_flag(TIF_POLLING_NRFLAG);
  595. while (1) {
  596. if (!need_resched()) {
  597. while (!need_resched()) {
  598. ppc64_runlatch_off();
  599. HMT_low();
  600. if (hvlpevent_is_pending()) {
  601. HMT_medium();
  602. ppc64_runlatch_on();
  603. process_iSeries_events();
  604. }
  605. }
  606. HMT_medium();
  607. }
  608. ppc64_runlatch_on();
  609. preempt_enable_no_resched();
  610. schedule();
  611. preempt_disable();
  612. }
  613. }
  614. #ifndef CONFIG_PCI
  615. void __init iSeries_init_IRQ(void) { }
  616. #endif
  617. static int __init iseries_probe(int platform)
  618. {
  619. if (PLATFORM_ISERIES_LPAR != platform)
  620. return 0;
  621. ppc64_firmware_features |= FW_FEATURE_ISERIES;
  622. ppc64_firmware_features |= FW_FEATURE_LPAR;
  623. return 1;
  624. }
  625. struct machdep_calls __initdata iseries_md = {
  626. .setup_arch = iSeries_setup_arch,
  627. .show_cpuinfo = iSeries_show_cpuinfo,
  628. .init_IRQ = iSeries_init_IRQ,
  629. .get_irq = iSeries_get_irq,
  630. .init_early = iSeries_init_early,
  631. .pcibios_fixup = iSeries_pci_final_fixup,
  632. .restart = iSeries_restart,
  633. .power_off = iSeries_power_off,
  634. .halt = iSeries_halt,
  635. .get_boot_time = iSeries_get_boot_time,
  636. .set_rtc_time = iSeries_set_rtc_time,
  637. .get_rtc_time = iSeries_get_rtc_time,
  638. .calibrate_decr = generic_calibrate_decr,
  639. .progress = iSeries_progress,
  640. .probe = iseries_probe,
  641. /* XXX Implement enable_pmcs for iSeries */
  642. };
  643. struct blob {
  644. unsigned char data[PAGE_SIZE];
  645. unsigned long next;
  646. };
  647. struct iseries_flat_dt {
  648. struct boot_param_header header;
  649. u64 reserve_map[2];
  650. struct blob dt;
  651. struct blob strings;
  652. };
  653. struct iseries_flat_dt iseries_dt;
  654. void dt_init(struct iseries_flat_dt *dt)
  655. {
  656. dt->header.off_mem_rsvmap =
  657. offsetof(struct iseries_flat_dt, reserve_map);
  658. dt->header.off_dt_struct = offsetof(struct iseries_flat_dt, dt);
  659. dt->header.off_dt_strings = offsetof(struct iseries_flat_dt, strings);
  660. dt->header.totalsize = sizeof(struct iseries_flat_dt);
  661. dt->header.dt_strings_size = sizeof(struct blob);
  662. /* There is no notion of hardware cpu id on iSeries */
  663. dt->header.boot_cpuid_phys = smp_processor_id();
  664. dt->dt.next = (unsigned long)&dt->dt.data;
  665. dt->strings.next = (unsigned long)&dt->strings.data;
  666. dt->header.magic = OF_DT_HEADER;
  667. dt->header.version = 0x10;
  668. dt->header.last_comp_version = 0x10;
  669. dt->reserve_map[0] = 0;
  670. dt->reserve_map[1] = 0;
  671. }
  672. void dt_check_blob(struct blob *b)
  673. {
  674. if (b->next >= (unsigned long)&b->next) {
  675. DBG("Ran out of space in flat device tree blob!\n");
  676. BUG();
  677. }
  678. }
  679. void dt_push_u32(struct iseries_flat_dt *dt, u32 value)
  680. {
  681. *((u32*)dt->dt.next) = value;
  682. dt->dt.next += sizeof(u32);
  683. dt_check_blob(&dt->dt);
  684. }
  685. void dt_push_u64(struct iseries_flat_dt *dt, u64 value)
  686. {
  687. *((u64*)dt->dt.next) = value;
  688. dt->dt.next += sizeof(u64);
  689. dt_check_blob(&dt->dt);
  690. }
  691. unsigned long dt_push_bytes(struct blob *blob, char *data, int len)
  692. {
  693. unsigned long start = blob->next - (unsigned long)blob->data;
  694. memcpy((char *)blob->next, data, len);
  695. blob->next = _ALIGN(blob->next + len, 4);
  696. dt_check_blob(blob);
  697. return start;
  698. }
  699. void dt_start_node(struct iseries_flat_dt *dt, char *name)
  700. {
  701. dt_push_u32(dt, OF_DT_BEGIN_NODE);
  702. dt_push_bytes(&dt->dt, name, strlen(name) + 1);
  703. }
  704. #define dt_end_node(dt) dt_push_u32(dt, OF_DT_END_NODE)
  705. void dt_prop(struct iseries_flat_dt *dt, char *name, char *data, int len)
  706. {
  707. unsigned long offset;
  708. dt_push_u32(dt, OF_DT_PROP);
  709. /* Length of the data */
  710. dt_push_u32(dt, len);
  711. /* Put the property name in the string blob. */
  712. offset = dt_push_bytes(&dt->strings, name, strlen(name) + 1);
  713. /* The offset of the properties name in the string blob. */
  714. dt_push_u32(dt, (u32)offset);
  715. /* The actual data. */
  716. dt_push_bytes(&dt->dt, data, len);
  717. }
  718. void dt_prop_str(struct iseries_flat_dt *dt, char *name, char *data)
  719. {
  720. dt_prop(dt, name, data, strlen(data) + 1); /* + 1 for NULL */
  721. }
  722. void dt_prop_u32(struct iseries_flat_dt *dt, char *name, u32 data)
  723. {
  724. dt_prop(dt, name, (char *)&data, sizeof(u32));
  725. }
  726. void dt_prop_u64(struct iseries_flat_dt *dt, char *name, u64 data)
  727. {
  728. dt_prop(dt, name, (char *)&data, sizeof(u64));
  729. }
  730. void dt_prop_u64_list(struct iseries_flat_dt *dt, char *name, u64 *data, int n)
  731. {
  732. dt_prop(dt, name, (char *)data, sizeof(u64) * n);
  733. }
  734. void dt_prop_u32_list(struct iseries_flat_dt *dt, char *name, u32 *data, int n)
  735. {
  736. dt_prop(dt, name, (char *)data, sizeof(u32) * n);
  737. }
  738. void dt_prop_empty(struct iseries_flat_dt *dt, char *name)
  739. {
  740. dt_prop(dt, name, NULL, 0);
  741. }
  742. void dt_cpus(struct iseries_flat_dt *dt)
  743. {
  744. unsigned char buf[32];
  745. unsigned char *p;
  746. unsigned int i, index;
  747. struct IoHriProcessorVpd *d;
  748. u32 pft_size[2];
  749. /* yuck */
  750. snprintf(buf, 32, "PowerPC,%s", cur_cpu_spec->cpu_name);
  751. p = strchr(buf, ' ');
  752. if (!p) p = buf + strlen(buf);
  753. dt_start_node(dt, "cpus");
  754. dt_prop_u32(dt, "#address-cells", 1);
  755. dt_prop_u32(dt, "#size-cells", 0);
  756. pft_size[0] = 0; /* NUMA CEC cookie, 0 for non NUMA */
  757. pft_size[1] = __ilog2(HvCallHpt_getHptPages() * HW_PAGE_SIZE);
  758. for (i = 0; i < NR_CPUS; i++) {
  759. if (lppaca[i].dyn_proc_status >= 2)
  760. continue;
  761. snprintf(p, 32 - (p - buf), "@%d", i);
  762. dt_start_node(dt, buf);
  763. dt_prop_str(dt, "device_type", "cpu");
  764. index = lppaca[i].dyn_hv_phys_proc_index;
  765. d = &xIoHriProcessorVpd[index];
  766. dt_prop_u32(dt, "i-cache-size", d->xInstCacheSize * 1024);
  767. dt_prop_u32(dt, "i-cache-line-size", d->xInstCacheOperandSize);
  768. dt_prop_u32(dt, "d-cache-size", d->xDataL1CacheSizeKB * 1024);
  769. dt_prop_u32(dt, "d-cache-line-size", d->xDataCacheOperandSize);
  770. /* magic conversions to Hz copied from old code */
  771. dt_prop_u32(dt, "clock-frequency",
  772. ((1UL << 34) * 1000000) / d->xProcFreq);
  773. dt_prop_u32(dt, "timebase-frequency",
  774. ((1UL << 32) * 1000000) / d->xTimeBaseFreq);
  775. dt_prop_u32(dt, "reg", i);
  776. dt_prop_u32_list(dt, "ibm,pft-size", pft_size, 2);
  777. dt_end_node(dt);
  778. }
  779. dt_end_node(dt);
  780. }
  781. void build_flat_dt(struct iseries_flat_dt *dt, unsigned long phys_mem_size)
  782. {
  783. u64 tmp[2];
  784. dt_init(dt);
  785. dt_start_node(dt, "");
  786. dt_prop_u32(dt, "#address-cells", 2);
  787. dt_prop_u32(dt, "#size-cells", 2);
  788. /* /memory */
  789. dt_start_node(dt, "memory@0");
  790. dt_prop_str(dt, "name", "memory");
  791. dt_prop_str(dt, "device_type", "memory");
  792. tmp[0] = 0;
  793. tmp[1] = phys_mem_size;
  794. dt_prop_u64_list(dt, "reg", tmp, 2);
  795. dt_end_node(dt);
  796. /* /chosen */
  797. dt_start_node(dt, "chosen");
  798. dt_prop_u32(dt, "linux,platform", PLATFORM_ISERIES_LPAR);
  799. if (cmd_mem_limit)
  800. dt_prop_u64(dt, "linux,memory-limit", cmd_mem_limit);
  801. dt_end_node(dt);
  802. dt_cpus(dt);
  803. dt_end_node(dt);
  804. dt_push_u32(dt, OF_DT_END);
  805. }
  806. void * __init iSeries_early_setup(void)
  807. {
  808. unsigned long phys_mem_size;
  809. iSeries_fixup_klimit();
  810. /*
  811. * Initialize the table which translate Linux physical addresses to
  812. * AS/400 absolute addresses
  813. */
  814. phys_mem_size = build_iSeries_Memory_Map();
  815. iSeries_get_cmdline();
  816. /* Save unparsed command line copy for /proc/cmdline */
  817. strlcpy(saved_command_line, cmd_line, COMMAND_LINE_SIZE);
  818. /* Parse early parameters, in particular mem=x */
  819. parse_early_param();
  820. build_flat_dt(&iseries_dt, phys_mem_size);
  821. return (void *) __pa(&iseries_dt);
  822. }
  823. /*
  824. * On iSeries we just parse the mem=X option from the command line.
  825. * On pSeries it's a bit more complicated, see prom_init_mem()
  826. */
  827. static int __init early_parsemem(char *p)
  828. {
  829. if (p)
  830. cmd_mem_limit = ALIGN(memparse(p, &p), PAGE_SIZE);
  831. return 0;
  832. }
  833. early_param("mem", early_parsemem);
  834. static void hvputc(char c)
  835. {
  836. if (c == '\n')
  837. hvputc('\r');
  838. HvCall_writeLogBuffer(&c, 1);
  839. }
  840. void __init udbg_init_iseries(void)
  841. {
  842. udbg_putc = hvputc;
  843. }