vmwgfx_prime.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. /**************************************************************************
  2. *
  3. * Copyright © 2013 VMware, Inc., Palo Alto, CA., USA
  4. * All Rights Reserved.
  5. *
  6. * Permission is hereby granted, free of charge, to any person obtaining a
  7. * copy of this software and associated documentation files (the
  8. * "Software"), to deal in the Software without restriction, including
  9. * without limitation the rights to use, copy, modify, merge, publish,
  10. * distribute, sub license, and/or sell copies of the Software, and to
  11. * permit persons to whom the Software is furnished to do so, subject to
  12. * the following conditions:
  13. *
  14. * The above copyright notice and this permission notice (including the
  15. * next paragraph) shall be included in all copies or substantial portions
  16. * of the Software.
  17. *
  18. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  19. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  20. * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
  21. * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
  22. * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  23. * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  24. * USE OR OTHER DEALINGS IN THE SOFTWARE.
  25. *
  26. **************************************************************************/
  27. /*
  28. * Authors:
  29. * Thomas Hellstrom <thellstrom@vmware.com>
  30. *
  31. */
  32. #include "vmwgfx_drv.h"
  33. #include <linux/dma-buf.h>
  34. #include <drm/ttm/ttm_object.h>
  35. /*
  36. * DMA-BUF attach- and mapping methods. No need to implement
  37. * these until we have other virtual devices use them.
  38. */
  39. static int vmw_prime_map_attach(struct dma_buf *dma_buf,
  40. struct device *target_dev,
  41. struct dma_buf_attachment *attach)
  42. {
  43. return -ENOSYS;
  44. }
  45. static void vmw_prime_map_detach(struct dma_buf *dma_buf,
  46. struct dma_buf_attachment *attach)
  47. {
  48. }
  49. static struct sg_table *vmw_prime_map_dma_buf(struct dma_buf_attachment *attach,
  50. enum dma_data_direction dir)
  51. {
  52. return ERR_PTR(-ENOSYS);
  53. }
  54. static void vmw_prime_unmap_dma_buf(struct dma_buf_attachment *attach,
  55. struct sg_table *sgb,
  56. enum dma_data_direction dir)
  57. {
  58. }
  59. static void *vmw_prime_dmabuf_vmap(struct dma_buf *dma_buf)
  60. {
  61. return NULL;
  62. }
  63. static void vmw_prime_dmabuf_vunmap(struct dma_buf *dma_buf, void *vaddr)
  64. {
  65. }
  66. static void *vmw_prime_dmabuf_kmap_atomic(struct dma_buf *dma_buf,
  67. unsigned long page_num)
  68. {
  69. return NULL;
  70. }
  71. static void vmw_prime_dmabuf_kunmap_atomic(struct dma_buf *dma_buf,
  72. unsigned long page_num, void *addr)
  73. {
  74. }
  75. static void *vmw_prime_dmabuf_kmap(struct dma_buf *dma_buf,
  76. unsigned long page_num)
  77. {
  78. return NULL;
  79. }
  80. static void vmw_prime_dmabuf_kunmap(struct dma_buf *dma_buf,
  81. unsigned long page_num, void *addr)
  82. {
  83. }
  84. static int vmw_prime_dmabuf_mmap(struct dma_buf *dma_buf,
  85. struct vm_area_struct *vma)
  86. {
  87. WARN_ONCE(true, "Attempted use of dmabuf mmap. Bad.\n");
  88. return -ENOSYS;
  89. }
  90. const struct dma_buf_ops vmw_prime_dmabuf_ops = {
  91. .attach = vmw_prime_map_attach,
  92. .detach = vmw_prime_map_detach,
  93. .map_dma_buf = vmw_prime_map_dma_buf,
  94. .unmap_dma_buf = vmw_prime_unmap_dma_buf,
  95. .release = NULL,
  96. .kmap = vmw_prime_dmabuf_kmap,
  97. .kmap_atomic = vmw_prime_dmabuf_kmap_atomic,
  98. .kunmap = vmw_prime_dmabuf_kunmap,
  99. .kunmap_atomic = vmw_prime_dmabuf_kunmap_atomic,
  100. .mmap = vmw_prime_dmabuf_mmap,
  101. .vmap = vmw_prime_dmabuf_vmap,
  102. .vunmap = vmw_prime_dmabuf_vunmap,
  103. };
  104. int vmw_prime_fd_to_handle(struct drm_device *dev,
  105. struct drm_file *file_priv,
  106. int fd, u32 *handle)
  107. {
  108. struct ttm_object_file *tfile = vmw_fpriv(file_priv)->tfile;
  109. return ttm_prime_fd_to_handle(tfile, fd, handle);
  110. }
  111. int vmw_prime_handle_to_fd(struct drm_device *dev,
  112. struct drm_file *file_priv,
  113. uint32_t handle, uint32_t flags,
  114. int *prime_fd)
  115. {
  116. struct ttm_object_file *tfile = vmw_fpriv(file_priv)->tfile;
  117. return ttm_prime_handle_to_fd(tfile, handle, flags, prime_fd);
  118. }