1 diff --git a/arch/x86/xen/enlighten.c b/arch/x86/xen/enlighten.c
2 index 0493093..97f848d 100644
3 --- a/arch/x86/xen/enlighten.c
4 +++ b/arch/x86/xen/enlighten.c
5 @@ -779,7 +779,7 @@ static __init void set_xen_basic_apic_ops(void)
6 apic->icr_write = xen_apic_icr_write;
7 apic->wait_icr_idle = xen_apic_wait_icr_idle;
8 apic->safe_wait_icr_idle = xen_safe_apic_wait_icr_idle;
9 - apic->probe = xen_safe_probe;
10 +// apic->probe = xen_safe_probe;
11 apic->acpi_madt_oem_check = xen_safe_flat_acpi_madt_oem_check;
12 /* Copy over the full contents of the newly modified apic into
13 * our apic_xen, which is to be called first by apic_probe[]. */
14 diff --git a/arch/x86/xen/mmu.c b/arch/x86/xen/mmu.c
15 index 204e3ba..8637eb8 100644
16 --- a/arch/x86/xen/mmu.c
17 +++ b/arch/x86/xen/mmu.c
18 @@ -1666,6 +1666,7 @@ static void xen_flush_tlb_single(unsigned long addr)
19 static void xen_flush_tlb_others(const struct cpumask *cpus,
20 struct mm_struct *mm, unsigned long va)
22 + extern unsigned int num_processors;
25 DECLARE_BITMAP(mask, num_processors);
26 @@ -2639,12 +2640,21 @@ static int remap_area_mfn_pte_fn(pte_t *ptep, pgtable_t token,
27 unsigned long addr, void *data)
29 struct remap_data *rmd = data;
30 - pte_t pte = pte_mkspecial(pfn_pte(rmd->mfn++, rmd->prot));
32 + /* Use the native_make_pte function because we are sure we don't
33 + * have to do any pfn->mfn translations but at the same time we
34 + * could in a stubdom so xen_initial_domain() would return false. */
35 + pte_t pte = pte_mkspecial(native_make_pte(((phys_addr_t)(rmd->mfn++)
36 + << PAGE_SHIFT) | massage_pgprot(rmd->prot)));
37 + pteval_t val = pte_val_ma(pte);
39 + if (pat_enabled && !WARN_ON(val & _PAGE_PAT)) {
40 + if ((val & (_PAGE_PCD | _PAGE_PWT)) == _PAGE_PWT)
41 + val = (val & ~(_PAGE_PCD | _PAGE_PWT)) | _PAGE_PAT;
43 rmd->mmu_update->ptr = arbitrary_virt_to_machine(ptep).maddr;
44 - rmd->mmu_update->val = pte_val_ma(pte);
45 + rmd->mmu_update->val = pte_val_ma(pte);
50 @@ -2693,6 +2703,58 @@ out:
52 EXPORT_SYMBOL_GPL(xen_remap_domain_mfn_range);
54 +int xen_remap_foreign_gpfn_range(unsigned long addr,unsigned long mfn,
55 + int nr, unsigned domid)
57 + struct remap_data rmd;
58 + struct mmu_update mmu_update[REMAP_BATCH_SIZE];
59 + int level,i,batch,nr_page = nr;
60 + unsigned long range;
62 + unsigned long vaddr,offset, set_mfn,base_addr = addr;
66 + rmd.prot = __pgprot(_PAGE_PRESENT | _PAGE_RW | _PAGE_ACCESSED | _PAGE_IOMAP);
69 + batch = min(REMAP_BATCH_SIZE, nr);
70 + range = (unsigned long)batch << PAGE_SHIFT;
72 + rmd.mmu_update = mmu_update;
74 + for(i=0; i < batch; i++){
75 + pte = pte_mkspecial(pfn_pte(rmd.mfn++, rmd.prot));
76 + vaddr = base_addr + i*PAGE_SIZE;
77 + ptep = lookup_address(vaddr, &level);
78 + BUG_ON(!ptep || (level != PG_LEVEL_4K));
80 + rmd.mmu_update->ptr = XMADDR((phys_addr_t)pte_mfn(*ptep) << PAGE_SHIFT).maddr;
81 + rmd.mmu_update->val = pte_val_ma(pte);
86 + if(HYPERVISOR_mmu_update(mmu_update, batch, NULL, domid) < 0)
98 +EXPORT_SYMBOL_GPL(xen_remap_foreign_gpfn_range);
100 +unsigned long mapped_vaddr_to_mfn(void *address)
102 + return arbitrary_virt_to_mfn(address);
104 +EXPORT_SYMBOL_GPL(mapped_vaddr_to_mfn);
106 #ifdef CONFIG_XEN_PVHVM
107 static void xen_hvm_exit_mmap(struct mm_struct *mm)
109 diff --git a/drivers/video/xen-fbfront.c b/drivers/video/xen-fbfront.c
110 index dc72563..0cea4a3 100644
111 --- a/drivers/video/xen-fbfront.c
112 +++ b/drivers/video/xen-fbfront.c
114 #include <linux/module.h>
115 #include <linux/vmalloc.h>
116 #include <linux/mm.h>
117 +#include <linux/sched.h>
118 +#include <asm/pgtable.h>
119 +#include <asm/page.h>
121 #include <asm/xen/hypervisor.h>
122 +#include <asm/xen/page.h>
125 #include <xen/events.h>
127 #include <xen/interface/io/fbif.h>
128 #include <xen/interface/io/protocols.h>
129 #include <xen/xenbus.h>
130 +#include <xen/xen-ops.h>
134 @@ -62,6 +67,12 @@ module_param_array(video, int, NULL, 0);
135 MODULE_PARM_DESC(video,
136 "Video memory size in MB, width, height in pixels (default 2,800,600)");
138 +static unsigned long foreign_gpfn = 0;
139 +module_param(foreign_gpfn, ulong, S_IRUGO);
141 +static unsigned long foreign_domid = 0;
142 +module_param(foreign_domid, ulong, S_IRUGO);
144 static void xenfb_make_preferred_console(void);
145 static int xenfb_remove(struct xenbus_device *);
146 static void xenfb_init_shared_page(struct xenfb_info *, struct fb_info *);
147 @@ -374,7 +385,6 @@ static int __devinit xenfb_probe(struct xenbus_device *dev,
149 /* Limit kernel param videoram amount to what is in xenstore */
150 if (xenbus_scanf(XBT_NIL, dev->otherend, "videoram", "%d", &val) == 1) {
151 - if (val < video[KPARAM_MEM])
152 video[KPARAM_MEM] = val;
155 @@ -397,7 +407,16 @@ static int __devinit xenfb_probe(struct xenbus_device *dev,
156 info->fb = vmalloc(fb_size);
157 if (info->fb == NULL)
159 - memset(info->fb, 0, fb_size);
161 + if((foreign_gpfn != 0) && (foreign_domid != 0)){
162 + ret = xen_remap_foreign_gpfn_range((unsigned long)(info->fb),
163 + foreign_gpfn >> PAGE_SHIFT,
164 + fb_size >> PAGE_SHIFT, foreign_domid);
166 + printk("Can not remap vram of hvm guest. rc(%d)\n",ret);
171 info->nr_pages = (fb_size + PAGE_SIZE - 1) >> PAGE_SHIFT;
172 diff --git a/drivers/xen/xenfs/privcmd.c b/drivers/xen/xenfs/privcmd.c
173 index f80be7f..4d25031 100644
174 --- a/drivers/xen/xenfs/privcmd.c
175 +++ b/drivers/xen/xenfs/privcmd.c
176 @@ -191,8 +191,10 @@ static long privcmd_ioctl_mmap(void __user *udata)
178 struct mmap_mfn_state state;
181 if (!xen_initial_domain())
185 if (copy_from_user(&mmapcmd, udata, sizeof(mmapcmd)))
187 @@ -282,9 +284,10 @@ static long privcmd_ioctl_mmap_batch(void __user *udata)
188 unsigned long nr_pages;
190 struct mmap_batch_state state;
193 if (!xen_initial_domain())
197 if (copy_from_user(&m, udata, sizeof(m)))
199 diff --git a/include/xen/xen-ops.h b/include/xen/xen-ops.h
200 index 4349e89..b9593b0 100644
201 --- a/include/xen/xen-ops.h
202 +++ b/include/xen/xen-ops.h
203 @@ -20,6 +20,10 @@ int xen_remap_domain_mfn_range(struct vm_area_struct *vma,
204 unsigned long mfn, int nr,
205 pgprot_t prot, unsigned domid);
207 +int xen_remap_foreign_gpfn_range(unsigned long addr,unsigned long mfn,
208 + int nr, unsigned domid);
209 +unsigned long mapped_vaddr_to_mfn(void *address);
211 extern unsigned long *xen_contiguous_bitmap;
212 int xen_create_contiguous_region(unsigned long vstart, unsigned int order,
213 unsigned int address_bits);