gntdev-common.h 2.2 KB

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