Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 
0003 /*
0004  * Common functionality of grant device.
0005  *
0006  * Copyright (c) 2006-2007, D G Murray.
0007  *           (c) 2009 Gerd Hoffmann <kraxel@redhat.com>
0008  *           (c) 2018 Oleksandr Andrushchenko, EPAM Systems Inc.
0009  */
0010 
0011 #ifndef _GNTDEV_COMMON_H
0012 #define _GNTDEV_COMMON_H
0013 
0014 #include <linux/mm.h>
0015 #include <linux/mman.h>
0016 #include <linux/mmu_notifier.h>
0017 #include <linux/types.h>
0018 #include <xen/interface/event_channel.h>
0019 #include <xen/grant_table.h>
0020 
0021 struct gntdev_dmabuf_priv;
0022 
0023 struct gntdev_priv {
0024     /* Maps with visible offsets in the file descriptor. */
0025     struct list_head maps;
0026     /* lock protects maps and freeable_maps. */
0027     struct mutex lock;
0028 
0029 #ifdef CONFIG_XEN_GRANT_DMA_ALLOC
0030     /* Device for which DMA memory is allocated. */
0031     struct device *dma_dev;
0032 #endif
0033 
0034 #ifdef CONFIG_XEN_GNTDEV_DMABUF
0035     struct gntdev_dmabuf_priv *dmabuf_priv;
0036 #endif
0037 };
0038 
0039 struct gntdev_unmap_notify {
0040     int flags;
0041     /* Address relative to the start of the gntdev_grant_map. */
0042     int addr;
0043     evtchn_port_t event;
0044 };
0045 
0046 struct gntdev_grant_map {
0047     struct mmu_interval_notifier notifier;
0048     struct list_head next;
0049     struct vm_area_struct *vma;
0050     int index;
0051     int count;
0052     int flags;
0053     refcount_t users;
0054     struct gntdev_unmap_notify notify;
0055     struct ioctl_gntdev_grant_ref *grants;
0056     struct gnttab_map_grant_ref   *map_ops;
0057     struct gnttab_unmap_grant_ref *unmap_ops;
0058     struct gnttab_map_grant_ref   *kmap_ops;
0059     struct gnttab_unmap_grant_ref *kunmap_ops;
0060     bool *being_removed;
0061     struct page **pages;
0062     unsigned long pages_vm_start;
0063 
0064 #ifdef CONFIG_XEN_GRANT_DMA_ALLOC
0065     /*
0066      * If dmabuf_vaddr is not NULL then this mapping is backed by DMA
0067      * capable memory.
0068      */
0069 
0070     struct device *dma_dev;
0071     /* Flags used to create this DMA buffer: GNTDEV_DMA_FLAG_XXX. */
0072     int dma_flags;
0073     void *dma_vaddr;
0074     dma_addr_t dma_bus_addr;
0075     /* Needed to avoid allocation in gnttab_dma_free_pages(). */
0076     xen_pfn_t *frames;
0077 #endif
0078 
0079     /* Number of live grants */
0080     atomic_t live_grants;
0081     /* Needed to avoid allocation in __unmap_grant_pages */
0082     struct gntab_unmap_queue_data unmap_data;
0083 };
0084 
0085 struct gntdev_grant_map *gntdev_alloc_map(struct gntdev_priv *priv, int count,
0086                       int dma_flags);
0087 
0088 void gntdev_add_map(struct gntdev_priv *priv, struct gntdev_grant_map *add);
0089 
0090 void gntdev_put_map(struct gntdev_priv *priv, struct gntdev_grant_map *map);
0091 
0092 bool gntdev_test_page_count(unsigned int count);
0093 
0094 int gntdev_map_grant_pages(struct gntdev_grant_map *map);
0095 
0096 #endif