ia64/xen-unstable

view xen/arch/ia64/xen/xensetup.c @ 15563:1ef9dc28810d

[IA64] Fix VGA console

VGA console support seems to have gotten broken somewhere along the
way. On current bits, console=vga doesn't seem to do anything. This
patch adds the necessary console info to get it working again.

Signed-off-by: Alex Williamson <alex.williamson@hp.com>
author Alex Williamson <alex.williamson@hp.com>
date Wed Jul 25 13:09:27 2007 -0600 (2007-07-25)
parents cbf749e9961f
children 6a89339b81d0
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 <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 alloc_dom0(void);
50 extern void setup_per_cpu_areas(void);
51 extern void mem_init(void);
52 extern void init_IRQ(void);
53 extern void trap_init(void);
54 extern void xen_patch_kernel(void);
56 /* opt_nosmp: If true, secondary processors are ignored. */
57 static int opt_nosmp;
58 boolean_param("nosmp", opt_nosmp);
60 /* maxcpus: maximum number of CPUs to activate. */
61 static unsigned int __initdata max_cpus = NR_CPUS;
62 integer_param("maxcpus", max_cpus);
64 /* xencons: if true enable xenconsole input (and irq).
65 Note: you have to disable 8250 serials in domains (to avoid use of the
66 same resource). */
67 static int __initdata opt_xencons = 1;
68 integer_param("xencons", opt_xencons);
70 /* Toggle to allow non-legacy xencons UARTs to run in polling mode */
71 static int __initdata opt_xencons_poll;
72 boolean_param("xencons_poll", opt_xencons_poll);
74 /*
75 * opt_xenheap_megabytes: Size of Xen heap in megabytes, including:
76 * xen image
77 * bootmap bits
78 * xen heap
79 * Note: To allow xenheap size configurable, the prerequisite is
80 * to configure elilo allowing relocation defaultly. Then since
81 * elilo chooses 256M as alignment when relocating, alignment issue
82 * on IPF can be addressed.
83 */
84 unsigned int opt_xenheap_megabytes = XENHEAP_DEFAULT_MB;
85 unsigned long xenheap_size = XENHEAP_DEFAULT_SIZE;
86 unsigned long xen_pstart;
87 void *xen_pickle_offset __read_mostly;
89 static int __init
90 xen_count_pages(u64 start, u64 end, void *arg)
91 {
92 unsigned long *count = arg;
94 /* FIXME: do we need consider difference between DMA-usable memory and
95 * normal memory? Seems that HV has no requirement to operate DMA which
96 * is owned by Dom0? */
97 *count += (end - start) >> PAGE_SHIFT;
98 return 0;
99 }
101 static void __init do_initcalls(void)
102 {
103 initcall_t *call;
104 for ( call = &__initcall_start; call < &__initcall_end; call++ )
105 (*call)();
106 }
108 /*
109 * IPF loader only supports one commaind line currently, for
110 * both xen and guest kernel. This function provides pre-parse
111 * to mixed command line, to split it into two parts.
112 *
113 * User should split the parameters by "--", with strings after
114 * spliter for guest kernel. Missing "--" means whole line belongs
115 * to guest. Example:
116 * "com2=57600,8n1 console=com2 -- console=ttyS1 console=tty
117 * root=/dev/sda3 ro"
118 */
119 static char null[4] = { 0 };
121 void __init early_cmdline_parse(char **cmdline_p)
122 {
123 char *guest_cmd;
124 static const char * const split = "--";
126 if (*cmdline_p == NULL) {
127 *cmdline_p = &null[0];
128 saved_command_line[0] = '\0';
129 dom0_command_line[0] = '\0';
130 return;
131 }
133 guest_cmd = strstr(*cmdline_p, split);
134 /* If no spliter, whole line is for guest */
135 if (guest_cmd == NULL) {
136 guest_cmd = *cmdline_p;
137 *cmdline_p = &null[0];
138 } else {
139 *guest_cmd = '\0'; /* Split boot parameters for xen and guest */
140 guest_cmd += strlen(split);
141 while (*guest_cmd == ' ') guest_cmd++;
142 }
144 strlcpy(saved_command_line, *cmdline_p, COMMAND_LINE_SIZE);
145 strlcpy(dom0_command_line, guest_cmd, COMMAND_LINE_SIZE);
146 return;
147 }
149 struct ns16550_defaults ns16550_com1 = {
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 .data_bits = 8,
161 .parity = 'n',
162 .stop_bits = 1
163 };
165 /* efi_print: print efi table at boot */
166 static int __initdata opt_efi_print;
167 boolean_param("efi_print", opt_efi_print);
169 /* print EFI memory map: */
170 static void __init
171 efi_print(void)
172 {
173 void *efi_map_start, *efi_map_end;
174 u64 efi_desc_size;
176 efi_memory_desc_t *md;
177 void *p;
178 int i;
180 if (!opt_efi_print)
181 return;
183 efi_map_start = __va(ia64_boot_param->efi_memmap);
184 efi_map_end = efi_map_start + ia64_boot_param->efi_memmap_size;
185 efi_desc_size = ia64_boot_param->efi_memdesc_size;
187 for (i = 0, p = efi_map_start; p < efi_map_end; ++i, p += efi_desc_size) {
188 md = p;
189 printk("mem%02u: type=%2u, attr=0x%016lx, range=[0x%016lx-0x%016lx) "
190 "(%luMB)\n", i, md->type, md->attribute, md->phys_addr,
191 md->phys_addr + (md->num_pages << EFI_PAGE_SHIFT),
192 md->num_pages >> (20 - EFI_PAGE_SHIFT));
193 }
194 }
196 /*
197 * These functions are utility functions for getting and
198 * testing memory descriptors for allocating the xenheap area.
199 */
200 static efi_memory_desc_t *
201 efi_get_md (unsigned long phys_addr)
202 {
203 void *efi_map_start, *efi_map_end, *p;
204 efi_memory_desc_t *md;
205 u64 efi_desc_size;
207 efi_map_start = __va(ia64_boot_param->efi_memmap);
208 efi_map_end = efi_map_start + ia64_boot_param->efi_memmap_size;
209 efi_desc_size = ia64_boot_param->efi_memdesc_size;
211 for (p = efi_map_start; p < efi_map_end; p += efi_desc_size) {
212 md = p;
213 if (phys_addr - md->phys_addr < (md->num_pages << EFI_PAGE_SHIFT))
214 return md;
215 }
216 return 0;
217 }
219 static int
220 is_xenheap_usable_memory(efi_memory_desc_t *md)
221 {
222 if (!(md->attribute & EFI_MEMORY_WB))
223 return 0;
225 switch (md->type) {
226 case EFI_LOADER_CODE:
227 case EFI_LOADER_DATA:
228 case EFI_BOOT_SERVICES_CODE:
229 case EFI_BOOT_SERVICES_DATA:
230 case EFI_CONVENTIONAL_MEMORY:
231 return 1;
232 }
233 return 0;
234 }
236 static inline int
237 md_overlaps(efi_memory_desc_t *md, unsigned long phys_addr)
238 {
239 return (phys_addr - md->phys_addr < (md->num_pages << EFI_PAGE_SHIFT));
240 }
242 #define MD_SIZE(md) (md->num_pages << EFI_PAGE_SHIFT)
244 extern char __init_begin[], __init_end[];
245 static void noinline init_done(void)
246 {
247 memset(__init_begin, 0, __init_end - __init_begin);
248 flush_icache_range((unsigned long)__init_begin, (unsigned long)__init_end);
249 init_xenheap_pages(__pa(__init_begin), __pa(__init_end));
250 printk("Freed %ldkB init memory.\n",
251 (long)(__init_end-__init_begin)>>10);
253 startup_cpu_idle_loop();
254 }
256 int running_on_sim;
258 static int __init
259 is_platform_hp_ski(void)
260 {
261 int i;
262 long cpuid[6];
264 for (i = 0; i < 5; ++i)
265 cpuid[i] = ia64_get_cpuid(i);
267 if ((cpuid[0] & 0xff) != 'H')
268 return 0;
269 if ((cpuid[3] & 0xff) != 0x4)
270 return 0;
271 if (((cpuid[3] >> 8) & 0xff) != 0x0)
272 return 0;
273 if (((cpuid[3] >> 16) & 0xff) != 0x0)
274 return 0;
275 if (((cpuid[3] >> 24) & 0x7) != 0x7)
276 return 0;
278 return 1;
279 }
281 void __init start_kernel(void)
282 {
283 char *cmdline;
284 unsigned long nr_pages;
285 unsigned long dom0_memory_start, dom0_memory_size;
286 unsigned long dom0_initrd_start, dom0_initrd_size;
287 unsigned long md_end, relo_start, relo_end, relo_size = 0;
288 struct domain *idle_domain;
289 struct vcpu *dom0_vcpu0;
290 efi_memory_desc_t *kern_md, *last_md, *md;
291 void *xen_heap_start;
292 #ifdef CONFIG_SMP
293 int i;
294 #endif
296 /* Be sure the struct shared_info size is <= XSI_SIZE. */
297 BUILD_BUG_ON(sizeof(struct shared_info) > XSI_SIZE);
299 /* Kernel may be relocated by EFI loader */
300 xen_pstart = ia64_tpa(KERNEL_START);
302 running_on_sim = is_platform_hp_ski();
304 early_setup_arch(&cmdline);
306 /* We initialise the serial devices very early so we can get debugging. */
307 if (running_on_sim)
308 hpsim_serial_init();
309 else {
310 ns16550_init(0, &ns16550_com1);
311 ns16550_init(1, &ns16550_com2);
312 }
313 serial_init_preirq();
315 #ifdef CONFIG_VGA
316 /* Plug in a default VGA mode */
317 vga_console_info.video_type = XEN_VGATYPE_TEXT_MODE_3;
318 vga_console_info.u.text_mode_3.font_height = 16; /* generic VGA? */
319 vga_console_info.u.text_mode_3.cursor_x =
320 ia64_boot_param->console_info.orig_x;
321 vga_console_info.u.text_mode_3.cursor_y =
322 ia64_boot_param->console_info.orig_y;
323 vga_console_info.u.text_mode_3.rows =
324 ia64_boot_param->console_info.num_rows;
325 vga_console_info.u.text_mode_3.columns =
326 ia64_boot_param->console_info.num_cols;
327 #endif
329 init_console();
330 set_printk_prefix("(XEN) ");
332 if (running_on_sim || ia64_boot_param->domain_start == 0 ||
333 ia64_boot_param->domain_size == 0) {
334 /* This is possible only with the old elilo, which does not support
335 a vmm. Fix now, and continue without initrd. */
336 printk ("Your elilo is not Xen-aware. Bootparams fixed\n");
337 ia64_boot_param->domain_start = ia64_boot_param->initrd_start;
338 ia64_boot_param->domain_size = ia64_boot_param->initrd_size;
339 ia64_boot_param->initrd_start = 0;
340 ia64_boot_param->initrd_size = 0;
341 }
343 printk("Xen command line: %s\n", saved_command_line);
344 /* xenheap should be in same TR-covered range with xen image */
345 xenheap_phys_end = xen_pstart + xenheap_size;
346 printk("xen image pstart: 0x%lx, xenheap pend: 0x%lx\n",
347 xen_pstart, xenheap_phys_end);
349 xen_patch_kernel();
351 kern_md = md = efi_get_md(xen_pstart);
352 md_end = __pa(ia64_imva(&_end));
353 relo_start = xenheap_phys_end;
355 /*
356 * Scan through the memory descriptors after the kernel
357 * image to make sure we have enough room for the xenheap
358 * area, pushing out whatever may already be there.
359 */
360 while (relo_start + relo_size >= md_end) {
361 md = efi_get_md(md_end);
363 BUG_ON(!md);
364 BUG_ON(!is_xenheap_usable_memory(md));
366 md_end = md->phys_addr + MD_SIZE(md);
367 /*
368 * The dom0 kernel or initrd could overlap, reserve space
369 * at the end to relocate them later.
370 */
371 if (md->type == EFI_LOADER_DATA) {
372 /* Test for ranges we're not prepared to move */
373 BUG_ON(md_overlaps(md, __pa(ia64_boot_param)) ||
374 md_overlaps(md, ia64_boot_param->efi_memmap) ||
375 md_overlaps(md, ia64_boot_param->command_line));
377 relo_size += MD_SIZE(md);
378 /* If range overlaps the end, push out the relocation start */
379 if (md_end > relo_start)
380 relo_start = md_end;
381 }
382 }
383 last_md = md;
384 relo_end = relo_start + relo_size;
386 md_end = __pa(ia64_imva(&_end));
388 /*
389 * Move any relocated data out into the previously found relocation
390 * area. Any extra memory descriptrs are moved out to the end
391 * and set to zero pages.
392 */
393 for (md = efi_get_md(md_end) ;; md = efi_get_md(md_end)) {
394 md_end = md->phys_addr + MD_SIZE(md);
396 if (md->type == EFI_LOADER_DATA) {
397 unsigned long relo_offset;
399 if (md_overlaps(md, ia64_boot_param->domain_start)) {
400 relo_offset = ia64_boot_param->domain_start - md->phys_addr;
401 printk("Moving Dom0 kernel image: 0x%lx -> 0x%lx (%ld KiB)\n",
402 ia64_boot_param->domain_start, relo_start + relo_offset,
403 ia64_boot_param->domain_size >> 10);
404 ia64_boot_param->domain_start = relo_start + relo_offset;
405 }
406 if (ia64_boot_param->initrd_size &&
407 md_overlaps(md, ia64_boot_param->initrd_start)) {
408 relo_offset = ia64_boot_param->initrd_start - md->phys_addr;
409 printk("Moving Dom0 initrd image: 0x%lx -> 0x%lx (%ld KiB)\n",
410 ia64_boot_param->initrd_start, relo_start + relo_offset,
411 ia64_boot_param->initrd_size >> 10);
412 ia64_boot_param->initrd_start = relo_start + relo_offset;
413 }
414 memcpy(__va(relo_start), __va(md->phys_addr), MD_SIZE(md));
415 relo_start += MD_SIZE(md);
416 }
418 if (md == kern_md)
419 continue;
420 if (md == last_md)
421 break;
423 md->phys_addr = relo_end;
424 md->num_pages = 0;
425 }
427 /* Trim the last entry */
428 md->phys_addr = relo_end;
429 md->num_pages = (md_end - relo_end) >> EFI_PAGE_SHIFT;
431 /*
432 * Expand the new kernel/xenheap (and maybe dom0/initrd) out to
433 * the full size. This range will already be type EFI_LOADER_DATA,
434 * therefore the xenheap area is now protected being allocated for
435 * use by find_memmap_space() in efi.c
436 */
437 kern_md->num_pages = (relo_end - kern_md->phys_addr) >> EFI_PAGE_SHIFT;
439 reserve_memory();
441 /* first find highest page frame number */
442 max_page = 0;
443 efi_memmap_walk(find_max_pfn, &max_page);
444 printk("find_memory: efi_memmap_walk returns max_page=%lx\n",max_page);
445 efi_print();
447 /*
448 * later [__init_begin, __init_end) will be freed up as xen heap
449 * so that struct domain might be allocated from the init area
450 * which is < xen_heap_start. so we can't simply set
451 * xen_pickle_offset = xen_heap_start.
452 */
453 xen_pickle_offset = ia64_imva(__init_begin);
455 xen_heap_start = memguard_init(ia64_imva(&_end));
456 printk("Before xen_heap_start: %p\n", xen_heap_start);
457 xen_heap_start = __va(init_boot_allocator(__pa(xen_heap_start)));
458 printk("After xen_heap_start: %p\n", xen_heap_start);
460 efi_memmap_walk(filter_rsvd_memory, init_boot_pages);
461 efi_memmap_walk(xen_count_pages, &nr_pages);
463 printk("System RAM: %luMB (%lukB)\n",
464 nr_pages >> (20 - PAGE_SHIFT),
465 nr_pages << (PAGE_SHIFT - 10));
466 total_pages = nr_pages;
468 init_frametable();
470 trap_init();
472 alloc_dom0();
474 init_xenheap_pages(__pa(xen_heap_start), xenheap_phys_end);
475 printk("Xen heap: %luMB (%lukB)\n",
476 (xenheap_phys_end-__pa(xen_heap_start)) >> 20,
477 (xenheap_phys_end-__pa(xen_heap_start)) >> 10);
479 end_boot_allocator();
481 late_setup_arch(&cmdline);
483 scheduler_init();
484 idle_vcpu[0] = (struct vcpu*) ia64_r13;
485 idle_domain = domain_create(IDLE_DOMAIN_ID, 0, 0);
486 if ( (idle_domain == NULL) || (alloc_vcpu(idle_domain, 0, 0) == NULL) )
487 BUG();
489 alloc_dom_xen_and_dom_io();
490 setup_per_cpu_areas();
491 mem_init();
493 local_irq_disable();
494 init_IRQ ();
495 init_xen_time(); /* initialise the time */
496 timer_init();
498 rcu_init();
500 #ifdef CONFIG_XEN_IA64_TLBFLUSH_CLOCK
501 open_softirq(NEW_TLBFLUSH_CLOCK_PERIOD_SOFTIRQ, new_tlbflush_clock_period);
502 #endif
504 #ifdef CONFIG_SMP
505 if ( opt_nosmp )
506 {
507 max_cpus = 0;
508 smp_num_siblings = 1;
509 //boot_cpu_data.x86_num_cores = 1;
510 }
512 /* A vcpu is created for the idle domain on every physical cpu.
513 Limit the number of cpus to the maximum number of vcpus. */
514 if (max_cpus > MAX_VIRT_CPUS)
515 max_cpus = MAX_VIRT_CPUS;
517 smp_prepare_cpus(max_cpus);
519 /* We aren't hotplug-capable yet. */
520 for_each_cpu ( i )
521 cpu_set(i, cpu_present_map);
523 /* Enable IRQ to receive IPI (needed for ITC sync). */
524 local_irq_enable();
526 printk("num_online_cpus=%d, max_cpus=%d\n",num_online_cpus(),max_cpus);
527 for_each_present_cpu ( i )
528 {
529 if ( num_online_cpus() >= max_cpus )
530 break;
531 if ( !cpu_online(i) ) {
532 rcu_online_cpu(i);
533 __cpu_up(i);
534 }
535 }
537 local_irq_disable();
539 printk("Brought up %ld CPUs\n", (long)num_online_cpus());
540 smp_cpus_done(max_cpus);
541 #endif
543 initialise_gdb(); /* could be moved earlier */
545 do_initcalls();
546 sort_main_extable();
548 init_rid_allocator ();
550 local_irq_enable();
552 if (opt_xencons) {
553 initialize_keytable();
554 if (ns16550_com1_gsi) {
555 if (opt_xencons_poll ||
556 iosapic_register_intr(ns16550_com1_gsi,
557 ns16550_com1_polarity,
558 ns16550_com1_trigger) < 0) {
559 ns16550_com1.irq = 0;
560 ns16550_init(0, &ns16550_com1);
561 }
562 }
563 serial_init_postirq();
565 /* Hide the HCDP table from dom0 */
566 efi.hcdp = NULL;
567 }
569 expose_p2m_init();
571 /* Create initial domain 0. */
572 dom0 = domain_create(0, 0, DOM0_SSIDREF);
573 if (dom0 == NULL)
574 panic("Error creating domain 0\n");
575 dom0_vcpu0 = alloc_vcpu(dom0, 0, 0);
576 if (dom0_vcpu0 == NULL || vcpu_late_initialise(dom0_vcpu0) != 0)
577 panic("Cannot allocate dom0 vcpu 0\n");
579 dom0->is_privileged = 1;
581 /*
582 * We're going to setup domain0 using the module(s) that we stashed safely
583 * above our heap. The second module, if present, is an initrd ramdisk.
584 */
585 dom0_memory_start = (unsigned long) __va(ia64_boot_param->domain_start);
586 dom0_memory_size = ia64_boot_param->domain_size;
587 dom0_initrd_start = (unsigned long) __va(ia64_boot_param->initrd_start);
588 dom0_initrd_size = ia64_boot_param->initrd_size;
590 if ( construct_dom0(dom0, dom0_memory_start, dom0_memory_size,
591 dom0_initrd_start,dom0_initrd_size,
592 0) != 0)
593 panic("Could not set up DOM0 guest OS\n");
595 if (!running_on_sim && !IS_MEDUSA()) // slow on ski and pages are pre-initialized to zero
596 scrub_heap_pages();
598 init_trace_bufs();
600 if (opt_xencons) {
601 console_endboot();
602 serial_endboot();
603 }
605 domain0_ready = 1;
607 domain_unpause_by_systemcontroller(dom0);
609 init_done();
610 }
612 void arch_get_xen_caps(xen_capabilities_info_t *info)
613 {
614 /* Interface name is always xen-3.0-* for Xen-3.x. */
615 int major = 3, minor = 0;
616 char s[32];
618 (*info)[0] = '\0';
620 snprintf(s, sizeof(s), "xen-%d.%d-ia64 ", major, minor);
621 safe_strcat(*info, s);
623 snprintf(s, sizeof(s), "xen-%d.%d-ia64be ", major, minor);
624 safe_strcat(*info, s);
626 if (vmx_enabled)
627 {
628 snprintf(s, sizeof(s), "hvm-%d.%d-ia64 ", major, minor);
629 safe_strcat(*info, s);
630 }
631 }