ia64/xen-unstable

changeset 16217:c17bfb091790

[IA64] Make Xen relocatable

1. Put xenheap at 0xf400000004000000, then xenheap doesn't
overlap with identity mapping.
2. Xen itself can be relocated by OS loader if there is no
low memory in platform.
3. Use another DTR for mapping xenheap

Signed-off-by: Anthony Xu <anthony.xu@intel.com>
author Alex Williamson <alex.williamson@hp.com>
date Tue Oct 30 11:33:55 2007 -0600 (2007-10-30)
parents 9adec82f7bfe
children a07288a84785
files xen/arch/ia64/linux-xen/head.S xen/arch/ia64/vmx/vmx_entry.S xen/arch/ia64/vmx/vmx_init.c xen/arch/ia64/xen/xenasm.S xen/include/asm-ia64/linux-xen/asm/io.h xen/include/asm-ia64/xenkregs.h xen/include/asm-ia64/xenpage.h xen/include/asm-ia64/xensystem.h
line diff
     1.1 --- a/xen/arch/ia64/linux-xen/head.S	Tue Oct 30 11:21:23 2007 -0600
     1.2 +++ b/xen/arch/ia64/linux-xen/head.S	Tue Oct 30 11:33:55 2007 -0600
     1.3 @@ -263,6 +263,16 @@ start_ap:
     1.4  	itr.d dtr[r16]=r18
     1.5  	;;
     1.6  	srlz.i
     1.7 +	;;
     1.8 +	/* XEN HEAP is identity mapped */
     1.9 +	mov r16 = IA64_TR_XEN_HEAP_REGS
    1.10 +	dep r17 = -1, r2, 60, 4
    1.11 +	;;
    1.12 +	mov cr.ifa = r17
    1.13 +	;;
    1.14 +	itr.d dtr[r16]=r18
    1.15 +	;;
    1.16 +	srlz.i
    1.17  
    1.18  	/*
    1.19  	 * Switch into virtual mode:
    1.20 @@ -294,7 +304,7 @@ 1:	// now we are in virtual mode
    1.21  	;;
    1.22  	srlz.i
    1.23  	movl gp=__gp
    1.24 -
    1.25 +	;;
    1.26  	mov ar.fpsr=r2
    1.27  	;;
    1.28  
     2.1 --- a/xen/arch/ia64/vmx/vmx_entry.S	Tue Oct 30 11:21:23 2007 -0600
     2.2 +++ b/xen/arch/ia64/vmx/vmx_entry.S	Tue Oct 30 11:33:55 2007 -0600
     2.3 @@ -677,13 +677,23 @@ 1:
     2.4      ;;
     2.5      dep r2=0,r3,0,KERNEL_TR_PAGE_SHIFT
     2.6      ;;
     2.7 -    or r18=r2,r25
     2.8 +    or r24=r2,r25
     2.9      ;;
    2.10     srlz.i
    2.11     ;;
    2.12 -   itr.i itr[r16]=r18
    2.13 +   itr.i itr[r16]=r24
    2.14 +   ;;
    2.15 +   itr.d dtr[r16]=r24
    2.16     ;;
    2.17 -   itr.d dtr[r16]=r18
    2.18 +   /* xen heap is also identity mapped */
    2.19 +   mov r16 = IA64_TR_XEN_HEAP_REGS
    2.20 +   dep r17=-1,r3,60,4
    2.21 +   ;;
    2.22 +   ptr.d r17, r18
    2.23 +   ;;
    2.24 +   mov cr.ifa=r17
    2.25 +   ;;
    2.26 +   itr.d dtr[r16]=r24
    2.27     ;;
    2.28  
    2.29     // re-pin mappings for per-cpu data
     3.1 --- a/xen/arch/ia64/vmx/vmx_init.c	Tue Oct 30 11:21:23 2007 -0600
     3.2 +++ b/xen/arch/ia64/vmx/vmx_init.c	Tue Oct 30 11:33:55 2007 -0600
     3.3 @@ -117,6 +117,7 @@ vmx_init_env(void)
     3.4  	if (!vm_buffer) {
     3.5  		vm_buffer = (unsigned long)alloc_xenheap_pages(vm_order);
     3.6  		ASSERT(vm_buffer);
     3.7 +		vm_buffer = virt_to_xenva((vm_buffer));
     3.8  		printk("vm_buffer: 0x%lx\n", vm_buffer);
     3.9  	}
    3.10  
    3.11 @@ -162,6 +163,7 @@ static vpd_t *alloc_vpd(void)
    3.12  		printk("VPD allocation failed.\n");
    3.13  		return NULL;
    3.14  	}
    3.15 +	vpd = (vpd_t *)virt_to_xenva(vpd);
    3.16  
    3.17  	printk(XENLOG_DEBUG "vpd base: 0x%p, vpd size:%ld\n",
    3.18  	       vpd, sizeof(vpd_t));
     4.1 --- a/xen/arch/ia64/xen/xenasm.S	Tue Oct 30 11:21:23 2007 -0600
     4.2 +++ b/xen/arch/ia64/xen/xenasm.S	Tue Oct 30 11:33:55 2007 -0600
     4.3 @@ -60,19 +60,21 @@ 1:	{
     4.4  	mov ar.rsc=0			// put RSE in enforced lazy, LE mode
     4.5  	or loc3=loc3,r17		// add in psr the bits to set
     4.6  	;;
     4.7 +	movl loc5=pal_vaddr		// get pal_vaddr
     4.8 +	;;
     4.9 +	ld8 loc5=[loc5]			// read pal_vaddr
    4.10 +	;;
    4.11  	andcm r16=loc3,r16		// removes bits to clear from psr
    4.12  	dep loc6=0,r8,0,KERNEL_TR_PAGE_SHIFT // Xen code paddr
    4.13  	br.call.sptk.many rp=ia64_switch_mode_phys
    4.14  1:
    4.15  	// now in physical mode with psr.i/ic off so do rr7 switch
    4.16 -	movl r16=pal_vaddr		// Note: belong to region 7!
    4.17 +	dep r16=-1,r0,61,3		// Note: belong to region 7!
    4.18  	;; 
    4.19  	mov	rr[r16]=in0
    4.20  	;; 
    4.21  	srlz.d
    4.22 -	dep	r16=0,r16,60,4		// Get physical address.
    4.23  	;;
    4.24 -	ld8 loc5=[r16]			// read pal_vaddr
    4.25  	movl	r26=PAGE_KERNEL
    4.26  	;; 
    4.27  
    4.28 @@ -90,7 +92,17 @@ 1:
    4.29  	itr.i itr[r16]=r18
    4.30  	;; 
    4.31  	itr.d dtr[r16]=r18
    4.32 -
    4.33 +	;;
    4.34 +	/* xen heap is also identity mapped */
    4.35 +	mov r16 = IA64_TR_XEN_HEAP_REGS  
    4.36 +	dep r17=-1,loc6,60,4
    4.37 +	;;
    4.38 +	ptr.d r17,r24
    4.39 +	;;
    4.40 +	mov cr.ifa=r17
    4.41 +	;;
    4.42 +	itr.d dtr[r16]=r18
    4.43 +	;;
    4.44  	// re-pin mappings for stack (current)
    4.45  
    4.46  	// unless overlaps with KERNEL_TR
     5.1 --- a/xen/include/asm-ia64/linux-xen/asm/io.h	Tue Oct 30 11:21:23 2007 -0600
     5.2 +++ b/xen/include/asm-ia64/linux-xen/asm/io.h	Tue Oct 30 11:33:55 2007 -0600
     5.3 @@ -82,6 +82,8 @@ extern unsigned int num_io_spaces;
     5.4  #include <asm/system.h>
     5.5  #include <asm-generic/iomap.h>
     5.6  
     5.7 +
     5.8 +#ifndef XEN
     5.9  /*
    5.10   * Change virtual addresses to physical addresses and vv.
    5.11   */
    5.12 @@ -90,6 +92,7 @@ virt_to_maddr (volatile void *address)
    5.13  {
    5.14  	return (unsigned long) address - PAGE_OFFSET;
    5.15  }
    5.16 +#endif
    5.17  
    5.18  static inline void*
    5.19  maddr_to_virt (unsigned long address)
    5.20 @@ -97,6 +100,7 @@ maddr_to_virt (unsigned long address)
    5.21  	return (void *) (address + PAGE_OFFSET);
    5.22  }
    5.23  
    5.24 +
    5.25  #define ARCH_HAS_VALID_PHYS_ADDR_RANGE
    5.26  extern int valid_phys_addr_range (unsigned long addr, size_t *count); /* efi.c */
    5.27  
     6.1 --- a/xen/include/asm-ia64/xenkregs.h	Tue Oct 30 11:21:23 2007 -0600
     6.2 +++ b/xen/include/asm-ia64/xenkregs.h	Tue Oct 30 11:33:55 2007 -0600
     6.3 @@ -7,7 +7,8 @@
     6.4  #define IA64_TR_SHARED_INFO	3	/* dtr3: page shared with domain */
     6.5  #define	IA64_TR_VHPT		4	/* dtr4: vhpt */
     6.6  #define IA64_TR_MAPPED_REGS	5	/* dtr5: vcpu mapped regs */
     6.7 -#define IA64_DTR_GUEST_KERNEL   6
     6.8 +#define IA64_TR_XEN_HEAP_REGS	6	/* dtr6: xen heap identity mapped regs */
     6.9 +#define IA64_DTR_GUEST_KERNEL   7
    6.10  #define IA64_ITR_GUEST_KERNEL   2
    6.11  /* Processor status register bits: */
    6.12  #define IA64_PSR_VM_BIT		46
     7.1 --- a/xen/include/asm-ia64/xenpage.h	Tue Oct 30 11:21:23 2007 -0600
     7.2 +++ b/xen/include/asm-ia64/xenpage.h	Tue Oct 30 11:33:55 2007 -0600
     7.3 @@ -1,14 +1,13 @@
     7.4  #ifndef _ASM_IA64_XENPAGE_H
     7.5  #define _ASM_IA64_XENPAGE_H
     7.6  
     7.7 +#ifndef __ASSEMBLY__
     7.8  #undef mfn_valid
     7.9  #undef page_to_mfn
    7.10  #undef mfn_to_page
    7.11  #ifdef CONFIG_VIRTUAL_FRAME_TABLE
    7.12  #undef ia64_mfn_valid
    7.13 -#ifndef __ASSEMBLY__
    7.14  extern int ia64_mfn_valid (unsigned long pfn);
    7.15 -#endif
    7.16  # define mfn_valid(_pfn)	(((_pfn) < max_page) && ia64_mfn_valid(_pfn))
    7.17  #else
    7.18  # define mfn_valid(_pfn)	((_pfn) < max_page)
    7.19 @@ -16,10 +15,24 @@ extern int ia64_mfn_valid (unsigned long
    7.20  # define page_to_mfn(_page)	((unsigned long) ((_page) - frame_table))
    7.21  # define mfn_to_page(_pfn)	(frame_table + (_pfn))
    7.22  
    7.23 +
    7.24 +#include <asm/xensystem.h>
    7.25 +
    7.26 +static inline unsigned long __virt_to_maddr(unsigned long va)
    7.27 +{
    7.28 +	if (va - KERNEL_START < xenheap_size)
    7.29 +		return xen_pstart + (va - KERNEL_START);
    7.30 +	else
    7.31 +		return (va & ((1UL << 60) - 1));
    7.32 +}
    7.33 +
    7.34 +#define virt_to_maddr(va)	(__virt_to_maddr((unsigned long)va))
    7.35 +
    7.36 +
    7.37  #undef page_to_maddr
    7.38  #undef virt_to_page
    7.39  #define page_to_maddr(page)	(page_to_mfn(page) << PAGE_SHIFT)
    7.40 -#define virt_to_page(kaddr)	mfn_to_page(__pa(kaddr) >> PAGE_SHIFT)
    7.41 +#define virt_to_page(kaddr)	(mfn_to_page(virt_to_maddr(kaddr) >> PAGE_SHIFT))
    7.42  
    7.43  #define page_to_virt(_page)	maddr_to_virt(page_to_maddr(_page))
    7.44  #define maddr_to_page(kaddr)	mfn_to_page(((kaddr) >> PAGE_SHIFT))
    7.45 @@ -28,7 +41,6 @@ extern int ia64_mfn_valid (unsigned long
    7.46  #define virt_to_mfn(va)		(virt_to_maddr(va) >> PAGE_SHIFT)
    7.47  #define mfn_to_virt(mfn)	maddr_to_virt(mfn << PAGE_SHIFT)
    7.48  
    7.49 -#ifndef __ASSEMBLY__
    7.50  typedef union xen_va {
    7.51  	struct {
    7.52  		unsigned long off : 60;
    7.53 @@ -63,14 +75,18 @@ static inline int get_order_from_shift(u
    7.54      else
    7.55  	return shift - PAGE_SHIFT;
    7.56  }
    7.57 -#endif
    7.58 +/* from identity va to xen va */
    7.59 +#define virt_to_xenva(va)	((unsigned long)va - PAGE_OFFSET - \
    7.60 +				 xen_pstart + KERNEL_START)
    7.61 +
    7.62  
    7.63  #undef __pa
    7.64  #undef __va
    7.65 -#define __pa(x)		({xen_va _v; _v.l = (long) (x); _v.f.reg = 0; _v.l;})
    7.66 +#define __pa(x)		(virt_to_maddr(x))
    7.67  #define __va(x)		({xen_va _v; _v.l = (long) (x); _v.f.reg = -1; _v.p;})
    7.68  
    7.69  /* It is sometimes very useful to have unsigned long as result.  */
    7.70  #define __va_ul(x)	({xen_va _v; _v.l = (long) (x); _v.f.reg = -1; _v.l;})
    7.71  
    7.72 +#endif
    7.73  #endif /* _ASM_IA64_XENPAGE_H */
     8.1 --- a/xen/include/asm-ia64/xensystem.h	Tue Oct 30 11:21:23 2007 -0600
     8.2 +++ b/xen/include/asm-ia64/xensystem.h	Tue Oct 30 11:33:55 2007 -0600
     8.3 @@ -30,7 +30,7 @@
     8.4  
     8.5  #define XEN_VIRT_UC_BIT	 57
     8.6  
     8.7 -#define KERNEL_START		 0xf000000004000000
     8.8 +#define KERNEL_START		 0xf400000004000000
     8.9  #define GATE_ADDR		 KERNEL_START
    8.10  
    8.11  #define IS_VMM_ADDRESS(addr) ((((addr) >> 60) ^ ((addr) >> 59)) & 1)