grant-table.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. /******************************************************************************
  2. * arch/ia64/xen/grant-table.c
  3. *
  4. * Copyright (c) 2006 Isaku Yamahata <yamahata at valinux co jp>
  5. * VA Linux Systems Japan K.K.
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  20. *
  21. */
  22. #include <linux/module.h>
  23. #include <linux/vmalloc.h>
  24. #include <linux/mm.h>
  25. #include <xen/interface/xen.h>
  26. #include <xen/interface/memory.h>
  27. #include <xen/grant_table.h>
  28. #include <asm/xen/hypervisor.h>
  29. struct vm_struct *xen_alloc_vm_area(unsigned long size)
  30. {
  31. int order;
  32. unsigned long virt;
  33. unsigned long nr_pages;
  34. struct vm_struct *area;
  35. order = get_order(size);
  36. virt = __get_free_pages(GFP_KERNEL, order);
  37. if (virt == 0)
  38. goto err0;
  39. nr_pages = 1 << order;
  40. scrub_pages(virt, nr_pages);
  41. area = kmalloc(sizeof(*area), GFP_KERNEL);
  42. if (area == NULL)
  43. goto err1;
  44. area->flags = VM_IOREMAP;
  45. area->addr = (void *)virt;
  46. area->size = size;
  47. area->pages = NULL;
  48. area->nr_pages = nr_pages;
  49. area->phys_addr = 0; /* xenbus_map_ring_valloc uses this field! */
  50. return area;
  51. err1:
  52. free_pages(virt, order);
  53. err0:
  54. return NULL;
  55. }
  56. EXPORT_SYMBOL_GPL(xen_alloc_vm_area);
  57. void xen_free_vm_area(struct vm_struct *area)
  58. {
  59. unsigned int order = get_order(area->size);
  60. unsigned long i;
  61. unsigned long phys_addr = __pa(area->addr);
  62. /* This area is used for foreign page mappping.
  63. * So underlying machine page may not be assigned. */
  64. for (i = 0; i < (1 << order); i++) {
  65. unsigned long ret;
  66. unsigned long gpfn = (phys_addr >> PAGE_SHIFT) + i;
  67. struct xen_memory_reservation reservation = {
  68. .nr_extents = 1,
  69. .address_bits = 0,
  70. .extent_order = 0,
  71. .domid = DOMID_SELF
  72. };
  73. set_xen_guest_handle(reservation.extent_start, &gpfn);
  74. ret = HYPERVISOR_memory_op(XENMEM_populate_physmap,
  75. &reservation);
  76. BUG_ON(ret != 1);
  77. }
  78. free_pages((unsigned long)area->addr, order);
  79. kfree(area);
  80. }
  81. EXPORT_SYMBOL_GPL(xen_free_vm_area);
  82. /****************************************************************************
  83. * grant table hack
  84. * cmd: GNTTABOP_xxx
  85. */
  86. int arch_gnttab_map_shared(unsigned long *frames, unsigned long nr_gframes,
  87. unsigned long max_nr_gframes,
  88. struct grant_entry **__shared)
  89. {
  90. *__shared = __va(frames[0] << PAGE_SHIFT);
  91. return 0;
  92. }
  93. void arch_gnttab_unmap_shared(struct grant_entry *shared,
  94. unsigned long nr_gframes)
  95. {
  96. /* nothing */
  97. }
  98. static void
  99. gnttab_map_grant_ref_pre(struct gnttab_map_grant_ref *uop)
  100. {
  101. uint32_t flags;
  102. flags = uop->flags;
  103. if (flags & GNTMAP_host_map) {
  104. if (flags & GNTMAP_application_map) {
  105. printk(KERN_DEBUG
  106. "GNTMAP_application_map is not supported yet: "
  107. "flags 0x%x\n", flags);
  108. BUG();
  109. }
  110. if (flags & GNTMAP_contains_pte) {
  111. printk(KERN_DEBUG
  112. "GNTMAP_contains_pte is not supported yet: "
  113. "flags 0x%x\n", flags);
  114. BUG();
  115. }
  116. } else if (flags & GNTMAP_device_map) {
  117. printk("GNTMAP_device_map is not supported yet 0x%x\n", flags);
  118. BUG(); /* not yet. actually this flag is not used. */
  119. } else {
  120. BUG();
  121. }
  122. }
  123. int
  124. HYPERVISOR_grant_table_op(unsigned int cmd, void *uop, unsigned int count)
  125. {
  126. if (cmd == GNTTABOP_map_grant_ref) {
  127. unsigned int i;
  128. for (i = 0; i < count; i++) {
  129. gnttab_map_grant_ref_pre(
  130. (struct gnttab_map_grant_ref *)uop + i);
  131. }
  132. }
  133. return xencomm_hypercall_grant_table_op(cmd, uop, count);
  134. }
  135. EXPORT_SYMBOL(HYPERVISOR_grant_table_op);