2 * Copyright (c) 2000 Mike Corrigan <mikejc@us.ibm.com>
3 * Copyright (c) 1999-2000 Grant Erickson <grant@lcse.umn.edu>
5 * Module name: iSeries_setup.c
8 * Architecture- / platform-specific boot-time initialization code for
9 * the IBM iSeries LPAR. Adapted from original code by Grant Erickson and
10 * code by Gary Thomas, Cort Dougan <cort@fsmlabs.com>, and Dan Malek
13 * This program is free software; you can redistribute it and/or
14 * modify it under the terms of the GNU General Public License
15 * as published by the Free Software Foundation; either version
16 * 2 of the License, or (at your option) any later version.
21 #include <linux/config.h>
22 #include <linux/init.h>
23 #include <linux/threads.h>
24 #include <linux/smp.h>
25 #include <linux/param.h>
26 #include <linux/string.h>
27 #include <linux/initrd.h>
28 #include <linux/seq_file.h>
29 #include <linux/kdev_t.h>
30 #include <linux/major.h>
31 #include <linux/root_dev.h>
33 #include <asm/processor.h>
34 #include <asm/machdep.h>
37 #include <asm/pgtable.h>
38 #include <asm/mmu_context.h>
39 #include <asm/cputable.h>
40 #include <asm/sections.h>
41 #include <asm/iommu.h>
44 #include "iSeries_setup.h"
47 #include <asm/cache.h>
48 #include <asm/sections.h>
49 #include <asm/abs_addr.h>
50 #include <asm/iSeries/HvCallHpt.h>
51 #include <asm/iSeries/HvLpConfig.h>
52 #include <asm/iSeries/HvCallEvent.h>
53 #include <asm/iSeries/HvCallSm.h>
54 #include <asm/iSeries/HvCallXm.h>
55 #include <asm/iSeries/ItLpQueue.h>
56 #include <asm/iSeries/IoHriMainStore.h>
57 #include <asm/iSeries/mf.h>
58 #include <asm/iSeries/HvLpEvent.h>
59 #include <asm/iSeries/iSeries_irq.h>
60 #include <asm/iSeries/IoHriProcessorVpd.h>
61 #include <asm/iSeries/ItVpdAreas.h>
62 #include <asm/iSeries/LparMap.h>
64 extern void hvlog(char *fmt, ...);
67 #define DBG(fmt...) hvlog(fmt)
72 /* Function Prototypes */
73 extern void ppcdbg_initialize(void);
75 static void build_iSeries_Memory_Map(void);
76 static void setup_iSeries_cache_sizes(void);
77 static void iSeries_bolt_kernel(unsigned long saddr, unsigned long eaddr);
79 extern void iSeries_pci_final_fixup(void);
81 static void iSeries_pci_final_fixup(void) { }
84 /* Global Variables */
85 static unsigned long procFreqHz;
86 static unsigned long procFreqMhz;
87 static unsigned long procFreqMhzHundreths;
89 static unsigned long tbFreqHz;
90 static unsigned long tbFreqMhz;
91 static unsigned long tbFreqMhzHundreths;
93 int piranha_simulator;
95 extern int rd_size; /* Defined in drivers/block/rd.c */
96 extern unsigned long klimit;
97 extern unsigned long embedded_sysmap_start;
98 extern unsigned long embedded_sysmap_end;
100 extern unsigned long iSeries_recal_tb;
101 extern unsigned long iSeries_recal_titan;
103 static int mf_initialized;
106 unsigned long absStart;
107 unsigned long absEnd;
108 unsigned long logicalStart;
109 unsigned long logicalEnd;
113 * Process the main store vpd to determine where the holes in memory are
114 * and return the number of physical blocks and fill in the array of
117 static unsigned long iSeries_process_Condor_mainstore_vpd(
118 struct MemoryBlock *mb_array, unsigned long max_entries)
120 unsigned long holeFirstChunk, holeSizeChunks;
121 unsigned long numMemoryBlocks = 1;
122 struct IoHriMainStoreSegment4 *msVpd =
123 (struct IoHriMainStoreSegment4 *)xMsVpd;
124 unsigned long holeStart = msVpd->nonInterleavedBlocksStartAdr;
125 unsigned long holeEnd = msVpd->nonInterleavedBlocksEndAdr;
126 unsigned long holeSize = holeEnd - holeStart;
128 printk("Mainstore_VPD: Condor\n");
130 * Determine if absolute memory has any
131 * holes so that we can interpret the
132 * access map we get back from the hypervisor
135 mb_array[0].logicalStart = 0;
136 mb_array[0].logicalEnd = 0x100000000;
137 mb_array[0].absStart = 0;
138 mb_array[0].absEnd = 0x100000000;
142 holeStart = holeStart & 0x000fffffffffffff;
143 holeStart = addr_to_chunk(holeStart);
144 holeFirstChunk = holeStart;
145 holeSize = addr_to_chunk(holeSize);
146 holeSizeChunks = holeSize;
147 printk( "Main store hole: start chunk = %0lx, size = %0lx chunks\n",
148 holeFirstChunk, holeSizeChunks );
149 mb_array[0].logicalEnd = holeFirstChunk;
150 mb_array[0].absEnd = holeFirstChunk;
151 mb_array[1].logicalStart = holeFirstChunk;
152 mb_array[1].logicalEnd = 0x100000000 - holeSizeChunks;
153 mb_array[1].absStart = holeFirstChunk + holeSizeChunks;
154 mb_array[1].absEnd = 0x100000000;
156 return numMemoryBlocks;
159 #define MaxSegmentAreas 32
160 #define MaxSegmentAdrRangeBlocks 128
161 #define MaxAreaRangeBlocks 4
163 static unsigned long iSeries_process_Regatta_mainstore_vpd(
164 struct MemoryBlock *mb_array, unsigned long max_entries)
166 struct IoHriMainStoreSegment5 *msVpdP =
167 (struct IoHriMainStoreSegment5 *)xMsVpd;
168 unsigned long numSegmentBlocks = 0;
169 u32 existsBits = msVpdP->msAreaExists;
170 unsigned long area_num;
172 printk("Mainstore_VPD: Regatta\n");
174 for (area_num = 0; area_num < MaxSegmentAreas; ++area_num ) {
175 unsigned long numAreaBlocks;
176 struct IoHriMainStoreArea4 *currentArea;
178 if (existsBits & 0x80000000) {
179 unsigned long block_num;
181 currentArea = &msVpdP->msAreaArray[area_num];
182 numAreaBlocks = currentArea->numAdrRangeBlocks;
183 printk("ms_vpd: processing area %2ld blocks=%ld",
184 area_num, numAreaBlocks);
185 for (block_num = 0; block_num < numAreaBlocks;
187 /* Process an address range block */
188 struct MemoryBlock tempBlock;
192 (unsigned long)currentArea->xAdrRangeBlock[block_num].blockStart;
194 (unsigned long)currentArea->xAdrRangeBlock[block_num].blockEnd;
195 tempBlock.logicalStart = 0;
196 tempBlock.logicalEnd = 0;
197 printk("\n block %ld absStart=%016lx absEnd=%016lx",
198 block_num, tempBlock.absStart,
201 for (i = 0; i < numSegmentBlocks; ++i) {
202 if (mb_array[i].absStart ==
206 if (i == numSegmentBlocks) {
207 if (numSegmentBlocks == max_entries)
208 panic("iSeries_process_mainstore_vpd: too many memory blocks");
209 mb_array[numSegmentBlocks] = tempBlock;
212 printk(" (duplicate)");
218 /* Now sort the blocks found into ascending sequence */
219 if (numSegmentBlocks > 1) {
222 for (m = 0; m < numSegmentBlocks - 1; ++m) {
223 for (n = numSegmentBlocks - 1; m < n; --n) {
224 if (mb_array[n].absStart <
225 mb_array[n-1].absStart) {
226 struct MemoryBlock tempBlock;
228 tempBlock = mb_array[n];
229 mb_array[n] = mb_array[n-1];
230 mb_array[n-1] = tempBlock;
236 * Assign "logical" addresses to each block. These
237 * addresses correspond to the hypervisor "bitmap" space.
238 * Convert all addresses into units of 256K chunks.
241 unsigned long i, nextBitmapAddress;
243 printk("ms_vpd: %ld sorted memory blocks\n", numSegmentBlocks);
244 nextBitmapAddress = 0;
245 for (i = 0; i < numSegmentBlocks; ++i) {
246 unsigned long length = mb_array[i].absEnd -
247 mb_array[i].absStart;
249 mb_array[i].logicalStart = nextBitmapAddress;
250 mb_array[i].logicalEnd = nextBitmapAddress + length;
251 nextBitmapAddress += length;
252 printk(" Bitmap range: %016lx - %016lx\n"
253 " Absolute range: %016lx - %016lx\n",
254 mb_array[i].logicalStart,
255 mb_array[i].logicalEnd,
256 mb_array[i].absStart, mb_array[i].absEnd);
257 mb_array[i].absStart = addr_to_chunk(mb_array[i].absStart &
259 mb_array[i].absEnd = addr_to_chunk(mb_array[i].absEnd &
261 mb_array[i].logicalStart =
262 addr_to_chunk(mb_array[i].logicalStart);
263 mb_array[i].logicalEnd = addr_to_chunk(mb_array[i].logicalEnd);
267 return numSegmentBlocks;
270 static unsigned long iSeries_process_mainstore_vpd(struct MemoryBlock *mb_array,
271 unsigned long max_entries)
274 unsigned long mem_blocks = 0;
276 if (cpu_has_feature(CPU_FTR_SLB))
277 mem_blocks = iSeries_process_Regatta_mainstore_vpd(mb_array,
280 mem_blocks = iSeries_process_Condor_mainstore_vpd(mb_array,
283 printk("Mainstore_VPD: numMemoryBlocks = %ld \n", mem_blocks);
284 for (i = 0; i < mem_blocks; ++i) {
285 printk("Mainstore_VPD: block %3ld logical chunks %016lx - %016lx\n"
286 " abs chunks %016lx - %016lx\n",
287 i, mb_array[i].logicalStart, mb_array[i].logicalEnd,
288 mb_array[i].absStart, mb_array[i].absEnd);
293 static void __init iSeries_get_cmdline(void)
297 /* copy the command line parameter from the primary VSP */
298 HvCallEvent_dmaToSp(cmd_line, 2 * 64* 1024, 256,
299 HvLpDma_Direction_RemoteToLocal);
304 if (!*p || *p == '\n')
311 static void __init iSeries_init_early(void)
313 extern unsigned long memory_limit;
315 DBG(" -> iSeries_init_early()\n");
319 #if defined(CONFIG_BLK_DEV_INITRD)
321 * If the init RAM disk has been configured and there is
322 * a non-zero starting address for it, set it up
325 initrd_start = (unsigned long)__va(naca.xRamDisk);
326 initrd_end = initrd_start + naca.xRamDiskSize * PAGE_SIZE;
327 initrd_below_start_ok = 1; // ramdisk in kernel space
328 ROOT_DEV = Root_RAM0;
329 if (((rd_size * 1024) / PAGE_SIZE) < naca.xRamDiskSize)
330 rd_size = (naca.xRamDiskSize * PAGE_SIZE) / 1024;
332 #endif /* CONFIG_BLK_DEV_INITRD */
334 /* ROOT_DEV = MKDEV(VIODASD_MAJOR, 1); */
337 iSeries_recal_tb = get_tb();
338 iSeries_recal_titan = HvCallXm_loadTod();
341 * Cache sizes must be initialized before hpte_init_iSeries is called
342 * as the later need them for flush_icache_range()
344 setup_iSeries_cache_sizes();
347 * Initialize the hash table management pointers
352 * Initialize the DMA/TCE management
354 iommu_init_early_iSeries();
357 * Initialize the table which translate Linux physical addresses to
358 * AS/400 absolute addresses
360 build_iSeries_Memory_Map();
362 iSeries_get_cmdline();
364 /* Save unparsed command line copy for /proc/cmdline */
365 strlcpy(saved_command_line, cmd_line, COMMAND_LINE_SIZE);
367 /* Parse early parameters, in particular mem=x */
371 if (memory_limit < systemcfg->physicalMemorySize)
372 systemcfg->physicalMemorySize = memory_limit;
374 printk("Ignoring mem=%lu >= ram_top.\n", memory_limit);
379 /* Bolt kernel mappings for all of memory (or just a bit if we've got a limit) */
380 iSeries_bolt_kernel(0, systemcfg->physicalMemorySize);
383 lmb_add(0, systemcfg->physicalMemorySize);
385 lmb_reserve(0, __pa(klimit));
387 /* Initialize machine-dependency vectors */
391 if (itLpNaca.xPirEnvironMode == 0)
392 piranha_simulator = 1;
394 /* Associate Lp Event Queue 0 with processor 0 */
395 HvCallEvent_setLpEventQueueInterruptProc(0, 0);
401 /* If we were passed an initrd, set the ROOT_DEV properly if the values
402 * look sensible. If not, clear initrd reference.
404 #ifdef CONFIG_BLK_DEV_INITRD
405 if (initrd_start >= KERNELBASE && initrd_end >= KERNELBASE &&
406 initrd_end > initrd_start)
407 ROOT_DEV = Root_RAM0;
409 initrd_start = initrd_end = 0;
410 #endif /* CONFIG_BLK_DEV_INITRD */
412 DBG(" <- iSeries_init_early()\n");
416 * The iSeries may have very large memories ( > 128 GB ) and a partition
417 * may get memory in "chunks" that may be anywhere in the 2**52 real
418 * address space. The chunks are 256K in size. To map this to the
419 * memory model Linux expects, the AS/400 specific code builds a
420 * translation table to translate what Linux thinks are "physical"
421 * addresses to the actual real addresses. This allows us to make
422 * it appear to Linux that we have contiguous memory starting at
423 * physical address zero while in fact this could be far from the truth.
424 * To avoid confusion, I'll let the words physical and/or real address
425 * apply to the Linux addresses while I'll use "absolute address" to
426 * refer to the actual hardware real address.
428 * build_iSeries_Memory_Map gets information from the Hypervisor and
429 * looks at the Main Store VPD to determine the absolute addresses
430 * of the memory that has been assigned to our partition and builds
431 * a table used to translate Linux's physical addresses to these
432 * absolute addresses. Absolute addresses are needed when
433 * communicating with the hypervisor (e.g. to build HPT entries)
436 static void __init build_iSeries_Memory_Map(void)
438 u32 loadAreaFirstChunk, loadAreaLastChunk, loadAreaSize;
440 u32 hptFirstChunk, hptLastChunk, hptSizeChunks, hptSizePages;
442 u32 totalChunks,moreChunks;
443 u32 currChunk, thisChunk, absChunk;
447 struct MemoryBlock mb[32];
448 unsigned long numMemoryBlocks, curBlock;
450 /* Chunk size on iSeries is 256K bytes */
451 totalChunks = (u32)HvLpConfig_getMsChunks();
452 klimit = msChunks_alloc(klimit, totalChunks, 1UL << 18);
455 * Get absolute address of our load area
456 * and map it to physical address 0
457 * This guarantees that the loadarea ends up at physical 0
458 * otherwise, it might not be returned by PLIC as the first
462 loadAreaFirstChunk = (u32)addr_to_chunk(itLpNaca.xLoadAreaAddr);
463 loadAreaSize = itLpNaca.xLoadAreaChunks;
466 * Only add the pages already mapped here.
467 * Otherwise we might add the hpt pages
468 * The rest of the pages of the load area
469 * aren't in the HPT yet and can still
470 * be assigned an arbitrary physical address
472 if ((loadAreaSize * 64) > HvPagesToMap)
473 loadAreaSize = HvPagesToMap / 64;
475 loadAreaLastChunk = loadAreaFirstChunk + loadAreaSize - 1;
478 * TODO Do we need to do something if the HPT is in the 64MB load area?
479 * This would be required if the itLpNaca.xLoadAreaChunks includes
483 printk("Mapping load area - physical addr = 0000000000000000\n"
484 " absolute addr = %016lx\n",
485 chunk_to_addr(loadAreaFirstChunk));
486 printk("Load area size %dK\n", loadAreaSize * 256);
488 for (nextPhysChunk = 0; nextPhysChunk < loadAreaSize; ++nextPhysChunk)
489 msChunks.abs[nextPhysChunk] =
490 loadAreaFirstChunk + nextPhysChunk;
493 * Get absolute address of our HPT and remember it so
494 * we won't map it to any physical address
496 hptFirstChunk = (u32)addr_to_chunk(HvCallHpt_getHptAddress());
497 hptSizePages = (u32)HvCallHpt_getHptPages();
498 hptSizeChunks = hptSizePages >> (msChunks.chunk_shift - PAGE_SHIFT);
499 hptLastChunk = hptFirstChunk + hptSizeChunks - 1;
501 printk("HPT absolute addr = %016lx, size = %dK\n",
502 chunk_to_addr(hptFirstChunk), hptSizeChunks * 256);
504 /* Fill in the hashed page table hash mask */
505 num_ptegs = hptSizePages *
506 (PAGE_SIZE / (sizeof(HPTE) * HPTES_PER_GROUP));
507 htab_hash_mask = num_ptegs - 1;
510 * The actual hashed page table is in the hypervisor,
511 * we have no direct access
516 * Determine if absolute memory has any
517 * holes so that we can interpret the
518 * access map we get back from the hypervisor
521 numMemoryBlocks = iSeries_process_mainstore_vpd(mb, 32);
524 * Process the main store access map from the hypervisor
525 * to build up our physical -> absolute translation table
530 moreChunks = totalChunks;
533 map = HvCallSm_get64BitsOfAccessMap(itLpNaca.xLpIndex,
535 thisChunk = currChunk;
537 chunkBit = map >> 63;
541 while (thisChunk >= mb[curBlock].logicalEnd) {
543 if (curBlock >= numMemoryBlocks)
544 panic("out of memory blocks");
546 if (thisChunk < mb[curBlock].logicalStart)
547 panic("memory block error");
549 absChunk = mb[curBlock].absStart +
550 (thisChunk - mb[curBlock].logicalStart);
551 if (((absChunk < hptFirstChunk) ||
552 (absChunk > hptLastChunk)) &&
553 ((absChunk < loadAreaFirstChunk) ||
554 (absChunk > loadAreaLastChunk))) {
555 msChunks.abs[nextPhysChunk] = absChunk;
566 * main store size (in chunks) is
567 * totalChunks - hptSizeChunks
568 * which should be equal to
571 systemcfg->physicalMemorySize = chunk_to_addr(nextPhysChunk);
575 * Set up the variables that describe the cache line sizes
578 static void __init setup_iSeries_cache_sizes(void)
581 unsigned int procIx = get_paca()->lppaca.dyn_hv_phys_proc_index;
583 systemcfg->icache_size =
584 ppc64_caches.isize = xIoHriProcessorVpd[procIx].xInstCacheSize * 1024;
585 systemcfg->icache_line_size =
586 ppc64_caches.iline_size =
587 xIoHriProcessorVpd[procIx].xInstCacheOperandSize;
588 systemcfg->dcache_size =
590 xIoHriProcessorVpd[procIx].xDataL1CacheSizeKB * 1024;
591 systemcfg->dcache_line_size =
592 ppc64_caches.dline_size =
593 xIoHriProcessorVpd[procIx].xDataCacheOperandSize;
594 ppc64_caches.ilines_per_page = PAGE_SIZE / ppc64_caches.iline_size;
595 ppc64_caches.dlines_per_page = PAGE_SIZE / ppc64_caches.dline_size;
597 i = ppc64_caches.iline_size;
599 while ((i = (i / 2)))
601 ppc64_caches.log_iline_size = n;
603 i = ppc64_caches.dline_size;
605 while ((i = (i / 2)))
607 ppc64_caches.log_dline_size = n;
609 printk("D-cache line size = %d\n",
610 (unsigned int)ppc64_caches.dline_size);
611 printk("I-cache line size = %d\n",
612 (unsigned int)ppc64_caches.iline_size);
616 * Create a pte. Used during initialization only.
618 static void iSeries_make_pte(unsigned long va, unsigned long pa,
621 HPTE local_hpte, rhpte;
622 unsigned long hash, vpn;
625 vpn = va >> PAGE_SHIFT;
626 hash = hpt_hash(vpn, 0);
628 local_hpte.dw1.dword1 = pa | mode;
629 local_hpte.dw0.dword0 = 0;
630 local_hpte.dw0.dw0.avpn = va >> 23;
631 local_hpte.dw0.dw0.bolted = 1; /* bolted */
632 local_hpte.dw0.dw0.v = 1;
634 slot = HvCallHpt_findValid(&rhpte, vpn);
636 /* Must find space in primary group */
637 panic("hash_page: hpte already exists\n");
639 HvCallHpt_addValidate(slot, 0, (HPTE *)&local_hpte );
643 * Bolt the kernel addr space into the HPT
645 static void __init iSeries_bolt_kernel(unsigned long saddr, unsigned long eaddr)
648 unsigned long mode_rw = _PAGE_ACCESSED | _PAGE_COHERENT | PP_RWXX;
651 for (pa = saddr; pa < eaddr ;pa += PAGE_SIZE) {
652 unsigned long ea = (unsigned long)__va(pa);
653 unsigned long vsid = get_kernel_vsid(ea);
654 unsigned long va = (vsid << 28) | (pa & 0xfffffff);
655 unsigned long vpn = va >> PAGE_SHIFT;
656 unsigned long slot = HvCallHpt_findValid(&hpte, vpn);
658 /* Make non-kernel text non-executable */
659 if (!in_kernel_text(ea))
660 mode_rw |= HW_NO_EXEC;
662 if (hpte.dw0.dw0.v) {
663 /* HPTE exists, so just bolt it */
664 HvCallHpt_setSwBits(slot, 0x10, 0);
665 /* And make sure the pp bits are correct */
666 HvCallHpt_setPp(slot, PP_RWXX);
668 /* No HPTE exists, so create a new bolted one */
669 iSeries_make_pte(va, phys_to_abs(pa), mode_rw);
676 static void __init iSeries_setup_arch(void)
678 unsigned procIx = get_paca()->lppaca.dyn_hv_phys_proc_index;
680 /* Add an eye catcher and the systemcfg layout version number */
681 strcpy(systemcfg->eye_catcher, "SYSTEMCFG:PPC64");
682 systemcfg->version.major = SYSTEMCFG_MAJOR;
683 systemcfg->version.minor = SYSTEMCFG_MINOR;
685 /* Setup the Lp Event Queue */
686 setup_hvlpevent_queue();
688 /* Compute processor frequency */
689 procFreqHz = ((1UL << 34) * 1000000) /
690 xIoHriProcessorVpd[procIx].xProcFreq;
691 procFreqMhz = procFreqHz / 1000000;
692 procFreqMhzHundreths = (procFreqHz / 10000) - (procFreqMhz * 100);
693 ppc_proc_freq = procFreqHz;
695 /* Compute time base frequency */
696 tbFreqHz = ((1UL << 32) * 1000000) /
697 xIoHriProcessorVpd[procIx].xTimeBaseFreq;
698 tbFreqMhz = tbFreqHz / 1000000;
699 tbFreqMhzHundreths = (tbFreqHz / 10000) - (tbFreqMhz * 100);
700 ppc_tb_freq = tbFreqHz;
702 printk("Max logical processors = %d\n",
703 itVpdAreas.xSlicMaxLogicalProcs);
704 printk("Max physical processors = %d\n",
705 itVpdAreas.xSlicMaxPhysicalProcs);
706 printk("Processor frequency = %lu.%02lu\n", procFreqMhz,
707 procFreqMhzHundreths);
708 printk("Time base frequency = %lu.%02lu\n", tbFreqMhz,
710 systemcfg->processor = xIoHriProcessorVpd[procIx].xPVR;
711 printk("Processor version = %x\n", systemcfg->processor);
714 static void iSeries_get_cpuinfo(struct seq_file *m)
716 seq_printf(m, "machine\t\t: 64-bit iSeries Logical Partition\n");
723 static int iSeries_get_irq(struct pt_regs *regs)
725 /* -2 means ignore this interrupt */
732 static void iSeries_restart(char *cmd)
740 static void iSeries_power_off(void)
748 static void iSeries_halt(void)
754 * void __init iSeries_calibrate_decr()
757 * This routine retrieves the internal processor frequency from the VPD,
758 * and sets up the kernel timer decrementer based on that value.
761 static void __init iSeries_calibrate_decr(void)
763 unsigned long cyclesPerUsec;
764 struct div_result divres;
766 /* Compute decrementer (and TB) frequency in cycles/sec */
767 cyclesPerUsec = ppc_tb_freq / 1000000;
770 * Set the amount to refresh the decrementer by. This
771 * is the number of decrementer ticks it takes for
774 tb_ticks_per_jiffy = ppc_tb_freq / HZ;
777 /* TEST CODE FOR ADJTIME */
778 tb_ticks_per_jiffy += tb_ticks_per_jiffy / 5000;
779 /* END OF TEST CODE */
783 * tb_ticks_per_sec = freq; would give better accuracy
784 * but tb_ticks_per_sec = tb_ticks_per_jiffy*HZ; assures
785 * that jiffies (and xtime) will match the time returned
786 * by do_gettimeofday.
788 tb_ticks_per_sec = tb_ticks_per_jiffy * HZ;
789 tb_ticks_per_usec = cyclesPerUsec;
790 tb_to_us = mulhwu_scale_factor(ppc_tb_freq, 1000000);
791 div128_by_32(1024 * 1024, 0, tb_ticks_per_sec, &divres);
792 tb_to_xs = divres.result_low;
793 setup_default_decr();
796 static void __init iSeries_progress(char * st, unsigned short code)
798 printk("Progress: [%04x] - %s\n", (unsigned)code, st);
799 if (!piranha_simulator && mf_initialized) {
801 mf_display_progress(code);
807 static void __init iSeries_fixup_klimit(void)
810 * Change klimit to take into account any ram disk
811 * that may be included
814 klimit = KERNELBASE + (u64)naca.xRamDisk +
815 (naca.xRamDiskSize * PAGE_SIZE);
818 * No ram disk was included - check and see if there
819 * was an embedded system map. Change klimit to take
820 * into account any embedded system map
822 if (embedded_sysmap_end)
823 klimit = KERNELBASE + ((embedded_sysmap_end + 4095) &
828 static int __init iSeries_src_init(void)
830 /* clear the progress line */
831 ppc_md.progress(" ", 0xffff);
835 late_initcall(iSeries_src_init);
837 static unsigned long maxYieldTime = 0;
838 static unsigned long minYieldTime = 0xffffffffffffffffUL;
840 static inline void process_iSeries_events(void)
842 asm volatile ("li 0,0x5555; sc" : : : "r0", "r3");
845 static void yield_shared_processor(void)
848 unsigned long yieldTime;
850 HvCall_setEnabledInterrupts(HvCall_MaskIPI |
856 /* Compute future tb value when yield should expire */
857 HvCall_yieldProcessor(HvCall_YieldTimed, tb+tb_ticks_per_jiffy);
859 yieldTime = get_tb() - tb;
860 if (yieldTime > maxYieldTime)
861 maxYieldTime = yieldTime;
863 if (yieldTime < minYieldTime)
864 minYieldTime = yieldTime;
867 * The decrementer stops during the yield. Force a fake decrementer
868 * here and let the timer_interrupt code sort out the actual time.
870 get_paca()->lppaca.int_dword.fields.decr_int = 1;
871 process_iSeries_events();
874 static int iSeries_idle(void)
876 struct paca_struct *lpaca;
879 /* ensure iSeries run light will be out when idle */
880 ppc64_runlatch_off();
885 if (lpaca->lppaca.shared_proc) {
886 if (hvlpevent_is_pending())
887 process_iSeries_events();
889 yield_shared_processor();
891 oldval = test_and_clear_thread_flag(TIF_NEED_RESCHED);
894 set_thread_flag(TIF_POLLING_NRFLAG);
896 while (!need_resched()) {
898 if (hvlpevent_is_pending())
899 process_iSeries_events();
904 clear_thread_flag(TIF_POLLING_NRFLAG);
912 ppc64_runlatch_off();
919 void __init iSeries_init_IRQ(void) { }
922 void __init iSeries_early_setup(void)
924 iSeries_fixup_klimit();
926 ppc_md.setup_arch = iSeries_setup_arch;
927 ppc_md.get_cpuinfo = iSeries_get_cpuinfo;
928 ppc_md.init_IRQ = iSeries_init_IRQ;
929 ppc_md.get_irq = iSeries_get_irq;
930 ppc_md.init_early = iSeries_init_early,
932 ppc_md.pcibios_fixup = iSeries_pci_final_fixup;
934 ppc_md.restart = iSeries_restart;
935 ppc_md.power_off = iSeries_power_off;
936 ppc_md.halt = iSeries_halt;
938 ppc_md.get_boot_time = iSeries_get_boot_time;
939 ppc_md.set_rtc_time = iSeries_set_rtc_time;
940 ppc_md.get_rtc_time = iSeries_get_rtc_time;
941 ppc_md.calibrate_decr = iSeries_calibrate_decr;
942 ppc_md.progress = iSeries_progress;