ia64/xen-unstable

view xen/arch/x86/setup.c @ 5593:384059d92d3b

bitkeeper revision 1.1760.1.5 (42c105a0IGE_9KbvmOfox8TMahmQVw)

Only enable PGE in CR4 if the CPU supports the feature.
Signed-off-by: Keir Fraser <keir@xensource.com>
author kaf24@firebug.cl.cam.ac.uk
date Tue Jun 28 08:09:04 2005 +0000 (2005-06-28)
parents 76346519b28e
children 63c1bb85fcea
line source
2 #include <xen/config.h>
3 #include <xen/init.h>
4 #include <xen/lib.h>
5 #include <xen/sched.h>
6 #include <xen/domain.h>
7 #include <xen/serial.h>
8 #include <xen/softirq.h>
9 #include <xen/acpi.h>
10 #include <xen/console.h>
11 #include <xen/serial.h>
12 #include <xen/trace.h>
13 #include <xen/multiboot.h>
14 #include <xen/domain_page.h>
15 #include <asm/bitops.h>
16 #include <asm/smp.h>
17 #include <asm/processor.h>
18 #include <asm/mpspec.h>
19 #include <asm/apic.h>
20 #include <asm/desc.h>
21 #include <asm/shadow.h>
22 #include <asm/e820.h>
23 #include <acm/acm_hooks.h>
25 extern void dmi_scan_machine(void);
26 extern void generic_apic_probe(void);
28 /*
29 * opt_xenheap_megabytes: Size of Xen heap in megabytes, excluding the
30 * pfn_info table and allocation bitmap.
31 */
32 static unsigned int opt_xenheap_megabytes = XENHEAP_DEFAULT_MB;
33 #if defined(CONFIG_X86_64)
34 integer_param("xenheap_megabytes", opt_xenheap_megabytes);
35 #endif
37 /* opt_nosmp: If true, secondary processors are ignored. */
38 static int opt_nosmp = 0;
39 boolean_param("nosmp", opt_nosmp);
41 /* maxcpus: maximum number of CPUs to activate. */
42 static unsigned int max_cpus = NR_CPUS;
43 integer_param("maxcpus", max_cpus);
45 /* opt_watchdog: If true, run a watchdog NMI on each processor. */
46 static int opt_watchdog = 0;
47 boolean_param("watchdog", opt_watchdog);
49 /* **** Linux config option: propagated to domain0. */
50 /* "acpi=off": Sisables both ACPI table parsing and interpreter. */
51 /* "acpi=force": Override the disable blacklist. */
52 /* "acpi=strict": Disables out-of-spec workarounds. */
53 /* "acpi=ht": Limit ACPI just to boot-time to enable HT. */
54 /* "acpi=noirq": Disables ACPI interrupt routing. */
55 static void parse_acpi_param(char *s);
56 custom_param("acpi", parse_acpi_param);
58 /* **** Linux config option: propagated to domain0. */
59 /* acpi_skip_timer_override: Skip IRQ0 overrides. */
60 extern int acpi_skip_timer_override;
61 boolean_param("acpi_skip_timer_override", acpi_skip_timer_override);
63 /* **** Linux config option: propagated to domain0. */
64 /* noapic: Disable IOAPIC setup. */
65 extern int skip_ioapic_setup;
66 boolean_param("noapic", skip_ioapic_setup);
68 int early_boot = 1;
70 cpumask_t cpu_present_map;
72 /* Limits of Xen heap, used to initialise the allocator. */
73 unsigned long xenheap_phys_start, xenheap_phys_end;
75 extern void arch_init_memory(void);
76 extern void init_IRQ(void);
77 extern void trap_init(void);
78 extern void time_init(void);
79 extern void ac_timer_init(void);
80 extern void initialize_keytable(void);
81 extern void early_cpu_init(void);
83 extern unsigned long cpu0_stack[];
85 struct cpuinfo_x86 boot_cpu_data = { 0, 0, 0, 0, -1, 1, 0, 0, -1 };
87 #if CONFIG_PAGING_LEVELS > 2
88 unsigned long mmu_cr4_features = X86_CR4_PSE | X86_CR4_PGE | X86_CR4_PAE;
89 #else
90 unsigned long mmu_cr4_features = X86_CR4_PSE;
91 #endif
92 EXPORT_SYMBOL(mmu_cr4_features);
94 struct vcpu *idle_task[NR_CPUS] = { &idle0_vcpu };
96 int acpi_disabled;
98 int acpi_force;
99 char acpi_param[10] = "";
100 static void parse_acpi_param(char *s)
101 {
102 /* Save the parameter so it can be propagated to domain0. */
103 strncpy(acpi_param, s, sizeof(acpi_param));
104 acpi_param[sizeof(acpi_param)-1] = '\0';
106 /* Interpret the parameter for use within Xen. */
107 if ( !strcmp(s, "off") )
108 {
109 disable_acpi();
110 }
111 else if ( !strcmp(s, "force") )
112 {
113 acpi_force = 1;
114 acpi_ht = 1;
115 acpi_disabled = 0;
116 }
117 else if ( !strcmp(s, "strict") )
118 {
119 acpi_strict = 1;
120 }
121 else if ( !strcmp(s, "ht") )
122 {
123 if ( !acpi_force )
124 disable_acpi();
125 acpi_ht = 1;
126 }
127 else if ( !strcmp(s, "noirq") )
128 {
129 acpi_noirq_set();
130 }
131 }
133 static void __init do_initcalls(void)
134 {
135 initcall_t *call;
136 for ( call = &__initcall_start; call < &__initcall_end; call++ )
137 (*call)();
138 }
140 static void __init start_of_day(void)
141 {
142 int i;
144 early_cpu_init();
146 paging_init();
148 /* Unmap the first page of CPU0's stack. */
149 memguard_guard_stack(cpu0_stack);
151 open_softirq(NEW_TLBFLUSH_CLOCK_PERIOD_SOFTIRQ, new_tlbflush_clock_period);
153 if ( opt_watchdog )
154 nmi_watchdog = NMI_LOCAL_APIC;
156 sort_exception_tables();
158 arch_do_createdomain(current);
160 /* Map default GDT into their final position in the idle page table. */
161 map_pages_to_xen(
162 GDT_VIRT_START(current) + FIRST_RESERVED_GDT_BYTE,
163 virt_to_phys(gdt_table) >> PAGE_SHIFT, 1, PAGE_HYPERVISOR);
165 find_smp_config();
167 smp_alloc_memory();
169 dmi_scan_machine();
171 generic_apic_probe();
173 acpi_boot_table_init();
174 acpi_boot_init();
176 if ( smp_found_config )
177 get_smp_config();
179 init_apic_mappings();
181 init_IRQ();
183 trap_init();
185 ac_timer_init();
187 time_init();
189 arch_init_memory();
191 scheduler_init();
193 identify_cpu(&boot_cpu_data);
194 if ( cpu_has_fxsr )
195 set_in_cr4(X86_CR4_OSFXSR);
196 if ( cpu_has_xmm )
197 set_in_cr4(X86_CR4_OSXMMEXCPT);
199 if ( opt_nosmp )
200 max_cpus = 0;
201 smp_prepare_cpus(max_cpus);
203 /* We aren't hotplug-capable yet. */
204 BUG_ON(!cpus_empty(cpu_present_map));
205 for_each_cpu ( i )
206 cpu_set(i, cpu_present_map);
208 /* Sanity: We ought to be taking interrupts by now. */
209 local_irq_enable();
211 initialize_keytable();
213 serial_init_postirq();
215 init_xen_time();
217 for_each_present_cpu ( i )
218 {
219 if ( num_online_cpus() >= max_cpus )
220 break;
221 if ( !cpu_online(i) )
222 __cpu_up(i);
223 }
225 printk("Brought up %ld CPUs\n", (long)num_online_cpus());
226 smp_cpus_done(max_cpus);
228 do_initcalls();
230 schedulers_start();
232 watchdog_enable();
233 }
235 #define EARLY_FAIL() for ( ; ; ) __asm__ __volatile__ ( "hlt" )
237 void __init __start_xen(multiboot_info_t *mbi)
238 {
239 char *cmdline;
240 module_t *mod = (module_t *)__va(mbi->mods_addr);
241 unsigned long firsthole_start, nr_pages;
242 unsigned long initial_images_start, initial_images_end;
243 struct e820entry e820_raw[E820MAX];
244 int i, e820_raw_nr = 0, bytes = 0;
246 /* Parse the command-line options. */
247 if ( (mbi->flags & MBI_CMDLINE) && (mbi->cmdline != 0) )
248 cmdline_parse(__va(mbi->cmdline));
250 /* Must do this early -- e.g., spinlocks rely on get_current(). */
251 set_current(&idle0_vcpu);
252 set_processor_id(0);
254 smp_prepare_boot_cpu();
256 /* We initialise the serial devices very early so we can get debugging. */
257 ns16550_init();
258 serial_init_preirq();
260 init_console();
262 /* Check that we have at least one Multiboot module. */
263 if ( !(mbi->flags & MBI_MODULES) || (mbi->mods_count == 0) )
264 {
265 printk("FATAL ERROR: dom0 kernel not specified."
266 " Check bootloader configuration.\n");
267 EARLY_FAIL();
268 }
270 if ( ((unsigned long)cpu0_stack & (STACK_SIZE-1)) != 0 )
271 {
272 printk("FATAL ERROR: Misaligned CPU0 stack.\n");
273 EARLY_FAIL();
274 }
276 xenheap_phys_end = opt_xenheap_megabytes << 20;
278 if ( mbi->flags & MBI_MEMMAP )
279 {
280 while ( bytes < mbi->mmap_length )
281 {
282 memory_map_t *map = __va(mbi->mmap_addr + bytes);
283 e820_raw[e820_raw_nr].addr =
284 ((u64)map->base_addr_high << 32) | (u64)map->base_addr_low;
285 e820_raw[e820_raw_nr].size =
286 ((u64)map->length_high << 32) | (u64)map->length_low;
287 e820_raw[e820_raw_nr].type =
288 (map->type > E820_SHARED_PAGE) ? E820_RESERVED : map->type;
289 e820_raw_nr++;
290 bytes += map->size + 4;
291 }
292 }
293 else if ( mbi->flags & MBI_MEMLIMITS )
294 {
295 e820_raw[0].addr = 0;
296 e820_raw[0].size = mbi->mem_lower << 10;
297 e820_raw[0].type = E820_RAM;
298 e820_raw[1].addr = 0x100000;
299 e820_raw[1].size = mbi->mem_upper << 10;
300 e820_raw[1].type = E820_RAM;
301 e820_raw_nr = 2;
302 }
303 else
304 {
305 printk("FATAL ERROR: Bootloader provided no memory information.\n");
306 for ( ; ; ) ;
307 }
309 max_page = init_e820(e820_raw, &e820_raw_nr);
311 /* Find the first high-memory RAM hole. */
312 for ( i = 0; i < e820.nr_map; i++ )
313 if ( (e820.map[i].type == E820_RAM) &&
314 (e820.map[i].addr >= 0x100000) )
315 break;
316 firsthole_start = e820.map[i].addr + e820.map[i].size;
318 /* Relocate the Multiboot modules. */
319 initial_images_start = xenheap_phys_end;
320 initial_images_end = initial_images_start +
321 (mod[mbi->mods_count-1].mod_end - mod[0].mod_start);
322 if ( initial_images_end > firsthole_start )
323 {
324 printk("Not enough memory to stash the DOM0 kernel image.\n");
325 for ( ; ; ) ;
326 }
327 #if defined(CONFIG_X86_32)
328 memmove((void *)initial_images_start, /* use low mapping */
329 (void *)mod[0].mod_start, /* use low mapping */
330 mod[mbi->mods_count-1].mod_end - mod[0].mod_start);
331 #elif defined(CONFIG_X86_64)
332 memmove(__va(initial_images_start),
333 __va(mod[0].mod_start),
334 mod[mbi->mods_count-1].mod_end - mod[0].mod_start);
335 #endif
337 /* Initialise boot-time allocator with all RAM situated after modules. */
338 xenheap_phys_start = init_boot_allocator(__pa(&_end));
339 nr_pages = 0;
340 for ( i = 0; i < e820.nr_map; i++ )
341 {
342 if ( e820.map[i].type != E820_RAM )
343 continue;
344 nr_pages += e820.map[i].size >> PAGE_SHIFT;
345 if ( (e820.map[i].addr + e820.map[i].size) >= initial_images_end )
346 init_boot_pages((e820.map[i].addr < initial_images_end) ?
347 initial_images_end : e820.map[i].addr,
348 e820.map[i].addr + e820.map[i].size);
349 #if defined (CONFIG_X86_64)
350 /*
351 * x86/64 maps all registered RAM. Points to note:
352 * 1. The initial pagetable already maps low 64MB, so skip that.
353 * 2. We must map *only* RAM areas, taking care to avoid I/O holes.
354 * Failure to do this can cause coherency problems and deadlocks
355 * due to cache-attribute mismatches (e.g., AMD/AGP Linux bug).
356 */
357 {
358 /* Calculate page-frame range, discarding partial frames. */
359 unsigned long start, end;
360 start = PFN_UP(e820.map[i].addr);
361 end = PFN_DOWN(e820.map[i].addr + e820.map[i].size);
362 /* Clip the range to above 64MB. */
363 if ( end < (64UL << (20-PAGE_SHIFT)) )
364 continue;
365 if ( start < (64UL << (20-PAGE_SHIFT)) )
366 start = 64UL << (20-PAGE_SHIFT);
367 /* Request the mapping. */
368 map_pages_to_xen(
369 PAGE_OFFSET + (start << PAGE_SHIFT),
370 start, end-start, PAGE_HYPERVISOR);
371 }
372 #endif
373 }
375 memguard_init();
377 printk("System RAM: %luMB (%lukB)\n",
378 nr_pages >> (20 - PAGE_SHIFT),
379 nr_pages << (PAGE_SHIFT - 10));
381 init_frametable();
383 end_boot_allocator();
385 init_xenheap_pages(xenheap_phys_start, xenheap_phys_end);
386 printk("Xen heap: %luMB (%lukB)\n",
387 (xenheap_phys_end-xenheap_phys_start) >> 20,
388 (xenheap_phys_end-xenheap_phys_start) >> 10);
390 early_boot = 0;
392 start_of_day();
394 grant_table_init();
396 shadow_mode_init();
398 /* initialize access control security module */
399 acm_init();
401 /* Create initial domain 0. */
402 dom0 = do_createdomain(0, 0);
403 if ( dom0 == NULL )
404 panic("Error creating domain 0\n");
406 set_bit(_DOMF_privileged, &dom0->domain_flags);
407 /* post-create hooks sets security label */
408 acm_post_domain0_create(dom0->domain_id);
410 /* Grab the DOM0 command line. */
411 cmdline = (char *)(mod[0].string ? __va(mod[0].string) : NULL);
412 if ( cmdline != NULL )
413 {
414 static char dom0_cmdline[MAX_GUEST_CMDLINE];
416 /* Skip past the image name. */
417 while ( *cmdline == ' ' ) cmdline++;
418 if ( (cmdline = strchr(cmdline, ' ')) != NULL )
419 while ( *cmdline == ' ' ) cmdline++;
421 /* Copy the command line to a local buffer. */
422 strcpy(dom0_cmdline, cmdline);
423 cmdline = dom0_cmdline;
425 /* Append any extra parameters. */
426 if ( skip_ioapic_setup && !strstr(cmdline, "noapic") )
427 strcat(cmdline, " noapic");
428 if ( acpi_skip_timer_override &&
429 !strstr(cmdline, "acpi_skip_timer_override") )
430 strcat(cmdline, " acpi_skip_timer_override");
431 if ( (strlen(acpi_param) != 0) && !strstr(cmdline, "acpi=") )
432 {
433 strcat(cmdline, " acpi=");
434 strcat(cmdline, acpi_param);
435 }
436 }
438 /*
439 * We're going to setup domain0 using the module(s) that we stashed safely
440 * above our heap. The second module, if present, is an initrd ramdisk.
441 */
442 if ( construct_dom0(dom0,
443 initial_images_start,
444 mod[0].mod_end-mod[0].mod_start,
445 (mbi->mods_count == 1) ? 0 :
446 initial_images_start +
447 (mod[1].mod_start-mod[0].mod_start),
448 (mbi->mods_count == 1) ? 0 :
449 mod[mbi->mods_count-1].mod_end - mod[1].mod_start,
450 cmdline) != 0)
451 panic("Could not set up DOM0 guest OS\n");
453 /* Scrub RAM that is still free and so may go to an unprivileged domain. */
454 scrub_heap_pages();
456 init_trace_bufs();
458 /* Give up the VGA console if DOM0 is configured to grab it. */
459 console_endboot(cmdline && strstr(cmdline, "tty0"));
461 /* Hide UART from DOM0 if we're using it */
462 serial_endboot();
464 domain_unpause_by_systemcontroller(dom0);
466 startup_cpu_idle_loop();
467 }
469 /*
470 * Local variables:
471 * mode: C
472 * c-set-style: "BSD"
473 * c-basic-offset: 4
474 * tab-width: 4
475 * indent-tabs-mode: nil
476 * End:
477 */