ia64/xen-unstable

annotate xen/arch/x86/setup.c @ 15083:03a13457d993

x86: Improve zap_low_mappings.

Do it earlier on x86/64, properly free non-superpages on x86/32, and
leave a mapping of the boot trampoline (0x90000-0xA0000) in place.

Signed-off-by: Keir Fraser <keir@xensource.com>
author Keir Fraser <keir@xensource.com>
date Sat May 12 12:07:01 2007 +0100 (2007-05-12)
parents 759d924af6d8
children a5ae31a91b10
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
kaf24@3344 398 if ( mbi->flags & MBI_MEMMAP )
kaf24@3344 399 {
kaf24@3344 400 while ( bytes < mbi->mmap_length )
kaf24@3344 401 {
kaf24@3344 402 memory_map_t *map = __va(mbi->mmap_addr + bytes);
kaf24@8402 403
kaf24@8402 404 /*
kaf24@8403 405 * This is a gross workaround for a BIOS bug. Some bootloaders do
kaf24@8402 406 * not write e820 map entries into pre-zeroed memory. This is
kaf24@8402 407 * okay if the BIOS fills in all fields of the map entry, but
kaf24@8402 408 * some broken BIOSes do not bother to write the high word of
kaf24@8402 409 * the length field if the length is smaller than 4GB. We
kaf24@8402 410 * detect and fix this by flagging sections below 4GB that
kaf24@8403 411 * appear to be larger than 4GB in size.
kaf24@8402 412 */
kaf24@8403 413 if ( (map->base_addr_high == 0) && (map->length_high != 0) )
kaf24@8402 414 {
kaf24@8402 415 e820_warn = 1;
kaf24@8402 416 map->length_high = 0;
kaf24@8402 417 }
kaf24@8402 418
kaf24@3344 419 e820_raw[e820_raw_nr].addr =
kaf24@3344 420 ((u64)map->base_addr_high << 32) | (u64)map->base_addr_low;
kaf24@3344 421 e820_raw[e820_raw_nr].size =
kaf24@3344 422 ((u64)map->length_high << 32) | (u64)map->length_low;
kaf24@3344 423 e820_raw[e820_raw_nr].type =
kfraser@12226 424 (map->type > E820_NVS) ? E820_RESERVED : map->type;
kaf24@3344 425 e820_raw_nr++;
kaf24@8402 426
kaf24@3344 427 bytes += map->size + 4;
kaf24@3344 428 }
kaf24@3344 429 }
kaf24@3344 430 else if ( mbi->flags & MBI_MEMLIMITS )
kaf24@3344 431 {
kaf24@3344 432 e820_raw[0].addr = 0;
kaf24@3344 433 e820_raw[0].size = mbi->mem_lower << 10;
kaf24@3344 434 e820_raw[0].type = E820_RAM;
kaf24@3354 435 e820_raw[1].addr = 0x100000;
kaf24@3354 436 e820_raw[1].size = mbi->mem_upper << 10;
kaf24@3354 437 e820_raw[1].type = E820_RAM;
kaf24@3344 438 e820_raw_nr = 2;
kaf24@3344 439 }
kaf24@3344 440 else
kaf24@3344 441 {
kfraser@15074 442 EARLY_FAIL("Bootloader provided no memory information.\n");
kaf24@3344 443 }
kaf24@3344 444
kaf24@8402 445 if ( e820_warn )
kaf24@8402 446 printk("WARNING: Buggy e820 map detected and fixed "
kaf24@8402 447 "(truncated length fields).\n");
kaf24@8402 448
kaf24@13427 449 /* Ensure that all E820 RAM regions are page-aligned and -sized. */
kaf24@13427 450 for ( i = 0; i < e820_raw_nr; i++ )
kaf24@13427 451 {
kaf24@13427 452 uint64_t s, e;
kaf24@13427 453 if ( e820_raw[i].type != E820_RAM )
kaf24@13427 454 continue;
kaf24@13427 455 s = PFN_UP(e820_raw[i].addr);
kaf24@13427 456 e = PFN_DOWN(e820_raw[i].addr + e820_raw[i].size);
kaf24@13427 457 e820_raw[i].size = 0; /* discarded later */
kaf24@13427 458 if ( s < e )
kaf24@13427 459 {
kaf24@13427 460 e820_raw[i].addr = s << PAGE_SHIFT;
kaf24@13427 461 e820_raw[i].size = (e - s) << PAGE_SHIFT;
kaf24@13427 462 }
kaf24@13427 463 }
kaf24@13427 464
kaf24@13427 465 /* Sanitise the raw E820 map to produce a final clean version. */
kaf24@4950 466 max_page = init_e820(e820_raw, &e820_raw_nr);
kaf24@3338 467
kfraser@15074 468 /*
kfraser@15074 469 * Create a temporary copy of the E820 map. Truncate it to above 16MB
kfraser@15074 470 * as anything below that is already mapped and has a statically-allocated
kfraser@15074 471 * purpose.
kfraser@15074 472 */
kfraser@15074 473 memcpy(&boot_e820, &e820, sizeof(e820));
kfraser@15074 474 for ( i = 0; i < boot_e820.nr_map; i++ )
kaf24@3338 475 {
kfraser@15074 476 uint64_t s, e, min = 16 << 20; /* 16MB */
kfraser@15074 477 s = boot_e820.map[i].addr;
kfraser@15074 478 e = boot_e820.map[i].addr + boot_e820.map[i].size;
kfraser@15074 479 if ( s >= min )
kfraser@15074 480 continue;
kfraser@15074 481 if ( e > min )
kaf24@6111 482 {
kfraser@15074 483 boot_e820.map[i].addr = min;
kfraser@15074 484 boot_e820.map[i].size = e - min;
kaf24@6111 485 }
kfraser@15074 486 else
kfraser@15074 487 boot_e820.map[i].type = E820_RESERVED;
kaf24@3338 488 }
kaf24@6111 489
kfraser@15074 490 /*
keir@15077 491 * Iterate backwards over all superpage-aligned RAM regions.
kfraser@15074 492 *
kfraser@15074 493 * We require superpage alignment because the boot allocator is not yet
kfraser@15074 494 * initialised. Hence we can only map superpages in the address range
kfraser@15074 495 * 0 to BOOTSTRAP_DIRECTMAP_END, as this is guaranteed not to require
kfraser@15074 496 * dynamic allocation of pagetables.
kfraser@15074 497 *
kfraser@15074 498 * As well as mapping superpages in that range, in preparation for
kfraser@15074 499 * initialising the boot allocator, we also look for a region to which
kfraser@15074 500 * we can relocate the dom0 kernel and other multiboot modules. Also, on
kfraser@15074 501 * x86/64, we relocate Xen to higher memory.
kfraser@15074 502 */
kfraser@15074 503 modules_length = mod[mbi->mods_count-1].mod_end - mod[0].mod_start;
keir@15077 504 for ( i = boot_e820.nr_map-1; i >= 0; i-- )
kfraser@15074 505 {
kfraser@15074 506 uint64_t s, e, mask = (1UL << L2_PAGETABLE_SHIFT) - 1;
kaf24@6134 507
kfraser@15074 508 /* Superpage-aligned chunks up to BOOTSTRAP_DIRECTMAP_END, please. */
kfraser@15074 509 s = (boot_e820.map[i].addr + mask) & ~mask;
kfraser@15074 510 e = (boot_e820.map[i].addr + boot_e820.map[i].size) & ~mask;
kfraser@15074 511 e = min_t(uint64_t, e, BOOTSTRAP_DIRECTMAP_END);
kfraser@15074 512 if ( (boot_e820.map[i].type != E820_RAM) || (s >= e) )
kaf24@3354 513 continue;
kaf24@6111 514
kfraser@15074 515 /* Map the chunk. No memory will need to be allocated to do this. */
kfraser@15074 516 map_pages_to_xen(
kfraser@15074 517 (unsigned long)maddr_to_bootstrap_virt(s),
kfraser@15074 518 s >> PAGE_SHIFT, (e-s) >> PAGE_SHIFT, PAGE_HYPERVISOR);
kaf24@6111 519
kfraser@14084 520 #if defined(CONFIG_X86_64)
kfraser@15074 521 /* Is the region suitable for relocating Xen? */
kfraser@15074 522 if ( !xen_phys_start && (((e-s) >> 20) >= opt_xenheap_megabytes) )
kaf24@5003 523 {
kfraser@15074 524 extern l2_pgentry_t l2_xenmap[];
kfraser@15074 525 l4_pgentry_t *pl4e;
kfraser@15074 526 l3_pgentry_t *pl3e;
kfraser@15074 527 l2_pgentry_t *pl2e;
kfraser@15074 528 int i, j;
kfraser@15074 529
kfraser@15074 530 /* Select relocation address. */
kfraser@15074 531 e = (e - (opt_xenheap_megabytes << 20)) & ~mask;
kfraser@15074 532 xen_phys_start = e;
kfraser@15074 533 boot_trampoline_va(trampoline_xen_phys_start) = e;
kfraser@15074 534
kfraser@15074 535 /*
kfraser@15074 536 * Perform relocation to new physical address.
kfraser@15074 537 * Before doing so we must sync static/global data with main memory
kfraser@15074 538 * with a barrier(). After this we must *not* modify static/global
kfraser@15074 539 * data until after we have switched to the relocated pagetables!
kfraser@15074 540 */
kfraser@15074 541 barrier();
kfraser@15074 542 move_memory(e, 0, __pa(&_end) - xen_phys_start);
kfraser@15074 543
kfraser@15074 544 /* Walk initial pagetables, relocating page directory entries. */
kfraser@15074 545 pl4e = __va(__pa(idle_pg_table));
kfraser@15074 546 for ( i = 0 ; i < L4_PAGETABLE_ENTRIES; i++, pl4e++ )
kfraser@15074 547 {
kfraser@15074 548 if ( !(l4e_get_flags(*pl4e) & _PAGE_PRESENT) )
kfraser@15074 549 continue;
kfraser@15074 550 *pl4e = l4e_from_intpte(l4e_get_intpte(*pl4e) +
kfraser@15074 551 xen_phys_start);
kfraser@15074 552 pl3e = l4e_to_l3e(*pl4e);
kfraser@15074 553 for ( j = 0; j < L3_PAGETABLE_ENTRIES; j++, pl3e++ )
kfraser@15074 554 {
kfraser@15074 555 /* Not present or already relocated? */
kfraser@15074 556 if ( !(l3e_get_flags(*pl3e) & _PAGE_PRESENT) ||
kfraser@15074 557 (l3e_get_pfn(*pl3e) > 0x1000) )
kfraser@15074 558 continue;
kfraser@15074 559 *pl3e = l3e_from_intpte(l3e_get_intpte(*pl3e) +
kfraser@15074 560 xen_phys_start);
kfraser@15074 561 }
kfraser@15074 562 }
kfraser@15074 563
kfraser@15074 564 /* The only data mappings to be relocated are in the Xen area. */
kfraser@15074 565 pl2e = __va(__pa(l2_xenmap));
kfraser@15074 566 for ( i = 0; i < L2_PAGETABLE_ENTRIES; i++, pl2e++ )
kfraser@15074 567 {
kfraser@15074 568 if ( !(l2e_get_flags(*pl2e) & _PAGE_PRESENT) )
kfraser@15074 569 continue;
kfraser@15074 570 *pl2e = l2e_from_intpte(l2e_get_intpte(*pl2e) +
kfraser@15074 571 xen_phys_start);
kfraser@15074 572 }
kfraser@15074 573
kfraser@15074 574 /* Re-sync the stack and then switch to relocated pagetables. */
kfraser@15074 575 asm volatile (
kfraser@15074 576 "rep movsb ; " /* re-sync the stack */
kfraser@15074 577 "movq %%cr4,%%rsi ; "
kfraser@15074 578 "andb $0x7f,%%sil ; "
kfraser@15074 579 "movq %%rsi,%%cr4 ; " /* CR4.PGE == 0 */
kfraser@15074 580 "movq %0,%%cr3 ; " /* CR3 == new pagetables */
kfraser@15074 581 "orb $0x80,%%sil ; "
kfraser@15074 582 "movq %%rsi,%%cr4 " /* CR4.PGE == 1 */
kfraser@15074 583 : : "r" (__pa(idle_pg_table)), "S" (cpu0_stack),
kfraser@15074 584 "D" (__va(__pa(cpu0_stack))), "c" (STACK_SIZE) : "memory" );
kaf24@5003 585 }
kaf24@5003 586 #endif
keir@15077 587
keir@15077 588 /* Is the region suitable for relocating the multiboot modules? */
keir@15077 589 if ( !initial_images_start && (s < e) && ((e-s) >= modules_length) )
keir@15077 590 {
keir@15077 591 e -= modules_length;
keir@15077 592 initial_images_start = e;
keir@15077 593 initial_images_end = initial_images_start + modules_length;
keir@15077 594 move_memory(initial_images_start,
keir@15077 595 mod[0].mod_start, mod[mbi->mods_count-1].mod_end);
keir@15077 596 }
kaf24@3354 597 }
kaf24@3354 598
kfraser@15074 599 if ( !initial_images_start )
kfraser@15074 600 EARLY_FAIL("Not enough memory to relocate the dom0 kernel image.\n");
kfraser@15074 601 reserve_in_boot_e820(initial_images_start, initial_images_end);
kfraser@15074 602
kfraser@15074 603 /*
kfraser@15074 604 * With modules (and Xen itself, on x86/64) relocated out of the way, we
kfraser@15074 605 * can now initialise the boot allocator with some memory.
kfraser@15074 606 */
kfraser@15074 607 xenheap_phys_start = init_boot_allocator(__pa(&_end));
kfraser@15074 608 xenheap_phys_end = opt_xenheap_megabytes << 20;
kfraser@15074 609 #if defined(CONFIG_X86_64)
kfraser@15074 610 if ( !xen_phys_start )
kfraser@15074 611 EARLY_FAIL("Not enough memory to relocate Xen.\n");
kfraser@15074 612 xenheap_phys_end += xen_phys_start;
kfraser@15074 613 reserve_in_boot_e820(xen_phys_start,
kfraser@15074 614 xen_phys_start + (opt_xenheap_megabytes<<20));
kfraser@15074 615 init_boot_pages(1<<20, 16<<20); /* Initial seed: 15MB */
kfraser@15074 616 #else
kfraser@15074 617 init_boot_pages(xenheap_phys_end, 16<<20); /* Initial seed: 4MB */
kfraser@15074 618 #endif
kfraser@15074 619
kfraser@15074 620 /*
kfraser@15074 621 * With the boot allocator now seeded, we can walk every RAM region and
kfraser@15074 622 * map it in its entirety (on x86/64, at least) and notify it to the
kfraser@15074 623 * boot allocator.
kfraser@15074 624 */
kfraser@15074 625 for ( i = 0; i < boot_e820.nr_map; i++ )
kfraser@15074 626 {
kfraser@15074 627 uint64_t s, e, map_e, mask = PAGE_SIZE - 1;
kfraser@15074 628
kfraser@15074 629 /* Only page alignment required now. */
kfraser@15074 630 s = (boot_e820.map[i].addr + mask) & ~mask;
kfraser@15074 631 e = (boot_e820.map[i].addr + boot_e820.map[i].size) & ~mask;
kfraser@15074 632 if ( (boot_e820.map[i].type != E820_RAM) || (s >= e) )
kfraser@15074 633 continue;
kfraser@15074 634
kfraser@15074 635 /* Perform the mapping (truncated in 32-bit mode). */
kfraser@15074 636 map_e = e;
kfraser@15074 637 #if defined(CONFIG_X86_32)
kfraser@15074 638 map_e = min_t(uint64_t, map_e, BOOTSTRAP_DIRECTMAP_END);
kfraser@15074 639 #endif
kfraser@15074 640 if ( s < map_e )
kfraser@15074 641 map_pages_to_xen(
kfraser@15074 642 (unsigned long)maddr_to_bootstrap_virt(s),
kfraser@15074 643 s >> PAGE_SHIFT, (map_e-s) >> PAGE_SHIFT, PAGE_HYPERVISOR);
kfraser@15074 644
kfraser@15074 645 init_boot_pages(s, e);
kfraser@15074 646 }
kfraser@15074 647
kfraser@15074 648 if ( (kexec_crash_area.size > 0) && (kexec_crash_area.start > 0) )
ian@12681 649 {
ian@12677 650 unsigned long kdump_start, kdump_size, k;
ian@12677 651
ian@12681 652 /* Mark images pages as free for now. */
ian@12677 653 init_boot_pages(initial_images_start, initial_images_end);
ian@12677 654
ian@12713 655 kdump_start = kexec_crash_area.start;
ian@12713 656 kdump_size = kexec_crash_area.size;
ian@12677 657
ian@12681 658 printk("Kdump: %luMB (%lukB) at 0x%lx\n",
ian@12677 659 kdump_size >> 20,
ian@12677 660 kdump_size >> 10,
ian@12677 661 kdump_start);
ian@12677 662
ian@12681 663 if ( (kdump_start & ~PAGE_MASK) || (kdump_size & ~PAGE_MASK) )
ian@12677 664 panic("Kdump parameters not page aligned\n");
ian@12677 665
ian@12677 666 kdump_start >>= PAGE_SHIFT;
ian@12677 667 kdump_size >>= PAGE_SHIFT;
ian@12677 668
kfraser@12853 669 /* Allocate pages for Kdump memory area. */
kfraser@14083 670 if ( !reserve_boot_pages(kdump_start, kdump_size) )
ian@12677 671 panic("Unable to reserve Kdump memory\n");
ian@12677 672
kfraser@12853 673 /* Allocate pages for relocated initial images. */
ian@12677 674 k = ((initial_images_end - initial_images_start) & ~PAGE_MASK) ? 1 : 0;
ian@12677 675 k += (initial_images_end - initial_images_start) >> PAGE_SHIFT;
ian@12677 676
kfraser@14084 677 #if defined(CONFIG_X86_32)
kfraser@14084 678 /* Must allocate within bootstrap 1:1 limits. */
kfraser@15074 679 k = alloc_boot_low_pages(k, 1); /* 0x0 - BOOTSTRAP_DIRECTMAP_END */
kfraser@14084 680 #else
kfraser@14084 681 k = alloc_boot_pages(k, 1);
kfraser@14084 682 #endif
kfraser@12853 683 if ( k == 0 )
ian@12677 684 panic("Unable to allocate initial images memory\n");
ian@12677 685
ian@12677 686 move_memory(k << PAGE_SHIFT, initial_images_start, initial_images_end);
ian@12677 687
ian@12677 688 initial_images_end -= initial_images_start;
ian@12677 689 initial_images_start = k << PAGE_SHIFT;
ian@12677 690 initial_images_end += initial_images_start;
ian@12681 691 }
ian@12677 692
kaf24@5003 693 memguard_init();
kaf24@4950 694
kfraser@15074 695 nr_pages = 0;
kfraser@15074 696 for ( i = 0; i < e820.nr_map; i++ )
kfraser@15074 697 if ( e820.map[i].type == E820_RAM )
kfraser@15074 698 nr_pages += e820.map[i].size >> PAGE_SHIFT;
ian@12681 699 printk("System RAM: %luMB (%lukB)\n",
kaf24@3354 700 nr_pages >> (20 - PAGE_SHIFT),
kaf24@3354 701 nr_pages << (PAGE_SHIFT - 10));
kaf24@7220 702 total_pages = nr_pages;
kaf24@3354 703
kfraser@11296 704 /* Sanity check for unwanted bloat of certain hypercall structures. */
kfraser@11296 705 BUILD_BUG_ON(sizeof(((struct xen_platform_op *)0)->u) !=
kfraser@11296 706 sizeof(((struct xen_platform_op *)0)->u.pad));
kfraser@11296 707 BUILD_BUG_ON(sizeof(((struct xen_domctl *)0)->u) !=
kfraser@11296 708 sizeof(((struct xen_domctl *)0)->u.pad));
kfraser@11296 709 BUILD_BUG_ON(sizeof(((struct xen_sysctl *)0)->u) !=
kfraser@11296 710 sizeof(((struct xen_sysctl *)0)->u.pad));
kaf24@7388 711
kaf24@9878 712 BUILD_BUG_ON(sizeof(start_info_t) > PAGE_SIZE);
kaf24@9878 713 BUILD_BUG_ON(sizeof(shared_info_t) > PAGE_SIZE);
ack@13292 714 BUILD_BUG_ON(sizeof(struct vcpu_info) != 64);
kaf24@7744 715
ack@13291 716 #ifdef CONFIG_COMPAT
ack@13291 717 BUILD_BUG_ON(sizeof(((struct compat_platform_op *)0)->u) !=
ack@13291 718 sizeof(((struct compat_platform_op *)0)->u.pad));
ack@13291 719 BUILD_BUG_ON(sizeof(start_info_compat_t) > PAGE_SIZE);
ack@13292 720 BUILD_BUG_ON(sizeof(struct compat_vcpu_info) != 64);
ack@13291 721 #endif
ack@13291 722
kfraser@10492 723 /* Check definitions in public headers match internal defs. */
kaf24@9878 724 BUILD_BUG_ON(__HYPERVISOR_VIRT_START != HYPERVISOR_VIRT_START);
kaf24@8521 725 #ifdef HYPERVISOR_VIRT_END
kaf24@9878 726 BUILD_BUG_ON(__HYPERVISOR_VIRT_END != HYPERVISOR_VIRT_END);
kaf24@8521 727 #endif
kfraser@10492 728 BUILD_BUG_ON(MACH2PHYS_VIRT_START != RO_MPT_VIRT_START);
kfraser@10492 729 BUILD_BUG_ON(MACH2PHYS_VIRT_END != RO_MPT_VIRT_END);
kaf24@8521 730
kaf24@3354 731 init_frametable();
kaf24@3338 732
kfraser@11971 733 acpi_boot_table_init();
kfraser@11971 734
kfraser@11971 735 acpi_numa_init();
kfraser@11971 736
kfraser@11971 737 numa_initmem_init(0, max_page);
kfraser@11971 738
kaf24@6111 739 /* Initialise the Xen heap, skipping RAM holes. */
kfraser@15074 740 init_xenheap_pages(xenheap_phys_start, xenheap_phys_end);
kfraser@15074 741 nr_pages = (xenheap_phys_end - xenheap_phys_start) >> PAGE_SHIFT;
kfraser@15074 742 #ifdef __x86_64__
kfraser@15074 743 init_xenheap_pages(xen_phys_start, __pa(&_start));
kfraser@15074 744 nr_pages += (__pa(&_start) - xen_phys_start) >> PAGE_SHIFT;
kfraser@15074 745 #endif
kfraser@15074 746 xenheap_phys_start = xen_phys_start;
kaf24@6111 747 printk("Xen heap: %luMB (%lukB)\n",
kaf24@6111 748 nr_pages >> (20 - PAGE_SHIFT),
kaf24@6111 749 nr_pages << (PAGE_SHIFT - 10));
kaf24@3338 750
keir@14680 751 end_boot_allocator();
keir@14680 752
kaf24@3594 753 early_boot = 0;
kaf24@3338 754
kaf24@8459 755 early_cpu_init();
kaf24@8459 756
kaf24@8459 757 paging_init();
kaf24@8459 758
kaf24@8459 759 /* Unmap the first page of CPU0's stack. */
kaf24@8459 760 memguard_guard_stack(cpu0_stack);
kaf24@8459 761
kaf24@8459 762 open_softirq(NEW_TLBFLUSH_CLOCK_PERIOD_SOFTIRQ, new_tlbflush_clock_period);
kaf24@8459 763
kaf24@8459 764 if ( opt_watchdog )
kaf24@8459 765 nmi_watchdog = NMI_LOCAL_APIC;
kaf24@8459 766
kaf24@8459 767 sort_exception_tables();
kaf24@8459 768
kaf24@8459 769 find_smp_config();
kaf24@8459 770
kaf24@8459 771 dmi_scan_machine();
kaf24@8459 772
kaf24@8459 773 generic_apic_probe();
kaf24@8459 774
kaf24@8459 775 acpi_boot_init();
kaf24@8459 776
kfraser@11971 777 init_cpu_to_node();
kfraser@11971 778
kfraser@11241 779 if ( smp_found_config )
kaf24@8459 780 get_smp_config();
kaf24@8459 781
keir@15083 782 #ifdef CONFIG_X86_64
keir@15083 783 /* Low mappings were only needed for some BIOS table parsing. */
keir@15083 784 zap_low_mappings();
keir@15083 785 #endif
keir@15083 786
kaf24@8459 787 init_apic_mappings();
kaf24@8459 788
kaf24@8459 789 init_IRQ();
kaf24@8459 790
kfraser@11241 791 percpu_init_areas();
kfraser@11241 792
kfraser@11240 793 init_idle_domain();
kfraser@11240 794
kaf24@8459 795 trap_init();
kaf24@8459 796
kaf24@13662 797 rcu_init();
kaf24@13662 798
kaf24@8586 799 timer_init();
kaf24@8459 800
kaf24@8459 801 early_time_init();
kaf24@8459 802
kaf24@8459 803 arch_init_memory();
kaf24@8459 804
kaf24@8459 805 identify_cpu(&boot_cpu_data);
kaf24@8459 806 if ( cpu_has_fxsr )
kaf24@8459 807 set_in_cr4(X86_CR4_OSFXSR);
kaf24@8459 808 if ( cpu_has_xmm )
kaf24@8459 809 set_in_cr4(X86_CR4_OSXMMEXCPT);
kaf24@8459 810
kaf24@8459 811 if ( opt_nosmp )
kaf24@8459 812 max_cpus = 0;
kaf24@8459 813
kaf24@8459 814 smp_prepare_cpus(max_cpus);
kaf24@8459 815
kaf24@8459 816 /*
kaf24@8459 817 * Initialise higher-level timer functions. We do this fairly late
kaf24@8459 818 * (post-SMP) because the time bases and scale factors need to be updated
kaf24@8459 819 * regularly, and SMP initialisation can cause a long delay with
kaf24@8459 820 * interrupts not yet enabled.
kaf24@8459 821 */
kaf24@8459 822 init_xen_time();
kaf24@8459 823
kaf24@8459 824 initialize_keytable();
kaf24@8459 825
kaf24@8459 826 serial_init_postirq();
kaf24@8459 827
kaf24@8459 828 BUG_ON(!local_irq_is_enabled());
kaf24@8459 829
kaf24@8459 830 for_each_present_cpu ( i )
kaf24@8459 831 {
kaf24@8459 832 if ( num_online_cpus() >= max_cpus )
kaf24@8459 833 break;
kaf24@8459 834 if ( !cpu_online(i) )
kaf24@13662 835 {
kaf24@13662 836 rcu_online_cpu(i);
kaf24@8459 837 __cpu_up(i);
kaf24@13662 838 }
kfraser@11971 839
kfraser@11998 840 /* Set up cpu_to_node[]. */
kfraser@11971 841 srat_detect_node(i);
kfraser@11998 842 /* Set up node_to_cpumask based on cpu_to_node[]. */
kfraser@11971 843 numa_add_cpu(i);
kaf24@8459 844 }
kaf24@8459 845
kaf24@8459 846 printk("Brought up %ld CPUs\n", (long)num_online_cpus());
kaf24@8459 847 smp_cpus_done(max_cpus);
kaf24@8459 848
kaf24@9117 849 initialise_gdb(); /* could be moved earlier */
kaf24@9117 850
kaf24@8459 851 do_initcalls();
kaf24@8459 852
kaf24@8594 853 if ( opt_watchdog )
kaf24@8594 854 watchdog_enable();
kaf24@8459 855
kfraser@11881 856 /* Extract policy from multiboot. */
kfraser@11881 857 extract_acm_policy(mbi, &initrdidx, &_policy_start, &_policy_len);
kfraser@11881 858
kaf24@8459 859 /* initialize access control security module */
kfraser@11881 860 acm_init(_policy_start, _policy_len);
kaf24@8459 861
kaf24@8459 862 /* Create initial domain 0. */
kfraser@14911 863 dom0 = domain_create(0, 0, DOM0_SSIDREF);
kfraser@10655 864 if ( (dom0 == NULL) || (alloc_vcpu(dom0, 0, 0) == NULL) )
kaf24@8459 865 panic("Error creating domain 0\n");
kaf24@8459 866
kfraser@12210 867 dom0->is_privileged = 1;
kfraser@12210 868
kaf24@8459 869 /* Grab the DOM0 command line. */
kaf24@8459 870 cmdline = (char *)(mod[0].string ? __va(mod[0].string) : NULL);
kaf24@8459 871 if ( cmdline != NULL )
kaf24@8459 872 {
kaf24@8459 873 static char dom0_cmdline[MAX_GUEST_CMDLINE];
kaf24@8459 874
kaf24@8459 875 /* Skip past the image name and copy to a local buffer. */
kaf24@8459 876 while ( *cmdline == ' ' ) cmdline++;
kaf24@8459 877 if ( (cmdline = strchr(cmdline, ' ')) != NULL )
kaf24@8459 878 {
kaf24@8459 879 while ( *cmdline == ' ' ) cmdline++;
kfraser@13689 880 safe_strcpy(dom0_cmdline, cmdline);
kaf24@8459 881 }
kaf24@8459 882
kaf24@8459 883 /* Append any extra parameters. */
kfraser@13691 884 if ( skip_ioapic_setup && !strstr(dom0_cmdline, "noapic") )
kfraser@13691 885 safe_strcat(dom0_cmdline, " noapic");
kaf24@8459 886 if ( acpi_skip_timer_override &&
kfraser@13691 887 !strstr(dom0_cmdline, "acpi_skip_timer_override") )
kfraser@13691 888 safe_strcat(dom0_cmdline, " acpi_skip_timer_override");
kfraser@13691 889 if ( (strlen(acpi_param) != 0) && !strstr(dom0_cmdline, "acpi=") )
kaf24@8459 890 {
kfraser@13691 891 safe_strcat(dom0_cmdline, " acpi=");
kfraser@13691 892 safe_strcat(dom0_cmdline, acpi_param);
kaf24@8459 893 }
kfraser@13691 894
kfraser@13691 895 cmdline = dom0_cmdline;
kaf24@8459 896 }
kaf24@8459 897
kaf24@8459 898 if ( (initrdidx > 0) && (initrdidx < mbi->mods_count) )
kaf24@8459 899 {
kaf24@8459 900 _initrd_start = initial_images_start +
kaf24@8459 901 (mod[initrdidx].mod_start - mod[0].mod_start);
kaf24@8459 902 _initrd_len = mod[initrdidx].mod_end - mod[initrdidx].mod_start;
kaf24@8459 903 }
kaf24@8459 904
kaf24@8459 905 /*
kaf24@8459 906 * We're going to setup domain0 using the module(s) that we stashed safely
kaf24@8459 907 * above our heap. The second module, if present, is an initrd ramdisk.
kaf24@8459 908 */
kaf24@8459 909 if ( construct_dom0(dom0,
kaf24@8459 910 initial_images_start,
kaf24@8459 911 mod[0].mod_end-mod[0].mod_start,
kaf24@8459 912 _initrd_start,
kaf24@8459 913 _initrd_len,
kaf24@8459 914 cmdline) != 0)
kaf24@8459 915 panic("Could not set up DOM0 guest OS\n");
kaf24@8459 916
kaf24@8459 917 /* Scrub RAM that is still free and so may go to an unprivileged domain. */
kaf24@8459 918 scrub_heap_pages();
kaf24@8459 919
kaf24@8459 920 init_trace_bufs();
kaf24@8459 921
kaf24@10502 922 console_endboot();
kaf24@8459 923
kaf24@8459 924 /* Hide UART from DOM0 if we're using it */
kaf24@8459 925 serial_endboot();
kaf24@8459 926
kaf24@8459 927 domain_unpause_by_systemcontroller(dom0);
kaf24@8459 928
keir@15082 929 reset_stack_and_jump(init_done);
kaf24@8459 930 }
kaf24@8459 931
ian@13763 932 void arch_get_xen_caps(xen_capabilities_info_t *info)
iap10@6721 933 {
kfraser@14997 934 /* Interface name is always xen-3.0-* for Xen-3.x. */
kfraser@14997 935 int major = 3, minor = 0;
keir@13754 936 char s[32];
keir@13754 937
ian@13763 938 (*info)[0] = '\0';
iap10@6721 939
kaf24@6725 940 #if defined(CONFIG_X86_32) && !defined(CONFIG_X86_PAE)
kaf24@6725 941
keir@13754 942 snprintf(s, sizeof(s), "xen-%d.%d-x86_32 ", major, minor);
ian@13763 943 safe_strcat(*info, s);
keir@13754 944 if ( hvm_enabled )
keir@13754 945 {
keir@13754 946 snprintf(s, sizeof(s), "hvm-%d.%d-x86_32 ", major, minor);
ian@13763 947 safe_strcat(*info, s);
kfraser@13685 948 }
kaf24@6725 949
kaf24@6725 950 #elif defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
kaf24@6725 951
keir@13754 952 snprintf(s, sizeof(s), "xen-%d.%d-x86_32p ", major, minor);
ian@13763 953 safe_strcat(*info, s);
kaf24@6725 954 if ( hvm_enabled )
iap10@6721 955 {
keir@13754 956 snprintf(s, sizeof(s), "hvm-%d.%d-x86_32 ", major, minor);
ian@13763 957 safe_strcat(*info, s);
keir@13754 958 snprintf(s, sizeof(s), "hvm-%d.%d-x86_32p ", major, minor);
ian@13763 959 safe_strcat(*info, s);
iap10@6721 960 }
iap10@6721 961
kaf24@6725 962 #elif defined(CONFIG_X86_64)
iap10@6721 963
keir@13754 964 snprintf(s, sizeof(s), "xen-%d.%d-x86_64 ", major, minor);
ian@13763 965 safe_strcat(*info, s);
ack@13288 966 #ifdef CONFIG_COMPAT
keir@13754 967 snprintf(s, sizeof(s), "xen-%d.%d-x86_32p ", major, minor);
ian@13763 968 safe_strcat(*info, s);
ack@13288 969 #endif
kaf24@6725 970 if ( hvm_enabled )
iap10@6721 971 {
keir@13754 972 snprintf(s, sizeof(s), "hvm-%d.%d-x86_32 ", major, minor);
ian@13763 973 safe_strcat(*info, s);
keir@13754 974 snprintf(s, sizeof(s), "hvm-%d.%d-x86_32p ", major, minor);
ian@13763 975 safe_strcat(*info, s);
keir@13754 976 snprintf(s, sizeof(s), "hvm-%d.%d-x86_64 ", major, minor);
ian@13763 977 safe_strcat(*info, s);
iap10@6721 978 }
kaf24@6725 979
iap10@6721 980 #endif
iap10@6721 981 }
iap10@6721 982
kaf24@3914 983 /*
kaf24@3914 984 * Local variables:
kaf24@3914 985 * mode: C
kaf24@3914 986 * c-set-style: "BSD"
kaf24@3914 987 * c-basic-offset: 4
kaf24@3914 988 * tab-width: 4
kaf24@3914 989 * indent-tabs-mode: nil
kaf24@3988 990 * End:
kaf24@3914 991 */