ia64/xen-unstable

annotate xen/arch/x86/setup.c @ 15298:3cc79ef896a2

x86: Allow selection of graphical video modes during boot.

The 'vga=' boot option is extended as follows:

----------
'vga=<mode-specifier>[,keep]' where <mode-specifier> is one of:

'vga=ask':
display a vga menu of available modes

'vga=text-80x<rows>':
text mode, where <rows> is one of {25,28,30,34,43,50,60}

'vga=gfx-<width>x<height>x<depth>':
graphics mode, e.g., vga=gfx-1024x768x16

'vga=mode-<mode>:
specifies a mode as specified in 'vga=ask' menu
(NB. menu modes are displayed in hex, so mode numbers here must
be prefixed with '0x' (e.g., 'vga=mode-0x0318'))

The option 'keep' causes Xen to continue to print to the VGA console even
after domain 0 starts to boot. The default behaviour is to relinquish
control of the console to domain 0.
----------

Signed-off-by: Keir Fraser <keir@xensource.com>
author Keir Fraser <keir@xensource.com>
date Sun Jun 10 15:58:08 2007 +0100 (2007-06-10)
parents 345ae2e61ba0
children 9766af047b6c
rev   line source
kaf24@1452 1 #include <xen/config.h>
kaf24@1452 2 #include <xen/init.h>
kaf24@1452 3 #include <xen/lib.h>
kaf24@1452 4 #include <xen/sched.h>
cl349@5247 5 #include <xen/domain.h>
kaf24@1452 6 #include <xen/serial.h>
kaf24@1506 7 #include <xen/softirq.h>
kaf24@1452 8 #include <xen/acpi.h>
kaf24@3338 9 #include <xen/console.h>
iap10@4287 10 #include <xen/serial.h>
kaf24@3338 11 #include <xen/trace.h>
kaf24@3338 12 #include <xen/multiboot.h>
kaf24@5356 13 #include <xen/domain_page.h>
kfraser@10890 14 #include <xen/version.h>
kaf24@9117 15 #include <xen/gdbstub.h>
kaf24@9818 16 #include <xen/percpu.h>
kfraser@11296 17 #include <xen/hypercall.h>
kfraser@11601 18 #include <xen/keyhandler.h>
kfraser@11971 19 #include <xen/numa.h>
kaf24@13662 20 #include <xen/rcupdate.h>
keir@15298 21 #include <xen/vga.h>
iap10@6721 22 #include <public/version.h>
ack@13291 23 #ifdef CONFIG_COMPAT
ack@13291 24 #include <compat/platform.h>
ack@13291 25 #include <compat/xen.h>
ack@13291 26 #endif
kaf24@1452 27 #include <asm/bitops.h>
kaf24@1452 28 #include <asm/smp.h>
kaf24@1452 29 #include <asm/processor.h>
kaf24@1452 30 #include <asm/mpspec.h>
kaf24@1452 31 #include <asm/apic.h>
kaf24@1452 32 #include <asm/desc.h>
Tim@13909 33 #include <asm/paging.h>
kaf24@3344 34 #include <asm/e820.h>
kaf24@5536 35 #include <acm/acm_hooks.h>
ian@12677 36 #include <xen/kexec.h>
kaf24@3338 37
kfraser@15074 38 #if defined(CONFIG_X86_64)
kfraser@15074 39 #define BOOTSTRAP_DIRECTMAP_END (1UL << 32)
kfraser@15074 40 #define maddr_to_bootstrap_virt(m) maddr_to_virt(m)
kfraser@15074 41 #else
kfraser@15074 42 #define BOOTSTRAP_DIRECTMAP_END HYPERVISOR_VIRT_START
kfraser@15074 43 #define maddr_to_bootstrap_virt(m) ((void *)(long)(m))
kfraser@15074 44 #endif
kfraser@15074 45
kaf24@5157 46 extern void dmi_scan_machine(void);
kaf24@5211 47 extern void generic_apic_probe(void);
kfraser@11971 48 extern void numa_initmem_init(unsigned long start_pfn, unsigned long end_pfn);
kaf24@5157 49
kaf24@3338 50 /*
kaf24@3338 51 * opt_xenheap_megabytes: Size of Xen heap in megabytes, excluding the
kaf24@8726 52 * page_info table and allocation bitmap.
kaf24@3338 53 */
kaf24@3338 54 static unsigned int opt_xenheap_megabytes = XENHEAP_DEFAULT_MB;
kaf24@4950 55 #if defined(CONFIG_X86_64)
kaf24@3338 56 integer_param("xenheap_megabytes", opt_xenheap_megabytes);
kaf24@3354 57 #endif
kaf24@1452 58
kaf24@5146 59 /* opt_nosmp: If true, secondary processors are ignored. */
kaf24@5900 60 static int opt_nosmp = 0;
kaf24@5146 61 boolean_param("nosmp", opt_nosmp);
kaf24@5146 62
kaf24@5146 63 /* maxcpus: maximum number of CPUs to activate. */
kaf24@5146 64 static unsigned int max_cpus = NR_CPUS;
shand@11156 65 integer_param("maxcpus", max_cpus);
kaf24@5146 66
kaf24@3334 67 /* opt_watchdog: If true, run a watchdog NMI on each processor. */
kaf24@3334 68 static int opt_watchdog = 0;
kaf24@3334 69 boolean_param("watchdog", opt_watchdog);
kaf24@3334 70
kaf24@4850 71 /* **** Linux config option: propagated to domain0. */
kaf24@4850 72 /* "acpi=off": Sisables both ACPI table parsing and interpreter. */
kaf24@4850 73 /* "acpi=force": Override the disable blacklist. */
kaf24@4850 74 /* "acpi=strict": Disables out-of-spec workarounds. */
kaf24@4850 75 /* "acpi=ht": Limit ACPI just to boot-time to enable HT. */
kaf24@4850 76 /* "acpi=noirq": Disables ACPI interrupt routing. */
kaf24@4850 77 static void parse_acpi_param(char *s);
kaf24@4850 78 custom_param("acpi", parse_acpi_param);
kaf24@4850 79
kaf24@4850 80 /* **** Linux config option: propagated to domain0. */
kaf24@4850 81 /* acpi_skip_timer_override: Skip IRQ0 overrides. */
kaf24@4850 82 extern int acpi_skip_timer_override;
kaf24@4850 83 boolean_param("acpi_skip_timer_override", acpi_skip_timer_override);
kaf24@4850 84
kaf24@4850 85 /* **** Linux config option: propagated to domain0. */
kaf24@4850 86 /* noapic: Disable IOAPIC setup. */
kaf24@4850 87 extern int skip_ioapic_setup;
kaf24@4850 88 boolean_param("noapic", skip_ioapic_setup);
kaf24@4850 89
kaf24@3594 90 int early_boot = 1;
kaf24@3594 91
kaf24@5146 92 cpumask_t cpu_present_map;
kaf24@5146 93
kfraser@15074 94 unsigned long xen_phys_start;
kfraser@15074 95
kaf24@5003 96 /* Limits of Xen heap, used to initialise the allocator. */
kaf24@5003 97 unsigned long xenheap_phys_start, xenheap_phys_end;
kaf24@3338 98
kaf24@2298 99 extern void arch_init_memory(void);
kaf24@1589 100 extern void init_IRQ(void);
kaf24@1589 101 extern void trap_init(void);
kaf24@5604 102 extern void early_time_init(void);
kaf24@5167 103 extern void early_cpu_init(void);
kaf24@1589 104
kaf24@8533 105 struct tss_struct init_tss[NR_CPUS];
kaf24@8533 106
kfraser@15074 107 char __attribute__ ((__section__(".bss.page_aligned"))) cpu0_stack[STACK_SIZE];
kaf24@5011 108
kaf24@5214 109 struct cpuinfo_x86 boot_cpu_data = { 0, 0, 0, 0, -1, 1, 0, 0, -1 };
kaf24@1452 110
kaf24@5237 111 #if CONFIG_PAGING_LEVELS > 2
kaf24@1670 112 unsigned long mmu_cr4_features = X86_CR4_PSE | X86_CR4_PGE | X86_CR4_PAE;
kaf24@1670 113 #else
kaf24@5593 114 unsigned long mmu_cr4_features = X86_CR4_PSE;
kaf24@1670 115 #endif
kaf24@1452 116 EXPORT_SYMBOL(mmu_cr4_features);
kaf24@1452 117
kaf24@4818 118 int acpi_disabled;
kaf24@1452 119
kaf24@4850 120 int acpi_force;
kaf24@4850 121 char acpi_param[10] = "";
kfraser@15074 122 static void __init parse_acpi_param(char *s)
kaf24@4850 123 {
kaf24@4850 124 /* Save the parameter so it can be propagated to domain0. */
kfraser@13689 125 safe_strcpy(acpi_param, s);
kaf24@4850 126
kaf24@4850 127 /* Interpret the parameter for use within Xen. */
kaf24@4850 128 if ( !strcmp(s, "off") )
kaf24@4850 129 {
kaf24@4850 130 disable_acpi();
kaf24@4850 131 }
kaf24@4850 132 else if ( !strcmp(s, "force") )
kaf24@4850 133 {
kaf24@4850 134 acpi_force = 1;
kaf24@4850 135 acpi_ht = 1;
kaf24@4850 136 acpi_disabled = 0;
kaf24@4850 137 }
kaf24@4850 138 else if ( !strcmp(s, "strict") )
kaf24@4850 139 {
kaf24@4850 140 acpi_strict = 1;
kaf24@4850 141 }
kaf24@4850 142 else if ( !strcmp(s, "ht") )
kaf24@4850 143 {
kaf24@4850 144 if ( !acpi_force )
kaf24@4850 145 disable_acpi();
kaf24@4850 146 acpi_ht = 1;
kaf24@4850 147 }
kaf24@4850 148 else if ( !strcmp(s, "noirq") )
kaf24@4850 149 {
kaf24@4850 150 acpi_noirq_set();
kaf24@4850 151 }
kaf24@4850 152 }
kaf24@4850 153
kaf24@1452 154 static void __init do_initcalls(void)
kaf24@1452 155 {
kaf24@1452 156 initcall_t *call;
kaf24@1452 157 for ( call = &__initcall_start; call < &__initcall_end; call++ )
kaf24@1452 158 (*call)();
kaf24@1452 159 }
kaf24@1452 160
kfraser@15074 161 #define EARLY_FAIL(f, a...) do { \
kfraser@15074 162 printk( f , ## a ); \
kfraser@15074 163 for ( ; ; ) __asm__ __volatile__ ( "hlt" ); \
kfraser@15074 164 } while (0)
kaf24@8459 165
kfraser@15074 166 static unsigned long __initdata initial_images_start, initial_images_end;
kaf24@9067 167
kfraser@15074 168 unsigned long __init initial_images_nrpages(void)
kaf24@9067 169 {
kaf24@9067 170 unsigned long s = initial_images_start + PAGE_SIZE - 1;
kaf24@9067 171 unsigned long e = initial_images_end;
kaf24@9067 172 return ((e >> PAGE_SHIFT) - (s >> PAGE_SHIFT));
kaf24@9067 173 }
kaf24@9067 174
kfraser@15074 175 void __init discard_initial_images(void)
kaf24@9067 176 {
kaf24@9067 177 init_domheap_pages(initial_images_start, initial_images_end);
kaf24@9067 178 }
kaf24@9067 179
kaf24@9818 180 extern char __per_cpu_start[], __per_cpu_data_end[], __per_cpu_end[];
kaf24@9818 181
kfraser@11241 182 static void __init percpu_init_areas(void)
kaf24@9818 183 {
kaf24@9818 184 unsigned int i, data_size = __per_cpu_data_end - __per_cpu_start;
kfraser@15074 185 unsigned int first_unused;
kaf24@9818 186
kaf24@9818 187 BUG_ON(data_size > PERCPU_SIZE);
kaf24@9818 188
kfraser@15074 189 /* Initialise per-cpu data area for all possible secondary CPUs. */
kfraser@15074 190 for ( i = 1; (i < NR_CPUS) && cpu_possible(i); i++ )
kfraser@15074 191 memcpy(__per_cpu_start + (i << PERCPU_SHIFT),
kfraser@15074 192 __per_cpu_start,
kfraser@15074 193 data_size);
kaf24@9818 194 first_unused = i;
kaf24@9818 195
kfraser@14340 196 /* Check that there are no holes in cpu_possible_map. */
kaf24@9818 197 for ( ; i < NR_CPUS; i++ )
kfraser@14340 198 BUG_ON(cpu_possible(i));
kaf24@9818 199
kfraser@11241 200 #ifndef MEMORY_GUARD
kaf24@9818 201 init_xenheap_pages(__pa(__per_cpu_start) + (first_unused << PERCPU_SHIFT),
kaf24@9818 202 __pa(__per_cpu_end));
kfraser@11241 203 #endif
keir@15082 204 memguard_guard_range(&__per_cpu_start[first_unused << PERCPU_SHIFT],
keir@15082 205 (NR_CPUS - first_unused) << PERCPU_SHIFT);
keir@15082 206 #if defined(CONFIG_X86_64)
keir@15082 207 /* Also zap the mapping in the 1:1 area. */
keir@15082 208 memguard_guard_range(__va(__pa(__per_cpu_start)) +
keir@15082 209 (first_unused << PERCPU_SHIFT),
keir@15082 210 (NR_CPUS - first_unused) << PERCPU_SHIFT);
keir@15082 211 #endif
kaf24@9818 212 }
kaf24@9818 213
kfraser@11881 214 /* Fetch acm policy module from multiboot modules. */
kfraser@15074 215 static void __init extract_acm_policy(
kfraser@11881 216 multiboot_info_t *mbi,
kfraser@11881 217 unsigned int *initrdidx,
kfraser@11881 218 char **_policy_start,
kfraser@11881 219 unsigned long *_policy_len)
kfraser@11881 220 {
kfraser@11881 221 int i;
kfraser@11881 222 module_t *mod = (module_t *)__va(mbi->mods_addr);
kfraser@11881 223 unsigned long start, policy_len;
kfraser@11881 224 char *policy_start;
kfraser@11881 225
kfraser@11881 226 /*
kfraser@11881 227 * Try all modules and see whichever could be the binary policy.
kfraser@11881 228 * Adjust the initrdidx if module[1] is the binary policy.
kfraser@11881 229 */
kfraser@11881 230 for ( i = mbi->mods_count-1; i >= 1; i-- )
kfraser@11881 231 {
kfraser@11881 232 start = initial_images_start + (mod[i].mod_start-mod[0].mod_start);
kfraser@15074 233 policy_start = maddr_to_bootstrap_virt(start);
kfraser@11881 234 policy_len = mod[i].mod_end - mod[i].mod_start;
kfraser@11881 235 if ( acm_is_policy(policy_start, policy_len) )
kfraser@11881 236 {
kfraser@11881 237 printk("Policy len 0x%lx, start at %p - module %d.\n",
kfraser@11881 238 policy_len, policy_start, i);
kfraser@11881 239 *_policy_start = policy_start;
kfraser@11881 240 *_policy_len = policy_len;
kfraser@11881 241 if ( i == 1 )
kfraser@11881 242 *initrdidx = (mbi->mods_count > 2) ? 2 : 0;
kfraser@11881 243 break;
kfraser@11881 244 }
kfraser@11881 245 }
kfraser@11881 246 }
kfraser@11881 247
kfraser@11241 248 static void __init init_idle_domain(void)
kfraser@11240 249 {
kfraser@11240 250 struct domain *idle_domain;
kfraser@11240 251
kfraser@11240 252 /* Domain creation requires that scheduler structures are initialised. */
kfraser@11240 253 scheduler_init();
kfraser@11240 254
kfraser@14911 255 idle_domain = domain_create(IDLE_DOMAIN_ID, 0, 0);
kfraser@11240 256 if ( (idle_domain == NULL) || (alloc_vcpu(idle_domain, 0, 0) == NULL) )
kfraser@11240 257 BUG();
kfraser@11240 258
kfraser@11240 259 set_current(idle_domain->vcpu[0]);
kfraser@11240 260 idle_vcpu[0] = this_cpu(curr_vcpu) = current;
kfraser@11240 261
kfraser@11240 262 setup_idle_pagetable();
kfraser@11240 263 }
kfraser@11240 264
kfraser@15074 265 static void __init srat_detect_node(int cpu)
kfraser@11971 266 {
kfraser@11998 267 unsigned node;
kfraser@11998 268 u8 apicid = x86_cpu_to_apicid[cpu];
kfraser@11971 269
kfraser@11998 270 node = apicid_to_node[apicid];
kfraser@11998 271 if ( node == NUMA_NO_NODE )
kfraser@11998 272 node = 0;
kfraser@11998 273 numa_set_node(cpu, node);
kfraser@11971 274
kfraser@11998 275 if ( acpi_numa > 0 )
kfraser@11998 276 printk(KERN_INFO "CPU %d APIC %d -> Node %d\n", cpu, apicid, node);
kfraser@11971 277 }
kfraser@11971 278
kfraser@15074 279 static void __init move_memory(
kfraser@15074 280 unsigned long dst, unsigned long src_start, unsigned long src_end)
ian@12677 281 {
kfraser@15074 282 memmove(maddr_to_bootstrap_virt(dst),
kfraser@15074 283 maddr_to_bootstrap_virt(src_start),
ian@12677 284 src_end - src_start);
kfraser@15074 285 }
kfraser@15074 286
kfraser@15074 287 /* A temporary copy of the e820 map that we can mess with during bootstrap. */
kfraser@15074 288 static struct e820map __initdata boot_e820;
kfraser@15074 289
kfraser@15074 290 /* Reserve area (@s,@e) in the temporary bootstrap e820 map. */
kfraser@15074 291 static void __init reserve_in_boot_e820(unsigned long s, unsigned long e)
kfraser@15074 292 {
kfraser@15074 293 unsigned long rs, re;
kfraser@15074 294 int i;
kfraser@15074 295
kfraser@15074 296 for ( i = 0; i < boot_e820.nr_map; i++ )
kfraser@15074 297 {
kfraser@15074 298 /* Have we found the e820 region that includes the specified range? */
kfraser@15074 299 rs = boot_e820.map[i].addr;
kfraser@15074 300 re = boot_e820.map[i].addr + boot_e820.map[i].size;
kfraser@15074 301 if ( (s < rs) || (e > re) )
kfraser@15074 302 continue;
kfraser@15074 303
kfraser@15074 304 /* Start fragment. */
kfraser@15074 305 boot_e820.map[i].size = s - rs;
kfraser@15074 306
kfraser@15074 307 /* End fragment. */
kfraser@15074 308 if ( e < re )
kfraser@15074 309 {
kfraser@15074 310 memmove(&boot_e820.map[i+1], &boot_e820.map[i],
kfraser@15074 311 (boot_e820.nr_map-i) * sizeof(boot_e820.map[0]));
kfraser@15074 312 boot_e820.nr_map++;
kfraser@15074 313 i++;
kfraser@15074 314 boot_e820.map[i].addr = e;
kfraser@15074 315 boot_e820.map[i].size = re - e;
kfraser@15074 316 }
kfraser@15074 317 }
ian@12677 318 }
ian@12677 319
keir@15298 320 struct boot_video_info {
keir@15298 321 u8 orig_x; /* 0x00 */
keir@15298 322 u8 orig_y; /* 0x01 */
keir@15298 323 u8 orig_video_mode; /* 0x02 */
keir@15298 324 u8 orig_video_cols; /* 0x03 */
keir@15298 325 u8 orig_video_lines; /* 0x04 */
keir@15298 326 u8 orig_video_isVGA; /* 0x05 */
keir@15298 327 u16 orig_video_points; /* 0x06 */
keir@15298 328
keir@15298 329 /* VESA graphic mode -- linear frame buffer */
keir@15298 330 u32 capabilities; /* 0x08 */
keir@15298 331 u16 lfb_linelength; /* 0x0c */
keir@15298 332 u16 lfb_width; /* 0x0e */
keir@15298 333 u16 lfb_height; /* 0x10 */
keir@15298 334 u16 lfb_depth; /* 0x12 */
keir@15298 335 u32 lfb_base; /* 0x14 */
keir@15298 336 u32 lfb_size; /* 0x18 */
keir@15298 337 u8 red_size; /* 0x1c */
keir@15298 338 u8 red_pos; /* 0x1d */
keir@15298 339 u8 green_size; /* 0x1e */
keir@15298 340 u8 green_pos; /* 0x1f */
keir@15298 341 u8 blue_size; /* 0x20 */
keir@15298 342 u8 blue_pos; /* 0x21 */
keir@15298 343 u8 rsvd_size; /* 0x22 */
keir@15298 344 u8 rsvd_pos; /* 0x23 */
keir@15298 345 u16 vesapm_seg; /* 0x24 */
keir@15298 346 u16 vesapm_off; /* 0x26 */
keir@15298 347 };
keir@15298 348
keir@15298 349 static void __init parse_video_info(void)
keir@15298 350 {
keir@15298 351 extern struct boot_video_info boot_vid_info;
keir@15298 352 struct boot_video_info *bvi = &bootsym(boot_vid_info);
keir@15298 353
keir@15298 354 if ( (bvi->orig_video_isVGA == 1) && (bvi->orig_video_mode == 3) )
keir@15298 355 {
keir@15298 356 vga_console_info.video_type = XEN_VGATYPE_TEXT_MODE_3;
keir@15298 357 vga_console_info.u.text_mode_3.font_height = bvi->orig_video_points;
keir@15298 358 vga_console_info.u.text_mode_3.cursor_x = bvi->orig_x;
keir@15298 359 vga_console_info.u.text_mode_3.cursor_y = bvi->orig_y;
keir@15298 360 vga_console_info.u.text_mode_3.rows = bvi->orig_video_lines;
keir@15298 361 vga_console_info.u.text_mode_3.columns = bvi->orig_video_cols;
keir@15298 362 }
keir@15298 363 else if ( bvi->orig_video_isVGA == 0x23 )
keir@15298 364 {
keir@15298 365 vga_console_info.video_type = XEN_VGATYPE_VESA_LFB;
keir@15298 366 vga_console_info.u.vesa_lfb.width = bvi->lfb_width;
keir@15298 367 vga_console_info.u.vesa_lfb.height = bvi->lfb_height;
keir@15298 368 vga_console_info.u.vesa_lfb.bytes_per_line = bvi->lfb_linelength;
keir@15298 369 vga_console_info.u.vesa_lfb.bits_per_pixel = bvi->lfb_depth;
keir@15298 370 vga_console_info.u.vesa_lfb.lfb_base = bvi->lfb_base;
keir@15298 371 vga_console_info.u.vesa_lfb.lfb_size = bvi->lfb_size;
keir@15298 372 vga_console_info.u.vesa_lfb.red_pos = bvi->red_pos;
keir@15298 373 vga_console_info.u.vesa_lfb.red_size = bvi->red_size;
keir@15298 374 vga_console_info.u.vesa_lfb.green_pos = bvi->green_pos;
keir@15298 375 vga_console_info.u.vesa_lfb.green_size = bvi->green_size;
keir@15298 376 vga_console_info.u.vesa_lfb.blue_pos = bvi->blue_pos;
keir@15298 377 vga_console_info.u.vesa_lfb.blue_size = bvi->blue_size;
keir@15298 378 vga_console_info.u.vesa_lfb.rsvd_pos = bvi->rsvd_pos;
keir@15298 379 vga_console_info.u.vesa_lfb.rsvd_size = bvi->rsvd_size;
keir@15298 380 }
keir@15298 381 }
keir@15298 382
keir@15082 383 void init_done(void)
keir@15082 384 {
keir@15082 385 extern char __init_begin[], __init_end[];
keir@15082 386
keir@15082 387 /* Free (or page-protect) the init areas. */
keir@15082 388 #ifndef MEMORY_GUARD
keir@15082 389 init_xenheap_pages(__pa(__init_begin), __pa(__init_end));
keir@15082 390 #endif
keir@15082 391 memguard_guard_range(__init_begin, __init_end - __init_begin);
keir@15082 392 #if defined(CONFIG_X86_64)
keir@15082 393 /* Also zap the mapping in the 1:1 area. */
keir@15082 394 memguard_guard_range(__va(__pa(__init_begin)), __init_end - __init_begin);
keir@15082 395 #endif
keir@15082 396 printk("Freed %ldkB init memory.\n", (long)(__init_end-__init_begin)>>10);
keir@15082 397
keir@15082 398 startup_cpu_idle_loop();
keir@15082 399 }
keir@15082 400
kaf24@8463 401 void __init __start_xen(multiboot_info_t *mbi)
kaf24@1452 402 {
kfraser@15293 403 char *memmap_type = NULL;
kaf24@9823 404 char __cmdline[] = "", *cmdline = __cmdline;
kaf24@8457 405 unsigned long _initrd_start = 0, _initrd_len = 0;
kaf24@8457 406 unsigned int initrdidx = 1;
kfraser@11881 407 char *_policy_start = NULL;
kfraser@11881 408 unsigned long _policy_len = 0;
kaf24@8457 409 module_t *mod = (module_t *)__va(mbi->mods_addr);
kaf24@6111 410 unsigned long nr_pages, modules_length;
kfraser@15293 411 int i, e820_warn = 0, bytes = 0;
kaf24@5776 412 struct ns16550_defaults ns16550 = {
kaf24@5776 413 .data_bits = 8,
kaf24@5776 414 .parity = 'n',
kaf24@5776 415 .stop_bits = 1
kaf24@5776 416 };
kaf24@3338 417
kfraser@12853 418 extern void early_page_fault(void);
kfraser@12853 419 set_intr_gate(TRAP_page_fault, &early_page_fault);
kfraser@12853 420
kaf24@3338 421 /* Parse the command-line options. */
kaf24@3344 422 if ( (mbi->flags & MBI_CMDLINE) && (mbi->cmdline != 0) )
kaf24@9823 423 cmdline = __va(mbi->cmdline);
kaf24@9823 424 cmdline_parse(cmdline);
kaf24@3338 425
keir@15298 426 parse_video_info();
keir@15298 427
kaf24@8534 428 set_current((struct vcpu *)0xfffff000); /* debug sanity */
kfraser@11240 429 idle_vcpu[0] = current;
kaf24@8534 430 set_processor_id(0); /* needed early, for smp_processor_id() */
kaf24@3338 431
kaf24@5146 432 smp_prepare_boot_cpu();
kaf24@5146 433
kaf24@3338 434 /* We initialise the serial devices very early so we can get debugging. */
kaf24@5776 435 ns16550.io_base = 0x3f8;
kaf24@5776 436 ns16550.irq = 4;
kaf24@5776 437 ns16550_init(0, &ns16550);
kaf24@5776 438 ns16550.io_base = 0x2f8;
kaf24@5776 439 ns16550.irq = 3;
kaf24@5776 440 ns16550_init(1, &ns16550);
kaf24@5195 441 serial_init_preirq();
kaf24@3338 442
kaf24@3338 443 init_console();
kaf24@3338 444
kfraser@11947 445 printk("Command line: %s\n", cmdline);
kaf24@9823 446
keir@15298 447 switch ( vga_console_info.video_type )
keir@15298 448 {
keir@15298 449 case XEN_VGATYPE_TEXT_MODE_3:
keir@15298 450 printk("VGA is text mode %dx%d, font 8x%d\n",
keir@15298 451 vga_console_info.u.text_mode_3.columns,
keir@15298 452 vga_console_info.u.text_mode_3.rows,
keir@15298 453 vga_console_info.u.text_mode_3.font_height);
keir@15298 454 break;
keir@15298 455 case XEN_VGATYPE_VESA_LFB:
keir@15298 456 printk("VGA is graphics mode %dx%d, %d bpp\n",
keir@15298 457 vga_console_info.u.vesa_lfb.width,
keir@15298 458 vga_console_info.u.vesa_lfb.height,
keir@15298 459 vga_console_info.u.vesa_lfb.bits_per_pixel);
keir@15298 460 break;
keir@15298 461 }
keir@15298 462
kaf24@3344 463 /* Check that we have at least one Multiboot module. */
kaf24@3344 464 if ( !(mbi->flags & MBI_MODULES) || (mbi->mods_count == 0) )
kfraser@15074 465 EARLY_FAIL("dom0 kernel not specified. "
kfraser@15074 466 "Check bootloader configuration.\n");
kaf24@5011 467
kaf24@5011 468 if ( ((unsigned long)cpu0_stack & (STACK_SIZE-1)) != 0 )
kfraser@15074 469 EARLY_FAIL("Misaligned CPU0 stack.\n");
kaf24@3338 470
kfraser@11618 471 /*
kfraser@11618 472 * Since there are some stubs getting built on the stacks which use
kfraser@11618 473 * direct calls/jumps, the heap must be confined to the lower 2G so
kfraser@11618 474 * that those branches can reach their targets.
kfraser@11618 475 */
kfraser@11618 476 if ( opt_xenheap_megabytes > 2048 )
kfraser@11618 477 opt_xenheap_megabytes = 2048;
kaf24@3338 478
kfraser@15293 479 if ( e820_raw_nr != 0 )
kfraser@15292 480 {
kfraser@15293 481 memmap_type = "Xen-e820";
kfraser@15292 482 }
kfraser@15293 483 else if ( bootsym(lowmem_kb) )
kfraser@15292 484 {
kfraser@15293 485 memmap_type = "Xen-e801";
kfraser@15292 486 e820_raw[0].addr = 0;
kfraser@15293 487 e820_raw[0].size = bootsym(lowmem_kb) << 10;
kfraser@15292 488 e820_raw[0].type = E820_RAM;
kfraser@15292 489 e820_raw[1].addr = 0x100000;
kfraser@15293 490 e820_raw[1].size = bootsym(highmem_kb) << 10;
kfraser@15292 491 e820_raw[1].type = E820_RAM;
kfraser@15292 492 e820_raw_nr = 2;
kfraser@15292 493 }
kfraser@15292 494 else if ( mbi->flags & MBI_MEMMAP )
kaf24@3344 495 {
kfraser@15293 496 memmap_type = "Multiboot-e820";
kaf24@3344 497 while ( bytes < mbi->mmap_length )
kaf24@3344 498 {
kaf24@3344 499 memory_map_t *map = __va(mbi->mmap_addr + bytes);
kaf24@8402 500
kaf24@8402 501 /*
kaf24@8403 502 * This is a gross workaround for a BIOS bug. Some bootloaders do
kaf24@8402 503 * not write e820 map entries into pre-zeroed memory. This is
kaf24@8402 504 * okay if the BIOS fills in all fields of the map entry, but
kaf24@8402 505 * some broken BIOSes do not bother to write the high word of
kaf24@8402 506 * the length field if the length is smaller than 4GB. We
kaf24@8402 507 * detect and fix this by flagging sections below 4GB that
kaf24@8403 508 * appear to be larger than 4GB in size.
kaf24@8402 509 */
kaf24@8403 510 if ( (map->base_addr_high == 0) && (map->length_high != 0) )
kaf24@8402 511 {
kfraser@15292 512 if ( !e820_warn )
kfraser@15292 513 {
kfraser@15292 514 printk("WARNING: Buggy e820 map detected and fixed "
kfraser@15292 515 "(truncated length fields).\n");
kfraser@15292 516 e820_warn = 1;
kfraser@15292 517 }
kaf24@8402 518 map->length_high = 0;
kaf24@8402 519 }
kaf24@8402 520
kaf24@3344 521 e820_raw[e820_raw_nr].addr =
kaf24@3344 522 ((u64)map->base_addr_high << 32) | (u64)map->base_addr_low;
kaf24@3344 523 e820_raw[e820_raw_nr].size =
kaf24@3344 524 ((u64)map->length_high << 32) | (u64)map->length_low;
kaf24@3344 525 e820_raw[e820_raw_nr].type =
kfraser@12226 526 (map->type > E820_NVS) ? E820_RESERVED : map->type;
kaf24@3344 527 e820_raw_nr++;
kaf24@8402 528
kaf24@3344 529 bytes += map->size + 4;
kaf24@3344 530 }
kaf24@3344 531 }
kaf24@3344 532 else if ( mbi->flags & MBI_MEMLIMITS )
kaf24@3344 533 {
kfraser@15293 534 memmap_type = "Multiboot-e801";
kaf24@3344 535 e820_raw[0].addr = 0;
kaf24@3344 536 e820_raw[0].size = mbi->mem_lower << 10;
kaf24@3344 537 e820_raw[0].type = E820_RAM;
kaf24@3354 538 e820_raw[1].addr = 0x100000;
kaf24@3354 539 e820_raw[1].size = mbi->mem_upper << 10;
kaf24@3354 540 e820_raw[1].type = E820_RAM;
kaf24@3344 541 e820_raw_nr = 2;
kaf24@3344 542 }
kaf24@3344 543 else
kaf24@3344 544 {
kfraser@15074 545 EARLY_FAIL("Bootloader provided no memory information.\n");
kaf24@3344 546 }
kaf24@3344 547
kaf24@13427 548 /* Ensure that all E820 RAM regions are page-aligned and -sized. */
kaf24@13427 549 for ( i = 0; i < e820_raw_nr; i++ )
kaf24@13427 550 {
kaf24@13427 551 uint64_t s, e;
kfraser@15292 552
kaf24@13427 553 if ( e820_raw[i].type != E820_RAM )
kaf24@13427 554 continue;
kaf24@13427 555 s = PFN_UP(e820_raw[i].addr);
kaf24@13427 556 e = PFN_DOWN(e820_raw[i].addr + e820_raw[i].size);
kaf24@13427 557 e820_raw[i].size = 0; /* discarded later */
kaf24@13427 558 if ( s < e )
kaf24@13427 559 {
kaf24@13427 560 e820_raw[i].addr = s << PAGE_SHIFT;
kaf24@13427 561 e820_raw[i].size = (e - s) << PAGE_SHIFT;
kaf24@13427 562 }
kaf24@13427 563 }
kaf24@13427 564
kaf24@13427 565 /* Sanitise the raw E820 map to produce a final clean version. */
kfraser@15293 566 max_page = init_e820(memmap_type, e820_raw, &e820_raw_nr);
kaf24@3338 567
kfraser@15074 568 /*
kfraser@15074 569 * Create a temporary copy of the E820 map. Truncate it to above 16MB
kfraser@15074 570 * as anything below that is already mapped and has a statically-allocated
kfraser@15074 571 * purpose.
kfraser@15074 572 */
kfraser@15074 573 memcpy(&boot_e820, &e820, sizeof(e820));
kfraser@15074 574 for ( i = 0; i < boot_e820.nr_map; i++ )
kaf24@3338 575 {
kfraser@15074 576 uint64_t s, e, min = 16 << 20; /* 16MB */
kfraser@15074 577 s = boot_e820.map[i].addr;
kfraser@15074 578 e = boot_e820.map[i].addr + boot_e820.map[i].size;
kfraser@15074 579 if ( s >= min )
kfraser@15074 580 continue;
kfraser@15074 581 if ( e > min )
kaf24@6111 582 {
kfraser@15074 583 boot_e820.map[i].addr = min;
kfraser@15074 584 boot_e820.map[i].size = e - min;
kaf24@6111 585 }
kfraser@15074 586 else
kfraser@15074 587 boot_e820.map[i].type = E820_RESERVED;
kaf24@3338 588 }
kaf24@6111 589
kfraser@15074 590 /*
keir@15077 591 * Iterate backwards over all superpage-aligned RAM regions.
kfraser@15074 592 *
kfraser@15074 593 * We require superpage alignment because the boot allocator is not yet
kfraser@15074 594 * initialised. Hence we can only map superpages in the address range
kfraser@15074 595 * 0 to BOOTSTRAP_DIRECTMAP_END, as this is guaranteed not to require
kfraser@15074 596 * dynamic allocation of pagetables.
kfraser@15074 597 *
kfraser@15074 598 * As well as mapping superpages in that range, in preparation for
kfraser@15074 599 * initialising the boot allocator, we also look for a region to which
kfraser@15074 600 * we can relocate the dom0 kernel and other multiboot modules. Also, on
kfraser@15074 601 * x86/64, we relocate Xen to higher memory.
kfraser@15074 602 */
kfraser@15074 603 modules_length = mod[mbi->mods_count-1].mod_end - mod[0].mod_start;
keir@15077 604 for ( i = boot_e820.nr_map-1; i >= 0; i-- )
kfraser@15074 605 {
kfraser@15074 606 uint64_t s, e, mask = (1UL << L2_PAGETABLE_SHIFT) - 1;
kaf24@6134 607
kfraser@15074 608 /* Superpage-aligned chunks up to BOOTSTRAP_DIRECTMAP_END, please. */
kfraser@15074 609 s = (boot_e820.map[i].addr + mask) & ~mask;
kfraser@15074 610 e = (boot_e820.map[i].addr + boot_e820.map[i].size) & ~mask;
kfraser@15074 611 e = min_t(uint64_t, e, BOOTSTRAP_DIRECTMAP_END);
kfraser@15074 612 if ( (boot_e820.map[i].type != E820_RAM) || (s >= e) )
kaf24@3354 613 continue;
kaf24@6111 614
kfraser@15074 615 /* Map the chunk. No memory will need to be allocated to do this. */
kfraser@15074 616 map_pages_to_xen(
kfraser@15074 617 (unsigned long)maddr_to_bootstrap_virt(s),
kfraser@15074 618 s >> PAGE_SHIFT, (e-s) >> PAGE_SHIFT, PAGE_HYPERVISOR);
kaf24@6111 619
kfraser@14084 620 #if defined(CONFIG_X86_64)
kfraser@15074 621 /* Is the region suitable for relocating Xen? */
kfraser@15074 622 if ( !xen_phys_start && (((e-s) >> 20) >= opt_xenheap_megabytes) )
kaf24@5003 623 {
kfraser@15074 624 extern l2_pgentry_t l2_xenmap[];
kfraser@15074 625 l4_pgentry_t *pl4e;
kfraser@15074 626 l3_pgentry_t *pl3e;
kfraser@15074 627 l2_pgentry_t *pl2e;
kfraser@15074 628 int i, j;
kfraser@15074 629
kfraser@15074 630 /* Select relocation address. */
kfraser@15074 631 e = (e - (opt_xenheap_megabytes << 20)) & ~mask;
kfraser@15074 632 xen_phys_start = e;
kfraser@15292 633 bootsym(trampoline_xen_phys_start) = e;
kfraser@15074 634
kfraser@15074 635 /*
kfraser@15074 636 * Perform relocation to new physical address.
kfraser@15074 637 * Before doing so we must sync static/global data with main memory
kfraser@15074 638 * with a barrier(). After this we must *not* modify static/global
kfraser@15074 639 * data until after we have switched to the relocated pagetables!
kfraser@15074 640 */
kfraser@15074 641 barrier();
kfraser@15074 642 move_memory(e, 0, __pa(&_end) - xen_phys_start);
kfraser@15074 643
kfraser@15074 644 /* Walk initial pagetables, relocating page directory entries. */
kfraser@15074 645 pl4e = __va(__pa(idle_pg_table));
kfraser@15074 646 for ( i = 0 ; i < L4_PAGETABLE_ENTRIES; i++, pl4e++ )
kfraser@15074 647 {
kfraser@15074 648 if ( !(l4e_get_flags(*pl4e) & _PAGE_PRESENT) )
kfraser@15074 649 continue;
kfraser@15074 650 *pl4e = l4e_from_intpte(l4e_get_intpte(*pl4e) +
kfraser@15074 651 xen_phys_start);
kfraser@15074 652 pl3e = l4e_to_l3e(*pl4e);
kfraser@15074 653 for ( j = 0; j < L3_PAGETABLE_ENTRIES; j++, pl3e++ )
kfraser@15074 654 {
kfraser@15074 655 /* Not present or already relocated? */
kfraser@15074 656 if ( !(l3e_get_flags(*pl3e) & _PAGE_PRESENT) ||
kfraser@15074 657 (l3e_get_pfn(*pl3e) > 0x1000) )
kfraser@15074 658 continue;
kfraser@15074 659 *pl3e = l3e_from_intpte(l3e_get_intpte(*pl3e) +
kfraser@15074 660 xen_phys_start);
kfraser@15074 661 }
kfraser@15074 662 }
kfraser@15074 663
kfraser@15074 664 /* The only data mappings to be relocated are in the Xen area. */
kfraser@15074 665 pl2e = __va(__pa(l2_xenmap));
kfraser@15074 666 for ( i = 0; i < L2_PAGETABLE_ENTRIES; i++, pl2e++ )
kfraser@15074 667 {
kfraser@15074 668 if ( !(l2e_get_flags(*pl2e) & _PAGE_PRESENT) )
kfraser@15074 669 continue;
kfraser@15074 670 *pl2e = l2e_from_intpte(l2e_get_intpte(*pl2e) +
kfraser@15074 671 xen_phys_start);
kfraser@15074 672 }
kfraser@15074 673
kfraser@15074 674 /* Re-sync the stack and then switch to relocated pagetables. */
kfraser@15074 675 asm volatile (
kfraser@15074 676 "rep movsb ; " /* re-sync the stack */
kfraser@15074 677 "movq %%cr4,%%rsi ; "
kfraser@15074 678 "andb $0x7f,%%sil ; "
kfraser@15074 679 "movq %%rsi,%%cr4 ; " /* CR4.PGE == 0 */
kfraser@15074 680 "movq %0,%%cr3 ; " /* CR3 == new pagetables */
kfraser@15074 681 "orb $0x80,%%sil ; "
kfraser@15074 682 "movq %%rsi,%%cr4 " /* CR4.PGE == 1 */
kfraser@15074 683 : : "r" (__pa(idle_pg_table)), "S" (cpu0_stack),
kfraser@15074 684 "D" (__va(__pa(cpu0_stack))), "c" (STACK_SIZE) : "memory" );
kaf24@5003 685 }
kaf24@5003 686 #endif
keir@15077 687
keir@15077 688 /* Is the region suitable for relocating the multiboot modules? */
keir@15077 689 if ( !initial_images_start && (s < e) && ((e-s) >= modules_length) )
keir@15077 690 {
keir@15077 691 e -= modules_length;
keir@15077 692 initial_images_start = e;
keir@15077 693 initial_images_end = initial_images_start + modules_length;
keir@15077 694 move_memory(initial_images_start,
keir@15077 695 mod[0].mod_start, mod[mbi->mods_count-1].mod_end);
keir@15077 696 }
kaf24@3354 697 }
kaf24@3354 698
kfraser@15074 699 if ( !initial_images_start )
kfraser@15074 700 EARLY_FAIL("Not enough memory to relocate the dom0 kernel image.\n");
kfraser@15074 701 reserve_in_boot_e820(initial_images_start, initial_images_end);
kfraser@15074 702
kfraser@15074 703 /*
kfraser@15074 704 * With modules (and Xen itself, on x86/64) relocated out of the way, we
kfraser@15074 705 * can now initialise the boot allocator with some memory.
kfraser@15074 706 */
kfraser@15074 707 xenheap_phys_start = init_boot_allocator(__pa(&_end));
kfraser@15074 708 xenheap_phys_end = opt_xenheap_megabytes << 20;
kfraser@15074 709 #if defined(CONFIG_X86_64)
kfraser@15074 710 if ( !xen_phys_start )
kfraser@15074 711 EARLY_FAIL("Not enough memory to relocate Xen.\n");
kfraser@15074 712 xenheap_phys_end += xen_phys_start;
kfraser@15074 713 reserve_in_boot_e820(xen_phys_start,
kfraser@15074 714 xen_phys_start + (opt_xenheap_megabytes<<20));
kfraser@15074 715 init_boot_pages(1<<20, 16<<20); /* Initial seed: 15MB */
kfraser@15074 716 #else
kfraser@15074 717 init_boot_pages(xenheap_phys_end, 16<<20); /* Initial seed: 4MB */
kfraser@15074 718 #endif
kfraser@15074 719
kfraser@15074 720 /*
kfraser@15074 721 * With the boot allocator now seeded, we can walk every RAM region and
kfraser@15074 722 * map it in its entirety (on x86/64, at least) and notify it to the
kfraser@15074 723 * boot allocator.
kfraser@15074 724 */
kfraser@15074 725 for ( i = 0; i < boot_e820.nr_map; i++ )
kfraser@15074 726 {
kfraser@15074 727 uint64_t s, e, map_e, mask = PAGE_SIZE - 1;
kfraser@15074 728
kfraser@15074 729 /* Only page alignment required now. */
kfraser@15074 730 s = (boot_e820.map[i].addr + mask) & ~mask;
kfraser@15074 731 e = (boot_e820.map[i].addr + boot_e820.map[i].size) & ~mask;
kfraser@15074 732 if ( (boot_e820.map[i].type != E820_RAM) || (s >= e) )
kfraser@15074 733 continue;
kfraser@15074 734
kfraser@15074 735 /* Perform the mapping (truncated in 32-bit mode). */
kfraser@15074 736 map_e = e;
kfraser@15074 737 #if defined(CONFIG_X86_32)
kfraser@15074 738 map_e = min_t(uint64_t, map_e, BOOTSTRAP_DIRECTMAP_END);
kfraser@15074 739 #endif
kfraser@15074 740 if ( s < map_e )
kfraser@15074 741 map_pages_to_xen(
kfraser@15074 742 (unsigned long)maddr_to_bootstrap_virt(s),
kfraser@15074 743 s >> PAGE_SHIFT, (map_e-s) >> PAGE_SHIFT, PAGE_HYPERVISOR);
kfraser@15074 744
kfraser@15074 745 init_boot_pages(s, e);
kfraser@15074 746 }
kfraser@15074 747
kfraser@15074 748 if ( (kexec_crash_area.size > 0) && (kexec_crash_area.start > 0) )
ian@12681 749 {
ian@12677 750 unsigned long kdump_start, kdump_size, k;
ian@12677 751
ian@12681 752 /* Mark images pages as free for now. */
ian@12677 753 init_boot_pages(initial_images_start, initial_images_end);
ian@12677 754
ian@12713 755 kdump_start = kexec_crash_area.start;
ian@12713 756 kdump_size = kexec_crash_area.size;
ian@12677 757
ian@12681 758 printk("Kdump: %luMB (%lukB) at 0x%lx\n",
ian@12677 759 kdump_size >> 20,
ian@12677 760 kdump_size >> 10,
ian@12677 761 kdump_start);
ian@12677 762
ian@12681 763 if ( (kdump_start & ~PAGE_MASK) || (kdump_size & ~PAGE_MASK) )
ian@12677 764 panic("Kdump parameters not page aligned\n");
ian@12677 765
ian@12677 766 kdump_start >>= PAGE_SHIFT;
ian@12677 767 kdump_size >>= PAGE_SHIFT;
ian@12677 768
kfraser@12853 769 /* Allocate pages for Kdump memory area. */
kfraser@14083 770 if ( !reserve_boot_pages(kdump_start, kdump_size) )
ian@12677 771 panic("Unable to reserve Kdump memory\n");
ian@12677 772
kfraser@12853 773 /* Allocate pages for relocated initial images. */
ian@12677 774 k = ((initial_images_end - initial_images_start) & ~PAGE_MASK) ? 1 : 0;
ian@12677 775 k += (initial_images_end - initial_images_start) >> PAGE_SHIFT;
ian@12677 776
kfraser@14084 777 #if defined(CONFIG_X86_32)
kfraser@14084 778 /* Must allocate within bootstrap 1:1 limits. */
kfraser@15074 779 k = alloc_boot_low_pages(k, 1); /* 0x0 - BOOTSTRAP_DIRECTMAP_END */
kfraser@14084 780 #else
kfraser@14084 781 k = alloc_boot_pages(k, 1);
kfraser@14084 782 #endif
kfraser@12853 783 if ( k == 0 )
ian@12677 784 panic("Unable to allocate initial images memory\n");
ian@12677 785
ian@12677 786 move_memory(k << PAGE_SHIFT, initial_images_start, initial_images_end);
ian@12677 787
ian@12677 788 initial_images_end -= initial_images_start;
ian@12677 789 initial_images_start = k << PAGE_SHIFT;
ian@12677 790 initial_images_end += initial_images_start;
ian@12681 791 }
ian@12677 792
kaf24@5003 793 memguard_init();
kaf24@4950 794
kfraser@15074 795 nr_pages = 0;
kfraser@15074 796 for ( i = 0; i < e820.nr_map; i++ )
kfraser@15074 797 if ( e820.map[i].type == E820_RAM )
kfraser@15074 798 nr_pages += e820.map[i].size >> PAGE_SHIFT;
ian@12681 799 printk("System RAM: %luMB (%lukB)\n",
kaf24@3354 800 nr_pages >> (20 - PAGE_SHIFT),
kaf24@3354 801 nr_pages << (PAGE_SHIFT - 10));
kaf24@7220 802 total_pages = nr_pages;
kaf24@3354 803
kfraser@11296 804 /* Sanity check for unwanted bloat of certain hypercall structures. */
kfraser@11296 805 BUILD_BUG_ON(sizeof(((struct xen_platform_op *)0)->u) !=
kfraser@11296 806 sizeof(((struct xen_platform_op *)0)->u.pad));
kfraser@11296 807 BUILD_BUG_ON(sizeof(((struct xen_domctl *)0)->u) !=
kfraser@11296 808 sizeof(((struct xen_domctl *)0)->u.pad));
kfraser@11296 809 BUILD_BUG_ON(sizeof(((struct xen_sysctl *)0)->u) !=
kfraser@11296 810 sizeof(((struct xen_sysctl *)0)->u.pad));
kaf24@7388 811
kaf24@9878 812 BUILD_BUG_ON(sizeof(start_info_t) > PAGE_SIZE);
kaf24@9878 813 BUILD_BUG_ON(sizeof(shared_info_t) > PAGE_SIZE);
ack@13292 814 BUILD_BUG_ON(sizeof(struct vcpu_info) != 64);
kaf24@7744 815
ack@13291 816 #ifdef CONFIG_COMPAT
ack@13291 817 BUILD_BUG_ON(sizeof(((struct compat_platform_op *)0)->u) !=
ack@13291 818 sizeof(((struct compat_platform_op *)0)->u.pad));
ack@13291 819 BUILD_BUG_ON(sizeof(start_info_compat_t) > PAGE_SIZE);
ack@13292 820 BUILD_BUG_ON(sizeof(struct compat_vcpu_info) != 64);
ack@13291 821 #endif
ack@13291 822
kfraser@10492 823 /* Check definitions in public headers match internal defs. */
kaf24@9878 824 BUILD_BUG_ON(__HYPERVISOR_VIRT_START != HYPERVISOR_VIRT_START);
kaf24@8521 825 #ifdef HYPERVISOR_VIRT_END
kaf24@9878 826 BUILD_BUG_ON(__HYPERVISOR_VIRT_END != HYPERVISOR_VIRT_END);
kaf24@8521 827 #endif
kfraser@10492 828 BUILD_BUG_ON(MACH2PHYS_VIRT_START != RO_MPT_VIRT_START);
kfraser@10492 829 BUILD_BUG_ON(MACH2PHYS_VIRT_END != RO_MPT_VIRT_END);
kaf24@8521 830
kaf24@3354 831 init_frametable();
kaf24@3338 832
kfraser@11971 833 acpi_boot_table_init();
kfraser@11971 834
kfraser@11971 835 acpi_numa_init();
kfraser@11971 836
kfraser@11971 837 numa_initmem_init(0, max_page);
kfraser@11971 838
kaf24@6111 839 /* Initialise the Xen heap, skipping RAM holes. */
kfraser@15074 840 init_xenheap_pages(xenheap_phys_start, xenheap_phys_end);
kfraser@15074 841 nr_pages = (xenheap_phys_end - xenheap_phys_start) >> PAGE_SHIFT;
kfraser@15074 842 #ifdef __x86_64__
kfraser@15074 843 init_xenheap_pages(xen_phys_start, __pa(&_start));
kfraser@15074 844 nr_pages += (__pa(&_start) - xen_phys_start) >> PAGE_SHIFT;
kfraser@15074 845 #endif
kfraser@15074 846 xenheap_phys_start = xen_phys_start;
kaf24@6111 847 printk("Xen heap: %luMB (%lukB)\n",
kaf24@6111 848 nr_pages >> (20 - PAGE_SHIFT),
kaf24@6111 849 nr_pages << (PAGE_SHIFT - 10));
kaf24@3338 850
keir@14680 851 end_boot_allocator();
keir@14680 852
kaf24@3594 853 early_boot = 0;
kaf24@3338 854
kaf24@8459 855 early_cpu_init();
kaf24@8459 856
kaf24@8459 857 paging_init();
kaf24@8459 858
kaf24@8459 859 /* Unmap the first page of CPU0's stack. */
kaf24@8459 860 memguard_guard_stack(cpu0_stack);
kaf24@8459 861
kaf24@8459 862 open_softirq(NEW_TLBFLUSH_CLOCK_PERIOD_SOFTIRQ, new_tlbflush_clock_period);
kaf24@8459 863
kaf24@8459 864 if ( opt_watchdog )
kaf24@8459 865 nmi_watchdog = NMI_LOCAL_APIC;
kaf24@8459 866
kaf24@8459 867 sort_exception_tables();
kaf24@8459 868
kaf24@8459 869 find_smp_config();
kaf24@8459 870
kaf24@8459 871 dmi_scan_machine();
kaf24@8459 872
kaf24@8459 873 generic_apic_probe();
kaf24@8459 874
kaf24@8459 875 acpi_boot_init();
kaf24@8459 876
kfraser@11971 877 init_cpu_to_node();
kfraser@11971 878
kfraser@11241 879 if ( smp_found_config )
kaf24@8459 880 get_smp_config();
kaf24@8459 881
keir@15083 882 #ifdef CONFIG_X86_64
keir@15083 883 /* Low mappings were only needed for some BIOS table parsing. */
keir@15083 884 zap_low_mappings();
keir@15083 885 #endif
keir@15083 886
kaf24@8459 887 init_apic_mappings();
kaf24@8459 888
kaf24@8459 889 init_IRQ();
kaf24@8459 890
kfraser@11241 891 percpu_init_areas();
kfraser@11241 892
kfraser@11240 893 init_idle_domain();
kfraser@11240 894
kaf24@8459 895 trap_init();
kaf24@8459 896
kaf24@13662 897 rcu_init();
kaf24@13662 898
kaf24@8586 899 timer_init();
kaf24@8459 900
kaf24@8459 901 early_time_init();
kaf24@8459 902
kaf24@8459 903 arch_init_memory();
kaf24@8459 904
kaf24@8459 905 identify_cpu(&boot_cpu_data);
kaf24@8459 906 if ( cpu_has_fxsr )
kaf24@8459 907 set_in_cr4(X86_CR4_OSFXSR);
kaf24@8459 908 if ( cpu_has_xmm )
kaf24@8459 909 set_in_cr4(X86_CR4_OSXMMEXCPT);
kaf24@8459 910
kaf24@8459 911 if ( opt_nosmp )
kaf24@8459 912 max_cpus = 0;
kaf24@8459 913
kaf24@8459 914 smp_prepare_cpus(max_cpus);
kaf24@8459 915
kaf24@8459 916 /*
kaf24@8459 917 * Initialise higher-level timer functions. We do this fairly late
kaf24@8459 918 * (post-SMP) because the time bases and scale factors need to be updated
kaf24@8459 919 * regularly, and SMP initialisation can cause a long delay with
kaf24@8459 920 * interrupts not yet enabled.
kaf24@8459 921 */
kaf24@8459 922 init_xen_time();
kaf24@8459 923
kaf24@8459 924 initialize_keytable();
kaf24@8459 925
kaf24@8459 926 serial_init_postirq();
kaf24@8459 927
kaf24@8459 928 BUG_ON(!local_irq_is_enabled());
kaf24@8459 929
kaf24@8459 930 for_each_present_cpu ( i )
kaf24@8459 931 {
kaf24@8459 932 if ( num_online_cpus() >= max_cpus )
kaf24@8459 933 break;
kaf24@8459 934 if ( !cpu_online(i) )
kaf24@13662 935 {
kaf24@13662 936 rcu_online_cpu(i);
kaf24@8459 937 __cpu_up(i);
kaf24@13662 938 }
kfraser@11971 939
kfraser@11998 940 /* Set up cpu_to_node[]. */
kfraser@11971 941 srat_detect_node(i);
kfraser@11998 942 /* Set up node_to_cpumask based on cpu_to_node[]. */
kfraser@11971 943 numa_add_cpu(i);
kaf24@8459 944 }
kaf24@8459 945
kaf24@8459 946 printk("Brought up %ld CPUs\n", (long)num_online_cpus());
kaf24@8459 947 smp_cpus_done(max_cpus);
kaf24@8459 948
kaf24@9117 949 initialise_gdb(); /* could be moved earlier */
kaf24@9117 950
kaf24@8459 951 do_initcalls();
kaf24@8459 952
kaf24@8594 953 if ( opt_watchdog )
kaf24@8594 954 watchdog_enable();
kaf24@8459 955
kfraser@11881 956 /* Extract policy from multiboot. */
kfraser@11881 957 extract_acm_policy(mbi, &initrdidx, &_policy_start, &_policy_len);
kfraser@11881 958
kaf24@8459 959 /* initialize access control security module */
kfraser@11881 960 acm_init(_policy_start, _policy_len);
kaf24@8459 961
kaf24@8459 962 /* Create initial domain 0. */
kfraser@14911 963 dom0 = domain_create(0, 0, DOM0_SSIDREF);
kfraser@10655 964 if ( (dom0 == NULL) || (alloc_vcpu(dom0, 0, 0) == NULL) )
kaf24@8459 965 panic("Error creating domain 0\n");
kaf24@8459 966
kfraser@12210 967 dom0->is_privileged = 1;
kfraser@12210 968
kaf24@8459 969 /* Grab the DOM0 command line. */
kaf24@8459 970 cmdline = (char *)(mod[0].string ? __va(mod[0].string) : NULL);
kaf24@8459 971 if ( cmdline != NULL )
kaf24@8459 972 {
kaf24@8459 973 static char dom0_cmdline[MAX_GUEST_CMDLINE];
kaf24@8459 974
kaf24@8459 975 /* Skip past the image name and copy to a local buffer. */
kaf24@8459 976 while ( *cmdline == ' ' ) cmdline++;
kaf24@8459 977 if ( (cmdline = strchr(cmdline, ' ')) != NULL )
kaf24@8459 978 {
kaf24@8459 979 while ( *cmdline == ' ' ) cmdline++;
kfraser@13689 980 safe_strcpy(dom0_cmdline, cmdline);
kaf24@8459 981 }
kaf24@8459 982
kaf24@8459 983 /* Append any extra parameters. */
kfraser@13691 984 if ( skip_ioapic_setup && !strstr(dom0_cmdline, "noapic") )
kfraser@13691 985 safe_strcat(dom0_cmdline, " noapic");
kaf24@8459 986 if ( acpi_skip_timer_override &&
kfraser@13691 987 !strstr(dom0_cmdline, "acpi_skip_timer_override") )
kfraser@13691 988 safe_strcat(dom0_cmdline, " acpi_skip_timer_override");
kfraser@13691 989 if ( (strlen(acpi_param) != 0) && !strstr(dom0_cmdline, "acpi=") )
kaf24@8459 990 {
kfraser@13691 991 safe_strcat(dom0_cmdline, " acpi=");
kfraser@13691 992 safe_strcat(dom0_cmdline, acpi_param);
kaf24@8459 993 }
kfraser@13691 994
kfraser@13691 995 cmdline = dom0_cmdline;
kaf24@8459 996 }
kaf24@8459 997
kaf24@8459 998 if ( (initrdidx > 0) && (initrdidx < mbi->mods_count) )
kaf24@8459 999 {
kaf24@8459 1000 _initrd_start = initial_images_start +
kaf24@8459 1001 (mod[initrdidx].mod_start - mod[0].mod_start);
kaf24@8459 1002 _initrd_len = mod[initrdidx].mod_end - mod[initrdidx].mod_start;
kaf24@8459 1003 }
kaf24@8459 1004
kaf24@8459 1005 /*
kaf24@8459 1006 * We're going to setup domain0 using the module(s) that we stashed safely
kaf24@8459 1007 * above our heap. The second module, if present, is an initrd ramdisk.
kaf24@8459 1008 */
kaf24@8459 1009 if ( construct_dom0(dom0,
kaf24@8459 1010 initial_images_start,
kaf24@8459 1011 mod[0].mod_end-mod[0].mod_start,
kaf24@8459 1012 _initrd_start,
kaf24@8459 1013 _initrd_len,
kaf24@8459 1014 cmdline) != 0)
kaf24@8459 1015 panic("Could not set up DOM0 guest OS\n");
kaf24@8459 1016
kaf24@8459 1017 /* Scrub RAM that is still free and so may go to an unprivileged domain. */
kaf24@8459 1018 scrub_heap_pages();
kaf24@8459 1019
kaf24@8459 1020 init_trace_bufs();
kaf24@8459 1021
kaf24@10502 1022 console_endboot();
kaf24@8459 1023
kaf24@8459 1024 /* Hide UART from DOM0 if we're using it */
kaf24@8459 1025 serial_endboot();
kaf24@8459 1026
kaf24@8459 1027 domain_unpause_by_systemcontroller(dom0);
kaf24@8459 1028
keir@15082 1029 reset_stack_and_jump(init_done);
kaf24@8459 1030 }
kaf24@8459 1031
ian@13763 1032 void arch_get_xen_caps(xen_capabilities_info_t *info)
iap10@6721 1033 {
kfraser@14997 1034 /* Interface name is always xen-3.0-* for Xen-3.x. */
kfraser@14997 1035 int major = 3, minor = 0;
keir@13754 1036 char s[32];
keir@13754 1037
ian@13763 1038 (*info)[0] = '\0';
iap10@6721 1039
kaf24@6725 1040 #if defined(CONFIG_X86_32) && !defined(CONFIG_X86_PAE)
kaf24@6725 1041
keir@13754 1042 snprintf(s, sizeof(s), "xen-%d.%d-x86_32 ", major, minor);
ian@13763 1043 safe_strcat(*info, s);
keir@13754 1044 if ( hvm_enabled )
keir@13754 1045 {
keir@13754 1046 snprintf(s, sizeof(s), "hvm-%d.%d-x86_32 ", major, minor);
ian@13763 1047 safe_strcat(*info, s);
kfraser@13685 1048 }
kaf24@6725 1049
kaf24@6725 1050 #elif defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
kaf24@6725 1051
keir@13754 1052 snprintf(s, sizeof(s), "xen-%d.%d-x86_32p ", major, minor);
ian@13763 1053 safe_strcat(*info, s);
kaf24@6725 1054 if ( hvm_enabled )
iap10@6721 1055 {
keir@13754 1056 snprintf(s, sizeof(s), "hvm-%d.%d-x86_32 ", major, minor);
ian@13763 1057 safe_strcat(*info, s);
keir@13754 1058 snprintf(s, sizeof(s), "hvm-%d.%d-x86_32p ", major, minor);
ian@13763 1059 safe_strcat(*info, s);
iap10@6721 1060 }
iap10@6721 1061
kaf24@6725 1062 #elif defined(CONFIG_X86_64)
iap10@6721 1063
keir@13754 1064 snprintf(s, sizeof(s), "xen-%d.%d-x86_64 ", major, minor);
ian@13763 1065 safe_strcat(*info, s);
ack@13288 1066 #ifdef CONFIG_COMPAT
keir@13754 1067 snprintf(s, sizeof(s), "xen-%d.%d-x86_32p ", major, minor);
ian@13763 1068 safe_strcat(*info, s);
ack@13288 1069 #endif
kaf24@6725 1070 if ( hvm_enabled )
iap10@6721 1071 {
keir@13754 1072 snprintf(s, sizeof(s), "hvm-%d.%d-x86_32 ", major, minor);
ian@13763 1073 safe_strcat(*info, s);
keir@13754 1074 snprintf(s, sizeof(s), "hvm-%d.%d-x86_32p ", major, minor);
ian@13763 1075 safe_strcat(*info, s);
keir@13754 1076 snprintf(s, sizeof(s), "hvm-%d.%d-x86_64 ", major, minor);
ian@13763 1077 safe_strcat(*info, s);
iap10@6721 1078 }
kaf24@6725 1079
iap10@6721 1080 #endif
iap10@6721 1081 }
iap10@6721 1082
kaf24@3914 1083 /*
kaf24@3914 1084 * Local variables:
kaf24@3914 1085 * mode: C
kaf24@3914 1086 * c-set-style: "BSD"
kaf24@3914 1087 * c-basic-offset: 4
kaf24@3914 1088 * tab-width: 4
kaf24@3914 1089 * indent-tabs-mode: nil
kaf24@3988 1090 * End:
kaf24@3914 1091 */