ia64/xen-unstable

annotate xen/arch/x86/setup.c @ 5146:de3abc161c24

bitkeeper revision 1.1548 (4294554btfa2GpomqV57KFpxEHsjEA)

Move to Linux's cpumask_t and 'hotplug' multi-processor booting
interfaces. This also brings apic.c and various other files closer to
their Linux 2.6 equivalents. Simplified the scheduler interfaces a
little (particularly per-cpu and idle-domain initialisation).
Signed-off-by: Keir Fraser <keir@xensource.com>
author kaf24@firebug.cl.cam.ac.uk
date Wed May 25 10:36:59 2005 +0000 (2005-05-25)
parents d1e3efb12a27
children f1ac5983d4d8
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>
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@1452 13 #include <asm/bitops.h>
kaf24@1452 14 #include <asm/smp.h>
kaf24@1452 15 #include <asm/processor.h>
kaf24@1452 16 #include <asm/mpspec.h>
kaf24@1452 17 #include <asm/apic.h>
kaf24@1452 18 #include <asm/desc.h>
kaf24@1452 19 #include <asm/domain_page.h>
kaf24@3338 20 #include <asm/shadow.h>
kaf24@3344 21 #include <asm/e820.h>
kaf24@3338 22
kaf24@3338 23 /*
kaf24@3338 24 * opt_xenheap_megabytes: Size of Xen heap in megabytes, excluding the
kaf24@3338 25 * pfn_info table and allocation bitmap.
kaf24@3338 26 */
kaf24@3338 27 static unsigned int opt_xenheap_megabytes = XENHEAP_DEFAULT_MB;
kaf24@4950 28 #if defined(CONFIG_X86_64)
kaf24@3338 29 integer_param("xenheap_megabytes", opt_xenheap_megabytes);
kaf24@3354 30 #endif
kaf24@1452 31
kaf24@3334 32 /* opt_noht: If true, Hyperthreading is ignored. */
kaf24@3334 33 int opt_noht = 0;
kaf24@3334 34 boolean_param("noht", opt_noht);
kaf24@3334 35
kaf24@5146 36 /* opt_nosmp: If true, secondary processors are ignored. */
kaf24@5146 37 static int opt_nosmp = 0;
kaf24@5146 38 boolean_param("nosmp", opt_nosmp);
kaf24@5146 39
kaf24@5146 40 /* maxcpus: maximum number of CPUs to activate. */
kaf24@5146 41 static unsigned int max_cpus = NR_CPUS;
kaf24@5146 42 integer_param("maxcpus", max_cpus);
kaf24@5146 43
kaf24@3334 44 /* opt_watchdog: If true, run a watchdog NMI on each processor. */
kaf24@3334 45 static int opt_watchdog = 0;
kaf24@3334 46 boolean_param("watchdog", opt_watchdog);
kaf24@3334 47
kaf24@4850 48 /* **** Linux config option: propagated to domain0. */
kaf24@4850 49 /* "acpi=off": Sisables both ACPI table parsing and interpreter. */
kaf24@4850 50 /* "acpi=force": Override the disable blacklist. */
kaf24@4850 51 /* "acpi=strict": Disables out-of-spec workarounds. */
kaf24@4850 52 /* "acpi=ht": Limit ACPI just to boot-time to enable HT. */
kaf24@4850 53 /* "acpi=noirq": Disables ACPI interrupt routing. */
kaf24@4850 54 static void parse_acpi_param(char *s);
kaf24@4850 55 custom_param("acpi", parse_acpi_param);
kaf24@4850 56
kaf24@4850 57 /* **** Linux config option: propagated to domain0. */
kaf24@4850 58 /* acpi_skip_timer_override: Skip IRQ0 overrides. */
kaf24@4850 59 extern int acpi_skip_timer_override;
kaf24@4850 60 boolean_param("acpi_skip_timer_override", acpi_skip_timer_override);
kaf24@4850 61
kaf24@4850 62 /* **** Linux config option: propagated to domain0. */
kaf24@4850 63 /* noapic: Disable IOAPIC setup. */
kaf24@4850 64 extern int skip_ioapic_setup;
kaf24@4850 65 boolean_param("noapic", skip_ioapic_setup);
kaf24@4850 66
kaf24@3594 67 int early_boot = 1;
kaf24@3594 68
kaf24@5146 69 int ht_per_core = 1;
kaf24@5146 70 cpumask_t cpu_present_map;
kaf24@5146 71
kaf24@5003 72 /* Limits of Xen heap, used to initialise the allocator. */
kaf24@5003 73 unsigned long xenheap_phys_start, xenheap_phys_end;
kaf24@3338 74
kaf24@2298 75 extern void arch_init_memory(void);
kaf24@1589 76 extern void init_IRQ(void);
kaf24@1589 77 extern void trap_init(void);
kaf24@1589 78 extern void time_init(void);
kaf24@1589 79 extern void ac_timer_init(void);
kaf24@1589 80 extern void initialize_keytable();
kaf24@1589 81
kaf24@5011 82 extern unsigned long cpu0_stack[];
kaf24@5011 83
kaf24@1480 84 struct cpuinfo_x86 boot_cpu_data = { 0, 0, 0, 0, -1 };
kaf24@1452 85
kaf24@4950 86 #if defined(CONFIG_X86_64)
kaf24@1670 87 unsigned long mmu_cr4_features = X86_CR4_PSE | X86_CR4_PGE | X86_CR4_PAE;
kaf24@1670 88 #else
kaf24@1452 89 unsigned long mmu_cr4_features = X86_CR4_PSE | X86_CR4_PGE;
kaf24@1670 90 #endif
kaf24@1452 91 EXPORT_SYMBOL(mmu_cr4_features);
kaf24@1452 92
cl349@2919 93 struct exec_domain *idle_task[NR_CPUS] = { &idle0_exec_domain };
kaf24@1452 94
kaf24@4818 95 int acpi_disabled;
kaf24@1452 96
kaf24@1452 97 int logical_proc_id[NR_CPUS];
kaf24@1452 98
kaf24@3623 99 /* Standard macro to see if a specific flag is changeable. */
kaf24@3623 100 static inline int flag_is_changeable_p(unsigned long flag)
kaf24@1452 101 {
kaf24@3623 102 unsigned long f1, f2;
kaf24@1452 103
kaf24@3623 104 asm("pushf\n\t"
kaf24@3623 105 "pushf\n\t"
kaf24@3623 106 "pop %0\n\t"
kaf24@3623 107 "mov %0,%1\n\t"
kaf24@3623 108 "xor %2,%0\n\t"
kaf24@3623 109 "push %0\n\t"
kaf24@3623 110 "popf\n\t"
kaf24@3623 111 "pushf\n\t"
kaf24@3623 112 "pop %0\n\t"
kaf24@3623 113 "popf\n\t"
kaf24@1452 114 : "=&r" (f1), "=&r" (f2)
kaf24@1452 115 : "ir" (flag));
kaf24@1452 116
kaf24@1452 117 return ((f1^f2) & flag) != 0;
kaf24@1452 118 }
kaf24@1452 119
kaf24@1452 120 /* Probe for the CPUID instruction */
kaf24@1452 121 static int __init have_cpuid_p(void)
kaf24@1452 122 {
kaf24@1452 123 return flag_is_changeable_p(X86_EFLAGS_ID);
kaf24@1452 124 }
kaf24@1452 125
kaf24@1452 126 void __init get_cpu_vendor(struct cpuinfo_x86 *c)
kaf24@1452 127 {
kaf24@1452 128 char *v = c->x86_vendor_id;
kaf24@1452 129
kaf24@1452 130 if (!strcmp(v, "GenuineIntel"))
kaf24@1452 131 c->x86_vendor = X86_VENDOR_INTEL;
kaf24@1452 132 else if (!strcmp(v, "AuthenticAMD"))
kaf24@1452 133 c->x86_vendor = X86_VENDOR_AMD;
kaf24@1452 134 else if (!strcmp(v, "CyrixInstead"))
kaf24@1452 135 c->x86_vendor = X86_VENDOR_CYRIX;
kaf24@1452 136 else if (!strcmp(v, "UMC UMC UMC "))
kaf24@1452 137 c->x86_vendor = X86_VENDOR_UMC;
kaf24@1452 138 else if (!strcmp(v, "CentaurHauls"))
kaf24@1452 139 c->x86_vendor = X86_VENDOR_CENTAUR;
kaf24@1452 140 else if (!strcmp(v, "NexGenDriven"))
kaf24@1452 141 c->x86_vendor = X86_VENDOR_NEXGEN;
kaf24@1452 142 else if (!strcmp(v, "RiseRiseRise"))
kaf24@1452 143 c->x86_vendor = X86_VENDOR_RISE;
kaf24@1452 144 else if (!strcmp(v, "GenuineTMx86") ||
kaf24@1452 145 !strcmp(v, "TransmetaCPU"))
kaf24@1452 146 c->x86_vendor = X86_VENDOR_TRANSMETA;
kaf24@1452 147 else
kaf24@1452 148 c->x86_vendor = X86_VENDOR_UNKNOWN;
kaf24@1452 149 }
kaf24@1452 150
kaf24@1452 151 static void __init init_intel(struct cpuinfo_x86 *c)
kaf24@1452 152 {
kaf24@1452 153 /* SEP CPUID bug: Pentium Pro reports SEP but doesn't have it */
kaf24@1452 154 if ( c->x86 == 6 && c->x86_model < 3 && c->x86_mask < 3 )
kaf24@1452 155 clear_bit(X86_FEATURE_SEP, &c->x86_capability);
kaf24@1452 156
kaf24@1452 157 if ( test_bit(X86_FEATURE_HT, &c->x86_capability) )
kaf24@1452 158 {
kaf24@1452 159 u32 eax, ebx, ecx, edx;
kaf24@1452 160 int initial_apic_id, siblings, cpu = smp_processor_id();
kaf24@5146 161
kaf24@1452 162 cpuid(1, &eax, &ebx, &ecx, &edx);
cl349@2703 163 ht_per_core = siblings = (ebx & 0xff0000) >> 16;
cl349@2703 164
cl349@2703 165 if ( opt_noht )
cl349@2703 166 clear_bit(X86_FEATURE_HT, &c->x86_capability[0]);
cl349@2703 167
kaf24@1452 168 if ( siblings <= 1 )
kaf24@1452 169 {
kaf24@1452 170 printk(KERN_INFO "CPU#%d: Hyper-Threading is disabled\n", cpu);
kaf24@1452 171 }
kaf24@1452 172 else if ( siblings > 2 )
kaf24@1452 173 {
kaf24@1452 174 panic("We don't support more than two logical CPUs per package!");
kaf24@1452 175 }
kaf24@1452 176 else
kaf24@1452 177 {
kaf24@1452 178 initial_apic_id = ebx >> 24 & 0xff;
kaf24@1452 179 phys_proc_id[cpu] = initial_apic_id >> 1;
kaf24@1452 180 logical_proc_id[cpu] = initial_apic_id & 1;
kaf24@1452 181 printk(KERN_INFO "CPU#%d: Physical ID: %d, Logical ID: %d\n",
kaf24@1452 182 cpu, phys_proc_id[cpu], logical_proc_id[cpu]);
kaf24@1452 183 }
kaf24@1452 184 }
iap10@3290 185
iap10@3290 186 #ifdef CONFIG_VMX
iap10@3290 187 start_vmx();
iap10@3290 188 #endif
iap10@3290 189
kaf24@1452 190 }
kaf24@1452 191
kaf24@1452 192 static void __init init_amd(struct cpuinfo_x86 *c)
kaf24@1452 193 {
kaf24@1452 194 /* Bit 31 in normal CPUID used for nonstandard 3DNow ID;
kaf24@1452 195 3DNow is IDd by bit 31 in extended CPUID (1*32+31) anyway */
kaf24@1452 196 clear_bit(0*32+31, &c->x86_capability);
kaf24@1452 197
kaf24@1452 198 switch(c->x86)
kaf24@1452 199 {
kaf24@1452 200 case 5:
kaf24@1452 201 panic("AMD K6 is not supported.\n");
kaf24@1452 202 case 6: /* An Athlon/Duron. We can trust the BIOS probably */
kaf24@1452 203 break;
kaf24@1452 204 }
kaf24@1452 205 }
kaf24@1452 206
kaf24@1452 207 /*
kaf24@1452 208 * This does the hard work of actually picking apart the CPU stuff...
kaf24@1452 209 */
kaf24@1452 210 void __init identify_cpu(struct cpuinfo_x86 *c)
kaf24@1452 211 {
riel@3992 212 int i, cpu = smp_processor_id();
riel@3992 213 u32 xlvl, tfms, junk;
kaf24@1452 214
kaf24@1452 215 phys_proc_id[cpu] = cpu;
kaf24@1452 216 logical_proc_id[cpu] = 0;
kaf24@1452 217
kaf24@1452 218 c->x86_vendor = X86_VENDOR_UNKNOWN;
kaf24@1452 219 c->cpuid_level = -1; /* CPUID not detected */
kaf24@1452 220 c->x86_model = c->x86_mask = 0; /* So far unknown... */
kaf24@1452 221 c->x86_vendor_id[0] = '\0'; /* Unset */
kaf24@1452 222 memset(&c->x86_capability, 0, sizeof c->x86_capability);
kaf24@1452 223
kaf24@1452 224 if ( !have_cpuid_p() )
kaf24@1452 225 panic("Ancient processors not supported\n");
kaf24@1452 226
kaf24@1452 227 /* Get vendor name */
riel@3992 228 cpuid(0x00000000, (unsigned int *)&c->cpuid_level,
riel@3992 229 (unsigned int *)&c->x86_vendor_id[0],
riel@3992 230 (unsigned int *)&c->x86_vendor_id[8],
riel@3992 231 (unsigned int *)&c->x86_vendor_id[4]);
kaf24@1452 232
kaf24@1452 233 get_cpu_vendor(c);
kaf24@1452 234
kaf24@1452 235 if ( c->cpuid_level == 0 )
kaf24@1452 236 panic("Decrepit CPUID not supported\n");
kaf24@1452 237
kaf24@1452 238 cpuid(0x00000001, &tfms, &junk, &junk,
kaf24@1452 239 &c->x86_capability[0]);
kaf24@1452 240 c->x86 = (tfms >> 8) & 15;
kaf24@1452 241 c->x86_model = (tfms >> 4) & 15;
kaf24@1452 242 c->x86_mask = tfms & 15;
kaf24@1452 243
kaf24@1452 244 /* AMD-defined flags: level 0x80000001 */
kaf24@1452 245 xlvl = cpuid_eax(0x80000000);
kaf24@1452 246 if ( (xlvl & 0xffff0000) == 0x80000000 ) {
kaf24@1452 247 if ( xlvl >= 0x80000001 )
kaf24@1452 248 c->x86_capability[1] = cpuid_edx(0x80000001);
kaf24@1452 249 }
kaf24@1452 250
kaf24@1452 251 /* Transmeta-defined flags: level 0x80860001 */
kaf24@1452 252 xlvl = cpuid_eax(0x80860000);
kaf24@1452 253 if ( (xlvl & 0xffff0000) == 0x80860000 ) {
kaf24@1452 254 if ( xlvl >= 0x80860001 )
kaf24@1452 255 c->x86_capability[2] = cpuid_edx(0x80860001);
kaf24@1452 256 }
kaf24@1452 257
kaf24@1452 258 printk("CPU%d: Before vendor init, caps: %08x %08x %08x, vendor = %d\n",
kaf24@1452 259 smp_processor_id(),
kaf24@1452 260 c->x86_capability[0],
kaf24@1452 261 c->x86_capability[1],
kaf24@1452 262 c->x86_capability[2],
kaf24@1452 263 c->x86_vendor);
kaf24@1452 264
kaf24@1452 265 switch ( c->x86_vendor ) {
kaf24@1452 266 case X86_VENDOR_INTEL:
kaf24@1452 267 init_intel(c);
kaf24@1452 268 break;
kaf24@1452 269 case X86_VENDOR_AMD:
kaf24@1452 270 init_amd(c);
kaf24@1452 271 break;
kaf24@1452 272 case X86_VENDOR_UNKNOWN: /* Connectix Virtual PC reports this */
kaf24@1452 273 break;
kaf24@1452 274 case X86_VENDOR_CENTAUR:
kaf24@1452 275 break;
kaf24@1452 276 default:
kaf24@1452 277 printk("Unknown CPU identifier (%d): continuing anyway, "
kaf24@1452 278 "but might fail.\n", c->x86_vendor);
kaf24@1452 279 }
kaf24@1452 280
kaf24@1452 281 printk("CPU caps: %08x %08x %08x %08x\n",
kaf24@1452 282 c->x86_capability[0],
kaf24@1452 283 c->x86_capability[1],
kaf24@1452 284 c->x86_capability[2],
kaf24@1452 285 c->x86_capability[3]);
kaf24@1452 286
kaf24@1452 287 /*
kaf24@1452 288 * On SMP, boot_cpu_data holds the common feature set between
kaf24@1452 289 * all CPUs; so make sure that we indicate which features are
kaf24@1452 290 * common between the CPUs. The first time this routine gets
kaf24@1452 291 * executed, c == &boot_cpu_data.
kaf24@1452 292 */
kaf24@1452 293 if ( c != &boot_cpu_data ) {
kaf24@1452 294 /* AND the already accumulated flags with these */
kaf24@1452 295 for ( i = 0 ; i < NCAPINTS ; i++ )
kaf24@1452 296 boot_cpu_data.x86_capability[i] &= c->x86_capability[i];
kaf24@1452 297 }
kaf24@1452 298 }
kaf24@1452 299
kaf24@5146 300 void __init print_cpu_info(struct cpuinfo_x86 *c)
kaf24@5146 301 {
kaf24@5146 302 printk("booted.\n");
kaf24@5146 303 }
kaf24@1452 304
kaf24@1452 305 unsigned long cpu_initialized;
kaf24@1452 306 void __init cpu_init(void)
kaf24@1452 307 {
kaf24@1452 308 int nr = smp_processor_id();
kaf24@3623 309 struct tss_struct *t = &init_tss[nr];
kaf24@4972 310 char gdt_load[10];
kaf24@1452 311
kaf24@1452 312 if ( test_and_set_bit(nr, &cpu_initialized) )
kaf24@1452 313 panic("CPU#%d already initialized!!!\n", nr);
kaf24@1452 314 printk("Initializing CPU#%d\n", nr);
kaf24@1452 315
kaf24@4972 316 *(unsigned short *)(&gdt_load[0]) = LAST_RESERVED_GDT_BYTE;
kaf24@4972 317 *(unsigned long *)(&gdt_load[2]) = GDT_VIRT_START(current);
kaf24@4972 318 __asm__ __volatile__ ( "lgdt %0" : "=m" (gdt_load) );
kaf24@1452 319
kaf24@1452 320 /* No nested task. */
kaf24@3623 321 __asm__ __volatile__ ( "pushf ; andw $0xbfff,(%"__OP"sp) ; popf" );
kaf24@1452 322
kaf24@1452 323 /* Ensure FPU gets initialised for each domain. */
kaf24@1452 324 stts();
kaf24@1452 325
kaf24@1452 326 /* Set up and load the per-CPU TSS and LDT. */
kaf24@3623 327 t->bitmap = IOBMP_INVALID_OFFSET;
kaf24@4950 328 #if defined(CONFIG_X86_32)
kaf24@1452 329 t->ss0 = __HYPERVISOR_DS;
kaf24@3761 330 t->esp0 = get_stack_bottom();
kaf24@4950 331 #elif defined(CONFIG_X86_64)
kaf24@4986 332 /* Bottom-of-stack must be 16-byte aligned or CPU will force it! :-o */
kaf24@4986 333 BUG_ON((get_stack_bottom() & 15) != 0);
kaf24@3761 334 t->rsp0 = get_stack_bottom();
kaf24@3623 335 #endif
kaf24@1452 336 set_tss_desc(nr,t);
kaf24@1452 337 load_TR(nr);
kaf24@3623 338 __asm__ __volatile__ ( "lldt %%ax" : : "a" (0) );
kaf24@1452 339
kaf24@1452 340 /* Clear all 6 debug registers. */
kaf24@3623 341 #define CD(register) __asm__ ( "mov %0,%%db" #register : : "r" (0UL) );
kaf24@1452 342 CD(0); CD(1); CD(2); CD(3); /* no db4 and db5 */; CD(6); CD(7);
kaf24@1452 343 #undef CD
kaf24@1452 344
kaf24@1452 345 /* Install correct page table. */
kaf24@3677 346 write_ptbase(current);
kaf24@1452 347 }
kaf24@1452 348
kaf24@4850 349 int acpi_force;
kaf24@4850 350 char acpi_param[10] = "";
kaf24@4850 351 static void parse_acpi_param(char *s)
kaf24@4850 352 {
kaf24@4850 353 /* Save the parameter so it can be propagated to domain0. */
kaf24@4850 354 strncpy(acpi_param, s, sizeof(acpi_param));
kaf24@4850 355 acpi_param[sizeof(acpi_param)-1] = '\0';
kaf24@4850 356
kaf24@4850 357 /* Interpret the parameter for use within Xen. */
kaf24@4850 358 if ( !strcmp(s, "off") )
kaf24@4850 359 {
kaf24@4850 360 disable_acpi();
kaf24@4850 361 }
kaf24@4850 362 else if ( !strcmp(s, "force") )
kaf24@4850 363 {
kaf24@4850 364 acpi_force = 1;
kaf24@4850 365 acpi_ht = 1;
kaf24@4850 366 acpi_disabled = 0;
kaf24@4850 367 }
kaf24@4850 368 else if ( !strcmp(s, "strict") )
kaf24@4850 369 {
kaf24@4850 370 acpi_strict = 1;
kaf24@4850 371 }
kaf24@4850 372 else if ( !strcmp(s, "ht") )
kaf24@4850 373 {
kaf24@4850 374 if ( !acpi_force )
kaf24@4850 375 disable_acpi();
kaf24@4850 376 acpi_ht = 1;
kaf24@4850 377 }
kaf24@4850 378 else if ( !strcmp(s, "noirq") )
kaf24@4850 379 {
kaf24@4850 380 acpi_noirq_set();
kaf24@4850 381 }
kaf24@4850 382 }
kaf24@4850 383
kaf24@1452 384 static void __init do_initcalls(void)
kaf24@1452 385 {
kaf24@1452 386 initcall_t *call;
kaf24@1452 387 for ( call = &__initcall_start; call < &__initcall_end; call++ )
kaf24@1452 388 (*call)();
kaf24@1452 389 }
kaf24@1452 390
kaf24@3338 391 static void __init start_of_day(void)
kaf24@1452 392 {
kaf24@5146 393 int i;
kaf24@5146 394
kaf24@1452 395 /* Unmap the first page of CPU0's stack. */
kaf24@3686 396 memguard_guard_stack(cpu0_stack);
kaf24@1452 397
kaf24@1505 398 open_softirq(NEW_TLBFLUSH_CLOCK_PERIOD_SOFTIRQ, new_tlbflush_clock_period);
kaf24@1452 399
kaf24@1452 400 if ( opt_watchdog )
kaf24@1452 401 nmi_watchdog = NMI_LOCAL_APIC;
kaf24@1452 402
kaf24@3120 403 sort_exception_tables();
kaf24@3120 404
kaf24@3272 405 arch_do_createdomain(current);
kaf24@4972 406
kaf24@4972 407 /* Map default GDT into their final position in the idle page table. */
kaf24@5003 408 map_pages_to_xen(
kaf24@4972 409 GDT_VIRT_START(current) + FIRST_RESERVED_GDT_BYTE,
kaf24@5004 410 virt_to_phys(gdt_table) >> PAGE_SHIFT, 1, PAGE_HYPERVISOR);
kaf24@3272 411
kaf24@4972 412 /* Process CPU type information. */
kaf24@4972 413 identify_cpu(&boot_cpu_data);
kaf24@4972 414 if ( cpu_has_fxsr )
kaf24@4972 415 set_in_cr4(X86_CR4_OSFXSR);
kaf24@4972 416 if ( cpu_has_xmm )
kaf24@4972 417 set_in_cr4(X86_CR4_OSXMMEXCPT);
kaf24@4850 418
kaf24@4850 419 find_smp_config();
kaf24@4850 420
kaf24@4850 421 smp_alloc_memory();
kaf24@4850 422
kaf24@4850 423 paging_init();
kaf24@4850 424
kaf24@4850 425 acpi_boot_table_init();
kaf24@4850 426 acpi_boot_init();
kaf24@4850 427
kaf24@1452 428 if ( smp_found_config )
kaf24@1452 429 get_smp_config();
kaf24@4850 430
kaf24@4850 431 init_apic_mappings();
kaf24@4850 432
kaf24@4850 433 init_IRQ();
kaf24@4850 434
kaf24@1452 435 trap_init();
kaf24@4850 436
kaf24@4850 437 time_init();
kaf24@1452 438
kaf24@2298 439 arch_init_memory();
kaf24@2298 440
kaf24@5146 441 scheduler_init();
kaf24@1452 442
kaf24@5146 443 if ( opt_nosmp )
kaf24@5146 444 max_cpus = 0;
kaf24@5146 445 smp_prepare_cpus(max_cpus);
kaf24@5146 446
kaf24@5146 447 /* We aren't hotplug-capable yet. */
kaf24@5146 448 BUG_ON(!cpus_empty(cpu_present_map));
kaf24@5146 449 for_each_cpu ( i )
kaf24@5146 450 cpu_set(i, cpu_present_map);
kaf24@1452 451
kaf24@4850 452 initialize_keytable();
kaf24@1452 453
kaf24@1452 454 serial_init_stage2();
kaf24@1452 455
kaf24@5146 456 ac_timer_init();
kaf24@5146 457
kaf24@5146 458 init_xen_time();
kaf24@5146 459
kaf24@5146 460 for_each_present_cpu ( i )
kaf24@1452 461 {
kaf24@5146 462 if ( num_online_cpus() >= max_cpus )
kaf24@5146 463 break;
kaf24@5146 464 if ( !cpu_online(i) )
kaf24@5146 465 __cpu_up(i);
kaf24@1452 466 }
kaf24@1452 467
kaf24@5146 468 printk("Brought up %ld CPUs\n", (long)num_online_cpus());
kaf24@5146 469 smp_cpus_done(max_cpus);
kaf24@1452 470
kaf24@1452 471 do_initcalls();
kaf24@1452 472
kaf24@5146 473 schedulers_start();
kaf24@1452 474
kaf24@4926 475 watchdog_enable();
kaf24@1452 476 }
kaf24@3338 477
kaf24@5011 478 #define EARLY_FAIL() for ( ; ; ) __asm__ __volatile__ ( "hlt" )
kaf24@5011 479
kaf24@3338 480 void __init __start_xen(multiboot_info_t *mbi)
kaf24@3338 481 {
riel@3992 482 char *cmdline;
kaf24@3338 483 module_t *mod = (module_t *)__va(mbi->mods_addr);
kaf24@3354 484 unsigned long firsthole_start, nr_pages;
kaf24@3338 485 unsigned long initial_images_start, initial_images_end;
kaf24@3344 486 struct e820entry e820_raw[E820MAX];
kaf24@3354 487 int i, e820_raw_nr = 0, bytes = 0;
kaf24@3338 488
kaf24@3338 489 /* Parse the command-line options. */
kaf24@3344 490 if ( (mbi->flags & MBI_CMDLINE) && (mbi->cmdline != 0) )
kaf24@3344 491 cmdline_parse(__va(mbi->cmdline));
kaf24@3338 492
kaf24@3338 493 /* Must do this early -- e.g., spinlocks rely on get_current(). */
kaf24@3340 494 set_current(&idle0_exec_domain);
kaf24@4986 495 set_processor_id(0);
kaf24@3338 496
kaf24@5146 497 smp_prepare_boot_cpu();
kaf24@5146 498
kaf24@3338 499 /* We initialise the serial devices very early so we can get debugging. */
kaf24@3338 500 serial_init_stage1();
kaf24@3338 501
kaf24@3338 502 init_console();
kaf24@3338 503
kaf24@3344 504 /* Check that we have at least one Multiboot module. */
kaf24@3344 505 if ( !(mbi->flags & MBI_MODULES) || (mbi->mods_count == 0) )
kaf24@3338 506 {
kaf24@3344 507 printk("FATAL ERROR: Require at least one Multiboot module.\n");
kaf24@5011 508 EARLY_FAIL();
kaf24@5011 509 }
kaf24@5011 510
kaf24@5011 511 if ( ((unsigned long)cpu0_stack & (STACK_SIZE-1)) != 0 )
kaf24@5011 512 {
kaf24@5011 513 printk("FATAL ERROR: Misaligned CPU0 stack.\n");
kaf24@5011 514 EARLY_FAIL();
kaf24@3338 515 }
kaf24@3338 516
kaf24@3338 517 xenheap_phys_end = opt_xenheap_megabytes << 20;
kaf24@3338 518
kaf24@3344 519 if ( mbi->flags & MBI_MEMMAP )
kaf24@3344 520 {
kaf24@3344 521 while ( bytes < mbi->mmap_length )
kaf24@3344 522 {
kaf24@3344 523 memory_map_t *map = __va(mbi->mmap_addr + bytes);
kaf24@3344 524 e820_raw[e820_raw_nr].addr =
kaf24@3344 525 ((u64)map->base_addr_high << 32) | (u64)map->base_addr_low;
kaf24@3344 526 e820_raw[e820_raw_nr].size =
kaf24@3344 527 ((u64)map->length_high << 32) | (u64)map->length_low;
kaf24@3344 528 e820_raw[e820_raw_nr].type =
kaf24@3346 529 (map->type > E820_SHARED_PAGE) ? E820_RESERVED : map->type;
kaf24@3344 530 e820_raw_nr++;
kaf24@3344 531 bytes += map->size + 4;
kaf24@3344 532 }
kaf24@3344 533 }
kaf24@3344 534 else if ( mbi->flags & MBI_MEMLIMITS )
kaf24@3344 535 {
kaf24@3344 536 e820_raw[0].addr = 0;
kaf24@3344 537 e820_raw[0].size = mbi->mem_lower << 10;
kaf24@3344 538 e820_raw[0].type = E820_RAM;
kaf24@3354 539 e820_raw[1].addr = 0x100000;
kaf24@3354 540 e820_raw[1].size = mbi->mem_upper << 10;
kaf24@3354 541 e820_raw[1].type = E820_RAM;
kaf24@3344 542 e820_raw_nr = 2;
kaf24@3344 543 }
kaf24@3344 544 else
kaf24@3344 545 {
kaf24@3344 546 printk("FATAL ERROR: Bootloader provided no memory information.\n");
kaf24@3344 547 for ( ; ; ) ;
kaf24@3344 548 }
kaf24@3344 549
kaf24@4950 550 max_page = init_e820(e820_raw, &e820_raw_nr);
kaf24@3338 551
kaf24@3354 552 /* Find the first high-memory RAM hole. */
kaf24@3354 553 for ( i = 0; i < e820.nr_map; i++ )
kaf24@3354 554 if ( (e820.map[i].type == E820_RAM) &&
kaf24@3354 555 (e820.map[i].addr >= 0x100000) )
kaf24@3354 556 break;
kaf24@3354 557 firsthole_start = e820.map[i].addr + e820.map[i].size;
kaf24@3338 558
kaf24@3354 559 /* Relocate the Multiboot modules. */
kaf24@3354 560 initial_images_start = xenheap_phys_end;
kaf24@3338 561 initial_images_end = initial_images_start +
kaf24@3338 562 (mod[mbi->mods_count-1].mod_end - mod[0].mod_start);
kaf24@3354 563 if ( initial_images_end > firsthole_start )
kaf24@3338 564 {
kaf24@3338 565 printk("Not enough memory to stash the DOM0 kernel image.\n");
kaf24@3338 566 for ( ; ; ) ;
kaf24@3338 567 }
kaf24@4950 568 #if defined(CONFIG_X86_32)
kaf24@3338 569 memmove((void *)initial_images_start, /* use low mapping */
kaf24@3338 570 (void *)mod[0].mod_start, /* use low mapping */
kaf24@3338 571 mod[mbi->mods_count-1].mod_end - mod[0].mod_start);
kaf24@4950 572 #elif defined(CONFIG_X86_64)
kaf24@3338 573 memmove(__va(initial_images_start),
kaf24@3338 574 __va(mod[0].mod_start),
kaf24@3338 575 mod[mbi->mods_count-1].mod_end - mod[0].mod_start);
kaf24@3338 576 #endif
kaf24@3338 577
kaf24@3354 578 /* Initialise boot-time allocator with all RAM situated after modules. */
kaf24@5003 579 xenheap_phys_start = init_boot_allocator(__pa(&_end));
kaf24@3354 580 nr_pages = 0;
kaf24@3354 581 for ( i = 0; i < e820.nr_map; i++ )
kaf24@3354 582 {
kaf24@3354 583 if ( e820.map[i].type != E820_RAM )
kaf24@3354 584 continue;
kaf24@3354 585 nr_pages += e820.map[i].size >> PAGE_SHIFT;
kaf24@3354 586 if ( (e820.map[i].addr + e820.map[i].size) >= initial_images_end )
kaf24@3354 587 init_boot_pages((e820.map[i].addr < initial_images_end) ?
kaf24@3354 588 initial_images_end : e820.map[i].addr,
kaf24@3354 589 e820.map[i].addr + e820.map[i].size);
kaf24@5003 590 #if defined (CONFIG_X86_64)
kaf24@5003 591 /*
kaf24@5003 592 * x86/64 maps all registered RAM. Points to note:
kaf24@5003 593 * 1. The initial pagetable already maps low 64MB, so skip that.
kaf24@5003 594 * 2. We must map *only* RAM areas, taking care to avoid I/O holes.
kaf24@5003 595 * Failure to do this can cause coherency problems and deadlocks
kaf24@5003 596 * due to cache-attribute mismatches (e.g., AMD/AGP Linux bug).
kaf24@5003 597 */
kaf24@5003 598 {
kaf24@5004 599 /* Calculate page-frame range, discarding partial frames. */
kaf24@5004 600 unsigned long start, end;
kaf24@5005 601 start = PFN_UP(e820.map[i].addr);
kaf24@5005 602 end = PFN_DOWN(e820.map[i].addr + e820.map[i].size);
kaf24@5004 603 /* Clip the range to above 64MB. */
kaf24@5004 604 if ( end < (64UL << (20-PAGE_SHIFT)) )
kaf24@5004 605 continue;
kaf24@5004 606 if ( start < (64UL << (20-PAGE_SHIFT)) )
kaf24@5004 607 start = 64UL << (20-PAGE_SHIFT);
kaf24@5004 608 /* Request the mapping. */
kaf24@5003 609 map_pages_to_xen(
kaf24@5004 610 PAGE_OFFSET + (start << PAGE_SHIFT),
kaf24@5004 611 start, end-start, PAGE_HYPERVISOR);
kaf24@5003 612 }
kaf24@5003 613 #endif
kaf24@3354 614 }
kaf24@3354 615
kaf24@5003 616 memguard_init();
kaf24@4950 617
kaf24@3354 618 printk("System RAM: %luMB (%lukB)\n",
kaf24@3354 619 nr_pages >> (20 - PAGE_SHIFT),
kaf24@3354 620 nr_pages << (PAGE_SHIFT - 10));
kaf24@3354 621
kaf24@3354 622 init_frametable();
kaf24@3338 623
kaf24@3354 624 end_boot_allocator();
kaf24@3354 625
kaf24@5003 626 init_xenheap_pages(xenheap_phys_start, xenheap_phys_end);
kaf24@3354 627 printk("Xen heap: %luMB (%lukB)\n",
kaf24@5003 628 (xenheap_phys_end-xenheap_phys_start) >> 20,
kaf24@5003 629 (xenheap_phys_end-xenheap_phys_start) >> 10);
kaf24@3338 630
kaf24@3594 631 early_boot = 0;
kaf24@3338 632
kaf24@3338 633 start_of_day();
kaf24@3338 634
kaf24@3338 635 grant_table_init();
kaf24@3338 636
kaf24@3338 637 shadow_mode_init();
kaf24@3338 638
kaf24@3338 639 /* Create initial domain 0. */
kaf24@3338 640 dom0 = do_createdomain(0, 0);
kaf24@3338 641 if ( dom0 == NULL )
kaf24@3338 642 panic("Error creating domain 0\n");
kaf24@3338 643
kaf24@4877 644 set_bit(_DOMF_privileged, &dom0->domain_flags);
kaf24@3338 645
kaf24@4850 646 /* Grab the DOM0 command line. */
riel@3992 647 cmdline = (char *)(mod[0].string ? __va(mod[0].string) : NULL);
kaf24@3338 648 if ( cmdline != NULL )
kaf24@3338 649 {
kaf24@4850 650 static char dom0_cmdline[256];
kaf24@4850 651
kaf24@4850 652 /* Skip past the image name. */
kaf24@3338 653 while ( *cmdline == ' ' ) cmdline++;
kaf24@3338 654 if ( (cmdline = strchr(cmdline, ' ')) != NULL )
kaf24@3338 655 while ( *cmdline == ' ' ) cmdline++;
kaf24@4850 656
kaf24@4850 657 /* Copy the command line to a local buffer. */
kaf24@4850 658 strcpy(dom0_cmdline, cmdline);
kaf24@4850 659 cmdline = dom0_cmdline;
kaf24@4850 660
kaf24@4850 661 /* Append any extra parameters. */
kaf24@4850 662 if ( skip_ioapic_setup && !strstr(cmdline, "noapic") )
kaf24@4850 663 strcat(cmdline, " noapic");
kaf24@4850 664 if ( acpi_skip_timer_override &&
kaf24@4850 665 !strstr(cmdline, "acpi_skip_timer_override") )
kaf24@4850 666 strcat(cmdline, " acpi_skip_timer_override");
kaf24@4850 667 if ( (strlen(acpi_param) != 0) && !strstr(cmdline, "acpi=") )
kaf24@4850 668 {
kaf24@4850 669 strcat(cmdline, " acpi=");
kaf24@4850 670 strcat(cmdline, acpi_param);
kaf24@4850 671 }
kaf24@4888 672 if ( !strstr(cmdline, "apic=") )
kaf24@4888 673 {
kaf24@4888 674 if ( apic_verbosity == APIC_VERBOSE )
kaf24@4888 675 strcat(cmdline, " apic=verbose");
kaf24@4888 676 else if ( apic_verbosity == APIC_DEBUG )
kaf24@4888 677 strcat(cmdline, " apic=debug");
kaf24@4888 678 }
kaf24@3338 679 }
kaf24@3338 680
kaf24@3338 681 /*
kaf24@3338 682 * We're going to setup domain0 using the module(s) that we stashed safely
kaf24@3338 683 * above our heap. The second module, if present, is an initrd ramdisk.
kaf24@3338 684 */
kaf24@3935 685 if ( construct_dom0(dom0,
kaf24@3635 686 initial_images_start,
kaf24@3338 687 mod[0].mod_end-mod[0].mod_start,
kaf24@3338 688 (mbi->mods_count == 1) ? 0 :
kaf24@3635 689 initial_images_start +
kaf24@3338 690 (mod[1].mod_start-mod[0].mod_start),
kaf24@3338 691 (mbi->mods_count == 1) ? 0 :
kaf24@3338 692 mod[mbi->mods_count-1].mod_end - mod[1].mod_start,
kaf24@3338 693 cmdline) != 0)
kaf24@3338 694 panic("Could not set up DOM0 guest OS\n");
kaf24@3338 695
kaf24@3935 696 /* Scrub RAM that is still free and so may go to an unprivileged domain. */
kaf24@3338 697 scrub_heap_pages();
kaf24@3338 698
kaf24@3338 699 init_trace_bufs();
kaf24@3338 700
kaf24@3338 701 /* Give up the VGA console if DOM0 is configured to grab it. */
kaf24@3338 702 console_endboot(cmdline && strstr(cmdline, "tty0"));
kaf24@3338 703
iap10@4287 704 /* Hide UART from DOM0 if we're using it */
iap10@4287 705 serial_endboot();
iap10@4287 706
kaf24@3338 707 domain_unpause_by_systemcontroller(dom0);
kaf24@5146 708
kaf24@3338 709 startup_cpu_idle_loop();
kaf24@3338 710 }
kaf24@3914 711
kaf24@3914 712 /*
kaf24@3914 713 * Local variables:
kaf24@3914 714 * mode: C
kaf24@3914 715 * c-set-style: "BSD"
kaf24@3914 716 * c-basic-offset: 4
kaf24@3914 717 * tab-width: 4
kaf24@3914 718 * indent-tabs-mode: nil
kaf24@3988 719 * End:
kaf24@3914 720 */