ia64/xen-unstable

annotate xen/arch/x86/setup.c @ 3344:e57bbce13b4a

bitkeeper revision 1.1159.170.72 (41d3eaaftC1Zqz_rl9bIUUcTSZFIjg)

Add e820 parsing to Xen. Currently not hooked into heap initialisation:
this is the next step.
author kaf24@scramble.cl.cam.ac.uk
date Thu Dec 30 11:46:55 2004 +0000 (2004-12-30)
parents 4b44501cd54c
children b3b0139a17e0 7f2bf9fecd7e
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/pci.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>
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@1452 20 #include <asm/pdb.h>
kaf24@3338 21 #include <asm/shadow.h>
kaf24@3344 22 #include <asm/e820.h>
kaf24@3338 23
kaf24@3338 24 /* opt_dom0_mem: Kilobytes of memory allocated to domain 0. */
kaf24@3338 25 static unsigned int opt_dom0_mem = 16000;
kaf24@3338 26 integer_param("dom0_mem", opt_dom0_mem);
kaf24@3338 27
kaf24@3338 28 /*
kaf24@3338 29 * opt_xenheap_megabytes: Size of Xen heap in megabytes, excluding the
kaf24@3338 30 * pfn_info table and allocation bitmap.
kaf24@3338 31 */
kaf24@3338 32 static unsigned int opt_xenheap_megabytes = XENHEAP_DEFAULT_MB;
kaf24@3338 33 integer_param("xenheap_megabytes", opt_xenheap_megabytes);
kaf24@1452 34
kaf24@3334 35 /* opt_noht: If true, Hyperthreading is ignored. */
kaf24@3334 36 int opt_noht = 0;
kaf24@3334 37 boolean_param("noht", opt_noht);
kaf24@3334 38
kaf24@3334 39 /* opt_noacpi: If true, ACPI tables are not parsed. */
kaf24@3334 40 static int opt_noacpi = 0;
kaf24@3334 41 boolean_param("noacpi", opt_noacpi);
kaf24@3334 42
kaf24@3334 43 /* opt_nosmp: If true, secondary processors are ignored. */
kaf24@3334 44 static int opt_nosmp = 0;
kaf24@3334 45 boolean_param("nosmp", opt_nosmp);
kaf24@3334 46
kaf24@3334 47 /* opt_ignorebiostables: If true, ACPI and MP tables are ignored. */
kaf24@3334 48 /* NB. This flag implies 'nosmp' and 'noacpi'. */
kaf24@3334 49 static int opt_ignorebiostables = 0;
kaf24@3334 50 boolean_param("ignorebiostables", opt_ignorebiostables);
kaf24@3334 51
kaf24@3334 52 /* opt_watchdog: If true, run a watchdog NMI on each processor. */
kaf24@3334 53 static int opt_watchdog = 0;
kaf24@3334 54 boolean_param("watchdog", opt_watchdog);
kaf24@3334 55
kaf24@3338 56 unsigned long xenheap_phys_end;
kaf24@3338 57
kaf24@2298 58 extern void arch_init_memory(void);
kaf24@1589 59 extern void init_IRQ(void);
kaf24@1589 60 extern void trap_init(void);
kaf24@1589 61 extern void time_init(void);
kaf24@1589 62 extern void ac_timer_init(void);
kaf24@1589 63 extern void initialize_keytable();
kaf24@1589 64 extern int do_timer_lists_from_pit;
kaf24@1589 65
kaf24@1452 66 char ignore_irq13; /* set if exception 16 works */
kaf24@1480 67 struct cpuinfo_x86 boot_cpu_data = { 0, 0, 0, 0, -1 };
kaf24@1452 68
kaf24@1670 69 #if defined(__x86_64__)
kaf24@1670 70 unsigned long mmu_cr4_features = X86_CR4_PSE | X86_CR4_PGE | X86_CR4_PAE;
kaf24@1670 71 #else
kaf24@1452 72 unsigned long mmu_cr4_features = X86_CR4_PSE | X86_CR4_PGE;
kaf24@1670 73 #endif
kaf24@1452 74 EXPORT_SYMBOL(mmu_cr4_features);
kaf24@1452 75
kaf24@1452 76 unsigned long wait_init_idle;
kaf24@1452 77
kaf24@1505 78 struct domain *idle_task[NR_CPUS] = { &idle0_task };
kaf24@1452 79
kaf24@1452 80 #ifdef CONFIG_ACPI_INTERPRETER
kaf24@1452 81 int acpi_disabled = 0;
kaf24@1452 82 #else
kaf24@1452 83 int acpi_disabled = 1;
kaf24@1452 84 #endif
kaf24@1452 85 EXPORT_SYMBOL(acpi_disabled);
kaf24@1452 86
kaf24@1452 87 int phys_proc_id[NR_CPUS];
kaf24@1452 88 int logical_proc_id[NR_CPUS];
kaf24@1452 89
kaf24@1672 90 #if defined(__i386__)
kaf24@1672 91
kaf24@1452 92 /* Standard macro to see if a specific flag is changeable */
kaf24@1452 93 static inline int flag_is_changeable_p(u32 flag)
kaf24@1452 94 {
kaf24@1452 95 u32 f1, f2;
kaf24@1452 96
kaf24@1452 97 asm("pushfl\n\t"
kaf24@1452 98 "pushfl\n\t"
kaf24@1452 99 "popl %0\n\t"
kaf24@1452 100 "movl %0,%1\n\t"
kaf24@1452 101 "xorl %2,%0\n\t"
kaf24@1452 102 "pushl %0\n\t"
kaf24@1452 103 "popfl\n\t"
kaf24@1452 104 "pushfl\n\t"
kaf24@1452 105 "popl %0\n\t"
kaf24@1452 106 "popfl\n\t"
kaf24@1452 107 : "=&r" (f1), "=&r" (f2)
kaf24@1452 108 : "ir" (flag));
kaf24@1452 109
kaf24@1452 110 return ((f1^f2) & flag) != 0;
kaf24@1452 111 }
kaf24@1452 112
kaf24@1452 113 /* Probe for the CPUID instruction */
kaf24@1452 114 static int __init have_cpuid_p(void)
kaf24@1452 115 {
kaf24@1452 116 return flag_is_changeable_p(X86_EFLAGS_ID);
kaf24@1452 117 }
kaf24@1452 118
kaf24@1672 119 #elif defined(__x86_64__)
kaf24@1672 120
kaf24@1672 121 #define have_cpuid_p() (1)
kaf24@1672 122
kaf24@1672 123 #endif
kaf24@1672 124
kaf24@1452 125 void __init get_cpu_vendor(struct cpuinfo_x86 *c)
kaf24@1452 126 {
kaf24@1452 127 char *v = c->x86_vendor_id;
kaf24@1452 128
kaf24@1452 129 if (!strcmp(v, "GenuineIntel"))
kaf24@1452 130 c->x86_vendor = X86_VENDOR_INTEL;
kaf24@1452 131 else if (!strcmp(v, "AuthenticAMD"))
kaf24@1452 132 c->x86_vendor = X86_VENDOR_AMD;
kaf24@1452 133 else if (!strcmp(v, "CyrixInstead"))
kaf24@1452 134 c->x86_vendor = X86_VENDOR_CYRIX;
kaf24@1452 135 else if (!strcmp(v, "UMC UMC UMC "))
kaf24@1452 136 c->x86_vendor = X86_VENDOR_UMC;
kaf24@1452 137 else if (!strcmp(v, "CentaurHauls"))
kaf24@1452 138 c->x86_vendor = X86_VENDOR_CENTAUR;
kaf24@1452 139 else if (!strcmp(v, "NexGenDriven"))
kaf24@1452 140 c->x86_vendor = X86_VENDOR_NEXGEN;
kaf24@1452 141 else if (!strcmp(v, "RiseRiseRise"))
kaf24@1452 142 c->x86_vendor = X86_VENDOR_RISE;
kaf24@1452 143 else if (!strcmp(v, "GenuineTMx86") ||
kaf24@1452 144 !strcmp(v, "TransmetaCPU"))
kaf24@1452 145 c->x86_vendor = X86_VENDOR_TRANSMETA;
kaf24@1452 146 else
kaf24@1452 147 c->x86_vendor = X86_VENDOR_UNKNOWN;
kaf24@1452 148 }
kaf24@1452 149
kaf24@1452 150 static void __init init_intel(struct cpuinfo_x86 *c)
kaf24@1452 151 {
kaf24@1452 152 /* SEP CPUID bug: Pentium Pro reports SEP but doesn't have it */
kaf24@1452 153 if ( c->x86 == 6 && c->x86_model < 3 && c->x86_mask < 3 )
kaf24@1452 154 clear_bit(X86_FEATURE_SEP, &c->x86_capability);
kaf24@1452 155
kaf24@1452 156 #ifdef CONFIG_SMP
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@1452 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 }
kaf24@1452 185 #endif
kaf24@1452 186 }
kaf24@1452 187
kaf24@1452 188 static void __init init_amd(struct cpuinfo_x86 *c)
kaf24@1452 189 {
kaf24@1452 190 /* Bit 31 in normal CPUID used for nonstandard 3DNow ID;
kaf24@1452 191 3DNow is IDd by bit 31 in extended CPUID (1*32+31) anyway */
kaf24@1452 192 clear_bit(0*32+31, &c->x86_capability);
kaf24@1452 193
kaf24@1452 194 switch(c->x86)
kaf24@1452 195 {
kaf24@1452 196 case 5:
kaf24@1452 197 panic("AMD K6 is not supported.\n");
kaf24@1452 198 case 6: /* An Athlon/Duron. We can trust the BIOS probably */
kaf24@1452 199 break;
kaf24@1452 200 }
kaf24@1452 201 }
kaf24@1452 202
kaf24@1452 203 /*
kaf24@1452 204 * This does the hard work of actually picking apart the CPU stuff...
kaf24@1452 205 */
kaf24@1452 206 void __init identify_cpu(struct cpuinfo_x86 *c)
kaf24@1452 207 {
kaf24@1452 208 int junk, i, cpu = smp_processor_id();
kaf24@1452 209 u32 xlvl, tfms;
kaf24@1452 210
kaf24@1452 211 phys_proc_id[cpu] = cpu;
kaf24@1452 212 logical_proc_id[cpu] = 0;
kaf24@1452 213
kaf24@1452 214 c->x86_vendor = X86_VENDOR_UNKNOWN;
kaf24@1452 215 c->cpuid_level = -1; /* CPUID not detected */
kaf24@1452 216 c->x86_model = c->x86_mask = 0; /* So far unknown... */
kaf24@1452 217 c->x86_vendor_id[0] = '\0'; /* Unset */
kaf24@1452 218 memset(&c->x86_capability, 0, sizeof c->x86_capability);
kaf24@1452 219
kaf24@1452 220 if ( !have_cpuid_p() )
kaf24@1452 221 panic("Ancient processors not supported\n");
kaf24@1452 222
kaf24@1452 223 /* Get vendor name */
kaf24@1452 224 cpuid(0x00000000, &c->cpuid_level,
kaf24@1452 225 (int *)&c->x86_vendor_id[0],
kaf24@1452 226 (int *)&c->x86_vendor_id[8],
kaf24@1452 227 (int *)&c->x86_vendor_id[4]);
kaf24@1452 228
kaf24@1452 229 get_cpu_vendor(c);
kaf24@1452 230
kaf24@1452 231 if ( c->cpuid_level == 0 )
kaf24@1452 232 panic("Decrepit CPUID not supported\n");
kaf24@1452 233
kaf24@1452 234 cpuid(0x00000001, &tfms, &junk, &junk,
kaf24@1452 235 &c->x86_capability[0]);
kaf24@1452 236 c->x86 = (tfms >> 8) & 15;
kaf24@1452 237 c->x86_model = (tfms >> 4) & 15;
kaf24@1452 238 c->x86_mask = tfms & 15;
kaf24@1452 239
kaf24@1452 240 /* AMD-defined flags: level 0x80000001 */
kaf24@1452 241 xlvl = cpuid_eax(0x80000000);
kaf24@1452 242 if ( (xlvl & 0xffff0000) == 0x80000000 ) {
kaf24@1452 243 if ( xlvl >= 0x80000001 )
kaf24@1452 244 c->x86_capability[1] = cpuid_edx(0x80000001);
kaf24@1452 245 }
kaf24@1452 246
kaf24@1452 247 /* Transmeta-defined flags: level 0x80860001 */
kaf24@1452 248 xlvl = cpuid_eax(0x80860000);
kaf24@1452 249 if ( (xlvl & 0xffff0000) == 0x80860000 ) {
kaf24@1452 250 if ( xlvl >= 0x80860001 )
kaf24@1452 251 c->x86_capability[2] = cpuid_edx(0x80860001);
kaf24@1452 252 }
kaf24@1452 253
kaf24@1452 254 printk("CPU%d: Before vendor init, caps: %08x %08x %08x, vendor = %d\n",
kaf24@1452 255 smp_processor_id(),
kaf24@1452 256 c->x86_capability[0],
kaf24@1452 257 c->x86_capability[1],
kaf24@1452 258 c->x86_capability[2],
kaf24@1452 259 c->x86_vendor);
kaf24@1452 260
kaf24@1452 261 switch ( c->x86_vendor ) {
kaf24@1452 262 case X86_VENDOR_INTEL:
kaf24@1452 263 init_intel(c);
kaf24@1452 264 break;
kaf24@1452 265 case X86_VENDOR_AMD:
kaf24@1452 266 init_amd(c);
kaf24@1452 267 break;
kaf24@1452 268 case X86_VENDOR_UNKNOWN: /* Connectix Virtual PC reports this */
kaf24@1452 269 break;
kaf24@1452 270 case X86_VENDOR_CENTAUR:
kaf24@1452 271 break;
kaf24@1452 272 default:
kaf24@1452 273 printk("Unknown CPU identifier (%d): continuing anyway, "
kaf24@1452 274 "but might fail.\n", c->x86_vendor);
kaf24@1452 275 }
kaf24@1452 276
kaf24@1452 277 printk("CPU caps: %08x %08x %08x %08x\n",
kaf24@1452 278 c->x86_capability[0],
kaf24@1452 279 c->x86_capability[1],
kaf24@1452 280 c->x86_capability[2],
kaf24@1452 281 c->x86_capability[3]);
kaf24@1452 282
kaf24@1452 283 /*
kaf24@1452 284 * On SMP, boot_cpu_data holds the common feature set between
kaf24@1452 285 * all CPUs; so make sure that we indicate which features are
kaf24@1452 286 * common between the CPUs. The first time this routine gets
kaf24@1452 287 * executed, c == &boot_cpu_data.
kaf24@1452 288 */
kaf24@1452 289 if ( c != &boot_cpu_data ) {
kaf24@1452 290 /* AND the already accumulated flags with these */
kaf24@1452 291 for ( i = 0 ; i < NCAPINTS ; i++ )
kaf24@1452 292 boot_cpu_data.x86_capability[i] &= c->x86_capability[i];
kaf24@1452 293 }
kaf24@1452 294 }
kaf24@1452 295
kaf24@1452 296
kaf24@1452 297 unsigned long cpu_initialized;
kaf24@1452 298 void __init cpu_init(void)
kaf24@1452 299 {
kaf24@1672 300 #if defined(__i386__) /* XXX */
kaf24@1452 301 int nr = smp_processor_id();
kaf24@1452 302 struct tss_struct * t = &init_tss[nr];
kaf24@1452 303
kaf24@1452 304 if ( test_and_set_bit(nr, &cpu_initialized) )
kaf24@1452 305 panic("CPU#%d already initialized!!!\n", nr);
kaf24@1452 306 printk("Initializing CPU#%d\n", nr);
kaf24@1452 307
kaf24@3050 308 t->bitmap = IOBMP_INVALID_OFFSET;
kaf24@1486 309 memset(t->io_bitmap, ~0, sizeof(t->io_bitmap));
kaf24@1486 310
kaf24@1452 311 /* Set up GDT and IDT. */
kaf24@1452 312 SET_GDT_ENTRIES(current, DEFAULT_GDT_ENTRIES);
kaf24@1452 313 SET_GDT_ADDRESS(current, DEFAULT_GDT_ADDRESS);
kaf24@1452 314 __asm__ __volatile__("lgdt %0": "=m" (*current->mm.gdt));
kaf24@1452 315 __asm__ __volatile__("lidt %0": "=m" (idt_descr));
kaf24@1452 316
kaf24@1452 317 /* No nested task. */
kaf24@1452 318 __asm__("pushfl ; andl $0xffffbfff,(%esp) ; popfl");
kaf24@1452 319
kaf24@1452 320 /* Ensure FPU gets initialised for each domain. */
kaf24@1452 321 stts();
kaf24@1452 322
kaf24@1452 323 /* Set up and load the per-CPU TSS and LDT. */
kaf24@1452 324 t->ss0 = __HYPERVISOR_DS;
kaf24@1452 325 t->esp0 = get_stack_top();
kaf24@1452 326 set_tss_desc(nr,t);
kaf24@1452 327 load_TR(nr);
kaf24@1452 328 __asm__ __volatile__("lldt %%ax"::"a" (0));
kaf24@1452 329
kaf24@1452 330 /* Clear all 6 debug registers. */
kaf24@1452 331 #define CD(register) __asm__("movl %0,%%db" #register ::"r"(0) );
kaf24@1452 332 CD(0); CD(1); CD(2); CD(3); /* no db4 and db5 */; CD(6); CD(7);
kaf24@1452 333 #undef CD
kaf24@1452 334
kaf24@1452 335 /* Install correct page table. */
kaf24@1452 336 write_ptbase(&current->mm);
kaf24@1452 337
kaf24@1452 338 init_idle_task();
kaf24@1672 339 #endif
kaf24@1452 340 }
kaf24@1452 341
kaf24@1452 342 static void __init do_initcalls(void)
kaf24@1452 343 {
kaf24@1452 344 initcall_t *call;
kaf24@1452 345 for ( call = &__initcall_start; call < &__initcall_end; call++ )
kaf24@1452 346 (*call)();
kaf24@1452 347 }
kaf24@1452 348
kaf24@1452 349 unsigned long pci_mem_start = 0x10000000;
kaf24@1452 350
kaf24@3338 351 static void __init start_of_day(void)
kaf24@1452 352 {
kaf24@1452 353 unsigned long low_mem_size;
kaf24@1452 354
kaf24@1452 355 #ifdef MEMORY_GUARD
kaf24@1452 356 /* Unmap the first page of CPU0's stack. */
kaf24@1452 357 extern unsigned long cpu0_stack[];
kaf24@1452 358 memguard_guard_range(cpu0_stack, PAGE_SIZE);
kaf24@1452 359 #endif
kaf24@1452 360
kaf24@1505 361 open_softirq(NEW_TLBFLUSH_CLOCK_PERIOD_SOFTIRQ, new_tlbflush_clock_period);
kaf24@1452 362
kaf24@1452 363 if ( opt_watchdog )
kaf24@1452 364 nmi_watchdog = NMI_LOCAL_APIC;
kaf24@1452 365
kaf24@3120 366 sort_exception_tables();
kaf24@3120 367
kaf24@3272 368 arch_do_createdomain(current);
kaf24@3272 369
kaf24@1452 370 /* Tell the PCI layer not to allocate too close to the RAM area.. */
kaf24@1452 371 low_mem_size = ((max_page << PAGE_SHIFT) + 0xfffff) & ~0xfffff;
kaf24@1452 372 if ( low_mem_size > pci_mem_start ) pci_mem_start = low_mem_size;
kaf24@1452 373
kaf24@1452 374 identify_cpu(&boot_cpu_data); /* get CPU type info */
kaf24@1452 375 if ( cpu_has_fxsr ) set_in_cr4(X86_CR4_OSFXSR);
kaf24@1452 376 if ( cpu_has_xmm ) set_in_cr4(X86_CR4_OSXMMEXCPT);
kaf24@1452 377 #ifdef CONFIG_SMP
kaf24@1452 378 if ( opt_ignorebiostables )
kaf24@1452 379 {
kaf24@1452 380 opt_nosmp = 1; /* No SMP without configuration */
kaf24@1452 381 opt_noacpi = 1; /* ACPI will just confuse matters also */
kaf24@1452 382 }
kaf24@1452 383 else
kaf24@1452 384 {
kaf24@1452 385 find_smp_config();
kaf24@1452 386 smp_alloc_memory(); /* trampoline which other CPUs jump at */
kaf24@1452 387 }
kaf24@1452 388 #endif
kaf24@1452 389 paging_init(); /* not much here now, but sets up fixmap */
kaf24@1452 390 if ( !opt_noacpi )
kaf24@1452 391 acpi_boot_init();
kaf24@1452 392 #ifdef CONFIG_SMP
kaf24@1452 393 if ( smp_found_config )
kaf24@1452 394 get_smp_config();
kaf24@1452 395 #endif
kaf24@1452 396 scheduler_init();
kaf24@1497 397 init_IRQ(); /* installs simple interrupt wrappers. Starts HZ clock. */
kaf24@1452 398 trap_init();
kaf24@1452 399 time_init(); /* installs software handler for HZ clock. */
kaf24@1452 400 init_apic_mappings(); /* make APICs addressable in our pagetables. */
kaf24@1452 401
kaf24@2298 402 arch_init_memory();
kaf24@2298 403
kaf24@1452 404 #ifndef CONFIG_SMP
kaf24@1452 405 APIC_init_uniprocessor();
kaf24@1452 406 #else
kaf24@1452 407 if ( opt_nosmp )
kaf24@1452 408 APIC_init_uniprocessor();
kaf24@1452 409 else
kaf24@1452 410 smp_boot_cpus();
kaf24@1452 411 /*
kaf24@1452 412 * Does loads of stuff, including kicking the local
kaf24@1452 413 * APIC, and the IO APIC after other CPUs are booted.
kaf24@1452 414 * Each IRQ is preferably handled by IO-APIC, but
kaf24@1452 415 * fall thru to 8259A if we have to (but slower).
kaf24@1452 416 */
kaf24@1452 417 #endif
kaf24@1452 418
kaf24@1452 419 __sti();
kaf24@1452 420
kaf24@1505 421 initialize_keytable(); /* call back handling for key codes */
kaf24@1452 422
kaf24@1452 423 serial_init_stage2();
kaf24@1452 424
kaf24@1452 425 #ifdef XEN_DEBUGGER
kaf24@1452 426 initialize_pdb(); /* pervasive debugger */
kaf24@1452 427 #endif
kaf24@1452 428
kaf24@1452 429 if ( !cpu_has_apic )
kaf24@1452 430 {
kaf24@1452 431 do_timer_lists_from_pit = 1;
kaf24@1452 432 if ( smp_num_cpus != 1 )
kaf24@1452 433 panic("We need local APICs on SMP machines!");
kaf24@1452 434 }
kaf24@1452 435
kaf24@1452 436 ac_timer_init(); /* init accurate timers */
kaf24@1452 437 init_xen_time(); /* initialise the time */
kaf24@1452 438 schedulers_start(); /* start scheduler for each CPU */
kaf24@1452 439
kaf24@1452 440 check_nmi_watchdog();
kaf24@1452 441
kaf24@1452 442 #ifdef CONFIG_PCI
kaf24@1452 443 pci_init();
kaf24@1452 444 #endif
kaf24@1452 445 do_initcalls();
kaf24@1452 446
kaf24@1452 447 #ifdef CONFIG_SMP
kaf24@1452 448 wait_init_idle = cpu_online_map;
kaf24@1452 449 clear_bit(smp_processor_id(), &wait_init_idle);
kaf24@1452 450 smp_threads_ready = 1;
kaf24@1452 451 smp_commence(); /* Tell other CPUs that state of the world is stable. */
kaf24@2344 452 while ( wait_init_idle != 0 )
kaf24@1452 453 {
kaf24@1452 454 cpu_relax();
kaf24@1452 455 barrier();
kaf24@1452 456 }
kaf24@1452 457 #endif
kaf24@1452 458
kaf24@1452 459 watchdog_on = 1;
kaf24@1452 460 }
kaf24@3338 461
kaf24@3338 462 void __init __start_xen(multiboot_info_t *mbi)
kaf24@3338 463 {
kaf24@3338 464 unsigned long max_page;
kaf24@3338 465 unsigned char *cmdline;
kaf24@3338 466 module_t *mod = (module_t *)__va(mbi->mods_addr);
kaf24@3338 467 void *heap_start;
kaf24@3338 468 unsigned long max_mem;
kaf24@3338 469 unsigned long dom0_memory_start, dom0_memory_end;
kaf24@3338 470 unsigned long initial_images_start, initial_images_end;
kaf24@3344 471 struct e820entry e820_raw[E820MAX];
kaf24@3344 472 int e820_raw_nr = 0, bytes = 0;
kaf24@3338 473
kaf24@3338 474 /* Parse the command-line options. */
kaf24@3344 475 if ( (mbi->flags & MBI_CMDLINE) && (mbi->cmdline != 0) )
kaf24@3344 476 cmdline_parse(__va(mbi->cmdline));
kaf24@3338 477
kaf24@3338 478 /* Must do this early -- e.g., spinlocks rely on get_current(). */
kaf24@3338 479 set_current(&idle0_task);
kaf24@3338 480
kaf24@3338 481 /* We initialise the serial devices very early so we can get debugging. */
kaf24@3338 482 serial_init_stage1();
kaf24@3338 483
kaf24@3338 484 init_console();
kaf24@3338 485
kaf24@3344 486 /* Check that we have at least one Multiboot module. */
kaf24@3344 487 if ( !(mbi->flags & MBI_MODULES) || (mbi->mods_count == 0) )
kaf24@3338 488 {
kaf24@3344 489 printk("FATAL ERROR: Require at least one Multiboot module.\n");
kaf24@3338 490 for ( ; ; ) ;
kaf24@3338 491 }
kaf24@3338 492
kaf24@3338 493 if ( opt_xenheap_megabytes < 4 )
kaf24@3338 494 {
kaf24@3344 495 printk("FATAL ERROR: Xen heap is too small to safely continue!\n");
kaf24@3338 496 for ( ; ; ) ;
kaf24@3338 497 }
kaf24@3338 498
kaf24@3338 499 xenheap_phys_end = opt_xenheap_megabytes << 20;
kaf24@3338 500
kaf24@3344 501 if ( mbi->flags & MBI_MEMMAP )
kaf24@3344 502 {
kaf24@3344 503 while ( bytes < mbi->mmap_length )
kaf24@3344 504 {
kaf24@3344 505 memory_map_t *map = __va(mbi->mmap_addr + bytes);
kaf24@3344 506 e820_raw[e820_raw_nr].addr =
kaf24@3344 507 ((u64)map->base_addr_high << 32) | (u64)map->base_addr_low;
kaf24@3344 508 e820_raw[e820_raw_nr].size =
kaf24@3344 509 ((u64)map->length_high << 32) | (u64)map->length_low;
kaf24@3344 510 e820_raw[e820_raw_nr].type =
kaf24@3344 511 (map->type > E820_NVS) ? E820_RESERVED : map->type;
kaf24@3344 512 e820_raw_nr++;
kaf24@3344 513 bytes += map->size + 4;
kaf24@3344 514 }
kaf24@3344 515 }
kaf24@3344 516 else if ( mbi->flags & MBI_MEMLIMITS )
kaf24@3344 517 {
kaf24@3344 518 e820_raw[0].addr = 0;
kaf24@3344 519 e820_raw[0].size = mbi->mem_lower << 10;
kaf24@3344 520 e820_raw[0].type = E820_RAM;
kaf24@3344 521 e820_raw[0].addr = 0x100000;
kaf24@3344 522 e820_raw[0].size = mbi->mem_upper << 10;
kaf24@3344 523 e820_raw[0].type = E820_RAM;
kaf24@3344 524 e820_raw_nr = 2;
kaf24@3344 525 }
kaf24@3344 526 else
kaf24@3344 527 {
kaf24@3344 528 printk("FATAL ERROR: Bootloader provided no memory information.\n");
kaf24@3344 529 for ( ; ; ) ;
kaf24@3344 530 }
kaf24@3344 531
kaf24@3344 532 max_mem = max_page = init_e820(e820_raw, e820_raw_nr);
kaf24@3338 533 max_mem = max_page = (mbi->mem_upper+1024) >> (PAGE_SHIFT - 10);
kaf24@3338 534
kaf24@3338 535 #if defined(__i386__)
kaf24@3338 536
kaf24@3338 537 initial_images_start = DIRECTMAP_PHYS_END;
kaf24@3338 538 initial_images_end = initial_images_start +
kaf24@3338 539 (mod[mbi->mods_count-1].mod_end - mod[0].mod_start);
kaf24@3338 540 if ( initial_images_end > (max_page << PAGE_SHIFT) )
kaf24@3338 541 {
kaf24@3338 542 printk("Not enough memory to stash the DOM0 kernel image.\n");
kaf24@3338 543 for ( ; ; ) ;
kaf24@3338 544 }
kaf24@3338 545 memmove((void *)initial_images_start, /* use low mapping */
kaf24@3338 546 (void *)mod[0].mod_start, /* use low mapping */
kaf24@3338 547 mod[mbi->mods_count-1].mod_end - mod[0].mod_start);
kaf24@3338 548
kaf24@3338 549 if ( opt_xenheap_megabytes > XENHEAP_DEFAULT_MB )
kaf24@3338 550 {
kaf24@3338 551 printk("Xen heap size is limited to %dMB - you specified %dMB.\n",
kaf24@3338 552 XENHEAP_DEFAULT_MB, opt_xenheap_megabytes);
kaf24@3338 553 for ( ; ; ) ;
kaf24@3338 554 }
kaf24@3338 555
kaf24@3338 556 ASSERT((sizeof(struct pfn_info) << 20) <=
kaf24@3338 557 (FRAMETABLE_VIRT_END - FRAMETABLE_VIRT_START));
kaf24@3338 558
kaf24@3338 559 init_frametable((void *)FRAMETABLE_VIRT_START, max_page);
kaf24@3338 560
kaf24@3338 561 #elif defined(__x86_64__)
kaf24@3338 562
kaf24@3338 563 init_frametable(__va(xenheap_phys_end), max_page);
kaf24@3338 564
kaf24@3338 565 initial_images_start = __pa(frame_table) + frame_table_size;
kaf24@3338 566 initial_images_end = initial_images_start +
kaf24@3338 567 (mod[mbi->mods_count-1].mod_end - mod[0].mod_start);
kaf24@3338 568 if ( initial_images_end > (max_page << PAGE_SHIFT) )
kaf24@3338 569 {
kaf24@3338 570 printk("Not enough memory to stash the DOM0 kernel image.\n");
kaf24@3338 571 for ( ; ; ) ;
kaf24@3338 572 }
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
kaf24@3338 577 #endif
kaf24@3338 578
kaf24@3338 579 dom0_memory_start = (initial_images_end + ((4<<20)-1)) & ~((4<<20)-1);
kaf24@3338 580 dom0_memory_end = dom0_memory_start + (opt_dom0_mem << 10);
kaf24@3338 581 dom0_memory_end = (dom0_memory_end + PAGE_SIZE - 1) & PAGE_MASK;
kaf24@3338 582
kaf24@3338 583 /* Cheesy sanity check: enough memory for DOM0 allocation + some slack? */
kaf24@3338 584 if ( (dom0_memory_end + (8<<20)) > (max_page << PAGE_SHIFT) )
kaf24@3338 585 {
kaf24@3338 586 printk("Not enough memory for DOM0 memory reservation.\n");
kaf24@3338 587 for ( ; ; ) ;
kaf24@3338 588 }
kaf24@3338 589
kaf24@3338 590 printk("Initialised %luMB memory (%lu pages) on a %luMB machine\n",
kaf24@3338 591 max_page >> (20-PAGE_SHIFT), max_page,
kaf24@3338 592 max_mem >> (20-PAGE_SHIFT));
kaf24@3338 593
kaf24@3338 594 heap_start = memguard_init(&_end);
kaf24@3338 595 heap_start = __va(init_heap_allocator(__pa(heap_start), max_page));
kaf24@3338 596
kaf24@3338 597 init_xenheap_pages(__pa(heap_start), xenheap_phys_end);
kaf24@3338 598 printk("Xen heap size is %luKB\n",
kaf24@3338 599 (xenheap_phys_end-__pa(heap_start))/1024 );
kaf24@3338 600
kaf24@3338 601 init_domheap_pages(dom0_memory_end, max_page << PAGE_SHIFT);
kaf24@3338 602
kaf24@3338 603 /* Initialise the slab allocator. */
kaf24@3338 604 xmem_cache_init();
kaf24@3338 605 xmem_cache_sizes_init(max_page);
kaf24@3338 606
kaf24@3338 607 domain_startofday();
kaf24@3338 608
kaf24@3338 609 start_of_day();
kaf24@3338 610
kaf24@3338 611 grant_table_init();
kaf24@3338 612
kaf24@3338 613 shadow_mode_init();
kaf24@3338 614
kaf24@3338 615 /* Create initial domain 0. */
kaf24@3338 616 dom0 = do_createdomain(0, 0);
kaf24@3338 617 if ( dom0 == NULL )
kaf24@3338 618 panic("Error creating domain 0\n");
kaf24@3338 619
kaf24@3338 620 set_bit(DF_PRIVILEGED, &dom0->flags);
kaf24@3338 621
kaf24@3338 622 /* Grab the DOM0 command line. Skip past the image name. */
kaf24@3338 623 cmdline = (unsigned char *)(mod[0].string ? __va(mod[0].string) : NULL);
kaf24@3338 624 if ( cmdline != NULL )
kaf24@3338 625 {
kaf24@3338 626 while ( *cmdline == ' ' ) cmdline++;
kaf24@3338 627 if ( (cmdline = strchr(cmdline, ' ')) != NULL )
kaf24@3338 628 while ( *cmdline == ' ' ) cmdline++;
kaf24@3338 629 }
kaf24@3338 630
kaf24@3338 631 /*
kaf24@3338 632 * We're going to setup domain0 using the module(s) that we stashed safely
kaf24@3338 633 * above our heap. The second module, if present, is an initrd ramdisk.
kaf24@3338 634 */
kaf24@3338 635 if ( construct_dom0(dom0, dom0_memory_start, dom0_memory_end,
kaf24@3338 636 (char *)initial_images_start,
kaf24@3338 637 mod[0].mod_end-mod[0].mod_start,
kaf24@3338 638 (mbi->mods_count == 1) ? 0 :
kaf24@3338 639 (char *)initial_images_start +
kaf24@3338 640 (mod[1].mod_start-mod[0].mod_start),
kaf24@3338 641 (mbi->mods_count == 1) ? 0 :
kaf24@3338 642 mod[mbi->mods_count-1].mod_end - mod[1].mod_start,
kaf24@3338 643 cmdline) != 0)
kaf24@3338 644 panic("Could not set up DOM0 guest OS\n");
kaf24@3338 645
kaf24@3338 646 /* The stash space for the initial kernel image can now be freed up. */
kaf24@3338 647 init_domheap_pages(__pa(frame_table) + frame_table_size,
kaf24@3338 648 dom0_memory_start);
kaf24@3338 649
kaf24@3338 650 scrub_heap_pages();
kaf24@3338 651
kaf24@3338 652 init_trace_bufs();
kaf24@3338 653
kaf24@3338 654 /* Give up the VGA console if DOM0 is configured to grab it. */
kaf24@3338 655 console_endboot(cmdline && strstr(cmdline, "tty0"));
kaf24@3338 656
kaf24@3338 657 domain_unpause_by_systemcontroller(current);
kaf24@3338 658 domain_unpause_by_systemcontroller(dom0);
kaf24@3338 659 startup_cpu_idle_loop();
kaf24@3338 660 }