setup.c 28 KB

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