iSeries_setup.c 23 KB

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