ia64/xen-unstable

annotate xen/arch/x86/setup.c @ 11881:8190a4a7ea4d

[ACM] Makes acm_setup arch-independant.
Move module extraction code to x86/setup.c

Be sure the dump binary file is aligned.

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