18eba8d44b9f768ee7dec927a327478f67be0113
[linux-flexiantxendom0-3.2.10.git] / arch / ia64 / kernel / setup.c
1 /*
2  * Architecture-specific setup.
3  *
4  * Copyright (C) 1998-2001, 2003 Hewlett-Packard Co
5  *      David Mosberger-Tang <davidm@hpl.hp.com>
6  *      Stephane Eranian <eranian@hpl.hp.com>
7  * Copyright (C) 2000, Rohit Seth <rohit.seth@intel.com>
8  * Copyright (C) 1999 VA Linux Systems
9  * Copyright (C) 1999 Walt Drummond <drummond@valinux.com>
10  *
11  * 11/12/01 D.Mosberger Convert get_cpuinfo() to seq_file based show_cpuinfo().
12  * 04/04/00 D.Mosberger renamed cpu_initialized to cpu_online_map
13  * 03/31/00 R.Seth      cpu_initialized and current->processor fixes
14  * 02/04/00 D.Mosberger some more get_cpuinfo fixes...
15  * 02/01/00 R.Seth      fixed get_cpuinfo for SMP
16  * 01/07/99 S.Eranian   added the support for command line argument
17  * 06/24/99 W.Drummond  added boot_cpu_data.
18  */
19 #include <linux/config.h>
20 #include <linux/init.h>
21
22 #include <linux/acpi.h>
23 #include <linux/bootmem.h>
24 #include <linux/console.h>
25 #include <linux/delay.h>
26 #include <linux/kernel.h>
27 #include <linux/reboot.h>
28 #include <linux/sched.h>
29 #include <linux/seq_file.h>
30 #include <linux/string.h>
31 #include <linux/threads.h>
32 #include <linux/tty.h>
33 #include <linux/efi.h>
34 #include <linux/initrd.h>
35
36 #include <asm/ia32.h>
37 #include <asm/page.h>
38 #include <asm/pgtable.h>
39 #include <asm/machvec.h>
40 #include <asm/processor.h>
41 #include <asm/sal.h>
42 #include <asm/system.h>
43 #include <asm/mca.h>
44 #include <asm/smp.h>
45
46 #if defined(CONFIG_SMP) && (IA64_CPU_SIZE > PAGE_SIZE)
47 # error "struct cpuinfo_ia64 too big!"
48 #endif
49
50 extern char _end;
51
52 #ifdef CONFIG_SMP
53 unsigned long __per_cpu_offset[NR_CPUS];
54 #endif
55
56 DEFINE_PER_CPU(struct cpuinfo_ia64, cpu_info);
57 DEFINE_PER_CPU(unsigned long, ia64_phys_stacked_size_p8);
58 unsigned long ia64_cycles_per_usec;
59 struct ia64_boot_param *ia64_boot_param;
60 struct screen_info screen_info;
61
62 unsigned long ia64_max_cacheline_size;
63 unsigned long ia64_iobase;      /* virtual address for I/O accesses */
64 struct io_space io_space[MAX_IO_SPACES];
65 unsigned int num_io_spaces;
66
67 unsigned char aux_device_present = 0xaa;        /* XXX remove this when legacy I/O is gone */
68
69 #define COMMAND_LINE_SIZE       512
70
71 char saved_command_line[COMMAND_LINE_SIZE]; /* used in proc filesystem */
72
73 /*
74  * Entries defined so far:
75  *      - boot param structure itself
76  *      - memory map
77  *      - initrd (optional)
78  *      - command line string
79  *      - kernel code & data
80  *
81  * More could be added if necessary
82  */
83 #define IA64_MAX_RSVD_REGIONS 5
84
85 struct rsvd_region {
86         unsigned long start;    /* virtual address of beginning of element */
87         unsigned long end;      /* virtual address of end of element + 1 */
88 };
89
90 /*
91  * We use a special marker for the end of memory and it uses the extra (+1) slot
92  */
93 static struct rsvd_region rsvd_region[IA64_MAX_RSVD_REGIONS + 1];
94 static int num_rsvd_regions;
95
96 #define IGNORE_PFN0     1       /* XXX fix me: ignore pfn 0 until TLB miss handler is updated... */
97
98 #ifndef CONFIG_DISCONTIGMEM
99
100 static unsigned long bootmap_start; /* physical address where the bootmem map is located */
101
102 static int
103 find_max_pfn (unsigned long start, unsigned long end, void *arg)
104 {
105         unsigned long *max_pfn = arg, pfn;
106
107         pfn = (PAGE_ALIGN(end - 1) - PAGE_OFFSET) >> PAGE_SHIFT;
108         if (pfn > *max_pfn)
109                 *max_pfn = pfn;
110         return 0;
111 }
112
113 #else /* CONFIG_DISCONTIGMEM */
114
115 /*
116  * efi_memmap_walk() knows nothing about layout of memory across nodes. Find
117  * out to which node a block of memory belongs.  Ignore memory that we cannot
118  * identify, and split blocks that run across multiple nodes.
119  *
120  * Take this opportunity to round the start address up and the end address
121  * down to page boundaries.
122  */
123 void
124 call_pernode_memory (unsigned long start, unsigned long end, void *arg)
125 {
126         unsigned long rs, re;
127         void (*func)(unsigned long, unsigned long, int, int);
128         int i;
129
130         start = PAGE_ALIGN(start);
131         end &= PAGE_MASK;
132         if (start >= end)
133                 return;
134
135         func = arg;
136
137         if (!num_memblks) {
138                 /*
139                  * This machine doesn't have SRAT, so call func with
140                  * nid=0, bank=0.
141                  */
142                 if (start < end)
143                         (*func)(start, end - start, 0, 0);
144                 return;
145         }
146
147         for (i = 0; i < num_memblks; i++) {
148                 rs = max(start, node_memblk[i].start_paddr);
149                 re = min(end, node_memblk[i].start_paddr+node_memblk[i].size);
150
151                 if (rs < re)
152                         (*func)(rs, re-rs, node_memblk[i].nid,
153                                 node_memblk[i].bank);
154         }
155 }
156
157 #endif /* CONFIG_DISCONTIGMEM */
158
159 /*
160  * Filter incoming memory segments based on the primitive map created from the boot
161  * parameters. Segments contained in the map are removed from the memory ranges. A
162  * caller-specified function is called with the memory ranges that remain after filtering.
163  * This routine does not assume the incoming segments are sorted.
164  */
165 int
166 filter_rsvd_memory (unsigned long start, unsigned long end, void *arg)
167 {
168         unsigned long range_start, range_end, prev_start;
169         void (*func)(unsigned long, unsigned long);
170         int i;
171
172 #if IGNORE_PFN0
173         if (start == PAGE_OFFSET) {
174                 printk(KERN_WARNING "warning: skipping physical page 0\n");
175                 start += PAGE_SIZE;
176                 if (start >= end) return 0;
177         }
178 #endif
179         /*
180          * lowest possible address(walker uses virtual)
181          */
182         prev_start = PAGE_OFFSET;
183         func = arg;
184
185         for (i = 0; i < num_rsvd_regions; ++i) {
186                 range_start = max(start, prev_start);
187                 range_end   = min(end, rsvd_region[i].start);
188
189                 if (range_start < range_end)
190 #ifdef CONFIG_DISCONTIGMEM
191                         call_pernode_memory(__pa(range_start), __pa(range_end), func);
192 #else
193                         (*func)(__pa(range_start), range_end - range_start);
194 #endif
195
196                 /* nothing more available in this segment */
197                 if (range_end == end) return 0;
198
199                 prev_start = rsvd_region[i].end;
200         }
201         /* end of memory marker allows full processing inside loop body */
202         return 0;
203 }
204
205
206 #ifndef CONFIG_DISCONTIGMEM
207 /*
208  * Find a place to put the bootmap and return its starting address in bootmap_start.
209  * This address must be page-aligned.
210  */
211 static int
212 find_bootmap_location (unsigned long start, unsigned long end, void *arg)
213 {
214         unsigned long needed = *(unsigned long *)arg;
215         unsigned long range_start, range_end, free_start;
216         int i;
217
218 #if IGNORE_PFN0
219         if (start == PAGE_OFFSET) {
220                 start += PAGE_SIZE;
221                 if (start >= end) return 0;
222         }
223 #endif
224
225         free_start = PAGE_OFFSET;
226
227         for (i = 0; i < num_rsvd_regions; i++) {
228                 range_start = max(start, free_start);
229                 range_end   = min(end, rsvd_region[i].start & PAGE_MASK);
230
231                 if (range_end <= range_start) continue; /* skip over empty range */
232
233                 if (range_end - range_start >= needed) {
234                         bootmap_start = __pa(range_start);
235                         return 1;       /* done */
236                 }
237
238                 /* nothing more available in this segment */
239                 if (range_end == end) return 0;
240
241                 free_start = PAGE_ALIGN(rsvd_region[i].end);
242         }
243         return 0;
244 }
245 #endif /* !CONFIG_DISCONTIGMEM */
246
247 static void
248 sort_regions (struct rsvd_region *rsvd_region, int max)
249 {
250         int j;
251
252         /* simple bubble sorting */
253         while (max--) {
254                 for (j = 0; j < max; ++j) {
255                         if (rsvd_region[j].start > rsvd_region[j+1].start) {
256                                 struct rsvd_region tmp;
257                                 tmp = rsvd_region[j];
258                                 rsvd_region[j] = rsvd_region[j + 1];
259                                 rsvd_region[j + 1] = tmp;
260                         }
261                 }
262         }
263 }
264
265 static void
266 find_memory (void)
267 {
268 #       define KERNEL_END       ((unsigned long) &_end)
269         unsigned long bootmap_size;
270         unsigned long max_pfn;
271         int n = 0;
272
273         /*
274          * none of the entries in this table overlap
275          */
276         rsvd_region[n].start = (unsigned long) ia64_boot_param;
277         rsvd_region[n].end   = rsvd_region[n].start + sizeof(*ia64_boot_param);
278         n++;
279
280         rsvd_region[n].start = (unsigned long) __va(ia64_boot_param->efi_memmap);
281         rsvd_region[n].end   = rsvd_region[n].start + ia64_boot_param->efi_memmap_size;
282         n++;
283
284         rsvd_region[n].start = (unsigned long) __va(ia64_boot_param->command_line);
285         rsvd_region[n].end   = (rsvd_region[n].start
286                                 + strlen(__va(ia64_boot_param->command_line)) + 1);
287         n++;
288
289         rsvd_region[n].start = KERNEL_START;
290         rsvd_region[n].end   = KERNEL_END;
291         n++;
292
293 #ifdef CONFIG_BLK_DEV_INITRD
294         if (ia64_boot_param->initrd_start) {
295                 rsvd_region[n].start = (unsigned long)__va(ia64_boot_param->initrd_start);
296                 rsvd_region[n].end   = rsvd_region[n].start + ia64_boot_param->initrd_size;
297                 n++;
298         }
299 #endif
300
301         /* end of memory marker */
302         rsvd_region[n].start = ~0UL;
303         rsvd_region[n].end   = ~0UL;
304         n++;
305
306         num_rsvd_regions = n;
307
308         sort_regions(rsvd_region, num_rsvd_regions);
309
310 #ifdef CONFIG_DISCONTIGMEM
311         {
312                 extern void discontig_mem_init (void);
313
314                 bootmap_size = max_pfn = 0;     /* stop gcc warnings */
315                 discontig_mem_init();
316         }
317 #else /* !CONFIG_DISCONTIGMEM */
318
319         /* first find highest page frame number */
320         max_pfn = 0;
321         efi_memmap_walk(find_max_pfn, &max_pfn);
322
323         /* how many bytes to cover all the pages */
324         bootmap_size = bootmem_bootmap_pages(max_pfn) << PAGE_SHIFT;
325
326         /* look for a location to hold the bootmap */
327         bootmap_start = ~0UL;
328         efi_memmap_walk(find_bootmap_location, &bootmap_size);
329         if (bootmap_start == ~0UL)
330                 panic("Cannot find %ld bytes for bootmap\n", bootmap_size);
331
332         bootmap_size = init_bootmem(bootmap_start >> PAGE_SHIFT, max_pfn);
333
334         /* Free all available memory, then mark bootmem-map as being in use.  */
335         efi_memmap_walk(filter_rsvd_memory, free_bootmem);
336         reserve_bootmem(bootmap_start, bootmap_size);
337 #endif /* !CONFIG_DISCONTIGMEM */
338
339 #ifdef CONFIG_BLK_DEV_INITRD
340         if (ia64_boot_param->initrd_start) {
341                 initrd_start = (unsigned long)__va(ia64_boot_param->initrd_start);
342                 initrd_end   = initrd_start+ia64_boot_param->initrd_size;
343
344                 printk(KERN_INFO "Initial ramdisk at: 0x%lx (%lu bytes)\n",
345                        initrd_start, ia64_boot_param->initrd_size);
346         }
347 #endif
348 }
349
350 void __init
351 setup_arch (char **cmdline_p)
352 {
353         extern unsigned long ia64_iobase;
354         unsigned long phys_iobase;
355
356         unw_init();
357
358         *cmdline_p = __va(ia64_boot_param->command_line);
359         strlcpy(saved_command_line, *cmdline_p, sizeof(saved_command_line));
360
361         efi_init();
362
363 #ifdef CONFIG_ACPI_BOOT
364         /* Initialize the ACPI boot-time table parser */
365         acpi_table_init();
366 # ifdef CONFIG_ACPI_NUMA
367         acpi_numa_init();
368 # endif
369 #else
370 # ifdef CONFIG_SMP
371         smp_build_cpu_map();    /* happens, e.g., with the Ski simulator */
372 # endif
373 #endif /* CONFIG_APCI_BOOT */
374
375         find_memory();
376
377 #if 0
378         /* XXX fix me */
379         init_mm.start_code = (unsigned long) &_stext;
380         init_mm.end_code = (unsigned long) &_etext;
381         init_mm.end_data = (unsigned long) &_edata;
382         init_mm.brk = (unsigned long) &_end;
383
384         code_resource.start = virt_to_bus(&_text);
385         code_resource.end = virt_to_bus(&_etext) - 1;
386         data_resource.start = virt_to_bus(&_etext);
387         data_resource.end = virt_to_bus(&_edata) - 1;
388 #endif
389
390         /* process SAL system table: */
391         ia64_sal_init(efi.sal_systab);
392
393 #ifdef CONFIG_IA64_GENERIC
394         machvec_init(acpi_get_sysname());
395 #endif
396
397         /*
398          *  Set `iobase' to the appropriate address in region 6 (uncached access range).
399          *
400          *  The EFI memory map is the "preferred" location to get the I/O port space base,
401          *  rather the relying on AR.KR0. This should become more clear in future SAL
402          *  specs. We'll fall back to getting it out of AR.KR0 if no appropriate entry is
403          *  found in the memory map.
404          */
405         phys_iobase = efi_get_iobase();
406         if (phys_iobase)
407                 /* set AR.KR0 since this is all we use it for anyway */
408                 ia64_set_kr(IA64_KR_IO_BASE, phys_iobase);
409         else {
410                 phys_iobase = ia64_get_kr(IA64_KR_IO_BASE);
411                 printk(KERN_INFO "No I/O port range found in EFI memory map, falling back "
412                        "to AR.KR0\n");
413                 printk(KERN_INFO "I/O port base = 0x%lx\n", phys_iobase);
414         }
415         ia64_iobase = (unsigned long) ioremap(phys_iobase, 0);
416
417         /* setup legacy IO port space */
418         io_space[0].mmio_base = ia64_iobase;
419         io_space[0].sparse = 1;
420         num_io_spaces = 1;
421
422 #ifdef CONFIG_SMP
423         cpu_physical_id(0) = hard_smp_processor_id();
424 #endif
425
426         cpu_init();     /* initialize the bootstrap CPU */
427
428 #ifdef CONFIG_ACPI_BOOT
429         acpi_boot_init();
430 #endif
431 #ifdef CONFIG_SERIAL_8250_HCDP
432         if (efi.hcdp) {
433                 void setup_serial_hcdp(void *);
434
435                 /* Setup the serial ports described by HCDP */
436                 setup_serial_hcdp(efi.hcdp);
437         }
438 #endif
439 #ifdef CONFIG_VT
440 # if defined(CONFIG_DUMMY_CONSOLE)
441         conswitchp = &dummy_con;
442 # endif
443 # if defined(CONFIG_VGA_CONSOLE)
444         /*
445          * Non-legacy systems may route legacy VGA MMIO range to system
446          * memory.  vga_con probes the MMIO hole, so memory looks like
447          * a VGA device to it.  The EFI memory map can tell us if it's
448          * memory so we can avoid this problem.
449          */
450         if (efi_mem_type(0xA0000) != EFI_CONVENTIONAL_MEMORY)
451                 conswitchp = &vga_con;
452 # endif
453 #endif
454
455 #ifdef CONFIG_IA64_MCA
456         /* enable IA-64 Machine Check Abort Handling */
457         ia64_mca_init();
458 #endif
459
460         platform_setup(cmdline_p);
461         paging_init();
462
463         unw_create_gate_table();
464 }
465
466 /*
467  * Display cpu info for all cpu's.
468  */
469 static int
470 show_cpuinfo (struct seq_file *m, void *v)
471 {
472 #ifdef CONFIG_SMP
473 #       define lpj      c->loops_per_jiffy
474 #       define cpunum   c->cpu
475 #else
476 #       define lpj      loops_per_jiffy
477 #       define cpunum   0
478 #endif
479         static struct {
480                 unsigned long mask;
481                 const char *feature_name;
482         } feature_bits[] = {
483                 { 1UL << 0, "branchlong" },
484                 { 1UL << 1, "spontaneous deferral"},
485                 { 1UL << 2, "16-byte atomic ops" }
486         };
487         char family[32], features[128], *cp, sep;
488         struct cpuinfo_ia64 *c = v;
489         unsigned long mask;
490         int i;
491
492         mask = c->features;
493
494         switch (c->family) {
495               case 0x07:        memcpy(family, "Itanium", 8); break;
496               case 0x1f:        memcpy(family, "Itanium 2", 10); break;
497               default:          sprintf(family, "%u", c->family); break;
498         }
499
500         /* build the feature string: */
501         memcpy(features, " standard", 10);
502         cp = features;
503         sep = 0;
504         for (i = 0; i < (int) ARRAY_SIZE(feature_bits); ++i) {
505                 if (mask & feature_bits[i].mask) {
506                         if (sep)
507                                 *cp++ = sep;
508                         sep = ',';
509                         *cp++ = ' ';
510                         strcpy(cp, feature_bits[i].feature_name);
511                         cp += strlen(feature_bits[i].feature_name);
512                         mask &= ~feature_bits[i].mask;
513                 }
514         }
515         if (mask) {
516                 /* print unknown features as a hex value: */
517                 if (sep)
518                         *cp++ = sep;
519                 sprintf(cp, " 0x%lx", mask);
520         }
521
522         seq_printf(m,
523                    "processor  : %d\n"
524                    "vendor     : %s\n"
525                    "arch       : IA-64\n"
526                    "family     : %s\n"
527                    "model      : %u\n"
528                    "revision   : %u\n"
529                    "archrev    : %u\n"
530                    "features   :%s\n"   /* don't change this---it _is_ right! */
531                    "cpu number : %lu\n"
532                    "cpu regs   : %u\n"
533                    "cpu MHz    : %lu.%06lu\n"
534                    "itc MHz    : %lu.%06lu\n"
535                    "BogoMIPS   : %lu.%02lu\n\n",
536                    cpunum, c->vendor, family, c->model, c->revision, c->archrev,
537                    features, c->ppn, c->number,
538                    c->proc_freq / 1000000, c->proc_freq % 1000000,
539                    c->itc_freq / 1000000, c->itc_freq % 1000000,
540                    lpj*HZ/500000, (lpj*HZ/5000) % 100);
541         return 0;
542 }
543
544 static void *
545 c_start (struct seq_file *m, loff_t *pos)
546 {
547 #ifdef CONFIG_SMP
548         while (*pos < NR_CPUS && !(cpu_online_map & (1UL << *pos)))
549                 ++*pos;
550 #endif
551         return *pos < NR_CPUS ? cpu_data(*pos) : NULL;
552 }
553
554 static void *
555 c_next (struct seq_file *m, void *v, loff_t *pos)
556 {
557         ++*pos;
558         return c_start(m, pos);
559 }
560
561 static void
562 c_stop (struct seq_file *m, void *v)
563 {
564 }
565
566 struct seq_operations cpuinfo_op = {
567         .start =        c_start,
568         .next =         c_next,
569         .stop =         c_stop,
570         .show =         show_cpuinfo
571 };
572
573 void
574 identify_cpu (struct cpuinfo_ia64 *c)
575 {
576         union {
577                 unsigned long bits[5];
578                 struct {
579                         /* id 0 & 1: */
580                         char vendor[16];
581
582                         /* id 2 */
583                         u64 ppn;                /* processor serial number */
584
585                         /* id 3: */
586                         unsigned number         :  8;
587                         unsigned revision       :  8;
588                         unsigned model          :  8;
589                         unsigned family         :  8;
590                         unsigned archrev        :  8;
591                         unsigned reserved       : 24;
592
593                         /* id 4: */
594                         u64 features;
595                 } field;
596         } cpuid;
597         pal_vm_info_1_u_t vm1;
598         pal_vm_info_2_u_t vm2;
599         pal_status_t status;
600         unsigned long impl_va_msb = 50, phys_addr_size = 44;    /* Itanium defaults */
601         int i;
602
603         for (i = 0; i < 5; ++i)
604                 cpuid.bits[i] = ia64_get_cpuid(i);
605
606         memcpy(c->vendor, cpuid.field.vendor, 16);
607 #ifdef CONFIG_SMP
608         c->cpu = smp_processor_id();
609 #endif
610         c->ppn = cpuid.field.ppn;
611         c->number = cpuid.field.number;
612         c->revision = cpuid.field.revision;
613         c->model = cpuid.field.model;
614         c->family = cpuid.field.family;
615         c->archrev = cpuid.field.archrev;
616         c->features = cpuid.field.features;
617
618         status = ia64_pal_vm_summary(&vm1, &vm2);
619         if (status == PAL_STATUS_SUCCESS) {
620                 impl_va_msb = vm2.pal_vm_info_2_s.impl_va_msb;
621                 phys_addr_size = vm1.pal_vm_info_1_s.phys_add_size;
622         }
623         printk(KERN_INFO "CPU %d: %lu virtual and %lu physical address bits\n",
624                smp_processor_id(), impl_va_msb + 1, phys_addr_size);
625         c->unimpl_va_mask = ~((7L<<61) | ((1L << (impl_va_msb + 1)) - 1));
626         c->unimpl_pa_mask = ~((1L<<63) | ((1L << phys_addr_size) - 1));
627 }
628
629 void
630 setup_per_cpu_areas (void)
631 {
632         /* start_kernel() requires this... */
633 }
634
635 static void
636 get_max_cacheline_size (void)
637 {
638         unsigned long line_size, max = 1;
639         u64 l, levels, unique_caches;
640         pal_cache_config_info_t cci;
641         s64 status;
642
643         status = ia64_pal_cache_summary(&levels, &unique_caches);
644         if (status != 0) {
645                 printk(KERN_ERR "%s: ia64_pal_cache_summary() failed (status=%ld)\n",
646                        __FUNCTION__, status);
647                 max = SMP_CACHE_BYTES;
648                 goto out;
649         }
650
651         for (l = 0; l < levels; ++l) {
652                 status = ia64_pal_cache_config_info(l, /* cache_type (data_or_unified)= */ 2,
653                                                     &cci);
654                 if (status != 0) {
655                         printk(KERN_ERR
656                                "%s: ia64_pal_cache_config_info(l=%lu) failed (status=%ld)\n",
657                                __FUNCTION__, l, status);
658                         max = SMP_CACHE_BYTES;
659                 }
660                 line_size = 1 << cci.pcci_line_size;
661                 if (line_size > max)
662                         max = line_size;
663         }
664   out:
665         if (max > ia64_max_cacheline_size)
666                 ia64_max_cacheline_size = max;
667 }
668
669 /*
670  * cpu_init() initializes state that is per-CPU.  This function acts
671  * as a 'CPU state barrier', nothing should get across.
672  */
673 void
674 cpu_init (void)
675 {
676         extern char __per_cpu_start[], __phys_per_cpu_start[];
677         extern void __init ia64_mmu_init (void *);
678         unsigned long num_phys_stacked;
679         pal_vm_info_2_u_t vmi;
680         unsigned int max_ctx;
681         struct cpuinfo_ia64 *cpu_info;
682         void *cpu_data;
683
684 #ifdef CONFIG_SMP
685         extern char __per_cpu_end[];
686         int cpu;
687
688         /*
689          * get_free_pages() cannot be used before cpu_init() done.  BSP allocates
690          * "NR_CPUS" pages for all CPUs to avoid that AP calls get_zeroed_page().
691          */
692         if (smp_processor_id() == 0) {
693                 cpu_data = __alloc_bootmem(PERCPU_PAGE_SIZE * NR_CPUS, PERCPU_PAGE_SIZE,
694                                            __pa(MAX_DMA_ADDRESS));
695                 for (cpu = 0; cpu < NR_CPUS; cpu++) {
696                         memcpy(cpu_data, __phys_per_cpu_start, __per_cpu_end - __per_cpu_start);
697                         __per_cpu_offset[cpu] = (char *) cpu_data - __per_cpu_start;
698                         cpu_data += PERCPU_PAGE_SIZE;
699                 }
700         }
701         cpu_data = __per_cpu_start + __per_cpu_offset[smp_processor_id()];
702 #else /* !CONFIG_SMP */
703         cpu_data = __phys_per_cpu_start;
704 #endif /* !CONFIG_SMP */
705
706         cpu_info = cpu_data + ((char *) &__get_cpu_var(cpu_info) - __per_cpu_start);
707 #ifdef CONFIG_NUMA
708         cpu_info->node_data = get_node_data_ptr();
709 #endif
710
711         get_max_cacheline_size();
712
713         /*
714          * We can't pass "local_cpu_data" to identify_cpu() because we haven't called
715          * ia64_mmu_init() yet.  And we can't call ia64_mmu_init() first because it
716          * depends on the data returned by identify_cpu().  We break the dependency by
717          * accessing cpu_data() the old way, through identity mapped space.
718          */
719         identify_cpu(cpu_info);
720
721 #ifdef CONFIG_MCKINLEY
722         {
723 #               define FEATURE_SET 16
724                 struct ia64_pal_retval iprv;
725
726                 if (cpu_info->family == 0x1f) {
727                         PAL_CALL_PHYS(iprv, PAL_PROC_GET_FEATURES, 0, FEATURE_SET, 0);
728                         if ((iprv.status == 0) && (iprv.v0 & 0x80) && (iprv.v2 & 0x80))
729                                 PAL_CALL_PHYS(iprv, PAL_PROC_SET_FEATURES,
730                                               (iprv.v1 | 0x80), FEATURE_SET, 0);
731                 }
732         }
733 #endif
734
735         /* Clear the stack memory reserved for pt_regs: */
736         memset(ia64_task_regs(current), 0, sizeof(struct pt_regs));
737
738         /*
739          * Initialize default control register to defer all speculative faults.  The
740          * kernel MUST NOT depend on a particular setting of these bits (in other words,
741          * the kernel must have recovery code for all speculative accesses).  Turn on
742          * dcr.lc as per recommendation by the architecture team.  Most IA-32 apps
743          * shouldn't be affected by this (moral: keep your ia32 locks aligned and you'll
744          * be fine).
745          */
746         ia64_set_dcr(  IA64_DCR_DP | IA64_DCR_DK | IA64_DCR_DX | IA64_DCR_DR
747                      | IA64_DCR_DA | IA64_DCR_DD | IA64_DCR_LC);
748 #ifndef CONFIG_SMP
749         ia64_set_fpu_owner(0);
750 #endif
751
752         atomic_inc(&init_mm.mm_count);
753         current->active_mm = &init_mm;
754         if (current->mm)
755                 BUG();
756
757         ia64_mmu_init(cpu_data);
758
759 #ifdef CONFIG_IA32_SUPPORT
760         /* initialize global ia32 state - CR0 and CR4 */
761         asm volatile ("mov ar.cflg = %0" :: "r" (((ulong) IA32_CR4 << 32) | IA32_CR0));
762 #endif
763
764         /* disable all local interrupt sources: */
765         ia64_set_itv(1 << 16);
766         ia64_set_lrr0(1 << 16);
767         ia64_set_lrr1(1 << 16);
768         ia64_set_pmv(1 << 16);
769         ia64_set_cmcv(1 << 16);
770
771         /* clear TPR & XTP to enable all interrupt classes: */
772         ia64_set_tpr(0);
773 #ifdef CONFIG_SMP
774         normal_xtp();
775 #endif
776
777         /* set ia64_ctx.max_rid to the maximum RID that is supported by all CPUs: */
778         if (ia64_pal_vm_summary(NULL, &vmi) == 0)
779                 max_ctx = (1U << (vmi.pal_vm_info_2_s.rid_size - 3)) - 1;
780         else {
781                 printk(KERN_WARNING "cpu_init: PAL VM summary failed, assuming 18 RID bits\n");
782                 max_ctx = (1U << 15) - 1;       /* use architected minimum */
783         }
784         while (max_ctx < ia64_ctx.max_ctx) {
785                 unsigned int old = ia64_ctx.max_ctx;
786                 if (cmpxchg(&ia64_ctx.max_ctx, old, max_ctx) == old)
787                         break;
788         }
789
790         if (ia64_pal_rse_info(&num_phys_stacked, 0) != 0) {
791                 printk(KERN_WARNING "cpu_init: PAL RSE info failed; assuming 96 physical "
792                        "stacked regs\n");
793                 num_phys_stacked = 96;
794         }
795         /* size of physical stacked register partition plus 8 bytes: */
796         __get_cpu_var(ia64_phys_stacked_size_p8) = num_phys_stacked*8 + 8;
797         platform_cpu_init();
798 }
799
800 void
801 check_bugs (void)
802 {
803         extern int __start___mckinley_e9_bundles[];
804         extern int __end___mckinley_e9_bundles[];
805         u64 *bundle;
806         int *wp;
807
808         if (local_cpu_data->family == 0x1f && local_cpu_data->model == 0)
809                 printk(KERN_INFO "check_bugs: leaving McKinley Errata 9 workaround enabled\n");
810         else {
811                 printk(KERN_INFO "check_bugs: McKinley Errata 9 workaround not needed; "
812                        "disabling it\n");
813                 for (wp = __start___mckinley_e9_bundles; wp < __end___mckinley_e9_bundles; ++wp) {
814                         bundle = (u64 *) ((char *) wp + *wp);
815                         /* install a bundle of NOPs: */
816                         bundle[0] = 0x0000000100000000;
817                         bundle[1] = 0x0004000000000200;
818                         ia64_fc(bundle);
819                 }
820                 ia64_insn_group_barrier();
821                 ia64_sync_i();
822                 ia64_insn_group_barrier();
823                 ia64_srlz_i();
824                 ia64_insn_group_barrier();
825         }
826 }