ia64/xen-unstable

view xen/arch/x86/setup.c @ 7221:e643fccb851b

Handle the case where there are no spaces or parameters
after the image name on the command line.

Signed-off-by: Mike Day <mdday@us.ibm.com>
author kaf24@firebug.cl.cam.ac.uk
date Wed Oct 05 14:10:49 2005 +0100 (2005-10-05)
parents 8be702637183
children bd3268de4145
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));
421 total_pages = nr_pages;
423 init_frametable();
425 end_boot_allocator();
427 /* Initialise the Xen heap, skipping RAM holes. */
428 nr_pages = 0;
429 for ( i = 0; i < e820.nr_map; i++ )
430 {
431 if ( e820.map[i].type != E820_RAM )
432 continue;
434 s = e820.map[i].addr;
435 e = s + e820.map[i].size;
436 if ( s < xenheap_phys_start )
437 s = xenheap_phys_start;
438 if ( e > xenheap_phys_end )
439 e = xenheap_phys_end;
441 if ( s < e )
442 {
443 nr_pages += (e - s) >> PAGE_SHIFT;
444 init_xenheap_pages(s, e);
445 }
446 }
448 printk("Xen heap: %luMB (%lukB)\n",
449 nr_pages >> (20 - PAGE_SHIFT),
450 nr_pages << (PAGE_SHIFT - 10));
452 early_boot = 0;
454 start_of_day();
456 grant_table_init();
458 shadow_mode_init();
460 /* initialize access control security module */
461 acm_init(&initrdidx, mbi, initial_images_start);
463 /* Create initial domain 0. */
464 dom0 = do_createdomain(0, 0);
465 if ( dom0 == NULL )
466 panic("Error creating domain 0\n");
468 set_bit(_DOMF_privileged, &dom0->domain_flags);
469 /* post-create hooks sets security label */
470 acm_post_domain0_create(dom0->domain_id);
472 /* Grab the DOM0 command line. */
473 cmdline = (char *)(mod[0].string ? __va(mod[0].string) : NULL);
474 if ( cmdline != NULL )
475 {
476 static char dom0_cmdline[MAX_GUEST_CMDLINE];
478 /* Skip past the image name and copy to a local buffer. */
479 while ( *cmdline == ' ' ) cmdline++;
480 if ( (cmdline = strchr(cmdline, ' ')) != NULL )
481 {
482 while ( *cmdline == ' ' ) cmdline++;
483 strcpy(dom0_cmdline, cmdline);
484 }
486 cmdline = dom0_cmdline;
488 /* Append any extra parameters. */
489 if ( skip_ioapic_setup && !strstr(cmdline, "noapic") )
490 strcat(cmdline, " noapic");
491 if ( acpi_skip_timer_override &&
492 !strstr(cmdline, "acpi_skip_timer_override") )
493 strcat(cmdline, " acpi_skip_timer_override");
494 if ( (strlen(acpi_param) != 0) && !strstr(cmdline, "acpi=") )
495 {
496 strcat(cmdline, " acpi=");
497 strcat(cmdline, acpi_param);
498 }
499 }
501 if ( (initrdidx > 0) && (initrdidx < mbi->mods_count) )
502 {
503 _initrd_start = initial_images_start +
504 (mod[initrdidx].mod_start - mod[0].mod_start);
505 _initrd_len = mod[initrdidx].mod_end - mod[initrdidx].mod_start;
506 }
508 /*
509 * We're going to setup domain0 using the module(s) that we stashed safely
510 * above our heap. The second module, if present, is an initrd ramdisk.
511 */
512 if ( construct_dom0(dom0,
513 initial_images_start,
514 mod[0].mod_end-mod[0].mod_start,
515 _initrd_start,
516 _initrd_len,
517 cmdline) != 0)
518 panic("Could not set up DOM0 guest OS\n");
520 /* Scrub RAM that is still free and so may go to an unprivileged domain. */
521 scrub_heap_pages();
523 init_trace_bufs();
525 /* Give up the VGA console if DOM0 is configured to grab it. */
526 console_endboot(cmdline && strstr(cmdline, "tty0"));
528 /* Hide UART from DOM0 if we're using it */
529 serial_endboot();
531 domain_unpause_by_systemcontroller(dom0);
533 startup_cpu_idle_loop();
534 }
536 void arch_get_xen_caps(xen_capabilities_info_t info)
537 {
538 char *p = info;
540 #if defined(CONFIG_X86_32) && !defined(CONFIG_X86_PAE)
542 p += sprintf(p, "xen_%d.%d_x86_32 ", XEN_VERSION, XEN_SUBVERSION);
543 if ( hvm_enabled )
544 p += sprintf(p, "hvm_%d.%d_x86_32 ", XEN_VERSION, XEN_SUBVERSION);
546 #elif defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
548 p += sprintf(p, "xen_%d.%d_x86_32p ", XEN_VERSION, XEN_SUBVERSION);
549 if ( hvm_enabled )
550 {
551 //p += sprintf(p, "hvm_%d.%d_x86_32 ", XEN_VERSION, XEN_SUBVERSION);
552 //p += sprintf(p, "hvm_%d.%d_x86_32p ", XEN_VERSION, XEN_SUBVERSION);
553 }
555 #elif defined(CONFIG_X86_64)
557 p += sprintf(p, "xen_%d.%d_x86_64 ", XEN_VERSION, XEN_SUBVERSION);
558 if ( hvm_enabled )
559 {
560 //p += sprintf(p, "hvm_%d.%d_x86_32 ", XEN_VERSION, XEN_SUBVERSION);
561 //p += sprintf(p, "hvm_%d.%d_x86_32p ", XEN_VERSION, XEN_SUBVERSION);
562 p += sprintf(p, "hvm_%d.%d_x86_64 ", XEN_VERSION, XEN_SUBVERSION);
563 }
565 #else
567 p++;
569 #endif
571 *(p-1) = 0;
573 BUG_ON((p - info) > sizeof(xen_capabilities_info_t));
574 }
576 /*
577 * Local variables:
578 * mode: C
579 * c-set-style: "BSD"
580 * c-basic-offset: 4
581 * tab-width: 4
582 * indent-tabs-mode: nil
583 * End:
584 */