ia64/xen-unstable

view xen/arch/ia64/xen/xensetup.c @ 10293:4122e88b6c75

Move idle-vcpu allocation logic to a common function.
Signed-off-by: Kevin Tian <kevin.tian@intel.com>
author kaf24@firebug.cl.cam.ac.uk
date Fri Jun 02 09:31:35 2006 +0100 (2006-06-02)
parents faae893d428e
children e74c47d073ee
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/spinlock.h>
11 #include <xen/multiboot.h>
12 #include <xen/sched.h>
13 #include <xen/mm.h>
14 #include <public/version.h>
15 #include <xen/gdbstub.h>
16 #include <xen/compile.h>
17 #include <xen/console.h>
18 #include <xen/serial.h>
19 #include <xen/trace.h>
20 #include <asm/meminit.h>
21 #include <asm/page.h>
22 #include <asm/setup.h>
23 #include <xen/string.h>
24 #include <asm/vmx.h>
25 #include <linux/efi.h>
27 /* Be sure the struct shared_info fits on a page because it is mapped in
28 domain. */
29 #if SHARED_INFO_SIZE > PAGE_SIZE
30 #error "struct shared_info does not not fit in PAGE_SIZE"
31 #endif
33 unsigned long xenheap_phys_end, total_pages;
35 char saved_command_line[COMMAND_LINE_SIZE];
36 char dom0_command_line[COMMAND_LINE_SIZE];
38 cpumask_t cpu_present_map;
40 extern unsigned long domain0_ready;
42 int find_max_pfn (unsigned long, unsigned long, void *);
43 void start_of_day(void);
45 /* FIXME: which header these declarations should be there ? */
46 extern long is_platform_hp_ski(void);
47 extern void early_setup_arch(char **);
48 extern void late_setup_arch(char **);
49 extern void hpsim_serial_init(void);
50 extern void alloc_dom0(void);
51 extern void setup_per_cpu_areas(void);
52 extern void mem_init(void);
53 extern void init_IRQ(void);
54 extern void trap_init(void);
56 /* opt_nosmp: If true, secondary processors are ignored. */
57 static int opt_nosmp = 0;
58 boolean_param("nosmp", opt_nosmp);
60 /* maxcpus: maximum number of CPUs to activate. */
61 static unsigned int max_cpus = NR_CPUS;
62 integer_param("maxcpus", max_cpus);
64 /*
65 * opt_xenheap_megabytes: Size of Xen heap in megabytes, including:
66 * xen image
67 * bootmap bits
68 * xen heap
69 * Note: To allow xenheap size configurable, the prerequisite is
70 * to configure elilo allowing relocation defaultly. Then since
71 * elilo chooses 256M as alignment when relocating, alignment issue
72 * on IPF can be addressed.
73 */
74 unsigned int opt_xenheap_megabytes = XENHEAP_DEFAULT_MB;
75 unsigned long xenheap_size = XENHEAP_DEFAULT_SIZE;
76 extern long running_on_sim;
77 unsigned long xen_pstart;
79 static int
80 xen_count_pages(u64 start, u64 end, void *arg)
81 {
82 unsigned long *count = arg;
84 /* FIXME: do we need consider difference between DMA-usable memory and
85 * normal memory? Seems that HV has no requirement to operate DMA which
86 * is owned by Dom0? */
87 *count += (end - start) >> PAGE_SHIFT;
88 return 0;
89 }
91 /* Find first hole after trunk for xen image */
92 static int
93 xen_find_first_hole(u64 start, u64 end, void *arg)
94 {
95 unsigned long *first_hole = arg;
97 if ((*first_hole) == 0) {
98 if ((start <= KERNEL_START) && (KERNEL_START < end))
99 *first_hole = __pa(end);
100 }
102 return 0;
103 }
105 static void __init do_initcalls(void)
106 {
107 initcall_t *call;
108 for ( call = &__initcall_start; call < &__initcall_end; call++ )
109 (*call)();
110 }
112 /*
113 * IPF loader only supports one commaind line currently, for
114 * both xen and guest kernel. This function provides pre-parse
115 * to mixed command line, to split it into two parts.
116 *
117 * User should split the parameters by "--", with strings after
118 * spliter for guest kernel. Missing "--" means whole line belongs
119 * to guest. Example:
120 * "com2=57600,8n1 console=com2 -- console=ttyS1 console=tty
121 * root=/dev/sda3 ro"
122 */
123 static char null[4] = { 0 };
125 void early_cmdline_parse(char **cmdline_p)
126 {
127 char *guest_cmd;
128 static const char * const split = "--";
130 if (*cmdline_p == NULL) {
131 *cmdline_p = &null[0];
132 saved_command_line[0] = '\0';
133 dom0_command_line[0] = '\0';
134 return;
135 }
137 guest_cmd = strstr(*cmdline_p, split);
138 /* If no spliter, whole line is for guest */
139 if (guest_cmd == NULL) {
140 guest_cmd = *cmdline_p;
141 *cmdline_p = &null[0];
142 } else {
143 *guest_cmd = '\0'; /* Split boot parameters for xen and guest */
144 guest_cmd += strlen(split);
145 while (*guest_cmd == ' ') guest_cmd++;
146 }
148 strlcpy(saved_command_line, *cmdline_p, COMMAND_LINE_SIZE);
149 strlcpy(dom0_command_line, guest_cmd, COMMAND_LINE_SIZE);
150 return;
151 }
153 struct ns16550_defaults ns16550_com1 = {
154 .baud = BAUD_AUTO,
155 .data_bits = 8,
156 .parity = 'n',
157 .stop_bits = 1
158 };
160 struct ns16550_defaults ns16550_com2 = {
161 .baud = BAUD_AUTO,
162 .data_bits = 8,
163 .parity = 'n',
164 .stop_bits = 1
165 };
167 /* efi_print: print efi table at boot */
168 static int opt_efi_print = 0;
169 boolean_param("efi_print", opt_efi_print);
171 /* print EFI memory map: */
172 static void
173 efi_print(void)
174 {
175 void *efi_map_start, *efi_map_end;
176 u64 efi_desc_size;
178 efi_memory_desc_t *md;
179 void *p;
180 int i;
182 if (!opt_efi_print)
183 return;
185 efi_map_start = __va(ia64_boot_param->efi_memmap);
186 efi_map_end = efi_map_start + ia64_boot_param->efi_memmap_size;
187 efi_desc_size = ia64_boot_param->efi_memdesc_size;
189 for (i = 0, p = efi_map_start; p < efi_map_end; ++i, p += efi_desc_size) {
190 md = p;
191 printk("mem%02u: type=%u, attr=0x%lx, range=[0x%016lx-0x%016lx) (%luMB)\n",
192 i, md->type, md->attribute, md->phys_addr,
193 md->phys_addr + (md->num_pages << EFI_PAGE_SHIFT),
194 md->num_pages >> (20 - EFI_PAGE_SHIFT));
195 }
196 }
198 void start_kernel(void)
199 {
200 unsigned char *cmdline;
201 void *heap_start;
202 unsigned long nr_pages, firsthole_start;
203 unsigned long dom0_memory_start, dom0_memory_size;
204 unsigned long dom0_initrd_start, dom0_initrd_size;
205 unsigned long initial_images_start, initial_images_end;
206 struct domain *idle_domain;
207 #ifdef CONFIG_SMP
208 int i;
209 #endif
211 running_on_sim = is_platform_hp_ski();
212 /* Kernel may be relocated by EFI loader */
213 xen_pstart = ia64_tpa(KERNEL_START);
215 early_setup_arch((char **) &cmdline);
217 /* We initialise the serial devices very early so we can get debugging. */
218 if (running_on_sim) hpsim_serial_init();
219 else {
220 ns16550_init(0, &ns16550_com1);
221 /* Also init com2 for Tiger4. */
222 ns16550_com2.io_base = 0x2f8;
223 ns16550_com2.irq = 3;
224 ns16550_init(1, &ns16550_com2);
225 }
226 serial_init_preirq();
228 init_console();
229 set_printk_prefix("(XEN) ");
231 /* xenheap should be in same TR-covered range with xen image */
232 xenheap_phys_end = xen_pstart + xenheap_size;
233 printk("xen image pstart: 0x%lx, xenheap pend: 0x%lx\n",
234 xen_pstart, xenheap_phys_end);
236 /* Find next hole */
237 firsthole_start = 0;
238 efi_memmap_walk(xen_find_first_hole, &firsthole_start);
240 if (running_on_sim || ia64_boot_param->domain_start == 0
241 || ia64_boot_param->domain_size == 0) {
242 /* This is possible only with the old elilo, which does not support
243 a vmm. Fix now, and continue without initrd. */
244 printk ("Your elilo is not Xen-aware. Bootparams fixed\n");
245 ia64_boot_param->domain_start = ia64_boot_param->initrd_start;
246 ia64_boot_param->domain_size = ia64_boot_param->initrd_size;
247 ia64_boot_param->initrd_start = 0;
248 ia64_boot_param->initrd_size = 0;
249 }
251 initial_images_start = xenheap_phys_end;
252 initial_images_end = initial_images_start +
253 PAGE_ALIGN(ia64_boot_param->domain_size);
255 /* also reserve space for initrd */
256 if (ia64_boot_param->initrd_start && ia64_boot_param->initrd_size)
257 initial_images_end += PAGE_ALIGN(ia64_boot_param->initrd_size);
258 else {
259 /* sanity cleanup */
260 ia64_boot_param->initrd_size = 0;
261 ia64_boot_param->initrd_start = 0;
262 }
265 /* Later may find another memory trunk, even away from xen image... */
266 if (initial_images_end > firsthole_start) {
267 printk("Not enough memory to stash the DOM0 kernel image.\n");
268 printk("First hole:0x%lx, relocation end: 0x%lx\n",
269 firsthole_start, initial_images_end);
270 for ( ; ; );
271 }
273 /* This copy is time consuming, but elilo may load Dom0 image
274 * within xenheap range */
275 printk("ready to move Dom0 to 0x%lx with len %lx...", initial_images_start,
276 ia64_boot_param->domain_size);
278 memmove(__va(initial_images_start),
279 __va(ia64_boot_param->domain_start),
280 ia64_boot_param->domain_size);
281 ia64_boot_param->domain_start = initial_images_start;
283 printk("ready to move initrd to 0x%lx with len %lx...",
284 initial_images_start+PAGE_ALIGN(ia64_boot_param->domain_size),
285 ia64_boot_param->initrd_size);
286 memmove(__va(initial_images_start+PAGE_ALIGN(ia64_boot_param->domain_size)),
287 __va(ia64_boot_param->initrd_start),
288 ia64_boot_param->initrd_size);
289 printk("Done\n");
290 ia64_boot_param->initrd_start = initial_images_start +
291 PAGE_ALIGN(ia64_boot_param->domain_size);
293 /* first find highest page frame number */
294 max_page = 0;
295 efi_memmap_walk(find_max_pfn, &max_page);
296 printf("find_memory: efi_memmap_walk returns max_page=%lx\n",max_page);
297 #ifndef CONFIG_XEN_IA64_DOM0_VP
298 /* this is a bad hack. see dom_fw.c creation of EFI map for dom0 */
299 max_page = (GRANULEROUNDDOWN(max_page << PAGE_SHIFT)
300 - IA64_GRANULE_SIZE) >> PAGE_SHIFT;
301 printf("find_memory: last granule reserved for dom0; xen max_page=%lx\n",
302 max_page);
303 #endif
304 efi_print();
306 heap_start = memguard_init(ia64_imva(&_end));
307 printf("Before heap_start: %p\n", heap_start);
308 heap_start = __va(init_boot_allocator(__pa(heap_start)));
309 printf("After heap_start: %p\n", heap_start);
311 reserve_memory();
313 efi_memmap_walk(filter_rsvd_memory, init_boot_pages);
314 efi_memmap_walk(xen_count_pages, &nr_pages);
316 printk("System RAM: %luMB (%lukB)\n",
317 nr_pages >> (20 - PAGE_SHIFT),
318 nr_pages << (PAGE_SHIFT - 10));
319 total_pages = nr_pages;
321 init_frametable();
323 trap_init();
325 alloc_dom0();
327 end_boot_allocator();
329 init_xenheap_pages(__pa(heap_start), xenheap_phys_end);
330 printk("Xen heap: %luMB (%lukB)\n",
331 (xenheap_phys_end-__pa(heap_start)) >> 20,
332 (xenheap_phys_end-__pa(heap_start)) >> 10);
334 printk("About to call scheduler_init()\n");
335 scheduler_init();
336 idle_vcpu[0] = (struct vcpu*) ia64_r13;
337 idle_domain = domain_create(IDLE_DOMAIN_ID, 0);
338 BUG_ON(idle_domain == NULL);
340 late_setup_arch((char **) &cmdline);
341 alloc_dom_xen_and_dom_io();
342 setup_per_cpu_areas();
343 mem_init();
345 local_irq_disable();
346 init_IRQ ();
347 printk("About to call init_xen_time()\n");
348 init_xen_time(); /* initialise the time */
349 printk("About to call timer_init()\n");
350 timer_init();
352 #ifdef CONFIG_XEN_CONSOLE_INPUT /* CONFIG_SERIAL_8250_CONSOLE=n in dom0! */
353 initialize_keytable();
354 serial_init_postirq();
355 #endif
357 #ifdef CONFIG_SMP
358 if ( opt_nosmp )
359 {
360 max_cpus = 0;
361 smp_num_siblings = 1;
362 //boot_cpu_data.x86_num_cores = 1;
363 }
365 /* A vcpu is created for the idle domain on every physical cpu.
366 Limit the number of cpus to the maximum number of vcpus. */
367 if (max_cpus > MAX_VIRT_CPUS)
368 max_cpus = MAX_VIRT_CPUS;
370 smp_prepare_cpus(max_cpus);
372 /* We aren't hotplug-capable yet. */
373 for_each_cpu ( i )
374 cpu_set(i, cpu_present_map);
376 /* Enable IRQ to receive IPI (needed for ITC sync). */
377 local_irq_enable();
379 printk("num_online_cpus=%d, max_cpus=%d\n",num_online_cpus(),max_cpus);
380 for_each_present_cpu ( i )
381 {
382 if ( num_online_cpus() >= max_cpus )
383 break;
384 if ( !cpu_online(i) ) {
385 __cpu_up(i);
386 }
387 }
389 local_irq_disable();
391 printk("Brought up %ld CPUs\n", (long)num_online_cpus());
392 smp_cpus_done(max_cpus);
393 #endif
395 initialise_gdb(); /* could be moved earlier */
397 do_initcalls();
398 printk("About to call sort_main_extable()\n");
399 sort_main_extable();
402 init_rid_allocator ();
404 /* Create initial domain 0. */
405 printk("About to call domain_create()\n");
406 dom0 = domain_create(0, 0);
408 if ( dom0 == NULL )
409 panic("Error creating domain 0\n");
411 set_bit(_DOMF_privileged, &dom0->domain_flags);
413 /*
414 * We're going to setup domain0 using the module(s) that we stashed safely
415 * above our heap. The second module, if present, is an initrd ramdisk.
416 */
417 printk("About to call construct_dom0()\n");
418 dom0_memory_start = (unsigned long) __va(initial_images_start);
419 dom0_memory_size = ia64_boot_param->domain_size;
420 dom0_initrd_start = (unsigned long) __va(ia64_boot_param->initrd_start);
421 dom0_initrd_size = ia64_boot_param->initrd_size;
423 if ( construct_dom0(dom0, dom0_memory_start, dom0_memory_size,
424 dom0_initrd_start,dom0_initrd_size,
425 0) != 0)
426 panic("Could not set up DOM0 guest OS\n");
428 /* PIN domain0 on CPU 0. */
429 dom0->vcpu[0]->cpu_affinity = cpumask_of_cpu(0);
431 if (!running_on_sim) // slow on ski and pages are pre-initialized to zero
432 scrub_heap_pages();
434 printk("About to call init_trace_bufs()\n");
435 init_trace_bufs();
437 /* Give up the VGA console if DOM0 is configured to grab it. */
438 #ifdef CONFIG_XEN_CONSOLE_INPUT /* CONFIG_SERIAL_8250_CONSOLE=n in dom0! */
439 console_endboot(cmdline && strstr(cmdline, "tty0"));
440 #endif
442 domain0_ready = 1;
444 local_irq_enable();
446 printf("About to call schedulers_start dom0=%p, idle_dom=%p\n",
447 dom0, &idle_domain);
448 schedulers_start();
450 domain_unpause_by_systemcontroller(dom0);
452 printk("About to call startup_cpu_idle_loop()\n");
453 startup_cpu_idle_loop();
454 }
456 void arch_get_xen_caps(xen_capabilities_info_t info)
457 {
458 char *p=info;
460 p += sprintf(p,"xen-%d.%d-ia64 ", XEN_VERSION, XEN_SUBVERSION);
462 if (vmx_enabled)
463 p += sprintf(p,"hvm-%d.%d-ia64 ", XEN_VERSION, XEN_SUBVERSION);
465 *(p-1) = 0;
467 BUG_ON((p-info)>sizeof(xen_capabilities_info_t));
469 }