2 * Architecture-specific setup.
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>
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.
19 #include <linux/config.h>
20 #include <linux/init.h>
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>
38 #include <asm/pgtable.h>
39 #include <asm/machvec.h>
40 #include <asm/processor.h>
42 #include <asm/system.h>
46 #if defined(CONFIG_SMP) && (IA64_CPU_SIZE > PAGE_SIZE)
47 # error "struct cpuinfo_ia64 too big!"
53 unsigned long __per_cpu_offset[NR_CPUS];
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;
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;
67 unsigned char aux_device_present = 0xaa; /* XXX remove this when legacy I/O is gone */
69 #define COMMAND_LINE_SIZE 512
71 char saved_command_line[COMMAND_LINE_SIZE]; /* used in proc filesystem */
74 * Entries defined so far:
75 * - boot param structure itself
78 * - command line string
79 * - kernel code & data
81 * More could be added if necessary
83 #define IA64_MAX_RSVD_REGIONS 5
86 unsigned long start; /* virtual address of beginning of element */
87 unsigned long end; /* virtual address of end of element + 1 */
91 * We use a special marker for the end of memory and it uses the extra (+1) slot
93 static struct rsvd_region rsvd_region[IA64_MAX_RSVD_REGIONS + 1];
94 static int num_rsvd_regions;
96 #define IGNORE_PFN0 1 /* XXX fix me: ignore pfn 0 until TLB miss handler is updated... */
98 #ifndef CONFIG_DISCONTIGMEM
100 static unsigned long bootmap_start; /* physical address where the bootmem map is located */
103 find_max_pfn (unsigned long start, unsigned long end, void *arg)
105 unsigned long *max_pfn = arg, pfn;
107 pfn = (PAGE_ALIGN(end - 1) - PAGE_OFFSET) >> PAGE_SHIFT;
113 #else /* CONFIG_DISCONTIGMEM */
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.
120 * Take this opportunity to round the start address up and the end address
121 * down to page boundaries.
124 call_pernode_memory (unsigned long start, unsigned long end, void *arg)
126 unsigned long rs, re;
127 void (*func)(unsigned long, unsigned long, int, int);
130 start = PAGE_ALIGN(start);
139 * This machine doesn't have SRAT, so call func with
143 (*func)(start, end - start, 0, 0);
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);
152 (*func)(rs, re-rs, node_memblk[i].nid,
153 node_memblk[i].bank);
157 #endif /* CONFIG_DISCONTIGMEM */
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.
166 filter_rsvd_memory (unsigned long start, unsigned long end, void *arg)
168 unsigned long range_start, range_end, prev_start;
169 void (*func)(unsigned long, unsigned long);
173 if (start == PAGE_OFFSET) {
174 printk(KERN_WARNING "warning: skipping physical page 0\n");
176 if (start >= end) return 0;
180 * lowest possible address(walker uses virtual)
182 prev_start = PAGE_OFFSET;
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);
189 if (range_start < range_end)
190 #ifdef CONFIG_DISCONTIGMEM
191 call_pernode_memory(__pa(range_start), __pa(range_end), func);
193 (*func)(__pa(range_start), range_end - range_start);
196 /* nothing more available in this segment */
197 if (range_end == end) return 0;
199 prev_start = rsvd_region[i].end;
201 /* end of memory marker allows full processing inside loop body */
206 #ifndef CONFIG_DISCONTIGMEM
208 * Find a place to put the bootmap and return its starting address in bootmap_start.
209 * This address must be page-aligned.
212 find_bootmap_location (unsigned long start, unsigned long end, void *arg)
214 unsigned long needed = *(unsigned long *)arg;
215 unsigned long range_start, range_end, free_start;
219 if (start == PAGE_OFFSET) {
221 if (start >= end) return 0;
225 free_start = PAGE_OFFSET;
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);
231 if (range_end <= range_start) continue; /* skip over empty range */
233 if (range_end - range_start >= needed) {
234 bootmap_start = __pa(range_start);
238 /* nothing more available in this segment */
239 if (range_end == end) return 0;
241 free_start = PAGE_ALIGN(rsvd_region[i].end);
245 #endif /* !CONFIG_DISCONTIGMEM */
248 sort_regions (struct rsvd_region *rsvd_region, int max)
252 /* simple bubble sorting */
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;
268 # define KERNEL_END ((unsigned long) &_end)
269 unsigned long bootmap_size;
270 unsigned long max_pfn;
274 * none of the entries in this table overlap
276 rsvd_region[n].start = (unsigned long) ia64_boot_param;
277 rsvd_region[n].end = rsvd_region[n].start + sizeof(*ia64_boot_param);
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;
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);
289 rsvd_region[n].start = KERNEL_START;
290 rsvd_region[n].end = KERNEL_END;
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;
301 /* end of memory marker */
302 rsvd_region[n].start = ~0UL;
303 rsvd_region[n].end = ~0UL;
306 num_rsvd_regions = n;
308 sort_regions(rsvd_region, num_rsvd_regions);
310 #ifdef CONFIG_DISCONTIGMEM
312 extern void discontig_mem_init (void);
314 bootmap_size = max_pfn = 0; /* stop gcc warnings */
315 discontig_mem_init();
317 #else /* !CONFIG_DISCONTIGMEM */
319 /* first find highest page frame number */
321 efi_memmap_walk(find_max_pfn, &max_pfn);
323 /* how many bytes to cover all the pages */
324 bootmap_size = bootmem_bootmap_pages(max_pfn) << PAGE_SHIFT;
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);
332 bootmap_size = init_bootmem(bootmap_start >> PAGE_SHIFT, max_pfn);
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 */
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;
344 printk(KERN_INFO "Initial ramdisk at: 0x%lx (%lu bytes)\n",
345 initrd_start, ia64_boot_param->initrd_size);
351 setup_arch (char **cmdline_p)
353 extern unsigned long ia64_iobase;
354 unsigned long phys_iobase;
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 */
364 #ifdef CONFIG_ACPI_BOOT
365 /* Initialize the ACPI boot-time table parser */
367 # ifdef CONFIG_ACPI_NUMA
372 smp_build_cpu_map(); /* happens, e.g., with the Ski simulator */
374 #endif /* CONFIG_APCI_BOOT */
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;
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;
391 /* process SAL system table: */
392 ia64_sal_init(efi.sal_systab);
394 #ifdef CONFIG_IA64_GENERIC
395 machvec_init(acpi_get_sysname());
399 * Set `iobase' to the appropriate address in region 6 (uncached access range).
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.
406 phys_iobase = efi_get_iobase();
408 /* set AR.KR0 since this is all we use it for anyway */
409 ia64_set_kr(IA64_KR_IO_BASE, phys_iobase);
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 "
414 printk(KERN_INFO "I/O port base = 0x%lx\n", phys_iobase);
416 ia64_iobase = (unsigned long) ioremap(phys_iobase, 0);
418 /* setup legacy IO port space */
419 io_space[0].mmio_base = ia64_iobase;
420 io_space[0].sparse = 1;
424 cpu_physical_id(0) = hard_smp_processor_id();
427 cpu_init(); /* initialize the bootstrap CPU */
429 #ifdef CONFIG_ACPI_BOOT
432 #ifdef CONFIG_SERIAL_8250_HCDP
434 void setup_serial_hcdp(void *);
436 /* Setup the serial ports described by HCDP */
437 setup_serial_hcdp(efi.hcdp);
441 # if defined(CONFIG_DUMMY_CONSOLE)
442 conswitchp = &dummy_con;
444 # if defined(CONFIG_VGA_CONSOLE)
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.
451 if (efi_mem_type(0xA0000) != EFI_CONVENTIONAL_MEMORY)
452 conswitchp = &vga_con;
456 #ifdef CONFIG_IA64_MCA
457 /* enable IA-64 Machine Check Abort Handling */
461 platform_setup(cmdline_p);
464 unw_create_gate_table();
468 * Display cpu info for all cpu's.
471 show_cpuinfo (struct seq_file *m, void *v)
474 # define lpj c->loops_per_jiffy
475 # define cpunum c->cpu
477 # define lpj loops_per_jiffy
482 const char *feature_name;
484 { 1UL << 0, "branchlong" },
485 { 1UL << 1, "spontaneous deferral"},
486 { 1UL << 2, "16-byte atomic ops" }
488 char family[32], features[128], *cp, sep;
489 struct cpuinfo_ia64 *c = v;
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;
501 /* build the feature string: */
502 memcpy(features, " standard", 10);
505 for (i = 0; i < (int) ARRAY_SIZE(feature_bits); ++i) {
506 if (mask & feature_bits[i].mask) {
511 strcpy(cp, feature_bits[i].feature_name);
512 cp += strlen(feature_bits[i].feature_name);
513 mask &= ~feature_bits[i].mask;
517 /* print unknown features as a hex value: */
520 sprintf(cp, " 0x%lx", mask);
531 "features :%s\n" /* don't change this---it _is_ right! */
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);
546 c_start (struct seq_file *m, loff_t *pos)
549 while (*pos < NR_CPUS && !(cpu_online_map & (1UL << *pos)))
552 return *pos < NR_CPUS ? cpu_data(*pos) : NULL;
556 c_next (struct seq_file *m, void *v, loff_t *pos)
559 return c_start(m, pos);
563 c_stop (struct seq_file *m, void *v)
567 struct seq_operations cpuinfo_op = {
575 identify_cpu (struct cpuinfo_ia64 *c)
578 unsigned long bits[5];
584 u64 ppn; /* processor serial number */
588 unsigned revision : 8;
591 unsigned archrev : 8;
592 unsigned reserved : 24;
598 pal_vm_info_1_u_t vm1;
599 pal_vm_info_2_u_t vm2;
601 unsigned long impl_va_msb = 50, phys_addr_size = 44; /* Itanium defaults */
604 for (i = 0; i < 5; ++i)
605 cpuid.bits[i] = ia64_get_cpuid(i);
607 memcpy(c->vendor, cpuid.field.vendor, 16);
609 c->cpu = smp_processor_id();
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;
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;
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));
631 setup_per_cpu_areas (void)
633 /* start_kernel() requires this... */
637 get_max_cacheline_size (void)
639 unsigned long line_size, max = 1;
640 u64 l, levels, unique_caches;
641 pal_cache_config_info_t cci;
644 status = ia64_pal_cache_summary(&levels, &unique_caches);
646 printk(KERN_ERR "%s: ia64_pal_cache_summary() failed (status=%ld)\n",
647 __FUNCTION__, status);
648 max = SMP_CACHE_BYTES;
652 for (l = 0; l < levels; ++l) {
653 status = ia64_pal_cache_config_info(l, /* cache_type (data_or_unified)= */ 2,
657 "%s: ia64_pal_cache_config_info(l=%lu) failed (status=%ld)\n",
658 __FUNCTION__, l, status);
659 max = SMP_CACHE_BYTES;
661 line_size = 1 << cci.pcci_line_size;
666 if (max > ia64_max_cacheline_size)
667 ia64_max_cacheline_size = max;
671 * cpu_init() initializes state that is per-CPU. This function acts
672 * as a 'CPU state barrier', nothing should get across.
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;
686 extern char __per_cpu_end[];
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().
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;
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 */
707 cpu_info = cpu_data + ((char *) &__get_cpu_var(cpu_info) - __per_cpu_start);
709 cpu_info->node_data = get_node_data_ptr();
712 get_max_cacheline_size();
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.
720 identify_cpu(cpu_info);
722 #ifdef CONFIG_MCKINLEY
724 # define FEATURE_SET 16
725 struct ia64_pal_retval iprv;
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);
736 /* Clear the stack memory reserved for pt_regs: */
737 memset(ia64_task_regs(current), 0, sizeof(struct pt_regs));
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
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);
750 ia64_set_fpu_owner(0);
753 atomic_inc(&init_mm.mm_count);
754 current->active_mm = &init_mm;
758 ia64_mmu_init(cpu_data);
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));
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);
772 /* clear TPR & XTP to enable all interrupt classes: */
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;
782 printk(KERN_WARNING "cpu_init: PAL VM summary failed, assuming 18 RID bits\n");
783 max_ctx = (1U << 15) - 1; /* use architected minimum */
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)
791 if (ia64_pal_rse_info(&num_phys_stacked, 0) != 0) {
792 printk(KERN_WARNING "cpu_init: PAL RSE info failed; assuming 96 physical "
794 num_phys_stacked = 96;
796 /* size of physical stacked register partition plus 8 bytes: */
797 __get_cpu_var(ia64_phys_stacked_size_p8) = num_phys_stacked*8 + 8;
804 extern int __start___mckinley_e9_bundles[];
805 extern int __end___mckinley_e9_bundles[];
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");
812 printk(KERN_INFO "check_bugs: McKinley Errata 9 workaround not needed; "
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;
821 ia64_insn_group_barrier();
823 ia64_insn_group_barrier();
825 ia64_insn_group_barrier();