debuggers.hg

view xen/arch/x86/setup.c @ 22798:ff97273750b8

cpu hotplug: Core functions are quiet on failure.

This was already inconsistent, so make them consistently quiet and
leave it to callers to log an error. Add suitable error logging to the
arch-specific CPU bringup loops,

In particular this avoids printing error on EBUSY, in which case
caller may want a silent retry loop.

Signed-off-by: Keir Fraser <keir@xen.org>
author Keir Fraser <keir@xen.org>
date Fri Jan 14 09:52:02 2011 +0000 (2011-01-14)
parents e8acb9753ff1
children 700ac6445812
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 extern u16 boot_edid_caps;
49 extern u8 boot_edid_info[128];
50 extern struct boot_video_info boot_vid_info;
52 /* opt_nosmp: If true, secondary processors are ignored. */
53 static bool_t __initdata opt_nosmp;
54 boolean_param("nosmp", opt_nosmp);
56 /* maxcpus: maximum number of CPUs to activate. */
57 static unsigned int __initdata max_cpus = NR_CPUS;
58 integer_param("maxcpus", max_cpus);
60 /* opt_watchdog: If true, run a watchdog NMI on each processor. */
61 static bool_t __initdata opt_watchdog;
62 boolean_param("watchdog", opt_watchdog);
64 /* **** Linux config option: propagated to domain0. */
65 /* "acpi=off": Sisables both ACPI table parsing and interpreter. */
66 /* "acpi=force": Override the disable blacklist. */
67 /* "acpi=strict": Disables out-of-spec workarounds. */
68 /* "acpi=ht": Limit ACPI just to boot-time to enable HT. */
69 /* "acpi=noirq": Disables ACPI interrupt routing. */
70 static void parse_acpi_param(char *s);
71 custom_param("acpi", parse_acpi_param);
73 /* **** Linux config option: propagated to domain0. */
74 /* acpi_skip_timer_override: Skip IRQ0 overrides. */
75 boolean_param("acpi_skip_timer_override", acpi_skip_timer_override);
77 /* **** Linux config option: propagated to domain0. */
78 /* noapic: Disable IOAPIC setup. */
79 boolean_param("noapic", skip_ioapic_setup);
81 /* **** Linux config option: propagated to domain0. */
82 /* xen_cpuidle: xen control cstate. */
83 s8 __read_mostly xen_cpuidle = -1;
84 boolean_param("cpuidle", xen_cpuidle);
86 bool_t __read_mostly early_boot = 1;
88 cpumask_t __read_mostly cpu_present_map;
90 unsigned long __read_mostly xen_phys_start;
92 #ifdef CONFIG_X86_32
93 /* Limits of Xen heap, used to initialise the allocator. */
94 unsigned long __initdata xenheap_initial_phys_start;
95 unsigned long __read_mostly xenheap_phys_end;
96 #endif
98 DEFINE_PER_CPU(struct tss_struct, init_tss);
100 char __attribute__ ((__section__(".bss.stack_aligned"))) cpu0_stack[STACK_SIZE];
102 struct cpuinfo_x86 __read_mostly boot_cpu_data = { 0, 0, 0, 0, -1 };
104 unsigned long __read_mostly mmu_cr4_features = X86_CR4_PSE | X86_CR4_PGE | X86_CR4_PAE;
106 bool_t __initdata acpi_disabled;
107 bool_t __initdata acpi_force;
108 static char __initdata acpi_param[10] = "";
109 static void __init parse_acpi_param(char *s)
110 {
111 /* Save the parameter so it can be propagated to domain0. */
112 safe_strcpy(acpi_param, s);
114 /* Interpret the parameter for use within Xen. */
115 if ( !parse_bool(s) )
116 {
117 disable_acpi();
118 }
119 else if ( !strcmp(s, "force") )
120 {
121 acpi_force = 1;
122 acpi_ht = 1;
123 acpi_disabled = 0;
124 }
125 else if ( !strcmp(s, "ht") )
126 {
127 if ( !acpi_force )
128 disable_acpi();
129 acpi_ht = 1;
130 }
131 else if ( !strcmp(s, "noirq") )
132 {
133 acpi_noirq_set();
134 }
135 }
137 #define EARLY_FAIL(f, a...) do { \
138 printk( f , ## a ); \
139 for ( ; ; ) halt(); \
140 } while (0)
142 static const module_t *__initdata initial_images;
143 static unsigned int __initdata nr_initial_images;
145 unsigned long __init initial_images_nrpages(void)
146 {
147 unsigned long nr;
148 unsigned int i;
150 for ( nr = i = 0; i < nr_initial_images; ++i )
151 nr += PFN_UP(initial_images[i].mod_end);
153 return nr;
154 }
156 void __init discard_initial_images(void)
157 {
158 unsigned int i;
160 for ( i = 0; i < nr_initial_images; ++i )
161 {
162 uint64_t start = (uint64_t)initial_images[i].mod_start << PAGE_SHIFT;
164 init_domheap_pages(start,
165 start + PAGE_ALIGN(initial_images[i].mod_end));
166 }
168 nr_initial_images = 0;
169 initial_images = NULL;
170 }
172 static void free_xen_data(char *s, char *e)
173 {
174 #ifndef MEMORY_GUARD
175 init_xenheap_pages(__pa(s), __pa(e));
176 #endif
177 memguard_guard_range(s, e-s);
178 #if defined(CONFIG_X86_64)
179 /* Also zap the mapping in the 1:1 area. */
180 memguard_guard_range(__va(__pa(s)), e-s);
181 #endif
182 }
184 extern char __init_begin[], __init_end[], __bss_start[];
186 static void __init init_idle_domain(void)
187 {
188 scheduler_init();
189 set_current(idle_vcpu[0]);
190 this_cpu(curr_vcpu) = current;
191 setup_idle_pagetable();
192 }
194 void __devinit srat_detect_node(int cpu)
195 {
196 unsigned node;
197 u32 apicid = x86_cpu_to_apicid[cpu];
199 node = apicid_to_node[apicid];
200 if ( node == NUMA_NO_NODE || !node_online(node) )
201 node = 0;
202 numa_set_node(cpu, node);
204 if ( opt_cpu_info && acpi_numa > 0 )
205 printk("CPU %d APIC %d -> Node %d\n", cpu, apicid, node);
206 }
208 /*
209 * Sort CPUs by <node,package,core,thread> tuple. Fortunately this hierarchy is
210 * reflected in the structure of modern APIC identifiers, so we sort based on
211 * those. This is slightly complicated by the fact that the BSP must remain
212 * CPU 0. Hence we do a variation on longest-prefix matching to do the best we
213 * can while keeping CPU 0 static.
214 */
215 static void __init normalise_cpu_order(void)
216 {
217 unsigned int i, j, min_cpu;
218 uint32_t apicid, diff, min_diff;
220 for_each_present_cpu ( i )
221 {
222 apicid = x86_cpu_to_apicid[i];
223 min_diff = min_cpu = ~0u;
225 /*
226 * Find remaining CPU with longest-prefix match on APIC ID.
227 * Among identical longest-prefix matches, pick the smallest APIC ID.
228 */
229 for ( j = next_cpu(i, cpu_present_map);
230 j < NR_CPUS;
231 j = next_cpu(j, cpu_present_map) )
232 {
233 diff = x86_cpu_to_apicid[j] ^ apicid;
234 while ( diff & (diff-1) )
235 diff &= diff-1;
236 if ( (diff < min_diff) ||
237 ((diff == min_diff) &&
238 (x86_cpu_to_apicid[j] < x86_cpu_to_apicid[min_cpu])) )
239 {
240 min_diff = diff;
241 min_cpu = j;
242 }
243 }
245 /* If no match then there must be no CPUs remaining to consider. */
246 if ( min_cpu >= NR_CPUS )
247 {
248 BUG_ON(next_cpu(i, cpu_present_map) < NR_CPUS);
249 break;
250 }
252 /* Switch the best-matching CPU with the next CPU in logical order. */
253 j = next_cpu(i, cpu_present_map);
254 apicid = x86_cpu_to_apicid[min_cpu];
255 x86_cpu_to_apicid[min_cpu] = x86_cpu_to_apicid[j];
256 x86_cpu_to_apicid[j] = apicid;
257 }
258 }
260 #define BOOTSTRAP_MAP_BASE (16UL << 20)
261 #define BOOTSTRAP_MAP_LIMIT (1UL << L3_PAGETABLE_SHIFT)
263 /*
264 * Ensure a given physical memory range is present in the bootstrap mappings.
265 * Use superpage mappings to ensure that pagetable memory needn't be allocated.
266 */
267 static void *__init bootstrap_map(const module_t *mod)
268 {
269 static unsigned long __initdata map_cur = BOOTSTRAP_MAP_BASE;
270 uint64_t start, end, mask = (1L << L2_PAGETABLE_SHIFT) - 1;
271 void *ret;
273 #ifdef __x86_64__
274 if ( !early_boot )
275 return mod ? mfn_to_virt(mod->mod_start) : NULL;
276 #endif
278 if ( !mod )
279 {
280 destroy_xen_mappings(BOOTSTRAP_MAP_BASE, BOOTSTRAP_MAP_LIMIT);
281 map_cur = BOOTSTRAP_MAP_BASE;
282 return NULL;
283 }
285 start = (uint64_t)mod->mod_start << PAGE_SHIFT;
286 end = start + mod->mod_end;
287 if ( start >= end )
288 return NULL;
290 if ( end <= BOOTSTRAP_MAP_BASE )
291 return (void *)(unsigned long)start;
293 ret = (void *)(map_cur + (unsigned long)(start & mask));
294 start &= ~mask;
295 end = (end + mask) & ~mask;
296 if ( end - start > BOOTSTRAP_MAP_LIMIT - map_cur )
297 return NULL;
299 map_pages_to_xen(map_cur, start >> PAGE_SHIFT,
300 (end - start) >> PAGE_SHIFT, PAGE_HYPERVISOR);
301 map_cur += end - start;
302 return ret;
303 }
305 static void *__init move_memory(
306 uint64_t dst, uint64_t src, unsigned int size, bool_t keep)
307 {
308 unsigned int blksz = BOOTSTRAP_MAP_LIMIT - BOOTSTRAP_MAP_BASE;
309 unsigned int mask = (1L << L2_PAGETABLE_SHIFT) - 1;
311 if ( src + size > BOOTSTRAP_MAP_BASE )
312 blksz >>= 1;
314 while ( size )
315 {
316 module_t mod;
317 unsigned int soffs = src & mask;
318 unsigned int doffs = dst & mask;
319 unsigned int sz;
320 void *d, *s;
322 mod.mod_start = (src - soffs) >> PAGE_SHIFT;
323 mod.mod_end = soffs + size;
324 if ( mod.mod_end > blksz )
325 mod.mod_end = blksz;
326 sz = mod.mod_end - soffs;
327 s = bootstrap_map(&mod);
329 mod.mod_start = (dst - doffs) >> PAGE_SHIFT;
330 mod.mod_end = doffs + size;
331 if ( mod.mod_end > blksz )
332 mod.mod_end = blksz;
333 if ( sz > mod.mod_end - doffs )
334 sz = mod.mod_end - doffs;
335 d = bootstrap_map(&mod);
337 memmove(d + doffs, s + soffs, sz);
339 dst += sz;
340 src += sz;
341 size -= sz;
343 if ( keep )
344 return size ? NULL : d + doffs;
346 bootstrap_map(NULL);
347 }
349 return NULL;
350 }
352 static uint64_t __init consider_modules(
353 uint64_t s, uint64_t e, uint32_t size, const module_t *mod,
354 unsigned int nr_mods, unsigned int this_mod)
355 {
356 unsigned int i;
358 if ( s > e || e - s < size )
359 return 0;
361 for ( i = 0; i < nr_mods ; ++i )
362 {
363 uint64_t start = (uint64_t)mod[i].mod_start << PAGE_SHIFT;
364 uint64_t end = start + PAGE_ALIGN(mod[i].mod_end);
366 if ( i == this_mod )
367 continue;
369 if ( s < end && start < e )
370 {
371 end = consider_modules(end, e, size, mod + i + 1,
372 nr_mods - i - 1, this_mod - i - 1);
373 if ( end )
374 return end;
376 return consider_modules(s, start, size, mod + i + 1,
377 nr_mods - i - 1, this_mod - i - 1);
378 }
379 }
381 return e;
382 }
384 static void __init setup_max_pdx(void)
385 {
386 #ifdef __x86_64__
387 max_pdx = pfn_to_pdx(max_page - 1) + 1;
389 if ( max_pdx > (DIRECTMAP_SIZE >> PAGE_SHIFT) )
390 max_pdx = DIRECTMAP_SIZE >> PAGE_SHIFT;
392 if ( max_pdx > FRAMETABLE_SIZE / sizeof(*frame_table) )
393 max_pdx = FRAMETABLE_SIZE / sizeof(*frame_table);
395 max_page = pdx_to_pfn(max_pdx - 1) + 1;
396 #endif
397 }
399 void set_pdx_range(unsigned long smfn, unsigned long emfn)
400 {
401 unsigned long idx, eidx;
403 idx = pfn_to_pdx(smfn) / PDX_GROUP_COUNT;
404 eidx = (pfn_to_pdx(emfn - 1) + PDX_GROUP_COUNT) / PDX_GROUP_COUNT;
405 for ( ; idx < eidx; ++idx )
406 __set_bit(idx, pdx_group_valid);
407 }
409 /* A temporary copy of the e820 map that we can mess with during bootstrap. */
410 static struct e820map __initdata boot_e820;
412 struct boot_video_info {
413 u8 orig_x; /* 0x00 */
414 u8 orig_y; /* 0x01 */
415 u8 orig_video_mode; /* 0x02 */
416 u8 orig_video_cols; /* 0x03 */
417 u8 orig_video_lines; /* 0x04 */
418 u8 orig_video_isVGA; /* 0x05 */
419 u16 orig_video_points; /* 0x06 */
421 /* VESA graphic mode -- linear frame buffer */
422 u32 capabilities; /* 0x08 */
423 u16 lfb_linelength; /* 0x0c */
424 u16 lfb_width; /* 0x0e */
425 u16 lfb_height; /* 0x10 */
426 u16 lfb_depth; /* 0x12 */
427 u32 lfb_base; /* 0x14 */
428 u32 lfb_size; /* 0x18 */
429 u8 red_size; /* 0x1c */
430 u8 red_pos; /* 0x1d */
431 u8 green_size; /* 0x1e */
432 u8 green_pos; /* 0x1f */
433 u8 blue_size; /* 0x20 */
434 u8 blue_pos; /* 0x21 */
435 u8 rsvd_size; /* 0x22 */
436 u8 rsvd_pos; /* 0x23 */
437 u16 vesapm_seg; /* 0x24 */
438 u16 vesapm_off; /* 0x26 */
439 u16 vesa_attrib; /* 0x28 */
440 };
442 static void __init parse_video_info(void)
443 {
444 struct boot_video_info *bvi = &bootsym(boot_vid_info);
446 if ( (bvi->orig_video_isVGA == 1) && (bvi->orig_video_mode == 3) )
447 {
448 vga_console_info.video_type = XEN_VGATYPE_TEXT_MODE_3;
449 vga_console_info.u.text_mode_3.font_height = bvi->orig_video_points;
450 vga_console_info.u.text_mode_3.cursor_x = bvi->orig_x;
451 vga_console_info.u.text_mode_3.cursor_y = bvi->orig_y;
452 vga_console_info.u.text_mode_3.rows = bvi->orig_video_lines;
453 vga_console_info.u.text_mode_3.columns = bvi->orig_video_cols;
454 }
455 else if ( bvi->orig_video_isVGA == 0x23 )
456 {
457 vga_console_info.video_type = XEN_VGATYPE_VESA_LFB;
458 vga_console_info.u.vesa_lfb.width = bvi->lfb_width;
459 vga_console_info.u.vesa_lfb.height = bvi->lfb_height;
460 vga_console_info.u.vesa_lfb.bytes_per_line = bvi->lfb_linelength;
461 vga_console_info.u.vesa_lfb.bits_per_pixel = bvi->lfb_depth;
462 vga_console_info.u.vesa_lfb.lfb_base = bvi->lfb_base;
463 vga_console_info.u.vesa_lfb.lfb_size = bvi->lfb_size;
464 vga_console_info.u.vesa_lfb.red_pos = bvi->red_pos;
465 vga_console_info.u.vesa_lfb.red_size = bvi->red_size;
466 vga_console_info.u.vesa_lfb.green_pos = bvi->green_pos;
467 vga_console_info.u.vesa_lfb.green_size = bvi->green_size;
468 vga_console_info.u.vesa_lfb.blue_pos = bvi->blue_pos;
469 vga_console_info.u.vesa_lfb.blue_size = bvi->blue_size;
470 vga_console_info.u.vesa_lfb.rsvd_pos = bvi->rsvd_pos;
471 vga_console_info.u.vesa_lfb.rsvd_size = bvi->rsvd_size;
472 vga_console_info.u.vesa_lfb.gbl_caps = bvi->capabilities;
473 vga_console_info.u.vesa_lfb.mode_attrs = bvi->vesa_attrib;
474 }
475 }
477 static void __init kexec_reserve_area(struct e820map *e820)
478 {
479 unsigned long kdump_start = kexec_crash_area.start;
480 unsigned long kdump_size = kexec_crash_area.size;
481 static int is_reserved = 0;
483 kdump_size = (kdump_size + PAGE_SIZE - 1) & PAGE_MASK;
485 if ( (kdump_start == 0) || (kdump_size == 0) || is_reserved )
486 return;
488 is_reserved = 1;
490 if ( !reserve_e820_ram(e820, kdump_start, kdump_start + kdump_size) )
491 {
492 printk("Kdump: DISABLED (failed to reserve %luMB (%lukB) at 0x%lx)"
493 "\n", kdump_size >> 20, kdump_size >> 10, kdump_start);
494 kexec_crash_area.start = kexec_crash_area.size = 0;
495 }
496 else
497 {
498 printk("Kdump: %luMB (%lukB) at 0x%lx\n",
499 kdump_size >> 20, kdump_size >> 10, kdump_start);
500 }
501 }
503 void init_done(void)
504 {
505 /* Free (or page-protect) the init areas. */
506 memset(__init_begin, 0xcc, __init_end - __init_begin); /* int3 poison */
507 free_xen_data(__init_begin, __init_end);
508 printk("Freed %ldkB init memory.\n", (long)(__init_end-__init_begin)>>10);
510 startup_cpu_idle_loop();
511 }
513 static bool_t __init loader_is_grub2(const char *loader_name)
514 {
515 /* GRUB1="GNU GRUB 0.xx"; GRUB2="GRUB 1.xx" */
516 const char *p = strstr(loader_name, "GRUB ");
517 return (p != NULL) && (p[5] != '0');
518 }
520 static char * __init cmdline_cook(char *p, char *loader_name)
521 {
522 p = p ? : "";
524 /* Strip leading whitespace. */
525 while ( *p == ' ' )
526 p++;
528 /* GRUB2 does not include image name as first item on command line. */
529 if ( loader_is_grub2(loader_name) )
530 return p;
532 /* Strip image name plus whitespace. */
533 while ( (*p != ' ') && (*p != '\0') )
534 p++;
535 while ( *p == ' ' )
536 p++;
538 return p;
539 }
541 void __init __start_xen(unsigned long mbi_p)
542 {
543 char *memmap_type = NULL;
544 char *cmdline, *kextra, *loader;
545 unsigned int initrdidx = 1;
546 multiboot_info_t *mbi = __va(mbi_p);
547 module_t *mod = (module_t *)__va(mbi->mods_addr);
548 unsigned long nr_pages, modules_headroom;
549 int i, j, e820_warn = 0, bytes = 0;
550 bool_t acpi_boot_table_init_done = 0;
551 struct ns16550_defaults ns16550 = {
552 .data_bits = 8,
553 .parity = 'n',
554 .stop_bits = 1
555 };
557 percpu_init_areas();
559 set_intr_gate(TRAP_page_fault, &early_page_fault);
561 loader = (mbi->flags & MBI_LOADERNAME)
562 ? (char *)__va(mbi->boot_loader_name) : "unknown";
564 /* Parse the command-line options. */
565 cmdline = cmdline_cook((mbi->flags & MBI_CMDLINE) ?
566 __va(mbi->cmdline) : NULL,
567 loader);
568 if ( (kextra = strstr(cmdline, " -- ")) != NULL )
569 {
570 /*
571 * Options after ' -- ' separator belong to dom0.
572 * 1. Orphan dom0's options from Xen's command line.
573 * 2. Skip all but final leading space from dom0's options.
574 */
575 *kextra = '\0';
576 kextra += 3;
577 while ( kextra[1] == ' ' ) kextra++;
578 }
579 cmdline_parse(cmdline);
581 parse_video_info();
583 set_current((struct vcpu *)0xfffff000); /* debug sanity */
584 idle_vcpu[0] = current;
585 set_processor_id(0); /* needed early, for smp_processor_id() */
586 if ( cpu_has_efer )
587 rdmsrl(MSR_EFER, this_cpu(efer));
588 asm volatile ( "mov %%cr4,%0" : "=r" (this_cpu(cr4)) );
590 smp_prepare_boot_cpu();
592 /* We initialise the serial devices very early so we can get debugging. */
593 ns16550.io_base = 0x3f8;
594 ns16550.irq = 4;
595 ns16550_init(0, &ns16550);
596 ns16550.io_base = 0x2f8;
597 ns16550.irq = 3;
598 ns16550_init(1, &ns16550);
599 console_init_preirq();
601 printk("Bootloader: %s\n", loader);
603 printk("Command line: %s\n", cmdline);
605 printk("Video information:\n");
607 /* Print VGA display mode information. */
608 switch ( vga_console_info.video_type )
609 {
610 case XEN_VGATYPE_TEXT_MODE_3:
611 printk(" VGA is text mode %dx%d, font 8x%d\n",
612 vga_console_info.u.text_mode_3.columns,
613 vga_console_info.u.text_mode_3.rows,
614 vga_console_info.u.text_mode_3.font_height);
615 break;
616 case XEN_VGATYPE_VESA_LFB:
617 printk(" VGA is graphics mode %dx%d, %d bpp\n",
618 vga_console_info.u.vesa_lfb.width,
619 vga_console_info.u.vesa_lfb.height,
620 vga_console_info.u.vesa_lfb.bits_per_pixel);
621 break;
622 default:
623 printk(" No VGA detected\n");
624 break;
625 }
627 /* Print VBE/DDC EDID information. */
628 if ( bootsym(boot_edid_caps) != 0x1313 )
629 {
630 u16 caps = bootsym(boot_edid_caps);
631 printk(" VBE/DDC methods:%s%s%s; ",
632 (caps & 1) ? " V1" : "",
633 (caps & 2) ? " V2" : "",
634 !(caps & 3) ? " none" : "");
635 printk("EDID transfer time: %d seconds\n", caps >> 8);
636 if ( *(u32 *)bootsym(boot_edid_info) == 0x13131313 )
637 {
638 printk(" EDID info not retrieved because ");
639 if ( !(caps & 3) )
640 printk("no DDC retrieval method detected\n");
641 else if ( (caps >> 8) > 5 )
642 printk("takes longer than 5 seconds\n");
643 else
644 printk("of reasons unknown\n");
645 }
646 }
648 printk("Disc information:\n");
649 printk(" Found %d MBR signatures\n",
650 bootsym(boot_mbr_signature_nr));
651 printk(" Found %d EDD information structures\n",
652 bootsym(boot_edd_info_nr));
654 /* Check that we have at least one Multiboot module. */
655 if ( !(mbi->flags & MBI_MODULES) || (mbi->mods_count == 0) )
656 EARLY_FAIL("dom0 kernel not specified. "
657 "Check bootloader configuration.\n");
659 if ( ((unsigned long)cpu0_stack & (STACK_SIZE-1)) != 0 )
660 EARLY_FAIL("Misaligned CPU0 stack.\n");
662 if ( e820_raw_nr != 0 )
663 {
664 memmap_type = "Xen-e820";
665 }
666 else if ( bootsym(lowmem_kb) )
667 {
668 memmap_type = "Xen-e801";
669 e820_raw[0].addr = 0;
670 e820_raw[0].size = bootsym(lowmem_kb) << 10;
671 e820_raw[0].type = E820_RAM;
672 e820_raw[1].addr = 0x100000;
673 e820_raw[1].size = bootsym(highmem_kb) << 10;
674 e820_raw[1].type = E820_RAM;
675 e820_raw_nr = 2;
676 }
677 else if ( mbi->flags & MBI_MEMMAP )
678 {
679 memmap_type = "Multiboot-e820";
680 while ( (bytes < mbi->mmap_length) && (e820_raw_nr < E820MAX) )
681 {
682 memory_map_t *map = __va(mbi->mmap_addr + bytes);
684 /*
685 * This is a gross workaround for a BIOS bug. Some bootloaders do
686 * not write e820 map entries into pre-zeroed memory. This is
687 * okay if the BIOS fills in all fields of the map entry, but
688 * some broken BIOSes do not bother to write the high word of
689 * the length field if the length is smaller than 4GB. We
690 * detect and fix this by flagging sections below 4GB that
691 * appear to be larger than 4GB in size.
692 */
693 if ( (map->base_addr_high == 0) && (map->length_high != 0) )
694 {
695 if ( !e820_warn )
696 {
697 printk("WARNING: Buggy e820 map detected and fixed "
698 "(truncated length fields).\n");
699 e820_warn = 1;
700 }
701 map->length_high = 0;
702 }
704 e820_raw[e820_raw_nr].addr =
705 ((u64)map->base_addr_high << 32) | (u64)map->base_addr_low;
706 e820_raw[e820_raw_nr].size =
707 ((u64)map->length_high << 32) | (u64)map->length_low;
708 e820_raw[e820_raw_nr].type = map->type;
709 e820_raw_nr++;
711 bytes += map->size + 4;
712 }
713 }
714 else if ( mbi->flags & MBI_MEMLIMITS )
715 {
716 memmap_type = "Multiboot-e801";
717 e820_raw[0].addr = 0;
718 e820_raw[0].size = mbi->mem_lower << 10;
719 e820_raw[0].type = E820_RAM;
720 e820_raw[1].addr = 0x100000;
721 e820_raw[1].size = mbi->mem_upper << 10;
722 e820_raw[1].type = E820_RAM;
723 e820_raw_nr = 2;
724 }
725 else
726 {
727 EARLY_FAIL("Bootloader provided no memory information.\n");
728 }
730 /* Sanitise the raw E820 map to produce a final clean version. */
731 max_page = init_e820(memmap_type, e820_raw, &e820_raw_nr);
733 /* Create a temporary copy of the E820 map. */
734 memcpy(&boot_e820, &e820, sizeof(e820));
736 /* Early kexec reservation (explicit static start address). */
737 nr_pages = 0;
738 for ( i = 0; i < e820.nr_map; i++ )
739 if ( e820.map[i].type == E820_RAM )
740 nr_pages += e820.map[i].size >> PAGE_SHIFT;
741 set_kexec_crash_area_size((u64)nr_pages << PAGE_SHIFT);
742 kexec_reserve_area(&boot_e820);
744 initial_images = mod;
745 nr_initial_images = mbi->mods_count;
747 /*
748 * Iterate backwards over all superpage-aligned RAM regions.
749 *
750 * We require superpage alignment because the boot allocator is not yet
751 * initialised. Hence we can only map superpages in the address range
752 * 0 to BOOTSTRAP_DIRECTMAP_END, as this is guaranteed not to require
753 * dynamic allocation of pagetables.
754 *
755 * As well as mapping superpages in that range, in preparation for
756 * initialising the boot allocator, we also look for a region to which
757 * we can relocate the dom0 kernel and other multiboot modules. Also, on
758 * x86/64, we relocate Xen to higher memory.
759 */
760 for ( i = 0; i < mbi->mods_count; i++ )
761 {
762 if ( mod[i].mod_start & (PAGE_SIZE - 1) )
763 EARLY_FAIL("Bootloader didn't honor module alignment request.\n");
764 mod[i].mod_end -= mod[i].mod_start;
765 mod[i].mod_start >>= PAGE_SHIFT;
766 mod[i].reserved = 0;
767 }
769 modules_headroom = bzimage_headroom(bootstrap_map(mod), mod->mod_end);
770 bootstrap_map(NULL);
772 for ( i = boot_e820.nr_map-1; i >= 0; i-- )
773 {
774 uint64_t s, e, mask = (1UL << L2_PAGETABLE_SHIFT) - 1;
775 uint64_t end, limit = ARRAY_SIZE(l2_identmap) << L2_PAGETABLE_SHIFT;
777 /* Superpage-aligned chunks from BOOTSTRAP_MAP_BASE. */
778 s = (boot_e820.map[i].addr + mask) & ~mask;
779 e = (boot_e820.map[i].addr + boot_e820.map[i].size) & ~mask;
780 s = max_t(uint64_t, s, BOOTSTRAP_MAP_BASE);
781 if ( (boot_e820.map[i].type != E820_RAM) || (s >= e) )
782 continue;
784 if ( s < limit )
785 {
786 end = min(e, limit);
787 set_pdx_range(s >> PAGE_SHIFT, end >> PAGE_SHIFT);
788 #ifdef CONFIG_X86_64
789 map_pages_to_xen((unsigned long)__va(s), s >> PAGE_SHIFT,
790 (end - s) >> PAGE_SHIFT, PAGE_HYPERVISOR);
791 #endif
792 }
794 #if defined(CONFIG_X86_64)
795 e = min_t(uint64_t, e, 1ULL << (PAGE_SHIFT + 32));
796 #define reloc_size ((__pa(&_end) + mask) & ~mask)
797 /* Is the region suitable for relocating Xen? */
798 if ( !xen_phys_start && e <= limit )
799 {
800 /* Don't overlap with modules. */
801 end = consider_modules(s, e, reloc_size + mask,
802 mod, mbi->mods_count, -1);
803 end &= ~mask;
804 }
805 else
806 end = 0;
807 if ( end > s )
808 {
809 extern l2_pgentry_t l2_xenmap[];
810 l4_pgentry_t *pl4e;
811 l3_pgentry_t *pl3e;
812 l2_pgentry_t *pl2e;
813 int i, j, k;
814 void *dst;
816 /* Select relocation address. */
817 e = end - reloc_size;
818 xen_phys_start = e;
819 bootsym(trampoline_xen_phys_start) = e;
821 /*
822 * Perform relocation to new physical address.
823 * Before doing so we must sync static/global data with main memory
824 * with a barrier(). After this we must *not* modify static/global
825 * data until after we have switched to the relocated pagetables!
826 */
827 barrier();
828 dst = move_memory(e, 0, (unsigned long)&_end - XEN_VIRT_START, 1);
830 /* Poison low 1MB to detect stray pointers to physical 0-1MB. */
831 memset(dst, 0x55, 1U << 20);
833 /* Walk initial pagetables, relocating page directory entries. */
834 pl4e = __va(__pa(idle_pg_table));
835 for ( i = 0 ; i < L4_PAGETABLE_ENTRIES; i++, pl4e++ )
836 {
837 if ( !(l4e_get_flags(*pl4e) & _PAGE_PRESENT) )
838 continue;
839 *pl4e = l4e_from_intpte(l4e_get_intpte(*pl4e) +
840 xen_phys_start);
841 pl3e = l4e_to_l3e(*pl4e);
842 for ( j = 0; j < L3_PAGETABLE_ENTRIES; j++, pl3e++ )
843 {
844 /* Not present, 1GB mapping, or already relocated? */
845 if ( !(l3e_get_flags(*pl3e) & _PAGE_PRESENT) ||
846 (l3e_get_flags(*pl3e) & _PAGE_PSE) ||
847 (l3e_get_pfn(*pl3e) > 0x1000) )
848 continue;
849 *pl3e = l3e_from_intpte(l3e_get_intpte(*pl3e) +
850 xen_phys_start);
851 pl2e = l3e_to_l2e(*pl3e);
852 for ( k = 0; k < L2_PAGETABLE_ENTRIES; k++, pl2e++ )
853 {
854 /* Not present, PSE, or already relocated? */
855 if ( !(l2e_get_flags(*pl2e) & _PAGE_PRESENT) ||
856 (l2e_get_flags(*pl2e) & _PAGE_PSE) ||
857 (l2e_get_pfn(*pl2e) > 0x1000) )
858 continue;
859 *pl2e = l2e_from_intpte(l2e_get_intpte(*pl2e) +
860 xen_phys_start);
861 }
862 }
863 }
865 /* The only data mappings to be relocated are in the Xen area. */
866 pl2e = __va(__pa(l2_xenmap));
867 *pl2e++ = l2e_from_pfn(xen_phys_start >> PAGE_SHIFT,
868 PAGE_HYPERVISOR | _PAGE_PSE);
869 for ( i = 1; i < L2_PAGETABLE_ENTRIES; i++, pl2e++ )
870 {
871 if ( !(l2e_get_flags(*pl2e) & _PAGE_PRESENT) )
872 continue;
873 *pl2e = l2e_from_intpte(l2e_get_intpte(*pl2e) +
874 xen_phys_start);
875 }
877 /* Re-sync the stack and then switch to relocated pagetables. */
878 asm volatile (
879 "rep movsb ; " /* re-sync the stack */
880 "movq %%cr4,%%rsi ; "
881 "andb $0x7f,%%sil ; "
882 "movq %%rsi,%%cr4 ; " /* CR4.PGE == 0 */
883 "movq %0,%%cr3 ; " /* CR3 == new pagetables */
884 "orb $0x80,%%sil ; "
885 "movq %%rsi,%%cr4 " /* CR4.PGE == 1 */
886 : : "r" (__pa(idle_pg_table)), "S" (cpu0_stack),
887 "D" (__va(__pa(cpu0_stack))), "c" (STACK_SIZE) : "memory" );
889 bootstrap_map(NULL);
890 }
891 #endif
893 /* Is the region suitable for relocating the multiboot modules? */
894 for ( j = mbi->mods_count - 1; j >= 0; j-- )
895 {
896 unsigned long headroom = j ? 0 : modules_headroom;
897 unsigned long size = PAGE_ALIGN(headroom + mod[j].mod_end);
899 if ( mod[j].reserved )
900 continue;
902 /* Don't overlap with other modules. */
903 end = consider_modules(s, e, size, mod, mbi->mods_count, j);
905 if ( s < end &&
906 (headroom ||
907 ((end - size) >> PAGE_SHIFT) > mod[j].mod_start) )
908 {
909 move_memory(end - size + headroom,
910 (uint64_t)mod[j].mod_start << PAGE_SHIFT,
911 mod[j].mod_end, 0);
912 mod[j].mod_start = (end - size) >> PAGE_SHIFT;
913 mod[j].mod_end += headroom;
914 mod[j].reserved = 1;
915 }
916 }
918 #ifdef CONFIG_X86_32
919 /* Confine the kexec area to below 4Gb. */
920 e = min_t(uint64_t, e, 1ULL << 32);
921 #endif
922 /* Don't overlap with modules. */
923 e = consider_modules(s, e, PAGE_ALIGN(kexec_crash_area.size),
924 mod, mbi->mods_count, -1);
925 if ( !kexec_crash_area.start && (s < e) )
926 {
927 e = (e - kexec_crash_area.size) & PAGE_MASK;
928 kexec_crash_area.start = e;
929 }
930 }
932 if ( modules_headroom && !mod->reserved )
933 EARLY_FAIL("Not enough memory to relocate the dom0 kernel image.\n");
934 for ( i = 0; i < mbi->mods_count; ++i )
935 {
936 uint64_t s = (uint64_t)mod[i].mod_start << PAGE_SHIFT;
938 reserve_e820_ram(&boot_e820, s, s + PAGE_ALIGN(mod[i].mod_end));
939 }
941 #if defined(CONFIG_X86_32)
942 xenheap_initial_phys_start = (PFN_UP(__pa(&_end)) + 1) << PAGE_SHIFT;
943 /* Must pass a single mapped page for populating bootmem_region_list. */
944 init_boot_pages(__pa(&_end), xenheap_initial_phys_start);
945 xenheap_phys_end = DIRECTMAP_MBYTES << 20;
946 #else
947 if ( !xen_phys_start )
948 EARLY_FAIL("Not enough memory to relocate Xen.\n");
949 reserve_e820_ram(&boot_e820, __pa(&_start), __pa(&_end));
950 #endif
952 /* Late kexec reservation (dynamic start address). */
953 kexec_reserve_area(&boot_e820);
955 setup_max_pdx();
957 /*
958 * Walk every RAM region and map it in its entirety (on x86/64, at least)
959 * and notify it to the boot allocator.
960 */
961 for ( i = 0; i < boot_e820.nr_map; i++ )
962 {
963 uint64_t s, e, mask = PAGE_SIZE - 1;
964 #ifdef CONFIG_X86_64
965 uint64_t map_s, map_e;
966 #endif
968 /* Only page alignment required now. */
969 s = (boot_e820.map[i].addr + mask) & ~mask;
970 e = (boot_e820.map[i].addr + boot_e820.map[i].size) & ~mask;
971 #if defined(CONFIG_X86_32)
972 s = max_t(uint64_t, s, xenheap_phys_end);
973 #else
974 s = max_t(uint64_t, s, 1<<20);
975 #endif
976 if ( (boot_e820.map[i].type != E820_RAM) || (s >= e) )
977 continue;
979 #ifdef __x86_64__
980 if ( !acpi_boot_table_init_done &&
981 s >= (1ULL << 32) &&
982 !acpi_boot_table_init() )
983 {
984 acpi_boot_table_init_done = 1;
985 srat_parse_regions(s);
986 setup_max_pdx();
987 }
989 if ( pfn_to_pdx((e - 1) >> PAGE_SHIFT) >= max_pdx )
990 {
991 if ( pfn_to_pdx(s >> PAGE_SHIFT) >= max_pdx )
992 {
993 for ( j = i - 1; ; --j )
994 {
995 if ( boot_e820.map[j].type == E820_RAM )
996 break;
997 ASSERT(j);
998 }
999 map_e = boot_e820.map[j].addr + boot_e820.map[j].size;
1000 if ( (map_e >> PAGE_SHIFT) < max_page )
1002 max_page = map_e >> PAGE_SHIFT;
1003 max_pdx = pfn_to_pdx(max_page - 1) + 1;
1005 printk(XENLOG_WARNING "Ignoring inaccessible memory range"
1006 " %013"PRIx64"-%013"PRIx64"\n",
1007 s, e);
1008 continue;
1010 map_e = e;
1011 e = (pdx_to_pfn(max_pdx - 1) + 1ULL) << PAGE_SHIFT;
1012 printk(XENLOG_WARNING "Ignoring inaccessible memory range"
1013 " %013"PRIx64"-%013"PRIx64"\n",
1014 e, map_e);
1016 #endif
1018 set_pdx_range(s >> PAGE_SHIFT, e >> PAGE_SHIFT);
1020 #ifdef CONFIG_X86_64
1021 /* Need to create mappings above BOOTSTRAP_MAP_BASE. */
1022 map_s = max_t(uint64_t, s, BOOTSTRAP_MAP_BASE);
1023 map_e = min_t(uint64_t, e,
1024 ARRAY_SIZE(l2_identmap) << L2_PAGETABLE_SHIFT);
1026 /* Pass mapped memory to allocator /before/ creating new mappings. */
1027 init_boot_pages(s, min(map_s, e));
1028 s = map_s;
1029 if ( s < map_e )
1031 uint64_t mask = (1UL << L2_PAGETABLE_SHIFT) - 1;
1033 map_s = (s + mask) & ~mask;
1034 map_e &= ~mask;
1035 init_boot_pages(map_s, map_e);
1038 if ( map_s > map_e )
1039 map_s = map_e = s;
1041 /* Create new mappings /before/ passing memory to the allocator. */
1042 if ( map_e < e )
1044 map_pages_to_xen((unsigned long)__va(map_e), map_e >> PAGE_SHIFT,
1045 (e - map_e) >> PAGE_SHIFT, PAGE_HYPERVISOR);
1046 init_boot_pages(map_e, e);
1048 if ( s < map_s )
1050 map_pages_to_xen((unsigned long)__va(s), s >> PAGE_SHIFT,
1051 (map_s - s) >> PAGE_SHIFT, PAGE_HYPERVISOR);
1052 init_boot_pages(s, map_s);
1054 #else
1055 init_boot_pages(s, e);
1056 #endif
1059 for ( i = 0; i < mbi->mods_count; ++i )
1061 set_pdx_range(mod[i].mod_start,
1062 mod[i].mod_start + PFN_UP(mod[i].mod_end));
1063 #ifdef CONFIG_X86_64
1064 map_pages_to_xen((unsigned long)mfn_to_virt(mod[i].mod_start),
1065 mod[i].mod_start,
1066 PFN_UP(mod[i].mod_end), PAGE_HYPERVISOR);
1067 #endif
1069 #ifdef CONFIG_X86_64
1070 map_pages_to_xen((unsigned long)__va(kexec_crash_area.start),
1071 kexec_crash_area.start >> PAGE_SHIFT,
1072 PFN_UP(kexec_crash_area.size), PAGE_HYPERVISOR);
1073 #endif
1075 memguard_init();
1077 nr_pages = 0;
1078 for ( i = 0; i < e820.nr_map; i++ )
1079 if ( e820.map[i].type == E820_RAM )
1080 nr_pages += e820.map[i].size >> PAGE_SHIFT;
1081 printk("System RAM: %luMB (%lukB)\n",
1082 nr_pages >> (20 - PAGE_SHIFT),
1083 nr_pages << (PAGE_SHIFT - 10));
1084 total_pages = nr_pages;
1086 /* Sanity check for unwanted bloat of certain hypercall structures. */
1087 BUILD_BUG_ON(sizeof(((struct xen_platform_op *)0)->u) !=
1088 sizeof(((struct xen_platform_op *)0)->u.pad));
1089 BUILD_BUG_ON(sizeof(((struct xen_domctl *)0)->u) !=
1090 sizeof(((struct xen_domctl *)0)->u.pad));
1091 BUILD_BUG_ON(sizeof(((struct xen_sysctl *)0)->u) !=
1092 sizeof(((struct xen_sysctl *)0)->u.pad));
1094 BUILD_BUG_ON(sizeof(start_info_t) > PAGE_SIZE);
1095 BUILD_BUG_ON(sizeof(shared_info_t) > PAGE_SIZE);
1096 BUILD_BUG_ON(sizeof(struct vcpu_info) != 64);
1098 #ifdef CONFIG_COMPAT
1099 BUILD_BUG_ON(sizeof(((struct compat_platform_op *)0)->u) !=
1100 sizeof(((struct compat_platform_op *)0)->u.pad));
1101 BUILD_BUG_ON(sizeof(start_info_compat_t) > PAGE_SIZE);
1102 BUILD_BUG_ON(sizeof(struct compat_vcpu_info) != 64);
1103 #endif
1105 /* Check definitions in public headers match internal defs. */
1106 BUILD_BUG_ON(__HYPERVISOR_VIRT_START != HYPERVISOR_VIRT_START);
1107 #ifdef HYPERVISOR_VIRT_END
1108 BUILD_BUG_ON(__HYPERVISOR_VIRT_END != HYPERVISOR_VIRT_END);
1109 #endif
1110 BUILD_BUG_ON(MACH2PHYS_VIRT_START != RO_MPT_VIRT_START);
1111 BUILD_BUG_ON(MACH2PHYS_VIRT_END != RO_MPT_VIRT_END);
1113 init_frametable();
1115 if ( !acpi_boot_table_init_done )
1116 acpi_boot_table_init();
1118 acpi_numa_init();
1120 numa_initmem_init(0, max_page);
1122 #if defined(CONFIG_X86_32)
1123 /* Initialise the Xen heap. */
1124 for ( nr_pages = i = 0; i < boot_e820.nr_map; i++ )
1126 uint64_t s = boot_e820.map[i].addr;
1127 uint64_t e = s + boot_e820.map[i].size;
1128 s = max_t(uint64_t, s, xenheap_initial_phys_start);
1129 e = min_t(uint64_t, e, xenheap_phys_end);
1130 if ( (boot_e820.map[i].type != E820_RAM) || (s >= e) )
1131 continue;
1132 init_xenheap_pages(s, e);
1133 nr_pages += (e - s) >> PAGE_SHIFT;
1135 printk("Xen heap: %luMB (%lukB)\n",
1136 nr_pages >> (20 - PAGE_SHIFT),
1137 nr_pages << (PAGE_SHIFT - 10));
1138 #endif
1140 end_boot_allocator();
1141 early_boot = 0;
1143 #if defined(CONFIG_X86_64)
1144 vesa_init();
1145 #endif
1147 softirq_init();
1148 tasklet_subsys_init();
1150 early_cpu_init();
1152 paging_init();
1154 tboot_probe();
1156 /* Unmap the first page of CPU0's stack. */
1157 memguard_guard_stack(cpu0_stack);
1159 open_softirq(NEW_TLBFLUSH_CLOCK_PERIOD_SOFTIRQ, new_tlbflush_clock_period);
1161 if ( opt_watchdog )
1162 nmi_watchdog = NMI_LOCAL_APIC;
1164 sort_exception_tables();
1166 find_smp_config();
1168 dmi_scan_machine();
1170 generic_apic_probe();
1172 acpi_boot_init();
1174 if ( smp_found_config )
1175 get_smp_config();
1177 #ifdef CONFIG_X86_64
1178 /* Low mappings were only needed for some BIOS table parsing. */
1179 zap_low_mappings();
1180 #endif
1182 init_apic_mappings();
1184 normalise_cpu_order();
1186 init_cpu_to_node();
1188 x2apic_bsp_setup();
1190 init_IRQ();
1192 xsm_init(&initrdidx, mbi, bootstrap_map);
1194 timer_init();
1196 init_idle_domain();
1198 trap_init();
1200 rcu_init();
1202 early_time_init();
1204 arch_init_memory();
1206 identify_cpu(&boot_cpu_data);
1207 if ( cpu_has_fxsr )
1208 set_in_cr4(X86_CR4_OSFXSR);
1209 if ( cpu_has_xmm )
1210 set_in_cr4(X86_CR4_OSXMMEXCPT);
1212 local_irq_enable();
1214 #ifdef CONFIG_X86_64
1215 vesa_mtrr_init();
1216 #endif
1218 if ( opt_nosmp )
1219 max_cpus = 0;
1221 iommu_setup(); /* setup iommu if available */
1223 smp_prepare_cpus(max_cpus);
1225 spin_debug_enable();
1227 /*
1228 * Initialise higher-level timer functions. We do this fairly late
1229 * (post-SMP) because the time bases and scale factors need to be updated
1230 * regularly, and SMP initialisation can cause a long delay with
1231 * interrupts not yet enabled.
1232 */
1233 init_xen_time();
1235 initialize_keytable();
1237 console_init_postirq();
1239 do_presmp_initcalls();
1241 for_each_present_cpu ( i )
1243 /* Set up cpu_to_node[]. */
1244 srat_detect_node(i);
1245 /* Set up node_to_cpumask based on cpu_to_node[]. */
1246 numa_add_cpu(i);
1248 if ( (num_online_cpus() < max_cpus) && !cpu_online(i) )
1250 int ret = cpu_up(i);
1251 if ( ret != 0 )
1252 printk("Failed to bring up CPU %u (error %d)\n", i, ret);
1256 printk("Brought up %ld CPUs\n", (long)num_online_cpus());
1257 smp_cpus_done(max_cpus);
1259 do_initcalls();
1261 if ( opt_watchdog )
1262 watchdog_enable();
1264 if ( !tboot_protect_mem_regions() )
1265 panic("Could not protect TXT memory regions\n");
1267 /* Create initial domain 0. */
1268 dom0 = domain_create(0, DOMCRF_s3_integrity, DOM0_SSIDREF);
1269 if ( (dom0 == NULL) || (alloc_dom0_vcpu0() == NULL) )
1270 panic("Error creating domain 0\n");
1272 dom0->is_privileged = 1;
1273 dom0->target = NULL;
1275 /* Grab the DOM0 command line. */
1276 cmdline = (char *)(mod[0].string ? __va(mod[0].string) : NULL);
1277 if ( (cmdline != NULL) || (kextra != NULL) )
1279 static char dom0_cmdline[MAX_GUEST_CMDLINE];
1281 cmdline = cmdline_cook(cmdline, loader);
1282 safe_strcpy(dom0_cmdline, cmdline);
1284 if ( kextra != NULL )
1285 /* kextra always includes exactly one leading space. */
1286 safe_strcat(dom0_cmdline, kextra);
1288 /* Append any extra parameters. */
1289 if ( skip_ioapic_setup && !strstr(dom0_cmdline, "noapic") )
1290 safe_strcat(dom0_cmdline, " noapic");
1291 if ( acpi_skip_timer_override &&
1292 !strstr(dom0_cmdline, "acpi_skip_timer_override") )
1293 safe_strcat(dom0_cmdline, " acpi_skip_timer_override");
1294 if ( (strlen(acpi_param) == 0) && acpi_disabled )
1296 printk("ACPI is disabled, notifying Domain 0 (acpi=off)\n");
1297 safe_strcpy(acpi_param, "off");
1299 if ( (strlen(acpi_param) != 0) && !strstr(dom0_cmdline, "acpi=") )
1301 safe_strcat(dom0_cmdline, " acpi=");
1302 safe_strcat(dom0_cmdline, acpi_param);
1305 cmdline = dom0_cmdline;
1308 if ( xen_cpuidle )
1309 xen_processor_pmbits |= XEN_PROCESSOR_PM_CX;
1311 /*
1312 * We're going to setup domain0 using the module(s) that we stashed safely
1313 * above our heap. The second module, if present, is an initrd ramdisk.
1314 */
1315 if ( construct_dom0(dom0, mod, modules_headroom,
1316 (initrdidx > 0) && (initrdidx < mbi->mods_count)
1317 ? mod + initrdidx : NULL,
1318 bootstrap_map, cmdline) != 0)
1319 panic("Could not set up DOM0 guest OS\n");
1321 /* Scrub RAM that is still free and so may go to an unprivileged domain. */
1322 scrub_heap_pages();
1324 init_trace_bufs();
1326 console_endboot();
1328 /* Hide UART from DOM0 if we're using it */
1329 serial_endboot();
1331 domain_unpause_by_systemcontroller(dom0);
1333 reset_stack_and_jump(init_done);
1336 void arch_get_xen_caps(xen_capabilities_info_t *info)
1338 /* Interface name is always xen-3.0-* for Xen-3.x. */
1339 int major = 3, minor = 0;
1340 char s[32];
1342 (*info)[0] = '\0';
1344 #ifdef CONFIG_X86_64
1345 snprintf(s, sizeof(s), "xen-%d.%d-x86_64 ", major, minor);
1346 safe_strcat(*info, s);
1347 #endif
1348 snprintf(s, sizeof(s), "xen-%d.%d-x86_32p ", major, minor);
1349 safe_strcat(*info, s);
1350 if ( hvm_enabled )
1352 snprintf(s, sizeof(s), "hvm-%d.%d-x86_32 ", major, minor);
1353 safe_strcat(*info, s);
1354 snprintf(s, sizeof(s), "hvm-%d.%d-x86_32p ", major, minor);
1355 safe_strcat(*info, s);
1356 #ifdef CONFIG_X86_64
1357 snprintf(s, sizeof(s), "hvm-%d.%d-x86_64 ", major, minor);
1358 safe_strcat(*info, s);
1359 #endif
1363 int xen_in_range(unsigned long mfn)
1365 paddr_t start, end;
1366 int i;
1368 enum { region_s3, region_text, region_bss, nr_regions };
1369 static struct {
1370 paddr_t s, e;
1371 } xen_regions[nr_regions];
1373 /* initialize first time */
1374 if ( !xen_regions[0].s )
1376 /* S3 resume code (and other real mode trampoline code) */
1377 xen_regions[region_s3].s = bootsym_phys(trampoline_start);
1378 xen_regions[region_s3].e = bootsym_phys(trampoline_end);
1379 /* hypervisor code + data */
1380 xen_regions[region_text].s =__pa(&_stext);
1381 xen_regions[region_text].e = __pa(&__init_begin);
1382 /* bss */
1383 xen_regions[region_bss].s = __pa(&__bss_start);
1384 xen_regions[region_bss].e = __pa(&_end);
1387 start = (paddr_t)mfn << PAGE_SHIFT;
1388 end = start + PAGE_SIZE;
1389 for ( i = 0; i < nr_regions; i++ )
1390 if ( (start < xen_regions[i].e) && (end > xen_regions[i].s) )
1391 return 1;
1393 return 0;
1396 /*
1397 * Local variables:
1398 * mode: C
1399 * c-set-style: "BSD"
1400 * c-basic-offset: 4
1401 * tab-width: 4
1402 * indent-tabs-mode: nil
1403 * End:
1404 */