setup.c 33 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276
  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. #include "call_pci.h"
  66. #include "pci.h"
  67. #ifdef DEBUG
  68. #define DBG(fmt...) udbg_printf(fmt)
  69. #else
  70. #define DBG(fmt...)
  71. #endif
  72. /* Function Prototypes */
  73. static unsigned long build_iSeries_Memory_Map(void);
  74. static void iseries_shared_idle(void);
  75. static void iseries_dedicated_idle(void);
  76. #ifdef CONFIG_PCI
  77. extern void iSeries_pci_final_fixup(void);
  78. #else
  79. static void iSeries_pci_final_fixup(void) { }
  80. #endif
  81. extern int rd_size; /* Defined in drivers/block/rd.c */
  82. extern unsigned long embedded_sysmap_start;
  83. extern unsigned long embedded_sysmap_end;
  84. extern unsigned long iSeries_recal_tb;
  85. extern unsigned long iSeries_recal_titan;
  86. struct MemoryBlock {
  87. unsigned long absStart;
  88. unsigned long absEnd;
  89. unsigned long logicalStart;
  90. unsigned long logicalEnd;
  91. };
  92. /*
  93. * Process the main store vpd to determine where the holes in memory are
  94. * and return the number of physical blocks and fill in the array of
  95. * block data.
  96. */
  97. static unsigned long iSeries_process_Condor_mainstore_vpd(
  98. struct MemoryBlock *mb_array, unsigned long max_entries)
  99. {
  100. unsigned long holeFirstChunk, holeSizeChunks;
  101. unsigned long numMemoryBlocks = 1;
  102. struct IoHriMainStoreSegment4 *msVpd =
  103. (struct IoHriMainStoreSegment4 *)xMsVpd;
  104. unsigned long holeStart = msVpd->nonInterleavedBlocksStartAdr;
  105. unsigned long holeEnd = msVpd->nonInterleavedBlocksEndAdr;
  106. unsigned long holeSize = holeEnd - holeStart;
  107. printk("Mainstore_VPD: Condor\n");
  108. /*
  109. * Determine if absolute memory has any
  110. * holes so that we can interpret the
  111. * access map we get back from the hypervisor
  112. * correctly.
  113. */
  114. mb_array[0].logicalStart = 0;
  115. mb_array[0].logicalEnd = 0x100000000;
  116. mb_array[0].absStart = 0;
  117. mb_array[0].absEnd = 0x100000000;
  118. if (holeSize) {
  119. numMemoryBlocks = 2;
  120. holeStart = holeStart & 0x000fffffffffffff;
  121. holeStart = addr_to_chunk(holeStart);
  122. holeFirstChunk = holeStart;
  123. holeSize = addr_to_chunk(holeSize);
  124. holeSizeChunks = holeSize;
  125. printk( "Main store hole: start chunk = %0lx, size = %0lx chunks\n",
  126. holeFirstChunk, holeSizeChunks );
  127. mb_array[0].logicalEnd = holeFirstChunk;
  128. mb_array[0].absEnd = holeFirstChunk;
  129. mb_array[1].logicalStart = holeFirstChunk;
  130. mb_array[1].logicalEnd = 0x100000000 - holeSizeChunks;
  131. mb_array[1].absStart = holeFirstChunk + holeSizeChunks;
  132. mb_array[1].absEnd = 0x100000000;
  133. }
  134. return numMemoryBlocks;
  135. }
  136. #define MaxSegmentAreas 32
  137. #define MaxSegmentAdrRangeBlocks 128
  138. #define MaxAreaRangeBlocks 4
  139. static unsigned long iSeries_process_Regatta_mainstore_vpd(
  140. struct MemoryBlock *mb_array, unsigned long max_entries)
  141. {
  142. struct IoHriMainStoreSegment5 *msVpdP =
  143. (struct IoHriMainStoreSegment5 *)xMsVpd;
  144. unsigned long numSegmentBlocks = 0;
  145. u32 existsBits = msVpdP->msAreaExists;
  146. unsigned long area_num;
  147. printk("Mainstore_VPD: Regatta\n");
  148. for (area_num = 0; area_num < MaxSegmentAreas; ++area_num ) {
  149. unsigned long numAreaBlocks;
  150. struct IoHriMainStoreArea4 *currentArea;
  151. if (existsBits & 0x80000000) {
  152. unsigned long block_num;
  153. currentArea = &msVpdP->msAreaArray[area_num];
  154. numAreaBlocks = currentArea->numAdrRangeBlocks;
  155. printk("ms_vpd: processing area %2ld blocks=%ld",
  156. area_num, numAreaBlocks);
  157. for (block_num = 0; block_num < numAreaBlocks;
  158. ++block_num ) {
  159. /* Process an address range block */
  160. struct MemoryBlock tempBlock;
  161. unsigned long i;
  162. tempBlock.absStart =
  163. (unsigned long)currentArea->xAdrRangeBlock[block_num].blockStart;
  164. tempBlock.absEnd =
  165. (unsigned long)currentArea->xAdrRangeBlock[block_num].blockEnd;
  166. tempBlock.logicalStart = 0;
  167. tempBlock.logicalEnd = 0;
  168. printk("\n block %ld absStart=%016lx absEnd=%016lx",
  169. block_num, tempBlock.absStart,
  170. tempBlock.absEnd);
  171. for (i = 0; i < numSegmentBlocks; ++i) {
  172. if (mb_array[i].absStart ==
  173. tempBlock.absStart)
  174. break;
  175. }
  176. if (i == numSegmentBlocks) {
  177. if (numSegmentBlocks == max_entries)
  178. panic("iSeries_process_mainstore_vpd: too many memory blocks");
  179. mb_array[numSegmentBlocks] = tempBlock;
  180. ++numSegmentBlocks;
  181. } else
  182. printk(" (duplicate)");
  183. }
  184. printk("\n");
  185. }
  186. existsBits <<= 1;
  187. }
  188. /* Now sort the blocks found into ascending sequence */
  189. if (numSegmentBlocks > 1) {
  190. unsigned long m, n;
  191. for (m = 0; m < numSegmentBlocks - 1; ++m) {
  192. for (n = numSegmentBlocks - 1; m < n; --n) {
  193. if (mb_array[n].absStart <
  194. mb_array[n-1].absStart) {
  195. struct MemoryBlock tempBlock;
  196. tempBlock = mb_array[n];
  197. mb_array[n] = mb_array[n-1];
  198. mb_array[n-1] = tempBlock;
  199. }
  200. }
  201. }
  202. }
  203. /*
  204. * Assign "logical" addresses to each block. These
  205. * addresses correspond to the hypervisor "bitmap" space.
  206. * Convert all addresses into units of 256K chunks.
  207. */
  208. {
  209. unsigned long i, nextBitmapAddress;
  210. printk("ms_vpd: %ld sorted memory blocks\n", numSegmentBlocks);
  211. nextBitmapAddress = 0;
  212. for (i = 0; i < numSegmentBlocks; ++i) {
  213. unsigned long length = mb_array[i].absEnd -
  214. mb_array[i].absStart;
  215. mb_array[i].logicalStart = nextBitmapAddress;
  216. mb_array[i].logicalEnd = nextBitmapAddress + length;
  217. nextBitmapAddress += length;
  218. printk(" Bitmap range: %016lx - %016lx\n"
  219. " Absolute range: %016lx - %016lx\n",
  220. mb_array[i].logicalStart,
  221. mb_array[i].logicalEnd,
  222. mb_array[i].absStart, mb_array[i].absEnd);
  223. mb_array[i].absStart = addr_to_chunk(mb_array[i].absStart &
  224. 0x000fffffffffffff);
  225. mb_array[i].absEnd = addr_to_chunk(mb_array[i].absEnd &
  226. 0x000fffffffffffff);
  227. mb_array[i].logicalStart =
  228. addr_to_chunk(mb_array[i].logicalStart);
  229. mb_array[i].logicalEnd = addr_to_chunk(mb_array[i].logicalEnd);
  230. }
  231. }
  232. return numSegmentBlocks;
  233. }
  234. static unsigned long iSeries_process_mainstore_vpd(struct MemoryBlock *mb_array,
  235. unsigned long max_entries)
  236. {
  237. unsigned long i;
  238. unsigned long mem_blocks = 0;
  239. if (cpu_has_feature(CPU_FTR_SLB))
  240. mem_blocks = iSeries_process_Regatta_mainstore_vpd(mb_array,
  241. max_entries);
  242. else
  243. mem_blocks = iSeries_process_Condor_mainstore_vpd(mb_array,
  244. max_entries);
  245. printk("Mainstore_VPD: numMemoryBlocks = %ld \n", mem_blocks);
  246. for (i = 0; i < mem_blocks; ++i) {
  247. printk("Mainstore_VPD: block %3ld logical chunks %016lx - %016lx\n"
  248. " abs chunks %016lx - %016lx\n",
  249. i, mb_array[i].logicalStart, mb_array[i].logicalEnd,
  250. mb_array[i].absStart, mb_array[i].absEnd);
  251. }
  252. return mem_blocks;
  253. }
  254. static void __init iSeries_get_cmdline(void)
  255. {
  256. char *p, *q;
  257. /* copy the command line parameter from the primary VSP */
  258. HvCallEvent_dmaToSp(cmd_line, 2 * 64* 1024, 256,
  259. HvLpDma_Direction_RemoteToLocal);
  260. p = cmd_line;
  261. q = cmd_line + 255;
  262. while(p < q) {
  263. if (!*p || *p == '\n')
  264. break;
  265. ++p;
  266. }
  267. *p = 0;
  268. }
  269. static void __init iSeries_init_early(void)
  270. {
  271. DBG(" -> iSeries_init_early()\n");
  272. ppc64_interrupt_controller = IC_ISERIES;
  273. #if defined(CONFIG_BLK_DEV_INITRD)
  274. /*
  275. * If the init RAM disk has been configured and there is
  276. * a non-zero starting address for it, set it up
  277. */
  278. if (naca.xRamDisk) {
  279. initrd_start = (unsigned long)__va(naca.xRamDisk);
  280. initrd_end = initrd_start + naca.xRamDiskSize * HW_PAGE_SIZE;
  281. initrd_below_start_ok = 1; // ramdisk in kernel space
  282. ROOT_DEV = Root_RAM0;
  283. if (((rd_size * 1024) / HW_PAGE_SIZE) < naca.xRamDiskSize)
  284. rd_size = (naca.xRamDiskSize * HW_PAGE_SIZE) / 1024;
  285. } else
  286. #endif /* CONFIG_BLK_DEV_INITRD */
  287. {
  288. /* ROOT_DEV = MKDEV(VIODASD_MAJOR, 1); */
  289. }
  290. iSeries_recal_tb = get_tb();
  291. iSeries_recal_titan = HvCallXm_loadTod();
  292. /*
  293. * Initialize the hash table management pointers
  294. */
  295. hpte_init_iSeries();
  296. /*
  297. * Initialize the DMA/TCE management
  298. */
  299. iommu_init_early_iSeries();
  300. /* Initialize machine-dependency vectors */
  301. #ifdef CONFIG_SMP
  302. smp_init_iSeries();
  303. #endif
  304. /* Associate Lp Event Queue 0 with processor 0 */
  305. HvCallEvent_setLpEventQueueInterruptProc(0, 0);
  306. mf_init();
  307. /* If we were passed an initrd, set the ROOT_DEV properly if the values
  308. * look sensible. If not, clear initrd reference.
  309. */
  310. #ifdef CONFIG_BLK_DEV_INITRD
  311. if (initrd_start >= KERNELBASE && initrd_end >= KERNELBASE &&
  312. initrd_end > initrd_start)
  313. ROOT_DEV = Root_RAM0;
  314. else
  315. initrd_start = initrd_end = 0;
  316. #endif /* CONFIG_BLK_DEV_INITRD */
  317. DBG(" <- iSeries_init_early()\n");
  318. }
  319. struct mschunks_map mschunks_map = {
  320. /* XXX We don't use these, but Piranha might need them. */
  321. .chunk_size = MSCHUNKS_CHUNK_SIZE,
  322. .chunk_shift = MSCHUNKS_CHUNK_SHIFT,
  323. .chunk_mask = MSCHUNKS_OFFSET_MASK,
  324. };
  325. EXPORT_SYMBOL(mschunks_map);
  326. void mschunks_alloc(unsigned long num_chunks)
  327. {
  328. klimit = _ALIGN(klimit, sizeof(u32));
  329. mschunks_map.mapping = (u32 *)klimit;
  330. klimit += num_chunks * sizeof(u32);
  331. mschunks_map.num_chunks = num_chunks;
  332. }
  333. /*
  334. * The iSeries may have very large memories ( > 128 GB ) and a partition
  335. * may get memory in "chunks" that may be anywhere in the 2**52 real
  336. * address space. The chunks are 256K in size. To map this to the
  337. * memory model Linux expects, the AS/400 specific code builds a
  338. * translation table to translate what Linux thinks are "physical"
  339. * addresses to the actual real addresses. This allows us to make
  340. * it appear to Linux that we have contiguous memory starting at
  341. * physical address zero while in fact this could be far from the truth.
  342. * To avoid confusion, I'll let the words physical and/or real address
  343. * apply to the Linux addresses while I'll use "absolute address" to
  344. * refer to the actual hardware real address.
  345. *
  346. * build_iSeries_Memory_Map gets information from the Hypervisor and
  347. * looks at the Main Store VPD to determine the absolute addresses
  348. * of the memory that has been assigned to our partition and builds
  349. * a table used to translate Linux's physical addresses to these
  350. * absolute addresses. Absolute addresses are needed when
  351. * communicating with the hypervisor (e.g. to build HPT entries)
  352. *
  353. * Returns the physical memory size
  354. */
  355. static unsigned long __init build_iSeries_Memory_Map(void)
  356. {
  357. u32 loadAreaFirstChunk, loadAreaLastChunk, loadAreaSize;
  358. u32 nextPhysChunk;
  359. u32 hptFirstChunk, hptLastChunk, hptSizeChunks, hptSizePages;
  360. u32 totalChunks,moreChunks;
  361. u32 currChunk, thisChunk, absChunk;
  362. u32 currDword;
  363. u32 chunkBit;
  364. u64 map;
  365. struct MemoryBlock mb[32];
  366. unsigned long numMemoryBlocks, curBlock;
  367. /* Chunk size on iSeries is 256K bytes */
  368. totalChunks = (u32)HvLpConfig_getMsChunks();
  369. mschunks_alloc(totalChunks);
  370. /*
  371. * Get absolute address of our load area
  372. * and map it to physical address 0
  373. * This guarantees that the loadarea ends up at physical 0
  374. * otherwise, it might not be returned by PLIC as the first
  375. * chunks
  376. */
  377. loadAreaFirstChunk = (u32)addr_to_chunk(itLpNaca.xLoadAreaAddr);
  378. loadAreaSize = itLpNaca.xLoadAreaChunks;
  379. /*
  380. * Only add the pages already mapped here.
  381. * Otherwise we might add the hpt pages
  382. * The rest of the pages of the load area
  383. * aren't in the HPT yet and can still
  384. * be assigned an arbitrary physical address
  385. */
  386. if ((loadAreaSize * 64) > HvPagesToMap)
  387. loadAreaSize = HvPagesToMap / 64;
  388. loadAreaLastChunk = loadAreaFirstChunk + loadAreaSize - 1;
  389. /*
  390. * TODO Do we need to do something if the HPT is in the 64MB load area?
  391. * This would be required if the itLpNaca.xLoadAreaChunks includes
  392. * the HPT size
  393. */
  394. printk("Mapping load area - physical addr = 0000000000000000\n"
  395. " absolute addr = %016lx\n",
  396. chunk_to_addr(loadAreaFirstChunk));
  397. printk("Load area size %dK\n", loadAreaSize * 256);
  398. for (nextPhysChunk = 0; nextPhysChunk < loadAreaSize; ++nextPhysChunk)
  399. mschunks_map.mapping[nextPhysChunk] =
  400. loadAreaFirstChunk + nextPhysChunk;
  401. /*
  402. * Get absolute address of our HPT and remember it so
  403. * we won't map it to any physical address
  404. */
  405. hptFirstChunk = (u32)addr_to_chunk(HvCallHpt_getHptAddress());
  406. hptSizePages = (u32)HvCallHpt_getHptPages();
  407. hptSizeChunks = hptSizePages >>
  408. (MSCHUNKS_CHUNK_SHIFT - HW_PAGE_SHIFT);
  409. hptLastChunk = hptFirstChunk + hptSizeChunks - 1;
  410. printk("HPT absolute addr = %016lx, size = %dK\n",
  411. chunk_to_addr(hptFirstChunk), hptSizeChunks * 256);
  412. /*
  413. * Determine if absolute memory has any
  414. * holes so that we can interpret the
  415. * access map we get back from the hypervisor
  416. * correctly.
  417. */
  418. numMemoryBlocks = iSeries_process_mainstore_vpd(mb, 32);
  419. /*
  420. * Process the main store access map from the hypervisor
  421. * to build up our physical -> absolute translation table
  422. */
  423. curBlock = 0;
  424. currChunk = 0;
  425. currDword = 0;
  426. moreChunks = totalChunks;
  427. while (moreChunks) {
  428. map = HvCallSm_get64BitsOfAccessMap(itLpNaca.xLpIndex,
  429. currDword);
  430. thisChunk = currChunk;
  431. while (map) {
  432. chunkBit = map >> 63;
  433. map <<= 1;
  434. if (chunkBit) {
  435. --moreChunks;
  436. while (thisChunk >= mb[curBlock].logicalEnd) {
  437. ++curBlock;
  438. if (curBlock >= numMemoryBlocks)
  439. panic("out of memory blocks");
  440. }
  441. if (thisChunk < mb[curBlock].logicalStart)
  442. panic("memory block error");
  443. absChunk = mb[curBlock].absStart +
  444. (thisChunk - mb[curBlock].logicalStart);
  445. if (((absChunk < hptFirstChunk) ||
  446. (absChunk > hptLastChunk)) &&
  447. ((absChunk < loadAreaFirstChunk) ||
  448. (absChunk > loadAreaLastChunk))) {
  449. mschunks_map.mapping[nextPhysChunk] =
  450. absChunk;
  451. ++nextPhysChunk;
  452. }
  453. }
  454. ++thisChunk;
  455. }
  456. ++currDword;
  457. currChunk += 64;
  458. }
  459. /*
  460. * main store size (in chunks) is
  461. * totalChunks - hptSizeChunks
  462. * which should be equal to
  463. * nextPhysChunk
  464. */
  465. return chunk_to_addr(nextPhysChunk);
  466. }
  467. /*
  468. * Document me.
  469. */
  470. static void __init iSeries_setup_arch(void)
  471. {
  472. if (get_lppaca()->shared_proc) {
  473. ppc_md.idle_loop = iseries_shared_idle;
  474. printk(KERN_DEBUG "Using shared processor idle loop\n");
  475. } else {
  476. ppc_md.idle_loop = iseries_dedicated_idle;
  477. printk(KERN_DEBUG "Using dedicated idle loop\n");
  478. }
  479. /* Setup the Lp Event Queue */
  480. setup_hvlpevent_queue();
  481. printk("Max logical processors = %d\n",
  482. itVpdAreas.xSlicMaxLogicalProcs);
  483. printk("Max physical processors = %d\n",
  484. itVpdAreas.xSlicMaxPhysicalProcs);
  485. }
  486. static void iSeries_show_cpuinfo(struct seq_file *m)
  487. {
  488. seq_printf(m, "machine\t\t: 64-bit iSeries Logical Partition\n");
  489. }
  490. static void __init iSeries_progress(char * st, unsigned short code)
  491. {
  492. printk("Progress: [%04x] - %s\n", (unsigned)code, st);
  493. mf_display_progress(code);
  494. }
  495. static void __init iSeries_fixup_klimit(void)
  496. {
  497. /*
  498. * Change klimit to take into account any ram disk
  499. * that may be included
  500. */
  501. if (naca.xRamDisk)
  502. klimit = KERNELBASE + (u64)naca.xRamDisk +
  503. (naca.xRamDiskSize * HW_PAGE_SIZE);
  504. else {
  505. /*
  506. * No ram disk was included - check and see if there
  507. * was an embedded system map. Change klimit to take
  508. * into account any embedded system map
  509. */
  510. if (embedded_sysmap_end)
  511. klimit = KERNELBASE + ((embedded_sysmap_end + 4095) &
  512. 0xfffffffffffff000);
  513. }
  514. }
  515. static int __init iSeries_src_init(void)
  516. {
  517. /* clear the progress line */
  518. ppc_md.progress(" ", 0xffff);
  519. return 0;
  520. }
  521. late_initcall(iSeries_src_init);
  522. static inline void process_iSeries_events(void)
  523. {
  524. asm volatile ("li 0,0x5555; sc" : : : "r0", "r3");
  525. }
  526. static void yield_shared_processor(void)
  527. {
  528. unsigned long tb;
  529. HvCall_setEnabledInterrupts(HvCall_MaskIPI |
  530. HvCall_MaskLpEvent |
  531. HvCall_MaskLpProd |
  532. HvCall_MaskTimeout);
  533. tb = get_tb();
  534. /* Compute future tb value when yield should expire */
  535. HvCall_yieldProcessor(HvCall_YieldTimed, tb+tb_ticks_per_jiffy);
  536. /*
  537. * The decrementer stops during the yield. Force a fake decrementer
  538. * here and let the timer_interrupt code sort out the actual time.
  539. */
  540. get_lppaca()->int_dword.fields.decr_int = 1;
  541. ppc64_runlatch_on();
  542. process_iSeries_events();
  543. }
  544. static void iseries_shared_idle(void)
  545. {
  546. while (1) {
  547. while (!need_resched() && !hvlpevent_is_pending()) {
  548. local_irq_disable();
  549. ppc64_runlatch_off();
  550. /* Recheck with irqs off */
  551. if (!need_resched() && !hvlpevent_is_pending())
  552. yield_shared_processor();
  553. HMT_medium();
  554. local_irq_enable();
  555. }
  556. ppc64_runlatch_on();
  557. if (hvlpevent_is_pending())
  558. process_iSeries_events();
  559. preempt_enable_no_resched();
  560. schedule();
  561. preempt_disable();
  562. }
  563. }
  564. static void iseries_dedicated_idle(void)
  565. {
  566. set_thread_flag(TIF_POLLING_NRFLAG);
  567. while (1) {
  568. if (!need_resched()) {
  569. while (!need_resched()) {
  570. ppc64_runlatch_off();
  571. HMT_low();
  572. if (hvlpevent_is_pending()) {
  573. HMT_medium();
  574. ppc64_runlatch_on();
  575. process_iSeries_events();
  576. }
  577. }
  578. HMT_medium();
  579. }
  580. ppc64_runlatch_on();
  581. preempt_enable_no_resched();
  582. schedule();
  583. preempt_disable();
  584. }
  585. }
  586. #ifndef CONFIG_PCI
  587. void __init iSeries_init_IRQ(void) { }
  588. #endif
  589. static int __init iseries_probe(void)
  590. {
  591. unsigned long root = of_get_flat_dt_root();
  592. if (!of_flat_dt_is_compatible(root, "IBM,iSeries"))
  593. return 0;
  594. powerpc_firmware_features |= FW_FEATURE_ISERIES;
  595. powerpc_firmware_features |= FW_FEATURE_LPAR;
  596. /*
  597. * The Hypervisor only allows us up to 256 interrupt
  598. * sources (the irq number is passed in a u8).
  599. */
  600. virt_irq_max = 255;
  601. return 1;
  602. }
  603. define_machine(iseries) {
  604. .name = "iSeries",
  605. .setup_arch = iSeries_setup_arch,
  606. .show_cpuinfo = iSeries_show_cpuinfo,
  607. .init_IRQ = iSeries_init_IRQ,
  608. .get_irq = iSeries_get_irq,
  609. .init_early = iSeries_init_early,
  610. .pcibios_fixup = iSeries_pci_final_fixup,
  611. .restart = mf_reboot,
  612. .power_off = mf_power_off,
  613. .halt = mf_power_off,
  614. .get_boot_time = iSeries_get_boot_time,
  615. .set_rtc_time = iSeries_set_rtc_time,
  616. .get_rtc_time = iSeries_get_rtc_time,
  617. .calibrate_decr = generic_calibrate_decr,
  618. .progress = iSeries_progress,
  619. .probe = iseries_probe,
  620. /* XXX Implement enable_pmcs for iSeries */
  621. };
  622. struct blob {
  623. unsigned char data[PAGE_SIZE * 2];
  624. unsigned long next;
  625. };
  626. struct iseries_flat_dt {
  627. struct boot_param_header header;
  628. u64 reserve_map[2];
  629. struct blob dt;
  630. struct blob strings;
  631. };
  632. static struct iseries_flat_dt iseries_dt;
  633. static void dt_init(struct iseries_flat_dt *dt)
  634. {
  635. dt->header.off_mem_rsvmap =
  636. offsetof(struct iseries_flat_dt, reserve_map);
  637. dt->header.off_dt_struct = offsetof(struct iseries_flat_dt, dt);
  638. dt->header.off_dt_strings = offsetof(struct iseries_flat_dt, strings);
  639. dt->header.totalsize = sizeof(struct iseries_flat_dt);
  640. dt->header.dt_strings_size = sizeof(struct blob);
  641. /* There is no notion of hardware cpu id on iSeries */
  642. dt->header.boot_cpuid_phys = smp_processor_id();
  643. dt->dt.next = (unsigned long)&dt->dt.data;
  644. dt->strings.next = (unsigned long)&dt->strings.data;
  645. dt->header.magic = OF_DT_HEADER;
  646. dt->header.version = 0x10;
  647. dt->header.last_comp_version = 0x10;
  648. dt->reserve_map[0] = 0;
  649. dt->reserve_map[1] = 0;
  650. }
  651. static void dt_check_blob(struct blob *b)
  652. {
  653. if (b->next >= (unsigned long)&b->next) {
  654. DBG("Ran out of space in flat device tree blob!\n");
  655. BUG();
  656. }
  657. }
  658. static void dt_push_u32(struct iseries_flat_dt *dt, u32 value)
  659. {
  660. *((u32*)dt->dt.next) = value;
  661. dt->dt.next += sizeof(u32);
  662. dt_check_blob(&dt->dt);
  663. }
  664. #ifdef notyet
  665. static void dt_push_u64(struct iseries_flat_dt *dt, u64 value)
  666. {
  667. *((u64*)dt->dt.next) = value;
  668. dt->dt.next += sizeof(u64);
  669. dt_check_blob(&dt->dt);
  670. }
  671. #endif
  672. static unsigned long dt_push_bytes(struct blob *blob, char *data, int len)
  673. {
  674. unsigned long start = blob->next - (unsigned long)blob->data;
  675. memcpy((char *)blob->next, data, len);
  676. blob->next = _ALIGN(blob->next + len, 4);
  677. dt_check_blob(blob);
  678. return start;
  679. }
  680. static void dt_start_node(struct iseries_flat_dt *dt, char *name)
  681. {
  682. dt_push_u32(dt, OF_DT_BEGIN_NODE);
  683. dt_push_bytes(&dt->dt, name, strlen(name) + 1);
  684. }
  685. #define dt_end_node(dt) dt_push_u32(dt, OF_DT_END_NODE)
  686. static void dt_prop(struct iseries_flat_dt *dt, char *name, char *data, int len)
  687. {
  688. unsigned long offset;
  689. dt_push_u32(dt, OF_DT_PROP);
  690. /* Length of the data */
  691. dt_push_u32(dt, len);
  692. /* Put the property name in the string blob. */
  693. offset = dt_push_bytes(&dt->strings, name, strlen(name) + 1);
  694. /* The offset of the properties name in the string blob. */
  695. dt_push_u32(dt, (u32)offset);
  696. /* The actual data. */
  697. dt_push_bytes(&dt->dt, data, len);
  698. }
  699. static void dt_prop_str(struct iseries_flat_dt *dt, char *name, char *data)
  700. {
  701. dt_prop(dt, name, data, strlen(data) + 1); /* + 1 for NULL */
  702. }
  703. static void dt_prop_u32(struct iseries_flat_dt *dt, char *name, u32 data)
  704. {
  705. dt_prop(dt, name, (char *)&data, sizeof(u32));
  706. }
  707. static void dt_prop_u64(struct iseries_flat_dt *dt, char *name, u64 data)
  708. {
  709. dt_prop(dt, name, (char *)&data, sizeof(u64));
  710. }
  711. static void dt_prop_u64_list(struct iseries_flat_dt *dt, char *name, u64 *data, int n)
  712. {
  713. dt_prop(dt, name, (char *)data, sizeof(u64) * n);
  714. }
  715. static void dt_prop_u32_list(struct iseries_flat_dt *dt, char *name, u32 *data, int n)
  716. {
  717. dt_prop(dt, name, (char *)data, sizeof(u32) * n);
  718. }
  719. #ifdef notyet
  720. static void dt_prop_empty(struct iseries_flat_dt *dt, char *name)
  721. {
  722. dt_prop(dt, name, NULL, 0);
  723. }
  724. #endif
  725. static void dt_cpus(struct iseries_flat_dt *dt)
  726. {
  727. unsigned char buf[32];
  728. unsigned char *p;
  729. unsigned int i, index;
  730. struct IoHriProcessorVpd *d;
  731. u32 pft_size[2];
  732. /* yuck */
  733. snprintf(buf, 32, "PowerPC,%s", cur_cpu_spec->cpu_name);
  734. p = strchr(buf, ' ');
  735. if (!p) p = buf + strlen(buf);
  736. dt_start_node(dt, "cpus");
  737. dt_prop_u32(dt, "#address-cells", 1);
  738. dt_prop_u32(dt, "#size-cells", 0);
  739. pft_size[0] = 0; /* NUMA CEC cookie, 0 for non NUMA */
  740. pft_size[1] = __ilog2(HvCallHpt_getHptPages() * HW_PAGE_SIZE);
  741. for (i = 0; i < NR_CPUS; i++) {
  742. if (lppaca[i].dyn_proc_status >= 2)
  743. continue;
  744. snprintf(p, 32 - (p - buf), "@%d", i);
  745. dt_start_node(dt, buf);
  746. dt_prop_str(dt, "device_type", "cpu");
  747. index = lppaca[i].dyn_hv_phys_proc_index;
  748. d = &xIoHriProcessorVpd[index];
  749. dt_prop_u32(dt, "i-cache-size", d->xInstCacheSize * 1024);
  750. dt_prop_u32(dt, "i-cache-line-size", d->xInstCacheOperandSize);
  751. dt_prop_u32(dt, "d-cache-size", d->xDataL1CacheSizeKB * 1024);
  752. dt_prop_u32(dt, "d-cache-line-size", d->xDataCacheOperandSize);
  753. /* magic conversions to Hz copied from old code */
  754. dt_prop_u32(dt, "clock-frequency",
  755. ((1UL << 34) * 1000000) / d->xProcFreq);
  756. dt_prop_u32(dt, "timebase-frequency",
  757. ((1UL << 32) * 1000000) / d->xTimeBaseFreq);
  758. dt_prop_u32(dt, "reg", i);
  759. dt_prop_u32_list(dt, "ibm,pft-size", pft_size, 2);
  760. dt_end_node(dt);
  761. }
  762. dt_end_node(dt);
  763. }
  764. static void dt_model(struct iseries_flat_dt *dt)
  765. {
  766. char buf[16] = "IBM,";
  767. /* "IBM," + mfgId[2:3] + systemSerial[1:5] */
  768. strne2a(buf + 4, xItExtVpdPanel.mfgID + 2, 2);
  769. strne2a(buf + 6, xItExtVpdPanel.systemSerial + 1, 5);
  770. buf[11] = '\0';
  771. dt_prop_str(dt, "system-id", buf);
  772. /* "IBM," + machineType[0:4] */
  773. strne2a(buf + 4, xItExtVpdPanel.machineType, 4);
  774. buf[8] = '\0';
  775. dt_prop_str(dt, "model", buf);
  776. dt_prop_str(dt, "compatible", "IBM,iSeries");
  777. }
  778. static void dt_vdevices(struct iseries_flat_dt *dt)
  779. {
  780. u32 reg = 0;
  781. HvLpIndexMap vlan_map;
  782. int i;
  783. char buf[32];
  784. dt_start_node(dt, "vdevice");
  785. dt_prop_str(dt, "device_type", "vdevice");
  786. dt_prop_str(dt, "compatible", "IBM,iSeries-vdevice");
  787. dt_prop_u32(dt, "#address-cells", 1);
  788. dt_prop_u32(dt, "#size-cells", 0);
  789. snprintf(buf, sizeof(buf), "vty@%08x", reg);
  790. dt_start_node(dt, buf);
  791. dt_prop_str(dt, "device_type", "serial");
  792. dt_prop_u32(dt, "reg", reg);
  793. dt_end_node(dt);
  794. reg++;
  795. snprintf(buf, sizeof(buf), "v-scsi@%08x", reg);
  796. dt_start_node(dt, buf);
  797. dt_prop_str(dt, "device_type", "vscsi");
  798. dt_prop_str(dt, "compatible", "IBM,v-scsi");
  799. dt_prop_u32(dt, "reg", reg);
  800. dt_end_node(dt);
  801. reg++;
  802. vlan_map = HvLpConfig_getVirtualLanIndexMap();
  803. for (i = 0; i < HVMAXARCHITECTEDVIRTUALLANS; i++) {
  804. unsigned char mac_addr[ETH_ALEN];
  805. if ((vlan_map & (0x8000 >> i)) == 0)
  806. continue;
  807. snprintf(buf, 32, "l-lan@%08x", reg + i);
  808. dt_start_node(dt, buf);
  809. dt_prop_str(dt, "device_type", "network");
  810. dt_prop_str(dt, "compatible", "IBM,iSeries-l-lan");
  811. dt_prop_u32(dt, "reg", reg + i);
  812. dt_prop_u32(dt, "linux,unit_address", i);
  813. mac_addr[0] = 0x02;
  814. mac_addr[1] = 0x01;
  815. mac_addr[2] = 0xff;
  816. mac_addr[3] = i;
  817. mac_addr[4] = 0xff;
  818. mac_addr[5] = HvLpConfig_getLpIndex_outline();
  819. dt_prop(dt, "local-mac-address", (char *)mac_addr, ETH_ALEN);
  820. dt_prop(dt, "mac-address", (char *)mac_addr, ETH_ALEN);
  821. dt_prop_u32(dt, "max-frame-size", 9000);
  822. dt_prop_u32(dt, "address-bits", 48);
  823. dt_end_node(dt);
  824. }
  825. reg += HVMAXARCHITECTEDVIRTUALLANS;
  826. for (i = 0; i < HVMAXARCHITECTEDVIRTUALDISKS; i++) {
  827. snprintf(buf, 32, "viodasd@%08x", reg + i);
  828. dt_start_node(dt, buf);
  829. dt_prop_str(dt, "device_type", "block");
  830. dt_prop_str(dt, "compatible", "IBM,iSeries-viodasd");
  831. dt_prop_u32(dt, "reg", reg + i);
  832. dt_prop_u32(dt, "linux,unit_address", i);
  833. dt_end_node(dt);
  834. }
  835. reg += HVMAXARCHITECTEDVIRTUALDISKS;
  836. for (i = 0; i < HVMAXARCHITECTEDVIRTUALCDROMS; i++) {
  837. snprintf(buf, 32, "viocd@%08x", reg + i);
  838. dt_start_node(dt, buf);
  839. dt_prop_str(dt, "device_type", "block");
  840. dt_prop_str(dt, "compatible", "IBM,iSeries-viocd");
  841. dt_prop_u32(dt, "reg", reg + i);
  842. dt_prop_u32(dt, "linux,unit_address", i);
  843. dt_end_node(dt);
  844. }
  845. reg += HVMAXARCHITECTEDVIRTUALCDROMS;
  846. for (i = 0; i < HVMAXARCHITECTEDVIRTUALTAPES; i++) {
  847. snprintf(buf, 32, "viotape@%08x", reg + i);
  848. dt_start_node(dt, buf);
  849. dt_prop_str(dt, "device_type", "byte");
  850. dt_prop_str(dt, "compatible", "IBM,iSeries-viotape");
  851. dt_prop_u32(dt, "reg", reg + i);
  852. dt_prop_u32(dt, "linux,unit_address", i);
  853. dt_end_node(dt);
  854. }
  855. dt_end_node(dt);
  856. }
  857. /*
  858. * This assumes that the node slot is always on the primary bus!
  859. */
  860. static void scan_bridge_slot(struct iseries_flat_dt *dt, HvBusNumber bus,
  861. struct HvCallPci_BridgeInfo *bridge_info)
  862. {
  863. HvSubBusNumber sub_bus = bridge_info->subBusNumber;
  864. u16 vendor_id;
  865. u16 device_id;
  866. u32 class_id;
  867. int err;
  868. char buf[32];
  869. u32 reg[5];
  870. int id_sel = ISERIES_GET_DEVICE_FROM_SUBBUS(sub_bus);
  871. int function = ISERIES_GET_FUNCTION_FROM_SUBBUS(sub_bus);
  872. HvAgentId eads_id_sel = ISERIES_PCI_AGENTID(id_sel, function);
  873. /*
  874. * Connect all functions of any device found.
  875. */
  876. for (id_sel = 1; id_sel <= bridge_info->maxAgents; id_sel++) {
  877. for (function = 0; function < 8; function++) {
  878. u8 devfn;
  879. HvAgentId agent_id = ISERIES_PCI_AGENTID(id_sel,
  880. function);
  881. err = HvCallXm_connectBusUnit(bus, sub_bus,
  882. agent_id, 0);
  883. if (err) {
  884. if (err != 0x302)
  885. printk(KERN_DEBUG
  886. "connectBusUnit(%x, %x, %x) "
  887. "== %x\n",
  888. bus, sub_bus, agent_id, err);
  889. continue;
  890. }
  891. err = HvCallPci_configLoad16(bus, sub_bus, agent_id,
  892. PCI_VENDOR_ID, &vendor_id);
  893. if (err) {
  894. printk(KERN_DEBUG
  895. "ReadVendor(%x, %x, %x) == %x\n",
  896. bus, sub_bus, agent_id, err);
  897. continue;
  898. }
  899. err = HvCallPci_configLoad16(bus, sub_bus, agent_id,
  900. PCI_DEVICE_ID, &device_id);
  901. if (err) {
  902. printk(KERN_DEBUG
  903. "ReadDevice(%x, %x, %x) == %x\n",
  904. bus, sub_bus, agent_id, err);
  905. continue;
  906. }
  907. err = HvCallPci_configLoad32(bus, sub_bus, agent_id,
  908. PCI_CLASS_REVISION , &class_id);
  909. if (err) {
  910. printk(KERN_DEBUG
  911. "ReadClass(%x, %x, %x) == %x\n",
  912. bus, sub_bus, agent_id, err);
  913. continue;
  914. }
  915. devfn = PCI_DEVFN(ISERIES_ENCODE_DEVICE(eads_id_sel),
  916. function);
  917. if (function == 0)
  918. snprintf(buf, sizeof(buf), "pci@%x",
  919. PCI_SLOT(devfn));
  920. else
  921. snprintf(buf, sizeof(buf), "pci@%x,%d",
  922. PCI_SLOT(devfn), function);
  923. dt_start_node(dt, buf);
  924. reg[0] = (bus << 16) | (devfn << 8);
  925. reg[1] = 0;
  926. reg[2] = 0;
  927. reg[3] = 0;
  928. reg[4] = 0;
  929. dt_prop_u32_list(dt, "reg", reg, 5);
  930. dt_prop_u32(dt, "vendor-id", vendor_id);
  931. dt_prop_u32(dt, "device-id", device_id);
  932. dt_prop_u32(dt, "class-code", class_id >> 8);
  933. dt_prop_u32(dt, "revision-id", class_id & 0xff);
  934. dt_prop_u32(dt, "linux,subbus", sub_bus);
  935. dt_prop_u32(dt, "linux,agent-id", agent_id);
  936. dt_prop_u32(dt, "linux,logical-slot-number",
  937. bridge_info->logicalSlotNumber);
  938. dt_end_node(dt);
  939. }
  940. }
  941. }
  942. static void scan_bridge(struct iseries_flat_dt *dt, HvBusNumber bus,
  943. HvSubBusNumber sub_bus, int id_sel)
  944. {
  945. struct HvCallPci_BridgeInfo bridge_info;
  946. HvAgentId agent_id;
  947. int function;
  948. int ret;
  949. /* Note: hvSubBus and irq is always be 0 at this level! */
  950. for (function = 0; function < 8; ++function) {
  951. agent_id = ISERIES_PCI_AGENTID(id_sel, function);
  952. ret = HvCallXm_connectBusUnit(bus, sub_bus, agent_id, 0);
  953. if (ret != 0) {
  954. if (ret != 0xb)
  955. printk(KERN_DEBUG "connectBusUnit(%x, %x, %x) "
  956. "== %x\n",
  957. bus, sub_bus, agent_id, ret);
  958. continue;
  959. }
  960. printk("found device at bus %d idsel %d func %d (AgentId %x)\n",
  961. bus, id_sel, function, agent_id);
  962. ret = HvCallPci_getBusUnitInfo(bus, sub_bus, agent_id,
  963. iseries_hv_addr(&bridge_info),
  964. sizeof(struct HvCallPci_BridgeInfo));
  965. if (ret != 0)
  966. continue;
  967. printk("bridge info: type %x subbus %x "
  968. "maxAgents %x maxsubbus %x logslot %x\n",
  969. bridge_info.busUnitInfo.deviceType,
  970. bridge_info.subBusNumber,
  971. bridge_info.maxAgents,
  972. bridge_info.maxSubBusNumber,
  973. bridge_info.logicalSlotNumber);
  974. if (bridge_info.busUnitInfo.deviceType ==
  975. HvCallPci_BridgeDevice)
  976. scan_bridge_slot(dt, bus, &bridge_info);
  977. else
  978. printk("PCI: Invalid Bridge Configuration(0x%02X)",
  979. bridge_info.busUnitInfo.deviceType);
  980. }
  981. }
  982. static void scan_phb(struct iseries_flat_dt *dt, HvBusNumber bus)
  983. {
  984. struct HvCallPci_DeviceInfo dev_info;
  985. const HvSubBusNumber sub_bus = 0; /* EADs is always 0. */
  986. int err;
  987. int id_sel;
  988. const int max_agents = 8;
  989. /*
  990. * Probe for EADs Bridges
  991. */
  992. for (id_sel = 1; id_sel < max_agents; ++id_sel) {
  993. err = HvCallPci_getDeviceInfo(bus, sub_bus, id_sel,
  994. iseries_hv_addr(&dev_info),
  995. sizeof(struct HvCallPci_DeviceInfo));
  996. if (err) {
  997. if (err != 0x302)
  998. printk(KERN_DEBUG "getDeviceInfo(%x, %x, %x) "
  999. "== %x\n",
  1000. bus, sub_bus, id_sel, err);
  1001. continue;
  1002. }
  1003. if (dev_info.deviceType != HvCallPci_NodeDevice) {
  1004. printk(KERN_DEBUG "PCI: Invalid System Configuration"
  1005. "(0x%02X) for bus 0x%02x id 0x%02x.\n",
  1006. dev_info.deviceType, bus, id_sel);
  1007. continue;
  1008. }
  1009. scan_bridge(dt, bus, sub_bus, id_sel);
  1010. }
  1011. }
  1012. static void dt_pci_devices(struct iseries_flat_dt *dt)
  1013. {
  1014. HvBusNumber bus;
  1015. char buf[32];
  1016. u32 buses[2];
  1017. int phb_num = 0;
  1018. /* Check all possible buses. */
  1019. for (bus = 0; bus < 256; bus++) {
  1020. int err = HvCallXm_testBus(bus);
  1021. if (err) {
  1022. /*
  1023. * Check for Unexpected Return code, a clue that
  1024. * something has gone wrong.
  1025. */
  1026. if (err != 0x0301)
  1027. printk(KERN_ERR "Unexpected Return on Probe"
  1028. "(0x%02X): 0x%04X", bus, err);
  1029. continue;
  1030. }
  1031. printk("bus %d appears to exist\n", bus);
  1032. snprintf(buf, 32, "pci@%d", phb_num);
  1033. dt_start_node(dt, buf);
  1034. dt_prop_str(dt, "device_type", "pci");
  1035. dt_prop_str(dt, "compatible", "IBM,iSeries-Logical-PHB");
  1036. dt_prop_u32(dt, "#address-cells", 3);
  1037. dt_prop_u32(dt, "#size-cells", 2);
  1038. buses[0] = buses[1] = bus;
  1039. dt_prop_u32_list(dt, "bus-range", buses, 2);
  1040. scan_phb(dt, bus);
  1041. dt_end_node(dt);
  1042. phb_num++;
  1043. }
  1044. }
  1045. static void build_flat_dt(struct iseries_flat_dt *dt, unsigned long phys_mem_size)
  1046. {
  1047. u64 tmp[2];
  1048. dt_init(dt);
  1049. dt_start_node(dt, "");
  1050. dt_prop_u32(dt, "#address-cells", 2);
  1051. dt_prop_u32(dt, "#size-cells", 2);
  1052. dt_model(dt);
  1053. /* /memory */
  1054. dt_start_node(dt, "memory@0");
  1055. dt_prop_str(dt, "name", "memory");
  1056. dt_prop_str(dt, "device_type", "memory");
  1057. tmp[0] = 0;
  1058. tmp[1] = phys_mem_size;
  1059. dt_prop_u64_list(dt, "reg", tmp, 2);
  1060. dt_end_node(dt);
  1061. /* /chosen */
  1062. dt_start_node(dt, "chosen");
  1063. dt_prop_str(dt, "bootargs", cmd_line);
  1064. dt_end_node(dt);
  1065. dt_cpus(dt);
  1066. dt_vdevices(dt);
  1067. dt_pci_devices(dt);
  1068. dt_end_node(dt);
  1069. dt_push_u32(dt, OF_DT_END);
  1070. }
  1071. void * __init iSeries_early_setup(void)
  1072. {
  1073. unsigned long phys_mem_size;
  1074. iSeries_fixup_klimit();
  1075. /*
  1076. * Initialize the table which translate Linux physical addresses to
  1077. * AS/400 absolute addresses
  1078. */
  1079. phys_mem_size = build_iSeries_Memory_Map();
  1080. iSeries_get_cmdline();
  1081. build_flat_dt(&iseries_dt, phys_mem_size);
  1082. return (void *) __pa(&iseries_dt);
  1083. }
  1084. static void hvputc(char c)
  1085. {
  1086. if (c == '\n')
  1087. hvputc('\r');
  1088. HvCall_writeLogBuffer(&c, 1);
  1089. }
  1090. void __init udbg_init_iseries(void)
  1091. {
  1092. udbg_putc = hvputc;
  1093. }