iSeries_setup.c 25 KB

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