setup.c 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005
  1. /*
  2. * Copyright (c) 2000 Mike Corrigan <mikejc@us.ibm.com>
  3. * Copyright (c) 1999-2000 Grant Erickson <grant@lcse.umn.edu>
  4. *
  5. * Description:
  6. * Architecture- / platform-specific boot-time initialization code for
  7. * the IBM iSeries LPAR. Adapted from original code by Grant Erickson and
  8. * code by Gary Thomas, Cort Dougan <cort@fsmlabs.com>, and Dan Malek
  9. * <dan@net4x.com>.
  10. *
  11. * This program is free software; you can redistribute it and/or
  12. * modify it under the terms of the GNU General Public License
  13. * as published by the Free Software Foundation; either version
  14. * 2 of the License, or (at your option) any later version.
  15. */
  16. #undef DEBUG
  17. #include <linux/config.h>
  18. #include <linux/init.h>
  19. #include <linux/threads.h>
  20. #include <linux/smp.h>
  21. #include <linux/param.h>
  22. #include <linux/string.h>
  23. #include <linux/initrd.h>
  24. #include <linux/seq_file.h>
  25. #include <linux/kdev_t.h>
  26. #include <linux/major.h>
  27. #include <linux/root_dev.h>
  28. #include <linux/kernel.h>
  29. #include <asm/processor.h>
  30. #include <asm/machdep.h>
  31. #include <asm/page.h>
  32. #include <asm/mmu.h>
  33. #include <asm/pgtable.h>
  34. #include <asm/mmu_context.h>
  35. #include <asm/cputable.h>
  36. #include <asm/sections.h>
  37. #include <asm/iommu.h>
  38. #include <asm/firmware.h>
  39. #include <asm/time.h>
  40. #include <asm/paca.h>
  41. #include <asm/cache.h>
  42. #include <asm/sections.h>
  43. #include <asm/abs_addr.h>
  44. #include <asm/iseries/hv_lp_config.h>
  45. #include <asm/iseries/hv_call_event.h>
  46. #include <asm/iseries/hv_call_xm.h>
  47. #include <asm/iseries/it_lp_queue.h>
  48. #include <asm/iseries/mf.h>
  49. #include <asm/iseries/hv_lp_event.h>
  50. #include <asm/iseries/lpar_map.h>
  51. #include "naca.h"
  52. #include "setup.h"
  53. #include "irq.h"
  54. #include "vpd_areas.h"
  55. #include "processor_vpd.h"
  56. #include "main_store.h"
  57. #include "call_sm.h"
  58. #include "call_hpt.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 iseries_shared_idle(void);
  69. static void iseries_dedicated_idle(void);
  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. int piranha_simulator;
  77. extern int rd_size; /* Defined in drivers/block/rd.c */
  78. extern unsigned long klimit;
  79. extern unsigned long embedded_sysmap_start;
  80. extern unsigned long embedded_sysmap_end;
  81. extern unsigned long iSeries_recal_tb;
  82. extern unsigned long iSeries_recal_titan;
  83. static int mf_initialized;
  84. static unsigned long cmd_mem_limit;
  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. DBG(" -> iSeries_init_early()\n");
  271. ppc64_firmware_features = FW_FEATURE_ISERIES;
  272. ppcdbg_initialize();
  273. ppc64_interrupt_controller = IC_ISERIES;
  274. #if defined(CONFIG_BLK_DEV_INITRD)
  275. /*
  276. * If the init RAM disk has been configured and there is
  277. * a non-zero starting address for it, set it up
  278. */
  279. if (naca.xRamDisk) {
  280. initrd_start = (unsigned long)__va(naca.xRamDisk);
  281. initrd_end = initrd_start + naca.xRamDiskSize * HW_PAGE_SIZE;
  282. initrd_below_start_ok = 1; // ramdisk in kernel space
  283. ROOT_DEV = Root_RAM0;
  284. if (((rd_size * 1024) / HW_PAGE_SIZE) < naca.xRamDiskSize)
  285. rd_size = (naca.xRamDiskSize * HW_PAGE_SIZE) / 1024;
  286. } else
  287. #endif /* CONFIG_BLK_DEV_INITRD */
  288. {
  289. /* ROOT_DEV = MKDEV(VIODASD_MAJOR, 1); */
  290. }
  291. iSeries_recal_tb = get_tb();
  292. iSeries_recal_titan = HvCallXm_loadTod();
  293. /*
  294. * Initialize the hash table management pointers
  295. */
  296. hpte_init_iSeries();
  297. /*
  298. * Initialize the DMA/TCE management
  299. */
  300. iommu_init_early_iSeries();
  301. /* Initialize machine-dependency vectors */
  302. #ifdef CONFIG_SMP
  303. smp_init_iSeries();
  304. #endif
  305. if (itLpNaca.xPirEnvironMode == 0)
  306. piranha_simulator = 1;
  307. /* Associate Lp Event Queue 0 with processor 0 */
  308. HvCallEvent_setLpEventQueueInterruptProc(0, 0);
  309. mf_init();
  310. mf_initialized = 1;
  311. mb();
  312. /* If we were passed an initrd, set the ROOT_DEV properly if the values
  313. * look sensible. If not, clear initrd reference.
  314. */
  315. #ifdef CONFIG_BLK_DEV_INITRD
  316. if (initrd_start >= KERNELBASE && initrd_end >= KERNELBASE &&
  317. initrd_end > initrd_start)
  318. ROOT_DEV = Root_RAM0;
  319. else
  320. initrd_start = initrd_end = 0;
  321. #endif /* CONFIG_BLK_DEV_INITRD */
  322. DBG(" <- iSeries_init_early()\n");
  323. }
  324. struct mschunks_map mschunks_map = {
  325. /* XXX We don't use these, but Piranha might need them. */
  326. .chunk_size = MSCHUNKS_CHUNK_SIZE,
  327. .chunk_shift = MSCHUNKS_CHUNK_SHIFT,
  328. .chunk_mask = MSCHUNKS_OFFSET_MASK,
  329. };
  330. EXPORT_SYMBOL(mschunks_map);
  331. void mschunks_alloc(unsigned long num_chunks)
  332. {
  333. klimit = _ALIGN(klimit, sizeof(u32));
  334. mschunks_map.mapping = (u32 *)klimit;
  335. klimit += num_chunks * sizeof(u32);
  336. mschunks_map.num_chunks = num_chunks;
  337. }
  338. /*
  339. * The iSeries may have very large memories ( > 128 GB ) and a partition
  340. * may get memory in "chunks" that may be anywhere in the 2**52 real
  341. * address space. The chunks are 256K in size. To map this to the
  342. * memory model Linux expects, the AS/400 specific code builds a
  343. * translation table to translate what Linux thinks are "physical"
  344. * addresses to the actual real addresses. This allows us to make
  345. * it appear to Linux that we have contiguous memory starting at
  346. * physical address zero while in fact this could be far from the truth.
  347. * To avoid confusion, I'll let the words physical and/or real address
  348. * apply to the Linux addresses while I'll use "absolute address" to
  349. * refer to the actual hardware real address.
  350. *
  351. * build_iSeries_Memory_Map gets information from the Hypervisor and
  352. * looks at the Main Store VPD to determine the absolute addresses
  353. * of the memory that has been assigned to our partition and builds
  354. * a table used to translate Linux's physical addresses to these
  355. * absolute addresses. Absolute addresses are needed when
  356. * communicating with the hypervisor (e.g. to build HPT entries)
  357. */
  358. static void __init build_iSeries_Memory_Map(void)
  359. {
  360. u32 loadAreaFirstChunk, loadAreaLastChunk, loadAreaSize;
  361. u32 nextPhysChunk;
  362. u32 hptFirstChunk, hptLastChunk, hptSizeChunks, hptSizePages;
  363. u32 totalChunks,moreChunks;
  364. u32 currChunk, thisChunk, absChunk;
  365. u32 currDword;
  366. u32 chunkBit;
  367. u64 map;
  368. struct MemoryBlock mb[32];
  369. unsigned long numMemoryBlocks, curBlock;
  370. /* Chunk size on iSeries is 256K bytes */
  371. totalChunks = (u32)HvLpConfig_getMsChunks();
  372. mschunks_alloc(totalChunks);
  373. /*
  374. * Get absolute address of our load area
  375. * and map it to physical address 0
  376. * This guarantees that the loadarea ends up at physical 0
  377. * otherwise, it might not be returned by PLIC as the first
  378. * chunks
  379. */
  380. loadAreaFirstChunk = (u32)addr_to_chunk(itLpNaca.xLoadAreaAddr);
  381. loadAreaSize = itLpNaca.xLoadAreaChunks;
  382. /*
  383. * Only add the pages already mapped here.
  384. * Otherwise we might add the hpt pages
  385. * The rest of the pages of the load area
  386. * aren't in the HPT yet and can still
  387. * be assigned an arbitrary physical address
  388. */
  389. if ((loadAreaSize * 64) > HvPagesToMap)
  390. loadAreaSize = HvPagesToMap / 64;
  391. loadAreaLastChunk = loadAreaFirstChunk + loadAreaSize - 1;
  392. /*
  393. * TODO Do we need to do something if the HPT is in the 64MB load area?
  394. * This would be required if the itLpNaca.xLoadAreaChunks includes
  395. * the HPT size
  396. */
  397. printk("Mapping load area - physical addr = 0000000000000000\n"
  398. " absolute addr = %016lx\n",
  399. chunk_to_addr(loadAreaFirstChunk));
  400. printk("Load area size %dK\n", loadAreaSize * 256);
  401. for (nextPhysChunk = 0; nextPhysChunk < loadAreaSize; ++nextPhysChunk)
  402. mschunks_map.mapping[nextPhysChunk] =
  403. loadAreaFirstChunk + nextPhysChunk;
  404. /*
  405. * Get absolute address of our HPT and remember it so
  406. * we won't map it to any physical address
  407. */
  408. hptFirstChunk = (u32)addr_to_chunk(HvCallHpt_getHptAddress());
  409. hptSizePages = (u32)HvCallHpt_getHptPages();
  410. hptSizeChunks = hptSizePages >>
  411. (MSCHUNKS_CHUNK_SHIFT - HW_PAGE_SHIFT);
  412. hptLastChunk = hptFirstChunk + hptSizeChunks - 1;
  413. printk("HPT absolute addr = %016lx, size = %dK\n",
  414. chunk_to_addr(hptFirstChunk), hptSizeChunks * 256);
  415. ppc64_pft_size = __ilog2(hptSizePages * HW_PAGE_SIZE);
  416. /*
  417. * The actual hashed page table is in the hypervisor,
  418. * we have no direct access
  419. */
  420. htab_address = NULL;
  421. /*
  422. * Determine if absolute memory has any
  423. * holes so that we can interpret the
  424. * access map we get back from the hypervisor
  425. * correctly.
  426. */
  427. numMemoryBlocks = iSeries_process_mainstore_vpd(mb, 32);
  428. /*
  429. * Process the main store access map from the hypervisor
  430. * to build up our physical -> absolute translation table
  431. */
  432. curBlock = 0;
  433. currChunk = 0;
  434. currDword = 0;
  435. moreChunks = totalChunks;
  436. while (moreChunks) {
  437. map = HvCallSm_get64BitsOfAccessMap(itLpNaca.xLpIndex,
  438. currDword);
  439. thisChunk = currChunk;
  440. while (map) {
  441. chunkBit = map >> 63;
  442. map <<= 1;
  443. if (chunkBit) {
  444. --moreChunks;
  445. while (thisChunk >= mb[curBlock].logicalEnd) {
  446. ++curBlock;
  447. if (curBlock >= numMemoryBlocks)
  448. panic("out of memory blocks");
  449. }
  450. if (thisChunk < mb[curBlock].logicalStart)
  451. panic("memory block error");
  452. absChunk = mb[curBlock].absStart +
  453. (thisChunk - mb[curBlock].logicalStart);
  454. if (((absChunk < hptFirstChunk) ||
  455. (absChunk > hptLastChunk)) &&
  456. ((absChunk < loadAreaFirstChunk) ||
  457. (absChunk > loadAreaLastChunk))) {
  458. mschunks_map.mapping[nextPhysChunk] =
  459. absChunk;
  460. ++nextPhysChunk;
  461. }
  462. }
  463. ++thisChunk;
  464. }
  465. ++currDword;
  466. currChunk += 64;
  467. }
  468. /*
  469. * main store size (in chunks) is
  470. * totalChunks - hptSizeChunks
  471. * which should be equal to
  472. * nextPhysChunk
  473. */
  474. systemcfg->physicalMemorySize = chunk_to_addr(nextPhysChunk);
  475. }
  476. /*
  477. * Document me.
  478. */
  479. static void __init iSeries_setup_arch(void)
  480. {
  481. unsigned procIx = get_paca()->lppaca.dyn_hv_phys_proc_index;
  482. if (get_paca()->lppaca.shared_proc) {
  483. ppc_md.idle_loop = iseries_shared_idle;
  484. printk(KERN_INFO "Using shared processor idle loop\n");
  485. } else {
  486. ppc_md.idle_loop = iseries_dedicated_idle;
  487. printk(KERN_INFO "Using dedicated idle loop\n");
  488. }
  489. /* Setup the Lp Event Queue */
  490. setup_hvlpevent_queue();
  491. printk("Max logical processors = %d\n",
  492. itVpdAreas.xSlicMaxLogicalProcs);
  493. printk("Max physical processors = %d\n",
  494. itVpdAreas.xSlicMaxPhysicalProcs);
  495. systemcfg->processor = xIoHriProcessorVpd[procIx].xPVR;
  496. printk("Processor version = %x\n", systemcfg->processor);
  497. }
  498. static void iSeries_show_cpuinfo(struct seq_file *m)
  499. {
  500. seq_printf(m, "machine\t\t: 64-bit iSeries Logical Partition\n");
  501. }
  502. /*
  503. * Document me.
  504. * and Implement me.
  505. */
  506. static int iSeries_get_irq(struct pt_regs *regs)
  507. {
  508. /* -2 means ignore this interrupt */
  509. return -2;
  510. }
  511. /*
  512. * Document me.
  513. */
  514. static void iSeries_restart(char *cmd)
  515. {
  516. mf_reboot();
  517. }
  518. /*
  519. * Document me.
  520. */
  521. static void iSeries_power_off(void)
  522. {
  523. mf_power_off();
  524. }
  525. /*
  526. * Document me.
  527. */
  528. static void iSeries_halt(void)
  529. {
  530. mf_power_off();
  531. }
  532. static void __init iSeries_progress(char * st, unsigned short code)
  533. {
  534. printk("Progress: [%04x] - %s\n", (unsigned)code, st);
  535. if (!piranha_simulator && mf_initialized) {
  536. if (code != 0xffff)
  537. mf_display_progress(code);
  538. else
  539. mf_clear_src();
  540. }
  541. }
  542. static void __init iSeries_fixup_klimit(void)
  543. {
  544. /*
  545. * Change klimit to take into account any ram disk
  546. * that may be included
  547. */
  548. if (naca.xRamDisk)
  549. klimit = KERNELBASE + (u64)naca.xRamDisk +
  550. (naca.xRamDiskSize * HW_PAGE_SIZE);
  551. else {
  552. /*
  553. * No ram disk was included - check and see if there
  554. * was an embedded system map. Change klimit to take
  555. * into account any embedded system map
  556. */
  557. if (embedded_sysmap_end)
  558. klimit = KERNELBASE + ((embedded_sysmap_end + 4095) &
  559. 0xfffffffffffff000);
  560. }
  561. }
  562. static int __init iSeries_src_init(void)
  563. {
  564. /* clear the progress line */
  565. ppc_md.progress(" ", 0xffff);
  566. return 0;
  567. }
  568. late_initcall(iSeries_src_init);
  569. static inline void process_iSeries_events(void)
  570. {
  571. asm volatile ("li 0,0x5555; sc" : : : "r0", "r3");
  572. }
  573. static void yield_shared_processor(void)
  574. {
  575. unsigned long tb;
  576. HvCall_setEnabledInterrupts(HvCall_MaskIPI |
  577. HvCall_MaskLpEvent |
  578. HvCall_MaskLpProd |
  579. HvCall_MaskTimeout);
  580. tb = get_tb();
  581. /* Compute future tb value when yield should expire */
  582. HvCall_yieldProcessor(HvCall_YieldTimed, tb+tb_ticks_per_jiffy);
  583. /*
  584. * The decrementer stops during the yield. Force a fake decrementer
  585. * here and let the timer_interrupt code sort out the actual time.
  586. */
  587. get_paca()->lppaca.int_dword.fields.decr_int = 1;
  588. process_iSeries_events();
  589. }
  590. static void iseries_shared_idle(void)
  591. {
  592. while (1) {
  593. while (!need_resched() && !hvlpevent_is_pending()) {
  594. local_irq_disable();
  595. ppc64_runlatch_off();
  596. /* Recheck with irqs off */
  597. if (!need_resched() && !hvlpevent_is_pending())
  598. yield_shared_processor();
  599. HMT_medium();
  600. local_irq_enable();
  601. }
  602. ppc64_runlatch_on();
  603. if (hvlpevent_is_pending())
  604. process_iSeries_events();
  605. schedule();
  606. }
  607. }
  608. static void iseries_dedicated_idle(void)
  609. {
  610. long oldval;
  611. while (1) {
  612. oldval = test_and_clear_thread_flag(TIF_NEED_RESCHED);
  613. if (!oldval) {
  614. set_thread_flag(TIF_POLLING_NRFLAG);
  615. while (!need_resched()) {
  616. ppc64_runlatch_off();
  617. HMT_low();
  618. if (hvlpevent_is_pending()) {
  619. HMT_medium();
  620. ppc64_runlatch_on();
  621. process_iSeries_events();
  622. }
  623. }
  624. HMT_medium();
  625. clear_thread_flag(TIF_POLLING_NRFLAG);
  626. } else {
  627. set_need_resched();
  628. }
  629. ppc64_runlatch_on();
  630. schedule();
  631. }
  632. }
  633. #ifndef CONFIG_PCI
  634. void __init iSeries_init_IRQ(void) { }
  635. #endif
  636. static int __init iseries_probe(int platform)
  637. {
  638. return PLATFORM_ISERIES_LPAR == platform;
  639. }
  640. struct machdep_calls __initdata iseries_md = {
  641. .setup_arch = iSeries_setup_arch,
  642. .show_cpuinfo = iSeries_show_cpuinfo,
  643. .init_IRQ = iSeries_init_IRQ,
  644. .get_irq = iSeries_get_irq,
  645. .init_early = iSeries_init_early,
  646. .pcibios_fixup = iSeries_pci_final_fixup,
  647. .restart = iSeries_restart,
  648. .power_off = iSeries_power_off,
  649. .halt = iSeries_halt,
  650. .get_boot_time = iSeries_get_boot_time,
  651. .set_rtc_time = iSeries_set_rtc_time,
  652. .get_rtc_time = iSeries_get_rtc_time,
  653. .calibrate_decr = generic_calibrate_decr,
  654. .progress = iSeries_progress,
  655. .probe = iseries_probe,
  656. /* XXX Implement enable_pmcs for iSeries */
  657. };
  658. struct blob {
  659. unsigned char data[PAGE_SIZE];
  660. unsigned long next;
  661. };
  662. struct iseries_flat_dt {
  663. struct boot_param_header header;
  664. u64 reserve_map[2];
  665. struct blob dt;
  666. struct blob strings;
  667. };
  668. struct iseries_flat_dt iseries_dt;
  669. void dt_init(struct iseries_flat_dt *dt)
  670. {
  671. dt->header.off_mem_rsvmap =
  672. offsetof(struct iseries_flat_dt, reserve_map);
  673. dt->header.off_dt_struct = offsetof(struct iseries_flat_dt, dt);
  674. dt->header.off_dt_strings = offsetof(struct iseries_flat_dt, strings);
  675. dt->header.totalsize = sizeof(struct iseries_flat_dt);
  676. dt->header.dt_strings_size = sizeof(struct blob);
  677. /* There is no notion of hardware cpu id on iSeries */
  678. dt->header.boot_cpuid_phys = smp_processor_id();
  679. dt->dt.next = (unsigned long)&dt->dt.data;
  680. dt->strings.next = (unsigned long)&dt->strings.data;
  681. dt->header.magic = OF_DT_HEADER;
  682. dt->header.version = 0x10;
  683. dt->header.last_comp_version = 0x10;
  684. dt->reserve_map[0] = 0;
  685. dt->reserve_map[1] = 0;
  686. }
  687. void dt_check_blob(struct blob *b)
  688. {
  689. if (b->next >= (unsigned long)&b->next) {
  690. DBG("Ran out of space in flat device tree blob!\n");
  691. BUG();
  692. }
  693. }
  694. void dt_push_u32(struct iseries_flat_dt *dt, u32 value)
  695. {
  696. *((u32*)dt->dt.next) = value;
  697. dt->dt.next += sizeof(u32);
  698. dt_check_blob(&dt->dt);
  699. }
  700. void dt_push_u64(struct iseries_flat_dt *dt, u64 value)
  701. {
  702. *((u64*)dt->dt.next) = value;
  703. dt->dt.next += sizeof(u64);
  704. dt_check_blob(&dt->dt);
  705. }
  706. unsigned long dt_push_bytes(struct blob *blob, char *data, int len)
  707. {
  708. unsigned long start = blob->next - (unsigned long)blob->data;
  709. memcpy((char *)blob->next, data, len);
  710. blob->next = _ALIGN(blob->next + len, 4);
  711. dt_check_blob(blob);
  712. return start;
  713. }
  714. void dt_start_node(struct iseries_flat_dt *dt, char *name)
  715. {
  716. dt_push_u32(dt, OF_DT_BEGIN_NODE);
  717. dt_push_bytes(&dt->dt, name, strlen(name) + 1);
  718. }
  719. #define dt_end_node(dt) dt_push_u32(dt, OF_DT_END_NODE)
  720. void dt_prop(struct iseries_flat_dt *dt, char *name, char *data, int len)
  721. {
  722. unsigned long offset;
  723. dt_push_u32(dt, OF_DT_PROP);
  724. /* Length of the data */
  725. dt_push_u32(dt, len);
  726. /* Put the property name in the string blob. */
  727. offset = dt_push_bytes(&dt->strings, name, strlen(name) + 1);
  728. /* The offset of the properties name in the string blob. */
  729. dt_push_u32(dt, (u32)offset);
  730. /* The actual data. */
  731. dt_push_bytes(&dt->dt, data, len);
  732. }
  733. void dt_prop_str(struct iseries_flat_dt *dt, char *name, char *data)
  734. {
  735. dt_prop(dt, name, data, strlen(data) + 1); /* + 1 for NULL */
  736. }
  737. void dt_prop_u32(struct iseries_flat_dt *dt, char *name, u32 data)
  738. {
  739. dt_prop(dt, name, (char *)&data, sizeof(u32));
  740. }
  741. void dt_prop_u64(struct iseries_flat_dt *dt, char *name, u64 data)
  742. {
  743. dt_prop(dt, name, (char *)&data, sizeof(u64));
  744. }
  745. void dt_prop_u64_list(struct iseries_flat_dt *dt, char *name, u64 *data, int n)
  746. {
  747. dt_prop(dt, name, (char *)data, sizeof(u64) * n);
  748. }
  749. void dt_prop_empty(struct iseries_flat_dt *dt, char *name)
  750. {
  751. dt_prop(dt, name, NULL, 0);
  752. }
  753. void dt_cpus(struct iseries_flat_dt *dt)
  754. {
  755. unsigned char buf[32];
  756. unsigned char *p;
  757. unsigned int i, index;
  758. struct IoHriProcessorVpd *d;
  759. /* yuck */
  760. snprintf(buf, 32, "PowerPC,%s", cur_cpu_spec->cpu_name);
  761. p = strchr(buf, ' ');
  762. if (!p) p = buf + strlen(buf);
  763. dt_start_node(dt, "cpus");
  764. dt_prop_u32(dt, "#address-cells", 1);
  765. dt_prop_u32(dt, "#size-cells", 0);
  766. for (i = 0; i < NR_CPUS; i++) {
  767. if (paca[i].lppaca.dyn_proc_status >= 2)
  768. continue;
  769. snprintf(p, 32 - (p - buf), "@%d", i);
  770. dt_start_node(dt, buf);
  771. dt_prop_str(dt, "device_type", "cpu");
  772. index = paca[i].lppaca.dyn_hv_phys_proc_index;
  773. d = &xIoHriProcessorVpd[index];
  774. dt_prop_u32(dt, "i-cache-size", d->xInstCacheSize * 1024);
  775. dt_prop_u32(dt, "i-cache-line-size", d->xInstCacheOperandSize);
  776. dt_prop_u32(dt, "d-cache-size", d->xDataL1CacheSizeKB * 1024);
  777. dt_prop_u32(dt, "d-cache-line-size", d->xDataCacheOperandSize);
  778. /* magic conversions to Hz copied from old code */
  779. dt_prop_u32(dt, "clock-frequency",
  780. ((1UL << 34) * 1000000) / d->xProcFreq);
  781. dt_prop_u32(dt, "timebase-frequency",
  782. ((1UL << 32) * 1000000) / d->xTimeBaseFreq);
  783. dt_prop_u32(dt, "reg", i);
  784. dt_end_node(dt);
  785. }
  786. dt_end_node(dt);
  787. }
  788. void build_flat_dt(struct iseries_flat_dt *dt)
  789. {
  790. u64 tmp[2];
  791. dt_init(dt);
  792. dt_start_node(dt, "");
  793. dt_prop_u32(dt, "#address-cells", 2);
  794. dt_prop_u32(dt, "#size-cells", 2);
  795. /* /memory */
  796. dt_start_node(dt, "memory@0");
  797. dt_prop_str(dt, "name", "memory");
  798. dt_prop_str(dt, "device_type", "memory");
  799. tmp[0] = 0;
  800. tmp[1] = systemcfg->physicalMemorySize;
  801. dt_prop_u64_list(dt, "reg", tmp, 2);
  802. dt_end_node(dt);
  803. /* /chosen */
  804. dt_start_node(dt, "chosen");
  805. dt_prop_u32(dt, "linux,platform", PLATFORM_ISERIES_LPAR);
  806. if (cmd_mem_limit)
  807. dt_prop_u64(dt, "linux,memory-limit", cmd_mem_limit);
  808. dt_end_node(dt);
  809. dt_cpus(dt);
  810. dt_end_node(dt);
  811. dt_push_u32(dt, OF_DT_END);
  812. }
  813. void * __init iSeries_early_setup(void)
  814. {
  815. iSeries_fixup_klimit();
  816. /*
  817. * Initialize the table which translate Linux physical addresses to
  818. * AS/400 absolute addresses
  819. */
  820. build_iSeries_Memory_Map();
  821. iSeries_get_cmdline();
  822. /* Save unparsed command line copy for /proc/cmdline */
  823. strlcpy(saved_command_line, cmd_line, COMMAND_LINE_SIZE);
  824. /* Parse early parameters, in particular mem=x */
  825. parse_early_param();
  826. build_flat_dt(&iseries_dt);
  827. return (void *) __pa(&iseries_dt);
  828. }
  829. /*
  830. * On iSeries we just parse the mem=X option from the command line.
  831. * On pSeries it's a bit more complicated, see prom_init_mem()
  832. */
  833. static int __init early_parsemem(char *p)
  834. {
  835. if (p)
  836. cmd_mem_limit = ALIGN(memparse(p, &p), PAGE_SIZE);
  837. return 0;
  838. }
  839. early_param("mem", early_parsemem);