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