Home | History | Annotate | Line # | Download | only in drm
      1  1.7  riastrad /*	$NetBSD: drm_prime.h,v 1.7 2021/12/19 11:33:30 riastradh Exp $	*/
      2  1.1  riastrad 
      3  1.1  riastrad /*
      4  1.1  riastrad  * Copyright  2012 Red Hat
      5  1.1  riastrad  * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
      6  1.1  riastrad  * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
      7  1.1  riastrad  * Copyright (c) 2009-2010, Code Aurora Forum.
      8  1.1  riastrad  *
      9  1.1  riastrad  * Permission is hereby granted, free of charge, to any person obtaining a
     10  1.1  riastrad  * copy of this software and associated documentation files (the "Software"),
     11  1.1  riastrad  * to deal in the Software without restriction, including without limitation
     12  1.1  riastrad  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
     13  1.1  riastrad  * and/or sell copies of the Software, and to permit persons to whom the
     14  1.1  riastrad  * Software is furnished to do so, subject to the following conditions:
     15  1.1  riastrad  *
     16  1.1  riastrad  * The above copyright notice and this permission notice (including the next
     17  1.1  riastrad  * paragraph) shall be included in all copies or substantial portions of the
     18  1.1  riastrad  * Software.
     19  1.1  riastrad  *
     20  1.1  riastrad  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
     21  1.1  riastrad  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
     22  1.1  riastrad  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
     23  1.1  riastrad  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
     24  1.1  riastrad  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
     25  1.1  riastrad  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
     26  1.1  riastrad  * IN THE SOFTWARE.
     27  1.1  riastrad  *
     28  1.1  riastrad  * Authors:
     29  1.1  riastrad  *      Dave Airlie <airlied (at) redhat.com>
     30  1.1  riastrad  *      Rob Clark <rob.clark (at) linaro.org>
     31  1.1  riastrad  *
     32  1.1  riastrad  */
     33  1.1  riastrad 
     34  1.1  riastrad #ifndef __DRM_PRIME_H__
     35  1.1  riastrad #define __DRM_PRIME_H__
     36  1.1  riastrad 
     37  1.1  riastrad #include <linux/mutex.h>
     38  1.1  riastrad #include <linux/rbtree.h>
     39  1.1  riastrad #include <linux/scatterlist.h>
     40  1.1  riastrad 
     41  1.1  riastrad /**
     42  1.1  riastrad  * struct drm_prime_file_private - per-file tracking for PRIME
     43  1.1  riastrad  *
     44  1.1  riastrad  * This just contains the internal &struct dma_buf and handle caches for each
     45  1.1  riastrad  * &struct drm_file used by the PRIME core code.
     46  1.1  riastrad  */
     47  1.1  riastrad struct drm_prime_file_private {
     48  1.1  riastrad /* private: */
     49  1.1  riastrad 	struct mutex lock;
     50  1.1  riastrad 	struct rb_root dmabufs;
     51  1.1  riastrad 	struct rb_root handles;
     52  1.1  riastrad };
     53  1.1  riastrad 
     54  1.1  riastrad struct device;
     55  1.1  riastrad 
     56  1.1  riastrad struct dma_buf_export_info;
     57  1.1  riastrad struct dma_buf;
     58  1.1  riastrad struct dma_buf_attachment;
     59  1.1  riastrad 
     60  1.1  riastrad enum dma_data_direction;
     61  1.1  riastrad 
     62  1.1  riastrad struct drm_device;
     63  1.1  riastrad struct drm_gem_object;
     64  1.1  riastrad struct drm_file;
     65  1.1  riastrad 
     66  1.1  riastrad /* core prime functions */
     67  1.1  riastrad struct dma_buf *drm_gem_dmabuf_export(struct drm_device *dev,
     68  1.1  riastrad 				      struct dma_buf_export_info *exp_info);
     69  1.1  riastrad void drm_gem_dmabuf_release(struct dma_buf *dma_buf);
     70  1.1  riastrad 
     71  1.1  riastrad int drm_gem_prime_fd_to_handle(struct drm_device *dev,
     72  1.1  riastrad 			       struct drm_file *file_priv, int prime_fd, uint32_t *handle);
     73  1.1  riastrad int drm_gem_prime_handle_to_fd(struct drm_device *dev,
     74  1.1  riastrad 			       struct drm_file *file_priv, uint32_t handle, uint32_t flags,
     75  1.1  riastrad 			       int *prime_fd);
     76  1.1  riastrad 
     77  1.1  riastrad /* helper functions for exporting */
     78  1.1  riastrad int drm_gem_map_attach(struct dma_buf *dma_buf,
     79  1.1  riastrad 		       struct dma_buf_attachment *attach);
     80  1.1  riastrad void drm_gem_map_detach(struct dma_buf *dma_buf,
     81  1.1  riastrad 			struct dma_buf_attachment *attach);
     82  1.1  riastrad struct sg_table *drm_gem_map_dma_buf(struct dma_buf_attachment *attach,
     83  1.1  riastrad 				     enum dma_data_direction dir);
     84  1.1  riastrad void drm_gem_unmap_dma_buf(struct dma_buf_attachment *attach,
     85  1.1  riastrad 			   struct sg_table *sgt,
     86  1.1  riastrad 			   enum dma_data_direction dir);
     87  1.1  riastrad void *drm_gem_dmabuf_vmap(struct dma_buf *dma_buf);
     88  1.1  riastrad void drm_gem_dmabuf_vunmap(struct dma_buf *dma_buf, void *vaddr);
     89  1.1  riastrad 
     90  1.3  riastrad #ifdef __NetBSD__
     91  1.5  riastrad int drm_gem_prime_mmap(struct drm_gem_object *, off_t *, size_t, int, int *,
     92  1.3  riastrad     int *, struct uvm_object **, int *);
     93  1.3  riastrad int drm_gem_dmabuf_mmap(struct dma_buf *, off_t *, size_t, int, int *,
     94  1.3  riastrad     int *, struct uvm_object **, int *);
     95  1.3  riastrad #else
     96  1.1  riastrad int drm_gem_prime_mmap(struct drm_gem_object *obj, struct vm_area_struct *vma);
     97  1.1  riastrad int drm_gem_dmabuf_mmap(struct dma_buf *dma_buf, struct vm_area_struct *vma);
     98  1.3  riastrad #endif
     99  1.1  riastrad 
    100  1.1  riastrad struct sg_table *drm_prime_pages_to_sg(struct page **pages, unsigned int nr_pages);
    101  1.1  riastrad struct dma_buf *drm_gem_prime_export(struct drm_gem_object *obj,
    102  1.1  riastrad 				     int flags);
    103  1.1  riastrad 
    104  1.1  riastrad /* helper functions for importing */
    105  1.7  riastrad #ifdef __NetBSD__
    106  1.7  riastrad struct drm_gem_object *drm_gem_prime_import_dev(struct drm_device *dev,
    107  1.7  riastrad 						struct dma_buf *dma_buf,
    108  1.7  riastrad 						bus_dma_tag_t attach_dev);
    109  1.7  riastrad #else
    110  1.1  riastrad struct drm_gem_object *drm_gem_prime_import_dev(struct drm_device *dev,
    111  1.1  riastrad 						struct dma_buf *dma_buf,
    112  1.1  riastrad 						struct device *attach_dev);
    113  1.7  riastrad #endif
    114  1.1  riastrad struct drm_gem_object *drm_gem_prime_import(struct drm_device *dev,
    115  1.1  riastrad 					    struct dma_buf *dma_buf);
    116  1.1  riastrad 
    117  1.1  riastrad void drm_prime_gem_destroy(struct drm_gem_object *obj, struct sg_table *sg);
    118  1.1  riastrad 
    119  1.4  riastrad #ifdef __NetBSD__
    120  1.4  riastrad extern struct sg_table *drm_prime_bus_dmamem_to_sg(bus_dma_tag_t, const bus_dma_segment_t *, int);
    121  1.4  riastrad extern int drm_prime_sg_to_bus_dmamem(bus_dma_tag_t, bus_dma_segment_t *, int, int *, const struct sg_table *);
    122  1.4  riastrad extern int drm_prime_bus_dmamap_load_sgt(bus_dma_tag_t, bus_dmamap_t, struct sg_table *);
    123  1.4  riastrad extern bus_size_t drm_prime_sg_size(struct sg_table *);
    124  1.4  riastrad extern void drm_prime_sg_free(struct sg_table *);
    125  1.4  riastrad extern bool drm_prime_sg_importable(bus_dma_tag_t, struct sg_table *);
    126  1.4  riastrad #else
    127  1.1  riastrad int drm_prime_sg_to_page_addr_arrays(struct sg_table *sgt, struct page **pages,
    128  1.1  riastrad 				     dma_addr_t *addrs, int max_pages);
    129  1.4  riastrad #endif
    130  1.1  riastrad 
    131  1.1  riastrad 
    132  1.1  riastrad #endif /* __DRM_PRIME_H__ */
    133