msm_gem_prime.c 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /*
  2. * Copyright (C) 2013 Red Hat
  3. * Author: Rob Clark <robdclark@gmail.com>
  4. *
  5. * This program is free software; you can redistribute it and/or modify it
  6. * under the terms of the GNU General Public License version 2 as published by
  7. * the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope that it will be useful, but WITHOUT
  10. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  12. * more details.
  13. *
  14. * You should have received a copy of the GNU General Public License along with
  15. * this program. If not, see <http://www.gnu.org/licenses/>.
  16. */
  17. #include "msm_drv.h"
  18. #include "msm_gem.h"
  19. #include <linux/dma-buf.h>
  20. struct sg_table *msm_gem_prime_get_sg_table(struct drm_gem_object *obj)
  21. {
  22. struct msm_gem_object *msm_obj = to_msm_bo(obj);
  23. int npages = obj->size >> PAGE_SHIFT;
  24. if (WARN_ON(!msm_obj->pages)) /* should have already pinned! */
  25. return NULL;
  26. return drm_prime_pages_to_sg(msm_obj->pages, npages);
  27. }
  28. void *msm_gem_prime_vmap(struct drm_gem_object *obj)
  29. {
  30. return msm_gem_vaddr(obj);
  31. }
  32. void msm_gem_prime_vunmap(struct drm_gem_object *obj, void *vaddr)
  33. {
  34. /* TODO msm_gem_vunmap() */
  35. }
  36. int msm_gem_prime_mmap(struct drm_gem_object *obj, struct vm_area_struct *vma)
  37. {
  38. int ret;
  39. ret = drm_gem_mmap_obj(obj, obj->size, vma);
  40. if (ret < 0)
  41. return ret;
  42. return msm_gem_mmap_obj(vma->vm_private_data, vma);
  43. }
  44. struct drm_gem_object *msm_gem_prime_import_sg_table(struct drm_device *dev,
  45. struct dma_buf_attachment *attach, struct sg_table *sg)
  46. {
  47. return msm_gem_import(dev, attach->dmabuf->size, sg);
  48. }
  49. int msm_gem_prime_pin(struct drm_gem_object *obj)
  50. {
  51. if (!obj->import_attach)
  52. msm_gem_get_pages(obj);
  53. return 0;
  54. }
  55. void msm_gem_prime_unpin(struct drm_gem_object *obj)
  56. {
  57. if (!obj->import_attach)
  58. msm_gem_put_pages(obj);
  59. }
  60. struct reservation_object *msm_gem_prime_res_obj(struct drm_gem_object *obj)
  61. {
  62. struct msm_gem_object *msm_obj = to_msm_bo(obj);
  63. return msm_obj->resv;
  64. }