ia64/xen-unstable

annotate xen/arch/x86/setup.c @ 16165:975811798ffe

Avoid passing uninitialised ACPI tables to dom0 when checksums fail.

If during boot, ACPI checksum failures disable ACPI support in Xen,
pass 'acpi=off' to the domain 0 kernel to avoid a fatal page fault
as domain 0 attempts to access the uninitialized ACPI tables.

Signed-off-by: David Lively <dlively@virtualiron.com>
Signed-off-by: Steve Ofsthun <sofsthun@virtualiron.com>
author Keir Fraser <keir@xensource.com>
date Fri Oct 19 17:47:12 2007 +0100 (2007-10-19)
parents 16f5672879c8
children 4034317507de
rev   line source
kaf24@1452 1 #include <xen/config.h>
kaf24@1452 2 #include <xen/init.h>
kaf24@1452 3 #include <xen/lib.h>
kaf24@1452 4 #include <xen/sched.h>
cl349@5247 5 #include <xen/domain.h>
kaf24@1452 6 #include <xen/serial.h>
kaf24@1506 7 #include <xen/softirq.h>
kaf24@1452 8 #include <xen/acpi.h>
kaf24@3338 9 #include <xen/console.h>
iap10@4287 10 #include <xen/serial.h>
kaf24@3338 11 #include <xen/trace.h>
kaf24@3338 12 #include <xen/multiboot.h>
kaf24@5356 13 #include <xen/domain_page.h>
kfraser@10890 14 #include <xen/version.h>
kaf24@9117 15 #include <xen/gdbstub.h>
kaf24@9818 16 #include <xen/percpu.h>
kfraser@11296 17 #include <xen/hypercall.h>
kfraser@11601 18 #include <xen/keyhandler.h>
kfraser@11971 19 #include <xen/numa.h>
kaf24@13662 20 #include <xen/rcupdate.h>
keir@15298 21 #include <xen/vga.h>
keir@15988 22 #include <xen/dmi.h>
iap10@6721 23 #include <public/version.h>
ack@13291 24 #ifdef CONFIG_COMPAT
ack@13291 25 #include <compat/platform.h>
ack@13291 26 #include <compat/xen.h>
ack@13291 27 #endif
kaf24@1452 28 #include <asm/bitops.h>
kaf24@1452 29 #include <asm/smp.h>
kaf24@1452 30 #include <asm/processor.h>
kaf24@1452 31 #include <asm/mpspec.h>
kaf24@1452 32 #include <asm/apic.h>
kaf24@1452 33 #include <asm/desc.h>
Tim@13909 34 #include <asm/paging.h>
kaf24@3344 35 #include <asm/e820.h>
kfraser@15819 36 #include <xsm/acm/acm_hooks.h>
ian@12677 37 #include <xen/kexec.h>
kfraser@15336 38 #include <asm/edd.h>
kfraser@15815 39 #include <xsm/xsm.h>
kaf24@3338 40
kfraser@15074 41 #if defined(CONFIG_X86_64)
kfraser@15597 42 #define BOOTSTRAP_DIRECTMAP_END (1UL << 32) /* 4GB */
kfraser@15074 43 #define maddr_to_bootstrap_virt(m) maddr_to_virt(m)
kfraser@15074 44 #else
kfraser@15597 45 #define BOOTSTRAP_DIRECTMAP_END (1UL << 30) /* 1GB */
kfraser@15074 46 #define maddr_to_bootstrap_virt(m) ((void *)(long)(m))
kfraser@15074 47 #endif
kfraser@15074 48
kaf24@5211 49 extern void generic_apic_probe(void);
kfraser@11971 50 extern void numa_initmem_init(unsigned long start_pfn, unsigned long end_pfn);
kaf24@5157 51
kfraser@15330 52 extern u16 boot_edid_caps;
kfraser@15330 53 extern u8 boot_edid_info[128];
kfraser@15330 54 extern struct boot_video_info boot_vid_info;
kfraser@15330 55
kaf24@3338 56 /*
kaf24@3338 57 * opt_xenheap_megabytes: Size of Xen heap in megabytes, excluding the
kaf24@8726 58 * page_info table and allocation bitmap.
kaf24@3338 59 */
kaf24@3338 60 static unsigned int opt_xenheap_megabytes = XENHEAP_DEFAULT_MB;
kaf24@4950 61 #if defined(CONFIG_X86_64)
kaf24@3338 62 integer_param("xenheap_megabytes", opt_xenheap_megabytes);
kaf24@3354 63 #endif
kaf24@1452 64
kaf24@5146 65 /* opt_nosmp: If true, secondary processors are ignored. */
kaf24@5900 66 static int opt_nosmp = 0;
kaf24@5146 67 boolean_param("nosmp", opt_nosmp);
kaf24@5146 68
kaf24@5146 69 /* maxcpus: maximum number of CPUs to activate. */
kaf24@5146 70 static unsigned int max_cpus = NR_CPUS;
shand@11156 71 integer_param("maxcpus", max_cpus);
kaf24@5146 72
kaf24@3334 73 /* opt_watchdog: If true, run a watchdog NMI on each processor. */
kaf24@3334 74 static int opt_watchdog = 0;
kaf24@3334 75 boolean_param("watchdog", opt_watchdog);
kaf24@3334 76
kaf24@4850 77 /* **** Linux config option: propagated to domain0. */
kaf24@4850 78 /* "acpi=off": Sisables both ACPI table parsing and interpreter. */
kaf24@4850 79 /* "acpi=force": Override the disable blacklist. */
kaf24@4850 80 /* "acpi=strict": Disables out-of-spec workarounds. */
kaf24@4850 81 /* "acpi=ht": Limit ACPI just to boot-time to enable HT. */
kaf24@4850 82 /* "acpi=noirq": Disables ACPI interrupt routing. */
kaf24@4850 83 static void parse_acpi_param(char *s);
kaf24@4850 84 custom_param("acpi", parse_acpi_param);
kaf24@4850 85
kaf24@4850 86 /* **** Linux config option: propagated to domain0. */
kaf24@4850 87 /* acpi_skip_timer_override: Skip IRQ0 overrides. */
kaf24@4850 88 extern int acpi_skip_timer_override;
kaf24@4850 89 boolean_param("acpi_skip_timer_override", acpi_skip_timer_override);
kaf24@4850 90
kaf24@4850 91 /* **** Linux config option: propagated to domain0. */
kaf24@4850 92 /* noapic: Disable IOAPIC setup. */
kaf24@4850 93 extern int skip_ioapic_setup;
kaf24@4850 94 boolean_param("noapic", skip_ioapic_setup);
kaf24@4850 95
kaf24@3594 96 int early_boot = 1;
kaf24@3594 97
kaf24@5146 98 cpumask_t cpu_present_map;
kaf24@5146 99
kfraser@15074 100 unsigned long xen_phys_start;
kfraser@15074 101
kaf24@5003 102 /* Limits of Xen heap, used to initialise the allocator. */
kaf24@5003 103 unsigned long xenheap_phys_start, xenheap_phys_end;
kaf24@3338 104
kaf24@2298 105 extern void arch_init_memory(void);
kaf24@1589 106 extern void init_IRQ(void);
kaf24@5604 107 extern void early_time_init(void);
kaf24@5167 108 extern void early_cpu_init(void);
kfraser@15747 109 extern void vesa_init(void);
kfraser@15747 110 extern void vesa_mtrr_init(void);
kaf24@1589 111
kaf24@8533 112 struct tss_struct init_tss[NR_CPUS];
kaf24@8533 113
kfraser@15490 114 char __attribute__ ((__section__(".bss.stack_aligned"))) cpu0_stack[STACK_SIZE];
kaf24@5011 115
keir@16144 116 struct cpuinfo_x86 boot_cpu_data = { 0, 0, 0, 0, -1 };
kaf24@1452 117
kaf24@5237 118 #if CONFIG_PAGING_LEVELS > 2
kaf24@1670 119 unsigned long mmu_cr4_features = X86_CR4_PSE | X86_CR4_PGE | X86_CR4_PAE;
kaf24@1670 120 #else
kaf24@5593 121 unsigned long mmu_cr4_features = X86_CR4_PSE;
kaf24@1670 122 #endif
kaf24@1452 123 EXPORT_SYMBOL(mmu_cr4_features);
kaf24@1452 124
kaf24@4818 125 int acpi_disabled;
kaf24@1452 126
kaf24@4850 127 int acpi_force;
kaf24@4850 128 char acpi_param[10] = "";
kfraser@15074 129 static void __init parse_acpi_param(char *s)
kaf24@4850 130 {
kaf24@4850 131 /* Save the parameter so it can be propagated to domain0. */
kfraser@13689 132 safe_strcpy(acpi_param, s);
kaf24@4850 133
kaf24@4850 134 /* Interpret the parameter for use within Xen. */
kaf24@4850 135 if ( !strcmp(s, "off") )
kaf24@4850 136 {
kaf24@4850 137 disable_acpi();
kaf24@4850 138 }
kaf24@4850 139 else if ( !strcmp(s, "force") )
kaf24@4850 140 {
kaf24@4850 141 acpi_force = 1;
kaf24@4850 142 acpi_ht = 1;
kaf24@4850 143 acpi_disabled = 0;
kaf24@4850 144 }
kaf24@4850 145 else if ( !strcmp(s, "strict") )
kaf24@4850 146 {
kaf24@4850 147 acpi_strict = 1;
kaf24@4850 148 }
kaf24@4850 149 else if ( !strcmp(s, "ht") )
kaf24@4850 150 {
kaf24@4850 151 if ( !acpi_force )
kaf24@4850 152 disable_acpi();
kaf24@4850 153 acpi_ht = 1;
kaf24@4850 154 }
kaf24@4850 155 else if ( !strcmp(s, "noirq") )
kaf24@4850 156 {
kaf24@4850 157 acpi_noirq_set();
kaf24@4850 158 }
kaf24@4850 159 }
kaf24@4850 160
kaf24@1452 161 static void __init do_initcalls(void)
kaf24@1452 162 {
kaf24@1452 163 initcall_t *call;
kaf24@1452 164 for ( call = &__initcall_start; call < &__initcall_end; call++ )
kaf24@1452 165 (*call)();
kaf24@1452 166 }
kaf24@1452 167
kfraser@15074 168 #define EARLY_FAIL(f, a...) do { \
kfraser@15074 169 printk( f , ## a ); \
kfraser@15871 170 for ( ; ; ) halt(); \
kfraser@15074 171 } while (0)
kaf24@8459 172
kfraser@15074 173 static unsigned long __initdata initial_images_start, initial_images_end;
kaf24@9067 174
kfraser@15074 175 unsigned long __init initial_images_nrpages(void)
kaf24@9067 176 {
kfraser@15489 177 ASSERT(!(initial_images_start & ~PAGE_MASK));
kfraser@15489 178 ASSERT(!(initial_images_end & ~PAGE_MASK));
kfraser@15489 179 return ((initial_images_end >> PAGE_SHIFT) -
kfraser@15489 180 (initial_images_start >> PAGE_SHIFT));
kaf24@9067 181 }
kaf24@9067 182
kfraser@15074 183 void __init discard_initial_images(void)
kaf24@9067 184 {
kaf24@9067 185 init_domheap_pages(initial_images_start, initial_images_end);
kaf24@9067 186 }
kaf24@9067 187
kaf24@9818 188 extern char __per_cpu_start[], __per_cpu_data_end[], __per_cpu_end[];
kaf24@9818 189
kfraser@11241 190 static void __init percpu_init_areas(void)
kaf24@9818 191 {
kaf24@9818 192 unsigned int i, data_size = __per_cpu_data_end - __per_cpu_start;
kfraser@15074 193 unsigned int first_unused;
kaf24@9818 194
kaf24@9818 195 BUG_ON(data_size > PERCPU_SIZE);
kaf24@9818 196
kfraser@15074 197 /* Initialise per-cpu data area for all possible secondary CPUs. */
kfraser@15074 198 for ( i = 1; (i < NR_CPUS) && cpu_possible(i); i++ )
kfraser@15074 199 memcpy(__per_cpu_start + (i << PERCPU_SHIFT),
kfraser@15074 200 __per_cpu_start,
kfraser@15074 201 data_size);
kaf24@9818 202 first_unused = i;
kaf24@9818 203
kfraser@14340 204 /* Check that there are no holes in cpu_possible_map. */
kaf24@9818 205 for ( ; i < NR_CPUS; i++ )
kfraser@14340 206 BUG_ON(cpu_possible(i));
kaf24@9818 207
kfraser@11241 208 #ifndef MEMORY_GUARD
kaf24@9818 209 init_xenheap_pages(__pa(__per_cpu_start) + (first_unused << PERCPU_SHIFT),
kaf24@9818 210 __pa(__per_cpu_end));
kfraser@11241 211 #endif
keir@15082 212 memguard_guard_range(&__per_cpu_start[first_unused << PERCPU_SHIFT],
keir@15082 213 (NR_CPUS - first_unused) << PERCPU_SHIFT);
keir@15082 214 #if defined(CONFIG_X86_64)
keir@15082 215 /* Also zap the mapping in the 1:1 area. */
keir@15082 216 memguard_guard_range(__va(__pa(__per_cpu_start)) +
keir@15082 217 (first_unused << PERCPU_SHIFT),
keir@15082 218 (NR_CPUS - first_unused) << PERCPU_SHIFT);
keir@15082 219 #endif
kaf24@9818 220 }
kaf24@9818 221
kfraser@11241 222 static void __init init_idle_domain(void)
kfraser@11240 223 {
kfraser@11240 224 struct domain *idle_domain;
kfraser@11240 225
kfraser@11240 226 /* Domain creation requires that scheduler structures are initialised. */
kfraser@11240 227 scheduler_init();
kfraser@11240 228
kfraser@14911 229 idle_domain = domain_create(IDLE_DOMAIN_ID, 0, 0);
kfraser@11240 230 if ( (idle_domain == NULL) || (alloc_vcpu(idle_domain, 0, 0) == NULL) )
kfraser@11240 231 BUG();
kfraser@11240 232
kfraser@11240 233 set_current(idle_domain->vcpu[0]);
kfraser@11240 234 idle_vcpu[0] = this_cpu(curr_vcpu) = current;
kfraser@11240 235
kfraser@11240 236 setup_idle_pagetable();
kfraser@11240 237 }
kfraser@11240 238
kfraser@15074 239 static void __init srat_detect_node(int cpu)
kfraser@11971 240 {
kfraser@11998 241 unsigned node;
kfraser@11998 242 u8 apicid = x86_cpu_to_apicid[cpu];
kfraser@11971 243
kfraser@11998 244 node = apicid_to_node[apicid];
kfraser@11998 245 if ( node == NUMA_NO_NODE )
kfraser@11998 246 node = 0;
kfraser@11998 247 numa_set_node(cpu, node);
kfraser@11971 248
kfraser@11998 249 if ( acpi_numa > 0 )
kfraser@11998 250 printk(KERN_INFO "CPU %d APIC %d -> Node %d\n", cpu, apicid, node);
kfraser@11971 251 }
kfraser@11971 252
kfraser@15740 253 /*
kfraser@15740 254 * Ensure a given physical memory range is present in the bootstrap mappings.
kfraser@15740 255 * Use superpage mappings to ensure that pagetable memory needn't be allocated.
kfraser@15740 256 */
kfraser@15740 257 static void __init bootstrap_map(unsigned long start, unsigned long end)
kfraser@15740 258 {
kfraser@15740 259 unsigned long mask = (1UL << L2_PAGETABLE_SHIFT) - 1;
kfraser@15740 260 start = start & ~mask;
kfraser@15740 261 end = (end + mask) & ~mask;
kfraser@15740 262 if ( end > BOOTSTRAP_DIRECTMAP_END )
kfraser@15740 263 panic("Cannot access memory beyond end of "
kfraser@15740 264 "bootstrap direct-map area\n");
kfraser@15740 265 map_pages_to_xen(
kfraser@15740 266 (unsigned long)maddr_to_bootstrap_virt(start),
kfraser@15740 267 start >> PAGE_SHIFT, (end-start) >> PAGE_SHIFT, PAGE_HYPERVISOR);
kfraser@15740 268 }
kfraser@15740 269
kfraser@15074 270 static void __init move_memory(
kfraser@15074 271 unsigned long dst, unsigned long src_start, unsigned long src_end)
ian@12677 272 {
kfraser@15740 273 bootstrap_map(src_start, src_end);
kfraser@15740 274 bootstrap_map(dst, dst + src_end - src_start);
kfraser@15074 275 memmove(maddr_to_bootstrap_virt(dst),
kfraser@15074 276 maddr_to_bootstrap_virt(src_start),
ian@12677 277 src_end - src_start);
kfraser@15074 278 }
kfraser@15074 279
kfraser@15074 280 /* A temporary copy of the e820 map that we can mess with during bootstrap. */
kfraser@15074 281 static struct e820map __initdata boot_e820;
kfraser@15074 282
keir@15298 283 struct boot_video_info {
keir@15298 284 u8 orig_x; /* 0x00 */
keir@15298 285 u8 orig_y; /* 0x01 */
keir@15298 286 u8 orig_video_mode; /* 0x02 */
keir@15298 287 u8 orig_video_cols; /* 0x03 */
keir@15298 288 u8 orig_video_lines; /* 0x04 */
keir@15298 289 u8 orig_video_isVGA; /* 0x05 */
keir@15298 290 u16 orig_video_points; /* 0x06 */
keir@15298 291
keir@15298 292 /* VESA graphic mode -- linear frame buffer */
keir@15298 293 u32 capabilities; /* 0x08 */
keir@15298 294 u16 lfb_linelength; /* 0x0c */
keir@15298 295 u16 lfb_width; /* 0x0e */
keir@15298 296 u16 lfb_height; /* 0x10 */
keir@15298 297 u16 lfb_depth; /* 0x12 */
keir@15298 298 u32 lfb_base; /* 0x14 */
keir@15298 299 u32 lfb_size; /* 0x18 */
keir@15298 300 u8 red_size; /* 0x1c */
keir@15298 301 u8 red_pos; /* 0x1d */
keir@15298 302 u8 green_size; /* 0x1e */
keir@15298 303 u8 green_pos; /* 0x1f */
keir@15298 304 u8 blue_size; /* 0x20 */
keir@15298 305 u8 blue_pos; /* 0x21 */
keir@15298 306 u8 rsvd_size; /* 0x22 */
keir@15298 307 u8 rsvd_pos; /* 0x23 */
keir@15298 308 u16 vesapm_seg; /* 0x24 */
keir@15298 309 u16 vesapm_off; /* 0x26 */
keir@16124 310 u16 vesa_attrib; /* 0x28 */
keir@15298 311 };
keir@15298 312
keir@15298 313 static void __init parse_video_info(void)
keir@15298 314 {
keir@15298 315 struct boot_video_info *bvi = &bootsym(boot_vid_info);
keir@15298 316
keir@15298 317 if ( (bvi->orig_video_isVGA == 1) && (bvi->orig_video_mode == 3) )
keir@15298 318 {
keir@15298 319 vga_console_info.video_type = XEN_VGATYPE_TEXT_MODE_3;
keir@15298 320 vga_console_info.u.text_mode_3.font_height = bvi->orig_video_points;
keir@15298 321 vga_console_info.u.text_mode_3.cursor_x = bvi->orig_x;
keir@15298 322 vga_console_info.u.text_mode_3.cursor_y = bvi->orig_y;
keir@15298 323 vga_console_info.u.text_mode_3.rows = bvi->orig_video_lines;
keir@15298 324 vga_console_info.u.text_mode_3.columns = bvi->orig_video_cols;
keir@15298 325 }
keir@15298 326 else if ( bvi->orig_video_isVGA == 0x23 )
keir@15298 327 {
keir@15298 328 vga_console_info.video_type = XEN_VGATYPE_VESA_LFB;
keir@15298 329 vga_console_info.u.vesa_lfb.width = bvi->lfb_width;
keir@15298 330 vga_console_info.u.vesa_lfb.height = bvi->lfb_height;
keir@15298 331 vga_console_info.u.vesa_lfb.bytes_per_line = bvi->lfb_linelength;
keir@15298 332 vga_console_info.u.vesa_lfb.bits_per_pixel = bvi->lfb_depth;
keir@15298 333 vga_console_info.u.vesa_lfb.lfb_base = bvi->lfb_base;
keir@15298 334 vga_console_info.u.vesa_lfb.lfb_size = bvi->lfb_size;
keir@15298 335 vga_console_info.u.vesa_lfb.red_pos = bvi->red_pos;
keir@15298 336 vga_console_info.u.vesa_lfb.red_size = bvi->red_size;
keir@15298 337 vga_console_info.u.vesa_lfb.green_pos = bvi->green_pos;
keir@15298 338 vga_console_info.u.vesa_lfb.green_size = bvi->green_size;
keir@15298 339 vga_console_info.u.vesa_lfb.blue_pos = bvi->blue_pos;
keir@15298 340 vga_console_info.u.vesa_lfb.blue_size = bvi->blue_size;
keir@15298 341 vga_console_info.u.vesa_lfb.rsvd_pos = bvi->rsvd_pos;
keir@15298 342 vga_console_info.u.vesa_lfb.rsvd_size = bvi->rsvd_size;
keir@16124 343 vga_console_info.u.vesa_lfb.gbl_caps = bvi->capabilities;
keir@16124 344 vga_console_info.u.vesa_lfb.mode_attrs = bvi->vesa_attrib;
keir@15298 345 }
keir@15298 346 }
keir@15298 347
keir@15082 348 void init_done(void)
keir@15082 349 {
keir@15082 350 extern char __init_begin[], __init_end[];
keir@15082 351
keir@15082 352 /* Free (or page-protect) the init areas. */
keir@15082 353 #ifndef MEMORY_GUARD
keir@15082 354 init_xenheap_pages(__pa(__init_begin), __pa(__init_end));
keir@15082 355 #endif
keir@15082 356 memguard_guard_range(__init_begin, __init_end - __init_begin);
keir@15082 357 #if defined(CONFIG_X86_64)
keir@15082 358 /* Also zap the mapping in the 1:1 area. */
keir@15082 359 memguard_guard_range(__va(__pa(__init_begin)), __init_end - __init_begin);
keir@15082 360 #endif
keir@15082 361 printk("Freed %ldkB init memory.\n", (long)(__init_end-__init_begin)>>10);
keir@15082 362
keir@15082 363 startup_cpu_idle_loop();
keir@15082 364 }
keir@15082 365
kfraser@15796 366 static char * __init cmdline_cook(char *p)
kfraser@15796 367 {
kfraser@15796 368 p = p ? : "";
kfraser@15796 369 while ( *p == ' ' )
kfraser@15796 370 p++;
kfraser@15796 371 while ( (*p != ' ') && (*p != '\0') )
kfraser@15796 372 p++;
kfraser@15796 373 while ( *p == ' ' )
kfraser@15796 374 p++;
kfraser@15796 375 return p;
kfraser@15796 376 }
kfraser@15796 377
kfraser@15379 378 void __init __start_xen(unsigned long mbi_p)
kaf24@1452 379 {
kfraser@15293 380 char *memmap_type = NULL;
kfraser@15796 381 char *cmdline, *kextra;
kaf24@8457 382 unsigned long _initrd_start = 0, _initrd_len = 0;
kaf24@8457 383 unsigned int initrdidx = 1;
kfraser@15379 384 multiboot_info_t *mbi = __va(mbi_p);
kaf24@8457 385 module_t *mod = (module_t *)__va(mbi->mods_addr);
kaf24@6111 386 unsigned long nr_pages, modules_length;
kfraser@15293 387 int i, e820_warn = 0, bytes = 0;
kaf24@5776 388 struct ns16550_defaults ns16550 = {
kaf24@5776 389 .data_bits = 8,
kaf24@5776 390 .parity = 'n',
kaf24@5776 391 .stop_bits = 1
kaf24@5776 392 };
kaf24@3338 393
kfraser@12853 394 extern void early_page_fault(void);
kfraser@12853 395 set_intr_gate(TRAP_page_fault, &early_page_fault);
kfraser@12853 396
kaf24@3338 397 /* Parse the command-line options. */
kfraser@15796 398 cmdline = cmdline_cook((mbi->flags & MBI_CMDLINE) ?
kfraser@15796 399 __va(mbi->cmdline) : NULL);
kfraser@15426 400 if ( (kextra = strstr(cmdline, " -- ")) != NULL )
kfraser@15426 401 {
kfraser@15426 402 /*
kfraser@15426 403 * Options after ' -- ' separator belong to dom0.
kfraser@15426 404 * 1. Orphan dom0's options from Xen's command line.
kfraser@15426 405 * 2. Skip all but final leading space from dom0's options.
kfraser@15426 406 */
kfraser@15426 407 *kextra = '\0';
kfraser@15426 408 kextra += 3;
kfraser@15426 409 while ( kextra[1] == ' ' ) kextra++;
kfraser@15426 410 }
kaf24@9823 411 cmdline_parse(cmdline);
kaf24@3338 412
keir@15298 413 parse_video_info();
keir@15298 414
kaf24@8534 415 set_current((struct vcpu *)0xfffff000); /* debug sanity */
kfraser@11240 416 idle_vcpu[0] = current;
kaf24@8534 417 set_processor_id(0); /* needed early, for smp_processor_id() */
kaf24@3338 418
kaf24@5146 419 smp_prepare_boot_cpu();
kaf24@5146 420
kaf24@3338 421 /* We initialise the serial devices very early so we can get debugging. */
kaf24@5776 422 ns16550.io_base = 0x3f8;
kaf24@5776 423 ns16550.irq = 4;
kaf24@5776 424 ns16550_init(0, &ns16550);
kaf24@5776 425 ns16550.io_base = 0x2f8;
kaf24@5776 426 ns16550.irq = 3;
kaf24@5776 427 ns16550_init(1, &ns16550);
kaf24@5195 428 serial_init_preirq();
kaf24@3338 429
kaf24@3338 430 init_console();
kaf24@3338 431
kfraser@11947 432 printk("Command line: %s\n", cmdline);
kaf24@9823 433
kfraser@15330 434 printk("Video information:\n");
kfraser@15330 435
kfraser@15330 436 /* Print VGA display mode information. */
keir@15298 437 switch ( vga_console_info.video_type )
keir@15298 438 {
keir@15298 439 case XEN_VGATYPE_TEXT_MODE_3:
kfraser@15330 440 printk(" VGA is text mode %dx%d, font 8x%d\n",
keir@15298 441 vga_console_info.u.text_mode_3.columns,
keir@15298 442 vga_console_info.u.text_mode_3.rows,
keir@15298 443 vga_console_info.u.text_mode_3.font_height);
keir@15298 444 break;
keir@15298 445 case XEN_VGATYPE_VESA_LFB:
kfraser@15330 446 printk(" VGA is graphics mode %dx%d, %d bpp\n",
keir@15298 447 vga_console_info.u.vesa_lfb.width,
keir@15298 448 vga_console_info.u.vesa_lfb.height,
keir@15298 449 vga_console_info.u.vesa_lfb.bits_per_pixel);
keir@15298 450 break;
kfraser@15330 451 default:
kfraser@15330 452 printk(" No VGA detected\n");
kfraser@15330 453 break;
kfraser@15330 454 }
kfraser@15330 455
kfraser@15330 456 /* Print VBE/DDC EDID information. */
kfraser@15330 457 if ( bootsym(boot_edid_caps) != 0x1313 )
kfraser@15330 458 {
kfraser@15330 459 u16 caps = bootsym(boot_edid_caps);
kfraser@15330 460 printk(" VBE/DDC methods:%s%s%s; ",
kfraser@15330 461 (caps & 1) ? " V1" : "",
kfraser@15330 462 (caps & 2) ? " V2" : "",
kfraser@15330 463 !(caps & 3) ? " none" : "");
kfraser@15330 464 printk("EDID transfer time: %d seconds\n", caps >> 8);
kfraser@15330 465 if ( *(u32 *)bootsym(boot_edid_info) == 0x13131313 )
kfraser@15330 466 {
kfraser@15330 467 printk(" EDID info not retrieved because ");
kfraser@15330 468 if ( !(caps & 3) )
kfraser@15330 469 printk("no DDC retrieval method detected\n");
kfraser@15330 470 else if ( (caps >> 8) > 5 )
kfraser@15330 471 printk("takes longer than 5 seconds\n");
kfraser@15330 472 else
kfraser@15330 473 printk("of reasons unknown\n");
kfraser@15330 474 }
keir@15298 475 }
keir@15298 476
kfraser@15336 477 printk("Disc information:\n");
kfraser@15336 478 printk(" Found %d MBR signatures\n",
kfraser@15430 479 bootsym(boot_mbr_signature_nr));
kfraser@15336 480 printk(" Found %d EDD information structures\n",
kfraser@15336 481 bootsym(boot_edd_info_nr));
kfraser@15336 482
kaf24@3344 483 /* Check that we have at least one Multiboot module. */
kaf24@3344 484 if ( !(mbi->flags & MBI_MODULES) || (mbi->mods_count == 0) )
kfraser@15074 485 EARLY_FAIL("dom0 kernel not specified. "
kfraser@15074 486 "Check bootloader configuration.\n");
kaf24@5011 487
kaf24@5011 488 if ( ((unsigned long)cpu0_stack & (STACK_SIZE-1)) != 0 )
kfraser@15074 489 EARLY_FAIL("Misaligned CPU0 stack.\n");
kaf24@3338 490
kfraser@11618 491 /*
kfraser@11618 492 * Since there are some stubs getting built on the stacks which use
kfraser@11618 493 * direct calls/jumps, the heap must be confined to the lower 2G so
kfraser@11618 494 * that those branches can reach their targets.
kfraser@11618 495 */
kfraser@11618 496 if ( opt_xenheap_megabytes > 2048 )
kfraser@11618 497 opt_xenheap_megabytes = 2048;
kaf24@3338 498
kfraser@15293 499 if ( e820_raw_nr != 0 )
kfraser@15292 500 {
kfraser@15293 501 memmap_type = "Xen-e820";
kfraser@15292 502 }
kfraser@15293 503 else if ( bootsym(lowmem_kb) )
kfraser@15292 504 {
kfraser@15293 505 memmap_type = "Xen-e801";
kfraser@15292 506 e820_raw[0].addr = 0;
kfraser@15293 507 e820_raw[0].size = bootsym(lowmem_kb) << 10;
kfraser@15292 508 e820_raw[0].type = E820_RAM;
kfraser@15292 509 e820_raw[1].addr = 0x100000;
kfraser@15293 510 e820_raw[1].size = bootsym(highmem_kb) << 10;
kfraser@15292 511 e820_raw[1].type = E820_RAM;
kfraser@15292 512 e820_raw_nr = 2;
kfraser@15292 513 }
kfraser@15292 514 else if ( mbi->flags & MBI_MEMMAP )
kaf24@3344 515 {
kfraser@15293 516 memmap_type = "Multiboot-e820";
keir@15988 517 while ( (bytes < mbi->mmap_length) && (e820_raw_nr < E820MAX) )
kaf24@3344 518 {
kaf24@3344 519 memory_map_t *map = __va(mbi->mmap_addr + bytes);
kaf24@8402 520
kaf24@8402 521 /*
kaf24@8403 522 * This is a gross workaround for a BIOS bug. Some bootloaders do
kaf24@8402 523 * not write e820 map entries into pre-zeroed memory. This is
kaf24@8402 524 * okay if the BIOS fills in all fields of the map entry, but
kaf24@8402 525 * some broken BIOSes do not bother to write the high word of
kaf24@8402 526 * the length field if the length is smaller than 4GB. We
kaf24@8402 527 * detect and fix this by flagging sections below 4GB that
kaf24@8403 528 * appear to be larger than 4GB in size.
kaf24@8402 529 */
kaf24@8403 530 if ( (map->base_addr_high == 0) && (map->length_high != 0) )
kaf24@8402 531 {
kfraser@15292 532 if ( !e820_warn )
kfraser@15292 533 {
kfraser@15292 534 printk("WARNING: Buggy e820 map detected and fixed "
kfraser@15292 535 "(truncated length fields).\n");
kfraser@15292 536 e820_warn = 1;
kfraser@15292 537 }
kaf24@8402 538 map->length_high = 0;
kaf24@8402 539 }
kaf24@8402 540
kaf24@3344 541 e820_raw[e820_raw_nr].addr =
kaf24@3344 542 ((u64)map->base_addr_high << 32) | (u64)map->base_addr_low;
kaf24@3344 543 e820_raw[e820_raw_nr].size =
kaf24@3344 544 ((u64)map->length_high << 32) | (u64)map->length_low;
kfraser@15799 545 e820_raw[e820_raw_nr].type = map->type;
kaf24@3344 546 e820_raw_nr++;
kaf24@8402 547
kaf24@3344 548 bytes += map->size + 4;
kaf24@3344 549 }
kaf24@3344 550 }
kaf24@3344 551 else if ( mbi->flags & MBI_MEMLIMITS )
kaf24@3344 552 {
kfraser@15293 553 memmap_type = "Multiboot-e801";
kaf24@3344 554 e820_raw[0].addr = 0;
kaf24@3344 555 e820_raw[0].size = mbi->mem_lower << 10;
kaf24@3344 556 e820_raw[0].type = E820_RAM;
kaf24@3354 557 e820_raw[1].addr = 0x100000;
kaf24@3354 558 e820_raw[1].size = mbi->mem_upper << 10;
kaf24@3354 559 e820_raw[1].type = E820_RAM;
kaf24@3344 560 e820_raw_nr = 2;
kaf24@3344 561 }
kaf24@3344 562 else
kaf24@3344 563 {
kfraser@15074 564 EARLY_FAIL("Bootloader provided no memory information.\n");
kaf24@3344 565 }
kaf24@3344 566
kaf24@13427 567 /* Sanitise the raw E820 map to produce a final clean version. */
kfraser@15293 568 max_page = init_e820(memmap_type, e820_raw, &e820_raw_nr);
kaf24@3338 569
kfraser@15074 570 /*
kfraser@15074 571 * Create a temporary copy of the E820 map. Truncate it to above 16MB
kfraser@15074 572 * as anything below that is already mapped and has a statically-allocated
kfraser@15074 573 * purpose.
kfraser@15074 574 */
kfraser@15074 575 memcpy(&boot_e820, &e820, sizeof(e820));
kfraser@15074 576 for ( i = 0; i < boot_e820.nr_map; i++ )
kaf24@3338 577 {
kfraser@15074 578 uint64_t s, e, min = 16 << 20; /* 16MB */
kfraser@15074 579 s = boot_e820.map[i].addr;
kfraser@15074 580 e = boot_e820.map[i].addr + boot_e820.map[i].size;
kfraser@15074 581 if ( s >= min )
kfraser@15074 582 continue;
kfraser@15074 583 if ( e > min )
kaf24@6111 584 {
kfraser@15074 585 boot_e820.map[i].addr = min;
kfraser@15074 586 boot_e820.map[i].size = e - min;
kaf24@6111 587 }
kfraser@15074 588 else
kfraser@15074 589 boot_e820.map[i].type = E820_RESERVED;
kaf24@3338 590 }
kaf24@6111 591
kfraser@15074 592 /*
keir@15077 593 * Iterate backwards over all superpage-aligned RAM regions.
kfraser@15074 594 *
kfraser@15074 595 * We require superpage alignment because the boot allocator is not yet
kfraser@15074 596 * initialised. Hence we can only map superpages in the address range
kfraser@15074 597 * 0 to BOOTSTRAP_DIRECTMAP_END, as this is guaranteed not to require
kfraser@15074 598 * dynamic allocation of pagetables.
kfraser@15074 599 *
kfraser@15074 600 * As well as mapping superpages in that range, in preparation for
kfraser@15074 601 * initialising the boot allocator, we also look for a region to which
kfraser@15074 602 * we can relocate the dom0 kernel and other multiboot modules. Also, on
kfraser@15074 603 * x86/64, we relocate Xen to higher memory.
kfraser@15074 604 */
kfraser@15074 605 modules_length = mod[mbi->mods_count-1].mod_end - mod[0].mod_start;
keir@15077 606 for ( i = boot_e820.nr_map-1; i >= 0; i-- )
kfraser@15074 607 {
kfraser@15074 608 uint64_t s, e, mask = (1UL << L2_PAGETABLE_SHIFT) - 1;
kaf24@6134 609
kfraser@15074 610 /* Superpage-aligned chunks up to BOOTSTRAP_DIRECTMAP_END, please. */
kfraser@15074 611 s = (boot_e820.map[i].addr + mask) & ~mask;
kfraser@15074 612 e = (boot_e820.map[i].addr + boot_e820.map[i].size) & ~mask;
kfraser@15074 613 e = min_t(uint64_t, e, BOOTSTRAP_DIRECTMAP_END);
kfraser@15074 614 if ( (boot_e820.map[i].type != E820_RAM) || (s >= e) )
kaf24@3354 615 continue;
kaf24@6111 616
kfraser@15074 617 /* Map the chunk. No memory will need to be allocated to do this. */
kfraser@15074 618 map_pages_to_xen(
kfraser@15074 619 (unsigned long)maddr_to_bootstrap_virt(s),
kfraser@15074 620 s >> PAGE_SHIFT, (e-s) >> PAGE_SHIFT, PAGE_HYPERVISOR);
kaf24@6111 621
kfraser@14084 622 #if defined(CONFIG_X86_64)
kfraser@15074 623 /* Is the region suitable for relocating Xen? */
kfraser@15074 624 if ( !xen_phys_start && (((e-s) >> 20) >= opt_xenheap_megabytes) )
kaf24@5003 625 {
kfraser@15074 626 extern l2_pgentry_t l2_xenmap[];
kfraser@15074 627 l4_pgentry_t *pl4e;
kfraser@15074 628 l3_pgentry_t *pl3e;
kfraser@15074 629 l2_pgentry_t *pl2e;
kfraser@15074 630 int i, j;
kfraser@15074 631
kfraser@15074 632 /* Select relocation address. */
kfraser@15074 633 e = (e - (opt_xenheap_megabytes << 20)) & ~mask;
kfraser@15074 634 xen_phys_start = e;
kfraser@15292 635 bootsym(trampoline_xen_phys_start) = e;
kfraser@15074 636
kfraser@15074 637 /*
kfraser@15074 638 * Perform relocation to new physical address.
kfraser@15074 639 * Before doing so we must sync static/global data with main memory
kfraser@15074 640 * with a barrier(). After this we must *not* modify static/global
kfraser@15074 641 * data until after we have switched to the relocated pagetables!
kfraser@15074 642 */
kfraser@15074 643 barrier();
kfraser@15074 644 move_memory(e, 0, __pa(&_end) - xen_phys_start);
kfraser@15074 645
kfraser@15379 646 /* Poison low 1MB to detect stray pointers to physical 0-1MB. */
kfraser@15379 647 memset(maddr_to_bootstrap_virt(e), 0x55, 1U<<20);
kfraser@15379 648
kfraser@15074 649 /* Walk initial pagetables, relocating page directory entries. */
kfraser@15074 650 pl4e = __va(__pa(idle_pg_table));
kfraser@15074 651 for ( i = 0 ; i < L4_PAGETABLE_ENTRIES; i++, pl4e++ )
kfraser@15074 652 {
kfraser@15074 653 if ( !(l4e_get_flags(*pl4e) & _PAGE_PRESENT) )
kfraser@15074 654 continue;
kfraser@15074 655 *pl4e = l4e_from_intpte(l4e_get_intpte(*pl4e) +
kfraser@15074 656 xen_phys_start);
kfraser@15074 657 pl3e = l4e_to_l3e(*pl4e);
kfraser@15074 658 for ( j = 0; j < L3_PAGETABLE_ENTRIES; j++, pl3e++ )
kfraser@15074 659 {
kfraser@15074 660 /* Not present or already relocated? */
kfraser@15074 661 if ( !(l3e_get_flags(*pl3e) & _PAGE_PRESENT) ||
kfraser@15074 662 (l3e_get_pfn(*pl3e) > 0x1000) )
kfraser@15074 663 continue;
kfraser@15074 664 *pl3e = l3e_from_intpte(l3e_get_intpte(*pl3e) +
kfraser@15074 665 xen_phys_start);
kfraser@15074 666 }
kfraser@15074 667 }
kfraser@15074 668
kfraser@15074 669 /* The only data mappings to be relocated are in the Xen area. */
kfraser@15074 670 pl2e = __va(__pa(l2_xenmap));
kfraser@15074 671 for ( i = 0; i < L2_PAGETABLE_ENTRIES; i++, pl2e++ )
kfraser@15074 672 {
kfraser@15074 673 if ( !(l2e_get_flags(*pl2e) & _PAGE_PRESENT) )
kfraser@15074 674 continue;
kfraser@15074 675 *pl2e = l2e_from_intpte(l2e_get_intpte(*pl2e) +
kfraser@15074 676 xen_phys_start);
kfraser@15074 677 }
kfraser@15074 678
kfraser@15074 679 /* Re-sync the stack and then switch to relocated pagetables. */
kfraser@15074 680 asm volatile (
kfraser@15074 681 "rep movsb ; " /* re-sync the stack */
kfraser@15074 682 "movq %%cr4,%%rsi ; "
kfraser@15074 683 "andb $0x7f,%%sil ; "
kfraser@15074 684 "movq %%rsi,%%cr4 ; " /* CR4.PGE == 0 */
kfraser@15074 685 "movq %0,%%cr3 ; " /* CR3 == new pagetables */
kfraser@15074 686 "orb $0x80,%%sil ; "
kfraser@15074 687 "movq %%rsi,%%cr4 " /* CR4.PGE == 1 */
kfraser@15074 688 : : "r" (__pa(idle_pg_table)), "S" (cpu0_stack),
kfraser@15074 689 "D" (__va(__pa(cpu0_stack))), "c" (STACK_SIZE) : "memory" );
kaf24@5003 690 }
kaf24@5003 691 #endif
keir@15077 692
keir@15077 693 /* Is the region suitable for relocating the multiboot modules? */
keir@15077 694 if ( !initial_images_start && (s < e) && ((e-s) >= modules_length) )
keir@15077 695 {
kfraser@15489 696 initial_images_end = e;
kfraser@15489 697 e = (e - modules_length) & PAGE_MASK;
keir@15077 698 initial_images_start = e;
keir@15077 699 move_memory(initial_images_start,
keir@15077 700 mod[0].mod_start, mod[mbi->mods_count-1].mod_end);
keir@15077 701 }
kfraser@15489 702
kfraser@15489 703 if ( !kexec_crash_area.start && (s < e) &&
kfraser@15489 704 ((e-s) >= kexec_crash_area.size) )
kfraser@15489 705 {
kfraser@15489 706 e = (e - kexec_crash_area.size) & PAGE_MASK;
kfraser@15489 707 kexec_crash_area.start = e;
kfraser@15489 708 }
kaf24@3354 709 }
kaf24@3354 710
kfraser@15074 711 if ( !initial_images_start )
kfraser@15074 712 EARLY_FAIL("Not enough memory to relocate the dom0 kernel image.\n");
keir@15988 713 reserve_e820_ram(&boot_e820, initial_images_start, initial_images_end);
kfraser@15074 714
kfraser@15074 715 /*
kfraser@15074 716 * With modules (and Xen itself, on x86/64) relocated out of the way, we
kfraser@15074 717 * can now initialise the boot allocator with some memory.
kfraser@15074 718 */
kfraser@15074 719 xenheap_phys_start = init_boot_allocator(__pa(&_end));
kfraser@15074 720 xenheap_phys_end = opt_xenheap_megabytes << 20;
kfraser@15074 721 #if defined(CONFIG_X86_64)
kfraser@15074 722 if ( !xen_phys_start )
kfraser@15074 723 EARLY_FAIL("Not enough memory to relocate Xen.\n");
kfraser@15074 724 xenheap_phys_end += xen_phys_start;
keir@15988 725 reserve_e820_ram(&boot_e820, xen_phys_start,
keir@15988 726 xen_phys_start + (opt_xenheap_megabytes<<20));
kfraser@15074 727 init_boot_pages(1<<20, 16<<20); /* Initial seed: 15MB */
kfraser@15074 728 #else
kfraser@15074 729 init_boot_pages(xenheap_phys_end, 16<<20); /* Initial seed: 4MB */
kfraser@15074 730 #endif
kfraser@15074 731
kfraser@15489 732 if ( kexec_crash_area.size != 0 )
kfraser@15489 733 {
kfraser@15489 734 unsigned long kdump_start = kexec_crash_area.start;
kfraser@15489 735 unsigned long kdump_size = kexec_crash_area.size;
kfraser@15489 736
kfraser@15489 737 kdump_size = (kdump_size + PAGE_SIZE - 1) & PAGE_MASK;
kfraser@15489 738
keir@15988 739 if ( !reserve_e820_ram(&boot_e820, kdump_start, kdump_size) )
kfraser@15489 740 {
kfraser@15489 741 printk("Kdump: DISABLED (failed to reserve %luMB (%lukB) at 0x%lx)"
kfraser@15489 742 "\n", kdump_size >> 20, kdump_size >> 10, kdump_start);
kfraser@15489 743 kexec_crash_area.start = kexec_crash_area.size = 0;
kfraser@15489 744 }
kfraser@15489 745 else
kfraser@15489 746 {
kfraser@15489 747 printk("Kdump: %luMB (%lukB) at 0x%lx\n",
kfraser@15489 748 kdump_size >> 20, kdump_size >> 10, kdump_start);
kfraser@15489 749 }
kfraser@15489 750 }
kfraser@15489 751
kfraser@15074 752 /*
kfraser@15074 753 * With the boot allocator now seeded, we can walk every RAM region and
kfraser@15074 754 * map it in its entirety (on x86/64, at least) and notify it to the
kfraser@15074 755 * boot allocator.
kfraser@15074 756 */
kfraser@15074 757 for ( i = 0; i < boot_e820.nr_map; i++ )
kfraser@15074 758 {
kfraser@15074 759 uint64_t s, e, map_e, mask = PAGE_SIZE - 1;
kfraser@15074 760
kfraser@15074 761 /* Only page alignment required now. */
kfraser@15074 762 s = (boot_e820.map[i].addr + mask) & ~mask;
kfraser@15074 763 e = (boot_e820.map[i].addr + boot_e820.map[i].size) & ~mask;
kfraser@15074 764 if ( (boot_e820.map[i].type != E820_RAM) || (s >= e) )
kfraser@15074 765 continue;
kfraser@15074 766
kfraser@15074 767 /* Perform the mapping (truncated in 32-bit mode). */
kfraser@15074 768 map_e = e;
kfraser@15074 769 #if defined(CONFIG_X86_32)
kfraser@15074 770 map_e = min_t(uint64_t, map_e, BOOTSTRAP_DIRECTMAP_END);
kfraser@15074 771 #endif
kfraser@15074 772 if ( s < map_e )
kfraser@15074 773 map_pages_to_xen(
kfraser@15074 774 (unsigned long)maddr_to_bootstrap_virt(s),
kfraser@15074 775 s >> PAGE_SHIFT, (map_e-s) >> PAGE_SHIFT, PAGE_HYPERVISOR);
kfraser@15074 776
kfraser@15074 777 init_boot_pages(s, e);
kfraser@15074 778 }
kfraser@15074 779
kaf24@5003 780 memguard_init();
kaf24@4950 781
kfraser@15074 782 nr_pages = 0;
kfraser@15074 783 for ( i = 0; i < e820.nr_map; i++ )
kfraser@15074 784 if ( e820.map[i].type == E820_RAM )
kfraser@15074 785 nr_pages += e820.map[i].size >> PAGE_SHIFT;
ian@12681 786 printk("System RAM: %luMB (%lukB)\n",
kaf24@3354 787 nr_pages >> (20 - PAGE_SHIFT),
kaf24@3354 788 nr_pages << (PAGE_SHIFT - 10));
kaf24@7220 789 total_pages = nr_pages;
kaf24@3354 790
kfraser@11296 791 /* Sanity check for unwanted bloat of certain hypercall structures. */
kfraser@11296 792 BUILD_BUG_ON(sizeof(((struct xen_platform_op *)0)->u) !=
kfraser@11296 793 sizeof(((struct xen_platform_op *)0)->u.pad));
kfraser@11296 794 BUILD_BUG_ON(sizeof(((struct xen_domctl *)0)->u) !=
kfraser@11296 795 sizeof(((struct xen_domctl *)0)->u.pad));
kfraser@11296 796 BUILD_BUG_ON(sizeof(((struct xen_sysctl *)0)->u) !=
kfraser@11296 797 sizeof(((struct xen_sysctl *)0)->u.pad));
kaf24@7388 798
kaf24@9878 799 BUILD_BUG_ON(sizeof(start_info_t) > PAGE_SIZE);
kaf24@9878 800 BUILD_BUG_ON(sizeof(shared_info_t) > PAGE_SIZE);
ack@13292 801 BUILD_BUG_ON(sizeof(struct vcpu_info) != 64);
kaf24@7744 802
ack@13291 803 #ifdef CONFIG_COMPAT
ack@13291 804 BUILD_BUG_ON(sizeof(((struct compat_platform_op *)0)->u) !=
ack@13291 805 sizeof(((struct compat_platform_op *)0)->u.pad));
ack@13291 806 BUILD_BUG_ON(sizeof(start_info_compat_t) > PAGE_SIZE);
ack@13292 807 BUILD_BUG_ON(sizeof(struct compat_vcpu_info) != 64);
ack@13291 808 #endif
ack@13291 809
kfraser@10492 810 /* Check definitions in public headers match internal defs. */
kaf24@9878 811 BUILD_BUG_ON(__HYPERVISOR_VIRT_START != HYPERVISOR_VIRT_START);
kaf24@8521 812 #ifdef HYPERVISOR_VIRT_END
kaf24@9878 813 BUILD_BUG_ON(__HYPERVISOR_VIRT_END != HYPERVISOR_VIRT_END);
kaf24@8521 814 #endif
kfraser@10492 815 BUILD_BUG_ON(MACH2PHYS_VIRT_START != RO_MPT_VIRT_START);
kfraser@10492 816 BUILD_BUG_ON(MACH2PHYS_VIRT_END != RO_MPT_VIRT_END);
kaf24@8521 817
kaf24@3354 818 init_frametable();
kaf24@3338 819
kfraser@11971 820 acpi_boot_table_init();
kfraser@11971 821
kfraser@11971 822 acpi_numa_init();
kfraser@11971 823
kfraser@11971 824 numa_initmem_init(0, max_page);
kfraser@11971 825
kaf24@6111 826 /* Initialise the Xen heap, skipping RAM holes. */
kfraser@15074 827 init_xenheap_pages(xenheap_phys_start, xenheap_phys_end);
kfraser@15074 828 nr_pages = (xenheap_phys_end - xenheap_phys_start) >> PAGE_SHIFT;
kfraser@15074 829 #ifdef __x86_64__
kfraser@15074 830 init_xenheap_pages(xen_phys_start, __pa(&_start));
kfraser@15074 831 nr_pages += (__pa(&_start) - xen_phys_start) >> PAGE_SHIFT;
kfraser@15747 832 vesa_init();
kfraser@15074 833 #endif
kfraser@15074 834 xenheap_phys_start = xen_phys_start;
kaf24@6111 835 printk("Xen heap: %luMB (%lukB)\n",
kaf24@6111 836 nr_pages >> (20 - PAGE_SHIFT),
kaf24@6111 837 nr_pages << (PAGE_SHIFT - 10));
kaf24@3338 838
keir@14680 839 end_boot_allocator();
keir@14680 840
kaf24@3594 841 early_boot = 0;
kaf24@3338 842
kaf24@8459 843 early_cpu_init();
kaf24@8459 844
kaf24@8459 845 paging_init();
kaf24@8459 846
kaf24@8459 847 /* Unmap the first page of CPU0's stack. */
kaf24@8459 848 memguard_guard_stack(cpu0_stack);
kaf24@8459 849
kaf24@8459 850 open_softirq(NEW_TLBFLUSH_CLOCK_PERIOD_SOFTIRQ, new_tlbflush_clock_period);
kaf24@8459 851
kaf24@8459 852 if ( opt_watchdog )
kaf24@8459 853 nmi_watchdog = NMI_LOCAL_APIC;
kaf24@8459 854
kaf24@8459 855 sort_exception_tables();
kaf24@8459 856
kaf24@8459 857 find_smp_config();
kaf24@8459 858
kaf24@8459 859 dmi_scan_machine();
kaf24@8459 860
kaf24@8459 861 generic_apic_probe();
kaf24@8459 862
kaf24@8459 863 acpi_boot_init();
kaf24@8459 864
kfraser@11971 865 init_cpu_to_node();
kfraser@11971 866
kfraser@11241 867 if ( smp_found_config )
kaf24@8459 868 get_smp_config();
kaf24@8459 869
keir@15083 870 #ifdef CONFIG_X86_64
keir@15083 871 /* Low mappings were only needed for some BIOS table parsing. */
keir@15083 872 zap_low_mappings();
keir@15083 873 #endif
keir@15083 874
kaf24@8459 875 init_apic_mappings();
kaf24@8459 876
kaf24@8459 877 init_IRQ();
kaf24@8459 878
kfraser@11241 879 percpu_init_areas();
kfraser@11241 880
kfraser@15815 881 xsm_init(&initrdidx, mbi, initial_images_start);
kfraser@15815 882
kfraser@11240 883 init_idle_domain();
kfraser@11240 884
kaf24@8459 885 trap_init();
kaf24@8459 886
kaf24@13662 887 rcu_init();
kaf24@13662 888
kaf24@8586 889 timer_init();
kaf24@8459 890
kaf24@8459 891 early_time_init();
kaf24@8459 892
kaf24@8459 893 arch_init_memory();
kaf24@8459 894
kaf24@8459 895 identify_cpu(&boot_cpu_data);
kaf24@8459 896 if ( cpu_has_fxsr )
kaf24@8459 897 set_in_cr4(X86_CR4_OSFXSR);
kaf24@8459 898 if ( cpu_has_xmm )
kaf24@8459 899 set_in_cr4(X86_CR4_OSXMMEXCPT);
kfraser@15747 900 #ifdef CONFIG_X86_64
kfraser@15747 901 vesa_mtrr_init();
kfraser@15747 902 #endif
kaf24@8459 903
kaf24@8459 904 if ( opt_nosmp )
kaf24@8459 905 max_cpus = 0;
kaf24@8459 906
kaf24@8459 907 smp_prepare_cpus(max_cpus);
kaf24@8459 908
kaf24@8459 909 /*
kaf24@8459 910 * Initialise higher-level timer functions. We do this fairly late
kaf24@8459 911 * (post-SMP) because the time bases and scale factors need to be updated
kaf24@8459 912 * regularly, and SMP initialisation can cause a long delay with
kaf24@8459 913 * interrupts not yet enabled.
kaf24@8459 914 */
kaf24@8459 915 init_xen_time();
kaf24@8459 916
kaf24@8459 917 initialize_keytable();
kaf24@8459 918
kaf24@8459 919 serial_init_postirq();
kaf24@8459 920
kaf24@8459 921 BUG_ON(!local_irq_is_enabled());
kaf24@8459 922
kaf24@8459 923 for_each_present_cpu ( i )
kaf24@8459 924 {
kaf24@8459 925 if ( num_online_cpus() >= max_cpus )
kaf24@8459 926 break;
kaf24@8459 927 if ( !cpu_online(i) )
kaf24@13662 928 {
kaf24@13662 929 rcu_online_cpu(i);
kaf24@8459 930 __cpu_up(i);
kaf24@13662 931 }
kfraser@11971 932
kfraser@11998 933 /* Set up cpu_to_node[]. */
kfraser@11971 934 srat_detect_node(i);
kfraser@11998 935 /* Set up node_to_cpumask based on cpu_to_node[]. */
kfraser@11971 936 numa_add_cpu(i);
kaf24@8459 937 }
kaf24@8459 938
kaf24@8459 939 printk("Brought up %ld CPUs\n", (long)num_online_cpus());
kaf24@8459 940 smp_cpus_done(max_cpus);
kaf24@8459 941
kaf24@9117 942 initialise_gdb(); /* could be moved earlier */
kaf24@9117 943
kaf24@8459 944 do_initcalls();
kaf24@8459 945
kaf24@8594 946 if ( opt_watchdog )
kaf24@8594 947 watchdog_enable();
kaf24@8459 948
kaf24@8459 949 /* Create initial domain 0. */
kfraser@14911 950 dom0 = domain_create(0, 0, DOM0_SSIDREF);
kfraser@10655 951 if ( (dom0 == NULL) || (alloc_vcpu(dom0, 0, 0) == NULL) )
kaf24@8459 952 panic("Error creating domain 0\n");
kaf24@8459 953
kfraser@12210 954 dom0->is_privileged = 1;
kfraser@12210 955
kaf24@8459 956 /* Grab the DOM0 command line. */
kaf24@8459 957 cmdline = (char *)(mod[0].string ? __va(mod[0].string) : NULL);
kfraser@15426 958 if ( (cmdline != NULL) || (kextra != NULL) )
kaf24@8459 959 {
kaf24@8459 960 static char dom0_cmdline[MAX_GUEST_CMDLINE];
kaf24@8459 961
kfraser@15796 962 cmdline = cmdline_cook(cmdline);
kfraser@15796 963 safe_strcpy(dom0_cmdline, cmdline);
kaf24@8459 964
kfraser@15426 965 if ( kextra != NULL )
kfraser@15426 966 /* kextra always includes exactly one leading space. */
kfraser@15426 967 safe_strcat(dom0_cmdline, kextra);
kfraser@15426 968
kaf24@8459 969 /* Append any extra parameters. */
kfraser@13691 970 if ( skip_ioapic_setup && !strstr(dom0_cmdline, "noapic") )
kfraser@13691 971 safe_strcat(dom0_cmdline, " noapic");
kaf24@8459 972 if ( acpi_skip_timer_override &&
kfraser@13691 973 !strstr(dom0_cmdline, "acpi_skip_timer_override") )
kfraser@13691 974 safe_strcat(dom0_cmdline, " acpi_skip_timer_override");
keir@16165 975 if ( (strlen(acpi_param) == 0) && acpi_disabled )
keir@16165 976 {
keir@16165 977 printk("ACPI is disabled, notifying Domain 0 (acpi=off)\n");
keir@16165 978 safe_strcpy(acpi_param, "off");
keir@16165 979 }
kfraser@13691 980 if ( (strlen(acpi_param) != 0) && !strstr(dom0_cmdline, "acpi=") )
kaf24@8459 981 {
kfraser@13691 982 safe_strcat(dom0_cmdline, " acpi=");
kfraser@13691 983 safe_strcat(dom0_cmdline, acpi_param);
kaf24@8459 984 }
kfraser@13691 985
kfraser@13691 986 cmdline = dom0_cmdline;
kaf24@8459 987 }
kaf24@8459 988
kaf24@8459 989 if ( (initrdidx > 0) && (initrdidx < mbi->mods_count) )
kaf24@8459 990 {
kaf24@8459 991 _initrd_start = initial_images_start +
kaf24@8459 992 (mod[initrdidx].mod_start - mod[0].mod_start);
kaf24@8459 993 _initrd_len = mod[initrdidx].mod_end - mod[initrdidx].mod_start;
kaf24@8459 994 }
kaf24@8459 995
kfraser@15929 996 iommu_setup();
kfraser@15929 997
keir@15957 998 amd_iommu_detect();
keir@15957 999
kaf24@8459 1000 /*
kaf24@8459 1001 * We're going to setup domain0 using the module(s) that we stashed safely
kaf24@8459 1002 * above our heap. The second module, if present, is an initrd ramdisk.
kaf24@8459 1003 */
kaf24@8459 1004 if ( construct_dom0(dom0,
kaf24@8459 1005 initial_images_start,
kaf24@8459 1006 mod[0].mod_end-mod[0].mod_start,
kaf24@8459 1007 _initrd_start,
kaf24@8459 1008 _initrd_len,
kaf24@8459 1009 cmdline) != 0)
kaf24@8459 1010 panic("Could not set up DOM0 guest OS\n");
kaf24@8459 1011
kaf24@8459 1012 /* Scrub RAM that is still free and so may go to an unprivileged domain. */
kaf24@8459 1013 scrub_heap_pages();
kaf24@8459 1014
kaf24@8459 1015 init_trace_bufs();
kaf24@8459 1016
kaf24@10502 1017 console_endboot();
kaf24@8459 1018
kaf24@8459 1019 /* Hide UART from DOM0 if we're using it */
kaf24@8459 1020 serial_endboot();
kaf24@8459 1021
kaf24@8459 1022 domain_unpause_by_systemcontroller(dom0);
kaf24@8459 1023
keir@15082 1024 reset_stack_and_jump(init_done);
kaf24@8459 1025 }
kaf24@8459 1026
ian@13763 1027 void arch_get_xen_caps(xen_capabilities_info_t *info)
iap10@6721 1028 {
kfraser@14997 1029 /* Interface name is always xen-3.0-* for Xen-3.x. */
kfraser@14997 1030 int major = 3, minor = 0;
keir@13754 1031 char s[32];
keir@13754 1032
ian@13763 1033 (*info)[0] = '\0';
iap10@6721 1034
kaf24@6725 1035 #if defined(CONFIG_X86_32) && !defined(CONFIG_X86_PAE)
kaf24@6725 1036
keir@13754 1037 snprintf(s, sizeof(s), "xen-%d.%d-x86_32 ", major, minor);
ian@13763 1038 safe_strcat(*info, s);
keir@13754 1039 if ( hvm_enabled )
keir@13754 1040 {
keir@13754 1041 snprintf(s, sizeof(s), "hvm-%d.%d-x86_32 ", major, minor);
ian@13763 1042 safe_strcat(*info, s);
kfraser@13685 1043 }
kaf24@6725 1044
kaf24@6725 1045 #elif defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
kaf24@6725 1046
keir@13754 1047 snprintf(s, sizeof(s), "xen-%d.%d-x86_32p ", major, minor);
ian@13763 1048 safe_strcat(*info, s);
kaf24@6725 1049 if ( hvm_enabled )
iap10@6721 1050 {
keir@13754 1051 snprintf(s, sizeof(s), "hvm-%d.%d-x86_32 ", major, minor);
ian@13763 1052 safe_strcat(*info, s);
keir@13754 1053 snprintf(s, sizeof(s), "hvm-%d.%d-x86_32p ", major, minor);
ian@13763 1054 safe_strcat(*info, s);
iap10@6721 1055 }
iap10@6721 1056
kaf24@6725 1057 #elif defined(CONFIG_X86_64)
iap10@6721 1058
keir@13754 1059 snprintf(s, sizeof(s), "xen-%d.%d-x86_64 ", major, minor);
ian@13763 1060 safe_strcat(*info, s);
ack@13288 1061 #ifdef CONFIG_COMPAT
keir@13754 1062 snprintf(s, sizeof(s), "xen-%d.%d-x86_32p ", major, minor);
ian@13763 1063 safe_strcat(*info, s);
ack@13288 1064 #endif
kaf24@6725 1065 if ( hvm_enabled )
iap10@6721 1066 {
keir@13754 1067 snprintf(s, sizeof(s), "hvm-%d.%d-x86_32 ", major, minor);
ian@13763 1068 safe_strcat(*info, s);
keir@13754 1069 snprintf(s, sizeof(s), "hvm-%d.%d-x86_32p ", major, minor);
ian@13763 1070 safe_strcat(*info, s);
keir@13754 1071 snprintf(s, sizeof(s), "hvm-%d.%d-x86_64 ", major, minor);
ian@13763 1072 safe_strcat(*info, s);
iap10@6721 1073 }
kaf24@6725 1074
iap10@6721 1075 #endif
iap10@6721 1076 }
iap10@6721 1077
kaf24@3914 1078 /*
kaf24@3914 1079 * Local variables:
kaf24@3914 1080 * mode: C
kaf24@3914 1081 * c-set-style: "BSD"
kaf24@3914 1082 * c-basic-offset: 4
kaf24@3914 1083 * tab-width: 4
kaf24@3914 1084 * indent-tabs-mode: nil
kaf24@3988 1085 * End:
kaf24@3914 1086 */