qxl_gem.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. /*
  2. * Copyright 2013 Red Hat Inc.
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a
  5. * copy of this software and associated documentation files (the "Software"),
  6. * to deal in the Software without restriction, including without limitation
  7. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  8. * and/or sell copies of the Software, and to permit persons to whom the
  9. * Software is furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice shall be included in
  12. * all copies or substantial portions of the Software.
  13. *
  14. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  17. * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
  18. * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  19. * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  20. * OTHER DEALINGS IN THE SOFTWARE.
  21. *
  22. * Authors: Dave Airlie
  23. * Alon Levy
  24. */
  25. #include <drm/drm.h>
  26. #include "qxl_drv.h"
  27. #include "qxl_object.h"
  28. void qxl_gem_object_free(struct drm_gem_object *gobj)
  29. {
  30. struct qxl_bo *qobj = gem_to_qxl_bo(gobj);
  31. struct qxl_device *qdev;
  32. struct ttm_buffer_object *tbo;
  33. qdev = to_qxl(gobj->dev);
  34. qxl_surface_evict(qdev, qobj, false);
  35. tbo = &qobj->tbo;
  36. ttm_bo_put(tbo);
  37. }
  38. int qxl_gem_object_create(struct qxl_device *qdev, int size,
  39. int alignment, int initial_domain,
  40. bool discardable, bool kernel,
  41. struct qxl_surface *surf,
  42. struct drm_gem_object **obj)
  43. {
  44. struct qxl_bo *qbo;
  45. int r;
  46. *obj = NULL;
  47. /* At least align on page size */
  48. if (alignment < PAGE_SIZE)
  49. alignment = PAGE_SIZE;
  50. r = qxl_bo_create(qdev, size, kernel, false, initial_domain, 0, surf, &qbo);
  51. if (r) {
  52. if (r != -ERESTARTSYS)
  53. DRM_ERROR(
  54. "Failed to allocate GEM object (%d, %d, %u, %d)\n",
  55. size, initial_domain, alignment, r);
  56. return r;
  57. }
  58. *obj = &qbo->tbo.base;
  59. mutex_lock(&qdev->gem.mutex);
  60. list_add_tail(&qbo->list, &qdev->gem.objects);
  61. mutex_unlock(&qdev->gem.mutex);
  62. return 0;
  63. }
  64. /*
  65. * If the caller passed a valid gobj pointer, it is responsible to call
  66. * drm_gem_object_put() when it no longer needs to acess the object.
  67. *
  68. * If gobj is NULL, it is handled internally.
  69. */
  70. int qxl_gem_object_create_with_handle(struct qxl_device *qdev,
  71. struct drm_file *file_priv,
  72. u32 domain,
  73. size_t size,
  74. struct qxl_surface *surf,
  75. struct drm_gem_object **gobj,
  76. uint32_t *handle)
  77. {
  78. int r;
  79. struct drm_gem_object *local_gobj;
  80. BUG_ON(!handle);
  81. r = qxl_gem_object_create(qdev, size, 0,
  82. domain,
  83. false, false, surf,
  84. &local_gobj);
  85. if (r)
  86. return -ENOMEM;
  87. r = drm_gem_handle_create(file_priv, local_gobj, handle);
  88. if (r)
  89. return r;
  90. if (gobj)
  91. *gobj = local_gobj;
  92. else
  93. /* drop reference from allocate - handle holds it now */
  94. drm_gem_object_put(local_gobj);
  95. return 0;
  96. }
  97. int qxl_gem_object_open(struct drm_gem_object *obj, struct drm_file *file_priv)
  98. {
  99. return 0;
  100. }
  101. void qxl_gem_object_close(struct drm_gem_object *obj,
  102. struct drm_file *file_priv)
  103. {
  104. }
  105. void qxl_gem_init(struct qxl_device *qdev)
  106. {
  107. INIT_LIST_HEAD(&qdev->gem.objects);
  108. }
  109. void qxl_gem_fini(struct qxl_device *qdev)
  110. {
  111. qxl_bo_force_delete(qdev);
  112. }