setup.c 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998
  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/HvLpConfig.h>
  45. #include <asm/iSeries/HvCallEvent.h>
  46. #include <asm/iSeries/HvCallXm.h>
  47. #include <asm/iSeries/ItLpQueue.h>
  48. #include <asm/iSeries/mf.h>
  49. #include <asm/iSeries/HvLpEvent.h>
  50. #include <asm/iSeries/LparMap.h>
  51. #include "setup.h"
  52. #include "irq.h"
  53. #include "vpd_areas.h"
  54. #include "processor_vpd.h"
  55. #include "main_store.h"
  56. #include "call_sm.h"
  57. #include "call_hpt.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 void iseries_shared_idle(void);
  68. static void 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 totalChunks,moreChunks;
  376. u32 currChunk, thisChunk, absChunk;
  377. u32 currDword;
  378. u32 chunkBit;
  379. u64 map;
  380. struct MemoryBlock mb[32];
  381. unsigned long numMemoryBlocks, curBlock;
  382. /* Chunk size on iSeries is 256K bytes */
  383. totalChunks = (u32)HvLpConfig_getMsChunks();
  384. mschunks_alloc(totalChunks);
  385. /*
  386. * Get absolute address of our load area
  387. * and map it to physical address 0
  388. * This guarantees that the loadarea ends up at physical 0
  389. * otherwise, it might not be returned by PLIC as the first
  390. * chunks
  391. */
  392. loadAreaFirstChunk = (u32)addr_to_chunk(itLpNaca.xLoadAreaAddr);
  393. loadAreaSize = itLpNaca.xLoadAreaChunks;
  394. /*
  395. * Only add the pages already mapped here.
  396. * Otherwise we might add the hpt pages
  397. * The rest of the pages of the load area
  398. * aren't in the HPT yet and can still
  399. * be assigned an arbitrary physical address
  400. */
  401. if ((loadAreaSize * 64) > HvPagesToMap)
  402. loadAreaSize = HvPagesToMap / 64;
  403. loadAreaLastChunk = loadAreaFirstChunk + loadAreaSize - 1;
  404. /*
  405. * TODO Do we need to do something if the HPT is in the 64MB load area?
  406. * This would be required if the itLpNaca.xLoadAreaChunks includes
  407. * the HPT size
  408. */
  409. printk("Mapping load area - physical addr = 0000000000000000\n"
  410. " absolute addr = %016lx\n",
  411. chunk_to_addr(loadAreaFirstChunk));
  412. printk("Load area size %dK\n", loadAreaSize * 256);
  413. for (nextPhysChunk = 0; nextPhysChunk < loadAreaSize; ++nextPhysChunk)
  414. mschunks_map.mapping[nextPhysChunk] =
  415. loadAreaFirstChunk + nextPhysChunk;
  416. /*
  417. * Get absolute address of our HPT and remember it so
  418. * we won't map it to any physical address
  419. */
  420. hptFirstChunk = (u32)addr_to_chunk(HvCallHpt_getHptAddress());
  421. hptSizePages = (u32)HvCallHpt_getHptPages();
  422. hptSizeChunks = hptSizePages >> (MSCHUNKS_CHUNK_SHIFT - PAGE_SHIFT);
  423. hptLastChunk = hptFirstChunk + hptSizeChunks - 1;
  424. printk("HPT absolute addr = %016lx, size = %dK\n",
  425. chunk_to_addr(hptFirstChunk), hptSizeChunks * 256);
  426. ppc64_pft_size = __ilog2(hptSizePages * PAGE_SIZE);
  427. /*
  428. * The actual hashed page table is in the hypervisor,
  429. * we have no direct access
  430. */
  431. htab_address = NULL;
  432. /*
  433. * Determine if absolute memory has any
  434. * holes so that we can interpret the
  435. * access map we get back from the hypervisor
  436. * correctly.
  437. */
  438. numMemoryBlocks = iSeries_process_mainstore_vpd(mb, 32);
  439. /*
  440. * Process the main store access map from the hypervisor
  441. * to build up our physical -> absolute translation table
  442. */
  443. curBlock = 0;
  444. currChunk = 0;
  445. currDword = 0;
  446. moreChunks = totalChunks;
  447. while (moreChunks) {
  448. map = HvCallSm_get64BitsOfAccessMap(itLpNaca.xLpIndex,
  449. currDword);
  450. thisChunk = currChunk;
  451. while (map) {
  452. chunkBit = map >> 63;
  453. map <<= 1;
  454. if (chunkBit) {
  455. --moreChunks;
  456. while (thisChunk >= mb[curBlock].logicalEnd) {
  457. ++curBlock;
  458. if (curBlock >= numMemoryBlocks)
  459. panic("out of memory blocks");
  460. }
  461. if (thisChunk < mb[curBlock].logicalStart)
  462. panic("memory block error");
  463. absChunk = mb[curBlock].absStart +
  464. (thisChunk - mb[curBlock].logicalStart);
  465. if (((absChunk < hptFirstChunk) ||
  466. (absChunk > hptLastChunk)) &&
  467. ((absChunk < loadAreaFirstChunk) ||
  468. (absChunk > loadAreaLastChunk))) {
  469. mschunks_map.mapping[nextPhysChunk] =
  470. absChunk;
  471. ++nextPhysChunk;
  472. }
  473. }
  474. ++thisChunk;
  475. }
  476. ++currDword;
  477. currChunk += 64;
  478. }
  479. /*
  480. * main store size (in chunks) is
  481. * totalChunks - hptSizeChunks
  482. * which should be equal to
  483. * nextPhysChunk
  484. */
  485. systemcfg->physicalMemorySize = chunk_to_addr(nextPhysChunk);
  486. }
  487. /*
  488. * Document me.
  489. */
  490. static void __init iSeries_setup_arch(void)
  491. {
  492. unsigned procIx = get_paca()->lppaca.dyn_hv_phys_proc_index;
  493. if (get_paca()->lppaca.shared_proc) {
  494. ppc_md.idle_loop = iseries_shared_idle;
  495. printk(KERN_INFO "Using shared processor idle loop\n");
  496. } else {
  497. ppc_md.idle_loop = iseries_dedicated_idle;
  498. printk(KERN_INFO "Using dedicated idle loop\n");
  499. }
  500. /* Setup the Lp Event Queue */
  501. setup_hvlpevent_queue();
  502. printk("Max logical processors = %d\n",
  503. itVpdAreas.xSlicMaxLogicalProcs);
  504. printk("Max physical processors = %d\n",
  505. itVpdAreas.xSlicMaxPhysicalProcs);
  506. systemcfg->processor = xIoHriProcessorVpd[procIx].xPVR;
  507. printk("Processor version = %x\n", systemcfg->processor);
  508. }
  509. static void iSeries_get_cpuinfo(struct seq_file *m)
  510. {
  511. seq_printf(m, "machine\t\t: 64-bit iSeries Logical Partition\n");
  512. }
  513. /*
  514. * Document me.
  515. * and Implement me.
  516. */
  517. static int iSeries_get_irq(struct pt_regs *regs)
  518. {
  519. /* -2 means ignore this interrupt */
  520. return -2;
  521. }
  522. /*
  523. * Document me.
  524. */
  525. static void iSeries_restart(char *cmd)
  526. {
  527. mf_reboot();
  528. }
  529. /*
  530. * Document me.
  531. */
  532. static void iSeries_power_off(void)
  533. {
  534. mf_power_off();
  535. }
  536. /*
  537. * Document me.
  538. */
  539. static void iSeries_halt(void)
  540. {
  541. mf_power_off();
  542. }
  543. static void __init iSeries_progress(char * st, unsigned short code)
  544. {
  545. printk("Progress: [%04x] - %s\n", (unsigned)code, st);
  546. if (!piranha_simulator && mf_initialized) {
  547. if (code != 0xffff)
  548. mf_display_progress(code);
  549. else
  550. mf_clear_src();
  551. }
  552. }
  553. static void __init iSeries_fixup_klimit(void)
  554. {
  555. /*
  556. * Change klimit to take into account any ram disk
  557. * that may be included
  558. */
  559. if (naca.xRamDisk)
  560. klimit = KERNELBASE + (u64)naca.xRamDisk +
  561. (naca.xRamDiskSize * PAGE_SIZE);
  562. else {
  563. /*
  564. * No ram disk was included - check and see if there
  565. * was an embedded system map. Change klimit to take
  566. * into account any embedded system map
  567. */
  568. if (embedded_sysmap_end)
  569. klimit = KERNELBASE + ((embedded_sysmap_end + 4095) &
  570. 0xfffffffffffff000);
  571. }
  572. }
  573. static int __init iSeries_src_init(void)
  574. {
  575. /* clear the progress line */
  576. ppc_md.progress(" ", 0xffff);
  577. return 0;
  578. }
  579. late_initcall(iSeries_src_init);
  580. static inline void process_iSeries_events(void)
  581. {
  582. asm volatile ("li 0,0x5555; sc" : : : "r0", "r3");
  583. }
  584. static void yield_shared_processor(void)
  585. {
  586. unsigned long tb;
  587. HvCall_setEnabledInterrupts(HvCall_MaskIPI |
  588. HvCall_MaskLpEvent |
  589. HvCall_MaskLpProd |
  590. HvCall_MaskTimeout);
  591. tb = get_tb();
  592. /* Compute future tb value when yield should expire */
  593. HvCall_yieldProcessor(HvCall_YieldTimed, tb+tb_ticks_per_jiffy);
  594. /*
  595. * The decrementer stops during the yield. Force a fake decrementer
  596. * here and let the timer_interrupt code sort out the actual time.
  597. */
  598. get_paca()->lppaca.int_dword.fields.decr_int = 1;
  599. process_iSeries_events();
  600. }
  601. static void iseries_shared_idle(void)
  602. {
  603. while (1) {
  604. while (!need_resched() && !hvlpevent_is_pending()) {
  605. local_irq_disable();
  606. ppc64_runlatch_off();
  607. /* Recheck with irqs off */
  608. if (!need_resched() && !hvlpevent_is_pending())
  609. yield_shared_processor();
  610. HMT_medium();
  611. local_irq_enable();
  612. }
  613. ppc64_runlatch_on();
  614. if (hvlpevent_is_pending())
  615. process_iSeries_events();
  616. schedule();
  617. }
  618. }
  619. static void iseries_dedicated_idle(void)
  620. {
  621. long oldval;
  622. while (1) {
  623. oldval = test_and_clear_thread_flag(TIF_NEED_RESCHED);
  624. if (!oldval) {
  625. set_thread_flag(TIF_POLLING_NRFLAG);
  626. while (!need_resched()) {
  627. ppc64_runlatch_off();
  628. HMT_low();
  629. if (hvlpevent_is_pending()) {
  630. HMT_medium();
  631. ppc64_runlatch_on();
  632. process_iSeries_events();
  633. }
  634. }
  635. HMT_medium();
  636. clear_thread_flag(TIF_POLLING_NRFLAG);
  637. } else {
  638. set_need_resched();
  639. }
  640. ppc64_runlatch_on();
  641. schedule();
  642. }
  643. }
  644. #ifndef CONFIG_PCI
  645. void __init iSeries_init_IRQ(void) { }
  646. #endif
  647. static int __init iseries_probe(int platform)
  648. {
  649. return PLATFORM_ISERIES_LPAR == platform;
  650. }
  651. struct machdep_calls __initdata iseries_md = {
  652. .setup_arch = iSeries_setup_arch,
  653. .get_cpuinfo = iSeries_get_cpuinfo,
  654. .init_IRQ = iSeries_init_IRQ,
  655. .get_irq = iSeries_get_irq,
  656. .init_early = iSeries_init_early,
  657. .pcibios_fixup = iSeries_pci_final_fixup,
  658. .restart = iSeries_restart,
  659. .power_off = iSeries_power_off,
  660. .halt = iSeries_halt,
  661. .get_boot_time = iSeries_get_boot_time,
  662. .set_rtc_time = iSeries_set_rtc_time,
  663. .get_rtc_time = iSeries_get_rtc_time,
  664. .calibrate_decr = generic_calibrate_decr,
  665. .progress = iSeries_progress,
  666. .probe = iseries_probe,
  667. /* XXX Implement enable_pmcs for iSeries */
  668. };
  669. struct blob {
  670. unsigned char data[PAGE_SIZE];
  671. unsigned long next;
  672. };
  673. struct iseries_flat_dt {
  674. struct boot_param_header header;
  675. u64 reserve_map[2];
  676. struct blob dt;
  677. struct blob strings;
  678. };
  679. struct iseries_flat_dt iseries_dt;
  680. void dt_init(struct iseries_flat_dt *dt)
  681. {
  682. dt->header.off_mem_rsvmap =
  683. offsetof(struct iseries_flat_dt, reserve_map);
  684. dt->header.off_dt_struct = offsetof(struct iseries_flat_dt, dt);
  685. dt->header.off_dt_strings = offsetof(struct iseries_flat_dt, strings);
  686. dt->header.totalsize = sizeof(struct iseries_flat_dt);
  687. dt->header.dt_strings_size = sizeof(struct blob);
  688. /* There is no notion of hardware cpu id on iSeries */
  689. dt->header.boot_cpuid_phys = smp_processor_id();
  690. dt->dt.next = (unsigned long)&dt->dt.data;
  691. dt->strings.next = (unsigned long)&dt->strings.data;
  692. dt->header.magic = OF_DT_HEADER;
  693. dt->header.version = 0x10;
  694. dt->header.last_comp_version = 0x10;
  695. dt->reserve_map[0] = 0;
  696. dt->reserve_map[1] = 0;
  697. }
  698. void dt_check_blob(struct blob *b)
  699. {
  700. if (b->next >= (unsigned long)&b->next) {
  701. DBG("Ran out of space in flat device tree blob!\n");
  702. BUG();
  703. }
  704. }
  705. void dt_push_u32(struct iseries_flat_dt *dt, u32 value)
  706. {
  707. *((u32*)dt->dt.next) = value;
  708. dt->dt.next += sizeof(u32);
  709. dt_check_blob(&dt->dt);
  710. }
  711. void dt_push_u64(struct iseries_flat_dt *dt, u64 value)
  712. {
  713. *((u64*)dt->dt.next) = value;
  714. dt->dt.next += sizeof(u64);
  715. dt_check_blob(&dt->dt);
  716. }
  717. unsigned long dt_push_bytes(struct blob *blob, char *data, int len)
  718. {
  719. unsigned long start = blob->next - (unsigned long)blob->data;
  720. memcpy((char *)blob->next, data, len);
  721. blob->next = _ALIGN(blob->next + len, 4);
  722. dt_check_blob(blob);
  723. return start;
  724. }
  725. void dt_start_node(struct iseries_flat_dt *dt, char *name)
  726. {
  727. dt_push_u32(dt, OF_DT_BEGIN_NODE);
  728. dt_push_bytes(&dt->dt, name, strlen(name) + 1);
  729. }
  730. #define dt_end_node(dt) dt_push_u32(dt, OF_DT_END_NODE)
  731. void dt_prop(struct iseries_flat_dt *dt, char *name, char *data, int len)
  732. {
  733. unsigned long offset;
  734. dt_push_u32(dt, OF_DT_PROP);
  735. /* Length of the data */
  736. dt_push_u32(dt, len);
  737. /* Put the property name in the string blob. */
  738. offset = dt_push_bytes(&dt->strings, name, strlen(name) + 1);
  739. /* The offset of the properties name in the string blob. */
  740. dt_push_u32(dt, (u32)offset);
  741. /* The actual data. */
  742. dt_push_bytes(&dt->dt, data, len);
  743. }
  744. void dt_prop_str(struct iseries_flat_dt *dt, char *name, char *data)
  745. {
  746. dt_prop(dt, name, data, strlen(data) + 1); /* + 1 for NULL */
  747. }
  748. void dt_prop_u32(struct iseries_flat_dt *dt, char *name, u32 data)
  749. {
  750. dt_prop(dt, name, (char *)&data, sizeof(u32));
  751. }
  752. void dt_prop_u64(struct iseries_flat_dt *dt, char *name, u64 data)
  753. {
  754. dt_prop(dt, name, (char *)&data, sizeof(u64));
  755. }
  756. void dt_prop_u64_list(struct iseries_flat_dt *dt, char *name, u64 *data, int n)
  757. {
  758. dt_prop(dt, name, (char *)data, sizeof(u64) * n);
  759. }
  760. void dt_prop_empty(struct iseries_flat_dt *dt, char *name)
  761. {
  762. dt_prop(dt, name, NULL, 0);
  763. }
  764. void dt_cpus(struct iseries_flat_dt *dt)
  765. {
  766. unsigned char buf[32];
  767. unsigned char *p;
  768. unsigned int i, index;
  769. struct IoHriProcessorVpd *d;
  770. /* yuck */
  771. snprintf(buf, 32, "PowerPC,%s", cur_cpu_spec->cpu_name);
  772. p = strchr(buf, ' ');
  773. if (!p) p = buf + strlen(buf);
  774. dt_start_node(dt, "cpus");
  775. dt_prop_u32(dt, "#address-cells", 1);
  776. dt_prop_u32(dt, "#size-cells", 0);
  777. for (i = 0; i < NR_CPUS; i++) {
  778. if (paca[i].lppaca.dyn_proc_status >= 2)
  779. continue;
  780. snprintf(p, 32 - (p - buf), "@%d", i);
  781. dt_start_node(dt, buf);
  782. dt_prop_str(dt, "device_type", "cpu");
  783. index = paca[i].lppaca.dyn_hv_phys_proc_index;
  784. d = &xIoHriProcessorVpd[index];
  785. dt_prop_u32(dt, "i-cache-size", d->xInstCacheSize * 1024);
  786. dt_prop_u32(dt, "i-cache-line-size", d->xInstCacheOperandSize);
  787. dt_prop_u32(dt, "d-cache-size", d->xDataL1CacheSizeKB * 1024);
  788. dt_prop_u32(dt, "d-cache-line-size", d->xDataCacheOperandSize);
  789. /* magic conversions to Hz copied from old code */
  790. dt_prop_u32(dt, "clock-frequency",
  791. ((1UL << 34) * 1000000) / d->xProcFreq);
  792. dt_prop_u32(dt, "timebase-frequency",
  793. ((1UL << 32) * 1000000) / d->xTimeBaseFreq);
  794. dt_prop_u32(dt, "reg", i);
  795. dt_end_node(dt);
  796. }
  797. dt_end_node(dt);
  798. }
  799. void build_flat_dt(struct iseries_flat_dt *dt)
  800. {
  801. u64 tmp[2];
  802. dt_init(dt);
  803. dt_start_node(dt, "");
  804. dt_prop_u32(dt, "#address-cells", 2);
  805. dt_prop_u32(dt, "#size-cells", 2);
  806. /* /memory */
  807. dt_start_node(dt, "memory@0");
  808. dt_prop_str(dt, "name", "memory");
  809. dt_prop_str(dt, "device_type", "memory");
  810. tmp[0] = 0;
  811. tmp[1] = systemcfg->physicalMemorySize;
  812. dt_prop_u64_list(dt, "reg", tmp, 2);
  813. dt_end_node(dt);
  814. /* /chosen */
  815. dt_start_node(dt, "chosen");
  816. dt_prop_u32(dt, "linux,platform", PLATFORM_ISERIES_LPAR);
  817. dt_end_node(dt);
  818. dt_cpus(dt);
  819. dt_end_node(dt);
  820. dt_push_u32(dt, OF_DT_END);
  821. }
  822. void * __init iSeries_early_setup(void)
  823. {
  824. iSeries_fixup_klimit();
  825. /*
  826. * Initialize the table which translate Linux physical addresses to
  827. * AS/400 absolute addresses
  828. */
  829. build_iSeries_Memory_Map();
  830. build_flat_dt(&iseries_dt);
  831. return (void *) __pa(&iseries_dt);
  832. }