ia64/xen-unstable

view xen/arch/x86/setup.c @ 8246:379921f2259d

Update xen cap to reflect 32 bit VMX guest support on x86_64

Signed-off-by: Xin Li <xin.b.li@intel.com>
author kaf24@firebug.cl.cam.ac.uk
date Tue Dec 06 12:46:43 2005 +0100 (2005-12-06)
parents 36ab34f1c31e
children 47d947e07205
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 <xen/compile.h>
16 #include <public/version.h>
17 #include <asm/bitops.h>
18 #include <asm/smp.h>
19 #include <asm/processor.h>
20 #include <asm/mpspec.h>
21 #include <asm/apic.h>
22 #include <asm/desc.h>
23 #include <asm/shadow.h>
24 #include <asm/e820.h>
25 #include <acm/acm_hooks.h>
27 extern void dmi_scan_machine(void);
28 extern void generic_apic_probe(void);
30 /*
31 * opt_xenheap_megabytes: Size of Xen heap in megabytes, excluding the
32 * pfn_info table and allocation bitmap.
33 */
34 static unsigned int opt_xenheap_megabytes = XENHEAP_DEFAULT_MB;
35 #if defined(CONFIG_X86_64)
36 integer_param("xenheap_megabytes", opt_xenheap_megabytes);
37 #endif
39 /* opt_nosmp: If true, secondary processors are ignored. */
40 static int opt_nosmp = 0;
41 boolean_param("nosmp", opt_nosmp);
43 /* maxcpus: maximum number of CPUs to activate. */
44 static unsigned int max_cpus = NR_CPUS;
45 integer_param("maxcpus", max_cpus);
47 /* opt_watchdog: If true, run a watchdog NMI on each processor. */
48 static int opt_watchdog = 0;
49 boolean_param("watchdog", opt_watchdog);
51 /* **** Linux config option: propagated to domain0. */
52 /* "acpi=off": Sisables both ACPI table parsing and interpreter. */
53 /* "acpi=force": Override the disable blacklist. */
54 /* "acpi=strict": Disables out-of-spec workarounds. */
55 /* "acpi=ht": Limit ACPI just to boot-time to enable HT. */
56 /* "acpi=noirq": Disables ACPI interrupt routing. */
57 static void parse_acpi_param(char *s);
58 custom_param("acpi", parse_acpi_param);
60 /* **** Linux config option: propagated to domain0. */
61 /* acpi_skip_timer_override: Skip IRQ0 overrides. */
62 extern int acpi_skip_timer_override;
63 boolean_param("acpi_skip_timer_override", acpi_skip_timer_override);
65 /* **** Linux config option: propagated to domain0. */
66 /* noapic: Disable IOAPIC setup. */
67 extern int skip_ioapic_setup;
68 boolean_param("noapic", skip_ioapic_setup);
70 int early_boot = 1;
72 cpumask_t cpu_present_map;
74 /* Limits of Xen heap, used to initialise the allocator. */
75 unsigned long xenheap_phys_start, xenheap_phys_end;
77 extern void arch_init_memory(void);
78 extern void init_IRQ(void);
79 extern void trap_init(void);
80 extern void early_time_init(void);
81 extern void initialize_keytable(void);
82 extern void early_cpu_init(void);
84 extern unsigned long cpu0_stack[];
86 struct cpuinfo_x86 boot_cpu_data = { 0, 0, 0, 0, -1, 1, 0, 0, -1 };
88 #if CONFIG_PAGING_LEVELS > 2
89 unsigned long mmu_cr4_features = X86_CR4_PSE | X86_CR4_PGE | X86_CR4_PAE;
90 #else
91 unsigned long mmu_cr4_features = X86_CR4_PSE;
92 #endif
93 EXPORT_SYMBOL(mmu_cr4_features);
95 struct vcpu *idle_task[NR_CPUS] = { &idle0_vcpu };
97 int acpi_disabled;
99 int acpi_force;
100 char acpi_param[10] = "";
101 static void parse_acpi_param(char *s)
102 {
103 /* Save the parameter so it can be propagated to domain0. */
104 strncpy(acpi_param, s, sizeof(acpi_param));
105 acpi_param[sizeof(acpi_param)-1] = '\0';
107 /* Interpret the parameter for use within Xen. */
108 if ( !strcmp(s, "off") )
109 {
110 disable_acpi();
111 }
112 else if ( !strcmp(s, "force") )
113 {
114 acpi_force = 1;
115 acpi_ht = 1;
116 acpi_disabled = 0;
117 }
118 else if ( !strcmp(s, "strict") )
119 {
120 acpi_strict = 1;
121 }
122 else if ( !strcmp(s, "ht") )
123 {
124 if ( !acpi_force )
125 disable_acpi();
126 acpi_ht = 1;
127 }
128 else if ( !strcmp(s, "noirq") )
129 {
130 acpi_noirq_set();
131 }
132 }
134 static void __init do_initcalls(void)
135 {
136 initcall_t *call;
137 for ( call = &__initcall_start; call < &__initcall_end; call++ )
138 (*call)();
139 }
141 static void __init start_of_day(void)
142 {
143 int i;
144 unsigned long vgdt, gdt_pfn;
146 early_cpu_init();
148 paging_init();
150 /* Unmap the first page of CPU0's stack. */
151 memguard_guard_stack(cpu0_stack);
153 open_softirq(NEW_TLBFLUSH_CLOCK_PERIOD_SOFTIRQ, new_tlbflush_clock_period);
155 if ( opt_watchdog )
156 nmi_watchdog = NMI_LOCAL_APIC;
158 sort_exception_tables();
160 arch_do_createdomain(current);
162 /*
163 * Map default GDT into its final positions in the idle page table. As
164 * noted in arch_do_createdomain(), we must map for every possible VCPU#.
165 */
166 vgdt = GDT_VIRT_START(current) + FIRST_RESERVED_GDT_BYTE;
167 gdt_pfn = virt_to_phys(gdt_table) >> PAGE_SHIFT;
168 for ( i = 0; i < MAX_VIRT_CPUS; i++ )
169 {
170 map_pages_to_xen(vgdt, gdt_pfn, 1, PAGE_HYPERVISOR);
171 vgdt += 1 << PDPT_VCPU_VA_SHIFT;
172 }
174 find_smp_config();
176 smp_alloc_memory();
178 dmi_scan_machine();
180 generic_apic_probe();
182 acpi_boot_table_init();
183 acpi_boot_init();
185 if ( smp_found_config )
186 get_smp_config();
188 init_apic_mappings();
190 init_IRQ();
192 trap_init();
194 ac_timer_init();
196 early_time_init();
198 arch_init_memory();
200 scheduler_init();
202 identify_cpu(&boot_cpu_data);
203 if ( cpu_has_fxsr )
204 set_in_cr4(X86_CR4_OSFXSR);
205 if ( cpu_has_xmm )
206 set_in_cr4(X86_CR4_OSXMMEXCPT);
208 if ( opt_nosmp )
209 {
210 max_cpus = 0;
211 smp_num_siblings = 1;
212 boot_cpu_data.x86_num_cores = 1;
213 }
215 smp_prepare_cpus(max_cpus);
217 /* We aren't hotplug-capable yet. */
218 BUG_ON(!cpus_empty(cpu_present_map));
219 for_each_cpu ( i )
220 cpu_set(i, cpu_present_map);
222 /*
223 * Initialise higher-level timer functions. We do this fairly late
224 * (post-SMP) because the time bases and scale factors need to be updated
225 * regularly, and SMP initialisation can cause a long delay with
226 * interrupts not yet enabled.
227 */
228 init_xen_time();
230 initialize_keytable();
232 serial_init_postirq();
234 BUG_ON(!local_irq_is_enabled());
236 for_each_present_cpu ( i )
237 {
238 if ( num_online_cpus() >= max_cpus )
239 break;
240 if ( !cpu_online(i) )
241 __cpu_up(i);
242 }
244 printk("Brought up %ld CPUs\n", (long)num_online_cpus());
245 smp_cpus_done(max_cpus);
247 do_initcalls();
249 schedulers_start();
251 watchdog_enable();
252 }
254 #define EARLY_FAIL() for ( ; ; ) __asm__ __volatile__ ( "hlt" )
256 static struct e820entry e820_raw[E820MAX];
258 void __init __start_xen(multiboot_info_t *mbi)
259 {
260 char *cmdline;
261 module_t *mod = (module_t *)__va(mbi->mods_addr);
262 unsigned long nr_pages, modules_length;
263 unsigned long initial_images_start, initial_images_end;
264 unsigned long _initrd_start = 0, _initrd_len = 0;
265 unsigned int initrdidx = 1;
266 physaddr_t s, e;
267 int i, e820_raw_nr = 0, bytes = 0;
268 struct ns16550_defaults ns16550 = {
269 .data_bits = 8,
270 .parity = 'n',
271 .stop_bits = 1
272 };
274 /* Parse the command-line options. */
275 if ( (mbi->flags & MBI_CMDLINE) && (mbi->cmdline != 0) )
276 cmdline_parse(__va(mbi->cmdline));
278 /* Must do this early -- e.g., spinlocks rely on get_current(). */
279 set_current(&idle0_vcpu);
280 set_processor_id(0);
282 smp_prepare_boot_cpu();
284 /* We initialise the serial devices very early so we can get debugging. */
285 ns16550.io_base = 0x3f8;
286 ns16550.irq = 4;
287 ns16550_init(0, &ns16550);
288 ns16550.io_base = 0x2f8;
289 ns16550.irq = 3;
290 ns16550_init(1, &ns16550);
291 serial_init_preirq();
293 init_console();
295 /* Check that we have at least one Multiboot module. */
296 if ( !(mbi->flags & MBI_MODULES) || (mbi->mods_count == 0) )
297 {
298 printk("FATAL ERROR: dom0 kernel not specified."
299 " Check bootloader configuration.\n");
300 EARLY_FAIL();
301 }
303 if ( ((unsigned long)cpu0_stack & (STACK_SIZE-1)) != 0 )
304 {
305 printk("FATAL ERROR: Misaligned CPU0 stack.\n");
306 EARLY_FAIL();
307 }
309 xenheap_phys_end = opt_xenheap_megabytes << 20;
311 if ( mbi->flags & MBI_MEMMAP )
312 {
313 while ( bytes < mbi->mmap_length )
314 {
315 memory_map_t *map = __va(mbi->mmap_addr + bytes);
316 e820_raw[e820_raw_nr].addr =
317 ((u64)map->base_addr_high << 32) | (u64)map->base_addr_low;
318 e820_raw[e820_raw_nr].size =
319 ((u64)map->length_high << 32) | (u64)map->length_low;
320 e820_raw[e820_raw_nr].type =
321 (map->type > E820_SHARED_PAGE) ? E820_RESERVED : map->type;
322 e820_raw_nr++;
323 bytes += map->size + 4;
324 }
325 }
326 else if ( mbi->flags & MBI_MEMLIMITS )
327 {
328 e820_raw[0].addr = 0;
329 e820_raw[0].size = mbi->mem_lower << 10;
330 e820_raw[0].type = E820_RAM;
331 e820_raw[1].addr = 0x100000;
332 e820_raw[1].size = mbi->mem_upper << 10;
333 e820_raw[1].type = E820_RAM;
334 e820_raw_nr = 2;
335 }
336 else
337 {
338 printk("FATAL ERROR: Bootloader provided no memory information.\n");
339 for ( ; ; ) ;
340 }
342 max_page = init_e820(e820_raw, &e820_raw_nr);
344 modules_length = mod[mbi->mods_count-1].mod_end - mod[0].mod_start;
346 /* Find a large enough RAM extent to stash the DOM0 modules. */
347 for ( i = 0; ; i++ )
348 {
349 if ( i == e820.nr_map )
350 {
351 printk("Not enough memory to stash the DOM0 kernel image.\n");
352 for ( ; ; ) ;
353 }
355 if ( (e820.map[i].type == E820_RAM) &&
356 (e820.map[i].size >= modules_length) &&
357 ((e820.map[i].addr + e820.map[i].size) >=
358 (xenheap_phys_end + modules_length)) )
359 break;
360 }
362 /* Stash as near as possible to the beginning of the RAM extent. */
363 initial_images_start = e820.map[i].addr;
364 if ( initial_images_start < xenheap_phys_end )
365 initial_images_start = xenheap_phys_end;
366 initial_images_end = initial_images_start + modules_length;
368 #if defined(CONFIG_X86_32)
369 memmove((void *)initial_images_start, /* use low mapping */
370 (void *)mod[0].mod_start, /* use low mapping */
371 mod[mbi->mods_count-1].mod_end - mod[0].mod_start);
372 #elif defined(CONFIG_X86_64)
373 memmove(__va(initial_images_start),
374 __va(mod[0].mod_start),
375 mod[mbi->mods_count-1].mod_end - mod[0].mod_start);
376 #endif
378 /* Initialise boot-time allocator with all RAM situated after modules. */
379 xenheap_phys_start = init_boot_allocator(__pa(&_end));
380 nr_pages = 0;
381 for ( i = 0; i < e820.nr_map; i++ )
382 {
383 if ( e820.map[i].type != E820_RAM )
384 continue;
386 nr_pages += e820.map[i].size >> PAGE_SHIFT;
388 /* Initialise boot heap, skipping Xen heap and dom0 modules. */
389 s = e820.map[i].addr;
390 e = s + e820.map[i].size;
391 if ( s < xenheap_phys_end )
392 s = xenheap_phys_end;
393 if ( (s < initial_images_end) && (e > initial_images_start) )
394 s = initial_images_end;
395 init_boot_pages(s, e);
397 #if defined (CONFIG_X86_64)
398 /*
399 * x86/64 maps all registered RAM. Points to note:
400 * 1. The initial pagetable already maps low 64MB, so skip that.
401 * 2. We must map *only* RAM areas, taking care to avoid I/O holes.
402 * Failure to do this can cause coherency problems and deadlocks
403 * due to cache-attribute mismatches (e.g., AMD/AGP Linux bug).
404 */
405 {
406 /* Calculate page-frame range, discarding partial frames. */
407 unsigned long start, end;
408 start = PFN_UP(e820.map[i].addr);
409 end = PFN_DOWN(e820.map[i].addr + e820.map[i].size);
410 /* Clip the range to above 64MB. */
411 if ( end < (64UL << (20-PAGE_SHIFT)) )
412 continue;
413 if ( start < (64UL << (20-PAGE_SHIFT)) )
414 start = 64UL << (20-PAGE_SHIFT);
415 /* Request the mapping. */
416 map_pages_to_xen(
417 PAGE_OFFSET + (start << PAGE_SHIFT),
418 start, end-start, PAGE_HYPERVISOR);
419 }
420 #endif
421 }
423 memguard_init();
425 printk("System RAM: %luMB (%lukB)\n",
426 nr_pages >> (20 - PAGE_SHIFT),
427 nr_pages << (PAGE_SHIFT - 10));
428 total_pages = nr_pages;
430 /* Sanity check for unwanted bloat of dom0_op_t structure. */
431 BUG_ON(sizeof(((dom0_op_t *)0)->u) != sizeof(((dom0_op_t *)0)->u.pad));
433 BUG_ON(sizeof(start_info_t) > PAGE_SIZE);
434 BUG_ON(sizeof(shared_info_t) > PAGE_SIZE);
435 BUG_ON(sizeof(vcpu_info_t) != 64);
437 init_frametable();
439 end_boot_allocator();
441 /* Initialise the Xen heap, skipping RAM holes. */
442 nr_pages = 0;
443 for ( i = 0; i < e820.nr_map; i++ )
444 {
445 if ( e820.map[i].type != E820_RAM )
446 continue;
448 s = e820.map[i].addr;
449 e = s + e820.map[i].size;
450 if ( s < xenheap_phys_start )
451 s = xenheap_phys_start;
452 if ( e > xenheap_phys_end )
453 e = xenheap_phys_end;
455 if ( s < e )
456 {
457 nr_pages += (e - s) >> PAGE_SHIFT;
458 init_xenheap_pages(s, e);
459 }
460 }
462 printk("Xen heap: %luMB (%lukB)\n",
463 nr_pages >> (20 - PAGE_SHIFT),
464 nr_pages << (PAGE_SHIFT - 10));
466 early_boot = 0;
468 start_of_day();
470 grant_table_init();
472 shadow_mode_init();
474 /* initialize access control security module */
475 acm_init(&initrdidx, mbi, initial_images_start);
477 /* Create initial domain 0. */
478 dom0 = do_createdomain(0, 0);
479 if ( dom0 == NULL )
480 panic("Error creating domain 0\n");
482 set_bit(_DOMF_privileged, &dom0->domain_flags);
483 /* post-create hooks sets security label */
484 acm_post_domain0_create(dom0->domain_id);
486 /* Grab the DOM0 command line. */
487 cmdline = (char *)(mod[0].string ? __va(mod[0].string) : NULL);
488 if ( cmdline != NULL )
489 {
490 static char dom0_cmdline[MAX_GUEST_CMDLINE];
492 /* Skip past the image name and copy to a local buffer. */
493 while ( *cmdline == ' ' ) cmdline++;
494 if ( (cmdline = strchr(cmdline, ' ')) != NULL )
495 {
496 while ( *cmdline == ' ' ) cmdline++;
497 strcpy(dom0_cmdline, cmdline);
498 }
500 cmdline = dom0_cmdline;
502 /* Append any extra parameters. */
503 if ( skip_ioapic_setup && !strstr(cmdline, "noapic") )
504 strcat(cmdline, " noapic");
505 if ( acpi_skip_timer_override &&
506 !strstr(cmdline, "acpi_skip_timer_override") )
507 strcat(cmdline, " acpi_skip_timer_override");
508 if ( (strlen(acpi_param) != 0) && !strstr(cmdline, "acpi=") )
509 {
510 strcat(cmdline, " acpi=");
511 strcat(cmdline, acpi_param);
512 }
513 }
515 if ( (initrdidx > 0) && (initrdidx < mbi->mods_count) )
516 {
517 _initrd_start = initial_images_start +
518 (mod[initrdidx].mod_start - mod[0].mod_start);
519 _initrd_len = mod[initrdidx].mod_end - mod[initrdidx].mod_start;
520 }
522 /*
523 * We're going to setup domain0 using the module(s) that we stashed safely
524 * above our heap. The second module, if present, is an initrd ramdisk.
525 */
526 if ( construct_dom0(dom0,
527 initial_images_start,
528 mod[0].mod_end-mod[0].mod_start,
529 _initrd_start,
530 _initrd_len,
531 cmdline) != 0)
532 panic("Could not set up DOM0 guest OS\n");
534 /* Scrub RAM that is still free and so may go to an unprivileged domain. */
535 scrub_heap_pages();
537 init_trace_bufs();
539 /* Give up the VGA console if DOM0 is configured to grab it. */
540 console_endboot(cmdline && strstr(cmdline, "tty0"));
542 /* Hide UART from DOM0 if we're using it */
543 serial_endboot();
545 domain_unpause_by_systemcontroller(dom0);
547 startup_cpu_idle_loop();
548 }
550 void arch_get_xen_caps(xen_capabilities_info_t info)
551 {
552 char *p = info;
554 #if defined(CONFIG_X86_32) && !defined(CONFIG_X86_PAE)
556 p += sprintf(p, "xen-%d.%d-x86_32 ", XEN_VERSION, XEN_SUBVERSION);
557 if ( hvm_enabled )
558 p += sprintf(p, "hvm-%d.%d-x86_32 ", XEN_VERSION, XEN_SUBVERSION);
560 #elif defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
562 p += sprintf(p, "xen-%d.%d-x86_32p ", XEN_VERSION, XEN_SUBVERSION);
563 if ( hvm_enabled )
564 {
565 //p += sprintf(p, "hvm-%d.%d-x86_32 ", XEN_VERSION, XEN_SUBVERSION);
566 //p += sprintf(p, "hvm-%d.%d-x86_32p ", XEN_VERSION, XEN_SUBVERSION);
567 }
569 #elif defined(CONFIG_X86_64)
571 p += sprintf(p, "xen-%d.%d-x86_64 ", XEN_VERSION, XEN_SUBVERSION);
572 if ( hvm_enabled )
573 {
574 p += sprintf(p, "hvm-%d.%d-x86_32 ", XEN_VERSION, XEN_SUBVERSION);
575 //p += sprintf(p, "hvm-%d.%d-x86_32p ", XEN_VERSION, XEN_SUBVERSION);
576 p += sprintf(p, "hvm-%d.%d-x86_64 ", XEN_VERSION, XEN_SUBVERSION);
577 }
579 #else
581 p++;
583 #endif
585 *(p-1) = 0;
587 BUG_ON((p - info) > sizeof(xen_capabilities_info_t));
588 }
590 /*
591 * Local variables:
592 * mode: C
593 * c-set-style: "BSD"
594 * c-basic-offset: 4
595 * tab-width: 4
596 * indent-tabs-mode: nil
597 * End:
598 */