vmwgfx_prime.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. // SPDX-License-Identifier: GPL-2.0 OR MIT
  2. /**************************************************************************
  3. *
  4. * Copyright (c) 2013-2024 Broadcom. All Rights Reserved. The term
  5. * “Broadcom” refers to Broadcom Inc. and/or its subsidiaries.
  6. *
  7. * Permission is hereby granted, free of charge, to any person obtaining a
  8. * copy of this software and associated documentation files (the
  9. * "Software"), to deal in the Software without restriction, including
  10. * without limitation the rights to use, copy, modify, merge, publish,
  11. * distribute, sub license, and/or sell copies of the Software, and to
  12. * permit persons to whom the Software is furnished to do so, subject to
  13. * the following conditions:
  14. *
  15. * The above copyright notice and this permission notice (including the
  16. * next paragraph) shall be included in all copies or substantial portions
  17. * of the Software.
  18. *
  19. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  20. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  21. * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
  22. * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
  23. * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  24. * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  25. * USE OR OTHER DEALINGS IN THE SOFTWARE.
  26. *
  27. **************************************************************************/
  28. /*
  29. * Authors:
  30. * Thomas Hellstrom <thellstrom@vmware.com>
  31. *
  32. */
  33. #include "vmwgfx_drv.h"
  34. #include "vmwgfx_bo.h"
  35. #include "ttm_object.h"
  36. #include <linux/dma-buf.h>
  37. /*
  38. * DMA-BUF attach- and mapping methods. No need to implement
  39. * these until we have other virtual devices use them.
  40. */
  41. static int vmw_prime_map_attach(struct dma_buf *dma_buf,
  42. struct dma_buf_attachment *attach)
  43. {
  44. return -ENOSYS;
  45. }
  46. static void vmw_prime_map_detach(struct dma_buf *dma_buf,
  47. struct dma_buf_attachment *attach)
  48. {
  49. }
  50. static struct sg_table *vmw_prime_map_dma_buf(struct dma_buf_attachment *attach,
  51. enum dma_data_direction dir)
  52. {
  53. return ERR_PTR(-ENOSYS);
  54. }
  55. static void vmw_prime_unmap_dma_buf(struct dma_buf_attachment *attach,
  56. struct sg_table *sgb,
  57. enum dma_data_direction dir)
  58. {
  59. }
  60. const struct dma_buf_ops vmw_prime_dmabuf_ops = {
  61. .attach = vmw_prime_map_attach,
  62. .detach = vmw_prime_map_detach,
  63. .map_dma_buf = vmw_prime_map_dma_buf,
  64. .unmap_dma_buf = vmw_prime_unmap_dma_buf,
  65. .release = NULL,
  66. };
  67. int vmw_prime_fd_to_handle(struct drm_device *dev,
  68. struct drm_file *file_priv,
  69. int fd, u32 *handle)
  70. {
  71. struct ttm_object_file *tfile = vmw_fpriv(file_priv)->tfile;
  72. int ret = ttm_prime_fd_to_handle(tfile, fd, handle);
  73. if (ret)
  74. ret = drm_gem_prime_fd_to_handle(dev, file_priv, fd, handle);
  75. return ret;
  76. }
  77. int vmw_prime_handle_to_fd(struct drm_device *dev,
  78. struct drm_file *file_priv,
  79. uint32_t handle, uint32_t flags,
  80. int *prime_fd)
  81. {
  82. struct vmw_private *vmw = vmw_priv(dev);
  83. struct ttm_object_file *tfile = vmw_fpriv(file_priv)->tfile;
  84. struct vmw_bo *vbo;
  85. int ret;
  86. int surf_handle;
  87. if (handle > VMWGFX_NUM_MOB) {
  88. ret = ttm_prime_handle_to_fd(tfile, handle, flags, prime_fd);
  89. } else {
  90. ret = vmw_user_bo_lookup(file_priv, handle, &vbo);
  91. if (ret)
  92. return ret;
  93. if (vbo && vbo->is_dumb) {
  94. ret = drm_gem_prime_handle_to_fd(dev, file_priv, handle,
  95. flags, prime_fd);
  96. } else {
  97. surf_handle = vmw_lookup_surface_handle_for_buffer(vmw,
  98. vbo,
  99. handle);
  100. if (surf_handle > 0)
  101. ret = ttm_prime_handle_to_fd(tfile, surf_handle,
  102. flags, prime_fd);
  103. else
  104. ret = drm_gem_prime_handle_to_fd(dev, file_priv,
  105. handle, flags,
  106. prime_fd);
  107. }
  108. vmw_user_bo_unref(&vbo);
  109. }
  110. return ret;
  111. }