ia64/xen-unstable

annotate xen/arch/x86/setup.c @ 9878:ef0a56c0784d

Add BUILD_BUG_ON() and a handful of users.
Signed-off-by: Jan Beulich <jbeulich@novell.com>
author kaf24@firebug.cl.cam.ac.uk
date Thu Apr 27 15:55:09 2006 +0100 (2006-04-27)
parents 428babd7c1e0
children 4122e88b6c75
rev   line source
kaf24@1452 1
kaf24@1452 2 #include <xen/config.h>
kaf24@1452 3 #include <xen/init.h>
kaf24@1452 4 #include <xen/lib.h>
kaf24@1452 5 #include <xen/sched.h>
cl349@5247 6 #include <xen/domain.h>
kaf24@1452 7 #include <xen/serial.h>
kaf24@1506 8 #include <xen/softirq.h>
kaf24@1452 9 #include <xen/acpi.h>
kaf24@3338 10 #include <xen/console.h>
iap10@4287 11 #include <xen/serial.h>
kaf24@3338 12 #include <xen/trace.h>
kaf24@3338 13 #include <xen/multiboot.h>
kaf24@5356 14 #include <xen/domain_page.h>
iap10@6721 15 #include <xen/compile.h>
kaf24@9117 16 #include <xen/gdbstub.h>
kaf24@9818 17 #include <xen/percpu.h>
iap10@6721 18 #include <public/version.h>
kaf24@1452 19 #include <asm/bitops.h>
kaf24@1452 20 #include <asm/smp.h>
kaf24@1452 21 #include <asm/processor.h>
kaf24@1452 22 #include <asm/mpspec.h>
kaf24@1452 23 #include <asm/apic.h>
kaf24@1452 24 #include <asm/desc.h>
kaf24@3338 25 #include <asm/shadow.h>
kaf24@3344 26 #include <asm/e820.h>
kaf24@5536 27 #include <acm/acm_hooks.h>
kaf24@3338 28
kaf24@5157 29 extern void dmi_scan_machine(void);
kaf24@5211 30 extern void generic_apic_probe(void);
kaf24@5157 31
kaf24@3338 32 /*
kaf24@3338 33 * opt_xenheap_megabytes: Size of Xen heap in megabytes, excluding the
kaf24@8726 34 * page_info table and allocation bitmap.
kaf24@3338 35 */
kaf24@3338 36 static unsigned int opt_xenheap_megabytes = XENHEAP_DEFAULT_MB;
kaf24@4950 37 #if defined(CONFIG_X86_64)
kaf24@3338 38 integer_param("xenheap_megabytes", opt_xenheap_megabytes);
kaf24@3354 39 #endif
kaf24@1452 40
kaf24@5146 41 /* opt_nosmp: If true, secondary processors are ignored. */
kaf24@5900 42 static int opt_nosmp = 0;
kaf24@5146 43 boolean_param("nosmp", opt_nosmp);
kaf24@5146 44
kaf24@5146 45 /* maxcpus: maximum number of CPUs to activate. */
kaf24@5146 46 static unsigned int max_cpus = NR_CPUS;
kaf24@5146 47 integer_param("maxcpus", max_cpus);
kaf24@5146 48
kaf24@3334 49 /* opt_watchdog: If true, run a watchdog NMI on each processor. */
kaf24@3334 50 static int opt_watchdog = 0;
kaf24@3334 51 boolean_param("watchdog", opt_watchdog);
kaf24@3334 52
kaf24@4850 53 /* **** Linux config option: propagated to domain0. */
kaf24@4850 54 /* "acpi=off": Sisables both ACPI table parsing and interpreter. */
kaf24@4850 55 /* "acpi=force": Override the disable blacklist. */
kaf24@4850 56 /* "acpi=strict": Disables out-of-spec workarounds. */
kaf24@4850 57 /* "acpi=ht": Limit ACPI just to boot-time to enable HT. */
kaf24@4850 58 /* "acpi=noirq": Disables ACPI interrupt routing. */
kaf24@4850 59 static void parse_acpi_param(char *s);
kaf24@4850 60 custom_param("acpi", parse_acpi_param);
kaf24@4850 61
kaf24@4850 62 /* **** Linux config option: propagated to domain0. */
kaf24@4850 63 /* acpi_skip_timer_override: Skip IRQ0 overrides. */
kaf24@4850 64 extern int acpi_skip_timer_override;
kaf24@4850 65 boolean_param("acpi_skip_timer_override", acpi_skip_timer_override);
kaf24@4850 66
kaf24@4850 67 /* **** Linux config option: propagated to domain0. */
kaf24@4850 68 /* noapic: Disable IOAPIC setup. */
kaf24@4850 69 extern int skip_ioapic_setup;
kaf24@4850 70 boolean_param("noapic", skip_ioapic_setup);
kaf24@4850 71
kaf24@3594 72 int early_boot = 1;
kaf24@3594 73
kaf24@5146 74 cpumask_t cpu_present_map;
kaf24@5146 75
kaf24@5003 76 /* Limits of Xen heap, used to initialise the allocator. */
kaf24@5003 77 unsigned long xenheap_phys_start, xenheap_phys_end;
kaf24@3338 78
kaf24@2298 79 extern void arch_init_memory(void);
kaf24@1589 80 extern void init_IRQ(void);
kaf24@1589 81 extern void trap_init(void);
kaf24@5604 82 extern void early_time_init(void);
kaf24@5167 83 extern void initialize_keytable(void);
kaf24@5167 84 extern void early_cpu_init(void);
kaf24@1589 85
kaf24@8533 86 struct tss_struct init_tss[NR_CPUS];
kaf24@8533 87
kaf24@8533 88 struct vcpu *idle_vcpu[NR_CPUS];
kaf24@8533 89
kaf24@5011 90 extern unsigned long cpu0_stack[];
kaf24@5011 91
kaf24@5214 92 struct cpuinfo_x86 boot_cpu_data = { 0, 0, 0, 0, -1, 1, 0, 0, -1 };
kaf24@1452 93
kaf24@5237 94 #if CONFIG_PAGING_LEVELS > 2
kaf24@1670 95 unsigned long mmu_cr4_features = X86_CR4_PSE | X86_CR4_PGE | X86_CR4_PAE;
kaf24@1670 96 #else
kaf24@5593 97 unsigned long mmu_cr4_features = X86_CR4_PSE;
kaf24@1670 98 #endif
kaf24@1452 99 EXPORT_SYMBOL(mmu_cr4_features);
kaf24@1452 100
kaf24@4818 101 int acpi_disabled;
kaf24@1452 102
kaf24@4850 103 int acpi_force;
kaf24@4850 104 char acpi_param[10] = "";
kaf24@4850 105 static void parse_acpi_param(char *s)
kaf24@4850 106 {
kaf24@4850 107 /* Save the parameter so it can be propagated to domain0. */
kaf24@4850 108 strncpy(acpi_param, s, sizeof(acpi_param));
kaf24@4850 109 acpi_param[sizeof(acpi_param)-1] = '\0';
kaf24@4850 110
kaf24@4850 111 /* Interpret the parameter for use within Xen. */
kaf24@4850 112 if ( !strcmp(s, "off") )
kaf24@4850 113 {
kaf24@4850 114 disable_acpi();
kaf24@4850 115 }
kaf24@4850 116 else if ( !strcmp(s, "force") )
kaf24@4850 117 {
kaf24@4850 118 acpi_force = 1;
kaf24@4850 119 acpi_ht = 1;
kaf24@4850 120 acpi_disabled = 0;
kaf24@4850 121 }
kaf24@4850 122 else if ( !strcmp(s, "strict") )
kaf24@4850 123 {
kaf24@4850 124 acpi_strict = 1;
kaf24@4850 125 }
kaf24@4850 126 else if ( !strcmp(s, "ht") )
kaf24@4850 127 {
kaf24@4850 128 if ( !acpi_force )
kaf24@4850 129 disable_acpi();
kaf24@4850 130 acpi_ht = 1;
kaf24@4850 131 }
kaf24@4850 132 else if ( !strcmp(s, "noirq") )
kaf24@4850 133 {
kaf24@4850 134 acpi_noirq_set();
kaf24@4850 135 }
kaf24@4850 136 }
kaf24@4850 137
kaf24@1452 138 static void __init do_initcalls(void)
kaf24@1452 139 {
kaf24@1452 140 initcall_t *call;
kaf24@1452 141 for ( call = &__initcall_start; call < &__initcall_end; call++ )
kaf24@1452 142 (*call)();
kaf24@1452 143 }
kaf24@1452 144
kaf24@8459 145 #define EARLY_FAIL() for ( ; ; ) __asm__ __volatile__ ( "hlt" )
kaf24@8459 146
kaf24@8459 147 static struct e820entry e820_raw[E820MAX];
kaf24@8459 148
kaf24@9067 149 static unsigned long initial_images_start, initial_images_end;
kaf24@9067 150
kaf24@9067 151 unsigned long initial_images_nrpages(void)
kaf24@9067 152 {
kaf24@9067 153 unsigned long s = initial_images_start + PAGE_SIZE - 1;
kaf24@9067 154 unsigned long e = initial_images_end;
kaf24@9067 155 return ((e >> PAGE_SHIFT) - (s >> PAGE_SHIFT));
kaf24@9067 156 }
kaf24@9067 157
kaf24@9067 158 void discard_initial_images(void)
kaf24@9067 159 {
kaf24@9067 160 init_domheap_pages(initial_images_start, initial_images_end);
kaf24@9067 161 }
kaf24@9067 162
kaf24@9818 163 extern char __per_cpu_start[], __per_cpu_data_end[], __per_cpu_end[];
kaf24@9818 164
kaf24@9818 165 static void percpu_init_areas(void)
kaf24@9818 166 {
kaf24@9818 167 unsigned int i, data_size = __per_cpu_data_end - __per_cpu_start;
kaf24@9818 168
kaf24@9818 169 BUG_ON(data_size > PERCPU_SIZE);
kaf24@9818 170
kaf24@9818 171 for ( i = 1; i < NR_CPUS; i++ )
kaf24@9818 172 memcpy(__per_cpu_start + (i << PERCPU_SHIFT),
kaf24@9818 173 __per_cpu_start,
kaf24@9818 174 data_size);
kaf24@9818 175 }
kaf24@9818 176
kaf24@9818 177 static void percpu_free_unused_areas(void)
kaf24@9818 178 {
kaf24@9818 179 unsigned int i, first_unused;
kaf24@9818 180
kaf24@9818 181 /* Find first unused CPU number. */
kaf24@9818 182 for ( i = 0; i < NR_CPUS; i++ )
kaf24@9818 183 if ( !cpu_online(i) )
kaf24@9818 184 break;
kaf24@9818 185 first_unused = i;
kaf24@9818 186
kaf24@9818 187 /* Check that there are no holes in cpu_online_map. */
kaf24@9818 188 for ( ; i < NR_CPUS; i++ )
kaf24@9818 189 BUG_ON(cpu_online(i));
kaf24@9818 190
kaf24@9818 191 init_xenheap_pages(__pa(__per_cpu_start) + (first_unused << PERCPU_SHIFT),
kaf24@9818 192 __pa(__per_cpu_end));
kaf24@9818 193 }
kaf24@9818 194
kaf24@8463 195 void __init __start_xen(multiboot_info_t *mbi)
kaf24@1452 196 {
kaf24@9823 197 char __cmdline[] = "", *cmdline = __cmdline;
kaf24@8533 198 struct domain *idle_domain;
kaf24@8457 199 unsigned long _initrd_start = 0, _initrd_len = 0;
kaf24@8457 200 unsigned int initrdidx = 1;
kaf24@8457 201 module_t *mod = (module_t *)__va(mbi->mods_addr);
kaf24@6111 202 unsigned long nr_pages, modules_length;
kaf24@8726 203 paddr_t s, e;
kaf24@8402 204 int i, e820_warn = 0, e820_raw_nr = 0, bytes = 0;
kaf24@5776 205 struct ns16550_defaults ns16550 = {
kaf24@5776 206 .data_bits = 8,
kaf24@5776 207 .parity = 'n',
kaf24@5776 208 .stop_bits = 1
kaf24@5776 209 };
kaf24@3338 210
kaf24@3338 211 /* Parse the command-line options. */
kaf24@3344 212 if ( (mbi->flags & MBI_CMDLINE) && (mbi->cmdline != 0) )
kaf24@9823 213 cmdline = __va(mbi->cmdline);
kaf24@9823 214 cmdline_parse(cmdline);
kaf24@3338 215
kaf24@8534 216 set_current((struct vcpu *)0xfffff000); /* debug sanity */
kaf24@8534 217 set_processor_id(0); /* needed early, for smp_processor_id() */
kaf24@3338 218
kaf24@5146 219 smp_prepare_boot_cpu();
kaf24@5146 220
kaf24@3338 221 /* We initialise the serial devices very early so we can get debugging. */
kaf24@5776 222 ns16550.io_base = 0x3f8;
kaf24@5776 223 ns16550.irq = 4;
kaf24@5776 224 ns16550_init(0, &ns16550);
kaf24@5776 225 ns16550.io_base = 0x2f8;
kaf24@5776 226 ns16550.irq = 3;
kaf24@5776 227 ns16550_init(1, &ns16550);
kaf24@5195 228 serial_init_preirq();
kaf24@3338 229
kaf24@3338 230 init_console();
kaf24@3338 231
kaf24@9823 232 printf("Command line: %s\n", cmdline);
kaf24@9823 233
kaf24@3344 234 /* Check that we have at least one Multiboot module. */
kaf24@3344 235 if ( !(mbi->flags & MBI_MODULES) || (mbi->mods_count == 0) )
kaf24@3338 236 {
kaf24@5542 237 printk("FATAL ERROR: dom0 kernel not specified."
kaf24@5542 238 " Check bootloader configuration.\n");
kaf24@5011 239 EARLY_FAIL();
kaf24@5011 240 }
kaf24@5011 241
kaf24@5011 242 if ( ((unsigned long)cpu0_stack & (STACK_SIZE-1)) != 0 )
kaf24@5011 243 {
kaf24@5011 244 printk("FATAL ERROR: Misaligned CPU0 stack.\n");
kaf24@5011 245 EARLY_FAIL();
kaf24@3338 246 }
kaf24@3338 247
kaf24@9818 248 percpu_init_areas();
kaf24@9818 249
kaf24@3338 250 xenheap_phys_end = opt_xenheap_megabytes << 20;
kaf24@3338 251
kaf24@3344 252 if ( mbi->flags & MBI_MEMMAP )
kaf24@3344 253 {
kaf24@3344 254 while ( bytes < mbi->mmap_length )
kaf24@3344 255 {
kaf24@3344 256 memory_map_t *map = __va(mbi->mmap_addr + bytes);
kaf24@8402 257
kaf24@8402 258 /*
kaf24@8403 259 * This is a gross workaround for a BIOS bug. Some bootloaders do
kaf24@8402 260 * not write e820 map entries into pre-zeroed memory. This is
kaf24@8402 261 * okay if the BIOS fills in all fields of the map entry, but
kaf24@8402 262 * some broken BIOSes do not bother to write the high word of
kaf24@8402 263 * the length field if the length is smaller than 4GB. We
kaf24@8402 264 * detect and fix this by flagging sections below 4GB that
kaf24@8403 265 * appear to be larger than 4GB in size.
kaf24@8402 266 */
kaf24@8403 267 if ( (map->base_addr_high == 0) && (map->length_high != 0) )
kaf24@8402 268 {
kaf24@8402 269 e820_warn = 1;
kaf24@8402 270 map->length_high = 0;
kaf24@8402 271 }
kaf24@8402 272
kaf24@3344 273 e820_raw[e820_raw_nr].addr =
kaf24@3344 274 ((u64)map->base_addr_high << 32) | (u64)map->base_addr_low;
kaf24@3344 275 e820_raw[e820_raw_nr].size =
kaf24@3344 276 ((u64)map->length_high << 32) | (u64)map->length_low;
kaf24@3344 277 e820_raw[e820_raw_nr].type =
kaf24@3346 278 (map->type > E820_SHARED_PAGE) ? E820_RESERVED : map->type;
kaf24@3344 279 e820_raw_nr++;
kaf24@8402 280
kaf24@3344 281 bytes += map->size + 4;
kaf24@3344 282 }
kaf24@3344 283 }
kaf24@3344 284 else if ( mbi->flags & MBI_MEMLIMITS )
kaf24@3344 285 {
kaf24@3344 286 e820_raw[0].addr = 0;
kaf24@3344 287 e820_raw[0].size = mbi->mem_lower << 10;
kaf24@3344 288 e820_raw[0].type = E820_RAM;
kaf24@3354 289 e820_raw[1].addr = 0x100000;
kaf24@3354 290 e820_raw[1].size = mbi->mem_upper << 10;
kaf24@3354 291 e820_raw[1].type = E820_RAM;
kaf24@3344 292 e820_raw_nr = 2;
kaf24@3344 293 }
kaf24@3344 294 else
kaf24@3344 295 {
kaf24@3344 296 printk("FATAL ERROR: Bootloader provided no memory information.\n");
kaf24@3344 297 for ( ; ; ) ;
kaf24@3344 298 }
kaf24@3344 299
kaf24@8402 300 if ( e820_warn )
kaf24@8402 301 printk("WARNING: Buggy e820 map detected and fixed "
kaf24@8402 302 "(truncated length fields).\n");
kaf24@8402 303
kaf24@4950 304 max_page = init_e820(e820_raw, &e820_raw_nr);
kaf24@3338 305
kaf24@6111 306 modules_length = mod[mbi->mods_count-1].mod_end - mod[0].mod_start;
kaf24@3338 307
kaf24@6111 308 /* Find a large enough RAM extent to stash the DOM0 modules. */
kaf24@6111 309 for ( i = 0; ; i++ )
kaf24@3338 310 {
kaf24@6111 311 if ( i == e820.nr_map )
kaf24@6111 312 {
kaf24@6111 313 printk("Not enough memory to stash the DOM0 kernel image.\n");
kaf24@6111 314 for ( ; ; ) ;
kaf24@6111 315 }
kaf24@6134 316
kaf24@6134 317 if ( (e820.map[i].type == E820_RAM) &&
kaf24@6134 318 (e820.map[i].size >= modules_length) &&
kaf24@6134 319 ((e820.map[i].addr + e820.map[i].size) >=
kaf24@6134 320 (xenheap_phys_end + modules_length)) )
kaf24@6134 321 break;
kaf24@3338 322 }
kaf24@6111 323
kaf24@6134 324 /* Stash as near as possible to the beginning of the RAM extent. */
kaf24@6134 325 initial_images_start = e820.map[i].addr;
kaf24@6134 326 if ( initial_images_start < xenheap_phys_end )
kaf24@6134 327 initial_images_start = xenheap_phys_end;
kaf24@6134 328 initial_images_end = initial_images_start + modules_length;
kaf24@6134 329
kaf24@4950 330 #if defined(CONFIG_X86_32)
kaf24@3338 331 memmove((void *)initial_images_start, /* use low mapping */
kaf24@3338 332 (void *)mod[0].mod_start, /* use low mapping */
kaf24@3338 333 mod[mbi->mods_count-1].mod_end - mod[0].mod_start);
kaf24@4950 334 #elif defined(CONFIG_X86_64)
kaf24@3338 335 memmove(__va(initial_images_start),
kaf24@3338 336 __va(mod[0].mod_start),
kaf24@3338 337 mod[mbi->mods_count-1].mod_end - mod[0].mod_start);
kaf24@3338 338 #endif
kaf24@3338 339
kaf24@3354 340 /* Initialise boot-time allocator with all RAM situated after modules. */
kaf24@5003 341 xenheap_phys_start = init_boot_allocator(__pa(&_end));
kaf24@6111 342 nr_pages = 0;
kaf24@3354 343 for ( i = 0; i < e820.nr_map; i++ )
kaf24@3354 344 {
kaf24@3354 345 if ( e820.map[i].type != E820_RAM )
kaf24@3354 346 continue;
kaf24@6111 347
kaf24@3354 348 nr_pages += e820.map[i].size >> PAGE_SHIFT;
kaf24@6111 349
kaf24@6111 350 /* Initialise boot heap, skipping Xen heap and dom0 modules. */
kaf24@6111 351 s = e820.map[i].addr;
kaf24@6111 352 e = s + e820.map[i].size;
kaf24@6111 353 if ( s < xenheap_phys_end )
kaf24@6111 354 s = xenheap_phys_end;
kaf24@6111 355 if ( (s < initial_images_end) && (e > initial_images_start) )
kaf24@6111 356 s = initial_images_end;
kaf24@6111 357 init_boot_pages(s, e);
kaf24@6111 358
kaf24@5003 359 #if defined (CONFIG_X86_64)
kaf24@5003 360 /*
kaf24@5003 361 * x86/64 maps all registered RAM. Points to note:
kaf24@9783 362 * 1. The initial pagetable already maps low 1GB, so skip that.
kaf24@5003 363 * 2. We must map *only* RAM areas, taking care to avoid I/O holes.
kaf24@5003 364 * Failure to do this can cause coherency problems and deadlocks
kaf24@5003 365 * due to cache-attribute mismatches (e.g., AMD/AGP Linux bug).
kaf24@5003 366 */
kaf24@5003 367 {
kaf24@5004 368 /* Calculate page-frame range, discarding partial frames. */
kaf24@5004 369 unsigned long start, end;
kaf24@9783 370 unsigned long init_mapped = 1UL << (30 - PAGE_SHIFT); /* 1GB */
kaf24@5005 371 start = PFN_UP(e820.map[i].addr);
kaf24@5005 372 end = PFN_DOWN(e820.map[i].addr + e820.map[i].size);
kaf24@9800 373 /* Clip the range to exclude what the bootstrapper initialised. */
kaf24@9783 374 if ( end < init_mapped )
kaf24@5004 375 continue;
kaf24@9783 376 if ( start < init_mapped )
kaf24@9783 377 start = init_mapped;
kaf24@5004 378 /* Request the mapping. */
kaf24@5003 379 map_pages_to_xen(
kaf24@5004 380 PAGE_OFFSET + (start << PAGE_SHIFT),
kaf24@5004 381 start, end-start, PAGE_HYPERVISOR);
kaf24@5003 382 }
kaf24@5003 383 #endif
kaf24@3354 384 }
kaf24@3354 385
kaf24@5003 386 memguard_init();
kaf24@4950 387
kaf24@3354 388 printk("System RAM: %luMB (%lukB)\n",
kaf24@3354 389 nr_pages >> (20 - PAGE_SHIFT),
kaf24@3354 390 nr_pages << (PAGE_SHIFT - 10));
kaf24@7220 391 total_pages = nr_pages;
kaf24@3354 392
kaf24@8679 393 /* Sanity check for unwanted bloat of dom0_op structure. */
kaf24@9878 394 BUILD_BUG_ON(sizeof(((struct dom0_op *)0)->u) !=
kaf24@9878 395 sizeof(((struct dom0_op *)0)->u.pad));
kaf24@7388 396
kaf24@9878 397 BUILD_BUG_ON(sizeof(start_info_t) > PAGE_SIZE);
kaf24@9878 398 BUILD_BUG_ON(sizeof(shared_info_t) > PAGE_SIZE);
kaf24@9878 399 BUILD_BUG_ON(sizeof(vcpu_info_t) != 64);
kaf24@7744 400
kaf24@8521 401 /* __foo are defined in public headers. Check they match internal defs. */
kaf24@9878 402 BUILD_BUG_ON(__HYPERVISOR_VIRT_START != HYPERVISOR_VIRT_START);
kaf24@8521 403 #ifdef HYPERVISOR_VIRT_END
kaf24@9878 404 BUILD_BUG_ON(__HYPERVISOR_VIRT_END != HYPERVISOR_VIRT_END);
kaf24@8521 405 #endif
kaf24@8521 406
kaf24@3354 407 init_frametable();
kaf24@3338 408
kaf24@3354 409 end_boot_allocator();
kaf24@3354 410
kaf24@6111 411 /* Initialise the Xen heap, skipping RAM holes. */
kaf24@6111 412 nr_pages = 0;
kaf24@6111 413 for ( i = 0; i < e820.nr_map; i++ )
kaf24@6111 414 {
kaf24@6111 415 if ( e820.map[i].type != E820_RAM )
kaf24@6111 416 continue;
kaf24@6111 417
kaf24@6111 418 s = e820.map[i].addr;
kaf24@6111 419 e = s + e820.map[i].size;
kaf24@6111 420 if ( s < xenheap_phys_start )
kaf24@6111 421 s = xenheap_phys_start;
kaf24@6111 422 if ( e > xenheap_phys_end )
kaf24@6111 423 e = xenheap_phys_end;
kaf24@6111 424
kaf24@6111 425 if ( s < e )
kaf24@6111 426 {
kaf24@6111 427 nr_pages += (e - s) >> PAGE_SHIFT;
kaf24@6111 428 init_xenheap_pages(s, e);
kaf24@6111 429 }
kaf24@6111 430 }
kaf24@6111 431
kaf24@6111 432 printk("Xen heap: %luMB (%lukB)\n",
kaf24@6111 433 nr_pages >> (20 - PAGE_SHIFT),
kaf24@6111 434 nr_pages << (PAGE_SHIFT - 10));
kaf24@3338 435
kaf24@3594 436 early_boot = 0;
kaf24@3338 437
kaf24@8459 438 early_cpu_init();
kaf24@8459 439
kaf24@8533 440 scheduler_init();
kaf24@8533 441
kaf24@8611 442 idle_domain = domain_create(IDLE_DOMAIN_ID, 0);
kaf24@8533 443 BUG_ON(idle_domain == NULL);
kaf24@8533 444
kaf24@8533 445 set_current(idle_domain->vcpu[0]);
kaf24@9818 446 this_cpu(curr_vcpu) = idle_domain->vcpu[0];
kaf24@8533 447 idle_vcpu[0] = current;
kaf24@8533 448
kaf24@8459 449 paging_init();
kaf24@8459 450
kaf24@8459 451 /* Unmap the first page of CPU0's stack. */
kaf24@8459 452 memguard_guard_stack(cpu0_stack);
kaf24@8459 453
kaf24@8459 454 open_softirq(NEW_TLBFLUSH_CLOCK_PERIOD_SOFTIRQ, new_tlbflush_clock_period);
kaf24@8459 455
kaf24@8459 456 if ( opt_watchdog )
kaf24@8459 457 nmi_watchdog = NMI_LOCAL_APIC;
kaf24@8459 458
kaf24@8459 459 sort_exception_tables();
kaf24@8459 460
kaf24@8459 461 find_smp_config();
kaf24@8459 462
kaf24@8459 463 smp_alloc_memory();
kaf24@8459 464
kaf24@8459 465 dmi_scan_machine();
kaf24@8459 466
kaf24@8459 467 generic_apic_probe();
kaf24@8459 468
kaf24@8459 469 acpi_boot_table_init();
kaf24@8459 470 acpi_boot_init();
kaf24@8459 471
kaf24@8459 472 if ( smp_found_config )
kaf24@8459 473 get_smp_config();
kaf24@8459 474
kaf24@8459 475 init_apic_mappings();
kaf24@8459 476
kaf24@8459 477 init_IRQ();
kaf24@8459 478
kaf24@8459 479 trap_init();
kaf24@8459 480
kaf24@8586 481 timer_init();
kaf24@8459 482
kaf24@8459 483 early_time_init();
kaf24@8459 484
kaf24@8459 485 arch_init_memory();
kaf24@8459 486
kaf24@8459 487 identify_cpu(&boot_cpu_data);
kaf24@8459 488 if ( cpu_has_fxsr )
kaf24@8459 489 set_in_cr4(X86_CR4_OSFXSR);
kaf24@8459 490 if ( cpu_has_xmm )
kaf24@8459 491 set_in_cr4(X86_CR4_OSXMMEXCPT);
kaf24@8459 492
kaf24@8459 493 if ( opt_nosmp )
kaf24@8459 494 max_cpus = 0;
kaf24@8459 495
kaf24@8459 496 smp_prepare_cpus(max_cpus);
kaf24@8459 497
kaf24@8459 498 /*
kaf24@8459 499 * Initialise higher-level timer functions. We do this fairly late
kaf24@8459 500 * (post-SMP) because the time bases and scale factors need to be updated
kaf24@8459 501 * regularly, and SMP initialisation can cause a long delay with
kaf24@8459 502 * interrupts not yet enabled.
kaf24@8459 503 */
kaf24@8459 504 init_xen_time();
kaf24@8459 505
kaf24@8459 506 initialize_keytable();
kaf24@8459 507
kaf24@8459 508 serial_init_postirq();
kaf24@8459 509
kaf24@8459 510 BUG_ON(!local_irq_is_enabled());
kaf24@8459 511
kaf24@8459 512 for_each_present_cpu ( i )
kaf24@8459 513 {
kaf24@8459 514 if ( num_online_cpus() >= max_cpus )
kaf24@8459 515 break;
kaf24@8459 516 if ( !cpu_online(i) )
kaf24@8459 517 __cpu_up(i);
kaf24@8459 518 }
kaf24@8459 519
kaf24@8459 520 printk("Brought up %ld CPUs\n", (long)num_online_cpus());
kaf24@8459 521 smp_cpus_done(max_cpus);
kaf24@8459 522
kaf24@9818 523 percpu_free_unused_areas();
kaf24@9818 524
kaf24@9117 525 initialise_gdb(); /* could be moved earlier */
kaf24@9117 526
kaf24@8459 527 do_initcalls();
kaf24@8459 528
kaf24@8459 529 schedulers_start();
kaf24@8459 530
kaf24@8594 531 if ( opt_watchdog )
kaf24@8594 532 watchdog_enable();
kaf24@8459 533
kaf24@8459 534 shadow_mode_init();
kaf24@8459 535
kaf24@8459 536 /* initialize access control security module */
kaf24@8459 537 acm_init(&initrdidx, mbi, initial_images_start);
kaf24@8459 538
kaf24@8459 539 /* Create initial domain 0. */
kaf24@8611 540 dom0 = domain_create(0, 0);
kaf24@8459 541 if ( dom0 == NULL )
kaf24@8459 542 panic("Error creating domain 0\n");
kaf24@8459 543
kaf24@8459 544 set_bit(_DOMF_privileged, &dom0->domain_flags);
kaf24@8459 545 /* post-create hooks sets security label */
kaf24@8459 546 acm_post_domain0_create(dom0->domain_id);
kaf24@8459 547
kaf24@8459 548 /* Grab the DOM0 command line. */
kaf24@8459 549 cmdline = (char *)(mod[0].string ? __va(mod[0].string) : NULL);
kaf24@8459 550 if ( cmdline != NULL )
kaf24@8459 551 {
kaf24@8459 552 static char dom0_cmdline[MAX_GUEST_CMDLINE];
kaf24@8459 553
kaf24@8459 554 /* Skip past the image name and copy to a local buffer. */
kaf24@8459 555 while ( *cmdline == ' ' ) cmdline++;
kaf24@8459 556 if ( (cmdline = strchr(cmdline, ' ')) != NULL )
kaf24@8459 557 {
kaf24@8459 558 while ( *cmdline == ' ' ) cmdline++;
kaf24@8459 559 strcpy(dom0_cmdline, cmdline);
kaf24@8459 560 }
kaf24@8459 561
kaf24@8459 562 cmdline = dom0_cmdline;
kaf24@8459 563
kaf24@8459 564 /* Append any extra parameters. */
kaf24@8459 565 if ( skip_ioapic_setup && !strstr(cmdline, "noapic") )
kaf24@8459 566 strcat(cmdline, " noapic");
kaf24@8459 567 if ( acpi_skip_timer_override &&
kaf24@8459 568 !strstr(cmdline, "acpi_skip_timer_override") )
kaf24@8459 569 strcat(cmdline, " acpi_skip_timer_override");
kaf24@8459 570 if ( (strlen(acpi_param) != 0) && !strstr(cmdline, "acpi=") )
kaf24@8459 571 {
kaf24@8459 572 strcat(cmdline, " acpi=");
kaf24@8459 573 strcat(cmdline, acpi_param);
kaf24@8459 574 }
kaf24@8459 575 }
kaf24@8459 576
kaf24@8459 577 if ( (initrdidx > 0) && (initrdidx < mbi->mods_count) )
kaf24@8459 578 {
kaf24@8459 579 _initrd_start = initial_images_start +
kaf24@8459 580 (mod[initrdidx].mod_start - mod[0].mod_start);
kaf24@8459 581 _initrd_len = mod[initrdidx].mod_end - mod[initrdidx].mod_start;
kaf24@8459 582 }
kaf24@8459 583
kaf24@8459 584 /*
kaf24@8459 585 * We're going to setup domain0 using the module(s) that we stashed safely
kaf24@8459 586 * above our heap. The second module, if present, is an initrd ramdisk.
kaf24@8459 587 */
kaf24@8459 588 if ( construct_dom0(dom0,
kaf24@8459 589 initial_images_start,
kaf24@8459 590 mod[0].mod_end-mod[0].mod_start,
kaf24@8459 591 _initrd_start,
kaf24@8459 592 _initrd_len,
kaf24@8459 593 cmdline) != 0)
kaf24@8459 594 panic("Could not set up DOM0 guest OS\n");
kaf24@8459 595
kaf24@8459 596 /* Scrub RAM that is still free and so may go to an unprivileged domain. */
kaf24@8459 597 scrub_heap_pages();
kaf24@8459 598
kaf24@8459 599 init_trace_bufs();
kaf24@8459 600
kaf24@8459 601 /* Give up the VGA console if DOM0 is configured to grab it. */
kaf24@8459 602 console_endboot(cmdline && strstr(cmdline, "tty0"));
kaf24@8459 603
kaf24@8459 604 /* Hide UART from DOM0 if we're using it */
kaf24@8459 605 serial_endboot();
kaf24@8459 606
kaf24@8459 607 domain_unpause_by_systemcontroller(dom0);
kaf24@8459 608
kaf24@8459 609 startup_cpu_idle_loop();
kaf24@8459 610 }
kaf24@8459 611
kaf24@6725 612 void arch_get_xen_caps(xen_capabilities_info_t info)
iap10@6721 613 {
kaf24@6725 614 char *p = info;
iap10@6721 615
kaf24@6725 616 #if defined(CONFIG_X86_32) && !defined(CONFIG_X86_PAE)
kaf24@6725 617
smh22@7709 618 p += sprintf(p, "xen-%d.%d-x86_32 ", XEN_VERSION, XEN_SUBVERSION);
kaf24@6725 619 if ( hvm_enabled )
smh22@7709 620 p += sprintf(p, "hvm-%d.%d-x86_32 ", XEN_VERSION, XEN_SUBVERSION);
kaf24@6725 621
kaf24@6725 622 #elif defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
kaf24@6725 623
smh22@7709 624 p += sprintf(p, "xen-%d.%d-x86_32p ", XEN_VERSION, XEN_SUBVERSION);
kaf24@6725 625 if ( hvm_enabled )
iap10@6721 626 {
kaf24@8770 627 p += sprintf(p, "hvm-%d.%d-x86_32 ", XEN_VERSION, XEN_SUBVERSION);
smh22@7709 628 //p += sprintf(p, "hvm-%d.%d-x86_32p ", XEN_VERSION, XEN_SUBVERSION);
iap10@6721 629 }
iap10@6721 630
kaf24@6725 631 #elif defined(CONFIG_X86_64)
iap10@6721 632
smh22@7709 633 p += sprintf(p, "xen-%d.%d-x86_64 ", XEN_VERSION, XEN_SUBVERSION);
kaf24@6725 634 if ( hvm_enabled )
iap10@6721 635 {
kaf24@8246 636 p += sprintf(p, "hvm-%d.%d-x86_32 ", XEN_VERSION, XEN_SUBVERSION);
kaf24@9844 637 p += sprintf(p, "hvm-%d.%d-x86_32p ", XEN_VERSION, XEN_SUBVERSION);
smh22@7709 638 p += sprintf(p, "hvm-%d.%d-x86_64 ", XEN_VERSION, XEN_SUBVERSION);
iap10@6721 639 }
kaf24@6725 640
kaf24@6725 641 #else
kaf24@6725 642
kaf24@6725 643 p++;
kaf24@6725 644
iap10@6721 645 #endif
kaf24@8246 646
kaf24@6725 647 *(p-1) = 0;
iap10@6721 648
shand@6734 649 BUG_ON((p - info) > sizeof(xen_capabilities_info_t));
iap10@6721 650 }
iap10@6721 651
kaf24@3914 652 /*
kaf24@3914 653 * Local variables:
kaf24@3914 654 * mode: C
kaf24@3914 655 * c-set-style: "BSD"
kaf24@3914 656 * c-basic-offset: 4
kaf24@3914 657 * tab-width: 4
kaf24@3914 658 * indent-tabs-mode: nil
kaf24@3988 659 * End:
kaf24@3914 660 */