1*9ff13907Sriastradh /* $NetBSD: drm_prime.h,v 1.7 2021/12/19 11:33:30 riastradh Exp $ */ 24e390cabSriastradh 34e390cabSriastradh /* 44e390cabSriastradh * Copyright © 2012 Red Hat 54e390cabSriastradh * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas. 64e390cabSriastradh * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California. 74e390cabSriastradh * Copyright (c) 2009-2010, Code Aurora Forum. 84e390cabSriastradh * 94e390cabSriastradh * Permission is hereby granted, free of charge, to any person obtaining a 104e390cabSriastradh * copy of this software and associated documentation files (the "Software"), 114e390cabSriastradh * to deal in the Software without restriction, including without limitation 124e390cabSriastradh * the rights to use, copy, modify, merge, publish, distribute, sublicense, 134e390cabSriastradh * and/or sell copies of the Software, and to permit persons to whom the 144e390cabSriastradh * Software is furnished to do so, subject to the following conditions: 154e390cabSriastradh * 164e390cabSriastradh * The above copyright notice and this permission notice (including the next 174e390cabSriastradh * paragraph) shall be included in all copies or substantial portions of the 184e390cabSriastradh * Software. 194e390cabSriastradh * 204e390cabSriastradh * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 214e390cabSriastradh * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 224e390cabSriastradh * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 234e390cabSriastradh * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 244e390cabSriastradh * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 254e390cabSriastradh * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 264e390cabSriastradh * IN THE SOFTWARE. 274e390cabSriastradh * 284e390cabSriastradh * Authors: 294e390cabSriastradh * Dave Airlie <airlied@redhat.com> 304e390cabSriastradh * Rob Clark <rob.clark@linaro.org> 314e390cabSriastradh * 324e390cabSriastradh */ 334e390cabSriastradh 344e390cabSriastradh #ifndef __DRM_PRIME_H__ 354e390cabSriastradh #define __DRM_PRIME_H__ 364e390cabSriastradh 374e390cabSriastradh #include <linux/mutex.h> 384e390cabSriastradh #include <linux/rbtree.h> 394e390cabSriastradh #include <linux/scatterlist.h> 404e390cabSriastradh 414e390cabSriastradh /** 424e390cabSriastradh * struct drm_prime_file_private - per-file tracking for PRIME 434e390cabSriastradh * 444e390cabSriastradh * This just contains the internal &struct dma_buf and handle caches for each 454e390cabSriastradh * &struct drm_file used by the PRIME core code. 464e390cabSriastradh */ 474e390cabSriastradh struct drm_prime_file_private { 484e390cabSriastradh /* private: */ 494e390cabSriastradh struct mutex lock; 504e390cabSriastradh struct rb_root dmabufs; 514e390cabSriastradh struct rb_root handles; 524e390cabSriastradh }; 534e390cabSriastradh 544e390cabSriastradh struct device; 554e390cabSriastradh 564e390cabSriastradh struct dma_buf_export_info; 574e390cabSriastradh struct dma_buf; 584e390cabSriastradh struct dma_buf_attachment; 594e390cabSriastradh 604e390cabSriastradh enum dma_data_direction; 614e390cabSriastradh 624e390cabSriastradh struct drm_device; 634e390cabSriastradh struct drm_gem_object; 644e390cabSriastradh struct drm_file; 654e390cabSriastradh 664e390cabSriastradh /* core prime functions */ 674e390cabSriastradh struct dma_buf *drm_gem_dmabuf_export(struct drm_device *dev, 684e390cabSriastradh struct dma_buf_export_info *exp_info); 694e390cabSriastradh void drm_gem_dmabuf_release(struct dma_buf *dma_buf); 704e390cabSriastradh 714e390cabSriastradh int drm_gem_prime_fd_to_handle(struct drm_device *dev, 724e390cabSriastradh struct drm_file *file_priv, int prime_fd, uint32_t *handle); 734e390cabSriastradh int drm_gem_prime_handle_to_fd(struct drm_device *dev, 744e390cabSriastradh struct drm_file *file_priv, uint32_t handle, uint32_t flags, 754e390cabSriastradh int *prime_fd); 764e390cabSriastradh 774e390cabSriastradh /* helper functions for exporting */ 784e390cabSriastradh int drm_gem_map_attach(struct dma_buf *dma_buf, 794e390cabSriastradh struct dma_buf_attachment *attach); 804e390cabSriastradh void drm_gem_map_detach(struct dma_buf *dma_buf, 814e390cabSriastradh struct dma_buf_attachment *attach); 824e390cabSriastradh struct sg_table *drm_gem_map_dma_buf(struct dma_buf_attachment *attach, 834e390cabSriastradh enum dma_data_direction dir); 844e390cabSriastradh void drm_gem_unmap_dma_buf(struct dma_buf_attachment *attach, 854e390cabSriastradh struct sg_table *sgt, 864e390cabSriastradh enum dma_data_direction dir); 874e390cabSriastradh void *drm_gem_dmabuf_vmap(struct dma_buf *dma_buf); 884e390cabSriastradh void drm_gem_dmabuf_vunmap(struct dma_buf *dma_buf, void *vaddr); 894e390cabSriastradh 90c0244fa5Sriastradh #ifdef __NetBSD__ 9176f0c10cSriastradh int drm_gem_prime_mmap(struct drm_gem_object *, off_t *, size_t, int, int *, 92c0244fa5Sriastradh int *, struct uvm_object **, int *); 93c0244fa5Sriastradh int drm_gem_dmabuf_mmap(struct dma_buf *, off_t *, size_t, int, int *, 94c0244fa5Sriastradh int *, struct uvm_object **, int *); 95c0244fa5Sriastradh #else 964e390cabSriastradh int drm_gem_prime_mmap(struct drm_gem_object *obj, struct vm_area_struct *vma); 974e390cabSriastradh int drm_gem_dmabuf_mmap(struct dma_buf *dma_buf, struct vm_area_struct *vma); 98c0244fa5Sriastradh #endif 994e390cabSriastradh 1004e390cabSriastradh struct sg_table *drm_prime_pages_to_sg(struct page **pages, unsigned int nr_pages); 1014e390cabSriastradh struct dma_buf *drm_gem_prime_export(struct drm_gem_object *obj, 1024e390cabSriastradh int flags); 1034e390cabSriastradh 1044e390cabSriastradh /* helper functions for importing */ 105*9ff13907Sriastradh #ifdef __NetBSD__ 106*9ff13907Sriastradh struct drm_gem_object *drm_gem_prime_import_dev(struct drm_device *dev, 107*9ff13907Sriastradh struct dma_buf *dma_buf, 108*9ff13907Sriastradh bus_dma_tag_t attach_dev); 109*9ff13907Sriastradh #else 1104e390cabSriastradh struct drm_gem_object *drm_gem_prime_import_dev(struct drm_device *dev, 1114e390cabSriastradh struct dma_buf *dma_buf, 1124e390cabSriastradh struct device *attach_dev); 113*9ff13907Sriastradh #endif 1144e390cabSriastradh struct drm_gem_object *drm_gem_prime_import(struct drm_device *dev, 1154e390cabSriastradh struct dma_buf *dma_buf); 1164e390cabSriastradh 1174e390cabSriastradh void drm_prime_gem_destroy(struct drm_gem_object *obj, struct sg_table *sg); 1184e390cabSriastradh 1197d1ade81Sriastradh #ifdef __NetBSD__ 1207d1ade81Sriastradh extern struct sg_table *drm_prime_bus_dmamem_to_sg(bus_dma_tag_t, const bus_dma_segment_t *, int); 1217d1ade81Sriastradh extern int drm_prime_sg_to_bus_dmamem(bus_dma_tag_t, bus_dma_segment_t *, int, int *, const struct sg_table *); 1227d1ade81Sriastradh extern int drm_prime_bus_dmamap_load_sgt(bus_dma_tag_t, bus_dmamap_t, struct sg_table *); 1237d1ade81Sriastradh extern bus_size_t drm_prime_sg_size(struct sg_table *); 1247d1ade81Sriastradh extern void drm_prime_sg_free(struct sg_table *); 1257d1ade81Sriastradh extern bool drm_prime_sg_importable(bus_dma_tag_t, struct sg_table *); 1267d1ade81Sriastradh #else 1274e390cabSriastradh int drm_prime_sg_to_page_addr_arrays(struct sg_table *sgt, struct page **pages, 1284e390cabSriastradh dma_addr_t *addrs, int max_pages); 1297d1ade81Sriastradh #endif 1304e390cabSriastradh 1314e390cabSriastradh 1324e390cabSriastradh #endif /* __DRM_PRIME_H__ */ 133