gntdev-common.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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. #include <xen/interface/event_channel.h>
  16. #include <xen/grant_table.h>
  17. struct gntdev_dmabuf_priv;
  18. struct gntdev_priv {
  19. /* Maps with visible offsets in the file descriptor. */
  20. struct list_head maps;
  21. /* lock protects maps and freeable_maps. */
  22. struct mutex lock;
  23. /* Free instances of struct gntdev_copy_batch. */
  24. struct gntdev_copy_batch *batch;
  25. struct mutex batch_lock;
  26. #ifdef CONFIG_XEN_GRANT_DMA_ALLOC
  27. /* Device for which DMA memory is allocated. */
  28. struct device *dma_dev;
  29. #endif
  30. #ifdef CONFIG_XEN_GNTDEV_DMABUF
  31. struct gntdev_dmabuf_priv *dmabuf_priv;
  32. #endif
  33. };
  34. struct gntdev_unmap_notify {
  35. int flags;
  36. /* Address relative to the start of the gntdev_grant_map. */
  37. int addr;
  38. evtchn_port_t event;
  39. };
  40. struct gntdev_grant_map {
  41. atomic_t in_use;
  42. struct mmu_interval_notifier notifier;
  43. bool notifier_init;
  44. struct list_head next;
  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. bool *being_removed;
  56. struct page **pages;
  57. unsigned long pages_vm_start;
  58. #ifdef CONFIG_XEN_GRANT_DMA_ALLOC
  59. /*
  60. * If dmabuf_vaddr is not NULL then this mapping is backed by DMA
  61. * capable memory.
  62. */
  63. struct device *dma_dev;
  64. /* Flags used to create this DMA buffer: GNTDEV_DMA_FLAG_XXX. */
  65. int dma_flags;
  66. void *dma_vaddr;
  67. dma_addr_t dma_bus_addr;
  68. /* Needed to avoid allocation in gnttab_dma_free_pages(). */
  69. xen_pfn_t *frames;
  70. #endif
  71. /* Number of live grants */
  72. atomic_t live_grants;
  73. /* Needed to avoid allocation in __unmap_grant_pages */
  74. struct gntab_unmap_queue_data unmap_data;
  75. };
  76. struct gntdev_grant_map *gntdev_alloc_map(struct gntdev_priv *priv, int count,
  77. int dma_flags);
  78. void gntdev_add_map(struct gntdev_priv *priv, struct gntdev_grant_map *add);
  79. void gntdev_put_map(struct gntdev_priv *priv, struct gntdev_grant_map *map);
  80. bool gntdev_test_page_count(unsigned int count);
  81. int gntdev_map_grant_pages(struct gntdev_grant_map *map);
  82. #endif