xencomm.c 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /*
  2. * Copyright (C) 2006 Hollis Blanchard <hollisb@us.ibm.com>, IBM Corporation
  3. *
  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.
  8. *
  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.
  13. *
  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
  17. */
  18. #include <linux/mm.h>
  19. static unsigned long kernel_virtual_offset;
  20. void
  21. xencomm_initialize(void)
  22. {
  23. kernel_virtual_offset = KERNEL_START - ia64_tpa(KERNEL_START);
  24. }
  25. /* Translate virtual address to physical address. */
  26. unsigned long
  27. xencomm_vtop(unsigned long vaddr)
  28. {
  29. struct page *page;
  30. struct vm_area_struct *vma;
  31. if (vaddr == 0)
  32. return 0UL;
  33. if (REGION_NUMBER(vaddr) == 5) {
  34. pgd_t *pgd;
  35. pud_t *pud;
  36. pmd_t *pmd;
  37. pte_t *ptep;
  38. /* On ia64, TASK_SIZE refers to current. It is not initialized
  39. during boot.
  40. Furthermore the kernel is relocatable and __pa() doesn't
  41. work on addresses. */
  42. if (vaddr >= KERNEL_START
  43. && vaddr < (KERNEL_START + KERNEL_TR_PAGE_SIZE))
  44. return vaddr - kernel_virtual_offset;
  45. /* In kernel area -- virtually mapped. */
  46. pgd = pgd_offset_k(vaddr);
  47. if (pgd_none(*pgd) || pgd_bad(*pgd))
  48. return ~0UL;
  49. pud = pud_offset(pgd, vaddr);
  50. if (pud_none(*pud) || pud_bad(*pud))
  51. return ~0UL;
  52. pmd = pmd_offset(pud, vaddr);
  53. if (pmd_none(*pmd) || pmd_bad(*pmd))
  54. return ~0UL;
  55. ptep = pte_offset_kernel(pmd, vaddr);
  56. if (!ptep)
  57. return ~0UL;
  58. return (pte_val(*ptep) & _PFN_MASK) | (vaddr & ~PAGE_MASK);
  59. }
  60. if (vaddr > TASK_SIZE) {
  61. /* percpu variables */
  62. if (REGION_NUMBER(vaddr) == 7 &&
  63. REGION_OFFSET(vaddr) >= (1ULL << IA64_MAX_PHYS_BITS))
  64. ia64_tpa(vaddr);
  65. /* kernel address */
  66. return __pa(vaddr);
  67. }
  68. /* XXX double-check (lack of) locking */
  69. vma = find_extend_vma(current->mm, vaddr);
  70. if (!vma)
  71. return ~0UL;
  72. /* We assume the page is modified. */
  73. page = follow_page(vma, vaddr, FOLL_WRITE | FOLL_TOUCH);
  74. if (!page)
  75. return ~0UL;
  76. return (page_to_pfn(page) << PAGE_SHIFT) | (vaddr & ~PAGE_MASK);
  77. }