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