blob: 13a8b1908deda3c4c733003fd649701eba0c7cce [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
Linus Torvalds1da177e2005-04-16 15:20:36 -070019#include <linux/init.h>
20#include <linux/threads.h>
21#include <linux/smp.h>
22#include <linux/param.h>
23#include <linux/string.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070024#include <linux/seq_file.h>
25#include <linux/kdev_t.h>
26#include <linux/major.h>
27#include <linux/root_dev.h>
Stephen Rothwellbec7c452005-11-01 11:45:19 +110028#include <linux/kernel.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070029
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>
Stephen Rothwellaed31352005-08-03 14:43:21 +100039#include <asm/firmware.h>
Paul Mackerras49b09852005-11-10 15:53:40 +110040#include <asm/system.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070041#include <asm/time.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070042#include <asm/paca.h>
43#include <asm/cache.h>
44#include <asm/sections.h>
Stephen Rothwell0bc0ffd2005-06-21 17:15:36 -070045#include <asm/abs_addr.h>
Kelly Daly15b17182005-11-02 11:55:28 +110046#include <asm/iseries/hv_lp_config.h>
Kelly Dalyc0a8d052005-11-02 11:11:11 +110047#include <asm/iseries/hv_call_event.h>
Kelly Daly8021b8a2005-11-02 11:41:12 +110048#include <asm/iseries/hv_call_xm.h>
Kelly Daly8875ccf2005-11-02 14:13:34 +110049#include <asm/iseries/it_lp_queue.h>
Kelly Dalybbc8b622005-11-02 15:10:38 +110050#include <asm/iseries/mf.h>
Kelly Dalye45423e2005-11-02 12:08:31 +110051#include <asm/iseries/hv_lp_event.h>
Kelly Dalyc43a55f2005-11-02 15:02:47 +110052#include <asm/iseries/lpar_map.h>
Michael Ellermanbf6a7112006-01-11 11:54:08 +110053#include <asm/udbg.h>
Stephen Rothwell7d01c882006-04-04 14:49:48 +100054#include <asm/irq.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070055
David Gibsonf11b7bd2005-11-01 15:30:26 +110056#include "naca.h"
Stephen Rothwellc8b84972005-09-27 18:44:42 +100057#include "setup.h"
Stephen Rothwellb08567cb2005-09-28 23:37:01 +100058#include "irq.h"
59#include "vpd_areas.h"
60#include "processor_vpd.h"
Michael Ellerman06a36db2006-07-13 17:52:17 +100061#include "it_lp_naca.h"
Stephen Rothwellb08567cb2005-09-28 23:37:01 +100062#include "main_store.h"
63#include "call_sm.h"
Stephen Rothwell0e29bb12005-10-14 17:09:16 +100064#include "call_hpt.h"
Stephen Rothwellc8b84972005-09-27 18:44:42 +100065
Linus Torvalds1da177e2005-04-16 15:20:36 -070066#ifdef DEBUG
Michael Ellermanbf6a7112006-01-11 11:54:08 +110067#define DBG(fmt...) udbg_printf(fmt)
Linus Torvalds1da177e2005-04-16 15:20:36 -070068#else
69#define DBG(fmt...)
70#endif
71
72/* Function Prototypes */
Paul Mackerras799d6042005-11-10 13:37:51 +110073static unsigned long build_iSeries_Memory_Map(void);
Paul Mackerras143a1de2005-10-19 23:11:21 +100074static void iseries_shared_idle(void);
75static void iseries_dedicated_idle(void);
Stephen Rothwell145d01e2005-06-21 17:15:52 -070076#ifdef CONFIG_PCI
Linus Torvalds1da177e2005-04-16 15:20:36 -070077extern void iSeries_pci_final_fixup(void);
Stephen Rothwell145d01e2005-06-21 17:15:52 -070078#else
79static void iSeries_pci_final_fixup(void) { }
80#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070081
Linus Torvalds1da177e2005-04-16 15:20:36 -070082
Linus Torvalds1da177e2005-04-16 15:20:36 -070083struct MemoryBlock {
84 unsigned long absStart;
85 unsigned long absEnd;
86 unsigned long logicalStart;
87 unsigned long logicalEnd;
88};
89
90/*
91 * Process the main store vpd to determine where the holes in memory are
92 * and return the number of physical blocks and fill in the array of
93 * block data.
94 */
95static unsigned long iSeries_process_Condor_mainstore_vpd(
96 struct MemoryBlock *mb_array, unsigned long max_entries)
97{
98 unsigned long holeFirstChunk, holeSizeChunks;
99 unsigned long numMemoryBlocks = 1;
100 struct IoHriMainStoreSegment4 *msVpd =
101 (struct IoHriMainStoreSegment4 *)xMsVpd;
102 unsigned long holeStart = msVpd->nonInterleavedBlocksStartAdr;
103 unsigned long holeEnd = msVpd->nonInterleavedBlocksEndAdr;
104 unsigned long holeSize = holeEnd - holeStart;
105
106 printk("Mainstore_VPD: Condor\n");
107 /*
108 * Determine if absolute memory has any
109 * holes so that we can interpret the
110 * access map we get back from the hypervisor
111 * correctly.
112 */
113 mb_array[0].logicalStart = 0;
114 mb_array[0].logicalEnd = 0x100000000;
115 mb_array[0].absStart = 0;
116 mb_array[0].absEnd = 0x100000000;
117
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
137#define MaxSegmentAreas 32
138#define MaxSegmentAdrRangeBlocks 128
139#define MaxAreaRangeBlocks 4
140
141static unsigned long iSeries_process_Regatta_mainstore_vpd(
142 struct MemoryBlock *mb_array, unsigned long max_entries)
143{
144 struct IoHriMainStoreSegment5 *msVpdP =
145 (struct IoHriMainStoreSegment5 *)xMsVpd;
146 unsigned long numSegmentBlocks = 0;
147 u32 existsBits = msVpdP->msAreaExists;
148 unsigned long area_num;
149
150 printk("Mainstore_VPD: Regatta\n");
151
152 for (area_num = 0; area_num < MaxSegmentAreas; ++area_num ) {
153 unsigned long numAreaBlocks;
154 struct IoHriMainStoreArea4 *currentArea;
155
156 if (existsBits & 0x80000000) {
157 unsigned long block_num;
158
159 currentArea = &msVpdP->msAreaArray[area_num];
160 numAreaBlocks = currentArea->numAdrRangeBlocks;
161 printk("ms_vpd: processing area %2ld blocks=%ld",
162 area_num, numAreaBlocks);
163 for (block_num = 0; block_num < numAreaBlocks;
164 ++block_num ) {
165 /* Process an address range block */
166 struct MemoryBlock tempBlock;
167 unsigned long i;
168
169 tempBlock.absStart =
170 (unsigned long)currentArea->xAdrRangeBlock[block_num].blockStart;
171 tempBlock.absEnd =
172 (unsigned long)currentArea->xAdrRangeBlock[block_num].blockEnd;
173 tempBlock.logicalStart = 0;
174 tempBlock.logicalEnd = 0;
175 printk("\n block %ld absStart=%016lx absEnd=%016lx",
176 block_num, tempBlock.absStart,
177 tempBlock.absEnd);
178
179 for (i = 0; i < numSegmentBlocks; ++i) {
180 if (mb_array[i].absStart ==
181 tempBlock.absStart)
182 break;
183 }
184 if (i == numSegmentBlocks) {
185 if (numSegmentBlocks == max_entries)
186 panic("iSeries_process_mainstore_vpd: too many memory blocks");
187 mb_array[numSegmentBlocks] = tempBlock;
188 ++numSegmentBlocks;
189 } else
190 printk(" (duplicate)");
191 }
192 printk("\n");
193 }
194 existsBits <<= 1;
195 }
196 /* Now sort the blocks found into ascending sequence */
197 if (numSegmentBlocks > 1) {
198 unsigned long m, n;
199
200 for (m = 0; m < numSegmentBlocks - 1; ++m) {
201 for (n = numSegmentBlocks - 1; m < n; --n) {
202 if (mb_array[n].absStart <
203 mb_array[n-1].absStart) {
204 struct MemoryBlock tempBlock;
205
206 tempBlock = mb_array[n];
207 mb_array[n] = mb_array[n-1];
208 mb_array[n-1] = tempBlock;
209 }
210 }
211 }
212 }
213 /*
214 * Assign "logical" addresses to each block. These
215 * addresses correspond to the hypervisor "bitmap" space.
216 * Convert all addresses into units of 256K chunks.
217 */
218 {
219 unsigned long i, nextBitmapAddress;
220
221 printk("ms_vpd: %ld sorted memory blocks\n", numSegmentBlocks);
222 nextBitmapAddress = 0;
223 for (i = 0; i < numSegmentBlocks; ++i) {
224 unsigned long length = mb_array[i].absEnd -
225 mb_array[i].absStart;
226
227 mb_array[i].logicalStart = nextBitmapAddress;
228 mb_array[i].logicalEnd = nextBitmapAddress + length;
229 nextBitmapAddress += length;
230 printk(" Bitmap range: %016lx - %016lx\n"
231 " Absolute range: %016lx - %016lx\n",
232 mb_array[i].logicalStart,
233 mb_array[i].logicalEnd,
234 mb_array[i].absStart, mb_array[i].absEnd);
235 mb_array[i].absStart = addr_to_chunk(mb_array[i].absStart &
236 0x000fffffffffffff);
237 mb_array[i].absEnd = addr_to_chunk(mb_array[i].absEnd &
238 0x000fffffffffffff);
239 mb_array[i].logicalStart =
240 addr_to_chunk(mb_array[i].logicalStart);
241 mb_array[i].logicalEnd = addr_to_chunk(mb_array[i].logicalEnd);
242 }
243 }
244
245 return numSegmentBlocks;
246}
247
248static unsigned long iSeries_process_mainstore_vpd(struct MemoryBlock *mb_array,
249 unsigned long max_entries)
250{
251 unsigned long i;
252 unsigned long mem_blocks = 0;
253
254 if (cpu_has_feature(CPU_FTR_SLB))
255 mem_blocks = iSeries_process_Regatta_mainstore_vpd(mb_array,
256 max_entries);
257 else
258 mem_blocks = iSeries_process_Condor_mainstore_vpd(mb_array,
259 max_entries);
260
261 printk("Mainstore_VPD: numMemoryBlocks = %ld \n", mem_blocks);
262 for (i = 0; i < mem_blocks; ++i) {
263 printk("Mainstore_VPD: block %3ld logical chunks %016lx - %016lx\n"
264 " abs chunks %016lx - %016lx\n",
265 i, mb_array[i].logicalStart, mb_array[i].logicalEnd,
266 mb_array[i].absStart, mb_array[i].absEnd);
267 }
268 return mem_blocks;
269}
270
271static void __init iSeries_get_cmdline(void)
272{
273 char *p, *q;
274
275 /* copy the command line parameter from the primary VSP */
276 HvCallEvent_dmaToSp(cmd_line, 2 * 64* 1024, 256,
277 HvLpDma_Direction_RemoteToLocal);
278
279 p = cmd_line;
280 q = cmd_line + 255;
281 while(p < q) {
282 if (!*p || *p == '\n')
283 break;
284 ++p;
285 }
286 *p = 0;
287}
288
289static void __init iSeries_init_early(void)
290{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700291 DBG(" -> iSeries_init_early()\n");
292
Tony Breeds71712b42007-06-22 16:54:30 +1000293 /* Snapshot the timebase, for use in later recalibration */
294 iSeries_time_init_early();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295
296 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700297 * Initialize the DMA/TCE management
298 */
299 iommu_init_early_iSeries();
300
Linus Torvalds1da177e2005-04-16 15:20:36 -0700301 /* Initialize machine-dependency vectors */
302#ifdef CONFIG_SMP
303 smp_init_iSeries();
304#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700305
306 /* Associate Lp Event Queue 0 with processor 0 */
307 HvCallEvent_setLpEventQueueInterruptProc(0, 0);
308
309 mf_init();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310
Linus Torvalds1da177e2005-04-16 15:20:36 -0700311 DBG(" <- iSeries_init_early()\n");
312}
313
Michael Ellerman56e97b72005-08-03 20:21:23 +1000314struct mschunks_map mschunks_map = {
Michael Ellerman34c8f692005-08-03 20:21:23 +1000315 /* XXX We don't use these, but Piranha might need them. */
316 .chunk_size = MSCHUNKS_CHUNK_SIZE,
317 .chunk_shift = MSCHUNKS_CHUNK_SHIFT,
318 .chunk_mask = MSCHUNKS_OFFSET_MASK,
319};
Michael Ellerman56e97b72005-08-03 20:21:23 +1000320EXPORT_SYMBOL(mschunks_map);
Michael Ellerman34c8f692005-08-03 20:21:23 +1000321
Michael Ellerman56e97b72005-08-03 20:21:23 +1000322void mschunks_alloc(unsigned long num_chunks)
Michael Ellerman34c8f692005-08-03 20:21:23 +1000323{
324 klimit = _ALIGN(klimit, sizeof(u32));
Michael Ellerman56e97b72005-08-03 20:21:23 +1000325 mschunks_map.mapping = (u32 *)klimit;
Michael Ellerman34c8f692005-08-03 20:21:23 +1000326 klimit += num_chunks * sizeof(u32);
Michael Ellerman56e97b72005-08-03 20:21:23 +1000327 mschunks_map.num_chunks = num_chunks;
Michael Ellerman34c8f692005-08-03 20:21:23 +1000328}
329
Linus Torvalds1da177e2005-04-16 15:20:36 -0700330/*
331 * The iSeries may have very large memories ( > 128 GB ) and a partition
332 * may get memory in "chunks" that may be anywhere in the 2**52 real
333 * address space. The chunks are 256K in size. To map this to the
334 * memory model Linux expects, the AS/400 specific code builds a
335 * translation table to translate what Linux thinks are "physical"
336 * addresses to the actual real addresses. This allows us to make
337 * it appear to Linux that we have contiguous memory starting at
338 * physical address zero while in fact this could be far from the truth.
339 * To avoid confusion, I'll let the words physical and/or real address
340 * apply to the Linux addresses while I'll use "absolute address" to
341 * refer to the actual hardware real address.
342 *
343 * build_iSeries_Memory_Map gets information from the Hypervisor and
344 * looks at the Main Store VPD to determine the absolute addresses
345 * of the memory that has been assigned to our partition and builds
346 * a table used to translate Linux's physical addresses to these
347 * absolute addresses. Absolute addresses are needed when
348 * communicating with the hypervisor (e.g. to build HPT entries)
Paul Mackerras799d6042005-11-10 13:37:51 +1100349 *
350 * Returns the physical memory size
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351 */
352
Paul Mackerras799d6042005-11-10 13:37:51 +1100353static unsigned long __init build_iSeries_Memory_Map(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354{
355 u32 loadAreaFirstChunk, loadAreaLastChunk, loadAreaSize;
356 u32 nextPhysChunk;
357 u32 hptFirstChunk, hptLastChunk, hptSizeChunks, hptSizePages;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700358 u32 totalChunks,moreChunks;
359 u32 currChunk, thisChunk, absChunk;
360 u32 currDword;
361 u32 chunkBit;
362 u64 map;
363 struct MemoryBlock mb[32];
364 unsigned long numMemoryBlocks, curBlock;
365
366 /* Chunk size on iSeries is 256K bytes */
367 totalChunks = (u32)HvLpConfig_getMsChunks();
Michael Ellerman56e97b72005-08-03 20:21:23 +1000368 mschunks_alloc(totalChunks);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700369
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
378 loadAreaFirstChunk = (u32)addr_to_chunk(itLpNaca.xLoadAreaAddr);
379 loadAreaSize = itLpNaca.xLoadAreaChunks;
380
381 /*
382 * Only add the pages already mapped here.
383 * Otherwise we might add the hpt pages
384 * The rest of the pages of the load area
385 * aren't in the HPT yet and can still
386 * be assigned an arbitrary physical address
387 */
388 if ((loadAreaSize * 64) > HvPagesToMap)
389 loadAreaSize = HvPagesToMap / 64;
390
391 loadAreaLastChunk = loadAreaFirstChunk + loadAreaSize - 1;
392
393 /*
394 * TODO Do we need to do something if the HPT is in the 64MB load area?
395 * This would be required if the itLpNaca.xLoadAreaChunks includes
396 * the HPT size
397 */
398
399 printk("Mapping load area - physical addr = 0000000000000000\n"
400 " absolute addr = %016lx\n",
401 chunk_to_addr(loadAreaFirstChunk));
402 printk("Load area size %dK\n", loadAreaSize * 256);
403
404 for (nextPhysChunk = 0; nextPhysChunk < loadAreaSize; ++nextPhysChunk)
Michael Ellerman56e97b72005-08-03 20:21:23 +1000405 mschunks_map.mapping[nextPhysChunk] =
Linus Torvalds1da177e2005-04-16 15:20:36 -0700406 loadAreaFirstChunk + nextPhysChunk;
407
408 /*
409 * Get absolute address of our HPT and remember it so
410 * we won't map it to any physical address
411 */
412 hptFirstChunk = (u32)addr_to_chunk(HvCallHpt_getHptAddress());
413 hptSizePages = (u32)HvCallHpt_getHptPages();
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100414 hptSizeChunks = hptSizePages >>
415 (MSCHUNKS_CHUNK_SHIFT - HW_PAGE_SHIFT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700416 hptLastChunk = hptFirstChunk + hptSizeChunks - 1;
417
418 printk("HPT absolute addr = %016lx, size = %dK\n",
419 chunk_to_addr(hptFirstChunk), hptSizeChunks * 256);
420
Linus Torvalds1da177e2005-04-16 15:20:36 -0700421 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700422 * Determine if absolute memory has any
423 * holes so that we can interpret the
424 * access map we get back from the hypervisor
425 * correctly.
426 */
427 numMemoryBlocks = iSeries_process_mainstore_vpd(mb, 32);
428
429 /*
430 * Process the main store access map from the hypervisor
431 * to build up our physical -> absolute translation table
432 */
433 curBlock = 0;
434 currChunk = 0;
435 currDword = 0;
436 moreChunks = totalChunks;
437
438 while (moreChunks) {
439 map = HvCallSm_get64BitsOfAccessMap(itLpNaca.xLpIndex,
440 currDword);
441 thisChunk = currChunk;
442 while (map) {
443 chunkBit = map >> 63;
444 map <<= 1;
445 if (chunkBit) {
446 --moreChunks;
447 while (thisChunk >= mb[curBlock].logicalEnd) {
448 ++curBlock;
449 if (curBlock >= numMemoryBlocks)
450 panic("out of memory blocks");
451 }
452 if (thisChunk < mb[curBlock].logicalStart)
453 panic("memory block error");
454
455 absChunk = mb[curBlock].absStart +
456 (thisChunk - mb[curBlock].logicalStart);
457 if (((absChunk < hptFirstChunk) ||
458 (absChunk > hptLastChunk)) &&
459 ((absChunk < loadAreaFirstChunk) ||
460 (absChunk > loadAreaLastChunk))) {
Michael Ellerman56e97b72005-08-03 20:21:23 +1000461 mschunks_map.mapping[nextPhysChunk] =
462 absChunk;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700463 ++nextPhysChunk;
464 }
465 }
466 ++thisChunk;
467 }
468 ++currDword;
469 currChunk += 64;
470 }
471
472 /*
473 * main store size (in chunks) is
474 * totalChunks - hptSizeChunks
475 * which should be equal to
476 * nextPhysChunk
477 */
Paul Mackerras799d6042005-11-10 13:37:51 +1100478 return chunk_to_addr(nextPhysChunk);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700479}
480
481/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700482 * Document me.
483 */
484static void __init iSeries_setup_arch(void)
485{
David Gibson3356bb92006-01-13 10:26:42 +1100486 if (get_lppaca()->shared_proc) {
Michael Ellerman9f497582005-09-23 14:10:59 +1000487 ppc_md.idle_loop = iseries_shared_idle;
Olof Johansson4baaf0c2006-04-12 15:23:22 -0500488 printk(KERN_DEBUG "Using shared processor idle loop\n");
Michael Ellerman9f497582005-09-23 14:10:59 +1000489 } else {
490 ppc_md.idle_loop = iseries_dedicated_idle;
Olof Johansson4baaf0c2006-04-12 15:23:22 -0500491 printk(KERN_DEBUG "Using dedicated idle loop\n");
Michael Ellerman9f497582005-09-23 14:10:59 +1000492 }
493
Linus Torvalds1da177e2005-04-16 15:20:36 -0700494 /* Setup the Lp Event Queue */
Michael Ellerman512d31d2005-06-30 15:08:27 +1000495 setup_hvlpevent_queue();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700496
Linus Torvalds1da177e2005-04-16 15:20:36 -0700497 printk("Max logical processors = %d\n",
498 itVpdAreas.xSlicMaxLogicalProcs);
499 printk("Max physical processors = %d\n",
500 itVpdAreas.xSlicMaxPhysicalProcs);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700501}
502
Paul Mackerrasd8699e62005-10-20 17:02:01 +1000503static void iSeries_show_cpuinfo(struct seq_file *m)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700504{
505 seq_printf(m, "machine\t\t: 64-bit iSeries Logical Partition\n");
506}
507
Linus Torvalds1da177e2005-04-16 15:20:36 -0700508static void __init iSeries_progress(char * st, unsigned short code)
509{
510 printk("Progress: [%04x] - %s\n", (unsigned)code, st);
Michael Ellerman260de222006-03-21 20:46:02 +1100511 mf_display_progress(code);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700512}
513
514static void __init iSeries_fixup_klimit(void)
515{
516 /*
517 * Change klimit to take into account any ram disk
518 * that may be included
519 */
520 if (naca.xRamDisk)
521 klimit = KERNELBASE + (u64)naca.xRamDisk +
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100522 (naca.xRamDiskSize * HW_PAGE_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700523}
524
525static int __init iSeries_src_init(void)
526{
527 /* clear the progress line */
Stephen Rothwelle75b1712007-01-04 17:06:21 +1100528 if (firmware_has_feature(FW_FEATURE_ISERIES))
529 ppc_md.progress(" ", 0xffff);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700530 return 0;
531}
532
533late_initcall(iSeries_src_init);
534
Michael Ellermand2009032005-07-07 17:56:29 -0700535static inline void process_iSeries_events(void)
536{
537 asm volatile ("li 0,0x5555; sc" : : : "r0", "r3");
538}
539
540static void yield_shared_processor(void)
541{
542 unsigned long tb;
Michael Ellermand2009032005-07-07 17:56:29 -0700543
544 HvCall_setEnabledInterrupts(HvCall_MaskIPI |
545 HvCall_MaskLpEvent |
546 HvCall_MaskLpProd |
547 HvCall_MaskTimeout);
548
549 tb = get_tb();
550 /* Compute future tb value when yield should expire */
551 HvCall_yieldProcessor(HvCall_YieldTimed, tb+tb_ticks_per_jiffy);
552
Michael Ellermand2009032005-07-07 17:56:29 -0700553 /*
554 * The decrementer stops during the yield. Force a fake decrementer
555 * here and let the timer_interrupt code sort out the actual time.
556 */
David Gibson3356bb92006-01-13 10:26:42 +1100557 get_lppaca()->int_dword.fields.decr_int = 1;
Anton Blanchardcb2c9b22006-02-13 14:48:35 +1100558 ppc64_runlatch_on();
Michael Ellermand2009032005-07-07 17:56:29 -0700559 process_iSeries_events();
560}
561
Paul Mackerras143a1de2005-10-19 23:11:21 +1000562static void iseries_shared_idle(void)
Michael Ellermand2009032005-07-07 17:56:29 -0700563{
Anton Blanchard3c57bb92005-07-07 17:56:32 -0700564 while (1) {
565 while (!need_resched() && !hvlpevent_is_pending()) {
566 local_irq_disable();
567 ppc64_runlatch_off();
568
569 /* Recheck with irqs off */
570 if (!need_resched() && !hvlpevent_is_pending())
571 yield_shared_processor();
572
573 HMT_medium();
574 local_irq_enable();
575 }
576
577 ppc64_runlatch_on();
578
579 if (hvlpevent_is_pending())
580 process_iSeries_events();
581
Nick Piggin5bfb5d62005-11-08 21:39:01 -0800582 preempt_enable_no_resched();
Anton Blanchard3c57bb92005-07-07 17:56:32 -0700583 schedule();
Nick Piggin5bfb5d62005-11-08 21:39:01 -0800584 preempt_disable();
Anton Blanchard3c57bb92005-07-07 17:56:32 -0700585 }
Anton Blanchard3c57bb92005-07-07 17:56:32 -0700586}
587
Paul Mackerras143a1de2005-10-19 23:11:21 +1000588static void iseries_dedicated_idle(void)
Anton Blanchard3c57bb92005-07-07 17:56:32 -0700589{
Nick Piggin64c7c8f2005-11-08 21:39:04 -0800590 set_thread_flag(TIF_POLLING_NRFLAG);
Michael Ellermand2009032005-07-07 17:56:29 -0700591
Michael Ellermand2009032005-07-07 17:56:29 -0700592 while (1) {
Nick Piggin64c7c8f2005-11-08 21:39:04 -0800593 if (!need_resched()) {
Anton Blanchard3c57bb92005-07-07 17:56:32 -0700594 while (!need_resched()) {
595 ppc64_runlatch_off();
596 HMT_low();
597
598 if (hvlpevent_is_pending()) {
Michael Ellermand2009032005-07-07 17:56:29 -0700599 HMT_medium();
Anton Blanchard3c57bb92005-07-07 17:56:32 -0700600 ppc64_runlatch_on();
601 process_iSeries_events();
Michael Ellermand2009032005-07-07 17:56:29 -0700602 }
Michael Ellermand2009032005-07-07 17:56:29 -0700603 }
Anton Blanchard3c57bb92005-07-07 17:56:32 -0700604
605 HMT_medium();
Michael Ellermand2009032005-07-07 17:56:29 -0700606 }
607
608 ppc64_runlatch_on();
Nick Piggin5bfb5d62005-11-08 21:39:01 -0800609 preempt_enable_no_resched();
Michael Ellermand2009032005-07-07 17:56:29 -0700610 schedule();
Nick Piggin5bfb5d62005-11-08 21:39:01 -0800611 preempt_disable();
Michael Ellermand2009032005-07-07 17:56:29 -0700612 }
Michael Ellermand2009032005-07-07 17:56:29 -0700613}
614
Stephen Rothwell145d01e2005-06-21 17:15:52 -0700615#ifndef CONFIG_PCI
616void __init iSeries_init_IRQ(void) { }
617#endif
618
Benjamin Herrenschmidt68a64352006-11-13 09:27:39 +1100619static void __iomem *iseries_ioremap(phys_addr_t address, unsigned long size,
Benjamin Herrenschmidt4cb3cee2006-11-11 17:25:10 +1100620 unsigned long flags)
621{
622 return (void __iomem *)address;
623}
624
Benjamin Herrenschmidt68a64352006-11-13 09:27:39 +1100625static void iseries_iounmap(volatile void __iomem *token)
Benjamin Herrenschmidt4cb3cee2006-11-11 17:25:10 +1100626{
627}
628
Benjamin Herrenschmidte8222502006-03-28 23:15:54 +1100629static int __init iseries_probe(void)
Michael Ellerman47627132005-09-23 14:59:04 +1000630{
Benjamin Herrenschmidte8222502006-03-28 23:15:54 +1100631 unsigned long root = of_get_flat_dt_root();
632 if (!of_flat_dt_is_compatible(root, "IBM,iSeries"))
Michael Ellerman57cfb812006-03-21 20:45:59 +1100633 return 0;
634
Michael Ellerman7d0daae2006-06-23 18:16:38 +1000635 hpte_init_iSeries();
Stephen Rothwell04704662006-11-30 11:46:22 +1100636 /* iSeries does not support 16M pages */
637 cur_cpu_spec->cpu_features &= ~CPU_FTR_16M_PAGE;
Michael Ellerman7d0daae2006-06-23 18:16:38 +1000638
Michael Ellerman57cfb812006-03-21 20:45:59 +1100639 return 1;
Michael Ellerman47627132005-09-23 14:59:04 +1000640}
641
Benjamin Herrenschmidte8222502006-03-28 23:15:54 +1100642define_machine(iseries) {
643 .name = "iSeries",
Michael Ellerman9f497582005-09-23 14:10:59 +1000644 .setup_arch = iSeries_setup_arch,
Paul Mackerrasd8699e62005-10-20 17:02:01 +1000645 .show_cpuinfo = iSeries_show_cpuinfo,
Michael Ellerman9f497582005-09-23 14:10:59 +1000646 .init_IRQ = iSeries_init_IRQ,
647 .get_irq = iSeries_get_irq,
648 .init_early = iSeries_init_early,
649 .pcibios_fixup = iSeries_pci_final_fixup,
Michael Ellermana9ea2102006-03-21 20:46:04 +1100650 .restart = mf_reboot,
651 .power_off = mf_power_off,
652 .halt = mf_power_off,
Michael Ellerman9f497582005-09-23 14:10:59 +1000653 .get_boot_time = iSeries_get_boot_time,
654 .set_rtc_time = iSeries_set_rtc_time,
655 .get_rtc_time = iSeries_get_rtc_time,
Michael Ellerman95b29382005-09-23 15:03:10 +1000656 .calibrate_decr = generic_calibrate_decr,
Michael Ellerman9f497582005-09-23 14:10:59 +1000657 .progress = iSeries_progress,
Michael Ellerman47627132005-09-23 14:59:04 +1000658 .probe = iseries_probe,
Benjamin Herrenschmidt4cb3cee2006-11-11 17:25:10 +1100659 .ioremap = iseries_ioremap,
660 .iounmap = iseries_iounmap,
Michael Ellerman9f497582005-09-23 14:10:59 +1000661 /* XXX Implement enable_pmcs for iSeries */
662};
663
Michael Ellerman47627132005-09-23 14:59:04 +1000664void * __init iSeries_early_setup(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700665{
Paul Mackerras799d6042005-11-10 13:37:51 +1100666 unsigned long phys_mem_size;
667
Benjamin Herrenschmidt42c4aaa2006-10-24 16:42:40 +1000668 /* Identify CPU type. This is done again by the common code later
669 * on but calling this function multiple times is fine.
670 */
Paul Mackerras974a76f2006-11-10 20:38:53 +1100671 identify_cpu(0, mfspr(SPRN_PVR));
Benjamin Herrenschmidt42c4aaa2006-10-24 16:42:40 +1000672
Stephen Rothwellef26a462006-09-25 13:27:17 +1000673 powerpc_firmware_features |= FW_FEATURE_ISERIES;
674 powerpc_firmware_features |= FW_FEATURE_LPAR;
675
Linus Torvalds1da177e2005-04-16 15:20:36 -0700676 iSeries_fixup_klimit();
Michael Ellermanc0a59492005-09-23 14:56:09 +1000677
Michael Ellerman47627132005-09-23 14:59:04 +1000678 /*
679 * Initialize the table which translate Linux physical addresses to
680 * AS/400 absolute addresses
681 */
Paul Mackerras799d6042005-11-10 13:37:51 +1100682 phys_mem_size = build_iSeries_Memory_Map();
Michael Ellerman47627132005-09-23 14:59:04 +1000683
Stephen Rothwellbec7c452005-11-01 11:45:19 +1100684 iSeries_get_cmdline();
685
Stephen Rothwellc81014f2006-05-19 17:00:04 +1000686 return (void *) __pa(build_flat_dt(phys_mem_size));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700687}
Stephen Rothwellbec7c452005-11-01 11:45:19 +1100688
Michael Ellermanbf6a7112006-01-11 11:54:08 +1100689static void hvputc(char c)
690{
691 if (c == '\n')
692 hvputc('\r');
693
694 HvCall_writeLogBuffer(&c, 1);
695}
696
697void __init udbg_init_iseries(void)
698{
699 udbg_putc = hvputc;
700}