162306a36Sopenharmony_ci/*
262306a36Sopenharmony_ci * Copyright © 2012 Red Hat
362306a36Sopenharmony_ci * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
462306a36Sopenharmony_ci * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
562306a36Sopenharmony_ci * Copyright (c) 2009-2010, Code Aurora Forum.
662306a36Sopenharmony_ci *
762306a36Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a
862306a36Sopenharmony_ci * copy of this software and associated documentation files (the "Software"),
962306a36Sopenharmony_ci * to deal in the Software without restriction, including without limitation
1062306a36Sopenharmony_ci * the rights to use, copy, modify, merge, publish, distribute, sublicense,
1162306a36Sopenharmony_ci * and/or sell copies of the Software, and to permit persons to whom the
1262306a36Sopenharmony_ci * Software is furnished to do so, subject to the following conditions:
1362306a36Sopenharmony_ci *
1462306a36Sopenharmony_ci * The above copyright notice and this permission notice (including the next
1562306a36Sopenharmony_ci * paragraph) shall be included in all copies or substantial portions of the
1662306a36Sopenharmony_ci * Software.
1762306a36Sopenharmony_ci *
1862306a36Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1962306a36Sopenharmony_ci * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
2062306a36Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
2162306a36Sopenharmony_ci * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
2262306a36Sopenharmony_ci * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
2362306a36Sopenharmony_ci * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
2462306a36Sopenharmony_ci * IN THE SOFTWARE.
2562306a36Sopenharmony_ci *
2662306a36Sopenharmony_ci * Authors:
2762306a36Sopenharmony_ci *      Dave Airlie <airlied@redhat.com>
2862306a36Sopenharmony_ci *      Rob Clark <rob.clark@linaro.org>
2962306a36Sopenharmony_ci *
3062306a36Sopenharmony_ci */
3162306a36Sopenharmony_ci
3262306a36Sopenharmony_ci#ifndef __DRM_PRIME_H__
3362306a36Sopenharmony_ci#define __DRM_PRIME_H__
3462306a36Sopenharmony_ci
3562306a36Sopenharmony_ci#include <linux/mutex.h>
3662306a36Sopenharmony_ci#include <linux/rbtree.h>
3762306a36Sopenharmony_ci#include <linux/scatterlist.h>
3862306a36Sopenharmony_ci
3962306a36Sopenharmony_ci/**
4062306a36Sopenharmony_ci * struct drm_prime_file_private - per-file tracking for PRIME
4162306a36Sopenharmony_ci *
4262306a36Sopenharmony_ci * This just contains the internal &struct dma_buf and handle caches for each
4362306a36Sopenharmony_ci * &struct drm_file used by the PRIME core code.
4462306a36Sopenharmony_ci */
4562306a36Sopenharmony_cistruct drm_prime_file_private {
4662306a36Sopenharmony_ci/* private: */
4762306a36Sopenharmony_ci	struct mutex lock;
4862306a36Sopenharmony_ci	struct rb_root dmabufs;
4962306a36Sopenharmony_ci	struct rb_root handles;
5062306a36Sopenharmony_ci};
5162306a36Sopenharmony_ci
5262306a36Sopenharmony_cistruct device;
5362306a36Sopenharmony_ci
5462306a36Sopenharmony_cistruct dma_buf_export_info;
5562306a36Sopenharmony_cistruct dma_buf;
5662306a36Sopenharmony_cistruct dma_buf_attachment;
5762306a36Sopenharmony_cistruct iosys_map;
5862306a36Sopenharmony_ci
5962306a36Sopenharmony_cienum dma_data_direction;
6062306a36Sopenharmony_ci
6162306a36Sopenharmony_cistruct drm_device;
6262306a36Sopenharmony_cistruct drm_gem_object;
6362306a36Sopenharmony_cistruct drm_file;
6462306a36Sopenharmony_ci
6562306a36Sopenharmony_ci/* core prime functions */
6662306a36Sopenharmony_cistruct dma_buf *drm_gem_dmabuf_export(struct drm_device *dev,
6762306a36Sopenharmony_ci				      struct dma_buf_export_info *exp_info);
6862306a36Sopenharmony_civoid drm_gem_dmabuf_release(struct dma_buf *dma_buf);
6962306a36Sopenharmony_ci
7062306a36Sopenharmony_ciint drm_gem_prime_fd_to_handle(struct drm_device *dev,
7162306a36Sopenharmony_ci			       struct drm_file *file_priv, int prime_fd, uint32_t *handle);
7262306a36Sopenharmony_ciint drm_gem_prime_handle_to_fd(struct drm_device *dev,
7362306a36Sopenharmony_ci			       struct drm_file *file_priv, uint32_t handle, uint32_t flags,
7462306a36Sopenharmony_ci			       int *prime_fd);
7562306a36Sopenharmony_ci
7662306a36Sopenharmony_ci/* helper functions for exporting */
7762306a36Sopenharmony_ciint drm_gem_map_attach(struct dma_buf *dma_buf,
7862306a36Sopenharmony_ci		       struct dma_buf_attachment *attach);
7962306a36Sopenharmony_civoid drm_gem_map_detach(struct dma_buf *dma_buf,
8062306a36Sopenharmony_ci			struct dma_buf_attachment *attach);
8162306a36Sopenharmony_cistruct sg_table *drm_gem_map_dma_buf(struct dma_buf_attachment *attach,
8262306a36Sopenharmony_ci				     enum dma_data_direction dir);
8362306a36Sopenharmony_civoid drm_gem_unmap_dma_buf(struct dma_buf_attachment *attach,
8462306a36Sopenharmony_ci			   struct sg_table *sgt,
8562306a36Sopenharmony_ci			   enum dma_data_direction dir);
8662306a36Sopenharmony_ciint drm_gem_dmabuf_vmap(struct dma_buf *dma_buf, struct iosys_map *map);
8762306a36Sopenharmony_civoid drm_gem_dmabuf_vunmap(struct dma_buf *dma_buf, struct iosys_map *map);
8862306a36Sopenharmony_ci
8962306a36Sopenharmony_ciint drm_gem_prime_mmap(struct drm_gem_object *obj, struct vm_area_struct *vma);
9062306a36Sopenharmony_ciint drm_gem_dmabuf_mmap(struct dma_buf *dma_buf, struct vm_area_struct *vma);
9162306a36Sopenharmony_ci
9262306a36Sopenharmony_cistruct sg_table *drm_prime_pages_to_sg(struct drm_device *dev,
9362306a36Sopenharmony_ci				       struct page **pages, unsigned int nr_pages);
9462306a36Sopenharmony_cistruct dma_buf *drm_gem_prime_export(struct drm_gem_object *obj,
9562306a36Sopenharmony_ci				     int flags);
9662306a36Sopenharmony_ci
9762306a36Sopenharmony_ciunsigned long drm_prime_get_contiguous_size(struct sg_table *sgt);
9862306a36Sopenharmony_ci
9962306a36Sopenharmony_ci/* helper functions for importing */
10062306a36Sopenharmony_cistruct drm_gem_object *drm_gem_prime_import_dev(struct drm_device *dev,
10162306a36Sopenharmony_ci						struct dma_buf *dma_buf,
10262306a36Sopenharmony_ci						struct device *attach_dev);
10362306a36Sopenharmony_cistruct drm_gem_object *drm_gem_prime_import(struct drm_device *dev,
10462306a36Sopenharmony_ci					    struct dma_buf *dma_buf);
10562306a36Sopenharmony_ci
10662306a36Sopenharmony_civoid drm_prime_gem_destroy(struct drm_gem_object *obj, struct sg_table *sg);
10762306a36Sopenharmony_ci
10862306a36Sopenharmony_ciint drm_prime_sg_to_page_array(struct sg_table *sgt, struct page **pages,
10962306a36Sopenharmony_ci			       int max_pages);
11062306a36Sopenharmony_ciint drm_prime_sg_to_dma_addr_array(struct sg_table *sgt, dma_addr_t *addrs,
11162306a36Sopenharmony_ci				   int max_pages);
11262306a36Sopenharmony_ci
11362306a36Sopenharmony_ci#endif /* __DRM_PRIME_H__ */
114