qxl_gem.c 3.1 KB

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