18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0 OR MIT
28c2ecf20Sopenharmony_ci/**************************************************************************
38c2ecf20Sopenharmony_ci *
48c2ecf20Sopenharmony_ci * Copyright 2013 VMware, Inc., Palo Alto, CA., USA
58c2ecf20Sopenharmony_ci *
68c2ecf20Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a
78c2ecf20Sopenharmony_ci * copy of this software and associated documentation files (the
88c2ecf20Sopenharmony_ci * "Software"), to deal in the Software without restriction, including
98c2ecf20Sopenharmony_ci * without limitation the rights to use, copy, modify, merge, publish,
108c2ecf20Sopenharmony_ci * distribute, sub license, and/or sell copies of the Software, and to
118c2ecf20Sopenharmony_ci * permit persons to whom the Software is furnished to do so, subject to
128c2ecf20Sopenharmony_ci * the following conditions:
138c2ecf20Sopenharmony_ci *
148c2ecf20Sopenharmony_ci * The above copyright notice and this permission notice (including the
158c2ecf20Sopenharmony_ci * next paragraph) shall be included in all copies or substantial portions
168c2ecf20Sopenharmony_ci * of the 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 NON-INFRINGEMENT. IN NO EVENT SHALL
218c2ecf20Sopenharmony_ci * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
228c2ecf20Sopenharmony_ci * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
238c2ecf20Sopenharmony_ci * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
248c2ecf20Sopenharmony_ci * USE OR OTHER DEALINGS IN THE SOFTWARE.
258c2ecf20Sopenharmony_ci *
268c2ecf20Sopenharmony_ci **************************************************************************/
278c2ecf20Sopenharmony_ci/*
288c2ecf20Sopenharmony_ci * Authors:
298c2ecf20Sopenharmony_ci *     Thomas Hellstrom <thellstrom@vmware.com>
308c2ecf20Sopenharmony_ci *
318c2ecf20Sopenharmony_ci */
328c2ecf20Sopenharmony_ci
338c2ecf20Sopenharmony_ci#include "vmwgfx_drv.h"
348c2ecf20Sopenharmony_ci#include "ttm_object.h"
358c2ecf20Sopenharmony_ci#include <linux/dma-buf.h>
368c2ecf20Sopenharmony_ci
378c2ecf20Sopenharmony_ci/*
388c2ecf20Sopenharmony_ci * DMA-BUF attach- and mapping methods. No need to implement
398c2ecf20Sopenharmony_ci * these until we have other virtual devices use them.
408c2ecf20Sopenharmony_ci */
418c2ecf20Sopenharmony_ci
428c2ecf20Sopenharmony_cistatic int vmw_prime_map_attach(struct dma_buf *dma_buf,
438c2ecf20Sopenharmony_ci				struct dma_buf_attachment *attach)
448c2ecf20Sopenharmony_ci{
458c2ecf20Sopenharmony_ci	return -ENOSYS;
468c2ecf20Sopenharmony_ci}
478c2ecf20Sopenharmony_ci
488c2ecf20Sopenharmony_cistatic void vmw_prime_map_detach(struct dma_buf *dma_buf,
498c2ecf20Sopenharmony_ci				 struct dma_buf_attachment *attach)
508c2ecf20Sopenharmony_ci{
518c2ecf20Sopenharmony_ci}
528c2ecf20Sopenharmony_ci
538c2ecf20Sopenharmony_cistatic struct sg_table *vmw_prime_map_dma_buf(struct dma_buf_attachment *attach,
548c2ecf20Sopenharmony_ci					      enum dma_data_direction dir)
558c2ecf20Sopenharmony_ci{
568c2ecf20Sopenharmony_ci	return ERR_PTR(-ENOSYS);
578c2ecf20Sopenharmony_ci}
588c2ecf20Sopenharmony_ci
598c2ecf20Sopenharmony_cistatic void vmw_prime_unmap_dma_buf(struct dma_buf_attachment *attach,
608c2ecf20Sopenharmony_ci				    struct sg_table *sgb,
618c2ecf20Sopenharmony_ci				    enum dma_data_direction dir)
628c2ecf20Sopenharmony_ci{
638c2ecf20Sopenharmony_ci}
648c2ecf20Sopenharmony_ci
658c2ecf20Sopenharmony_ciconst struct dma_buf_ops vmw_prime_dmabuf_ops =  {
668c2ecf20Sopenharmony_ci	.attach = vmw_prime_map_attach,
678c2ecf20Sopenharmony_ci	.detach = vmw_prime_map_detach,
688c2ecf20Sopenharmony_ci	.map_dma_buf = vmw_prime_map_dma_buf,
698c2ecf20Sopenharmony_ci	.unmap_dma_buf = vmw_prime_unmap_dma_buf,
708c2ecf20Sopenharmony_ci	.release = NULL,
718c2ecf20Sopenharmony_ci};
728c2ecf20Sopenharmony_ci
738c2ecf20Sopenharmony_ciint vmw_prime_fd_to_handle(struct drm_device *dev,
748c2ecf20Sopenharmony_ci			   struct drm_file *file_priv,
758c2ecf20Sopenharmony_ci			   int fd, u32 *handle)
768c2ecf20Sopenharmony_ci{
778c2ecf20Sopenharmony_ci	struct ttm_object_file *tfile = vmw_fpriv(file_priv)->tfile;
788c2ecf20Sopenharmony_ci
798c2ecf20Sopenharmony_ci	return ttm_prime_fd_to_handle(tfile, fd, handle);
808c2ecf20Sopenharmony_ci}
818c2ecf20Sopenharmony_ci
828c2ecf20Sopenharmony_ciint vmw_prime_handle_to_fd(struct drm_device *dev,
838c2ecf20Sopenharmony_ci			   struct drm_file *file_priv,
848c2ecf20Sopenharmony_ci			   uint32_t handle, uint32_t flags,
858c2ecf20Sopenharmony_ci			   int *prime_fd)
868c2ecf20Sopenharmony_ci{
878c2ecf20Sopenharmony_ci	struct ttm_object_file *tfile = vmw_fpriv(file_priv)->tfile;
888c2ecf20Sopenharmony_ci
898c2ecf20Sopenharmony_ci	return ttm_prime_handle_to_fd(tfile, handle, flags, prime_fd);
908c2ecf20Sopenharmony_ci}
91