ia64/xen-unstable

annotate xen/arch/x86/setup.c @ 15292:a5ae31a91b10

x86: Return to real-mode when booting primary CPU, and gather
memory-map information (from int15{e820,e801,88} and int12 bios
calls).

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