1 /* SPDX-License-Identifier: GPL-2.0 */
4 * Common functionality of grant device.
6 * Copyright (c) 2006-2007, D G Murray.
7 * (c) 2009 Gerd Hoffmann <kraxel@redhat.com>
8 * (c) 2018 Oleksandr Andrushchenko, EPAM Systems Inc.
11 #ifndef _GNTDEV_COMMON_H
12 #define _GNTDEV_COMMON_H
15 #include <linux/mman.h>
16 #include <linux/mmu_notifier.h>
17 #include <linux/types.h>
18 #include <xen/interface/event_channel.h>
19 #include <xen/grant_table.h>
21 struct gntdev_dmabuf_priv;
24 /* Maps with visible offsets in the file descriptor. */
25 struct list_head maps;
26 /* lock protects maps and freeable_maps. */
29 #ifdef CONFIG_XEN_GRANT_DMA_ALLOC
30 /* Device for which DMA memory is allocated. */
31 struct device *dma_dev;
34 #ifdef CONFIG_XEN_GNTDEV_DMABUF
35 struct gntdev_dmabuf_priv *dmabuf_priv;
39 struct gntdev_unmap_notify {
41 /* Address relative to the start of the gntdev_grant_map. */
46 struct gntdev_grant_map {
47 struct mmu_interval_notifier notifier;
48 struct list_head next;
49 struct vm_area_struct *vma;
54 struct gntdev_unmap_notify notify;
55 struct ioctl_gntdev_grant_ref *grants;
56 struct gnttab_map_grant_ref *map_ops;
57 struct gnttab_unmap_grant_ref *unmap_ops;
58 struct gnttab_map_grant_ref *kmap_ops;
59 struct gnttab_unmap_grant_ref *kunmap_ops;
62 unsigned long pages_vm_start;
64 #ifdef CONFIG_XEN_GRANT_DMA_ALLOC
66 * If dmabuf_vaddr is not NULL then this mapping is backed by DMA
70 struct device *dma_dev;
71 /* Flags used to create this DMA buffer: GNTDEV_DMA_FLAG_XXX. */
74 dma_addr_t dma_bus_addr;
75 /* Needed to avoid allocation in gnttab_dma_free_pages(). */
79 /* Number of live grants */
81 /* Needed to avoid allocation in __unmap_grant_pages */
82 struct gntab_unmap_queue_data unmap_data;
85 struct gntdev_grant_map *gntdev_alloc_map(struct gntdev_priv *priv, int count,
88 void gntdev_add_map(struct gntdev_priv *priv, struct gntdev_grant_map *add);
90 void gntdev_put_map(struct gntdev_priv *priv, struct gntdev_grant_map *map);
92 bool gntdev_test_page_count(unsigned int count);
94 int gntdev_map_grant_pages(struct gntdev_grant_map *map);