2 * Architecture-specific setup.
4 * Copyright (C) 1998-2001 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/delay.h>
25 #include <linux/kernel.h>
26 #include <linux/reboot.h>
27 #include <linux/sched.h>
28 #include <linux/seq_file.h>
29 #include <linux/string.h>
30 #include <linux/threads.h>
31 #include <linux/console.h>
32 #include <linux/ioport.h>
33 #include <linux/efi.h>
35 #ifdef CONFIG_BLK_DEV_RAM
36 # include <linux/blk.h>
41 #include <asm/machvec.h>
42 #include <asm/processor.h>
44 #include <asm/system.h>
46 #include <asm/pgtable.h>
47 #include <asm/pgalloc.h>
51 #ifdef CONFIG_BLK_DEV_RAM
52 # include <linux/blk.h>
55 #if defined(CONFIG_SMP) && (IA64_CPU_SIZE > PAGE_SIZE)
56 # error "struct cpuinfo_ia64 too big!"
59 #define MIN(a,b) ((a) < (b) ? (a) : (b))
60 #define MAX(a,b) ((a) > (b) ? (a) : (b))
65 struct cpuinfo_ia64 *_cpu_data[NR_CPUS];
67 struct cpuinfo_ia64 _cpu_data[NR_CPUS] __attribute__ ((section ("__special_page_section")));
68 mmu_gather_t mmu_gathers[NR_CPUS];
71 unsigned long ia64_cycles_per_usec;
72 struct ia64_boot_param *ia64_boot_param;
73 struct screen_info screen_info;
75 unsigned long ia64_iobase; /* virtual address for I/O accesses */
76 struct io_space io_space[MAX_IO_SPACES];
77 unsigned int num_io_spaces;
79 unsigned char aux_device_present = 0xaa; /* XXX remove this when legacy I/O is gone */
81 #define COMMAND_LINE_SIZE 512
83 char saved_command_line[COMMAND_LINE_SIZE]; /* used in proc filesystem */
86 * Entries defined so far:
87 * - boot param structure itself
90 * - command line string
91 * - kernel code & data
93 * More could be added if necessary
95 #define IA64_MAX_RSVD_REGIONS 5
98 unsigned long start; /* virtual address of beginning of element */
99 unsigned long end; /* virtual address of end of element + 1 */
103 * We use a special marker for the end of memory and it uses the extra (+1) slot
105 static struct rsvd_region rsvd_region[IA64_MAX_RSVD_REGIONS + 1];
106 static int num_rsvd_regions;
108 #ifndef CONFIG_DISCONTIGMEM
109 static unsigned long bootmap_start; /* physical address where the bootmem map is located */
112 find_max_pfn (unsigned long start, unsigned long end, void *arg)
114 unsigned long *max_pfn = arg, pfn;
116 pfn = (PAGE_ALIGN(end - 1) - PAGE_OFFSET) >> PAGE_SHIFT;
121 #endif /* !CONFIG_DISCONTIGMEM */
123 #define IGNORE_PFN0 1 /* XXX fix me: ignore pfn 0 until TLB miss handler is updated... */
125 #ifdef CONFIG_DISCONTIGMEM
127 * efi_memmap_walk() knows nothing about layout of memory across nodes. Find
128 * out to which node a block of memory belongs. Ignore memory that we cannot
129 * identify, and split blocks that run across multiple nodes.
131 * Take this opportunity to round the start address up and the end address
132 * down to page boundaries.
135 call_pernode_memory (unsigned long start, unsigned long end, void *arg)
137 unsigned long rs, re;
138 void (*func)(unsigned long, unsigned long, int);
141 start = PAGE_ALIGN(start);
149 /* this machine doesn't have SRAT, */
150 /* so call func with nid=0, bank=0 */
152 (*func)(start, end, 0);
156 for (i = 0; i < num_memblks; i++) {
157 rs = MAX(__pa(start), node_memblk[i].start_paddr);
158 re = MIN(__pa(end), node_memblk[i].start_paddr+node_memblk[i].size);
161 (*func)((unsigned long)__va(rs), (unsigned long)__va(re), node_memblk[i].nid);
162 if ((unsigned long)__va(re) == end)
167 #else /* CONFIG_DISCONTIGMEM */
170 free_available_memory (unsigned long start, unsigned long end, void *arg)
172 free_bootmem(__pa(start), end - start);
175 #endif /* CONFIG_DISCONTIGMEM */
178 * Filter incoming memory segments based on the primitive map created from
179 * the boot parameters. Segments contained in the map are removed from the
180 * memory ranges. A caller-specified function is called with the memory
181 * ranges that remain after filtering.
182 * This routine does not assume the incoming segments are sorted.
185 filter_rsvd_memory (unsigned long start, unsigned long end, void *arg)
187 unsigned long range_start, range_end, prev_start;
188 void (*func)(unsigned long, unsigned long, int);
192 if (start == PAGE_OFFSET) {
193 printk(KERN_WARNING "warning: skipping physical page 0\n");
195 if (start >= end) return 0;
199 * lowest possible address(walker uses virtual)
201 prev_start = PAGE_OFFSET;
204 for (i = 0; i < num_rsvd_regions; ++i) {
205 range_start = MAX(start, prev_start);
206 range_end = MIN(end, rsvd_region[i].start);
208 if (range_start < range_end)
209 #ifdef CONFIG_DISCONTIGMEM
210 call_pernode_memory(range_start, range_end, func);
212 (*func)(range_start, range_end, 0);
215 /* nothing more available in this segment */
216 if (range_end == end) return 0;
218 prev_start = rsvd_region[i].end;
220 /* end of memory marker allows full processing inside loop body */
225 #ifndef CONFIG_DISCONTIGMEM
227 * Find a place to put the bootmap and return its starting address in bootmap_start.
228 * This address must be page-aligned.
231 find_bootmap_location (unsigned long start, unsigned long end, void *arg)
233 unsigned long needed = *(unsigned long *)arg;
234 unsigned long range_start, range_end, free_start;
238 if (start == PAGE_OFFSET) {
240 if (start >= end) return 0;
244 free_start = PAGE_OFFSET;
246 for (i = 0; i < num_rsvd_regions; i++) {
247 range_start = MAX(start, free_start);
248 range_end = MIN(end, rsvd_region[i].start & PAGE_MASK);
250 if (range_end <= range_start) continue; /* skip over empty range */
252 if (range_end - range_start >= needed) {
253 bootmap_start = __pa(range_start);
257 /* nothing more available in this segment */
258 if (range_end == end) return 0;
260 free_start = PAGE_ALIGN(rsvd_region[i].end);
264 #endif /* CONFIG_DISCONTIGMEM */
267 sort_regions (struct rsvd_region *rsvd_region, int max)
271 /* simple bubble sorting */
273 for (j = 0; j < max; ++j) {
274 if (rsvd_region[j].start > rsvd_region[j+1].start) {
275 struct rsvd_region tmp;
276 tmp = rsvd_region[j];
277 rsvd_region[j] = rsvd_region[j + 1];
278 rsvd_region[j + 1] = tmp;
287 # define KERNEL_END ((unsigned long) &_end)
288 unsigned long bootmap_size;
289 unsigned long max_pfn;
293 * none of the entries in this table overlap
295 rsvd_region[n].start = (unsigned long) ia64_boot_param;
296 rsvd_region[n].end = rsvd_region[n].start + sizeof(*ia64_boot_param);
299 rsvd_region[n].start = (unsigned long) __va(ia64_boot_param->efi_memmap);
300 rsvd_region[n].end = rsvd_region[n].start + ia64_boot_param->efi_memmap_size;
303 rsvd_region[n].start = (unsigned long) __va(ia64_boot_param->command_line);
304 rsvd_region[n].end = (rsvd_region[n].start
305 + strlen(__va(ia64_boot_param->command_line)) + 1);
308 rsvd_region[n].start = ia64_imva(KERNEL_START);
309 rsvd_region[n].end = ia64_imva(KERNEL_END);
312 #ifdef CONFIG_BLK_DEV_INITRD
313 if (ia64_boot_param->initrd_start) {
314 rsvd_region[n].start = (unsigned long)__va(ia64_boot_param->initrd_start);
315 rsvd_region[n].end = rsvd_region[n].start + ia64_boot_param->initrd_size;
320 /* end of memory marker */
321 rsvd_region[n].start = ~0UL;
322 rsvd_region[n].end = ~0UL;
325 num_rsvd_regions = n;
327 sort_regions(rsvd_region, num_rsvd_regions);
329 #ifdef CONFIG_DISCONTIGMEM
331 extern void discontig_mem_init(void);
332 bootmap_size = max_pfn = 0; /* stop gcc warnings */
333 discontig_mem_init();
335 #else /* !CONFIG_DISCONTIGMEM */
337 /* first find highest page frame number */
339 efi_memmap_walk(find_max_pfn, &max_pfn);
341 /* how many bytes to cover all the pages */
342 bootmap_size = bootmem_bootmap_pages(max_pfn) << PAGE_SHIFT;
344 /* look for a location to hold the bootmap */
345 bootmap_start = ~0UL;
346 efi_memmap_walk(find_bootmap_location, &bootmap_size);
347 if (bootmap_start == ~0UL)
348 panic("Cannot find %ld bytes for bootmap\n", bootmap_size);
350 bootmap_size = init_bootmem(bootmap_start >> PAGE_SHIFT, max_pfn);
352 /* Free all available memory, then mark bootmem-map as being in use. */
353 efi_memmap_walk(filter_rsvd_memory, free_available_memory);
354 reserve_bootmem(bootmap_start, bootmap_size);
355 #endif /* !CONFIG_DISCONTIGMEM */
357 #ifdef CONFIG_BLK_DEV_INITRD
358 if (ia64_boot_param->initrd_start) {
359 initrd_start = (unsigned long)__va(ia64_boot_param->initrd_start);
360 initrd_end = initrd_start+ia64_boot_param->initrd_size;
362 printk(KERN_INFO "Initial ramdisk at: 0x%lx (%lu bytes)\n",
363 initrd_start, ia64_boot_param->initrd_size);
369 setup_arch (char **cmdline_p)
371 extern unsigned long ia64_iobase;
372 unsigned long phys_iobase;
376 *cmdline_p = __va(ia64_boot_param->command_line);
377 strncpy(saved_command_line, *cmdline_p, sizeof(saved_command_line));
378 saved_command_line[COMMAND_LINE_SIZE-1] = '\0'; /* for safety */
382 #ifdef CONFIG_ACPI_BOOT
383 /* Initialize the ACPI boot-time table parser */
386 # ifdef CONFIG_ACPI_NUMA
391 smp_build_cpu_map(); /* happens, e.g., with the Ski simulator */
393 #endif /* CONFIG_APCI_BOOT */
395 iomem_resource.end = ~0UL; /* FIXME probably belongs elsewhere */
400 init_mm.start_code = (unsigned long) &_stext;
401 init_mm.end_code = (unsigned long) &_etext;
402 init_mm.end_data = (unsigned long) &_edata;
403 init_mm.brk = (unsigned long) &_end;
405 code_resource.start = virt_to_bus(&_text);
406 code_resource.end = virt_to_bus(&_etext) - 1;
407 data_resource.start = virt_to_bus(&_etext);
408 data_resource.end = virt_to_bus(&_edata) - 1;
411 /* process SAL system table: */
412 ia64_sal_init(efi.sal_systab);
414 #ifdef CONFIG_IA64_GENERIC
415 machvec_init(acpi_get_sysname());
419 * Set `iobase' to the appropriate address in region 6 (uncached access range).
421 * The EFI memory map is the "preferred" location to get the I/O port space base,
422 * rather the relying on AR.KR0. This should become more clear in future SAL
423 * specs. We'll fall back to getting it out of AR.KR0 if no appropriate entry is
424 * found in the memory map.
426 phys_iobase = efi_get_iobase();
428 /* set AR.KR0 since this is all we use it for anyway */
429 ia64_set_kr(IA64_KR_IO_BASE, phys_iobase);
431 phys_iobase = ia64_get_kr(IA64_KR_IO_BASE);
432 printk(KERN_INFO "No I/O port range found in EFI memory map, falling back "
434 printk(KERN_INFO "I/O port base = 0x%lx\n", phys_iobase);
436 ia64_iobase = (unsigned long) ioremap(phys_iobase, 0);
438 /* setup legacy IO port space */
439 io_space[0].mmio_base = ia64_iobase;
440 io_space[0].sparse = 1;
444 cpu_physical_id(0) = hard_smp_processor_id();
447 cpu_init(); /* initialize the bootstrap CPU */
449 #ifdef CONFIG_ACPI_BOOT
452 #ifdef CONFIG_SERIAL_HCDP
454 void setup_serial_hcdp(void *);
456 /* Setup the serial ports described by HCDP */
457 setup_serial_hcdp(efi.hcdp);
461 # if defined(CONFIG_DUMMY_CONSOLE)
462 conswitchp = &dummy_con;
464 # if defined(CONFIG_VGA_CONSOLE)
466 * Non-legacy systems may route legacy VGA MMIO range to system
467 * memory. vga_con probes the MMIO hole, so memory looks like
468 * a VGA device to it. The EFI memory map can tell us if it's
469 * memory so we can avoid this problem.
471 if (efi_mem_type(0xA0000) != EFI_CONVENTIONAL_MEMORY)
472 conswitchp = &vga_con;
476 #ifdef CONFIG_IA64_MCA
477 /* enable IA-64 Machine Check Abort Handling */
481 platform_setup(cmdline_p);
484 unw_create_gate_table();
488 * Display cpu info for all cpu's.
491 show_cpuinfo (struct seq_file *m, void *v)
494 # define lpj c->loops_per_jiffy
495 # define cpu c->processor
497 # define lpj loops_per_jiffy
500 char family[32], features[128], *cp;
501 struct cpuinfo_ia64 *c = v;
507 case 0x07: memcpy(family, "Itanium", 8); break;
508 case 0x1f: memcpy(family, "Itanium 2", 10); break;
509 default: sprintf(family, "%u", c->family); break;
512 /* build the feature string: */
513 memcpy(features, " standard", 10);
516 strcpy(cp, " branchlong");
517 cp = strchr(cp, '\0');
521 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 cpu, 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);
548 c_start (struct seq_file *m, loff_t *pos)
551 while (*pos < NR_CPUS && !(cpu_online_map & (1UL << *pos)))
554 return *pos < NR_CPUS ? cpu_data(*pos) : NULL;
558 c_next (struct seq_file *m, void *v, loff_t *pos)
561 return c_start(m, pos);
565 c_stop (struct seq_file *m, void *v)
569 struct seq_operations cpuinfo_op = {
577 identify_cpu (struct cpuinfo_ia64 *c)
580 unsigned long bits[5];
586 u64 ppn; /* processor serial number */
590 unsigned revision : 8;
593 unsigned archrev : 8;
594 unsigned reserved : 24;
600 pal_vm_info_1_u_t vm1;
601 pal_vm_info_2_u_t vm2;
603 unsigned long impl_va_msb = 50, phys_addr_size = 44; /* Itanium defaults */
606 for (i = 0; i < 5; ++i)
607 cpuid.bits[i] = ia64_get_cpuid(i);
609 memcpy(c->vendor, cpuid.field.vendor, 16);
611 c->processor = smp_processor_id();
613 c->ppn = cpuid.field.ppn;
614 c->number = cpuid.field.number;
615 c->revision = cpuid.field.revision;
616 c->model = cpuid.field.model;
617 c->family = cpuid.field.family;
618 c->archrev = cpuid.field.archrev;
619 c->features = cpuid.field.features;
621 status = ia64_pal_vm_summary(&vm1, &vm2);
622 if (status == PAL_STATUS_SUCCESS) {
623 impl_va_msb = vm2.pal_vm_info_2_s.impl_va_msb;
624 phys_addr_size = vm1.pal_vm_info_1_s.phys_add_size;
626 printk(KERN_INFO "CPU %d: %lu virtual and %lu physical address bits\n",
627 smp_processor_id(), impl_va_msb + 1, phys_addr_size);
628 c->unimpl_va_mask = ~((7L<<61) | ((1L << (impl_va_msb + 1)) - 1));
629 c->unimpl_pa_mask = ~((1L<<63) | ((1L << phys_addr_size) - 1));
633 * cpu_init() initializes state that is per-CPU. This function acts
634 * as a 'CPU state barrier', nothing should get across.
639 extern void __init ia64_mmu_init (void *);
640 unsigned long num_phys_stacked;
641 pal_vm_info_2_u_t vmi;
642 unsigned int max_ctx;
643 struct cpuinfo_ia64 *my_cpu_data;
648 * If NUMA is configured, the cpu_data array is not preallocated. The boot cpu
649 * allocates entries for every possible cpu. As the remaining cpus come online,
650 * they reallocate a new cpu_data structure on their local node. This extra work
651 * is required because some boot code references all cpu_data structures
652 * before the cpus are actually started.
654 for (cpu=0; cpu < NR_CPUS; cpu++)
655 if (node_cpuid[cpu].phys_id == hard_smp_processor_id())
657 my_cpu_data = _cpu_data[cpu];
658 my_cpu_data->node_data->active_cpu_count++;
660 for (cpu=0; cpu<NR_CPUS; cpu++)
661 _cpu_data[cpu]->cpu_data[smp_processor_id()] = my_cpu_data;
663 my_cpu_data = cpu_data(smp_processor_id());
664 my_cpu_data->mmu_gathers = &mmu_gathers[smp_processor_id()];
668 * We can't pass "local_cpu_data" to identify_cpu() because we haven't called
669 * ia64_mmu_init() yet. And we can't call ia64_mmu_init() first because it
670 * depends on the data returned by identify_cpu(). We break the dependency by
671 * accessing cpu_data() the old way, through identity mapped space.
673 identify_cpu(my_cpu_data);
675 #ifdef CONFIG_MCKINLEY
677 #define FEATURE_SET 16
678 struct ia64_pal_retval iprv;
680 if (my_cpu_data->family == 0x1f) {
682 PAL_CALL_PHYS(iprv, PAL_PROC_GET_FEATURES, 0, FEATURE_SET, 0);
684 if ((iprv.status == 0) && (iprv.v0 & 0x80) && (iprv.v2 & 0x80)) {
686 PAL_CALL_PHYS(iprv, PAL_PROC_SET_FEATURES,
687 (iprv.v1 | 0x80), FEATURE_SET, 0);
693 /* Clear the stack memory reserved for pt_regs: */
694 memset(ia64_task_regs(current), 0, sizeof(struct pt_regs));
696 ia64_set_kr(IA64_KR_FPU_OWNER, 0);
699 * Initialize default control register to defer all speculative faults. The
700 * kernel MUST NOT depend on a particular setting of these bits (in other words,
701 * the kernel must have recovery code for all speculative accesses). Turn on
702 * dcr.lc as per recommendation by the architecture team. Most IA-32 apps
703 * shouldn't be affected by this (moral: keep your ia32 locks aligned and you'll
706 ia64_set_dcr( IA64_DCR_DP | IA64_DCR_DK | IA64_DCR_DX | IA64_DCR_DR
707 | IA64_DCR_DA | IA64_DCR_DD | IA64_DCR_LC);
708 atomic_inc(&init_mm.mm_count);
709 current->active_mm = &init_mm;
711 ia64_mmu_init(my_cpu_data);
713 #ifdef CONFIG_IA32_SUPPORT
714 /* initialize global ia32 state - CR0 and CR4 */
715 asm volatile ("mov ar.cflg = %0" :: "r" (((ulong) IA32_CR4 << 32) | IA32_CR0));
718 /* disable all local interrupt sources: */
719 ia64_set_itv(1 << 16);
720 ia64_set_lrr0(1 << 16);
721 ia64_set_lrr1(1 << 16);
722 ia64_set_pmv(1 << 16);
723 ia64_set_cmcv(1 << 16);
725 /* clear TPR & XTP to enable all interrupt classes: */
731 /* set ia64_ctx.max_rid to the maximum RID that is supported by all CPUs: */
732 if (ia64_pal_vm_summary(NULL, &vmi) == 0)
733 max_ctx = (1U << (vmi.pal_vm_info_2_s.rid_size - 3)) - 1;
735 printk(KERN_WARNING "cpu_init: PAL VM summary failed, assuming 18 RID bits\n");
736 max_ctx = (1U << 15) - 1; /* use architected minimum */
738 while (max_ctx < ia64_ctx.max_ctx) {
739 unsigned int old = ia64_ctx.max_ctx;
740 if (cmpxchg(&ia64_ctx.max_ctx, old, max_ctx) == old)
744 if (ia64_pal_rse_info(&num_phys_stacked, 0) != 0) {
745 printk(KERN_WARNING "cpu_init: PAL RSE info failed, assuming 96 physical stacked regs\n");
746 num_phys_stacked = 96;
748 local_cpu_data->phys_stacked_size_p8 = num_phys_stacked*8 + 8;