qxl_gem.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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. int qxl_gem_object_create_with_handle(struct qxl_device *qdev,
  65. struct drm_file *file_priv,
  66. u32 domain,
  67. size_t size,
  68. struct qxl_surface *surf,
  69. struct qxl_bo **qobj,
  70. uint32_t *handle)
  71. {
  72. struct drm_gem_object *gobj;
  73. int r;
  74. BUG_ON(!qobj);
  75. BUG_ON(!handle);
  76. r = qxl_gem_object_create(qdev, size, 0,
  77. domain,
  78. false, false, surf,
  79. &gobj);
  80. if (r)
  81. return -ENOMEM;
  82. r = drm_gem_handle_create(file_priv, gobj, handle);
  83. if (r)
  84. return r;
  85. /* drop reference from allocate - handle holds it now */
  86. *qobj = gem_to_qxl_bo(gobj);
  87. drm_gem_object_put(gobj);
  88. return 0;
  89. }
  90. int qxl_gem_object_open(struct drm_gem_object *obj, struct drm_file *file_priv)
  91. {
  92. return 0;
  93. }
  94. void qxl_gem_object_close(struct drm_gem_object *obj,
  95. struct drm_file *file_priv)
  96. {
  97. }
  98. void qxl_gem_init(struct qxl_device *qdev)
  99. {
  100. INIT_LIST_HEAD(&qdev->gem.objects);
  101. }
  102. void qxl_gem_fini(struct qxl_device *qdev)
  103. {
  104. qxl_bo_force_delete(qdev);
  105. }