ia64/xen-unstable

annotate xen/arch/x86/setup.c @ 13291:4a164bf1edfc

Handle the creation of startup info for compatibility mode guests. This
includes a script to auto-generate checking or translation code between
native and compatibility mode hypercall argument structures.

Signed-off-by: Jan Beulich <jbeulich@novell.com>
author Emmanuel Ackaouy <ack@xensource.com>
date Fri Jan 05 17:34:28 2007 +0000 (2007-01-05)
parents 7c5eea5feebd
children 4c8f157a3a47
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>
iap10@6721 20 #include <public/version.h>
ack@13291 21 #ifdef CONFIG_COMPAT
ack@13291 22 #include <compat/platform.h>
ack@13291 23 #include <compat/xen.h>
ack@13291 24 #endif
kaf24@1452 25 #include <asm/bitops.h>
kaf24@1452 26 #include <asm/smp.h>
kaf24@1452 27 #include <asm/processor.h>
kaf24@1452 28 #include <asm/mpspec.h>
kaf24@1452 29 #include <asm/apic.h>
kaf24@1452 30 #include <asm/desc.h>
kaf24@3338 31 #include <asm/shadow.h>
kaf24@3344 32 #include <asm/e820.h>
kaf24@5536 33 #include <acm/acm_hooks.h>
ian@12677 34 #include <xen/kexec.h>
kaf24@3338 35
kaf24@5157 36 extern void dmi_scan_machine(void);
kaf24@5211 37 extern void generic_apic_probe(void);
kfraser@11971 38 extern void numa_initmem_init(unsigned long start_pfn, unsigned long end_pfn);
kaf24@5157 39
kaf24@3338 40 /*
kaf24@3338 41 * opt_xenheap_megabytes: Size of Xen heap in megabytes, excluding the
kaf24@8726 42 * page_info table and allocation bitmap.
kaf24@3338 43 */
kaf24@3338 44 static unsigned int opt_xenheap_megabytes = XENHEAP_DEFAULT_MB;
kaf24@4950 45 #if defined(CONFIG_X86_64)
kaf24@3338 46 integer_param("xenheap_megabytes", opt_xenheap_megabytes);
kaf24@3354 47 #endif
kaf24@1452 48
kaf24@5146 49 /* opt_nosmp: If true, secondary processors are ignored. */
kaf24@5900 50 static int opt_nosmp = 0;
kaf24@5146 51 boolean_param("nosmp", opt_nosmp);
kaf24@5146 52
kaf24@5146 53 /* maxcpus: maximum number of CPUs to activate. */
kaf24@5146 54 static unsigned int max_cpus = NR_CPUS;
shand@11156 55 integer_param("maxcpus", max_cpus);
kaf24@5146 56
kaf24@3334 57 /* opt_watchdog: If true, run a watchdog NMI on each processor. */
kaf24@3334 58 static int opt_watchdog = 0;
kaf24@3334 59 boolean_param("watchdog", opt_watchdog);
kaf24@3334 60
kaf24@4850 61 /* **** Linux config option: propagated to domain0. */
kaf24@4850 62 /* "acpi=off": Sisables both ACPI table parsing and interpreter. */
kaf24@4850 63 /* "acpi=force": Override the disable blacklist. */
kaf24@4850 64 /* "acpi=strict": Disables out-of-spec workarounds. */
kaf24@4850 65 /* "acpi=ht": Limit ACPI just to boot-time to enable HT. */
kaf24@4850 66 /* "acpi=noirq": Disables ACPI interrupt routing. */
kaf24@4850 67 static void parse_acpi_param(char *s);
kaf24@4850 68 custom_param("acpi", parse_acpi_param);
kaf24@4850 69
kaf24@4850 70 /* **** Linux config option: propagated to domain0. */
kaf24@4850 71 /* acpi_skip_timer_override: Skip IRQ0 overrides. */
kaf24@4850 72 extern int acpi_skip_timer_override;
kaf24@4850 73 boolean_param("acpi_skip_timer_override", acpi_skip_timer_override);
kaf24@4850 74
kaf24@4850 75 /* **** Linux config option: propagated to domain0. */
kaf24@4850 76 /* noapic: Disable IOAPIC setup. */
kaf24@4850 77 extern int skip_ioapic_setup;
kaf24@4850 78 boolean_param("noapic", skip_ioapic_setup);
kaf24@4850 79
kaf24@3594 80 int early_boot = 1;
kaf24@3594 81
kaf24@5146 82 cpumask_t cpu_present_map;
kaf24@5146 83
kaf24@5003 84 /* Limits of Xen heap, used to initialise the allocator. */
kaf24@5003 85 unsigned long xenheap_phys_start, xenheap_phys_end;
kaf24@3338 86
kaf24@2298 87 extern void arch_init_memory(void);
kaf24@1589 88 extern void init_IRQ(void);
kaf24@1589 89 extern void trap_init(void);
kaf24@5604 90 extern void early_time_init(void);
kaf24@5167 91 extern void early_cpu_init(void);
kaf24@1589 92
kaf24@8533 93 struct tss_struct init_tss[NR_CPUS];
kaf24@8533 94
kaf24@5011 95 extern unsigned long cpu0_stack[];
kaf24@5011 96
kaf24@5214 97 struct cpuinfo_x86 boot_cpu_data = { 0, 0, 0, 0, -1, 1, 0, 0, -1 };
kaf24@1452 98
kaf24@5237 99 #if CONFIG_PAGING_LEVELS > 2
kaf24@1670 100 unsigned long mmu_cr4_features = X86_CR4_PSE | X86_CR4_PGE | X86_CR4_PAE;
kaf24@1670 101 #else
kaf24@5593 102 unsigned long mmu_cr4_features = X86_CR4_PSE;
kaf24@1670 103 #endif
kaf24@1452 104 EXPORT_SYMBOL(mmu_cr4_features);
kaf24@1452 105
kaf24@4818 106 int acpi_disabled;
kaf24@1452 107
kaf24@4850 108 int acpi_force;
kaf24@4850 109 char acpi_param[10] = "";
kaf24@4850 110 static void parse_acpi_param(char *s)
kaf24@4850 111 {
kaf24@4850 112 /* Save the parameter so it can be propagated to domain0. */
kaf24@4850 113 strncpy(acpi_param, s, sizeof(acpi_param));
kaf24@4850 114 acpi_param[sizeof(acpi_param)-1] = '\0';
kaf24@4850 115
kaf24@4850 116 /* Interpret the parameter for use within Xen. */
kaf24@4850 117 if ( !strcmp(s, "off") )
kaf24@4850 118 {
kaf24@4850 119 disable_acpi();
kaf24@4850 120 }
kaf24@4850 121 else if ( !strcmp(s, "force") )
kaf24@4850 122 {
kaf24@4850 123 acpi_force = 1;
kaf24@4850 124 acpi_ht = 1;
kaf24@4850 125 acpi_disabled = 0;
kaf24@4850 126 }
kaf24@4850 127 else if ( !strcmp(s, "strict") )
kaf24@4850 128 {
kaf24@4850 129 acpi_strict = 1;
kaf24@4850 130 }
kaf24@4850 131 else if ( !strcmp(s, "ht") )
kaf24@4850 132 {
kaf24@4850 133 if ( !acpi_force )
kaf24@4850 134 disable_acpi();
kaf24@4850 135 acpi_ht = 1;
kaf24@4850 136 }
kaf24@4850 137 else if ( !strcmp(s, "noirq") )
kaf24@4850 138 {
kaf24@4850 139 acpi_noirq_set();
kaf24@4850 140 }
kaf24@4850 141 }
kaf24@4850 142
kaf24@1452 143 static void __init do_initcalls(void)
kaf24@1452 144 {
kaf24@1452 145 initcall_t *call;
kaf24@1452 146 for ( call = &__initcall_start; call < &__initcall_end; call++ )
kaf24@1452 147 (*call)();
kaf24@1452 148 }
kaf24@1452 149
kaf24@8459 150 #define EARLY_FAIL() for ( ; ; ) __asm__ __volatile__ ( "hlt" )
kaf24@8459 151
kaf24@8459 152 static struct e820entry e820_raw[E820MAX];
kaf24@8459 153
kaf24@9067 154 static unsigned long initial_images_start, initial_images_end;
kaf24@9067 155
kaf24@9067 156 unsigned long initial_images_nrpages(void)
kaf24@9067 157 {
kaf24@9067 158 unsigned long s = initial_images_start + PAGE_SIZE - 1;
kaf24@9067 159 unsigned long e = initial_images_end;
kaf24@9067 160 return ((e >> PAGE_SHIFT) - (s >> PAGE_SHIFT));
kaf24@9067 161 }
kaf24@9067 162
kaf24@9067 163 void discard_initial_images(void)
kaf24@9067 164 {
kaf24@9067 165 init_domheap_pages(initial_images_start, initial_images_end);
kaf24@9067 166 }
kaf24@9067 167
kaf24@9818 168 extern char __per_cpu_start[], __per_cpu_data_end[], __per_cpu_end[];
kaf24@9818 169
kfraser@11241 170 static void __init percpu_init_areas(void)
kaf24@9818 171 {
kaf24@9818 172 unsigned int i, data_size = __per_cpu_data_end - __per_cpu_start;
kaf24@9818 173
kaf24@9818 174 BUG_ON(data_size > PERCPU_SIZE);
kaf24@9818 175
kfraser@11241 176 for_each_cpu ( i )
kfraser@11241 177 {
kfraser@11241 178 memguard_unguard_range(__per_cpu_start + (i << PERCPU_SHIFT),
kfraser@11241 179 1 << PERCPU_SHIFT);
kfraser@11241 180 if ( i != 0 )
kfraser@11241 181 memcpy(__per_cpu_start + (i << PERCPU_SHIFT),
kfraser@11241 182 __per_cpu_start,
kfraser@11241 183 data_size);
kfraser@11241 184 }
kaf24@9818 185 }
kaf24@9818 186
kfraser@11241 187 static void __init percpu_guard_areas(void)
kfraser@11241 188 {
kfraser@11241 189 memguard_guard_range(__per_cpu_start, __per_cpu_end - __per_cpu_start);
kfraser@11241 190 }
kfraser@11241 191
kfraser@11241 192 static void __init percpu_free_unused_areas(void)
kaf24@9818 193 {
kaf24@9818 194 unsigned int i, first_unused;
kaf24@9818 195
kaf24@9818 196 /* Find first unused CPU number. */
kaf24@9818 197 for ( i = 0; i < NR_CPUS; i++ )
kaf24@9818 198 if ( !cpu_online(i) )
kaf24@9818 199 break;
kaf24@9818 200 first_unused = i;
kaf24@9818 201
kaf24@9818 202 /* Check that there are no holes in cpu_online_map. */
kaf24@9818 203 for ( ; i < NR_CPUS; i++ )
kaf24@9818 204 BUG_ON(cpu_online(i));
kaf24@9818 205
kfraser@11241 206 #ifndef MEMORY_GUARD
kaf24@9818 207 init_xenheap_pages(__pa(__per_cpu_start) + (first_unused << PERCPU_SHIFT),
kaf24@9818 208 __pa(__per_cpu_end));
kfraser@11241 209 #endif
kaf24@9818 210 }
kaf24@9818 211
kfraser@11881 212 /* Fetch acm policy module from multiboot modules. */
kfraser@11881 213 static void extract_acm_policy(
kfraser@11881 214 multiboot_info_t *mbi,
kfraser@11881 215 unsigned int *initrdidx,
kfraser@11881 216 char **_policy_start,
kfraser@11881 217 unsigned long *_policy_len)
kfraser@11881 218 {
kfraser@11881 219 int i;
kfraser@11881 220 module_t *mod = (module_t *)__va(mbi->mods_addr);
kfraser@11881 221 unsigned long start, policy_len;
kfraser@11881 222 char *policy_start;
kfraser@11881 223
kfraser@11881 224 /*
kfraser@11881 225 * Try all modules and see whichever could be the binary policy.
kfraser@11881 226 * Adjust the initrdidx if module[1] is the binary policy.
kfraser@11881 227 */
kfraser@11881 228 for ( i = mbi->mods_count-1; i >= 1; i-- )
kfraser@11881 229 {
kfraser@11881 230 start = initial_images_start + (mod[i].mod_start-mod[0].mod_start);
kfraser@11881 231 #if defined(__i386__)
kfraser@11881 232 policy_start = (char *)start;
kfraser@11881 233 #elif defined(__x86_64__)
kfraser@11881 234 policy_start = __va(start);
kfraser@11881 235 #endif
kfraser@11881 236 policy_len = mod[i].mod_end - mod[i].mod_start;
kfraser@11881 237 if ( acm_is_policy(policy_start, policy_len) )
kfraser@11881 238 {
kfraser@11881 239 printk("Policy len 0x%lx, start at %p - module %d.\n",
kfraser@11881 240 policy_len, policy_start, i);
kfraser@11881 241 *_policy_start = policy_start;
kfraser@11881 242 *_policy_len = policy_len;
kfraser@11881 243 if ( i == 1 )
kfraser@11881 244 *initrdidx = (mbi->mods_count > 2) ? 2 : 0;
kfraser@11881 245 break;
kfraser@11881 246 }
kfraser@11881 247 }
kfraser@11881 248 }
kfraser@11881 249
kfraser@11241 250 static void __init init_idle_domain(void)
kfraser@11240 251 {
kfraser@11240 252 struct domain *idle_domain;
kfraser@11240 253
kfraser@11240 254 /* Domain creation requires that scheduler structures are initialised. */
kfraser@11240 255 scheduler_init();
kfraser@11240 256
kfraser@12210 257 idle_domain = domain_create(IDLE_DOMAIN_ID, 0);
kfraser@11240 258 if ( (idle_domain == NULL) || (alloc_vcpu(idle_domain, 0, 0) == NULL) )
kfraser@11240 259 BUG();
kfraser@11240 260
kfraser@11240 261 set_current(idle_domain->vcpu[0]);
kfraser@11240 262 idle_vcpu[0] = this_cpu(curr_vcpu) = current;
kfraser@11240 263
kfraser@11240 264 setup_idle_pagetable();
kfraser@11240 265 }
kfraser@11240 266
kfraser@11971 267 static void srat_detect_node(int cpu)
kfraser@11971 268 {
kfraser@11998 269 unsigned node;
kfraser@11998 270 u8 apicid = x86_cpu_to_apicid[cpu];
kfraser@11971 271
kfraser@11998 272 node = apicid_to_node[apicid];
kfraser@11998 273 if ( node == NUMA_NO_NODE )
kfraser@11998 274 node = 0;
kfraser@11998 275 numa_set_node(cpu, node);
kfraser@11971 276
kfraser@11998 277 if ( acpi_numa > 0 )
kfraser@11998 278 printk(KERN_INFO "CPU %d APIC %d -> Node %d\n", cpu, apicid, node);
kfraser@11971 279 }
kfraser@11971 280
ian@12681 281 void __init move_memory(unsigned long dst,
ian@12677 282 unsigned long src_start, unsigned long src_end)
ian@12677 283 {
ian@12677 284 #if defined(CONFIG_X86_32)
ian@12681 285 memmove((void *)dst, /* use low mapping */
ian@12677 286 (void *)src_start, /* use low mapping */
ian@12677 287 src_end - src_start);
ian@12677 288 #elif defined(CONFIG_X86_64)
ian@12677 289 memmove(__va(dst),
ian@12677 290 __va(src_start),
ian@12677 291 src_end - src_start);
ian@12677 292 #endif
ian@12677 293 }
ian@12677 294
kaf24@8463 295 void __init __start_xen(multiboot_info_t *mbi)
kaf24@1452 296 {
kaf24@9823 297 char __cmdline[] = "", *cmdline = __cmdline;
kaf24@8457 298 unsigned long _initrd_start = 0, _initrd_len = 0;
kaf24@8457 299 unsigned int initrdidx = 1;
kfraser@11881 300 char *_policy_start = NULL;
kfraser@11881 301 unsigned long _policy_len = 0;
kaf24@8457 302 module_t *mod = (module_t *)__va(mbi->mods_addr);
kaf24@6111 303 unsigned long nr_pages, modules_length;
kaf24@8726 304 paddr_t s, e;
kaf24@8402 305 int i, e820_warn = 0, e820_raw_nr = 0, bytes = 0;
kaf24@5776 306 struct ns16550_defaults ns16550 = {
kaf24@5776 307 .data_bits = 8,
kaf24@5776 308 .parity = 'n',
kaf24@5776 309 .stop_bits = 1
kaf24@5776 310 };
kaf24@3338 311
kfraser@12853 312 extern void early_page_fault(void);
kfraser@12853 313 set_intr_gate(TRAP_page_fault, &early_page_fault);
kfraser@12853 314
kaf24@3338 315 /* Parse the command-line options. */
kaf24@3344 316 if ( (mbi->flags & MBI_CMDLINE) && (mbi->cmdline != 0) )
kaf24@9823 317 cmdline = __va(mbi->cmdline);
kaf24@9823 318 cmdline_parse(cmdline);
kaf24@3338 319
kaf24@8534 320 set_current((struct vcpu *)0xfffff000); /* debug sanity */
kfraser@11240 321 idle_vcpu[0] = current;
kaf24@8534 322 set_processor_id(0); /* needed early, for smp_processor_id() */
kaf24@3338 323
kaf24@5146 324 smp_prepare_boot_cpu();
kaf24@5146 325
kaf24@3338 326 /* We initialise the serial devices very early so we can get debugging. */
kaf24@5776 327 ns16550.io_base = 0x3f8;
kaf24@5776 328 ns16550.irq = 4;
kaf24@5776 329 ns16550_init(0, &ns16550);
kaf24@5776 330 ns16550.io_base = 0x2f8;
kaf24@5776 331 ns16550.irq = 3;
kaf24@5776 332 ns16550_init(1, &ns16550);
kaf24@5195 333 serial_init_preirq();
kaf24@3338 334
kaf24@3338 335 init_console();
kaf24@3338 336
kfraser@11947 337 printk("Command line: %s\n", cmdline);
kaf24@9823 338
kaf24@3344 339 /* Check that we have at least one Multiboot module. */
kaf24@3344 340 if ( !(mbi->flags & MBI_MODULES) || (mbi->mods_count == 0) )
kaf24@3338 341 {
kaf24@5542 342 printk("FATAL ERROR: dom0 kernel not specified."
kaf24@5542 343 " Check bootloader configuration.\n");
kaf24@5011 344 EARLY_FAIL();
kaf24@5011 345 }
kaf24@5011 346
kaf24@5011 347 if ( ((unsigned long)cpu0_stack & (STACK_SIZE-1)) != 0 )
kaf24@5011 348 {
kaf24@5011 349 printk("FATAL ERROR: Misaligned CPU0 stack.\n");
kaf24@5011 350 EARLY_FAIL();
kaf24@3338 351 }
kaf24@3338 352
kfraser@11618 353 /*
kfraser@11618 354 * Since there are some stubs getting built on the stacks which use
kfraser@11618 355 * direct calls/jumps, the heap must be confined to the lower 2G so
kfraser@11618 356 * that those branches can reach their targets.
kfraser@11618 357 */
kfraser@11618 358 if ( opt_xenheap_megabytes > 2048 )
kfraser@11618 359 opt_xenheap_megabytes = 2048;
kaf24@3338 360 xenheap_phys_end = opt_xenheap_megabytes << 20;
kaf24@3338 361
kaf24@3344 362 if ( mbi->flags & MBI_MEMMAP )
kaf24@3344 363 {
kaf24@3344 364 while ( bytes < mbi->mmap_length )
kaf24@3344 365 {
kaf24@3344 366 memory_map_t *map = __va(mbi->mmap_addr + bytes);
kaf24@8402 367
kaf24@8402 368 /*
kaf24@8403 369 * This is a gross workaround for a BIOS bug. Some bootloaders do
kaf24@8402 370 * not write e820 map entries into pre-zeroed memory. This is
kaf24@8402 371 * okay if the BIOS fills in all fields of the map entry, but
kaf24@8402 372 * some broken BIOSes do not bother to write the high word of
kaf24@8402 373 * the length field if the length is smaller than 4GB. We
kaf24@8402 374 * detect and fix this by flagging sections below 4GB that
kaf24@8403 375 * appear to be larger than 4GB in size.
kaf24@8402 376 */
kaf24@8403 377 if ( (map->base_addr_high == 0) && (map->length_high != 0) )
kaf24@8402 378 {
kaf24@8402 379 e820_warn = 1;
kaf24@8402 380 map->length_high = 0;
kaf24@8402 381 }
kaf24@8402 382
kaf24@3344 383 e820_raw[e820_raw_nr].addr =
kaf24@3344 384 ((u64)map->base_addr_high << 32) | (u64)map->base_addr_low;
kaf24@3344 385 e820_raw[e820_raw_nr].size =
kaf24@3344 386 ((u64)map->length_high << 32) | (u64)map->length_low;
kaf24@3344 387 e820_raw[e820_raw_nr].type =
kfraser@12226 388 (map->type > E820_NVS) ? E820_RESERVED : map->type;
kaf24@3344 389 e820_raw_nr++;
kaf24@8402 390
kaf24@3344 391 bytes += map->size + 4;
kaf24@3344 392 }
kaf24@3344 393 }
kaf24@3344 394 else if ( mbi->flags & MBI_MEMLIMITS )
kaf24@3344 395 {
kaf24@3344 396 e820_raw[0].addr = 0;
kaf24@3344 397 e820_raw[0].size = mbi->mem_lower << 10;
kaf24@3344 398 e820_raw[0].type = E820_RAM;
kaf24@3354 399 e820_raw[1].addr = 0x100000;
kaf24@3354 400 e820_raw[1].size = mbi->mem_upper << 10;
kaf24@3354 401 e820_raw[1].type = E820_RAM;
kaf24@3344 402 e820_raw_nr = 2;
kaf24@3344 403 }
kaf24@3344 404 else
kaf24@3344 405 {
kaf24@3344 406 printk("FATAL ERROR: Bootloader provided no memory information.\n");
kaf24@3344 407 for ( ; ; ) ;
kaf24@3344 408 }
kaf24@3344 409
kaf24@8402 410 if ( e820_warn )
kaf24@8402 411 printk("WARNING: Buggy e820 map detected and fixed "
kaf24@8402 412 "(truncated length fields).\n");
kaf24@8402 413
kaf24@4950 414 max_page = init_e820(e820_raw, &e820_raw_nr);
kaf24@3338 415
kaf24@6111 416 modules_length = mod[mbi->mods_count-1].mod_end - mod[0].mod_start;
kaf24@3338 417
kaf24@6111 418 /* Find a large enough RAM extent to stash the DOM0 modules. */
kaf24@6111 419 for ( i = 0; ; i++ )
kaf24@3338 420 {
kaf24@6111 421 if ( i == e820.nr_map )
kaf24@6111 422 {
kaf24@6111 423 printk("Not enough memory to stash the DOM0 kernel image.\n");
kaf24@6111 424 for ( ; ; ) ;
kaf24@6111 425 }
kaf24@6134 426
kaf24@6134 427 if ( (e820.map[i].type == E820_RAM) &&
kaf24@6134 428 (e820.map[i].size >= modules_length) &&
kaf24@6134 429 ((e820.map[i].addr + e820.map[i].size) >=
kaf24@6134 430 (xenheap_phys_end + modules_length)) )
kaf24@6134 431 break;
kaf24@3338 432 }
kaf24@6111 433
kaf24@6134 434 /* Stash as near as possible to the beginning of the RAM extent. */
kaf24@6134 435 initial_images_start = e820.map[i].addr;
kaf24@6134 436 if ( initial_images_start < xenheap_phys_end )
kaf24@6134 437 initial_images_start = xenheap_phys_end;
kaf24@6134 438 initial_images_end = initial_images_start + modules_length;
kaf24@6134 439
ian@12677 440 move_memory(initial_images_start,
ian@12677 441 mod[0].mod_start, mod[mbi->mods_count-1].mod_end);
kaf24@3338 442
kaf24@3354 443 /* Initialise boot-time allocator with all RAM situated after modules. */
kaf24@5003 444 xenheap_phys_start = init_boot_allocator(__pa(&_end));
kaf24@6111 445 nr_pages = 0;
kaf24@3354 446 for ( i = 0; i < e820.nr_map; i++ )
kaf24@3354 447 {
kaf24@3354 448 if ( e820.map[i].type != E820_RAM )
kaf24@3354 449 continue;
kaf24@6111 450
kaf24@3354 451 nr_pages += e820.map[i].size >> PAGE_SHIFT;
kaf24@6111 452
kaf24@6111 453 /* Initialise boot heap, skipping Xen heap and dom0 modules. */
kaf24@6111 454 s = e820.map[i].addr;
kaf24@6111 455 e = s + e820.map[i].size;
kaf24@6111 456 if ( s < xenheap_phys_end )
kaf24@6111 457 s = xenheap_phys_end;
kaf24@6111 458 if ( (s < initial_images_end) && (e > initial_images_start) )
kaf24@6111 459 s = initial_images_end;
kaf24@6111 460 init_boot_pages(s, e);
kaf24@6111 461
kaf24@5003 462 #if defined (CONFIG_X86_64)
kaf24@5003 463 /*
kaf24@5003 464 * x86/64 maps all registered RAM. Points to note:
kaf24@9783 465 * 1. The initial pagetable already maps low 1GB, so skip that.
kaf24@5003 466 * 2. We must map *only* RAM areas, taking care to avoid I/O holes.
kaf24@5003 467 * Failure to do this can cause coherency problems and deadlocks
kaf24@5003 468 * due to cache-attribute mismatches (e.g., AMD/AGP Linux bug).
kaf24@5003 469 */
kaf24@5003 470 {
kaf24@5004 471 /* Calculate page-frame range, discarding partial frames. */
kaf24@5004 472 unsigned long start, end;
kaf24@9783 473 unsigned long init_mapped = 1UL << (30 - PAGE_SHIFT); /* 1GB */
kaf24@5005 474 start = PFN_UP(e820.map[i].addr);
kaf24@5005 475 end = PFN_DOWN(e820.map[i].addr + e820.map[i].size);
kaf24@9800 476 /* Clip the range to exclude what the bootstrapper initialised. */
kaf24@9783 477 if ( end < init_mapped )
kaf24@5004 478 continue;
kaf24@9783 479 if ( start < init_mapped )
kaf24@9783 480 start = init_mapped;
kaf24@5004 481 /* Request the mapping. */
kaf24@5003 482 map_pages_to_xen(
kaf24@5004 483 PAGE_OFFSET + (start << PAGE_SHIFT),
kaf24@5004 484 start, end-start, PAGE_HYPERVISOR);
kaf24@5003 485 }
kaf24@5003 486 #endif
kaf24@3354 487 }
kaf24@3354 488
ian@12713 489 if ( kexec_crash_area.size > 0 )
ian@12681 490 {
ian@12677 491 unsigned long kdump_start, kdump_size, k;
ian@12677 492
ian@12681 493 /* Mark images pages as free for now. */
ian@12677 494
ian@12677 495 init_boot_pages(initial_images_start, initial_images_end);
ian@12677 496
ian@12713 497 kdump_start = kexec_crash_area.start;
ian@12713 498 kdump_size = kexec_crash_area.size;
ian@12677 499
ian@12681 500 printk("Kdump: %luMB (%lukB) at 0x%lx\n",
ian@12677 501 kdump_size >> 20,
ian@12677 502 kdump_size >> 10,
ian@12677 503 kdump_start);
ian@12677 504
ian@12681 505 if ( (kdump_start & ~PAGE_MASK) || (kdump_size & ~PAGE_MASK) )
ian@12677 506 panic("Kdump parameters not page aligned\n");
ian@12677 507
ian@12677 508 kdump_start >>= PAGE_SHIFT;
ian@12677 509 kdump_size >>= PAGE_SHIFT;
ian@12677 510
kfraser@12853 511 /* Allocate pages for Kdump memory area. */
ian@12677 512
ian@12677 513 k = alloc_boot_pages_at(kdump_size, kdump_start);
ian@12681 514 if ( k != kdump_start )
ian@12677 515 panic("Unable to reserve Kdump memory\n");
ian@12677 516
kfraser@12853 517 /* Allocate pages for relocated initial images. */
ian@12677 518
ian@12677 519 k = ((initial_images_end - initial_images_start) & ~PAGE_MASK) ? 1 : 0;
ian@12677 520 k += (initial_images_end - initial_images_start) >> PAGE_SHIFT;
ian@12677 521
ian@12677 522 k = alloc_boot_pages(k, 1);
kfraser@12853 523 if ( k == 0 )
ian@12677 524 panic("Unable to allocate initial images memory\n");
ian@12677 525
ian@12677 526 move_memory(k << PAGE_SHIFT, initial_images_start, initial_images_end);
ian@12677 527
ian@12677 528 initial_images_end -= initial_images_start;
ian@12677 529 initial_images_start = k << PAGE_SHIFT;
ian@12677 530 initial_images_end += initial_images_start;
ian@12681 531 }
ian@12677 532
kaf24@5003 533 memguard_init();
kfraser@11241 534 percpu_guard_areas();
kaf24@4950 535
ian@12681 536 printk("System RAM: %luMB (%lukB)\n",
kaf24@3354 537 nr_pages >> (20 - PAGE_SHIFT),
kaf24@3354 538 nr_pages << (PAGE_SHIFT - 10));
kaf24@7220 539 total_pages = nr_pages;
kaf24@3354 540
kfraser@11296 541 /* Sanity check for unwanted bloat of certain hypercall structures. */
kfraser@11296 542 BUILD_BUG_ON(sizeof(((struct xen_platform_op *)0)->u) !=
kfraser@11296 543 sizeof(((struct xen_platform_op *)0)->u.pad));
kfraser@11296 544 BUILD_BUG_ON(sizeof(((struct xen_domctl *)0)->u) !=
kfraser@11296 545 sizeof(((struct xen_domctl *)0)->u.pad));
kfraser@11296 546 BUILD_BUG_ON(sizeof(((struct xen_sysctl *)0)->u) !=
kfraser@11296 547 sizeof(((struct xen_sysctl *)0)->u.pad));
kaf24@7388 548
kaf24@9878 549 BUILD_BUG_ON(sizeof(start_info_t) > PAGE_SIZE);
kaf24@9878 550 BUILD_BUG_ON(sizeof(shared_info_t) > PAGE_SIZE);
kaf24@9878 551 BUILD_BUG_ON(sizeof(vcpu_info_t) != 64);
kaf24@7744 552
ack@13291 553 #ifdef CONFIG_COMPAT
ack@13291 554 BUILD_BUG_ON(sizeof(((struct compat_platform_op *)0)->u) !=
ack@13291 555 sizeof(((struct compat_platform_op *)0)->u.pad));
ack@13291 556 BUILD_BUG_ON(sizeof(start_info_compat_t) > PAGE_SIZE);
ack@13291 557 BUILD_BUG_ON(sizeof(shared_info_compat_t) > PAGE_SIZE);
ack@13291 558 BUILD_BUG_ON(sizeof(vcpu_info_compat_t) != 64);
ack@13291 559 #endif
ack@13291 560
kfraser@10492 561 /* Check definitions in public headers match internal defs. */
kaf24@9878 562 BUILD_BUG_ON(__HYPERVISOR_VIRT_START != HYPERVISOR_VIRT_START);
kaf24@8521 563 #ifdef HYPERVISOR_VIRT_END
kaf24@9878 564 BUILD_BUG_ON(__HYPERVISOR_VIRT_END != HYPERVISOR_VIRT_END);
kaf24@8521 565 #endif
kfraser@10492 566 BUILD_BUG_ON(MACH2PHYS_VIRT_START != RO_MPT_VIRT_START);
kfraser@10492 567 BUILD_BUG_ON(MACH2PHYS_VIRT_END != RO_MPT_VIRT_END);
kaf24@8521 568
kaf24@3354 569 init_frametable();
kaf24@3338 570
kfraser@11971 571 acpi_boot_table_init();
kfraser@11971 572
kfraser@11971 573 acpi_numa_init();
kfraser@11971 574
kfraser@11971 575 numa_initmem_init(0, max_page);
kfraser@11971 576
kaf24@3354 577 end_boot_allocator();
kaf24@3354 578
kaf24@6111 579 /* Initialise the Xen heap, skipping RAM holes. */
kaf24@6111 580 nr_pages = 0;
kaf24@6111 581 for ( i = 0; i < e820.nr_map; i++ )
kaf24@6111 582 {
kaf24@6111 583 if ( e820.map[i].type != E820_RAM )
kaf24@6111 584 continue;
kaf24@6111 585
kaf24@6111 586 s = e820.map[i].addr;
kaf24@6111 587 e = s + e820.map[i].size;
kaf24@6111 588 if ( s < xenheap_phys_start )
kaf24@6111 589 s = xenheap_phys_start;
kaf24@6111 590 if ( e > xenheap_phys_end )
kaf24@6111 591 e = xenheap_phys_end;
kaf24@6111 592
kaf24@6111 593 if ( s < e )
kaf24@6111 594 {
kaf24@6111 595 nr_pages += (e - s) >> PAGE_SHIFT;
kaf24@6111 596 init_xenheap_pages(s, e);
kaf24@6111 597 }
kaf24@6111 598 }
kaf24@6111 599
kaf24@6111 600 printk("Xen heap: %luMB (%lukB)\n",
kaf24@6111 601 nr_pages >> (20 - PAGE_SHIFT),
kaf24@6111 602 nr_pages << (PAGE_SHIFT - 10));
kaf24@3338 603
kaf24@3594 604 early_boot = 0;
kaf24@3338 605
kaf24@8459 606 early_cpu_init();
kaf24@8459 607
kaf24@8459 608 paging_init();
kaf24@8459 609
kaf24@8459 610 /* Unmap the first page of CPU0's stack. */
kaf24@8459 611 memguard_guard_stack(cpu0_stack);
kaf24@8459 612
kaf24@8459 613 open_softirq(NEW_TLBFLUSH_CLOCK_PERIOD_SOFTIRQ, new_tlbflush_clock_period);
kaf24@8459 614
kaf24@8459 615 if ( opt_watchdog )
kaf24@8459 616 nmi_watchdog = NMI_LOCAL_APIC;
kaf24@8459 617
kaf24@8459 618 sort_exception_tables();
kaf24@8459 619
kaf24@8459 620 find_smp_config();
kaf24@8459 621
kaf24@8459 622 smp_alloc_memory();
kaf24@8459 623
kaf24@8459 624 dmi_scan_machine();
kaf24@8459 625
kaf24@8459 626 generic_apic_probe();
kaf24@8459 627
kaf24@8459 628 acpi_boot_init();
kaf24@8459 629
kfraser@11971 630 init_cpu_to_node();
kfraser@11971 631
kfraser@11241 632 if ( smp_found_config )
kaf24@8459 633 get_smp_config();
kaf24@8459 634
kaf24@8459 635 init_apic_mappings();
kaf24@8459 636
kaf24@8459 637 init_IRQ();
kaf24@8459 638
kfraser@11241 639 percpu_init_areas();
kfraser@11241 640
kfraser@11240 641 init_idle_domain();
kfraser@11240 642
kaf24@8459 643 trap_init();
kaf24@8459 644
kaf24@8586 645 timer_init();
kaf24@8459 646
kaf24@8459 647 early_time_init();
kaf24@8459 648
kaf24@8459 649 arch_init_memory();
kaf24@8459 650
kaf24@8459 651 identify_cpu(&boot_cpu_data);
kaf24@8459 652 if ( cpu_has_fxsr )
kaf24@8459 653 set_in_cr4(X86_CR4_OSFXSR);
kaf24@8459 654 if ( cpu_has_xmm )
kaf24@8459 655 set_in_cr4(X86_CR4_OSXMMEXCPT);
kaf24@8459 656
kaf24@8459 657 if ( opt_nosmp )
kaf24@8459 658 max_cpus = 0;
kaf24@8459 659
kaf24@8459 660 smp_prepare_cpus(max_cpus);
kaf24@8459 661
kaf24@8459 662 /*
kaf24@8459 663 * Initialise higher-level timer functions. We do this fairly late
kaf24@8459 664 * (post-SMP) because the time bases and scale factors need to be updated
kaf24@8459 665 * regularly, and SMP initialisation can cause a long delay with
kaf24@8459 666 * interrupts not yet enabled.
kaf24@8459 667 */
kaf24@8459 668 init_xen_time();
kaf24@8459 669
kaf24@8459 670 initialize_keytable();
kaf24@8459 671
kaf24@8459 672 serial_init_postirq();
kaf24@8459 673
kaf24@8459 674 BUG_ON(!local_irq_is_enabled());
kaf24@8459 675
kaf24@8459 676 for_each_present_cpu ( i )
kaf24@8459 677 {
kaf24@8459 678 if ( num_online_cpus() >= max_cpus )
kaf24@8459 679 break;
kaf24@8459 680 if ( !cpu_online(i) )
kaf24@8459 681 __cpu_up(i);
kfraser@11971 682
kfraser@11998 683 /* Set up cpu_to_node[]. */
kfraser@11971 684 srat_detect_node(i);
kfraser@11998 685 /* Set up node_to_cpumask based on cpu_to_node[]. */
kfraser@11971 686 numa_add_cpu(i);
kaf24@8459 687 }
kaf24@8459 688
kaf24@8459 689 printk("Brought up %ld CPUs\n", (long)num_online_cpus());
kaf24@8459 690 smp_cpus_done(max_cpus);
kaf24@8459 691
kaf24@9818 692 percpu_free_unused_areas();
kaf24@9818 693
kaf24@9117 694 initialise_gdb(); /* could be moved earlier */
kaf24@9117 695
kaf24@8459 696 do_initcalls();
kaf24@8459 697
kaf24@8459 698 schedulers_start();
kaf24@8459 699
kaf24@8594 700 if ( opt_watchdog )
kaf24@8594 701 watchdog_enable();
kaf24@8459 702
kfraser@11881 703 /* Extract policy from multiboot. */
kfraser@11881 704 extract_acm_policy(mbi, &initrdidx, &_policy_start, &_policy_len);
kfraser@11881 705
kaf24@8459 706 /* initialize access control security module */
kfraser@11881 707 acm_init(_policy_start, _policy_len);
kaf24@8459 708
kaf24@8459 709 /* Create initial domain 0. */
kfraser@12210 710 dom0 = domain_create(0, 0);
kfraser@10655 711 if ( (dom0 == NULL) || (alloc_vcpu(dom0, 0, 0) == NULL) )
kaf24@8459 712 panic("Error creating domain 0\n");
kaf24@8459 713
kfraser@12210 714 dom0->is_privileged = 1;
kfraser@12210 715
kfraser@12210 716 /* Post-create hook sets security label. */
kaf24@8459 717 acm_post_domain0_create(dom0->domain_id);
kaf24@8459 718
kaf24@8459 719 /* Grab the DOM0 command line. */
kaf24@8459 720 cmdline = (char *)(mod[0].string ? __va(mod[0].string) : NULL);
kaf24@8459 721 if ( cmdline != NULL )
kaf24@8459 722 {
kaf24@8459 723 static char dom0_cmdline[MAX_GUEST_CMDLINE];
kaf24@8459 724
kaf24@8459 725 /* Skip past the image name and copy to a local buffer. */
kaf24@8459 726 while ( *cmdline == ' ' ) cmdline++;
kaf24@8459 727 if ( (cmdline = strchr(cmdline, ' ')) != NULL )
kaf24@8459 728 {
kaf24@8459 729 while ( *cmdline == ' ' ) cmdline++;
kaf24@8459 730 strcpy(dom0_cmdline, cmdline);
kaf24@8459 731 }
kaf24@8459 732
kaf24@8459 733 cmdline = dom0_cmdline;
kaf24@8459 734
kaf24@8459 735 /* Append any extra parameters. */
kaf24@8459 736 if ( skip_ioapic_setup && !strstr(cmdline, "noapic") )
kaf24@8459 737 strcat(cmdline, " noapic");
kaf24@8459 738 if ( acpi_skip_timer_override &&
kaf24@8459 739 !strstr(cmdline, "acpi_skip_timer_override") )
kaf24@8459 740 strcat(cmdline, " acpi_skip_timer_override");
kaf24@8459 741 if ( (strlen(acpi_param) != 0) && !strstr(cmdline, "acpi=") )
kaf24@8459 742 {
kaf24@8459 743 strcat(cmdline, " acpi=");
kaf24@8459 744 strcat(cmdline, acpi_param);
kaf24@8459 745 }
kaf24@8459 746 }
kaf24@8459 747
kaf24@8459 748 if ( (initrdidx > 0) && (initrdidx < mbi->mods_count) )
kaf24@8459 749 {
kaf24@8459 750 _initrd_start = initial_images_start +
kaf24@8459 751 (mod[initrdidx].mod_start - mod[0].mod_start);
kaf24@8459 752 _initrd_len = mod[initrdidx].mod_end - mod[initrdidx].mod_start;
kaf24@8459 753 }
kaf24@8459 754
kaf24@8459 755 /*
kaf24@8459 756 * We're going to setup domain0 using the module(s) that we stashed safely
kaf24@8459 757 * above our heap. The second module, if present, is an initrd ramdisk.
kaf24@8459 758 */
kaf24@8459 759 if ( construct_dom0(dom0,
kaf24@8459 760 initial_images_start,
kaf24@8459 761 mod[0].mod_end-mod[0].mod_start,
kaf24@8459 762 _initrd_start,
kaf24@8459 763 _initrd_len,
kaf24@8459 764 cmdline) != 0)
kaf24@8459 765 panic("Could not set up DOM0 guest OS\n");
kaf24@8459 766
kaf24@8459 767 /* Scrub RAM that is still free and so may go to an unprivileged domain. */
kaf24@8459 768 scrub_heap_pages();
kaf24@8459 769
kaf24@8459 770 init_trace_bufs();
kaf24@8459 771
kaf24@10502 772 console_endboot();
kaf24@8459 773
kaf24@8459 774 /* Hide UART from DOM0 if we're using it */
kaf24@8459 775 serial_endboot();
kaf24@8459 776
kaf24@8459 777 domain_unpause_by_systemcontroller(dom0);
kaf24@8459 778
kaf24@8459 779 startup_cpu_idle_loop();
kaf24@8459 780 }
kaf24@8459 781
kaf24@6725 782 void arch_get_xen_caps(xen_capabilities_info_t info)
iap10@6721 783 {
kaf24@6725 784 char *p = info;
kfraser@10890 785 int major = xen_major_version();
kfraser@10890 786 int minor = xen_minor_version();
iap10@6721 787
kaf24@6725 788 #if defined(CONFIG_X86_32) && !defined(CONFIG_X86_PAE)
kaf24@6725 789
kfraser@10890 790 p += sprintf(p, "xen-%d.%d-x86_32 ", major, minor);
kaf24@6725 791 if ( hvm_enabled )
kfraser@10890 792 p += sprintf(p, "hvm-%d.%d-x86_32 ", major, minor);
kaf24@6725 793
kaf24@6725 794 #elif defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
kaf24@6725 795
kfraser@10890 796 p += sprintf(p, "xen-%d.%d-x86_32p ", major, minor);
kaf24@6725 797 if ( hvm_enabled )
iap10@6721 798 {
kfraser@10890 799 p += sprintf(p, "hvm-%d.%d-x86_32 ", major, minor);
kfraser@10890 800 p += sprintf(p, "hvm-%d.%d-x86_32p ", major, minor);
iap10@6721 801 }
iap10@6721 802
kaf24@6725 803 #elif defined(CONFIG_X86_64)
iap10@6721 804
kfraser@10890 805 p += sprintf(p, "xen-%d.%d-x86_64 ", major, minor);
ack@13288 806 #ifdef CONFIG_COMPAT
ack@13288 807 p += sprintf(p, "xen-%d.%d-x86_32p ", major, minor);
ack@13288 808 #endif
kaf24@6725 809 if ( hvm_enabled )
iap10@6721 810 {
kfraser@10890 811 p += sprintf(p, "hvm-%d.%d-x86_32 ", major, minor);
kfraser@10890 812 p += sprintf(p, "hvm-%d.%d-x86_32p ", major, minor);
kfraser@10890 813 p += sprintf(p, "hvm-%d.%d-x86_64 ", major, minor);
iap10@6721 814 }
kaf24@6725 815
kaf24@6725 816 #else
kaf24@6725 817
kaf24@6725 818 p++;
kaf24@6725 819
iap10@6721 820 #endif
kaf24@8246 821
kaf24@6725 822 *(p-1) = 0;
iap10@6721 823
shand@6734 824 BUG_ON((p - info) > sizeof(xen_capabilities_info_t));
iap10@6721 825 }
iap10@6721 826
kaf24@3914 827 /*
kaf24@3914 828 * Local variables:
kaf24@3914 829 * mode: C
kaf24@3914 830 * c-set-style: "BSD"
kaf24@3914 831 * c-basic-offset: 4
kaf24@3914 832 * tab-width: 4
kaf24@3914 833 * indent-tabs-mode: nil
kaf24@3988 834 * End:
kaf24@3914 835 */