xen-vt-testing

view xen/arch/x86/setup.c @ 6705:a5e9a7fcade9

cleanups
author kaf24@firebug.cl.cam.ac.uk
date Fri Sep 09 16:17:17 2005 +0000 (2005-09-09)
parents ec4a3f2d060e
children 813c37b68376
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 ac_timer_init(void);
82 extern void initialize_keytable(void);
83 extern void early_cpu_init(void);
85 extern unsigned long cpu0_stack[];
87 struct cpuinfo_x86 boot_cpu_data = { 0, 0, 0, 0, -1, 1, 0, 0, -1 };
89 #if CONFIG_PAGING_LEVELS > 2
90 unsigned long mmu_cr4_features = X86_CR4_PSE | X86_CR4_PGE | X86_CR4_PAE;
91 #else
92 unsigned long mmu_cr4_features = X86_CR4_PSE;
93 #endif
94 EXPORT_SYMBOL(mmu_cr4_features);
96 struct vcpu *idle_task[NR_CPUS] = { &idle0_vcpu };
98 int acpi_disabled;
100 int acpi_force;
101 char acpi_param[10] = "";
102 static void parse_acpi_param(char *s)
103 {
104 /* Save the parameter so it can be propagated to domain0. */
105 strncpy(acpi_param, s, sizeof(acpi_param));
106 acpi_param[sizeof(acpi_param)-1] = '\0';
108 /* Interpret the parameter for use within Xen. */
109 if ( !strcmp(s, "off") )
110 {
111 disable_acpi();
112 }
113 else if ( !strcmp(s, "force") )
114 {
115 acpi_force = 1;
116 acpi_ht = 1;
117 acpi_disabled = 0;
118 }
119 else if ( !strcmp(s, "strict") )
120 {
121 acpi_strict = 1;
122 }
123 else if ( !strcmp(s, "ht") )
124 {
125 if ( !acpi_force )
126 disable_acpi();
127 acpi_ht = 1;
128 }
129 else if ( !strcmp(s, "noirq") )
130 {
131 acpi_noirq_set();
132 }
133 }
135 static void __init do_initcalls(void)
136 {
137 initcall_t *call;
138 for ( call = &__initcall_start; call < &__initcall_end; call++ )
139 (*call)();
140 }
142 static void __init start_of_day(void)
143 {
144 int i;
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 /* Map default GDT into their final position in the idle page table. */
163 map_pages_to_xen(
164 GDT_VIRT_START(current) + FIRST_RESERVED_GDT_BYTE,
165 virt_to_phys(gdt_table) >> PAGE_SHIFT, 1, PAGE_HYPERVISOR);
167 find_smp_config();
169 smp_alloc_memory();
171 dmi_scan_machine();
173 generic_apic_probe();
175 acpi_boot_table_init();
176 acpi_boot_init();
178 if ( smp_found_config )
179 get_smp_config();
181 init_apic_mappings();
183 init_IRQ();
185 trap_init();
187 ac_timer_init();
189 early_time_init();
191 arch_init_memory();
193 scheduler_init();
195 identify_cpu(&boot_cpu_data);
196 if ( cpu_has_fxsr )
197 set_in_cr4(X86_CR4_OSFXSR);
198 if ( cpu_has_xmm )
199 set_in_cr4(X86_CR4_OSXMMEXCPT);
201 if ( opt_nosmp )
202 {
203 max_cpus = 0;
204 smp_num_siblings = 1;
205 boot_cpu_data.x86_num_cores = 1;
206 }
208 smp_prepare_cpus(max_cpus);
210 /* We aren't hotplug-capable yet. */
211 BUG_ON(!cpus_empty(cpu_present_map));
212 for_each_cpu ( i )
213 cpu_set(i, cpu_present_map);
215 /*
216 * Initialise higher-level timer functions. We do this fairly late
217 * (post-SMP) because the time bases and scale factors need to be updated
218 * regularly, and SMP initialisation can cause a long delay with
219 * interrupts not yet enabled.
220 */
221 init_xen_time();
223 initialize_keytable();
225 serial_init_postirq();
227 BUG_ON(!local_irq_is_enabled());
229 for_each_present_cpu ( i )
230 {
231 if ( num_online_cpus() >= max_cpus )
232 break;
233 if ( !cpu_online(i) )
234 __cpu_up(i);
235 }
237 printk("Brought up %ld CPUs\n", (long)num_online_cpus());
238 smp_cpus_done(max_cpus);
240 do_initcalls();
242 schedulers_start();
244 watchdog_enable();
245 }
247 #define EARLY_FAIL() for ( ; ; ) __asm__ __volatile__ ( "hlt" )
249 static struct e820entry e820_raw[E820MAX];
251 void __init __start_xen(multiboot_info_t *mbi)
252 {
253 char *cmdline;
254 module_t *mod = (module_t *)__va(mbi->mods_addr);
255 unsigned long nr_pages, modules_length;
256 unsigned long initial_images_start, initial_images_end;
257 unsigned long _initrd_start = 0, _initrd_len = 0;
258 unsigned int initrdidx = 1;
259 physaddr_t s, e;
260 int i, e820_raw_nr = 0, bytes = 0;
261 struct ns16550_defaults ns16550 = {
262 .data_bits = 8,
263 .parity = 'n',
264 .stop_bits = 1
265 };
267 /* Parse the command-line options. */
268 if ( (mbi->flags & MBI_CMDLINE) && (mbi->cmdline != 0) )
269 cmdline_parse(__va(mbi->cmdline));
271 /* Must do this early -- e.g., spinlocks rely on get_current(). */
272 set_current(&idle0_vcpu);
273 set_processor_id(0);
275 smp_prepare_boot_cpu();
277 /* We initialise the serial devices very early so we can get debugging. */
278 ns16550.io_base = 0x3f8;
279 ns16550.irq = 4;
280 ns16550_init(0, &ns16550);
281 ns16550.io_base = 0x2f8;
282 ns16550.irq = 3;
283 ns16550_init(1, &ns16550);
284 serial_init_preirq();
286 init_console();
288 /* Check that we have at least one Multiboot module. */
289 if ( !(mbi->flags & MBI_MODULES) || (mbi->mods_count == 0) )
290 {
291 printk("FATAL ERROR: dom0 kernel not specified."
292 " Check bootloader configuration.\n");
293 EARLY_FAIL();
294 }
296 if ( ((unsigned long)cpu0_stack & (STACK_SIZE-1)) != 0 )
297 {
298 printk("FATAL ERROR: Misaligned CPU0 stack.\n");
299 EARLY_FAIL();
300 }
302 xenheap_phys_end = opt_xenheap_megabytes << 20;
304 if ( mbi->flags & MBI_MEMMAP )
305 {
306 while ( bytes < mbi->mmap_length )
307 {
308 memory_map_t *map = __va(mbi->mmap_addr + bytes);
309 e820_raw[e820_raw_nr].addr =
310 ((u64)map->base_addr_high << 32) | (u64)map->base_addr_low;
311 e820_raw[e820_raw_nr].size =
312 ((u64)map->length_high << 32) | (u64)map->length_low;
313 e820_raw[e820_raw_nr].type =
314 (map->type > E820_SHARED_PAGE) ? E820_RESERVED : map->type;
315 e820_raw_nr++;
316 bytes += map->size + 4;
317 }
318 }
319 else if ( mbi->flags & MBI_MEMLIMITS )
320 {
321 e820_raw[0].addr = 0;
322 e820_raw[0].size = mbi->mem_lower << 10;
323 e820_raw[0].type = E820_RAM;
324 e820_raw[1].addr = 0x100000;
325 e820_raw[1].size = mbi->mem_upper << 10;
326 e820_raw[1].type = E820_RAM;
327 e820_raw_nr = 2;
328 }
329 else
330 {
331 printk("FATAL ERROR: Bootloader provided no memory information.\n");
332 for ( ; ; ) ;
333 }
335 max_page = init_e820(e820_raw, &e820_raw_nr);
337 modules_length = mod[mbi->mods_count-1].mod_end - mod[0].mod_start;
339 /* Find a large enough RAM extent to stash the DOM0 modules. */
340 for ( i = 0; ; i++ )
341 {
342 if ( i == e820.nr_map )
343 {
344 printk("Not enough memory to stash the DOM0 kernel image.\n");
345 for ( ; ; ) ;
346 }
348 if ( (e820.map[i].type == E820_RAM) &&
349 (e820.map[i].size >= modules_length) &&
350 ((e820.map[i].addr + e820.map[i].size) >=
351 (xenheap_phys_end + modules_length)) )
352 break;
353 }
355 /* Stash as near as possible to the beginning of the RAM extent. */
356 initial_images_start = e820.map[i].addr;
357 if ( initial_images_start < xenheap_phys_end )
358 initial_images_start = xenheap_phys_end;
359 initial_images_end = initial_images_start + modules_length;
361 #if defined(CONFIG_X86_32)
362 memmove((void *)initial_images_start, /* use low mapping */
363 (void *)mod[0].mod_start, /* use low mapping */
364 mod[mbi->mods_count-1].mod_end - mod[0].mod_start);
365 #elif defined(CONFIG_X86_64)
366 memmove(__va(initial_images_start),
367 __va(mod[0].mod_start),
368 mod[mbi->mods_count-1].mod_end - mod[0].mod_start);
369 #endif
371 /* Initialise boot-time allocator with all RAM situated after modules. */
372 xenheap_phys_start = init_boot_allocator(__pa(&_end));
373 nr_pages = 0;
374 for ( i = 0; i < e820.nr_map; i++ )
375 {
376 if ( e820.map[i].type != E820_RAM )
377 continue;
379 nr_pages += e820.map[i].size >> PAGE_SHIFT;
381 /* Initialise boot heap, skipping Xen heap and dom0 modules. */
382 s = e820.map[i].addr;
383 e = s + e820.map[i].size;
384 if ( s < xenheap_phys_end )
385 s = xenheap_phys_end;
386 if ( (s < initial_images_end) && (e > initial_images_start) )
387 s = initial_images_end;
388 init_boot_pages(s, e);
390 #if defined (CONFIG_X86_64)
391 /*
392 * x86/64 maps all registered RAM. Points to note:
393 * 1. The initial pagetable already maps low 64MB, so skip that.
394 * 2. We must map *only* RAM areas, taking care to avoid I/O holes.
395 * Failure to do this can cause coherency problems and deadlocks
396 * due to cache-attribute mismatches (e.g., AMD/AGP Linux bug).
397 */
398 {
399 /* Calculate page-frame range, discarding partial frames. */
400 unsigned long start, end;
401 start = PFN_UP(e820.map[i].addr);
402 end = PFN_DOWN(e820.map[i].addr + e820.map[i].size);
403 /* Clip the range to above 64MB. */
404 if ( end < (64UL << (20-PAGE_SHIFT)) )
405 continue;
406 if ( start < (64UL << (20-PAGE_SHIFT)) )
407 start = 64UL << (20-PAGE_SHIFT);
408 /* Request the mapping. */
409 map_pages_to_xen(
410 PAGE_OFFSET + (start << PAGE_SHIFT),
411 start, end-start, PAGE_HYPERVISOR);
412 }
413 #endif
414 }
416 memguard_init();
418 printk("System RAM: %luMB (%lukB)\n",
419 nr_pages >> (20 - PAGE_SHIFT),
420 nr_pages << (PAGE_SHIFT - 10));
422 init_frametable();
424 end_boot_allocator();
426 /* Initialise the Xen heap, skipping RAM holes. */
427 nr_pages = 0;
428 for ( i = 0; i < e820.nr_map; i++ )
429 {
430 if ( e820.map[i].type != E820_RAM )
431 continue;
433 s = e820.map[i].addr;
434 e = s + e820.map[i].size;
435 if ( s < xenheap_phys_start )
436 s = xenheap_phys_start;
437 if ( e > xenheap_phys_end )
438 e = xenheap_phys_end;
440 if ( s < e )
441 {
442 nr_pages += (e - s) >> PAGE_SHIFT;
443 init_xenheap_pages(s, e);
444 }
445 }
447 printk("Xen heap: %luMB (%lukB)\n",
448 nr_pages >> (20 - PAGE_SHIFT),
449 nr_pages << (PAGE_SHIFT - 10));
451 early_boot = 0;
453 start_of_day();
455 grant_table_init();
457 shadow_mode_init();
459 /* initialize access control security module */
460 acm_init(&initrdidx, mbi, initial_images_start);
462 /* Create initial domain 0. */
463 dom0 = do_createdomain(0, 0);
464 if ( dom0 == NULL )
465 panic("Error creating domain 0\n");
467 set_bit(_DOMF_privileged, &dom0->domain_flags);
468 /* post-create hooks sets security label */
469 acm_post_domain0_create(dom0->domain_id);
471 /* Grab the DOM0 command line. */
472 cmdline = (char *)(mod[0].string ? __va(mod[0].string) : NULL);
473 if ( cmdline != NULL )
474 {
475 static char dom0_cmdline[MAX_GUEST_CMDLINE];
477 /* Skip past the image name. */
478 while ( *cmdline == ' ' ) cmdline++;
479 if ( (cmdline = strchr(cmdline, ' ')) != NULL )
480 while ( *cmdline == ' ' ) cmdline++;
482 /* Copy the command line to a local buffer. */
483 strcpy(dom0_cmdline, cmdline);
484 cmdline = dom0_cmdline;
486 /* Append any extra parameters. */
487 if ( skip_ioapic_setup && !strstr(cmdline, "noapic") )
488 strcat(cmdline, " noapic");
489 if ( acpi_skip_timer_override &&
490 !strstr(cmdline, "acpi_skip_timer_override") )
491 strcat(cmdline, " acpi_skip_timer_override");
492 if ( (strlen(acpi_param) != 0) && !strstr(cmdline, "acpi=") )
493 {
494 strcat(cmdline, " acpi=");
495 strcat(cmdline, acpi_param);
496 }
497 }
499 if ( (initrdidx > 0) && (initrdidx < mbi->mods_count) )
500 {
501 _initrd_start = initial_images_start +
502 (mod[initrdidx].mod_start - mod[0].mod_start);
503 _initrd_len = mod[initrdidx].mod_end - mod[initrdidx].mod_start;
504 }
506 /*
507 * We're going to setup domain0 using the module(s) that we stashed safely
508 * above our heap. The second module, if present, is an initrd ramdisk.
509 */
510 if ( construct_dom0(dom0,
511 initial_images_start,
512 mod[0].mod_end-mod[0].mod_start,
513 _initrd_start,
514 _initrd_len,
515 cmdline) != 0)
516 panic("Could not set up DOM0 guest OS\n");
518 /* Scrub RAM that is still free and so may go to an unprivileged domain. */
519 scrub_heap_pages();
521 init_trace_bufs();
523 /* Give up the VGA console if DOM0 is configured to grab it. */
524 console_endboot(cmdline && strstr(cmdline, "tty0"));
526 /* Hide UART from DOM0 if we're using it */
527 serial_endboot();
529 domain_unpause_by_systemcontroller(dom0);
531 startup_cpu_idle_loop();
532 }
534 void arch_get_xen_caps(xen_capabilities_info_t info)
535 {
536 char *p = info;
538 #if defined(CONFIG_X86_32) && !defined(CONFIG_X86_PAE)
540 p += sprintf(p, "xen_%d.%d_x86_32 ", XEN_VERSION, XEN_SUBVERSION);
541 if ( hvm_enabled )
542 p += sprintf(p, "hvm_%d.%d_x86_32 ", XEN_VERSION, XEN_SUBVERSION);
544 #elif defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
546 p += sprintf(p, "xen_%d.%d_x86_32p ", XEN_VERSION, XEN_SUBVERSION);
547 if ( hvm_enabled )
548 {
549 //p += sprintf(p, "hvm_%d.%d_x86_32 ", XEN_VERSION, XEN_SUBVERSION);
550 //p += sprintf(p, "hvm_%d.%d_x86_32p ", XEN_VERSION, XEN_SUBVERSION);
551 }
553 #elif defined(CONFIG_X86_64)
555 p += sprintf(p, "xen_%d.%d_x86_64 ", XEN_VERSION, XEN_SUBVERSION);
556 if ( hvm_enabled )
557 {
558 //p += sprintf(p, "hvm_%d.%d_x86_32 ", XEN_VERSION, XEN_SUBVERSION);
559 //p += sprintf(p, "hvm_%d.%d_x86_32p ", XEN_VERSION, XEN_SUBVERSION);
560 p += sprintf(p, "hvm_%d.%d_x86_64 ", XEN_VERSION, XEN_SUBVERSION);
561 }
563 #else
565 p++;
567 #endif
569 *(p-1) = 0;
571 BUG_ON((p - info) > sizeof(info));
572 }
574 /*
575 * Local variables:
576 * mode: C
577 * c-set-style: "BSD"
578 * c-basic-offset: 4
579 * tab-width: 4
580 * indent-tabs-mode: nil
581 * End:
582 */