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 strlcpy(saved_command_line, *cmdline_p, sizeof(saved_command_line));
363 #ifdef CONFIG_ACPI_BOOT
364 /* Initialize the ACPI boot-time table parser */
366 # ifdef CONFIG_ACPI_NUMA
371 smp_build_cpu_map(); /* happens, e.g., with the Ski simulator */
373 #endif /* CONFIG_APCI_BOOT */
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;
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;
390 /* process SAL system table: */
391 ia64_sal_init(efi.sal_systab);
393 #ifdef CONFIG_IA64_GENERIC
394 machvec_init(acpi_get_sysname());
398 * Set `iobase' to the appropriate address in region 6 (uncached access range).
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.
405 phys_iobase = efi_get_iobase();
407 /* set AR.KR0 since this is all we use it for anyway */
408 ia64_set_kr(IA64_KR_IO_BASE, phys_iobase);
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 "
413 printk(KERN_INFO "I/O port base = 0x%lx\n", phys_iobase);
415 ia64_iobase = (unsigned long) ioremap(phys_iobase, 0);
417 /* setup legacy IO port space */
418 io_space[0].mmio_base = ia64_iobase;
419 io_space[0].sparse = 1;
423 cpu_physical_id(0) = hard_smp_processor_id();
426 cpu_init(); /* initialize the bootstrap CPU */
428 #ifdef CONFIG_ACPI_BOOT
431 #ifdef CONFIG_SERIAL_8250_HCDP
433 void setup_serial_hcdp(void *);
435 /* Setup the serial ports described by HCDP */
436 setup_serial_hcdp(efi.hcdp);
440 # if defined(CONFIG_DUMMY_CONSOLE)
441 conswitchp = &dummy_con;
443 # if defined(CONFIG_VGA_CONSOLE)
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.
450 if (efi_mem_type(0xA0000) != EFI_CONVENTIONAL_MEMORY)
451 conswitchp = &vga_con;
455 #ifdef CONFIG_IA64_MCA
456 /* enable IA-64 Machine Check Abort Handling */
460 platform_setup(cmdline_p);
463 unw_create_gate_table();
467 * Display cpu info for all cpu's.
470 show_cpuinfo (struct seq_file *m, void *v)
473 # define lpj c->loops_per_jiffy
474 # define cpunum c->cpu
476 # define lpj loops_per_jiffy
481 const char *feature_name;
483 { 1UL << 0, "branchlong" },
484 { 1UL << 1, "spontaneous deferral"},
485 { 1UL << 2, "16-byte atomic ops" }
487 char family[32], features[128], *cp, sep;
488 struct cpuinfo_ia64 *c = v;
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;
500 /* build the feature string: */
501 memcpy(features, " standard", 10);
504 for (i = 0; i < (int) ARRAY_SIZE(feature_bits); ++i) {
505 if (mask & feature_bits[i].mask) {
510 strcpy(cp, feature_bits[i].feature_name);
511 cp += strlen(feature_bits[i].feature_name);
512 mask &= ~feature_bits[i].mask;
516 /* print unknown features as a hex value: */
519 sprintf(cp, " 0x%lx", mask);
530 "features :%s\n" /* don't change this---it _is_ right! */
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);
545 c_start (struct seq_file *m, loff_t *pos)
548 while (*pos < NR_CPUS && !(cpu_online_map & (1UL << *pos)))
551 return *pos < NR_CPUS ? cpu_data(*pos) : NULL;
555 c_next (struct seq_file *m, void *v, loff_t *pos)
558 return c_start(m, pos);
562 c_stop (struct seq_file *m, void *v)
566 struct seq_operations cpuinfo_op = {
574 identify_cpu (struct cpuinfo_ia64 *c)
577 unsigned long bits[5];
583 u64 ppn; /* processor serial number */
587 unsigned revision : 8;
590 unsigned archrev : 8;
591 unsigned reserved : 24;
597 pal_vm_info_1_u_t vm1;
598 pal_vm_info_2_u_t vm2;
600 unsigned long impl_va_msb = 50, phys_addr_size = 44; /* Itanium defaults */
603 for (i = 0; i < 5; ++i)
604 cpuid.bits[i] = ia64_get_cpuid(i);
606 memcpy(c->vendor, cpuid.field.vendor, 16);
608 c->cpu = smp_processor_id();
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;
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;
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));
630 setup_per_cpu_areas (void)
632 /* start_kernel() requires this... */
636 get_max_cacheline_size (void)
638 unsigned long line_size, max = 1;
639 u64 l, levels, unique_caches;
640 pal_cache_config_info_t cci;
643 status = ia64_pal_cache_summary(&levels, &unique_caches);
645 printk(KERN_ERR "%s: ia64_pal_cache_summary() failed (status=%ld)\n",
646 __FUNCTION__, status);
647 max = SMP_CACHE_BYTES;
651 for (l = 0; l < levels; ++l) {
652 status = ia64_pal_cache_config_info(l, /* cache_type (data_or_unified)= */ 2,
656 "%s: ia64_pal_cache_config_info(l=%lu) failed (status=%ld)\n",
657 __FUNCTION__, l, status);
658 max = SMP_CACHE_BYTES;
660 line_size = 1 << cci.pcci_line_size;
665 if (max > ia64_max_cacheline_size)
666 ia64_max_cacheline_size = max;
670 * cpu_init() initializes state that is per-CPU. This function acts
671 * as a 'CPU state barrier', nothing should get across.
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;
685 extern char __per_cpu_end[];
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().
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;
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 */
706 cpu_info = cpu_data + ((char *) &__get_cpu_var(cpu_info) - __per_cpu_start);
708 cpu_info->node_data = get_node_data_ptr();
711 get_max_cacheline_size();
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.
719 identify_cpu(cpu_info);
721 #ifdef CONFIG_MCKINLEY
723 # define FEATURE_SET 16
724 struct ia64_pal_retval iprv;
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);
735 /* Clear the stack memory reserved for pt_regs: */
736 memset(ia64_task_regs(current), 0, sizeof(struct pt_regs));
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
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);
749 ia64_set_fpu_owner(0);
752 atomic_inc(&init_mm.mm_count);
753 current->active_mm = &init_mm;
757 ia64_mmu_init(cpu_data);
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));
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);
771 /* clear TPR & XTP to enable all interrupt classes: */
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;
781 printk(KERN_WARNING "cpu_init: PAL VM summary failed, assuming 18 RID bits\n");
782 max_ctx = (1U << 15) - 1; /* use architected minimum */
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)
790 if (ia64_pal_rse_info(&num_phys_stacked, 0) != 0) {
791 printk(KERN_WARNING "cpu_init: PAL RSE info failed; assuming 96 physical "
793 num_phys_stacked = 96;
795 /* size of physical stacked register partition plus 8 bytes: */
796 __get_cpu_var(ia64_phys_stacked_size_p8) = num_phys_stacked*8 + 8;
803 extern int __start___mckinley_e9_bundles[];
804 extern int __end___mckinley_e9_bundles[];
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");
811 printk(KERN_INFO "check_bugs: McKinley Errata 9 workaround not needed; "
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;
820 ia64_insn_group_barrier();
822 ia64_insn_group_barrier();
824 ia64_insn_group_barrier();