ia64/xen-unstable

view xen/arch/ia64/xen/xensetup.c @ 16785:af3550f53874

[IA64] domheap: Don't pin xenheap down. Now it's unnecessary.

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