gntdev-common.h 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * Common functionality of grant device.
  4. *
  5. * Copyright (c) 2006-2007, D G Murray.
  6. * (c) 2009 Gerd Hoffmann <kraxel@redhat.com>
  7. * (c) 2018 Oleksandr Andrushchenko, EPAM Systems Inc.
  8. */
  9. #ifndef _GNTDEV_COMMON_H
  10. #define _GNTDEV_COMMON_H
  11. #include <linux/mm.h>
  12. #include <linux/mman.h>
  13. #include <linux/mmu_notifier.h>
  14. #include <linux/types.h>
  15. struct gntdev_priv {
  16. /* Maps with visible offsets in the file descriptor. */
  17. struct list_head maps;
  18. /*
  19. * Maps that are not visible; will be freed on munmap.
  20. * Only populated if populate_freeable_maps == 1
  21. */
  22. struct list_head freeable_maps;
  23. /* lock protects maps and freeable_maps. */
  24. struct mutex lock;
  25. struct mm_struct *mm;
  26. struct mmu_notifier mn;
  27. #ifdef CONFIG_XEN_GRANT_DMA_ALLOC
  28. /* Device for which DMA memory is allocated. */
  29. struct device *dma_dev;
  30. #endif
  31. };
  32. struct gntdev_unmap_notify {
  33. int flags;
  34. /* Address relative to the start of the gntdev_grant_map. */
  35. int addr;
  36. int event;
  37. };
  38. struct gntdev_grant_map {
  39. struct list_head next;
  40. struct vm_area_struct *vma;
  41. int index;
  42. int count;
  43. int flags;
  44. refcount_t users;
  45. struct gntdev_unmap_notify notify;
  46. struct ioctl_gntdev_grant_ref *grants;
  47. struct gnttab_map_grant_ref *map_ops;
  48. struct gnttab_unmap_grant_ref *unmap_ops;
  49. struct gnttab_map_grant_ref *kmap_ops;
  50. struct gnttab_unmap_grant_ref *kunmap_ops;
  51. struct page **pages;
  52. unsigned long pages_vm_start;
  53. #ifdef CONFIG_XEN_GRANT_DMA_ALLOC
  54. /*
  55. * If dmabuf_vaddr is not NULL then this mapping is backed by DMA
  56. * capable memory.
  57. */
  58. struct device *dma_dev;
  59. /* Flags used to create this DMA buffer: GNTDEV_DMA_FLAG_XXX. */
  60. int dma_flags;
  61. void *dma_vaddr;
  62. dma_addr_t dma_bus_addr;
  63. /* Needed to avoid allocation in gnttab_dma_free_pages(). */
  64. xen_pfn_t *frames;
  65. #endif
  66. };
  67. struct gntdev_grant_map *gntdev_alloc_map(struct gntdev_priv *priv, int count,
  68. int dma_flags);
  69. void gntdev_add_map(struct gntdev_priv *priv, struct gntdev_grant_map *add);
  70. void gntdev_put_map(struct gntdev_priv *priv, struct gntdev_grant_map *map);
  71. bool gntdev_account_mapped_pages(int count);
  72. int gntdev_map_grant_pages(struct gntdev_grant_map *map);
  73. #endif