Add ia64 patch.
[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         strncpy(saved_command_line, *cmdline_p, sizeof(saved_command_line));
360         saved_command_line[COMMAND_LINE_SIZE-1] = '\0';         /* for safety */
361
362         efi_init();
363
364 #ifdef CONFIG_ACPI_BOOT
365         /* Initialize the ACPI boot-time table parser */
366         acpi_table_init();
367 # ifdef CONFIG_ACPI_NUMA
368         acpi_numa_init();
369 # endif
370 #else
371 # ifdef CONFIG_SMP
372         smp_build_cpu_map();    /* happens, e.g., with the Ski simulator */
373 # endif
374 #endif /* CONFIG_APCI_BOOT */
375
376         find_memory();
377
378 #if 0
379         /* XXX fix me */
380         init_mm.start_code = (unsigned long) &_stext;
381         init_mm.end_code = (unsigned long) &_etext;
382         init_mm.end_data = (unsigned long) &_edata;
383         init_mm.brk = (unsigned long) &_end;
384
385         code_resource.start = virt_to_bus(&_text);
386         code_resource.end = virt_to_bus(&_etext) - 1;
387         data_resource.start = virt_to_bus(&_etext);
388         data_resource.end = virt_to_bus(&_edata) - 1;
389 #endif
390
391         /* process SAL system table: */
392         ia64_sal_init(efi.sal_systab);
393
394 #ifdef CONFIG_IA64_GENERIC
395         machvec_init(acpi_get_sysname());
396 #endif
397
398         /*
399          *  Set `iobase' to the appropriate address in region 6 (uncached access range).
400          *
401          *  The EFI memory map is the "preferred" location to get the I/O port space base,
402          *  rather the relying on AR.KR0. This should become more clear in future SAL
403          *  specs. We'll fall back to getting it out of AR.KR0 if no appropriate entry is
404          *  found in the memory map.
405          */
406         phys_iobase = efi_get_iobase();
407         if (phys_iobase)
408                 /* set AR.KR0 since this is all we use it for anyway */
409                 ia64_set_kr(IA64_KR_IO_BASE, phys_iobase);
410         else {
411                 phys_iobase = ia64_get_kr(IA64_KR_IO_BASE);
412                 printk(KERN_INFO "No I/O port range found in EFI memory map, falling back "
413                        "to AR.KR0\n");
414                 printk(KERN_INFO "I/O port base = 0x%lx\n", phys_iobase);
415         }
416         ia64_iobase = (unsigned long) ioremap(phys_iobase, 0);
417
418         /* setup legacy IO port space */
419         io_space[0].mmio_base = ia64_iobase;
420         io_space[0].sparse = 1;
421         num_io_spaces = 1;
422
423 #ifdef CONFIG_SMP
424         cpu_physical_id(0) = hard_smp_processor_id();
425 #endif
426
427         cpu_init();     /* initialize the bootstrap CPU */
428
429 #ifdef CONFIG_ACPI_BOOT
430         acpi_boot_init();
431 #endif
432 #ifdef CONFIG_SERIAL_8250_HCDP
433         if (efi.hcdp) {
434                 void setup_serial_hcdp(void *);
435
436                 /* Setup the serial ports described by HCDP */
437                 setup_serial_hcdp(efi.hcdp);
438         }
439 #endif
440 #ifdef CONFIG_VT
441 # if defined(CONFIG_DUMMY_CONSOLE)
442         conswitchp = &dummy_con;
443 # endif
444 # if defined(CONFIG_VGA_CONSOLE)
445         /*
446          * Non-legacy systems may route legacy VGA MMIO range to system
447          * memory.  vga_con probes the MMIO hole, so memory looks like
448          * a VGA device to it.  The EFI memory map can tell us if it's
449          * memory so we can avoid this problem.
450          */
451         if (efi_mem_type(0xA0000) != EFI_CONVENTIONAL_MEMORY)
452                 conswitchp = &vga_con;
453 # endif
454 #endif
455
456 #ifdef CONFIG_IA64_MCA
457         /* enable IA-64 Machine Check Abort Handling */
458         ia64_mca_init();
459 #endif
460
461         platform_setup(cmdline_p);
462         paging_init();
463
464         unw_create_gate_table();
465 }
466
467 /*
468  * Display cpu info for all cpu's.
469  */
470 static int
471 show_cpuinfo (struct seq_file *m, void *v)
472 {
473 #ifdef CONFIG_SMP
474 #       define lpj      c->loops_per_jiffy
475 #       define cpunum   c->cpu
476 #else
477 #       define lpj      loops_per_jiffy
478 #       define cpunum   0
479 #endif
480         static struct {
481                 unsigned long mask;
482                 const char *feature_name;
483         } feature_bits[] = {
484                 { 1UL << 0, "branchlong" },
485                 { 1UL << 1, "spontaneous deferral"},
486                 { 1UL << 2, "16-byte atomic ops" }
487         };
488         char family[32], features[128], *cp, sep;
489         struct cpuinfo_ia64 *c = v;
490         unsigned long mask;
491         int i;
492
493         mask = c->features;
494
495         switch (c->family) {
496               case 0x07:        memcpy(family, "Itanium", 8); break;
497               case 0x1f:        memcpy(family, "Itanium 2", 10); break;
498               default:          sprintf(family, "%u", c->family); break;
499         }
500
501         /* build the feature string: */
502         memcpy(features, " standard", 10);
503         cp = features;
504         sep = 0;
505         for (i = 0; i < (int) ARRAY_SIZE(feature_bits); ++i) {
506                 if (mask & feature_bits[i].mask) {
507                         if (sep)
508                                 *cp++ = sep;
509                         sep = ',';
510                         *cp++ = ' ';
511                         strcpy(cp, feature_bits[i].feature_name);
512                         cp += strlen(feature_bits[i].feature_name);
513                         mask &= ~feature_bits[i].mask;
514                 }
515         }
516         if (mask) {
517                 /* print unknown features as a hex value: */
518                 if (sep)
519                         *cp++ = sep;
520                 sprintf(cp, " 0x%lx", mask);
521         }
522
523         seq_printf(m,
524                    "processor  : %d\n"
525                    "vendor     : %s\n"
526                    "arch       : IA-64\n"
527                    "family     : %s\n"
528                    "model      : %u\n"
529                    "revision   : %u\n"
530                    "archrev    : %u\n"
531                    "features   :%s\n"   /* don't change this---it _is_ right! */
532                    "cpu number : %lu\n"
533                    "cpu regs   : %u\n"
534                    "cpu MHz    : %lu.%06lu\n"
535                    "itc MHz    : %lu.%06lu\n"
536                    "BogoMIPS   : %lu.%02lu\n\n",
537                    cpunum, c->vendor, family, c->model, c->revision, c->archrev,
538                    features, c->ppn, c->number,
539                    c->proc_freq / 1000000, c->proc_freq % 1000000,
540                    c->itc_freq / 1000000, c->itc_freq % 1000000,
541                    lpj*HZ/500000, (lpj*HZ/5000) % 100);
542         return 0;
543 }
544
545 static void *
546 c_start (struct seq_file *m, loff_t *pos)
547 {
548 #ifdef CONFIG_SMP
549         while (*pos < NR_CPUS && !(cpu_online_map & (1UL << *pos)))
550                 ++*pos;
551 #endif
552         return *pos < NR_CPUS ? cpu_data(*pos) : NULL;
553 }
554
555 static void *
556 c_next (struct seq_file *m, void *v, loff_t *pos)
557 {
558         ++*pos;
559         return c_start(m, pos);
560 }
561
562 static void
563 c_stop (struct seq_file *m, void *v)
564 {
565 }
566
567 struct seq_operations cpuinfo_op = {
568         .start =        c_start,
569         .next =         c_next,
570         .stop =         c_stop,
571         .show =         show_cpuinfo
572 };
573
574 void
575 identify_cpu (struct cpuinfo_ia64 *c)
576 {
577         union {
578                 unsigned long bits[5];
579                 struct {
580                         /* id 0 & 1: */
581                         char vendor[16];
582
583                         /* id 2 */
584                         u64 ppn;                /* processor serial number */
585
586                         /* id 3: */
587                         unsigned number         :  8;
588                         unsigned revision       :  8;
589                         unsigned model          :  8;
590                         unsigned family         :  8;
591                         unsigned archrev        :  8;
592                         unsigned reserved       : 24;
593
594                         /* id 4: */
595                         u64 features;
596                 } field;
597         } cpuid;
598         pal_vm_info_1_u_t vm1;
599         pal_vm_info_2_u_t vm2;
600         pal_status_t status;
601         unsigned long impl_va_msb = 50, phys_addr_size = 44;    /* Itanium defaults */
602         int i;
603
604         for (i = 0; i < 5; ++i)
605                 cpuid.bits[i] = ia64_get_cpuid(i);
606
607         memcpy(c->vendor, cpuid.field.vendor, 16);
608 #ifdef CONFIG_SMP
609         c->cpu = smp_processor_id();
610 #endif
611         c->ppn = cpuid.field.ppn;
612         c->number = cpuid.field.number;
613         c->revision = cpuid.field.revision;
614         c->model = cpuid.field.model;
615         c->family = cpuid.field.family;
616         c->archrev = cpuid.field.archrev;
617         c->features = cpuid.field.features;
618
619         status = ia64_pal_vm_summary(&vm1, &vm2);
620         if (status == PAL_STATUS_SUCCESS) {
621                 impl_va_msb = vm2.pal_vm_info_2_s.impl_va_msb;
622                 phys_addr_size = vm1.pal_vm_info_1_s.phys_add_size;
623         }
624         printk(KERN_INFO "CPU %d: %lu virtual and %lu physical address bits\n",
625                smp_processor_id(), impl_va_msb + 1, phys_addr_size);
626         c->unimpl_va_mask = ~((7L<<61) | ((1L << (impl_va_msb + 1)) - 1));
627         c->unimpl_pa_mask = ~((1L<<63) | ((1L << phys_addr_size) - 1));
628 }
629
630 void
631 setup_per_cpu_areas (void)
632 {
633         /* start_kernel() requires this... */
634 }
635
636 static void
637 get_max_cacheline_size (void)
638 {
639         unsigned long line_size, max = 1;
640         u64 l, levels, unique_caches;
641         pal_cache_config_info_t cci;
642         s64 status;
643
644         status = ia64_pal_cache_summary(&levels, &unique_caches);
645         if (status != 0) {
646                 printk(KERN_ERR "%s: ia64_pal_cache_summary() failed (status=%ld)\n",
647                        __FUNCTION__, status);
648                 max = SMP_CACHE_BYTES;
649                 goto out;
650         }
651
652         for (l = 0; l < levels; ++l) {
653                 status = ia64_pal_cache_config_info(l, /* cache_type (data_or_unified)= */ 2,
654                                                     &cci);
655                 if (status != 0) {
656                         printk(KERN_ERR
657                                "%s: ia64_pal_cache_config_info(l=%lu) failed (status=%ld)\n",
658                                __FUNCTION__, l, status);
659                         max = SMP_CACHE_BYTES;
660                 }
661                 line_size = 1 << cci.pcci_line_size;
662                 if (line_size > max)
663                         max = line_size;
664         }
665   out:
666         if (max > ia64_max_cacheline_size)
667                 ia64_max_cacheline_size = max;
668 }
669
670 /*
671  * cpu_init() initializes state that is per-CPU.  This function acts
672  * as a 'CPU state barrier', nothing should get across.
673  */
674 void
675 cpu_init (void)
676 {
677         extern char __per_cpu_start[], __phys_per_cpu_start[];
678         extern void __init ia64_mmu_init (void *);
679         unsigned long num_phys_stacked;
680         pal_vm_info_2_u_t vmi;
681         unsigned int max_ctx;
682         struct cpuinfo_ia64 *cpu_info;
683         void *cpu_data;
684
685 #ifdef CONFIG_SMP
686         extern char __per_cpu_end[];
687         int cpu;
688
689         /*
690          * get_free_pages() cannot be used before cpu_init() done.  BSP allocates
691          * "NR_CPUS" pages for all CPUs to avoid that AP calls get_zeroed_page().
692          */
693         if (smp_processor_id() == 0) {
694                 cpu_data = __alloc_bootmem(PERCPU_PAGE_SIZE * NR_CPUS, PERCPU_PAGE_SIZE,
695                                            __pa(MAX_DMA_ADDRESS));
696                 for (cpu = 0; cpu < NR_CPUS; cpu++) {
697                         memcpy(cpu_data, __phys_per_cpu_start, __per_cpu_end - __per_cpu_start);
698                         __per_cpu_offset[cpu] = (char *) cpu_data - __per_cpu_start;
699                         cpu_data += PERCPU_PAGE_SIZE;
700                 }
701         }
702         cpu_data = __per_cpu_start + __per_cpu_offset[smp_processor_id()];
703 #else /* !CONFIG_SMP */
704         cpu_data = __phys_per_cpu_start;
705 #endif /* !CONFIG_SMP */
706
707         cpu_info = cpu_data + ((char *) &__get_cpu_var(cpu_info) - __per_cpu_start);
708 #ifdef CONFIG_NUMA
709         cpu_info->node_data = get_node_data_ptr();
710 #endif
711
712         get_max_cacheline_size();
713
714         /*
715          * We can't pass "local_cpu_data" to identify_cpu() because we haven't called
716          * ia64_mmu_init() yet.  And we can't call ia64_mmu_init() first because it
717          * depends on the data returned by identify_cpu().  We break the dependency by
718          * accessing cpu_data() the old way, through identity mapped space.
719          */
720         identify_cpu(cpu_info);
721
722 #ifdef CONFIG_MCKINLEY
723         {
724 #               define FEATURE_SET 16
725                 struct ia64_pal_retval iprv;
726
727                 if (cpu_info->family == 0x1f) {
728                         PAL_CALL_PHYS(iprv, PAL_PROC_GET_FEATURES, 0, FEATURE_SET, 0);
729                         if ((iprv.status == 0) && (iprv.v0 & 0x80) && (iprv.v2 & 0x80))
730                                 PAL_CALL_PHYS(iprv, PAL_PROC_SET_FEATURES,
731                                               (iprv.v1 | 0x80), FEATURE_SET, 0);
732                 }
733         }
734 #endif
735
736         /* Clear the stack memory reserved for pt_regs: */
737         memset(ia64_task_regs(current), 0, sizeof(struct pt_regs));
738
739         /*
740          * Initialize default control register to defer all speculative faults.  The
741          * kernel MUST NOT depend on a particular setting of these bits (in other words,
742          * the kernel must have recovery code for all speculative accesses).  Turn on
743          * dcr.lc as per recommendation by the architecture team.  Most IA-32 apps
744          * shouldn't be affected by this (moral: keep your ia32 locks aligned and you'll
745          * be fine).
746          */
747         ia64_set_dcr(  IA64_DCR_DP | IA64_DCR_DK | IA64_DCR_DX | IA64_DCR_DR
748                      | IA64_DCR_DA | IA64_DCR_DD | IA64_DCR_LC);
749 #ifndef CONFIG_SMP
750         ia64_set_fpu_owner(0);
751 #endif
752
753         atomic_inc(&init_mm.mm_count);
754         current->active_mm = &init_mm;
755         if (current->mm)
756                 BUG();
757
758         ia64_mmu_init(cpu_data);
759
760 #ifdef CONFIG_IA32_SUPPORT
761         /* initialize global ia32 state - CR0 and CR4 */
762         asm volatile ("mov ar.cflg = %0" :: "r" (((ulong) IA32_CR4 << 32) | IA32_CR0));
763 #endif
764
765         /* disable all local interrupt sources: */
766         ia64_set_itv(1 << 16);
767         ia64_set_lrr0(1 << 16);
768         ia64_set_lrr1(1 << 16);
769         ia64_set_pmv(1 << 16);
770         ia64_set_cmcv(1 << 16);
771
772         /* clear TPR & XTP to enable all interrupt classes: */
773         ia64_set_tpr(0);
774 #ifdef CONFIG_SMP
775         normal_xtp();
776 #endif
777
778         /* set ia64_ctx.max_rid to the maximum RID that is supported by all CPUs: */
779         if (ia64_pal_vm_summary(NULL, &vmi) == 0)
780                 max_ctx = (1U << (vmi.pal_vm_info_2_s.rid_size - 3)) - 1;
781         else {
782                 printk(KERN_WARNING "cpu_init: PAL VM summary failed, assuming 18 RID bits\n");
783                 max_ctx = (1U << 15) - 1;       /* use architected minimum */
784         }
785         while (max_ctx < ia64_ctx.max_ctx) {
786                 unsigned int old = ia64_ctx.max_ctx;
787                 if (cmpxchg(&ia64_ctx.max_ctx, old, max_ctx) == old)
788                         break;
789         }
790
791         if (ia64_pal_rse_info(&num_phys_stacked, 0) != 0) {
792                 printk(KERN_WARNING "cpu_init: PAL RSE info failed; assuming 96 physical "
793                        "stacked regs\n");
794                 num_phys_stacked = 96;
795         }
796         /* size of physical stacked register partition plus 8 bytes: */
797         __get_cpu_var(ia64_phys_stacked_size_p8) = num_phys_stacked*8 + 8;
798         platform_cpu_init();
799 }
800
801 void
802 check_bugs (void)
803 {
804         extern int __start___mckinley_e9_bundles[];
805         extern int __end___mckinley_e9_bundles[];
806         u64 *bundle;
807         int *wp;
808
809         if (local_cpu_data->family == 0x1f && local_cpu_data->model == 0)
810                 printk(KERN_INFO "check_bugs: leaving McKinley Errata 9 workaround enabled\n");
811         else {
812                 printk(KERN_INFO "check_bugs: McKinley Errata 9 workaround not needed; "
813                        "disabling it\n");
814                 for (wp = __start___mckinley_e9_bundles; wp < __end___mckinley_e9_bundles; ++wp) {
815                         bundle = (u64 *) ((char *) wp + *wp);
816                         /* install a bundle of NOPs: */
817                         bundle[0] = 0x0000000100000000;
818                         bundle[1] = 0x0004000000000200;
819                         ia64_fc(bundle);
820                 }
821                 ia64_insn_group_barrier();
822                 ia64_sync_i();
823                 ia64_insn_group_barrier();
824                 ia64_srlz_i();
825                 ia64_insn_group_barrier();
826         }
827 }