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