ia64/xen-unstable

changeset 8613:a9ead230cc60

Complete arch_domain_create refactoring for ia64.

Signed-off-by: Kevin Tian <kevin.tian@intel.com>
author kaf24@firebug.cl.cam.ac.uk
date Mon Jan 16 14:47:31 2006 +0100 (2006-01-16)
parents d783bdd14f2e
children bd606783c6bf
files xen/arch/ia64/xen/domain.c
line diff
     1.1 --- a/xen/arch/ia64/xen/domain.c	Sat Jan 14 23:40:09 2006 +0100
     1.2 +++ b/xen/arch/ia64/xen/domain.c	Mon Jan 16 14:47:31 2006 +0100
     1.3 @@ -65,6 +65,7 @@ extern int readelfimage_base_and_size(ch
     1.4  
     1.5  unsigned long map_domain_page0(struct domain *);
     1.6  extern unsigned long dom_fw_setup(struct domain *, char *, int);
     1.7 +static void init_switch_stack(struct vcpu *v);
     1.8  
     1.9  /* this belongs in include/asm, but there doesn't seem to be a suitable place */
    1.10  void arch_domain_destroy(struct domain *d)
    1.11 @@ -145,27 +146,45 @@ void startup_cpu_idle_loop(void)
    1.12  struct vcpu *alloc_vcpu_struct(struct domain *d, unsigned int vcpu_id)
    1.13  {
    1.14  	struct vcpu *v;
    1.15 +	struct thread_info *ti;
    1.16  
    1.17  	/* Still keep idle vcpu0 static allocated at compilation, due
    1.18  	 * to some code from Linux still requires it in early phase.
    1.19  	 */
    1.20  	if (is_idle_domain(d) && !vcpu_id)
    1.21 -		return idle_vcpu[0];
    1.22 -
    1.23 -	if ((v = alloc_xenheap_pages(KERNEL_STACK_SIZE_ORDER)) == NULL)
    1.24 +	    v = idle_vcpu[0];
    1.25 +	else {
    1.26 +	    if ((v = alloc_xenheap_pages(KERNEL_STACK_SIZE_ORDER)) == NULL)
    1.27  		return NULL;
    1.28 +	    memset(v, 0, sizeof(*v)); 
    1.29 +	}
    1.30  
    1.31 -	memset(v, 0, sizeof(*v)); 
    1.32 -        memcpy(&v->arch, &idle_vcpu[0]->arch, sizeof(v->arch));
    1.33 +	ti = alloc_thread_info(v);
    1.34 +	/* Clear thread_info to clear some important fields, like
    1.35 +	 * preempt_count
    1.36 +	 */
    1.37 +	memset(ti, 0, sizeof(struct thread_info));
    1.38 +	init_switch_stack(v);
    1.39  
    1.40  	if (!is_idle_domain(d)) {
    1.41  	    v->arch.privregs = 
    1.42  		alloc_xenheap_pages(get_order(sizeof(mapped_regs_t)));
    1.43  	    BUG_ON(v->arch.privregs == NULL);
    1.44  	    memset(v->arch.privregs, 0, PAGE_SIZE);
    1.45 -	}
    1.46 +
    1.47 +	    if (!vcpu_id)
    1.48 +	    	memset(&d->shared_info->evtchn_mask[0], 0xff,
    1.49 +		    sizeof(d->shared_info->evtchn_mask));
    1.50  
    1.51 -	printf("arch_vcpu_info=%p\n", v->arch.privregs);
    1.52 +	    v->vcpu_info = &(d->shared_info->vcpu_info[0]);
    1.53 +	    v->arch.metaphysical_rr0 = d->arch.metaphysical_rr0;
    1.54 +	    v->arch.metaphysical_rr4 = d->arch.metaphysical_rr4;
    1.55 +	    v->arch.metaphysical_saved_rr0 = d->arch.metaphysical_rr0;
    1.56 +	    v->arch.metaphysical_saved_rr4 = d->arch.metaphysical_rr4;
    1.57 +	    v->arch.starting_rid = d->arch.starting_rid;
    1.58 +	    v->arch.ending_rid = d->arch.ending_rid;
    1.59 +	    v->arch.breakimm = d->arch.breakimm;
    1.60 +	}
    1.61  
    1.62  	return v;
    1.63  }
    1.64 @@ -195,34 +214,19 @@ static void init_switch_stack(struct vcp
    1.65  
    1.66  int arch_domain_create(struct domain *d)
    1.67  {
    1.68 -	struct thread_info *ti = alloc_thread_info(v);
    1.69 -
    1.70 -	/* Clear thread_info to clear some important fields, like preempt_count */
    1.71 -	memset(ti, 0, sizeof(struct thread_info));
    1.72 -	init_switch_stack(v);
    1.73 -
    1.74  	// the following will eventually need to be negotiated dynamically
    1.75  	d->xen_vastart = XEN_START_ADDR;
    1.76  	d->xen_vaend = XEN_END_ADDR;
    1.77  	d->shared_info_va = SHAREDINFO_ADDR;
    1.78  
    1.79 -	if (is_idle_vcpu(v))
    1.80 +	if (is_idle_domain(d))
    1.81  	    return 0;
    1.82  
    1.83 -	d->shared_info = (void *)alloc_xenheap_page();
    1.84 -	if (!d->shared_info) {
    1.85 -   		printk("ERROR/HALTING: CAN'T ALLOC PAGE\n");
    1.86 -   		while (1);
    1.87 -	}
    1.88 +	if ((d->shared_info = (void *)alloc_xenheap_page()) == NULL)
    1.89 +	    goto fail_nomem;
    1.90  	memset(d->shared_info, 0, PAGE_SIZE);
    1.91 -	if (v == d->vcpu[0])
    1.92 -	    memset(&d->shared_info->evtchn_mask[0], 0xff,
    1.93 -		sizeof(d->shared_info->evtchn_mask));
    1.94 -
    1.95 -	v->vcpu_info = &(d->shared_info->vcpu_info[0]);
    1.96  
    1.97  	d->max_pages = (128UL*1024*1024)/PAGE_SIZE; // 128MB default // FIXME
    1.98 -
    1.99  	/* We may also need emulation rid for region4, though it's unlikely
   1.100  	 * to see guest issue uncacheable access in metaphysical mode. But
   1.101  	 * keep such info here may be more sane.
   1.102 @@ -230,34 +234,27 @@ int arch_domain_create(struct domain *d)
   1.103  	if (((d->arch.metaphysical_rr0 = allocate_metaphysical_rr()) == -1UL)
   1.104  	 || ((d->arch.metaphysical_rr4 = allocate_metaphysical_rr()) == -1UL))
   1.105  		BUG();
   1.106 -//	VCPU(v, metaphysical_mode) = 1;
   1.107 -	v->arch.metaphysical_rr0 = d->arch.metaphysical_rr0;
   1.108 -	v->arch.metaphysical_rr4 = d->arch.metaphysical_rr4;
   1.109 -	v->arch.metaphysical_saved_rr0 = d->arch.metaphysical_rr0;
   1.110 -	v->arch.metaphysical_saved_rr4 = d->arch.metaphysical_rr4;
   1.111  #define DOMAIN_RID_BITS_DEFAULT 18
   1.112  	if (!allocate_rid_range(d,DOMAIN_RID_BITS_DEFAULT)) // FIXME
   1.113  		BUG();
   1.114 -	v->arch.starting_rid = d->arch.starting_rid;
   1.115 -	v->arch.ending_rid = d->arch.ending_rid;
   1.116  	d->arch.breakimm = 0x1000;
   1.117 -	v->arch.breakimm = d->arch.breakimm;
   1.118 -
   1.119  	d->arch.sys_pgnr = 0;
   1.120 -	d->arch.mm = xmalloc(struct mm_struct);
   1.121 -	if (unlikely(!d->arch.mm)) {
   1.122 -		printk("Can't allocate mm_struct for domain %d\n",d->domain_id);
   1.123 -		return -ENOMEM;
   1.124 -	}
   1.125 +
   1.126 +	if ((d->arch.mm = xmalloc(struct mm_struct)) == NULL)
   1.127 +	    goto fail_nomem;
   1.128  	memset(d->arch.mm, 0, sizeof(*d->arch.mm));
   1.129 -	d->arch.mm->pgd = pgd_alloc(d->arch.mm);
   1.130 -	if (unlikely(!d->arch.mm->pgd)) {
   1.131 -		printk("Can't allocate pgd for domain %d\n",d->domain_id);
   1.132 -		return -ENOMEM;
   1.133 -	}
   1.134 +
   1.135 +	if ((d->arch.mm->pgd = pgd_alloc(d->arch.mm)) == NULL)
   1.136 +	    goto fail_nomem;
   1.137 +
   1.138  	printf ("arch_domain_create: domain=%p\n", d);
   1.139 +	return 0;
   1.140  
   1.141 -	return 0;
   1.142 +fail_nomem:
   1.143 +	free_xenheap_page(d->shared_info);
   1.144 +	xfree(d->arch.mm);
   1.145 +	pgd_free(d->arch.mm->pgd);
   1.146 +	return -ENOMEM;
   1.147  }
   1.148  
   1.149  void arch_getdomaininfo_ctxt(struct vcpu *v, struct vcpu_guest_context *c)