iSeries_setup.c 25 KB

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