ia64/xen-unstable

view xen/arch/ia64/xen/xensetup.c @ 15423:cbf749e9961f

[IA64] Cleanup: Move is_platform_hp_ski() from xenmisc.c to xensetup.c

- only caller is start_kernel
- change to static __init
- also move running_on_sim to xensetup.c, and change it from unsigned
long to int, since it's just a boolean
- declare running_on_sim in config.h near some other externs

Tested by building, booting, starting a PV guest on rx2620.

Signed-off-by: Aron Griffis <aron@hp.com>
author Alex Williamson <alex.williamson@hp.com>
date Mon Jul 02 10:25:29 2007 -0600 (2007-07-02)
parents b46c2ff6dfb0
children 1ef9dc28810d
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 <asm/meminit.h>
22 #include <asm/page.h>
23 #include <asm/setup.h>
24 #include <xen/string.h>
25 #include <asm/vmx.h>
26 #include <linux/efi.h>
27 #include <asm/iosapic.h>
28 #include <xen/softirq.h>
29 #include <xen/rcupdate.h>
30 #include <acm/acm_hooks.h>
31 #include <asm/sn/simulator.h>
33 unsigned long xenheap_phys_end, total_pages;
35 char saved_command_line[COMMAND_LINE_SIZE];
36 char __initdata 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 *);
44 /* FIXME: which header these declarations should be there ? */
45 extern void early_setup_arch(char **);
46 extern void late_setup_arch(char **);
47 extern void hpsim_serial_init(void);
48 extern void alloc_dom0(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 /* opt_nosmp: If true, secondary processors are ignored. */
56 static int 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: if true enable 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 /* Toggle to allow 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 /*
74 * opt_xenheap_megabytes: Size of Xen heap in megabytes, including:
75 * xen image
76 * bootmap bits
77 * xen heap
78 * Note: To allow xenheap size configurable, the prerequisite is
79 * to configure elilo allowing relocation defaultly. Then since
80 * elilo chooses 256M as alignment when relocating, alignment issue
81 * on IPF can be addressed.
82 */
83 unsigned int opt_xenheap_megabytes = XENHEAP_DEFAULT_MB;
84 unsigned long xenheap_size = XENHEAP_DEFAULT_SIZE;
85 unsigned long xen_pstart;
86 void *xen_pickle_offset __read_mostly;
88 static int __init
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 __init 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 .data_bits = 8,
150 .parity = 'n',
151 .stop_bits = 1
152 };
154 unsigned int ns16550_com1_gsi;
155 unsigned int ns16550_com1_polarity;
156 unsigned int ns16550_com1_trigger;
158 struct ns16550_defaults ns16550_com2 = {
159 .data_bits = 8,
160 .parity = 'n',
161 .stop_bits = 1
162 };
164 /* efi_print: print efi table at boot */
165 static int __initdata opt_efi_print;
166 boolean_param("efi_print", opt_efi_print);
168 /* print EFI memory map: */
169 static void __init
170 efi_print(void)
171 {
172 void *efi_map_start, *efi_map_end;
173 u64 efi_desc_size;
175 efi_memory_desc_t *md;
176 void *p;
177 int i;
179 if (!opt_efi_print)
180 return;
182 efi_map_start = __va(ia64_boot_param->efi_memmap);
183 efi_map_end = efi_map_start + ia64_boot_param->efi_memmap_size;
184 efi_desc_size = ia64_boot_param->efi_memdesc_size;
186 for (i = 0, p = efi_map_start; p < efi_map_end; ++i, p += efi_desc_size) {
187 md = p;
188 printk("mem%02u: type=%2u, attr=0x%016lx, range=[0x%016lx-0x%016lx) "
189 "(%luMB)\n", i, md->type, md->attribute, md->phys_addr,
190 md->phys_addr + (md->num_pages << EFI_PAGE_SHIFT),
191 md->num_pages >> (20 - EFI_PAGE_SHIFT));
192 }
193 }
195 /*
196 * These functions are utility functions for getting and
197 * testing memory descriptors for allocating the xenheap area.
198 */
199 static efi_memory_desc_t *
200 efi_get_md (unsigned long phys_addr)
201 {
202 void *efi_map_start, *efi_map_end, *p;
203 efi_memory_desc_t *md;
204 u64 efi_desc_size;
206 efi_map_start = __va(ia64_boot_param->efi_memmap);
207 efi_map_end = efi_map_start + ia64_boot_param->efi_memmap_size;
208 efi_desc_size = ia64_boot_param->efi_memdesc_size;
210 for (p = efi_map_start; p < efi_map_end; p += efi_desc_size) {
211 md = p;
212 if (phys_addr - md->phys_addr < (md->num_pages << EFI_PAGE_SHIFT))
213 return md;
214 }
215 return 0;
216 }
218 static int
219 is_xenheap_usable_memory(efi_memory_desc_t *md)
220 {
221 if (!(md->attribute & EFI_MEMORY_WB))
222 return 0;
224 switch (md->type) {
225 case EFI_LOADER_CODE:
226 case EFI_LOADER_DATA:
227 case EFI_BOOT_SERVICES_CODE:
228 case EFI_BOOT_SERVICES_DATA:
229 case EFI_CONVENTIONAL_MEMORY:
230 return 1;
231 }
232 return 0;
233 }
235 static inline int
236 md_overlaps(efi_memory_desc_t *md, unsigned long phys_addr)
237 {
238 return (phys_addr - md->phys_addr < (md->num_pages << EFI_PAGE_SHIFT));
239 }
241 #define MD_SIZE(md) (md->num_pages << EFI_PAGE_SHIFT)
243 extern char __init_begin[], __init_end[];
244 static void noinline init_done(void)
245 {
246 memset(__init_begin, 0, __init_end - __init_begin);
247 flush_icache_range((unsigned long)__init_begin, (unsigned long)__init_end);
248 init_xenheap_pages(__pa(__init_begin), __pa(__init_end));
249 printk("Freed %ldkB init memory.\n",
250 (long)(__init_end-__init_begin)>>10);
252 startup_cpu_idle_loop();
253 }
255 int running_on_sim;
257 static int __init
258 is_platform_hp_ski(void)
259 {
260 int i;
261 long cpuid[6];
263 for (i = 0; i < 5; ++i)
264 cpuid[i] = ia64_get_cpuid(i);
266 if ((cpuid[0] & 0xff) != 'H')
267 return 0;
268 if ((cpuid[3] & 0xff) != 0x4)
269 return 0;
270 if (((cpuid[3] >> 8) & 0xff) != 0x0)
271 return 0;
272 if (((cpuid[3] >> 16) & 0xff) != 0x0)
273 return 0;
274 if (((cpuid[3] >> 24) & 0x7) != 0x7)
275 return 0;
277 return 1;
278 }
280 void __init start_kernel(void)
281 {
282 char *cmdline;
283 unsigned long nr_pages;
284 unsigned long dom0_memory_start, dom0_memory_size;
285 unsigned long dom0_initrd_start, dom0_initrd_size;
286 unsigned long md_end, relo_start, relo_end, relo_size = 0;
287 struct domain *idle_domain;
288 struct vcpu *dom0_vcpu0;
289 efi_memory_desc_t *kern_md, *last_md, *md;
290 void *xen_heap_start;
291 #ifdef CONFIG_SMP
292 int i;
293 #endif
295 /* Be sure the struct shared_info size is <= XSI_SIZE. */
296 BUILD_BUG_ON(sizeof(struct shared_info) > XSI_SIZE);
298 /* Kernel may be relocated by EFI loader */
299 xen_pstart = ia64_tpa(KERNEL_START);
301 running_on_sim = is_platform_hp_ski();
303 early_setup_arch(&cmdline);
305 /* We initialise the serial devices very early so we can get debugging. */
306 if (running_on_sim)
307 hpsim_serial_init();
308 else {
309 ns16550_init(0, &ns16550_com1);
310 ns16550_init(1, &ns16550_com2);
311 }
312 serial_init_preirq();
314 init_console();
315 set_printk_prefix("(XEN) ");
317 if (running_on_sim || ia64_boot_param->domain_start == 0 ||
318 ia64_boot_param->domain_size == 0) {
319 /* This is possible only with the old elilo, which does not support
320 a vmm. Fix now, and continue without initrd. */
321 printk ("Your elilo is not Xen-aware. Bootparams fixed\n");
322 ia64_boot_param->domain_start = ia64_boot_param->initrd_start;
323 ia64_boot_param->domain_size = ia64_boot_param->initrd_size;
324 ia64_boot_param->initrd_start = 0;
325 ia64_boot_param->initrd_size = 0;
326 }
328 printk("Xen command line: %s\n", saved_command_line);
329 /* xenheap should be in same TR-covered range with xen image */
330 xenheap_phys_end = xen_pstart + xenheap_size;
331 printk("xen image pstart: 0x%lx, xenheap pend: 0x%lx\n",
332 xen_pstart, xenheap_phys_end);
334 xen_patch_kernel();
336 kern_md = md = efi_get_md(xen_pstart);
337 md_end = __pa(ia64_imva(&_end));
338 relo_start = xenheap_phys_end;
340 /*
341 * Scan through the memory descriptors after the kernel
342 * image to make sure we have enough room for the xenheap
343 * area, pushing out whatever may already be there.
344 */
345 while (relo_start + relo_size >= md_end) {
346 md = efi_get_md(md_end);
348 BUG_ON(!md);
349 BUG_ON(!is_xenheap_usable_memory(md));
351 md_end = md->phys_addr + MD_SIZE(md);
352 /*
353 * The dom0 kernel or initrd could overlap, reserve space
354 * at the end to relocate them later.
355 */
356 if (md->type == EFI_LOADER_DATA) {
357 /* Test for ranges we're not prepared to move */
358 BUG_ON(md_overlaps(md, __pa(ia64_boot_param)) ||
359 md_overlaps(md, ia64_boot_param->efi_memmap) ||
360 md_overlaps(md, ia64_boot_param->command_line));
362 relo_size += MD_SIZE(md);
363 /* If range overlaps the end, push out the relocation start */
364 if (md_end > relo_start)
365 relo_start = md_end;
366 }
367 }
368 last_md = md;
369 relo_end = relo_start + relo_size;
371 md_end = __pa(ia64_imva(&_end));
373 /*
374 * Move any relocated data out into the previously found relocation
375 * area. Any extra memory descriptrs are moved out to the end
376 * and set to zero pages.
377 */
378 for (md = efi_get_md(md_end) ;; md = efi_get_md(md_end)) {
379 md_end = md->phys_addr + MD_SIZE(md);
381 if (md->type == EFI_LOADER_DATA) {
382 unsigned long relo_offset;
384 if (md_overlaps(md, ia64_boot_param->domain_start)) {
385 relo_offset = ia64_boot_param->domain_start - md->phys_addr;
386 printk("Moving Dom0 kernel image: 0x%lx -> 0x%lx (%ld KiB)\n",
387 ia64_boot_param->domain_start, relo_start + relo_offset,
388 ia64_boot_param->domain_size >> 10);
389 ia64_boot_param->domain_start = relo_start + relo_offset;
390 }
391 if (ia64_boot_param->initrd_size &&
392 md_overlaps(md, ia64_boot_param->initrd_start)) {
393 relo_offset = ia64_boot_param->initrd_start - md->phys_addr;
394 printk("Moving Dom0 initrd image: 0x%lx -> 0x%lx (%ld KiB)\n",
395 ia64_boot_param->initrd_start, relo_start + relo_offset,
396 ia64_boot_param->initrd_size >> 10);
397 ia64_boot_param->initrd_start = relo_start + relo_offset;
398 }
399 memcpy(__va(relo_start), __va(md->phys_addr), MD_SIZE(md));
400 relo_start += MD_SIZE(md);
401 }
403 if (md == kern_md)
404 continue;
405 if (md == last_md)
406 break;
408 md->phys_addr = relo_end;
409 md->num_pages = 0;
410 }
412 /* Trim the last entry */
413 md->phys_addr = relo_end;
414 md->num_pages = (md_end - relo_end) >> EFI_PAGE_SHIFT;
416 /*
417 * Expand the new kernel/xenheap (and maybe dom0/initrd) out to
418 * the full size. This range will already be type EFI_LOADER_DATA,
419 * therefore the xenheap area is now protected being allocated for
420 * use by find_memmap_space() in efi.c
421 */
422 kern_md->num_pages = (relo_end - kern_md->phys_addr) >> EFI_PAGE_SHIFT;
424 reserve_memory();
426 /* first find highest page frame number */
427 max_page = 0;
428 efi_memmap_walk(find_max_pfn, &max_page);
429 printk("find_memory: efi_memmap_walk returns max_page=%lx\n",max_page);
430 efi_print();
432 /*
433 * later [__init_begin, __init_end) will be freed up as xen heap
434 * so that struct domain might be allocated from the init area
435 * which is < xen_heap_start. so we can't simply set
436 * xen_pickle_offset = xen_heap_start.
437 */
438 xen_pickle_offset = ia64_imva(__init_begin);
440 xen_heap_start = memguard_init(ia64_imva(&_end));
441 printk("Before xen_heap_start: %p\n", xen_heap_start);
442 xen_heap_start = __va(init_boot_allocator(__pa(xen_heap_start)));
443 printk("After xen_heap_start: %p\n", xen_heap_start);
445 efi_memmap_walk(filter_rsvd_memory, init_boot_pages);
446 efi_memmap_walk(xen_count_pages, &nr_pages);
448 printk("System RAM: %luMB (%lukB)\n",
449 nr_pages >> (20 - PAGE_SHIFT),
450 nr_pages << (PAGE_SHIFT - 10));
451 total_pages = nr_pages;
453 init_frametable();
455 trap_init();
457 alloc_dom0();
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();
550 /* Hide the HCDP table from dom0 */
551 efi.hcdp = NULL;
552 }
554 expose_p2m_init();
556 /* Create initial domain 0. */
557 dom0 = domain_create(0, 0, DOM0_SSIDREF);
558 if (dom0 == NULL)
559 panic("Error creating domain 0\n");
560 dom0_vcpu0 = alloc_vcpu(dom0, 0, 0);
561 if (dom0_vcpu0 == NULL || vcpu_late_initialise(dom0_vcpu0) != 0)
562 panic("Cannot allocate dom0 vcpu 0\n");
564 dom0->is_privileged = 1;
566 /*
567 * We're going to setup domain0 using the module(s) that we stashed safely
568 * above our heap. The second module, if present, is an initrd ramdisk.
569 */
570 dom0_memory_start = (unsigned long) __va(ia64_boot_param->domain_start);
571 dom0_memory_size = ia64_boot_param->domain_size;
572 dom0_initrd_start = (unsigned long) __va(ia64_boot_param->initrd_start);
573 dom0_initrd_size = ia64_boot_param->initrd_size;
575 if ( construct_dom0(dom0, dom0_memory_start, dom0_memory_size,
576 dom0_initrd_start,dom0_initrd_size,
577 0) != 0)
578 panic("Could not set up DOM0 guest OS\n");
580 if (!running_on_sim && !IS_MEDUSA()) // slow on ski and pages are pre-initialized to zero
581 scrub_heap_pages();
583 init_trace_bufs();
585 if (opt_xencons) {
586 console_endboot();
587 serial_endboot();
588 }
590 domain0_ready = 1;
592 domain_unpause_by_systemcontroller(dom0);
594 init_done();
595 }
597 void arch_get_xen_caps(xen_capabilities_info_t *info)
598 {
599 /* Interface name is always xen-3.0-* for Xen-3.x. */
600 int major = 3, minor = 0;
601 char s[32];
603 (*info)[0] = '\0';
605 snprintf(s, sizeof(s), "xen-%d.%d-ia64 ", major, minor);
606 safe_strcat(*info, s);
608 snprintf(s, sizeof(s), "xen-%d.%d-ia64be ", major, minor);
609 safe_strcat(*info, s);
611 if (vmx_enabled)
612 {
613 snprintf(s, sizeof(s), "hvm-%d.%d-ia64 ", major, minor);
614 safe_strcat(*info, s);
615 }
616 }