iSeries_setup.c 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902
  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/bootmem.h>
  26. #include <linux/initrd.h>
  27. #include <linux/seq_file.h>
  28. #include <linux/kdev_t.h>
  29. #include <linux/major.h>
  30. #include <linux/root_dev.h>
  31. #include <asm/processor.h>
  32. #include <asm/machdep.h>
  33. #include <asm/page.h>
  34. #include <asm/mmu.h>
  35. #include <asm/pgtable.h>
  36. #include <asm/mmu_context.h>
  37. #include <asm/cputable.h>
  38. #include <asm/sections.h>
  39. #include <asm/iommu.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. ppcdbg_initialize();
  279. #if defined(CONFIG_BLK_DEV_INITRD)
  280. /*
  281. * If the init RAM disk has been configured and there is
  282. * a non-zero starting address for it, set it up
  283. */
  284. if (naca.xRamDisk) {
  285. initrd_start = (unsigned long)__va(naca.xRamDisk);
  286. initrd_end = initrd_start + naca.xRamDiskSize * PAGE_SIZE;
  287. initrd_below_start_ok = 1; // ramdisk in kernel space
  288. ROOT_DEV = Root_RAM0;
  289. if (((rd_size * 1024) / PAGE_SIZE) < naca.xRamDiskSize)
  290. rd_size = (naca.xRamDiskSize * PAGE_SIZE) / 1024;
  291. } else
  292. #endif /* CONFIG_BLK_DEV_INITRD */
  293. {
  294. /* ROOT_DEV = MKDEV(VIODASD_MAJOR, 1); */
  295. }
  296. iSeries_recal_tb = get_tb();
  297. iSeries_recal_titan = HvCallXm_loadTod();
  298. /*
  299. * Cache sizes must be initialized before hpte_init_iSeries is called
  300. * as the later need them for flush_icache_range()
  301. */
  302. setup_iSeries_cache_sizes();
  303. /*
  304. * Initialize the hash table management pointers
  305. */
  306. hpte_init_iSeries();
  307. /*
  308. * Initialize the DMA/TCE management
  309. */
  310. iommu_init_early_iSeries();
  311. /*
  312. * Initialize the table which translate Linux physical addresses to
  313. * AS/400 absolute addresses
  314. */
  315. build_iSeries_Memory_Map();
  316. iSeries_get_cmdline();
  317. /* Save unparsed command line copy for /proc/cmdline */
  318. strlcpy(saved_command_line, cmd_line, COMMAND_LINE_SIZE);
  319. /* Parse early parameters, in particular mem=x */
  320. parse_early_param();
  321. if (memory_limit) {
  322. if (memory_limit < systemcfg->physicalMemorySize)
  323. systemcfg->physicalMemorySize = memory_limit;
  324. else {
  325. printk("Ignoring mem=%lu >= ram_top.\n", memory_limit);
  326. memory_limit = 0;
  327. }
  328. }
  329. /* Bolt kernel mappings for all of memory (or just a bit if we've got a limit) */
  330. iSeries_bolt_kernel(0, systemcfg->physicalMemorySize);
  331. lmb_init();
  332. lmb_add(0, systemcfg->physicalMemorySize);
  333. lmb_analyze();
  334. lmb_reserve(0, __pa(klimit));
  335. /* Initialize machine-dependency vectors */
  336. #ifdef CONFIG_SMP
  337. smp_init_iSeries();
  338. #endif
  339. if (itLpNaca.xPirEnvironMode == 0)
  340. piranha_simulator = 1;
  341. /* Associate Lp Event Queue 0 with processor 0 */
  342. HvCallEvent_setLpEventQueueInterruptProc(0, 0);
  343. mf_init();
  344. mf_initialized = 1;
  345. mb();
  346. /* If we were passed an initrd, set the ROOT_DEV properly if the values
  347. * look sensible. If not, clear initrd reference.
  348. */
  349. #ifdef CONFIG_BLK_DEV_INITRD
  350. if (initrd_start >= KERNELBASE && initrd_end >= KERNELBASE &&
  351. initrd_end > initrd_start)
  352. ROOT_DEV = Root_RAM0;
  353. else
  354. initrd_start = initrd_end = 0;
  355. #endif /* CONFIG_BLK_DEV_INITRD */
  356. DBG(" <- iSeries_init_early()\n");
  357. }
  358. /*
  359. * The iSeries may have very large memories ( > 128 GB ) and a partition
  360. * may get memory in "chunks" that may be anywhere in the 2**52 real
  361. * address space. The chunks are 256K in size. To map this to the
  362. * memory model Linux expects, the AS/400 specific code builds a
  363. * translation table to translate what Linux thinks are "physical"
  364. * addresses to the actual real addresses. This allows us to make
  365. * it appear to Linux that we have contiguous memory starting at
  366. * physical address zero while in fact this could be far from the truth.
  367. * To avoid confusion, I'll let the words physical and/or real address
  368. * apply to the Linux addresses while I'll use "absolute address" to
  369. * refer to the actual hardware real address.
  370. *
  371. * build_iSeries_Memory_Map gets information from the Hypervisor and
  372. * looks at the Main Store VPD to determine the absolute addresses
  373. * of the memory that has been assigned to our partition and builds
  374. * a table used to translate Linux's physical addresses to these
  375. * absolute addresses. Absolute addresses are needed when
  376. * communicating with the hypervisor (e.g. to build HPT entries)
  377. */
  378. static void __init build_iSeries_Memory_Map(void)
  379. {
  380. u32 loadAreaFirstChunk, loadAreaLastChunk, loadAreaSize;
  381. u32 nextPhysChunk;
  382. u32 hptFirstChunk, hptLastChunk, hptSizeChunks, hptSizePages;
  383. u32 num_ptegs;
  384. u32 totalChunks,moreChunks;
  385. u32 currChunk, thisChunk, absChunk;
  386. u32 currDword;
  387. u32 chunkBit;
  388. u64 map;
  389. struct MemoryBlock mb[32];
  390. unsigned long numMemoryBlocks, curBlock;
  391. /* Chunk size on iSeries is 256K bytes */
  392. totalChunks = (u32)HvLpConfig_getMsChunks();
  393. klimit = msChunks_alloc(klimit, totalChunks, 1UL << 18);
  394. /*
  395. * Get absolute address of our load area
  396. * and map it to physical address 0
  397. * This guarantees that the loadarea ends up at physical 0
  398. * otherwise, it might not be returned by PLIC as the first
  399. * chunks
  400. */
  401. loadAreaFirstChunk = (u32)addr_to_chunk(itLpNaca.xLoadAreaAddr);
  402. loadAreaSize = itLpNaca.xLoadAreaChunks;
  403. /*
  404. * Only add the pages already mapped here.
  405. * Otherwise we might add the hpt pages
  406. * The rest of the pages of the load area
  407. * aren't in the HPT yet and can still
  408. * be assigned an arbitrary physical address
  409. */
  410. if ((loadAreaSize * 64) > HvPagesToMap)
  411. loadAreaSize = HvPagesToMap / 64;
  412. loadAreaLastChunk = loadAreaFirstChunk + loadAreaSize - 1;
  413. /*
  414. * TODO Do we need to do something if the HPT is in the 64MB load area?
  415. * This would be required if the itLpNaca.xLoadAreaChunks includes
  416. * the HPT size
  417. */
  418. printk("Mapping load area - physical addr = 0000000000000000\n"
  419. " absolute addr = %016lx\n",
  420. chunk_to_addr(loadAreaFirstChunk));
  421. printk("Load area size %dK\n", loadAreaSize * 256);
  422. for (nextPhysChunk = 0; nextPhysChunk < loadAreaSize; ++nextPhysChunk)
  423. msChunks.abs[nextPhysChunk] =
  424. loadAreaFirstChunk + nextPhysChunk;
  425. /*
  426. * Get absolute address of our HPT and remember it so
  427. * we won't map it to any physical address
  428. */
  429. hptFirstChunk = (u32)addr_to_chunk(HvCallHpt_getHptAddress());
  430. hptSizePages = (u32)HvCallHpt_getHptPages();
  431. hptSizeChunks = hptSizePages >> (msChunks.chunk_shift - PAGE_SHIFT);
  432. hptLastChunk = hptFirstChunk + hptSizeChunks - 1;
  433. printk("HPT absolute addr = %016lx, size = %dK\n",
  434. chunk_to_addr(hptFirstChunk), hptSizeChunks * 256);
  435. /* Fill in the hashed page table hash mask */
  436. num_ptegs = hptSizePages *
  437. (PAGE_SIZE / (sizeof(HPTE) * HPTES_PER_GROUP));
  438. htab_hash_mask = num_ptegs - 1;
  439. /*
  440. * The actual hashed page table is in the hypervisor,
  441. * we have no direct access
  442. */
  443. htab_address = NULL;
  444. /*
  445. * Determine if absolute memory has any
  446. * holes so that we can interpret the
  447. * access map we get back from the hypervisor
  448. * correctly.
  449. */
  450. numMemoryBlocks = iSeries_process_mainstore_vpd(mb, 32);
  451. /*
  452. * Process the main store access map from the hypervisor
  453. * to build up our physical -> absolute translation table
  454. */
  455. curBlock = 0;
  456. currChunk = 0;
  457. currDword = 0;
  458. moreChunks = totalChunks;
  459. while (moreChunks) {
  460. map = HvCallSm_get64BitsOfAccessMap(itLpNaca.xLpIndex,
  461. currDword);
  462. thisChunk = currChunk;
  463. while (map) {
  464. chunkBit = map >> 63;
  465. map <<= 1;
  466. if (chunkBit) {
  467. --moreChunks;
  468. while (thisChunk >= mb[curBlock].logicalEnd) {
  469. ++curBlock;
  470. if (curBlock >= numMemoryBlocks)
  471. panic("out of memory blocks");
  472. }
  473. if (thisChunk < mb[curBlock].logicalStart)
  474. panic("memory block error");
  475. absChunk = mb[curBlock].absStart +
  476. (thisChunk - mb[curBlock].logicalStart);
  477. if (((absChunk < hptFirstChunk) ||
  478. (absChunk > hptLastChunk)) &&
  479. ((absChunk < loadAreaFirstChunk) ||
  480. (absChunk > loadAreaLastChunk))) {
  481. msChunks.abs[nextPhysChunk] = absChunk;
  482. ++nextPhysChunk;
  483. }
  484. }
  485. ++thisChunk;
  486. }
  487. ++currDword;
  488. currChunk += 64;
  489. }
  490. /*
  491. * main store size (in chunks) is
  492. * totalChunks - hptSizeChunks
  493. * which should be equal to
  494. * nextPhysChunk
  495. */
  496. systemcfg->physicalMemorySize = chunk_to_addr(nextPhysChunk);
  497. }
  498. /*
  499. * Set up the variables that describe the cache line sizes
  500. * for this machine.
  501. */
  502. static void __init setup_iSeries_cache_sizes(void)
  503. {
  504. unsigned int i, n;
  505. unsigned int procIx = get_paca()->lppaca.dyn_hv_phys_proc_index;
  506. systemcfg->icache_size =
  507. ppc64_caches.isize = xIoHriProcessorVpd[procIx].xInstCacheSize * 1024;
  508. systemcfg->icache_line_size =
  509. ppc64_caches.iline_size =
  510. xIoHriProcessorVpd[procIx].xInstCacheOperandSize;
  511. systemcfg->dcache_size =
  512. ppc64_caches.dsize =
  513. xIoHriProcessorVpd[procIx].xDataL1CacheSizeKB * 1024;
  514. systemcfg->dcache_line_size =
  515. ppc64_caches.dline_size =
  516. xIoHriProcessorVpd[procIx].xDataCacheOperandSize;
  517. ppc64_caches.ilines_per_page = PAGE_SIZE / ppc64_caches.iline_size;
  518. ppc64_caches.dlines_per_page = PAGE_SIZE / ppc64_caches.dline_size;
  519. i = ppc64_caches.iline_size;
  520. n = 0;
  521. while ((i = (i / 2)))
  522. ++n;
  523. ppc64_caches.log_iline_size = n;
  524. i = ppc64_caches.dline_size;
  525. n = 0;
  526. while ((i = (i / 2)))
  527. ++n;
  528. ppc64_caches.log_dline_size = n;
  529. printk("D-cache line size = %d\n",
  530. (unsigned int)ppc64_caches.dline_size);
  531. printk("I-cache line size = %d\n",
  532. (unsigned int)ppc64_caches.iline_size);
  533. }
  534. /*
  535. * Create a pte. Used during initialization only.
  536. */
  537. static void iSeries_make_pte(unsigned long va, unsigned long pa,
  538. int mode)
  539. {
  540. HPTE local_hpte, rhpte;
  541. unsigned long hash, vpn;
  542. long slot;
  543. vpn = va >> PAGE_SHIFT;
  544. hash = hpt_hash(vpn, 0);
  545. local_hpte.dw1.dword1 = pa | mode;
  546. local_hpte.dw0.dword0 = 0;
  547. local_hpte.dw0.dw0.avpn = va >> 23;
  548. local_hpte.dw0.dw0.bolted = 1; /* bolted */
  549. local_hpte.dw0.dw0.v = 1;
  550. slot = HvCallHpt_findValid(&rhpte, vpn);
  551. if (slot < 0) {
  552. /* Must find space in primary group */
  553. panic("hash_page: hpte already exists\n");
  554. }
  555. HvCallHpt_addValidate(slot, 0, (HPTE *)&local_hpte );
  556. }
  557. /*
  558. * Bolt the kernel addr space into the HPT
  559. */
  560. static void __init iSeries_bolt_kernel(unsigned long saddr, unsigned long eaddr)
  561. {
  562. unsigned long pa;
  563. unsigned long mode_rw = _PAGE_ACCESSED | _PAGE_COHERENT | PP_RWXX;
  564. HPTE hpte;
  565. for (pa = saddr; pa < eaddr ;pa += PAGE_SIZE) {
  566. unsigned long ea = (unsigned long)__va(pa);
  567. unsigned long vsid = get_kernel_vsid(ea);
  568. unsigned long va = (vsid << 28) | (pa & 0xfffffff);
  569. unsigned long vpn = va >> PAGE_SHIFT;
  570. unsigned long slot = HvCallHpt_findValid(&hpte, vpn);
  571. /* Make non-kernel text non-executable */
  572. if (!in_kernel_text(ea))
  573. mode_rw |= HW_NO_EXEC;
  574. if (hpte.dw0.dw0.v) {
  575. /* HPTE exists, so just bolt it */
  576. HvCallHpt_setSwBits(slot, 0x10, 0);
  577. /* And make sure the pp bits are correct */
  578. HvCallHpt_setPp(slot, PP_RWXX);
  579. } else
  580. /* No HPTE exists, so create a new bolted one */
  581. iSeries_make_pte(va, phys_to_abs(pa), mode_rw);
  582. }
  583. }
  584. /*
  585. * Document me.
  586. */
  587. static void __init iSeries_setup_arch(void)
  588. {
  589. void *eventStack;
  590. unsigned procIx = get_paca()->lppaca.dyn_hv_phys_proc_index;
  591. /* Add an eye catcher and the systemcfg layout version number */
  592. strcpy(systemcfg->eye_catcher, "SYSTEMCFG:PPC64");
  593. systemcfg->version.major = SYSTEMCFG_MAJOR;
  594. systemcfg->version.minor = SYSTEMCFG_MINOR;
  595. /* Setup the Lp Event Queue */
  596. /* Allocate a page for the Event Stack
  597. * The hypervisor wants the absolute real address, so
  598. * we subtract out the KERNELBASE and add in the
  599. * absolute real address of the kernel load area
  600. */
  601. eventStack = alloc_bootmem_pages(LpEventStackSize);
  602. memset(eventStack, 0, LpEventStackSize);
  603. /* Invoke the hypervisor to initialize the event stack */
  604. HvCallEvent_setLpEventStack(0, eventStack, LpEventStackSize);
  605. /* Initialize fields in our Lp Event Queue */
  606. xItLpQueue.xSlicEventStackPtr = (char *)eventStack;
  607. xItLpQueue.xSlicCurEventPtr = (char *)eventStack;
  608. xItLpQueue.xSlicLastValidEventPtr = (char *)eventStack +
  609. (LpEventStackSize - LpEventMaxSize);
  610. xItLpQueue.xIndex = 0;
  611. /* Compute processor frequency */
  612. procFreqHz = ((1UL << 34) * 1000000) /
  613. xIoHriProcessorVpd[procIx].xProcFreq;
  614. procFreqMhz = procFreqHz / 1000000;
  615. procFreqMhzHundreths = (procFreqHz / 10000) - (procFreqMhz * 100);
  616. ppc_proc_freq = procFreqHz;
  617. /* Compute time base frequency */
  618. tbFreqHz = ((1UL << 32) * 1000000) /
  619. xIoHriProcessorVpd[procIx].xTimeBaseFreq;
  620. tbFreqMhz = tbFreqHz / 1000000;
  621. tbFreqMhzHundreths = (tbFreqHz / 10000) - (tbFreqMhz * 100);
  622. ppc_tb_freq = tbFreqHz;
  623. printk("Max logical processors = %d\n",
  624. itVpdAreas.xSlicMaxLogicalProcs);
  625. printk("Max physical processors = %d\n",
  626. itVpdAreas.xSlicMaxPhysicalProcs);
  627. printk("Processor frequency = %lu.%02lu\n", procFreqMhz,
  628. procFreqMhzHundreths);
  629. printk("Time base frequency = %lu.%02lu\n", tbFreqMhz,
  630. tbFreqMhzHundreths);
  631. systemcfg->processor = xIoHriProcessorVpd[procIx].xPVR;
  632. printk("Processor version = %x\n", systemcfg->processor);
  633. }
  634. static void iSeries_get_cpuinfo(struct seq_file *m)
  635. {
  636. seq_printf(m, "machine\t\t: 64-bit iSeries Logical Partition\n");
  637. }
  638. /*
  639. * Document me.
  640. * and Implement me.
  641. */
  642. static int iSeries_get_irq(struct pt_regs *regs)
  643. {
  644. /* -2 means ignore this interrupt */
  645. return -2;
  646. }
  647. /*
  648. * Document me.
  649. */
  650. static void iSeries_restart(char *cmd)
  651. {
  652. mf_reboot();
  653. }
  654. /*
  655. * Document me.
  656. */
  657. static void iSeries_power_off(void)
  658. {
  659. mf_power_off();
  660. }
  661. /*
  662. * Document me.
  663. */
  664. static void iSeries_halt(void)
  665. {
  666. mf_power_off();
  667. }
  668. /*
  669. * void __init iSeries_calibrate_decr()
  670. *
  671. * Description:
  672. * This routine retrieves the internal processor frequency from the VPD,
  673. * and sets up the kernel timer decrementer based on that value.
  674. *
  675. */
  676. static void __init iSeries_calibrate_decr(void)
  677. {
  678. unsigned long cyclesPerUsec;
  679. struct div_result divres;
  680. /* Compute decrementer (and TB) frequency in cycles/sec */
  681. cyclesPerUsec = ppc_tb_freq / 1000000;
  682. /*
  683. * Set the amount to refresh the decrementer by. This
  684. * is the number of decrementer ticks it takes for
  685. * 1/HZ seconds.
  686. */
  687. tb_ticks_per_jiffy = ppc_tb_freq / HZ;
  688. #if 0
  689. /* TEST CODE FOR ADJTIME */
  690. tb_ticks_per_jiffy += tb_ticks_per_jiffy / 5000;
  691. /* END OF TEST CODE */
  692. #endif
  693. /*
  694. * tb_ticks_per_sec = freq; would give better accuracy
  695. * but tb_ticks_per_sec = tb_ticks_per_jiffy*HZ; assures
  696. * that jiffies (and xtime) will match the time returned
  697. * by do_gettimeofday.
  698. */
  699. tb_ticks_per_sec = tb_ticks_per_jiffy * HZ;
  700. tb_ticks_per_usec = cyclesPerUsec;
  701. tb_to_us = mulhwu_scale_factor(ppc_tb_freq, 1000000);
  702. div128_by_32(1024 * 1024, 0, tb_ticks_per_sec, &divres);
  703. tb_to_xs = divres.result_low;
  704. setup_default_decr();
  705. }
  706. static void __init iSeries_progress(char * st, unsigned short code)
  707. {
  708. printk("Progress: [%04x] - %s\n", (unsigned)code, st);
  709. if (!piranha_simulator && mf_initialized) {
  710. if (code != 0xffff)
  711. mf_display_progress(code);
  712. else
  713. mf_clear_src();
  714. }
  715. }
  716. static void __init iSeries_fixup_klimit(void)
  717. {
  718. /*
  719. * Change klimit to take into account any ram disk
  720. * that may be included
  721. */
  722. if (naca.xRamDisk)
  723. klimit = KERNELBASE + (u64)naca.xRamDisk +
  724. (naca.xRamDiskSize * PAGE_SIZE);
  725. else {
  726. /*
  727. * No ram disk was included - check and see if there
  728. * was an embedded system map. Change klimit to take
  729. * into account any embedded system map
  730. */
  731. if (embedded_sysmap_end)
  732. klimit = KERNELBASE + ((embedded_sysmap_end + 4095) &
  733. 0xfffffffffffff000);
  734. }
  735. }
  736. static int __init iSeries_src_init(void)
  737. {
  738. /* clear the progress line */
  739. ppc_md.progress(" ", 0xffff);
  740. return 0;
  741. }
  742. late_initcall(iSeries_src_init);
  743. static int set_spread_lpevents(char *str)
  744. {
  745. unsigned long val = simple_strtoul(str, NULL, 0);
  746. extern unsigned long spread_lpevents;
  747. /*
  748. * The parameter is the number of processors to share in processing
  749. * lp events.
  750. */
  751. if (( val > 0) && (val <= NR_CPUS)) {
  752. spread_lpevents = val;
  753. printk("lpevent processing spread over %ld processors\n", val);
  754. } else {
  755. printk("invalid spread_lpevents %ld\n", val);
  756. }
  757. return 1;
  758. }
  759. __setup("spread_lpevents=", set_spread_lpevents);
  760. #ifndef CONFIG_PCI
  761. void __init iSeries_init_IRQ(void) { }
  762. #endif
  763. void __init iSeries_early_setup(void)
  764. {
  765. iSeries_fixup_klimit();
  766. ppc_md.setup_arch = iSeries_setup_arch;
  767. ppc_md.get_cpuinfo = iSeries_get_cpuinfo;
  768. ppc_md.init_IRQ = iSeries_init_IRQ;
  769. ppc_md.get_irq = iSeries_get_irq;
  770. ppc_md.init_early = iSeries_init_early,
  771. ppc_md.pcibios_fixup = iSeries_pci_final_fixup;
  772. ppc_md.restart = iSeries_restart;
  773. ppc_md.power_off = iSeries_power_off;
  774. ppc_md.halt = iSeries_halt;
  775. ppc_md.get_boot_time = iSeries_get_boot_time;
  776. ppc_md.set_rtc_time = iSeries_set_rtc_time;
  777. ppc_md.get_rtc_time = iSeries_get_rtc_time;
  778. ppc_md.calibrate_decr = iSeries_calibrate_decr;
  779. ppc_md.progress = iSeries_progress;
  780. }