iSeries_setup.c 25 KB

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