18c2ecf20Sopenharmony_ci/*
28c2ecf20Sopenharmony_ci * Copyright © 2012 Red Hat
38c2ecf20Sopenharmony_ci * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
48c2ecf20Sopenharmony_ci * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
58c2ecf20Sopenharmony_ci * Copyright (c) 2009-2010, Code Aurora Forum.
68c2ecf20Sopenharmony_ci *
78c2ecf20Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a
88c2ecf20Sopenharmony_ci * copy of this software and associated documentation files (the "Software"),
98c2ecf20Sopenharmony_ci * to deal in the Software without restriction, including without limitation
108c2ecf20Sopenharmony_ci * the rights to use, copy, modify, merge, publish, distribute, sublicense,
118c2ecf20Sopenharmony_ci * and/or sell copies of the Software, and to permit persons to whom the
128c2ecf20Sopenharmony_ci * Software is furnished to do so, subject to the following conditions:
138c2ecf20Sopenharmony_ci *
148c2ecf20Sopenharmony_ci * The above copyright notice and this permission notice (including the next
158c2ecf20Sopenharmony_ci * paragraph) shall be included in all copies or substantial portions of the
168c2ecf20Sopenharmony_ci * Software.
178c2ecf20Sopenharmony_ci *
188c2ecf20Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
198c2ecf20Sopenharmony_ci * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
208c2ecf20Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
218c2ecf20Sopenharmony_ci * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
228c2ecf20Sopenharmony_ci * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
238c2ecf20Sopenharmony_ci * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
248c2ecf20Sopenharmony_ci * IN THE SOFTWARE.
258c2ecf20Sopenharmony_ci *
268c2ecf20Sopenharmony_ci * Authors:
278c2ecf20Sopenharmony_ci *      Dave Airlie <airlied@redhat.com>
288c2ecf20Sopenharmony_ci *      Rob Clark <rob.clark@linaro.org>
298c2ecf20Sopenharmony_ci *
308c2ecf20Sopenharmony_ci */
318c2ecf20Sopenharmony_ci
328c2ecf20Sopenharmony_ci#ifndef __DRM_PRIME_H__
338c2ecf20Sopenharmony_ci#define __DRM_PRIME_H__
348c2ecf20Sopenharmony_ci
358c2ecf20Sopenharmony_ci#include <linux/mutex.h>
368c2ecf20Sopenharmony_ci#include <linux/rbtree.h>
378c2ecf20Sopenharmony_ci#include <linux/scatterlist.h>
388c2ecf20Sopenharmony_ci
398c2ecf20Sopenharmony_ci/**
408c2ecf20Sopenharmony_ci * struct drm_prime_file_private - per-file tracking for PRIME
418c2ecf20Sopenharmony_ci *
428c2ecf20Sopenharmony_ci * This just contains the internal &struct dma_buf and handle caches for each
438c2ecf20Sopenharmony_ci * &struct drm_file used by the PRIME core code.
448c2ecf20Sopenharmony_ci */
458c2ecf20Sopenharmony_cistruct drm_prime_file_private {
468c2ecf20Sopenharmony_ci/* private: */
478c2ecf20Sopenharmony_ci	struct mutex lock;
488c2ecf20Sopenharmony_ci	struct rb_root dmabufs;
498c2ecf20Sopenharmony_ci	struct rb_root handles;
508c2ecf20Sopenharmony_ci};
518c2ecf20Sopenharmony_ci
528c2ecf20Sopenharmony_cistruct device;
538c2ecf20Sopenharmony_ci
548c2ecf20Sopenharmony_cistruct dma_buf_export_info;
558c2ecf20Sopenharmony_cistruct dma_buf;
568c2ecf20Sopenharmony_cistruct dma_buf_attachment;
578c2ecf20Sopenharmony_ci
588c2ecf20Sopenharmony_cienum dma_data_direction;
598c2ecf20Sopenharmony_ci
608c2ecf20Sopenharmony_cistruct drm_device;
618c2ecf20Sopenharmony_cistruct drm_gem_object;
628c2ecf20Sopenharmony_cistruct drm_file;
638c2ecf20Sopenharmony_ci
648c2ecf20Sopenharmony_ci/* core prime functions */
658c2ecf20Sopenharmony_cistruct dma_buf *drm_gem_dmabuf_export(struct drm_device *dev,
668c2ecf20Sopenharmony_ci				      struct dma_buf_export_info *exp_info);
678c2ecf20Sopenharmony_civoid drm_gem_dmabuf_release(struct dma_buf *dma_buf);
688c2ecf20Sopenharmony_ci
698c2ecf20Sopenharmony_ciint drm_gem_prime_fd_to_handle(struct drm_device *dev,
708c2ecf20Sopenharmony_ci			       struct drm_file *file_priv, int prime_fd, uint32_t *handle);
718c2ecf20Sopenharmony_ciint drm_gem_prime_handle_to_fd(struct drm_device *dev,
728c2ecf20Sopenharmony_ci			       struct drm_file *file_priv, uint32_t handle, uint32_t flags,
738c2ecf20Sopenharmony_ci			       int *prime_fd);
748c2ecf20Sopenharmony_ci
758c2ecf20Sopenharmony_ci/* helper functions for exporting */
768c2ecf20Sopenharmony_ciint drm_gem_map_attach(struct dma_buf *dma_buf,
778c2ecf20Sopenharmony_ci		       struct dma_buf_attachment *attach);
788c2ecf20Sopenharmony_civoid drm_gem_map_detach(struct dma_buf *dma_buf,
798c2ecf20Sopenharmony_ci			struct dma_buf_attachment *attach);
808c2ecf20Sopenharmony_cistruct sg_table *drm_gem_map_dma_buf(struct dma_buf_attachment *attach,
818c2ecf20Sopenharmony_ci				     enum dma_data_direction dir);
828c2ecf20Sopenharmony_civoid drm_gem_unmap_dma_buf(struct dma_buf_attachment *attach,
838c2ecf20Sopenharmony_ci			   struct sg_table *sgt,
848c2ecf20Sopenharmony_ci			   enum dma_data_direction dir);
858c2ecf20Sopenharmony_civoid *drm_gem_dmabuf_vmap(struct dma_buf *dma_buf);
868c2ecf20Sopenharmony_civoid drm_gem_dmabuf_vunmap(struct dma_buf *dma_buf, void *vaddr);
878c2ecf20Sopenharmony_ci
888c2ecf20Sopenharmony_ciint drm_gem_prime_mmap(struct drm_gem_object *obj, struct vm_area_struct *vma);
898c2ecf20Sopenharmony_ciint drm_gem_dmabuf_mmap(struct dma_buf *dma_buf, struct vm_area_struct *vma);
908c2ecf20Sopenharmony_ci
918c2ecf20Sopenharmony_cistruct sg_table *drm_prime_pages_to_sg(struct drm_device *dev,
928c2ecf20Sopenharmony_ci				       struct page **pages, unsigned int nr_pages);
938c2ecf20Sopenharmony_cistruct dma_buf *drm_gem_prime_export(struct drm_gem_object *obj,
948c2ecf20Sopenharmony_ci				     int flags);
958c2ecf20Sopenharmony_ci
968c2ecf20Sopenharmony_ciunsigned long drm_prime_get_contiguous_size(struct sg_table *sgt);
978c2ecf20Sopenharmony_ci
988c2ecf20Sopenharmony_ci/* helper functions for importing */
998c2ecf20Sopenharmony_cistruct drm_gem_object *drm_gem_prime_import_dev(struct drm_device *dev,
1008c2ecf20Sopenharmony_ci						struct dma_buf *dma_buf,
1018c2ecf20Sopenharmony_ci						struct device *attach_dev);
1028c2ecf20Sopenharmony_cistruct drm_gem_object *drm_gem_prime_import(struct drm_device *dev,
1038c2ecf20Sopenharmony_ci					    struct dma_buf *dma_buf);
1048c2ecf20Sopenharmony_ci
1058c2ecf20Sopenharmony_civoid drm_prime_gem_destroy(struct drm_gem_object *obj, struct sg_table *sg);
1068c2ecf20Sopenharmony_ci
1078c2ecf20Sopenharmony_ciint drm_prime_sg_to_page_addr_arrays(struct sg_table *sgt, struct page **pages,
1088c2ecf20Sopenharmony_ci				     dma_addr_t *addrs, int max_pages);
1098c2ecf20Sopenharmony_ci
1108c2ecf20Sopenharmony_ci
1118c2ecf20Sopenharmony_ci#endif /* __DRM_PRIME_H__ */
112