gntdev-common.h 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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_dmabuf_priv;
  16. struct gntdev_priv {
  17. /* Maps with visible offsets in the file descriptor. */
  18. struct list_head maps;
  19. /*
  20. * Maps that are not visible; will be freed on munmap.
  21. * Only populated if populate_freeable_maps == 1
  22. */
  23. struct list_head freeable_maps;
  24. /* lock protects maps and freeable_maps. */
  25. struct mutex lock;
  26. struct mm_struct *mm;
  27. struct mmu_notifier mn;
  28. #ifdef CONFIG_XEN_GRANT_DMA_ALLOC
  29. /* Device for which DMA memory is allocated. */
  30. struct device *dma_dev;
  31. #endif
  32. #ifdef CONFIG_XEN_GNTDEV_DMABUF
  33. struct gntdev_dmabuf_priv *dmabuf_priv;
  34. #endif
  35. };
  36. struct gntdev_unmap_notify {
  37. int flags;
  38. /* Address relative to the start of the gntdev_grant_map. */
  39. int addr;
  40. int event;
  41. };
  42. struct gntdev_grant_map {
  43. struct list_head next;
  44. struct vm_area_struct *vma;
  45. int index;
  46. int count;
  47. int flags;
  48. refcount_t users;
  49. struct gntdev_unmap_notify notify;
  50. struct ioctl_gntdev_grant_ref *grants;
  51. struct gnttab_map_grant_ref *map_ops;
  52. struct gnttab_unmap_grant_ref *unmap_ops;
  53. struct gnttab_map_grant_ref *kmap_ops;
  54. struct gnttab_unmap_grant_ref *kunmap_ops;
  55. struct page **pages;
  56. unsigned long pages_vm_start;
  57. #ifdef CONFIG_XEN_GRANT_DMA_ALLOC
  58. /*
  59. * If dmabuf_vaddr is not NULL then this mapping is backed by DMA
  60. * capable memory.
  61. */
  62. struct device *dma_dev;
  63. /* Flags used to create this DMA buffer: GNTDEV_DMA_FLAG_XXX. */
  64. int dma_flags;
  65. void *dma_vaddr;
  66. dma_addr_t dma_bus_addr;
  67. /* Needed to avoid allocation in gnttab_dma_free_pages(). */
  68. xen_pfn_t *frames;
  69. #endif
  70. };
  71. struct gntdev_grant_map *gntdev_alloc_map(struct gntdev_priv *priv, int count,
  72. int dma_flags);
  73. void gntdev_add_map(struct gntdev_priv *priv, struct gntdev_grant_map *add);
  74. void gntdev_put_map(struct gntdev_priv *priv, struct gntdev_grant_map *map);
  75. bool gntdev_account_mapped_pages(int count);
  76. int gntdev_map_grant_pages(struct gntdev_grant_map *map);
  77. #endif