ia64/xen-unstable

view xen/arch/ia64/xen/xensetup.c @ 9685:4e8a64d8bd0e

[IA64] regionreg.c: deallocate metaphysical rids

allocate_rid_range also allocates metaphysical rids.
deallocate_rid_range also deallocates mp rids.
init_rid_allocator() added.

Signed-off-by: Tristan Gingold <tristan.gingold@bull.net>
author awilliam@xenbuild.aw
date Fri Apr 14 14:13:13 2006 -0600 (2006-04-14)
parents 8e0b9f31cf3f
children bd264ded5bec
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;
35 char saved_command_line[COMMAND_LINE_SIZE];
36 char dom0_command_line[COMMAND_LINE_SIZE];
38 struct vcpu *idle_vcpu[NR_CPUS];
40 cpumask_t cpu_present_map;
42 extern unsigned long domain0_ready;
44 int find_max_pfn (unsigned long, unsigned long, void *);
45 void start_of_day(void);
47 /* FIXME: which header these declarations should be there ? */
48 extern long is_platform_hp_ski(void);
49 extern void early_setup_arch(char **);
50 extern void late_setup_arch(char **);
51 extern void hpsim_serial_init(void);
52 extern void alloc_dom0(void);
53 extern void setup_per_cpu_areas(void);
54 extern void mem_init(void);
55 extern void init_IRQ(void);
57 /* opt_nosmp: If true, secondary processors are ignored. */
58 static int opt_nosmp = 0;
59 boolean_param("nosmp", opt_nosmp);
61 /* maxcpus: maximum number of CPUs to activate. */
62 static unsigned int max_cpus = NR_CPUS;
63 integer_param("maxcpus", max_cpus);
65 /*
66 * opt_xenheap_megabytes: Size of Xen heap in megabytes, including:
67 * xen image
68 * bootmap bits
69 * xen heap
70 * Note: To allow xenheap size configurable, the prerequisite is
71 * to configure elilo allowing relocation defaultly. Then since
72 * elilo chooses 256M as alignment when relocating, alignment issue
73 * on IPF can be addressed.
74 */
75 unsigned int opt_xenheap_megabytes = XENHEAP_DEFAULT_MB;
76 unsigned long xenheap_size = XENHEAP_DEFAULT_SIZE;
77 extern long running_on_sim;
78 unsigned long xen_pstart;
80 static int
81 xen_count_pages(u64 start, u64 end, void *arg)
82 {
83 unsigned long *count = arg;
85 /* FIXME: do we need consider difference between DMA-usable memory and
86 * normal memory? Seems that HV has no requirement to operate DMA which
87 * is owned by Dom0? */
88 *count += (end - start) >> PAGE_SHIFT;
89 return 0;
90 }
92 /* Find first hole after trunk for xen image */
93 static int
94 xen_find_first_hole(u64 start, u64 end, void *arg)
95 {
96 unsigned long *first_hole = arg;
98 if ((*first_hole) == 0) {
99 if ((start <= KERNEL_START) && (KERNEL_START < end))
100 *first_hole = __pa(end);
101 }
103 return 0;
104 }
106 static void __init do_initcalls(void)
107 {
108 initcall_t *call;
109 for ( call = &__initcall_start; call < &__initcall_end; call++ )
110 (*call)();
111 }
113 /*
114 * IPF loader only supports one commaind line currently, for
115 * both xen and guest kernel. This function provides pre-parse
116 * to mixed command line, to split it into two parts.
117 *
118 * User should split the parameters by "--", with strings after
119 * spliter for guest kernel. Missing "--" means whole line belongs
120 * to guest. Example:
121 * "com2=57600,8n1 console=com2 -- console=ttyS1 console=tty
122 * root=/dev/sda3 ro"
123 */
124 static char null[4] = { 0 };
126 void early_cmdline_parse(char **cmdline_p)
127 {
128 char *guest_cmd;
129 static const char * const split = "--";
131 if (*cmdline_p == NULL) {
132 *cmdline_p = &null[0];
133 saved_command_line[0] = '\0';
134 dom0_command_line[0] = '\0';
135 return;
136 }
138 guest_cmd = strstr(*cmdline_p, split);
139 /* If no spliter, whole line is for guest */
140 if (guest_cmd == NULL) {
141 guest_cmd = *cmdline_p;
142 *cmdline_p = &null[0];
143 } else {
144 *guest_cmd = '\0'; /* Split boot parameters for xen and guest */
145 guest_cmd += strlen(split);
146 while (*guest_cmd == ' ') guest_cmd++;
147 }
149 strlcpy(saved_command_line, *cmdline_p, COMMAND_LINE_SIZE);
150 strlcpy(dom0_command_line, guest_cmd, COMMAND_LINE_SIZE);
151 return;
152 }
154 struct ns16550_defaults ns16550_com1 = {
155 .baud = BAUD_AUTO,
156 .data_bits = 8,
157 .parity = 'n',
158 .stop_bits = 1
159 };
161 struct ns16550_defaults ns16550_com2 = {
162 .baud = BAUD_AUTO,
163 .data_bits = 8,
164 .parity = 'n',
165 .stop_bits = 1
166 };
168 void start_kernel(void)
169 {
170 unsigned char *cmdline;
171 void *heap_start;
172 unsigned long nr_pages, firsthole_start;
173 unsigned long dom0_memory_start, dom0_memory_size;
174 unsigned long dom0_initrd_start, dom0_initrd_size;
175 unsigned long initial_images_start, initial_images_end;
176 struct domain *idle_domain;
177 #ifdef CONFIG_SMP
178 int i;
179 #endif
181 running_on_sim = is_platform_hp_ski();
182 /* Kernel may be relocated by EFI loader */
183 xen_pstart = ia64_tpa(KERNEL_START);
185 early_setup_arch((char **) &cmdline);
187 /* We initialise the serial devices very early so we can get debugging. */
188 if (running_on_sim) hpsim_serial_init();
189 else {
190 ns16550_init(0, &ns16550_com1);
191 /* Also init com2 for Tiger4. */
192 ns16550_com2.io_base = 0x2f8;
193 ns16550_com2.irq = 3;
194 ns16550_init(1, &ns16550_com2);
195 }
196 serial_init_preirq();
198 init_console();
199 set_printk_prefix("(XEN) ");
201 /* xenheap should be in same TR-covered range with xen image */
202 xenheap_phys_end = xen_pstart + xenheap_size;
203 printk("xen image pstart: 0x%lx, xenheap pend: 0x%lx\n",
204 xen_pstart, xenheap_phys_end);
206 /* Find next hole */
207 firsthole_start = 0;
208 efi_memmap_walk(xen_find_first_hole, &firsthole_start);
210 if (running_on_sim || ia64_boot_param->domain_start == 0
211 || ia64_boot_param->domain_size == 0) {
212 /* This is possible only with the old elilo, which does not support
213 a vmm. Fix now, and continue without initrd. */
214 printk ("Your elilo is not Xen-aware. Bootparams fixed\n");
215 ia64_boot_param->domain_start = ia64_boot_param->initrd_start;
216 ia64_boot_param->domain_size = ia64_boot_param->initrd_size;
217 ia64_boot_param->initrd_start = 0;
218 ia64_boot_param->initrd_size = 0;
219 }
221 initial_images_start = xenheap_phys_end;
222 initial_images_end = initial_images_start +
223 PAGE_ALIGN(ia64_boot_param->domain_size);
225 /* also reserve space for initrd */
226 if (ia64_boot_param->initrd_start && ia64_boot_param->initrd_size)
227 initial_images_end += PAGE_ALIGN(ia64_boot_param->initrd_size);
228 else {
229 /* sanity cleanup */
230 ia64_boot_param->initrd_size = 0;
231 ia64_boot_param->initrd_start = 0;
232 }
235 /* Later may find another memory trunk, even away from xen image... */
236 if (initial_images_end > firsthole_start) {
237 printk("Not enough memory to stash the DOM0 kernel image.\n");
238 printk("First hole:0x%lx, relocation end: 0x%lx\n",
239 firsthole_start, initial_images_end);
240 for ( ; ; );
241 }
243 /* This copy is time consuming, but elilo may load Dom0 image
244 * within xenheap range */
245 printk("ready to move Dom0 to 0x%lx with len %lx...", initial_images_start,
246 ia64_boot_param->domain_size);
248 memmove(__va(initial_images_start),
249 __va(ia64_boot_param->domain_start),
250 ia64_boot_param->domain_size);
251 // ia64_boot_param->domain_start = initial_images_start;
253 printk("ready to move initrd to 0x%lx with len %lx...",
254 initial_images_start+PAGE_ALIGN(ia64_boot_param->domain_size),
255 ia64_boot_param->initrd_size);
256 memmove(__va(initial_images_start+PAGE_ALIGN(ia64_boot_param->domain_size)),
258 __va(ia64_boot_param->initrd_start),
259 ia64_boot_param->initrd_size);
260 printk("Done\n");
262 /* first find highest page frame number */
263 max_page = 0;
264 efi_memmap_walk(find_max_pfn, &max_page);
265 printf("find_memory: efi_memmap_walk returns max_page=%lx\n",max_page);
266 /* this is a bad hack. see dom_fw.c creation of EFI map for dom0 */
267 max_page = (GRANULEROUNDDOWN(max_page << PAGE_SHIFT)
268 - IA64_GRANULE_SIZE) >> PAGE_SHIFT;
269 printf("find_memory: last granule reserved for dom0; xen max_page=%lx\n",
270 max_page);
272 heap_start = memguard_init(ia64_imva(&_end));
273 printf("Before heap_start: %p\n", heap_start);
274 heap_start = __va(init_boot_allocator(__pa(heap_start)));
275 printf("After heap_start: %p\n", heap_start);
277 reserve_memory();
279 efi_memmap_walk(filter_rsvd_memory, init_boot_pages);
280 efi_memmap_walk(xen_count_pages, &nr_pages);
282 printk("System RAM: %luMB (%lukB)\n",
283 nr_pages >> (20 - PAGE_SHIFT),
284 nr_pages << (PAGE_SHIFT - 10));
286 init_frametable();
288 ia64_fph_enable();
289 __ia64_init_fpu();
291 alloc_dom0();
293 end_boot_allocator();
295 init_xenheap_pages(__pa(heap_start), xenheap_phys_end);
296 printk("Xen heap: %luMB (%lukB)\n",
297 (xenheap_phys_end-__pa(heap_start)) >> 20,
298 (xenheap_phys_end-__pa(heap_start)) >> 10);
300 printk("About to call scheduler_init()\n");
301 scheduler_init();
302 idle_vcpu[0] = (struct vcpu*) ia64_r13;
303 idle_domain = domain_create(IDLE_DOMAIN_ID, 0);
304 BUG_ON(idle_domain == NULL);
306 late_setup_arch((char **) &cmdline);
307 setup_per_cpu_areas();
308 mem_init();
310 local_irq_disable();
311 init_IRQ ();
312 printk("About to call init_xen_time()\n");
313 init_xen_time(); /* initialise the time */
314 printk("About to call timer_init()\n");
315 timer_init();
317 #ifdef CONFIG_XEN_CONSOLE_INPUT /* CONFIG_SERIAL_8250_CONSOLE=n in dom0! */
318 initialize_keytable();
319 serial_init_postirq();
320 #endif
322 #ifdef CONFIG_SMP
323 if ( opt_nosmp )
324 {
325 max_cpus = 0;
326 smp_num_siblings = 1;
327 //boot_cpu_data.x86_num_cores = 1;
328 }
330 /* A vcpu is created for the idle domain on every physical cpu.
331 Limit the number of cpus to the maximum number of vcpus. */
332 if (max_cpus > MAX_VIRT_CPUS)
333 max_cpus = MAX_VIRT_CPUS;
335 smp_prepare_cpus(max_cpus);
337 /* We aren't hotplug-capable yet. */
338 for_each_cpu ( i )
339 cpu_set(i, cpu_present_map);
341 /* Enable IRQ to receive IPI (needed for ITC sync). */
342 local_irq_enable();
344 printk("num_online_cpus=%d, max_cpus=%d\n",num_online_cpus(),max_cpus);
345 for_each_present_cpu ( i )
346 {
347 if ( num_online_cpus() >= max_cpus )
348 break;
349 if ( !cpu_online(i) ) {
350 __cpu_up(i);
351 }
352 }
354 local_irq_disable();
356 printk("Brought up %ld CPUs\n", (long)num_online_cpus());
357 smp_cpus_done(max_cpus);
358 #endif
360 initialise_gdb(); /* could be moved earlier */
362 do_initcalls();
363 printk("About to call sort_main_extable()\n");
364 sort_main_extable();
367 init_rid_allocator ();
369 /* Create initial domain 0. */
370 printk("About to call domain_create()\n");
371 dom0 = domain_create(0, 0);
373 if ( dom0 == NULL )
374 panic("Error creating domain 0\n");
376 set_bit(_DOMF_privileged, &dom0->domain_flags);
378 /*
379 * We're going to setup domain0 using the module(s) that we stashed safely
380 * above our heap. The second module, if present, is an initrd ramdisk.
381 */
382 printk("About to call construct_dom0()\n");
383 dom0_memory_start = (unsigned long) __va(initial_images_start);
384 dom0_memory_size = ia64_boot_param->domain_size;
385 dom0_initrd_start = (unsigned long) __va(initial_images_start +
386 PAGE_ALIGN(ia64_boot_param->domain_size));
387 dom0_initrd_size = ia64_boot_param->initrd_size;
389 if ( construct_dom0(dom0, dom0_memory_start, dom0_memory_size,
390 dom0_initrd_start,dom0_initrd_size,
391 0) != 0)
392 panic("Could not set up DOM0 guest OS\n");
394 /* PIN domain0 on CPU 0. */
395 dom0->vcpu[0]->cpu_affinity = cpumask_of_cpu(0);
397 if (!running_on_sim) // slow on ski and pages are pre-initialized to zero
398 scrub_heap_pages();
400 printk("About to call init_trace_bufs()\n");
401 init_trace_bufs();
403 /* Give up the VGA console if DOM0 is configured to grab it. */
404 #ifdef CONFIG_XEN_CONSOLE_INPUT /* CONFIG_SERIAL_8250_CONSOLE=n in dom0! */
405 console_endboot(cmdline && strstr(cmdline, "tty0"));
406 #endif
408 domain0_ready = 1;
410 local_irq_enable();
412 printf("About to call schedulers_start dom0=%p, idle_dom=%p\n",
413 dom0, &idle_domain);
414 schedulers_start();
416 domain_unpause_by_systemcontroller(dom0);
418 printk("About to call startup_cpu_idle_loop()\n");
419 startup_cpu_idle_loop();
420 }
422 void arch_get_xen_caps(xen_capabilities_info_t info)
423 {
424 char *p=info;
426 p += sprintf(p,"xen-%d.%d-ia64 ", XEN_VERSION, XEN_SUBVERSION);
428 if (vmx_enabled)
429 p += sprintf(p,"hvm-%d.%d-ia64 ", XEN_VERSION, XEN_SUBVERSION);
431 *(p-1) = 0;
433 BUG_ON((p-info)>sizeof(xen_capabilities_info_t));
435 }