debuggers.hg

view xen/arch/x86/setup.c @ 22906:700ac6445812

Now add KDB to the non-kdb tree
author Mukesh Rathor
date Thu Feb 03 15:42:41 2011 -0800 (2011-02-03)
parents ff97273750b8
children
line source
1 #include <xen/config.h>
2 #include <xen/init.h>
3 #include <xen/lib.h>
4 #include <xen/sched.h>
5 #include <xen/sched-if.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/version.h>
16 #include <xen/gdbstub.h>
17 #include <xen/percpu.h>
18 #include <xen/hypercall.h>
19 #include <xen/keyhandler.h>
20 #include <xen/numa.h>
21 #include <xen/rcupdate.h>
22 #include <xen/vga.h>
23 #include <xen/dmi.h>
24 #include <xen/nodemask.h>
25 #include <public/version.h>
26 #ifdef CONFIG_COMPAT
27 #include <compat/platform.h>
28 #include <compat/xen.h>
29 #endif
30 #include <asm/bitops.h>
31 #include <asm/smp.h>
32 #include <asm/processor.h>
33 #include <asm/mpspec.h>
34 #include <asm/apic.h>
35 #include <asm/desc.h>
36 #include <asm/paging.h>
37 #include <asm/e820.h>
38 #include <xsm/acm/acm_hooks.h>
39 #include <xen/kexec.h>
40 #include <asm/edd.h>
41 #include <xsm/xsm.h>
42 #include <asm/tboot.h>
43 #include <asm/bzimage.h> /* for bzimage_headroom */
44 #include <asm/mach-generic/mach_apic.h> /* for generic_apic_probe */
45 #include <asm/setup.h>
46 #include <xen/cpu.h>
48 #ifdef XEN_KDB_CONFIG
49 #include <asm/debugger.h>
51 int opt_earlykdb=0;
52 boolean_param("earlykdb", opt_earlykdb);
53 #endif
55 extern u16 boot_edid_caps;
56 extern u8 boot_edid_info[128];
57 extern struct boot_video_info boot_vid_info;
59 /* opt_nosmp: If true, secondary processors are ignored. */
60 static bool_t __initdata opt_nosmp;
61 boolean_param("nosmp", opt_nosmp);
63 /* maxcpus: maximum number of CPUs to activate. */
64 static unsigned int __initdata max_cpus = NR_CPUS;
65 integer_param("maxcpus", max_cpus);
67 /* opt_watchdog: If true, run a watchdog NMI on each processor. */
68 static bool_t __initdata opt_watchdog;
69 boolean_param("watchdog", opt_watchdog);
71 /* **** Linux config option: propagated to domain0. */
72 /* "acpi=off": Sisables both ACPI table parsing and interpreter. */
73 /* "acpi=force": Override the disable blacklist. */
74 /* "acpi=strict": Disables out-of-spec workarounds. */
75 /* "acpi=ht": Limit ACPI just to boot-time to enable HT. */
76 /* "acpi=noirq": Disables ACPI interrupt routing. */
77 static void parse_acpi_param(char *s);
78 custom_param("acpi", parse_acpi_param);
80 /* **** Linux config option: propagated to domain0. */
81 /* acpi_skip_timer_override: Skip IRQ0 overrides. */
82 boolean_param("acpi_skip_timer_override", acpi_skip_timer_override);
84 /* **** Linux config option: propagated to domain0. */
85 /* noapic: Disable IOAPIC setup. */
86 boolean_param("noapic", skip_ioapic_setup);
88 /* **** Linux config option: propagated to domain0. */
89 /* xen_cpuidle: xen control cstate. */
90 s8 __read_mostly xen_cpuidle = -1;
91 boolean_param("cpuidle", xen_cpuidle);
93 bool_t __read_mostly early_boot = 1;
95 cpumask_t __read_mostly cpu_present_map;
97 unsigned long __read_mostly xen_phys_start;
99 #ifdef CONFIG_X86_32
100 /* Limits of Xen heap, used to initialise the allocator. */
101 unsigned long __initdata xenheap_initial_phys_start;
102 unsigned long __read_mostly xenheap_phys_end;
103 #endif
105 DEFINE_PER_CPU(struct tss_struct, init_tss);
107 char __attribute__ ((__section__(".bss.stack_aligned"))) cpu0_stack[STACK_SIZE];
109 struct cpuinfo_x86 __read_mostly boot_cpu_data = { 0, 0, 0, 0, -1 };
111 unsigned long __read_mostly mmu_cr4_features = X86_CR4_PSE | X86_CR4_PGE | X86_CR4_PAE;
113 bool_t __initdata acpi_disabled;
114 bool_t __initdata acpi_force;
115 static char __initdata acpi_param[10] = "";
116 static void __init parse_acpi_param(char *s)
117 {
118 /* Save the parameter so it can be propagated to domain0. */
119 safe_strcpy(acpi_param, s);
121 /* Interpret the parameter for use within Xen. */
122 if ( !parse_bool(s) )
123 {
124 disable_acpi();
125 }
126 else if ( !strcmp(s, "force") )
127 {
128 acpi_force = 1;
129 acpi_ht = 1;
130 acpi_disabled = 0;
131 }
132 else if ( !strcmp(s, "ht") )
133 {
134 if ( !acpi_force )
135 disable_acpi();
136 acpi_ht = 1;
137 }
138 else if ( !strcmp(s, "noirq") )
139 {
140 acpi_noirq_set();
141 }
142 }
144 #define EARLY_FAIL(f, a...) do { \
145 printk( f , ## a ); \
146 for ( ; ; ) halt(); \
147 } while (0)
149 static const module_t *__initdata initial_images;
150 static unsigned int __initdata nr_initial_images;
152 unsigned long __init initial_images_nrpages(void)
153 {
154 unsigned long nr;
155 unsigned int i;
157 for ( nr = i = 0; i < nr_initial_images; ++i )
158 nr += PFN_UP(initial_images[i].mod_end);
160 return nr;
161 }
163 void __init discard_initial_images(void)
164 {
165 unsigned int i;
167 for ( i = 0; i < nr_initial_images; ++i )
168 {
169 uint64_t start = (uint64_t)initial_images[i].mod_start << PAGE_SHIFT;
171 init_domheap_pages(start,
172 start + PAGE_ALIGN(initial_images[i].mod_end));
173 }
175 nr_initial_images = 0;
176 initial_images = NULL;
177 }
179 static void free_xen_data(char *s, char *e)
180 {
181 #ifndef MEMORY_GUARD
182 init_xenheap_pages(__pa(s), __pa(e));
183 #endif
184 memguard_guard_range(s, e-s);
185 #if defined(CONFIG_X86_64)
186 /* Also zap the mapping in the 1:1 area. */
187 memguard_guard_range(__va(__pa(s)), e-s);
188 #endif
189 }
191 extern char __init_begin[], __init_end[], __bss_start[];
193 static void __init init_idle_domain(void)
194 {
195 scheduler_init();
196 set_current(idle_vcpu[0]);
197 this_cpu(curr_vcpu) = current;
198 setup_idle_pagetable();
199 }
201 void __devinit srat_detect_node(int cpu)
202 {
203 unsigned node;
204 u32 apicid = x86_cpu_to_apicid[cpu];
206 node = apicid_to_node[apicid];
207 if ( node == NUMA_NO_NODE || !node_online(node) )
208 node = 0;
209 numa_set_node(cpu, node);
211 if ( opt_cpu_info && acpi_numa > 0 )
212 printk("CPU %d APIC %d -> Node %d\n", cpu, apicid, node);
213 }
215 /*
216 * Sort CPUs by <node,package,core,thread> tuple. Fortunately this hierarchy is
217 * reflected in the structure of modern APIC identifiers, so we sort based on
218 * those. This is slightly complicated by the fact that the BSP must remain
219 * CPU 0. Hence we do a variation on longest-prefix matching to do the best we
220 * can while keeping CPU 0 static.
221 */
222 static void __init normalise_cpu_order(void)
223 {
224 unsigned int i, j, min_cpu;
225 uint32_t apicid, diff, min_diff;
227 for_each_present_cpu ( i )
228 {
229 apicid = x86_cpu_to_apicid[i];
230 min_diff = min_cpu = ~0u;
232 /*
233 * Find remaining CPU with longest-prefix match on APIC ID.
234 * Among identical longest-prefix matches, pick the smallest APIC ID.
235 */
236 for ( j = next_cpu(i, cpu_present_map);
237 j < NR_CPUS;
238 j = next_cpu(j, cpu_present_map) )
239 {
240 diff = x86_cpu_to_apicid[j] ^ apicid;
241 while ( diff & (diff-1) )
242 diff &= diff-1;
243 if ( (diff < min_diff) ||
244 ((diff == min_diff) &&
245 (x86_cpu_to_apicid[j] < x86_cpu_to_apicid[min_cpu])) )
246 {
247 min_diff = diff;
248 min_cpu = j;
249 }
250 }
252 /* If no match then there must be no CPUs remaining to consider. */
253 if ( min_cpu >= NR_CPUS )
254 {
255 BUG_ON(next_cpu(i, cpu_present_map) < NR_CPUS);
256 break;
257 }
259 /* Switch the best-matching CPU with the next CPU in logical order. */
260 j = next_cpu(i, cpu_present_map);
261 apicid = x86_cpu_to_apicid[min_cpu];
262 x86_cpu_to_apicid[min_cpu] = x86_cpu_to_apicid[j];
263 x86_cpu_to_apicid[j] = apicid;
264 }
265 }
267 #define BOOTSTRAP_MAP_BASE (16UL << 20)
268 #define BOOTSTRAP_MAP_LIMIT (1UL << L3_PAGETABLE_SHIFT)
270 /*
271 * Ensure a given physical memory range is present in the bootstrap mappings.
272 * Use superpage mappings to ensure that pagetable memory needn't be allocated.
273 */
274 static void *__init bootstrap_map(const module_t *mod)
275 {
276 static unsigned long __initdata map_cur = BOOTSTRAP_MAP_BASE;
277 uint64_t start, end, mask = (1L << L2_PAGETABLE_SHIFT) - 1;
278 void *ret;
280 #ifdef __x86_64__
281 if ( !early_boot )
282 return mod ? mfn_to_virt(mod->mod_start) : NULL;
283 #endif
285 if ( !mod )
286 {
287 destroy_xen_mappings(BOOTSTRAP_MAP_BASE, BOOTSTRAP_MAP_LIMIT);
288 map_cur = BOOTSTRAP_MAP_BASE;
289 return NULL;
290 }
292 start = (uint64_t)mod->mod_start << PAGE_SHIFT;
293 end = start + mod->mod_end;
294 if ( start >= end )
295 return NULL;
297 if ( end <= BOOTSTRAP_MAP_BASE )
298 return (void *)(unsigned long)start;
300 ret = (void *)(map_cur + (unsigned long)(start & mask));
301 start &= ~mask;
302 end = (end + mask) & ~mask;
303 if ( end - start > BOOTSTRAP_MAP_LIMIT - map_cur )
304 return NULL;
306 map_pages_to_xen(map_cur, start >> PAGE_SHIFT,
307 (end - start) >> PAGE_SHIFT, PAGE_HYPERVISOR);
308 map_cur += end - start;
309 return ret;
310 }
312 static void *__init move_memory(
313 uint64_t dst, uint64_t src, unsigned int size, bool_t keep)
314 {
315 unsigned int blksz = BOOTSTRAP_MAP_LIMIT - BOOTSTRAP_MAP_BASE;
316 unsigned int mask = (1L << L2_PAGETABLE_SHIFT) - 1;
318 if ( src + size > BOOTSTRAP_MAP_BASE )
319 blksz >>= 1;
321 while ( size )
322 {
323 module_t mod;
324 unsigned int soffs = src & mask;
325 unsigned int doffs = dst & mask;
326 unsigned int sz;
327 void *d, *s;
329 mod.mod_start = (src - soffs) >> PAGE_SHIFT;
330 mod.mod_end = soffs + size;
331 if ( mod.mod_end > blksz )
332 mod.mod_end = blksz;
333 sz = mod.mod_end - soffs;
334 s = bootstrap_map(&mod);
336 mod.mod_start = (dst - doffs) >> PAGE_SHIFT;
337 mod.mod_end = doffs + size;
338 if ( mod.mod_end > blksz )
339 mod.mod_end = blksz;
340 if ( sz > mod.mod_end - doffs )
341 sz = mod.mod_end - doffs;
342 d = bootstrap_map(&mod);
344 memmove(d + doffs, s + soffs, sz);
346 dst += sz;
347 src += sz;
348 size -= sz;
350 if ( keep )
351 return size ? NULL : d + doffs;
353 bootstrap_map(NULL);
354 }
356 return NULL;
357 }
359 static uint64_t __init consider_modules(
360 uint64_t s, uint64_t e, uint32_t size, const module_t *mod,
361 unsigned int nr_mods, unsigned int this_mod)
362 {
363 unsigned int i;
365 if ( s > e || e - s < size )
366 return 0;
368 for ( i = 0; i < nr_mods ; ++i )
369 {
370 uint64_t start = (uint64_t)mod[i].mod_start << PAGE_SHIFT;
371 uint64_t end = start + PAGE_ALIGN(mod[i].mod_end);
373 if ( i == this_mod )
374 continue;
376 if ( s < end && start < e )
377 {
378 end = consider_modules(end, e, size, mod + i + 1,
379 nr_mods - i - 1, this_mod - i - 1);
380 if ( end )
381 return end;
383 return consider_modules(s, start, size, mod + i + 1,
384 nr_mods - i - 1, this_mod - i - 1);
385 }
386 }
388 return e;
389 }
391 static void __init setup_max_pdx(void)
392 {
393 #ifdef __x86_64__
394 max_pdx = pfn_to_pdx(max_page - 1) + 1;
396 if ( max_pdx > (DIRECTMAP_SIZE >> PAGE_SHIFT) )
397 max_pdx = DIRECTMAP_SIZE >> PAGE_SHIFT;
399 if ( max_pdx > FRAMETABLE_SIZE / sizeof(*frame_table) )
400 max_pdx = FRAMETABLE_SIZE / sizeof(*frame_table);
402 max_page = pdx_to_pfn(max_pdx - 1) + 1;
403 #endif
404 }
406 void set_pdx_range(unsigned long smfn, unsigned long emfn)
407 {
408 unsigned long idx, eidx;
410 idx = pfn_to_pdx(smfn) / PDX_GROUP_COUNT;
411 eidx = (pfn_to_pdx(emfn - 1) + PDX_GROUP_COUNT) / PDX_GROUP_COUNT;
412 for ( ; idx < eidx; ++idx )
413 __set_bit(idx, pdx_group_valid);
414 }
416 /* A temporary copy of the e820 map that we can mess with during bootstrap. */
417 static struct e820map __initdata boot_e820;
419 struct boot_video_info {
420 u8 orig_x; /* 0x00 */
421 u8 orig_y; /* 0x01 */
422 u8 orig_video_mode; /* 0x02 */
423 u8 orig_video_cols; /* 0x03 */
424 u8 orig_video_lines; /* 0x04 */
425 u8 orig_video_isVGA; /* 0x05 */
426 u16 orig_video_points; /* 0x06 */
428 /* VESA graphic mode -- linear frame buffer */
429 u32 capabilities; /* 0x08 */
430 u16 lfb_linelength; /* 0x0c */
431 u16 lfb_width; /* 0x0e */
432 u16 lfb_height; /* 0x10 */
433 u16 lfb_depth; /* 0x12 */
434 u32 lfb_base; /* 0x14 */
435 u32 lfb_size; /* 0x18 */
436 u8 red_size; /* 0x1c */
437 u8 red_pos; /* 0x1d */
438 u8 green_size; /* 0x1e */
439 u8 green_pos; /* 0x1f */
440 u8 blue_size; /* 0x20 */
441 u8 blue_pos; /* 0x21 */
442 u8 rsvd_size; /* 0x22 */
443 u8 rsvd_pos; /* 0x23 */
444 u16 vesapm_seg; /* 0x24 */
445 u16 vesapm_off; /* 0x26 */
446 u16 vesa_attrib; /* 0x28 */
447 };
449 static void __init parse_video_info(void)
450 {
451 struct boot_video_info *bvi = &bootsym(boot_vid_info);
453 if ( (bvi->orig_video_isVGA == 1) && (bvi->orig_video_mode == 3) )
454 {
455 vga_console_info.video_type = XEN_VGATYPE_TEXT_MODE_3;
456 vga_console_info.u.text_mode_3.font_height = bvi->orig_video_points;
457 vga_console_info.u.text_mode_3.cursor_x = bvi->orig_x;
458 vga_console_info.u.text_mode_3.cursor_y = bvi->orig_y;
459 vga_console_info.u.text_mode_3.rows = bvi->orig_video_lines;
460 vga_console_info.u.text_mode_3.columns = bvi->orig_video_cols;
461 }
462 else if ( bvi->orig_video_isVGA == 0x23 )
463 {
464 vga_console_info.video_type = XEN_VGATYPE_VESA_LFB;
465 vga_console_info.u.vesa_lfb.width = bvi->lfb_width;
466 vga_console_info.u.vesa_lfb.height = bvi->lfb_height;
467 vga_console_info.u.vesa_lfb.bytes_per_line = bvi->lfb_linelength;
468 vga_console_info.u.vesa_lfb.bits_per_pixel = bvi->lfb_depth;
469 vga_console_info.u.vesa_lfb.lfb_base = bvi->lfb_base;
470 vga_console_info.u.vesa_lfb.lfb_size = bvi->lfb_size;
471 vga_console_info.u.vesa_lfb.red_pos = bvi->red_pos;
472 vga_console_info.u.vesa_lfb.red_size = bvi->red_size;
473 vga_console_info.u.vesa_lfb.green_pos = bvi->green_pos;
474 vga_console_info.u.vesa_lfb.green_size = bvi->green_size;
475 vga_console_info.u.vesa_lfb.blue_pos = bvi->blue_pos;
476 vga_console_info.u.vesa_lfb.blue_size = bvi->blue_size;
477 vga_console_info.u.vesa_lfb.rsvd_pos = bvi->rsvd_pos;
478 vga_console_info.u.vesa_lfb.rsvd_size = bvi->rsvd_size;
479 vga_console_info.u.vesa_lfb.gbl_caps = bvi->capabilities;
480 vga_console_info.u.vesa_lfb.mode_attrs = bvi->vesa_attrib;
481 }
482 }
484 static void __init kexec_reserve_area(struct e820map *e820)
485 {
486 unsigned long kdump_start = kexec_crash_area.start;
487 unsigned long kdump_size = kexec_crash_area.size;
488 static int is_reserved = 0;
490 kdump_size = (kdump_size + PAGE_SIZE - 1) & PAGE_MASK;
492 if ( (kdump_start == 0) || (kdump_size == 0) || is_reserved )
493 return;
495 is_reserved = 1;
497 if ( !reserve_e820_ram(e820, kdump_start, kdump_start + kdump_size) )
498 {
499 printk("Kdump: DISABLED (failed to reserve %luMB (%lukB) at 0x%lx)"
500 "\n", kdump_size >> 20, kdump_size >> 10, kdump_start);
501 kexec_crash_area.start = kexec_crash_area.size = 0;
502 }
503 else
504 {
505 printk("Kdump: %luMB (%lukB) at 0x%lx\n",
506 kdump_size >> 20, kdump_size >> 10, kdump_start);
507 }
508 }
510 void init_done(void)
511 {
512 /* Free (or page-protect) the init areas. */
513 memset(__init_begin, 0xcc, __init_end - __init_begin); /* int3 poison */
514 free_xen_data(__init_begin, __init_end);
515 printk("Freed %ldkB init memory.\n", (long)(__init_end-__init_begin)>>10);
517 startup_cpu_idle_loop();
518 }
520 static bool_t __init loader_is_grub2(const char *loader_name)
521 {
522 /* GRUB1="GNU GRUB 0.xx"; GRUB2="GRUB 1.xx" */
523 const char *p = strstr(loader_name, "GRUB ");
524 return (p != NULL) && (p[5] != '0');
525 }
527 static char * __init cmdline_cook(char *p, char *loader_name)
528 {
529 p = p ? : "";
531 /* Strip leading whitespace. */
532 while ( *p == ' ' )
533 p++;
535 /* GRUB2 does not include image name as first item on command line. */
536 if ( loader_is_grub2(loader_name) )
537 return p;
539 /* Strip image name plus whitespace. */
540 while ( (*p != ' ') && (*p != '\0') )
541 p++;
542 while ( *p == ' ' )
543 p++;
545 return p;
546 }
548 void __init __start_xen(unsigned long mbi_p)
549 {
550 char *memmap_type = NULL;
551 char *cmdline, *kextra, *loader;
552 unsigned int initrdidx = 1;
553 multiboot_info_t *mbi = __va(mbi_p);
554 module_t *mod = (module_t *)__va(mbi->mods_addr);
555 unsigned long nr_pages, modules_headroom;
556 int i, j, e820_warn = 0, bytes = 0;
557 bool_t acpi_boot_table_init_done = 0;
558 struct ns16550_defaults ns16550 = {
559 .data_bits = 8,
560 .parity = 'n',
561 .stop_bits = 1
562 };
564 percpu_init_areas();
566 set_intr_gate(TRAP_page_fault, &early_page_fault);
568 loader = (mbi->flags & MBI_LOADERNAME)
569 ? (char *)__va(mbi->boot_loader_name) : "unknown";
571 /* Parse the command-line options. */
572 cmdline = cmdline_cook((mbi->flags & MBI_CMDLINE) ?
573 __va(mbi->cmdline) : NULL,
574 loader);
575 if ( (kextra = strstr(cmdline, " -- ")) != NULL )
576 {
577 /*
578 * Options after ' -- ' separator belong to dom0.
579 * 1. Orphan dom0's options from Xen's command line.
580 * 2. Skip all but final leading space from dom0's options.
581 */
582 *kextra = '\0';
583 kextra += 3;
584 while ( kextra[1] == ' ' ) kextra++;
585 }
586 cmdline_parse(cmdline);
588 parse_video_info();
590 set_current((struct vcpu *)0xfffff000); /* debug sanity */
591 idle_vcpu[0] = current;
592 set_processor_id(0); /* needed early, for smp_processor_id() */
593 if ( cpu_has_efer )
594 rdmsrl(MSR_EFER, this_cpu(efer));
595 asm volatile ( "mov %%cr4,%0" : "=r" (this_cpu(cr4)) );
597 smp_prepare_boot_cpu();
599 /* We initialise the serial devices very early so we can get debugging. */
600 ns16550.io_base = 0x3f8;
601 ns16550.irq = 4;
602 ns16550_init(0, &ns16550);
603 ns16550.io_base = 0x2f8;
604 ns16550.irq = 3;
605 ns16550_init(1, &ns16550);
606 console_init_preirq();
608 printk("Bootloader: %s\n", loader);
610 printk("Command line: %s\n", cmdline);
612 printk("Video information:\n");
614 /* Print VGA display mode information. */
615 switch ( vga_console_info.video_type )
616 {
617 case XEN_VGATYPE_TEXT_MODE_3:
618 printk(" VGA is text mode %dx%d, font 8x%d\n",
619 vga_console_info.u.text_mode_3.columns,
620 vga_console_info.u.text_mode_3.rows,
621 vga_console_info.u.text_mode_3.font_height);
622 break;
623 case XEN_VGATYPE_VESA_LFB:
624 printk(" VGA is graphics mode %dx%d, %d bpp\n",
625 vga_console_info.u.vesa_lfb.width,
626 vga_console_info.u.vesa_lfb.height,
627 vga_console_info.u.vesa_lfb.bits_per_pixel);
628 break;
629 default:
630 printk(" No VGA detected\n");
631 break;
632 }
634 /* Print VBE/DDC EDID information. */
635 if ( bootsym(boot_edid_caps) != 0x1313 )
636 {
637 u16 caps = bootsym(boot_edid_caps);
638 printk(" VBE/DDC methods:%s%s%s; ",
639 (caps & 1) ? " V1" : "",
640 (caps & 2) ? " V2" : "",
641 !(caps & 3) ? " none" : "");
642 printk("EDID transfer time: %d seconds\n", caps >> 8);
643 if ( *(u32 *)bootsym(boot_edid_info) == 0x13131313 )
644 {
645 printk(" EDID info not retrieved because ");
646 if ( !(caps & 3) )
647 printk("no DDC retrieval method detected\n");
648 else if ( (caps >> 8) > 5 )
649 printk("takes longer than 5 seconds\n");
650 else
651 printk("of reasons unknown\n");
652 }
653 }
655 printk("Disc information:\n");
656 printk(" Found %d MBR signatures\n",
657 bootsym(boot_mbr_signature_nr));
658 printk(" Found %d EDD information structures\n",
659 bootsym(boot_edd_info_nr));
661 /* Check that we have at least one Multiboot module. */
662 if ( !(mbi->flags & MBI_MODULES) || (mbi->mods_count == 0) )
663 EARLY_FAIL("dom0 kernel not specified. "
664 "Check bootloader configuration.\n");
666 if ( ((unsigned long)cpu0_stack & (STACK_SIZE-1)) != 0 )
667 EARLY_FAIL("Misaligned CPU0 stack.\n");
669 if ( e820_raw_nr != 0 )
670 {
671 memmap_type = "Xen-e820";
672 }
673 else if ( bootsym(lowmem_kb) )
674 {
675 memmap_type = "Xen-e801";
676 e820_raw[0].addr = 0;
677 e820_raw[0].size = bootsym(lowmem_kb) << 10;
678 e820_raw[0].type = E820_RAM;
679 e820_raw[1].addr = 0x100000;
680 e820_raw[1].size = bootsym(highmem_kb) << 10;
681 e820_raw[1].type = E820_RAM;
682 e820_raw_nr = 2;
683 }
684 else if ( mbi->flags & MBI_MEMMAP )
685 {
686 memmap_type = "Multiboot-e820";
687 while ( (bytes < mbi->mmap_length) && (e820_raw_nr < E820MAX) )
688 {
689 memory_map_t *map = __va(mbi->mmap_addr + bytes);
691 /*
692 * This is a gross workaround for a BIOS bug. Some bootloaders do
693 * not write e820 map entries into pre-zeroed memory. This is
694 * okay if the BIOS fills in all fields of the map entry, but
695 * some broken BIOSes do not bother to write the high word of
696 * the length field if the length is smaller than 4GB. We
697 * detect and fix this by flagging sections below 4GB that
698 * appear to be larger than 4GB in size.
699 */
700 if ( (map->base_addr_high == 0) && (map->length_high != 0) )
701 {
702 if ( !e820_warn )
703 {
704 printk("WARNING: Buggy e820 map detected and fixed "
705 "(truncated length fields).\n");
706 e820_warn = 1;
707 }
708 map->length_high = 0;
709 }
711 e820_raw[e820_raw_nr].addr =
712 ((u64)map->base_addr_high << 32) | (u64)map->base_addr_low;
713 e820_raw[e820_raw_nr].size =
714 ((u64)map->length_high << 32) | (u64)map->length_low;
715 e820_raw[e820_raw_nr].type = map->type;
716 e820_raw_nr++;
718 bytes += map->size + 4;
719 }
720 }
721 else if ( mbi->flags & MBI_MEMLIMITS )
722 {
723 memmap_type = "Multiboot-e801";
724 e820_raw[0].addr = 0;
725 e820_raw[0].size = mbi->mem_lower << 10;
726 e820_raw[0].type = E820_RAM;
727 e820_raw[1].addr = 0x100000;
728 e820_raw[1].size = mbi->mem_upper << 10;
729 e820_raw[1].type = E820_RAM;
730 e820_raw_nr = 2;
731 }
732 else
733 {
734 EARLY_FAIL("Bootloader provided no memory information.\n");
735 }
737 /* Sanitise the raw E820 map to produce a final clean version. */
738 max_page = init_e820(memmap_type, e820_raw, &e820_raw_nr);
740 /* Create a temporary copy of the E820 map. */
741 memcpy(&boot_e820, &e820, sizeof(e820));
743 /* Early kexec reservation (explicit static start address). */
744 nr_pages = 0;
745 for ( i = 0; i < e820.nr_map; i++ )
746 if ( e820.map[i].type == E820_RAM )
747 nr_pages += e820.map[i].size >> PAGE_SHIFT;
748 set_kexec_crash_area_size((u64)nr_pages << PAGE_SHIFT);
749 kexec_reserve_area(&boot_e820);
751 initial_images = mod;
752 nr_initial_images = mbi->mods_count;
754 /*
755 * Iterate backwards over all superpage-aligned RAM regions.
756 *
757 * We require superpage alignment because the boot allocator is not yet
758 * initialised. Hence we can only map superpages in the address range
759 * 0 to BOOTSTRAP_DIRECTMAP_END, as this is guaranteed not to require
760 * dynamic allocation of pagetables.
761 *
762 * As well as mapping superpages in that range, in preparation for
763 * initialising the boot allocator, we also look for a region to which
764 * we can relocate the dom0 kernel and other multiboot modules. Also, on
765 * x86/64, we relocate Xen to higher memory.
766 */
767 for ( i = 0; i < mbi->mods_count; i++ )
768 {
769 if ( mod[i].mod_start & (PAGE_SIZE - 1) )
770 EARLY_FAIL("Bootloader didn't honor module alignment request.\n");
771 mod[i].mod_end -= mod[i].mod_start;
772 mod[i].mod_start >>= PAGE_SHIFT;
773 mod[i].reserved = 0;
774 }
776 modules_headroom = bzimage_headroom(bootstrap_map(mod), mod->mod_end);
777 bootstrap_map(NULL);
779 for ( i = boot_e820.nr_map-1; i >= 0; i-- )
780 {
781 uint64_t s, e, mask = (1UL << L2_PAGETABLE_SHIFT) - 1;
782 uint64_t end, limit = ARRAY_SIZE(l2_identmap) << L2_PAGETABLE_SHIFT;
784 /* Superpage-aligned chunks from BOOTSTRAP_MAP_BASE. */
785 s = (boot_e820.map[i].addr + mask) & ~mask;
786 e = (boot_e820.map[i].addr + boot_e820.map[i].size) & ~mask;
787 s = max_t(uint64_t, s, BOOTSTRAP_MAP_BASE);
788 if ( (boot_e820.map[i].type != E820_RAM) || (s >= e) )
789 continue;
791 if ( s < limit )
792 {
793 end = min(e, limit);
794 set_pdx_range(s >> PAGE_SHIFT, end >> PAGE_SHIFT);
795 #ifdef CONFIG_X86_64
796 map_pages_to_xen((unsigned long)__va(s), s >> PAGE_SHIFT,
797 (end - s) >> PAGE_SHIFT, PAGE_HYPERVISOR);
798 #endif
799 }
801 #if defined(CONFIG_X86_64)
802 e = min_t(uint64_t, e, 1ULL << (PAGE_SHIFT + 32));
803 #define reloc_size ((__pa(&_end) + mask) & ~mask)
804 /* Is the region suitable for relocating Xen? */
805 if ( !xen_phys_start && e <= limit )
806 {
807 /* Don't overlap with modules. */
808 end = consider_modules(s, e, reloc_size + mask,
809 mod, mbi->mods_count, -1);
810 end &= ~mask;
811 }
812 else
813 end = 0;
814 if ( end > s )
815 {
816 extern l2_pgentry_t l2_xenmap[];
817 l4_pgentry_t *pl4e;
818 l3_pgentry_t *pl3e;
819 l2_pgentry_t *pl2e;
820 int i, j, k;
821 void *dst;
823 /* Select relocation address. */
824 e = end - reloc_size;
825 xen_phys_start = e;
826 bootsym(trampoline_xen_phys_start) = e;
828 /*
829 * Perform relocation to new physical address.
830 * Before doing so we must sync static/global data with main memory
831 * with a barrier(). After this we must *not* modify static/global
832 * data until after we have switched to the relocated pagetables!
833 */
834 barrier();
835 dst = move_memory(e, 0, (unsigned long)&_end - XEN_VIRT_START, 1);
837 /* Poison low 1MB to detect stray pointers to physical 0-1MB. */
838 memset(dst, 0x55, 1U << 20);
840 /* Walk initial pagetables, relocating page directory entries. */
841 pl4e = __va(__pa(idle_pg_table));
842 for ( i = 0 ; i < L4_PAGETABLE_ENTRIES; i++, pl4e++ )
843 {
844 if ( !(l4e_get_flags(*pl4e) & _PAGE_PRESENT) )
845 continue;
846 *pl4e = l4e_from_intpte(l4e_get_intpte(*pl4e) +
847 xen_phys_start);
848 pl3e = l4e_to_l3e(*pl4e);
849 for ( j = 0; j < L3_PAGETABLE_ENTRIES; j++, pl3e++ )
850 {
851 /* Not present, 1GB mapping, or already relocated? */
852 if ( !(l3e_get_flags(*pl3e) & _PAGE_PRESENT) ||
853 (l3e_get_flags(*pl3e) & _PAGE_PSE) ||
854 (l3e_get_pfn(*pl3e) > 0x1000) )
855 continue;
856 *pl3e = l3e_from_intpte(l3e_get_intpte(*pl3e) +
857 xen_phys_start);
858 pl2e = l3e_to_l2e(*pl3e);
859 for ( k = 0; k < L2_PAGETABLE_ENTRIES; k++, pl2e++ )
860 {
861 /* Not present, PSE, or already relocated? */
862 if ( !(l2e_get_flags(*pl2e) & _PAGE_PRESENT) ||
863 (l2e_get_flags(*pl2e) & _PAGE_PSE) ||
864 (l2e_get_pfn(*pl2e) > 0x1000) )
865 continue;
866 *pl2e = l2e_from_intpte(l2e_get_intpte(*pl2e) +
867 xen_phys_start);
868 }
869 }
870 }
872 /* The only data mappings to be relocated are in the Xen area. */
873 pl2e = __va(__pa(l2_xenmap));
874 *pl2e++ = l2e_from_pfn(xen_phys_start >> PAGE_SHIFT,
875 PAGE_HYPERVISOR | _PAGE_PSE);
876 for ( i = 1; i < L2_PAGETABLE_ENTRIES; i++, pl2e++ )
877 {
878 if ( !(l2e_get_flags(*pl2e) & _PAGE_PRESENT) )
879 continue;
880 *pl2e = l2e_from_intpte(l2e_get_intpte(*pl2e) +
881 xen_phys_start);
882 }
884 /* Re-sync the stack and then switch to relocated pagetables. */
885 asm volatile (
886 "rep movsb ; " /* re-sync the stack */
887 "movq %%cr4,%%rsi ; "
888 "andb $0x7f,%%sil ; "
889 "movq %%rsi,%%cr4 ; " /* CR4.PGE == 0 */
890 "movq %0,%%cr3 ; " /* CR3 == new pagetables */
891 "orb $0x80,%%sil ; "
892 "movq %%rsi,%%cr4 " /* CR4.PGE == 1 */
893 : : "r" (__pa(idle_pg_table)), "S" (cpu0_stack),
894 "D" (__va(__pa(cpu0_stack))), "c" (STACK_SIZE) : "memory" );
896 bootstrap_map(NULL);
897 }
898 #endif
900 /* Is the region suitable for relocating the multiboot modules? */
901 for ( j = mbi->mods_count - 1; j >= 0; j-- )
902 {
903 unsigned long headroom = j ? 0 : modules_headroom;
904 unsigned long size = PAGE_ALIGN(headroom + mod[j].mod_end);
906 if ( mod[j].reserved )
907 continue;
909 /* Don't overlap with other modules. */
910 end = consider_modules(s, e, size, mod, mbi->mods_count, j);
912 if ( s < end &&
913 (headroom ||
914 ((end - size) >> PAGE_SHIFT) > mod[j].mod_start) )
915 {
916 move_memory(end - size + headroom,
917 (uint64_t)mod[j].mod_start << PAGE_SHIFT,
918 mod[j].mod_end, 0);
919 mod[j].mod_start = (end - size) >> PAGE_SHIFT;
920 mod[j].mod_end += headroom;
921 mod[j].reserved = 1;
922 }
923 }
925 #ifdef CONFIG_X86_32
926 /* Confine the kexec area to below 4Gb. */
927 e = min_t(uint64_t, e, 1ULL << 32);
928 #endif
929 /* Don't overlap with modules. */
930 e = consider_modules(s, e, PAGE_ALIGN(kexec_crash_area.size),
931 mod, mbi->mods_count, -1);
932 if ( !kexec_crash_area.start && (s < e) )
933 {
934 e = (e - kexec_crash_area.size) & PAGE_MASK;
935 kexec_crash_area.start = e;
936 }
937 }
939 if ( modules_headroom && !mod->reserved )
940 EARLY_FAIL("Not enough memory to relocate the dom0 kernel image.\n");
941 for ( i = 0; i < mbi->mods_count; ++i )
942 {
943 uint64_t s = (uint64_t)mod[i].mod_start << PAGE_SHIFT;
945 reserve_e820_ram(&boot_e820, s, s + PAGE_ALIGN(mod[i].mod_end));
946 }
948 #if defined(CONFIG_X86_32)
949 xenheap_initial_phys_start = (PFN_UP(__pa(&_end)) + 1) << PAGE_SHIFT;
950 /* Must pass a single mapped page for populating bootmem_region_list. */
951 init_boot_pages(__pa(&_end), xenheap_initial_phys_start);
952 xenheap_phys_end = DIRECTMAP_MBYTES << 20;
953 #else
954 if ( !xen_phys_start )
955 EARLY_FAIL("Not enough memory to relocate Xen.\n");
956 reserve_e820_ram(&boot_e820, __pa(&_start), __pa(&_end));
957 #endif
959 /* Late kexec reservation (dynamic start address). */
960 kexec_reserve_area(&boot_e820);
962 setup_max_pdx();
964 /*
965 * Walk every RAM region and map it in its entirety (on x86/64, at least)
966 * and notify it to the boot allocator.
967 */
968 for ( i = 0; i < boot_e820.nr_map; i++ )
969 {
970 uint64_t s, e, mask = PAGE_SIZE - 1;
971 #ifdef CONFIG_X86_64
972 uint64_t map_s, map_e;
973 #endif
975 /* Only page alignment required now. */
976 s = (boot_e820.map[i].addr + mask) & ~mask;
977 e = (boot_e820.map[i].addr + boot_e820.map[i].size) & ~mask;
978 #if defined(CONFIG_X86_32)
979 s = max_t(uint64_t, s, xenheap_phys_end);
980 #else
981 s = max_t(uint64_t, s, 1<<20);
982 #endif
983 if ( (boot_e820.map[i].type != E820_RAM) || (s >= e) )
984 continue;
986 #ifdef __x86_64__
987 if ( !acpi_boot_table_init_done &&
988 s >= (1ULL << 32) &&
989 !acpi_boot_table_init() )
990 {
991 acpi_boot_table_init_done = 1;
992 srat_parse_regions(s);
993 setup_max_pdx();
994 }
996 if ( pfn_to_pdx((e - 1) >> PAGE_SHIFT) >= max_pdx )
997 {
998 if ( pfn_to_pdx(s >> PAGE_SHIFT) >= max_pdx )
999 {
1000 for ( j = i - 1; ; --j )
1002 if ( boot_e820.map[j].type == E820_RAM )
1003 break;
1004 ASSERT(j);
1006 map_e = boot_e820.map[j].addr + boot_e820.map[j].size;
1007 if ( (map_e >> PAGE_SHIFT) < max_page )
1009 max_page = map_e >> PAGE_SHIFT;
1010 max_pdx = pfn_to_pdx(max_page - 1) + 1;
1012 printk(XENLOG_WARNING "Ignoring inaccessible memory range"
1013 " %013"PRIx64"-%013"PRIx64"\n",
1014 s, e);
1015 continue;
1017 map_e = e;
1018 e = (pdx_to_pfn(max_pdx - 1) + 1ULL) << PAGE_SHIFT;
1019 printk(XENLOG_WARNING "Ignoring inaccessible memory range"
1020 " %013"PRIx64"-%013"PRIx64"\n",
1021 e, map_e);
1023 #endif
1025 set_pdx_range(s >> PAGE_SHIFT, e >> PAGE_SHIFT);
1027 #ifdef CONFIG_X86_64
1028 /* Need to create mappings above BOOTSTRAP_MAP_BASE. */
1029 map_s = max_t(uint64_t, s, BOOTSTRAP_MAP_BASE);
1030 map_e = min_t(uint64_t, e,
1031 ARRAY_SIZE(l2_identmap) << L2_PAGETABLE_SHIFT);
1033 /* Pass mapped memory to allocator /before/ creating new mappings. */
1034 init_boot_pages(s, min(map_s, e));
1035 s = map_s;
1036 if ( s < map_e )
1038 uint64_t mask = (1UL << L2_PAGETABLE_SHIFT) - 1;
1040 map_s = (s + mask) & ~mask;
1041 map_e &= ~mask;
1042 init_boot_pages(map_s, map_e);
1045 if ( map_s > map_e )
1046 map_s = map_e = s;
1048 /* Create new mappings /before/ passing memory to the allocator. */
1049 if ( map_e < e )
1051 map_pages_to_xen((unsigned long)__va(map_e), map_e >> PAGE_SHIFT,
1052 (e - map_e) >> PAGE_SHIFT, PAGE_HYPERVISOR);
1053 init_boot_pages(map_e, e);
1055 if ( s < map_s )
1057 map_pages_to_xen((unsigned long)__va(s), s >> PAGE_SHIFT,
1058 (map_s - s) >> PAGE_SHIFT, PAGE_HYPERVISOR);
1059 init_boot_pages(s, map_s);
1061 #else
1062 init_boot_pages(s, e);
1063 #endif
1066 for ( i = 0; i < mbi->mods_count; ++i )
1068 set_pdx_range(mod[i].mod_start,
1069 mod[i].mod_start + PFN_UP(mod[i].mod_end));
1070 #ifdef CONFIG_X86_64
1071 map_pages_to_xen((unsigned long)mfn_to_virt(mod[i].mod_start),
1072 mod[i].mod_start,
1073 PFN_UP(mod[i].mod_end), PAGE_HYPERVISOR);
1074 #endif
1076 #ifdef CONFIG_X86_64
1077 map_pages_to_xen((unsigned long)__va(kexec_crash_area.start),
1078 kexec_crash_area.start >> PAGE_SHIFT,
1079 PFN_UP(kexec_crash_area.size), PAGE_HYPERVISOR);
1080 #endif
1082 memguard_init();
1084 nr_pages = 0;
1085 for ( i = 0; i < e820.nr_map; i++ )
1086 if ( e820.map[i].type == E820_RAM )
1087 nr_pages += e820.map[i].size >> PAGE_SHIFT;
1088 printk("System RAM: %luMB (%lukB)\n",
1089 nr_pages >> (20 - PAGE_SHIFT),
1090 nr_pages << (PAGE_SHIFT - 10));
1091 total_pages = nr_pages;
1093 /* Sanity check for unwanted bloat of certain hypercall structures. */
1094 BUILD_BUG_ON(sizeof(((struct xen_platform_op *)0)->u) !=
1095 sizeof(((struct xen_platform_op *)0)->u.pad));
1096 BUILD_BUG_ON(sizeof(((struct xen_domctl *)0)->u) !=
1097 sizeof(((struct xen_domctl *)0)->u.pad));
1098 BUILD_BUG_ON(sizeof(((struct xen_sysctl *)0)->u) !=
1099 sizeof(((struct xen_sysctl *)0)->u.pad));
1101 BUILD_BUG_ON(sizeof(start_info_t) > PAGE_SIZE);
1102 BUILD_BUG_ON(sizeof(shared_info_t) > PAGE_SIZE);
1103 BUILD_BUG_ON(sizeof(struct vcpu_info) != 64);
1105 #ifdef CONFIG_COMPAT
1106 BUILD_BUG_ON(sizeof(((struct compat_platform_op *)0)->u) !=
1107 sizeof(((struct compat_platform_op *)0)->u.pad));
1108 BUILD_BUG_ON(sizeof(start_info_compat_t) > PAGE_SIZE);
1109 BUILD_BUG_ON(sizeof(struct compat_vcpu_info) != 64);
1110 #endif
1112 /* Check definitions in public headers match internal defs. */
1113 BUILD_BUG_ON(__HYPERVISOR_VIRT_START != HYPERVISOR_VIRT_START);
1114 #ifdef HYPERVISOR_VIRT_END
1115 BUILD_BUG_ON(__HYPERVISOR_VIRT_END != HYPERVISOR_VIRT_END);
1116 #endif
1117 BUILD_BUG_ON(MACH2PHYS_VIRT_START != RO_MPT_VIRT_START);
1118 BUILD_BUG_ON(MACH2PHYS_VIRT_END != RO_MPT_VIRT_END);
1120 init_frametable();
1122 if ( !acpi_boot_table_init_done )
1123 acpi_boot_table_init();
1125 acpi_numa_init();
1127 numa_initmem_init(0, max_page);
1129 #if defined(CONFIG_X86_32)
1130 /* Initialise the Xen heap. */
1131 for ( nr_pages = i = 0; i < boot_e820.nr_map; i++ )
1133 uint64_t s = boot_e820.map[i].addr;
1134 uint64_t e = s + boot_e820.map[i].size;
1135 s = max_t(uint64_t, s, xenheap_initial_phys_start);
1136 e = min_t(uint64_t, e, xenheap_phys_end);
1137 if ( (boot_e820.map[i].type != E820_RAM) || (s >= e) )
1138 continue;
1139 init_xenheap_pages(s, e);
1140 nr_pages += (e - s) >> PAGE_SHIFT;
1142 printk("Xen heap: %luMB (%lukB)\n",
1143 nr_pages >> (20 - PAGE_SHIFT),
1144 nr_pages << (PAGE_SHIFT - 10));
1145 #endif
1147 end_boot_allocator();
1148 early_boot = 0;
1150 #if defined(CONFIG_X86_64)
1151 vesa_init();
1152 #endif
1154 softirq_init();
1155 tasklet_subsys_init();
1157 early_cpu_init();
1159 paging_init();
1161 tboot_probe();
1163 /* Unmap the first page of CPU0's stack. */
1164 memguard_guard_stack(cpu0_stack);
1166 open_softirq(NEW_TLBFLUSH_CLOCK_PERIOD_SOFTIRQ, new_tlbflush_clock_period);
1168 if ( opt_watchdog )
1169 nmi_watchdog = NMI_LOCAL_APIC;
1171 sort_exception_tables();
1173 find_smp_config();
1175 dmi_scan_machine();
1177 generic_apic_probe();
1179 acpi_boot_init();
1181 if ( smp_found_config )
1182 get_smp_config();
1184 #ifdef CONFIG_X86_64
1185 /* Low mappings were only needed for some BIOS table parsing. */
1186 zap_low_mappings();
1187 #endif
1189 init_apic_mappings();
1191 normalise_cpu_order();
1193 init_cpu_to_node();
1195 x2apic_bsp_setup();
1197 init_IRQ();
1199 xsm_init(&initrdidx, mbi, bootstrap_map);
1201 timer_init();
1203 init_idle_domain();
1205 trap_init();
1207 #ifdef XEN_KDB_CONFIG
1208 kdb_init();
1209 if (opt_earlykdb)
1210 kdb_trap_immed(KDB_TRAP_NONFATAL);
1211 #endif
1213 rcu_init();
1215 early_time_init();
1217 arch_init_memory();
1219 identify_cpu(&boot_cpu_data);
1220 if ( cpu_has_fxsr )
1221 set_in_cr4(X86_CR4_OSFXSR);
1222 if ( cpu_has_xmm )
1223 set_in_cr4(X86_CR4_OSXMMEXCPT);
1225 local_irq_enable();
1227 #ifdef CONFIG_X86_64
1228 vesa_mtrr_init();
1229 #endif
1231 if ( opt_nosmp )
1232 max_cpus = 0;
1234 iommu_setup(); /* setup iommu if available */
1236 smp_prepare_cpus(max_cpus);
1238 spin_debug_enable();
1240 /*
1241 * Initialise higher-level timer functions. We do this fairly late
1242 * (post-SMP) because the time bases and scale factors need to be updated
1243 * regularly, and SMP initialisation can cause a long delay with
1244 * interrupts not yet enabled.
1245 */
1246 init_xen_time();
1248 initialize_keytable();
1250 console_init_postirq();
1252 do_presmp_initcalls();
1254 for_each_present_cpu ( i )
1256 /* Set up cpu_to_node[]. */
1257 srat_detect_node(i);
1258 /* Set up node_to_cpumask based on cpu_to_node[]. */
1259 numa_add_cpu(i);
1261 if ( (num_online_cpus() < max_cpus) && !cpu_online(i) )
1263 int ret = cpu_up(i);
1264 if ( ret != 0 )
1265 printk("Failed to bring up CPU %u (error %d)\n", i, ret);
1269 printk("Brought up %ld CPUs\n", (long)num_online_cpus());
1270 smp_cpus_done(max_cpus);
1272 do_initcalls();
1274 if ( opt_watchdog )
1275 watchdog_enable();
1277 if ( !tboot_protect_mem_regions() )
1278 panic("Could not protect TXT memory regions\n");
1280 /* Create initial domain 0. */
1281 dom0 = domain_create(0, DOMCRF_s3_integrity, DOM0_SSIDREF);
1282 if ( (dom0 == NULL) || (alloc_dom0_vcpu0() == NULL) )
1283 panic("Error creating domain 0\n");
1285 dom0->is_privileged = 1;
1286 dom0->target = NULL;
1288 /* Grab the DOM0 command line. */
1289 cmdline = (char *)(mod[0].string ? __va(mod[0].string) : NULL);
1290 if ( (cmdline != NULL) || (kextra != NULL) )
1292 static char dom0_cmdline[MAX_GUEST_CMDLINE];
1294 cmdline = cmdline_cook(cmdline, loader);
1295 safe_strcpy(dom0_cmdline, cmdline);
1297 if ( kextra != NULL )
1298 /* kextra always includes exactly one leading space. */
1299 safe_strcat(dom0_cmdline, kextra);
1301 /* Append any extra parameters. */
1302 if ( skip_ioapic_setup && !strstr(dom0_cmdline, "noapic") )
1303 safe_strcat(dom0_cmdline, " noapic");
1304 if ( acpi_skip_timer_override &&
1305 !strstr(dom0_cmdline, "acpi_skip_timer_override") )
1306 safe_strcat(dom0_cmdline, " acpi_skip_timer_override");
1307 if ( (strlen(acpi_param) == 0) && acpi_disabled )
1309 printk("ACPI is disabled, notifying Domain 0 (acpi=off)\n");
1310 safe_strcpy(acpi_param, "off");
1312 if ( (strlen(acpi_param) != 0) && !strstr(dom0_cmdline, "acpi=") )
1314 safe_strcat(dom0_cmdline, " acpi=");
1315 safe_strcat(dom0_cmdline, acpi_param);
1318 cmdline = dom0_cmdline;
1321 if ( xen_cpuidle )
1322 xen_processor_pmbits |= XEN_PROCESSOR_PM_CX;
1324 /*
1325 * We're going to setup domain0 using the module(s) that we stashed safely
1326 * above our heap. The second module, if present, is an initrd ramdisk.
1327 */
1328 if ( construct_dom0(dom0, mod, modules_headroom,
1329 (initrdidx > 0) && (initrdidx < mbi->mods_count)
1330 ? mod + initrdidx : NULL,
1331 bootstrap_map, cmdline) != 0)
1332 panic("Could not set up DOM0 guest OS\n");
1334 /* Scrub RAM that is still free and so may go to an unprivileged domain. */
1335 scrub_heap_pages();
1337 init_trace_bufs();
1339 console_endboot();
1341 /* Hide UART from DOM0 if we're using it */
1342 serial_endboot();
1344 domain_unpause_by_systemcontroller(dom0);
1346 reset_stack_and_jump(init_done);
1349 void arch_get_xen_caps(xen_capabilities_info_t *info)
1351 /* Interface name is always xen-3.0-* for Xen-3.x. */
1352 int major = 3, minor = 0;
1353 char s[32];
1355 (*info)[0] = '\0';
1357 #ifdef CONFIG_X86_64
1358 snprintf(s, sizeof(s), "xen-%d.%d-x86_64 ", major, minor);
1359 safe_strcat(*info, s);
1360 #endif
1361 snprintf(s, sizeof(s), "xen-%d.%d-x86_32p ", major, minor);
1362 safe_strcat(*info, s);
1363 if ( hvm_enabled )
1365 snprintf(s, sizeof(s), "hvm-%d.%d-x86_32 ", major, minor);
1366 safe_strcat(*info, s);
1367 snprintf(s, sizeof(s), "hvm-%d.%d-x86_32p ", major, minor);
1368 safe_strcat(*info, s);
1369 #ifdef CONFIG_X86_64
1370 snprintf(s, sizeof(s), "hvm-%d.%d-x86_64 ", major, minor);
1371 safe_strcat(*info, s);
1372 #endif
1376 int xen_in_range(unsigned long mfn)
1378 paddr_t start, end;
1379 int i;
1381 enum { region_s3, region_text, region_bss, nr_regions };
1382 static struct {
1383 paddr_t s, e;
1384 } xen_regions[nr_regions];
1386 /* initialize first time */
1387 if ( !xen_regions[0].s )
1389 /* S3 resume code (and other real mode trampoline code) */
1390 xen_regions[region_s3].s = bootsym_phys(trampoline_start);
1391 xen_regions[region_s3].e = bootsym_phys(trampoline_end);
1392 /* hypervisor code + data */
1393 xen_regions[region_text].s =__pa(&_stext);
1394 xen_regions[region_text].e = __pa(&__init_begin);
1395 /* bss */
1396 xen_regions[region_bss].s = __pa(&__bss_start);
1397 xen_regions[region_bss].e = __pa(&_end);
1400 start = (paddr_t)mfn << PAGE_SHIFT;
1401 end = start + PAGE_SIZE;
1402 for ( i = 0; i < nr_regions; i++ )
1403 if ( (start < xen_regions[i].e) && (end > xen_regions[i].s) )
1404 return 1;
1406 return 0;
1409 /*
1410 * Local variables:
1411 * mode: C
1412 * c-set-style: "BSD"
1413 * c-basic-offset: 4
1414 * tab-width: 4
1415 * indent-tabs-mode: nil
1416 * End:
1417 */