Oleksandr Andrushchenko | 1d31456 | 2018-07-20 12:01:47 +0300 | [diff] [blame] | 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> |
Yan Yankovskyi | 0102e4e | 2020-03-23 18:15:11 +0200 | [diff] [blame] | 18 | #include <xen/interface/event_channel.h> |
Oleksandr Andrushchenko | 1d31456 | 2018-07-20 12:01:47 +0300 | [diff] [blame] | 19 | |
Oleksandr Andrushchenko | 932d656 | 2018-07-20 12:01:48 +0300 | [diff] [blame] | 20 | struct gntdev_dmabuf_priv; |
| 21 | |
Oleksandr Andrushchenko | 1d31456 | 2018-07-20 12:01:47 +0300 | [diff] [blame] | 22 | struct gntdev_priv { |
| 23 | /* Maps with visible offsets in the file descriptor. */ |
| 24 | struct list_head maps; |
Oleksandr Andrushchenko | 1d31456 | 2018-07-20 12:01:47 +0300 | [diff] [blame] | 25 | /* lock protects maps and freeable_maps. */ |
| 26 | struct mutex lock; |
Oleksandr Andrushchenko | 1d31456 | 2018-07-20 12:01:47 +0300 | [diff] [blame] | 27 | |
| 28 | #ifdef CONFIG_XEN_GRANT_DMA_ALLOC |
| 29 | /* Device for which DMA memory is allocated. */ |
| 30 | struct device *dma_dev; |
| 31 | #endif |
Oleksandr Andrushchenko | 932d656 | 2018-07-20 12:01:48 +0300 | [diff] [blame] | 32 | |
| 33 | #ifdef CONFIG_XEN_GNTDEV_DMABUF |
| 34 | struct gntdev_dmabuf_priv *dmabuf_priv; |
| 35 | #endif |
Oleksandr Andrushchenko | 1d31456 | 2018-07-20 12:01:47 +0300 | [diff] [blame] | 36 | }; |
| 37 | |
| 38 | struct gntdev_unmap_notify { |
| 39 | int flags; |
| 40 | /* Address relative to the start of the gntdev_grant_map. */ |
| 41 | int addr; |
Yan Yankovskyi | 0102e4e | 2020-03-23 18:15:11 +0200 | [diff] [blame] | 42 | evtchn_port_t event; |
Oleksandr Andrushchenko | 1d31456 | 2018-07-20 12:01:47 +0300 | [diff] [blame] | 43 | }; |
| 44 | |
| 45 | struct gntdev_grant_map { |
Jason Gunthorpe | d3eeb1d | 2019-11-12 16:22:31 -0400 | [diff] [blame] | 46 | struct mmu_interval_notifier notifier; |
Oleksandr Andrushchenko | 1d31456 | 2018-07-20 12:01:47 +0300 | [diff] [blame] | 47 | struct list_head next; |
| 48 | struct vm_area_struct *vma; |
| 49 | int index; |
| 50 | int count; |
| 51 | int flags; |
| 52 | refcount_t users; |
| 53 | struct gntdev_unmap_notify notify; |
| 54 | struct ioctl_gntdev_grant_ref *grants; |
| 55 | struct gnttab_map_grant_ref *map_ops; |
| 56 | struct gnttab_unmap_grant_ref *unmap_ops; |
| 57 | struct gnttab_map_grant_ref *kmap_ops; |
| 58 | struct gnttab_unmap_grant_ref *kunmap_ops; |
| 59 | struct page **pages; |
| 60 | unsigned long pages_vm_start; |
| 61 | |
| 62 | #ifdef CONFIG_XEN_GRANT_DMA_ALLOC |
| 63 | /* |
| 64 | * If dmabuf_vaddr is not NULL then this mapping is backed by DMA |
| 65 | * capable memory. |
| 66 | */ |
| 67 | |
| 68 | struct device *dma_dev; |
| 69 | /* Flags used to create this DMA buffer: GNTDEV_DMA_FLAG_XXX. */ |
| 70 | int dma_flags; |
| 71 | void *dma_vaddr; |
| 72 | dma_addr_t dma_bus_addr; |
| 73 | /* Needed to avoid allocation in gnttab_dma_free_pages(). */ |
| 74 | xen_pfn_t *frames; |
| 75 | #endif |
| 76 | }; |
| 77 | |
| 78 | struct gntdev_grant_map *gntdev_alloc_map(struct gntdev_priv *priv, int count, |
| 79 | int dma_flags); |
| 80 | |
| 81 | void gntdev_add_map(struct gntdev_priv *priv, struct gntdev_grant_map *add); |
| 82 | |
| 83 | void gntdev_put_map(struct gntdev_priv *priv, struct gntdev_grant_map *map); |
| 84 | |
Juergen Gross | 3b06ac6 | 2019-11-07 12:15:45 +0100 | [diff] [blame] | 85 | bool gntdev_test_page_count(unsigned int count); |
Oleksandr Andrushchenko | 1d31456 | 2018-07-20 12:01:47 +0300 | [diff] [blame] | 86 | |
| 87 | int gntdev_map_grant_pages(struct gntdev_grant_map *map); |
| 88 | |
| 89 | #endif |