blob: 0877a88341100e7cdf25a49c3167f0c3a94fdffc [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>
Tony Breeds1ad74992007-09-21 13:26:03 +100029#include <linux/hrtimer.h>
30#include <linux/tick.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>
Stephen Rothwell0bc0ffd2005-06-21 17:15:36 -070046#include <asm/abs_addr.h>
Kelly Daly15b17182005-11-02 11:55:28 +110047#include <asm/iseries/hv_lp_config.h>
Kelly Dalyc0a8d052005-11-02 11:11:11 +110048#include <asm/iseries/hv_call_event.h>
Kelly Daly8021b8a2005-11-02 11:41:12 +110049#include <asm/iseries/hv_call_xm.h>
Kelly Daly8875ccf2005-11-02 14:13:34 +110050#include <asm/iseries/it_lp_queue.h>
Kelly Dalybbc8b622005-11-02 15:10:38 +110051#include <asm/iseries/mf.h>
Kelly Dalye45423e2005-11-02 12:08:31 +110052#include <asm/iseries/hv_lp_event.h>
Kelly Dalyc43a55f2005-11-02 15:02:47 +110053#include <asm/iseries/lpar_map.h>
Michael Ellermanbf6a7112006-01-11 11:54:08 +110054#include <asm/udbg.h>
Stephen Rothwell7d01c882006-04-04 14:49:48 +100055#include <asm/irq.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070056
David Gibsonf11b7bd2005-11-01 15:30:26 +110057#include "naca.h"
Stephen Rothwellc8b84972005-09-27 18:44:42 +100058#include "setup.h"
Stephen Rothwellb08567cb2005-09-28 23:37:01 +100059#include "irq.h"
60#include "vpd_areas.h"
61#include "processor_vpd.h"
Michael Ellerman06a36db2006-07-13 17:52:17 +100062#include "it_lp_naca.h"
Stephen Rothwellb08567cb2005-09-28 23:37:01 +100063#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 -070083
Linus Torvalds1da177e2005-04-16 15:20:36 -070084struct MemoryBlock {
85 unsigned long absStart;
86 unsigned long absEnd;
87 unsigned long logicalStart;
88 unsigned long logicalEnd;
89};
90
91/*
92 * Process the main store vpd to determine where the holes in memory are
93 * and return the number of physical blocks and fill in the array of
94 * block data.
95 */
96static unsigned long iSeries_process_Condor_mainstore_vpd(
97 struct MemoryBlock *mb_array, unsigned long max_entries)
98{
99 unsigned long holeFirstChunk, holeSizeChunks;
100 unsigned long numMemoryBlocks = 1;
101 struct IoHriMainStoreSegment4 *msVpd =
102 (struct IoHriMainStoreSegment4 *)xMsVpd;
103 unsigned long holeStart = msVpd->nonInterleavedBlocksStartAdr;
104 unsigned long holeEnd = msVpd->nonInterleavedBlocksEndAdr;
105 unsigned long holeSize = holeEnd - holeStart;
106
107 printk("Mainstore_VPD: Condor\n");
108 /*
109 * Determine if absolute memory has any
110 * holes so that we can interpret the
111 * access map we get back from the hypervisor
112 * correctly.
113 */
114 mb_array[0].logicalStart = 0;
115 mb_array[0].logicalEnd = 0x100000000;
116 mb_array[0].absStart = 0;
117 mb_array[0].absEnd = 0x100000000;
118
119 if (holeSize) {
120 numMemoryBlocks = 2;
121 holeStart = holeStart & 0x000fffffffffffff;
122 holeStart = addr_to_chunk(holeStart);
123 holeFirstChunk = holeStart;
124 holeSize = addr_to_chunk(holeSize);
125 holeSizeChunks = holeSize;
126 printk( "Main store hole: start chunk = %0lx, size = %0lx chunks\n",
127 holeFirstChunk, holeSizeChunks );
128 mb_array[0].logicalEnd = holeFirstChunk;
129 mb_array[0].absEnd = holeFirstChunk;
130 mb_array[1].logicalStart = holeFirstChunk;
131 mb_array[1].logicalEnd = 0x100000000 - holeSizeChunks;
132 mb_array[1].absStart = holeFirstChunk + holeSizeChunks;
133 mb_array[1].absEnd = 0x100000000;
134 }
135 return numMemoryBlocks;
136}
137
138#define MaxSegmentAreas 32
139#define MaxSegmentAdrRangeBlocks 128
140#define MaxAreaRangeBlocks 4
141
142static unsigned long iSeries_process_Regatta_mainstore_vpd(
143 struct MemoryBlock *mb_array, unsigned long max_entries)
144{
145 struct IoHriMainStoreSegment5 *msVpdP =
146 (struct IoHriMainStoreSegment5 *)xMsVpd;
147 unsigned long numSegmentBlocks = 0;
148 u32 existsBits = msVpdP->msAreaExists;
149 unsigned long area_num;
150
151 printk("Mainstore_VPD: Regatta\n");
152
153 for (area_num = 0; area_num < MaxSegmentAreas; ++area_num ) {
154 unsigned long numAreaBlocks;
155 struct IoHriMainStoreArea4 *currentArea;
156
157 if (existsBits & 0x80000000) {
158 unsigned long block_num;
159
160 currentArea = &msVpdP->msAreaArray[area_num];
161 numAreaBlocks = currentArea->numAdrRangeBlocks;
162 printk("ms_vpd: processing area %2ld blocks=%ld",
163 area_num, numAreaBlocks);
164 for (block_num = 0; block_num < numAreaBlocks;
165 ++block_num ) {
166 /* Process an address range block */
167 struct MemoryBlock tempBlock;
168 unsigned long i;
169
170 tempBlock.absStart =
171 (unsigned long)currentArea->xAdrRangeBlock[block_num].blockStart;
172 tempBlock.absEnd =
173 (unsigned long)currentArea->xAdrRangeBlock[block_num].blockEnd;
174 tempBlock.logicalStart = 0;
175 tempBlock.logicalEnd = 0;
176 printk("\n block %ld absStart=%016lx absEnd=%016lx",
177 block_num, tempBlock.absStart,
178 tempBlock.absEnd);
179
180 for (i = 0; i < numSegmentBlocks; ++i) {
181 if (mb_array[i].absStart ==
182 tempBlock.absStart)
183 break;
184 }
185 if (i == numSegmentBlocks) {
186 if (numSegmentBlocks == max_entries)
187 panic("iSeries_process_mainstore_vpd: too many memory blocks");
188 mb_array[numSegmentBlocks] = tempBlock;
189 ++numSegmentBlocks;
190 } else
191 printk(" (duplicate)");
192 }
193 printk("\n");
194 }
195 existsBits <<= 1;
196 }
197 /* Now sort the blocks found into ascending sequence */
198 if (numSegmentBlocks > 1) {
199 unsigned long m, n;
200
201 for (m = 0; m < numSegmentBlocks - 1; ++m) {
202 for (n = numSegmentBlocks - 1; m < n; --n) {
203 if (mb_array[n].absStart <
204 mb_array[n-1].absStart) {
205 struct MemoryBlock tempBlock;
206
207 tempBlock = mb_array[n];
208 mb_array[n] = mb_array[n-1];
209 mb_array[n-1] = tempBlock;
210 }
211 }
212 }
213 }
214 /*
215 * Assign "logical" addresses to each block. These
216 * addresses correspond to the hypervisor "bitmap" space.
217 * Convert all addresses into units of 256K chunks.
218 */
219 {
220 unsigned long i, nextBitmapAddress;
221
222 printk("ms_vpd: %ld sorted memory blocks\n", numSegmentBlocks);
223 nextBitmapAddress = 0;
224 for (i = 0; i < numSegmentBlocks; ++i) {
225 unsigned long length = mb_array[i].absEnd -
226 mb_array[i].absStart;
227
228 mb_array[i].logicalStart = nextBitmapAddress;
229 mb_array[i].logicalEnd = nextBitmapAddress + length;
230 nextBitmapAddress += length;
231 printk(" Bitmap range: %016lx - %016lx\n"
232 " Absolute range: %016lx - %016lx\n",
233 mb_array[i].logicalStart,
234 mb_array[i].logicalEnd,
235 mb_array[i].absStart, mb_array[i].absEnd);
236 mb_array[i].absStart = addr_to_chunk(mb_array[i].absStart &
237 0x000fffffffffffff);
238 mb_array[i].absEnd = addr_to_chunk(mb_array[i].absEnd &
239 0x000fffffffffffff);
240 mb_array[i].logicalStart =
241 addr_to_chunk(mb_array[i].logicalStart);
242 mb_array[i].logicalEnd = addr_to_chunk(mb_array[i].logicalEnd);
243 }
244 }
245
246 return numSegmentBlocks;
247}
248
249static unsigned long iSeries_process_mainstore_vpd(struct MemoryBlock *mb_array,
250 unsigned long max_entries)
251{
252 unsigned long i;
253 unsigned long mem_blocks = 0;
254
255 if (cpu_has_feature(CPU_FTR_SLB))
256 mem_blocks = iSeries_process_Regatta_mainstore_vpd(mb_array,
257 max_entries);
258 else
259 mem_blocks = iSeries_process_Condor_mainstore_vpd(mb_array,
260 max_entries);
261
262 printk("Mainstore_VPD: numMemoryBlocks = %ld \n", mem_blocks);
263 for (i = 0; i < mem_blocks; ++i) {
264 printk("Mainstore_VPD: block %3ld logical chunks %016lx - %016lx\n"
265 " abs chunks %016lx - %016lx\n",
266 i, mb_array[i].logicalStart, mb_array[i].logicalEnd,
267 mb_array[i].absStart, mb_array[i].absEnd);
268 }
269 return mem_blocks;
270}
271
272static void __init iSeries_get_cmdline(void)
273{
274 char *p, *q;
275
276 /* copy the command line parameter from the primary VSP */
277 HvCallEvent_dmaToSp(cmd_line, 2 * 64* 1024, 256,
278 HvLpDma_Direction_RemoteToLocal);
279
280 p = cmd_line;
281 q = cmd_line + 255;
282 while(p < q) {
283 if (!*p || *p == '\n')
284 break;
285 ++p;
286 }
287 *p = 0;
288}
289
290static void __init iSeries_init_early(void)
291{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700292 DBG(" -> iSeries_init_early()\n");
293
Tony Breeds71712b42007-06-22 16:54:30 +1000294 /* Snapshot the timebase, for use in later recalibration */
295 iSeries_time_init_early();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700296
297 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700298 * Initialize the DMA/TCE management
299 */
300 iommu_init_early_iSeries();
301
Linus Torvalds1da177e2005-04-16 15:20:36 -0700302 /* Initialize machine-dependency vectors */
303#ifdef CONFIG_SMP
304 smp_init_iSeries();
305#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700306
307 /* Associate Lp Event Queue 0 with processor 0 */
308 HvCallEvent_setLpEventQueueInterruptProc(0, 0);
309
310 mf_init();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700311
Linus Torvalds1da177e2005-04-16 15:20:36 -0700312 DBG(" <- iSeries_init_early()\n");
313}
314
Michael Ellerman56e97b72005-08-03 20:21:23 +1000315struct mschunks_map mschunks_map = {
Michael Ellerman34c8f692005-08-03 20:21:23 +1000316 /* XXX We don't use these, but Piranha might need them. */
317 .chunk_size = MSCHUNKS_CHUNK_SIZE,
318 .chunk_shift = MSCHUNKS_CHUNK_SHIFT,
319 .chunk_mask = MSCHUNKS_OFFSET_MASK,
320};
Michael Ellerman56e97b72005-08-03 20:21:23 +1000321EXPORT_SYMBOL(mschunks_map);
Michael Ellerman34c8f692005-08-03 20:21:23 +1000322
Michael Ellerman56e97b72005-08-03 20:21:23 +1000323void mschunks_alloc(unsigned long num_chunks)
Michael Ellerman34c8f692005-08-03 20:21:23 +1000324{
325 klimit = _ALIGN(klimit, sizeof(u32));
Michael Ellerman56e97b72005-08-03 20:21:23 +1000326 mschunks_map.mapping = (u32 *)klimit;
Michael Ellerman34c8f692005-08-03 20:21:23 +1000327 klimit += num_chunks * sizeof(u32);
Michael Ellerman56e97b72005-08-03 20:21:23 +1000328 mschunks_map.num_chunks = num_chunks;
Michael Ellerman34c8f692005-08-03 20:21:23 +1000329}
330
Linus Torvalds1da177e2005-04-16 15:20:36 -0700331/*
332 * The iSeries may have very large memories ( > 128 GB ) and a partition
333 * may get memory in "chunks" that may be anywhere in the 2**52 real
334 * address space. The chunks are 256K in size. To map this to the
335 * memory model Linux expects, the AS/400 specific code builds a
336 * translation table to translate what Linux thinks are "physical"
337 * addresses to the actual real addresses. This allows us to make
338 * it appear to Linux that we have contiguous memory starting at
339 * physical address zero while in fact this could be far from the truth.
340 * To avoid confusion, I'll let the words physical and/or real address
341 * apply to the Linux addresses while I'll use "absolute address" to
342 * refer to the actual hardware real address.
343 *
344 * build_iSeries_Memory_Map gets information from the Hypervisor and
345 * looks at the Main Store VPD to determine the absolute addresses
346 * of the memory that has been assigned to our partition and builds
347 * a table used to translate Linux's physical addresses to these
348 * absolute addresses. Absolute addresses are needed when
349 * communicating with the hypervisor (e.g. to build HPT entries)
Paul Mackerras799d6042005-11-10 13:37:51 +1100350 *
351 * Returns the physical memory size
Linus Torvalds1da177e2005-04-16 15:20:36 -0700352 */
353
Paul Mackerras799d6042005-11-10 13:37:51 +1100354static unsigned long __init build_iSeries_Memory_Map(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700355{
356 u32 loadAreaFirstChunk, loadAreaLastChunk, loadAreaSize;
357 u32 nextPhysChunk;
358 u32 hptFirstChunk, hptLastChunk, hptSizeChunks, hptSizePages;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700359 u32 totalChunks,moreChunks;
360 u32 currChunk, thisChunk, absChunk;
361 u32 currDword;
362 u32 chunkBit;
363 u64 map;
364 struct MemoryBlock mb[32];
365 unsigned long numMemoryBlocks, curBlock;
366
367 /* Chunk size on iSeries is 256K bytes */
368 totalChunks = (u32)HvLpConfig_getMsChunks();
Michael Ellerman56e97b72005-08-03 20:21:23 +1000369 mschunks_alloc(totalChunks);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700370
371 /*
372 * Get absolute address of our load area
373 * and map it to physical address 0
374 * This guarantees that the loadarea ends up at physical 0
375 * otherwise, it might not be returned by PLIC as the first
376 * chunks
377 */
378
379 loadAreaFirstChunk = (u32)addr_to_chunk(itLpNaca.xLoadAreaAddr);
380 loadAreaSize = itLpNaca.xLoadAreaChunks;
381
382 /*
383 * Only add the pages already mapped here.
384 * Otherwise we might add the hpt pages
385 * The rest of the pages of the load area
386 * aren't in the HPT yet and can still
387 * be assigned an arbitrary physical address
388 */
389 if ((loadAreaSize * 64) > HvPagesToMap)
390 loadAreaSize = HvPagesToMap / 64;
391
392 loadAreaLastChunk = loadAreaFirstChunk + loadAreaSize - 1;
393
394 /*
395 * TODO Do we need to do something if the HPT is in the 64MB load area?
396 * This would be required if the itLpNaca.xLoadAreaChunks includes
397 * the HPT size
398 */
399
400 printk("Mapping load area - physical addr = 0000000000000000\n"
401 " absolute addr = %016lx\n",
402 chunk_to_addr(loadAreaFirstChunk));
403 printk("Load area size %dK\n", loadAreaSize * 256);
404
405 for (nextPhysChunk = 0; nextPhysChunk < loadAreaSize; ++nextPhysChunk)
Michael Ellerman56e97b72005-08-03 20:21:23 +1000406 mschunks_map.mapping[nextPhysChunk] =
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407 loadAreaFirstChunk + nextPhysChunk;
408
409 /*
410 * Get absolute address of our HPT and remember it so
411 * we won't map it to any physical address
412 */
413 hptFirstChunk = (u32)addr_to_chunk(HvCallHpt_getHptAddress());
414 hptSizePages = (u32)HvCallHpt_getHptPages();
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100415 hptSizeChunks = hptSizePages >>
416 (MSCHUNKS_CHUNK_SHIFT - HW_PAGE_SHIFT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700417 hptLastChunk = hptFirstChunk + hptSizeChunks - 1;
418
419 printk("HPT absolute addr = %016lx, size = %dK\n",
420 chunk_to_addr(hptFirstChunk), hptSizeChunks * 256);
421
Linus Torvalds1da177e2005-04-16 15:20:36 -0700422 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423 * Determine if absolute memory has any
424 * holes so that we can interpret the
425 * access map we get back from the hypervisor
426 * correctly.
427 */
428 numMemoryBlocks = iSeries_process_mainstore_vpd(mb, 32);
429
430 /*
431 * Process the main store access map from the hypervisor
432 * to build up our physical -> absolute translation table
433 */
434 curBlock = 0;
435 currChunk = 0;
436 currDword = 0;
437 moreChunks = totalChunks;
438
439 while (moreChunks) {
440 map = HvCallSm_get64BitsOfAccessMap(itLpNaca.xLpIndex,
441 currDword);
442 thisChunk = currChunk;
443 while (map) {
444 chunkBit = map >> 63;
445 map <<= 1;
446 if (chunkBit) {
447 --moreChunks;
448 while (thisChunk >= mb[curBlock].logicalEnd) {
449 ++curBlock;
450 if (curBlock >= numMemoryBlocks)
451 panic("out of memory blocks");
452 }
453 if (thisChunk < mb[curBlock].logicalStart)
454 panic("memory block error");
455
456 absChunk = mb[curBlock].absStart +
457 (thisChunk - mb[curBlock].logicalStart);
458 if (((absChunk < hptFirstChunk) ||
459 (absChunk > hptLastChunk)) &&
460 ((absChunk < loadAreaFirstChunk) ||
461 (absChunk > loadAreaLastChunk))) {
Michael Ellerman56e97b72005-08-03 20:21:23 +1000462 mschunks_map.mapping[nextPhysChunk] =
463 absChunk;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700464 ++nextPhysChunk;
465 }
466 }
467 ++thisChunk;
468 }
469 ++currDword;
470 currChunk += 64;
471 }
472
473 /*
474 * main store size (in chunks) is
475 * totalChunks - hptSizeChunks
476 * which should be equal to
477 * nextPhysChunk
478 */
Paul Mackerras799d6042005-11-10 13:37:51 +1100479 return chunk_to_addr(nextPhysChunk);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700480}
481
482/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700483 * Document me.
484 */
485static void __init iSeries_setup_arch(void)
486{
David Gibson3356bb92006-01-13 10:26:42 +1100487 if (get_lppaca()->shared_proc) {
Michael Ellerman9f497582005-09-23 14:10:59 +1000488 ppc_md.idle_loop = iseries_shared_idle;
Olof Johansson4baaf0c2006-04-12 15:23:22 -0500489 printk(KERN_DEBUG "Using shared processor idle loop\n");
Michael Ellerman9f497582005-09-23 14:10:59 +1000490 } else {
491 ppc_md.idle_loop = iseries_dedicated_idle;
Olof Johansson4baaf0c2006-04-12 15:23:22 -0500492 printk(KERN_DEBUG "Using dedicated idle loop\n");
Michael Ellerman9f497582005-09-23 14:10:59 +1000493 }
494
Linus Torvalds1da177e2005-04-16 15:20:36 -0700495 /* Setup the Lp Event Queue */
Michael Ellerman512d31d2005-06-30 15:08:27 +1000496 setup_hvlpevent_queue();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700497
Linus Torvalds1da177e2005-04-16 15:20:36 -0700498 printk("Max logical processors = %d\n",
499 itVpdAreas.xSlicMaxLogicalProcs);
500 printk("Max physical processors = %d\n",
501 itVpdAreas.xSlicMaxPhysicalProcs);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700502}
503
Paul Mackerrasd8699e62005-10-20 17:02:01 +1000504static void iSeries_show_cpuinfo(struct seq_file *m)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700505{
506 seq_printf(m, "machine\t\t: 64-bit iSeries Logical Partition\n");
507}
508
Linus Torvalds1da177e2005-04-16 15:20:36 -0700509static void __init iSeries_progress(char * st, unsigned short code)
510{
511 printk("Progress: [%04x] - %s\n", (unsigned)code, st);
Michael Ellerman260de222006-03-21 20:46:02 +1100512 mf_display_progress(code);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700513}
514
515static void __init iSeries_fixup_klimit(void)
516{
517 /*
518 * Change klimit to take into account any ram disk
519 * that may be included
520 */
521 if (naca.xRamDisk)
522 klimit = KERNELBASE + (u64)naca.xRamDisk +
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100523 (naca.xRamDiskSize * HW_PAGE_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700524}
525
526static int __init iSeries_src_init(void)
527{
528 /* clear the progress line */
Stephen Rothwelle75b1712007-01-04 17:06:21 +1100529 if (firmware_has_feature(FW_FEATURE_ISERIES))
530 ppc_md.progress(" ", 0xffff);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700531 return 0;
532}
533
534late_initcall(iSeries_src_init);
535
Michael Ellermand2009032005-07-07 17:56:29 -0700536static inline void process_iSeries_events(void)
537{
538 asm volatile ("li 0,0x5555; sc" : : : "r0", "r3");
539}
540
541static void yield_shared_processor(void)
542{
543 unsigned long tb;
Michael Ellermand2009032005-07-07 17:56:29 -0700544
545 HvCall_setEnabledInterrupts(HvCall_MaskIPI |
546 HvCall_MaskLpEvent |
547 HvCall_MaskLpProd |
548 HvCall_MaskTimeout);
549
550 tb = get_tb();
551 /* Compute future tb value when yield should expire */
552 HvCall_yieldProcessor(HvCall_YieldTimed, tb+tb_ticks_per_jiffy);
553
Michael Ellermand2009032005-07-07 17:56:29 -0700554 /*
555 * The decrementer stops during the yield. Force a fake decrementer
556 * here and let the timer_interrupt code sort out the actual time.
557 */
David Gibson3356bb92006-01-13 10:26:42 +1100558 get_lppaca()->int_dword.fields.decr_int = 1;
Anton Blanchardcb2c9b22006-02-13 14:48:35 +1100559 ppc64_runlatch_on();
Michael Ellermand2009032005-07-07 17:56:29 -0700560 process_iSeries_events();
561}
562
Paul Mackerras143a1de2005-10-19 23:11:21 +1000563static void iseries_shared_idle(void)
Michael Ellermand2009032005-07-07 17:56:29 -0700564{
Anton Blanchard3c57bb92005-07-07 17:56:32 -0700565 while (1) {
Tony Breeds1ad74992007-09-21 13:26:03 +1000566 tick_nohz_stop_sched_tick();
Anton Blanchard3c57bb92005-07-07 17:56:32 -0700567 while (!need_resched() && !hvlpevent_is_pending()) {
568 local_irq_disable();
569 ppc64_runlatch_off();
570
571 /* Recheck with irqs off */
572 if (!need_resched() && !hvlpevent_is_pending())
573 yield_shared_processor();
574
575 HMT_medium();
576 local_irq_enable();
577 }
578
579 ppc64_runlatch_on();
Tony Breeds1ad74992007-09-21 13:26:03 +1000580 tick_nohz_restart_sched_tick();
Anton Blanchard3c57bb92005-07-07 17:56:32 -0700581
582 if (hvlpevent_is_pending())
583 process_iSeries_events();
584
Nick Piggin5bfb5d62005-11-08 21:39:01 -0800585 preempt_enable_no_resched();
Anton Blanchard3c57bb92005-07-07 17:56:32 -0700586 schedule();
Nick Piggin5bfb5d62005-11-08 21:39:01 -0800587 preempt_disable();
Anton Blanchard3c57bb92005-07-07 17:56:32 -0700588 }
Anton Blanchard3c57bb92005-07-07 17:56:32 -0700589}
590
Paul Mackerras143a1de2005-10-19 23:11:21 +1000591static void iseries_dedicated_idle(void)
Anton Blanchard3c57bb92005-07-07 17:56:32 -0700592{
Nick Piggin64c7c8f2005-11-08 21:39:04 -0800593 set_thread_flag(TIF_POLLING_NRFLAG);
Michael Ellermand2009032005-07-07 17:56:29 -0700594
Michael Ellermand2009032005-07-07 17:56:29 -0700595 while (1) {
Tony Breeds1ad74992007-09-21 13:26:03 +1000596 tick_nohz_stop_sched_tick();
Nick Piggin64c7c8f2005-11-08 21:39:04 -0800597 if (!need_resched()) {
Anton Blanchard3c57bb92005-07-07 17:56:32 -0700598 while (!need_resched()) {
599 ppc64_runlatch_off();
600 HMT_low();
601
602 if (hvlpevent_is_pending()) {
Michael Ellermand2009032005-07-07 17:56:29 -0700603 HMT_medium();
Anton Blanchard3c57bb92005-07-07 17:56:32 -0700604 ppc64_runlatch_on();
605 process_iSeries_events();
Michael Ellermand2009032005-07-07 17:56:29 -0700606 }
Michael Ellermand2009032005-07-07 17:56:29 -0700607 }
Anton Blanchard3c57bb92005-07-07 17:56:32 -0700608
609 HMT_medium();
Michael Ellermand2009032005-07-07 17:56:29 -0700610 }
611
612 ppc64_runlatch_on();
Tony Breeds1ad74992007-09-21 13:26:03 +1000613 tick_nohz_restart_sched_tick();
Nick Piggin5bfb5d62005-11-08 21:39:01 -0800614 preempt_enable_no_resched();
Michael Ellermand2009032005-07-07 17:56:29 -0700615 schedule();
Nick Piggin5bfb5d62005-11-08 21:39:01 -0800616 preempt_disable();
Michael Ellermand2009032005-07-07 17:56:29 -0700617 }
Michael Ellermand2009032005-07-07 17:56:29 -0700618}
619
Benjamin Herrenschmidt68a64352006-11-13 09:27:39 +1100620static void __iomem *iseries_ioremap(phys_addr_t address, unsigned long size,
Benjamin Herrenschmidt4cb3cee2006-11-11 17:25:10 +1100621 unsigned long flags)
622{
623 return (void __iomem *)address;
624}
625
Benjamin Herrenschmidt68a64352006-11-13 09:27:39 +1100626static void iseries_iounmap(volatile void __iomem *token)
Benjamin Herrenschmidt4cb3cee2006-11-11 17:25:10 +1100627{
628}
629
Benjamin Herrenschmidte8222502006-03-28 23:15:54 +1100630static int __init iseries_probe(void)
Michael Ellerman47627132005-09-23 14:59:04 +1000631{
Benjamin Herrenschmidte8222502006-03-28 23:15:54 +1100632 unsigned long root = of_get_flat_dt_root();
633 if (!of_flat_dt_is_compatible(root, "IBM,iSeries"))
Michael Ellerman57cfb812006-03-21 20:45:59 +1100634 return 0;
635
Michael Ellerman7d0daae2006-06-23 18:16:38 +1000636 hpte_init_iSeries();
Stephen Rothwell04704662006-11-30 11:46:22 +1100637 /* iSeries does not support 16M pages */
638 cur_cpu_spec->cpu_features &= ~CPU_FTR_16M_PAGE;
Michael Ellerman7d0daae2006-06-23 18:16:38 +1000639
Michael Ellerman57cfb812006-03-21 20:45:59 +1100640 return 1;
Michael Ellerman47627132005-09-23 14:59:04 +1000641}
642
Benjamin Herrenschmidte8222502006-03-28 23:15:54 +1100643define_machine(iseries) {
644 .name = "iSeries",
Michael Ellerman9f497582005-09-23 14:10:59 +1000645 .setup_arch = iSeries_setup_arch,
Paul Mackerrasd8699e62005-10-20 17:02:01 +1000646 .show_cpuinfo = iSeries_show_cpuinfo,
Michael Ellerman9f497582005-09-23 14:10:59 +1000647 .init_IRQ = iSeries_init_IRQ,
648 .get_irq = iSeries_get_irq,
649 .init_early = iSeries_init_early,
650 .pcibios_fixup = iSeries_pci_final_fixup,
Michael Ellermana9ea2102006-03-21 20:46:04 +1100651 .restart = mf_reboot,
652 .power_off = mf_power_off,
653 .halt = mf_power_off,
Michael Ellerman9f497582005-09-23 14:10:59 +1000654 .get_boot_time = iSeries_get_boot_time,
655 .set_rtc_time = iSeries_set_rtc_time,
656 .get_rtc_time = iSeries_get_rtc_time,
Michael Ellerman95b29382005-09-23 15:03:10 +1000657 .calibrate_decr = generic_calibrate_decr,
Michael Ellerman9f497582005-09-23 14:10:59 +1000658 .progress = iSeries_progress,
Michael Ellerman47627132005-09-23 14:59:04 +1000659 .probe = iseries_probe,
Benjamin Herrenschmidt4cb3cee2006-11-11 17:25:10 +1100660 .ioremap = iseries_ioremap,
661 .iounmap = iseries_iounmap,
Michael Ellerman9f497582005-09-23 14:10:59 +1000662 /* XXX Implement enable_pmcs for iSeries */
663};
664
Michael Ellerman47627132005-09-23 14:59:04 +1000665void * __init iSeries_early_setup(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700666{
Paul Mackerras799d6042005-11-10 13:37:51 +1100667 unsigned long phys_mem_size;
668
Benjamin Herrenschmidt42c4aaa2006-10-24 16:42:40 +1000669 /* Identify CPU type. This is done again by the common code later
670 * on but calling this function multiple times is fine.
671 */
Paul Mackerras974a76f2006-11-10 20:38:53 +1100672 identify_cpu(0, mfspr(SPRN_PVR));
Benjamin Herrenschmidt42c4aaa2006-10-24 16:42:40 +1000673
Stephen Rothwellef26a462006-09-25 13:27:17 +1000674 powerpc_firmware_features |= FW_FEATURE_ISERIES;
675 powerpc_firmware_features |= FW_FEATURE_LPAR;
676
Linus Torvalds1da177e2005-04-16 15:20:36 -0700677 iSeries_fixup_klimit();
Michael Ellermanc0a59492005-09-23 14:56:09 +1000678
Michael Ellerman47627132005-09-23 14:59:04 +1000679 /*
680 * Initialize the table which translate Linux physical addresses to
681 * AS/400 absolute addresses
682 */
Paul Mackerras799d6042005-11-10 13:37:51 +1100683 phys_mem_size = build_iSeries_Memory_Map();
Michael Ellerman47627132005-09-23 14:59:04 +1000684
Stephen Rothwellbec7c452005-11-01 11:45:19 +1100685 iSeries_get_cmdline();
686
Stephen Rothwellc81014f2006-05-19 17:00:04 +1000687 return (void *) __pa(build_flat_dt(phys_mem_size));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700688}
Stephen Rothwellbec7c452005-11-01 11:45:19 +1100689
Michael Ellermanbf6a7112006-01-11 11:54:08 +1100690static void hvputc(char c)
691{
692 if (c == '\n')
693 hvputc('\r');
694
695 HvCall_writeLogBuffer(&c, 1);
696}
697
698void __init udbg_init_iseries(void)
699{
700 udbg_putc = hvputc;
701}