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