ia64/xen-unstable

view xen/arch/ia64/xen/xensetup.c @ 13479:1faf482f119c

[IA64] Register NEW_TLBFLUSH_CLOCK_PERIOD_SOFTIRQ

NEW_TLBFLUSH_CLOCK_PERIOD_SOFTIRQ is used but not registered.
I've never experienced but system will panic in the very long run.

Signed-off-by: Kouya Shimura <kouya@jp.fujitsu.com>
author awilliam@xenbuild2.aw
date Fri Jan 26 14:19:37 2007 -0700 (2007-01-26)
parents 7d8670a30445
children cf0ae8105ffe
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/version.h>
17 #include <xen/console.h>
18 #include <xen/domain.h>
19 #include <xen/serial.h>
20 #include <xen/trace.h>
21 #include <xen/keyhandler.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>
31 unsigned long xenheap_phys_end, total_pages;
33 char saved_command_line[COMMAND_LINE_SIZE];
34 char dom0_command_line[COMMAND_LINE_SIZE];
36 cpumask_t cpu_present_map;
38 extern unsigned long domain0_ready;
40 int find_max_pfn (unsigned long, unsigned long, void *);
42 /* FIXME: which header these declarations should be there ? */
43 extern long is_platform_hp_ski(void);
44 extern void early_setup_arch(char **);
45 extern void late_setup_arch(char **);
46 extern void hpsim_serial_init(void);
47 extern void alloc_dom0(void);
48 extern void setup_per_cpu_areas(void);
49 extern void mem_init(void);
50 extern void init_IRQ(void);
51 extern void trap_init(void);
52 extern void xen_patch_kernel(void);
54 /* opt_nosmp: If true, secondary processors are ignored. */
55 static int opt_nosmp;
56 boolean_param("nosmp", opt_nosmp);
58 /* maxcpus: maximum number of CPUs to activate. */
59 static unsigned int max_cpus = NR_CPUS;
60 integer_param("maxcpus", max_cpus);
62 /* xencons: if true enable xenconsole input (and irq).
63 Note: you have to disable 8250 serials in domains (to avoid use of the
64 same resource). */
65 static int opt_xencons = 1;
66 integer_param("xencons", opt_xencons);
68 /* Toggle to allow non-legacy xencons UARTs to run in polling mode */
69 static int opt_xencons_poll;
70 boolean_param("xencons_poll", opt_xencons_poll);
72 /*
73 * opt_xenheap_megabytes: Size of Xen heap in megabytes, including:
74 * xen image
75 * bootmap bits
76 * xen heap
77 * Note: To allow xenheap size configurable, the prerequisite is
78 * to configure elilo allowing relocation defaultly. Then since
79 * elilo chooses 256M as alignment when relocating, alignment issue
80 * on IPF can be addressed.
81 */
82 unsigned int opt_xenheap_megabytes = XENHEAP_DEFAULT_MB;
83 unsigned long xenheap_size = XENHEAP_DEFAULT_SIZE;
84 extern long running_on_sim;
85 unsigned long xen_pstart;
86 void *xen_heap_start __read_mostly;
88 static int
89 xen_count_pages(u64 start, u64 end, void *arg)
90 {
91 unsigned long *count = arg;
93 /* FIXME: do we need consider difference between DMA-usable memory and
94 * normal memory? Seems that HV has no requirement to operate DMA which
95 * is owned by Dom0? */
96 *count += (end - start) >> PAGE_SHIFT;
97 return 0;
98 }
100 static void __init do_initcalls(void)
101 {
102 initcall_t *call;
103 for ( call = &__initcall_start; call < &__initcall_end; call++ )
104 (*call)();
105 }
107 /*
108 * IPF loader only supports one commaind line currently, for
109 * both xen and guest kernel. This function provides pre-parse
110 * to mixed command line, to split it into two parts.
111 *
112 * User should split the parameters by "--", with strings after
113 * spliter for guest kernel. Missing "--" means whole line belongs
114 * to guest. Example:
115 * "com2=57600,8n1 console=com2 -- console=ttyS1 console=tty
116 * root=/dev/sda3 ro"
117 */
118 static char null[4] = { 0 };
120 void early_cmdline_parse(char **cmdline_p)
121 {
122 char *guest_cmd;
123 static const char * const split = "--";
125 if (*cmdline_p == NULL) {
126 *cmdline_p = &null[0];
127 saved_command_line[0] = '\0';
128 dom0_command_line[0] = '\0';
129 return;
130 }
132 guest_cmd = strstr(*cmdline_p, split);
133 /* If no spliter, whole line is for guest */
134 if (guest_cmd == NULL) {
135 guest_cmd = *cmdline_p;
136 *cmdline_p = &null[0];
137 } else {
138 *guest_cmd = '\0'; /* Split boot parameters for xen and guest */
139 guest_cmd += strlen(split);
140 while (*guest_cmd == ' ') guest_cmd++;
141 }
143 strlcpy(saved_command_line, *cmdline_p, COMMAND_LINE_SIZE);
144 strlcpy(dom0_command_line, guest_cmd, COMMAND_LINE_SIZE);
145 return;
146 }
148 struct ns16550_defaults ns16550_com1 = {
149 .baud = BAUD_AUTO,
150 .data_bits = 8,
151 .parity = 'n',
152 .stop_bits = 1
153 };
155 unsigned int ns16550_com1_gsi;
156 unsigned int ns16550_com1_polarity;
157 unsigned int ns16550_com1_trigger;
159 struct ns16550_defaults ns16550_com2 = {
160 .baud = BAUD_AUTO,
161 .data_bits = 8,
162 .parity = 'n',
163 .stop_bits = 1
164 };
166 /* efi_print: print efi table at boot */
167 static int opt_efi_print;
168 boolean_param("efi_print", opt_efi_print);
170 /* print EFI memory map: */
171 static void
172 efi_print(void)
173 {
174 void *efi_map_start, *efi_map_end;
175 u64 efi_desc_size;
177 efi_memory_desc_t *md;
178 void *p;
179 int i;
181 if (!opt_efi_print)
182 return;
184 efi_map_start = __va(ia64_boot_param->efi_memmap);
185 efi_map_end = efi_map_start + ia64_boot_param->efi_memmap_size;
186 efi_desc_size = ia64_boot_param->efi_memdesc_size;
188 for (i = 0, p = efi_map_start; p < efi_map_end; ++i, p += efi_desc_size) {
189 md = p;
190 printk("mem%02u: type=%2u, attr=0x%016lx, range=[0x%016lx-0x%016lx) "
191 "(%luMB)\n", i, md->type, md->attribute, md->phys_addr,
192 md->phys_addr + (md->num_pages << EFI_PAGE_SHIFT),
193 md->num_pages >> (20 - EFI_PAGE_SHIFT));
194 }
195 }
197 /*
198 * These functions are utility functions for getting and
199 * testing memory descriptors for allocating the xenheap area.
200 */
201 static efi_memory_desc_t *
202 efi_get_md (unsigned long phys_addr)
203 {
204 void *efi_map_start, *efi_map_end, *p;
205 efi_memory_desc_t *md;
206 u64 efi_desc_size;
208 efi_map_start = __va(ia64_boot_param->efi_memmap);
209 efi_map_end = efi_map_start + ia64_boot_param->efi_memmap_size;
210 efi_desc_size = ia64_boot_param->efi_memdesc_size;
212 for (p = efi_map_start; p < efi_map_end; p += efi_desc_size) {
213 md = p;
214 if (phys_addr - md->phys_addr < (md->num_pages << EFI_PAGE_SHIFT))
215 return md;
216 }
217 return 0;
218 }
220 static int
221 is_xenheap_usable_memory(efi_memory_desc_t *md)
222 {
223 if (!(md->attribute & EFI_MEMORY_WB))
224 return 0;
226 switch (md->type) {
227 case EFI_LOADER_CODE:
228 case EFI_LOADER_DATA:
229 case EFI_BOOT_SERVICES_CODE:
230 case EFI_BOOT_SERVICES_DATA:
231 case EFI_CONVENTIONAL_MEMORY:
232 return 1;
233 }
234 return 0;
235 }
237 static inline int
238 md_overlaps(efi_memory_desc_t *md, unsigned long phys_addr)
239 {
240 return (phys_addr - md->phys_addr < (md->num_pages << EFI_PAGE_SHIFT));
241 }
243 #define MD_SIZE(md) (md->num_pages << EFI_PAGE_SHIFT)
245 void start_kernel(void)
246 {
247 char *cmdline;
248 unsigned long nr_pages;
249 unsigned long dom0_memory_start, dom0_memory_size;
250 unsigned long dom0_initrd_start, dom0_initrd_size;
251 unsigned long md_end, relo_start, relo_end, relo_size = 0;
252 struct domain *idle_domain;
253 struct vcpu *dom0_vcpu0;
254 efi_memory_desc_t *kern_md, *last_md, *md;
255 #ifdef CONFIG_SMP
256 int i;
257 #endif
259 /* Be sure the struct shared_info size is <= XSI_SIZE. */
260 BUILD_BUG_ON(sizeof(struct shared_info) > XSI_SIZE);
262 running_on_sim = is_platform_hp_ski();
263 /* Kernel may be relocated by EFI loader */
264 xen_pstart = ia64_tpa(KERNEL_START);
266 early_setup_arch(&cmdline);
268 /* We initialise the serial devices very early so we can get debugging. */
269 if (running_on_sim) hpsim_serial_init();
270 else {
271 ns16550_init(0, &ns16550_com1);
272 /* Also init com2 for Tiger4. */
273 ns16550_com2.io_base = 0x2f8;
274 ns16550_com2.irq = 3;
275 ns16550_init(1, &ns16550_com2);
276 }
277 serial_init_preirq();
279 init_console();
280 set_printk_prefix("(XEN) ");
282 if (running_on_sim || ia64_boot_param->domain_start == 0 ||
283 ia64_boot_param->domain_size == 0) {
284 /* This is possible only with the old elilo, which does not support
285 a vmm. Fix now, and continue without initrd. */
286 printk ("Your elilo is not Xen-aware. Bootparams fixed\n");
287 ia64_boot_param->domain_start = ia64_boot_param->initrd_start;
288 ia64_boot_param->domain_size = ia64_boot_param->initrd_size;
289 ia64_boot_param->initrd_start = 0;
290 ia64_boot_param->initrd_size = 0;
291 }
293 printk("Xen command line: %s\n", saved_command_line);
294 /* xenheap should be in same TR-covered range with xen image */
295 xenheap_phys_end = xen_pstart + xenheap_size;
296 printk("xen image pstart: 0x%lx, xenheap pend: 0x%lx\n",
297 xen_pstart, xenheap_phys_end);
299 xen_patch_kernel();
301 kern_md = md = efi_get_md(xen_pstart);
302 md_end = __pa(ia64_imva(&_end));
303 relo_start = xenheap_phys_end;
305 /*
306 * Scan through the memory descriptors after the kernel
307 * image to make sure we have enough room for the xenheap
308 * area, pushing out whatever may already be there.
309 */
310 while (relo_start + relo_size >= md_end) {
311 md = efi_get_md(md_end);
313 BUG_ON(!md);
314 BUG_ON(!is_xenheap_usable_memory(md));
316 md_end = md->phys_addr + MD_SIZE(md);
317 /*
318 * The dom0 kernel or initrd could overlap, reserve space
319 * at the end to relocate them later.
320 */
321 if (md->type == EFI_LOADER_DATA) {
322 /* Test for ranges we're not prepared to move */
323 BUG_ON(md_overlaps(md, __pa(ia64_boot_param)) ||
324 md_overlaps(md, ia64_boot_param->efi_memmap) ||
325 md_overlaps(md, ia64_boot_param->command_line));
327 relo_size += MD_SIZE(md);
328 /* If range overlaps the end, push out the relocation start */
329 if (md_end > relo_start)
330 relo_start = md_end;
331 }
332 }
333 last_md = md;
334 relo_end = relo_start + relo_size;
336 md_end = __pa(ia64_imva(&_end));
338 /*
339 * Move any relocated data out into the previously found relocation
340 * area. Any extra memory descriptrs are moved out to the end
341 * and set to zero pages.
342 */
343 for (md = efi_get_md(md_end) ;; md = efi_get_md(md_end)) {
344 md_end = md->phys_addr + MD_SIZE(md);
346 if (md->type == EFI_LOADER_DATA) {
347 unsigned long relo_offset;
349 if (md_overlaps(md, ia64_boot_param->domain_start)) {
350 relo_offset = ia64_boot_param->domain_start - md->phys_addr;
351 printk("Moving Dom0 kernel image: 0x%lx -> 0x%lx (%ld KiB)\n",
352 ia64_boot_param->domain_start, relo_start + relo_offset,
353 ia64_boot_param->domain_size >> 10);
354 ia64_boot_param->domain_start = relo_start + relo_offset;
355 }
356 if (ia64_boot_param->initrd_size &&
357 md_overlaps(md, ia64_boot_param->initrd_start)) {
358 relo_offset = ia64_boot_param->initrd_start - md->phys_addr;
359 printk("Moving Dom0 initrd image: 0x%lx -> 0x%lx (%ld KiB)\n",
360 ia64_boot_param->initrd_start, relo_start + relo_offset,
361 ia64_boot_param->initrd_size >> 10);
362 ia64_boot_param->initrd_start = relo_start + relo_offset;
363 }
364 memcpy(__va(relo_start), __va(md->phys_addr), MD_SIZE(md));
365 relo_start += MD_SIZE(md);
366 }
368 if (md == kern_md)
369 continue;
370 if (md == last_md)
371 break;
373 md->phys_addr = relo_end;
374 md->num_pages = 0;
375 }
377 /* Trim the last entry */
378 md->phys_addr = relo_end;
379 md->num_pages = (md_end - relo_end) >> EFI_PAGE_SHIFT;
381 /*
382 * Expand the new kernel/xenheap (and maybe dom0/initrd) out to
383 * the full size. This range will already be type EFI_LOADER_DATA,
384 * therefore the xenheap area is now protected being allocated for
385 * use by find_memmap_space() in efi.c
386 */
387 kern_md->num_pages = (relo_end - kern_md->phys_addr) >> EFI_PAGE_SHIFT;
389 reserve_memory();
391 /* first find highest page frame number */
392 max_page = 0;
393 efi_memmap_walk(find_max_pfn, &max_page);
394 printk("find_memory: efi_memmap_walk returns max_page=%lx\n",max_page);
395 efi_print();
397 xen_heap_start = memguard_init(ia64_imva(&_end));
398 printk("Before xen_heap_start: %p\n", xen_heap_start);
399 xen_heap_start = __va(init_boot_allocator(__pa(xen_heap_start)));
400 printk("After xen_heap_start: %p\n", xen_heap_start);
402 efi_memmap_walk(filter_rsvd_memory, init_boot_pages);
403 efi_memmap_walk(xen_count_pages, &nr_pages);
405 printk("System RAM: %luMB (%lukB)\n",
406 nr_pages >> (20 - PAGE_SHIFT),
407 nr_pages << (PAGE_SHIFT - 10));
408 total_pages = nr_pages;
410 init_frametable();
412 trap_init();
414 alloc_dom0();
416 end_boot_allocator();
418 init_xenheap_pages(__pa(xen_heap_start), xenheap_phys_end);
419 printk("Xen heap: %luMB (%lukB)\n",
420 (xenheap_phys_end-__pa(xen_heap_start)) >> 20,
421 (xenheap_phys_end-__pa(xen_heap_start)) >> 10);
423 late_setup_arch(&cmdline);
425 scheduler_init();
426 idle_vcpu[0] = (struct vcpu*) ia64_r13;
427 idle_domain = domain_create(IDLE_DOMAIN_ID, 0);
428 if ( (idle_domain == NULL) || (alloc_vcpu(idle_domain, 0, 0) == NULL) )
429 BUG();
431 alloc_dom_xen_and_dom_io();
432 setup_per_cpu_areas();
433 mem_init();
435 local_irq_disable();
436 init_IRQ ();
437 init_xen_time(); /* initialise the time */
438 timer_init();
440 #ifdef CONFIG_XEN_IA64_TLBFLUSH_CLOCK
441 open_softirq(NEW_TLBFLUSH_CLOCK_PERIOD_SOFTIRQ, new_tlbflush_clock_period);
442 #endif
444 #ifdef CONFIG_SMP
445 if ( opt_nosmp )
446 {
447 max_cpus = 0;
448 smp_num_siblings = 1;
449 //boot_cpu_data.x86_num_cores = 1;
450 }
452 /* A vcpu is created for the idle domain on every physical cpu.
453 Limit the number of cpus to the maximum number of vcpus. */
454 if (max_cpus > MAX_VIRT_CPUS)
455 max_cpus = MAX_VIRT_CPUS;
457 smp_prepare_cpus(max_cpus);
459 /* We aren't hotplug-capable yet. */
460 for_each_cpu ( i )
461 cpu_set(i, cpu_present_map);
463 /* Enable IRQ to receive IPI (needed for ITC sync). */
464 local_irq_enable();
466 printk("num_online_cpus=%d, max_cpus=%d\n",num_online_cpus(),max_cpus);
467 for_each_present_cpu ( i )
468 {
469 if ( num_online_cpus() >= max_cpus )
470 break;
471 if ( !cpu_online(i) ) {
472 __cpu_up(i);
473 }
474 }
476 local_irq_disable();
478 printk("Brought up %ld CPUs\n", (long)num_online_cpus());
479 smp_cpus_done(max_cpus);
480 #endif
482 initialise_gdb(); /* could be moved earlier */
484 do_initcalls();
485 sort_main_extable();
487 init_rid_allocator ();
489 local_irq_enable();
491 if (opt_xencons) {
492 initialize_keytable();
493 if (ns16550_com1_gsi) {
494 if (opt_xencons_poll ||
495 iosapic_register_intr(ns16550_com1_gsi,
496 ns16550_com1_polarity,
497 ns16550_com1_trigger) < 0) {
498 ns16550_com1.irq = 0;
499 ns16550_init(0, &ns16550_com1);
500 }
501 }
502 serial_init_postirq();
504 /* Hide the HCDP table from dom0 */
505 efi.hcdp = NULL;
506 }
508 expose_p2m_init();
510 /* Create initial domain 0. */
511 dom0 = domain_create(0, 0);
512 if (dom0 == NULL)
513 panic("Error creating domain 0\n");
514 dom0_vcpu0 = alloc_vcpu(dom0, 0, 0);
515 if (dom0_vcpu0 == NULL || vcpu_late_initialise(dom0_vcpu0) != 0)
516 panic("Cannot allocate dom0 vcpu 0\n");
518 dom0->is_privileged = 1;
520 /*
521 * We're going to setup domain0 using the module(s) that we stashed safely
522 * above our heap. The second module, if present, is an initrd ramdisk.
523 */
524 dom0_memory_start = (unsigned long) __va(ia64_boot_param->domain_start);
525 dom0_memory_size = ia64_boot_param->domain_size;
526 dom0_initrd_start = (unsigned long) __va(ia64_boot_param->initrd_start);
527 dom0_initrd_size = ia64_boot_param->initrd_size;
529 if ( construct_dom0(dom0, dom0_memory_start, dom0_memory_size,
530 dom0_initrd_start,dom0_initrd_size,
531 0) != 0)
532 panic("Could not set up DOM0 guest OS\n");
534 if (!running_on_sim) // slow on ski and pages are pre-initialized to zero
535 scrub_heap_pages();
537 init_trace_bufs();
539 if (opt_xencons) {
540 console_endboot();
541 serial_endboot();
542 }
544 domain0_ready = 1;
546 schedulers_start();
548 domain_unpause_by_systemcontroller(dom0);
550 startup_cpu_idle_loop();
551 }
553 void arch_get_xen_caps(xen_capabilities_info_t info)
554 {
555 char *p=info;
556 int major = xen_major_version();
557 int minor = xen_minor_version();
559 p += sprintf(p,"xen-%d.%d-ia64 ", major, minor);
561 if (vmx_enabled)
562 p += sprintf(p,"hvm-%d.%d-ia64 ", major, minor);
564 *(p-1) = 0;
566 BUG_ON((p-info)>sizeof(xen_capabilities_info_t));
568 }