• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* SPDX-License-Identifier: GPL-2.0 */
2 
3 /*
4  * Common functionality of grant device.
5  *
6  * Copyright (c) 2006-2007, D G Murray.
7  *           (c) 2009 Gerd Hoffmann <kraxel@redhat.com>
8  *           (c) 2018 Oleksandr Andrushchenko, EPAM Systems Inc.
9  */
10 
11 #ifndef _GNTDEV_COMMON_H
12 #define _GNTDEV_COMMON_H
13 
14 #include <linux/mm.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>
20 
21 struct gntdev_dmabuf_priv;
22 
23 struct gntdev_priv {
24 	/* Maps with visible offsets in the file descriptor. */
25 	struct list_head maps;
26 	/*
27 	 * Maps that are not visible; will be freed on munmap.
28 	 * Only populated if populate_freeable_maps == 1
29 	 */
30 	struct list_head freeable_maps;
31 	/* lock protects maps and freeable_maps. */
32 	struct mutex lock;
33 	struct mm_struct *mm;
34 	struct mmu_notifier mn;
35 
36 #ifdef CONFIG_XEN_GRANT_DMA_ALLOC
37 	/* Device for which DMA memory is allocated. */
38 	struct device *dma_dev;
39 #endif
40 
41 #ifdef CONFIG_XEN_GNTDEV_DMABUF
42 	struct gntdev_dmabuf_priv *dmabuf_priv;
43 #endif
44 };
45 
46 struct gntdev_unmap_notify {
47 	int flags;
48 	/* Address relative to the start of the gntdev_grant_map. */
49 	int addr;
50 	int event;
51 };
52 
53 struct gntdev_grant_map {
54 	struct list_head next;
55 	struct vm_area_struct *vma;
56 	int index;
57 	int count;
58 	int flags;
59 	refcount_t users;
60 	struct gntdev_unmap_notify notify;
61 	struct ioctl_gntdev_grant_ref *grants;
62 	struct gnttab_map_grant_ref   *map_ops;
63 	struct gnttab_unmap_grant_ref *unmap_ops;
64 	struct gnttab_map_grant_ref   *kmap_ops;
65 	struct gnttab_unmap_grant_ref *kunmap_ops;
66 	bool *being_removed;
67 	struct page **pages;
68 	unsigned long pages_vm_start;
69 
70 #ifdef CONFIG_XEN_GRANT_DMA_ALLOC
71 	/*
72 	 * If dmabuf_vaddr is not NULL then this mapping is backed by DMA
73 	 * capable memory.
74 	 */
75 
76 	struct device *dma_dev;
77 	/* Flags used to create this DMA buffer: GNTDEV_DMA_FLAG_XXX. */
78 	int dma_flags;
79 	void *dma_vaddr;
80 	dma_addr_t dma_bus_addr;
81 	/* Needed to avoid allocation in gnttab_dma_free_pages(). */
82 	xen_pfn_t *frames;
83 #endif
84 
85 	/* Number of live grants */
86 	atomic_t live_grants;
87 	/* Needed to avoid allocation in __unmap_grant_pages */
88 	struct gntab_unmap_queue_data unmap_data;
89 };
90 
91 struct gntdev_grant_map *gntdev_alloc_map(struct gntdev_priv *priv, int count,
92 					  int dma_flags);
93 
94 void gntdev_add_map(struct gntdev_priv *priv, struct gntdev_grant_map *add);
95 
96 void gntdev_put_map(struct gntdev_priv *priv, struct gntdev_grant_map *map);
97 
98 bool gntdev_account_mapped_pages(int count);
99 
100 int gntdev_map_grant_pages(struct gntdev_grant_map *map);
101 
102 #endif
103