ia64/pv_ops/xen: implement xen pv_time_ops.
[pv_ops_mirror.git] / arch / ia64 / xen / xencomm.c
blob659d98f0e8ba778502588c7a9cadd66a295c6c6b
1 /*
2 * Copyright (C) 2006 Hollis Blanchard <hollisb@us.ibm.com>, IBM Corporation
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 #include <linux/mm.h>
21 #ifdef HAVE_XEN_PLATFORM_COMPAT_H
22 #include <xen/platform-compat.h>
23 #endif
25 static unsigned long kernel_start_pa;
27 void
28 xencomm_initialize(void)
30 kernel_start_pa = KERNEL_START - ia64_tpa(KERNEL_START);
33 /* Translate virtual address to physical address. */
34 unsigned long
35 xencomm_vtop(unsigned long vaddr)
37 struct page *page;
38 struct vm_area_struct *vma;
40 if (vaddr == 0)
41 return 0;
43 #ifdef __ia64__
44 if (REGION_NUMBER(vaddr) == 5) {
45 pgd_t *pgd;
46 pud_t *pud;
47 pmd_t *pmd;
48 pte_t *ptep;
50 /* On ia64, TASK_SIZE refers to current. It is not initialized
51 during boot.
52 Furthermore the kernel is relocatable and __pa() doesn't
53 work on addresses. */
54 if (vaddr >= KERNEL_START
55 && vaddr < (KERNEL_START + KERNEL_TR_PAGE_SIZE))
56 return vaddr - kernel_start_pa;
58 /* In kernel area -- virtually mapped. */
59 pgd = pgd_offset_k(vaddr);
60 if (pgd_none(*pgd) || pgd_bad(*pgd))
61 return ~0UL;
63 pud = pud_offset(pgd, vaddr);
64 if (pud_none(*pud) || pud_bad(*pud))
65 return ~0UL;
67 pmd = pmd_offset(pud, vaddr);
68 if (pmd_none(*pmd) || pmd_bad(*pmd))
69 return ~0UL;
71 ptep = pte_offset_kernel(pmd, vaddr);
72 if (!ptep)
73 return ~0UL;
75 return (pte_val(*ptep) & _PFN_MASK) | (vaddr & ~PAGE_MASK);
77 #endif
79 if (vaddr > TASK_SIZE) {
80 /* kernel address */
81 return __pa(vaddr);
84 /* XXX double-check (lack of) locking */
85 vma = find_extend_vma(current->mm, vaddr);
86 if (!vma)
87 return ~0UL;
89 /* We assume the page is modified. */
90 page = follow_page(vma, vaddr, FOLL_WRITE | FOLL_TOUCH);
91 if (!page)
92 return ~0UL;
94 return (page_to_pfn(page) << PAGE_SHIFT) | (vaddr & ~PAGE_MASK);