ia64/xen-unstable

annotate xen/arch/ia64/xen/xensetup.c @ 15131:26492c6476f0

[IA64] free initmem and add __init and __initdata.

ia64 counter part of xen-unstable.hg 15043:759d924af6d8.
By freeing init area, un/pickle_domain() is broken because
__init_begin < xen_heap_start. This is fixed by introducing xen_pickle_offset.

Signed-off-by: Isaku Yamahata <yamahata@valinux.co.jp>
author Alex Williamson <alex.williamson@hp.com>
date Wed May 23 08:51:42 2007 -0600 (2007-05-23)
parents aeac9a7d97e0
children 90f19b7667f7
rev   line source
djm@6458 1 /******************************************************************************
djm@6458 2 * xensetup.c
djm@6458 3 * Copyright (c) 2004-2005 Hewlett-Packard Co
djm@6458 4 * Dan Magenheimer <dan.magenheimer@hp.com>
djm@6458 5 */
djm@6458 6
djm@6458 7 #include <xen/config.h>
djm@6458 8 #include <xen/lib.h>
djm@6458 9 #include <xen/errno.h>
djm@6458 10 //#include <xen/spinlock.h>
djm@6458 11 #include <xen/multiboot.h>
djm@6458 12 #include <xen/sched.h>
djm@6458 13 #include <xen/mm.h>
djm@6723 14 #include <public/version.h>
kaf24@9117 15 #include <xen/gdbstub.h>
kfraser@10890 16 #include <xen/version.h>
awilliam@9005 17 #include <xen/console.h>
awilliam@10664 18 #include <xen/domain.h>
djm@6458 19 #include <xen/serial.h>
djm@6458 20 #include <xen/trace.h>
kfraser@11718 21 #include <xen/keyhandler.h>
djm@6458 22 #include <asm/meminit.h>
djm@6458 23 #include <asm/page.h>
djm@6458 24 #include <asm/setup.h>
djm@6458 25 #include <xen/string.h>
djm@8475 26 #include <asm/vmx.h>
awilliam@9005 27 #include <linux/efi.h>
awilliam@10445 28 #include <asm/iosapic.h>
awilliam@13479 29 #include <xen/softirq.h>
awilliam@13780 30 #include <xen/rcupdate.h>
keir@14916 31 #include <acm/acm_hooks.h>
djm@6458 32
awilliam@9773 33 unsigned long xenheap_phys_end, total_pages;
djm@6458 34
djm@6458 35 char saved_command_line[COMMAND_LINE_SIZE];
alex@15131 36 char __initdata dom0_command_line[COMMAND_LINE_SIZE];
djm@6458 37
djm@6458 38 cpumask_t cpu_present_map;
djm@6458 39
djm@6458 40 extern unsigned long domain0_ready;
djm@6458 41
djm@6458 42 int find_max_pfn (unsigned long, unsigned long, void *);
djm@6458 43
awilliam@9005 44 /* FIXME: which header these declarations should be there ? */
awilliam@9005 45 extern long is_platform_hp_ski(void);
awilliam@9005 46 extern void early_setup_arch(char **);
awilliam@9005 47 extern void late_setup_arch(char **);
awilliam@9005 48 extern void hpsim_serial_init(void);
awilliam@9005 49 extern void alloc_dom0(void);
awilliam@9005 50 extern void setup_per_cpu_areas(void);
awilliam@9005 51 extern void mem_init(void);
awilliam@9005 52 extern void init_IRQ(void);
awilliam@10157 53 extern void trap_init(void);
awilliam@11639 54 extern void xen_patch_kernel(void);
awilliam@9005 55
djm@6458 56 /* opt_nosmp: If true, secondary processors are ignored. */
awilliam@13063 57 static int opt_nosmp;
djm@6458 58 boolean_param("nosmp", opt_nosmp);
djm@6458 59
djm@6458 60 /* maxcpus: maximum number of CPUs to activate. */
alex@15131 61 static unsigned int __initdata max_cpus = NR_CPUS;
djm@6458 62 integer_param("maxcpus", max_cpus);
djm@6458 63
awilliam@10442 64 /* xencons: if true enable xenconsole input (and irq).
awilliam@10442 65 Note: you have to disable 8250 serials in domains (to avoid use of the
awilliam@10442 66 same resource). */
alex@15131 67 static int __initdata opt_xencons = 1;
awilliam@10698 68 integer_param("xencons", opt_xencons);
awilliam@10442 69
awilliam@10445 70 /* Toggle to allow non-legacy xencons UARTs to run in polling mode */
alex@15131 71 static int __initdata opt_xencons_poll;
awilliam@10445 72 boolean_param("xencons_poll", opt_xencons_poll);
awilliam@10445 73
djm@6458 74 /*
djm@6458 75 * opt_xenheap_megabytes: Size of Xen heap in megabytes, including:
djm@6458 76 * xen image
djm@6458 77 * bootmap bits
djm@6458 78 * xen heap
djm@6458 79 * Note: To allow xenheap size configurable, the prerequisite is
djm@6458 80 * to configure elilo allowing relocation defaultly. Then since
djm@6458 81 * elilo chooses 256M as alignment when relocating, alignment issue
djm@6458 82 * on IPF can be addressed.
djm@6458 83 */
djm@6458 84 unsigned int opt_xenheap_megabytes = XENHEAP_DEFAULT_MB;
djm@6458 85 unsigned long xenheap_size = XENHEAP_DEFAULT_SIZE;
djm@6458 86 extern long running_on_sim;
djm@6458 87 unsigned long xen_pstart;
alex@15131 88 void *xen_pickle_offset __read_mostly;
djm@6458 89
alex@15131 90 static int __init
djm@6458 91 xen_count_pages(u64 start, u64 end, void *arg)
djm@6458 92 {
djm@6458 93 unsigned long *count = arg;
djm@6458 94
djm@6458 95 /* FIXME: do we need consider difference between DMA-usable memory and
djm@6458 96 * normal memory? Seems that HV has no requirement to operate DMA which
djm@6458 97 * is owned by Dom0? */
djm@6458 98 *count += (end - start) >> PAGE_SHIFT;
djm@6458 99 return 0;
djm@6458 100 }
djm@6458 101
djm@6458 102 static void __init do_initcalls(void)
djm@6458 103 {
djm@6458 104 initcall_t *call;
djm@6458 105 for ( call = &__initcall_start; call < &__initcall_end; call++ )
djm@6458 106 (*call)();
djm@6458 107 }
djm@6458 108
djm@6458 109 /*
djm@6458 110 * IPF loader only supports one commaind line currently, for
djm@6458 111 * both xen and guest kernel. This function provides pre-parse
djm@6458 112 * to mixed command line, to split it into two parts.
djm@6458 113 *
djm@6458 114 * User should split the parameters by "--", with strings after
djm@6458 115 * spliter for guest kernel. Missing "--" means whole line belongs
djm@6458 116 * to guest. Example:
djm@6458 117 * "com2=57600,8n1 console=com2 -- console=ttyS1 console=tty
djm@6458 118 * root=/dev/sda3 ro"
djm@6458 119 */
djm@6458 120 static char null[4] = { 0 };
djm@6458 121
alex@15131 122 void __init early_cmdline_parse(char **cmdline_p)
djm@6458 123 {
djm@6458 124 char *guest_cmd;
awilliam@9270 125 static const char * const split = "--";
djm@6458 126
djm@6458 127 if (*cmdline_p == NULL) {
djm@6458 128 *cmdline_p = &null[0];
djm@6458 129 saved_command_line[0] = '\0';
awilliam@9270 130 dom0_command_line[0] = '\0';
djm@6458 131 return;
djm@6458 132 }
djm@6458 133
djm@6458 134 guest_cmd = strstr(*cmdline_p, split);
djm@6458 135 /* If no spliter, whole line is for guest */
djm@6458 136 if (guest_cmd == NULL) {
djm@6458 137 guest_cmd = *cmdline_p;
djm@6458 138 *cmdline_p = &null[0];
djm@6458 139 } else {
djm@6458 140 *guest_cmd = '\0'; /* Split boot parameters for xen and guest */
djm@6458 141 guest_cmd += strlen(split);
djm@6458 142 while (*guest_cmd == ' ') guest_cmd++;
djm@6458 143 }
djm@6458 144
awilliam@9270 145 strlcpy(saved_command_line, *cmdline_p, COMMAND_LINE_SIZE);
awilliam@9270 146 strlcpy(dom0_command_line, guest_cmd, COMMAND_LINE_SIZE);
djm@6458 147 return;
djm@6458 148 }
djm@6458 149
djm@6458 150 struct ns16550_defaults ns16550_com1 = {
djm@6458 151 .data_bits = 8,
djm@6458 152 .parity = 'n',
djm@6458 153 .stop_bits = 1
djm@6458 154 };
djm@6458 155
awilliam@10445 156 unsigned int ns16550_com1_gsi;
awilliam@10445 157 unsigned int ns16550_com1_polarity;
awilliam@10445 158 unsigned int ns16550_com1_trigger;
awilliam@10445 159
djm@6458 160 struct ns16550_defaults ns16550_com2 = {
djm@6458 161 .data_bits = 8,
djm@6458 162 .parity = 'n',
djm@6458 163 .stop_bits = 1
djm@6458 164 };
djm@6458 165
awilliam@9750 166 /* efi_print: print efi table at boot */
alex@15131 167 static int __initdata opt_efi_print;
awilliam@9750 168 boolean_param("efi_print", opt_efi_print);
awilliam@9750 169
awilliam@9750 170 /* print EFI memory map: */
alex@15131 171 static void __init
awilliam@9750 172 efi_print(void)
awilliam@9750 173 {
awilliam@9750 174 void *efi_map_start, *efi_map_end;
awilliam@9750 175 u64 efi_desc_size;
awilliam@9750 176
awilliam@9750 177 efi_memory_desc_t *md;
awilliam@9750 178 void *p;
awilliam@9750 179 int i;
awilliam@9750 180
awilliam@9750 181 if (!opt_efi_print)
awilliam@9750 182 return;
awilliam@9750 183
awilliam@9750 184 efi_map_start = __va(ia64_boot_param->efi_memmap);
awilliam@9750 185 efi_map_end = efi_map_start + ia64_boot_param->efi_memmap_size;
awilliam@9750 186 efi_desc_size = ia64_boot_param->efi_memdesc_size;
awilliam@9750 187
awilliam@9750 188 for (i = 0, p = efi_map_start; p < efi_map_end; ++i, p += efi_desc_size) {
awilliam@9750 189 md = p;
awilliam@11741 190 printk("mem%02u: type=%2u, attr=0x%016lx, range=[0x%016lx-0x%016lx) "
awilliam@11741 191 "(%luMB)\n", i, md->type, md->attribute, md->phys_addr,
awilliam@9750 192 md->phys_addr + (md->num_pages << EFI_PAGE_SHIFT),
awilliam@9750 193 md->num_pages >> (20 - EFI_PAGE_SHIFT));
awilliam@9750 194 }
awilliam@9750 195 }
awilliam@9750 196
awilliam@10270 197 /*
awilliam@10270 198 * These functions are utility functions for getting and
awilliam@10270 199 * testing memory descriptors for allocating the xenheap area.
awilliam@10270 200 */
awilliam@10270 201 static efi_memory_desc_t *
awilliam@10270 202 efi_get_md (unsigned long phys_addr)
awilliam@10270 203 {
awilliam@10270 204 void *efi_map_start, *efi_map_end, *p;
awilliam@10270 205 efi_memory_desc_t *md;
awilliam@10270 206 u64 efi_desc_size;
awilliam@10270 207
awilliam@10270 208 efi_map_start = __va(ia64_boot_param->efi_memmap);
awilliam@10270 209 efi_map_end = efi_map_start + ia64_boot_param->efi_memmap_size;
awilliam@10270 210 efi_desc_size = ia64_boot_param->efi_memdesc_size;
awilliam@10270 211
awilliam@10270 212 for (p = efi_map_start; p < efi_map_end; p += efi_desc_size) {
awilliam@10270 213 md = p;
awilliam@10270 214 if (phys_addr - md->phys_addr < (md->num_pages << EFI_PAGE_SHIFT))
awilliam@10270 215 return md;
awilliam@10270 216 }
awilliam@10270 217 return 0;
awilliam@10270 218 }
awilliam@10270 219
awilliam@10270 220 static int
awilliam@10270 221 is_xenheap_usable_memory(efi_memory_desc_t *md)
awilliam@10270 222 {
awilliam@10270 223 if (!(md->attribute & EFI_MEMORY_WB))
awilliam@10270 224 return 0;
awilliam@10270 225
awilliam@10270 226 switch (md->type) {
awilliam@10270 227 case EFI_LOADER_CODE:
awilliam@10270 228 case EFI_LOADER_DATA:
awilliam@10270 229 case EFI_BOOT_SERVICES_CODE:
awilliam@10270 230 case EFI_BOOT_SERVICES_DATA:
awilliam@10270 231 case EFI_CONVENTIONAL_MEMORY:
awilliam@10270 232 return 1;
awilliam@10270 233 }
awilliam@10270 234 return 0;
awilliam@10270 235 }
awilliam@10270 236
awilliam@10270 237 static inline int
awilliam@10270 238 md_overlaps(efi_memory_desc_t *md, unsigned long phys_addr)
awilliam@10270 239 {
awilliam@10270 240 return (phys_addr - md->phys_addr < (md->num_pages << EFI_PAGE_SHIFT));
awilliam@10270 241 }
awilliam@10270 242
awilliam@10270 243 #define MD_SIZE(md) (md->num_pages << EFI_PAGE_SHIFT)
awilliam@10270 244
alex@15131 245 extern char __init_begin[], __init_end[];
alex@15131 246 static void noinline init_done(void)
alex@15131 247 {
alex@15131 248 memset(__init_begin, 0, __init_end - __init_begin);
alex@15131 249 flush_icache_range((unsigned long)__init_begin, (unsigned long)__init_end);
alex@15131 250 init_xenheap_pages(__pa(__init_begin), __pa(__init_end));
alex@15131 251 printk("Freed %ldkB init memory.\n",
alex@15131 252 (long)(__init_end-__init_begin)>>10);
alex@15131 253
alex@15131 254 startup_cpu_idle_loop();
alex@15131 255 }
alex@15131 256
alex@15131 257 void __init start_kernel(void)
djm@6458 258 {
awilliam@10442 259 char *cmdline;
awilliam@10270 260 unsigned long nr_pages;
djm@7735 261 unsigned long dom0_memory_start, dom0_memory_size;
djm@7735 262 unsigned long dom0_initrd_start, dom0_initrd_size;
awilliam@10270 263 unsigned long md_end, relo_start, relo_end, relo_size = 0;
kaf24@8552 264 struct domain *idle_domain;
awilliam@13434 265 struct vcpu *dom0_vcpu0;
awilliam@10270 266 efi_memory_desc_t *kern_md, *last_md, *md;
alex@15131 267 void *xen_heap_start;
awilliam@9314 268 #ifdef CONFIG_SMP
awilliam@9314 269 int i;
awilliam@9314 270 #endif
djm@6458 271
awilliam@11036 272 /* Be sure the struct shared_info size is <= XSI_SIZE. */
awilliam@11036 273 BUILD_BUG_ON(sizeof(struct shared_info) > XSI_SIZE);
awilliam@11036 274
djm@6458 275 running_on_sim = is_platform_hp_ski();
djm@6458 276 /* Kernel may be relocated by EFI loader */
djm@6458 277 xen_pstart = ia64_tpa(KERNEL_START);
djm@6458 278
awilliam@10442 279 early_setup_arch(&cmdline);
djm@6458 280
djm@6458 281 /* We initialise the serial devices very early so we can get debugging. */
awilliam@13845 282 if (running_on_sim)
awilliam@13845 283 hpsim_serial_init();
djm@6458 284 else {
awilliam@13845 285 ns16550_init(0, &ns16550_com1);
awilliam@13904 286 ns16550_init(1, &ns16550_com2);
djm@6458 287 }
djm@6458 288 serial_init_preirq();
djm@6458 289
djm@6458 290 init_console();
djm@6458 291 set_printk_prefix("(XEN) ");
djm@6458 292
awilliam@10270 293 if (running_on_sim || ia64_boot_param->domain_start == 0 ||
awilliam@10270 294 ia64_boot_param->domain_size == 0) {
awilliam@10270 295 /* This is possible only with the old elilo, which does not support
awilliam@10270 296 a vmm. Fix now, and continue without initrd. */
awilliam@10270 297 printk ("Your elilo is not Xen-aware. Bootparams fixed\n");
awilliam@10270 298 ia64_boot_param->domain_start = ia64_boot_param->initrd_start;
awilliam@10270 299 ia64_boot_param->domain_size = ia64_boot_param->initrd_size;
awilliam@10270 300 ia64_boot_param->initrd_start = 0;
awilliam@10270 301 ia64_boot_param->initrd_size = 0;
awilliam@10270 302 }
awilliam@10270 303
awilliam@11306 304 printk("Xen command line: %s\n", saved_command_line);
djm@6458 305 /* xenheap should be in same TR-covered range with xen image */
djm@6458 306 xenheap_phys_end = xen_pstart + xenheap_size;
djm@6458 307 printk("xen image pstart: 0x%lx, xenheap pend: 0x%lx\n",
awilliam@10270 308 xen_pstart, xenheap_phys_end);
awilliam@10270 309
awilliam@11639 310 xen_patch_kernel();
awilliam@11639 311
awilliam@10270 312 kern_md = md = efi_get_md(xen_pstart);
awilliam@10270 313 md_end = __pa(ia64_imva(&_end));
awilliam@10270 314 relo_start = xenheap_phys_end;
awilliam@10270 315
awilliam@10270 316 /*
awilliam@10270 317 * Scan through the memory descriptors after the kernel
awilliam@10270 318 * image to make sure we have enough room for the xenheap
awilliam@10270 319 * area, pushing out whatever may already be there.
awilliam@10270 320 */
awilliam@10270 321 while (relo_start + relo_size >= md_end) {
awilliam@10270 322 md = efi_get_md(md_end);
awilliam@10270 323
awilliam@10270 324 BUG_ON(!md);
awilliam@10270 325 BUG_ON(!is_xenheap_usable_memory(md));
djm@6458 326
awilliam@10270 327 md_end = md->phys_addr + MD_SIZE(md);
awilliam@10270 328 /*
awilliam@10270 329 * The dom0 kernel or initrd could overlap, reserve space
awilliam@10270 330 * at the end to relocate them later.
awilliam@10270 331 */
awilliam@10270 332 if (md->type == EFI_LOADER_DATA) {
awilliam@10270 333 /* Test for ranges we're not prepared to move */
awilliam@10270 334 BUG_ON(md_overlaps(md, __pa(ia64_boot_param)) ||
awilliam@10270 335 md_overlaps(md, ia64_boot_param->efi_memmap) ||
awilliam@10270 336 md_overlaps(md, ia64_boot_param->command_line));
awilliam@10270 337
awilliam@10270 338 relo_size += MD_SIZE(md);
awilliam@10270 339 /* If range overlaps the end, push out the relocation start */
awilliam@10270 340 if (md_end > relo_start)
awilliam@10270 341 relo_start = md_end;
awilliam@10270 342 }
awilliam@10270 343 }
awilliam@10270 344 last_md = md;
awilliam@10270 345 relo_end = relo_start + relo_size;
djm@6458 346
awilliam@10270 347 md_end = __pa(ia64_imva(&_end));
awilliam@10270 348
awilliam@10270 349 /*
awilliam@10270 350 * Move any relocated data out into the previously found relocation
awilliam@10270 351 * area. Any extra memory descriptrs are moved out to the end
awilliam@10270 352 * and set to zero pages.
awilliam@10270 353 */
awilliam@10270 354 for (md = efi_get_md(md_end) ;; md = efi_get_md(md_end)) {
awilliam@10270 355 md_end = md->phys_addr + MD_SIZE(md);
awilliam@10270 356
awilliam@10270 357 if (md->type == EFI_LOADER_DATA) {
awilliam@10270 358 unsigned long relo_offset;
awilliam@10270 359
awilliam@10270 360 if (md_overlaps(md, ia64_boot_param->domain_start)) {
awilliam@10270 361 relo_offset = ia64_boot_param->domain_start - md->phys_addr;
awilliam@10270 362 printk("Moving Dom0 kernel image: 0x%lx -> 0x%lx (%ld KiB)\n",
awilliam@10270 363 ia64_boot_param->domain_start, relo_start + relo_offset,
awilliam@10270 364 ia64_boot_param->domain_size >> 10);
awilliam@10270 365 ia64_boot_param->domain_start = relo_start + relo_offset;
awilliam@10270 366 }
awilliam@10270 367 if (ia64_boot_param->initrd_size &&
awilliam@10270 368 md_overlaps(md, ia64_boot_param->initrd_start)) {
awilliam@10270 369 relo_offset = ia64_boot_param->initrd_start - md->phys_addr;
awilliam@10270 370 printk("Moving Dom0 initrd image: 0x%lx -> 0x%lx (%ld KiB)\n",
awilliam@10270 371 ia64_boot_param->initrd_start, relo_start + relo_offset,
awilliam@10270 372 ia64_boot_param->initrd_size >> 10);
awilliam@10270 373 ia64_boot_param->initrd_start = relo_start + relo_offset;
awilliam@10270 374 }
awilliam@10270 375 memcpy(__va(relo_start), __va(md->phys_addr), MD_SIZE(md));
awilliam@10270 376 relo_start += MD_SIZE(md);
awilliam@10270 377 }
awilliam@10270 378
awilliam@10270 379 if (md == kern_md)
awilliam@10270 380 continue;
awilliam@10270 381 if (md == last_md)
awilliam@10270 382 break;
awilliam@10270 383
awilliam@10270 384 md->phys_addr = relo_end;
awilliam@10270 385 md->num_pages = 0;
djm@7735 386 }
djm@7735 387
awilliam@10270 388 /* Trim the last entry */
awilliam@10270 389 md->phys_addr = relo_end;
awilliam@10270 390 md->num_pages = (md_end - relo_end) >> EFI_PAGE_SHIFT;
djm@6458 391
awilliam@10270 392 /*
awilliam@10270 393 * Expand the new kernel/xenheap (and maybe dom0/initrd) out to
awilliam@10270 394 * the full size. This range will already be type EFI_LOADER_DATA,
awilliam@10270 395 * therefore the xenheap area is now protected being allocated for
awilliam@10270 396 * use by find_memmap_space() in efi.c
awilliam@10270 397 */
awilliam@10270 398 kern_md->num_pages = (relo_end - kern_md->phys_addr) >> EFI_PAGE_SHIFT;
djm@7735 399
awilliam@10270 400 reserve_memory();
djm@6458 401
djm@6458 402 /* first find highest page frame number */
djm@6458 403 max_page = 0;
djm@6458 404 efi_memmap_walk(find_max_pfn, &max_page);
kfraser@11947 405 printk("find_memory: efi_memmap_walk returns max_page=%lx\n",max_page);
awilliam@9750 406 efi_print();
alex@15131 407
alex@15131 408 /*
alex@15131 409 * later [__init_begin, __init_end) will be freed up as xen heap
alex@15131 410 * so that struct domain might be allocated from the init area
alex@15131 411 * which is < xen_heap_start. so we can't simply set
alex@15131 412 * xen_pickle_offset = xen_heap_start.
alex@15131 413 */
alex@15131 414 xen_pickle_offset = ia64_imva(__init_begin);
djm@6458 415
awilliam@11606 416 xen_heap_start = memguard_init(ia64_imva(&_end));
awilliam@11961 417 printk("Before xen_heap_start: %p\n", xen_heap_start);
awilliam@11606 418 xen_heap_start = __va(init_boot_allocator(__pa(xen_heap_start)));
awilliam@11961 419 printk("After xen_heap_start: %p\n", xen_heap_start);
djm@6458 420
djm@6458 421 efi_memmap_walk(filter_rsvd_memory, init_boot_pages);
djm@6458 422 efi_memmap_walk(xen_count_pages, &nr_pages);
djm@6458 423
djm@6458 424 printk("System RAM: %luMB (%lukB)\n",
djm@6458 425 nr_pages >> (20 - PAGE_SHIFT),
djm@6458 426 nr_pages << (PAGE_SHIFT - 10));
awilliam@9773 427 total_pages = nr_pages;
djm@6458 428
djm@6458 429 init_frametable();
djm@6458 430
awilliam@10157 431 trap_init();
awilliam@10157 432
djm@6458 433 alloc_dom0();
djm@6458 434
djm@6458 435 end_boot_allocator();
djm@6458 436
awilliam@11606 437 init_xenheap_pages(__pa(xen_heap_start), xenheap_phys_end);
djm@6458 438 printk("Xen heap: %luMB (%lukB)\n",
awilliam@11606 439 (xenheap_phys_end-__pa(xen_heap_start)) >> 20,
awilliam@11606 440 (xenheap_phys_end-__pa(xen_heap_start)) >> 10);
djm@6458 441
kaf24@11019 442 late_setup_arch(&cmdline);
kaf24@11019 443
kaf24@8552 444 scheduler_init();
kaf24@8552 445 idle_vcpu[0] = (struct vcpu*) ia64_r13;
kfraser@14911 446 idle_domain = domain_create(IDLE_DOMAIN_ID, 0, 0);
kfraser@10655 447 if ( (idle_domain == NULL) || (alloc_vcpu(idle_domain, 0, 0) == NULL) )
kfraser@10655 448 BUG();
kaf24@8552 449
awilliam@10151 450 alloc_dom_xen_and_dom_io();
djm@6458 451 setup_per_cpu_areas();
djm@6458 452 mem_init();
djm@6458 453
djm@6458 454 local_irq_disable();
djm@7332 455 init_IRQ ();
djm@6458 456 init_xen_time(); /* initialise the time */
kaf24@8586 457 timer_init();
djm@6458 458
awilliam@13667 459 rcu_init();
awilliam@13667 460
awilliam@13479 461 #ifdef CONFIG_XEN_IA64_TLBFLUSH_CLOCK
awilliam@13479 462 open_softirq(NEW_TLBFLUSH_CLOCK_PERIOD_SOFTIRQ, new_tlbflush_clock_period);
awilliam@13479 463 #endif
awilliam@13479 464
djm@6458 465 #ifdef CONFIG_SMP
djm@6458 466 if ( opt_nosmp )
djm@6458 467 {
djm@6458 468 max_cpus = 0;
djm@6458 469 smp_num_siblings = 1;
djm@6458 470 //boot_cpu_data.x86_num_cores = 1;
djm@6458 471 }
djm@6458 472
awilliam@9495 473 /* A vcpu is created for the idle domain on every physical cpu.
awilliam@9495 474 Limit the number of cpus to the maximum number of vcpus. */
awilliam@9495 475 if (max_cpus > MAX_VIRT_CPUS)
awilliam@9495 476 max_cpus = MAX_VIRT_CPUS;
awilliam@9495 477
djm@6458 478 smp_prepare_cpus(max_cpus);
awilliam@9495 479
djm@6458 480 /* We aren't hotplug-capable yet. */
djm@6458 481 for_each_cpu ( i )
djm@6458 482 cpu_set(i, cpu_present_map);
djm@6458 483
djm@7332 484 /* Enable IRQ to receive IPI (needed for ITC sync). */
djm@7332 485 local_irq_enable();
djm@7332 486
djm@6458 487 printk("num_online_cpus=%d, max_cpus=%d\n",num_online_cpus(),max_cpus);
djm@6458 488 for_each_present_cpu ( i )
djm@6458 489 {
djm@6458 490 if ( num_online_cpus() >= max_cpus )
djm@6458 491 break;
djm@6458 492 if ( !cpu_online(i) ) {
awilliam@13667 493 rcu_online_cpu(i);
djm@6458 494 __cpu_up(i);
djm@6458 495 }
djm@6458 496 }
djm@6458 497
djm@7332 498 local_irq_disable();
djm@7332 499
djm@6458 500 printk("Brought up %ld CPUs\n", (long)num_online_cpus());
djm@6458 501 smp_cpus_done(max_cpus);
djm@6458 502 #endif
djm@6458 503
kaf24@9117 504 initialise_gdb(); /* could be moved earlier */
kaf24@9117 505
djm@6458 506 do_initcalls();
djm@6458 507 sort_main_extable();
djm@6458 508
awilliam@9685 509 init_rid_allocator ();
awilliam@9685 510
awilliam@10442 511 local_irq_enable();
awilliam@10442 512
awilliam@10442 513 if (opt_xencons) {
awilliam@10445 514 initialize_keytable();
awilliam@10445 515 if (ns16550_com1_gsi) {
awilliam@10445 516 if (opt_xencons_poll ||
awilliam@10445 517 iosapic_register_intr(ns16550_com1_gsi,
awilliam@10445 518 ns16550_com1_polarity,
awilliam@10445 519 ns16550_com1_trigger) < 0) {
awilliam@10445 520 ns16550_com1.irq = 0;
awilliam@10445 521 ns16550_init(0, &ns16550_com1);
awilliam@10445 522 }
awilliam@10445 523 }
awilliam@10445 524 serial_init_postirq();
awilliam@10445 525
awilliam@10445 526 /* Hide the HCDP table from dom0 */
awilliam@10445 527 efi.hcdp = NULL;
awilliam@10442 528 }
awilliam@9685 529
awilliam@11726 530 expose_p2m_init();
awilliam@11726 531
djm@6458 532 /* Create initial domain 0. */
kfraser@14911 533 dom0 = domain_create(0, 0, DOM0_SSIDREF);
awilliam@13434 534 if (dom0 == NULL)
djm@6458 535 panic("Error creating domain 0\n");
awilliam@13434 536 dom0_vcpu0 = alloc_vcpu(dom0, 0, 0);
awilliam@13434 537 if (dom0_vcpu0 == NULL || vcpu_late_initialise(dom0_vcpu0) != 0)
awilliam@13434 538 panic("Cannot allocate dom0 vcpu 0\n");
djm@6458 539
kfraser@12210 540 dom0->is_privileged = 1;
djm@6458 541
djm@6458 542 /*
djm@6458 543 * We're going to setup domain0 using the module(s) that we stashed safely
djm@6458 544 * above our heap. The second module, if present, is an initrd ramdisk.
djm@6458 545 */
awilliam@10270 546 dom0_memory_start = (unsigned long) __va(ia64_boot_param->domain_start);
djm@7735 547 dom0_memory_size = ia64_boot_param->domain_size;
awilliam@9864 548 dom0_initrd_start = (unsigned long) __va(ia64_boot_param->initrd_start);
djm@7735 549 dom0_initrd_size = ia64_boot_param->initrd_size;
djm@7735 550
djm@7735 551 if ( construct_dom0(dom0, dom0_memory_start, dom0_memory_size,
djm@7735 552 dom0_initrd_start,dom0_initrd_size,
djm@7735 553 0) != 0)
djm@6458 554 panic("Could not set up DOM0 guest OS\n");
djm@7332 555
djm@6458 556 if (!running_on_sim) // slow on ski and pages are pre-initialized to zero
djm@6458 557 scrub_heap_pages();
djm@6458 558
djm@6458 559 init_trace_bufs();
djm@6458 560
awilliam@10934 561 if (opt_xencons) {
awilliam@10513 562 console_endboot();
awilliam@10934 563 serial_endboot();
awilliam@10934 564 }
djm@6458 565
djm@7332 566 domain0_ready = 1;
djm@7332 567
djm@6458 568 domain_unpause_by_systemcontroller(dom0);
djm@7332 569
alex@15131 570 init_done();
djm@6458 571 }
djm@6723 572
ian@13763 573 void arch_get_xen_caps(xen_capabilities_info_t *info)
djm@6723 574 {
kfraser@14997 575 /* Interface name is always xen-3.0-* for Xen-3.x. */
kfraser@14997 576 int major = 3, minor = 0;
keir@13754 577 char s[32];
djm@6723 578
ian@13763 579 (*info)[0] = '\0';
keir@13754 580
ian@13763 581 snprintf(s, sizeof(s), "xen-%d.%d-ia64 ", major, minor);
ian@13763 582 safe_strcat(*info, s);
djm@6723 583
awilliam@14037 584 snprintf(s, sizeof(s), "xen-%d.%d-ia64be ", major, minor);
awilliam@14037 585 safe_strcat(*info, s);
awilliam@14037 586
djm@8475 587 if (vmx_enabled)
keir@13754 588 {
keir@13754 589 snprintf(s, sizeof(s), "hvm-%d.%d-ia64 ", major, minor);
ian@13763 590 safe_strcat(*info, s);
keir@13754 591 }
djm@6723 592 }
djm@6723 593