gntdev-common.h 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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 <[email protected]>
  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. #ifdef CONFIG_XEN_GRANT_DMA_ALLOC
  24. /* Device for which DMA memory is allocated. */
  25. struct device *dma_dev;
  26. #endif
  27. #ifdef CONFIG_XEN_GNTDEV_DMABUF
  28. struct gntdev_dmabuf_priv *dmabuf_priv;
  29. #endif
  30. };
  31. struct gntdev_unmap_notify {
  32. int flags;
  33. /* Address relative to the start of the gntdev_grant_map. */
  34. int addr;
  35. evtchn_port_t event;
  36. };
  37. struct gntdev_grant_map {
  38. atomic_t in_use;
  39. struct mmu_interval_notifier notifier;
  40. bool notifier_init;
  41. struct list_head next;
  42. int index;
  43. int count;
  44. int flags;
  45. refcount_t users;
  46. struct gntdev_unmap_notify notify;
  47. struct ioctl_gntdev_grant_ref *grants;
  48. struct gnttab_map_grant_ref *map_ops;
  49. struct gnttab_unmap_grant_ref *unmap_ops;
  50. struct gnttab_map_grant_ref *kmap_ops;
  51. struct gnttab_unmap_grant_ref *kunmap_ops;
  52. bool *being_removed;
  53. struct page **pages;
  54. unsigned long pages_vm_start;
  55. #ifdef CONFIG_XEN_GRANT_DMA_ALLOC
  56. /*
  57. * If dmabuf_vaddr is not NULL then this mapping is backed by DMA
  58. * capable memory.
  59. */
  60. struct device *dma_dev;
  61. /* Flags used to create this DMA buffer: GNTDEV_DMA_FLAG_XXX. */
  62. int dma_flags;
  63. void *dma_vaddr;
  64. dma_addr_t dma_bus_addr;
  65. /* Needed to avoid allocation in gnttab_dma_free_pages(). */
  66. xen_pfn_t *frames;
  67. #endif
  68. /* Number of live grants */
  69. atomic_t live_grants;
  70. /* Needed to avoid allocation in __unmap_grant_pages */
  71. struct gntab_unmap_queue_data unmap_data;
  72. };
  73. struct gntdev_grant_map *gntdev_alloc_map(struct gntdev_priv *priv, int count,
  74. int dma_flags);
  75. void gntdev_add_map(struct gntdev_priv *priv, struct gntdev_grant_map *add);
  76. void gntdev_put_map(struct gntdev_priv *priv, struct gntdev_grant_map *map);
  77. bool gntdev_test_page_count(unsigned int count);
  78. int gntdev_map_grant_pages(struct gntdev_grant_map *map);
  79. #endif