blob: 617c724c4590841df47f43e1512743db0d155f62 [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 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07005 * 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
17#undef DEBUG
18
19#include <linux/config.h>
20#include <linux/init.h>
21#include <linux/threads.h>
22#include <linux/smp.h>
23#include <linux/param.h>
24#include <linux/string.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070025#include <linux/initrd.h>
26#include <linux/seq_file.h>
27#include <linux/kdev_t.h>
28#include <linux/major.h>
29#include <linux/root_dev.h>
Stephen Rothwellbec7c452005-11-01 11:45:19 +110030#include <linux/kernel.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070031
32#include <asm/processor.h>
33#include <asm/machdep.h>
34#include <asm/page.h>
35#include <asm/mmu.h>
36#include <asm/pgtable.h>
37#include <asm/mmu_context.h>
38#include <asm/cputable.h>
39#include <asm/sections.h>
40#include <asm/iommu.h>
Stephen Rothwellaed31352005-08-03 14:43:21 +100041#include <asm/firmware.h>
Paul Mackerras49b09852005-11-10 15:53:40 +110042#include <asm/system.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070043#include <asm/time.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070044#include <asm/paca.h>
45#include <asm/cache.h>
46#include <asm/sections.h>
Stephen Rothwell0bc0ffd2005-06-21 17:15:36 -070047#include <asm/abs_addr.h>
Kelly Daly15b17182005-11-02 11:55:28 +110048#include <asm/iseries/hv_lp_config.h>
Kelly Dalyc0a8d052005-11-02 11:11:11 +110049#include <asm/iseries/hv_call_event.h>
Kelly Daly8021b8a2005-11-02 11:41:12 +110050#include <asm/iseries/hv_call_xm.h>
Kelly Daly8875ccf2005-11-02 14:13:34 +110051#include <asm/iseries/it_lp_queue.h>
Kelly Dalybbc8b622005-11-02 15:10:38 +110052#include <asm/iseries/mf.h>
Kelly Dalye45423e2005-11-02 12:08:31 +110053#include <asm/iseries/hv_lp_event.h>
Kelly Dalyc43a55f2005-11-02 15:02:47 +110054#include <asm/iseries/lpar_map.h>
Michael Ellermanbf6a7112006-01-11 11:54:08 +110055#include <asm/udbg.h>
Stephen Rothwell7d01c882006-04-04 14:49:48 +100056#include <asm/irq.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070057
David Gibsonf11b7bd2005-11-01 15:30:26 +110058#include "naca.h"
Stephen Rothwellc8b84972005-09-27 18:44:42 +100059#include "setup.h"
Stephen Rothwellb08567cb2005-09-28 23:37:01 +100060#include "irq.h"
61#include "vpd_areas.h"
62#include "processor_vpd.h"
63#include "main_store.h"
64#include "call_sm.h"
Stephen Rothwell0e29bb12005-10-14 17:09:16 +100065#include "call_hpt.h"
Stephen Rothwellc8b84972005-09-27 18:44:42 +100066
Linus Torvalds1da177e2005-04-16 15:20:36 -070067#ifdef DEBUG
Michael Ellermanbf6a7112006-01-11 11:54:08 +110068#define DBG(fmt...) udbg_printf(fmt)
Linus Torvalds1da177e2005-04-16 15:20:36 -070069#else
70#define DBG(fmt...)
71#endif
72
73/* Function Prototypes */
Paul Mackerras799d6042005-11-10 13:37:51 +110074static unsigned long build_iSeries_Memory_Map(void);
Paul Mackerras143a1de2005-10-19 23:11:21 +100075static void iseries_shared_idle(void);
76static void iseries_dedicated_idle(void);
Stephen Rothwell145d01e2005-06-21 17:15:52 -070077#ifdef CONFIG_PCI
Linus Torvalds1da177e2005-04-16 15:20:36 -070078extern void iSeries_pci_final_fixup(void);
Stephen Rothwell145d01e2005-06-21 17:15:52 -070079#else
80static void iSeries_pci_final_fixup(void) { }
81#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070082
Linus Torvalds1da177e2005-04-16 15:20:36 -070083extern int rd_size; /* Defined in drivers/block/rd.c */
Linus Torvalds1da177e2005-04-16 15:20:36 -070084extern unsigned long embedded_sysmap_start;
85extern unsigned long embedded_sysmap_end;
86
87extern unsigned long iSeries_recal_tb;
88extern unsigned long iSeries_recal_titan;
89
Linus Torvalds1da177e2005-04-16 15:20:36 -070090struct MemoryBlock {
91 unsigned long absStart;
92 unsigned long absEnd;
93 unsigned long logicalStart;
94 unsigned long logicalEnd;
95};
96
97/*
98 * Process the main store vpd to determine where the holes in memory are
99 * and return the number of physical blocks and fill in the array of
100 * block data.
101 */
102static unsigned long iSeries_process_Condor_mainstore_vpd(
103 struct MemoryBlock *mb_array, unsigned long max_entries)
104{
105 unsigned long holeFirstChunk, holeSizeChunks;
106 unsigned long numMemoryBlocks = 1;
107 struct IoHriMainStoreSegment4 *msVpd =
108 (struct IoHriMainStoreSegment4 *)xMsVpd;
109 unsigned long holeStart = msVpd->nonInterleavedBlocksStartAdr;
110 unsigned long holeEnd = msVpd->nonInterleavedBlocksEndAdr;
111 unsigned long holeSize = holeEnd - holeStart;
112
113 printk("Mainstore_VPD: Condor\n");
114 /*
115 * Determine if absolute memory has any
116 * holes so that we can interpret the
117 * access map we get back from the hypervisor
118 * correctly.
119 */
120 mb_array[0].logicalStart = 0;
121 mb_array[0].logicalEnd = 0x100000000;
122 mb_array[0].absStart = 0;
123 mb_array[0].absEnd = 0x100000000;
124
125 if (holeSize) {
126 numMemoryBlocks = 2;
127 holeStart = holeStart & 0x000fffffffffffff;
128 holeStart = addr_to_chunk(holeStart);
129 holeFirstChunk = holeStart;
130 holeSize = addr_to_chunk(holeSize);
131 holeSizeChunks = holeSize;
132 printk( "Main store hole: start chunk = %0lx, size = %0lx chunks\n",
133 holeFirstChunk, holeSizeChunks );
134 mb_array[0].logicalEnd = holeFirstChunk;
135 mb_array[0].absEnd = holeFirstChunk;
136 mb_array[1].logicalStart = holeFirstChunk;
137 mb_array[1].logicalEnd = 0x100000000 - holeSizeChunks;
138 mb_array[1].absStart = holeFirstChunk + holeSizeChunks;
139 mb_array[1].absEnd = 0x100000000;
140 }
141 return numMemoryBlocks;
142}
143
144#define MaxSegmentAreas 32
145#define MaxSegmentAdrRangeBlocks 128
146#define MaxAreaRangeBlocks 4
147
148static unsigned long iSeries_process_Regatta_mainstore_vpd(
149 struct MemoryBlock *mb_array, unsigned long max_entries)
150{
151 struct IoHriMainStoreSegment5 *msVpdP =
152 (struct IoHriMainStoreSegment5 *)xMsVpd;
153 unsigned long numSegmentBlocks = 0;
154 u32 existsBits = msVpdP->msAreaExists;
155 unsigned long area_num;
156
157 printk("Mainstore_VPD: Regatta\n");
158
159 for (area_num = 0; area_num < MaxSegmentAreas; ++area_num ) {
160 unsigned long numAreaBlocks;
161 struct IoHriMainStoreArea4 *currentArea;
162
163 if (existsBits & 0x80000000) {
164 unsigned long block_num;
165
166 currentArea = &msVpdP->msAreaArray[area_num];
167 numAreaBlocks = currentArea->numAdrRangeBlocks;
168 printk("ms_vpd: processing area %2ld blocks=%ld",
169 area_num, numAreaBlocks);
170 for (block_num = 0; block_num < numAreaBlocks;
171 ++block_num ) {
172 /* Process an address range block */
173 struct MemoryBlock tempBlock;
174 unsigned long i;
175
176 tempBlock.absStart =
177 (unsigned long)currentArea->xAdrRangeBlock[block_num].blockStart;
178 tempBlock.absEnd =
179 (unsigned long)currentArea->xAdrRangeBlock[block_num].blockEnd;
180 tempBlock.logicalStart = 0;
181 tempBlock.logicalEnd = 0;
182 printk("\n block %ld absStart=%016lx absEnd=%016lx",
183 block_num, tempBlock.absStart,
184 tempBlock.absEnd);
185
186 for (i = 0; i < numSegmentBlocks; ++i) {
187 if (mb_array[i].absStart ==
188 tempBlock.absStart)
189 break;
190 }
191 if (i == numSegmentBlocks) {
192 if (numSegmentBlocks == max_entries)
193 panic("iSeries_process_mainstore_vpd: too many memory blocks");
194 mb_array[numSegmentBlocks] = tempBlock;
195 ++numSegmentBlocks;
196 } else
197 printk(" (duplicate)");
198 }
199 printk("\n");
200 }
201 existsBits <<= 1;
202 }
203 /* Now sort the blocks found into ascending sequence */
204 if (numSegmentBlocks > 1) {
205 unsigned long m, n;
206
207 for (m = 0; m < numSegmentBlocks - 1; ++m) {
208 for (n = numSegmentBlocks - 1; m < n; --n) {
209 if (mb_array[n].absStart <
210 mb_array[n-1].absStart) {
211 struct MemoryBlock tempBlock;
212
213 tempBlock = mb_array[n];
214 mb_array[n] = mb_array[n-1];
215 mb_array[n-1] = tempBlock;
216 }
217 }
218 }
219 }
220 /*
221 * Assign "logical" addresses to each block. These
222 * addresses correspond to the hypervisor "bitmap" space.
223 * Convert all addresses into units of 256K chunks.
224 */
225 {
226 unsigned long i, nextBitmapAddress;
227
228 printk("ms_vpd: %ld sorted memory blocks\n", numSegmentBlocks);
229 nextBitmapAddress = 0;
230 for (i = 0; i < numSegmentBlocks; ++i) {
231 unsigned long length = mb_array[i].absEnd -
232 mb_array[i].absStart;
233
234 mb_array[i].logicalStart = nextBitmapAddress;
235 mb_array[i].logicalEnd = nextBitmapAddress + length;
236 nextBitmapAddress += length;
237 printk(" Bitmap range: %016lx - %016lx\n"
238 " Absolute range: %016lx - %016lx\n",
239 mb_array[i].logicalStart,
240 mb_array[i].logicalEnd,
241 mb_array[i].absStart, mb_array[i].absEnd);
242 mb_array[i].absStart = addr_to_chunk(mb_array[i].absStart &
243 0x000fffffffffffff);
244 mb_array[i].absEnd = addr_to_chunk(mb_array[i].absEnd &
245 0x000fffffffffffff);
246 mb_array[i].logicalStart =
247 addr_to_chunk(mb_array[i].logicalStart);
248 mb_array[i].logicalEnd = addr_to_chunk(mb_array[i].logicalEnd);
249 }
250 }
251
252 return numSegmentBlocks;
253}
254
255static unsigned long iSeries_process_mainstore_vpd(struct MemoryBlock *mb_array,
256 unsigned long max_entries)
257{
258 unsigned long i;
259 unsigned long mem_blocks = 0;
260
261 if (cpu_has_feature(CPU_FTR_SLB))
262 mem_blocks = iSeries_process_Regatta_mainstore_vpd(mb_array,
263 max_entries);
264 else
265 mem_blocks = iSeries_process_Condor_mainstore_vpd(mb_array,
266 max_entries);
267
268 printk("Mainstore_VPD: numMemoryBlocks = %ld \n", mem_blocks);
269 for (i = 0; i < mem_blocks; ++i) {
270 printk("Mainstore_VPD: block %3ld logical chunks %016lx - %016lx\n"
271 " abs chunks %016lx - %016lx\n",
272 i, mb_array[i].logicalStart, mb_array[i].logicalEnd,
273 mb_array[i].absStart, mb_array[i].absEnd);
274 }
275 return mem_blocks;
276}
277
278static void __init iSeries_get_cmdline(void)
279{
280 char *p, *q;
281
282 /* copy the command line parameter from the primary VSP */
283 HvCallEvent_dmaToSp(cmd_line, 2 * 64* 1024, 256,
284 HvLpDma_Direction_RemoteToLocal);
285
286 p = cmd_line;
287 q = cmd_line + 255;
288 while(p < q) {
289 if (!*p || *p == '\n')
290 break;
291 ++p;
292 }
293 *p = 0;
294}
295
296static void __init iSeries_init_early(void)
297{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700298 DBG(" -> iSeries_init_early()\n");
299
Michael Ellermanba293ff2005-09-23 14:43:22 +1000300 ppc64_interrupt_controller = IC_ISERIES;
301
Linus Torvalds1da177e2005-04-16 15:20:36 -0700302#if defined(CONFIG_BLK_DEV_INITRD)
303 /*
304 * If the init RAM disk has been configured and there is
305 * a non-zero starting address for it, set it up
306 */
307 if (naca.xRamDisk) {
308 initrd_start = (unsigned long)__va(naca.xRamDisk);
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100309 initrd_end = initrd_start + naca.xRamDiskSize * HW_PAGE_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310 initrd_below_start_ok = 1; // ramdisk in kernel space
311 ROOT_DEV = Root_RAM0;
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100312 if (((rd_size * 1024) / HW_PAGE_SIZE) < naca.xRamDiskSize)
313 rd_size = (naca.xRamDiskSize * HW_PAGE_SIZE) / 1024;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700314 } else
315#endif /* CONFIG_BLK_DEV_INITRD */
316 {
317 /* ROOT_DEV = MKDEV(VIODASD_MAJOR, 1); */
318 }
319
320 iSeries_recal_tb = get_tb();
321 iSeries_recal_titan = HvCallXm_loadTod();
322
323 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700324 * Initialize the hash table management pointers
325 */
326 hpte_init_iSeries();
327
328 /*
329 * Initialize the DMA/TCE management
330 */
331 iommu_init_early_iSeries();
332
Linus Torvalds1da177e2005-04-16 15:20:36 -0700333 /* Initialize machine-dependency vectors */
334#ifdef CONFIG_SMP
335 smp_init_iSeries();
336#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700337
338 /* Associate Lp Event Queue 0 with processor 0 */
339 HvCallEvent_setLpEventQueueInterruptProc(0, 0);
340
341 mf_init();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342
343 /* If we were passed an initrd, set the ROOT_DEV properly if the values
344 * look sensible. If not, clear initrd reference.
345 */
346#ifdef CONFIG_BLK_DEV_INITRD
347 if (initrd_start >= KERNELBASE && initrd_end >= KERNELBASE &&
348 initrd_end > initrd_start)
349 ROOT_DEV = Root_RAM0;
350 else
351 initrd_start = initrd_end = 0;
352#endif /* CONFIG_BLK_DEV_INITRD */
353
354 DBG(" <- iSeries_init_early()\n");
355}
356
Michael Ellerman56e97b72005-08-03 20:21:23 +1000357struct mschunks_map mschunks_map = {
Michael Ellerman34c8f692005-08-03 20:21:23 +1000358 /* XXX We don't use these, but Piranha might need them. */
359 .chunk_size = MSCHUNKS_CHUNK_SIZE,
360 .chunk_shift = MSCHUNKS_CHUNK_SHIFT,
361 .chunk_mask = MSCHUNKS_OFFSET_MASK,
362};
Michael Ellerman56e97b72005-08-03 20:21:23 +1000363EXPORT_SYMBOL(mschunks_map);
Michael Ellerman34c8f692005-08-03 20:21:23 +1000364
Michael Ellerman56e97b72005-08-03 20:21:23 +1000365void mschunks_alloc(unsigned long num_chunks)
Michael Ellerman34c8f692005-08-03 20:21:23 +1000366{
367 klimit = _ALIGN(klimit, sizeof(u32));
Michael Ellerman56e97b72005-08-03 20:21:23 +1000368 mschunks_map.mapping = (u32 *)klimit;
Michael Ellerman34c8f692005-08-03 20:21:23 +1000369 klimit += num_chunks * sizeof(u32);
Michael Ellerman56e97b72005-08-03 20:21:23 +1000370 mschunks_map.num_chunks = num_chunks;
Michael Ellerman34c8f692005-08-03 20:21:23 +1000371}
372
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373/*
374 * The iSeries may have very large memories ( > 128 GB ) and a partition
375 * may get memory in "chunks" that may be anywhere in the 2**52 real
376 * address space. The chunks are 256K in size. To map this to the
377 * memory model Linux expects, the AS/400 specific code builds a
378 * translation table to translate what Linux thinks are "physical"
379 * addresses to the actual real addresses. This allows us to make
380 * it appear to Linux that we have contiguous memory starting at
381 * physical address zero while in fact this could be far from the truth.
382 * To avoid confusion, I'll let the words physical and/or real address
383 * apply to the Linux addresses while I'll use "absolute address" to
384 * refer to the actual hardware real address.
385 *
386 * build_iSeries_Memory_Map gets information from the Hypervisor and
387 * looks at the Main Store VPD to determine the absolute addresses
388 * of the memory that has been assigned to our partition and builds
389 * a table used to translate Linux's physical addresses to these
390 * absolute addresses. Absolute addresses are needed when
391 * communicating with the hypervisor (e.g. to build HPT entries)
Paul Mackerras799d6042005-11-10 13:37:51 +1100392 *
393 * Returns the physical memory size
Linus Torvalds1da177e2005-04-16 15:20:36 -0700394 */
395
Paul Mackerras799d6042005-11-10 13:37:51 +1100396static unsigned long __init build_iSeries_Memory_Map(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700397{
398 u32 loadAreaFirstChunk, loadAreaLastChunk, loadAreaSize;
399 u32 nextPhysChunk;
400 u32 hptFirstChunk, hptLastChunk, hptSizeChunks, hptSizePages;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700401 u32 totalChunks,moreChunks;
402 u32 currChunk, thisChunk, absChunk;
403 u32 currDword;
404 u32 chunkBit;
405 u64 map;
406 struct MemoryBlock mb[32];
407 unsigned long numMemoryBlocks, curBlock;
408
409 /* Chunk size on iSeries is 256K bytes */
410 totalChunks = (u32)HvLpConfig_getMsChunks();
Michael Ellerman56e97b72005-08-03 20:21:23 +1000411 mschunks_alloc(totalChunks);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412
413 /*
414 * Get absolute address of our load area
415 * and map it to physical address 0
416 * This guarantees that the loadarea ends up at physical 0
417 * otherwise, it might not be returned by PLIC as the first
418 * chunks
419 */
420
421 loadAreaFirstChunk = (u32)addr_to_chunk(itLpNaca.xLoadAreaAddr);
422 loadAreaSize = itLpNaca.xLoadAreaChunks;
423
424 /*
425 * Only add the pages already mapped here.
426 * Otherwise we might add the hpt pages
427 * The rest of the pages of the load area
428 * aren't in the HPT yet and can still
429 * be assigned an arbitrary physical address
430 */
431 if ((loadAreaSize * 64) > HvPagesToMap)
432 loadAreaSize = HvPagesToMap / 64;
433
434 loadAreaLastChunk = loadAreaFirstChunk + loadAreaSize - 1;
435
436 /*
437 * TODO Do we need to do something if the HPT is in the 64MB load area?
438 * This would be required if the itLpNaca.xLoadAreaChunks includes
439 * the HPT size
440 */
441
442 printk("Mapping load area - physical addr = 0000000000000000\n"
443 " absolute addr = %016lx\n",
444 chunk_to_addr(loadAreaFirstChunk));
445 printk("Load area size %dK\n", loadAreaSize * 256);
446
447 for (nextPhysChunk = 0; nextPhysChunk < loadAreaSize; ++nextPhysChunk)
Michael Ellerman56e97b72005-08-03 20:21:23 +1000448 mschunks_map.mapping[nextPhysChunk] =
Linus Torvalds1da177e2005-04-16 15:20:36 -0700449 loadAreaFirstChunk + nextPhysChunk;
450
451 /*
452 * Get absolute address of our HPT and remember it so
453 * we won't map it to any physical address
454 */
455 hptFirstChunk = (u32)addr_to_chunk(HvCallHpt_getHptAddress());
456 hptSizePages = (u32)HvCallHpt_getHptPages();
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100457 hptSizeChunks = hptSizePages >>
458 (MSCHUNKS_CHUNK_SHIFT - HW_PAGE_SHIFT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700459 hptLastChunk = hptFirstChunk + hptSizeChunks - 1;
460
461 printk("HPT absolute addr = %016lx, size = %dK\n",
462 chunk_to_addr(hptFirstChunk), hptSizeChunks * 256);
463
Linus Torvalds1da177e2005-04-16 15:20:36 -0700464 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700465 * Determine if absolute memory has any
466 * holes so that we can interpret the
467 * access map we get back from the hypervisor
468 * correctly.
469 */
470 numMemoryBlocks = iSeries_process_mainstore_vpd(mb, 32);
471
472 /*
473 * Process the main store access map from the hypervisor
474 * to build up our physical -> absolute translation table
475 */
476 curBlock = 0;
477 currChunk = 0;
478 currDword = 0;
479 moreChunks = totalChunks;
480
481 while (moreChunks) {
482 map = HvCallSm_get64BitsOfAccessMap(itLpNaca.xLpIndex,
483 currDword);
484 thisChunk = currChunk;
485 while (map) {
486 chunkBit = map >> 63;
487 map <<= 1;
488 if (chunkBit) {
489 --moreChunks;
490 while (thisChunk >= mb[curBlock].logicalEnd) {
491 ++curBlock;
492 if (curBlock >= numMemoryBlocks)
493 panic("out of memory blocks");
494 }
495 if (thisChunk < mb[curBlock].logicalStart)
496 panic("memory block error");
497
498 absChunk = mb[curBlock].absStart +
499 (thisChunk - mb[curBlock].logicalStart);
500 if (((absChunk < hptFirstChunk) ||
501 (absChunk > hptLastChunk)) &&
502 ((absChunk < loadAreaFirstChunk) ||
503 (absChunk > loadAreaLastChunk))) {
Michael Ellerman56e97b72005-08-03 20:21:23 +1000504 mschunks_map.mapping[nextPhysChunk] =
505 absChunk;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700506 ++nextPhysChunk;
507 }
508 }
509 ++thisChunk;
510 }
511 ++currDword;
512 currChunk += 64;
513 }
514
515 /*
516 * main store size (in chunks) is
517 * totalChunks - hptSizeChunks
518 * which should be equal to
519 * nextPhysChunk
520 */
Paul Mackerras799d6042005-11-10 13:37:51 +1100521 return chunk_to_addr(nextPhysChunk);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700522}
523
524/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700525 * Document me.
526 */
527static void __init iSeries_setup_arch(void)
528{
David Gibson3356bb92006-01-13 10:26:42 +1100529 if (get_lppaca()->shared_proc) {
Michael Ellerman9f497582005-09-23 14:10:59 +1000530 ppc_md.idle_loop = iseries_shared_idle;
Olof Johansson4baaf0c2006-04-12 15:23:22 -0500531 printk(KERN_DEBUG "Using shared processor idle loop\n");
Michael Ellerman9f497582005-09-23 14:10:59 +1000532 } else {
533 ppc_md.idle_loop = iseries_dedicated_idle;
Olof Johansson4baaf0c2006-04-12 15:23:22 -0500534 printk(KERN_DEBUG "Using dedicated idle loop\n");
Michael Ellerman9f497582005-09-23 14:10:59 +1000535 }
536
Linus Torvalds1da177e2005-04-16 15:20:36 -0700537 /* Setup the Lp Event Queue */
Michael Ellerman512d31d2005-06-30 15:08:27 +1000538 setup_hvlpevent_queue();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700539
Linus Torvalds1da177e2005-04-16 15:20:36 -0700540 printk("Max logical processors = %d\n",
541 itVpdAreas.xSlicMaxLogicalProcs);
542 printk("Max physical processors = %d\n",
543 itVpdAreas.xSlicMaxPhysicalProcs);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700544}
545
Paul Mackerrasd8699e62005-10-20 17:02:01 +1000546static void iSeries_show_cpuinfo(struct seq_file *m)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700547{
548 seq_printf(m, "machine\t\t: 64-bit iSeries Logical Partition\n");
549}
550
Linus Torvalds1da177e2005-04-16 15:20:36 -0700551static void __init iSeries_progress(char * st, unsigned short code)
552{
553 printk("Progress: [%04x] - %s\n", (unsigned)code, st);
Michael Ellerman260de222006-03-21 20:46:02 +1100554 mf_display_progress(code);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700555}
556
557static void __init iSeries_fixup_klimit(void)
558{
559 /*
560 * Change klimit to take into account any ram disk
561 * that may be included
562 */
563 if (naca.xRamDisk)
564 klimit = KERNELBASE + (u64)naca.xRamDisk +
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100565 (naca.xRamDiskSize * HW_PAGE_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700566 else {
567 /*
568 * No ram disk was included - check and see if there
569 * was an embedded system map. Change klimit to take
570 * into account any embedded system map
571 */
572 if (embedded_sysmap_end)
573 klimit = KERNELBASE + ((embedded_sysmap_end + 4095) &
574 0xfffffffffffff000);
575 }
576}
577
578static int __init iSeries_src_init(void)
579{
580 /* clear the progress line */
581 ppc_md.progress(" ", 0xffff);
582 return 0;
583}
584
585late_initcall(iSeries_src_init);
586
Michael Ellermand2009032005-07-07 17:56:29 -0700587static inline void process_iSeries_events(void)
588{
589 asm volatile ("li 0,0x5555; sc" : : : "r0", "r3");
590}
591
592static void yield_shared_processor(void)
593{
594 unsigned long tb;
Michael Ellermand2009032005-07-07 17:56:29 -0700595
596 HvCall_setEnabledInterrupts(HvCall_MaskIPI |
597 HvCall_MaskLpEvent |
598 HvCall_MaskLpProd |
599 HvCall_MaskTimeout);
600
601 tb = get_tb();
602 /* Compute future tb value when yield should expire */
603 HvCall_yieldProcessor(HvCall_YieldTimed, tb+tb_ticks_per_jiffy);
604
Michael Ellermand2009032005-07-07 17:56:29 -0700605 /*
606 * The decrementer stops during the yield. Force a fake decrementer
607 * here and let the timer_interrupt code sort out the actual time.
608 */
David Gibson3356bb92006-01-13 10:26:42 +1100609 get_lppaca()->int_dword.fields.decr_int = 1;
Anton Blanchardcb2c9b22006-02-13 14:48:35 +1100610 ppc64_runlatch_on();
Michael Ellermand2009032005-07-07 17:56:29 -0700611 process_iSeries_events();
612}
613
Paul Mackerras143a1de2005-10-19 23:11:21 +1000614static void iseries_shared_idle(void)
Michael Ellermand2009032005-07-07 17:56:29 -0700615{
Anton Blanchard3c57bb92005-07-07 17:56:32 -0700616 while (1) {
617 while (!need_resched() && !hvlpevent_is_pending()) {
618 local_irq_disable();
619 ppc64_runlatch_off();
620
621 /* Recheck with irqs off */
622 if (!need_resched() && !hvlpevent_is_pending())
623 yield_shared_processor();
624
625 HMT_medium();
626 local_irq_enable();
627 }
628
629 ppc64_runlatch_on();
630
631 if (hvlpevent_is_pending())
632 process_iSeries_events();
633
Nick Piggin5bfb5d62005-11-08 21:39:01 -0800634 preempt_enable_no_resched();
Anton Blanchard3c57bb92005-07-07 17:56:32 -0700635 schedule();
Nick Piggin5bfb5d62005-11-08 21:39:01 -0800636 preempt_disable();
Anton Blanchard3c57bb92005-07-07 17:56:32 -0700637 }
Anton Blanchard3c57bb92005-07-07 17:56:32 -0700638}
639
Paul Mackerras143a1de2005-10-19 23:11:21 +1000640static void iseries_dedicated_idle(void)
Anton Blanchard3c57bb92005-07-07 17:56:32 -0700641{
Nick Piggin64c7c8f2005-11-08 21:39:04 -0800642 set_thread_flag(TIF_POLLING_NRFLAG);
Michael Ellermand2009032005-07-07 17:56:29 -0700643
Michael Ellermand2009032005-07-07 17:56:29 -0700644 while (1) {
Nick Piggin64c7c8f2005-11-08 21:39:04 -0800645 if (!need_resched()) {
Anton Blanchard3c57bb92005-07-07 17:56:32 -0700646 while (!need_resched()) {
647 ppc64_runlatch_off();
648 HMT_low();
649
650 if (hvlpevent_is_pending()) {
Michael Ellermand2009032005-07-07 17:56:29 -0700651 HMT_medium();
Anton Blanchard3c57bb92005-07-07 17:56:32 -0700652 ppc64_runlatch_on();
653 process_iSeries_events();
Michael Ellermand2009032005-07-07 17:56:29 -0700654 }
Michael Ellermand2009032005-07-07 17:56:29 -0700655 }
Anton Blanchard3c57bb92005-07-07 17:56:32 -0700656
657 HMT_medium();
Michael Ellermand2009032005-07-07 17:56:29 -0700658 }
659
660 ppc64_runlatch_on();
Nick Piggin5bfb5d62005-11-08 21:39:01 -0800661 preempt_enable_no_resched();
Michael Ellermand2009032005-07-07 17:56:29 -0700662 schedule();
Nick Piggin5bfb5d62005-11-08 21:39:01 -0800663 preempt_disable();
Michael Ellermand2009032005-07-07 17:56:29 -0700664 }
Michael Ellermand2009032005-07-07 17:56:29 -0700665}
666
Stephen Rothwell145d01e2005-06-21 17:15:52 -0700667#ifndef CONFIG_PCI
668void __init iSeries_init_IRQ(void) { }
669#endif
670
Benjamin Herrenschmidte8222502006-03-28 23:15:54 +1100671static int __init iseries_probe(void)
Michael Ellerman47627132005-09-23 14:59:04 +1000672{
Benjamin Herrenschmidte8222502006-03-28 23:15:54 +1100673 unsigned long root = of_get_flat_dt_root();
674 if (!of_flat_dt_is_compatible(root, "IBM,iSeries"))
Michael Ellerman57cfb812006-03-21 20:45:59 +1100675 return 0;
676
Michael Ellermand0160bf2006-03-27 14:26:25 +1100677 powerpc_firmware_features |= FW_FEATURE_ISERIES;
678 powerpc_firmware_features |= FW_FEATURE_LPAR;
Michael Ellerman57cfb812006-03-21 20:45:59 +1100679
Stephen Rothwell7d01c882006-04-04 14:49:48 +1000680 /*
681 * The Hypervisor only allows us up to 256 interrupt
682 * sources (the irq number is passed in a u8).
683 */
684 virt_irq_max = 255;
685
Michael Ellerman57cfb812006-03-21 20:45:59 +1100686 return 1;
Michael Ellerman47627132005-09-23 14:59:04 +1000687}
688
Benjamin Herrenschmidte8222502006-03-28 23:15:54 +1100689define_machine(iseries) {
690 .name = "iSeries",
Michael Ellerman9f497582005-09-23 14:10:59 +1000691 .setup_arch = iSeries_setup_arch,
Paul Mackerrasd8699e62005-10-20 17:02:01 +1000692 .show_cpuinfo = iSeries_show_cpuinfo,
Michael Ellerman9f497582005-09-23 14:10:59 +1000693 .init_IRQ = iSeries_init_IRQ,
694 .get_irq = iSeries_get_irq,
695 .init_early = iSeries_init_early,
696 .pcibios_fixup = iSeries_pci_final_fixup,
Michael Ellermana9ea2102006-03-21 20:46:04 +1100697 .restart = mf_reboot,
698 .power_off = mf_power_off,
699 .halt = mf_power_off,
Michael Ellerman9f497582005-09-23 14:10:59 +1000700 .get_boot_time = iSeries_get_boot_time,
701 .set_rtc_time = iSeries_set_rtc_time,
702 .get_rtc_time = iSeries_get_rtc_time,
Michael Ellerman95b29382005-09-23 15:03:10 +1000703 .calibrate_decr = generic_calibrate_decr,
Michael Ellerman9f497582005-09-23 14:10:59 +1000704 .progress = iSeries_progress,
Michael Ellerman47627132005-09-23 14:59:04 +1000705 .probe = iseries_probe,
Michael Ellerman9f497582005-09-23 14:10:59 +1000706 /* XXX Implement enable_pmcs for iSeries */
707};
708
Michael Ellerman47627132005-09-23 14:59:04 +1000709void * __init iSeries_early_setup(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700710{
Paul Mackerras799d6042005-11-10 13:37:51 +1100711 unsigned long phys_mem_size;
712
Linus Torvalds1da177e2005-04-16 15:20:36 -0700713 iSeries_fixup_klimit();
Michael Ellermanc0a59492005-09-23 14:56:09 +1000714
Michael Ellerman47627132005-09-23 14:59:04 +1000715 /*
716 * Initialize the table which translate Linux physical addresses to
717 * AS/400 absolute addresses
718 */
Paul Mackerras799d6042005-11-10 13:37:51 +1100719 phys_mem_size = build_iSeries_Memory_Map();
Michael Ellerman47627132005-09-23 14:59:04 +1000720
Stephen Rothwellbec7c452005-11-01 11:45:19 +1100721 iSeries_get_cmdline();
722
Stephen Rothwellc81014f2006-05-19 17:00:04 +1000723 return (void *) __pa(build_flat_dt(phys_mem_size));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700724}
Stephen Rothwellbec7c452005-11-01 11:45:19 +1100725
Michael Ellermanbf6a7112006-01-11 11:54:08 +1100726static void hvputc(char c)
727{
728 if (c == '\n')
729 hvputc('\r');
730
731 HvCall_writeLogBuffer(&c, 1);
732}
733
734void __init udbg_init_iseries(void)
735{
736 udbg_putc = hvputc;
737}