qxl_gem.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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 "drmP.h"
  26. #include "drm/drm.h"
  27. #include "qxl_drv.h"
  28. #include "qxl_object.h"
  29. void qxl_gem_object_free(struct drm_gem_object *gobj)
  30. {
  31. struct qxl_bo *qobj = gem_to_qxl_bo(gobj);
  32. struct qxl_device *qdev;
  33. struct ttm_buffer_object *tbo;
  34. qdev = (struct qxl_device *)gobj->dev->dev_private;
  35. qxl_surface_evict(qdev, qobj, false);
  36. tbo = &qobj->tbo;
  37. ttm_bo_unref(&tbo);
  38. }
  39. int qxl_gem_object_create(struct qxl_device *qdev, int size,
  40. int alignment, int initial_domain,
  41. bool discardable, bool kernel,
  42. struct qxl_surface *surf,
  43. struct drm_gem_object **obj)
  44. {
  45. struct qxl_bo *qbo;
  46. int r;
  47. *obj = NULL;
  48. /* At least align on page size */
  49. if (alignment < PAGE_SIZE)
  50. alignment = PAGE_SIZE;
  51. r = qxl_bo_create(qdev, size, kernel, false, initial_domain, surf, &qbo);
  52. if (r) {
  53. if (r != -ERESTARTSYS)
  54. DRM_ERROR(
  55. "Failed to allocate GEM object (%d, %d, %u, %d)\n",
  56. size, initial_domain, alignment, r);
  57. return r;
  58. }
  59. *obj = &qbo->gem_base;
  60. mutex_lock(&qdev->gem.mutex);
  61. list_add_tail(&qbo->list, &qdev->gem.objects);
  62. mutex_unlock(&qdev->gem.mutex);
  63. return 0;
  64. }
  65. int qxl_gem_object_create_with_handle(struct qxl_device *qdev,
  66. struct drm_file *file_priv,
  67. u32 domain,
  68. size_t size,
  69. struct qxl_surface *surf,
  70. struct qxl_bo **qobj,
  71. uint32_t *handle)
  72. {
  73. struct drm_gem_object *gobj;
  74. int r;
  75. BUG_ON(!qobj);
  76. BUG_ON(!handle);
  77. r = qxl_gem_object_create(qdev, size, 0,
  78. domain,
  79. false, false, surf,
  80. &gobj);
  81. if (r)
  82. return -ENOMEM;
  83. r = drm_gem_handle_create(file_priv, gobj, handle);
  84. if (r)
  85. return r;
  86. /* drop reference from allocate - handle holds it now */
  87. *qobj = gem_to_qxl_bo(gobj);
  88. drm_gem_object_unreference_unlocked(gobj);
  89. return 0;
  90. }
  91. int qxl_gem_object_open(struct drm_gem_object *obj, struct drm_file *file_priv)
  92. {
  93. return 0;
  94. }
  95. void qxl_gem_object_close(struct drm_gem_object *obj,
  96. struct drm_file *file_priv)
  97. {
  98. }
  99. int qxl_gem_init(struct qxl_device *qdev)
  100. {
  101. INIT_LIST_HEAD(&qdev->gem.objects);
  102. return 0;
  103. }
  104. void qxl_gem_fini(struct qxl_device *qdev)
  105. {
  106. qxl_bo_force_delete(qdev);
  107. }