iSeries_setup.c 26 KB

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