ia64/xen-unstable

view xen/arch/ia64/domain.c @ 5797:ca44d2dbb273

Intel's pre-bk->hg transition patches
Signed-off-by Eddie Dong <Eddie.dong@intel.com>
Signed-off-by Anthony Xu <Anthony.xu@intel.com>
Signed-off-by Kevin Tian <Kevin.tian@intel.com>
author djm@kirby.fc.hp.com
date Sat Jul 09 07:58:56 2005 -0700 (2005-07-09)
parents da2752f150a0
children a83ac0806d6b
line source
1 /*
2 * Copyright (C) 1995 Linus Torvalds
3 *
4 * Pentium III FXSR, SSE support
5 * Gareth Hughes <gareth@valinux.com>, May 2000
6 *
7 * Copyright (C) 2005 Intel Co
8 * Kun Tian (Kevin Tian) <kevin.tian@intel.com>
9 *
10 * 05/04/29 Kun Tian (Kevin Tian) <kevin.tian@intel.com> Add CONFIG_VTI domain support
11 */
13 #include <xen/config.h>
14 #include <xen/lib.h>
15 #include <xen/errno.h>
16 #include <xen/sched.h>
17 #include <xen/smp.h>
18 #include <xen/delay.h>
19 #include <xen/softirq.h>
20 #include <xen/mm.h>
21 #include <asm/ptrace.h>
22 #include <asm/system.h>
23 #include <asm/io.h>
24 #include <asm/processor.h>
25 #include <asm/desc.h>
26 //#include <asm/mpspec.h>
27 #include <xen/irq.h>
28 #include <xen/event.h>
29 //#include <xen/shadow.h>
30 #include <xen/console.h>
32 #include <xen/elf.h>
33 //#include <asm/page.h>
34 #include <asm/pgalloc.h>
35 #include <asm/dma.h> /* for MAX_DMA_ADDRESS */
37 #include <asm/asm-offsets.h> /* for IA64_THREAD_INFO_SIZE */
39 #include <asm/vcpu.h> /* for function declarations */
40 #include <public/arch-ia64.h>
41 #ifdef CONFIG_VTI
42 #include <asm/vmx.h>
43 #include <asm/vmx_vcpu.h>
44 #include <asm/vmx_vpd.h>
45 #include <asm/pal.h>
46 #include <public/io/ioreq.h>
47 #endif // CONFIG_VTI
49 #define CONFIG_DOMAIN0_CONTIGUOUS
50 unsigned long dom0_start = -1L;
51 #ifdef CONFIG_VTI
52 unsigned long dom0_size = 512*1024*1024; //FIXME: Should be configurable
53 //FIXME: alignment should be 256MB, lest Linux use a 256MB page size
54 unsigned long dom0_align = 256*1024*1024;
55 #else // CONFIG_VTI
56 unsigned long dom0_size = 512*1024*1024; //FIXME: Should be configurable
57 //FIXME: alignment should be 256MB, lest Linux use a 256MB page size
58 unsigned long dom0_align = 64*1024*1024;
59 #endif // CONFIG_VTI
60 #ifdef DOMU_BUILD_STAGING
61 unsigned long domU_staging_size = 32*1024*1024; //FIXME: Should be configurable
62 unsigned long domU_staging_start;
63 unsigned long domU_staging_align = 64*1024;
64 unsigned long *domU_staging_area;
65 #endif
67 // initialized by arch/ia64/setup.c:find_initrd()
68 unsigned long initrd_start = 0, initrd_end = 0;
70 #define IS_XEN_ADDRESS(d,a) ((a >= d->xen_vastart) && (a <= d->xen_vaend))
72 //extern int loadelfimage(char *);
73 extern int readelfimage_base_and_size(char *, unsigned long,
74 unsigned long *, unsigned long *, unsigned long *);
76 unsigned long map_domain_page0(struct domain *);
77 extern unsigned long dom_fw_setup(struct domain *, char *, int);
79 /* this belongs in include/asm, but there doesn't seem to be a suitable place */
80 void free_perdomain_pt(struct domain *d)
81 {
82 printf("free_perdomain_pt: not implemented\n");
83 //free_page((unsigned long)d->mm.perdomain_pt);
84 }
86 int hlt_counter;
88 void disable_hlt(void)
89 {
90 hlt_counter++;
91 }
93 void enable_hlt(void)
94 {
95 hlt_counter--;
96 }
98 static void default_idle(void)
99 {
100 if ( hlt_counter == 0 )
101 {
102 local_irq_disable();
103 if ( !softirq_pending(smp_processor_id()) )
104 safe_halt();
105 //else
106 local_irq_enable();
107 }
108 }
110 void continue_cpu_idle_loop(void)
111 {
112 int cpu = smp_processor_id();
113 for ( ; ; )
114 {
115 #ifdef IA64
116 // __IRQ_STAT(cpu, idle_timestamp) = jiffies
117 #else
118 irq_stat[cpu].idle_timestamp = jiffies;
119 #endif
120 while ( !softirq_pending(cpu) )
121 default_idle();
122 raise_softirq(SCHEDULE_SOFTIRQ);
123 do_softirq();
124 }
125 }
127 void startup_cpu_idle_loop(void)
128 {
129 /* Just some sanity to ensure that the scheduler is set up okay. */
130 ASSERT(current->domain == IDLE_DOMAIN_ID);
131 raise_softirq(SCHEDULE_SOFTIRQ);
132 do_softirq();
134 /*
135 * Declares CPU setup done to the boot processor.
136 * Therefore memory barrier to ensure state is visible.
137 */
138 smp_mb();
139 #if 0
140 //do we have to ensure the idle task has a shared page so that, for example,
141 //region registers can be loaded from it. Apparently not...
142 idle0_task.shared_info = (void *)alloc_xenheap_page();
143 memset(idle0_task.shared_info, 0, PAGE_SIZE);
144 /* pin mapping */
145 // FIXME: Does this belong here? Or do only at domain switch time?
146 {
147 /* WARNING: following must be inlined to avoid nested fault */
148 unsigned long psr = ia64_clear_ic();
149 ia64_itr(0x2, IA64_TR_SHARED_INFO, SHAREDINFO_ADDR,
150 pte_val(pfn_pte(ia64_tpa(idle0_task.shared_info) >> PAGE_SHIFT, PAGE_KERNEL)),
151 PAGE_SHIFT);
152 ia64_set_psr(psr);
153 ia64_srlz_i();
154 }
155 #endif
157 continue_cpu_idle_loop();
158 }
160 struct vcpu *arch_alloc_vcpu_struct(void)
161 {
162 /* Per-vp stack is used here. So we need keep vcpu
163 * same page as per-vp stack */
164 return alloc_xenheap_pages(KERNEL_STACK_SIZE_ORDER);
165 }
167 void arch_free_vcpu_struct(struct vcpu *v)
168 {
169 free_xenheap_pages(v, KERNEL_STACK_SIZE_ORDER);
170 }
172 static void init_switch_stack(struct vcpu *v)
173 {
174 struct pt_regs *regs = (struct pt_regs *) ((unsigned long) v + IA64_STK_OFFSET) - 1;
175 struct switch_stack *sw = (struct switch_stack *) regs - 1;
176 extern void ia64_ret_from_clone;
178 memset(sw, 0, sizeof(struct switch_stack) + sizeof(struct pt_regs));
179 sw->ar_bspstore = (unsigned long)v + IA64_RBS_OFFSET;
180 sw->b0 = (unsigned long) &ia64_ret_from_clone;
181 sw->ar_fpsr = FPSR_DEFAULT;
182 v->arch._thread.ksp = (unsigned long) sw - 16;
183 // stay on kernel stack because may get interrupts!
184 // ia64_ret_from_clone (which b0 gets in new_thread) switches
185 // to user stack
186 v->arch._thread.on_ustack = 0;
187 memset(v->arch._thread.fph,0,sizeof(struct ia64_fpreg)*96);
188 }
190 #ifdef CONFIG_VTI
191 void arch_do_createdomain(struct vcpu *v)
192 {
193 struct domain *d = v->domain;
194 struct thread_info *ti = alloc_thread_info(v);
196 /* Clear thread_info to clear some important fields, like preempt_count */
197 memset(ti, 0, sizeof(struct thread_info));
198 init_switch_stack(v);
200 /* Shared info area is required to be allocated at domain
201 * creation, since control panel will write some I/O info
202 * between front end and back end to that area. However for
203 * vmx domain, our design is to let domain itself to allcoate
204 * shared info area, to keep machine page contiguous. So this
205 * page will be released later when domainN issues request
206 * after up.
207 */
208 d->shared_info = (void *)alloc_xenheap_page();
209 /* Now assume all vcpu info and event indicators can be
210 * held in one shared page. Definitely later we need to
211 * consider more about it
212 */
214 memset(d->shared_info, 0, PAGE_SIZE);
215 v->vcpu_info = &d->shared_info->vcpu_data[v->vcpu_id];
216 /* Mask all events, and specific port will be unmasked
217 * when customer subscribes to it.
218 */
219 if(v == d->vcpu[0]) {
220 memset(&d->shared_info->evtchn_mask[0], 0xff,
221 sizeof(d->shared_info->evtchn_mask));
222 }
224 /* Allocate per-domain vTLB and vhpt */
225 v->arch.vtlb = init_domain_tlb(v);
227 /* Physical->machine page table will be allocated when
228 * final setup, since we have no the maximum pfn number in
229 * this stage
230 */
232 /* FIXME: This is identity mapped address for xenheap.
233 * Do we need it at all?
234 */
235 d->xen_vastart = 0xf000000000000000;
236 d->xen_vaend = 0xf300000000000000;
237 d->arch.breakimm = 0x1000;
238 }
239 #else // CONFIG_VTI
240 void arch_do_createdomain(struct vcpu *v)
241 {
242 struct domain *d = v->domain;
243 struct thread_info *ti = alloc_thread_info(v);
245 /* Clear thread_info to clear some important fields, like preempt_count */
246 memset(ti, 0, sizeof(struct thread_info));
247 init_switch_stack(v);
249 d->shared_info = (void *)alloc_xenheap_page();
250 if (!d->shared_info) {
251 printk("ERROR/HALTING: CAN'T ALLOC PAGE\n");
252 while (1);
253 }
254 memset(d->shared_info, 0, PAGE_SIZE);
255 v->vcpu_info = &(d->shared_info->vcpu_data[0]);
257 d->max_pages = (128*1024*1024)/PAGE_SIZE; // 128MB default // FIXME
258 if ((d->arch.metaphysical_rr0 = allocate_metaphysical_rr0()) == -1UL)
259 BUG();
260 v->vcpu_info->arch.metaphysical_mode = 1;
261 v->arch.metaphysical_rr0 = d->arch.metaphysical_rr0;
262 v->arch.metaphysical_saved_rr0 = d->arch.metaphysical_rr0;
263 #define DOMAIN_RID_BITS_DEFAULT 18
264 if (!allocate_rid_range(d,DOMAIN_RID_BITS_DEFAULT)) // FIXME
265 BUG();
266 v->arch.starting_rid = d->arch.starting_rid;
267 v->arch.ending_rid = d->arch.ending_rid;
268 // the following will eventually need to be negotiated dynamically
269 d->xen_vastart = 0xf000000000000000;
270 d->xen_vaend = 0xf300000000000000;
271 d->shared_info_va = 0xf100000000000000;
272 d->arch.breakimm = 0x1000;
273 v->arch.breakimm = d->arch.breakimm;
275 d->arch.mm = xmalloc(struct mm_struct);
276 if (unlikely(!d->arch.mm)) {
277 printk("Can't allocate mm_struct for domain %d\n",d->domain_id);
278 return -ENOMEM;
279 }
280 memset(d->arch.mm, 0, sizeof(*d->arch.mm));
281 d->arch.mm->pgd = pgd_alloc(d->arch.mm);
282 if (unlikely(!d->arch.mm->pgd)) {
283 printk("Can't allocate pgd for domain %d\n",d->domain_id);
284 return -ENOMEM;
285 }
286 }
287 #endif // CONFIG_VTI
289 void arch_getdomaininfo_ctxt(struct vcpu *v, struct vcpu_guest_context *c)
290 {
291 struct pt_regs *regs = (struct pt_regs *) ((unsigned long) v + IA64_STK_OFFSET) - 1;
293 printf("arch_getdomaininfo_ctxt\n");
294 c->regs = *regs;
295 c->vcpu = v->vcpu_info->arch;
296 c->shared = v->domain->shared_info->arch;
297 }
299 #ifndef CONFIG_VTI
300 int arch_set_info_guest(struct vcpu *v, struct vcpu_guest_context *c)
301 {
302 struct pt_regs *regs = (struct pt_regs *) ((unsigned long) v + IA64_STK_OFFSET) - 1;
304 printf("arch_set_info_guest\n");
305 *regs = c->regs;
306 regs->cr_ipsr = IA64_PSR_IT|IA64_PSR_DT|IA64_PSR_RT|IA64_PSR_IC|IA64_PSR_I|IA64_PSR_DFH|IA64_PSR_BN|IA64_PSR_SP|IA64_PSR_DI;
307 regs->cr_ipsr |= 2UL << IA64_PSR_CPL0_BIT;
308 regs->ar_rsc |= (2 << 2); /* force PL2/3 */
310 v->vcpu_info->arch = c->vcpu;
311 init_all_rr(v);
313 // this should be in userspace
314 regs->r28 = dom_fw_setup(v->domain,"nomca nosmp xencons=ttyS console=ttyS0",256L); //FIXME
315 v->vcpu_info->arch.banknum = 1;
316 v->vcpu_info->arch.metaphysical_mode = 1;
318 v->domain->shared_info->arch = c->shared;
319 return 0;
320 }
321 #else // CONFIG_VTI
322 int arch_set_info_guest(
323 struct vcpu *v, struct vcpu_guest_context *c)
324 {
325 struct domain *d = v->domain;
326 int i, rc, ret;
327 unsigned long progress = 0;
329 if ( test_bit(_VCPUF_initialised, &v->vcpu_flags) )
330 return 0;
332 /* Lazy FP not implemented yet */
333 clear_bit(_VCPUF_fpu_initialised, &v->vcpu_flags);
334 if ( c->flags & VGCF_FPU_VALID )
335 set_bit(_VCPUF_fpu_initialised, &v->vcpu_flags);
337 /* Sync d/i cache conservatively, after domain N is loaded */
338 ret = ia64_pal_cache_flush(3, 0, &progress, NULL);
339 if (ret != PAL_STATUS_SUCCESS)
340 panic("PAL CACHE FLUSH failed for dom[%d].\n",
341 v->domain->domain_id);
342 DPRINTK("Sync i/d cache for dom%d image SUCC\n",
343 v->domain->domain_id);
345 /* Physical mode emulation initialization, including
346 * emulation ID allcation and related memory request
347 */
348 physical_mode_init(v);
350 /* FIXME: only support PMT table continuously by far */
351 d->arch.pmt = __va(c->pt_base);
352 d->arch.max_pfn = c->pt_max_pfn;
353 v->arch.arch_vmx.vmx_platform.shared_page_va = __va(c->share_io_pg);
354 memset((char *)__va(c->share_io_pg),0,PAGE_SIZE);
356 if (c->flags & VGCF_VMX_GUEST) {
357 if (!vmx_enabled)
358 panic("No VMX hardware feature for vmx domain.\n");
360 vmx_final_setup_domain(d);
362 /* One more step to enable interrupt assist */
363 set_bit(ARCH_VMX_INTR_ASSIST, &v->arch.arch_vmx.flags);
364 }
366 vlsapic_reset(v);
367 vtm_init(v);
369 /* Only open one port for I/O and interrupt emulation */
370 if (v == d->vcpu[0]) {
371 memset(&d->shared_info->evtchn_mask[0], 0xff,
372 sizeof(d->shared_info->evtchn_mask));
373 clear_bit(IOPACKET_PORT, &d->shared_info->evtchn_mask[0]);
374 }
375 /* Setup domain context. Actually IA-64 is a bit different with
376 * x86, with almost all system resources better managed by HV
377 * directly. CP only needs to provide start IP of guest, which
378 * ideally is the load address of guest Firmware.
379 */
380 new_thread(v, c->guest_iip, 0, 0);
383 d->xen_vastart = 0xf000000000000000;
384 d->xen_vaend = 0xf300000000000000;
385 d->arch.breakimm = 0x1000 + d->domain_id;
386 v->arch._thread.on_ustack = 0;
388 /* Don't redo final setup */
389 set_bit(_VCPUF_initialised, &v->vcpu_flags);
391 return 0;
392 }
393 #endif // CONFIG_VTI
395 void arch_do_boot_vcpu(struct vcpu *v)
396 {
397 printf("arch_do_boot_vcpu: not implemented\n");
398 return;
399 }
401 void domain_relinquish_resources(struct domain *d)
402 {
403 /* FIXME */
404 printf("domain_relinquish_resources: not implemented\n");
405 }
407 #ifdef CONFIG_VTI
408 void new_thread(struct vcpu *v,
409 unsigned long start_pc,
410 unsigned long start_stack,
411 unsigned long start_info)
412 {
413 struct domain *d = v->domain;
414 struct xen_regs *regs;
415 struct ia64_boot_param *bp;
416 extern char saved_command_line[];
417 //char *dom0_cmdline = "BOOT_IMAGE=scsi0:\EFI\redhat\xenlinux nomca root=/dev/sdb1 ro";
420 #ifdef CONFIG_DOMAIN0_CONTIGUOUS
421 if (d == dom0) start_pc += dom0_start;
422 #endif
424 regs = (struct pt_regs *) ((unsigned long) v + IA64_STK_OFFSET) - 1;
425 if (VMX_DOMAIN(v)) {
426 /* dt/rt/it:1;i/ic:1, si:1, vm/bn:1, ac:1 */
427 regs->cr_ipsr = 0x501008826008; /* Need to be expanded as macro */
428 } else {
429 regs->cr_ipsr = ia64_getreg(_IA64_REG_PSR)
430 | IA64_PSR_BITS_TO_SET | IA64_PSR_BN
431 & ~(IA64_PSR_BITS_TO_CLEAR | IA64_PSR_RI | IA64_PSR_IS);
432 regs->cr_ipsr |= 2UL << IA64_PSR_CPL0_BIT; // domain runs at PL2
433 }
434 regs->cr_iip = start_pc;
435 regs->cr_ifs = 0; /* why? - matthewc */
436 regs->ar_fpsr = FPSR_DEFAULT;
437 if (VMX_DOMAIN(v)) {
438 vmx_init_all_rr(v);
439 } else
440 init_all_rr(v);
442 if (VMX_DOMAIN(v)) {
443 if (d == dom0) {
444 VMX_VPD(v,vgr[12]) = dom_fw_setup(d,saved_command_line,256L);
445 printk("new_thread, done with dom_fw_setup\n");
446 }
447 /* Virtual processor context setup */
448 VMX_VPD(v, vpsr) = IA64_PSR_BN;
449 VPD_CR(v, dcr) = 0;
450 } else {
451 regs->r28 = dom_fw_setup(d,saved_command_line,256L);
452 v->vcpu_info->arch.banknum = 1;
453 v->vcpu_info->arch.metaphysical_mode = 1;
454 d->shared_info->arch.flags = (d == dom0) ? (SIF_INITDOMAIN|SIF_PRIVILEGED|SIF_BLK_BE_DOMAIN|SIF_NET_BE_DOMAIN|SIF_USB_BE_DOMAIN) : 0;
455 }
456 }
457 #else // CONFIG_VTI
459 // heavily leveraged from linux/arch/ia64/kernel/process.c:copy_thread()
460 // and linux/arch/ia64/kernel/process.c:kernel_thread()
461 void new_thread(struct vcpu *v,
462 unsigned long start_pc,
463 unsigned long start_stack,
464 unsigned long start_info)
465 {
466 struct domain *d = v->domain;
467 struct pt_regs *regs;
468 struct ia64_boot_param *bp;
469 extern char saved_command_line[];
471 #ifdef CONFIG_DOMAIN0_CONTIGUOUS
472 if (d == dom0) start_pc += dom0_start;
473 #endif
475 regs = (struct pt_regs *) ((unsigned long) v + IA64_STK_OFFSET) - 1;
476 regs->cr_ipsr = ia64_getreg(_IA64_REG_PSR)
477 | IA64_PSR_BITS_TO_SET | IA64_PSR_BN
478 & ~(IA64_PSR_BITS_TO_CLEAR | IA64_PSR_RI | IA64_PSR_IS);
479 regs->cr_ipsr |= 2UL << IA64_PSR_CPL0_BIT; // domain runs at PL2
480 regs->cr_iip = start_pc;
481 regs->cr_ifs = 1UL << 63;
482 regs->ar_fpsr = FPSR_DEFAULT;
483 init_all_rr(v);
484 regs->r28 = dom_fw_setup(d,saved_command_line,256L); //FIXME
485 v->vcpu_info->arch.banknum = 1;
486 v->vcpu_info->arch.metaphysical_mode = 1;
487 d->shared_info->arch.flags = (d == dom0) ? (SIF_INITDOMAIN|SIF_PRIVILEGED|SIF_BLK_BE_DOMAIN|SIF_NET_BE_DOMAIN|SIF_USB_BE_DOMAIN) : 0;
488 }
489 #endif // CONFIG_VTI
491 static struct page * map_new_domain0_page(unsigned long mpaddr)
492 {
493 if (mpaddr < dom0_start || mpaddr >= dom0_start + dom0_size) {
494 printk("map_new_domain0_page: bad domain0 mpaddr %p!\n",mpaddr);
495 printk("map_new_domain0_page: start=%p,end=%p!\n",dom0_start,dom0_start+dom0_size);
496 while(1);
497 }
498 return pfn_to_page((mpaddr >> PAGE_SHIFT));
499 }
501 /* allocate new page for domain and map it to the specified metaphysical addr */
502 struct page * map_new_domain_page(struct domain *d, unsigned long mpaddr)
503 {
504 struct mm_struct *mm = d->arch.mm;
505 struct page *p = (struct page *)0;
506 pgd_t *pgd;
507 pud_t *pud;
508 pmd_t *pmd;
509 pte_t *pte;
510 extern unsigned long vhpt_paddr, vhpt_pend;
512 if (!mm->pgd) {
513 printk("map_new_domain_page: domain pgd must exist!\n");
514 return(p);
515 }
516 pgd = pgd_offset(mm,mpaddr);
517 if (pgd_none(*pgd))
518 pgd_populate(mm, pgd, pud_alloc_one(mm,mpaddr));
520 pud = pud_offset(pgd, mpaddr);
521 if (pud_none(*pud))
522 pud_populate(mm, pud, pmd_alloc_one(mm,mpaddr));
524 pmd = pmd_offset(pud, mpaddr);
525 if (pmd_none(*pmd))
526 pmd_populate_kernel(mm, pmd, pte_alloc_one_kernel(mm,mpaddr));
527 // pmd_populate(mm, pmd, pte_alloc_one(mm,mpaddr));
529 pte = pte_offset_map(pmd, mpaddr);
530 if (pte_none(*pte)) {
531 #ifdef CONFIG_DOMAIN0_CONTIGUOUS
532 if (d == dom0) p = map_new_domain0_page(mpaddr);
533 else
534 #endif
535 {
536 p = alloc_domheap_page(d);
537 // zero out pages for security reasons
538 memset(__va(page_to_phys(p)),0,PAGE_SIZE);
539 }
540 if (unlikely(!p)) {
541 printf("map_new_domain_page: Can't alloc!!!! Aaaargh!\n");
542 return(p);
543 }
544 if (unlikely(page_to_phys(p) > vhpt_paddr && page_to_phys(p) < vhpt_pend)) {
545 printf("map_new_domain_page: reassigned vhpt page %p!!\n",page_to_phys(p));
546 }
547 set_pte(pte, pfn_pte(page_to_phys(p) >> PAGE_SHIFT,
548 __pgprot(__DIRTY_BITS | _PAGE_PL_2 | _PAGE_AR_RWX)));
549 }
550 else printk("map_new_domain_page: mpaddr %lx already mapped!\n",mpaddr);
551 return p;
552 }
554 /* map a physical address to the specified metaphysical addr */
555 void map_domain_page(struct domain *d, unsigned long mpaddr, unsigned long physaddr)
556 {
557 struct mm_struct *mm = d->arch.mm;
558 pgd_t *pgd;
559 pud_t *pud;
560 pmd_t *pmd;
561 pte_t *pte;
563 if (!mm->pgd) {
564 printk("map_domain_page: domain pgd must exist!\n");
565 return;
566 }
567 pgd = pgd_offset(mm,mpaddr);
568 if (pgd_none(*pgd))
569 pgd_populate(mm, pgd, pud_alloc_one(mm,mpaddr));
571 pud = pud_offset(pgd, mpaddr);
572 if (pud_none(*pud))
573 pud_populate(mm, pud, pmd_alloc_one(mm,mpaddr));
575 pmd = pmd_offset(pud, mpaddr);
576 if (pmd_none(*pmd))
577 pmd_populate_kernel(mm, pmd, pte_alloc_one_kernel(mm,mpaddr));
578 // pmd_populate(mm, pmd, pte_alloc_one(mm,mpaddr));
580 pte = pte_offset_map(pmd, mpaddr);
581 if (pte_none(*pte)) {
582 set_pte(pte, pfn_pte(physaddr >> PAGE_SHIFT,
583 __pgprot(__DIRTY_BITS | _PAGE_PL_2 | _PAGE_AR_RWX)));
584 }
585 else printk("map_domain_page: mpaddr %lx already mapped!\n",mpaddr);
586 }
588 void mpafoo(unsigned long mpaddr)
589 {
590 extern unsigned long privop_trace;
591 if (mpaddr == 0x3800)
592 privop_trace = 1;
593 }
595 unsigned long lookup_domain_mpa(struct domain *d, unsigned long mpaddr)
596 {
597 struct mm_struct *mm = d->arch.mm;
598 pgd_t *pgd = pgd_offset(mm, mpaddr);
599 pud_t *pud;
600 pmd_t *pmd;
601 pte_t *pte;
603 #ifdef CONFIG_DOMAIN0_CONTIGUOUS
604 if (d == dom0) {
605 if (mpaddr < dom0_start || mpaddr >= dom0_start + dom0_size) {
606 //printk("lookup_domain_mpa: bad dom0 mpaddr %p!\n",mpaddr);
607 //printk("lookup_domain_mpa: start=%p,end=%p!\n",dom0_start,dom0_start+dom0_size);
608 mpafoo(mpaddr);
609 }
610 pte_t pteval = pfn_pte(mpaddr >> PAGE_SHIFT,
611 __pgprot(__DIRTY_BITS | _PAGE_PL_2 | _PAGE_AR_RWX));
612 pte = &pteval;
613 return *(unsigned long *)pte;
614 }
615 #endif
616 tryagain:
617 if (pgd_present(*pgd)) {
618 pud = pud_offset(pgd,mpaddr);
619 if (pud_present(*pud)) {
620 pmd = pmd_offset(pud,mpaddr);
621 if (pmd_present(*pmd)) {
622 pte = pte_offset_map(pmd,mpaddr);
623 if (pte_present(*pte)) {
624 //printk("lookup_domain_page: found mapping for %lx, pte=%lx\n",mpaddr,pte_val(*pte));
625 return *(unsigned long *)pte;
626 }
627 }
628 }
629 }
630 /* if lookup fails and mpaddr is "legal", "create" the page */
631 if ((mpaddr >> PAGE_SHIFT) < d->max_pages) {
632 if (map_new_domain_page(d,mpaddr)) goto tryagain;
633 }
634 printk("lookup_domain_mpa: bad mpa %p (> %p\n",
635 mpaddr,d->max_pages<<PAGE_SHIFT);
636 mpafoo(mpaddr);
637 return 0;
638 }
640 // FIXME: ONLY USE FOR DOMAIN PAGE_SIZE == PAGE_SIZE
641 #ifndef CONFIG_VTI
642 unsigned long domain_mpa_to_imva(struct domain *d, unsigned long mpaddr)
643 {
644 unsigned long pte = lookup_domain_mpa(d,mpaddr);
645 unsigned long imva;
647 pte &= _PAGE_PPN_MASK;
648 imva = __va(pte);
649 imva |= mpaddr & ~PAGE_MASK;
650 return(imva);
651 }
652 #else // CONFIG_VTI
653 unsigned long domain_mpa_to_imva(struct domain *d, unsigned long mpaddr)
654 {
655 unsigned long imva = __gpa_to_mpa(d, mpaddr);
657 return __va(imva);
658 }
659 #endif // CONFIG_VTI
661 // remove following line if not privifying in memory
662 //#define HAVE_PRIVIFY_MEMORY
663 #ifndef HAVE_PRIVIFY_MEMORY
664 #define privify_memory(x,y) do {} while(0)
665 #endif
667 // see arch/x86/xxx/domain_build.c
668 int elf_sanity_check(Elf_Ehdr *ehdr)
669 {
670 return (IS_ELF(*ehdr));
671 }
673 static void copy_memory(void *dst, void *src, int size)
674 {
675 int remain;
677 if (IS_XEN_ADDRESS(dom0,src)) {
678 memcpy(dst,src,size);
679 }
680 else {
681 printf("About to call __copy_from_user(%p,%p,%d)\n",
682 dst,src,size);
683 while (remain = __copy_from_user(dst,src,size)) {
684 printf("incomplete user copy, %d remain of %d\n",
685 remain,size);
686 dst += size - remain; src += size - remain;
687 size -= remain;
688 }
689 }
690 }
692 void loaddomainelfimage(struct domain *d, unsigned long image_start)
693 {
694 char *elfbase = image_start;
695 //Elf_Ehdr *ehdr = (Elf_Ehdr *)image_start;
696 Elf_Ehdr ehdr;
697 Elf_Phdr phdr;
698 int h, filesz, memsz, paddr;
699 unsigned long elfaddr, dom_mpaddr, dom_imva;
700 struct page *p;
701 unsigned long pteval;
703 copy_memory(&ehdr,image_start,sizeof(Elf_Ehdr));
704 for ( h = 0; h < ehdr.e_phnum; h++ ) {
705 copy_memory(&phdr,elfbase + ehdr.e_phoff + (h*ehdr.e_phentsize),
706 sizeof(Elf_Phdr));
707 //if ( !is_loadable_phdr(phdr) )
708 if ((phdr.p_type != PT_LOAD)) {
709 continue;
710 }
711 filesz = phdr.p_filesz; memsz = phdr.p_memsz;
712 elfaddr = elfbase + phdr.p_offset;
713 dom_mpaddr = phdr.p_paddr;
714 //printf("p_offset: %x, size=%x\n",elfaddr,filesz);
715 #ifdef CONFIG_DOMAIN0_CONTIGUOUS
716 if (d == dom0) {
717 if (dom_mpaddr+memsz>dom0_size || dom_mpaddr+filesz>dom0_size) {
718 printf("Domain0 doesn't fit in allocated space!\n");
719 while(1);
720 }
721 dom_imva = __va(dom_mpaddr + dom0_start);
722 copy_memory(dom_imva,elfaddr,filesz);
723 if (memsz > filesz) memset(dom_imva+filesz,0,memsz-filesz);
724 //FIXME: This test for code seems to find a lot more than objdump -x does
725 if (phdr.p_flags & PF_X) privify_memory(dom_imva,filesz);
726 }
727 else
728 #endif
729 while (memsz > 0) {
730 #ifdef DOMU_AUTO_RESTART
731 pteval = lookup_domain_mpa(d,dom_mpaddr);
732 if (pteval) dom_imva = __va(pteval & _PFN_MASK);
733 else { printf("loaddomainelfimage: BAD!\n"); while(1); }
734 #else
735 p = map_new_domain_page(d,dom_mpaddr);
736 if (unlikely(!p)) BUG();
737 dom_imva = __va(page_to_phys(p));
738 #endif
739 if (filesz > 0) {
740 if (filesz >= PAGE_SIZE)
741 copy_memory(dom_imva,elfaddr,PAGE_SIZE);
742 else { // copy partial page, zero the rest of page
743 copy_memory(dom_imva,elfaddr,filesz);
744 memset(dom_imva+filesz,0,PAGE_SIZE-filesz);
745 }
746 //FIXME: This test for code seems to find a lot more than objdump -x does
747 if (phdr.p_flags & PF_X)
748 privify_memory(dom_imva,PAGE_SIZE);
749 }
750 else if (memsz > 0) // always zero out entire page
751 memset(dom_imva,0,PAGE_SIZE);
752 memsz -= PAGE_SIZE; filesz -= PAGE_SIZE;
753 elfaddr += PAGE_SIZE; dom_mpaddr += PAGE_SIZE;
754 }
755 }
756 }
758 int
759 parsedomainelfimage(char *elfbase, unsigned long elfsize, unsigned long *entry)
760 {
761 Elf_Ehdr ehdr;
763 copy_memory(&ehdr,elfbase,sizeof(Elf_Ehdr));
765 if ( !elf_sanity_check(&ehdr) ) {
766 printk("ELF sanity check failed.\n");
767 return -EINVAL;
768 }
770 if ( (ehdr.e_phoff + (ehdr.e_phnum * ehdr.e_phentsize)) > elfsize )
771 {
772 printk("ELF program headers extend beyond end of image.\n");
773 return -EINVAL;
774 }
776 if ( (ehdr.e_shoff + (ehdr.e_shnum * ehdr.e_shentsize)) > elfsize )
777 {
778 printk("ELF section headers extend beyond end of image.\n");
779 return -EINVAL;
780 }
782 #if 0
783 /* Find the section-header strings table. */
784 if ( ehdr.e_shstrndx == SHN_UNDEF )
785 {
786 printk("ELF image has no section-header strings table (shstrtab).\n");
787 return -EINVAL;
788 }
789 #endif
791 *entry = ehdr.e_entry;
792 printf("parsedomainelfimage: entry point = %p\n",*entry);
794 return 0;
795 }
798 void alloc_dom0(void)
799 {
800 #ifdef CONFIG_DOMAIN0_CONTIGUOUS
801 if (platform_is_hp_ski()) {
802 dom0_size = 128*1024*1024; //FIXME: Should be configurable
803 }
804 printf("alloc_dom0: starting (initializing %d MB...)\n",dom0_size/(1024*1024));
806 /* FIXME: The first trunk (say 256M) should always be assigned to
807 * Dom0, since Dom0's physical == machine address for DMA purpose.
808 * Some old version linux, like 2.4, assumes physical memory existing
809 * in 2nd 64M space.
810 */
811 dom0_start = alloc_boot_pages(
812 dom0_size >> PAGE_SHIFT, dom0_align >> PAGE_SHIFT);
813 dom0_start <<= PAGE_SHIFT;
814 if (!dom0_start) {
815 printf("construct_dom0: can't allocate contiguous memory size=%p\n",
816 dom0_size);
817 while(1);
818 }
819 printf("alloc_dom0: dom0_start=%p\n",dom0_start);
820 #else
821 dom0_start = 0;
822 #endif
824 }
826 #ifdef DOMU_BUILD_STAGING
827 void alloc_domU_staging(void)
828 {
829 domU_staging_size = 32*1024*1024; //FIXME: Should be configurable
830 printf("alloc_domU_staging: starting (initializing %d MB...)\n",domU_staging_size/(1024*1024));
831 domU_staging_start = alloc_boot_pages(
832 domU_staging_size >> PAGE_SHIFT, domU_staging_align >> PAGE_SHIFT);
833 domU_staging_start <<= PAGE_SHIFT;
834 if (!domU_staging_size) {
835 printf("alloc_domU_staging: can't allocate, spinning...\n");
836 while(1);
837 }
838 else domU_staging_area = (unsigned long *)__va(domU_staging_start);
839 printf("alloc_domU_staging: domU_staging_area=%p\n",domU_staging_area);
841 }
843 unsigned long
844 domU_staging_read_8(unsigned long at)
845 {
846 // no way to return errors so just do it
847 return domU_staging_area[at>>3];
849 }
851 unsigned long
852 domU_staging_write_32(unsigned long at, unsigned long a, unsigned long b,
853 unsigned long c, unsigned long d)
854 {
855 if (at + 32 > domU_staging_size) return -1;
856 if (at & 0x1f) return -1;
857 at >>= 3;
858 domU_staging_area[at++] = a;
859 domU_staging_area[at++] = b;
860 domU_staging_area[at++] = c;
861 domU_staging_area[at] = d;
862 return 0;
864 }
865 #endif
867 #ifdef CONFIG_VTI
868 /* Up to whether domain is vmx one, different context may be setup
869 * here.
870 */
871 void
872 post_arch_do_create_domain(struct vcpu *v, int vmx_domain)
873 {
874 struct domain *d = v->domain;
876 if (!vmx_domain) {
877 d->shared_info = (void*)alloc_xenheap_page();
878 if (!d->shared_info)
879 panic("Allocate share info for non-vmx domain failed.\n");
880 d->shared_info_va = 0xfffd000000000000;
882 printk("Build shared info for non-vmx domain\n");
883 build_shared_info(d);
884 /* Setup start info area */
885 }
886 }
888 /* For VMX domain, this is invoked when kernel model in domain
889 * request actively
890 */
891 void build_shared_info(struct domain *d)
892 {
893 int i;
895 /* Set up shared-info area. */
896 update_dom_time(d);
897 d->shared_info->domain_time = 0;
899 /* Mask all upcalls... */
900 for ( i = 0; i < MAX_VIRT_CPUS; i++ )
901 d->shared_info->vcpu_data[i].evtchn_upcall_mask = 1;
903 /* ... */
904 }
906 /*
907 * Domain 0 has direct access to all devices absolutely. However
908 * the major point of this stub here, is to allow alloc_dom_mem
909 * handled with order > 0 request. Dom0 requires that bit set to
910 * allocate memory for other domains.
911 */
912 void physdev_init_dom0(struct domain *d)
913 {
914 set_bit(_DOMF_physdev_access, &d->domain_flags);
915 }
917 extern unsigned long running_on_sim;
918 unsigned int vmx_dom0 = 0;
919 int construct_dom0(struct domain *d,
920 unsigned long image_start, unsigned long image_len,
921 unsigned long initrd_start, unsigned long initrd_len,
922 char *cmdline)
923 {
924 char *dst;
925 int i, rc;
926 unsigned long pfn, mfn;
927 unsigned long nr_pt_pages;
928 unsigned long count;
929 unsigned long alloc_start, alloc_end;
930 struct pfn_info *page = NULL;
931 start_info_t *si;
932 struct vcpu *v = d->vcpu[0];
933 struct domain_setup_info dsi;
934 unsigned long p_start;
935 unsigned long pkern_start;
936 unsigned long pkern_entry;
937 unsigned long pkern_end;
938 unsigned long ret;
939 unsigned long progress = 0;
941 //printf("construct_dom0: starting\n");
942 /* Sanity! */
943 #ifndef CLONE_DOMAIN0
944 if ( d != dom0 )
945 BUG();
946 if ( test_bit(_DOMF_constructed, &d->domain_flags) )
947 BUG();
948 #endif
950 printk("##Dom0: 0x%lx, domain: 0x%lx\n", (u64)dom0, (u64)d);
951 memset(&dsi, 0, sizeof(struct domain_setup_info));
953 printk("*** LOADING DOMAIN 0 ***\n");
955 alloc_start = dom0_start;
956 alloc_end = dom0_start + dom0_size;
957 d->tot_pages = d->max_pages = (alloc_end - alloc_start)/PAGE_SIZE;
958 image_start = __va(ia64_boot_param->initrd_start);
959 image_len = ia64_boot_param->initrd_size;
961 dsi.image_addr = (unsigned long)image_start;
962 dsi.image_len = image_len;
963 rc = parseelfimage(&dsi);
964 if ( rc != 0 )
965 return rc;
967 /* Temp workaround */
968 if (running_on_sim)
969 dsi.xen_section_string = (char *)1;
971 if ((!vmx_enabled) && !dsi.xen_section_string) {
972 printk("Lack of hardware support for unmodified vmx dom0\n");
973 panic("");
974 }
976 if (vmx_enabled && !dsi.xen_section_string) {
977 printk("Dom0 is vmx domain!\n");
978 vmx_dom0 = 1;
979 }
981 p_start = dsi.v_start;
982 pkern_start = dsi.v_kernstart;
983 pkern_end = dsi.v_kernend;
984 pkern_entry = dsi.v_kernentry;
986 printk("p_start=%lx, pkern_start=%lx, pkern_end=%lx, pkern_entry=%lx\n",
987 p_start,pkern_start,pkern_end,pkern_entry);
989 if ( (p_start & (PAGE_SIZE-1)) != 0 )
990 {
991 printk("Initial guest OS must load to a page boundary.\n");
992 return -EINVAL;
993 }
995 printk("METAPHYSICAL MEMORY ARRANGEMENT:\n"
996 " Kernel image: %lx->%lx\n"
997 " Entry address: %lx\n"
998 " Init. ramdisk: (NOT IMPLEMENTED YET)\n",
999 pkern_start, pkern_end, pkern_entry);
1001 if ( (pkern_end - pkern_start) > (d->max_pages * PAGE_SIZE) )
1003 printk("Initial guest OS requires too much space\n"
1004 "(%luMB is greater than %luMB limit)\n",
1005 (pkern_end-pkern_start)>>20, (d->max_pages<<PAGE_SHIFT)>>20);
1006 return -ENOMEM;
1009 // Other sanity check about Dom0 image
1011 /* Construct a frame-allocation list for the initial domain, since these
1012 * pages are allocated by boot allocator and pfns are not set properly
1013 */
1014 for ( mfn = (alloc_start>>PAGE_SHIFT);
1015 mfn < (alloc_end>>PAGE_SHIFT);
1016 mfn++ )
1018 page = &frame_table[mfn];
1019 page_set_owner(page, d);
1020 page->u.inuse.type_info = 0;
1021 page->count_info = PGC_allocated | 1;
1022 list_add_tail(&page->list, &d->page_list);
1024 /* Construct 1:1 mapping */
1025 machine_to_phys_mapping[mfn] = mfn;
1028 post_arch_do_create_domain(v, vmx_dom0);
1030 /* Load Dom0 image to its own memory */
1031 loaddomainelfimage(d,image_start);
1033 /* Copy the initial ramdisk. */
1035 /* Sync d/i cache conservatively */
1036 ret = ia64_pal_cache_flush(4, 0, &progress, NULL);
1037 if (ret != PAL_STATUS_SUCCESS)
1038 panic("PAL CACHE FLUSH failed for dom0.\n");
1039 printk("Sync i/d cache for dom0 image SUCC\n");
1041 /* Physical mode emulation initialization, including
1042 * emulation ID allcation and related memory request
1043 */
1044 physical_mode_init(v);
1045 /* Dom0's pfn is equal to mfn, so there's no need to allocate pmt
1046 * for dom0
1047 */
1048 d->arch.pmt = NULL;
1050 /* Give up the VGA console if DOM0 is configured to grab it. */
1051 if (cmdline != NULL)
1052 console_endboot(strstr(cmdline, "tty0") != NULL);
1054 /* VMX specific construction for Dom0, if hardware supports VMX
1055 * and Dom0 is unmodified image
1056 */
1057 printk("Dom0: 0x%lx, domain: 0x%lx\n", (u64)dom0, (u64)d);
1058 if (vmx_dom0)
1059 vmx_final_setup_domain(dom0);
1061 /* vpd is ready now */
1062 vlsapic_reset(v);
1063 vtm_init(v);
1065 set_bit(_DOMF_constructed, &d->domain_flags);
1066 new_thread(v, pkern_entry, 0, 0);
1068 physdev_init_dom0(d);
1069 // FIXME: Hack for keyboard input
1070 #ifdef CLONE_DOMAIN0
1071 if (d == dom0)
1072 #endif
1073 serial_input_init();
1074 if (d == dom0) {
1075 v->vcpu_info->arch.delivery_mask[0] = -1L;
1076 v->vcpu_info->arch.delivery_mask[1] = -1L;
1077 v->vcpu_info->arch.delivery_mask[2] = -1L;
1078 v->vcpu_info->arch.delivery_mask[3] = -1L;
1080 else __set_bit(0x30,v->vcpu_info->arch.delivery_mask);
1082 return 0;
1086 #else //CONFIG_VTI
1088 int construct_dom0(struct domain *d,
1089 unsigned long image_start, unsigned long image_len,
1090 unsigned long initrd_start, unsigned long initrd_len,
1091 char *cmdline)
1093 char *dst;
1094 int i, rc;
1095 unsigned long pfn, mfn;
1096 unsigned long nr_pt_pages;
1097 unsigned long count;
1098 //l2_pgentry_t *l2tab, *l2start;
1099 //l1_pgentry_t *l1tab = NULL, *l1start = NULL;
1100 struct pfn_info *page = NULL;
1101 start_info_t *si;
1102 struct vcpu *v = d->vcpu[0];
1104 struct domain_setup_info dsi;
1105 unsigned long p_start;
1106 unsigned long pkern_start;
1107 unsigned long pkern_entry;
1108 unsigned long pkern_end;
1110 //printf("construct_dom0: starting\n");
1111 /* Sanity! */
1112 #ifndef CLONE_DOMAIN0
1113 if ( d != dom0 )
1114 BUG();
1115 if ( test_bit(_DOMF_constructed, &d->domain_flags) )
1116 BUG();
1117 #endif
1119 memset(&dsi, 0, sizeof(struct domain_setup_info));
1121 printk("*** LOADING DOMAIN 0 ***\n");
1123 d->max_pages = dom0_size/PAGE_SIZE;
1124 image_start = __va(ia64_boot_param->initrd_start);
1125 image_len = ia64_boot_param->initrd_size;
1126 //printk("image_start=%lx, image_len=%lx\n",image_start,image_len);
1127 //printk("First word of image: %lx\n",*(unsigned long *)image_start);
1129 //printf("construct_dom0: about to call parseelfimage\n");
1130 dsi.image_addr = (unsigned long)image_start;
1131 dsi.image_len = image_len;
1132 rc = parseelfimage(&dsi);
1133 if ( rc != 0 )
1134 return rc;
1136 p_start = dsi.v_start;
1137 pkern_start = dsi.v_kernstart;
1138 pkern_end = dsi.v_kernend;
1139 pkern_entry = dsi.v_kernentry;
1141 //printk("p_start=%lx, pkern_start=%lx, pkern_end=%lx, pkern_entry=%lx\n",p_start,pkern_start,pkern_end,pkern_entry);
1143 if ( (p_start & (PAGE_SIZE-1)) != 0 )
1145 printk("Initial guest OS must load to a page boundary.\n");
1146 return -EINVAL;
1149 printk("METAPHYSICAL MEMORY ARRANGEMENT:\n"
1150 " Kernel image: %lx->%lx\n"
1151 " Entry address: %lx\n"
1152 " Init. ramdisk: (NOT IMPLEMENTED YET)\n",
1153 pkern_start, pkern_end, pkern_entry);
1155 if ( (pkern_end - pkern_start) > (d->max_pages * PAGE_SIZE) )
1157 printk("Initial guest OS requires too much space\n"
1158 "(%luMB is greater than %luMB limit)\n",
1159 (pkern_end-pkern_start)>>20, (d->max_pages<<PAGE_SHIFT)>>20);
1160 return -ENOMEM;
1163 // if high 3 bits of pkern start are non-zero, error
1165 // if pkern end is after end of metaphysical memory, error
1166 // (we should be able to deal with this... later)
1169 //
1171 #if 0
1172 strcpy(d->name,"Domain0");
1173 #endif
1175 /* Mask all upcalls... */
1176 for ( i = 0; i < MAX_VIRT_CPUS; i++ )
1177 d->shared_info->vcpu_data[i].evtchn_upcall_mask = 1;
1179 /* Copy the OS image. */
1180 //(void)loadelfimage(image_start);
1181 loaddomainelfimage(d,image_start);
1183 /* Copy the initial ramdisk. */
1184 //if ( initrd_len != 0 )
1185 // memcpy((void *)vinitrd_start, initrd_start, initrd_len);
1187 #if 0
1188 /* Set up start info area. */
1189 //si = (start_info_t *)vstartinfo_start;
1190 memset(si, 0, PAGE_SIZE);
1191 si->nr_pages = d->tot_pages;
1192 si->shared_info = virt_to_phys(d->shared_info);
1193 si->flags = SIF_PRIVILEGED | SIF_INITDOMAIN;
1194 //si->pt_base = vpt_start;
1195 //si->nr_pt_frames = nr_pt_pages;
1196 //si->mfn_list = vphysmap_start;
1198 if ( initrd_len != 0 )
1200 //si->mod_start = vinitrd_start;
1201 si->mod_len = initrd_len;
1202 printk("Initrd len 0x%lx, start at 0x%08lx\n",
1203 si->mod_len, si->mod_start);
1206 dst = si->cmd_line;
1207 if ( cmdline != NULL )
1209 for ( i = 0; i < 255; i++ )
1211 if ( cmdline[i] == '\0' )
1212 break;
1213 *dst++ = cmdline[i];
1216 *dst = '\0';
1218 zap_low_mappings(); /* Do the same for the idle page tables. */
1219 #endif
1221 /* Give up the VGA console if DOM0 is configured to grab it. */
1222 #ifdef IA64
1223 if (cmdline != NULL)
1224 #endif
1225 console_endboot(strstr(cmdline, "tty0") != NULL);
1227 set_bit(_DOMF_constructed, &d->domain_flags);
1229 new_thread(v, pkern_entry, 0, 0);
1230 // FIXME: Hack for keyboard input
1231 #ifdef CLONE_DOMAIN0
1232 if (d == dom0)
1233 #endif
1234 serial_input_init();
1235 if (d == dom0) {
1236 v->vcpu_info->arch.delivery_mask[0] = -1L;
1237 v->vcpu_info->arch.delivery_mask[1] = -1L;
1238 v->vcpu_info->arch.delivery_mask[2] = -1L;
1239 v->vcpu_info->arch.delivery_mask[3] = -1L;
1241 else __set_bit(0x30,v->vcpu_info->arch.delivery_mask);
1243 return 0;
1245 #endif // CONFIG_VTI
1247 // FIXME: When dom0 can construct domains, this goes away (or is rewritten)
1248 int construct_domU(struct domain *d,
1249 unsigned long image_start, unsigned long image_len,
1250 unsigned long initrd_start, unsigned long initrd_len,
1251 char *cmdline)
1253 int i, rc;
1254 struct vcpu *v = d->vcpu[0];
1255 unsigned long pkern_entry;
1257 #ifndef DOMU_AUTO_RESTART
1258 if ( test_bit(_DOMF_constructed, &d->domain_flags) ) BUG();
1259 #endif
1261 printk("*** LOADING DOMAIN %d ***\n",d->domain_id);
1263 d->max_pages = dom0_size/PAGE_SIZE; // FIXME: use dom0 size
1264 // FIXME: use domain0 command line
1265 rc = parsedomainelfimage(image_start, image_len, &pkern_entry);
1266 printk("parsedomainelfimage returns %d\n",rc);
1267 if ( rc != 0 ) return rc;
1269 /* Mask all upcalls... */
1270 for ( i = 0; i < MAX_VIRT_CPUS; i++ )
1271 d->shared_info->vcpu_data[i].evtchn_upcall_mask = 1;
1273 /* Copy the OS image. */
1274 printk("calling loaddomainelfimage(%p,%p)\n",d,image_start);
1275 loaddomainelfimage(d,image_start);
1276 printk("loaddomainelfimage returns\n");
1278 set_bit(_DOMF_constructed, &d->domain_flags);
1280 printk("calling new_thread, entry=%p\n",pkern_entry);
1281 #ifdef DOMU_AUTO_RESTART
1282 v->domain->arch.image_start = image_start;
1283 v->domain->arch.image_len = image_len;
1284 v->domain->arch.entry = pkern_entry;
1285 #endif
1286 new_thread(v, pkern_entry, 0, 0);
1287 printk("new_thread returns\n");
1288 __set_bit(0x30,v->vcpu_info->arch.delivery_mask);
1290 return 0;
1293 #ifdef DOMU_AUTO_RESTART
1294 void reconstruct_domU(struct vcpu *v)
1296 /* re-copy the OS image to reset data values to original */
1297 printk("reconstruct_domU: restarting domain %d...\n",
1298 v->domain->domain_id);
1299 loaddomainelfimage(v->domain,v->domain->arch.image_start);
1300 new_thread(v, v->domain->arch.entry, 0, 0);
1302 #endif
1304 // FIXME: When dom0 can construct domains, this goes away (or is rewritten)
1305 int launch_domainU(unsigned long size)
1307 #ifdef CLONE_DOMAIN0
1308 static int next = CLONE_DOMAIN0+1;
1309 #else
1310 static int next = 1;
1311 #endif
1313 struct domain *d = do_createdomain(next,0);
1314 if (!d) {
1315 printf("launch_domainU: couldn't create\n");
1316 return 1;
1318 else next++;
1319 if (construct_domU(d, (unsigned long)domU_staging_area, size,0,0,0)) {
1320 printf("launch_domainU: couldn't construct(id=%d,%lx,%lx)\n",
1321 d->domain_id,domU_staging_area,size);
1322 return 2;
1324 domain_unpause_by_systemcontroller(d);
1327 void machine_restart(char * __unused)
1329 if (platform_is_hp_ski()) dummy();
1330 printf("machine_restart called: spinning....\n");
1331 while(1);
1334 void machine_halt(void)
1336 if (platform_is_hp_ski()) dummy();
1337 printf("machine_halt called: spinning....\n");
1338 while(1);
1341 void dummy_called(char *function)
1343 if (platform_is_hp_ski()) asm("break 0;;");
1344 printf("dummy called in %s: spinning....\n", function);
1345 while(1);
1349 #if 0
1350 void switch_to(struct vcpu *prev, struct vcpu *next)
1352 struct vcpu *last;
1354 __switch_to(prev,next,last);
1355 //set_current(next);
1357 #endif
1359 void domain_pend_keyboard_interrupt(int irq)
1361 vcpu_pend_interrupt(dom0->vcpu[0],irq);