Back to home page

OSCL-LXR

 
 

    


0001 /*
0002  * Copyright © 2012 Red Hat
0003  * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
0004  * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
0005  * Copyright (c) 2009-2010, Code Aurora Forum.
0006  *
0007  * Permission is hereby granted, free of charge, to any person obtaining a
0008  * copy of this software and associated documentation files (the "Software"),
0009  * to deal in the Software without restriction, including without limitation
0010  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
0011  * and/or sell copies of the Software, and to permit persons to whom the
0012  * Software is furnished to do so, subject to the following conditions:
0013  *
0014  * The above copyright notice and this permission notice (including the next
0015  * paragraph) shall be included in all copies or substantial portions of the
0016  * Software.
0017  *
0018  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
0019  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
0020  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
0021  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
0022  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
0023  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
0024  * IN THE SOFTWARE.
0025  *
0026  * Authors:
0027  *      Dave Airlie <airlied@redhat.com>
0028  *      Rob Clark <rob.clark@linaro.org>
0029  *
0030  */
0031 
0032 #ifndef __DRM_PRIME_H__
0033 #define __DRM_PRIME_H__
0034 
0035 #include <linux/mutex.h>
0036 #include <linux/rbtree.h>
0037 #include <linux/scatterlist.h>
0038 
0039 /**
0040  * struct drm_prime_file_private - per-file tracking for PRIME
0041  *
0042  * This just contains the internal &struct dma_buf and handle caches for each
0043  * &struct drm_file used by the PRIME core code.
0044  */
0045 struct drm_prime_file_private {
0046 /* private: */
0047     struct mutex lock;
0048     struct rb_root dmabufs;
0049     struct rb_root handles;
0050 };
0051 
0052 struct device;
0053 
0054 struct dma_buf_export_info;
0055 struct dma_buf;
0056 struct dma_buf_attachment;
0057 struct iosys_map;
0058 
0059 enum dma_data_direction;
0060 
0061 struct drm_device;
0062 struct drm_gem_object;
0063 struct drm_file;
0064 
0065 /* core prime functions */
0066 struct dma_buf *drm_gem_dmabuf_export(struct drm_device *dev,
0067                       struct dma_buf_export_info *exp_info);
0068 void drm_gem_dmabuf_release(struct dma_buf *dma_buf);
0069 
0070 int drm_gem_prime_fd_to_handle(struct drm_device *dev,
0071                    struct drm_file *file_priv, int prime_fd, uint32_t *handle);
0072 int drm_gem_prime_handle_to_fd(struct drm_device *dev,
0073                    struct drm_file *file_priv, uint32_t handle, uint32_t flags,
0074                    int *prime_fd);
0075 
0076 /* helper functions for exporting */
0077 int drm_gem_map_attach(struct dma_buf *dma_buf,
0078                struct dma_buf_attachment *attach);
0079 void drm_gem_map_detach(struct dma_buf *dma_buf,
0080             struct dma_buf_attachment *attach);
0081 struct sg_table *drm_gem_map_dma_buf(struct dma_buf_attachment *attach,
0082                      enum dma_data_direction dir);
0083 void drm_gem_unmap_dma_buf(struct dma_buf_attachment *attach,
0084                struct sg_table *sgt,
0085                enum dma_data_direction dir);
0086 int drm_gem_dmabuf_vmap(struct dma_buf *dma_buf, struct iosys_map *map);
0087 void drm_gem_dmabuf_vunmap(struct dma_buf *dma_buf, struct iosys_map *map);
0088 
0089 int drm_gem_prime_mmap(struct drm_gem_object *obj, struct vm_area_struct *vma);
0090 int drm_gem_dmabuf_mmap(struct dma_buf *dma_buf, struct vm_area_struct *vma);
0091 
0092 struct sg_table *drm_prime_pages_to_sg(struct drm_device *dev,
0093                        struct page **pages, unsigned int nr_pages);
0094 struct dma_buf *drm_gem_prime_export(struct drm_gem_object *obj,
0095                      int flags);
0096 
0097 unsigned long drm_prime_get_contiguous_size(struct sg_table *sgt);
0098 
0099 /* helper functions for importing */
0100 struct drm_gem_object *drm_gem_prime_import_dev(struct drm_device *dev,
0101                         struct dma_buf *dma_buf,
0102                         struct device *attach_dev);
0103 struct drm_gem_object *drm_gem_prime_import(struct drm_device *dev,
0104                         struct dma_buf *dma_buf);
0105 
0106 void drm_prime_gem_destroy(struct drm_gem_object *obj, struct sg_table *sg);
0107 
0108 int drm_prime_sg_to_page_array(struct sg_table *sgt, struct page **pages,
0109                    int max_pages);
0110 int drm_prime_sg_to_dma_addr_array(struct sg_table *sgt, dma_addr_t *addrs,
0111                    int max_pages);
0112 
0113 #endif /* __DRM_PRIME_H__ */